@junobuild/core-standalone 2.2.0 → 2.2.1-next-2025-10-22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +28 -28
- package/dist/browser/index.js.map +4 -4
- package/dist/node/index.mjs +63 -63
- package/dist/node/index.mjs.map +4 -4
- package/dist/types/auth/providers/_auth-client.providers.d.ts +2 -2
- package/dist/types/auth/services/auth.services.d.ts +1 -1
- package/dist/types/auth/services/user-webauthn.services.d.ts +1 -1
- package/dist/types/auth/utils/auth.utils.d.ts +1 -1
- package/dist/types/core/api/actor.api.d.ts +2 -2
- package/dist/types/core/services/identity.services.d.ts +1 -1
- package/dist/types/core/stores/_agent.factory.d.ts +1 -1
- package/dist/types/core/stores/actor.store.d.ts +2 -2
- package/dist/types/core/stores/agent.store.d.ts +1 -1
- package/dist/types/core/types/list.d.ts +1 -1
- package/dist/types/core/types/satellite.d.ts +1 -1
- package/dist/types/functions/services/functions.services.d.ts +2 -2
- package/dist/workers/auth.worker.js +6 -6
- package/dist/workers/auth.worker.js.map +4 -4
- package/package.json +4 -7
package/dist/node/index.mjs
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
1
|
import { createRequire as topLevelCreateRequire } from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
-
var M1=Object.create;var Tl=Object.defineProperty;var k1=Object.getOwnPropertyDescriptor;var j1=Object.getOwnPropertyNames;var H1=Object.getPrototypeOf,$1=Object.prototype.hasOwnProperty;var K1=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Z=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),G1=(t,e)=>{for(var r in e)Tl(t,r,{get:e[r],enumerable:!0})},z1=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of j1(e))!$1.call(t,o)&&o!==r&&Tl(t,o,{get:()=>e[o],enumerable:!(n=k1(e,o))||n.enumerable});return t};var De=(t,e,r)=>(r=t!=null?M1(H1(t)):{},z1(e||!t||!t.__esModule?Tl(r,"default",{value:t,enumerable:!0}):r,t));var Ol=Z(ao=>{"use strict";Object.defineProperty(ao,"__esModule",{value:!0});ao.QueryResponseStatus=ao.ReplicaRejectCode=void 0;ao.isV2ResponseBody=Z1;ao.isV3ResponseBody=Y1;var fm;(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"})(fm||(ao.ReplicaRejectCode=fm={}));var pm;(function(t){t.Replied="replied",t.Rejected="rejected"})(pm||(ao.QueryResponseStatus=pm={}));function Z1(t){return t!=null&&"reject_code"in t}function Y1(t){return t!=null&&"certificate"in t}});var hm=Z(Fc=>{"use strict";Object.defineProperty(Fc,"__esModule",{value:!0});Fc.encode=W1;Fc.decode=X1;var Dc="abcdefghijklmnopqrstuvwxyz234567",Hs=Object.create(null);for(let t=0;t<Dc.length;t++)Hs[Dc[t]]=t;Hs[0]=Hs.o;Hs[1]=Hs.i;function W1(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+=Dc[r>>3],e+=5),0)}for(let s=0;s<t.length;)s+=o(t[s]);return n+(e<0?Dc[r>>3]:"")}function X1(t){let e=0,r=0,n=new Uint8Array(t.length*4/3|0),o=0;function s(i){let a=Hs[i.toLowerCase()];if(a===void 0)throw new Error(`Invalid character: ${JSON.stringify(i)}`);a<<=3,r|=a>>>e,e+=5,e>=8&&(n[o++]=r,e-=8,e>0?r=a<<5-e&255:r=0)}for(let i of t)s(i);return n.slice(0,o)}});var vl=Z(Nl=>{"use strict";Object.defineProperty(Nl,"__esModule",{value:!0});Nl.getCrc32=Q1;var J1=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 Q1(t){let e=-1;for(let r=0;r<t.length;r++){let o=(t[r]^e)&255;e=J1[o]^e>>>8}return(e^-1)>>>0}});var mm=Z(Vc=>{"use strict";Object.defineProperty(Vc,"__esModule",{value:!0});Vc.crypto=void 0;var co=K1("node:crypto");Vc.crypto=co&&typeof co=="object"&&"webcrypto"in co?co.webcrypto:co&&typeof co=="object"&&"randomBytes"in co?co:void 0});var dt=Z(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.wrapXOFConstructorWithOpts=te.wrapConstructorWithOpts=te.wrapConstructor=te.Hash=te.nextTick=te.swap32IfBE=te.byteSwapIfBE=te.swap8IfBE=te.isLE=void 0;te.isBytes=_m;te.anumber=Il;te.abytes=Ks;te.ahash=e2;te.aexists=t2;te.aoutput=r2;te.u8=n2;te.u32=o2;te.clean=s2;te.createView=i2;te.rotr=a2;te.rotl=c2;te.byteSwap=Sl;te.byteSwap32=bm;te.bytesToHex=d2;te.hexToBytes=l2;te.asyncLoop=p2;te.utf8ToBytes=Al;te.bytesToUtf8=h2;te.toBytes=Uc;te.kdfInputToBytes=m2;te.concatBytes=y2;te.checkOpts=_2;te.createHasher=xm;te.createOptHasher=wm;te.createXOFer=Em;te.randomBytes=b2;var $s=mm();function _m(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Il(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Ks(t,...e){if(!_m(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function e2(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Il(t.outputLen),Il(t.blockLen)}function t2(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function r2(t,e){Ks(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function n2(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function o2(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function s2(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function i2(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function a2(t,e){return t<<32-e|t>>>e}function c2(t,e){return t<<e|t>>>32-e>>>0}te.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Sl(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}te.swap8IfBE=te.isLE?t=>t:t=>Sl(t);te.byteSwapIfBE=te.swap8IfBE;function bm(t){for(let e=0;e<t.length;e++)t[e]=Sl(t[e]);return t}te.swap32IfBE=te.isLE?t=>t:bm;var gm=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",u2=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function d2(t){if(Ks(t),gm)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=u2[t[r]];return e}var Tn={_0:48,_9:57,A:65,F:70,a:97,f:102};function ym(t){if(t>=Tn._0&&t<=Tn._9)return t-Tn._0;if(t>=Tn.A&&t<=Tn.F)return t-(Tn.A-10);if(t>=Tn.a&&t<=Tn.f)return t-(Tn.a-10)}function l2(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(gm)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("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=ym(t.charCodeAt(s)),a=ym(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}var f2=async()=>{};te.nextTick=f2;async function p2(t,e,r){let n=Date.now();for(let o=0;o<t;o++){r(o);let s=Date.now()-n;s>=0&&s<e||(await(0,te.nextTick)(),n+=s)}}function Al(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function h2(t){return new TextDecoder().decode(t)}function Uc(t){return typeof t=="string"&&(t=Al(t)),Ks(t),t}function m2(t){return typeof t=="string"&&(t=Al(t)),Ks(t),t}function y2(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ks(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 _2(t,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(t,e)}var Rl=class{};te.Hash=Rl;function xm(t){let e=n=>t().update(Uc(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function wm(t){let e=(n,o)=>t(o).update(Uc(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}function Em(t){let e=(n,o)=>t(o).update(Uc(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}te.wrapConstructor=xm;te.wrapConstructorWithOpts=wm;te.wrapXOFConstructorWithOpts=Em;function b2(t=32){if($s.crypto&&typeof $s.crypto.getRandomValues=="function")return $s.crypto.getRandomValues(new Uint8Array(t));if($s.crypto&&typeof $s.crypto.randomBytes=="function")return Uint8Array.from($s.crypto.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}});var Om=Z(Ft=>{"use strict";Object.defineProperty(Ft,"__esModule",{value:!0});Ft.SHA512_IV=Ft.SHA384_IV=Ft.SHA224_IV=Ft.SHA256_IV=Ft.HashMD=void 0;Ft.setBigUint64=Tm;Ft.Chi=g2;Ft.Maj=x2;var $r=dt();function Tm(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,d=n?0:4;t.setUint32(e+c,i,n),t.setUint32(e+d,a,n)}function g2(t,e,r){return t&e^~t&r}function x2(t,e,r){return t&e^t&r^e&r}var Bl=class extends $r.Hash{constructor(e,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=(0,$r.createView)(this.buffer)}update(e){(0,$r.aexists)(this),e=(0,$r.toBytes)(e),(0,$r.abytes)(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=(0,$r.createView)(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){(0,$r.aexists)(this),(0,$r.aoutput)(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,(0,$r.clean)(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;Tm(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=(0,$r.createView)(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=c/4,p=this.get();if(d>p.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)a.setUint32(4*l,p[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}};Ft.HashMD=Bl;Ft.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);Ft.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);Ft.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]);Ft.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});var Gm=Z(ue=>{"use strict";Object.defineProperty(ue,"__esModule",{value:!0});ue.toBig=ue.shrSL=ue.shrSH=ue.rotrSL=ue.rotrSH=ue.rotrBL=ue.rotrBH=ue.rotr32L=ue.rotr32H=ue.rotlSL=ue.rotlSH=ue.rotlBL=ue.rotlBH=ue.add5L=ue.add5H=ue.add4L=ue.add4H=ue.add3L=ue.add3H=void 0;ue.add=qm;ue.fromBig=Pl;ue.split=Nm;var Lc=BigInt(2**32-1),Cl=BigInt(32);function Pl(t,e=!1){return e?{h:Number(t&Lc),l:Number(t>>Cl&Lc)}:{h:Number(t>>Cl&Lc)|0,l:Number(t&Lc)|0}}function Nm(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:a}=Pl(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var vm=(t,e)=>BigInt(t>>>0)<<Cl|BigInt(e>>>0);ue.toBig=vm;var Im=(t,e,r)=>t>>>r;ue.shrSH=Im;var Rm=(t,e,r)=>t<<32-r|e>>>r;ue.shrSL=Rm;var Sm=(t,e,r)=>t>>>r|e<<32-r;ue.rotrSH=Sm;var Am=(t,e,r)=>t<<32-r|e>>>r;ue.rotrSL=Am;var Bm=(t,e,r)=>t<<64-r|e>>>r-32;ue.rotrBH=Bm;var Cm=(t,e,r)=>t>>>r-32|e<<64-r;ue.rotrBL=Cm;var Pm=(t,e)=>e;ue.rotr32H=Pm;var Dm=(t,e)=>t;ue.rotr32L=Dm;var Fm=(t,e,r)=>t<<r|e>>>32-r;ue.rotlSH=Fm;var Vm=(t,e,r)=>e<<r|t>>>32-r;ue.rotlSL=Vm;var Um=(t,e,r)=>e<<r-32|t>>>64-r;ue.rotlBH=Um;var Lm=(t,e,r)=>t<<r-32|e>>>64-r;ue.rotlBL=Lm;function qm(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Mm=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0);ue.add3L=Mm;var km=(t,e,r,n)=>e+r+n+(t/2**32|0)|0;ue.add3H=km;var jm=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0);ue.add4L=jm;var Hm=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0;ue.add4H=Hm;var $m=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0);ue.add5L=$m;var Km=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;ue.add5H=Km;var w2={fromBig:Pl,split:Nm,toBig:vm,shrSH:Im,shrSL:Rm,rotrSH:Sm,rotrSL:Am,rotrBH:Bm,rotrBL:Cm,rotr32H:Pm,rotr32L:Dm,rotlSH:Fm,rotlSL:Vm,rotlBH:Um,rotlBL:Lm,add:qm,add3L:Mm,add3H:km,add4L:jm,add4H:Hm,add5H:Km,add5L:$m};ue.default=w2});var Gs=Z(Le=>{"use strict";Object.defineProperty(Le,"__esModule",{value:!0});Le.sha512_224=Le.sha512_256=Le.sha384=Le.sha512=Le.sha224=Le.sha256=Le.SHA512_256=Le.SHA512_224=Le.SHA384=Le.SHA512=Le.SHA224=Le.SHA256=void 0;var Q=Om(),ye=Gm(),Qe=dt(),E2=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]),uo=new Uint32Array(64),ea=class extends Q.HashMD{constructor(e=32){super(64,e,8,!1),this.A=Q.SHA256_IV[0]|0,this.B=Q.SHA256_IV[1]|0,this.C=Q.SHA256_IV[2]|0,this.D=Q.SHA256_IV[3]|0,this.E=Q.SHA256_IV[4]|0,this.F=Q.SHA256_IV[5]|0,this.G=Q.SHA256_IV[6]|0,this.H=Q.SHA256_IV[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){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=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)uo[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let u=uo[l-15],f=uo[l-2],h=(0,Qe.rotr)(u,7)^(0,Qe.rotr)(u,18)^u>>>3,m=(0,Qe.rotr)(f,17)^(0,Qe.rotr)(f,19)^f>>>10;uo[l]=m+uo[l-7]+h+uo[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:d,H:p}=this;for(let l=0;l<64;l++){let u=(0,Qe.rotr)(a,6)^(0,Qe.rotr)(a,11)^(0,Qe.rotr)(a,25),f=p+u+(0,Q.Chi)(a,c,d)+E2[l]+uo[l]|0,m=((0,Qe.rotr)(n,2)^(0,Qe.rotr)(n,13)^(0,Qe.rotr)(n,22))+(0,Q.Maj)(n,o,s)|0;p=d,d=c,c=a,a=i+f|0,i=s,s=o,o=n,n=f+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,d=d+this.G|0,p=p+this.H|0,this.set(n,o,s,i,a,c,d,p)}roundClean(){(0,Qe.clean)(uo)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,Qe.clean)(this.buffer)}};Le.SHA256=ea;var qc=class extends ea{constructor(){super(28),this.A=Q.SHA224_IV[0]|0,this.B=Q.SHA224_IV[1]|0,this.C=Q.SHA224_IV[2]|0,this.D=Q.SHA224_IV[3]|0,this.E=Q.SHA224_IV[4]|0,this.F=Q.SHA224_IV[5]|0,this.G=Q.SHA224_IV[6]|0,this.H=Q.SHA224_IV[7]|0}};Le.SHA224=qc;var zm=ye.split(["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))),T2=zm[0],O2=zm[1],lo=new Uint32Array(80),fo=new Uint32Array(80),Go=class extends Q.HashMD{constructor(e=64){super(128,e,16,!1),this.Ah=Q.SHA512_IV[0]|0,this.Al=Q.SHA512_IV[1]|0,this.Bh=Q.SHA512_IV[2]|0,this.Bl=Q.SHA512_IV[3]|0,this.Ch=Q.SHA512_IV[4]|0,this.Cl=Q.SHA512_IV[5]|0,this.Dh=Q.SHA512_IV[6]|0,this.Dl=Q.SHA512_IV[7]|0,this.Eh=Q.SHA512_IV[8]|0,this.El=Q.SHA512_IV[9]|0,this.Fh=Q.SHA512_IV[10]|0,this.Fl=Q.SHA512_IV[11]|0,this.Gh=Q.SHA512_IV[12]|0,this.Gl=Q.SHA512_IV[13]|0,this.Hh=Q.SHA512_IV[14]|0,this.Hl=Q.SHA512_IV[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:d,El:p,Fh:l,Fl:u,Gh:f,Gl:h,Hh:m,Hl:b}=this;return[e,r,n,o,s,i,a,c,d,p,l,u,f,h,m,b]}set(e,r,n,o,s,i,a,c,d,p,l,u,f,h,m,b){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=a|0,this.Dl=c|0,this.Eh=d|0,this.El=p|0,this.Fh=l|0,this.Fl=u|0,this.Gh=f|0,this.Gl=h|0,this.Hh=m|0,this.Hl=b|0}process(e,r){for(let _=0;_<16;_++,r+=4)lo[_]=e.getUint32(r),fo[_]=e.getUint32(r+=4);for(let _=16;_<80;_++){let T=lo[_-15]|0,N=fo[_-15]|0,I=ye.rotrSH(T,N,1)^ye.rotrSH(T,N,8)^ye.shrSH(T,N,7),v=ye.rotrSL(T,N,1)^ye.rotrSL(T,N,8)^ye.shrSL(T,N,7),A=lo[_-2]|0,E=fo[_-2]|0,S=ye.rotrSH(A,E,19)^ye.rotrBH(A,E,61)^ye.shrSH(A,E,6),V=ye.rotrSL(A,E,19)^ye.rotrBL(A,E,61)^ye.shrSL(A,E,6),C=ye.add4L(v,V,fo[_-7],fo[_-16]),g=ye.add4H(C,I,S,lo[_-7],lo[_-16]);lo[_]=g|0,fo[_]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:d,Dl:p,Eh:l,El:u,Fh:f,Fl:h,Gh:m,Gl:b,Hh:y,Hl:x}=this;for(let _=0;_<80;_++){let T=ye.rotrSH(l,u,14)^ye.rotrSH(l,u,18)^ye.rotrBH(l,u,41),N=ye.rotrSL(l,u,14)^ye.rotrSL(l,u,18)^ye.rotrBL(l,u,41),I=l&f^~l&m,v=u&h^~u&b,A=ye.add5L(x,N,v,O2[_],fo[_]),E=ye.add5H(A,y,T,I,T2[_],lo[_]),S=A|0,V=ye.rotrSH(n,o,28)^ye.rotrBH(n,o,34)^ye.rotrBH(n,o,39),C=ye.rotrSL(n,o,28)^ye.rotrBL(n,o,34)^ye.rotrBL(n,o,39),g=n&s^n&a^s&a,w=o&i^o&c^i&c;y=m|0,x=b|0,m=f|0,b=h|0,f=l|0,h=u|0,{h:l,l:u}=ye.add(d|0,p|0,E|0,S|0),d=a|0,p=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let O=ye.add3L(S,C,w);n=ye.add3H(O,E,V,g),o=O|0}({h:n,l:o}=ye.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=ye.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=ye.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:d,l:p}=ye.add(this.Dh|0,this.Dl|0,d|0,p|0),{h:l,l:u}=ye.add(this.Eh|0,this.El|0,l|0,u|0),{h:f,l:h}=ye.add(this.Fh|0,this.Fl|0,f|0,h|0),{h:m,l:b}=ye.add(this.Gh|0,this.Gl|0,m|0,b|0),{h:y,l:x}=ye.add(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,o,s,i,a,c,d,p,l,u,f,h,m,b,y,x)}roundClean(){(0,Qe.clean)(lo,fo)}destroy(){(0,Qe.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};Le.SHA512=Go;var Mc=class extends Go{constructor(){super(48),this.Ah=Q.SHA384_IV[0]|0,this.Al=Q.SHA384_IV[1]|0,this.Bh=Q.SHA384_IV[2]|0,this.Bl=Q.SHA384_IV[3]|0,this.Ch=Q.SHA384_IV[4]|0,this.Cl=Q.SHA384_IV[5]|0,this.Dh=Q.SHA384_IV[6]|0,this.Dl=Q.SHA384_IV[7]|0,this.Eh=Q.SHA384_IV[8]|0,this.El=Q.SHA384_IV[9]|0,this.Fh=Q.SHA384_IV[10]|0,this.Fl=Q.SHA384_IV[11]|0,this.Gh=Q.SHA384_IV[12]|0,this.Gl=Q.SHA384_IV[13]|0,this.Hh=Q.SHA384_IV[14]|0,this.Hl=Q.SHA384_IV[15]|0}};Le.SHA384=Mc;var Nt=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),vt=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]),kc=class extends Go{constructor(){super(28),this.Ah=Nt[0]|0,this.Al=Nt[1]|0,this.Bh=Nt[2]|0,this.Bl=Nt[3]|0,this.Ch=Nt[4]|0,this.Cl=Nt[5]|0,this.Dh=Nt[6]|0,this.Dl=Nt[7]|0,this.Eh=Nt[8]|0,this.El=Nt[9]|0,this.Fh=Nt[10]|0,this.Fl=Nt[11]|0,this.Gh=Nt[12]|0,this.Gl=Nt[13]|0,this.Hh=Nt[14]|0,this.Hl=Nt[15]|0}};Le.SHA512_224=kc;var jc=class extends Go{constructor(){super(32),this.Ah=vt[0]|0,this.Al=vt[1]|0,this.Bh=vt[2]|0,this.Bl=vt[3]|0,this.Ch=vt[4]|0,this.Cl=vt[5]|0,this.Dh=vt[6]|0,this.Dl=vt[7]|0,this.Eh=vt[8]|0,this.El=vt[9]|0,this.Fh=vt[10]|0,this.Fl=vt[11]|0,this.Gh=vt[12]|0,this.Gl=vt[13]|0,this.Hh=vt[14]|0,this.Hl=vt[15]|0}};Le.SHA512_256=jc;Le.sha256=(0,Qe.createHasher)(()=>new ea);Le.sha224=(0,Qe.createHasher)(()=>new qc);Le.sha512=(0,Qe.createHasher)(()=>new Go);Le.sha384=(0,Qe.createHasher)(()=>new Mc);Le.sha512_256=(0,Qe.createHasher)(()=>new jc);Le.sha512_224=(0,Qe.createHasher)(()=>new kc)});var Xm=Z(Kr=>{"use strict";Object.defineProperty(Kr,"__esModule",{value:!0});Kr.Principal=Kr.JSON_KEY_PRINCIPAL=void 0;var Zm=hm(),N2=vl(),v2=Gs(),Ym=dt();Kr.JSON_KEY_PRINCIPAL="__principal__";var I2=2,Wm=4,R2="aaaaa-aa",Dl=class t{static anonymous(){return new this(new Uint8Array([Wm]))}static managementCanister(){return this.fromText(R2)}static selfAuthenticating(e){let r=(0,v2.sha224)(e);return new this(new Uint8Array([...r,I2]))}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((0,Ym.hexToBytes)(e))}static fromText(e){let r=e;if(e.includes(Kr.JSON_KEY_PRINCIPAL)){let i=JSON.parse(e);Kr.JSON_KEY_PRINCIPAL in i&&(r=i[Kr.JSON_KEY_PRINCIPAL])}let n=r.toLowerCase().replace(/-/g,""),o=(0,Zm.decode)(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]===Wm}toUint8Array(){return this._arr}toHex(){return(0,Ym.bytesToHex)(this._arr).toUpperCase()}toText(){let e=new ArrayBuffer(4);new DataView(e).setUint32(0,(0,N2.getCrc32)(this._arr));let n=new Uint8Array(e),o=new Uint8Array([...n,...this._arr]),i=(0,Zm.encode)(o).match(/.{1,5}/g);if(!i)throw new Error;return i.join("-")}toString(){return this.toText()}toJSON(){return{[Kr.JSON_KEY_PRINCIPAL]: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"}};Kr.Principal=Dl});var Ir=Z(On=>{"use strict";var S2=On&&On.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),A2=On&&On.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&S2(e,t,r)};Object.defineProperty(On,"__esModule",{value:!0});On.getCrc32=void 0;A2(Xm(),On);var B2=vl();Object.defineProperty(On,"getCrc32",{enumerable:!0,get:function(){return B2.getCrc32}})});var sr=Z(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.UNREACHABLE_ERROR=k.ExpiryJsonDeserializeErrorCode=k.InvalidReadStateRequestErrorCode=k.MissingCanisterIdErrorCode=k.HttpFetchErrorCode=k.HttpV3ApiNotSupportedErrorCode=k.HttpErrorCode=k.HashTreeDecodeErrorCode=k.UnexpectedErrorCode=k.QuerySignatureVerificationFailedErrorCode=k.MalformedPublicKeyErrorCode=k.MissingSignatureErrorCode=k.MalformedSignatureErrorCode=k.CreateHttpAgentErrorCode=k.IngressExpiryInvalidErrorCode=k.IdentityInvalidErrorCode=k.HttpDefaultFetchErrorCode=k.HashValueErrorCode=k.MissingRootKeyErrorCode=k.RequestStatusDoneNoReplyErrorCode=k.UncertifiedRejectUpdateErrorCode=k.UncertifiedRejectErrorCode=k.CertifiedRejectErrorCode=k.CertificateOutdatedErrorCode=k.TimeoutWaitingForResponseErrorCode=k.HexDecodeErrorCode=k.CborEncodeErrorCode=k.CborDecodeErrorCode=k.DerEncodeErrorCode=k.DerDecodeErrorCode=k.DerDecodeLengthMismatchErrorCode=k.DerPrefixMismatchErrorCode=k.DerKeyLengthMismatchErrorCode=k.MissingLookupValueErrorCode=k.MalformedLookupFoundValueErrorCode=k.LookupErrorCode=k.CertificateNotAuthorizedErrorCode=k.CertificateHasTooManyDelegationsErrorCode=k.CertificateTimeErrorCode=k.CertificateVerificationErrorCode=k.UnknownError=k.InputError=k.LimitError=k.ExternalError=k.TransportError=k.RejectError=k.ProtocolError=k.TrustError=k.AgentError=k.ErrorKindEnum=void 0;var pr=dt(),Gr;(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"})(Gr||(k.ErrorKindEnum=Gr={}));var he=class{constructor(e=!1){this.isCertified=e}toString(){let e=this.toErrorMessage();return this.requestContext&&(e+=`
|
|
3
|
+
var U2=Object.create;var nf=Object.defineProperty;var V2=Object.getOwnPropertyDescriptor;var L2=Object.getOwnPropertyNames;var q2=Object.getPrototypeOf,M2=Object.prototype.hasOwnProperty;var k2=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Y=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),j2=(t,e)=>{for(var r in e)nf(t,r,{get:e[r],enumerable:!0})},H2=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of L2(e))!M2.call(t,s)&&s!==r&&nf(t,s,{get:()=>e[s],enumerable:!(n=V2(e,s))||n.enumerable});return t};var Fe=(t,e,r)=>(r=t!=null?U2(q2(t)):{},H2(e||!t||!t.__esModule?nf(r,"default",{value:t,enumerable:!0}):r,t));var sf=Y(Es=>{"use strict";Object.defineProperty(Es,"__esModule",{value:!0});Es.QueryResponseStatus=Es.ReplicaRejectCode=void 0;Es.isV2ResponseBody=$2;Es.isV3ResponseBody=K2;var Jm;(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"})(Jm||(Es.ReplicaRejectCode=Jm={}));var Qm;(function(t){t.Replied="replied",t.Rejected="rejected"})(Qm||(Es.QueryResponseStatus=Qm={}));function $2(t){return t!=null&&"reject_code"in t}function K2(t){return t!=null&&"certificate"in t}});var of=Y(ou=>{"use strict";Object.defineProperty(ou,"__esModule",{value:!0});ou.base32Encode=G2;ou.base32Decode=Z2;var su="abcdefghijklmnopqrstuvwxyz234567",ai=Object.create(null);for(let t=0;t<su.length;t++)ai[su[t]]=t;ai[0]=ai.o;ai[1]=ai.i;function G2(t){let e=0,r=0,n="";function s(o){return e<0?r|=o>>-e:r=o<<e&248,e>3?(e-=8,1):(e<4&&(n+=su[r>>3],e+=5),0)}for(let o=0;o<t.length;)o+=s(t[o]);return n+(e<0?su[r>>3]:"")}function Z2(t){let e=0,r=0,n=new Uint8Array(t.length*4/3|0),s=0;function o(i){let a=ai[i.toLowerCase()];if(a===void 0)throw new Error(`Invalid character: ${JSON.stringify(i)}`);a<<=3,r|=a>>>e,e+=5,e>=8&&(n[s++]=r,e-=8,e>0?r=a<<5-e&255:r=0)}for(let i of t)o(i);return n.slice(0,s)}});var cf=Y(af=>{"use strict";Object.defineProperty(af,"__esModule",{value:!0});af.getCrc32=Y2;var z2=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 Y2(t){let e=-1;for(let r=0;r<t.length;r++){let s=(t[r]^e)&255;e=z2[s]^e>>>8}return(e^-1)>>>0}});var ey=Y(iu=>{"use strict";Object.defineProperty(iu,"__esModule",{value:!0});iu.crypto=void 0;var Ts=k2("node:crypto");iu.crypto=Ts&&typeof Ts=="object"&&"webcrypto"in Ts?Ts.webcrypto:Ts&&typeof Ts=="object"&&"randomBytes"in Ts?Ts:void 0});var ht=Y(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.wrapXOFConstructorWithOpts=ee.wrapConstructorWithOpts=ee.wrapConstructor=ee.Hash=ee.nextTick=ee.swap32IfBE=ee.byteSwapIfBE=ee.swap8IfBE=ee.isLE=void 0;ee.isBytes=ry;ee.anumber=uf;ee.abytes=ui;ee.ahash=W2;ee.aexists=X2;ee.aoutput=J2;ee.u8=Q2;ee.u32=eE;ee.clean=tE;ee.createView=rE;ee.rotr=nE;ee.rotl=sE;ee.byteSwap=lf;ee.byteSwap32=ny;ee.bytesToHex=iE;ee.hexToBytes=aE;ee.asyncLoop=uE;ee.utf8ToBytes=ff;ee.bytesToUtf8=dE;ee.toBytes=au;ee.kdfInputToBytes=lE;ee.concatBytes=fE;ee.checkOpts=pE;ee.createHasher=oy;ee.createOptHasher=iy;ee.createXOFer=ay;ee.randomBytes=hE;var ci=ey();function ry(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function uf(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function ui(t,...e){if(!ry(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function W2(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");uf(t.outputLen),uf(t.blockLen)}function X2(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function J2(t,e){ui(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Q2(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function eE(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function tE(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function rE(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function nE(t,e){return t<<32-e|t>>>e}function sE(t,e){return t<<e|t>>>32-e>>>0}ee.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function lf(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}ee.swap8IfBE=ee.isLE?t=>t:t=>lf(t);ee.byteSwapIfBE=ee.swap8IfBE;function ny(t){for(let e=0;e<t.length;e++)t[e]=lf(t[e]);return t}ee.swap32IfBE=ee.isLE?t=>t:ny;var sy=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",oE=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function iE(t){if(ui(t),sy)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=oE[t[r]];return e}var Cn={_0:48,_9:57,A:65,F:70,a:97,f:102};function ty(t){if(t>=Cn._0&&t<=Cn._9)return t-Cn._0;if(t>=Cn.A&&t<=Cn.F)return t-(Cn.A-10);if(t>=Cn.a&&t<=Cn.f)return t-(Cn.a-10)}function aE(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(sy)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=ty(t.charCodeAt(o)),a=ty(t.charCodeAt(o+1));if(i===void 0||a===void 0){let c=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}var cE=async()=>{};ee.nextTick=cE;async function uE(t,e,r){let n=Date.now();for(let s=0;s<t;s++){r(s);let o=Date.now()-n;o>=0&&o<e||(await(0,ee.nextTick)(),n+=o)}}function ff(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function dE(t){return new TextDecoder().decode(t)}function au(t){return typeof t=="string"&&(t=ff(t)),ui(t),t}function lE(t){return typeof t=="string"&&(t=ff(t)),ui(t),t}function fE(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];ui(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function pE(t,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(t,e)}var df=class{};ee.Hash=df;function oy(t){let e=n=>t().update(au(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function iy(t){let e=(n,s)=>t(s).update(au(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}function ay(t){let e=(n,s)=>t(s).update(au(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}ee.wrapConstructor=oy;ee.wrapConstructorWithOpts=iy;ee.wrapXOFConstructorWithOpts=ay;function hE(t=32){if(ci.crypto&&typeof ci.crypto.getRandomValues=="function")return ci.crypto.getRandomValues(new Uint8Array(t));if(ci.crypto&&typeof ci.crypto.randomBytes=="function")return Uint8Array.from(ci.crypto.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}});var uy=Y(Ht=>{"use strict";Object.defineProperty(Ht,"__esModule",{value:!0});Ht.SHA512_IV=Ht.SHA384_IV=Ht.SHA224_IV=Ht.SHA256_IV=Ht.HashMD=void 0;Ht.setBigUint64=cy;Ht.Chi=mE;Ht.Maj=yE;var Qr=ht();function cy(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),a=Number(r&o),c=n?4:0,d=n?0:4;t.setUint32(e+c,i,n),t.setUint32(e+d,a,n)}function mE(t,e,r){return t&e^~t&r}function yE(t,e,r){return t&e^t&r^e&r}var pf=class extends Qr.Hash{constructor(e,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=(0,Qr.createView)(this.buffer)}update(e){(0,Qr.aexists)(this),e=(0,Qr.toBytes)(e),(0,Qr.abytes)(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=(0,Qr.createView)(e);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){(0,Qr.aexists)(this),(0,Qr.aoutput)(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,(0,Qr.clean)(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let l=i;l<s;l++)r[l]=0;cy(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=(0,Qr.createView)(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=c/4,f=this.get();if(d>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)a.setUint32(4*l,f[l],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=o,e.length=s,e.pos=a,s%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}};Ht.HashMD=pf;Ht.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);Ht.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);Ht.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]);Ht.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])});var By=Y(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.toBig=ce.shrSL=ce.shrSH=ce.rotrSL=ce.rotrSH=ce.rotrBL=ce.rotrBH=ce.rotr32L=ce.rotr32H=ce.rotlSL=ce.rotlSH=ce.rotlBL=ce.rotlBH=ce.add5L=ce.add5H=ce.add4L=ce.add4H=ce.add3L=ce.add3H=void 0;ce.add=Oy;ce.fromBig=mf;ce.split=dy;var cu=BigInt(2**32-1),hf=BigInt(32);function mf(t,e=!1){return e?{h:Number(t&cu),l:Number(t>>hf&cu)}:{h:Number(t>>hf&cu)|0,l:Number(t&cu)|0}}function dy(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=mf(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var ly=(t,e)=>BigInt(t>>>0)<<hf|BigInt(e>>>0);ce.toBig=ly;var fy=(t,e,r)=>t>>>r;ce.shrSH=fy;var py=(t,e,r)=>t<<32-r|e>>>r;ce.shrSL=py;var hy=(t,e,r)=>t>>>r|e<<32-r;ce.rotrSH=hy;var my=(t,e,r)=>t<<32-r|e>>>r;ce.rotrSL=my;var yy=(t,e,r)=>t<<64-r|e>>>r-32;ce.rotrBH=yy;var _y=(t,e,r)=>t>>>r-32|e<<64-r;ce.rotrBL=_y;var by=(t,e)=>e;ce.rotr32H=by;var gy=(t,e)=>t;ce.rotr32L=gy;var xy=(t,e,r)=>t<<r|e>>>32-r;ce.rotlSH=xy;var wy=(t,e,r)=>e<<r|t>>>32-r;ce.rotlSL=wy;var Ey=(t,e,r)=>e<<r-32|t>>>64-r;ce.rotlBH=Ey;var Ty=(t,e,r)=>t<<r-32|e>>>64-r;ce.rotlBL=Ty;function Oy(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Ny=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0);ce.add3L=Ny;var vy=(t,e,r,n)=>e+r+n+(t/2**32|0)|0;ce.add3H=vy;var Ry=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0);ce.add4L=Ry;var Iy=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0;ce.add4H=Iy;var Sy=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0);ce.add5L=Sy;var Ay=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;ce.add5H=Ay;var _E={fromBig:mf,split:dy,toBig:ly,shrSH:fy,shrSL:py,rotrSH:hy,rotrSL:my,rotrBH:yy,rotrBL:_y,rotr32H:by,rotr32L:gy,rotlSH:xy,rotlSL:wy,rotlBH:Ey,rotlBL:Ty,add:Oy,add3L:Ny,add3H:vy,add4L:Ry,add4H:Iy,add5H:Ay,add5L:Sy};ce.default=_E});var di=Y(Le=>{"use strict";Object.defineProperty(Le,"__esModule",{value:!0});Le.sha512_224=Le.sha512_256=Le.sha384=Le.sha512=Le.sha224=Le.sha256=Le.SHA512_256=Le.SHA512_224=Le.SHA384=Le.SHA512=Le.SHA224=Le.SHA256=void 0;var Q=uy(),ye=By(),rt=ht(),bE=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Os=new Uint32Array(64),wa=class extends Q.HashMD{constructor(e=32){super(64,e,8,!1),this.A=Q.SHA256_IV[0]|0,this.B=Q.SHA256_IV[1]|0,this.C=Q.SHA256_IV[2]|0,this.D=Q.SHA256_IV[3]|0,this.E=Q.SHA256_IV[4]|0,this.F=Q.SHA256_IV[5]|0,this.G=Q.SHA256_IV[6]|0,this.H=Q.SHA256_IV[7]|0}get(){let{A:e,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,r,n,s,o,i,a,c]}set(e,r,n,s,o,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)Os[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let u=Os[l-15],p=Os[l-2],h=(0,rt.rotr)(u,7)^(0,rt.rotr)(u,18)^u>>>3,m=(0,rt.rotr)(p,17)^(0,rt.rotr)(p,19)^p>>>10;Os[l]=m+Os[l-7]+h+Os[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:d,H:f}=this;for(let l=0;l<64;l++){let u=(0,rt.rotr)(a,6)^(0,rt.rotr)(a,11)^(0,rt.rotr)(a,25),p=f+u+(0,Q.Chi)(a,c,d)+bE[l]+Os[l]|0,m=((0,rt.rotr)(n,2)^(0,rt.rotr)(n,13)^(0,rt.rotr)(n,22))+(0,Q.Maj)(n,s,o)|0;f=d,d=c,c=a,a=i+p|0,i=o,o=s,s=n,n=p+m|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,d=d+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,d,f)}roundClean(){(0,rt.clean)(Os)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,rt.clean)(this.buffer)}};Le.SHA256=wa;var uu=class extends wa{constructor(){super(28),this.A=Q.SHA224_IV[0]|0,this.B=Q.SHA224_IV[1]|0,this.C=Q.SHA224_IV[2]|0,this.D=Q.SHA224_IV[3]|0,this.E=Q.SHA224_IV[4]|0,this.F=Q.SHA224_IV[5]|0,this.G=Q.SHA224_IV[6]|0,this.H=Q.SHA224_IV[7]|0}};Le.SHA224=uu;var Cy=ye.split(["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))),gE=Cy[0],xE=Cy[1],Ns=new Uint32Array(80),vs=new Uint32Array(80),lo=class extends Q.HashMD{constructor(e=64){super(128,e,16,!1),this.Ah=Q.SHA512_IV[0]|0,this.Al=Q.SHA512_IV[1]|0,this.Bh=Q.SHA512_IV[2]|0,this.Bl=Q.SHA512_IV[3]|0,this.Ch=Q.SHA512_IV[4]|0,this.Cl=Q.SHA512_IV[5]|0,this.Dh=Q.SHA512_IV[6]|0,this.Dl=Q.SHA512_IV[7]|0,this.Eh=Q.SHA512_IV[8]|0,this.El=Q.SHA512_IV[9]|0,this.Fh=Q.SHA512_IV[10]|0,this.Fl=Q.SHA512_IV[11]|0,this.Gh=Q.SHA512_IV[12]|0,this.Gl=Q.SHA512_IV[13]|0,this.Hh=Q.SHA512_IV[14]|0,this.Hl=Q.SHA512_IV[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:d,El:f,Fh:l,Fl:u,Gh:p,Gl:h,Hh:m,Hl:b}=this;return[e,r,n,s,o,i,a,c,d,f,l,u,p,h,m,b]}set(e,r,n,s,o,i,a,c,d,f,l,u,p,h,m,b){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=d|0,this.El=f|0,this.Fh=l|0,this.Fl=u|0,this.Gh=p|0,this.Gl=h|0,this.Hh=m|0,this.Hl=b|0}process(e,r){for(let _=0;_<16;_++,r+=4)Ns[_]=e.getUint32(r),vs[_]=e.getUint32(r+=4);for(let _=16;_<80;_++){let T=Ns[_-15]|0,N=vs[_-15]|0,v=ye.rotrSH(T,N,1)^ye.rotrSH(T,N,8)^ye.shrSH(T,N,7),R=ye.rotrSL(T,N,1)^ye.rotrSL(T,N,8)^ye.shrSL(T,N,7),A=Ns[_-2]|0,E=vs[_-2]|0,S=ye.rotrSH(A,E,19)^ye.rotrBH(A,E,61)^ye.shrSH(A,E,6),U=ye.rotrSL(A,E,19)^ye.rotrBL(A,E,61)^ye.shrSL(A,E,6),C=ye.add4L(R,U,vs[_-7],vs[_-16]),g=ye.add4H(C,v,S,Ns[_-7],Ns[_-16]);Ns[_]=g|0,vs[_]=C|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:d,Dl:f,Eh:l,El:u,Fh:p,Fl:h,Gh:m,Gl:b,Hh:y,Hl:x}=this;for(let _=0;_<80;_++){let T=ye.rotrSH(l,u,14)^ye.rotrSH(l,u,18)^ye.rotrBH(l,u,41),N=ye.rotrSL(l,u,14)^ye.rotrSL(l,u,18)^ye.rotrBL(l,u,41),v=l&p^~l&m,R=u&h^~u&b,A=ye.add5L(x,N,R,xE[_],vs[_]),E=ye.add5H(A,y,T,v,gE[_],Ns[_]),S=A|0,U=ye.rotrSH(n,s,28)^ye.rotrBH(n,s,34)^ye.rotrBH(n,s,39),C=ye.rotrSL(n,s,28)^ye.rotrBL(n,s,34)^ye.rotrBL(n,s,39),g=n&o^n&a^o&a,w=s&i^s&c^i&c;y=m|0,x=b|0,m=p|0,b=h|0,p=l|0,h=u|0,{h:l,l:u}=ye.add(d|0,f|0,E|0,S|0),d=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let O=ye.add3L(S,C,w);n=ye.add3H(O,E,U,g),s=O|0}({h:n,l:s}=ye.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=ye.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=ye.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:d,l:f}=ye.add(this.Dh|0,this.Dl|0,d|0,f|0),{h:l,l:u}=ye.add(this.Eh|0,this.El|0,l|0,u|0),{h:p,l:h}=ye.add(this.Fh|0,this.Fl|0,p|0,h|0),{h:m,l:b}=ye.add(this.Gh|0,this.Gl|0,m|0,b|0),{h:y,l:x}=ye.add(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,s,o,i,a,c,d,f,l,u,p,h,m,b,y,x)}roundClean(){(0,rt.clean)(Ns,vs)}destroy(){(0,rt.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};Le.SHA512=lo;var du=class extends lo{constructor(){super(48),this.Ah=Q.SHA384_IV[0]|0,this.Al=Q.SHA384_IV[1]|0,this.Bh=Q.SHA384_IV[2]|0,this.Bl=Q.SHA384_IV[3]|0,this.Ch=Q.SHA384_IV[4]|0,this.Cl=Q.SHA384_IV[5]|0,this.Dh=Q.SHA384_IV[6]|0,this.Dl=Q.SHA384_IV[7]|0,this.Eh=Q.SHA384_IV[8]|0,this.El=Q.SHA384_IV[9]|0,this.Fh=Q.SHA384_IV[10]|0,this.Fl=Q.SHA384_IV[11]|0,this.Gh=Q.SHA384_IV[12]|0,this.Gl=Q.SHA384_IV[13]|0,this.Hh=Q.SHA384_IV[14]|0,this.Hl=Q.SHA384_IV[15]|0}};Le.SHA384=du;var Bt=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),Ct=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]),lu=class extends lo{constructor(){super(28),this.Ah=Bt[0]|0,this.Al=Bt[1]|0,this.Bh=Bt[2]|0,this.Bl=Bt[3]|0,this.Ch=Bt[4]|0,this.Cl=Bt[5]|0,this.Dh=Bt[6]|0,this.Dl=Bt[7]|0,this.Eh=Bt[8]|0,this.El=Bt[9]|0,this.Fh=Bt[10]|0,this.Fl=Bt[11]|0,this.Gh=Bt[12]|0,this.Gl=Bt[13]|0,this.Hh=Bt[14]|0,this.Hl=Bt[15]|0}};Le.SHA512_224=lu;var fu=class extends lo{constructor(){super(32),this.Ah=Ct[0]|0,this.Al=Ct[1]|0,this.Bh=Ct[2]|0,this.Bl=Ct[3]|0,this.Ch=Ct[4]|0,this.Cl=Ct[5]|0,this.Dh=Ct[6]|0,this.Dl=Ct[7]|0,this.Eh=Ct[8]|0,this.El=Ct[9]|0,this.Fh=Ct[10]|0,this.Fl=Ct[11]|0,this.Gh=Ct[12]|0,this.Gl=Ct[13]|0,this.Hh=Ct[14]|0,this.Hl=Ct[15]|0}};Le.SHA512_256=fu;Le.sha256=(0,rt.createHasher)(()=>new wa);Le.sha224=(0,rt.createHasher)(()=>new uu);Le.sha512=(0,rt.createHasher)(()=>new lo);Le.sha384=(0,rt.createHasher)(()=>new du);Le.sha512_256=(0,rt.createHasher)(()=>new fu);Le.sha512_224=(0,rt.createHasher)(()=>new lu)});var Uy=Y(en=>{"use strict";Object.defineProperty(en,"__esModule",{value:!0});en.Principal=en.JSON_KEY_PRINCIPAL=void 0;var Py=of(),wE=cf(),EE=di(),Dy=ht();en.JSON_KEY_PRINCIPAL="__principal__";var TE=2,Fy=4,OE="aaaaa-aa",yf=class t{static anonymous(){return new this(new Uint8Array([Fy]))}static managementCanister(){return this.fromText(OE)}static selfAuthenticating(e){let r=(0,EE.sha224)(e);return new this(new Uint8Array([...r,TE]))}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((0,Dy.hexToBytes)(e))}static fromText(e){let r=e;if(e.includes(en.JSON_KEY_PRINCIPAL)){let i=JSON.parse(e);en.JSON_KEY_PRINCIPAL in i&&(r=i[en.JSON_KEY_PRINCIPAL])}let n=r.toLowerCase().replace(/-/g,""),s=(0,Py.base32Decode)(n);s=s.slice(4,s.length);let o=new this(s);if(o.toText()!==r)throw new Error(`Principal "${o.toText()}" does not have a valid checksum (original value "${r}" may not be a valid Principal ID).`);return o}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]===Fy}toUint8Array(){return this._arr}toHex(){return(0,Dy.bytesToHex)(this._arr).toUpperCase()}toText(){let e=new ArrayBuffer(4);new DataView(e).setUint32(0,(0,wE.getCrc32)(this._arr));let n=new Uint8Array(e),s=new Uint8Array([...n,...this._arr]),i=(0,Py.base32Encode)(s).match(/.{1,5}/g);if(!i)throw new Error;return i.join("-")}toString(){return this.toText()}toJSON(){return{[en.JSON_KEY_PRINCIPAL]: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"}};en.Principal=yf});var Ur=Y(mr=>{"use strict";var NE=mr&&mr.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),vE=mr&&mr.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&NE(e,t,r)};Object.defineProperty(mr,"__esModule",{value:!0});mr.base32Decode=mr.base32Encode=mr.getCrc32=void 0;vE(Uy(),mr);var RE=cf();Object.defineProperty(mr,"getCrc32",{enumerable:!0,get:function(){return RE.getCrc32}});var Vy=of();Object.defineProperty(mr,"base32Encode",{enumerable:!0,get:function(){return Vy.base32Encode}});Object.defineProperty(mr,"base32Decode",{enumerable:!0,get:function(){return Vy.base32Decode}})});var yr=Y(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.UNREACHABLE_ERROR=k.ExpiryJsonDeserializeErrorCode=k.InvalidReadStateRequestErrorCode=k.MissingCanisterIdErrorCode=k.HttpFetchErrorCode=k.HttpV3ApiNotSupportedErrorCode=k.HttpErrorCode=k.HashTreeDecodeErrorCode=k.UnexpectedErrorCode=k.QuerySignatureVerificationFailedErrorCode=k.MalformedPublicKeyErrorCode=k.MissingSignatureErrorCode=k.MalformedSignatureErrorCode=k.CreateHttpAgentErrorCode=k.IngressExpiryInvalidErrorCode=k.IdentityInvalidErrorCode=k.HttpDefaultFetchErrorCode=k.HashValueErrorCode=k.MissingRootKeyErrorCode=k.RequestStatusDoneNoReplyErrorCode=k.UncertifiedRejectUpdateErrorCode=k.UncertifiedRejectErrorCode=k.CertifiedRejectErrorCode=k.CertificateOutdatedErrorCode=k.TimeoutWaitingForResponseErrorCode=k.HexDecodeErrorCode=k.CborEncodeErrorCode=k.CborDecodeErrorCode=k.DerEncodeErrorCode=k.DerDecodeErrorCode=k.DerDecodeLengthMismatchErrorCode=k.DerPrefixMismatchErrorCode=k.DerKeyLengthMismatchErrorCode=k.MissingLookupValueErrorCode=k.MalformedLookupFoundValueErrorCode=k.LookupErrorCode=k.CertificateNotAuthorizedErrorCode=k.CertificateHasTooManyDelegationsErrorCode=k.CertificateTimeErrorCode=k.CertificateVerificationErrorCode=k.UnknownError=k.InputError=k.LimitError=k.ExternalError=k.TransportError=k.RejectError=k.ProtocolError=k.TrustError=k.AgentError=k.ErrorKindEnum=void 0;var Er=ht(),tn;(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"})(tn||(k.ErrorKindEnum=tn={}));var pe=class{constructor(e=!1){this.isCertified=e}toString(){let e=this.toErrorMessage();return this.requestContext&&(e+=`
|
|
4
4
|
Request context:
|
|
5
|
-
Request ID (hex): ${this.requestContext.requestId?(0,
|
|
6
|
-
Sender pubkey (hex): ${(0,
|
|
7
|
-
Sender signature (hex): ${(0,
|
|
5
|
+
Request ID (hex): ${this.requestContext.requestId?(0,Er.bytesToHex)(this.requestContext.requestId):"undefined"}
|
|
6
|
+
Sender pubkey (hex): ${(0,Er.bytesToHex)(this.requestContext.senderPubKey)}
|
|
7
|
+
Sender signature (hex): ${(0,Er.bytesToHex)(this.requestContext.senderSignature)}
|
|
8
8
|
Ingress expiry: ${this.requestContext.ingressExpiry.toString()}`),this.callContext&&(e+=`
|
|
9
9
|
Call context:
|
|
10
10
|
Canister ID: ${this.callContext.canisterId.toText()}
|
|
11
11
|
Method name: ${this.callContext.methodName}
|
|
12
|
-
HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),e}},
|
|
13
|
-
`;return this.requestId&&(e+=` Request ID: ${(0,
|
|
12
|
+
HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),e}},pu=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}`}};k.AgentError=pu;var rn=class extends pu{static fromCode(e){return new this(e)}},_f=class t extends rn{constructor(e){super(e,tn.Trust),this.name="TrustError",Object.setPrototypeOf(this,t.prototype)}};k.TrustError=_f;var bf=class t extends rn{constructor(e){super(e,tn.Protocol),this.name="ProtocolError",Object.setPrototypeOf(this,t.prototype)}};k.ProtocolError=bf;var gf=class t extends rn{constructor(e){super(e,tn.Reject),this.name="RejectError",Object.setPrototypeOf(this,t.prototype)}};k.RejectError=gf;var xf=class t extends rn{constructor(e){super(e,tn.Transport),this.name="TransportError",Object.setPrototypeOf(this,t.prototype)}};k.TransportError=xf;var wf=class t extends rn{constructor(e){super(e,tn.External),this.name="ExternalError",Object.setPrototypeOf(this,t.prototype)}};k.ExternalError=wf;var Ef=class t extends rn{constructor(e){super(e,tn.Limit),this.name="LimitError",Object.setPrototypeOf(this,t.prototype)}};k.LimitError=Ef;var Tf=class t extends rn{constructor(e){super(e,tn.Input),this.name="InputError",Object.setPrototypeOf(this,t.prototype)}};k.InputError=Tf;var Of=class t extends rn{constructor(e){super(e,tn.Unknown),this.name="UnknownError",Object.setPrototypeOf(this,t.prototype)}};k.UnknownError=Of;var Nf=class t extends pe{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+=`: ${Ea(this.error)}`),`Certificate verification error: "${e}"`}};k.CertificateVerificationErrorCode=Nf;var vf=class t extends pe{constructor(e,r,n,s,o){super(),this.maxAgeInMinutes=e,this.certificateTime=r,this.currentTime=n,this.timeDiffMsecs=s,this.ageType=o,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`}};k.CertificateTimeErrorCode=vf;var Rf=class t extends pe{constructor(){super(),this.name="CertificateHasTooManyDelegationsErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Certificate has too many delegations"}};k.CertificateHasTooManyDelegationsErrorCode=Rf;var If=class t extends pe{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()}`}};k.CertificateNotAuthorizedErrorCode=If;var Sf=class t extends pe{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}`}};k.LookupErrorCode=Sf;var Af=class t extends pe{constructor(e){super(),this.message=e,this.name="MalformedLookupFoundValueErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return this.message}};k.MalformedLookupFoundValueErrorCode=Af;var Bf=class t extends pe{constructor(e){super(),this.message=e,this.name="MissingLookupValueErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return this.message}};k.MissingLookupValueErrorCode=Bf;var Cf=class t extends pe{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`}};k.DerKeyLengthMismatchErrorCode=Cf;var Pf=class t extends pe{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: ${(0,Er.bytesToHex)(this.expectedPrefix)}, but got ${(0,Er.bytesToHex)(this.actualPrefix)}`}};k.DerPrefixMismatchErrorCode=Pf;var Df=class t extends pe{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}`}};k.DerDecodeLengthMismatchErrorCode=Df;var Ff=class t extends pe{constructor(e){super(),this.error=e,this.name="DerDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode DER: ${this.error}`}};k.DerDecodeErrorCode=Ff;var Uf=class t extends pe{constructor(e){super(),this.error=e,this.name="DerEncodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to encode DER: ${this.error}`}};k.DerEncodeErrorCode=Uf;var Vf=class t extends pe{constructor(e,r){super(),this.error=e,this.input=r,this.name="CborDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode CBOR: ${Ea(this.error)}, input: ${(0,Er.bytesToHex)(this.input)}`}};k.CborDecodeErrorCode=Vf;var Lf=class t extends pe{constructor(e,r){super(),this.error=e,this.value=r,this.name="CborEncodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to encode CBOR: ${Ea(this.error)}, input: ${this.value}`}};k.CborEncodeErrorCode=Lf;var qf=class t extends pe{constructor(e){super(),this.error=e,this.name="HexDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode hex: ${this.error}`}};k.HexDecodeErrorCode=qf;var Mf=class t extends pe{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}
|
|
13
|
+
`;return this.requestId&&(e+=` Request ID: ${(0,Er.bytesToHex)(this.requestId)}
|
|
14
14
|
`),this.status&&(e+=` Request status: ${this.status}
|
|
15
|
-
`),e}};k.TimeoutWaitingForResponseErrorCode=
|
|
16
|
-
Request ID: ${(0,
|
|
17
|
-
`;return this.retryTimes!==void 0&&(e+=` Retried ${this.retryTimes} times.`),e}};k.CertificateOutdatedErrorCode=
|
|
18
|
-
Request ID: ${(0,
|
|
15
|
+
`),e}};k.TimeoutWaitingForResponseErrorCode=Mf;var kf=class t extends pe{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?
|
|
16
|
+
Request ID: ${(0,Er.bytesToHex)(this.requestId)}
|
|
17
|
+
`;return this.retryTimes!==void 0&&(e+=` Retried ${this.retryTimes} times.`),e}};k.CertificateOutdatedErrorCode=kf;var jf=class t extends pe{constructor(e,r,n,s){super(!0),this.requestId=e,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=s,this.name="CertifiedRejectErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The replica returned a rejection error:
|
|
18
|
+
Request ID: ${(0,Er.bytesToHex)(this.requestId)}
|
|
19
19
|
Reject code: ${this.rejectCode}
|
|
20
20
|
Reject text: ${this.rejectMessage}
|
|
21
21
|
Error code: ${this.rejectErrorCode}
|
|
22
|
-
`}};k.CertifiedRejectErrorCode=
|
|
23
|
-
Request ID: ${(0,
|
|
22
|
+
`}};k.CertifiedRejectErrorCode=jf;var Hf=class t extends pe{constructor(e,r,n,s,o){super(),this.requestId=e,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=s,this.signatures=o,this.name="UncertifiedRejectErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The replica returned a rejection error:
|
|
23
|
+
Request ID: ${(0,Er.bytesToHex)(this.requestId)}
|
|
24
24
|
Reject code: ${this.rejectCode}
|
|
25
25
|
Reject text: ${this.rejectMessage}
|
|
26
26
|
Error code: ${this.rejectErrorCode}
|
|
27
|
-
`}};k.UncertifiedRejectErrorCode=
|
|
28
|
-
Request ID: ${(0,
|
|
27
|
+
`}};k.UncertifiedRejectErrorCode=Hf;var $f=class t extends pe{constructor(e,r,n,s){super(),this.requestId=e,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=s,this.name="UncertifiedRejectUpdateErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The replica returned a rejection error:
|
|
28
|
+
Request ID: ${(0,Er.bytesToHex)(this.requestId)}
|
|
29
29
|
Reject code: ${this.rejectCode}
|
|
30
30
|
Reject text: ${this.rejectMessage}
|
|
31
31
|
Error code: ${this.rejectErrorCode}
|
|
32
|
-
`}};k.UncertifiedRejectUpdateErrorCode
|
|
33
|
-
Request ID: ${(0,
|
|
34
|
-
`}};k.RequestStatusDoneNoReplyErrorCode=
|
|
32
|
+
`}};k.UncertifiedRejectUpdateErrorCode=$f;var Kf=class t extends pe{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:
|
|
33
|
+
Request ID: ${(0,Er.bytesToHex)(this.requestId)}
|
|
34
|
+
`}};k.RequestStatusDoneNoReplyErrorCode=Kf;var Gf=class t extends pe{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.`}};k.MissingRootKeyErrorCode=Gf;var Zf=class t extends pe{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}`}};k.HashValueErrorCode=Zf;var zf=class t extends pe{constructor(e){super(),this.error=e,this.name="HttpDefaultFetchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return this.error}};k.HttpDefaultFetchErrorCode=zf;var Yf=class t extends pe{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."}};k.IdentityInvalidErrorCode=Yf;var Wf=class t extends pe{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.`}};k.IngressExpiryInvalidErrorCode=Wf;var Xf=class t extends pe{constructor(){super(),this.name="CreateHttpAgentErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Failed to create agent from provided agent"}};k.CreateHttpAgentErrorCode=Xf;var Jf=class t extends pe{constructor(e){super(),this.error=e,this.name="MalformedSignatureErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Query response contained a malformed signature: ${this.error}`}};k.MalformedSignatureErrorCode=Jf;var Qf=class t extends pe{constructor(){super(),this.name="MissingSignatureErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Query response did not contain any node signatures"}};k.MissingSignatureErrorCode=Qf;var ep=class t extends pe{constructor(){super(),this.name="MalformedPublicKeyErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Read state response contained a malformed public key"}};k.MalformedPublicKeyErrorCode=ep;var tp=class t extends pe{constructor(e){super(),this.nodeId=e,this.name="QuerySignatureVerificationFailedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Query signature verification failed. Node ID: ${this.nodeId}`}};k.QuerySignatureVerificationFailedErrorCode=tp;var rp=class t extends pe{constructor(e){super(),this.error=e,this.name="UnexpectedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Unexpected error: ${Ea(this.error)}`}};k.UnexpectedErrorCode=rp;var np=class t extends pe{constructor(e){super(),this.error=e,this.name="HashTreeDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode certificate: ${this.error}`}};k.HashTreeDecodeErrorCode=np;var sp=class t extends pe{constructor(e,r,n,s){super(),this.status=e,this.statusText=r,this.headers=n,this.bodyText=s,this.name="HttpErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){let e=`HTTP request failed:
|
|
35
35
|
Status: ${this.status} (${this.statusText})
|
|
36
36
|
Headers: ${JSON.stringify(this.headers)}
|
|
37
37
|
`;return this.bodyText&&(e+=` Body: ${this.bodyText}
|
|
38
|
-
`),e}};k.HttpErrorCode=Tf;var Of=class t extends he{constructor(){super(),this.name="HttpV3ApiNotSupportedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"HTTP request failed: v3 API is not supported"}};k.HttpV3ApiNotSupportedErrorCode=Of;var Nf=class t extends he{constructor(e){super(),this.error=e,this.name="HttpFetchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to fetch HTTP request: ${ta(this.error)}`}};k.HttpFetchErrorCode=Nf;var vf=class t extends he{constructor(e){super(),this.receivedCanisterId=e,this.name="MissingCanisterIdErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Canister ID is required, but received ${typeof this.receivedCanisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`}};k.MissingCanisterIdErrorCode=vf;var If=class t extends he{constructor(e){super(),this.request=e,this.name="InvalidReadStateRequestErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Invalid read state request: ${this.request}`}};k.InvalidReadStateRequestErrorCode=If;var Rf=class t extends he{constructor(e){super(),this.error=e,this.name="ExpiryJsonDeserializeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to deserialize expiry: ${this.error}`}};k.ExpiryJsonDeserializeErrorCode=Rf;function ta(t){if(t instanceof Error)return t.stack??t.message;try{return JSON.stringify(t)}catch{return String(t)}}k.UNREACHABLE_ERROR=new Error("unreachable")});var $c=Z(Nn=>{"use strict";Object.defineProperty(Nn,"__esModule",{value:!0});Nn.PipeArrayBuffer=void 0;Nn.concat=C2;Nn.uint8FromBufLike=Af;Nn.compare=Jm;Nn.uint8Equals=P2;Nn.uint8ToDataView=D2;function C2(...t){let e=new Uint8Array(t.reduce((n,o)=>n+o.byteLength,0)),r=0;for(let n of t)e.set(n,r),r+=n.byteLength;return e}var Sf=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=Af(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}};Nn.PipeArrayBuffer=Sf;function Af(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?Af(t.buffer):new Uint8Array(t)}function Jm(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 P2(t,e){return Jm(t,e)===0}function D2(t){if(!(t instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(t.buffer,t.byteOffset,t.byteLength)}});var Cf=Z(Bf=>{"use strict";Object.defineProperty(Bf,"__esModule",{value:!0});Bf.idlLabelToId=V2;function F2(t){let r=new TextEncoder().encode(t),n=0;for(let o of r)n=(n*223+o)%2**32;return n}function V2(t){if(/^_\d+_$/.test(t)||/^_0x[0-9a-fA-F]+_$/.test(t)){let e=+t.slice(1,-1);if(Number.isSafeInteger(e)&&e>=0&&e<2**32)return e}return F2(t)}});var Pf=Z(Kc=>{"use strict";Object.defineProperty(Kc,"__esModule",{value:!0});Kc.ilog2=U2;Kc.iexp2=L2;function U2(t){let e=BigInt(t);if(t<=0)throw new RangeError("Input must be positive");return e.toString(2).length-1}function L2(t){let e=BigInt(t);if(t<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<e}});var Ff=Z(hr=>{"use strict";Object.defineProperty(hr,"__esModule",{value:!0});hr.safeRead=ty;hr.safeReadUint8=Gc;hr.lebEncode=q2;hr.lebDecode=ry;hr.slebEncode=M2;hr.slebDecode=k2;hr.writeUIntLE=j2;hr.writeIntLE=ny;hr.readUIntLE=oy;hr.readIntLE=H2;var Df=$c(),Qm=Pf();function ey(){throw new Error("unexpected end of buffer")}function ty(t,e){return t.byteLength<e&&ey(),t.read(e)}function Gc(t){let e=t.readUint8();return e===void 0&&ey(),e}function q2(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:(0,Qm.ilog2)(t))+1,r=new Df.PipeArrayBuffer(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 ry(t){let e=BigInt(1),r=BigInt(0),n;do n=Gc(t),r+=BigInt(n&127).valueOf()*e,e*=BigInt(128);while(n>=128);return r}function M2(t){typeof t=="number"&&(t=BigInt(t));let e=t<BigInt(0);e&&(t=-t-BigInt(1));let r=(t===BigInt(0)?0:(0,Qm.ilog2)(t))+1,n=new Df.PipeArrayBuffer(new Uint8Array(r),0);for(;;){let s=o(t);if(t/=BigInt(128),e&&t===BigInt(0)&&(s&64)!==0||!e&&t===BigInt(0)&&(s&64)===0){n.write(new Uint8Array([s]));break}else n.write(new Uint8Array([s|128]))}function o(s){let i=s%BigInt(128);return Number(e?BigInt(128)-i-BigInt(1):i)}return n.buffer}function k2(t){let e=new Uint8Array(t.buffer),r=0;for(;r<e.byteLength;r++)if(e[r]<128){if((e[r]&64)===0)return ry(t);break}let n=new Uint8Array(ty(t,r+1)),o=BigInt(0);for(let s=n.byteLength-1;s>=0;s--)o=o*BigInt(128)+BigInt(128-(n[s]&127)-1);return-o-BigInt(1)}function j2(t,e){if(BigInt(t)<BigInt(0))throw new Error("Cannot write negative values.");return ny(t,e)}function ny(t,e){t=BigInt(t);let r=new Df.PipeArrayBuffer(new Uint8Array(Math.min(1,e)),0),n=0,o=BigInt(256),s=BigInt(0),i=Number(t%o);for(r.write(new Uint8Array([i]));++n<e;)t<0&&s===BigInt(0)&&i!==0&&(s=BigInt(1)),i=Number((t/o-s)%BigInt(256)),r.write(new Uint8Array([i])),o*=BigInt(256);return r.buffer}function oy(t,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let r=BigInt(Gc(t)),n=BigInt(1),o=0;for(;++o<e;){n*=BigInt(256);let s=BigInt(Gc(t));r=r+n*s}return r}function H2(t,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let r=oy(t,e),n=BigInt(2)**(BigInt(8)*BigInt(e-1)+BigInt(7));return r>=n&&(r-=n*BigInt(2)),r}});var Hf=Z(M=>{"use strict";Object.defineProperty(M,"__esModule",{value:!0});M.Principal=M.Nat64=M.Nat32=M.Nat16=M.Nat8=M.Int64=M.Int32=M.Int16=M.Int8=M.Float64=M.Float32=M.Nat=M.Int=M.Text=M.Null=M.Bool=M.Unknown=M.Reserved=M.Empty=M.ServiceClass=M.FuncClass=M.PrincipalClass=M.RecClass=M.VariantClass=M.TupleClass=M.RecordClass=M.OptClass=M.VecClass=M.FixedNatClass=M.FixedIntClass=M.FloatClass=M.NatClass=M.IntClass=M.TextClass=M.ReservedClass=M.NullClass=M.BoolClass=M.UnknownClass=M.EmptyClass=M.ConstructType=M.PrimitiveType=M.Type=M.Visitor=void 0;M.encode=K2;M.decode=G2;M.Tuple=iy;M.Vec=ay;M.Opt=cy;M.Record=uy;M.Variant=dy;M.Rec=ly;M.Func=fy;M.Service=py;M.resetSubtypeCache=Mf;M.subtype=jf;var $2=Ir(),Te=$c(),Zt=Cf(),$=Ff(),Uf=Pf(),Se;(function(t){t[t.Null=-1]="Null",t[t.Bool=-2]="Bool",t[t.Nat=-3]="Nat",t[t.Int=-4]="Int",t[t.Float32=-13]="Float32",t[t.Float64=-14]="Float64",t[t.Text=-15]="Text",t[t.Reserved=-16]="Reserved",t[t.Empty=-17]="Empty",t[t.Opt=-18]="Opt",t[t.Vector=-19]="Vector",t[t.Record=-20]="Record",t[t.Variant=-21]="Variant",t[t.Func=-22]="Func",t[t.Service=-23]="Service",t[t.Principal=-24]="Principal"})(Se||(Se={}));var zc="DIDL",sy=400;function ra(t,e,r){return t.map((n,o)=>r(n,e[o]))}var Lf=class{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(e){return this._idx.has(e.name)}add(e,r){let n=this._typs.length;this._idx.set(e.name,n),this._idxRefCount.set(n,1),this._typs.push(r)}merge(e,r){let n=this._idx.get(e.name),o=this._idx.get(r);if(n===void 0)throw new Error("Missing type index for "+e);if(o===void 0)throw new Error("Missing type index for "+r);this._typs[n]=this._typs[o];let s=this._getIdxRefCount(o);this._idxRefCount.set(o,s-1),this._idx.delete(r),this._compactFromEnd()}_getIdxRefCount(e){return this._idxRefCount.get(e)||0}_compactFromEnd(){for(;this._typs.length>0;){let e=this._typs.length-1;if(this._getIdxRefCount(e)>0)break;this._typs.pop(),this._idxRefCount.delete(e)}}encode(){let e=(0,$.lebEncode)(this._typs.length),r=(0,Te.concat)(...this._typs);return(0,Te.concat)(e,r)}indexOf(e){if(!this._idx.has(e))throw new Error("Missing type index for "+e);return(0,$.slebEncode)(this._idx.get(e)||0)}},qf=class{visitType(e,r){throw new Error("Not implemented")}visitPrimitive(e,r){return this.visitType(e,r)}visitEmpty(e,r){return this.visitPrimitive(e,r)}visitBool(e,r){return this.visitPrimitive(e,r)}visitNull(e,r){return this.visitPrimitive(e,r)}visitReserved(e,r){return this.visitPrimitive(e,r)}visitText(e,r){return this.visitPrimitive(e,r)}visitNumber(e,r){return this.visitPrimitive(e,r)}visitInt(e,r){return this.visitNumber(e,r)}visitNat(e,r){return this.visitNumber(e,r)}visitFloat(e,r){return this.visitPrimitive(e,r)}visitFixedInt(e,r){return this.visitNumber(e,r)}visitFixedNat(e,r){return this.visitNumber(e,r)}visitPrincipal(e,r){return this.visitPrimitive(e,r)}visitConstruct(e,r){return this.visitType(e,r)}visitVec(e,r,n){return this.visitConstruct(e,n)}visitOpt(e,r,n){return this.visitConstruct(e,n)}visitRecord(e,r,n){return this.visitConstruct(e,n)}visitTuple(e,r,n){let o=r.map((s,i)=>[`_${i}_`,s]);return this.visitRecord(e,o,n)}visitVariant(e,r,n){return this.visitConstruct(e,n)}visitRec(e,r,n){return this.visitConstruct(r,n)}visitFunc(e,r){return this.visitConstruct(e,r)}visitService(e,r){return this.visitConstruct(e,r)}};M.Visitor=qf;var le;(function(t){t.EmptyClass="__IDL_EmptyClass__",t.UnknownClass="__IDL_UnknownClass__",t.BoolClass="__IDL_BoolClass__",t.NullClass="__IDL_NullClass__",t.ReservedClass="__IDL_ReservedClass__",t.TextClass="__IDL_TextClass__",t.IntClass="__IDL_IntClass__",t.NatClass="__IDL_NatClass__",t.FloatClass="__IDL_FloatClass__",t.FixedIntClass="__IDL_FixedIntClass__",t.FixedNatClass="__IDL_FixedNatClass__",t.VecClass="__IDL_VecClass__",t.OptClass="__IDL_OptClass__",t.RecordClass="__IDL_RecordClass__",t.TupleClass="__IDL_TupleClass__",t.VariantClass="__IDL_VariantClass__",t.RecClass="__IDL_RecClass__",t.PrincipalClass="__IDL_PrincipalClass__",t.FuncClass="__IDL_FuncClass__",t.ServiceClass="__IDL_ServiceClass__"})(le||(le={}));var zs=class{display(){return this.name}valueToString(e){return We(e)}buildTypeTable(e){e.has(this)||this._buildTypeTableImpl(e)}};M.Type=zs;var Yt=class extends zs{checkType(e){if(this.name!==e.name)throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`);return e}_buildTypeTableImpl(e){}};M.PrimitiveType=Yt;var Yr=class extends zs{checkType(e){if(e instanceof mr){let r=e.getType();if(typeof r>"u")throw new Error("type mismatch with uninitialized type");return r}throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`)}encodeType(e){return e.indexOf(this.name)}};M.ConstructType=Yr;var na=class extends Yt{get typeName(){return le.EmptyClass}static[Symbol.hasInstance](e){return e.typeName===le.EmptyClass}accept(e,r){return e.visitEmpty(this,r)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return(0,$.slebEncode)(Se.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}};M.EmptyClass=na;var Yc=class extends zs{get typeName(){return le.UnknownClass}static[Symbol.hasInstance](e){return e.typeName===le.UnknownClass}checkType(e){throw new Error("Method not implemented for unknown.")}accept(e,r){throw e.visitType(this,r)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(){throw new Error("Unknown cannot appear as a function argument")}valueToString(){throw new Error("Unknown cannot appear as a value")}encodeType(){throw new Error("Unknown cannot be serialized")}decodeValue(e,r){let n=r.decodeValue(e,r);Object(n)!==n&&(n=Object(n));let o;return r instanceof mr?o=()=>r.getType():o=()=>r,Object.defineProperty(n,"type",{value:o,writable:!0,enumerable:!1,configurable:!0}),n}_buildTypeTableImpl(){throw new Error("Unknown cannot be serialized")}get name(){return"Unknown"}};M.UnknownClass=Yc;var Wc=class extends Yt{get typeName(){return le.BoolClass}static[Symbol.hasInstance](e){return e.typeName===le.BoolClass}accept(e,r){return e.visitBool(this,r)}covariant(e){if(typeof e=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(e){return new Uint8Array([e?1:0])}encodeType(){return(0,$.slebEncode)(Se.Bool)}decodeValue(e,r){switch(this.checkType(r),(0,$.safeReadUint8)(e)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}};M.BoolClass=Wc;var zo=class extends Yt{get typeName(){return le.NullClass}static[Symbol.hasInstance](e){return e.typeName===le.NullClass}accept(e,r){return e.visitNull(this,r)}covariant(e){if(e===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return(0,$.slebEncode)(Se.Null)}decodeValue(e,r){return this.checkType(r),null}get name(){return"null"}};M.NullClass=zo;var Wr=class extends Yt{get typeName(){return le.ReservedClass}static[Symbol.hasInstance](e){return e.typeName===le.ReservedClass}accept(e,r){return e.visitReserved(this,r)}covariant(e){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return(0,$.slebEncode)(Se.Reserved)}decodeValue(e,r){return r.name!==this.name&&r.decodeValue(e,r),null}get name(){return"reserved"}};M.ReservedClass=Wr;var Xc=class extends Yt{get typeName(){return le.TextClass}static[Symbol.hasInstance](e){return e.typeName===le.TextClass}accept(e,r){return e.visitText(this,r)}covariant(e){if(typeof e=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(e){let r=new TextEncoder().encode(e),n=(0,$.lebEncode)(r.byteLength);return(0,Te.concat)(n,r)}encodeType(){return(0,$.slebEncode)(Se.Text)}decodeValue(e,r){this.checkType(r);let n=(0,$.lebDecode)(e),o=(0,$.safeRead)(e,Number(n));return new TextDecoder("utf8",{fatal:!0}).decode(o)}get name(){return"text"}valueToString(e){return'"'+e+'"'}};M.TextClass=Xc;var oa=class extends Yt{get typeName(){return le.IntClass}static[Symbol.hasInstance](e){return e.typeName===le.IntClass}accept(e,r){return e.visitInt(this,r)}covariant(e){if(typeof e=="bigint"||Number.isInteger(e))return!0;throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(e){return(0,$.slebEncode)(e)}encodeType(){return(0,$.slebEncode)(Se.Int)}decodeValue(e,r){return this.checkType(r),(0,$.slebDecode)(e)}get name(){return"int"}valueToString(e){return e.toString()}};M.IntClass=oa;var sa=class extends Yt{get typeName(){return le.NatClass}static[Symbol.hasInstance](e){return e.typeName===le.NatClass}accept(e,r){return e.visitNat(this,r)}covariant(e){if(typeof e=="bigint"&&e>=BigInt(0)||Number.isInteger(e)&&e>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(e){return(0,$.lebEncode)(e)}encodeType(){return(0,$.slebEncode)(Se.Nat)}decodeValue(e,r){return this.checkType(r),(0,$.lebDecode)(e)}get name(){return"nat"}valueToString(e){return e.toString()}};M.NatClass=sa;var ia=class extends Yt{get typeName(){return le.FloatClass}static[Symbol.hasInstance](e){return e.typeName===le.FloatClass}constructor(e){if(super(),this._bits=e,e!==32&&e!==64)throw new Error("not a valid float type")}accept(e,r){return e.visitFloat(this,r)}covariant(e){if(typeof e=="number"||e instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(e){let r=new ArrayBuffer(this._bits/8),n=new DataView(r);return this._bits===32?n.setFloat32(0,e,!0):n.setFloat64(0,e,!0),new Uint8Array(r)}encodeType(){let e=this._bits===32?Se.Float32:Se.Float64;return(0,$.slebEncode)(e)}decodeValue(e,r){this.checkType(r);let n=(0,$.safeRead)(e,this._bits/8),o=(0,Te.uint8ToDataView)(n);return this._bits===32?o.getFloat32(0,!0):o.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(e){return e.toString()}};M.FloatClass=ia;var In=class extends Yt{get typeName(){return le.FixedIntClass}static[Symbol.hasInstance](e){return e.typeName===le.FixedIntClass}constructor(e){super(),this._bits=e}accept(e,r){return e.visitFixedInt(this,r)}covariant(e){let r=(0,Uf.iexp2)(this._bits-1)*BigInt(-1),n=(0,Uf.iexp2)(this._bits-1)-BigInt(1),o=!1;if(typeof e=="bigint")o=e>=r&&e<=n;else if(Number.isInteger(e)){let s=BigInt(e);o=s>=r&&s<=n}else o=!1;if(o)return!0;throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(e){return(0,$.writeIntLE)(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return(0,$.slebEncode)(-9-e)}decodeValue(e,r){this.checkType(r);let n=(0,$.readIntLE)(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`int${this._bits}`}valueToString(e){return e.toString()}};M.FixedIntClass=In;var Zr=class extends Yt{get typeName(){return le.FixedNatClass}static[Symbol.hasInstance](e){return e.typeName===le.FixedNatClass}constructor(e){super(),this._bits=e}accept(e,r){return e.visitFixedNat(this,r)}covariant(e){let r=(0,Uf.iexp2)(this._bits),n=!1;if(typeof e=="bigint"&&e>=BigInt(0)?n=e<r:Number.isInteger(e)&&e>=0?n=BigInt(e)<r:n=!1,n)return!0;throw new Error(`Invalid ${this.display()} argument: ${We(e)}`)}encodeValue(e){return(0,$.writeUIntLE)(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return(0,$.slebEncode)(-5-e)}decodeValue(e,r){this.checkType(r);let n=(0,$.readUIntLE)(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`nat${this._bits}`}valueToString(e){return e.toString()}};M.FixedNatClass=Zr;var Zs=class t extends Yr{get typeName(){return le.VecClass}static[Symbol.hasInstance](e){return e.typeName===le.VecClass}constructor(e){super(),this._type=e,this._blobOptimization=!1,e instanceof Zr&&e._bits===8&&(this._blobOptimization=!0)}accept(e,r){return e.visitVec(this,this._type,r)}covariant(e){let r=this._type instanceof Zr?this._type._bits:this._type instanceof In?this._type._bits:0;if(ArrayBuffer.isView(e)&&r==e.BYTES_PER_ELEMENT*8||Array.isArray(e)&&e.every((n,o)=>{try{return this._type.covariant(n)}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
38
|
+
`),e}};k.HttpErrorCode=sp;var op=class t extends pe{constructor(){super(),this.name="HttpV3ApiNotSupportedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"HTTP request failed: v3 API is not supported"}};k.HttpV3ApiNotSupportedErrorCode=op;var ip=class t extends pe{constructor(e){super(),this.error=e,this.name="HttpFetchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to fetch HTTP request: ${Ea(this.error)}`}};k.HttpFetchErrorCode=ip;var ap=class t extends pe{constructor(e){super(),this.receivedCanisterId=e,this.name="MissingCanisterIdErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Canister ID is required, but received ${typeof this.receivedCanisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`}};k.MissingCanisterIdErrorCode=ap;var cp=class t extends pe{constructor(e){super(),this.request=e,this.name="InvalidReadStateRequestErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Invalid read state request: ${this.request}`}};k.InvalidReadStateRequestErrorCode=cp;var up=class t extends pe{constructor(e){super(),this.error=e,this.name="ExpiryJsonDeserializeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to deserialize expiry: ${this.error}`}};k.ExpiryJsonDeserializeErrorCode=up;function Ea(t){if(t instanceof Error)return t.stack??t.message;try{return JSON.stringify(t)}catch{return String(t)}}k.UNREACHABLE_ERROR=new Error("unreachable")});var hu=Y(Pn=>{"use strict";Object.defineProperty(Pn,"__esModule",{value:!0});Pn.PipeArrayBuffer=void 0;Pn.concat=IE;Pn.uint8FromBufLike=lp;Pn.compare=Ly;Pn.uint8Equals=SE;Pn.uint8ToDataView=AE;function IE(...t){let e=new Uint8Array(t.reduce((n,s)=>n+s.byteLength,0)),r=0;for(let n of t)e.set(n,r),r+=n.byteLength;return e}var dp=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=lp(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}};Pn.PipeArrayBuffer=dp;function lp(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?lp(t.buffer):new Uint8Array(t)}function Ly(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 SE(t,e){return Ly(t,e)===0}function AE(t){if(!(t instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(t.buffer,t.byteOffset,t.byteLength)}});var pp=Y(fp=>{"use strict";Object.defineProperty(fp,"__esModule",{value:!0});fp.idlLabelToId=CE;function BE(t){let r=new TextEncoder().encode(t),n=0;for(let s of r)n=(n*223+s)%2**32;return n}function CE(t){if(/^_\d+_$/.test(t)||/^_0x[0-9a-fA-F]+_$/.test(t)){let e=+t.slice(1,-1);if(Number.isSafeInteger(e)&&e>=0&&e<2**32)return e}return BE(t)}});var hp=Y(mu=>{"use strict";Object.defineProperty(mu,"__esModule",{value:!0});mu.ilog2=PE;mu.iexp2=DE;function PE(t){let e=BigInt(t);if(t<=0)throw new RangeError("Input must be positive");return e.toString(2).length-1}function DE(t){let e=BigInt(t);if(t<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<e}});var yp=Y(Tr=>{"use strict";Object.defineProperty(Tr,"__esModule",{value:!0});Tr.safeRead=ky;Tr.safeReadUint8=yu;Tr.lebEncode=FE;Tr.lebDecode=jy;Tr.slebEncode=UE;Tr.slebDecode=VE;Tr.writeUIntLE=LE;Tr.writeIntLE=Hy;Tr.readUIntLE=$y;Tr.readIntLE=qE;var mp=hu(),qy=hp();function My(){throw new Error("unexpected end of buffer")}function ky(t,e){return t.byteLength<e&&My(),t.read(e)}function yu(t){let e=t.readUint8();return e===void 0&&My(),e}function FE(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:(0,qy.ilog2)(t))+1,r=new mp.PipeArrayBuffer(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 jy(t){let e=BigInt(1),r=BigInt(0),n;do n=yu(t),r+=BigInt(n&127).valueOf()*e,e*=BigInt(128);while(n>=128);return r}function UE(t){typeof t=="number"&&(t=BigInt(t));let e=t<BigInt(0);e&&(t=-t-BigInt(1));let r=(t===BigInt(0)?0:(0,qy.ilog2)(t))+1,n=new mp.PipeArrayBuffer(new Uint8Array(r),0);for(;;){let o=s(t);if(t/=BigInt(128),e&&t===BigInt(0)&&(o&64)!==0||!e&&t===BigInt(0)&&(o&64)===0){n.write(new Uint8Array([o]));break}else n.write(new Uint8Array([o|128]))}function s(o){let i=o%BigInt(128);return Number(e?BigInt(128)-i-BigInt(1):i)}return n.buffer}function VE(t){let e=new Uint8Array(t.buffer),r=0;for(;r<e.byteLength;r++)if(e[r]<128){if((e[r]&64)===0)return jy(t);break}let n=new Uint8Array(ky(t,r+1)),s=BigInt(0);for(let o=n.byteLength-1;o>=0;o--)s=s*BigInt(128)+BigInt(128-(n[o]&127)-1);return-s-BigInt(1)}function LE(t,e){if(BigInt(t)<BigInt(0))throw new Error("Cannot write negative values.");return Hy(t,e)}function Hy(t,e){t=BigInt(t);let r=new mp.PipeArrayBuffer(new Uint8Array(Math.min(1,e)),0),n=0,s=BigInt(256),o=BigInt(0),i=Number(t%s);for(r.write(new Uint8Array([i]));++n<e;)t<0&&o===BigInt(0)&&i!==0&&(o=BigInt(1)),i=Number((t/s-o)%BigInt(256)),r.write(new Uint8Array([i])),s*=BigInt(256);return r.buffer}function $y(t,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let r=BigInt(yu(t)),n=BigInt(1),s=0;for(;++s<e;){n*=BigInt(256);let o=BigInt(yu(t));r=r+n*o}return r}function qE(t,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let r=$y(t,e),n=BigInt(2)**(BigInt(8)*BigInt(e-1)+BigInt(7));return r>=n&&(r-=n*BigInt(2)),r}});var Op=Y(M=>{"use strict";Object.defineProperty(M,"__esModule",{value:!0});M.Principal=M.Nat64=M.Nat32=M.Nat16=M.Nat8=M.Int64=M.Int32=M.Int16=M.Int8=M.Float64=M.Float32=M.Nat=M.Int=M.Text=M.Null=M.Bool=M.Unknown=M.Reserved=M.Empty=M.ServiceClass=M.FuncClass=M.PrincipalClass=M.RecClass=M.VariantClass=M.TupleClass=M.RecordClass=M.OptClass=M.VecClass=M.FixedNatClass=M.FixedIntClass=M.FloatClass=M.NatClass=M.IntClass=M.TextClass=M.ReservedClass=M.NullClass=M.BoolClass=M.UnknownClass=M.EmptyClass=M.ConstructType=M.PrimitiveType=M.Type=M.Visitor=void 0;M.encode=kE;M.decode=jE;M.Tuple=Gy;M.Vec=Zy;M.Opt=zy;M.Record=Yy;M.Variant=Wy;M.Rec=Xy;M.Func=Jy;M.Service=Qy;M.resetSubtypeCache=wp;M.subtype=Tp;var ME=Ur(),Te=hu(),tr=pp(),$=yp(),bp=hp(),Se;(function(t){t[t.Null=-1]="Null",t[t.Bool=-2]="Bool",t[t.Nat=-3]="Nat",t[t.Int=-4]="Int",t[t.Float32=-13]="Float32",t[t.Float64=-14]="Float64",t[t.Text=-15]="Text",t[t.Reserved=-16]="Reserved",t[t.Empty=-17]="Empty",t[t.Opt=-18]="Opt",t[t.Vector=-19]="Vector",t[t.Record=-20]="Record",t[t.Variant=-21]="Variant",t[t.Func=-22]="Func",t[t.Service=-23]="Service",t[t.Principal=-24]="Principal"})(Se||(Se={}));var _u="DIDL",Ky=400;function Ta(t,e,r){return t.map((n,s)=>r(n,e[s]))}var gp=class{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(e){return this._idx.has(e.name)}add(e,r){let n=this._typs.length;this._idx.set(e.name,n),this._idxRefCount.set(n,1),this._typs.push(r)}merge(e,r){let n=this._idx.get(e.name),s=this._idx.get(r);if(n===void 0)throw new Error("Missing type index for "+e);if(s===void 0)throw new Error("Missing type index for "+r);this._typs[n]=this._typs[s];let o=this._getIdxRefCount(n),i=this._getIdxRefCount(s);this._idxRefCount.set(n,o+i),this._idx.set(r,n),this._idxRefCount.set(s,0),this._compactFromEnd()}_getIdxRefCount(e){return this._idxRefCount.get(e)||0}_compactFromEnd(){for(;this._typs.length>0;){let e=this._typs.length-1;if(this._getIdxRefCount(e)>0)break;this._typs.pop(),this._idxRefCount.delete(e)}}encode(){let e=(0,$.lebEncode)(this._typs.length),r=(0,Te.concat)(...this._typs);return(0,Te.concat)(e,r)}indexOf(e){if(!this._idx.has(e))throw new Error("Missing type index for "+e);return(0,$.slebEncode)(this._idx.get(e)||0)}},xp=class{visitType(e,r){throw new Error("Not implemented")}visitPrimitive(e,r){return this.visitType(e,r)}visitEmpty(e,r){return this.visitPrimitive(e,r)}visitBool(e,r){return this.visitPrimitive(e,r)}visitNull(e,r){return this.visitPrimitive(e,r)}visitReserved(e,r){return this.visitPrimitive(e,r)}visitText(e,r){return this.visitPrimitive(e,r)}visitNumber(e,r){return this.visitPrimitive(e,r)}visitInt(e,r){return this.visitNumber(e,r)}visitNat(e,r){return this.visitNumber(e,r)}visitFloat(e,r){return this.visitPrimitive(e,r)}visitFixedInt(e,r){return this.visitNumber(e,r)}visitFixedNat(e,r){return this.visitNumber(e,r)}visitPrincipal(e,r){return this.visitPrimitive(e,r)}visitConstruct(e,r){return this.visitType(e,r)}visitVec(e,r,n){return this.visitConstruct(e,n)}visitOpt(e,r,n){return this.visitConstruct(e,n)}visitRecord(e,r,n){return this.visitConstruct(e,n)}visitTuple(e,r,n){let s=r.map((o,i)=>[`_${i}_`,o]);return this.visitRecord(e,s,n)}visitVariant(e,r,n){return this.visitConstruct(e,n)}visitRec(e,r,n){return this.visitConstruct(r,n)}visitFunc(e,r){return this.visitConstruct(e,r)}visitService(e,r){return this.visitConstruct(e,r)}};M.Visitor=xp;var ue;(function(t){t.EmptyClass="__IDL_EmptyClass__",t.UnknownClass="__IDL_UnknownClass__",t.BoolClass="__IDL_BoolClass__",t.NullClass="__IDL_NullClass__",t.ReservedClass="__IDL_ReservedClass__",t.TextClass="__IDL_TextClass__",t.IntClass="__IDL_IntClass__",t.NatClass="__IDL_NatClass__",t.FloatClass="__IDL_FloatClass__",t.FixedIntClass="__IDL_FixedIntClass__",t.FixedNatClass="__IDL_FixedNatClass__",t.VecClass="__IDL_VecClass__",t.OptClass="__IDL_OptClass__",t.RecordClass="__IDL_RecordClass__",t.TupleClass="__IDL_TupleClass__",t.VariantClass="__IDL_VariantClass__",t.RecClass="__IDL_RecClass__",t.PrincipalClass="__IDL_PrincipalClass__",t.FuncClass="__IDL_FuncClass__",t.ServiceClass="__IDL_ServiceClass__"})(ue||(ue={}));var li=class{display(){return this.name}valueToString(e){return Je(e)}buildTypeTable(e){e.has(this)||this._buildTypeTableImpl(e)}};M.Type=li;var rr=class extends li{checkType(e){if(this.name!==e.name)throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`);return e}_buildTypeTableImpl(e){}};M.PrimitiveType=rr;var sn=class extends li{checkType(e){if(e instanceof Or){let r=e.getType();if(typeof r>"u")throw new Error("type mismatch with uninitialized type");return r}throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`)}encodeType(e){return e.indexOf(this.name)}};M.ConstructType=sn;var Oa=class extends rr{get typeName(){return ue.EmptyClass}static[Symbol.hasInstance](e){return e.typeName===ue.EmptyClass}accept(e,r){return e.visitEmpty(this,r)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return(0,$.slebEncode)(Se.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}};M.EmptyClass=Oa;var gu=class extends li{get typeName(){return ue.UnknownClass}static[Symbol.hasInstance](e){return e.typeName===ue.UnknownClass}checkType(e){throw new Error("Method not implemented for unknown.")}accept(e,r){throw e.visitType(this,r)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(){throw new Error("Unknown cannot appear as a function argument")}valueToString(){throw new Error("Unknown cannot appear as a value")}encodeType(){throw new Error("Unknown cannot be serialized")}decodeValue(e,r){let n=r.decodeValue(e,r);Object(n)!==n&&(n=Object(n));let s;return r instanceof Or?s=()=>r.getType():s=()=>r,Object.defineProperty(n,"type",{value:s,writable:!0,enumerable:!1,configurable:!0}),n}_buildTypeTableImpl(){throw new Error("Unknown cannot be serialized")}get name(){return"Unknown"}};M.UnknownClass=gu;var xu=class extends rr{get typeName(){return ue.BoolClass}static[Symbol.hasInstance](e){return e.typeName===ue.BoolClass}accept(e,r){return e.visitBool(this,r)}covariant(e){if(typeof e=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return new Uint8Array([e?1:0])}encodeType(){return(0,$.slebEncode)(Se.Bool)}decodeValue(e,r){switch(this.checkType(r),(0,$.safeReadUint8)(e)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}};M.BoolClass=xu;var fo=class extends rr{get typeName(){return ue.NullClass}static[Symbol.hasInstance](e){return e.typeName===ue.NullClass}accept(e,r){return e.visitNull(this,r)}covariant(e){if(e===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return(0,$.slebEncode)(Se.Null)}decodeValue(e,r){return this.checkType(r),null}get name(){return"null"}};M.NullClass=fo;var on=class extends rr{get typeName(){return ue.ReservedClass}static[Symbol.hasInstance](e){return e.typeName===ue.ReservedClass}accept(e,r){return e.visitReserved(this,r)}covariant(e){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return(0,$.slebEncode)(Se.Reserved)}decodeValue(e,r){return r.name!==this.name&&r.decodeValue(e,r),null}get name(){return"reserved"}};M.ReservedClass=on;var wu=class extends rr{get typeName(){return ue.TextClass}static[Symbol.hasInstance](e){return e.typeName===ue.TextClass}accept(e,r){return e.visitText(this,r)}covariant(e){if(typeof e=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){let r=new TextEncoder().encode(e),n=(0,$.lebEncode)(r.byteLength);return(0,Te.concat)(n,r)}encodeType(){return(0,$.slebEncode)(Se.Text)}decodeValue(e,r){this.checkType(r);let n=(0,$.lebDecode)(e),s=(0,$.safeRead)(e,Number(n));return new TextDecoder("utf8",{fatal:!0}).decode(s)}get name(){return"text"}valueToString(e){return'"'+e+'"'}};M.TextClass=wu;var Na=class extends rr{get typeName(){return ue.IntClass}static[Symbol.hasInstance](e){return e.typeName===ue.IntClass}accept(e,r){return e.visitInt(this,r)}covariant(e){if(typeof e=="bigint"||Number.isInteger(e))return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return(0,$.slebEncode)(e)}encodeType(){return(0,$.slebEncode)(Se.Int)}decodeValue(e,r){return this.checkType(r),(0,$.slebDecode)(e)}get name(){return"int"}valueToString(e){return e.toString()}};M.IntClass=Na;var va=class extends rr{get typeName(){return ue.NatClass}static[Symbol.hasInstance](e){return e.typeName===ue.NatClass}accept(e,r){return e.visitNat(this,r)}covariant(e){if(typeof e=="bigint"&&e>=BigInt(0)||Number.isInteger(e)&&e>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return(0,$.lebEncode)(e)}encodeType(){return(0,$.slebEncode)(Se.Nat)}decodeValue(e,r){return this.checkType(r),(0,$.lebDecode)(e)}get name(){return"nat"}valueToString(e){return e.toString()}};M.NatClass=va;var Ra=class extends rr{get typeName(){return ue.FloatClass}static[Symbol.hasInstance](e){return e.typeName===ue.FloatClass}constructor(e){if(super(),this._bits=e,e!==32&&e!==64)throw new Error("not a valid float type")}accept(e,r){return e.visitFloat(this,r)}covariant(e){if(typeof e=="number"||e instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){let r=new ArrayBuffer(this._bits/8),n=new DataView(r);return this._bits===32?n.setFloat32(0,e,!0):n.setFloat64(0,e,!0),new Uint8Array(r)}encodeType(){let e=this._bits===32?Se.Float32:Se.Float64;return(0,$.slebEncode)(e)}decodeValue(e,r){this.checkType(r);let n=(0,$.safeRead)(e,this._bits/8),s=(0,Te.uint8ToDataView)(n);return this._bits===32?s.getFloat32(0,!0):s.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(e){return e.toString()}};M.FloatClass=Ra;var Fn=class extends rr{get typeName(){return ue.FixedIntClass}static[Symbol.hasInstance](e){return e.typeName===ue.FixedIntClass}constructor(e){super(),this._bits=e}accept(e,r){return e.visitFixedInt(this,r)}covariant(e){let r=(0,bp.iexp2)(this._bits-1)*BigInt(-1),n=(0,bp.iexp2)(this._bits-1)-BigInt(1),s=!1;if(typeof e=="bigint")s=e>=r&&e<=n;else if(Number.isInteger(e)){let o=BigInt(e);s=o>=r&&o<=n}else s=!1;if(s)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return(0,$.writeIntLE)(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return(0,$.slebEncode)(-9-e)}decodeValue(e,r){this.checkType(r);let n=(0,$.readIntLE)(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`int${this._bits}`}valueToString(e){return e.toString()}};M.FixedIntClass=Fn;var nn=class extends rr{get typeName(){return ue.FixedNatClass}static[Symbol.hasInstance](e){return e.typeName===ue.FixedNatClass}constructor(e){super(),this._bits=e}accept(e,r){return e.visitFixedNat(this,r)}covariant(e){let r=(0,bp.iexp2)(this._bits),n=!1;if(typeof e=="bigint"&&e>=BigInt(0)?n=e<r:Number.isInteger(e)&&e>=0?n=BigInt(e)<r:n=!1,n)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return(0,$.writeUIntLE)(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return(0,$.slebEncode)(-5-e)}decodeValue(e,r){this.checkType(r);let n=(0,$.readUIntLE)(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`nat${this._bits}`}valueToString(e){return e.toString()}};M.FixedNatClass=nn;var fi=class t extends sn{get typeName(){return ue.VecClass}static[Symbol.hasInstance](e){return e.typeName===ue.VecClass}constructor(e){super(),this._type=e,this._blobOptimization=!1,e instanceof nn&&e._bits===8&&(this._blobOptimization=!0)}accept(e,r){return e.visitVec(this,this._type,r)}covariant(e){let r=this._type instanceof nn?this._type._bits:this._type instanceof Fn?this._type._bits:0;if(ArrayBuffer.isView(e)&&r==e.BYTES_PER_ELEMENT*8||Array.isArray(e)&&e.every((n,s)=>{try{return this._type.covariant(n)}catch(o){throw new Error(`Invalid ${this.display()} argument:
|
|
39
39
|
|
|
40
|
-
index ${
|
|
40
|
+
index ${s} -> ${o.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){let r=(0,$.lebEncode)(e.length);if(this._blobOptimization)return(0,Te.concat)(r,new Uint8Array(e));if(ArrayBuffer.isView(e))if(e instanceof Int16Array||e instanceof Uint16Array){let s=new DataView(new ArrayBuffer(e.length*2));for(let o=0;o<e.length;o++)e instanceof Int16Array?s.setInt16(o*2,e[o],!0):s.setUint16(o*2,e[o],!0);return(0,Te.concat)(r,new Uint8Array(s.buffer))}else if(e instanceof Int32Array||e instanceof Uint32Array){let s=new DataView(new ArrayBuffer(e.length*4));for(let o=0;o<e.length;o++)e instanceof Int32Array?s.setInt32(o*4,e[o],!0):s.setUint32(o*4,e[o],!0);return(0,Te.concat)(r,new Uint8Array(s.buffer))}else if(e instanceof BigInt64Array||e instanceof BigUint64Array){let s=new DataView(new ArrayBuffer(e.length*8));for(let o=0;o<e.length;o++)e instanceof BigInt64Array?s.setBigInt64(o*8,e[o],!0):s.setBigUint64(o*8,e[o],!0);return(0,Te.concat)(r,new Uint8Array(s.buffer))}else return(0,Te.concat)(r,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));let n=new Te.PipeArrayBuffer(new Uint8Array(r.byteLength+e.length),0);n.write(r);for(let s of e){let o=this._type.encodeValue(s);n.write(new Uint8Array(o))}return n.buffer}_buildTypeTableImpl(e){this._type.buildTypeTable(e);let r=(0,$.slebEncode)(Se.Vector),n=this._type.encodeType(e);e.add(this,(0,Te.concat)(r,n))}decodeValue(e,r){let n=this.checkType(r);if(!(n instanceof t))throw new Error("Not a vector type");let s=Number((0,$.lebDecode)(e));if(this._type instanceof nn){if(this._type._bits==8)return new Uint8Array(e.read(s));if(this._type._bits==16){let i=e.read(s*2);return new Uint16Array(i.buffer,i.byteOffset,s)}if(this._type._bits==32){let i=e.read(s*4);return new Uint32Array(i.buffer,i.byteOffset,s)}if(this._type._bits==64)return new BigUint64Array(e.read(s*8).buffer)}if(this._type instanceof Fn){if(this._type._bits==8)return new Int8Array(e.read(s));if(this._type._bits==16){let i=e.read(s*2),a=new DataView(i.buffer,i.byteOffset,i.byteLength),c=new Int16Array(s);for(let d=0;d<s;d++)c[d]=a.getInt16(d*2,!0);return c}if(this._type._bits==32){let i=e.read(s*4),a=new DataView(i.buffer,i.byteOffset,i.byteLength),c=new Int32Array(s);for(let d=0;d<s;d++)c[d]=a.getInt32(d*4,!0);return c}if(this._type._bits==64){let i=e.read(s*8),a=new DataView(i.buffer,i.byteOffset,i.byteLength),c=new BigInt64Array(s);for(let d=0;d<s;d++)c[d]=a.getBigInt64(d*8,!0);return c}}let o=[];for(let i=0;i<s;i++)o.push(this._type.decodeValue(e,n._type));return o}get name(){return`vec ${this._type.name}`}display(){return`vec ${this._type.display()}`}valueToString(e){return"vec {"+e.map(n=>this._type.valueToString(n)).join("; ")+"}"}};M.VecClass=fi;var Rs=class t extends sn{get typeName(){return ue.OptClass}static[Symbol.hasInstance](e){return e.typeName===ue.OptClass}constructor(e){super(),this._type=e}accept(e,r){return e.visitOpt(this,this._type,r)}covariant(e){try{if(Array.isArray(e)&&(e.length===0||e.length===1&&this._type.covariant(e[0])))return!0}catch(r){throw new Error(`Invalid ${this.display()} argument: ${Je(e)}
|
|
41
41
|
|
|
42
|
-
-> ${r.message}`)}throw new Error(`Invalid ${this.display()} argument: ${
|
|
42
|
+
-> ${r.message}`)}throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return e.length===0?new Uint8Array([0]):(0,Te.concat)(new Uint8Array([1]),this._type.encodeValue(e[0]))}_buildTypeTableImpl(e){this._type.buildTypeTable(e);let r=(0,$.slebEncode)(Se.Opt),n=this._type.encodeType(e);e.add(this,(0,Te.concat)(r,n))}decodeValue(e,r){if(r instanceof fo)return[];if(r instanceof on)return[];let n=r;if(r instanceof Or){let s=r.getType();if(typeof s>"u")throw new Error("type mismatch with uninitialized type");n=s}if(n instanceof t)switch((0,$.safeReadUint8)(e)){case 0:return[];case 1:{let s=e.save();try{return[this._type.decodeValue(e,n._type)]}catch{return e.restore(s),n._type.decodeValue(e,n._type),[]}}default:throw new Error("Not an option value")}else{if(this._type instanceof fo||this._type instanceof t||this._type instanceof on)return n.decodeValue(e,n),[];{let s=e.save();try{return[this._type.decodeValue(e,r)]}catch{return e.restore(s),n.decodeValue(e,r),[]}}}}get name(){return`opt ${this._type.name}`}display(){return`opt ${this._type.display()}`}valueToString(e){return e.length===0?"null":`opt ${this._type.valueToString(e[0])}`}};M.OptClass=Rs;var po=class t extends sn{get typeName(){return ue.RecordClass}static[Symbol.hasInstance](e){return e.typeName===ue.RecordClass||e.typeName===ue.TupleClass}constructor(e={}){super(),this._fields=Object.entries(e).sort((r,n)=>(0,tr.idlLabelToId)(r[0])-(0,tr.idlLabelToId)(n[0]))}accept(e,r){return e.visitRecord(this,this._fields,r)}tryAsTuple(){let e=[];for(let r=0;r<this._fields.length;r++){let[n,s]=this._fields[r];if(n!==`_${r}_`)return null;e.push(s)}return e}covariant(e){if(typeof e=="object"&&this._fields.every(([r,n])=>{if(!e.hasOwnProperty(r))throw new Error(`Record is missing key "${r}".`);try{return n.covariant(e[r])}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
43
43
|
|
|
44
|
-
field ${r} -> ${
|
|
44
|
+
field ${r} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){let r=this._fields.map(([s])=>e[s]),n=Ta(this._fields,r,([,s],o)=>s.encodeValue(o));return(0,Te.concat)(...n)}_buildTypeTableImpl(e){this._fields.forEach(([o,i])=>i.buildTypeTable(e));let r=(0,$.slebEncode)(Se.Record),n=(0,$.lebEncode)(this._fields.length),s=this._fields.map(([o,i])=>(0,Te.concat)((0,$.lebEncode)((0,tr.idlLabelToId)(o)),i.encodeType(e)));e.add(this,(0,Te.concat)(r,n,(0,Te.concat)(...s)))}decodeValue(e,r){let n=this.checkType(r);if(!(n instanceof t))throw new Error("Not a record type");let s={},o=0,i=0;for(;i<n._fields.length;){let[a,c]=n._fields[i];if(o>=this._fields.length){c.decodeValue(e,c),i++;continue}let[d,f]=this._fields[o],l=(0,tr.idlLabelToId)(this._fields[o][0]),u=(0,tr.idlLabelToId)(a);if(l===u)s[d]=f.decodeValue(e,c),o++,i++;else if(u>l)if(f instanceof Rs||f instanceof on)s[d]=[],o++;else throw new Error("Cannot find required field "+d);else c.decodeValue(e,c),i++}for(let[a,c]of this._fields.slice(o))if(c instanceof Rs||c instanceof on)s[a]=[];else throw new Error("Cannot find required field "+a);return s}get fieldsAsObject(){let e={};for(let[r,n]of this._fields)e[(0,tr.idlLabelToId)(r)]=n;return e}get name(){return`record {${this._fields.map(([r,n])=>r+":"+n.name).join("; ")}}`}display(){return`record {${this._fields.map(([r,n])=>r+":"+n.display()).join("; ")}}`}valueToString(e){let r=this._fields.map(([s])=>e[s]);return`record {${Ta(this._fields,r,([s,o],i)=>s+"="+o.valueToString(i)).join("; ")}}`}};M.RecordClass=po;var Eu=class t extends po{get typeName(){return ue.TupleClass}static[Symbol.hasInstance](e){return e.typeName===ue.TupleClass}constructor(e){let r={};e.forEach((n,s)=>r["_"+s+"_"]=n),super(r),this._components=e}accept(e,r){return e.visitTuple(this,this._components,r)}covariant(e){if(Array.isArray(e)&&e.length>=this._fields.length&&this._components.every((r,n)=>{try{return r.covariant(e[n])}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
45
45
|
|
|
46
|
-
index ${n} -> ${
|
|
46
|
+
index ${n} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){let r=Ta(this._components,e,(n,s)=>n.encodeValue(s));return(0,Te.concat)(...r)}decodeValue(e,r){let n=this.checkType(r);if(!(n instanceof t))throw new Error("not a tuple type");if(n._components.length<this._components.length)throw new Error("tuple mismatch");let s=[];for(let[o,i]of n._components.entries())o>=this._components.length?i.decodeValue(e,i):s.push(this._components[o].decodeValue(e,i));return s}display(){return`record {${this._components.map(r=>r.display()).join("; ")}}`}valueToString(e){return`record {${Ta(this._components,e,(n,s)=>n.valueToString(s)).join("; ")}}`}};M.TupleClass=Eu;var pi=class t extends sn{get typeName(){return ue.VariantClass}static[Symbol.hasInstance](e){return e.typeName===ue.VariantClass}constructor(e={}){super(),this._fields=Object.entries(e).sort((r,n)=>(0,tr.idlLabelToId)(r[0])-(0,tr.idlLabelToId)(n[0]))}accept(e,r){return e.visitVariant(this,this._fields,r)}covariant(e){if(typeof e=="object"&&Object.entries(e).length===1&&this._fields.every(([r,n])=>{try{return!e.hasOwnProperty(r)||n.covariant(e[r])}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
47
47
|
|
|
48
|
-
variant ${r} -> ${
|
|
48
|
+
variant ${r} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){for(let r=0;r<this._fields.length;r++){let[n,s]=this._fields[r];if(e.hasOwnProperty(n)){let o=(0,$.lebEncode)(r),i=s.encodeValue(e[n]);return(0,Te.concat)(o,i)}}throw Error("Variant has no data: "+e)}_buildTypeTableImpl(e){this._fields.forEach(([,o])=>{o.buildTypeTable(e)});let r=(0,$.slebEncode)(Se.Variant),n=(0,$.lebEncode)(this._fields.length),s=this._fields.map(([o,i])=>(0,Te.concat)((0,$.lebEncode)((0,tr.idlLabelToId)(o)),i.encodeType(e)));e.add(this,(0,Te.concat)(r,n,...s))}decodeValue(e,r){let n=this.checkType(r);if(!(n instanceof t))throw new Error("Not a variant type");let s=Number((0,$.lebDecode)(e));if(s>=n._fields.length)throw Error("Invalid variant index: "+s);let[o,i]=n._fields[s];for(let[a,c]of this._fields)if((0,tr.idlLabelToId)(o)===(0,tr.idlLabelToId)(a)){let d=c.decodeValue(e,i);return{[a]:d}}throw new Error("Cannot find field hash "+o)}get name(){return`variant {${this._fields.map(([r,n])=>r+":"+n.name).join("; ")}}`}display(){return`variant {${this._fields.map(([r,n])=>r+(n.name==="null"?"":`:${n.display()}`)).join("; ")}}`}valueToString(e){for(let[r,n]of this._fields)if(e.hasOwnProperty(r)){let s=n.valueToString(e[r]);return s==="null"?`variant {${r}}`:`variant {${r}=${s}}`}throw new Error("Variant has no data: "+e)}get alternativesAsObject(){let e={};for(let[r,n]of this._fields)e[(0,tr.idlLabelToId)(r)]=n;return e}};M.VariantClass=pi;var Or=class t extends sn{constructor(){super(...arguments),this._id=t._counter++}get typeName(){return ue.RecClass}static{this._counter=0}static[Symbol.hasInstance](e){return e.typeName===ue.RecClass}accept(e,r){if(!this._type)throw Error("Recursive type uninitialized.");return e.visitRec(this,this._type,r)}fill(e){this._type=e}getType(){return this._type}covariant(e){if(this._type&&this._type.covariant(e))return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.encodeValue(e)}_buildTypeTableImpl(e){if(!this._type)throw Error("Recursive type uninitialized.");e.add(this,new Uint8Array([])),this._type.buildTypeTable(e),e.merge(this,this._type.name)}decodeValue(e,r){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.decodeValue(e,r)}get name(){return`rec_${this._id}`}display(){if(!this._type)throw Error("Recursive type uninitialized.");return`\u03BC${this.name}.${this._type.name}`}valueToString(e){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.valueToString(e)}};M.RecClass=Or;function Ep(t){if((0,$.safeReadUint8)(t)!==1)throw new Error("Cannot decode principal");let r=Number((0,$.lebDecode)(t));return ME.Principal.fromUint8Array(new Uint8Array((0,$.safeRead)(t,r)))}var Tu=class extends rr{get typeName(){return ue.PrincipalClass}static[Symbol.hasInstance](e){return e.typeName===ue.PrincipalClass}accept(e,r){return e.visitPrincipal(this,r)}covariant(e){if(e&&e._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){let r=e.toUint8Array(),n=(0,$.lebEncode)(r.byteLength);return(0,Te.concat)(new Uint8Array([1]),n,r)}encodeType(){return(0,$.slebEncode)(Se.Principal)}decodeValue(e,r){return this.checkType(r),Ep(e)}get name(){return"principal"}valueToString(e){return`${this.name} "${e.toText()}"`}};M.PrincipalClass=Tu;var ho=class extends sn{get typeName(){return ue.FuncClass}static[Symbol.hasInstance](e){return e.typeName===ue.FuncClass}static argsToString(e,r){if(e.length!==r.length)throw new Error("arity mismatch");return"("+e.map((n,s)=>n.valueToString(r[s])).join(", ")+")"}constructor(e,r,n=[]){super(),this.argTypes=e,this.retTypes=r,this.annotations=n}accept(e,r){return e.visitFunc(this,r)}covariant(e){if(Array.isArray(e)&&e.length===2&&e[0]&&e[0]._isPrincipal&&typeof e[1]=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue([e,r]){let n=e.toUint8Array(),s=(0,$.lebEncode)(n.byteLength),o=(0,Te.concat)(new Uint8Array([1]),s,n),i=new TextEncoder().encode(r),a=(0,$.lebEncode)(i.byteLength);return(0,Te.concat)(new Uint8Array([1]),o,a,i)}_buildTypeTableImpl(e){this.argTypes.forEach(d=>d.buildTypeTable(e)),this.retTypes.forEach(d=>d.buildTypeTable(e));let r=(0,$.slebEncode)(Se.Func),n=(0,$.lebEncode)(this.argTypes.length),s=(0,Te.concat)(...this.argTypes.map(d=>d.encodeType(e))),o=(0,$.lebEncode)(this.retTypes.length),i=(0,Te.concat)(...this.retTypes.map(d=>d.encodeType(e))),a=(0,$.lebEncode)(this.annotations.length),c=(0,Te.concat)(...this.annotations.map(d=>this.encodeAnnotation(d)));e.add(this,(0,Te.concat)(r,n,s,o,i,a,c))}decodeValue(e,r){let n=r instanceof Or?r.getType()??r:r;if(!Tp(n,this))throw new Error(`Cannot decode function reference at type ${this.display()} from wire type ${n.display()}`);if((0,$.safeReadUint8)(e)!==1)throw new Error("Cannot decode function reference");let o=Ep(e),i=Number((0,$.lebDecode)(e)),a=(0,$.safeRead)(e,i),d=new TextDecoder("utf8",{fatal:!0}).decode(a);return[o,d]}get name(){let e=this.argTypes.map(s=>s.name).join(", "),r=this.retTypes.map(s=>s.name).join(", "),n=" "+this.annotations.join(" ");return`(${e}) -> (${r})${n}`}valueToString([e,r]){return`func "${e.toText()}".${r}`}display(){let e=this.argTypes.map(s=>s.display()).join(", "),r=this.retTypes.map(s=>s.display()).join(", "),n=" "+this.annotations.join(" ");return`(${e}) \u2192 (${r})${n}`}encodeAnnotation(e){if(e==="query")return new Uint8Array([1]);if(e==="oneway")return new Uint8Array([2]);if(e==="composite_query")return new Uint8Array([3]);throw new Error("Illegal function annotation")}};M.FuncClass=ho;var hi=class extends sn{get typeName(){return ue.ServiceClass}static[Symbol.hasInstance](e){return e.typeName===ue.ServiceClass}constructor(e){super(),this._fields=Object.entries(e).sort((r,n)=>r[0]<n[0]?-1:r[0]>n[0]?1:0)}accept(e,r){return e.visitService(this,r)}covariant(e){if(e&&e._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){let r=e.toUint8Array(),n=(0,$.lebEncode)(r.length);return(0,Te.concat)(new Uint8Array([1]),n,r)}_buildTypeTableImpl(e){this._fields.forEach(([o,i])=>i.buildTypeTable(e));let r=(0,$.slebEncode)(Se.Service),n=(0,$.lebEncode)(this._fields.length),s=this._fields.map(([o,i])=>{let a=new TextEncoder().encode(o),c=(0,$.lebEncode)(a.length);return(0,Te.concat)(c,a,i.encodeType(e))});e.add(this,(0,Te.concat)(r,n,...s))}decodeValue(e,r){let n=r instanceof Or?r.getType()??r:r;if(!Tp(n,this))throw new Error(`Cannot decode service reference at type ${this.display()} from wire type ${n.display()}`);return Ep(e)}get name(){return`service {${this._fields.map(([r,n])=>r+":"+n.name).join("; ")}}`}valueToString(e){return`service "${e.toText()}"`}fieldsAsObject(){let e={};for(let[r,n]of this._fields)e[r]=n;return e}};M.ServiceClass=hi;function Je(t){let e=JSON.stringify(t,(r,n)=>typeof n=="bigint"?`BigInt(${n})`:n);return e&&e.length>Ky?e.substring(0,Ky-3)+"...":e}function kE(t,e){if(e.length<t.length)throw Error("Wrong number of message arguments");let r=new gp;t.forEach(c=>c.buildTypeTable(r));let n=new TextEncoder().encode(_u),s=r.encode(),o=(0,$.lebEncode)(e.length),i=(0,Te.concat)(...t.map(c=>c.encodeType(r))),a=(0,Te.concat)(...Ta(t,e,(c,d)=>{try{c.covariant(d)}catch(f){throw new Error(f.message+`
|
|
49
49
|
|
|
50
|
-
`)}return c.encodeValue(d)}));return(0,Te.concat)(n,o,
|
|
51
|
-
`;return e}addNames(e,r,n){let o=this.rels.get(e);if(o==null){let s=new Map;s.set(r,n),this.rels.set(e,s)}else o.set(r,n)}},Zc=new eu;function Mf(){Zc=new eu}function z2(t,e){let r=new Set(t.annotations),n=new Set(e.annotations);if(r.size!==n.size)return!1;for(let o of r)if(!n.has(o))return!1;return!0}function Vf(t){return t instanceof po||t instanceof zo||t instanceof Wr}function jf(t,e){let r=Zc.copy(),n=vn(r,t,e);return n?Zc.add(t,e):Zc.addNegative(t,e),n}function vn(t,e,r){if(e.name===r.name)return!0;let n=t.known(e,r);if(n!==void 0)return n;if(t.add(e,r),r instanceof Wr||e instanceof na||e instanceof sa&&r instanceof oa)return!0;if(e instanceof Zs&&r instanceof Zs)return vn(t,e._type,r._type);if(r instanceof po)return!0;if(e instanceof Zo&&r instanceof Zo){let o=e.fieldsAsObject;for(let[s,i]of r._fields){let a=o[(0,Zt.idlLabelToId)(s)];if(a){if(!vn(t,a,i))return!1}else if(!Vf(i))return!1}return!0}if(e instanceof Yo&&r instanceof Yo){if(!z2(e,r))return!1;for(let o=0;o<e.argTypes.length;o++){let s=e.argTypes[o];if(o<r.argTypes.length){if(!vn(t,r.argTypes[o],s))return!1}else if(!Vf(s))return!1}for(let o=0;o<r.retTypes.length;o++){let s=r.retTypes[o];if(o<e.retTypes.length){if(!vn(t,e.retTypes[o],s))return!1}else if(!Vf(s))return!1}return!0}if(e instanceof Ys&&r instanceof Ys){let o=r.alternativesAsObject;for(let[s,i]of e._fields){let a=o[(0,Zt.idlLabelToId)(s)];if(!a||!vn(t,i,a))return!1}return!0}if(e instanceof Ws&&r instanceof Ws){let o=e.fieldsAsObject();for(let[s,i]of r._fields){let a=o[s];if(!a||!vn(t,a,i))return!1}return!0}return e instanceof mr?vn(t,e.getType(),r):r instanceof mr?vn(t,e,r.getType()):!1}});var Wf=Z(It=>{"use strict";Object.defineProperty(It,"__esModule",{value:!0});It.VecForm=It.OptionForm=It.VariantForm=It.TupleForm=It.RecordForm=It.InputForm=It.InputBox=void 0;var $f=class{constructor(e,r){this.idl=e,this.ui=r,this.label=null,this.value=void 0;let n=document.createElement("span");n.className="status",this.status=n,r.input&&(r.input.addEventListener("blur",()=>{r.input.value!==""&&this.parse()}),r.input.addEventListener("input",()=>{n.style.display="none",r.input.classList.remove("reject")}))}isRejected(){return this.value===void 0}parse(e={}){if(this.ui.form){let r=this.ui.form.parse(e);return this.value=r,r}if(this.ui.input){let r=this.ui.input;try{let n=this.ui.parse(this.idl,e,r.value);if(!this.idl.covariant(n))throw new Error(`${r.value} is not of type ${this.idl.display()}`);return this.status.style.display="none",this.value=n,n}catch(n){r.classList.add("reject"),this.status.style.display="block",this.status.innerHTML="InputError: "+n.message,this.value=void 0;return}}return null}render(e){let r=document.createElement("span");if(this.label){let n=document.createElement("label");n.innerText=this.label,r.appendChild(n)}this.ui.input&&(r.appendChild(this.ui.input),r.appendChild(this.status)),this.ui.form&&this.ui.form.render(r),e.appendChild(r)}};It.InputBox=$f;var ho=class{constructor(e){this.ui=e,this.form=[]}renderForm(e){this.ui.container?(this.form.forEach(r=>r.render(this.ui.container)),e.appendChild(this.ui.container)):this.form.forEach(r=>r.render(e))}render(e){if(this.ui.open&&this.ui.event){e.appendChild(this.ui.open);let r=this;r.ui.open.addEventListener(r.ui.event,()=>{if(r.ui.container)r.ui.container.innerHTML="";else{let n=r.ui.open.nextElementSibling;n&&n.parentNode.removeChild(n)}r.generateForm(),r.renderForm(e)})}else this.generateForm(),this.renderForm(e)}};It.InputForm=ho;var Kf=class extends ho{constructor(e,r){super(r),this.fields=e,this.ui=r}generateForm(){this.form=this.fields.map(([e,r])=>{let n=this.ui.render(r);return this.ui.labelMap&&this.ui.labelMap.hasOwnProperty(e)?n.label=this.ui.labelMap[e]+" ":n.label=e+" ",n})}parse(e){let r={};if(this.fields.forEach(([n,o],s)=>{let i=this.form[s].parse(e);r[n]=i}),!this.form.some(n=>n.isRejected()))return r}};It.RecordForm=Kf;var Gf=class extends ho{constructor(e,r){super(r),this.components=e,this.ui=r}generateForm(){this.form=this.components.map(e=>this.ui.render(e))}parse(e){let r=[];if(this.components.forEach((n,o)=>{let s=this.form[o].parse(e);r.push(s)}),!this.form.some(n=>n.isRejected()))return r}};It.TupleForm=Gf;var zf=class extends ho{constructor(e,r){super(r),this.fields=e,this.ui=r}generateForm(){let e=this.ui.open.selectedIndex,[r,n]=this.fields[e],o=this.ui.render(n);this.form=[o]}parse(e){let r=this.ui.open,n=r.options[r.selectedIndex].value,o=this.form[0].parse(e);if(o===void 0)return;let s={};return s[n]=o,s}};It.VariantForm=zf;var Zf=class extends ho{constructor(e,r){super(r),this.ty=e,this.ui=r}generateForm(){if(this.ui.open.checked){let e=this.ui.render(this.ty);this.form=[e]}else this.form=[]}parse(e){if(this.form.length===0)return[];{let r=this.form[0].parse(e);return r===void 0?void 0:[r]}}};It.OptionForm=Zf;var Yf=class extends ho{constructor(e,r){super(r),this.ty=e,this.ui=r}generateForm(){let e=+this.ui.open.value;this.form=[];for(let r=0;r<e;r++){let n=this.ui.render(this.ty);this.form.push(n)}}parse(e){let r=this.form.map(n=>n.parse(e));if(!this.form.some(n=>n.isRejected()))return r}};It.VecForm=Yf});var my=Z(Ee=>{"use strict";var Z2=Ee&&Ee.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),Y2=Ee&&Ee.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),hy=Ee&&Ee.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),o=0;o<n.length;o++)n[o]!=="default"&&Z2(r,e,n[o]);return Y2(r,e),r}})();Object.defineProperty(Ee,"__esModule",{value:!0});Ee.Render=Ee.vecForm=Ee.optForm=Ee.variantForm=Ee.tupleForm=Ee.recordForm=Ee.inputBox=void 0;Ee.renderInput=tp;Ee.renderValue=Wo;var ru=hy(Hf()),Xf=Ir(),Xs=hy(Wf()),W2={parse:nE},aa={render:tp},X2=(t,e)=>new Xs.InputBox(t,{...W2,...e});Ee.inputBox=X2;var J2=(t,e)=>new Xs.RecordForm(t,{...aa,...e});Ee.recordForm=J2;var Q2=(t,e)=>new Xs.TupleForm(t,{...aa,...e});Ee.tupleForm=Q2;var eE=(t,e)=>new Xs.VariantForm(t,{...aa,...e});Ee.variantForm=eE;var tE=(t,e)=>new Xs.OptionForm(t,{...aa,...e});Ee.optForm=tE;var rE=(t,e)=>new Xs.VecForm(t,{...aa,...e});Ee.vecForm=rE;var tu=class extends ru.Visitor{visitType(e,r){let n=document.createElement("input");return n.classList.add("argument"),n.placeholder=e.display(),(0,Ee.inputBox)(e,{input:n})}visitNull(e,r){return(0,Ee.inputBox)(e,{})}visitRecord(e,r,n){let o={};if(r.length>1){let i=document.createElement("div");i.classList.add("popup-form"),o={container:i}}let s=(0,Ee.recordForm)(r,o);return(0,Ee.inputBox)(e,{form:s})}visitTuple(e,r,n){let o={};if(r.length>1){let i=document.createElement("div");i.classList.add("popup-form"),o={container:i}}let s=(0,Ee.tupleForm)(r,o);return(0,Ee.inputBox)(e,{form:s})}visitVariant(e,r,n){let o=document.createElement("select");for(let[a,c]of r){let d=new Option(a);o.add(d)}o.selectedIndex=-1,o.classList.add("open");let s={open:o,event:"change"},i=(0,Ee.variantForm)(r,s);return(0,Ee.inputBox)(e,{form:i})}visitOpt(e,r,n){let o=document.createElement("input");o.type="checkbox",o.classList.add("open");let s=(0,Ee.optForm)(r,{open:o,event:"change"});return(0,Ee.inputBox)(e,{form:s})}visitVec(e,r,n){let o=document.createElement("input");o.type="number",o.min="0",o.max="100",o.style.width="8rem",o.placeholder="len",o.classList.add("open");let s=document.createElement("div");s.classList.add("popup-form");let i=(0,Ee.vecForm)(r,{open:o,event:"change",container:s});return(0,Ee.inputBox)(e,{form:i})}visitRec(e,r,n){return tp(r)}};Ee.Render=tu;var Jf=class extends ru.Visitor{visitNull(e,r){return null}visitBool(e,r){if(r==="true")return!0;if(r==="false")return!1;throw new Error(`Cannot parse ${r} as boolean`)}visitText(e,r){return r}visitFloat(e,r){return parseFloat(r)}visitFixedInt(e,r){return e._bits<=32?parseInt(r,10):BigInt(r)}visitFixedNat(e,r){return e._bits<=32?parseInt(r,10):BigInt(r)}visitNumber(e,r){return BigInt(r)}visitPrincipal(e,r){return Xf.Principal.fromText(r)}visitService(e,r){return Xf.Principal.fromText(r)}visitFunc(e,r){let n=r.split(".",2);return[Xf.Principal.fromText(n[0]),n[1]]}},Qf=class extends ru.Visitor{visitNull(e,r){return null}visitBool(e,r){return Math.random()<.5}visitText(e,r){return Math.random().toString(36).substring(6)}visitFloat(e,r){return Math.random()}visitInt(e,r){return BigInt(this.generateNumber(!0))}visitNat(e,r){return BigInt(this.generateNumber(!1))}visitFixedInt(e,r){let n=this.generateNumber(!0);return e._bits<=32?n:BigInt(r)}visitFixedNat(e,r){let n=this.generateNumber(!1);return e._bits<=32?n:BigInt(r)}generateNumber(e){let r=Math.floor(Math.random()*100);return e&&Math.random()<.5?-r:r}};function nE(t,e,r){return e.random&&r===""?t.accept(new Qf,r):t.accept(new Jf,r)}function tp(t){return t.accept(new tu,null)}function Wo(t,e,r){return t.accept(new ep,{input:e,value:r})}var ep=class extends ru.Visitor{visitType(e,r){r.input.ui.input.value=e.valueToString(r.value)}visitNull(e,r){}visitText(e,r){r.input.ui.input.value=r.value}visitRec(e,r,n){Wo(r,n.input,n.value)}visitOpt(e,r,n){if(n.value.length!==0){let o=n.input.ui.form,s=o.ui.open;s.checked=!0,s.dispatchEvent(new Event(o.ui.event)),Wo(r,o.form[0],n.value[0])}}visitRecord(e,r,n){let o=n.input.ui.form;r.forEach(([s,i],a)=>{Wo(i,o.form[a],n.value[s])})}visitTuple(e,r,n){let o=n.input.ui.form;r.forEach((s,i)=>{Wo(s,o.form[i],n.value[i])})}visitVariant(e,r,n){let o=n.input.ui.form,s=Object.entries(n.value)[0];r.forEach(([i,a],c)=>{if(i===s[0]){let d=o.ui.open;d.selectedIndex=c,d.dispatchEvent(new Event(o.ui.event)),Wo(a,o.form[0],s[1])}})}visitVec(e,r,n){let o=n.input.ui.form,s=n.value.length,i=o.ui.open;i.value=s,i.dispatchEvent(new Event(o.ui.event)),n.value.forEach((a,c)=>{Wo(r,o.form[c],a)})}}});var _y=Z(yy=>{"use strict";Object.defineProperty(yy,"__esModule",{value:!0})});var ca=Z(lt=>{"use strict";var by=lt&<.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),oE=lt&<.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),Js=lt&<.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&by(e,t,r)},sE=lt&<.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),o=0;o<n.length;o++)n[o]!=="default"&&by(r,e,n[o]);return oE(r,e),r}})();Object.defineProperty(lt,"__esModule",{value:!0});lt.IDL=void 0;Js(my(),lt);Js(Wf(),lt);lt.IDL=sE(Hf());Js(Cf(),lt);Js(Ff(),lt);Js($c(),lt);Js(_y(),lt)});var Qs=Z(ua=>{"use strict";Object.defineProperty(ua,"__esModule",{value:!0});ua.uint8FromBufLike=gy;ua.uint8ToBuf=iE;ua.uint8Equals=aE;function gy(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?gy(t.buffer):new Uint8Array(t)}function iE(t){let e=new ArrayBuffer(t.byteLength);return new Uint8Array(e).set(t),e}function aE(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 ou=Z(da=>{"use strict";Object.defineProperty(da,"__esModule",{value:!0});da.hashValue=nu;da.requestIdOf=uE;da.hashOfMap=op;var rp=ca(),xy=sr(),cE=Qs(),np=dt(),Xo=Gs();function nu(t){if(typeof t=="string")return wy(t);if(typeof t=="number")return(0,Xo.sha256)((0,rp.lebEncode)(t));if(t instanceof Uint8Array||ArrayBuffer.isView(t))return(0,Xo.sha256)((0,cE.uint8FromBufLike)(t));if(Array.isArray(t)){let e=t.map(nu);return(0,Xo.sha256)((0,np.concatBytes)(...e))}else{if(t&&typeof t=="object"&&t._isPrincipal)return(0,Xo.sha256)(t.toUint8Array());if(typeof t=="object"&&t!==null&&typeof t.toHash=="function")return nu(t.toHash());if(typeof t=="object")return op(t);if(typeof t=="bigint")return(0,Xo.sha256)((0,rp.lebEncode)(t))}throw xy.InputError.fromCode(new xy.HashValueErrorCode(t))}var wy=t=>{let e=new TextEncoder().encode(t);return(0,Xo.sha256)(e)};function uE(t){return op(t)}function op(t){let n=Object.entries(t).filter(([,i])=>i!==void 0).map(([i,a])=>{let c=wy(i),d=nu(a);return[c,d]}).sort(([i],[a])=>(0,rp.compare)(i,a)),o=(0,np.concatBytes)(...n.map(i=>(0,np.concatBytes)(...i)));return(0,Xo.sha256)(o)}});var su=Z(Xr=>{"use strict";Object.defineProperty(Xr,"__esModule",{value:!0});Xr.IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR=Xr.IC_RESPONSE_DOMAIN_SEPARATOR=Xr.IC_REQUEST_DOMAIN_SEPARATOR=Xr.DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS=void 0;Xr.DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS=300*1e3;Xr.IC_REQUEST_DOMAIN_SEPARATOR=new TextEncoder().encode(`
|
|
52
|
-
ic-request`);Xr.IC_RESPONSE_DOMAIN_SEPARATOR=new TextEncoder().encode("\vic-response");Xr.IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR=new TextEncoder().encode("ic-request-auth-delegation")});var ap=Z(Jo=>{"use strict";Object.defineProperty(Jo,"__esModule",{value:!0});Jo.AnonymousIdentity=Jo.SignIdentity=void 0;Jo.createIdentityDescriptor=fE;var Ey=Ir(),dE=ou(),Ty=dt(),lE=su(),sp=class{getPrincipal(){return this._principal||(this._principal=Ey.Principal.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:r,...n}=e,o=(0,dE.requestIdOf)(r);return{...n,body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign((0,Ty.concatBytes)(lE.IC_REQUEST_DOMAIN_SEPARATOR,o))}}}};Jo.SignIdentity=sp;var ip=class{getPrincipal(){return Ey.Principal.anonymous()}async transformRequest(e){return{...e,body:{content:e.body}}}};Jo.AnonymousIdentity=ip;function fE(t){return"getPublicKey"in t?{type:"PublicKeyIdentity",publicKey:(0,Ty.bytesToHex)(t.getPublicKey().toDer())}:{type:"AnonymousIdentity"}}});var Ny=Z((iu,Oy)=>{(function(t,e){typeof iu=="object"&&typeof Oy<"u"?e(iu):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.Cbor={}))})(iu,function(t){"use strict";class e extends Error{constructor(j){super(j),this.name="DecodingError"}}let r=55799,n=Symbol("CBOR_STOP_CODE");var o=(D=>(D[D.False=20]="False",D[D.True=21]="True",D[D.Null=22]="Null",D[D.Undefined=23]="Undefined",D[D.Break=31]="Break",D))(o||{}),s=(D=>(D[D.UnsignedInteger=0]="UnsignedInteger",D[D.NegativeInteger=1]="NegativeInteger",D[D.ByteString=2]="ByteString",D[D.TextString=3]="TextString",D[D.Array=4]="Array",D[D.Map=5]="Map",D[D.Tag=6]="Tag",D[D.Simple=7]="Simple",D))(s||{});let i=23,a=255,c=65535,d=4294967295,p=BigInt("0xffffffffffffffff");var l=(D=>(D[D.Value=23]="Value",D[D.OneByte=24]="OneByte",D[D.TwoBytes=25]="TwoBytes",D[D.FourBytes=26]="FourBytes",D[D.EightBytes=27]="EightBytes",D[D.Indefinite=31]="Indefinite",D))(l||{});let u=!1;function f(D){return D==null}function h(D,j){let se=new Uint8Array(j);return se.set(D),se}let m=new TextDecoder;function b(D){return(D&224)>>5}function y(D){return D&31}let x=new Uint8Array,_,T=0;function N(D,j){x=D,T=0;let se=I(j);return j?.(se)??se}function I(D){let[j,se]=v();switch(j){case s.UnsignedInteger:return V(se);case s.NegativeInteger:return C(se);case s.ByteString:return g(se);case s.TextString:return w(se);case s.Array:return A(se,D);case s.Map:return S(se,D);case s.Tag:return O(se,D);case s.Simple:return E(se)}throw new e(`Unsupported major type: ${j}`)}function v(){let D=x.at(T);if(f(D))throw new e("Provided CBOR data is empty");let j=b(D),se=y(D);return T++,[j,se]}function A(D,j){let se=V(D);if(se===1/0){let Ot=[],bt=I(j);for(;bt!==n;)Ot.push(j?.(bt)??bt),bt=I(j);return Ot}let Tt=new Array(se);for(let Ot=0;Ot<se;Ot++){let bt=I(j);Tt[Ot]=j?.(bt)??bt}return Tt}function E(D){switch(D){case o.False:return!1;case o.True:return!0;case o.Null:return null;case o.Undefined:return;case o.Break:return n}throw new e(`Unrecognized simple type: ${D.toString(2)}`)}function S(D,j){let se=V(D),Tt={};if(se===1/0){let[Ot,bt]=v();for(;Ot!==s.Simple&&bt!==o.Break;){let Hr=w(bt),En=I(j);Tt[Hr]=j?.(En,Hr)??En,[Ot,bt]=v()}return Tt}for(let Ot=0;Ot<se;Ot++){let[bt,Hr]=v();if(bt!==s.TextString)throw new e("Map keys must be text strings");let En=w(Hr),js=I(j);Tt[En]=j?.(js,En)??js}return Tt}function V(D){if(D<=l.Value)return D;switch(_=new DataView(x.buffer,x.byteOffset+T),D){case l.OneByte:return T++,_.getUint8(0);case l.TwoBytes:return T+=2,_.getUint16(0,u);case l.FourBytes:return T+=4,_.getUint32(0,u);case l.EightBytes:return T+=8,_.getBigUint64(0,u);case l.Indefinite:return 1/0;default:throw new e(`Unsupported integer info: ${D.toString(2)}`)}}function C(D){let j=V(D);return typeof j=="number"?-1-j:-1n-j}function g(D){let j=V(D);if(j>Number.MAX_SAFE_INTEGER)throw new e("Byte length is too large");let se=Number(j);return T+=se,x.slice(T-se,T)}function w(D){let j=g(D);return m.decode(j)}function O(D,j){let se=V(D);if(se===r)return I(j);throw new e(`Unsupported tag: ${se}.`)}class P extends Error{constructor(j){super(j),this.name="SerializationError"}}let L=2*1024,R=100,B=new TextEncoder;function F(D){return D<<5}let U=new Uint8Array(L),q=new DataView(U.buffer),H=0,Y=[];function G(D,j){H=0;let se=j?.(D)??D;return ae(se,j),U.slice(0,H)}function ie(D,j){H=0;let se=j?.(D)??D;return Xi(r,se,j),U.slice(0,H)}function ae(D,j){if(H>U.length-R&&(U=h(U,U.length*2),q=new DataView(U.buffer)),D===!1||D===!0||D===null||D===void 0){lr(D);return}if(typeof D=="number"||typeof D=="bigint"){Wi(D);return}if(typeof D=="string"){Ms(D);return}if(D instanceof Uint8Array){ks(D);return}if(D instanceof ArrayBuffer){ks(new Uint8Array(D));return}if(Array.isArray(D)){Ce(D,j);return}if(typeof D=="object"){ee(D,j);return}throw new P(`Unsupported type: ${typeof D}`)}function Ce(D,j){ce(s.Array,D.length),D.forEach((se,Tt)=>{ae(j?.(se,Tt.toString())??se,j)})}function ee(D,j){Y=Object.entries(D),ce(s.Map,Y.length),Y.forEach(([se,Tt])=>{Ms(se),ae(j?.(Tt,se)??Tt,j)})}function ce(D,j){if(j<=i){q.setUint8(H++,F(D)|Number(j));return}if(j<=a){q.setUint8(H++,F(D)|l.OneByte),q.setUint8(H,Number(j)),H+=1;return}if(j<=c){q.setUint8(H++,F(D)|l.TwoBytes),q.setUint16(H,Number(j),u),H+=2;return}if(j<=d){q.setUint8(H++,F(D)|l.FourBytes),q.setUint32(H,Number(j),u),H+=4;return}if(j<=p){q.setUint8(H++,F(D)|l.EightBytes),q.setBigUint64(H,BigInt(j),u),H+=8;return}throw new P(`Value too large to encode: ${j}`)}function lr(D){ce(s.Simple,vr(D))}function vr(D){if(D===!1)return o.False;if(D===!0)return o.True;if(D===null)return o.Null;if(D===void 0)return o.Undefined;throw new P(`Unrecognized simple value: ${D.toString()}`)}function fr(D,j){ce(D,j.length),H>U.length-j.length&&(U=h(U,U.length+j.length),q=new DataView(U.buffer)),U.set(j,H),H+=j.length}function wn(D,j){ce(D,j)}function io(D){wn(s.UnsignedInteger,D)}function Yi(D){wn(s.NegativeInteger,typeof D=="bigint"?-1n-D:-1-D)}function Wi(D){D>=0?io(D):Yi(D)}function Ms(D){fr(s.TextString,B.encode(D))}function ks(D){fr(s.ByteString,D)}function Xi(D,j,se){ce(s.Tag,D),ae(j,se)}t.DecodingError=e,t.EncodingError=P,t.decode=N,t.encode=G,t.encodeWithSelfDescribedTag=ie,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})})});var la=Z(Wt=>{"use strict";var pE=Wt&&Wt.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),hE=Wt&&Wt.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),mE=Wt&&Wt.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),o=0;o<n.length;o++)n[o]!=="default"&&pE(r,e,n[o]);return hE(r,e),r}})();Object.defineProperty(Wt,"__esModule",{value:!0});Wt.Cbor=Wt.ToCborValue=void 0;Wt.encode=Iy;Wt.decode=Ry;var yE=Ir(),vy=mE(Ny()),au=sr(),_E=fa(),cp=class{};Wt.ToCborValue=cp;function bE(t){return typeof t=="object"&&t!==null&&"toCborValue"in t}function Iy(t){try{return vy.encodeWithSelfDescribedTag(t,e=>yE.Principal.isPrincipal(e)?e.toUint8Array():_E.Expiry.isExpiry(e)?e.toBigInt():bE(e)?e.toCborValue():e)}catch(e){throw au.InputError.fromCode(new au.CborEncodeErrorCode(e,t))}}function Ry(t){try{return vy.decode(t)}catch(e){throw au.InputError.fromCode(new au.CborDecodeErrorCode(e,t))}}Wt.Cbor={encode:Iy,decode:Ry}});var up=Z(cu=>{"use strict";Object.defineProperty(cu,"__esModule",{value:!0});cu.randomNumber=void 0;var gE=()=>{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)};cu.randomNumber=gE});var ei=Z(Rn=>{"use strict";Object.defineProperty(Rn,"__esModule",{value:!0});Rn.ReadRequestType=Rn.SubmitRequestType=Rn.Endpoint=void 0;Rn.makeNonce=xE;var uu=up(),Sy;(function(t){t.Query="read",t.ReadState="read_state",t.Call="call"})(Sy||(Rn.Endpoint=Sy={}));var Ay;(function(t){t.Call="call"})(Ay||(Rn.SubmitRequestType=Ay={}));var By;(function(t){t.Query="query",t.ReadState="read_state"})(By||(Rn.ReadRequestType=By={}));function xE(){let t=new ArrayBuffer(16),e=new DataView(t),r=(0,uu.randomNumber)(),n=(0,uu.randomNumber)(),o=(0,uu.randomNumber)(),s=(0,uu.randomNumber)();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})}});var fu=Z(ir=>{"use strict";Object.defineProperty(ir,"__esModule",{value:!0});ir.Expiry=ir.JSON_KEY_EXPIRY=void 0;ir.makeNonceTransform=NE;ir.makeExpiryTransform=vE;ir.httpHeadersTransform=IE;var wE=ca(),Cy=ei(),du=sr();ir.JSON_KEY_EXPIRY="__expiry__";var dp=BigInt(1e3),EE=BigInt(1e6),Py=BigInt(60),TE=BigInt(90)*dp;function Dy(t){return t/dp}function OE(t){return Dy(t)/Py}var lu=class t{constructor(e){this.__expiry__=e,this._isExpiry=!0}static fromDeltaInMilliseconds(e,r=0){let n=BigInt(e),o=BigInt(Date.now())+n+BigInt(r),s;return n<TE?s=Dy(o):s=OE(o)*Py,new t(s*dp*EE)}toBigInt(){return this.__expiry__}toHash(){return(0,wE.lebEncode)(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[ir.JSON_KEY_EXPIRY]:this.toString()}}static fromJSON(e){let r=JSON.parse(e);if(r[ir.JSON_KEY_EXPIRY])try{let n=BigInt(r[ir.JSON_KEY_EXPIRY]);return new t(n)}catch(n){throw new du.InputError(new du.ExpiryJsonDeserializeErrorCode(`Not a valid BigInt: ${n}`))}throw new du.InputError(new du.ExpiryJsonDeserializeErrorCode(`The input does not contain the key ${ir.JSON_KEY_EXPIRY}`))}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"}};ir.Expiry=lu;function NE(t=Cy.makeNonce){return async e=>{let r=e.request.headers;e.request.headers=r,e.endpoint===Cy.Endpoint.Call&&(e.body.nonce=t())}}function vE(t){return async e=>{e.body.ingress_expiry=lu.fromDeltaInMilliseconds(t)}}function IE(t){let e=[];return t.forEach((r,n)=>{e.push([n,r])}),e}});var Rr=Z(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});re.notImplemented=re.bitMask=re.utf8ToBytes=re.randomBytes=re.isBytes=re.hexToBytes=re.concatBytes=re.bytesToUtf8=re.bytesToHex=re.anumber=re.abytes=void 0;re.abool=RE;re._abool2=SE;re._abytes2=AE;re.numberToHexUnpadded=Fy;re.hexToNumber=fp;re.bytesToNumberBE=BE;re.bytesToNumberLE=CE;re.numberToBytesBE=Vy;re.numberToBytesLE=PE;re.numberToVarBytesBE=DE;re.ensureBytes=FE;re.equalBytes=VE;re.copyBytes=UE;re.asciiToBytes=LE;re.inRange=Uy;re.aInRange=qE;re.bitLen=ME;re.bitGet=kE;re.bitSet=jE;re.createHmacDrbg=$E;re.validateObject=GE;re.isHash=zE;re._validateObject=ZE;re.memoized=WE;var Jr=dt(),Sn=dt();Object.defineProperty(re,"abytes",{enumerable:!0,get:function(){return Sn.abytes}});Object.defineProperty(re,"anumber",{enumerable:!0,get:function(){return Sn.anumber}});Object.defineProperty(re,"bytesToHex",{enumerable:!0,get:function(){return Sn.bytesToHex}});Object.defineProperty(re,"bytesToUtf8",{enumerable:!0,get:function(){return Sn.bytesToUtf8}});Object.defineProperty(re,"concatBytes",{enumerable:!0,get:function(){return Sn.concatBytes}});Object.defineProperty(re,"hexToBytes",{enumerable:!0,get:function(){return Sn.hexToBytes}});Object.defineProperty(re,"isBytes",{enumerable:!0,get:function(){return Sn.isBytes}});Object.defineProperty(re,"randomBytes",{enumerable:!0,get:function(){return Sn.randomBytes}});Object.defineProperty(re,"utf8ToBytes",{enumerable:!0,get:function(){return Sn.utf8ToBytes}});var pu=BigInt(0),pa=BigInt(1);function RE(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}function SE(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}"`;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function AE(t,e,r=""){let n=(0,Jr.isBytes)(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return t}function Fy(t){let e=t.toString(16);return e.length&1?"0"+e:e}function fp(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?pu:BigInt("0x"+t)}function BE(t){return fp((0,Jr.bytesToHex)(t))}function CE(t){return(0,Jr.abytes)(t),fp((0,Jr.bytesToHex)(Uint8Array.from(t).reverse()))}function Vy(t,e){return(0,Jr.hexToBytes)(t.toString(16).padStart(e*2,"0"))}function PE(t,e){return Vy(t,e).reverse()}function DE(t){return(0,Jr.hexToBytes)(Fy(t))}function FE(t,e,r){let n;if(typeof e=="string")try{n=(0,Jr.hexToBytes)(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if((0,Jr.isBytes)(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(t+" of length "+r+" expected, got "+o);return n}function VE(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function UE(t){return Uint8Array.from(t)}function LE(t){return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var lp=t=>typeof t=="bigint"&&pu<=t;function Uy(t,e,r){return lp(t)&&lp(e)&&lp(r)&&e<=t&&t<r}function qE(t,e,r,n){if(!Uy(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function ME(t){let e;for(e=0;t>pu;t>>=pa,e+=1);return e}function kE(t,e){return t>>BigInt(e)&pa}function jE(t,e,r){return t|(r?pa:pu)<<BigInt(e)}var HE=t=>(pa<<BigInt(t))-pa;re.bitMask=HE;function $E(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=f=>new Uint8Array(f),o=f=>Uint8Array.of(f),s=n(t),i=n(t),a=0,c=()=>{s.fill(1),i.fill(0),a=0},d=(...f)=>r(i,s,...f),p=(f=n(0))=>{i=d(o(0),f),s=d(),f.length!==0&&(i=d(o(1),f),s=d())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<e;){s=d();let m=s.slice();h.push(m),f+=s.length}return(0,Jr.concatBytes)(...h)};return(f,h)=>{c(),p(f);let m;for(;!(m=h(l()));)p();return c(),m}}var KE={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||(0,Jr.isBytes)(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function GE(t,e,r={}){let n=(o,s,i)=>{let a=KE[s];if(typeof a!="function")throw new Error("invalid validator function");let c=t[o];if(!(i&&c===void 0)&&!a(c,t))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(e))n(o,s,!1);for(let[o,s]of Object.entries(r))n(o,s,!0);return t}function zE(t){return typeof t=="function"&&Number.isSafeInteger(t.outputLen)}function ZE(t,e,r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(o,s,i){let a=t[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(e).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var YE=()=>{throw new Error("not implemented")};re.notImplemented=YE;function WE(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let s=t(r,...n);return e.set(r,s),s}}});var Qr=Z(je=>{"use strict";Object.defineProperty(je,"__esModule",{value:!0});je.isNegativeLE=void 0;je.mod=Xt;je.pow=QE;je.pow2=eT;je.invert=hu;je.tonelliShanks=hp;je.FpSqrt=$y;je.validateField=sT;je.FpPow=mp;je.FpInvertBatch=Ky;je.FpDiv=iT;je.FpLegendre=mu;je.FpIsSquare=aT;je.nLength=yp;je.Field=yu;je.FpSqrtOdd=cT;je.FpSqrtEven=uT;je.hashToPrivateScalar=dT;je.getFieldBytesLength=_p;je.getMinHashLength=Gy;je.mapHashToField=lT;var Jt=Rr(),Vt=BigInt(0),et=BigInt(1),Qo=BigInt(2),Ly=BigInt(3),qy=BigInt(4),My=BigInt(5),XE=BigInt(7),ky=BigInt(8),JE=BigInt(9),jy=BigInt(16);function Xt(t,e){let r=t%e;return r>=Vt?r:e+r}function QE(t,e,r){return mp(yu(r),t,e)}function eT(t,e,r){let n=t;for(;e-- >Vt;)n*=n,n%=r;return n}function hu(t,e){if(t===Vt)throw new Error("invert: expected non-zero number");if(e<=Vt)throw new Error("invert: expected positive modulus, got "+e);let r=Xt(t,e),n=e,o=Vt,s=et,i=et,a=Vt;for(;r!==Vt;){let d=n/r,p=n%r,l=o-i*d,u=s-a*d;n=r,r=p,o=i,s=a,i=l,a=u}if(n!==et)throw new Error("invert: does not exist");return Xt(o,e)}function pp(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function Hy(t,e){let r=(t.ORDER+et)/qy,n=t.pow(e,r);return pp(t,n,e),n}function tT(t,e){let r=(t.ORDER-My)/ky,n=t.mul(e,Qo),o=t.pow(n,r),s=t.mul(e,o),i=t.mul(t.mul(s,Qo),o),a=t.mul(s,t.sub(i,t.ONE));return pp(t,a,e),a}function rT(t){let e=yu(t),r=hp(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+XE)/jy;return(a,c)=>{let d=a.pow(c,i),p=a.mul(d,n),l=a.mul(d,o),u=a.mul(d,s),f=a.eql(a.sqr(p),c),h=a.eql(a.sqr(l),c);d=a.cmov(d,p,f),p=a.cmov(u,l,h);let m=a.eql(a.sqr(p),c),b=a.cmov(d,p,m);return pp(a,b,c),b}}function hp(t){if(t<Ly)throw new Error("sqrt is not defined for small field");let e=t-et,r=0;for(;e%Qo===Vt;)e/=Qo,r++;let n=Qo,o=yu(t);for(;mu(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Hy;let s=o.pow(n,e),i=(e+et)/Qo;return function(c,d){if(c.is0(d))return d;if(mu(c,d)!==1)throw new Error("Cannot find square root");let p=r,l=c.mul(c.ONE,s),u=c.pow(d,e),f=c.pow(d,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let h=1,m=c.sqr(u);for(;!c.eql(m,c.ONE);)if(h++,m=c.sqr(m),h===p)throw new Error("Cannot find square root");let b=et<<BigInt(p-h-1),y=c.pow(l,b);p=h,l=c.sqr(y),u=c.mul(u,l),f=c.mul(f,y)}return f}}function $y(t){return t%qy===Ly?Hy:t%ky===My?tT:t%jy===JE?rT(t):hp(t)}var nT=(t,e)=>(Xt(t,e)&et)===et;je.isNegativeLE=nT;var oT=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function sT(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=oT.reduce((n,o)=>(n[o]="function",n),e);return(0,Jt._validateObject)(t,r),t}function mp(t,e,r){if(r<Vt)throw new Error("invalid exponent, negatives unsupported");if(r===Vt)return t.ONE;if(r===et)return e;let n=t.ONE,o=e;for(;r>Vt;)r&et&&(n=t.mul(n,o)),o=t.sqr(o),r>>=et;return n}function Ky(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),o=e.reduce((i,a,c)=>t.is0(a)?i:(n[c]=i,t.mul(i,a)),t.ONE),s=t.inv(o);return e.reduceRight((i,a,c)=>t.is0(a)?i:(n[c]=t.mul(i,n[c]),t.mul(i,a)),s),n}function iT(t,e,r){return t.mul(e,typeof r=="bigint"?hu(r,t.ORDER):t.inv(r))}function mu(t,e){let r=(t.ORDER-et)/Qo,n=t.pow(e,r),o=t.eql(n,t.ONE),s=t.eql(n,t.ZERO),i=t.eql(n,t.neg(t.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function aT(t,e){return mu(t,e)===1}function yp(t,e){e!==void 0&&(0,Jt.anumber)(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function yu(t,e,r=!1,n={}){if(t<=Vt)throw new Error("invalid field: expected ORDER > 0, got "+t);let o,s,i=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=e;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),a=u.allowedLengths}else typeof e=="number"&&(o=e),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:d}=yp(t,o);if(d>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,l=Object.freeze({ORDER:t,isLE:r,BITS:c,BYTES:d,MASK:(0,Jt.bitMask)(c),ZERO:Vt,ONE:et,allowedLengths:a,create:u=>Xt(u,t),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return Vt<=u&&u<t},is0:u=>u===Vt,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&et)===et,neg:u=>Xt(-u,t),eql:(u,f)=>u===f,sqr:u=>Xt(u*u,t),add:(u,f)=>Xt(u+f,t),sub:(u,f)=>Xt(u-f,t),mul:(u,f)=>Xt(u*f,t),pow:(u,f)=>mp(l,u,f),div:(u,f)=>Xt(u*hu(f,t),t),sqrN:u=>u*u,addN:(u,f)=>u+f,subN:(u,f)=>u-f,mulN:(u,f)=>u*f,inv:u=>hu(u,t),sqrt:s||(u=>(p||(p=$y(t)),p(l,u))),toBytes:u=>r?(0,Jt.numberToBytesLE)(u,d):(0,Jt.numberToBytesBE)(u,d),fromBytes:(u,f=!0)=>{if(a){if(!a.includes(u.length)||u.length>d)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let m=new Uint8Array(d);m.set(u,r?0:m.length-u.length),u=m}if(u.length!==d)throw new Error("Field.fromBytes: expected "+d+" bytes, got "+u.length);let h=r?(0,Jt.bytesToNumberLE)(u):(0,Jt.bytesToNumberBE)(u);if(i&&(h=Xt(h,t)),!f&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:u=>Ky(l,u),cmov:(u,f,h)=>h?f:u});return Object.freeze(l)}function cT(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?r:t.neg(r)}function uT(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}function dT(t,e,r=!1){t=(0,Jt.ensureBytes)("privateHash",t);let n=t.length,o=yp(e).nByteLength+8;if(o<24||n<o||n>1024)throw new Error("hashToPrivateScalar: expected "+o+"-1024 bytes of input, got "+n);let s=r?(0,Jt.bytesToNumberLE)(t):(0,Jt.bytesToNumberBE)(t);return Xt(s,e-et)+et}function _p(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Gy(t){let e=_p(t);return e+Math.ceil(e/2)}function lT(t,e,r=!1){let n=t.length,o=_p(e),s=Gy(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?(0,Jt.bytesToNumberLE)(t):(0,Jt.bytesToNumberBE)(t),a=Xt(i,e-et)+et;return r?(0,Jt.numberToBytesLE)(a,o):(0,Jt.numberToBytesBE)(a,o)}});var ya=Z(Sr=>{"use strict";Object.defineProperty(Sr,"__esModule",{value:!0});Sr.wNAF=void 0;Sr.negateCt=wp;Sr.normalizeZ=fT;Sr.mulEndoUnsafe=pT;Sr.pippenger=hT;Sr.precomputeMSMUnsafe=mT;Sr.validateBasic=yT;Sr._createCurveFields=_T;var ha=Rr(),ma=Qr(),ti=BigInt(0),es=BigInt(1);function wp(t,e){let r=e.negate();return t?r:e}function fT(t,e){let r=(0,ma.FpInvertBatch)(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function Tp(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function bp(t,e){Tp(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=(0,ha.bitMask)(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function zy(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=es);let d=e*n,p=d+Math.abs(a)-1,l=a===0,u=a<0,f=e%2!==0;return{nextN:c,offset:p,isZero:l,isNeg:u,isNegF:f,offsetF:d}}function Wy(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Xy(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var gp=new WeakMap,Jy=new WeakMap;function xp(t){return Jy.get(t)||1}function Zy(t){if(t!==ti)throw new Error("invalid wNAF")}var Ep=class{constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>ti;)r&es&&(n=n.add(o)),o=o.double(),r>>=es;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=bp(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let d=1;d<o;d++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=bp(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:d,isZero:p,isNeg:l,isNegF:u,offsetF:f}=zy(n,a,i);n=c,p?s=s.add(wp(u,r[f])):o=o.add(wp(l,r[d]))}return Zy(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=bp(e,this.bits);for(let i=0;i<s.windows&&n!==ti;i++){let{nextN:a,offset:c,isZero:d,isNeg:p}=zy(n,i,s);if(n=a,!d){let l=r[c];o=o.add(p?l.negate():l)}}return Zy(n),o}getPrecomputes(e,r,n){let o=gp.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),gp.set(r,o))),o}cached(e,r,n){let o=xp(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=xp(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){Tp(r,this.bits),Jy.set(e,r),gp.delete(e)}hasCache(e){return xp(e)!==1}};Sr.wNAF=Ep;function pT(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>ti||n>ti;)r&es&&(s=s.add(o)),n&es&&(i=i.add(o)),o=o.double(),r>>=es,n>>=es;return{p1:s,p2:i}}function hT(t,e,r,n){Wy(r,t),Xy(n,e);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=t.ZERO,a=(0,ha.bitLen)(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let d=(0,ha.bitMask)(c),p=new Array(Number(d)+1).fill(i),l=Math.floor((e.BITS-1)/c)*c,u=i;for(let f=l;f>=0;f-=c){p.fill(i);for(let m=0;m<s;m++){let b=n[m],y=Number(b>>BigInt(f)&d);p[y]=p[y].add(r[m])}let h=i;for(let m=p.length-1,b=i;m>0;m--)b=b.add(p[m]),h=h.add(b);if(u=u.add(h),f!==0)for(let m=0;m<c;m++)u=u.double()}return u}function mT(t,e,r,n){Tp(n,e.BITS),Wy(r,t);let o=t.ZERO,s=2**n-1,i=Math.ceil(e.BITS/n),a=(0,ha.bitMask)(n),c=r.map(d=>{let p=[];for(let l=0,u=d;l<s;l++)p.push(u),u=u.add(d);return p});return d=>{if(Xy(d,e),d.length>r.length)throw new Error("array of scalars must be smaller than array of points");let p=o;for(let l=0;l<i;l++){if(p!==o)for(let f=0;f<n;f++)p=p.double();let u=BigInt(i*n-(l+1)*n);for(let f=0;f<d.length;f++){let h=d[f],m=Number(h>>u&a);m&&(p=p.add(c[f][m-1]))}}return p}}function yT(t){return(0,ma.validateField)(t.Fp),(0,ha.validateObject)(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,ma.nLength)(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function Yy(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return(0,ma.validateField)(e),e}else return(0,ma.Field)(t,{isLE:r})}function _T(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let d=e[c];if(!(typeof d=="bigint"&&d>ti))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Yy(e.p,r.Fp,n),s=Yy(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}});var bu=Z(en=>{"use strict";Object.defineProperty(en,"__esModule",{value:!0});en._DST_scalar=void 0;en.expand_message_xmd=t_;en.expand_message_xof=r_;en.hash_to_field=_u;en.isogenyMap=xT;en.createHasher=wT;var gt=Rr(),Qy=Qr(),bT=gt.bytesToNumberBE;function mo(t,e){if(_a(t),_a(e),t<0||t>=1<<8*e)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 gT(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 _a(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function e_(t){if(!(0,gt.isBytes)(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or string");return typeof t=="string"?(0,gt.utf8ToBytes)(t):t}function t_(t,e,r,n){(0,gt.abytes)(t),_a(r),e=e_(e),e.length>255&&(e=n((0,gt.concatBytes)((0,gt.utf8ToBytes)("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 a=(0,gt.concatBytes)(e,mo(e.length,1)),c=mo(0,s),d=mo(r,2),p=new Array(i),l=n((0,gt.concatBytes)(c,t,d,mo(0,1),a));p[0]=n((0,gt.concatBytes)(l,mo(1,1),a));for(let f=1;f<=i;f++){let h=[gT(l,p[f-1]),mo(f+1,1),a];p[f]=n((0,gt.concatBytes)(...h))}return(0,gt.concatBytes)(...p).slice(0,r)}function r_(t,e,r,n,o){if((0,gt.abytes)(t),_a(r),e=e_(e),e.length>255){let s=Math.ceil(2*n/8);e=o.create({dkLen:s}).update((0,gt.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return o.create({dkLen:r}).update(t).update(mo(r,2)).update(e).update(mo(e.length,1)).digest()}function _u(t,e,r){(0,gt._validateObject)(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:o,m:s,hash:i,expand:a,DST:c}=r;if(!(0,gt.isHash)(r.hash))throw new Error("expected valid hash");(0,gt.abytes)(t),_a(e);let d=n.toString(2).length,p=Math.ceil((d+o)/8),l=e*s*p,u;if(a==="xmd")u=t_(t,c,l,i);else if(a==="xof")u=r_(t,c,l,o,i);else if(a==="_internal_pass")u=t;else throw new Error('expand must be "xmd" or "xof"');let f=new Array(e);for(let h=0;h<e;h++){let m=new Array(s);for(let b=0;b<s;b++){let y=p*(b+h*s),x=u.subarray(y,y+p);m[b]=(0,Qy.mod)(bT(x),n)}f[h]=m}return f}function xT(t,e){let r=e.map(n=>Array.from(n).reverse());return(n,o)=>{let[s,i,a,c]=r.map(l=>l.reduce((u,f)=>t.add(t.mul(u,n),f))),[d,p]=(0,Qy.FpInvertBatch)(t,[i,c],!0);return n=t.mul(s,d),o=t.mul(o,t.mul(a,p)),{x:n,y:o}}}en._DST_scalar=(0,gt.utf8ToBytes)("HashToScalar-");function wT(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function n(s){return t.fromAffine(e(s))}function o(s){let i=s.clearCofactor();return i.equals(t.ZERO)?t.ZERO:(i.assertValidity(),i)}return{defaults:r,hashToCurve(s,i){let a=Object.assign({},r,i),c=_u(s,2,a),d=n(c[0]),p=n(c[1]);return o(d.add(p))},encodeToCurve(s,i){let a=r.encodeDST?{DST:r.encodeDST}:{},c=Object.assign({},r,a,i),d=_u(s,1,c),p=n(d[0]);return o(p)},mapToCurve(s){if(!Array.isArray(s))throw new Error("expected array of bigints");for(let i of s)if(typeof i!="bigint")throw new Error("expected array of bigints");return o(n(s))},hashToScalar(s,i){let a=t.Fn.ORDER,c=Object.assign({},r,{p:a,m:1,DST:en._DST_scalar},i);return _u(s,1,c)[0][0]}}}});var n_=Z(rs=>{"use strict";Object.defineProperty(rs,"__esModule",{value:!0});rs.hmac=rs.HMAC=void 0;var ts=dt(),ba=class extends ts.Hash{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,(0,ts.ahash)(e);let n=(0,ts.toBytes)(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?e.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),(0,ts.clean)(s)}update(e){return(0,ts.aexists)(this),this.iHash.update(e),this}digestInto(e){(0,ts.aexists)(this),(0,ts.abytes)(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};rs.HMAC=ba;var ET=(t,e,r)=>new ba(t,e).update(r).digest();rs.hmac=ET;rs.hmac.create=(t,e)=>new ba(t,e)});var Rp=Z(qe=>{"use strict";Object.defineProperty(qe,"__esModule",{value:!0});qe.DER=qe.DERErr=void 0;qe._splitEndoScalar=s_;qe._normFnElement=yo;qe.weierstrassN=Ip;qe.SWUFpSqrtRatio=a_;qe.mapToCurveSimpleSWU=NT;qe.ecdh=u_;qe.ecdsa=d_;qe.weierstrassPoints=vT;qe._legacyHelperEquat=f_;qe.weierstrass=AT;var TT=n_(),OT=dt(),W=Rr(),An=ya(),ni=Qr(),o_=(t,e)=>(t+(t>=0?e:-e)/tn)/e;function s_(t,e,r){let[[n,o],[s,i]]=e,a=o_(i*t,r),c=o_(-o*t,r),d=t-a*n-c*s,p=-a*o-c*i,l=d<Ar,u=p<Ar;l&&(d=-d),u&&(p=-p);let f=(0,W.bitMask)(Math.ceil((0,W.bitLen)(r)/2))+xt;if(d<Ar||d>=f||p<Ar||p>=f)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:l,k1:d,k2neg:u,k2:p}}function Np(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Op(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return(0,W._abool2)(r.lowS,"lowS"),(0,W._abool2)(r.prehash,"prehash"),r.format!==void 0&&Np(r.format),r}var gu=class extends Error{constructor(e=""){super(e)}};qe.DERErr=gu;qe.DER={Err:gu,_tlv:{encode:(t,e)=>{let{Err:r}=qe.DER;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=(0,W.numberToHexUnpadded)(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?(0,W.numberToHexUnpadded)(o.length/2|128):"";return(0,W.numberToHexUnpadded)(t)+s+o+e},decode(t,e){let{Err:r}=qe.DER,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let d=e.subarray(n,n+c);if(d.length!==c)throw new r("tlv.decode: length bytes not complete");if(d[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let p of d)i=i<<8|p;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=qe.DER;if(t<Ar)throw new e("integer: negative integers are not allowed");let r=(0,W.numberToHexUnpadded)(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=qe.DER;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return(0,W.bytesToNumberBE)(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=qe.DER,o=(0,W.ensureBytes)("signature",t),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:d,l:p}=n.decode(2,c);if(p.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(d)}},hexFromSig(t){let{_tlv:e,_int:r}=qe.DER,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};var Ar=BigInt(0),xt=BigInt(1),tn=BigInt(2),ri=BigInt(3),vp=BigInt(4);function yo(t,e){let{BYTES:r}=t,n;if(typeof e=="bigint")n=e;else{let o=(0,W.ensureBytes)("private key",e);try{n=t.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`)}}if(!t.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Ip(t,e={}){let r=(0,An._createCurveFields)("weierstrass",t,e),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;(0,W._validateObject)(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=c_(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,g,w){let{x:O,y:P}=g.toAffine(),L=n.toBytes(O);if((0,W._abool2)(w,"isCompressed"),w){p();let R=!n.isOdd(P);return(0,W.concatBytes)(i_(R),L)}else return(0,W.concatBytes)(Uint8Array.of(4),L,n.toBytes(P))}function u(C){(0,W._abytes2)(C,void 0,"Point");let{publicKey:g,publicKeyUncompressed:w}=d,O=C.length,P=C[0],L=C.subarray(1);if(O===g&&(P===2||P===3)){let R=n.fromBytes(L);if(!n.isValid(R))throw new Error("bad point: is not on curve, wrong x");let B=m(R),F;try{F=n.sqrt(B)}catch(H){let Y=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}p();let U=n.isOdd(F);return(P&1)===1!==U&&(F=n.neg(F)),{x:R,y:F}}else if(O===w&&P===4){let R=n.BYTES,B=n.fromBytes(L.subarray(0,R)),F=n.fromBytes(L.subarray(R,R*2));if(!b(B,F))throw new Error("bad point: is not on curve");return{x:B,y:F}}else throw new Error(`bad point: got length ${O}, expected compressed=${g} or uncompressed=${w}`)}let f=e.toBytes||l,h=e.fromBytes||u;function m(C){let g=n.sqr(C),w=n.mul(g,C);return n.add(n.add(w,n.mul(C,s.a)),s.b)}function b(C,g){let w=n.sqr(g),O=m(C);return n.eql(w,O)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,ri),vp),x=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,x)))throw new Error("bad curve params: a or b");function _(C,g,w=!1){if(!n.isValid(g)||w&&n.is0(g))throw new Error(`bad point coordinate ${C}`);return g}function T(C){if(!(C instanceof E))throw new Error("ProjectivePoint expected")}function N(C){if(!c||!c.basises)throw new Error("no endo");return s_(C,c.basises,o.ORDER)}let I=(0,W.memoized)((C,g)=>{let{X:w,Y:O,Z:P}=C;if(n.eql(P,n.ONE))return{x:w,y:O};let L=C.is0();g==null&&(g=L?n.ONE:n.inv(P));let R=n.mul(w,g),B=n.mul(O,g),F=n.mul(P,g);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:R,y:B}}),v=(0,W.memoized)(C=>{if(C.is0()){if(e.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:w}=C.toAffine();if(!n.isValid(g)||!n.isValid(w))throw new Error("bad point: x or y not field elements");if(!b(g,w))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(C,g,w,O,P){return w=new E(n.mul(w.X,C),w.Y,w.Z),g=(0,An.negateCt)(O,g),w=(0,An.negateCt)(P,w),g.add(w)}class E{constructor(g,w,O){this.X=_("x",g),this.Y=_("y",w,!0),this.Z=_("z",O),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:w,y:O}=g||{};if(!g||!n.isValid(w)||!n.isValid(O))throw new Error("invalid affine point");if(g instanceof E)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(O)?E.ZERO:new E(w,O,n.ONE)}static fromBytes(g){let w=E.fromAffine(h((0,W._abytes2)(g,void 0,"point")));return w.assertValidity(),w}static fromHex(g){return E.fromBytes((0,W.ensureBytes)("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,w=!0){return V.createCache(this,g),w||this.multiply(ri),this}assertValidity(){v(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){T(g);let{X:w,Y:O,Z:P}=this,{X:L,Y:R,Z:B}=g,F=n.eql(n.mul(w,B),n.mul(L,P)),U=n.eql(n.mul(O,B),n.mul(R,P));return F&&U}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:w}=s,O=n.mul(w,ri),{X:P,Y:L,Z:R}=this,B=n.ZERO,F=n.ZERO,U=n.ZERO,q=n.mul(P,P),H=n.mul(L,L),Y=n.mul(R,R),G=n.mul(P,L);return G=n.add(G,G),U=n.mul(P,R),U=n.add(U,U),B=n.mul(g,U),F=n.mul(O,Y),F=n.add(B,F),B=n.sub(H,F),F=n.add(H,F),F=n.mul(B,F),B=n.mul(G,B),U=n.mul(O,U),Y=n.mul(g,Y),G=n.sub(q,Y),G=n.mul(g,G),G=n.add(G,U),U=n.add(q,q),q=n.add(U,q),q=n.add(q,Y),q=n.mul(q,G),F=n.add(F,q),Y=n.mul(L,R),Y=n.add(Y,Y),q=n.mul(Y,G),B=n.sub(B,q),U=n.mul(Y,H),U=n.add(U,U),U=n.add(U,U),new E(B,F,U)}add(g){T(g);let{X:w,Y:O,Z:P}=this,{X:L,Y:R,Z:B}=g,F=n.ZERO,U=n.ZERO,q=n.ZERO,H=s.a,Y=n.mul(s.b,ri),G=n.mul(w,L),ie=n.mul(O,R),ae=n.mul(P,B),Ce=n.add(w,O),ee=n.add(L,R);Ce=n.mul(Ce,ee),ee=n.add(G,ie),Ce=n.sub(Ce,ee),ee=n.add(w,P);let ce=n.add(L,B);return ee=n.mul(ee,ce),ce=n.add(G,ae),ee=n.sub(ee,ce),ce=n.add(O,P),F=n.add(R,B),ce=n.mul(ce,F),F=n.add(ie,ae),ce=n.sub(ce,F),q=n.mul(H,ee),F=n.mul(Y,ae),q=n.add(F,q),F=n.sub(ie,q),q=n.add(ie,q),U=n.mul(F,q),ie=n.add(G,G),ie=n.add(ie,G),ae=n.mul(H,ae),ee=n.mul(Y,ee),ie=n.add(ie,ae),ae=n.sub(G,ae),ae=n.mul(H,ae),ee=n.add(ee,ae),G=n.mul(ie,ee),U=n.add(U,G),G=n.mul(ce,ee),F=n.mul(Ce,F),F=n.sub(F,G),G=n.mul(Ce,ie),q=n.mul(ce,q),q=n.add(q,G),new E(F,U,q)}subtract(g){return this.add(g.negate())}is0(){return this.equals(E.ZERO)}multiply(g){let{endo:w}=e;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let O,P,L=R=>V.cached(this,R,B=>(0,An.normalizeZ)(E,B));if(w){let{k1neg:R,k1:B,k2neg:F,k2:U}=N(g),{p:q,f:H}=L(B),{p:Y,f:G}=L(U);P=H.add(G),O=A(w.beta,q,Y,R,F)}else{let{p:R,f:B}=L(g);O=R,P=B}return(0,An.normalizeZ)(E,[O,P])[0]}multiplyUnsafe(g){let{endo:w}=e,O=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===Ar||O.is0())return E.ZERO;if(g===xt)return O;if(V.hasCache(this))return this.multiply(g);if(w){let{k1neg:P,k1:L,k2neg:R,k2:B}=N(g),{p1:F,p2:U}=(0,An.mulEndoUnsafe)(E,O,L,B);return A(w.beta,F,U,P,R)}else return V.unsafe(O,g)}multiplyAndAddUnsafe(g,w,O){let P=this.multiplyUnsafe(w).add(g.multiplyUnsafe(O));return P.is0()?void 0:P}toAffine(g){return I(this,g)}isTorsionFree(){let{isTorsionFree:g}=e;return i===xt?!0:g?g(E,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=e;return i===xt?this:g?g(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return(0,W._abool2)(g,"isCompressed"),this.assertValidity(),f(E,this,g)}toHex(g=!0){return(0,W.bytesToHex)(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return(0,An.normalizeZ)(E,g)}static msm(g,w){return(0,An.pippenger)(E,o,g,w)}static fromPrivateKey(g){return E.BASE.multiply(yo(o,g))}}E.BASE=new E(s.Gx,s.Gy,n.ONE),E.ZERO=new E(n.ZERO,n.ONE,n.ZERO),E.Fp=n,E.Fn=o;let S=o.BITS,V=new An.wNAF(E,e.endo?Math.ceil(S/2):S);return E.BASE.precompute(8),E}function i_(t){return Uint8Array.of(t?2:3)}function a_(t,e){let r=t.ORDER,n=Ar;for(let h=r-xt;h%tn===Ar;h/=tn)n+=xt;let o=n,s=tn<<o-xt-xt,i=s*tn,a=(r-xt)/i,c=(a-xt)/tn,d=i-xt,p=s,l=t.pow(e,a),u=t.pow(e,(a+xt)/tn),f=(h,m)=>{let b=l,y=t.pow(m,d),x=t.sqr(y);x=t.mul(x,m);let _=t.mul(h,x);_=t.pow(_,c),_=t.mul(_,y),y=t.mul(_,m),x=t.mul(_,h);let T=t.mul(x,y);_=t.pow(T,p);let N=t.eql(_,t.ONE);y=t.mul(x,u),_=t.mul(T,b),x=t.cmov(y,x,N),T=t.cmov(_,T,N);for(let I=o;I>xt;I--){let v=I-tn;v=tn<<v-xt;let A=t.pow(T,v),E=t.eql(A,t.ONE);y=t.mul(x,b),b=t.mul(b,b),A=t.mul(T,b),x=t.cmov(y,x,E),T=t.cmov(A,T,E)}return{isValid:N,value:x}};if(t.ORDER%vp===ri){let h=(t.ORDER-ri)/vp,m=t.sqrt(t.neg(e));f=(b,y)=>{let x=t.sqr(y),_=t.mul(b,y);x=t.mul(x,_);let T=t.pow(x,h);T=t.mul(T,_);let N=t.mul(T,m),I=t.mul(t.sqr(T),y),v=t.eql(I,b),A=t.cmov(N,T,v);return{isValid:v,value:A}}}return f}function NT(t,e){(0,ni.validateField)(t);let{A:r,B:n,Z:o}=e;if(!t.isValid(r)||!t.isValid(n)||!t.isValid(o))throw new Error("mapToCurveSimpleSWU: invalid opts");let s=a_(t,o);if(!t.isOdd)throw new Error("Field does not have .isOdd()");return i=>{let a,c,d,p,l,u,f,h;a=t.sqr(i),a=t.mul(a,o),c=t.sqr(a),c=t.add(c,a),d=t.add(c,t.ONE),d=t.mul(d,n),p=t.cmov(o,t.neg(c),!t.eql(c,t.ZERO)),p=t.mul(p,r),c=t.sqr(d),u=t.sqr(p),l=t.mul(u,r),c=t.add(c,l),c=t.mul(c,d),u=t.mul(u,p),l=t.mul(u,n),c=t.add(c,l),f=t.mul(a,d);let{isValid:m,value:b}=s(c,u);h=t.mul(a,i),h=t.mul(h,b),f=t.cmov(f,d,m),h=t.cmov(h,b,m);let y=t.isOdd(i)===t.isOdd(h);h=t.cmov(t.neg(h),h,y);let x=(0,ni.FpInvertBatch)(t,[p],!0)[0];return f=t.mul(f,x),{x:f,y:h}}}function c_(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function u_(t,e={}){let{Fn:r}=t,n=e.randomBytes||W.randomBytes,o=Object.assign(c_(t.Fp,r),{seed:(0,ni.getMinHashLength)(r.ORDER)});function s(f){try{return!!yo(r,f)}catch{return!1}}function i(f,h){let{publicKey:m,publicKeyUncompressed:b}=o;try{let y=f.length;return h===!0&&y!==m||h===!1&&y!==b?!1:!!t.fromBytes(f)}catch{return!1}}function a(f=n(o.seed)){return(0,ni.mapHashToField)((0,W._abytes2)(f,o.seed,"seed"),r.ORDER)}function c(f,h=!0){return t.BASE.multiply(yo(r,f)).toBytes(h)}function d(f){let h=a(f);return{secretKey:h,publicKey:c(h)}}function p(f){if(typeof f=="bigint")return!1;if(f instanceof t)return!0;let{secretKey:h,publicKey:m,publicKeyUncompressed:b}=o;if(r.allowedLengths||h===m)return;let y=(0,W.ensureBytes)("key",f).length;return y===m||y===b}function l(f,h,m=!0){if(p(f)===!0)throw new Error("first arg must be private key");if(p(h)===!1)throw new Error("second arg must be public key");let b=yo(r,f);return t.fromHex(h).multiply(b).toBytes(m)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:d,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:f=>yo(r,f),precompute(f=8,h=t.BASE){return h.precompute(f,!1)}},lengths:o})}function d_(t,e,r={}){(0,OT.ahash)(e),(0,W._validateObject)(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||W.randomBytes,o=r.hmac||((w,...O)=>(0,TT.hmac)(e,w,(0,W.concatBytes)(...O))),{Fp:s,Fn:i}=t,{ORDER:a,BITS:c}=i,{keygen:d,getPublicKey:p,getSharedSecret:l,utils:u,lengths:f}=u_(t,r),h={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},m="compact";function b(w){let O=a>>xt;return w>O}function y(w,O){if(!i.isValidNot0(O))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return O}function x(w,O){Np(O);let P=f.signature,L=O==="compact"?P:O==="recovered"?P+1:void 0;return(0,W._abytes2)(w,L,`${O} signature`)}class _{constructor(O,P,L){this.r=y("r",O),this.s=y("s",P),L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(O,P=m){x(O,P);let L;if(P==="der"){let{r:U,s:q}=qe.DER.toSig((0,W._abytes2)(O));return new _(U,q)}P==="recovered"&&(L=O[0],P="compact",O=O.subarray(1));let R=i.BYTES,B=O.subarray(0,R),F=O.subarray(R,R*2);return new _(i.fromBytes(B),i.fromBytes(F),L)}static fromHex(O,P){return this.fromBytes((0,W.hexToBytes)(O),P)}addRecoveryBit(O){return new _(this.r,this.s,O)}recoverPublicKey(O){let P=s.ORDER,{r:L,s:R,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(a*tn<P&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let U=B===2||B===3?L+a:L;if(!s.isValid(U))throw new Error("recovery id 2 or 3 invalid");let q=s.toBytes(U),H=t.fromBytes((0,W.concatBytes)(i_((B&1)===0),q)),Y=i.inv(U),G=N((0,W.ensureBytes)("msgHash",O)),ie=i.create(-G*Y),ae=i.create(R*Y),Ce=t.BASE.multiplyUnsafe(ie).add(H.multiplyUnsafe(ae));if(Ce.is0())throw new Error("point at infinify");return Ce.assertValidity(),Ce}hasHighS(){return b(this.s)}toBytes(O=m){if(Np(O),O==="der")return(0,W.hexToBytes)(qe.DER.hexFromSig(this));let P=i.toBytes(this.r),L=i.toBytes(this.s);if(O==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return(0,W.concatBytes)(Uint8Array.of(this.recovery),P,L)}return(0,W.concatBytes)(P,L)}toHex(O){return(0,W.bytesToHex)(this.toBytes(O))}assertValidity(){}static fromCompact(O){return _.fromBytes((0,W.ensureBytes)("sig",O),"compact")}static fromDER(O){return _.fromBytes((0,W.ensureBytes)("sig",O),"der")}normalizeS(){return this.hasHighS()?new _(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return(0,W.bytesToHex)(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return(0,W.bytesToHex)(this.toBytes("compact"))}}let T=r.bits2int||function(O){if(O.length>8192)throw new Error("input is too large");let P=(0,W.bytesToNumberBE)(O),L=O.length*8-c;return L>0?P>>BigInt(L):P},N=r.bits2int_modN||function(O){return i.create(T(O))},I=(0,W.bitMask)(c);function v(w){return(0,W.aInRange)("num < 2^"+c,w,Ar,I),i.toBytes(w)}function A(w,O){return(0,W._abytes2)(w,void 0,"message"),O?(0,W._abytes2)(e(w),void 0,"prehashed message"):w}function E(w,O,P){if(["recovered","canonical"].some(ie=>ie in P))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:R,extraEntropy:B}=Op(P,h);w=A(w,R);let F=N(w),U=yo(i,O),q=[v(U),v(F)];if(B!=null&&B!==!1){let ie=B===!0?n(f.secretKey):B;q.push((0,W.ensureBytes)("extraEntropy",ie))}let H=(0,W.concatBytes)(...q),Y=F;function G(ie){let ae=T(ie);if(!i.isValidNot0(ae))return;let Ce=i.inv(ae),ee=t.BASE.multiply(ae).toAffine(),ce=i.create(ee.x);if(ce===Ar)return;let lr=i.create(Ce*i.create(Y+ce*U));if(lr===Ar)return;let vr=(ee.x===ce?0:2)|Number(ee.y&xt),fr=lr;return L&&b(lr)&&(fr=i.neg(lr),vr^=1),new _(ce,fr,vr)}return{seed:H,k2sig:G}}function S(w,O,P={}){w=(0,W.ensureBytes)("message",w);let{seed:L,k2sig:R}=E(w,O,P);return(0,W.createHmacDrbg)(e.outputLen,i.BYTES,o)(L,R)}function V(w){let O,P=typeof w=="string"||(0,W.isBytes)(w),L=!P&&w!==null&&typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!P&&!L)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(L)O=new _(w.r,w.s);else if(P){try{O=_.fromBytes((0,W.ensureBytes)("sig",w),"der")}catch(R){if(!(R instanceof qe.DER.Err))throw R}if(!O)try{O=_.fromBytes((0,W.ensureBytes)("sig",w),"compact")}catch{return!1}}return O||!1}function C(w,O,P,L={}){let{lowS:R,prehash:B,format:F}=Op(L,h);if(P=(0,W.ensureBytes)("publicKey",P),O=A((0,W.ensureBytes)("message",O),B),"strict"in L)throw new Error("options.strict was renamed to lowS");let U=F===void 0?V(w):_.fromBytes((0,W.ensureBytes)("sig",w),F);if(U===!1)return!1;try{let q=t.fromBytes(P);if(R&&U.hasHighS())return!1;let{r:H,s:Y}=U,G=N(O),ie=i.inv(Y),ae=i.create(G*ie),Ce=i.create(H*ie),ee=t.BASE.multiplyUnsafe(ae).add(q.multiplyUnsafe(Ce));return ee.is0()?!1:i.create(ee.x)===H}catch{return!1}}function g(w,O,P={}){let{prehash:L}=Op(P,h);return O=A(O,L),_.fromBytes(w,"recovered").recoverPublicKey(O).toBytes()}return Object.freeze({keygen:d,getPublicKey:p,getSharedSecret:l,utils:u,lengths:f,Point:t,sign:S,verify:C,recoverPublicKey:g,Signature:_,hash:e})}function vT(t){let{CURVE:e,curveOpts:r}=l_(t),n=Ip(e,r);return RT(t,n)}function l_(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=(0,ni.Field)(e.n,{BITS:t.nBitLength,allowedLengths:n,modFromBytes:t.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:s}}function IT(t){let{CURVE:e,curveOpts:r}=l_(t),n={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:r,hash:t.hash,ecdsaOpts:n}}function f_(t,e,r){function n(o){let s=t.sqr(o),i=t.mul(s,o);return t.add(t.add(i,t.mul(o,e)),r)}return n}function RT(t,e){let{Fp:r,Fn:n}=e;function o(i){return(0,W.inRange)(i,xt,n.ORDER)}let s=f_(r,t.a,t.b);return Object.assign({},{CURVE:t,Point:e,ProjectivePoint:e,normPrivateKeyToScalar:i=>yo(n,i),weierstrassEquation:s,isWithinCurveOrder:o})}function ST(t,e){let r=e.Point;return Object.assign({},e,{ProjectivePoint:r,CURVE:Object.assign({},t,(0,ni.nLength)(r.Fn.ORDER,r.Fn.BITS))})}function AT(t){let{CURVE:e,curveOpts:r,hash:n,ecdsaOpts:o}=IT(t),s=Ip(e,r),i=d_(s,n,o);return ST(t,i)}});var b_=Z(Ap=>{"use strict";Object.defineProperty(Ap,"__esModule",{value:!0});Ap.bls=DT;var ga=Rr(),p_=ya(),h_=bu(),m_=Qr(),wu=Rp(),BT=BigInt(0),xu=BigInt(1),y_=BigInt(2),oi=BigInt(3);function CT(t){let e=[];for(;t>xu;t>>=xu)(t&xu)===BT?e.unshift(0):(t&oi)===oi?(e.unshift(-1),t+=xu):e.unshift(1);return e}function Sp(t){if(!Array.isArray(t)||t.length===0)throw new Error("expected non-empty array")}function PT(t,e,r,n){let{Fp2:o,Fp12:s}=t,{twistType:i,ateLoopSize:a,xNegative:c,postPrecompute:d}=n,p;if(i==="multiplicative")p=(_,T,N,I,v,A)=>s.mul014(I,_,o.mul(T,v),o.mul(N,A));else if(i==="divisive")p=(_,T,N,I,v,A)=>s.mul034(I,o.mul(N,A),o.mul(T,v),_);else throw new Error("bls: unknown twist type");let l=o.div(o.ONE,o.mul(o.ONE,y_));function u(_,T,N,I){let v=o.sqr(N),A=o.sqr(I),E=o.mulByB(o.mul(A,oi)),S=o.mul(E,oi),V=o.sub(o.sub(o.sqr(o.add(N,I)),A),v),C=o.sub(E,v),g=o.mul(o.sqr(T),oi),w=o.neg(V);return _.push([C,g,w]),T=o.mul(o.mul(o.mul(o.sub(v,S),T),N),l),N=o.sub(o.sqr(o.mul(o.add(v,S),l)),o.mul(o.sqr(E),oi)),I=o.mul(v,V),{Rx:T,Ry:N,Rz:I}}function f(_,T,N,I,v,A){let E=o.sub(N,o.mul(A,I)),S=o.sub(T,o.mul(v,I)),V=o.sub(o.mul(E,v),o.mul(S,A)),C=o.neg(E),g=S;_.push([V,C,g]);let w=o.sqr(S),O=o.mul(w,S),P=o.mul(w,T),L=o.add(o.sub(O,o.mul(P,y_)),o.mul(o.sqr(E),I));return T=o.mul(S,L),N=o.sub(o.mul(o.sub(P,L),E),o.mul(O,N)),I=o.mul(I,O),{Rx:T,Ry:N,Rz:I}}let h=CT(a),m=(0,ga.memoized)(_=>{let T=_,{x:N,y:I}=T.toAffine(),v=N,A=I,E=o.neg(I),S=v,V=A,C=o.ONE,g=[];for(let w of h){let O=[];({Rx:S,Ry:V,Rz:C}=u(O,S,V,C)),w&&({Rx:S,Ry:V,Rz:C}=f(O,S,V,C,v,w===-1?E:A)),g.push(O)}if(d){let w=g[g.length-1];d(S,V,C,v,A,f.bind(null,w))}return g});function b(_,T=!1){let N=s.ONE;if(_.length){let I=_[0][0].length;for(let v=0;v<I;v++){N=s.sqr(N);for(let[A,E,S]of _)for(let[V,C,g]of A[v])N=p(V,C,g,N,E,S)}}return c&&(N=s.conjugate(N)),T?s.finalExponentiate(N):N}function y(_,T=!0){let N=[];(0,p_.normalizeZ)(e,_.map(({g1:I})=>I)),(0,p_.normalizeZ)(r,_.map(({g2:I})=>I));for(let{g1:I,g2:v}of _){if(I.is0()||v.is0())throw new Error("pairing is not available for ZERO point");I.assertValidity(),v.assertValidity();let A=I.toAffine();N.push([m(v),A.x,A.y])}return b(N,T)}function x(_,T,N=!0){return y([{g1:_,g2:T}],N)}return{Fp12:s,millerLoopBatch:b,pairing:x,pairingBatch:y,calcPairingPrecomputes:m}}function __(t,e,r,n,o){let{Fp12:s,pairingBatch:i}=t;function a(l){return l instanceof e.Point?l:e.Point.fromHex(l)}function c(l){return l instanceof r.Point?l:r.Point.fromHex(l)}function d(l){if(!(l instanceof r.Point))throw new Error(`expected valid message hashed to ${o?"G1":"G2"} curve`);return l}let p=o?(l,u)=>({g1:u,g2:l}):(l,u)=>({g1:l,g2:u});return{getPublicKey(l){let u=(0,wu._normFnElement)(e.Point.Fn,l);return e.Point.BASE.multiply(u)},sign(l,u,f){if(f!=null)throw new Error("sign() expects 2 arguments");let h=(0,wu._normFnElement)(e.Point.Fn,u);return d(l).assertValidity(),l.multiply(h)},verify(l,u,f,h){if(h!=null)throw new Error("verify() expects 3 arguments");l=c(l),f=a(f);let m=f.negate(),b=e.Point.BASE,y=d(u),x=l,_=i([p(m,y),p(b,x)]);return s.eql(_,s.ONE)},verifyBatch(l,u,f){if(Sp(u),f.length!==u.length)throw new Error("amount of public keys and messages should be equal");let h=c(l),m=u,b=f.map(a),y=new Map;for(let T=0;T<b.length;T++){let N=b[T],I=m[T],v=y.get(I);v===void 0&&(v=[],y.set(I,v)),v.push(N)}let x=[],_=e.Point.BASE;try{for(let[T,N]of y){let I=N.reduce((v,A)=>v.add(A));x.push(p(I,T))}return x.push(p(_.negate(),h)),s.eql(i(x),s.ONE)}catch{return!1}},aggregatePublicKeys(l){Sp(l),l=l.map(f=>a(f));let u=l.reduce((f,h)=>f.add(h),e.Point.ZERO);return u.assertValidity(),u},aggregateSignatures(l){Sp(l),l=l.map(f=>c(f));let u=l.reduce((f,h)=>f.add(h),r.Point.ZERO);return u.assertValidity(),u},hash(l,u){(0,ga.abytes)(l);let f=u?{DST:u}:void 0;return r.hashToCurve(l,f)},Signature:n}}function DT(t){let{Fp:e,Fr:r,Fp2:n,Fp6:o,Fp12:s}=t.fields,i=(0,wu.weierstrassPoints)(t.G1),a=Object.assign(i,(0,h_.createHasher)(i.Point,t.G1.mapToCurve,{...t.htfDefaults,...t.G1.htfDefaults})),c=(0,wu.weierstrassPoints)(t.G2),d=Object.assign(c,(0,h_.createHasher)(c.Point,t.G2.mapToCurve,{...t.htfDefaults,...t.G2.htfDefaults})),p=PT(t.fields,a.Point,d.Point,{...t.params,postPrecompute:t.postPrecompute}),{millerLoopBatch:l,pairing:u,pairingBatch:f,calcPairingPrecomputes:h}=p,m=__(p,a,d,t.G2.Signature,!1),b=__(p,d,a,t.G1.ShortSignature,!0),y=t.randomBytes||ga.randomBytes,x=()=>{let R=(0,m_.getMinHashLength)(r.ORDER);return(0,m_.mapHashToField)(y(R),r.ORDER)},_={randomSecretKey:x,randomPrivateKey:x,calcPairingPrecomputes:h},{ShortSignature:T}=t.G1,{Signature:N}=t.G2;function I(R,B){return R instanceof a.Point?R:b.hash((0,ga.ensureBytes)("point",R),B?.DST)}function v(R,B){return R instanceof d.Point?R:m.hash((0,ga.ensureBytes)("point",R),B?.DST)}function A(R){return m.getPublicKey(R).toBytes(!0)}function E(R){return b.getPublicKey(R).toBytes(!0)}function S(R,B,F){let U=v(R,F),q=m.sign(U,B);return R instanceof d.Point?q:N.toBytes(q)}function V(R,B,F){let U=I(R,F),q=b.sign(U,B);return R instanceof a.Point?q:T.toBytes(q)}function C(R,B,F,U){let q=v(B,U);return m.verify(R,q,F)}function g(R,B,F,U){let q=I(B,U);return b.verify(R,q,F)}function w(R){let B=m.aggregatePublicKeys(R);return R[0]instanceof a.Point?B:B.toBytes(!0)}function O(R){let B=m.aggregateSignatures(R);return R[0]instanceof d.Point?B:N.toBytes(B)}function P(R){let B=b.aggregateSignatures(R);return R[0]instanceof a.Point?B:T.toBytes(B)}function L(R,B,F,U){let q=B.map(H=>v(H,U));return m.verifyBatch(R,q,F)}return a.Point.BASE.precompute(4),{longSignatures:m,shortSignatures:b,millerLoopBatch:l,pairing:u,pairingBatch:f,verifyBatch:L,fields:{Fr:r,Fp:e,Fp2:n,Fp6:o,Fp12:s},params:{ateLoopSize:t.params.ateLoopSize,twistType:t.params.twistType,r:t.params.r,G1b:t.G1.b,G2b:t.G2.b},utils:_,getPublicKey:A,getPublicKeyForShortSignatures:E,sign:S,signShortSignature:V,verify:C,verifyShortSignature:g,aggregatePublicKeys:w,aggregateSignatures:O,aggregateShortSignatures:P,G1:a,G2:d,Signature:N,ShortSignature:T}}});var E_=Z(Eu=>{"use strict";Object.defineProperty(Eu,"__esModule",{value:!0});Eu.psiFrobenius=FT;Eu.tower12=VT;var _o=Rr(),Bn=Qr(),g_=BigInt(0),Cn=BigInt(1),Ut=BigInt(2),x_=BigInt(3);function Dp(t,e,r,n,o=1,s){let i=BigInt(s===void 0?n:s),a=r**BigInt(n),c=[];for(let d=0;d<o;d++){let p=BigInt(d+1),l=[];for(let u=0,f=Cn;u<n;u++){let h=(p*f-p)/i%a;l.push(t.pow(e,h)),f*=r}c.push(l)}return c}function FT(t,e,r){let n=e.pow(r,(t.ORDER-Cn)/x_),o=e.pow(r,(t.ORDER-Cn)/Ut);function s(u,f){let h=e.mul(e.frobeniusMap(u,1),n),m=e.mul(e.frobeniusMap(f,1),o);return[h,m]}let i=e.pow(r,(t.ORDER**Ut-Cn)/x_),a=e.pow(r,(t.ORDER**Ut-Cn)/Ut);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(u,f){return[e.mul(u,i),e.neg(f)]}let d=u=>(f,h)=>{let m=h.toAffine(),b=u(m.x,m.y);return f.fromAffine({x:b[0],y:b[1]})},p=d(s),l=d(c);return{psi:s,psi2:c,G2psi:p,G2psi2:l,PSI_X:n,PSI_Y:o,PSI2_X:i,PSI2_Y:a}}var w_=(t,e)=>{if(e.length!==2)throw new Error("invalid tuple");let r=e.map(n=>t.create(n));return{c0:r[0],c1:r[1]}},Bp=class{constructor(e,r={}){this.MASK=Cn;let n=e.ORDER,o=n*n;this.Fp=e,this.ORDER=o,this.BITS=(0,_o.bitLen)(o),this.BYTES=Math.ceil((0,_o.bitLen)(o)/8),this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.Fp_NONRESIDUE=e.create(r.NONRESIDUE||BigInt(-1)),this.Fp_div2=e.div(e.ONE,Ut),this.NONRESIDUE=w_(e,r.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=Dp(e,this.Fp_NONRESIDUE,e.ORDER,2)[0],this.mulByB=r.Fp2mulByB,Object.seal(this)}fromBigTuple(e){return w_(this.Fp,e)}create(e){return e}isValid({c0:e,c1:r}){function n(o,s){return typeof o=="bigint"&&g_<=o&&o<s}return n(e,this.ORDER)&&n(r,this.ORDER)}is0({c0:e,c1:r}){return this.Fp.is0(e)&&this.Fp.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}eql({c0:e,c1:r},{c0:n,c1:o}){return this.Fp.eql(e,n)&&this.Fp.eql(r,o)}neg({c0:e,c1:r}){return{c0:this.Fp.neg(e),c1:this.Fp.neg(r)}}pow(e,r){return Bn.FpPow(this,e,r)}invertBatch(e){return Bn.FpInvertBatch(this,e)}add(e,r){let{c0:n,c1:o}=e,{c0:s,c1:i}=r;return{c0:this.Fp.add(n,s),c1:this.Fp.add(o,i)}}sub({c0:e,c1:r},{c0:n,c1:o}){return{c0:this.Fp.sub(e,n),c1:this.Fp.sub(r,o)}}mul({c0:e,c1:r},n){let{Fp:o}=this;if(typeof n=="bigint")return{c0:o.mul(e,n),c1:o.mul(r,n)};let{c0:s,c1:i}=n,a=o.mul(e,s),c=o.mul(r,i),d=o.sub(a,c),p=o.sub(o.mul(o.add(e,r),o.add(s,i)),o.add(a,c));return{c0:d,c1:p}}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{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{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 Bn.FpLegendre(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))),a=r.mul(r.add(i,o),this.Fp_div2);Bn.FpLegendre(r,a)===-1&&(a=r.sub(a,i));let d=r.sqrt(a),p=n.create({c0:d,c1:r.div(r.mul(s,this.Fp_div2),d)});if(!n.eql(n.sqr(p),e))throw new Error("Cannot find square root");let l=p,u=n.neg(l),{re:f,im:h}=n.reim(l),{re:m,im:b}=n.reim(u);return h>b||h===b&&f>m?l:u}isOdd(e){let{re:r,im:n}=this.reim(e),o=r%Ut,s=r===g_,i=n%Ut;return BigInt(o||s&&i)==Cn}fromBytes(e){let{Fp:r}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{c0:r.fromBytes(e.subarray(0,r.BYTES)),c1:r.fromBytes(e.subarray(r.BYTES))}}toBytes({c0:e,c1:r}){return(0,_o.concatBytes)(this.Fp.toBytes(e),this.Fp.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:o},s){return{c0:this.Fp.cmov(e,n,s),c1:this.Fp.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}){return this.mul({c0:e,c1:r},this.NONRESIDUE)}frobeniusMap({c0:e,c1:r},n){return{c0:e,c1:this.Fp.mul(r,this.FROBENIUS_COEFFICIENTS[n%2])}}},Cp=class{constructor(e){this.MASK=Cn,this.Fp2=e,this.ORDER=e.ORDER,this.BITS=3*e.BITS,this.BYTES=3*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO,c2:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO,c2:e.ZERO};let{Fp:r}=e,n=Dp(e,e.NONRESIDUE,r.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=n[0],this.FROBENIUS_COEFFICIENTS_2=n[1],Object.seal(this)}add({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i}){let{Fp2:a}=this;return{c0:a.add(e,o),c1:a.add(r,s),c2:a.add(n,i)}}sub({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i}){let{Fp2:a}=this;return{c0:a.sub(e,o),c1:a.sub(r,s),c2:a.sub(n,i)}}mul({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;if(typeof o=="bigint")return{c0:s.mul(e,o),c1:s.mul(r,o),c2:s.mul(n,o)};let{c0:i,c1:a,c2:c}=o,d=s.mul(e,i),p=s.mul(r,a),l=s.mul(n,c);return{c0:s.add(d,s.mulByNonresidue(s.sub(s.mul(s.add(r,n),s.add(a,c)),s.add(p,l)))),c1:s.add(s.sub(s.mul(s.add(e,r),s.add(i,a)),s.add(d,p)),s.mulByNonresidue(l)),c2:s.sub(s.add(p,s.mul(s.add(e,n),s.add(i,c))),s.add(d,l))}}sqr({c0:e,c1:r,c2:n}){let{Fp2:o}=this,s=o.sqr(e),i=o.mul(o.mul(e,r),Ut),a=o.mul(o.mul(r,n),Ut),c=o.sqr(n);return{c0:o.add(o.mulByNonresidue(a),s),c1:o.add(o.mulByNonresidue(c),i),c2:o.sub(o.sub(o.add(o.add(i,o.sqr(o.add(o.sub(e,r),n))),a),s),c)}}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){return e}isValid({c0:e,c1:r,c2:n}){let{Fp2:o}=this;return o.isValid(e)&&o.isValid(r)&&o.isValid(n)}is0({c0:e,c1:r,c2:n}){let{Fp2:o}=this;return o.is0(e)&&o.is0(r)&&o.is0(n)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r,c2:n}){let{Fp2:o}=this;return{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:a}=this;return a.eql(e,o)&&a.eql(r,s)&&a.eql(n,i)}sqrt(e){return(0,_o.notImplemented)()}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 Bn.FpPow(this,e,r)}invertBatch(e){return Bn.FpInvertBatch(this,e)}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)),a=o.sub(o.sqr(r),o.mul(e,n)),c=o.inv(o.add(o.mulByNonresidue(o.add(o.mul(n,i),o.mul(r,a))),o.mul(e,s)));return{c0:o.mul(c,s),c1:o.mul(c,i),c2:o.mul(c,a)}}fromBytes(e){let{Fp2:r}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);let n=r.BYTES;return{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(0,_o.concatBytes)(o.toBytes(e),o.toBytes(r),o.toBytes(n))}cmov({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i},a){let{Fp2:c}=this;return{c0:c.cmov(e,o,a),c1:c.cmov(r,s,a),c2:c.cmov(n,i,a)}}fromBigSix(e){let{Fp2:r}=this;if(!Array.isArray(e)||e.length!==6)throw new Error("invalid Fp6 usage");return{c0:r.fromBigTuple(e.slice(0,2)),c1:r.fromBigTuple(e.slice(2,4)),c2:r.fromBigTuple(e.slice(4,6))}}frobeniusMap({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;return{c0:s.frobeniusMap(e,o),c1:s.mul(s.frobeniusMap(r,o),this.FROBENIUS_COEFFICIENTS_1[o%6]),c2:s.mul(s.frobeniusMap(n,o),this.FROBENIUS_COEFFICIENTS_2[o%6])}}mulByFp2({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;return{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{c0:o.mulByNonresidue(n),c1:e,c2:r}}mul1({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;return{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,a=i.mul(e,o),c=i.mul(r,s);return{c0:i.add(i.mulByNonresidue(i.sub(i.mul(i.add(r,n),s),c)),a),c1:i.sub(i.sub(i.mul(i.add(o,s),i.add(e,r)),a),c),c2:i.add(i.sub(i.mul(i.add(e,n),o),a),c)}}},Pp=class{constructor(e,r){this.MASK=Cn;let{Fp2:n}=e,{Fp:o}=n;this.Fp6=e,this.ORDER=n.ORDER,this.BITS=2*e.BITS,this.BYTES=2*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.FROBENIUS_COEFFICIENTS=Dp(n,n.NONRESIDUE,o.ORDER,12,1,6)[0],this.X_LEN=r.X_LEN,this.finalExponentiate=r.Fp12finalExponentiate}create(e){return e}isValid({c0:e,c1:r}){let{Fp6:n}=this;return n.isValid(e)&&n.isValid(r)}is0({c0:e,c1:r}){let{Fp6:n}=this;return n.is0(e)&&n.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r}){let{Fp6:n}=this;return{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){(0,_o.notImplemented)()}inv({c0:e,c1:r}){let{Fp6:n}=this,o=n.inv(n.sub(n.sqr(e),n.mulByNonresidue(n.sqr(r))));return{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 Bn.FpPow(this,e,r)}invertBatch(e){return Bn.FpInvertBatch(this,e)}add({c0:e,c1:r},{c0:n,c1:o}){let{Fp6:s}=this;return{c0:s.add(e,n),c1:s.add(r,o)}}sub({c0:e,c1:r},{c0:n,c1:o}){let{Fp6:s}=this;return{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{c0:o.mul(e,n),c1:o.mul(r,n)};let{c0:s,c1:i}=n,a=o.mul(e,s),c=o.mul(r,i);return{c0:o.add(a,o.mulByNonresidue(c)),c1:o.sub(o.mul(o.add(e,r),o.add(s,i)),o.add(a,c))}}sqr({c0:e,c1:r}){let{Fp6:n}=this,o=n.mul(e,r);return{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(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{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(0,_o.concatBytes)(n.toBytes(e),n.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:o},s){let{Fp6:i}=this;return{c0:i.cmov(e,n,s),c1:i.cmov(r,o,s)}}fromBigTwelve(e){let{Fp6:r}=this;return{c0:r.fromBigSix(e.slice(0,6)),c1:r.fromBigSix(e.slice(6,12))}}frobeniusMap(e,r){let{Fp6:n}=this,{Fp2:o}=n,{c0:s,c1:i,c2:a}=n.frobeniusMap(e.c1,r),c=this.FROBENIUS_COEFFICIENTS[r%12];return{c0:n.frobeniusMap(e.c0,r),c1:n.create({c0:o.mul(s,c),c1:o.mul(i,c),c2:o.mul(a,c)})}}mulByFp2({c0:e,c1:r},n){let{Fp6:o}=this;return{c0:o.mulByFp2(e,n),c1:o.mulByFp2(r,n)}}conjugate({c0:e,c1:r}){return{c0:e,c1:this.Fp6.neg(r)}}mul014({c0:e,c1:r},n,o,s){let{Fp6:i}=this,{Fp2:a}=i,c=i.mul01(e,n,o),d=i.mul1(r,s);return{c0:i.add(i.mulByNonresidue(d),c),c1:i.sub(i.sub(i.mul01(i.add(r,e),n,a.add(o,s)),c),d)}}mul034({c0:e,c1:r},n,o,s){let{Fp6:i}=this,{Fp2:a}=i,c=i.create({c0:a.mul(e.c0,n),c1:a.mul(e.c1,n),c2:a.mul(e.c2,n)}),d=i.mul01(r,o,s),p=i.mul01(i.add(e,r),a.add(n,o),s);return{c0:i.add(i.mulByNonresidue(d),c),c1:i.sub(p,i.add(c,d))}}_cyclotomicSquare({c0:e,c1:r}){let{Fp6:n}=this,{Fp2:o}=n,{c0:s,c1:i,c2:a}=e,{c0:c,c1:d,c2:p}=r,{first:l,second:u}=o.Fp4Square(s,d),{first:f,second:h}=o.Fp4Square(c,a),{first:m,second:b}=o.Fp4Square(i,p),y=o.mulByNonresidue(b);return{c0:n.create({c0:o.add(o.mul(o.sub(l,s),Ut),l),c1:o.add(o.mul(o.sub(f,i),Ut),f),c2:o.add(o.mul(o.sub(m,a),Ut),m)}),c1:n.create({c0:o.add(o.mul(o.add(y,c),Ut),y),c1:o.add(o.mul(o.add(u,d),Ut),u),c2:o.add(o.mul(o.add(h,p),Ut),h)})}}_cyclotomicExp(e,r){let n=this.ONE;for(let o=this.X_LEN-1;o>=0;o--)n=this._cyclotomicSquare(n),(0,_o.bitGet)(r,o)&&(n=this.mul(n,e));return n}};function VT(t){let e=Bn.Field(t.ORDER),r=new Bp(e,t),n=new Cp(r),o=new Pp(n,t);return{Fp:e,Fp2:r,Fp6:n,Fp12:o}}});var A_=Z(rn=>{"use strict";Object.defineProperty(rn,"__esModule",{value:!0});rn.bls12_381=rn.bls12_381_Fr=void 0;var v_=Gs(),UT=b_(),LT=Qr(),ge=Rr(),I_=bu(),R_=E_(),S_=Rp(),Rt=BigInt(0),Tu=BigInt(1),yr=BigInt(2),Ou=BigInt(3),xa=BigInt(4),bo=BigInt("0xd201000000010000"),qT=(0,ge.bitLen)(bo),ns={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:Rt,b:xa,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")};rn.bls12_381_Fr=(0,LT.Field)(ns.n,{modFromBytes:!0,isLE:!0});var{Fp:X,Fp2:xe,Fp6:MT,Fp12:ve}=(0,R_.tower12)({ORDER:ns.p,X_LEN:qT,FP2_NONRESIDUE:[Tu,Tu],Fp2mulByB:({c0:t,c1:e})=>{let r=X.mul(t,xa),n=X.mul(e,xa);return{c0:X.sub(r,n),c1:X.add(r,n)}},Fp12finalExponentiate:t=>{let e=bo,r=ve.div(ve.frobeniusMap(t,6),t),n=ve.mul(ve.frobeniusMap(r,2),r),o=ve.conjugate(ve._cyclotomicExp(n,e)),s=ve.mul(ve.conjugate(ve._cyclotomicSquare(n)),o),i=ve.conjugate(ve._cyclotomicExp(s,e)),a=ve.conjugate(ve._cyclotomicExp(i,e)),c=ve.mul(ve.conjugate(ve._cyclotomicExp(a,e)),ve._cyclotomicSquare(o)),d=ve.conjugate(ve._cyclotomicExp(c,e)),p=ve.frobeniusMap(ve.mul(o,a),2),l=ve.frobeniusMap(ve.mul(i,n),3),u=ve.frobeniusMap(ve.mul(c,ve.conjugate(n)),1),f=ve.mul(ve.mul(d,ve.conjugate(s)),n);return ve.mul(ve.mul(ve.mul(p,l),u),f)}}),{G2psi:T_,G2psi2:kT}=(0,R_.psiFrobenius)(X,xe,xe.div(xe.ONE,xe.NONRESIDUE)),Fp=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:X.ORDER,m:2,k:128,expand:"xmd",hash:v_.sha256}),Lp={p:xe.ORDER,n:ns.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:xe.ZERO,b:xe.fromBigTuple([xa,xa]),Gx:xe.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:xe.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},Nu=wa(X.toBytes(Rt),{infinity:!0,compressed:!0});function vu(t){t=t.slice();let e=t[0]&224,r=!!(e>>7&1),n=!!(e>>6&1),o=!!(e>>5&1);return t[0]&=31,{compressed:r,infinity:n,sort:o,value:t}}function wa(t,e){if(t[0]&224)throw new Error("setMask: non-empty mask");return e.compressed&&(t[0]|=128),e.infinity&&(t[0]|=64),e.sort&&(t[0]|=32),t}function jT(t,e,r){let{BYTES:n,ORDER:o}=X,s=e.is0(),{x:i,y:a}=e.toAffine();if(r){if(s)return Nu.slice();let c=!!(a*yr/o);return wa((0,ge.numberToBytesBE)(i,n),{compressed:!0,sort:c})}else return s?(0,ge.concatBytes)(Uint8Array.of(64),new Uint8Array(2*n-1)):(0,ge.concatBytes)((0,ge.numberToBytesBE)(i,n),(0,ge.numberToBytesBE)(a,n))}function Vp(t){t.assertValidity();let{BYTES:e,ORDER:r}=X,{x:n,y:o}=t.toAffine();if(t.is0())return Nu.slice();let s=!!(o*yr/r);return wa((0,ge.numberToBytesBE)(n,e),{compressed:!0,sort:s})}function HT(t){let{compressed:e,infinity:r,sort:n,value:o}=vu(t),{BYTES:s,ORDER:i}=X;if(o.length===48&&e){let a=(0,ge.bytesToNumberBE)(o),c=X.create(a&(0,ge.bitMask)(X.BITS));if(r){if(c!==Rt)throw new Error("invalid G1 point: non-empty, at infinity, with compression");return{x:Rt,y:Rt}}let d=X.add(X.pow(c,Ou),X.create(ns.b)),p=X.sqrt(d);if(!p)throw new Error("invalid G1 point: compressed point");return p*yr/i!==BigInt(n)&&(p=X.neg(p)),{x:X.create(c),y:X.create(p)}}else if(o.length===96&&!e){let a=(0,ge.bytesToNumberBE)(o.subarray(0,s)),c=(0,ge.bytesToNumberBE)(o.subarray(s));if(r){if(a!==Rt||c!==Rt)throw new Error("G1: non-empty point at infinity");return rn.bls12_381.G1.Point.ZERO.toAffine()}return{x:X.create(a),y:X.create(c)}}else throw new Error("invalid G1 point: expected 48/96 bytes")}function O_(t){let{infinity:e,sort:r,value:n}=vu((0,ge.ensureBytes)("signatureHex",t,48)),o=X.ORDER,s=rn.bls12_381.G1.Point,i=(0,ge.bytesToNumberBE)(n);if(e)return s.ZERO;let a=X.create(i&(0,ge.bitMask)(X.BITS)),c=X.add(X.pow(a,Ou),X.create(ns.b)),d=X.sqrt(c);if(!d)throw new Error("invalid G1 point: compressed");let p=BigInt(r);d*yr/o!==p&&(d=X.neg(d));let l=s.fromAffine({x:a,y:d});return l.assertValidity(),l}function $T(t,e,r){let{BYTES:n,ORDER:o}=X,s=e.is0(),{x:i,y:a}=e.toAffine();if(r){if(s)return(0,ge.concatBytes)(Nu,(0,ge.numberToBytesBE)(Rt,n));let c=!!(a.c1===Rt?a.c0*yr/o:a.c1*yr/o);return(0,ge.concatBytes)(wa((0,ge.numberToBytesBE)(i.c1,n),{compressed:!0,sort:c}),(0,ge.numberToBytesBE)(i.c0,n))}else{if(s)return(0,ge.concatBytes)(Uint8Array.of(64),new Uint8Array(4*n-1));let{re:c,im:d}=xe.reim(i),{re:p,im:l}=xe.reim(a);return(0,ge.concatBytes)((0,ge.numberToBytesBE)(d,n),(0,ge.numberToBytesBE)(c,n),(0,ge.numberToBytesBE)(l,n),(0,ge.numberToBytesBE)(p,n))}}function Up(t){t.assertValidity();let{BYTES:e}=X;if(t.is0())return(0,ge.concatBytes)(Nu,(0,ge.numberToBytesBE)(Rt,e));let{x:r,y:n}=t.toAffine(),{re:o,im:s}=xe.reim(r),{re:i,im:a}=xe.reim(n),d=!!((a>Rt?a*yr:i*yr)/X.ORDER&Tu),p=o;return(0,ge.concatBytes)(wa((0,ge.numberToBytesBE)(s,e),{sort:d,compressed:!0}),(0,ge.numberToBytesBE)(p,e))}function KT(t){let{BYTES:e,ORDER:r}=X,{compressed:n,infinity:o,sort:s,value:i}=vu(t);if(!n&&!o&&s||!n&&o&&s||s&&o&&n)throw new Error("invalid encoding flag: "+(t[0]&224));let a=(c,d,p)=>(0,ge.bytesToNumberBE)(c.slice(d,p));if(i.length===96&&n){if(o){if(i.reduce((h,m)=>h!==0?m+1:m,0)>0)throw new Error("invalid G2 point: compressed");return{x:xe.ZERO,y:xe.ZERO}}let c=a(i,0,e),d=a(i,e,2*e),p=xe.create({c0:X.create(d),c1:X.create(c)}),l=xe.add(xe.pow(p,Ou),Lp.b),u=xe.sqrt(l),f=u.c1===Rt?u.c0*yr/r:u.c1*yr/r?Tu:Rt;return u=s&&f>0?u:xe.neg(u),{x:p,y:u}}else if(i.length===192&&!n){if(o){if(i.reduce((u,f)=>u!==0?f+1:f,0)>0)throw new Error("invalid G2 point: uncompressed");return{x:xe.ZERO,y:xe.ZERO}}let c=a(i,0*e,1*e),d=a(i,1*e,2*e),p=a(i,2*e,3*e),l=a(i,3*e,4*e);return{x:xe.fromBigTuple([d,c]),y:xe.fromBigTuple([l,p])}}else throw new Error("invalid G2 point: expected 96/192 bytes")}function N_(t){let{ORDER:e}=X,{infinity:r,sort:n,value:o}=vu((0,ge.ensureBytes)("signatureHex",t)),s=rn.bls12_381.G2.Point,i=o.length/2;if(i!==48&&i!==96)throw new Error("invalid compressed signature length, expected 96/192 bytes");let a=(0,ge.bytesToNumberBE)(o.slice(0,i)),c=(0,ge.bytesToNumberBE)(o.slice(i));if(r)return s.ZERO;let d=X.create(a&(0,ge.bitMask)(X.BITS)),p=X.create(c),l=xe.create({c0:p,c1:d}),u=xe.add(xe.pow(l,Ou),Lp.b),f=xe.sqrt(u);if(!f)throw new Error("Failed to find a square root");let{re:h,im:m}=xe.reim(f),b=BigInt(n),y=m>Rt&&m*yr/e!==b,x=m===Rt&&h*yr/e!==b;(y||x)&&(f=xe.neg(f));let _=s.fromAffine({x:l,y:f});return _.assertValidity(),_}rn.bls12_381=(0,UT.bls)({fields:{Fp:X,Fp2:xe,Fp6:MT,Fp12:ve,Fr:rn.bls12_381_Fr},G1:{...ns,Fp:X,htfDefaults:{...Fp,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(t,e)=>{let r=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),n=new t(X.mul(e.X,r),e.Y,e.Z);return e.multiplyUnsafe(bo).negate().multiplyUnsafe(bo).equals(n)},clearCofactor:(t,e)=>e.multiplyUnsafe(bo).add(e),mapToCurve:WT,fromBytes:HT,toBytes:jT,ShortSignature:{fromBytes(t){return(0,ge.abytes)(t),O_(t)},fromHex(t){return O_(t)},toBytes(t){return Vp(t)},toRawBytes(t){return Vp(t)},toHex(t){return(0,ge.bytesToHex)(Vp(t))}}},G2:{...Lp,Fp:xe,hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...Fp},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:XT,isTorsionFree:(t,e)=>e.multiplyUnsafe(bo).negate().equals(T_(t,e)),clearCofactor:(t,e)=>{let r=bo,n=e.multiplyUnsafe(r).negate(),o=T_(t,e),s=e.double();return s=kT(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)},fromBytes:KT,toBytes:$T,Signature:{fromBytes(t){return(0,ge.abytes)(t),N_(t)},fromHex(t){return N_(t)},toBytes(t){return Up(t)},toRawBytes(t){return Up(t)},toHex(t){return(0,ge.bytesToHex)(Up(t))}}},params:{ateLoopSize:bo,r:ns.n,xNegative:!0,twistType:"multiplicative"},htfDefaults:Fp,hash:v_.sha256});var GT=(0,I_.isogenyMap)(xe,[[["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=>xe.fromBigTuple(e.map(BigInt))))),zT=(0,I_.isogenyMap)(X,[["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)))),ZT=(0,S_.mapToCurveSimpleSWU)(X,{A:X.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:X.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:X.create(BigInt(11))}),YT=(0,S_.mapToCurveSimpleSWU)(xe,{A:xe.create({c0:X.create(Rt),c1:X.create(BigInt(240))}),B:xe.create({c0:X.create(BigInt(1012)),c1:X.create(BigInt(1012))}),Z:xe.create({c0:X.create(BigInt(-2)),c1:X.create(BigInt(-1))})});function WT(t){let{x:e,y:r}=ZT(X.create(t[0]));return zT(e,r)}function XT(t){let{x:e,y:r}=YT(xe.fromBigTuple(t));return GT(e,r)}});var Mp=Z(Iu=>{"use strict";Object.defineProperty(Iu,"__esModule",{value:!0});Iu.verify=void 0;Iu.blsVerify=QT;var JT=A_(),qp=dt();function QT(t,e,r){let n=typeof t=="string"?t:(0,qp.bytesToHex)(t),o=typeof e=="string"?e:(0,qp.bytesToHex)(e),s=typeof r=="string"?r:(0,qp.bytesToHex)(r);return JT.bls12_381.verifyShortSignature(o,s,n)}});var Ru=Z(os=>{"use strict";Object.defineProperty(os,"__esModule",{value:!0});os.decodeTime=os.decodeLeb128=void 0;var B_=ca(),e6=BigInt(1e6),t6=t=>(0,B_.lebDecode)(new B_.PipeArrayBuffer(t));os.decodeLeb128=t6;var r6=t=>{let r=(0,os.decodeLeb128)(t)/e6;return new Date(Number(r))};os.decodeTime=r6});var ai=Z(Ue=>{"use strict";var n6=Ue&&Ue.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),o6=Ue&&Ue.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),P_=Ue&&Ue.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),o=0;o<n.length;o++)n[o]!=="default"&&n6(r,e,n[o]);return o6(r,e),r}})();Object.defineProperty(Ue,"__esModule",{value:!0});Ue.LookupLabelStatus=Ue.LookupSubtreeStatus=Ue.LookupPathStatus=Ue.Certificate=Ue.NodeType=void 0;Ue.hashTreeToString=Au;Ue.lookupResultToBuffer=Hp;Ue.reconstruct=Ta;Ue.domain_sep=si;Ue.lookup_path=Bu;Ue.lookup_subtree=Kp;Ue.flatten_forks=$p;Ue.find_label=ii;Ue.check_canister_ranges=U_;var D_=P_(la()),me=sr(),kp=Ir(),s6=P_(Mp()),i6=Ru(),go=dt(),F_=Qs(),Su=Gs(),C_=60*1e3,a6=60,c6=24,u6=c6*a6,d6=5,l6=5,f6=30*u6,ze;(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"})(ze||(Ue.NodeType=ze={}));function Au(t){let e=n=>n.split(`
|
|
53
|
-
`).map(
|
|
54
|
-
`);function r(n){let
|
|
50
|
+
`)}return c.encodeValue(d)}));return(0,Te.concat)(n,s,o,i,a)}function jE(t,e){let r=new Te.PipeArrayBuffer(e);if(e.byteLength<_u.length)throw new Error("Message length smaller than magic number");let n=(0,$.safeRead)(r,_u.length),s=new TextDecoder().decode(n);if(s!==_u)throw new Error("Wrong magic number: "+JSON.stringify(s));function o(u){let p=[],h=Number((0,$.lebDecode)(u));for(let y=0;y<h;y++){let x=Number((0,$.slebDecode)(u));switch(x){case Se.Opt:case Se.Vector:{let _=Number((0,$.slebDecode)(u));p.push([x,_]);break}case Se.Record:case Se.Variant:{let _=[],T=Number((0,$.lebDecode)(u)),N;for(;T--;){let v=Number((0,$.lebDecode)(u));if(v>=Math.pow(2,32))throw new Error("field id out of 32-bit range");if(typeof N=="number"&&N>=v)throw new Error("field id collision or not sorted");N=v;let R=Number((0,$.slebDecode)(u));_.push([v,R])}p.push([x,_]);break}case Se.Func:{let _=[],T=Number((0,$.lebDecode)(u));for(;T--;)_.push(Number((0,$.slebDecode)(u)));let N=[],v=Number((0,$.lebDecode)(u));for(;v--;)N.push(Number((0,$.slebDecode)(u)));let R=[],A=Number((0,$.lebDecode)(u));for(;A--;)switch(Number((0,$.lebDecode)(u))){case 1:{R.push("query");break}case 2:{R.push("oneway");break}case 3:{R.push("composite_query");break}default:throw new Error("unknown annotation")}p.push([x,[_,N,R]]);break}case Se.Service:{let _=Number((0,$.lebDecode)(u)),T=[];for(;_--;){let N=Number((0,$.lebDecode)(u)),v=new TextDecoder().decode((0,$.safeRead)(u,N)),R=(0,$.slebDecode)(u);T.push([v,R])}p.push([x,T]);break}default:throw new Error("Illegal op_code: "+x)}}let m=[],b=Number((0,$.lebDecode)(u));for(let y=0;y<b;y++)m.push(Number((0,$.slebDecode)(u)));return[p,m]}let[i,a]=o(r);if(a.length<t.length)throw new Error("Wrong number of return values");let c=i.map(u=>Xy());function d(u){if(u<-24)throw new Error("future value not supported");if(u<0)switch(u){case-1:return M.Null;case-2:return M.Bool;case-3:return M.Nat;case-4:return M.Int;case-5:return M.Nat8;case-6:return M.Nat16;case-7:return M.Nat32;case-8:return M.Nat64;case-9:return M.Int8;case-10:return M.Int16;case-11:return M.Int32;case-12:return M.Int64;case-13:return M.Float32;case-14:return M.Float64;case-15:return M.Text;case-16:return M.Reserved;case-17:return M.Empty;case-24:return M.Principal;default:throw new Error("Illegal op_code: "+u)}if(u>=i.length)throw new Error("type index out of range");return c[u]}function f(u){switch(u[0]){case Se.Vector:{let p=d(u[1]);return Zy(p)}case Se.Opt:{let p=d(u[1]);return zy(p)}case Se.Record:{let p={};for(let[b,y]of u[1]){let x=`_${b}_`;p[x]=d(y)}let h=Yy(p),m=h.tryAsTuple();return Array.isArray(m)?Gy(...m):h}case Se.Variant:{let p={};for(let[h,m]of u[1]){let b=`_${h}_`;p[b]=d(m)}return Wy(p)}case Se.Func:{let[p,h,m]=u[1];return Jy(p.map(b=>d(b)),h.map(b=>d(b)),m)}case Se.Service:{let p={},h=u[1];for(let[m,b]of h){let y=d(b);if(y instanceof Or&&(y=y.getType()),!(y instanceof ho))throw new Error("Illegal service definition: services can only contain functions");p[m]=y}return Qy(p)}default:throw new Error("Illegal op_code: "+u[0])}}i.forEach((u,p)=>{if(u[0]===Se.Func){let h=f(u);c[p].fill(h)}}),i.forEach((u,p)=>{if(u[0]!==Se.Func){let h=f(u);c[p].fill(h)}}),wp();let l=a.map(u=>d(u));try{let u=t.map((p,h)=>p.decodeValue(r,l[h]));for(let p=t.length;p<l.length;p++)l[p].decodeValue(r,l[p]);if(r.byteLength>0)throw new Error("decode: Left-over bytes");return u}finally{wp()}}M.Empty=new Oa;M.Reserved=new on;M.Unknown=new gu;M.Bool=new xu;M.Null=new fo;M.Text=new wu;M.Int=new Na;M.Nat=new va;M.Float32=new Ra(32);M.Float64=new Ra(64);M.Int8=new Fn(8);M.Int16=new Fn(16);M.Int32=new Fn(32);M.Int64=new Fn(64);M.Nat8=new nn(8);M.Nat16=new nn(16);M.Nat32=new nn(32);M.Nat64=new nn(64);M.Principal=new Tu;function Gy(...t){return new Eu(t)}function Zy(t){return new fi(t)}function zy(t){return new Rs(t)}function Yy(t){return new po(t)}function Wy(t){return new pi(t)}function Xy(){return new Or}function Jy(t,e,r=[]){return new ho(t,e,r)}function Qy(t){return new hi(t)}var Ou=class t{constructor(e=new Map){this.rels=e}copy(){let e=new Map;for(let[r,n]of this.rels.entries()){let s=new Map(n);e.set(r,s)}return new t(e)}known(e,r){return this.rels.get(e.name)?.get(r.name)}addNegative(e,r){this.addNames(e.name,r.name,!1)}add(e,r){this.addNames(e.name,r.name,!0)}display(){let e="";for(let[r,n]of this.rels)for(let[s,o]of n)e+=`${r} ${o?":<":"!<:"} ${s}
|
|
51
|
+
`;return e}addNames(e,r,n){let s=this.rels.get(e);if(s==null){let o=new Map;o.set(r,n),this.rels.set(e,o)}else s.set(r,n)}},bu=new Ou;function wp(){bu=new Ou}function HE(t,e){let r=new Set(t.annotations),n=new Set(e.annotations);if(r.size!==n.size)return!1;for(let s of r)if(!n.has(s))return!1;return!0}function _p(t){return t instanceof Rs||t instanceof fo||t instanceof on}function Tp(t,e){let r=bu.copy(),n=Dn(r,t,e);return n?bu.add(t,e):bu.addNegative(t,e),n}function Dn(t,e,r){if(e.name===r.name)return!0;let n=t.known(e,r);if(n!==void 0)return n;if(t.add(e,r),r instanceof on||e instanceof Oa||e instanceof va&&r instanceof Na)return!0;if(e instanceof fi&&r instanceof fi)return Dn(t,e._type,r._type);if(r instanceof Rs)return!0;if(e instanceof po&&r instanceof po){let s=e.fieldsAsObject;for(let[o,i]of r._fields){let a=s[(0,tr.idlLabelToId)(o)];if(a){if(!Dn(t,a,i))return!1}else if(!_p(i))return!1}return!0}if(e instanceof ho&&r instanceof ho){if(!HE(e,r))return!1;for(let s=0;s<e.argTypes.length;s++){let o=e.argTypes[s];if(s<r.argTypes.length){if(!Dn(t,r.argTypes[s],o))return!1}else if(!_p(o))return!1}for(let s=0;s<r.retTypes.length;s++){let o=r.retTypes[s];if(s<e.retTypes.length){if(!Dn(t,e.retTypes[s],o))return!1}else if(!_p(o))return!1}return!0}if(e instanceof pi&&r instanceof pi){let s=r.alternativesAsObject;for(let[o,i]of e._fields){let a=s[(0,tr.idlLabelToId)(o)];if(!a||!Dn(t,i,a))return!1}return!0}if(e instanceof hi&&r instanceof hi){let s=e.fieldsAsObject();for(let[o,i]of r._fields){let a=s[o];if(!a||!Dn(t,a,i))return!1}return!0}return e instanceof Or?Dn(t,e.getType(),r):r instanceof Or?Dn(t,e,r.getType()):!1}});var Bp=Y(Pt=>{"use strict";Object.defineProperty(Pt,"__esModule",{value:!0});Pt.VecForm=Pt.OptionForm=Pt.VariantForm=Pt.TupleForm=Pt.RecordForm=Pt.InputForm=Pt.InputBox=void 0;var Np=class{constructor(e,r){this.idl=e,this.ui=r,this.label=null,this.value=void 0;let n=document.createElement("span");n.className="status",this.status=n,r.input&&(r.input.addEventListener("blur",()=>{r.input.value!==""&&this.parse()}),r.input.addEventListener("input",()=>{n.style.display="none",r.input.classList.remove("reject")}))}isRejected(){return this.value===void 0}parse(e={}){if(this.ui.form){let r=this.ui.form.parse(e);return this.value=r,r}if(this.ui.input){let r=this.ui.input;try{let n=this.ui.parse(this.idl,e,r.value);if(!this.idl.covariant(n))throw new Error(`${r.value} is not of type ${this.idl.display()}`);return this.status.style.display="none",this.value=n,n}catch(n){r.classList.add("reject"),this.status.style.display="block",this.status.innerHTML="InputError: "+n.message,this.value=void 0;return}}return null}render(e){let r=document.createElement("span");if(this.label){let n=document.createElement("label");n.innerText=this.label,r.appendChild(n)}this.ui.input&&(r.appendChild(this.ui.input),r.appendChild(this.status)),this.ui.form&&this.ui.form.render(r),e.appendChild(r)}};Pt.InputBox=Np;var Is=class{constructor(e){this.ui=e,this.form=[]}renderForm(e){this.ui.container?(this.form.forEach(r=>r.render(this.ui.container)),e.appendChild(this.ui.container)):this.form.forEach(r=>r.render(e))}render(e){if(this.ui.open&&this.ui.event){e.appendChild(this.ui.open);let r=this;r.ui.open.addEventListener(r.ui.event,()=>{if(r.ui.container)r.ui.container.innerHTML="";else{let n=r.ui.open.nextElementSibling;n&&n.parentNode.removeChild(n)}r.generateForm(),r.renderForm(e)})}else this.generateForm(),this.renderForm(e)}};Pt.InputForm=Is;var vp=class extends Is{constructor(e,r){super(r),this.fields=e,this.ui=r}generateForm(){this.form=this.fields.map(([e,r])=>{let n=this.ui.render(r);return this.ui.labelMap&&this.ui.labelMap.hasOwnProperty(e)?n.label=this.ui.labelMap[e]+" ":n.label=e+" ",n})}parse(e){let r={};if(this.fields.forEach(([n,s],o)=>{let i=this.form[o].parse(e);r[n]=i}),!this.form.some(n=>n.isRejected()))return r}};Pt.RecordForm=vp;var Rp=class extends Is{constructor(e,r){super(r),this.components=e,this.ui=r}generateForm(){this.form=this.components.map(e=>this.ui.render(e))}parse(e){let r=[];if(this.components.forEach((n,s)=>{let o=this.form[s].parse(e);r.push(o)}),!this.form.some(n=>n.isRejected()))return r}};Pt.TupleForm=Rp;var Ip=class extends Is{constructor(e,r){super(r),this.fields=e,this.ui=r}generateForm(){let e=this.ui.open.selectedIndex,[r,n]=this.fields[e],s=this.ui.render(n);this.form=[s]}parse(e){let r=this.ui.open,n=r.options[r.selectedIndex].value,s=this.form[0].parse(e);if(s===void 0)return;let o={};return o[n]=s,o}};Pt.VariantForm=Ip;var Sp=class extends Is{constructor(e,r){super(r),this.ty=e,this.ui=r}generateForm(){if(this.ui.open.checked){let e=this.ui.render(this.ty);this.form=[e]}else this.form=[]}parse(e){if(this.form.length===0)return[];{let r=this.form[0].parse(e);return r===void 0?void 0:[r]}}};Pt.OptionForm=Sp;var Ap=class extends Is{constructor(e,r){super(r),this.ty=e,this.ui=r}generateForm(){let e=+this.ui.open.value;this.form=[];for(let r=0;r<e;r++){let n=this.ui.render(this.ty);this.form.push(n)}}parse(e){let r=this.form.map(n=>n.parse(e));if(!this.form.some(n=>n.isRejected()))return r}};Pt.VecForm=Ap});var t_=Y(Ee=>{"use strict";var $E=Ee&&Ee.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),KE=Ee&&Ee.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),e_=Ee&&Ee.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[n.length]=s);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),s=0;s<n.length;s++)n[s]!=="default"&&$E(r,e,n[s]);return KE(r,e),r}})();Object.defineProperty(Ee,"__esModule",{value:!0});Ee.Render=Ee.vecForm=Ee.optForm=Ee.variantForm=Ee.tupleForm=Ee.recordForm=Ee.inputBox=void 0;Ee.renderInput=Up;Ee.renderValue=mo;var vu=e_(Op()),Cp=Ur(),mi=e_(Bp()),GE={parse:QE},Ia={render:Up},ZE=(t,e)=>new mi.InputBox(t,{...GE,...e});Ee.inputBox=ZE;var zE=(t,e)=>new mi.RecordForm(t,{...Ia,...e});Ee.recordForm=zE;var YE=(t,e)=>new mi.TupleForm(t,{...Ia,...e});Ee.tupleForm=YE;var WE=(t,e)=>new mi.VariantForm(t,{...Ia,...e});Ee.variantForm=WE;var XE=(t,e)=>new mi.OptionForm(t,{...Ia,...e});Ee.optForm=XE;var JE=(t,e)=>new mi.VecForm(t,{...Ia,...e});Ee.vecForm=JE;var Nu=class extends vu.Visitor{visitType(e,r){let n=document.createElement("input");return n.classList.add("argument"),n.placeholder=e.display(),(0,Ee.inputBox)(e,{input:n})}visitNull(e,r){return(0,Ee.inputBox)(e,{})}visitRecord(e,r,n){let s={};if(r.length>1){let i=document.createElement("div");i.classList.add("popup-form"),s={container:i}}let o=(0,Ee.recordForm)(r,s);return(0,Ee.inputBox)(e,{form:o})}visitTuple(e,r,n){let s={};if(r.length>1){let i=document.createElement("div");i.classList.add("popup-form"),s={container:i}}let o=(0,Ee.tupleForm)(r,s);return(0,Ee.inputBox)(e,{form:o})}visitVariant(e,r,n){let s=document.createElement("select");for(let[a,c]of r){let d=new Option(a);s.add(d)}s.selectedIndex=-1,s.classList.add("open");let o={open:s,event:"change"},i=(0,Ee.variantForm)(r,o);return(0,Ee.inputBox)(e,{form:i})}visitOpt(e,r,n){let s=document.createElement("input");s.type="checkbox",s.classList.add("open");let o=(0,Ee.optForm)(r,{open:s,event:"change"});return(0,Ee.inputBox)(e,{form:o})}visitVec(e,r,n){let s=document.createElement("input");s.type="number",s.min="0",s.max="100",s.style.width="8rem",s.placeholder="len",s.classList.add("open");let o=document.createElement("div");o.classList.add("popup-form");let i=(0,Ee.vecForm)(r,{open:s,event:"change",container:o});return(0,Ee.inputBox)(e,{form:i})}visitRec(e,r,n){return Up(r)}};Ee.Render=Nu;var Pp=class extends vu.Visitor{visitNull(e,r){return null}visitBool(e,r){if(r==="true")return!0;if(r==="false")return!1;throw new Error(`Cannot parse ${r} as boolean`)}visitText(e,r){return r}visitFloat(e,r){return parseFloat(r)}visitFixedInt(e,r){return e._bits<=32?parseInt(r,10):BigInt(r)}visitFixedNat(e,r){return e._bits<=32?parseInt(r,10):BigInt(r)}visitNumber(e,r){return BigInt(r)}visitPrincipal(e,r){return Cp.Principal.fromText(r)}visitService(e,r){return Cp.Principal.fromText(r)}visitFunc(e,r){let n=r.split(".",2);return[Cp.Principal.fromText(n[0]),n[1]]}},Dp=class extends vu.Visitor{visitNull(e,r){return null}visitBool(e,r){return Math.random()<.5}visitText(e,r){return Math.random().toString(36).substring(6)}visitFloat(e,r){return Math.random()}visitInt(e,r){return BigInt(this.generateNumber(!0))}visitNat(e,r){return BigInt(this.generateNumber(!1))}visitFixedInt(e,r){let n=this.generateNumber(!0);return e._bits<=32?n:BigInt(r)}visitFixedNat(e,r){let n=this.generateNumber(!1);return e._bits<=32?n:BigInt(r)}generateNumber(e){let r=Math.floor(Math.random()*100);return e&&Math.random()<.5?-r:r}};function QE(t,e,r){return e.random&&r===""?t.accept(new Dp,r):t.accept(new Pp,r)}function Up(t){return t.accept(new Nu,null)}function mo(t,e,r){return t.accept(new Fp,{input:e,value:r})}var Fp=class extends vu.Visitor{visitType(e,r){r.input.ui.input.value=e.valueToString(r.value)}visitNull(e,r){}visitText(e,r){r.input.ui.input.value=r.value}visitRec(e,r,n){mo(r,n.input,n.value)}visitOpt(e,r,n){if(n.value.length!==0){let s=n.input.ui.form,o=s.ui.open;o.checked=!0,o.dispatchEvent(new Event(s.ui.event)),mo(r,s.form[0],n.value[0])}}visitRecord(e,r,n){let s=n.input.ui.form;r.forEach(([o,i],a)=>{mo(i,s.form[a],n.value[o])})}visitTuple(e,r,n){let s=n.input.ui.form;r.forEach((o,i)=>{mo(o,s.form[i],n.value[i])})}visitVariant(e,r,n){let s=n.input.ui.form,o=Object.entries(n.value)[0];r.forEach(([i,a],c)=>{if(i===o[0]){let d=s.ui.open;d.selectedIndex=c,d.dispatchEvent(new Event(s.ui.event)),mo(a,s.form[0],o[1])}})}visitVec(e,r,n){let s=n.input.ui.form,o=n.value.length,i=s.ui.open;i.value=o,i.dispatchEvent(new Event(s.ui.event)),n.value.forEach((a,c)=>{mo(r,s.form[c],a)})}}});var n_=Y(r_=>{"use strict";Object.defineProperty(r_,"__esModule",{value:!0})});var Sa=Y(mt=>{"use strict";var s_=mt&&mt.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),eT=mt&&mt.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),yi=mt&&mt.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&s_(e,t,r)},tT=mt&&mt.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[n.length]=s);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),s=0;s<n.length;s++)n[s]!=="default"&&s_(r,e,n[s]);return eT(r,e),r}})();Object.defineProperty(mt,"__esModule",{value:!0});mt.IDL=void 0;yi(t_(),mt);yi(Bp(),mt);mt.IDL=tT(Op());yi(pp(),mt);yi(yp(),mt);yi(hu(),mt);yi(n_(),mt)});var _i=Y(Aa=>{"use strict";Object.defineProperty(Aa,"__esModule",{value:!0});Aa.uint8FromBufLike=o_;Aa.uint8ToBuf=rT;Aa.uint8Equals=nT;function o_(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?o_(t.buffer):new Uint8Array(t)}function rT(t){let e=new ArrayBuffer(t.byteLength);return new Uint8Array(e).set(t),e}function nT(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 Iu=Y(Ba=>{"use strict";Object.defineProperty(Ba,"__esModule",{value:!0});Ba.hashValue=Ru;Ba.requestIdOf=oT;Ba.hashOfMap=qp;var Vp=Sa(),i_=yr(),sT=_i(),Lp=ht(),yo=di();function Ru(t){if(typeof t=="string")return a_(t);if(typeof t=="number")return(0,yo.sha256)((0,Vp.lebEncode)(t));if(t instanceof Uint8Array||ArrayBuffer.isView(t))return(0,yo.sha256)((0,sT.uint8FromBufLike)(t));if(Array.isArray(t)){let e=t.map(Ru);return(0,yo.sha256)((0,Lp.concatBytes)(...e))}else{if(t&&typeof t=="object"&&t._isPrincipal)return(0,yo.sha256)(t.toUint8Array());if(typeof t=="object"&&t!==null&&typeof t.toHash=="function")return Ru(t.toHash());if(typeof t=="object")return qp(t);if(typeof t=="bigint")return(0,yo.sha256)((0,Vp.lebEncode)(t))}throw i_.InputError.fromCode(new i_.HashValueErrorCode(t))}var a_=t=>{let e=new TextEncoder().encode(t);return(0,yo.sha256)(e)};function oT(t){return qp(t)}function qp(t){let n=Object.entries(t).filter(([,i])=>i!==void 0).map(([i,a])=>{let c=a_(i),d=Ru(a);return[c,d]}).sort(([i],[a])=>(0,Vp.compare)(i,a)),s=(0,Lp.concatBytes)(...n.map(i=>(0,Lp.concatBytes)(...i)));return(0,yo.sha256)(s)}});var Su=Y(an=>{"use strict";Object.defineProperty(an,"__esModule",{value:!0});an.IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR=an.IC_RESPONSE_DOMAIN_SEPARATOR=an.IC_REQUEST_DOMAIN_SEPARATOR=an.DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS=void 0;an.DEFAULT_INGRESS_EXPIRY_DELTA_IN_MSECS=300*1e3;an.IC_REQUEST_DOMAIN_SEPARATOR=new TextEncoder().encode(`
|
|
52
|
+
ic-request`);an.IC_RESPONSE_DOMAIN_SEPARATOR=new TextEncoder().encode("\vic-response");an.IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR=new TextEncoder().encode("ic-request-auth-delegation")});var jp=Y(_o=>{"use strict";Object.defineProperty(_o,"__esModule",{value:!0});_o.AnonymousIdentity=_o.SignIdentity=void 0;_o.createIdentityDescriptor=cT;var c_=Ur(),iT=Iu(),u_=ht(),aT=Su(),Mp=class{getPrincipal(){return this._principal||(this._principal=c_.Principal.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:r,...n}=e,s=(0,iT.requestIdOf)(r);return{...n,body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign((0,u_.concatBytes)(aT.IC_REQUEST_DOMAIN_SEPARATOR,s))}}}};_o.SignIdentity=Mp;var kp=class{getPrincipal(){return c_.Principal.anonymous()}async transformRequest(e){return{...e,body:{content:e.body}}}};_o.AnonymousIdentity=kp;function cT(t){return"getPublicKey"in t?{type:"PublicKeyIdentity",publicKey:(0,u_.bytesToHex)(t.getPublicKey().toDer())}:{type:"AnonymousIdentity"}}});var l_=Y((Au,d_)=>{(function(t,e){typeof Au=="object"&&typeof d_<"u"?e(Au):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.Cbor={}))})(Au,function(t){"use strict";class e extends Error{constructor(j){super(j),this.name="DecodingError"}}let r=55799,n=Symbol("CBOR_STOP_CODE");var s=(D=>(D[D.False=20]="False",D[D.True=21]="True",D[D.Null=22]="Null",D[D.Undefined=23]="Undefined",D[D.Break=31]="Break",D))(s||{}),o=(D=>(D[D.UnsignedInteger=0]="UnsignedInteger",D[D.NegativeInteger=1]="NegativeInteger",D[D.ByteString=2]="ByteString",D[D.TextString=3]="TextString",D[D.Array=4]="Array",D[D.Map=5]="Map",D[D.Tag=6]="Tag",D[D.Simple=7]="Simple",D))(o||{});let i=23,a=255,c=65535,d=4294967295,f=BigInt("0xffffffffffffffff");var l=(D=>(D[D.Value=23]="Value",D[D.OneByte=24]="OneByte",D[D.TwoBytes=25]="TwoBytes",D[D.FourBytes=26]="FourBytes",D[D.EightBytes=27]="EightBytes",D[D.Indefinite=31]="Indefinite",D))(l||{});let u=!1;function p(D){return D==null}function h(D,j){let ie=new Uint8Array(j);return ie.set(D),ie}let m=new TextDecoder;function b(D){return(D&224)>>5}function y(D){return D&31}let x=new Uint8Array,_,T=0;function N(D,j){x=D,T=0;let ie=v(j);return j?.(ie)??ie}function v(D){let[j,ie]=R();switch(j){case o.UnsignedInteger:return U(ie);case o.NegativeInteger:return C(ie);case o.ByteString:return g(ie);case o.TextString:return w(ie);case o.Array:return A(ie,D);case o.Map:return S(ie,D);case o.Tag:return O(ie,D);case o.Simple:return E(ie)}throw new e(`Unsupported major type: ${j}`)}function R(){let D=x.at(T);if(p(D))throw new e("Provided CBOR data is empty");let j=b(D),ie=y(D);return T++,[j,ie]}function A(D,j){let ie=U(D);if(ie===1/0){let At=[],Tt=v(j);for(;Tt!==n;)At.push(j?.(Tt)??Tt),Tt=v(j);return At}let St=new Array(ie);for(let At=0;At<ie;At++){let Tt=v(j);St[At]=j?.(Tt)??Tt}return St}function E(D){switch(D){case s.False:return!1;case s.True:return!0;case s.Null:return null;case s.Undefined:return;case s.Break:return n}throw new e(`Unrecognized simple type: ${D.toString(2)}`)}function S(D,j){let ie=U(D),St={};if(ie===1/0){let[At,Tt]=R();for(;At!==o.Simple&&Tt!==s.Break;){let xs=w(Tt),Bn=v(j);St[xs]=j?.(Bn,xs)??Bn,[At,Tt]=R()}return St}for(let At=0;At<ie;At++){let[Tt,xs]=R();if(Tt!==o.TextString)throw new e("Map keys must be text strings");let Bn=w(xs),ws=v(j);St[Bn]=j?.(ws,Bn)??ws}return St}function U(D){if(D<=l.Value)return D;switch(_=new DataView(x.buffer,x.byteOffset+T),D){case l.OneByte:return T++,_.getUint8(0);case l.TwoBytes:return T+=2,_.getUint16(0,u);case l.FourBytes:return T+=4,_.getUint32(0,u);case l.EightBytes:return T+=8,_.getBigUint64(0,u);case l.Indefinite:return 1/0;default:throw new e(`Unsupported integer info: ${D.toString(2)}`)}}function C(D){let j=U(D);return typeof j=="number"?-1-j:-1n-j}function g(D){let j=U(D);if(j>Number.MAX_SAFE_INTEGER)throw new e("Byte length is too large");let ie=Number(j);return T+=ie,x.slice(T-ie,T)}function w(D){let j=g(D);return m.decode(j)}function O(D,j){let ie=U(D);if(ie===r)return v(j);throw new e(`Unsupported tag: ${ie}.`)}class P extends Error{constructor(j){super(j),this.name="SerializationError"}}let L=2*1024,I=100,B=new TextEncoder;function F(D){return D<<5}let V=new Uint8Array(L),q=new DataView(V.buffer),H=0,z=[];function G(D,j){H=0;let ie=j?.(D)??D;return re(ie,j),V.slice(0,H)}function ae(D,j){H=0;let ie=j?.(D)??D;return ba(r,ie,j),V.slice(0,H)}function re(D,j){if(H>V.length-I&&(V=h(V,V.length*2),q=new DataView(V.buffer)),D===!1||D===!0||D===null||D===void 0){It(D);return}if(typeof D=="number"||typeof D=="bigint"){_a(D);return}if(typeof D=="string"){oi(D);return}if(D instanceof Uint8Array){ii(D);return}if(D instanceof ArrayBuffer){ii(new Uint8Array(D));return}if(Array.isArray(D)){Ce(D,j);return}if(typeof D=="object"){se(D,j);return}throw new P(`Unsupported type: ${typeof D}`)}function Ce(D,j){me(o.Array,D.length),D.forEach((ie,St)=>{re(j?.(ie,St.toString())??ie,j)})}function se(D,j){z=Object.entries(D),me(o.Map,z.length),z.forEach(([ie,St])=>{oi(ie),re(j?.(St,ie)??St,j)})}function me(D,j){if(j<=i){q.setUint8(H++,F(D)|Number(j));return}if(j<=a){q.setUint8(H++,F(D)|l.OneByte),q.setUint8(H,Number(j)),H+=1;return}if(j<=c){q.setUint8(H++,F(D)|l.TwoBytes),q.setUint16(H,Number(j),u),H+=2;return}if(j<=d){q.setUint8(H++,F(D)|l.FourBytes),q.setUint32(H,Number(j),u),H+=4;return}if(j<=f){q.setUint8(H++,F(D)|l.EightBytes),q.setBigUint64(H,BigInt(j),u),H+=8;return}throw new P(`Value too large to encode: ${j}`)}function It(D){me(o.Simple,jt(D))}function jt(D){if(D===!1)return s.False;if(D===!0)return s.True;if(D===null)return s.Null;if(D===void 0)return s.Undefined;throw new P(`Unrecognized simple value: ${D.toString()}`)}function wr(D,j){me(D,j.length),H>V.length-j.length&&(V=h(V,V.length+j.length),q=new DataView(V.buffer)),V.set(j,H),H+=j.length}function An(D,j){me(D,j)}function gs(D){An(o.UnsignedInteger,D)}function ya(D){An(o.NegativeInteger,typeof D=="bigint"?-1n-D:-1-D)}function _a(D){D>=0?gs(D):ya(D)}function oi(D){wr(o.TextString,B.encode(D))}function ii(D){wr(o.ByteString,D)}function ba(D,j,ie){me(o.Tag,D),re(j,ie)}t.DecodingError=e,t.EncodingError=P,t.decode=N,t.encode=G,t.encodeWithSelfDescribedTag=ae,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})})});var Ca=Y(nr=>{"use strict";var uT=nr&&nr.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),dT=nr&&nr.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),lT=nr&&nr.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[n.length]=s);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),s=0;s<n.length;s++)n[s]!=="default"&&uT(r,e,n[s]);return dT(r,e),r}})();Object.defineProperty(nr,"__esModule",{value:!0});nr.Cbor=nr.ToCborValue=void 0;nr.encode=p_;nr.decode=h_;var fT=Ur(),f_=lT(l_()),Bu=yr(),pT=Pa(),Hp=class{};nr.ToCborValue=Hp;function hT(t){return typeof t=="object"&&t!==null&&"toCborValue"in t}function p_(t){try{return f_.encodeWithSelfDescribedTag(t,e=>fT.Principal.isPrincipal(e)?e.toUint8Array():pT.Expiry.isExpiry(e)?e.toBigInt():hT(e)?e.toCborValue():e)}catch(e){throw Bu.InputError.fromCode(new Bu.CborEncodeErrorCode(e,t))}}function h_(t){try{return f_.decode(t)}catch(e){throw Bu.InputError.fromCode(new Bu.CborDecodeErrorCode(e,t))}}nr.Cbor={encode:p_,decode:h_}});var $p=Y(Cu=>{"use strict";Object.defineProperty(Cu,"__esModule",{value:!0});Cu.randomNumber=void 0;var mT=()=>{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)};Cu.randomNumber=mT});var bi=Y(Un=>{"use strict";Object.defineProperty(Un,"__esModule",{value:!0});Un.ReadRequestType=Un.SubmitRequestType=Un.Endpoint=void 0;Un.makeNonce=yT;var Pu=$p(),m_;(function(t){t.Query="read",t.ReadState="read_state",t.Call="call"})(m_||(Un.Endpoint=m_={}));var y_;(function(t){t.Call="call"})(y_||(Un.SubmitRequestType=y_={}));var __;(function(t){t.Query="query",t.ReadState="read_state"})(__||(Un.ReadRequestType=__={}));function yT(){let t=new ArrayBuffer(16),e=new DataView(t),r=(0,Pu.randomNumber)(),n=(0,Pu.randomNumber)(),s=(0,Pu.randomNumber)(),o=(0,Pu.randomNumber)();return e.setUint32(0,r),e.setUint32(4,n),e.setUint32(8,s),e.setUint32(12,o),Object.assign(new Uint8Array(t),{__nonce__:void 0})}});var Uu=Y(_r=>{"use strict";Object.defineProperty(_r,"__esModule",{value:!0});_r.Expiry=_r.JSON_KEY_EXPIRY=void 0;_r.makeNonceTransform=wT;_r.makeExpiryTransform=ET;_r.httpHeadersTransform=TT;var _T=Sa(),b_=bi(),Du=yr();_r.JSON_KEY_EXPIRY="__expiry__";var Kp=BigInt(1e3),bT=BigInt(1e6),g_=BigInt(60),gT=BigInt(90)*Kp;function x_(t){return t/Kp}function xT(t){return x_(t)/g_}var Fu=class t{constructor(e){this.__expiry__=e,this._isExpiry=!0}static fromDeltaInMilliseconds(e,r=0){let n=BigInt(e),s=BigInt(Date.now())+n+BigInt(r),o;return n<gT?o=x_(s):o=xT(s)*g_,new t(o*Kp*bT)}toBigInt(){return this.__expiry__}toHash(){return(0,_T.lebEncode)(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[_r.JSON_KEY_EXPIRY]:this.toString()}}static fromJSON(e){let r=JSON.parse(e);if(r[_r.JSON_KEY_EXPIRY])try{let n=BigInt(r[_r.JSON_KEY_EXPIRY]);return new t(n)}catch(n){throw new Du.InputError(new Du.ExpiryJsonDeserializeErrorCode(`Not a valid BigInt: ${n}`))}throw new Du.InputError(new Du.ExpiryJsonDeserializeErrorCode(`The input does not contain the key ${_r.JSON_KEY_EXPIRY}`))}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"}};_r.Expiry=Fu;function wT(t=b_.makeNonce){return async e=>{let r=e.request.headers;e.request.headers=r,e.endpoint===b_.Endpoint.Call&&(e.body.nonce=t())}}function ET(t){return async e=>{e.body.ingress_expiry=Fu.fromDeltaInMilliseconds(t)}}function TT(t){let e=[];return t.forEach((r,n)=>{e.push([n,r])}),e}});var Vr=Y(ne=>{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});ne.notImplemented=ne.bitMask=ne.utf8ToBytes=ne.randomBytes=ne.isBytes=ne.hexToBytes=ne.concatBytes=ne.bytesToUtf8=ne.bytesToHex=ne.anumber=ne.abytes=void 0;ne.abool=OT;ne._abool2=NT;ne._abytes2=vT;ne.numberToHexUnpadded=w_;ne.hexToNumber=Zp;ne.bytesToNumberBE=RT;ne.bytesToNumberLE=IT;ne.numberToBytesBE=E_;ne.numberToBytesLE=ST;ne.numberToVarBytesBE=AT;ne.ensureBytes=BT;ne.equalBytes=CT;ne.copyBytes=PT;ne.asciiToBytes=DT;ne.inRange=T_;ne.aInRange=FT;ne.bitLen=UT;ne.bitGet=VT;ne.bitSet=LT;ne.createHmacDrbg=MT;ne.validateObject=jT;ne.isHash=HT;ne._validateObject=$T;ne.memoized=GT;var cn=ht(),Vn=ht();Object.defineProperty(ne,"abytes",{enumerable:!0,get:function(){return Vn.abytes}});Object.defineProperty(ne,"anumber",{enumerable:!0,get:function(){return Vn.anumber}});Object.defineProperty(ne,"bytesToHex",{enumerable:!0,get:function(){return Vn.bytesToHex}});Object.defineProperty(ne,"bytesToUtf8",{enumerable:!0,get:function(){return Vn.bytesToUtf8}});Object.defineProperty(ne,"concatBytes",{enumerable:!0,get:function(){return Vn.concatBytes}});Object.defineProperty(ne,"hexToBytes",{enumerable:!0,get:function(){return Vn.hexToBytes}});Object.defineProperty(ne,"isBytes",{enumerable:!0,get:function(){return Vn.isBytes}});Object.defineProperty(ne,"randomBytes",{enumerable:!0,get:function(){return Vn.randomBytes}});Object.defineProperty(ne,"utf8ToBytes",{enumerable:!0,get:function(){return Vn.utf8ToBytes}});var Vu=BigInt(0),Da=BigInt(1);function OT(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}function NT(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}"`;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function vT(t,e,r=""){let n=(0,cn.isBytes)(t),s=t?.length,o=e!==void 0;if(!n||o&&s!==e){let i=r&&`"${r}" `,a=o?` of length ${e}`:"",c=n?`length=${s}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return t}function w_(t){let e=t.toString(16);return e.length&1?"0"+e:e}function Zp(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Vu:BigInt("0x"+t)}function RT(t){return Zp((0,cn.bytesToHex)(t))}function IT(t){return(0,cn.abytes)(t),Zp((0,cn.bytesToHex)(Uint8Array.from(t).reverse()))}function E_(t,e){return(0,cn.hexToBytes)(t.toString(16).padStart(e*2,"0"))}function ST(t,e){return E_(t,e).reverse()}function AT(t){return(0,cn.hexToBytes)(w_(t))}function BT(t,e,r){let n;if(typeof e=="string")try{n=(0,cn.hexToBytes)(e)}catch(o){throw new Error(t+" must be hex string or Uint8Array, cause: "+o)}else if((0,cn.isBytes)(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let s=n.length;if(typeof r=="number"&&s!==r)throw new Error(t+" of length "+r+" expected, got "+s);return n}function CT(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function PT(t){return Uint8Array.from(t)}function DT(t){return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Gp=t=>typeof t=="bigint"&&Vu<=t;function T_(t,e,r){return Gp(t)&&Gp(e)&&Gp(r)&&e<=t&&t<r}function FT(t,e,r,n){if(!T_(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function UT(t){let e;for(e=0;t>Vu;t>>=Da,e+=1);return e}function VT(t,e){return t>>BigInt(e)&Da}function LT(t,e,r){return t|(r?Da:Vu)<<BigInt(e)}var qT=t=>(Da<<BigInt(t))-Da;ne.bitMask=qT;function MT(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),s=p=>Uint8Array.of(p),o=n(t),i=n(t),a=0,c=()=>{o.fill(1),i.fill(0),a=0},d=(...p)=>r(i,o,...p),f=(p=n(0))=>{i=d(s(0),p),o=d(),p.length!==0&&(i=d(s(1),p),o=d())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,h=[];for(;p<e;){o=d();let m=o.slice();h.push(m),p+=o.length}return(0,cn.concatBytes)(...h)};return(p,h)=>{c(),f(p);let m;for(;!(m=h(l()));)f();return c(),m}}var kT={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||(0,cn.isBytes)(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function jT(t,e,r={}){let n=(s,o,i)=>{let a=kT[o];if(typeof a!="function")throw new Error("invalid validator function");let c=t[s];if(!(i&&c===void 0)&&!a(c,t))throw new Error("param "+String(s)+" is invalid. Expected "+o+", got "+c)};for(let[s,o]of Object.entries(e))n(s,o,!1);for(let[s,o]of Object.entries(r))n(s,o,!0);return t}function HT(t){return typeof t=="function"&&Number.isSafeInteger(t.outputLen)}function $T(t,e,r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(s,o,i){let a=t[s];if(i&&a===void 0)return;let c=typeof a;if(c!==o||a===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${c}`)}Object.entries(e).forEach(([s,o])=>n(s,o,!1)),Object.entries(r).forEach(([s,o])=>n(s,o,!0))}var KT=()=>{throw new Error("not implemented")};ne.notImplemented=KT;function GT(t){let e=new WeakMap;return(r,...n)=>{let s=e.get(r);if(s!==void 0)return s;let o=t(r,...n);return e.set(r,o),o}}});var un=Y(je=>{"use strict";Object.defineProperty(je,"__esModule",{value:!0});je.isNegativeLE=void 0;je.mod=sr;je.pow=YT;je.pow2=WT;je.invert=Lu;je.tonelliShanks=Yp;je.FpSqrt=A_;je.validateField=t6;je.FpPow=Wp;je.FpInvertBatch=B_;je.FpDiv=r6;je.FpLegendre=qu;je.FpIsSquare=n6;je.nLength=Xp;je.Field=Mu;je.FpSqrtOdd=s6;je.FpSqrtEven=o6;je.hashToPrivateScalar=i6;je.getFieldBytesLength=Jp;je.getMinHashLength=C_;je.mapHashToField=a6;var or=Vr(),$t=BigInt(0),nt=BigInt(1),bo=BigInt(2),O_=BigInt(3),N_=BigInt(4),v_=BigInt(5),ZT=BigInt(7),R_=BigInt(8),zT=BigInt(9),I_=BigInt(16);function sr(t,e){let r=t%e;return r>=$t?r:e+r}function YT(t,e,r){return Wp(Mu(r),t,e)}function WT(t,e,r){let n=t;for(;e-- >$t;)n*=n,n%=r;return n}function Lu(t,e){if(t===$t)throw new Error("invert: expected non-zero number");if(e<=$t)throw new Error("invert: expected positive modulus, got "+e);let r=sr(t,e),n=e,s=$t,o=nt,i=nt,a=$t;for(;r!==$t;){let d=n/r,f=n%r,l=s-i*d,u=o-a*d;n=r,r=f,s=i,o=a,i=l,a=u}if(n!==nt)throw new Error("invert: does not exist");return sr(s,e)}function zp(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function S_(t,e){let r=(t.ORDER+nt)/N_,n=t.pow(e,r);return zp(t,n,e),n}function XT(t,e){let r=(t.ORDER-v_)/R_,n=t.mul(e,bo),s=t.pow(n,r),o=t.mul(e,s),i=t.mul(t.mul(o,bo),s),a=t.mul(o,t.sub(i,t.ONE));return zp(t,a,e),a}function JT(t){let e=Mu(t),r=Yp(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+ZT)/I_;return(a,c)=>{let d=a.pow(c,i),f=a.mul(d,n),l=a.mul(d,s),u=a.mul(d,o),p=a.eql(a.sqr(f),c),h=a.eql(a.sqr(l),c);d=a.cmov(d,f,p),f=a.cmov(u,l,h);let m=a.eql(a.sqr(f),c),b=a.cmov(d,f,m);return zp(a,b,c),b}}function Yp(t){if(t<O_)throw new Error("sqrt is not defined for small field");let e=t-nt,r=0;for(;e%bo===$t;)e/=bo,r++;let n=bo,s=Mu(t);for(;qu(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return S_;let o=s.pow(n,e),i=(e+nt)/bo;return function(c,d){if(c.is0(d))return d;if(qu(c,d)!==1)throw new Error("Cannot find square root");let f=r,l=c.mul(c.ONE,o),u=c.pow(d,e),p=c.pow(d,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let h=1,m=c.sqr(u);for(;!c.eql(m,c.ONE);)if(h++,m=c.sqr(m),h===f)throw new Error("Cannot find square root");let b=nt<<BigInt(f-h-1),y=c.pow(l,b);f=h,l=c.sqr(y),u=c.mul(u,l),p=c.mul(p,y)}return p}}function A_(t){return t%N_===O_?S_:t%R_===v_?XT:t%I_===zT?JT(t):Yp(t)}var QT=(t,e)=>(sr(t,e)&nt)===nt;je.isNegativeLE=QT;var e6=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function t6(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=e6.reduce((n,s)=>(n[s]="function",n),e);return(0,or._validateObject)(t,r),t}function Wp(t,e,r){if(r<$t)throw new Error("invalid exponent, negatives unsupported");if(r===$t)return t.ONE;if(r===nt)return e;let n=t.ONE,s=e;for(;r>$t;)r&nt&&(n=t.mul(n,s)),s=t.sqr(s),r>>=nt;return n}function B_(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),s=e.reduce((i,a,c)=>t.is0(a)?i:(n[c]=i,t.mul(i,a)),t.ONE),o=t.inv(s);return e.reduceRight((i,a,c)=>t.is0(a)?i:(n[c]=t.mul(i,n[c]),t.mul(i,a)),o),n}function r6(t,e,r){return t.mul(e,typeof r=="bigint"?Lu(r,t.ORDER):t.inv(r))}function qu(t,e){let r=(t.ORDER-nt)/bo,n=t.pow(e,r),s=t.eql(n,t.ONE),o=t.eql(n,t.ZERO),i=t.eql(n,t.neg(t.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function n6(t,e){return qu(t,e)===1}function Xp(t,e){e!==void 0&&(0,or.anumber)(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Mu(t,e,r=!1,n={}){if(t<=$t)throw new Error("invalid field: expected ORDER > 0, got "+t);let s,o,i=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=e;u.BITS&&(s=u.BITS),u.sqrt&&(o=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),a=u.allowedLengths}else typeof e=="number"&&(s=e),n.sqrt&&(o=n.sqrt);let{nBitLength:c,nByteLength:d}=Xp(t,s);if(d>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,l=Object.freeze({ORDER:t,isLE:r,BITS:c,BYTES:d,MASK:(0,or.bitMask)(c),ZERO:$t,ONE:nt,allowedLengths:a,create:u=>sr(u,t),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return $t<=u&&u<t},is0:u=>u===$t,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&nt)===nt,neg:u=>sr(-u,t),eql:(u,p)=>u===p,sqr:u=>sr(u*u,t),add:(u,p)=>sr(u+p,t),sub:(u,p)=>sr(u-p,t),mul:(u,p)=>sr(u*p,t),pow:(u,p)=>Wp(l,u,p),div:(u,p)=>sr(u*Lu(p,t),t),sqrN:u=>u*u,addN:(u,p)=>u+p,subN:(u,p)=>u-p,mulN:(u,p)=>u*p,inv:u=>Lu(u,t),sqrt:o||(u=>(f||(f=A_(t)),f(l,u))),toBytes:u=>r?(0,or.numberToBytesLE)(u,d):(0,or.numberToBytesBE)(u,d),fromBytes:(u,p=!0)=>{if(a){if(!a.includes(u.length)||u.length>d)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let m=new Uint8Array(d);m.set(u,r?0:m.length-u.length),u=m}if(u.length!==d)throw new Error("Field.fromBytes: expected "+d+" bytes, got "+u.length);let h=r?(0,or.bytesToNumberLE)(u):(0,or.bytesToNumberBE)(u);if(i&&(h=sr(h,t)),!p&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:u=>B_(l,u),cmov:(u,p,h)=>h?p:u});return Object.freeze(l)}function s6(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?r:t.neg(r)}function o6(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}function i6(t,e,r=!1){t=(0,or.ensureBytes)("privateHash",t);let n=t.length,s=Xp(e).nByteLength+8;if(s<24||n<s||n>1024)throw new Error("hashToPrivateScalar: expected "+s+"-1024 bytes of input, got "+n);let o=r?(0,or.bytesToNumberLE)(t):(0,or.bytesToNumberBE)(t);return sr(o,e-nt)+nt}function Jp(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function C_(t){let e=Jp(t);return e+Math.ceil(e/2)}function a6(t,e,r=!1){let n=t.length,s=Jp(e),o=C_(e);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?(0,or.bytesToNumberLE)(t):(0,or.bytesToNumberBE)(t),a=sr(i,e-nt)+nt;return r?(0,or.numberToBytesLE)(a,s):(0,or.numberToBytesBE)(a,s)}});var Va=Y(Lr=>{"use strict";Object.defineProperty(Lr,"__esModule",{value:!0});Lr.wNAF=void 0;Lr.negateCt=rh;Lr.normalizeZ=c6;Lr.mulEndoUnsafe=u6;Lr.pippenger=d6;Lr.precomputeMSMUnsafe=l6;Lr.validateBasic=f6;Lr._createCurveFields=p6;var Fa=Vr(),Ua=un(),gi=BigInt(0),go=BigInt(1);function rh(t,e){let r=e.negate();return t?r:e}function c6(t,e){let r=(0,Ua.FpInvertBatch)(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function sh(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Qp(t,e){sh(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),s=2**t,o=(0,Fa.bitMask)(t),i=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function P_(t,e,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(t&s),c=t>>i;a>n&&(a-=o,c+=go);let d=e*n,f=d+Math.abs(a)-1,l=a===0,u=a<0,p=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:u,isNegF:p,offsetF:d}}function U_(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function V_(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var eh=new WeakMap,L_=new WeakMap;function th(t){return L_.get(t)||1}function D_(t){if(t!==gi)throw new Error("invalid wNAF")}var nh=class{constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let s=e;for(;r>gi;)r&go&&(n=n.add(s)),s=s.double(),r>>=go;return n}precomputeWindow(e,r){let{windows:n,windowSize:s}=Qp(r,this.bits),o=[],i=e,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let d=1;d<s;d++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=Qp(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:d,isZero:f,isNeg:l,isNegF:u,offsetF:p}=P_(n,a,i);n=c,f?o=o.add(rh(u,r[p])):s=s.add(rh(l,r[d]))}return D_(n),{p:s,f:o}}wNAFUnsafe(e,r,n,s=this.ZERO){let o=Qp(e,this.bits);for(let i=0;i<o.windows&&n!==gi;i++){let{nextN:a,offset:c,isZero:d,isNeg:f}=P_(n,i,o);if(n=a,!d){let l=r[c];s=s.add(f?l.negate():l)}}return D_(n),s}getPrecomputes(e,r,n){let s=eh.get(r);return s||(s=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(s=n(s)),eh.set(r,s))),s}cached(e,r,n){let s=th(e);return this.wNAF(s,this.getPrecomputes(s,e,n),r)}unsafe(e,r,n,s){let o=th(e);return o===1?this._unsafeLadder(e,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,s)}createCache(e,r){sh(r,this.bits),L_.set(e,r),eh.delete(e)}hasCache(e){return th(e)!==1}};Lr.wNAF=nh;function u6(t,e,r,n){let s=e,o=t.ZERO,i=t.ZERO;for(;r>gi||n>gi;)r&go&&(o=o.add(s)),n&go&&(i=i.add(s)),s=s.double(),r>>=go,n>>=go;return{p1:o,p2:i}}function d6(t,e,r,n){U_(r,t),V_(n,e);let s=r.length,o=n.length;if(s!==o)throw new Error("arrays of points and scalars must have equal length");let i=t.ZERO,a=(0,Fa.bitLen)(BigInt(s)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let d=(0,Fa.bitMask)(c),f=new Array(Number(d)+1).fill(i),l=Math.floor((e.BITS-1)/c)*c,u=i;for(let p=l;p>=0;p-=c){f.fill(i);for(let m=0;m<o;m++){let b=n[m],y=Number(b>>BigInt(p)&d);f[y]=f[y].add(r[m])}let h=i;for(let m=f.length-1,b=i;m>0;m--)b=b.add(f[m]),h=h.add(b);if(u=u.add(h),p!==0)for(let m=0;m<c;m++)u=u.double()}return u}function l6(t,e,r,n){sh(n,e.BITS),U_(r,t);let s=t.ZERO,o=2**n-1,i=Math.ceil(e.BITS/n),a=(0,Fa.bitMask)(n),c=r.map(d=>{let f=[];for(let l=0,u=d;l<o;l++)f.push(u),u=u.add(d);return f});return d=>{if(V_(d,e),d.length>r.length)throw new Error("array of scalars must be smaller than array of points");let f=s;for(let l=0;l<i;l++){if(f!==s)for(let p=0;p<n;p++)f=f.double();let u=BigInt(i*n-(l+1)*n);for(let p=0;p<d.length;p++){let h=d[p],m=Number(h>>u&a);m&&(f=f.add(c[p][m-1]))}}return f}}function f6(t){return(0,Ua.validateField)(t.Fp),(0,Fa.validateObject)(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,Ua.nLength)(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function F_(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return(0,Ua.validateField)(e),e}else return(0,Ua.Field)(t,{isLE:r})}function p6(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let d=e[c];if(!(typeof d=="bigint"&&d>gi))throw new Error(`CURVE.${c} must be positive bigint`)}let s=F_(e.p,r.Fp,n),o=F_(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}});var ju=Y(dn=>{"use strict";Object.defineProperty(dn,"__esModule",{value:!0});dn._DST_scalar=void 0;dn.expand_message_xmd=k_;dn.expand_message_xof=j_;dn.hash_to_field=ku;dn.isogenyMap=y6;dn.createHasher=_6;var Ot=Vr(),q_=un(),h6=Ot.bytesToNumberBE;function Ss(t,e){if(La(t),La(e),t<0||t>=1<<8*e)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 m6(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 La(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function M_(t){if(!(0,Ot.isBytes)(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or string");return typeof t=="string"?(0,Ot.utf8ToBytes)(t):t}function k_(t,e,r,n){(0,Ot.abytes)(t),La(r),e=M_(e),e.length>255&&(e=n((0,Ot.concatBytes)((0,Ot.utf8ToBytes)("H2C-OVERSIZE-DST-"),e)));let{outputLen:s,blockLen:o}=n,i=Math.ceil(r/s);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=(0,Ot.concatBytes)(e,Ss(e.length,1)),c=Ss(0,o),d=Ss(r,2),f=new Array(i),l=n((0,Ot.concatBytes)(c,t,d,Ss(0,1),a));f[0]=n((0,Ot.concatBytes)(l,Ss(1,1),a));for(let p=1;p<=i;p++){let h=[m6(l,f[p-1]),Ss(p+1,1),a];f[p]=n((0,Ot.concatBytes)(...h))}return(0,Ot.concatBytes)(...f).slice(0,r)}function j_(t,e,r,n,s){if((0,Ot.abytes)(t),La(r),e=M_(e),e.length>255){let o=Math.ceil(2*n/8);e=s.create({dkLen:o}).update((0,Ot.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return s.create({dkLen:r}).update(t).update(Ss(r,2)).update(e).update(Ss(e.length,1)).digest()}function ku(t,e,r){(0,Ot._validateObject)(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:s,m:o,hash:i,expand:a,DST:c}=r;if(!(0,Ot.isHash)(r.hash))throw new Error("expected valid hash");(0,Ot.abytes)(t),La(e);let d=n.toString(2).length,f=Math.ceil((d+s)/8),l=e*o*f,u;if(a==="xmd")u=k_(t,c,l,i);else if(a==="xof")u=j_(t,c,l,s,i);else if(a==="_internal_pass")u=t;else throw new Error('expand must be "xmd" or "xof"');let p=new Array(e);for(let h=0;h<e;h++){let m=new Array(o);for(let b=0;b<o;b++){let y=f*(b+h*o),x=u.subarray(y,y+f);m[b]=(0,q_.mod)(h6(x),n)}p[h]=m}return p}function y6(t,e){let r=e.map(n=>Array.from(n).reverse());return(n,s)=>{let[o,i,a,c]=r.map(l=>l.reduce((u,p)=>t.add(t.mul(u,n),p))),[d,f]=(0,q_.FpInvertBatch)(t,[i,c],!0);return n=t.mul(o,d),s=t.mul(s,t.mul(a,f)),{x:n,y:s}}}dn._DST_scalar=(0,Ot.utf8ToBytes)("HashToScalar-");function _6(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function n(o){return t.fromAffine(e(o))}function s(o){let i=o.clearCofactor();return i.equals(t.ZERO)?t.ZERO:(i.assertValidity(),i)}return{defaults:r,hashToCurve(o,i){let a=Object.assign({},r,i),c=ku(o,2,a),d=n(c[0]),f=n(c[1]);return s(d.add(f))},encodeToCurve(o,i){let a=r.encodeDST?{DST:r.encodeDST}:{},c=Object.assign({},r,a,i),d=ku(o,1,c),f=n(d[0]);return s(f)},mapToCurve(o){if(!Array.isArray(o))throw new Error("expected array of bigints");for(let i of o)if(typeof i!="bigint")throw new Error("expected array of bigints");return s(n(o))},hashToScalar(o,i){let a=t.Fn.ORDER,c=Object.assign({},r,{p:a,m:1,DST:dn._DST_scalar},i);return ku(o,1,c)[0][0]}}}});var H_=Y(wo=>{"use strict";Object.defineProperty(wo,"__esModule",{value:!0});wo.hmac=wo.HMAC=void 0;var xo=ht(),qa=class extends xo.Hash{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,(0,xo.ahash)(e);let n=(0,xo.toBytes)(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?e.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),(0,xo.clean)(o)}update(e){return(0,xo.aexists)(this),this.iHash.update(e),this}digestInto(e){(0,xo.aexists)(this),(0,xo.abytes)(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};wo.HMAC=qa;var b6=(t,e,r)=>new qa(t,e).update(r).digest();wo.hmac=b6;wo.hmac.create=(t,e)=>new qa(t,e)});var uh=Y(qe=>{"use strict";Object.defineProperty(qe,"__esModule",{value:!0});qe.DER=qe.DERErr=void 0;qe._splitEndoScalar=K_;qe._normFnElement=As;qe.weierstrassN=ch;qe.SWUFpSqrtRatio=Z_;qe.mapToCurveSimpleSWU=w6;qe.ecdh=Y_;qe.ecdsa=W_;qe.weierstrassPoints=E6;qe._legacyHelperEquat=J_;qe.weierstrass=v6;var g6=H_(),x6=ht(),W=Vr(),Ln=Va(),wi=un(),$_=(t,e)=>(t+(t>=0?e:-e)/ln)/e;function K_(t,e,r){let[[n,s],[o,i]]=e,a=$_(i*t,r),c=$_(-s*t,r),d=t-a*n-c*o,f=-a*s-c*i,l=d<qr,u=f<qr;l&&(d=-d),u&&(f=-f);let p=(0,W.bitMask)(Math.ceil((0,W.bitLen)(r)/2))+Nt;if(d<qr||d>=p||f<qr||f>=p)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:l,k1:d,k2neg:u,k2:f}}function ih(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function oh(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return(0,W._abool2)(r.lowS,"lowS"),(0,W._abool2)(r.prehash,"prehash"),r.format!==void 0&&ih(r.format),r}var Hu=class extends Error{constructor(e=""){super(e)}};qe.DERErr=Hu;qe.DER={Err:Hu,_tlv:{encode:(t,e)=>{let{Err:r}=qe.DER;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=(0,W.numberToHexUnpadded)(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?(0,W.numberToHexUnpadded)(s.length/2|128):"";return(0,W.numberToHexUnpadded)(t)+o+s+e},decode(t,e){let{Err:r}=qe.DER,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let d=e.subarray(n,n+c);if(d.length!==c)throw new r("tlv.decode: length bytes not complete");if(d[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of d)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=qe.DER;if(t<qr)throw new e("integer: negative integers are not allowed");let r=(0,W.numberToHexUnpadded)(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=qe.DER;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return(0,W.bytesToNumberBE)(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=qe.DER,s=(0,W.ensureBytes)("signature",t),{v:o,l:i}=n.decode(48,s);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:d,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(d)}},hexFromSig(t){let{_tlv:e,_int:r}=qe.DER,n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}};var qr=BigInt(0),Nt=BigInt(1),ln=BigInt(2),xi=BigInt(3),ah=BigInt(4);function As(t,e){let{BYTES:r}=t,n;if(typeof e=="bigint")n=e;else{let s=(0,W.ensureBytes)("private key",e);try{n=t.fromBytes(s)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`)}}if(!t.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function ch(t,e={}){let r=(0,Ln._createCurveFields)("weierstrass",t,e),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i,n:a}=o;(0,W._validateObject)(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=z_(n,s);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,g,w){let{x:O,y:P}=g.toAffine(),L=n.toBytes(O);if((0,W._abool2)(w,"isCompressed"),w){f();let I=!n.isOdd(P);return(0,W.concatBytes)(G_(I),L)}else return(0,W.concatBytes)(Uint8Array.of(4),L,n.toBytes(P))}function u(C){(0,W._abytes2)(C,void 0,"Point");let{publicKey:g,publicKeyUncompressed:w}=d,O=C.length,P=C[0],L=C.subarray(1);if(O===g&&(P===2||P===3)){let I=n.fromBytes(L);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let B=m(I),F;try{F=n.sqrt(B)}catch(H){let z=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}f();let V=n.isOdd(F);return(P&1)===1!==V&&(F=n.neg(F)),{x:I,y:F}}else if(O===w&&P===4){let I=n.BYTES,B=n.fromBytes(L.subarray(0,I)),F=n.fromBytes(L.subarray(I,I*2));if(!b(B,F))throw new Error("bad point: is not on curve");return{x:B,y:F}}else throw new Error(`bad point: got length ${O}, expected compressed=${g} or uncompressed=${w}`)}let p=e.toBytes||l,h=e.fromBytes||u;function m(C){let g=n.sqr(C),w=n.mul(g,C);return n.add(n.add(w,n.mul(C,o.a)),o.b)}function b(C,g){let w=n.sqr(g),O=m(C);return n.eql(w,O)}if(!b(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(o.a,xi),ah),x=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(y,x)))throw new Error("bad curve params: a or b");function _(C,g,w=!1){if(!n.isValid(g)||w&&n.is0(g))throw new Error(`bad point coordinate ${C}`);return g}function T(C){if(!(C instanceof E))throw new Error("ProjectivePoint expected")}function N(C){if(!c||!c.basises)throw new Error("no endo");return K_(C,c.basises,s.ORDER)}let v=(0,W.memoized)((C,g)=>{let{X:w,Y:O,Z:P}=C;if(n.eql(P,n.ONE))return{x:w,y:O};let L=C.is0();g==null&&(g=L?n.ONE:n.inv(P));let I=n.mul(w,g),B=n.mul(O,g),F=n.mul(P,g);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:I,y:B}}),R=(0,W.memoized)(C=>{if(C.is0()){if(e.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:w}=C.toAffine();if(!n.isValid(g)||!n.isValid(w))throw new Error("bad point: x or y not field elements");if(!b(g,w))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(C,g,w,O,P){return w=new E(n.mul(w.X,C),w.Y,w.Z),g=(0,Ln.negateCt)(O,g),w=(0,Ln.negateCt)(P,w),g.add(w)}class E{constructor(g,w,O){this.X=_("x",g),this.Y=_("y",w,!0),this.Z=_("z",O),Object.freeze(this)}static CURVE(){return o}static fromAffine(g){let{x:w,y:O}=g||{};if(!g||!n.isValid(w)||!n.isValid(O))throw new Error("invalid affine point");if(g instanceof E)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(O)?E.ZERO:new E(w,O,n.ONE)}static fromBytes(g){let w=E.fromAffine(h((0,W._abytes2)(g,void 0,"point")));return w.assertValidity(),w}static fromHex(g){return E.fromBytes((0,W.ensureBytes)("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,w=!0){return U.createCache(this,g),w||this.multiply(xi),this}assertValidity(){R(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){T(g);let{X:w,Y:O,Z:P}=this,{X:L,Y:I,Z:B}=g,F=n.eql(n.mul(w,B),n.mul(L,P)),V=n.eql(n.mul(O,B),n.mul(I,P));return F&&V}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:w}=o,O=n.mul(w,xi),{X:P,Y:L,Z:I}=this,B=n.ZERO,F=n.ZERO,V=n.ZERO,q=n.mul(P,P),H=n.mul(L,L),z=n.mul(I,I),G=n.mul(P,L);return G=n.add(G,G),V=n.mul(P,I),V=n.add(V,V),B=n.mul(g,V),F=n.mul(O,z),F=n.add(B,F),B=n.sub(H,F),F=n.add(H,F),F=n.mul(B,F),B=n.mul(G,B),V=n.mul(O,V),z=n.mul(g,z),G=n.sub(q,z),G=n.mul(g,G),G=n.add(G,V),V=n.add(q,q),q=n.add(V,q),q=n.add(q,z),q=n.mul(q,G),F=n.add(F,q),z=n.mul(L,I),z=n.add(z,z),q=n.mul(z,G),B=n.sub(B,q),V=n.mul(z,H),V=n.add(V,V),V=n.add(V,V),new E(B,F,V)}add(g){T(g);let{X:w,Y:O,Z:P}=this,{X:L,Y:I,Z:B}=g,F=n.ZERO,V=n.ZERO,q=n.ZERO,H=o.a,z=n.mul(o.b,xi),G=n.mul(w,L),ae=n.mul(O,I),re=n.mul(P,B),Ce=n.add(w,O),se=n.add(L,I);Ce=n.mul(Ce,se),se=n.add(G,ae),Ce=n.sub(Ce,se),se=n.add(w,P);let me=n.add(L,B);return se=n.mul(se,me),me=n.add(G,re),se=n.sub(se,me),me=n.add(O,P),F=n.add(I,B),me=n.mul(me,F),F=n.add(ae,re),me=n.sub(me,F),q=n.mul(H,se),F=n.mul(z,re),q=n.add(F,q),F=n.sub(ae,q),q=n.add(ae,q),V=n.mul(F,q),ae=n.add(G,G),ae=n.add(ae,G),re=n.mul(H,re),se=n.mul(z,se),ae=n.add(ae,re),re=n.sub(G,re),re=n.mul(H,re),se=n.add(se,re),G=n.mul(ae,se),V=n.add(V,G),G=n.mul(me,se),F=n.mul(Ce,F),F=n.sub(F,G),G=n.mul(Ce,ae),q=n.mul(me,q),q=n.add(q,G),new E(F,V,q)}subtract(g){return this.add(g.negate())}is0(){return this.equals(E.ZERO)}multiply(g){let{endo:w}=e;if(!s.isValidNot0(g))throw new Error("invalid scalar: out of range");let O,P,L=I=>U.cached(this,I,B=>(0,Ln.normalizeZ)(E,B));if(w){let{k1neg:I,k1:B,k2neg:F,k2:V}=N(g),{p:q,f:H}=L(B),{p:z,f:G}=L(V);P=H.add(G),O=A(w.beta,q,z,I,F)}else{let{p:I,f:B}=L(g);O=I,P=B}return(0,Ln.normalizeZ)(E,[O,P])[0]}multiplyUnsafe(g){let{endo:w}=e,O=this;if(!s.isValid(g))throw new Error("invalid scalar: out of range");if(g===qr||O.is0())return E.ZERO;if(g===Nt)return O;if(U.hasCache(this))return this.multiply(g);if(w){let{k1neg:P,k1:L,k2neg:I,k2:B}=N(g),{p1:F,p2:V}=(0,Ln.mulEndoUnsafe)(E,O,L,B);return A(w.beta,F,V,P,I)}else return U.unsafe(O,g)}multiplyAndAddUnsafe(g,w,O){let P=this.multiplyUnsafe(w).add(g.multiplyUnsafe(O));return P.is0()?void 0:P}toAffine(g){return v(this,g)}isTorsionFree(){let{isTorsionFree:g}=e;return i===Nt?!0:g?g(E,this):U.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=e;return i===Nt?this:g?g(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return(0,W._abool2)(g,"isCompressed"),this.assertValidity(),p(E,this,g)}toHex(g=!0){return(0,W.bytesToHex)(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return(0,Ln.normalizeZ)(E,g)}static msm(g,w){return(0,Ln.pippenger)(E,s,g,w)}static fromPrivateKey(g){return E.BASE.multiply(As(s,g))}}E.BASE=new E(o.Gx,o.Gy,n.ONE),E.ZERO=new E(n.ZERO,n.ONE,n.ZERO),E.Fp=n,E.Fn=s;let S=s.BITS,U=new Ln.wNAF(E,e.endo?Math.ceil(S/2):S);return E.BASE.precompute(8),E}function G_(t){return Uint8Array.of(t?2:3)}function Z_(t,e){let r=t.ORDER,n=qr;for(let h=r-Nt;h%ln===qr;h/=ln)n+=Nt;let s=n,o=ln<<s-Nt-Nt,i=o*ln,a=(r-Nt)/i,c=(a-Nt)/ln,d=i-Nt,f=o,l=t.pow(e,a),u=t.pow(e,(a+Nt)/ln),p=(h,m)=>{let b=l,y=t.pow(m,d),x=t.sqr(y);x=t.mul(x,m);let _=t.mul(h,x);_=t.pow(_,c),_=t.mul(_,y),y=t.mul(_,m),x=t.mul(_,h);let T=t.mul(x,y);_=t.pow(T,f);let N=t.eql(_,t.ONE);y=t.mul(x,u),_=t.mul(T,b),x=t.cmov(y,x,N),T=t.cmov(_,T,N);for(let v=s;v>Nt;v--){let R=v-ln;R=ln<<R-Nt;let A=t.pow(T,R),E=t.eql(A,t.ONE);y=t.mul(x,b),b=t.mul(b,b),A=t.mul(T,b),x=t.cmov(y,x,E),T=t.cmov(A,T,E)}return{isValid:N,value:x}};if(t.ORDER%ah===xi){let h=(t.ORDER-xi)/ah,m=t.sqrt(t.neg(e));p=(b,y)=>{let x=t.sqr(y),_=t.mul(b,y);x=t.mul(x,_);let T=t.pow(x,h);T=t.mul(T,_);let N=t.mul(T,m),v=t.mul(t.sqr(T),y),R=t.eql(v,b),A=t.cmov(N,T,R);return{isValid:R,value:A}}}return p}function w6(t,e){(0,wi.validateField)(t);let{A:r,B:n,Z:s}=e;if(!t.isValid(r)||!t.isValid(n)||!t.isValid(s))throw new Error("mapToCurveSimpleSWU: invalid opts");let o=Z_(t,s);if(!t.isOdd)throw new Error("Field does not have .isOdd()");return i=>{let a,c,d,f,l,u,p,h;a=t.sqr(i),a=t.mul(a,s),c=t.sqr(a),c=t.add(c,a),d=t.add(c,t.ONE),d=t.mul(d,n),f=t.cmov(s,t.neg(c),!t.eql(c,t.ZERO)),f=t.mul(f,r),c=t.sqr(d),u=t.sqr(f),l=t.mul(u,r),c=t.add(c,l),c=t.mul(c,d),u=t.mul(u,f),l=t.mul(u,n),c=t.add(c,l),p=t.mul(a,d);let{isValid:m,value:b}=o(c,u);h=t.mul(a,i),h=t.mul(h,b),p=t.cmov(p,d,m),h=t.cmov(h,b,m);let y=t.isOdd(i)===t.isOdd(h);h=t.cmov(t.neg(h),h,y);let x=(0,wi.FpInvertBatch)(t,[f],!0)[0];return p=t.mul(p,x),{x:p,y:h}}}function z_(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Y_(t,e={}){let{Fn:r}=t,n=e.randomBytes||W.randomBytes,s=Object.assign(z_(t.Fp,r),{seed:(0,wi.getMinHashLength)(r.ORDER)});function o(p){try{return!!As(r,p)}catch{return!1}}function i(p,h){let{publicKey:m,publicKeyUncompressed:b}=s;try{let y=p.length;return h===!0&&y!==m||h===!1&&y!==b?!1:!!t.fromBytes(p)}catch{return!1}}function a(p=n(s.seed)){return(0,wi.mapHashToField)((0,W._abytes2)(p,s.seed,"seed"),r.ORDER)}function c(p,h=!0){return t.BASE.multiply(As(r,p)).toBytes(h)}function d(p){let h=a(p);return{secretKey:h,publicKey:c(h)}}function f(p){if(typeof p=="bigint")return!1;if(p instanceof t)return!0;let{secretKey:h,publicKey:m,publicKeyUncompressed:b}=s;if(r.allowedLengths||h===m)return;let y=(0,W.ensureBytes)("key",p).length;return y===m||y===b}function l(p,h,m=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(h)===!1)throw new Error("second arg must be public key");let b=As(r,p);return t.fromHex(h).multiply(b).toBytes(m)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:d,Point:t,utils:{isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:p=>As(r,p),precompute(p=8,h=t.BASE){return h.precompute(p,!1)}},lengths:s})}function W_(t,e,r={}){(0,x6.ahash)(e),(0,W._validateObject)(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||W.randomBytes,s=r.hmac||((w,...O)=>(0,g6.hmac)(e,w,(0,W.concatBytes)(...O))),{Fp:o,Fn:i}=t,{ORDER:a,BITS:c}=i,{keygen:d,getPublicKey:f,getSharedSecret:l,utils:u,lengths:p}=Y_(t,r),h={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},m="compact";function b(w){let O=a>>Nt;return w>O}function y(w,O){if(!i.isValidNot0(O))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return O}function x(w,O){ih(O);let P=p.signature,L=O==="compact"?P:O==="recovered"?P+1:void 0;return(0,W._abytes2)(w,L,`${O} signature`)}class _{constructor(O,P,L){this.r=y("r",O),this.s=y("s",P),L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(O,P=m){x(O,P);let L;if(P==="der"){let{r:V,s:q}=qe.DER.toSig((0,W._abytes2)(O));return new _(V,q)}P==="recovered"&&(L=O[0],P="compact",O=O.subarray(1));let I=i.BYTES,B=O.subarray(0,I),F=O.subarray(I,I*2);return new _(i.fromBytes(B),i.fromBytes(F),L)}static fromHex(O,P){return this.fromBytes((0,W.hexToBytes)(O),P)}addRecoveryBit(O){return new _(this.r,this.s,O)}recoverPublicKey(O){let P=o.ORDER,{r:L,s:I,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(a*ln<P&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let V=B===2||B===3?L+a:L;if(!o.isValid(V))throw new Error("recovery id 2 or 3 invalid");let q=o.toBytes(V),H=t.fromBytes((0,W.concatBytes)(G_((B&1)===0),q)),z=i.inv(V),G=N((0,W.ensureBytes)("msgHash",O)),ae=i.create(-G*z),re=i.create(I*z),Ce=t.BASE.multiplyUnsafe(ae).add(H.multiplyUnsafe(re));if(Ce.is0())throw new Error("point at infinify");return Ce.assertValidity(),Ce}hasHighS(){return b(this.s)}toBytes(O=m){if(ih(O),O==="der")return(0,W.hexToBytes)(qe.DER.hexFromSig(this));let P=i.toBytes(this.r),L=i.toBytes(this.s);if(O==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return(0,W.concatBytes)(Uint8Array.of(this.recovery),P,L)}return(0,W.concatBytes)(P,L)}toHex(O){return(0,W.bytesToHex)(this.toBytes(O))}assertValidity(){}static fromCompact(O){return _.fromBytes((0,W.ensureBytes)("sig",O),"compact")}static fromDER(O){return _.fromBytes((0,W.ensureBytes)("sig",O),"der")}normalizeS(){return this.hasHighS()?new _(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return(0,W.bytesToHex)(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return(0,W.bytesToHex)(this.toBytes("compact"))}}let T=r.bits2int||function(O){if(O.length>8192)throw new Error("input is too large");let P=(0,W.bytesToNumberBE)(O),L=O.length*8-c;return L>0?P>>BigInt(L):P},N=r.bits2int_modN||function(O){return i.create(T(O))},v=(0,W.bitMask)(c);function R(w){return(0,W.aInRange)("num < 2^"+c,w,qr,v),i.toBytes(w)}function A(w,O){return(0,W._abytes2)(w,void 0,"message"),O?(0,W._abytes2)(e(w),void 0,"prehashed message"):w}function E(w,O,P){if(["recovered","canonical"].some(ae=>ae in P))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:I,extraEntropy:B}=oh(P,h);w=A(w,I);let F=N(w),V=As(i,O),q=[R(V),R(F)];if(B!=null&&B!==!1){let ae=B===!0?n(p.secretKey):B;q.push((0,W.ensureBytes)("extraEntropy",ae))}let H=(0,W.concatBytes)(...q),z=F;function G(ae){let re=T(ae);if(!i.isValidNot0(re))return;let Ce=i.inv(re),se=t.BASE.multiply(re).toAffine(),me=i.create(se.x);if(me===qr)return;let It=i.create(Ce*i.create(z+me*V));if(It===qr)return;let jt=(se.x===me?0:2)|Number(se.y&Nt),wr=It;return L&&b(It)&&(wr=i.neg(It),jt^=1),new _(me,wr,jt)}return{seed:H,k2sig:G}}function S(w,O,P={}){w=(0,W.ensureBytes)("message",w);let{seed:L,k2sig:I}=E(w,O,P);return(0,W.createHmacDrbg)(e.outputLen,i.BYTES,s)(L,I)}function U(w){let O,P=typeof w=="string"||(0,W.isBytes)(w),L=!P&&w!==null&&typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!P&&!L)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(L)O=new _(w.r,w.s);else if(P){try{O=_.fromBytes((0,W.ensureBytes)("sig",w),"der")}catch(I){if(!(I instanceof qe.DER.Err))throw I}if(!O)try{O=_.fromBytes((0,W.ensureBytes)("sig",w),"compact")}catch{return!1}}return O||!1}function C(w,O,P,L={}){let{lowS:I,prehash:B,format:F}=oh(L,h);if(P=(0,W.ensureBytes)("publicKey",P),O=A((0,W.ensureBytes)("message",O),B),"strict"in L)throw new Error("options.strict was renamed to lowS");let V=F===void 0?U(w):_.fromBytes((0,W.ensureBytes)("sig",w),F);if(V===!1)return!1;try{let q=t.fromBytes(P);if(I&&V.hasHighS())return!1;let{r:H,s:z}=V,G=N(O),ae=i.inv(z),re=i.create(G*ae),Ce=i.create(H*ae),se=t.BASE.multiplyUnsafe(re).add(q.multiplyUnsafe(Ce));return se.is0()?!1:i.create(se.x)===H}catch{return!1}}function g(w,O,P={}){let{prehash:L}=oh(P,h);return O=A(O,L),_.fromBytes(w,"recovered").recoverPublicKey(O).toBytes()}return Object.freeze({keygen:d,getPublicKey:f,getSharedSecret:l,utils:u,lengths:p,Point:t,sign:S,verify:C,recoverPublicKey:g,Signature:_,hash:e})}function E6(t){let{CURVE:e,curveOpts:r}=X_(t),n=ch(e,r);return O6(t,n)}function X_(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,s=(0,wi.Field)(e.n,{BITS:t.nBitLength,allowedLengths:n,modFromBytes:t.wrapPrivateKey}),o={Fp:r,Fn:s,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:o}}function T6(t){let{CURVE:e,curveOpts:r}=X_(t),n={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:r,hash:t.hash,ecdsaOpts:n}}function J_(t,e,r){function n(s){let o=t.sqr(s),i=t.mul(o,s);return t.add(t.add(i,t.mul(s,e)),r)}return n}function O6(t,e){let{Fp:r,Fn:n}=e;function s(i){return(0,W.inRange)(i,Nt,n.ORDER)}let o=J_(r,t.a,t.b);return Object.assign({},{CURVE:t,Point:e,ProjectivePoint:e,normPrivateKeyToScalar:i=>As(n,i),weierstrassEquation:o,isWithinCurveOrder:s})}function N6(t,e){let r=e.Point;return Object.assign({},e,{ProjectivePoint:r,CURVE:Object.assign({},t,(0,wi.nLength)(r.Fn.ORDER,r.Fn.BITS))})}function v6(t){let{CURVE:e,curveOpts:r,hash:n,ecdsaOpts:s}=T6(t),o=ch(e,r),i=W_(o,n,s);return N6(t,i)}});var sb=Y(lh=>{"use strict";Object.defineProperty(lh,"__esModule",{value:!0});lh.bls=A6;var Ma=Vr(),Q_=Va(),eb=ju(),tb=un(),Ku=uh(),R6=BigInt(0),$u=BigInt(1),rb=BigInt(2),Ei=BigInt(3);function I6(t){let e=[];for(;t>$u;t>>=$u)(t&$u)===R6?e.unshift(0):(t&Ei)===Ei?(e.unshift(-1),t+=$u):e.unshift(1);return e}function dh(t){if(!Array.isArray(t)||t.length===0)throw new Error("expected non-empty array")}function S6(t,e,r,n){let{Fp2:s,Fp12:o}=t,{twistType:i,ateLoopSize:a,xNegative:c,postPrecompute:d}=n,f;if(i==="multiplicative")f=(_,T,N,v,R,A)=>o.mul014(v,_,s.mul(T,R),s.mul(N,A));else if(i==="divisive")f=(_,T,N,v,R,A)=>o.mul034(v,s.mul(N,A),s.mul(T,R),_);else throw new Error("bls: unknown twist type");let l=s.div(s.ONE,s.mul(s.ONE,rb));function u(_,T,N,v){let R=s.sqr(N),A=s.sqr(v),E=s.mulByB(s.mul(A,Ei)),S=s.mul(E,Ei),U=s.sub(s.sub(s.sqr(s.add(N,v)),A),R),C=s.sub(E,R),g=s.mul(s.sqr(T),Ei),w=s.neg(U);return _.push([C,g,w]),T=s.mul(s.mul(s.mul(s.sub(R,S),T),N),l),N=s.sub(s.sqr(s.mul(s.add(R,S),l)),s.mul(s.sqr(E),Ei)),v=s.mul(R,U),{Rx:T,Ry:N,Rz:v}}function p(_,T,N,v,R,A){let E=s.sub(N,s.mul(A,v)),S=s.sub(T,s.mul(R,v)),U=s.sub(s.mul(E,R),s.mul(S,A)),C=s.neg(E),g=S;_.push([U,C,g]);let w=s.sqr(S),O=s.mul(w,S),P=s.mul(w,T),L=s.add(s.sub(O,s.mul(P,rb)),s.mul(s.sqr(E),v));return T=s.mul(S,L),N=s.sub(s.mul(s.sub(P,L),E),s.mul(O,N)),v=s.mul(v,O),{Rx:T,Ry:N,Rz:v}}let h=I6(a),m=(0,Ma.memoized)(_=>{let T=_,{x:N,y:v}=T.toAffine(),R=N,A=v,E=s.neg(v),S=R,U=A,C=s.ONE,g=[];for(let w of h){let O=[];({Rx:S,Ry:U,Rz:C}=u(O,S,U,C)),w&&({Rx:S,Ry:U,Rz:C}=p(O,S,U,C,R,w===-1?E:A)),g.push(O)}if(d){let w=g[g.length-1];d(S,U,C,R,A,p.bind(null,w))}return g});function b(_,T=!1){let N=o.ONE;if(_.length){let v=_[0][0].length;for(let R=0;R<v;R++){N=o.sqr(N);for(let[A,E,S]of _)for(let[U,C,g]of A[R])N=f(U,C,g,N,E,S)}}return c&&(N=o.conjugate(N)),T?o.finalExponentiate(N):N}function y(_,T=!0){let N=[];(0,Q_.normalizeZ)(e,_.map(({g1:v})=>v)),(0,Q_.normalizeZ)(r,_.map(({g2:v})=>v));for(let{g1:v,g2:R}of _){if(v.is0()||R.is0())throw new Error("pairing is not available for ZERO point");v.assertValidity(),R.assertValidity();let A=v.toAffine();N.push([m(R),A.x,A.y])}return b(N,T)}function x(_,T,N=!0){return y([{g1:_,g2:T}],N)}return{Fp12:o,millerLoopBatch:b,pairing:x,pairingBatch:y,calcPairingPrecomputes:m}}function nb(t,e,r,n,s){let{Fp12:o,pairingBatch:i}=t;function a(l){return l instanceof e.Point?l:e.Point.fromHex(l)}function c(l){return l instanceof r.Point?l:r.Point.fromHex(l)}function d(l){if(!(l instanceof r.Point))throw new Error(`expected valid message hashed to ${s?"G1":"G2"} curve`);return l}let f=s?(l,u)=>({g1:u,g2:l}):(l,u)=>({g1:l,g2:u});return{getPublicKey(l){let u=(0,Ku._normFnElement)(e.Point.Fn,l);return e.Point.BASE.multiply(u)},sign(l,u,p){if(p!=null)throw new Error("sign() expects 2 arguments");let h=(0,Ku._normFnElement)(e.Point.Fn,u);return d(l).assertValidity(),l.multiply(h)},verify(l,u,p,h){if(h!=null)throw new Error("verify() expects 3 arguments");l=c(l),p=a(p);let m=p.negate(),b=e.Point.BASE,y=d(u),x=l,_=i([f(m,y),f(b,x)]);return o.eql(_,o.ONE)},verifyBatch(l,u,p){if(dh(u),p.length!==u.length)throw new Error("amount of public keys and messages should be equal");let h=c(l),m=u,b=p.map(a),y=new Map;for(let T=0;T<b.length;T++){let N=b[T],v=m[T],R=y.get(v);R===void 0&&(R=[],y.set(v,R)),R.push(N)}let x=[],_=e.Point.BASE;try{for(let[T,N]of y){let v=N.reduce((R,A)=>R.add(A));x.push(f(v,T))}return x.push(f(_.negate(),h)),o.eql(i(x),o.ONE)}catch{return!1}},aggregatePublicKeys(l){dh(l),l=l.map(p=>a(p));let u=l.reduce((p,h)=>p.add(h),e.Point.ZERO);return u.assertValidity(),u},aggregateSignatures(l){dh(l),l=l.map(p=>c(p));let u=l.reduce((p,h)=>p.add(h),r.Point.ZERO);return u.assertValidity(),u},hash(l,u){(0,Ma.abytes)(l);let p=u?{DST:u}:void 0;return r.hashToCurve(l,p)},Signature:n}}function A6(t){let{Fp:e,Fr:r,Fp2:n,Fp6:s,Fp12:o}=t.fields,i=(0,Ku.weierstrassPoints)(t.G1),a=Object.assign(i,(0,eb.createHasher)(i.Point,t.G1.mapToCurve,{...t.htfDefaults,...t.G1.htfDefaults})),c=(0,Ku.weierstrassPoints)(t.G2),d=Object.assign(c,(0,eb.createHasher)(c.Point,t.G2.mapToCurve,{...t.htfDefaults,...t.G2.htfDefaults})),f=S6(t.fields,a.Point,d.Point,{...t.params,postPrecompute:t.postPrecompute}),{millerLoopBatch:l,pairing:u,pairingBatch:p,calcPairingPrecomputes:h}=f,m=nb(f,a,d,t.G2.Signature,!1),b=nb(f,d,a,t.G1.ShortSignature,!0),y=t.randomBytes||Ma.randomBytes,x=()=>{let I=(0,tb.getMinHashLength)(r.ORDER);return(0,tb.mapHashToField)(y(I),r.ORDER)},_={randomSecretKey:x,randomPrivateKey:x,calcPairingPrecomputes:h},{ShortSignature:T}=t.G1,{Signature:N}=t.G2;function v(I,B){return I instanceof a.Point?I:b.hash((0,Ma.ensureBytes)("point",I),B?.DST)}function R(I,B){return I instanceof d.Point?I:m.hash((0,Ma.ensureBytes)("point",I),B?.DST)}function A(I){return m.getPublicKey(I).toBytes(!0)}function E(I){return b.getPublicKey(I).toBytes(!0)}function S(I,B,F){let V=R(I,F),q=m.sign(V,B);return I instanceof d.Point?q:N.toBytes(q)}function U(I,B,F){let V=v(I,F),q=b.sign(V,B);return I instanceof a.Point?q:T.toBytes(q)}function C(I,B,F,V){let q=R(B,V);return m.verify(I,q,F)}function g(I,B,F,V){let q=v(B,V);return b.verify(I,q,F)}function w(I){let B=m.aggregatePublicKeys(I);return I[0]instanceof a.Point?B:B.toBytes(!0)}function O(I){let B=m.aggregateSignatures(I);return I[0]instanceof d.Point?B:N.toBytes(B)}function P(I){let B=b.aggregateSignatures(I);return I[0]instanceof a.Point?B:T.toBytes(B)}function L(I,B,F,V){let q=B.map(H=>R(H,V));return m.verifyBatch(I,q,F)}return a.Point.BASE.precompute(4),{longSignatures:m,shortSignatures:b,millerLoopBatch:l,pairing:u,pairingBatch:p,verifyBatch:L,fields:{Fr:r,Fp:e,Fp2:n,Fp6:s,Fp12:o},params:{ateLoopSize:t.params.ateLoopSize,twistType:t.params.twistType,r:t.params.r,G1b:t.G1.b,G2b:t.G2.b},utils:_,getPublicKey:A,getPublicKeyForShortSignatures:E,sign:S,signShortSignature:U,verify:C,verifyShortSignature:g,aggregatePublicKeys:w,aggregateSignatures:O,aggregateShortSignatures:P,G1:a,G2:d,Signature:N,ShortSignature:T}}});var cb=Y(Gu=>{"use strict";Object.defineProperty(Gu,"__esModule",{value:!0});Gu.psiFrobenius=B6;Gu.tower12=C6;var Bs=Vr(),qn=un(),ob=BigInt(0),Mn=BigInt(1),Kt=BigInt(2),ib=BigInt(3);function mh(t,e,r,n,s=1,o){let i=BigInt(o===void 0?n:o),a=r**BigInt(n),c=[];for(let d=0;d<s;d++){let f=BigInt(d+1),l=[];for(let u=0,p=Mn;u<n;u++){let h=(f*p-f)/i%a;l.push(t.pow(e,h)),p*=r}c.push(l)}return c}function B6(t,e,r){let n=e.pow(r,(t.ORDER-Mn)/ib),s=e.pow(r,(t.ORDER-Mn)/Kt);function o(u,p){let h=e.mul(e.frobeniusMap(u,1),n),m=e.mul(e.frobeniusMap(p,1),s);return[h,m]}let i=e.pow(r,(t.ORDER**Kt-Mn)/ib),a=e.pow(r,(t.ORDER**Kt-Mn)/Kt);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(u,p){return[e.mul(u,i),e.neg(p)]}let d=u=>(p,h)=>{let m=h.toAffine(),b=u(m.x,m.y);return p.fromAffine({x:b[0],y:b[1]})},f=d(o),l=d(c);return{psi:o,psi2:c,G2psi:f,G2psi2:l,PSI_X:n,PSI_Y:s,PSI2_X:i,PSI2_Y:a}}var ab=(t,e)=>{if(e.length!==2)throw new Error("invalid tuple");let r=e.map(n=>t.create(n));return{c0:r[0],c1:r[1]}},fh=class{constructor(e,r={}){this.MASK=Mn;let n=e.ORDER,s=n*n;this.Fp=e,this.ORDER=s,this.BITS=(0,Bs.bitLen)(s),this.BYTES=Math.ceil((0,Bs.bitLen)(s)/8),this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.Fp_NONRESIDUE=e.create(r.NONRESIDUE||BigInt(-1)),this.Fp_div2=e.div(e.ONE,Kt),this.NONRESIDUE=ab(e,r.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=mh(e,this.Fp_NONRESIDUE,e.ORDER,2)[0],this.mulByB=r.Fp2mulByB,Object.seal(this)}fromBigTuple(e){return ab(this.Fp,e)}create(e){return e}isValid({c0:e,c1:r}){function n(s,o){return typeof s=="bigint"&&ob<=s&&s<o}return n(e,this.ORDER)&&n(r,this.ORDER)}is0({c0:e,c1:r}){return this.Fp.is0(e)&&this.Fp.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}eql({c0:e,c1:r},{c0:n,c1:s}){return this.Fp.eql(e,n)&&this.Fp.eql(r,s)}neg({c0:e,c1:r}){return{c0:this.Fp.neg(e),c1:this.Fp.neg(r)}}pow(e,r){return qn.FpPow(this,e,r)}invertBatch(e){return qn.FpInvertBatch(this,e)}add(e,r){let{c0:n,c1:s}=e,{c0:o,c1:i}=r;return{c0:this.Fp.add(n,o),c1:this.Fp.add(s,i)}}sub({c0:e,c1:r},{c0:n,c1:s}){return{c0:this.Fp.sub(e,n),c1:this.Fp.sub(r,s)}}mul({c0:e,c1:r},n){let{Fp:s}=this;if(typeof n=="bigint")return{c0:s.mul(e,n),c1:s.mul(r,n)};let{c0:o,c1:i}=n,a=s.mul(e,o),c=s.mul(r,i),d=s.sub(a,c),f=s.sub(s.mul(s.add(e,r),s.add(o,i)),s.add(a,c));return{c0:d,c1:f}}sqr({c0:e,c1:r}){let{Fp:n}=this,s=n.add(e,r),o=n.sub(e,r),i=n.add(e,e);return{c0:n.mul(s,o),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,s=n.inv(n.create(e*e+r*r));return{c0:n.mul(s,n.create(e)),c1:n.mul(s,n.create(-r))}}sqrt(e){let{Fp:r}=this,n=this,{c0:s,c1:o}=e;if(r.is0(o))return qn.FpLegendre(r,s)===1?n.create({c0:r.sqrt(s),c1:r.ZERO}):n.create({c0:r.ZERO,c1:r.sqrt(r.div(s,this.Fp_NONRESIDUE))});let i=r.sqrt(r.sub(r.sqr(s),r.mul(r.sqr(o),this.Fp_NONRESIDUE))),a=r.mul(r.add(i,s),this.Fp_div2);qn.FpLegendre(r,a)===-1&&(a=r.sub(a,i));let d=r.sqrt(a),f=n.create({c0:d,c1:r.div(r.mul(o,this.Fp_div2),d)});if(!n.eql(n.sqr(f),e))throw new Error("Cannot find square root");let l=f,u=n.neg(l),{re:p,im:h}=n.reim(l),{re:m,im:b}=n.reim(u);return h>b||h===b&&p>m?l:u}isOdd(e){let{re:r,im:n}=this.reim(e),s=r%Kt,o=r===ob,i=n%Kt;return BigInt(s||o&&i)==Mn}fromBytes(e){let{Fp:r}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{c0:r.fromBytes(e.subarray(0,r.BYTES)),c1:r.fromBytes(e.subarray(r.BYTES))}}toBytes({c0:e,c1:r}){return(0,Bs.concatBytes)(this.Fp.toBytes(e),this.Fp.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:s},o){return{c0:this.Fp.cmov(e,n,o),c1:this.Fp.cmov(r,s,o)}}reim({c0:e,c1:r}){return{re:e,im:r}}Fp4Square(e,r){let n=this,s=n.sqr(e),o=n.sqr(r);return{first:n.add(n.mulByNonresidue(o),s),second:n.sub(n.sub(n.sqr(n.add(e,r)),s),o)}}mulByNonresidue({c0:e,c1:r}){return this.mul({c0:e,c1:r},this.NONRESIDUE)}frobeniusMap({c0:e,c1:r},n){return{c0:e,c1:this.Fp.mul(r,this.FROBENIUS_COEFFICIENTS[n%2])}}},ph=class{constructor(e){this.MASK=Mn,this.Fp2=e,this.ORDER=e.ORDER,this.BITS=3*e.BITS,this.BYTES=3*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO,c2:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO,c2:e.ZERO};let{Fp:r}=e,n=mh(e,e.NONRESIDUE,r.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=n[0],this.FROBENIUS_COEFFICIENTS_2=n[1],Object.seal(this)}add({c0:e,c1:r,c2:n},{c0:s,c1:o,c2:i}){let{Fp2:a}=this;return{c0:a.add(e,s),c1:a.add(r,o),c2:a.add(n,i)}}sub({c0:e,c1:r,c2:n},{c0:s,c1:o,c2:i}){let{Fp2:a}=this;return{c0:a.sub(e,s),c1:a.sub(r,o),c2:a.sub(n,i)}}mul({c0:e,c1:r,c2:n},s){let{Fp2:o}=this;if(typeof s=="bigint")return{c0:o.mul(e,s),c1:o.mul(r,s),c2:o.mul(n,s)};let{c0:i,c1:a,c2:c}=s,d=o.mul(e,i),f=o.mul(r,a),l=o.mul(n,c);return{c0:o.add(d,o.mulByNonresidue(o.sub(o.mul(o.add(r,n),o.add(a,c)),o.add(f,l)))),c1:o.add(o.sub(o.mul(o.add(e,r),o.add(i,a)),o.add(d,f)),o.mulByNonresidue(l)),c2:o.sub(o.add(f,o.mul(o.add(e,n),o.add(i,c))),o.add(d,l))}}sqr({c0:e,c1:r,c2:n}){let{Fp2:s}=this,o=s.sqr(e),i=s.mul(s.mul(e,r),Kt),a=s.mul(s.mul(r,n),Kt),c=s.sqr(n);return{c0:s.add(s.mulByNonresidue(a),o),c1:s.add(s.mulByNonresidue(c),i),c2:s.sub(s.sub(s.add(s.add(i,s.sqr(s.add(s.sub(e,r),n))),a),o),c)}}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){return e}isValid({c0:e,c1:r,c2:n}){let{Fp2:s}=this;return s.isValid(e)&&s.isValid(r)&&s.isValid(n)}is0({c0:e,c1:r,c2:n}){let{Fp2:s}=this;return s.is0(e)&&s.is0(r)&&s.is0(n)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r,c2:n}){let{Fp2:s}=this;return{c0:s.neg(e),c1:s.neg(r),c2:s.neg(n)}}eql({c0:e,c1:r,c2:n},{c0:s,c1:o,c2:i}){let{Fp2:a}=this;return a.eql(e,s)&&a.eql(r,o)&&a.eql(n,i)}sqrt(e){return(0,Bs.notImplemented)()}div(e,r){let{Fp2:n}=this,{Fp:s}=n;return this.mul(e,typeof r=="bigint"?s.inv(s.create(r)):this.inv(r))}pow(e,r){return qn.FpPow(this,e,r)}invertBatch(e){return qn.FpInvertBatch(this,e)}inv({c0:e,c1:r,c2:n}){let{Fp2:s}=this,o=s.sub(s.sqr(e),s.mulByNonresidue(s.mul(n,r))),i=s.sub(s.mulByNonresidue(s.sqr(n)),s.mul(e,r)),a=s.sub(s.sqr(r),s.mul(e,n)),c=s.inv(s.add(s.mulByNonresidue(s.add(s.mul(n,i),s.mul(r,a))),s.mul(e,o)));return{c0:s.mul(c,o),c1:s.mul(c,i),c2:s.mul(c,a)}}fromBytes(e){let{Fp2:r}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);let n=r.BYTES;return{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:s}=this;return(0,Bs.concatBytes)(s.toBytes(e),s.toBytes(r),s.toBytes(n))}cmov({c0:e,c1:r,c2:n},{c0:s,c1:o,c2:i},a){let{Fp2:c}=this;return{c0:c.cmov(e,s,a),c1:c.cmov(r,o,a),c2:c.cmov(n,i,a)}}fromBigSix(e){let{Fp2:r}=this;if(!Array.isArray(e)||e.length!==6)throw new Error("invalid Fp6 usage");return{c0:r.fromBigTuple(e.slice(0,2)),c1:r.fromBigTuple(e.slice(2,4)),c2:r.fromBigTuple(e.slice(4,6))}}frobeniusMap({c0:e,c1:r,c2:n},s){let{Fp2:o}=this;return{c0:o.frobeniusMap(e,s),c1:o.mul(o.frobeniusMap(r,s),this.FROBENIUS_COEFFICIENTS_1[s%6]),c2:o.mul(o.frobeniusMap(n,s),this.FROBENIUS_COEFFICIENTS_2[s%6])}}mulByFp2({c0:e,c1:r,c2:n},s){let{Fp2:o}=this;return{c0:o.mul(e,s),c1:o.mul(r,s),c2:o.mul(n,s)}}mulByNonresidue({c0:e,c1:r,c2:n}){let{Fp2:s}=this;return{c0:s.mulByNonresidue(n),c1:e,c2:r}}mul1({c0:e,c1:r,c2:n},s){let{Fp2:o}=this;return{c0:o.mulByNonresidue(o.mul(n,s)),c1:o.mul(e,s),c2:o.mul(r,s)}}mul01({c0:e,c1:r,c2:n},s,o){let{Fp2:i}=this,a=i.mul(e,s),c=i.mul(r,o);return{c0:i.add(i.mulByNonresidue(i.sub(i.mul(i.add(r,n),o),c)),a),c1:i.sub(i.sub(i.mul(i.add(s,o),i.add(e,r)),a),c),c2:i.add(i.sub(i.mul(i.add(e,n),s),a),c)}}},hh=class{constructor(e,r){this.MASK=Mn;let{Fp2:n}=e,{Fp:s}=n;this.Fp6=e,this.ORDER=n.ORDER,this.BITS=2*e.BITS,this.BYTES=2*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.FROBENIUS_COEFFICIENTS=mh(n,n.NONRESIDUE,s.ORDER,12,1,6)[0],this.X_LEN=r.X_LEN,this.finalExponentiate=r.Fp12finalExponentiate}create(e){return e}isValid({c0:e,c1:r}){let{Fp6:n}=this;return n.isValid(e)&&n.isValid(r)}is0({c0:e,c1:r}){let{Fp6:n}=this;return n.is0(e)&&n.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r}){let{Fp6:n}=this;return{c0:n.neg(e),c1:n.neg(r)}}eql({c0:e,c1:r},{c0:n,c1:s}){let{Fp6:o}=this;return o.eql(e,n)&&o.eql(r,s)}sqrt(e){(0,Bs.notImplemented)()}inv({c0:e,c1:r}){let{Fp6:n}=this,s=n.inv(n.sub(n.sqr(e),n.mulByNonresidue(n.sqr(r))));return{c0:n.mul(e,s),c1:n.neg(n.mul(r,s))}}div(e,r){let{Fp6:n}=this,{Fp2:s}=n,{Fp:o}=s;return this.mul(e,typeof r=="bigint"?o.inv(o.create(r)):this.inv(r))}pow(e,r){return qn.FpPow(this,e,r)}invertBatch(e){return qn.FpInvertBatch(this,e)}add({c0:e,c1:r},{c0:n,c1:s}){let{Fp6:o}=this;return{c0:o.add(e,n),c1:o.add(r,s)}}sub({c0:e,c1:r},{c0:n,c1:s}){let{Fp6:o}=this;return{c0:o.sub(e,n),c1:o.sub(r,s)}}mul({c0:e,c1:r},n){let{Fp6:s}=this;if(typeof n=="bigint")return{c0:s.mul(e,n),c1:s.mul(r,n)};let{c0:o,c1:i}=n,a=s.mul(e,o),c=s.mul(r,i);return{c0:s.add(a,s.mulByNonresidue(c)),c1:s.sub(s.mul(s.add(e,r),s.add(o,i)),s.add(a,c))}}sqr({c0:e,c1:r}){let{Fp6:n}=this,s=n.mul(e,r);return{c0:n.sub(n.sub(n.mul(n.add(n.mulByNonresidue(r),e),n.add(e,r)),s),n.mulByNonresidue(s)),c1:n.add(s,s)}}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(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{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(0,Bs.concatBytes)(n.toBytes(e),n.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:s},o){let{Fp6:i}=this;return{c0:i.cmov(e,n,o),c1:i.cmov(r,s,o)}}fromBigTwelve(e){let{Fp6:r}=this;return{c0:r.fromBigSix(e.slice(0,6)),c1:r.fromBigSix(e.slice(6,12))}}frobeniusMap(e,r){let{Fp6:n}=this,{Fp2:s}=n,{c0:o,c1:i,c2:a}=n.frobeniusMap(e.c1,r),c=this.FROBENIUS_COEFFICIENTS[r%12];return{c0:n.frobeniusMap(e.c0,r),c1:n.create({c0:s.mul(o,c),c1:s.mul(i,c),c2:s.mul(a,c)})}}mulByFp2({c0:e,c1:r},n){let{Fp6:s}=this;return{c0:s.mulByFp2(e,n),c1:s.mulByFp2(r,n)}}conjugate({c0:e,c1:r}){return{c0:e,c1:this.Fp6.neg(r)}}mul014({c0:e,c1:r},n,s,o){let{Fp6:i}=this,{Fp2:a}=i,c=i.mul01(e,n,s),d=i.mul1(r,o);return{c0:i.add(i.mulByNonresidue(d),c),c1:i.sub(i.sub(i.mul01(i.add(r,e),n,a.add(s,o)),c),d)}}mul034({c0:e,c1:r},n,s,o){let{Fp6:i}=this,{Fp2:a}=i,c=i.create({c0:a.mul(e.c0,n),c1:a.mul(e.c1,n),c2:a.mul(e.c2,n)}),d=i.mul01(r,s,o),f=i.mul01(i.add(e,r),a.add(n,s),o);return{c0:i.add(i.mulByNonresidue(d),c),c1:i.sub(f,i.add(c,d))}}_cyclotomicSquare({c0:e,c1:r}){let{Fp6:n}=this,{Fp2:s}=n,{c0:o,c1:i,c2:a}=e,{c0:c,c1:d,c2:f}=r,{first:l,second:u}=s.Fp4Square(o,d),{first:p,second:h}=s.Fp4Square(c,a),{first:m,second:b}=s.Fp4Square(i,f),y=s.mulByNonresidue(b);return{c0:n.create({c0:s.add(s.mul(s.sub(l,o),Kt),l),c1:s.add(s.mul(s.sub(p,i),Kt),p),c2:s.add(s.mul(s.sub(m,a),Kt),m)}),c1:n.create({c0:s.add(s.mul(s.add(y,c),Kt),y),c1:s.add(s.mul(s.add(u,d),Kt),u),c2:s.add(s.mul(s.add(h,f),Kt),h)})}}_cyclotomicExp(e,r){let n=this.ONE;for(let s=this.X_LEN-1;s>=0;s--)n=this._cyclotomicSquare(n),(0,Bs.bitGet)(r,s)&&(n=this.mul(n,e));return n}};function C6(t){let e=qn.Field(t.ORDER),r=new fh(e,t),n=new ph(r),s=new hh(n,t);return{Fp:e,Fp2:r,Fp6:n,Fp12:s}}});var yb=Y(fn=>{"use strict";Object.defineProperty(fn,"__esModule",{value:!0});fn.bls12_381=fn.bls12_381_Fr=void 0;var fb=di(),P6=sb(),D6=un(),ge=Vr(),pb=ju(),hb=cb(),mb=uh(),Dt=BigInt(0),Zu=BigInt(1),Nr=BigInt(2),zu=BigInt(3),ka=BigInt(4),Cs=BigInt("0xd201000000010000"),F6=(0,ge.bitLen)(Cs),Eo={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:Dt,b:ka,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")};fn.bls12_381_Fr=(0,D6.Field)(Eo.n,{modFromBytes:!0,isLE:!0});var{Fp:X,Fp2:xe,Fp6:U6,Fp12:ve}=(0,hb.tower12)({ORDER:Eo.p,X_LEN:F6,FP2_NONRESIDUE:[Zu,Zu],Fp2mulByB:({c0:t,c1:e})=>{let r=X.mul(t,ka),n=X.mul(e,ka);return{c0:X.sub(r,n),c1:X.add(r,n)}},Fp12finalExponentiate:t=>{let e=Cs,r=ve.div(ve.frobeniusMap(t,6),t),n=ve.mul(ve.frobeniusMap(r,2),r),s=ve.conjugate(ve._cyclotomicExp(n,e)),o=ve.mul(ve.conjugate(ve._cyclotomicSquare(n)),s),i=ve.conjugate(ve._cyclotomicExp(o,e)),a=ve.conjugate(ve._cyclotomicExp(i,e)),c=ve.mul(ve.conjugate(ve._cyclotomicExp(a,e)),ve._cyclotomicSquare(s)),d=ve.conjugate(ve._cyclotomicExp(c,e)),f=ve.frobeniusMap(ve.mul(s,a),2),l=ve.frobeniusMap(ve.mul(i,n),3),u=ve.frobeniusMap(ve.mul(c,ve.conjugate(n)),1),p=ve.mul(ve.mul(d,ve.conjugate(o)),n);return ve.mul(ve.mul(ve.mul(f,l),u),p)}}),{G2psi:ub,G2psi2:V6}=(0,hb.psiFrobenius)(X,xe,xe.div(xe.ONE,xe.NONRESIDUE)),yh=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:X.ORDER,m:2,k:128,expand:"xmd",hash:fb.sha256}),gh={p:xe.ORDER,n:Eo.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:xe.ZERO,b:xe.fromBigTuple([ka,ka]),Gx:xe.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:xe.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},Yu=ja(X.toBytes(Dt),{infinity:!0,compressed:!0});function Wu(t){t=t.slice();let e=t[0]&224,r=!!(e>>7&1),n=!!(e>>6&1),s=!!(e>>5&1);return t[0]&=31,{compressed:r,infinity:n,sort:s,value:t}}function ja(t,e){if(t[0]&224)throw new Error("setMask: non-empty mask");return e.compressed&&(t[0]|=128),e.infinity&&(t[0]|=64),e.sort&&(t[0]|=32),t}function L6(t,e,r){let{BYTES:n,ORDER:s}=X,o=e.is0(),{x:i,y:a}=e.toAffine();if(r){if(o)return Yu.slice();let c=!!(a*Nr/s);return ja((0,ge.numberToBytesBE)(i,n),{compressed:!0,sort:c})}else return o?(0,ge.concatBytes)(Uint8Array.of(64),new Uint8Array(2*n-1)):(0,ge.concatBytes)((0,ge.numberToBytesBE)(i,n),(0,ge.numberToBytesBE)(a,n))}function _h(t){t.assertValidity();let{BYTES:e,ORDER:r}=X,{x:n,y:s}=t.toAffine();if(t.is0())return Yu.slice();let o=!!(s*Nr/r);return ja((0,ge.numberToBytesBE)(n,e),{compressed:!0,sort:o})}function q6(t){let{compressed:e,infinity:r,sort:n,value:s}=Wu(t),{BYTES:o,ORDER:i}=X;if(s.length===48&&e){let a=(0,ge.bytesToNumberBE)(s),c=X.create(a&(0,ge.bitMask)(X.BITS));if(r){if(c!==Dt)throw new Error("invalid G1 point: non-empty, at infinity, with compression");return{x:Dt,y:Dt}}let d=X.add(X.pow(c,zu),X.create(Eo.b)),f=X.sqrt(d);if(!f)throw new Error("invalid G1 point: compressed point");return f*Nr/i!==BigInt(n)&&(f=X.neg(f)),{x:X.create(c),y:X.create(f)}}else if(s.length===96&&!e){let a=(0,ge.bytesToNumberBE)(s.subarray(0,o)),c=(0,ge.bytesToNumberBE)(s.subarray(o));if(r){if(a!==Dt||c!==Dt)throw new Error("G1: non-empty point at infinity");return fn.bls12_381.G1.Point.ZERO.toAffine()}return{x:X.create(a),y:X.create(c)}}else throw new Error("invalid G1 point: expected 48/96 bytes")}function db(t){let{infinity:e,sort:r,value:n}=Wu((0,ge.ensureBytes)("signatureHex",t,48)),s=X.ORDER,o=fn.bls12_381.G1.Point,i=(0,ge.bytesToNumberBE)(n);if(e)return o.ZERO;let a=X.create(i&(0,ge.bitMask)(X.BITS)),c=X.add(X.pow(a,zu),X.create(Eo.b)),d=X.sqrt(c);if(!d)throw new Error("invalid G1 point: compressed");let f=BigInt(r);d*Nr/s!==f&&(d=X.neg(d));let l=o.fromAffine({x:a,y:d});return l.assertValidity(),l}function M6(t,e,r){let{BYTES:n,ORDER:s}=X,o=e.is0(),{x:i,y:a}=e.toAffine();if(r){if(o)return(0,ge.concatBytes)(Yu,(0,ge.numberToBytesBE)(Dt,n));let c=!!(a.c1===Dt?a.c0*Nr/s:a.c1*Nr/s);return(0,ge.concatBytes)(ja((0,ge.numberToBytesBE)(i.c1,n),{compressed:!0,sort:c}),(0,ge.numberToBytesBE)(i.c0,n))}else{if(o)return(0,ge.concatBytes)(Uint8Array.of(64),new Uint8Array(4*n-1));let{re:c,im:d}=xe.reim(i),{re:f,im:l}=xe.reim(a);return(0,ge.concatBytes)((0,ge.numberToBytesBE)(d,n),(0,ge.numberToBytesBE)(c,n),(0,ge.numberToBytesBE)(l,n),(0,ge.numberToBytesBE)(f,n))}}function bh(t){t.assertValidity();let{BYTES:e}=X;if(t.is0())return(0,ge.concatBytes)(Yu,(0,ge.numberToBytesBE)(Dt,e));let{x:r,y:n}=t.toAffine(),{re:s,im:o}=xe.reim(r),{re:i,im:a}=xe.reim(n),d=!!((a>Dt?a*Nr:i*Nr)/X.ORDER&Zu),f=s;return(0,ge.concatBytes)(ja((0,ge.numberToBytesBE)(o,e),{sort:d,compressed:!0}),(0,ge.numberToBytesBE)(f,e))}function k6(t){let{BYTES:e,ORDER:r}=X,{compressed:n,infinity:s,sort:o,value:i}=Wu(t);if(!n&&!s&&o||!n&&s&&o||o&&s&&n)throw new Error("invalid encoding flag: "+(t[0]&224));let a=(c,d,f)=>(0,ge.bytesToNumberBE)(c.slice(d,f));if(i.length===96&&n){if(s){if(i.reduce((h,m)=>h!==0?m+1:m,0)>0)throw new Error("invalid G2 point: compressed");return{x:xe.ZERO,y:xe.ZERO}}let c=a(i,0,e),d=a(i,e,2*e),f=xe.create({c0:X.create(d),c1:X.create(c)}),l=xe.add(xe.pow(f,zu),gh.b),u=xe.sqrt(l),p=u.c1===Dt?u.c0*Nr/r:u.c1*Nr/r?Zu:Dt;return u=o&&p>0?u:xe.neg(u),{x:f,y:u}}else if(i.length===192&&!n){if(s){if(i.reduce((u,p)=>u!==0?p+1:p,0)>0)throw new Error("invalid G2 point: uncompressed");return{x:xe.ZERO,y:xe.ZERO}}let c=a(i,0*e,1*e),d=a(i,1*e,2*e),f=a(i,2*e,3*e),l=a(i,3*e,4*e);return{x:xe.fromBigTuple([d,c]),y:xe.fromBigTuple([l,f])}}else throw new Error("invalid G2 point: expected 96/192 bytes")}function lb(t){let{ORDER:e}=X,{infinity:r,sort:n,value:s}=Wu((0,ge.ensureBytes)("signatureHex",t)),o=fn.bls12_381.G2.Point,i=s.length/2;if(i!==48&&i!==96)throw new Error("invalid compressed signature length, expected 96/192 bytes");let a=(0,ge.bytesToNumberBE)(s.slice(0,i)),c=(0,ge.bytesToNumberBE)(s.slice(i));if(r)return o.ZERO;let d=X.create(a&(0,ge.bitMask)(X.BITS)),f=X.create(c),l=xe.create({c0:f,c1:d}),u=xe.add(xe.pow(l,zu),gh.b),p=xe.sqrt(u);if(!p)throw new Error("Failed to find a square root");let{re:h,im:m}=xe.reim(p),b=BigInt(n),y=m>Dt&&m*Nr/e!==b,x=m===Dt&&h*Nr/e!==b;(y||x)&&(p=xe.neg(p));let _=o.fromAffine({x:l,y:p});return _.assertValidity(),_}fn.bls12_381=(0,P6.bls)({fields:{Fp:X,Fp2:xe,Fp6:U6,Fp12:ve,Fr:fn.bls12_381_Fr},G1:{...Eo,Fp:X,htfDefaults:{...yh,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(t,e)=>{let r=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),n=new t(X.mul(e.X,r),e.Y,e.Z);return e.multiplyUnsafe(Cs).negate().multiplyUnsafe(Cs).equals(n)},clearCofactor:(t,e)=>e.multiplyUnsafe(Cs).add(e),mapToCurve:G6,fromBytes:q6,toBytes:L6,ShortSignature:{fromBytes(t){return(0,ge.abytes)(t),db(t)},fromHex(t){return db(t)},toBytes(t){return _h(t)},toRawBytes(t){return _h(t)},toHex(t){return(0,ge.bytesToHex)(_h(t))}}},G2:{...gh,Fp:xe,hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...yh},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:Z6,isTorsionFree:(t,e)=>e.multiplyUnsafe(Cs).negate().equals(ub(t,e)),clearCofactor:(t,e)=>{let r=Cs,n=e.multiplyUnsafe(r).negate(),s=ub(t,e),o=e.double();return o=V6(t,o),o=o.subtract(s),s=n.add(s),s=s.multiplyUnsafe(r).negate(),o=o.add(s),o=o.subtract(n),o.subtract(e)},fromBytes:k6,toBytes:M6,Signature:{fromBytes(t){return(0,ge.abytes)(t),lb(t)},fromHex(t){return lb(t)},toBytes(t){return bh(t)},toRawBytes(t){return bh(t)},toHex(t){return(0,ge.bytesToHex)(bh(t))}}},params:{ateLoopSize:Cs,r:Eo.n,xNegative:!0,twistType:"multiplicative"},htfDefaults:yh,hash:fb.sha256});var j6=(0,pb.isogenyMap)(xe,[[["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=>xe.fromBigTuple(e.map(BigInt))))),H6=(0,pb.isogenyMap)(X,[["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)))),$6=(0,mb.mapToCurveSimpleSWU)(X,{A:X.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:X.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:X.create(BigInt(11))}),K6=(0,mb.mapToCurveSimpleSWU)(xe,{A:xe.create({c0:X.create(Dt),c1:X.create(BigInt(240))}),B:xe.create({c0:X.create(BigInt(1012)),c1:X.create(BigInt(1012))}),Z:xe.create({c0:X.create(BigInt(-2)),c1:X.create(BigInt(-1))})});function G6(t){let{x:e,y:r}=$6(X.create(t[0]));return H6(e,r)}function Z6(t){let{x:e,y:r}=K6(xe.fromBigTuple(t));return j6(e,r)}});var wh=Y(Xu=>{"use strict";Object.defineProperty(Xu,"__esModule",{value:!0});Xu.verify=void 0;Xu.blsVerify=Y6;var z6=yb(),xh=ht();function Y6(t,e,r){let n=typeof t=="string"?t:(0,xh.bytesToHex)(t),s=typeof e=="string"?e:(0,xh.bytesToHex)(e),o=typeof r=="string"?r:(0,xh.bytesToHex)(r);return z6.bls12_381.verifyShortSignature(s,o,n)}});var Ju=Y(To=>{"use strict";Object.defineProperty(To,"__esModule",{value:!0});To.decodeTime=To.decodeLeb128=void 0;var _b=Sa(),W6=BigInt(1e6),X6=t=>(0,_b.lebDecode)(new _b.PipeArrayBuffer(t));To.decodeLeb128=X6;var J6=t=>{let r=(0,To.decodeLeb128)(t)/W6;return new Date(Number(r))};To.decodeTime=J6});var Ni=Y(Ve=>{"use strict";var Q6=Ve&&Ve.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),eO=Ve&&Ve.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),gb=Ve&&Ve.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[n.length]=s);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),s=0;s<n.length;s++)n[s]!=="default"&&Q6(r,e,n[s]);return eO(r,e),r}})();Object.defineProperty(Ve,"__esModule",{value:!0});Ve.LookupLabelStatus=Ve.LookupSubtreeStatus=Ve.LookupPathStatus=Ve.Certificate=Ve.NodeType=void 0;Ve.hashTreeToString=ed;Ve.lookupResultToBuffer=Oh;Ve.reconstruct=$a;Ve.domain_sep=Ti;Ve.lookup_path=td;Ve.lookup_subtree=vh;Ve.flatten_forks=Nh;Ve.find_label=Oi;Ve.check_canister_ranges=Tb;var xb=gb(Ca()),he=yr(),Eh=Ur(),tO=gb(wh()),rO=Ju(),Ps=ht(),wb=_i(),Qu=di(),bb=60*1e3,nO=60,sO=24,oO=sO*nO,iO=5,aO=5,cO=30*oO,Ye;(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"})(Ye||(Ve.NodeType=Ye={}));function ed(t){let e=n=>n.split(`
|
|
53
|
+
`).map(s=>" "+s).join(`
|
|
54
|
+
`);function r(n){let s=new TextDecoder(void 0,{fatal:!0});try{return JSON.stringify(s.decode(n))}catch{return`data(...${n.byteLength} bytes)`}}switch(t[0]){case Ye.Empty:return"()";case Ye.Fork:if(t[1]instanceof Array&&t[2]instanceof Uint8Array){let n=ed(t[1]),s=ed(t[2]);return`sub(
|
|
55
55
|
left:
|
|
56
56
|
${e(n)}
|
|
57
57
|
---
|
|
58
58
|
right:
|
|
59
|
-
${e(
|
|
60
|
-
)`}else throw
|
|
59
|
+
${e(s)}
|
|
60
|
+
)`}else throw he.UnknownError.fromCode(new he.HashTreeDecodeErrorCode("Invalid tree structure for fork"));case Ye.Labeled:if(t[1]instanceof Uint8Array&&t[2]instanceof Uint8Array){let n=r(t[1]),s=ed(t[2]);return`label(
|
|
61
61
|
label:
|
|
62
62
|
${e(n)}
|
|
63
63
|
sub:
|
|
64
|
-
${e(
|
|
65
|
-
)`}else throw me.UnknownError.fromCode(new me.HashTreeDecodeErrorCode("Invalid tree structure for labeled"));case ze.Leaf:{if(t[1]){if(Array.isArray(t[1]))return JSON.stringify(t[1])}else throw me.UnknownError.fromCode(new me.HashTreeDecodeErrorCode("Invalid tree structure for leaf"));return`leaf(...${t[1].byteLength} bytes)`}case ze.Pruned:{if(t[1]){if(Array.isArray(t[1]))return JSON.stringify(t[1])}else throw me.UnknownError.fromCode(new me.HashTreeDecodeErrorCode("Invalid tree structure for pruned"));return`pruned(${(0,go.bytesToHex)(new Uint8Array(t[1]))}`}default:return`unknown(${JSON.stringify(t[0])})`}}function p6(t,e){for(let r=0;r<t.length;r++)if(t[r]>e[r])return!0;return!1}var jp=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.canisterId,e.blsVerify??s6.blsVerify,e.maxAgeInMinutes,e.disableTimeVerification,e.agent)}constructor(e,r,n,o,s=d6,i=!1,a){this._rootKey=r,this._canisterId=n,this._blsVerify=o,this._maxAgeInMinutes=s,this.#e=i,this.cert=D_.decode(e),a&&"getTimeDiffMsecs"in a&&"hasSyncedTime"in a&&"syncTime"in a&&(this.#t=a)}lookup_path(e){return Bu(e,this.cert.tree)}lookup_subtree(e){return Kp(e,this.cert.tree)}async verify(){let e=await Ta(this.cert.tree),r=await this._checkDelegationAndGetKey(this.cert.delegation),n=this.cert.signature,o=m6(r),s=(0,go.concatBytes)(si("ic-state-root"),e),i=Hp(this.lookup_path(["time"]));if(!i)throw me.ProtocolError.fromCode(new me.CertificateVerificationErrorCode("Certificate does not contain a time"));if(!this.#e){let a=this.#t?.getTimeDiffMsecs()??0,c=this._maxAgeInMinutes*C_,d=new Date,p=d.getTime()+a,l=p-c,u=p+l6*C_,f=(0,i6.decodeTime)(i),h=f.getTime()<l,m=f.getTime()>u;if((h||m)&&this.#t&&!this.#t.hasSyncedTime())return await this.#t.syncTime(this._canisterId),await this.verify();if(h)throw me.TrustError.fromCode(new me.CertificateTimeErrorCode(this._maxAgeInMinutes,f,d,a,"past"));if(m)throw this.#t?.hasSyncedTime()?me.UnknownError.fromCode(new me.UnexpectedErrorCode("System time has been synced with the IC network, but certificate is still too far in the future.")):me.TrustError.fromCode(new me.CertificateTimeErrorCode(5,f,d,a,"future"))}try{if(!await this._blsVerify(o,n,s))throw me.TrustError.fromCode(new me.CertificateVerificationErrorCode("Invalid signature"))}catch(a){throw me.TrustError.fromCode(new me.CertificateVerificationErrorCode("Signature verification failed",a))}}async _checkDelegationAndGetKey(e){if(!e)return this._rootKey;let r=t.createUnverified({certificate:e.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,disableTimeVerification:this.#e,maxAgeInMinutes:f6,agent:this.#t});if(r.cert.delegation)throw me.ProtocolError.fromCode(new me.CertificateHasTooManyDelegationsErrorCode);await r.verify();let n=e.subnet_id,o=kp.Principal.fromUint8Array(n);if(!U_({canisterId:this._canisterId,subnetId:o,tree:r.cert.tree}))throw me.TrustError.fromCode(new me.CertificateNotAuthorizedErrorCode(this._canisterId,o));let i=Hp(r.lookup_path(["subnet",n,"public_key"]));if(!i)throw me.TrustError.fromCode(new me.MissingLookupValueErrorCode(`Could not find subnet key for subnet ID ${o.toText()}`));return i}};Ue.Certificate=jp;var Ea=(0,go.hexToBytes)("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),h6=96;function m6(t){let e=Ea.byteLength+h6;if(t.byteLength!==e)throw me.ProtocolError.fromCode(new me.DerKeyLengthMismatchErrorCode(e,t.byteLength));let r=t.slice(0,Ea.byteLength);if(!(0,F_.uint8Equals)(r,Ea))throw me.ProtocolError.fromCode(new me.DerPrefixMismatchErrorCode(Ea,r));return t.slice(Ea.byteLength)}function Hp(t){if(t.status===nn.Found&&t.value instanceof Uint8Array)return t.value}async function Ta(t){switch(t[0]){case ze.Empty:return(0,Su.sha256)(si("ic-hashtree-empty"));case ze.Pruned:return t[1];case ze.Leaf:return(0,Su.sha256)((0,go.concatBytes)(si("ic-hashtree-leaf"),t[1]));case ze.Labeled:return(0,Su.sha256)((0,go.concatBytes)(si("ic-hashtree-labeled"),t[1],await Ta(t[2])));case ze.Fork:return(0,Su.sha256)((0,go.concatBytes)(si("ic-hashtree-fork"),await Ta(t[1]),await Ta(t[2])));default:throw me.UNREACHABLE_ERROR}}function si(t){let e=new Uint8Array([t.length]),r=new TextEncoder().encode(t);return(0,go.concatBytes)(e,r)}function V_(t){return typeof t[0]=="string"?(0,go.utf8ToBytes)(t[0]):t[0]}var nn;(function(t){t.Unknown="Unknown",t.Absent="Absent",t.Found="Found",t.Error="Error"})(nn||(Ue.LookupPathStatus=nn={}));var Oa;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found"})(Oa||(Ue.LookupSubtreeStatus=Oa={}));var He;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found",t.Less="Less",t.Greater="Greater"})(He||(Ue.LookupLabelStatus=He={}));function Bu(t,e){if(t.length===0)switch(e[0]){case ze.Empty:return{status:nn.Absent};case ze.Leaf:{if(!e[1])throw me.UnknownError.fromCode(new me.HashTreeDecodeErrorCode("Invalid tree structure for leaf"));if(e[1]instanceof Uint8Array)return{status:nn.Found,value:e[1].slice(e[1].byteOffset,e[1].byteLength+e[1].byteOffset)};throw me.UNREACHABLE_ERROR}case ze.Pruned:return{status:nn.Unknown};case ze.Labeled:case ze.Fork:return{status:nn.Error};default:throw me.UNREACHABLE_ERROR}let r=V_(t),n=ii(r,e);switch(n.status){case He.Found:return Bu(t.slice(1),n.value);case He.Absent:case He.Greater:case He.Less:return{status:nn.Absent};case He.Unknown:return{status:nn.Unknown};default:throw me.UNREACHABLE_ERROR}}function Kp(t,e){if(t.length===0)return{status:Oa.Found,value:e};let r=V_(t),n=ii(r,e);switch(n.status){case He.Found:return Kp(t.slice(1),n.value);case He.Unknown:return{status:Oa.Unknown};case He.Absent:case He.Greater:case He.Less:return{status:Oa.Absent};default:throw me.UNREACHABLE_ERROR}}function $p(t){switch(t[0]){case ze.Empty:return[];case ze.Fork:return $p(t[1]).concat($p(t[2]));default:return[t]}}function ii(t,e){switch(e[0]){case ze.Labeled:return p6(t,e[1])?{status:He.Greater}:(0,F_.uint8Equals)(t,e[1])?{status:He.Found,value:e[2]}:{status:He.Less};case ze.Fork:{let r=ii(t,e[1]);switch(r.status){case He.Greater:{let n=ii(t,e[2]);return n.status===He.Less?{status:He.Absent}:n}case He.Unknown:{let n=ii(t,e[2]);return n.status===He.Less?{status:He.Unknown}:n}default:return r}}case ze.Pruned:return{status:He.Unknown};default:return{status:He.Absent}}}function U_(t){let{canisterId:e,subnetId:r,tree:n}=t,o=Bu(["subnet",r.toUint8Array(),"canister_ranges"],n);if(o.status!==nn.Found)throw me.ProtocolError.fromCode(new me.LookupErrorCode(`Could not find canister ranges for subnet ${r.toText()}`,o.status));if(!(o.value instanceof Uint8Array))throw me.ProtocolError.fromCode(new me.MalformedLookupFoundValueErrorCode(`Could not find canister ranges for subnet ${r.toText()}`));return D_.decode(o.value).map(c=>[kp.Principal.fromUint8Array(c[0]),kp.Principal.fromUint8Array(c[1])]).some(c=>c[0].ltEq(e)&&c[1].gtEq(e))}});var Cu=Z(ft=>{"use strict";var y6=ft&&ft.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),_6=ft&&ft.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),b6=ft&&ft.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),o=0;o<n.length;o++)n[o]!=="default"&&y6(r,e,n[o]);return _6(r,e),r}})();Object.defineProperty(ft,"__esModule",{value:!0});ft.encodePath=ft.fetchNodeKeys=ft.request=ft.CustomPath=void 0;var xo=Ir(),ot=sr(),wo=ai(),zp=b6(la()),L_=Ru(),Qt=dt(),Gp=class{constructor(e,r,n){this.key=e,this.path=r,this.decodeStrategy=n}};ft.CustomPath=Gp;var g6=async t=>{let{agent:e,paths:r,disableCertificateTimeVerification:n=!1}=t,o=xo.Principal.from(t.canisterId),s=[...new Set(r)],i=new Map,a=s.map((c,d)=>{let p=(0,ft.encodePath)(c,o);return(async()=>{try{if(e.rootKey===null)throw ot.ExternalError.fromCode(new ot.MissingRootKeyErrorCode);let l=e.rootKey,u=await e.readState(o,{paths:[p]}),f=await wo.Certificate.create({certificate:u.certificate,rootKey:l,canisterId:o,disableTimeVerification:n,agent:e}),h=(y,x)=>{if(x==="subnet"){let _=(0,ft.fetchNodeKeys)(u.certificate,o,l);return{path:x,data:_}}else return{path:x,data:(0,wo.lookupResultToBuffer)(y.lookup_path(p))}},{path:m,data:b}=h(f,s[d]);if(!b)console.warn(`Expected to find result for path ${m}, but instead found nothing.`),typeof m=="string"?i.set(m,null):i.set(m.key,null);else switch(m){case"time":{i.set(m,(0,L_.decodeTime)(b));break}case"controllers":{i.set(m,E6(b));break}case"module_hash":{i.set(m,(0,Qt.bytesToHex)(b));break}case"subnet":{i.set(m,b);break}case"candid":{i.set(m,new TextDecoder().decode(b));break}default:if(typeof m!="string"&&"key"in m&&"path"in m)switch(m.decodeStrategy){case"raw":i.set(m.key,b);break;case"leb128":{i.set(m.key,(0,L_.decodeLeb128)(b));break}case"cbor":{i.set(m.key,zp.decode(b));break}case"hex":{i.set(m.key,(0,Qt.bytesToHex)(b));break}case"utf-8":i.set(m.key,new TextDecoder().decode(b))}}}catch(l){if(l instanceof ot.AgentError&&(l.hasCode(ot.CertificateVerificationErrorCode)||l.hasCode(ot.CertificateTimeErrorCode)))throw l;typeof c!="string"&&"key"in c&&"path"in c?i.set(c.key,null):i.set(c,null),console.group(),console.warn(`Expected to find result for path ${c}, but instead found nothing.`),console.warn(l),console.groupEnd()}})()});return await Promise.all(a),i};ft.request=g6;var x6=(t,e,r)=>{if(!e._isPrincipal)throw ot.InputError.fromCode(new ot.UnexpectedErrorCode("Invalid canisterId"));let n=zp.decode(t),o=n.tree,s=n.delegation,i;if(s&&s.subnet_id?i=xo.Principal.fromUint8Array(new Uint8Array(s.subnet_id)):!s&&typeof r<"u"?(i=xo.Principal.selfAuthenticating(new Uint8Array(r)),s={subnet_id:i.toUint8Array(),certificate:new Uint8Array(0)}):(i=xo.Principal.selfAuthenticating(xo.Principal.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),s={subnet_id:i.toUint8Array(),certificate:new Uint8Array(0)}),!(0,wo.check_canister_ranges)({canisterId:e,subnetId:i,tree:o}))throw ot.TrustError.fromCode(new ot.CertificateNotAuthorizedErrorCode(e,i));let c=(0,wo.lookup_subtree)(["subnet",s.subnet_id,"node"],o);if(c.status!==wo.LookupSubtreeStatus.Found)throw ot.ProtocolError.fromCode(new ot.LookupErrorCode("Node not found",c.status));if(c.value instanceof Uint8Array)throw ot.UnknownError.fromCode(new ot.HashTreeDecodeErrorCode("Invalid node tree"));let d=(0,wo.flatten_forks)(c.value),p=new Map;return d.forEach(l=>{let u=xo.Principal.from(l[1]).toText(),f=(0,wo.lookup_path)(["public_key"],l[2]);if(f.status!==wo.LookupPathStatus.Found)throw ot.ProtocolError.fromCode(new ot.LookupErrorCode("Public key not found",f.status));let h=f.value;if(h.byteLength!==44)throw ot.ProtocolError.fromCode(new ot.DerKeyLengthMismatchErrorCode(44,h.byteLength));p.set(u,h)}),{subnetId:xo.Principal.fromUint8Array(new Uint8Array(s.subnet_id)).toText(),nodeKeys:p}};ft.fetchNodeKeys=x6;var w6=(t,e)=>{let r=e.toUint8Array();switch(t){case"time":return[(0,Qt.utf8ToBytes)("time")];case"controllers":return[(0,Qt.utf8ToBytes)("canister"),r,(0,Qt.utf8ToBytes)("controllers")];case"module_hash":return[(0,Qt.utf8ToBytes)("canister"),r,(0,Qt.utf8ToBytes)("module_hash")];case"subnet":return[(0,Qt.utf8ToBytes)("subnet")];case"candid":return[(0,Qt.utf8ToBytes)("canister"),r,(0,Qt.utf8ToBytes)("metadata"),(0,Qt.utf8ToBytes)("candid:service")];default:if("key"in t&&"path"in t)if(typeof t.path=="string"||t.path instanceof Uint8Array){let n=t.path,o=typeof n=="string"?(0,Qt.utf8ToBytes)(n):n;return[(0,Qt.utf8ToBytes)("canister"),r,(0,Qt.utf8ToBytes)("metadata"),o]}else return t.path}throw ot.UnknownError.fromCode(new ot.UnexpectedErrorCode(`Error while encoding your path for canister status. Please ensure that your path ${t} was formatted correctly.`))};ft.encodePath=w6;var E6=t=>zp.decode(t).map(r=>xo.Principal.fromUint8Array(r))});var k_=Z(is=>{"use strict";Object.defineProperty(is,"__esModule",{value:!0});is.PrimeEdwardsPoint=void 0;is.edwards=q_;is.eddsa=M_;is.twistedEdwards=R6;var Oe=Rr(),ss=ya(),T6=Qr(),Eo=BigInt(0),pt=BigInt(1),Zp=BigInt(2),O6=BigInt(8);function N6(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function q_(t,e={}){let r=(0,ss._createCurveFields)("edwards",t,e,e.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;(0,Oe._validateObject)(e,{},{uvRatio:"function"});let a=Zp<<BigInt(o.BYTES*8)-pt,c=b=>n.create(b),d=e.uvRatio||((b,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(b,y))}}catch{return{isValid:!1,value:Eo}}});if(!N6(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function p(b,y,x=!1){let _=x?pt:Eo;return(0,Oe.aInRange)("coordinate "+b,y,_,a),y}function l(b){if(!(b instanceof h))throw new Error("ExtendedPoint expected")}let u=(0,Oe.memoized)((b,y)=>{let{X:x,Y:_,Z:T}=b,N=b.is0();y==null&&(y=N?O6:n.inv(T));let I=c(x*y),v=c(_*y),A=n.mul(T,y);if(N)return{x:Eo,y:pt};if(A!==pt)throw new Error("invZ was invalid");return{x:I,y:v}}),f=(0,Oe.memoized)(b=>{let{a:y,d:x}=s;if(b.is0())throw new Error("bad point: ZERO");let{X:_,Y:T,Z:N,T:I}=b,v=c(_*_),A=c(T*T),E=c(N*N),S=c(E*E),V=c(v*y),C=c(E*c(V+A)),g=c(S+c(x*c(v*A)));if(C!==g)throw new Error("bad point: equation left != right (1)");let w=c(_*T),O=c(N*I);if(w!==O)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(y,x,_,T){this.X=p("x",y),this.Y=p("y",x),this.Z=p("z",_,!0),this.T=p("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof h)throw new Error("extended point not allowed");let{x,y:_}=y||{};return p("x",x),p("y",_),new h(x,_,pt,c(x*_))}static fromBytes(y,x=!1){let _=n.BYTES,{a:T,d:N}=s;y=(0,Oe.copyBytes)((0,Oe._abytes2)(y,_,"point")),(0,Oe._abool2)(x,"zip215");let I=(0,Oe.copyBytes)(y),v=y[_-1];I[_-1]=v&-129;let A=(0,Oe.bytesToNumberLE)(I),E=x?a:n.ORDER;(0,Oe.aInRange)("point.y",A,Eo,E);let S=c(A*A),V=c(S-pt),C=c(N*S-T),{isValid:g,value:w}=d(V,C);if(!g)throw new Error("bad point: invalid y coordinate");let O=(w&pt)===pt,P=(v&128)!==0;if(!x&&w===Eo&&P)throw new Error("bad point: x=0 and x_0=1");return P!==O&&(w=c(-w)),h.fromAffine({x:w,y:A})}static fromHex(y,x=!1){return h.fromBytes((0,Oe.ensureBytes)("point",y),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,x=!0){return m.createCache(this,y),x||this.multiply(Zp),this}assertValidity(){f(this)}equals(y){l(y);let{X:x,Y:_,Z:T}=this,{X:N,Y:I,Z:v}=y,A=c(x*v),E=c(N*T),S=c(_*v),V=c(I*T);return A===E&&S===V}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=s,{X:x,Y:_,Z:T}=this,N=c(x*x),I=c(_*_),v=c(Zp*c(T*T)),A=c(y*N),E=x+_,S=c(c(E*E)-N-I),V=A+I,C=V-v,g=A-I,w=c(S*C),O=c(V*g),P=c(S*g),L=c(C*V);return new h(w,O,L,P)}add(y){l(y);let{a:x,d:_}=s,{X:T,Y:N,Z:I,T:v}=this,{X:A,Y:E,Z:S,T:V}=y,C=c(T*A),g=c(N*E),w=c(v*_*V),O=c(I*S),P=c((T+N)*(A+E)-C-g),L=O-w,R=O+w,B=c(g-x*C),F=c(P*L),U=c(R*B),q=c(P*B),H=c(L*R);return new h(F,U,H,q)}subtract(y){return this.add(y.negate())}multiply(y){if(!o.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:_}=m.cached(this,y,T=>(0,ss.normalizeZ)(h,T));return(0,ss.normalizeZ)(h,[x,_])[0]}multiplyUnsafe(y,x=h.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===Eo?h.ZERO:this.is0()||y===pt?this:m.unsafe(this,y,_=>(0,ss.normalizeZ)(h,_),x)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return m.unsafe(this,s.n).is0()}toAffine(y){return u(this,y)}clearCofactor(){return i===pt?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:x}=this.toAffine(),_=n.toBytes(x);return _[_.length-1]|=y&pt?128:0,_}toHex(){return(0,Oe.bytesToHex)(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(y){return(0,ss.normalizeZ)(h,y)}static msm(y,x){return(0,ss.pippenger)(h,o,y,x)}_setWindowSize(y){this.precompute(y)}toRawBytes(){return this.toBytes()}}h.BASE=new h(s.Gx,s.Gy,pt,c(s.Gx*s.Gy)),h.ZERO=new h(Eo,pt,pt,Eo),h.Fp=n,h.Fn=o;let m=new ss.wNAF(h,o.BITS);return h.BASE.precompute(8),h}var Yp=class{constructor(e){this.ep=e}static fromBytes(e){(0,Oe.notImplemented)()}static fromHex(e){(0,Oe.notImplemented)()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return(0,Oe.bytesToHex)(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.init(this.ep.precompute(e,r))}toRawBytes(){return this.toBytes()}};is.PrimeEdwardsPoint=Yp;function M_(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');(0,Oe._validateObject)(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=t,a=r.randomBytes||Oe.randomBytes,c=r.adjustScalarBytes||(E=>E),d=r.domain||((E,S,V)=>{if((0,Oe._abool2)(V,"phflag"),S.length||V)throw new Error("Contexts/pre-hash are not supported");return E});function p(E){return i.create((0,Oe.bytesToNumberLE)(E))}function l(E){let S=_.secretKey;E=(0,Oe.ensureBytes)("private key",E,S);let V=(0,Oe.ensureBytes)("hashed private key",e(E),2*S),C=c(V.slice(0,S)),g=V.slice(S,2*S),w=p(C);return{head:C,prefix:g,scalar:w}}function u(E){let{head:S,prefix:V,scalar:C}=l(E),g=o.multiply(C),w=g.toBytes();return{head:S,prefix:V,scalar:C,point:g,pointBytes:w}}function f(E){return u(E).pointBytes}function h(E=Uint8Array.of(),...S){let V=(0,Oe.concatBytes)(...S);return p(e(d(V,(0,Oe.ensureBytes)("context",E),!!n)))}function m(E,S,V={}){E=(0,Oe.ensureBytes)("message",E),n&&(E=n(E));let{prefix:C,scalar:g,pointBytes:w}=u(S),O=h(V.context,C,E),P=o.multiply(O).toBytes(),L=h(V.context,P,w,E),R=i.create(O+L*g);if(!i.isValid(R))throw new Error("sign failed: invalid s");let B=(0,Oe.concatBytes)(P,i.toBytes(R));return(0,Oe._abytes2)(B,_.signature,"result")}let b={zip215:!0};function y(E,S,V,C=b){let{context:g,zip215:w}=C,O=_.signature;E=(0,Oe.ensureBytes)("signature",E,O),S=(0,Oe.ensureBytes)("message",S),V=(0,Oe.ensureBytes)("publicKey",V,_.publicKey),w!==void 0&&(0,Oe._abool2)(w,"zip215"),n&&(S=n(S));let P=O/2,L=E.subarray(0,P),R=(0,Oe.bytesToNumberLE)(E.subarray(P,O)),B,F,U;try{B=t.fromBytes(V,w),F=t.fromBytes(L,w),U=o.multiplyUnsafe(R)}catch{return!1}if(!w&&B.isSmallOrder())return!1;let q=h(g,F.toBytes(),B.toBytes(),S);return F.add(B.multiplyUnsafe(q)).subtract(U).clearCofactor().is0()}let x=s.BYTES,_={secretKey:x,publicKey:x,signature:2*x,seed:x};function T(E=a(_.seed)){return(0,Oe._abytes2)(E,_.seed,"seed")}function N(E){let S=A.randomSecretKey(E);return{secretKey:S,publicKey:f(S)}}function I(E){return(0,Oe.isBytes)(E)&&E.length===i.BYTES}function v(E,S){try{return!!t.fromBytes(E,S)}catch{return!1}}let A={getExtendedPublicKey:u,randomSecretKey:T,isValidSecretKey:I,isValidPublicKey:v,toMontgomery(E){let{y:S}=t.fromBytes(E),V=_.publicKey,C=V===32;if(!C&&V!==57)throw new Error("only defined for 25519 and 448");let g=C?s.div(pt+S,pt-S):s.div(S-pt,S+pt);return s.toBytes(g)},toMontgomerySecret(E){let S=_.secretKey;(0,Oe._abytes2)(E,S);let V=e(E.subarray(0,S));return c(V).subarray(0,S)},randomPrivateKey:T,precompute(E=8,S=t.BASE){return S.precompute(E,!1)}};return Object.freeze({keygen:N,getPublicKey:f,sign:m,verify:y,utils:A,Point:t,lengths:_})}function v6(t){let e={a:t.a,d:t.d,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=(0,T6.Field)(e.n,t.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:t.uvRatio},s={randomBytes:t.randomBytes,adjustScalarBytes:t.adjustScalarBytes,domain:t.domain,prehash:t.prehash,mapToCurve:t.mapToCurve};return{CURVE:e,curveOpts:o,hash:t.hash,eddsaOpts:s}}function I6(t,e){let r=e.Point;return Object.assign({},e,{ExtendedPoint:r,CURVE:t,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function R6(t){let{CURVE:e,curveOpts:r,hash:n,eddsaOpts:o}=v6(t),s=q_(e,r),i=M_(s,n,o);return I6(t,i)}});var j_=Z(Wp=>{"use strict";Object.defineProperty(Wp,"__esModule",{value:!0});Wp.montgomery=B6;var on=Rr(),S6=Qr(),Na=BigInt(0),ci=BigInt(1),Pu=BigInt(2);function A6(t){return(0,on._validateObject)(t,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...t})}function B6(t){let e=A6(t),{P:r,type:n,adjustScalarBytes:o,powPminus2:s,randomBytes:i}=e,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=i||on.randomBytes,d=a?255:448,p=a?32:56,l=BigInt(a?9:5),u=BigInt(a?121665:39081),f=a?Pu**BigInt(254):Pu**BigInt(447),h=a?BigInt(8)*Pu**BigInt(251)-ci:BigInt(4)*Pu**BigInt(445)-ci,m=f+h+ci,b=g=>(0,S6.mod)(g,r),y=x(l);function x(g){return(0,on.numberToBytesLE)(b(g),p)}function _(g){let w=(0,on.ensureBytes)("u coordinate",g,p);return a&&(w[31]&=127),b((0,on.bytesToNumberLE)(w))}function T(g){return(0,on.bytesToNumberLE)(o((0,on.ensureBytes)("scalar",g,p)))}function N(g,w){let O=A(_(w),T(g));if(O===Na)throw new Error("invalid private or public key received");return x(O)}function I(g){return N(g,y)}function v(g,w,O){let P=b(g*(w-O));return w=b(w-P),O=b(O+P),{x_2:w,x_3:O}}function A(g,w){(0,on.aInRange)("u",g,Na,r),(0,on.aInRange)("scalar",w,f,m);let O=w,P=g,L=ci,R=Na,B=g,F=ci,U=Na;for(let H=BigInt(d-1);H>=Na;H--){let Y=O>>H&ci;U^=Y,{x_2:L,x_3:B}=v(U,L,B),{x_2:R,x_3:F}=v(U,R,F),U=Y;let G=L+R,ie=b(G*G),ae=L-R,Ce=b(ae*ae),ee=ie-Ce,ce=B+F,lr=B-F,vr=b(lr*G),fr=b(ce*ae),wn=vr+fr,io=vr-fr;B=b(wn*wn),F=b(P*b(io*io)),L=b(ie*Ce),R=b(ee*(ie+b(u*ee)))}({x_2:L,x_3:B}=v(U,L,B)),{x_2:R,x_3:F}=v(U,R,F);let q=s(R);return b(L*q)}let E={secretKey:p,publicKey:p,seed:p},S=(g=c(p))=>((0,on.abytes)(g,E.seed),g);function V(g){let w=S(g);return{secretKey:w,publicKey:I(w)}}return{keygen:V,getSharedSecret:(g,w)=>N(g,w),getPublicKey:g=>I(g),scalarMult:N,scalarMultBase:I,utils:{randomSecretKey:S,randomPrivateKey:S},GuBytes:y.slice(),lengths:E}}});var eb=Z(ne=>{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});ne.hash_to_ristretto255=ne.hashToRistretto255=ne.encodeToCurve=ne.hashToCurve=ne.RistrettoPoint=ne.edwardsToMontgomery=ne.ED25519_TORSION_SUBGROUP=ne.ristretto255_hasher=ne.ristretto255=ne.ed25519_hasher=ne.x25519=ne.ed25519ph=ne.ed25519ctx=ne.ed25519=void 0;ne.edwardsToMontgomeryPub=Q_;ne.edwardsToMontgomeryPriv=K6;var va=Gs(),Fu=dt(),C6=ya(),Uu=k_(),Du=bu(),Ae=Qr(),P6=j_(),as=Rr(),D6=BigInt(0),sn=BigInt(1),Vu=BigInt(2),G_=BigInt(3),z_=BigInt(5),eh=BigInt(8),Pn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ia={p:Pn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:eh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Z_(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Pn,a=t*t%s*t%s,c=(0,Ae.pow2)(a,Vu,s)*a%s,d=(0,Ae.pow2)(c,sn,s)*t%s,p=(0,Ae.pow2)(d,z_,s)*d%s,l=(0,Ae.pow2)(p,e,s)*p%s,u=(0,Ae.pow2)(l,r,s)*l%s,f=(0,Ae.pow2)(u,n,s)*u%s,h=(0,Ae.pow2)(f,o,s)*f%s,m=(0,Ae.pow2)(h,o,s)*f%s,b=(0,Ae.pow2)(m,e,s)*p%s;return{pow_p_5_8:(0,Ae.pow2)(b,Vu,s)*t%s,b2:a}}function Y_(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Xp=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function th(t,e){let r=Pn,n=(0,Ae.mod)(e*e*e,r),o=(0,Ae.mod)(n*n*e,r),s=Z_(t*o).pow_p_5_8,i=(0,Ae.mod)(t*n*s,r),a=(0,Ae.mod)(e*i*i,r),c=i,d=(0,Ae.mod)(i*Xp,r),p=a===t,l=a===(0,Ae.mod)(-t,r),u=a===(0,Ae.mod)(-t*Xp,r);return p&&(i=c),(l||u)&&(i=d),(0,Ae.isNegativeLE)(i,r)&&(i=(0,Ae.mod)(-i,r)),{isValid:p||l,value:i}}var K=(0,Ae.Field)(Ia.p,{isLE:!0}),W_=(0,Ae.Field)(Ia.n,{isLE:!0}),rh={...Ia,Fp:K,hash:va.sha512,adjustScalarBytes:Y_,uvRatio:th};ne.ed25519=(0,Uu.twistedEdwards)(rh);function X_(t,e,r){if(e.length>255)throw new Error("Context is too big");return(0,Fu.concatBytes)((0,Fu.utf8ToBytes)("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}ne.ed25519ctx=(0,Uu.twistedEdwards)({...rh,domain:X_});ne.ed25519ph=(0,Uu.twistedEdwards)(Object.assign({},rh,{domain:X_,prehash:va.sha512}));ne.x25519=(()=>{let t=K.ORDER;return(0,P6.montgomery)({P:t,type:"x25519",powPminus2:e=>{let{pow_p_5_8:r,b2:n}=Z_(e);return(0,Ae.mod)((0,Ae.pow2)(r,G_,t)*n,t)},adjustScalarBytes:Y_})})();var F6=(Pn+G_)/eh,V6=K.pow(Vu,F6),H_=K.sqrt(K.neg(K.ONE));function U6(t){let e=(Pn-z_)/eh,r=BigInt(486662),n=K.sqr(t);n=K.mul(n,Vu);let o=K.add(n,K.ONE),s=K.neg(r),i=K.sqr(o),a=K.mul(i,o),c=K.mul(n,r);c=K.mul(c,s),c=K.add(c,i),c=K.mul(c,s);let d=K.sqr(a);i=K.sqr(d),d=K.mul(d,a),d=K.mul(d,c),i=K.mul(i,d);let p=K.pow(i,e);p=K.mul(p,d);let l=K.mul(p,H_);i=K.sqr(p),i=K.mul(i,a);let u=K.eql(i,c),f=K.cmov(l,p,u),h=K.mul(s,n),m=K.mul(p,t);m=K.mul(m,V6);let b=K.mul(m,H_),y=K.mul(c,n);i=K.sqr(m),i=K.mul(i,a);let x=K.eql(i,y),_=K.cmov(b,m,x);i=K.sqr(f),i=K.mul(i,a);let T=K.eql(i,c),N=K.cmov(h,s,T),I=K.cmov(_,f,T),v=K.isOdd(I);return I=K.cmov(I,K.neg(I),T!==v),{xMn:N,xMd:o,yMn:I,yMd:sn}}var L6=(0,Ae.FpSqrtEven)(K,K.neg(BigInt(486664)));function q6(t){let{xMn:e,xMd:r,yMn:n,yMd:o}=U6(t),s=K.mul(e,o);s=K.mul(s,L6);let i=K.mul(r,n),a=K.sub(e,r),c=K.add(e,r),d=K.mul(i,c),p=K.eql(d,K.ZERO);s=K.cmov(s,K.ZERO,p),i=K.cmov(i,K.ONE,p),a=K.cmov(a,K.ONE,p),c=K.cmov(c,K.ONE,p);let[l,u]=(0,Ae.FpInvertBatch)(K,[i,c],!0);return{x:K.mul(s,l),y:K.mul(a,u)}}ne.ed25519_hasher=(0,Du.createHasher)(ne.ed25519.Point,t=>q6(t[0]),{DST:"edwards25519_XMD:SHA-512_ELL2_RO_",encodeDST:"edwards25519_XMD:SHA-512_ELL2_NU_",p:Pn,m:1,k:128,expand:"xmd",hash:va.sha512});var Jp=Xp,M6=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),k6=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),j6=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),H6=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),$_=t=>th(sn,t),$6=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Qp=t=>ne.ed25519.Point.Fp.create((0,as.bytesToNumberLE)(t)&$6);function K_(t){let{d:e}=Ia,r=Pn,n=y=>K.create(y),o=n(Jp*t*t),s=n((o+sn)*j6),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:d}=th(s,a),p=n(d*t);(0,Ae.isNegativeLE)(p,r)||(p=n(-p)),c||(d=p),c||(i=o);let l=n(i*(o-sn)*H6-a),u=d*d,f=n((d+d)*a),h=n(l*M6),m=n(sn-u),b=n(sn+u);return new ne.ed25519.Point(n(f*b),n(m*h),n(h*b),n(f*m))}function J_(t){(0,Fu.abytes)(t,64);let e=Qp(t.subarray(0,32)),r=K_(e),n=Qp(t.subarray(32,64)),o=K_(n);return new Br(r.add(o))}var Br=class t extends Uu.PrimeEdwardsPoint{constructor(e){super(e)}static fromAffine(e){return new t(ne.ed25519.Point.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static hashToCurve(e){return J_((0,as.ensureBytes)("ristrettoHash",e,64))}static fromBytes(e){(0,Fu.abytes)(e,32);let{a:r,d:n}=Ia,o=Pn,s=T=>K.create(T),i=Qp(e);if(!(0,as.equalBytes)(K.toBytes(i),e)||(0,Ae.isNegativeLE)(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(sn+r*a),d=s(sn-r*a),p=s(c*c),l=s(d*d),u=s(r*n*p-l),{isValid:f,value:h}=$_(s(u*l)),m=s(h*d),b=s(h*m*u),y=s((i+i)*m);(0,Ae.isNegativeLE)(y,o)&&(y=s(-y));let x=s(c*b),_=s(y*x);if(!f||(0,Ae.isNegativeLE)(_,o)||x===D6)throw new Error("invalid ristretto255 encoding 2");return new t(new ne.ed25519.Point(y,x,sn,_))}static fromHex(e){return t.fromBytes((0,as.ensureBytes)("ristrettoHex",e,32))}static msm(e,r){return(0,C6.pippenger)(t,ne.ed25519.Point.Fn,e,r)}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=Pn,i=b=>K.create(b),a=i(i(n+r)*i(n-r)),c=i(e*r),d=i(c*c),{value:p}=$_(i(a*d)),l=i(p*a),u=i(p*c),f=i(l*u*o),h;if((0,Ae.isNegativeLE)(o*f,s)){let b=i(r*Jp),y=i(e*Jp);e=b,r=y,h=i(l*k6)}else h=u;(0,Ae.isNegativeLE)(e*f,s)&&(r=i(-r));let m=i((n-r)*h);return(0,Ae.isNegativeLE)(m,s)&&(m=i(-m)),K.toBytes(m)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=d=>K.create(d),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Br.BASE=new Br(ne.ed25519.Point.BASE);Br.ZERO=new Br(ne.ed25519.Point.ZERO);Br.Fp=K;Br.Fn=W_;ne.ristretto255={Point:Br};ne.ristretto255_hasher={hashToCurve(t,e){let r=e?.DST||"ristretto255_XMD:SHA-512_R255MAP_RO_",n=(0,Du.expand_message_xmd)(t,r,64,va.sha512);return J_(n)},hashToScalar(t,e={DST:Du._DST_scalar}){let r=(0,Du.expand_message_xmd)(t,e.DST,64,va.sha512);return W_.create((0,as.bytesToNumberLE)(r))}};ne.ED25519_TORSION_SUBGROUP=["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"];function Q_(t){return ne.ed25519.utils.toMontgomery((0,as.ensureBytes)("pub",t))}ne.edwardsToMontgomery=Q_;function K6(t){return ne.ed25519.utils.toMontgomerySecret((0,as.ensureBytes)("pub",t))}ne.RistrettoPoint=Br;ne.hashToCurve=ne.ed25519_hasher.hashToCurve;ne.encodeToCurve=ne.ed25519_hasher.encodeToCurve;ne.hashToRistretto255=ne.ristretto255_hasher.hashToCurve;ne.hash_to_ristretto255=ne.ristretto255_hasher.hashToCurve});var nb=Z(Lu=>{"use strict";var tb,rb;Object.defineProperty(Lu,"__esModule",{value:!0});Lu.ExpirableMap=void 0;var nh=class{static{tb=Symbol.iterator,rb=Symbol.toStringTag}#e;#t;constructor(e={}){this[tb]=this.entries.bind(this),this[rb]="ExpirableMap";let{source:r=[],expirationTime:n=600*1e3}=e,o=Date.now();this.#e=new Map([...r].map(([s,i])=>[s,{value:i,timestamp:o}])),this.#t=n}prune(){let e=Date.now();for(let[r,n]of this.#e.entries())e-n.timestamp>this.#t&&this.#e.delete(r);return this}set(e,r){this.prune();let n={value:r,timestamp:Date.now()};return this.#e.set(e,n),this}get(e){let r=this.#e.get(e);if(r!==void 0){if(Date.now()-r.timestamp>this.#t){this.#e.delete(e);return}return r.value}}clear(){this.#e.clear()}entries(){let e=this.#e.entries();return function*(){for(let[n,o]of e)yield[n,o.value]}()}values(){let e=this.#e.values();return function*(){for(let n of e)yield n.value}()}keys(){return this.#e.keys()}forEach(e,r){for(let[n,o]of this.#e.entries())e.call(r,o.value,n,this)}has(e){return this.#e.has(e)}delete(e){return this.#e.delete(e)}get size(){return this.#e.size}};Lu.ExpirableMap=nh});var oh=Z(Fe=>{"use strict";Object.defineProperty(Fe,"__esModule",{value:!0});Fe.unwrapDER=Fe.BLS12_381_G2_OID=Fe.SECP256K1_OID=Fe.ED25519_OID=Fe.DER_COSE_OID=Fe.decodeLen=Fe.decodeLenBytes=Fe.encodeLen=Fe.encodeLenBytes=void 0;Fe.wrapDER=X6;var St=sr(),G6=Qs(),z6=t=>{if(t<=127)return 1;if(t<=255)return 2;if(t<=65535)return 3;if(t<=16777215)return 4;throw St.InputError.fromCode(new St.DerEncodeErrorCode("Length too long (> 4 bytes)"))};Fe.encodeLenBytes=z6;var Z6=(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 St.InputError.fromCode(new St.DerEncodeErrorCode("Length too long (> 4 bytes)"))};Fe.encodeLen=Z6;var Y6=(t,e)=>{if(t[e]<128)return 1;if(t[e]===128)throw St.InputError.fromCode(new St.DerDecodeErrorCode("Invalid length 0"));if(t[e]===129)return 2;if(t[e]===130)return 3;if(t[e]===131)return 4;throw St.InputError.fromCode(new St.DerDecodeErrorCode("Length too long (> 4 bytes)"))};Fe.decodeLenBytes=Y6;var W6=(t,e)=>{let r=(0,Fe.decodeLenBytes)(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 St.InputError.fromCode(new St.DerDecodeErrorCode("Length too long (> 4 bytes)"))};Fe.decodeLen=W6;Fe.DER_COSE_OID=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]);Fe.ED25519_OID=Uint8Array.from([48,5,6,3,43,101,112]);Fe.SECP256K1_OID=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);Fe.BLS12_381_G2_OID=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 X6(t,e){let r=2+(0,Fe.encodeLenBytes)(t.byteLength+1),n=e.byteLength+r+t.byteLength,o=0,s=new Uint8Array(1+(0,Fe.encodeLenBytes)(n)+n);return s[o++]=48,o+=(0,Fe.encodeLen)(s,o,n),s.set(e,o),o+=e.byteLength,s[o++]=3,o+=(0,Fe.encodeLen)(s,o,t.byteLength+1),s[o++]=0,s.set(new Uint8Array(t),o),s}var J6=(t,e)=>{let r=0,n=(a,c)=>{if(o[r++]!==a)throw St.InputError.fromCode(new St.DerDecodeErrorCode(`Expected ${c} at offset ${r}`))},o=new Uint8Array(t);if(n(48,"sequence"),r+=(0,Fe.decodeLenBytes)(o,r),!(0,G6.uint8Equals)(o.slice(r,r+e.byteLength),e))throw St.InputError.fromCode(new St.DerDecodeErrorCode("Not the expected OID."));r+=e.byteLength,n(3,"bit string");let s=(0,Fe.decodeLen)(o,r)-1;r+=(0,Fe.decodeLenBytes)(o,r),n(0,"0 padding");let i=o.slice(r);if(s!==i.length)throw St.InputError.fromCode(new St.DerDecodeLengthMismatchErrorCode(s,i.length));return i};Fe.unwrapDER=J6});var ih=Z(ku=>{"use strict";Object.defineProperty(ku,"__esModule",{value:!0});ku.Ed25519PublicKey=void 0;var qu=oh(),Mu=sr(),sh=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(0,qu.wrapDER)(e,qu.ED25519_OID)}static derDecode(e){let r=(0,qu.unwrapDER)(e,qu.ED25519_OID);if(r.length!==this.RAW_KEY_LENGTH)throw Mu.InputError.fromCode(new Mu.DerDecodeErrorCode("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 Mu.InputError.fromCode(new Mu.DerDecodeErrorCode("An Ed25519 public key must be exactly 32 bytes long"));this.#e=e,this.#t=t.derEncode(e)}toDer(){return this.derKey}toRaw(){return this.rawKey}};ku.Ed25519PublicKey=sh});var ch=Z(ui=>{"use strict";Object.defineProperty(ui,"__esModule",{value:!0});ui.ObservableLog=ui.Observable=void 0;var ju=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))}};ui.Observable=ju;var ah=class extends ju{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)}};ui.ObservableLog=ah});var db=Z(Sa=>{"use strict";Object.defineProperty(Sa,"__esModule",{value:!0});Sa.ExponentialBackoff=void 0;Sa.exponentialBackoff=Q6;var ob=.5,sb=1.5,ib=500,ab=6e4,cb=9e5,ub=10,Ra=class t{#e;#t;#r;#c;#i;#d;#n;#o;#a=0;static{this.default={initialInterval:ib,randomizationFactor:ob,multiplier:sb,maxInterval:ab,maxElapsedTime:cb,maxIterations:ub,date:Date}}constructor(e=t.default){let{initialInterval:r=ib,randomizationFactor:n=ob,multiplier:o=sb,maxInterval:s=ab,maxElapsedTime:i=cb,maxIterations:a=ub,date:c=Date}=e;this.#e=r,this.#t=n,this.#r=o,this.#c=s,this.#o=c,this.#i=c.now(),this.#d=i,this.#n=a}get ellapsedTimeInMsec(){return this.#o.now()-this.#i}get currentInterval(){return this.#e}get count(){return this.#a}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.#c),this.#a++,this.#e}next(){return this.ellapsedTimeInMsec>=this.#d||this.#a>=this.#n?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};Sa.ExponentialBackoff=Ra;function*Q6(t=Ra.default){let e=new Ra(t),r=e.next();for(;r;)yield r,r=e.next()}});var $u=Z($e=>{"use strict";var _b=$e&&$e.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),e4=$e&&$e.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),t4=$e&&$e.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),o=0;o<n.length;o++)n[o]!=="default"&&_b(r,e,n[o]);return e4(r,e),r}})(),r4=$e&&$e.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&_b(e,t,r)};Object.defineProperty($e,"__esModule",{value:!0});$e.HttpAgent=$e.MANAGEMENT_CANISTER_ID=$e.IC_ROOT_KEY=$e.RequestStatusResponseStatus=$e.makeNonce=void 0;$e.calculateIngressExpiry=Hu;var Dn=Ir(),z=sr(),lb=ap(),To=t4(la()),Aa=ou(),fb=Ol(),di=fu(),Fn=ei(),pb=Cu(),hb=ai(),n4=eb(),o4=nb(),s4=ih(),i4=ch(),a4=db(),c4=Ru(),mb=dt(),uh=Qs(),u4=su();r4(fu(),$e);var d4=ei();Object.defineProperty($e,"makeNonce",{enumerable:!0,get:function(){return d4.makeNonce}});var yb;(function(t){t.Received="received",t.Processing="processing",t.Replied="replied",t.Rejected="rejected",t.Unknown="unknown",t.Done="done"})(yb||($e.RequestStatusResponseStatus=yb={}));var lh=60*1e3,l4=1e6,f4=0;$e.IC_ROOT_KEY="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae";$e.MANAGEMENT_CANISTER_ID="aaaaa-aa";var p4="ic0.app",h4=".ic0.app",m4="icp0.io",y4=".icp0.io",_4="icp-api.io",b4=".icp-api.io",dh=200,g4=202,x4=404;function w4(){let t;if(typeof window<"u")if(window.fetch)t=window.fetch.bind(window);else throw z.ExternalError.fromCode(new z.HttpDefaultFetchErrorCode("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present."));else if(typeof global<"u")if(global.fetch)t=global.fetch.bind(global);else throw z.ExternalError.fromCode(new z.HttpDefaultFetchErrorCode("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available."));else typeof self<"u"&&self.fetch&&(t=self.fetch.bind(self));if(t)return t;throw z.ExternalError.fromCode(new z.HttpDefaultFetchErrorCode("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context."))}function E4(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(a=>s.endsWith(a))?i=s:i=r.find(a=>s.endsWith(a))),o&&i?e=new URL(`${o.protocol}//${i}${o.port?":"+o.port:""}`):e=new URL("https://icp-api.io")}return e.toString()}var fh=class t{#e;#t;#r;#c;#i;#d;#n;#o;#a;#g;#s;#l;#f;#u;get#T(){return this.#u*lh}#p;#h;#m;#y;constructor(e={}){this.#e=null,this.#t=!1,this.#r=f4,this.#c=!1,this.#i=null,this.#d=!1,this._isAgent=!0,this.config={},this.log=new i4.ObservableLog,this.#p=[],this.#h=[],this.#m=new o4.ExpirableMap({expirationTime:5*lh}),this.#y=!0,this.#w=(o,s)=>{if(this.#y===!1)return o;let{status:i,signatures:a=[],requestId:c}=o;for(let d of a){let{timestamp:p,identity:l}=d,u=Dn.Principal.fromUint8Array(l).toText(),f;if(i===fb.QueryResponseStatus.Replied){let{reply:x}=o;f=(0,Aa.hashOfMap)({status:i,reply:x,timestamp:BigInt(p),request_id:c})}else if(i===fb.QueryResponseStatus.Rejected){let{reject_code:x,reject_message:_,error_code:T}=o;f=(0,Aa.hashOfMap)({status:i,reject_code:x,reject_message:_,error_code:T,timestamp:BigInt(p),request_id:c})}else throw z.UnknownError.fromCode(new z.UnexpectedErrorCode(`Unknown status: ${i}`));let h=(0,mb.concatBytes)(u4.IC_RESPONSE_DOMAIN_SEPARATOR,f),m=s.nodeKeys.get(u);if(!m)throw z.ProtocolError.fromCode(new z.MalformedPublicKeyErrorCode);let b=s4.Ed25519PublicKey.fromDer(m).rawKey;if(n4.ed25519.verify(d.signature,h,b))return o;throw z.TrustError.fromCode(new z.QuerySignatureVerificationFailedErrorCode(u))}return o},this.config=e,this.#o=e.fetch||w4()||fetch.bind(global),this.#a=e.fetchOptions,this.#g=e.callOptions,this.#t=e.shouldFetchRootKey??!1,this.#d=e.shouldSyncTime??!1,e.rootKey?this.rootKey=e.rootKey:this.#t?this.rootKey=null:this.rootKey=(0,mb.hexToBytes)($e.IC_ROOT_KEY);let r=E4(e.host);this.host=new URL(r),e.verifyQuerySignatures!==void 0&&(this.#y=e.verifyQuerySignatures),this.#l=e.retryTimes??3;let n=()=>new a4.ExponentialBackoff({maxIterations:this.#l});if(this.#f=e.backoffStrategy||n,this.host.hostname.endsWith(h4)?this.host.hostname=p4:this.host.hostname.endsWith(y4)?this.host.hostname=m4:this.host.hostname.endsWith(b4)&&(this.host.hostname=_4),e.credentials){let{name:o,password:s}=e.credentials;this.#s=`${o}${s?":"+s:""}`}if(this.#n=Promise.resolve(e.identity||new lb.AnonymousIdentity),e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes>5)throw z.InputError.fromCode(new z.IngressExpiryInvalidErrorCode("The maximum ingress expiry time is 5 minutes.",e.ingressExpiryInMinutes));if(e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes<=0)throw z.InputError.fromCode(new z.IngressExpiryInvalidErrorCode("Ingress expiry time must be greater than 0.",e.ingressExpiryInMinutes));this.#u=e.ingressExpiryInMinutes||5,this.addTransform("update",(0,di.makeNonceTransform)(Fn.makeNonce)),e.useQueryNonces&&this.addTransform("query",(0,di.makeNonceTransform)(Fn.makeNonce)),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.#b(),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 z.InputError.fromCode(new z.CreateHttpAgentErrorCode)}}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.#h.findIndex(s=>(s.priority||0)<n);this.#h.splice(o>=0?o:this.#h.length,0,Object.assign(r,{priority:n}))}else if(e==="query"){let o=this.#p.findIndex(s=>(s.priority||0)<n);this.#p.splice(o>=0?o:this.#p.length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!this.#n)throw z.ExternalError.fromCode(new z.IdentityInvalidErrorCode);return(await this.#n).getPrincipal()}async call(e,r,n){let o=r.callSync??!0,s=await(n??this.#n);if(!s)throw z.ExternalError.fromCode(new z.IdentityInvalidErrorCode);let i=Dn.Principal.from(e),a=r.effectiveCanisterId?Dn.Principal.from(r.effectiveCanisterId):i;await this.#b(a);let c=s.getPrincipal(),d=Hu(this.#u,this.#r),p={request_type:Fn.SubmitRequestType.Call,canister_id:i,method_name:r.methodName,arg:r.arg,sender:c,ingress_expiry:d},l=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#s?{Authorization:"Basic "+btoa(this.#s)}:{}}},endpoint:Fn.Endpoint.Call,body:p}),u;r?.nonce?u=f(r.nonce):l.body.nonce?u=f(l.body.nonce):u=void 0,p.nonce=u;function f(y){return Object.assign(y,{__nonce__:void 0})}l=await s.transformRequest(l);let h=To.encode(l.body),m=this.#f(),b=(0,Aa.requestIdOf)(p);try{let _=o?()=>(this.log.print(`fetching "/api/v3/canister/${a.toText()}/call" with request:`,l),this.#o(""+new URL(`/api/v3/canister/${a.toText()}/call`,this.host),{...this.#g,...l.request,body:h})):()=>(this.log.print(`fetching "/api/v2/canister/${a.toText()}/call" with request:`,l),this.#o(""+new URL(`/api/v2/canister/${a.toText()}/call`,this.host),{...this.#g,...l.request,body:h})),{responseBodyBytes:T,...N}=await this.#_({requestFn:_,backoff:m,tries:0}),I=T.byteLength>0?To.decode(T):null;return{requestId:b,response:{...N,body:I},requestDetails:p}}catch(y){let x;if(y instanceof z.AgentError){if(y.hasCode(z.HttpV3ApiNotSupportedErrorCode))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(e,{...r,callSync:!1},n);if(y.hasCode(z.IngressExpiryInvalidErrorCode)&&!this.#c)return await this.syncTime(i),this.call(i,r,n);y.code.requestContext={requestId:b,senderPubKey:l.body.sender_pubkey,senderSignature:l.body.sender_sig,ingressExpiry:l.body.content.ingress_expiry},x=y}else x=z.UnknownError.fromCode(new z.UnexpectedErrorCode(y));throw this.log.error(`Error while making call: ${x.message}`,x),x}}async#x(e){let{ecid:r,transformedRequest:n,body:o,requestId:s,backoff:i,tries:a}=e,c=a===0?0:i.next();if(this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with tries:`,{tries:a,backoff:i,delay:c}),c===null)throw z.UnknownError.fromCode(new z.TimeoutWaitingForResponseErrorCode(`Backoff strategy exhausted after ${a} attempts.`,s));c>0&&await new Promise(f=>setTimeout(f,c));let d;try{this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with request:`,n);let f=await this.#o(""+new URL(`/api/v2/canister/${r.toString()}/query`,this.host),{...this.#a,...n.request,body:o});if(f.status===dh)d={...To.decode((0,uh.uint8FromBufLike)(await f.arrayBuffer())),httpDetails:{ok:f.ok,status:f.status,statusText:f.statusText,headers:(0,di.httpHeadersTransform)(f.headers)},requestId:s};else throw z.ProtocolError.fromCode(new z.HttpErrorCode(f.status,f.statusText,(0,di.httpHeadersTransform)(f.headers),await f.text()))}catch(f){if(a<this.#l)return this.log.warn(`Caught exception while attempting to make query:
|
|
66
|
-
${f}
|
|
67
|
-
Retrying query.`),await this.#x({...e,tries:a+1});throw f instanceof z.AgentError?f:z.TransportError.fromCode(new z.HttpFetchErrorCode(f))}if(!this.#y)return d;let p=d.signatures?.[0]?.timestamp;if(!p)throw z.ProtocolError.fromCode(new z.MalformedSignatureErrorCode("Timestamp not found in query response. This suggests a malformed or malicious response."));let l=Number(BigInt(p)/BigInt(l4));if(Date.now()+this.#r-l>this.#T){if(a<this.#l)return this.log.warn("Timestamp is older than the max ingress expiry. Retrying query.",{requestId:s,signatureTimestampMs:l}),await this.#x({...e,tries:a+1});throw z.TrustError.fromCode(new z.CertificateOutdatedErrorCode(this.#u,s,a))}return d}async#_(e){let{requestFn:r,backoff:n,tries:o}=e,s=o===0?0:n.next();if(s===null)throw z.ProtocolError.fromCode(new z.TimeoutWaitingForResponseErrorCode(`Retry strategy exhausted after ${o} attempts.`));s>0&&await new Promise(p=>setTimeout(p,s));let i,a=new Uint8Array;try{i=await r(),i.status===dh&&(a=(0,uh.uint8FromBufLike)(await i.clone().arrayBuffer()))}catch(p){if(o<this.#l)return this.log.warn(`Caught exception while attempting to make request:
|
|
64
|
+
${e(s)}
|
|
65
|
+
)`}else throw he.UnknownError.fromCode(new he.HashTreeDecodeErrorCode("Invalid tree structure for labeled"));case Ye.Leaf:{if(t[1]){if(Array.isArray(t[1]))return JSON.stringify(t[1])}else throw he.UnknownError.fromCode(new he.HashTreeDecodeErrorCode("Invalid tree structure for leaf"));return`leaf(...${t[1].byteLength} bytes)`}case Ye.Pruned:{if(t[1]){if(Array.isArray(t[1]))return JSON.stringify(t[1])}else throw he.UnknownError.fromCode(new he.HashTreeDecodeErrorCode("Invalid tree structure for pruned"));return`pruned(${(0,Ps.bytesToHex)(new Uint8Array(t[1]))}`}default:return`unknown(${JSON.stringify(t[0])})`}}function uO(t,e){for(let r=0;r<t.length;r++)if(t[r]>e[r])return!0;return!1}var Th=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.canisterId,e.blsVerify??tO.blsVerify,e.maxAgeInMinutes,e.disableTimeVerification,e.agent)}constructor(e,r,n,s,o=iO,i=!1,a){this._rootKey=r,this._canisterId=n,this._blsVerify=s,this._maxAgeInMinutes=o,this.#e=i,this.cert=xb.decode(e),a&&"getTimeDiffMsecs"in a&&"hasSyncedTime"in a&&"syncTime"in a&&(this.#t=a)}lookup_path(e){return td(e,this.cert.tree)}lookup_subtree(e){return vh(e,this.cert.tree)}async verify(){let e=await $a(this.cert.tree),r=await this._checkDelegationAndGetKey(this.cert.delegation),n=this.cert.signature,s=lO(r),o=(0,Ps.concatBytes)(Ti("ic-state-root"),e),i=Oh(this.lookup_path(["time"]));if(!i)throw he.ProtocolError.fromCode(new he.CertificateVerificationErrorCode("Certificate does not contain a time"));if(!this.#e){let a=this.#t?.getTimeDiffMsecs()??0,c=this._maxAgeInMinutes*bb,d=new Date,f=d.getTime()+a,l=f-c,u=f+aO*bb,p=(0,rO.decodeTime)(i),h=p.getTime()<l,m=p.getTime()>u;if((h||m)&&this.#t&&!this.#t.hasSyncedTime())return await this.#t.syncTime(this._canisterId),await this.verify();if(h)throw he.TrustError.fromCode(new he.CertificateTimeErrorCode(this._maxAgeInMinutes,p,d,a,"past"));if(m)throw this.#t?.hasSyncedTime()?he.UnknownError.fromCode(new he.UnexpectedErrorCode("System time has been synced with the IC network, but certificate is still too far in the future.")):he.TrustError.fromCode(new he.CertificateTimeErrorCode(5,p,d,a,"future"))}try{if(!await this._blsVerify(s,n,o))throw he.TrustError.fromCode(new he.CertificateVerificationErrorCode("Invalid signature"))}catch(a){throw he.TrustError.fromCode(new he.CertificateVerificationErrorCode("Signature verification failed",a))}}async _checkDelegationAndGetKey(e){if(!e)return this._rootKey;let r=t.createUnverified({certificate:e.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,disableTimeVerification:this.#e,maxAgeInMinutes:cO,agent:this.#t});if(r.cert.delegation)throw he.ProtocolError.fromCode(new he.CertificateHasTooManyDelegationsErrorCode);await r.verify();let n=e.subnet_id,s=Eh.Principal.fromUint8Array(n);if(!Tb({canisterId:this._canisterId,subnetId:s,tree:r.cert.tree}))throw he.TrustError.fromCode(new he.CertificateNotAuthorizedErrorCode(this._canisterId,s));let i=Oh(r.lookup_path(["subnet",n,"public_key"]));if(!i)throw he.TrustError.fromCode(new he.MissingLookupValueErrorCode(`Could not find subnet key for subnet ID ${s.toText()}`));return i}};Ve.Certificate=Th;var Ha=(0,Ps.hexToBytes)("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),dO=96;function lO(t){let e=Ha.byteLength+dO;if(t.byteLength!==e)throw he.ProtocolError.fromCode(new he.DerKeyLengthMismatchErrorCode(e,t.byteLength));let r=t.slice(0,Ha.byteLength);if(!(0,wb.uint8Equals)(r,Ha))throw he.ProtocolError.fromCode(new he.DerPrefixMismatchErrorCode(Ha,r));return t.slice(Ha.byteLength)}function Oh(t){if(t.status===pn.Found&&t.value instanceof Uint8Array)return t.value}async function $a(t){switch(t[0]){case Ye.Empty:return(0,Qu.sha256)(Ti("ic-hashtree-empty"));case Ye.Pruned:return t[1];case Ye.Leaf:return(0,Qu.sha256)((0,Ps.concatBytes)(Ti("ic-hashtree-leaf"),t[1]));case Ye.Labeled:return(0,Qu.sha256)((0,Ps.concatBytes)(Ti("ic-hashtree-labeled"),t[1],await $a(t[2])));case Ye.Fork:return(0,Qu.sha256)((0,Ps.concatBytes)(Ti("ic-hashtree-fork"),await $a(t[1]),await $a(t[2])));default:throw he.UNREACHABLE_ERROR}}function Ti(t){let e=new Uint8Array([t.length]),r=new TextEncoder().encode(t);return(0,Ps.concatBytes)(e,r)}function Eb(t){return typeof t[0]=="string"?(0,Ps.utf8ToBytes)(t[0]):t[0]}var pn;(function(t){t.Unknown="Unknown",t.Absent="Absent",t.Found="Found",t.Error="Error"})(pn||(Ve.LookupPathStatus=pn={}));var Ka;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found"})(Ka||(Ve.LookupSubtreeStatus=Ka={}));var He;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found",t.Less="Less",t.Greater="Greater"})(He||(Ve.LookupLabelStatus=He={}));function td(t,e){if(t.length===0)switch(e[0]){case Ye.Empty:return{status:pn.Absent};case Ye.Leaf:{if(!e[1])throw he.UnknownError.fromCode(new he.HashTreeDecodeErrorCode("Invalid tree structure for leaf"));if(e[1]instanceof Uint8Array)return{status:pn.Found,value:e[1].slice(e[1].byteOffset,e[1].byteLength+e[1].byteOffset)};throw he.UNREACHABLE_ERROR}case Ye.Pruned:return{status:pn.Unknown};case Ye.Labeled:case Ye.Fork:return{status:pn.Error};default:throw he.UNREACHABLE_ERROR}let r=Eb(t),n=Oi(r,e);switch(n.status){case He.Found:return td(t.slice(1),n.value);case He.Absent:case He.Greater:case He.Less:return{status:pn.Absent};case He.Unknown:return{status:pn.Unknown};default:throw he.UNREACHABLE_ERROR}}function vh(t,e){if(t.length===0)return{status:Ka.Found,value:e};let r=Eb(t),n=Oi(r,e);switch(n.status){case He.Found:return vh(t.slice(1),n.value);case He.Unknown:return{status:Ka.Unknown};case He.Absent:case He.Greater:case He.Less:return{status:Ka.Absent};default:throw he.UNREACHABLE_ERROR}}function Nh(t){switch(t[0]){case Ye.Empty:return[];case Ye.Fork:return Nh(t[1]).concat(Nh(t[2]));default:return[t]}}function Oi(t,e){switch(e[0]){case Ye.Labeled:return uO(t,e[1])?{status:He.Greater}:(0,wb.uint8Equals)(t,e[1])?{status:He.Found,value:e[2]}:{status:He.Less};case Ye.Fork:{let r=Oi(t,e[1]);switch(r.status){case He.Greater:{let n=Oi(t,e[2]);return n.status===He.Less?{status:He.Absent}:n}case He.Unknown:{let n=Oi(t,e[2]);return n.status===He.Less?{status:He.Unknown}:n}default:return r}}case Ye.Pruned:return{status:He.Unknown};default:return{status:He.Absent}}}function Tb(t){let{canisterId:e,subnetId:r,tree:n}=t,s=td(["subnet",r.toUint8Array(),"canister_ranges"],n);if(s.status!==pn.Found)throw he.ProtocolError.fromCode(new he.LookupErrorCode(`Could not find canister ranges for subnet ${r.toText()}`,s.status));if(!(s.value instanceof Uint8Array))throw he.ProtocolError.fromCode(new he.MalformedLookupFoundValueErrorCode(`Could not find canister ranges for subnet ${r.toText()}`));return xb.decode(s.value).map(c=>[Eh.Principal.fromUint8Array(c[0]),Eh.Principal.fromUint8Array(c[1])]).some(c=>c[0].ltEq(e)&&c[1].gtEq(e))}});var rd=Y(yt=>{"use strict";var fO=yt&&yt.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),pO=yt&&yt.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),hO=yt&&yt.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[n.length]=s);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),s=0;s<n.length;s++)n[s]!=="default"&&fO(r,e,n[s]);return pO(r,e),r}})();Object.defineProperty(yt,"__esModule",{value:!0});yt.encodePath=yt.fetchNodeKeys=yt.request=yt.CustomPath=void 0;var Ds=Ur(),at=yr(),Fs=Ni(),Ih=hO(Ca()),Ob=Ju(),ir=ht(),Rh=class{constructor(e,r,n){this.key=e,this.path=r,this.decodeStrategy=n}};yt.CustomPath=Rh;var mO=async t=>{let{agent:e,paths:r,disableCertificateTimeVerification:n=!1}=t,s=Ds.Principal.from(t.canisterId),o=[...new Set(r)],i=new Map,a=o.map((c,d)=>{let f=(0,yt.encodePath)(c,s);return(async()=>{try{if(e.rootKey===null)throw at.ExternalError.fromCode(new at.MissingRootKeyErrorCode);let l=e.rootKey,u=await e.readState(s,{paths:[f]}),p=await Fs.Certificate.create({certificate:u.certificate,rootKey:l,canisterId:s,disableTimeVerification:n,agent:e}),h=(y,x)=>{if(x==="subnet"){let _=(0,yt.fetchNodeKeys)(u.certificate,s,l);return{path:x,data:_}}else return{path:x,data:(0,Fs.lookupResultToBuffer)(y.lookup_path(f))}},{path:m,data:b}=h(p,o[d]);if(!b)console.warn(`Expected to find result for path ${m}, but instead found nothing.`),typeof m=="string"?i.set(m,null):i.set(m.key,null);else switch(m){case"time":{i.set(m,(0,Ob.decodeTime)(b));break}case"controllers":{i.set(m,bO(b));break}case"module_hash":{i.set(m,(0,ir.bytesToHex)(b));break}case"subnet":{i.set(m,b);break}case"candid":{i.set(m,new TextDecoder().decode(b));break}default:if(typeof m!="string"&&"key"in m&&"path"in m)switch(m.decodeStrategy){case"raw":i.set(m.key,b);break;case"leb128":{i.set(m.key,(0,Ob.decodeLeb128)(b));break}case"cbor":{i.set(m.key,Ih.decode(b));break}case"hex":{i.set(m.key,(0,ir.bytesToHex)(b));break}case"utf-8":i.set(m.key,new TextDecoder().decode(b))}}}catch(l){if(l instanceof at.AgentError&&(l.hasCode(at.CertificateVerificationErrorCode)||l.hasCode(at.CertificateTimeErrorCode)))throw l;typeof c!="string"&&"key"in c&&"path"in c?i.set(c.key,null):i.set(c,null),console.group(),console.warn(`Expected to find result for path ${c}, but instead found nothing.`),console.warn(l),console.groupEnd()}})()});return await Promise.all(a),i};yt.request=mO;var yO=(t,e,r)=>{if(!e._isPrincipal)throw at.InputError.fromCode(new at.UnexpectedErrorCode("Invalid canisterId"));let n=Ih.decode(t),s=n.tree,o=n.delegation,i;if(o&&o.subnet_id?i=Ds.Principal.fromUint8Array(new Uint8Array(o.subnet_id)):!o&&typeof r<"u"?(i=Ds.Principal.selfAuthenticating(new Uint8Array(r)),o={subnet_id:i.toUint8Array(),certificate:new Uint8Array(0)}):(i=Ds.Principal.selfAuthenticating(Ds.Principal.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),o={subnet_id:i.toUint8Array(),certificate:new Uint8Array(0)}),!(0,Fs.check_canister_ranges)({canisterId:e,subnetId:i,tree:s}))throw at.TrustError.fromCode(new at.CertificateNotAuthorizedErrorCode(e,i));let c=(0,Fs.lookup_subtree)(["subnet",o.subnet_id,"node"],s);if(c.status!==Fs.LookupSubtreeStatus.Found)throw at.ProtocolError.fromCode(new at.LookupErrorCode("Node not found",c.status));if(c.value instanceof Uint8Array)throw at.UnknownError.fromCode(new at.HashTreeDecodeErrorCode("Invalid node tree"));let d=(0,Fs.flatten_forks)(c.value),f=new Map;return d.forEach(l=>{let u=Ds.Principal.from(l[1]).toText(),p=(0,Fs.lookup_path)(["public_key"],l[2]);if(p.status!==Fs.LookupPathStatus.Found)throw at.ProtocolError.fromCode(new at.LookupErrorCode("Public key not found",p.status));let h=p.value;if(h.byteLength!==44)throw at.ProtocolError.fromCode(new at.DerKeyLengthMismatchErrorCode(44,h.byteLength));f.set(u,h)}),{subnetId:Ds.Principal.fromUint8Array(new Uint8Array(o.subnet_id)).toText(),nodeKeys:f}};yt.fetchNodeKeys=yO;var _O=(t,e)=>{let r=e.toUint8Array();switch(t){case"time":return[(0,ir.utf8ToBytes)("time")];case"controllers":return[(0,ir.utf8ToBytes)("canister"),r,(0,ir.utf8ToBytes)("controllers")];case"module_hash":return[(0,ir.utf8ToBytes)("canister"),r,(0,ir.utf8ToBytes)("module_hash")];case"subnet":return[(0,ir.utf8ToBytes)("subnet")];case"candid":return[(0,ir.utf8ToBytes)("canister"),r,(0,ir.utf8ToBytes)("metadata"),(0,ir.utf8ToBytes)("candid:service")];default:if("key"in t&&"path"in t)if(typeof t.path=="string"||t.path instanceof Uint8Array){let n=t.path,s=typeof n=="string"?(0,ir.utf8ToBytes)(n):n;return[(0,ir.utf8ToBytes)("canister"),r,(0,ir.utf8ToBytes)("metadata"),s]}else return t.path}throw at.UnknownError.fromCode(new at.UnexpectedErrorCode(`Error while encoding your path for canister status. Please ensure that your path ${t} was formatted correctly.`))};yt.encodePath=_O;var bO=t=>Ih.decode(t).map(r=>Ds.Principal.fromUint8Array(r))});var Rb=Y(No=>{"use strict";Object.defineProperty(No,"__esModule",{value:!0});No.PrimeEdwardsPoint=void 0;No.edwards=Nb;No.eddsa=vb;No.twistedEdwards=OO;var Oe=Vr(),Oo=Va(),gO=un(),Us=BigInt(0),_t=BigInt(1),Sh=BigInt(2),xO=BigInt(8);function wO(t,e,r,n){let s=t.sqr(r),o=t.sqr(n),i=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(i,a)}function Nb(t,e={}){let r=(0,Oo._createCurveFields)("edwards",t,e,e.FpFnLE),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i}=o;(0,Oe._validateObject)(e,{},{uvRatio:"function"});let a=Sh<<BigInt(s.BYTES*8)-_t,c=b=>n.create(b),d=e.uvRatio||((b,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(b,y))}}catch{return{isValid:!1,value:Us}}});if(!wO(n,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(b,y,x=!1){let _=x?_t:Us;return(0,Oe.aInRange)("coordinate "+b,y,_,a),y}function l(b){if(!(b instanceof h))throw new Error("ExtendedPoint expected")}let u=(0,Oe.memoized)((b,y)=>{let{X:x,Y:_,Z:T}=b,N=b.is0();y==null&&(y=N?xO:n.inv(T));let v=c(x*y),R=c(_*y),A=n.mul(T,y);if(N)return{x:Us,y:_t};if(A!==_t)throw new Error("invZ was invalid");return{x:v,y:R}}),p=(0,Oe.memoized)(b=>{let{a:y,d:x}=o;if(b.is0())throw new Error("bad point: ZERO");let{X:_,Y:T,Z:N,T:v}=b,R=c(_*_),A=c(T*T),E=c(N*N),S=c(E*E),U=c(R*y),C=c(E*c(U+A)),g=c(S+c(x*c(R*A)));if(C!==g)throw new Error("bad point: equation left != right (1)");let w=c(_*T),O=c(N*v);if(w!==O)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(y,x,_,T){this.X=f("x",y),this.Y=f("y",x),this.Z=f("z",_,!0),this.T=f("t",T),Object.freeze(this)}static CURVE(){return o}static fromAffine(y){if(y instanceof h)throw new Error("extended point not allowed");let{x,y:_}=y||{};return f("x",x),f("y",_),new h(x,_,_t,c(x*_))}static fromBytes(y,x=!1){let _=n.BYTES,{a:T,d:N}=o;y=(0,Oe.copyBytes)((0,Oe._abytes2)(y,_,"point")),(0,Oe._abool2)(x,"zip215");let v=(0,Oe.copyBytes)(y),R=y[_-1];v[_-1]=R&-129;let A=(0,Oe.bytesToNumberLE)(v),E=x?a:n.ORDER;(0,Oe.aInRange)("point.y",A,Us,E);let S=c(A*A),U=c(S-_t),C=c(N*S-T),{isValid:g,value:w}=d(U,C);if(!g)throw new Error("bad point: invalid y coordinate");let O=(w&_t)===_t,P=(R&128)!==0;if(!x&&w===Us&&P)throw new Error("bad point: x=0 and x_0=1");return P!==O&&(w=c(-w)),h.fromAffine({x:w,y:A})}static fromHex(y,x=!1){return h.fromBytes((0,Oe.ensureBytes)("point",y),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,x=!0){return m.createCache(this,y),x||this.multiply(Sh),this}assertValidity(){p(this)}equals(y){l(y);let{X:x,Y:_,Z:T}=this,{X:N,Y:v,Z:R}=y,A=c(x*R),E=c(N*T),S=c(_*R),U=c(v*T);return A===E&&S===U}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=o,{X:x,Y:_,Z:T}=this,N=c(x*x),v=c(_*_),R=c(Sh*c(T*T)),A=c(y*N),E=x+_,S=c(c(E*E)-N-v),U=A+v,C=U-R,g=A-v,w=c(S*C),O=c(U*g),P=c(S*g),L=c(C*U);return new h(w,O,L,P)}add(y){l(y);let{a:x,d:_}=o,{X:T,Y:N,Z:v,T:R}=this,{X:A,Y:E,Z:S,T:U}=y,C=c(T*A),g=c(N*E),w=c(R*_*U),O=c(v*S),P=c((T+N)*(A+E)-C-g),L=O-w,I=O+w,B=c(g-x*C),F=c(P*L),V=c(I*B),q=c(P*B),H=c(L*I);return new h(F,V,H,q)}subtract(y){return this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:_}=m.cached(this,y,T=>(0,Oo.normalizeZ)(h,T));return(0,Oo.normalizeZ)(h,[x,_])[0]}multiplyUnsafe(y,x=h.ZERO){if(!s.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===Us?h.ZERO:this.is0()||y===_t?this:m.unsafe(this,y,_=>(0,Oo.normalizeZ)(h,_),x)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return m.unsafe(this,o.n).is0()}toAffine(y){return u(this,y)}clearCofactor(){return i===_t?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:x}=this.toAffine(),_=n.toBytes(x);return _[_.length-1]|=y&_t?128:0,_}toHex(){return(0,Oe.bytesToHex)(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(y){return(0,Oo.normalizeZ)(h,y)}static msm(y,x){return(0,Oo.pippenger)(h,s,y,x)}_setWindowSize(y){this.precompute(y)}toRawBytes(){return this.toBytes()}}h.BASE=new h(o.Gx,o.Gy,_t,c(o.Gx*o.Gy)),h.ZERO=new h(Us,_t,_t,Us),h.Fp=n,h.Fn=s;let m=new Oo.wNAF(h,s.BITS);return h.BASE.precompute(8),h}var Ah=class{constructor(e){this.ep=e}static fromBytes(e){(0,Oe.notImplemented)()}static fromHex(e){(0,Oe.notImplemented)()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return(0,Oe.bytesToHex)(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.init(this.ep.precompute(e,r))}toRawBytes(){return this.toBytes()}};No.PrimeEdwardsPoint=Ah;function vb(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');(0,Oe._validateObject)(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:s,Fp:o,Fn:i}=t,a=r.randomBytes||Oe.randomBytes,c=r.adjustScalarBytes||(E=>E),d=r.domain||((E,S,U)=>{if((0,Oe._abool2)(U,"phflag"),S.length||U)throw new Error("Contexts/pre-hash are not supported");return E});function f(E){return i.create((0,Oe.bytesToNumberLE)(E))}function l(E){let S=_.secretKey;E=(0,Oe.ensureBytes)("private key",E,S);let U=(0,Oe.ensureBytes)("hashed private key",e(E),2*S),C=c(U.slice(0,S)),g=U.slice(S,2*S),w=f(C);return{head:C,prefix:g,scalar:w}}function u(E){let{head:S,prefix:U,scalar:C}=l(E),g=s.multiply(C),w=g.toBytes();return{head:S,prefix:U,scalar:C,point:g,pointBytes:w}}function p(E){return u(E).pointBytes}function h(E=Uint8Array.of(),...S){let U=(0,Oe.concatBytes)(...S);return f(e(d(U,(0,Oe.ensureBytes)("context",E),!!n)))}function m(E,S,U={}){E=(0,Oe.ensureBytes)("message",E),n&&(E=n(E));let{prefix:C,scalar:g,pointBytes:w}=u(S),O=h(U.context,C,E),P=s.multiply(O).toBytes(),L=h(U.context,P,w,E),I=i.create(O+L*g);if(!i.isValid(I))throw new Error("sign failed: invalid s");let B=(0,Oe.concatBytes)(P,i.toBytes(I));return(0,Oe._abytes2)(B,_.signature,"result")}let b={zip215:!0};function y(E,S,U,C=b){let{context:g,zip215:w}=C,O=_.signature;E=(0,Oe.ensureBytes)("signature",E,O),S=(0,Oe.ensureBytes)("message",S),U=(0,Oe.ensureBytes)("publicKey",U,_.publicKey),w!==void 0&&(0,Oe._abool2)(w,"zip215"),n&&(S=n(S));let P=O/2,L=E.subarray(0,P),I=(0,Oe.bytesToNumberLE)(E.subarray(P,O)),B,F,V;try{B=t.fromBytes(U,w),F=t.fromBytes(L,w),V=s.multiplyUnsafe(I)}catch{return!1}if(!w&&B.isSmallOrder())return!1;let q=h(g,F.toBytes(),B.toBytes(),S);return F.add(B.multiplyUnsafe(q)).subtract(V).clearCofactor().is0()}let x=o.BYTES,_={secretKey:x,publicKey:x,signature:2*x,seed:x};function T(E=a(_.seed)){return(0,Oe._abytes2)(E,_.seed,"seed")}function N(E){let S=A.randomSecretKey(E);return{secretKey:S,publicKey:p(S)}}function v(E){return(0,Oe.isBytes)(E)&&E.length===i.BYTES}function R(E,S){try{return!!t.fromBytes(E,S)}catch{return!1}}let A={getExtendedPublicKey:u,randomSecretKey:T,isValidSecretKey:v,isValidPublicKey:R,toMontgomery(E){let{y:S}=t.fromBytes(E),U=_.publicKey,C=U===32;if(!C&&U!==57)throw new Error("only defined for 25519 and 448");let g=C?o.div(_t+S,_t-S):o.div(S-_t,S+_t);return o.toBytes(g)},toMontgomerySecret(E){let S=_.secretKey;(0,Oe._abytes2)(E,S);let U=e(E.subarray(0,S));return c(U).subarray(0,S)},randomPrivateKey:T,precompute(E=8,S=t.BASE){return S.precompute(E,!1)}};return Object.freeze({keygen:N,getPublicKey:p,sign:m,verify:y,utils:A,Point:t,lengths:_})}function EO(t){let e={a:t.a,d:t.d,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=(0,gO.Field)(e.n,t.nBitLength,!0),s={Fp:r,Fn:n,uvRatio:t.uvRatio},o={randomBytes:t.randomBytes,adjustScalarBytes:t.adjustScalarBytes,domain:t.domain,prehash:t.prehash,mapToCurve:t.mapToCurve};return{CURVE:e,curveOpts:s,hash:t.hash,eddsaOpts:o}}function TO(t,e){let r=e.Point;return Object.assign({},e,{ExtendedPoint:r,CURVE:t,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function OO(t){let{CURVE:e,curveOpts:r,hash:n,eddsaOpts:s}=EO(t),o=Nb(e,r),i=vb(o,n,s);return TO(t,i)}});var Ib=Y(Bh=>{"use strict";Object.defineProperty(Bh,"__esModule",{value:!0});Bh.montgomery=RO;var hn=Vr(),NO=un(),Ga=BigInt(0),vi=BigInt(1),nd=BigInt(2);function vO(t){return(0,hn._validateObject)(t,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...t})}function RO(t){let e=vO(t),{P:r,type:n,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=e,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=i||hn.randomBytes,d=a?255:448,f=a?32:56,l=BigInt(a?9:5),u=BigInt(a?121665:39081),p=a?nd**BigInt(254):nd**BigInt(447),h=a?BigInt(8)*nd**BigInt(251)-vi:BigInt(4)*nd**BigInt(445)-vi,m=p+h+vi,b=g=>(0,NO.mod)(g,r),y=x(l);function x(g){return(0,hn.numberToBytesLE)(b(g),f)}function _(g){let w=(0,hn.ensureBytes)("u coordinate",g,f);return a&&(w[31]&=127),b((0,hn.bytesToNumberLE)(w))}function T(g){return(0,hn.bytesToNumberLE)(s((0,hn.ensureBytes)("scalar",g,f)))}function N(g,w){let O=A(_(w),T(g));if(O===Ga)throw new Error("invalid private or public key received");return x(O)}function v(g){return N(g,y)}function R(g,w,O){let P=b(g*(w-O));return w=b(w-P),O=b(O+P),{x_2:w,x_3:O}}function A(g,w){(0,hn.aInRange)("u",g,Ga,r),(0,hn.aInRange)("scalar",w,p,m);let O=w,P=g,L=vi,I=Ga,B=g,F=vi,V=Ga;for(let H=BigInt(d-1);H>=Ga;H--){let z=O>>H&vi;V^=z,{x_2:L,x_3:B}=R(V,L,B),{x_2:I,x_3:F}=R(V,I,F),V=z;let G=L+I,ae=b(G*G),re=L-I,Ce=b(re*re),se=ae-Ce,me=B+F,It=B-F,jt=b(It*G),wr=b(me*re),An=jt+wr,gs=jt-wr;B=b(An*An),F=b(P*b(gs*gs)),L=b(ae*Ce),I=b(se*(ae+b(u*se)))}({x_2:L,x_3:B}=R(V,L,B)),{x_2:I,x_3:F}=R(V,I,F);let q=o(I);return b(L*q)}let E={secretKey:f,publicKey:f,seed:f},S=(g=c(f))=>((0,hn.abytes)(g,E.seed),g);function U(g){let w=S(g);return{secretKey:w,publicKey:v(w)}}return{keygen:U,getSharedSecret:(g,w)=>N(g,w),getPublicKey:g=>v(g),scalarMult:N,scalarMultBase:v,utils:{randomSecretKey:S,randomPrivateKey:S},GuBytes:y.slice(),lengths:E}}});var Mb=Y(oe=>{"use strict";Object.defineProperty(oe,"__esModule",{value:!0});oe.hash_to_ristretto255=oe.hashToRistretto255=oe.encodeToCurve=oe.hashToCurve=oe.RistrettoPoint=oe.edwardsToMontgomery=oe.ED25519_TORSION_SUBGROUP=oe.ristretto255_hasher=oe.ristretto255=oe.ed25519_hasher=oe.x25519=oe.ed25519ph=oe.ed25519ctx=oe.ed25519=void 0;oe.edwardsToMontgomeryPub=qb;oe.edwardsToMontgomeryPriv=kO;var Za=di(),od=ht(),IO=Va(),ad=Rb(),sd=ju(),Ae=un(),SO=Ib(),vo=Vr(),AO=BigInt(0),mn=BigInt(1),id=BigInt(2),Cb=BigInt(3),Pb=BigInt(5),Fh=BigInt(8),kn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),za={p:kn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Fh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Db(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=kn,a=t*t%o*t%o,c=(0,Ae.pow2)(a,id,o)*a%o,d=(0,Ae.pow2)(c,mn,o)*t%o,f=(0,Ae.pow2)(d,Pb,o)*d%o,l=(0,Ae.pow2)(f,e,o)*f%o,u=(0,Ae.pow2)(l,r,o)*l%o,p=(0,Ae.pow2)(u,n,o)*u%o,h=(0,Ae.pow2)(p,s,o)*p%o,m=(0,Ae.pow2)(h,s,o)*p%o,b=(0,Ae.pow2)(m,e,o)*f%o;return{pow_p_5_8:(0,Ae.pow2)(b,id,o)*t%o,b2:a}}function Fb(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Ch=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Uh(t,e){let r=kn,n=(0,Ae.mod)(e*e*e,r),s=(0,Ae.mod)(n*n*e,r),o=Db(t*s).pow_p_5_8,i=(0,Ae.mod)(t*n*o,r),a=(0,Ae.mod)(e*i*i,r),c=i,d=(0,Ae.mod)(i*Ch,r),f=a===t,l=a===(0,Ae.mod)(-t,r),u=a===(0,Ae.mod)(-t*Ch,r);return f&&(i=c),(l||u)&&(i=d),(0,Ae.isNegativeLE)(i,r)&&(i=(0,Ae.mod)(-i,r)),{isValid:f||l,value:i}}var K=(0,Ae.Field)(za.p,{isLE:!0}),Ub=(0,Ae.Field)(za.n,{isLE:!0}),Vh={...za,Fp:K,hash:Za.sha512,adjustScalarBytes:Fb,uvRatio:Uh};oe.ed25519=(0,ad.twistedEdwards)(Vh);function Vb(t,e,r){if(e.length>255)throw new Error("Context is too big");return(0,od.concatBytes)((0,od.utf8ToBytes)("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}oe.ed25519ctx=(0,ad.twistedEdwards)({...Vh,domain:Vb});oe.ed25519ph=(0,ad.twistedEdwards)(Object.assign({},Vh,{domain:Vb,prehash:Za.sha512}));oe.x25519=(()=>{let t=K.ORDER;return(0,SO.montgomery)({P:t,type:"x25519",powPminus2:e=>{let{pow_p_5_8:r,b2:n}=Db(e);return(0,Ae.mod)((0,Ae.pow2)(r,Cb,t)*n,t)},adjustScalarBytes:Fb})})();var BO=(kn+Cb)/Fh,CO=K.pow(id,BO),Sb=K.sqrt(K.neg(K.ONE));function PO(t){let e=(kn-Pb)/Fh,r=BigInt(486662),n=K.sqr(t);n=K.mul(n,id);let s=K.add(n,K.ONE),o=K.neg(r),i=K.sqr(s),a=K.mul(i,s),c=K.mul(n,r);c=K.mul(c,o),c=K.add(c,i),c=K.mul(c,o);let d=K.sqr(a);i=K.sqr(d),d=K.mul(d,a),d=K.mul(d,c),i=K.mul(i,d);let f=K.pow(i,e);f=K.mul(f,d);let l=K.mul(f,Sb);i=K.sqr(f),i=K.mul(i,a);let u=K.eql(i,c),p=K.cmov(l,f,u),h=K.mul(o,n),m=K.mul(f,t);m=K.mul(m,CO);let b=K.mul(m,Sb),y=K.mul(c,n);i=K.sqr(m),i=K.mul(i,a);let x=K.eql(i,y),_=K.cmov(b,m,x);i=K.sqr(p),i=K.mul(i,a);let T=K.eql(i,c),N=K.cmov(h,o,T),v=K.cmov(_,p,T),R=K.isOdd(v);return v=K.cmov(v,K.neg(v),T!==R),{xMn:N,xMd:s,yMn:v,yMd:mn}}var DO=(0,Ae.FpSqrtEven)(K,K.neg(BigInt(486664)));function FO(t){let{xMn:e,xMd:r,yMn:n,yMd:s}=PO(t),o=K.mul(e,s);o=K.mul(o,DO);let i=K.mul(r,n),a=K.sub(e,r),c=K.add(e,r),d=K.mul(i,c),f=K.eql(d,K.ZERO);o=K.cmov(o,K.ZERO,f),i=K.cmov(i,K.ONE,f),a=K.cmov(a,K.ONE,f),c=K.cmov(c,K.ONE,f);let[l,u]=(0,Ae.FpInvertBatch)(K,[i,c],!0);return{x:K.mul(o,l),y:K.mul(a,u)}}oe.ed25519_hasher=(0,sd.createHasher)(oe.ed25519.Point,t=>FO(t[0]),{DST:"edwards25519_XMD:SHA-512_ELL2_RO_",encodeDST:"edwards25519_XMD:SHA-512_ELL2_NU_",p:kn,m:1,k:128,expand:"xmd",hash:Za.sha512});var Ph=Ch,UO=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),VO=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),LO=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),qO=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ab=t=>Uh(mn,t),MO=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Dh=t=>oe.ed25519.Point.Fp.create((0,vo.bytesToNumberLE)(t)&MO);function Bb(t){let{d:e}=za,r=kn,n=y=>K.create(y),s=n(Ph*t*t),o=n((s+mn)*LO),i=BigInt(-1),a=n((i-e*s)*n(s+e)),{isValid:c,value:d}=Uh(o,a),f=n(d*t);(0,Ae.isNegativeLE)(f,r)||(f=n(-f)),c||(d=f),c||(i=s);let l=n(i*(s-mn)*qO-a),u=d*d,p=n((d+d)*a),h=n(l*UO),m=n(mn-u),b=n(mn+u);return new oe.ed25519.Point(n(p*b),n(m*h),n(h*b),n(p*m))}function Lb(t){(0,od.abytes)(t,64);let e=Dh(t.subarray(0,32)),r=Bb(e),n=Dh(t.subarray(32,64)),s=Bb(n);return new Mr(r.add(s))}var Mr=class t extends ad.PrimeEdwardsPoint{constructor(e){super(e)}static fromAffine(e){return new t(oe.ed25519.Point.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static hashToCurve(e){return Lb((0,vo.ensureBytes)("ristrettoHash",e,64))}static fromBytes(e){(0,od.abytes)(e,32);let{a:r,d:n}=za,s=kn,o=T=>K.create(T),i=Dh(e);if(!(0,vo.equalBytes)(K.toBytes(i),e)||(0,Ae.isNegativeLE)(i,s))throw new Error("invalid ristretto255 encoding 1");let a=o(i*i),c=o(mn+r*a),d=o(mn-r*a),f=o(c*c),l=o(d*d),u=o(r*n*f-l),{isValid:p,value:h}=Ab(o(u*l)),m=o(h*d),b=o(h*m*u),y=o((i+i)*m);(0,Ae.isNegativeLE)(y,s)&&(y=o(-y));let x=o(c*b),_=o(y*x);if(!p||(0,Ae.isNegativeLE)(_,s)||x===AO)throw new Error("invalid ristretto255 encoding 2");return new t(new oe.ed25519.Point(y,x,mn,_))}static fromHex(e){return t.fromBytes((0,vo.ensureBytes)("ristrettoHex",e,32))}static msm(e,r){return(0,IO.pippenger)(t,oe.ed25519.Point.Fn,e,r)}toBytes(){let{X:e,Y:r,Z:n,T:s}=this.ep,o=kn,i=b=>K.create(b),a=i(i(n+r)*i(n-r)),c=i(e*r),d=i(c*c),{value:f}=Ab(i(a*d)),l=i(f*a),u=i(f*c),p=i(l*u*s),h;if((0,Ae.isNegativeLE)(s*p,o)){let b=i(r*Ph),y=i(e*Ph);e=b,r=y,h=i(l*VO)}else h=u;(0,Ae.isNegativeLE)(e*p,o)&&(r=i(-r));let m=i((n-r)*h);return(0,Ae.isNegativeLE)(m,o)&&(m=i(-m)),K.toBytes(m)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:s,Y:o}=e.ep,i=d=>K.create(d),a=i(r*o)===i(n*s),c=i(n*o)===i(r*s);return a||c}is0(){return this.equals(t.ZERO)}};Mr.BASE=new Mr(oe.ed25519.Point.BASE);Mr.ZERO=new Mr(oe.ed25519.Point.ZERO);Mr.Fp=K;Mr.Fn=Ub;oe.ristretto255={Point:Mr};oe.ristretto255_hasher={hashToCurve(t,e){let r=e?.DST||"ristretto255_XMD:SHA-512_R255MAP_RO_",n=(0,sd.expand_message_xmd)(t,r,64,Za.sha512);return Lb(n)},hashToScalar(t,e={DST:sd._DST_scalar}){let r=(0,sd.expand_message_xmd)(t,e.DST,64,Za.sha512);return Ub.create((0,vo.bytesToNumberLE)(r))}};oe.ED25519_TORSION_SUBGROUP=["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"];function qb(t){return oe.ed25519.utils.toMontgomery((0,vo.ensureBytes)("pub",t))}oe.edwardsToMontgomery=qb;function kO(t){return oe.ed25519.utils.toMontgomerySecret((0,vo.ensureBytes)("pub",t))}oe.RistrettoPoint=Mr;oe.hashToCurve=oe.ed25519_hasher.hashToCurve;oe.encodeToCurve=oe.ed25519_hasher.encodeToCurve;oe.hashToRistretto255=oe.ristretto255_hasher.hashToCurve;oe.hash_to_ristretto255=oe.ristretto255_hasher.hashToCurve});var Hb=Y(cd=>{"use strict";var kb,jb;Object.defineProperty(cd,"__esModule",{value:!0});cd.ExpirableMap=void 0;var Lh=class{static{kb=Symbol.iterator,jb=Symbol.toStringTag}#e;#t;constructor(e={}){this[kb]=this.entries.bind(this),this[jb]="ExpirableMap";let{source:r=[],expirationTime:n=600*1e3}=e,s=Date.now();this.#e=new Map([...r].map(([o,i])=>[o,{value:i,timestamp:s}])),this.#t=n}prune(){let e=Date.now();for(let[r,n]of this.#e.entries())e-n.timestamp>this.#t&&this.#e.delete(r);return this}set(e,r){this.prune();let n={value:r,timestamp:Date.now()};return this.#e.set(e,n),this}get(e){let r=this.#e.get(e);if(r!==void 0){if(Date.now()-r.timestamp>this.#t){this.#e.delete(e);return}return r.value}}clear(){this.#e.clear()}entries(){let e=this.#e.entries();return function*(){for(let[n,s]of e)yield[n,s.value]}()}values(){let e=this.#e.values();return function*(){for(let n of e)yield n.value}()}keys(){return this.#e.keys()}forEach(e,r){for(let[n,s]of this.#e.entries())e.call(r,s.value,n,this)}has(e){return this.#e.has(e)}delete(e){return this.#e.delete(e)}get size(){return this.#e.size}};cd.ExpirableMap=Lh});var qh=Y(Pe=>{"use strict";Object.defineProperty(Pe,"__esModule",{value:!0});Pe.unwrapDER=Pe.BLS12_381_G2_OID=Pe.SECP256K1_OID=Pe.ED25519_OID=Pe.DER_COSE_OID=Pe.decodeLen=Pe.decodeLenBytes=Pe.encodeLen=Pe.encodeLenBytes=void 0;Pe.wrapDER=ZO;var Ft=yr(),jO=_i(),HO=t=>{if(t<=127)return 1;if(t<=255)return 2;if(t<=65535)return 3;if(t<=16777215)return 4;throw Ft.InputError.fromCode(new Ft.DerEncodeErrorCode("Length too long (> 4 bytes)"))};Pe.encodeLenBytes=HO;var $O=(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 Ft.InputError.fromCode(new Ft.DerEncodeErrorCode("Length too long (> 4 bytes)"))};Pe.encodeLen=$O;var KO=(t,e)=>{if(t[e]<128)return 1;if(t[e]===128)throw Ft.InputError.fromCode(new Ft.DerDecodeErrorCode("Invalid length 0"));if(t[e]===129)return 2;if(t[e]===130)return 3;if(t[e]===131)return 4;throw Ft.InputError.fromCode(new Ft.DerDecodeErrorCode("Length too long (> 4 bytes)"))};Pe.decodeLenBytes=KO;var GO=(t,e)=>{let r=(0,Pe.decodeLenBytes)(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 Ft.InputError.fromCode(new Ft.DerDecodeErrorCode("Length too long (> 4 bytes)"))};Pe.decodeLen=GO;Pe.DER_COSE_OID=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]);Pe.ED25519_OID=Uint8Array.from([48,5,6,3,43,101,112]);Pe.SECP256K1_OID=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);Pe.BLS12_381_G2_OID=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 ZO(t,e){let r=2+(0,Pe.encodeLenBytes)(t.byteLength+1),n=e.byteLength+r+t.byteLength,s=0,o=new Uint8Array(1+(0,Pe.encodeLenBytes)(n)+n);return o[s++]=48,s+=(0,Pe.encodeLen)(o,s,n),o.set(e,s),s+=e.byteLength,o[s++]=3,s+=(0,Pe.encodeLen)(o,s,t.byteLength+1),o[s++]=0,o.set(new Uint8Array(t),s),o}var zO=(t,e)=>{let r=0,n=(a,c)=>{if(s[r++]!==a)throw Ft.InputError.fromCode(new Ft.DerDecodeErrorCode(`Expected ${c} at offset ${r}`))},s=new Uint8Array(t);if(n(48,"sequence"),r+=(0,Pe.decodeLenBytes)(s,r),!(0,jO.uint8Equals)(s.slice(r,r+e.byteLength),e))throw Ft.InputError.fromCode(new Ft.DerDecodeErrorCode("Not the expected OID."));r+=e.byteLength,n(3,"bit string");let o=(0,Pe.decodeLen)(s,r)-1;r+=(0,Pe.decodeLenBytes)(s,r),n(0,"0 padding");let i=s.slice(r);if(o!==i.length)throw Ft.InputError.fromCode(new Ft.DerDecodeLengthMismatchErrorCode(o,i.length));return i};Pe.unwrapDER=zO});var kh=Y(ld=>{"use strict";Object.defineProperty(ld,"__esModule",{value:!0});ld.Ed25519PublicKey=void 0;var ud=qh(),dd=yr(),Mh=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(0,ud.wrapDER)(e,ud.ED25519_OID)}static derDecode(e){let r=(0,ud.unwrapDER)(e,ud.ED25519_OID);if(r.length!==this.RAW_KEY_LENGTH)throw dd.InputError.fromCode(new dd.DerDecodeErrorCode("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 dd.InputError.fromCode(new dd.DerDecodeErrorCode("An Ed25519 public key must be exactly 32 bytes long"));this.#e=e,this.#t=t.derEncode(e)}toDer(){return this.derKey}toRaw(){return this.rawKey}};ld.Ed25519PublicKey=Mh});var Hh=Y(Ri=>{"use strict";Object.defineProperty(Ri,"__esModule",{value:!0});Ri.ObservableLog=Ri.Observable=void 0;var fd=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))}};Ri.Observable=fd;var jh=class extends fd{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)}};Ri.ObservableLog=jh});var Wb=Y(Wa=>{"use strict";Object.defineProperty(Wa,"__esModule",{value:!0});Wa.ExponentialBackoff=void 0;Wa.exponentialBackoff=YO;var $b=.5,Kb=1.5,Gb=500,Zb=6e4,zb=9e5,Yb=10,Ya=class t{#e;#t;#r;#c;#i;#d;#n;#s;#a=0;static{this.default={initialInterval:Gb,randomizationFactor:$b,multiplier:Kb,maxInterval:Zb,maxElapsedTime:zb,maxIterations:Yb,date:Date}}constructor(e=t.default){let{initialInterval:r=Gb,randomizationFactor:n=$b,multiplier:s=Kb,maxInterval:o=Zb,maxElapsedTime:i=zb,maxIterations:a=Yb,date:c=Date}=e;this.#e=r,this.#t=n,this.#r=s,this.#c=o,this.#s=c,this.#i=c.now(),this.#d=i,this.#n=a}get ellapsedTimeInMsec(){return this.#s.now()-this.#i}get currentInterval(){return this.#e}get count(){return this.#a}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.#c),this.#a++,this.#e}next(){return this.ellapsedTimeInMsec>=this.#d||this.#a>=this.#n?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};Wa.ExponentialBackoff=Ya;function*YO(t=Ya.default){let e=new Ya(t),r=e.next();for(;r;)yield r,r=e.next()}});var hd=Y($e=>{"use strict";var ng=$e&&$e.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),WO=$e&&$e.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),XO=$e&&$e.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[n.length]=s);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),s=0;s<n.length;s++)n[s]!=="default"&&ng(r,e,n[s]);return WO(r,e),r}})(),JO=$e&&$e.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&ng(e,t,r)};Object.defineProperty($e,"__esModule",{value:!0});$e.HttpAgent=$e.MANAGEMENT_CANISTER_ID=$e.IC_ROOT_KEY=$e.RequestStatusResponseStatus=$e.makeNonce=void 0;$e.calculateIngressExpiry=pd;var jn=Ur(),Z=yr(),Xb=jp(),Vs=XO(Ca()),Xa=Iu(),Jb=sf(),Ii=Uu(),Hn=bi(),Qb=rd(),eg=Ni(),QO=Mb(),e4=Hb(),t4=kh(),r4=Hh(),n4=Wb(),s4=Ju(),tg=ht(),$h=_i(),o4=Su();JO(Uu(),$e);var i4=bi();Object.defineProperty($e,"makeNonce",{enumerable:!0,get:function(){return i4.makeNonce}});var rg;(function(t){t.Received="received",t.Processing="processing",t.Replied="replied",t.Rejected="rejected",t.Unknown="unknown",t.Done="done"})(rg||($e.RequestStatusResponseStatus=rg={}));var Gh=60*1e3,a4=1e6,c4=0;$e.IC_ROOT_KEY="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae";$e.MANAGEMENT_CANISTER_ID="aaaaa-aa";var u4="ic0.app",d4=".ic0.app",l4="icp0.io",f4=".icp0.io",p4="icp-api.io",h4=".icp-api.io",Kh=200,m4=202,y4=404;function _4(){let t;if(typeof window<"u")if(window.fetch)t=window.fetch.bind(window);else throw Z.ExternalError.fromCode(new Z.HttpDefaultFetchErrorCode("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present."));else if(typeof global<"u")if(global.fetch)t=global.fetch.bind(global);else throw Z.ExternalError.fromCode(new Z.HttpDefaultFetchErrorCode("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available."));else typeof self<"u"&&self.fetch&&(t=self.fetch.bind(self));if(t)return t;throw Z.ExternalError.fromCode(new Z.HttpDefaultFetchErrorCode("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context."))}function b4(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"],s=typeof window<"u"?window.location:void 0,o=s?.hostname,i;o&&typeof o=="string"&&(n.some(a=>o.endsWith(a))?i=o:i=r.find(a=>o.endsWith(a))),s&&i?e=new URL(`${s.protocol}//${i}${s.port?":"+s.port:""}`):e=new URL("https://icp-api.io")}return e.toString()}var Zh=class t{#e;#t;#r;#c;#i;#d;#n;#s;#a;#g;#o;#l;#f;#u;get#T(){return this.#u*Gh}#p;#h;#m;#y;constructor(e={}){this.#e=null,this.#t=!1,this.#r=c4,this.#c=!1,this.#i=null,this.#d=!1,this._isAgent=!0,this.config={},this.log=new r4.ObservableLog,this.#p=[],this.#h=[],this.#m=new e4.ExpirableMap({expirationTime:5*Gh}),this.#y=!0,this.#w=(s,o)=>{if(this.#y===!1)return s;let{status:i,signatures:a=[],requestId:c}=s;for(let d of a){let{timestamp:f,identity:l}=d,u=jn.Principal.fromUint8Array(l).toText(),p;if(i===Jb.QueryResponseStatus.Replied){let{reply:x}=s;p=(0,Xa.hashOfMap)({status:i,reply:x,timestamp:BigInt(f),request_id:c})}else if(i===Jb.QueryResponseStatus.Rejected){let{reject_code:x,reject_message:_,error_code:T}=s;p=(0,Xa.hashOfMap)({status:i,reject_code:x,reject_message:_,error_code:T,timestamp:BigInt(f),request_id:c})}else throw Z.UnknownError.fromCode(new Z.UnexpectedErrorCode(`Unknown status: ${i}`));let h=(0,tg.concatBytes)(o4.IC_RESPONSE_DOMAIN_SEPARATOR,p),m=o.nodeKeys.get(u);if(!m)throw Z.ProtocolError.fromCode(new Z.MalformedPublicKeyErrorCode);let b=t4.Ed25519PublicKey.fromDer(m).rawKey;if(QO.ed25519.verify(d.signature,h,b))return s;throw Z.TrustError.fromCode(new Z.QuerySignatureVerificationFailedErrorCode(u))}return s},this.config=e,this.#s=e.fetch||_4()||fetch.bind(global),this.#a=e.fetchOptions,this.#g=e.callOptions,this.#t=e.shouldFetchRootKey??!1,this.#d=e.shouldSyncTime??!1,e.rootKey?this.rootKey=e.rootKey:this.#t?this.rootKey=null:this.rootKey=(0,tg.hexToBytes)($e.IC_ROOT_KEY);let r=b4(e.host);this.host=new URL(r),e.verifyQuerySignatures!==void 0&&(this.#y=e.verifyQuerySignatures),this.#l=e.retryTimes??3;let n=()=>new n4.ExponentialBackoff({maxIterations:this.#l});if(this.#f=e.backoffStrategy||n,this.host.hostname.endsWith(d4)?this.host.hostname=u4:this.host.hostname.endsWith(f4)?this.host.hostname=l4:this.host.hostname.endsWith(h4)&&(this.host.hostname=p4),e.credentials){let{name:s,password:o}=e.credentials;this.#o=`${s}${o?":"+o:""}`}if(this.#n=Promise.resolve(e.identity||new Xb.AnonymousIdentity),e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes>5)throw Z.InputError.fromCode(new Z.IngressExpiryInvalidErrorCode("The maximum ingress expiry time is 5 minutes.",e.ingressExpiryInMinutes));if(e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes<=0)throw Z.InputError.fromCode(new Z.IngressExpiryInvalidErrorCode("Ingress expiry time must be greater than 0.",e.ingressExpiryInMinutes));this.#u=e.ingressExpiryInMinutes||5,this.addTransform("update",(0,Ii.makeNonceTransform)(Hn.makeNonce)),e.useQueryNonces&&this.addTransform("query",(0,Ii.makeNonceTransform)(Hn.makeNonce)),e.logToConsole&&this.log.subscribe(s=>{s.level==="error"?console.error(s.message):s.level==="warn"?console.warn(s.message):console.log(s.message)})}static createSync(e={}){return new this({...e})}static async create(e={}){let r=t.createSync(e);return await r.#b(),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 Z.InputError.fromCode(new Z.CreateHttpAgentErrorCode)}}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 s=this.#h.findIndex(o=>(o.priority||0)<n);this.#h.splice(s>=0?s:this.#h.length,0,Object.assign(r,{priority:n}))}else if(e==="query"){let s=this.#p.findIndex(o=>(o.priority||0)<n);this.#p.splice(s>=0?s:this.#p.length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!this.#n)throw Z.ExternalError.fromCode(new Z.IdentityInvalidErrorCode);return(await this.#n).getPrincipal()}async call(e,r,n){let s=r.callSync??!0,o=await(n??this.#n);if(!o)throw Z.ExternalError.fromCode(new Z.IdentityInvalidErrorCode);let i=jn.Principal.from(e),a=r.effectiveCanisterId?jn.Principal.from(r.effectiveCanisterId):i;await this.#b(a);let c=o.getPrincipal(),d=pd(this.#u,this.#r),f={request_type:Hn.SubmitRequestType.Call,canister_id:i,method_name:r.methodName,arg:r.arg,sender:c,ingress_expiry:d},l=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#o?{Authorization:"Basic "+btoa(this.#o)}:{}}},endpoint:Hn.Endpoint.Call,body:f}),u;r?.nonce?u=p(r.nonce):l.body.nonce?u=p(l.body.nonce):u=void 0,f.nonce=u;function p(y){return Object.assign(y,{__nonce__:void 0})}l=await o.transformRequest(l);let h=Vs.encode(l.body),m=this.#f(),b=(0,Xa.requestIdOf)(f);try{let _=s?()=>(this.log.print(`fetching "/api/v3/canister/${a.toText()}/call" with request:`,l),this.#s(""+new URL(`/api/v3/canister/${a.toText()}/call`,this.host),{...this.#g,...l.request,body:h})):()=>(this.log.print(`fetching "/api/v2/canister/${a.toText()}/call" with request:`,l),this.#s(""+new URL(`/api/v2/canister/${a.toText()}/call`,this.host),{...this.#g,...l.request,body:h})),{responseBodyBytes:T,...N}=await this.#_({requestFn:_,backoff:m,tries:0}),v=T.byteLength>0?Vs.decode(T):null;return{requestId:b,response:{...N,body:v},requestDetails:f}}catch(y){let x;if(y instanceof Z.AgentError){if(y.hasCode(Z.HttpV3ApiNotSupportedErrorCode))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(e,{...r,callSync:!1},n);if(y.hasCode(Z.IngressExpiryInvalidErrorCode)&&!this.#c)return await this.syncTime(i),this.call(i,r,n);y.code.requestContext={requestId:b,senderPubKey:l.body.sender_pubkey,senderSignature:l.body.sender_sig,ingressExpiry:l.body.content.ingress_expiry},x=y}else x=Z.UnknownError.fromCode(new Z.UnexpectedErrorCode(y));throw this.log.error(`Error while making call: ${x.message}`,x),x}}async#x(e){let{ecid:r,transformedRequest:n,body:s,requestId:o,backoff:i,tries:a}=e,c=a===0?0:i.next();if(this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with tries:`,{tries:a,backoff:i,delay:c}),c===null)throw Z.UnknownError.fromCode(new Z.TimeoutWaitingForResponseErrorCode(`Backoff strategy exhausted after ${a} attempts.`,o));c>0&&await new Promise(p=>setTimeout(p,c));let d;try{this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with request:`,n);let p=await this.#s(""+new URL(`/api/v2/canister/${r.toString()}/query`,this.host),{...this.#a,...n.request,body:s});if(p.status===Kh)d={...Vs.decode((0,$h.uint8FromBufLike)(await p.arrayBuffer())),httpDetails:{ok:p.ok,status:p.status,statusText:p.statusText,headers:(0,Ii.httpHeadersTransform)(p.headers)},requestId:o};else throw Z.ProtocolError.fromCode(new Z.HttpErrorCode(p.status,p.statusText,(0,Ii.httpHeadersTransform)(p.headers),await p.text()))}catch(p){if(a<this.#l)return this.log.warn(`Caught exception while attempting to make query:
|
|
68
66
|
${p}
|
|
69
|
-
Retrying request.`),await this.#_({requestFn:r,backoff:n,tries:o+1});throw z.TransportError.fromCode(new z.HttpFetchErrorCode(p))}let c=(0,di.httpHeadersTransform)(i.headers);if(i.status===dh||i.status===g4)return{ok:i.ok,status:i.status,statusText:i.statusText,responseBodyBytes:a,headers:c};let d=await i.text();if(i.status===x4&&i.url.includes("api/v3"))throw z.ProtocolError.fromCode(new z.HttpV3ApiNotSupportedErrorCode);if(d.startsWith("Invalid request expiry: "))throw z.InputError.fromCode(new z.IngressExpiryInvalidErrorCode(d,this.#u));if(o<this.#l)return await this.#_({requestFn:r,backoff:n,tries:o+1});throw z.ProtocolError.fromCode(new z.HttpErrorCode(i.status,i.statusText,c,d))}async query(e,r,n){let o=this.#f(),s=r.effectiveCanisterId?Dn.Principal.from(r.effectiveCanisterId):Dn.Principal.from(e);await this.#b(s),this.log.print(`ecid ${s.toString()}`),this.log.print(`canisterId ${e.toString()}`);let i,a=await(n??this.#n);if(!a)throw z.ExternalError.fromCode(new z.IdentityInvalidErrorCode);let c=Dn.Principal.from(e),d=a.getPrincipal(),p=Hu(this.#u,this.#r),l={request_type:Fn.ReadRequestType.Query,canister_id:c,method_name:r.methodName,arg:r.arg,sender:d,ingress_expiry:p},u=(0,Aa.requestIdOf)(l);i=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#s?{Authorization:"Basic "+btoa(this.#s)}:{}}},endpoint:Fn.Endpoint.Query,body:l}),i=await a.transformRequest(i);let f=To.encode(i.body),h={canister:c.toText(),ecid:s,transformedRequest:i,body:f,requestId:u,backoff:o,tries:0},m=async()=>{let y=await this.#x(h);return{requestDetails:l,...y}},b=async()=>{let y=this.#m.get(s.toString());if(y)return y;await this.fetchSubnetKeys(s.toString());let x=this.#m.get(s.toString());if(!x)throw z.TrustError.fromCode(new z.MissingSignatureErrorCode);return x};try{if(!this.#y)return await m();let[y,x]=await Promise.all([m(),b()]);try{return this.#w(y,x)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),this.#m.delete(s.toString());let _=await b();return this.#w(y,_)}}catch(y){let x;throw y instanceof z.AgentError?(y.code.requestContext={requestId:u,senderPubKey:i.body.sender_pubkey,senderSignature:i.body.sender_sig,ingressExpiry:i.body.content.ingress_expiry},x=y):x=z.UnknownError.fromCode(new z.UnexpectedErrorCode(y)),this.log.error(`Error while making query: ${x.message}`,x),x}}#w;async createReadStateRequest(e,r){await this.#b();let n=await(r??this.#n);if(!n)throw z.ExternalError.fromCode(new z.IdentityInvalidErrorCode);let o=n.getPrincipal(),s=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#s?{Authorization:"Basic "+btoa(this.#s)}:{}}},endpoint:Fn.Endpoint.ReadState,body:{request_type:Fn.ReadRequestType.ReadState,paths:e.paths,sender:o,ingress_expiry:Hu(this.#u,this.#r)}});return n.transformRequest(s)}async readState(e,r,n,o){await this.#E();let s=Dn.Principal.from(e);function i(p){for(let l of p.paths){let[u,f]=l,h=new TextEncoder().encode("request_status");if((0,uh.uint8Equals)(u,h))return f}}let a,c;if(o)a=o,c=(0,Aa.requestIdOf)(a);else{c=i(r);let p=await this.#n;if(!p)throw z.ExternalError.fromCode(new z.IdentityInvalidErrorCode);a=await this.createReadStateRequest(r,p)}this.log.print(`fetching "/api/v2/canister/${s}/read_state" with request:`,a);let d=this.#f();try{let{responseBodyBytes:p}=await this.#_({requestFn:()=>this.#o(""+new URL(`/api/v2/canister/${s.toString()}/read_state`,this.host),{...this.#a,...a.request,body:To.encode(a.body)}),backoff:d,tries:0}),l=To.decode(p);return this.log.print("Read state response:",l),l}catch(p){let l;throw p instanceof z.AgentError?(p.code.requestContext={requestId:c,senderPubKey:a.body.sender_pubkey,senderSignature:a.body.sender_sig,ingressExpiry:a.body.content.ingress_expiry},l=p):l=z.UnknownError.fromCode(new z.UnexpectedErrorCode(p)),this.log.error(`Error while making read state: ${l.message}`,l),l}}parseTimeFromResponse(e){let r;if(e.certificate){let n=To.decode(e.certificate);if(n&&"tree"in n)r=n.tree;else throw z.ProtocolError.fromCode(new z.HashTreeDecodeErrorCode("Could not decode time from response"));let o=(0,hb.lookup_path)(["time"],r);if(o.status!==hb.LookupPathStatus.Found)throw z.ProtocolError.fromCode(new z.LookupErrorCode("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 z.ProtocolError.fromCode(new z.MalformedLookupFoundValueErrorCode("Time was not in its expected format."));let s=(0,c4.decodeTime)(o.value);return this.log.print("Time from response:",s),this.log.print("Time from response in milliseconds:",s.getTime()),s.getTime()}else this.log.warn("No certificate found in response");return 0}async syncTime(e){this.#i=this.#i??(async()=>{await this.#E();let r=Date.now();try{e||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let n=e??Dn.Principal.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),o=t.createSync({identity:new lb.AnonymousIdentity,host:this.host.toString(),fetch:this.#o,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),i=(await Promise.all(Array(3).fill(null).map(async()=>{let c=(await(0,pb.request)({canisterId:n,agent:o,paths:["time"],disableCertificateTimeVerification:!0})).get("time");if(c instanceof Date)return c.getTime()},[]))).reduce((a,c)=>typeof c=="number"&&c>a?c:a,0);i>0&&(this.#r=i-r,this.#c=!0,this.log.notify({message:`Syncing time: offset of ${this.#r}`,level:"info"}))}catch(n){let o=n instanceof z.AgentError?n:z.UnknownError.fromCode(new z.UnexpectedErrorCode(n));throw this.log.error("Caught exception while attempting to sync time",o),o}})(),await this.#i.finally(()=>{this.#i=null})}async status(){let e=this.#s?{Authorization:"Basic "+btoa(this.#s)}:{};this.log.print('fetching "/api/v2/status"');let r=this.#f(),{responseBodyBytes:n}=await this.#_({backoff:r,requestFn:()=>this.#o(""+new URL("/api/v2/status",this.host),{headers:e,...this.#a}),tries:0});return To.decode(n)}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#b(e){await Promise.all([this.#E(),this.#O(e)])}async#E(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#t)await this.fetchRootKey();else throw z.ExternalError.fromCode(new z.MissingRootKeyErrorCode(this.#t))}async#O(e){this.#d&&!this.hasSyncedTime()&&await this.syncTime(e)}invalidateIdentity(){this.#n=null}replaceIdentity(e){this.#n=Promise.resolve(e)}async fetchSubnetKeys(e){let r=Dn.Principal.from(e);await this.#b(r);let o=(await(0,pb.request)({canisterId:r,paths:["subnet"],agent:this})).get("subnet");if(o&&typeof o=="object"&&"nodeKeys"in o)return this.#m.set(r.toText(),o),o}_transform(e){let r=Promise.resolve(e);if(e.endpoint===Fn.Endpoint.Call)for(let n of this.#h)r=r.then(o=>n(o).then(s=>s||o));else for(let n of this.#p)r=r.then(o=>n(o).then(s=>s||o));return r}getTimeDiffMsecs(){return this.#r}hasSyncedTime(){return this.#c}};$e.HttpAgent=fh;function Hu(t,e){let r=t*lh;return di.Expiry.fromDeltaInMilliseconds(r,e)}});var fa=Z(Oo=>{"use strict";var T4=Oo&&Oo.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),bb=Oo&&Oo.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&T4(e,t,r)};Object.defineProperty(Oo,"__esModule",{value:!0});bb(Ol(),Oo);bb($u(),Oo)});var Gu=Z(an=>{"use strict";Object.defineProperty(an,"__esModule",{value:!0});an.defaultStrategy=N4;an.once=gb;an.conditionalDelay=xb;an.maxAttempts=v4;an.throttle=I4;an.timeout=wb;an.backoff=Eb;an.chain=Tb;var Ku=sr(),O4=300*1e3;function N4(){return Tb(xb(gb(),1e3),Eb(1e3,1.2),wb(O4))}function gb(){let t=!0;return async()=>t?(t=!1,!0):!1}function xb(t,e){return async(r,n,o)=>{if(await t(r,n,o))return new Promise(s=>setTimeout(s,e))}}function v4(t){let e=t;return async(r,n,o)=>{if(--e<=0)throw Ku.ProtocolError.fromCode(new Ku.TimeoutWaitingForResponseErrorCode(`Failed to retrieve a reply for request after ${t} attempts`,n,o))}}function I4(t){return()=>new Promise(e=>setTimeout(e,t))}function wb(t){let e=Date.now()+t;return async(r,n,o)=>{if(Date.now()>e)throw Ku.ProtocolError.fromCode(new Ku.TimeoutWaitingForResponseErrorCode(`Request timed out after ${t} msec`,n,o))}}function Eb(t,e){let r=t;return()=>new Promise(n=>setTimeout(()=>{r*=e,n()},r))}function Tb(...t){return async(e,r,n)=>{for(let o of t)await o(e,r,n)}}});var zu=Z(At=>{"use strict";var R4=At&&At.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),S4=At&&At.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),A4=At&&At.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),o=0;o<n.length;o++)n[o]!=="default"&&R4(r,e,n[o]);return S4(r,e),r}})();Object.defineProperty(At,"__esModule",{value:!0});At.DEFAULT_POLLING_OPTIONS=At.defaultStrategy=At.strategy=void 0;At.pollForResponse=Ib;At.constructRequest=Rb;var li=ai(),Vn=sr();At.strategy=A4(Gu());var B4=Gu(),C4=ei(),cs=fa(),Ob=dt(),P4=Gu();Object.defineProperty(At,"defaultStrategy",{enumerable:!0,get:function(){return P4.defaultStrategy}});At.DEFAULT_POLLING_OPTIONS={preSignReadStateRequest:!1};function vb(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function ph(t,e){return t!==null&&typeof t=="object"&&vb(t,e)}function D4(t,e){return vb(t,e)&&typeof t[e]=="function"}function Nb(t){return ph(t,"body")&&ph(t.body,"content")&&t.body.content.request_type===C4.ReadRequestType.ReadState&&ph(t.body.content,"ingress_expiry")&&typeof t.body.content.ingress_expiry=="object"&&t.body.content.ingress_expiry!==null&&D4(t.body.content.ingress_expiry,"toHash")}async function Ib(t,e,r,n={}){let o=[(0,Ob.utf8ToBytes)("request_status"),r],s,i;if(n.preSignReadStateRequest??!1?(i=await Rb({paths:[o],agent:t,pollingOptions:n}),s=await t.readState(e,{paths:[o]},void 0,i)):s=await t.readState(e,{paths:[o]}),t.rootKey==null)throw Vn.ExternalError.fromCode(new Vn.MissingRootKeyErrorCode);let c=await li.Certificate.create({certificate:s.certificate,rootKey:t.rootKey,canisterId:e,blsVerify:n.blsVerify,agent:t}),d=(0,li.lookupResultToBuffer)(c.lookup_path([...o,(0,Ob.utf8ToBytes)("status")])),p;switch(typeof d>"u"?p=cs.RequestStatusResponseStatus.Unknown:p=new TextDecoder().decode(d),p){case cs.RequestStatusResponseStatus.Replied:return{reply:(0,li.lookupResultToBuffer)(c.lookup_path([...o,"reply"])),certificate:c};case cs.RequestStatusResponseStatus.Received:case cs.RequestStatusResponseStatus.Unknown:case cs.RequestStatusResponseStatus.Processing:{let l=n.strategy??(0,B4.defaultStrategy)();return await l(e,r,p),Ib(t,e,r,{...n,strategy:l,request:i})}case cs.RequestStatusResponseStatus.Rejected:{let l=new Uint8Array((0,li.lookupResultToBuffer)(c.lookup_path([...o,"reject_code"])))[0],u=new TextDecoder().decode((0,li.lookupResultToBuffer)(c.lookup_path([...o,"reject_message"]))),f=(0,li.lookupResultToBuffer)(c.lookup_path([...o,"error_code"])),h=f?new TextDecoder().decode(f):void 0;throw Vn.RejectError.fromCode(new Vn.CertifiedRejectErrorCode(r,l,u,h))}case cs.RequestStatusResponseStatus.Done:throw Vn.UnknownError.fromCode(new Vn.RequestStatusDoneNoReplyErrorCode(r))}throw Vn.UNREACHABLE_ERROR}async function Rb(t){let{paths:e,agent:r,pollingOptions:n}=t;if(n.request&&Nb(n.request))return n.request;let o=await r.createReadStateRequest?.({paths:e},void 0);if(!Nb(o))throw Vn.InputError.fromCode(new Vn.InvalidReadStateRequestErrorCode(o));return o}});var mh=Z(ar=>{"use strict";Object.defineProperty(ar,"__esModule",{value:!0});ar.ACTOR_METHOD_WITH_CERTIFICATE=ar.ACTOR_METHOD_WITH_HTTP_DETAILS=ar.Actor=void 0;var Zu=fa(),er=sr(),Yu=ca(),Ab=zu(),Ba=Ir(),fi=ai(),Sb=$u(),F4=dt(),_r=Symbol.for("ic-agent-metadata"),hh=class t{static agentOf(e){return e[_r].config.agent}static interfaceOf(e){return e[_r].service}static canisterIdOf(e){return Ba.Principal.from(e[_r].config.canisterId)}static createActorClass(e,r){let n=e({IDL:Yu.IDL});class o extends t{constructor(i){if(!i.canisterId)throw er.InputError.fromCode(new er.MissingCanisterIdErrorCode(i.canisterId));let a=typeof i.canisterId=="string"?Ba.Principal.fromText(i.canisterId):i.canisterId;super({config:{...Bb,...i,canisterId:a},service:n});for(let[c,d]of n._fields)r?.httpDetails&&d.annotations.push(ar.ACTOR_METHOD_WITH_HTTP_DETAILS),r?.certificate&&d.annotations.push(ar.ACTOR_METHOD_WITH_CERTIFICATE),this[c]=V4(this,c,d,i.blsVerify)}}return o}static createActor(e,r){if(!r.canisterId)throw er.InputError.fromCode(new er.MissingCanisterIdErrorCode(r.canisterId));return new(this.createActorClass(e))(r)}static createActorWithHttpDetails(e,r){return new(this.createActorClass(e,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(e,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(e,n))(r)}constructor(e){this[_r]=Object.freeze(e)}};ar.Actor=hh;function pi(t,e){let r=Yu.IDL.decode(t,e);switch(r.length){case 0:return;case 1:return r[0];default:return r}}var Bb={pollingOptions:Ab.DEFAULT_POLLING_OPTIONS};ar.ACTOR_METHOD_WITH_HTTP_DETAILS="http-details";ar.ACTOR_METHOD_WITH_CERTIFICATE="certificate";function V4(t,e,r,n){let o;r.annotations.includes("query")||r.annotations.includes("composite_query")?o=async(i,...a)=>{i={...i,...t[_r].config.queryTransform?.(e,a,{...t[_r].config,...i})};let c=i.agent||t[_r].config.agent||new Sb.HttpAgent,d=Ba.Principal.from(i.canisterId||t[_r].config.canisterId),p=Yu.IDL.encode(r.argTypes,a),l=await c.query(d,{methodName:e,arg:p,effectiveCanisterId:i.effectiveCanisterId}),u={...l.httpDetails,requestDetails:l.requestDetails};switch(l.status){case Zu.QueryResponseStatus.Rejected:{let f=new er.UncertifiedRejectErrorCode(l.requestId,l.reject_code,l.reject_message,l.error_code,l.signatures);throw f.callContext={canisterId:d,methodName:e,httpDetails:u},er.RejectError.fromCode(f)}case Zu.QueryResponseStatus.Replied:return r.annotations.includes(ar.ACTOR_METHOD_WITH_HTTP_DETAILS)?{httpDetails:u,result:pi(r.retTypes,l.reply.arg)}:pi(r.retTypes,l.reply.arg)}}:o=async(i,...a)=>{i={...i,...t[_r].config.callTransform?.(e,a,{...t[_r].config,...i})};let c=i.agent||t[_r].config.agent||Sb.HttpAgent.createSync(),{canisterId:d,effectiveCanisterId:p,pollingOptions:l}={...Bb,...t[_r].config,...i},u=Ba.Principal.from(d),f=p!==void 0?Ba.Principal.from(p):u,h=Yu.IDL.encode(r.argTypes,a),{requestId:m,response:b,requestDetails:y}=await c.call(u,{methodName:e,arg:h,effectiveCanisterId:f,nonce:i.nonce}),x,_;if((0,Zu.isV3ResponseBody)(b.body)){if(c.rootKey==null)throw er.ExternalError.fromCode(new er.MissingRootKeyErrorCode);let v=b.body.certificate;_=await fi.Certificate.create({certificate:v,rootKey:c.rootKey,canisterId:f,blsVerify:n,agent:c});let A=[(0,F4.utf8ToBytes)("request_status"),m];switch(new TextDecoder().decode((0,fi.lookupResultToBuffer)(_.lookup_path([...A,"status"])))){case"replied":x=(0,fi.lookupResultToBuffer)(_.lookup_path([...A,"reply"]));break;case"rejected":{let S=new Uint8Array((0,fi.lookupResultToBuffer)(_.lookup_path([...A,"reject_code"])))[0],V=new TextDecoder().decode((0,fi.lookupResultToBuffer)(_.lookup_path([...A,"reject_message"]))),C=(0,fi.lookupResultToBuffer)(_.lookup_path([...A,"error_code"])),g=C?new TextDecoder().decode(C):void 0,w=new er.CertifiedRejectErrorCode(m,S,V,g);throw w.callContext={canisterId:u,methodName:e,httpDetails:b},er.RejectError.fromCode(w)}}}else if((0,Zu.isV2ResponseBody)(b.body)){let{reject_code:v,reject_message:A,error_code:E}=b.body,S=new er.UncertifiedRejectUpdateErrorCode(m,v,A,E);throw S.callContext={canisterId:u,methodName:e,httpDetails:b},er.RejectError.fromCode(S)}if(b.status===202){let v={...l,blsVerify:n},A=await(0,Ab.pollForResponse)(c,f,m,v);_=A.certificate,x=A.reply}let T=r.annotations.includes(ar.ACTOR_METHOD_WITH_HTTP_DETAILS),N=r.annotations.includes(ar.ACTOR_METHOD_WITH_CERTIFICATE),I={...b,requestDetails:y};if(x!==void 0)return T&&N?{httpDetails:I,certificate:_,result:pi(r.retTypes,x)}:N?{certificate:_,result:pi(r.retTypes,x)}:T?{httpDetails:I,result:pi(r.retTypes,x)}:pi(r.retTypes,x);{let v=new er.UnexpectedErrorCode(`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${r.retTypes.map(A=>A.display()).join(",")}].`);throw v.callContext={canisterId:u,methodName:e,httpDetails:I},er.UnknownError.fromCode(v)}};let s=(...i)=>o({},...i);return s.withOptions=i=>(...a)=>o(i,...a),s}});var Cb=Z(Un=>{"use strict";var U4=Un&&Un.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),L4=Un&&Un.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),q4=Un&&Un.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),o=0;o<n.length;o++)n[o]!=="default"&&U4(r,e,n[o]);return L4(r,e),r}})();Object.defineProperty(Un,"__esModule",{value:!0});Un.fetchCandid=$4;var M4=Ir(),k4=q4(Cu()),j4=$u(),H4=mh();async function $4(t,e){e||(e=await j4.HttpAgent.create());let n=(await k4.request({agent:e,canisterId:M4.Principal.fromText(t),paths:["candid"]})).get("candid");if(n)return n;let o=({IDL:i})=>i.Service({__get_candid_interface_tmp_hack:i.Func([],[i.Text],["query"])});return await H4.Actor.createActor(o,{agent:e,canisterId:t}).__get_candid_interface_tmp_hack()}});var _h=Z(_e=>{"use strict";var Pb=_e&&_e.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),K4=_e&&_e.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),Bt=_e&&_e.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&Pb(e,t,r)},Db=_e&&_e.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[n.length]=o);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),o=0;o<n.length;o++)n[o]!=="default"&&Pb(r,e,n[o]);return K4(r,e),r}})();Object.defineProperty(_e,"__esModule",{value:!0});_e.ToCborValue=_e.Cbor=_e.CanisterStatus=_e.polling=_e.IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR=_e.IC_RESPONSE_DOMAIN_SEPARATOR=_e.IC_REQUEST_DOMAIN_SEPARATOR=void 0;Bt(mh(),_e);Bt(fa(),_e);Bt(fu(),_e);Bt(ei(),_e);Bt(ap(),_e);Bt(ai(),_e);var yh=su();Object.defineProperty(_e,"IC_REQUEST_DOMAIN_SEPARATOR",{enumerable:!0,get:function(){return yh.IC_REQUEST_DOMAIN_SEPARATOR}});Object.defineProperty(_e,"IC_RESPONSE_DOMAIN_SEPARATOR",{enumerable:!0,get:function(){return yh.IC_RESPONSE_DOMAIN_SEPARATOR}});Object.defineProperty(_e,"IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR",{enumerable:!0,get:function(){return yh.IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR}});Bt(oh(),_e);Bt(sr(),_e);Bt(Cb(),_e);Bt(ch(),_e);Bt(ih(),_e);Bt(ou(),_e);Bt(Mp(),_e);Bt(Qs(),_e);Bt(up(),_e);_e.polling=Db(zu());var G4=Db(Cu());_e.CanisterStatus=G4;var Fb=la();Object.defineProperty(_e,"Cbor",{enumerable:!0,get:function(){return Fb.Cbor}});Object.defineProperty(_e,"ToCborValue",{enumerable:!0,get:function(){return Fb.ToCborValue}});Bt(zu(),_e)});var Pe=Z((q5,Qb)=>{"use strict";var Th=Object.defineProperty,z4=Object.getOwnPropertyDescriptor,Z4=Object.getOwnPropertyNames,Y4=Object.prototype.hasOwnProperty,W4=(t,e)=>{for(var r in e)Th(t,r,{get:e[r],enumerable:!0})},X4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Z4(e))!Y4.call(t,o)&&o!==r&&Th(t,o,{get:()=>e[o],enumerable:!(n=z4(e,o))||n.enumerable});return t},J4=t=>X4(Th({},"__esModule",{value:!0}),t),qb={};W4(qb,{AgentManager:()=>cO,Canister:()=>sO,FromStringToTokenError:()=>Mb,ICPToken:()=>rO,InvalidPercentageError:()=>Gb,NullishError:()=>zb,TokenAmount:()=>nO,TokenAmountV2:()=>oO,arrayBufferToUint8Array:()=>mO,arrayOfNumberToUint8Array:()=>_O,asNonNullish:()=>dO,asciiStringToByteArray:()=>bO,assertNonNullish:()=>Va,assertPercentageNumber:()=>lO,base64ToUint8Array:()=>NO,bigEndianCrc32:()=>RO,bigIntToUint8Array:()=>pO,candidNumberArrayToBigInt:()=>wO,convertStringToE8s:()=>kb,createAgent:()=>$b,createServices:()=>uO,debounce:()=>VO,decodeBase32:()=>TO,defaultAgent:()=>Hb,encodeBase32:()=>EO,fromDefinedNullable:()=>LO,fromNullable:()=>Oh,fromNullishNullable:()=>qO,hashObject:()=>AO,hashText:()=>Wb,hexStringToUint8Array:()=>gO,isEmptyString:()=>iO,isNullish:()=>Fa,jsonReplacer:()=>Yb,jsonReviver:()=>SO,nonNullish:()=>cn,notEmptyString:()=>jb,nowInBigIntNanoSeconds:()=>DO,numberToUint8Array:()=>hO,principalToSubAccount:()=>MO,queryAndUpdate:()=>aO,secondsToDuration:()=>CO,smallerVersion:()=>kO,toBigIntNanoSeconds:()=>FO,toNullable:()=>UO,uint8ArrayToArrayOfNumber:()=>yO,uint8ArrayToBase64:()=>OO,uint8ArrayToBigInt:()=>fO,uint8ArrayToHexString:()=>Zb,uint8ArraysEqual:()=>xO});Qb.exports=J4(qb);var Mb=(t=>(t[t.FractionalMoreThan8Decimals=0]="FractionalMoreThan8Decimals",t[t.InvalidFormat=1]="InvalidFormat",t[t.FractionalTooManyDecimals=2]="FractionalTooManyDecimals",t))(Mb||{}),Q4=BigInt(1e8),eO=8,kb=t=>{let e=t.includes("e")?Number(t).toLocaleString("en",{useGrouping:!1,maximumFractionDigits:20}):t;e=e.trim().replace(/[,']/g,"");let r=e.match(/\d*(\.\d*)?/);if(!r||r[0]!==e)return 1;let[n,o]=e.split("."),s=BigInt(0);if(n)try{s+=BigInt(n)*Q4}catch{return 1}if(o){if(o.length>8)return 0;try{s+=BigInt(o.padEnd(8,"0"))}catch{return 1}}return s},tO=({amount:t,decimals:e})=>{t=t.trim().replace(/[,']/g,"");let r=t.match(/\d*(\.\d*)?/);if(!r||r[0]!==t)return 1;let[n,o]=t.split("."),s=0n,i=10n**BigInt(e);if(n)try{s+=BigInt(n)*i}catch{return 1}if(o){if(o.length>e)return 2;try{s+=BigInt(o.padEnd(e,"0"))}catch{return 1}}return s},rO={symbol:"ICP",name:"Internet Computer",decimals:8},nO=class Pa{constructor(e,r){if(this.e8s=e,this.token=r,r.decimals!==8)throw new Error("Use TokenAmountV2 for number of decimals other than 8")}static fromE8s({amount:e,token:r}){return new Pa(e,r)}static fromString({amount:e,token:r}){if(r.decimals!==8)throw new Error("Use TokenAmountV2 for number of decimals other than 8");let n=kb(e);return typeof n=="bigint"?new Pa(n,r):n}static fromNumber({amount:e,token:r}){let n=Pa.fromString({amount:e.toString(),token:r});if(n instanceof Pa)return n;throw n===0?new Error(`Number ${e} has more than 8 decimals`):new Error(`Invalid number ${e}`)}toE8s(){return this.e8s}},oO=class Da{constructor(e,r){this.ulps=e,this.token=r}static fromUlps({amount:e,token:r}){return new Da(e,r)}static fromString({amount:e,token:r}){let n=tO({amount:e,decimals:r.decimals});return typeof n=="bigint"?new Da(n,r):n}static fromNumber({amount:e,token:r}){let n=Da.fromString({amount:e.toFixed(Math.min(eO,r.decimals)),token:r});if(n instanceof Da)return n;throw n===2?new Error(`Number ${e} has more than ${r.decimals} decimals`):new Error(`Invalid number ${e}`)}toUlps(){return this.ulps}toE8s(){return this.token.decimals<8?this.ulps*10n**BigInt(8-this.token.decimals):this.token.decimals===8?this.ulps:this.ulps/10n**BigInt(this.token.decimals-8)}},sO=class{constructor(t,e,r){this.id=t,this.service=e,this.certifiedService=r}get canisterId(){return this.id}caller=({certified:t=!0})=>t?this.certifiedService:this.service},Fa=t=>t==null,cn=t=>!Fa(t),jb=t=>cn(t)&&t!=="",iO=t=>!jb(t),aO=async({request:t,onLoad:e,onQueryError:r,onUpdateError:n,strategy:o="query_and_update",identity:s,resolution:i="race"})=>{let a=!1,c=p=>t({certified:p,identity:s}).then(l=>{a||e({certified:p,response:l})}).catch(l=>{p||r==null||r({error:l,identity:s}),!a&&(Fa(n)||(console.error(l),p&&n({error:l,identity:s})))}).finally(()=>a=a||p),d=o==="query"?[c(!1)]:o==="update"?[c(!0)]:[c(!1),c(!0)];await(i==="all_settled"?Promise.allSettled(d):Promise.race(d))},Vb=_h(),bh=_h(),Hb=()=>bh.HttpAgent.createSync({host:"https://icp-api.io",identity:new bh.AnonymousIdentity}),$b=async({identity:t,host:e,fetchRootKey:r=!1,verifyQuerySignatures:n=!1,retryTimes:o})=>await bh.HttpAgent.create({identity:t,...cn(e)&&{host:e},verifyQuerySignatures:n,...cn(o)&&{retryTimes:o},shouldFetchRootKey:r}),cO=class Kb{constructor(e){this.config=e}agents=void 0;static create(e){return new Kb(e)}getAgent=async({identity:e})=>{let r=e.getPrincipal().toText();if(Fa(this.agents)||Fa(this.agents[r])){let n=await $b({identity:e,fetchRootKey:this.config.fetchRootKey,host:this.config.host,verifyQuerySignatures:!0});return this.agents={...this.agents??{},[r]:n},n}return this.agents[r]};clearAgents=()=>{this.agents=null}},uO=({options:{canisterId:t,serviceOverride:e,certifiedServiceOverride:r,agent:n,callTransform:o,queryTransform:s},idlFactory:i,certifiedIdlFactory:a})=>{let c=n??Hb(),d=e??Vb.Actor.createActor(i,{agent:c,canisterId:t,callTransform:o,queryTransform:s}),p=r??Vb.Actor.createActor(a,{agent:c,canisterId:t,callTransform:o,queryTransform:s});return{service:d,certifiedService:p,agent:c,canisterId:t}},Gb=class extends Error{},zb=class extends Error{},Va=(t,e)=>{if(t==null)throw new zb(e)},dO=(t,e)=>(Va(t,e),t),lO=t=>{if(t<0||t>100)throw new Gb(`${t} is not a valid percentage number.`)},fO=t=>{let e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(typeof e.getBigUint64=="function")return e.getBigUint64(0);let r=BigInt(e.getUint32(0)),n=BigInt(e.getUint32(4));return(r<<BigInt(32))+n},pO=t=>{let e=new ArrayBuffer(8),r=new DataView(e);if(typeof r.setBigUint64=="function")r.setBigUint64(0,t);else{let n=Number(t>>BigInt(32)),o=Number(t&BigInt(4294967295));r.setUint32(0,n),r.setUint32(4,o)}return new Uint8Array(e)},hO=t=>{let e=new DataView(new ArrayBuffer(8));for(let r=7;r>=0;--r)e.setUint8(r,t%256),t=t>>8;return new Uint8Array(e.buffer)},mO=t=>new Uint8Array(t),yO=t=>Array.from(t),_O=t=>new Uint8Array(t),bO=t=>Array.from(t).map(e=>e.charCodeAt(0)),gO=t=>{let e=t.match(/.{1,2}/g);return Va(e,"Invalid hex string."),Uint8Array.from(e.map(r=>parseInt(r,16)))},xO=({a:t,b:e})=>t.length===e.length&&t.every((r,n)=>r===e[n]),Zb=t=>(t instanceof Uint8Array||(t=Uint8Array.from(t)),t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")),wO=t=>{let e=0n;for(let r=t.length-1;r>=0;r--)e=(e<<32n)+BigInt(t[r]);return e},Wu="abcdefghijklmnopqrstuvwxyz234567",hi=Object.create(null);for(let t=0;t<Wu.length;t++)hi[Wu[t]]=t;hi[0]=hi.o;hi[1]=hi.i;var EO=t=>{let e=0,r=0,n="",o=s=>(e<0?r|=s>>-e:r=s<<e&248,e>3?(e-=8,1):(e<4&&(n+=Wu[r>>3],e+=5),0));for(let s=0;s<t.length;)s+=o(t[s]);return n+(e<0?Wu[r>>3]:"")},TO=t=>{let e=0,r=0,n=new Uint8Array(t.length*4/3|0),o=0,s=i=>{let a=hi[i.toLowerCase()];Va(a,`Invalid character: ${JSON.stringify(i)}`),a<<=3,r|=a>>>e,e+=5,e>=8&&(n[o++]=r,e-=8,e>0?r=a<<5-e&255:r=0)};for(let i of t)s(i);return n.slice(0,o)},OO=t=>btoa(String.fromCharCode(...new Uint8Array(t))),NO=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),vO=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]),IO=t=>{let e=-1;for(let r=0;r<t.length;r++){let n=(t[r]^e)&255;e=vO[n]^e>>>8}return(e^-1)>>>0},RO=t=>{let e=new ArrayBuffer(4);return new DataView(e).setUint32(0,IO(t),!1),new Uint8Array(e)},gh=Ir(),xh="__bigint__",wh="__principal__",Eh="__uint8array__",Yb=(t,e)=>typeof e=="bigint"?{[xh]:`${e}`}:cn(e)&&gh.Principal.isPrincipal(e)?{[wh]:gh.Principal.from(e).toText()}:cn(e)&&e instanceof Uint8Array?{[Eh]:Array.from(e)}:e,SO=(t,e)=>{let r=n=>e[n];return cn(e)&&typeof e=="object"&&xh in e?BigInt(r(xh)):cn(e)&&typeof e=="object"&&wh in e?gh.Principal.fromText(r(wh)):cn(e)&&typeof e=="object"&&Eh in e?Uint8Array.from(r(Eh)):e},AO=async t=>{let e=JSON.stringify(t,Yb);return await Wb(e)},Wb=async t=>{let e=new TextEncoder().encode(t),r=await crypto.subtle.digest("SHA-256",e);return Zb(new Uint8Array(r))},BO={year:"year",year_plural:"years",month:"month",month_plural:"months",day:"day",day_plural:"days",hour:"hour",hour_plural:"hours",minute:"minute",minute_plural:"minutes",second:"second",second_plural:"seconds"},CO=({seconds:t,i18n:e=BO})=>{let r=t/BigInt(60),n=r/BigInt(60);r-=n*BigInt(60);let o=n/BigInt(24);n-=o*BigInt(24);let s=PO(o);return o-=Xb(s),[Ca({labelKey:"year",amount:s}),Ca({labelKey:"day",amount:o}),Ca({labelKey:"hour",amount:n}),Ca({labelKey:"minute",amount:r}),...t>BigInt(0)&&t<BigInt(60)?[Ca({labelKey:"second",amount:t})]:[]].filter(({amount:i})=>i>0).slice(0,2).map(i=>`${i.amount} ${i.amount===1?e[i.labelKey]:e[`${i.labelKey}_plural`]}`).join(", ")},PO=t=>{let e=t/BigInt(365);for(;Xb(e)>t;)e--;return e},Xb=t=>{let e=t/BigInt(4);return t*BigInt(365)+e},Ca=({labelKey:t,amount:e})=>({labelKey:t,amount:Number(e)}),Jb=1000000n,DO=()=>BigInt(Date.now())*Jb,FO=t=>BigInt(t.getTime())*Jb,VO=(t,e)=>{let r;return(...n)=>{let o=()=>t(...n);r&&clearTimeout(r),r=setTimeout(o,e!==void 0&&e>0?e:300)}},UO=t=>cn(t)?[t]:[],Oh=t=>t?.[0],LO=t=>{let e=Oh(t);return Va(e),e},qO=t=>Oh(t??[]),MO=t=>{let e=t.toUint8Array(),r=new Uint8Array(32);return r[0]=e.length,r.set(e,1),r},Ub=({nums:t,amountZeros:e})=>e>t.length?[...t,...[...Array(e-t.length).keys()].map(()=>0)]:t,Lb=t=>{if(!Number.isNaN(Number(t)))return Number(t);let e=t.split("").reduce((r,n)=>Number.isNaN(Number(n))?r:r+n,"");return Number(e)},kO=({minVersion:t,currentVersion:e})=>{let r=Ub({nums:t.split(".").map(Lb),amountZeros:3}).join(".");return Ub({nums:e.split(".").map(Lb),amountZeros:3}).join(".").localeCompare(r,void 0,{numeric:!0,sensitivity:"base"})<0}});var q1=De(Pe(),1);var pw=De(Pe(),1);var eg;(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"})(eg||(eg={}));var No;(function(t){t.Replied="replied",t.Rejected="rejected"})(No||(No={}));function tg(t){return t!=null&&"reject_code"in t}function rg(t){return t!=null&&"certificate"in t}var Xu="abcdefghijklmnopqrstuvwxyz234567",mi=Object.create(null);for(let t=0;t<Xu.length;t++)mi[Xu[t]]=t;mi[0]=mi.o;mi[1]=mi.i;function ng(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+=Xu[r>>3],e+=5),0)}for(let s=0;s<t.length;)s+=o(t[s]);return n+(e<0?Xu[r>>3]:"")}function og(t){let e=0,r=0,n=new Uint8Array(t.length*4/3|0),o=0;function s(i){let a=mi[i.toLowerCase()];if(a===void 0)throw new Error(`Invalid character: ${JSON.stringify(i)}`);a<<=3,r|=a>>>e,e+=5,e>=8&&(n[o++]=r,e-=8,e>0?r=a<<5-e&255:r=0)}for(let i of t)s(i);return n.slice(0,o)}var jO=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 sg(t){let e=-1;for(let r=0;r<t.length;r++){let o=(t[r]^e)&255;e=jO[o]^e>>>8}return(e^-1)>>>0}import*as Ln from"node:crypto";var us=Ln&&typeof Ln=="object"&&"webcrypto"in Ln?Ln.webcrypto:Ln&&typeof Ln=="object"&&"randomBytes"in Ln?Ln:void 0;function un(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Nh(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Xe(t,...e){if(!un(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function vh(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function ag(t,e){Xe(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ds(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Qu(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Cr(t,e){return t<<32-e|t>>>e}var cg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",HO=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function de(t){if(Xe(t),cg)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=HO[t[r]];return e}var qn={_0:48,_9:57,A:65,F:70,a:97,f:102};function ig(t){if(t>=qn._0&&t<=qn._9)return t-qn._0;if(t>=qn.A&&t<=qn.F)return t-(qn.A-10);if(t>=qn.a&&t<=qn.f)return t-(qn.a-10)}function ht(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(cg)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("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=ig(t.charCodeAt(s)),a=ig(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ve(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Ih(t){return typeof t=="string"&&(t=Ve(t)),Xe(t),t}function fe(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Xe(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}var Ju=class{};function ed(t){let e=n=>t().update(Ih(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function yi(t=32){if(us&&typeof us.getRandomValues=="function")return us.getRandomValues(new Uint8Array(t));if(us&&typeof us.randomBytes=="function")return Uint8Array.from(us.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function $O(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,d=n?0:4;t.setUint32(e+c,i,n),t.setUint32(e+d,a,n)}function ug(t,e,r){return t&e^~t&r}function dg(t,e,r){return t&e^t&r^e&r}var Ua=class extends Ju{constructor(e,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Qu(this.buffer)}update(e){vh(this),e=Ih(e),Xe(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Qu(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){vh(this),ag(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,ds(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;$O(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Qu(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=c/4,p=this.get();if(d>p.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)a.setUint32(4*l,p[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Mn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),kn=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var wt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var td=BigInt(4294967295),lg=BigInt(32);function KO(t,e=!1){return e?{h:Number(t&td),l:Number(t>>lg&td)}:{h:Number(t>>lg&td)|0,l:Number(t&td)|0}}function fg(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:a}=KO(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Rh=(t,e,r)=>t>>>r,Sh=(t,e,r)=>t<<32-r|e>>>r,ls=(t,e,r)=>t>>>r|e<<32-r,fs=(t,e,r)=>t<<32-r|e>>>r,La=(t,e,r)=>t<<64-r|e>>>r-32,qa=(t,e,r)=>t>>>r-32|e<<64-r;function dn(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var pg=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),hg=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,mg=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),yg=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,_g=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),bg=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var zO=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]),vo=new Uint32Array(64),rd=class extends Ua{constructor(e=32){super(64,e,8,!1),this.A=Mn[0]|0,this.B=Mn[1]|0,this.C=Mn[2]|0,this.D=Mn[3]|0,this.E=Mn[4]|0,this.F=Mn[5]|0,this.G=Mn[6]|0,this.H=Mn[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){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=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)vo[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let u=vo[l-15],f=vo[l-2],h=Cr(u,7)^Cr(u,18)^u>>>3,m=Cr(f,17)^Cr(f,19)^f>>>10;vo[l]=m+vo[l-7]+h+vo[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:d,H:p}=this;for(let l=0;l<64;l++){let u=Cr(a,6)^Cr(a,11)^Cr(a,25),f=p+u+ug(a,c,d)+zO[l]+vo[l]|0,m=(Cr(n,2)^Cr(n,13)^Cr(n,22))+dg(n,o,s)|0;p=d,d=c,c=a,a=i+f|0,i=s,s=o,o=n,n=f+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,d=d+this.G|0,p=p+this.H|0,this.set(n,o,s,i,a,c,d,p)}roundClean(){ds(vo)}destroy(){this.set(0,0,0,0,0,0,0,0),ds(this.buffer)}},Ah=class extends rd{constructor(){super(28),this.A=kn[0]|0,this.B=kn[1]|0,this.C=kn[2]|0,this.D=kn[3]|0,this.E=kn[4]|0,this.F=kn[5]|0,this.G=kn[6]|0,this.H=kn[7]|0}},gg=fg(["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))),ZO=gg[0],YO=gg[1],Io=new Uint32Array(80),Ro=new Uint32Array(80),Bh=class extends Ua{constructor(e=64){super(128,e,16,!1),this.Ah=wt[0]|0,this.Al=wt[1]|0,this.Bh=wt[2]|0,this.Bl=wt[3]|0,this.Ch=wt[4]|0,this.Cl=wt[5]|0,this.Dh=wt[6]|0,this.Dl=wt[7]|0,this.Eh=wt[8]|0,this.El=wt[9]|0,this.Fh=wt[10]|0,this.Fl=wt[11]|0,this.Gh=wt[12]|0,this.Gl=wt[13]|0,this.Hh=wt[14]|0,this.Hl=wt[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:d,El:p,Fh:l,Fl:u,Gh:f,Gl:h,Hh:m,Hl:b}=this;return[e,r,n,o,s,i,a,c,d,p,l,u,f,h,m,b]}set(e,r,n,o,s,i,a,c,d,p,l,u,f,h,m,b){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=a|0,this.Dl=c|0,this.Eh=d|0,this.El=p|0,this.Fh=l|0,this.Fl=u|0,this.Gh=f|0,this.Gl=h|0,this.Hh=m|0,this.Hl=b|0}process(e,r){for(let _=0;_<16;_++,r+=4)Io[_]=e.getUint32(r),Ro[_]=e.getUint32(r+=4);for(let _=16;_<80;_++){let T=Io[_-15]|0,N=Ro[_-15]|0,I=ls(T,N,1)^ls(T,N,8)^Rh(T,N,7),v=fs(T,N,1)^fs(T,N,8)^Sh(T,N,7),A=Io[_-2]|0,E=Ro[_-2]|0,S=ls(A,E,19)^La(A,E,61)^Rh(A,E,6),V=fs(A,E,19)^qa(A,E,61)^Sh(A,E,6),C=mg(v,V,Ro[_-7],Ro[_-16]),g=yg(C,I,S,Io[_-7],Io[_-16]);Io[_]=g|0,Ro[_]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:d,Dl:p,Eh:l,El:u,Fh:f,Fl:h,Gh:m,Gl:b,Hh:y,Hl:x}=this;for(let _=0;_<80;_++){let T=ls(l,u,14)^ls(l,u,18)^La(l,u,41),N=fs(l,u,14)^fs(l,u,18)^qa(l,u,41),I=l&f^~l&m,v=u&h^~u&b,A=_g(x,N,v,YO[_],Ro[_]),E=bg(A,y,T,I,ZO[_],Io[_]),S=A|0,V=ls(n,o,28)^La(n,o,34)^La(n,o,39),C=fs(n,o,28)^qa(n,o,34)^qa(n,o,39),g=n&s^n&a^s&a,w=o&i^o&c^i&c;y=m|0,x=b|0,m=f|0,b=h|0,f=l|0,h=u|0,{h:l,l:u}=dn(d|0,p|0,E|0,S|0),d=a|0,p=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let O=pg(S,C,w);n=hg(O,E,V,g),o=O|0}({h:n,l:o}=dn(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=dn(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=dn(this.Ch|0,this.Cl|0,a|0,c|0),{h:d,l:p}=dn(this.Dh|0,this.Dl|0,d|0,p|0),{h:l,l:u}=dn(this.Eh|0,this.El|0,l|0,u|0),{h:f,l:h}=dn(this.Fh|0,this.Fl|0,f|0,h|0),{h:m,l:b}=dn(this.Gh|0,this.Gl|0,m|0,b|0),{h:y,l:x}=dn(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,o,s,i,a,c,d,p,l,u,f,h,m,b,y,x)}roundClean(){ds(Io,Ro)}destroy(){ds(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ct=ed(()=>new rd),xg=ed(()=>new Ah),wg=ed(()=>new Bh);var nd="__principal__",WO=2,Eg=4,XO="aaaaa-aa",oe=class t{static anonymous(){return new this(new Uint8Array([Eg]))}static managementCanister(){return this.fromText(XO)}static selfAuthenticating(e){let r=xg(e);return new this(new Uint8Array([...r,WO]))}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(ht(e))}static fromText(e){let r=e;if(e.includes(nd)){let i=JSON.parse(e);nd in i&&(r=i[nd])}let n=r.toLowerCase().replace(/-/g,""),o=og(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]===Eg}toUint8Array(){return this._arr}toHex(){return de(this._arr).toUpperCase()}toText(){let e=new ArrayBuffer(4);new DataView(e).setUint32(0,sg(this._arr));let n=new Uint8Array(e),o=new Uint8Array([...n,...this._arr]),i=ng(o).match(/.{1,5}/g);if(!i)throw new Error;return i.join("-")}toString(){return this.toText()}toJSON(){return{[nd]: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 jn;(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"})(jn||(jn={}));var be=class{constructor(e=!1){this.isCertified=e}toString(){let e=this.toErrorMessage();return this.requestContext&&(e+=`
|
|
67
|
+
Retrying query.`),await this.#x({...e,tries:a+1});throw p instanceof Z.AgentError?p:Z.TransportError.fromCode(new Z.HttpFetchErrorCode(p))}if(!this.#y)return d;let f=d.signatures?.[0]?.timestamp;if(!f)throw Z.ProtocolError.fromCode(new Z.MalformedSignatureErrorCode("Timestamp not found in query response. This suggests a malformed or malicious response."));let l=Number(BigInt(f)/BigInt(a4));if(Date.now()+this.#r-l>this.#T){if(a<this.#l)return this.log.warn("Timestamp is older than the max ingress expiry. Retrying query.",{requestId:o,signatureTimestampMs:l}),await this.#x({...e,tries:a+1});throw Z.TrustError.fromCode(new Z.CertificateOutdatedErrorCode(this.#u,o,a))}return d}async#_(e){let{requestFn:r,backoff:n,tries:s}=e,o=s===0?0:n.next();if(o===null)throw Z.ProtocolError.fromCode(new Z.TimeoutWaitingForResponseErrorCode(`Retry strategy exhausted after ${s} attempts.`));o>0&&await new Promise(f=>setTimeout(f,o));let i,a=new Uint8Array;try{i=await r(),i.status===Kh&&(a=(0,$h.uint8FromBufLike)(await i.clone().arrayBuffer()))}catch(f){if(s<this.#l)return this.log.warn(`Caught exception while attempting to make request:
|
|
68
|
+
${f}
|
|
69
|
+
Retrying request.`),await this.#_({requestFn:r,backoff:n,tries:s+1});throw Z.TransportError.fromCode(new Z.HttpFetchErrorCode(f))}let c=(0,Ii.httpHeadersTransform)(i.headers);if(i.status===Kh||i.status===m4)return{ok:i.ok,status:i.status,statusText:i.statusText,responseBodyBytes:a,headers:c};let d=await i.text();if(i.status===y4&&i.url.includes("api/v3"))throw Z.ProtocolError.fromCode(new Z.HttpV3ApiNotSupportedErrorCode);if(d.startsWith("Invalid request expiry: "))throw Z.InputError.fromCode(new Z.IngressExpiryInvalidErrorCode(d,this.#u));if(s<this.#l)return await this.#_({requestFn:r,backoff:n,tries:s+1});throw Z.ProtocolError.fromCode(new Z.HttpErrorCode(i.status,i.statusText,c,d))}async query(e,r,n){let s=this.#f(),o=r.effectiveCanisterId?jn.Principal.from(r.effectiveCanisterId):jn.Principal.from(e);await this.#b(o),this.log.print(`ecid ${o.toString()}`),this.log.print(`canisterId ${e.toString()}`);let i,a=await(n??this.#n);if(!a)throw Z.ExternalError.fromCode(new Z.IdentityInvalidErrorCode);let c=jn.Principal.from(e),d=a.getPrincipal(),f=pd(this.#u,this.#r),l={request_type:Hn.ReadRequestType.Query,canister_id:c,method_name:r.methodName,arg:r.arg,sender:d,ingress_expiry:f},u=(0,Xa.requestIdOf)(l);i=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#o?{Authorization:"Basic "+btoa(this.#o)}:{}}},endpoint:Hn.Endpoint.Query,body:l}),i=await a.transformRequest(i);let p=Vs.encode(i.body),h={canister:c.toText(),ecid:o,transformedRequest:i,body:p,requestId:u,backoff:s,tries:0},m=async()=>{let y=await this.#x(h);return{requestDetails:l,...y}},b=async()=>{let y=this.#m.get(o.toString());if(y)return y;await this.fetchSubnetKeys(o.toString());let x=this.#m.get(o.toString());if(!x)throw Z.TrustError.fromCode(new Z.MissingSignatureErrorCode);return x};try{if(!this.#y)return await m();let[y,x]=await Promise.all([m(),b()]);try{return this.#w(y,x)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),this.#m.delete(o.toString());let _=await b();return this.#w(y,_)}}catch(y){let x;throw y instanceof Z.AgentError?(y.code.requestContext={requestId:u,senderPubKey:i.body.sender_pubkey,senderSignature:i.body.sender_sig,ingressExpiry:i.body.content.ingress_expiry},x=y):x=Z.UnknownError.fromCode(new Z.UnexpectedErrorCode(y)),this.log.error(`Error while making query: ${x.message}`,x),x}}#w;async createReadStateRequest(e,r){await this.#b();let n=await(r??this.#n);if(!n)throw Z.ExternalError.fromCode(new Z.IdentityInvalidErrorCode);let s=n.getPrincipal(),o=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#o?{Authorization:"Basic "+btoa(this.#o)}:{}}},endpoint:Hn.Endpoint.ReadState,body:{request_type:Hn.ReadRequestType.ReadState,paths:e.paths,sender:s,ingress_expiry:pd(this.#u,this.#r)}});return n.transformRequest(o)}async readState(e,r,n,s){await this.#E();let o=jn.Principal.from(e);function i(f){for(let l of f.paths){let[u,p]=l,h=new TextEncoder().encode("request_status");if((0,$h.uint8Equals)(u,h))return p}}let a,c;if(s)a=s,c=(0,Xa.requestIdOf)(a);else{c=i(r);let f=await this.#n;if(!f)throw Z.ExternalError.fromCode(new Z.IdentityInvalidErrorCode);a=await this.createReadStateRequest(r,f)}this.log.print(`fetching "/api/v2/canister/${o}/read_state" with request:`,a);let d=this.#f();try{let{responseBodyBytes:f}=await this.#_({requestFn:()=>this.#s(""+new URL(`/api/v2/canister/${o.toString()}/read_state`,this.host),{...this.#a,...a.request,body:Vs.encode(a.body)}),backoff:d,tries:0}),l=Vs.decode(f);return this.log.print("Read state response:",l),l}catch(f){let l;throw f instanceof Z.AgentError?(f.code.requestContext={requestId:c,senderPubKey:a.body.sender_pubkey,senderSignature:a.body.sender_sig,ingressExpiry:a.body.content.ingress_expiry},l=f):l=Z.UnknownError.fromCode(new Z.UnexpectedErrorCode(f)),this.log.error(`Error while making read state: ${l.message}`,l),l}}parseTimeFromResponse(e){let r;if(e.certificate){let n=Vs.decode(e.certificate);if(n&&"tree"in n)r=n.tree;else throw Z.ProtocolError.fromCode(new Z.HashTreeDecodeErrorCode("Could not decode time from response"));let s=(0,eg.lookup_path)(["time"],r);if(s.status!==eg.LookupPathStatus.Found)throw Z.ProtocolError.fromCode(new Z.LookupErrorCode("Time was not found in the response or was not in its expected format.",s.status));if(!(s.value instanceof Uint8Array)&&!ArrayBuffer.isView(s))throw Z.ProtocolError.fromCode(new Z.MalformedLookupFoundValueErrorCode("Time was not in its expected format."));let o=(0,s4.decodeTime)(s.value);return this.log.print("Time from response:",o),this.log.print("Time from response in milliseconds:",o.getTime()),o.getTime()}else this.log.warn("No certificate found in response");return 0}async syncTime(e){this.#i=this.#i??(async()=>{await this.#E();let r=Date.now();try{e||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let n=e??jn.Principal.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),s=t.createSync({identity:new Xb.AnonymousIdentity,host:this.host.toString(),fetch:this.#s,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),i=(await Promise.all(Array(3).fill(null).map(async()=>{let c=(await(0,Qb.request)({canisterId:n,agent:s,paths:["time"],disableCertificateTimeVerification:!0})).get("time");if(c instanceof Date)return c.getTime()},[]))).reduce((a,c)=>typeof c=="number"&&c>a?c:a,0);i>0&&(this.#r=i-r,this.#c=!0,this.log.notify({message:`Syncing time: offset of ${this.#r}`,level:"info"}))}catch(n){let s=n instanceof Z.AgentError?n:Z.UnknownError.fromCode(new Z.UnexpectedErrorCode(n));throw this.log.error("Caught exception while attempting to sync time",s),s}})(),await this.#i.finally(()=>{this.#i=null})}async status(){let e=this.#o?{Authorization:"Basic "+btoa(this.#o)}:{};this.log.print('fetching "/api/v2/status"');let r=this.#f(),{responseBodyBytes:n}=await this.#_({backoff:r,requestFn:()=>this.#s(""+new URL("/api/v2/status",this.host),{headers:e,...this.#a}),tries:0});return Vs.decode(n)}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#b(e){await Promise.all([this.#E(),this.#O(e)])}async#E(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#t)await this.fetchRootKey();else throw Z.ExternalError.fromCode(new Z.MissingRootKeyErrorCode(this.#t))}async#O(e){this.#d&&!this.hasSyncedTime()&&await this.syncTime(e)}invalidateIdentity(){this.#n=null}replaceIdentity(e){this.#n=Promise.resolve(e)}async fetchSubnetKeys(e){let r=jn.Principal.from(e);await this.#b(r);let s=(await(0,Qb.request)({canisterId:r,paths:["subnet"],agent:this})).get("subnet");if(s&&typeof s=="object"&&"nodeKeys"in s)return this.#m.set(r.toText(),s),s}_transform(e){let r=Promise.resolve(e);if(e.endpoint===Hn.Endpoint.Call)for(let n of this.#h)r=r.then(s=>n(s).then(o=>o||s));else for(let n of this.#p)r=r.then(s=>n(s).then(o=>o||s));return r}getTimeDiffMsecs(){return this.#r}hasSyncedTime(){return this.#c}};$e.HttpAgent=Zh;function pd(t,e){let r=t*Gh;return Ii.Expiry.fromDeltaInMilliseconds(r,e)}});var Pa=Y(Ls=>{"use strict";var g4=Ls&&Ls.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),sg=Ls&&Ls.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&g4(e,t,r)};Object.defineProperty(Ls,"__esModule",{value:!0});sg(sf(),Ls);sg(hd(),Ls)});var yd=Y(yn=>{"use strict";Object.defineProperty(yn,"__esModule",{value:!0});yn.defaultStrategy=w4;yn.once=og;yn.conditionalDelay=ig;yn.maxAttempts=E4;yn.throttle=T4;yn.timeout=ag;yn.backoff=cg;yn.chain=ug;var md=yr(),x4=300*1e3;function w4(){return ug(ig(og(),1e3),cg(1e3,1.2),ag(x4))}function og(){let t=!0;return async()=>t?(t=!1,!0):!1}function ig(t,e){return async(r,n,s)=>{if(await t(r,n,s))return new Promise(o=>setTimeout(o,e))}}function E4(t){let e=t;return async(r,n,s)=>{if(--e<=0)throw md.ProtocolError.fromCode(new md.TimeoutWaitingForResponseErrorCode(`Failed to retrieve a reply for request after ${t} attempts`,n,s))}}function T4(t){return()=>new Promise(e=>setTimeout(e,t))}function ag(t){let e=Date.now()+t;return async(r,n,s)=>{if(Date.now()>e)throw md.ProtocolError.fromCode(new md.TimeoutWaitingForResponseErrorCode(`Request timed out after ${t} msec`,n,s))}}function cg(t,e){let r=t;return()=>new Promise(n=>setTimeout(()=>{r*=e,n()},r))}function ug(...t){return async(e,r,n)=>{for(let s of t)await s(e,r,n)}}});var _d=Y(Ut=>{"use strict";var O4=Ut&&Ut.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),N4=Ut&&Ut.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),v4=Ut&&Ut.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[n.length]=s);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),s=0;s<n.length;s++)n[s]!=="default"&&O4(r,e,n[s]);return N4(r,e),r}})();Object.defineProperty(Ut,"__esModule",{value:!0});Ut.DEFAULT_POLLING_OPTIONS=Ut.defaultStrategy=Ut.strategy=void 0;Ut.pollForResponse=pg;Ut.constructRequest=hg;var Si=Ni(),$n=yr();Ut.strategy=v4(yd());var R4=yd(),I4=bi(),Ro=Pa(),dg=ht(),S4=yd();Object.defineProperty(Ut,"defaultStrategy",{enumerable:!0,get:function(){return S4.defaultStrategy}});Ut.DEFAULT_POLLING_OPTIONS={preSignReadStateRequest:!1};function fg(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function zh(t,e){return t!==null&&typeof t=="object"&&fg(t,e)}function A4(t,e){return fg(t,e)&&typeof t[e]=="function"}function lg(t){return zh(t,"body")&&zh(t.body,"content")&&t.body.content.request_type===I4.ReadRequestType.ReadState&&zh(t.body.content,"ingress_expiry")&&typeof t.body.content.ingress_expiry=="object"&&t.body.content.ingress_expiry!==null&&A4(t.body.content.ingress_expiry,"toHash")}async function pg(t,e,r,n={}){let s=[(0,dg.utf8ToBytes)("request_status"),r],o,i;if(n.preSignReadStateRequest??!1?(i=await hg({paths:[s],agent:t,pollingOptions:n}),o=await t.readState(e,{paths:[s]},void 0,i)):o=await t.readState(e,{paths:[s]}),t.rootKey==null)throw $n.ExternalError.fromCode(new $n.MissingRootKeyErrorCode);let c=await Si.Certificate.create({certificate:o.certificate,rootKey:t.rootKey,canisterId:e,blsVerify:n.blsVerify,agent:t}),d=(0,Si.lookupResultToBuffer)(c.lookup_path([...s,(0,dg.utf8ToBytes)("status")])),f;switch(typeof d>"u"?f=Ro.RequestStatusResponseStatus.Unknown:f=new TextDecoder().decode(d),f){case Ro.RequestStatusResponseStatus.Replied:return{reply:(0,Si.lookupResultToBuffer)(c.lookup_path([...s,"reply"])),certificate:c};case Ro.RequestStatusResponseStatus.Received:case Ro.RequestStatusResponseStatus.Unknown:case Ro.RequestStatusResponseStatus.Processing:{let l=n.strategy??(0,R4.defaultStrategy)();return await l(e,r,f),pg(t,e,r,{...n,strategy:l,request:i})}case Ro.RequestStatusResponseStatus.Rejected:{let l=new Uint8Array((0,Si.lookupResultToBuffer)(c.lookup_path([...s,"reject_code"])))[0],u=new TextDecoder().decode((0,Si.lookupResultToBuffer)(c.lookup_path([...s,"reject_message"]))),p=(0,Si.lookupResultToBuffer)(c.lookup_path([...s,"error_code"])),h=p?new TextDecoder().decode(p):void 0;throw $n.RejectError.fromCode(new $n.CertifiedRejectErrorCode(r,l,u,h))}case Ro.RequestStatusResponseStatus.Done:throw $n.UnknownError.fromCode(new $n.RequestStatusDoneNoReplyErrorCode(r))}throw $n.UNREACHABLE_ERROR}async function hg(t){let{paths:e,agent:r,pollingOptions:n}=t;if(n.request&&lg(n.request))return n.request;let s=await r.createReadStateRequest?.({paths:e},void 0);if(!lg(s))throw $n.InputError.fromCode(new $n.InvalidReadStateRequestErrorCode(s));return s}});var Wh=Y(br=>{"use strict";Object.defineProperty(br,"__esModule",{value:!0});br.ACTOR_METHOD_WITH_CERTIFICATE=br.ACTOR_METHOD_WITH_HTTP_DETAILS=br.Actor=void 0;var bd=Pa(),ar=yr(),gd=Sa(),yg=_d(),Ja=Ur(),Ai=Ni(),mg=hd(),B4=ht(),vr=Symbol.for("ic-agent-metadata"),Yh=class t{static agentOf(e){return e[vr].config.agent}static interfaceOf(e){return e[vr].service}static canisterIdOf(e){return Ja.Principal.from(e[vr].config.canisterId)}static createActorClass(e,r){let n=e({IDL:gd.IDL});class s extends t{constructor(i){if(!i.canisterId)throw ar.InputError.fromCode(new ar.MissingCanisterIdErrorCode(i.canisterId));let a=typeof i.canisterId=="string"?Ja.Principal.fromText(i.canisterId):i.canisterId;super({config:{..._g,...i,canisterId:a},service:n});for(let[c,d]of n._fields)r?.httpDetails&&d.annotations.push(br.ACTOR_METHOD_WITH_HTTP_DETAILS),r?.certificate&&d.annotations.push(br.ACTOR_METHOD_WITH_CERTIFICATE),this[c]=C4(this,c,d,i.blsVerify)}}return s}static createActor(e,r){if(!r.canisterId)throw ar.InputError.fromCode(new ar.MissingCanisterIdErrorCode(r.canisterId));return new(this.createActorClass(e))(r)}static createActorWithHttpDetails(e,r){return new(this.createActorClass(e,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(e,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(e,n))(r)}constructor(e){this[vr]=Object.freeze(e)}};br.Actor=Yh;function Bi(t,e){let r=gd.IDL.decode(t,e);switch(r.length){case 0:return;case 1:return r[0];default:return r}}var _g={pollingOptions:yg.DEFAULT_POLLING_OPTIONS};br.ACTOR_METHOD_WITH_HTTP_DETAILS="http-details";br.ACTOR_METHOD_WITH_CERTIFICATE="certificate";function C4(t,e,r,n){let s;r.annotations.includes("query")||r.annotations.includes("composite_query")?s=async(i,...a)=>{i={...i,...t[vr].config.queryTransform?.(e,a,{...t[vr].config,...i})};let c=i.agent||t[vr].config.agent||new mg.HttpAgent,d=Ja.Principal.from(i.canisterId||t[vr].config.canisterId),f=gd.IDL.encode(r.argTypes,a),l=await c.query(d,{methodName:e,arg:f,effectiveCanisterId:i.effectiveCanisterId}),u={...l.httpDetails,requestDetails:l.requestDetails};switch(l.status){case bd.QueryResponseStatus.Rejected:{let p=new ar.UncertifiedRejectErrorCode(l.requestId,l.reject_code,l.reject_message,l.error_code,l.signatures);throw p.callContext={canisterId:d,methodName:e,httpDetails:u},ar.RejectError.fromCode(p)}case bd.QueryResponseStatus.Replied:return r.annotations.includes(br.ACTOR_METHOD_WITH_HTTP_DETAILS)?{httpDetails:u,result:Bi(r.retTypes,l.reply.arg)}:Bi(r.retTypes,l.reply.arg)}}:s=async(i,...a)=>{i={...i,...t[vr].config.callTransform?.(e,a,{...t[vr].config,...i})};let c=i.agent||t[vr].config.agent||mg.HttpAgent.createSync(),{canisterId:d,effectiveCanisterId:f,pollingOptions:l}={..._g,...t[vr].config,...i},u=Ja.Principal.from(d),p=f!==void 0?Ja.Principal.from(f):u,h=gd.IDL.encode(r.argTypes,a),{requestId:m,response:b,requestDetails:y}=await c.call(u,{methodName:e,arg:h,effectiveCanisterId:p,nonce:i.nonce}),x,_;if((0,bd.isV3ResponseBody)(b.body)){if(c.rootKey==null)throw ar.ExternalError.fromCode(new ar.MissingRootKeyErrorCode);let R=b.body.certificate;_=await Ai.Certificate.create({certificate:R,rootKey:c.rootKey,canisterId:p,blsVerify:n,agent:c});let A=[(0,B4.utf8ToBytes)("request_status"),m];switch(new TextDecoder().decode((0,Ai.lookupResultToBuffer)(_.lookup_path([...A,"status"])))){case"replied":x=(0,Ai.lookupResultToBuffer)(_.lookup_path([...A,"reply"]));break;case"rejected":{let S=new Uint8Array((0,Ai.lookupResultToBuffer)(_.lookup_path([...A,"reject_code"])))[0],U=new TextDecoder().decode((0,Ai.lookupResultToBuffer)(_.lookup_path([...A,"reject_message"]))),C=(0,Ai.lookupResultToBuffer)(_.lookup_path([...A,"error_code"])),g=C?new TextDecoder().decode(C):void 0,w=new ar.CertifiedRejectErrorCode(m,S,U,g);throw w.callContext={canisterId:u,methodName:e,httpDetails:b},ar.RejectError.fromCode(w)}}}else if((0,bd.isV2ResponseBody)(b.body)){let{reject_code:R,reject_message:A,error_code:E}=b.body,S=new ar.UncertifiedRejectUpdateErrorCode(m,R,A,E);throw S.callContext={canisterId:u,methodName:e,httpDetails:b},ar.RejectError.fromCode(S)}if(b.status===202){let R={...l,blsVerify:n},A=await(0,yg.pollForResponse)(c,p,m,R);_=A.certificate,x=A.reply}let T=r.annotations.includes(br.ACTOR_METHOD_WITH_HTTP_DETAILS),N=r.annotations.includes(br.ACTOR_METHOD_WITH_CERTIFICATE),v={...b,requestDetails:y};if(x!==void 0)return T&&N?{httpDetails:v,certificate:_,result:Bi(r.retTypes,x)}:N?{certificate:_,result:Bi(r.retTypes,x)}:T?{httpDetails:v,result:Bi(r.retTypes,x)}:Bi(r.retTypes,x);{let R=new ar.UnexpectedErrorCode(`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${r.retTypes.map(A=>A.display()).join(",")}].`);throw R.callContext={canisterId:u,methodName:e,httpDetails:v},ar.UnknownError.fromCode(R)}};let o=(...i)=>s({},...i);return o.withOptions=i=>(...a)=>s(i,...a),o}});var bg=Y(Kn=>{"use strict";var P4=Kn&&Kn.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),D4=Kn&&Kn.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),F4=Kn&&Kn.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[n.length]=s);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),s=0;s<n.length;s++)n[s]!=="default"&&P4(r,e,n[s]);return D4(r,e),r}})();Object.defineProperty(Kn,"__esModule",{value:!0});Kn.fetchCandid=M4;var U4=Ur(),V4=F4(rd()),L4=hd(),q4=Wh();async function M4(t,e){e||(e=await L4.HttpAgent.create());let n=(await V4.request({agent:e,canisterId:U4.Principal.fromText(t),paths:["candid"]})).get("candid");if(n)return n;let s=({IDL:i})=>i.Service({__get_candid_interface_tmp_hack:i.Func([],[i.Text],["query"])});return await q4.Actor.createActor(s,{agent:e,canisterId:t}).__get_candid_interface_tmp_hack()}});var Jh=Y(_e=>{"use strict";var gg=_e&&_e.__createBinding||(Object.create?(function(t,e,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}):(function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]})),k4=_e&&_e.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),Vt=_e&&_e.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&gg(e,t,r)},xg=_e&&_e.__importStar||(function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var n=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[n.length]=s);return n},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n=t(e),s=0;s<n.length;s++)n[s]!=="default"&&gg(r,e,n[s]);return k4(r,e),r}})();Object.defineProperty(_e,"__esModule",{value:!0});_e.ToCborValue=_e.Cbor=_e.CanisterStatus=_e.polling=_e.IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR=_e.IC_RESPONSE_DOMAIN_SEPARATOR=_e.IC_REQUEST_DOMAIN_SEPARATOR=void 0;Vt(Wh(),_e);Vt(Pa(),_e);Vt(Uu(),_e);Vt(bi(),_e);Vt(jp(),_e);Vt(Ni(),_e);var Xh=Su();Object.defineProperty(_e,"IC_REQUEST_DOMAIN_SEPARATOR",{enumerable:!0,get:function(){return Xh.IC_REQUEST_DOMAIN_SEPARATOR}});Object.defineProperty(_e,"IC_RESPONSE_DOMAIN_SEPARATOR",{enumerable:!0,get:function(){return Xh.IC_RESPONSE_DOMAIN_SEPARATOR}});Object.defineProperty(_e,"IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR",{enumerable:!0,get:function(){return Xh.IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR}});Vt(qh(),_e);Vt(yr(),_e);Vt(bg(),_e);Vt(Hh(),_e);Vt(kh(),_e);Vt(Iu(),_e);Vt(wh(),_e);Vt(_i(),_e);Vt($p(),_e);_e.polling=xg(_d());var j4=xg(rd());_e.CanisterStatus=j4;var wg=Ca();Object.defineProperty(_e,"Cbor",{enumerable:!0,get:function(){return wg.Cbor}});Object.defineProperty(_e,"ToCborValue",{enumerable:!0,get:function(){return wg.ToCborValue}});Vt(_d(),_e)});var De=Y((LR,qg)=>{"use strict";var s0=Object.defineProperty,H4=Object.getOwnPropertyDescriptor,$4=Object.getOwnPropertyNames,K4=Object.prototype.hasOwnProperty,G4=(t,e)=>{for(var r in e)s0(t,r,{get:e[r],enumerable:!0})},Z4=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of $4(e))!K4.call(t,s)&&s!==r&&s0(t,s,{get:()=>e[s],enumerable:!(n=H4(e,s))||n.enumerable});return t},z4=t=>Z4(s0({},"__esModule",{value:!0}),t),Ng={};G4(Ng,{AgentManager:()=>s8,Canister:()=>t8,FromStringToTokenError:()=>vg,ICPToken:()=>J4,InvalidPercentageError:()=>Cg,NullishError:()=>Pg,TokenAmount:()=>Q4,TokenAmountV2:()=>e8,arrayBufferToUint8Array:()=>l8,arrayOfNumberToUint8Array:()=>p8,asNonNullish:()=>i8,asciiStringToByteArray:()=>h8,assertNonNullish:()=>nc,assertPercentageNumber:()=>a8,base64ToUint8Array:()=>w8,bigEndianCrc32:()=>O8,bigIntToUint8Array:()=>u8,candidNumberArrayToBigInt:()=>_8,convertStringToE8s:()=>Rg,createAgent:()=>Ag,createServices:()=>o8,debounce:()=>C8,decodeBase32:()=>g8,defaultAgent:()=>Sg,encodeBase32:()=>b8,fromDefinedNullable:()=>D8,fromNullable:()=>o0,fromNullishNullable:()=>F8,hashObject:()=>v8,hashText:()=>Ug,hexStringToUint8Array:()=>m8,isEmptyString:()=>r8,isNullish:()=>rc,jsonReplacer:()=>Fg,jsonReviver:()=>N8,nonNullish:()=>_n,notEmptyString:()=>Ig,nowInBigIntNanoSeconds:()=>A8,numberToUint8Array:()=>d8,principalToSubAccount:()=>U8,queryAndUpdate:()=>n8,secondsToDuration:()=>I8,smallerVersion:()=>V8,toBigIntNanoSeconds:()=>B8,toNullable:()=>P8,uint8ArrayToArrayOfNumber:()=>f8,uint8ArrayToBase64:()=>x8,uint8ArrayToBigInt:()=>c8,uint8ArrayToHexString:()=>Dg,uint8ArraysEqual:()=>y8});qg.exports=z4(Ng);var vg=(t=>(t[t.FractionalMoreThan8Decimals=0]="FractionalMoreThan8Decimals",t[t.InvalidFormat=1]="InvalidFormat",t[t.FractionalTooManyDecimals=2]="FractionalTooManyDecimals",t))(vg||{}),Y4=BigInt(1e8),W4=8,Rg=t=>{let e=t.includes("e")?Number(t).toLocaleString("en",{useGrouping:!1,maximumFractionDigits:20}):t;e=e.trim().replace(/[,']/g,"");let r=e.match(/\d*(\.\d*)?/);if(!r||r[0]!==e)return 1;let[n,s]=e.split("."),o=BigInt(0);if(n)try{o+=BigInt(n)*Y4}catch{return 1}if(s){if(s.length>8)return 0;try{o+=BigInt(s.padEnd(8,"0"))}catch{return 1}}return o},X4=({amount:t,decimals:e})=>{t=t.trim().replace(/[,']/g,"");let r=t.match(/\d*(\.\d*)?/);if(!r||r[0]!==t)return 1;let[n,s]=t.split("."),o=0n,i=10n**BigInt(e);if(n)try{o+=BigInt(n)*i}catch{return 1}if(s){if(s.length>e)return 2;try{o+=BigInt(s.padEnd(e,"0"))}catch{return 1}}return o},J4={symbol:"ICP",name:"Internet Computer",decimals:8},Q4=class ec{constructor(e,r){if(this.e8s=e,this.token=r,r.decimals!==8)throw new Error("Use TokenAmountV2 for number of decimals other than 8")}static fromE8s({amount:e,token:r}){return new ec(e,r)}static fromString({amount:e,token:r}){if(r.decimals!==8)throw new Error("Use TokenAmountV2 for number of decimals other than 8");let n=Rg(e);return typeof n=="bigint"?new ec(n,r):n}static fromNumber({amount:e,token:r}){let n=ec.fromString({amount:e.toString(),token:r});if(n instanceof ec)return n;throw n===0?new Error(`Number ${e} has more than 8 decimals`):new Error(`Invalid number ${e}`)}toE8s(){return this.e8s}},e8=class tc{constructor(e,r){this.ulps=e,this.token=r}static fromUlps({amount:e,token:r}){return new tc(e,r)}static fromString({amount:e,token:r}){let n=X4({amount:e,decimals:r.decimals});return typeof n=="bigint"?new tc(n,r):n}static fromNumber({amount:e,token:r}){let n=tc.fromString({amount:e.toFixed(Math.min(W4,r.decimals)),token:r});if(n instanceof tc)return n;throw n===2?new Error(`Number ${e} has more than ${r.decimals} decimals`):new Error(`Invalid number ${e}`)}toUlps(){return this.ulps}toE8s(){return this.token.decimals<8?this.ulps*10n**BigInt(8-this.token.decimals):this.token.decimals===8?this.ulps:this.ulps/10n**BigInt(this.token.decimals-8)}},t8=class{constructor(t,e,r){this.id=t,this.service=e,this.certifiedService=r}get canisterId(){return this.id}caller=({certified:t=!0})=>t?this.certifiedService:this.service},rc=t=>t==null,_n=t=>!rc(t),Ig=t=>_n(t)&&t!=="",r8=t=>!Ig(t),n8=async({request:t,onLoad:e,onQueryError:r,onUpdateError:n,strategy:s="query_and_update",identity:o,resolution:i="race"})=>{let a=!1,c=f=>t({certified:f,identity:o}).then(l=>{a||e({certified:f,response:l})}).catch(l=>{f||r==null||r({error:l,identity:o}),!a&&(rc(n)||(console.error(l),f&&n({error:l,identity:o})))}).finally(()=>a=a||f),d=s==="query"?[c(!1)]:s==="update"?[c(!0)]:[c(!1),c(!0)];await(i==="all_settled"?Promise.allSettled(d):Promise.race(d))},Eg=Jh(),Qh=Jh(),Sg=()=>Qh.HttpAgent.createSync({host:"https://icp-api.io",identity:new Qh.AnonymousIdentity}),Ag=async({identity:t,host:e,fetchRootKey:r=!1,verifyQuerySignatures:n=!1,retryTimes:s})=>await Qh.HttpAgent.create({identity:t,..._n(e)&&{host:e},verifyQuerySignatures:n,..._n(s)&&{retryTimes:s},shouldFetchRootKey:r}),s8=class Bg{constructor(e){this.config=e}agents=void 0;static create(e){return new Bg(e)}getAgent=async({identity:e})=>{let r=e.getPrincipal().toText();if(rc(this.agents)||rc(this.agents[r])){let n=await Ag({identity:e,fetchRootKey:this.config.fetchRootKey,host:this.config.host,verifyQuerySignatures:!0});return this.agents={...this.agents??{},[r]:n},n}return this.agents[r]};clearAgents=()=>{this.agents=null}},o8=({options:{canisterId:t,serviceOverride:e,certifiedServiceOverride:r,agent:n,callTransform:s,queryTransform:o},idlFactory:i,certifiedIdlFactory:a})=>{let c=n??Sg(),d=e??Eg.Actor.createActor(i,{agent:c,canisterId:t,callTransform:s,queryTransform:o}),f=r??Eg.Actor.createActor(a,{agent:c,canisterId:t,callTransform:s,queryTransform:o});return{service:d,certifiedService:f,agent:c,canisterId:t}},Cg=class extends Error{},Pg=class extends Error{},nc=(t,e)=>{if(t==null)throw new Pg(e)},i8=(t,e)=>(nc(t,e),t),a8=t=>{if(t<0||t>100)throw new Cg(`${t} is not a valid percentage number.`)},c8=t=>{let e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(typeof e.getBigUint64=="function")return e.getBigUint64(0);let r=BigInt(e.getUint32(0)),n=BigInt(e.getUint32(4));return(r<<BigInt(32))+n},u8=t=>{let e=new ArrayBuffer(8),r=new DataView(e);if(typeof r.setBigUint64=="function")r.setBigUint64(0,t);else{let n=Number(t>>BigInt(32)),s=Number(t&BigInt(4294967295));r.setUint32(0,n),r.setUint32(4,s)}return new Uint8Array(e)},d8=t=>{let e=new DataView(new ArrayBuffer(8));for(let r=7;r>=0;--r)e.setUint8(r,t%256),t=t>>8;return new Uint8Array(e.buffer)},l8=t=>new Uint8Array(t),f8=t=>Array.from(t),p8=t=>new Uint8Array(t),h8=t=>Array.from(t).map(e=>e.charCodeAt(0)),m8=t=>{let e=t.match(/.{1,2}/g);return nc(e,"Invalid hex string."),Uint8Array.from(e.map(r=>parseInt(r,16)))},y8=({a:t,b:e})=>t.length===e.length&&t.every((r,n)=>r===e[n]),Dg=t=>(t instanceof Uint8Array||(t=Uint8Array.from(t)),t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")),_8=t=>{let e=0n;for(let r=t.length-1;r>=0;r--)e=(e<<32n)+BigInt(t[r]);return e},xd="abcdefghijklmnopqrstuvwxyz234567",Ci=Object.create(null);for(let t=0;t<xd.length;t++)Ci[xd[t]]=t;Ci[0]=Ci.o;Ci[1]=Ci.i;var b8=t=>{let e=0,r=0,n="",s=o=>(e<0?r|=o>>-e:r=o<<e&248,e>3?(e-=8,1):(e<4&&(n+=xd[r>>3],e+=5),0));for(let o=0;o<t.length;)o+=s(t[o]);return n+(e<0?xd[r>>3]:"")},g8=t=>{let e=0,r=0,n=new Uint8Array(t.length*4/3|0),s=0,o=i=>{let a=Ci[i.toLowerCase()];nc(a,`Invalid character: ${JSON.stringify(i)}`),a<<=3,r|=a>>>e,e+=5,e>=8&&(n[s++]=r,e-=8,e>0?r=a<<5-e&255:r=0)};for(let i of t)o(i);return n.slice(0,s)},x8=t=>btoa(String.fromCharCode(...new Uint8Array(t))),w8=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),E8=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]),T8=t=>{let e=-1;for(let r=0;r<t.length;r++){let n=(t[r]^e)&255;e=E8[n]^e>>>8}return(e^-1)>>>0},O8=t=>{let e=new ArrayBuffer(4);return new DataView(e).setUint32(0,T8(t),!1),new Uint8Array(e)},e0=Ur(),t0="__bigint__",r0="__principal__",n0="__uint8array__",Fg=(t,e)=>typeof e=="bigint"?{[t0]:`${e}`}:_n(e)&&e0.Principal.isPrincipal(e)?{[r0]:e0.Principal.from(e).toText()}:_n(e)&&e instanceof Uint8Array?{[n0]:Array.from(e)}:e,N8=(t,e)=>{let r=n=>e[n];return _n(e)&&typeof e=="object"&&t0 in e?BigInt(r(t0)):_n(e)&&typeof e=="object"&&r0 in e?e0.Principal.fromText(r(r0)):_n(e)&&typeof e=="object"&&n0 in e?Uint8Array.from(r(n0)):e},v8=async t=>{let e=JSON.stringify(t,Fg);return await Ug(e)},Ug=async t=>{let e=new TextEncoder().encode(t),r=await crypto.subtle.digest("SHA-256",e);return Dg(new Uint8Array(r))},R8={year:"year",year_plural:"years",month:"month",month_plural:"months",day:"day",day_plural:"days",hour:"hour",hour_plural:"hours",minute:"minute",minute_plural:"minutes",second:"second",second_plural:"seconds"},I8=({seconds:t,i18n:e=R8})=>{let r=t/BigInt(60),n=r/BigInt(60);r-=n*BigInt(60);let s=n/BigInt(24);n-=s*BigInt(24);let o=S8(s);return s-=Vg(o),[Qa({labelKey:"year",amount:o}),Qa({labelKey:"day",amount:s}),Qa({labelKey:"hour",amount:n}),Qa({labelKey:"minute",amount:r}),...t>BigInt(0)&&t<BigInt(60)?[Qa({labelKey:"second",amount:t})]:[]].filter(({amount:i})=>i>0).slice(0,2).map(i=>`${i.amount} ${i.amount===1?e[i.labelKey]:e[`${i.labelKey}_plural`]}`).join(", ")},S8=t=>{let e=t/BigInt(365);for(;Vg(e)>t;)e--;return e},Vg=t=>{let e=t/BigInt(4);return t*BigInt(365)+e},Qa=({labelKey:t,amount:e})=>({labelKey:t,amount:Number(e)}),Lg=1000000n,A8=()=>BigInt(Date.now())*Lg,B8=t=>BigInt(t.getTime())*Lg,C8=(t,e)=>{let r;return(...n)=>{let s=()=>t(...n);r&&clearTimeout(r),r=setTimeout(s,e!==void 0&&e>0?e:300)}},P8=t=>_n(t)?[t]:[],o0=t=>t?.[0],D8=t=>{let e=o0(t);return nc(e),e},F8=t=>o0(t??[]),U8=t=>{let e=t.toUint8Array(),r=new Uint8Array(32);return r[0]=e.length,r.set(e,1),r},Tg=({nums:t,amountZeros:e})=>e>t.length?[...t,...[...Array(e-t.length).keys()].map(()=>0)]:t,Og=t=>{if(!Number.isNaN(Number(t)))return Number(t);let e=t.split("").reduce((r,n)=>Number.isNaN(Number(n))?r:r+n,"");return Number(e)},V8=({minVersion:t,currentVersion:e})=>{let r=Tg({nums:t.split(".").map(Og),amountZeros:3}).join(".");return Tg({nums:e.split(".").map(Og),amountZeros:3}).join(".").localeCompare(r,void 0,{numeric:!0,sensitivity:"base"})<0}});var F2=Fe(De(),1);var Qw=Fe(De(),1);var Mg;(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"})(Mg||(Mg={}));var qs;(function(t){t.Replied="replied",t.Rejected="rejected"})(qs||(qs={}));function kg(t){return t!=null&&"reject_code"in t}function jg(t){return t!=null&&"certificate"in t}var wd="abcdefghijklmnopqrstuvwxyz234567",Pi=Object.create(null);for(let t=0;t<wd.length;t++)Pi[wd[t]]=t;Pi[0]=Pi.o;Pi[1]=Pi.i;function Hg(t){let e=0,r=0,n="";function s(o){return e<0?r|=o>>-e:r=o<<e&248,e>3?(e-=8,1):(e<4&&(n+=wd[r>>3],e+=5),0)}for(let o=0;o<t.length;)o+=s(t[o]);return n+(e<0?wd[r>>3]:"")}function $g(t){let e=0,r=0,n=new Uint8Array(t.length*4/3|0),s=0;function o(i){let a=Pi[i.toLowerCase()];if(a===void 0)throw new Error(`Invalid character: ${JSON.stringify(i)}`);a<<=3,r|=a>>>e,e+=5,e>=8&&(n[s++]=r,e-=8,e>0?r=a<<5-e&255:r=0)}for(let i of t)o(i);return n.slice(0,s)}var L8=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 Kg(t){let e=-1;for(let r=0;r<t.length;r++){let s=(t[r]^e)&255;e=L8[s]^e>>>8}return(e^-1)>>>0}import*as Gn from"node:crypto";var Io=Gn&&typeof Gn=="object"&&"webcrypto"in Gn?Gn.webcrypto:Gn&&typeof Gn=="object"&&"randomBytes"in Gn?Gn:void 0;function bn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function i0(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Qe(t,...e){if(!bn(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function a0(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Zg(t,e){Qe(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function So(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Td(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function kr(t,e){return t<<32-e|t>>>e}var zg=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",q8=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function fe(t){if(Qe(t),zg)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=q8[t[r]];return e}var Zn={_0:48,_9:57,A:65,F:70,a:97,f:102};function Gg(t){if(t>=Zn._0&&t<=Zn._9)return t-Zn._0;if(t>=Zn.A&&t<=Zn.F)return t-(Zn.A-10);if(t>=Zn.a&&t<=Zn.f)return t-(Zn.a-10)}function bt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(zg)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=Gg(t.charCodeAt(o)),a=Gg(t.charCodeAt(o+1));if(i===void 0||a===void 0){let c=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Ue(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function c0(t){return typeof t=="string"&&(t=Ue(t)),Qe(t),t}function de(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];Qe(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}var Ed=class{};function Od(t){let e=n=>t().update(c0(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Di(t=32){if(Io&&typeof Io.getRandomValues=="function")return Io.getRandomValues(new Uint8Array(t));if(Io&&typeof Io.randomBytes=="function")return Uint8Array.from(Io.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function M8(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),a=Number(r&o),c=n?4:0,d=n?0:4;t.setUint32(e+c,i,n),t.setUint32(e+d,a,n)}function Yg(t,e,r){return t&e^~t&r}function Wg(t,e,r){return t&e^t&r^e&r}var sc=class extends Ed{constructor(e,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=Td(this.buffer)}update(e){a0(this),e=c0(e),Qe(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=Td(e);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){a0(this),Zg(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,So(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let l=i;l<s;l++)r[l]=0;M8(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=Td(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=c/4,f=this.get();if(d>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)a.setUint32(4*l,f[l],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=o,e.length=s,e.pos=a,s%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},zn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Yn=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var vt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nd=BigInt(4294967295),Xg=BigInt(32);function k8(t,e=!1){return e?{h:Number(t&Nd),l:Number(t>>Xg&Nd)}:{h:Number(t>>Xg&Nd)|0,l:Number(t&Nd)|0}}function Jg(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=k8(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var u0=(t,e,r)=>t>>>r,d0=(t,e,r)=>t<<32-r|e>>>r,Ao=(t,e,r)=>t>>>r|e<<32-r,Bo=(t,e,r)=>t<<32-r|e>>>r,oc=(t,e,r)=>t<<64-r|e>>>r-32,ic=(t,e,r)=>t>>>r-32|e<<64-r;function gn(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Qg=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),ex=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,tx=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),rx=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,nx=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),sx=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;var H8=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]),Ms=new Uint32Array(64),vd=class extends sc{constructor(e=32){super(64,e,8,!1),this.A=zn[0]|0,this.B=zn[1]|0,this.C=zn[2]|0,this.D=zn[3]|0,this.E=zn[4]|0,this.F=zn[5]|0,this.G=zn[6]|0,this.H=zn[7]|0}get(){let{A:e,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,r,n,s,o,i,a,c]}set(e,r,n,s,o,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)Ms[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let u=Ms[l-15],p=Ms[l-2],h=kr(u,7)^kr(u,18)^u>>>3,m=kr(p,17)^kr(p,19)^p>>>10;Ms[l]=m+Ms[l-7]+h+Ms[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:d,H:f}=this;for(let l=0;l<64;l++){let u=kr(a,6)^kr(a,11)^kr(a,25),p=f+u+Yg(a,c,d)+H8[l]+Ms[l]|0,m=(kr(n,2)^kr(n,13)^kr(n,22))+Wg(n,s,o)|0;f=d,d=c,c=a,a=i+p|0,i=o,o=s,s=n,n=p+m|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,d=d+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,d,f)}roundClean(){So(Ms)}destroy(){this.set(0,0,0,0,0,0,0,0),So(this.buffer)}},l0=class extends vd{constructor(){super(28),this.A=Yn[0]|0,this.B=Yn[1]|0,this.C=Yn[2]|0,this.D=Yn[3]|0,this.E=Yn[4]|0,this.F=Yn[5]|0,this.G=Yn[6]|0,this.H=Yn[7]|0}},ox=Jg(["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))),$8=ox[0],K8=ox[1],ks=new Uint32Array(80),js=new Uint32Array(80),f0=class extends sc{constructor(e=64){super(128,e,16,!1),this.Ah=vt[0]|0,this.Al=vt[1]|0,this.Bh=vt[2]|0,this.Bl=vt[3]|0,this.Ch=vt[4]|0,this.Cl=vt[5]|0,this.Dh=vt[6]|0,this.Dl=vt[7]|0,this.Eh=vt[8]|0,this.El=vt[9]|0,this.Fh=vt[10]|0,this.Fl=vt[11]|0,this.Gh=vt[12]|0,this.Gl=vt[13]|0,this.Hh=vt[14]|0,this.Hl=vt[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:d,El:f,Fh:l,Fl:u,Gh:p,Gl:h,Hh:m,Hl:b}=this;return[e,r,n,s,o,i,a,c,d,f,l,u,p,h,m,b]}set(e,r,n,s,o,i,a,c,d,f,l,u,p,h,m,b){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=d|0,this.El=f|0,this.Fh=l|0,this.Fl=u|0,this.Gh=p|0,this.Gl=h|0,this.Hh=m|0,this.Hl=b|0}process(e,r){for(let _=0;_<16;_++,r+=4)ks[_]=e.getUint32(r),js[_]=e.getUint32(r+=4);for(let _=16;_<80;_++){let T=ks[_-15]|0,N=js[_-15]|0,v=Ao(T,N,1)^Ao(T,N,8)^u0(T,N,7),R=Bo(T,N,1)^Bo(T,N,8)^d0(T,N,7),A=ks[_-2]|0,E=js[_-2]|0,S=Ao(A,E,19)^oc(A,E,61)^u0(A,E,6),U=Bo(A,E,19)^ic(A,E,61)^d0(A,E,6),C=tx(R,U,js[_-7],js[_-16]),g=rx(C,v,S,ks[_-7],ks[_-16]);ks[_]=g|0,js[_]=C|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:d,Dl:f,Eh:l,El:u,Fh:p,Fl:h,Gh:m,Gl:b,Hh:y,Hl:x}=this;for(let _=0;_<80;_++){let T=Ao(l,u,14)^Ao(l,u,18)^oc(l,u,41),N=Bo(l,u,14)^Bo(l,u,18)^ic(l,u,41),v=l&p^~l&m,R=u&h^~u&b,A=nx(x,N,R,K8[_],js[_]),E=sx(A,y,T,v,$8[_],ks[_]),S=A|0,U=Ao(n,s,28)^oc(n,s,34)^oc(n,s,39),C=Bo(n,s,28)^ic(n,s,34)^ic(n,s,39),g=n&o^n&a^o&a,w=s&i^s&c^i&c;y=m|0,x=b|0,m=p|0,b=h|0,p=l|0,h=u|0,{h:l,l:u}=gn(d|0,f|0,E|0,S|0),d=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let O=Qg(S,C,w);n=ex(O,E,U,g),s=O|0}({h:n,l:s}=gn(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=gn(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=gn(this.Ch|0,this.Cl|0,a|0,c|0),{h:d,l:f}=gn(this.Dh|0,this.Dl|0,d|0,f|0),{h:l,l:u}=gn(this.Eh|0,this.El|0,l|0,u|0),{h:p,l:h}=gn(this.Fh|0,this.Fl|0,p|0,h|0),{h:m,l:b}=gn(this.Gh|0,this.Gl|0,m|0,b|0),{h:y,l:x}=gn(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,s,o,i,a,c,d,f,l,u,p,h,m,b,y,x)}roundClean(){So(ks,js)}destroy(){So(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Lt=Od(()=>new vd),ix=Od(()=>new l0),ax=Od(()=>new f0);var Rd="__principal__",G8=2,cx=4,Z8="aaaaa-aa",te=class t{static anonymous(){return new this(new Uint8Array([cx]))}static managementCanister(){return this.fromText(Z8)}static selfAuthenticating(e){let r=ix(e);return new this(new Uint8Array([...r,G8]))}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(bt(e))}static fromText(e){let r=e;if(e.includes(Rd)){let i=JSON.parse(e);Rd in i&&(r=i[Rd])}let n=r.toLowerCase().replace(/-/g,""),s=$g(n);s=s.slice(4,s.length);let o=new this(s);if(o.toText()!==r)throw new Error(`Principal "${o.toText()}" does not have a valid checksum (original value "${r}" may not be a valid Principal ID).`);return o}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]===cx}toUint8Array(){return this._arr}toHex(){return fe(this._arr).toUpperCase()}toText(){let e=new ArrayBuffer(4);new DataView(e).setUint32(0,Kg(this._arr));let n=new Uint8Array(e),s=new Uint8Array([...n,...this._arr]),i=Hg(s).match(/.{1,5}/g);if(!i)throw new Error;return i.join("-")}toString(){return this.toText()}toJSON(){return{[Rd]: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 Wn;(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"})(Wn||(Wn={}));var be=class{constructor(e=!1){this.isCertified=e}toString(){let e=this.toErrorMessage();return this.requestContext&&(e+=`
|
|
70
70
|
Request context:
|
|
71
|
-
Request ID (hex): ${this.requestContext.requestId?
|
|
72
|
-
Sender pubkey (hex): ${
|
|
73
|
-
Sender signature (hex): ${
|
|
71
|
+
Request ID (hex): ${this.requestContext.requestId?fe(this.requestContext.requestId):"undefined"}
|
|
72
|
+
Sender pubkey (hex): ${fe(this.requestContext.senderPubKey)}
|
|
73
|
+
Sender signature (hex): ${fe(this.requestContext.senderSignature)}
|
|
74
74
|
Ingress expiry: ${this.requestContext.ingressExpiry.toString()}`),this.callContext&&(e+=`
|
|
75
75
|
Call context:
|
|
76
76
|
Canister ID: ${this.callContext.canisterId.toText()}
|
|
77
77
|
Method name: ${this.callContext.methodName}
|
|
78
|
-
HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),e}},
|
|
79
|
-
`;return this.requestId&&(e+=` Request ID: ${
|
|
78
|
+
HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),e}},jr=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}`}},Xn=class extends jr{static fromCode(e){return new this(e)}},Gt=class t extends Xn{constructor(e){super(e,Wn.Trust),this.name="TrustError",Object.setPrototypeOf(this,t.prototype)}},Me=class t extends Xn{constructor(e){super(e,Wn.Protocol),this.name="ProtocolError",Object.setPrototypeOf(this,t.prototype)}},Hs=class t extends Xn{constructor(e){super(e,Wn.Reject),this.name="RejectError",Object.setPrototypeOf(this,t.prototype)}},ac=class t extends Xn{constructor(e){super(e,Wn.Transport),this.name="TransportError",Object.setPrototypeOf(this,t.prototype)}},gt=class t extends Xn{constructor(e){super(e,Wn.External),this.name="ExternalError",Object.setPrototypeOf(this,t.prototype)}};var Ne=class t extends Xn{constructor(e){super(e,Wn.Input),this.name="InputError",Object.setPrototypeOf(this,t.prototype)}},ct=class t extends Xn{constructor(e){super(e,Wn.Unknown),this.name="UnknownError",Object.setPrototypeOf(this,t.prototype)}},$s=class t extends be{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+=`: ${hc(this.error)}`),`Certificate verification error: "${e}"`}},Co=class t extends be{constructor(e,r,n,s,o){super(),this.maxAgeInMinutes=e,this.certificateTime=r,this.currentTime=n,this.timeDiffMsecs=s,this.ageType=o,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`}},Id=class t extends be{constructor(){super(),this.name="CertificateHasTooManyDelegationsErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Certificate has too many delegations"}},Fi=class t extends be{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()}`}},Jn=class t extends be{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}`}},Ui=class t extends be{constructor(e){super(),this.message=e,this.name="MalformedLookupFoundValueErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return this.message}},Sd=class t extends be{constructor(e){super(),this.message=e,this.name="MissingLookupValueErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return this.message}},Vi=class t extends be{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`}},Ad=class t extends be{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: ${fe(this.expectedPrefix)}, but got ${fe(this.actualPrefix)}`}},Bd=class t extends be{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}`}},Hr=class t extends be{constructor(e){super(),this.error=e,this.name="DerDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode DER: ${this.error}`}},cc=class t extends be{constructor(e){super(),this.error=e,this.name="DerEncodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to encode DER: ${this.error}`}},Cd=class t extends be{constructor(e,r){super(),this.error=e,this.input=r,this.name="CborDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode CBOR: ${hc(this.error)}, input: ${fe(this.input)}`}},Pd=class t extends be{constructor(e,r){super(),this.error=e,this.value=r,this.name="CborEncodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to encode CBOR: ${hc(this.error)}, input: ${this.value}`}};var Po=class t extends be{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}
|
|
79
|
+
`;return this.requestId&&(e+=` Request ID: ${fe(this.requestId)}
|
|
80
80
|
`),this.status&&(e+=` Request status: ${this.status}
|
|
81
|
-
`),e}},
|
|
82
|
-
Request ID: ${
|
|
83
|
-
`;return this.retryTimes!==void 0&&(e+=` Retried ${this.retryTimes} times.`),e}},
|
|
84
|
-
Request ID: ${
|
|
81
|
+
`),e}},Dd=class t extends be{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?
|
|
82
|
+
Request ID: ${fe(this.requestId)}
|
|
83
|
+
`;return this.retryTimes!==void 0&&(e+=` Retried ${this.retryTimes} times.`),e}},Li=class t extends be{constructor(e,r,n,s){super(!0),this.requestId=e,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=s,this.name="CertifiedRejectErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The replica returned a rejection error:
|
|
84
|
+
Request ID: ${fe(this.requestId)}
|
|
85
85
|
Reject code: ${this.rejectCode}
|
|
86
86
|
Reject text: ${this.rejectMessage}
|
|
87
87
|
Error code: ${this.rejectErrorCode}
|
|
88
|
-
`}},
|
|
89
|
-
Request ID: ${
|
|
88
|
+
`}},Fd=class t extends be{constructor(e,r,n,s,o){super(),this.requestId=e,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=s,this.signatures=o,this.name="UncertifiedRejectErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The replica returned a rejection error:
|
|
89
|
+
Request ID: ${fe(this.requestId)}
|
|
90
90
|
Reject code: ${this.rejectCode}
|
|
91
91
|
Reject text: ${this.rejectMessage}
|
|
92
92
|
Error code: ${this.rejectErrorCode}
|
|
93
|
-
`}},
|
|
94
|
-
Request ID: ${
|
|
93
|
+
`}},Ud=class t extends be{constructor(e,r,n,s){super(),this.requestId=e,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=s,this.name="UncertifiedRejectUpdateErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`The replica returned a rejection error:
|
|
94
|
+
Request ID: ${fe(this.requestId)}
|
|
95
95
|
Reject code: ${this.rejectCode}
|
|
96
96
|
Reject text: ${this.rejectMessage}
|
|
97
97
|
Error code: ${this.rejectErrorCode}
|
|
98
|
-
`}},
|
|
99
|
-
Request ID: ${
|
|
100
|
-
`}},
|
|
98
|
+
`}},Vd=class t extends be{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:
|
|
99
|
+
Request ID: ${fe(this.requestId)}
|
|
100
|
+
`}},xn=class t extends be{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.`}},Ld=class t extends be{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}`}},qi=class t extends be{constructor(e){super(),this.error=e,this.name="HttpDefaultFetchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return this.error}},Ks=class t extends be{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."}},Do=class t extends be{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.`}},qd=class t extends be{constructor(){super(),this.name="CreateHttpAgentErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Failed to create agent from provided agent"}},Md=class t extends be{constructor(e){super(),this.error=e,this.name="MalformedSignatureErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Query response contained a malformed signature: ${this.error}`}},kd=class t extends be{constructor(){super(),this.name="MissingSignatureErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Query response did not contain any node signatures"}},jd=class t extends be{constructor(){super(),this.name="MalformedPublicKeyErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"Read state response contained a malformed public key"}},Hd=class t extends be{constructor(e){super(),this.nodeId=e,this.name="QuerySignatureVerificationFailedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Query signature verification failed. Node ID: ${this.nodeId}`}},Zt=class t extends be{constructor(e){super(),this.error=e,this.name="UnexpectedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Unexpected error: ${hc(this.error)}`}},Gs=class t extends be{constructor(e){super(),this.error=e,this.name="HashTreeDecodeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to decode certificate: ${this.error}`}},uc=class t extends be{constructor(e,r,n,s){super(),this.status=e,this.statusText=r,this.headers=n,this.bodyText=s,this.name="HttpErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){let e=`HTTP request failed:
|
|
101
101
|
Status: ${this.status} (${this.statusText})
|
|
102
102
|
Headers: ${JSON.stringify(this.headers)}
|
|
103
103
|
`;return this.bodyText&&(e+=` Body: ${this.bodyText}
|
|
104
|
-
`),e}},Ha=class t extends be{constructor(){super(),this.name="HttpV3ApiNotSupportedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"HTTP request failed: v3 API is not supported"}},$a=class t extends be{constructor(e){super(),this.error=e,this.name="HttpFetchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to fetch HTTP request: ${za(this.error)}`}},Ka=class t extends be{constructor(e){super(),this.receivedCanisterId=e,this.name="MissingCanisterIdErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Canister ID is required, but received ${typeof this.receivedCanisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`}},xd=class t extends be{constructor(e){super(),this.request=e,this.name="InvalidReadStateRequestErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Invalid read state request: ${this.request}`}},Ga=class t extends be{constructor(e){super(),this.error=e,this.name="ExpiryJsonDeserializeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to deserialize expiry: ${this.error}`}};function za(t){if(t instanceof Error)return t.stack??t.message;try{return JSON.stringify(t)}catch{return String(t)}}var Po=new Error("unreachable");var gs={};G1(gs,{Bool:()=>Bg,BoolClass:()=>Nd,ConstructType:()=>hn,Empty:()=>Sg,EmptyClass:()=>Ya,FixedIntClass:()=>zn,FixedNatClass:()=>pn,Float32:()=>Vg,Float64:()=>Ug,FloatClass:()=>Ja,Func:()=>Qg,FuncClass:()=>bs,Int:()=>Dg,Int16:()=>qg,Int32:()=>Mg,Int64:()=>kg,Int8:()=>Lg,IntClass:()=>Wa,Nat:()=>Fg,Nat16:()=>Hg,Nat32:()=>$g,Nat64:()=>Kg,Nat8:()=>jg,NatClass:()=>Xa,Null:()=>Cg,NullClass:()=>ys,Opt:()=>Yg,OptClass:()=>Vo,PrimitiveType:()=>tr,Principal:()=>Gg,PrincipalClass:()=>Rd,Rec:()=>Jg,RecClass:()=>br,Record:()=>Wg,RecordClass:()=>_s,Reserved:()=>Ag,ReservedClass:()=>mn,Service:()=>ex,ServiceClass:()=>Ni,Text:()=>Pg,TextClass:()=>vd,Tuple:()=>zg,TupleClass:()=>Id,Type:()=>Ei,Unknown:()=>t8,UnknownClass:()=>Od,Variant:()=>Xg,VariantClass:()=>Oi,Vec:()=>Zg,VecClass:()=>Ti,Visitor:()=>Lh,decode:()=>e8,encode:()=>QO,resetSubtypeCache:()=>qh,subtype:()=>kh});function Ie(...t){let e=new Uint8Array(t.reduce((n,o)=>n+o.byteLength,0)),r=0;for(let n of t)e.set(n,r),r+=n.byteLength;return e}var Fr=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=fn(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 fn(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?fn(t.buffer):new Uint8Array(t)}function Ch(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 Tg(t,e){return Ch(t,e)===0}function Og(t){if(!(t instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(t.buffer,t.byteOffset,t.byteLength)}function JO(t){let r=new TextEncoder().encode(t),n=0;for(let o of r)n=(n*223+o)%2**32;return n}function Mt(t){if(/^_\d+_$/.test(t)||/^_0x[0-9a-fA-F]+_$/.test(t)){let e=+t.slice(1,-1);if(Number.isSafeInteger(e)&&e>=0&&e<2**32)return e}return JO(t)}function Ph(t){let e=BigInt(t);if(t<=0)throw new RangeError("Input must be positive");return e.toString(2).length-1}function wd(t){let e=BigInt(t);if(t<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<e}function Ng(){throw new Error("unexpected end of buffer")}function Fo(t,e){return t.byteLength<e&&Ng(),t.read(e)}function Do(t){let e=t.readUint8();return e===void 0&&Ng(),e}function ke(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:Ph(t))+1,r=new Fr(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 tt(t){let e=BigInt(1),r=BigInt(0),n;do n=Do(t),r+=BigInt(n&127).valueOf()*e,e*=BigInt(128);while(n>=128);return r}function rt(t){typeof t=="number"&&(t=BigInt(t));let e=t<BigInt(0);e&&(t=-t-BigInt(1));let r=(t===BigInt(0)?0:Ph(t))+1,n=new Fr(new Uint8Array(r),0);for(;;){let s=o(t);if(t/=BigInt(128),e&&t===BigInt(0)&&(s&64)!==0||!e&&t===BigInt(0)&&(s&64)===0){n.write(new Uint8Array([s]));break}else n.write(new Uint8Array([s|128]))}function o(s){let i=s%BigInt(128);return Number(e?BigInt(128)-i-BigInt(1):i)}return n.buffer}function Kn(t){let e=new Uint8Array(t.buffer),r=0;for(;r<e.byteLength;r++)if(e[r]<128){if((e[r]&64)===0)return tt(t);break}let n=new Uint8Array(Fo(t,r+1)),o=BigInt(0);for(let s=n.byteLength-1;s>=0;s--)o=o*BigInt(128)+BigInt(128-(n[s]&127)-1);return-o-BigInt(1)}function vg(t,e){if(BigInt(t)<BigInt(0))throw new Error("Cannot write negative values.");return Dh(t,e)}function Dh(t,e){t=BigInt(t);let r=new Fr(new Uint8Array(Math.min(1,e)),0),n=0,o=BigInt(256),s=BigInt(0),i=Number(t%o);for(r.write(new Uint8Array([i]));++n<e;)t<0&&s===BigInt(0)&&i!==0&&(s=BigInt(1)),i=Number((t/o-s)%BigInt(256)),r.write(new Uint8Array([i])),o*=BigInt(256);return r.buffer}function Fh(t,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let r=BigInt(Do(t)),n=BigInt(1),o=0;for(;++o<e;){n*=BigInt(256);let s=BigInt(Do(t));r=r+n*s}return r}function Ig(t,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let r=Fh(t,e),n=BigInt(2)**(BigInt(8)*BigInt(e-1)+BigInt(7));return r>=n&&(r-=n*BigInt(2)),r}var Be;(function(t){t[t.Null=-1]="Null",t[t.Bool=-2]="Bool",t[t.Nat=-3]="Nat",t[t.Int=-4]="Int",t[t.Float32=-13]="Float32",t[t.Float64=-14]="Float64",t[t.Text=-15]="Text",t[t.Reserved=-16]="Reserved",t[t.Empty=-17]="Empty",t[t.Opt=-18]="Opt",t[t.Vector=-19]="Vector",t[t.Record=-20]="Record",t[t.Variant=-21]="Variant",t[t.Func=-22]="Func",t[t.Service=-23]="Service",t[t.Principal=-24]="Principal"})(Be||(Be={}));var Ed="DIDL",Rg=400;function Za(t,e,r){return t.map((n,o)=>r(n,e[o]))}var Uh=class{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(e){return this._idx.has(e.name)}add(e,r){let n=this._typs.length;this._idx.set(e.name,n),this._idxRefCount.set(n,1),this._typs.push(r)}merge(e,r){let n=this._idx.get(e.name),o=this._idx.get(r);if(n===void 0)throw new Error("Missing type index for "+e);if(o===void 0)throw new Error("Missing type index for "+r);this._typs[n]=this._typs[o];let s=this._getIdxRefCount(o);this._idxRefCount.set(o,s-1),this._idx.delete(r),this._compactFromEnd()}_getIdxRefCount(e){return this._idxRefCount.get(e)||0}_compactFromEnd(){for(;this._typs.length>0;){let e=this._typs.length-1;if(this._getIdxRefCount(e)>0)break;this._typs.pop(),this._idxRefCount.delete(e)}}encode(){let e=ke(this._typs.length),r=Ie(...this._typs);return Ie(e,r)}indexOf(e){if(!this._idx.has(e))throw new Error("Missing type index for "+e);return rt(this._idx.get(e)||0)}},Lh=class{visitType(e,r){throw new Error("Not implemented")}visitPrimitive(e,r){return this.visitType(e,r)}visitEmpty(e,r){return this.visitPrimitive(e,r)}visitBool(e,r){return this.visitPrimitive(e,r)}visitNull(e,r){return this.visitPrimitive(e,r)}visitReserved(e,r){return this.visitPrimitive(e,r)}visitText(e,r){return this.visitPrimitive(e,r)}visitNumber(e,r){return this.visitPrimitive(e,r)}visitInt(e,r){return this.visitNumber(e,r)}visitNat(e,r){return this.visitNumber(e,r)}visitFloat(e,r){return this.visitPrimitive(e,r)}visitFixedInt(e,r){return this.visitNumber(e,r)}visitFixedNat(e,r){return this.visitNumber(e,r)}visitPrincipal(e,r){return this.visitPrimitive(e,r)}visitConstruct(e,r){return this.visitType(e,r)}visitVec(e,r,n){return this.visitConstruct(e,n)}visitOpt(e,r,n){return this.visitConstruct(e,n)}visitRecord(e,r,n){return this.visitConstruct(e,n)}visitTuple(e,r,n){let o=r.map((s,i)=>[`_${i}_`,s]);return this.visitRecord(e,o,n)}visitVariant(e,r,n){return this.visitConstruct(e,n)}visitRec(e,r,n){return this.visitConstruct(r,n)}visitFunc(e,r){return this.visitConstruct(e,r)}visitService(e,r){return this.visitConstruct(e,r)}},pe;(function(t){t.EmptyClass="__IDL_EmptyClass__",t.UnknownClass="__IDL_UnknownClass__",t.BoolClass="__IDL_BoolClass__",t.NullClass="__IDL_NullClass__",t.ReservedClass="__IDL_ReservedClass__",t.TextClass="__IDL_TextClass__",t.IntClass="__IDL_IntClass__",t.NatClass="__IDL_NatClass__",t.FloatClass="__IDL_FloatClass__",t.FixedIntClass="__IDL_FixedIntClass__",t.FixedNatClass="__IDL_FixedNatClass__",t.VecClass="__IDL_VecClass__",t.OptClass="__IDL_OptClass__",t.RecordClass="__IDL_RecordClass__",t.TupleClass="__IDL_TupleClass__",t.VariantClass="__IDL_VariantClass__",t.RecClass="__IDL_RecClass__",t.PrincipalClass="__IDL_PrincipalClass__",t.FuncClass="__IDL_FuncClass__",t.ServiceClass="__IDL_ServiceClass__"})(pe||(pe={}));var Ei=class{display(){return this.name}valueToString(e){return Je(e)}buildTypeTable(e){e.has(this)||this._buildTypeTableImpl(e)}},tr=class extends Ei{checkType(e){if(this.name!==e.name)throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`);return e}_buildTypeTableImpl(e){}},hn=class extends Ei{checkType(e){if(e instanceof br){let r=e.getType();if(typeof r>"u")throw new Error("type mismatch with uninitialized type");return r}throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`)}encodeType(e){return e.indexOf(this.name)}},Ya=class extends tr{get typeName(){return pe.EmptyClass}static[Symbol.hasInstance](e){return e.typeName===pe.EmptyClass}accept(e,r){return e.visitEmpty(this,r)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return rt(Be.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}},Od=class extends Ei{get typeName(){return pe.UnknownClass}static[Symbol.hasInstance](e){return e.typeName===pe.UnknownClass}checkType(e){throw new Error("Method not implemented for unknown.")}accept(e,r){throw e.visitType(this,r)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(){throw new Error("Unknown cannot appear as a function argument")}valueToString(){throw new Error("Unknown cannot appear as a value")}encodeType(){throw new Error("Unknown cannot be serialized")}decodeValue(e,r){let n=r.decodeValue(e,r);Object(n)!==n&&(n=Object(n));let o;return r instanceof br?o=()=>r.getType():o=()=>r,Object.defineProperty(n,"type",{value:o,writable:!0,enumerable:!1,configurable:!0}),n}_buildTypeTableImpl(){throw new Error("Unknown cannot be serialized")}get name(){return"Unknown"}},Nd=class extends tr{get typeName(){return pe.BoolClass}static[Symbol.hasInstance](e){return e.typeName===pe.BoolClass}accept(e,r){return e.visitBool(this,r)}covariant(e){if(typeof e=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return new Uint8Array([e?1:0])}encodeType(){return rt(Be.Bool)}decodeValue(e,r){switch(this.checkType(r),Do(e)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}},ys=class extends tr{get typeName(){return pe.NullClass}static[Symbol.hasInstance](e){return e.typeName===pe.NullClass}accept(e,r){return e.visitNull(this,r)}covariant(e){if(e===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return rt(Be.Null)}decodeValue(e,r){return this.checkType(r),null}get name(){return"null"}},mn=class extends tr{get typeName(){return pe.ReservedClass}static[Symbol.hasInstance](e){return e.typeName===pe.ReservedClass}accept(e,r){return e.visitReserved(this,r)}covariant(e){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return rt(Be.Reserved)}decodeValue(e,r){return r.name!==this.name&&r.decodeValue(e,r),null}get name(){return"reserved"}},vd=class extends tr{get typeName(){return pe.TextClass}static[Symbol.hasInstance](e){return e.typeName===pe.TextClass}accept(e,r){return e.visitText(this,r)}covariant(e){if(typeof e=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){let r=new TextEncoder().encode(e),n=ke(r.byteLength);return Ie(n,r)}encodeType(){return rt(Be.Text)}decodeValue(e,r){this.checkType(r);let n=tt(e),o=Fo(e,Number(n));return new TextDecoder("utf8",{fatal:!0}).decode(o)}get name(){return"text"}valueToString(e){return'"'+e+'"'}},Wa=class extends tr{get typeName(){return pe.IntClass}static[Symbol.hasInstance](e){return e.typeName===pe.IntClass}accept(e,r){return e.visitInt(this,r)}covariant(e){if(typeof e=="bigint"||Number.isInteger(e))return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return rt(e)}encodeType(){return rt(Be.Int)}decodeValue(e,r){return this.checkType(r),Kn(e)}get name(){return"int"}valueToString(e){return e.toString()}},Xa=class extends tr{get typeName(){return pe.NatClass}static[Symbol.hasInstance](e){return e.typeName===pe.NatClass}accept(e,r){return e.visitNat(this,r)}covariant(e){if(typeof e=="bigint"&&e>=BigInt(0)||Number.isInteger(e)&&e>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return ke(e)}encodeType(){return rt(Be.Nat)}decodeValue(e,r){return this.checkType(r),tt(e)}get name(){return"nat"}valueToString(e){return e.toString()}},Ja=class extends tr{get typeName(){return pe.FloatClass}static[Symbol.hasInstance](e){return e.typeName===pe.FloatClass}constructor(e){if(super(),this._bits=e,e!==32&&e!==64)throw new Error("not a valid float type")}accept(e,r){return e.visitFloat(this,r)}covariant(e){if(typeof e=="number"||e instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){let r=new ArrayBuffer(this._bits/8),n=new DataView(r);return this._bits===32?n.setFloat32(0,e,!0):n.setFloat64(0,e,!0),new Uint8Array(r)}encodeType(){let e=this._bits===32?Be.Float32:Be.Float64;return rt(e)}decodeValue(e,r){this.checkType(r);let n=Fo(e,this._bits/8),o=Og(n);return this._bits===32?o.getFloat32(0,!0):o.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(e){return e.toString()}},zn=class extends tr{get typeName(){return pe.FixedIntClass}static[Symbol.hasInstance](e){return e.typeName===pe.FixedIntClass}constructor(e){super(),this._bits=e}accept(e,r){return e.visitFixedInt(this,r)}covariant(e){let r=wd(this._bits-1)*BigInt(-1),n=wd(this._bits-1)-BigInt(1),o=!1;if(typeof e=="bigint")o=e>=r&&e<=n;else if(Number.isInteger(e)){let s=BigInt(e);o=s>=r&&s<=n}else o=!1;if(o)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return Dh(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return rt(-9-e)}decodeValue(e,r){this.checkType(r);let n=Ig(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`int${this._bits}`}valueToString(e){return e.toString()}},pn=class extends tr{get typeName(){return pe.FixedNatClass}static[Symbol.hasInstance](e){return e.typeName===pe.FixedNatClass}constructor(e){super(),this._bits=e}accept(e,r){return e.visitFixedNat(this,r)}covariant(e){let r=wd(this._bits),n=!1;if(typeof e=="bigint"&&e>=BigInt(0)?n=e<r:Number.isInteger(e)&&e>=0?n=BigInt(e)<r:n=!1,n)return!0;throw new Error(`Invalid ${this.display()} argument: ${Je(e)}`)}encodeValue(e){return vg(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return rt(-5-e)}decodeValue(e,r){this.checkType(r);let n=Fh(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`nat${this._bits}`}valueToString(e){return e.toString()}},Ti=class t extends hn{get typeName(){return pe.VecClass}static[Symbol.hasInstance](e){return e.typeName===pe.VecClass}constructor(e){super(),this._type=e,this._blobOptimization=!1,e instanceof pn&&e._bits===8&&(this._blobOptimization=!0)}accept(e,r){return e.visitVec(this,this._type,r)}covariant(e){let r=this._type instanceof pn?this._type._bits:this._type instanceof zn?this._type._bits:0;if(ArrayBuffer.isView(e)&&r==e.BYTES_PER_ELEMENT*8||Array.isArray(e)&&e.every((n,o)=>{try{return this._type.covariant(n)}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
104
|
+
`),e}},dc=class t extends be{constructor(){super(),this.name="HttpV3ApiNotSupportedErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return"HTTP request failed: v3 API is not supported"}},lc=class t extends be{constructor(e){super(),this.error=e,this.name="HttpFetchErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to fetch HTTP request: ${hc(this.error)}`}},fc=class t extends be{constructor(e){super(),this.receivedCanisterId=e,this.name="MissingCanisterIdErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Canister ID is required, but received ${typeof this.receivedCanisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`}},$d=class t extends be{constructor(e){super(),this.request=e,this.name="InvalidReadStateRequestErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Invalid read state request: ${this.request}`}},pc=class t extends be{constructor(e){super(),this.error=e,this.name="ExpiryJsonDeserializeErrorCode",Object.setPrototypeOf(this,t.prototype)}toErrorMessage(){return`Failed to deserialize expiry: ${this.error}`}};function hc(t){if(t instanceof Error)return t.stack??t.message;try{return JSON.stringify(t)}catch{return String(t)}}var Zs=new Error("unreachable");var Lo={};j2(Lo,{Bool:()=>_x,BoolClass:()=>Yd,ConstructType:()=>Tn,Empty:()=>mx,EmptyClass:()=>yc,FixedIntClass:()=>ts,FixedNatClass:()=>En,Float32:()=>Ex,Float64:()=>Tx,FloatClass:()=>gc,Func:()=>qx,FuncClass:()=>Vo,Int:()=>xx,Int16:()=>Nx,Int32:()=>vx,Int64:()=>Rx,Int8:()=>Ox,IntClass:()=>_c,Nat:()=>wx,Nat16:()=>Sx,Nat32:()=>Ax,Nat64:()=>Bx,Nat8:()=>Ix,NatClass:()=>bc,Null:()=>bx,NullClass:()=>Fo,Opt:()=>Fx,OptClass:()=>Ws,PrimitiveType:()=>cr,Principal:()=>Cx,PrincipalClass:()=>Jd,Rec:()=>Lx,RecClass:()=>Rr,Record:()=>Ux,RecordClass:()=>Uo,Reserved:()=>yx,ReservedClass:()=>On,Service:()=>Mx,ServiceClass:()=>Hi,Text:()=>gx,TextClass:()=>Wd,Tuple:()=>Px,TupleClass:()=>Xd,Type:()=>Mi,Unknown:()=>X8,UnknownClass:()=>zd,Variant:()=>Vx,VariantClass:()=>ji,Vec:()=>Dx,VecClass:()=>ki,Visitor:()=>g0,decode:()=>W8,encode:()=>Y8,resetSubtypeCache:()=>x0,subtype:()=>E0});function Re(...t){let e=new Uint8Array(t.reduce((n,s)=>n+s.byteLength,0)),r=0;for(let n of t)e.set(n,r),r+=n.byteLength;return e}var $r=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=wn(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 wn(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?wn(t.buffer):new Uint8Array(t)}function p0(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 ux(t,e){return p0(t,e)===0}function dx(t){if(!(t instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(t.buffer,t.byteOffset,t.byteLength)}function z8(t){let r=new TextEncoder().encode(t),n=0;for(let s of r)n=(n*223+s)%2**32;return n}function zt(t){if(/^_\d+_$/.test(t)||/^_0x[0-9a-fA-F]+_$/.test(t)){let e=+t.slice(1,-1);if(Number.isSafeInteger(e)&&e>=0&&e<2**32)return e}return z8(t)}function h0(t){let e=BigInt(t);if(t<=0)throw new RangeError("Input must be positive");return e.toString(2).length-1}function Kd(t){let e=BigInt(t);if(t<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<e}function lx(){throw new Error("unexpected end of buffer")}function Ys(t,e){return t.byteLength<e&&lx(),t.read(e)}function zs(t){let e=t.readUint8();return e===void 0&&lx(),e}function ke(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:h0(t))+1,r=new $r(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 st(t){let e=BigInt(1),r=BigInt(0),n;do n=zs(t),r+=BigInt(n&127).valueOf()*e,e*=BigInt(128);while(n>=128);return r}function ot(t){typeof t=="number"&&(t=BigInt(t));let e=t<BigInt(0);e&&(t=-t-BigInt(1));let r=(t===BigInt(0)?0:h0(t))+1,n=new $r(new Uint8Array(r),0);for(;;){let o=s(t);if(t/=BigInt(128),e&&t===BigInt(0)&&(o&64)!==0||!e&&t===BigInt(0)&&(o&64)===0){n.write(new Uint8Array([o]));break}else n.write(new Uint8Array([o|128]))}function s(o){let i=o%BigInt(128);return Number(e?BigInt(128)-i-BigInt(1):i)}return n.buffer}function Qn(t){let e=new Uint8Array(t.buffer),r=0;for(;r<e.byteLength;r++)if(e[r]<128){if((e[r]&64)===0)return st(t);break}let n=new Uint8Array(Ys(t,r+1)),s=BigInt(0);for(let o=n.byteLength-1;o>=0;o--)s=s*BigInt(128)+BigInt(128-(n[o]&127)-1);return-s-BigInt(1)}function fx(t,e){if(BigInt(t)<BigInt(0))throw new Error("Cannot write negative values.");return m0(t,e)}function m0(t,e){t=BigInt(t);let r=new $r(new Uint8Array(Math.min(1,e)),0),n=0,s=BigInt(256),o=BigInt(0),i=Number(t%s);for(r.write(new Uint8Array([i]));++n<e;)t<0&&o===BigInt(0)&&i!==0&&(o=BigInt(1)),i=Number((t/s-o)%BigInt(256)),r.write(new Uint8Array([i])),s*=BigInt(256);return r.buffer}function y0(t,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let r=BigInt(zs(t)),n=BigInt(1),s=0;for(;++s<e;){n*=BigInt(256);let o=BigInt(zs(t));r=r+n*o}return r}function px(t,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let r=y0(t,e),n=BigInt(2)**(BigInt(8)*BigInt(e-1)+BigInt(7));return r>=n&&(r-=n*BigInt(2)),r}var Be;(function(t){t[t.Null=-1]="Null",t[t.Bool=-2]="Bool",t[t.Nat=-3]="Nat",t[t.Int=-4]="Int",t[t.Float32=-13]="Float32",t[t.Float64=-14]="Float64",t[t.Text=-15]="Text",t[t.Reserved=-16]="Reserved",t[t.Empty=-17]="Empty",t[t.Opt=-18]="Opt",t[t.Vector=-19]="Vector",t[t.Record=-20]="Record",t[t.Variant=-21]="Variant",t[t.Func=-22]="Func",t[t.Service=-23]="Service",t[t.Principal=-24]="Principal"})(Be||(Be={}));var Gd="DIDL",hx=400;function mc(t,e,r){return t.map((n,s)=>r(n,e[s]))}var b0=class{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(e){return this._idx.has(e.name)}add(e,r){let n=this._typs.length;this._idx.set(e.name,n),this._idxRefCount.set(n,1),this._typs.push(r)}merge(e,r){let n=this._idx.get(e.name),s=this._idx.get(r);if(n===void 0)throw new Error("Missing type index for "+e);if(s===void 0)throw new Error("Missing type index for "+r);this._typs[n]=this._typs[s];let o=this._getIdxRefCount(n),i=this._getIdxRefCount(s);this._idxRefCount.set(n,o+i),this._idx.set(r,n),this._idxRefCount.set(s,0),this._compactFromEnd()}_getIdxRefCount(e){return this._idxRefCount.get(e)||0}_compactFromEnd(){for(;this._typs.length>0;){let e=this._typs.length-1;if(this._getIdxRefCount(e)>0)break;this._typs.pop(),this._idxRefCount.delete(e)}}encode(){let e=ke(this._typs.length),r=Re(...this._typs);return Re(e,r)}indexOf(e){if(!this._idx.has(e))throw new Error("Missing type index for "+e);return ot(this._idx.get(e)||0)}},g0=class{visitType(e,r){throw new Error("Not implemented")}visitPrimitive(e,r){return this.visitType(e,r)}visitEmpty(e,r){return this.visitPrimitive(e,r)}visitBool(e,r){return this.visitPrimitive(e,r)}visitNull(e,r){return this.visitPrimitive(e,r)}visitReserved(e,r){return this.visitPrimitive(e,r)}visitText(e,r){return this.visitPrimitive(e,r)}visitNumber(e,r){return this.visitPrimitive(e,r)}visitInt(e,r){return this.visitNumber(e,r)}visitNat(e,r){return this.visitNumber(e,r)}visitFloat(e,r){return this.visitPrimitive(e,r)}visitFixedInt(e,r){return this.visitNumber(e,r)}visitFixedNat(e,r){return this.visitNumber(e,r)}visitPrincipal(e,r){return this.visitPrimitive(e,r)}visitConstruct(e,r){return this.visitType(e,r)}visitVec(e,r,n){return this.visitConstruct(e,n)}visitOpt(e,r,n){return this.visitConstruct(e,n)}visitRecord(e,r,n){return this.visitConstruct(e,n)}visitTuple(e,r,n){let s=r.map((o,i)=>[`_${i}_`,o]);return this.visitRecord(e,s,n)}visitVariant(e,r,n){return this.visitConstruct(e,n)}visitRec(e,r,n){return this.visitConstruct(r,n)}visitFunc(e,r){return this.visitConstruct(e,r)}visitService(e,r){return this.visitConstruct(e,r)}},le;(function(t){t.EmptyClass="__IDL_EmptyClass__",t.UnknownClass="__IDL_UnknownClass__",t.BoolClass="__IDL_BoolClass__",t.NullClass="__IDL_NullClass__",t.ReservedClass="__IDL_ReservedClass__",t.TextClass="__IDL_TextClass__",t.IntClass="__IDL_IntClass__",t.NatClass="__IDL_NatClass__",t.FloatClass="__IDL_FloatClass__",t.FixedIntClass="__IDL_FixedIntClass__",t.FixedNatClass="__IDL_FixedNatClass__",t.VecClass="__IDL_VecClass__",t.OptClass="__IDL_OptClass__",t.RecordClass="__IDL_RecordClass__",t.TupleClass="__IDL_TupleClass__",t.VariantClass="__IDL_VariantClass__",t.RecClass="__IDL_RecClass__",t.PrincipalClass="__IDL_PrincipalClass__",t.FuncClass="__IDL_FuncClass__",t.ServiceClass="__IDL_ServiceClass__"})(le||(le={}));var Mi=class{display(){return this.name}valueToString(e){return et(e)}buildTypeTable(e){e.has(this)||this._buildTypeTableImpl(e)}},cr=class extends Mi{checkType(e){if(this.name!==e.name)throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`);return e}_buildTypeTableImpl(e){}},Tn=class extends Mi{checkType(e){if(e instanceof Rr){let r=e.getType();if(typeof r>"u")throw new Error("type mismatch with uninitialized type");return r}throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`)}encodeType(e){return e.indexOf(this.name)}},yc=class extends cr{get typeName(){return le.EmptyClass}static[Symbol.hasInstance](e){return e.typeName===le.EmptyClass}accept(e,r){return e.visitEmpty(this,r)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return ot(Be.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}},zd=class extends Mi{get typeName(){return le.UnknownClass}static[Symbol.hasInstance](e){return e.typeName===le.UnknownClass}checkType(e){throw new Error("Method not implemented for unknown.")}accept(e,r){throw e.visitType(this,r)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(){throw new Error("Unknown cannot appear as a function argument")}valueToString(){throw new Error("Unknown cannot appear as a value")}encodeType(){throw new Error("Unknown cannot be serialized")}decodeValue(e,r){let n=r.decodeValue(e,r);Object(n)!==n&&(n=Object(n));let s;return r instanceof Rr?s=()=>r.getType():s=()=>r,Object.defineProperty(n,"type",{value:s,writable:!0,enumerable:!1,configurable:!0}),n}_buildTypeTableImpl(){throw new Error("Unknown cannot be serialized")}get name(){return"Unknown"}},Yd=class extends cr{get typeName(){return le.BoolClass}static[Symbol.hasInstance](e){return e.typeName===le.BoolClass}accept(e,r){return e.visitBool(this,r)}covariant(e){if(typeof e=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){return new Uint8Array([e?1:0])}encodeType(){return ot(Be.Bool)}decodeValue(e,r){switch(this.checkType(r),zs(e)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}},Fo=class extends cr{get typeName(){return le.NullClass}static[Symbol.hasInstance](e){return e.typeName===le.NullClass}accept(e,r){return e.visitNull(this,r)}covariant(e){if(e===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return ot(Be.Null)}decodeValue(e,r){return this.checkType(r),null}get name(){return"null"}},On=class extends cr{get typeName(){return le.ReservedClass}static[Symbol.hasInstance](e){return e.typeName===le.ReservedClass}accept(e,r){return e.visitReserved(this,r)}covariant(e){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return ot(Be.Reserved)}decodeValue(e,r){return r.name!==this.name&&r.decodeValue(e,r),null}get name(){return"reserved"}},Wd=class extends cr{get typeName(){return le.TextClass}static[Symbol.hasInstance](e){return e.typeName===le.TextClass}accept(e,r){return e.visitText(this,r)}covariant(e){if(typeof e=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){let r=new TextEncoder().encode(e),n=ke(r.byteLength);return Re(n,r)}encodeType(){return ot(Be.Text)}decodeValue(e,r){this.checkType(r);let n=st(e),s=Ys(e,Number(n));return new TextDecoder("utf8",{fatal:!0}).decode(s)}get name(){return"text"}valueToString(e){return'"'+e+'"'}},_c=class extends cr{get typeName(){return le.IntClass}static[Symbol.hasInstance](e){return e.typeName===le.IntClass}accept(e,r){return e.visitInt(this,r)}covariant(e){if(typeof e=="bigint"||Number.isInteger(e))return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){return ot(e)}encodeType(){return ot(Be.Int)}decodeValue(e,r){return this.checkType(r),Qn(e)}get name(){return"int"}valueToString(e){return e.toString()}},bc=class extends cr{get typeName(){return le.NatClass}static[Symbol.hasInstance](e){return e.typeName===le.NatClass}accept(e,r){return e.visitNat(this,r)}covariant(e){if(typeof e=="bigint"&&e>=BigInt(0)||Number.isInteger(e)&&e>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){return ke(e)}encodeType(){return ot(Be.Nat)}decodeValue(e,r){return this.checkType(r),st(e)}get name(){return"nat"}valueToString(e){return e.toString()}},gc=class extends cr{get typeName(){return le.FloatClass}static[Symbol.hasInstance](e){return e.typeName===le.FloatClass}constructor(e){if(super(),this._bits=e,e!==32&&e!==64)throw new Error("not a valid float type")}accept(e,r){return e.visitFloat(this,r)}covariant(e){if(typeof e=="number"||e instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){let r=new ArrayBuffer(this._bits/8),n=new DataView(r);return this._bits===32?n.setFloat32(0,e,!0):n.setFloat64(0,e,!0),new Uint8Array(r)}encodeType(){let e=this._bits===32?Be.Float32:Be.Float64;return ot(e)}decodeValue(e,r){this.checkType(r);let n=Ys(e,this._bits/8),s=dx(n);return this._bits===32?s.getFloat32(0,!0):s.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(e){return e.toString()}},ts=class extends cr{get typeName(){return le.FixedIntClass}static[Symbol.hasInstance](e){return e.typeName===le.FixedIntClass}constructor(e){super(),this._bits=e}accept(e,r){return e.visitFixedInt(this,r)}covariant(e){let r=Kd(this._bits-1)*BigInt(-1),n=Kd(this._bits-1)-BigInt(1),s=!1;if(typeof e=="bigint")s=e>=r&&e<=n;else if(Number.isInteger(e)){let o=BigInt(e);s=o>=r&&o<=n}else s=!1;if(s)return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){return m0(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return ot(-9-e)}decodeValue(e,r){this.checkType(r);let n=px(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`int${this._bits}`}valueToString(e){return e.toString()}},En=class extends cr{get typeName(){return le.FixedNatClass}static[Symbol.hasInstance](e){return e.typeName===le.FixedNatClass}constructor(e){super(),this._bits=e}accept(e,r){return e.visitFixedNat(this,r)}covariant(e){let r=Kd(this._bits),n=!1;if(typeof e=="bigint"&&e>=BigInt(0)?n=e<r:Number.isInteger(e)&&e>=0?n=BigInt(e)<r:n=!1,n)return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){return fx(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return ot(-5-e)}decodeValue(e,r){this.checkType(r);let n=y0(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`nat${this._bits}`}valueToString(e){return e.toString()}},ki=class t extends Tn{get typeName(){return le.VecClass}static[Symbol.hasInstance](e){return e.typeName===le.VecClass}constructor(e){super(),this._type=e,this._blobOptimization=!1,e instanceof En&&e._bits===8&&(this._blobOptimization=!0)}accept(e,r){return e.visitVec(this,this._type,r)}covariant(e){let r=this._type instanceof En?this._type._bits:this._type instanceof ts?this._type._bits:0;if(ArrayBuffer.isView(e)&&r==e.BYTES_PER_ELEMENT*8||Array.isArray(e)&&e.every((n,s)=>{try{return this._type.covariant(n)}catch(o){throw new Error(`Invalid ${this.display()} argument:
|
|
105
105
|
|
|
106
|
-
index ${
|
|
106
|
+
index ${s} -> ${o.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){let r=ke(e.length);if(this._blobOptimization)return Re(r,new Uint8Array(e));if(ArrayBuffer.isView(e))if(e instanceof Int16Array||e instanceof Uint16Array){let s=new DataView(new ArrayBuffer(e.length*2));for(let o=0;o<e.length;o++)e instanceof Int16Array?s.setInt16(o*2,e[o],!0):s.setUint16(o*2,e[o],!0);return Re(r,new Uint8Array(s.buffer))}else if(e instanceof Int32Array||e instanceof Uint32Array){let s=new DataView(new ArrayBuffer(e.length*4));for(let o=0;o<e.length;o++)e instanceof Int32Array?s.setInt32(o*4,e[o],!0):s.setUint32(o*4,e[o],!0);return Re(r,new Uint8Array(s.buffer))}else if(e instanceof BigInt64Array||e instanceof BigUint64Array){let s=new DataView(new ArrayBuffer(e.length*8));for(let o=0;o<e.length;o++)e instanceof BigInt64Array?s.setBigInt64(o*8,e[o],!0):s.setBigUint64(o*8,e[o],!0);return Re(r,new Uint8Array(s.buffer))}else return Re(r,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));let n=new $r(new Uint8Array(r.byteLength+e.length),0);n.write(r);for(let s of e){let o=this._type.encodeValue(s);n.write(new Uint8Array(o))}return n.buffer}_buildTypeTableImpl(e){this._type.buildTypeTable(e);let r=ot(Be.Vector),n=this._type.encodeType(e);e.add(this,Re(r,n))}decodeValue(e,r){let n=this.checkType(r);if(!(n instanceof t))throw new Error("Not a vector type");let s=Number(st(e));if(this._type instanceof En){if(this._type._bits==8)return new Uint8Array(e.read(s));if(this._type._bits==16){let i=e.read(s*2);return new Uint16Array(i.buffer,i.byteOffset,s)}if(this._type._bits==32){let i=e.read(s*4);return new Uint32Array(i.buffer,i.byteOffset,s)}if(this._type._bits==64)return new BigUint64Array(e.read(s*8).buffer)}if(this._type instanceof ts){if(this._type._bits==8)return new Int8Array(e.read(s));if(this._type._bits==16){let i=e.read(s*2),a=new DataView(i.buffer,i.byteOffset,i.byteLength),c=new Int16Array(s);for(let d=0;d<s;d++)c[d]=a.getInt16(d*2,!0);return c}if(this._type._bits==32){let i=e.read(s*4),a=new DataView(i.buffer,i.byteOffset,i.byteLength),c=new Int32Array(s);for(let d=0;d<s;d++)c[d]=a.getInt32(d*4,!0);return c}if(this._type._bits==64){let i=e.read(s*8),a=new DataView(i.buffer,i.byteOffset,i.byteLength),c=new BigInt64Array(s);for(let d=0;d<s;d++)c[d]=a.getBigInt64(d*8,!0);return c}}let o=[];for(let i=0;i<s;i++)o.push(this._type.decodeValue(e,n._type));return o}get name(){return`vec ${this._type.name}`}display(){return`vec ${this._type.display()}`}valueToString(e){return"vec {"+e.map(n=>this._type.valueToString(n)).join("; ")+"}"}},Ws=class t extends Tn{get typeName(){return le.OptClass}static[Symbol.hasInstance](e){return e.typeName===le.OptClass}constructor(e){super(),this._type=e}accept(e,r){return e.visitOpt(this,this._type,r)}covariant(e){try{if(Array.isArray(e)&&(e.length===0||e.length===1&&this._type.covariant(e[0])))return!0}catch(r){throw new Error(`Invalid ${this.display()} argument: ${et(e)}
|
|
107
107
|
|
|
108
|
-
-> ${r.message}`)}throw new Error(`Invalid ${this.display()} argument: ${
|
|
108
|
+
-> ${r.message}`)}throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){return e.length===0?new Uint8Array([0]):Re(new Uint8Array([1]),this._type.encodeValue(e[0]))}_buildTypeTableImpl(e){this._type.buildTypeTable(e);let r=ot(Be.Opt),n=this._type.encodeType(e);e.add(this,Re(r,n))}decodeValue(e,r){if(r instanceof Fo)return[];if(r instanceof On)return[];let n=r;if(r instanceof Rr){let s=r.getType();if(typeof s>"u")throw new Error("type mismatch with uninitialized type");n=s}if(n instanceof t)switch(zs(e)){case 0:return[];case 1:{let s=e.save();try{return[this._type.decodeValue(e,n._type)]}catch{return e.restore(s),n._type.decodeValue(e,n._type),[]}}default:throw new Error("Not an option value")}else{if(this._type instanceof Fo||this._type instanceof t||this._type instanceof On)return n.decodeValue(e,n),[];{let s=e.save();try{return[this._type.decodeValue(e,r)]}catch{return e.restore(s),n.decodeValue(e,r),[]}}}}get name(){return`opt ${this._type.name}`}display(){return`opt ${this._type.display()}`}valueToString(e){return e.length===0?"null":`opt ${this._type.valueToString(e[0])}`}},Uo=class t extends Tn{get typeName(){return le.RecordClass}static[Symbol.hasInstance](e){return e.typeName===le.RecordClass||e.typeName===le.TupleClass}constructor(e={}){super(),this._fields=Object.entries(e).sort((r,n)=>zt(r[0])-zt(n[0]))}accept(e,r){return e.visitRecord(this,this._fields,r)}tryAsTuple(){let e=[];for(let r=0;r<this._fields.length;r++){let[n,s]=this._fields[r];if(n!==`_${r}_`)return null;e.push(s)}return e}covariant(e){if(typeof e=="object"&&this._fields.every(([r,n])=>{if(!e.hasOwnProperty(r))throw new Error(`Record is missing key "${r}".`);try{return n.covariant(e[r])}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
109
109
|
|
|
110
|
-
field ${r} -> ${
|
|
110
|
+
field ${r} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){let r=this._fields.map(([s])=>e[s]),n=mc(this._fields,r,([,s],o)=>s.encodeValue(o));return Re(...n)}_buildTypeTableImpl(e){this._fields.forEach(([o,i])=>i.buildTypeTable(e));let r=ot(Be.Record),n=ke(this._fields.length),s=this._fields.map(([o,i])=>Re(ke(zt(o)),i.encodeType(e)));e.add(this,Re(r,n,Re(...s)))}decodeValue(e,r){let n=this.checkType(r);if(!(n instanceof t))throw new Error("Not a record type");let s={},o=0,i=0;for(;i<n._fields.length;){let[a,c]=n._fields[i];if(o>=this._fields.length){c.decodeValue(e,c),i++;continue}let[d,f]=this._fields[o],l=zt(this._fields[o][0]),u=zt(a);if(l===u)s[d]=f.decodeValue(e,c),o++,i++;else if(u>l)if(f instanceof Ws||f instanceof On)s[d]=[],o++;else throw new Error("Cannot find required field "+d);else c.decodeValue(e,c),i++}for(let[a,c]of this._fields.slice(o))if(c instanceof Ws||c instanceof On)s[a]=[];else throw new Error("Cannot find required field "+a);return s}get fieldsAsObject(){let e={};for(let[r,n]of this._fields)e[zt(r)]=n;return e}get name(){return`record {${this._fields.map(([r,n])=>r+":"+n.name).join("; ")}}`}display(){return`record {${this._fields.map(([r,n])=>r+":"+n.display()).join("; ")}}`}valueToString(e){let r=this._fields.map(([s])=>e[s]);return`record {${mc(this._fields,r,([s,o],i)=>s+"="+o.valueToString(i)).join("; ")}}`}},Xd=class t extends Uo{get typeName(){return le.TupleClass}static[Symbol.hasInstance](e){return e.typeName===le.TupleClass}constructor(e){let r={};e.forEach((n,s)=>r["_"+s+"_"]=n),super(r),this._components=e}accept(e,r){return e.visitTuple(this,this._components,r)}covariant(e){if(Array.isArray(e)&&e.length>=this._fields.length&&this._components.every((r,n)=>{try{return r.covariant(e[n])}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
111
111
|
|
|
112
|
-
index ${n} -> ${
|
|
112
|
+
index ${n} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){let r=mc(this._components,e,(n,s)=>n.encodeValue(s));return Re(...r)}decodeValue(e,r){let n=this.checkType(r);if(!(n instanceof t))throw new Error("not a tuple type");if(n._components.length<this._components.length)throw new Error("tuple mismatch");let s=[];for(let[o,i]of n._components.entries())o>=this._components.length?i.decodeValue(e,i):s.push(this._components[o].decodeValue(e,i));return s}display(){return`record {${this._components.map(r=>r.display()).join("; ")}}`}valueToString(e){return`record {${mc(this._components,e,(n,s)=>n.valueToString(s)).join("; ")}}`}},ji=class t extends Tn{get typeName(){return le.VariantClass}static[Symbol.hasInstance](e){return e.typeName===le.VariantClass}constructor(e={}){super(),this._fields=Object.entries(e).sort((r,n)=>zt(r[0])-zt(n[0]))}accept(e,r){return e.visitVariant(this,this._fields,r)}covariant(e){if(typeof e=="object"&&Object.entries(e).length===1&&this._fields.every(([r,n])=>{try{return!e.hasOwnProperty(r)||n.covariant(e[r])}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
113
113
|
|
|
114
|
-
variant ${r} -> ${
|
|
114
|
+
variant ${r} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){for(let r=0;r<this._fields.length;r++){let[n,s]=this._fields[r];if(e.hasOwnProperty(n)){let o=ke(r),i=s.encodeValue(e[n]);return Re(o,i)}}throw Error("Variant has no data: "+e)}_buildTypeTableImpl(e){this._fields.forEach(([,o])=>{o.buildTypeTable(e)});let r=ot(Be.Variant),n=ke(this._fields.length),s=this._fields.map(([o,i])=>Re(ke(zt(o)),i.encodeType(e)));e.add(this,Re(r,n,...s))}decodeValue(e,r){let n=this.checkType(r);if(!(n instanceof t))throw new Error("Not a variant type");let s=Number(st(e));if(s>=n._fields.length)throw Error("Invalid variant index: "+s);let[o,i]=n._fields[s];for(let[a,c]of this._fields)if(zt(o)===zt(a)){let d=c.decodeValue(e,i);return{[a]:d}}throw new Error("Cannot find field hash "+o)}get name(){return`variant {${this._fields.map(([r,n])=>r+":"+n.name).join("; ")}}`}display(){return`variant {${this._fields.map(([r,n])=>r+(n.name==="null"?"":`:${n.display()}`)).join("; ")}}`}valueToString(e){for(let[r,n]of this._fields)if(e.hasOwnProperty(r)){let s=n.valueToString(e[r]);return s==="null"?`variant {${r}}`:`variant {${r}=${s}}`}throw new Error("Variant has no data: "+e)}get alternativesAsObject(){let e={};for(let[r,n]of this._fields)e[zt(r)]=n;return e}},Rr=class t extends Tn{constructor(){super(...arguments),this._id=t._counter++}get typeName(){return le.RecClass}static{this._counter=0}static[Symbol.hasInstance](e){return e.typeName===le.RecClass}accept(e,r){if(!this._type)throw Error("Recursive type uninitialized.");return e.visitRec(this,this._type,r)}fill(e){this._type=e}getType(){return this._type}covariant(e){if(this._type&&this._type.covariant(e))return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.encodeValue(e)}_buildTypeTableImpl(e){if(!this._type)throw Error("Recursive type uninitialized.");e.add(this,new Uint8Array([])),this._type.buildTypeTable(e),e.merge(this,this._type.name)}decodeValue(e,r){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.decodeValue(e,r)}get name(){return`rec_${this._id}`}display(){if(!this._type)throw Error("Recursive type uninitialized.");return`\u03BC${this.name}.${this._type.name}`}valueToString(e){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.valueToString(e)}};function w0(t){if(zs(t)!==1)throw new Error("Cannot decode principal");let r=Number(st(t));return te.fromUint8Array(new Uint8Array(Ys(t,r)))}var Jd=class extends cr{get typeName(){return le.PrincipalClass}static[Symbol.hasInstance](e){return e.typeName===le.PrincipalClass}accept(e,r){return e.visitPrincipal(this,r)}covariant(e){if(e&&e._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){let r=e.toUint8Array(),n=ke(r.byteLength);return Re(new Uint8Array([1]),n,r)}encodeType(){return ot(Be.Principal)}decodeValue(e,r){return this.checkType(r),w0(e)}get name(){return"principal"}valueToString(e){return`${this.name} "${e.toText()}"`}},Vo=class extends Tn{get typeName(){return le.FuncClass}static[Symbol.hasInstance](e){return e.typeName===le.FuncClass}static argsToString(e,r){if(e.length!==r.length)throw new Error("arity mismatch");return"("+e.map((n,s)=>n.valueToString(r[s])).join(", ")+")"}constructor(e,r,n=[]){super(),this.argTypes=e,this.retTypes=r,this.annotations=n}accept(e,r){return e.visitFunc(this,r)}covariant(e){if(Array.isArray(e)&&e.length===2&&e[0]&&e[0]._isPrincipal&&typeof e[1]=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue([e,r]){let n=e.toUint8Array(),s=ke(n.byteLength),o=Re(new Uint8Array([1]),s,n),i=new TextEncoder().encode(r),a=ke(i.byteLength);return Re(new Uint8Array([1]),o,a,i)}_buildTypeTableImpl(e){this.argTypes.forEach(d=>d.buildTypeTable(e)),this.retTypes.forEach(d=>d.buildTypeTable(e));let r=ot(Be.Func),n=ke(this.argTypes.length),s=Re(...this.argTypes.map(d=>d.encodeType(e))),o=ke(this.retTypes.length),i=Re(...this.retTypes.map(d=>d.encodeType(e))),a=ke(this.annotations.length),c=Re(...this.annotations.map(d=>this.encodeAnnotation(d)));e.add(this,Re(r,n,s,o,i,a,c))}decodeValue(e,r){let n=r instanceof Rr?r.getType()??r:r;if(!E0(n,this))throw new Error(`Cannot decode function reference at type ${this.display()} from wire type ${n.display()}`);if(zs(e)!==1)throw new Error("Cannot decode function reference");let o=w0(e),i=Number(st(e)),a=Ys(e,i),d=new TextDecoder("utf8",{fatal:!0}).decode(a);return[o,d]}get name(){let e=this.argTypes.map(s=>s.name).join(", "),r=this.retTypes.map(s=>s.name).join(", "),n=" "+this.annotations.join(" ");return`(${e}) -> (${r})${n}`}valueToString([e,r]){return`func "${e.toText()}".${r}`}display(){let e=this.argTypes.map(s=>s.display()).join(", "),r=this.retTypes.map(s=>s.display()).join(", "),n=" "+this.annotations.join(" ");return`(${e}) \u2192 (${r})${n}`}encodeAnnotation(e){if(e==="query")return new Uint8Array([1]);if(e==="oneway")return new Uint8Array([2]);if(e==="composite_query")return new Uint8Array([3]);throw new Error("Illegal function annotation")}},Hi=class extends Tn{get typeName(){return le.ServiceClass}static[Symbol.hasInstance](e){return e.typeName===le.ServiceClass}constructor(e){super(),this._fields=Object.entries(e).sort((r,n)=>r[0]<n[0]?-1:r[0]>n[0]?1:0)}accept(e,r){return e.visitService(this,r)}covariant(e){if(e&&e._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${et(e)}`)}encodeValue(e){let r=e.toUint8Array(),n=ke(r.length);return Re(new Uint8Array([1]),n,r)}_buildTypeTableImpl(e){this._fields.forEach(([o,i])=>i.buildTypeTable(e));let r=ot(Be.Service),n=ke(this._fields.length),s=this._fields.map(([o,i])=>{let a=new TextEncoder().encode(o),c=ke(a.length);return Re(c,a,i.encodeType(e))});e.add(this,Re(r,n,...s))}decodeValue(e,r){let n=r instanceof Rr?r.getType()??r:r;if(!E0(n,this))throw new Error(`Cannot decode service reference at type ${this.display()} from wire type ${n.display()}`);return w0(e)}get name(){return`service {${this._fields.map(([r,n])=>r+":"+n.name).join("; ")}}`}valueToString(e){return`service "${e.toText()}"`}fieldsAsObject(){let e={};for(let[r,n]of this._fields)e[r]=n;return e}};function et(t){let e=JSON.stringify(t,(r,n)=>typeof n=="bigint"?`BigInt(${n})`:n);return e&&e.length>hx?e.substring(0,hx-3)+"...":e}function Y8(t,e){if(e.length<t.length)throw Error("Wrong number of message arguments");let r=new b0;t.forEach(c=>c.buildTypeTable(r));let n=new TextEncoder().encode(Gd),s=r.encode(),o=ke(e.length),i=Re(...t.map(c=>c.encodeType(r))),a=Re(...mc(t,e,(c,d)=>{try{c.covariant(d)}catch(f){throw new Error(f.message+`
|
|
115
115
|
|
|
116
|
-
`)}return c.encodeValue(d)}));return
|
|
117
|
-
`;return e}addNames(e,r,n){let
|
|
118
|
-
ic-request`),Hh=new TextEncoder().encode("\vic-response"),$h=new TextEncoder().encode("ic-request-auth-delegation");var yn=class{getPrincipal(){return this._principal||(this._principal=oe.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:r,...n}=e,o=Zn(r);return{...n,body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(fe(ec,o))}}}},gr=class{getPrincipal(){return oe.anonymous()}async transformRequest(e){return{...e,body:{content:e.body}}}};var Yn=class extends Error{constructor(e){super(e),this.name="DecodingError"}},nx=55799,ox=Symbol("CBOR_STOP_CODE"),Lr=(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))(Lr||{}),at=(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))(at||{}),n8=23,o8=255,s8=65535,i8=4294967295,a8=BigInt("0xffffffffffffffff"),Ur=(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))(Ur||{}),Ii=!1;function c8(t){return t==null}function sx(t,e){let r=new Uint8Array(e);return r.set(t),r}var u8=new TextDecoder;function d8(t){return(t&224)>>5}function l8(t){return t&31}var nc=new Uint8Array,tc,qr=0;function ix(t,e){nc=t,qr=0;let r=ws(e);return e?.(r)??r}function ws(t){let[e,r]=Ad();switch(e){case at.UnsignedInteger:return Ri(r);case at.NegativeInteger:return m8(r);case at.ByteString:return ax(r);case at.TextString:return Gh(r);case at.Array:return f8(r,t);case at.Map:return h8(r,t);case at.Tag:return y8(r,t);case at.Simple:return p8(r)}throw new Yn(`Unsupported major type: ${e}`)}function Ad(){let t=nc.at(qr);if(c8(t))throw new Yn("Provided CBOR data is empty");let e=d8(t),r=l8(t);return qr++,[e,r]}function f8(t,e){let r=Ri(t);if(r===1/0){let o=[],s=ws(e);for(;s!==ox;)o.push(e?.(s)??s),s=ws(e);return o}let n=new Array(r);for(let o=0;o<r;o++){let s=ws(e);n[o]=e?.(s)??s}return n}function p8(t){switch(t){case Lr.False:return!1;case Lr.True:return!0;case Lr.Null:return null;case Lr.Undefined:return;case Lr.Break:return ox}throw new Yn(`Unrecognized simple type: ${t.toString(2)}`)}function h8(t,e){let r=Ri(t),n={};if(r===1/0){let[o,s]=Ad();for(;o!==at.Simple&&s!==Lr.Break;){let i=Gh(s),a=ws(e);n[i]=e?.(a,i)??a,[o,s]=Ad()}return n}for(let o=0;o<r;o++){let[s,i]=Ad();if(s!==at.TextString)throw new Yn("Map keys must be text strings");let a=Gh(i),c=ws(e);n[a]=e?.(c,a)??c}return n}function Ri(t){if(t<=Ur.Value)return t;switch(tc=new DataView(nc.buffer,nc.byteOffset+qr),t){case Ur.OneByte:return qr++,tc.getUint8(0);case Ur.TwoBytes:return qr+=2,tc.getUint16(0,Ii);case Ur.FourBytes:return qr+=4,tc.getUint32(0,Ii);case Ur.EightBytes:return qr+=8,tc.getBigUint64(0,Ii);case Ur.Indefinite:return 1/0;default:throw new Yn(`Unsupported integer info: ${t.toString(2)}`)}}function m8(t){let e=Ri(t);return typeof e=="number"?-1-e:-1n-e}function ax(t){let e=Ri(t);if(e>Number.MAX_SAFE_INTEGER)throw new Yn("Byte length is too large");let r=Number(e);return qr+=r,nc.slice(qr-r,qr)}function Gh(t){let e=ax(t);return u8.decode(e)}function y8(t,e){let r=Ri(t);if(r===nx)return ws(e);throw new Yn(`Unsupported tag: ${r}.`)}var oc=class extends Error{constructor(e){super(e),this.name="SerializationError"}},_8=2*1024,b8=100,g8=new TextEncoder;function rc(t){return t<<5}var cr=new Uint8Array(_8),Vr=new DataView(cr.buffer),it=0,Kh=[];function cx(t,e){it=0;let r=e?.(t)??t;return I8(nx,r,e),cr.slice(0,it)}function zh(t,e){if(it>cr.length-b8&&(cr=sx(cr,cr.length*2),Vr=new DataView(cr.buffer)),t===!1||t===!0||t===null||t===void 0){E8(t);return}if(typeof t=="number"||typeof t=="bigint"){v8(t);return}if(typeof t=="string"){lx(t);return}if(t instanceof Uint8Array){rx(t);return}if(t instanceof ArrayBuffer){rx(new Uint8Array(t));return}if(Array.isArray(t)){x8(t,e);return}if(typeof t=="object"){w8(t,e);return}throw new oc(`Unsupported type: ${typeof t}`)}function x8(t,e){Si(at.Array,t.length),t.forEach((r,n)=>{zh(e?.(r,n.toString())??r,e)})}function w8(t,e){Kh=Object.entries(t),Si(at.Map,Kh.length),Kh.forEach(([r,n])=>{lx(r),zh(e?.(n,r)??n,e)})}function Si(t,e){if(e<=n8){Vr.setUint8(it++,rc(t)|Number(e));return}if(e<=o8){Vr.setUint8(it++,rc(t)|Ur.OneByte),Vr.setUint8(it,Number(e)),it+=1;return}if(e<=s8){Vr.setUint8(it++,rc(t)|Ur.TwoBytes),Vr.setUint16(it,Number(e),Ii),it+=2;return}if(e<=i8){Vr.setUint8(it++,rc(t)|Ur.FourBytes),Vr.setUint32(it,Number(e),Ii),it+=4;return}if(e<=a8){Vr.setUint8(it++,rc(t)|Ur.EightBytes),Vr.setBigUint64(it,BigInt(e),Ii),it+=8;return}throw new oc(`Value too large to encode: ${e}`)}function E8(t){Si(at.Simple,T8(t))}function T8(t){if(t===!1)return Lr.False;if(t===!0)return Lr.True;if(t===null)return Lr.Null;if(t===void 0)return Lr.Undefined;throw new oc(`Unrecognized simple value: ${t.toString()}`)}function ux(t,e){Si(t,e.length),it>cr.length-e.length&&(cr=sx(cr,cr.length+e.length),Vr=new DataView(cr.buffer)),cr.set(e,it),it+=e.length}function dx(t,e){Si(t,e)}function O8(t){dx(at.UnsignedInteger,t)}function N8(t){dx(at.NegativeInteger,typeof t=="bigint"?-1n-t:-1-t)}function v8(t){t>=0?O8(t):N8(t)}function lx(t){ux(at.TextString,g8.encode(t))}function rx(t){ux(at.ByteString,t)}function I8(t,e,r){Si(at.Tag,t),zh(e,r)}function S8(t){return typeof t=="object"&&t!==null&&"toCborValue"in t}function sc(t){try{return cx(t,e=>oe.isPrincipal(e)?e.toUint8Array():Ai.isExpiry(e)?e.toBigInt():S8(e)?e.toCborValue():e)}catch(e){throw Ne.fromCode(new ud(e,t))}}function rr(t){try{return ix(t)}catch(e){throw Ne.fromCode(new cd(e,t))}}var Bd={encode:sc,decode:rr};var ic=()=>{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 Wn;(function(t){t.Query="read",t.ReadState="read_state",t.Call="call"})(Wn||(Wn={}));var Cd;(function(t){t.Call="call"})(Cd||(Cd={}));var Es;(function(t){t.Query="query",t.ReadState="read_state"})(Es||(Es={}));function ac(){let t=new ArrayBuffer(16),e=new DataView(t),r=ic(),n=ic(),o=ic(),s=ic();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})}var Pd="__expiry__",Yh=BigInt(1e3),A8=BigInt(1e6),fx=BigInt(60),B8=BigInt(90)*Yh;function px(t){return t/Yh}function C8(t){return px(t)/fx}var Ai=class t{constructor(e){this.__expiry__=e,this._isExpiry=!0}static fromDeltaInMilliseconds(e,r=0){let n=BigInt(e),o=BigInt(Date.now())+n+BigInt(r),s;return n<B8?s=px(o):s=C8(o)*fx,new t(s*Yh*A8)}toBigInt(){return this.__expiry__}toHash(){return ke(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[Pd]:this.toString()}}static fromJSON(e){let r=JSON.parse(e);if(r[Pd])try{let n=BigInt(r[Pd]);return new t(n)}catch(n){throw new Ne(new Ga(`Not a valid BigInt: ${n}`))}throw new Ne(new Ga(`The input does not contain the key ${Pd}`))}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 Wh(t=ac){return async e=>{let r=e.request.headers;e.request.headers=r,e.endpoint===Wn.Call&&(e.body.nonce=t())}}function Dd(t){let e=[];return t.forEach((r,n)=>{e.push([n,r])}),e}var Jh=BigInt(0),Fd=BigInt(1);function Ts(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}"`;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Uo(t,e,r=""){let n=un(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return t}function hx(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Jh:BigInt("0x"+t)}function nr(t){return hx(de(t))}function Xn(t){return Xe(t),hx(de(Uint8Array.from(t).reverse()))}function ct(t,e){return ht(t.toString(16).padStart(e*2,"0"))}function Qh(t,e){return ct(t,e).reverse()}function Ze(t,e,r){let n;if(typeof e=="string")try{n=ht(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(un(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(t+" of length "+r+" expected, got "+o);return n}function mx(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function e0(t){return Uint8Array.from(t)}var Xh=t=>typeof t=="bigint"&&Jh<=t;function t0(t,e,r){return Xh(t)&&Xh(e)&&Xh(r)&&e<=t&&t<r}function Vd(t,e,r,n){if(!t0(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Jn(t){let e;for(e=0;t>Jh;t>>=Fd,e+=1);return e}function yx(t,e){return t>>BigInt(e)&Fd}var Mr=t=>(Fd<<BigInt(t))-Fd;function _x(t){return typeof t=="function"&&Number.isSafeInteger(t.outputLen)}function Qn(t,e,r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(o,s,i){let a=t[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(e).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Bi=()=>{throw new Error("not implemented")};function Lo(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let s=t(r,...n);return e.set(r,s),s}}var kt=BigInt(0),yt=BigInt(1),Os=BigInt(2),gx=BigInt(3),xx=BigInt(4),wx=BigInt(5),P8=BigInt(7),Ex=BigInt(8),D8=BigInt(9),Tx=BigInt(16);function Ke(t,e){let r=t%e;return r>=kt?r:e+r}function kr(t,e,r){let n=t;for(;e-- >kt;)n*=n,n%=r;return n}function bx(t,e){if(t===kt)throw new Error("invert: expected non-zero number");if(e<=kt)throw new Error("invert: expected positive modulus, got "+e);let r=Ke(t,e),n=e,o=kt,s=yt,i=yt,a=kt;for(;r!==kt;){let d=n/r,p=n%r,l=o-i*d,u=s-a*d;n=r,r=p,o=i,s=a,i=l,a=u}if(n!==yt)throw new Error("invert: does not exist");return Ke(o,e)}function r0(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function Ox(t,e){let r=(t.ORDER+yt)/xx,n=t.pow(e,r);return r0(t,n,e),n}function F8(t,e){let r=(t.ORDER-wx)/Ex,n=t.mul(e,Os),o=t.pow(n,r),s=t.mul(e,o),i=t.mul(t.mul(s,Os),o),a=t.mul(s,t.sub(i,t.ONE));return r0(t,a,e),a}function V8(t){let e=jt(t),r=Nx(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+P8)/Tx;return(a,c)=>{let d=a.pow(c,i),p=a.mul(d,n),l=a.mul(d,o),u=a.mul(d,s),f=a.eql(a.sqr(p),c),h=a.eql(a.sqr(l),c);d=a.cmov(d,p,f),p=a.cmov(u,l,h);let m=a.eql(a.sqr(p),c),b=a.cmov(d,p,m);return r0(a,b,c),b}}function Nx(t){if(t<gx)throw new Error("sqrt is not defined for small field");let e=t-yt,r=0;for(;e%Os===kt;)e/=Os,r++;let n=Os,o=jt(t);for(;cc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ox;let s=o.pow(n,e),i=(e+yt)/Os;return function(c,d){if(c.is0(d))return d;if(cc(c,d)!==1)throw new Error("Cannot find square root");let p=r,l=c.mul(c.ONE,s),u=c.pow(d,e),f=c.pow(d,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let h=1,m=c.sqr(u);for(;!c.eql(m,c.ONE);)if(h++,m=c.sqr(m),h===p)throw new Error("Cannot find square root");let b=yt<<BigInt(p-h-1),y=c.pow(l,b);p=h,l=c.sqr(y),u=c.mul(u,l),f=c.mul(f,y)}return f}}function U8(t){return t%xx===gx?Ox:t%Ex===wx?F8:t%Tx===D8?V8(t):Nx(t)}var eo=(t,e)=>(Ke(t,e)&yt)===yt,L8=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ud(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=L8.reduce((n,o)=>(n[o]="function",n),e);return Qn(t,r),t}function uc(t,e,r){if(r<kt)throw new Error("invalid exponent, negatives unsupported");if(r===kt)return t.ONE;if(r===yt)return e;let n=t.ONE,o=e;for(;r>kt;)r&yt&&(n=t.mul(n,o)),o=t.sqr(o),r>>=yt;return n}function xr(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),o=e.reduce((i,a,c)=>t.is0(a)?i:(n[c]=i,t.mul(i,a)),t.ONE),s=t.inv(o);return e.reduceRight((i,a,c)=>t.is0(a)?i:(n[c]=t.mul(i,n[c]),t.mul(i,a)),s),n}function cc(t,e){let r=(t.ORDER-yt)/Os,n=t.pow(e,r),o=t.eql(n,t.ONE),s=t.eql(n,t.ZERO),i=t.eql(n,t.neg(t.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function n0(t,e){e!==void 0&&Nh(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function jt(t,e,r=!1,n={}){if(t<=kt)throw new Error("invalid field: expected ORDER > 0, got "+t);let o,s,i=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=e;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),a=u.allowedLengths}else typeof e=="number"&&(o=e),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:d}=n0(t,o);if(d>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,l=Object.freeze({ORDER:t,isLE:r,BITS:c,BYTES:d,MASK:Mr(c),ZERO:kt,ONE:yt,allowedLengths:a,create:u=>Ke(u,t),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return kt<=u&&u<t},is0:u=>u===kt,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&yt)===yt,neg:u=>Ke(-u,t),eql:(u,f)=>u===f,sqr:u=>Ke(u*u,t),add:(u,f)=>Ke(u+f,t),sub:(u,f)=>Ke(u-f,t),mul:(u,f)=>Ke(u*f,t),pow:(u,f)=>uc(l,u,f),div:(u,f)=>Ke(u*bx(f,t),t),sqrN:u=>u*u,addN:(u,f)=>u+f,subN:(u,f)=>u-f,mulN:(u,f)=>u*f,inv:u=>bx(u,t),sqrt:s||(u=>(p||(p=U8(t)),p(l,u))),toBytes:u=>r?Qh(u,d):ct(u,d),fromBytes:(u,f=!0)=>{if(a){if(!a.includes(u.length)||u.length>d)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let m=new Uint8Array(d);m.set(u,r?0:m.length-u.length),u=m}if(u.length!==d)throw new Error("Field.fromBytes: expected "+d+" bytes, got "+u.length);let h=r?Xn(u):nr(u);if(i&&(h=Ke(h,t)),!f&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:u=>xr(l,u),cmov:(u,f,h)=>h?f:u});return Object.freeze(l)}function vx(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ld(t){let e=vx(t);return e+Math.ceil(e/2)}function o0(t,e,r=!1){let n=t.length,o=vx(e),s=Ld(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Xn(t):nr(t),a=Ke(i,e-yt)+yt;return r?Qh(a,o):ct(a,o)}var Ci=BigInt(0),Ns=BigInt(1);function dc(t,e){let r=e.negate();return t?r:e}function wr(t,e){let r=xr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function Ax(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function s0(t,e){Ax(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Mr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ix(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=Ns);let d=e*n,p=d+Math.abs(a)-1,l=a===0,u=a<0,f=e%2!==0;return{nextN:c,offset:p,isZero:l,isNeg:u,isNegF:f,offsetF:d}}function M8(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function k8(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var i0=new WeakMap,Bx=new WeakMap;function a0(t){return Bx.get(t)||1}function Rx(t){if(t!==Ci)throw new Error("invalid wNAF")}var Pi=class{constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>Ci;)r&Ns&&(n=n.add(o)),o=o.double(),r>>=Ns;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=s0(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let d=1;d<o;d++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=s0(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:d,isZero:p,isNeg:l,isNegF:u,offsetF:f}=Ix(n,a,i);n=c,p?s=s.add(dc(u,r[f])):o=o.add(dc(l,r[d]))}return Rx(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=s0(e,this.bits);for(let i=0;i<s.windows&&n!==Ci;i++){let{nextN:a,offset:c,isZero:d,isNeg:p}=Ix(n,i,s);if(n=a,!d){let l=r[c];o=o.add(p?l.negate():l)}}return Rx(n),o}getPrecomputes(e,r,n){let o=i0.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),i0.set(r,o))),o}cached(e,r,n){let o=a0(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=a0(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){Ax(r,this.bits),Bx.set(e,r),i0.delete(e)}hasCache(e){return a0(e)!==1}};function Cx(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>Ci||n>Ci;)r&Ns&&(s=s.add(o)),n&Ns&&(i=i.add(o)),o=o.double(),r>>=Ns,n>>=Ns;return{p1:s,p2:i}}function Di(t,e,r,n){M8(r,t),k8(n,e);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=t.ZERO,a=Jn(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let d=Mr(c),p=new Array(Number(d)+1).fill(i),l=Math.floor((e.BITS-1)/c)*c,u=i;for(let f=l;f>=0;f-=c){p.fill(i);for(let m=0;m<s;m++){let b=n[m],y=Number(b>>BigInt(f)&d);p[y]=p[y].add(r[m])}let h=i;for(let m=p.length-1,b=i;m>0;m--)b=b.add(p[m]),h=h.add(b);if(u=u.add(h),f!==0)for(let m=0;m<c;m++)u=u.double()}return u}function Sx(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ud(e),e}else return jt(t,{isLE:r})}function qd(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let d=e[c];if(!(typeof d=="bigint"&&d>Ci))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Sx(e.p,r.Fp,n),s=Sx(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}var j8=nr;function qo(t,e){if(lc(t),lc(e),t<0||t>=1<<8*e)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 H8(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 lc(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function Px(t){if(!un(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or string");return typeof t=="string"?Ve(t):t}function $8(t,e,r,n){Xe(t),lc(r),e=Px(e),e.length>255&&(e=n(fe(Ve("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 a=fe(e,qo(e.length,1)),c=qo(0,s),d=qo(r,2),p=new Array(i),l=n(fe(c,t,d,qo(0,1),a));p[0]=n(fe(l,qo(1,1),a));for(let f=1;f<=i;f++){let h=[H8(l,p[f-1]),qo(f+1,1),a];p[f]=n(fe(...h))}return fe(...p).slice(0,r)}function K8(t,e,r,n,o){if(Xe(t),lc(r),e=Px(e),e.length>255){let s=Math.ceil(2*n/8);e=o.create({dkLen:s}).update(Ve("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return o.create({dkLen:r}).update(t).update(qo(r,2)).update(e).update(qo(e.length,1)).digest()}function c0(t,e,r){Qn(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:o,m:s,hash:i,expand:a,DST:c}=r;if(!_x(r.hash))throw new Error("expected valid hash");Xe(t),lc(e);let d=n.toString(2).length,p=Math.ceil((d+o)/8),l=e*s*p,u;if(a==="xmd")u=$8(t,c,l,i);else if(a==="xof")u=K8(t,c,l,o,i);else if(a==="_internal_pass")u=t;else throw new Error('expand must be "xmd" or "xof"');let f=new Array(e);for(let h=0;h<e;h++){let m=new Array(s);for(let b=0;b<s;b++){let y=p*(b+h*s),x=u.subarray(y,y+p);m[b]=Ke(j8(x),n)}f[h]=m}return f}function u0(t,e){let r=e.map(n=>Array.from(n).reverse());return(n,o)=>{let[s,i,a,c]=r.map(l=>l.reduce((u,f)=>t.add(t.mul(u,n),f))),[d,p]=xr(t,[i,c],!0);return n=t.mul(s,d),o=t.mul(o,t.mul(a,p)),{x:n,y:o}}}var G8=Ve("HashToScalar-");function d0(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function n(s){return t.fromAffine(e(s))}function o(s){let i=s.clearCofactor();return i.equals(t.ZERO)?t.ZERO:(i.assertValidity(),i)}return{defaults:r,hashToCurve(s,i){let a=Object.assign({},r,i),c=c0(s,2,a),d=n(c[0]),p=n(c[1]);return o(d.add(p))},encodeToCurve(s,i){let a=r.encodeDST?{DST:r.encodeDST}:{},c=Object.assign({},r,a,i),d=c0(s,1,c),p=n(d[0]);return o(p)},mapToCurve(s){if(!Array.isArray(s))throw new Error("expected array of bigints");for(let i of s)if(typeof i!="bigint")throw new Error("expected array of bigints");return o(n(s))},hashToScalar(s,i){let a=t.Fn.ORDER,c=Object.assign({},r,{p:a,m:1,DST:G8},i);return c0(s,1,c)[0][0]}}}var Dx=(t,e)=>(t+(t>=0?e:-e)/to)/e;function z8(t,e,r){let[[n,o],[s,i]]=e,a=Dx(i*t,r),c=Dx(-o*t,r),d=t-a*n-c*s,p=-a*o-c*i,l=d<vs,u=p<vs;l&&(d=-d),u&&(p=-p);let f=Mr(Math.ceil(Jn(r)/2))+Ht;if(d<vs||d>=f||p<vs||p>=f)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:l,k1:d,k2neg:u,k2:p}}var vs=BigInt(0),Ht=BigInt(1),to=BigInt(2),Fi=BigInt(3),l0=BigInt(4);function fc(t,e){let{BYTES:r}=t,n;if(typeof e=="bigint")n=e;else{let o=Ze("private key",e);try{n=t.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`)}}if(!t.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Z8(t,e={}){let r=qd("weierstrass",t,e),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;Qn(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=X8(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,g,w){let{x:O,y:P}=g.toAffine(),L=n.toBytes(O);if(Ts(w,"isCompressed"),w){p();let R=!n.isOdd(P);return fe(Y8(R),L)}else return fe(Uint8Array.of(4),L,n.toBytes(P))}function u(C){Uo(C,void 0,"Point");let{publicKey:g,publicKeyUncompressed:w}=d,O=C.length,P=C[0],L=C.subarray(1);if(O===g&&(P===2||P===3)){let R=n.fromBytes(L);if(!n.isValid(R))throw new Error("bad point: is not on curve, wrong x");let B=m(R),F;try{F=n.sqrt(B)}catch(H){let Y=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}p();let U=n.isOdd(F);return(P&1)===1!==U&&(F=n.neg(F)),{x:R,y:F}}else if(O===w&&P===4){let R=n.BYTES,B=n.fromBytes(L.subarray(0,R)),F=n.fromBytes(L.subarray(R,R*2));if(!b(B,F))throw new Error("bad point: is not on curve");return{x:B,y:F}}else throw new Error(`bad point: got length ${O}, expected compressed=${g} or uncompressed=${w}`)}let f=e.toBytes||l,h=e.fromBytes||u;function m(C){let g=n.sqr(C),w=n.mul(g,C);return n.add(n.add(w,n.mul(C,s.a)),s.b)}function b(C,g){let w=n.sqr(g),O=m(C);return n.eql(w,O)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,Fi),l0),x=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,x)))throw new Error("bad curve params: a or b");function _(C,g,w=!1){if(!n.isValid(g)||w&&n.is0(g))throw new Error(`bad point coordinate ${C}`);return g}function T(C){if(!(C instanceof E))throw new Error("ProjectivePoint expected")}function N(C){if(!c||!c.basises)throw new Error("no endo");return z8(C,c.basises,o.ORDER)}let I=Lo((C,g)=>{let{X:w,Y:O,Z:P}=C;if(n.eql(P,n.ONE))return{x:w,y:O};let L=C.is0();g==null&&(g=L?n.ONE:n.inv(P));let R=n.mul(w,g),B=n.mul(O,g),F=n.mul(P,g);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:R,y:B}}),v=Lo(C=>{if(C.is0()){if(e.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:w}=C.toAffine();if(!n.isValid(g)||!n.isValid(w))throw new Error("bad point: x or y not field elements");if(!b(g,w))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(C,g,w,O,P){return w=new E(n.mul(w.X,C),w.Y,w.Z),g=dc(O,g),w=dc(P,w),g.add(w)}class E{constructor(g,w,O){this.X=_("x",g),this.Y=_("y",w,!0),this.Z=_("z",O),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:w,y:O}=g||{};if(!g||!n.isValid(w)||!n.isValid(O))throw new Error("invalid affine point");if(g instanceof E)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(O)?E.ZERO:new E(w,O,n.ONE)}static fromBytes(g){let w=E.fromAffine(h(Uo(g,void 0,"point")));return w.assertValidity(),w}static fromHex(g){return E.fromBytes(Ze("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,w=!0){return V.createCache(this,g),w||this.multiply(Fi),this}assertValidity(){v(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){T(g);let{X:w,Y:O,Z:P}=this,{X:L,Y:R,Z:B}=g,F=n.eql(n.mul(w,B),n.mul(L,P)),U=n.eql(n.mul(O,B),n.mul(R,P));return F&&U}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:w}=s,O=n.mul(w,Fi),{X:P,Y:L,Z:R}=this,B=n.ZERO,F=n.ZERO,U=n.ZERO,q=n.mul(P,P),H=n.mul(L,L),Y=n.mul(R,R),G=n.mul(P,L);return G=n.add(G,G),U=n.mul(P,R),U=n.add(U,U),B=n.mul(g,U),F=n.mul(O,Y),F=n.add(B,F),B=n.sub(H,F),F=n.add(H,F),F=n.mul(B,F),B=n.mul(G,B),U=n.mul(O,U),Y=n.mul(g,Y),G=n.sub(q,Y),G=n.mul(g,G),G=n.add(G,U),U=n.add(q,q),q=n.add(U,q),q=n.add(q,Y),q=n.mul(q,G),F=n.add(F,q),Y=n.mul(L,R),Y=n.add(Y,Y),q=n.mul(Y,G),B=n.sub(B,q),U=n.mul(Y,H),U=n.add(U,U),U=n.add(U,U),new E(B,F,U)}add(g){T(g);let{X:w,Y:O,Z:P}=this,{X:L,Y:R,Z:B}=g,F=n.ZERO,U=n.ZERO,q=n.ZERO,H=s.a,Y=n.mul(s.b,Fi),G=n.mul(w,L),ie=n.mul(O,R),ae=n.mul(P,B),Ce=n.add(w,O),ee=n.add(L,R);Ce=n.mul(Ce,ee),ee=n.add(G,ie),Ce=n.sub(Ce,ee),ee=n.add(w,P);let ce=n.add(L,B);return ee=n.mul(ee,ce),ce=n.add(G,ae),ee=n.sub(ee,ce),ce=n.add(O,P),F=n.add(R,B),ce=n.mul(ce,F),F=n.add(ie,ae),ce=n.sub(ce,F),q=n.mul(H,ee),F=n.mul(Y,ae),q=n.add(F,q),F=n.sub(ie,q),q=n.add(ie,q),U=n.mul(F,q),ie=n.add(G,G),ie=n.add(ie,G),ae=n.mul(H,ae),ee=n.mul(Y,ee),ie=n.add(ie,ae),ae=n.sub(G,ae),ae=n.mul(H,ae),ee=n.add(ee,ae),G=n.mul(ie,ee),U=n.add(U,G),G=n.mul(ce,ee),F=n.mul(Ce,F),F=n.sub(F,G),G=n.mul(Ce,ie),q=n.mul(ce,q),q=n.add(q,G),new E(F,U,q)}subtract(g){return this.add(g.negate())}is0(){return this.equals(E.ZERO)}multiply(g){let{endo:w}=e;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let O,P,L=R=>V.cached(this,R,B=>wr(E,B));if(w){let{k1neg:R,k1:B,k2neg:F,k2:U}=N(g),{p:q,f:H}=L(B),{p:Y,f:G}=L(U);P=H.add(G),O=A(w.beta,q,Y,R,F)}else{let{p:R,f:B}=L(g);O=R,P=B}return wr(E,[O,P])[0]}multiplyUnsafe(g){let{endo:w}=e,O=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===vs||O.is0())return E.ZERO;if(g===Ht)return O;if(V.hasCache(this))return this.multiply(g);if(w){let{k1neg:P,k1:L,k2neg:R,k2:B}=N(g),{p1:F,p2:U}=Cx(E,O,L,B);return A(w.beta,F,U,P,R)}else return V.unsafe(O,g)}multiplyAndAddUnsafe(g,w,O){let P=this.multiplyUnsafe(w).add(g.multiplyUnsafe(O));return P.is0()?void 0:P}toAffine(g){return I(this,g)}isTorsionFree(){let{isTorsionFree:g}=e;return i===Ht?!0:g?g(E,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=e;return i===Ht?this:g?g(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return Ts(g,"isCompressed"),this.assertValidity(),f(E,this,g)}toHex(g=!0){return de(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return wr(E,g)}static msm(g,w){return Di(E,o,g,w)}static fromPrivateKey(g){return E.BASE.multiply(fc(o,g))}}E.BASE=new E(s.Gx,s.Gy,n.ONE),E.ZERO=new E(n.ZERO,n.ONE,n.ZERO),E.Fp=n,E.Fn=o;let S=o.BITS,V=new Pi(E,e.endo?Math.ceil(S/2):S);return E.BASE.precompute(8),E}function Y8(t){return Uint8Array.of(t?2:3)}function W8(t,e){let r=t.ORDER,n=vs;for(let h=r-Ht;h%to===vs;h/=to)n+=Ht;let o=n,s=to<<o-Ht-Ht,i=s*to,a=(r-Ht)/i,c=(a-Ht)/to,d=i-Ht,p=s,l=t.pow(e,a),u=t.pow(e,(a+Ht)/to),f=(h,m)=>{let b=l,y=t.pow(m,d),x=t.sqr(y);x=t.mul(x,m);let _=t.mul(h,x);_=t.pow(_,c),_=t.mul(_,y),y=t.mul(_,m),x=t.mul(_,h);let T=t.mul(x,y);_=t.pow(T,p);let N=t.eql(_,t.ONE);y=t.mul(x,u),_=t.mul(T,b),x=t.cmov(y,x,N),T=t.cmov(_,T,N);for(let I=o;I>Ht;I--){let v=I-to;v=to<<v-Ht;let A=t.pow(T,v),E=t.eql(A,t.ONE);y=t.mul(x,b),b=t.mul(b,b),A=t.mul(T,b),x=t.cmov(y,x,E),T=t.cmov(A,T,E)}return{isValid:N,value:x}};if(t.ORDER%l0===Fi){let h=(t.ORDER-Fi)/l0,m=t.sqrt(t.neg(e));f=(b,y)=>{let x=t.sqr(y),_=t.mul(b,y);x=t.mul(x,_);let T=t.pow(x,h);T=t.mul(T,_);let N=t.mul(T,m),I=t.mul(t.sqr(T),y),v=t.eql(I,b),A=t.cmov(N,T,v);return{isValid:v,value:A}}}return f}function f0(t,e){Ud(t);let{A:r,B:n,Z:o}=e;if(!t.isValid(r)||!t.isValid(n)||!t.isValid(o))throw new Error("mapToCurveSimpleSWU: invalid opts");let s=W8(t,o);if(!t.isOdd)throw new Error("Field does not have .isOdd()");return i=>{let a,c,d,p,l,u,f,h;a=t.sqr(i),a=t.mul(a,o),c=t.sqr(a),c=t.add(c,a),d=t.add(c,t.ONE),d=t.mul(d,n),p=t.cmov(o,t.neg(c),!t.eql(c,t.ZERO)),p=t.mul(p,r),c=t.sqr(d),u=t.sqr(p),l=t.mul(u,r),c=t.add(c,l),c=t.mul(c,d),u=t.mul(u,p),l=t.mul(u,n),c=t.add(c,l),f=t.mul(a,d);let{isValid:m,value:b}=s(c,u);h=t.mul(a,i),h=t.mul(h,b),f=t.cmov(f,d,m),h=t.cmov(h,b,m);let y=t.isOdd(i)===t.isOdd(h);h=t.cmov(t.neg(h),h,y);let x=xr(t,[p],!0)[0];return f=t.mul(f,x),{x:f,y:h}}}function X8(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function p0(t){let{CURVE:e,curveOpts:r}=J8(t),n=Z8(e,r);return e3(t,n)}function J8(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=jt(e.n,{BITS:t.nBitLength,allowedLengths:n,modFromBytes:t.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:s}}function Q8(t,e,r){function n(o){let s=t.sqr(o),i=t.mul(s,o);return t.add(t.add(i,t.mul(o,e)),r)}return n}function e3(t,e){let{Fp:r,Fn:n}=e;function o(i){return t0(i,Ht,n.ORDER)}let s=Q8(r,t.a,t.b);return Object.assign({},{CURVE:t,Point:e,ProjectivePoint:e,normPrivateKeyToScalar:i=>fc(n,i),weierstrassEquation:s,isWithinCurveOrder:o})}var t3=BigInt(0),Md=BigInt(1),Fx=BigInt(2),Vi=BigInt(3);function r3(t){let e=[];for(;t>Md;t>>=Md)(t&Md)===t3?e.unshift(0):(t&Vi)===Vi?(e.unshift(-1),t+=Md):e.unshift(1);return e}function h0(t){if(!Array.isArray(t)||t.length===0)throw new Error("expected non-empty array")}function n3(t,e,r,n){let{Fp2:o,Fp12:s}=t,{twistType:i,ateLoopSize:a,xNegative:c,postPrecompute:d}=n,p;if(i==="multiplicative")p=(_,T,N,I,v,A)=>s.mul014(I,_,o.mul(T,v),o.mul(N,A));else if(i==="divisive")p=(_,T,N,I,v,A)=>s.mul034(I,o.mul(N,A),o.mul(T,v),_);else throw new Error("bls: unknown twist type");let l=o.div(o.ONE,o.mul(o.ONE,Fx));function u(_,T,N,I){let v=o.sqr(N),A=o.sqr(I),E=o.mulByB(o.mul(A,Vi)),S=o.mul(E,Vi),V=o.sub(o.sub(o.sqr(o.add(N,I)),A),v),C=o.sub(E,v),g=o.mul(o.sqr(T),Vi),w=o.neg(V);return _.push([C,g,w]),T=o.mul(o.mul(o.mul(o.sub(v,S),T),N),l),N=o.sub(o.sqr(o.mul(o.add(v,S),l)),o.mul(o.sqr(E),Vi)),I=o.mul(v,V),{Rx:T,Ry:N,Rz:I}}function f(_,T,N,I,v,A){let E=o.sub(N,o.mul(A,I)),S=o.sub(T,o.mul(v,I)),V=o.sub(o.mul(E,v),o.mul(S,A)),C=o.neg(E),g=S;_.push([V,C,g]);let w=o.sqr(S),O=o.mul(w,S),P=o.mul(w,T),L=o.add(o.sub(O,o.mul(P,Fx)),o.mul(o.sqr(E),I));return T=o.mul(S,L),N=o.sub(o.mul(o.sub(P,L),E),o.mul(O,N)),I=o.mul(I,O),{Rx:T,Ry:N,Rz:I}}let h=r3(a),m=Lo(_=>{let T=_,{x:N,y:I}=T.toAffine(),v=N,A=I,E=o.neg(I),S=v,V=A,C=o.ONE,g=[];for(let w of h){let O=[];({Rx:S,Ry:V,Rz:C}=u(O,S,V,C)),w&&({Rx:S,Ry:V,Rz:C}=f(O,S,V,C,v,w===-1?E:A)),g.push(O)}if(d){let w=g[g.length-1];d(S,V,C,v,A,f.bind(null,w))}return g});function b(_,T=!1){let N=s.ONE;if(_.length){let I=_[0][0].length;for(let v=0;v<I;v++){N=s.sqr(N);for(let[A,E,S]of _)for(let[V,C,g]of A[v])N=p(V,C,g,N,E,S)}}return c&&(N=s.conjugate(N)),T?s.finalExponentiate(N):N}function y(_,T=!0){let N=[];wr(e,_.map(({g1:I})=>I)),wr(r,_.map(({g2:I})=>I));for(let{g1:I,g2:v}of _){if(I.is0()||v.is0())throw new Error("pairing is not available for ZERO point");I.assertValidity(),v.assertValidity();let A=I.toAffine();N.push([m(v),A.x,A.y])}return b(N,T)}function x(_,T,N=!0){return y([{g1:_,g2:T}],N)}return{Fp12:s,millerLoopBatch:b,pairing:x,pairingBatch:y,calcPairingPrecomputes:m}}function Vx(t,e,r,n,o){let{Fp12:s,pairingBatch:i}=t;function a(l){return l instanceof e.Point?l:e.Point.fromHex(l)}function c(l){return l instanceof r.Point?l:r.Point.fromHex(l)}function d(l){if(!(l instanceof r.Point))throw new Error(`expected valid message hashed to ${o?"G1":"G2"} curve`);return l}let p=o?(l,u)=>({g1:u,g2:l}):(l,u)=>({g1:l,g2:u});return{getPublicKey(l){let u=fc(e.Point.Fn,l);return e.Point.BASE.multiply(u)},sign(l,u,f){if(f!=null)throw new Error("sign() expects 2 arguments");let h=fc(e.Point.Fn,u);return d(l).assertValidity(),l.multiply(h)},verify(l,u,f,h){if(h!=null)throw new Error("verify() expects 3 arguments");l=c(l),f=a(f);let m=f.negate(),b=e.Point.BASE,y=d(u),x=l,_=i([p(m,y),p(b,x)]);return s.eql(_,s.ONE)},verifyBatch(l,u,f){if(h0(u),f.length!==u.length)throw new Error("amount of public keys and messages should be equal");let h=c(l),m=u,b=f.map(a),y=new Map;for(let T=0;T<b.length;T++){let N=b[T],I=m[T],v=y.get(I);v===void 0&&(v=[],y.set(I,v)),v.push(N)}let x=[],_=e.Point.BASE;try{for(let[T,N]of y){let I=N.reduce((v,A)=>v.add(A));x.push(p(I,T))}return x.push(p(_.negate(),h)),s.eql(i(x),s.ONE)}catch{return!1}},aggregatePublicKeys(l){h0(l),l=l.map(f=>a(f));let u=l.reduce((f,h)=>f.add(h),e.Point.ZERO);return u.assertValidity(),u},aggregateSignatures(l){h0(l),l=l.map(f=>c(f));let u=l.reduce((f,h)=>f.add(h),r.Point.ZERO);return u.assertValidity(),u},hash(l,u){Xe(l);let f=u?{DST:u}:void 0;return r.hashToCurve(l,f)},Signature:n}}function Ux(t){let{Fp:e,Fr:r,Fp2:n,Fp6:o,Fp12:s}=t.fields,i=p0(t.G1),a=Object.assign(i,d0(i.Point,t.G1.mapToCurve,{...t.htfDefaults,...t.G1.htfDefaults})),c=p0(t.G2),d=Object.assign(c,d0(c.Point,t.G2.mapToCurve,{...t.htfDefaults,...t.G2.htfDefaults})),p=n3(t.fields,a.Point,d.Point,{...t.params,postPrecompute:t.postPrecompute}),{millerLoopBatch:l,pairing:u,pairingBatch:f,calcPairingPrecomputes:h}=p,m=Vx(p,a,d,t.G2.Signature,!1),b=Vx(p,d,a,t.G1.ShortSignature,!0),y=t.randomBytes||yi,x=()=>{let R=Ld(r.ORDER);return o0(y(R),r.ORDER)},_={randomSecretKey:x,randomPrivateKey:x,calcPairingPrecomputes:h},{ShortSignature:T}=t.G1,{Signature:N}=t.G2;function I(R,B){return R instanceof a.Point?R:b.hash(Ze("point",R),B?.DST)}function v(R,B){return R instanceof d.Point?R:m.hash(Ze("point",R),B?.DST)}function A(R){return m.getPublicKey(R).toBytes(!0)}function E(R){return b.getPublicKey(R).toBytes(!0)}function S(R,B,F){let U=v(R,F),q=m.sign(U,B);return R instanceof d.Point?q:N.toBytes(q)}function V(R,B,F){let U=I(R,F),q=b.sign(U,B);return R instanceof a.Point?q:T.toBytes(q)}function C(R,B,F,U){let q=v(B,U);return m.verify(R,q,F)}function g(R,B,F,U){let q=I(B,U);return b.verify(R,q,F)}function w(R){let B=m.aggregatePublicKeys(R);return R[0]instanceof a.Point?B:B.toBytes(!0)}function O(R){let B=m.aggregateSignatures(R);return R[0]instanceof d.Point?B:N.toBytes(B)}function P(R){let B=b.aggregateSignatures(R);return R[0]instanceof a.Point?B:T.toBytes(B)}function L(R,B,F,U){let q=B.map(H=>v(H,U));return m.verifyBatch(R,q,F)}return a.Point.BASE.precompute(4),{longSignatures:m,shortSignatures:b,millerLoopBatch:l,pairing:u,pairingBatch:f,verifyBatch:L,fields:{Fr:r,Fp:e,Fp2:n,Fp6:o,Fp12:s},params:{ateLoopSize:t.params.ateLoopSize,twistType:t.params.twistType,r:t.params.r,G1b:t.G1.b,G2b:t.G2.b},utils:_,getPublicKey:A,getPublicKeyForShortSignatures:E,sign:S,signShortSignature:V,verify:C,verifyShortSignature:g,aggregatePublicKeys:w,aggregateSignatures:O,aggregateShortSignatures:P,G1:a,G2:d,Signature:N,ShortSignature:T}}var Lx=BigInt(0),ro=BigInt(1),$t=BigInt(2),qx=BigInt(3);function b0(t,e,r,n,o=1,s){let i=BigInt(s===void 0?n:s),a=r**BigInt(n),c=[];for(let d=0;d<o;d++){let p=BigInt(d+1),l=[];for(let u=0,f=ro;u<n;u++){let h=(p*f-p)/i%a;l.push(t.pow(e,h)),f*=r}c.push(l)}return c}function kx(t,e,r){let n=e.pow(r,(t.ORDER-ro)/qx),o=e.pow(r,(t.ORDER-ro)/$t);function s(u,f){let h=e.mul(e.frobeniusMap(u,1),n),m=e.mul(e.frobeniusMap(f,1),o);return[h,m]}let i=e.pow(r,(t.ORDER**$t-ro)/qx),a=e.pow(r,(t.ORDER**$t-ro)/$t);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(u,f){return[e.mul(u,i),e.neg(f)]}let d=u=>(f,h)=>{let m=h.toAffine(),b=u(m.x,m.y);return f.fromAffine({x:b[0],y:b[1]})},p=d(s),l=d(c);return{psi:s,psi2:c,G2psi:p,G2psi2:l,PSI_X:n,PSI_Y:o,PSI2_X:i,PSI2_Y:a}}var Mx=(t,e)=>{if(e.length!==2)throw new Error("invalid tuple");let r=e.map(n=>t.create(n));return{c0:r[0],c1:r[1]}},m0=class{constructor(e,r={}){this.MASK=ro;let n=e.ORDER,o=n*n;this.Fp=e,this.ORDER=o,this.BITS=Jn(o),this.BYTES=Math.ceil(Jn(o)/8),this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.Fp_NONRESIDUE=e.create(r.NONRESIDUE||BigInt(-1)),this.Fp_div2=e.div(e.ONE,$t),this.NONRESIDUE=Mx(e,r.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=b0(e,this.Fp_NONRESIDUE,e.ORDER,2)[0],this.mulByB=r.Fp2mulByB,Object.seal(this)}fromBigTuple(e){return Mx(this.Fp,e)}create(e){return e}isValid({c0:e,c1:r}){function n(o,s){return typeof o=="bigint"&&Lx<=o&&o<s}return n(e,this.ORDER)&&n(r,this.ORDER)}is0({c0:e,c1:r}){return this.Fp.is0(e)&&this.Fp.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}eql({c0:e,c1:r},{c0:n,c1:o}){return this.Fp.eql(e,n)&&this.Fp.eql(r,o)}neg({c0:e,c1:r}){return{c0:this.Fp.neg(e),c1:this.Fp.neg(r)}}pow(e,r){return uc(this,e,r)}invertBatch(e){return xr(this,e)}add(e,r){let{c0:n,c1:o}=e,{c0:s,c1:i}=r;return{c0:this.Fp.add(n,s),c1:this.Fp.add(o,i)}}sub({c0:e,c1:r},{c0:n,c1:o}){return{c0:this.Fp.sub(e,n),c1:this.Fp.sub(r,o)}}mul({c0:e,c1:r},n){let{Fp:o}=this;if(typeof n=="bigint")return{c0:o.mul(e,n),c1:o.mul(r,n)};let{c0:s,c1:i}=n,a=o.mul(e,s),c=o.mul(r,i),d=o.sub(a,c),p=o.sub(o.mul(o.add(e,r),o.add(s,i)),o.add(a,c));return{c0:d,c1:p}}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{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{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 cc(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))),a=r.mul(r.add(i,o),this.Fp_div2);cc(r,a)===-1&&(a=r.sub(a,i));let d=r.sqrt(a),p=n.create({c0:d,c1:r.div(r.mul(s,this.Fp_div2),d)});if(!n.eql(n.sqr(p),e))throw new Error("Cannot find square root");let l=p,u=n.neg(l),{re:f,im:h}=n.reim(l),{re:m,im:b}=n.reim(u);return h>b||h===b&&f>m?l:u}isOdd(e){let{re:r,im:n}=this.reim(e),o=r%$t,s=r===Lx,i=n%$t;return BigInt(o||s&&i)==ro}fromBytes(e){let{Fp:r}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{c0:r.fromBytes(e.subarray(0,r.BYTES)),c1:r.fromBytes(e.subarray(r.BYTES))}}toBytes({c0:e,c1:r}){return fe(this.Fp.toBytes(e),this.Fp.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:o},s){return{c0:this.Fp.cmov(e,n,s),c1:this.Fp.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}){return this.mul({c0:e,c1:r},this.NONRESIDUE)}frobeniusMap({c0:e,c1:r},n){return{c0:e,c1:this.Fp.mul(r,this.FROBENIUS_COEFFICIENTS[n%2])}}},y0=class{constructor(e){this.MASK=ro,this.Fp2=e,this.ORDER=e.ORDER,this.BITS=3*e.BITS,this.BYTES=3*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO,c2:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO,c2:e.ZERO};let{Fp:r}=e,n=b0(e,e.NONRESIDUE,r.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=n[0],this.FROBENIUS_COEFFICIENTS_2=n[1],Object.seal(this)}add({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i}){let{Fp2:a}=this;return{c0:a.add(e,o),c1:a.add(r,s),c2:a.add(n,i)}}sub({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i}){let{Fp2:a}=this;return{c0:a.sub(e,o),c1:a.sub(r,s),c2:a.sub(n,i)}}mul({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;if(typeof o=="bigint")return{c0:s.mul(e,o),c1:s.mul(r,o),c2:s.mul(n,o)};let{c0:i,c1:a,c2:c}=o,d=s.mul(e,i),p=s.mul(r,a),l=s.mul(n,c);return{c0:s.add(d,s.mulByNonresidue(s.sub(s.mul(s.add(r,n),s.add(a,c)),s.add(p,l)))),c1:s.add(s.sub(s.mul(s.add(e,r),s.add(i,a)),s.add(d,p)),s.mulByNonresidue(l)),c2:s.sub(s.add(p,s.mul(s.add(e,n),s.add(i,c))),s.add(d,l))}}sqr({c0:e,c1:r,c2:n}){let{Fp2:o}=this,s=o.sqr(e),i=o.mul(o.mul(e,r),$t),a=o.mul(o.mul(r,n),$t),c=o.sqr(n);return{c0:o.add(o.mulByNonresidue(a),s),c1:o.add(o.mulByNonresidue(c),i),c2:o.sub(o.sub(o.add(o.add(i,o.sqr(o.add(o.sub(e,r),n))),a),s),c)}}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){return e}isValid({c0:e,c1:r,c2:n}){let{Fp2:o}=this;return o.isValid(e)&&o.isValid(r)&&o.isValid(n)}is0({c0:e,c1:r,c2:n}){let{Fp2:o}=this;return o.is0(e)&&o.is0(r)&&o.is0(n)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r,c2:n}){let{Fp2:o}=this;return{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:a}=this;return a.eql(e,o)&&a.eql(r,s)&&a.eql(n,i)}sqrt(e){return Bi()}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 uc(this,e,r)}invertBatch(e){return xr(this,e)}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)),a=o.sub(o.sqr(r),o.mul(e,n)),c=o.inv(o.add(o.mulByNonresidue(o.add(o.mul(n,i),o.mul(r,a))),o.mul(e,s)));return{c0:o.mul(c,s),c1:o.mul(c,i),c2:o.mul(c,a)}}fromBytes(e){let{Fp2:r}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);let n=r.BYTES;return{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 fe(o.toBytes(e),o.toBytes(r),o.toBytes(n))}cmov({c0:e,c1:r,c2:n},{c0:o,c1:s,c2:i},a){let{Fp2:c}=this;return{c0:c.cmov(e,o,a),c1:c.cmov(r,s,a),c2:c.cmov(n,i,a)}}fromBigSix(e){let{Fp2:r}=this;if(!Array.isArray(e)||e.length!==6)throw new Error("invalid Fp6 usage");return{c0:r.fromBigTuple(e.slice(0,2)),c1:r.fromBigTuple(e.slice(2,4)),c2:r.fromBigTuple(e.slice(4,6))}}frobeniusMap({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;return{c0:s.frobeniusMap(e,o),c1:s.mul(s.frobeniusMap(r,o),this.FROBENIUS_COEFFICIENTS_1[o%6]),c2:s.mul(s.frobeniusMap(n,o),this.FROBENIUS_COEFFICIENTS_2[o%6])}}mulByFp2({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;return{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{c0:o.mulByNonresidue(n),c1:e,c2:r}}mul1({c0:e,c1:r,c2:n},o){let{Fp2:s}=this;return{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,a=i.mul(e,o),c=i.mul(r,s);return{c0:i.add(i.mulByNonresidue(i.sub(i.mul(i.add(r,n),s),c)),a),c1:i.sub(i.sub(i.mul(i.add(o,s),i.add(e,r)),a),c),c2:i.add(i.sub(i.mul(i.add(e,n),o),a),c)}}},_0=class{constructor(e,r){this.MASK=ro;let{Fp2:n}=e,{Fp:o}=n;this.Fp6=e,this.ORDER=n.ORDER,this.BITS=2*e.BITS,this.BYTES=2*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.FROBENIUS_COEFFICIENTS=b0(n,n.NONRESIDUE,o.ORDER,12,1,6)[0],this.X_LEN=r.X_LEN,this.finalExponentiate=r.Fp12finalExponentiate}create(e){return e}isValid({c0:e,c1:r}){let{Fp6:n}=this;return n.isValid(e)&&n.isValid(r)}is0({c0:e,c1:r}){let{Fp6:n}=this;return n.is0(e)&&n.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r}){let{Fp6:n}=this;return{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){Bi()}inv({c0:e,c1:r}){let{Fp6:n}=this,o=n.inv(n.sub(n.sqr(e),n.mulByNonresidue(n.sqr(r))));return{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 uc(this,e,r)}invertBatch(e){return xr(this,e)}add({c0:e,c1:r},{c0:n,c1:o}){let{Fp6:s}=this;return{c0:s.add(e,n),c1:s.add(r,o)}}sub({c0:e,c1:r},{c0:n,c1:o}){let{Fp6:s}=this;return{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{c0:o.mul(e,n),c1:o.mul(r,n)};let{c0:s,c1:i}=n,a=o.mul(e,s),c=o.mul(r,i);return{c0:o.add(a,o.mulByNonresidue(c)),c1:o.sub(o.mul(o.add(e,r),o.add(s,i)),o.add(a,c))}}sqr({c0:e,c1:r}){let{Fp6:n}=this,o=n.mul(e,r);return{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(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{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 fe(n.toBytes(e),n.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:o},s){let{Fp6:i}=this;return{c0:i.cmov(e,n,s),c1:i.cmov(r,o,s)}}fromBigTwelve(e){let{Fp6:r}=this;return{c0:r.fromBigSix(e.slice(0,6)),c1:r.fromBigSix(e.slice(6,12))}}frobeniusMap(e,r){let{Fp6:n}=this,{Fp2:o}=n,{c0:s,c1:i,c2:a}=n.frobeniusMap(e.c1,r),c=this.FROBENIUS_COEFFICIENTS[r%12];return{c0:n.frobeniusMap(e.c0,r),c1:n.create({c0:o.mul(s,c),c1:o.mul(i,c),c2:o.mul(a,c)})}}mulByFp2({c0:e,c1:r},n){let{Fp6:o}=this;return{c0:o.mulByFp2(e,n),c1:o.mulByFp2(r,n)}}conjugate({c0:e,c1:r}){return{c0:e,c1:this.Fp6.neg(r)}}mul014({c0:e,c1:r},n,o,s){let{Fp6:i}=this,{Fp2:a}=i,c=i.mul01(e,n,o),d=i.mul1(r,s);return{c0:i.add(i.mulByNonresidue(d),c),c1:i.sub(i.sub(i.mul01(i.add(r,e),n,a.add(o,s)),c),d)}}mul034({c0:e,c1:r},n,o,s){let{Fp6:i}=this,{Fp2:a}=i,c=i.create({c0:a.mul(e.c0,n),c1:a.mul(e.c1,n),c2:a.mul(e.c2,n)}),d=i.mul01(r,o,s),p=i.mul01(i.add(e,r),a.add(n,o),s);return{c0:i.add(i.mulByNonresidue(d),c),c1:i.sub(p,i.add(c,d))}}_cyclotomicSquare({c0:e,c1:r}){let{Fp6:n}=this,{Fp2:o}=n,{c0:s,c1:i,c2:a}=e,{c0:c,c1:d,c2:p}=r,{first:l,second:u}=o.Fp4Square(s,d),{first:f,second:h}=o.Fp4Square(c,a),{first:m,second:b}=o.Fp4Square(i,p),y=o.mulByNonresidue(b);return{c0:n.create({c0:o.add(o.mul(o.sub(l,s),$t),l),c1:o.add(o.mul(o.sub(f,i),$t),f),c2:o.add(o.mul(o.sub(m,a),$t),m)}),c1:n.create({c0:o.add(o.mul(o.add(y,c),$t),y),c1:o.add(o.mul(o.add(u,d),$t),u),c2:o.add(o.mul(o.add(h,p),$t),h)})}}_cyclotomicExp(e,r){let n=this.ONE;for(let o=this.X_LEN-1;o>=0;o--)n=this._cyclotomicSquare(n),yx(r,o)&&(n=this.mul(n,e));return n}};function jx(t){let e=jt(t.ORDER),r=new m0(e,t),n=new y0(r),o=new _0(n,t);return{Fp:e,Fp2:r,Fp6:n,Fp12:o}}var Pt=BigInt(0),kd=BigInt(1),Er=BigInt(2),jd=BigInt(3),pc=BigInt(4),Mo=BigInt("0xd201000000010000"),o3=Jn(Mo),Is={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:Pt,b:pc,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")},s3=jt(Is.n,{modFromBytes:!0,isLE:!0}),{Fp:J,Fp2:we,Fp6:i3,Fp12:Re}=jx({ORDER:Is.p,X_LEN:o3,FP2_NONRESIDUE:[kd,kd],Fp2mulByB:({c0:t,c1:e})=>{let r=J.mul(t,pc),n=J.mul(e,pc);return{c0:J.sub(r,n),c1:J.add(r,n)}},Fp12finalExponentiate:t=>{let e=Mo,r=Re.div(Re.frobeniusMap(t,6),t),n=Re.mul(Re.frobeniusMap(r,2),r),o=Re.conjugate(Re._cyclotomicExp(n,e)),s=Re.mul(Re.conjugate(Re._cyclotomicSquare(n)),o),i=Re.conjugate(Re._cyclotomicExp(s,e)),a=Re.conjugate(Re._cyclotomicExp(i,e)),c=Re.mul(Re.conjugate(Re._cyclotomicExp(a,e)),Re._cyclotomicSquare(o)),d=Re.conjugate(Re._cyclotomicExp(c,e)),p=Re.frobeniusMap(Re.mul(o,a),2),l=Re.frobeniusMap(Re.mul(i,n),3),u=Re.frobeniusMap(Re.mul(c,Re.conjugate(n)),1),f=Re.mul(Re.mul(d,Re.conjugate(s)),n);return Re.mul(Re.mul(Re.mul(p,l),u),f)}}),{G2psi:Hx,G2psi2:a3}=kx(J,we,we.div(we.ONE,we.NONRESIDUE)),g0=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:J.ORDER,m:2,k:128,expand:"xmd",hash:Ct}),E0={p:we.ORDER,n:Is.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:we.ZERO,b:we.fromBigTuple([pc,pc]),Gx:we.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:we.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},Hd=hc(J.toBytes(Pt),{infinity:!0,compressed:!0});function $d(t){t=t.slice();let e=t[0]&224,r=!!(e>>7&1),n=!!(e>>6&1),o=!!(e>>5&1);return t[0]&=31,{compressed:r,infinity:n,sort:o,value:t}}function hc(t,e){if(t[0]&224)throw new Error("setMask: non-empty mask");return e.compressed&&(t[0]|=128),e.infinity&&(t[0]|=64),e.sort&&(t[0]|=32),t}function c3(t,e,r){let{BYTES:n,ORDER:o}=J,s=e.is0(),{x:i,y:a}=e.toAffine();if(r){if(s)return Hd.slice();let c=!!(a*Er/o);return hc(ct(i,n),{compressed:!0,sort:c})}else return s?fe(Uint8Array.of(64),new Uint8Array(2*n-1)):fe(ct(i,n),ct(a,n))}function x0(t){t.assertValidity();let{BYTES:e,ORDER:r}=J,{x:n,y:o}=t.toAffine();if(t.is0())return Hd.slice();let s=!!(o*Er/r);return hc(ct(n,e),{compressed:!0,sort:s})}function u3(t){let{compressed:e,infinity:r,sort:n,value:o}=$d(t),{BYTES:s,ORDER:i}=J;if(o.length===48&&e){let a=nr(o),c=J.create(a&Mr(J.BITS));if(r){if(c!==Pt)throw new Error("invalid G1 point: non-empty, at infinity, with compression");return{x:Pt,y:Pt}}let d=J.add(J.pow(c,jd),J.create(Is.b)),p=J.sqrt(d);if(!p)throw new Error("invalid G1 point: compressed point");return p*Er/i!==BigInt(n)&&(p=J.neg(p)),{x:J.create(c),y:J.create(p)}}else if(o.length===96&&!e){let a=nr(o.subarray(0,s)),c=nr(o.subarray(s));if(r){if(a!==Pt||c!==Pt)throw new Error("G1: non-empty point at infinity");return mc.G1.Point.ZERO.toAffine()}return{x:J.create(a),y:J.create(c)}}else throw new Error("invalid G1 point: expected 48/96 bytes")}function $x(t){let{infinity:e,sort:r,value:n}=$d(Ze("signatureHex",t,48)),o=J.ORDER,s=mc.G1.Point,i=nr(n);if(e)return s.ZERO;let a=J.create(i&Mr(J.BITS)),c=J.add(J.pow(a,jd),J.create(Is.b)),d=J.sqrt(c);if(!d)throw new Error("invalid G1 point: compressed");let p=BigInt(r);d*Er/o!==p&&(d=J.neg(d));let l=s.fromAffine({x:a,y:d});return l.assertValidity(),l}function d3(t,e,r){let{BYTES:n,ORDER:o}=J,s=e.is0(),{x:i,y:a}=e.toAffine();if(r){if(s)return fe(Hd,ct(Pt,n));let c=!!(a.c1===Pt?a.c0*Er/o:a.c1*Er/o);return fe(hc(ct(i.c1,n),{compressed:!0,sort:c}),ct(i.c0,n))}else{if(s)return fe(Uint8Array.of(64),new Uint8Array(4*n-1));let{re:c,im:d}=we.reim(i),{re:p,im:l}=we.reim(a);return fe(ct(d,n),ct(c,n),ct(l,n),ct(p,n))}}function w0(t){t.assertValidity();let{BYTES:e}=J;if(t.is0())return fe(Hd,ct(Pt,e));let{x:r,y:n}=t.toAffine(),{re:o,im:s}=we.reim(r),{re:i,im:a}=we.reim(n),d=!!((a>Pt?a*Er:i*Er)/J.ORDER&kd),p=o;return fe(hc(ct(s,e),{sort:d,compressed:!0}),ct(p,e))}function l3(t){let{BYTES:e,ORDER:r}=J,{compressed:n,infinity:o,sort:s,value:i}=$d(t);if(!n&&!o&&s||!n&&o&&s||s&&o&&n)throw new Error("invalid encoding flag: "+(t[0]&224));let a=(c,d,p)=>nr(c.slice(d,p));if(i.length===96&&n){if(o){if(i.reduce((h,m)=>h!==0?m+1:m,0)>0)throw new Error("invalid G2 point: compressed");return{x:we.ZERO,y:we.ZERO}}let c=a(i,0,e),d=a(i,e,2*e),p=we.create({c0:J.create(d),c1:J.create(c)}),l=we.add(we.pow(p,jd),E0.b),u=we.sqrt(l),f=u.c1===Pt?u.c0*Er/r:u.c1*Er/r?kd:Pt;return u=s&&f>0?u:we.neg(u),{x:p,y:u}}else if(i.length===192&&!n){if(o){if(i.reduce((u,f)=>u!==0?f+1:f,0)>0)throw new Error("invalid G2 point: uncompressed");return{x:we.ZERO,y:we.ZERO}}let c=a(i,0*e,1*e),d=a(i,1*e,2*e),p=a(i,2*e,3*e),l=a(i,3*e,4*e);return{x:we.fromBigTuple([d,c]),y:we.fromBigTuple([l,p])}}else throw new Error("invalid G2 point: expected 96/192 bytes")}function Kx(t){let{ORDER:e}=J,{infinity:r,sort:n,value:o}=$d(Ze("signatureHex",t)),s=mc.G2.Point,i=o.length/2;if(i!==48&&i!==96)throw new Error("invalid compressed signature length, expected 96/192 bytes");let a=nr(o.slice(0,i)),c=nr(o.slice(i));if(r)return s.ZERO;let d=J.create(a&Mr(J.BITS)),p=J.create(c),l=we.create({c0:p,c1:d}),u=we.add(we.pow(l,jd),E0.b),f=we.sqrt(u);if(!f)throw new Error("Failed to find a square root");let{re:h,im:m}=we.reim(f),b=BigInt(n),y=m>Pt&&m*Er/e!==b,x=m===Pt&&h*Er/e!==b;(y||x)&&(f=we.neg(f));let _=s.fromAffine({x:l,y:f});return _.assertValidity(),_}var mc=Ux({fields:{Fp:J,Fp2:we,Fp6:i3,Fp12:Re,Fr:s3},G1:{...Is,Fp:J,htfDefaults:{...g0,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(t,e)=>{let r=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),n=new t(J.mul(e.X,r),e.Y,e.Z);return e.multiplyUnsafe(Mo).negate().multiplyUnsafe(Mo).equals(n)},clearCofactor:(t,e)=>e.multiplyUnsafe(Mo).add(e),mapToCurve:y3,fromBytes:u3,toBytes:c3,ShortSignature:{fromBytes(t){return Xe(t),$x(t)},fromHex(t){return $x(t)},toBytes(t){return x0(t)},toRawBytes(t){return x0(t)},toHex(t){return de(x0(t))}}},G2:{...E0,Fp:we,hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...g0},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:_3,isTorsionFree:(t,e)=>e.multiplyUnsafe(Mo).negate().equals(Hx(t,e)),clearCofactor:(t,e)=>{let r=Mo,n=e.multiplyUnsafe(r).negate(),o=Hx(t,e),s=e.double();return s=a3(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)},fromBytes:l3,toBytes:d3,Signature:{fromBytes(t){return Xe(t),Kx(t)},fromHex(t){return Kx(t)},toBytes(t){return w0(t)},toRawBytes(t){return w0(t)},toHex(t){return de(w0(t))}}},params:{ateLoopSize:Mo,r:Is.n,xNegative:!0,twistType:"multiplicative"},htfDefaults:g0,hash:Ct}),f3=u0(we,[[["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=>we.fromBigTuple(e.map(BigInt))))),p3=u0(J,[["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)))),h3=f0(J,{A:J.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:J.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:J.create(BigInt(11))}),m3=f0(we,{A:we.create({c0:J.create(Pt),c1:J.create(BigInt(240))}),B:we.create({c0:J.create(BigInt(1012)),c1:J.create(BigInt(1012))}),Z:we.create({c0:J.create(BigInt(-2)),c1:J.create(BigInt(-1))})});function y3(t){let{x:e,y:r}=h3(J.create(t[0]));return p3(e,r)}function _3(t){let{x:e,y:r}=m3(we.fromBigTuple(t));return f3(e,r)}function Gx(t,e,r){let n=typeof t=="string"?t:de(t),o=typeof e=="string"?e:de(e),s=typeof r=="string"?r:de(r);return mc.verifyShortSignature(o,s,n)}var g3=BigInt(1e6),T0=t=>tt(new Fr(t)),Ui=t=>{let r=T0(t)/g3;return new Date(Number(r))};var zx=60*1e3,x3=60,w3=24,E3=w3*x3,T3=5,O3=5,N3=30*E3,Et;(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"})(Et||(Et={}));function v3(t,e){for(let r=0;r<t.length;r++)if(t[r]>e[r])return!0;return!1}var ko=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.canisterId,e.blsVerify??Gx,e.maxAgeInMinutes,e.disableTimeVerification,e.agent)}constructor(e,r,n,o,s=T3,i=!1,a){this._rootKey=r,this._canisterId=n,this._blsVerify=o,this._maxAgeInMinutes=s,this.#e=i,this.cert=rr(e),a&&"getTimeDiffMsecs"in a&&"hasSyncedTime"in a&&"syncTime"in a&&(this.#t=a)}lookup_path(e){return Ss(e,this.cert.tree)}lookup_subtree(e){return zd(e,this.cert.tree)}async verify(){let e=await Kd(this.cert.tree),r=await this._checkDelegationAndGetKey(this.cert.delegation),n=this.cert.signature,o=R3(r),s=fe(_c("ic-state-root"),e),i=Dt(this.lookup_path(["time"]));if(!i)throw Me.fromCode(new Ao("Certificate does not contain a time"));if(!this.#e){let a=this.#t?.getTimeDiffMsecs()??0,c=this._maxAgeInMinutes*zx,d=new Date,p=d.getTime()+a,l=p-c,u=p+O3*zx,f=Ui(i),h=f.getTime()<l,m=f.getTime()>u;if((h||m)&&this.#t&&!this.#t.hasSyncedTime())return await this.#t.syncTime(this._canisterId),await this.verify();if(h)throw Lt.fromCode(new ps(this._maxAgeInMinutes,f,d,a,"past"));if(m)throw this.#t?.hasSyncedTime()?st.fromCode(new qt("System time has been synced with the IC network, but certificate is still too far in the future.")):Lt.fromCode(new ps(5,f,d,a,"future"))}try{if(!await this._blsVerify(o,n,s))throw Lt.fromCode(new Ao("Invalid signature"))}catch(a){throw Lt.fromCode(new Ao("Signature verification failed",a))}}async _checkDelegationAndGetKey(e){if(!e)return this._rootKey;let r=t.createUnverified({certificate:e.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,disableTimeVerification:this.#e,maxAgeInMinutes:N3,agent:this.#t});if(r.cert.delegation)throw Me.fromCode(new od);await r.verify();let n=e.subnet_id,o=oe.fromUint8Array(n);if(!O0({canisterId:this._canisterId,subnetId:o,tree:r.cert.tree}))throw Lt.fromCode(new _i(this._canisterId,o));let i=Dt(r.lookup_path(["subnet",n,"public_key"]));if(!i)throw Lt.fromCode(new sd(`Could not find subnet key for subnet ID ${o.toText()}`));return i}},yc=ht("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),I3=96;function R3(t){let e=yc.byteLength+I3;if(t.byteLength!==e)throw Me.fromCode(new gi(e,t.byteLength));let r=t.slice(0,yc.byteLength);if(!xs(r,yc))throw Me.fromCode(new id(yc,r));return t.slice(yc.byteLength)}function Dt(t){if(t.status===or.Found&&t.value instanceof Uint8Array)return t.value}async function Kd(t){switch(t[0]){case Et.Empty:return Ct(_c("ic-hashtree-empty"));case Et.Pruned:return t[1];case Et.Leaf:return Ct(fe(_c("ic-hashtree-leaf"),t[1]));case Et.Labeled:return Ct(fe(_c("ic-hashtree-labeled"),t[1],await Kd(t[2])));case Et.Fork:return Ct(fe(_c("ic-hashtree-fork"),await Kd(t[1]),await Kd(t[2])));default:throw Po}}function _c(t){let e=new Uint8Array([t.length]),r=new TextEncoder().encode(t);return fe(e,r)}function Zx(t){return typeof t[0]=="string"?Ve(t[0]):t[0]}var or;(function(t){t.Unknown="Unknown",t.Absent="Absent",t.Found="Found",t.Error="Error"})(or||(or={}));var Rs;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found"})(Rs||(Rs={}));var Ge;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found",t.Less="Less",t.Greater="Greater"})(Ge||(Ge={}));function Ss(t,e){if(t.length===0)switch(e[0]){case Et.Empty:return{status:or.Absent};case Et.Leaf:{if(!e[1])throw st.fromCode(new Co("Invalid tree structure for leaf"));if(e[1]instanceof Uint8Array)return{status:or.Found,value:e[1].slice(e[1].byteOffset,e[1].byteLength+e[1].byteOffset)};throw Po}case Et.Pruned:return{status:or.Unknown};case Et.Labeled:case Et.Fork:return{status:or.Error};default:throw Po}let r=Zx(t),n=bc(r,e);switch(n.status){case Ge.Found:return Ss(t.slice(1),n.value);case Ge.Absent:case Ge.Greater:case Ge.Less:return{status:or.Absent};case Ge.Unknown:return{status:or.Unknown};default:throw Po}}function zd(t,e){if(t.length===0)return{status:Rs.Found,value:e};let r=Zx(t),n=bc(r,e);switch(n.status){case Ge.Found:return zd(t.slice(1),n.value);case Ge.Unknown:return{status:Rs.Unknown};case Ge.Absent:case Ge.Greater:case Ge.Less:return{status:Rs.Absent};default:throw Po}}function Gd(t){switch(t[0]){case Et.Empty:return[];case Et.Fork:return Gd(t[1]).concat(Gd(t[2]));default:return[t]}}function bc(t,e){switch(e[0]){case Et.Labeled:return v3(t,e[1])?{status:Ge.Greater}:xs(t,e[1])?{status:Ge.Found,value:e[2]}:{status:Ge.Less};case Et.Fork:{let r=bc(t,e[1]);switch(r.status){case Ge.Greater:{let n=bc(t,e[2]);return n.status===Ge.Less?{status:Ge.Absent}:n}case Ge.Unknown:{let n=bc(t,e[2]);return n.status===Ge.Less?{status:Ge.Unknown}:n}default:return r}}case Et.Pruned:return{status:Ge.Unknown};default:return{status:Ge.Absent}}}function O0(t){let{canisterId:e,subnetId:r,tree:n}=t,o=Ss(["subnet",r.toUint8Array(),"canister_ranges"],n);if(o.status!==or.Found)throw Me.fromCode(new $n(`Could not find canister ranges for subnet ${r.toText()}`,o.status));if(!(o.value instanceof Uint8Array))throw Me.fromCode(new bi(`Could not find canister ranges for subnet ${r.toText()}`));return rr(o.value).map(c=>[oe.fromUint8Array(c[0]),oe.fromUint8Array(c[1])]).some(c=>c[0].ltEq(e)&&c[1].gtEq(e))}var N0=async t=>{let{agent:e,paths:r,disableCertificateTimeVerification:n=!1}=t,o=oe.from(t.canisterId),s=[...new Set(r)],i=new Map,a=s.map((c,d)=>{let p=A3(c,o);return(async()=>{try{if(e.rootKey===null)throw mt.fromCode(new ln);let l=e.rootKey,u=await e.readState(o,{paths:[p]}),f=await ko.create({certificate:u.certificate,rootKey:l,canisterId:o,disableTimeVerification:n,agent:e}),h=(y,x)=>{if(x==="subnet"){let _=S3(u.certificate,o,l);return{path:x,data:_}}else return{path:x,data:Dt(y.lookup_path(p))}},{path:m,data:b}=h(f,s[d]);if(!b)console.warn(`Expected to find result for path ${m}, but instead found nothing.`),typeof m=="string"?i.set(m,null):i.set(m.key,null);else switch(m){case"time":{i.set(m,Ui(b));break}case"controllers":{i.set(m,B3(b));break}case"module_hash":{i.set(m,de(b));break}case"subnet":{i.set(m,b);break}case"candid":{i.set(m,new TextDecoder().decode(b));break}default:if(typeof m!="string"&&"key"in m&&"path"in m)switch(m.decodeStrategy){case"raw":i.set(m.key,b);break;case"leb128":{i.set(m.key,T0(b));break}case"cbor":{i.set(m.key,rr(b));break}case"hex":{i.set(m.key,de(b));break}case"utf-8":i.set(m.key,new TextDecoder().decode(b))}}}catch(l){if(l instanceof Pr&&(l.hasCode(Ao)||l.hasCode(ps)))throw l;typeof c!="string"&&"key"in c&&"path"in c?i.set(c.key,null):i.set(c,null),console.group(),console.warn(`Expected to find result for path ${c}, but instead found nothing.`),console.warn(l),console.groupEnd()}})()});return await Promise.all(a),i},S3=(t,e,r)=>{if(!e._isPrincipal)throw Ne.fromCode(new qt("Invalid canisterId"));let n=rr(t),o=n.tree,s=n.delegation,i;if(s&&s.subnet_id?i=oe.fromUint8Array(new Uint8Array(s.subnet_id)):!s&&typeof r<"u"?(i=oe.selfAuthenticating(new Uint8Array(r)),s={subnet_id:i.toUint8Array(),certificate:new Uint8Array(0)}):(i=oe.selfAuthenticating(oe.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),s={subnet_id:i.toUint8Array(),certificate:new Uint8Array(0)}),!O0({canisterId:e,subnetId:i,tree:o}))throw Lt.fromCode(new _i(e,i));let c=zd(["subnet",s.subnet_id,"node"],o);if(c.status!==Rs.Found)throw Me.fromCode(new $n("Node not found",c.status));if(c.value instanceof Uint8Array)throw st.fromCode(new Co("Invalid node tree"));let d=Gd(c.value),p=new Map;return d.forEach(l=>{let u=oe.from(l[1]).toText(),f=Ss(["public_key"],l[2]);if(f.status!==or.Found)throw Me.fromCode(new $n("Public key not found",f.status));let h=f.value;if(h.byteLength!==44)throw Me.fromCode(new gi(44,h.byteLength));p.set(u,h)}),{subnetId:oe.fromUint8Array(new Uint8Array(s.subnet_id)).toText(),nodeKeys:p}},A3=(t,e)=>{let r=e.toUint8Array();switch(t){case"time":return[Ve("time")];case"controllers":return[Ve("canister"),r,Ve("controllers")];case"module_hash":return[Ve("canister"),r,Ve("module_hash")];case"subnet":return[Ve("subnet")];case"candid":return[Ve("canister"),r,Ve("metadata"),Ve("candid:service")];default:if("key"in t&&"path"in t)if(typeof t.path=="string"||t.path instanceof Uint8Array){let n=t.path,o=typeof n=="string"?Ve(n):n;return[Ve("canister"),r,Ve("metadata"),o]}else return t.path}throw st.fromCode(new qt(`Error while encoding your path for canister status. Please ensure that your path ${t} was formatted correctly.`))},B3=t=>rr(t).map(r=>oe.fromUint8Array(r));var jo=BigInt(0),_t=BigInt(1),v0=BigInt(2),C3=BigInt(8);function P3(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function D3(t,e={}){let r=qd("edwards",t,e,e.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;Qn(e,{},{uvRatio:"function"});let a=v0<<BigInt(o.BYTES*8)-_t,c=b=>n.create(b),d=e.uvRatio||((b,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(b,y))}}catch{return{isValid:!1,value:jo}}});if(!P3(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function p(b,y,x=!1){let _=x?_t:jo;return Vd("coordinate "+b,y,_,a),y}function l(b){if(!(b instanceof h))throw new Error("ExtendedPoint expected")}let u=Lo((b,y)=>{let{X:x,Y:_,Z:T}=b,N=b.is0();y==null&&(y=N?C3:n.inv(T));let I=c(x*y),v=c(_*y),A=n.mul(T,y);if(N)return{x:jo,y:_t};if(A!==_t)throw new Error("invZ was invalid");return{x:I,y:v}}),f=Lo(b=>{let{a:y,d:x}=s;if(b.is0())throw new Error("bad point: ZERO");let{X:_,Y:T,Z:N,T:I}=b,v=c(_*_),A=c(T*T),E=c(N*N),S=c(E*E),V=c(v*y),C=c(E*c(V+A)),g=c(S+c(x*c(v*A)));if(C!==g)throw new Error("bad point: equation left != right (1)");let w=c(_*T),O=c(N*I);if(w!==O)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(y,x,_,T){this.X=p("x",y),this.Y=p("y",x),this.Z=p("z",_,!0),this.T=p("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof h)throw new Error("extended point not allowed");let{x,y:_}=y||{};return p("x",x),p("y",_),new h(x,_,_t,c(x*_))}static fromBytes(y,x=!1){let _=n.BYTES,{a:T,d:N}=s;y=e0(Uo(y,_,"point")),Ts(x,"zip215");let I=e0(y),v=y[_-1];I[_-1]=v&-129;let A=Xn(I),E=x?a:n.ORDER;Vd("point.y",A,jo,E);let S=c(A*A),V=c(S-_t),C=c(N*S-T),{isValid:g,value:w}=d(V,C);if(!g)throw new Error("bad point: invalid y coordinate");let O=(w&_t)===_t,P=(v&128)!==0;if(!x&&w===jo&&P)throw new Error("bad point: x=0 and x_0=1");return P!==O&&(w=c(-w)),h.fromAffine({x:w,y:A})}static fromHex(y,x=!1){return h.fromBytes(Ze("point",y),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,x=!0){return m.createCache(this,y),x||this.multiply(v0),this}assertValidity(){f(this)}equals(y){l(y);let{X:x,Y:_,Z:T}=this,{X:N,Y:I,Z:v}=y,A=c(x*v),E=c(N*T),S=c(_*v),V=c(I*T);return A===E&&S===V}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=s,{X:x,Y:_,Z:T}=this,N=c(x*x),I=c(_*_),v=c(v0*c(T*T)),A=c(y*N),E=x+_,S=c(c(E*E)-N-I),V=A+I,C=V-v,g=A-I,w=c(S*C),O=c(V*g),P=c(S*g),L=c(C*V);return new h(w,O,L,P)}add(y){l(y);let{a:x,d:_}=s,{X:T,Y:N,Z:I,T:v}=this,{X:A,Y:E,Z:S,T:V}=y,C=c(T*A),g=c(N*E),w=c(v*_*V),O=c(I*S),P=c((T+N)*(A+E)-C-g),L=O-w,R=O+w,B=c(g-x*C),F=c(P*L),U=c(R*B),q=c(P*B),H=c(L*R);return new h(F,U,H,q)}subtract(y){return this.add(y.negate())}multiply(y){if(!o.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:_}=m.cached(this,y,T=>wr(h,T));return wr(h,[x,_])[0]}multiplyUnsafe(y,x=h.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===jo?h.ZERO:this.is0()||y===_t?this:m.unsafe(this,y,_=>wr(h,_),x)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return m.unsafe(this,s.n).is0()}toAffine(y){return u(this,y)}clearCofactor(){return i===_t?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:x}=this.toAffine(),_=n.toBytes(x);return _[_.length-1]|=y&_t?128:0,_}toHex(){return de(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(y){return wr(h,y)}static msm(y,x){return Di(h,o,y,x)}_setWindowSize(y){this.precompute(y)}toRawBytes(){return this.toBytes()}}h.BASE=new h(s.Gx,s.Gy,_t,c(s.Gx*s.Gy)),h.ZERO=new h(jo,_t,_t,jo),h.Fp=n,h.Fn=o;let m=new Pi(h,o.BITS);return h.BASE.precompute(8),h}var Zd=class{constructor(e){this.ep=e}static fromBytes(e){Bi()}static fromHex(e){Bi()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return de(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.init(this.ep.precompute(e,r))}toRawBytes(){return this.toBytes()}};function F3(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');Qn(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=t,a=r.randomBytes||yi,c=r.adjustScalarBytes||(E=>E),d=r.domain||((E,S,V)=>{if(Ts(V,"phflag"),S.length||V)throw new Error("Contexts/pre-hash are not supported");return E});function p(E){return i.create(Xn(E))}function l(E){let S=_.secretKey;E=Ze("private key",E,S);let V=Ze("hashed private key",e(E),2*S),C=c(V.slice(0,S)),g=V.slice(S,2*S),w=p(C);return{head:C,prefix:g,scalar:w}}function u(E){let{head:S,prefix:V,scalar:C}=l(E),g=o.multiply(C),w=g.toBytes();return{head:S,prefix:V,scalar:C,point:g,pointBytes:w}}function f(E){return u(E).pointBytes}function h(E=Uint8Array.of(),...S){let V=fe(...S);return p(e(d(V,Ze("context",E),!!n)))}function m(E,S,V={}){E=Ze("message",E),n&&(E=n(E));let{prefix:C,scalar:g,pointBytes:w}=u(S),O=h(V.context,C,E),P=o.multiply(O).toBytes(),L=h(V.context,P,w,E),R=i.create(O+L*g);if(!i.isValid(R))throw new Error("sign failed: invalid s");let B=fe(P,i.toBytes(R));return Uo(B,_.signature,"result")}let b={zip215:!0};function y(E,S,V,C=b){let{context:g,zip215:w}=C,O=_.signature;E=Ze("signature",E,O),S=Ze("message",S),V=Ze("publicKey",V,_.publicKey),w!==void 0&&Ts(w,"zip215"),n&&(S=n(S));let P=O/2,L=E.subarray(0,P),R=Xn(E.subarray(P,O)),B,F,U;try{B=t.fromBytes(V,w),F=t.fromBytes(L,w),U=o.multiplyUnsafe(R)}catch{return!1}if(!w&&B.isSmallOrder())return!1;let q=h(g,F.toBytes(),B.toBytes(),S);return F.add(B.multiplyUnsafe(q)).subtract(U).clearCofactor().is0()}let x=s.BYTES,_={secretKey:x,publicKey:x,signature:2*x,seed:x};function T(E=a(_.seed)){return Uo(E,_.seed,"seed")}function N(E){let S=A.randomSecretKey(E);return{secretKey:S,publicKey:f(S)}}function I(E){return un(E)&&E.length===i.BYTES}function v(E,S){try{return!!t.fromBytes(E,S)}catch{return!1}}let A={getExtendedPublicKey:u,randomSecretKey:T,isValidSecretKey:I,isValidPublicKey:v,toMontgomery(E){let{y:S}=t.fromBytes(E),V=_.publicKey,C=V===32;if(!C&&V!==57)throw new Error("only defined for 25519 and 448");let g=C?s.div(_t+S,_t-S):s.div(S-_t,S+_t);return s.toBytes(g)},toMontgomerySecret(E){let S=_.secretKey;Uo(E,S);let V=e(E.subarray(0,S));return c(V).subarray(0,S)},randomPrivateKey:T,precompute(E=8,S=t.BASE){return S.precompute(E,!1)}};return Object.freeze({keygen:N,getPublicKey:f,sign:m,verify:y,utils:A,Point:t,lengths:_})}function V3(t){let e={a:t.a,d:t.d,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=jt(e.n,t.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:t.uvRatio},s={randomBytes:t.randomBytes,adjustScalarBytes:t.adjustScalarBytes,domain:t.domain,prehash:t.prehash,mapToCurve:t.mapToCurve};return{CURVE:e,curveOpts:o,hash:t.hash,eddsaOpts:s}}function U3(t,e){let r=e.Point;return Object.assign({},e,{ExtendedPoint:r,CURVE:t,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Yx(t){let{CURVE:e,curveOpts:r,hash:n,eddsaOpts:o}=V3(t),s=D3(e,r),i=F3(s,n,o);return U3(t,i)}var L3=BigInt(0),no=BigInt(1),Wx=BigInt(2),nS=BigInt(3),q3=BigInt(5),M3=BigInt(8),Li=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),gc={p:Li,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:M3,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function k3(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Li,a=t*t%s*t%s,c=kr(a,Wx,s)*a%s,d=kr(c,no,s)*t%s,p=kr(d,q3,s)*d%s,l=kr(p,e,s)*p%s,u=kr(l,r,s)*l%s,f=kr(u,n,s)*u%s,h=kr(f,o,s)*f%s,m=kr(h,o,s)*f%s,b=kr(m,e,s)*p%s;return{pow_p_5_8:kr(b,Wx,s)*t%s,b2:a}}function j3(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var I0=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function A0(t,e){let r=Li,n=Ke(e*e*e,r),o=Ke(n*n*e,r),s=k3(t*o).pow_p_5_8,i=Ke(t*n*s,r),a=Ke(e*i*i,r),c=i,d=Ke(i*I0,r),p=a===t,l=a===Ke(-t,r),u=a===Ke(-t*I0,r);return p&&(i=c),(l||u)&&(i=d),eo(i,r)&&(i=Ke(-i,r)),{isValid:p||l,value:i}}var Ho=jt(gc.p,{isLE:!0}),H3=jt(gc.n,{isLE:!0}),$3={...gc,Fp:Ho,hash:wg,adjustScalarBytes:j3,uvRatio:A0},Kt=Yx($3);var R0=I0,K3=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),G3=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),z3=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Z3=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Xx=t=>A0(no,t),Y3=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),S0=t=>Kt.Point.Fp.create(Xn(t)&Y3);function Jx(t){let{d:e}=gc,r=Li,n=y=>Ho.create(y),o=n(R0*t*t),s=n((o+no)*z3),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:d}=A0(s,a),p=n(d*t);eo(p,r)||(p=n(-p)),c||(d=p),c||(i=o);let l=n(i*(o-no)*Z3-a),u=d*d,f=n((d+d)*a),h=n(l*K3),m=n(no-u),b=n(no+u);return new Kt.Point(n(f*b),n(m*h),n(h*b),n(f*m))}function W3(t){Xe(t,64);let e=S0(t.subarray(0,32)),r=Jx(e),n=S0(t.subarray(32,64)),o=Jx(n);return new oo(r.add(o))}var oo=class t extends Zd{constructor(e){super(e)}static fromAffine(e){return new t(Kt.Point.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static hashToCurve(e){return W3(Ze("ristrettoHash",e,64))}static fromBytes(e){Xe(e,32);let{a:r,d:n}=gc,o=Li,s=T=>Ho.create(T),i=S0(e);if(!mx(Ho.toBytes(i),e)||eo(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(no+r*a),d=s(no-r*a),p=s(c*c),l=s(d*d),u=s(r*n*p-l),{isValid:f,value:h}=Xx(s(u*l)),m=s(h*d),b=s(h*m*u),y=s((i+i)*m);eo(y,o)&&(y=s(-y));let x=s(c*b),_=s(y*x);if(!f||eo(_,o)||x===L3)throw new Error("invalid ristretto255 encoding 2");return new t(new Kt.Point(y,x,no,_))}static fromHex(e){return t.fromBytes(Ze("ristrettoHex",e,32))}static msm(e,r){return Di(t,Kt.Point.Fn,e,r)}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=Li,i=b=>Ho.create(b),a=i(i(n+r)*i(n-r)),c=i(e*r),d=i(c*c),{value:p}=Xx(i(a*d)),l=i(p*a),u=i(p*c),f=i(l*u*o),h;if(eo(o*f,s)){let b=i(r*R0),y=i(e*R0);e=b,r=y,h=i(l*G3)}else h=u;eo(e*f,s)&&(r=i(-r));let m=i((n-r)*h);return eo(m,s)&&(m=i(-m)),Ho.toBytes(m)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=d=>Ho.create(d),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(t.ZERO)}};oo.BASE=new oo(Kt.Point.BASE);oo.ZERO=new oo(Kt.Point.ZERO);oo.Fp=Ho;oo.Fn=H3;var Qx,ew,Yd=class{static{Qx=Symbol.iterator,ew=Symbol.toStringTag}#e;#t;constructor(e={}){this[Qx]=this.entries.bind(this),this[ew]="ExpirableMap";let{source:r=[],expirationTime:n=600*1e3}=e,o=Date.now();this.#e=new Map([...r].map(([s,i])=>[s,{value:i,timestamp:o}])),this.#t=n}prune(){let e=Date.now();for(let[r,n]of this.#e.entries())e-n.timestamp>this.#t&&this.#e.delete(r);return this}set(e,r){this.prune();let n={value:r,timestamp:Date.now()};return this.#e.set(e,n),this}get(e){let r=this.#e.get(e);if(r!==void 0){if(Date.now()-r.timestamp>this.#t){this.#e.delete(e);return}return r.value}}clear(){this.#e.clear()}entries(){let e=this.#e.entries();return function*(){for(let[n,o]of e)yield[n,o.value]}()}values(){let e=this.#e.values();return function*(){for(let n of e)yield n.value}()}keys(){return this.#e.keys()}forEach(e,r){for(let[n,o]of this.#e.entries())e.call(r,o.value,n,this)}has(e){return this.#e.has(e)}delete(e){return this.#e.delete(e)}get size(){return this.#e.size}};var tw=t=>{if(t<=127)return 1;if(t<=255)return 2;if(t<=65535)return 3;if(t<=16777215)return 4;throw Ne.fromCode(new ka("Length too long (> 4 bytes)"))},rw=(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 Ne.fromCode(new ka("Length too long (> 4 bytes)"))},B0=(t,e)=>{if(t[e]<128)return 1;if(t[e]===128)throw Ne.fromCode(new Dr("Invalid length 0"));if(t[e]===129)return 2;if(t[e]===130)return 3;if(t[e]===131)return 4;throw Ne.fromCode(new Dr("Length too long (> 4 bytes)"))},X3=(t,e)=>{let r=B0(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 Ne.fromCode(new Dr("Length too long (> 4 bytes)"))},xc=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),As=Uint8Array.from([48,5,6,3,43,101,112]),cS=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]),uS=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 Bs(t,e){let r=2+tw(t.byteLength+1),n=e.byteLength+r+t.byteLength,o=0,s=new Uint8Array(1+tw(n)+n);return s[o++]=48,o+=rw(s,o,n),s.set(e,o),o+=e.byteLength,s[o++]=3,o+=rw(s,o,t.byteLength+1),s[o++]=0,s.set(new Uint8Array(t),o),s}var Cs=(t,e)=>{let r=0,n=(a,c)=>{if(o[r++]!==a)throw Ne.fromCode(new Dr(`Expected ${c} at offset ${r}`))},o=new Uint8Array(t);if(n(48,"sequence"),r+=B0(o,r),!xs(o.slice(r,r+e.byteLength),e))throw Ne.fromCode(new Dr("Not the expected OID."));r+=e.byteLength,n(3,"bit string");let s=X3(o,r)-1;r+=B0(o,r),n(0,"0 padding");let i=o.slice(r);if(s!==i.length)throw Ne.fromCode(new ad(s,i.length));return i};var Wd=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 Bs(e,As)}static derDecode(e){let r=Cs(e,As);if(r.length!==this.RAW_KEY_LENGTH)throw Ne.fromCode(new Dr("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 Ne.fromCode(new Dr("An Ed25519 public key must be exactly 32 bytes long"));this.#e=e,this.#t=t.derEncode(e)}toDer(){return this.derKey}toRaw(){return this.rawKey}};var C0=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))}},Xd=class extends C0{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 Jd=class t{#e;#t;#r;#c;#i;#d;#n;#o;#a=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:a=10,date:c=Date}=e;this.#e=r,this.#t=n,this.#r=o,this.#c=s,this.#o=c,this.#i=c.now(),this.#d=i,this.#n=a}get ellapsedTimeInMsec(){return this.#o.now()-this.#i}get currentInterval(){return this.#e}get count(){return this.#a}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.#c),this.#a++,this.#e}next(){return this.ellapsedTimeInMsec>=this.#d||this.#a>=this.#n?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};var _n;(function(t){t.Received="received",t.Processing="processing",t.Replied="replied",t.Rejected="rejected",t.Unknown="unknown",t.Done="done"})(_n||(_n={}));var F0=60*1e3,J3=1e6,Q3=0,eN="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae";var tN="ic0.app",rN=".ic0.app",nN="icp0.io",oN=".icp0.io",sN="icp-api.io",iN=".icp-api.io",P0=200,aN=202,cN=404;function uN(){let t;if(typeof window<"u")if(window.fetch)t=window.fetch.bind(window);else throw mt.fromCode(new wi("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present."));else if(typeof global<"u")if(global.fetch)t=global.fetch.bind(global);else throw mt.fromCode(new wi("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available."));else typeof self<"u"&&self.fetch&&(t=self.fetch.bind(self));if(t)return t;throw mt.fromCode(new wi("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context."))}function dN(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(a=>s.endsWith(a))?i=s:i=r.find(a=>s.endsWith(a))),o&&i?e=new URL(`${o.protocol}//${i}${o.port?":"+o.port:""}`):e=new URL("https://icp-api.io")}return e.toString()}var Ps=class t{#e;#t;#r;#c;#i;#d;#n;#o;#a;#g;#s;#l;#f;#u;get#T(){return this.#u*F0}#p;#h;#m;#y;constructor(e={}){this.#e=null,this.#t=!1,this.#r=Q3,this.#c=!1,this.#i=null,this.#d=!1,this._isAgent=!0,this.config={},this.log=new Xd,this.#p=[],this.#h=[],this.#m=new Yd({expirationTime:5*F0}),this.#y=!0,this.#w=(o,s)=>{if(this.#y===!1)return o;let{status:i,signatures:a=[],requestId:c}=o;for(let d of a){let{timestamp:p,identity:l}=d,u=oe.fromUint8Array(l).toText(),f;if(i===No.Replied){let{reply:x}=o;f=Qa({status:i,reply:x,timestamp:BigInt(p),request_id:c})}else if(i===No.Rejected){let{reject_code:x,reject_message:_,error_code:T}=o;f=Qa({status:i,reject_code:x,reject_message:_,error_code:T,timestamp:BigInt(p),request_id:c})}else throw st.fromCode(new qt(`Unknown status: ${i}`));let h=fe(Hh,f),m=s.nodeKeys.get(u);if(!m)throw Me.fromCode(new bd);let b=Wd.fromDer(m).rawKey;if(Kt.verify(d.signature,h,b))return o;throw Lt.fromCode(new gd(u))}return o},this.config=e,this.#o=e.fetch||uN()||fetch.bind(global),this.#a=e.fetchOptions,this.#g=e.callOptions,this.#t=e.shouldFetchRootKey??!1,this.#d=e.shouldSyncTime??!1,e.rootKey?this.rootKey=e.rootKey:this.#t?this.rootKey=null:this.rootKey=ht(eN);let r=dN(e.host);this.host=new URL(r),e.verifyQuerySignatures!==void 0&&(this.#y=e.verifyQuerySignatures),this.#l=e.retryTimes??3;let n=()=>new Jd({maxIterations:this.#l});if(this.#f=e.backoffStrategy||n,this.host.hostname.endsWith(rN)?this.host.hostname=tN:this.host.hostname.endsWith(oN)?this.host.hostname=nN:this.host.hostname.endsWith(iN)&&(this.host.hostname=sN),e.credentials){let{name:o,password:s}=e.credentials;this.#s=`${o}${s?":"+s:""}`}if(this.#n=Promise.resolve(e.identity||new gr),e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes>5)throw Ne.fromCode(new ms("The maximum ingress expiry time is 5 minutes.",e.ingressExpiryInMinutes));if(e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes<=0)throw Ne.fromCode(new ms("Ingress expiry time must be greater than 0.",e.ingressExpiryInMinutes));this.#u=e.ingressExpiryInMinutes||5,this.addTransform("update",Wh(ac)),e.useQueryNonces&&this.addTransform("query",Wh(ac)),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.#b(),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 Ne.fromCode(new md)}}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.#h.findIndex(s=>(s.priority||0)<n);this.#h.splice(o>=0?o:this.#h.length,0,Object.assign(r,{priority:n}))}else if(e==="query"){let o=this.#p.findIndex(s=>(s.priority||0)<n);this.#p.splice(o>=0?o:this.#p.length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!this.#n)throw mt.fromCode(new Bo);return(await this.#n).getPrincipal()}async call(e,r,n){let o=r.callSync??!0,s=await(n??this.#n);if(!s)throw mt.fromCode(new Bo);let i=oe.from(e),a=r.effectiveCanisterId?oe.from(r.effectiveCanisterId):i;await this.#b(a);let c=s.getPrincipal(),d=D0(this.#u,this.#r),p={request_type:Cd.Call,canister_id:i,method_name:r.methodName,arg:r.arg,sender:c,ingress_expiry:d},l=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#s?{Authorization:"Basic "+btoa(this.#s)}:{}}},endpoint:Wn.Call,body:p}),u;r?.nonce?u=f(r.nonce):l.body.nonce?u=f(l.body.nonce):u=void 0,p.nonce=u;function f(y){return Object.assign(y,{__nonce__:void 0})}l=await s.transformRequest(l);let h=sc(l.body),m=this.#f(),b=Zn(p);try{let _=o?()=>(this.log.print(`fetching "/api/v3/canister/${a.toText()}/call" with request:`,l),this.#o(""+new URL(`/api/v3/canister/${a.toText()}/call`,this.host),{...this.#g,...l.request,body:h})):()=>(this.log.print(`fetching "/api/v2/canister/${a.toText()}/call" with request:`,l),this.#o(""+new URL(`/api/v2/canister/${a.toText()}/call`,this.host),{...this.#g,...l.request,body:h})),{responseBodyBytes:T,...N}=await this.#_({requestFn:_,backoff:m,tries:0}),I=T.byteLength>0?rr(T):null;return{requestId:b,response:{...N,body:I},requestDetails:p}}catch(y){let x;if(y instanceof Pr){if(y.hasCode(Ha))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(e,{...r,callSync:!1},n);if(y.hasCode(ms)&&!this.#c)return await this.syncTime(i),this.call(i,r,n);y.code.requestContext={requestId:b,senderPubKey:l.body.sender_pubkey,senderSignature:l.body.sender_sig,ingressExpiry:l.body.content.ingress_expiry},x=y}else x=st.fromCode(new qt(y));throw this.log.error(`Error while making call: ${x.message}`,x),x}}async#x(e){let{ecid:r,transformedRequest:n,body:o,requestId:s,backoff:i,tries:a}=e,c=a===0?0:i.next();if(this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with tries:`,{tries:a,backoff:i,delay:c}),c===null)throw st.fromCode(new hs(`Backoff strategy exhausted after ${a} attempts.`,s));c>0&&await new Promise(f=>setTimeout(f,c));let d;try{this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with request:`,n);let f=await this.#o(""+new URL(`/api/v2/canister/${r.toString()}/query`,this.host),{...this.#a,...n.request,body:o});if(f.status===P0)d={...rr(vi(await f.arrayBuffer())),httpDetails:{ok:f.ok,status:f.status,statusText:f.statusText,headers:Dd(f.headers)},requestId:s};else throw Me.fromCode(new ja(f.status,f.statusText,Dd(f.headers),await f.text()))}catch(f){if(a<this.#l)return this.log.warn(`Caught exception while attempting to make query:
|
|
119
|
-
${f}
|
|
120
|
-
Retrying query.`),await this.#x({...e,tries:a+1});throw f instanceof Pr?f:Ma.fromCode(new $a(f))}if(!this.#y)return d;let p=d.signatures?.[0]?.timestamp;if(!p)throw Me.fromCode(new yd("Timestamp not found in query response. This suggests a malformed or malicious response."));let l=Number(BigInt(p)/BigInt(J3));if(Date.now()+this.#r-l>this.#T){if(a<this.#l)return this.log.warn("Timestamp is older than the max ingress expiry. Retrying query.",{requestId:s,signatureTimestampMs:l}),await this.#x({...e,tries:a+1});throw Lt.fromCode(new dd(this.#u,s,a))}return d}async#_(e){let{requestFn:r,backoff:n,tries:o}=e,s=o===0?0:n.next();if(s===null)throw Me.fromCode(new hs(`Retry strategy exhausted after ${o} attempts.`));s>0&&await new Promise(p=>setTimeout(p,s));let i,a=new Uint8Array;try{i=await r(),i.status===P0&&(a=vi(await i.clone().arrayBuffer()))}catch(p){if(o<this.#l)return this.log.warn(`Caught exception while attempting to make request:
|
|
116
|
+
`)}return c.encodeValue(d)}));return Re(n,s,o,i,a)}function W8(t,e){let r=new $r(e);if(e.byteLength<Gd.length)throw new Error("Message length smaller than magic number");let n=Ys(r,Gd.length),s=new TextDecoder().decode(n);if(s!==Gd)throw new Error("Wrong magic number: "+JSON.stringify(s));function o(u){let p=[],h=Number(st(u));for(let y=0;y<h;y++){let x=Number(Qn(u));switch(x){case Be.Opt:case Be.Vector:{let _=Number(Qn(u));p.push([x,_]);break}case Be.Record:case Be.Variant:{let _=[],T=Number(st(u)),N;for(;T--;){let v=Number(st(u));if(v>=Math.pow(2,32))throw new Error("field id out of 32-bit range");if(typeof N=="number"&&N>=v)throw new Error("field id collision or not sorted");N=v;let R=Number(Qn(u));_.push([v,R])}p.push([x,_]);break}case Be.Func:{let _=[],T=Number(st(u));for(;T--;)_.push(Number(Qn(u)));let N=[],v=Number(st(u));for(;v--;)N.push(Number(Qn(u)));let R=[],A=Number(st(u));for(;A--;)switch(Number(st(u))){case 1:{R.push("query");break}case 2:{R.push("oneway");break}case 3:{R.push("composite_query");break}default:throw new Error("unknown annotation")}p.push([x,[_,N,R]]);break}case Be.Service:{let _=Number(st(u)),T=[];for(;_--;){let N=Number(st(u)),v=new TextDecoder().decode(Ys(u,N)),R=Qn(u);T.push([v,R])}p.push([x,T]);break}default:throw new Error("Illegal op_code: "+x)}}let m=[],b=Number(st(u));for(let y=0;y<b;y++)m.push(Number(Qn(u)));return[p,m]}let[i,a]=o(r);if(a.length<t.length)throw new Error("Wrong number of return values");let c=i.map(u=>Lx());function d(u){if(u<-24)throw new Error("future value not supported");if(u<0)switch(u){case-1:return bx;case-2:return _x;case-3:return wx;case-4:return xx;case-5:return Ix;case-6:return Sx;case-7:return Ax;case-8:return Bx;case-9:return Ox;case-10:return Nx;case-11:return vx;case-12:return Rx;case-13:return Ex;case-14:return Tx;case-15:return gx;case-16:return yx;case-17:return mx;case-24:return Cx;default:throw new Error("Illegal op_code: "+u)}if(u>=i.length)throw new Error("type index out of range");return c[u]}function f(u){switch(u[0]){case Be.Vector:{let p=d(u[1]);return Dx(p)}case Be.Opt:{let p=d(u[1]);return Fx(p)}case Be.Record:{let p={};for(let[b,y]of u[1]){let x=`_${b}_`;p[x]=d(y)}let h=Ux(p),m=h.tryAsTuple();return Array.isArray(m)?Px(...m):h}case Be.Variant:{let p={};for(let[h,m]of u[1]){let b=`_${h}_`;p[b]=d(m)}return Vx(p)}case Be.Func:{let[p,h,m]=u[1];return qx(p.map(b=>d(b)),h.map(b=>d(b)),m)}case Be.Service:{let p={},h=u[1];for(let[m,b]of h){let y=d(b);if(y instanceof Rr&&(y=y.getType()),!(y instanceof Vo))throw new Error("Illegal service definition: services can only contain functions");p[m]=y}return Mx(p)}default:throw new Error("Illegal op_code: "+u[0])}}i.forEach((u,p)=>{if(u[0]===Be.Func){let h=f(u);c[p].fill(h)}}),i.forEach((u,p)=>{if(u[0]!==Be.Func){let h=f(u);c[p].fill(h)}}),x0();let l=a.map(u=>d(u));try{let u=t.map((p,h)=>p.decodeValue(r,l[h]));for(let p=t.length;p<l.length;p++)l[p].decodeValue(r,l[p]);if(r.byteLength>0)throw new Error("decode: Left-over bytes");return u}finally{x0()}}var mx=new yc,yx=new On,X8=new zd,_x=new Yd,bx=new Fo,gx=new Wd,xx=new _c,wx=new bc,Ex=new gc(32),Tx=new gc(64),Ox=new ts(8),Nx=new ts(16),vx=new ts(32),Rx=new ts(64),Ix=new En(8),Sx=new En(16),Ax=new En(32),Bx=new En(64),Cx=new Jd;function Px(...t){return new Xd(t)}function Dx(t){return new ki(t)}function Fx(t){return new Ws(t)}function Ux(t){return new Uo(t)}function Vx(t){return new ji(t)}function Lx(){return new Rr}function qx(t,e,r=[]){return new Vo(t,e,r)}function Mx(t){return new Hi(t)}var Qd=class t{constructor(e=new Map){this.rels=e}copy(){let e=new Map;for(let[r,n]of this.rels.entries()){let s=new Map(n);e.set(r,s)}return new t(e)}known(e,r){return this.rels.get(e.name)?.get(r.name)}addNegative(e,r){this.addNames(e.name,r.name,!1)}add(e,r){this.addNames(e.name,r.name,!0)}display(){let e="";for(let[r,n]of this.rels)for(let[s,o]of n)e+=`${r} ${o?":<":"!<:"} ${s}
|
|
117
|
+
`;return e}addNames(e,r,n){let s=this.rels.get(e);if(s==null){let o=new Map;o.set(r,n),this.rels.set(e,o)}else s.set(r,n)}},Zd=new Qd;function x0(){Zd=new Qd}function J8(t,e){let r=new Set(t.annotations),n=new Set(e.annotations);if(r.size!==n.size)return!1;for(let s of r)if(!n.has(s))return!1;return!0}function _0(t){return t instanceof Ws||t instanceof Fo||t instanceof On}function E0(t,e){let r=Zd.copy(),n=es(r,t,e);return n?Zd.add(t,e):Zd.addNegative(t,e),n}function es(t,e,r){if(e.name===r.name)return!0;let n=t.known(e,r);if(n!==void 0)return n;if(t.add(e,r),r instanceof On||e instanceof yc||e instanceof bc&&r instanceof _c)return!0;if(e instanceof ki&&r instanceof ki)return es(t,e._type,r._type);if(r instanceof Ws)return!0;if(e instanceof Uo&&r instanceof Uo){let s=e.fieldsAsObject;for(let[o,i]of r._fields){let a=s[zt(o)];if(a){if(!es(t,a,i))return!1}else if(!_0(i))return!1}return!0}if(e instanceof Vo&&r instanceof Vo){if(!J8(e,r))return!1;for(let s=0;s<e.argTypes.length;s++){let o=e.argTypes[s];if(s<r.argTypes.length){if(!es(t,r.argTypes[s],o))return!1}else if(!_0(o))return!1}for(let s=0;s<r.retTypes.length;s++){let o=r.retTypes[s];if(s<e.retTypes.length){if(!es(t,e.retTypes[s],o))return!1}else if(!_0(o))return!1}return!0}if(e instanceof ji&&r instanceof ji){let s=r.alternativesAsObject;for(let[o,i]of e._fields){let a=s[zt(o)];if(!a||!es(t,i,a))return!1}return!0}if(e instanceof Hi&&r instanceof Hi){let s=e.fieldsAsObject();for(let[o,i]of r._fields){let a=s[o];if(!a||!es(t,a,i))return!1}return!0}return e instanceof Rr?es(t,e.getType(),r):r instanceof Rr?es(t,e,r.getType()):!1}function $i(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?$i(t.buffer):new Uint8Array(t)}function qo(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}function T0(t){if(typeof t=="string")return kx(t);if(typeof t=="number")return Lt(ke(t));if(t instanceof Uint8Array||ArrayBuffer.isView(t))return Lt($i(t));if(Array.isArray(t)){let e=t.map(T0);return Lt(de(...e))}else{if(t&&typeof t=="object"&&t._isPrincipal)return Lt(t.toUint8Array());if(typeof t=="object"&&t!==null&&typeof t.toHash=="function")return T0(t.toHash());if(typeof t=="object")return xc(t);if(typeof t=="bigint")return Lt(ke(t))}throw Ne.fromCode(new Ld(t))}var kx=t=>{let e=new TextEncoder().encode(t);return Lt(e)};function rs(t){return xc(t)}function xc(t){let n=Object.entries(t).filter(([,i])=>i!==void 0).map(([i,a])=>{let c=kx(i),d=T0(a);return[c,d]}).sort(([i],[a])=>p0(i,a)),s=de(...n.map(i=>de(...i)));return Lt(s)}var wc=new TextEncoder().encode(`
|
|
118
|
+
ic-request`),O0=new TextEncoder().encode("\vic-response"),N0=new TextEncoder().encode("ic-request-auth-delegation");var Nn=class{getPrincipal(){return this._principal||(this._principal=te.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:r,...n}=e,s=rs(r);return{...n,body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(de(wc,s))}}}},Ir=class{getPrincipal(){return te.anonymous()}async transformRequest(e){return{...e,body:{content:e.body}}}};var ns=class extends Error{constructor(e){super(e),this.name="DecodingError"}},Hx=55799,$x=Symbol("CBOR_STOP_CODE"),Zr=(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))(Zr||{}),dt=(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))(dt||{}),Q8=23,e3=255,t3=65535,r3=4294967295,n3=BigInt("0xffffffffffffffff"),Gr=(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))(Gr||{}),Ki=!1;function s3(t){return t==null}function Kx(t,e){let r=new Uint8Array(e);return r.set(t),r}var o3=new TextDecoder;function i3(t){return(t&224)>>5}function a3(t){return t&31}var Oc=new Uint8Array,Ec,zr=0;function Gx(t,e){Oc=t,zr=0;let r=Mo(e);return e?.(r)??r}function Mo(t){let[e,r]=el();switch(e){case dt.UnsignedInteger:return Gi(r);case dt.NegativeInteger:return l3(r);case dt.ByteString:return Zx(r);case dt.TextString:return R0(r);case dt.Array:return c3(r,t);case dt.Map:return d3(r,t);case dt.Tag:return f3(r,t);case dt.Simple:return u3(r)}throw new ns(`Unsupported major type: ${e}`)}function el(){let t=Oc.at(zr);if(s3(t))throw new ns("Provided CBOR data is empty");let e=i3(t),r=a3(t);return zr++,[e,r]}function c3(t,e){let r=Gi(t);if(r===1/0){let s=[],o=Mo(e);for(;o!==$x;)s.push(e?.(o)??o),o=Mo(e);return s}let n=new Array(r);for(let s=0;s<r;s++){let o=Mo(e);n[s]=e?.(o)??o}return n}function u3(t){switch(t){case Zr.False:return!1;case Zr.True:return!0;case Zr.Null:return null;case Zr.Undefined:return;case Zr.Break:return $x}throw new ns(`Unrecognized simple type: ${t.toString(2)}`)}function d3(t,e){let r=Gi(t),n={};if(r===1/0){let[s,o]=el();for(;s!==dt.Simple&&o!==Zr.Break;){let i=R0(o),a=Mo(e);n[i]=e?.(a,i)??a,[s,o]=el()}return n}for(let s=0;s<r;s++){let[o,i]=el();if(o!==dt.TextString)throw new ns("Map keys must be text strings");let a=R0(i),c=Mo(e);n[a]=e?.(c,a)??c}return n}function Gi(t){if(t<=Gr.Value)return t;switch(Ec=new DataView(Oc.buffer,Oc.byteOffset+zr),t){case Gr.OneByte:return zr++,Ec.getUint8(0);case Gr.TwoBytes:return zr+=2,Ec.getUint16(0,Ki);case Gr.FourBytes:return zr+=4,Ec.getUint32(0,Ki);case Gr.EightBytes:return zr+=8,Ec.getBigUint64(0,Ki);case Gr.Indefinite:return 1/0;default:throw new ns(`Unsupported integer info: ${t.toString(2)}`)}}function l3(t){let e=Gi(t);return typeof e=="number"?-1-e:-1n-e}function Zx(t){let e=Gi(t);if(e>Number.MAX_SAFE_INTEGER)throw new ns("Byte length is too large");let r=Number(e);return zr+=r,Oc.slice(zr-r,zr)}function R0(t){let e=Zx(t);return o3.decode(e)}function f3(t,e){let r=Gi(t);if(r===Hx)return Mo(e);throw new ns(`Unsupported tag: ${r}.`)}var Nc=class extends Error{constructor(e){super(e),this.name="SerializationError"}},p3=2*1024,h3=100,m3=new TextEncoder;function Tc(t){return t<<5}var gr=new Uint8Array(p3),Kr=new DataView(gr.buffer),ut=0,v0=[];function zx(t,e){ut=0;let r=e?.(t)??t;return T3(Hx,r,e),gr.slice(0,ut)}function I0(t,e){if(ut>gr.length-h3&&(gr=Kx(gr,gr.length*2),Kr=new DataView(gr.buffer)),t===!1||t===!0||t===null||t===void 0){b3(t);return}if(typeof t=="number"||typeof t=="bigint"){E3(t);return}if(typeof t=="string"){Xx(t);return}if(t instanceof Uint8Array){jx(t);return}if(t instanceof ArrayBuffer){jx(new Uint8Array(t));return}if(Array.isArray(t)){y3(t,e);return}if(typeof t=="object"){_3(t,e);return}throw new Nc(`Unsupported type: ${typeof t}`)}function y3(t,e){Zi(dt.Array,t.length),t.forEach((r,n)=>{I0(e?.(r,n.toString())??r,e)})}function _3(t,e){v0=Object.entries(t),Zi(dt.Map,v0.length),v0.forEach(([r,n])=>{Xx(r),I0(e?.(n,r)??n,e)})}function Zi(t,e){if(e<=Q8){Kr.setUint8(ut++,Tc(t)|Number(e));return}if(e<=e3){Kr.setUint8(ut++,Tc(t)|Gr.OneByte),Kr.setUint8(ut,Number(e)),ut+=1;return}if(e<=t3){Kr.setUint8(ut++,Tc(t)|Gr.TwoBytes),Kr.setUint16(ut,Number(e),Ki),ut+=2;return}if(e<=r3){Kr.setUint8(ut++,Tc(t)|Gr.FourBytes),Kr.setUint32(ut,Number(e),Ki),ut+=4;return}if(e<=n3){Kr.setUint8(ut++,Tc(t)|Gr.EightBytes),Kr.setBigUint64(ut,BigInt(e),Ki),ut+=8;return}throw new Nc(`Value too large to encode: ${e}`)}function b3(t){Zi(dt.Simple,g3(t))}function g3(t){if(t===!1)return Zr.False;if(t===!0)return Zr.True;if(t===null)return Zr.Null;if(t===void 0)return Zr.Undefined;throw new Nc(`Unrecognized simple value: ${t.toString()}`)}function Yx(t,e){Zi(t,e.length),ut>gr.length-e.length&&(gr=Kx(gr,gr.length+e.length),Kr=new DataView(gr.buffer)),gr.set(e,ut),ut+=e.length}function Wx(t,e){Zi(t,e)}function x3(t){Wx(dt.UnsignedInteger,t)}function w3(t){Wx(dt.NegativeInteger,typeof t=="bigint"?-1n-t:-1-t)}function E3(t){t>=0?x3(t):w3(t)}function Xx(t){Yx(dt.TextString,m3.encode(t))}function jx(t){Yx(dt.ByteString,t)}function T3(t,e,r){Zi(dt.Tag,t),I0(e,r)}function N3(t){return typeof t=="object"&&t!==null&&"toCborValue"in t}function vc(t){try{return zx(t,e=>te.isPrincipal(e)?e.toUint8Array():zi.isExpiry(e)?e.toBigInt():N3(e)?e.toCborValue():e)}catch(e){throw Ne.fromCode(new Pd(e,t))}}function ur(t){try{return Gx(t)}catch(e){throw Ne.fromCode(new Cd(e,t))}}var tl={encode:vc,decode:ur};var Rc=()=>{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 ss;(function(t){t.Query="read",t.ReadState="read_state",t.Call="call"})(ss||(ss={}));var rl;(function(t){t.Call="call"})(rl||(rl={}));var ko;(function(t){t.Query="query",t.ReadState="read_state"})(ko||(ko={}));function Ic(){let t=new ArrayBuffer(16),e=new DataView(t),r=Rc(),n=Rc(),s=Rc(),o=Rc();return e.setUint32(0,r),e.setUint32(4,n),e.setUint32(8,s),e.setUint32(12,o),Object.assign(new Uint8Array(t),{__nonce__:void 0})}var nl="__expiry__",A0=BigInt(1e3),v3=BigInt(1e6),Jx=BigInt(60),R3=BigInt(90)*A0;function Qx(t){return t/A0}function I3(t){return Qx(t)/Jx}var zi=class t{constructor(e){this.__expiry__=e,this._isExpiry=!0}static fromDeltaInMilliseconds(e,r=0){let n=BigInt(e),s=BigInt(Date.now())+n+BigInt(r),o;return n<R3?o=Qx(s):o=I3(s)*Jx,new t(o*A0*v3)}toBigInt(){return this.__expiry__}toHash(){return ke(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[nl]:this.toString()}}static fromJSON(e){let r=JSON.parse(e);if(r[nl])try{let n=BigInt(r[nl]);return new t(n)}catch(n){throw new Ne(new pc(`Not a valid BigInt: ${n}`))}throw new Ne(new pc(`The input does not contain the key ${nl}`))}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 B0(t=Ic){return async e=>{let r=e.request.headers;e.request.headers=r,e.endpoint===ss.Call&&(e.body.nonce=t())}}function sl(t){let e=[];return t.forEach((r,n)=>{e.push([n,r])}),e}var P0=BigInt(0),ol=BigInt(1);function jo(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}"`;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Xs(t,e,r=""){let n=bn(t),s=t?.length,o=e!==void 0;if(!n||o&&s!==e){let i=r&&`"${r}" `,a=o?` of length ${e}`:"",c=n?`length=${s}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return t}function ew(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?P0:BigInt("0x"+t)}function dr(t){return ew(fe(t))}function os(t){return Qe(t),ew(fe(Uint8Array.from(t).reverse()))}function lt(t,e){return bt(t.toString(16).padStart(e*2,"0"))}function D0(t,e){return lt(t,e).reverse()}function We(t,e,r){let n;if(typeof e=="string")try{n=bt(e)}catch(o){throw new Error(t+" must be hex string or Uint8Array, cause: "+o)}else if(bn(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let s=n.length;if(typeof r=="number"&&s!==r)throw new Error(t+" of length "+r+" expected, got "+s);return n}function tw(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function F0(t){return Uint8Array.from(t)}var C0=t=>typeof t=="bigint"&&P0<=t;function U0(t,e,r){return C0(t)&&C0(e)&&C0(r)&&e<=t&&t<r}function il(t,e,r,n){if(!U0(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function is(t){let e;for(e=0;t>P0;t>>=ol,e+=1);return e}function rw(t,e){return t>>BigInt(e)&ol}var Yr=t=>(ol<<BigInt(t))-ol;function nw(t){return typeof t=="function"&&Number.isSafeInteger(t.outputLen)}function as(t,e,r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(s,o,i){let a=t[s];if(i&&a===void 0)return;let c=typeof a;if(c!==o||a===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${c}`)}Object.entries(e).forEach(([s,o])=>n(s,o,!1)),Object.entries(r).forEach(([s,o])=>n(s,o,!0))}var Yi=()=>{throw new Error("not implemented")};function Js(t){let e=new WeakMap;return(r,...n)=>{let s=e.get(r);if(s!==void 0)return s;let o=t(r,...n);return e.set(r,o),o}}var Yt=BigInt(0),xt=BigInt(1),Ho=BigInt(2),ow=BigInt(3),iw=BigInt(4),aw=BigInt(5),S3=BigInt(7),cw=BigInt(8),A3=BigInt(9),uw=BigInt(16);function Ke(t,e){let r=t%e;return r>=Yt?r:e+r}function Wr(t,e,r){let n=t;for(;e-- >Yt;)n*=n,n%=r;return n}function sw(t,e){if(t===Yt)throw new Error("invert: expected non-zero number");if(e<=Yt)throw new Error("invert: expected positive modulus, got "+e);let r=Ke(t,e),n=e,s=Yt,o=xt,i=xt,a=Yt;for(;r!==Yt;){let d=n/r,f=n%r,l=s-i*d,u=o-a*d;n=r,r=f,s=i,o=a,i=l,a=u}if(n!==xt)throw new Error("invert: does not exist");return Ke(s,e)}function V0(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function dw(t,e){let r=(t.ORDER+xt)/iw,n=t.pow(e,r);return V0(t,n,e),n}function B3(t,e){let r=(t.ORDER-aw)/cw,n=t.mul(e,Ho),s=t.pow(n,r),o=t.mul(e,s),i=t.mul(t.mul(o,Ho),s),a=t.mul(o,t.sub(i,t.ONE));return V0(t,a,e),a}function C3(t){let e=Wt(t),r=lw(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+S3)/uw;return(a,c)=>{let d=a.pow(c,i),f=a.mul(d,n),l=a.mul(d,s),u=a.mul(d,o),p=a.eql(a.sqr(f),c),h=a.eql(a.sqr(l),c);d=a.cmov(d,f,p),f=a.cmov(u,l,h);let m=a.eql(a.sqr(f),c),b=a.cmov(d,f,m);return V0(a,b,c),b}}function lw(t){if(t<ow)throw new Error("sqrt is not defined for small field");let e=t-xt,r=0;for(;e%Ho===Yt;)e/=Ho,r++;let n=Ho,s=Wt(t);for(;Sc(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return dw;let o=s.pow(n,e),i=(e+xt)/Ho;return function(c,d){if(c.is0(d))return d;if(Sc(c,d)!==1)throw new Error("Cannot find square root");let f=r,l=c.mul(c.ONE,o),u=c.pow(d,e),p=c.pow(d,i);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let h=1,m=c.sqr(u);for(;!c.eql(m,c.ONE);)if(h++,m=c.sqr(m),h===f)throw new Error("Cannot find square root");let b=xt<<BigInt(f-h-1),y=c.pow(l,b);f=h,l=c.sqr(y),u=c.mul(u,l),p=c.mul(p,y)}return p}}function P3(t){return t%iw===ow?dw:t%cw===aw?B3:t%uw===A3?C3(t):lw(t)}var cs=(t,e)=>(Ke(t,e)&xt)===xt,D3=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function al(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=D3.reduce((n,s)=>(n[s]="function",n),e);return as(t,r),t}function Ac(t,e,r){if(r<Yt)throw new Error("invalid exponent, negatives unsupported");if(r===Yt)return t.ONE;if(r===xt)return e;let n=t.ONE,s=e;for(;r>Yt;)r&xt&&(n=t.mul(n,s)),s=t.sqr(s),r>>=xt;return n}function Sr(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),s=e.reduce((i,a,c)=>t.is0(a)?i:(n[c]=i,t.mul(i,a)),t.ONE),o=t.inv(s);return e.reduceRight((i,a,c)=>t.is0(a)?i:(n[c]=t.mul(i,n[c]),t.mul(i,a)),o),n}function Sc(t,e){let r=(t.ORDER-xt)/Ho,n=t.pow(e,r),s=t.eql(n,t.ONE),o=t.eql(n,t.ZERO),i=t.eql(n,t.neg(t.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function L0(t,e){e!==void 0&&i0(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Wt(t,e,r=!1,n={}){if(t<=Yt)throw new Error("invalid field: expected ORDER > 0, got "+t);let s,o,i=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=e;u.BITS&&(s=u.BITS),u.sqrt&&(o=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),a=u.allowedLengths}else typeof e=="number"&&(s=e),n.sqrt&&(o=n.sqrt);let{nBitLength:c,nByteLength:d}=L0(t,s);if(d>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,l=Object.freeze({ORDER:t,isLE:r,BITS:c,BYTES:d,MASK:Yr(c),ZERO:Yt,ONE:xt,allowedLengths:a,create:u=>Ke(u,t),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return Yt<=u&&u<t},is0:u=>u===Yt,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&xt)===xt,neg:u=>Ke(-u,t),eql:(u,p)=>u===p,sqr:u=>Ke(u*u,t),add:(u,p)=>Ke(u+p,t),sub:(u,p)=>Ke(u-p,t),mul:(u,p)=>Ke(u*p,t),pow:(u,p)=>Ac(l,u,p),div:(u,p)=>Ke(u*sw(p,t),t),sqrN:u=>u*u,addN:(u,p)=>u+p,subN:(u,p)=>u-p,mulN:(u,p)=>u*p,inv:u=>sw(u,t),sqrt:o||(u=>(f||(f=P3(t)),f(l,u))),toBytes:u=>r?D0(u,d):lt(u,d),fromBytes:(u,p=!0)=>{if(a){if(!a.includes(u.length)||u.length>d)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let m=new Uint8Array(d);m.set(u,r?0:m.length-u.length),u=m}if(u.length!==d)throw new Error("Field.fromBytes: expected "+d+" bytes, got "+u.length);let h=r?os(u):dr(u);if(i&&(h=Ke(h,t)),!p&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:u=>Sr(l,u),cmov:(u,p,h)=>h?p:u});return Object.freeze(l)}function fw(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function cl(t){let e=fw(t);return e+Math.ceil(e/2)}function q0(t,e,r=!1){let n=t.length,s=fw(e),o=cl(e);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?os(t):dr(t),a=Ke(i,e-xt)+xt;return r?D0(a,s):lt(a,s)}var Wi=BigInt(0),$o=BigInt(1);function Bc(t,e){let r=e.negate();return t?r:e}function Ar(t,e){let r=Sr(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function yw(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function M0(t,e){yw(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),s=2**t,o=Yr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function pw(t,e,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(t&s),c=t>>i;a>n&&(a-=o,c+=$o);let d=e*n,f=d+Math.abs(a)-1,l=a===0,u=a<0,p=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:u,isNegF:p,offsetF:d}}function U3(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function V3(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var k0=new WeakMap,_w=new WeakMap;function j0(t){return _w.get(t)||1}function hw(t){if(t!==Wi)throw new Error("invalid wNAF")}var Xi=class{constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let s=e;for(;r>Wi;)r&$o&&(n=n.add(s)),s=s.double(),r>>=$o;return n}precomputeWindow(e,r){let{windows:n,windowSize:s}=M0(r,this.bits),o=[],i=e,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let d=1;d<s;d++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=M0(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:d,isZero:f,isNeg:l,isNegF:u,offsetF:p}=pw(n,a,i);n=c,f?o=o.add(Bc(u,r[p])):s=s.add(Bc(l,r[d]))}return hw(n),{p:s,f:o}}wNAFUnsafe(e,r,n,s=this.ZERO){let o=M0(e,this.bits);for(let i=0;i<o.windows&&n!==Wi;i++){let{nextN:a,offset:c,isZero:d,isNeg:f}=pw(n,i,o);if(n=a,!d){let l=r[c];s=s.add(f?l.negate():l)}}return hw(n),s}getPrecomputes(e,r,n){let s=k0.get(r);return s||(s=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(s=n(s)),k0.set(r,s))),s}cached(e,r,n){let s=j0(e);return this.wNAF(s,this.getPrecomputes(s,e,n),r)}unsafe(e,r,n,s){let o=j0(e);return o===1?this._unsafeLadder(e,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,s)}createCache(e,r){yw(r,this.bits),_w.set(e,r),k0.delete(e)}hasCache(e){return j0(e)!==1}};function bw(t,e,r,n){let s=e,o=t.ZERO,i=t.ZERO;for(;r>Wi||n>Wi;)r&$o&&(o=o.add(s)),n&$o&&(i=i.add(s)),s=s.double(),r>>=$o,n>>=$o;return{p1:o,p2:i}}function Ji(t,e,r,n){U3(r,t),V3(n,e);let s=r.length,o=n.length;if(s!==o)throw new Error("arrays of points and scalars must have equal length");let i=t.ZERO,a=is(BigInt(s)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let d=Yr(c),f=new Array(Number(d)+1).fill(i),l=Math.floor((e.BITS-1)/c)*c,u=i;for(let p=l;p>=0;p-=c){f.fill(i);for(let m=0;m<o;m++){let b=n[m],y=Number(b>>BigInt(p)&d);f[y]=f[y].add(r[m])}let h=i;for(let m=f.length-1,b=i;m>0;m--)b=b.add(f[m]),h=h.add(b);if(u=u.add(h),p!==0)for(let m=0;m<c;m++)u=u.double()}return u}function mw(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return al(e),e}else return Wt(t,{isLE:r})}function ul(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let d=e[c];if(!(typeof d=="bigint"&&d>Wi))throw new Error(`CURVE.${c} must be positive bigint`)}let s=mw(e.p,r.Fp,n),o=mw(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}var L3=dr;function Qs(t,e){if(Cc(t),Cc(e),t<0||t>=1<<8*e)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 q3(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(!Number.isSafeInteger(t))throw new Error("number expected")}function gw(t){if(!bn(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or string");return typeof t=="string"?Ue(t):t}function M3(t,e,r,n){Qe(t),Cc(r),e=gw(e),e.length>255&&(e=n(de(Ue("H2C-OVERSIZE-DST-"),e)));let{outputLen:s,blockLen:o}=n,i=Math.ceil(r/s);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=de(e,Qs(e.length,1)),c=Qs(0,o),d=Qs(r,2),f=new Array(i),l=n(de(c,t,d,Qs(0,1),a));f[0]=n(de(l,Qs(1,1),a));for(let p=1;p<=i;p++){let h=[q3(l,f[p-1]),Qs(p+1,1),a];f[p]=n(de(...h))}return de(...f).slice(0,r)}function k3(t,e,r,n,s){if(Qe(t),Cc(r),e=gw(e),e.length>255){let o=Math.ceil(2*n/8);e=s.create({dkLen:o}).update(Ue("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return s.create({dkLen:r}).update(t).update(Qs(r,2)).update(e).update(Qs(e.length,1)).digest()}function H0(t,e,r){as(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:s,m:o,hash:i,expand:a,DST:c}=r;if(!nw(r.hash))throw new Error("expected valid hash");Qe(t),Cc(e);let d=n.toString(2).length,f=Math.ceil((d+s)/8),l=e*o*f,u;if(a==="xmd")u=M3(t,c,l,i);else if(a==="xof")u=k3(t,c,l,s,i);else if(a==="_internal_pass")u=t;else throw new Error('expand must be "xmd" or "xof"');let p=new Array(e);for(let h=0;h<e;h++){let m=new Array(o);for(let b=0;b<o;b++){let y=f*(b+h*o),x=u.subarray(y,y+f);m[b]=Ke(L3(x),n)}p[h]=m}return p}function $0(t,e){let r=e.map(n=>Array.from(n).reverse());return(n,s)=>{let[o,i,a,c]=r.map(l=>l.reduce((u,p)=>t.add(t.mul(u,n),p))),[d,f]=Sr(t,[i,c],!0);return n=t.mul(o,d),s=t.mul(s,t.mul(a,f)),{x:n,y:s}}}var j3=Ue("HashToScalar-");function K0(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function n(o){return t.fromAffine(e(o))}function s(o){let i=o.clearCofactor();return i.equals(t.ZERO)?t.ZERO:(i.assertValidity(),i)}return{defaults:r,hashToCurve(o,i){let a=Object.assign({},r,i),c=H0(o,2,a),d=n(c[0]),f=n(c[1]);return s(d.add(f))},encodeToCurve(o,i){let a=r.encodeDST?{DST:r.encodeDST}:{},c=Object.assign({},r,a,i),d=H0(o,1,c),f=n(d[0]);return s(f)},mapToCurve(o){if(!Array.isArray(o))throw new Error("expected array of bigints");for(let i of o)if(typeof i!="bigint")throw new Error("expected array of bigints");return s(n(o))},hashToScalar(o,i){let a=t.Fn.ORDER,c=Object.assign({},r,{p:a,m:1,DST:j3},i);return H0(o,1,c)[0][0]}}}var xw=(t,e)=>(t+(t>=0?e:-e)/us)/e;function H3(t,e,r){let[[n,s],[o,i]]=e,a=xw(i*t,r),c=xw(-s*t,r),d=t-a*n-c*o,f=-a*s-c*i,l=d<Ko,u=f<Ko;l&&(d=-d),u&&(f=-f);let p=Yr(Math.ceil(is(r)/2))+Xt;if(d<Ko||d>=p||f<Ko||f>=p)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:l,k1:d,k2neg:u,k2:f}}var Ko=BigInt(0),Xt=BigInt(1),us=BigInt(2),Qi=BigInt(3),G0=BigInt(4);function Pc(t,e){let{BYTES:r}=t,n;if(typeof e=="bigint")n=e;else{let s=We("private key",e);try{n=t.fromBytes(s)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`)}}if(!t.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function $3(t,e={}){let r=ul("weierstrass",t,e),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i,n:a}=o;as(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=Z3(n,s);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,g,w){let{x:O,y:P}=g.toAffine(),L=n.toBytes(O);if(jo(w,"isCompressed"),w){f();let I=!n.isOdd(P);return de(K3(I),L)}else return de(Uint8Array.of(4),L,n.toBytes(P))}function u(C){Xs(C,void 0,"Point");let{publicKey:g,publicKeyUncompressed:w}=d,O=C.length,P=C[0],L=C.subarray(1);if(O===g&&(P===2||P===3)){let I=n.fromBytes(L);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let B=m(I),F;try{F=n.sqrt(B)}catch(H){let z=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}f();let V=n.isOdd(F);return(P&1)===1!==V&&(F=n.neg(F)),{x:I,y:F}}else if(O===w&&P===4){let I=n.BYTES,B=n.fromBytes(L.subarray(0,I)),F=n.fromBytes(L.subarray(I,I*2));if(!b(B,F))throw new Error("bad point: is not on curve");return{x:B,y:F}}else throw new Error(`bad point: got length ${O}, expected compressed=${g} or uncompressed=${w}`)}let p=e.toBytes||l,h=e.fromBytes||u;function m(C){let g=n.sqr(C),w=n.mul(g,C);return n.add(n.add(w,n.mul(C,o.a)),o.b)}function b(C,g){let w=n.sqr(g),O=m(C);return n.eql(w,O)}if(!b(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(o.a,Qi),G0),x=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(y,x)))throw new Error("bad curve params: a or b");function _(C,g,w=!1){if(!n.isValid(g)||w&&n.is0(g))throw new Error(`bad point coordinate ${C}`);return g}function T(C){if(!(C instanceof E))throw new Error("ProjectivePoint expected")}function N(C){if(!c||!c.basises)throw new Error("no endo");return H3(C,c.basises,s.ORDER)}let v=Js((C,g)=>{let{X:w,Y:O,Z:P}=C;if(n.eql(P,n.ONE))return{x:w,y:O};let L=C.is0();g==null&&(g=L?n.ONE:n.inv(P));let I=n.mul(w,g),B=n.mul(O,g),F=n.mul(P,g);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:I,y:B}}),R=Js(C=>{if(C.is0()){if(e.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:w}=C.toAffine();if(!n.isValid(g)||!n.isValid(w))throw new Error("bad point: x or y not field elements");if(!b(g,w))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(C,g,w,O,P){return w=new E(n.mul(w.X,C),w.Y,w.Z),g=Bc(O,g),w=Bc(P,w),g.add(w)}class E{constructor(g,w,O){this.X=_("x",g),this.Y=_("y",w,!0),this.Z=_("z",O),Object.freeze(this)}static CURVE(){return o}static fromAffine(g){let{x:w,y:O}=g||{};if(!g||!n.isValid(w)||!n.isValid(O))throw new Error("invalid affine point");if(g instanceof E)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(O)?E.ZERO:new E(w,O,n.ONE)}static fromBytes(g){let w=E.fromAffine(h(Xs(g,void 0,"point")));return w.assertValidity(),w}static fromHex(g){return E.fromBytes(We("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,w=!0){return U.createCache(this,g),w||this.multiply(Qi),this}assertValidity(){R(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){T(g);let{X:w,Y:O,Z:P}=this,{X:L,Y:I,Z:B}=g,F=n.eql(n.mul(w,B),n.mul(L,P)),V=n.eql(n.mul(O,B),n.mul(I,P));return F&&V}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:w}=o,O=n.mul(w,Qi),{X:P,Y:L,Z:I}=this,B=n.ZERO,F=n.ZERO,V=n.ZERO,q=n.mul(P,P),H=n.mul(L,L),z=n.mul(I,I),G=n.mul(P,L);return G=n.add(G,G),V=n.mul(P,I),V=n.add(V,V),B=n.mul(g,V),F=n.mul(O,z),F=n.add(B,F),B=n.sub(H,F),F=n.add(H,F),F=n.mul(B,F),B=n.mul(G,B),V=n.mul(O,V),z=n.mul(g,z),G=n.sub(q,z),G=n.mul(g,G),G=n.add(G,V),V=n.add(q,q),q=n.add(V,q),q=n.add(q,z),q=n.mul(q,G),F=n.add(F,q),z=n.mul(L,I),z=n.add(z,z),q=n.mul(z,G),B=n.sub(B,q),V=n.mul(z,H),V=n.add(V,V),V=n.add(V,V),new E(B,F,V)}add(g){T(g);let{X:w,Y:O,Z:P}=this,{X:L,Y:I,Z:B}=g,F=n.ZERO,V=n.ZERO,q=n.ZERO,H=o.a,z=n.mul(o.b,Qi),G=n.mul(w,L),ae=n.mul(O,I),re=n.mul(P,B),Ce=n.add(w,O),se=n.add(L,I);Ce=n.mul(Ce,se),se=n.add(G,ae),Ce=n.sub(Ce,se),se=n.add(w,P);let me=n.add(L,B);return se=n.mul(se,me),me=n.add(G,re),se=n.sub(se,me),me=n.add(O,P),F=n.add(I,B),me=n.mul(me,F),F=n.add(ae,re),me=n.sub(me,F),q=n.mul(H,se),F=n.mul(z,re),q=n.add(F,q),F=n.sub(ae,q),q=n.add(ae,q),V=n.mul(F,q),ae=n.add(G,G),ae=n.add(ae,G),re=n.mul(H,re),se=n.mul(z,se),ae=n.add(ae,re),re=n.sub(G,re),re=n.mul(H,re),se=n.add(se,re),G=n.mul(ae,se),V=n.add(V,G),G=n.mul(me,se),F=n.mul(Ce,F),F=n.sub(F,G),G=n.mul(Ce,ae),q=n.mul(me,q),q=n.add(q,G),new E(F,V,q)}subtract(g){return this.add(g.negate())}is0(){return this.equals(E.ZERO)}multiply(g){let{endo:w}=e;if(!s.isValidNot0(g))throw new Error("invalid scalar: out of range");let O,P,L=I=>U.cached(this,I,B=>Ar(E,B));if(w){let{k1neg:I,k1:B,k2neg:F,k2:V}=N(g),{p:q,f:H}=L(B),{p:z,f:G}=L(V);P=H.add(G),O=A(w.beta,q,z,I,F)}else{let{p:I,f:B}=L(g);O=I,P=B}return Ar(E,[O,P])[0]}multiplyUnsafe(g){let{endo:w}=e,O=this;if(!s.isValid(g))throw new Error("invalid scalar: out of range");if(g===Ko||O.is0())return E.ZERO;if(g===Xt)return O;if(U.hasCache(this))return this.multiply(g);if(w){let{k1neg:P,k1:L,k2neg:I,k2:B}=N(g),{p1:F,p2:V}=bw(E,O,L,B);return A(w.beta,F,V,P,I)}else return U.unsafe(O,g)}multiplyAndAddUnsafe(g,w,O){let P=this.multiplyUnsafe(w).add(g.multiplyUnsafe(O));return P.is0()?void 0:P}toAffine(g){return v(this,g)}isTorsionFree(){let{isTorsionFree:g}=e;return i===Xt?!0:g?g(E,this):U.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=e;return i===Xt?this:g?g(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return jo(g,"isCompressed"),this.assertValidity(),p(E,this,g)}toHex(g=!0){return fe(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return Ar(E,g)}static msm(g,w){return Ji(E,s,g,w)}static fromPrivateKey(g){return E.BASE.multiply(Pc(s,g))}}E.BASE=new E(o.Gx,o.Gy,n.ONE),E.ZERO=new E(n.ZERO,n.ONE,n.ZERO),E.Fp=n,E.Fn=s;let S=s.BITS,U=new Xi(E,e.endo?Math.ceil(S/2):S);return E.BASE.precompute(8),E}function K3(t){return Uint8Array.of(t?2:3)}function G3(t,e){let r=t.ORDER,n=Ko;for(let h=r-Xt;h%us===Ko;h/=us)n+=Xt;let s=n,o=us<<s-Xt-Xt,i=o*us,a=(r-Xt)/i,c=(a-Xt)/us,d=i-Xt,f=o,l=t.pow(e,a),u=t.pow(e,(a+Xt)/us),p=(h,m)=>{let b=l,y=t.pow(m,d),x=t.sqr(y);x=t.mul(x,m);let _=t.mul(h,x);_=t.pow(_,c),_=t.mul(_,y),y=t.mul(_,m),x=t.mul(_,h);let T=t.mul(x,y);_=t.pow(T,f);let N=t.eql(_,t.ONE);y=t.mul(x,u),_=t.mul(T,b),x=t.cmov(y,x,N),T=t.cmov(_,T,N);for(let v=s;v>Xt;v--){let R=v-us;R=us<<R-Xt;let A=t.pow(T,R),E=t.eql(A,t.ONE);y=t.mul(x,b),b=t.mul(b,b),A=t.mul(T,b),x=t.cmov(y,x,E),T=t.cmov(A,T,E)}return{isValid:N,value:x}};if(t.ORDER%G0===Qi){let h=(t.ORDER-Qi)/G0,m=t.sqrt(t.neg(e));p=(b,y)=>{let x=t.sqr(y),_=t.mul(b,y);x=t.mul(x,_);let T=t.pow(x,h);T=t.mul(T,_);let N=t.mul(T,m),v=t.mul(t.sqr(T),y),R=t.eql(v,b),A=t.cmov(N,T,R);return{isValid:R,value:A}}}return p}function Z0(t,e){al(t);let{A:r,B:n,Z:s}=e;if(!t.isValid(r)||!t.isValid(n)||!t.isValid(s))throw new Error("mapToCurveSimpleSWU: invalid opts");let o=G3(t,s);if(!t.isOdd)throw new Error("Field does not have .isOdd()");return i=>{let a,c,d,f,l,u,p,h;a=t.sqr(i),a=t.mul(a,s),c=t.sqr(a),c=t.add(c,a),d=t.add(c,t.ONE),d=t.mul(d,n),f=t.cmov(s,t.neg(c),!t.eql(c,t.ZERO)),f=t.mul(f,r),c=t.sqr(d),u=t.sqr(f),l=t.mul(u,r),c=t.add(c,l),c=t.mul(c,d),u=t.mul(u,f),l=t.mul(u,n),c=t.add(c,l),p=t.mul(a,d);let{isValid:m,value:b}=o(c,u);h=t.mul(a,i),h=t.mul(h,b),p=t.cmov(p,d,m),h=t.cmov(h,b,m);let y=t.isOdd(i)===t.isOdd(h);h=t.cmov(t.neg(h),h,y);let x=Sr(t,[f],!0)[0];return p=t.mul(p,x),{x:p,y:h}}}function Z3(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function z0(t){let{CURVE:e,curveOpts:r}=z3(t),n=$3(e,r);return W3(t,n)}function z3(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,s=Wt(e.n,{BITS:t.nBitLength,allowedLengths:n,modFromBytes:t.wrapPrivateKey}),o={Fp:r,Fn:s,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:o}}function Y3(t,e,r){function n(s){let o=t.sqr(s),i=t.mul(o,s);return t.add(t.add(i,t.mul(s,e)),r)}return n}function W3(t,e){let{Fp:r,Fn:n}=e;function s(i){return U0(i,Xt,n.ORDER)}let o=Y3(r,t.a,t.b);return Object.assign({},{CURVE:t,Point:e,ProjectivePoint:e,normPrivateKeyToScalar:i=>Pc(n,i),weierstrassEquation:o,isWithinCurveOrder:s})}var X3=BigInt(0),dl=BigInt(1),ww=BigInt(2),ea=BigInt(3);function J3(t){let e=[];for(;t>dl;t>>=dl)(t&dl)===X3?e.unshift(0):(t&ea)===ea?(e.unshift(-1),t+=dl):e.unshift(1);return e}function Y0(t){if(!Array.isArray(t)||t.length===0)throw new Error("expected non-empty array")}function Q3(t,e,r,n){let{Fp2:s,Fp12:o}=t,{twistType:i,ateLoopSize:a,xNegative:c,postPrecompute:d}=n,f;if(i==="multiplicative")f=(_,T,N,v,R,A)=>o.mul014(v,_,s.mul(T,R),s.mul(N,A));else if(i==="divisive")f=(_,T,N,v,R,A)=>o.mul034(v,s.mul(N,A),s.mul(T,R),_);else throw new Error("bls: unknown twist type");let l=s.div(s.ONE,s.mul(s.ONE,ww));function u(_,T,N,v){let R=s.sqr(N),A=s.sqr(v),E=s.mulByB(s.mul(A,ea)),S=s.mul(E,ea),U=s.sub(s.sub(s.sqr(s.add(N,v)),A),R),C=s.sub(E,R),g=s.mul(s.sqr(T),ea),w=s.neg(U);return _.push([C,g,w]),T=s.mul(s.mul(s.mul(s.sub(R,S),T),N),l),N=s.sub(s.sqr(s.mul(s.add(R,S),l)),s.mul(s.sqr(E),ea)),v=s.mul(R,U),{Rx:T,Ry:N,Rz:v}}function p(_,T,N,v,R,A){let E=s.sub(N,s.mul(A,v)),S=s.sub(T,s.mul(R,v)),U=s.sub(s.mul(E,R),s.mul(S,A)),C=s.neg(E),g=S;_.push([U,C,g]);let w=s.sqr(S),O=s.mul(w,S),P=s.mul(w,T),L=s.add(s.sub(O,s.mul(P,ww)),s.mul(s.sqr(E),v));return T=s.mul(S,L),N=s.sub(s.mul(s.sub(P,L),E),s.mul(O,N)),v=s.mul(v,O),{Rx:T,Ry:N,Rz:v}}let h=J3(a),m=Js(_=>{let T=_,{x:N,y:v}=T.toAffine(),R=N,A=v,E=s.neg(v),S=R,U=A,C=s.ONE,g=[];for(let w of h){let O=[];({Rx:S,Ry:U,Rz:C}=u(O,S,U,C)),w&&({Rx:S,Ry:U,Rz:C}=p(O,S,U,C,R,w===-1?E:A)),g.push(O)}if(d){let w=g[g.length-1];d(S,U,C,R,A,p.bind(null,w))}return g});function b(_,T=!1){let N=o.ONE;if(_.length){let v=_[0][0].length;for(let R=0;R<v;R++){N=o.sqr(N);for(let[A,E,S]of _)for(let[U,C,g]of A[R])N=f(U,C,g,N,E,S)}}return c&&(N=o.conjugate(N)),T?o.finalExponentiate(N):N}function y(_,T=!0){let N=[];Ar(e,_.map(({g1:v})=>v)),Ar(r,_.map(({g2:v})=>v));for(let{g1:v,g2:R}of _){if(v.is0()||R.is0())throw new Error("pairing is not available for ZERO point");v.assertValidity(),R.assertValidity();let A=v.toAffine();N.push([m(R),A.x,A.y])}return b(N,T)}function x(_,T,N=!0){return y([{g1:_,g2:T}],N)}return{Fp12:o,millerLoopBatch:b,pairing:x,pairingBatch:y,calcPairingPrecomputes:m}}function Ew(t,e,r,n,s){let{Fp12:o,pairingBatch:i}=t;function a(l){return l instanceof e.Point?l:e.Point.fromHex(l)}function c(l){return l instanceof r.Point?l:r.Point.fromHex(l)}function d(l){if(!(l instanceof r.Point))throw new Error(`expected valid message hashed to ${s?"G1":"G2"} curve`);return l}let f=s?(l,u)=>({g1:u,g2:l}):(l,u)=>({g1:l,g2:u});return{getPublicKey(l){let u=Pc(e.Point.Fn,l);return e.Point.BASE.multiply(u)},sign(l,u,p){if(p!=null)throw new Error("sign() expects 2 arguments");let h=Pc(e.Point.Fn,u);return d(l).assertValidity(),l.multiply(h)},verify(l,u,p,h){if(h!=null)throw new Error("verify() expects 3 arguments");l=c(l),p=a(p);let m=p.negate(),b=e.Point.BASE,y=d(u),x=l,_=i([f(m,y),f(b,x)]);return o.eql(_,o.ONE)},verifyBatch(l,u,p){if(Y0(u),p.length!==u.length)throw new Error("amount of public keys and messages should be equal");let h=c(l),m=u,b=p.map(a),y=new Map;for(let T=0;T<b.length;T++){let N=b[T],v=m[T],R=y.get(v);R===void 0&&(R=[],y.set(v,R)),R.push(N)}let x=[],_=e.Point.BASE;try{for(let[T,N]of y){let v=N.reduce((R,A)=>R.add(A));x.push(f(v,T))}return x.push(f(_.negate(),h)),o.eql(i(x),o.ONE)}catch{return!1}},aggregatePublicKeys(l){Y0(l),l=l.map(p=>a(p));let u=l.reduce((p,h)=>p.add(h),e.Point.ZERO);return u.assertValidity(),u},aggregateSignatures(l){Y0(l),l=l.map(p=>c(p));let u=l.reduce((p,h)=>p.add(h),r.Point.ZERO);return u.assertValidity(),u},hash(l,u){Qe(l);let p=u?{DST:u}:void 0;return r.hashToCurve(l,p)},Signature:n}}function Tw(t){let{Fp:e,Fr:r,Fp2:n,Fp6:s,Fp12:o}=t.fields,i=z0(t.G1),a=Object.assign(i,K0(i.Point,t.G1.mapToCurve,{...t.htfDefaults,...t.G1.htfDefaults})),c=z0(t.G2),d=Object.assign(c,K0(c.Point,t.G2.mapToCurve,{...t.htfDefaults,...t.G2.htfDefaults})),f=Q3(t.fields,a.Point,d.Point,{...t.params,postPrecompute:t.postPrecompute}),{millerLoopBatch:l,pairing:u,pairingBatch:p,calcPairingPrecomputes:h}=f,m=Ew(f,a,d,t.G2.Signature,!1),b=Ew(f,d,a,t.G1.ShortSignature,!0),y=t.randomBytes||Di,x=()=>{let I=cl(r.ORDER);return q0(y(I),r.ORDER)},_={randomSecretKey:x,randomPrivateKey:x,calcPairingPrecomputes:h},{ShortSignature:T}=t.G1,{Signature:N}=t.G2;function v(I,B){return I instanceof a.Point?I:b.hash(We("point",I),B?.DST)}function R(I,B){return I instanceof d.Point?I:m.hash(We("point",I),B?.DST)}function A(I){return m.getPublicKey(I).toBytes(!0)}function E(I){return b.getPublicKey(I).toBytes(!0)}function S(I,B,F){let V=R(I,F),q=m.sign(V,B);return I instanceof d.Point?q:N.toBytes(q)}function U(I,B,F){let V=v(I,F),q=b.sign(V,B);return I instanceof a.Point?q:T.toBytes(q)}function C(I,B,F,V){let q=R(B,V);return m.verify(I,q,F)}function g(I,B,F,V){let q=v(B,V);return b.verify(I,q,F)}function w(I){let B=m.aggregatePublicKeys(I);return I[0]instanceof a.Point?B:B.toBytes(!0)}function O(I){let B=m.aggregateSignatures(I);return I[0]instanceof d.Point?B:N.toBytes(B)}function P(I){let B=b.aggregateSignatures(I);return I[0]instanceof a.Point?B:T.toBytes(B)}function L(I,B,F,V){let q=B.map(H=>R(H,V));return m.verifyBatch(I,q,F)}return a.Point.BASE.precompute(4),{longSignatures:m,shortSignatures:b,millerLoopBatch:l,pairing:u,pairingBatch:p,verifyBatch:L,fields:{Fr:r,Fp:e,Fp2:n,Fp6:s,Fp12:o},params:{ateLoopSize:t.params.ateLoopSize,twistType:t.params.twistType,r:t.params.r,G1b:t.G1.b,G2b:t.G2.b},utils:_,getPublicKey:A,getPublicKeyForShortSignatures:E,sign:S,signShortSignature:U,verify:C,verifyShortSignature:g,aggregatePublicKeys:w,aggregateSignatures:O,aggregateShortSignatures:P,G1:a,G2:d,Signature:N,ShortSignature:T}}var Ow=BigInt(0),ds=BigInt(1),Jt=BigInt(2),Nw=BigInt(3);function Q0(t,e,r,n,s=1,o){let i=BigInt(o===void 0?n:o),a=r**BigInt(n),c=[];for(let d=0;d<s;d++){let f=BigInt(d+1),l=[];for(let u=0,p=ds;u<n;u++){let h=(f*p-f)/i%a;l.push(t.pow(e,h)),p*=r}c.push(l)}return c}function Rw(t,e,r){let n=e.pow(r,(t.ORDER-ds)/Nw),s=e.pow(r,(t.ORDER-ds)/Jt);function o(u,p){let h=e.mul(e.frobeniusMap(u,1),n),m=e.mul(e.frobeniusMap(p,1),s);return[h,m]}let i=e.pow(r,(t.ORDER**Jt-ds)/Nw),a=e.pow(r,(t.ORDER**Jt-ds)/Jt);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(u,p){return[e.mul(u,i),e.neg(p)]}let d=u=>(p,h)=>{let m=h.toAffine(),b=u(m.x,m.y);return p.fromAffine({x:b[0],y:b[1]})},f=d(o),l=d(c);return{psi:o,psi2:c,G2psi:f,G2psi2:l,PSI_X:n,PSI_Y:s,PSI2_X:i,PSI2_Y:a}}var vw=(t,e)=>{if(e.length!==2)throw new Error("invalid tuple");let r=e.map(n=>t.create(n));return{c0:r[0],c1:r[1]}},W0=class{constructor(e,r={}){this.MASK=ds;let n=e.ORDER,s=n*n;this.Fp=e,this.ORDER=s,this.BITS=is(s),this.BYTES=Math.ceil(is(s)/8),this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.Fp_NONRESIDUE=e.create(r.NONRESIDUE||BigInt(-1)),this.Fp_div2=e.div(e.ONE,Jt),this.NONRESIDUE=vw(e,r.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=Q0(e,this.Fp_NONRESIDUE,e.ORDER,2)[0],this.mulByB=r.Fp2mulByB,Object.seal(this)}fromBigTuple(e){return vw(this.Fp,e)}create(e){return e}isValid({c0:e,c1:r}){function n(s,o){return typeof s=="bigint"&&Ow<=s&&s<o}return n(e,this.ORDER)&&n(r,this.ORDER)}is0({c0:e,c1:r}){return this.Fp.is0(e)&&this.Fp.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}eql({c0:e,c1:r},{c0:n,c1:s}){return this.Fp.eql(e,n)&&this.Fp.eql(r,s)}neg({c0:e,c1:r}){return{c0:this.Fp.neg(e),c1:this.Fp.neg(r)}}pow(e,r){return Ac(this,e,r)}invertBatch(e){return Sr(this,e)}add(e,r){let{c0:n,c1:s}=e,{c0:o,c1:i}=r;return{c0:this.Fp.add(n,o),c1:this.Fp.add(s,i)}}sub({c0:e,c1:r},{c0:n,c1:s}){return{c0:this.Fp.sub(e,n),c1:this.Fp.sub(r,s)}}mul({c0:e,c1:r},n){let{Fp:s}=this;if(typeof n=="bigint")return{c0:s.mul(e,n),c1:s.mul(r,n)};let{c0:o,c1:i}=n,a=s.mul(e,o),c=s.mul(r,i),d=s.sub(a,c),f=s.sub(s.mul(s.add(e,r),s.add(o,i)),s.add(a,c));return{c0:d,c1:f}}sqr({c0:e,c1:r}){let{Fp:n}=this,s=n.add(e,r),o=n.sub(e,r),i=n.add(e,e);return{c0:n.mul(s,o),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,s=n.inv(n.create(e*e+r*r));return{c0:n.mul(s,n.create(e)),c1:n.mul(s,n.create(-r))}}sqrt(e){let{Fp:r}=this,n=this,{c0:s,c1:o}=e;if(r.is0(o))return Sc(r,s)===1?n.create({c0:r.sqrt(s),c1:r.ZERO}):n.create({c0:r.ZERO,c1:r.sqrt(r.div(s,this.Fp_NONRESIDUE))});let i=r.sqrt(r.sub(r.sqr(s),r.mul(r.sqr(o),this.Fp_NONRESIDUE))),a=r.mul(r.add(i,s),this.Fp_div2);Sc(r,a)===-1&&(a=r.sub(a,i));let d=r.sqrt(a),f=n.create({c0:d,c1:r.div(r.mul(o,this.Fp_div2),d)});if(!n.eql(n.sqr(f),e))throw new Error("Cannot find square root");let l=f,u=n.neg(l),{re:p,im:h}=n.reim(l),{re:m,im:b}=n.reim(u);return h>b||h===b&&p>m?l:u}isOdd(e){let{re:r,im:n}=this.reim(e),s=r%Jt,o=r===Ow,i=n%Jt;return BigInt(s||o&&i)==ds}fromBytes(e){let{Fp:r}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{c0:r.fromBytes(e.subarray(0,r.BYTES)),c1:r.fromBytes(e.subarray(r.BYTES))}}toBytes({c0:e,c1:r}){return de(this.Fp.toBytes(e),this.Fp.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:s},o){return{c0:this.Fp.cmov(e,n,o),c1:this.Fp.cmov(r,s,o)}}reim({c0:e,c1:r}){return{re:e,im:r}}Fp4Square(e,r){let n=this,s=n.sqr(e),o=n.sqr(r);return{first:n.add(n.mulByNonresidue(o),s),second:n.sub(n.sub(n.sqr(n.add(e,r)),s),o)}}mulByNonresidue({c0:e,c1:r}){return this.mul({c0:e,c1:r},this.NONRESIDUE)}frobeniusMap({c0:e,c1:r},n){return{c0:e,c1:this.Fp.mul(r,this.FROBENIUS_COEFFICIENTS[n%2])}}},X0=class{constructor(e){this.MASK=ds,this.Fp2=e,this.ORDER=e.ORDER,this.BITS=3*e.BITS,this.BYTES=3*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO,c2:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO,c2:e.ZERO};let{Fp:r}=e,n=Q0(e,e.NONRESIDUE,r.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=n[0],this.FROBENIUS_COEFFICIENTS_2=n[1],Object.seal(this)}add({c0:e,c1:r,c2:n},{c0:s,c1:o,c2:i}){let{Fp2:a}=this;return{c0:a.add(e,s),c1:a.add(r,o),c2:a.add(n,i)}}sub({c0:e,c1:r,c2:n},{c0:s,c1:o,c2:i}){let{Fp2:a}=this;return{c0:a.sub(e,s),c1:a.sub(r,o),c2:a.sub(n,i)}}mul({c0:e,c1:r,c2:n},s){let{Fp2:o}=this;if(typeof s=="bigint")return{c0:o.mul(e,s),c1:o.mul(r,s),c2:o.mul(n,s)};let{c0:i,c1:a,c2:c}=s,d=o.mul(e,i),f=o.mul(r,a),l=o.mul(n,c);return{c0:o.add(d,o.mulByNonresidue(o.sub(o.mul(o.add(r,n),o.add(a,c)),o.add(f,l)))),c1:o.add(o.sub(o.mul(o.add(e,r),o.add(i,a)),o.add(d,f)),o.mulByNonresidue(l)),c2:o.sub(o.add(f,o.mul(o.add(e,n),o.add(i,c))),o.add(d,l))}}sqr({c0:e,c1:r,c2:n}){let{Fp2:s}=this,o=s.sqr(e),i=s.mul(s.mul(e,r),Jt),a=s.mul(s.mul(r,n),Jt),c=s.sqr(n);return{c0:s.add(s.mulByNonresidue(a),o),c1:s.add(s.mulByNonresidue(c),i),c2:s.sub(s.sub(s.add(s.add(i,s.sqr(s.add(s.sub(e,r),n))),a),o),c)}}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){return e}isValid({c0:e,c1:r,c2:n}){let{Fp2:s}=this;return s.isValid(e)&&s.isValid(r)&&s.isValid(n)}is0({c0:e,c1:r,c2:n}){let{Fp2:s}=this;return s.is0(e)&&s.is0(r)&&s.is0(n)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r,c2:n}){let{Fp2:s}=this;return{c0:s.neg(e),c1:s.neg(r),c2:s.neg(n)}}eql({c0:e,c1:r,c2:n},{c0:s,c1:o,c2:i}){let{Fp2:a}=this;return a.eql(e,s)&&a.eql(r,o)&&a.eql(n,i)}sqrt(e){return Yi()}div(e,r){let{Fp2:n}=this,{Fp:s}=n;return this.mul(e,typeof r=="bigint"?s.inv(s.create(r)):this.inv(r))}pow(e,r){return Ac(this,e,r)}invertBatch(e){return Sr(this,e)}inv({c0:e,c1:r,c2:n}){let{Fp2:s}=this,o=s.sub(s.sqr(e),s.mulByNonresidue(s.mul(n,r))),i=s.sub(s.mulByNonresidue(s.sqr(n)),s.mul(e,r)),a=s.sub(s.sqr(r),s.mul(e,n)),c=s.inv(s.add(s.mulByNonresidue(s.add(s.mul(n,i),s.mul(r,a))),s.mul(e,o)));return{c0:s.mul(c,o),c1:s.mul(c,i),c2:s.mul(c,a)}}fromBytes(e){let{Fp2:r}=this;if(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);let n=r.BYTES;return{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:s}=this;return de(s.toBytes(e),s.toBytes(r),s.toBytes(n))}cmov({c0:e,c1:r,c2:n},{c0:s,c1:o,c2:i},a){let{Fp2:c}=this;return{c0:c.cmov(e,s,a),c1:c.cmov(r,o,a),c2:c.cmov(n,i,a)}}fromBigSix(e){let{Fp2:r}=this;if(!Array.isArray(e)||e.length!==6)throw new Error("invalid Fp6 usage");return{c0:r.fromBigTuple(e.slice(0,2)),c1:r.fromBigTuple(e.slice(2,4)),c2:r.fromBigTuple(e.slice(4,6))}}frobeniusMap({c0:e,c1:r,c2:n},s){let{Fp2:o}=this;return{c0:o.frobeniusMap(e,s),c1:o.mul(o.frobeniusMap(r,s),this.FROBENIUS_COEFFICIENTS_1[s%6]),c2:o.mul(o.frobeniusMap(n,s),this.FROBENIUS_COEFFICIENTS_2[s%6])}}mulByFp2({c0:e,c1:r,c2:n},s){let{Fp2:o}=this;return{c0:o.mul(e,s),c1:o.mul(r,s),c2:o.mul(n,s)}}mulByNonresidue({c0:e,c1:r,c2:n}){let{Fp2:s}=this;return{c0:s.mulByNonresidue(n),c1:e,c2:r}}mul1({c0:e,c1:r,c2:n},s){let{Fp2:o}=this;return{c0:o.mulByNonresidue(o.mul(n,s)),c1:o.mul(e,s),c2:o.mul(r,s)}}mul01({c0:e,c1:r,c2:n},s,o){let{Fp2:i}=this,a=i.mul(e,s),c=i.mul(r,o);return{c0:i.add(i.mulByNonresidue(i.sub(i.mul(i.add(r,n),o),c)),a),c1:i.sub(i.sub(i.mul(i.add(s,o),i.add(e,r)),a),c),c2:i.add(i.sub(i.mul(i.add(e,n),s),a),c)}}},J0=class{constructor(e,r){this.MASK=ds;let{Fp2:n}=e,{Fp:s}=n;this.Fp6=e,this.ORDER=n.ORDER,this.BITS=2*e.BITS,this.BYTES=2*e.BYTES,this.isLE=e.isLE,this.ZERO={c0:e.ZERO,c1:e.ZERO},this.ONE={c0:e.ONE,c1:e.ZERO},this.FROBENIUS_COEFFICIENTS=Q0(n,n.NONRESIDUE,s.ORDER,12,1,6)[0],this.X_LEN=r.X_LEN,this.finalExponentiate=r.Fp12finalExponentiate}create(e){return e}isValid({c0:e,c1:r}){let{Fp6:n}=this;return n.isValid(e)&&n.isValid(r)}is0({c0:e,c1:r}){let{Fp6:n}=this;return n.is0(e)&&n.is0(r)}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}neg({c0:e,c1:r}){let{Fp6:n}=this;return{c0:n.neg(e),c1:n.neg(r)}}eql({c0:e,c1:r},{c0:n,c1:s}){let{Fp6:o}=this;return o.eql(e,n)&&o.eql(r,s)}sqrt(e){Yi()}inv({c0:e,c1:r}){let{Fp6:n}=this,s=n.inv(n.sub(n.sqr(e),n.mulByNonresidue(n.sqr(r))));return{c0:n.mul(e,s),c1:n.neg(n.mul(r,s))}}div(e,r){let{Fp6:n}=this,{Fp2:s}=n,{Fp:o}=s;return this.mul(e,typeof r=="bigint"?o.inv(o.create(r)):this.inv(r))}pow(e,r){return Ac(this,e,r)}invertBatch(e){return Sr(this,e)}add({c0:e,c1:r},{c0:n,c1:s}){let{Fp6:o}=this;return{c0:o.add(e,n),c1:o.add(r,s)}}sub({c0:e,c1:r},{c0:n,c1:s}){let{Fp6:o}=this;return{c0:o.sub(e,n),c1:o.sub(r,s)}}mul({c0:e,c1:r},n){let{Fp6:s}=this;if(typeof n=="bigint")return{c0:s.mul(e,n),c1:s.mul(r,n)};let{c0:o,c1:i}=n,a=s.mul(e,o),c=s.mul(r,i);return{c0:s.add(a,s.mulByNonresidue(c)),c1:s.sub(s.mul(s.add(e,r),s.add(o,i)),s.add(a,c))}}sqr({c0:e,c1:r}){let{Fp6:n}=this,s=n.mul(e,r);return{c0:n.sub(n.sub(n.mul(n.add(n.mulByNonresidue(r),e),n.add(e,r)),s),n.mulByNonresidue(s)),c1:n.add(s,s)}}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(e.length!==this.BYTES)throw new Error("fromBytes invalid length="+e.length);return{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 de(n.toBytes(e),n.toBytes(r))}cmov({c0:e,c1:r},{c0:n,c1:s},o){let{Fp6:i}=this;return{c0:i.cmov(e,n,o),c1:i.cmov(r,s,o)}}fromBigTwelve(e){let{Fp6:r}=this;return{c0:r.fromBigSix(e.slice(0,6)),c1:r.fromBigSix(e.slice(6,12))}}frobeniusMap(e,r){let{Fp6:n}=this,{Fp2:s}=n,{c0:o,c1:i,c2:a}=n.frobeniusMap(e.c1,r),c=this.FROBENIUS_COEFFICIENTS[r%12];return{c0:n.frobeniusMap(e.c0,r),c1:n.create({c0:s.mul(o,c),c1:s.mul(i,c),c2:s.mul(a,c)})}}mulByFp2({c0:e,c1:r},n){let{Fp6:s}=this;return{c0:s.mulByFp2(e,n),c1:s.mulByFp2(r,n)}}conjugate({c0:e,c1:r}){return{c0:e,c1:this.Fp6.neg(r)}}mul014({c0:e,c1:r},n,s,o){let{Fp6:i}=this,{Fp2:a}=i,c=i.mul01(e,n,s),d=i.mul1(r,o);return{c0:i.add(i.mulByNonresidue(d),c),c1:i.sub(i.sub(i.mul01(i.add(r,e),n,a.add(s,o)),c),d)}}mul034({c0:e,c1:r},n,s,o){let{Fp6:i}=this,{Fp2:a}=i,c=i.create({c0:a.mul(e.c0,n),c1:a.mul(e.c1,n),c2:a.mul(e.c2,n)}),d=i.mul01(r,s,o),f=i.mul01(i.add(e,r),a.add(n,s),o);return{c0:i.add(i.mulByNonresidue(d),c),c1:i.sub(f,i.add(c,d))}}_cyclotomicSquare({c0:e,c1:r}){let{Fp6:n}=this,{Fp2:s}=n,{c0:o,c1:i,c2:a}=e,{c0:c,c1:d,c2:f}=r,{first:l,second:u}=s.Fp4Square(o,d),{first:p,second:h}=s.Fp4Square(c,a),{first:m,second:b}=s.Fp4Square(i,f),y=s.mulByNonresidue(b);return{c0:n.create({c0:s.add(s.mul(s.sub(l,o),Jt),l),c1:s.add(s.mul(s.sub(p,i),Jt),p),c2:s.add(s.mul(s.sub(m,a),Jt),m)}),c1:n.create({c0:s.add(s.mul(s.add(y,c),Jt),y),c1:s.add(s.mul(s.add(u,d),Jt),u),c2:s.add(s.mul(s.add(h,f),Jt),h)})}}_cyclotomicExp(e,r){let n=this.ONE;for(let s=this.X_LEN-1;s>=0;s--)n=this._cyclotomicSquare(n),rw(r,s)&&(n=this.mul(n,e));return n}};function Iw(t){let e=Wt(t.ORDER),r=new W0(e,t),n=new X0(r),s=new J0(n,t);return{Fp:e,Fp2:r,Fp6:n,Fp12:s}}var qt=BigInt(0),ll=BigInt(1),Br=BigInt(2),fl=BigInt(3),Dc=BigInt(4),eo=BigInt("0xd201000000010000"),eN=is(eo),Go={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:qt,b:Dc,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")},tN=Wt(Go.n,{modFromBytes:!0,isLE:!0}),{Fp:J,Fp2:we,Fp6:rN,Fp12:Ie}=Iw({ORDER:Go.p,X_LEN:eN,FP2_NONRESIDUE:[ll,ll],Fp2mulByB:({c0:t,c1:e})=>{let r=J.mul(t,Dc),n=J.mul(e,Dc);return{c0:J.sub(r,n),c1:J.add(r,n)}},Fp12finalExponentiate:t=>{let e=eo,r=Ie.div(Ie.frobeniusMap(t,6),t),n=Ie.mul(Ie.frobeniusMap(r,2),r),s=Ie.conjugate(Ie._cyclotomicExp(n,e)),o=Ie.mul(Ie.conjugate(Ie._cyclotomicSquare(n)),s),i=Ie.conjugate(Ie._cyclotomicExp(o,e)),a=Ie.conjugate(Ie._cyclotomicExp(i,e)),c=Ie.mul(Ie.conjugate(Ie._cyclotomicExp(a,e)),Ie._cyclotomicSquare(s)),d=Ie.conjugate(Ie._cyclotomicExp(c,e)),f=Ie.frobeniusMap(Ie.mul(s,a),2),l=Ie.frobeniusMap(Ie.mul(i,n),3),u=Ie.frobeniusMap(Ie.mul(c,Ie.conjugate(n)),1),p=Ie.mul(Ie.mul(d,Ie.conjugate(o)),n);return Ie.mul(Ie.mul(Ie.mul(f,l),u),p)}}),{G2psi:Sw,G2psi2:nN}=Rw(J,we,we.div(we.ONE,we.NONRESIDUE)),em=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:J.ORDER,m:2,k:128,expand:"xmd",hash:Lt}),nm={p:we.ORDER,n:Go.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:we.ZERO,b:we.fromBigTuple([Dc,Dc]),Gx:we.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:we.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},pl=Fc(J.toBytes(qt),{infinity:!0,compressed:!0});function hl(t){t=t.slice();let e=t[0]&224,r=!!(e>>7&1),n=!!(e>>6&1),s=!!(e>>5&1);return t[0]&=31,{compressed:r,infinity:n,sort:s,value:t}}function Fc(t,e){if(t[0]&224)throw new Error("setMask: non-empty mask");return e.compressed&&(t[0]|=128),e.infinity&&(t[0]|=64),e.sort&&(t[0]|=32),t}function sN(t,e,r){let{BYTES:n,ORDER:s}=J,o=e.is0(),{x:i,y:a}=e.toAffine();if(r){if(o)return pl.slice();let c=!!(a*Br/s);return Fc(lt(i,n),{compressed:!0,sort:c})}else return o?de(Uint8Array.of(64),new Uint8Array(2*n-1)):de(lt(i,n),lt(a,n))}function tm(t){t.assertValidity();let{BYTES:e,ORDER:r}=J,{x:n,y:s}=t.toAffine();if(t.is0())return pl.slice();let o=!!(s*Br/r);return Fc(lt(n,e),{compressed:!0,sort:o})}function oN(t){let{compressed:e,infinity:r,sort:n,value:s}=hl(t),{BYTES:o,ORDER:i}=J;if(s.length===48&&e){let a=dr(s),c=J.create(a&Yr(J.BITS));if(r){if(c!==qt)throw new Error("invalid G1 point: non-empty, at infinity, with compression");return{x:qt,y:qt}}let d=J.add(J.pow(c,fl),J.create(Go.b)),f=J.sqrt(d);if(!f)throw new Error("invalid G1 point: compressed point");return f*Br/i!==BigInt(n)&&(f=J.neg(f)),{x:J.create(c),y:J.create(f)}}else if(s.length===96&&!e){let a=dr(s.subarray(0,o)),c=dr(s.subarray(o));if(r){if(a!==qt||c!==qt)throw new Error("G1: non-empty point at infinity");return Uc.G1.Point.ZERO.toAffine()}return{x:J.create(a),y:J.create(c)}}else throw new Error("invalid G1 point: expected 48/96 bytes")}function Aw(t){let{infinity:e,sort:r,value:n}=hl(We("signatureHex",t,48)),s=J.ORDER,o=Uc.G1.Point,i=dr(n);if(e)return o.ZERO;let a=J.create(i&Yr(J.BITS)),c=J.add(J.pow(a,fl),J.create(Go.b)),d=J.sqrt(c);if(!d)throw new Error("invalid G1 point: compressed");let f=BigInt(r);d*Br/s!==f&&(d=J.neg(d));let l=o.fromAffine({x:a,y:d});return l.assertValidity(),l}function iN(t,e,r){let{BYTES:n,ORDER:s}=J,o=e.is0(),{x:i,y:a}=e.toAffine();if(r){if(o)return de(pl,lt(qt,n));let c=!!(a.c1===qt?a.c0*Br/s:a.c1*Br/s);return de(Fc(lt(i.c1,n),{compressed:!0,sort:c}),lt(i.c0,n))}else{if(o)return de(Uint8Array.of(64),new Uint8Array(4*n-1));let{re:c,im:d}=we.reim(i),{re:f,im:l}=we.reim(a);return de(lt(d,n),lt(c,n),lt(l,n),lt(f,n))}}function rm(t){t.assertValidity();let{BYTES:e}=J;if(t.is0())return de(pl,lt(qt,e));let{x:r,y:n}=t.toAffine(),{re:s,im:o}=we.reim(r),{re:i,im:a}=we.reim(n),d=!!((a>qt?a*Br:i*Br)/J.ORDER&ll),f=s;return de(Fc(lt(o,e),{sort:d,compressed:!0}),lt(f,e))}function aN(t){let{BYTES:e,ORDER:r}=J,{compressed:n,infinity:s,sort:o,value:i}=hl(t);if(!n&&!s&&o||!n&&s&&o||o&&s&&n)throw new Error("invalid encoding flag: "+(t[0]&224));let a=(c,d,f)=>dr(c.slice(d,f));if(i.length===96&&n){if(s){if(i.reduce((h,m)=>h!==0?m+1:m,0)>0)throw new Error("invalid G2 point: compressed");return{x:we.ZERO,y:we.ZERO}}let c=a(i,0,e),d=a(i,e,2*e),f=we.create({c0:J.create(d),c1:J.create(c)}),l=we.add(we.pow(f,fl),nm.b),u=we.sqrt(l),p=u.c1===qt?u.c0*Br/r:u.c1*Br/r?ll:qt;return u=o&&p>0?u:we.neg(u),{x:f,y:u}}else if(i.length===192&&!n){if(s){if(i.reduce((u,p)=>u!==0?p+1:p,0)>0)throw new Error("invalid G2 point: uncompressed");return{x:we.ZERO,y:we.ZERO}}let c=a(i,0*e,1*e),d=a(i,1*e,2*e),f=a(i,2*e,3*e),l=a(i,3*e,4*e);return{x:we.fromBigTuple([d,c]),y:we.fromBigTuple([l,f])}}else throw new Error("invalid G2 point: expected 96/192 bytes")}function Bw(t){let{ORDER:e}=J,{infinity:r,sort:n,value:s}=hl(We("signatureHex",t)),o=Uc.G2.Point,i=s.length/2;if(i!==48&&i!==96)throw new Error("invalid compressed signature length, expected 96/192 bytes");let a=dr(s.slice(0,i)),c=dr(s.slice(i));if(r)return o.ZERO;let d=J.create(a&Yr(J.BITS)),f=J.create(c),l=we.create({c0:f,c1:d}),u=we.add(we.pow(l,fl),nm.b),p=we.sqrt(u);if(!p)throw new Error("Failed to find a square root");let{re:h,im:m}=we.reim(p),b=BigInt(n),y=m>qt&&m*Br/e!==b,x=m===qt&&h*Br/e!==b;(y||x)&&(p=we.neg(p));let _=o.fromAffine({x:l,y:p});return _.assertValidity(),_}var Uc=Tw({fields:{Fp:J,Fp2:we,Fp6:rN,Fp12:Ie,Fr:tN},G1:{...Go,Fp:J,htfDefaults:{...em,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(t,e)=>{let r=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),n=new t(J.mul(e.X,r),e.Y,e.Z);return e.multiplyUnsafe(eo).negate().multiplyUnsafe(eo).equals(n)},clearCofactor:(t,e)=>e.multiplyUnsafe(eo).add(e),mapToCurve:fN,fromBytes:oN,toBytes:sN,ShortSignature:{fromBytes(t){return Qe(t),Aw(t)},fromHex(t){return Aw(t)},toBytes(t){return tm(t)},toRawBytes(t){return tm(t)},toHex(t){return fe(tm(t))}}},G2:{...nm,Fp:we,hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...em},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:pN,isTorsionFree:(t,e)=>e.multiplyUnsafe(eo).negate().equals(Sw(t,e)),clearCofactor:(t,e)=>{let r=eo,n=e.multiplyUnsafe(r).negate(),s=Sw(t,e),o=e.double();return o=nN(t,o),o=o.subtract(s),s=n.add(s),s=s.multiplyUnsafe(r).negate(),o=o.add(s),o=o.subtract(n),o.subtract(e)},fromBytes:aN,toBytes:iN,Signature:{fromBytes(t){return Qe(t),Bw(t)},fromHex(t){return Bw(t)},toBytes(t){return rm(t)},toRawBytes(t){return rm(t)},toHex(t){return fe(rm(t))}}},params:{ateLoopSize:eo,r:Go.n,xNegative:!0,twistType:"multiplicative"},htfDefaults:em,hash:Lt}),cN=$0(we,[[["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=>we.fromBigTuple(e.map(BigInt))))),uN=$0(J,[["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)))),dN=Z0(J,{A:J.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:J.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:J.create(BigInt(11))}),lN=Z0(we,{A:we.create({c0:J.create(qt),c1:J.create(BigInt(240))}),B:we.create({c0:J.create(BigInt(1012)),c1:J.create(BigInt(1012))}),Z:we.create({c0:J.create(BigInt(-2)),c1:J.create(BigInt(-1))})});function fN(t){let{x:e,y:r}=dN(J.create(t[0]));return uN(e,r)}function pN(t){let{x:e,y:r}=lN(we.fromBigTuple(t));return cN(e,r)}function Cw(t,e,r){let n=typeof t=="string"?t:fe(t),s=typeof e=="string"?e:fe(e),o=typeof r=="string"?r:fe(r);return Uc.verifyShortSignature(s,o,n)}var mN=BigInt(1e6),sm=t=>st(new $r(t)),ta=t=>{let r=sm(t)/mN;return new Date(Number(r))};var Pw=60*1e3,yN=60,_N=24,bN=_N*yN,gN=5,xN=5,wN=30*bN,Rt;(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"})(Rt||(Rt={}));function EN(t,e){for(let r=0;r<t.length;r++)if(t[r]>e[r])return!0;return!1}var to=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.canisterId,e.blsVerify??Cw,e.maxAgeInMinutes,e.disableTimeVerification,e.agent)}constructor(e,r,n,s,o=gN,i=!1,a){this._rootKey=r,this._canisterId=n,this._blsVerify=s,this._maxAgeInMinutes=o,this.#e=i,this.cert=ur(e),a&&"getTimeDiffMsecs"in a&&"hasSyncedTime"in a&&"syncTime"in a&&(this.#t=a)}lookup_path(e){return zo(e,this.cert.tree)}lookup_subtree(e){return _l(e,this.cert.tree)}async verify(){let e=await ml(this.cert.tree),r=await this._checkDelegationAndGetKey(this.cert.delegation),n=this.cert.signature,s=ON(r),o=de(Lc("ic-state-root"),e),i=Mt(this.lookup_path(["time"]));if(!i)throw Me.fromCode(new $s("Certificate does not contain a time"));if(!this.#e){let a=this.#t?.getTimeDiffMsecs()??0,c=this._maxAgeInMinutes*Pw,d=new Date,f=d.getTime()+a,l=f-c,u=f+xN*Pw,p=ta(i),h=p.getTime()<l,m=p.getTime()>u;if((h||m)&&this.#t&&!this.#t.hasSyncedTime())return await this.#t.syncTime(this._canisterId),await this.verify();if(h)throw Gt.fromCode(new Co(this._maxAgeInMinutes,p,d,a,"past"));if(m)throw this.#t?.hasSyncedTime()?ct.fromCode(new Zt("System time has been synced with the IC network, but certificate is still too far in the future.")):Gt.fromCode(new Co(5,p,d,a,"future"))}try{if(!await this._blsVerify(s,n,o))throw Gt.fromCode(new $s("Invalid signature"))}catch(a){throw Gt.fromCode(new $s("Signature verification failed",a))}}async _checkDelegationAndGetKey(e){if(!e)return this._rootKey;let r=t.createUnverified({certificate:e.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,disableTimeVerification:this.#e,maxAgeInMinutes:wN,agent:this.#t});if(r.cert.delegation)throw Me.fromCode(new Id);await r.verify();let n=e.subnet_id,s=te.fromUint8Array(n);if(!om({canisterId:this._canisterId,subnetId:s,tree:r.cert.tree}))throw Gt.fromCode(new Fi(this._canisterId,s));let i=Mt(r.lookup_path(["subnet",n,"public_key"]));if(!i)throw Gt.fromCode(new Sd(`Could not find subnet key for subnet ID ${s.toText()}`));return i}},Vc=bt("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),TN=96;function ON(t){let e=Vc.byteLength+TN;if(t.byteLength!==e)throw Me.fromCode(new Vi(e,t.byteLength));let r=t.slice(0,Vc.byteLength);if(!qo(r,Vc))throw Me.fromCode(new Ad(Vc,r));return t.slice(Vc.byteLength)}function Mt(t){if(t.status===lr.Found&&t.value instanceof Uint8Array)return t.value}async function ml(t){switch(t[0]){case Rt.Empty:return Lt(Lc("ic-hashtree-empty"));case Rt.Pruned:return t[1];case Rt.Leaf:return Lt(de(Lc("ic-hashtree-leaf"),t[1]));case Rt.Labeled:return Lt(de(Lc("ic-hashtree-labeled"),t[1],await ml(t[2])));case Rt.Fork:return Lt(de(Lc("ic-hashtree-fork"),await ml(t[1]),await ml(t[2])));default:throw Zs}}function Lc(t){let e=new Uint8Array([t.length]),r=new TextEncoder().encode(t);return de(e,r)}function Dw(t){return typeof t[0]=="string"?Ue(t[0]):t[0]}var lr;(function(t){t.Unknown="Unknown",t.Absent="Absent",t.Found="Found",t.Error="Error"})(lr||(lr={}));var Zo;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found"})(Zo||(Zo={}));var Ge;(function(t){t.Absent="Absent",t.Unknown="Unknown",t.Found="Found",t.Less="Less",t.Greater="Greater"})(Ge||(Ge={}));function zo(t,e){if(t.length===0)switch(e[0]){case Rt.Empty:return{status:lr.Absent};case Rt.Leaf:{if(!e[1])throw ct.fromCode(new Gs("Invalid tree structure for leaf"));if(e[1]instanceof Uint8Array)return{status:lr.Found,value:e[1].slice(e[1].byteOffset,e[1].byteLength+e[1].byteOffset)};throw Zs}case Rt.Pruned:return{status:lr.Unknown};case Rt.Labeled:case Rt.Fork:return{status:lr.Error};default:throw Zs}let r=Dw(t),n=qc(r,e);switch(n.status){case Ge.Found:return zo(t.slice(1),n.value);case Ge.Absent:case Ge.Greater:case Ge.Less:return{status:lr.Absent};case Ge.Unknown:return{status:lr.Unknown};default:throw Zs}}function _l(t,e){if(t.length===0)return{status:Zo.Found,value:e};let r=Dw(t),n=qc(r,e);switch(n.status){case Ge.Found:return _l(t.slice(1),n.value);case Ge.Unknown:return{status:Zo.Unknown};case Ge.Absent:case Ge.Greater:case Ge.Less:return{status:Zo.Absent};default:throw Zs}}function yl(t){switch(t[0]){case Rt.Empty:return[];case Rt.Fork:return yl(t[1]).concat(yl(t[2]));default:return[t]}}function qc(t,e){switch(e[0]){case Rt.Labeled:return EN(t,e[1])?{status:Ge.Greater}:qo(t,e[1])?{status:Ge.Found,value:e[2]}:{status:Ge.Less};case Rt.Fork:{let r=qc(t,e[1]);switch(r.status){case Ge.Greater:{let n=qc(t,e[2]);return n.status===Ge.Less?{status:Ge.Absent}:n}case Ge.Unknown:{let n=qc(t,e[2]);return n.status===Ge.Less?{status:Ge.Unknown}:n}default:return r}}case Rt.Pruned:return{status:Ge.Unknown};default:return{status:Ge.Absent}}}function om(t){let{canisterId:e,subnetId:r,tree:n}=t,s=zo(["subnet",r.toUint8Array(),"canister_ranges"],n);if(s.status!==lr.Found)throw Me.fromCode(new Jn(`Could not find canister ranges for subnet ${r.toText()}`,s.status));if(!(s.value instanceof Uint8Array))throw Me.fromCode(new Ui(`Could not find canister ranges for subnet ${r.toText()}`));return ur(s.value).map(c=>[te.fromUint8Array(c[0]),te.fromUint8Array(c[1])]).some(c=>c[0].ltEq(e)&&c[1].gtEq(e))}var im=async t=>{let{agent:e,paths:r,disableCertificateTimeVerification:n=!1}=t,s=te.from(t.canisterId),o=[...new Set(r)],i=new Map,a=o.map((c,d)=>{let f=vN(c,s);return(async()=>{try{if(e.rootKey===null)throw gt.fromCode(new xn);let l=e.rootKey,u=await e.readState(s,{paths:[f]}),p=await to.create({certificate:u.certificate,rootKey:l,canisterId:s,disableTimeVerification:n,agent:e}),h=(y,x)=>{if(x==="subnet"){let _=NN(u.certificate,s,l);return{path:x,data:_}}else return{path:x,data:Mt(y.lookup_path(f))}},{path:m,data:b}=h(p,o[d]);if(!b)console.warn(`Expected to find result for path ${m}, but instead found nothing.`),typeof m=="string"?i.set(m,null):i.set(m.key,null);else switch(m){case"time":{i.set(m,ta(b));break}case"controllers":{i.set(m,RN(b));break}case"module_hash":{i.set(m,fe(b));break}case"subnet":{i.set(m,b);break}case"candid":{i.set(m,new TextDecoder().decode(b));break}default:if(typeof m!="string"&&"key"in m&&"path"in m)switch(m.decodeStrategy){case"raw":i.set(m.key,b);break;case"leb128":{i.set(m.key,sm(b));break}case"cbor":{i.set(m.key,ur(b));break}case"hex":{i.set(m.key,fe(b));break}case"utf-8":i.set(m.key,new TextDecoder().decode(b))}}}catch(l){if(l instanceof jr&&(l.hasCode($s)||l.hasCode(Co)))throw l;typeof c!="string"&&"key"in c&&"path"in c?i.set(c.key,null):i.set(c,null),console.group(),console.warn(`Expected to find result for path ${c}, but instead found nothing.`),console.warn(l),console.groupEnd()}})()});return await Promise.all(a),i},NN=(t,e,r)=>{if(!e._isPrincipal)throw Ne.fromCode(new Zt("Invalid canisterId"));let n=ur(t),s=n.tree,o=n.delegation,i;if(o&&o.subnet_id?i=te.fromUint8Array(new Uint8Array(o.subnet_id)):!o&&typeof r<"u"?(i=te.selfAuthenticating(new Uint8Array(r)),o={subnet_id:i.toUint8Array(),certificate:new Uint8Array(0)}):(i=te.selfAuthenticating(te.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),o={subnet_id:i.toUint8Array(),certificate:new Uint8Array(0)}),!om({canisterId:e,subnetId:i,tree:s}))throw Gt.fromCode(new Fi(e,i));let c=_l(["subnet",o.subnet_id,"node"],s);if(c.status!==Zo.Found)throw Me.fromCode(new Jn("Node not found",c.status));if(c.value instanceof Uint8Array)throw ct.fromCode(new Gs("Invalid node tree"));let d=yl(c.value),f=new Map;return d.forEach(l=>{let u=te.from(l[1]).toText(),p=zo(["public_key"],l[2]);if(p.status!==lr.Found)throw Me.fromCode(new Jn("Public key not found",p.status));let h=p.value;if(h.byteLength!==44)throw Me.fromCode(new Vi(44,h.byteLength));f.set(u,h)}),{subnetId:te.fromUint8Array(new Uint8Array(o.subnet_id)).toText(),nodeKeys:f}},vN=(t,e)=>{let r=e.toUint8Array();switch(t){case"time":return[Ue("time")];case"controllers":return[Ue("canister"),r,Ue("controllers")];case"module_hash":return[Ue("canister"),r,Ue("module_hash")];case"subnet":return[Ue("subnet")];case"candid":return[Ue("canister"),r,Ue("metadata"),Ue("candid:service")];default:if("key"in t&&"path"in t)if(typeof t.path=="string"||t.path instanceof Uint8Array){let n=t.path,s=typeof n=="string"?Ue(n):n;return[Ue("canister"),r,Ue("metadata"),s]}else return t.path}throw ct.fromCode(new Zt(`Error while encoding your path for canister status. Please ensure that your path ${t} was formatted correctly.`))},RN=t=>ur(t).map(r=>te.fromUint8Array(r));var ro=BigInt(0),wt=BigInt(1),am=BigInt(2),IN=BigInt(8);function SN(t,e,r,n){let s=t.sqr(r),o=t.sqr(n),i=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(i,a)}function AN(t,e={}){let r=ul("edwards",t,e,e.FpFnLE),{Fp:n,Fn:s}=r,o=r.CURVE,{h:i}=o;as(e,{},{uvRatio:"function"});let a=am<<BigInt(s.BYTES*8)-wt,c=b=>n.create(b),d=e.uvRatio||((b,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(b,y))}}catch{return{isValid:!1,value:ro}}});if(!SN(n,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(b,y,x=!1){let _=x?wt:ro;return il("coordinate "+b,y,_,a),y}function l(b){if(!(b instanceof h))throw new Error("ExtendedPoint expected")}let u=Js((b,y)=>{let{X:x,Y:_,Z:T}=b,N=b.is0();y==null&&(y=N?IN:n.inv(T));let v=c(x*y),R=c(_*y),A=n.mul(T,y);if(N)return{x:ro,y:wt};if(A!==wt)throw new Error("invZ was invalid");return{x:v,y:R}}),p=Js(b=>{let{a:y,d:x}=o;if(b.is0())throw new Error("bad point: ZERO");let{X:_,Y:T,Z:N,T:v}=b,R=c(_*_),A=c(T*T),E=c(N*N),S=c(E*E),U=c(R*y),C=c(E*c(U+A)),g=c(S+c(x*c(R*A)));if(C!==g)throw new Error("bad point: equation left != right (1)");let w=c(_*T),O=c(N*v);if(w!==O)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(y,x,_,T){this.X=f("x",y),this.Y=f("y",x),this.Z=f("z",_,!0),this.T=f("t",T),Object.freeze(this)}static CURVE(){return o}static fromAffine(y){if(y instanceof h)throw new Error("extended point not allowed");let{x,y:_}=y||{};return f("x",x),f("y",_),new h(x,_,wt,c(x*_))}static fromBytes(y,x=!1){let _=n.BYTES,{a:T,d:N}=o;y=F0(Xs(y,_,"point")),jo(x,"zip215");let v=F0(y),R=y[_-1];v[_-1]=R&-129;let A=os(v),E=x?a:n.ORDER;il("point.y",A,ro,E);let S=c(A*A),U=c(S-wt),C=c(N*S-T),{isValid:g,value:w}=d(U,C);if(!g)throw new Error("bad point: invalid y coordinate");let O=(w&wt)===wt,P=(R&128)!==0;if(!x&&w===ro&&P)throw new Error("bad point: x=0 and x_0=1");return P!==O&&(w=c(-w)),h.fromAffine({x:w,y:A})}static fromHex(y,x=!1){return h.fromBytes(We("point",y),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,x=!0){return m.createCache(this,y),x||this.multiply(am),this}assertValidity(){p(this)}equals(y){l(y);let{X:x,Y:_,Z:T}=this,{X:N,Y:v,Z:R}=y,A=c(x*R),E=c(N*T),S=c(_*R),U=c(v*T);return A===E&&S===U}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=o,{X:x,Y:_,Z:T}=this,N=c(x*x),v=c(_*_),R=c(am*c(T*T)),A=c(y*N),E=x+_,S=c(c(E*E)-N-v),U=A+v,C=U-R,g=A-v,w=c(S*C),O=c(U*g),P=c(S*g),L=c(C*U);return new h(w,O,L,P)}add(y){l(y);let{a:x,d:_}=o,{X:T,Y:N,Z:v,T:R}=this,{X:A,Y:E,Z:S,T:U}=y,C=c(T*A),g=c(N*E),w=c(R*_*U),O=c(v*S),P=c((T+N)*(A+E)-C-g),L=O-w,I=O+w,B=c(g-x*C),F=c(P*L),V=c(I*B),q=c(P*B),H=c(L*I);return new h(F,V,H,q)}subtract(y){return this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:_}=m.cached(this,y,T=>Ar(h,T));return Ar(h,[x,_])[0]}multiplyUnsafe(y,x=h.ZERO){if(!s.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===ro?h.ZERO:this.is0()||y===wt?this:m.unsafe(this,y,_=>Ar(h,_),x)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return m.unsafe(this,o.n).is0()}toAffine(y){return u(this,y)}clearCofactor(){return i===wt?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:x}=this.toAffine(),_=n.toBytes(x);return _[_.length-1]|=y&wt?128:0,_}toHex(){return fe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(y){return Ar(h,y)}static msm(y,x){return Ji(h,s,y,x)}_setWindowSize(y){this.precompute(y)}toRawBytes(){return this.toBytes()}}h.BASE=new h(o.Gx,o.Gy,wt,c(o.Gx*o.Gy)),h.ZERO=new h(ro,wt,wt,ro),h.Fp=n,h.Fn=s;let m=new Xi(h,s.BITS);return h.BASE.precompute(8),h}var bl=class{constructor(e){this.ep=e}static fromBytes(e){Yi()}static fromHex(e){Yi()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return fe(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.init(this.ep.precompute(e,r))}toRawBytes(){return this.toBytes()}};function BN(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');as(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:s,Fp:o,Fn:i}=t,a=r.randomBytes||Di,c=r.adjustScalarBytes||(E=>E),d=r.domain||((E,S,U)=>{if(jo(U,"phflag"),S.length||U)throw new Error("Contexts/pre-hash are not supported");return E});function f(E){return i.create(os(E))}function l(E){let S=_.secretKey;E=We("private key",E,S);let U=We("hashed private key",e(E),2*S),C=c(U.slice(0,S)),g=U.slice(S,2*S),w=f(C);return{head:C,prefix:g,scalar:w}}function u(E){let{head:S,prefix:U,scalar:C}=l(E),g=s.multiply(C),w=g.toBytes();return{head:S,prefix:U,scalar:C,point:g,pointBytes:w}}function p(E){return u(E).pointBytes}function h(E=Uint8Array.of(),...S){let U=de(...S);return f(e(d(U,We("context",E),!!n)))}function m(E,S,U={}){E=We("message",E),n&&(E=n(E));let{prefix:C,scalar:g,pointBytes:w}=u(S),O=h(U.context,C,E),P=s.multiply(O).toBytes(),L=h(U.context,P,w,E),I=i.create(O+L*g);if(!i.isValid(I))throw new Error("sign failed: invalid s");let B=de(P,i.toBytes(I));return Xs(B,_.signature,"result")}let b={zip215:!0};function y(E,S,U,C=b){let{context:g,zip215:w}=C,O=_.signature;E=We("signature",E,O),S=We("message",S),U=We("publicKey",U,_.publicKey),w!==void 0&&jo(w,"zip215"),n&&(S=n(S));let P=O/2,L=E.subarray(0,P),I=os(E.subarray(P,O)),B,F,V;try{B=t.fromBytes(U,w),F=t.fromBytes(L,w),V=s.multiplyUnsafe(I)}catch{return!1}if(!w&&B.isSmallOrder())return!1;let q=h(g,F.toBytes(),B.toBytes(),S);return F.add(B.multiplyUnsafe(q)).subtract(V).clearCofactor().is0()}let x=o.BYTES,_={secretKey:x,publicKey:x,signature:2*x,seed:x};function T(E=a(_.seed)){return Xs(E,_.seed,"seed")}function N(E){let S=A.randomSecretKey(E);return{secretKey:S,publicKey:p(S)}}function v(E){return bn(E)&&E.length===i.BYTES}function R(E,S){try{return!!t.fromBytes(E,S)}catch{return!1}}let A={getExtendedPublicKey:u,randomSecretKey:T,isValidSecretKey:v,isValidPublicKey:R,toMontgomery(E){let{y:S}=t.fromBytes(E),U=_.publicKey,C=U===32;if(!C&&U!==57)throw new Error("only defined for 25519 and 448");let g=C?o.div(wt+S,wt-S):o.div(S-wt,S+wt);return o.toBytes(g)},toMontgomerySecret(E){let S=_.secretKey;Xs(E,S);let U=e(E.subarray(0,S));return c(U).subarray(0,S)},randomPrivateKey:T,precompute(E=8,S=t.BASE){return S.precompute(E,!1)}};return Object.freeze({keygen:N,getPublicKey:p,sign:m,verify:y,utils:A,Point:t,lengths:_})}function CN(t){let e={a:t.a,d:t.d,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=Wt(e.n,t.nBitLength,!0),s={Fp:r,Fn:n,uvRatio:t.uvRatio},o={randomBytes:t.randomBytes,adjustScalarBytes:t.adjustScalarBytes,domain:t.domain,prehash:t.prehash,mapToCurve:t.mapToCurve};return{CURVE:e,curveOpts:s,hash:t.hash,eddsaOpts:o}}function PN(t,e){let r=e.Point;return Object.assign({},e,{ExtendedPoint:r,CURVE:t,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Fw(t){let{CURVE:e,curveOpts:r,hash:n,eddsaOpts:s}=CN(t),o=AN(e,r),i=BN(o,n,s);return PN(t,i)}var DN=BigInt(0),ls=BigInt(1),Uw=BigInt(2),rA=BigInt(3),FN=BigInt(5),UN=BigInt(8),ra=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Mc={p:ra,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:UN,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function VN(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=ra,a=t*t%o*t%o,c=Wr(a,Uw,o)*a%o,d=Wr(c,ls,o)*t%o,f=Wr(d,FN,o)*d%o,l=Wr(f,e,o)*f%o,u=Wr(l,r,o)*l%o,p=Wr(u,n,o)*u%o,h=Wr(p,s,o)*p%o,m=Wr(h,s,o)*p%o,b=Wr(m,e,o)*f%o;return{pow_p_5_8:Wr(b,Uw,o)*t%o,b2:a}}function LN(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var cm=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function lm(t,e){let r=ra,n=Ke(e*e*e,r),s=Ke(n*n*e,r),o=VN(t*s).pow_p_5_8,i=Ke(t*n*o,r),a=Ke(e*i*i,r),c=i,d=Ke(i*cm,r),f=a===t,l=a===Ke(-t,r),u=a===Ke(-t*cm,r);return f&&(i=c),(l||u)&&(i=d),cs(i,r)&&(i=Ke(-i,r)),{isValid:f||l,value:i}}var no=Wt(Mc.p,{isLE:!0}),qN=Wt(Mc.n,{isLE:!0}),MN={...Mc,Fp:no,hash:ax,adjustScalarBytes:LN,uvRatio:lm},Qt=Fw(MN);var um=cm,kN=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),jN=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),HN=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),$N=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Vw=t=>lm(ls,t),KN=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),dm=t=>Qt.Point.Fp.create(os(t)&KN);function Lw(t){let{d:e}=Mc,r=ra,n=y=>no.create(y),s=n(um*t*t),o=n((s+ls)*HN),i=BigInt(-1),a=n((i-e*s)*n(s+e)),{isValid:c,value:d}=lm(o,a),f=n(d*t);cs(f,r)||(f=n(-f)),c||(d=f),c||(i=s);let l=n(i*(s-ls)*$N-a),u=d*d,p=n((d+d)*a),h=n(l*kN),m=n(ls-u),b=n(ls+u);return new Qt.Point(n(p*b),n(m*h),n(h*b),n(p*m))}function GN(t){Qe(t,64);let e=dm(t.subarray(0,32)),r=Lw(e),n=dm(t.subarray(32,64)),s=Lw(n);return new fs(r.add(s))}var fs=class t extends bl{constructor(e){super(e)}static fromAffine(e){return new t(Qt.Point.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static hashToCurve(e){return GN(We("ristrettoHash",e,64))}static fromBytes(e){Qe(e,32);let{a:r,d:n}=Mc,s=ra,o=T=>no.create(T),i=dm(e);if(!tw(no.toBytes(i),e)||cs(i,s))throw new Error("invalid ristretto255 encoding 1");let a=o(i*i),c=o(ls+r*a),d=o(ls-r*a),f=o(c*c),l=o(d*d),u=o(r*n*f-l),{isValid:p,value:h}=Vw(o(u*l)),m=o(h*d),b=o(h*m*u),y=o((i+i)*m);cs(y,s)&&(y=o(-y));let x=o(c*b),_=o(y*x);if(!p||cs(_,s)||x===DN)throw new Error("invalid ristretto255 encoding 2");return new t(new Qt.Point(y,x,ls,_))}static fromHex(e){return t.fromBytes(We("ristrettoHex",e,32))}static msm(e,r){return Ji(t,Qt.Point.Fn,e,r)}toBytes(){let{X:e,Y:r,Z:n,T:s}=this.ep,o=ra,i=b=>no.create(b),a=i(i(n+r)*i(n-r)),c=i(e*r),d=i(c*c),{value:f}=Vw(i(a*d)),l=i(f*a),u=i(f*c),p=i(l*u*s),h;if(cs(s*p,o)){let b=i(r*um),y=i(e*um);e=b,r=y,h=i(l*jN)}else h=u;cs(e*p,o)&&(r=i(-r));let m=i((n-r)*h);return cs(m,o)&&(m=i(-m)),no.toBytes(m)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:s,Y:o}=e.ep,i=d=>no.create(d),a=i(r*o)===i(n*s),c=i(n*o)===i(r*s);return a||c}is0(){return this.equals(t.ZERO)}};fs.BASE=new fs(Qt.Point.BASE);fs.ZERO=new fs(Qt.Point.ZERO);fs.Fp=no;fs.Fn=qN;var qw,Mw,gl=class{static{qw=Symbol.iterator,Mw=Symbol.toStringTag}#e;#t;constructor(e={}){this[qw]=this.entries.bind(this),this[Mw]="ExpirableMap";let{source:r=[],expirationTime:n=600*1e3}=e,s=Date.now();this.#e=new Map([...r].map(([o,i])=>[o,{value:i,timestamp:s}])),this.#t=n}prune(){let e=Date.now();for(let[r,n]of this.#e.entries())e-n.timestamp>this.#t&&this.#e.delete(r);return this}set(e,r){this.prune();let n={value:r,timestamp:Date.now()};return this.#e.set(e,n),this}get(e){let r=this.#e.get(e);if(r!==void 0){if(Date.now()-r.timestamp>this.#t){this.#e.delete(e);return}return r.value}}clear(){this.#e.clear()}entries(){let e=this.#e.entries();return function*(){for(let[n,s]of e)yield[n,s.value]}()}values(){let e=this.#e.values();return function*(){for(let n of e)yield n.value}()}keys(){return this.#e.keys()}forEach(e,r){for(let[n,s]of this.#e.entries())e.call(r,s.value,n,this)}has(e){return this.#e.has(e)}delete(e){return this.#e.delete(e)}get size(){return this.#e.size}};var kw=t=>{if(t<=127)return 1;if(t<=255)return 2;if(t<=65535)return 3;if(t<=16777215)return 4;throw Ne.fromCode(new cc("Length too long (> 4 bytes)"))},jw=(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 Ne.fromCode(new cc("Length too long (> 4 bytes)"))},fm=(t,e)=>{if(t[e]<128)return 1;if(t[e]===128)throw Ne.fromCode(new Hr("Invalid length 0"));if(t[e]===129)return 2;if(t[e]===130)return 3;if(t[e]===131)return 4;throw Ne.fromCode(new Hr("Length too long (> 4 bytes)"))},ZN=(t,e)=>{let r=fm(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 Ne.fromCode(new Hr("Length too long (> 4 bytes)"))},kc=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),Yo=Uint8Array.from([48,5,6,3,43,101,112]),aA=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]),cA=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 Wo(t,e){let r=2+kw(t.byteLength+1),n=e.byteLength+r+t.byteLength,s=0,o=new Uint8Array(1+kw(n)+n);return o[s++]=48,s+=jw(o,s,n),o.set(e,s),s+=e.byteLength,o[s++]=3,s+=jw(o,s,t.byteLength+1),o[s++]=0,o.set(new Uint8Array(t),s),o}var Xo=(t,e)=>{let r=0,n=(a,c)=>{if(s[r++]!==a)throw Ne.fromCode(new Hr(`Expected ${c} at offset ${r}`))},s=new Uint8Array(t);if(n(48,"sequence"),r+=fm(s,r),!qo(s.slice(r,r+e.byteLength),e))throw Ne.fromCode(new Hr("Not the expected OID."));r+=e.byteLength,n(3,"bit string");let o=ZN(s,r)-1;r+=fm(s,r),n(0,"0 padding");let i=s.slice(r);if(o!==i.length)throw Ne.fromCode(new Bd(o,i.length));return i};var xl=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 Wo(e,Yo)}static derDecode(e){let r=Xo(e,Yo);if(r.length!==this.RAW_KEY_LENGTH)throw Ne.fromCode(new Hr("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 Ne.fromCode(new Hr("An Ed25519 public key must be exactly 32 bytes long"));this.#e=e,this.#t=t.derEncode(e)}toDer(){return this.derKey}toRaw(){return this.rawKey}};var pm=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))}},wl=class extends pm{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 El=class t{#e;#t;#r;#c;#i;#d;#n;#s;#a=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:s=1.5,maxInterval:o=6e4,maxElapsedTime:i=9e5,maxIterations:a=10,date:c=Date}=e;this.#e=r,this.#t=n,this.#r=s,this.#c=o,this.#s=c,this.#i=c.now(),this.#d=i,this.#n=a}get ellapsedTimeInMsec(){return this.#s.now()-this.#i}get currentInterval(){return this.#e}get count(){return this.#a}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.#c),this.#a++,this.#e}next(){return this.ellapsedTimeInMsec>=this.#d||this.#a>=this.#n?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};var vn;(function(t){t.Received="received",t.Processing="processing",t.Replied="replied",t.Rejected="rejected",t.Unknown="unknown",t.Done="done"})(vn||(vn={}));var ym=60*1e3,zN=1e6,YN=0,WN="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae";var XN="ic0.app",JN=".ic0.app",QN="icp0.io",ev=".icp0.io",tv="icp-api.io",rv=".icp-api.io",hm=200,nv=202,sv=404;function ov(){let t;if(typeof window<"u")if(window.fetch)t=window.fetch.bind(window);else throw gt.fromCode(new qi("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present."));else if(typeof global<"u")if(global.fetch)t=global.fetch.bind(global);else throw gt.fromCode(new qi("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available."));else typeof self<"u"&&self.fetch&&(t=self.fetch.bind(self));if(t)return t;throw gt.fromCode(new qi("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context."))}function iv(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"],s=typeof window<"u"?window.location:void 0,o=s?.hostname,i;o&&typeof o=="string"&&(n.some(a=>o.endsWith(a))?i=o:i=r.find(a=>o.endsWith(a))),s&&i?e=new URL(`${s.protocol}//${i}${s.port?":"+s.port:""}`):e=new URL("https://icp-api.io")}return e.toString()}var Jo=class t{#e;#t;#r;#c;#i;#d;#n;#s;#a;#g;#o;#l;#f;#u;get#T(){return this.#u*ym}#p;#h;#m;#y;constructor(e={}){this.#e=null,this.#t=!1,this.#r=YN,this.#c=!1,this.#i=null,this.#d=!1,this._isAgent=!0,this.config={},this.log=new wl,this.#p=[],this.#h=[],this.#m=new gl({expirationTime:5*ym}),this.#y=!0,this.#w=(s,o)=>{if(this.#y===!1)return s;let{status:i,signatures:a=[],requestId:c}=s;for(let d of a){let{timestamp:f,identity:l}=d,u=te.fromUint8Array(l).toText(),p;if(i===qs.Replied){let{reply:x}=s;p=xc({status:i,reply:x,timestamp:BigInt(f),request_id:c})}else if(i===qs.Rejected){let{reject_code:x,reject_message:_,error_code:T}=s;p=xc({status:i,reject_code:x,reject_message:_,error_code:T,timestamp:BigInt(f),request_id:c})}else throw ct.fromCode(new Zt(`Unknown status: ${i}`));let h=de(O0,p),m=o.nodeKeys.get(u);if(!m)throw Me.fromCode(new jd);let b=xl.fromDer(m).rawKey;if(Qt.verify(d.signature,h,b))return s;throw Gt.fromCode(new Hd(u))}return s},this.config=e,this.#s=e.fetch||ov()||fetch.bind(global),this.#a=e.fetchOptions,this.#g=e.callOptions,this.#t=e.shouldFetchRootKey??!1,this.#d=e.shouldSyncTime??!1,e.rootKey?this.rootKey=e.rootKey:this.#t?this.rootKey=null:this.rootKey=bt(WN);let r=iv(e.host);this.host=new URL(r),e.verifyQuerySignatures!==void 0&&(this.#y=e.verifyQuerySignatures),this.#l=e.retryTimes??3;let n=()=>new El({maxIterations:this.#l});if(this.#f=e.backoffStrategy||n,this.host.hostname.endsWith(JN)?this.host.hostname=XN:this.host.hostname.endsWith(ev)?this.host.hostname=QN:this.host.hostname.endsWith(rv)&&(this.host.hostname=tv),e.credentials){let{name:s,password:o}=e.credentials;this.#o=`${s}${o?":"+o:""}`}if(this.#n=Promise.resolve(e.identity||new Ir),e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes>5)throw Ne.fromCode(new Do("The maximum ingress expiry time is 5 minutes.",e.ingressExpiryInMinutes));if(e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes<=0)throw Ne.fromCode(new Do("Ingress expiry time must be greater than 0.",e.ingressExpiryInMinutes));this.#u=e.ingressExpiryInMinutes||5,this.addTransform("update",B0(Ic)),e.useQueryNonces&&this.addTransform("query",B0(Ic)),e.logToConsole&&this.log.subscribe(s=>{s.level==="error"?console.error(s.message):s.level==="warn"?console.warn(s.message):console.log(s.message)})}static createSync(e={}){return new this({...e})}static async create(e={}){let r=t.createSync(e);return await r.#b(),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 Ne.fromCode(new qd)}}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 s=this.#h.findIndex(o=>(o.priority||0)<n);this.#h.splice(s>=0?s:this.#h.length,0,Object.assign(r,{priority:n}))}else if(e==="query"){let s=this.#p.findIndex(o=>(o.priority||0)<n);this.#p.splice(s>=0?s:this.#p.length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!this.#n)throw gt.fromCode(new Ks);return(await this.#n).getPrincipal()}async call(e,r,n){let s=r.callSync??!0,o=await(n??this.#n);if(!o)throw gt.fromCode(new Ks);let i=te.from(e),a=r.effectiveCanisterId?te.from(r.effectiveCanisterId):i;await this.#b(a);let c=o.getPrincipal(),d=mm(this.#u,this.#r),f={request_type:rl.Call,canister_id:i,method_name:r.methodName,arg:r.arg,sender:c,ingress_expiry:d},l=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#o?{Authorization:"Basic "+btoa(this.#o)}:{}}},endpoint:ss.Call,body:f}),u;r?.nonce?u=p(r.nonce):l.body.nonce?u=p(l.body.nonce):u=void 0,f.nonce=u;function p(y){return Object.assign(y,{__nonce__:void 0})}l=await o.transformRequest(l);let h=vc(l.body),m=this.#f(),b=rs(f);try{let _=s?()=>(this.log.print(`fetching "/api/v3/canister/${a.toText()}/call" with request:`,l),this.#s(""+new URL(`/api/v3/canister/${a.toText()}/call`,this.host),{...this.#g,...l.request,body:h})):()=>(this.log.print(`fetching "/api/v2/canister/${a.toText()}/call" with request:`,l),this.#s(""+new URL(`/api/v2/canister/${a.toText()}/call`,this.host),{...this.#g,...l.request,body:h})),{responseBodyBytes:T,...N}=await this.#_({requestFn:_,backoff:m,tries:0}),v=T.byteLength>0?ur(T):null;return{requestId:b,response:{...N,body:v},requestDetails:f}}catch(y){let x;if(y instanceof jr){if(y.hasCode(dc))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(e,{...r,callSync:!1},n);if(y.hasCode(Do)&&!this.#c)return await this.syncTime(i),this.call(i,r,n);y.code.requestContext={requestId:b,senderPubKey:l.body.sender_pubkey,senderSignature:l.body.sender_sig,ingressExpiry:l.body.content.ingress_expiry},x=y}else x=ct.fromCode(new Zt(y));throw this.log.error(`Error while making call: ${x.message}`,x),x}}async#x(e){let{ecid:r,transformedRequest:n,body:s,requestId:o,backoff:i,tries:a}=e,c=a===0?0:i.next();if(this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with tries:`,{tries:a,backoff:i,delay:c}),c===null)throw ct.fromCode(new Po(`Backoff strategy exhausted after ${a} attempts.`,o));c>0&&await new Promise(p=>setTimeout(p,c));let d;try{this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with request:`,n);let p=await this.#s(""+new URL(`/api/v2/canister/${r.toString()}/query`,this.host),{...this.#a,...n.request,body:s});if(p.status===hm)d={...ur($i(await p.arrayBuffer())),httpDetails:{ok:p.ok,status:p.status,statusText:p.statusText,headers:sl(p.headers)},requestId:o};else throw Me.fromCode(new uc(p.status,p.statusText,sl(p.headers),await p.text()))}catch(p){if(a<this.#l)return this.log.warn(`Caught exception while attempting to make query:
|
|
121
119
|
${p}
|
|
122
|
-
Retrying request.`),await this.#_({requestFn:r,backoff:n,tries:o+1});throw Ma.fromCode(new $a(p))}let c=Dd(i.headers);if(i.status===P0||i.status===aN)return{ok:i.ok,status:i.status,statusText:i.statusText,responseBodyBytes:a,headers:c};let d=await i.text();if(i.status===cN&&i.url.includes("api/v3"))throw Me.fromCode(new Ha);if(d.startsWith("Invalid request expiry: "))throw Ne.fromCode(new ms(d,this.#u));if(o<this.#l)return await this.#_({requestFn:r,backoff:n,tries:o+1});throw Me.fromCode(new ja(i.status,i.statusText,c,d))}async query(e,r,n){let o=this.#f(),s=r.effectiveCanisterId?oe.from(r.effectiveCanisterId):oe.from(e);await this.#b(s),this.log.print(`ecid ${s.toString()}`),this.log.print(`canisterId ${e.toString()}`);let i,a=await(n??this.#n);if(!a)throw mt.fromCode(new Bo);let c=oe.from(e),d=a.getPrincipal(),p=D0(this.#u,this.#r),l={request_type:Es.Query,canister_id:c,method_name:r.methodName,arg:r.arg,sender:d,ingress_expiry:p},u=Zn(l);i=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#s?{Authorization:"Basic "+btoa(this.#s)}:{}}},endpoint:Wn.Query,body:l}),i=await a.transformRequest(i);let f=sc(i.body),h={canister:c.toText(),ecid:s,transformedRequest:i,body:f,requestId:u,backoff:o,tries:0},m=async()=>{let y=await this.#x(h);return{requestDetails:l,...y}},b=async()=>{let y=this.#m.get(s.toString());if(y)return y;await this.fetchSubnetKeys(s.toString());let x=this.#m.get(s.toString());if(!x)throw Lt.fromCode(new _d);return x};try{if(!this.#y)return await m();let[y,x]=await Promise.all([m(),b()]);try{return this.#w(y,x)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),this.#m.delete(s.toString());let _=await b();return this.#w(y,_)}}catch(y){let x;throw y instanceof Pr?(y.code.requestContext={requestId:u,senderPubKey:i.body.sender_pubkey,senderSignature:i.body.sender_sig,ingressExpiry:i.body.content.ingress_expiry},x=y):x=st.fromCode(new qt(y)),this.log.error(`Error while making query: ${x.message}`,x),x}}#w;async createReadStateRequest(e,r){await this.#b();let n=await(r??this.#n);if(!n)throw mt.fromCode(new Bo);let o=n.getPrincipal(),s=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#s?{Authorization:"Basic "+btoa(this.#s)}:{}}},endpoint:Wn.ReadState,body:{request_type:Es.ReadState,paths:e.paths,sender:o,ingress_expiry:D0(this.#u,this.#r)}});return n.transformRequest(s)}async readState(e,r,n,o){await this.#E();let s=oe.from(e);function i(p){for(let l of p.paths){let[u,f]=l,h=new TextEncoder().encode("request_status");if(xs(u,h))return f}}let a,c;if(o)a=o,c=Zn(a);else{c=i(r);let p=await this.#n;if(!p)throw mt.fromCode(new Bo);a=await this.createReadStateRequest(r,p)}this.log.print(`fetching "/api/v2/canister/${s}/read_state" with request:`,a);let d=this.#f();try{let{responseBodyBytes:p}=await this.#_({requestFn:()=>this.#o(""+new URL(`/api/v2/canister/${s.toString()}/read_state`,this.host),{...this.#a,...a.request,body:sc(a.body)}),backoff:d,tries:0}),l=rr(p);return this.log.print("Read state response:",l),l}catch(p){let l;throw p instanceof Pr?(p.code.requestContext={requestId:c,senderPubKey:a.body.sender_pubkey,senderSignature:a.body.sender_sig,ingressExpiry:a.body.content.ingress_expiry},l=p):l=st.fromCode(new qt(p)),this.log.error(`Error while making read state: ${l.message}`,l),l}}parseTimeFromResponse(e){let r;if(e.certificate){let n=rr(e.certificate);if(n&&"tree"in n)r=n.tree;else throw Me.fromCode(new Co("Could not decode time from response"));let o=Ss(["time"],r);if(o.status!==or.Found)throw Me.fromCode(new $n("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 Me.fromCode(new bi("Time was not in its expected format."));let s=Ui(o.value);return this.log.print("Time from response:",s),this.log.print("Time from response in milliseconds:",s.getTime()),s.getTime()}else this.log.warn("No certificate found in response");return 0}async syncTime(e){this.#i=this.#i??(async()=>{await this.#E();let r=Date.now();try{e||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let n=e??oe.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),o=t.createSync({identity:new gr,host:this.host.toString(),fetch:this.#o,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),i=(await Promise.all(Array(3).fill(null).map(async()=>{let c=(await N0({canisterId:n,agent:o,paths:["time"],disableCertificateTimeVerification:!0})).get("time");if(c instanceof Date)return c.getTime()},[]))).reduce((a,c)=>typeof c=="number"&&c>a?c:a,0);i>0&&(this.#r=i-r,this.#c=!0,this.log.notify({message:`Syncing time: offset of ${this.#r}`,level:"info"}))}catch(n){let o=n instanceof Pr?n:st.fromCode(new qt(n));throw this.log.error("Caught exception while attempting to sync time",o),o}})(),await this.#i.finally(()=>{this.#i=null})}async status(){let e=this.#s?{Authorization:"Basic "+btoa(this.#s)}:{};this.log.print('fetching "/api/v2/status"');let r=this.#f(),{responseBodyBytes:n}=await this.#_({backoff:r,requestFn:()=>this.#o(""+new URL("/api/v2/status",this.host),{headers:e,...this.#a}),tries:0});return rr(n)}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#b(e){await Promise.all([this.#E(),this.#O(e)])}async#E(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#t)await this.fetchRootKey();else throw mt.fromCode(new ln(this.#t))}async#O(e){this.#d&&!this.hasSyncedTime()&&await this.syncTime(e)}invalidateIdentity(){this.#n=null}replaceIdentity(e){this.#n=Promise.resolve(e)}async fetchSubnetKeys(e){let r=oe.from(e);await this.#b(r);let o=(await N0({canisterId:r,paths:["subnet"],agent:this})).get("subnet");if(o&&typeof o=="object"&&"nodeKeys"in o)return this.#m.set(r.toText(),o),o}_transform(e){let r=Promise.resolve(e);if(e.endpoint===Wn.Call)for(let n of this.#h)r=r.then(o=>n(o).then(s=>s||o));else for(let n of this.#p)r=r.then(o=>n(o).then(s=>s||o));return r}getTimeDiffMsecs(){return this.#r}hasSyncedTime(){return this.#c}};function D0(t,e){let r=t*F0;return Ai.fromDeltaInMilliseconds(r,e)}var lN=300*1e3;function nw(){return yN(pN(fN(),1e3),mN(1e3,1.2),hN(lN))}function fN(){let t=!0;return async()=>t?(t=!1,!0):!1}function pN(t,e){return async(r,n,o)=>{if(await t(r,n,o))return new Promise(s=>setTimeout(s,e))}}function hN(t){let e=Date.now()+t;return async(r,n,o)=>{if(Date.now()>e)throw Me.fromCode(new hs(`Request timed out after ${t} msec`,n,o))}}function mN(t,e){let r=t;return()=>new Promise(n=>setTimeout(()=>{r*=e,n()},r))}function yN(...t){return async(e,r,n)=>{for(let o of t)await o(e,r,n)}}var sw={preSignReadStateRequest:!1};function iw(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function V0(t,e){return t!==null&&typeof t=="object"&&iw(t,e)}function bN(t,e){return iw(t,e)&&typeof t[e]=="function"}function ow(t){return V0(t,"body")&&V0(t.body,"content")&&t.body.content.request_type===Es.ReadState&&V0(t.body.content,"ingress_expiry")&&typeof t.body.content.ingress_expiry=="object"&&t.body.content.ingress_expiry!==null&&bN(t.body.content.ingress_expiry,"toHash")}async function U0(t,e,r,n={}){let o=[Ve("request_status"),r],s,i;if(n.preSignReadStateRequest??!1?(i=await gN({paths:[o],agent:t,pollingOptions:n}),s=await t.readState(e,{paths:[o]},void 0,i)):s=await t.readState(e,{paths:[o]}),t.rootKey==null)throw mt.fromCode(new ln);let c=await ko.create({certificate:s.certificate,rootKey:t.rootKey,canisterId:e,blsVerify:n.blsVerify,agent:t}),d=Dt(c.lookup_path([...o,Ve("status")])),p;switch(typeof d>"u"?p=_n.Unknown:p=new TextDecoder().decode(d),p){case _n.Replied:return{reply:Dt(c.lookup_path([...o,"reply"])),certificate:c};case _n.Received:case _n.Unknown:case _n.Processing:{let l=n.strategy??nw();return await l(e,r,p),U0(t,e,r,{...n,strategy:l,request:i})}case _n.Rejected:{let l=new Uint8Array(Dt(c.lookup_path([...o,"reject_code"])))[0],u=new TextDecoder().decode(Dt(c.lookup_path([...o,"reject_message"]))),f=Dt(c.lookup_path([...o,"error_code"])),h=f?new TextDecoder().decode(f):void 0;throw So.fromCode(new xi(r,l,u,h))}case _n.Done:throw st.fromCode(new pd(r))}throw Po}async function gN(t){let{paths:e,agent:r,pollingOptions:n}=t;if(n.request&&ow(n.request))return n.request;let o=await r.createReadStateRequest?.({paths:e},void 0);if(!ow(o))throw Ne.fromCode(new xd(o));return o}var Tr=Symbol.for("ic-agent-metadata"),Qd=class t{static agentOf(e){return e[Tr].config.agent}static interfaceOf(e){return e[Tr].service}static canisterIdOf(e){return oe.from(e[Tr].config.canisterId)}static createActorClass(e,r){let n=e({IDL:gs});class o extends t{constructor(i){if(!i.canisterId)throw Ne.fromCode(new Ka(i.canisterId));let a=typeof i.canisterId=="string"?oe.fromText(i.canisterId):i.canisterId;super({config:{...aw,...i,canisterId:a},service:n});for(let[c,d]of n._fields)r?.httpDetails&&d.annotations.push(L0),r?.certificate&&d.annotations.push(cw),this[c]=wN(this,c,d,i.blsVerify)}}return o}static createActor(e,r){if(!r.canisterId)throw Ne.fromCode(new Ka(r.canisterId));return new(this.createActorClass(e))(r)}static createActorWithHttpDetails(e,r){return new(this.createActorClass(e,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(e,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(e,n))(r)}constructor(e){this[Tr]=Object.freeze(e)}};function qi(t,e){let r=gs.decode(t,e);switch(r.length){case 0:return;case 1:return r[0];default:return r}}var aw={pollingOptions:sw},L0="http-details",cw="certificate";function wN(t,e,r,n){let o;r.annotations.includes("query")||r.annotations.includes("composite_query")?o=async(i,...a)=>{i={...i,...t[Tr].config.queryTransform?.(e,a,{...t[Tr].config,...i})};let c=i.agent||t[Tr].config.agent||new Ps,d=oe.from(i.canisterId||t[Tr].config.canisterId),p=gs.encode(r.argTypes,a),l=await c.query(d,{methodName:e,arg:p,effectiveCanisterId:i.effectiveCanisterId}),u={...l.httpDetails,requestDetails:l.requestDetails};switch(l.status){case No.Rejected:{let f=new ld(l.requestId,l.reject_code,l.reject_message,l.error_code,l.signatures);throw f.callContext={canisterId:d,methodName:e,httpDetails:u},So.fromCode(f)}case No.Replied:return r.annotations.includes(L0)?{httpDetails:u,result:qi(r.retTypes,l.reply.arg)}:qi(r.retTypes,l.reply.arg)}}:o=async(i,...a)=>{i={...i,...t[Tr].config.callTransform?.(e,a,{...t[Tr].config,...i})};let c=i.agent||t[Tr].config.agent||Ps.createSync(),{canisterId:d,effectiveCanisterId:p,pollingOptions:l}={...aw,...t[Tr].config,...i},u=oe.from(d),f=p!==void 0?oe.from(p):u,h=gs.encode(r.argTypes,a),{requestId:m,response:b,requestDetails:y}=await c.call(u,{methodName:e,arg:h,effectiveCanisterId:f,nonce:i.nonce}),x,_;if(rg(b.body)){if(c.rootKey==null)throw mt.fromCode(new ln);let v=b.body.certificate;_=await ko.create({certificate:v,rootKey:c.rootKey,canisterId:f,blsVerify:n,agent:c});let A=[Ve("request_status"),m];switch(new TextDecoder().decode(Dt(_.lookup_path([...A,"status"])))){case"replied":x=Dt(_.lookup_path([...A,"reply"]));break;case"rejected":{let S=new Uint8Array(Dt(_.lookup_path([...A,"reject_code"])))[0],V=new TextDecoder().decode(Dt(_.lookup_path([...A,"reject_message"]))),C=Dt(_.lookup_path([...A,"error_code"])),g=C?new TextDecoder().decode(C):void 0,w=new xi(m,S,V,g);throw w.callContext={canisterId:u,methodName:e,httpDetails:b},So.fromCode(w)}}}else if(tg(b.body)){let{reject_code:v,reject_message:A,error_code:E}=b.body,S=new fd(m,v,A,E);throw S.callContext={canisterId:u,methodName:e,httpDetails:b},So.fromCode(S)}if(b.status===202){let v={...l,blsVerify:n},A=await U0(c,f,m,v);_=A.certificate,x=A.reply}let T=r.annotations.includes(L0),N=r.annotations.includes(cw),I={...b,requestDetails:y};if(x!==void 0)return T&&N?{httpDetails:I,certificate:_,result:qi(r.retTypes,x)}:N?{certificate:_,result:qi(r.retTypes,x)}:T?{httpDetails:I,result:qi(r.retTypes,x)}:qi(r.retTypes,x);{let v=new qt(`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${r.retTypes.map(A=>A.display()).join(",")}].`);throw v.callContext={canisterId:u,methodName:e,httpDetails:I},st.fromCode(v)}};let s=(...i)=>o({},...i);return s.withOptions=i=>(...a)=>o(i,...a),s}var hw=De(Pe(),1);var Gt=De(Pe(),1),yw=De(Pe(),1),xw=De(Pe(),1),EN=({authData:t})=>{if(t.byteLength<37)return{invalidAuthData:null};if(t.byteLength<53)return{invalidAuthData:null};let e=t.slice(37,53),r=TN({bytes:e});return"aaguid"in r?{aaguidBytes:e,aaguidText:r.aaguid}:{unknownProvider:null}},TN=({bytes:t})=>{if(t.length!==16)return{invalidBytes:null};let e=(t instanceof Uint8Array?(0,pw.uint8ArrayToArrayOfNumber)(t):t).map(r=>r.toString(16).padStart(2,"0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5");return e==="00000000-0000-0000-0000-000000000000"?{unknownProvider:null}:{aaguid:e}};function ON(t){let e=new DataView(new ArrayBuffer(2)),r=t.slice(53,55);[...new Uint8Array(r)].forEach((o,s)=>e.setUint8(s,o));let n=e.getUint16(0);return t.slice(55+n)}function NN(t){return Bs(t,xc)}var vN=class{constructor(t){this._cose=t,this.#e=NN(t)}#e;toDer(){return this.#e}toRaw(){return new Uint8Array(this.#e)}},mw=class{#e;#t;constructor({rawId:t,cose:e}){this.#e=t,this.#t=new vN(e)}getPublicKey(){return this.#t}getCredentialId(){return this.#e}getCredentialIdText(){return(0,hw.uint8ArrayToBase64)(this.#e)}},IN=class extends mw{#e;#t;constructor({authData:t,...e}){super(e);let r=EN({authData:t});this.#e="aaguidText"in r?r.aaguidText:void 0,this.#t="aaguidBytes"in r?r.aaguidBytes:void 0}getAAGUID(){return this.#t}getAAGUIDText(){return this.#e}},RN=class extends mw{},SN=class extends Error{},AN=class extends Error{},BN=class extends Error{},CN=class extends Error{},PN=class extends Error{},DN=class extends Error{},FN=class extends Error{},uw=class extends Error{};var VN={ECDSA_WITH_SHA256:-7,RSA_WITH_SHA256:-257},UN=6e4,_w=()=>window.crypto.getRandomValues(new Uint8Array(16)),LN=()=>_w(),qN=()=>_w(),MN=()=>{let{location:{href:t}}=window,e=URL.parse(t);if((0,yw.isNullish)(e))throw new SN;let{hostname:r}=e;return r},bw=({appId:t})=>t?.id??MN(),kN=({appId:t,user:e}={})=>{let{document:{title:r}}=window,n=()=>({rp:{name:t?.name??r,id:bw({appId:t})}}),o=()=>({user:{id:qN(),name:e?.name??e?.displayName??r,displayName:e?.displayName??r}});return{attestation:"direct",challenge:LN(),...n(),...o(),pubKeyCredParams:Object.values(VN).map(s=>({type:"public-key",alg:s})),excludeCredentials:[],authenticatorSelection:{authenticatorAttachment:"platform",userVerification:"preferred",residentKey:"required",requireResidentKey:!0}}},jN=(t={})=>({rpId:bw(t),allowCredentials:[],userVerification:"required"}),q0=async({fn:t,step:e,onProgress:r})=>{r?.({step:e,state:"in_progress"});try{let n=await t();return r?.({step:e,state:"success"}),n}catch(n){throw r?.({step:e,state:"error"}),n}},$o=(t=>(t[t.RequestingUserCredential=0]="RequestingUserCredential",t[t.FinalizingCredential=1]="FinalizingCredential",t[t.Signing=2]="Signing",t))($o||{}),gw=({timeout:t})=>AbortSignal.timeout(t??UN),HN=async({challenge:t,credentialIds:e,passkeyOptions:r,timeout:n})=>await navigator.credentials.get({publicKey:{...jN(r),challenge:t.buffer,allowCredentials:(e??[]).map(o=>({id:o.buffer,type:"public-key"}))},signal:gw({timeout:n})}),dw=t=>{if(t.status!=="initialized")throw new AN},lw=t=>{if((0,Gt.isNullish)(t))throw new BN},fw=({type:t})=>{if(t!=="public-key")throw new CN},M0=class wc extends yn{#e;#t;constructor({onProgress:e,...r}){if(super(),this.#e=e,"retrievePublicKey"in r){let{retrievePublicKey:n}=r;this.#t={status:"pending",retrievePublicKey:n};return}this.#t=wc.#r({credential:new IN(r)})}static#r({credential:e}){return{status:"initialized",credential:e}}static async createWithNewCredential({passkeyOptions:e,timeout:r,...n}={}){let o=await navigator.credentials.create({publicKey:kN(e),signal:gw({timeout:r})});lw(o),fw(o);let{response:{attestationObject:s},rawId:i}=o;if((0,Gt.isNullish)(s))throw new PN;let{authData:a}=Bd.decode((0,Gt.arrayBufferToUint8Array)(s)),c=ON(a);return new wc({...n,rawId:(0,Gt.arrayBufferToUint8Array)(i),cose:c,authData:a})}static async createWithExistingCredential(e){return new wc(e)}getPublicKey(){dw(this.#t);let{credential:e}=this.#t;return e.getPublicKey()}getCredential(){dw(this.#t);let{credential:e}=this.#t;return e}async sign(e){let r=await q0({fn:async()=>{let n=await HN({challenge:e,...this.#t.status==="initialized"&&{credentialIds:[this.#t.credential.getCredentialId()]}});return lw(n),fw(n),n},step:0,onProgress:this.#e});return await q0({fn:async()=>{let{rawId:n}=r;if(this.#t.status==="initialized"){if(!(0,Gt.uint8ArraysEqual)({a:this.#t.credential.getCredentialId(),b:(0,Gt.arrayBufferToUint8Array)(n)}))throw new DN;return}let{retrievePublicKey:o}=this.#t,s=await o({credentialId:(0,Gt.arrayBufferToUint8Array)(n)});this.#t=wc.#r({credential:new RN({rawId:(0,Gt.arrayBufferToUint8Array)(n),cose:s})})},step:1,onProgress:this.#e}),await q0({fn:async()=>{let{response:n}=r,{clientDataJSON:o}=n,{authenticatorData:s,signature:i}="authenticatorData"in n&&"signature"in n?n:{};if((0,Gt.isNullish)(s))throw new uw;if((0,Gt.isNullish)(i))throw new uw;let a=Bd.encode({authenticator_data:s,client_data_json:new TextDecoder().decode(o),signature:(0,Gt.arrayBufferToUint8Array)(i)});if((0,Gt.isNullish)(a))throw new FN;return Object.assign(a,{__signature__:void 0}),a},step:2,onProgress:this.#e})}},$N=async()=>(0,xw.nonNullish)(window.PublicKeyCredential)&&"isUserVerifyingPlatformAuthenticatorAvailable"in PublicKeyCredential?await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():!1;var T1=De(Pe(),1);var Mi=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:r})=>r(e))}subscribe(e){let r=Symbol();return this.callbacks.push({id:r,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:n})=>n!==r)}};var Or=class t extends Mi{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let r=super.subscribe(e);return e(this.authUser),r}reset(){this.authUser=null,this.populate(this.authUser)}};var k0=({message:t,detail:e})=>{let r=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(r)};var E1=De(Pe(),1);var tl=De(Pe(),1);var el=De(Pe(),1);var j0=De(Pe(),1);var ki="http://127.0.0.1:5987",ww="rdmx6-jaaaa-aaaaa-aaadq-cai";var Ew=async({identity:t,container:e})=>{let n=(0,j0.nonNullish)(e)&&e!==!1?e===!0?ki:e:"https://icp-api.io",o=(0,j0.nonNullish)(e);return await Ps.create({identity:t,shouldFetchRootKey:o,host:n})};var ji=class t{static instance;#e=void 0;constructor(){}static getInstance(){return(0,el.isNullish)(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...r}){let n=e.getPrincipal().toText();if((0,el.isNullish)(this.#e)||(0,el.isNullish)(this.#e[n])){let o=await Ew({identity:e,...r});return this.#e={...this.#e??{},[n]:o},o}return this.#e[n]}reset(){this.#e=null}};var Hi=class t{static instance;#e=void 0;constructor(){}static getInstance(){return(0,tl.isNullish)(t.instance)&&(t.instance=new t),t.instance}async getActor({satelliteId:e,identity:r,actorKey:n,...o}){let s=`${n}#${r.getPrincipal().toText()}#${e};`;if((0,tl.isNullish)(this.#e)||(0,tl.isNullish)(this.#e[s])){let i=await this.createActor({satelliteId:e,identity:r,...o});return this.#e={...this.#e??{},[s]:i},i}return this.#e[s]}reset(){this.#e=null}async createActor({idlFactory:e,satelliteId:r,...n}){let o=await ji.getInstance().getAgent(n);return Qd.createActor(e,{agent:o,canisterId:r})}};var Tw=t=>(t.preventDefault(),t.returnValue="Are you sure you want to exit?"),KN=()=>{window.addEventListener("beforeunload",Tw,{capture:!0})},GN=()=>{window.removeEventListener("beforeunload",Tw,{capture:!0})},H0=async({fn:t})=>{try{return KN(),await t()}finally{GN()}};var Ls=De(Pe(),1);var ur=class t extends Mi{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}reset(){this.env=null}subscribe(e){let r=super.subscribe(e);return e(this.env),r}};var Ow=BigInt(144e11),Nw=!1,vw={width:576,height:576},Iw={width:424,height:576},Rw={width:505,height:705},Ec="internetcomputer.org",Sw="ic0.app",Aw="id.ai";var $0=De(Pe(),1);var rl=De(Pe(),1),Bw=async t=>{let e=new Blob([JSON.stringify(t,rl.jsonReplacer)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},nl=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),rl.jsonReviver)},ol=()=>typeof window<"u";var sl=({width:t,height:e})=>{if(!ol()||(0,$0.isNullish)(window)||(0,$0.isNullish)(window.top))return;let{top:{innerWidth:r,innerHeight:n}}=window,o=n/2+screenY-e/2,s=r/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${o}, left=${s}`};function Cw(t){return t!==null&&typeof t=="object"}var Tc=class t{static from(e){if(typeof e=="string"){let r=ht(e);return this.fromRaw(r)}else if(Cw(e)){let r=e;if(Cw(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(fn(n.buffer))}else{if(r instanceof ArrayBuffer)return this.fromRaw(fn(r));if("rawKey"in r&&r.rawKey instanceof Uint8Array)return this.fromRaw(r.rawKey);if("derKey"in r)return this.fromDer(r.derKey);if("toDer"in r)return this.fromDer(r.toDer())}}throw new Error("Cannot construct Ed25519PublicKey from the provided key.")}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){let r=Bs(e,As);return r.__derEncodedPublicKey__=void 0,r}static derDecode(e){let r=Cs(e,As);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes 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 new Error("An Ed25519 public key must be exactly 32bytes long");this.#e=e,this.#t=t.derEncode(e)}toDer(){return this.derKey}toRaw(){return this.rawKey}},$i=class t extends yn{static generate(e){if(e&&e.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");e||(e=Kt.utils.randomPrivateKey()),Tg(e,new Uint8Array(new Array(32).fill(0)))&&console.warn("Seed is all zeros. This is not a secure seed. Please provide a seed with sufficient entropy if this is a production environment.");let r=new Uint8Array(32);for(let o=0;o<32;o++)r[o]=e[o];let n=Kt.getPublicKey(r);return t.fromKeyPair(n,r)}static fromParsedJson(e){let[r,n]=e;return new t(Tc.fromDer(ht(r)),ht(n))}static fromJSON(e){let r=JSON.parse(e);if(Array.isArray(r)){if(typeof r[0]=="string"&&typeof r[1]=="string")return this.fromParsedJson([r[0],r[1]]);throw new Error("Deserialization error: JSON must have at least 2 items.")}throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(e)}`)}static fromKeyPair(e,r){return new t(Tc.fromRaw(e),r)}static fromSecretKey(e){let r=Kt.getPublicKey(e);return t.fromKeyPair(r,e)}#e;#t;constructor(e,r){super(),this.#e=Tc.from(e),this.#t=r}toJSON(){return[de(this.#e.toDer()),de(this.#t)]}getKeyPair(){return{secretKey:this.#t,publicKey:this.#e}}getPublicKey(){return this.#e}async sign(e){let r=Kt.sign(e,this.#t.slice(0,32));return Object.defineProperty(r,"__signature__",{enumerable:!1,value:void 0}),r}static verify(e,r,n){let[o,s,i]=[e,r,n].map(a=>(typeof a=="string"&&(a=ht(a)),fn(a)));return Kt.verify(o,s,i)}};var K0=class t extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,t.prototype)}};function Pw(t){if(typeof global<"u"&&global.crypto&&global.crypto.subtle)return global.crypto.subtle;if(t)return t;if(typeof crypto<"u"&&crypto.subtle)return crypto.subtle;throw new K0("Global crypto was not available and none was provided. Please inlcude a SubtleCrypto implementation. See https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto")}var Ds=class t extends yn{static async generate(e){let{extractable:r=!1,keyUsages:n=["sign","verify"],subtleCrypto:o}=e??{},s=Pw(o),i=await s.generateKey({name:"ECDSA",namedCurve:"P-256"},r,n),a=fn(await s.exportKey("spki",i.publicKey));return Object.assign(a,{__derEncodedPublicKey__:void 0}),new this(i,a,s)}static async fromKeyPair(e,r){let n=Pw(r),o=fn(await n.exportKey("spki",e.publicKey));return Object.assign(o,{__derEncodedPublicKey__:void 0}),new t(e,o,n)}constructor(e,r,n){super(),this._keyPair=e,this._derKey=r,this._subtleCrypto=n}getKeyPair(){return this._keyPair}getPublicKey(){let e=this._derKey,r=Object.create(this._keyPair.publicKey);return r.toDer=function(){return e},r}async sign(e){let r={name:"ECDSA",hash:{name:"SHA-256"}},n=fn(await this._subtleCrypto.sign(r,this._keyPair.privateKey,e));return Object.assign(n,{__signature__:void 0}),n}};var il=class{#e;get rawKey(){return this.#e.rawKey}get derKey(){return this.#e.derKey}toDer(){return this.#e.toDer()}getPublicKey(){return this.#e}getPrincipal(){if(!this.#e.rawKey)throw new Error("Cannot get principal from a public key without a raw key.");return oe.fromUint8Array(new Uint8Array(this.#e.rawKey))}transformRequest(){return Promise.reject("Not implemented. You are attempting to use a partial identity to sign calls, but this identity only has access to the public key.To sign calls, use a DelegationIdentity instead.")}constructor(e){this.#e=e}};function G0(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return ht(t)}var Ki=class{constructor(e,r,n){this.pubkey=e,this.expiration=r,this.targets=n}toCborValue(){return{pubkey:this.pubkey,expiration:this.expiration,...this.targets&&{targets:this.targets}}}toJSON(){return{expiration:this.expiration.toString(16),pubkey:de(this.pubkey),...this.targets&&{targets:this.targets.map(e=>e.toHex())}}}};async function zN(t,e,r,n){let o=new Ki(e.toDer(),BigInt(+r)*BigInt(1e6),n),s=new Uint8Array([...$h,...new Uint8Array(Zn({...o}))]),i=await t.sign(s);return{delegation:o,signature:i}}var Fs=class t{static async create(e,r,n=new Date(Date.now()+900*1e3),o={}){let s=await zN(e,r,n,o.targets);return new t([...o.previous?.delegations||[],s],o.previous?.publicKey||e.getPublicKey().toDer())}static fromJSON(e){let{publicKey:r,delegations:n}=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(n))throw new Error("Invalid delegations.");let o=n.map(s=>{let{delegation:i,signature:a}=s,{pubkey:c,expiration:d,targets:p}=i;if(p!==void 0&&!Array.isArray(p))throw new Error("Invalid targets.");return{delegation:new Ki(G0(c),BigInt("0x"+d),p&&p.map(l=>{if(typeof l!="string")throw new Error("Invalid target.");return oe.fromHex(l)})),signature:G0(a)}});return new this(o,G0(r))}static fromDelegations(e,r){return new this(e,r)}constructor(e,r){this.delegations=e,this.publicKey=r}toJSON(){return{delegations:this.delegations.map(e=>{let{delegation:r,signature:n}=e,{targets:o}=r;return{delegation:{expiration:r.expiration.toString(16),pubkey:de(r.pubkey),...o&&{targets:o.map(s=>s.toHex())}},signature:de(n)}}),publicKey:de(this.publicKey)}}},Vs=class extends yn{static fromDelegation(e,r){return new this(e,r)}constructor(e,r){super(),this._inner=e,this._delegation=r}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(e){return this._inner.sign(e)}async transformRequest(e){let{body:r,...n}=e,o=await Zn(r);return{...n,body:{content:r,sender_sig:await this.sign(new Uint8Array([...ec,...new Uint8Array(o)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}}}},Oc=class t extends il{#e;get delegation(){return this.#e}constructor(e,r){super(e),this.#e=r}static fromDelegation(e,r){return new t(e,r)}};function z0(t,e){for(let{delegation:o}of t.delegations)if(+new Date(Number(o.expiration/BigInt(1e6)))<=+Date.now())return!1;let r=[],n=e?.scope;n&&(Array.isArray(n)?r.push(...n.map(o=>typeof o=="string"?oe.fromText(o):o)):r.push(typeof n=="string"?oe.fromText(n):n));for(let o of r){let s=o.toText();for(let{delegation:i}of t.delegations){if(i.targets===void 0)continue;let a=!0;for(let c of i.targets)if(c.toText()===s){a=!1;break}if(a)return!1}}return!0}var Dw=["mousedown","mousemove","keydown","touchstart","wheel"],Nc=class{callbacks=[];idleTimeout=600*1e3;timeoutID=void 0;static create(e={}){return new this(e)}constructor(e={}){let{onIdle:r,idleTimeout:n=600*1e3}=e||{};this.callbacks=r?[r]:[],this.idleTimeout=n;let o=this._resetTimer.bind(this);window.addEventListener("load",o,!0),Dw.forEach(function(i){document.addEventListener(i,o,!0)});let s=(i,a)=>{let c;return(...d)=>{let p=this,l=function(){c=void 0,i.apply(p,d)};clearTimeout(c),c=window.setTimeout(l,a)}};if(e?.captureScroll){let i=s(o,e?.scrollDebounce??100);window.addEventListener("scroll",i,!0)}o()}registerCallback(e){this.callbacks.push(e)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let e=this._resetTimer.bind(this);Dw.forEach(function(r){document.removeEventListener(r,e,!0)}),this.callbacks.forEach(r=>r())}_resetTimer(){let e=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(e,this.idleTimeout)}};var ZN=(t,e)=>e.some(r=>t instanceof r),Fw,Vw;function YN(){return Fw||(Fw=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function WN(){return Vw||(Vw=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var Uw=new WeakMap,Y0=new WeakMap,Lw=new WeakMap,Z0=new WeakMap,X0=new WeakMap;function XN(t){let e=new Promise((r,n)=>{let o=()=>{t.removeEventListener("success",s),t.removeEventListener("error",i)},s=()=>{r(bn(t.result)),o()},i=()=>{n(t.error),o()};t.addEventListener("success",s),t.addEventListener("error",i)});return e.then(r=>{r instanceof IDBCursor&&Uw.set(r,t)}).catch(()=>{}),X0.set(e,t),e}function JN(t){if(Y0.has(t))return;let e=new Promise((r,n)=>{let o=()=>{t.removeEventListener("complete",s),t.removeEventListener("error",i),t.removeEventListener("abort",i)},s=()=>{r(),o()},i=()=>{n(t.error||new DOMException("AbortError","AbortError")),o()};t.addEventListener("complete",s),t.addEventListener("error",i),t.addEventListener("abort",i)});Y0.set(t,e)}var W0={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return Y0.get(t);if(e==="objectStoreNames")return t.objectStoreNames||Lw.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return bn(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function qw(t){W0=t(W0)}function QN(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(al(this),e,...r);return Lw.set(n,e.sort?e.sort():[e]),bn(n)}:WN().includes(t)?function(...e){return t.apply(al(this),e),bn(Uw.get(this))}:function(...e){return bn(t.apply(al(this),e))}}function ev(t){return typeof t=="function"?QN(t):(t instanceof IDBTransaction&&JN(t),ZN(t,YN())?new Proxy(t,W0):t)}function bn(t){if(t instanceof IDBRequest)return XN(t);if(Z0.has(t))return Z0.get(t);let e=ev(t);return e!==t&&(Z0.set(t,e),X0.set(e,t)),e}var al=t=>X0.get(t);function kw(t,e,{blocked:r,upgrade:n,blocking:o,terminated:s}={}){let i=indexedDB.open(t,e),a=bn(i);return n&&i.addEventListener("upgradeneeded",c=>{n(bn(i.result),c.oldVersion,c.newVersion,bn(i.transaction),c)}),r&&i.addEventListener("blocked",c=>r(c.oldVersion,c.newVersion,c)),a.then(c=>{s&&c.addEventListener("close",()=>s()),o&&c.addEventListener("versionchange",d=>o(d.oldVersion,d.newVersion,d))}).catch(()=>{}),a}var tv=["get","getKey","getAll","getAllKeys","count"],rv=["put","add","delete","clear"],J0=new Map;function Mw(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(J0.get(e))return J0.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,o=rv.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(o||tv.includes(r)))return;let s=async function(i,...a){let c=this.transaction(i,o?"readwrite":"readonly"),d=c.store;return n&&(d=d.index(a.shift())),(await Promise.all([d[r](...a),o&&c.done]))[0]};return J0.set(e,s),s}qw(t=>({...t,get:(e,r,n)=>Mw(e,r)||t.get(e,r,n),has:(e,r)=>!!Mw(e,r)||t.has(e,r)}));var jw="auth-client-db",Hw="ic-keyval",nv=async(t=jw,e=Hw,r)=>(cl&&localStorage?.getItem(dr)&&(localStorage.removeItem(dr),localStorage.removeItem(zt)),await kw(t,r,{upgrade:n=>{n.objectStoreNames.contains(e)&&n.clear(e),n.createObjectStore(e)}}));async function ov(t,e,r){return await t.get(e,r)}async function sv(t,e,r,n){return await t.put(e,n,r)}async function iv(t,e,r){return await t.delete(e,r)}var vc=class t{_db;_storeName;static async create(e){let{dbName:r=jw,storeName:n=Hw,version:o=$w}=e??{},s=await nv(r,n,o);return new t(s,n)}constructor(e,r){this._db=e,this._storeName=r}async set(e,r){return await sv(this._db,this._storeName,e,r)}async get(e){return await ov(this._db,this._storeName,e)??null}async remove(e){return await iv(this._db,this._storeName,e)}};var zt="identity",dr="delegation",Kw="iv",$w=1,cl=typeof window<"u",Ic=class{prefix;_localStorage;constructor(e="ic-",r){this.prefix=e,this._localStorage=r}get(e){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+e))}set(e,r){return this._getLocalStorage().setItem(this.prefix+e,r),Promise.resolve()}remove(e){return this._getLocalStorage().removeItem(this.prefix+e),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let e=typeof window>"u"?typeof global>"u"?typeof self>"u"?void 0:self.localStorage:global.localStorage:window.localStorage;if(!e)throw new Error("Could not find local storage.");return e}},so=class{#e;constructor(e){this.#e=e??{}}initializedDb;get _db(){return new Promise(e=>{if(this.initializedDb){e(this.initializedDb);return}vc.create(this.#e).then(r=>{this.initializedDb=r,e(r)})})}async get(e){return await(await this._db).get(e)}async set(e,r){await(await this._db).set(e,r)}async remove(e){await(await this._db).remove(e)}};var av=BigInt(1e9),cv=BigInt(3600),uv=av*cv,dv="https://identity.internetcomputer.org",lv="#authorize",fv=BigInt(8)*uv,Q0="ECDSA",em="Ed25519",pv=500,rm="UserInterrupt",ul=class{_identity;_key;_chain;_storage;idleManager;_createOptions;_idpWindow;_eventHandler;static async create(e={}){let r=e.storage??new so,n=e.keyType??Q0,o=null;if(e.identity)o=e.identity;else{let c=await r.get(zt);if(!c&&cl)try{let d=new Ic,p=await d.get(dr),l=await d.get(zt);p&&l&&n===Q0&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await r.set(dr,p),await r.set(zt,l),c=p,await d.remove(dr),await d.remove(zt))}catch(d){console.error("error while attempting to recover localstorage: "+d)}if(c)try{typeof c=="object"?n===em&&typeof c=="string"?o=$i.fromJSON(c):o=await Ds.fromKeyPair(c):typeof c=="string"&&(o=$i.fromJSON(c))}catch{}}let s=new gr,i=null;if(o)try{let c=await r.get(dr);if(typeof c=="object"&&c!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?s=e.identity:c&&(i=Fs.fromJSON(c),z0(i)?"toDer"in o?s=Oc.fromDelegation(o,i):s=Vs.fromDelegation(o,i):(await tm(r),o=null))}catch(c){console.error(c),await tm(r),o=null}let a;return e.idleOptions?.disableIdle?a=void 0:(i||e.identity)&&(a=Nc.create(e.idleOptions)),o||(n===em?(o=$i.generate(),await r.set(zt,JSON.stringify(o.toJSON()))):(e.storage&&n===Q0&&console.warn(`You are using a custom storage provider that may not support CryptoKey storage. If you are using a custom storage provider that does not support CryptoKey storage, you should use '${em}' as the key type, as it can serialize to a string`),o=await Ds.generate(),await r.set(zt,o.getKeyPair()))),new this(s,o,i,r,a,e)}constructor(e,r,n,o,s,i,a,c){this._identity=e,this._key=r,this._chain=n,this._storage=o,this.idleManager=s,this._createOptions=i,this._idpWindow=a,this._eventHandler=c,this._registerDefaultIdleCallback()}_registerDefaultIdleCallback(){let e=this._createOptions?.idleOptions;!e?.onIdle&&!e?.disableDefaultIdleCallback&&this.idleManager?.registerCallback(()=>{this.logout(),location.reload()})}async _handleSuccess(e,r){let n=e.delegations.map(a=>({delegation:new Ki(a.delegation.pubkey,a.delegation.expiration,a.delegation.targets),signature:a.signature})),o=Fs.fromDelegations(n,e.userPublicKey),s=this._key;if(!s)return;this._chain=o,"toDer"in s?this._identity=Oc.fromDelegation(s,this._chain):this._identity=Vs.fromDelegation(s,this._chain),this._idpWindow?.close();let i=this._createOptions?.idleOptions;!this.idleManager&&!i?.disableIdle&&(this.idleManager=Nc.create(i),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(dr,JSON.stringify(this._chain.toJSON())),r?.(e)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null&&z0(this._chain)}async login(e){let r=hv(this._createOptions?.loginOptions,e),n=r?.maxTimeToLive??fv,o=new URL(r?.identityProvider?.toString()||dv);o.hash=lv,this._idpWindow?.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(o,{maxTimeToLive:n,...r}),window.addEventListener("message",this._eventHandler),this._idpWindow=window.open(o.toString(),"idpWindow",r?.windowOpenerFeatures)??void 0;let s=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(rm,r?.onError):setTimeout(s,pv))};s()}_getEventHandler(e,r){return async n=>{if(n.origin!==e.origin)return;let o=n.data;switch(o.kind){case"authorize-ready":{let s={kind:"authorize-client",sessionPublicKey:new Uint8Array(this._key?.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,allowPinAuthentication:r?.allowPinAuthentication,derivationOrigin:r?.derivationOrigin?.toString(),...r?.customValues};this._idpWindow?.postMessage(s,e.origin);break}case"authorize-client-success":try{await this._handleSuccess(o,r?.onSuccess)}catch(s){this._handleFailure(s.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(o.text,r?.onError);break;default:break}}}_handleFailure(e,r){this._idpWindow?.close(),r?.(e),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(e={}){if(await tm(this._storage),this._identity=new gr,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function tm(t){await t.remove(zt),await t.remove(dr),await t.remove(Kw)}function hv(t,e){if(!t&&!e)return;let r=t?.customValues||e?.customValues?{...t?.customValues,...e?.customValues}:void 0;return{...t,...e,customValues:r}}var zw=De(Pe(),1);var gn=async({fn:t,step:e,onProgress:r})=>{r?.({step:e,state:"in_progress"});try{let n=await t();return r?.({step:e,state:"success"}),n}catch(n){throw r?.({step:e,state:"error"}),n}};var Gw=(r=>(r[r.AuthorizingWithProvider=0]="AuthorizingWithProvider",r[r.CreatingOrRetrievingUser=1]="CreatingOrRetrievingUser",r))(Gw||{});var dl=class extends Error{},Us=class extends Error{},ll=class extends Error{},fl=class extends Error{},pl=class extends Error{},hl=class extends Error{},ml=class extends Error{},yl=class extends Error{};var Gi=class{async signIn({options:e,authClient:r,initAuth:n}){await gn({fn:async()=>await this.#e({options:e,authClient:r}),step:0,onProgress:e?.onProgress}),await gn({fn:async()=>await n({provider:this.id}),step:1,onProgress:e?.onProgress})}#e({options:e,authClient:r}){return new Promise(async(n,o)=>{if((0,zw.isNullish)(r)){o(new Us("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}await r.login({onSuccess:n,onError:s=>{if(s===rm){o(new ll(s));return}o(new dl(s))},maxTimeToLive:e?.maxTimeToLiveInNanoseconds??Ow,allowPinAuthentication:e?.allowPin??Nw,...e?.derivationOrigin!==void 0&&{derivationOrigin:e.derivationOrigin},...this.signInOptions({windowed:e?.windowed})})})}};var _l=class extends Gi{#e;constructor({domain:e}){super(),this.#e=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let n=(()=>{let s=ur.getInstance().get()?.container;if((0,Ls.isNullish)(s)||s===!1){let p=[Ec,Sw].includes(this.#e??Ec);return(0,Ls.isEmptyString)(this.#e)?`https://identity.${Ec}`:p?`https://identity.${this.#e??Ec}`:`https://${this.#e}`}let i=ur.getInstance().get(),a=(0,Ls.nonNullish)(i)&&(0,Ls.nonNullish)(i?.internetIdentityId)?i.internetIdentityId:ww,{host:c,protocol:d}=new URL(s===!0?ki:s);return/apple/i.test(navigator?.vendor)?`${d}//${c}?canisterId=${a}`:`${d}//${a}.${c.replace("127.0.0.1","localhost")}`})(),o=URL.parse(n)?.hostname?.includes(Aw)===!0;return{...e!==!1&&{windowOpenerFeatures:sl(o?Iw:vw)},identityProvider:n}}};var bl=class extends Gi{#e;#t;constructor({appName:e,logoUrl:r}){super(),this.#e=e,this.#t=r}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:sl(Rw)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#e)}&applicationLogo=${encodeURI(this.#t)}`}}};var zi=De(Pe(),1);var xn={certified:!1};var Zw=De(Pe(),1);var Ye=t=>(0,Zw.nonNullish)(t)?t:gl()??new gr;var jr=De(Pe(),1);var Jw=De(Pe(),1);var mv=De(Pe(),1),yv=De(Pe(),1);var Yw=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),r=t.Record({sha256:t.Vec(t.Nat8),proposal_id:t.Nat}),n=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),o=t.Record({field:n,desc:t.Bool}),s=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),i=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(s),description:t.Opt(t.Text),created_at:t.Opt(s)}),a=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),c=t.Record({order:t.Opt(o),owner:t.Opt(t.Principal),matcher:t.Opt(i),paginate:t.Opt(a)}),d=t.Record({controllers:t.Vec(t.Principal)}),p=t.Variant({Write:t.Null,Admin:t.Null,Submit:t.Null}),l=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:p,expires_at:t.Opt(t.Nat64)}),u=t.Record({version:t.Opt(t.Nat64)}),f=t.Variant({Db:t.Null,Storage:t.Null}),h=t.Record({version:t.Opt(t.Nat64)}),m=t.Record({proposal_ids:t.Vec(t.Nat)}),b=t.Record({cycles:t.Nat,destination_id:t.Principal}),y=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),x=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),_=t.Record({key:y,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,x)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),T=t.Record({derivation_origin:t.Opt(t.Text),external_alternative_origins:t.Opt(t.Vec(t.Text))}),N=t.Record({allowed_callers:t.Vec(t.Principal)}),I=t.Record({updated_at:t.Opt(t.Nat64),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),internet_identity:t.Opt(T),rules:t.Opt(N)}),v=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),A=t.Record({updated_at:t.Opt(t.Nat64),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),max_memory_size:t.Opt(v)}),E=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),S=t.Variant({Deny:t.Null,Allow:t.Null}),V=t.Record({status_code:t.Nat16,location:t.Text}),C=t.Record({iframe:t.Opt(E),updated_at:t.Opt(t.Nat64),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),max_memory_size:t.Opt(v),raw_access:t.Opt(S),redirects:t.Opt(t.Vec(t.Tuple(t.Text,V)))}),g=t.Record({db:t.Opt(A),authentication:t.Opt(I),storage:C}),w=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),O=t.Variant({Initialized:t.Null,Failed:t.Null,Open:t.Null,Rejected:t.Null,Executed:t.Null,Accepted:t.Null}),P=t.Record({clear_existing_assets:t.Opt(t.Bool)}),L=t.Record({orbiter:t.Opt(t.Text),mission_control_version:t.Opt(t.Text),satellite_version:t.Opt(t.Text)}),R=t.Variant({AssetsUpgrade:P,SegmentsDeployment:L}),B=t.Record({status:O,updated_at:t.Nat64,sha256:t.Opt(t.Vec(t.Nat8)),executed_at:t.Opt(t.Nat64),owner:t.Principal,created_at:t.Nat64,version:t.Opt(t.Nat64),proposal_type:R}),F=t.Variant({Heap:t.Null,Stable:t.Null}),U=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),q=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),H=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(F),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:U,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(q),write:U,max_changes_per_user:t.Opt(t.Nat32)}),Y=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),G=t.Record({memory:F,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),ie=t.Variant({Callback:t.Record({token:G,callback:t.Func([],[],["query"])})}),ae=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(ie),status_code:t.Nat16}),Ce=t.Record({token:t.Opt(G),body:t.Vec(t.Nat8)}),ee=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),ce=t.Record({batch_id:t.Nat}),lr=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,_)),items_length:t.Nat64}),vr=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),fr=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,w)),items_length:t.Nat64}),wn=t.Record({desc:t.Bool}),io=t.Record({start_after:t.Opt(t.Nat),limit:t.Opt(t.Nat)}),Yi=t.Record({order:t.Opt(wn),paginate:t.Opt(io)}),Wi=t.Record({proposal_id:t.Nat}),Ms=t.Record({matches_length:t.Nat64,items:t.Vec(t.Tuple(Wi,B)),items_length:t.Nat64}),ks=t.Record({include_system:t.Bool}),Xi=t.Record({matcher:t.Opt(ks)}),D=t.Record({matches_length:t.Nat64,items:t.Vec(t.Tuple(t.Text,H)),items_length:t.Nat64}),j=t.Record({stable:t.Nat64,heap:t.Nat64}),se=t.Record({version:t.Opt(t.Nat64),internet_identity:t.Opt(T),rules:t.Opt(N)}),Tt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:p,expires_at:t.Opt(t.Nat64)}),Ot=t.Record({controller:Tt,controllers:t.Vec(t.Principal)}),bt=t.Record({version:t.Opt(t.Nat64),max_memory_size:t.Opt(v)}),Hr=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),En=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(F),max_size:t.Opt(t.Nat),read:U,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(q),write:U,max_changes_per_user:t.Opt(t.Nat32)}),js=t.Record({iframe:t.Opt(E),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),version:t.Opt(t.Nat64),max_memory_size:t.Opt(v),raw_access:t.Opt(S),redirects:t.Opt(t.Vec(t.Tuple(t.Text,V)))}),Ji=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Qi=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([e],[],[]),commit_proposal:t.Func([r],[t.Null],[]),commit_proposal_asset_upload:t.Func([e],[],[]),commit_proposal_many_assets_upload:t.Func([t.Vec(e)],[],[]),count_assets:t.Func([t.Text,c],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,c],[t.Nat64],["query"]),count_proposals:t.Func([],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([d],[t.Vec(t.Tuple(t.Principal,l))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,u],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,c],[],[]),del_filtered_docs:t.Func([t.Text,c],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,u))],[],[]),del_rule:t.Func([f,t.Text,h],[],[]),delete_proposal_assets:t.Func([m],[],[]),deposit_cycles:t.Func([b],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(_)],["query"]),get_auth_config:t.Func([],[t.Opt(I)],["query"]),get_config:t.Func([],[g],[]),get_db_config:t.Func([],[t.Opt(A)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(w)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(_)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(w)))],["query"]),get_proposal:t.Func([t.Nat],[t.Opt(B)],["query"]),get_rule:t.Func([f,t.Text],[t.Opt(H)],["query"]),get_storage_config:t.Func([],[C],["query"]),http_request:t.Func([Y],[ae],["query"]),http_request_streaming_callback:t.Func([G],[Ce],["query"]),init_asset_upload:t.Func([ee],[ce],[]),init_proposal:t.Func([R],[t.Nat,B],[]),init_proposal_asset_upload:t.Func([ee,t.Nat],[ce],[]),init_proposal_many_assets_upload:t.Func([t.Vec(ee),t.Nat],[t.Vec(t.Tuple(t.Text,ce))],[]),list_assets:t.Func([t.Text,c],[lr],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,l))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,vr))],["query"]),list_docs:t.Func([t.Text,c],[fr],["query"]),list_proposals:t.Func([Yi],[Ms],["query"]),list_rules:t.Func([f,Xi],[D],["query"]),memory_size:t.Func([],[j],["query"]),reject_proposal:t.Func([r],[t.Null],[]),set_auth_config:t.Func([se],[I],[]),set_controllers:t.Func([Ot],[t.Vec(t.Tuple(t.Principal,l))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([bt],[A],[]),set_doc:t.Func([t.Text,t.Text,Hr],[w],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,Hr))],[t.Vec(t.Tuple(t.Text,w))],[]),set_rule:t.Func([f,t.Text,En],[H],[]),set_storage_config:t.Func([js],[C],[]),submit_proposal:t.Func([t.Nat],[t.Nat,B],[]),upload_asset_chunk:t.Func([Ji],[Qi],[]),upload_proposal_asset_chunk:t.Func([Ji],[Qi],[])})},Ww=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),r=t.Record({sha256:t.Vec(t.Nat8),proposal_id:t.Nat}),n=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),o=t.Record({field:n,desc:t.Bool}),s=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),i=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(s),description:t.Opt(t.Text),created_at:t.Opt(s)}),a=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),c=t.Record({order:t.Opt(o),owner:t.Opt(t.Principal),matcher:t.Opt(i),paginate:t.Opt(a)}),d=t.Record({controllers:t.Vec(t.Principal)}),p=t.Variant({Write:t.Null,Admin:t.Null,Submit:t.Null}),l=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:p,expires_at:t.Opt(t.Nat64)}),u=t.Record({version:t.Opt(t.Nat64)}),f=t.Variant({Db:t.Null,Storage:t.Null}),h=t.Record({version:t.Opt(t.Nat64)}),m=t.Record({proposal_ids:t.Vec(t.Nat)}),b=t.Record({cycles:t.Nat,destination_id:t.Principal}),y=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),x=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),_=t.Record({key:y,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,x)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),T=t.Record({derivation_origin:t.Opt(t.Text),external_alternative_origins:t.Opt(t.Vec(t.Text))}),N=t.Record({allowed_callers:t.Vec(t.Principal)}),I=t.Record({updated_at:t.Opt(t.Nat64),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),internet_identity:t.Opt(T),rules:t.Opt(N)}),v=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),A=t.Record({updated_at:t.Opt(t.Nat64),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),max_memory_size:t.Opt(v)}),E=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),S=t.Variant({Deny:t.Null,Allow:t.Null}),V=t.Record({status_code:t.Nat16,location:t.Text}),C=t.Record({iframe:t.Opt(E),updated_at:t.Opt(t.Nat64),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),max_memory_size:t.Opt(v),raw_access:t.Opt(S),redirects:t.Opt(t.Vec(t.Tuple(t.Text,V)))}),g=t.Record({db:t.Opt(A),authentication:t.Opt(I),storage:C}),w=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),O=t.Variant({Initialized:t.Null,Failed:t.Null,Open:t.Null,Rejected:t.Null,Executed:t.Null,Accepted:t.Null}),P=t.Record({clear_existing_assets:t.Opt(t.Bool)}),L=t.Record({orbiter:t.Opt(t.Text),mission_control_version:t.Opt(t.Text),satellite_version:t.Opt(t.Text)}),R=t.Variant({AssetsUpgrade:P,SegmentsDeployment:L}),B=t.Record({status:O,updated_at:t.Nat64,sha256:t.Opt(t.Vec(t.Nat8)),executed_at:t.Opt(t.Nat64),owner:t.Principal,created_at:t.Nat64,version:t.Opt(t.Nat64),proposal_type:R}),F=t.Variant({Heap:t.Null,Stable:t.Null}),U=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),q=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),H=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(F),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:U,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(q),write:U,max_changes_per_user:t.Opt(t.Nat32)}),Y=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),G=t.Record({memory:F,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),ie=t.Variant({Callback:t.Record({token:G,callback:t.Func([],[],[])})}),ae=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(ie),status_code:t.Nat16}),Ce=t.Record({token:t.Opt(G),body:t.Vec(t.Nat8)}),ee=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),ce=t.Record({batch_id:t.Nat}),lr=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,_)),items_length:t.Nat64}),vr=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),fr=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,w)),items_length:t.Nat64}),wn=t.Record({desc:t.Bool}),io=t.Record({start_after:t.Opt(t.Nat),limit:t.Opt(t.Nat)}),Yi=t.Record({order:t.Opt(wn),paginate:t.Opt(io)}),Wi=t.Record({proposal_id:t.Nat}),Ms=t.Record({matches_length:t.Nat64,items:t.Vec(t.Tuple(Wi,B)),items_length:t.Nat64}),ks=t.Record({include_system:t.Bool}),Xi=t.Record({matcher:t.Opt(ks)}),D=t.Record({matches_length:t.Nat64,items:t.Vec(t.Tuple(t.Text,H)),items_length:t.Nat64}),j=t.Record({stable:t.Nat64,heap:t.Nat64}),se=t.Record({version:t.Opt(t.Nat64),internet_identity:t.Opt(T),rules:t.Opt(N)}),Tt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:p,expires_at:t.Opt(t.Nat64)}),Ot=t.Record({controller:Tt,controllers:t.Vec(t.Principal)}),bt=t.Record({version:t.Opt(t.Nat64),max_memory_size:t.Opt(v)}),Hr=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),En=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(F),max_size:t.Opt(t.Nat),read:U,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(q),write:U,max_changes_per_user:t.Opt(t.Nat32)}),js=t.Record({iframe:t.Opt(E),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),version:t.Opt(t.Nat64),max_memory_size:t.Opt(v),raw_access:t.Opt(S),redirects:t.Opt(t.Vec(t.Tuple(t.Text,V)))}),Ji=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Qi=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([e],[],[]),commit_proposal:t.Func([r],[t.Null],[]),commit_proposal_asset_upload:t.Func([e],[],[]),commit_proposal_many_assets_upload:t.Func([t.Vec(e)],[],[]),count_assets:t.Func([t.Text,c],[t.Nat64],[]),count_collection_assets:t.Func([t.Text],[t.Nat64],[]),count_collection_docs:t.Func([t.Text],[t.Nat64],[]),count_docs:t.Func([t.Text,c],[t.Nat64],[]),count_proposals:t.Func([],[t.Nat64],[]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([d],[t.Vec(t.Tuple(t.Principal,l))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,u],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,c],[],[]),del_filtered_docs:t.Func([t.Text,c],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,u))],[],[]),del_rule:t.Func([f,t.Text,h],[],[]),delete_proposal_assets:t.Func([m],[],[]),deposit_cycles:t.Func([b],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(_)],[]),get_auth_config:t.Func([],[t.Opt(I)],[]),get_config:t.Func([],[g],[]),get_db_config:t.Func([],[t.Opt(A)],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(w)],[]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(_)))],[]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(w)))],[]),get_proposal:t.Func([t.Nat],[t.Opt(B)],[]),get_rule:t.Func([f,t.Text],[t.Opt(H)],[]),get_storage_config:t.Func([],[C],[]),http_request:t.Func([Y],[ae],[]),http_request_streaming_callback:t.Func([G],[Ce],[]),init_asset_upload:t.Func([ee],[ce],[]),init_proposal:t.Func([R],[t.Nat,B],[]),init_proposal_asset_upload:t.Func([ee,t.Nat],[ce],[]),init_proposal_many_assets_upload:t.Func([t.Vec(ee),t.Nat],[t.Vec(t.Tuple(t.Text,ce))],[]),list_assets:t.Func([t.Text,c],[lr],[]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,l))],[]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,vr))],[]),list_docs:t.Func([t.Text,c],[fr],[]),list_proposals:t.Func([Yi],[Ms],[]),list_rules:t.Func([f,Xi],[D],[]),memory_size:t.Func([],[j],[]),reject_proposal:t.Func([r],[t.Null],[]),set_auth_config:t.Func([se],[I],[]),set_controllers:t.Func([Ot],[t.Vec(t.Tuple(t.Principal,l))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([bt],[A],[]),set_doc:t.Func([t.Text,t.Text,Hr],[w],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,Hr))],[t.Vec(t.Tuple(t.Text,w))],[]),set_rule:t.Func([f,t.Text,En],[H],[]),set_storage_config:t.Func([js],[C],[]),submit_proposal:t.Func([t.Nat],[t.Nat,B],[]),upload_asset_chunk:t.Func([Ji],[Qi],[]),upload_proposal_asset_chunk:t.Func([Ji],[Qi],[])})};var xl=De(Pe(),1);var Xw=({satelliteId:t,container:e})=>{let{satelliteId:r}=nm({satelliteId:t}),{container:n}=om({container:e});if((0,xl.nonNullish)(n)&&n!==!1){let{host:o,protocol:s}=new URL(n===!0?ki:n);return`${s}//${r??"unknown"}.${o.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},nm=({satelliteId:t})=>(0,xl.nonNullish)(t)?{satelliteId:t}:ur.getInstance().get()??{satelliteId:void 0},om=({container:t})=>(0,xl.nonNullish)(t)?{container:t}:ur.getInstance().get()??{container:void 0};var ut=({satellite:t,options:{certified:e}})=>e1({idlFactory:e?Ww:Yw,actorKey:`stock#${e?"update":"query"}`,...t}),Qw=({idlFactory:t,...e})=>e1({idlFactory:t,actorKey:"extended#query",...e}),e1=async({satelliteId:t,container:e,...r})=>{let{satelliteId:n}=nm({satelliteId:t});(0,Jw.assertNonNullish)(n,"No satellite ID defined. Did you initialize Juno?");let{container:o}=om({container:e});return await Hi.getInstance().getActor({satelliteId:n,container:o,...r})};var nt=De(Pe(),1);var t1=t=>{if((0,nt.isNullish)(t))return(0,nt.toNullable)();switch(t.matcher){case"equal":return(0,nt.toNullable)({Equal:t.timestamp});case"greaterThan":return(0,nt.toNullable)({GreaterThan:t.timestamp});case"lessThan":return(0,nt.toNullable)({LessThan:t.timestamp});case"between":return(0,nt.toNullable)({Between:[t.timestamps.start,t.timestamps.end]});default:throw new yl("Invalid list matcher for timestamp",t)}},Ko=({matcher:t,paginate:e,order:r,owner:n})=>({matcher:(0,nt.isNullish)(t)?[]:[{key:(0,nt.toNullable)(t.key),description:(0,nt.toNullable)(t.description),created_at:t1(t.createdAt),updated_at:t1(t.updatedAt)}],paginate:(0,nt.toNullable)((0,nt.isNullish)(e)?void 0:{start_after:(0,nt.toNullable)(e.startAfter),limit:(0,nt.toNullable)((0,nt.isNullish)(e.limit)?void 0:BigInt(e.limit))}),order:(0,nt.toNullable)((0,nt.isNullish)(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:(0,nt.toNullable)((0,nt.isNullish)(n)?void 0:typeof n=="string"?oe.fromText(n):n)});var r1=async({data:t})=>{try{return await nl(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var qs=De(Pe(),1);var sm=async t=>{let{data:e,version:r,description:n}=t;return{description:(0,qs.toNullable)(n),data:await Bw(e),version:(0,qs.toNullable)(r)}},im=t=>{let{version:e}=t;return{version:(0,qs.toNullable)(e)}},Rc=async({doc:t,key:e})=>{let{owner:r,version:n,description:o,data:s,...i}=t;return{key:e,description:(0,qs.fromNullable)(o),owner:r.toText(),data:await nl(s),version:(0,qs.fromNullable)(n),...i}};var n1=async({collection:t,key:e,...r})=>{let{get_doc:n}=await ut(r),o=(0,jr.fromNullable)(await n(t,e));if(!(0,jr.isNullish)(o))return Rc({doc:o,key:e})},o1=async({docs:t,...e})=>{let{get_many_docs:r}=await ut(e),n=t.map(({collection:i,key:a})=>[i,a]),o=await r(n),s=[];for(let[i,a]of o){let c=(0,jr.fromNullable)(a);s.push((0,jr.nonNullish)(c)?await Rc({key:i,doc:c}):void 0)}return s},s1=async({collection:t,doc:e,...r})=>{let{set_doc:n}=await ut(r),{key:o}=e,s=await sm(e),i=await n(t,o,s);return await Rc({key:o,doc:i})},i1=async({docs:t,...e})=>{let{set_many_docs:r}=await ut(e),n=[];for(let{collection:i,doc:a}of t){let{key:c}=a;n.push([i,c,await sm(a)])}let o=await r(n),s=[];for(let[i,a]of o)s.push(await Rc({key:i,doc:a}));return s},a1=async({collection:t,doc:e,...r})=>{let{del_doc:n}=await ut(r),{key:o}=e;return n(t,o,im(e))},c1=async({docs:t,...e})=>{let{del_many_docs:r}=await ut(e),n=t.map(({collection:o,doc:s})=>[o,s.key,im(s)]);await r(n)},u1=async({collection:t,filter:e,...r})=>{let{del_filtered_docs:n}=await ut(r);return n(t,Ko(e))},d1=async({collection:t,filter:e,...r})=>{let{list_docs:n}=await ut(r),{items:o,items_page:s,items_length:i,matches_length:a,matches_pages:c}=await n(t,Ko(e)),d=[];for(let[p,l]of o){let{data:u,owner:f,description:h,version:m,...b}=l;d.push({key:p,description:(0,jr.fromNullable)(h),owner:f.toText(),data:await r1({data:u}),version:(0,jr.fromNullable)(m),...b})}return{items:d,items_length:i,items_page:(0,jr.fromNullable)(s),matches_length:a,matches_pages:(0,jr.fromNullable)(c)}},l1=async({collection:t,filter:e,...r})=>{let{count_docs:n}=await ut(r);return n(t,Ko(e))};var wl=async({satellite:t,options:e,...r})=>{let n=Ye(t?.identity);return await n1({...r,satellite:{...t,identity:n},options:e??xn})},C7=async({satellite:t,options:e,...r})=>{let n=Ye(t?.identity);return await o1({...r,satellite:{...t,identity:n},options:e??xn})},f1=async({satellite:t,...e})=>{let r=Ye(t?.identity);return await s1({...e,satellite:{...t,identity:r},options:{certified:!0}})},p1=async({satellite:t,...e})=>{let r=Ye(t?.identity);return await i1({...e,satellite:{...t,identity:r},options:{certified:!0}})},P7=async({satellite:t,...e})=>{let r=Ye(t?.identity);return await a1({...e,satellite:{...t,identity:r},options:{certified:!0}})},D7=async({satellite:t,...e})=>{let r=Ye(t?.identity);return await c1({...e,satellite:{...t,identity:r},options:{certified:!0}})},F7=async({satellite:t,filter:e,...r})=>{let n=Ye(t?.identity);return await u1({...r,filter:e??{},satellite:{...t,identity:n},options:{certified:!0}})},V7=async({satellite:t,options:e,filter:r,...n})=>{let o=Ye(t?.identity);return await d1({...n,filter:r??{},satellite:{...t,identity:o},options:e??xn})},U7=async({satellite:t,options:e,filter:r,...n})=>{let o=Ye(t?.identity);return await l1({...n,filter:r??{},satellite:{...t,identity:o},options:e??xn})};var El=De(Pe(),1);var h1=async({delegationIdentity:t,passkeyIdentity:e,satelliteId:r})=>{let n=e.getCredential().getAAGUID(),[o,s]=await p1({docs:[{collection:"#user",doc:{key:t.getPrincipal().toText(),data:{provider:"webauthn",providerData:{webauthn:{...(0,El.nonNullish)(n)&&{aaguid:(0,El.uint8ArrayToArrayOfNumber)(n)}}}}}},{collection:"#user-webauthn",doc:{key:e.getCredential().getCredentialIdText(),data:{publicKey:e.getPublicKey().toRaw()}}}],satellite:{identity:t,satelliteId:r}});return o};var m1=(s=>(s[s.RequestingUserCredential=0]="RequestingUserCredential",s[s.FinalizingCredential=1]="FinalizingCredential",s[s.Signing=2]="Signing",s[s.FinalizingSession=3]="FinalizingSession",s[s.RetrievingUser=4]="RetrievingUser",s))(m1||{}),y1=(i=>(i[i.CreatingUserCredential=0]="CreatingUserCredential",i[i.ValidatingUserCredential=1]="ValidatingUserCredential",i[i.FinalizingCredential=2]="FinalizingCredential",i[i.Signing=3]="Signing",i[i.FinalizingSession=4]="FinalizingSession",i[i.RegisteringUser=5]="RegisteringUser",i))(y1||{});var Sc=class{get id(){return"webauthn"}async signUp({options:{onProgress:e,maxTimeToLiveInMilliseconds:r,passkey:n}={},loadAuthWithUser:o}){let{satelliteId:s}=ur.getInstance().get()??{satelliteId:void 0};if((0,zi.isNullish)(s))throw new Us("Satellite ID not set. Have you initialized the Satellite?");let i=({step:m,state:b})=>{switch(m){case $o.RequestingUserCredential:e?.({step:1,state:b});break;case $o.FinalizingCredential:e?.({step:2,state:b});break;case $o.Signing:e?.({step:3,state:b});break}},c=await gn({fn:async()=>await M0.createWithNewCredential({onProgress:i,passkeyOptions:n}),step:0,onProgress:e}),{delegationIdentity:d,sessionKey:p}=await this.#e({identity:c,maxTimeToLiveInMilliseconds:r}),u=await gn({fn:async()=>await h1({delegationIdentity:d,passkeyIdentity:c,satelliteId:s}),step:5,onProgress:e});await gn({fn:async()=>await this.#t({delegationIdentity:d,sessionKey:p}),step:4,onProgress:e}),await gn({fn:async()=>await o({user:u}),step:5,onProgress:e})}async signIn({options:{onProgress:e,maxTimeToLiveInMilliseconds:r}={},loadAuth:n}){let{satelliteId:o}=ur.getInstance().get()??{satelliteId:void 0};if((0,zi.isNullish)(o))throw new Us("Satellite ID not set. Have you initialized the Satellite?");let s=async({credentialId:l})=>{let u=await wl({collection:"#user-webauthn",key:(0,zi.uint8ArrayToBase64)(l),options:{certified:!0},satellite:{identity:new gr,satelliteId:o}});if((0,zi.isNullish)(u))throw new pl("No public key found for the selected passkey.");let{data:f}=u,{publicKey:h}=f;return Cs(h,xc)},i=({step:l,state:u})=>{switch(l){case $o.RequestingUserCredential:e?.({step:0,state:u});break;case $o.FinalizingCredential:e?.({step:1,state:u});break;case $o.Signing:e?.({step:2,state:u});break}},a=await M0.createWithExistingCredential({retrievePublicKey:s,onProgress:i}),{delegationIdentity:c,sessionKey:d}=await this.#e({identity:a,maxTimeToLiveInMilliseconds:r});await gn({fn:async()=>await this.#t({delegationIdentity:c,sessionKey:d}),step:3,onProgress:e}),await gn({fn:n,step:4,onProgress:e})}async#e({identity:e,maxTimeToLiveInMilliseconds:r}){let n=await Ds.generate({extractable:!1}),o=r??144e5,s=await Fs.create(e,n.getPublicKey(),new Date(Date.now()+o));return{delegationIdentity:Vs.fromDelegation(n,s),sessionKey:n}}async#t({sessionKey:e,delegationIdentity:r}){let n=new so;await Promise.all([n.set(zt,e.getKeyPair()),n.set(dr,JSON.stringify(r.getDelegation().toJSON()))])}};var Ac=()=>ul.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}}),_1=async()=>(await new so().remove(zt),await Ac());var Bc=De(Pe(),1);var am=({error:t,type:e})=>typeof t=="string"?t.includes(e):t instanceof Error?t.message.includes(e):!1;var b1="juno.datastore.error.user.cannot_update";var g1=async({provider:t})=>{let{user:e,userId:r}=await cm();if((0,Bc.nonNullish)(e))return e;try{return await bv({userId:r,provider:t})}catch(n){if(am({error:n,type:b1})){let o=await x1({userId:r});if((0,Bc.nonNullish)(o))return o}throw n}},cm=async()=>{let t=gl();if((0,Bc.isNullish)(t))throw new ml("No identity to initialize the user. Have you initialized Juno?");let e=t.getPrincipal().toText(),r=await x1({userId:e});return{userId:e,user:r}},x1=({userId:t})=>wl({collection:"#user",key:t}),bv=({userId:t,...e})=>f1({collection:"#user",doc:{key:t,data:e}});var Nr,um=async()=>{await dm({fn:async()=>{let{user:e}=await cm();Or.getInstance().set(e??null)}})},gv=async({user:t})=>{await dm({fn:async()=>{Or.getInstance().set(t)}})},w1=async({provider:t})=>{await dm({fn:async()=>{let r=await g1({provider:t});Or.getInstance().set(r)}})},dm=async({fn:t})=>{if(Nr=await Ac(),!await Nr.isAuthenticated()){Nr=await _1();return}await t()},xv=async t=>{let e=async()=>await Ev(t);if(Object.values(t)[0].context?.windowGuard===!1){await e();return}await H0({fn:e})},wv=async t=>{let e=async()=>await Tv(t);if(Object.values(t)?.[0].context?.windowGuard===!1){await e();return}await H0({fn:e})},Ev=async t=>{if("webauthn"in t){let{webauthn:{options:e}}=t;await new Sc().signIn({options:e,loadAuth:um});return}if("nfid"in t){let{nfid:{options:e}}=t,{appName:r,logoUrl:n,...o}=e??{};await new bl({appName:r,logoUrl:n}).signIn({options:o,authClient:Nr,initAuth:w1});return}if("internet_identity"in t){let{internet_identity:{options:e}}=t,{domain:r,...n}=e??{};await new _l({domain:r}).signIn({options:n,authClient:Nr,initAuth:w1});return}throw new fl("An unknown or unsupported provider was provided for sign-in.")},Tv=async t=>{if("webauthn"in t){let{webauthn:{options:e}}=t;await new Sc().signUp({options:e,loadAuthWithUser:gv});return}throw new hl("An unknown or unsupported provider was provided for sign-up.")},lm=async t=>{await Ov(),Nr=await Ac(),t?.windowReload!==!1&&window.location.reload()},Ov=async()=>{await Nr?.logout(),Nr=null,Or.getInstance().reset(),Hi.getInstance().reset(),ji.getInstance().reset()},gl=()=>Nr?.getIdentity(),Nv=async()=>(Nr??await Ac()).getIdentity(),vv=async()=>{let t=Or.getInstance().get();return(0,E1.isNullish)(t)||!(await Nr?.isAuthenticated()??!1)?null:Nr?.getIdentity()??null};var O1=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),n=async()=>{k0({message:"junoSignOutAuthTimer"}),await lm()};return r.onmessage=async({data:o})=>{let{msg:s,data:i}=o;switch(s){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":k0({message:"junoDelegationRemainingTime",detail:i?.authRemainingTime});return}},Or.getInstance().subscribe(o=>{if((0,T1.isNullish)(o)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var N1=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_SATELLITE_ID??t():t()},v1=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_CONTAINER??t():t()};var R9=async({idlFactory:t,satellite:e})=>{let r=Ye(e?.identity);return await Qw({idlFactory:t,...e,identity:r})};var Pc=De(Pe(),1);var Cc=De(Pe(),1);var Zi=De(Pe(),1);var I1=async({asset:{data:t,headers:e,...r},actor:n,progress:o})=>{let{init_asset_upload:s,upload_asset_chunk:i,commit_asset_upload:a}=n,{batch_id:c}=await s(Iv(r));o?.onInitiatedBatch();let{chunkIds:d}=await Av({data:t,uploadFn:i,batchId:c});o?.onUploadedFileChunks(r.fullPath),await Sv({commitFn:a,batchId:c,data:t,headers:e,chunkIds:d}),o?.onCommittedBatch()};var Iv=({filename:t,collection:e,token:r,fullPath:n,encoding:o,description:s})=>({collection:e,full_path:n,name:t,token:(0,Zi.toNullable)(r),encoding_type:(0,Zi.toNullable)(o),description:(0,Zi.toNullable)(s)}),Rv=({batchId:t,chunkIds:e,headers:r,data:n})=>{let o=r.find(([s,i])=>s.toLowerCase()==="content-type")===void 0&&n.type!==void 0&&n.type!==""?[["Content-Type",n.type]]:void 0;return{batch_id:t,chunk_ids:e.map(({chunk_id:s})=>s),headers:[...r,...o??[]]}},Sv=async({commitFn:t,...e})=>{let r=Rv(e);await t(r)},Av=async({data:t,uploadFn:e,batchId:r})=>{let n=[],o=ol()?new Blob([await t.arrayBuffer()]):t,s=0n;for(let a=0;a<o.size;a+=19e5){let c=o.slice(a,a+19e5);n.push({batchId:r,chunk:c,uploadFn:e,orderId:s}),s++}let i=[];for await(let a of Bv({uploadChunks:n}))i=[...i,...a];return{chunkIds:i}};async function*Bv({uploadChunks:t,limit:e=12}){for(let r=0;r<t.length;r=r+e){let n=t.slice(r,r+e);yield await Promise.all(n.map(o=>Cv(o)))}}var Cv=async({batchId:t,chunk:e,uploadFn:r,orderId:n})=>r({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:(0,Zi.toNullable)(n)});var R1=async({asset:t,...e})=>{let r=await ut(e);await I1({actor:r,asset:t})},S1=async({collection:t,filter:e,...r})=>{let{list_assets:n}=await ut(r),{items:o,items_length:s,items_page:i,matches_length:a,matches_pages:c}=await n(t,Ko(e));return{items:o.map(([d,p])=>p),items_length:s,items_page:(0,Cc.fromNullable)(i),matches_length:a,matches_pages:(0,Cc.fromNullable)(c)}},A1=async({collection:t,filter:e,...r})=>{let{count_assets:n}=await ut(r);return n(t,Ko(e))},B1=async({collection:t,fullPath:e,...r})=>(await ut(r)).del_asset(t,e),C1=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await ut({satellite:e,options:{certified:!0}}),n=t.map(({collection:o,fullPath:s})=>[o,s]);await r(n)},P1=async({collection:t,filter:e,...r})=>{let{del_filtered_assets:n}=await ut(r);return n(t,Ko(e))},D1=async({collection:t,fullPath:e,...r})=>{let{get_asset:n}=await ut(r);return(0,Cc.fromNullable)(await n(t,e))},F1=async({assets:t,...e})=>{let{get_many_assets:r}=await ut(e),n=t.map(({collection:s,fullPath:i})=>[s,i]);return(await r(n)).map(([s,i])=>(0,Cc.fromNullable)(i))};var V1=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var j9=t=>U1(t),H9=t=>U1({filename:t.data.name,...t}),U1=async({filename:t,data:e,collection:r,headers:n=[],fullPath:o,token:s,satellite:i,encoding:a,description:c})=>{let d=Ye(i?.identity),p=decodeURI(t),l=o??`/${r}/${p}`,u={...i,identity:d};return await R1({asset:{data:e,filename:p,collection:r,token:s,headers:n,fullPath:l,encoding:a,description:c},satellite:u,options:{certified:!0}}),{downloadUrl:L1({satellite:u,assetKey:{fullPath:l,token:s}}),fullPath:l,name:p}},$9=async({collection:t,filter:e,satellite:r,options:n})=>{let o={...r,identity:Ye(r?.identity)},{items:s,...i}=await S1({collection:t,filter:e??{},satellite:o,options:n??xn}),a=s.map(({key:{full_path:c,token:d,name:p,owner:l,description:u},headers:f,encodings:h,created_at:m,updated_at:b})=>{let y=(0,Pc.fromNullable)(d);return{fullPath:c,description:(0,Pc.fromNullable)(u),name:p,downloadUrl:L1({satellite:o,assetKey:{fullPath:c,token:y}}),token:y,headers:f,encodings:h.reduce((x,[_,{modified:T,sha256:N,total_length:I}])=>({...x,[_]:{modified:T,sha256:V1(N),total_length:I}}),{}),owner:l.toText(),created_at:m,updated_at:b}});return{items:a,assets:a,...i}},K9=async({collection:t,filter:e,satellite:r,options:n})=>{let o={...r,identity:Ye(r?.identity)};return await A1({collection:t,satellite:o,filter:e??{},options:n??xn})},G9=({collection:t,fullPath:e,satellite:r})=>B1({collection:t,fullPath:e,satellite:{...r,identity:Ye(r?.identity)},options:{certified:!0}}),z9=({assets:t,satellite:e})=>C1({assets:t,satellite:{...e,identity:Ye(e?.identity)},options:{certified:!0}}),Z9=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:Ye(e?.identity)};return await P1({collection:t,satellite:n,filter:r??{},options:{certified:!0}})},Y9=async({satellite:t,options:e,...r})=>{let n=Ye(t?.identity);return await D1({...r,satellite:{...t,identity:n},options:e??xn})},W9=async({satellite:t,options:e,...r})=>{let n=Ye(t?.identity);return await F1({...r,satellite:{...t,identity:n},options:e??xn})},L1=({assetKey:{fullPath:t,token:e},satellite:r})=>{let n={...r,identity:Ye(r?.identity)};return`${Xw(n)}${t}${(0,Pc.nonNullish)(e)?`?token=${e}`:""}`};var Pv=t=>{let e=t?.satelliteId??N1();(0,q1.assertNonNullish)(e,"Satellite ID is not configured. Juno cannot be initialized.");let r=t?.container??v1();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:r}},oC=t=>Dv(t),Dv=async t=>{let e=Pv(t);ur.getInstance().set(e),await um();let r=e.workers?.auth!==void 0?O1(e.workers.auth):void 0;return[...r?[r]:[]]},Fv=t=>Or.getInstance().subscribe(t),sC=Fv;export{Gw as AuthClientSignInProgressStep,ml as InitError,_l as InternetIdentityProvider,yl as ListError,bl as NFIDProvider,dl as SignInError,Us as SignInInitError,fl as SignInProviderNotSupportedError,ll as SignInUserInterruptError,hl as SignUpProviderNotSupportedError,m1 as WebAuthnSignInProgressStep,pl as WebAuthnSignInRetrievePublicKeyError,y1 as WebAuthnSignUpProgressStep,sC as authSubscribe,K9 as countAssets,U7 as countDocs,G9 as deleteAsset,P7 as deleteDoc,Z9 as deleteFilteredAssets,F7 as deleteFilteredDocs,z9 as deleteManyAssets,D7 as deleteManyDocs,L1 as downloadUrl,Y9 as getAsset,wl as getDoc,vv as getIdentityOnce,W9 as getManyAssets,C7 as getManyDocs,R9 as getSatelliteExtendedActor,oC as initJuno,Dv as initSatellite,$N as isWebAuthnAvailable,$9 as listAssets,V7 as listDocs,Fv as onAuthStateChange,f1 as setDoc,p1 as setManyDocs,xv as signIn,lm as signOut,wv as signUp,Nv as unsafeIdentity,j9 as uploadBlob,H9 as uploadFile};
|
|
120
|
+
Retrying query.`),await this.#x({...e,tries:a+1});throw p instanceof jr?p:ac.fromCode(new lc(p))}if(!this.#y)return d;let f=d.signatures?.[0]?.timestamp;if(!f)throw Me.fromCode(new Md("Timestamp not found in query response. This suggests a malformed or malicious response."));let l=Number(BigInt(f)/BigInt(zN));if(Date.now()+this.#r-l>this.#T){if(a<this.#l)return this.log.warn("Timestamp is older than the max ingress expiry. Retrying query.",{requestId:o,signatureTimestampMs:l}),await this.#x({...e,tries:a+1});throw Gt.fromCode(new Dd(this.#u,o,a))}return d}async#_(e){let{requestFn:r,backoff:n,tries:s}=e,o=s===0?0:n.next();if(o===null)throw Me.fromCode(new Po(`Retry strategy exhausted after ${s} attempts.`));o>0&&await new Promise(f=>setTimeout(f,o));let i,a=new Uint8Array;try{i=await r(),i.status===hm&&(a=$i(await i.clone().arrayBuffer()))}catch(f){if(s<this.#l)return this.log.warn(`Caught exception while attempting to make request:
|
|
121
|
+
${f}
|
|
122
|
+
Retrying request.`),await this.#_({requestFn:r,backoff:n,tries:s+1});throw ac.fromCode(new lc(f))}let c=sl(i.headers);if(i.status===hm||i.status===nv)return{ok:i.ok,status:i.status,statusText:i.statusText,responseBodyBytes:a,headers:c};let d=await i.text();if(i.status===sv&&i.url.includes("api/v3"))throw Me.fromCode(new dc);if(d.startsWith("Invalid request expiry: "))throw Ne.fromCode(new Do(d,this.#u));if(s<this.#l)return await this.#_({requestFn:r,backoff:n,tries:s+1});throw Me.fromCode(new uc(i.status,i.statusText,c,d))}async query(e,r,n){let s=this.#f(),o=r.effectiveCanisterId?te.from(r.effectiveCanisterId):te.from(e);await this.#b(o),this.log.print(`ecid ${o.toString()}`),this.log.print(`canisterId ${e.toString()}`);let i,a=await(n??this.#n);if(!a)throw gt.fromCode(new Ks);let c=te.from(e),d=a.getPrincipal(),f=mm(this.#u,this.#r),l={request_type:ko.Query,canister_id:c,method_name:r.methodName,arg:r.arg,sender:d,ingress_expiry:f},u=rs(l);i=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#o?{Authorization:"Basic "+btoa(this.#o)}:{}}},endpoint:ss.Query,body:l}),i=await a.transformRequest(i);let p=vc(i.body),h={canister:c.toText(),ecid:o,transformedRequest:i,body:p,requestId:u,backoff:s,tries:0},m=async()=>{let y=await this.#x(h);return{requestDetails:l,...y}},b=async()=>{let y=this.#m.get(o.toString());if(y)return y;await this.fetchSubnetKeys(o.toString());let x=this.#m.get(o.toString());if(!x)throw Gt.fromCode(new kd);return x};try{if(!this.#y)return await m();let[y,x]=await Promise.all([m(),b()]);try{return this.#w(y,x)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),this.#m.delete(o.toString());let _=await b();return this.#w(y,_)}}catch(y){let x;throw y instanceof jr?(y.code.requestContext={requestId:u,senderPubKey:i.body.sender_pubkey,senderSignature:i.body.sender_sig,ingressExpiry:i.body.content.ingress_expiry},x=y):x=ct.fromCode(new Zt(y)),this.log.error(`Error while making query: ${x.message}`,x),x}}#w;async createReadStateRequest(e,r){await this.#b();let n=await(r??this.#n);if(!n)throw gt.fromCode(new Ks);let s=n.getPrincipal(),o=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#o?{Authorization:"Basic "+btoa(this.#o)}:{}}},endpoint:ss.ReadState,body:{request_type:ko.ReadState,paths:e.paths,sender:s,ingress_expiry:mm(this.#u,this.#r)}});return n.transformRequest(o)}async readState(e,r,n,s){await this.#E();let o=te.from(e);function i(f){for(let l of f.paths){let[u,p]=l,h=new TextEncoder().encode("request_status");if(qo(u,h))return p}}let a,c;if(s)a=s,c=rs(a);else{c=i(r);let f=await this.#n;if(!f)throw gt.fromCode(new Ks);a=await this.createReadStateRequest(r,f)}this.log.print(`fetching "/api/v2/canister/${o}/read_state" with request:`,a);let d=this.#f();try{let{responseBodyBytes:f}=await this.#_({requestFn:()=>this.#s(""+new URL(`/api/v2/canister/${o.toString()}/read_state`,this.host),{...this.#a,...a.request,body:vc(a.body)}),backoff:d,tries:0}),l=ur(f);return this.log.print("Read state response:",l),l}catch(f){let l;throw f instanceof jr?(f.code.requestContext={requestId:c,senderPubKey:a.body.sender_pubkey,senderSignature:a.body.sender_sig,ingressExpiry:a.body.content.ingress_expiry},l=f):l=ct.fromCode(new Zt(f)),this.log.error(`Error while making read state: ${l.message}`,l),l}}parseTimeFromResponse(e){let r;if(e.certificate){let n=ur(e.certificate);if(n&&"tree"in n)r=n.tree;else throw Me.fromCode(new Gs("Could not decode time from response"));let s=zo(["time"],r);if(s.status!==lr.Found)throw Me.fromCode(new Jn("Time was not found in the response or was not in its expected format.",s.status));if(!(s.value instanceof Uint8Array)&&!ArrayBuffer.isView(s))throw Me.fromCode(new Ui("Time was not in its expected format."));let o=ta(s.value);return this.log.print("Time from response:",o),this.log.print("Time from response in milliseconds:",o.getTime()),o.getTime()}else this.log.warn("No certificate found in response");return 0}async syncTime(e){this.#i=this.#i??(async()=>{await this.#E();let r=Date.now();try{e||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let n=e??te.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),s=t.createSync({identity:new Ir,host:this.host.toString(),fetch:this.#s,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),i=(await Promise.all(Array(3).fill(null).map(async()=>{let c=(await im({canisterId:n,agent:s,paths:["time"],disableCertificateTimeVerification:!0})).get("time");if(c instanceof Date)return c.getTime()},[]))).reduce((a,c)=>typeof c=="number"&&c>a?c:a,0);i>0&&(this.#r=i-r,this.#c=!0,this.log.notify({message:`Syncing time: offset of ${this.#r}`,level:"info"}))}catch(n){let s=n instanceof jr?n:ct.fromCode(new Zt(n));throw this.log.error("Caught exception while attempting to sync time",s),s}})(),await this.#i.finally(()=>{this.#i=null})}async status(){let e=this.#o?{Authorization:"Basic "+btoa(this.#o)}:{};this.log.print('fetching "/api/v2/status"');let r=this.#f(),{responseBodyBytes:n}=await this.#_({backoff:r,requestFn:()=>this.#s(""+new URL("/api/v2/status",this.host),{headers:e,...this.#a}),tries:0});return ur(n)}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#b(e){await Promise.all([this.#E(),this.#O(e)])}async#E(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#t)await this.fetchRootKey();else throw gt.fromCode(new xn(this.#t))}async#O(e){this.#d&&!this.hasSyncedTime()&&await this.syncTime(e)}invalidateIdentity(){this.#n=null}replaceIdentity(e){this.#n=Promise.resolve(e)}async fetchSubnetKeys(e){let r=te.from(e);await this.#b(r);let s=(await im({canisterId:r,paths:["subnet"],agent:this})).get("subnet");if(s&&typeof s=="object"&&"nodeKeys"in s)return this.#m.set(r.toText(),s),s}_transform(e){let r=Promise.resolve(e);if(e.endpoint===ss.Call)for(let n of this.#h)r=r.then(s=>n(s).then(o=>o||s));else for(let n of this.#p)r=r.then(s=>n(s).then(o=>o||s));return r}getTimeDiffMsecs(){return this.#r}hasSyncedTime(){return this.#c}};function mm(t,e){let r=t*ym;return zi.fromDeltaInMilliseconds(r,e)}var av=300*1e3;function Hw(){return fv(uv(cv(),1e3),lv(1e3,1.2),dv(av))}function cv(){let t=!0;return async()=>t?(t=!1,!0):!1}function uv(t,e){return async(r,n,s)=>{if(await t(r,n,s))return new Promise(o=>setTimeout(o,e))}}function dv(t){let e=Date.now()+t;return async(r,n,s)=>{if(Date.now()>e)throw Me.fromCode(new Po(`Request timed out after ${t} msec`,n,s))}}function lv(t,e){let r=t;return()=>new Promise(n=>setTimeout(()=>{r*=e,n()},r))}function fv(...t){return async(e,r,n)=>{for(let s of t)await s(e,r,n)}}var Kw={preSignReadStateRequest:!1};function Gw(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function _m(t,e){return t!==null&&typeof t=="object"&&Gw(t,e)}function hv(t,e){return Gw(t,e)&&typeof t[e]=="function"}function $w(t){return _m(t,"body")&&_m(t.body,"content")&&t.body.content.request_type===ko.ReadState&&_m(t.body.content,"ingress_expiry")&&typeof t.body.content.ingress_expiry=="object"&&t.body.content.ingress_expiry!==null&&hv(t.body.content.ingress_expiry,"toHash")}async function bm(t,e,r,n={}){let s=[Ue("request_status"),r],o,i;if(n.preSignReadStateRequest??!1?(i=await mv({paths:[s],agent:t,pollingOptions:n}),o=await t.readState(e,{paths:[s]},void 0,i)):o=await t.readState(e,{paths:[s]}),t.rootKey==null)throw gt.fromCode(new xn);let c=await to.create({certificate:o.certificate,rootKey:t.rootKey,canisterId:e,blsVerify:n.blsVerify,agent:t}),d=Mt(c.lookup_path([...s,Ue("status")])),f;switch(typeof d>"u"?f=vn.Unknown:f=new TextDecoder().decode(d),f){case vn.Replied:return{reply:Mt(c.lookup_path([...s,"reply"])),certificate:c};case vn.Received:case vn.Unknown:case vn.Processing:{let l=n.strategy??Hw();return await l(e,r,f),bm(t,e,r,{...n,strategy:l,request:i})}case vn.Rejected:{let l=new Uint8Array(Mt(c.lookup_path([...s,"reject_code"])))[0],u=new TextDecoder().decode(Mt(c.lookup_path([...s,"reject_message"]))),p=Mt(c.lookup_path([...s,"error_code"])),h=p?new TextDecoder().decode(p):void 0;throw Hs.fromCode(new Li(r,l,u,h))}case vn.Done:throw ct.fromCode(new Vd(r))}throw Zs}async function mv(t){let{paths:e,agent:r,pollingOptions:n}=t;if(n.request&&$w(n.request))return n.request;let s=await r.createReadStateRequest?.({paths:e},void 0);if(!$w(s))throw Ne.fromCode(new $d(s));return s}var Cr=Symbol.for("ic-agent-metadata"),Tl=class t{static agentOf(e){return e[Cr].config.agent}static interfaceOf(e){return e[Cr].service}static canisterIdOf(e){return te.from(e[Cr].config.canisterId)}static createActorClass(e,r){let n=e({IDL:Lo});class s extends t{constructor(i){if(!i.canisterId)throw Ne.fromCode(new fc(i.canisterId));let a=typeof i.canisterId=="string"?te.fromText(i.canisterId):i.canisterId;super({config:{...Zw,...i,canisterId:a},service:n});for(let[c,d]of n._fields)r?.httpDetails&&d.annotations.push(gm),r?.certificate&&d.annotations.push(zw),this[c]=_v(this,c,d,i.blsVerify)}}return s}static createActor(e,r){if(!r.canisterId)throw Ne.fromCode(new fc(r.canisterId));return new(this.createActorClass(e))(r)}static createActorWithHttpDetails(e,r){return new(this.createActorClass(e,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(e,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(e,n))(r)}constructor(e){this[Cr]=Object.freeze(e)}};function na(t,e){let r=Lo.decode(t,e);switch(r.length){case 0:return;case 1:return r[0];default:return r}}var Zw={pollingOptions:Kw},gm="http-details",zw="certificate";function _v(t,e,r,n){let s;r.annotations.includes("query")||r.annotations.includes("composite_query")?s=async(i,...a)=>{i={...i,...t[Cr].config.queryTransform?.(e,a,{...t[Cr].config,...i})};let c=i.agent||t[Cr].config.agent||new Jo,d=te.from(i.canisterId||t[Cr].config.canisterId),f=Lo.encode(r.argTypes,a),l=await c.query(d,{methodName:e,arg:f,effectiveCanisterId:i.effectiveCanisterId}),u={...l.httpDetails,requestDetails:l.requestDetails};switch(l.status){case qs.Rejected:{let p=new Fd(l.requestId,l.reject_code,l.reject_message,l.error_code,l.signatures);throw p.callContext={canisterId:d,methodName:e,httpDetails:u},Hs.fromCode(p)}case qs.Replied:return r.annotations.includes(gm)?{httpDetails:u,result:na(r.retTypes,l.reply.arg)}:na(r.retTypes,l.reply.arg)}}:s=async(i,...a)=>{i={...i,...t[Cr].config.callTransform?.(e,a,{...t[Cr].config,...i})};let c=i.agent||t[Cr].config.agent||Jo.createSync(),{canisterId:d,effectiveCanisterId:f,pollingOptions:l}={...Zw,...t[Cr].config,...i},u=te.from(d),p=f!==void 0?te.from(f):u,h=Lo.encode(r.argTypes,a),{requestId:m,response:b,requestDetails:y}=await c.call(u,{methodName:e,arg:h,effectiveCanisterId:p,nonce:i.nonce}),x,_;if(jg(b.body)){if(c.rootKey==null)throw gt.fromCode(new xn);let R=b.body.certificate;_=await to.create({certificate:R,rootKey:c.rootKey,canisterId:p,blsVerify:n,agent:c});let A=[Ue("request_status"),m];switch(new TextDecoder().decode(Mt(_.lookup_path([...A,"status"])))){case"replied":x=Mt(_.lookup_path([...A,"reply"]));break;case"rejected":{let S=new Uint8Array(Mt(_.lookup_path([...A,"reject_code"])))[0],U=new TextDecoder().decode(Mt(_.lookup_path([...A,"reject_message"]))),C=Mt(_.lookup_path([...A,"error_code"])),g=C?new TextDecoder().decode(C):void 0,w=new Li(m,S,U,g);throw w.callContext={canisterId:u,methodName:e,httpDetails:b},Hs.fromCode(w)}}}else if(kg(b.body)){let{reject_code:R,reject_message:A,error_code:E}=b.body,S=new Ud(m,R,A,E);throw S.callContext={canisterId:u,methodName:e,httpDetails:b},Hs.fromCode(S)}if(b.status===202){let R={...l,blsVerify:n},A=await bm(c,p,m,R);_=A.certificate,x=A.reply}let T=r.annotations.includes(gm),N=r.annotations.includes(zw),v={...b,requestDetails:y};if(x!==void 0)return T&&N?{httpDetails:v,certificate:_,result:na(r.retTypes,x)}:N?{certificate:_,result:na(r.retTypes,x)}:T?{httpDetails:v,result:na(r.retTypes,x)}:na(r.retTypes,x);{let R=new Zt(`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${r.retTypes.map(A=>A.display()).join(",")}].`);throw R.callContext={canisterId:u,methodName:e,httpDetails:v},ct.fromCode(R)}};let o=(...i)=>s({},...i);return o.withOptions=i=>(...a)=>s(i,...a),o}var e1=Fe(De(),1),er=Fe(De(),1);var o1=Fe(De(),1),bv=({authData:t})=>{if(t.byteLength<37)return{invalidAuthData:null};if(t.byteLength<53)return{invalidAuthData:null};let e=t.slice(37,53),r=gv({bytes:e});return"aaguid"in r?{aaguidBytes:e,aaguidText:r.aaguid}:{unknownProvider:null}},gv=({bytes:t})=>{if(t.length!==16)return{invalidBytes:null};let e=(t instanceof Uint8Array?(0,Qw.uint8ArrayToArrayOfNumber)(t):t).map(r=>r.toString(16).padStart(2,"0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5");return e==="00000000-0000-0000-0000-000000000000"?{unknownProvider:null}:{aaguid:e}};function xv(t){let e=new DataView(new ArrayBuffer(2)),r=t.slice(53,55);[...new Uint8Array(r)].forEach((s,o)=>e.setUint8(o,s));let n=e.getUint16(0);return t.slice(55+n)}function wv(t){return Wo(t,kc)}var Ev=class{constructor(t){this._cose=t,this.#e=wv(t)}#e;toDer(){return this.#e}toRaw(){return new Uint8Array(this.#e)}},t1=class{#e;#t;constructor({rawId:t,cose:e}){this.#e=t,this.#t=new Ev(e)}getPublicKey(){return this.#t}getCredentialId(){return this.#e}getCredentialIdText(){return(0,e1.uint8ArrayToBase64)(this.#e)}},Tv=class extends t1{#e;#t;constructor({authData:t,...e}){super(e);let r=bv({authData:t});this.#e="aaguidText"in r?r.aaguidText:void 0,this.#t="aaguidBytes"in r?r.aaguidBytes:void 0}getAAGUID(){return this.#t}getAAGUIDText(){return this.#e}},Ov=class extends t1{},Nv=class extends Error{},vv=class extends Error{},Rv=class extends Error{},Iv=class extends Error{},Sv=class extends Error{},Av=class extends Error{},Bv=class extends Error{},Yw=class extends Error{};var Cv={ECDSA_WITH_SHA256:-7,RSA_WITH_SHA256:-257},Pv=6e4,r1=()=>window.crypto.getRandomValues(new Uint8Array(16)),Dv=()=>r1(),Fv=()=>r1(),Uv=()=>{let{location:{href:t}}=window;try{let{hostname:e}=new URL(t);return e}catch{throw new Nv}},n1=({appId:t})=>t?.id??Uv(),Vv=({appId:t,user:e}={})=>{let{document:{title:r}}=window,n=()=>({rp:{name:t?.name??r,id:n1({appId:t})}}),s=()=>({user:{id:Fv(),name:e?.name??e?.displayName??r,displayName:e?.displayName??r}});return{attestation:"direct",challenge:Dv(),...n(),...s(),pubKeyCredParams:Object.values(Cv).map(o=>({type:"public-key",alg:o})),excludeCredentials:[],authenticatorSelection:{authenticatorAttachment:"platform",userVerification:"preferred",residentKey:"required",requireResidentKey:!0}}},Lv=(t={})=>({rpId:n1(t),allowCredentials:[],userVerification:"required"}),xm=async({fn:t,step:e,onProgress:r})=>{r?.({step:e,state:"in_progress"});try{let n=await t();return r?.({step:e,state:"success"}),n}catch(n){throw r?.({step:e,state:"error"}),n}},so=(t=>(t[t.RequestingUserCredential=0]="RequestingUserCredential",t[t.FinalizingCredential=1]="FinalizingCredential",t[t.Signing=2]="Signing",t))(so||{}),s1=({timeout:t})=>AbortSignal.timeout(t??Pv),qv=async({challenge:t,credentialIds:e,passkeyOptions:r,timeout:n})=>await navigator.credentials.get({publicKey:{...Lv(r),challenge:t.buffer,allowCredentials:(e??[]).map(s=>({id:s.buffer,type:"public-key"}))},signal:s1({timeout:n})}),Ww=t=>{if(t.status!=="initialized")throw new vv},Xw=t=>{if((0,er.isNullish)(t))throw new Rv},Jw=({type:t})=>{if(t!=="public-key")throw new Iv},wm=class jc extends Nn{#e;#t;constructor({onProgress:e,...r}){if(super(),this.#e=e,"retrievePublicKey"in r){let{retrievePublicKey:n}=r;this.#t={status:"pending",retrievePublicKey:n};return}this.#t=jc.#r({credential:new Tv(r)})}static#r({credential:e}){return{status:"initialized",credential:e}}static async createWithNewCredential({passkeyOptions:e,timeout:r,...n}={}){let s=await navigator.credentials.create({publicKey:Vv(e),signal:s1({timeout:r})});Xw(s),Jw(s);let{response:{attestationObject:o},rawId:i}=s;if((0,er.isNullish)(o))throw new Sv;let{authData:a}=tl.decode((0,er.arrayBufferToUint8Array)(o)),c=xv(a);return new jc({...n,rawId:(0,er.arrayBufferToUint8Array)(i),cose:c,authData:a})}static async createWithExistingCredential(e){return new jc(e)}getPublicKey(){Ww(this.#t);let{credential:e}=this.#t;return e.getPublicKey()}getCredential(){Ww(this.#t);let{credential:e}=this.#t;return e}async sign(e){let r=await xm({fn:async()=>{let n=await qv({challenge:e,...this.#t.status==="initialized"&&{credentialIds:[this.#t.credential.getCredentialId()]}});return Xw(n),Jw(n),n},step:0,onProgress:this.#e});return await xm({fn:async()=>{let{rawId:n}=r;if(this.#t.status==="initialized"){if(!(0,er.uint8ArraysEqual)({a:this.#t.credential.getCredentialId(),b:(0,er.arrayBufferToUint8Array)(n)}))throw new Av;return}let{retrievePublicKey:s}=this.#t,o=await s({credentialId:(0,er.arrayBufferToUint8Array)(n)});this.#t=jc.#r({credential:new Ov({rawId:(0,er.arrayBufferToUint8Array)(n),cose:o})})},step:1,onProgress:this.#e}),await xm({fn:async()=>{let{response:n}=r,{clientDataJSON:s}=n,{authenticatorData:o,signature:i}="authenticatorData"in n&&"signature"in n?n:{};if((0,er.isNullish)(o))throw new Yw;if((0,er.isNullish)(i))throw new Yw;let a=tl.encode({authenticator_data:o,client_data_json:new TextDecoder().decode(s),signature:(0,er.arrayBufferToUint8Array)(i)});if((0,er.isNullish)(a))throw new Bv;return Object.assign(a,{__signature__:void 0}),a},step:2,onProgress:this.#e})}},Mv=async()=>(0,o1.nonNullish)(window.PublicKeyCredential)&&"isUserVerifyingPlatformAuthenticatorAvailable"in PublicKeyCredential?await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():!1;var g2=Fe(De(),1);var sa=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:r})=>r(e))}subscribe(e){let r=Symbol();return this.callbacks.push({id:r,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:n})=>n!==r)}};var Pr=class t extends sa{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let r=super.subscribe(e);return e(this.authUser),r}reset(){this.authUser=null,this.populate(this.authUser)}};var Em=({message:t,detail:e})=>{let r=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(r)};var b2=Fe(De(),1);var Nl=Fe(De(),1);var Ol=Fe(De(),1);var Tm=Fe(De(),1);var oa="http://127.0.0.1:5987",i1="rdmx6-jaaaa-aaaaa-aaadq-cai";var a1=async({identity:t,container:e})=>{let n=(0,Tm.nonNullish)(e)&&e!==!1?e===!0?oa:e:"https://icp-api.io",s=(0,Tm.nonNullish)(e);return await Jo.create({identity:t,shouldFetchRootKey:s,host:n})};var ia=class t{static instance;#e=void 0;constructor(){}static getInstance(){return(0,Ol.isNullish)(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...r}){let n=e.getPrincipal().toText();if((0,Ol.isNullish)(this.#e)||(0,Ol.isNullish)(this.#e[n])){let s=await a1({identity:e,...r});return this.#e={...this.#e??{},[n]:s},s}return this.#e[n]}reset(){this.#e=null}};var aa=class t{static instance;#e=void 0;constructor(){}static getInstance(){return(0,Nl.isNullish)(t.instance)&&(t.instance=new t),t.instance}async getActor({satelliteId:e,identity:r,actorKey:n,...s}){let o=`${n}#${r.getPrincipal().toText()}#${e};`;if((0,Nl.isNullish)(this.#e)||(0,Nl.isNullish)(this.#e[o])){let i=await this.createActor({satelliteId:e,identity:r,...s});return this.#e={...this.#e??{},[o]:i},i}return this.#e[o]}reset(){this.#e=null}async createActor({idlFactory:e,satelliteId:r,...n}){let s=await ia.getInstance().getAgent(n);return Tl.createActor(e,{agent:s,canisterId:r})}};var c1=t=>(t.preventDefault(),t.returnValue="Are you sure you want to exit?"),kv=()=>{window.addEventListener("beforeunload",c1,{capture:!0})},jv=()=>{window.removeEventListener("beforeunload",c1,{capture:!0})},Om=async({fn:t})=>{try{return kv(),await t()}finally{jv()}};var ni=Fe(De(),1);var xr=class t extends sa{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}reset(){this.env=null}subscribe(e){let r=super.subscribe(e);return e(this.env),r}};var u1=BigInt(144e11),d1=!1,l1={width:576,height:576},f1={width:424,height:576},p1={width:505,height:705},Hc="internetcomputer.org",h1="ic0.app",m1="id.ai";var Nm=Fe(De(),1);var vl=Fe(De(),1),y1=async t=>{let e=new Blob([JSON.stringify(t,vl.jsonReplacer)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},Rl=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),vl.jsonReviver)},Il=()=>typeof window<"u";var Sl=({width:t,height:e})=>{if(!Il()||(0,Nm.isNullish)(window)||(0,Nm.isNullish)(window.top))return;let{top:{innerWidth:r,innerHeight:n}}=window,s=n/2+screenY-e/2,o=r/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${s}, left=${o}`};var H1=Fe(De(),1);function _1(t){return t!==null&&typeof t=="object"}var $c=class t{static from(e){if(typeof e=="string"){let r=bt(e);return this.fromRaw(r)}else if(_1(e)){let r=e;if(_1(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(wn(n.buffer))}else{if(r instanceof ArrayBuffer)return this.fromRaw(wn(r));if("rawKey"in r&&r.rawKey instanceof Uint8Array)return this.fromRaw(r.rawKey);if("derKey"in r)return this.fromDer(r.derKey);if("toDer"in r)return this.fromDer(r.toDer())}}throw new Error("Cannot construct Ed25519PublicKey from the provided key.")}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){let r=Wo(e,Yo);return r.__derEncodedPublicKey__=void 0,r}static derDecode(e){let r=Xo(e,Yo);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes 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 new Error("An Ed25519 public key must be exactly 32bytes long");this.#e=e,this.#t=t.derEncode(e)}toDer(){return this.derKey}toRaw(){return this.rawKey}},Qo=class t extends Nn{static generate(e){if(e&&e.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");e||(e=Qt.utils.randomPrivateKey()),ux(e,new Uint8Array(new Array(32).fill(0)))&&console.warn("Seed is all zeros. This is not a secure seed. Please provide a seed with sufficient entropy if this is a production environment.");let r=new Uint8Array(32);for(let s=0;s<32;s++)r[s]=e[s];let n=Qt.getPublicKey(r);return t.fromKeyPair(n,r)}static fromParsedJson(e){let[r,n]=e;return new t($c.fromDer(bt(r)),bt(n))}static fromJSON(e){let r=JSON.parse(e);if(Array.isArray(r)){if(typeof r[0]=="string"&&typeof r[1]=="string")return this.fromParsedJson([r[0],r[1]]);throw new Error("Deserialization error: JSON must have at least 2 items.")}throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(e)}`)}static fromKeyPair(e,r){return new t($c.fromRaw(e),r)}static fromSecretKey(e){let r=Qt.getPublicKey(e);return t.fromKeyPair(r,e)}#e;#t;constructor(e,r){super(),this.#e=$c.from(e),this.#t=r}toJSON(){return[fe(this.#e.toDer()),fe(this.#t)]}getKeyPair(){return{secretKey:this.#t,publicKey:this.#e}}getPublicKey(){return this.#e}async sign(e){let r=Qt.sign(e,this.#t.slice(0,32));return Object.defineProperty(r,"__signature__",{enumerable:!1,value:void 0}),r}static verify(e,r,n){let[s,o,i]=[e,r,n].map(a=>(typeof a=="string"&&(a=bt(a)),wn(a)));return Qt.verify(s,o,i)}};var vm=class t extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,t.prototype)}};function b1(t){if(typeof global<"u"&&global.crypto&&global.crypto.subtle)return global.crypto.subtle;if(t)return t;if(typeof crypto<"u"&&crypto.subtle)return crypto.subtle;throw new vm("Global crypto was not available and none was provided. Please inlcude a SubtleCrypto implementation. See https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto")}var oo=class t extends Nn{static async generate(e){let{extractable:r=!1,keyUsages:n=["sign","verify"],subtleCrypto:s}=e??{},o=b1(s),i=await o.generateKey({name:"ECDSA",namedCurve:"P-256"},r,n),a=wn(await o.exportKey("spki",i.publicKey));return Object.assign(a,{__derEncodedPublicKey__:void 0}),new this(i,a,o)}static async fromKeyPair(e,r){let n=b1(r),s=wn(await n.exportKey("spki",e.publicKey));return Object.assign(s,{__derEncodedPublicKey__:void 0}),new t(e,s,n)}constructor(e,r,n){super(),this._keyPair=e,this._derKey=r,this._subtleCrypto=n}getKeyPair(){return this._keyPair}getPublicKey(){let e=this._derKey,r=Object.create(this._keyPair.publicKey);return r.toDer=function(){return e},r}async sign(e){let r={name:"ECDSA",hash:{name:"SHA-256"}},n=wn(await this._subtleCrypto.sign(r,this._keyPair.privateKey,e));return Object.assign(n,{__signature__:void 0}),n}};var Al=class{#e;get rawKey(){return this.#e.rawKey}get derKey(){return this.#e.derKey}toDer(){return this.#e.toDer()}getPublicKey(){return this.#e}getPrincipal(){if(!this.#e.rawKey)throw new Error("Cannot get principal from a public key without a raw key.");return te.fromUint8Array(new Uint8Array(this.#e.rawKey))}transformRequest(){return Promise.reject("Not implemented. You are attempting to use a partial identity to sign calls, but this identity only has access to the public key.To sign calls, use a DelegationIdentity instead.")}constructor(e){this.#e=e}};function Bl(t){return t instanceof Uint8Array?fe(t):fe(new Uint8Array(t))}function Rm(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return bt(t)}var io=class{constructor(e,r,n){this.pubkey=e,this.expiration=r,this.targets=n}toCborValue(){return{pubkey:this.pubkey,expiration:this.expiration,...this.targets&&{targets:this.targets}}}toJSON(){return{expiration:this.expiration.toString(16),pubkey:Bl(this.pubkey),...this.targets&&{targets:this.targets.map(e=>e.toHex())}}}};async function Hv(t,e,r,n){let s=new io(e.toDer(),BigInt(+r)*BigInt(1e6),n),o=new Uint8Array([...N0,...new Uint8Array(rs({...s}))]),i=await t.sign(o);return{delegation:s,signature:i}}var ps=class t{static async create(e,r,n=new Date(Date.now()+900*1e3),s={}){let o=await Hv(e,r,n,s.targets);return new t([...s.previous?.delegations||[],o],s.previous?.publicKey||e.getPublicKey().toDer())}static fromJSON(e){let{publicKey:r,delegations:n}=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(n))throw new Error("Invalid delegations.");let s=n.map(o=>{let{delegation:i,signature:a}=o,{pubkey:c,expiration:d,targets:f}=i;if(f!==void 0&&!Array.isArray(f))throw new Error("Invalid targets.");return{delegation:new io(Rm(c),BigInt("0x"+d),f&&f.map(l=>{if(typeof l!="string")throw new Error("Invalid target.");return te.fromHex(l)})),signature:Rm(a)}});return new this(s,Rm(r))}static fromDelegations(e,r){return new this(e,r)}constructor(e,r){this.delegations=e,this.publicKey=r}toJSON(){return{delegations:this.delegations.map(e=>{let{delegation:r,signature:n}=e,{targets:s}=r;return{delegation:{expiration:r.expiration.toString(16),pubkey:Bl(r.pubkey),...s&&{targets:s.map(o=>o.toHex())}},signature:Bl(n)}}),publicKey:Bl(this.publicKey)}}},ao=class extends Nn{static fromDelegation(e,r){return new this(e,r)}constructor(e,r){super(),this._inner=e,this._delegation=r}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(e){return this._inner.sign(e)}async transformRequest(e){let{body:r,...n}=e,s=await rs(r);return{...n,body:{content:r,sender_sig:await this.sign(new Uint8Array([...wc,...new Uint8Array(s)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}}}},ca=class t extends Al{#e;get delegation(){return this.#e}constructor(e,r){super(e),this.#e=r}static fromDelegation(e,r){return new t(e,r)}};function Im(t,e){for(let{delegation:s}of t.delegations)if(+new Date(Number(s.expiration/BigInt(1e6)))<=+Date.now())return!1;let r=[],n=e?.scope;n&&(Array.isArray(n)?r.push(...n.map(s=>typeof s=="string"?te.fromText(s):s)):r.push(typeof n=="string"?te.fromText(n):n));for(let s of r){let o=s.toText();for(let{delegation:i}of t.delegations){if(i.targets===void 0)continue;let a=!0;for(let c of i.targets)if(c.toText()===o){a=!1;break}if(a)return!1}}return!0}var hs=t=>{if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(t,"base64");if(typeof globalThis.atob<"u")return Uint8Array.from(globalThis.atob(t),e=>e.charCodeAt(0));throw Error("Could not decode base64 string")},ua=t=>{if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(t).toString("base64");if(typeof globalThis.btoa<"u")return btoa(Array.from({length:Math.ceil(t.byteLength/1e5)}).map((e,r)=>String.fromCharCode(...new Uint8Array(t.slice(r*1e5,(r+1)*1e5)))).join(""));throw Error("Could not encode base64 string")};var da=function(t,e,r,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(t,r):s?s.value=r:e.set(t,r),r},tt=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},kt,ms,la,Cl,ti=class t extends Error{constructor(e){super(e.message),Object.setPrototypeOf(this,t.prototype),this.code=e.code,this.data=e.data}},g1=t=>new ti({code:4e3,message:t instanceof Error?t.message:"Network error"}),ei=t=>{if("error"in t)throw new ti(t.error);if("result"in t)return t.result;throw new ti({code:4e3,message:"Invalid response"})},Dl=class{constructor(e){kt.set(this,void 0),ms.set(this,void 0),la.set(this,void 0),Cl.set(this,void 0),da(this,kt,Object.assign({autoCloseTransportChannel:!0,closeTransportChannelAfter:200,crypto:globalThis.crypto},e),"f")}get transport(){return tt(this,kt,"f").transport}async openChannel(){if(clearTimeout(tt(this,Cl,"f")),tt(this,la,"f")&&await tt(this,la,"f"),tt(this,ms,"f")&&!tt(this,ms,"f").closed)return tt(this,ms,"f");let e=tt(this,kt,"f").transport.establishChannel();return da(this,la,e.then(()=>{}).catch(()=>{}),"f"),da(this,ms,void 0,"f"),da(this,ms,await e.catch(r=>{throw g1(r)}),"f"),da(this,la,void 0,"f"),tt(this,ms,"f")}async closeChannel(){var e;await((e=tt(this,ms,"f"))===null||e===void 0?void 0:e.close())}async transformRequest(e){return tt(this,kt,"f").derivationOrigin?Object.assign(Object.assign({},e),{params:Object.assign(Object.assign({},e.params),{icrc95DerivationOrigin:tt(this,kt,"f").derivationOrigin})}):e}async sendRequest(e){let r=await this.openChannel();return new Promise(async(n,s)=>{let o=r.addEventListener("response",async a=>{a.id===e.id&&(o(),i(),n(a),tt(this,kt,"f").autoCloseTransportChannel&&da(this,Cl,setTimeout(()=>{r.closed||r.close()},tt(this,kt,"f").closeTransportChannelAfter),"f"))}),i=r.addEventListener("close",()=>{o(),i(),s(new ti({code:4e3,message:"Channel was closed before a response was received"}))});try{await r.send(await this.transformRequest(e))}catch(a){o(),i(),s(g1(a))}})}async supportedStandards(){let e=await this.sendRequest({id:tt(this,kt,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc25_supported_standards"});return ei(e).supportedStandards}async requestPermissions(e){let r=await this.sendRequest({id:tt(this,kt,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc25_request_permissions",params:{scopes:e}});return ei(r).scopes}async permissions(){let e=await this.sendRequest({id:tt(this,kt,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc25_permissions"});return ei(e).scopes}async accounts(){let e=await this.sendRequest({id:tt(this,kt,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc27_accounts"});return ei(e).accounts.map(({owner:n,subaccount:s})=>({owner:te.fromText(n),subaccount:s===void 0?void 0:hs(s)}))}async delegation(e){var r;let n=await this.sendRequest({id:tt(this,kt,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc34_delegation",params:{publicKey:ua(e.publicKey),targets:(r=e.targets)===null||r===void 0?void 0:r.map(o=>o.toText()),maxTimeToLive:e.maxTimeToLive===void 0?void 0:String(e.maxTimeToLive)}}),s=ei(n);return ps.fromDelegations(s.signerDelegation.map(o=>{var i;return{delegation:new io(hs(o.delegation.pubkey),BigInt(o.delegation.expiration),(i=o.delegation.targets)===null||i===void 0?void 0:i.map(a=>te.fromText(a))),signature:hs(o.signature)}}),hs(s.publicKey))}async callCanister(e){let r=await this.sendRequest({id:tt(this,kt,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc49_call_canister",params:{canisterId:e.canisterId.toText(),sender:e.sender.toText(),method:e.method,arg:ua(e.arg),nonce:e.nonce?ua(e.nonce):void 0}}),n=ei(r),s=hs(n.contentMap),o=hs(n.certificate);return{contentMap:s,certificate:o}}async batchCallCanister(e){var r;let n=await this.sendRequest({id:tt(this,kt,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc112_batch_call_canister",params:{sender:e.sender.toText(),validationCanisterId:(r=e.validationCanisterId)===null||r===void 0?void 0:r.toText(),requests:e.requests.map(o=>o.map(i=>({canisterId:i.canisterId.toText(),method:i.method,arg:ua(i.arg),nonce:i.nonce?ua(i.nonce):void 0})))}}),s=ei(n);if(e.requests.length!==s.responses.length||e.requests.some((o,i)=>o.length!==s.responses[i].length))throw new ti({code:4e3,message:"Invalid batch call canister response, structure does not match request structure"});return s.responses.map(o=>o.map(i=>({result:{contentMap:hs(i.contentMap),certificate:hs(i.certificate)}})))}};kt=new WeakMap,ms=new WeakMap,la=new WeakMap,Cl=new WeakMap;var x1=t=>typeof t=="object"&&!!t&&"jsonrpc"in t&&t.jsonrpc==="2.0",w1=t=>x1(t)&&"method"in t&&typeof t.method=="string",Fl=t=>x1(t)&&"id"in t&&(typeof t.id=="string"||typeof t.id=="number");var Sm=function(t,e,r,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(t,r):s?s.value=r:e.set(t,r),r},Ze=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Kc,Et,fa,Gc,Ul=class{constructor(e){Kc.set(this,new Set),Et.set(this,void 0),fa.set(this,!1),Gc.set(this,[]),Sm(this,Et,Object.assign({signerStatus:"ready",window:globalThis.window,manageFocus:!0},e),"f")}get closed(){return Ze(this,fa,"f")}addEventListener(...[e,r]){switch(e){case"close":return Ze(this,Kc,"f").add(r),()=>{Ze(this,Kc,"f").delete(r)};case"response":let n=async s=>{s.source!==Ze(this,Et,"f").signerWindow||s.origin!==Ze(this,Et,"f").signerOrigin||!Fl(s.data)||r(s.data)};return Ze(this,Et,"f").window.addEventListener("message",n),()=>{Ze(this,Et,"f").window.removeEventListener("message",n)}}}async send(e){if(Ze(this,fa,"f"))throw new ys("Communication channel is closed");if(Ze(this,Et,"f").signerStatus==="pending"){Ze(this,Gc,"f").push(e);return}Ze(this,Et,"f").signerWindow.postMessage(e,Ze(this,Et,"f").signerOrigin),Ze(this,Et,"f").manageFocus&&Ze(this,Et,"f").signerWindow.focus()}async close(){Ze(this,fa,"f")||(Sm(this,fa,!0,"f"),Ze(this,Et,"f").signerWindow.close(),Ze(this,Et,"f").manageFocus&&Ze(this,Et,"f").window.focus(),Ze(this,Kc,"f").forEach(e=>e()))}changeStatus(e){if(Ze(this,Et,"f").signerStatus=e,e==="ready"){let r=Ze(this,Gc,"f");Sm(this,Gc,[],"f"),r.forEach((n,s)=>{Ze(this,Et,"f").signerWindow.postMessage(n,Ze(this,Et,"f").signerOrigin)})}}};Kc=new WeakMap,Et=new WeakMap,fa=new WeakMap,Gc=new WeakMap;var E1=t=>{try{let e=new URL(t);return e.protocol==="https:"||e.hostname==="127.0.0.1"||e.hostname.split(".").slice(-1)[0]==="localhost"}catch{return!1}};var Cm=function(t,e,r,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(t,r):s?s.value=r:e.set(t,r),r},ze=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},co,ft,Zc,O1,T1,Am,Bm,Vl=class{constructor(e){co.add(this),ft.set(this,void 0),Zc.set(this,void 0),Cm(this,ft,Object.assign({establishTimeout:1e4,pendingTimeout:3e5,disconnectTimeout:2e3,statusPollingRate:300,window:globalThis.window,crypto:globalThis.crypto},e),"f"),ze(this,co,"m",O1).call(this)}};ft=new WeakMap,Zc=new WeakMap,co=new WeakSet,O1=function(){let e=[],r=()=>{let i=ze(this,ft,"f").crypto.randomUUID();return e.push(i),i},n=ze(this,co,"m",Am).call(this,i=>{"result"in i.data&&e.includes(i.data.id)&&(e=[],n(),clearInterval(o),clearTimeout(s),Cm(this,Zc,i.data.result,"f"),ze(this,ft,"f").onEstablish(i.origin,i.data.result),ze(this,co,"m",T1).call(this,i.origin,i.data.result))}),s=setTimeout(()=>{n(),clearInterval(o),ze(this,ft,"f").onEstablishTimeout()},ze(this,ft,"f").establishTimeout),o=setInterval(()=>ze(this,co,"m",Bm).call(this,r()),ze(this,ft,"f").statusPollingRate)},T1=function(e,r){let n,s,o=[],i=f=>{let l=o.findIndex(u=>u.id===f);return l>-1&&o.splice(l,1),l>-1},a=()=>{let f=ze(this,ft,"f").crypto.randomUUID(),l=new Date().getTime();return o=o.filter(u=>l-ze(this,ft,"f").disconnectTimeout>u.time),o.push({id:f,time:l}),f},c=f=>{clearTimeout(s),s=setTimeout(()=>{d(),clearInterval(n),ze(this,ft,"f").onDisconnect()},f==="pending"?ze(this,ft,"f").pendingTimeout:ze(this,ft,"f").disconnectTimeout)},d=ze(this,co,"m",Am).call(this,f=>{"result"in f.data&&f.origin===e&&i(f.data.id)&&(c(f.data.result),ze(this,Zc,"f")!==f.data.result&&(Cm(this,Zc,f.data.result,"f"),ze(this,ft,"f").onStatusChange(f.data.result)))});c(r),n=setInterval(()=>ze(this,co,"m",Bm).call(this,a()),ze(this,ft,"f").statusPollingRate)},Am=function(e){let r=n=>{(n.source===ze(this,ft,"f").signerWindow&&Fl(n.data)&&"result"in n.data&&n.data.result==="pending"||n.data.result==="ready")&&e(n)};return ze(this,ft,"f").window.addEventListener("message",r),()=>ze(this,ft,"f").window.removeEventListener("message",r)},Bm=function(e){ze(this,ft,"f").signerWindow.postMessage({jsonrpc:"2.0",id:e,method:"icrc29_status"},"*")};var fr=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},zc,Xr,$v,N1,Pm,v1;Xr=new WeakMap,zc=new WeakSet,$v=function(){let e=fr(this,zc,"m",Pm).call(this,n=>{n.source&&(e(),clearTimeout(r),fr(this,Xr,"f").onEstablish(n.origin,n.source),fr(this,zc,"m",N1).call(this,n.origin,n.source))}),r=setTimeout(()=>{e(),fr(this,Xr,"f").onEstablishTimeout()},fr(this,Xr,"f").establishTimeout)},N1=function(e,r){let n,s=()=>{clearTimeout(n),n=setTimeout(()=>{o(),fr(this,Xr,"f").onDisconnect()},fr(this,Xr,"f").disconnectTimeout)};s();let o=fr(this,zc,"m",Pm).call(this,i=>{i.origin===e&&i.source===r&&i.data.id!==void 0&&(s(),fr(this,zc,"m",v1).call(this,i.data.id,i.origin,i.source))})},Pm=function(e){let r=n=>{w1(n.data)&&n.data.method==="icrc29_status"&&(!fr(this,Xr,"f").allowedOrigin||fr(this,Xr,"f").allowedOrigin===n.origin)&&e(n)};return fr(this,Xr,"f").window.addEventListener("message",r),()=>fr(this,Xr,"f").window.removeEventListener("message",r)},v1=function(e,r,n){n.postMessage({jsonrpc:"2.0",id:e,result:fr(this,Xr,"f").status},r)};var Kv=function(t,e,r,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(t,r):s?s.value=r:e.set(t,r),r},_s=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Dr,Gv="https://github.com/slide-computer/signer-js/blob/main/packages/signer-web/README.md#channels-must-be-established-in-a-click-handler",ys=class t extends Error{constructor(e){super(e),Object.setPrototypeOf(this,t.prototype)}},Dm=!1;globalThis.window&&(globalThis.window.addEventListener("click",()=>Dm=!0,!0),globalThis.window.addEventListener("click",()=>Dm=!1));var Ll=class{constructor(e){if(Dr.set(this,void 0),!E1(e.url))throw new ys("Invalid signer RPC url");Kv(this,Dr,Object.assign({windowOpenerFeatures:"",window:globalThis.window,establishTimeout:12e4,pendingTimeout:3e5,disconnectTimeout:2e3,statusPollingRate:300,crypto:globalThis.crypto,manageFocus:!0,closeOnEstablishTimeout:!0,closeOnPendingTimeout:!0,detectNonClickEstablishment:!0},e),"f")}async establishChannel(){if(_s(this,Dr,"f").detectNonClickEstablishment&&!Dm)throw new ys(`Signer window should not be opened outside of click handler, see: ${Gv}`);let e=_s(this,Dr,"f").window.open(_s(this,Dr,"f").url,`${new URL(_s(this,Dr,"f").url).origin}-signer-window`,_s(this,Dr,"f").windowOpenerFeatures);if(!e)throw new ys("Signer window could not be opened");return new Promise((r,n)=>{let s;new Vl(Object.assign(Object.assign({},_s(this,Dr,"f")),{signerWindow:e,onEstablish:(o,i)=>{s=new Ul(Object.assign(Object.assign({},_s(this,Dr,"f")),{signerOrigin:o,signerWindow:e,signerStatus:i})),r(s)},onEstablishTimeout:()=>{_s(this,Dr,"f").closeOnEstablishTimeout&&e.close(),n(new ys("Communication channel could not be established within a reasonable time"))},onPendingTimeout:()=>{_s(this,Dr,"f").closeOnPendingTimeout&&e.close(),n(new ys("Communication channel was pending for too long"))},onDisconnect:()=>s.close(),onStatusChange:o=>s.changeStatus(o)}))})}};Dr=new WeakMap;var R1=["mousedown","mousemove","keydown","touchstart","wheel"],Yc=class t{callbacks=[];idleTimeout=600*1e3;timeoutID=void 0;static create(e={}){return new t(e)}constructor(e={}){let{onIdle:r,idleTimeout:n=600*1e3}=e||{};this.callbacks=r?[r]:[],this.idleTimeout=n;let s=this._resetTimer.bind(this);window.addEventListener("load",s,!0),R1.forEach(i=>{document.addEventListener(i,s,!0)});let o=(i,a)=>{let c;return(...d)=>{let f=this,l=()=>{c=void 0,i.apply(f,d)};clearTimeout(c),c=window.setTimeout(l,a)}};if(e?.captureScroll){let i=o(s,e?.scrollDebounce??100);window.addEventListener("scroll",i,!0)}s()}registerCallback(e){this.callbacks.push(e)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let e=this._resetTimer.bind(this);R1.forEach(r=>{document.removeEventListener(r,e,!0)}),this.callbacks.forEach(r=>{r()})}_resetTimer(){let e=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(e,this.idleTimeout)}};var Zv=(t,e)=>e.some(r=>t instanceof r),I1,S1;function zv(){return I1||(I1=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Yv(){return S1||(S1=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var A1=new WeakMap,Um=new WeakMap,B1=new WeakMap,Fm=new WeakMap,Lm=new WeakMap;function Wv(t){let e=new Promise((r,n)=>{let s=()=>{t.removeEventListener("success",o),t.removeEventListener("error",i)},o=()=>{r(Rn(t.result)),s()},i=()=>{n(t.error),s()};t.addEventListener("success",o),t.addEventListener("error",i)});return e.then(r=>{r instanceof IDBCursor&&A1.set(r,t)}).catch(()=>{}),Lm.set(e,t),e}function Xv(t){if(Um.has(t))return;let e=new Promise((r,n)=>{let s=()=>{t.removeEventListener("complete",o),t.removeEventListener("error",i),t.removeEventListener("abort",i)},o=()=>{r(),s()},i=()=>{n(t.error||new DOMException("AbortError","AbortError")),s()};t.addEventListener("complete",o),t.addEventListener("error",i),t.addEventListener("abort",i)});Um.set(t,e)}var Vm={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return Um.get(t);if(e==="objectStoreNames")return t.objectStoreNames||B1.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return Rn(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function C1(t){Vm=t(Vm)}function Jv(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(ql(this),e,...r);return B1.set(n,e.sort?e.sort():[e]),Rn(n)}:Yv().includes(t)?function(...e){return t.apply(ql(this),e),Rn(A1.get(this))}:function(...e){return Rn(t.apply(ql(this),e))}}function Qv(t){return typeof t=="function"?Jv(t):(t instanceof IDBTransaction&&Xv(t),Zv(t,zv())?new Proxy(t,Vm):t)}function Rn(t){if(t instanceof IDBRequest)return Wv(t);if(Fm.has(t))return Fm.get(t);let e=Qv(t);return e!==t&&(Fm.set(t,e),Lm.set(e,t)),e}var ql=t=>Lm.get(t);function D1(t,e,{blocked:r,upgrade:n,blocking:s,terminated:o}={}){let i=indexedDB.open(t,e),a=Rn(i);return n&&i.addEventListener("upgradeneeded",c=>{n(Rn(i.result),c.oldVersion,c.newVersion,Rn(i.transaction),c)}),r&&i.addEventListener("blocked",c=>r(c.oldVersion,c.newVersion,c)),a.then(c=>{o&&c.addEventListener("close",()=>o()),s&&c.addEventListener("versionchange",d=>s(d.oldVersion,d.newVersion,d))}).catch(()=>{}),a}var e5=["get","getKey","getAll","getAllKeys","count"],t5=["put","add","delete","clear"],qm=new Map;function P1(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(qm.get(e))return qm.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,s=t5.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(s||e5.includes(r)))return;let o=async function(i,...a){let c=this.transaction(i,s?"readwrite":"readonly"),d=c.store;return n&&(d=d.index(a.shift())),(await Promise.all([d[r](...a),s&&c.done]))[0]};return qm.set(e,o),o}C1(t=>({...t,get:(e,r,n)=>P1(e,r)||t.get(e,r,n),has:(e,r)=>!!P1(e,r)||t.has(e,r)}));var F1="auth-client-db",U1="ic-keyval",r5=async(t=F1,e=U1,r)=>(globalThis.localStorage?.getItem(pr)&&(globalThis.localStorage.removeItem(pr),globalThis.localStorage.removeItem(hr)),await D1(t,r,{upgrade:n=>{n.objectStoreNames.contains(e)&&n.clear(e),n.createObjectStore(e)}}));async function n5(t,e,r){return await t.get(e,r)}async function s5(t,e,r,n){return await t.put(e,n,r)}async function o5(t,e,r){return await t.delete(e,r)}var Ml=class t{constructor(e,r){this._db=e,this._storeName=r}static async create(e){let{dbName:r=F1,storeName:n=U1,version:s=V1}=e??{},o=await r5(r,n,s);return new t(o,n)}async set(e,r){return await s5(this._db,this._storeName,e,r)}async get(e){return await n5(this._db,this._storeName,e)??null}async remove(e){return await o5(this._db,this._storeName,e)}};var hr="identity",pr="delegation",L1="iv",V1=1,Wc=class{constructor(e="ic-",r){this.prefix=e,this._localStorage=r}get(e){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+e))}set(e,r){return this._getLocalStorage().setItem(this.prefix+e,r),Promise.resolve()}remove(e){return this._getLocalStorage().removeItem(this.prefix+e),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let e=globalThis.localStorage;if(!e)throw new Error("Could not find local storage.");return e}},bs=class{#e;constructor(e){this.#e=e??{}}initializedDb;get _db(){return new Promise((e,r)=>{if(this.initializedDb){e(this.initializedDb);return}Ml.create(this.#e).then(n=>{this.initializedDb=n,e(n)}).catch(r)})}async get(e){return await(await this._db).get(e)}async set(e,r){await(await this._db).set(e,r)}async remove(e){await(await this._db).remove(e)}};var i5=BigInt(1e9),a5=BigInt(3600),c5=i5*a5,u5="https://identity.internetcomputer.org",d5="#authorize",l5="https://id.ai/authorize",q1=BigInt(8)*c5,Mm="ECDSA",km="Ed25519",f5=500,kl="UserInterrupt",Xc=class t{constructor(e,r,n,s,o,i,a,c){this._identity=e,this._key=r,this._chain=n,this._storage=s,this.idleManager=o,this._createOptions=i,this._idpWindow=a,this._eventHandler=c,this._registerDefaultIdleCallback()}_signer=void 0;static async create(e={}){let r=e.storage??new bs,n=e.keyType??Mm,s=null;if(e.identity)s=e.identity;else{let c=await r.get(hr);if(!c)try{let d=new Wc,f=await d.get(pr),l=await d.get(hr);f&&l&&n===Mm&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await r.set(pr,f),await r.set(hr,l),c=f,await d.remove(pr),await d.remove(hr))}catch(d){console.error(`error while attempting to recover localstorage: ${d}`)}if(c)try{typeof c=="object"?n===km&&typeof c=="string"?s=Qo.fromJSON(c):s=await oo.fromKeyPair(c):typeof c=="string"&&(s=Qo.fromJSON(c))}catch{}}let o=new Ir,i=null;if(s)try{let c=await r.get(pr);if(typeof c=="object"&&c!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?o=e.identity:c&&(i=ps.fromJSON(c),Im(i)?"toDer"in s?o=ca.fromDelegation(s,i):o=ao.fromDelegation(s,i):(await jm(r),s=null))}catch(c){console.error(c),await jm(r),s=null}let a;return e.idleOptions?.disableIdle?a=void 0:(i||e.identity)&&(a=Yc.create(e.idleOptions)),s||(n===km?s=Qo.generate():(e.storage&&n===Mm&&console.warn(`You are using a custom storage provider that may not support CryptoKey storage. If you are using a custom storage provider that does not support CryptoKey storage, you should use '${km}' as the key type, as it can serialize to a string`),s=await oo.generate()),await k1(r,s)),new t(o,s,i,r,a,e)}_registerDefaultIdleCallback(){let e=this._createOptions?.idleOptions;!e?.onIdle&&!e?.disableDefaultIdleCallback&&this.idleManager?.registerCallback(()=>{this.logout(),location.reload()})}async _handleSuccess(e,r){let n=e.delegations.map(a=>({delegation:new io(a.delegation.pubkey,a.delegation.expiration,a.delegation.targets),signature:a.signature})),s=ps.fromDelegations(n,e.userPublicKey),o=this._key;if(!o)return;this._chain=s,"toDer"in o?this._identity=ca.fromDelegation(o,this._chain):this._identity=ao.fromDelegation(o,this._chain),this._idpWindow?.close();let i=this._createOptions?.idleOptions;!this.idleManager&&!i?.disableIdle&&(this.idleManager=Yc.create(i),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(pr,JSON.stringify(this._chain.toJSON())),await k1(this._storage,this._key),r?.(e)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null&&Im(this._chain)}async login(e){let r=M1(this._createOptions?.loginOptions,e),n=r?.maxTimeToLive??q1,s=new URL(r?.identityProvider?.toString()||u5);s.hash=d5,this._idpWindow?.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(s,{maxTimeToLive:n,...r}),window.addEventListener("message",this._eventHandler),this._idpWindow=window.open(s.toString(),"idpWindow",r?.windowOpenerFeatures)??void 0;let o=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(kl,r?.onError):setTimeout(o,f5))};o()}async loginWithIcrc29(e){let r=M1(this._createOptions?.loginOptions,e),n=r?.maxTimeToLive??q1,s=new URL(r?.identityProvider?.toString()||l5);this._signer?.closeChannel();let o=new Ll({url:s.toString(),windowOpenerFeatures:r?.windowOpenerFeatures});this._signer=new Dl({transport:o,derivationOrigin:r?.derivationOrigin?.toString()});let i=this._key;if(!i)return;let a=await this._signer.delegation({publicKey:this._key.getPublicKey().toDer(),maxTimeToLive:n});this._chain=a,"toDer"in i?this._identity=ca.fromDelegation(i,this._chain):this._identity=ao.fromDelegation(i,this._chain),this._chain&&await this._storage.set(pr,JSON.stringify(this._chain.toJSON())),e?.onSuccess?.({kind:"authorize-client-success",delegations:a.delegations,userPublicKey:this._key?.getPublicKey().toDer(),authnMethod:"passkey"})}_getEventHandler(e,r){return async n=>{if(n.origin!==e.origin)return;let s=n.data;switch(s.kind){case"authorize-ready":{let o={kind:"authorize-client",sessionPublicKey:new Uint8Array(this._key?.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,allowPinAuthentication:r?.allowPinAuthentication,derivationOrigin:r?.derivationOrigin?.toString(),...r?.customValues};this._idpWindow?.postMessage(o,e.origin);break}case"authorize-client-success":try{await this._handleSuccess(s,r?.onSuccess)}catch(o){this._handleFailure(o.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(s.text,r?.onError);break}}}_handleFailure(e,r){this._idpWindow?.close(),r?.(e),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(e={}){if(await jm(this._storage),this._identity=new Ir,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function jm(t){await t.remove(hr),await t.remove(pr),await t.remove(L1)}function M1(t,e){if(!t&&!e)return;let r=t?.customValues||e?.customValues?{...t?.customValues,...e?.customValues}:void 0;return{...t,...e,customValues:r}}function p5(t){if(t instanceof oo)return t.getKeyPair();if(t instanceof Qo)return JSON.stringify(t.toJSON());throw new Error("Unsupported key type")}async function k1(t,e){let r=p5(e);await t.set(hr,r)}var In=async({fn:t,step:e,onProgress:r})=>{r?.({step:e,state:"in_progress"});try{let n=await t();return r?.({step:e,state:"success"}),n}catch(n){throw r?.({step:e,state:"error"}),n}};var j1=(r=>(r[r.AuthorizingWithProvider=0]="AuthorizingWithProvider",r[r.CreatingOrRetrievingUser=1]="CreatingOrRetrievingUser",r))(j1||{});var jl=class extends Error{},ri=class extends Error{},Hl=class extends Error{},$l=class extends Error{},Kl=class extends Error{},Gl=class extends Error{},Zl=class extends Error{},zl=class extends Error{};var pa=class{async signIn({options:e,authClient:r,initAuth:n}){await In({fn:async()=>await this.#e({options:e,authClient:r}),step:0,onProgress:e?.onProgress}),await In({fn:async()=>await n({provider:this.id}),step:1,onProgress:e?.onProgress})}#e({options:e,authClient:r}){return new Promise(async(n,s)=>{if((0,H1.isNullish)(r)){s(new ri("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}await r.login({onSuccess:n,onError:o=>{if(o===kl){s(new Hl(o));return}s(new jl(o))},maxTimeToLive:e?.maxTimeToLiveInNanoseconds??u1,allowPinAuthentication:e?.allowPin??d1,...e?.derivationOrigin!==void 0&&{derivationOrigin:e.derivationOrigin},...this.signInOptions({windowed:e?.windowed})})})}};var Yl=class extends pa{#e;constructor({domain:e}){super(),this.#e=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let n=(()=>{let o=xr.getInstance().get()?.container;if((0,ni.isNullish)(o)||o===!1){let f=[Hc,h1].includes(this.#e??Hc);return(0,ni.isEmptyString)(this.#e)?`https://identity.${Hc}`:f?`https://identity.${this.#e??Hc}`:`https://${this.#e}`}let i=xr.getInstance().get(),a=(0,ni.nonNullish)(i)&&(0,ni.nonNullish)(i?.internetIdentityId)?i.internetIdentityId:i1,{host:c,protocol:d}=new URL(o===!0?oa:o);return/apple/i.test(navigator?.vendor)?`${d}//${c}?canisterId=${a}`:`${d}//${a}.${c.replace("127.0.0.1","localhost")}`})();return{...e!==!1&&{windowOpenerFeatures:Sl((()=>{try{let{hostname:o}=new URL(n);return o.includes(m1)}catch{return!1}})()?f1:l1)},identityProvider:n}}};var Wl=class extends pa{#e;#t;constructor({appName:e,logoUrl:r}){super(),this.#e=e,this.#t=r}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:Sl(p1)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#e)}&applicationLogo=${encodeURI(this.#t)}`}}};var ha=Fe(De(),1);var Sn={certified:!1};var $1=Fe(De(),1);var Xe=t=>(0,$1.nonNullish)(t)?t:Xl()??new Ir;var Jr=Fe(De(),1);var z1=Fe(De(),1);var h5=Fe(De(),1);var m5=Fe(De(),1);var K1=({IDL:t})=>{let e=t.Variant({Heap:t.Null,Stable:t.Null}),r=t.Record({system_memory:t.Opt(e)}),n=t.Record({controllers:t.Vec(t.Principal),storage:t.Opt(r)}),s=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),o=t.Record({sha256:t.Vec(t.Nat8),proposal_id:t.Nat}),i=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),a=t.Record({field:i,desc:t.Bool}),c=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),d=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(c),description:t.Opt(t.Text),created_at:t.Opt(c)}),f=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),l=t.Record({order:t.Opt(a),owner:t.Opt(t.Principal),matcher:t.Opt(d),paginate:t.Opt(f)}),u=t.Record({controllers:t.Vec(t.Principal)}),p=t.Variant({Write:t.Null,Admin:t.Null,Submit:t.Null}),h=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:p,expires_at:t.Opt(t.Nat64)}),m=t.Record({version:t.Opt(t.Nat64)}),b=t.Variant({Db:t.Null,Storage:t.Null}),y=t.Record({version:t.Opt(t.Nat64)}),x=t.Record({proposal_ids:t.Vec(t.Nat)}),_=t.Record({cycles:t.Nat,destination_id:t.Principal}),T=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),N=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),v=t.Record({key:T,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,N)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),R=t.Record({derivation_origin:t.Opt(t.Text),external_alternative_origins:t.Opt(t.Vec(t.Text))}),A=t.Record({allowed_callers:t.Vec(t.Principal)}),E=t.Record({updated_at:t.Opt(t.Nat64),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),internet_identity:t.Opt(R),rules:t.Opt(A)}),S=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),U=t.Record({updated_at:t.Opt(t.Nat64),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),max_memory_size:t.Opt(S)}),C=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),g=t.Variant({Deny:t.Null,Allow:t.Null}),w=t.Record({status_code:t.Nat16,location:t.Text}),O=t.Record({iframe:t.Opt(C),updated_at:t.Opt(t.Nat64),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),max_memory_size:t.Opt(S),raw_access:t.Opt(g),redirects:t.Opt(t.Vec(t.Tuple(t.Text,w)))}),P=t.Record({db:t.Opt(U),authentication:t.Opt(E),storage:O}),L=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),I=t.Variant({Initialized:t.Null,Failed:t.Null,Open:t.Null,Rejected:t.Null,Executed:t.Null,Accepted:t.Null}),B=t.Record({clear_existing_assets:t.Opt(t.Bool)}),F=t.Record({orbiter:t.Opt(t.Text),mission_control_version:t.Opt(t.Text),satellite_version:t.Opt(t.Text)}),V=t.Variant({AssetsUpgrade:B,SegmentsDeployment:F}),q=t.Record({status:I,updated_at:t.Nat64,sha256:t.Opt(t.Vec(t.Nat8)),executed_at:t.Opt(t.Nat64),owner:t.Principal,created_at:t.Nat64,version:t.Opt(t.Nat64),proposal_type:V}),H=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),z=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),G=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(e),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:H,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(z),write:H,max_changes_per_user:t.Opt(t.Nat32)}),ae=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),re=t.Record({memory:e,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),Ce=t.Variant({Callback:t.Record({token:re,callback:t.Func([],[],["query"])})}),se=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Ce),status_code:t.Nat16}),me=t.Record({token:t.Opt(re),body:t.Vec(t.Nat8)}),It=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),jt=t.Record({batch_id:t.Nat}),wr=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,v)),items_length:t.Nat64}),An=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),gs=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,L)),items_length:t.Nat64}),ya=t.Record({desc:t.Bool}),_a=t.Record({start_after:t.Opt(t.Nat),limit:t.Opt(t.Nat)}),oi=t.Record({order:t.Opt(ya),paginate:t.Opt(_a)}),ii=t.Record({proposal_id:t.Nat}),ba=t.Record({matches_length:t.Nat64,items:t.Vec(t.Tuple(ii,q)),items_length:t.Nat64}),D=t.Record({include_system:t.Bool}),j=t.Record({matcher:t.Opt(D)}),ie=t.Record({matches_length:t.Nat64,items:t.Vec(t.Tuple(t.Text,G)),items_length:t.Nat64}),St=t.Record({stable:t.Nat64,heap:t.Nat64}),At=t.Record({version:t.Opt(t.Nat64),internet_identity:t.Opt(R),rules:t.Opt(A)}),Tt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:p,expires_at:t.Opt(t.Nat64)}),xs=t.Record({controller:Tt,controllers:t.Vec(t.Principal)}),Bn=t.Record({version:t.Opt(t.Nat64),max_memory_size:t.Opt(S)}),ws=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),tf=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(e),max_size:t.Opt(t.Nat),read:H,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(z),write:H,max_changes_per_user:t.Opt(t.Nat32)}),rf=t.Record({iframe:t.Opt(C),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),version:t.Opt(t.Nat64),max_memory_size:t.Opt(S),raw_access:t.Opt(g),redirects:t.Opt(t.Vec(t.Tuple(t.Text,w)))}),ga=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),xa=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([s],[],[]),commit_proposal:t.Func([o],[t.Null],[]),commit_proposal_asset_upload:t.Func([s],[],[]),commit_proposal_many_assets_upload:t.Func([t.Vec(s)],[],[]),count_assets:t.Func([t.Text,l],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,l],[t.Nat64],["query"]),count_proposals:t.Func([],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([u],[t.Vec(t.Tuple(t.Principal,h))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,m],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,l],[],[]),del_filtered_docs:t.Func([t.Text,l],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,m))],[],[]),del_rule:t.Func([b,t.Text,y],[],[]),delete_proposal_assets:t.Func([x],[],[]),deposit_cycles:t.Func([_],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(v)],["query"]),get_auth_config:t.Func([],[t.Opt(E)],["query"]),get_config:t.Func([],[P],[]),get_db_config:t.Func([],[t.Opt(U)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(L)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(v)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(L)))],["query"]),get_proposal:t.Func([t.Nat],[t.Opt(q)],["query"]),get_rule:t.Func([b,t.Text],[t.Opt(G)],["query"]),get_storage_config:t.Func([],[O],["query"]),http_request:t.Func([ae],[se],["query"]),http_request_streaming_callback:t.Func([re],[me],["query"]),init_asset_upload:t.Func([It],[jt],[]),init_proposal:t.Func([V],[t.Nat,q],[]),init_proposal_asset_upload:t.Func([It,t.Nat],[jt],[]),init_proposal_many_assets_upload:t.Func([t.Vec(It),t.Nat],[t.Vec(t.Tuple(t.Text,jt))],[]),list_assets:t.Func([t.Text,l],[wr],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,h))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,An))],["query"]),list_docs:t.Func([t.Text,l],[gs],["query"]),list_proposals:t.Func([oi],[ba],["query"]),list_rules:t.Func([b,j],[ie],["query"]),memory_size:t.Func([],[St],["query"]),reject_proposal:t.Func([o],[t.Null],[]),set_auth_config:t.Func([At],[E],[]),set_controllers:t.Func([xs],[t.Vec(t.Tuple(t.Principal,h))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([Bn],[U],[]),set_doc:t.Func([t.Text,t.Text,ws],[L],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,ws))],[t.Vec(t.Tuple(t.Text,L))],[]),set_rule:t.Func([b,t.Text,tf],[G],[]),set_storage_config:t.Func([rf],[O],[]),submit_proposal:t.Func([t.Nat],[t.Nat,q],[]),switch_storage_system_memory:t.Func([],[],[]),upload_asset_chunk:t.Func([ga],[xa],[]),upload_proposal_asset_chunk:t.Func([ga],[xa],[])})},G1=({IDL:t})=>{let e=t.Variant({Heap:t.Null,Stable:t.Null}),r=t.Record({system_memory:t.Opt(e)}),n=t.Record({controllers:t.Vec(t.Principal),storage:t.Opt(r)}),s=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),o=t.Record({sha256:t.Vec(t.Nat8),proposal_id:t.Nat}),i=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),a=t.Record({field:i,desc:t.Bool}),c=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),d=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(c),description:t.Opt(t.Text),created_at:t.Opt(c)}),f=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),l=t.Record({order:t.Opt(a),owner:t.Opt(t.Principal),matcher:t.Opt(d),paginate:t.Opt(f)}),u=t.Record({controllers:t.Vec(t.Principal)}),p=t.Variant({Write:t.Null,Admin:t.Null,Submit:t.Null}),h=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:p,expires_at:t.Opt(t.Nat64)}),m=t.Record({version:t.Opt(t.Nat64)}),b=t.Variant({Db:t.Null,Storage:t.Null}),y=t.Record({version:t.Opt(t.Nat64)}),x=t.Record({proposal_ids:t.Vec(t.Nat)}),_=t.Record({cycles:t.Nat,destination_id:t.Principal}),T=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),N=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),v=t.Record({key:T,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,N)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),R=t.Record({derivation_origin:t.Opt(t.Text),external_alternative_origins:t.Opt(t.Vec(t.Text))}),A=t.Record({allowed_callers:t.Vec(t.Principal)}),E=t.Record({updated_at:t.Opt(t.Nat64),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),internet_identity:t.Opt(R),rules:t.Opt(A)}),S=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),U=t.Record({updated_at:t.Opt(t.Nat64),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),max_memory_size:t.Opt(S)}),C=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),g=t.Variant({Deny:t.Null,Allow:t.Null}),w=t.Record({status_code:t.Nat16,location:t.Text}),O=t.Record({iframe:t.Opt(C),updated_at:t.Opt(t.Nat64),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),created_at:t.Opt(t.Nat64),version:t.Opt(t.Nat64),max_memory_size:t.Opt(S),raw_access:t.Opt(g),redirects:t.Opt(t.Vec(t.Tuple(t.Text,w)))}),P=t.Record({db:t.Opt(U),authentication:t.Opt(E),storage:O}),L=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),I=t.Variant({Initialized:t.Null,Failed:t.Null,Open:t.Null,Rejected:t.Null,Executed:t.Null,Accepted:t.Null}),B=t.Record({clear_existing_assets:t.Opt(t.Bool)}),F=t.Record({orbiter:t.Opt(t.Text),mission_control_version:t.Opt(t.Text),satellite_version:t.Opt(t.Text)}),V=t.Variant({AssetsUpgrade:B,SegmentsDeployment:F}),q=t.Record({status:I,updated_at:t.Nat64,sha256:t.Opt(t.Vec(t.Nat8)),executed_at:t.Opt(t.Nat64),owner:t.Principal,created_at:t.Nat64,version:t.Opt(t.Nat64),proposal_type:V}),H=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),z=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),G=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(e),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:H,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(z),write:H,max_changes_per_user:t.Opt(t.Nat32)}),ae=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),re=t.Record({memory:e,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),Ce=t.Variant({Callback:t.Record({token:re,callback:t.Func([],[],[])})}),se=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Ce),status_code:t.Nat16}),me=t.Record({token:t.Opt(re),body:t.Vec(t.Nat8)}),It=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),jt=t.Record({batch_id:t.Nat}),wr=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,v)),items_length:t.Nat64}),An=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),gs=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,L)),items_length:t.Nat64}),ya=t.Record({desc:t.Bool}),_a=t.Record({start_after:t.Opt(t.Nat),limit:t.Opt(t.Nat)}),oi=t.Record({order:t.Opt(ya),paginate:t.Opt(_a)}),ii=t.Record({proposal_id:t.Nat}),ba=t.Record({matches_length:t.Nat64,items:t.Vec(t.Tuple(ii,q)),items_length:t.Nat64}),D=t.Record({include_system:t.Bool}),j=t.Record({matcher:t.Opt(D)}),ie=t.Record({matches_length:t.Nat64,items:t.Vec(t.Tuple(t.Text,G)),items_length:t.Nat64}),St=t.Record({stable:t.Nat64,heap:t.Nat64}),At=t.Record({version:t.Opt(t.Nat64),internet_identity:t.Opt(R),rules:t.Opt(A)}),Tt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:p,expires_at:t.Opt(t.Nat64)}),xs=t.Record({controller:Tt,controllers:t.Vec(t.Principal)}),Bn=t.Record({version:t.Opt(t.Nat64),max_memory_size:t.Opt(S)}),ws=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),tf=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(e),max_size:t.Opt(t.Nat),read:H,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(z),write:H,max_changes_per_user:t.Opt(t.Nat32)}),rf=t.Record({iframe:t.Opt(C),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),version:t.Opt(t.Nat64),max_memory_size:t.Opt(S),raw_access:t.Opt(g),redirects:t.Opt(t.Vec(t.Tuple(t.Text,w)))}),ga=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),xa=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([s],[],[]),commit_proposal:t.Func([o],[t.Null],[]),commit_proposal_asset_upload:t.Func([s],[],[]),commit_proposal_many_assets_upload:t.Func([t.Vec(s)],[],[]),count_assets:t.Func([t.Text,l],[t.Nat64],[]),count_collection_assets:t.Func([t.Text],[t.Nat64],[]),count_collection_docs:t.Func([t.Text],[t.Nat64],[]),count_docs:t.Func([t.Text,l],[t.Nat64],[]),count_proposals:t.Func([],[t.Nat64],[]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([u],[t.Vec(t.Tuple(t.Principal,h))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,m],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,l],[],[]),del_filtered_docs:t.Func([t.Text,l],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,m))],[],[]),del_rule:t.Func([b,t.Text,y],[],[]),delete_proposal_assets:t.Func([x],[],[]),deposit_cycles:t.Func([_],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(v)],[]),get_auth_config:t.Func([],[t.Opt(E)],[]),get_config:t.Func([],[P],[]),get_db_config:t.Func([],[t.Opt(U)],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(L)],[]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(v)))],[]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(L)))],[]),get_proposal:t.Func([t.Nat],[t.Opt(q)],[]),get_rule:t.Func([b,t.Text],[t.Opt(G)],[]),get_storage_config:t.Func([],[O],[]),http_request:t.Func([ae],[se],[]),http_request_streaming_callback:t.Func([re],[me],[]),init_asset_upload:t.Func([It],[jt],[]),init_proposal:t.Func([V],[t.Nat,q],[]),init_proposal_asset_upload:t.Func([It,t.Nat],[jt],[]),init_proposal_many_assets_upload:t.Func([t.Vec(It),t.Nat],[t.Vec(t.Tuple(t.Text,jt))],[]),list_assets:t.Func([t.Text,l],[wr],[]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,h))],[]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,An))],[]),list_docs:t.Func([t.Text,l],[gs],[]),list_proposals:t.Func([oi],[ba],[]),list_rules:t.Func([b,j],[ie],[]),memory_size:t.Func([],[St],[]),reject_proposal:t.Func([o],[t.Null],[]),set_auth_config:t.Func([At],[E],[]),set_controllers:t.Func([xs],[t.Vec(t.Tuple(t.Principal,h))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([Bn],[U],[]),set_doc:t.Func([t.Text,t.Text,ws],[L],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,ws))],[t.Vec(t.Tuple(t.Text,L))],[]),set_rule:t.Func([b,t.Text,tf],[G],[]),set_storage_config:t.Func([rf],[O],[]),submit_proposal:t.Func([t.Nat],[t.Nat,q],[]),switch_storage_system_memory:t.Func([],[],[]),upload_asset_chunk:t.Func([ga],[xa],[]),upload_proposal_asset_chunk:t.Func([ga],[xa],[])})};var Jl=Fe(De(),1);var Z1=({satelliteId:t,container:e})=>{let{satelliteId:r}=Hm({satelliteId:t}),{container:n}=$m({container:e});if((0,Jl.nonNullish)(n)&&n!==!1){let{host:s,protocol:o}=new URL(n===!0?oa:n);return`${o}//${r??"unknown"}.${s.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},Hm=({satelliteId:t})=>(0,Jl.nonNullish)(t)?{satelliteId:t}:xr.getInstance().get()??{satelliteId:void 0},$m=({container:t})=>(0,Jl.nonNullish)(t)?{container:t}:xr.getInstance().get()??{container:void 0};var pt=({satellite:t,options:{certified:e}})=>W1({idlFactory:e?G1:K1,actorKey:`stock#${e?"update":"query"}`,...t}),Y1=({idlFactory:t,...e})=>W1({idlFactory:t,actorKey:"extended#query",...e}),W1=async({satelliteId:t,container:e,...r})=>{let{satelliteId:n}=Hm({satelliteId:t});(0,z1.assertNonNullish)(n,"No satellite ID defined. Did you initialize Juno?");let{container:s}=$m({container:e});return await aa.getInstance().getActor({satelliteId:n,container:s,...r})};var it=Fe(De(),1);var X1=t=>{if((0,it.isNullish)(t))return(0,it.toNullable)();switch(t.matcher){case"equal":return(0,it.toNullable)({Equal:t.timestamp});case"greaterThan":return(0,it.toNullable)({GreaterThan:t.timestamp});case"lessThan":return(0,it.toNullable)({LessThan:t.timestamp});case"between":return(0,it.toNullable)({Between:[t.timestamps.start,t.timestamps.end]});default:throw new zl("Invalid list matcher for timestamp",t)}},uo=({matcher:t,paginate:e,order:r,owner:n})=>({matcher:(0,it.isNullish)(t)?[]:[{key:(0,it.toNullable)(t.key),description:(0,it.toNullable)(t.description),created_at:X1(t.createdAt),updated_at:X1(t.updatedAt)}],paginate:(0,it.toNullable)((0,it.isNullish)(e)?void 0:{start_after:(0,it.toNullable)(e.startAfter),limit:(0,it.toNullable)((0,it.isNullish)(e.limit)?void 0:BigInt(e.limit))}),order:(0,it.toNullable)((0,it.isNullish)(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:(0,it.toNullable)((0,it.isNullish)(n)?void 0:typeof n=="string"?te.fromText(n):n)});var J1=async({data:t})=>{try{return await Rl(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var si=Fe(De(),1);var Km=async t=>{let{data:e,version:r,description:n}=t;return{description:(0,si.toNullable)(n),data:await y1(e),version:(0,si.toNullable)(r)}},Gm=t=>{let{version:e}=t;return{version:(0,si.toNullable)(e)}},Jc=async({doc:t,key:e})=>{let{owner:r,version:n,description:s,data:o,...i}=t;return{key:e,description:(0,si.fromNullable)(s),owner:r.toText(),data:await Rl(o),version:(0,si.fromNullable)(n),...i}};var Q1=async({collection:t,key:e,...r})=>{let{get_doc:n}=await pt(r),s=(0,Jr.fromNullable)(await n(t,e));if(!(0,Jr.isNullish)(s))return Jc({doc:s,key:e})},e2=async({docs:t,...e})=>{let{get_many_docs:r}=await pt(e),n=t.map(({collection:i,key:a})=>[i,a]),s=await r(n),o=[];for(let[i,a]of s){let c=(0,Jr.fromNullable)(a);o.push((0,Jr.nonNullish)(c)?await Jc({key:i,doc:c}):void 0)}return o},t2=async({collection:t,doc:e,...r})=>{let{set_doc:n}=await pt(r),{key:s}=e,o=await Km(e),i=await n(t,s,o);return await Jc({key:s,doc:i})},r2=async({docs:t,...e})=>{let{set_many_docs:r}=await pt(e),n=[];for(let{collection:i,doc:a}of t){let{key:c}=a;n.push([i,c,await Km(a)])}let s=await r(n),o=[];for(let[i,a]of s)o.push(await Jc({key:i,doc:a}));return o},n2=async({collection:t,doc:e,...r})=>{let{del_doc:n}=await pt(r),{key:s}=e;return n(t,s,Gm(e))},s2=async({docs:t,...e})=>{let{del_many_docs:r}=await pt(e),n=t.map(({collection:s,doc:o})=>[s,o.key,Gm(o)]);await r(n)},o2=async({collection:t,filter:e,...r})=>{let{del_filtered_docs:n}=await pt(r);return n(t,uo(e))},i2=async({collection:t,filter:e,...r})=>{let{list_docs:n}=await pt(r),{items:s,items_page:o,items_length:i,matches_length:a,matches_pages:c}=await n(t,uo(e)),d=[];for(let[f,l]of s){let{data:u,owner:p,description:h,version:m,...b}=l;d.push({key:f,description:(0,Jr.fromNullable)(h),owner:p.toText(),data:await J1({data:u}),version:(0,Jr.fromNullable)(m),...b})}return{items:d,items_length:i,items_page:(0,Jr.fromNullable)(o),matches_length:a,matches_pages:(0,Jr.fromNullable)(c)}},a2=async({collection:t,filter:e,...r})=>{let{count_docs:n}=await pt(r);return n(t,uo(e))};var Ql=async({satellite:t,options:e,...r})=>{let n=Xe(t?.identity);return await Q1({...r,satellite:{...t,identity:n},options:e??Sn})},VC=async({satellite:t,options:e,...r})=>{let n=Xe(t?.identity);return await e2({...r,satellite:{...t,identity:n},options:e??Sn})},c2=async({satellite:t,...e})=>{let r=Xe(t?.identity);return await t2({...e,satellite:{...t,identity:r},options:{certified:!0}})},u2=async({satellite:t,...e})=>{let r=Xe(t?.identity);return await r2({...e,satellite:{...t,identity:r},options:{certified:!0}})},LC=async({satellite:t,...e})=>{let r=Xe(t?.identity);return await n2({...e,satellite:{...t,identity:r},options:{certified:!0}})},qC=async({satellite:t,...e})=>{let r=Xe(t?.identity);return await s2({...e,satellite:{...t,identity:r},options:{certified:!0}})},MC=async({satellite:t,filter:e,...r})=>{let n=Xe(t?.identity);return await o2({...r,filter:e??{},satellite:{...t,identity:n},options:{certified:!0}})},kC=async({satellite:t,options:e,filter:r,...n})=>{let s=Xe(t?.identity);return await i2({...n,filter:r??{},satellite:{...t,identity:s},options:e??Sn})},jC=async({satellite:t,options:e,filter:r,...n})=>{let s=Xe(t?.identity);return await a2({...n,filter:r??{},satellite:{...t,identity:s},options:e??Sn})};var ef=Fe(De(),1);var d2=async({delegationIdentity:t,passkeyIdentity:e,satelliteId:r})=>{let n=e.getCredential().getAAGUID(),[s,o]=await u2({docs:[{collection:"#user",doc:{key:t.getPrincipal().toText(),data:{provider:"webauthn",providerData:{webauthn:{...(0,ef.nonNullish)(n)&&{aaguid:(0,ef.uint8ArrayToArrayOfNumber)(n)}}}}}},{collection:"#user-webauthn",doc:{key:e.getCredential().getCredentialIdText(),data:{publicKey:e.getPublicKey().toRaw()}}}],satellite:{identity:t,satelliteId:r}});return s};var l2=(o=>(o[o.RequestingUserCredential=0]="RequestingUserCredential",o[o.FinalizingCredential=1]="FinalizingCredential",o[o.Signing=2]="Signing",o[o.FinalizingSession=3]="FinalizingSession",o[o.RetrievingUser=4]="RetrievingUser",o))(l2||{}),f2=(i=>(i[i.CreatingUserCredential=0]="CreatingUserCredential",i[i.ValidatingUserCredential=1]="ValidatingUserCredential",i[i.FinalizingCredential=2]="FinalizingCredential",i[i.Signing=3]="Signing",i[i.FinalizingSession=4]="FinalizingSession",i[i.RegisteringUser=5]="RegisteringUser",i))(f2||{});var Qc=class{get id(){return"webauthn"}async signUp({options:{onProgress:e,maxTimeToLiveInMilliseconds:r,passkey:n}={},loadAuthWithUser:s}){let{satelliteId:o}=xr.getInstance().get()??{satelliteId:void 0};if((0,ha.isNullish)(o))throw new ri("Satellite ID not set. Have you initialized the Satellite?");let i=({step:m,state:b})=>{switch(m){case so.RequestingUserCredential:e?.({step:1,state:b});break;case so.FinalizingCredential:e?.({step:2,state:b});break;case so.Signing:e?.({step:3,state:b});break}},c=await In({fn:async()=>await wm.createWithNewCredential({onProgress:i,passkeyOptions:n}),step:0,onProgress:e}),{delegationIdentity:d,sessionKey:f}=await this.#e({identity:c,maxTimeToLiveInMilliseconds:r}),u=await In({fn:async()=>await d2({delegationIdentity:d,passkeyIdentity:c,satelliteId:o}),step:5,onProgress:e});await In({fn:async()=>await this.#t({delegationIdentity:d,sessionKey:f}),step:4,onProgress:e}),await In({fn:async()=>await s({user:u}),step:5,onProgress:e})}async signIn({options:{onProgress:e,maxTimeToLiveInMilliseconds:r}={},loadAuth:n}){let{satelliteId:s}=xr.getInstance().get()??{satelliteId:void 0};if((0,ha.isNullish)(s))throw new ri("Satellite ID not set. Have you initialized the Satellite?");let o=async({credentialId:l})=>{let u=await Ql({collection:"#user-webauthn",key:(0,ha.uint8ArrayToBase64)(l),options:{certified:!0},satellite:{identity:new Ir,satelliteId:s}});if((0,ha.isNullish)(u))throw new Kl("No public key found for the selected passkey.");let{data:p}=u,{publicKey:h}=p;return Xo(h,kc)},i=({step:l,state:u})=>{switch(l){case so.RequestingUserCredential:e?.({step:0,state:u});break;case so.FinalizingCredential:e?.({step:1,state:u});break;case so.Signing:e?.({step:2,state:u});break}},a=await wm.createWithExistingCredential({retrievePublicKey:o,onProgress:i}),{delegationIdentity:c,sessionKey:d}=await this.#e({identity:a,maxTimeToLiveInMilliseconds:r});await In({fn:async()=>await this.#t({delegationIdentity:c,sessionKey:d}),step:3,onProgress:e}),await In({fn:n,step:4,onProgress:e})}async#e({identity:e,maxTimeToLiveInMilliseconds:r}){let n=await oo.generate({extractable:!1}),s=r??144e5,o=await ps.create(e,n.getPublicKey(),new Date(Date.now()+s));return{delegationIdentity:ao.fromDelegation(n,o),sessionKey:n}}async#t({sessionKey:e,delegationIdentity:r}){let n=new bs;await Promise.all([n.set(hr,e.getKeyPair()),n.set(pr,JSON.stringify(r.getDelegation().toJSON()))])}};var eu=()=>Xc.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}}),p2=async()=>(await new bs().remove(hr),await eu());var tu=Fe(De(),1);var Zm=({error:t,type:e})=>typeof t=="string"?t.includes(e):t instanceof Error?t.message.includes(e):!1;var h2="juno.datastore.error.user.cannot_update";var m2=async({provider:t})=>{let{user:e,userId:r}=await zm();if((0,tu.nonNullish)(e))return e;try{return await _5({userId:r,provider:t})}catch(n){if(Zm({error:n,type:h2})){let s=await y2({userId:r});if((0,tu.nonNullish)(s))return s}throw n}},zm=async()=>{let t=Xl();if((0,tu.isNullish)(t))throw new Zl("No identity to initialize the user. Have you initialized Juno?");let e=t.getPrincipal().toText(),r=await y2({userId:e});return{userId:e,user:r}},y2=({userId:t})=>Ql({collection:"#user",key:t}),_5=({userId:t,...e})=>c2({collection:"#user",doc:{key:t,data:e}});var Fr,Ym=async()=>{await Wm({fn:async()=>{let{user:e}=await zm();Pr.getInstance().set(e??null)}})},b5=async({user:t})=>{await Wm({fn:async()=>{Pr.getInstance().set(t)}})},_2=async({provider:t})=>{await Wm({fn:async()=>{let r=await m2({provider:t});Pr.getInstance().set(r)}})},Wm=async({fn:t})=>{if(Fr=await eu(),!await Fr.isAuthenticated()){Fr=await p2();return}await t()},g5=async t=>{let e=async()=>await w5(t);if(Object.values(t)[0].context?.windowGuard===!1){await e();return}await Om({fn:e})},x5=async t=>{let e=async()=>await E5(t);if(Object.values(t)?.[0].context?.windowGuard===!1){await e();return}await Om({fn:e})},w5=async t=>{if("webauthn"in t){let{webauthn:{options:e}}=t;await new Qc().signIn({options:e,loadAuth:Ym});return}if("nfid"in t){let{nfid:{options:e}}=t,{appName:r,logoUrl:n,...s}=e??{};await new Wl({appName:r,logoUrl:n}).signIn({options:s,authClient:Fr,initAuth:_2});return}if("internet_identity"in t){let{internet_identity:{options:e}}=t,{domain:r,...n}=e??{};await new Yl({domain:r}).signIn({options:n,authClient:Fr,initAuth:_2});return}throw new $l("An unknown or unsupported provider was provided for sign-in.")},E5=async t=>{if("webauthn"in t){let{webauthn:{options:e}}=t;await new Qc().signUp({options:e,loadAuthWithUser:b5});return}throw new Gl("An unknown or unsupported provider was provided for sign-up.")},Xm=async t=>{await T5(),Fr=await eu(),t?.windowReload!==!1&&window.location.reload()},T5=async()=>{await Fr?.logout(),Fr=null,Pr.getInstance().reset(),aa.getInstance().reset(),ia.getInstance().reset()},Xl=()=>Fr?.getIdentity(),O5=async()=>(Fr??await eu()).getIdentity(),N5=async()=>{let t=Pr.getInstance().get();return(0,b2.isNullish)(t)||!(await Fr?.isAuthenticated()??!1)?null:Fr?.getIdentity()??null};var x2=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),n=async()=>{Em({message:"junoSignOutAuthTimer"}),await Xm()};return r.onmessage=async({data:s})=>{let{msg:o,data:i}=s;switch(o){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":Em({message:"junoDelegationRemainingTime",detail:i?.authRemainingTime});return}},Pr.getInstance().subscribe(s=>{if((0,g2.isNullish)(s)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var w2=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_SATELLITE_ID??t():t()},E2=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_CONTAINER??t():t()};var PP=async({idlFactory:t,satellite:e})=>{let r=Xe(e?.identity);return await Y1({idlFactory:t,...e,identity:r})};var nu=Fe(De(),1);var ru=Fe(De(),1);var ma=Fe(De(),1);var T2=async({asset:{data:t,headers:e,...r},actor:n,progress:s})=>{let{init_asset_upload:o,upload_asset_chunk:i,commit_asset_upload:a}=n,{batch_id:c}=await o(v5(r));s?.onInitiatedBatch();let{chunkIds:d}=await S5({data:t,uploadFn:i,batchId:c});s?.onUploadedFileChunks(r.fullPath),await I5({commitFn:a,batchId:c,data:t,headers:e,chunkIds:d}),s?.onCommittedBatch()};var v5=({filename:t,collection:e,token:r,fullPath:n,encoding:s,description:o})=>({collection:e,full_path:n,name:t,token:(0,ma.toNullable)(r),encoding_type:(0,ma.toNullable)(s),description:(0,ma.toNullable)(o)}),R5=({batchId:t,chunkIds:e,headers:r,data:n})=>{let s=r.find(([o,i])=>o.toLowerCase()==="content-type")===void 0&&n.type!==void 0&&n.type!==""?[["Content-Type",n.type]]:void 0;return{batch_id:t,chunk_ids:e.map(({chunk_id:o})=>o),headers:[...r,...s??[]]}},I5=async({commitFn:t,...e})=>{let r=R5(e);await t(r)},S5=async({data:t,uploadFn:e,batchId:r})=>{let n=[],s=Il()?new Blob([await t.arrayBuffer()]):t,o=0n;for(let a=0;a<s.size;a+=19e5){let c=s.slice(a,a+19e5);n.push({batchId:r,chunk:c,uploadFn:e,orderId:o}),o++}let i=[];for await(let a of A5({uploadChunks:n}))i=[...i,...a];return{chunkIds:i}};async function*A5({uploadChunks:t,limit:e=12}){for(let r=0;r<t.length;r=r+e){let n=t.slice(r,r+e);yield await Promise.all(n.map(s=>B5(s)))}}var B5=async({batchId:t,chunk:e,uploadFn:r,orderId:n})=>r({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:(0,ma.toNullable)(n)});var O2=async({asset:t,...e})=>{let r=await pt(e);await T2({actor:r,asset:t})},N2=async({collection:t,filter:e,...r})=>{let{list_assets:n}=await pt(r),{items:s,items_length:o,items_page:i,matches_length:a,matches_pages:c}=await n(t,uo(e));return{items:s.map(([d,f])=>f),items_length:o,items_page:(0,ru.fromNullable)(i),matches_length:a,matches_pages:(0,ru.fromNullable)(c)}},v2=async({collection:t,filter:e,...r})=>{let{count_assets:n}=await pt(r);return n(t,uo(e))},R2=async({collection:t,fullPath:e,...r})=>(await pt(r)).del_asset(t,e),I2=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await pt({satellite:e,options:{certified:!0}}),n=t.map(({collection:s,fullPath:o})=>[s,o]);await r(n)},S2=async({collection:t,filter:e,...r})=>{let{del_filtered_assets:n}=await pt(r);return n(t,uo(e))},A2=async({collection:t,fullPath:e,...r})=>{let{get_asset:n}=await pt(r);return(0,ru.fromNullable)(await n(t,e))},B2=async({assets:t,...e})=>{let{get_many_assets:r}=await pt(e),n=t.map(({collection:o,fullPath:i})=>[o,i]);return(await r(n)).map(([o,i])=>(0,ru.fromNullable)(i))};var C2=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var ZP=t=>P2(t),zP=t=>P2({filename:t.data.name,...t}),P2=async({filename:t,data:e,collection:r,headers:n=[],fullPath:s,token:o,satellite:i,encoding:a,description:c})=>{let d=Xe(i?.identity),f=decodeURI(t),l=s??`/${r}/${f}`,u={...i,identity:d};return await O2({asset:{data:e,filename:f,collection:r,token:o,headers:n,fullPath:l,encoding:a,description:c},satellite:u,options:{certified:!0}}),{downloadUrl:D2({satellite:u,assetKey:{fullPath:l,token:o}}),fullPath:l,name:f}},YP=async({collection:t,filter:e,satellite:r,options:n})=>{let s={...r,identity:Xe(r?.identity)},{items:o,...i}=await N2({collection:t,filter:e??{},satellite:s,options:n??Sn}),a=o.map(({key:{full_path:c,token:d,name:f,owner:l,description:u},headers:p,encodings:h,created_at:m,updated_at:b})=>{let y=(0,nu.fromNullable)(d);return{fullPath:c,description:(0,nu.fromNullable)(u),name:f,downloadUrl:D2({satellite:s,assetKey:{fullPath:c,token:y}}),token:y,headers:p,encodings:h.reduce((x,[_,{modified:T,sha256:N,total_length:v}])=>({...x,[_]:{modified:T,sha256:C2(N),total_length:v}}),{}),owner:l.toText(),created_at:m,updated_at:b}});return{items:a,assets:a,...i}},WP=async({collection:t,filter:e,satellite:r,options:n})=>{let s={...r,identity:Xe(r?.identity)};return await v2({collection:t,satellite:s,filter:e??{},options:n??Sn})},XP=({collection:t,fullPath:e,satellite:r})=>R2({collection:t,fullPath:e,satellite:{...r,identity:Xe(r?.identity)},options:{certified:!0}}),JP=({assets:t,satellite:e})=>I2({assets:t,satellite:{...e,identity:Xe(e?.identity)},options:{certified:!0}}),QP=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:Xe(e?.identity)};return await S2({collection:t,satellite:n,filter:r??{},options:{certified:!0}})},eD=async({satellite:t,options:e,...r})=>{let n=Xe(t?.identity);return await A2({...r,satellite:{...t,identity:n},options:e??Sn})},tD=async({satellite:t,options:e,...r})=>{let n=Xe(t?.identity);return await B2({...r,satellite:{...t,identity:n},options:e??Sn})},D2=({assetKey:{fullPath:t,token:e},satellite:r})=>{let n={...r,identity:Xe(r?.identity)};return`${Z1(n)}${t}${(0,nu.nonNullish)(e)?`?token=${e}`:""}`};var C5=t=>{let e=t?.satelliteId??w2();(0,F2.assertNonNullish)(e,"Satellite ID is not configured. Juno cannot be initialized.");let r=t?.container??E2();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:r}},uD=t=>P5(t),P5=async t=>{let e=C5(t);xr.getInstance().set(e),await Ym();let r=e.workers?.auth!==void 0?x2(e.workers.auth):void 0;return[...r?[r]:[]]},D5=t=>Pr.getInstance().subscribe(t),dD=D5;export{j1 as AuthClientSignInProgressStep,Zl as InitError,Yl as InternetIdentityProvider,zl as ListError,Wl as NFIDProvider,jl as SignInError,ri as SignInInitError,$l as SignInProviderNotSupportedError,Hl as SignInUserInterruptError,Gl as SignUpProviderNotSupportedError,l2 as WebAuthnSignInProgressStep,Kl as WebAuthnSignInRetrievePublicKeyError,f2 as WebAuthnSignUpProgressStep,dD as authSubscribe,WP as countAssets,jC as countDocs,XP as deleteAsset,LC as deleteDoc,QP as deleteFilteredAssets,MC as deleteFilteredDocs,JP as deleteManyAssets,qC as deleteManyDocs,D2 as downloadUrl,eD as getAsset,Ql as getDoc,N5 as getIdentityOnce,tD as getManyAssets,VC as getManyDocs,PP as getSatelliteExtendedActor,uD as initJuno,P5 as initSatellite,Mv as isWebAuthnAvailable,YP as listAssets,kC as listDocs,D5 as onAuthStateChange,c2 as setDoc,u2 as setManyDocs,g5 as signIn,Xm as signOut,x5 as signUp,O5 as unsafeIdentity,ZP as uploadBlob,zP as uploadFile};
|
|
123
123
|
/*! Bundled license information:
|
|
124
124
|
|
|
125
125
|
@noble/hashes/utils.js:
|