UNPKG

@flarenetwork/flarejs

Version:
11 lines 156 kB
"use strict";var t=require("@scure/base"),e=require("@noble/hashes/utils"),r=require("@noble/hashes/sha256"),s=require("@noble/hashes/ripemd160"),n=require("util");function o(t,e,r,s){var n,o=arguments.length,a=o<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,s);else for(var i=t.length-1;i>=0;i--)(n=t[i])&&(a=(o<3?n(a):o>3?n(e,r,a):n(e,r))||a);return o>3&&a&&Object.defineProperty(e,r,a),a}function a(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}const i=Symbol.for("nodejs.util.inspect.custom"),c="-";function u(t){const e=t.split(c);if(e.length<2)throw new Error(`Invalid address: ${t}`);const r=e[0],s=e[1],[n,o]=f(s);return[r,n,o]}function d(t){return u(t)[2]}function f(e){const{prefix:r,words:s}=t.bech32.decode(e);return[r,t.bech32.fromWords(s)]}function p(e,r){const s=t.bech32.toWords(r);return t.bech32.encode(e,s)}function l(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function h(t,...e){if(!((r=t)instanceof Uint8Array||null!=r&&"object"==typeof r&&"Uint8Array"===r.constructor.name))throw new Error("Expected Uint8Array");var r;if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function m(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}const x=BigInt(2**32-1),b=BigInt(32);function g(t,e=!1){return e?{h:Number(t&x),l:Number(t>>b&x)}:{h:0|Number(t>>b&x),l:0|Number(t&x)}}function y(t,e=!1){let r=new Uint32Array(t.length),s=new Uint32Array(t.length);for(let n=0;n<t.length;n++){const{h:o,l:a}=g(t[n],e);[r[n],s[n]]=[o,a]}return[r,s]}if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");function w(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}(t)),!((e=t)instanceof Uint8Array||null!=e&&"object"==typeof e&&"Uint8Array"===e.constructor.name))throw new Error("expected Uint8Array, got "+typeof t);var e;return t}class I{clone(){return this._cloneInto()}}const[B,T,S]=[[],[],[]],O=BigInt(0),v=BigInt(1),E=BigInt(2),A=BigInt(7),k=BigInt(256),P=BigInt(113);for(let t=0,e=v,r=1,s=0;t<24;t++){[r,s]=[s,(2*r+3*s)%5],B.push(2*(5*s+r)),T.push((t+1)*(t+2)/2%64);let n=O;for(let t=0;t<7;t++)e=(e<<v^(e>>A)*P)%k,e&E&&(n^=v<<(v<<BigInt(t))-v);S.push(n)}const[R,D]=y(S,!0),N=(t,e,r)=>r>32?((t,e,r)=>e<<r-32|t>>>64-r)(t,e,r):((t,e,r)=>t<<r|e>>>32-r)(t,e,r),_=(t,e,r)=>r>32?((t,e,r)=>t<<r-32|e>>>64-r) /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */(t,e,r):((t,e,r)=>e<<r|t>>>32-r)(t,e,r);class F extends I{constructor(t,e,r,s=!1,n=24){if(super(),this.blockLen=t,this.suffix=e,this.outputLen=r,this.enableXOF=s,this.rounds=n,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,l(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var o;this.state=new Uint8Array(200),this.state32=(o=this.state,new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}keccak(){!function(t,e=24){const r=new Uint32Array(10);for(let s=24-e;s<24;s++){for(let e=0;e<10;e++)r[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(let e=0;e<10;e+=2){const s=(e+8)%10,n=(e+2)%10,o=r[n],a=r[n+1],i=N(o,a,1)^r[s],c=_(o,a,1)^r[s+1];for(let r=0;r<50;r+=10)t[e+r]^=i,t[e+r+1]^=c}let e=t[2],n=t[3];for(let r=0;r<24;r++){const s=T[r],o=N(e,n,s),a=_(e,n,s),i=B[r];e=t[i],n=t[i+1],t[i]=o,t[i+1]=a}for(let e=0;e<50;e+=10){for(let s=0;s<10;s++)r[s]=t[e+s];for(let s=0;s<10;s++)t[e+s]^=~r[(s+2)%10]&r[(s+4)%10]}t[0]^=R[s],t[1]^=D[s]}r.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){m(this);const{blockLen:e,state:r}=this,s=(t=w(t)).length;for(let n=0;n<s;){const o=Math.min(e-this.pos,s-n);for(let e=0;e<o;e++)r[this.pos++]^=t[n++];this.pos===e&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:e,pos:r,blockLen:s}=this;t[r]^=e,0!=(128&e)&&r===s-1&&this.keccak(),t[s-1]^=128,this.keccak()}writeInto(t){m(this,!1),h(t),this.finish();const e=this.state,{blockLen:r}=this;for(let s=0,n=t.length;s<n;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,n-s);t.set(e.subarray(this.posOut,this.posOut+o),s),this.posOut+=o,s+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return l(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(function(t,e){h(t);const r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){const{blockLen:e,suffix:r,outputLen:s,rounds:n,enableXOF:o}=this;return t||(t=new F(e,r,s,o,n)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=n,t.suffix=r,t.outputLen=s,t.enableXOF=o,t.destroyed=this.destroyed,t}}const V=((t,e,r)=>function(t){const e=e=>t().update(w(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}((()=>new F(e,t,r))))(1,136,32),U=BigInt(0),C=BigInt(1),M=BigInt(2);function q(t){return t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name}const L=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function H(t){if(!q(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=L[t[r]];return e}function j(t){const e=t.toString(16);return 1&e.length?`0${e}`:e}function Z(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);return BigInt(""===t?"0":`0x${t}`)}const K={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function G(t){return t>=K._0&&t<=K._9?t-K._0:t>=K._A&&t<=K._F?t-(K._A-10):t>=K._a&&t<=K._f?t-(K._a-10):void 0}function X(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);const e=t.length,r=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const s=new Uint8Array(r);for(let e=0,n=0;e<r;e++,n+=2){const r=G(t.charCodeAt(n)),o=G(t.charCodeAt(n+1));if(void 0===r||void 0===o){const e=t[n]+t[n+1];throw new Error('hex string expected, got non-hex character "'+e+'" at index '+n)}s[e]=16*r+o}return s}function z(t){return Z(H(t))}function $(t){if(!q(t))throw new Error("Uint8Array expected");return Z(H(Uint8Array.from(t).reverse()))}function Y(t,e){return X(t.toString(16).padStart(2*e,"0"))}function J(t,e){return Y(t,e).reverse()}function W(t,e,r){let s;if("string"==typeof e)try{s=X(e)}catch(r){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${r}`)}else{if(!q(e))throw new Error(`${t} must be hex string or Uint8Array`);s=Uint8Array.from(e)}const n=s.length;if("number"==typeof r&&n!==r)throw new Error(`${t} expected ${r} bytes, got ${n}`);return s}function Q(...t){let e=0;for(let r=0;r<t.length;r++){const s=t[r];if(!q(s))throw new Error("Uint8Array expected");e+=s.length}let r=new Uint8Array(e),s=0;for(let e=0;e<t.length;e++){const n=t[e];r.set(n,s),s+=n.length}return r}function tt(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}function et(t){let e;for(e=0;t>U;t>>=C,e+=1);return e}function rt(t,e){return t>>BigInt(e)&C}const st=t=>(M<<BigInt(t-1))-C,nt=t=>new Uint8Array(t),ot=t=>Uint8Array.from(t);function at(t,e,r){if("number"!=typeof t||t<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 r)throw new Error("hmacFn must be a function");let s=nt(t),n=nt(t),o=0;const a=()=>{s.fill(1),n.fill(0),o=0},i=(...t)=>r(n,s,...t),c=(t=nt())=>{n=i(ot([0]),t),s=i(),0!==t.length&&(n=i(ot([1]),t),s=i())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let t=0;const r=[];for(;t<e;){s=i();const e=s.slice();r.push(e),t+=s.length}return Q(...r)};return(t,e)=>{let r;for(a(),c(t);!(r=e(u()));)c();return a(),r}}const it={bigint:t=>"bigint"==typeof t,function:t=>"function"==typeof t,boolean:t=>"boolean"==typeof t,string:t=>"string"==typeof t,stringOrUint8Array:t=>"string"==typeof t||q(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>"function"==typeof t&&Number.isSafeInteger(t.outputLen)};function ct(t,e,r={}){const s=(e,r,s)=>{const n=it[r];if("function"!=typeof n)throw new Error(`Invalid validator "${r}", expected function`);const o=t[e];if(!(s&&void 0===o||n(o,t)))throw new Error(`Invalid param ${String(e)}=${o} (${typeof o}), expected ${r}`)};for(const[t,r]of Object.entries(e))s(t,r,!1);for(const[t,e]of Object.entries(r))s(t,e,!0);return t}var ut=Object.freeze({__proto__:null,bitGet:rt,bitLen:et,bitMask:st,bitSet:(t,e,r)=>t|(r?C:U)<<BigInt(e),bytesToHex:H,bytesToNumberBE:z,bytesToNumberLE:$,concatBytes:Q,createHmacDrbg:at,ensureBytes:W,equalBytes:function(t,e){if(t.length!==e.length)return!1;let r=0;for(let s=0;s<t.length;s++)r|=t[s]^e[s];return 0===r},hexToBytes:X,hexToNumber:Z,isBytes:q,numberToBytesBE:Y,numberToBytesLE:J,numberToHexUnpadded:j,numberToVarBytesBE:function(t){return X(j(t))},utf8ToBytes:tt,validateObject:ct}); /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const dt=BigInt(0),ft=BigInt(1),pt=BigInt(2),lt=BigInt(3),ht=BigInt(4),mt=BigInt(5),xt=BigInt(8);function bt(t,e){const r=t%e;return r>=dt?r:e+r}function gt(t,e,r){if(r<=dt||e<dt)throw new Error("Expected power/modulo > 0");if(r===ft)return dt;let s=ft;for(;e>dt;)e&ft&&(s=s*t%r),t=t*t%r,e>>=ft;return s}function yt(t,e,r){let s=t;for(;e-- >dt;)s*=s,s%=r;return s}function wt(t,e){if(t===dt||e<=dt)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=bt(t,e),s=e,n=dt,o=ft;for(;r!==dt;){const t=s%r,e=n-o*(s/r);s=r,r=t,n=o,o=e}if(s!==ft)throw new Error("invert: does not exist");return bt(n,e)}function It(t){if(t%ht===lt){const e=(t+ft)/ht;return function(t,r){const s=t.pow(r,e);if(!t.eql(t.sqr(s),r))throw new Error("Cannot find square root");return s}}if(t%xt===mt){const e=(t-mt)/xt;return function(t,r){const s=t.mul(r,pt),n=t.pow(s,e),o=t.mul(r,n),a=t.mul(t.mul(o,pt),n),i=t.mul(o,t.sub(a,t.ONE));if(!t.eql(t.sqr(i),r))throw new Error("Cannot find square root");return i}}return function(t){const e=(t-ft)/pt;let r,s,n;for(r=t-ft,s=0;r%pt===dt;r/=pt,s++);for(n=pt;n<t&&gt(n,e,t)!==t-ft;n++);if(1===s){const e=(t+ft)/ht;return function(t,r){const s=t.pow(r,e);if(!t.eql(t.sqr(s),r))throw new Error("Cannot find square root");return s}}const o=(r+ft)/pt;return function(t,a){if(t.pow(a,e)===t.neg(t.ONE))throw new Error("Cannot find square root");let i=s,c=t.pow(t.mul(t.ONE,n),r),u=t.pow(a,o),d=t.pow(a,r);for(;!t.eql(d,t.ONE);){if(t.eql(d,t.ZERO))return t.ZERO;let e=1;for(let r=t.sqr(d);e<i&&!t.eql(r,t.ONE);e++)r=t.sqr(r);const r=t.pow(c,ft<<BigInt(i-e-1));c=t.sqr(r),u=t.mul(u,r),d=t.mul(d,c),i=e}return u}}(t)}BigInt(9),BigInt(16);const Bt=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Tt(t){return ct(t,Bt.reduce(((t,e)=>(t[e]="function",t)),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"}))}function St(t,e,r){if(r<dt)throw new Error("Expected power > 0");if(r===dt)return t.ONE;if(r===ft)return e;let s=t.ONE,n=e;for(;r>dt;)r&ft&&(s=t.mul(s,n)),n=t.sqr(n),r>>=ft;return s}function Ot(t,e){const r=new Array(e.length),s=e.reduce(((e,s,n)=>t.is0(s)?e:(r[n]=e,t.mul(e,s))),t.ONE),n=t.inv(s);return e.reduceRight(((e,s,n)=>t.is0(s)?e:(r[n]=t.mul(e,r[n]),t.mul(e,s))),n),r}function vt(t,e){const r=void 0!==e?e:t.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}function Et(t,e,r=!1,s={}){if(t<=dt)throw new Error(`Expected Field ORDER > 0, got ${t}`);const{nBitLength:n,nByteLength:o}=vt(t,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const a=It(t),i=Object.freeze({ORDER:t,BITS:n,BYTES:o,MASK:st(n),ZERO:dt,ONE:ft,create:e=>bt(e,t),isValid:e=>{if("bigint"!=typeof e)throw new Error("Invalid field element: expected bigint, got "+typeof e);return dt<=e&&e<t},is0:t=>t===dt,isOdd:t=>(t&ft)===ft,neg:e=>bt(-e,t),eql:(t,e)=>t===e,sqr:e=>bt(e*e,t),add:(e,r)=>bt(e+r,t),sub:(e,r)=>bt(e-r,t),mul:(e,r)=>bt(e*r,t),pow:(t,e)=>St(i,t,e),div:(e,r)=>bt(e*wt(r,t),t),sqrN:t=>t*t,addN:(t,e)=>t+e,subN:(t,e)=>t-e,mulN:(t,e)=>t*e,inv:e=>wt(e,t),sqrt:s.sqrt||(t=>a(i,t)),invertBatch:t=>Ot(i,t),cmov:(t,e,r)=>r?e:t,toBytes:t=>r?J(t,o):Y(t,o),fromBytes:t=>{if(t.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${t.length}`);return r?$(t):z(t)}});return Object.freeze(i)}function At(t){if("bigint"!=typeof t)throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function kt(t){const e=At(t);return e+Math.ceil(e/2)}function Pt(t,e,r=!1){const s=t.length,n=At(e),o=kt(e);if(s<16||s<o||s>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${s}`);const a=bt(r?z(t):$(t),e-ft)+ft;return r?J(a,n):Y(a,n)} /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Rt=BigInt(0),Dt=BigInt(1);function Nt(t){return Tt(t.Fp),ct(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...vt(t.n,t.nBitLength),...t,p:t.Fp.ORDER})} /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const{bytesToNumberBE:_t,hexToBytes:Ft}=ut,Vt={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(t){const{Err:e}=Vt;if(t.length<2||2!==t[0])throw new e("Invalid signature integer tag");const r=t[1],s=t.subarray(2,r+2);if(!r||s.length!==r)throw new e("Invalid signature integer: wrong length");if(128&s[0])throw new e("Invalid signature integer: negative");if(0===s[0]&&!(128&s[1]))throw new e("Invalid signature integer: unnecessary leading zero");return{d:_t(s),l:t.subarray(r+2)}},toSig(t){const{Err:e}=Vt,r="string"==typeof t?Ft(t):t;if(!q(r))throw new Error("ui8a expected");let s=r.length;if(s<2||48!=r[0])throw new e("Invalid signature tag");if(r[1]!==s-2)throw new e("Invalid signature: incorrect length");const{d:n,l:o}=Vt._parseInt(r.subarray(2)),{d:a,l:i}=Vt._parseInt(o);if(i.length)throw new e("Invalid signature: left bytes after parsing");return{r:n,s:a}},hexFromSig(t){const e=t=>8&Number.parseInt(t[0],16)?"00"+t:t,r=t=>{const e=t.toString(16);return 1&e.length?`0${e}`:e},s=e(r(t.s)),n=e(r(t.r)),o=s.length/2,a=n.length/2,i=r(o),c=r(a);return`30${r(a+o+4)}02${c}${n}02${i}${s}`}},Ut=BigInt(0),Ct=BigInt(1),Mt=BigInt(2),qt=BigInt(3),Lt=BigInt(4);function Ht(t){const e=function(t){const e=Nt(t);ct(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:s,a:n}=e;if(r){if(!s.eql(n,s.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof r||"bigint"!=typeof r.beta||"function"!=typeof r.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}(t),{Fp:r}=e,s=e.toBytes||((t,e,s)=>{const n=e.toAffine();return Q(Uint8Array.from([4]),r.toBytes(n.x),r.toBytes(n.y))}),n=e.fromBytes||(t=>{const e=t.subarray(1);return{x:r.fromBytes(e.subarray(0,r.BYTES)),y:r.fromBytes(e.subarray(r.BYTES,2*r.BYTES))}});function o(t){const{a:s,b:n}=e,o=r.sqr(t),a=r.mul(o,t);return r.add(r.add(a,r.mul(t,s)),n)}if(!r.eql(r.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function a(t){return"bigint"==typeof t&&Ut<t&&t<e.n}function i(t){if(!a(t))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(t){const{allowedPrivateKeyLengths:r,nByteLength:s,wrapPrivateKey:n,n:o}=e;if(r&&"bigint"!=typeof t){if(q(t)&&(t=H(t)),"string"!=typeof t||!r.includes(t.length))throw new Error("Invalid key");t=t.padStart(2*s,"0")}let a;try{a="bigint"==typeof t?t:z(W("private key",t,s))}catch(e){throw new Error(`private key must be ${s} bytes, hex or bigint, not ${typeof t}`)}return n&&(a=bt(a,o)),i(a),a}const u=new Map;function d(t){if(!(t instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(t,e,s){if(this.px=t,this.py=e,this.pz=s,null==t||!r.isValid(t))throw new Error("x required");if(null==e||!r.isValid(e))throw new Error("y required");if(null==s||!r.isValid(s))throw new Error("z required")}static fromAffine(t){const{x:e,y:s}=t||{};if(!t||!r.isValid(e)||!r.isValid(s))throw new Error("invalid affine point");if(t instanceof f)throw new Error("projective point not allowed");const n=t=>r.eql(t,r.ZERO);return n(e)&&n(s)?f.ZERO:new f(e,s,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(t){const e=r.invertBatch(t.map((t=>t.pz)));return t.map(((t,r)=>t.toAffine(e[r]))).map(f.fromAffine)}static fromHex(t){const e=f.fromAffine(n(W("pointHex",t)));return e.assertValidity(),e}static fromPrivateKey(t){return f.BASE.multiply(c(t))}_setWindowSize(t){this._WINDOW_SIZE=t,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!r.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:t,y:s}=this.toAffine();if(!r.isValid(t)||!r.isValid(s))throw new Error("bad point: x or y not FE");const n=r.sqr(s),a=o(t);if(!r.eql(n,a))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:t}=this.toAffine();if(r.isOdd)return!r.isOdd(t);throw new Error("Field doesn't support isOdd")}equals(t){d(t);const{px:e,py:s,pz:n}=this,{px:o,py:a,pz:i}=t,c=r.eql(r.mul(e,i),r.mul(o,n)),u=r.eql(r.mul(s,i),r.mul(a,n));return c&&u}negate(){return new f(this.px,r.neg(this.py),this.pz)}double(){const{a:t,b:s}=e,n=r.mul(s,qt),{px:o,py:a,pz:i}=this;let c=r.ZERO,u=r.ZERO,d=r.ZERO,p=r.mul(o,o),l=r.mul(a,a),h=r.mul(i,i),m=r.mul(o,a);return m=r.add(m,m),d=r.mul(o,i),d=r.add(d,d),c=r.mul(t,d),u=r.mul(n,h),u=r.add(c,u),c=r.sub(l,u),u=r.add(l,u),u=r.mul(c,u),c=r.mul(m,c),d=r.mul(n,d),h=r.mul(t,h),m=r.sub(p,h),m=r.mul(t,m),m=r.add(m,d),d=r.add(p,p),p=r.add(d,p),p=r.add(p,h),p=r.mul(p,m),u=r.add(u,p),h=r.mul(a,i),h=r.add(h,h),p=r.mul(h,m),c=r.sub(c,p),d=r.mul(h,l),d=r.add(d,d),d=r.add(d,d),new f(c,u,d)}add(t){d(t);const{px:s,py:n,pz:o}=this,{px:a,py:i,pz:c}=t;let u=r.ZERO,p=r.ZERO,l=r.ZERO;const h=e.a,m=r.mul(e.b,qt);let x=r.mul(s,a),b=r.mul(n,i),g=r.mul(o,c),y=r.add(s,n),w=r.add(a,i);y=r.mul(y,w),w=r.add(x,b),y=r.sub(y,w),w=r.add(s,o);let I=r.add(a,c);return w=r.mul(w,I),I=r.add(x,g),w=r.sub(w,I),I=r.add(n,o),u=r.add(i,c),I=r.mul(I,u),u=r.add(b,g),I=r.sub(I,u),l=r.mul(h,w),u=r.mul(m,g),l=r.add(u,l),u=r.sub(b,l),l=r.add(b,l),p=r.mul(u,l),b=r.add(x,x),b=r.add(b,x),g=r.mul(h,g),w=r.mul(m,w),b=r.add(b,g),g=r.sub(x,g),g=r.mul(h,g),w=r.add(w,g),x=r.mul(b,w),p=r.add(p,x),x=r.mul(I,w),u=r.mul(y,u),u=r.sub(u,x),x=r.mul(y,b),l=r.mul(I,l),l=r.add(l,x),new f(u,p,l)}subtract(t){return this.add(t.negate())}is0(){return this.equals(f.ZERO)}wNAF(t){return l.wNAFCached(this,u,t,(t=>{const e=r.invertBatch(t.map((t=>t.pz)));return t.map(((t,r)=>t.toAffine(e[r]))).map(f.fromAffine)}))}multiplyUnsafe(t){const s=f.ZERO;if(t===Ut)return s;if(i(t),t===Ct)return this;const{endo:n}=e;if(!n)return l.unsafeLadder(this,t);let{k1neg:o,k1:a,k2neg:c,k2:u}=n.splitScalar(t),d=s,p=s,h=this;for(;a>Ut||u>Ut;)a&Ct&&(d=d.add(h)),u&Ct&&(p=p.add(h)),h=h.double(),a>>=Ct,u>>=Ct;return o&&(d=d.negate()),c&&(p=p.negate()),p=new f(r.mul(p.px,n.beta),p.py,p.pz),d.add(p)}multiply(t){i(t);let s,n,o=t;const{endo:a}=e;if(a){const{k1neg:t,k1:e,k2neg:i,k2:c}=a.splitScalar(o);let{p:u,f:d}=this.wNAF(e),{p:p,f:h}=this.wNAF(c);u=l.constTimeNegate(t,u),p=l.constTimeNegate(i,p),p=new f(r.mul(p.px,a.beta),p.py,p.pz),s=u.add(p),n=d.add(h)}else{const{p:t,f:e}=this.wNAF(o);s=t,n=e}return f.normalizeZ([s,n])[0]}multiplyAndAddUnsafe(t,e,r){const s=f.BASE,n=(t,e)=>e!==Ut&&e!==Ct&&t.equals(s)?t.multiply(e):t.multiplyUnsafe(e),o=n(this,e).add(n(t,r));return o.is0()?void 0:o}toAffine(t){const{px:e,py:s,pz:n}=this,o=this.is0();null==t&&(t=o?r.ONE:r.inv(n));const a=r.mul(e,t),i=r.mul(s,t),c=r.mul(n,t);if(o)return{x:r.ZERO,y:r.ZERO};if(!r.eql(c,r.ONE))throw new Error("invZ was invalid");return{x:a,y:i}}isTorsionFree(){const{h:t,isTorsionFree:r}=e;if(t===Ct)return!0;if(r)return r(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:t,clearCofactor:r}=e;return t===Ct?this:r?r(f,this):this.multiplyUnsafe(e.h)}toRawBytes(t=!0){return this.assertValidity(),s(f,this,t)}toHex(t=!0){return H(this.toRawBytes(t))}}f.BASE=new f(e.Gx,e.Gy,r.ONE),f.ZERO=new f(r.ZERO,r.ONE,r.ZERO);const p=e.nBitLength,l=function(t,e){const r=(t,e)=>{const r=e.negate();return t?r:e},s=t=>({windows:Math.ceil(e/t)+1,windowSize:2**(t-1)});return{constTimeNegate:r,unsafeLadder(e,r){let s=t.ZERO,n=e;for(;r>Rt;)r&Dt&&(s=s.add(n)),n=n.double(),r>>=Dt;return s},precomputeWindow(t,e){const{windows:r,windowSize:n}=s(e),o=[];let a=t,i=a;for(let t=0;t<r;t++){i=a,o.push(i);for(let t=1;t<n;t++)i=i.add(a),o.push(i);a=i.double()}return o},wNAF(e,n,o){const{windows:a,windowSize:i}=s(e);let c=t.ZERO,u=t.BASE;const d=BigInt(2**e-1),f=2**e,p=BigInt(e);for(let t=0;t<a;t++){const e=t*i;let s=Number(o&d);o>>=p,s>i&&(s-=f,o+=Dt);const a=e,l=e+Math.abs(s)-1,h=t%2!=0,m=s<0;0===s?u=u.add(r(h,n[a])):c=c.add(r(m,n[l]))}return{p:c,f:u}},wNAFCached(t,e,r,s){const n=t._WINDOW_SIZE||1;let o=e.get(t);return o||(o=this.precomputeWindow(t,n),1!==n&&e.set(t,s(o))),this.wNAF(n,o,r)}}}(f,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function jt(t){const e=function(t){const e=Nt(t);return ct(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}(t),{Fp:r,n:s}=e,n=r.BYTES+1,o=2*r.BYTES+1;function a(t){return bt(t,s)}function i(t){return wt(t,s)}const{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:d,isWithinCurveOrder:f}=Ht({...e,toBytes(t,e,s){const n=e.toAffine(),o=r.toBytes(n.x),a=Q;return s?a(Uint8Array.from([e.hasEvenY()?2:3]),o):a(Uint8Array.from([4]),o,r.toBytes(n.y))},fromBytes(t){const e=t.length,s=t[0],a=t.subarray(1);if(e!==n||2!==s&&3!==s){if(e===o&&4===s){return{x:r.fromBytes(a.subarray(0,r.BYTES)),y:r.fromBytes(a.subarray(r.BYTES,2*r.BYTES))}}throw new Error(`Point of length ${e} was invalid. Expected ${n} compressed bytes or ${o} uncompressed bytes`)}{const t=z(a);if(!(Ut<(i=t)&&i<r.ORDER))throw new Error("Point is not on curve");const e=d(t);let n=r.sqrt(e);return 1==(1&s)!==((n&Ct)===Ct)&&(n=r.neg(n)),{x:t,y:n}}var i}}),p=t=>H(Y(t,e.nByteLength));function l(t){return t>s>>Ct}const h=(t,e,r)=>z(t.slice(e,r));class m{constructor(t,e,r){this.r=t,this.s=e,this.recovery=r,this.assertValidity()}static fromCompact(t){const r=e.nByteLength;return t=W("compactSignature",t,2*r),new m(h(t,0,r),h(t,r,2*r))}static fromDER(t){const{r:e,s:r}=Vt.toSig(W("DER",t));return new m(e,r)}assertValidity(){if(!f(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!f(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(t){return new m(this.r,this.s,t)}recoverPublicKey(t){const{r:s,s:n,recovery:o}=this,u=y(W("msgHash",t));if(null==o||![0,1,2,3].includes(o))throw new Error("recovery id invalid");const d=2===o||3===o?s+e.n:s;if(d>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");const f=0==(1&o)?"02":"03",l=c.fromHex(f+p(d)),h=i(d),m=a(-u*h),x=a(n*h),b=c.BASE.multiplyAndAddUnsafe(l,m,x);if(!b)throw new Error("point at infinify");return b.assertValidity(),b}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return X(this.toDERHex())}toDERHex(){return Vt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return X(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}const x={isValidPrivateKey(t){try{return u(t),!0}catch(t){return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const t=kt(e.n);return Pt(e.randomBytes(t),e.n)},precompute:(t=8,e=c.BASE)=>(e._setWindowSize(t),e.multiply(BigInt(3)),e)};function b(t){const e=q(t),r="string"==typeof t,s=(e||r)&&t.length;return e?s===n||s===o:r?s===2*n||s===2*o:t instanceof c}const g=e.bits2int||function(t){const r=z(t),s=8*t.length-e.nBitLength;return s>0?r>>BigInt(s):r},y=e.bits2int_modN||function(t){return a(g(t))},w=st(e.nBitLength);function I(t){if("bigint"!=typeof t)throw new Error("bigint expected");if(!(Ut<=t&&t<w))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Y(t,e.nByteLength)}function B(t,s,n=T){if(["recovered","canonical"].some((t=>t in n)))throw new Error("sign() legacy options not supported");const{hash:o,randomBytes:d}=e;let{lowS:p,prehash:h,extraEntropy:x}=n;null==p&&(p=!0),t=W("msgHash",t),h&&(t=W("prehashed msgHash",o(t)));const b=y(t),w=u(s),B=[I(w),I(b)];if(null!=x){const t=!0===x?d(r.BYTES):x;B.push(W("extraEntropy",t))}const S=Q(...B),O=b;return{seed:S,k2sig:function(t){const e=g(t);if(!f(e))return;const r=i(e),s=c.BASE.multiply(e).toAffine(),n=a(s.x);if(n===Ut)return;const o=a(r*a(O+n*w));if(o===Ut)return;let u=(s.x===n?0:2)|Number(s.y&Ct),d=o;return p&&l(o)&&(d=function(t){return l(t)?a(-t):t}(o),u^=1),new m(n,d,u)}}}const T={lowS:e.lowS,prehash:!1},S={lowS:e.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:e,getPublicKey:function(t,e=!0){return c.fromPrivateKey(t).toRawBytes(e)},getSharedSecret:function(t,e,r=!0){if(b(t))throw new Error("first arg must be private key");if(!b(e))throw new Error("second arg must be public key");return c.fromHex(e).multiply(u(t)).toRawBytes(r)},sign:function(t,r,s=T){const{seed:n,k2sig:o}=B(t,r,s),a=e;return at(a.hash.outputLen,a.nByteLength,a.hmac)(n,o)},verify:function(t,r,s,n=S){const o=t;if(r=W("msgHash",r),s=W("publicKey",s),"strict"in n)throw new Error("options.strict was renamed to lowS");const{lowS:u,prehash:d}=n;let f,p;try{if("string"==typeof o||q(o))try{f=m.fromDER(o)}catch(t){if(!(t instanceof Vt.Err))throw t;f=m.fromCompact(o)}else{if("object"!=typeof o||"bigint"!=typeof o.r||"bigint"!=typeof o.s)throw new Error("PARSE");{const{r:t,s:e}=o;f=new m(t,e)}}p=c.fromHex(s)}catch(t){if("PARSE"===t.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(u&&f.hasHighS())return!1;d&&(r=e.hash(r));const{r:l,s:h}=f,x=y(r),b=i(h),g=a(x*b),w=a(l*b),I=c.BASE.multiplyAndAddUnsafe(p,g,w)?.toAffine();return!!I&&a(I.x)===l},ProjectivePoint:c,Signature:m,utils:x}}function Zt(t,e){if(Tt(t),!t.isValid(e.A)||!t.isValid(e.B)||!t.isValid(e.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const r=function(t,e){const r=t.ORDER;let s=Ut;for(let t=r-Ct;t%Mt===Ut;t/=Mt)s+=Ct;const n=s,o=Mt<<n-Ct-Ct,a=o*Mt,i=(r-Ct)/a,c=(i-Ct)/Mt,u=a-Ct,d=o,f=t.pow(e,i),p=t.pow(e,(i+Ct)/Mt);let l=(e,r)=>{let s=f,o=t.pow(r,u),a=t.sqr(o);a=t.mul(a,r);let i=t.mul(e,a);i=t.pow(i,c),i=t.mul(i,o),o=t.mul(i,r),a=t.mul(i,e);let l=t.mul(a,o);i=t.pow(l,d);let h=t.eql(i,t.ONE);o=t.mul(a,p),i=t.mul(l,s),a=t.cmov(o,a,h),l=t.cmov(i,l,h);for(let e=n;e>Ct;e--){let r=e-Mt;r=Mt<<r-Ct;let n=t.pow(l,r);const i=t.eql(n,t.ONE);o=t.mul(a,s),s=t.mul(s,s),n=t.mul(l,s),a=t.cmov(o,a,i),l=t.cmov(n,l,i)}return{isValid:h,value:a}};if(t.ORDER%Lt===qt){const r=(t.ORDER-qt)/Lt,s=t.sqrt(t.neg(e));l=(e,n)=>{let o=t.sqr(n);const a=t.mul(e,n);o=t.mul(o,a);let i=t.pow(o,r);i=t.mul(i,a);const c=t.mul(i,s),u=t.mul(t.sqr(i),n),d=t.eql(u,e);return{isValid:d,value:t.cmov(c,i,d)}}}return l}(t,e.Z);if(!t.isOdd)throw new Error("Fp.isOdd is not implemented!");return s=>{let n,o,a,i,c,u,d,f;n=t.sqr(s),n=t.mul(n,e.Z),o=t.sqr(n),o=t.add(o,n),a=t.add(o,t.ONE),a=t.mul(a,e.B),i=t.cmov(e.Z,t.neg(o),!t.eql(o,t.ZERO)),i=t.mul(i,e.A),o=t.sqr(a),u=t.sqr(i),c=t.mul(u,e.A),o=t.add(o,c),o=t.mul(o,a),u=t.mul(u,i),c=t.mul(u,e.B),o=t.add(o,c),d=t.mul(n,a);const{isValid:p,value:l}=r(o,u);f=t.mul(n,s),f=t.mul(f,l),d=t.cmov(d,a,p),f=t.cmov(f,l,p);const h=t.isOdd(s)===t.isOdd(f);return f=t.cmov(t.neg(f),f,h),d=t.div(d,i),{x:d,y:f}}}const Kt=z;function Gt(t,e){if(t<0||t>=1<<8*e)throw new Error(`bad I2OSP call: value=${t} length=${e}`);const r=Array.from({length:e}).fill(0);for(let s=e-1;s>=0;s--)r[s]=255&t,t>>>=8;return new Uint8Array(r)}function Xt(t,e){const r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t[s]^e[s];return r}function zt(t){if(!q(t))throw new Error("Uint8Array expected")}function $t(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function Yt(t,e,r){ct(r,{DST:"stringOrUint8Array",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:s,k:n,m:o,hash:a,expand:i,DST:c}=r;zt(t),$t(e);const u=function(t){if(q(t))return t;if("string"==typeof t)return tt(t);throw new Error("DST must be Uint8Array or string")}(c),d=s.toString(2).length,f=Math.ceil((d+n)/8),p=e*o*f;let l;if("xmd"===i)l=function(t,e,r,s){zt(t),zt(e),$t(r),e.length>255&&(e=s(Q(tt("H2C-OVERSIZE-DST-"),e)));const{outputLen:n,blockLen:o}=s,a=Math.ceil(r/n);if(a>255)throw new Error("Invalid xmd length");const i=Q(e,Gt(e.length,1)),c=Gt(0,o),u=Gt(r,2),d=new Array(a),f=s(Q(c,t,u,Gt(0,1),i));d[0]=s(Q(f,Gt(1,1),i));for(let t=1;t<=a;t++){const e=[Xt(f,d[t-1]),Gt(t+1,1),i];d[t]=s(Q(...e))}return Q(...d).slice(0,r)}(t,u,p,a);else if("xof"===i)l=function(t,e,r,s,n){if(zt(t),zt(e),$t(r),e.length>255){const t=Math.ceil(2*s/8);e=n.create({dkLen:t}).update(tt("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return n.create({dkLen:r}).update(t).update(Gt(r,2)).update(e).update(Gt(e.length,1)).digest()}(t,u,p,n,a);else{if("_internal_pass"!==i)throw new Error('expand must be "xmd" or "xof"');l=t}const h=new Array(e);for(let t=0;t<e;t++){const e=new Array(o);for(let r=0;r<o;r++){const n=f*(r+t*o),a=l.subarray(n,n+f);e[r]=bt(Kt(a),s)}h[t]=e}return h}function Jt(t,e){const r=e.map((t=>Array.from(t).reverse()));return(e,s)=>{const[n,o,a,i]=r.map((r=>r.reduce(((r,s)=>t.add(t.mul(r,e),s)))));return e=t.div(n,o),s=t.mul(s,t.div(a,i)),{x:e,y:s}}}function Wt(t,e,r){if("function"!=typeof e)throw new Error("mapToCurve() must be defined");return{hashToCurve(s,n){const o=Yt(s,2,{...r,DST:r.DST,...n}),a=t.fromAffine(e(o[0])),i=t.fromAffine(e(o[1])),c=a.add(i).clearCofactor();return c.assertValidity(),c},encodeToCurve(s,n){const o=Yt(s,1,{...r,DST:r.encodeDST,...n}),a=t.fromAffine(e(o[0])).clearCofactor();return a.assertValidity(),a}}}class Qt extends I{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,function(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");l(t.outputLen),l(t.blockLen)}(t);const r=w(e);if(this.iHash=t.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 s=this.blockLen,n=new Uint8Array(s);n.set(r.length>s?t.create().update(r).digest():r);for(let t=0;t<n.length;t++)n[t]^=54;this.iHash.update(n),this.oHash=t.create();for(let t=0;t<n.length;t++)n[t]^=106;this.oHash.update(n),n.fill(0)}update(t){return m(this),this.iHash.update(t),this}digestInto(t){m(this),h(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:e,iHash:r,finished:s,destroyed:n,blockLen:o,outputLen:a}=this;return t.finished=s,t.destroyed=n,t.blockLen=o,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const te=(t,e,r)=>new Qt(t,e).update(r).digest(); /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ function ee(t){return{hash:t,hmac:(r,...s)=>te(t,r,e.concatBytes(...s)),randomBytes:e.randomBytes}}te.create=(t,e)=>new Qt(t,e); /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ const re=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),se=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ne=BigInt(1),oe=BigInt(2),ae=(t,e)=>(t+e/oe)/e;const ie=Et(re,void 0,void 0,{sqrt:function(t){const e=re,r=BigInt(3),s=BigInt(6),n=BigInt(11),o=BigInt(22),a=BigInt(23),i=BigInt(44),c=BigInt(88),u=t*t*t%e,d=u*u*t%e,f=yt(d,r,e)*d%e,p=yt(f,r,e)*d%e,l=yt(p,oe,e)*u%e,h=yt(l,n,e)*l%e,m=yt(h,o,e)*h%e,x=yt(m,i,e)*m%e,b=yt(x,c,e)*x%e,g=yt(b,i,e)*m%e,y=yt(g,r,e)*d%e,w=yt(y,a,e)*h%e,I=yt(w,s,e)*u%e,B=yt(I,oe,e);if(!ie.eql(ie.sqr(B),t))throw new Error("Cannot find square root");return B}}),ce=function(t,e){const r=e=>jt({...t,...ee(e)});return Object.freeze({...r(e),create:r})}({a:BigInt(0),b:BigInt(7),Fp:ie,n:se,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=se,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),s=-ne*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),n=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=r,a=BigInt("0x100000000000000000000000000000000"),i=ae(o*t,e),c=ae(-s*t,e);let u=bt(t-i*r-c*n,e),d=bt(-i*s-c*o,e);const f=u>a,p=d>a;if(f&&(u=e-u),p&&(d=e-d),u>a||d>a)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:f,k1:u,k2neg:p,k2:d}}}},r.sha256);BigInt(0),ce.ProjectivePoint,Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0"))); /*! micro-eth-signer - MIT License (c) 2021 Paul Miller (paulmillr.com) */ const ue=t=>ce.getPublicKey(t,!1),de=t=>ce.ProjectivePoint.fromHex(t).toRawBytes(!1);function fe(t){return/^0x/i.test(t)?t:`0x${t}`}function pe(t){return t.replace(/^0x/i,"")}function le(t){return e.hexToBytes(pe(t))}const he={fromPrivateKey:t=>("string"==typeof t&&(t=le(t)),he.fromPublicKey(ue(t))),fromPublicKey(t){const r=de(t),s=e.bytesToHex(V(r.subarray(1,65))).slice(24);return he.checksum(s)},checksum(t){const r=pe(t.toLowerCase());if(40!==r.length)throw new Error("Invalid address, must have 40 chars");const s=pe(e.bytesToHex(V(r)));let n="";for(let t=0;t<r.length;t++){const e=Number.parseInt(s[t],16);let o=r[t];e>7&&(o=o.toUpperCase()),n+=o}return fe(n)},verifyChecksum(t){const r=pe(t);if(40!==r.length)throw new Error("Invalid address, must have 40 chars");if(r===r.toLowerCase()||r===r.toUpperCase())return!0;const s=e.bytesToHex(V(r.toLowerCase()));for(let t=0;t<40;t++){const e=r[t],n=Number.parseInt(s[t],16);if(n>7&&e.toUpperCase()!==e)return!1;if(n<=7&&e.toLowerCase()!==e)return!1}return!0}};function me(t){return BigInt(be(t))}function xe(t){return Number.parseInt(e.bytesToHex(t),16)}function be(t){return fe(e.bytesToHex(t))}function ge(t){return 1&(t=pe(t)).length&&(t="0"+t),e.hexToBytes(t)}function ye(t,e){const r=e-t.length;if(r<=0)return t;const s=new Uint8Array(e);return s.set(t,r),s}class we{}const Ie="AVM",Be="EVM",Te="PVM",Se=[Ie,Be,Te];var Oe,ve;exports.TypeSymbols=void 0,(Oe=exports.TypeSymbols||(exports.TypeSymbols={})).Codec="codec",Oe.BaseTx="avax.BaseTx",Oe.TransferableOutput="avax.TransferableOutput",Oe.TransferableInput="avax.TransferableInput",Oe.TransferableOp="avax.TransferableOp",Oe.UTXOID="avax.UTXOID",Oe.UTXO="avax.Utxo",Oe.Id="common.Id",Oe.Address="common.Address",Oe.NodeId="common.NodeId",Oe.Int="primitives.Int",Oe.BigIntPr="primitives.BigInt",Oe.StringPr="primitives.String",Oe.Byte="primitives.Byte",Oe.Bytes="primitives.Bytes",Oe.Short="primitives.Short",Oe.Input="secp256k1fx.Input",Oe.TransferInput="secp256k1fx.TransferInput",Oe.TransferOutput="secp256k1fx.TransferOutput",Oe.OutputOwners="secp256k1fx.OutputOwners",Oe.OutputOwnersList="secp256k1fx.OutputOwnersList",Oe.Credential="secp256k1fx.Credential",Oe.Signature="secp256k1fx.Signature",Oe.SecpMintOperation="secp256k1fx.MintOperation",Oe.SecpMintOutput="secp256k1fx.MintOutput",Oe.NftFxMintOperation="nftfx.MintOperation",Oe.NftFxMintOutput="nftfx.MintOutput",Oe.NftFxTransferOperation="nftfx.TransferOperation",Oe.NftFxTransferOutput="nftfx.TransferOutput",Oe.NftFxCredential="nftfx.Credential",Oe.AvmBaseTx="avm.BaseTx",Oe.AvmExportTx="avm.ExportTx",Oe.AvmImportTx="avm.ImportTx",Oe.CreateAssetTx="avm.CreateAssetTx",Oe.OperationTx="avm.OperationTx",Oe.InitialState="avm.InitialState",Oe.AvmSignedTx="avm.SignedTx",Oe.PvmBaseTx="pvm.BaseTx",Oe.StakeableLockIn="pvm.StakeableLockIn",Oe.StakeableLockOut="pvm.StakeableLockOut",Oe.AddDelegatorTx="pvm.AddDelegatorTx",Oe.AddValidatorTx="pvm.AddValidatorTx",Oe.AddPermissionlessDelegatorTx="pvm.AddPermissionlessDelegator",Oe.AddPermissionlessValidatorTx="pvm.AddPermissionlessValidator",Oe.Validator="pvm.Validator",Oe.SubnetValidator="pvm.SubnetValidator",Oe.Signer="pvm.signer",Oe.SignerEmpty="pvm.signerEmpty",Oe.ProofOfPossession="pvm.proofOfPossession",Oe.AddSubnetValidatorTx="pvm.AddSubnetValidator",Oe.AdvanceTimeTx="pvm.AdvanceTimeTx",Oe.CreateChainTx="pvm.CreateChainTx",Oe.CreateSubnetTx="pvm.CreateSubnetTx",Oe.PvmExportTx="pvm.ExportTx",Oe.PvmImportTx="pvm.ImportTx",Oe.RewardValidatorTx="pvm.RewardValidatorTx",Oe.RemoveSubnetValidatorTx="pvm.RemoveSubnetValidator",Oe.TransformSubnetTx="pvm.TransformSubnetTx",Oe.TransferSubnetOwnershipTx="pvm.TransferSubnetOwnershipTx",Oe.EvmExportTx="evm.ExportTx",Oe.EvmInput="evm.Input",Oe.EvmOutput="evm.Output",Oe.EvmImportTx="evm.ImportTx",exports.Address=ve=class extends we{address;_type=exports.TypeSymbols.Address;constructor(t){super(),this.address=t}static fromBytes(t){return[new ve(t.slice(0,20)),t.slice(20)]}[i](t,e){return e.stylize(this.toJSON(),"string")}toJSON(t="avax"){return this.toString(t)}static fromString(t){return new ve(d(t))}static fromHex(t){return new ve(ge(t))}toHex(){return be(this.address)}toBytes(){return ye(this.address,20)}toString(t="avax"){return p(t,this.address)}value(){return this.toString()}},exports.Address=ve=o([t=>{},a("design:paramtypes",[Uint8Array])],exports.Address);const Ee={encode:s=>t.base58.encode(e.concatBytes(s,r.sha256(s).subarray(-4))),decode:e=>t.base58.decode(e).subarray(0,-4)},Ae=(t,e)=>{let r;for(r=0;r<t.length&&r<e.length;r++){const s=t[r],n=e[r];if(s!==n)return s-n}return r===t.length&&r===e.length?0:r===t.length?-1:1};var ke,Pe;exports.Id=ke=class extends we{idVal;_type=exports.TypeSymbols.Id;constructor(t){super(),this.idVal=t}static fromBytes(t){return[new ke(t.slice(0,32)),t.slice(32)]}static compare(t,e){return Ae(t.toBytes(),e.toBytes())}[i](t,e){return e.stylize(this.toString(),"string")}toBytes(){return ye(this.idVal,32)}toJSON(){return this.toString()}toString(){return Ee.encode(this.toBytes())}static fromString(t){return ke.fromBytes(Ee.decode(t))[0]}static fromHex(t){return new ke(ge(t))}value(){return this.toString()}},exports.Id=ke=o([t=>{},a("design:paramtypes",[Uint8Array])],exports.Id);const Re="NodeID-";exports.NodeId=Pe=class extends we{idVal;_type=exports.TypeSymbols.NodeId;constructor(t){super(),this.idVal=t}static fromBytes(t){return[new Pe(t.slice(0,20)),t.slice(20)]}[i](t,e){return e.stylize(this.toString(),"string")}toBytes(){return ye(this.idVal,20)}toJSON(){return this.toString()}toString(){return Re+Ee.encode(this.toBytes())}static fromString(t){if(!t.includes(Re))throw new Error("ID is missing prefix");return this.fromBytes(Ee.decode(t.replace(Re,"")))[0]}static fromHex(t){return new Pe(ge(t))}value(){return this.toString()}},exports.NodeId=Pe=o([t=>{},a("design:paramtypes",[Uint8Array])],exports.NodeId);const De=new exports.Id(new Uint8Array(32)),Ne=new exports.Id(new Uint8Array(32)),_e="avax",Fe="cascade",Ve="denali",Ue="everest",Ce="testing",Me="local",qe="custom",Le="flare",He="costwo",je="localflare",Ze="songbird",Ke="coston",Ge={1:_e,2:Fe,3:Ve,4:Ue,10:Ce,12345:Me,14:Le,114:He,162:je,5:Ze,7:Ke},Xe=t=>Ge[t]??qe;var ze,$e=Object.freeze({__proto__:null,CascadeHRP:Fe,CascadeID:2,CascadeName:"cascade",CostonHRP:Ke,CostonID:7,CostonName:"coston",CostwoHRP:He,CostwoID:114,CostwoName:"costwo",DenaliHRP:Ve,DenaliID:3,DenaliName:"denali",EverestHRP:Ue,EverestID:4,EverestName:"everest",FallbackHRP:qe,FlareHRP:Le,FlareID:14,FlareName:"flare",FujiHRP:"fuji",FujiID:5,FujiName:"fuji",LocalFlareHRP:je,LocalFlareID:162,LocalFlareName:"localflare",LocalHRP:Me,LocalID:12345,LocalName:"local",MainnetHRP:_e,MainnetID:1,MainnetName:"mainnet",NetworkIDToHRP:Ge,PlatformChainID:Ne,PrimaryNetworkID:De,SongbirdHRP:Ze,SongbirdID:5,SongbirdName:"songbird",TestnetID:5,TestnetName:"testnet",UnitTestHRP:Ce,UnitTestID:10,UnitTestName:"testing",getHRP:Xe});class Ye{getVM(){return this.vm}}class Je extends Ye{getInputs(){return this.baseTx?.inputs??[]}getBlockchainId(){return this.baseTx?.BlockchainId.toString()??""}getSigIndices(){return this.getInputs().map((t=>t.sigIndicies())).filter((t=>void 0!==t))}}exports.Int=ze=class extends we{int;_type=exports.TypeSymbols.Int;constructor(t){super(),this.int=t}static fromBytes(t){return[new ze(xe(t.slice(0,4))),t.slice(4)]}[i](){return this.value()}toJSON(){return this.int}toBytes(){return ye(ge(this.int.toString(16)),4)}value(){return this.int}},exports.Int=ze=o([t=>{},a("design:paramtypes",[Number])],exports.Int);const We=t=>new exports.Int(t).toBytes(),Qe=(t,e,r)=>tr(t,e.fromBytes,r),tr=(t,e,r)=>{let s;[s,t]=exports.Int.fromBytes(t);const n=[];for(let o=0;o<s.value();o++){if(0===t.length)throw new Error("not enough bytes");let s;[s,t]=e(t,r),n.push(s)}return[n,t]},er=t=>({fromBytes:(e,r)=>Qe(e,t,r)}),rr={fromBytes:(t,e)=>{if(!e)throw new Error("codec required when using unpackCodecList");return tr(t,e.UnpackPrefix,e)}},sr=(t,r)=>e.concatBytes(We(t.length),...t.map((t=>t.toBytes(r))));function nr(t,e,r){return[...e.map((e=>{let s;if(!t.length)throw new Error("not enough bytes");return[s,t]=e.fromBytes(t,r),s})),t]}function or(t,r){return e.concatBytes(...t.map((t=>Array.isArray(t)?sr(t,r):t.toBytes(r))))}function ar(t,...e){return or(e,t)}var ir,cr,ur,dr,fr,pr;function lr(t){return t._type===exports.TypeSymbols.TransferOutput}function hr(t){return t._type===exports.TypeSymbols.StakeableLockOut}function mr(t){return t._type===exports.TypeSymbols.OutputOwners}function xr(t){return t._type===exports.TypeSymbols.StakeableLockIn}function br(t){return t._type===exports.TypeSymbols.TransferInput}exports.BigIntPr=ir=class extends we{bigint;_type=exports.TypeSymbols.BigIntPr;constructor(t){super(),this.bigint=t}[i](){return this.bigint}static fromBytes(t){return[new ir(me(t.slice(0,8))),t.slice(8)]}toJSON(){return this.bigint.toString()}toBytes(){return ye(ge(this.bigint.toString(16)),8)}value(){return this.bigint}},exports.BigIntPr=ir=o([t=>{},a("design:paramtypes",[BigInt])],exports.BigIntPr),exports.Byte=cr=class extends we{byte;_type=exports.TypeSymbols.Byte;constructor(t){super(),this.byte=t}static fromBytes(t){return[new cr(t.slice(0,1)),t.slice(1)]}toJSON(){return be(this.byte)}toBytes(){return this.byte}},exports.Byte=cr=o([t=>{},a("design:paramtypes",[Uint8Array])],exports.Byte),exports.Bytes=ur=class extends we{bytes;_type=exports.TypeSymbols.Bytes;constructor(t){super(),this.bytes=t}toString(e="utf8"){return t.bytesToString(e,this.bytes)}toJSON(){return be(this.bytes)}static fromBytes(t){const[e,r]=exports.Int.fromBytes(t);return[new ur(r.slice(0,e.value())),r.slice(e.value())]}toBytes(){return e.concatBytes(We(this.bytes.length),this.bytes)}},exports.Bytes=ur=o([t=>{},a("design:paramtypes",[Uint8Array])],exports.Bytes),exports.Short=dr=class extends we{short;_type=exports.TypeSymbols.Short;constructor(t){super(),this.short=t}static fromBytes(t){return[new dr(xe(t.slice(0,2))),t.slice(2)]}toJSON(){return this.short.toString()}toBytes(){return ye(ge(this.short.toString(16)),2)}value(){return this.short}},exports.Short=dr=o([t=>{},a("design:paramtypes",[Number])],exports.Short),exports.Stringpr=fr=class extends we{string;_type=exports.TypeSymbols.StringPr;constructor(t){super(),this.string=t}static fromBytes(t){const[e,r]=exports.Short.fromBytes(t);return[new fr((new TextDecoder).decode(r.slice(0,e.value()))),r.slice(e.value())]}toJSON(){return this.string}toBytes(){return e.concatBytes(ye(ge(this.string.length.toString(16)),2),(new TextEncoder).encode(this.string))}value(){return this.string}},exports.Stringpr=fr=o([t=>{},a("design:paramtypes",[String])],exports.Stringpr);var gr,yr,wr,Ir,Br,Tr,Sr,Or;function vr(t){return t.map((t=>new exports.Address(t)))}exports.Signature=pr=class{sig;_type=exports.TypeSymbols.Signature;constructor(t){if(this.sig=t,65!==t.length)throw new Error("incorrect number of bytes for signature")}toJSON(){return e.bytesToHex(this.sig)}static fromJSON(t){return new pr(le(t))}static fromBytes(t){return[new pr(t.slice(0,65)),t.slice(65)]}[i](t,e){return e.stylize(this.toString(),"string")}toString(){return be(this.sig)}toBytes(){return ye(this.sig,65)}},exports.Signature=pr=o([t=>{},a("design:paramtypes",[Uint8Array])],exports.Signature),exports.Credential=gr=class{signatures;_type=exports.TypeSymbols.Credential;constructor(t){this.signatures=t}static fromBytes(t,e){const[r,s]=Qe(t,exports.Signature,e);return[new gr(r),s]}toJSON(){return this.signatures}static fromJSON(t){return new gr(t.map((t=>exports.Signature.fromJSON(t))))}setSignature(t,e){if(t>=this.signatures.length)throw new Error(`index ${t} is out of bounds for credential`);this.signatures[t]=new exports.Signature(e)}getSignatures(){return this.signatures.map((t=>t.toString()))}toBytes(t){return sr(this.signatures,t)}},exports.Credential=gr=o([t=>{},a("design:paramtypes",[Array])],exports.Credential),exports.Input=yr=class{sigIndices;_type=exports.TypeSymbols.Input;constructor(t){this.sigIndices=t}static fromNative(t){return new yr(t.map((t=>new exports.Int(t))))}static fromBytes(t){const[e,r]=nr(t,[er(exports.Int)]);return[new yr(e),r]}values(){return this.sigIndices.map((t=>t.value()))}toBytes(t){return sr(this.sigIndices,t)}},exports.Input=yr=o([t=>{},a("design:paramtypes",[Array])],exports.Input),exports.OutputOwners=wr=class{locktime;threshold;addrs;_type=exports.TypeSymbols.OutputOwners;constructor(t,e,r){this.locktime=t,this.threshold=e,this.addrs=r}static fromNative(t,e=0n,r=1){return new wr(new exports.BigIntPr(e),new exports.Int(r),vr(t))}static fromBytes(t,e){const[r,s,n,o]=nr(t,[exports.BigIntPr,exports.Int,er(exports.Address)],e);return[new wr(r,s,n),o]}toBytes(t){return e.concatBytes(or([this.locktime,this.threshold],t),sr(this.addrs,t))}equals(t){return this.locktime.value()===t.locktime.value()&&this.threshold.value()===t.threshold.value()&&this.addrs.length===t.addrs.length&&this.addrs.every(((e,r)=>e.value()===t.addrs[r].value()))}},exports.OutputOwners=wr=o([t=>{},a("design:paramtypes",[exports.BigIntPr,exports.Int,Array])],exports.OutputOwners),exports.MintOutput=Ir=class{outputOwners;_type=exports.TypeSymbols.SecpMintOutput;constructor(t){this.outputOwners=t}static fromBytes(t,e){let r;return[r,t]=exports.OutputOwners.fromBytes(t,e),[new Ir(r),t]}toBytes(t){return this.outputOwners.toBytes(t)}},exports.MintOutput=Ir=o([t=>{},a("design:paramtypes",[exports.OutputOwners])],exports.MintOutput),exports.TransferOutput=Br=class{amt;outputOwners;_type=exports.TypeSymbols.TransferOutput;constructor(t,e){this.amt=t,this.outputOwners=e}amount(){return this.amt.value()}getLocktime(){return this.outputOwners.locktime.value()}getOwners(){return this.outputOwners.addrs.map((t=>t.toBytes()))}getThreshold(){return this.outputOwners.threshold.value()}static fromBytes(t){const[e,r,s]=nr(t,[exports.BigIntPr,exports.OutputOwners]);return[new Br(e,r),s]}toBytes(t){return or([this.amt,this.outputOwners],t)}},exports.TransferOutput=Br=o([t=>{},a("design:paramtypes",[exports.BigIntPr,exports.OutputOwners])],exports.TransferOutput),exports.MintOperation=Tr=class{input;mintOutput;transferOutput;_type=exports.TypeSymbols.SecpMintOperation;constructor(t,e,r){this.input=t,this.mintOutput=e,this.transferOutput=r}static fromBytes(t){const[e,r,s,n]=nr(t,[exports.Input,exports.MintOutput,exports.TransferOutput]);return[new Tr(e,r,s),n]}toBytes(t){return e.concatBytes(this.input.toBytes(t),this.mintOutput.toBytes(t),this.transferOutput.toBytes(t))}},exports.MintOperation=Tr=o([t=>{},a("design:paramtypes",[exports.Input,exports.MintOutput,exports.TransferOutput])],exports.MintOperation),exports.OutputOwnersList=Sr=class{outputOwners;_type=exports.TypeSymbols.OutputOwnersList;constructor(t){this.outputOwners=t}static fromBytes(t,e){const[r,s]=Qe(t,exports.OutputOwners,e);return[new Sr(r),s]}toBytes(t){return sr(this.outputOwners,t)}},exports.OutputOwnersList=Sr=o([t=>{},a("design:paramtypes",[Array])],exports.OutputOwnersList),exports.TransferInput=Or=class{amt;input;_type=exports.TypeSymbols.TransferInput;constructor(t,e){this.amt=t,this.input=e}static fromBytes(t){const[e,r,s]=nr(t,[exports.BigIntPr,exports.Input]);return[new Or(e,r),s]}static fromNative(t,e){return new Or(new exports.BigIntPr(t),exports.Input.fromNative(e))}sigIndicies(){return this.input.values()}amount(){return this.amt.value()}toBytes(t){return or([this.amt,this.input],t)}},exports.TransferInput=Or=o([t=>{},a("design:paramtypes",[exports.BigIntPr,exports.Input])],exports.TransferInput);const Er=Object.freeze([exports.TransferInput,exports.MintOutput,exports.TransferOutput,exports.MintOperation,exports.Credential]);var Ar;let kr=Ar=class{txID;outputIdx;_type=exports.TypeSymbols.UTXOID;constructor(t,e){this.txID=t,this.outputIdx=e}static fromBytes(t,e){const[r,s,n]=nr(t,[exports.Id,exports.Int],e);return[new Ar(r,s),n]}static