UNPKG

starknetkit

Version:

<!-- logo --> <p align="center"> <img width='300' src="https://starknetkit-website-git-blo-1541-argentlabs.vercel.app/starknetKit-logo.svg"> </p>

2 lines (1 loc) 31.9 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./index-1c0d8f8b.cjs");require("./connector-e4ffe813.cjs");require("starknet");require("./Modal-0ef58a76.cjs");require("./trpc-23773a5d.cjs");require("./lastConnected-2e5632be.cjs");require("./index-7ba3f4da.cjs");require("./core-40df00f1.cjs");require("./argentX.cjs");require("./index-3ed0d8c7.cjs");require("./braavos.cjs");function he(n,e,t,r){if(typeof n.setBigUint64=="function")return n.setBigUint64(e,t,r);const i=BigInt(32),s=BigInt(4294967295),c=Number(t>>i&s),f=Number(t&s),o=r?4:0,l=r?0:4;n.setUint32(e+o,c,r),n.setUint32(e+l,f,r)}function we(n,e,t){return n&e^~n&t}function ge(n,e,t){return n&e^n&t^e&t}class pe extends N.Hash{constructor(e,t,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=N.createView(this.buffer)}update(e){N.aexists(this),e=N.toBytes(e),N.abytes(e);const{view:t,buffer:r,blockLen:i}=this,s=e.length;for(let c=0;c<s;){const f=Math.min(i-this.pos,s-c);if(f===i){const o=N.createView(e);for(;i<=s-c;c+=i)this.process(o,c);continue}r.set(e.subarray(c,c+f),this.pos),this.pos+=f,c+=f,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){N.aexists(this),N.aoutput(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:i,isLE:s}=this;let{pos:c}=this;t[c++]=128,N.clean(this.buffer.subarray(c)),this.padOffset>i-c&&(this.process(r,0),c=0);for(let h=c;h<i;h++)t[h]=0;he(r,i-8,BigInt(this.length*8),s),this.process(r,0);const f=N.createView(e),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=o/4,g=this.get();if(l>g.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<l;h++)f.setUint32(4*h,g[h],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:i,finished:s,destroyed:c,pos:f}=this;return e.destroyed=c,e.finished=s,e.length=i,e.pos=f,i%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const J=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),be=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),tt=new Uint32Array(64);class me extends pe{constructor(e=32){super(64,e,8,!1),this.A=J[0]|0,this.B=J[1]|0,this.C=J[2]|0,this.D=J[3]|0,this.E=J[4]|0,this.F=J[5]|0,this.G=J[6]|0,this.H=J[7]|0}get(){const{A:e,B:t,C:r,D:i,E:s,F:c,G:f,H:o}=this;return[e,t,r,i,s,c,f,o]}set(e,t,r,i,s,c,f,o){this.A=e|0,this.B=t|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=c|0,this.G=f|0,this.H=o|0}process(e,t){for(let h=0;h<16;h++,t+=4)tt[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){const B=tt[h-15],H=tt[h-2],R=N.rotr(B,7)^N.rotr(B,18)^B>>>3,p=N.rotr(H,17)^N.rotr(H,19)^H>>>10;tt[h]=p+tt[h-7]+R+tt[h-16]|0}let{A:r,B:i,C:s,D:c,E:f,F:o,G:l,H:g}=this;for(let h=0;h<64;h++){const B=N.rotr(f,6)^N.rotr(f,11)^N.rotr(f,25),H=g+B+we(f,o,l)+be[h]+tt[h]|0,p=(N.rotr(r,2)^N.rotr(r,13)^N.rotr(r,22))+ge(r,i,s)|0;g=l,l=o,o=f,f=c+H|0,c=s,s=i,i=r,r=H+p|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,c=c+this.D|0,f=f+this.E|0,o=o+this.F|0,l=l+this.G|0,g=g+this.H|0,this.set(r,i,s,c,f,o,l,g)}roundClean(){N.clean(tt)}destroy(){this.set(0,0,0,0,0,0,0,0),N.clean(this.buffer)}}const ye=N.createHasher(()=>new me);class $t extends N.Hash{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,N.ahash(e);const r=N.toBytes(t);if(this.iHash=e.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 i=this.blockLen,s=new Uint8Array(i);s.set(r.length>i?e.create().update(r).digest():r);for(let c=0;c<s.length;c++)s[c]^=54;this.iHash.update(s),this.oHash=e.create();for(let c=0;c<s.length;c++)s[c]^=106;this.oHash.update(s),N.clean(s)}update(e){return N.aexists(this),this.iHash.update(e),this}digestInto(e){N.aexists(this),N.abytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:r,finished:i,destroyed:s,blockLen:c,outputLen:f}=this;return e=e,e.finished=i,e.destroyed=s,e.blockLen=c,e.outputLen=f,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Ft=(n,e,t)=>new $t(n,e).update(t).digest();Ft.create=(n,e)=>new $t(n,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Tt=BigInt(0),Ht=BigInt(1);function ht(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function kt(n){if(!ht(n))throw new Error("Uint8Array expected")}function lt(n,e){if(typeof e!="boolean")throw new Error(n+" boolean expected, got "+e)}function gt(n){const e=n.toString(16);return e.length&1?"0"+e:e}function Xt(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);return n===""?Tt:BigInt("0x"+n)}const Qt=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",xe=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function dt(n){if(kt(n),Qt)return n.toHex();let e="";for(let t=0;t<n.length;t++)e+=xe[n[t]];return e}const $={_0:48,_9:57,A:65,F:70,a:97,f:102};function Vt(n){if(n>=$._0&&n<=$._9)return n-$._0;if(n>=$.A&&n<=$.F)return n-($.A-10);if(n>=$.a&&n<=$.f)return n-($.a-10)}function pt(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);if(Qt)return Uint8Array.fromHex(n);const e=n.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(t);for(let i=0,s=0;i<t;i++,s+=2){const c=Vt(n.charCodeAt(s)),f=Vt(n.charCodeAt(s+1));if(c===void 0||f===void 0){const o=n[s]+n[s+1];throw new Error('hex string expected, got non-hex character "'+o+'" at index '+s)}r[i]=c*16+f}return r}function ot(n){return Xt(dt(n))}function Jt(n){return kt(n),Xt(dt(Uint8Array.from(n).reverse()))}function wt(n,e){return pt(n.toString(16).padStart(e*2,"0"))}function te(n,e){return wt(n,e).reverse()}function P(n,e,t){let r;if(typeof e=="string")try{r=pt(e)}catch(s){throw new Error(n+" must be hex string or Uint8Array, cause: "+s)}else if(ht(e))r=Uint8Array.from(e);else throw new Error(n+" must be hex string or Uint8Array");const i=r.length;if(typeof t=="number"&&i!==t)throw new Error(n+" of length "+t+" expected, got "+i);return r}function bt(...n){let e=0;for(let r=0;r<n.length;r++){const i=n[r];kt(i),e+=i.length}const t=new Uint8Array(e);for(let r=0,i=0;r<n.length;r++){const s=n[r];t.set(s,i),i+=s.length}return t}const Bt=n=>typeof n=="bigint"&&Tt<=n;function Zt(n,e,t){return Bt(n)&&Bt(e)&&Bt(t)&&e<=n&&n<t}function ft(n,e,t,r){if(!Zt(e,t,r))throw new Error("expected valid "+n+": "+t+" <= n < "+r+", got "+e)}function Ee(n){let e;for(e=0;n>Tt;n>>=Ht,e+=1);return e}const mt=n=>(Ht<<BigInt(n))-Ht,vt=n=>new Uint8Array(n),Mt=n=>Uint8Array.from(n);function Be(n,e,t){if(typeof n!="number"||n<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let r=vt(n),i=vt(n),s=0;const c=()=>{r.fill(1),i.fill(0),s=0},f=(...h)=>t(i,r,...h),o=(h=vt(0))=>{i=f(Mt([0]),h),r=f(),h.length!==0&&(i=f(Mt([1]),h),r=f())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const B=[];for(;h<e;){r=f();const H=r.slice();B.push(H),h+=r.length}return bt(...B)};return(h,B)=>{c(),o(h);let H;for(;!(H=B(l()));)o();return c(),H}}const ve={bigint:n=>typeof n=="bigint",function:n=>typeof n=="function",boolean:n=>typeof n=="boolean",string:n=>typeof n=="string",stringOrUint8Array:n=>typeof n=="string"||ht(n),isSafeInteger:n=>Number.isSafeInteger(n),array:n=>Array.isArray(n),field:(n,e)=>e.Fp.isValid(n),hash:n=>typeof n=="function"&&Number.isSafeInteger(n.outputLen)};function yt(n,e,t={}){const r=(i,s,c)=>{const f=ve[s];if(typeof f!="function")throw new Error("invalid validator function");const o=n[i];if(!(c&&o===void 0)&&!f(o,n))throw new Error("param "+String(i)+" is invalid. Expected "+s+", got "+o)};for(const[i,s]of Object.entries(e))r(i,s,!1);for(const[i,s]of Object.entries(t))r(i,s,!0);return n}function jt(n){const e=new WeakMap;return(t,...r)=>{const i=e.get(t);if(i!==void 0)return i;const s=n(t,...r);return e.set(t,s),s}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Y=BigInt(0),V=BigInt(1),rt=BigInt(2),Se=BigInt(3),ee=BigInt(4),ne=BigInt(5),re=BigInt(8);function j(n,e){const t=n%e;return t>=Y?t:e+t}function K(n,e,t){let r=n;for(;e-- >Y;)r*=r,r%=t;return r}function Lt(n,e){if(n===Y)throw new Error("invert: expected non-zero number");if(e<=Y)throw new Error("invert: expected positive modulus, got "+e);let t=j(n,e),r=e,i=Y,s=V;for(;t!==Y;){const f=r/t,o=r%t,l=i-s*f;r=t,t=o,i=s,s=l}if(r!==V)throw new Error("invert: does not exist");return j(i,e)}function oe(n,e){const t=(n.ORDER+V)/ee,r=n.pow(e,t);if(!n.eql(n.sqr(r),e))throw new Error("Cannot find square root");return r}function Ae(n,e){const t=(n.ORDER-ne)/re,r=n.mul(e,rt),i=n.pow(r,t),s=n.mul(e,i),c=n.mul(n.mul(s,rt),i),f=n.mul(s,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),e))throw new Error("Cannot find square root");return f}function Ie(n){if(n<BigInt(3))throw new Error("sqrt is not defined for small field");let e=n-V,t=0;for(;e%rt===Y;)e/=rt,t++;let r=rt;const i=zt(n);for(;Yt(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return oe;let s=i.pow(r,e);const c=(e+V)/rt;return function(o,l){if(o.is0(l))return l;if(Yt(o,l)!==1)throw new Error("Cannot find square root");let g=t,h=o.mul(o.ONE,s),B=o.pow(l,e),H=o.pow(l,c);for(;!o.eql(B,o.ONE);){if(o.is0(B))return o.ZERO;let R=1,p=o.sqr(B);for(;!o.eql(p,o.ONE);)if(R++,p=o.sqr(p),R===g)throw new Error("Cannot find square root");const z=V<<BigInt(g-R-1),T=o.pow(h,z);g=R,h=o.sqr(T),B=o.mul(B,h),H=o.mul(H,T)}return H}}function qe(n){return n%ee===Se?oe:n%re===ne?Ae:Ie(n)}const Ne=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Oe(n){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Ne.reduce((r,i)=>(r[i]="function",r),e);return yt(n,t)}function He(n,e,t){if(t<Y)throw new Error("invalid exponent, negatives unsupported");if(t===Y)return n.ONE;if(t===V)return e;let r=n.ONE,i=e;for(;t>Y;)t&V&&(r=n.mul(r,i)),i=n.sqr(i),t>>=V;return r}function ie(n,e,t=!1){const r=new Array(e.length).fill(t?n.ZERO:void 0),i=e.reduce((c,f,o)=>n.is0(f)?c:(r[o]=c,n.mul(c,f)),n.ONE),s=n.inv(i);return e.reduceRight((c,f,o)=>n.is0(f)?c:(r[o]=n.mul(c,r[o]),n.mul(c,f)),s),r}function Yt(n,e){const t=(n.ORDER-V)/rt,r=n.pow(e,t),i=n.eql(r,n.ONE),s=n.eql(r,n.ZERO),c=n.eql(r,n.neg(n.ONE));if(!i&&!s&&!c)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function se(n,e){e!==void 0&&N.anumber(e);const t=e!==void 0?e:n.toString(2).length,r=Math.ceil(t/8);return{nBitLength:t,nByteLength:r}}function zt(n,e,t=!1,r={}){if(n<=Y)throw new Error("invalid field: expected ORDER > 0, got "+n);const{nBitLength:i,nByteLength:s}=se(n,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c;const f=Object.freeze({ORDER:n,isLE:t,BITS:i,BYTES:s,MASK:mt(i),ZERO:Y,ONE:V,create:o=>j(o,n),isValid:o=>{if(typeof o!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof o);return Y<=o&&o<n},is0:o=>o===Y,isOdd:o=>(o&V)===V,neg:o=>j(-o,n),eql:(o,l)=>o===l,sqr:o=>j(o*o,n),add:(o,l)=>j(o+l,n),sub:(o,l)=>j(o-l,n),mul:(o,l)=>j(o*l,n),pow:(o,l)=>He(f,o,l),div:(o,l)=>j(o*Lt(l,n),n),sqrN:o=>o*o,addN:(o,l)=>o+l,subN:(o,l)=>o-l,mulN:(o,l)=>o*l,inv:o=>Lt(o,n),sqrt:r.sqrt||(o=>(c||(c=qe(n)),c(f,o))),toBytes:o=>t?te(o,s):wt(o,s),fromBytes:o=>{if(o.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+o.length);return t?Jt(o):ot(o)},invertBatch:o=>ie(f,o),cmov:(o,l,g)=>g?l:o});return Object.freeze(f)}function ce(n){if(typeof n!="bigint")throw new Error("field order must be bigint");const e=n.toString(2).length;return Math.ceil(e/8)}function fe(n){const e=ce(n);return e+Math.ceil(e/2)}function Le(n,e,t=!1){const r=n.length,i=ce(e),s=fe(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const c=t?Jt(n):ot(n),f=j(c,e-V)+V;return t?te(f,i):wt(f,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Kt=BigInt(0),Ut=BigInt(1);function St(n,e){const t=e.negate();return n?t:e}function ae(n,e){if(!Number.isSafeInteger(n)||n<=0||n>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+n)}function At(n,e){ae(n,e);const t=Math.ceil(e/n)+1,r=2**(n-1),i=2**n,s=mt(n),c=BigInt(n);return{windows:t,windowSize:r,mask:s,maxNumber:i,shiftBy:c}}function Pt(n,e,t){const{windowSize:r,mask:i,maxNumber:s,shiftBy:c}=t;let f=Number(n&i),o=n>>c;f>r&&(f-=s,o+=Ut);const l=e*r,g=l+Math.abs(f)-1,h=f===0,B=f<0,H=e%2!==0;return{nextN:o,offset:g,isZero:h,isNeg:B,isNegF:H,offsetF:l}}function Ue(n,e){if(!Array.isArray(n))throw new Error("array expected");n.forEach((t,r)=>{if(!(t instanceof e))throw new Error("invalid point at index "+r)})}function _e(n,e){if(!Array.isArray(n))throw new Error("array of scalars expected");n.forEach((t,r)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+r)})}const It=new WeakMap,ue=new WeakMap;function qt(n){return ue.get(n)||1}function Re(n,e){return{constTimeNegate:St,hasPrecomputes(t){return qt(t)!==1},unsafeLadder(t,r,i=n.ZERO){let s=t;for(;r>Kt;)r&Ut&&(i=i.add(s)),s=s.double(),r>>=Ut;return i},precomputeWindow(t,r){const{windows:i,windowSize:s}=At(r,e),c=[];let f=t,o=f;for(let l=0;l<i;l++){o=f,c.push(o);for(let g=1;g<s;g++)o=o.add(f),c.push(o);f=o.double()}return c},wNAF(t,r,i){let s=n.ZERO,c=n.BASE;const f=At(t,e);for(let o=0;o<f.windows;o++){const{nextN:l,offset:g,isZero:h,isNeg:B,isNegF:H,offsetF:R}=Pt(i,o,f);i=l,h?c=c.add(St(H,r[R])):s=s.add(St(B,r[g]))}return{p:s,f:c}},wNAFUnsafe(t,r,i,s=n.ZERO){const c=At(t,e);for(let f=0;f<c.windows&&i!==Kt;f++){const{nextN:o,offset:l,isZero:g,isNeg:h}=Pt(i,f,c);if(i=o,!g){const B=r[l];s=s.add(h?B.negate():B)}}return s},getPrecomputes(t,r,i){let s=It.get(r);return s||(s=this.precomputeWindow(r,t),t!==1&&It.set(r,i(s))),s},wNAFCached(t,r,i){const s=qt(t);return this.wNAF(s,this.getPrecomputes(s,t,i),r)},wNAFCachedUnsafe(t,r,i,s){const c=qt(t);return c===1?this.unsafeLadder(t,r,s):this.wNAFUnsafe(c,this.getPrecomputes(c,t,i),r,s)},setWindowSize(t,r){ae(r,e),ue.set(t,r),It.delete(t)}}}function Te(n,e,t,r){Ue(t,n),_e(r,e);const i=t.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const c=n.ZERO,f=Ee(BigInt(i));let o=1;f>12?o=f-3:f>4?o=f-2:f>0&&(o=2);const l=mt(o),g=new Array(Number(l)+1).fill(c),h=Math.floor((e.BITS-1)/o)*o;let B=c;for(let H=h;H>=0;H-=o){g.fill(c);for(let p=0;p<s;p++){const z=r[p],T=Number(z>>BigInt(H)&l);g[T]=g[T].add(t[p])}let R=c;for(let p=g.length-1,z=c;p>0;p--)z=z.add(g[p]),R=R.add(z);if(B=B.add(R),H!==0)for(let p=0;p<o;p++)B=B.double()}return B}function le(n){return Oe(n.Fp),yt(n,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...se(n.n,n.nBitLength),...n,p:n.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Dt(n){n.lowS!==void 0&&lt("lowS",n.lowS),n.prehash!==void 0&&lt("prehash",n.prehash)}function ke(n){const e=le(n);yt(e,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});const{endo:t,Fp:r,a:i}=e;if(t){if(!r.eql(i,r.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...e})}class Ze extends Error{constructor(e=""){super(e)}}const F={Err:Ze,_tlv:{encode:(n,e)=>{const{Err:t}=F;if(n<0||n>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");const r=e.length/2,i=gt(r);if(i.length/2&128)throw new t("tlv.encode: long form length too big");const s=r>127?gt(i.length/2|128):"";return gt(n)+s+i+e},decode(n,e){const{Err:t}=F;let r=0;if(n<0||n>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[r++]!==n)throw new t("tlv.decode: wrong tlv");const i=e[r++],s=!!(i&128);let c=0;if(!s)c=i;else{const o=i&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 l=e.subarray(r,r+o);if(l.length!==o)throw new t("tlv.decode: length bytes not complete");if(l[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(const g of l)c=c<<8|g;if(r+=o,c<128)throw new t("tlv.decode(long): not minimal encoding")}const f=e.subarray(r,r+c);if(f.length!==c)throw new t("tlv.decode: wrong value length");return{v:f,l:e.subarray(r+c)}}},_int:{encode(n){const{Err:e}=F;if(n<X)throw new e("integer: negative integers are not allowed");let t=gt(n);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(n){const{Err:e}=F;if(n[0]&128)throw new e("invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ot(n)}},toSig(n){const{Err:e,_int:t,_tlv:r}=F,i=P("signature",n),{v:s,l:c}=r.decode(48,i);if(c.length)throw new e("invalid signature: left bytes after parsing");const{v:f,l:o}=r.decode(2,s),{v:l,l:g}=r.decode(2,o);if(g.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(f),s:t.decode(l)}},hexFromSig(n){const{_tlv:e,_int:t}=F,r=e.encode(2,t.encode(n.r)),i=e.encode(2,t.encode(n.s)),s=r+i;return e.encode(48,s)}};function Nt(n,e){return dt(wt(n,e))}const X=BigInt(0),k=BigInt(1);BigInt(2);const Ot=BigInt(3),ze=BigInt(4);function Ce(n){const e=ke(n),{Fp:t}=e,r=zt(e.n,e.nBitLength),i=e.toBytes||((A,a,w)=>{const m=a.toAffine();return bt(Uint8Array.from([4]),t.toBytes(m.x),t.toBytes(m.y))}),s=e.fromBytes||(A=>{const a=A.subarray(1),w=t.fromBytes(a.subarray(0,t.BYTES)),m=t.fromBytes(a.subarray(t.BYTES,2*t.BYTES));return{x:w,y:m}});function c(A){const{a,b:w}=e,m=t.sqr(A),v=t.mul(m,A);return t.add(t.add(v,t.mul(A,a)),w)}function f(A,a){const w=t.sqr(a),m=c(A);return t.eql(w,m)}if(!f(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const o=t.mul(t.pow(e.a,Ot),ze),l=t.mul(t.sqr(e.b),BigInt(27));if(t.is0(t.add(o,l)))throw new Error("bad curve params: a or b");function g(A){return Zt(A,k,e.n)}function h(A){const{allowedPrivateKeyLengths:a,nByteLength:w,wrapPrivateKey:m,n:v}=e;if(a&&typeof A!="bigint"){if(ht(A)&&(A=dt(A)),typeof A!="string"||!a.includes(A.length))throw new Error("invalid private key");A=A.padStart(w*2,"0")}let O;try{O=typeof A=="bigint"?A:ot(P("private key",A,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof A)}return m&&(O=j(O,v)),ft("private key",O,k,v),O}function B(A){if(!(A instanceof p))throw new Error("ProjectivePoint expected")}const H=jt((A,a)=>{const{px:w,py:m,pz:v}=A;if(t.eql(v,t.ONE))return{x:w,y:m};const O=A.is0();a==null&&(a=O?t.ONE:t.inv(v));const U=t.mul(w,a),L=t.mul(m,a),y=t.mul(v,a);if(O)return{x:t.ZERO,y:t.ZERO};if(!t.eql(y,t.ONE))throw new Error("invZ was invalid");return{x:U,y:L}}),R=jt(A=>{if(A.is0()){if(e.allowInfinityPoint&&!t.is0(A.py))return;throw new Error("bad point: ZERO")}const{x:a,y:w}=A.toAffine();if(!t.isValid(a)||!t.isValid(w))throw new Error("bad point: x or y not FE");if(!f(a,w))throw new Error("bad point: equation left != right");if(!A.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class p{constructor(a,w,m){if(a==null||!t.isValid(a))throw new Error("x required");if(w==null||!t.isValid(w)||t.is0(w))throw new Error("y required");if(m==null||!t.isValid(m))throw new Error("z required");this.px=a,this.py=w,this.pz=m,Object.freeze(this)}static fromAffine(a){const{x:w,y:m}=a||{};if(!a||!t.isValid(w)||!t.isValid(m))throw new Error("invalid affine point");if(a instanceof p)throw new Error("projective point not allowed");const v=O=>t.eql(O,t.ZERO);return v(w)&&v(m)?p.ZERO:new p(w,m,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(a){const w=ie(t,a.map(m=>m.pz));return a.map((m,v)=>m.toAffine(w[v])).map(p.fromAffine)}static fromHex(a){const w=p.fromAffine(s(P("pointHex",a)));return w.assertValidity(),w}static fromPrivateKey(a){return p.BASE.multiply(h(a))}static msm(a,w){return Te(p,r,a,w)}_setWindowSize(a){G.setWindowSize(this,a)}assertValidity(){R(this)}hasEvenY(){const{y:a}=this.toAffine();if(t.isOdd)return!t.isOdd(a);throw new Error("Field doesn't support isOdd")}equals(a){B(a);const{px:w,py:m,pz:v}=this,{px:O,py:U,pz:L}=a,y=t.eql(t.mul(w,L),t.mul(O,v)),q=t.eql(t.mul(m,L),t.mul(U,v));return y&&q}negate(){return new p(this.px,t.neg(this.py),this.pz)}double(){const{a,b:w}=e,m=t.mul(w,Ot),{px:v,py:O,pz:U}=this;let L=t.ZERO,y=t.ZERO,q=t.ZERO,x=t.mul(v,v),Z=t.mul(O,O),d=t.mul(U,U),u=t.mul(v,O);return u=t.add(u,u),q=t.mul(v,U),q=t.add(q,q),L=t.mul(a,q),y=t.mul(m,d),y=t.add(L,y),L=t.sub(Z,y),y=t.add(Z,y),y=t.mul(L,y),L=t.mul(u,L),q=t.mul(m,q),d=t.mul(a,d),u=t.sub(x,d),u=t.mul(a,u),u=t.add(u,q),q=t.add(x,x),x=t.add(q,x),x=t.add(x,d),x=t.mul(x,u),y=t.add(y,x),d=t.mul(O,U),d=t.add(d,d),x=t.mul(d,u),L=t.sub(L,x),q=t.mul(d,Z),q=t.add(q,q),q=t.add(q,q),new p(L,y,q)}add(a){B(a);const{px:w,py:m,pz:v}=this,{px:O,py:U,pz:L}=a;let y=t.ZERO,q=t.ZERO,x=t.ZERO;const Z=e.a,d=t.mul(e.b,Ot);let u=t.mul(w,O),b=t.mul(m,U),I=t.mul(v,L),E=t.add(w,m),S=t.add(O,U);E=t.mul(E,S),S=t.add(u,b),E=t.sub(E,S),S=t.add(w,v);let _=t.add(O,L);return S=t.mul(S,_),_=t.add(u,I),S=t.sub(S,_),_=t.add(m,v),y=t.add(U,L),_=t.mul(_,y),y=t.add(b,I),_=t.sub(_,y),x=t.mul(Z,S),y=t.mul(d,I),x=t.add(y,x),y=t.sub(b,x),x=t.add(b,x),q=t.mul(y,x),b=t.add(u,u),b=t.add(b,u),I=t.mul(Z,I),S=t.mul(d,S),b=t.add(b,I),I=t.sub(u,I),I=t.mul(Z,I),S=t.add(S,I),u=t.mul(b,S),q=t.add(q,u),u=t.mul(_,S),y=t.mul(E,y),y=t.sub(y,u),u=t.mul(E,b),x=t.mul(_,x),x=t.add(x,u),new p(y,q,x)}subtract(a){return this.add(a.negate())}is0(){return this.equals(p.ZERO)}wNAF(a){return G.wNAFCached(this,a,p.normalizeZ)}multiplyUnsafe(a){const{endo:w,n:m}=e;ft("scalar",a,X,m);const v=p.ZERO;if(a===X)return v;if(this.is0()||a===k)return this;if(!w||G.hasPrecomputes(this))return G.wNAFCachedUnsafe(this,a,p.normalizeZ);let{k1neg:O,k1:U,k2neg:L,k2:y}=w.splitScalar(a),q=v,x=v,Z=this;for(;U>X||y>X;)U&k&&(q=q.add(Z)),y&k&&(x=x.add(Z)),Z=Z.double(),U>>=k,y>>=k;return O&&(q=q.negate()),L&&(x=x.negate()),x=new p(t.mul(x.px,w.beta),x.py,x.pz),q.add(x)}multiply(a){const{endo:w,n:m}=e;ft("scalar",a,k,m);let v,O;if(w){const{k1neg:U,k1:L,k2neg:y,k2:q}=w.splitScalar(a);let{p:x,f:Z}=this.wNAF(L),{p:d,f:u}=this.wNAF(q);x=G.constTimeNegate(U,x),d=G.constTimeNegate(y,d),d=new p(t.mul(d.px,w.beta),d.py,d.pz),v=x.add(d),O=Z.add(u)}else{const{p:U,f:L}=this.wNAF(a);v=U,O=L}return p.normalizeZ([v,O])[0]}multiplyAndAddUnsafe(a,w,m){const v=p.BASE,O=(L,y)=>y===X||y===k||!L.equals(v)?L.multiplyUnsafe(y):L.multiply(y),U=O(this,w).add(O(a,m));return U.is0()?void 0:U}toAffine(a){return H(this,a)}isTorsionFree(){const{h:a,isTorsionFree:w}=e;if(a===k)return!0;if(w)return w(p,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:a,clearCofactor:w}=e;return a===k?this:w?w(p,this):this.multiplyUnsafe(e.h)}toRawBytes(a=!0){return lt("isCompressed",a),this.assertValidity(),i(p,this,a)}toHex(a=!0){return lt("isCompressed",a),dt(this.toRawBytes(a))}}p.BASE=new p(e.Gx,e.Gy,t.ONE),p.ZERO=new p(t.ZERO,t.ONE,t.ZERO);const{endo:z,nBitLength:T}=e,G=Re(p,z?Math.ceil(T/2):T);return{CURVE:e,ProjectivePoint:p,normPrivateKeyToScalar:h,weierstrassEquation:c,isWithinCurveOrder:g}}function Ve(n){const e=le(n);return yt(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Me(n){const e=Ve(n),{Fp:t,n:r,nByteLength:i,nBitLength:s}=e,c=t.BYTES+1,f=2*t.BYTES+1;function o(d){return j(d,r)}function l(d){return Lt(d,r)}const{ProjectivePoint:g,normPrivateKeyToScalar:h,weierstrassEquation:B,isWithinCurveOrder:H}=Ce({...e,toBytes(d,u,b){const I=u.toAffine(),E=t.toBytes(I.x),S=bt;return lt("isCompressed",b),b?S(Uint8Array.from([u.hasEvenY()?2:3]),E):S(Uint8Array.from([4]),E,t.toBytes(I.y))},fromBytes(d){const u=d.length,b=d[0],I=d.subarray(1);if(u===c&&(b===2||b===3)){const E=ot(I);if(!Zt(E,k,t.ORDER))throw new Error("Point is not on curve");const S=B(E);let _;try{_=t.sqrt(S)}catch(D){const M=D instanceof Error?": "+D.message:"";throw new Error("Point is not on curve"+M)}const C=(_&k)===k;return(b&1)===1!==C&&(_=t.neg(_)),{x:E,y:_}}else if(u===f&&b===4){const E=t.fromBytes(I.subarray(0,t.BYTES)),S=t.fromBytes(I.subarray(t.BYTES,2*t.BYTES));return{x:E,y:S}}else{const E=c,S=f;throw new Error("invalid Point, expected length of "+E+", or uncompressed "+S+", got "+u)}}});function R(d){const u=r>>k;return d>u}function p(d){return R(d)?o(-d):d}const z=(d,u,b)=>ot(d.slice(u,b));class T{constructor(u,b,I){ft("r",u,k,r),ft("s",b,k,r),this.r=u,this.s=b,I!=null&&(this.recovery=I),Object.freeze(this)}static fromCompact(u){const b=i;return u=P("compactSignature",u,b*2),new T(z(u,0,b),z(u,b,2*b))}static fromDER(u){const{r:b,s:I}=F.toSig(P("DER",u));return new T(b,I)}assertValidity(){}addRecoveryBit(u){return new T(this.r,this.s,u)}recoverPublicKey(u){const{r:b,s:I,recovery:E}=this,S=v(P("msgHash",u));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");const _=E===2||E===3?b+e.n:b;if(_>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");const C=E&1?"03":"02",W=g.fromHex(C+Nt(_,t.BYTES)),D=l(_),M=o(-S*D),it=o(I*D),Q=g.BASE.multiplyAndAddUnsafe(W,M,it);if(!Q)throw new Error("point at infinify");return Q.assertValidity(),Q}hasHighS(){return R(this.s)}normalizeS(){return this.hasHighS()?new T(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return pt(this.toDERHex())}toDERHex(){return F.hexFromSig(this)}toCompactRawBytes(){return pt(this.toCompactHex())}toCompactHex(){const u=i;return Nt(this.r,u)+Nt(this.s,u)}}const G={isValidPrivateKey(d){try{return h(d),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const d=fe(e.n);return Le(e.randomBytes(d),e.n)},precompute(d=8,u=g.BASE){return u._setWindowSize(d),u.multiply(BigInt(3)),u}};function A(d,u=!0){return g.fromPrivateKey(d).toRawBytes(u)}function a(d){if(typeof d=="bigint")return!1;if(d instanceof g)return!0;const b=P("key",d).length,I=t.BYTES,E=I+1,S=2*I+1;if(!(e.allowedPrivateKeyLengths||i===E))return b===E||b===S}function w(d,u,b=!0){if(a(d)===!0)throw new Error("first arg must be private key");if(a(u)===!1)throw new Error("second arg must be public key");return g.fromHex(u).multiply(h(d)).toRawBytes(b)}const m=e.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");const u=ot(d),b=d.length*8-s;return b>0?u>>BigInt(b):u},v=e.bits2int_modN||function(d){return o(m(d))},O=mt(s);function U(d){return ft("num < 2^"+s,d,X,O),wt(d,i)}function L(d,u,b=y){if(["recovered","canonical"].some(et=>et in b))throw new Error("sign() legacy options not supported");const{hash:I,randomBytes:E}=e;let{lowS:S,prehash:_,extraEntropy:C}=b;S==null&&(S=!0),d=P("msgHash",d),Dt(b),_&&(d=P("prehashed msgHash",I(d)));const W=v(d),D=h(u),M=[U(D),U(W)];if(C!=null&&C!==!1){const et=C===!0?E(t.BYTES):C;M.push(P("extraEntropy",et))}const it=bt(...M),Q=W;function xt(et){const st=m(et);if(!H(st))return;const Et=l(st),at=g.BASE.multiply(st).toAffine(),nt=o(at.x);if(nt===X)return;const ut=o(Et*o(Q+nt*D));if(ut===X)return;let ct=(at.x===nt?0:2)|Number(at.y&k),Ct=ut;return S&&R(ut)&&(Ct=p(ut),ct^=1),new T(nt,Ct,ct)}return{seed:it,k2sig:xt}}const y={lowS:e.lowS,prehash:!1},q={lowS:e.lowS,prehash:!1};function x(d,u,b=y){const{seed:I,k2sig:E}=L(d,u,b),S=e;return Be(S.hash.outputLen,S.nByteLength,S.hmac)(I,E)}g.BASE._setWindowSize(8);function Z(d,u,b,I=q){const E=d;u=P("msgHash",u),b=P("publicKey",b);const{lowS:S,prehash:_,format:C}=I;if(Dt(I),"strict"in I)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 W=typeof E=="string"||ht(E),D=!W&&!C&&typeof E=="object"&&E!==null&&typeof E.r=="bigint"&&typeof E.s=="bigint";if(!W&&!D)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let M,it;try{if(D&&(M=new T(E.r,E.s)),W){try{C!=="compact"&&(M=T.fromDER(E))}catch(ct){if(!(ct instanceof F.Err))throw ct}!M&&C!=="der"&&(M=T.fromCompact(E))}it=g.fromHex(b)}catch{return!1}if(!M||S&&M.hasHighS())return!1;_&&(u=e.hash(u));const{r:Q,s:xt}=M,et=v(u),st=l(xt),Et=o(et*st),at=o(Q*st),nt=g.BASE.multiplyAndAddUnsafe(it,Et,at)?.toAffine();return nt?o(nt.x)===Q:!1}return{CURVE:e,getPublicKey:A,getSharedSecret:w,sign:x,verify:Z,ProjectivePoint:g,Signature:T,utils:G}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function je(n){return{hash:n,hmac:(e,...t)=>Ft(n,e,N.concatBytes(...t)),randomBytes:N.randomBytes}}function Ye(n,e){const t=r=>Me({...n,...je(r)});return{...t(e),create:t}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const de=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Gt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ke=BigInt(0),Pe=BigInt(1),_t=BigInt(2),Wt=(n,e)=>(n+e/_t)/e;function De(n){const e=de,t=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),c=BigInt(23),f=BigInt(44),o=BigInt(88),l=n*n*n%e,g=l*l*n%e,h=K(g,t,e)*g%e,B=K(h,t,e)*g%e,H=K(B,_t,e)*l%e,R=K(H,i,e)*H%e,p=K(R,s,e)*R%e,z=K(p,f,e)*p%e,T=K(z,o,e)*z%e,G=K(T,f,e)*p%e,A=K(G,t,e)*g%e,a=K(A,c,e)*R%e,w=K(a,r,e)*l%e,m=K(w,_t,e);if(!Rt.eql(Rt.sqr(m),n))throw new Error("Cannot find square root");return m}const Rt=zt(de,void 0,void 0,{sqrt:De}),Ge=Ye({a:Ke,b:BigInt(7),Fp:Rt,n:Gt,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:n=>{const e=Gt,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Pe*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=t,c=BigInt("0x100000000000000000000000000000000"),f=Wt(s*n,e),o=Wt(-r*n,e);let l=j(n-f*t-o*i,e),g=j(-f*r-o*s,e);const h=l>c,B=g>c;if(h&&(l=e-l),B&&(g=e-g),l>c||g>c)throw new Error("splitScalar: Endomorphism failed, k="+n);return{k1neg:h,k1:l,k2neg:B,k2:g}}}},ye);exports.secp256k1=Ge;