canic-cli 0.292.2

Canic command line deployment tool
var bn="abcdefghijklmnopqrstuvwxyz234567",ar=Object.create(null);for(let t=0;t<bn.length;t++)ar[bn[t]]=t;ar[0]=ar.o;ar[1]=ar.i;function wi(t){let e=0,r=0,n="";function o(s){return e<0?r|=s>>-e:r=s<<e&248,e>3?(e-=8,1):(e<4&&(n+=bn[r>>3],e+=5),0)}for(let s=0;s<t.length;)s+=o(t[s]);return n+(e<0?bn[r>>3]:"")}function Ei(t){let e=0,r=0,n=new Uint8Array(t.length*4/3|0),o=0;function s(i){let c=ar[i.toLowerCase()];if(c===void 0)throw new Error(`Invalid character: ${JSON.stringify(i)}`);c<<=3,r|=c>>>e,e+=5,e>=8&&(n[o++]=r,e-=8,e>0?r=c<<5-e&255:r=0)}for(let i of t)s(i);return n.slice(0,o)}var Ef=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);function Bi(t){let e=-1;for(let r=0;r<t.length;r++){let o=(t[r]^e)&255;e=Ef[o]^e>>>8}return(e^-1)>>>0}var yn=BigInt(4294967295),Si=BigInt(32);function Bf(t,e=!1){return e?{h:Number(t&yn),l:Number(t>>Si&yn)}:{h:Number(t>>Si&yn)|0,l:Number(t&yn)|0}}function Ti(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Bf(t[s],e);[n[s],o[s]]=[i,c]}return[n,o]}var Sf=t=>t/2**32|0,Tf=t=>t>>>0;function Oi(t,e,r,n){let o=Sf(r),s=Tf(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var Yo=(t,e,r)=>t>>>r,Go=(t,e,r)=>t<<32-r|e>>>r,Pt=(t,e,r)=>t>>>r|e<<32-r,Ht=(t,e,r)=>t<<32-r|e>>>r,kr=(t,e,r)=>t<<64-r|e>>>r-32,Ur=(t,e,r)=>t>>>r-32|e<<64-r;function rt(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var _i=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ii=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,vi=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ri=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Ai=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ci=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function xn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Xo=t=>t?`"${t}" `:"";function Fr(t,e=""){if(typeof t!="number")throw new TypeError(Xo(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Xo(e)+"expected integer >= 0, got "+t);return t}function nt(t,e,r=""){if(xn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&Fr(e,"length");let n=xn(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Xo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}var _f=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Ni=(t,e)=>{_f(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Wo(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function Ui(t,e){nt(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function fr(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function gn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Ve(t,e){return t<<32-e|t>>>e}var Fi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",If=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ne(t){if(nt(t),Fi)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=If[t[r]];return e}function ki(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Ae(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Fi)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=ki(t.charCodeAt(s)),c=ki(t.charCodeAt(s+1));if(i===void 0||c===void 0){let a=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Se(t){if(typeof t!="string")throw new TypeError("string expected");let e=new TextEncoder().encode(t);try{return new Uint8Array(e)}finally{fr(e)}}function Te(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];nt(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function vf(t,e,r="opts"){return Ni(t,"defaults"),e!==void 0&&Ni(e,r),Object.assign(Object.create(null),t,e)}function wn(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=vf({},e,"info");let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function qi(t=32){Fr(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var En=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Mi(t,e,r){return t&e^~t&r}function Li(t,e,r){return t&e^t&r^e&r}var qr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=gn(this.buffer)}update(e){Wo(this),nt(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let c=0;c<s;){let a=Math.min(o-this.pos,s-c);if(a===o){let f=gn(e);for(;o<=s-c;c+=o)this.process(f,c);i=!0;continue}n.set(c===0&&a===s?e:e.subarray(c,c+a),this.pos),this.pos+=a,c+=a,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Wo(this),Ui(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),Oi(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let c=e===r?n:gn(e),a=this.outputLen,f=a/4,u=this.get();if(a%4||f>u.length)throw new Error("invalid outputLen");for(let d=0;d<f;d++)c.setUint32(4*d,u[d],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Di=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ji=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var $i=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Rf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),wt=new Uint32Array(64),Bn=class extends qr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[e,r,n,o,s,i,c,a]}set(e,r,n,o,s,i,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let d=0;d<16;d++,r+=4)wt[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){let l=wt[d-15],h=wt[d-2],m=Ve(l,7)^Ve(l,18)^l>>>3,b=Ve(h,17)^Ve(h,19)^h>>>10;wt[d]=b+wt[d-7]+m+wt[d-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:u}=this;for(let d=0;d<64;d++){let l=Ve(c,6)^Ve(c,11)^Ve(c,25),h=u+l+Mi(c,a,f)+Rf[d]+wt[d]|0,b=(Ve(n,2)^Ve(n,13)^Ve(n,22))+Li(n,o,s)|0;u=f,f=a,a=c,c=i+h|0,i=s,s=o,o=n,n=h+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,f,u)}roundClean(){fr(wt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),fr(this.buffer)}},Qo=class extends Bn{constructor(){super(32,Di)}},Jo=class extends Bn{constructor(){super(28,ji)}},Pi=Ti(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Af=Pi[0],Cf=Pi[1],Et=new Uint32Array(80),Bt=new Uint32Array(80),es=class extends qr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:u,Fh:d,Fl:l,Gh:h,Gl:m,Hh:b,Hl:p}=this;return[e,r,n,o,s,i,c,a,f,u,d,l,h,m,b,p]}set(e,r,n,o,s,i,c,a,f,u,d,l,h,m,b,p){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=u|0,this.Fh=d|0,this.Fl=l|0,this.Gh=h|0,this.Gl=m|0,this.Hh=b|0,this.Hl=p|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let y=0;y<16;y++,r+=4)Et[y]=e.getUint32(r),Bt[y]=e.getUint32(r+=4);for(let y=16;y<80;y++){let O=Et[y-15]|0,S=Bt[y-15]|0,M=Pt(O,S,1)^Pt(O,S,8)^Yo(O,S,7),$=Ht(O,S,1)^Ht(O,S,8)^Go(O,S,7),R=Et[y-2]|0,F=Bt[y-2]|0,P=Pt(R,F,19)^kr(R,F,61)^Yo(R,F,6),K=Ht(R,F,19)^Ur(R,F,61)^Go(R,F,6),X=vi($,K,Bt[y-7],Bt[y-16]),re=Ri(X,M,P,Et[y-7],Et[y-16]);Et[y]=re|0,Bt[y]=X|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:u,Eh:d,El:l,Fh:h,Fl:m,Gh:b,Gl:p,Hh:x,Hl:g}=this;for(let y=0;y<80;y++){let O=Pt(d,l,14)^Pt(d,l,18)^kr(d,l,41),S=Ht(d,l,14)^Ht(d,l,18)^Ur(d,l,41),M=d&h^~d&b,$=l&m^~l&p,R=Ai(g,S,$,Cf[y],Bt[y]),F=Ci(R,x,O,M,Af[y],Et[y]),P=R|0,K=Pt(n,o,28)^kr(n,o,34)^kr(n,o,39),X=Ht(n,o,28)^Ur(n,o,34)^Ur(n,o,39),re=n&s^n&c^s&c,N=o&i^o&a^i&a;x=b|0,g=p|0,b=h|0,p=m|0,h=d|0,m=l|0,{h:d,l}=rt(f|0,u|0,F|0,P|0),f=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let V=_i(P,X,N);n=Ii(V,F,K,re),o=V|0}({h:n,l:o}=rt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=rt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=rt(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:u}=rt(this.Dh|0,this.Dl|0,f|0,u|0),{h:d,l}=rt(this.Eh|0,this.El|0,d|0,l|0),{h,l:m}=rt(this.Fh|0,this.Fl|0,h|0,m|0),{h:b,l:p}=rt(this.Gh|0,this.Gl|0,b|0,p|0),{h:x,l:g}=rt(this.Hh|0,this.Hl|0,x|0,g|0),this.set(n,o,s,i,c,a,f,u,d,l,h,m,b,p,x,g)}roundClean(){fr(Et,Bt)}destroy(){this.destroyed=!0,fr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ts=class extends es{constructor(){super(64,$i)}};var Oe=wn(()=>new Qo,En(1)),Hi=wn(()=>new Jo,En(4)),rs=wn(()=>new ts,En(3));var Sn="__principal__",Nf=2,Vi=4,kf="aaaaa-aa",L=class t{static anonymous(){return new this(new Uint8Array([Vi]))}static managementCanister(){return this.fromText(kf)}static selfAuthenticating(e){let r=Hi(e);return new this(new Uint8Array([...r,Nf]))}static from(e){if(typeof e=="string")return t.fromText(e);if(Object.getPrototypeOf(e)===Uint8Array.prototype)return new t(e);if(t.isPrincipal(e))return new t(e._arr);throw new Error(`Impossible to convert ${JSON.stringify(e)} to Principal.`)}static fromHex(e){return new this(Ae(e))}static fromText(e){let r=e;if(e.includes(Sn)){let i=JSON.parse(e);Sn in i&&(r=i[Sn])}let n=r.toLowerCase().replace(/-/g,""),o=Ei(n);o=o.slice(4,o.length);let s=new this(o);if(s.toText()!==r)throw new Error(`Principal "${s.toText()}" does not have a valid checksum (original value "${r}" may not be a valid Principal ID).`);return s}static fromUint8Array(e){return new this(e)}static isPrincipal(e){return e instanceof t||typeof e=="object"&&e!==null&&"_isPrincipal"in e&&e._isPrincipal===!0&&"_arr"in e&&e._arr instanceof Uint8Array}constructor(e){this._arr=e,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===Vi}toUint8Array(){return this._arr}toHex(){return ne(this._arr).toUpperCase()}toText(){let e=new ArrayBuffer(4);new DataView(e).setUint32(0,Bi(this._arr));let n=new Uint8Array(e),o=new Uint8Array([...n,...this._arr]),i=wi(o).match(/.{1,5}/g);if(!i)throw new Error;return i.join("-")}toString(){return this.toText()}toJSON(){return{[Sn]:this.toText()}}compareTo(e){for(let r=0;r<Math.min(this._arr.length,e._arr.length);r++){if(this._arr[r]<e._arr[r])return"lt";if(this._arr[r]>e._arr[r])return"gt"}return this._arr.length<e._arr.length?"lt":this._arr.length>e._arr.length?"gt":"eq"}ltEq(e){let r=this.compareTo(e);return r=="lt"||r=="eq"}gtEq(e){let r=this.compareTo(e);return r=="gt"||r=="eq"}};var lt=class extends Error{constructor(e){super(e),this.name="DecodingError"}},Yi=55799,Gi=Symbol("CBOR_STOP_CODE"),Ke=(t=>(t[t.False=20]="False",t[t.True=21]="True",t[t.Null=22]="Null",t[t.Undefined=23]="Undefined",t[t.Break=31]="Break",t))(Ke||{}),xe=(t=>(t[t.UnsignedInteger=0]="UnsignedInteger",t[t.NegativeInteger=1]="NegativeInteger",t[t.ByteString=2]="ByteString",t[t.TextString=3]="TextString",t[t.Array=4]="Array",t[t.Map=5]="Map",t[t.Tag=6]="Tag",t[t.Simple=7]="Simple",t))(xe||{}),Uf=23,Ff=255,qf=65535,Mf=4294967295,Lf=BigInt("0xffffffffffffffff"),ze=(t=>(t[t.Value=23]="Value",t[t.OneByte=24]="OneByte",t[t.TwoBytes=25]="TwoBytes",t[t.FourBytes=26]="FourBytes",t[t.EightBytes=27]="EightBytes",t[t.Indefinite=31]="Indefinite",t))(ze||{}),ur=!1;function Df(t){return t==null}function jf(t,e){let r=new Uint8Array(e);return r.set(t),r}var $f=new TextDecoder;function Pf(t){return(t&224)>>5}function Hf(t){return t&31}var Dr=new Uint8Array,Mr,Ze=0;function Xi(t,e){Dr=t,Ze=0;let r=Vt(e);return e?.(r)??r}function Vt(t){let[e,r]=Tn();switch(e){case xe.UnsignedInteger:return dr(r);case xe.NegativeInteger:return Zf(r);case xe.ByteString:return Wi(r);case xe.TextString:return os(r);case xe.Array:return Vf(r,t);case xe.Map:return Kf(r,t);case xe.Tag:return Yf(r,t);case xe.Simple:return zf(r)}throw new lt(`Unsupported major type: ${e}`)}function Tn(){let t=Dr.at(Ze);if(Df(t))throw new lt("Provided CBOR data is empty");let e=Pf(t),r=Hf(t);return Ze++,[e,r]}function Vf(t,e){let r=dr(t);if(r===1/0){let o=[],s=Vt(e);for(;s!==Gi;)o.push(e?.(s)??s),s=Vt(e);return o}let n=new Array(r);for(let o=0;o<r;o++){let s=Vt(e);n[o]=e?.(s)??s}return n}function zf(t){switch(t){case Ke.False:return!1;case Ke.True:return!0;case Ke.Null:return null;case Ke.Undefined:return;case Ke.Break:return Gi}throw new lt(`Unrecognized simple type: ${t.toString(2)}`)}function Kf(t,e){let r=dr(t),n={};if(r===1/0){let[o,s]=Tn();for(;o!==xe.Simple&&s!==Ke.Break;){let i=os(s),c=Vt(e);zi(n,i,e?.(c,i)??c),[o,s]=Tn()}return n}for(let o=0;o<r;o++){let[s,i]=Tn();if(s!==xe.TextString)throw new lt("Map keys must be text strings");let c=os(i),a=Vt(e);zi(n,c,e?.(a,c)??a)}return n}function zi(t,e,r){if(e==="__proto__"){Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0});return}t[e]=r}function dr(t){if(t<=ze.Value)return t;switch(Mr=new DataView(Dr.buffer,Dr.byteOffset+Ze),t){case ze.OneByte:return Ze++,Mr.getUint8(0);case ze.TwoBytes:return Ze+=2,Mr.getUint16(0,ur);case ze.FourBytes:return Ze+=4,Mr.getUint32(0,ur);case ze.EightBytes:return Ze+=8,Mr.getBigUint64(0,ur);case ze.Indefinite:return 1/0;default:throw new lt(`Unsupported integer info: ${t.toString(2)}`)}}function Zf(t){let e=dr(t);return typeof e=="number"?-1-e:-1n-e}function Wi(t){let e=dr(t);if(e>Number.MAX_SAFE_INTEGER)throw new lt("Byte length is too large");let r=Number(e);return Ze+=r,Dr.slice(Ze-r,Ze)}function os(t){let e=Wi(t);return $f.decode(e)}function Yf(t,e){let r=dr(t);if(r===Yi)return Vt(e);throw new lt(`Unsupported tag: ${r}.`)}var jr=class extends Error{constructor(e){super(e),this.name="SerializationError"}},Gf=2*1024,Ki=100,Xf=new TextEncoder;function Lr(t){return t<<5}var dt=new Uint8Array(Gf),ot=new DataView(dt.buffer),me=0,ns=[];function Qi(t,e){me=0;let r=e?.(t)??t;return ou(Yi,r,e),dt.slice(0,me)}function Ji(t){let e=dt.length*2;for(;e<t;)e*=2;dt=jf(dt,e),ot=new DataView(dt.buffer)}function ss(t,e){if(t===!1||t===!0||t===null||t===void 0){Jf(t);return}if(typeof t=="number"||typeof t=="bigint"){nu(t);return}if(typeof t=="string"){rc(t);return}if(t instanceof Uint8Array){Zi(t);return}if(t instanceof ArrayBuffer){Zi(new Uint8Array(t));return}if(Array.isArray(t)){Wf(t,e);return}if(typeof t=="object"){Qf(t,e);return}throw new jr(`Unsupported type: ${typeof t}`)}function Wf(t,e){lr(xe.Array,t.length),t.forEach((r,n)=>{ss(e?.(r,n.toString())??r,e)})}function Qf(t,e){ns=Object.entries(t),lr(xe.Map,ns.length),ns.forEach(([r,n])=>{rc(r),ss(e?.(n,r)??n,e)})}function lr(t,e){if(me>dt.length-Ki&&Ji(me+Ki),e<=Uf){ot.setUint8(me++,Lr(t)|Number(e));return}if(e<=Ff){ot.setUint8(me++,Lr(t)|ze.OneByte),ot.setUint8(me,Number(e)),me+=1;return}if(e<=qf){ot.setUint8(me++,Lr(t)|ze.TwoBytes),ot.setUint16(me,Number(e),ur),me+=2;return}if(e<=Mf){ot.setUint8(me++,Lr(t)|ze.FourBytes),ot.setUint32(me,Number(e),ur),me+=4;return}if(e<=Lf){ot.setUint8(me++,Lr(t)|ze.EightBytes),ot.setBigUint64(me,BigInt(e),ur),me+=8;return}throw new jr(`Value too large to encode: ${e}`)}function Jf(t){lr(xe.Simple,eu(t))}function eu(t){if(t===!1)return Ke.False;if(t===!0)return Ke.True;if(t===null)return Ke.Null;if(t===void 0)return Ke.Undefined;throw new jr(`Unrecognized simple value: ${t.toString()}`)}function ec(t,e){lr(t,e.length),me>dt.length-e.length&&Ji(me+e.length),dt.set(e,me),me+=e.length}function tc(t,e){lr(t,e)}function tu(t){tc(xe.UnsignedInteger,t)}function ru(t){tc(xe.NegativeInteger,typeof t=="bigint"?-1n-t:-1-t)}function nu(t){t>=0?tu(t):ru(t)}function rc(t){ec(xe.TextString,Xf.encode(t))}function Zi(t){ec(xe.ByteString,t)}function ou(t,e,r){lr(xe.Tag,t),ss(e,r)}var ht;(function(t){t.Trust="Trust",t.Protocol="Protocol",t.Reject="Reject",t.Transport="Transport",t.External="External",t.Limit="Limit",t.Input="Input",t.Unknown="Unknown"})(ht||(ht={}));var On;(function(t){t.Normal="normal",t.Verbose="verbose"})(On||(On={}));var iu=new Set(["arg","certificate","nonce"]);function is(t){return(e,r)=>r instanceof Uint8Array?t===On.Normal&&iu.has(e)?`<${r.length} bytes, set ErrorCode.verbosity = ErrorVerbosity.Verbose to display>`:`hex(${r.length}):${ne(r)}`:r}var H=class t{static{this.verbosity=On.Normal}constructor(e=!1){this.isCertified=e}toString(){let e=this.toErrorMessage();return this.requestContext&&(e+=`
Request context:
  Request ID (hex): ${this.requestContext.requestId?ne(this.requestContext.requestId):"undefined"}
  Sender pubkey (hex): ${ne(this.requestContext.senderPubKey)}
  Sender signature (hex): ${ne(this.requestContext.senderSignature)}
  Ingress expiry: ${this.requestContext.ingressExpiry.toString()}`),this.callContext&&(e+=`
Call context:
  Canister ID: ${this.callContext.canisterId.toText()}
  Method name: ${this.callContext.methodName}`,"subnetId"in this.callContext.effectiveTarget?e+=`
  Effective target subnet: ${this.callContext.effectiveTarget.subnetId.toText()}`:this.callContext.effectiveTarget.canisterId.toText()!==this.callContext.canisterId.toText()&&(e+=`
  Effective target canister: ${this.callContext.effectiveTarget.canisterId.toText()}`),"httpDetails"in this.callContext&&(e+=`
  HTTP details: ${JSON.stringify(this.callContext.httpDetails,is(t.verbosity),2)}`)),e}},qe=class t extends Error{get code(){return this.cause.code}set code(e){this.cause.code=e}get kind(){return this.cause.kind}set kind(e){this.cause.kind=e}get isCertified(){return this.code.isCertified}constructor(e,r){super(e.toString()),this.name="AgentError",this.cause={code:e,kind:r},Object.setPrototypeOf(this,t.prototype)}hasCode(e){return this.code instanceof e}toString(){return`${this.name} (${this.kind}): ${this.message}`}},pt=class extends qe{static fromCode(e){return new this(e)}},Ce=class t extends pt{constructor(e){super(e,ht.Trust),this.name="TrustError",Object.setPrototypeOf(this,t.prototype)}},te=class t extends pt{constructor(e){super(e,ht.Protocol),this.name="ProtocolError",Object.setPrototypeOf(this,t.prototype)}},zt=class t extends pt{constructor(e){super(e,ht.Reject),this.name="RejectError",Object.setPrototypeOf(this,t.prototype)}},$r=class t extends pt{constructor(e){super(e,ht.Transport),this.name="TransportError",Object.setPrototypeOf(this,t.prototype)}},Me=class t extends pt{constructor(e){super(e,ht.External),this.name="ExternalError",Object.setPrototypeOf(this,t.prototype)}};var W=class t extends pt{constructor(e){super(e,ht.Input),this.name="InputError",Object.setPrototypeOf(this,t.prototype)}},ge=class t extends pt{constructor(e){super(e,ht.Unknown),this.name="UnknownError",Object.setPrototypeOf(this,t.prototype)}},Ye=class t extends H{constructor(e,r){super(),this.reason=e,this.error=r,this.name="CertificateVerificationErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){let e=this.reason;return this.error&&(e+=`: ${Zr(this.error)}`),`Certificate verification error: "${e}"`}},mt=class t extends H{constructor(e,r,n,o,s){super(),this.maxAgeInMinutes=e,this.certificateTime=r,this.currentTime=n,this.timeDiffMsecs=o,this.ageType=s,this.name="CertificateTimeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Certificate is signed more than ${this.maxAgeInMinutes} minutes in the ${this.ageType}. Certificate time: ${this.certificateTime.toISOString()} Current time: ${this.currentTime.toISOString()} Clock drift: ${this.timeDiffMsecs}ms`}},_n=class t extends H{constructor(){super(),this.name="CertificateHasTooManyDelegationsErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Certificate has too many delegations"}},Kt=class t extends H{constructor(e,r){super(),this.canisterId=e,this.subnetId=r,this.name="CertificateNotAuthorizedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The certificate contains a delegation that does not include the canister ${this.canisterId.toText()} in the canister_ranges field. Subnet ID: ${this.subnetId.toText()}`}},In=class t extends H{constructor(e){super(),this.subnetId=e,this.name="CertificateNotAuthorizedForSubnetErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The certificate is not authorized for subnet ${this.subnetId.toText()}`}},Ge=class t extends H{constructor(e,r){super(),this.message=e,this.lookupStatus=r,this.name="LookupErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`${this.message}. Lookup status: ${this.lookupStatus}`}},vn=class t extends H{constructor(e){super(),this.message=e,this.name="MalformedLookupFoundValueErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return this.message}},Rn=class t extends H{constructor(e){super(),this.message=e,this.name="MissingLookupValueErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return this.message}},hr=class t extends H{constructor(e,r){super(),this.expectedLength=e,this.actualLength=r,this.name="DerKeyLengthMismatchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`BLS DER-encoded public key must be ${this.expectedLength} bytes long, but is ${this.actualLength} bytes long`}},An=class t extends H{constructor(e,r){super(),this.expectedPrefix=e,this.actualPrefix=r,this.name="DerPrefixMismatchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`BLS DER-encoded public key is invalid. Expected the following prefix: ${ne(this.expectedPrefix)}, but got ${ne(this.actualPrefix)}`}},Cn=class t extends H{constructor(e,r){super(),this.expectedLength=e,this.actualLength=r,this.name="DerDecodeLengthMismatchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`DER payload mismatch: Expected length ${this.expectedLength}, actual length: ${this.actualLength}`}},Xe=class t extends H{constructor(e){super(),this.error=e,this.name="DerDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode DER: ${this.error}`}},Pr=class t extends H{constructor(e){super(),this.error=e,this.name="DerEncodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to encode DER: ${this.error}`}},Nn=class t extends H{constructor(e,r){super(),this.error=e,this.input=r,this.name="CborDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode CBOR: ${Zr(this.error)}, input: ${ne(this.input)}`}},kn=class t extends H{constructor(e,r){super(),this.error=e,this.value=r,this.name="CborEncodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to encode CBOR: ${Zr(this.error)}, input: ${this.value}`}};var Zt=class t extends H{constructor(e,r,n){super(),this.message=e,this.requestId=r,this.status=n,this.name="TimeoutWaitingForResponseErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){let e=`${this.message}
`;return this.requestId&&(e+=`  Request ID: ${ne(this.requestId)}
`),this.status&&(e+=`  Request status: ${this.status}
`),e}},Un=class t extends H{constructor(e,r,n){super(),this.maxIngressExpiryInMinutes=e,this.requestId=r,this.retryTimes=n,this.name="CertificateOutdatedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){let e=`Certificate is stale (over ${this.maxIngressExpiryInMinutes} minutes). Is the computer's clock synchronized?
  Request ID: ${ne(this.requestId)}
`;return this.retryTimes!==void 0&&(e+=`  Retried ${this.retryTimes} times.`),e}},Fn=class t extends H{constructor(e,r,n,o){super(!0),this.requestId=e,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=o,this.name="CertifiedRejectErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The replica returned a rejection error:
  Request ID: ${ne(this.requestId)}
  Reject code: ${this.rejectCode}
  Reject text: ${this.rejectMessage}
  Error code: ${this.rejectErrorCode}
`}};var qn=class t extends H{constructor(e,r,n,o){super(),this.requestId=e,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=o,this.name="UncertifiedRejectUpdateErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The replica returned a rejection error:
  Request ID: ${ne(this.requestId)}
  Reject code: ${this.rejectCode}
  Reject text: ${this.rejectMessage}
  Error code: ${this.rejectErrorCode}
`}},Mn=class t extends H{constructor(e){super(),this.requestId=e,this.name="RequestStatusDoneNoReplyErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Call was marked as done but we never saw the reply:
  Request ID: ${ne(this.requestId)}
`}},We=class t extends H{constructor(e){super(),this.shouldFetchRootKey=e,this.name="MissingRootKeyErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return this.shouldFetchRootKey===void 0?"Agent is missing root key":`Agent is missing root key and the shouldFetchRootKey value is set to ${this.shouldFetchRootKey}. The root key should only be unknown if you are in local development. Otherwise you should avoid fetching and use the default IC Root Key or the known root key of your environment.`}},Ln=class t extends H{constructor(e){super(),this.value=e,this.name="HashValueErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Attempt to hash a value of unsupported type: ${this.value}`}},St=class t extends H{constructor(){super(),this.name="IdentityInvalidErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"This identity has expired due this application's security policy. Please refresh your authentication."}},st=class t extends H{constructor(e,r){super(),this.message=e,this.providedIngressExpiryInMinutes=r,this.name="IngressExpiryInvalidErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`${this.message}. Provided ingress expiry time is ${this.providedIngressExpiryInMinutes} minutes.`}},Dn=class t extends H{constructor(){super(),this.name="MissingFetchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"No fetch implementation available. Provide a `fetch` function in HttpAgentOptions or ensure `globalThis.fetch` is defined."}},jn=class t extends H{constructor(){super(),this.name="CreateHttpAgentErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Failed to create agent from provided agent"}},$n=class t extends H{constructor(e,r){super(),this.signatureCount=e,this.maxExpected=r,this.name="ExcessiveSignaturesErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Query response contains ${this.signatureCount} signatures, which exceeds the subnet size of ${this.maxExpected}. This suggests a malformed or malicious response.`}},Pn=class t extends H{constructor(e){super(),this.error=e,this.name="MalformedSignatureErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Query response contained a malformed signature: ${this.error}`}};var Hn=class t extends H{constructor(){super(),this.name="MalformedPublicKeyErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Read state response contained a malformed public key"}},Vn=class t extends H{constructor(e){super(),this.nodeId=e,this.name="QuerySignatureVerificationFailedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Query signature verification failed. Node ID: ${this.nodeId}`}},Ne=class t extends H{constructor(e){super(),this.error=e,this.name="UnexpectedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Unexpected error: ${Zr(this.error)}`}},zn=class t extends H{constructor(e,r,n,o){super(),this.status=e,this.requestId=r,this.response=n,this.rawCertificate=o,this.name="UnexpectedV4StatusErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){let e=(r,n)=>n instanceof Uint8Array?`hex(${n.length}):${ne(n)}`:n;return`Unexpected request status in v4 sync response: "${this.status}"
  Request ID (hex): ${ne(this.requestId)}
  Response: ${JSON.stringify(this.response,e,2)}`}},Tt=class t extends H{constructor(e){super(),this.error=e,this.name="HashTreeDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode certificate: ${this.error}`}},Hr=class t extends H{constructor(e,r,n,o){super(),this.status=e,this.statusText=r,this.headers=n,this.bodyText=o,this.name="HttpErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){let e=`HTTP request failed:
  Status: ${this.status} (${this.statusText})
  Headers: ${JSON.stringify(this.headers,is(H.verbosity))}
`;return this.bodyText&&(e+=`  Body: ${this.bodyText}
`),e}},Vr=class t extends H{constructor(){super(),this.name="HttpV4ApiNotSupportedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"HTTP request failed: v4 API is not supported"}},zr=class t extends H{constructor(e){super(),this.error=e,this.name="HttpFetchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to fetch HTTP request: ${Zr(this.error)}`}};var Kn=class t extends H{constructor(e){super(),this.request=e,this.name="InvalidReadStateRequestErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Invalid read state request: ${this.request}`}},Kr=class t extends H{constructor(e){super(),this.error=e,this.name="ExpiryJsonDeserializeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to deserialize expiry: ${this.error}`}};var Zn=class t extends H{constructor(){super(),this.name="EffectiveSubnetIdAsyncErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Setting `effectiveTarget` to a `subnetId` is not allowed in `callSync = false` calls"}};function Zr(t){if(t instanceof Error)return t.stack??t.message;try{return JSON.stringify(t,is(H.verbosity))}catch{return String(t)}}var it=new Error("unreachable");var pr=class{save(){return this._view}restore(e){if(!(e instanceof Uint8Array))throw new Error("Checkpoint must be a Uint8Array");this._view=e}constructor(e,r=e?.byteLength||0){if(e&&!(e instanceof Uint8Array))try{e=nc(e)}catch{throw new Error("Buffer must be a Uint8Array")}if(r<0||!Number.isInteger(r))throw new Error("Length must be a non-negative integer");if(e&&r>e.byteLength)throw new Error("Length cannot exceed buffer length");this._buffer=e||new Uint8Array(0),this._view=new Uint8Array(this._buffer.buffer,0,r)}get buffer(){return this._view.slice()}get byteLength(){return this._view.byteLength}read(e){let r=this._view.subarray(0,e);return this._view=this._view.subarray(e),r.slice()}readUint8(){if(this._view.byteLength===0)return;let e=this._view[0];return this._view=this._view.subarray(1),e}write(e){if(!(e instanceof Uint8Array))throw new Error("Buffer must be a Uint8Array");let r=this._view.byteLength;this._view.byteOffset+this._view.byteLength+e.byteLength>=this._buffer.byteLength?this.alloc(e.byteLength):this._view=new Uint8Array(this._buffer.buffer,this._view.byteOffset,this._view.byteLength+e.byteLength),this._view.set(e,r)}get end(){return this._view.byteLength===0}alloc(e){if(e<=0||!Number.isInteger(e))throw new Error("Amount must be a positive integer");let r=new Uint8Array((this._buffer.byteLength+e)*1.2|0),n=new Uint8Array(r.buffer,0,this._view.byteLength+e);n.set(this._view),this._buffer=r,this._view=n}};function nc(t){if(!t)throw new Error("Input cannot be null or undefined");return t instanceof Uint8Array?t.buffer instanceof ArrayBuffer?t:new Uint8Array(t):t instanceof ArrayBuffer?new Uint8Array(t):Array.isArray(t)?new Uint8Array(t):"buffer"in t?nc(t.buffer):new Uint8Array(t).slice()}function Yr(t,e){if(t.byteLength!==e.byteLength)return t.byteLength-e.byteLength;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]-e[r];return 0}function oc(t){let e=BigInt(t);if(t<=0)throw new RangeError("Input must be positive");return e.toString(2).length-1}function cu(){throw new Error("unexpected end of buffer")}var sc=8192;function au(t){let e=t.readUint8();return e===void 0&&cu(),e}function Gr(t){if(typeof t=="number"&&(t=BigInt(t)),t<BigInt(0))throw new Error("Cannot leb encode negative values.");let e=(t===BigInt(0)?0:oc(t))+1,r=new pr(new Uint8Array(e),0);for(;;){let n=Number(t&BigInt(127));if(t/=BigInt(128),t===BigInt(0)){r.write(new Uint8Array([n]));break}else r.write(new Uint8Array([n|128]))}return r.buffer}function ic(t){let e=BigInt(1),r=BigInt(0),n,o=0;do{if(o++>=sc)throw new Error(`LEB128 value exceeds maximum length of ${sc} bytes`);n=au(t),r+=BigInt(n&127).valueOf()*e,e*=BigInt(128)}while(n>=128);return r}var Xr="__expiry__",cs=BigInt(1e3),fu=BigInt(1e6),uu=BigInt(60),as=uu*cs,du=BigInt(1)*as;function lu(t){return t/cs*cs}function hu(t){return t/as*as}var Yt=class t{constructor(e){this.__expiry__=e,this._isExpiry=!0}static fromDeltaInMilliseconds(e,r=0){let n=BigInt(Date.now())+BigInt(r),o=n+BigInt(e),s=hu(o),i;return s>=n+du?i=s:i=lu(o),new t(i*fu)}toBigInt(){return this.__expiry__}toHash(){return Gr(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[Xr]:this.toString()}}static fromJSON(e){let r=JSON.parse(e);if(r[Xr])try{let n=BigInt(r[Xr]);return new t(n)}catch(n){throw new W(new Kr(`Not a valid BigInt: ${n}`))}throw new W(new Kr(`The input does not contain the key ${Xr}`))}static isExpiry(e){return e instanceof t||typeof e=="object"&&e!==null&&"_isExpiry"in e&&e._isExpiry===!0&&"__expiry__"in e&&typeof e.__expiry__=="bigint"}};function pu(t){return typeof t=="object"&&t!==null&&"toCborValue"in t}function Yn(t){try{let e=Qi(t,r=>L.isPrincipal(r)?r.toUint8Array():Yt.isExpiry(r)?r.toBigInt():pu(r)?r.toCborValue():r);return e.buffer instanceof ArrayBuffer?e:e.slice()}catch(e){throw W.fromCode(new kn(e,t))}}function ke(t){try{return Xi(t)}catch(e){throw W.fromCode(new Nn(e,t))}}var mu=BigInt(1e6),fs=t=>ic(new pr(t)),mr=t=>{let r=fs(t)/mu;return new Date(Number(r))};function $e(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var Q=(t,e,r)=>nt(t,e,r),ds=Fr;function Ot(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Gt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Xt=ne,ye=(...t)=>Te(...t),Wt=t=>Ae(t),ct=xn,bt=t=>qi(t),Xn=BigInt(0),us=BigInt(1),bu=t=>t?`"${t}" `:"";function Pe(t,e=""){if(typeof t!="boolean")throw new TypeError(bu(e)+"expected boolean, got type="+typeof t);return t}function yu(t){if(typeof t=="bigint"){if(!_t(t))throw new RangeError("positive bigint expected, got "+t)}else ds(t);return t}function ie(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function cc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Xn:BigInt("0x"+t)}function It(t){return cc(ne(t))}function Qt(t){return cc(ne(at(nt(t)).reverse()))}function vt(t,e){if(Fr(e),e===0)throw new Error("zero output length is invalid");t=yu(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Ae(n.padStart(r,"0"))}function ls(t,e){return vt(t,e).reverse()}function at(t){return Uint8Array.from(Q(t))}function Wn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}function _t(t){return typeof t=="bigint"&&Xn<=t}function hs(t,e,r){return _t(t)&&_t(e)&&_t(r)&&e<=t&&t<r}function Jt(t,e,r,n){if(!hs(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function He(t){if(t<Xn)throw new Error("expected non-negative bigint, got "+t);return t===Xn?0:t.toString(2).length}function ac(t,e){if(typeof t!="bigint")throw new TypeError('"n" expected bigint, got type='+typeof t);return ie(e,"pos"),t>>BigInt(e)&us}var Qn=t=>(ie(t,"n"),(us<<BigInt(t))-us);function le(t,e={},r={},n="object"){Ot(t,n),Ot(e,"fields"),Ot(r,"optFields");function o(i,c,a){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,u=t[i];if(!Object.hasOwn(t,i)&&(a?u!==void 0:c!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(a&&u===void 0)return;let d=typeof u;if(d!==c||u===null)throw new TypeError(`${f} is invalid: expected ${c}, got ${d}`)}let s=(i,c)=>Object.entries(i).forEach(([a,f])=>o(a,f,c));s(e,!1),s(r,!0)}var Qe=()=>{throw new Error("not implemented")};var he=BigInt(0),ee=BigInt(1),er=BigInt(2),dc=BigInt(3),eo=BigInt(4),lc=BigInt(5),xu=BigInt(7),hc=BigInt(8),gu=BigInt(9),pc=BigInt(15),mc=BigInt(16),bc=BigInt("0x10000000000000000");function ce(t,e){if(e<=he)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=he?r:e+r}function wu(t,e,r){if(r<=ee)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<he)throw new Error("invalid exponent, negatives unsupported");if(e===he)return ee;if(e===ee)return t;let n=t%r;if(n<he&&(n+=r),e<bc){let c=ee;for(;e>he;)e&ee&&(c=c*n%r),n=n*n%r,e>>=ee;return c}let o=[];for(;e>he;)o.push(Number(e&pc)),e>>=eo;let s=new Array(16);s[0]=ee,s[1]=n;for(let c=2;c<16;c++)s[c]=s[c-1]*n%r;let i=s[o[o.length-1]];for(let c=o.length-2;c>=0;c--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let a=o[c];a!==0&&(i=i*s[a]%r)}return i}function Je(t,e,r){if(r<=ee)throw new Error("pow2: expected modulus > 1, got "+r);if(e<he)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >he;)n*=n,n%=r;return n}function fc(t,e){if(t===he)throw new Error("invert: expected non-zero number");if(e<=ee)throw new Error("invert: expected modulus > 1, got "+e);let r=ce(t,e),n=e,o=he,s=ee;for(;r!==he;){let c=n/r,a=n-r*c,f=o-s*c;n=r,r=a,o=s,s=f}if(n!==ee)throw new Error("invert: does not exist");return ce(o,e)}function ps(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function ms(t,e){if((t&ee)===he)throw new Error(e+": expected odd modulus, got "+t)}function yc(t,e){let r=t,n=(r.ORDER+ee)/eo,o=r.pow(e,n);return ps(r,o,e),o}function Eu(t,e){let r=t,n=(r.ORDER-lc)/hc,o=r.mul(e,er),s=r.pow(o,n),i=r.mul(e,s),c=r.mul(r.mul(i,er),s),a=r.mul(i,r.sub(c,r.ONE));return ps(r,a,e),a}function Bu(t){let e=Rt(t),r=xc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+xu)/mc;return((c,a)=>{let f=c,u=f.pow(a,i),d=f.mul(u,n),l=f.mul(u,o),h=f.mul(u,s),m=f.eql(f.sqr(d),a),b=f.eql(f.sqr(l),a);u=f.cmov(u,d,m),d=f.cmov(h,l,b);let p=f.eql(f.sqr(d),a),x=f.cmov(u,d,p);return ps(f,x,a),x})}function xc(t){if(t<dc)throw new Error("sqrt is not defined for small field");ms(t,"tonelliShanks");let e=t-ee,r=0;for(;e%er===he;)e/=er,r++;let n=er,o=Rt(t);for(;yt(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return yc;let s=o.pow(n,e),i=(e+ee)/er;return function(a,f){let u=a;if(u.is0(f))return f;if(yt(u,f)!==1)throw new Error("Cannot find square root");let d=r,l=u.mul(u.ONE,s),h=u.pow(f,e),m=u.pow(f,i);for(;!u.eql(h,u.ONE);){if(u.is0(h))throw new Error("Cannot find square root: probably non-prime P");let b=1,p=u.sqr(h);for(;!u.eql(p,u.ONE);)if(b++,p=u.sqr(p),b===d)throw new Error("Cannot find square root");let x=ee<<BigInt(d-b-1),g=u.pow(l,x);d=b,l=u.sqr(g),h=u.mul(h,l),m=u.mul(m,g)}return m}}function Su(t){return ms(t,"Fp.sqrt"),t%eo===dc?yc:t%hc===lc?Eu:t%mc===gu?Bu(t):xc(t)}var gc=(t,e)=>(ce(t,e)&ee)===ee,Tu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ue(t){if(Ot(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);ie(t.BYTES,"BYTES"),ie(t.BITS,"BITS");for(let e of Tu)Gt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=ee)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function to(t,e,r){Ue(t);let n=t;if(typeof r!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof r);if(r<he)throw new Error("invalid exponent, negatives unsupported");if(r===he)return n.ONE;if(r===ee)return e;if(r<bc){let c=n.ONE,a=e;for(;r>he;)r&ee&&(c=n.mul(c,a)),a=n.sqr(a),r>>=ee;return c}let o=[];for(;r>he;)o.push(Number(r&pc)),r>>=eo;let s=new Array(16);s[0]=n.ONE,s[1]=e;for(let c=2;c<16;c++)s[c]=n.mul(s[c-1],e);let i=s[o[o.length-1]];for(let c=o.length-2;c>=0;c--){i=n.sqr(n.sqr(n.sqr(n.sqr(i))));let a=o[c];a!==0&&(i=n.mul(i,s[a]))}return i}function et(t,e,r=!1){Ue(t),$e(e,"nums"),Pe(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((c,a,f)=>n.is0(a)?c:(o[f]=c,n.mul(c,a)),n.ONE),i=n.inv(s);return e.reduceRight((c,a,f)=>n.is0(a)?c:(o[f]=n.mul(c,o[f]),n.mul(c,a)),i),o}function yt(t,e){Ue(t);let r=t;ms(r.ORDER,"FpLegendre");let n=(r.ORDER-ee)/er,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),c=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!c)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function bs(t,e){return yt(t,e)!==-1}function Ou(t,e){if(e!==void 0&&ds(e),t<=he)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=He(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var uc=new WeakMap,Jn=class{ORDER;BITS;BYTES;isLE;ZERO=he;ONE=ee;_lengths;_mod;constructor(e,r={}){if(e<=ee)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Ou(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ce(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return he<=e&&e<this.ORDER}is0(e){return e===he}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ee)===ee}neg(e){return ce(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ce(e*e,this.ORDER)}add(e,r){return ce(e+r,this.ORDER)}sub(e,r){return ce(e-r,this.ORDER)}mul(e,r){return ce(e*r,this.ORDER)}pow(e,r){return wu(e,r,this.ORDER)}div(e,r){return ce(e*fc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return fc(e,this.ORDER)}sqrt(e){let r=uc.get(this);return r||uc.set(this,r=Su(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ls(e,this.BYTES):vt(e,this.BYTES)}fromBytes(e,r=!1){Q(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,s?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let a=s?Qt(e):It(e);if(c&&(a=ce(a,i)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return et(this,e,!0)}cmov(e,r,n){return Pe(n,"condition"),n?r:e}};function Rt(t,e={}){return Object.freeze(Jn.prototype),new Jn(t,e)}function wc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=ee)throw new Error("field order must be greater than 1");let e=He(t-ee);return Math.ceil(e/8)}function ys(t){let e=wc(t);return e+Math.ceil(e/2)}function Ec(t,e,r=!1){Q(t);let n=t.length,o=wc(e),s=Math.max(ys(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Qt(t):It(t),c=ce(i,e-ee)+ee;return r?ls(c,o):vt(c,o)}var ws=BigInt(0),Wr=BigInt(1),Iu=BigInt(4),xs=16,Bc=128,vu=5,Sc=2**31;function At(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Gt(e.fromAffine,"Point.fromAffine"),Gt(e.fromBytes,"Point.fromBytes"),Gt(e.fromHex,"Point.fromHex"),Ot(e.BASE,"Point.BASE"),Ot(e.ZERO,"Point.ZERO"),Ue(e.Fp),Ue(e.Fn)}function ro(t,e){At(t),_c(e,t);let r=et(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function Ru(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function Au(t,e){let r=t*(4*e+128);if(r>Sc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Sc/2**20+" MiB")}function Oc(t,e){if(t!==void 0){Gt(t,"randomBytes");try{let r=t(e);if(!ct(r)||r.length!==e)return}catch{return}return t}}function _c(t,e){$e(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Cu(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):_t(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var Ic=new WeakMap;function gs(t){return Ic.get(t)||1}function Nu(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function ku(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>ws;){let i=0;t&Wr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Wr}return s}function Uu(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),c=[];for(let a=0;a<r;a++){let f=Number(t&s);t>>=i,f>o&&(f-=n,t+=Wr),c.push(f)}if(t!==ws)throw new Error("invalid wnaf");return c}function Fu(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let c=r[i][s];if(c){let a=e[i][Math.abs(c)-1>>1];o=o.add(c<0?a.negate():a)}}}return o}var br=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){At(e),this.randomBytes=Oc(r,xs),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],c=e;for(let a=0;a<o;a++){let f=c;for(let u=0;u<s;u++)i.push(f),f=f.add(c);c=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),c=Uu(r,n,o),a=this.ZERO,f=this.BASE;for(let u=0;u<o;u++){let d=c[u],l=u*i,h=Math.abs(d)-1,m=s[l];for(let p=1;p<i;p++)m=p===h?s[l+p]:m;let b=m.negate();d===0?f=f.add(s[l]):a=a.add(d<0?b:m)}return{p:a,f}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(c=>c.W===e&&c.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!hs(r,Wr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=gs(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Bc,s=this.randomBytes(xs);if(!ct(s)||s.length!==xs)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+It(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=vu,s=1<<o,i=Qn(o),c=new Array(s);c[0]=this.ZERO;for(let u=1;u<s;u++)c[u]=c[u-1].add(e);let a=Math.ceil(n/o),f=this.ZERO;for(let u=a-1;u>=0;u--){if(u!==a-1)for(let h=0;h<o;h++)f=f.double();let d=Number(r>>BigInt(u*o)&i),l=c[0];for(let h=1;h<s;h++)l=h===d?c[h]:l;f=f.add(l)}return{p:f,f}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Wr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!_t(r))throw new Error("invalid scalar");let o=gs(e);if(o===1||r>=this.Point.Fn.ORDER)return no(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),Ru(r,this.bits);let n=Math.ceil((this.bits+Bc)/r)+1;Au(n*2**(r-1),this.Point.Fp.BYTES),Ic.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return gs(e)!==1}};function no(t,e,r,n=!1){if(At(t),_c(e,t),Pe(n,"allowOversized"),Cu(r,t.Fn,n?t.Fn.ORDER**Iu:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>Nu(i,4)),s=r.map(i=>ku(i,4));return Fu(t.ZERO,o,s)}function Tc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ue(e),e}else return Rt(t,{isLE:r})}function oo(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);le(r);for(let a of["p","n","h"]){let f=e[a];if(!(_t(f)&&f!==ws))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Tc(e.p,r.Fp,n),s=Tc(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Es(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var vc=BigInt(0),ft=BigInt(1),Ct=BigInt(2),Rc=BigInt(3),Ac=BigInt(4),qu=It;function tr(t,e){if(ie(t),ie(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function Mu(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Cc(t){if(!ct(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Wn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Lu(t,e,r,n){if(Q(t),ie(r),typeof n!="function")throw new Error("expand_message_xmd: expected hash function");ie(n.outputLen,"hash.outputLen"),ie(n.blockLen,"hash.blockLen"),e=Cc(e),e.length>255&&(e=n(ye(Wn("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let c=ye(e,tr(e.length,1)),a=new Uint8Array(s),f=tr(r,2),u=new Array(i),d=n(ye(a,t,f,tr(0,1),c));u[0]=n(ye(d,tr(1,1),c));for(let h=1;h<i;h++){let m=[Mu(d,u[h-1]),tr(h+1,1),c];u[h]=n(ye(...m))}return ye(...u).slice(0,r)}function Du(t,e,r,n,o){if(Q(t),ie(r),ie(n,"k"),n<0)throw new Error("expand_message_xof: invalid k");if(typeof o!="function")throw new Error("expand_message_xof: expected XOF function");if(typeof o.create!="function")throw new Error("expand_message_xof: expected XOF create");if(e=Cc(e),r<0||r>65535)throw new Error("expand_message_xof: invalid lenInBytes");if(e.length>255){let s=Math.ceil(2*n/8);e=o.create({dkLen:s}).update(Wn("H2C-OVERSIZE-DST-")).update(e).digest()}if(e.length>255)throw new Error("expand_message_xof: invalid DST");return o.create({dkLen:r}).update(t).update(tr(r,2)).update(e).update(tr(e.length,1)).digest()}function Bs(t,e,r){le(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:o,m:s,hash:i,expand:c,DST:a}=r;if(ie(i.outputLen,"valid hash"),Q(t),ie(e),ie(s,"m"),ie(o,"k"),n<=BigInt(1))throw new Error("hash_to_field: expected valid field characteristic");if(e<1)throw new Error("hash_to_field: expected count >= 1");if(s<1)throw new Error("hash_to_field: expected m >= 1");if(o<0)throw new Error("hash_to_field: invalid k");let f=n.toString(2).length,u=Math.ceil((f+o)/8),d=e*s*u,l;if(c==="xmd")l=Lu(t,a,d,i);else if(c==="xof")l=Du(t,a,d,o,i);else if(c==="_internal_pass")l=t;else throw new Error('expand must be "xmd" or "xof"');let h=new Array(e);for(let m=0;m<e;m++){let b=new Array(s);for(let p=0;p<s;p++){let x=u*(p+m*s),g=l.subarray(x,x+u);b[p]=ce(qu(g),n)}h[m]=b}return h}function Ss(t,e){Ue(t),$e(e,"map");let r=e.map((n,o)=>{if($e(n,"map["+o+"]"),n.length<1)throw new Error("isogenyMap: expected non-empty coefficients");return Array.from(n).reverse()});return(n,o)=>{let[s,i,c,a]=r.map(l=>l.reduce((h,m)=>t.add(t.mul(h,n),m))),f=t.is0(i)||t.is0(a),[u,d]=et(t,[i,a],!0);return n=t.mul(s,u),o=t.mul(o,t.mul(c,d)),f?{x:t.ZERO,y:t.ZERO}:{x:n,y:o}}}var ju="HashToScalar-";function Ts(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");le(r);let n=a=>Object.freeze({...a,DST:ct(a.DST)?at(a.DST):a.DST,...a.encodeDST===void 0?{}:{encodeDST:ct(a.encodeDST)?at(a.encodeDST):a.encodeDST}}),o=n(r),s=a=>a&&a.DST!==void 0?{DST:a.DST}:void 0;function i(a){return t.fromAffine(e(a))}function c(a){let f=a.clearCofactor();return f.equals(t.ZERO)?t.ZERO:(f.assertValidity(),f)}return Object.freeze({get defaults(){return n(o)},Point:t,hashToCurve(a,f){let u=Object.assign({},o,s(f)),d=Bs(a,2,u),l=i(d[0]),h=i(d[1]);return c(l.add(h))},encodeToCurve(a,f){let u=o.encodeDST===void 0?{}:{DST:o.encodeDST},d=Object.assign({},o,u,s(f)),l=Bs(a,1,d),h=i(l[0]);return c(h)},mapToCurve(a){if(o.m===1){if(typeof a!="bigint")throw new Error("expected bigint (m=1)");return c(i([a]))}if(!Array.isArray(a))throw new Error("expected array of bigints");if(a.length!==o.m)throw new Error(`expected array of ${o.m} bigints`);for(let f of a)if(typeof f!="bigint")throw new Error("expected array of bigints");return c(i(a))},hashToScalar(a,f){let u=t.Fn.ORDER,d=Object.assign({},o,{DST:ju},s(f),{p:u,m:1});return Bs(a,1,d)[0][0]}})}function $u(t,e){let r=Ue(t),n=r.ORDER,o=vc;for(let b=n-ft;b%Ct===vc;b/=Ct)o+=ft;let s=o,i=Ct<<s-ft-ft,c=i*Ct,a=(n-ft)/c,f=(a-ft)/Ct,u=c-ft,d=i,l=r.pow(e,a),h=r.pow(e,(a+ft)/Ct),m=(b,p)=>{let x=l,g=r.pow(p,u),y=r.sqr(g);y=r.mul(y,p);let O=r.mul(b,y);O=r.pow(O,f),O=r.mul(O,g),g=r.mul(O,p),y=r.mul(O,b);let S=r.mul(y,g);O=r.pow(S,d);let M=r.eql(O,r.ONE);g=r.mul(y,h),O=r.mul(S,x),y=r.cmov(g,y,M),S=r.cmov(O,S,M);for(let $=s;$>ft;$--){let R=$-Ct;R=Ct<<R-ft;let F=r.pow(S,R),P=r.eql(F,r.ONE);g=r.mul(y,x),x=r.mul(x,x),F=r.mul(S,x),y=r.cmov(g,y,P),S=r.cmov(F,S,P)}return{isValid:!r.is0(p)&&(M||r.is0(b)),value:y}};if(r.ORDER%Ac===Rc){let b=(r.ORDER-Rc)/Ac,p=r.sqrt(r.neg(e));m=(x,g)=>{let y=r.sqr(g),O=r.mul(x,g);y=r.mul(y,O);let S=r.pow(y,b);S=r.mul(S,O);let M=r.mul(S,p),$=r.mul(r.sqr(S),g),R=r.eql($,x),F=r.cmov(M,S,R);return{isValid:!r.is0(g)&&R,value:F}}}return m}function Os(t,e){let r=Ue(t);le(e,{},{},"opts");let{A:n,B:o,Z:s}=e;if(!r.isValidNot0(n)||!r.isValidNot0(o)||!r.isValid(s))throw new Error("mapToCurveSimpleSWU: invalid opts");if(r.eql(s,r.neg(r.ONE))||bs(r,s))throw new Error("mapToCurveSimpleSWU: invalid opts");let i=r.mul(o,r.inv(r.mul(s,n))),c=r.add(r.add(r.mul(r.sqr(i),i),r.mul(n,i)),o);if(!bs(r,c))throw new Error("mapToCurveSimpleSWU: invalid opts");let a=$u(r,s);if(!r.isOdd)throw new Error("Field does not have .isOdd()");return f=>{let u,d,l,h,m,b,p,x;u=r.sqr(f),u=r.mul(u,s),d=r.sqr(u),d=r.add(d,u),l=r.add(d,r.ONE),l=r.mul(l,o),h=r.cmov(s,r.neg(d),!r.eql(d,r.ZERO)),h=r.mul(h,n),d=r.sqr(l),b=r.sqr(h),m=r.mul(b,n),d=r.add(d,m),d=r.mul(d,l),b=r.mul(b,h),m=r.mul(b,o),d=r.add(d,m),p=r.mul(u,l);let{isValid:g,value:y}=a(d,b);x=r.mul(u,f),x=r.mul(x,y),p=r.cmov(p,l,g),x=r.cmov(x,y,g);let O=r.isOdd(f)===r.isOdd(x);x=r.cmov(r.neg(x),x,O);let S=et(r,[h],!0)[0];return p=r.mul(p,S),{x:p,y:x}}}var Nc=(t,e)=>(t+(t>=0?e:-e)/Hu)/e;function Pu(t,e,r){Jt("scalar",t,yr,r);let[[n,o],[s,i]]=e,c=Nc(i*t,r),a=Nc(-o*t,r),f=t-c*n-a*s,u=-c*o-a*i,d=f<yr,l=u<yr;d&&(f=-f),l&&(u=-u);let h=Qn(Math.ceil(He(r)/2))+Qr;if(f<yr||f>=h||u<yr||u>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:f,k2neg:l,k2:u}}var yr=BigInt(0),Qr=BigInt(1),Hu=BigInt(2),_s=BigInt(3),Vu=BigInt(4);function Is(t,e={}){let r=oo("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:c}=s;le(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:a,allowInfinityPoint:f,clearCofactor:u,isTorsionFree:d,fromBytes:l,toBytes:h}=e,m=e.randomBytes===void 0?bt:e.randomBytes;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=a?{beta:a.beta,basises:a.basises.map(I=>[...I])}:void 0,p=Ku(n,o);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function g(I,w,B){if(w.is0()){if(!f)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:_,y:v}=w.toAffine(),U=n.toBytes(_);if(Pe(B,"isCompressed"),B){x();let k=!n.isOdd(v);return ye(zu(k),U)}else return ye(Uint8Array.of(4),U,n.toBytes(v))}function y(I){Q(I,void 0,"Point");let{publicKey:w,publicKeyUncompressed:B}=p,_=I.length,v=I[0],U=I.subarray(1);if(f&&_===1&&v===0)return{x:n.ZERO,y:n.ZERO};if(_===w&&(v===2||v===3)){let k=n.fromBytes(U);if(!n.isValid(k))throw new Error("bad point: is not on curve, wrong x");let j=R(k),D;try{D=n.sqrt(j)}catch(se){let be=se instanceof Error?": "+se.message:"";throw new Error("bad point: is not on curve, sqrt error"+be)}x();let Z=n.isOdd(D);return(v&1)===1!==Z&&(D=n.neg(D)),{x:k,y:D}}else if(_===B&&v===4){let k=n.BYTES,j=n.fromBytes(U.subarray(0,k)),D=n.fromBytes(U.subarray(k,k*2));if(!F(j,D))throw new Error("bad point: is not on curve");return{x:j,y:D}}else throw new Error(`bad point: got length ${_}, expected compressed=${w} or uncompressed=${B}`)}let O=h===void 0?g:h,S=l===void 0?y:l,M=n.mul(s.b,_s),$=n.is0(s.a)?I=>n.ZERO:I=>n.mul(s.a,I);function R(I){let w=n.sqr(I),B=n.mul(w,I);return n.add(n.add(B,n.mul(I,s.a)),s.b)}function F(I,w){let B=n.sqr(w),_=R(I);return n.eql(B,_)}if(!F(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let P=n.mul(n.pow(s.a,_s),Vu),K=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(P,K)))throw new Error("bad curve params: a or b");function X(I,w,B=!1){if(!n.isValid(w)||B&&n.is0(w))throw new Error(`bad point coordinate ${I}`);return typeof w=="object"&&w!==null?n.create(w):w}function re(I){if(!(I instanceof E))throw new Error("Weierstrass Point expected")}function N(I){if(!b||!b.basises)throw new Error("no endo");return Pu(I,b.basises,o.ORDER)}function V(I,w,B,_){if(!o.isValid(_))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:v,k1:U,k2neg:k,k2:j}=N(_),D=new E(n.mul(B.X,b.beta),B.Y,B.Z);I.push(v?B.negate():B,k?D.negate():D),w.push(U,j)}else I.push(B),w.push(_)}let z=new WeakSet;class E{static BASE=new E(s.Gx,s.Gy,n.ONE);static ZERO=new E(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(w,B,_){this.X=X("x",w),this.Y=X("y",B,!0),this.Z=X("z",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(w){let{x:B,y:_}=w||{};if(!w||!n.isValid(B)||!n.isValid(_))throw new Error("invalid affine point");if(w instanceof E)throw new Error("projective point not allowed");return n.is0(B)&&n.is0(_)?E.ZERO:new E(B,_,n.ONE)}static fromBytes(w){let B=E.fromAffine(S(Q(w,void 0,"point")));return B.assertValidity(),B}static fromHex(w){return E.fromBytes(Wt(w))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=6,B=!0){return C.setWindowSize(this,w),B||this.multiply(_s),this}assertValidity(){let w=this;if(w.is0()){if(f&&n.is0(w.X)&&n.eql(w.Y,n.ONE)&&n.is0(w.Z))return;throw new Error("bad point: ZERO")}if(z.has(w))return;let{x:B,y:_}=w.toAffine();if(!n.isValid(B)||!n.isValid(_))throw new Error("bad point: x or y not field elements");if(!F(B,_))throw new Error("bad point: equation left != right");if(!w.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");z.add(w)}hasEvenY(){let{y:w}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(w)}equals(w){re(w);let{X:B,Y:_,Z:v}=this,{X:U,Y:k,Z:j}=w,D=n.eql(n.mul(B,j),n.mul(U,v)),Z=n.eql(n.mul(_,j),n.mul(k,v));return D&&Z}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{X:w,Y:B,Z:_}=this,v=n.ZERO,U=n.ZERO,k=n.ZERO,j=n.mul(w,w),D=n.mul(B,B),Z=n.mul(_,_),Y=n.mul(w,B);return Y=n.add(Y,Y),k=n.mul(w,_),k=n.add(k,k),v=$(k),U=n.mul(M,Z),U=n.add(v,U),v=n.sub(D,U),U=n.add(D,U),U=n.mul(v,U),v=n.mul(Y,v),k=n.mul(M,k),Z=$(Z),Y=n.sub(j,Z),Y=$(Y),Y=n.add(Y,k),k=n.add(j,j),j=n.add(k,j),j=n.add(j,Z),j=n.mul(j,Y),U=n.add(U,j),Z=n.mul(B,_),Z=n.add(Z,Z),j=n.mul(Z,Y),v=n.sub(v,j),k=n.mul(Z,D),k=n.add(k,k),k=n.add(k,k),new E(v,U,k)}add(w){re(w);let{X:B,Y:_,Z:v}=this,{X:U,Y:k,Z:j}=w,D=n.ZERO,Z=n.ZERO,Y=n.ZERO,se=n.mul(B,U),be=n.mul(_,k),Ee=n.mul(v,j),je=n.add(B,_),de=n.add(U,k);je=n.mul(je,de),de=n.add(se,be),je=n.sub(je,de),de=n.add(B,v);let Be=n.add(U,j);return de=n.mul(de,Be),Be=n.add(se,Ee),de=n.sub(de,Be),Be=n.add(_,v),D=n.add(k,j),Be=n.mul(Be,D),D=n.add(be,Ee),Be=n.sub(Be,D),Y=$(de),D=n.mul(M,Ee),Y=n.add(D,Y),D=n.sub(be,Y),Y=n.add(be,Y),Z=n.mul(D,Y),be=n.add(se,se),be=n.add(be,se),Ee=$(Ee),de=n.mul(M,de),be=n.add(be,Ee),Ee=n.sub(se,Ee),Ee=$(Ee),de=n.add(de,Ee),se=n.mul(be,de),Z=n.add(Z,se),se=n.mul(Be,de),D=n.mul(je,D),D=n.sub(D,se),se=n.mul(je,be),Y=n.mul(Be,Y),Y=n.add(Y,se),new E(D,Z,Y)}subtract(w){return re(w),this.add(w.negate())}is0(){return this.equals(E.ZERO)}multiply(w){if(!o.isValidNot0(w))throw new RangeError("invalid scalar: out of range");let{p:B,f:_}=C.mulSecret(this,w,i,A);return A([B,_])[0]}multiplyUnsafe(w){let B=this,_=w;if(!o.isValid(_))throw new RangeError("invalid scalar: out of range");if(_===yr||B.is0())return E.ZERO;if(_===Qr)return B;if(C.hasWindowSize(this))return C.mulUnsafe(B,_,A);let v=[],U=[];return V(v,U,B,_),no(E,v,U)}mulAddUnsafe(w,B,_){re(B);let v=[],U=[];return V(v,U,this,w),V(v,U,B,_),no(E,v,U)}toAffine(w){let B=this,_=w;if(_!=null&&!n.isValid(_))throw new RangeError('"invertedZ" expected valid field element');let{X:v,Y:U,Z:k}=B;if(n.eql(k,n.ONE))return{x:v,y:U};let j=B.is0();_==null&&(_=j?n.ONE:n.inv(k));let D=n.mul(v,_),Z=n.mul(U,_),Y=n.mul(k,_);if(j)return{x:n.ZERO,y:n.ZERO};if(!n.eql(Y,n.ONE))throw new Error("invZ was invalid");return{x:D,y:Z}}isTorsionFree(){return i===Qr?!0:d?d(E,this):C.mulUnsafe(this,c).is0()}clearCofactor(){return i===Qr?this:u?u(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Qr?this.is0():this.clearCofactor().is0()}toBytes(w=!0){return Pe(w,"isCompressed"),this.assertValidity(),O(E,this,w)}toHex(w=!0){return Xt(this.toBytes(w))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let A=I=>ro(E,I),C=new br(E,m);return C.bits>=6&&E.BASE.precompute(6),Object.freeze(E.prototype),Object.freeze(E),E}function zu(t){return Uint8Array.of(t?2:3)}function Ku(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}var Zu=BigInt(0),so=BigInt(1),kc=BigInt(2),xr=BigInt(3);function Yu(t){let e=[];for(;t>so;t>>=so)(t&so)===Zu?e.unshift(0):(t&xr)===xr?(e.unshift(-1),t+=so):e.unshift(1);return e}function vs(t){if(!Array.isArray(t)||t.length===0)throw new Error("expected non-empty array")}function Gu(t,e,r,n){if(le(t,{Fp:"object",Fr:"object",Fp2:"object",Fp12:"object"},{Fp6:"object"},"fields"),typeof e!="function")throw new TypeError('"G1_Point" expected point constructor, got type='+typeof e);if(typeof r!="function")throw new TypeError('"G2_Point" expected point constructor, got type='+typeof r);le(n,{ateLoopSize:"bigint",xNegative:"boolean",twistType:"string"},{randomBytes:"function",postPrecompute:"function"},"params");let{Fp:o,Fr:s,Fp2:i,Fp12:c}=t,{twistType:a,ateLoopSize:f,xNegative:u,postPrecompute:d}=n,l=(E,A)=>({c0:E,c1:A}),h=({c0:E,c1:A})=>Object.freeze({c0:E,c1:A}),m=(E,A)=>l(o.add(E.c0,A.c0),o.add(E.c1,A.c1)),b=(E,A)=>l(o.sub(E.c0,A.c0),o.sub(E.c1,A.c1)),p=(E,A)=>{let C=o.mul(E.c0,A.c0),I=o.mul(E.c1,A.c1);return l(o.sub(C,I),o.sub(o.mul(o.add(E.c0,E.c1),o.add(A.c0,A.c1)),o.add(C,I)))},x=(E,A)=>l(o.mul(E.c0,A),o.mul(E.c1,A)),g=E=>i.mulByNonresidue(E),y=({c0:E,c1:A},C,I,w,B,_)=>{let v=x(I,B),U=x(w,_),{c0:k,c1:j,c2:D}=E,{c0:Z,c1:Y,c2:se}=A,be=p(k,C),Ee=p(j,v),je=m(g(b(p(m(j,D),v),Ee)),be),de=b(b(p(m(C,v),m(k,j)),be),Ee),Be=m(b(p(m(k,D),C),be),Ee),Rr=g(p(se,U)),Ar=p(Z,U),Cr=p(Y,U),Mt=m(k,Z),Lt=m(j,Y),Nr=m(D,se),Dt=m(v,U),jt=p(Mt,C),$t=p(Lt,Dt),zo=m(g(b(p(m(Lt,Nr),Dt),$t)),jt),Ko=b(b(p(m(C,Dt),m(Mt,Lt)),jt),$t),Zo=m(b(p(m(Mt,Nr),C),jt),$t);return Object.freeze({c0:Object.freeze({c0:h(m(g(Cr),je)),c1:h(m(Rr,de)),c2:h(m(Ar,Be))}),c1:Object.freeze({c0:h(b(b(zo,je),Rr)),c1:h(b(b(Ko,de),Ar)),c2:h(b(b(Zo,Be),Cr))})})},O=({c0:E,c1:A},C,I,w,B,_)=>{let v=x(C,_),U=x(I,B),{c0:k,c1:j,c2:D}=E,{c0:Z,c1:Y,c2:se}=A,be=p(k,v),Ee=p(j,v),je=p(D,v),de=p(Z,U),Be=p(Y,w),Rr=m(g(b(p(m(Y,se),w),Be)),de),Ar=b(b(p(m(U,w),m(Z,Y)),de),Be),Cr=m(b(p(m(Z,se),U),de),Be),Mt=m(k,Z),Lt=m(j,Y),Nr=m(D,se),Dt=m(v,U),jt=p(Mt,Dt),$t=p(Lt,w),zo=m(g(b(p(m(Lt,Nr),w),$t)),jt),Ko=b(b(p(m(Dt,w),m(Mt,Lt)),jt),$t),Zo=m(b(p(m(Mt,Nr),Dt),jt),$t);return Object.freeze({c0:Object.freeze({c0:h(m(g(Cr),be)),c1:h(m(Rr,Ee)),c2:h(m(Ar,je))}),c1:Object.freeze({c0:h(b(b(zo,be),Rr)),c1:h(b(b(Ko,Ee),Ar)),c2:h(b(b(Zo,je),Cr))})})},S;if(a==="multiplicative")S=(E,A,C,I,w,B)=>y(I,E,A,C,w,B);else if(a==="divisive")S=(E,A,C,I,w,B)=>O(I,C,A,E,w,B);else throw new Error("bls: unknown twist type");let M=i.div(i.ONE,i.mul(i.ONE,kc));function $(E,A,C,I){let w=i.sqr(C),B=i.sqr(I),_=i.mulByB(i.mul(B,xr)),v=i.mul(_,xr),U=i.sub(i.sub(i.sqr(i.add(C,I)),B),w),k=i.sub(_,w),j=i.mul(i.sqr(A),xr),D=i.neg(U);return E.push([k,j,D]),A=i.mul(i.mul(i.mul(i.sub(w,v),A),C),M),C=i.sub(i.sqr(i.mul(i.add(w,v),M)),i.mul(i.sqr(_),xr)),I=i.mul(w,U),{Rx:A,Ry:C,Rz:I}}function R(E,A,C,I,w,B){let _=i.sub(C,i.mul(B,I)),v=i.sub(A,i.mul(w,I)),U=i.sub(i.mul(_,w),i.mul(v,B)),k=i.neg(_),j=v;E.push([U,k,j]);let D=i.sqr(v),Z=i.mul(D,v),Y=i.mul(D,A),se=i.add(i.sub(Z,i.mul(Y,kc)),i.mul(i.sqr(_),I));return A=i.mul(v,se),C=i.sub(i.mul(i.sub(Y,se),_),i.mul(Z,C)),I=i.mul(I,Z),{Rx:A,Ry:C,Rz:I}}let F=Yu(f),P=E=>{if(!(E instanceof r))throw new TypeError('"point" expected G2 point, got type='+typeof E);let A=E,{x:C,y:I}=A.toAffine(),w=C,B=I,_=i.neg(I),v=w,U=B,k=i.ONE,j=[];for(let D of F){let Z=[];({Rx:v,Ry:U,Rz:k}=$(Z,v,U,k)),D&&({Rx:v,Ry:U,Rz:k}=R(Z,v,U,k,w,D===-1?_:B)),j.push(Z)}if(d){let D=j[j.length-1];d(v,U,k,w,B,R.bind(null,D))}return j};function K(E,A=!1){$e(E,"pairs",(I,w)=>{if($e(I,w),I.length!==3)throw new TypeError(`"${w}" expected precompute tuple`);$e(I[0],w+"[0]")});let C=c.ONE;if(E.length){let I=E[0][0].length;for(let w=0;w<I;w++){w!==0&&(C=c.sqr(C));for(let[B,_,v]of E)for(let[U,k,j]of B[w])C=S(U,k,j,C,_,v)}}return u&&(C=c.conjugate(C)),A?c.finalExponentiate(C):C}function X(E,A=!0){$e(E,"pairs");let C=[];for(let I=0;I<E.length;I++){let w=E[I];le(w,{g1:"object",g2:"object"},{},"pairs["+I+"]");let{g1:B,g2:_}=w;if(!(B instanceof e))throw new TypeError('"pairs['+I+'].g1" expected G1 point, got type='+typeof B);if(!(_ instanceof r))throw new TypeError('"pairs['+I+'].g2" expected G2 point, got type='+typeof _);if(B.is0()||_.is0())throw new Error("pairing is not available for ZERO point");B.assertValidity(),_.assertValidity();let v=B.toAffine();C.push([P(_),v.x,v.y])}return K(C,A)}function re(E,A,C=!0){if(!(E instanceof e))throw new TypeError('"Q" expected G1 point, got type='+typeof E);if(!(A instanceof r))throw new TypeError('"P" expected G2 point, got type='+typeof A);return X([{g1:E,g2:A}],C)}let N={seed:ys(s.ORDER)},V=n.randomBytes===void 0?bt:n.randomBytes,z=E=>(E=E===void 0?V(N.seed):E,Q(E,N.seed,"seed"),Ec(E,s.ORDER));return Object.freeze(N),{lengths:N,Fr:s,Fp12:c,millerLoopBatch:K,pairing:re,pairingBatch:X,calcPairingPrecomputes:P,randomSecretKey:z}}function Uc(t,e,r,n,o,s){let{Fr:i,Fp12:c,pairingBatch:a,randomSecretKey:f,lengths:u}=t;s||(s={fromBytes:Qe,fromHex:Qe,toBytes:Qe,toHex:Qe});let d=Object.freeze({...s});function l(p){return p instanceof e?p:e.fromBytes(p)}function h(p){return p instanceof r?p:d.fromBytes(p)}function m(p){if(!(p instanceof r))throw new Error(`expected valid message hashed to ${n?"G1":"G2"} curve`);return p}let b=n?(p,x)=>({g1:x,g2:p}):(p,x)=>({g1:p,g2:x});return Object.freeze({lengths:Object.freeze({...u,secretKey:i.BYTES}),keygen(p){let x=f(p),g=this.getPublicKey(x);return{secretKey:x,publicKey:g}},getPublicKey(p){let x;try{x=e.Fn.fromBytes(p)}catch(g){throw new Error("invalid private key: "+typeof p,{cause:g})}return e.BASE.multiply(x)},sign(p,x,g){if(g!=null)throw new Error("sign() expects 2 arguments");let y=e.Fn.fromBytes(x);return m(p).assertValidity(),p.multiply(y)},verify(p,x,g,y){if(y!=null)throw new Error("verify() expects 3 arguments");p=h(p),g=l(g);let O=g.negate(),S=e.BASE,M=m(x),$=p;try{let R=a([b(O,M),b(S,$)]);return c.eql(R,c.ONE)}catch{return!1}},verifyBatch(p,x){vs(x);let g=h(p),y=x.map(R=>m(R.message)),O=x.map(R=>l(R.publicKey)),S=new Map;for(let R=0;R<O.length;R++){let F=O[R],P=y[R],K=S.get(P);K===void 0&&(K=[],S.set(P,K)),K.push(F)}let M=[],$=e.BASE;try{for(let[R,F]of S){let P=F.reduce((K,X)=>K.add(X));M.push(b(P,R))}return M.push(b($.negate(),g)),c.eql(a(M),c.ONE)}catch{return!1}},aggregatePublicKeys(p){vs(p),p=p.map(g=>l(g));let x=p.reduce((g,y)=>g.add(y),e.ZERO);return x.assertValidity(),x},aggregateSignatures(p){vs(p),p=p.map(g=>h(g));let x=p.reduce((g,y)=>g.add(y),r.ZERO);return x.assertValidity(),x},hash(p,x){return Q(p),o(p,x===void 0?void 0:{DST:x})},Signature:Object.freeze({...d})})}function Xu(t,e,r,n){let{Fp:o,Fr:s,Fp2:i,Fp6:c,Fp12:a}=t,f={Point:e},u={Point:r},d=Gu(t,e,r,n),{millerLoopBatch:l,pairing:h,pairingBatch:m,calcPairingPrecomputes:b,randomSecretKey:p,lengths:x}=d;return f.Point.BASE.precompute(4),Object.freeze(f),Object.freeze(u),Object.freeze({lengths:Object.freeze(x),millerLoopBatch:l,pairing:h,pairingBatch:m,G1:f,G2:u,fields:Object.freeze({Fr:s,Fp:o,Fp2:i,Fp6:c,Fp12:a}),params:Object.freeze({ateLoopSize:n.ateLoopSize,xNegative:n.xNegative,twistType:n.twistType,postPrecompute:n.postPrecompute}),utils:Object.freeze({randomSecretKey:p,calcPairingPrecomputes:b})})}function Wu(t,e,r,n,o){let s=Xu(t,e,r,n);le(o,{hasherOpts:"object",hasherOptsG1:"object",hasherOptsG2:"object"},{mapToG1:"function",mapToG2:"function"},"hasherParams");let i=Ts(e,o.mapToG1===void 0?Qe:o.mapToG1,{...o.hasherOpts,...o.hasherOptsG1}),c=Ts(r,o.mapToG2===void 0?Qe:o.mapToG2,{...o.hasherOpts,...o.hasherOptsG2});return Object.freeze({...s,G1:i,G2:c})}function Fc(t,e,r,n,o,s){let i=Wu(t,e,r,n,o),c={...i,Fr:i.fields.Fr,Fp12:i.fields.Fp12,calcPairingPrecomputes:i.utils.calcPairingPrecomputes,randomSecretKey:i.utils.randomSecretKey},a=Uc(c,e,r,!1,i.G2.hashToCurve,s?.LongSignature),f=Uc(c,r,e,!0,i.G1.hashToCurve,s?.ShortSignature);return Object.freeze({...i,longSignatures:a,shortSignatures:f})}var Rs=BigInt(0),Nt=BigInt(1),_e=BigInt(2),qc=BigInt(3),Qu=BigInt(6),Ju=BigInt(12),rr=t=>!!t&&typeof t=="object";function Lc(t,e,r,n,o=1,s){ie(o,"num"),ie(n,"degree");let i=s===void 0?n:s;ie(i,"divisor");let c=t;if(typeof r!="bigint"||r<=Nt)throw new Error("calcFrobeniusCoefficients: expected valid modulus, got "+r);if(n<=0)throw new Error("calcFrobeniusCoefficients: expected positive degree, got "+n);if(o<=0)throw new Error("calcFrobeniusCoefficients: expected positive row count, got "+o);if(i<=0)throw new Error("calcFrobeniusCoefficients: expected positive divisor, got "+i);let a=BigInt(i),f=r**BigInt(n),u=[];for(let d=0;d<o;d++){let l=BigInt(d+1),h=[];for(let m=0,b=Nt;m<n;m++){let p=l*b-l;if(p%a)throw new Error("calcFrobeniusCoefficients: inexact tower exponent");let x=p/a%f;h.push(c.pow(e,x)),b*=r}u.push(h)}return u}function Dc(t,e,r){if(Ue(t),Ue(e),le(e,{Fp:"object",frobeniusMap:"function",fromBigTuple:"function",mulByB:"function",mulByNonresidue:"function",reim:"function",Fp4Square:"function",NONRESIDUE:"object"},{}),!rr(r)||Array.isArray(r))throw new TypeError('"base" expected Fp2 element, got type='+typeof r);if(!e.isValid(r))throw new RangeError('"base" expected valid Fp2 element');let n=e.pow(r,(t.ORDER-Nt)/qc),o=e.pow(r,(t.ORDER-Nt)/_e);function s(l,h){let m=e.mul(e.frobeniusMap(l,1),n),b=e.mul(e.frobeniusMap(h,1),o);return[m,b]}let i=e.pow(r,(t.ORDER**_e-Nt)/qc),c=e.pow(r,(t.ORDER**_e-Nt)/_e);if(!e.eql(c,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function a(l,h){return[e.mul(l,i),e.neg(h)]}let f=l=>(h,m)=>{if(typeof h!="function")throw new TypeError('"c" expected point constructor, got type='+typeof h);if(At(h),!(m instanceof h))throw new TypeError('"P" expected Point instance, got type='+typeof m);let b=m.toAffine(),p=l(b.x,b.y);return h.fromAffine({x:p[0],y:p[1]})},u=f(s),d=f(a);return{psi:s,psi2:a,G2psi:u,G2psi2:d,PSI_X:n,PSI_Y:o,PSI2_X:i,PSI2_Y:c}}var As=class{ORDER;BITS;BYTES;isLE;ZERO;ONE;Fp;NONRESIDUE;mulByB;Fp_NONRESIDUE;Fp_div2;constructor(e,r={}){let{NONRESIDUE:n=BigInt(-1),FP2_NONRESIDUE:o,Fp2mulByB:s}=r,i=e.ORDER,c=i*i;this.Fp=e,this.ORDER=c,this.BITS=He(c),this.BYTES=Math.ceil(He(c)/8),this.isLE=e.isLE,this.ZERO=this.create({c0:e.ZERO,c1:e.ZERO}),this.ONE=this.create({c0:e.ONE,c1:e.ZERO}),this.Fp_NONRESIDUE=e.create(n),this.Fp_div2=e.div(e.ONE,_e),this.NONRESIDUE=this.create({c0:o[0],c1:o[1]}),this.mulByB=a=>{let{c0:f,c1:u}=s(a);return Object.freeze({c0:f,c1:u})},Object.freeze(this)}fromBigTuple(e){if(!Array.isArray(e)||e.length!==2)throw new Error("invalid Fp2.fromBigTuple");let[r,n]=e;if(typeof r!="bigint"||typeof n!="bigint")throw new Error("invalid Fp2.fromBigTuple");return this.create({c0:r,c1:n})}create(e){let{Fp:r}=this,n=r.create(e.c0),o=r.create(e.c1);return Object.freeze({c0:n,c1:o})}isValid(e){if(!rr(e))throw new TypeError("invalid field element: expected object, got "+typeof e);let{c0:r,c1:n}=e,{Fp:o}=this;return o.isValid(r)&&o.isValid(n)}is0(e){if(!rr(e))return!1;let{c0:r,c1:n}=e,{Fp:o}=this;return o.is0(r)&&o.is0(n)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}eql({c0:e,c1:r},{c0:n,c1:o}){let{Fp:s}=this;return s.eql(e,n)&&s.eql(r,o)}neg({c0:e,c1:r}){let{Fp:n}=this;return Object.freeze({c0:n.neg(e),c1:n.neg(r)})}pow(e,r){return to(this,e,r)}invertBatch(e){return et(this,e,!0)}add(e,r){let{Fp:n}=this,{c0:o,c1:s}=e,{c0:i,c1:c}=r;return Object.freeze({c0:n.add(o,i),c1:n.add(s,c)})}sub({c0:e,c1:r},{c0:n,c1:o}){let{Fp:s}=this;return Object.freeze({c0:s.sub(e,n),c1:s.sub(r,o)})}mul({c0:e,c1:r},n){let{Fp:o}=this;if(typeof n=="bigint")return Object.freeze({c0:o.mul(e,n),c1:o.mul(r,n)});let{c0:s,c1:i}=n,c=o.mul(e,s),a=o.mul(r,i),f=o.sub(c,a),u=o.sub(o.mul(o.add(e,r),o.add(s,i)),o.add(c,a));return Object.freeze({c0:f,c1:u})}sqr({c0:e,c1:r}){let{Fp:n}=this,o=n.add(e,r),s=n.sub(e,r),i=n.add(e,e);return Object.freeze({c0:n.mul(o,s),c1:n.mul(i,r)})}addN(e,r){return this.add(e,r)}subN(e,r){return this.sub(e,r)}mulN(e,r){return this.mul(e,r)}sqrN(e){return this.sqr(e)}div(e,r){let{Fp:n}=this;return this.mul(e,typeof r=="bigint"?n.inv(n.create(r)):this.inv(r))}inv({c0:e,c1:r}){let{Fp:n}=this,o=n.inv(n.create(e*e+r*r));return Object.freeze({c0:n.mul(o,n.create(e)),c1:n.mul(o,n.create(-r))})}sqrt(e){let{Fp:r}=this,n=this,{c0:o,c1:s}=e;if(r.is0(s))return yt(r,o)===1?n.create({c0:r.sqrt(o),c1:r.ZERO}):n.create({c0:r.ZERO,c1:r.sqrt(r.div(o,this.Fp_NONRESIDUE))});let i=r.sqrt(r.sub(r.sqr(o),r.mul(r.sqr(s),this.Fp_NONRESIDUE))),c=r.mul(r.add(i,o),this.Fp_div2);yt(r,c)===-1&&(c=r.sub(c,i));let f=r.sqrt(c),u=n.create({c0:f,c1:r.div(r.mul(s,this.Fp_div2),f)});if(!n.eql(n.sqr(u),e))throw new Error("Cannot find square root");let d=u,l=n.neg(d),{re:h,im:m}=n.reim(d),{re:b,im:p}=n.reim(l);return m>p||m===p&&h>b?d:l}isOdd(e){let{re:r,im:n}=this.reim(e),o=r%_e,s=r===Rs,i=n%_e;return BigInt(o||s&&i)==Nt}fromBytes(e){let{Fp:r}=this;if(Q(e),e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return this.create({c0:r.fromBytes(e.subarray(0,r.BYTES)),c1:r.fromBytes(e.subarray(r.BYTES))})}toBytes({c0:e,c1:r}){return ye(this.Fp.toBytes(e),this.Fp.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:o},s){let{Fp:i}=this;return this.create({c0:i.cmov(e,n,s),c1:i.cmov(r,o,s)})}reim({c0:e,c1:r}){return{re:e,im:r}}Fp4Square(e,r){let n=this,o=n.sqr(e),s=n.sqr(r);return{first:n.add(n.mulByNonresidue(s),o),second:n.sub(n.sub(n.sqr(n.add(e,r)),o),s)}}mulByNonresidue({c0:e,c1:r}){let{Fp:n,NONRESIDUE:o}=this;return o.c0===n.ONE&&o.c1===n.ONE?Object.freeze({c0:n.sub(e,r),c1:n.add(e,r)}):o.c1===n.ONE?Object.freeze({c0:n.sub(n.mul(e,o.c0),r),c1:n.add(e,n.mul(r,o.c0))}):this.mul({c0:e,c1:r},o)}frobeniusMap(e,r){let{c0:n,c1:o}=e,{Fp:s}=this;return Object.freeze({c0:n,c1:r%2===0?o:s.neg(o)})}},Cs=class{ORDER;BITS;BYTES;isLE;ZERO;ONE;Fp2;constructor(e){this.Fp2=e,this.ORDER=e.Fp.ORDER**Qu,this.BITS=3*e.BITS,this.BYTES=3*e.BYTES,this.isLE=e.isLE,this.ZERO=this.create({c0:e.ZERO,c1:e.ZERO,c2:e.ZERO}),this.ONE=this.create({c0:e.ONE,c1:e.ZERO,c2:e.ZERO}),Object.freeze(this)}get FROBENIUS_COEFFICIENTS_1(){let e=io.get(this);if(e)return e[0];let{Fp2:r}=this,{Fp:n}=r,o=Lc(r,r.NONRESIDUE,n.ORDER,6,2,3),s=[Object.freeze(o[0]),Object.freeze(o[1])];return io.set(this,s),s[0]}get FROBENIUS_COEFFICIENTS_2(){let e=io.get(this);return e?e[1]:(this.FROBENIUS_COEFFICIENTS_1,io.get(this)[1])}add({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i}){let{Fp2:c}=this;return Object.freeze({c0:c.add(e,o),c1:c.add(r,s),c2:c.add(n,i)})}sub({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i}){let{Fp2:c}=this;return Object.freeze({c0:c.sub(e,o),c1:c.sub(r,s),c2:c.sub(n,i)})}mul({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;if(typeof o=="bigint")return Object.freeze({c0:s.mul(e,o),c1:s.mul(r,o),c2:s.mul(n,o)});let{c0:i,c1:c,c2:a}=o,f=s.mul(e,i),u=s.mul(r,c),d=s.mul(n,a);return Object.freeze({c0:s.add(f,s.mulByNonresidue(s.sub(s.mul(s.add(r,n),s.add(c,a)),s.add(u,d)))),c1:s.add(s.sub(s.mul(s.add(e,r),s.add(i,c)),s.add(f,u)),s.mulByNonresidue(d)),c2:s.sub(s.add(u,s.mul(s.add(e,n),s.add(i,a))),s.add(f,d))})}sqr({c0:e,c1:r,c2:n}){let{Fp2:o}=this,s=o.sqr(e),i=o.mul(o.mul(e,r),_e),c=o.mul(o.mul(r,n),_e),a=o.sqr(n);return Object.freeze({c0:o.add(o.mulByNonresidue(c),s),c1:o.add(o.mulByNonresidue(a),i),c2:o.sub(o.sub(o.add(o.add(i,o.sqr(o.add(o.sub(e,r),n))),c),s),a)})}addN(e,r){return this.add(e,r)}subN(e,r){return this.sub(e,r)}mulN(e,r){return this.mul(e,r)}sqrN(e){return this.sqr(e)}create(e){let{Fp2:r}=this,n=r.create(e.c0),o=r.create(e.c1),s=r.create(e.c2);return Object.freeze({c0:n,c1:o,c2:s})}isValid(e){if(!rr(e))throw new TypeError("invalid field element: expected object, got "+typeof e);let{c0:r,c1:n,c2:o}=e,{Fp2:s}=this;return s.isValid(r)&&s.isValid(n)&&s.isValid(o)}is0(e){if(!rr(e))return!1;let{c0:r,c1:n,c2:o}=e,{Fp2:s}=this;return s.is0(r)&&s.is0(n)&&s.is0(o)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r,c2:n}){let{Fp2:o}=this;return Object.freeze({c0:o.neg(e),c1:o.neg(r),c2:o.neg(n)})}eql({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i}){let{Fp2:c}=this;return c.eql(e,o)&&c.eql(r,s)&&c.eql(n,i)}sqrt(e){return Qe()}div(e,r){let{Fp2:n}=this,{Fp:o}=n;return this.mul(e,typeof r=="bigint"?o.inv(o.create(r)):this.inv(r))}pow(e,r){return to(this,e,r)}invertBatch(e){return et(this,e,!0)}inv({c0:e,c1:r,c2:n}){let{Fp2:o}=this,s=o.sub(o.sqr(e),o.mulByNonresidue(o.mul(n,r))),i=o.sub(o.mulByNonresidue(o.sqr(n)),o.mul(e,r)),c=o.sub(o.sqr(r),o.mul(e,n)),a=o.inv(o.add(o.mulByNonresidue(o.add(o.mul(n,i),o.mul(r,c))),o.mul(e,s)));return Object.freeze({c0:o.mul(a,s),c1:o.mul(a,i),c2:o.mul(a,c)})}fromBytes(e){let{Fp2:r}=this;if(Q(e),e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);let n=r.BYTES;return this.create({c0:r.fromBytes(e.subarray(0,n)),c1:r.fromBytes(e.subarray(n,n*2)),c2:r.fromBytes(e.subarray(2*n))})}toBytes({c0:e,c1:r,c2:n}){let{Fp2:o}=this;return ye(o.toBytes(e),o.toBytes(r),o.toBytes(n))}cmov({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i},c){let{Fp2:a}=this;return this.create({c0:a.cmov(e,o,c),c1:a.cmov(r,s,c),c2:a.cmov(n,i,c)})}fromBigSix(e){let{Fp2:r}=this;if(!Array.isArray(e)||e.length!==6)throw new Error("invalid Fp6.fromBigSix");for(let o=0;o<6;o++)if(typeof e[o]!="bigint")throw new Error("invalid Fp6.fromBigSix");let n=e;return this.create({c0:r.fromBigTuple(n.slice(0,2)),c1:r.fromBigTuple(n.slice(2,4)),c2:r.fromBigTuple(n.slice(4,6))})}frobeniusMap(e,r){let{c0:n,c1:o,c2:s}=e;if(r%6===0)return Object.freeze({c0:n,c1:o,c2:s});let{Fp2:i}=this;return Object.freeze({c0:i.frobeniusMap(n,r),c1:i.mul(i.frobeniusMap(o,r),this.FROBENIUS_COEFFICIENTS_1[r%6]),c2:i.mul(i.frobeniusMap(s,r),this.FROBENIUS_COEFFICIENTS_2[r%6])})}mulByFp2({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;return Object.freeze({c0:s.mul(e,o),c1:s.mul(r,o),c2:s.mul(n,o)})}mulByNonresidue({c0:e,c1:r,c2:n}){let{Fp2:o}=this;return Object.freeze({c0:o.mulByNonresidue(n),c1:e,c2:r})}mul1({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;return Object.freeze({c0:s.mulByNonresidue(s.mul(n,o)),c1:s.mul(e,o),c2:s.mul(r,o)})}mul01({c0:e,c1:r,c2:n},o,s){let{Fp2:i}=this,c=i.mul(e,o),a=i.mul(r,s);return Object.freeze({c0:i.add(i.mulByNonresidue(i.sub(i.mul(i.add(r,n),s),a)),c),c1:i.sub(i.sub(i.mul(i.add(o,s),i.add(e,r)),c),a),c2:i.add(i.sub(i.mul(i.add(e,n),o),c),a)})}},io=new WeakMap,Ns=class{ORDER;BITS;BYTES;isLE;ZERO;ONE;Fp6;X_LEN;finalExponentiate;constructor(e,r){let{X_LEN:n,Fp12finalExponentiate:o}=r,{Fp2:s}=e,{Fp:i}=s;this.Fp6=e,this.ORDER=i.ORDER**Ju,this.BITS=2*e.BITS,this.BYTES=2*e.BYTES,this.isLE=e.isLE,this.ZERO=this.create({c0:e.ZERO,c1:e.ZERO}),this.ONE=this.create({c0:e.ONE,c1:e.ZERO}),this.X_LEN=n,this.finalExponentiate=c=>{let a=({c0:d,c1:l})=>Object.freeze({c0:d,c1:l}),f=({c0:d,c1:l,c2:h})=>Object.freeze({c0:a(d),c1:a(l),c2:a(h)}),u=o(c);return Object.freeze({c0:f(u.c0),c1:f(u.c1)})},Object.freeze(this)}get FROBENIUS_COEFFICIENTS(){let e=Mc.get(this);if(e)return e;let{Fp2:r}=this.Fp6,{Fp:n}=r,o=Object.freeze(Lc(r,r.NONRESIDUE,n.ORDER,12,1,6)[0]);return Mc.set(this,o),o}create(e){let{Fp6:r}=this,n=r.create(e.c0),o=r.create(e.c1);return Object.freeze({c0:n,c1:o})}isValid(e){if(!rr(e))throw new TypeError("invalid field element: expected object, got "+typeof e);let{c0:r,c1:n}=e,{Fp6:o}=this;return o.isValid(r)&&o.isValid(n)}is0(e){if(!rr(e))return!1;let{c0:r,c1:n}=e,{Fp6:o}=this;return o.is0(r)&&o.is0(n)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r}){let{Fp6:n}=this;return Object.freeze({c0:n.neg(e),c1:n.neg(r)})}eql({c0:e,c1:r},{c0:n,c1:o}){let{Fp6:s}=this;return s.eql(e,n)&&s.eql(r,o)}sqrt(e){return Qe()}inv({c0:e,c1:r}){let{Fp6:n}=this,o=n.inv(n.sub(n.sqr(e),n.mulByNonresidue(n.sqr(r))));return Object.freeze({c0:n.mul(e,o),c1:n.neg(n.mul(r,o))})}div(e,r){let{Fp6:n}=this,{Fp2:o}=n,{Fp:s}=o;return this.mul(e,typeof r=="bigint"?s.inv(s.create(r)):this.inv(r))}pow(e,r){return to(this,e,r)}invertBatch(e){return et(this,e,!0)}add({c0:e,c1:r},{c0:n,c1:o}){let{Fp6:s}=this;return Object.freeze({c0:s.add(e,n),c1:s.add(r,o)})}sub({c0:e,c1:r},{c0:n,c1:o}){let{Fp6:s}=this;return Object.freeze({c0:s.sub(e,n),c1:s.sub(r,o)})}mul({c0:e,c1:r},n){let{Fp6:o}=this;if(typeof n=="bigint")return Object.freeze({c0:o.mul(e,n),c1:o.mul(r,n)});let{c0:s,c1:i}=n,c=o.mul(e,s),a=o.mul(r,i);return Object.freeze({c0:o.add(c,o.mulByNonresidue(a)),c1:o.sub(o.mul(o.add(e,r),o.add(s,i)),o.add(c,a))})}sqr({c0:e,c1:r}){let{Fp6:n}=this,o=n.mul(e,r);return Object.freeze({c0:n.sub(n.sub(n.mul(n.add(n.mulByNonresidue(r),e),n.add(e,r)),o),n.mulByNonresidue(o)),c1:n.add(o,o)})}addN(e,r){return this.add(e,r)}subN(e,r){return this.sub(e,r)}mulN(e,r){return this.mul(e,r)}sqrN(e){return this.sqr(e)}fromBytes(e){let{Fp6:r}=this;if(Q(e),e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return this.create({c0:r.fromBytes(e.subarray(0,r.BYTES)),c1:r.fromBytes(e.subarray(r.BYTES))})}toBytes({c0:e,c1:r}){let{Fp6:n}=this;return ye(n.toBytes(e),n.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:o},s){let{Fp6:i}=this;return this.create({c0:i.cmov(e,n,s),c1:i.cmov(r,o,s)})}fromBigTwelve(e){let{Fp6:r}=this;if(!Array.isArray(e)||e.length!==12)throw new Error("invalid Fp12.fromBigTwelve");for(let o=0;o<12;o++)if(typeof e[o]!="bigint")throw new Error("invalid Fp12.fromBigTwelve");let n=e;return this.create({c0:r.fromBigSix(n.slice(0,6)),c1:r.fromBigSix(n.slice(6,12))})}frobeniusMap(e,r){let n=r%12;if(n===0)return Object.freeze({c0:e.c0,c1:e.c1});if(n===6)return this.conjugate(e);let{Fp6:o}=this,{Fp2:s}=o,{c0:i,c1:c,c2:a}=o.frobeniusMap(e.c1,r),f=this.FROBENIUS_COEFFICIENTS[n];return Object.freeze({c0:o.frobeniusMap(e.c0,r),c1:Object.freeze({c0:s.mul(i,f),c1:s.mul(c,f),c2:s.mul(a,f)})})}mulByFp2({c0:e,c1:r},n){let{Fp6:o}=this;return Object.freeze({c0:o.mulByFp2(e,n),c1:o.mulByFp2(r,n)})}conjugate({c0:e,c1:r}){return Object.freeze({c0:e,c1:this.Fp6.neg(r)})}_cyclotomicSquare({c0:e,c1:r}){let{Fp6:n}=this,{Fp2:o}=n,{c0:s,c1:i,c2:c}=e,{c0:a,c1:f,c2:u}=r,{first:d,second:l}=o.Fp4Square(s,f),{first:h,second:m}=o.Fp4Square(a,c),{first:b,second:p}=o.Fp4Square(i,u),x=o.mulByNonresidue(p);return Object.freeze({c0:Object.freeze({c0:o.add(o.mul(o.sub(d,s),_e),d),c1:o.add(o.mul(o.sub(h,i),_e),h),c2:o.add(o.mul(o.sub(b,c),_e),b)}),c1:Object.freeze({c0:o.add(o.mul(o.add(x,a),_e),x),c1:o.add(o.mul(o.add(l,f),_e),l),c2:o.add(o.mul(o.add(m,u),_e),m)})})}_cyclotomicExp(e,r){if(Jt("cyclotomic exponent",r,Rs,Nt<<BigInt(this.X_LEN)),r===Rs)return this.ONE;let n=e;for(let o=He(r)-2;o>=0;o--)n=this._cyclotomicSquare(n),ac(r,o)&&(n=this.mul(n,e));return n}},Mc=new WeakMap;function jc(t){if(le(t,{ORDER:"bigint",X_LEN:"number",FP2_NONRESIDUE:"object",Fp2mulByB:"function",Fp12finalExponentiate:"function"},{NONRESIDUE:"bigint"}),ie(t.X_LEN,"X_LEN"),t.X_LEN<1)throw new Error("invalid X_LEN");let e=t.FP2_NONRESIDUE;if(!Array.isArray(e)||e.length!==2)throw new Error("invalid FP2_NONRESIDUE");if(typeof e[0]!="bigint"||typeof e[1]!="bigint")throw new Error("invalid FP2_NONRESIDUE");let r=Rt(t.ORDER),n=new As(r,t),o=new Cs(n),s=new Ns(o,t);return{Fp:r,Fp2:n,Fp6:o,Fp12:s}}var Ls=BigInt(0),$c=BigInt(1),co=BigInt(2),gr=BigInt(3),wr=BigInt(4),nr=BigInt("0xd201000000010000"),ed=He(nr),Jr={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:Ls,b:wr,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")},Ds=Rt(Jr.n,{modFromBytes:!0});function td(t,e,{g2:r,g3:n,g4:o,g5:s}){return{c0:{c0:t,c1:o,c2:n},c1:{c0:r,c1:e,c2:s}}}function rd({c0:t,c1:e}){return{g2:e.c0,g3:t.c2,g4:t.c1,g5:e.c2}}function nd({g2:t,g3:e,g4:r,g5:n}){let{first:o,second:s}=q.Fp4Square(r,n),{first:i,second:c}=q.Fp4Square(t,e),a=q.add(t,t),f=q.add(e,e),u=q.add(r,r),d=q.add(n,n);return{g2:q.add(q.mul(q.mulByNonresidue(s),gr),a),g3:q.sub(q.mul(o,gr),f),g4:q.sub(q.mul(i,gr),u),g5:q.add(q.mul(c,gr),d)}}function od({g2:t,g3:e,g4:r,g5:n}){return q.is0(t)?{num:q.mul(q.mul(r,n),co),den:e}:{num:q.add(q.sub(q.mul(q.sqr(r),gr),q.mul(e,co)),q.mulByNonresidue(q.sqr(n))),den:q.mul(t,wr)}}function sd(t,{g2:e,g3:r,g4:n,g5:o}){let s=q.mul(r,n),i=q.add(q.sub(q.mul(q.sub(q.sqr(t),s),co),s),q.mul(e,o));return q.add(q.mulByNonresidue(i),q.ONE)}function id(t,e){let r=[],n=rd(t);for(let a of e){for(let f=0;f<a;f++)n=nd(n);r.push(n)}let o=r.map(({g2:a,g3:f})=>q.is0(a)&&q.is0(f)),s=r.map(od),i=q.invertBatch(s.map(({den:a})=>a)),c=r.map((a,f)=>{if(o[f])return J.ONE;let u=q.mul(s[f].num,i[f]);return td(sd(u,a),u,a)});return{result:J.mul(J.mul(c[0],c[1]),c[2]),last:c[2]}}function cd(t){let{result:e,last:r}=id(t,[16,32,9]),n=e,o=r;for(let s=0;s<3;s++)o=J._cyclotomicSquare(o);n=J.mul(n,o);for(let s=0;s<2;s++)o=J._cyclotomicSquare(o);return n=J.mul(n,o),o=J._cyclotomicSquare(o),J.mul(n,o)}var{Fp:oe,Fp2:q,Fp6:ad,Fp12:J}=jc({ORDER:Jr.p,X_LEN:ed,FP2_NONRESIDUE:[$c,$c],Fp2mulByB:({c0:t,c1:e})=>{let r=oe.mul(t,wr),n=oe.mul(e,wr);return{c0:oe.sub(r,n),c1:oe.add(r,n)}},Fp12finalExponentiate:t=>{let e=m=>J.conjugate(cd(m)),r=J.div(J.frobeniusMap(t,6),t),n=J.mul(J.frobeniusMap(r,2),r),o=e(n),s=J.mul(J.conjugate(J._cyclotomicSquare(n)),o),i=e(s),c=e(i),a=J.mul(e(c),J._cyclotomicSquare(o)),f=e(a),u=J.frobeniusMap(J.mul(o,c),2),d=J.frobeniusMap(J.mul(i,n),3),l=J.frobeniusMap(J.mul(a,J.conjugate(n)),1),h=J.mul(J.mul(f,J.conjugate(s)),n);return J.mul(J.mul(J.mul(u,d),l),h)}}),Pc,Qc=()=>Pc||(Pc=Dc(oe,q,q.div(q.ONE,q.NONRESIDUE))),qs=(t,e)=>{let r=Qc().G2psi;return qs=r,r(t,e)},Jc=(t,e)=>{let r=Qc().G2psi2;return Jc=r,r(t,e)},ks=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:oe.ORDER,m:2,k:128,expand:"xmd",hash:Oe}),ea={p:q.ORDER,n:Jr.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:q.ZERO,b:q.fromBigTuple([wr,wr]),Gx:q.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:q.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},Hc=(t,e)=>{for(let r of t)if(r!==Ls)return!!(r*co/e);return!1},Vc={encode({c0:t,c1:e}){let{BYTES:r}=oe;return ye(vt(e,r),vt(t,r))},decode(t){let{BYTES:e}=oe;return q.create({c0:Ms(t.subarray(e)),c1:Ms(t.subarray(0,e))})}},zc=oe;function Ms(t){return oe.fromBytes(t)}var ta=(t,e,r,n,o,s)=>{let i=e,c=n,a=o,f=i.BYTES;return u=>({encode(d,l=!0){if(!l&&!u)throw new Error("invalid signature: expected compressed encoding");let h=d.is0(),{x:m,y:b}=d.toAffine(),p=l?c(m):ye(c(m),c(b)),x;return l&&!h&&(x=Hc(s(b),zc.ORDER)),ud(p,{compressed:l,infinity:h,sort:x})},decode(d){let l=u?Q(d,void 0,"point"):Q(d,f,"signature"),{compressed:h,infinity:m,sort:b,value:p}=fd(l);if(!u&&!h)throw new Error("invalid signature: expected compressed encoding");let x=h?f:2*f;if(p.length!==x)throw new Error(`invalid ${t} point: expected ${x} bytes`);if(m){for(let O of p)if(O)throw new Error(`invalid ${t} point: non-canonical zero`);return{x:i.ZERO,y:i.ZERO}}let g=a(h?p:p.subarray(0,f)),y;if(h){if(y=i.sqrt(i.add(i.pow(g,gr),r)),!y)throw new Error(`invalid ${t} point: compressed`);Hc(s(y),zc.ORDER)!==b&&(y=i.neg(y))}else y=a(p.subarray(f));if(!h&&i.is0(g)&&i.is0(y))throw new Error(`invalid ${t} point: uncompressed`);return{x:g,y}}})};function ra({compressed:t,infinity:e,sort:r}){if(!t&&!e&&r||!t&&e&&r||t&&e&&r)throw new Error("invalid encoding flag")}function fd(t){t=at(t);let e=t[0]&224,r=!!(e>>7&1),n=!!(e>>6&1),o=!!(e>>5&1);return ra({compressed:r,infinity:n,sort:o}),t[0]&=31,{compressed:r,infinity:n,sort:o,value:t}}function ud(t,e){if(t[0]&224)throw new Error("setMask: non-empty mask");return ra({compressed:!!e.compressed,infinity:!!e.infinity,sort:!!e.sort}),e.compressed&&(t[0]|=128),e.infinity&&(t[0]|=64),e.sort&&(t[0]|=32),t}var Kc=ta("G1",oe,oe.create(Jr.b),t=>vt(t,oe.BYTES),Ms,t=>[t]),ao={point:Kc(!0),sig:Kc(!1)},Us=t=>(t.assertValidity(),ao.sig.encode(t));function Zc(t){let r=uo.G1.Point.fromAffine(ao.sig.decode(t));return r.assertValidity(),r}var Yc=ta("G2",q,ea.b,Vc.encode,Vc.decode,t=>[t.c1,t.c0]),fo={point:Yc(!0),sig:Yc(!1)},Fs=t=>(t.assertValidity(),fo.sig.encode(t));function Gc(t){let r=uo.G2.Point.fromAffine(fo.sig.decode(t));return r.assertValidity(),r}var dd={ShortSignature:{fromBytes(t){return Zc(Q(t))},fromHex(t){return Zc(Wt(t))},toBytes(t){return Us(t)},toRawBytes(t){return Us(t)},toHex(t){return Xt(Us(t))}},LongSignature:{fromBytes(t){return Gc(Q(t))},fromHex(t){return Gc(Wt(t))},toBytes(t){return Fs(t)},toRawBytes(t){return Fs(t)},toHex(t){return Xt(Fs(t))}}},ld={Fp:oe,Fp2:q,Fp6:ad,Fp12:J,Fr:Ds},hd=Is(Jr,{allowInfinityPoint:!0,Fn:Ds,fromBytes:ao.point.decode,toBytes:(t,e,r)=>ao.point.encode(e,r),isTorsionFree:(t,e)=>{let r=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),n=new t(oe.mul(e.X,r),e.Y,e.Z);return e.multiplyUnsafe(nr).negate().multiplyUnsafe(nr).equals(n)},clearCofactor:(t,e)=>e.multiplyUnsafe(nr).add(e)}),pd=Is(ea,{Fp:q,allowInfinityPoint:!0,Fn:Ds,fromBytes:fo.point.decode,toBytes:(t,e,r)=>fo.point.encode(e,r),isTorsionFree:(t,e)=>e.multiplyUnsafe(nr).negate().equals(qs(t,e)),clearCofactor:(t,e)=>{let r=nr,n=e.multiplyUnsafe(r).negate(),o=qs(t,e),s=e.double();return s=Jc(t,s),s=s.subtract(o),o=n.add(o),o=o.multiplyUnsafe(r).negate(),s=s.add(o),s=s.subtract(n),s.subtract(e)}}),md={mapToG1:Ed,mapToG2:Bd,hasherOpts:ks,hasherOptsG1:{...ks,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},hasherOptsG2:{...ks}},bd={ateLoopSize:nr,xNegative:!0,twistType:"multiplicative",randomBytes:bt},uo=Fc(ld,hd,pd,bd,md,dd),yd=Ss(q,[[["0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6"],["0x0","0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71a"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71e","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38d"],["0x171d6541fa38ccfaed6dea691f5fb614cb14b4e7f4e810aa22d6108f142b85757098e38d0f671c7188e2aaaaaaaa5ed1","0x0"]],[["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa63"],["0xc","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa9f"],["0x1","0x0"]],[["0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706","0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706"],["0x0","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97be"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71c","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38f"],["0x124c9ad43b6cf79bfbf7043de3811ad0761b0f37a1e26286b0e977c69aa274524e79097a56dc4bd9e1b371c71c718b10","0x0"]],[["0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb"],["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa9d3"],["0x12","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99"],["0x1","0x0"]]].map(t=>t.map(e=>q.fromBigTuple(e.map(BigInt))))),xd=Ss(oe,[["0x11a05f2b1e833340b809101dd99815856b303e88a2d7005ff2627b56cdb4e2c85610c2d5f2e62d6eaeac1662734649b7","0x17294ed3e943ab2f0588bab22147a81c7c17e75b2f6a8417f565e33c70d1e86b4838f2a6f318c356e834eef1b3cb83bb","0xd54005db97678ec1d1048c5d10a9a1bce032473295983e56878e501ec68e25c958c3e3d2a09729fe0179f9dac9edcb0","0x1778e7166fcc6db74e0609d307e55412d7f5e4656a8dbf25f1b33289f1b330835336e25ce3107193c5b388641d9b6861","0xe99726a3199f4436642b4b3e4118e5499db995a1257fb3f086eeb65982fac18985a286f301e77c451154ce9ac8895d9","0x1630c3250d7313ff01d1201bf7a74ab5db3cb17dd952799b9ed3ab9097e68f90a0870d2dcae73d19cd13c1c66f652983","0xd6ed6553fe44d296a3726c38ae652bfb11586264f0f8ce19008e218f9c86b2a8da25128c1052ecaddd7f225a139ed84","0x17b81e7701abdbe2e8743884d1117e53356de5ab275b4db1a682c62ef0f2753339b7c8f8c8f475af9ccb5618e3f0c88e","0x80d3cf1f9a78fc47b90b33563be990dc43b756ce79f5574a2c596c928c5d1de4fa295f296b74e956d71986a8497e317","0x169b1f8e1bcfa7c42e0c37515d138f22dd2ecb803a0c5c99676314baf4bb1b7fa3190b2edc0327797f241067be390c9e","0x10321da079ce07e272d8ec09d2565b0dfa7dccdde6787f96d50af36003b14866f69b771f8c285decca67df3f1605fb7b","0x6e08c248e260e70bd1e962381edee3d31d79d7e22c837bc23c0bf1bc24c6b68c24b1b80b64d391fa9c8ba2e8ba2d229"],["0x8ca8d548cff19ae18b2e62f4bd3fa6f01d5ef4ba35b48ba9c9588617fc8ac62b558d681be343df8993cf9fa40d21b1c","0x12561a5deb559c4348b4711298e536367041e8ca0cf0800c0126c2588c48bf5713daa8846cb026e9e5c8276ec82b3bff","0xb2962fe57a3225e8137e629bff2991f6f89416f5a718cd1fca64e00b11aceacd6a3d0967c94fedcfcc239ba5cb83e19","0x3425581a58ae2fec83aafef7c40eb545b08243f16b1655154cca8abc28d6fd04976d5243eecf5c4130de8938dc62cd8","0x13a8e162022914a80a6f1d5f43e7a07dffdfc759a12062bb8d6b44e833b306da9bd29ba81f35781d539d395b3532a21e","0xe7355f8e4e667b955390f7f0506c6e9395735e9ce9cad4d0a43bcef24b8982f7400d24bc4228f11c02df9a29f6304a5","0x772caacf16936190f3e0c63e0596721570f5799af53a1894e2e073062aede9cea73b3538f0de06cec2574496ee84a3a","0x14a7ac2a9d64a8b230b3f5b074cf01996e7f63c21bca68a81996e1cdf9822c580fa5b9489d11e2d311f7d99bbdcc5a5e","0xa10ecf6ada54f825e920b3dafc7a3cce07f8d1d7161366b74100da67f39883503826692abba43704776ec3a79a1d641","0x95fc13ab9e92ad4476d6e3eb3a56680f682b4ee96f7d03776df533978f31c1593174e4b4b7865002d6384d168ecdd0a","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"],["0x90d97c81ba24ee0259d1f094980dcfa11ad138e48a869522b52af6c956543d3cd0c7aee9b3ba3c2be9845719707bb33","0x134996a104ee5811d51036d776fb46831223e96c254f383d0f906343eb67ad34d6c56711962fa8bfe097e75a2e41c696","0xcc786baa966e66f4a384c86a3b49942552e2d658a31ce2c344be4b91400da7d26d521628b00523b8dfe240c72de1f6","0x1f86376e8981c217898751ad8746757d42aa7b90eeb791c09e4a3ec03251cf9de405aba9ec61deca6355c77b0e5f4cb","0x8cc03fdefe0ff135caf4fe2a21529c4195536fbe3ce50b879833fd221351adc2ee7f8dc099040a841b6daecf2e8fedb","0x16603fca40634b6a2211e11db8f0a6a074a7d0d4afadb7bd76505c3d3ad5544e203f6326c95a807299b23ab13633a5f0","0x4ab0b9bcfac1bbcb2c977d027796b3ce75bb8ca2be184cb5231413c4d634f3747a87ac2460f415ec961f8855fe9d6f2","0x987c8d5333ab86fde9926bd2ca6c674170a05bfe3bdd81ffd038da6c26c842642f64550fedfe935a15e4ca31870fb29","0x9fc4018bd96684be88c9e221e4da1bb8f3abd16679dc26c1e8b6e6a1f20cabe69d65201c78607a360370e577bdba587","0xe1bba7a1186bdb5223abde7ada14a23c42a0ca7915af6fe06985e7ed1e4d43b9b3f7055dd4eba6f2bafaaebca731c30","0x19713e47937cd1be0dfd0b8f1d43fb93cd2fcbcb6caf493fd1183e416389e61031bf3a5cce3fbafce813711ad011c132","0x18b46a908f36f6deb918c143fed2edcc523559b8aaf0c2462e6bfe7f911f643249d9cdf41b44d606ce07c8a4d0074d8e","0xb182cac101b9399d155096004f53f447aa7b12a3426b08ec02710e807b4633f06c851c1919211f20d4c04f00b971ef8","0x245a394ad1eca9b72fc00ae7be315dc757b3b080d4c158013e6632d3c40659cc6cf90ad1c232a6442d9d3f5db980133","0x5c129645e44cf1102a159f748c4a3fc5e673d81d7e86568d9ab0f5d396a7ce46ba1049b6579afb7866b1e715475224b","0x15e6be4e990f03ce4ea50b3b42df2eb5cb181d8f84965a3957add4fa95af01b2b665027efec01c7704b456be69c8b604"],["0x16112c4c3a9c98b252181140fad0eae9601a6de578980be6eec3232b5be72e7a07f3688ef60c206d01479253b03663c1","0x1962d75c2381201e1a0cbd6c43c348b885c84ff731c4d59ca4a10356f453e01f78a4260763529e3532f6102c2e49a03d","0x58df3306640da276faaae7d6e8eb15778c4855551ae7f310c35a5dd279cd2eca6757cd636f96f891e2538b53dbf67f2","0x16b7d288798e5395f20d23bf89edb4d1d115c5dbddbcd30e123da489e726af41727364f2c28297ada8d26d98445f5416","0xbe0e079545f43e4b00cc912f8228ddcc6d19c9f0f69bbb0542eda0fc9dec916a20b15dc0fd2ededda39142311a5001d","0x8d9e5297186db2d9fb266eaac783182b70152c65550d881c5ecd87b6f0f5a6449f38db9dfa9cce202c6477faaf9b7ac","0x166007c08a99db2fc3ba8734ace9824b5eecfdfa8d0cf8ef5dd365bc400a0051d5fa9c01a58b1fb93d1a1399126a775c","0x16a3ef08be3ea7ea03bcddfabba6ff6ee5a4375efa1f4fd7feb34fd206357132b920f5b00801dee460ee415a15812ed9","0x1866c8ed336c61231a1be54fd1d74cc4f9fb0ce4c6af5920abc5750c4bf39b4852cfe2f7bb9248836b233d9d55535d4a","0x167a55cda70a6e1cea820597d94a84903216f763e13d87bb5308592e7ea7d4fbc7385ea3d529b35e346ef48bb8913f55","0x4d2f259eea405bd48f010a01ad2911d9c6dd039bb61a6290e591b36e636a5c871a5c29f4f83060400f8b49cba8f6aa8","0xaccbb67481d033ff5852c1e48c50c477f94ff8aefce42d28c0f9a88cea7913516f968986f7ebbea9684b529e2561092","0xad6b9514c767fe3c3613144b45f1496543346d98adf02267d5ceef9a00d9b8693000763e3b90ac11e99b138573345cc","0x2660400eb2e4f3b628bdd0d53cd76f2bf565b94e72927c1cb748df27942480e420517bd8714cc80d1fadc1326ed06f7","0xe0fa1d816ddc03e6b24255e0d7819c171c40f65e273b853324efcd6356caa205ca2f570f13497804415473a1d634b8f","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"]].map(t=>t.map(e=>BigInt(e)))),Xc,Wc,gd=()=>Xc||(Xc=Os(oe,{A:oe.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:oe.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:oe.create(BigInt(11))})),wd=()=>Wc||(Wc=Os(q,{A:q.create({c0:oe.create(Ls),c1:oe.create(BigInt(240))}),B:q.create({c0:oe.create(BigInt(1012)),c1:oe.create(BigInt(1012))}),Z:q.create({c0:oe.create(BigInt(-2)),c1:oe.create(BigInt(-1))})}));function Ed(t){let{x:e,y:r}=gd()(oe.create(t[0]));return xd(e,r)}function Bd(t){let{x:e,y:r}=wd()(q.fromBigTuple(t));return yd(e,r)}function na(t,e,r){let n=typeof t=="string"?Ae(t):t,o=typeof e=="string"?Ae(e):e,s=typeof r=="string"?Ae(r):r,i=uo.shortSignatures;return i.verify(o,i.hash(s),n)}function Er(t){if(!t)throw new Error("Input cannot be null or undefined");return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):Array.isArray(t)?new Uint8Array(t):"buffer"in t?Er(t.buffer):new Uint8Array(t)}function or(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}var oa=new TextEncoder().encode("\ric-state-root"),H0=new TextEncoder().encode(`
ic-request`),sa=new TextEncoder().encode("\vic-response"),V0=new TextEncoder().encode("ic-request-auth-delegation");var ia=60*1e3,Td=60,Od=24,_d=Od*Td,Id=5,vd=5,Rd=30*_d,pe;(function(t){t[t.Empty=0]="Empty",t[t.Fork=1]="Fork",t[t.Labeled=2]="Labeled",t[t.Leaf=3]="Leaf",t[t.Pruned=4]="Pruned"})(pe||(pe={}));function Ad(t,e){for(let r=0;r<t.length;r++)if(t[r]>e[r])return!0;return!1}var rn=class t{#e=!1;#t=void 0;static async create(e){let r=t.createUnverified(e);return await r.verify(),r}static createUnverified(e){return new t(e.certificate,e.rootKey,e.principal,e.blsVerify??na,e.maxAgeInMinutes,e.disableTimeVerification,e.agent)}constructor(e,r,n,o,s=Id,i=!1,c){this._rootKey=r,this._principal=n,this._blsVerify=o,this._maxAgeInMinutes=s,this.#e=i,this.cert=ke(e),c&&"getTimeDiffMsecs"in c&&"hasSyncedTime"in c&&"syncTime"in c&&(this.#t=c)}lookup_path(e){return Ut(e,this.cert.tree)}lookup_subtree(e){return nn(e,this.cert.tree)}async verify(){let e=await ho(this.cert.tree),r=await this._checkDelegationAndGetKey(this.cert.delegation),n=this.cert.signature,o=Nd(r),s=Te(oa,e),i=Le(this.lookup_path(["time"]));if(!i)throw te.fromCode(new Ye("Certificate does not contain a time"));if(!this.#e){let c=this.#t?.getTimeDiffMsecs()??0,a=this._maxAgeInMinutes*ia,f=new Date,u=f.getTime()+c,d=u-a,l=u+vd*ia,h=mr(i),m=h.getTime()<d,b=h.getTime()>l;if((m||b)&&this.#t&&!this.#t.hasSyncedTime())return await this._syncTime(),await this.verify();if(m)throw Ce.fromCode(new mt(this._maxAgeInMinutes,h,f,c,"past"));if(b)throw this.#t?.hasSyncedTime()?ge.fromCode(new Ne("System time has been synced with the IC network, but certificate is still too far in the future.")):Ce.fromCode(new mt(5,h,f,c,"future"))}try{if(!await this._blsVerify(o,n,s))throw Ce.fromCode(new Ye("Invalid signature"))}catch(c){throw Ce.fromCode(new Ye("Signature verification failed",c))}}async _checkDelegationAndGetKey(e){if(!e)return this._rootKey;let r=t.createUnverified({certificate:e.certificate,rootKey:this._rootKey,principal:this._principal,blsVerify:this._blsVerify,disableTimeVerification:this.#e,maxAgeInMinutes:Rd,agent:this.#t});if(r.cert.delegation)throw te.fromCode(new _n);await r.verify();let n;if(aa(this._principal)){let s=this._principal.canisterId;if(n=L.fromUint8Array(e.subnet_id),!js({canisterId:s,subnetId:n,tree:r.cert.tree}))throw Ce.fromCode(new Kt(s,n))}else if(ca(this._principal))n=this._principal.subnetId;else throw it;let o=Le(r.lookup_path(["subnet",n.toUint8Array(),"public_key"]));if(!o)throw ca(this._principal)?Ce.fromCode(new In(n)):Ce.fromCode(new Rn(`Could not find subnet key for subnet ID ${n.toText()}`));return o}async _syncTime(){this.#t&&(aa(this._principal)?await this.#t.syncTime({canisterId:this._principal.canisterId}):await this.#t.syncTime({subnetId:this._principal.subnetId}))}};function ca(t){return"subnetId"in t}function aa(t){return"canisterId"in t}var en=Ae("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),Cd=96;function Nd(t){let e=en.byteLength+Cd;if(t.byteLength!==e)throw te.fromCode(new hr(e,t.byteLength));let r=t.slice(0,en.byteLength);if(!or(r,en))throw te.fromCode(new An(en,r));return t.slice(en.byteLength)}function Le(t){if(t.status===Ie.Found&&t.value instanceof Uint8Array)return t.value}async function ho(t){switch(t[0]){case pe.Empty:return Oe(lo("ic-hashtree-empty"));case pe.Pruned:return t[1];case pe.Leaf:return Oe(Te(lo("ic-hashtree-leaf"),t[1]));case pe.Labeled:return Oe(Te(lo("ic-hashtree-labeled"),t[1],await ho(t[2])));case pe.Fork:return Oe(Te(lo("ic-hashtree-fork"),await ho(t[1]),await ho(t[2])));default:throw it}}function lo(t){let e=new Uint8Array([t.length]),r=new TextEncoder().encode(t);return Te(e,r)}function fa(t){return typeof t[0]=="string"?Se(t[0]):t[0]}var Ie;(function(t){t.Unknown="Unknown",t.Absent="Absent",t.Found="Found",t.Error="Error"})(Ie||(Ie={}));var kt;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found"})(kt||(kt={}));var ae;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found",t.Less="Less",t.Greater="Greater"})(ae||(ae={}));function Ut(t,e){if(t.length===0)switch(e[0]){case pe.Empty:return{status:Ie.Absent};case pe.Leaf:{if(!e[1])throw ge.fromCode(new Tt("Invalid tree structure for leaf"));if(e[1]instanceof Uint8Array)return{status:Ie.Found,value:e[1].slice(e[1].byteOffset,e[1].byteLength+e[1].byteOffset)};throw it}case pe.Pruned:return{status:Ie.Unknown};case pe.Labeled:case pe.Fork:return{status:Ie.Error};default:throw it}let r=fa(t),n=tn(r,e);switch(n.status){case ae.Found:return Ut(t.slice(1),n.value);case ae.Absent:case ae.Greater:case ae.Less:return{status:Ie.Absent};case ae.Unknown:return{status:Ie.Unknown};default:throw it}}function nn(t,e){if(t.length===0)return{status:kt.Found,value:e};let r=fa(t),n=tn(r,e);switch(n.status){case ae.Found:return nn(t.slice(1),n.value);case ae.Unknown:return{status:kt.Unknown};case ae.Absent:case ae.Greater:case ae.Less:return{status:kt.Absent};default:throw it}}function mo(t){switch(t[0]){case pe.Empty:return[];case pe.Fork:return mo(t[1]).concat(mo(t[2]));default:return[t]}}function tn(t,e){switch(e[0]){case pe.Labeled:return Ad(t,e[1])?{status:ae.Greater}:or(t,e[1])?{status:ae.Found,value:e[2]}:{status:ae.Less};case pe.Fork:{let r=tn(t,e[1]);switch(r.status){case ae.Greater:{let n=tn(t,e[2]);return n.status===ae.Less?{status:ae.Absent}:n}case ae.Unknown:{let n=tn(t,e[2]);return n.status===ae.Less?{status:ae.Unknown}:n}default:return r}}case pe.Pruned:return{status:ae.Unknown};default:return{status:ae.Absent}}}function po(t,e){switch(e[0]){case pe.Empty|pe.Pruned:return[];case pe.Leaf:return[t];case pe.Fork:return po(t,e[1]).concat(po(t,e[2]));case pe.Labeled:{let r=e[1],n=e[2],o=[...t,r];return po(o,n)}default:throw it}}function js(t){let e=kd(t),r=$s(e),{canisterId:n}=t;return r.some(s=>s[0].ltEq(n)&&s[1].gtEq(n))}function kd(t){let{subnetId:e,tree:r,canisterId:n}=t,o=nn(["canister_ranges",e.toUint8Array()],r);if(o.status!==kt.Found)return Ud(e,r);let s=o.value,i=Fd(s);if(i.length===0)throw te.fromCode(new Kt(n,e));i.sort(Yr);let c=qd(i,n),a=i[c];return Md(a,s)}function Ud(t,e){let r=Ut(["subnet",t.toUint8Array(),"canister_ranges"],e);if(r.status!==Ie.Found)throw te.fromCode(new Ge(`Could not find canister ranges for subnet ${t.toText()}`,r.status));return r.value}function $s(t){return ke(t).map(n=>[L.fromUint8Array(n[0]),L.fromUint8Array(n[1])])}function Fd(t){let e=[];for(let r of po([],t)){let n=r[0];if(!n)throw te.fromCode(new Ye("Path is invalid"));e.push(n)}return e}function qd(t,e){let r=e.toUint8Array(),n=0,o=t.length-1;for(;n<o;){let s=Math.floor((n+o)/2);Yr(t[s],r)<=0?o=s:n=s+1}return n}function Md(t,e){let r=Ut([t],e);if(r.status!==Ie.Found)throw te.fromCode(new Ge(`Could not find canister range for shard ${t.toString()}`,r.status));return r.value}function Ps(t,e){return t.delegation?L.fromUint8Array(t.delegation.subnet_id):L.selfAuthenticating(e)}var ua=L.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe"),ve=class{constructor(e,r){this.decode=r,this.key=Symbol();let n=Array.isArray(e)?e:[e];this.path=n.map(o=>typeof o=="string"?Se(o):o)}};var ut={time:new ve(["time"],mr),canisterControllers:t=>new ve(["canister",t.toUint8Array(),"controllers"],Ld),canisterModuleHash:t=>new ve(["canister",t.toUint8Array(),"module_hash"],e=>e),canisterCandid:t=>ut.canisterMetadataString(t,"candid:service"),canisterMetadataString:(t,e)=>new ve(["canister",t.toUint8Array(),"metadata",e],r=>new TextDecoder().decode(r)),subnetCanisterRanges:t=>new ve(["subnet",t.toUint8Array(),"canister_ranges"],$s),subnetPublicKey:t=>new ve(["subnet",t.toUint8Array(),"public_key"],e=>e)},bo=class{#e;constructor(e=new Map){this.#e=e}get(e){return this.#e.get(e.key)??null}};function da(t){return Array.isArray(t)?t:t.path}function yo(t,e){switch(e){case"raw":return t;case"leb128":return fs(t);case"cbor":return ke(t);case"hex":return ne(t);case"utf-8":return new TextDecoder().decode(t)}}function Ld(t){return ke(t).map(r=>L.fromUint8Array(r))}function Br(t,e){let r=nn(["subnet",e.toUint8Array(),"node"],t.tree);if(r.status!==kt.Found)throw te.fromCode(new Ge("Node not found",r.status));if(r.value instanceof Uint8Array)throw ge.fromCode(new Tt("Invalid node tree"));let n=mo(r.value),o=new Map;return n.forEach(s=>{let i=L.from(s[1]).toText(),c=Ut(["public_key"],s[2]);if(c.status!==Ie.Found)throw te.fromCode(new Ge("Public key not found",c.status));let a=c.value;if(a.byteLength!==44)throw te.fromCode(new hr(44,a.byteLength));o.set(i,a)}),o}var la;(function(t){t[t.SysFatal=1]="SysFatal",t[t.SysTransient=2]="SysTransient",t[t.DestinationInvalid=3]="DestinationInvalid",t[t.CanisterReject=4]="CanisterReject",t[t.CanisterError=5]="CanisterError"})(la||(la={}));var on;(function(t){t.Replied="replied",t.Rejected="rejected"})(on||(on={}));function ha(t){return t!=null&&"reject_code"in t}function pa(t){return t!=null&&"certificate"in t}function Hs(t){if(typeof t=="string")return ma(t);if(typeof t=="number")return Oe(Gr(t));if(t instanceof Uint8Array||ArrayBuffer.isView(t))return Oe(Er(t));if(Array.isArray(t)){let e=t.map(Hs);return Oe(Te(...e))}if(t&&typeof t=="object"&&t._isPrincipal)return Oe(t.toUint8Array());if(typeof t=="object"&&t!==null&&typeof t.toHash=="function")return Hs(t.toHash());if(typeof t=="object")return sn(t);if(typeof t=="bigint")return Oe(Gr(t));throw W.fromCode(new Ln(t))}var ma=t=>{let e=new TextEncoder().encode(t);return Oe(e)};function xo(t){return sn(t)}function sn(t){let n=Object.entries(t).filter(([,i])=>i!==void 0).map(([i,c])=>{let a=ma(i),f=Hs(c);return[a,f]}).sort(([i],[c])=>Yr(i,c)),o=Te(...n.map(i=>Te(...i)));return Oe(o)}var sr=class{getPrincipal(){return L.anonymous()}async transformRequest(e){return{...e,body:{content:e.body}}}};var cn=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){let t=new Uint32Array(1);return window.crypto.getRandomValues(t),t[0]}if(typeof crypto<"u"&&crypto.getRandomValues){let t=new Uint32Array(1);return crypto.getRandomValues(t),t[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var xt;(function(t){t.Query="read",t.ReadState="read_state",t.Call="call"})(xt||(xt={}));var go;(function(t){t.Call="call"})(go||(go={}));var ir;(function(t){t.Query="query",t.ReadState="read_state"})(ir||(ir={}));var De;(function(t){t.Received="received",t.Processing="processing",t.Replied="replied",t.Rejected="rejected",t.Unknown="unknown",t.Done="done"})(De||(De={}));function an(){let t=new ArrayBuffer(16),e=new DataView(t),r=cn(),n=cn(),o=cn(),s=cn();return e.setUint32(0,r),e.setUint32(4,n),e.setUint32(8,o),e.setUint32(12,s),Object.assign(new Uint8Array(t),{__nonce__:void 0})}function Vs(t=an){return async e=>{let r=e.request.headers;e.request.headers=r,e.endpoint===xt.Call&&(e.body.nonce=t())}}function zs(t){let e=[];return t.forEach((r,n)=>{e.push([n,r])}),e}var Dd=(t,e)=>{switch(t){case"time":return ut.time;case"controllers":return ut.canisterControllers(e);case"module_hash":return new ve(ut.canisterModuleHash(e).path,ne);case"candid":return ut.canisterCandid(e)}},jd=(t,e)=>{let r=n=>yo(n,t.decodeStrategy);return typeof t.path=="string"||t.path instanceof Uint8Array?new ve(["canister",e.toUint8Array(),"metadata",t.path],r):new ve(t.path,r)},ba=async t=>{let{agent:e,paths:r,disableCertificateTimeVerification:n=!1}=t,o=L.from(t.canisterId),s=[...new Set(r??[])],i=new Map,c=f=>typeof f=="string"?f:f.key,a=s.map(async f=>{try{if(e.rootKey===null)throw Me.fromCode(new We);let u=e.rootKey;if(f==="subnet"){let h=await e.readState({canisterId:o},{paths:[[Se("subnet")]],disableTimeVerification:n});i.set("subnet",$d(h.certificate,o,u));return}let d=typeof f=="string"?Dd(f,o):jd(f,o),{values:l}=await e.readState({canisterId:o},{paths:[d],disableTimeVerification:n});i.set(c(f),l.get(d))}catch(u){if(u instanceof qe&&(u.hasCode(Ye)||u.hasCode(mt)||u.hasCode(We)))throw u;i.set(c(f),null)}});return await Promise.all(a),i},$d=(t,e,r)=>{if(!e._isPrincipal)throw W.fromCode(new Ne("Invalid canisterId"));let n=ke(t),{delegation:o}=n,s;o&&o.subnet_id?s=L.fromUint8Array(new Uint8Array(o.subnet_id)):!o&&typeof r<"u"?s=L.selfAuthenticating(new Uint8Array(r)):s=ua;let i=Br(n,s);return{subnetId:s.toText(),nodeKeys:i}};var Pd=(t,e)=>{switch(t){case"time":return ut.time;case"publicKey":return ut.subnetPublicKey(e);case"canisterRanges":return ut.subnetCanisterRanges(e)}},Hd=(t,e)=>{let r=n=>yo(n,t.decodeStrategy);return typeof t.path=="string"||t.path instanceof Uint8Array?new ve(["subnet",e.toUint8Array(),t.path],r):new ve(t.path,r)};async function ya(t){let{agent:e,paths:r,disableCertificateTimeVerification:n=!1}=t,o=L.from(t.subnetId),s=[...new Set(r??[])],i=new Map,c=f=>typeof f=="string"?f:f.key,a=s.map(async f=>{try{if(f==="nodeKeys"){let{verifiedCertificate:l}=await e.readState({subnetId:o},{paths:[[Se("subnet"),o.toUint8Array(),Se("node")]],disableTimeVerification:n});i.set("nodeKeys",Br(l.cert,o));return}let u=typeof f=="string"?Pd(f,o):Hd(f,o),{values:d}=await e.readState({subnetId:o},{paths:[u],disableTimeVerification:n});i.set(c(f),d.get(u))}catch(u){if(u instanceof qe&&(u.hasCode(Ye)||u.hasCode(mt)||u.hasCode(We)))throw u;i.set(c(f),null)}});return await Promise.all(a),i}function wo(t,e,r){let n=new Uint8Array(Le(t.lookup_path([...e,"reject_code"])))[0],o=new TextDecoder().decode(Le(t.lookup_path([...e,"reject_message"]))),s=Le(t.lookup_path([...e,"error_code"])),i=s?new TextDecoder().decode(s):void 0;return new Fn(r,n,o,i)}var Eo=BigInt(0),Bo=BigInt(1),So=BigInt(2),Vd=BigInt(4),xa=BigInt(8);function zd(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),c=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,c)}function ga(t,e={}){le(e,{},{},"extraOpts");let r=e,n=oo("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:c}=i;if(yt(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(yt(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");le(r,{},{uvRatio:"function",randomBytes:"function"});let a=r.randomBytes===void 0?bt:r.randomBytes,f=So<<BigInt(o.BYTES*8)-Bo;function u(g){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(g)}let d=r.uvRatio===void 0?(g,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(g,y))}}catch{return{isValid:!1,value:Eo}}}:r.uvRatio;if(!zd(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let l=o.eql(i.a,o.neg(o.ONE))?g=>o.neg(g):o.eql(i.a,o.ONE)?g=>g:g=>o.mul(i.a,g);function h(g,y,O=!1){let S=O?Bo:Eo;return Jt("coordinate "+g,y,S,f),y}function m(g){if(!(g instanceof b))throw new Error("EdwardsPoint expected")}class b{static BASE=new b(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new b(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(y,O,S,M){this.X=h("x",y),this.Y=h("y",O),this.Z=h("z",S,!0),this.T=h("t",M),Object.freeze(this)}static CURVE(){return i}static fromAffine(y){if(y instanceof b)throw new Error("extended point not allowed");let{x:O,y:S}=y||{};return h("x",O),h("y",S),new b(O,S,o.ONE,o.mul(O,S))}static fromBytes(y,O=!1){let S=o.BYTES,{a:M,d:$}=i;y=at(Q(y,S,"point")),Pe(O,"zip215");let R=at(y),F=y[S-1];R[S-1]=F&-129;let P=Qt(R),K=O?f:o.ORDER;Jt("point.y",P,Eo,K);let X=o.sqr(P),re=o.sub(X,o.ONE),N=o.sub(o.mulN($,X),M),{isValid:V,value:z}=d(re,N);if(!V)throw new Error("bad point: invalid y coordinate");let E=u(z),A=(F&128)!==0;if(!O&&o.is0(z)&&A)throw new Error("bad point: x=0 and x_0=1");return A!==E&&(z=o.neg(z)),b.fromAffine({x:z,y:P})}static fromHex(y,O=!1){return b.fromBytes(Wt(y),O)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,O=!0){return x.setWindowSize(this,y),O||this.multiply(So),this}assertValidity(){let y=this,{a:O,d:S}=i;if(y.is0())throw new Error("bad point: ZERO");let{X:M,Y:$,Z:R,T:F}=y,P=o.sqr(M),K=o.sqr($),X=o.sqr(R),re=o.sqr(X),N=o.mul(P,O),V=o.mul(o.add(N,K),X),z=o.add(re,o.mul(S,o.mul(P,K)));if(!o.eql(V,z))throw new Error("bad point: equation left != right (1)");let E=o.mul(M,$),A=o.mul(R,F);if(!o.eql(E,A))throw new Error("bad point: equation left != right (2)")}equals(y){m(y);let{X:O,Y:S,Z:M}=this,{X:$,Y:R,Z:F}=y,P=o.mul(O,F),K=o.mul($,M),X=o.mul(S,F),re=o.mul(R,M);return o.eql(P,K)&&o.eql(X,re)}is0(){return this.equals(b.ZERO)}negate(){return new b(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:y,Y:O,Z:S}=this,M=o.sqr(y),$=o.sqr(O),R=o.mul(o.sqr(S),So),F=l(M),P=o.addN(y,O),K=o.sub(o.subN(o.sqr(P),M),$),X=o.addN(F,$),re=o.subN(X,R),N=o.subN(F,$),V=o.mul(K,re),z=o.mul(X,N),E=o.mul(K,N),A=o.mul(re,X);return new b(V,z,A,E)}add(y){m(y);let{d:O}=i,{X:S,Y:M,Z:$,T:R}=this,{X:F,Y:P,Z:K,T:X}=y,re=o.mul(S,F),N=o.mul(M,P),V=o.mul(o.mulN(R,O),X),z=o.mul($,K),E=o.sub(o.subN(o.mulN(o.addN(S,M),o.addN(F,P)),re),N),A=o.subN(z,V),C=o.addN(z,V),I=o.sub(N,l(re)),w=o.mul(E,A),B=o.mul(C,I),_=o.mul(E,I),v=o.mul(A,C);return new b(w,B,v,_)}subtract(y){return m(y),this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:O,f:S}=x.mulSecret(this,y,c,p);return p([O,S])[0]}multiplyUnsafe(y){if(!s.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===Eo?b.ZERO:this.is0()||y===Bo?this:x.mulUnsafe(this,y,p)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(y){let O=this,S=y;if(S!=null&&typeof S!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof S);let{X:M,Y:$,Z:R}=O,F=O.is0();S==null&&(S=F?o.create(xa):o.inv(R));let P=o.mul(M,S),K=o.mul($,S),X=o.mul(R,S);if(F)return{x:o.ZERO,y:o.ONE};if(!o.eql(X,o.ONE))throw new Error("invZ was invalid");return{x:P,y:K}}clearCofactor(){return c===Bo?this:c===So?this.double():c===Vd?this.double().double():c===xa?this.double().double().double():this.multiplyUnsafe(c)}toBytes(){let{x:y,y:O}=this.toAffine(),S=o.toBytes(O);return S[S.length-1]|=u(y)?128:0,S}toHex(){return Xt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let p=g=>ro(b,g),x=new br(b,a);return x.bits>=6&&b.BASE.precompute(6),Object.freeze(b.prototype),Object.freeze(b),b}function wa(t,e,r={}){if(At(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;le(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:c,Fn:a}=t,f=n.outputLen,u=2*c.BYTES;if(f!==void 0&&(ie(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let d=o.randomBytes===void 0?bt:o.randomBytes,l=o.toMontgomery,h=o.toMontgomerySecret,m=o.adjustScalarBytes===void 0?N=>N:o.adjustScalarBytes,b=o.domain===void 0?(N,V,z)=>{if(Pe(z,"phflag"),V.length||z)throw new Error("Contexts/pre-hash are not supported");return N}:o.domain;function p(N){return a.create(Qt(N))}function x(N){let V=F.secretKey;Q(N,F.secretKey,"secretKey");let z=Q(n(N),2*V,"hashedSecretKey"),E=m(z.slice(0,V)),A=z.slice(V,2*V),C=p(E);return{head:E,prefix:A,scalar:C}}function g(N){let{head:V,prefix:z,scalar:E}=x(N),A=i.multiply(E),C=A.toBytes();return{head:V,prefix:z,scalar:E,point:A,pointBytes:C}}function y(N){return g(N).pointBytes}function O(N=Uint8Array.of(),...V){let z=ye(...V);return p(n(b(z,Q(N,void 0,"context"),!!s)))}function S(N,V,z={}){le(z,{},{},"options"),N=at(Q(N,void 0,"message")),s&&(N=s(N));let{prefix:E,scalar:A,pointBytes:C}=g(V),I=O(z.context,E,N),w=i.multiply(I).toBytes(),B=O(z.context,w,C,N),_=a.create(I+B*A);if(!a.isValid(_))throw new Error("sign failed: invalid s");let v=ye(w,a.toBytes(_));return Q(v,F.signature,"result")}let M={zip215:o.zip215};function $(N,V,z,E=M){le(E);let{context:A}=E,C=E.zip215===void 0?!!M.zip215:E.zip215,I=F.signature;N=Q(N,I,"signature"),V=Q(V,void 0,"message"),z=Q(z,F.publicKey,"publicKey"),C!==void 0&&Pe(C,"zip215"),s&&(V=s(V));let w=I/2,B=N.subarray(0,w),_=Qt(N.subarray(w,I)),v,U,k;try{v=t.fromBytes(z,C),U=t.fromBytes(B,C),k=i.multiplyUnsafe(_)}catch{return!1}if(!C&&v.isSmallOrder())return!1;let j=O(A,B,z,V);return U.add(v.multiplyUnsafe(j)).subtract(k).clearCofactor().is0()}let R=c.BYTES,F={secretKey:R,publicKey:R,signature:2*R,seed:R};function P(N){return N=N===void 0?d(F.seed):N,Q(N,F.seed,"seed")}function K(N){return ct(N)&&N.length===F.secretKey}function X(N,V){try{return!!t.fromBytes(N,V===void 0?M.zip215:V)}catch{return!1}}let re={getExtendedPublicKey:g,randomSecretKey:P,isValidSecretKey:K,isValidPublicKey:X,toMontgomery(N){if(l===void 0)throw new Error("Montgomery conversion is not supported for this curve");return l(t.fromBytes(N))},toMontgomerySecret(N){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(N)}};return Object.freeze(F),Object.freeze(re),Object.freeze({keygen:Es(P,y),getPublicKey:y,sign:S,verify:$,utils:re,Point:t,lengths:F})}var Ks=BigInt(1),Ea=BigInt(2);var Kd=BigInt(5),Zd=BigInt(8),Zs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Yd={p:Zs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Zd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Gd(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Zs,c=t*t%s*t%s,a=Je(c,Ea,s)*c%s,f=Je(a,Ks,s)*t%s,u=Je(f,Kd,s)*f%s,d=Je(u,e,s)*u%s,l=Je(d,r,s)*d%s,h=Je(l,n,s)*l%s,m=Je(h,o,s)*h%s,b=Je(m,o,s)*h%s,p=Je(b,e,s)*u%s;return{pow_p_5_8:Je(p,Ea,s)*t%s,b2:c}}function Ta(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Ba=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Xd(t,e){let r=Zs,n=ce(e*e*e,r),o=ce(n*n*e,r),s=Gd(t*o).pow_p_5_8,i=ce(t*n*s,r),c=ce(e*i*i,r),a=i,f=ce(i*Ba,r),u=c===t,d=c===ce(-t,r),l=c===ce(-t*Ba,r);return u&&(i=a),(d||l)&&(i=f),gc(i,r)&&(i=ce(-i,r)),{isValid:u||d,value:i}}var Ys=ga(Yd,{uvRatio:Xd}),Sa=Ys.Fp;function Wd(t){let{y:e}=t;return Sa.toBytes(Sa.div(Ks+e,Ks-e))}function Qd(t){let e=Ys.Fp.BYTES;return nt(t,e),Ta(rs(t.subarray(0,e))).subarray(0,e)}function Jd(t){return wa(Ys,rs,Object.assign({adjustScalarBytes:Ta,toMontgomery:Wd,toMontgomerySecret:Qd,zip215:!0},t))}var Oa=Jd({});function To(t){if(!Number.isFinite(t)||t<=0)throw new Error(`expirationTime must be a positive finite number, got ${t}`)}var Oo=class{#e;#t;#r=null;constructor(e){if(typeof globalThis.indexedDB>"u")throw new Error("IndexedDBExpirableStore requires IndexedDB, which is not available in this environment");To(e.expirationTime),this.#e=e.dbName,this.#t=e.storeName,this.expirationTime=e.expirationTime}#o(){return this.#r||(this.#r=this.#i().catch(e=>{throw this.#r=null,e})),this.#r}async#i(){let e=await this.#c();if(e.objectStoreNames.contains(this.#t))return e;let r=e.version+1;return e.close(),this.#c(r)}#c(e){let r=this.#t;return new Promise((n,o)=>{let s=globalThis.indexedDB.open(this.#e,e);s.onupgradeneeded=()=>{let i=s.result;i.objectStoreNames.contains(r)||i.createObjectStore(r,{keyPath:"key"})},s.onsuccess=()=>{let i=s.result;i.onversionchange=()=>{i.close(),this.#r=null},n(i)},s.onerror=()=>o(s.error)})}async get(e){let r=await this.#o();return new Promise((n,o)=>{let c=r.transaction(this.#t,"readonly").objectStore(this.#t).get(e);c.onsuccess=()=>{let a=c.result;if(!a){n(void 0);return}if(Date.now()-a.timestamp>this.expirationTime){this.delete(e).then(()=>n(void 0),()=>n(void 0));return}n(a.value)},c.onerror=()=>o(c.error)})}async set(e,r){await this.#f();let n=await this.#o();return new Promise((o,s)=>{let i=n.transaction(this.#t,"readwrite"),c=i.objectStore(this.#t),a={key:e,value:r,timestamp:Date.now()};c.put(a),i.oncomplete=()=>o(),i.onerror=()=>s(i.error)})}async delete(e){let r=await this.#o();return new Promise((n,o)=>{let s=r.transaction(this.#t,"readwrite");s.objectStore(this.#t).delete(e),s.oncomplete=()=>n(),s.onerror=()=>o(s.error)})}async#f(){let e=await this.#o(),r=Date.now();return new Promise((n,o)=>{let s=e.transaction(this.#t,"readwrite"),c=s.objectStore(this.#t).openCursor();c.onsuccess=()=>{let a=c.result;if(!a)return;let f=a.value;r-f.timestamp>this.expirationTime&&a.delete(),a.continue()},s.oncomplete=()=>n(),s.onerror=()=>o(s.error)})}};var _o=class{#e;constructor(e){To(e.expirationTime),this.expirationTime=e.expirationTime,this.#e=new Map}get(e){let r=this.#e.get(e);return r?Date.now()-r.timestamp>this.expirationTime?(this.#e.delete(e),Promise.resolve(void 0)):Promise.resolve(r.value):Promise.resolve(void 0)}set(e,r){return this.#t(),this.#e.set(e,{value:r,timestamp:Date.now()}),Promise.resolve()}delete(e){return this.#e.delete(e),Promise.resolve()}#t(){let e=Date.now();for(let[r,n]of this.#e)e-n.timestamp>this.expirationTime&&this.#e.delete(r)}};function _a(t){return typeof globalThis.indexedDB<"u"?new Oo(t):new _o({expirationTime:t.expirationTime})}var Ia=t=>{if(t<=127)return 1;if(t<=255)return 2;if(t<=65535)return 3;if(t<=16777215)return 4;throw W.fromCode(new Pr("Length too long (> 4 bytes)"))},va=(t,e,r)=>{if(r<=127)return t[e]=r,1;if(r<=255)return t[e]=129,t[e+1]=r,2;if(r<=65535)return t[e]=130,t[e+1]=r>>8,t[e+2]=r,3;if(r<=16777215)return t[e]=131,t[e+1]=r>>16,t[e+2]=r>>8,t[e+3]=r,4;throw W.fromCode(new Pr("Length too long (> 4 bytes)"))},Gs=(t,e)=>{if(t[e]<128)return 1;if(t[e]===128)throw W.fromCode(new Xe("Invalid length 0"));if(t[e]===129)return 2;if(t[e]===130)return 3;if(t[e]===131)return 4;throw W.fromCode(new Xe("Length too long (> 4 bytes)"))},el=(t,e)=>{let r=Gs(t,e);if(r===1)return t[e];if(r===2)return t[e+1];if(r===3)return(t[e+1]<<8)+t[e+2];if(r===4)return(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];throw W.fromCode(new Xe("Length too long (> 4 bytes)"))},np=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),Xs=Uint8Array.from([48,5,6,3,43,101,112]),op=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]),sp=Uint8Array.from([48,29,6,13,43,6,1,4,1,130,220,124,5,3,1,2,1,6,12,43,6,1,4,1,130,220,124,5,3,2,1]);function Ra(t,e){let r=2+Ia(t.byteLength+1),n=e.byteLength+r+t.byteLength,o=0,s=new Uint8Array(1+Ia(n)+n);return s[o++]=48,o+=va(s,o,n),s.set(e,o),o+=e.byteLength,s[o++]=3,o+=va(s,o,t.byteLength+1),s[o++]=0,s.set(new Uint8Array(t),o),s}var Aa=(t,e)=>{let r=0,n=(c,a)=>{if(o[r++]!==c)throw W.fromCode(new Xe(`Expected ${a} at offset ${r}`))},o=new Uint8Array(t);if(n(48,"sequence"),r+=Gs(o,r),!or(o.slice(r,r+e.byteLength),e))throw W.fromCode(new Xe("Not the expected OID."));r+=e.byteLength,n(3,"bit string");let s=el(o,r)-1;r+=Gs(o,r),n(0,"0 padding");let i=o.slice(r);if(s!==i.length)throw W.fromCode(new Cn(s,i.length));return i};var Io=class t{static from(e){return this.fromDer(e.toDer())}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static{this.RAW_KEY_LENGTH=32}static derEncode(e){return Ra(e,Xs)}static derDecode(e){let r=Aa(e,Xs);if(r.length!==this.RAW_KEY_LENGTH)throw W.fromCode(new Xe("An Ed25519 public key must be exactly 32 bytes long"));return r}#e;get rawKey(){return this.#e}#t;get derKey(){return this.#t}constructor(e){if(e.byteLength!==t.RAW_KEY_LENGTH)throw W.fromCode(new Xe("An Ed25519 public key must be exactly 32 bytes long"));this.#e=e.slice(),this.#t=t.derEncode(this.#e)}toDer(){return this.derKey}toRaw(){return this.rawKey}};var Ws=class{constructor(){this.observers=[]}subscribe(e){this.observers.push(e)}unsubscribe(e){this.observers=this.observers.filter(r=>r!==e)}notify(e,...r){this.observers.forEach(n=>n(e,...r))}},vo=class extends Ws{constructor(){super()}print(e,...r){this.notify({message:e,level:"info"},...r)}warn(e,...r){this.notify({message:e,level:"warn"},...r)}error(e,r,...n){this.notify({message:e,level:"error",error:r},...n)}};var Ro=class t{#e;#t;#r;#o;#i;#c;#f;#s;#n=0;static{this.default={initialInterval:500,randomizationFactor:.5,multiplier:1.5,maxInterval:6e4,maxElapsedTime:9e5,maxIterations:10,date:Date}}constructor(e=t.default){let{initialInterval:r=500,randomizationFactor:n=.5,multiplier:o=1.5,maxInterval:s=6e4,maxElapsedTime:i=9e5,maxIterations:c=10,date:a=Date}=e;this.#e=r,this.#t=n,this.#r=o,this.#o=s,this.#s=a,this.#i=a.now(),this.#c=i,this.#f=c}get ellapsedTimeInMsec(){return this.#s.now()-this.#i}get currentInterval(){return this.#e}get count(){return this.#n}get randomValueFromInterval(){let e=this.#t*this.#e,r=this.#e-e,n=this.#e+e;return Math.random()*(n-r)+r}incrementCurrentInterval(){return this.#e=Math.min(this.#e*this.#r,this.#o),this.#n++,this.#e}next(){return this.ellapsedTimeInMsec>=this.#c||this.#n>=this.#f?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};var tl=300*1e3;function Ca(){return il(nl(rl(),1e3),sl(1e3,1.2),ol(tl))}function rl(){let t=!0;return async()=>t?(t=!1,!0):!1}function nl(t,e){return async(r,n,o)=>{if(await t(r,n,o))return new Promise(s=>setTimeout(s,e))}}function ol(t){let e=Date.now()+t;return async(r,n,o)=>{if(Date.now()>e)throw te.fromCode(new Zt(`Request timed out after ${t} msec`,n,o))}}function sl(t,e){let r=t;return()=>new Promise(n=>setTimeout(()=>{r*=e,n()},r))}function il(...t){return async(e,r,n)=>{for(let o of t)await o(e,r,n)}}function Ft(t){return"canisterId"in t?{canisterId:L.from(t.canisterId)}:{subnetId:L.from(t.subnetId)}}function Ao(t){return"canisterId"in t?`canister:${t.canisterId.toText()}`:`subnet:${t.subnetId.toText()}`}function ka(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function Qs(t,e){return t!==null&&typeof t=="object"&&ka(t,e)}function al(t,e){return ka(t,e)&&typeof t[e]=="function"}function Na(t){return Qs(t,"body")&&Qs(t.body,"content")&&t.body.content.request_type===ir.ReadState&&Qs(t.body.content,"ingress_expiry")&&typeof t.body.content.ingress_expiry=="object"&&t.body.content.ingress_expiry!==null&&al(t.body.content.ingress_expiry,"toHash")}async function Co(t,e,r,n={}){(typeof e=="string"||e instanceof L)&&(e={canisterId:L.from(e)});let o=Ft(e),s=[Se("request_status"),r],i,c;n.preSignReadStateRequest??!1?(c=await fl({paths:[s],agent:t,pollingOptions:n}),i=await t.readState(o,{paths:[s],blsVerify:n.blsVerify},void 0,c)):i=await t.readState(o,{paths:[s],blsVerify:n.blsVerify});let f=i.verifiedCertificate,u=Le(f.lookup_path([...s,Se("status")])),d;switch(typeof u>"u"?d=De.Unknown:d=new TextDecoder().decode(u),d){case De.Replied:return{reply:Le(f.lookup_path([...s,"reply"])),certificate:f,rawCertificate:i.certificate};case De.Received:case De.Unknown:case De.Processing:{let l=n.strategy??Ca();return await l(o,r,d),Co(t,o,r,{...n,strategy:l,request:c})}case De.Rejected:throw zt.fromCode(wo(f,s,r));case De.Done:throw ge.fromCode(new Mn(r))}throw it}async function fl(t){let{paths:e,agent:r,pollingOptions:n}=t;if(n.request&&Na(n.request))return n.request;let o=await r.createReadStateRequest?.({paths:e},void 0);if(!Na(o))throw W.fromCode(new Kn(o));return o}var ti=60*1e3,Ua=1e6,ul=0,dl="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae";var ll="ic0.app",hl=".ic0.app",pl="icp0.io",ml=".icp0.io",bl="icp-api.io",yl=".icp-api.io",Js=200,Fa=202,xl=404;function gl(t){let e;if(t!==void 0)!t.match(/^[a-z]+:/)&&typeof window<"u"?e=new URL(`${window.location.protocol}//${t}`):e=new URL(t);else{let r=["ic0.app","icp0.io","127.0.0.1","localhost"],n=[".github.dev",".gitpod.io"],o=typeof window<"u"?window.location:void 0,s=o?.hostname,i;s&&typeof s=="string"&&(n.some(c=>s.endsWith(c))?i=s:i=r.find(c=>s.endsWith(c))),o&&i?e=new URL(`${o.protocol}//${i}${o.port?`:${o.port}`:""}`):e=new URL("https://icp-api.io")}return e.toString()}var No=class t{#e;#t;#r;#o;#i;#c;#f;#s;#n;#x;#g;#a;#d;#l;#u;#w;get#I(){return this.#u*ti}#m;#b;#E;#y;constructor(e={}){if(this.#e=null,this.#t=!1,this.#r=ul,this.#o=null,this.#i=!1,this.#c=null,this.#f=!1,this._isAgent=!0,this.config={},this.log=new vo,this.#m=[],this.#b=[],this.#E=new Map,this.#y=!0,this.#S=(o,s)=>{if(this.#y===!1)return o;let{status:i,signatures:c=[],requestId:a}=o,f=s.size;if(c.length>f)throw te.fromCode(new $n(c.length,f));for(let u of c){let{timestamp:d,identity:l}=u,h=L.fromUint8Array(l).toText(),m;if(i===on.Replied){let{reply:y}=o;m=sn({status:i,reply:y,timestamp:BigInt(d),request_id:a})}else if(i===on.Rejected){let{reject_code:y,reject_message:O,error_code:S}=o;m=sn({status:i,reject_code:y,reject_message:O,error_code:S,timestamp:BigInt(d),request_id:a})}else throw ge.fromCode(new Ne(`Unknown status: ${i}`));let b=Te(sa,m),p=s.get(h);if(!p)throw te.fromCode(new Hn);let x=Io.fromDer(p).rawKey;if(!Oa.verify(u.signature,b,x))throw Ce.fromCode(new Vn(h))}return o},this.config=e,e.fetch)this.#n=e.fetch;else{let o=globalThis.fetch;if(typeof o!="function")throw W.fromCode(new Dn);this.#n=o.bind(globalThis)}this.#x=e.fetchOptions,this.#g=e.callOptions,this.#t=e.shouldFetchRootKey??!1,this.#f=e.shouldSyncTime??!1,e.rootKey?this.rootKey=e.rootKey:this.#t?this.rootKey=null:this.rootKey=Ae(dl);let r=gl(e.host);this.host=new URL(r),this.host.pathname.endsWith("/")||(this.host.pathname+="/"),this.host.hostname.endsWith(hl)?this.host.hostname=ll:this.host.hostname.endsWith(ml)?this.host.hostname=pl:this.host.hostname.endsWith(yl)&&(this.host.hostname=bl),e.verifyQuerySignatures!==void 0&&(this.#y=e.verifyQuerySignatures),this.#w=e.subnetNodeKeyExpirableStore??_a({dbName:`icp-sdk-${this.host.host}`,storeName:"subnetNodeKeys",expirationTime:5*ti}),this.#d=e.retryTimes??3;let n=()=>new Ro({maxIterations:this.#d});if(this.#l=e.backoffStrategy||n,e.credentials){let{name:o,password:s}=e.credentials;this.#a=`${o}${s?`:${s}`:""}`}if(this.#s=Promise.resolve(e.identity||new sr),e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes>5)throw W.fromCode(new st("The maximum ingress expiry time is 5 minutes.",e.ingressExpiryInMinutes));if(e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes<=0)throw W.fromCode(new st("Ingress expiry time must be greater than 0.",e.ingressExpiryInMinutes));this.#u=e.ingressExpiryInMinutes||5,this.addTransform("update",Vs(an)),e.useQueryNonces&&this.addTransform("query",Vs(an)),e.logToConsole&&this.log.subscribe(o=>{o.level==="error"?console.error(o.message):o.level==="warn"?console.warn(o.message):console.log(o.message)})}static createSync(e={}){return new this({...e})}static async create(e={}){let r=t.createSync(e);return await r.#p(),r}static async from(e){try{return"config"in e?await t.create(e.config):await t.create({fetch:e._fetch,fetchOptions:e._fetchOptions,callOptions:e._callOptions,host:e._host.toString(),identity:e._identity??void 0})}catch{throw W.fromCode(new jn)}}isLocal(){let e=this.host.hostname;return e==="127.0.0.1"||e.endsWith("127.0.0.1")}addTransform(e,r,n=r.priority||0){if(e==="update"){let o=this.#b.findIndex(s=>(s.priority||0)<n);this.#b.splice(o>=0?o:this.#b.length,0,Object.assign(r,{priority:n}))}else if(e==="query"){let o=this.#m.findIndex(s=>(s.priority||0)<n);this.#m.splice(o>=0?o:this.#m.length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!this.#s)throw Me.fromCode(new St);return(await this.#s).getPrincipal()}async call(e,r,n){let o=r.callSync??!0,s=await(n??this.#s);if(!s)throw Me.fromCode(new St);let i=L.from(e),c=r.effectiveTarget?Ft(r.effectiveTarget):r.effectiveCanisterId?{canisterId:L.from(r.effectiveCanisterId)}:{canisterId:i};await this.#p(c);let a=s.getPrincipal(),f=ei(this.#u,this.#r),u={request_type:go.Call,canister_id:i,method_name:r.methodName,arg:r.arg,sender:a,ingress_expiry:f},d=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#a?{Authorization:`Basic ${btoa(this.#a)}`}:{}}},endpoint:xt.Call,body:u}),l;r?.nonce?l=h(r.nonce):d.body.nonce?l=h(d.body.nonce):l=void 0,u.nonce=l;function h(g){return Object.assign(g,{__nonce__:void 0})}d=await s.transformRequest(d);let m=xo(d.body.content??u),b=Yn(d.body),p=this.#l(),x=qa();try{let g,y;if("canisterId"in c){let R=()=>{let P=new URL(`api/v4/canister/${c.canisterId.toText()}/call`,this.host);return this.log.print(`fetching "${P.pathname}" with request:`,d),this.#n(P,{...this.#g,...d.request,body:b})},F=()=>{let P=new URL(`api/v2/canister/${c.canisterId.toText()}/call`,this.host);return this.log.print(`fetching "${P.pathname}" with request:`,d),this.#n(P,{...this.#g,...d.request,body:b})};g=o?R:F,y=o?F:void 0}else{if(!o)throw W.fromCode(new Zn);g=()=>{let R=new URL(`api/v4/subnet/${c.subnetId.toText()}/call`,this.host);return this.log.print(`fetching "${R.pathname}" with request:`,d),this.#n(R,{...this.#g,...d.request,body:b})}}let O;try{O=await this.#h({requestFn:g,backoff:p,tries:0})}catch(R){if(!y||!(R instanceof qe)||!R.hasCode(Vr))throw R;this.log.warn("v4 api not supported. Fall back to v2"),O=await this.#h({requestFn:y,backoff:this.#l(),tries:0})}let{responseBodyBytes:S,...M}=O,$=S.byteLength>0?ke(S):null;return{requestId:m,response:{...M,body:$},requestDetails:u}}catch(g){let y;if(g instanceof qe){if(g.hasCode(st)&&!this.#i&&(await this.syncTime(c),this.#N(d.body.content.ingress_expiry,x)))return this.call(i,r,n);g.code.requestContext={requestId:m,senderPubKey:d.body.sender_pubkey,senderSignature:d.body.sender_sig,ingressExpiry:d.body.content.ingress_expiry},y=g}else y=ge.fromCode(new Ne(g));throw this.log.error(`Error while making call: ${y.message}`,y),y}}async update(e,r,n={}){let o=L.from(e),s=r.effectiveTarget?Ft(r.effectiveTarget):r.effectiveCanisterId?{canisterId:L.from(r.effectiveCanisterId)}:{canisterId:o},{requestId:i,response:c,requestDetails:a}=await this.call(e,r),{body:f,...u}=c;if(pa(f))return this.#v(f,c,i,o,s,r.methodName,u,a,n,r.onPollingStarted);if(ha(f)&&this.#R(f,i,o,s,r.methodName,u),c.status===Fa)return r.onPollingStarted?.(),{...await Co(this,s,i,n),requestDetails:a,callResponse:c};let d=new Ne(`Unexpected response from call: status ${c.status} with unrecognized body`);throw d.callContext={canisterId:o,effectiveTarget:s,methodName:r.methodName,httpDetails:u},ge.fromCode(d)}async#v(e,r,n,o,s,i,c,a,f,u){if(this.rootKey==null)throw Me.fromCode(new We);let d=e.certificate,l=await rn.create({certificate:d,rootKey:this.rootKey,principal:s,blsVerify:f.blsVerify,agent:this}),h=[Se("request_status"),n],m=Le(l.lookup_path([...h,Se("status")])),b=m?new TextDecoder().decode(m):void 0;switch(b){case De.Replied:return{reply:Le(l.lookup_path([...h,"reply"])),certificate:l,rawCertificate:d,requestDetails:a,callResponse:r};case De.Rejected:{let p=wo(l,h,n);throw p.callContext={canisterId:o,effectiveTarget:s,methodName:i,httpDetails:c},zt.fromCode(p)}case void 0:return this.log.warn(`v4 sync response certificate does not contain request ID ${ne(n)} status. Falling back to polling.`),u?.(),{...await Co(this,s,n,f),requestDetails:a,callResponse:r};default:{let p=new zn(b,n,r,d);throw p.callContext={canisterId:o,effectiveTarget:s,methodName:i,httpDetails:c},ge.fromCode(p)}}}#R(e,r,n,o,s,i){let{reject_code:c,reject_message:a,error_code:f}=e,u=new qn(r,c,a,f);throw u.callContext={canisterId:n,methodName:s,httpDetails:i,effectiveTarget:o},zt.fromCode(u)}async#B(e){let{target:r,transformedRequest:n,body:o,requestId:s,backoff:i,tries:c}=e,a=c===0?0:i.next(),f="canisterId"in r?new URL(`api/v3/canister/${r.canisterId.toString()}/query`,this.host):new URL(`api/v3/subnet/${r.subnetId.toString()}/query`,this.host);if(this.log.print(`fetching "${f.pathname}" with tries:`,{tries:c,backoff:i,delay:a}),a===null)throw ge.fromCode(new Zt(`Backoff strategy exhausted after ${c} attempts.`,s));a>0&&await new Promise(x=>setTimeout(x,a));let u;try{this.log.print(`fetching "${f.pathname}" with request:`,n),u=await this.#n(f,{...this.#x,...n.request,body:o})}catch(x){if(c<this.#d)return this.log.warn(`Caught exception while attempting to make query:
  ${x}
  Retrying query.`),await this.#B({...e,tries:c+1});throw $r.fromCode(new zr(x))}let d=zs(u.headers);if(u.status!==Js){let x=await u.text();if(Ma(x))throw W.fromCode(new st(x,this.#u));if(c<this.#d)return await this.#B({...e,tries:c+1});throw te.fromCode(new Hr(u.status,u.statusText,d,x))}let h={...ke(Er(await u.arrayBuffer())),httpDetails:{ok:u.ok,status:u.status,statusText:u.statusText,headers:d},requestId:s};if(!this.#y)return h;let m=h.signatures?.[0]?.timestamp;if(!m)throw te.fromCode(new Pn("Timestamp not found in query response. This suggests a malformed or malicious response."));let b=Number(BigInt(m)/BigInt(Ua));if(Date.now()+this.#r-b>this.#I){if(c<this.#d)return this.log.warn("Timestamp is older than the max ingress expiry. Retrying query.",{requestId:s,signatureTimestampMs:b}),await this.syncTime(r),await this.#B({...e,tries:c+1});throw Ce.fromCode(new Un(this.#u,s,c))}return h}async#h(e){let{requestFn:r,backoff:n,tries:o}=e,s=o===0?0:n.next();if(s===null)throw te.fromCode(new Zt(`Retry strategy exhausted after ${o} attempts.`));s>0&&await new Promise(u=>setTimeout(u,s));let i,c=new Uint8Array;try{i=await r(),i.status===Js&&(c=Er(await i.clone().arrayBuffer()))}catch(u){if(o<this.#d)return this.log.warn(`Caught exception while attempting to make request:
  ${u}
  Retrying request.`),await this.#h({requestFn:r,backoff:n,tries:o+1});throw $r.fromCode(new zr(u))}let a=zs(i.headers);if(i.status===Js||i.status===Fa)return{ok:i.ok,status:i.status,statusText:i.statusText,responseBodyBytes:c,headers:a};let f=await i.text();if(i.status===xl&&i.url.includes("api/v4/canister"))throw te.fromCode(new Vr);if(Ma(f))throw W.fromCode(new st(f,this.#u));if(o<this.#d)return await this.#h({requestFn:r,backoff:n,tries:o+1});throw te.fromCode(new Hr(i.status,i.statusText,a,f))}async query(e,r,n){let o=this.#l(),s=L.from(e),i=r.effectiveTarget?Ft(r.effectiveTarget):r.effectiveCanisterId?{canisterId:L.from(r.effectiveCanisterId)}:{canisterId:s},c=Ao(i);await this.#p(i),"canisterId"in i?this.log.print(`ecid ${i.canisterId.toString()}`):this.log.print(`esid ${i.subnetId.toString()}`),this.log.print(`canisterId ${e.toString()}`);let a,f=await(n??this.#s);if(!f)throw Me.fromCode(new St);let u=f.getPrincipal(),d=ei(this.#u,this.#r),l={request_type:ir.Query,canister_id:s,method_name:r.methodName,arg:r.arg,sender:u,ingress_expiry:d};a=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#a?{Authorization:`Basic ${btoa(this.#a)}`}:{}}},endpoint:xt.Query,body:l}),a=await f.transformRequest(a);let h=xo(a.body.content??l),m=Yn(a.body),b={canister:s.toText(),target:i,transformedRequest:a,body:m,requestId:h,backoff:o,tries:0},p=async()=>{let x=await this.#B(b);return{requestDetails:l,...x}};try{if(!this.#y)return await p();let[x,g]=await Promise.all([p(),this.fetchSubnetKeys(i)]);try{return this.#S(x,g)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),await this.#w.delete(c);let y=await this.fetchSubnetKeys(i);return this.#S(x,y)}}catch(x){let g;if(x instanceof qe){if(x.hasCode(st)&&!this.#i)return await this.syncTime(i),this.query(e,r,n);x.code.requestContext={requestId:h,senderPubKey:a.body.sender_pubkey,senderSignature:a.body.sender_sig,ingressExpiry:a.body.content.ingress_expiry},g=x}else g=ge.fromCode(new Ne(x));throw this.log.error(`Error while making query: ${g.message}`,g),g}}#S;async createReadStateRequest(e,r){await this.#p();let n=await(r??this.#s);if(!n)throw Me.fromCode(new St);let o=n.getPrincipal(),s=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#a?{Authorization:`Basic ${btoa(this.#a)}`}:{}}},endpoint:xt.ReadState,body:{request_type:ir.ReadState,paths:e.paths,sender:o,ingress_expiry:ei(this.#u,this.#r)}});return n.transformRequest(s)}#A(e){for(let r of e.paths){let[n,o]=r,s=new TextEncoder().encode("request_status");if(or(n,s))return o}}async readState(e,r,n,o){(typeof e=="string"||e instanceof L)&&(e={canisterId:L.from(e)}),await this.#T();let s=Ft(e);r.disableTimeVerification||await this.#_(s);let i=[],c=[];for(let p of r.paths){let x=da(p);i.push(x),Array.isArray(p)||c.push({path:p,encoded:x})}let a={...r,paths:i},f,u;if(o)f=o;else{u=this.#A(a);let p=await this.#s;if(!p)throw Me.fromCode(new St);f=await this.createReadStateRequest(a,p)}let d="canisterId"in s?new URL(`api/v3/canister/${s.canisterId.toString()}/read_state`,this.host):new URL(`api/v3/subnet/${s.subnetId.toString()}/read_state`,this.host);if(this.rootKey===null)throw Me.fromCode(new We(this.#t));let l=this.rootKey,{certificate:h}=await this.#O(d,s,f,u),m=await rn.create({certificate:h,rootKey:l,principal:s,blsVerify:r.blsVerify,maxAgeInMinutes:r.maxAgeInMinutes,disableTimeVerification:r.disableTimeVerification,agent:this}),b=new Map;for(let{path:p,encoded:x}of c){let g=Le(m.lookup_path(x));b.set(p.key,g===void 0?null:p.decode(g))}return{certificate:h,verifiedCertificate:m,values:new bo(b)}}readSubnetState(e,r){return this.readState({subnetId:L.from(e)},r)}async#O(e,r,n,o){let s=this.#l();try{let{responseBodyBytes:i}=await this.#h({requestFn:()=>this.#n(e,{...this.#x,...n.request,body:Yn(n.body)}),backoff:s,tries:0});return ke(i)}catch(i){let c;if(i instanceof qe){if(i.hasCode(st)&&!this.#i)return await this.syncTime(r),await this.#O(e,r,n,o);i.code.requestContext={requestId:o??xo(n),senderPubKey:n.body.sender_pubkey,senderSignature:n.body.sender_sig,ingressExpiry:n.body.content.ingress_expiry},c=i}else c=ge.fromCode(new Ne(i));throw this.log.error(`Error while making read state: ${c.message}`,c),c}}parseTimeFromResponse(e){let r;if(e.certificate){let n=ke(e.certificate);if(n&&"tree"in n)r=n.tree;else throw te.fromCode(new Tt("Could not decode time from response"));let o=Ut(["time"],r);if(o.status!==Ie.Found)throw te.fromCode(new Ge("Time was not found in the response or was not in its expected format.",o.status));if(!(o.value instanceof Uint8Array)&&!ArrayBuffer.isView(o))throw te.fromCode(new vn("Time was not in its expected format."));let s=mr(o.value);return this.log.print("Time from response:",s),this.log.print("Time from response in milliseconds:",s.getTime()),s.getTime()}return this.log.warn("No certificate found in response"),0}async syncTime(e){e&&(typeof e=="string"||e instanceof L)&&(e={canisterId:L.from(e)}),this.#c=this.#c??(async()=>{await this.#T();let r=Date.now();try{e||this.log.print("Syncing time with the IC. No target provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let n=e??{canisterId:L.from("ryjl3-tyaaa-aaaaa-aaaba-cai")},o=t.createSync({identity:new sr,host:this.host.toString(),fetch:this.#n,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),s=await Promise.all(Array(3).fill(null).map(async()=>{let c=("canisterId"in n?await ba({canisterId:n.canisterId,agent:o,paths:["time"],disableCertificateTimeVerification:!0}):await ya({subnetId:n.subnetId,agent:o,paths:["time"],disableCertificateTimeVerification:!0})).get("time");if(c instanceof Date)return c.getTime()},[]));this.#C(r,qa(),s)}catch(n){let o=n instanceof qe?n:ge.fromCode(new Ne(n));throw this.log.error("Caught exception while attempting to sync time",o),o}})(),await this.#c.finally(()=>{this.#c=null})}syncTimeWithSubnet(e){return this.syncTime({subnetId:e})}#C(e,r,n){let o=n.reduce((s,i)=>typeof i=="number"&&i>s?i:s,0);o>0&&(this.#r=o-e,this.#o={replicaTimeMs:o,receivedAt:r},this.#i=!0,this.log.notify({message:`Syncing time: offset of ${this.#r}`,level:"info"}))}#N(e,r){if(this.#o===null)return!1;let{replicaTimeMs:n,receivedAt:o}=this.#o,s=Math.max(o.wallMs-r.wallMs,o.monotonicMs-r.monotonicMs),i=BigInt(Math.floor(n-s))*BigInt(Ua);return e.toBigInt()<i}async status(){let e=this.#a?{Authorization:`Basic ${btoa(this.#a)}`}:{},r=new URL("api/v2/status",this.host);this.log.print(`fetching "${r.pathname}"`);let n=this.#l(),{responseBodyBytes:o}=await this.#h({backoff:n,requestFn:()=>this.#n(r,{headers:e,...this.#x}),tries:0});return ke(o)}async fetchRootKey(){return this.#e=this.#e??(async()=>{let e=await this.status();return this.rootKey=e.root_key,this.rootKey})(),await this.#e.finally(()=>{this.#e=null})}async#p(e){await Promise.all([this.#T(),this.#_(e)])}async#T(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#t)await this.fetchRootKey();else throw Me.fromCode(new We(this.#t))}async#_(e){this.#f&&!this.hasSyncedTime()&&await this.syncTime(e)}invalidateIdentity(){this.#s=null}replaceIdentity(e){this.#s=Promise.resolve(e)}async fetchSubnetKeys(e){(typeof e=="string"||e instanceof L)&&(e={canisterId:L.from(e)});let r=Ft(e),n=Ao(r),o=await this.#w.get(n);if(o)return o;let s=this.#E.get(n);if(s)return s;let i=this.#k(r).finally(()=>{this.#E.delete(n)});return this.#E.set(n,i),i}async#k(e){await this.#p(e);let r=this.rootKey,{verifiedCertificate:n}=await this.readState(e,{paths:[[Se("subnet")]]}),o=Ao(e);if("canisterId"in e&&!n.cert.delegation){let c=L.selfAuthenticating(r);if(!js({canisterId:e.canisterId,subnetId:c,tree:n.cert.tree}))throw Ce.fromCode(new Kt(e.canisterId,c))}let s=Ps(n.cert,r),i=Br(n.cert,s);return await this.#w.set(o,i),i}async getSubnetIdFromCanister(e){let r=L.from(e);await this.#p({canisterId:r});let{verifiedCertificate:n}=await this.readState({canisterId:r},{paths:[[Se("time")]]});return Ps(n.cert,this.rootKey)}_transform(e){let r=Promise.resolve(e);if(e.endpoint===xt.Call)for(let n of this.#b)r=r.then(o=>n(o).then(s=>s||o));else for(let n of this.#m)r=r.then(o=>n(o).then(s=>s||o));return r}getTimeDiffMsecs(){return this.#r}hasSyncedTime(){return this.#i}};function ei(t,e){let r=t*ti;return Yt.fromDeltaInMilliseconds(r,e)}function qa(){let t=Date.now(),e=typeof performance<"u"&&typeof performance.now=="function"?performance.now():t;return{wallMs:t,monotonicMs:e}}function Ma(t){return t.includes("Invalid request expiry: ")}var Tr=class extends Error{constructor(r,n,o=`wire ${r}`){super(o);this.code=r;this.reason=n}name="WireError"},Sr=11,T=t=>{throw new Tr(t)},$a=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),wl=new TextEncoder,ri=new Uint8Array(new Uint16Array([1]).buffer)[0]===1,Pa={i8:Int8Array,i16:Int16Array,u16:Uint16Array,i32:Int32Array,u32:Uint32Array,i64:BigInt64Array,u64:BigUint64Array,hash16:Uint8Array,hash32:Uint8Array,"finite-f32":Float32Array,"finite-f64":Float64Array},El=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get;function ni(t,e){return El.call(t)===e.name}function Ha(t,e,r){let n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let o=0;o<t.length;o+=e)if(!Number.isFinite(e===4?n.getFloat32(o,r):n.getFloat64(o,r)))return!1;return!0}function Va(t,e){for(let r=0;r<t.length;r+=e)for(let n=0;n<e/2;n++){let o=r+e-1-n,s=t[r+n];t[r+n]=t[o],t[o]=s}}function qt(t,e){return!t||typeof t!="object"||Array.isArray(t)||Reflect.ownKeys(t).length!==e.length||e.some(r=>!Object.hasOwn(t,typeof r=="string"?r:r.name))?T("value"):t}var ko=class{constructor(e,r){this.remaining=e;this.depth=r}incompatible=0;visit(e){(--this.remaining<0||e>this.depth)&&T("limit")}length(e){e>this.remaining&&T("limit")}};function oi(t,e,r){let n,o=0,s=1;for(;t.k==="ref";){if(t.name===n||!Object.hasOwn(e,t.name))return T("value");o++===s&&(n=t.name,s*=2,o=1),r?.(t);let i=e[t.name];if(i===void 0)return T("value");t=i}return r?.(t),t}function La(t,e){let r=new Set;for(;;){if(!t||typeof t!="object"||r.has(t))return T("value");if(t.k==="extension-record"||t.k==="extension-tuple")return 1;if(r.add(t),t.k==="newtype"&&!t.fixed)t=t.item;else if(t.k==="ref"){if(!Object.hasOwn(e,t.name))return T("value");let n=e[t.name];if(n===void 0)return T("value");t=n}else return T("value")}}function za(t,e,r){if(t.check!==void 0){if(!Object.hasOwn(r,t.check))return T("value");let n=r[t.check];if(n===void 0)return T("value");n(e)}}var si=class{constructor(e,r=0){this.limit=e;this.offset=r;this.bytes=new Uint8Array(Math.min(e,64))}bytes;grow(e){e>this.limit&&T("limit");let r=new Uint8Array(Math.min(this.limit,Math.max(e,this.bytes.length*2)));r.set(this.bytes),this.bytes=r}header(e,r){this.bytes.set([73,87]),new DataView(this.bytes.buffer).setBigUint64(2,e,!0),this.bytes[10]=r}byte(e){this.offset===this.bytes.length&&this.grow(this.offset+1),this.bytes[this.offset++]=e}varint(e){do{let r=Number(e&127n);e>>=7n,this.byte(e?r|128:r)}while(e)}raw(e){e.length>this.bytes.length-this.offset&&this.grow(this.offset+e.length),this.bytes.set(e,this.offset),this.offset+=e.length}prefix(e,r,n){let o=c=>!Number.isInteger(c)||c<0||c>4294967295?T("limit"):Math.max(1,Math.ceil((32-Math.clz32(c))/7)),s=o(r)+(n===void 0?0:o(n)),i=this.offset+s;Number.isSafeInteger(i)||T("limit"),i>this.bytes.length&&this.grow(i),this.bytes.copyWithin(e+s,e,this.offset),this.offset=e,this.varint(BigInt(r)),n!==void 0&&this.varint(BigInt(n)),this.offset=i}finish(){return this.offset===this.bytes.length?this.bytes:this.bytes.slice(0,this.offset)}},fn=class{constructor(e,r=0){this.bytes=e;this.offset=r;this.view=new DataView(e.buffer,e.byteOffset,e.byteLength)}view;byte(){let e=this.bytes[this.offset++];return e===void 0?T("malformed"):e}varint(e){let r=0n;for(let n=0;n<Math.ceil(e/7);n++){let o=this.byte();if(r|=BigInt(o&127)<<BigInt(n*7),!(o&128))return r>=1n<<BigInt(e)?T("malformed"):r}return T("malformed")}length(e){let r=Number(this.varint(32));return r>e?T("limit"):r}raw(e){if(e>this.bytes.length-this.offset)return T("malformed");let r=this.bytes.subarray(this.offset,this.offset+e);return this.offset+=e,r}skip(e){e>this.bytes.length-this.offset&&T("malformed"),this.offset+=e}};function Da(t,e,r,n,o,s){let i=r.offset;for(let c of t){n.visit(o+1);let a=e(c);if(!c.required&&a===null)continue;let f=r.offset;s(c.value,c.required?a:qt(a,["some"]).some),r.prefix(f,c.id,r.offset-f)}r.prefix(i,r.offset-i)}function Ka(t,e,r,n,o,s,i){n.visit(o);let c=oi(t,s,f=>za(f,e,i)),a=(f,u)=>Ka(f,u,r,n,o+1,s,i);switch(c.k){case"unit":e!==null&&T("value");return;case"bool":typeof e!="boolean"&&T("value"),r.byte(e?1:0);return;case"float":{if(typeof e!="number"||!Number.isFinite(e)||c.bits===32&&!Object.is(Math.fround(e),e)||c.min!==void 0&&e<c.min||c.max!==void 0&&e>c.max)return T("value");let f=new Uint8Array(c.bits/8),u=new DataView(f.buffer);c.bits===32?u.setFloat32(0,e,!0):u.setFloat64(0,e,!0),r.raw(f);return}case"u":case"i":{(c.bits<=32?typeof e!="number"||!Number.isSafeInteger(e):typeof e!="bigint")&&T("value");let f=BigInt(e),u=BigInt(c.bits),d=c.k==="i",l=d?-(1n<<u-1n):0n,h=(1n<<u-(d?1n:0n))-1n;if((f<l||f>h)&&T("limit"),c.min!==void 0&&f<BigInt(c.min)||c.max!==void 0&&f>BigInt(c.max))return T("value");c.bits===8?r.byte(Number(f&255n)):r.varint(d?f<<1n^f>>u-1n:f);return}case"bytes":{if(!ni(e,Uint8Array))return T("value");c.min!==void 0&&e.length<c.min&&T("value"),c.max!==void 0&&e.length>c.max&&T("limit"),r.varint(BigInt(e.length)),r.raw(e);return}case"packed":{if(c.word==="bool"){if(!Array.isArray(e))return T("value");if(c.max!==void 0&&e.length>c.max||(r.varint(BigInt(e.length)),e.length>r.limit-r.offset))return T("limit");for(let m of e){if(typeof m!="boolean")return T("value");r.byte(m?1:0)}return}let f=c.word,u=Pa[f];if(!ni(e,u))return T("value");let d=f==="hash16"||f==="hash32",l=f==="hash16"?16:f==="hash32"?32:u.BYTES_PER_ELEMENT;if(e.byteLength%l||(c.max!==void 0&&e.byteLength/l>c.max&&T("limit"),r.varint(BigInt(e.byteLength)),e.byteLength>r.limit-r.offset&&T("limit"),c.nonzero&&e.includes(0n)))return T("value");let h=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if((f==="finite-f32"||f==="finite-f64")&&!Ha(h,l,ri))return T("value");if(ri||d)r.raw(h);else{let m=new Uint8Array(h);Va(m,l),r.raw(m)}return}case"text":{if(typeof e!="string")return T("value");let f=Math.min(c.max??r.limit,r.limit-r.offset);e.length>f&&T("limit");let u=new Uint8Array(Math.min(f,e.length*3)),d=wl.encodeInto(e,u);d.read!==e.length&&T("limit");let l=u.subarray(0,d.written);$a.decode(l)!==e&&T("value"),r.varint(BigInt(l.length)),r.raw(l);return}case"newtype":a(c.item,e);return;case"list":case"array":case"tuple":{if(!Array.isArray(e))return T("value");(c.k==="array"&&e.length!==c.max||c.k==="list"&&e.length>(c.max??n.remaining))&&T("limit"),c.k==="tuple"&&e.length!==c.items.length&&T("value"),n.length(e.length),c.k==="list"&&r.varint(BigInt(e.length));for(let f=0;f<e.length;f++){Object.hasOwn(e,f)||T("value");let u=c.k==="tuple"?c.items[f]:c.item;if(u===void 0)return T("value");a(u,e[f])}return}case"option":{if(e===null){r.byte(0);return}let f=qt(e,["some"]);r.byte(1),a(c.item,f.some);return}case"recover":{if(e===null){r.byte(0);return}let f=qt(e,["some"]);r.byte(1);let u=r.offset;a(c.item,f.some),r.prefix(u,r.offset-u);return}case"result":{let f=e&&typeof e=="object"&&Object.hasOwn(e,"ok")?"ok":"err",u=qt(e,[f]);r.byte(f==="ok"?0:1),a(c[f],u[f]);return}case"record":{let f=qt(e,c.fields);for(let u of c.fields)a(u.value,f[u.name]);return}case"extension-record":{n.length(c.fields.length+c.extensions.length);let f=qt(e,[...c.fields,...c.extensions]);for(let u of c.fields)a(u.value,f[u.name]);Da(c.extensions,u=>f[u.name],r,n,o,a);return}case"extension-tuple":{if(!Array.isArray(e)||e.length!==c.items.length+c.extensions.length)return T("value");n.length(e.length);let f=0;for(let u of c.items)Object.hasOwn(e,f)||T("value"),a(u,e[f++]);Da(c.extensions,u=>{let d=u.id-1;return Object.hasOwn(e,d)?e[d]:T("value")},r,n,o,a);return}case"enum":{let f=qt(e,["tag","value"]),u=c.variants.find(d=>d.name===f.tag);if(!u)return T("value");r.varint(BigInt(u.id)),a(u.value,f.value);return}case"open-variant":{if(e===null&&!c.required){r.byte(0);return}let f=qt(e,["tag","value"]),u=c.variants.find(h=>h.name===f.tag);if(!u)return T("value");let d=r.offset;a(u.value,f.value);let l=r.offset-d;r.prefix(d,u.id*2+ +(l!==0),l||void 0);return}default:return T("value")}}function ci(t,e,r,n,o,s){let i=r.incompatible,c=Bl(oi(t,o),e,r,n,o,s);return r.incompatible===i&&oi(t,o,a=>za(a,c,s)),c}function ii(t,e,r,n,o,s){let i=new fn(e),c=ci(t,i,r,n,o,s);return i.offset!==e.length&&T("malformed"),c}function ja(t,e,r,n,o,s,i){let c=new fn(e.raw(Number(e.varint(32)))),a=0,f=0,u=!1;function d(l){r.visit(n+1),l.required?u=!0:i(l,null)}for(;c.offset<c.bytes.length;){r.visit(n+1);let l=Number(c.varint(32));l<=a&&T("malformed"),a=l;let h=Number(c.varint(32)),m=t[f];for(;m&&m.id<l;)d(m),m=t[++f];if(m?.id===l){let b=ii(m.value,c.raw(h),r,n+1,o,s);i(m,m.required?b:{some:b}),f++}else c.skip(h)}for(;f<t.length;f++)d(t[f]);u&&r.incompatible++}function Bl(t,e,r,n,o,s){let i=t;r.visit(n);let c=a=>ci(a,e,r,n+1,o,s);switch(i.k){case"unit":return null;case"bool":{let a=e.byte();return a>1?T("malformed"):a===1}case"float":{let a=e.raw(i.bits/8),f=new DataView(a.buffer,a.byteOffset,a.byteLength),u=i.bits===32?f.getFloat32(0,!0):f.getFloat64(0,!0);return!Number.isFinite(u)||i.min!==void 0&&u<i.min||i.max!==void 0&&u>i.max?T("malformed"):u}case"u":case"i":{let a=i.bits===8?BigInt(e.byte()):e.varint(i.bits);return i.k==="i"&&(a=i.bits===8?a>=128n?a-256n:a:a>>1n^-(a&1n)),i.min!==void 0&&a<BigInt(i.min)||i.max!==void 0&&a>BigInt(i.max)?T("malformed"):i.bits<=32?Number(a):a}case"bytes":{let a=e.length(i.max??e.bytes.length-e.offset);return i.min!==void 0&&a<i.min&&T("malformed"),new Uint8Array(e.raw(a))}case"packed":{if(i.word==="bool"){let p=e.raw(e.length(Math.min(i.max??e.bytes.length,e.bytes.length-e.offset)));for(let g of p)if(g>1)return T("malformed");let x=new Array(p.length);for(let g=0;g<p.length;g++)x[g]=p[g]===1;return x}let a=i.word,f=Pa[a],u=a==="hash16"||a==="hash32",d=a==="hash16"?16:a==="hash32"?32:f.BYTES_PER_ELEMENT,l=e.length(Math.min(i.max===void 0?e.bytes.length:i.max*d,e.bytes.length-e.offset));if(l%d)return T("malformed");if(l===0)return new f(0);let h=e.raw(l);if((a==="finite-f32"||a==="finite-f64")&&!Ha(h,d,!0))return T("malformed");let m=new Uint8Array(h);!ri&&!u&&Va(m,d);let b=new f(m.buffer);return i.nonzero&&b.includes(0n)?T("malformed"):b}case"text":return $a.decode(e.raw(e.length(Math.min(i.max??e.bytes.length,e.bytes.length-e.offset))));case"newtype":return c(i.item);case"list":case"array":case"tuple":{let a=i.k==="list"?e.length(Math.min(i.max??r.remaining,r.remaining)):i.k==="array"?i.max:i.items.length;r.length(a);let f=[];for(let u=0;u<a;u++){let d=i.k==="tuple"?i.items[u]:i.item;if(d===void 0)return T("value");f.push(c(d))}return f}case"option":{let a=e.byte();return a===0?null:a!==1?T("malformed"):{some:c(i.item)}}case"recover":{let a=e.byte();if(a===0)return null;if(a!==1)return T("malformed");let f=r.incompatible,u=e.raw(Number(e.varint(32))),d=ii(i.item,u,r,n+1,o,s);return r.incompatible===f?{some:d}:(r.incompatible=f,null)}case"result":{let a=e.varint(32);return a>1n?T("malformed"):a===0n?{ok:c(i.ok)}:{err:c(i.err)}}case"record":{let a=Object.create(null);for(let f of i.fields)a[f.name]=c(f.value);return a}case"extension-record":{let a=Object.create(null);for(let f of i.fields)a[f.name]=c(f.value);return ja(i.extensions,e,r,n,o,s,(f,u)=>{a[f.name]=u}),a}case"extension-tuple":{r.length(i.items.length);let a=[];for(let f of i.items)a.push(c(f));return ja(i.extensions,e,r,n,o,s,(f,u)=>{a[f.id-1]=u}),a}case"enum":{let a=Number(e.varint(32)),f=i.variants.find(u=>u.id===a);return f?{tag:f.name,value:c(f.value)}:T("malformed")}case"open-variant":{let a=Number(e.varint(32));if(a===0)return i.required?T("malformed"):null;if(a===1)return T("malformed");let f=a%2===1,u=f?Number(e.varint(32)):0;if(f&&u===0)return T("malformed");let d=Math.floor(a/2),l=i.variants.find(h=>h.id===d);return l?{tag:l.name,value:ii(l.value,e.raw(u),r,n+1,o,s)}:(r.visit(n+1),e.skip(u),i.required&&r.incompatible++,null)}default:return T("value")}}function Sl(t,e,r,n,o,s,i){try{let c=new fn(t,i===void 0?0:Sr);if(i!==void 0&&c.view.getBigUint64(2,!0)!==i)return T("identity");let a=new ko(o,s),f=ci(e,c,a,1,r,n);if(c.offset!==t.length){let u=t.length-c.offset;throw new Tr("malformed","trailing_bytes",`${u} trailing byte${u===1?"":"s"} after the decoded value.`)}return a.incompatible!==0?T("incompatible"):f}catch(c){if(c instanceof Tr)throw c;return T("malformed")}}function Za(t,e={},r={}){let n=t,{request:o,response:s}=n,i=e,c=BigInt(n.id);(c<0n||c>=1n<<64n)&&T("value");for(let u of[n.requestBytes,n.responseBytes,n.requestNodes,n.responseNodes,n.requestDepth,n.responseDepth])(!Number.isSafeInteger(u)||u<1)&&T("value");(n.requestBytes<Sr+La(o,i)||n.responseBytes<Sr+La(s,i))&&T("value");function a(u,d){let l=new si(d?n.responseBytes:n.requestBytes,Sr);return l.header(c,d),Ka(d?s:o,u,l,new ko(d?n.responseNodes:n.requestNodes,d?n.responseDepth:n.requestDepth),1,i,r),l.finish()}function f(u,d){if(!ni(u,Uint8Array))return T("value");if(u.length>(d?n.responseBytes:n.requestBytes))return T("limit");if(u.length<Sr){let l=d===0?"Request":"Response";throw new Tr("malformed","short_header",`${l} frame is too short (expected at least ${Sr} bytes, received ${u.length}).`)}return u[0]!==73||u[1]!==87||u[10]!==d?T("identity"):Sl(u,d?s:o,i,r,d?n.responseNodes:n.requestNodes,d?n.responseDepth:n.requestDepth,c)}return{encodeRequest:u=>a(u,0),decodeRequest:u=>f(u,0),encodeResponse:u=>a(u,1),decodeResponse:u=>f(u,1)}}function Fo(t){return[...t.fields??[],...(t.extensions??[]).map(e=>({name:e.name,value:e.required?e.value:{k:"option",item:e.value}}))]}function gt(t){let e=[...t.items??[]];for(let r of t.extensions??[])e[r.id-1]=r.required?r.value:{k:"option",item:r.value};return e}var Ga="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function Uo(t){if(t.length!==26)throw Error(`ULID needs 26 characters: ${t}`);let e=0n;for(let r of t.toUpperCase()){let n=Ga.indexOf(r);if(n<0)throw Error(`bad ULID character "${r}"`);e=e*32n+BigInt(n)}if(e>=1n<<128n)throw Error("ULID exceeds 128 bits");return Array.from({length:16},(r,n)=>Number(e>>BigInt(8*(15-n))&0xffn))}function Tl(){let t=crypto.getRandomValues(new Uint8Array(16)),e=Date.now();for(let r=5;r>=0;r--,e=Math.floor(e/256))t[r]=e%256;return qo(t)}function qo(t){let e=Array.from(t).reduce((n,o)=>n<<8n|BigInt(o),0n),r="";for(let n=0;n<26;n++,e>>=5n)r=Ga[Number(e&31n)]+r;return r}var di=t=>Array.from(t,e=>e.toString(16).padStart(2,"0")).join("");function ai(t){if(!/^([0-9a-f]{2})*$/i.test(t))throw Error("hex needs pairs of 0-9/a-f");return Uint8Array.from(t.match(/../g)??[],e=>parseInt(e,16))}function li(t,e){if(typeof e=="string"&&/^-?\d+n$/.test(e))return BigInt(e.slice(0,-1));if(e&&typeof e=="object"&&!Array.isArray(e)){let r=e;if("$principal"in r)return L.fromText(r.$principal).toUint8Array();if("$hex"in r)return ai(r.$hex);if("$ulid"in r)return Uo(r.$ulid);if("$ulidBytes"in r)return Uint8Array.from(Uo(r.$ulidBytes))}return e}var Xa=t=>t.replace(/^Wire_/,"").replace(/_[0-9a-f]{16}$/,""),un=t=>t.k==="ref"&&t.name.startsWith("Wire_Ulid_"),Mo=t=>t.k==="ref"&&/^Wire_(NonAnonymous)?Principal_/.test(t.name),Fe=(t,e)=>t.k==="ref"&&!un(t)&&!Mo(t)?Fe(e[t.name],e):t.k==="newtype"?Fe(t.item,e):t;function dn(t,e,r=0){if(un(t))return"Ulid";if(Mo(t))return"principal";if(r>6)return"\u2026";let n=o=>dn(o,e,r+1);switch(t.k){case"ref":{let o=Fe(t,e);return o.k==="record"||o.k==="enum"?Xa(t.name):n(o)}case"newtype":return n(t.item);case"unit":return"()";case"u":case"i":return`${t.k}${t.bits}`;case"float":return`f${t.bits}`;case"option":return`Option<${n(t.item)}>`;case"list":case"packed":return`Vec<${t.item?n(t.item):t.word}>`;case"array":return`[${n(t.item)}; ${t.max}]`;case"extension-tuple":case"tuple":return`(${gt(t).map(n).join(", ")})`;case"result":return`Result<${n(t.ok)}, ${n(t.err)}>`;case"extension-record":return"record";default:return t.k}}var fi=(t,e)=>{let r=Fe(t,e);return r.k==="array"&&Fe(r.item,e).k==="u"&&Fe(r.item,e).bits===8};function Wa(t,e,r=0){if(un(t))return"ULID";if(Mo(t))return t.name.includes("NonAnonymous")?"principal (not anonymous)":"principal";if(fi(t,e))return Fe(t,e).max===16?"ULID, or exactly 16 bytes as hex":`exactly ${Fe(t,e).max} bytes as hex`;if(r>6)return"\u2026";let n=o=>Wa(o,e,r+1);switch(t.k){case"ref":{let o=Fe(t,e);return o.k==="record"||o.k==="enum"?Xa(t.name):n(o)}case"newtype":return n(t.item);case"unit":return"nothing";case"bool":return"yes/no";case"u":case"i":return`${t.k==="u"?"whole number \u2265 0":"whole number"} (${t.bits}-bit)`;case"float":return"decimal number";case"text":return t.max?`text, max ${t.max} bytes`:"text";case"bytes":return t.max?`bytes as hex, max ${t.max}`:"bytes as hex";case"option":return`optional ${n(t.item)}`;case"list":case"packed":return`list of ${t.item?n(t.item):t.word}`;case"array":return`${t.max} \xD7 ${n(t.item)}`;case"extension-tuple":case"tuple":return`(${gt(t).map(n).join(", ")})`;case"result":return`Result<${n(t.ok)}, ${n(t.err)}>`;case"extension-record":case"record":return"record";case"enum":return`one of ${t.variants.map(o=>o.name).join(" | ")}`;default:return t.k}}function fe(t,e={},...r){let n=Object.assign(document.createElement(t),e);return n.append(...r.map(o=>typeof o=="string"||o instanceof HTMLElement?o:o.el)),n}function Ya(t,e,r,n){let o=Fe(t,e),s=(()=>{if(un(o))return a=>Uo(a.trim());if(Mo(o))return a=>L.fromText(a.trim()).toUint8Array();if(fi(o,e))return a=>{if(o.max===16&&a.trim().length===26)return Uo(a.trim());let f=Array.from(ai(a.trim()));if(f.length!==o.max)throw Error(`needs exactly ${o.max} bytes (${o.max*2} hex characters)`);return f};switch(o.k){case"text":return a=>a;case"bytes":return a=>ai(a.trim());case"float":return a=>{let f=Number(a);if(!Number.isFinite(f))throw Error("not a number");return f};case"u":case"i":return a=>{if(!/^-?\d+$/.test(a.trim()))throw Error("not a whole number");return o.bits>32?BigInt(a.trim()):Number(a.trim())};default:return}})();if(!s)return;let i=!n&&(un(o)||fi(o,e)&&o.max===16&&/(request_id|idempotency_key)$/.test(r)),c=fe("input",{placeholder:n?"leave empty for none":"",value:i?Tl():""});return{el:c,read(){if(n&&c.value==="")return null;try{let a=s(c.value);return n?{some:a}:a}catch(a){throw Error(`${r}: ${a.message}`)}}}}function Qa(t,e,r="request",n=0){if(n>12)throw Error(`${r}: type nests too deeply for the form; use raw JSON`);let o=Ya(t,e,r,!1);if(o)return o;let s=Fe(t,e),i=(c,a)=>Qa(c,e,a,n+1);switch(s.k){case"unit":return{el:fe("em",{},"No input needed."),read:()=>null};case"bool":{let c=fe("input",{type:"checkbox"});return{el:fe("label",{className:"check"},c," yes"),read:()=>c.checked}}case"option":{let c=Ya(s.item,e,r,!0);if(c)return c;let a=fe("input",{type:"checkbox"}),f=i(s.item,r),u=fe("div",{hidden:!0},f.el);return a.onchange=()=>{u.hidden=!a.checked},{el:fe("div",{},fe("label",{className:"check"},a," include"),u),read:()=>a.checked?{some:f.read()}:null}}case"extension-record":case"record":{let c=Fo(s).map(a=>({f:a,node:i(a.value,`${r}.${a.name}`)}));return{el:fe("div",{className:"record"},...c.map(({f:a,node:f})=>ui(a.name,a.value,e,f))),read:()=>Object.fromEntries(c.map(({f:a,node:f})=>[a.name,f.read()]))}}case"extension-tuple":case"tuple":{let c=gt(s),a=c.map((f,u)=>i(f,`${r}[${u}]`));return{el:fe("div",{className:"record"},...a.map((f,u)=>ui(`#${u+1}`,c[u],e,f))),read:()=>a.map(f=>f.read())}}case"enum":{let c=fe("select",{},...s.variants.map(d=>new Option(d.name,d.name))),a=fe("div"),f,u=()=>{let d=s.variants.find(l=>l.name===c.value);f=Fe(d.value,e).k==="unit"?{el:fe("span"),read:()=>null}:i(d.value,`${r}.${d.name}`),a.replaceChildren(f.el)};return c.onchange=u,u(),{el:fe("div",{},c,a),read:()=>({tag:c.value,value:f.read()})}}default:{let c=fe("textarea",{rows:2,value:"[]"});return{el:fe("div",{},c,fe("small",{},' JSON list; tags like {"$principal":"\u2026"} work here')),read(){try{return JSON.parse(c.value,li)}catch(a){throw Error(`${r}: ${a.message}`)}}}}}}function ui(t,e,r,n){let o=Fe(e,r).k==="option";return fe("div",{className:"field"},fe("div",{className:"field-label"},fe("strong",{},t)," ",fe("span",{className:o?"tag optional":"tag required"},o?"optional":"required")," ",fe("small",{},Wa(e,r).replace(/^optional /,""))),n.el)}function Ja(t,e){let r=Qa(t,e),n=Fe(t,e),o=n.k==="record"||n.k==="unit"?r.el:ui("value",t,e,r);return{el:fe("div",{},o),read:r.read}}var Ol=new Set(["Option","Result","List","Vec","Bytes","Box","String","Text"]),hi=t=>t.replace(/^Wire_/,"").replace(/_[0-9a-f]{16}$/,""),_l=t=>/^[A-Z]/.test(hi(t))&&!Ol.has(hi(t)),Lo=t=>/^[A-Za-z_$][\w$]*$/.test(t)?t:JSON.stringify(t),Il=t=>t.replace(/(^|_)(\w)/g,(e,r,n)=>n.toUpperCase());function ef(){let t=new Map,e=new Map,r=new Map,n=c=>{let a=t.get(c);if(a)return a;let f=hi(c),u=f;for(let d=2;e.has(u);d++)u=`${f}${d}`;return t.set(c,u),e.set(u,c),u},o=(c,a,f)=>{if(a.k==="record"||a.k==="extension-record")return`export interface ${c} {
${Fo(a).map(d=>`  readonly ${Lo(d.name)}: ${s(d.value,f)};`).join(`
`)}
}`;if(a.k==="enum")return`export type ${c} =
${a.variants.map(d=>`  | { readonly tag: ${JSON.stringify(d.name)}; readonly value: ${s(d.value,f)} }`).join(`
`)};`;let u=a.max!==void 0?` // max ${a.max}`:"";return`export type ${c} = ${s(a,f)};${u}`},s=(c,a)=>{if(!c)return"null";switch(c.k){case"ref":{let f=a[c.name];if(!f)return"unknown";if(!_l(c.name))return s(f,a);let u=n(c.name);return r.has(u)||(r.set(u,""),r.set(u,o(u,f,a))),u}case"unit":return"null";case"bool":return"boolean";case"u":case"i":return(c.bits??64)>32?"bigint":"number";case"float":return"number";case"text":return"string";case"bytes":return"Uint8Array";case"newtype":return s(c.item,a);case"option":return`null | { readonly some: ${s(c.item,a)} }`;case"list":case"packed":case"array":return`ReadonlyArray<${c.item?s(c.item,a):"number"}>`;case"extension-tuple":case"tuple":return`readonly [${gt(c).map(f=>s(f,a)).join(", ")}]`;case"result":return`{ readonly ok: ${s(c.ok,a)} } | { readonly err: ${s(c.err,a)} }`;case"extension-record":case"record":return`{ ${Fo(c).map(f=>`readonly ${Lo(f.name)}: ${s(f.value,a)};`).join(" ")} }`;case"enum":return c.variants.map(f=>`{ readonly tag: ${JSON.stringify(f.name)}; readonly value: ${s(f.value,a)} }`).join(" | ");default:return"unknown"}};return{method:c=>{let a=`  /** ${c.mode} \xB7 ${c.access} */`;return c.schemas?`${a}
  ${Lo(c.name)}(request: ${s(c.schemas.Request,c.schemas)}): Promise<${s(c.schemas.Response,c.schemas)}>;`:`${a}
  ${Lo(c.name)}(request: unknown): Promise<unknown>;`},declarations:()=>[...r.values()]}}function tf(t,e){let r=ef(),n=e.map(r.method).join(`
`);return`// ${t}: TypeScript view of the Wire contracts for ${t}.
${r.declarations().join(`

`)}

export interface ${Il(t)}Service {
${n}
}
`}function rf(t,e){let r=ef(),n=r.method(e).replace(/^ {2}/gm,""),o=r.declarations();return`// ${t}.${e.name}
${n}${o.length?`

${o.join(`

`)}`:""}
`}var ue=t=>document.getElementById(t);function G(t,e={},...r){let n=Object.assign(document.createElement(t),e);return n.append(...r),n}var sf=ue("actors"),cf=ue("search"),pi=ue("mode"),af=ue("methods"),ff=ue("method-links"),hn=ue("notice"),Or=ue("id"),$o=ue("application"),cr=await(await fetch("/console.json")).json();Number.isInteger(cr.app_port)&&cr.app_port>0&&cr.app_port<=65535&&($o.href="http://localhost:"+cr.app_port+"/",$o.hidden=!1);var Re=cr.connection,Po=cr.methods??{},mn=cr.contracts??{},vr=new Map,_r=new Map,we="",jo="",tt=[];function vl(){return Array.from(new Set([...Object.keys(Po),...Object.keys(Re?.canisters??{}),...Object.keys(mn),...vr.keys()])).sort()}function uf(t,e){let r=vr.get(t)?.get(e);if(r)return r;let n=mn[t]?.[e];if(!n)return;let{Root:o,...s}=n.request.schema,{Root:i,...c}=n.reply.schema;return{id:n.id,schemas:{...s,...c,Request:o,Response:i},request:n.request_limits,response:n.reply_limits}}function Rl(t){return{id:t.id,request:{k:"ref",name:"Request"},response:{k:"ref",name:"Response"},requestBytes:t.request.bytes,responseBytes:t.response.bytes,requestNodes:t.request.nodes,responseNodes:t.response.nodes,requestDepth:t.request.depth,responseDepth:t.response.depth}}function Ho(t){let e=new URL(t.gateway);if(e.protocol!=="http:"||!["localhost","127.0.0.1","[::1]"].includes(e.hostname)||e.username||e.password||e.pathname!=="/"||e.search||e.hash)throw Error("Select a local simulator gateway.");let r=t.root_key,n=typeof r=="string"&&/^(?:[a-f\d]{2})+$/i.test(r)?Uint8Array.from(r.match(/../g),o=>parseInt(o,16)):Array.isArray(r)&&r.every(o=>Number.isInteger(o)&&o>=0&&o<=255)?Uint8Array.from(r):null;if(!n?.length)throw Error("Connection needs a pinned root key.");return{host:e.origin,rootKey:n,shouldFetchRootKey:!1,retryTimes:0}}var pn=(t,e)=>t?.k==="ref"&&e[t.name]?pn(e[t.name],e):t,mi=t=>!!t&&(t.k==="tuple"||t.k==="extension-tuple")&&gt(t).length===1,df=(t,e)=>{let r=pn(t,e);return mi(r)?gt(r)[0]:t},Al=t=>Array.isArray(t)&&t.length===16&&t.every(e=>Number.isInteger(e)&&e>=0&&e<256);function lf(t,e){return typeof e=="bigint"?`${e}n`:e instanceof Uint8Array?e.length===16?{$ulidBytes:qo(e)}:e.length===10||e.length===29?{$hex:di(e),_principal:L.fromUint8Array(e).toText()}:{$hex:di(e)}:Al(e)?{$ulid:qo(e)}:e}var bi=t=>JSON.stringify(t,lf,2),Cl=t=>JSON.stringify(t,lf);function Nl(t){let e=[],r=/("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|(-?\d+(?:\.\d+)?)/g,n=0;for(let o of t.matchAll(r)){e.push(document.createTextNode(t.slice(n,o.index)));let s=o[2]?"j-key":o[1]?"j-str":o[3]?"j-lit":"j-num";e.push(G("span",{className:s,textContent:o[1]??o[0]})),o[2]&&e.push(document.createTextNode(o[2])),n=o.index+o[0].length}return e.push(document.createTextNode(t.slice(n))),e}function Do(t){let e=t instanceof Error?t.message:String(t);return/authori[sz]ation|unauthenticated/i.test(e)?`This endpoint needs a signed caller; the console calls anonymously.
${e}`:e==="wire value"?"The request doesn't match the endpoint's input type (wire value).":e}var Ir=ue("history-list"),hf=ue("clear-history");function pf(){ue("history-count").textContent=String(Ir.childElementCount),hf.disabled=Ir.childElementCount===0}function mf(){Ir.replaceChildren(),pf()}hf.onclick=mf;function kl(t,e,r,n){let o=`${new Date().toLocaleTimeString()} \xB7 ${t}.${e} \xB7 ${r}`,s=G("summary",{},`${o} \xB7 Pending`),i=G("div",{className:"entry"},G("code",{},n)),c=G("li",{className:"pending"},G("details",{},s,i));Ir.prepend(c),Ir.childElementCount>50&&Ir.lastElementChild.remove(),pf();let a=(f,u)=>i.append(G("strong",{},f),G("pre",{},u.length>4096?u.slice(0,4096)+"\u2026":u));return{request(f){a("Request",bi(f))},finish(f,u){s.textContent=`${o} \xB7 ${f}`,c.className=f==="Reply"?"":"error",a(f,u)}}}function bf(t,e){let r=G("button",{textContent:t});return r.onclick=async()=>{try{await navigator.clipboard.writeText(e()),r.textContent="Copied",setTimeout(()=>{r.textContent=t},1500)}catch{hn.textContent="Clipboard access failed. Select the declaration or use Download."}},r}function yf(t){return _r.get(t)??Re?.canisters?.[t]??""}Or.oninput=()=>{let t=Or.value.trim();t&&t!==Re?.canisters?.[we]?_r.set(we,t):_r.delete(we),Or.classList.toggle("edited",_r.has(we))};function Ul(t,e){let r=uf(t,e.name),n=r?.schemas??{},o=r&&pn(n.Request,n),s=(o?o.k==="tuple"||o.k==="extension-tuple"?gt(o).map(a=>dn(a,n)).join(", "):dn(o,n):"").replace(/^\(\)$/,""),i=r?`(${s}) \u2192 ${dn(df(n.Response,n),n)}`:e.rust??"",c=G("details",{className:"method"},G("summary",{},G("span",{className:"name"},e.name),G("span",{className:"sig"},i),G("span",{className:`badge ${e.mode}`},e.mode.replace("_"," "))));return c.addEventListener("toggle",()=>{c.open&&c.children.length===1&&c.append(Fl(t,e,r))}),c}function Fl(t,e,r){let n=G("div",{className:"body"});if(!r)return n.append(G("p",{},"Load this endpoint\u2019s Wire manifest, or the app\u2019s contracts.json, to build its request.")),n;let o=r.schemas,s=mi(pn(o.Request,o)),i=mi(pn(o.Response,o)),c;try{c=Ja(df(o.Request,o),o)}catch(M){c={el:G("em",{},Do(M)),read:()=>{throw M}}}let a=G("textarea",{rows:4,hidden:!0,spellcheck:!1}),f=G("input",{type:"checkbox"});f.onchange=()=>{if(f.checked)try{a.value=Cl(c.read())}catch{a.value="null"}a.hidden=!f.checked,c.el.hidden=f.checked};let u=!0;try{Ho(Re)}catch{u=!1}let d=["query","composite_query","update"].includes(e.mode),l=u&&d,h=G("button",{className:`btn ${e.mode}`,disabled:!l,title:u?"":"Load a local fleet connection with a pinned gateway and root key to send calls.",textContent:u?e.mode==="update"?"Send anonymous update":d?"Run anonymous query":"Unknown call mode":"No local gateway"}),m=G("span",{className:"chip"}),b=G("span",{className:"elapsed"}),p=G("pre"),x=G("div",{className:"result"},G("div",{className:"result-head"},m,b),p),g=(M,$,R)=>{x.className=M==="err"&&typeof R=="string"?"result shown error":"result shown",m.className=`chip ${M}`,m.textContent=$,p.replaceChildren(...typeof R=="string"?[R]:R)};h.onclick=async()=>{let M;try{M=f.checked?JSON.parse(a.value,li):c.read()}catch(K){return b.textContent="",g("err","Invalid input",Do(K))}let $=yf(t).trim(),R;try{R=L.fromText($)}catch{return g("err","No target","Enter the canister principal under Canister ID.")}let F=kl(t,e.name,e.mode,$);F.request(M),g("wait","Waiting\u2026",""),b.textContent="",h.disabled=!0;let P=performance.now();try{let K=Za(Rl(r),o),X=K.encodeRequest(s?[M]:M),re=await No.create({...Ho(Re),identity:new sr}),N;if(e.mode==="update")N=(await re.update(R,{methodName:e.name,arg:X})).reply;else{let C=await re.query(R,{methodName:e.name,arg:X});if(C.status!=="replied")throw Error(`reject ${C.reject_code}: ${C.reject_message}`);N=C.reply.arg}let V=K.decodeResponse(new Uint8Array(N)),z=i?V[0]:V,E=z,A=E&&typeof E=="object"&&"err"in E?`Err${E.err?.tag?` \xB7 ${E.err.tag}`:""}`:"Ok";g(A==="Ok"?"ok":"err",A,Nl(bi(z))),F.finish("Reply",bi(z))}catch(K){g("err","Rejected",Do(K)),F.finish("Error",Do(K))}finally{b.textContent=`${((performance.now()-P)/1e3).toFixed(3)} s`,h.disabled=!l}};let y=G("pre",{className:"ts-code"}),O=()=>y.textContent||(y.textContent=rf(t,e)),S=G("details",{className:"ts"},G("summary",{},"TypeScript"),y,bf("Copy TypeScript",O));return S.ontoggle=()=>{S.open&&O()},n.append(c.el,a,G("div",{className:"actions"},h,G("label",{className:"json-toggle"},f," edit as JSON")),x,S),n}function xi(){let t=cf.value.trim().toLowerCase(),e=n=>n.dataset.name.toLowerCase().includes(t)&&(!jo||n.dataset.mode===jo||jo==="query"&&n.dataset.mode==="composite_query"),r=0;for(let n of af.children)(n.hidden=!e(n))||r++;for(let n of ff.children)n.hidden=!e(n);ue("no-matches").hidden=tt.length===0||r>0}cf.oninput=xi;for(let t of pi.children)t.onclick=()=>{jo=t.dataset.mode;for(let e of pi.children)e.classList.toggle("active",e===t);xi()};function xf(t){let e=new Map;for(let r of Po[t]??[])e.set(r.name,{name:r.name,mode:r.mode,access:"application-defined",rust:r.argument&&r.reply?`${r.argument} \u2192 ${r.reply}`:""});for(let[r,n]of Object.entries(mn[t]??{}))e.has(r)||e.set(r,{name:r,mode:n.mode,access:"application-defined"});for(let r of vr.get(t)?.keys()??[])e.has(r)||e.set(r,{name:r,mode:"unknown",access:"application-defined"});return[...e.values()].sort((r,n)=>r.name.localeCompare(n.name)).map(r=>({...r,schemas:uf(t,r.name)?.schemas}))}function gf(){let t=vl();t.includes(we)||(we=t.includes("user_hub")?"user_hub":t[0]??""),sf.replaceChildren(...t.map(e=>{let r=G("button",{},e,G("span",{className:"count"},String(xf(e).length)));return r.dataset.name=e,r.onclick=()=>{we=e,nf()},r})),nf()}function nf(){for(let e of sf.children)e.classList.toggle("active",e.dataset.name===we);ue("fleet").textContent=[Re?.app,Re?.fleet].filter(Boolean).join(" / "),Or.value=yf(we),Or.placeholder=we?"principal of this canister":"",Or.classList.toggle("edited",_r.has(we)),ue("canister-title").textContent=we,tt=xf(we),yi.textContent="",ln.hidden||Vo(),af.replaceChildren(...tt.map(e=>{let r=G("li",{id:`method-${e.name}`},Ul(we,e));return r.dataset.name=e.name,r.dataset.mode=e.mode,r})),ff.replaceChildren(...tt.map(e=>{let r=G("a",{href:`#method-${e.name}`,className:e.schemas?"":"unknown",title:e.schemas?e.mode:`${e.mode} \xB7 no Wire manifest loaded`},G("span",{className:`mode-dot ${e.mode}`}),e.name);return r.dataset.name=e.name,r.dataset.mode=e.mode,r.onclick=()=>{ue(`method-${e.name}`).firstElementChild.open=!0},r}));for(let e of pi.children){let r=e.dataset.mode;e.querySelector(".n").textContent=String(tt.filter(n=>!r||n.mode===r||r==="query"&&n.mode==="composite_query").length)}let t=tt.filter(e=>e.schemas).length;hn.className="",hn.textContent=tt.length?t<tt.length?`${tt.length-t} of ${tt.length} endpoints have no Wire manifest; load the app\u2019s contracts.json to build their requests. Calls use the anonymous identity.`:"Calls use the browser\u2019s anonymous identity. Endpoints that need a signed caller refuse them; use the application for signed calls.":"Load Wire contracts to inspect endpoints.",xi()}var ln=ue("types-panel"),yi=ue("types-code"),of=ue("show-types"),Vo=()=>yi.textContent||(yi.textContent=tf(we,tt));of.onclick=()=>{ln.hidden=!ln.hidden,of.classList.toggle("active",!ln.hidden),ln.hidden||Vo()};ue("copy-types").replaceWith(bf("Copy",Vo));ue("download-types").onclick=()=>{let t=URL.createObjectURL(new Blob([Vo()],{type:"text/plain"}));G("a",{href:t,download:`${we}.ts`}).click(),setTimeout(()=>URL.revokeObjectURL(t),1e3)};async function gi(){let t=ue("status"),e;try{e=Ho(Re).host}catch{}let r=e?await fetch(e+"/api/v2/status").then(n=>n.ok).catch(()=>!1):!1;t.className=r?"up":"down",ue("status-text").textContent=e?r?`fleet up \xB7 ${new URL(e).host}`:`fleet offline \xB7 ${new URL(e).host}`:"no local gateway"}gi();setInterval(gi,5e3);function wf(t,e){let r=ue(t);r.onchange=async()=>{try{for(let n of r.files??[]){if(n.size>16*1024*1024)throw Error("File exceeds 16 MiB.");e(JSON.parse(await n.text()))}gf()}catch(n){hn.className="error",hn.textContent=String(n)}r.value=""}}wf("connection",t=>{if(Ho(t),!t.canisters||typeof t.canisters!="object")throw Error("Missing canister map.");for(let r of Object.values(t.canisters))L.fromText(String(r));let e=t.app===Re?.app&&t.fleet===Re?.fleet&&t.gateway===Re?.gateway&&String(t.root_key)===String(Re?.root_key)&&Object.keys({...Re?.canisters,...t.canisters}).every(r=>t.canisters[r]===Re?.canisters?.[r]);if(Re=t,gi(),!e){mf(),_r.clear(),$o.hidden=!0,$o.removeAttribute("href");for(let r of Object.keys(Po))delete Po[r];mn={},vr.clear()}});wf("contracts",t=>{if(t.schemas&&t.endpoint){if(!we)throw Error("Select a canister first.");let e=vr.get(we)??new Map,r=n=>({...n.payload_limits,bytes:n.payload_limits.bytes+11});e.set(t.endpoint,{id:t.id,schemas:t.schemas,request:r(t.request),response:r(t.response)}),vr.set(we,e)}else{for(let e of Object.values(t))for(let r of Object.values(e))if(!r.request?.schema?.Root||!r.reply?.schema?.Root)throw Error("Expected a Canic contracts.json inventory.");mn=t}});gf();
/*! Bundled license information:

@noble/curves/utils.js:
@noble/curves/abstract/modular.js:
@noble/curves/abstract/curve.js:
@noble/curves/abstract/weierstrass.js:
@noble/curves/abstract/bls.js:
@noble/curves/abstract/tower.js:
@noble/curves/bls12-381.js:
@noble/curves/abstract/edwards.js:
@noble/curves/ed25519.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
*/

/*! @dfinity/cbor, @icp-sdk/core, ic-wire
Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

/*! @noble/curves, @noble/hashes
The MIT License (MIT)

Copyright (c) 2022 Paul Miller (https://paulmillr.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/