libp2p-middleware-evm
Version:
EVM middleware for libp2p
3 lines • 126 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PMiddlewareEvm = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Libp2PMiddlewareEvm=(()=>{var Ir=Object.defineProperty;var Ds=Object.getOwnPropertyDescriptor;var Zs=Object.getOwnPropertyNames;var Hs=Object.prototype.hasOwnProperty;var Nr=(r,e)=>{for(var t in e)Ir(r,t,{get:e[t],enumerable:!0})},zs=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Zs(e))!Hs.call(r,s)&&s!==t&&Ir(r,s,{get:()=>e[s],enumerable:!(n=Ds(e,s))||n.enumerable});return r};var Fs=r=>zs(Ir({},"__esModule",{value:!0}),r);var Na={};Nr(Na,{middlewareEVM:()=>Ia});var wn="6.14.4";function Ws(r,e,t){let n=e.split("|").map(i=>i.trim());for(let i=0;i<n.length;i++)switch(e){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof r===e)return}let s=new Error(`invalid value for type ${e}`);throw s.code="INVALID_ARGUMENT",s.argument=`value.${t}`,s.value=r,s}function Or(r,e,t){for(let n in e){let s=e[n],i=t?t[n]:null;i&&Ws(s,i,n),Object.defineProperty(r,n,{enumerable:!0,value:s,writable:!1})}}function _t(r,e){if(r==null)return"null";if(e==null&&(e=new Set),typeof r=="object"){if(e.has(r))return"[Circular]";e.add(r)}if(Array.isArray(r))return"[ "+r.map(t=>_t(t,e)).join(", ")+" ]";if(r instanceof Uint8Array){let t="0123456789abcdef",n="0x";for(let s=0;s<r.length;s++)n+=t[r[s]>>4],n+=t[r[s]&15];return n}if(typeof r=="object"&&typeof r.toJSON=="function")return _t(r.toJSON(),e);switch(typeof r){case"boolean":case"number":case"symbol":return r.toString();case"bigint":return BigInt(r).toString();case"string":return JSON.stringify(r);case"object":{let t=Object.keys(r);return t.sort(),"{ "+t.map(n=>`${_t(n,e)}: ${_t(r[n],e)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function bn(r,e,t){let n=r;{let i=[];if(t){if("message"in t||"code"in t||"name"in t)throw new Error(`value will overwrite populated values: ${_t(t)}`);for(let o in t){if(o==="shortMessage")continue;let a=t[o];i.push(o+"="+_t(a))}}i.push(`code=${e}`),i.push(`version=${wn}`),i.length&&(r+=" ("+i.join(", ")+")")}let s;switch(e){case"INVALID_ARGUMENT":s=new TypeError(r);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":s=new RangeError(r);break;default:s=new Error(r)}return Or(s,{code:e}),t&&Object.assign(s,t),s.shortMessage==null&&Or(s,{shortMessage:n}),s}function be(r,e,t,n){if(!r)throw bn(e,t,n)}function P(r,e,t,n){be(r,e,"INVALID_ARGUMENT",{argument:t,value:n})}var Ks=["NFD","NFC","NFKD","NFKC"].reduce((r,e)=>{try{if("test".normalize(e)!=="test")throw new Error("bad");if(e==="NFD"&&"\xE9".normalize("NFD")!=="e\u0301")throw new Error("broken");r.push(e)}catch{}return r},[]);function Rr(r){be(Ks.indexOf(r)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:r}})}function Cr(r,e,t){if(t==null&&(t=""),r!==e){let n=t,s="new";t&&(n+=".",s+=" "+t),be(!1,`private constructor; use ${n}from* methods`,"UNSUPPORTED_OPERATION",{operation:s})}}function _n(r,e,t){if(r instanceof Uint8Array)return t?new Uint8Array(r):r;if(typeof r=="string"&&r.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)){let n=new Uint8Array((r.length-2)/2),s=2;for(let i=0;i<n.length;i++)n[i]=parseInt(r.substring(s,s+2),16),s+=2;return n}P(!1,"invalid BytesLike value",e||"value",r)}function K(r,e){return _n(r,e,!1)}function Ge(r,e){return _n(r,e,!0)}function $t(r,e){return!(typeof r!="string"||!r.match(/^0x[0-9A-Fa-f]*$/)||typeof e=="number"&&r.length!==2+2*e||e===!0&&r.length%2!==0)}var vn="0123456789abcdef";function z(r){let e=K(r),t="0x";for(let n=0;n<e.length;n++){let s=e[n];t+=vn[(s&240)>>4]+vn[s&15]}return t}function Le(r){return"0x"+r.map(e=>z(e).substring(2)).join("")}function Ue(r){return $t(r,!0)?(r.length-2)/2:K(r).length}function Gs(r,e,t){let n=K(r);be(e>=n.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(n),length:e,offset:e+1});let s=new Uint8Array(e);return s.fill(0),t?s.set(n,e-n.length):s.set(n,0),z(s)}function Lr(r,e){return Gs(r,e,!0)}var En=BigInt(0),Va=BigInt(1),Et=9007199254740991;function Xe(r,e){switch(typeof r){case"bigint":return r;case"number":return P(Number.isInteger(r),"underflow",e||"value",r),P(r>=-Et&&r<=Et,"overflow",e||"value",r),BigInt(r);case"string":try{if(r==="")throw new Error("empty string");return r[0]==="-"&&r[1]!=="-"?-BigInt(r.substring(1)):BigInt(r)}catch(t){P(!1,`invalid BigNumberish string: ${t.message}`,e||"value",r)}}P(!1,"invalid BigNumberish value",e||"value",r)}function Ur(r,e){let t=Xe(r,e);return be(t>=En,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:r}),t}function Ye(r,e){switch(typeof r){case"bigint":return P(r>=-Et&&r<=Et,"overflow",e||"value",r),Number(r);case"number":return P(Number.isInteger(r),"underflow",e||"value",r),P(r>=-Et&&r<=Et,"overflow",e||"value",r),r;case"string":try{if(r==="")throw new Error("empty string");return Ye(BigInt(r),e)}catch(t){P(!1,`invalid numeric string: ${t.message}`,e||"value",r)}}P(!1,"invalid numeric value",e||"value",r)}function Jt(r,e){let n=Ur(r,"value").toString(16);if(e==null)n.length%2&&(n="0"+n);else{let s=Ye(e,"width");for(be(s*2>=n.length,`value exceeds width (${s} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:r});n.length<s*2;)n="0"+n}return"0x"+n}function Pr(r){let e=Ur(r,"value");if(e===En)return new Uint8Array([]);let t=e.toString(16);t.length%2&&(t="0"+t);let n=new Uint8Array(t.length/2);for(let s=0;s<n.length;s++){let i=s*2;n[s]=parseInt(t.substring(i,i+2),16)}return n}function Xs(r,e,t,n,s){P(!1,`invalid codepoint at offset ${e}; ${r}`,"bytes",t)}function kn(r,e,t,n,s){if(r==="BAD_PREFIX"||r==="UNEXPECTED_CONTINUE"){let i=0;for(let o=e+1;o<t.length&&t[o]>>6===2;o++)i++;return i}return r==="OVERRUN"?t.length-e-1:0}function Ys(r,e,t,n,s){return r==="OVERLONG"?(P(typeof s=="number","invalid bad code point for replacement","badCodepoint",s),n.push(s),0):(n.push(65533),kn(r,e,t,n,s))}var Js=Object.freeze({error:Xs,ignore:kn,replace:Ys});function jt(r,e){P(typeof r=="string","invalid string value","str",r),e!=null&&(Rr(e),r=r.normalize(e));let t=[];for(let n=0;n<r.length;n++){let s=r.charCodeAt(n);if(s<128)t.push(s);else if(s<2048)t.push(s>>6|192),t.push(s&63|128);else if((s&64512)==55296){n++;let i=r.charCodeAt(n);P(n<r.length&&(i&64512)===56320,"invalid surrogate pair","str",r);let o=65536+((s&1023)<<10)+(i&1023);t.push(o>>18|240),t.push(o>>12&63|128),t.push(o>>6&63|128),t.push(o&63|128)}else t.push(s>>12|224),t.push(s>>6&63|128),t.push(s&63|128)}return new Uint8Array(t)}function Mt(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Vt(r,...e){if(!(r instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function An(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Mt(r.outputLen),Mt(r.blockLen)}function ve(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Qt(r,e){Vt(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var er=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Sn=r=>r instanceof Uint8Array;var Tn=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),tr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),he=(r,e)=>r<<32-e|r>>>e,Qs=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Qs)throw new Error("Non little-endian hardware is not supported");function ei(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function $e(r){if(typeof r=="string"&&(r=ei(r)),!Sn(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Bn(...r){let e=new Uint8Array(r.reduce((n,s)=>n+s.length,0)),t=0;return r.forEach(n=>{if(!Sn(n))throw new Error("Uint8Array expected");e.set(n,t),t+=n.length}),e}var Pe=class{clone(){return this._cloneInto()}},hc={}.toString;function rr(r){let e=n=>r().update($e(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function In(r){let e=(n,s)=>r(s).update($e(n)).digest(),t=r({});return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}function Nn(r=32){if(er&&typeof er.getRandomValues=="function")return er.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}var nr=class extends Pe{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,An(e);let n=$e(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?e.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),i.fill(0)}update(e){return ve(this),this.iHash.update(e),this}digestInto(e){ve(this),Vt(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},$r=(r,e,t)=>new nr(r,e).update(t).digest();$r.create=(r,e)=>new nr(r,e);function ti(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(t>>s&i),a=Number(t&i),c=n?4:0,u=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+u,a,n)}var sr=class extends Pe{constructor(e,t,n,s){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=tr(this.buffer)}update(e){ve(this);let{view:t,buffer:n,blockLen:s}=this;e=$e(e);let i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=tr(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ve(this),Qt(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let l=o;l<s;l++)t[l]=0;ti(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=tr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,d[l],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%t&&e.buffer.set(n),e}};var ri=(r,e,t)=>r&e^~r&t,ni=(r,e,t)=>r&e^r&t^e&t,si=new Uint32Array([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]),je=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Me=new Uint32Array(64),jr=class extends sr{constructor(){super(64,32,8,!1),this.A=je[0]|0,this.B=je[1]|0,this.C=je[2]|0,this.D=je[3]|0,this.E=je[4]|0,this.F=je[5]|0,this.G=je[6]|0,this.H=je[7]|0}get(){let{A:e,B:t,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[e,t,n,s,i,o,a,c]}set(e,t,n,s,i,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let l=0;l<16;l++,t+=4)Me[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let x=Me[l-15],T=Me[l-2],S=he(x,7)^he(x,18)^x>>>3,h=he(T,17)^he(T,19)^T>>>10;Me[l]=h+Me[l-7]+S+Me[l-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){let x=he(a,6)^he(a,11)^he(a,25),T=d+x+ri(a,c,u)+si[l]+Me[l]|0,h=(he(n,2)^he(n,13)^he(n,22))+ni(n,s,i)|0;d=u,u=c,c=a,a=o+T|0,o=i,i=s,s=n,n=T+h|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,s,i,o,a,c,u,d)}roundClean(){Me.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var On=rr(()=>new jr);var ir=BigInt(4294967295),Rn=BigInt(32);function ii(r,e=!1){return e?{h:Number(r&ir),l:Number(r>>Rn&ir)}:{h:Number(r>>Rn&ir)|0,l:Number(r&ir)|0}}function Cn(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:i,l:o}=ii(r[s],e);[t[s],n[s]]=[i,o]}return[t,n]}var Ln=(r,e,t)=>r<<t|e>>>32-t,Un=(r,e,t)=>e<<t|r>>>32-t,Pn=(r,e,t)=>e<<t-32|r>>>64-t,$n=(r,e,t)=>r<<t-32|e>>>64-t;var[Vn,qn,Dn]=[[],[],[]],oi=BigInt(0),qt=BigInt(1),ai=BigInt(2),ci=BigInt(7),ui=BigInt(256),li=BigInt(113);for(let r=0,e=qt,t=1,n=0;r<24;r++){[t,n]=[n,(2*t+3*n)%5],Vn.push(2*(5*n+t)),qn.push((r+1)*(r+2)/2%64);let s=oi;for(let i=0;i<7;i++)e=(e<<qt^(e>>ci)*li)%ui,e&ai&&(s^=qt<<(qt<<BigInt(i))-qt);Dn.push(s)}var[di,fi]=Cn(Dn,!0),jn=(r,e,t)=>t>32?Pn(r,e,t):Ln(r,e,t),Mn=(r,e,t)=>t>32?$n(r,e,t):Un(r,e,t);function hi(r,e=24){let t=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let o=0;o<10;o++)t[o]=r[o]^r[o+10]^r[o+20]^r[o+30]^r[o+40];for(let o=0;o<10;o+=2){let a=(o+8)%10,c=(o+2)%10,u=t[c],d=t[c+1],l=jn(u,d,1)^t[a],x=Mn(u,d,1)^t[a+1];for(let T=0;T<50;T+=10)r[o+T]^=l,r[o+T+1]^=x}let s=r[2],i=r[3];for(let o=0;o<24;o++){let a=qn[o],c=jn(s,i,a),u=Mn(s,i,a),d=Vn[o];s=r[d],i=r[d+1],r[d]=c,r[d+1]=u}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)t[a]=r[o+a];for(let a=0;a<10;a++)r[o+a]^=~t[(a+2)%10]&t[(a+4)%10]}r[0]^=di[n],r[1]^=fi[n]}t.fill(0)}var or=class r extends Pe{constructor(e,t,n,s=!1,i=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=s,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Mt(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=Tn(this.state)}keccak(){hi(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){ve(this);let{blockLen:t,state:n}=this;e=$e(e);let s=e.length;for(let i=0;i<s;){let o=Math.min(t-this.pos,s-i);for(let a=0;a<o;a++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:s}=this;e[n]^=t,(t&128)!==0&&n===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){ve(this,!1),Vt(e),this.finish();let t=this.state,{blockLen:n}=this;for(let s=0,i=e.length;s<i;){this.posOut>=n&&this.keccak();let o=Math.min(n-this.posOut,i-s);e.set(t.subarray(this.posOut,this.posOut+o),s),this.posOut+=o,s+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Mt(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Qt(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:t,suffix:n,outputLen:s,rounds:i,enableXOF:o}=this;return e||(e=new r(t,n,s,o,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=n,e.outputLen=s,e.enableXOF=o,e.destroyed=this.destroyed,e}},Ve=(r,e,t)=>rr(()=>new or(e,r,t)),Bc=Ve(6,144,224/8),Ic=Ve(6,136,256/8),Nc=Ve(6,104,384/8),Oc=Ve(6,72,512/8),Rc=Ve(1,144,224/8),Zn=Ve(1,136,256/8),Cc=Ve(1,104,384/8),Lc=Ve(1,72,512/8),Hn=(r,e,t)=>In((n={})=>new or(e,r,n.dkLen===void 0?t:n.dkLen,!0)),Uc=Hn(31,168,128/8),Pc=Hn(31,136,256/8);var zn=!1,Fn=function(r){return Zn(r)},Wn=Fn;function pe(r){let e=K(r,"data");return z(Wn(e))}pe._=Fn;pe.lock=function(){zn=!0};pe.register=function(r){if(zn)throw new TypeError("keccak256 is locked");Wn=r};Object.freeze(pe);var Dr={};Nr(Dr,{bitGet:()=>bi,bitLen:()=>wi,bitMask:()=>Dt,bitSet:()=>vi,bytesToHex:()=>Je,bytesToNumberBE:()=>_e,bytesToNumberLE:()=>ur,concatBytes:()=>kt,createHmacDrbg:()=>qr,ensureBytes:()=>oe,equalBytes:()=>yi,hexToBytes:()=>Qe,hexToNumber:()=>Vr,numberToBytesBE:()=>qe,numberToBytesLE:()=>lr,numberToHexUnpadded:()=>Xn,numberToVarBytesBE:()=>gi,utf8ToBytes:()=>xi,validateObject:()=>De});var Gn=BigInt(0),ar=BigInt(1),pi=BigInt(2),cr=r=>r instanceof Uint8Array,mi=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Je(r){if(!cr(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t<r.length;t++)e+=mi[r[t]];return e}function Xn(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function Vr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}function Qe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let t=new Uint8Array(e/2);for(let n=0;n<t.length;n++){let s=n*2,i=r.slice(s,s+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");t[n]=o}return t}function _e(r){return Vr(Je(r))}function ur(r){if(!cr(r))throw new Error("Uint8Array expected");return Vr(Je(Uint8Array.from(r).reverse()))}function qe(r,e){return Qe(r.toString(16).padStart(e*2,"0"))}function lr(r,e){return qe(r,e).reverse()}function gi(r){return Qe(Xn(r))}function oe(r,e,t){let n;if(typeof e=="string")try{n=Qe(e)}catch(i){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${i}`)}else if(cr(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof t=="number"&&s!==t)throw new Error(`${r} expected ${t} bytes, got ${s}`);return n}function kt(...r){let e=new Uint8Array(r.reduce((n,s)=>n+s.length,0)),t=0;return r.forEach(n=>{if(!cr(n))throw new Error("Uint8Array expected");e.set(n,t),t+=n.length}),e}function yi(r,e){if(r.length!==e.length)return!1;for(let t=0;t<r.length;t++)if(r[t]!==e[t])return!1;return!0}function xi(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function wi(r){let e;for(e=0;r>Gn;r>>=ar,e+=1);return e}function bi(r,e){return r>>BigInt(e)&ar}var vi=(r,e,t)=>r|(t?ar:Gn)<<BigInt(e),Dt=r=>(pi<<BigInt(r-1))-ar,Mr=r=>new Uint8Array(r),Kn=r=>Uint8Array.from(r);function qr(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=Mr(r),s=Mr(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...l)=>t(s,n,...l),c=(l=Mr())=>{s=a(Kn([0]),l),n=a(),l.length!==0&&(s=a(Kn([1]),l),n=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,x=[];for(;l<e;){n=a();let T=n.slice();x.push(T),l+=n.length}return kt(...x)};return(l,x)=>{o(),c(l);let T;for(;!(T=x(u()));)c();return o(),T}}var _i={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||r instanceof Uint8Array,isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function De(r,e,t={}){let n=(s,i,o)=>{let a=_i[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[s];if(!(o&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${i}`)};for(let[s,i]of Object.entries(e))n(s,i,!1);for(let[s,i]of Object.entries(t))n(s,i,!0);return r}var F=BigInt(0),H=BigInt(1),et=BigInt(2),Ei=BigInt(3),Zr=BigInt(4),Yn=BigInt(5),Jn=BigInt(8),ki=BigInt(9),Ai=BigInt(16);function Y(r,e){let t=r%e;return t>=F?t:e+t}function Si(r,e,t){if(t<=F||e<F)throw new Error("Expected power/modulo > 0");if(t===H)return F;let n=H;for(;e>F;)e&H&&(n=n*r%t),r=r*r%t,e>>=H;return n}function ae(r,e,t){let n=r;for(;e-- >F;)n*=n,n%=t;return n}function dr(r,e){if(r===F||e<=F)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=Y(r,e),n=e,s=F,i=H,o=H,a=F;for(;t!==F;){let u=n/t,d=n%t,l=s-o*u,x=i-a*u;n=t,t=d,s=o,i=a,o=l,a=x}if(n!==H)throw new Error("invert: does not exist");return Y(s,e)}function Ti(r){let e=(r-H)/et,t,n,s;for(t=r-H,n=0;t%et===F;t/=et,n++);for(s=et;s<r&&Si(s,e,r)!==r-H;s++);if(n===1){let o=(r+H)/Zr;return function(c,u){let d=c.pow(u,o);if(!c.eql(c.sqr(d),u))throw new Error("Cannot find square root");return d}}let i=(t+H)/et;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,d=a.pow(a.mul(a.ONE,s),t),l=a.pow(c,i),x=a.pow(c,t);for(;!a.eql(x,a.ONE);){if(a.eql(x,a.ZERO))return a.ZERO;let T=1;for(let h=a.sqr(x);T<u&&!a.eql(h,a.ONE);T++)h=a.sqr(h);let S=a.pow(d,H<<BigInt(u-T-1));d=a.sqr(S),l=a.mul(l,S),x=a.mul(x,d),u=T}return l}}function Bi(r){if(r%Zr===Ei){let e=(r+H)/Zr;return function(n,s){let i=n.pow(s,e);if(!n.eql(n.sqr(i),s))throw new Error("Cannot find square root");return i}}if(r%Jn===Yn){let e=(r-Yn)/Jn;return function(n,s){let i=n.mul(s,et),o=n.pow(i,e),a=n.mul(s,o),c=n.mul(n.mul(a,et),o),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),s))throw new Error("Cannot find square root");return u}}return r%Ai,Ti(r)}var Ii=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Hr(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Ii.reduce((n,s)=>(n[s]="function",n),e);return De(r,t)}function Ni(r,e,t){if(t<F)throw new Error("Expected power > 0");if(t===F)return r.ONE;if(t===H)return e;let n=r.ONE,s=e;for(;t>F;)t&H&&(n=r.mul(n,s)),s=r.sqr(s),t>>=H;return n}function Oi(r,e){let t=new Array(e.length),n=e.reduce((i,o,a)=>r.is0(o)?i:(t[a]=i,r.mul(i,o)),r.ONE),s=r.inv(n);return e.reduceRight((i,o,a)=>r.is0(o)?i:(t[a]=r.mul(i,t[a]),r.mul(i,o)),s),t}function zr(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Qn(r,e,t=!1,n={}){if(r<=F)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:i}=zr(r,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=Bi(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:i,MASK:Dt(s),ZERO:F,ONE:H,create:c=>Y(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return F<=c&&c<r},is0:c=>c===F,isOdd:c=>(c&H)===H,neg:c=>Y(-c,r),eql:(c,u)=>c===u,sqr:c=>Y(c*c,r),add:(c,u)=>Y(c+u,r),sub:(c,u)=>Y(c-u,r),mul:(c,u)=>Y(c*u,r),pow:(c,u)=>Ni(a,c,u),div:(c,u)=>Y(c*dr(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>dr(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>Oi(a,c),cmov:(c,u,d)=>d?u:c,toBytes:c=>t?lr(c,i):qe(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return t?ur(c):_e(c)}});return Object.freeze(a)}function es(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Fr(r){let e=es(r);return e+Math.ceil(e/2)}function ts(r,e,t=!1){let n=r.length,s=es(e),i=Fr(e);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let o=t?_e(r):ur(r),a=Y(o,e-H)+H;return t?lr(a,s):qe(a,s)}var Ci=BigInt(0),Wr=BigInt(1);function rs(r,e){let t=(s,i)=>{let o=i.negate();return s?o:i},n=s=>{let i=Math.ceil(e/s)+1,o=2**(s-1);return{windows:i,windowSize:o}};return{constTimeNegate:t,unsafeLadder(s,i){let o=r.ZERO,a=s;for(;i>Ci;)i&Wr&&(o=o.add(a)),a=a.double(),i>>=Wr;return o},precomputeWindow(s,i){let{windows:o,windowSize:a}=n(i),c=[],u=s,d=u;for(let l=0;l<o;l++){d=u,c.push(d);for(let x=1;x<a;x++)d=d.add(u),c.push(d);u=d.double()}return c},wNAF(s,i,o){let{windows:a,windowSize:c}=n(s),u=r.ZERO,d=r.BASE,l=BigInt(2**s-1),x=2**s,T=BigInt(s);for(let S=0;S<a;S++){let h=S*c,w=Number(o&l);o>>=T,w>c&&(w-=x,o+=Wr);let v=h,B=h+Math.abs(w)-1,O=S%2!==0,M=w<0;w===0?d=d.add(t(O,i[v])):u=u.add(t(M,i[B]))}return{p:u,f:d}},wNAFCached(s,i,o,a){let c=s._WINDOW_SIZE||1,u=i.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&i.set(s,a(u))),this.wNAF(c,u,o)}}}function Kr(r){return Hr(r.Fp),De(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...zr(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function Li(r){let e=Kr(r);De(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:s}=e;if(t){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:Ui,hexToBytes:Pi}=Dr,tt={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(r){let{Err:e}=tt;if(r.length<2||r[0]!==2)throw new e("Invalid signature integer tag");let t=r[1],n=r.subarray(2,t+2);if(!t||n.length!==t)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:Ui(n),l:r.subarray(t+2)}},toSig(r){let{Err:e}=tt,t=typeof r=="string"?Pi(r):r;if(!(t instanceof Uint8Array))throw new Error("ui8a expected");let n=t.length;if(n<2||t[0]!=48)throw new e("Invalid signature tag");if(t[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:s,l:i}=tt._parseInt(t.subarray(2)),{d:o,l:a}=tt._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:s,s:o}},hexFromSig(r){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,t=u=>{let d=u.toString(16);return d.length&1?`0${d}`:d},n=e(t(r.s)),s=e(t(r.r)),i=n.length/2,o=s.length/2,a=t(i),c=t(o);return`30${t(o+i+4)}02${c}${s}02${a}${n}`}},Ee=BigInt(0),ue=BigInt(1),Kc=BigInt(2),ns=BigInt(3),Gc=BigInt(4);function $i(r){let e=Li(r),{Fp:t}=e,n=e.toBytes||((S,h,w)=>{let v=h.toAffine();return kt(Uint8Array.from([4]),t.toBytes(v.x),t.toBytes(v.y))}),s=e.fromBytes||(S=>{let h=S.subarray(1),w=t.fromBytes(h.subarray(0,t.BYTES)),v=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:w,y:v}});function i(S){let{a:h,b:w}=e,v=t.sqr(S),B=t.mul(v,S);return t.add(t.add(B,t.mul(S,h)),w)}if(!t.eql(t.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function o(S){return typeof S=="bigint"&&Ee<S&&S<e.n}function a(S){if(!o(S))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(S){let{allowedPrivateKeyLengths:h,nByteLength:w,wrapPrivateKey:v,n:B}=e;if(h&&typeof S!="bigint"){if(S instanceof Uint8Array&&(S=Je(S)),typeof S!="string"||!h.includes(S.length))throw new Error("Invalid key");S=S.padStart(w*2,"0")}let O;try{O=typeof S=="bigint"?S:_e(oe("private key",S,w))}catch{throw new Error(`private key must be ${w} bytes, hex or bigint, not ${typeof S}`)}return v&&(O=Y(O,B)),a(O),O}let u=new Map;function d(S){if(!(S instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(h,w,v){if(this.px=h,this.py=w,this.pz=v,h==null||!t.isValid(h))throw new Error("x required");if(w==null||!t.isValid(w))throw new Error("y required");if(v==null||!t.isValid(v))throw new Error("z required")}static fromAffine(h){let{x:w,y:v}=h||{};if(!h||!t.isValid(w)||!t.isValid(v))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");let B=O=>t.eql(O,t.ZERO);return B(w)&&B(v)?l.ZERO:new l(w,v,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let w=t.invertBatch(h.map(v=>v.pz));return h.map((v,B)=>v.toAffine(w[B])).map(l.fromAffine)}static fromHex(h){let w=l.fromAffine(s(oe("pointHex",h)));return w.assertValidity(),w}static fromPrivateKey(h){return l.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!t.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:w}=this.toAffine();if(!t.isValid(h)||!t.isValid(w))throw new Error("bad point: x or y not FE");let v=t.sqr(w),B=i(h);if(!t.eql(v,B))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){d(h);let{px:w,py:v,pz:B}=this,{px:O,py:M,pz:$}=h,A=t.eql(t.mul(w,$),t.mul(O,B)),N=t.eql(t.mul(v,$),t.mul(M,B));return A&&N}negate(){return new l(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:w}=e,v=t.mul(w,ns),{px:B,py:O,pz:M}=this,$=t.ZERO,A=t.ZERO,N=t.ZERO,U=t.mul(B,B),ce=t.mul(O,O),Z=t.mul(M,M),V=t.mul(B,O);return V=t.add(V,V),N=t.mul(B,M),N=t.add(N,N),$=t.mul(h,N),A=t.mul(v,Z),A=t.add($,A),$=t.sub(ce,A),A=t.add(ce,A),A=t.mul($,A),$=t.mul(V,$),N=t.mul(v,N),Z=t.mul(h,Z),V=t.sub(U,Z),V=t.mul(h,V),V=t.add(V,N),N=t.add(U,U),U=t.add(N,U),U=t.add(U,Z),U=t.mul(U,V),A=t.add(A,U),Z=t.mul(O,M),Z=t.add(Z,Z),U=t.mul(Z,V),$=t.sub($,U),N=t.mul(Z,ce),N=t.add(N,N),N=t.add(N,N),new l($,A,N)}add(h){d(h);let{px:w,py:v,pz:B}=this,{px:O,py:M,pz:$}=h,A=t.ZERO,N=t.ZERO,U=t.ZERO,ce=e.a,Z=t.mul(e.b,ns),V=t.mul(w,O),re=t.mul(v,M),ne=t.mul(B,$),Ne=t.add(w,v),g=t.add(O,M);Ne=t.mul(Ne,g),g=t.add(V,re),Ne=t.sub(Ne,g),g=t.add(w,B);let _=t.add(O,$);return g=t.mul(g,_),_=t.add(V,ne),g=t.sub(g,_),_=t.add(v,B),A=t.add(M,$),_=t.mul(_,A),A=t.add(re,ne),_=t.sub(_,A),U=t.mul(ce,g),A=t.mul(Z,ne),U=t.add(A,U),A=t.sub(re,U),U=t.add(re,U),N=t.mul(A,U),re=t.add(V,V),re=t.add(re,V),ne=t.mul(ce,ne),g=t.mul(Z,g),re=t.add(re,ne),ne=t.sub(V,ne),ne=t.mul(ce,ne),g=t.add(g,ne),V=t.mul(re,g),N=t.add(N,V),V=t.mul(_,g),A=t.mul(Ne,A),A=t.sub(A,V),V=t.mul(Ne,re),U=t.mul(_,U),U=t.add(U,V),new l(A,N,U)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return T.wNAFCached(this,u,h,w=>{let v=t.invertBatch(w.map(B=>B.pz));return w.map((B,O)=>B.toAffine(v[O])).map(l.fromAffine)})}multiplyUnsafe(h){let w=l.ZERO;if(h===Ee)return w;if(a(h),h===ue)return this;let{endo:v}=e;if(!v)return T.unsafeLadder(this,h);let{k1neg:B,k1:O,k2neg:M,k2:$}=v.splitScalar(h),A=w,N=w,U=this;for(;O>Ee||$>Ee;)O&ue&&(A=A.add(U)),$&ue&&(N=N.add(U)),U=U.double(),O>>=ue,$>>=ue;return B&&(A=A.negate()),M&&(N=N.negate()),N=new l(t.mul(N.px,v.beta),N.py,N.pz),A.add(N)}multiply(h){a(h);let w=h,v,B,{endo:O}=e;if(O){let{k1neg:M,k1:$,k2neg:A,k2:N}=O.splitScalar(w),{p:U,f:ce}=this.wNAF($),{p:Z,f:V}=this.wNAF(N);U=T.constTimeNegate(M,U),Z=T.constTimeNegate(A,Z),Z=new l(t.mul(Z.px,O.beta),Z.py,Z.pz),v=U.add(Z),B=ce.add(V)}else{let{p:M,f:$}=this.wNAF(w);v=M,B=$}return l.normalizeZ([v,B])[0]}multiplyAndAddUnsafe(h,w,v){let B=l.BASE,O=($,A)=>A===Ee||A===ue||!$.equals(B)?$.multiplyUnsafe(A):$.multiply(A),M=O(this,w).add(O(h,v));return M.is0()?void 0:M}toAffine(h){let{px:w,py:v,pz:B}=this,O=this.is0();h==null&&(h=O?t.ONE:t.inv(B));let M=t.mul(w,h),$=t.mul(v,h),A=t.mul(B,h);if(O)return{x:t.ZERO,y:t.ZERO};if(!t.eql(A,t.ONE))throw new Error("invZ was invalid");return{x:M,y:$}}isTorsionFree(){let{h,isTorsionFree:w}=e;if(h===ue)return!0;if(w)return w(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:w}=e;return h===ue?this:w?w(l,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return this.assertValidity(),n(l,this,h)}toHex(h=!0){return Je(this.toRawBytes(h))}}l.BASE=new l(e.Gx,e.Gy,t.ONE),l.ZERO=new l(t.ZERO,t.ONE,t.ZERO);let x=e.nBitLength,T=rs(l,e.endo?Math.ceil(x/2):x);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:o}}function ji(r){let e=Kr(r);return De(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function ss(r){let e=ji(r),{Fp:t,n}=e,s=t.BYTES+1,i=2*t.BYTES+1;function o(g){return Ee<g&&g<t.ORDER}function a(g){return Y(g,n)}function c(g){return dr(g,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:d,weierstrassEquation:l,isWithinCurveOrder:x}=$i({...e,toBytes(g,_,C){let D=_.toAffine(),q=t.toBytes(D.x),W=kt;return C?W(Uint8Array.from([_.hasEvenY()?2:3]),q):W(Uint8Array.from([4]),q,t.toBytes(D.y))},fromBytes(g){let _=g.length,C=g[0],D=g.subarray(1);if(_===s&&(C===2||C===3)){let q=_e(D);if(!o(q))throw new Error("Point is not on curve");let W=l(q),se=t.sqrt(W),ie=(se&ue)===ue;return(C&1)===1!==ie&&(se=t.neg(se)),{x:q,y:se}}else if(_===i&&C===4){let q=t.fromBytes(D.subarray(0,t.BYTES)),W=t.fromBytes(D.subarray(t.BYTES,2*t.BYTES));return{x:q,y:W}}else throw new Error(`Point of length ${_} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),T=g=>Je(qe(g,e.nByteLength));function S(g){let _=n>>ue;return g>_}function h(g){return S(g)?a(-g):g}let w=(g,_,C)=>_e(g.slice(_,C));class v{constructor(_,C,D){this.r=_,this.s=C,this.recovery=D,this.assertValidity()}static fromCompact(_){let C=e.nByteLength;return _=oe("compactSignature",_,C*2),new v(w(_,0,C),w(_,C,2*C))}static fromDER(_){let{r:C,s:D}=tt.toSig(oe("DER",_));return new v(C,D)}assertValidity(){if(!x(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!x(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(_){return new v(this.r,this.s,_)}recoverPublicKey(_){let{r:C,s:D,recovery:q}=this,W=N(oe("msgHash",_));if(q==null||![0,1,2,3].includes(q))throw new Error("recovery id invalid");let se=q===2||q===3?C+e.n:C;if(se>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let ie=(q&1)===0?"02":"03",Oe=u.fromHex(ie+T(se)),Re=c(se),wt=a(-W*Re),Pt=a(D*Re),Ce=u.BASE.multiplyAndAddUnsafe(Oe,wt,Pt);if(!Ce)throw new Error("point at infinify");return Ce.assertValidity(),Ce}hasHighS(){return S(this.s)}normalizeS(){return this.hasHighS()?new v(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Qe(this.toDERHex())}toDERHex(){return tt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Qe(this.toCompactHex())}toCompactHex(){return T(this.r)+T(this.s)}}let B={isValidPrivateKey(g){try{return d(g),!0}catch{return!1}},normPrivateKeyToScalar:d,randomPrivateKey:()=>{let g=Fr(e.n);return ts(e.randomBytes(g),e.n)},precompute(g=8,_=u.BASE){return _._setWindowSize(g),_.multiply(BigInt(3)),_}};function O(g,_=!0){return u.fromPrivateKey(g).toRawBytes(_)}function M(g){let _=g instanceof Uint8Array,C=typeof g=="string",D=(_||C)&&g.length;return _?D===s||D===i:C?D===2*s||D===2*i:g instanceof u}function $(g,_,C=!0){if(M(g))throw new Error("first arg must be private key");if(!M(_))throw new Error("second arg must be public key");return u.fromHex(_).multiply(d(g)).toRawBytes(C)}let A=e.bits2int||function(g){let _=_e(g),C=g.length*8-e.nBitLength;return C>0?_>>BigInt(C):_},N=e.bits2int_modN||function(g){return a(A(g))},U=Dt(e.nBitLength);function ce(g){if(typeof g!="bigint")throw new Error("bigint expected");if(!(Ee<=g&&g<U))throw new Error(`bigint expected < 2^${e.nBitLength}`);return qe(g,e.nByteLength)}function Z(g,_,C=V){if(["recovered","canonical"].some(Ke=>Ke in C))throw new Error("sign() legacy options not supported");let{hash:D,randomBytes:q}=e,{lowS:W,prehash:se,extraEntropy:ie}=C;W==null&&(W=!0),g=oe("msgHash",g),se&&(g=oe("prehashed msgHash",D(g)));let Oe=N(g),Re=d(_),wt=[ce(Re),ce(Oe)];if(ie!=null){let Ke=ie===!0?q(t.BYTES):ie;wt.push(oe("extraEntropy",Ke))}let Pt=kt(...wt),Ce=Oe;function Br(Ke){let bt=A(Ke);if(!x(bt))return;let gn=c(bt),ge=u.BASE.multiply(bt).toAffine(),vt=a(ge.x);if(vt===Ee)return;let Yt=a(gn*a(Ce+vt*Re));if(Yt===Ee)return;let yn=(ge.x===vt?0:2)|Number(ge.y&ue),xn=Yt;return W&&S(Yt)&&(xn=h(Yt),yn^=1),new v(vt,xn,yn)}return{seed:Pt,k2sig:Br}}let V={lowS:e.lowS,prehash:!1},re={lowS:e.lowS,prehash:!1};function ne(g,_,C=V){let{seed:D,k2sig:q}=Z(g,_,C),W=e;return qr(W.hash.outputLen,W.nByteLength,W.hmac)(D,q)}u.BASE._setWindowSize(8);function Ne(g,_,C,D=re){let q=g;if(_=oe("msgHash",_),C=oe("publicKey",C),"strict"in D)throw new Error("options.strict was renamed to lowS");let{lowS:W,prehash:se}=D,ie,Oe;try{if(typeof q=="string"||q instanceof Uint8Array)try{ie=v.fromDER(q)}catch(ge){if(!(ge instanceof tt.Err))throw ge;ie=v.fromCompact(q)}else if(typeof q=="object"&&typeof q.r=="bigint"&&typeof q.s=="bigint"){let{r:ge,s:vt}=q;ie=new v(ge,vt)}else throw new Error("PARSE");Oe=u.fromHex(C)}catch(ge){if(ge.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(W&&ie.hasHighS())return!1;se&&(_=e.hash(_));let{r:Re,s:wt}=ie,Pt=N(_),Ce=c(wt),Br=a(Pt*Ce),Ke=a(Re*Ce),bt=u.BASE.multiplyAndAddUnsafe(Oe,Br,Ke)?.toAffine();return bt?a(bt.x)===Re:!1}return{CURVE:e,getPublicKey:O,getSharedSecret:$,sign:ne,verify:Ne,ProjectivePoint:u,Signature:v,utils:B}}function Mi(r){return{hash:r,hmac:(e,...t)=>$r(r,e,Bn(...t)),randomBytes:Nn}}function is(r,e){let t=n=>ss({...r,...Mi(n)});return Object.freeze({...t(e),create:t})}var cs=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),os=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Vi=BigInt(1),Gr=BigInt(2),as=(r,e)=>(r+e/Gr)/e;function qi(r){let e=cs,t=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,d=u*u*r%e,l=ae(d,t,e)*d%e,x=ae(l,t,e)*d%e,T=ae(x,Gr,e)*u%e,S=ae(T,s,e)*T%e,h=ae(S,i,e)*S%e,w=ae(h,a,e)*h%e,v=ae(w,c,e)*w%e,B=ae(v,a,e)*h%e,O=ae(B,t,e)*d%e,M=ae(O,o,e)*S%e,$=ae(M,n,e)*u%e,A=ae($,Gr,e);if(!Xr.eql(Xr.sqr(A),r))throw new Error("Cannot find square root");return A}var Xr=Qn(cs,void 0,void 0,{sqrt:qi}),ke=is({a:BigInt(0),b:BigInt(7),Fp:Xr,n:os,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=os,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Vi*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,o=BigInt("0x100000000000000000000000000000000"),a=as(i*r,e),c=as(-n*r,e),u=Y(r-a*t-c*s,e),d=Y(-a*n-c*i,e),l=u>o,x=d>o;if(l&&(u=e-u),x&&(d=e-d),u>o||d>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:u,k2neg:x,k2:d}}}},On),su=BigInt(0);var iu=ke.ProjectivePoint;var fr="0x0000000000000000000000000000000000000000000000000000000000000000";var Yr=`Ethereum Signed Message:
`;var us=BigInt(0),ls=BigInt(1),ds=BigInt(2),fs=BigInt(27),hs=BigInt(28),hr=BigInt(35),At={};function ps(r){return Lr(Pr(r),32)}var Zt=class r{#e;#r;#n;#t;get r(){return this.#e}set r(e){P(Ue(e)===32,"invalid r","value",e),this.#e=z(e)}get s(){return this.#r}set s(e){P(Ue(e)===32,"invalid s","value",e);let t=z(e);P(parseInt(t.substring(0,3))<8,"non-canonical s","value",t),this.#r=t}get v(){return this.#n}set v(e){let t=Ye(e,"value");P(t===27||t===28,"invalid v","v",e),this.#n=t}get networkV(){return this.#t}get legacyChainId(){let e=this.networkV;return e==null?null:r.getChainId(e)}get yParity(){return this.v===27?0:1}get yParityAndS(){let e=K(this.s);return this.yParity&&(e[0]|=128),z(e)}get compactSerialized(){return Le([this.r,this.yParityAndS])}get serialized(){return Le([this.r,this.s,this.yParity?"0x1c":"0x1b"])}constructor(e,t,n,s){Cr(e,At,"Signature"),this.#e=t,this.#r=n,this.#n=s,this.#t=null}[Symbol.for("nodejs.util.inspect.custom")](){return`Signature { r: "${this.r}", s: "${this.s}", yParity: ${this.yParity}, networkV: ${this.networkV} }`}clone(){let e=new r(At,this.r,this.s,this.v);return this.networkV&&(e.#t=this.networkV),e}toJSON(){let e=this.networkV;return{_type:"signature",networkV:e!=null?e.toString():null,r:this.r,s:this.s,v:this.v}}static getChainId(e){let t=Xe(e,"v");return t==fs||t==hs?us:(P(t>=hr,"invalid EIP-155 v","v",e),(t-hr)/ds)}static getChainIdV(e,t){return Xe(e)*ds+BigInt(35+t-27)}static getNormalizedV(e){let t=Xe(e);return t===us||t===fs?27:t===ls||t===hs?28:(P(t>=hr,"invalid v","v",e),t&ls?27:28)}static from(e){function t(u,d){P(u,d,"signature",e)}if(e==null)return new r(At,fr,fr,27);if(typeof e=="string"){let u=K(e,"signature");if(u.length===64){let d=z(u.slice(0,32)),l=u.slice(32,64),x=l[0]&128?28:27;return l[0]&=127,new r(At,d,z(l),x)}if(u.length===65){let d=z(u.slice(0,32)),l=u.slice(32,64);t((l[0]&128)===0,"non-canonical s");let x=r.getNormalizedV(u[64]);return new r(At,d,z(l),x)}t(!1,"invalid raw signature length")}if(e instanceof r)return e.clone();let n=e.r;t(n!=null,"missing r");let s=ps(n),i=function(u,d){if(u!=null)return ps(u);if(d!=null){t($t(d,32),"invalid yParityAndS");let l=K(d);return l[0]&=127,z(l)}t(!1,"missing s")}(e.s,e.yParityAndS);t((K(i)[0]&128)==0,"non-canonical s");let{networkV:o,v:a}=function(u,d,l){if(u!=null){let x=Xe(u);return{networkV:x>=hr?x:void 0,v:r.getNormalizedV(x)}}if(d!=null)return t($t(d,32),"invalid yParityAndS"),{v:K(d)[0]&128?28:27};if(l!=null){switch(Ye(l,"sig.yParity")){case 0:return{v:27};case 1:return{v:28}}t(!1,"invalid yParity")}t(!1,"missing v")}(e.v,e.yParityAndS,e.yParity),c=new r(At,s,i,a);return o&&(c.#t=o),t(e.yParity==null||Ye(e.yParity,"sig.yParity")===c.yParity,"yParity mismatch"),t(e.yParityAndS==null||e.yParityAndS===c.yParityAndS,"yParityAndS mismatch"),c}};var St=class r{#e;constructor(e){P(Ue(e)===32,"invalid private key","privateKey","[REDACTED]"),this.#e=z(e)}get privateKey(){return this.#e}get publicKey(){return r.computePublicKey(this.#e)}get compressedPublicKey(){return r.computePublicKey(this.#e,!0)}sign(e){P(Ue(e)===32,"invalid digest length","digest",e);let t=ke.sign(Ge(e),Ge(this.#e),{lowS:!0});return Zt.from({r:Jt(t.r,32),s:Jt(t.s,32),v:t.recovery?28:27})}computeSharedSecret(e){let t=r.computePublicKey(e);return z(ke.getSharedSecret(Ge(this.#e),K(t),!1))}static computePublicKey(e,t){let n=K(e,"key");if(n.length===32){let i=ke.getPublicKey(n,!!t);return z(i)}if(n.length===64){let i=new Uint8Array(65);i[0]=4,i.set(n,1),n=i}let s=ke.ProjectivePoint.fromHex(n);return z(s.toRawBytes(t))}static recoverPublicKey(e,t){P(Ue(e)===32,"invalid digest length","digest",e);let n=Zt.from(t),s=ke.Signature.fromCompact(Ge(Le([n.r,n.s])));s=s.addRecoveryBit(n.yParity);let i=s.recoverPublicKey(Ge(e));return P(i!=null,"invalid signature for digest","signature",t),"0x"+i.toHex(!1)}static addPoints(e,t,n){let s=ke.ProjectivePoint.fromHex(r.computePublicKey(e).substring(2)),i=ke.ProjectivePoint.fromHex(r.computePublicKey(t).substring(2));return"0x"+s.add(i).toHex(!!n)}};var Di=BigInt(0),Zi=BigInt(36);function ms(r){r=r.toLowerCase();let e=r.substring(2).split(""),t=new Uint8Array(40);for(let s=0;s<40;s++)t[s]=e[s].charCodeAt(0);let n=K(pe(t));for(let s=0;s<40;s+=2)n[s>>1]>>4>=8&&(e[s]=e[s].toUpperCase()),(n[s>>1]&15)>=8&&(e[s+1]=e[s+1].toUpperCase());return"0x"+e.join("")}var Jr={};for(let r=0;r<10;r++)Jr[String(r)]=String(r);for(let r=0;r<26;r++)Jr[String.fromCharCode(65+r)]=String(10+r);var gs=15;function Hi(r){r=r.toUpperCase(),r=r.substring(4)+r.substring(0,2)+"00";let e=r.split("").map(n=>Jr[n]).join("");for(;e.length>=gs;){let n=e.substring(0,gs);e=parseInt(n,10)%97+e.substring(n.length)}let t=String(98-parseInt(e,10)%97);for(;t.length<2;)t="0"+t;return t}var zi=function(){let r={};for(let e=0;e<36;e++){let t="0123456789abcdefghijklmnopqrstuvwxyz"[e];r[t]=BigInt(e)}return r}();function Fi(r){r=r.toLowerCase();let e=Di;for(let t=0;t<r.length;t++)e=e*Zi+zi[r[t]];return e}function Qr(r){if(P(typeof r=="string","invalid address","address",r),r.match(/^(0x)?[0-9a-fA-F]{40}$/)){r.startsWith("0x")||(r="0x"+r);let e=ms(r);return P(!r.match(/([A-F].*[a-f])|([a-f].*[A-F])/)||e===r,"bad address checksum","address",r),e}if(r.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){P(r.substring(2,4)===Hi(r),"bad icap checksum","address",r);let e=Fi(r.substring(4)).toString(16);for(;e.length<40;)e="0"+e;return ms("0x"+e)}P(!1,"invalid address","address",r)}function ys(r){let e;return typeof r=="string"?e=St.computePublicKey(r,!1):e=r.publicKey,Qr(pe("0x"+e.substring(4)).substring(26))}function en(r,e){return ys(St.recoverPublicKey(r,e))}function tn(r){return typeof r=="string"&&(r=jt(r)),pe(Le([jt(Yr),jt(String(r.length)),r]))}function pr(r,e){let t=tn(r);return en(t,e)}var m={};Nr(m,{BRAND:()=>wo,DIRTY:()=>rt,EMPTY_PATH:()=>Xi,INVALID:()=>E,NEVER:()=>na,OK:()=>J,ParseStatus:()=>G,Schema:()=>R,ZodAny:()=>ze,ZodArray:()=>Be,ZodBigInt:()=>st,ZodBoolean:()=>it,ZodBranded:()=>zt,ZodCatch:()=>gt,ZodDate:()=>ot,ZodDefault:()=>mt,ZodDiscriminatedUnion:()=>yr,ZodEffects:()=>fe,ZodEnum:()=>ht,ZodError:()=>ee,ZodFirstPartyTypeKind:()=>k,ZodFunction:()=>wr,ZodIntersection:()=>lt,ZodIssueCode:()=>f,ZodLazy:()=>dt,ZodLiteral:()=>ft,ZodMap:()=>Rt,ZodNaN:()=>Lt,ZodNativeEnum:()=>pt,ZodNever:()=>me,ZodNull:()=>ct,ZodNullable:()=>we,ZodNumber:()=>nt,ZodObject:()=>te,ZodOptional:()=>le,ZodParsedType:()=>y,ZodPipeline:()=>Ft,ZodPromise:()=>Fe,ZodReadonly:()=>yt,ZodRecord:()=>xr,ZodSchema:()=>R,ZodSet:()=>Ct,ZodString:()=>He,ZodSymbol:()=>Nt,ZodTransformer:()=>fe,ZodTuple:()=>xe,ZodType:()=>R,ZodUndefined:()=>at,ZodUnion:()=>ut,ZodUnknown:()=>Te,ZodVoid:()=>Ot,addIssueToContext:()=>p,any:()=>Bo,array:()=>Ro,bigint:()=>Eo,boolean:()=>Bs,coerce:()=>ra,custom:()=>As,date:()=>ko,datetimeRegex:()=>Es,defaultErrorMap:()=>Ae,discriminatedUnion:()=>Po,effect:()=>Ko,enum:()=>zo,function:()=>Do,getErrorMap:()=>Tt,getParsedType:()=>ye,instanceof:()=>vo,intersection:()=>$o,isAborted:()=>mr,isAsync:()=>Bt,isDirty:()=>gr,isValid:()=>Ze,late:()=>bo,lazy:()=>Zo,literal:()=>Ho,makeIssue:()=>Ht,map:()=>Vo,nan:()=>_o,nativeEnum:()=>Fo,never:()=>No,null:()=>To,nullable:()=>Xo,number:()=>Ts,object:()=>Co,objectUtil:()=>rn,oboolean:()=>ta,onumber:()=>ea,optional:()=>Go,ostring:()=>Qo,pipeline:()=>Jo,preprocess:()=>Yo,promise:()=>Wo,quotelessJson:()=>Wi,record:()=>Mo,set:()=>qo,setErrorMap:()=>Gi,strictObject:()=>Lo,string:()=>Ss,symbol:()=>Ao,transformer:()=>Ko,tuple:()=>jo,undefined:()=>So,union:()=>Uo,unknown:()=>Io,util:()=>L,void:()=>Oo});var L;(function(r){r.assertEqual=s=>{};function e(s){}r.assertIs=e;function t(s){throw new Error}r.assertNever=t,r.arrayToEnum=s=>{let i={};for(let o of s)i[o]=o;return i},r.getValidEnumValues=s=>{let i=r.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),o={};for(let a of i)o[a]=s[a];return r.objectValues(o)},r.objectValues=s=>r.objectKeys(s).map(function(i){return s[i]}),r.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{let i=[];for(let o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},r.find=(s,i)=>{for(let o of s)if(i(o))return o},r.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function n(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}r.joinValues=n,r.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(L||(L={}));var rn;(function(r){r.mergeShapes=(e,t)=>({...e,...t})})(rn||(rn={}));var y=L.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ye=r=>{switch(typeof r){case"undefined":return y.undefined;case"string":return y.string;case"number":return Number.isNaN(r)?y.nan:y.number;case"boolean":return y.boolean;case"function":return y.function;case"bigint":return y.bigint;case"symbol":return y.symbol;case"object":return Array.isArray(r)?y.array:r===null?y.null:r.then&&typeof r.then=="function"&&r.catch&&typeof r.catch=="function"?y.promise:typeof Map<"u"&&r instanceof Map?y.map:typeof Set<"u"&&r instanceof Set?y.set:typeof Date<"u"&&r instanceof Date?y.date:y.object;default:return y.unknown}};var f=L.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Wi=r=>JSON.stringify(r,null,2).replace(/"([^"]+)":/g,"$1:"),ee=class r extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};let t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){let t=e||function(i){return i.message},n={_errors:[]},s=i=>{for(let o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError