zksync-easy-onramp
Version:
SDK package for ZKsync easy on ramp
3 lines (2 loc) • 27.7 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./index-Bx76ZFXt.cjs");class Pt extends G.Hash{constructor(n,t){super(),this.finished=!1,this.destroyed=!1,G.ahash(n);const r=G.toBytes(t);if(this.iHash=n.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,i=new Uint8Array(s);i.set(r.length>s?n.create().update(r).digest():r);for(let c=0;c<i.length;c++)i[c]^=54;this.iHash.update(i),this.oHash=n.create();for(let c=0;c<i.length;c++)i[c]^=106;this.oHash.update(i),i.fill(0)}update(n){return G.aexists(this),this.iHash.update(n),this}digestInto(n){G.aexists(this),G.abytes(n,this.outputLen),this.finished=!0,this.iHash.digestInto(n),this.oHash.update(n),this.oHash.digestInto(n),this.destroy()}digest(){const n=new Uint8Array(this.oHash.outputLen);return this.digestInto(n),n}_cloneInto(n){n||(n=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:r,finished:s,destroyed:i,blockLen:c,outputLen:f}=this;return n=n,n.finished=s,n.destroyed=i,n.blockLen=c,n.outputLen=f,n.oHash=t._cloneInto(n.oHash),n.iHash=r._cloneInto(n.iHash),n}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Wt=(e,n,t)=>new Pt(e,n).update(t).digest();Wt.create=(e,n)=>new Pt(e,n);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Zt=BigInt(0),It=BigInt(1);function st(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function zt(e){if(!st(e))throw new Error("Uint8Array expected")}function ut(e,n){if(typeof n!="boolean")throw new Error(e+" boolean expected, got "+n)}function ht(e){const n=e.toString(16);return n.length&1?"0"+n:n}function Gt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Zt:BigInt("0x"+e)}const $t=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ce=Array.from({length:256},(e,n)=>n.toString(16).padStart(2,"0"));function lt(e){if(zt(e),$t)return e.toHex();let n="";for(let t=0;t<e.length;t++)n+=ce[e[t]];return n}const W={_0:48,_9:57,A:65,F:70,a:97,f:102};function kt(e){if(e>=W._0&&e<=W._9)return e-W._0;if(e>=W.A&&e<=W.F)return e-(W.A-10);if(e>=W.a&&e<=W.f)return e-(W.a-10)}function wt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if($t)return Uint8Array.fromHex(e);const n=e.length,t=n/2;if(n%2)throw new Error("hex string expected, got unpadded hex of length "+n);const r=new Uint8Array(t);for(let s=0,i=0;s<t;s++,i+=2){const c=kt(e.charCodeAt(i)),f=kt(e.charCodeAt(i+1));if(c===void 0||f===void 0){const o=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+o+'" at index '+i)}r[s]=c*16+f}return r}function et(e){return Gt(lt(e))}function Xt(e){return zt(e),Gt(lt(Uint8Array.from(e).reverse()))}function dt(e,n){return wt(e.toString(16).padStart(n*2,"0"))}function Dt(e,n){return dt(e,n).reverse()}function K(e,n,t){let r;if(typeof n=="string")try{r=wt(n)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(st(n))r=Uint8Array.from(n);else throw new Error(e+" must be hex string or Uint8Array");const s=r.length;if(typeof t=="number"&&s!==t)throw new Error(e+" of length "+t+" expected, got "+s);return r}function gt(...e){let n=0;for(let r=0;r<e.length;r++){const s=e[r];zt(s),n+=s.length}const t=new Uint8Array(n);for(let r=0,s=0;r<e.length;r++){const i=e[r];t.set(i,s),s+=i.length}return t}const Et=e=>typeof e=="bigint"&&Zt<=e;function Ut(e,n,t){return Et(e)&&Et(n)&&Et(t)&&n<=e&&e<t}function it(e,n,t,r){if(!Ut(n,t,r))throw new Error("expected valid "+e+": "+t+" <= n < "+r+", got "+n)}function fe(e){let n;for(n=0;e>Zt;e>>=It,n+=1);return n}const pt=e=>(It<<BigInt(e))-It,Bt=e=>new Uint8Array(e),Tt=e=>Uint8Array.from(e);function ae(e,n,t){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof n!="number"||n<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let r=Bt(e),s=Bt(e),i=0;const c=()=>{r.fill(1),s.fill(0),i=0},f=(...I)=>t(s,r,...I),o=(I=Bt(0))=>{s=f(Tt([0]),I),r=f(),I.length!==0&&(s=f(Tt([1]),I),r=f())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let I=0;const d=[];for(;I<n;){r=f();const S=r.slice();d.push(S),I+=r.length}return gt(...d)};return(I,d)=>{c(),o(I);let S;for(;!(S=d(u()));)o();return c(),S}}const ue={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||st(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,n)=>n.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function yt(e,n,t={}){const r=(s,i,c)=>{const f=ue[i];if(typeof f!="function")throw new Error("invalid validator function");const o=e[s];if(!(c&&o===void 0)&&!f(o,e))throw new Error("param "+String(s)+" is invalid. Expected "+i+", got "+o)};for(const[s,i]of Object.entries(n))r(s,i,!1);for(const[s,i]of Object.entries(t))r(s,i,!0);return e}function Rt(e){const n=new WeakMap;return(t,...r)=>{const s=n.get(t);if(s!==void 0)return s;const i=e(t,...r);return n.set(t,i),i}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const T=BigInt(0),z=BigInt(1),tt=BigInt(2),le=BigInt(3),Nt=BigInt(4),Ct=BigInt(5),_t=BigInt(8);function j(e,n){const t=e%n;return t>=T?t:n+t}function de(e,n,t){if(n<T)throw new Error("invalid exponent, negatives unsupported");if(t<=T)throw new Error("invalid modulus");if(t===z)return T;let r=z;for(;n>T;)n&z&&(r=r*e%t),e=e*e%t,n>>=z;return r}function Y(e,n,t){let r=e;for(;n-- >T;)r*=r,r%=t;return r}function qt(e,n){if(e===T)throw new Error("invert: expected non-zero number");if(n<=T)throw new Error("invert: expected positive modulus, got "+n);let t=j(e,n),r=n,s=T,i=z;for(;t!==T;){const f=r/t,o=r%t,u=s-i*f;r=t,t=o,s=i,i=u}if(r!==z)throw new Error("invert: does not exist");return j(s,n)}function he(e){const n=(e-z)/tt;let t,r,s;for(t=e-z,r=0;t%tt===T;t/=tt,r++);for(s=tt;s<e&&de(s,n,e)!==e-z;s++)if(s>1e3)throw new Error("Cannot find square root: likely non-prime P");if(r===1){const c=(e+z)/Nt;return function(o,u){const m=o.pow(u,c);if(!o.eql(o.sqr(m),u))throw new Error("Cannot find square root");return m}}const i=(t+z)/tt;return function(f,o){if(f.pow(o,n)===f.neg(f.ONE))throw new Error("Cannot find square root");let u=r,m=f.pow(f.mul(f.ONE,s),t),I=f.pow(o,i),d=f.pow(o,t);for(;!f.eql(d,f.ONE);){if(f.eql(d,f.ZERO))return f.ZERO;let S=1;for(let p=f.sqr(d);S<u&&!f.eql(p,f.ONE);S++)p=f.sqr(p);const L=f.pow(m,z<<BigInt(u-S-1));m=f.sqr(L),I=f.mul(I,L),d=f.mul(d,m),u=S}return I}}function we(e){if(e%Nt===le){const n=(e+z)/Nt;return function(r,s){const i=r.pow(s,n);if(!r.eql(r.sqr(i),s))throw new Error("Cannot find square root");return i}}if(e%_t===Ct){const n=(e-Ct)/_t;return function(r,s){const i=r.mul(s,tt),c=r.pow(i,n),f=r.mul(s,c),o=r.mul(r.mul(f,tt),c),u=r.mul(f,r.sub(o,r.ONE));if(!r.eql(r.sqr(u),s))throw new Error("Cannot find square root");return u}}return he(e)}const ge=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function pe(e){const n={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=ge.reduce((r,s)=>(r[s]="function",r),n);return yt(e,t)}function ye(e,n,t){if(t<T)throw new Error("invalid exponent, negatives unsupported");if(t===T)return e.ONE;if(t===z)return n;let r=e.ONE,s=n;for(;t>T;)t&z&&(r=e.mul(r,s)),s=e.sqr(s),t>>=z;return r}function me(e,n){const t=new Array(n.length),r=n.reduce((i,c,f)=>e.is0(c)?i:(t[f]=i,e.mul(i,c)),e.ONE),s=e.inv(r);return n.reduceRight((i,c,f)=>e.is0(c)?i:(t[f]=e.mul(i,t[f]),e.mul(i,c)),s),t}function Qt(e,n){const t=n!==void 0?n:e.toString(2).length,r=Math.ceil(t/8);return{nBitLength:t,nByteLength:r}}function Jt(e,n,t=!1,r={}){if(e<=T)throw new Error("invalid field: expected ORDER > 0, got "+e);const{nBitLength:s,nByteLength:i}=Qt(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c;const f=Object.freeze({ORDER:e,isLE:t,BITS:s,BYTES:i,MASK:pt(s),ZERO:T,ONE:z,create:o=>j(o,e),isValid:o=>{if(typeof o!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof o);return T<=o&&o<e},is0:o=>o===T,isOdd:o=>(o&z)===z,neg:o=>j(-o,e),eql:(o,u)=>o===u,sqr:o=>j(o*o,e),add:(o,u)=>j(o+u,e),sub:(o,u)=>j(o-u,e),mul:(o,u)=>j(o*u,e),pow:(o,u)=>ye(f,o,u),div:(o,u)=>j(o*qt(u,e),e),sqrN:o=>o*o,addN:(o,u)=>o+u,subN:(o,u)=>o-u,mulN:(o,u)=>o*u,inv:o=>qt(o,e),sqrt:r.sqrt||(o=>(c||(c=we(e)),c(f,o))),invertBatch:o=>me(f,o),cmov:(o,u,m)=>m?u:o,toBytes:o=>t?Dt(o,i):dt(o,i),fromBytes:o=>{if(o.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+o.length);return t?Xt(o):et(o)}});return Object.freeze(f)}function te(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const n=e.toString(2).length;return Math.ceil(n/8)}function ee(e){const n=te(e);return n+Math.ceil(n/2)}function be(e,n,t=!1){const r=e.length,s=te(n),i=ee(n);if(r<16||r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);const c=t?Xt(e):et(e),f=j(c,n-z)+z;return t?Dt(f,s):dt(f,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Mt=BigInt(0),Ot=BigInt(1);function vt(e,n){const t=n.negate();return e?t:n}function ne(e,n){if(!Number.isSafeInteger(e)||e<=0||e>n)throw new Error("invalid window size, expected [1.."+n+"], got W="+e)}function xt(e,n){ne(e,n);const t=Math.ceil(n/e)+1,r=2**(e-1),s=2**e,i=pt(e),c=BigInt(e);return{windows:t,windowSize:r,mask:i,maxNumber:s,shiftBy:c}}function jt(e,n,t){const{windowSize:r,mask:s,maxNumber:i,shiftBy:c}=t;let f=Number(e&s),o=e>>c;f>r&&(f-=i,o+=Ot);const u=n*r,m=u+Math.abs(f)-1,I=f===0,d=f<0,S=n%2!==0;return{nextN:o,offset:m,isZero:I,isNeg:d,isNegF:S,offsetF:u}}function Ee(e,n){if(!Array.isArray(e))throw new Error("array expected");e.forEach((t,r)=>{if(!(t instanceof n))throw new Error("invalid point at index "+r)})}function Be(e,n){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((t,r)=>{if(!n.isValid(t))throw new Error("invalid scalar at index "+r)})}const St=new WeakMap,re=new WeakMap;function At(e){return re.get(e)||1}function ve(e,n){return{constTimeNegate:vt,hasPrecomputes(t){return At(t)!==1},unsafeLadder(t,r,s=e.ZERO){let i=t;for(;r>Mt;)r&Ot&&(s=s.add(i)),i=i.double(),r>>=Ot;return s},precomputeWindow(t,r){const{windows:s,windowSize:i}=xt(r,n),c=[];let f=t,o=f;for(let u=0;u<s;u++){o=f,c.push(o);for(let m=1;m<i;m++)o=o.add(f),c.push(o);f=o.double()}return c},wNAF(t,r,s){let i=e.ZERO,c=e.BASE;const f=xt(t,n);for(let o=0;o<f.windows;o++){const{nextN:u,offset:m,isZero:I,isNeg:d,isNegF:S,offsetF:L}=jt(s,o,f);s=u,I?c=c.add(vt(S,r[L])):i=i.add(vt(d,r[m]))}return{p:i,f:c}},wNAFUnsafe(t,r,s,i=e.ZERO){const c=xt(t,n);for(let f=0;f<c.windows&&s!==Mt;f++){const{nextN:o,offset:u,isZero:m,isNeg:I}=jt(s,f,c);if(s=o,!m){const d=r[u];i=i.add(I?d.negate():d)}}return i},getPrecomputes(t,r,s){let i=St.get(r);return i||(i=this.precomputeWindow(r,t),t!==1&&St.set(r,s(i))),i},wNAFCached(t,r,s){const i=At(t);return this.wNAF(i,this.getPrecomputes(i,t,s),r)},wNAFCachedUnsafe(t,r,s,i){const c=At(t);return c===1?this.unsafeLadder(t,r,i):this.wNAFUnsafe(c,this.getPrecomputes(c,t,s),r,i)},setWindowSize(t,r){ne(r,n),re.set(t,r),St.delete(t)}}}function xe(e,n,t,r){if(Ee(t,e),Be(r,n),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");const s=e.ZERO,i=fe(BigInt(t.length)),c=i>12?i-3:i>4?i-2:i?2:1,f=pt(c),o=new Array(Number(f)+1).fill(s),u=Math.floor((n.BITS-1)/c)*c;let m=s;for(let I=u;I>=0;I-=c){o.fill(s);for(let S=0;S<r.length;S++){const L=r[S],p=Number(L>>BigInt(I)&f);o[p]=o[p].add(t[S])}let d=s;for(let S=o.length-1,L=s;S>0;S--)L=L.add(o[S]),d=d.add(L);if(m=m.add(d),I!==0)for(let S=0;S<c;S++)m=m.double()}return m}function oe(e){return pe(e.Fp),yt(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Qt(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Vt(e){e.lowS!==void 0&&ut("lowS",e.lowS),e.prehash!==void 0&&ut("prehash",e.prehash)}function Se(e){const n=oe(e);yt(n,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:t,Fp:r,a:s}=n;if(t){if(!r.eql(s,r.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...n})}class Ae extends Error{constructor(n=""){super(n)}}const $={Err:Ae,_tlv:{encode:(e,n)=>{const{Err:t}=$;if(e<0||e>256)throw new t("tlv.encode: wrong tag");if(n.length&1)throw new t("tlv.encode: unpadded data");const r=n.length/2,s=ht(r);if(s.length/2&128)throw new t("tlv.encode: long form length too big");const i=r>127?ht(s.length/2|128):"";return ht(e)+i+s+n},decode(e,n){const{Err:t}=$;let r=0;if(e<0||e>256)throw new t("tlv.encode: wrong tag");if(n.length<2||n[r++]!==e)throw new t("tlv.decode: wrong tlv");const s=n[r++],i=!!(s&128);let c=0;if(!i)c=s;else{const o=s&127;if(!o)throw new t("tlv.decode(long): indefinite length not supported");if(o>4)throw new t("tlv.decode(long): byte length is too big");const u=n.subarray(r,r+o);if(u.length!==o)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(const m of u)c=c<<8|m;if(r+=o,c<128)throw new t("tlv.decode(long): not minimal encoding")}const f=n.subarray(r,r+c);if(f.length!==c)throw new t("tlv.decode: wrong value length");return{v:f,l:n.subarray(r+c)}}},_int:{encode(e){const{Err:n}=$;if(e<X)throw new n("integer: negative integers are not allowed");let t=ht(e);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new n("unexpected DER parsing assertion: unpadded hex");return t},decode(e){const{Err:n}=$;if(e[0]&128)throw new n("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new n("invalid signature integer: unnecessary leading zero");return et(e)}},toSig(e){const{Err:n,_int:t,_tlv:r}=$,s=K("signature",e),{v:i,l:c}=r.decode(48,s);if(c.length)throw new n("invalid signature: left bytes after parsing");const{v:f,l:o}=r.decode(2,i),{v:u,l:m}=r.decode(2,o);if(m.length)throw new n("invalid signature: left bytes after parsing");return{r:t.decode(f),s:t.decode(u)}},hexFromSig(e){const{_tlv:n,_int:t}=$,r=n.encode(2,t.encode(e.r)),s=n.encode(2,t.encode(e.s)),i=r+s;return n.encode(48,i)}},X=BigInt(0),k=BigInt(1);BigInt(2);const Yt=BigInt(3);BigInt(4);function Ie(e){const n=Se(e),{Fp:t}=n,r=Jt(n.n,n.nBitLength),s=n.toBytes||((p,a,h)=>{const y=a.toAffine();return gt(Uint8Array.from([4]),t.toBytes(y.x),t.toBytes(y.y))}),i=n.fromBytes||(p=>{const a=p.subarray(1),h=t.fromBytes(a.subarray(0,t.BYTES)),y=t.fromBytes(a.subarray(t.BYTES,2*t.BYTES));return{x:h,y}});function c(p){const{a,b:h}=n,y=t.sqr(p),b=t.mul(y,p);return t.add(t.add(b,t.mul(p,a)),h)}if(!t.eql(t.sqr(n.Gy),c(n.Gx)))throw new Error("bad generator point: equation left != right");function f(p){return Ut(p,k,n.n)}function o(p){const{allowedPrivateKeyLengths:a,nByteLength:h,wrapPrivateKey:y,n:b}=n;if(a&&typeof p!="bigint"){if(st(p)&&(p=lt(p)),typeof p!="string"||!a.includes(p.length))throw new Error("invalid private key");p=p.padStart(h*2,"0")}let N;try{N=typeof p=="bigint"?p:et(K("private key",p,h))}catch{throw new Error("invalid private key, expected hex or "+h+" bytes, got "+typeof p)}return y&&(N=j(N,b)),it("private key",N,k,b),N}function u(p){if(!(p instanceof d))throw new Error("ProjectivePoint expected")}const m=Rt((p,a)=>{const{px:h,py:y,pz:b}=p;if(t.eql(b,t.ONE))return{x:h,y};const N=p.is0();a==null&&(a=N?t.ONE:t.inv(b));const O=t.mul(h,a),A=t.mul(y,a),E=t.mul(b,a);if(N)return{x:t.ZERO,y:t.ZERO};if(!t.eql(E,t.ONE))throw new Error("invZ was invalid");return{x:O,y:A}}),I=Rt(p=>{if(p.is0()){if(n.allowInfinityPoint&&!t.is0(p.py))return;throw new Error("bad point: ZERO")}const{x:a,y:h}=p.toAffine();if(!t.isValid(a)||!t.isValid(h))throw new Error("bad point: x or y not FE");const y=t.sqr(h),b=c(a);if(!t.eql(y,b))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(a,h,y){if(a==null||!t.isValid(a))throw new Error("x required");if(h==null||!t.isValid(h))throw new Error("y required");if(y==null||!t.isValid(y))throw new Error("z required");this.px=a,this.py=h,this.pz=y,Object.freeze(this)}static fromAffine(a){const{x:h,y}=a||{};if(!a||!t.isValid(h)||!t.isValid(y))throw new Error("invalid affine point");if(a instanceof d)throw new Error("projective point not allowed");const b=N=>t.eql(N,t.ZERO);return b(h)&&b(y)?d.ZERO:new d(h,y,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(a){const h=t.invertBatch(a.map(y=>y.pz));return a.map((y,b)=>y.toAffine(h[b])).map(d.fromAffine)}static fromHex(a){const h=d.fromAffine(i(K("pointHex",a)));return h.assertValidity(),h}static fromPrivateKey(a){return d.BASE.multiply(o(a))}static msm(a,h){return xe(d,r,a,h)}_setWindowSize(a){L.setWindowSize(this,a)}assertValidity(){I(this)}hasEvenY(){const{y:a}=this.toAffine();if(t.isOdd)return!t.isOdd(a);throw new Error("Field doesn't support isOdd")}equals(a){u(a);const{px:h,py:y,pz:b}=this,{px:N,py:O,pz:A}=a,E=t.eql(t.mul(h,A),t.mul(N,b)),x=t.eql(t.mul(y,A),t.mul(O,b));return E&&x}negate(){return new d(this.px,t.neg(this.py),this.pz)}double(){const{a,b:h}=n,y=t.mul(h,Yt),{px:b,py:N,pz:O}=this;let A=t.ZERO,E=t.ZERO,x=t.ZERO,B=t.mul(b,b),R=t.mul(N,N),Z=t.mul(O,O),H=t.mul(b,N);return H=t.add(H,H),x=t.mul(b,O),x=t.add(x,x),A=t.mul(a,x),E=t.mul(y,Z),E=t.add(A,E),A=t.sub(R,E),E=t.add(R,E),E=t.mul(A,E),A=t.mul(H,A),x=t.mul(y,x),Z=t.mul(a,Z),H=t.sub(B,Z),H=t.mul(a,H),H=t.add(H,x),x=t.add(B,B),B=t.add(x,B),B=t.add(B,Z),B=t.mul(B,H),E=t.add(E,B),Z=t.mul(N,O),Z=t.add(Z,Z),B=t.mul(Z,H),A=t.sub(A,B),x=t.mul(Z,R),x=t.add(x,x),x=t.add(x,x),new d(A,E,x)}add(a){u(a);const{px:h,py:y,pz:b}=this,{px:N,py:O,pz:A}=a;let E=t.ZERO,x=t.ZERO,B=t.ZERO;const R=n.a,Z=t.mul(n.b,Yt);let H=t.mul(h,N),V=t.mul(y,O),l=t.mul(b,A),w=t.add(h,y),g=t.add(N,O);w=t.mul(w,g),g=t.add(H,V),w=t.sub(w,g),g=t.add(h,b);let v=t.add(N,A);return g=t.mul(g,v),v=t.add(H,l),g=t.sub(g,v),v=t.add(y,b),E=t.add(O,A),v=t.mul(v,E),E=t.add(V,l),v=t.sub(v,E),B=t.mul(R,g),E=t.mul(Z,l),B=t.add(E,B),E=t.sub(V,B),B=t.add(V,B),x=t.mul(E,B),V=t.add(H,H),V=t.add(V,H),l=t.mul(R,l),g=t.mul(Z,g),V=t.add(V,l),l=t.sub(H,l),l=t.mul(R,l),g=t.add(g,l),H=t.mul(V,g),x=t.add(x,H),H=t.mul(v,g),E=t.mul(w,E),E=t.sub(E,H),H=t.mul(w,V),B=t.mul(v,B),B=t.add(B,H),new d(E,x,B)}subtract(a){return this.add(a.negate())}is0(){return this.equals(d.ZERO)}wNAF(a){return L.wNAFCached(this,a,d.normalizeZ)}multiplyUnsafe(a){const{endo:h,n:y}=n;it("scalar",a,X,y);const b=d.ZERO;if(a===X)return b;if(this.is0()||a===k)return this;if(!h||L.hasPrecomputes(this))return L.wNAFCachedUnsafe(this,a,d.normalizeZ);let{k1neg:N,k1:O,k2neg:A,k2:E}=h.splitScalar(a),x=b,B=b,R=this;for(;O>X||E>X;)O&k&&(x=x.add(R)),E&k&&(B=B.add(R)),R=R.double(),O>>=k,E>>=k;return N&&(x=x.negate()),A&&(B=B.negate()),B=new d(t.mul(B.px,h.beta),B.py,B.pz),x.add(B)}multiply(a){const{endo:h,n:y}=n;it("scalar",a,k,y);let b,N;if(h){const{k1neg:O,k1:A,k2neg:E,k2:x}=h.splitScalar(a);let{p:B,f:R}=this.wNAF(A),{p:Z,f:H}=this.wNAF(x);B=L.constTimeNegate(O,B),Z=L.constTimeNegate(E,Z),Z=new d(t.mul(Z.px,h.beta),Z.py,Z.pz),b=B.add(Z),N=R.add(H)}else{const{p:O,f:A}=this.wNAF(a);b=O,N=A}return d.normalizeZ([b,N])[0]}multiplyAndAddUnsafe(a,h,y){const b=d.BASE,N=(A,E)=>E===X||E===k||!A.equals(b)?A.multiplyUnsafe(E):A.multiply(E),O=N(this,h).add(N(a,y));return O.is0()?void 0:O}toAffine(a){return m(this,a)}isTorsionFree(){const{h:a,isTorsionFree:h}=n;if(a===k)return!0;if(h)return h(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:a,clearCofactor:h}=n;return a===k?this:h?h(d,this):this.multiplyUnsafe(n.h)}toRawBytes(a=!0){return ut("isCompressed",a),this.assertValidity(),s(d,this,a)}toHex(a=!0){return ut("isCompressed",a),lt(this.toRawBytes(a))}}d.BASE=new d(n.Gx,n.Gy,t.ONE),d.ZERO=new d(t.ZERO,t.ONE,t.ZERO);const S=n.nBitLength,L=ve(d,n.endo?Math.ceil(S/2):S);return{CURVE:n,ProjectivePoint:d,normPrivateKeyToScalar:o,weierstrassEquation:c,isWithinCurveOrder:f}}function Ne(e){const n=oe(e);return yt(n,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...n})}function qe(e){const n=Ne(e),{Fp:t,n:r}=n,s=t.BYTES+1,i=2*t.BYTES+1;function c(l){return j(l,r)}function f(l){return qt(l,r)}const{ProjectivePoint:o,normPrivateKeyToScalar:u,weierstrassEquation:m,isWithinCurveOrder:I}=Ie({...n,toBytes(l,w,g){const v=w.toAffine(),q=t.toBytes(v.x),U=gt;return ut("isCompressed",g),g?U(Uint8Array.from([w.hasEvenY()?2:3]),q):U(Uint8Array.from([4]),q,t.toBytes(v.y))},fromBytes(l){const w=l.length,g=l[0],v=l.subarray(1);if(w===s&&(g===2||g===3)){const q=et(v);if(!Ut(q,k,t.ORDER))throw new Error("Point is not on curve");const U=m(q);let _;try{_=t.sqrt(U)}catch(F){const M=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+M)}const C=(_&k)===k;return(g&1)===1!==C&&(_=t.neg(_)),{x:q,y:_}}else if(w===i&&g===4){const q=t.fromBytes(v.subarray(0,t.BYTES)),U=t.fromBytes(v.subarray(t.BYTES,2*t.BYTES));return{x:q,y:U}}else{const q=s,U=i;throw new Error("invalid Point, expected length of "+q+", or uncompressed "+U+", got "+w)}}}),d=l=>lt(dt(l,n.nByteLength));function S(l){const w=r>>k;return l>w}function L(l){return S(l)?c(-l):l}const p=(l,w,g)=>et(l.slice(w,g));class a{constructor(w,g,v){it("r",w,k,r),it("s",g,k,r),this.r=w,this.s=g,v!=null&&(this.recovery=v),Object.freeze(this)}static fromCompact(w){const g=n.nByteLength;return w=K("compactSignature",w,g*2),new a(p(w,0,g),p(w,g,2*g))}static fromDER(w){const{r:g,s:v}=$.toSig(K("DER",w));return new a(g,v)}assertValidity(){}addRecoveryBit(w){return new a(this.r,this.s,w)}recoverPublicKey(w){const{r:g,s:v,recovery:q}=this,U=A(K("msgHash",w));if(q==null||![0,1,2,3].includes(q))throw new Error("recovery id invalid");const _=q===2||q===3?g+n.n:g;if(_>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");const C=(q&1)===0?"02":"03",P=o.fromHex(C+d(_)),F=f(_),M=c(-U*F),nt=c(v*F),D=o.BASE.multiplyAndAddUnsafe(P,M,nt);if(!D)throw new Error("point at infinify");return D.assertValidity(),D}hasHighS(){return S(this.s)}normalizeS(){return this.hasHighS()?new a(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return wt(this.toDERHex())}toDERHex(){return $.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return wt(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}const h={isValidPrivateKey(l){try{return u(l),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const l=ee(n.n);return be(n.randomBytes(l),n.n)},precompute(l=8,w=o.BASE){return w._setWindowSize(l),w.multiply(BigInt(3)),w}};function y(l,w=!0){return o.fromPrivateKey(l).toRawBytes(w)}function b(l){const w=st(l),g=typeof l=="string",v=(w||g)&&l.length;return w?v===s||v===i:g?v===2*s||v===2*i:l instanceof o}function N(l,w,g=!0){if(b(l))throw new Error("first arg must be private key");if(!b(w))throw new Error("second arg must be public key");return o.fromHex(w).multiply(u(l)).toRawBytes(g)}const O=n.bits2int||function(l){if(l.length>8192)throw new Error("input is too large");const w=et(l),g=l.length*8-n.nBitLength;return g>0?w>>BigInt(g):w},A=n.bits2int_modN||function(l){return c(O(l))},E=pt(n.nBitLength);function x(l){return it("num < 2^"+n.nBitLength,l,X,E),dt(l,n.nByteLength)}function B(l,w,g=R){if(["recovered","canonical"].some(Q=>Q in g))throw new Error("sign() legacy options not supported");const{hash:v,randomBytes:q}=n;let{lowS:U,prehash:_,extraEntropy:C}=g;U==null&&(U=!0),l=K("msgHash",l),Vt(g),_&&(l=K("prehashed msgHash",v(l)));const P=A(l),F=u(w),M=[x(F),x(P)];if(C!=null&&C!==!1){const Q=C===!0?q(t.BYTES):C;M.push(K("extraEntropy",Q))}const nt=gt(...M),D=P;function mt(Q){const rt=O(Q);if(!I(rt))return;const bt=f(rt),ct=o.BASE.multiply(rt).toAffine(),J=c(ct.x);if(J===X)return;const ft=c(bt*c(D+J*F));if(ft===X)return;let at=(ct.x===J?0:2)|Number(ct.y&k),ot=ft;return U&&S(ft)&&(ot=L(ft),at^=1),new a(J,ot,at)}return{seed:nt,k2sig:mt}}const R={lowS:n.lowS,prehash:!1},Z={lowS:n.lowS,prehash:!1};function H(l,w,g=R){const{seed:v,k2sig:q}=B(l,w,g),U=n;return ae(U.hash.outputLen,U.nByteLength,U.hmac)(v,q)}o.BASE._setWindowSize(8);function V(l,w,g,v=Z){var at;const q=l;w=K("msgHash",w),g=K("publicKey",g);const{lowS:U,prehash:_,format:C}=v;if(Vt(v),"strict"in v)throw new Error("options.strict was renamed to lowS");if(C!==void 0&&C!=="compact"&&C!=="der")throw new Error("format must be compact or der");const P=typeof q=="string"||st(q),F=!P&&!C&&typeof q=="object"&&q!==null&&typeof q.r=="bigint"&&typeof q.s=="bigint";if(!P&&!F)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let M,nt;try{if(F&&(M=new a(q.r,q.s)),P){try{C!=="compact"&&(M=a.fromDER(q))}catch(ot){if(!(ot instanceof $.Err))throw ot}!M&&C!=="der"&&(M=a.fromCompact(q))}nt=o.fromHex(g)}catch{return!1}if(!M||U&&M.hasHighS())return!1;_&&(w=n.hash(w));const{r:D,s:mt}=M,Q=A(w),rt=f(mt),bt=c(Q*rt),ct=c(D*rt),J=(at=o.BASE.multiplyAndAddUnsafe(nt,bt,ct))==null?void 0:at.toAffine();return J?c(J.x)===D:!1}return{CURVE:n,getPublicKey:y,getSharedSecret:N,sign:H,verify:V,ProjectivePoint:o,Signature:a,utils:h}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Oe(e){return{hash:e,hmac:(n,...t)=>Wt(e,n,G.concatBytes(...t)),randomBytes:G.randomBytes}}function He(e,n){const t=r=>qe({...e,...Oe(r)});return{...t(n),create:t}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ie=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ft=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Le=BigInt(1),Ht=BigInt(2),Kt=(e,n)=>(e+n/Ht)/n;function Ze(e){const n=ie,t=BigInt(3),r=BigInt(6),s=BigInt(11),i=BigInt(22),c=BigInt(23),f=BigInt(44),o=BigInt(88),u=e*e*e%n,m=u*u*e%n,I=Y(m,t,n)*m%n,d=Y(I,t,n)*m%n,S=Y(d,Ht,n)*u%n,L=Y(S,s,n)*S%n,p=Y(L,i,n)*L%n,a=Y(p,f,n)*p%n,h=Y(a,o,n)*a%n,y=Y(h,f,n)*p%n,b=Y(y,t,n)*m%n,N=Y(b,c,n)*L%n,O=Y(N,r,n)*u%n,A=Y(O,Ht,n);if(!Lt.eql(Lt.sqr(A),e))throw new Error("Cannot find square root");return A}const Lt=Jt(ie,void 0,void 0,{sqrt:Ze}),se=He({a:BigInt(0),b:BigInt(7),Fp:Lt,n:Ft,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const n=Ft,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Le*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,c=BigInt("0x100000000000000000000000000000000"),f=Kt(i*e,n),o=Kt(-r*e,n);let u=j(e-f*t-o*s,n),m=j(-f*r-o*i,n);const I=u>c,d=m>c;if(I&&(u=n-u),d&&(m=n-m),u>c||m>c)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:I,k1:u,k2neg:d,k2:m}}}},G.sha256);BigInt(0);se.ProjectivePoint;exports.secp256k1=se;
//# sourceMappingURL=secp256k1-BxV6NE0K.cjs.map