/* esm.sh - @noble/curves@1.9.7/abstract/weierstrass */
import{hmac as St}from"/@noble/hashes@1.8.0/es2022/hmac.mjs";import{ahash as Ot}from"/@noble/hashes@1.8.0/es2022/utils.mjs";import{_validateObject as gt,_abool2 as st,_abytes2 as J,aInRange as qt,bitLen as Vt,bitMask as Et,bytesToHex as ot,bytesToNumberBE as vt,concatBytes as Q,createHmacDrbg as _t,ensureBytes as X,hexToBytes as mt,inRange as Ut,isBytes as Zt,memoized as ht,numberToHexUnpadded as nt,randomBytes as bt}from"../utils.mjs";import{_createCurveFields as At,mulEndoUnsafe as Nt,negateCt as yt,normalizeZ as it,pippenger as Tt,wNAF as Yt}from"./curve.mjs";import{Field as Ct,FpInvertBatch as Kt,getMinHashLength as Ht,mapHashToField as Lt,nLength as Dt,validateField as It}from"./modular.mjs";var wt=(e,s)=>(e+(e>=0?s:-s)/$)/s;function Xt(e,s,i){let[[t,d],[h,a]]=s,R=wt(a*e,i),w=wt(-d*e,i),S=e-R*t-w*h,O=-R*d-w*a,D=S<M,H=O<M;D&&(S=-S),H&&(O=-O);let g=Et(Math.ceil(Vt(i)/2))+K;if(S<M||S>=g||O<M||O>=g)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:D,k1:S,k2neg:H,k2:O}}function at(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ct(e,s){let i={};for(let t of Object.keys(s))i[t]=e[t]===void 0?s[t]:e[t];return st(i.lowS,"lowS"),st(i.prehash,"prehash"),i.format!==void 0&&at(i.format),i}var ut=class extends Error{constructor(s=""){super(s)}},P={Err:ut,_tlv:{encode:(e,s)=>{let{Err:i}=P;if(e<0||e>256)throw new i("tlv.encode: wrong tag");if(s.length&1)throw new i("tlv.encode: unpadded data");let t=s.length/2,d=nt(t);if(d.length/2&128)throw new i("tlv.encode: long form length too big");let h=t>127?nt(d.length/2|128):"";return nt(e)+h+d+s},decode(e,s){let{Err:i}=P,t=0;if(e<0||e>256)throw new i("tlv.encode: wrong tag");if(s.length<2||s[t++]!==e)throw new i("tlv.decode: wrong tlv");let d=s[t++],h=!!(d&128),a=0;if(!h)a=d;else{let w=d&127;if(!w)throw new i("tlv.decode(long): indefinite length not supported");if(w>4)throw new i("tlv.decode(long): byte length is too big");let S=s.subarray(t,t+w);if(S.length!==w)throw new i("tlv.decode: length bytes not complete");if(S[0]===0)throw new i("tlv.decode(long): zero leftmost byte");for(let O of S)a=a<<8|O;if(t+=w,a<128)throw new i("tlv.decode(long): not minimal encoding")}let R=s.subarray(t,t+a);if(R.length!==a)throw new i("tlv.decode: wrong value length");return{v:R,l:s.subarray(t+a)}}},_int:{encode(e){let{Err:s}=P;if(e<M)throw new s("integer: negative integers are not allowed");let i=nt(e);if(Number.parseInt(i[0],16)&8&&(i="00"+i),i.length&1)throw new s("unexpected DER parsing assertion: unpadded hex");return i},decode(e){let{Err:s}=P;if(e[0]&128)throw new s("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new s("invalid signature integer: unnecessary leading zero");return vt(e)}},toSig(e){let{Err:s,_int:i,_tlv:t}=P,d=X("signature",e),{v:h,l:a}=t.decode(48,d);if(a.length)throw new s("invalid signature: left bytes after parsing");let{v:R,l:w}=t.decode(2,h),{v:S,l:O}=t.decode(2,w);if(O.length)throw new s("invalid signature: left bytes after parsing");return{r:i.decode(R),s:i.decode(S)}},hexFromSig(e){let{_tlv:s,_int:i}=P,t=s.encode(2,i.encode(e.r)),d=s.encode(2,i.encode(e.s)),h=t+d;return s.encode(48,h)}},M=BigInt(0),K=BigInt(1),$=BigInt(2),tt=BigInt(3),lt=BigInt(4);function F(e,s){let{BYTES:i}=e,t;if(typeof s=="bigint")t=s;else{let d=X("private key",s);try{t=e.fromBytes(d)}catch{throw new Error(`invalid private key: expected ui8a of size ${i}, got ${typeof s}`)}}if(!e.isValidNot0(t))throw new Error("invalid private key: out of range [1..N-1]");return t}function pt(e,s={}){let i=At("weierstrass",e,s),{Fp:t,Fn:d}=i,h=i.CURVE,{h:a,n:R}=h;gt(s,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:w}=s;if(w&&(!t.is0(h.a)||typeof w.beta!="bigint"||!Array.isArray(w.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let S=Rt(t,d);function O(){if(!t.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function D(x,o,n){let{x:r,y:c}=o.toAffine(),u=t.toBytes(r);if(st(n,"isCompressed"),n){O();let m=!t.isOdd(c);return Q(Bt(m),u)}else return Q(Uint8Array.of(4),u,t.toBytes(c))}function H(x){J(x,void 0,"Point");let{publicKey:o,publicKeyUncompressed:n}=S,r=x.length,c=x[0],u=x.subarray(1);if(r===o&&(c===2||c===3)){let m=t.fromBytes(u);if(!t.isValid(m))throw new Error("bad point: is not on curve, wrong x");let f=N(m),l;try{l=t.sqrt(f)}catch(Y){let _=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+_)}O();let y=t.isOdd(l);return(c&1)===1!==y&&(l=t.neg(l)),{x:m,y:l}}else if(r===n&&c===4){let m=t.BYTES,f=t.fromBytes(u.subarray(0,m)),l=t.fromBytes(u.subarray(m,m*2));if(!V(f,l))throw new Error("bad point: is not on curve");return{x:f,y:l}}else throw new Error(`bad point: got length ${r}, expected compressed=${o} or uncompressed=${n}`)}let g=s.toBytes||D,E=s.fromBytes||H;function N(x){let o=t.sqr(x),n=t.mul(o,x);return t.add(t.add(n,t.mul(x,h.a)),h.b)}function V(x,o){let n=t.sqr(o),r=N(x);return t.eql(n,r)}if(!V(h.Gx,h.Gy))throw new Error("bad curve params: generator point");let q=t.mul(t.pow(h.a,tt),lt),U=t.mul(t.sqr(h.b),BigInt(27));if(t.is0(t.add(q,U)))throw new Error("bad curve params: a or b");function p(x,o,n=!1){if(!t.isValid(o)||n&&t.is0(o))throw new Error(`bad point coordinate ${x}`);return o}function T(x){if(!(x instanceof b))throw new Error("ProjectivePoint expected")}function j(x){if(!w||!w.basises)throw new Error("no endo");return Xt(x,w.basises,d.ORDER)}let G=ht((x,o)=>{let{X:n,Y:r,Z:c}=x;if(t.eql(c,t.ONE))return{x:n,y:r};let u=x.is0();o==null&&(o=u?t.ONE:t.inv(c));let m=t.mul(n,o),f=t.mul(r,o),l=t.mul(c,o);if(u)return{x:t.ZERO,y:t.ZERO};if(!t.eql(l,t.ONE))throw new Error("invZ was invalid");return{x:m,y:f}}),z=ht(x=>{if(x.is0()){if(s.allowInfinityPoint&&!t.is0(x.Y))return;throw new Error("bad point: ZERO")}let{x:o,y:n}=x.toAffine();if(!t.isValid(o)||!t.isValid(n))throw new Error("bad point: x or y not field elements");if(!V(o,n))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function k(x,o,n,r,c){return n=new b(t.mul(n.X,x),n.Y,n.Z),o=yt(r,o),n=yt(c,n),o.add(n)}class b{constructor(o,n,r){this.X=p("x",o),this.Y=p("y",n,!0),this.Z=p("z",r),Object.freeze(this)}static CURVE(){return h}static fromAffine(o){let{x:n,y:r}=o||{};if(!o||!t.isValid(n)||!t.isValid(r))throw new Error("invalid affine point");if(o instanceof b)throw new Error("projective point not allowed");return t.is0(n)&&t.is0(r)?b.ZERO:new b(n,r,t.ONE)}static fromBytes(o){let n=b.fromAffine(E(J(o,void 0,"point")));return n.assertValidity(),n}static fromHex(o){return b.fromBytes(X("pointHex",o))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(o=8,n=!0){return W.createCache(this,o),n||this.multiply(tt),this}assertValidity(){z(this)}hasEvenY(){let{y:o}=this.toAffine();if(!t.isOdd)throw new Error("Field doesn't support isOdd");return!t.isOdd(o)}equals(o){T(o);let{X:n,Y:r,Z:c}=this,{X:u,Y:m,Z:f}=o,l=t.eql(t.mul(n,f),t.mul(u,c)),y=t.eql(t.mul(r,f),t.mul(m,c));return l&&y}negate(){return new b(this.X,t.neg(this.Y),this.Z)}double(){let{a:o,b:n}=h,r=t.mul(n,tt),{X:c,Y:u,Z:m}=this,f=t.ZERO,l=t.ZERO,y=t.ZERO,v=t.mul(c,c),Y=t.mul(u,u),_=t.mul(m,m),B=t.mul(c,u);return B=t.add(B,B),y=t.mul(c,m),y=t.add(y,y),f=t.mul(o,y),l=t.mul(r,_),l=t.add(f,l),f=t.sub(Y,l),l=t.add(Y,l),l=t.mul(f,l),f=t.mul(B,f),y=t.mul(r,y),_=t.mul(o,_),B=t.sub(v,_),B=t.mul(o,B),B=t.add(B,y),y=t.add(v,v),v=t.add(y,v),v=t.add(v,_),v=t.mul(v,B),l=t.add(l,v),_=t.mul(u,m),_=t.add(_,_),v=t.mul(_,B),f=t.sub(f,v),y=t.mul(_,Y),y=t.add(y,y),y=t.add(y,y),new b(f,l,y)}add(o){T(o);let{X:n,Y:r,Z:c}=this,{X:u,Y:m,Z:f}=o,l=t.ZERO,y=t.ZERO,v=t.ZERO,Y=h.a,_=t.mul(h.b,tt),B=t.mul(n,u),Z=t.mul(r,m),C=t.mul(c,f),I=t.add(n,r),A=t.add(u,m);I=t.mul(I,A),A=t.add(B,Z),I=t.sub(I,A),A=t.add(n,c);let L=t.add(u,f);return A=t.mul(A,L),L=t.add(B,C),A=t.sub(A,L),L=t.add(r,c),l=t.add(m,f),L=t.mul(L,l),l=t.add(Z,C),L=t.sub(L,l),v=t.mul(Y,A),l=t.mul(_,C),v=t.add(l,v),l=t.sub(Z,v),v=t.add(Z,v),y=t.mul(l,v),Z=t.add(B,B),Z=t.add(Z,B),C=t.mul(Y,C),A=t.mul(_,A),Z=t.add(Z,C),C=t.sub(B,C),C=t.mul(Y,C),A=t.add(A,C),B=t.mul(Z,A),y=t.add(y,B),B=t.mul(L,A),l=t.mul(I,l),l=t.sub(l,B),B=t.mul(I,Z),v=t.mul(L,v),v=t.add(v,B),new b(l,y,v)}subtract(o){return this.add(o.negate())}is0(){return this.equals(b.ZERO)}multiply(o){let{endo:n}=s;if(!d.isValidNot0(o))throw new Error("invalid scalar: out of range");let r,c,u=m=>W.cached(this,m,f=>it(b,f));if(n){let{k1neg:m,k1:f,k2neg:l,k2:y}=j(o),{p:v,f:Y}=u(f),{p:_,f:B}=u(y);c=Y.add(B),r=k(n.beta,v,_,m,l)}else{let{p:m,f}=u(o);r=m,c=f}return it(b,[r,c])[0]}multiplyUnsafe(o){let{endo:n}=s,r=this;if(!d.isValid(o))throw new Error("invalid scalar: out of range");if(o===M||r.is0())return b.ZERO;if(o===K)return r;if(W.hasCache(this))return this.multiply(o);if(n){let{k1neg:c,k1:u,k2neg:m,k2:f}=j(o),{p1:l,p2:y}=Nt(b,r,u,f);return k(n.beta,l,y,c,m)}else return W.unsafe(r,o)}multiplyAndAddUnsafe(o,n,r){let c=this.multiplyUnsafe(n).add(o.multiplyUnsafe(r));return c.is0()?void 0:c}toAffine(o){return G(this,o)}isTorsionFree(){let{isTorsionFree:o}=s;return a===K?!0:o?o(b,this):W.unsafe(this,R).is0()}clearCofactor(){let{clearCofactor:o}=s;return a===K?this:o?o(b,this):this.multiplyUnsafe(a)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}toBytes(o=!0){return st(o,"isCompressed"),this.assertValidity(),g(b,this,o)}toHex(o=!0){return ot(this.toBytes(o))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(o=!0){return this.toBytes(o)}_setWindowSize(o){this.precompute(o)}static normalizeZ(o){return it(b,o)}static msm(o,n){return Tt(b,d,o,n)}static fromPrivateKey(o){return b.BASE.multiply(F(d,o))}}b.BASE=new b(h.Gx,h.Gy,t.ONE),b.ZERO=new b(t.ZERO,t.ONE,t.ZERO),b.Fp=t,b.Fn=d;let et=d.BITS,W=new Yt(b,s.endo?Math.ceil(et/2):et);return b.BASE.precompute(8),b}function Bt(e){return Uint8Array.of(e?2:3)}function jt(e,s){let i=e.ORDER,t=M;for(let E=i-K;E%$===M;E/=$)t+=K;let d=t,h=$<<d-K-K,a=h*$,R=(i-K)/a,w=(R-K)/$,S=a-K,O=h,D=e.pow(s,R),H=e.pow(s,(R+K)/$),g=(E,N)=>{let V=D,q=e.pow(N,S),U=e.sqr(q);U=e.mul(U,N);let p=e.mul(E,U);p=e.pow(p,w),p=e.mul(p,q),q=e.mul(p,N),U=e.mul(p,E);let T=e.mul(U,q);p=e.pow(T,O);let j=e.eql(p,e.ONE);q=e.mul(U,H),p=e.mul(T,V),U=e.cmov(q,U,j),T=e.cmov(p,T,j);for(let G=d;G>K;G--){let z=G-$;z=$<<z-K;let k=e.pow(T,z),b=e.eql(k,e.ONE);q=e.mul(U,V),V=e.mul(V,V),k=e.mul(T,V),U=e.cmov(q,U,b),T=e.cmov(k,T,b)}return{isValid:j,value:U}};if(e.ORDER%lt===tt){let E=(e.ORDER-tt)/lt,N=e.sqrt(e.neg(s));g=(V,q)=>{let U=e.sqr(q),p=e.mul(V,q);U=e.mul(U,p);let T=e.pow(U,E);T=e.mul(T,p);let j=e.mul(T,N),G=e.mul(e.sqr(T),q),z=e.eql(G,V),k=e.cmov(j,T,z);return{isValid:z,value:k}}}return g}function ee(e,s){It(e);let{A:i,B:t,Z:d}=s;if(!e.isValid(i)||!e.isValid(t)||!e.isValid(d))throw new Error("mapToCurveSimpleSWU: invalid opts");let h=jt(e,d);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return a=>{let R,w,S,O,D,H,g,E;R=e.sqr(a),R=e.mul(R,d),w=e.sqr(R),w=e.add(w,R),S=e.add(w,e.ONE),S=e.mul(S,t),O=e.cmov(d,e.neg(w),!e.eql(w,e.ZERO)),O=e.mul(O,i),w=e.sqr(S),H=e.sqr(O),D=e.mul(H,i),w=e.add(w,D),w=e.mul(w,S),H=e.mul(H,O),D=e.mul(H,t),w=e.add(w,D),g=e.mul(R,S);let{isValid:N,value:V}=h(w,H);E=e.mul(R,a),E=e.mul(E,V),g=e.cmov(g,S,N),E=e.cmov(E,V,N);let q=e.isOdd(a)===e.isOdd(E);E=e.cmov(e.neg(E),E,q);let U=Kt(e,[O],!0)[0];return g=e.mul(g,U),{x:g,y:E}}}function Rt(e,s){return{secretKey:s.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*s.BYTES}}function kt(e,s={}){let{Fn:i}=e,t=s.randomBytes||bt,d=Object.assign(Rt(e.Fp,i),{seed:Ht(i.ORDER)});function h(g){try{return!!F(i,g)}catch{return!1}}function a(g,E){let{publicKey:N,publicKeyUncompressed:V}=d;try{let q=g.length;return E===!0&&q!==N||E===!1&&q!==V?!1:!!e.fromBytes(g)}catch{return!1}}function R(g=t(d.seed)){return Lt(J(g,d.seed,"seed"),i.ORDER)}function w(g,E=!0){return e.BASE.multiply(F(i,g)).toBytes(E)}function S(g){let E=R(g);return{secretKey:E,publicKey:w(E)}}function O(g){if(typeof g=="bigint")return!1;if(g instanceof e)return!0;let{secretKey:E,publicKey:N,publicKeyUncompressed:V}=d;if(i.allowedLengths||E===N)return;let q=X("key",g).length;return q===N||q===V}function D(g,E,N=!0){if(O(g)===!0)throw new Error("first arg must be private key");if(O(E)===!1)throw new Error("second arg must be public key");let V=F(i,g);return e.fromHex(E).multiply(V).toBytes(N)}return Object.freeze({getPublicKey:w,getSharedSecret:D,keygen:S,Point:e,utils:{isValidSecretKey:h,isValidPublicKey:a,randomSecretKey:R,isValidPrivateKey:h,randomPrivateKey:R,normPrivateKeyToScalar:g=>F(i,g),precompute(g=8,E=e.BASE){return E.precompute(g,!1)}},lengths:d})}function zt(e,s,i={}){Ot(s),gt(i,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let t=i.randomBytes||bt,d=i.hmac||((n,...r)=>St(s,n,Q(...r))),{Fp:h,Fn:a}=e,{ORDER:R,BITS:w}=a,{keygen:S,getPublicKey:O,getSharedSecret:D,utils:H,lengths:g}=kt(e,i),E={prehash:!1,lowS:typeof i.lowS=="boolean"?i.lowS:!1,format:void 0,extraEntropy:!1},N="compact";function V(n){let r=R>>K;return n>r}function q(n,r){if(!a.isValidNot0(r))throw new Error(`invalid signature ${n}: out of range 1..Point.Fn.ORDER`);return r}function U(n,r){at(r);let c=g.signature,u=r==="compact"?c:r==="recovered"?c+1:void 0;return J(n,u,`${r} signature`)}class p{constructor(r,c,u){this.r=q("r",r),this.s=q("s",c),u!=null&&(this.recovery=u),Object.freeze(this)}static fromBytes(r,c=N){U(r,c);let u;if(c==="der"){let{r:y,s:v}=P.toSig(J(r));return new p(y,v)}c==="recovered"&&(u=r[0],c="compact",r=r.subarray(1));let m=a.BYTES,f=r.subarray(0,m),l=r.subarray(m,m*2);return new p(a.fromBytes(f),a.fromBytes(l),u)}static fromHex(r,c){return this.fromBytes(mt(r),c)}addRecoveryBit(r){return new p(this.r,this.s,r)}recoverPublicKey(r){let c=h.ORDER,{r:u,s:m,recovery:f}=this;if(f==null||![0,1,2,3].includes(f))throw new Error("recovery id invalid");if(R*$<c&&f>1)throw new Error("recovery id is ambiguous for h>1 curve");let y=f===2||f===3?u+R:u;if(!h.isValid(y))throw new Error("recovery id 2 or 3 invalid");let v=h.toBytes(y),Y=e.fromBytes(Q(Bt((f&1)===0),v)),_=a.inv(y),B=j(X("msgHash",r)),Z=a.create(-B*_),C=a.create(m*_),I=e.BASE.multiplyUnsafe(Z).add(Y.multiplyUnsafe(C));if(I.is0())throw new Error("point at infinify");return I.assertValidity(),I}hasHighS(){return V(this.s)}toBytes(r=N){if(at(r),r==="der")return mt(P.hexFromSig(this));let c=a.toBytes(this.r),u=a.toBytes(this.s);if(r==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Q(Uint8Array.of(this.recovery),c,u)}return Q(c,u)}toHex(r){return ot(this.toBytes(r))}assertValidity(){}static fromCompact(r){return p.fromBytes(X("sig",r),"compact")}static fromDER(r){return p.fromBytes(X("sig",r),"der")}normalizeS(){return this.hasHighS()?new p(this.r,a.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return ot(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return ot(this.toBytes("compact"))}}let T=i.bits2int||function(r){if(r.length>8192)throw new Error("input is too large");let c=vt(r),u=r.length*8-w;return u>0?c>>BigInt(u):c},j=i.bits2int_modN||function(r){return a.create(T(r))},G=Et(w);function z(n){return qt("num < 2^"+w,n,M,G),a.toBytes(n)}function k(n,r){return J(n,void 0,"message"),r?J(s(n),void 0,"prehashed message"):n}function b(n,r,c){if(["recovered","canonical"].some(Z=>Z in c))throw new Error("sign() legacy options not supported");let{lowS:u,prehash:m,extraEntropy:f}=ct(c,E);n=k(n,m);let l=j(n),y=F(a,r),v=[z(y),z(l)];if(f!=null&&f!==!1){let Z=f===!0?t(g.secretKey):f;v.push(X("extraEntropy",Z))}let Y=Q(...v),_=l;function B(Z){let C=T(Z);if(!a.isValidNot0(C))return;let I=a.inv(C),A=e.BASE.multiply(C).toAffine(),L=a.create(A.x);if(L===M)return;let rt=a.create(I*a.create(_+L*y));if(rt===M)return;let dt=(A.x===L?0:2)|Number(A.y&K),ft=rt;return u&&V(rt)&&(ft=a.neg(rt),dt^=1),new p(L,ft,dt)}return{seed:Y,k2sig:B}}function et(n,r,c={}){n=X("message",n);let{seed:u,k2sig:m}=b(n,r,c);return _t(s.outputLen,a.BYTES,d)(u,m)}function W(n){let r,c=typeof n=="string"||Zt(n),u=!c&&n!==null&&typeof n=="object"&&typeof n.r=="bigint"&&typeof n.s=="bigint";if(!c&&!u)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(u)r=new p(n.r,n.s);else if(c){try{r=p.fromBytes(X("sig",n),"der")}catch(m){if(!(m instanceof P.Err))throw m}if(!r)try{r=p.fromBytes(X("sig",n),"compact")}catch{return!1}}return r||!1}function x(n,r,c,u={}){let{lowS:m,prehash:f,format:l}=ct(u,E);if(c=X("publicKey",c),r=k(X("message",r),f),"strict"in u)throw new Error("options.strict was renamed to lowS");let y=l===void 0?W(n):p.fromBytes(X("sig",n),l);if(y===!1)return!1;try{let v=e.fromBytes(c);if(m&&y.hasHighS())return!1;let{r:Y,s:_}=y,B=j(r),Z=a.inv(_),C=a.create(B*Z),I=a.create(Y*Z),A=e.BASE.multiplyUnsafe(C).add(v.multiplyUnsafe(I));return A.is0()?!1:a.create(A.x)===Y}catch{return!1}}function o(n,r,c={}){let{prehash:u}=ct(c,E);return r=k(r,u),p.fromBytes(n,"recovered").recoverPublicKey(r).toBytes()}return Object.freeze({keygen:S,getPublicKey:O,getSharedSecret:D,utils:H,lengths:g,Point:e,sign:et,verify:x,recoverPublicKey:o,Signature:p,hash:s})}function re(e){let{CURVE:s,curveOpts:i}=xt(e),t=pt(s,i);return Gt(e,t)}function xt(e){let s={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},i=e.Fp,t=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(a=>Math.ceil(a/2)))):void 0,d=Ct(s.n,{BITS:e.nBitLength,allowedLengths:t,modFromBytes:e.wrapPrivateKey}),h={Fp:i,Fn:d,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:s,curveOpts:h}}function Mt(e){let{CURVE:s,curveOpts:i}=xt(e),t={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:s,curveOpts:i,hash:e.hash,ecdsaOpts:t}}function $t(e,s,i){function t(d){let h=e.sqr(d),a=e.mul(h,d);return e.add(e.add(a,e.mul(d,s)),i)}return t}function Gt(e,s){let{Fp:i,Fn:t}=s;function d(a){return Ut(a,K,t.ORDER)}let h=$t(i,e.a,e.b);return Object.assign({},{CURVE:e,Point:s,ProjectivePoint:s,normPrivateKeyToScalar:a=>F(t,a),weierstrassEquation:h,isWithinCurveOrder:d})}function Pt(e,s){let i=s.Point;return Object.assign({},s,{ProjectivePoint:i,CURVE:Object.assign({},e,Dt(i.Fn.ORDER,i.Fn.BITS))})}function ne(e){let{CURVE:s,curveOpts:i,hash:t,ecdsaOpts:d}=Mt(e),h=pt(s,i),a=zt(h,t,d);return Pt(e,a)}export{P as DER,ut as DERErr,jt as SWUFpSqrtRatio,$t as _legacyHelperEquat,F as _normFnElement,Xt as _splitEndoScalar,kt as ecdh,zt as ecdsa,ee as mapToCurveSimpleSWU,ne as weierstrass,pt as weierstrassN,re as weierstrassPoints};
/*! Bundled license information:

@noble/curves/esm/abstract/weierstrass.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
*/
//# sourceMappingURL=weierstrass.mjs.map