UNPKG

@avalanche-sdk/client

Version:

A TypeScript SDK for interacting with the Avalanche network through JSON-RPC APIs. This SDK provides a comprehensive set of tools to interact with all Avalanche chains (P-Chain, X-Chain, C-Chain) and various APIs, including wallet functionality for transa

13 lines 342 kB
import*as n from"node:crypto";import{secp256k1 as e,utils as t,Int as r}from"@avalabs/avalanchejs";import{toHex as o}from"viem";const a=n&&"object"==typeof n&&"webcrypto"in n?n.webcrypto:n&&"object"==typeof n&&"randomBytes"in n?n:void 0; /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function i(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name}function s(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("positive integer expected, got "+n)}function c(n,...e){if(!i(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error("Uint8Array expected of length "+e+", got length="+n.length)}function l(n){if("function"!=typeof n||"function"!=typeof n.create)throw new Error("Hash should be wrapped by utils.createHasher");s(n.outputLen),s(n.blockLen)}function u(n,e=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(e&&n.finished)throw new Error("Hash#digest() has already been called")}function d(...n){for(let e=0;e<n.length;e++)n[e].fill(0)}function p(n){return new DataView(n.buffer,n.byteOffset,n.byteLength)}function h(n,e){return n<<32-e|n>>>e}function f(n,e){return n<<e|n>>>32-e>>>0}const m=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),g=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function b(n){if(c(n),m)return n.toHex();let e="";for(let t=0;t<n.length;t++)e+=g[n[t]];return e}const v=48,y=57,w=65,k=70,x=97,z=102;function E(n){return n>=v&&n<=y?n-v:n>=w&&n<=k?n-(w-10):n>=x&&n<=z?n-(x-10):void 0}function j(n){if("string"!=typeof n)throw new Error("hex string expected, got "+typeof n);if(m)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 e=0,o=0;e<t;e++,o+=2){const t=E(n.charCodeAt(o)),a=E(n.charCodeAt(o+1));if(void 0===t||void 0===a){const e=n[o]+n[o+1];throw new Error('hex string expected, got non-hex character "'+e+'" at index '+o)}r[e]=16*t+a}return r}function B(n){if("string"!=typeof n)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(n))}function A(n){return"string"==typeof n&&(n=B(n)),c(n),n}function I(...n){let e=0;for(let t=0;t<n.length;t++){const r=n[t];c(r),e+=r.length}const t=new Uint8Array(e);for(let e=0,r=0;e<n.length;e++){const o=n[e];t.set(o,r),r+=o.length}return t}let q=class{};function U(n){const e=e=>n().update(A(e)).digest(),t=n();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>n(),e}function S(n=32){if(a&&"function"==typeof a.getRandomValues)return a.getRandomValues(new Uint8Array(n));if(a&&"function"==typeof a.randomBytes)return Uint8Array.from(a.randomBytes(n));throw new Error("crypto.getRandomValues must be defined")} /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const O=BigInt(0),R=BigInt(1);function L(n,e=""){if("boolean"!=typeof n){throw new Error((e&&`"${e}"`)+"expected boolean, got type="+typeof n)}return n}function P(n,e,t=""){const r=i(n),o=n?.length,a=void 0!==e;if(!r||a&&o!==e){throw new Error((t&&`"${t}" `)+"expected Uint8Array"+(a?` of length ${e}`:"")+", got "+(r?`length=${o}`:"type="+typeof n))}return n}function N(n){const e=n.toString(16);return 1&e.length?"0"+e:e}function H(n){if("string"!=typeof n)throw new Error("hex string expected, got "+typeof n);return""===n?O:BigInt("0x"+n)}function $(n){return H(b(n))}function F(n){return c(n),H(b(Uint8Array.from(n).reverse()))}function C(n,e){return j(n.toString(16).padStart(2*e,"0"))}function K(n,e){return C(n,e).reverse()}function T(n,e,t){let r;if("string"==typeof e)try{r=j(e)}catch(e){throw new Error(n+" must be hex string or Uint8Array, cause: "+e)}else{if(!i(e))throw new Error(n+" must be hex string or Uint8Array");r=Uint8Array.from(e)}return r.length,r}const V=n=>"bigint"==typeof n&&O<=n;function D(n,e,t,r){if(!function(n,e,t){return V(n)&&V(e)&&V(t)&&e<=n&&n<t}(e,t,r))throw new Error("expected valid "+n+": "+t+" <= n < "+r+", got "+e)}function G(n){let e;for(e=0;n>O;n>>=R,e+=1);return e}const M=n=>(R<<BigInt(n))-R;function Z(n,e,t={}){if(!n||"object"!=typeof n)throw new Error("expected valid options object");function r(e,t,r){const o=n[e];if(r&&void 0===o)return;const a=typeof o;if(a!==t||null===o)throw new Error(`param "${e}" is invalid: expected ${t}, got ${a}`)}Object.entries(e).forEach(([n,e])=>r(n,e,!1)),Object.entries(t).forEach(([n,e])=>r(n,e,!0))}function _(n){const e=new WeakMap;return(t,...r)=>{const o=e.get(t);if(void 0!==o)return o;const a=n(t,...r);return e.set(t,a),a}} /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Y=BigInt(0),W=BigInt(1),X=BigInt(2),J=BigInt(3),Q=BigInt(4),nn=BigInt(5),en=BigInt(7),tn=BigInt(8),rn=BigInt(9),on=BigInt(16);function an(n,e){const t=n%e;return t>=Y?t:e+t}function sn(n,e,t){let r=n;for(;e-- >Y;)r*=r,r%=t;return r}function cn(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=an(n,e),r=e,o=Y,a=W;for(;t!==Y;){const n=r%t,e=o-a*(r/t);r=t,t=n,o=a,a=e}if(r!==W)throw new Error("invert: does not exist");return an(o,e)}function ln(n,e,t){if(!n.eql(n.sqr(e),t))throw new Error("Cannot find square root")}function un(n,e){const t=(n.ORDER+W)/Q,r=n.pow(e,t);return ln(n,r,e),r}function dn(n,e){const t=(n.ORDER-nn)/tn,r=n.mul(e,X),o=n.pow(r,t),a=n.mul(e,o),i=n.mul(n.mul(a,X),o),s=n.mul(a,n.sub(i,n.ONE));return ln(n,s,e),s}function pn(n){if(n<J)throw new Error("sqrt is not defined for small field");let e=n-W,t=0;for(;e%X===Y;)e/=X,t++;let r=X;const o=vn(n);for(;1===gn(o,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===t)return un;let a=o.pow(r,e);const i=(e+W)/X;return function(n,r){if(n.is0(r))return r;if(1!==gn(n,r))throw new Error("Cannot find square root");let o=t,s=n.mul(n.ONE,a),c=n.pow(r,e),l=n.pow(r,i);for(;!n.eql(c,n.ONE);){if(n.is0(c))return n.ZERO;let e=1,t=n.sqr(c);for(;!n.eql(t,n.ONE);)if(e++,t=n.sqr(t),e===o)throw new Error("Cannot find square root");const r=W<<BigInt(o-e-1),a=n.pow(s,r);o=e,s=n.sqr(a),c=n.mul(c,s),l=n.mul(l,a)}return l}}function hn(n){return n%Q===J?un:n%tn===nn?dn:n%on===rn?function(n){const e=vn(n),t=pn(n),r=t(e,e.neg(e.ONE)),o=t(e,r),a=t(e,e.neg(r)),i=(n+en)/on;return(n,e)=>{let t=n.pow(e,i),s=n.mul(t,r);const c=n.mul(t,o),l=n.mul(t,a),u=n.eql(n.sqr(s),e),d=n.eql(n.sqr(c),e);t=n.cmov(t,s,u),s=n.cmov(l,c,d);const p=n.eql(n.sqr(s),e),h=n.cmov(t,s,p);return ln(n,h,e),h}}(n):pn(n)}const fn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function mn(n,e,t=!1){const r=new Array(e.length).fill(t?n.ZERO:void 0),o=e.reduce((e,t,o)=>n.is0(t)?e:(r[o]=e,n.mul(e,t)),n.ONE),a=n.inv(o);return e.reduceRight((e,t,o)=>n.is0(t)?e:(r[o]=n.mul(e,r[o]),n.mul(e,t)),a),r}function gn(n,e){const t=(n.ORDER-W)/X,r=n.pow(e,t),o=n.eql(r,n.ONE),a=n.eql(r,n.ZERO),i=n.eql(r,n.neg(n.ONE));if(!o&&!a&&!i)throw new Error("invalid Legendre symbol result");return o?1:a?0:-1}function bn(n,e){void 0!==e&&s(e);const t=void 0!==e?e:n.toString(2).length;return{nBitLength:t,nByteLength:Math.ceil(t/8)}}function vn(n,e,t=!1,r={}){if(n<=Y)throw new Error("invalid field: expected ORDER > 0, got "+n);let o,a,i,s=!1;if("object"==typeof e&&null!=e){if(r.sqrt||t)throw new Error("cannot specify opts in two arguments");const n=e;n.BITS&&(o=n.BITS),n.sqrt&&(a=n.sqrt),"boolean"==typeof n.isLE&&(t=n.isLE),"boolean"==typeof n.modFromBytes&&(s=n.modFromBytes),i=n.allowedLengths}else"number"==typeof e&&(o=e),r.sqrt&&(a=r.sqrt);const{nBitLength:c,nByteLength:l}=bn(n,o);if(l>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u;const d=Object.freeze({ORDER:n,isLE:t,BITS:c,BYTES:l,MASK:M(c),ZERO:Y,ONE:W,allowedLengths:i,create:e=>an(e,n),isValid:e=>{if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return Y<=e&&e<n},is0:n=>n===Y,isValidNot0:n=>!d.is0(n)&&d.isValid(n),isOdd:n=>(n&W)===W,neg:e=>an(-e,n),eql:(n,e)=>n===e,sqr:e=>an(e*e,n),add:(e,t)=>an(e+t,n),sub:(e,t)=>an(e-t,n),mul:(e,t)=>an(e*t,n),pow:(n,e)=>function(n,e,t){if(t<Y)throw new Error("invalid exponent, negatives unsupported");if(t===Y)return n.ONE;if(t===W)return e;let r=n.ONE,o=e;for(;t>Y;)t&W&&(r=n.mul(r,o)),o=n.sqr(o),t>>=W;return r}(d,n,e),div:(e,t)=>an(e*cn(t,n),n),sqrN:n=>n*n,addN:(n,e)=>n+e,subN:(n,e)=>n-e,mulN:(n,e)=>n*e,inv:e=>cn(e,n),sqrt:a||(e=>(u||(u=hn(n)),u(d,e))),toBytes:n=>t?K(n,l):C(n,l),fromBytes:(e,r=!0)=>{if(i){if(!i.includes(e.length)||e.length>l)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);const n=new Uint8Array(l);n.set(e,t?0:n.length-e.length),e=n}if(e.length!==l)throw new Error("Field.fromBytes: expected "+l+" bytes, got "+e.length);let o=t?F(e):$(e);if(s&&(o=an(o,n)),!r&&!d.isValid(o))throw new Error("invalid field element: outside of range 0..ORDER");return o},invertBatch:n=>mn(d,n),cmov:(n,e,t)=>t?e:n});return Object.freeze(d)}function yn(n){if("bigint"!=typeof n)throw new Error("field order must be bigint");const e=n.toString(2).length;return Math.ceil(e/8)}function wn(n){const e=yn(n);return e+Math.ceil(e/2)}function kn(n,e,t){return n&e^~n&t}function xn(n,e,t){return n&e^n&t^e&t}let zn=class extends q{constructor(n,e,t,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=n,this.outputLen=e,this.padOffset=t,this.isLE=r,this.buffer=new Uint8Array(n),this.view=p(this.buffer)}update(n){u(this),c(n=A(n));const{view:e,buffer:t,blockLen:r}=this,o=n.length;for(let a=0;a<o;){const i=Math.min(r-this.pos,o-a);if(i===r){const e=p(n);for(;r<=o-a;a+=r)this.process(e,a);continue}t.set(n.subarray(a,a+i),this.pos),this.pos+=i,a+=i,this.pos===r&&(this.process(e,0),this.pos=0)}return this.length+=n.length,this.roundClean(),this}digestInto(n){u(this),function(n,e){c(n);const t=e.outputLen;if(n.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}(n,this),this.finished=!0;const{buffer:e,view:t,blockLen:r,isLE:o}=this;let{pos:a}=this;e[a++]=128,d(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(t,0),a=0);for(let n=a;n<r;n++)e[n]=0;!function(n,e,t,r){if("function"==typeof n.setBigUint64)return n.setBigUint64(e,t,r);const o=BigInt(32),a=BigInt(4294967295),i=Number(t>>o&a),s=Number(t&a),c=r?4:0,l=r?0:4;n.setUint32(e+c,i,r),n.setUint32(e+l,s,r)}(t,r-8,BigInt(8*this.length),o),this.process(t,0);const i=p(n),s=this.outputLen;if(s%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=s/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let n=0;n<l;n++)i.setUint32(4*n,h[n],o)}digest(){const{buffer:n,outputLen:e}=this;this.digestInto(n);const t=n.slice(0,e);return this.destroy(),t}_cloneInto(n){n||(n=new this.constructor),n.set(...this.get());const{blockLen:e,buffer:t,length:r,finished:o,destroyed:a,pos:i}=this;return n.destroyed=a,n.finished=o,n.length=r,n.pos=i,r%e&&n.buffer.set(t),n}clone(){return this._cloneInto()}};const En=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),jn=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Bn=BigInt(2**32-1),An=BigInt(32);function In(n,e=!1){return e?{h:Number(n&Bn),l:Number(n>>An&Bn)}:{h:0|Number(n>>An&Bn),l:0|Number(n&Bn)}}const qn=(n,e,t)=>n>>>t,Un=(n,e,t)=>n<<32-t|e>>>t,Sn=(n,e,t)=>n>>>t|e<<32-t,On=(n,e,t)=>n<<32-t|e>>>t,Rn=(n,e,t)=>n<<64-t|e>>>t-32,Ln=(n,e,t)=>n>>>t-32|e<<64-t;function Pn(n,e,t,r){const o=(e>>>0)+(r>>>0);return{h:n+t+(o/2**32|0)|0,l:0|o}}const Nn=(n,e,t)=>(n>>>0)+(e>>>0)+(t>>>0),Hn=(n,e,t,r)=>e+t+r+(n/2**32|0)|0,$n=(n,e,t,r)=>(n>>>0)+(e>>>0)+(t>>>0)+(r>>>0),Fn=(n,e,t,r,o)=>e+t+r+o+(n/2**32|0)|0,Cn=(n,e,t,r,o)=>(n>>>0)+(e>>>0)+(t>>>0)+(r>>>0)+(o>>>0),Kn=(n,e,t,r,o,a)=>e+t+r+o+a+(n/2**32|0)|0,Tn=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]),Vn=new Uint32Array(64);let Dn=class extends zn{constructor(n=32){super(64,n,8,!1),this.A=0|En[0],this.B=0|En[1],this.C=0|En[2],this.D=0|En[3],this.E=0|En[4],this.F=0|En[5],this.G=0|En[6],this.H=0|En[7]}get(){const{A:n,B:e,C:t,D:r,E:o,F:a,G:i,H:s}=this;return[n,e,t,r,o,a,i,s]}set(n,e,t,r,o,a,i,s){this.A=0|n,this.B=0|e,this.C=0|t,this.D=0|r,this.E=0|o,this.F=0|a,this.G=0|i,this.H=0|s}process(n,e){for(let t=0;t<16;t++,e+=4)Vn[t]=n.getUint32(e,!1);for(let n=16;n<64;n++){const e=Vn[n-15],t=Vn[n-2],r=h(e,7)^h(e,18)^e>>>3,o=h(t,17)^h(t,19)^t>>>10;Vn[n]=o+Vn[n-7]+r+Vn[n-16]|0}let{A:t,B:r,C:o,D:a,E:i,F:s,G:c,H:l}=this;for(let n=0;n<64;n++){const e=l+(h(i,6)^h(i,11)^h(i,25))+kn(i,s,c)+Tn[n]+Vn[n]|0,u=(h(t,2)^h(t,13)^h(t,22))+xn(t,r,o)|0;l=c,c=s,s=i,i=a+e|0,a=o,o=r,r=t,t=e+u|0}t=t+this.A|0,r=r+this.B|0,o=o+this.C|0,a=a+this.D|0,i=i+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(t,r,o,a,i,s,c,l)}roundClean(){d(Vn)}destroy(){this.set(0,0,0,0,0,0,0,0),d(this.buffer)}};const Gn=(()=>function(n,e=!1){const t=n.length;let r=new Uint32Array(t),o=new Uint32Array(t);for(let a=0;a<t;a++){const{h:t,l:i}=In(n[a],e);[r[a],o[a]]=[t,i]}return[r,o]}(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(n=>BigInt(n))))(),Mn=(()=>Gn[0])(),Zn=(()=>Gn[1])(),_n=new Uint32Array(80),Yn=new Uint32Array(80);let Wn=class extends zn{constructor(n=64){super(128,n,16,!1),this.Ah=0|jn[0],this.Al=0|jn[1],this.Bh=0|jn[2],this.Bl=0|jn[3],this.Ch=0|jn[4],this.Cl=0|jn[5],this.Dh=0|jn[6],this.Dl=0|jn[7],this.Eh=0|jn[8],this.El=0|jn[9],this.Fh=0|jn[10],this.Fl=0|jn[11],this.Gh=0|jn[12],this.Gl=0|jn[13],this.Hh=0|jn[14],this.Hl=0|jn[15]}get(){const{Ah:n,Al:e,Bh:t,Bl:r,Ch:o,Cl:a,Dh:i,Dl:s,Eh:c,El:l,Fh:u,Fl:d,Gh:p,Gl:h,Hh:f,Hl:m}=this;return[n,e,t,r,o,a,i,s,c,l,u,d,p,h,f,m]}set(n,e,t,r,o,a,i,s,c,l,u,d,p,h,f,m){this.Ah=0|n,this.Al=0|e,this.Bh=0|t,this.Bl=0|r,this.Ch=0|o,this.Cl=0|a,this.Dh=0|i,this.Dl=0|s,this.Eh=0|c,this.El=0|l,this.Fh=0|u,this.Fl=0|d,this.Gh=0|p,this.Gl=0|h,this.Hh=0|f,this.Hl=0|m}process(n,e){for(let t=0;t<16;t++,e+=4)_n[t]=n.getUint32(e),Yn[t]=n.getUint32(e+=4);for(let n=16;n<80;n++){const e=0|_n[n-15],t=0|Yn[n-15],r=Sn(e,t,1)^Sn(e,t,8)^qn(e,0,7),o=On(e,t,1)^On(e,t,8)^Un(e,t,7),a=0|_n[n-2],i=0|Yn[n-2],s=Sn(a,i,19)^Rn(a,i,61)^qn(a,0,6),c=On(a,i,19)^Ln(a,i,61)^Un(a,i,6),l=$n(o,c,Yn[n-7],Yn[n-16]),u=Fn(l,r,s,_n[n-7],_n[n-16]);_n[n]=0|u,Yn[n]=0|l}let{Ah:t,Al:r,Bh:o,Bl:a,Ch:i,Cl:s,Dh:c,Dl:l,Eh:u,El:d,Fh:p,Fl:h,Gh:f,Gl:m,Hh:g,Hl:b}=this;for(let n=0;n<80;n++){const e=Sn(u,d,14)^Sn(u,d,18)^Rn(u,d,41),v=On(u,d,14)^On(u,d,18)^Ln(u,d,41),y=u&p^~u&f,w=Cn(b,v,d&h^~d&m,Zn[n],Yn[n]),k=Kn(w,g,e,y,Mn[n],_n[n]),x=0|w,z=Sn(t,r,28)^Rn(t,r,34)^Rn(t,r,39),E=On(t,r,28)^Ln(t,r,34)^Ln(t,r,39),j=t&o^t&i^o&i,B=r&a^r&s^a&s;g=0|f,b=0|m,f=0|p,m=0|h,p=0|u,h=0|d,({h:u,l:d}=Pn(0|c,0|l,0|k,0|x)),c=0|i,l=0|s,i=0|o,s=0|a,o=0|t,a=0|r;const A=Nn(x,E,B);t=Hn(A,k,z,j),r=0|A}({h:t,l:r}=Pn(0|this.Ah,0|this.Al,0|t,0|r)),({h:o,l:a}=Pn(0|this.Bh,0|this.Bl,0|o,0|a)),({h:i,l:s}=Pn(0|this.Ch,0|this.Cl,0|i,0|s)),({h:c,l:l}=Pn(0|this.Dh,0|this.Dl,0|c,0|l)),({h:u,l:d}=Pn(0|this.Eh,0|this.El,0|u,0|d)),({h:p,l:h}=Pn(0|this.Fh,0|this.Fl,0|p,0|h)),({h:f,l:m}=Pn(0|this.Gh,0|this.Gl,0|f,0|m)),({h:g,l:b}=Pn(0|this.Hh,0|this.Hl,0|g,0|b)),this.set(t,r,o,a,i,s,c,l,u,d,p,h,f,m,g,b)}roundClean(){d(_n,Yn)}destroy(){d(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};const Xn=U(()=>new Dn),Jn=U(()=>new Wn);let Qn=class extends q{constructor(n,e){super(),this.finished=!1,this.destroyed=!1,l(n);const t=A(e);if(this.iHash=n.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(t.length>r?n.create().update(t).digest():t);for(let n=0;n<o.length;n++)o[n]^=54;this.iHash.update(o),this.oHash=n.create();for(let n=0;n<o.length;n++)o[n]^=106;this.oHash.update(o),d(o)}update(n){return u(this),this.iHash.update(n),this}digestInto(n){u(this),c(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:e,iHash:t,finished:r,destroyed:o,blockLen:a,outputLen:i}=this;return n.finished=r,n.destroyed=o,n.blockLen=a,n.outputLen=i,n.oHash=e._cloneInto(n.oHash),n.iHash=t._cloneInto(n.iHash),n}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const ne=(n,e,t)=>new Qn(n,e).update(t).digest();ne.create=(n,e)=>new Qn(n,e); /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ const ee=BigInt(0),te=BigInt(1);function re(n,e){const t=e.negate();return n?t:e}function oe(n,e){const t=mn(n.Fp,e.map(n=>n.Z));return e.map((e,r)=>n.fromAffine(e.toAffine(t[r])))}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 ie(n,e){ae(n,e);const t=2**n;return{windows:Math.ceil(e/n)+1,windowSize:2**(n-1),mask:M(n),maxNumber:t,shiftBy:BigInt(n)}}function se(n,e,t){const{windowSize:r,mask:o,maxNumber:a,shiftBy:i}=t;let s=Number(n&o),c=n>>i;s>r&&(s-=a,c+=te);const l=e*r;return{nextN:c,offset:l+Math.abs(s)-1,isZero:0===s,isNeg:s<0,isNegF:e%2!=0,offsetF:l}}const ce=new WeakMap,le=new WeakMap;function ue(n){return le.get(n)||1}function de(n){if(n!==ee)throw new Error("invalid wNAF")}let pe=class{constructor(n,e){this.BASE=n.BASE,this.ZERO=n.ZERO,this.Fn=n.Fn,this.bits=e}_unsafeLadder(n,e,t=this.ZERO){let r=n;for(;e>ee;)e&te&&(t=t.add(r)),r=r.double(),e>>=te;return t}precomputeWindow(n,e){const{windows:t,windowSize:r}=ie(e,this.bits),o=[];let a=n,i=a;for(let n=0;n<t;n++){i=a,o.push(i);for(let n=1;n<r;n++)i=i.add(a),o.push(i);a=i.double()}return o}wNAF(n,e,t){if(!this.Fn.isValid(t))throw new Error("invalid scalar");let r=this.ZERO,o=this.BASE;const a=ie(n,this.bits);for(let n=0;n<a.windows;n++){const{nextN:i,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=se(t,n,a);t=i,c?o=o.add(re(u,e[d])):r=r.add(re(l,e[s]))}return de(t),{p:r,f:o}}wNAFUnsafe(n,e,t,r=this.ZERO){const o=ie(n,this.bits);for(let n=0;n<o.windows&&t!==ee;n++){const{nextN:a,offset:i,isZero:s,isNeg:c}=se(t,n,o);if(t=a,!s){const n=e[i];r=r.add(c?n.negate():n)}}return de(t),r}getPrecomputes(n,e,t){let r=ce.get(e);return r||(r=this.precomputeWindow(e,n),1!==n&&("function"==typeof t&&(r=t(r)),ce.set(e,r))),r}cached(n,e,t){const r=ue(n);return this.wNAF(r,this.getPrecomputes(r,n,t),e)}unsafe(n,e,t,r){const o=ue(n);return 1===o?this._unsafeLadder(n,e,r):this.wNAFUnsafe(o,this.getPrecomputes(o,n,t),e,r)}createCache(n,e){ae(e,this.bits),le.set(n,e),ce.delete(n)}hasCache(n){return 1!==ue(n)}};function he(n,e,t,r){!function(n,e){if(!Array.isArray(n))throw new Error("array expected");n.forEach((n,t)=>{if(!(n instanceof e))throw new Error("invalid point at index "+t)})}(t,n),function(n,e){if(!Array.isArray(n))throw new Error("array of scalars expected");n.forEach((n,t)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+t)})}(r,e);const o=t.length,a=r.length;if(o!==a)throw new Error("arrays of points and scalars must have equal length");const i=n.ZERO,s=G(BigInt(o));let c=1;s>12?c=s-3:s>4?c=s-2:s>0&&(c=2);const l=M(c),u=new Array(Number(l)+1).fill(i);let d=i;for(let n=Math.floor((e.BITS-1)/c)*c;n>=0;n-=c){u.fill(i);for(let e=0;e<a;e++){const o=r[e],a=Number(o>>BigInt(n)&l);u[a]=u[a].add(t[e])}let e=i;for(let n=u.length-1,t=i;n>0;n--)t=t.add(u[n]),e=e.add(t);if(d=d.add(e),0!==n)for(let n=0;n<c;n++)d=d.double()}return d}function fe(n,e,t){if(e){if(e.ORDER!==n)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(n){Z(n,fn.reduce((n,e)=>(n[e]="function",n),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(e),e}return vn(n,{isLE:t})} /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ const me=(n,e)=>(n+(n>=0?e:-e)/ke)/e;function ge(n){if(!["compact","recovered","der"].includes(n))throw new Error('Signature format must be "compact", "recovered", or "der"');return n}function be(n,e){const t={};for(let r of Object.keys(e))t[r]=void 0===n[r]?e[r]:n[r];return L(t.lowS,"lowS"),L(t.prehash,"prehash"),void 0!==t.format&&ge(t.format),t}const ve={Err:class extends Error{constructor(n=""){super(n)}},_tlv:{encode:(n,e)=>{const{Err:t}=ve;if(n<0||n>256)throw new t("tlv.encode: wrong tag");if(1&e.length)throw new t("tlv.encode: unpadded data");const r=e.length/2,o=N(r);if(o.length/2&128)throw new t("tlv.encode: long form length too big");const a=r>127?N(o.length/2|128):"";return N(n)+a+o+e},decode(n,e){const{Err:t}=ve;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 o=e[r++];let a=0;if(!!(128&o)){const n=127&o;if(!n)throw new t("tlv.decode(long): indefinite length not supported");if(n>4)throw new t("tlv.decode(long): byte length is too big");const i=e.subarray(r,r+n);if(i.length!==n)throw new t("tlv.decode: length bytes not complete");if(0===i[0])throw new t("tlv.decode(long): zero leftmost byte");for(const n of i)a=a<<8|n;if(r+=n,a<128)throw new t("tlv.decode(long): not minimal encoding")}else a=o;const i=e.subarray(r,r+a);if(i.length!==a)throw new t("tlv.decode: wrong value length");return{v:i,l:e.subarray(r+a)}}},_int:{encode(n){const{Err:e}=ve;if(n<ye)throw new e("integer: negative integers are not allowed");let t=N(n);if(8&Number.parseInt(t[0],16)&&(t="00"+t),1&t.length)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(n){const{Err:e}=ve;if(128&n[0])throw new e("invalid signature integer: negative");if(0===n[0]&&!(128&n[1]))throw new e("invalid signature integer: unnecessary leading zero");return $(n)}},toSig(n){const{Err:e,_int:t,_tlv:r}=ve,o=T("signature",n),{v:a,l:i}=r.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");const{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(s),s:t.decode(l)}},hexFromSig(n){const{_tlv:e,_int:t}=ve,r=e.encode(2,t.encode(n.r))+e.encode(2,t.encode(n.s));return e.encode(48,r)}},ye=BigInt(0),we=BigInt(1),ke=BigInt(2),xe=BigInt(3),ze=BigInt(4);function Ee(n,e){const{BYTES:t}=n;let r;if("bigint"==typeof e)r=e;else{let o=T("private key",e);try{r=n.fromBytes(o)}catch(n){throw new Error(`invalid private key: expected ui8a of size ${t}, got ${typeof e}`)}}if(!n.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function je(n,e={}){const t=function(n,e,t={},r){if(void 0===r&&(r="edwards"===n),!e||"object"!=typeof e)throw new Error(`expected valid ${n} CURVE object`);for(const n of["p","n","h"]){const t=e[n];if(!("bigint"==typeof t&&t>ee))throw new Error(`CURVE.${n} must be positive bigint`)}const o=fe(e.p,t.Fp,r),a=fe(e.n,t.Fn,r),i=["Gx","Gy","a","b"];for(const n of i)if(!o.isValid(e[n]))throw new Error(`CURVE.${n} must be valid field element of CURVE.Fp`);return{CURVE:e=Object.freeze(Object.assign({},e)),Fp:o,Fn:a}}("weierstrass",n,e),{Fp:r,Fn:o}=t;let a=t.CURVE;const{h:i,n:s}=a;Z(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=e;if(c&&(!r.is0(a.a)||"bigint"!=typeof c.beta||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const l=Ae(r,o);function u(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const d=e.toBytes||function(n,e,t){const{x:o,y:a}=e.toAffine(),i=r.toBytes(o);if(L(t,"isCompressed"),t){u();return I(Be(!r.isOdd(a)),i)}return I(Uint8Array.of(4),i,r.toBytes(a))},p=e.fromBytes||function(n){P(n,void 0,"Point");const{publicKey:e,publicKeyUncompressed:t}=l,o=n.length,a=n[0],i=n.subarray(1);if(o!==e||2!==a&&3!==a){if(o===t&&4===a){const n=r.BYTES,e=r.fromBytes(i.subarray(0,n)),t=r.fromBytes(i.subarray(n,2*n));if(!f(e,t))throw new Error("bad point: is not on curve");return{x:e,y:t}}throw new Error(`bad point: got length ${o}, expected compressed=${e} or uncompressed=${t}`)}{const n=r.fromBytes(i);if(!r.isValid(n))throw new Error("bad point: is not on curve, wrong x");const e=h(n);let t;try{t=r.sqrt(e)}catch(n){const e=n instanceof Error?": "+n.message:"";throw new Error("bad point: is not on curve, sqrt error"+e)}u();return!(1&~a)!==r.isOdd(t)&&(t=r.neg(t)),{x:n,y:t}}};function h(n){const e=r.sqr(n),t=r.mul(e,n);return r.add(r.add(t,r.mul(n,a.a)),a.b)}function f(n,e){const t=r.sqr(e),o=h(n);return r.eql(t,o)}if(!f(a.Gx,a.Gy))throw new Error("bad curve params: generator point");const m=r.mul(r.pow(a.a,xe),ze),g=r.mul(r.sqr(a.b),BigInt(27));if(r.is0(r.add(m,g)))throw new Error("bad curve params: a or b");function v(n,e,t=!1){if(!r.isValid(e)||t&&r.is0(e))throw new Error(`bad point coordinate ${n}`);return e}function y(n){if(!(n instanceof E))throw new Error("ProjectivePoint expected")}function w(n){if(!c||!c.basises)throw new Error("no endo");return function(n,e,t){const[[r,o],[a,i]]=e,s=me(i*n,t),c=me(-o*n,t);let l=n-s*r-c*a,u=-s*o-c*i;const d=l<ye,p=u<ye;d&&(l=-l),p&&(u=-u);const h=M(Math.ceil(G(t)/2))+we;if(l<ye||l>=h||u<ye||u>=h)throw new Error("splitScalar (endomorphism): failed, k="+n);return{k1neg:d,k1:l,k2neg:p,k2:u}}(n,c.basises,o.ORDER)}const k=_((n,e)=>{const{X:t,Y:o,Z:a}=n;if(r.eql(a,r.ONE))return{x:t,y:o};const i=n.is0();null==e&&(e=i?r.ONE:r.inv(a));const s=r.mul(t,e),c=r.mul(o,e),l=r.mul(a,e);if(i)return{x:r.ZERO,y:r.ZERO};if(!r.eql(l,r.ONE))throw new Error("invZ was invalid");return{x:s,y:c}}),x=_(n=>{if(n.is0()){if(e.allowInfinityPoint&&!r.is0(n.Y))return;throw new Error("bad point: ZERO")}const{x:t,y:o}=n.toAffine();if(!r.isValid(t)||!r.isValid(o))throw new Error("bad point: x or y not field elements");if(!f(t,o))throw new Error("bad point: equation left != right");if(!n.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function z(n,e,t,o,a){return t=new E(r.mul(t.X,n),t.Y,t.Z),e=re(o,e),t=re(a,t),e.add(t)}class E{constructor(n,e,t){this.X=v("x",n),this.Y=v("y",e,!0),this.Z=v("z",t),Object.freeze(this)}static CURVE(){return a}static fromAffine(n){const{x:e,y:t}=n||{};if(!n||!r.isValid(e)||!r.isValid(t))throw new Error("invalid affine point");if(n instanceof E)throw new Error("projective point not allowed");return r.is0(e)&&r.is0(t)?E.ZERO:new E(e,t,r.ONE)}static fromBytes(n){const e=E.fromAffine(p(P(n,void 0,"point")));return e.assertValidity(),e}static fromHex(n){return E.fromBytes(T("pointHex",n))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(n=8,e=!0){return B.createCache(this,n),e||this.multiply(xe),this}assertValidity(){x(this)}hasEvenY(){const{y:n}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(n)}equals(n){y(n);const{X:e,Y:t,Z:o}=this,{X:a,Y:i,Z:s}=n,c=r.eql(r.mul(e,s),r.mul(a,o)),l=r.eql(r.mul(t,s),r.mul(i,o));return c&&l}negate(){return new E(this.X,r.neg(this.Y),this.Z)}double(){const{a:n,b:e}=a,t=r.mul(e,xe),{X:o,Y:i,Z:s}=this;let c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(o,o),p=r.mul(i,i),h=r.mul(s,s),f=r.mul(o,i);return f=r.add(f,f),u=r.mul(o,s),u=r.add(u,u),c=r.mul(n,u),l=r.mul(t,h),l=r.add(c,l),c=r.sub(p,l),l=r.add(p,l),l=r.mul(c,l),c=r.mul(f,c),u=r.mul(t,u),h=r.mul(n,h),f=r.sub(d,h),f=r.mul(n,f),f=r.add(f,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,h),d=r.mul(d,f),l=r.add(l,d),h=r.mul(i,s),h=r.add(h,h),d=r.mul(h,f),c=r.sub(c,d),u=r.mul(h,p),u=r.add(u,u),u=r.add(u,u),new E(c,l,u)}add(n){y(n);const{X:e,Y:t,Z:o}=this,{X:i,Y:s,Z:c}=n;let l=r.ZERO,u=r.ZERO,d=r.ZERO;const p=a.a,h=r.mul(a.b,xe);let f=r.mul(e,i),m=r.mul(t,s),g=r.mul(o,c),b=r.add(e,t),v=r.add(i,s);b=r.mul(b,v),v=r.add(f,m),b=r.sub(b,v),v=r.add(e,o);let w=r.add(i,c);return v=r.mul(v,w),w=r.add(f,g),v=r.sub(v,w),w=r.add(t,o),l=r.add(s,c),w=r.mul(w,l),l=r.add(m,g),w=r.sub(w,l),d=r.mul(p,v),l=r.mul(h,g),d=r.add(l,d),l=r.sub(m,d),d=r.add(m,d),u=r.mul(l,d),m=r.add(f,f),m=r.add(m,f),g=r.mul(p,g),v=r.mul(h,v),m=r.add(m,g),g=r.sub(f,g),g=r.mul(p,g),v=r.add(v,g),f=r.mul(m,v),u=r.add(u,f),f=r.mul(w,v),l=r.mul(b,l),l=r.sub(l,f),f=r.mul(b,m),d=r.mul(w,d),d=r.add(d,f),new E(l,u,d)}subtract(n){return this.add(n.negate())}is0(){return this.equals(E.ZERO)}multiply(n){const{endo:t}=e;if(!o.isValidNot0(n))throw new Error("invalid scalar: out of range");let r,a;const i=n=>B.cached(this,n,n=>oe(E,n));if(t){const{k1neg:e,k1:o,k2neg:s,k2:c}=w(n),{p:l,f:u}=i(o),{p:d,f:p}=i(c);a=u.add(p),r=z(t.beta,l,d,e,s)}else{const{p:e,f:t}=i(n);r=e,a=t}return oe(E,[r,a])[0]}multiplyUnsafe(n){const{endo:t}=e,r=this;if(!o.isValid(n))throw new Error("invalid scalar: out of range");if(n===ye||r.is0())return E.ZERO;if(n===we)return r;if(B.hasCache(this))return this.multiply(n);if(t){const{k1neg:e,k1:o,k2neg:a,k2:i}=w(n),{p1:s,p2:c}=function(n,e,t,r){let o=e,a=n.ZERO,i=n.ZERO;for(;t>ee||r>ee;)t&te&&(a=a.add(o)),r&te&&(i=i.add(o)),o=o.double(),t>>=te,r>>=te;return{p1:a,p2:i}}(E,r,o,i);return z(t.beta,s,c,e,a)}return B.unsafe(r,n)}multiplyAndAddUnsafe(n,e,t){const r=this.multiplyUnsafe(e).add(n.multiplyUnsafe(t));return r.is0()?void 0:r}toAffine(n){return k(this,n)}isTorsionFree(){const{isTorsionFree:n}=e;return i===we||(n?n(E,this):B.unsafe(this,s).is0())}clearCofactor(){const{clearCofactor:n}=e;return i===we?this:n?n(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(n=!0){return L(n,"isCompressed"),this.assertValidity(),d(E,this,n)}toHex(n=!0){return b(this.toBytes(n))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(n=!0){return this.toBytes(n)}_setWindowSize(n){this.precompute(n)}static normalizeZ(n){return oe(E,n)}static msm(n,e){return he(E,o,n,e)}static fromPrivateKey(n){return E.BASE.multiply(Ee(o,n))}}E.BASE=new E(a.Gx,a.Gy,r.ONE),E.ZERO=new E(r.ZERO,r.ONE,r.ZERO),E.Fp=r,E.Fn=o;const j=o.BITS,B=new pe(E,e.endo?Math.ceil(j/2):j);return E.BASE.precompute(8),E}function Be(n){return Uint8Array.of(n?2:3)}function Ae(n,e){return{secretKey:e.BYTES,publicKey:1+n.BYTES,publicKeyUncompressed:1+2*n.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Ie(n,e={}){const{Fn:t}=n,r=e.randomBytes||S,o=Object.assign(Ae(n.Fp,t),{seed:wn(t.ORDER)});function a(n){try{return!!Ee(t,n)}catch(n){return!1}}function i(n=r(o.seed)){return function(n,e,t=!1){const r=n.length,o=yn(e),a=wn(e);if(r<16||r<a||r>1024)throw new Error("expected "+a+"-1024 bytes of input, got "+r);const i=an(t?F(n):$(n),e-W)+W;return t?K(i,o):C(i,o)}(P(n,o.seed,"seed"),t.ORDER)}function s(e,r=!0){return n.BASE.multiply(Ee(t,e)).toBytes(r)}function c(e){if("bigint"==typeof e)return!1;if(e instanceof n)return!0;const{secretKey:r,publicKey:a,publicKeyUncompressed:i}=o;if(t.allowedLengths||r===a)return;const s=T("key",e).length;return s===a||s===i}const l={isValidSecretKey:a,isValidPublicKey:function(e,t){const{publicKey:r,publicKeyUncompressed:a}=o;try{const o=e.length;return(!0!==t||o===r)&&((!1!==t||o===a)&&!!n.fromBytes(e))}catch(n){return!1}},randomSecretKey:i,isValidPrivateKey:a,randomPrivateKey:i,normPrivateKeyToScalar:n=>Ee(t,n),precompute:(e=8,t=n.BASE)=>t.precompute(e,!1)};return Object.freeze({getPublicKey:s,getSharedSecret:function(e,r,o=!0){if(!0===c(e))throw new Error("first arg must be private key");if(!1===c(r))throw new Error("second arg must be public key");const a=Ee(t,e);return n.fromHex(r).multiply(a).toBytes(o)},keygen:function(n){const e=i(n);return{secretKey:e,publicKey:s(e)}},Point:n,utils:l,lengths:o})}function qe(n,e,t={}){l(e),Z(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=t.randomBytes||S,o=t.hmac||((n,...t)=>ne(e,n,I(...t))),{Fp:a,Fn:s}=n,{ORDER:c,BITS:u}=s,{keygen:d,getPublicKey:p,getSharedSecret:h,utils:f,lengths:m}=Ie(n,t),g={prehash:!1,lowS:"boolean"==typeof t.lowS&&t.lowS,format:void 0,extraEntropy:!1},v="compact";function y(n){return n>c>>we}function w(n,e){if(!s.isValidNot0(e))throw new Error(`invalid signature ${n}: out of range 1..Point.Fn.ORDER`);return e}class k{constructor(n,e,t){this.r=w("r",n),this.s=w("s",e),null!=t&&(this.recovery=t),Object.freeze(this)}static fromBytes(n,e=v){let t;if(function(n,e){ge(e);const t=m.signature;P(n,"compact"===e?t:"recovered"===e?t+1:void 0,`${e} signature`)}(n,e),"der"===e){const{r:e,s:t}=ve.toSig(P(n));return new k(e,t)}"recovered"===e&&(t=n[0],e="compact",n=n.subarray(1));const r=s.BYTES,o=n.subarray(0,r),a=n.subarray(r,2*r);return new k(s.fromBytes(o),s.fromBytes(a),t)}static fromHex(n,e){return this.fromBytes(j(n),e)}addRecoveryBit(n){return new k(this.r,this.s,n)}recoverPublicKey(e){const t=a.ORDER,{r:r,s:o,recovery:i}=this;if(null==i||![0,1,2,3].includes(i))throw new Error("recovery id invalid");if(c*ke<t&&i>1)throw new Error("recovery id is ambiguous for h>1 curve");const l=2===i||3===i?r+c:r;if(!a.isValid(l))throw new Error("recovery id 2 or 3 invalid");const u=a.toBytes(l),d=n.fromBytes(I(Be(!(1&i)),u)),p=s.inv(l),h=z(T("msgHash",e)),f=s.create(-h*p),m=s.create(o*p),g=n.BASE.multiplyUnsafe(f).add(d.multiplyUnsafe(m));if(g.is0())throw new Error("point at infinify");return g.assertValidity(),g}hasHighS(){return y(this.s)}toBytes(n=v){if(ge(n),"der"===n)return j(ve.hexFromSig(this));const e=s.toBytes(this.r),t=s.toBytes(this.s);if("recovered"===n){if(null==this.recovery)throw new Error("recovery bit must be present");return I(Uint8Array.of(this.recovery),e,t)}return I(e,t)}toHex(n){return b(this.toBytes(n))}assertValidity(){}static fromCompact(n){return k.fromBytes(T("sig",n),"compact")}static fromDER(n){return k.fromBytes(T("sig",n),"der")}normalizeS(){return this.hasHighS()?new k(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return b(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return b(this.toBytes("compact"))}}const x=t.bits2int||function(n){if(n.length>8192)throw new Error("input is too large");const e=$(n),t=8*n.length-u;return t>0?e>>BigInt(t):e},z=t.bits2int_modN||function(n){return s.create(x(n))},E=M(u);function B(n){return D("num < 2^"+u,n,ye,E),s.toBytes(n)}function A(n,t){return P(n,void 0,"message"),t?P(e(n),void 0,"prehashed message"):n}return Object.freeze({keygen:d,getPublicKey:p,getSharedSecret:h,utils:f,lengths:m,Point:n,sign:function(t,a,i={}){t=T("message",t);const{seed:c,k2sig:l}=function(e,t,o){if(["recovered","canonical"].some(n=>n in o))throw new Error("sign() legacy options not supported");const{lowS:a,prehash:i,extraEntropy:c}=be(o,g);e=A(e,i);const l=z(e),u=Ee(s,t),d=[B(u),B(l)];if(null!=c&&!1!==c){const n=!0===c?r(m.secretKey):c;d.push(T("extraEntropy",n))}const p=I(...d),h=l;return{seed:p,k2sig:function(e){const t=x(e);if(!s.isValidNot0(t))return;const r=s.inv(t),o=n.BASE.multiply(t).toAffine(),i=s.create(o.x);if(i===ye)return;const c=s.create(r*s.create(h+i*u));if(c===ye)return;let l=(o.x===i?0:2)|Number(o.y&we),d=c;return a&&y(c)&&(d=s.neg(c),l^=1),new k(i,d,l)}}}(t,a,i),u=function(n,e,t){if("number"!=typeof n||n<2)throw new Error("hashLen must be a number");if("number"!=typeof e||e<2)throw new Error("qByteLen must be a number");if("function"!=typeof t)throw new Error("hmacFn must be a function");const r=n=>new Uint8Array(n),o=n=>Uint8Array.of(n);let a=r(n),i=r(n),s=0;const c=()=>{a.fill(1),i.fill(0),s=0},l=(...n)=>t(i,a,...n),u=(n=r(0))=>{i=l(o(0),n),a=l(),0!==n.length&&(i=l(o(1),n),a=l())},d=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let n=0;const t=[];for(;n<e;){a=l();const e=a.slice();t.push(e),n+=a.length}return I(...t)};return(n,e)=>{let t;for(c(),u(n);!(t=e(d()));)u();return c(),t}}(e.outputLen,s.BYTES,o);return u(c,l)},verify:function(e,t,r,o={}){const{lowS:a,prehash:c,format:l}=be(o,g);if(r=T("publicKey",r),t=A(T("message",t),c),"strict"in o)throw new Error("options.strict was renamed to lowS");const u=void 0===l?function(n){let e;const t="string"==typeof n||i(n),r=!t&&null!==n&&"object"==typeof n&&"bigint"==typeof n.r&&"bigint"==typeof n.s;if(!t&&!r)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)e=new k(n.r,n.s);else if(t){try{e=k.fromBytes(T("sig",n),"der")}catch(n){if(!(n instanceof ve.Err))throw n}if(!e)try{e=k.fromBytes(T("sig",n),"compact")}catch(n){return!1}}return e||!1}(e):k.fromBytes(T("sig",e),l);if(!1===u)return!1;try{const e=n.fromBytes(r);if(a&&u.hasHighS())return!1;const{r:o,s:i}=u,c=z(t),l=s.inv(i),d=s.create(c*l),p=s.create(o*l),h=n.BASE.multiplyUnsafe(d).add(e.multiplyUnsafe(p));if(h.is0())return!1;return s.create(h.x)===o}catch(n){return!1}},recoverPublicKey:function(n,e,t={}){const{prehash:r}=be(t,g);return e=A(e,r),k.fromBytes(n,"recovered").recoverPublicKey(e).toBytes()},Signature:k,hash:e})}function Ue(n){const{CURVE:e,curveOpts:t}=function(n){const e={a:n.a,b:n.b,p:n.Fp.ORDER,n:n.n,h:n.h,Gx:n.Gx,Gy:n.Gy},t=n.Fp;let r=n.allowedPrivateKeyLengths?Array.from(new Set(n.allowedPrivateKeyLengths.map(n=>Math.ceil(n/2)))):void 0;return{CURVE:e,curveOpts:{Fp:t,Fn:vn(e.n,{BITS:n.nBitLength,allowedLengths:r,modFromBytes:n.wrapPrivateKey}),allowInfinityPoint:n.allowInfinityPoint,endo:n.endo,isTorsionFree:n.isTorsionFree,clearCofactor:n.clearCofactor,fromBytes:n.fromBytes,toBytes:n.toBytes}}}(n),r={hmac:n.hmac,randomBytes:n.randomBytes,lowS:n.lowS,bits2int:n.bits2int,bits2int_modN:n.bits2int_modN};return{CURVE:e,curveOpts:t,hash:n.hash,ecdsaOpts:r}}function Se(n){const{CURVE:e,curveOpts:t,hash:r,ecdsaOpts:o}=Ue(n);return function(n,e){const t=e.Point;return Object.assign({},e,{ProjectivePoint:t,CURVE:Object.assign({},n,bn(t.Fn.ORDER,t.Fn.BITS))})}(n,qe(je(e,t),r,o))} /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ const Oe={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Re={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Le=BigInt(2);const Pe=vn(Oe.p,{sqrt:function(n){const e=Oe.p,t=BigInt(3),r=BigInt(6),o=BigInt(11),a=BigInt(22),i=BigInt(23),s=BigInt(44),c=BigInt(88),l=n*n*n%e,u=l*l*n%e,d=sn(u,t,e)*u%e,p=sn(d,t,e)*u%e,h=sn(p,Le,e)*l%e,f=sn(h,o,e)*h%e,m=sn(f,a,e)*f%e,g=sn(m,s,e)*m%e,b=sn(g,c,e)*g%e,v=sn(b,s,e)*m%e,y=sn(v,t,e)*u%e,w=sn(y,i,e)*f%e,k=sn(w,r,e)*l%e,x=sn(k,Le,e);if(!Pe.eql(Pe.sqr(x),n))throw new Error("Cannot find square root");return x}}),Ne=function(n,e){const t=e=>Se({...n,hash:e});return{...t(e),create:t}}({...Oe,Fp:Pe,lowS:!0,endo:Re},Xn),He=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),$e=(()=>Uint8Array.from(new Array(16).fill(0).map((n,e)=>e)))(),Fe=(()=>$e.map(n=>(9*n+5)%16))(),Ce=(()=>{const n=[[$e],[Fe]];for(let e=0;e<4;e++)for(let t of n)t.push(t[e].map(n=>He[n]));return n})(),Ke=(()=>Ce[0])(),Te=(()=>Ce[1])(),Ve=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(n=>Uint8Array.from(n)),De=Ke.map((n,e)=>n.map(n=>Ve[e][n])),Ge=Te.map((n,e)=>n.map(n=>Ve[e][n])),Me=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Ze=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function _e(n,e,t,r){return 0===n?e^t^r:1===n?e&t|~e&r:2===n?(e|~t)^r:3===n?e&r|t&~r:e^(t|~r)}const Ye=new Uint32Array(16);class We extends zn{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:n,h1:e,h2:t,h3:r,h4:o}=this;return[n,e,t,r,o]}set(n,e,t,r,o){this.h0=0|n,this.h1=0|e,this.h2=0|t,this.h3=0|r,this.h4=0|o}process(n,e){for(let t=0;t<16;t++,e+=4)Ye[t]=n.getUint32(e,!0);let t=0|this.h0,r=t,o=0|this.h1,a=o,i=0|this.h2,s=i,c=0|this.h3,l=c,u=0|this.h4,d=u;for(let n=0;n<5;n++){const e=4-n,p=Me[n],h=Ze[n],m=Ke[n],g=Te[n],b=De[n],v=Ge[n];for(let e=0;e<16;e++){const r=f(t+_e(n,o,i,c)+Ye[m[e]]+p,b[e])+u|0;t=u,u=c,c=0|f(i,10),i=o,o=r}for(let n=0;n<16;n++){const t=f(r+_e(e,a,s,l)+Ye[g[n]]+h,v[n])+d|0;r=d,d=l,l=0|f(s,10),s=a,a=t}}this.set(this.h1+i+l|0,this.h2+c+d|0,this.h3+u+r|0,this.h4+t+a|0,this.h0+o+s|0)}roundClean(){d(Ye)}destroy(){this.destroyed=!0,d(this.buffer),this.set(0,0,0,0,0)}}const Xe=U(()=>new We); /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Je(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name}function Qe(n,e){return!!Array.isArray(e)&&(0===e.length||(n?e.every(n=>"string"==typeof n):e.every(n=>Number.isSafeInteger(n))))}function nt(n,e){if("string"!=typeof e)throw new Error(`${n}: string expected`);return!0}function et(n){if(!Number.isSafeInteger(n))throw new Error(`invalid integer: ${n}`)}function tt(n){if(!Array.isArray(n))throw new Error("array expected")}function rt(n,e){if(!Qe(!0,e))throw new Error(`${n}: array of strings expected`)}function ot(...n){const e=n=>n,t=(n,e)=>t=>n(e(t));return{encode:n.map(n=>n.encode).reduceRight(t,e),decode:n.map(n=>n.decode).reduce(t,e)}}function at(n,e,t){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(t<2)throw new Error(`convertRadix: invalid to=${t}, base cannot be less than 2`);if(tt(n),!n.length)return[];let r=0;const o=[],a=Array.from(n,n=>{if(et(n),n<0||n>=e)throw new Error(`invalid integer: ${n}`);return n}),i=a.length;for(;;){let n=0,s=!0;for(let o=r;o<i;o++){const i=a[o],c=e*n,l=c+i;if(!Number.isSafeInteger(l)||c/e!==n||l-i!==c)throw new Error("convertRadix: carry overflow");const u=l/t;n=l%t;const d=Math.floor(u);if(a[o]=d,!Number.isSafeInteger(d)||d*t+n!==l)throw new Error("convertRadix: carry overflow");s&&(d?s=!1:r=o)}if(o.push(n),s)break}for(let e=0;e<n.length-1&&0===n[e];e++)o.push(0);return o.reverse()}function it(n){et(n);return{encode:e=>{if(!Je(e))throw new Error("radix.encode input should be Uint8Array");return at(Array.from(e),256,n)},decode:e=>(function(n,e){if(!Qe(!1,e))throw new Error(`${n}: array of numbers expected`)}("radix.decode",e),Uint8Array.from(at(e,n,256)))}}function st(n,e){return et(n),function(n){if("function"!=typeof n)throw new Error("function expected")}(e),{encode(t){if(!Je(t))throw new Error("checksum.encode: input should be Uint8Array");const r=e(t).slice(0,n),o=new Uint8Array(t.length+n);return o.set(t),o.set(r,t.length),o},decode(t){if(!Je(t))throw new Error("checksum.decode: input should be Uint8Array");const r=t.slice(0,-n),o=t.slice(-n),a=e(r).slice(0,n);for(let e=0;e<n;e++)if(a[e]!==o[e])throw new Error("Invalid checksum");return r}}}const ct=(lt="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",ot(it(58),function(n){const e="string"==typeof n?n.split(""):n,t=e.length;rt("alphabet",e);const r=new Map(e.map((n,e)=>[n,e]));return{encode:r=>(tt(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=t)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${n}`);return e[r]})),decode:e=>(tt(e),e.map(e=>{nt("alphabet.decode",e);const t=r.get(e);if(void 0===t)throw new Error(`Unknown letter: "${e}". Allowed: ${n}`);return t}))}}(lt),function(n=""){return nt("join",n),{encode:e=>(rt("join.decode",e),e.join(n)),decode:e=>(nt("join.decode",e),e.split(n))}}("")));var lt;const ut=Ne.ProjectivePoint,dt=(n=>ot(st(4,e=>n(n(e))),ct))(Xn); /*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */function pt(n){c(n);const e=0===n.length?"0":b(n);return BigInt("0x"+e)}const ht=B("Bitcoin seed"),ft={private:76066276,public:76067358},mt=2147483648,gt=n=>{if(!Number.isSafeInteger(n)||n<0||n>2**32-1)throw new Error("invalid number, should be from 0 to 2**32-1, got "+n);const e=new Uint8Array(4);return p(e).setUint32(0,n,!1),e};class bt{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return p(this.pubHash).getUint32(0,!1)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this.privKeyBytes||null}get publicKey(){return this.pubKey||null}get privateExtendedKey(){const n=this.privateKey;if(!n)throw new Error("No private key");return dt.encode(this.serialize(this.versions.private,I(new Uint8Array([0]),n)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return dt.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(n,e=ft){if(c(n),8*n.length<128||8*n.length>512)throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got "+n.length);const t=ne(Jn,ht,n);return new bt({versions:e,chainCode:t.slice(32),privateKey:t.slice(0,32)})}static fromExtendedKey(n,e=ft){const t=dt.decode(n),r=p(t),o=r.getUint32(0,!1),a={versions:e,depth:t[4],parentFingerprint:r.getUint32(5,!1),index:r.getUint32(9,!1),chainCode:t.slice(13,45)},i=t.slice(45),s=0===i[0];if(o!==e[s?"private":"public"])throw new Error("Version mismatch");return new bt(s?{...a,privateKey:i.slice(1)}:{...a,publicKey:i})}static fromJSON(n){return bt.fromExtendedKey(n.xpriv)}constructor(n){if(this.depth=0,this.index=0,this.chainCode=null,this.parentFingerprint=0,!n||"object"!=typeof n)throw new Error("HDKey.constructor must not be called directly");if(this.versions=n.versions||ft,this.depth=n.depth||0,this.chainCode=n.chainCode||null,this.index=n.index||0,this.parentFingerprint=n.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(n.publicKey&&n.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(n.privateKey){if(!Ne.utils.isValidPrivateKey(n.privateKey))throw new Error("Invalid private key");this.privKey="bigint"==typeof n.privateKey?n.privateKey:pt(n.privateKey),this.privKeyBytes=function(n){if("bigint"!=typeof n)throw new Error("bigint expected");return j(n.toString(16).padStart(64,"0"))}(this.privKey),this.pubKey=Ne.getPublicKey(n.privateKey,!0)}else{if(!n.publicKey)throw new Error("HDKey: no public or private key provided");this.pubKey=ut.fromHex(n.publicKey).toRawBytes(!0)}var e;this.pubHash=(e=this.pubKey,Xe(Xn(e)))}derive(n){if(!/^[mM]'?/.test(n))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(n))return this;const e=n.replace(/^[mM]'?\//,"").split("/");let t=this;for(const n of e){const e=/^(\d+)('?)$/.exec(n),r=e&&e[1];if(!e||3!==e.length||"string"!=typeof r)throw new Error("invalid child index: "+n);let o=+r;if(!Number.isSafeInteger(o)||o>=mt)throw new Error("Invalid index");"'"===e[2]&&(o+=mt),t=t.deriveChild(o)}return t}deriveChild(n){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let e=gt(n);if(n>=mt){const n=this.privateKey;if(!n)throw new Error("Could not derive hardened child key");e=I(new Uint8Array([0]),n,e)}else e=I(this.pubKey,e);const t=ne(Jn,this.chainCode,e),r=pt(t.slice(0,32)),o=t.slice(32);if(!Ne.utils.isValidPrivateKey(r))throw new Error("Tweak bigger than curve order");const a={versions:this.versions,chainCode:o,depth:this.depth+1,parentFingerprint:this.fingerprint,index:n};try{i