@junobuild/core-standalone 2.2.1-next-2025-11-05.2 → 2.2.1-next-2025-11-06

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.
Files changed (31) hide show
  1. package/dist/browser/index.js +28 -28
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/node/index.mjs +28 -28
  4. package/dist/node/index.mjs.map +4 -4
  5. package/dist/types/auth/providers/_auth-client.providers.d.ts +1 -10
  6. package/dist/types/auth/providers/_auth.providers.d.ts +11 -0
  7. package/dist/types/auth/providers/google.providers.d.ts +25 -0
  8. package/dist/types/auth/providers/webauthn.providers.d.ts +1 -1
  9. package/dist/types/auth/services/_auth-client.services.d.ts +17 -0
  10. package/dist/types/auth/services/identity.services.d.ts +22 -0
  11. package/dist/types/auth/services/load.services.d.ts +13 -0
  12. package/dist/types/auth/services/redirect.services.d.ts +1 -0
  13. package/dist/types/auth/services/sign-in.services.d.ts +19 -0
  14. package/dist/types/auth/services/sign-out.services.d.ts +10 -0
  15. package/dist/types/auth/services/sign-up.services.d.ts +8 -0
  16. package/dist/types/auth/stores/auth-client.store.d.ts +15 -0
  17. package/dist/types/auth/types/auth.d.ts +11 -14
  18. package/dist/types/auth/types/errors.d.ts +2 -0
  19. package/dist/types/auth/types/google.d.ts +50 -0
  20. package/dist/types/auth/types/provider.d.ts +7 -3
  21. package/dist/types/core/types/utility.d.ts +5 -3
  22. package/dist/types/core/utils/window.env.utils.d.ts +1 -0
  23. package/dist/types/index.d.ts +5 -3
  24. package/dist/workers/auth.worker.js +6 -6
  25. package/dist/workers/auth.worker.js.map +4 -4
  26. package/package.json +1 -1
  27. package/dist/types/auth/providers/nfid.providers.d.ts +0 -28
  28. package/dist/types/auth/services/auth.services.d.ts +0 -60
  29. package/dist/types/auth/types/nfid.d.ts +0 -24
  30. package/dist/types/auth/utils/auth.utils.d.ts +0 -3
  31. /package/dist/types/core/services/{identity.services.d.ts → any-identity.services.d.ts} +0 -0
@@ -1,57 +1,57 @@
1
- var tp=Object.defineProperty;var rp=(e,t)=>{for(var r in t)tp(e,r,{get:t[r],enumerable:!0})};var xc;(function(e){e[e.SysFatal=1]="SysFatal",e[e.SysTransient=2]="SysTransient",e[e.DestinationInvalid=3]="DestinationInvalid",e[e.CanisterReject=4]="CanisterReject",e[e.CanisterError=5]="CanisterError"})(xc||(xc={}));var zt;(function(e){e.Replied="replied",e.Rejected="rejected"})(zt||(zt={}));function bc(e){return e!=null&&"reject_code"in e}function Tc(e){return e!=null&&"certificate"in e}var So="abcdefghijklmnopqrstuvwxyz234567",Yr=Object.create(null);for(let e=0;e<So.length;e++)Yr[So[e]]=e;Yr[0]=Yr.o;Yr[1]=Yr.i;function wc(e){let t=0,r=0,n="";function o(i){return t<0?r|=i>>-t:r=i<<t&248,t>3?(t-=8,1):(t<4&&(n+=So[r>>3],t+=5),0)}for(let i=0;i<e.length;)i+=o(e[i]);return n+(t<0?So[r>>3]:"")}function Nc(e){let t=0,r=0,n=new Uint8Array(e.length*4/3|0),o=0;function i(s){let a=Yr[s.toLowerCase()];if(a===void 0)throw new Error(`Invalid character: ${JSON.stringify(s)}`);a<<=3,r|=a>>>t,t+=5,t>=8&&(n[o++]=r,t-=8,t>0?r=a<<5-t&255:r=0)}for(let s of e)i(s);return n.slice(0,o)}var np=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 Oc(e){let t=-1;for(let r=0;r<e.length;r++){let o=(e[r]^t)&255;t=np[o]^t>>>8}return(t^-1)>>>0}var br=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ft(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Vs(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ue(e,...t){if(!ft(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Ps(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Rc(e,t){ue(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Tr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Vo(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function nt(e,t){return e<<32-t|e>>>t}var vc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",op=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function K(e){if(ue(e),vc)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=op[e[r]];return t}var vt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ec(e){if(e>=vt._0&&e<=vt._9)return e-vt._0;if(e>=vt.A&&e<=vt.F)return e-(vt.A-10);if(e>=vt.a&&e<=vt.f)return e-(vt.a-10)}function Te(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(vc)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Ec(e.charCodeAt(i)),a=Ec(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Q(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Cs(e){return typeof e=="string"&&(e=Q(e)),ue(e),e}function M(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ue(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}var Fo=class{};function Po(e){let t=n=>e().update(Cs(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Zr(e=32){if(br&&typeof br.getRandomValues=="function")return br.getRandomValues(new Uint8Array(e));if(br&&typeof br.randomBytes=="function")return Uint8Array.from(br.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function ip(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,u=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+u,a,n)}function Ic(e,t,r){return e&t^~e&r}function Ac(e,t,r){return e&t^e&r^t&r}var Pn=class extends Fo{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Vo(this.buffer)}update(t){Ps(this),t=Cs(t),ue(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Vo(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ps(this),Rc(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,Tr(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let d=s;d<o;d++)r[d]=0;ip(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Vo(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,p=this.get();if(u>p.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,p[d],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},It=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),At=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var ve=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Co=BigInt(4294967295),Sc=BigInt(32);function sp(e,t=!1){return t?{h:Number(e&Co),l:Number(e>>Sc&Co)}:{h:Number(e>>Sc&Co)|0,l:Number(e&Co)|0}}function Fc(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=sp(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var Bs=(e,t,r)=>e>>>r,Ds=(e,t,r)=>e<<32-r|t>>>r,wr=(e,t,r)=>e>>>r|t<<32-r,Nr=(e,t,r)=>e<<32-r|t>>>r,Cn=(e,t,r)=>e<<64-r|t>>>r-32,Bn=(e,t,r)=>e>>>r-32|t<<64-r;function ht(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Vc=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Pc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Cc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Bc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Dc=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Uc=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var cp=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Wt=new Uint32Array(64),Bo=class extends Pn{constructor(t=32){super(64,t,8,!1),this.A=It[0]|0,this.B=It[1]|0,this.C=It[2]|0,this.D=It[3]|0,this.E=It[4]|0,this.F=It[5]|0,this.G=It[6]|0,this.H=It[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let d=0;d<16;d++,r+=4)Wt[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let l=Wt[d-15],f=Wt[d-2],h=nt(l,7)^nt(l,18)^l>>>3,m=nt(f,17)^nt(f,19)^f>>>10;Wt[d]=m+Wt[d-7]+h+Wt[d-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:p}=this;for(let d=0;d<64;d++){let l=nt(a,6)^nt(a,11)^nt(a,25),f=p+l+Ic(a,c,u)+cp[d]+Wt[d]|0,m=(nt(n,2)^nt(n,13)^nt(n,22))+Ac(n,o,i)|0;p=u,u=c,c=a,a=s+f|0,s=i,i=o,o=n,n=f+m|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,p=p+this.H|0,this.set(n,o,i,s,a,c,u,p)}roundClean(){Tr(Wt)}destroy(){this.set(0,0,0,0,0,0,0,0),Tr(this.buffer)}},Us=class extends Bo{constructor(){super(28),this.A=At[0]|0,this.B=At[1]|0,this.C=At[2]|0,this.D=At[3]|0,this.E=At[4]|0,this.F=At[5]|0,this.G=At[6]|0,this.H=At[7]|0}},kc=Fc(["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(e=>BigInt(e))),lp=kc[0],up=kc[1],Yt=new Uint32Array(80),Zt=new Uint32Array(80),ks=class extends Pn{constructor(t=64){super(128,t,16,!1),this.Ah=ve[0]|0,this.Al=ve[1]|0,this.Bh=ve[2]|0,this.Bl=ve[3]|0,this.Ch=ve[4]|0,this.Cl=ve[5]|0,this.Dh=ve[6]|0,this.Dl=ve[7]|0,this.Eh=ve[8]|0,this.El=ve[9]|0,this.Fh=ve[10]|0,this.Fl=ve[11]|0,this.Gh=ve[12]|0,this.Gl=ve[13]|0,this.Hh=ve[14]|0,this.Hl=ve[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:p,Fh:d,Fl:l,Gh:f,Gl:h,Hh:m,Hl:g}=this;return[t,r,n,o,i,s,a,c,u,p,d,l,f,h,m,g]}set(t,r,n,o,i,s,a,c,u,p,d,l,f,h,m,g){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=p|0,this.Fh=d|0,this.Fl=l|0,this.Gh=f|0,this.Gl=h|0,this.Hh=m|0,this.Hl=g|0}process(t,r){for(let y=0;y<16;y++,r+=4)Yt[y]=t.getUint32(r),Zt[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let w=Yt[y-15]|0,E=Zt[y-15]|0,O=wr(w,E,1)^wr(w,E,8)^Bs(w,E,7),R=Nr(w,E,1)^Nr(w,E,8)^Ds(w,E,7),I=Yt[y-2]|0,T=Zt[y-2]|0,v=wr(I,T,19)^Cn(I,T,61)^Bs(I,T,6),F=Nr(I,T,19)^Bn(I,T,61)^Ds(I,T,6),S=Cc(R,F,Zt[y-7],Zt[y-16]),b=Bc(S,O,v,Yt[y-7],Yt[y-16]);Yt[y]=b|0,Zt[y]=S|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:p,Eh:d,El:l,Fh:f,Fl:h,Gh:m,Gl:g,Hh:_,Hl:x}=this;for(let y=0;y<80;y++){let w=wr(d,l,14)^wr(d,l,18)^Cn(d,l,41),E=Nr(d,l,14)^Nr(d,l,18)^Bn(d,l,41),O=d&f^~d&m,R=l&h^~l&g,I=Dc(x,E,R,up[y],Zt[y]),T=Uc(I,_,w,O,lp[y],Yt[y]),v=I|0,F=wr(n,o,28)^Cn(n,o,34)^Cn(n,o,39),S=Nr(n,o,28)^Bn(n,o,34)^Bn(n,o,39),b=n&i^n&a^i&a,N=o&s^o&c^s&c;_=m|0,x=g|0,m=f|0,g=h|0,f=d|0,h=l|0,{h:d,l}=ht(u|0,p|0,T|0,v|0),u=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let V=Vc(v,S,N);n=Pc(V,T,F,b),o=V|0}({h:n,l:o}=ht(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=ht(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=ht(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:p}=ht(this.Dh|0,this.Dl|0,u|0,p|0),{h:d,l}=ht(this.Eh|0,this.El|0,d|0,l|0),{h:f,l:h}=ht(this.Fh|0,this.Fl|0,f|0,h|0),{h:m,l:g}=ht(this.Gh|0,this.Gl|0,m|0,g|0),{h:_,l:x}=ht(this.Hh|0,this.Hl|0,_|0,x|0),this.set(n,o,i,s,a,c,u,p,d,l,f,h,m,g,_,x)}roundClean(){Tr(Yt,Zt)}destroy(){Tr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ae=Po(()=>new Bo),Lc=Po(()=>new Us),qc=Po(()=>new ks);var Do="__principal__",dp=2,Mc=4,pp="aaaaa-aa",L=class e{static anonymous(){return new this(new Uint8Array([Mc]))}static managementCanister(){return this.fromText(pp)}static selfAuthenticating(t){let r=Lc(t);return new this(new Uint8Array([...r,dp]))}static from(t){if(typeof t=="string")return e.fromText(t);if(Object.getPrototypeOf(t)===Uint8Array.prototype)return new e(t);if(e.isPrincipal(t))return new e(t._arr);throw new Error(`Impossible to convert ${JSON.stringify(t)} to Principal.`)}static fromHex(t){return new this(Te(t))}static fromText(t){let r=t;if(t.includes(Do)){let s=JSON.parse(t);Do in s&&(r=s[Do])}let n=r.toLowerCase().replace(/-/g,""),o=Nc(n);o=o.slice(4,o.length);let i=new this(o);if(i.toText()!==r)throw new Error(`Principal "${i.toText()}" does not have a valid checksum (original value "${r}" may not be a valid Principal ID).`);return i}static fromUint8Array(t){return new this(t)}static isPrincipal(t){return t instanceof e||typeof t=="object"&&t!==null&&"_isPrincipal"in t&&t._isPrincipal===!0&&"_arr"in t&&t._arr instanceof Uint8Array}constructor(t){this._arr=t,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===Mc}toUint8Array(){return this._arr}toHex(){return K(this._arr).toUpperCase()}toText(){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,Oc(this._arr));let n=new Uint8Array(t),o=new Uint8Array([...n,...this._arr]),s=wc(o).match(/.{1,5}/g);if(!s)throw new Error;return s.join("-")}toString(){return this.toText()}toJSON(){return{[Do]:this.toText()}}compareTo(t){for(let r=0;r<Math.min(this._arr.length,t._arr.length);r++){if(this._arr[r]<t._arr[r])return"lt";if(this._arr[r]>t._arr[r])return"gt"}return this._arr.length<t._arr.length?"lt":this._arr.length>t._arr.length?"gt":"eq"}ltEq(t){let r=this.compareTo(t);return r=="lt"||r=="eq"}gtEq(t){let r=this.compareTo(t);return r=="gt"||r=="eq"}};var St;(function(e){e.Trust="Trust",e.Protocol="Protocol",e.Reject="Reject",e.Transport="Transport",e.External="External",e.Limit="Limit",e.Input="Input",e.Unknown="Unknown"})(St||(St={}));var H=class{constructor(t=!1){this.isCertified=t}toString(){let t=this.toErrorMessage();return this.requestContext&&(t+=`
1
+ var Ap=Object.defineProperty;var Sp=(e,t)=>{for(var r in t)Ap(e,r,{get:t[r],enumerable:!0})};var kc;(function(e){e[e.SysFatal=1]="SysFatal",e[e.SysTransient=2]="SysTransient",e[e.DestinationInvalid=3]="DestinationInvalid",e[e.CanisterReject=4]="CanisterReject",e[e.CanisterError=5]="CanisterError"})(kc||(kc={}));var fr;(function(e){e.Replied="replied",e.Rejected="rejected"})(fr||(fr={}));function Lc(e){return e!=null&&"reject_code"in e}function qc(e){return e!=null&&"certificate"in e}var ci="abcdefghijklmnopqrstuvwxyz234567",Cn=Object.create(null);for(let e=0;e<ci.length;e++)Cn[ci[e]]=e;Cn[0]=Cn.o;Cn[1]=Cn.i;function Mc(e){let t=0,r=0,n="";function o(i){return t<0?r|=i>>-t:r=i<<t&248,t>3?(t-=8,1):(t<4&&(n+=ci[r>>3],t+=5),0)}for(let i=0;i<e.length;)i+=o(e[i]);return n+(t<0?ci[r>>3]:"")}function jc(e){let t=0,r=0,n=new Uint8Array(e.length*4/3|0),o=0;function i(s){let a=Cn[s.toLowerCase()];if(a===void 0)throw new Error(`Invalid character: ${JSON.stringify(s)}`);a<<=3,r|=a>>>t,t+=5,t>=8&&(n[o++]=r,t-=8,t>0?r=a<<5-t&255:r=0)}for(let s of e)i(s);return n.slice(0,o)}var Fp=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 Kc(e){let t=-1;for(let r=0;r<e.length;r++){let o=(e[r]^t)&255;t=Fp[o]^t>>>8}return(t^-1)>>>0}var cn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ot(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ds(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function fe(e,...t){if(!Ot(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Us(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function $c(e,t){fe(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ln(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ui(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ft(e,t){return e<<32-t|e>>>t}var Gc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Vp=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function H(e){if(fe(e),Gc)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Vp[e[r]];return t}var jt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Hc(e){if(e>=jt._0&&e<=jt._9)return e-jt._0;if(e>=jt.A&&e<=jt.F)return e-(jt.A-10);if(e>=jt.a&&e<=jt.f)return e-(jt.a-10)}function Ne(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Gc)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Hc(e.charCodeAt(i)),a=Hc(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function ee(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ks(e){return typeof e=="string"&&(e=ee(e)),fe(e),e}function j(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];fe(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}var li=class{};function di(e){let t=n=>e().update(ks(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Pn(e=32){if(cn&&typeof cn.getRandomValues=="function")return cn.getRandomValues(new Uint8Array(e));if(cn&&typeof cn.randomBytes=="function")return Uint8Array.from(cn.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Cp(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,u=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+u,a,n)}function Jc(e,t,r){return e&t^~e&r}function zc(e,t,r){return e&t^e&r^t&r}var ho=class extends li{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=ui(this.buffer)}update(t){Us(this),t=ks(t),fe(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=ui(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Us(this),$c(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,ln(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let d=s;d<o;d++)r[d]=0;Cp(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=ui(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,p=this.get();if(u>p.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,p[d],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Kt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ht=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var ve=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var pi=BigInt(4294967295),Wc=BigInt(32);function Pp(e,t=!1){return t?{h:Number(e&pi),l:Number(e>>Wc&pi)}:{h:Number(e>>Wc&pi)|0,l:Number(e&pi)|0}}function Yc(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=Pp(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var Ls=(e,t,r)=>e>>>r,qs=(e,t,r)=>e<<32-r|t>>>r,un=(e,t,r)=>e>>>r|t<<32-r,dn=(e,t,r)=>e<<32-r|t>>>r,mo=(e,t,r)=>e<<64-r|t>>>r-32,_o=(e,t,r)=>e>>>r-32|t<<64-r;function Et(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Zc=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Xc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Qc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),el=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,tl=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),rl=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Dp=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]),hr=new Uint32Array(64),fi=class extends ho{constructor(t=32){super(64,t,8,!1),this.A=Kt[0]|0,this.B=Kt[1]|0,this.C=Kt[2]|0,this.D=Kt[3]|0,this.E=Kt[4]|0,this.F=Kt[5]|0,this.G=Kt[6]|0,this.H=Kt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let d=0;d<16;d++,r+=4)hr[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let l=hr[d-15],f=hr[d-2],h=ft(l,7)^ft(l,18)^l>>>3,m=ft(f,17)^ft(f,19)^f>>>10;hr[d]=m+hr[d-7]+h+hr[d-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:p}=this;for(let d=0;d<64;d++){let l=ft(a,6)^ft(a,11)^ft(a,25),f=p+l+Jc(a,c,u)+Dp[d]+hr[d]|0,m=(ft(n,2)^ft(n,13)^ft(n,22))+zc(n,o,i)|0;p=u,u=c,c=a,a=s+f|0,s=i,i=o,o=n,n=f+m|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,p=p+this.H|0,this.set(n,o,i,s,a,c,u,p)}roundClean(){ln(hr)}destroy(){this.set(0,0,0,0,0,0,0,0),ln(this.buffer)}},Ms=class extends fi{constructor(){super(28),this.A=Ht[0]|0,this.B=Ht[1]|0,this.C=Ht[2]|0,this.D=Ht[3]|0,this.E=Ht[4]|0,this.F=Ht[5]|0,this.G=Ht[6]|0,this.H=Ht[7]|0}},nl=Yc(["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(e=>BigInt(e))),Up=nl[0],kp=nl[1],mr=new Uint32Array(80),_r=new Uint32Array(80),js=class extends ho{constructor(t=64){super(128,t,16,!1),this.Ah=ve[0]|0,this.Al=ve[1]|0,this.Bh=ve[2]|0,this.Bl=ve[3]|0,this.Ch=ve[4]|0,this.Cl=ve[5]|0,this.Dh=ve[6]|0,this.Dl=ve[7]|0,this.Eh=ve[8]|0,this.El=ve[9]|0,this.Fh=ve[10]|0,this.Fl=ve[11]|0,this.Gh=ve[12]|0,this.Gl=ve[13]|0,this.Hh=ve[14]|0,this.Hl=ve[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:u,El:p,Fh:d,Fl:l,Gh:f,Gl:h,Hh:m,Hl:g}=this;return[t,r,n,o,i,s,a,c,u,p,d,l,f,h,m,g]}set(t,r,n,o,i,s,a,c,u,p,d,l,f,h,m,g){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=p|0,this.Fh=d|0,this.Fl=l|0,this.Gh=f|0,this.Gl=h|0,this.Hh=m|0,this.Hl=g|0}process(t,r){for(let y=0;y<16;y++,r+=4)mr[y]=t.getUint32(r),_r[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let T=mr[y-15]|0,E=_r[y-15]|0,O=un(T,E,1)^un(T,E,8)^Ls(T,E,7),R=dn(T,E,1)^dn(T,E,8)^qs(T,E,7),I=mr[y-2]|0,w=_r[y-2]|0,v=un(I,w,19)^mo(I,w,61)^Ls(I,w,6),V=dn(I,w,19)^_o(I,w,61)^qs(I,w,6),S=Qc(R,V,_r[y-7],_r[y-16]),b=el(S,O,v,mr[y-7],mr[y-16]);mr[y]=b|0,_r[y]=S|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:u,Dl:p,Eh:d,El:l,Fh:f,Fl:h,Gh:m,Gl:g,Hh:_,Hl:x}=this;for(let y=0;y<80;y++){let T=un(d,l,14)^un(d,l,18)^mo(d,l,41),E=dn(d,l,14)^dn(d,l,18)^_o(d,l,41),O=d&f^~d&m,R=l&h^~l&g,I=tl(x,E,R,kp[y],_r[y]),w=rl(I,_,T,O,Up[y],mr[y]),v=I|0,V=un(n,o,28)^mo(n,o,34)^mo(n,o,39),S=dn(n,o,28)^_o(n,o,34)^_o(n,o,39),b=n&i^n&a^i&a,N=o&s^o&c^s&c;_=m|0,x=g|0,m=f|0,g=h|0,f=d|0,h=l|0,{h:d,l}=Et(u|0,p|0,w|0,v|0),u=a|0,p=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let F=Zc(v,S,N);n=Xc(F,w,V,b),o=F|0}({h:n,l:o}=Et(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Et(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Et(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:p}=Et(this.Dh|0,this.Dl|0,u|0,p|0),{h:d,l}=Et(this.Eh|0,this.El|0,d|0,l|0),{h:f,l:h}=Et(this.Fh|0,this.Fl|0,f|0,h|0),{h:m,l:g}=Et(this.Gh|0,this.Gl|0,m|0,g|0),{h:_,l:x}=Et(this.Hh|0,this.Hl|0,_|0,x|0),this.set(n,o,i,s,a,c,u,p,d,l,f,h,m,g,_,x)}roundClean(){ln(mr,_r)}destroy(){ln(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Se=di(()=>new fi),ol=di(()=>new Ms),il=di(()=>new js);var hi="__principal__",Lp=2,sl=4,qp="aaaaa-aa",M=class e{static anonymous(){return new this(new Uint8Array([sl]))}static managementCanister(){return this.fromText(qp)}static selfAuthenticating(t){let r=ol(t);return new this(new Uint8Array([...r,Lp]))}static from(t){if(typeof t=="string")return e.fromText(t);if(Object.getPrototypeOf(t)===Uint8Array.prototype)return new e(t);if(e.isPrincipal(t))return new e(t._arr);throw new Error(`Impossible to convert ${JSON.stringify(t)} to Principal.`)}static fromHex(t){return new this(Ne(t))}static fromText(t){let r=t;if(t.includes(hi)){let s=JSON.parse(t);hi in s&&(r=s[hi])}let n=r.toLowerCase().replace(/-/g,""),o=jc(n);o=o.slice(4,o.length);let i=new this(o);if(i.toText()!==r)throw new Error(`Principal "${i.toText()}" does not have a valid checksum (original value "${r}" may not be a valid Principal ID).`);return i}static fromUint8Array(t){return new this(t)}static isPrincipal(t){return t instanceof e||typeof t=="object"&&t!==null&&"_isPrincipal"in t&&t._isPrincipal===!0&&"_arr"in t&&t._arr instanceof Uint8Array}constructor(t){this._arr=t,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===sl}toUint8Array(){return this._arr}toHex(){return H(this._arr).toUpperCase()}toText(){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,Kc(this._arr));let n=new Uint8Array(t),o=new Uint8Array([...n,...this._arr]),s=Mc(o).match(/.{1,5}/g);if(!s)throw new Error;return s.join("-")}toString(){return this.toText()}toJSON(){return{[hi]:this.toText()}}compareTo(t){for(let r=0;r<Math.min(this._arr.length,t._arr.length);r++){if(this._arr[r]<t._arr[r])return"lt";if(this._arr[r]>t._arr[r])return"gt"}return this._arr.length<t._arr.length?"lt":this._arr.length>t._arr.length?"gt":"eq"}ltEq(t){let r=this.compareTo(t);return r=="lt"||r=="eq"}gtEq(t){let r=this.compareTo(t);return r=="gt"||r=="eq"}};var $t;(function(e){e.Trust="Trust",e.Protocol="Protocol",e.Reject="Reject",e.Transport="Transport",e.External="External",e.Limit="Limit",e.Input="Input",e.Unknown="Unknown"})($t||($t={}));var G=class{constructor(t=!1){this.isCertified=t}toString(){let t=this.toErrorMessage();return this.requestContext&&(t+=`
2
2
  Request context:
3
- Request ID (hex): ${this.requestContext.requestId?K(this.requestContext.requestId):"undefined"}
4
- Sender pubkey (hex): ${K(this.requestContext.senderPubKey)}
5
- Sender signature (hex): ${K(this.requestContext.senderSignature)}
3
+ Request ID (hex): ${this.requestContext.requestId?H(this.requestContext.requestId):"undefined"}
4
+ Sender pubkey (hex): ${H(this.requestContext.senderPubKey)}
5
+ Sender signature (hex): ${H(this.requestContext.senderSignature)}
6
6
  Ingress expiry: ${this.requestContext.ingressExpiry.toString()}`),this.callContext&&(t+=`
7
7
  Call context:
8
8
  Canister ID: ${this.callContext.canisterId.toText()}
9
9
  Method name: ${this.callContext.methodName}
10
- HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),t}},ot=class e extends Error{get code(){return this.cause.code}set code(t){this.cause.code=t}get kind(){return this.cause.kind}set kind(t){this.cause.kind=t}get isCertified(){return this.code.isCertified}constructor(t,r){super(t.toString()),this.name="AgentError",this.cause={code:t,kind:r},Object.setPrototypeOf(this,e.prototype)}hasCode(t){return this.code instanceof t}toString(){return`${this.name} (${this.kind}): ${this.message}`}},Ft=class extends ot{static fromCode(t){return new this(t)}},Ve=class e extends Ft{constructor(t){super(t,St.Trust),this.name="TrustError",Object.setPrototypeOf(this,e.prototype)}},te=class e extends Ft{constructor(t){super(t,St.Protocol),this.name="ProtocolError",Object.setPrototypeOf(this,e.prototype)}},Xt=class e extends Ft{constructor(t){super(t,St.Reject),this.name="RejectError",Object.setPrototypeOf(this,e.prototype)}},Dn=class e extends Ft{constructor(t){super(t,St.Transport),this.name="TransportError",Object.setPrototypeOf(this,e.prototype)}},we=class e extends Ft{constructor(t){super(t,St.External),this.name="ExternalError",Object.setPrototypeOf(this,e.prototype)}};var z=class e extends Ft{constructor(t){super(t,St.Input),this.name="InputError",Object.setPrototypeOf(this,e.prototype)}},me=class e extends Ft{constructor(t){super(t,St.Unknown),this.name="UnknownError",Object.setPrototypeOf(this,e.prototype)}},Qt=class e extends H{constructor(t,r){super(),this.reason=t,this.error=r,this.name="CertificateVerificationErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){let t=this.reason;return this.error&&(t+=`: ${Kn(this.error)}`),`Certificate verification error: "${t}"`}},Or=class e extends H{constructor(t,r,n,o,i){super(),this.maxAgeInMinutes=t,this.certificateTime=r,this.currentTime=n,this.timeDiffMsecs=o,this.ageType=i,this.name="CertificateTimeErrorCode",Object.setPrototypeOf(this,e.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`}},Uo=class e extends H{constructor(){super(),this.name="CertificateHasTooManyDelegationsErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"Certificate has too many delegations"}},Xr=class e extends H{constructor(t,r){super(),this.canisterId=t,this.subnetId=r,this.name="CertificateNotAuthorizedErrorCode",Object.setPrototypeOf(this,e.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()}`}},Vt=class e extends H{constructor(t,r){super(),this.message=t,this.lookupStatus=r,this.name="LookupErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`${this.message}. Lookup status: ${this.lookupStatus}`}},Qr=class e extends H{constructor(t){super(),this.message=t,this.name="MalformedLookupFoundValueErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return this.message}},ko=class e extends H{constructor(t){super(),this.message=t,this.name="MissingLookupValueErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return this.message}},en=class e extends H{constructor(t,r){super(),this.expectedLength=t,this.actualLength=r,this.name="DerKeyLengthMismatchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`BLS DER-encoded public key must be ${this.expectedLength} bytes long, but is ${this.actualLength} bytes long`}},Lo=class e extends H{constructor(t,r){super(),this.expectedPrefix=t,this.actualPrefix=r,this.name="DerPrefixMismatchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`BLS DER-encoded public key is invalid. Expected the following prefix: ${K(this.expectedPrefix)}, but got ${K(this.actualPrefix)}`}},qo=class e extends H{constructor(t,r){super(),this.expectedLength=t,this.actualLength=r,this.name="DerDecodeLengthMismatchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`DER payload mismatch: Expected length ${this.expectedLength}, actual length: ${this.actualLength}`}},it=class e extends H{constructor(t){super(),this.error=t,this.name="DerDecodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to decode DER: ${this.error}`}},Un=class e extends H{constructor(t){super(),this.error=t,this.name="DerEncodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to encode DER: ${this.error}`}},Mo=class e extends H{constructor(t,r){super(),this.error=t,this.input=r,this.name="CborDecodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to decode CBOR: ${Kn(this.error)}, input: ${K(this.input)}`}},jo=class e extends H{constructor(t,r){super(),this.error=t,this.value=r,this.name="CborEncodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to encode CBOR: ${Kn(this.error)}, input: ${this.value}`}};var Er=class e extends H{constructor(t,r,n){super(),this.message=t,this.requestId=r,this.status=n,this.name="TimeoutWaitingForResponseErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){let t=`${this.message}
11
- `;return this.requestId&&(t+=` Request ID: ${K(this.requestId)}
10
+ HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),t}},ht=class e extends Error{get code(){return this.cause.code}set code(t){this.cause.code=t}get kind(){return this.cause.kind}set kind(t){this.cause.kind=t}get isCertified(){return this.code.isCertified}constructor(t,r){super(t.toString()),this.name="AgentError",this.cause={code:t,kind:r},Object.setPrototypeOf(this,e.prototype)}hasCode(t){return this.code instanceof t}toString(){return`${this.name} (${this.kind}): ${this.message}`}},Gt=class extends ht{static fromCode(t){return new this(t)}},Pe=class e extends Gt{constructor(t){super(t,$t.Trust),this.name="TrustError",Object.setPrototypeOf(this,e.prototype)}},ne=class e extends Gt{constructor(t){super(t,$t.Protocol),this.name="ProtocolError",Object.setPrototypeOf(this,e.prototype)}},yr=class e extends Gt{constructor(t){super(t,$t.Reject),this.name="RejectError",Object.setPrototypeOf(this,e.prototype)}},yo=class e extends Gt{constructor(t){super(t,$t.Transport),this.name="TransportError",Object.setPrototypeOf(this,e.prototype)}},Oe=class e extends Gt{constructor(t){super(t,$t.External),this.name="ExternalError",Object.setPrototypeOf(this,e.prototype)}};var z=class e extends Gt{constructor(t){super(t,$t.Input),this.name="InputError",Object.setPrototypeOf(this,e.prototype)}},ge=class e extends Gt{constructor(t){super(t,$t.Unknown),this.name="UnknownError",Object.setPrototypeOf(this,e.prototype)}},gr=class e extends G{constructor(t,r){super(),this.reason=t,this.error=r,this.name="CertificateVerificationErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){let t=this.reason;return this.error&&(t+=`: ${Oo(this.error)}`),`Certificate verification error: "${t}"`}},pn=class e extends G{constructor(t,r,n,o,i){super(),this.maxAgeInMinutes=t,this.certificateTime=r,this.currentTime=n,this.timeDiffMsecs=o,this.ageType=i,this.name="CertificateTimeErrorCode",Object.setPrototypeOf(this,e.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`}},mi=class e extends G{constructor(){super(),this.name="CertificateHasTooManyDelegationsErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"Certificate has too many delegations"}},Bn=class e extends G{constructor(t,r){super(),this.canisterId=t,this.subnetId=r,this.name="CertificateNotAuthorizedErrorCode",Object.setPrototypeOf(this,e.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()}`}},Jt=class e extends G{constructor(t,r){super(),this.message=t,this.lookupStatus=r,this.name="LookupErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`${this.message}. Lookup status: ${this.lookupStatus}`}},Dn=class e extends G{constructor(t){super(),this.message=t,this.name="MalformedLookupFoundValueErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return this.message}},_i=class e extends G{constructor(t){super(),this.message=t,this.name="MissingLookupValueErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return this.message}},Un=class e extends G{constructor(t,r){super(),this.expectedLength=t,this.actualLength=r,this.name="DerKeyLengthMismatchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`BLS DER-encoded public key must be ${this.expectedLength} bytes long, but is ${this.actualLength} bytes long`}},yi=class e extends G{constructor(t,r){super(),this.expectedPrefix=t,this.actualPrefix=r,this.name="DerPrefixMismatchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`BLS DER-encoded public key is invalid. Expected the following prefix: ${H(this.expectedPrefix)}, but got ${H(this.actualPrefix)}`}},gi=class e extends G{constructor(t,r){super(),this.expectedLength=t,this.actualLength=r,this.name="DerDecodeLengthMismatchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`DER payload mismatch: Expected length ${this.expectedLength}, actual length: ${this.actualLength}`}},mt=class e extends G{constructor(t){super(),this.error=t,this.name="DerDecodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to decode DER: ${this.error}`}},go=class e extends G{constructor(t){super(),this.error=t,this.name="DerEncodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to encode DER: ${this.error}`}},xi=class e extends G{constructor(t,r){super(),this.error=t,this.input=r,this.name="CborDecodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to decode CBOR: ${Oo(this.error)}, input: ${H(this.input)}`}},bi=class e extends G{constructor(t,r){super(),this.error=t,this.value=r,this.name="CborEncodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to encode CBOR: ${Oo(this.error)}, input: ${this.value}`}};var fn=class e extends G{constructor(t,r,n){super(),this.message=t,this.requestId=r,this.status=n,this.name="TimeoutWaitingForResponseErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){let t=`${this.message}
11
+ `;return this.requestId&&(t+=` Request ID: ${H(this.requestId)}
12
12
  `),this.status&&(t+=` Request status: ${this.status}
13
- `),t}},Ko=class e extends H{constructor(t,r,n){super(),this.maxIngressExpiryInMinutes=t,this.requestId=r,this.retryTimes=n,this.name="CertificateOutdatedErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){let t=`Certificate is stale (over ${this.maxIngressExpiryInMinutes} minutes). Is the computer's clock synchronized?
14
- Request ID: ${K(this.requestId)}
15
- `;return this.retryTimes!==void 0&&(t+=` Retried ${this.retryTimes} times.`),t}},tn=class e extends H{constructor(t,r,n,o){super(!0),this.requestId=t,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=o,this.name="CertifiedRejectErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`The replica returned a rejection error:
16
- Request ID: ${K(this.requestId)}
13
+ `),t}},wi=class e extends G{constructor(t,r,n){super(),this.maxIngressExpiryInMinutes=t,this.requestId=r,this.retryTimes=n,this.name="CertificateOutdatedErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){let t=`Certificate is stale (over ${this.maxIngressExpiryInMinutes} minutes). Is the computer's clock synchronized?
14
+ Request ID: ${H(this.requestId)}
15
+ `;return this.retryTimes!==void 0&&(t+=` Retried ${this.retryTimes} times.`),t}},kn=class e extends G{constructor(t,r,n,o){super(!0),this.requestId=t,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=o,this.name="CertifiedRejectErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`The replica returned a rejection error:
16
+ Request ID: ${H(this.requestId)}
17
17
  Reject code: ${this.rejectCode}
18
18
  Reject text: ${this.rejectMessage}
19
19
  Error code: ${this.rejectErrorCode}
20
- `}},$o=class e extends H{constructor(t,r,n,o,i){super(),this.requestId=t,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=o,this.signatures=i,this.name="UncertifiedRejectErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`The replica returned a rejection error:
21
- Request ID: ${K(this.requestId)}
20
+ `}},Ti=class e extends G{constructor(t,r,n,o,i){super(),this.requestId=t,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=o,this.signatures=i,this.name="UncertifiedRejectErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`The replica returned a rejection error:
21
+ Request ID: ${H(this.requestId)}
22
22
  Reject code: ${this.rejectCode}
23
23
  Reject text: ${this.rejectMessage}
24
24
  Error code: ${this.rejectErrorCode}
25
- `}},Ho=class e extends H{constructor(t,r,n,o){super(),this.requestId=t,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=o,this.name="UncertifiedRejectUpdateErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`The replica returned a rejection error:
26
- Request ID: ${K(this.requestId)}
25
+ `}},Ni=class e extends G{constructor(t,r,n,o){super(),this.requestId=t,this.rejectCode=r,this.rejectMessage=n,this.rejectErrorCode=o,this.name="UncertifiedRejectUpdateErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`The replica returned a rejection error:
26
+ Request ID: ${H(this.requestId)}
27
27
  Reject code: ${this.rejectCode}
28
28
  Reject text: ${this.rejectMessage}
29
29
  Error code: ${this.rejectErrorCode}
30
- `}},Go=class e extends H{constructor(t){super(),this.requestId=t,this.name="RequestStatusDoneNoReplyErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Call was marked as done but we never saw the reply:
31
- Request ID: ${K(this.requestId)}
32
- `}},mt=class e extends H{constructor(t){super(),this.shouldFetchRootKey=t,this.name="MissingRootKeyErrorCode",Object.setPrototypeOf(this,e.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.`}},Jo=class e extends H{constructor(t){super(),this.value=t,this.name="HashValueErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Attempt to hash a value of unsupported type: ${this.value}`}},rn=class e extends H{constructor(t){super(),this.error=t,this.name="HttpDefaultFetchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return this.error}},er=class e extends H{constructor(){super(),this.name="IdentityInvalidErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"This identity has expired due this application's security policy. Please refresh your authentication."}},Rr=class e extends H{constructor(t,r){super(),this.message=t,this.providedIngressExpiryInMinutes=r,this.name="IngressExpiryInvalidErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`${this.message}. Provided ingress expiry time is ${this.providedIngressExpiryInMinutes} minutes.`}},zo=class e extends H{constructor(){super(),this.name="CreateHttpAgentErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"Failed to create agent from provided agent"}},Wo=class e extends H{constructor(t){super(),this.error=t,this.name="MalformedSignatureErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Query response contained a malformed signature: ${this.error}`}},Yo=class e extends H{constructor(){super(),this.name="MissingSignatureErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"Query response did not contain any node signatures"}},Zo=class e extends H{constructor(){super(),this.name="MalformedPublicKeyErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"Read state response contained a malformed public key"}},Xo=class e extends H{constructor(t){super(),this.nodeId=t,this.name="QuerySignatureVerificationFailedErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Query signature verification failed. Node ID: ${this.nodeId}`}},Pe=class e extends H{constructor(t){super(),this.error=t,this.name="UnexpectedErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Unexpected error: ${Kn(this.error)}`}},tr=class e extends H{constructor(t){super(),this.error=t,this.name="HashTreeDecodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to decode certificate: ${this.error}`}},kn=class e extends H{constructor(t,r,n,o){super(),this.status=t,this.statusText=r,this.headers=n,this.bodyText=o,this.name="HttpErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){let t=`HTTP request failed:
30
+ `}},Oi=class e extends G{constructor(t){super(),this.requestId=t,this.name="RequestStatusDoneNoReplyErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Call was marked as done but we never saw the reply:
31
+ Request ID: ${H(this.requestId)}
32
+ `}},Rt=class e extends G{constructor(t){super(),this.shouldFetchRootKey=t,this.name="MissingRootKeyErrorCode",Object.setPrototypeOf(this,e.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.`}},Ei=class e extends G{constructor(t){super(),this.value=t,this.name="HashValueErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Attempt to hash a value of unsupported type: ${this.value}`}},Ln=class e extends G{constructor(t){super(),this.error=t,this.name="HttpDefaultFetchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return this.error}},xr=class e extends G{constructor(){super(),this.name="IdentityInvalidErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"This identity has expired due this application's security policy. Please refresh your authentication."}},hn=class e extends G{constructor(t,r){super(),this.message=t,this.providedIngressExpiryInMinutes=r,this.name="IngressExpiryInvalidErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`${this.message}. Provided ingress expiry time is ${this.providedIngressExpiryInMinutes} minutes.`}},Ri=class e extends G{constructor(){super(),this.name="CreateHttpAgentErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"Failed to create agent from provided agent"}},vi=class e extends G{constructor(t){super(),this.error=t,this.name="MalformedSignatureErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Query response contained a malformed signature: ${this.error}`}},Ii=class e extends G{constructor(){super(),this.name="MissingSignatureErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"Query response did not contain any node signatures"}},Ai=class e extends G{constructor(){super(),this.name="MalformedPublicKeyErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"Read state response contained a malformed public key"}},Si=class e extends G{constructor(t){super(),this.nodeId=t,this.name="QuerySignatureVerificationFailedErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Query signature verification failed. Node ID: ${this.nodeId}`}},Be=class e extends G{constructor(t){super(),this.error=t,this.name="UnexpectedErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Unexpected error: ${Oo(this.error)}`}},br=class e extends G{constructor(t){super(),this.error=t,this.name="HashTreeDecodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to decode certificate: ${this.error}`}},xo=class e extends G{constructor(t,r,n,o){super(),this.status=t,this.statusText=r,this.headers=n,this.bodyText=o,this.name="HttpErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){let t=`HTTP request failed:
33
33
  Status: ${this.status} (${this.statusText})
34
34
  Headers: ${JSON.stringify(this.headers)}
35
35
  `;return this.bodyText&&(t+=` Body: ${this.bodyText}
36
- `),t}},Ln=class e extends H{constructor(){super(),this.name="HttpV3ApiNotSupportedErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"HTTP request failed: v3 API is not supported"}},qn=class e extends H{constructor(t){super(),this.error=t,this.name="HttpFetchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to fetch HTTP request: ${Kn(this.error)}`}},Mn=class e extends H{constructor(t){super(),this.receivedCanisterId=t,this.name="MissingCanisterIdErrorCode",Object.setPrototypeOf(this,e.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.`}},Qo=class e extends H{constructor(t){super(),this.request=t,this.name="InvalidReadStateRequestErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Invalid read state request: ${this.request}`}},jn=class e extends H{constructor(t){super(),this.error=t,this.name="ExpiryJsonDeserializeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to deserialize expiry: ${this.error}`}};function Kn(e){if(e instanceof Error)return e.stack??e.message;try{return JSON.stringify(e)}catch{return String(e)}}var rr=new Error("unreachable");var Sr={};rp(Sr,{Bool:()=>Yc,BoolClass:()=>oi,ConstructType:()=>gt,Empty:()=>zc,EmptyClass:()=>Hn,FixedIntClass:()=>Bt,FixedNatClass:()=>yt,Float32:()=>tl,Float64:()=>rl,FloatClass:()=>zn,Func:()=>gl,FuncClass:()=>Ar,Int:()=>Qc,Int16:()=>ol,Int32:()=>il,Int64:()=>sl,Int8:()=>nl,IntClass:()=>Gn,Nat:()=>el,Nat16:()=>cl,Nat32:()=>ll,Nat64:()=>ul,Nat8:()=>al,NatClass:()=>Jn,Null:()=>Zc,NullClass:()=>vr,Opt:()=>hl,OptClass:()=>ir,PrimitiveType:()=>qe,Principal:()=>dl,PrincipalClass:()=>ai,Rec:()=>yl,RecClass:()=>We,Record:()=>ml,RecordClass:()=>Ir,Reserved:()=>Wc,ReservedClass:()=>xt,Service:()=>xl,ServiceClass:()=>an,Text:()=>Xc,TextClass:()=>ii,Tuple:()=>pl,TupleClass:()=>si,Type:()=>nn,Unknown:()=>_p,UnknownClass:()=>ni,Variant:()=>_l,VariantClass:()=>sn,Vec:()=>fl,VecClass:()=>on,Visitor:()=>Hs,decode:()=>mp,encode:()=>hp,resetSubtypeCache:()=>Gs,subtype:()=>zs});function W(...e){let t=new Uint8Array(e.reduce((n,o)=>n+o.byteLength,0)),r=0;for(let n of e)t.set(n,r),r+=n.byteLength;return t}var st=class{save(){return this._view}restore(t){if(!(t instanceof Uint8Array))throw new Error("Checkpoint must be a Uint8Array");this._view=t}constructor(t,r=t?.byteLength||0){if(t&&!(t instanceof Uint8Array))try{t=_t(t)}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(t&&r>t.byteLength)throw new Error("Length cannot exceed buffer length");this._buffer=t||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(t){let r=this._view.subarray(0,t);return this._view=this._view.subarray(t),r.slice()}readUint8(){if(this._view.byteLength===0)return;let t=this._view[0];return this._view=this._view.subarray(1),t}write(t){if(!(t instanceof Uint8Array))throw new Error("Buffer must be a Uint8Array");let r=this._view.byteLength;this._view.byteOffset+this._view.byteLength+t.byteLength>=this._buffer.byteLength?this.alloc(t.byteLength):this._view=new Uint8Array(this._buffer.buffer,this._view.byteOffset,this._view.byteLength+t.byteLength),this._view.set(t,r)}get end(){return this._view.byteLength===0}alloc(t){if(t<=0||!Number.isInteger(t))throw new Error("Amount must be a positive integer");let r=new Uint8Array((this._buffer.byteLength+t)*1.2|0),n=new Uint8Array(r.buffer,0,this._view.byteLength+t);n.set(this._view),this._buffer=r,this._view=n}};function _t(e){if(!e)throw new Error("Input cannot be null or undefined");return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?new Uint8Array(e):"buffer"in e?_t(e.buffer):new Uint8Array(e)}function Ls(e,t){if(e.byteLength!==t.byteLength)return e.byteLength-t.byteLength;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]-t[r];return 0}function jc(e,t){return Ls(e,t)===0}function Kc(e){if(!(e instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(e.buffer,e.byteOffset,e.byteLength)}function fp(e){let r=new TextEncoder().encode(e),n=0;for(let o of r)n=(n*223+o)%2**32;return n}function Ce(e){if(/^_\d+_$/.test(e)||/^_0x[0-9a-fA-F]+_$/.test(e)){let t=+e.slice(1,-1);if(Number.isSafeInteger(t)&&t>=0&&t<2**32)return t}return fp(e)}function qs(e){let t=BigInt(e);if(e<=0)throw new RangeError("Input must be positive");return t.toString(2).length-1}function ei(e){let t=BigInt(e);if(e<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<t}function $c(){throw new Error("unexpected end of buffer")}function or(e,t){return e.byteLength<t&&$c(),e.read(t)}function nr(e){let t=e.readUint8();return t===void 0&&$c(),t}function re(e){if(typeof e=="number"&&(e=BigInt(e)),e<BigInt(0))throw new Error("Cannot leb encode negative values.");let t=(e===BigInt(0)?0:qs(e))+1,r=new st(new Uint8Array(t),0);for(;;){let n=Number(e&BigInt(127));if(e/=BigInt(128),e===BigInt(0)){r.write(new Uint8Array([n]));break}else r.write(new Uint8Array([n|128]))}return r.buffer}function pe(e){let t=BigInt(1),r=BigInt(0),n;do n=nr(e),r+=BigInt(n&127).valueOf()*t,t*=BigInt(128);while(n>=128);return r}function fe(e){typeof e=="number"&&(e=BigInt(e));let t=e<BigInt(0);t&&(e=-e-BigInt(1));let r=(e===BigInt(0)?0:qs(e))+1,n=new st(new Uint8Array(r),0);for(;;){let i=o(e);if(e/=BigInt(128),t&&e===BigInt(0)&&(i&64)!==0||!t&&e===BigInt(0)&&(i&64)===0){n.write(new Uint8Array([i]));break}else n.write(new Uint8Array([i|128]))}function o(i){let s=i%BigInt(128);return Number(t?BigInt(128)-s-BigInt(1):s)}return n.buffer}function Pt(e){let t=new Uint8Array(e.buffer),r=0;for(;r<t.byteLength;r++)if(t[r]<128){if((t[r]&64)===0)return pe(e);break}let n=new Uint8Array(or(e,r+1)),o=BigInt(0);for(let i=n.byteLength-1;i>=0;i--)o=o*BigInt(128)+BigInt(128-(n[i]&127)-1);return-o-BigInt(1)}function Hc(e,t){if(BigInt(e)<BigInt(0))throw new Error("Cannot write negative values.");return Ms(e,t)}function Ms(e,t){e=BigInt(e);let r=new st(new Uint8Array(Math.min(1,t)),0),n=0,o=BigInt(256),i=BigInt(0),s=Number(e%o);for(r.write(new Uint8Array([s]));++n<t;)e<0&&i===BigInt(0)&&s!==0&&(i=BigInt(1)),s=Number((e/o-i)%BigInt(256)),r.write(new Uint8Array([s])),o*=BigInt(256);return r.buffer}function js(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let r=BigInt(nr(e)),n=BigInt(1),o=0;for(;++o<t;){n*=BigInt(256);let i=BigInt(nr(e));r=r+n*i}return r}function Gc(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let r=js(e,t),n=BigInt(2)**(BigInt(8)*BigInt(t-1)+BigInt(7));return r>=n&&(r-=n*BigInt(2)),r}var Z;(function(e){e[e.Null=-1]="Null",e[e.Bool=-2]="Bool",e[e.Nat=-3]="Nat",e[e.Int=-4]="Int",e[e.Float32=-13]="Float32",e[e.Float64=-14]="Float64",e[e.Text=-15]="Text",e[e.Reserved=-16]="Reserved",e[e.Empty=-17]="Empty",e[e.Opt=-18]="Opt",e[e.Vector=-19]="Vector",e[e.Record=-20]="Record",e[e.Variant=-21]="Variant",e[e.Func=-22]="Func",e[e.Service=-23]="Service",e[e.Principal=-24]="Principal"})(Z||(Z={}));var ti="DIDL",Jc=400;function $n(e,t,r){return e.map((n,o)=>r(n,t[o]))}var $s=class{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(t){return this._idx.has(t.name)}add(t,r){let n=this._typs.length;this._idx.set(t.name,n),this._idxRefCount.set(n,1),this._typs.push(r)}merge(t,r){let n=this._idx.get(t.name),o=this._idx.get(r);if(n===void 0)throw new Error("Missing type index for "+t);if(o===void 0)throw new Error("Missing type index for "+r);this._typs[n]=this._typs[o];let i=this._getIdxRefCount(n),s=this._getIdxRefCount(o);this._idxRefCount.set(n,i+s),this._idx.set(r,n),this._idxRefCount.set(o,0),this._compactFromEnd()}_getIdxRefCount(t){return this._idxRefCount.get(t)||0}_compactFromEnd(){for(;this._typs.length>0;){let t=this._typs.length-1;if(this._getIdxRefCount(t)>0)break;this._typs.pop(),this._idxRefCount.delete(t)}}encode(){let t=re(this._typs.length),r=W(...this._typs);return W(t,r)}indexOf(t){if(!this._idx.has(t))throw new Error("Missing type index for "+t);return fe(this._idx.get(t)||0)}},Hs=class{visitType(t,r){throw new Error("Not implemented")}visitPrimitive(t,r){return this.visitType(t,r)}visitEmpty(t,r){return this.visitPrimitive(t,r)}visitBool(t,r){return this.visitPrimitive(t,r)}visitNull(t,r){return this.visitPrimitive(t,r)}visitReserved(t,r){return this.visitPrimitive(t,r)}visitText(t,r){return this.visitPrimitive(t,r)}visitNumber(t,r){return this.visitPrimitive(t,r)}visitInt(t,r){return this.visitNumber(t,r)}visitNat(t,r){return this.visitNumber(t,r)}visitFloat(t,r){return this.visitPrimitive(t,r)}visitFixedInt(t,r){return this.visitNumber(t,r)}visitFixedNat(t,r){return this.visitNumber(t,r)}visitPrincipal(t,r){return this.visitPrimitive(t,r)}visitConstruct(t,r){return this.visitType(t,r)}visitVec(t,r,n){return this.visitConstruct(t,n)}visitOpt(t,r,n){return this.visitConstruct(t,n)}visitRecord(t,r,n){return this.visitConstruct(t,n)}visitTuple(t,r,n){let o=r.map((i,s)=>[`_${s}_`,i]);return this.visitRecord(t,o,n)}visitVariant(t,r,n){return this.visitConstruct(t,n)}visitRec(t,r,n){return this.visitConstruct(r,n)}visitFunc(t,r){return this.visitConstruct(t,r)}visitService(t,r){return this.visitConstruct(t,r)}},j;(function(e){e.EmptyClass="__IDL_EmptyClass__",e.UnknownClass="__IDL_UnknownClass__",e.BoolClass="__IDL_BoolClass__",e.NullClass="__IDL_NullClass__",e.ReservedClass="__IDL_ReservedClass__",e.TextClass="__IDL_TextClass__",e.IntClass="__IDL_IntClass__",e.NatClass="__IDL_NatClass__",e.FloatClass="__IDL_FloatClass__",e.FixedIntClass="__IDL_FixedIntClass__",e.FixedNatClass="__IDL_FixedNatClass__",e.VecClass="__IDL_VecClass__",e.OptClass="__IDL_OptClass__",e.RecordClass="__IDL_RecordClass__",e.TupleClass="__IDL_TupleClass__",e.VariantClass="__IDL_VariantClass__",e.RecClass="__IDL_RecClass__",e.PrincipalClass="__IDL_PrincipalClass__",e.FuncClass="__IDL_FuncClass__",e.ServiceClass="__IDL_ServiceClass__"})(j||(j={}));var nn=class{display(){return this.name}valueToString(t){return de(t)}buildTypeTable(t){t.has(this)||this._buildTypeTableImpl(t)}},qe=class extends nn{checkType(t){if(this.name!==t.name)throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`);return t}_buildTypeTableImpl(t){}},gt=class extends nn{checkType(t){if(t instanceof We){let r=t.getType();if(typeof r>"u")throw new Error("type mismatch with uninitialized type");return r}throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`)}encodeType(t){return t.indexOf(this.name)}},Hn=class extends qe{get typeName(){return j.EmptyClass}static[Symbol.hasInstance](t){return t.typeName===j.EmptyClass}accept(t,r){return t.visitEmpty(this,r)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return fe(Z.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}},ni=class extends nn{get typeName(){return j.UnknownClass}static[Symbol.hasInstance](t){return t.typeName===j.UnknownClass}checkType(t){throw new Error("Method not implemented for unknown.")}accept(t,r){throw t.visitType(this,r)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}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(t,r){let n=r.decodeValue(t,r);Object(n)!==n&&(n=Object(n));let o;return r instanceof We?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"}},oi=class extends qe{get typeName(){return j.BoolClass}static[Symbol.hasInstance](t){return t.typeName===j.BoolClass}accept(t,r){return t.visitBool(this,r)}covariant(t){if(typeof t=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){return new Uint8Array([t?1:0])}encodeType(){return fe(Z.Bool)}decodeValue(t,r){switch(this.checkType(r),nr(t)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}},vr=class extends qe{get typeName(){return j.NullClass}static[Symbol.hasInstance](t){return t.typeName===j.NullClass}accept(t,r){return t.visitNull(this,r)}covariant(t){if(t===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return fe(Z.Null)}decodeValue(t,r){return this.checkType(r),null}get name(){return"null"}},xt=class extends qe{get typeName(){return j.ReservedClass}static[Symbol.hasInstance](t){return t.typeName===j.ReservedClass}accept(t,r){return t.visitReserved(this,r)}covariant(t){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return fe(Z.Reserved)}decodeValue(t,r){return r.name!==this.name&&r.decodeValue(t,r),null}get name(){return"reserved"}},ii=class extends qe{get typeName(){return j.TextClass}static[Symbol.hasInstance](t){return t.typeName===j.TextClass}accept(t,r){return t.visitText(this,r)}covariant(t){if(typeof t=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){let r=new TextEncoder().encode(t),n=re(r.byteLength);return W(n,r)}encodeType(){return fe(Z.Text)}decodeValue(t,r){this.checkType(r);let n=pe(t),o=or(t,Number(n));return new TextDecoder("utf8",{fatal:!0}).decode(o)}get name(){return"text"}valueToString(t){return'"'+t+'"'}},Gn=class extends qe{get typeName(){return j.IntClass}static[Symbol.hasInstance](t){return t.typeName===j.IntClass}accept(t,r){return t.visitInt(this,r)}covariant(t){if(typeof t=="bigint"||Number.isInteger(t))return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){return fe(t)}encodeType(){return fe(Z.Int)}decodeValue(t,r){return this.checkType(r),Pt(t)}get name(){return"int"}valueToString(t){return t.toString()}},Jn=class extends qe{get typeName(){return j.NatClass}static[Symbol.hasInstance](t){return t.typeName===j.NatClass}accept(t,r){return t.visitNat(this,r)}covariant(t){if(typeof t=="bigint"&&t>=BigInt(0)||Number.isInteger(t)&&t>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){return re(t)}encodeType(){return fe(Z.Nat)}decodeValue(t,r){return this.checkType(r),pe(t)}get name(){return"nat"}valueToString(t){return t.toString()}},zn=class extends qe{get typeName(){return j.FloatClass}static[Symbol.hasInstance](t){return t.typeName===j.FloatClass}constructor(t){if(super(),this._bits=t,t!==32&&t!==64)throw new Error("not a valid float type")}accept(t,r){return t.visitFloat(this,r)}covariant(t){if(typeof t=="number"||t instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){let r=new ArrayBuffer(this._bits/8),n=new DataView(r);return this._bits===32?n.setFloat32(0,t,!0):n.setFloat64(0,t,!0),new Uint8Array(r)}encodeType(){let t=this._bits===32?Z.Float32:Z.Float64;return fe(t)}decodeValue(t,r){this.checkType(r);let n=or(t,this._bits/8),o=Kc(n);return this._bits===32?o.getFloat32(0,!0):o.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(t){return t.toString()}},Bt=class extends qe{get typeName(){return j.FixedIntClass}static[Symbol.hasInstance](t){return t.typeName===j.FixedIntClass}constructor(t){super(),this._bits=t}accept(t,r){return t.visitFixedInt(this,r)}covariant(t){let r=ei(this._bits-1)*BigInt(-1),n=ei(this._bits-1)-BigInt(1),o=!1;if(typeof t=="bigint")o=t>=r&&t<=n;else if(Number.isInteger(t)){let i=BigInt(t);o=i>=r&&i<=n}else o=!1;if(o)return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){return Ms(t,this._bits/8)}encodeType(){let t=Math.log2(this._bits)-3;return fe(-9-t)}decodeValue(t,r){this.checkType(r);let n=Gc(t,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`int${this._bits}`}valueToString(t){return t.toString()}},yt=class extends qe{get typeName(){return j.FixedNatClass}static[Symbol.hasInstance](t){return t.typeName===j.FixedNatClass}constructor(t){super(),this._bits=t}accept(t,r){return t.visitFixedNat(this,r)}covariant(t){let r=ei(this._bits),n=!1;if(typeof t=="bigint"&&t>=BigInt(0)?n=t<r:Number.isInteger(t)&&t>=0?n=BigInt(t)<r:n=!1,n)return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){return Hc(t,this._bits/8)}encodeType(){let t=Math.log2(this._bits)-3;return fe(-5-t)}decodeValue(t,r){this.checkType(r);let n=js(t,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`nat${this._bits}`}valueToString(t){return t.toString()}},on=class e extends gt{get typeName(){return j.VecClass}static[Symbol.hasInstance](t){return t.typeName===j.VecClass}constructor(t){super(),this._type=t,this._blobOptimization=!1,t instanceof yt&&t._bits===8&&(this._blobOptimization=!0)}accept(t,r){return t.visitVec(this,this._type,r)}covariant(t){let r=this._type instanceof yt?this._type._bits:this._type instanceof Bt?this._type._bits:0;if(ArrayBuffer.isView(t)&&r==t.BYTES_PER_ELEMENT*8||Array.isArray(t)&&t.every((n,o)=>{try{return this._type.covariant(n)}catch(i){throw new Error(`Invalid ${this.display()} argument:
36
+ `),t}},bo=class e extends G{constructor(){super(),this.name="HttpV3ApiNotSupportedErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return"HTTP request failed: v3 API is not supported"}},wo=class e extends G{constructor(t){super(),this.error=t,this.name="HttpFetchErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to fetch HTTP request: ${Oo(this.error)}`}},To=class e extends G{constructor(t){super(),this.receivedCanisterId=t,this.name="MissingCanisterIdErrorCode",Object.setPrototypeOf(this,e.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.`}},Fi=class e extends G{constructor(t){super(),this.request=t,this.name="InvalidReadStateRequestErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Invalid read state request: ${this.request}`}},No=class e extends G{constructor(t){super(),this.error=t,this.name="ExpiryJsonDeserializeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to deserialize expiry: ${this.error}`}};function Oo(e){if(e instanceof Error)return e.stack??e.message;try{return JSON.stringify(e)}catch{return String(e)}}var wr=new Error("unreachable");var gn={};Sp(gn,{Bool:()=>ml,BoolClass:()=>Di,ConstructType:()=>At,Empty:()=>fl,EmptyClass:()=>Ro,FixedIntClass:()=>Yt,FixedNatClass:()=>It,Float32:()=>bl,Float64:()=>wl,FloatClass:()=>Ao,Func:()=>Ul,FuncClass:()=>yn,Int:()=>gl,Int16:()=>Nl,Int32:()=>Ol,Int64:()=>El,Int8:()=>Tl,IntClass:()=>vo,Nat:()=>xl,Nat16:()=>vl,Nat32:()=>Il,Nat64:()=>Al,Nat8:()=>Rl,NatClass:()=>Io,Null:()=>_l,NullClass:()=>mn,Opt:()=>Cl,OptClass:()=>Or,PrimitiveType:()=>Ge,Principal:()=>Sl,PrincipalClass:()=>Li,Rec:()=>Dl,RecClass:()=>tt,Record:()=>Pl,RecordClass:()=>_n,Reserved:()=>hl,ReservedClass:()=>St,Service:()=>kl,ServiceClass:()=>Kn,Text:()=>yl,TextClass:()=>Ui,Tuple:()=>Fl,TupleClass:()=>ki,Type:()=>qn,Unknown:()=>Hp,UnknownClass:()=>Bi,Variant:()=>Bl,VariantClass:()=>jn,Vec:()=>Vl,VecClass:()=>Mn,Visitor:()=>Ws,decode:()=>Kp,encode:()=>jp,resetSubtypeCache:()=>Ys,subtype:()=>Xs});function W(...e){let t=new Uint8Array(e.reduce((n,o)=>n+o.byteLength,0)),r=0;for(let n of e)t.set(n,r),r+=n.byteLength;return t}var _t=class{save(){return this._view}restore(t){if(!(t instanceof Uint8Array))throw new Error("Checkpoint must be a Uint8Array");this._view=t}constructor(t,r=t?.byteLength||0){if(t&&!(t instanceof Uint8Array))try{t=vt(t)}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(t&&r>t.byteLength)throw new Error("Length cannot exceed buffer length");this._buffer=t||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(t){let r=this._view.subarray(0,t);return this._view=this._view.subarray(t),r.slice()}readUint8(){if(this._view.byteLength===0)return;let t=this._view[0];return this._view=this._view.subarray(1),t}write(t){if(!(t instanceof Uint8Array))throw new Error("Buffer must be a Uint8Array");let r=this._view.byteLength;this._view.byteOffset+this._view.byteLength+t.byteLength>=this._buffer.byteLength?this.alloc(t.byteLength):this._view=new Uint8Array(this._buffer.buffer,this._view.byteOffset,this._view.byteLength+t.byteLength),this._view.set(t,r)}get end(){return this._view.byteLength===0}alloc(t){if(t<=0||!Number.isInteger(t))throw new Error("Amount must be a positive integer");let r=new Uint8Array((this._buffer.byteLength+t)*1.2|0),n=new Uint8Array(r.buffer,0,this._view.byteLength+t);n.set(this._view),this._buffer=r,this._view=n}};function vt(e){if(!e)throw new Error("Input cannot be null or undefined");return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?new Uint8Array(e):"buffer"in e?vt(e.buffer):new Uint8Array(e)}function Ks(e,t){if(e.byteLength!==t.byteLength)return e.byteLength-t.byteLength;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]-t[r];return 0}function al(e,t){return Ks(e,t)===0}function cl(e){if(!(e instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Mp(e){let r=new TextEncoder().encode(e),n=0;for(let o of r)n=(n*223+o)%2**32;return n}function De(e){if(/^_\d+_$/.test(e)||/^_0x[0-9a-fA-F]+_$/.test(e)){let t=+e.slice(1,-1);if(Number.isSafeInteger(t)&&t>=0&&t<2**32)return t}return Mp(e)}function Hs(e){let t=BigInt(e);if(e<=0)throw new RangeError("Input must be positive");return t.toString(2).length-1}function Vi(e){let t=BigInt(e);if(e<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<t}function ll(){throw new Error("unexpected end of buffer")}function Nr(e,t){return e.byteLength<t&&ll(),e.read(t)}function Tr(e){let t=e.readUint8();return t===void 0&&ll(),t}function oe(e){if(typeof e=="number"&&(e=BigInt(e)),e<BigInt(0))throw new Error("Cannot leb encode negative values.");let t=(e===BigInt(0)?0:Hs(e))+1,r=new _t(new Uint8Array(t),0);for(;;){let n=Number(e&BigInt(127));if(e/=BigInt(128),e===BigInt(0)){r.write(new Uint8Array([n]));break}else r.write(new Uint8Array([n|128]))}return r.buffer}function me(e){let t=BigInt(1),r=BigInt(0),n;do n=Tr(e),r+=BigInt(n&127).valueOf()*t,t*=BigInt(128);while(n>=128);return r}function _e(e){typeof e=="number"&&(e=BigInt(e));let t=e<BigInt(0);t&&(e=-e-BigInt(1));let r=(e===BigInt(0)?0:Hs(e))+1,n=new _t(new Uint8Array(r),0);for(;;){let i=o(e);if(e/=BigInt(128),t&&e===BigInt(0)&&(i&64)!==0||!t&&e===BigInt(0)&&(i&64)===0){n.write(new Uint8Array([i]));break}else n.write(new Uint8Array([i|128]))}function o(i){let s=i%BigInt(128);return Number(t?BigInt(128)-s-BigInt(1):s)}return n.buffer}function zt(e){let t=new Uint8Array(e.buffer),r=0;for(;r<t.byteLength;r++)if(t[r]<128){if((t[r]&64)===0)return me(e);break}let n=new Uint8Array(Nr(e,r+1)),o=BigInt(0);for(let i=n.byteLength-1;i>=0;i--)o=o*BigInt(128)+BigInt(128-(n[i]&127)-1);return-o-BigInt(1)}function ul(e,t){if(BigInt(e)<BigInt(0))throw new Error("Cannot write negative values.");return $s(e,t)}function $s(e,t){e=BigInt(e);let r=new _t(new Uint8Array(Math.min(1,t)),0),n=0,o=BigInt(256),i=BigInt(0),s=Number(e%o);for(r.write(new Uint8Array([s]));++n<t;)e<0&&i===BigInt(0)&&s!==0&&(i=BigInt(1)),s=Number((e/o-i)%BigInt(256)),r.write(new Uint8Array([s])),o*=BigInt(256);return r.buffer}function Gs(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let r=BigInt(Tr(e)),n=BigInt(1),o=0;for(;++o<t;){n*=BigInt(256);let i=BigInt(Tr(e));r=r+n*i}return r}function dl(e,t){if(t<=0||!Number.isInteger(t))throw new Error("Byte length must be a positive integer");let r=Gs(e,t),n=BigInt(2)**(BigInt(8)*BigInt(t-1)+BigInt(7));return r>=n&&(r-=n*BigInt(2)),r}var Z;(function(e){e[e.Null=-1]="Null",e[e.Bool=-2]="Bool",e[e.Nat=-3]="Nat",e[e.Int=-4]="Int",e[e.Float32=-13]="Float32",e[e.Float64=-14]="Float64",e[e.Text=-15]="Text",e[e.Reserved=-16]="Reserved",e[e.Empty=-17]="Empty",e[e.Opt=-18]="Opt",e[e.Vector=-19]="Vector",e[e.Record=-20]="Record",e[e.Variant=-21]="Variant",e[e.Func=-22]="Func",e[e.Service=-23]="Service",e[e.Principal=-24]="Principal"})(Z||(Z={}));var Ci="DIDL",pl=400;function Eo(e,t,r){return e.map((n,o)=>r(n,t[o]))}var zs=class{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(t){return this._idx.has(t.name)}add(t,r){let n=this._typs.length;this._idx.set(t.name,n),this._idxRefCount.set(n,1),this._typs.push(r)}merge(t,r){let n=this._idx.get(t.name),o=this._idx.get(r);if(n===void 0)throw new Error("Missing type index for "+t);if(o===void 0)throw new Error("Missing type index for "+r);this._typs[n]=this._typs[o];let i=this._getIdxRefCount(n),s=this._getIdxRefCount(o);this._idxRefCount.set(n,i+s),this._idx.set(r,n),this._idxRefCount.set(o,0),this._compactFromEnd()}_getIdxRefCount(t){return this._idxRefCount.get(t)||0}_compactFromEnd(){for(;this._typs.length>0;){let t=this._typs.length-1;if(this._getIdxRefCount(t)>0)break;this._typs.pop(),this._idxRefCount.delete(t)}}encode(){let t=oe(this._typs.length),r=W(...this._typs);return W(t,r)}indexOf(t){if(!this._idx.has(t))throw new Error("Missing type index for "+t);return _e(this._idx.get(t)||0)}},Ws=class{visitType(t,r){throw new Error("Not implemented")}visitPrimitive(t,r){return this.visitType(t,r)}visitEmpty(t,r){return this.visitPrimitive(t,r)}visitBool(t,r){return this.visitPrimitive(t,r)}visitNull(t,r){return this.visitPrimitive(t,r)}visitReserved(t,r){return this.visitPrimitive(t,r)}visitText(t,r){return this.visitPrimitive(t,r)}visitNumber(t,r){return this.visitPrimitive(t,r)}visitInt(t,r){return this.visitNumber(t,r)}visitNat(t,r){return this.visitNumber(t,r)}visitFloat(t,r){return this.visitPrimitive(t,r)}visitFixedInt(t,r){return this.visitNumber(t,r)}visitFixedNat(t,r){return this.visitNumber(t,r)}visitPrincipal(t,r){return this.visitPrimitive(t,r)}visitConstruct(t,r){return this.visitType(t,r)}visitVec(t,r,n){return this.visitConstruct(t,n)}visitOpt(t,r,n){return this.visitConstruct(t,n)}visitRecord(t,r,n){return this.visitConstruct(t,n)}visitTuple(t,r,n){let o=r.map((i,s)=>[`_${s}_`,i]);return this.visitRecord(t,o,n)}visitVariant(t,r,n){return this.visitConstruct(t,n)}visitRec(t,r,n){return this.visitConstruct(r,n)}visitFunc(t,r){return this.visitConstruct(t,r)}visitService(t,r){return this.visitConstruct(t,r)}},K;(function(e){e.EmptyClass="__IDL_EmptyClass__",e.UnknownClass="__IDL_UnknownClass__",e.BoolClass="__IDL_BoolClass__",e.NullClass="__IDL_NullClass__",e.ReservedClass="__IDL_ReservedClass__",e.TextClass="__IDL_TextClass__",e.IntClass="__IDL_IntClass__",e.NatClass="__IDL_NatClass__",e.FloatClass="__IDL_FloatClass__",e.FixedIntClass="__IDL_FixedIntClass__",e.FixedNatClass="__IDL_FixedNatClass__",e.VecClass="__IDL_VecClass__",e.OptClass="__IDL_OptClass__",e.RecordClass="__IDL_RecordClass__",e.TupleClass="__IDL_TupleClass__",e.VariantClass="__IDL_VariantClass__",e.RecClass="__IDL_RecClass__",e.PrincipalClass="__IDL_PrincipalClass__",e.FuncClass="__IDL_FuncClass__",e.ServiceClass="__IDL_ServiceClass__"})(K||(K={}));var qn=class{display(){return this.name}valueToString(t){return he(t)}buildTypeTable(t){t.has(this)||this._buildTypeTableImpl(t)}},Ge=class extends qn{checkType(t){if(this.name!==t.name)throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`);return t}_buildTypeTableImpl(t){}},At=class extends qn{checkType(t){if(t instanceof tt){let r=t.getType();if(typeof r>"u")throw new Error("type mismatch with uninitialized type");return r}throw new Error(`type mismatch: type on the wire ${t.name}, expect type ${this.name}`)}encodeType(t){return t.indexOf(this.name)}},Ro=class extends Ge{get typeName(){return K.EmptyClass}static[Symbol.hasInstance](t){return t.typeName===K.EmptyClass}accept(t,r){return t.visitEmpty(this,r)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return _e(Z.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}},Bi=class extends qn{get typeName(){return K.UnknownClass}static[Symbol.hasInstance](t){return t.typeName===K.UnknownClass}checkType(t){throw new Error("Method not implemented for unknown.")}accept(t,r){throw t.visitType(this,r)}covariant(t){throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}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(t,r){let n=r.decodeValue(t,r);Object(n)!==n&&(n=Object(n));let o;return r instanceof tt?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"}},Di=class extends Ge{get typeName(){return K.BoolClass}static[Symbol.hasInstance](t){return t.typeName===K.BoolClass}accept(t,r){return t.visitBool(this,r)}covariant(t){if(typeof t=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){return new Uint8Array([t?1:0])}encodeType(){return _e(Z.Bool)}decodeValue(t,r){switch(this.checkType(r),Tr(t)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}},mn=class extends Ge{get typeName(){return K.NullClass}static[Symbol.hasInstance](t){return t.typeName===K.NullClass}accept(t,r){return t.visitNull(this,r)}covariant(t){if(t===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return _e(Z.Null)}decodeValue(t,r){return this.checkType(r),null}get name(){return"null"}},St=class extends Ge{get typeName(){return K.ReservedClass}static[Symbol.hasInstance](t){return t.typeName===K.ReservedClass}accept(t,r){return t.visitReserved(this,r)}covariant(t){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return _e(Z.Reserved)}decodeValue(t,r){return r.name!==this.name&&r.decodeValue(t,r),null}get name(){return"reserved"}},Ui=class extends Ge{get typeName(){return K.TextClass}static[Symbol.hasInstance](t){return t.typeName===K.TextClass}accept(t,r){return t.visitText(this,r)}covariant(t){if(typeof t=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){let r=new TextEncoder().encode(t),n=oe(r.byteLength);return W(n,r)}encodeType(){return _e(Z.Text)}decodeValue(t,r){this.checkType(r);let n=me(t),o=Nr(t,Number(n));return new TextDecoder("utf8",{fatal:!0}).decode(o)}get name(){return"text"}valueToString(t){return'"'+t+'"'}},vo=class extends Ge{get typeName(){return K.IntClass}static[Symbol.hasInstance](t){return t.typeName===K.IntClass}accept(t,r){return t.visitInt(this,r)}covariant(t){if(typeof t=="bigint"||Number.isInteger(t))return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){return _e(t)}encodeType(){return _e(Z.Int)}decodeValue(t,r){return this.checkType(r),zt(t)}get name(){return"int"}valueToString(t){return t.toString()}},Io=class extends Ge{get typeName(){return K.NatClass}static[Symbol.hasInstance](t){return t.typeName===K.NatClass}accept(t,r){return t.visitNat(this,r)}covariant(t){if(typeof t=="bigint"&&t>=BigInt(0)||Number.isInteger(t)&&t>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){return oe(t)}encodeType(){return _e(Z.Nat)}decodeValue(t,r){return this.checkType(r),me(t)}get name(){return"nat"}valueToString(t){return t.toString()}},Ao=class extends Ge{get typeName(){return K.FloatClass}static[Symbol.hasInstance](t){return t.typeName===K.FloatClass}constructor(t){if(super(),this._bits=t,t!==32&&t!==64)throw new Error("not a valid float type")}accept(t,r){return t.visitFloat(this,r)}covariant(t){if(typeof t=="number"||t instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){let r=new ArrayBuffer(this._bits/8),n=new DataView(r);return this._bits===32?n.setFloat32(0,t,!0):n.setFloat64(0,t,!0),new Uint8Array(r)}encodeType(){let t=this._bits===32?Z.Float32:Z.Float64;return _e(t)}decodeValue(t,r){this.checkType(r);let n=Nr(t,this._bits/8),o=cl(n);return this._bits===32?o.getFloat32(0,!0):o.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(t){return t.toString()}},Yt=class extends Ge{get typeName(){return K.FixedIntClass}static[Symbol.hasInstance](t){return t.typeName===K.FixedIntClass}constructor(t){super(),this._bits=t}accept(t,r){return t.visitFixedInt(this,r)}covariant(t){let r=Vi(this._bits-1)*BigInt(-1),n=Vi(this._bits-1)-BigInt(1),o=!1;if(typeof t=="bigint")o=t>=r&&t<=n;else if(Number.isInteger(t)){let i=BigInt(t);o=i>=r&&i<=n}else o=!1;if(o)return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){return $s(t,this._bits/8)}encodeType(){let t=Math.log2(this._bits)-3;return _e(-9-t)}decodeValue(t,r){this.checkType(r);let n=dl(t,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`int${this._bits}`}valueToString(t){return t.toString()}},It=class extends Ge{get typeName(){return K.FixedNatClass}static[Symbol.hasInstance](t){return t.typeName===K.FixedNatClass}constructor(t){super(),this._bits=t}accept(t,r){return t.visitFixedNat(this,r)}covariant(t){let r=Vi(this._bits),n=!1;if(typeof t=="bigint"&&t>=BigInt(0)?n=t<r:Number.isInteger(t)&&t>=0?n=BigInt(t)<r:n=!1,n)return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){return ul(t,this._bits/8)}encodeType(){let t=Math.log2(this._bits)-3;return _e(-5-t)}decodeValue(t,r){this.checkType(r);let n=Gs(t,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`nat${this._bits}`}valueToString(t){return t.toString()}},Mn=class e extends At{get typeName(){return K.VecClass}static[Symbol.hasInstance](t){return t.typeName===K.VecClass}constructor(t){super(),this._type=t,this._blobOptimization=!1,t instanceof It&&t._bits===8&&(this._blobOptimization=!0)}accept(t,r){return t.visitVec(this,this._type,r)}covariant(t){let r=this._type instanceof It?this._type._bits:this._type instanceof Yt?this._type._bits:0;if(ArrayBuffer.isView(t)&&r==t.BYTES_PER_ELEMENT*8||Array.isArray(t)&&t.every((n,o)=>{try{return this._type.covariant(n)}catch(i){throw new Error(`Invalid ${this.display()} argument:
37
37
 
38
- index ${o} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){let r=re(t.length);if(this._blobOptimization)return W(r,new Uint8Array(t));if(ArrayBuffer.isView(t))if(t instanceof Int16Array||t instanceof Uint16Array){let o=new DataView(new ArrayBuffer(t.length*2));for(let i=0;i<t.length;i++)t instanceof Int16Array?o.setInt16(i*2,t[i],!0):o.setUint16(i*2,t[i],!0);return W(r,new Uint8Array(o.buffer))}else if(t instanceof Int32Array||t instanceof Uint32Array){let o=new DataView(new ArrayBuffer(t.length*4));for(let i=0;i<t.length;i++)t instanceof Int32Array?o.setInt32(i*4,t[i],!0):o.setUint32(i*4,t[i],!0);return W(r,new Uint8Array(o.buffer))}else if(t instanceof BigInt64Array||t instanceof BigUint64Array){let o=new DataView(new ArrayBuffer(t.length*8));for(let i=0;i<t.length;i++)t instanceof BigInt64Array?o.setBigInt64(i*8,t[i],!0):o.setBigUint64(i*8,t[i],!0);return W(r,new Uint8Array(o.buffer))}else return W(r,new Uint8Array(t.buffer,t.byteOffset,t.byteLength));let n=new st(new Uint8Array(r.byteLength+t.length),0);n.write(r);for(let o of t){let i=this._type.encodeValue(o);n.write(new Uint8Array(i))}return n.buffer}_buildTypeTableImpl(t){this._type.buildTypeTable(t);let r=fe(Z.Vector),n=this._type.encodeType(t);t.add(this,W(r,n))}decodeValue(t,r){let n=this.checkType(r);if(!(n instanceof e))throw new Error("Not a vector type");let o=Number(pe(t));if(this._type instanceof yt){if(this._type._bits==8)return new Uint8Array(t.read(o));if(this._type._bits==16){let s=t.read(o*2);return new Uint16Array(s.buffer,s.byteOffset,o)}if(this._type._bits==32){let s=t.read(o*4);return new Uint32Array(s.buffer,s.byteOffset,o)}if(this._type._bits==64)return new BigUint64Array(t.read(o*8).buffer)}if(this._type instanceof Bt){if(this._type._bits==8)return new Int8Array(t.read(o));if(this._type._bits==16){let s=t.read(o*2),a=new DataView(s.buffer,s.byteOffset,s.byteLength),c=new Int16Array(o);for(let u=0;u<o;u++)c[u]=a.getInt16(u*2,!0);return c}if(this._type._bits==32){let s=t.read(o*4),a=new DataView(s.buffer,s.byteOffset,s.byteLength),c=new Int32Array(o);for(let u=0;u<o;u++)c[u]=a.getInt32(u*4,!0);return c}if(this._type._bits==64){let s=t.read(o*8),a=new DataView(s.buffer,s.byteOffset,s.byteLength),c=new BigInt64Array(o);for(let u=0;u<o;u++)c[u]=a.getBigInt64(u*8,!0);return c}}let i=[];for(let s=0;s<o;s++)i.push(this._type.decodeValue(t,n._type));return i}get name(){return`vec ${this._type.name}`}display(){return`vec ${this._type.display()}`}valueToString(t){return"vec {"+t.map(n=>this._type.valueToString(n)).join("; ")+"}"}},ir=class e extends gt{get typeName(){return j.OptClass}static[Symbol.hasInstance](t){return t.typeName===j.OptClass}constructor(t){super(),this._type=t}accept(t,r){return t.visitOpt(this,this._type,r)}covariant(t){try{if(Array.isArray(t)&&(t.length===0||t.length===1&&this._type.covariant(t[0])))return!0}catch(r){throw new Error(`Invalid ${this.display()} argument: ${de(t)}
38
+ index ${o} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){let r=oe(t.length);if(this._blobOptimization)return W(r,new Uint8Array(t));if(ArrayBuffer.isView(t))if(t instanceof Int16Array||t instanceof Uint16Array){let o=new DataView(new ArrayBuffer(t.length*2));for(let i=0;i<t.length;i++)t instanceof Int16Array?o.setInt16(i*2,t[i],!0):o.setUint16(i*2,t[i],!0);return W(r,new Uint8Array(o.buffer))}else if(t instanceof Int32Array||t instanceof Uint32Array){let o=new DataView(new ArrayBuffer(t.length*4));for(let i=0;i<t.length;i++)t instanceof Int32Array?o.setInt32(i*4,t[i],!0):o.setUint32(i*4,t[i],!0);return W(r,new Uint8Array(o.buffer))}else if(t instanceof BigInt64Array||t instanceof BigUint64Array){let o=new DataView(new ArrayBuffer(t.length*8));for(let i=0;i<t.length;i++)t instanceof BigInt64Array?o.setBigInt64(i*8,t[i],!0):o.setBigUint64(i*8,t[i],!0);return W(r,new Uint8Array(o.buffer))}else return W(r,new Uint8Array(t.buffer,t.byteOffset,t.byteLength));let n=new _t(new Uint8Array(r.byteLength+t.length),0);n.write(r);for(let o of t){let i=this._type.encodeValue(o);n.write(new Uint8Array(i))}return n.buffer}_buildTypeTableImpl(t){this._type.buildTypeTable(t);let r=_e(Z.Vector),n=this._type.encodeType(t);t.add(this,W(r,n))}decodeValue(t,r){let n=this.checkType(r);if(!(n instanceof e))throw new Error("Not a vector type");let o=Number(me(t));if(this._type instanceof It){if(this._type._bits==8)return new Uint8Array(t.read(o));if(this._type._bits==16){let s=t.read(o*2);return new Uint16Array(s.buffer,s.byteOffset,o)}if(this._type._bits==32){let s=t.read(o*4);return new Uint32Array(s.buffer,s.byteOffset,o)}if(this._type._bits==64)return new BigUint64Array(t.read(o*8).buffer)}if(this._type instanceof Yt){if(this._type._bits==8)return new Int8Array(t.read(o));if(this._type._bits==16){let s=t.read(o*2),a=new DataView(s.buffer,s.byteOffset,s.byteLength),c=new Int16Array(o);for(let u=0;u<o;u++)c[u]=a.getInt16(u*2,!0);return c}if(this._type._bits==32){let s=t.read(o*4),a=new DataView(s.buffer,s.byteOffset,s.byteLength),c=new Int32Array(o);for(let u=0;u<o;u++)c[u]=a.getInt32(u*4,!0);return c}if(this._type._bits==64){let s=t.read(o*8),a=new DataView(s.buffer,s.byteOffset,s.byteLength),c=new BigInt64Array(o);for(let u=0;u<o;u++)c[u]=a.getBigInt64(u*8,!0);return c}}let i=[];for(let s=0;s<o;s++)i.push(this._type.decodeValue(t,n._type));return i}get name(){return`vec ${this._type.name}`}display(){return`vec ${this._type.display()}`}valueToString(t){return"vec {"+t.map(n=>this._type.valueToString(n)).join("; ")+"}"}},Or=class e extends At{get typeName(){return K.OptClass}static[Symbol.hasInstance](t){return t.typeName===K.OptClass}constructor(t){super(),this._type=t}accept(t,r){return t.visitOpt(this,this._type,r)}covariant(t){try{if(Array.isArray(t)&&(t.length===0||t.length===1&&this._type.covariant(t[0])))return!0}catch(r){throw new Error(`Invalid ${this.display()} argument: ${he(t)}
39
39
 
40
- -> ${r.message}`)}throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){return t.length===0?new Uint8Array([0]):W(new Uint8Array([1]),this._type.encodeValue(t[0]))}_buildTypeTableImpl(t){this._type.buildTypeTable(t);let r=fe(Z.Opt),n=this._type.encodeType(t);t.add(this,W(r,n))}decodeValue(t,r){if(r instanceof vr)return[];if(r instanceof xt)return[];let n=r;if(r instanceof We){let o=r.getType();if(typeof o>"u")throw new Error("type mismatch with uninitialized type");n=o}if(n instanceof e)switch(nr(t)){case 0:return[];case 1:{let o=t.save();try{return[this._type.decodeValue(t,n._type)]}catch{return t.restore(o),n._type.decodeValue(t,n._type),[]}}default:throw new Error("Not an option value")}else{if(this._type instanceof vr||this._type instanceof e||this._type instanceof xt)return n.decodeValue(t,n),[];{let o=t.save();try{return[this._type.decodeValue(t,r)]}catch{return t.restore(o),n.decodeValue(t,r),[]}}}}get name(){return`opt ${this._type.name}`}display(){return`opt ${this._type.display()}`}valueToString(t){return t.length===0?"null":`opt ${this._type.valueToString(t[0])}`}},Ir=class e extends gt{get typeName(){return j.RecordClass}static[Symbol.hasInstance](t){return t.typeName===j.RecordClass||t.typeName===j.TupleClass}constructor(t={}){super(),this._fields=Object.entries(t).sort((r,n)=>Ce(r[0])-Ce(n[0]))}accept(t,r){return t.visitRecord(this,this._fields,r)}tryAsTuple(){let t=[];for(let r=0;r<this._fields.length;r++){let[n,o]=this._fields[r];if(n!==`_${r}_`)return null;t.push(o)}return t}covariant(t){if(typeof t=="object"&&this._fields.every(([r,n])=>{if(!t.hasOwnProperty(r))throw new Error(`Record is missing key "${r}".`);try{return n.covariant(t[r])}catch(o){throw new Error(`Invalid ${this.display()} argument:
40
+ -> ${r.message}`)}throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){return t.length===0?new Uint8Array([0]):W(new Uint8Array([1]),this._type.encodeValue(t[0]))}_buildTypeTableImpl(t){this._type.buildTypeTable(t);let r=_e(Z.Opt),n=this._type.encodeType(t);t.add(this,W(r,n))}decodeValue(t,r){if(r instanceof mn)return[];if(r instanceof St)return[];let n=r;if(r instanceof tt){let o=r.getType();if(typeof o>"u")throw new Error("type mismatch with uninitialized type");n=o}if(n instanceof e)switch(Tr(t)){case 0:return[];case 1:{let o=t.save();try{return[this._type.decodeValue(t,n._type)]}catch{return t.restore(o),n._type.decodeValue(t,n._type),[]}}default:throw new Error("Not an option value")}else{if(this._type instanceof mn||this._type instanceof e||this._type instanceof St)return n.decodeValue(t,n),[];{let o=t.save();try{return[this._type.decodeValue(t,r)]}catch{return t.restore(o),n.decodeValue(t,r),[]}}}}get name(){return`opt ${this._type.name}`}display(){return`opt ${this._type.display()}`}valueToString(t){return t.length===0?"null":`opt ${this._type.valueToString(t[0])}`}},_n=class e extends At{get typeName(){return K.RecordClass}static[Symbol.hasInstance](t){return t.typeName===K.RecordClass||t.typeName===K.TupleClass}constructor(t={}){super(),this._fields=Object.entries(t).sort((r,n)=>De(r[0])-De(n[0]))}accept(t,r){return t.visitRecord(this,this._fields,r)}tryAsTuple(){let t=[];for(let r=0;r<this._fields.length;r++){let[n,o]=this._fields[r];if(n!==`_${r}_`)return null;t.push(o)}return t}covariant(t){if(typeof t=="object"&&this._fields.every(([r,n])=>{if(!t.hasOwnProperty(r))throw new Error(`Record is missing key "${r}".`);try{return n.covariant(t[r])}catch(o){throw new Error(`Invalid ${this.display()} argument:
41
41
 
42
- field ${r} -> ${o.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){let r=this._fields.map(([o])=>t[o]),n=$n(this._fields,r,([,o],i)=>o.encodeValue(i));return W(...n)}_buildTypeTableImpl(t){this._fields.forEach(([i,s])=>s.buildTypeTable(t));let r=fe(Z.Record),n=re(this._fields.length),o=this._fields.map(([i,s])=>W(re(Ce(i)),s.encodeType(t)));t.add(this,W(r,n,W(...o)))}decodeValue(t,r){let n=this.checkType(r);if(!(n instanceof e))throw new Error("Not a record type");let o={},i=0,s=0;for(;s<n._fields.length;){let[a,c]=n._fields[s];if(i>=this._fields.length){c.decodeValue(t,c),s++;continue}let[u,p]=this._fields[i],d=Ce(this._fields[i][0]),l=Ce(a);if(d===l)o[u]=p.decodeValue(t,c),i++,s++;else if(l>d)if(p instanceof ir||p instanceof xt)o[u]=[],i++;else throw new Error("Cannot find required field "+u);else c.decodeValue(t,c),s++}for(let[a,c]of this._fields.slice(i))if(c instanceof ir||c instanceof xt)o[a]=[];else throw new Error("Cannot find required field "+a);return o}get fieldsAsObject(){let t={};for(let[r,n]of this._fields)t[Ce(r)]=n;return t}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(t){let r=this._fields.map(([o])=>t[o]);return`record {${$n(this._fields,r,([o,i],s)=>o+"="+i.valueToString(s)).join("; ")}}`}},si=class e extends Ir{get typeName(){return j.TupleClass}static[Symbol.hasInstance](t){return t.typeName===j.TupleClass}constructor(t){let r={};t.forEach((n,o)=>r["_"+o+"_"]=n),super(r),this._components=t}accept(t,r){return t.visitTuple(this,this._components,r)}covariant(t){if(Array.isArray(t)&&t.length>=this._fields.length&&this._components.every((r,n)=>{try{return r.covariant(t[n])}catch(o){throw new Error(`Invalid ${this.display()} argument:
42
+ field ${r} -> ${o.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){let r=this._fields.map(([o])=>t[o]),n=Eo(this._fields,r,([,o],i)=>o.encodeValue(i));return W(...n)}_buildTypeTableImpl(t){this._fields.forEach(([i,s])=>s.buildTypeTable(t));let r=_e(Z.Record),n=oe(this._fields.length),o=this._fields.map(([i,s])=>W(oe(De(i)),s.encodeType(t)));t.add(this,W(r,n,W(...o)))}decodeValue(t,r){let n=this.checkType(r);if(!(n instanceof e))throw new Error("Not a record type");let o={},i=0,s=0;for(;s<n._fields.length;){let[a,c]=n._fields[s];if(i>=this._fields.length){c.decodeValue(t,c),s++;continue}let[u,p]=this._fields[i],d=De(this._fields[i][0]),l=De(a);if(d===l)o[u]=p.decodeValue(t,c),i++,s++;else if(l>d)if(p instanceof Or||p instanceof St)o[u]=[],i++;else throw new Error("Cannot find required field "+u);else c.decodeValue(t,c),s++}for(let[a,c]of this._fields.slice(i))if(c instanceof Or||c instanceof St)o[a]=[];else throw new Error("Cannot find required field "+a);return o}get fieldsAsObject(){let t={};for(let[r,n]of this._fields)t[De(r)]=n;return t}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(t){let r=this._fields.map(([o])=>t[o]);return`record {${Eo(this._fields,r,([o,i],s)=>o+"="+i.valueToString(s)).join("; ")}}`}},ki=class e extends _n{get typeName(){return K.TupleClass}static[Symbol.hasInstance](t){return t.typeName===K.TupleClass}constructor(t){let r={};t.forEach((n,o)=>r["_"+o+"_"]=n),super(r),this._components=t}accept(t,r){return t.visitTuple(this,this._components,r)}covariant(t){if(Array.isArray(t)&&t.length>=this._fields.length&&this._components.every((r,n)=>{try{return r.covariant(t[n])}catch(o){throw new Error(`Invalid ${this.display()} argument:
43
43
 
44
- index ${n} -> ${o.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){let r=$n(this._components,t,(n,o)=>n.encodeValue(o));return W(...r)}decodeValue(t,r){let n=this.checkType(r);if(!(n instanceof e))throw new Error("not a tuple type");if(n._components.length<this._components.length)throw new Error("tuple mismatch");let o=[];for(let[i,s]of n._components.entries())i>=this._components.length?s.decodeValue(t,s):o.push(this._components[i].decodeValue(t,s));return o}display(){return`record {${this._components.map(r=>r.display()).join("; ")}}`}valueToString(t){return`record {${$n(this._components,t,(n,o)=>n.valueToString(o)).join("; ")}}`}},sn=class e extends gt{get typeName(){return j.VariantClass}static[Symbol.hasInstance](t){return t.typeName===j.VariantClass}constructor(t={}){super(),this._fields=Object.entries(t).sort((r,n)=>Ce(r[0])-Ce(n[0]))}accept(t,r){return t.visitVariant(this,this._fields,r)}covariant(t){if(typeof t=="object"&&Object.entries(t).length===1&&this._fields.every(([r,n])=>{try{return!t.hasOwnProperty(r)||n.covariant(t[r])}catch(o){throw new Error(`Invalid ${this.display()} argument:
44
+ index ${n} -> ${o.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){let r=Eo(this._components,t,(n,o)=>n.encodeValue(o));return W(...r)}decodeValue(t,r){let n=this.checkType(r);if(!(n instanceof e))throw new Error("not a tuple type");if(n._components.length<this._components.length)throw new Error("tuple mismatch");let o=[];for(let[i,s]of n._components.entries())i>=this._components.length?s.decodeValue(t,s):o.push(this._components[i].decodeValue(t,s));return o}display(){return`record {${this._components.map(r=>r.display()).join("; ")}}`}valueToString(t){return`record {${Eo(this._components,t,(n,o)=>n.valueToString(o)).join("; ")}}`}},jn=class e extends At{get typeName(){return K.VariantClass}static[Symbol.hasInstance](t){return t.typeName===K.VariantClass}constructor(t={}){super(),this._fields=Object.entries(t).sort((r,n)=>De(r[0])-De(n[0]))}accept(t,r){return t.visitVariant(this,this._fields,r)}covariant(t){if(typeof t=="object"&&Object.entries(t).length===1&&this._fields.every(([r,n])=>{try{return!t.hasOwnProperty(r)||n.covariant(t[r])}catch(o){throw new Error(`Invalid ${this.display()} argument:
45
45
 
46
- variant ${r} -> ${o.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){for(let r=0;r<this._fields.length;r++){let[n,o]=this._fields[r];if(t.hasOwnProperty(n)){let i=re(r),s=o.encodeValue(t[n]);return W(i,s)}}throw Error("Variant has no data: "+t)}_buildTypeTableImpl(t){this._fields.forEach(([,i])=>{i.buildTypeTable(t)});let r=fe(Z.Variant),n=re(this._fields.length),o=this._fields.map(([i,s])=>W(re(Ce(i)),s.encodeType(t)));t.add(this,W(r,n,...o))}decodeValue(t,r){let n=this.checkType(r);if(!(n instanceof e))throw new Error("Not a variant type");let o=Number(pe(t));if(o>=n._fields.length)throw Error("Invalid variant index: "+o);let[i,s]=n._fields[o];for(let[a,c]of this._fields)if(Ce(i)===Ce(a)){let u=c.decodeValue(t,s);return{[a]:u}}throw new Error("Cannot find field hash "+i)}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(t){for(let[r,n]of this._fields)if(t.hasOwnProperty(r)){let o=n.valueToString(t[r]);return o==="null"?`variant {${r}}`:`variant {${r}=${o}}`}throw new Error("Variant has no data: "+t)}get alternativesAsObject(){let t={};for(let[r,n]of this._fields)t[Ce(r)]=n;return t}},We=class e extends gt{constructor(){super(...arguments),this._id=e._counter++}get typeName(){return j.RecClass}static{this._counter=0}static[Symbol.hasInstance](t){return t.typeName===j.RecClass}accept(t,r){if(!this._type)throw Error("Recursive type uninitialized.");return t.visitRec(this,this._type,r)}fill(t){this._type=t}getType(){return this._type}covariant(t){if(this._type&&this._type.covariant(t))return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.encodeValue(t)}_buildTypeTableImpl(t){if(!this._type)throw Error("Recursive type uninitialized.");t.add(this,new Uint8Array([])),this._type.buildTypeTable(t),t.merge(this,this._type.name)}decodeValue(t,r){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.decodeValue(t,r)}get name(){return`rec_${this._id}`}display(){if(!this._type)throw Error("Recursive type uninitialized.");return`\u03BC${this.name}.${this._type.name}`}valueToString(t){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.valueToString(t)}};function Js(e){if(nr(e)!==1)throw new Error("Cannot decode principal");let r=Number(pe(e));return L.fromUint8Array(new Uint8Array(or(e,r)))}var ai=class extends qe{get typeName(){return j.PrincipalClass}static[Symbol.hasInstance](t){return t.typeName===j.PrincipalClass}accept(t,r){return t.visitPrincipal(this,r)}covariant(t){if(t&&t._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){let r=t.toUint8Array(),n=re(r.byteLength);return W(new Uint8Array([1]),n,r)}encodeType(){return fe(Z.Principal)}decodeValue(t,r){return this.checkType(r),Js(t)}get name(){return"principal"}valueToString(t){return`${this.name} "${t.toText()}"`}},Ar=class extends gt{get typeName(){return j.FuncClass}static[Symbol.hasInstance](t){return t.typeName===j.FuncClass}static argsToString(t,r){if(t.length!==r.length)throw new Error("arity mismatch");return"("+t.map((n,o)=>n.valueToString(r[o])).join(", ")+")"}constructor(t,r,n=[]){super(),this.argTypes=t,this.retTypes=r,this.annotations=n}accept(t,r){return t.visitFunc(this,r)}covariant(t){if(Array.isArray(t)&&t.length===2&&t[0]&&t[0]._isPrincipal&&typeof t[1]=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue([t,r]){let n=t.toUint8Array(),o=re(n.byteLength),i=W(new Uint8Array([1]),o,n),s=new TextEncoder().encode(r),a=re(s.byteLength);return W(new Uint8Array([1]),i,a,s)}_buildTypeTableImpl(t){this.argTypes.forEach(u=>u.buildTypeTable(t)),this.retTypes.forEach(u=>u.buildTypeTable(t));let r=fe(Z.Func),n=re(this.argTypes.length),o=W(...this.argTypes.map(u=>u.encodeType(t))),i=re(this.retTypes.length),s=W(...this.retTypes.map(u=>u.encodeType(t))),a=re(this.annotations.length),c=W(...this.annotations.map(u=>this.encodeAnnotation(u)));t.add(this,W(r,n,o,i,s,a,c))}decodeValue(t,r){let n=r instanceof We?r.getType()??r:r;if(!zs(n,this))throw new Error(`Cannot decode function reference at type ${this.display()} from wire type ${n.display()}`);if(nr(t)!==1)throw new Error("Cannot decode function reference");let i=Js(t),s=Number(pe(t)),a=or(t,s),u=new TextDecoder("utf8",{fatal:!0}).decode(a);return[i,u]}get name(){let t=this.argTypes.map(o=>o.name).join(", "),r=this.retTypes.map(o=>o.name).join(", "),n=" "+this.annotations.join(" ");return`(${t}) -> (${r})${n}`}valueToString([t,r]){return`func "${t.toText()}".${r}`}display(){let t=this.argTypes.map(o=>o.display()).join(", "),r=this.retTypes.map(o=>o.display()).join(", "),n=" "+this.annotations.join(" ");return`(${t}) \u2192 (${r})${n}`}encodeAnnotation(t){if(t==="query")return new Uint8Array([1]);if(t==="oneway")return new Uint8Array([2]);if(t==="composite_query")return new Uint8Array([3]);throw new Error("Illegal function annotation")}},an=class extends gt{get typeName(){return j.ServiceClass}static[Symbol.hasInstance](t){return t.typeName===j.ServiceClass}constructor(t){super(),this._fields=Object.entries(t).sort((r,n)=>r[0]<n[0]?-1:r[0]>n[0]?1:0)}accept(t,r){return t.visitService(this,r)}covariant(t){if(t&&t._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${de(t)}`)}encodeValue(t){let r=t.toUint8Array(),n=re(r.length);return W(new Uint8Array([1]),n,r)}_buildTypeTableImpl(t){this._fields.forEach(([i,s])=>s.buildTypeTable(t));let r=fe(Z.Service),n=re(this._fields.length),o=this._fields.map(([i,s])=>{let a=new TextEncoder().encode(i),c=re(a.length);return W(c,a,s.encodeType(t))});t.add(this,W(r,n,...o))}decodeValue(t,r){let n=r instanceof We?r.getType()??r:r;if(!zs(n,this))throw new Error(`Cannot decode service reference at type ${this.display()} from wire type ${n.display()}`);return Js(t)}get name(){return`service {${this._fields.map(([r,n])=>r+":"+n.name).join("; ")}}`}valueToString(t){return`service "${t.toText()}"`}fieldsAsObject(){let t={};for(let[r,n]of this._fields)t[r]=n;return t}};function de(e){let t=JSON.stringify(e,(r,n)=>typeof n=="bigint"?`BigInt(${n})`:n);return t&&t.length>Jc?t.substring(0,Jc-3)+"...":t}function hp(e,t){if(t.length<e.length)throw Error("Wrong number of message arguments");let r=new $s;e.forEach(c=>c.buildTypeTable(r));let n=new TextEncoder().encode(ti),o=r.encode(),i=re(t.length),s=W(...e.map(c=>c.encodeType(r))),a=W(...$n(e,t,(c,u)=>{try{c.covariant(u)}catch(p){throw new Error(p.message+`
46
+ variant ${r} -> ${o.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){for(let r=0;r<this._fields.length;r++){let[n,o]=this._fields[r];if(t.hasOwnProperty(n)){let i=oe(r),s=o.encodeValue(t[n]);return W(i,s)}}throw Error("Variant has no data: "+t)}_buildTypeTableImpl(t){this._fields.forEach(([,i])=>{i.buildTypeTable(t)});let r=_e(Z.Variant),n=oe(this._fields.length),o=this._fields.map(([i,s])=>W(oe(De(i)),s.encodeType(t)));t.add(this,W(r,n,...o))}decodeValue(t,r){let n=this.checkType(r);if(!(n instanceof e))throw new Error("Not a variant type");let o=Number(me(t));if(o>=n._fields.length)throw Error("Invalid variant index: "+o);let[i,s]=n._fields[o];for(let[a,c]of this._fields)if(De(i)===De(a)){let u=c.decodeValue(t,s);return{[a]:u}}throw new Error("Cannot find field hash "+i)}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(t){for(let[r,n]of this._fields)if(t.hasOwnProperty(r)){let o=n.valueToString(t[r]);return o==="null"?`variant {${r}}`:`variant {${r}=${o}}`}throw new Error("Variant has no data: "+t)}get alternativesAsObject(){let t={};for(let[r,n]of this._fields)t[De(r)]=n;return t}},tt=class e extends At{constructor(){super(...arguments),this._id=e._counter++}get typeName(){return K.RecClass}static{this._counter=0}static[Symbol.hasInstance](t){return t.typeName===K.RecClass}accept(t,r){if(!this._type)throw Error("Recursive type uninitialized.");return t.visitRec(this,this._type,r)}fill(t){this._type=t}getType(){return this._type}covariant(t){if(this._type&&this._type.covariant(t))return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.encodeValue(t)}_buildTypeTableImpl(t){if(!this._type)throw Error("Recursive type uninitialized.");t.add(this,new Uint8Array([])),this._type.buildTypeTable(t),t.merge(this,this._type.name)}decodeValue(t,r){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.decodeValue(t,r)}get name(){return`rec_${this._id}`}display(){if(!this._type)throw Error("Recursive type uninitialized.");return`\u03BC${this.name}.${this._type.name}`}valueToString(t){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.valueToString(t)}};function Zs(e){if(Tr(e)!==1)throw new Error("Cannot decode principal");let r=Number(me(e));return M.fromUint8Array(new Uint8Array(Nr(e,r)))}var Li=class extends Ge{get typeName(){return K.PrincipalClass}static[Symbol.hasInstance](t){return t.typeName===K.PrincipalClass}accept(t,r){return t.visitPrincipal(this,r)}covariant(t){if(t&&t._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){let r=t.toUint8Array(),n=oe(r.byteLength);return W(new Uint8Array([1]),n,r)}encodeType(){return _e(Z.Principal)}decodeValue(t,r){return this.checkType(r),Zs(t)}get name(){return"principal"}valueToString(t){return`${this.name} "${t.toText()}"`}},yn=class extends At{get typeName(){return K.FuncClass}static[Symbol.hasInstance](t){return t.typeName===K.FuncClass}static argsToString(t,r){if(t.length!==r.length)throw new Error("arity mismatch");return"("+t.map((n,o)=>n.valueToString(r[o])).join(", ")+")"}constructor(t,r,n=[]){super(),this.argTypes=t,this.retTypes=r,this.annotations=n}accept(t,r){return t.visitFunc(this,r)}covariant(t){if(Array.isArray(t)&&t.length===2&&t[0]&&t[0]._isPrincipal&&typeof t[1]=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue([t,r]){let n=t.toUint8Array(),o=oe(n.byteLength),i=W(new Uint8Array([1]),o,n),s=new TextEncoder().encode(r),a=oe(s.byteLength);return W(new Uint8Array([1]),i,a,s)}_buildTypeTableImpl(t){this.argTypes.forEach(u=>u.buildTypeTable(t)),this.retTypes.forEach(u=>u.buildTypeTable(t));let r=_e(Z.Func),n=oe(this.argTypes.length),o=W(...this.argTypes.map(u=>u.encodeType(t))),i=oe(this.retTypes.length),s=W(...this.retTypes.map(u=>u.encodeType(t))),a=oe(this.annotations.length),c=W(...this.annotations.map(u=>this.encodeAnnotation(u)));t.add(this,W(r,n,o,i,s,a,c))}decodeValue(t,r){let n=r instanceof tt?r.getType()??r:r;if(!Xs(n,this))throw new Error(`Cannot decode function reference at type ${this.display()} from wire type ${n.display()}`);if(Tr(t)!==1)throw new Error("Cannot decode function reference");let i=Zs(t),s=Number(me(t)),a=Nr(t,s),u=new TextDecoder("utf8",{fatal:!0}).decode(a);return[i,u]}get name(){let t=this.argTypes.map(o=>o.name).join(", "),r=this.retTypes.map(o=>o.name).join(", "),n=" "+this.annotations.join(" ");return`(${t}) -> (${r})${n}`}valueToString([t,r]){return`func "${t.toText()}".${r}`}display(){let t=this.argTypes.map(o=>o.display()).join(", "),r=this.retTypes.map(o=>o.display()).join(", "),n=" "+this.annotations.join(" ");return`(${t}) \u2192 (${r})${n}`}encodeAnnotation(t){if(t==="query")return new Uint8Array([1]);if(t==="oneway")return new Uint8Array([2]);if(t==="composite_query")return new Uint8Array([3]);throw new Error("Illegal function annotation")}},Kn=class extends At{get typeName(){return K.ServiceClass}static[Symbol.hasInstance](t){return t.typeName===K.ServiceClass}constructor(t){super(),this._fields=Object.entries(t).sort((r,n)=>r[0]<n[0]?-1:r[0]>n[0]?1:0)}accept(t,r){return t.visitService(this,r)}covariant(t){if(t&&t._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${he(t)}`)}encodeValue(t){let r=t.toUint8Array(),n=oe(r.length);return W(new Uint8Array([1]),n,r)}_buildTypeTableImpl(t){this._fields.forEach(([i,s])=>s.buildTypeTable(t));let r=_e(Z.Service),n=oe(this._fields.length),o=this._fields.map(([i,s])=>{let a=new TextEncoder().encode(i),c=oe(a.length);return W(c,a,s.encodeType(t))});t.add(this,W(r,n,...o))}decodeValue(t,r){let n=r instanceof tt?r.getType()??r:r;if(!Xs(n,this))throw new Error(`Cannot decode service reference at type ${this.display()} from wire type ${n.display()}`);return Zs(t)}get name(){return`service {${this._fields.map(([r,n])=>r+":"+n.name).join("; ")}}`}valueToString(t){return`service "${t.toText()}"`}fieldsAsObject(){let t={};for(let[r,n]of this._fields)t[r]=n;return t}};function he(e){let t=JSON.stringify(e,(r,n)=>typeof n=="bigint"?`BigInt(${n})`:n);return t&&t.length>pl?t.substring(0,pl-3)+"...":t}function jp(e,t){if(t.length<e.length)throw Error("Wrong number of message arguments");let r=new zs;e.forEach(c=>c.buildTypeTable(r));let n=new TextEncoder().encode(Ci),o=r.encode(),i=oe(t.length),s=W(...e.map(c=>c.encodeType(r))),a=W(...Eo(e,t,(c,u)=>{try{c.covariant(u)}catch(p){throw new Error(p.message+`
47
47
 
48
- `)}return c.encodeValue(u)}));return W(n,o,i,s,a)}function mp(e,t){let r=new st(t);if(t.byteLength<ti.length)throw new Error("Message length smaller than magic number");let n=or(r,ti.length),o=new TextDecoder().decode(n);if(o!==ti)throw new Error("Wrong magic number: "+JSON.stringify(o));function i(l){let f=[],h=Number(pe(l));for(let _=0;_<h;_++){let x=Number(Pt(l));switch(x){case Z.Opt:case Z.Vector:{let y=Number(Pt(l));f.push([x,y]);break}case Z.Record:case Z.Variant:{let y=[],w=Number(pe(l)),E;for(;w--;){let O=Number(pe(l));if(O>=Math.pow(2,32))throw new Error("field id out of 32-bit range");if(typeof E=="number"&&E>=O)throw new Error("field id collision or not sorted");E=O;let R=Number(Pt(l));y.push([O,R])}f.push([x,y]);break}case Z.Func:{let y=[],w=Number(pe(l));for(;w--;)y.push(Number(Pt(l)));let E=[],O=Number(pe(l));for(;O--;)E.push(Number(Pt(l)));let R=[],I=Number(pe(l));for(;I--;)switch(Number(pe(l))){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")}f.push([x,[y,E,R]]);break}case Z.Service:{let y=Number(pe(l)),w=[];for(;y--;){let E=Number(pe(l)),O=new TextDecoder().decode(or(l,E)),R=Pt(l);w.push([O,R])}f.push([x,w]);break}default:throw new Error("Illegal op_code: "+x)}}let m=[],g=Number(pe(l));for(let _=0;_<g;_++)m.push(Number(Pt(l)));return[f,m]}let[s,a]=i(r);if(a.length<e.length)throw new Error("Wrong number of return values");let c=s.map(l=>yl());function u(l){if(l<-24)throw new Error("future value not supported");if(l<0)switch(l){case-1:return Zc;case-2:return Yc;case-3:return el;case-4:return Qc;case-5:return al;case-6:return cl;case-7:return ll;case-8:return ul;case-9:return nl;case-10:return ol;case-11:return il;case-12:return sl;case-13:return tl;case-14:return rl;case-15:return Xc;case-16:return Wc;case-17:return zc;case-24:return dl;default:throw new Error("Illegal op_code: "+l)}if(l>=s.length)throw new Error("type index out of range");return c[l]}function p(l){switch(l[0]){case Z.Vector:{let f=u(l[1]);return fl(f)}case Z.Opt:{let f=u(l[1]);return hl(f)}case Z.Record:{let f={};for(let[g,_]of l[1]){let x=`_${g}_`;f[x]=u(_)}let h=ml(f),m=h.tryAsTuple();return Array.isArray(m)?pl(...m):h}case Z.Variant:{let f={};for(let[h,m]of l[1]){let g=`_${h}_`;f[g]=u(m)}return _l(f)}case Z.Func:{let[f,h,m]=l[1];return gl(f.map(g=>u(g)),h.map(g=>u(g)),m)}case Z.Service:{let f={},h=l[1];for(let[m,g]of h){let _=u(g);if(_ instanceof We&&(_=_.getType()),!(_ instanceof Ar))throw new Error("Illegal service definition: services can only contain functions");f[m]=_}return xl(f)}default:throw new Error("Illegal op_code: "+l[0])}}s.forEach((l,f)=>{if(l[0]===Z.Func){let h=p(l);c[f].fill(h)}}),s.forEach((l,f)=>{if(l[0]!==Z.Func){let h=p(l);c[f].fill(h)}}),Gs();let d=a.map(l=>u(l));try{let l=e.map((f,h)=>f.decodeValue(r,d[h]));for(let f=e.length;f<d.length;f++)d[f].decodeValue(r,d[f]);if(r.byteLength>0)throw new Error("decode: Left-over bytes");return l}finally{Gs()}}var zc=new Hn,Wc=new xt,_p=new ni,Yc=new oi,Zc=new vr,Xc=new ii,Qc=new Gn,el=new Jn,tl=new zn(32),rl=new zn(64),nl=new Bt(8),ol=new Bt(16),il=new Bt(32),sl=new Bt(64),al=new yt(8),cl=new yt(16),ll=new yt(32),ul=new yt(64),dl=new ai;function pl(...e){return new si(e)}function fl(e){return new on(e)}function hl(e){return new ir(e)}function ml(e){return new Ir(e)}function _l(e){return new sn(e)}function yl(){return new We}function gl(e,t,r=[]){return new Ar(e,t,r)}function xl(e){return new an(e)}var ci=class e{constructor(t=new Map){this.rels=t}copy(){let t=new Map;for(let[r,n]of this.rels.entries()){let o=new Map(n);t.set(r,o)}return new e(t)}known(t,r){return this.rels.get(t.name)?.get(r.name)}addNegative(t,r){this.addNames(t.name,r.name,!1)}add(t,r){this.addNames(t.name,r.name,!0)}display(){let t="";for(let[r,n]of this.rels)for(let[o,i]of n)t+=`${r} ${i?":<":"!<:"} ${o}
49
- `;return t}addNames(t,r,n){let o=this.rels.get(t);if(o==null){let i=new Map;i.set(r,n),this.rels.set(t,i)}else o.set(r,n)}},ri=new ci;function Gs(){ri=new ci}function yp(e,t){let r=new Set(e.annotations),n=new Set(t.annotations);if(r.size!==n.size)return!1;for(let o of r)if(!n.has(o))return!1;return!0}function Ks(e){return e instanceof ir||e instanceof vr||e instanceof xt}function zs(e,t){let r=ri.copy(),n=Ct(r,e,t);return n?ri.add(e,t):ri.addNegative(e,t),n}function Ct(e,t,r){if(t.name===r.name)return!0;let n=e.known(t,r);if(n!==void 0)return n;if(e.add(t,r),r instanceof xt||t instanceof Hn||t instanceof Jn&&r instanceof Gn)return!0;if(t instanceof on&&r instanceof on)return Ct(e,t._type,r._type);if(r instanceof ir)return!0;if(t instanceof Ir&&r instanceof Ir){let o=t.fieldsAsObject;for(let[i,s]of r._fields){let a=o[Ce(i)];if(a){if(!Ct(e,a,s))return!1}else if(!Ks(s))return!1}return!0}if(t instanceof Ar&&r instanceof Ar){if(!yp(t,r))return!1;for(let o=0;o<t.argTypes.length;o++){let i=t.argTypes[o];if(o<r.argTypes.length){if(!Ct(e,r.argTypes[o],i))return!1}else if(!Ks(i))return!1}for(let o=0;o<r.retTypes.length;o++){let i=r.retTypes[o];if(o<t.retTypes.length){if(!Ct(e,t.retTypes[o],i))return!1}else if(!Ks(i))return!1}return!0}if(t instanceof sn&&r instanceof sn){let o=r.alternativesAsObject;for(let[i,s]of t._fields){let a=o[Ce(i)];if(!a||!Ct(e,s,a))return!1}return!0}if(t instanceof an&&r instanceof an){let o=t.fieldsAsObject();for(let[i,s]of r._fields){let a=o[i];if(!a||!Ct(e,a,s))return!1}return!0}return t instanceof We?Ct(e,t.getType(),r):r instanceof We?Ct(e,t,r.getType()):!1}function cn(e){if(!e)throw new Error("Input cannot be null or undefined");return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?new Uint8Array(e):"buffer"in e?cn(e.buffer):new Uint8Array(e)}function Fr(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function Ws(e){if(typeof e=="string")return bl(e);if(typeof e=="number")return Ae(re(e));if(e instanceof Uint8Array||ArrayBuffer.isView(e))return Ae(cn(e));if(Array.isArray(e)){let t=e.map(Ws);return Ae(M(...t))}else{if(e&&typeof e=="object"&&e._isPrincipal)return Ae(e.toUint8Array());if(typeof e=="object"&&e!==null&&typeof e.toHash=="function")return Ws(e.toHash());if(typeof e=="object")return Wn(e);if(typeof e=="bigint")return Ae(re(e))}throw z.fromCode(new Jo(e))}var bl=e=>{let t=new TextEncoder().encode(e);return Ae(t)};function Dt(e){return Wn(e)}function Wn(e){let n=Object.entries(e).filter(([,s])=>s!==void 0).map(([s,a])=>{let c=bl(s),u=Ws(a);return[c,u]}).sort(([s],[a])=>Ls(s,a)),o=M(...n.map(s=>M(...s)));return Ae(o)}var Yn=new TextEncoder().encode(`
50
- ic-request`),Ys=new TextEncoder().encode("\vic-response"),Zs=new TextEncoder().encode("ic-request-auth-delegation");var bt=class{getPrincipal(){return this._principal||(this._principal=L.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(t){let{body:r,...n}=t,o=Dt(r);return{...n,body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(M(Yn,o))}}}},Ye=class{getPrincipal(){return L.anonymous()}async transformRequest(t){return{...t,body:{content:t.body}}}};var Ut=class extends Error{constructor(t){super(t),this.name="DecodingError"}},wl=55799,Nl=Symbol("CBOR_STOP_CODE"),lt=(e=>(e[e.False=20]="False",e[e.True=21]="True",e[e.Null=22]="Null",e[e.Undefined=23]="Undefined",e[e.Break=31]="Break",e))(lt||{}),ye=(e=>(e[e.UnsignedInteger=0]="UnsignedInteger",e[e.NegativeInteger=1]="NegativeInteger",e[e.ByteString=2]="ByteString",e[e.TextString=3]="TextString",e[e.Array=4]="Array",e[e.Map=5]="Map",e[e.Tag=6]="Tag",e[e.Simple=7]="Simple",e))(ye||{}),gp=23,xp=255,bp=65535,Tp=4294967295,wp=BigInt("0xffffffffffffffff"),ct=(e=>(e[e.Value=23]="Value",e[e.OneByte=24]="OneByte",e[e.TwoBytes=25]="TwoBytes",e[e.FourBytes=26]="FourBytes",e[e.EightBytes=27]="EightBytes",e[e.Indefinite=31]="Indefinite",e))(ct||{}),ln=!1;function Np(e){return e==null}function Ol(e,t){let r=new Uint8Array(t);return r.set(e),r}var Op=new TextDecoder;function Ep(e){return(e&224)>>5}function Rp(e){return e&31}var Qn=new Uint8Array,Zn,ut=0;function El(e,t){Qn=e,ut=0;let r=Vr(t);return t?.(r)??r}function Vr(e){let[t,r]=li();switch(t){case ye.UnsignedInteger:return un(r);case ye.NegativeInteger:return Sp(r);case ye.ByteString:return Rl(r);case ye.TextString:return Qs(r);case ye.Array:return vp(r,e);case ye.Map:return Ap(r,e);case ye.Tag:return Fp(r,e);case ye.Simple:return Ip(r)}throw new Ut(`Unsupported major type: ${t}`)}function li(){let e=Qn.at(ut);if(Np(e))throw new Ut("Provided CBOR data is empty");let t=Ep(e),r=Rp(e);return ut++,[t,r]}function vp(e,t){let r=un(e);if(r===1/0){let o=[],i=Vr(t);for(;i!==Nl;)o.push(t?.(i)??i),i=Vr(t);return o}let n=new Array(r);for(let o=0;o<r;o++){let i=Vr(t);n[o]=t?.(i)??i}return n}function Ip(e){switch(e){case lt.False:return!1;case lt.True:return!0;case lt.Null:return null;case lt.Undefined:return;case lt.Break:return Nl}throw new Ut(`Unrecognized simple type: ${e.toString(2)}`)}function Ap(e,t){let r=un(e),n={};if(r===1/0){let[o,i]=li();for(;o!==ye.Simple&&i!==lt.Break;){let s=Qs(i),a=Vr(t);n[s]=t?.(a,s)??a,[o,i]=li()}return n}for(let o=0;o<r;o++){let[i,s]=li();if(i!==ye.TextString)throw new Ut("Map keys must be text strings");let a=Qs(s),c=Vr(t);n[a]=t?.(c,a)??c}return n}function un(e){if(e<=ct.Value)return e;switch(Zn=new DataView(Qn.buffer,Qn.byteOffset+ut),e){case ct.OneByte:return ut++,Zn.getUint8(0);case ct.TwoBytes:return ut+=2,Zn.getUint16(0,ln);case ct.FourBytes:return ut+=4,Zn.getUint32(0,ln);case ct.EightBytes:return ut+=8,Zn.getBigUint64(0,ln);case ct.Indefinite:return 1/0;default:throw new Ut(`Unsupported integer info: ${e.toString(2)}`)}}function Sp(e){let t=un(e);return typeof t=="number"?-1-t:-1n-t}function Rl(e){let t=un(e);if(t>Number.MAX_SAFE_INTEGER)throw new Ut("Byte length is too large");let r=Number(t);return ut+=r,Qn.slice(ut-r,ut)}function Qs(e){let t=Rl(e);return Op.decode(t)}function Fp(e,t){let r=un(e);if(r===wl)return Vr(t);throw new Ut(`Unsupported tag: ${r}.`)}var eo=class extends Error{constructor(t){super(t),this.name="SerializationError"}},Vp=2*1024,Pp=100,Cp=new TextEncoder;function Xn(e){return e<<5}var He=new Uint8Array(Vp),at=new DataView(He.buffer),_e=0,Xs=[];function vl(e,t){_e=0;let r=t?.(e)??e;return jp(wl,r,t),He.slice(0,_e)}function ea(e,t){if(_e>He.length-Pp&&(He=Ol(He,He.length*2),at=new DataView(He.buffer)),e===!1||e===!0||e===null||e===void 0){Up(e);return}if(typeof e=="number"||typeof e=="bigint"){Mp(e);return}if(typeof e=="string"){Sl(e);return}if(e instanceof Uint8Array){Tl(e);return}if(e instanceof ArrayBuffer){Tl(new Uint8Array(e));return}if(Array.isArray(e)){Bp(e,t);return}if(typeof e=="object"){Dp(e,t);return}throw new eo(`Unsupported type: ${typeof e}`)}function Bp(e,t){dn(ye.Array,e.length),e.forEach((r,n)=>{ea(t?.(r,n.toString())??r,t)})}function Dp(e,t){Xs=Object.entries(e),dn(ye.Map,Xs.length),Xs.forEach(([r,n])=>{Sl(r),ea(t?.(n,r)??n,t)})}function dn(e,t){if(t<=gp){at.setUint8(_e++,Xn(e)|Number(t));return}if(t<=xp){at.setUint8(_e++,Xn(e)|ct.OneByte),at.setUint8(_e,Number(t)),_e+=1;return}if(t<=bp){at.setUint8(_e++,Xn(e)|ct.TwoBytes),at.setUint16(_e,Number(t),ln),_e+=2;return}if(t<=Tp){at.setUint8(_e++,Xn(e)|ct.FourBytes),at.setUint32(_e,Number(t),ln),_e+=4;return}if(t<=wp){at.setUint8(_e++,Xn(e)|ct.EightBytes),at.setBigUint64(_e,BigInt(t),ln),_e+=8;return}throw new eo(`Value too large to encode: ${t}`)}function Up(e){dn(ye.Simple,kp(e))}function kp(e){if(e===!1)return lt.False;if(e===!0)return lt.True;if(e===null)return lt.Null;if(e===void 0)return lt.Undefined;throw new eo(`Unrecognized simple value: ${e.toString()}`)}function Il(e,t){dn(e,t.length),_e>He.length-t.length&&(He=Ol(He,He.length+t.length),at=new DataView(He.buffer)),He.set(t,_e),_e+=t.length}function Al(e,t){dn(e,t)}function Lp(e){Al(ye.UnsignedInteger,e)}function qp(e){Al(ye.NegativeInteger,typeof e=="bigint"?-1n-e:-1-e)}function Mp(e){e>=0?Lp(e):qp(e)}function Sl(e){Il(ye.TextString,Cp.encode(e))}function Tl(e){Il(ye.ByteString,e)}function jp(e,t,r){dn(ye.Tag,e),ea(t,r)}function $p(e){return typeof e=="object"&&e!==null&&"toCborValue"in e}function to(e){try{return vl(e,t=>L.isPrincipal(t)?t.toUint8Array():pn.isExpiry(t)?t.toBigInt():$p(t)?t.toCborValue():t)}catch(t){throw z.fromCode(new jo(t,e))}}function Me(e){try{return El(e)}catch(t){throw z.fromCode(new Mo(t,e))}}var ui={encode:to,decode:Me};var ro=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){let e=new Uint32Array(1);return window.crypto.getRandomValues(e),e[0]}if(typeof crypto<"u"&&crypto.getRandomValues){let e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var kt;(function(e){e.Query="read",e.ReadState="read_state",e.Call="call"})(kt||(kt={}));var di;(function(e){e.Call="call"})(di||(di={}));var Pr;(function(e){e.Query="query",e.ReadState="read_state"})(Pr||(Pr={}));function no(){let e=new ArrayBuffer(16),t=new DataView(e),r=ro(),n=ro(),o=ro(),i=ro();return t.setUint32(0,r),t.setUint32(4,n),t.setUint32(8,o),t.setUint32(12,i),Object.assign(new Uint8Array(e),{__nonce__:void 0})}var pi="__expiry__",ra=BigInt(1e3),Hp=BigInt(1e6),Fl=BigInt(60),Gp=BigInt(90)*ra;function Vl(e){return e/ra}function Jp(e){return Vl(e)/Fl}var pn=class e{constructor(t){this.__expiry__=t,this._isExpiry=!0}static fromDeltaInMilliseconds(t,r=0){let n=BigInt(t),o=BigInt(Date.now())+n+BigInt(r),i;return n<Gp?i=Vl(o):i=Jp(o)*Fl,new e(i*ra*Hp)}toBigInt(){return this.__expiry__}toHash(){return re(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[pi]:this.toString()}}static fromJSON(t){let r=JSON.parse(t);if(r[pi])try{let n=BigInt(r[pi]);return new e(n)}catch(n){throw new z(new jn(`Not a valid BigInt: ${n}`))}throw new z(new jn(`The input does not contain the key ${pi}`))}static isExpiry(t){return t instanceof e||typeof t=="object"&&t!==null&&"_isExpiry"in t&&t._isExpiry===!0&&"__expiry__"in t&&typeof t.__expiry__=="bigint"}};function na(e=no){return async t=>{let r=t.request.headers;t.request.headers=r,t.endpoint===kt.Call&&(t.body.nonce=e())}}function fi(e){let t=[];return e.forEach((r,n)=>{t.push([n,r])}),t}var ia=BigInt(0),hi=BigInt(1);function Cr(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function sr(e,t,r=""){let n=ft(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,a=i?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return e}function Pl(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ia:BigInt("0x"+e)}function je(e){return Pl(K(e))}function Lt(e){return ue(e),Pl(K(Uint8Array.from(e).reverse()))}function ge(e,t){return Te(e.toString(16).padStart(t*2,"0"))}function sa(e,t){return ge(e,t).reverse()}function se(e,t,r){let n;if(typeof t=="string")try{n=Te(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(ft(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Cl(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function aa(e){return Uint8Array.from(e)}var oa=e=>typeof e=="bigint"&&ia<=e;function ca(e,t,r){return oa(e)&&oa(t)&&oa(r)&&t<=e&&e<r}function mi(e,t,r,n){if(!ca(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function qt(e){let t;for(t=0;e>ia;e>>=hi,t+=1);return t}function Bl(e,t){return e>>BigInt(t)&hi}var dt=e=>(hi<<BigInt(e))-hi;function Dl(e){return typeof e=="function"&&Number.isSafeInteger(e.outputLen)}function Mt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,i,s){let a=e[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(t).forEach(([o,i])=>n(o,i,!1)),Object.entries(r).forEach(([o,i])=>n(o,i,!0))}var fn=()=>{throw new Error("not implemented")};function ar(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var Be=BigInt(0),Ne=BigInt(1),Br=BigInt(2),kl=BigInt(3),Ll=BigInt(4),ql=BigInt(5),zp=BigInt(7),Ml=BigInt(8),Wp=BigInt(9),jl=BigInt(16);function oe(e,t){let r=e%t;return r>=Be?r:t+r}function pt(e,t,r){let n=e;for(;t-- >Be;)n*=n,n%=r;return n}function Ul(e,t){if(e===Be)throw new Error("invert: expected non-zero number");if(t<=Be)throw new Error("invert: expected positive modulus, got "+t);let r=oe(e,t),n=t,o=Be,i=Ne,s=Ne,a=Be;for(;r!==Be;){let u=n/r,p=n%r,d=o-s*u,l=i-a*u;n=r,r=p,o=s,i=a,s=d,a=l}if(n!==Ne)throw new Error("invert: does not exist");return oe(o,t)}function la(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Kl(e,t){let r=(e.ORDER+Ne)/Ll,n=e.pow(t,r);return la(e,n,t),n}function Yp(e,t){let r=(e.ORDER-ql)/Ml,n=e.mul(t,Br),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Br),o),a=e.mul(i,e.sub(s,e.ONE));return la(e,a,t),a}function Zp(e){let t=De(e),r=$l(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+zp)/jl;return(a,c)=>{let u=a.pow(c,s),p=a.mul(u,n),d=a.mul(u,o),l=a.mul(u,i),f=a.eql(a.sqr(p),c),h=a.eql(a.sqr(d),c);u=a.cmov(u,p,f),p=a.cmov(l,d,h);let m=a.eql(a.sqr(p),c),g=a.cmov(u,p,m);return la(a,g,c),g}}function $l(e){if(e<kl)throw new Error("sqrt is not defined for small field");let t=e-Ne,r=0;for(;t%Br===Be;)t/=Br,r++;let n=Br,o=De(e);for(;oo(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Kl;let i=o.pow(n,t),s=(t+Ne)/Br;return function(c,u){if(c.is0(u))return u;if(oo(c,u)!==1)throw new Error("Cannot find square root");let p=r,d=c.mul(c.ONE,i),l=c.pow(u,t),f=c.pow(u,s);for(;!c.eql(l,c.ONE);){if(c.is0(l))return c.ZERO;let h=1,m=c.sqr(l);for(;!c.eql(m,c.ONE);)if(h++,m=c.sqr(m),h===p)throw new Error("Cannot find square root");let g=Ne<<BigInt(p-h-1),_=c.pow(d,g);p=h,d=c.sqr(_),l=c.mul(l,d),f=c.mul(f,_)}return f}}function Xp(e){return e%Ll===kl?Kl:e%Ml===ql?Yp:e%jl===Wp?Zp(e):$l(e)}var jt=(e,t)=>(oe(e,t)&Ne)===Ne,Qp=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _i(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Qp.reduce((n,o)=>(n[o]="function",n),t);return Mt(e,r),e}function io(e,t,r){if(r<Be)throw new Error("invalid exponent, negatives unsupported");if(r===Be)return e.ONE;if(r===Ne)return t;let n=e.ONE,o=t;for(;r>Be;)r&Ne&&(n=e.mul(n,o)),o=e.sqr(o),r>>=Ne;return n}function Ze(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,c)=>e.is0(a)?s:(n[c]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,c)=>e.is0(a)?s:(n[c]=e.mul(s,n[c]),e.mul(s,a)),i),n}function oo(e,t){let r=(e.ORDER-Ne)/Br,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function ua(e,t){t!==void 0&&Vs(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function De(e,t,r=!1,n={}){if(e<=Be)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i,s=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(o=l.BITS),l.sqrt&&(i=l.sqrt),typeof l.isLE=="boolean"&&(r=l.isLE),typeof l.modFromBytes=="boolean"&&(s=l.modFromBytes),a=l.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:u}=ua(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,d=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:u,MASK:dt(c),ZERO:Be,ONE:Ne,allowedLengths:a,create:l=>oe(l,e),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return Be<=l&&l<e},is0:l=>l===Be,isValidNot0:l=>!d.is0(l)&&d.isValid(l),isOdd:l=>(l&Ne)===Ne,neg:l=>oe(-l,e),eql:(l,f)=>l===f,sqr:l=>oe(l*l,e),add:(l,f)=>oe(l+f,e),sub:(l,f)=>oe(l-f,e),mul:(l,f)=>oe(l*f,e),pow:(l,f)=>io(d,l,f),div:(l,f)=>oe(l*Ul(f,e),e),sqrN:l=>l*l,addN:(l,f)=>l+f,subN:(l,f)=>l-f,mulN:(l,f)=>l*f,inv:l=>Ul(l,e),sqrt:i||(l=>(p||(p=Xp(e)),p(d,l))),toBytes:l=>r?sa(l,u):ge(l,u),fromBytes:(l,f=!0)=>{if(a){if(!a.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);let m=new Uint8Array(u);m.set(l,r?0:m.length-l.length),l=m}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let h=r?Lt(l):je(l);if(s&&(h=oe(h,e)),!f&&!d.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:l=>Ze(d,l),cmov:(l,f,h)=>h?f:l});return Object.freeze(d)}function Hl(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function yi(e){let t=Hl(e);return t+Math.ceil(t/2)}function da(e,t,r=!1){let n=e.length,o=Hl(t),i=yi(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Lt(e):je(e),a=oe(s,t-Ne)+Ne;return r?sa(a,o):ge(a,o)}var hn=BigInt(0),Dr=BigInt(1);function so(e,t){let r=t.negate();return e?r:t}function Xe(e,t){let r=Ze(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Wl(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function pa(e,t){Wl(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=dt(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Gl(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),c=e>>s;a>n&&(a-=i,c+=Dr);let u=t*n,p=u+Math.abs(a)-1,d=a===0,l=a<0,f=t%2!==0;return{nextN:c,offset:p,isZero:d,isNeg:l,isNegF:f,offsetF:u}}function tf(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function rf(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var fa=new WeakMap,Yl=new WeakMap;function ha(e){return Yl.get(e)||1}function Jl(e){if(e!==hn)throw new Error("invalid wNAF")}var mn=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>hn;)r&Dr&&(n=n.add(o)),o=o.double(),r>>=Dr;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=pa(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=pa(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:p,isNeg:d,isNegF:l,offsetF:f}=Gl(n,a,s);n=c,p?i=i.add(so(l,r[f])):o=o.add(so(d,r[u]))}return Jl(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=pa(t,this.bits);for(let s=0;s<i.windows&&n!==hn;s++){let{nextN:a,offset:c,isZero:u,isNeg:p}=Gl(n,s,i);if(n=a,!u){let d=r[c];o=o.add(p?d.negate():d)}}return Jl(n),o}getPrecomputes(t,r,n){let o=fa.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),fa.set(r,o))),o}cached(t,r,n){let o=ha(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=ha(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Wl(r,this.bits),Yl.set(t,r),fa.delete(t)}hasCache(t){return ha(t)!==1}};function Zl(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>hn||n>hn;)r&Dr&&(i=i.add(o)),n&Dr&&(s=s.add(o)),o=o.double(),r>>=Dr,n>>=Dr;return{p1:i,p2:s}}function _n(e,t,r,n){tf(r,e),rf(n,t);let o=r.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=e.ZERO,a=qt(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=dt(c),p=new Array(Number(u)+1).fill(s),d=Math.floor((t.BITS-1)/c)*c,l=s;for(let f=d;f>=0;f-=c){p.fill(s);for(let m=0;m<i;m++){let g=n[m],_=Number(g>>BigInt(f)&u);p[_]=p[_].add(r[m])}let h=s;for(let m=p.length-1,g=s;m>0;m--)g=g.add(p[m]),h=h.add(g);if(l=l.add(h),f!==0)for(let m=0;m<c;m++)l=l.double()}return l}function zl(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return _i(t),t}else return De(e,{isLE:r})}function gi(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>hn))throw new Error(`CURVE.${c} must be positive bigint`)}let o=zl(t.p,r.Fp,n),i=zl(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}var nf=je;function cr(e,t){if(ao(e),ao(t),e<0||e>=1<<8*t)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function of(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function ao(e){if(!Number.isSafeInteger(e))throw new Error("number expected")}function Xl(e){if(!ft(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or string");return typeof e=="string"?Q(e):e}function sf(e,t,r,n){ue(e),ao(r),t=Xl(t),t.length>255&&(t=n(M(Q("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:i}=n,s=Math.ceil(r/o);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=M(t,cr(t.length,1)),c=cr(0,i),u=cr(r,2),p=new Array(s),d=n(M(c,e,u,cr(0,1),a));p[0]=n(M(d,cr(1,1),a));for(let f=1;f<=s;f++){let h=[of(d,p[f-1]),cr(f+1,1),a];p[f]=n(M(...h))}return M(...p).slice(0,r)}function af(e,t,r,n,o){if(ue(e),ao(r),t=Xl(t),t.length>255){let i=Math.ceil(2*n/8);t=o.create({dkLen:i}).update(Q("H2C-OVERSIZE-DST-")).update(t).digest()}if(r>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return o.create({dkLen:r}).update(e).update(cr(r,2)).update(t).update(cr(t.length,1)).digest()}function ma(e,t,r){Mt(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:o,m:i,hash:s,expand:a,DST:c}=r;if(!Dl(r.hash))throw new Error("expected valid hash");ue(e),ao(t);let u=n.toString(2).length,p=Math.ceil((u+o)/8),d=t*i*p,l;if(a==="xmd")l=sf(e,c,d,s);else if(a==="xof")l=af(e,c,d,o,s);else if(a==="_internal_pass")l=e;else throw new Error('expand must be "xmd" or "xof"');let f=new Array(t);for(let h=0;h<t;h++){let m=new Array(i);for(let g=0;g<i;g++){let _=p*(g+h*i),x=l.subarray(_,_+p);m[g]=oe(nf(x),n)}f[h]=m}return f}function _a(e,t){let r=t.map(n=>Array.from(n).reverse());return(n,o)=>{let[i,s,a,c]=r.map(d=>d.reduce((l,f)=>e.add(e.mul(l,n),f))),[u,p]=Ze(e,[s,c],!0);return n=e.mul(i,u),o=e.mul(o,e.mul(a,p)),{x:n,y:o}}}var cf=Q("HashToScalar-");function ya(e,t,r){if(typeof t!="function")throw new Error("mapToCurve() must be defined");function n(i){return e.fromAffine(t(i))}function o(i){let s=i.clearCofactor();return s.equals(e.ZERO)?e.ZERO:(s.assertValidity(),s)}return{defaults:r,hashToCurve(i,s){let a=Object.assign({},r,s),c=ma(i,2,a),u=n(c[0]),p=n(c[1]);return o(u.add(p))},encodeToCurve(i,s){let a=r.encodeDST?{DST:r.encodeDST}:{},c=Object.assign({},r,a,s),u=ma(i,1,c),p=n(u[0]);return o(p)},mapToCurve(i){if(!Array.isArray(i))throw new Error("expected array of bigints");for(let s of i)if(typeof s!="bigint")throw new Error("expected array of bigints");return o(n(i))},hashToScalar(i,s){let a=e.Fn.ORDER,c=Object.assign({},r,{p:a,m:1,DST:cf},s);return ma(i,1,c)[0][0]}}}var Ql=(e,t)=>(e+(e>=0?t:-t)/Kt)/t;function lf(e,t,r){let[[n,o],[i,s]]=t,a=Ql(s*e,r),c=Ql(-o*e,r),u=e-a*n-c*i,p=-a*o-c*s,d=u<Ur,l=p<Ur;d&&(u=-u),l&&(p=-p);let f=dt(Math.ceil(qt(r)/2))+Ue;if(u<Ur||u>=f||p<Ur||p>=f)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:u,k2neg:l,k2:p}}var Ur=BigInt(0),Ue=BigInt(1),Kt=BigInt(2),yn=BigInt(3),ga=BigInt(4);function co(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=se("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function uf(e,t={}){let r=gi("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:a}=i;Mt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=ff(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(S,b,N){let{x:V,y:B}=b.toAffine(),q=n.toBytes(V);if(Cr(N,"isCompressed"),N){p();let A=!n.isOdd(B);return M(df(A),q)}else return M(Uint8Array.of(4),q,n.toBytes(B))}function l(S){sr(S,void 0,"Point");let{publicKey:b,publicKeyUncompressed:N}=u,V=S.length,B=S[0],q=S.subarray(1);if(V===b&&(B===2||B===3)){let A=n.fromBytes(q);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let P=m(A),C;try{C=n.sqrt(P)}catch(ne){let ee=ne instanceof Error?": "+ne.message:"";throw new Error("bad point: is not on curve, sqrt error"+ee)}p();let U=n.isOdd(C);return(B&1)===1!==U&&(C=n.neg(C)),{x:A,y:C}}else if(V===N&&B===4){let A=n.BYTES,P=n.fromBytes(q.subarray(0,A)),C=n.fromBytes(q.subarray(A,A*2));if(!g(P,C))throw new Error("bad point: is not on curve");return{x:P,y:C}}else throw new Error(`bad point: got length ${V}, expected compressed=${b} or uncompressed=${N}`)}let f=t.toBytes||d,h=t.fromBytes||l;function m(S){let b=n.sqr(S),N=n.mul(b,S);return n.add(n.add(N,n.mul(S,i.a)),i.b)}function g(S,b){let N=n.sqr(b),V=m(S);return n.eql(N,V)}if(!g(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let _=n.mul(n.pow(i.a,yn),ga),x=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(_,x)))throw new Error("bad curve params: a or b");function y(S,b,N=!1){if(!n.isValid(b)||N&&n.is0(b))throw new Error(`bad point coordinate ${S}`);return b}function w(S){if(!(S instanceof T))throw new Error("ProjectivePoint expected")}function E(S){if(!c||!c.basises)throw new Error("no endo");return lf(S,c.basises,o.ORDER)}let O=ar((S,b)=>{let{X:N,Y:V,Z:B}=S;if(n.eql(B,n.ONE))return{x:N,y:V};let q=S.is0();b==null&&(b=q?n.ONE:n.inv(B));let A=n.mul(N,b),P=n.mul(V,b),C=n.mul(B,b);if(q)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:A,y:P}}),R=ar(S=>{if(S.is0()){if(t.allowInfinityPoint&&!n.is0(S.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:N}=S.toAffine();if(!n.isValid(b)||!n.isValid(N))throw new Error("bad point: x or y not field elements");if(!g(b,N))throw new Error("bad point: equation left != right");if(!S.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function I(S,b,N,V,B){return N=new T(n.mul(N.X,S),N.Y,N.Z),b=so(V,b),N=so(B,N),b.add(N)}class T{constructor(b,N,V){this.X=y("x",b),this.Y=y("y",N,!0),this.Z=y("z",V),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){let{x:N,y:V}=b||{};if(!b||!n.isValid(N)||!n.isValid(V))throw new Error("invalid affine point");if(b instanceof T)throw new Error("projective point not allowed");return n.is0(N)&&n.is0(V)?T.ZERO:new T(N,V,n.ONE)}static fromBytes(b){let N=T.fromAffine(h(sr(b,void 0,"point")));return N.assertValidity(),N}static fromHex(b){return T.fromBytes(se("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,N=!0){return F.createCache(this,b),N||this.multiply(yn),this}assertValidity(){R(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){w(b);let{X:N,Y:V,Z:B}=this,{X:q,Y:A,Z:P}=b,C=n.eql(n.mul(N,P),n.mul(q,B)),U=n.eql(n.mul(V,P),n.mul(A,B));return C&&U}negate(){return new T(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:N}=i,V=n.mul(N,yn),{X:B,Y:q,Z:A}=this,P=n.ZERO,C=n.ZERO,U=n.ZERO,k=n.mul(B,B),ne=n.mul(q,q),ee=n.mul(A,A),J=n.mul(B,q);return J=n.add(J,J),U=n.mul(B,A),U=n.add(U,U),P=n.mul(b,U),C=n.mul(V,ee),C=n.add(P,C),P=n.sub(ne,C),C=n.add(ne,C),C=n.mul(P,C),P=n.mul(J,P),U=n.mul(V,U),ee=n.mul(b,ee),J=n.sub(k,ee),J=n.mul(b,J),J=n.add(J,U),U=n.add(k,k),k=n.add(U,k),k=n.add(k,ee),k=n.mul(k,J),C=n.add(C,k),ee=n.mul(q,A),ee=n.add(ee,ee),k=n.mul(ee,J),P=n.sub(P,k),U=n.mul(ee,ne),U=n.add(U,U),U=n.add(U,U),new T(P,C,U)}add(b){w(b);let{X:N,Y:V,Z:B}=this,{X:q,Y:A,Z:P}=b,C=n.ZERO,U=n.ZERO,k=n.ZERO,ne=i.a,ee=n.mul(i.b,yn),J=n.mul(N,q),he=n.mul(V,A),Re=n.mul(B,P),ze=n.add(N,V),le=n.add(q,A);ze=n.mul(ze,le),le=n.add(J,he),ze=n.sub(ze,le),le=n.add(N,B);let be=n.add(q,P);return le=n.mul(le,be),be=n.add(J,Re),le=n.sub(le,be),be=n.add(V,B),C=n.add(A,P),be=n.mul(be,C),C=n.add(he,Re),be=n.sub(be,C),k=n.mul(ne,le),C=n.mul(ee,Re),k=n.add(C,k),C=n.sub(he,k),k=n.add(he,k),U=n.mul(C,k),he=n.add(J,J),he=n.add(he,J),Re=n.mul(ne,Re),le=n.mul(ee,le),he=n.add(he,Re),Re=n.sub(J,Re),Re=n.mul(ne,Re),le=n.add(le,Re),J=n.mul(he,le),U=n.add(U,J),J=n.mul(be,le),C=n.mul(ze,C),C=n.sub(C,J),J=n.mul(ze,he),k=n.mul(be,k),k=n.add(k,J),new T(C,U,k)}subtract(b){return this.add(b.negate())}is0(){return this.equals(T.ZERO)}multiply(b){let{endo:N}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let V,B,q=A=>F.cached(this,A,P=>Xe(T,P));if(N){let{k1neg:A,k1:P,k2neg:C,k2:U}=E(b),{p:k,f:ne}=q(P),{p:ee,f:J}=q(U);B=ne.add(J),V=I(N.beta,k,ee,A,C)}else{let{p:A,f:P}=q(b);V=A,B=P}return Xe(T,[V,B])[0]}multiplyUnsafe(b){let{endo:N}=t,V=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Ur||V.is0())return T.ZERO;if(b===Ue)return V;if(F.hasCache(this))return this.multiply(b);if(N){let{k1neg:B,k1:q,k2neg:A,k2:P}=E(b),{p1:C,p2:U}=Zl(T,V,q,P);return I(N.beta,C,U,B,A)}else return F.unsafe(V,b)}multiplyAndAddUnsafe(b,N,V){let B=this.multiplyUnsafe(N).add(b.multiplyUnsafe(V));return B.is0()?void 0:B}toAffine(b){return O(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return s===Ue?!0:b?b(T,this):F.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:b}=t;return s===Ue?this:b?b(T,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(b=!0){return Cr(b,"isCompressed"),this.assertValidity(),f(T,this,b)}toHex(b=!0){return K(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return Xe(T,b)}static msm(b,N){return _n(T,o,b,N)}static fromPrivateKey(b){return T.BASE.multiply(co(o,b))}}T.BASE=new T(i.Gx,i.Gy,n.ONE),T.ZERO=new T(n.ZERO,n.ONE,n.ZERO),T.Fp=n,T.Fn=o;let v=o.BITS,F=new mn(T,t.endo?Math.ceil(v/2):v);return T.BASE.precompute(8),T}function df(e){return Uint8Array.of(e?2:3)}function pf(e,t){let r=e.ORDER,n=Ur;for(let h=r-Ue;h%Kt===Ur;h/=Kt)n+=Ue;let o=n,i=Kt<<o-Ue-Ue,s=i*Kt,a=(r-Ue)/s,c=(a-Ue)/Kt,u=s-Ue,p=i,d=e.pow(t,a),l=e.pow(t,(a+Ue)/Kt),f=(h,m)=>{let g=d,_=e.pow(m,u),x=e.sqr(_);x=e.mul(x,m);let y=e.mul(h,x);y=e.pow(y,c),y=e.mul(y,_),_=e.mul(y,m),x=e.mul(y,h);let w=e.mul(x,_);y=e.pow(w,p);let E=e.eql(y,e.ONE);_=e.mul(x,l),y=e.mul(w,g),x=e.cmov(_,x,E),w=e.cmov(y,w,E);for(let O=o;O>Ue;O--){let R=O-Kt;R=Kt<<R-Ue;let I=e.pow(w,R),T=e.eql(I,e.ONE);_=e.mul(x,g),g=e.mul(g,g),I=e.mul(w,g),x=e.cmov(_,x,T),w=e.cmov(I,w,T)}return{isValid:E,value:x}};if(e.ORDER%ga===yn){let h=(e.ORDER-yn)/ga,m=e.sqrt(e.neg(t));f=(g,_)=>{let x=e.sqr(_),y=e.mul(g,_);x=e.mul(x,y);let w=e.pow(x,h);w=e.mul(w,y);let E=e.mul(w,m),O=e.mul(e.sqr(w),_),R=e.eql(O,g),I=e.cmov(E,w,R);return{isValid:R,value:I}}}return f}function xa(e,t){_i(e);let{A:r,B:n,Z:o}=t;if(!e.isValid(r)||!e.isValid(n)||!e.isValid(o))throw new Error("mapToCurveSimpleSWU: invalid opts");let i=pf(e,o);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return s=>{let a,c,u,p,d,l,f,h;a=e.sqr(s),a=e.mul(a,o),c=e.sqr(a),c=e.add(c,a),u=e.add(c,e.ONE),u=e.mul(u,n),p=e.cmov(o,e.neg(c),!e.eql(c,e.ZERO)),p=e.mul(p,r),c=e.sqr(u),l=e.sqr(p),d=e.mul(l,r),c=e.add(c,d),c=e.mul(c,u),l=e.mul(l,p),d=e.mul(l,n),c=e.add(c,d),f=e.mul(a,u);let{isValid:m,value:g}=i(c,l);h=e.mul(a,s),h=e.mul(h,g),f=e.cmov(f,u,m),h=e.cmov(h,g,m);let _=e.isOdd(s)===e.isOdd(h);h=e.cmov(e.neg(h),h,_);let x=Ze(e,[p],!0)[0];return f=e.mul(f,x),{x:f,y:h}}}function ff(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ba(e){let{CURVE:t,curveOpts:r}=hf(e),n=uf(t,r);return _f(e,n)}function hf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=De(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),i={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:i}}function mf(e,t,r){function n(o){let i=e.sqr(o),s=e.mul(i,o);return e.add(e.add(s,e.mul(o,t)),r)}return n}function _f(e,t){let{Fp:r,Fn:n}=t;function o(s){return ca(s,Ue,n.ORDER)}let i=mf(r,e.a,e.b);return Object.assign({},{CURVE:e,Point:t,ProjectivePoint:t,normPrivateKeyToScalar:s=>co(n,s),weierstrassEquation:i,isWithinCurveOrder:o})}var yf=BigInt(0),xi=BigInt(1),eu=BigInt(2),gn=BigInt(3);function gf(e){let t=[];for(;e>xi;e>>=xi)(e&xi)===yf?t.unshift(0):(e&gn)===gn?(t.unshift(-1),e+=xi):t.unshift(1);return t}function Ta(e){if(!Array.isArray(e)||e.length===0)throw new Error("expected non-empty array")}function xf(e,t,r,n){let{Fp2:o,Fp12:i}=e,{twistType:s,ateLoopSize:a,xNegative:c,postPrecompute:u}=n,p;if(s==="multiplicative")p=(y,w,E,O,R,I)=>i.mul014(O,y,o.mul(w,R),o.mul(E,I));else if(s==="divisive")p=(y,w,E,O,R,I)=>i.mul034(O,o.mul(E,I),o.mul(w,R),y);else throw new Error("bls: unknown twist type");let d=o.div(o.ONE,o.mul(o.ONE,eu));function l(y,w,E,O){let R=o.sqr(E),I=o.sqr(O),T=o.mulByB(o.mul(I,gn)),v=o.mul(T,gn),F=o.sub(o.sub(o.sqr(o.add(E,O)),I),R),S=o.sub(T,R),b=o.mul(o.sqr(w),gn),N=o.neg(F);return y.push([S,b,N]),w=o.mul(o.mul(o.mul(o.sub(R,v),w),E),d),E=o.sub(o.sqr(o.mul(o.add(R,v),d)),o.mul(o.sqr(T),gn)),O=o.mul(R,F),{Rx:w,Ry:E,Rz:O}}function f(y,w,E,O,R,I){let T=o.sub(E,o.mul(I,O)),v=o.sub(w,o.mul(R,O)),F=o.sub(o.mul(T,R),o.mul(v,I)),S=o.neg(T),b=v;y.push([F,S,b]);let N=o.sqr(v),V=o.mul(N,v),B=o.mul(N,w),q=o.add(o.sub(V,o.mul(B,eu)),o.mul(o.sqr(T),O));return w=o.mul(v,q),E=o.sub(o.mul(o.sub(B,q),T),o.mul(V,E)),O=o.mul(O,V),{Rx:w,Ry:E,Rz:O}}let h=gf(a),m=ar(y=>{let w=y,{x:E,y:O}=w.toAffine(),R=E,I=O,T=o.neg(O),v=R,F=I,S=o.ONE,b=[];for(let N of h){let V=[];({Rx:v,Ry:F,Rz:S}=l(V,v,F,S)),N&&({Rx:v,Ry:F,Rz:S}=f(V,v,F,S,R,N===-1?T:I)),b.push(V)}if(u){let N=b[b.length-1];u(v,F,S,R,I,f.bind(null,N))}return b});function g(y,w=!1){let E=i.ONE;if(y.length){let O=y[0][0].length;for(let R=0;R<O;R++){E=i.sqr(E);for(let[I,T,v]of y)for(let[F,S,b]of I[R])E=p(F,S,b,E,T,v)}}return c&&(E=i.conjugate(E)),w?i.finalExponentiate(E):E}function _(y,w=!0){let E=[];Xe(t,y.map(({g1:O})=>O)),Xe(r,y.map(({g2:O})=>O));for(let{g1:O,g2:R}of y){if(O.is0()||R.is0())throw new Error("pairing is not available for ZERO point");O.assertValidity(),R.assertValidity();let I=O.toAffine();E.push([m(R),I.x,I.y])}return g(E,w)}function x(y,w,E=!0){return _([{g1:y,g2:w}],E)}return{Fp12:i,millerLoopBatch:g,pairing:x,pairingBatch:_,calcPairingPrecomputes:m}}function tu(e,t,r,n,o){let{Fp12:i,pairingBatch:s}=e;function a(d){return d instanceof t.Point?d:t.Point.fromHex(d)}function c(d){return d instanceof r.Point?d:r.Point.fromHex(d)}function u(d){if(!(d instanceof r.Point))throw new Error(`expected valid message hashed to ${o?"G1":"G2"} curve`);return d}let p=o?(d,l)=>({g1:l,g2:d}):(d,l)=>({g1:d,g2:l});return{getPublicKey(d){let l=co(t.Point.Fn,d);return t.Point.BASE.multiply(l)},sign(d,l,f){if(f!=null)throw new Error("sign() expects 2 arguments");let h=co(t.Point.Fn,l);return u(d).assertValidity(),d.multiply(h)},verify(d,l,f,h){if(h!=null)throw new Error("verify() expects 3 arguments");d=c(d),f=a(f);let m=f.negate(),g=t.Point.BASE,_=u(l),x=d,y=s([p(m,_),p(g,x)]);return i.eql(y,i.ONE)},verifyBatch(d,l,f){if(Ta(l),f.length!==l.length)throw new Error("amount of public keys and messages should be equal");let h=c(d),m=l,g=f.map(a),_=new Map;for(let w=0;w<g.length;w++){let E=g[w],O=m[w],R=_.get(O);R===void 0&&(R=[],_.set(O,R)),R.push(E)}let x=[],y=t.Point.BASE;try{for(let[w,E]of _){let O=E.reduce((R,I)=>R.add(I));x.push(p(O,w))}return x.push(p(y.negate(),h)),i.eql(s(x),i.ONE)}catch{return!1}},aggregatePublicKeys(d){Ta(d),d=d.map(f=>a(f));let l=d.reduce((f,h)=>f.add(h),t.Point.ZERO);return l.assertValidity(),l},aggregateSignatures(d){Ta(d),d=d.map(f=>c(f));let l=d.reduce((f,h)=>f.add(h),r.Point.ZERO);return l.assertValidity(),l},hash(d,l){ue(d);let f=l?{DST:l}:void 0;return r.hashToCurve(d,f)},Signature:n}}function ru(e){let{Fp:t,Fr:r,Fp2:n,Fp6:o,Fp12:i}=e.fields,s=ba(e.G1),a=Object.assign(s,ya(s.Point,e.G1.mapToCurve,{...e.htfDefaults,...e.G1.htfDefaults})),c=ba(e.G2),u=Object.assign(c,ya(c.Point,e.G2.mapToCurve,{...e.htfDefaults,...e.G2.htfDefaults})),p=xf(e.fields,a.Point,u.Point,{...e.params,postPrecompute:e.postPrecompute}),{millerLoopBatch:d,pairing:l,pairingBatch:f,calcPairingPrecomputes:h}=p,m=tu(p,a,u,e.G2.Signature,!1),g=tu(p,u,a,e.G1.ShortSignature,!0),_=e.randomBytes||Zr,x=()=>{let A=yi(r.ORDER);return da(_(A),r.ORDER)},y={randomSecretKey:x,randomPrivateKey:x,calcPairingPrecomputes:h},{ShortSignature:w}=e.G1,{Signature:E}=e.G2;function O(A,P){return A instanceof a.Point?A:g.hash(se("point",A),P?.DST)}function R(A,P){return A instanceof u.Point?A:m.hash(se("point",A),P?.DST)}function I(A){return m.getPublicKey(A).toBytes(!0)}function T(A){return g.getPublicKey(A).toBytes(!0)}function v(A,P,C){let U=R(A,C),k=m.sign(U,P);return A instanceof u.Point?k:E.toBytes(k)}function F(A,P,C){let U=O(A,C),k=g.sign(U,P);return A instanceof a.Point?k:w.toBytes(k)}function S(A,P,C,U){let k=R(P,U);return m.verify(A,k,C)}function b(A,P,C,U){let k=O(P,U);return g.verify(A,k,C)}function N(A){let P=m.aggregatePublicKeys(A);return A[0]instanceof a.Point?P:P.toBytes(!0)}function V(A){let P=m.aggregateSignatures(A);return A[0]instanceof u.Point?P:E.toBytes(P)}function B(A){let P=g.aggregateSignatures(A);return A[0]instanceof a.Point?P:w.toBytes(P)}function q(A,P,C,U){let k=P.map(ne=>R(ne,U));return m.verifyBatch(A,k,C)}return a.Point.BASE.precompute(4),{longSignatures:m,shortSignatures:g,millerLoopBatch:d,pairing:l,pairingBatch:f,verifyBatch:q,fields:{Fr:r,Fp:t,Fp2:n,Fp6:o,Fp12:i},params:{ateLoopSize:e.params.ateLoopSize,twistType:e.params.twistType,r:e.params.r,G1b:e.G1.b,G2b:e.G2.b},utils:y,getPublicKey:I,getPublicKeyForShortSignatures:T,sign:v,signShortSignature:F,verify:S,verifyShortSignature:b,aggregatePublicKeys:N,aggregateSignatures:V,aggregateShortSignatures:B,G1:a,G2:u,Signature:E,ShortSignature:w}}var nu=BigInt(0),$t=BigInt(1),ke=BigInt(2),ou=BigInt(3);function Ea(e,t,r,n,o=1,i){let s=BigInt(i===void 0?n:i),a=r**BigInt(n),c=[];for(let u=0;u<o;u++){let p=BigInt(u+1),d=[];for(let l=0,f=$t;l<n;l++){let h=(p*f-p)/s%a;d.push(e.pow(t,h)),f*=r}c.push(d)}return c}function su(e,t,r){let n=t.pow(r,(e.ORDER-$t)/ou),o=t.pow(r,(e.ORDER-$t)/ke);function i(l,f){let h=t.mul(t.frobeniusMap(l,1),n),m=t.mul(t.frobeniusMap(f,1),o);return[h,m]}let s=t.pow(r,(e.ORDER**ke-$t)/ou),a=t.pow(r,(e.ORDER**ke-$t)/ke);if(!t.eql(a,t.neg(t.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(l,f){return[t.mul(l,s),t.neg(f)]}let u=l=>(f,h)=>{let m=h.toAffine(),g=l(m.x,m.y);return f.fromAffine({x:g[0],y:g[1]})},p=u(i),d=u(c);return{psi:i,psi2:c,G2psi:p,G2psi2:d,PSI_X:n,PSI_Y:o,PSI2_X:s,PSI2_Y:a}}var iu=(e,t)=>{if(t.length!==2)throw new Error("invalid tuple");let r=t.map(n=>e.create(n));return{c0:r[0],c1:r[1]}},wa=class{constructor(t,r={}){this.MASK=$t;let n=t.ORDER,o=n*n;this.Fp=t,this.ORDER=o,this.BITS=qt(o),this.BYTES=Math.ceil(qt(o)/8),this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.Fp_NONRESIDUE=t.create(r.NONRESIDUE||BigInt(-1)),this.Fp_div2=t.div(t.ONE,ke),this.NONRESIDUE=iu(t,r.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=Ea(t,this.Fp_NONRESIDUE,t.ORDER,2)[0],this.mulByB=r.Fp2mulByB,Object.seal(this)}fromBigTuple(t){return iu(this.Fp,t)}create(t){return t}isValid({c0:t,c1:r}){function n(o,i){return typeof o=="bigint"&&nu<=o&&o<i}return n(t,this.ORDER)&&n(r,this.ORDER)}is0({c0:t,c1:r}){return this.Fp.is0(t)&&this.Fp.is0(r)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}eql({c0:t,c1:r},{c0:n,c1:o}){return this.Fp.eql(t,n)&&this.Fp.eql(r,o)}neg({c0:t,c1:r}){return{c0:this.Fp.neg(t),c1:this.Fp.neg(r)}}pow(t,r){return io(this,t,r)}invertBatch(t){return Ze(this,t)}add(t,r){let{c0:n,c1:o}=t,{c0:i,c1:s}=r;return{c0:this.Fp.add(n,i),c1:this.Fp.add(o,s)}}sub({c0:t,c1:r},{c0:n,c1:o}){return{c0:this.Fp.sub(t,n),c1:this.Fp.sub(r,o)}}mul({c0:t,c1:r},n){let{Fp:o}=this;if(typeof n=="bigint")return{c0:o.mul(t,n),c1:o.mul(r,n)};let{c0:i,c1:s}=n,a=o.mul(t,i),c=o.mul(r,s),u=o.sub(a,c),p=o.sub(o.mul(o.add(t,r),o.add(i,s)),o.add(a,c));return{c0:u,c1:p}}sqr({c0:t,c1:r}){let{Fp:n}=this,o=n.add(t,r),i=n.sub(t,r),s=n.add(t,t);return{c0:n.mul(o,i),c1:n.mul(s,r)}}addN(t,r){return this.add(t,r)}subN(t,r){return this.sub(t,r)}mulN(t,r){return this.mul(t,r)}sqrN(t){return this.sqr(t)}div(t,r){let{Fp:n}=this;return this.mul(t,typeof r=="bigint"?n.inv(n.create(r)):this.inv(r))}inv({c0:t,c1:r}){let{Fp:n}=this,o=n.inv(n.create(t*t+r*r));return{c0:n.mul(o,n.create(t)),c1:n.mul(o,n.create(-r))}}sqrt(t){let{Fp:r}=this,n=this,{c0:o,c1:i}=t;if(r.is0(i))return oo(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 s=r.sqrt(r.sub(r.sqr(o),r.mul(r.sqr(i),this.Fp_NONRESIDUE))),a=r.mul(r.add(s,o),this.Fp_div2);oo(r,a)===-1&&(a=r.sub(a,s));let u=r.sqrt(a),p=n.create({c0:u,c1:r.div(r.mul(i,this.Fp_div2),u)});if(!n.eql(n.sqr(p),t))throw new Error("Cannot find square root");let d=p,l=n.neg(d),{re:f,im:h}=n.reim(d),{re:m,im:g}=n.reim(l);return h>g||h===g&&f>m?d:l}isOdd(t){let{re:r,im:n}=this.reim(t),o=r%ke,i=r===nu,s=n%ke;return BigInt(o||i&&s)==$t}fromBytes(t){let{Fp:r}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:r.fromBytes(t.subarray(0,r.BYTES)),c1:r.fromBytes(t.subarray(r.BYTES))}}toBytes({c0:t,c1:r}){return M(this.Fp.toBytes(t),this.Fp.toBytes(r))}cmov({c0:t,c1:r},{c0:n,c1:o},i){return{c0:this.Fp.cmov(t,n,i),c1:this.Fp.cmov(r,o,i)}}reim({c0:t,c1:r}){return{re:t,im:r}}Fp4Square(t,r){let n=this,o=n.sqr(t),i=n.sqr(r);return{first:n.add(n.mulByNonresidue(i),o),second:n.sub(n.sub(n.sqr(n.add(t,r)),o),i)}}mulByNonresidue({c0:t,c1:r}){return this.mul({c0:t,c1:r},this.NONRESIDUE)}frobeniusMap({c0:t,c1:r},n){return{c0:t,c1:this.Fp.mul(r,this.FROBENIUS_COEFFICIENTS[n%2])}}},Na=class{constructor(t){this.MASK=$t,this.Fp2=t,this.ORDER=t.ORDER,this.BITS=3*t.BITS,this.BYTES=3*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO,c2:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO,c2:t.ZERO};let{Fp:r}=t,n=Ea(t,t.NONRESIDUE,r.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=n[0],this.FROBENIUS_COEFFICIENTS_2=n[1],Object.seal(this)}add({c0:t,c1:r,c2:n},{c0:o,c1:i,c2:s}){let{Fp2:a}=this;return{c0:a.add(t,o),c1:a.add(r,i),c2:a.add(n,s)}}sub({c0:t,c1:r,c2:n},{c0:o,c1:i,c2:s}){let{Fp2:a}=this;return{c0:a.sub(t,o),c1:a.sub(r,i),c2:a.sub(n,s)}}mul({c0:t,c1:r,c2:n},o){let{Fp2:i}=this;if(typeof o=="bigint")return{c0:i.mul(t,o),c1:i.mul(r,o),c2:i.mul(n,o)};let{c0:s,c1:a,c2:c}=o,u=i.mul(t,s),p=i.mul(r,a),d=i.mul(n,c);return{c0:i.add(u,i.mulByNonresidue(i.sub(i.mul(i.add(r,n),i.add(a,c)),i.add(p,d)))),c1:i.add(i.sub(i.mul(i.add(t,r),i.add(s,a)),i.add(u,p)),i.mulByNonresidue(d)),c2:i.sub(i.add(p,i.mul(i.add(t,n),i.add(s,c))),i.add(u,d))}}sqr({c0:t,c1:r,c2:n}){let{Fp2:o}=this,i=o.sqr(t),s=o.mul(o.mul(t,r),ke),a=o.mul(o.mul(r,n),ke),c=o.sqr(n);return{c0:o.add(o.mulByNonresidue(a),i),c1:o.add(o.mulByNonresidue(c),s),c2:o.sub(o.sub(o.add(o.add(s,o.sqr(o.add(o.sub(t,r),n))),a),i),c)}}addN(t,r){return this.add(t,r)}subN(t,r){return this.sub(t,r)}mulN(t,r){return this.mul(t,r)}sqrN(t){return this.sqr(t)}create(t){return t}isValid({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return o.isValid(t)&&o.isValid(r)&&o.isValid(n)}is0({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return o.is0(t)&&o.is0(r)&&o.is0(n)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return{c0:o.neg(t),c1:o.neg(r),c2:o.neg(n)}}eql({c0:t,c1:r,c2:n},{c0:o,c1:i,c2:s}){let{Fp2:a}=this;return a.eql(t,o)&&a.eql(r,i)&&a.eql(n,s)}sqrt(t){return fn()}div(t,r){let{Fp2:n}=this,{Fp:o}=n;return this.mul(t,typeof r=="bigint"?o.inv(o.create(r)):this.inv(r))}pow(t,r){return io(this,t,r)}invertBatch(t){return Ze(this,t)}inv({c0:t,c1:r,c2:n}){let{Fp2:o}=this,i=o.sub(o.sqr(t),o.mulByNonresidue(o.mul(n,r))),s=o.sub(o.mulByNonresidue(o.sqr(n)),o.mul(t,r)),a=o.sub(o.sqr(r),o.mul(t,n)),c=o.inv(o.add(o.mulByNonresidue(o.add(o.mul(n,s),o.mul(r,a))),o.mul(t,i)));return{c0:o.mul(c,i),c1:o.mul(c,s),c2:o.mul(c,a)}}fromBytes(t){let{Fp2:r}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);let n=r.BYTES;return{c0:r.fromBytes(t.subarray(0,n)),c1:r.fromBytes(t.subarray(n,n*2)),c2:r.fromBytes(t.subarray(2*n))}}toBytes({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return M(o.toBytes(t),o.toBytes(r),o.toBytes(n))}cmov({c0:t,c1:r,c2:n},{c0:o,c1:i,c2:s},a){let{Fp2:c}=this;return{c0:c.cmov(t,o,a),c1:c.cmov(r,i,a),c2:c.cmov(n,s,a)}}fromBigSix(t){let{Fp2:r}=this;if(!Array.isArray(t)||t.length!==6)throw new Error("invalid Fp6 usage");return{c0:r.fromBigTuple(t.slice(0,2)),c1:r.fromBigTuple(t.slice(2,4)),c2:r.fromBigTuple(t.slice(4,6))}}frobeniusMap({c0:t,c1:r,c2:n},o){let{Fp2:i}=this;return{c0:i.frobeniusMap(t,o),c1:i.mul(i.frobeniusMap(r,o),this.FROBENIUS_COEFFICIENTS_1[o%6]),c2:i.mul(i.frobeniusMap(n,o),this.FROBENIUS_COEFFICIENTS_2[o%6])}}mulByFp2({c0:t,c1:r,c2:n},o){let{Fp2:i}=this;return{c0:i.mul(t,o),c1:i.mul(r,o),c2:i.mul(n,o)}}mulByNonresidue({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return{c0:o.mulByNonresidue(n),c1:t,c2:r}}mul1({c0:t,c1:r,c2:n},o){let{Fp2:i}=this;return{c0:i.mulByNonresidue(i.mul(n,o)),c1:i.mul(t,o),c2:i.mul(r,o)}}mul01({c0:t,c1:r,c2:n},o,i){let{Fp2:s}=this,a=s.mul(t,o),c=s.mul(r,i);return{c0:s.add(s.mulByNonresidue(s.sub(s.mul(s.add(r,n),i),c)),a),c1:s.sub(s.sub(s.mul(s.add(o,i),s.add(t,r)),a),c),c2:s.add(s.sub(s.mul(s.add(t,n),o),a),c)}}},Oa=class{constructor(t,r){this.MASK=$t;let{Fp2:n}=t,{Fp:o}=n;this.Fp6=t,this.ORDER=n.ORDER,this.BITS=2*t.BITS,this.BYTES=2*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.FROBENIUS_COEFFICIENTS=Ea(n,n.NONRESIDUE,o.ORDER,12,1,6)[0],this.X_LEN=r.X_LEN,this.finalExponentiate=r.Fp12finalExponentiate}create(t){return t}isValid({c0:t,c1:r}){let{Fp6:n}=this;return n.isValid(t)&&n.isValid(r)}is0({c0:t,c1:r}){let{Fp6:n}=this;return n.is0(t)&&n.is0(r)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:r}){let{Fp6:n}=this;return{c0:n.neg(t),c1:n.neg(r)}}eql({c0:t,c1:r},{c0:n,c1:o}){let{Fp6:i}=this;return i.eql(t,n)&&i.eql(r,o)}sqrt(t){fn()}inv({c0:t,c1:r}){let{Fp6:n}=this,o=n.inv(n.sub(n.sqr(t),n.mulByNonresidue(n.sqr(r))));return{c0:n.mul(t,o),c1:n.neg(n.mul(r,o))}}div(t,r){let{Fp6:n}=this,{Fp2:o}=n,{Fp:i}=o;return this.mul(t,typeof r=="bigint"?i.inv(i.create(r)):this.inv(r))}pow(t,r){return io(this,t,r)}invertBatch(t){return Ze(this,t)}add({c0:t,c1:r},{c0:n,c1:o}){let{Fp6:i}=this;return{c0:i.add(t,n),c1:i.add(r,o)}}sub({c0:t,c1:r},{c0:n,c1:o}){let{Fp6:i}=this;return{c0:i.sub(t,n),c1:i.sub(r,o)}}mul({c0:t,c1:r},n){let{Fp6:o}=this;if(typeof n=="bigint")return{c0:o.mul(t,n),c1:o.mul(r,n)};let{c0:i,c1:s}=n,a=o.mul(t,i),c=o.mul(r,s);return{c0:o.add(a,o.mulByNonresidue(c)),c1:o.sub(o.mul(o.add(t,r),o.add(i,s)),o.add(a,c))}}sqr({c0:t,c1:r}){let{Fp6:n}=this,o=n.mul(t,r);return{c0:n.sub(n.sub(n.mul(n.add(n.mulByNonresidue(r),t),n.add(t,r)),o),n.mulByNonresidue(o)),c1:n.add(o,o)}}addN(t,r){return this.add(t,r)}subN(t,r){return this.sub(t,r)}mulN(t,r){return this.mul(t,r)}sqrN(t){return this.sqr(t)}fromBytes(t){let{Fp6:r}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:r.fromBytes(t.subarray(0,r.BYTES)),c1:r.fromBytes(t.subarray(r.BYTES))}}toBytes({c0:t,c1:r}){let{Fp6:n}=this;return M(n.toBytes(t),n.toBytes(r))}cmov({c0:t,c1:r},{c0:n,c1:o},i){let{Fp6:s}=this;return{c0:s.cmov(t,n,i),c1:s.cmov(r,o,i)}}fromBigTwelve(t){let{Fp6:r}=this;return{c0:r.fromBigSix(t.slice(0,6)),c1:r.fromBigSix(t.slice(6,12))}}frobeniusMap(t,r){let{Fp6:n}=this,{Fp2:o}=n,{c0:i,c1:s,c2:a}=n.frobeniusMap(t.c1,r),c=this.FROBENIUS_COEFFICIENTS[r%12];return{c0:n.frobeniusMap(t.c0,r),c1:n.create({c0:o.mul(i,c),c1:o.mul(s,c),c2:o.mul(a,c)})}}mulByFp2({c0:t,c1:r},n){let{Fp6:o}=this;return{c0:o.mulByFp2(t,n),c1:o.mulByFp2(r,n)}}conjugate({c0:t,c1:r}){return{c0:t,c1:this.Fp6.neg(r)}}mul014({c0:t,c1:r},n,o,i){let{Fp6:s}=this,{Fp2:a}=s,c=s.mul01(t,n,o),u=s.mul1(r,i);return{c0:s.add(s.mulByNonresidue(u),c),c1:s.sub(s.sub(s.mul01(s.add(r,t),n,a.add(o,i)),c),u)}}mul034({c0:t,c1:r},n,o,i){let{Fp6:s}=this,{Fp2:a}=s,c=s.create({c0:a.mul(t.c0,n),c1:a.mul(t.c1,n),c2:a.mul(t.c2,n)}),u=s.mul01(r,o,i),p=s.mul01(s.add(t,r),a.add(n,o),i);return{c0:s.add(s.mulByNonresidue(u),c),c1:s.sub(p,s.add(c,u))}}_cyclotomicSquare({c0:t,c1:r}){let{Fp6:n}=this,{Fp2:o}=n,{c0:i,c1:s,c2:a}=t,{c0:c,c1:u,c2:p}=r,{first:d,second:l}=o.Fp4Square(i,u),{first:f,second:h}=o.Fp4Square(c,a),{first:m,second:g}=o.Fp4Square(s,p),_=o.mulByNonresidue(g);return{c0:n.create({c0:o.add(o.mul(o.sub(d,i),ke),d),c1:o.add(o.mul(o.sub(f,s),ke),f),c2:o.add(o.mul(o.sub(m,a),ke),m)}),c1:n.create({c0:o.add(o.mul(o.add(_,c),ke),_),c1:o.add(o.mul(o.add(l,u),ke),l),c2:o.add(o.mul(o.add(h,p),ke),h)})}}_cyclotomicExp(t,r){let n=this.ONE;for(let o=this.X_LEN-1;o>=0;o--)n=this._cyclotomicSquare(n),Bl(r,o)&&(n=this.mul(n,t));return n}};function au(e){let t=De(e.ORDER),r=new wa(t,e),n=new Na(r),o=new Oa(n,e);return{Fp:t,Fp2:r,Fp6:n,Fp12:o}}var Se=BigInt(0),bi=BigInt(1),Qe=BigInt(2),Ti=BigInt(3),lo=BigInt(4),lr=BigInt("0xd201000000010000"),bf=qt(lr),kr={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:Se,b:lo,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")},Tf=De(kr.n,{modFromBytes:!0,isLE:!0}),{Fp:D,Fp2:G,Fp6:wf,Fp12:Y}=au({ORDER:kr.p,X_LEN:bf,FP2_NONRESIDUE:[bi,bi],Fp2mulByB:({c0:e,c1:t})=>{let r=D.mul(e,lo),n=D.mul(t,lo);return{c0:D.sub(r,n),c1:D.add(r,n)}},Fp12finalExponentiate:e=>{let t=lr,r=Y.div(Y.frobeniusMap(e,6),e),n=Y.mul(Y.frobeniusMap(r,2),r),o=Y.conjugate(Y._cyclotomicExp(n,t)),i=Y.mul(Y.conjugate(Y._cyclotomicSquare(n)),o),s=Y.conjugate(Y._cyclotomicExp(i,t)),a=Y.conjugate(Y._cyclotomicExp(s,t)),c=Y.mul(Y.conjugate(Y._cyclotomicExp(a,t)),Y._cyclotomicSquare(o)),u=Y.conjugate(Y._cyclotomicExp(c,t)),p=Y.frobeniusMap(Y.mul(o,a),2),d=Y.frobeniusMap(Y.mul(s,n),3),l=Y.frobeniusMap(Y.mul(c,Y.conjugate(n)),1),f=Y.mul(Y.mul(u,Y.conjugate(i)),n);return Y.mul(Y.mul(Y.mul(p,d),l),f)}}),{G2psi:cu,G2psi2:Nf}=su(D,G,G.div(G.ONE,G.NONRESIDUE)),Ra=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:D.ORDER,m:2,k:128,expand:"xmd",hash:Ae}),Aa={p:G.ORDER,n:kr.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:G.ZERO,b:G.fromBigTuple([lo,lo]),Gx:G.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:G.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},wi=uo(D.toBytes(Se),{infinity:!0,compressed:!0});function Ni(e){e=e.slice();let t=e[0]&224,r=!!(t>>7&1),n=!!(t>>6&1),o=!!(t>>5&1);return e[0]&=31,{compressed:r,infinity:n,sort:o,value:e}}function uo(e,t){if(e[0]&224)throw new Error("setMask: non-empty mask");return t.compressed&&(e[0]|=128),t.infinity&&(e[0]|=64),t.sort&&(e[0]|=32),e}function Of(e,t,r){let{BYTES:n,ORDER:o}=D,i=t.is0(),{x:s,y:a}=t.toAffine();if(r){if(i)return wi.slice();let c=!!(a*Qe/o);return uo(ge(s,n),{compressed:!0,sort:c})}else return i?M(Uint8Array.of(64),new Uint8Array(2*n-1)):M(ge(s,n),ge(a,n))}function va(e){e.assertValidity();let{BYTES:t,ORDER:r}=D,{x:n,y:o}=e.toAffine();if(e.is0())return wi.slice();let i=!!(o*Qe/r);return uo(ge(n,t),{compressed:!0,sort:i})}function Ef(e){let{compressed:t,infinity:r,sort:n,value:o}=Ni(e),{BYTES:i,ORDER:s}=D;if(o.length===48&&t){let a=je(o),c=D.create(a&dt(D.BITS));if(r){if(c!==Se)throw new Error("invalid G1 point: non-empty, at infinity, with compression");return{x:Se,y:Se}}let u=D.add(D.pow(c,Ti),D.create(kr.b)),p=D.sqrt(u);if(!p)throw new Error("invalid G1 point: compressed point");return p*Qe/s!==BigInt(n)&&(p=D.neg(p)),{x:D.create(c),y:D.create(p)}}else if(o.length===96&&!t){let a=je(o.subarray(0,i)),c=je(o.subarray(i));if(r){if(a!==Se||c!==Se)throw new Error("G1: non-empty point at infinity");return po.G1.Point.ZERO.toAffine()}return{x:D.create(a),y:D.create(c)}}else throw new Error("invalid G1 point: expected 48/96 bytes")}function lu(e){let{infinity:t,sort:r,value:n}=Ni(se("signatureHex",e,48)),o=D.ORDER,i=po.G1.Point,s=je(n);if(t)return i.ZERO;let a=D.create(s&dt(D.BITS)),c=D.add(D.pow(a,Ti),D.create(kr.b)),u=D.sqrt(c);if(!u)throw new Error("invalid G1 point: compressed");let p=BigInt(r);u*Qe/o!==p&&(u=D.neg(u));let d=i.fromAffine({x:a,y:u});return d.assertValidity(),d}function Rf(e,t,r){let{BYTES:n,ORDER:o}=D,i=t.is0(),{x:s,y:a}=t.toAffine();if(r){if(i)return M(wi,ge(Se,n));let c=!!(a.c1===Se?a.c0*Qe/o:a.c1*Qe/o);return M(uo(ge(s.c1,n),{compressed:!0,sort:c}),ge(s.c0,n))}else{if(i)return M(Uint8Array.of(64),new Uint8Array(4*n-1));let{re:c,im:u}=G.reim(s),{re:p,im:d}=G.reim(a);return M(ge(u,n),ge(c,n),ge(d,n),ge(p,n))}}function Ia(e){e.assertValidity();let{BYTES:t}=D;if(e.is0())return M(wi,ge(Se,t));let{x:r,y:n}=e.toAffine(),{re:o,im:i}=G.reim(r),{re:s,im:a}=G.reim(n),u=!!((a>Se?a*Qe:s*Qe)/D.ORDER&bi),p=o;return M(uo(ge(i,t),{sort:u,compressed:!0}),ge(p,t))}function vf(e){let{BYTES:t,ORDER:r}=D,{compressed:n,infinity:o,sort:i,value:s}=Ni(e);if(!n&&!o&&i||!n&&o&&i||i&&o&&n)throw new Error("invalid encoding flag: "+(e[0]&224));let a=(c,u,p)=>je(c.slice(u,p));if(s.length===96&&n){if(o){if(s.reduce((h,m)=>h!==0?m+1:m,0)>0)throw new Error("invalid G2 point: compressed");return{x:G.ZERO,y:G.ZERO}}let c=a(s,0,t),u=a(s,t,2*t),p=G.create({c0:D.create(u),c1:D.create(c)}),d=G.add(G.pow(p,Ti),Aa.b),l=G.sqrt(d),f=l.c1===Se?l.c0*Qe/r:l.c1*Qe/r?bi:Se;return l=i&&f>0?l:G.neg(l),{x:p,y:l}}else if(s.length===192&&!n){if(o){if(s.reduce((l,f)=>l!==0?f+1:f,0)>0)throw new Error("invalid G2 point: uncompressed");return{x:G.ZERO,y:G.ZERO}}let c=a(s,0*t,1*t),u=a(s,1*t,2*t),p=a(s,2*t,3*t),d=a(s,3*t,4*t);return{x:G.fromBigTuple([u,c]),y:G.fromBigTuple([d,p])}}else throw new Error("invalid G2 point: expected 96/192 bytes")}function uu(e){let{ORDER:t}=D,{infinity:r,sort:n,value:o}=Ni(se("signatureHex",e)),i=po.G2.Point,s=o.length/2;if(s!==48&&s!==96)throw new Error("invalid compressed signature length, expected 96/192 bytes");let a=je(o.slice(0,s)),c=je(o.slice(s));if(r)return i.ZERO;let u=D.create(a&dt(D.BITS)),p=D.create(c),d=G.create({c0:p,c1:u}),l=G.add(G.pow(d,Ti),Aa.b),f=G.sqrt(l);if(!f)throw new Error("Failed to find a square root");let{re:h,im:m}=G.reim(f),g=BigInt(n),_=m>Se&&m*Qe/t!==g,x=m===Se&&h*Qe/t!==g;(_||x)&&(f=G.neg(f));let y=i.fromAffine({x:d,y:f});return y.assertValidity(),y}var po=ru({fields:{Fp:D,Fp2:G,Fp6:wf,Fp12:Y,Fr:Tf},G1:{...kr,Fp:D,htfDefaults:{...Ra,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(e,t)=>{let r=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),n=new e(D.mul(t.X,r),t.Y,t.Z);return t.multiplyUnsafe(lr).negate().multiplyUnsafe(lr).equals(n)},clearCofactor:(e,t)=>t.multiplyUnsafe(lr).add(t),mapToCurve:Vf,fromBytes:Ef,toBytes:Of,ShortSignature:{fromBytes(e){return ue(e),lu(e)},fromHex(e){return lu(e)},toBytes(e){return va(e)},toRawBytes(e){return va(e)},toHex(e){return K(va(e))}}},G2:{...Aa,Fp:G,hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...Ra},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:Pf,isTorsionFree:(e,t)=>t.multiplyUnsafe(lr).negate().equals(cu(e,t)),clearCofactor:(e,t)=>{let r=lr,n=t.multiplyUnsafe(r).negate(),o=cu(e,t),i=t.double();return i=Nf(e,i),i=i.subtract(o),o=n.add(o),o=o.multiplyUnsafe(r).negate(),i=i.add(o),i=i.subtract(n),i.subtract(t)},fromBytes:vf,toBytes:Rf,Signature:{fromBytes(e){return ue(e),uu(e)},fromHex(e){return uu(e)},toBytes(e){return Ia(e)},toRawBytes(e){return Ia(e)},toHex(e){return K(Ia(e))}}},params:{ateLoopSize:lr,r:kr.n,xNegative:!0,twistType:"multiplicative"},htfDefaults:Ra,hash:Ae}),If=_a(G,[[["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(e=>e.map(t=>G.fromBigTuple(t.map(BigInt))))),Af=_a(D,[["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(e=>e.map(t=>BigInt(t)))),Sf=xa(D,{A:D.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:D.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:D.create(BigInt(11))}),Ff=xa(G,{A:G.create({c0:D.create(Se),c1:D.create(BigInt(240))}),B:G.create({c0:D.create(BigInt(1012)),c1:D.create(BigInt(1012))}),Z:G.create({c0:D.create(BigInt(-2)),c1:D.create(BigInt(-1))})});function Vf(e){let{x:t,y:r}=Sf(D.create(e[0]));return Af(t,r)}function Pf(e){let{x:t,y:r}=Ff(G.fromBigTuple(e));return If(t,r)}function du(e,t,r){let n=typeof e=="string"?e:K(e),o=typeof t=="string"?t:K(t),i=typeof r=="string"?r:K(r);return po.verifyShortSignature(o,i,n)}var Bf=BigInt(1e6),Sa=e=>pe(new st(e)),xn=e=>{let r=Sa(e)/Bf;return new Date(Number(r))};var pu=60*1e3,Df=60,Uf=24,kf=Uf*Df,Lf=5,qf=5,Mf=30*kf,Ie;(function(e){e[e.Empty=0]="Empty",e[e.Fork=1]="Fork",e[e.Labeled=2]="Labeled",e[e.Leaf=3]="Leaf",e[e.Pruned=4]="Pruned"})(Ie||(Ie={}));function jf(e,t){for(let r=0;r<e.length;r++)if(e[r]>t[r])return!0;return!1}var ur=class e{#e=!1;#t=void 0;static async create(t){let r=e.createUnverified(t);return await r.verify(),r}static createUnverified(t){return new e(t.certificate,t.rootKey,t.canisterId,t.blsVerify??du,t.maxAgeInMinutes,t.disableTimeVerification,t.agent)}constructor(t,r,n,o,i=Lf,s=!1,a){this._rootKey=r,this._canisterId=n,this._blsVerify=o,this._maxAgeInMinutes=i,this.#e=s,this.cert=Me(t),a&&"getTimeDiffMsecs"in a&&"hasSyncedTime"in a&&"syncTime"in a&&(this.#t=a)}lookup_path(t){return qr(t,this.cert.tree)}lookup_subtree(t){return Ri(t,this.cert.tree)}async verify(){let t=await Oi(this.cert.tree),r=await this._checkDelegationAndGetKey(this.cert.delegation),n=this.cert.signature,o=$f(r),i=M(ho("ic-state-root"),t),s=Fe(this.lookup_path(["time"]));if(!s)throw te.fromCode(new Qt("Certificate does not contain a time"));if(!this.#e){let a=this.#t?.getTimeDiffMsecs()??0,c=this._maxAgeInMinutes*pu,u=new Date,p=u.getTime()+a,d=p-c,l=p+qf*pu,f=xn(s),h=f.getTime()<d,m=f.getTime()>l;if((h||m)&&this.#t&&!this.#t.hasSyncedTime())return await this.#t.syncTime(this._canisterId),await this.verify();if(h)throw Ve.fromCode(new Or(this._maxAgeInMinutes,f,u,a,"past"));if(m)throw this.#t?.hasSyncedTime()?me.fromCode(new Pe("System time has been synced with the IC network, but certificate is still too far in the future.")):Ve.fromCode(new Or(5,f,u,a,"future"))}try{if(!await this._blsVerify(o,n,i))throw Ve.fromCode(new Qt("Invalid signature"))}catch(a){throw Ve.fromCode(new Qt("Signature verification failed",a))}}async _checkDelegationAndGetKey(t){if(!t)return this._rootKey;let r=e.createUnverified({certificate:t.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,disableTimeVerification:this.#e,maxAgeInMinutes:Mf,agent:this.#t});if(r.cert.delegation)throw te.fromCode(new Uo);await r.verify();let n=t.subnet_id,o=L.fromUint8Array(n);if(!Fa({canisterId:this._canisterId,subnetId:o,tree:r.cert.tree}))throw Ve.fromCode(new Xr(this._canisterId,o));let s=Fe(r.lookup_path(["subnet",n,"public_key"]));if(!s)throw Ve.fromCode(new ko(`Could not find subnet key for subnet ID ${o.toText()}`));return s}},fo=Te("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),Kf=96;function $f(e){let t=fo.byteLength+Kf;if(e.byteLength!==t)throw te.fromCode(new en(t,e.byteLength));let r=e.slice(0,fo.byteLength);if(!Fr(r,fo))throw te.fromCode(new Lo(fo,r));return e.slice(fo.byteLength)}function Fe(e){if(e.status===Ke.Found&&e.value instanceof Uint8Array)return e.value}async function Oi(e){switch(e[0]){case Ie.Empty:return Ae(ho("ic-hashtree-empty"));case Ie.Pruned:return e[1];case Ie.Leaf:return Ae(M(ho("ic-hashtree-leaf"),e[1]));case Ie.Labeled:return Ae(M(ho("ic-hashtree-labeled"),e[1],await Oi(e[2])));case Ie.Fork:return Ae(M(ho("ic-hashtree-fork"),await Oi(e[1]),await Oi(e[2])));default:throw rr}}function ho(e){let t=new Uint8Array([e.length]),r=new TextEncoder().encode(e);return M(t,r)}function fu(e){return typeof e[0]=="string"?Q(e[0]):e[0]}var Ke;(function(e){e.Unknown="Unknown",e.Absent="Absent",e.Found="Found",e.Error="Error"})(Ke||(Ke={}));var Lr;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found"})(Lr||(Lr={}));var ie;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found",e.Less="Less",e.Greater="Greater"})(ie||(ie={}));function qr(e,t){if(e.length===0)switch(t[0]){case Ie.Empty:return{status:Ke.Absent};case Ie.Leaf:{if(!t[1])throw me.fromCode(new tr("Invalid tree structure for leaf"));if(t[1]instanceof Uint8Array)return{status:Ke.Found,value:t[1].slice(t[1].byteOffset,t[1].byteLength+t[1].byteOffset)};throw rr}case Ie.Pruned:return{status:Ke.Unknown};case Ie.Labeled:case Ie.Fork:return{status:Ke.Error};default:throw rr}let r=fu(e),n=mo(r,t);switch(n.status){case ie.Found:return qr(e.slice(1),n.value);case ie.Absent:case ie.Greater:case ie.Less:return{status:Ke.Absent};case ie.Unknown:return{status:Ke.Unknown};default:throw rr}}function Ri(e,t){if(e.length===0)return{status:Lr.Found,value:t};let r=fu(e),n=mo(r,t);switch(n.status){case ie.Found:return Ri(e.slice(1),n.value);case ie.Unknown:return{status:Lr.Unknown};case ie.Absent:case ie.Greater:case ie.Less:return{status:Lr.Absent};default:throw rr}}function Ei(e){switch(e[0]){case Ie.Empty:return[];case Ie.Fork:return Ei(e[1]).concat(Ei(e[2]));default:return[e]}}function mo(e,t){switch(t[0]){case Ie.Labeled:return jf(e,t[1])?{status:ie.Greater}:Fr(e,t[1])?{status:ie.Found,value:t[2]}:{status:ie.Less};case Ie.Fork:{let r=mo(e,t[1]);switch(r.status){case ie.Greater:{let n=mo(e,t[2]);return n.status===ie.Less?{status:ie.Absent}:n}case ie.Unknown:{let n=mo(e,t[2]);return n.status===ie.Less?{status:ie.Unknown}:n}default:return r}}case Ie.Pruned:return{status:ie.Unknown};default:return{status:ie.Absent}}}function Fa(e){let{canisterId:t,subnetId:r,tree:n}=e,o=qr(["subnet",r.toUint8Array(),"canister_ranges"],n);if(o.status!==Ke.Found)throw te.fromCode(new Vt(`Could not find canister ranges for subnet ${r.toText()}`,o.status));if(!(o.value instanceof Uint8Array))throw te.fromCode(new Qr(`Could not find canister ranges for subnet ${r.toText()}`));return Me(o.value).map(c=>[L.fromUint8Array(c[0]),L.fromUint8Array(c[1])]).some(c=>c[0].ltEq(t)&&c[1].gtEq(t))}var Va=async e=>{let{agent:t,paths:r,disableCertificateTimeVerification:n=!1}=e,o=L.from(e.canisterId),i=[...new Set(r)],s=new Map,a=i.map((c,u)=>{let p=Gf(c,o);return(async()=>{try{if(t.rootKey===null)throw we.fromCode(new mt);let d=t.rootKey,l=await t.readState(o,{paths:[p]}),f=await ur.create({certificate:l.certificate,rootKey:d,canisterId:o,disableTimeVerification:n,agent:t}),h=(_,x)=>{if(x==="subnet"){let y=Hf(l.certificate,o,d);return{path:x,data:y}}else return{path:x,data:Fe(_.lookup_path(p))}},{path:m,data:g}=h(f,i[u]);if(!g)console.warn(`Expected to find result for path ${m}, but instead found nothing.`),typeof m=="string"?s.set(m,null):s.set(m.key,null);else switch(m){case"time":{s.set(m,xn(g));break}case"controllers":{s.set(m,Jf(g));break}case"module_hash":{s.set(m,K(g));break}case"subnet":{s.set(m,g);break}case"candid":{s.set(m,new TextDecoder().decode(g));break}default:if(typeof m!="string"&&"key"in m&&"path"in m)switch(m.decodeStrategy){case"raw":s.set(m.key,g);break;case"leb128":{s.set(m.key,Sa(g));break}case"cbor":{s.set(m.key,Me(g));break}case"hex":{s.set(m.key,K(g));break}case"utf-8":s.set(m.key,new TextDecoder().decode(g))}}}catch(d){if(d instanceof ot&&(d.hasCode(Qt)||d.hasCode(Or)))throw d;typeof c!="string"&&"key"in c&&"path"in c?s.set(c.key,null):s.set(c,null),console.group(),console.warn(`Expected to find result for path ${c}, but instead found nothing.`),console.warn(d),console.groupEnd()}})()});return await Promise.all(a),s},Hf=(e,t,r)=>{if(!t._isPrincipal)throw z.fromCode(new Pe("Invalid canisterId"));let n=Me(e),o=n.tree,i=n.delegation,s;if(i&&i.subnet_id?s=L.fromUint8Array(new Uint8Array(i.subnet_id)):!i&&typeof r<"u"?(s=L.selfAuthenticating(new Uint8Array(r)),i={subnet_id:s.toUint8Array(),certificate:new Uint8Array(0)}):(s=L.selfAuthenticating(L.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),i={subnet_id:s.toUint8Array(),certificate:new Uint8Array(0)}),!Fa({canisterId:t,subnetId:s,tree:o}))throw Ve.fromCode(new Xr(t,s));let c=Ri(["subnet",i.subnet_id,"node"],o);if(c.status!==Lr.Found)throw te.fromCode(new Vt("Node not found",c.status));if(c.value instanceof Uint8Array)throw me.fromCode(new tr("Invalid node tree"));let u=Ei(c.value),p=new Map;return u.forEach(d=>{let l=L.from(d[1]).toText(),f=qr(["public_key"],d[2]);if(f.status!==Ke.Found)throw te.fromCode(new Vt("Public key not found",f.status));let h=f.value;if(h.byteLength!==44)throw te.fromCode(new en(44,h.byteLength));p.set(l,h)}),{subnetId:L.fromUint8Array(new Uint8Array(i.subnet_id)).toText(),nodeKeys:p}},Gf=(e,t)=>{let r=t.toUint8Array();switch(e){case"time":return[Q("time")];case"controllers":return[Q("canister"),r,Q("controllers")];case"module_hash":return[Q("canister"),r,Q("module_hash")];case"subnet":return[Q("subnet")];case"candid":return[Q("canister"),r,Q("metadata"),Q("candid:service")];default:if("key"in e&&"path"in e)if(typeof e.path=="string"||e.path instanceof Uint8Array){let n=e.path,o=typeof n=="string"?Q(n):n;return[Q("canister"),r,Q("metadata"),o]}else return e.path}throw me.fromCode(new Pe(`Error while encoding your path for canister status. Please ensure that your path ${e} was formatted correctly.`))},Jf=e=>Me(e).map(r=>L.fromUint8Array(r));var dr=BigInt(0),Oe=BigInt(1),Pa=BigInt(2),zf=BigInt(8);function Wf(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}function Yf(e,t={}){let r=gi("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;Mt(t,{},{uvRatio:"function"});let a=Pa<<BigInt(o.BYTES*8)-Oe,c=g=>n.create(g),u=t.uvRatio||((g,_)=>{try{return{isValid:!0,value:n.sqrt(n.div(g,_))}}catch{return{isValid:!1,value:dr}}});if(!Wf(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function p(g,_,x=!1){let y=x?Oe:dr;return mi("coordinate "+g,_,y,a),_}function d(g){if(!(g instanceof h))throw new Error("ExtendedPoint expected")}let l=ar((g,_)=>{let{X:x,Y:y,Z:w}=g,E=g.is0();_==null&&(_=E?zf:n.inv(w));let O=c(x*_),R=c(y*_),I=n.mul(w,_);if(E)return{x:dr,y:Oe};if(I!==Oe)throw new Error("invZ was invalid");return{x:O,y:R}}),f=ar(g=>{let{a:_,d:x}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:y,Y:w,Z:E,T:O}=g,R=c(y*y),I=c(w*w),T=c(E*E),v=c(T*T),F=c(R*_),S=c(T*c(F+I)),b=c(v+c(x*c(R*I)));if(S!==b)throw new Error("bad point: equation left != right (1)");let N=c(y*w),V=c(E*O);if(N!==V)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(_,x,y,w){this.X=p("x",_),this.Y=p("y",x),this.Z=p("z",y,!0),this.T=p("t",w),Object.freeze(this)}static CURVE(){return i}static fromAffine(_){if(_ instanceof h)throw new Error("extended point not allowed");let{x,y}=_||{};return p("x",x),p("y",y),new h(x,y,Oe,c(x*y))}static fromBytes(_,x=!1){let y=n.BYTES,{a:w,d:E}=i;_=aa(sr(_,y,"point")),Cr(x,"zip215");let O=aa(_),R=_[y-1];O[y-1]=R&-129;let I=Lt(O),T=x?a:n.ORDER;mi("point.y",I,dr,T);let v=c(I*I),F=c(v-Oe),S=c(E*v-w),{isValid:b,value:N}=u(F,S);if(!b)throw new Error("bad point: invalid y coordinate");let V=(N&Oe)===Oe,B=(R&128)!==0;if(!x&&N===dr&&B)throw new Error("bad point: x=0 and x_0=1");return B!==V&&(N=c(-N)),h.fromAffine({x:N,y:I})}static fromHex(_,x=!1){return h.fromBytes(se("point",_),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(_=8,x=!0){return m.createCache(this,_),x||this.multiply(Pa),this}assertValidity(){f(this)}equals(_){d(_);let{X:x,Y:y,Z:w}=this,{X:E,Y:O,Z:R}=_,I=c(x*R),T=c(E*w),v=c(y*R),F=c(O*w);return I===T&&v===F}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:_}=i,{X:x,Y:y,Z:w}=this,E=c(x*x),O=c(y*y),R=c(Pa*c(w*w)),I=c(_*E),T=x+y,v=c(c(T*T)-E-O),F=I+O,S=F-R,b=I-O,N=c(v*S),V=c(F*b),B=c(v*b),q=c(S*F);return new h(N,V,q,B)}add(_){d(_);let{a:x,d:y}=i,{X:w,Y:E,Z:O,T:R}=this,{X:I,Y:T,Z:v,T:F}=_,S=c(w*I),b=c(E*T),N=c(R*y*F),V=c(O*v),B=c((w+E)*(I+T)-S-b),q=V-N,A=V+N,P=c(b-x*S),C=c(B*q),U=c(A*P),k=c(B*P),ne=c(q*A);return new h(C,U,ne,k)}subtract(_){return this.add(_.negate())}multiply(_){if(!o.isValidNot0(_))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:y}=m.cached(this,_,w=>Xe(h,w));return Xe(h,[x,y])[0]}multiplyUnsafe(_,x=h.ZERO){if(!o.isValid(_))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return _===dr?h.ZERO:this.is0()||_===Oe?this:m.unsafe(this,_,y=>Xe(h,y),x)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(_){return l(this,_)}clearCofactor(){return s===Oe?this:this.multiplyUnsafe(s)}toBytes(){let{x:_,y:x}=this.toAffine(),y=n.toBytes(x);return y[y.length-1]|=_&Oe?128:0,y}toHex(){return K(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(_){return Xe(h,_)}static msm(_,x){return _n(h,o,_,x)}_setWindowSize(_){this.precompute(_)}toRawBytes(){return this.toBytes()}}h.BASE=new h(i.Gx,i.Gy,Oe,c(i.Gx*i.Gy)),h.ZERO=new h(dr,Oe,Oe,dr),h.Fp=n,h.Fn=o;let m=new mn(h,o.BITS);return h.BASE.precompute(8),h}var vi=class{constructor(t){this.ep=t}static fromBytes(t){fn()}static fromHex(t){fn()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return K(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function Zf(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Mt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,a=r.randomBytes||Zr,c=r.adjustScalarBytes||(T=>T),u=r.domain||((T,v,F)=>{if(Cr(F,"phflag"),v.length||F)throw new Error("Contexts/pre-hash are not supported");return T});function p(T){return s.create(Lt(T))}function d(T){let v=y.secretKey;T=se("private key",T,v);let F=se("hashed private key",t(T),2*v),S=c(F.slice(0,v)),b=F.slice(v,2*v),N=p(S);return{head:S,prefix:b,scalar:N}}function l(T){let{head:v,prefix:F,scalar:S}=d(T),b=o.multiply(S),N=b.toBytes();return{head:v,prefix:F,scalar:S,point:b,pointBytes:N}}function f(T){return l(T).pointBytes}function h(T=Uint8Array.of(),...v){let F=M(...v);return p(t(u(F,se("context",T),!!n)))}function m(T,v,F={}){T=se("message",T),n&&(T=n(T));let{prefix:S,scalar:b,pointBytes:N}=l(v),V=h(F.context,S,T),B=o.multiply(V).toBytes(),q=h(F.context,B,N,T),A=s.create(V+q*b);if(!s.isValid(A))throw new Error("sign failed: invalid s");let P=M(B,s.toBytes(A));return sr(P,y.signature,"result")}let g={zip215:!0};function _(T,v,F,S=g){let{context:b,zip215:N}=S,V=y.signature;T=se("signature",T,V),v=se("message",v),F=se("publicKey",F,y.publicKey),N!==void 0&&Cr(N,"zip215"),n&&(v=n(v));let B=V/2,q=T.subarray(0,B),A=Lt(T.subarray(B,V)),P,C,U;try{P=e.fromBytes(F,N),C=e.fromBytes(q,N),U=o.multiplyUnsafe(A)}catch{return!1}if(!N&&P.isSmallOrder())return!1;let k=h(b,C.toBytes(),P.toBytes(),v);return C.add(P.multiplyUnsafe(k)).subtract(U).clearCofactor().is0()}let x=i.BYTES,y={secretKey:x,publicKey:x,signature:2*x,seed:x};function w(T=a(y.seed)){return sr(T,y.seed,"seed")}function E(T){let v=I.randomSecretKey(T);return{secretKey:v,publicKey:f(v)}}function O(T){return ft(T)&&T.length===s.BYTES}function R(T,v){try{return!!e.fromBytes(T,v)}catch{return!1}}let I={getExtendedPublicKey:l,randomSecretKey:w,isValidSecretKey:O,isValidPublicKey:R,toMontgomery(T){let{y:v}=e.fromBytes(T),F=y.publicKey,S=F===32;if(!S&&F!==57)throw new Error("only defined for 25519 and 448");let b=S?i.div(Oe+v,Oe-v):i.div(v-Oe,v+Oe);return i.toBytes(b)},toMontgomerySecret(T){let v=y.secretKey;sr(T,v);let F=t(T.subarray(0,v));return c(F).subarray(0,v)},randomPrivateKey:w,precompute(T=8,v=e.BASE){return v.precompute(T,!1)}};return Object.freeze({keygen:E,getPublicKey:f,sign:m,verify:_,utils:I,Point:e,lengths:y})}function Xf(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=De(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},i={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:i}}function Qf(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function hu(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Xf(e),i=Yf(t,r),s=Zf(i,n,o);return Qf(e,s)}var eh=BigInt(0),Ht=BigInt(1),mu=BigInt(2),m0=BigInt(3),th=BigInt(5),rh=BigInt(8),bn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),_o={p:bn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:rh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function nh(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=bn,a=e*e%i*e%i,c=pt(a,mu,i)*a%i,u=pt(c,Ht,i)*e%i,p=pt(u,th,i)*u%i,d=pt(p,t,i)*p%i,l=pt(d,r,i)*d%i,f=pt(l,n,i)*l%i,h=pt(f,o,i)*f%i,m=pt(h,o,i)*f%i,g=pt(m,t,i)*p%i;return{pow_p_5_8:pt(g,mu,i)*e%i,b2:a}}function oh(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ca=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ua(e,t){let r=bn,n=oe(t*t*t,r),o=oe(n*n*t,r),i=nh(e*o).pow_p_5_8,s=oe(e*n*i,r),a=oe(t*s*s,r),c=s,u=oe(s*Ca,r),p=a===e,d=a===oe(-e,r),l=a===oe(-e*Ca,r);return p&&(s=c),(d||l)&&(s=u),jt(s,r)&&(s=oe(-s,r)),{isValid:p||d,value:s}}var pr=De(_o.p,{isLE:!0}),ih=De(_o.n,{isLE:!0}),sh={..._o,Fp:pr,hash:qc,adjustScalarBytes:oh,uvRatio:Ua},Le=hu(sh);var Ba=Ca,ah=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),ch=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),lh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),uh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),_u=e=>Ua(Ht,e),dh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Da=e=>Le.Point.Fp.create(Lt(e)&dh);function yu(e){let{d:t}=_o,r=bn,n=_=>pr.create(_),o=n(Ba*e*e),i=n((o+Ht)*lh),s=BigInt(-1),a=n((s-t*o)*n(o+t)),{isValid:c,value:u}=Ua(i,a),p=n(u*e);jt(p,r)||(p=n(-p)),c||(u=p),c||(s=o);let d=n(s*(o-Ht)*uh-a),l=u*u,f=n((u+u)*a),h=n(d*ah),m=n(Ht-l),g=n(Ht+l);return new Le.Point(n(f*g),n(m*h),n(h*g),n(f*m))}function ph(e){ue(e,64);let t=Da(e.subarray(0,32)),r=yu(t),n=Da(e.subarray(32,64)),o=yu(n);return new Gt(r.add(o))}var Gt=class e extends vi{constructor(t){super(t)}static fromAffine(t){return new e(Le.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return ph(se("ristrettoHash",t,64))}static fromBytes(t){ue(t,32);let{a:r,d:n}=_o,o=bn,i=w=>pr.create(w),s=Da(t);if(!Cl(pr.toBytes(s),t)||jt(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(Ht+r*a),u=i(Ht-r*a),p=i(c*c),d=i(u*u),l=i(r*n*p-d),{isValid:f,value:h}=_u(i(l*d)),m=i(h*u),g=i(h*m*l),_=i((s+s)*m);jt(_,o)&&(_=i(-_));let x=i(c*g),y=i(_*x);if(!f||jt(y,o)||x===eh)throw new Error("invalid ristretto255 encoding 2");return new e(new Le.Point(_,x,Ht,y))}static fromHex(t){return e.fromBytes(se("ristrettoHex",t,32))}static msm(t,r){return _n(e,Le.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,i=bn,s=g=>pr.create(g),a=s(s(n+r)*s(n-r)),c=s(t*r),u=s(c*c),{value:p}=_u(s(a*u)),d=s(p*a),l=s(p*c),f=s(d*l*o),h;if(jt(o*f,i)){let g=s(r*Ba),_=s(t*Ba);t=g,r=_,h=s(d*ch)}else h=l;jt(t*f,i)&&(r=s(-r));let m=s((n-r)*h);return jt(m,i)&&(m=s(-m)),pr.toBytes(m)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:i}=t.ep,s=u=>pr.create(u),a=s(r*i)===s(n*o),c=s(n*i)===s(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Gt.BASE=new Gt(Le.Point.BASE);Gt.ZERO=new Gt(Le.Point.ZERO);Gt.Fp=pr;Gt.Fn=ih;var gu,xu,Ii=class{static{gu=Symbol.iterator,xu=Symbol.toStringTag}#e;#t;constructor(t={}){this[gu]=this.entries.bind(this),this[xu]="ExpirableMap";let{source:r=[],expirationTime:n=600*1e3}=t,o=Date.now();this.#e=new Map([...r].map(([i,s])=>[i,{value:s,timestamp:o}])),this.#t=n}prune(){let t=Date.now();for(let[r,n]of this.#e.entries())t-n.timestamp>this.#t&&this.#e.delete(r);return this}set(t,r){this.prune();let n={value:r,timestamp:Date.now()};return this.#e.set(t,n),this}get(t){let r=this.#e.get(t);if(r!==void 0){if(Date.now()-r.timestamp>this.#t){this.#e.delete(t);return}return r.value}}clear(){this.#e.clear()}entries(){let t=this.#e.entries();return function*(){for(let[n,o]of t)yield[n,o.value]}()}values(){let t=this.#e.values();return function*(){for(let n of t)yield n.value}()}keys(){return this.#e.keys()}forEach(t,r){for(let[n,o]of this.#e.entries())t.call(r,o.value,n,this)}has(t){return this.#e.has(t)}delete(t){return this.#e.delete(t)}get size(){return this.#e.size}};var bu=e=>{if(e<=127)return 1;if(e<=255)return 2;if(e<=65535)return 3;if(e<=16777215)return 4;throw z.fromCode(new Un("Length too long (> 4 bytes)"))},Tu=(e,t,r)=>{if(r<=127)return e[t]=r,1;if(r<=255)return e[t]=129,e[t+1]=r,2;if(r<=65535)return e[t]=130,e[t+1]=r>>8,e[t+2]=r,3;if(r<=16777215)return e[t]=131,e[t+1]=r>>16,e[t+2]=r>>8,e[t+3]=r,4;throw z.fromCode(new Un("Length too long (> 4 bytes)"))},ka=(e,t)=>{if(e[t]<128)return 1;if(e[t]===128)throw z.fromCode(new it("Invalid length 0"));if(e[t]===129)return 2;if(e[t]===130)return 3;if(e[t]===131)return 4;throw z.fromCode(new it("Length too long (> 4 bytes)"))},fh=(e,t)=>{let r=ka(e,t);if(r===1)return e[t];if(r===2)return e[t+1];if(r===3)return(e[t+1]<<8)+e[t+2];if(r===4)return(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];throw z.fromCode(new it("Length too long (> 4 bytes)"))},yo=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),Mr=Uint8Array.from([48,5,6,3,43,101,112]),b0=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]),T0=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 jr(e,t){let r=2+bu(e.byteLength+1),n=t.byteLength+r+e.byteLength,o=0,i=new Uint8Array(1+bu(n)+n);return i[o++]=48,o+=Tu(i,o,n),i.set(t,o),o+=t.byteLength,i[o++]=3,o+=Tu(i,o,e.byteLength+1),i[o++]=0,i.set(new Uint8Array(e),o),i}var Kr=(e,t)=>{let r=0,n=(a,c)=>{if(o[r++]!==a)throw z.fromCode(new it(`Expected ${c} at offset ${r}`))},o=new Uint8Array(e);if(n(48,"sequence"),r+=ka(o,r),!Fr(o.slice(r,r+t.byteLength),t))throw z.fromCode(new it("Not the expected OID."));r+=t.byteLength,n(3,"bit string");let i=fh(o,r)-1;r+=ka(o,r),n(0,"0 padding");let s=o.slice(r);if(i!==s.length)throw z.fromCode(new qo(i,s.length));return s};var Ai=class e{static from(t){return this.fromDer(t.toDer())}static fromRaw(t){return new e(t)}static fromDer(t){return new e(this.derDecode(t))}static{this.RAW_KEY_LENGTH=32}static derEncode(t){return jr(t,Mr)}static derDecode(t){let r=Kr(t,Mr);if(r.length!==this.RAW_KEY_LENGTH)throw z.fromCode(new it("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(t){if(t.byteLength!==e.RAW_KEY_LENGTH)throw z.fromCode(new it("An Ed25519 public key must be exactly 32 bytes long"));this.#e=t,this.#t=e.derEncode(t)}toDer(){return this.derKey}toRaw(){return this.rawKey}};var La=class{constructor(){this.observers=[]}subscribe(t){this.observers.push(t)}unsubscribe(t){this.observers=this.observers.filter(r=>r!==t)}notify(t,...r){this.observers.forEach(n=>n(t,...r))}},Si=class extends La{constructor(){super()}print(t,...r){this.notify({message:t,level:"info"},...r)}warn(t,...r){this.notify({message:t,level:"warn"},...r)}error(t,r,...n){this.notify({message:t,level:"error",error:r},...n)}};var Fi=class e{#e;#t;#r;#c;#s;#u;#n;#o;#a=0;static{this.default={initialInterval:500,randomizationFactor:.5,multiplier:1.5,maxInterval:6e4,maxElapsedTime:9e5,maxIterations:10,date:Date}}constructor(t=e.default){let{initialInterval:r=500,randomizationFactor:n=.5,multiplier:o=1.5,maxInterval:i=6e4,maxElapsedTime:s=9e5,maxIterations:a=10,date:c=Date}=t;this.#e=r,this.#t=n,this.#r=o,this.#c=i,this.#o=c,this.#s=c.now(),this.#u=s,this.#n=a}get ellapsedTimeInMsec(){return this.#o.now()-this.#s}get currentInterval(){return this.#e}get count(){return this.#a}get randomValueFromInterval(){let t=this.#t*this.#e,r=this.#e-t,n=this.#e+t;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.#u||this.#a>=this.#n?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};var Tt;(function(e){e.Received="received",e.Processing="processing",e.Replied="replied",e.Rejected="rejected",e.Unknown="unknown",e.Done="done"})(Tt||(Tt={}));var ja=60*1e3,hh=1e6,mh=0,_h="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae";var yh="ic0.app",gh=".ic0.app",xh="icp0.io",bh=".icp0.io",Th="icp-api.io",wh=".icp-api.io",qa=200,Nh=202,Oh=404;function Eh(){let e;if(typeof window<"u")if(window.fetch)e=window.fetch.bind(window);else throw we.fromCode(new rn("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)e=global.fetch.bind(global);else throw we.fromCode(new rn("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&&(e=self.fetch.bind(self));if(e)return e;throw we.fromCode(new rn("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context."))}function Rh(e){let t;if(e!==void 0)!e.match(/^[a-z]+:/)&&typeof window<"u"?t=new URL(window.location.protocol+"//"+e):t=new URL(e);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,i=o?.hostname,s;i&&typeof i=="string"&&(n.some(a=>i.endsWith(a))?s=i:s=r.find(a=>i.endsWith(a))),o&&s?t=new URL(`${o.protocol}//${s}${o.port?":"+o.port:""}`):t=new URL("https://icp-api.io")}return t.toString()}var $r=class e{#e;#t;#r;#c;#s;#u;#n;#o;#a;#x;#i;#d;#p;#l;get#N(){return this.#l*ja}#f;#h;#m;#_;constructor(t={}){this.#e=null,this.#t=!1,this.#r=mh,this.#c=!1,this.#s=null,this.#u=!1,this._isAgent=!0,this.config={},this.log=new Si,this.#f=[],this.#h=[],this.#m=new Ii({expirationTime:5*ja}),this.#_=!0,this.#T=(o,i)=>{if(this.#_===!1)return o;let{status:s,signatures:a=[],requestId:c}=o;for(let u of a){let{timestamp:p,identity:d}=u,l=L.fromUint8Array(d).toText(),f;if(s===zt.Replied){let{reply:x}=o;f=Wn({status:s,reply:x,timestamp:BigInt(p),request_id:c})}else if(s===zt.Rejected){let{reject_code:x,reject_message:y,error_code:w}=o;f=Wn({status:s,reject_code:x,reject_message:y,error_code:w,timestamp:BigInt(p),request_id:c})}else throw me.fromCode(new Pe(`Unknown status: ${s}`));let h=M(Ys,f),m=i.nodeKeys.get(l);if(!m)throw te.fromCode(new Zo);let g=Ai.fromDer(m).rawKey;if(Le.verify(u.signature,h,g))return o;throw Ve.fromCode(new Xo(l))}return o},this.config=t,this.#o=t.fetch||Eh()||fetch.bind(global),this.#a=t.fetchOptions,this.#x=t.callOptions,this.#t=t.shouldFetchRootKey??!1,this.#u=t.shouldSyncTime??!1,t.rootKey?this.rootKey=t.rootKey:this.#t?this.rootKey=null:this.rootKey=Te(_h);let r=Rh(t.host);this.host=new URL(r),t.verifyQuerySignatures!==void 0&&(this.#_=t.verifyQuerySignatures),this.#d=t.retryTimes??3;let n=()=>new Fi({maxIterations:this.#d});if(this.#p=t.backoffStrategy||n,this.host.hostname.endsWith(gh)?this.host.hostname=yh:this.host.hostname.endsWith(bh)?this.host.hostname=xh:this.host.hostname.endsWith(wh)&&(this.host.hostname=Th),t.credentials){let{name:o,password:i}=t.credentials;this.#i=`${o}${i?":"+i:""}`}if(this.#n=Promise.resolve(t.identity||new Ye),t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes>5)throw z.fromCode(new Rr("The maximum ingress expiry time is 5 minutes.",t.ingressExpiryInMinutes));if(t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes<=0)throw z.fromCode(new Rr("Ingress expiry time must be greater than 0.",t.ingressExpiryInMinutes));this.#l=t.ingressExpiryInMinutes||5,this.addTransform("update",na(no)),t.useQueryNonces&&this.addTransform("query",na(no)),t.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(t={}){return new this({...t})}static async create(t={}){let r=e.createSync(t);return await r.#g(),r}static async from(t){try{return"config"in t?await e.create(t.config):await e.create({fetch:t._fetch,fetchOptions:t._fetchOptions,callOptions:t._callOptions,host:t._host.toString(),identity:t._identity??void 0})}catch{throw z.fromCode(new zo)}}isLocal(){let t=this.host.hostname;return t==="127.0.0.1"||t.endsWith("127.0.0.1")}addTransform(t,r,n=r.priority||0){if(t==="update"){let o=this.#h.findIndex(i=>(i.priority||0)<n);this.#h.splice(o>=0?o:this.#h.length,0,Object.assign(r,{priority:n}))}else if(t==="query"){let o=this.#f.findIndex(i=>(i.priority||0)<n);this.#f.splice(o>=0?o:this.#f.length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!this.#n)throw we.fromCode(new er);return(await this.#n).getPrincipal()}async call(t,r,n){let o=r.callSync??!0,i=await(n??this.#n);if(!i)throw we.fromCode(new er);let s=L.from(t),a=r.effectiveCanisterId?L.from(r.effectiveCanisterId):s;await this.#g(a);let c=i.getPrincipal(),u=Ma(this.#l,this.#r),p={request_type:di.Call,canister_id:s,method_name:r.methodName,arg:r.arg,sender:c,ingress_expiry:u},d=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#i?{Authorization:"Basic "+btoa(this.#i)}:{}}},endpoint:kt.Call,body:p}),l;r?.nonce?l=f(r.nonce):d.body.nonce?l=f(d.body.nonce):l=void 0,p.nonce=l;function f(_){return Object.assign(_,{__nonce__:void 0})}d=await i.transformRequest(d);let h=to(d.body),m=this.#p(),g=Dt(p);try{let y=o?()=>(this.log.print(`fetching "/api/v3/canister/${a.toText()}/call" with request:`,d),this.#o(""+new URL(`/api/v3/canister/${a.toText()}/call`,this.host),{...this.#x,...d.request,body:h})):()=>(this.log.print(`fetching "/api/v2/canister/${a.toText()}/call" with request:`,d),this.#o(""+new URL(`/api/v2/canister/${a.toText()}/call`,this.host),{...this.#x,...d.request,body:h})),{responseBodyBytes:w,...E}=await this.#y({requestFn:y,backoff:m,tries:0}),O=w.byteLength>0?Me(w):null;return{requestId:g,response:{...E,body:O},requestDetails:p}}catch(_){let x;if(_ instanceof ot){if(_.hasCode(Ln))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(t,{...r,callSync:!1},n);if(_.hasCode(Rr)&&!this.#c)return await this.syncTime(s),this.call(s,r,n);_.code.requestContext={requestId:g,senderPubKey:d.body.sender_pubkey,senderSignature:d.body.sender_sig,ingressExpiry:d.body.content.ingress_expiry},x=_}else x=me.fromCode(new Pe(_));throw this.log.error(`Error while making call: ${x.message}`,x),x}}async#b(t){let{ecid:r,transformedRequest:n,body:o,requestId:i,backoff:s,tries:a}=t,c=a===0?0:s.next();if(this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with tries:`,{tries:a,backoff:s,delay:c}),c===null)throw me.fromCode(new Er(`Backoff strategy exhausted after ${a} attempts.`,i));c>0&&await new Promise(f=>setTimeout(f,c));let u;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===qa)u={...Me(cn(await f.arrayBuffer())),httpDetails:{ok:f.ok,status:f.status,statusText:f.statusText,headers:fi(f.headers)},requestId:i};else throw te.fromCode(new kn(f.status,f.statusText,fi(f.headers),await f.text()))}catch(f){if(a<this.#d)return this.log.warn(`Caught exception while attempting to make query:
48
+ `)}return c.encodeValue(u)}));return W(n,o,i,s,a)}function Kp(e,t){let r=new _t(t);if(t.byteLength<Ci.length)throw new Error("Message length smaller than magic number");let n=Nr(r,Ci.length),o=new TextDecoder().decode(n);if(o!==Ci)throw new Error("Wrong magic number: "+JSON.stringify(o));function i(l){let f=[],h=Number(me(l));for(let _=0;_<h;_++){let x=Number(zt(l));switch(x){case Z.Opt:case Z.Vector:{let y=Number(zt(l));f.push([x,y]);break}case Z.Record:case Z.Variant:{let y=[],T=Number(me(l)),E;for(;T--;){let O=Number(me(l));if(O>=Math.pow(2,32))throw new Error("field id out of 32-bit range");if(typeof E=="number"&&E>=O)throw new Error("field id collision or not sorted");E=O;let R=Number(zt(l));y.push([O,R])}f.push([x,y]);break}case Z.Func:{let y=[],T=Number(me(l));for(;T--;)y.push(Number(zt(l)));let E=[],O=Number(me(l));for(;O--;)E.push(Number(zt(l)));let R=[],I=Number(me(l));for(;I--;)switch(Number(me(l))){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")}f.push([x,[y,E,R]]);break}case Z.Service:{let y=Number(me(l)),T=[];for(;y--;){let E=Number(me(l)),O=new TextDecoder().decode(Nr(l,E)),R=zt(l);T.push([O,R])}f.push([x,T]);break}default:throw new Error("Illegal op_code: "+x)}}let m=[],g=Number(me(l));for(let _=0;_<g;_++)m.push(Number(zt(l)));return[f,m]}let[s,a]=i(r);if(a.length<e.length)throw new Error("Wrong number of return values");let c=s.map(l=>Dl());function u(l){if(l<-24)throw new Error("future value not supported");if(l<0)switch(l){case-1:return _l;case-2:return ml;case-3:return xl;case-4:return gl;case-5:return Rl;case-6:return vl;case-7:return Il;case-8:return Al;case-9:return Tl;case-10:return Nl;case-11:return Ol;case-12:return El;case-13:return bl;case-14:return wl;case-15:return yl;case-16:return hl;case-17:return fl;case-24:return Sl;default:throw new Error("Illegal op_code: "+l)}if(l>=s.length)throw new Error("type index out of range");return c[l]}function p(l){switch(l[0]){case Z.Vector:{let f=u(l[1]);return Vl(f)}case Z.Opt:{let f=u(l[1]);return Cl(f)}case Z.Record:{let f={};for(let[g,_]of l[1]){let x=`_${g}_`;f[x]=u(_)}let h=Pl(f),m=h.tryAsTuple();return Array.isArray(m)?Fl(...m):h}case Z.Variant:{let f={};for(let[h,m]of l[1]){let g=`_${h}_`;f[g]=u(m)}return Bl(f)}case Z.Func:{let[f,h,m]=l[1];return Ul(f.map(g=>u(g)),h.map(g=>u(g)),m)}case Z.Service:{let f={},h=l[1];for(let[m,g]of h){let _=u(g);if(_ instanceof tt&&(_=_.getType()),!(_ instanceof yn))throw new Error("Illegal service definition: services can only contain functions");f[m]=_}return kl(f)}default:throw new Error("Illegal op_code: "+l[0])}}s.forEach((l,f)=>{if(l[0]===Z.Func){let h=p(l);c[f].fill(h)}}),s.forEach((l,f)=>{if(l[0]!==Z.Func){let h=p(l);c[f].fill(h)}}),Ys();let d=a.map(l=>u(l));try{let l=e.map((f,h)=>f.decodeValue(r,d[h]));for(let f=e.length;f<d.length;f++)d[f].decodeValue(r,d[f]);if(r.byteLength>0)throw new Error("decode: Left-over bytes");return l}finally{Ys()}}var fl=new Ro,hl=new St,Hp=new Bi,ml=new Di,_l=new mn,yl=new Ui,gl=new vo,xl=new Io,bl=new Ao(32),wl=new Ao(64),Tl=new Yt(8),Nl=new Yt(16),Ol=new Yt(32),El=new Yt(64),Rl=new It(8),vl=new It(16),Il=new It(32),Al=new It(64),Sl=new Li;function Fl(...e){return new ki(e)}function Vl(e){return new Mn(e)}function Cl(e){return new Or(e)}function Pl(e){return new _n(e)}function Bl(e){return new jn(e)}function Dl(){return new tt}function Ul(e,t,r=[]){return new yn(e,t,r)}function kl(e){return new Kn(e)}var qi=class e{constructor(t=new Map){this.rels=t}copy(){let t=new Map;for(let[r,n]of this.rels.entries()){let o=new Map(n);t.set(r,o)}return new e(t)}known(t,r){return this.rels.get(t.name)?.get(r.name)}addNegative(t,r){this.addNames(t.name,r.name,!1)}add(t,r){this.addNames(t.name,r.name,!0)}display(){let t="";for(let[r,n]of this.rels)for(let[o,i]of n)t+=`${r} ${i?":<":"!<:"} ${o}
49
+ `;return t}addNames(t,r,n){let o=this.rels.get(t);if(o==null){let i=new Map;i.set(r,n),this.rels.set(t,i)}else o.set(r,n)}},Pi=new qi;function Ys(){Pi=new qi}function $p(e,t){let r=new Set(e.annotations),n=new Set(t.annotations);if(r.size!==n.size)return!1;for(let o of r)if(!n.has(o))return!1;return!0}function Js(e){return e instanceof Or||e instanceof mn||e instanceof St}function Xs(e,t){let r=Pi.copy(),n=Wt(r,e,t);return n?Pi.add(e,t):Pi.addNegative(e,t),n}function Wt(e,t,r){if(t.name===r.name)return!0;let n=e.known(t,r);if(n!==void 0)return n;if(e.add(t,r),r instanceof St||t instanceof Ro||t instanceof Io&&r instanceof vo)return!0;if(t instanceof Mn&&r instanceof Mn)return Wt(e,t._type,r._type);if(r instanceof Or)return!0;if(t instanceof _n&&r instanceof _n){let o=t.fieldsAsObject;for(let[i,s]of r._fields){let a=o[De(i)];if(a){if(!Wt(e,a,s))return!1}else if(!Js(s))return!1}return!0}if(t instanceof yn&&r instanceof yn){if(!$p(t,r))return!1;for(let o=0;o<t.argTypes.length;o++){let i=t.argTypes[o];if(o<r.argTypes.length){if(!Wt(e,r.argTypes[o],i))return!1}else if(!Js(i))return!1}for(let o=0;o<r.retTypes.length;o++){let i=r.retTypes[o];if(o<t.retTypes.length){if(!Wt(e,t.retTypes[o],i))return!1}else if(!Js(i))return!1}return!0}if(t instanceof jn&&r instanceof jn){let o=r.alternativesAsObject;for(let[i,s]of t._fields){let a=o[De(i)];if(!a||!Wt(e,s,a))return!1}return!0}if(t instanceof Kn&&r instanceof Kn){let o=t.fieldsAsObject();for(let[i,s]of r._fields){let a=o[i];if(!a||!Wt(e,a,s))return!1}return!0}return t instanceof tt?Wt(e,t.getType(),r):r instanceof tt?Wt(e,t,r.getType()):!1}function Hn(e){if(!e)throw new Error("Input cannot be null or undefined");return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?new Uint8Array(e):"buffer"in e?Hn(e.buffer):new Uint8Array(e)}function xn(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function Qs(e){if(typeof e=="string")return Ll(e);if(typeof e=="number")return Se(oe(e));if(e instanceof Uint8Array||ArrayBuffer.isView(e))return Se(Hn(e));if(Array.isArray(e)){let t=e.map(Qs);return Se(j(...t))}else{if(e&&typeof e=="object"&&e._isPrincipal)return Se(e.toUint8Array());if(typeof e=="object"&&e!==null&&typeof e.toHash=="function")return Qs(e.toHash());if(typeof e=="object")return So(e);if(typeof e=="bigint")return Se(oe(e))}throw z.fromCode(new Ei(e))}var Ll=e=>{let t=new TextEncoder().encode(e);return Se(t)};function Zt(e){return So(e)}function So(e){let n=Object.entries(e).filter(([,s])=>s!==void 0).map(([s,a])=>{let c=Ll(s),u=Qs(a);return[c,u]}).sort(([s],[a])=>Ks(s,a)),o=j(...n.map(s=>j(...s)));return Se(o)}var Fo=new TextEncoder().encode(`
50
+ ic-request`),ea=new TextEncoder().encode("\vic-response"),ta=new TextEncoder().encode("ic-request-auth-delegation");var Ft=class{getPrincipal(){return this._principal||(this._principal=M.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(t){let{body:r,...n}=t,o=Zt(r);return{...n,body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(j(Fo,o))}}}},rt=class{getPrincipal(){return M.anonymous()}async transformRequest(t){return{...t,body:{content:t.body}}}};var Xt=class extends Error{constructor(t){super(t),this.name="DecodingError"}},Ml=55799,jl=Symbol("CBOR_STOP_CODE"),xt=(e=>(e[e.False=20]="False",e[e.True=21]="True",e[e.Null=22]="Null",e[e.Undefined=23]="Undefined",e[e.Break=31]="Break",e))(xt||{}),be=(e=>(e[e.UnsignedInteger=0]="UnsignedInteger",e[e.NegativeInteger=1]="NegativeInteger",e[e.ByteString=2]="ByteString",e[e.TextString=3]="TextString",e[e.Array=4]="Array",e[e.Map=5]="Map",e[e.Tag=6]="Tag",e[e.Simple=7]="Simple",e))(be||{}),Gp=23,Jp=255,zp=65535,Wp=4294967295,Yp=BigInt("0xffffffffffffffff"),gt=(e=>(e[e.Value=23]="Value",e[e.OneByte=24]="OneByte",e[e.TwoBytes=25]="TwoBytes",e[e.FourBytes=26]="FourBytes",e[e.EightBytes=27]="EightBytes",e[e.Indefinite=31]="Indefinite",e))(gt||{}),$n=!1;function Zp(e){return e==null}function Kl(e,t){let r=new Uint8Array(t);return r.set(e),r}var Xp=new TextDecoder;function Qp(e){return(e&224)>>5}function ef(e){return e&31}var Po=new Uint8Array,Vo,bt=0;function Hl(e,t){Po=e,bt=0;let r=bn(t);return t?.(r)??r}function bn(e){let[t,r]=Mi();switch(t){case be.UnsignedInteger:return Gn(r);case be.NegativeInteger:return of(r);case be.ByteString:return $l(r);case be.TextString:return na(r);case be.Array:return tf(r,e);case be.Map:return nf(r,e);case be.Tag:return sf(r,e);case be.Simple:return rf(r)}throw new Xt(`Unsupported major type: ${t}`)}function Mi(){let e=Po.at(bt);if(Zp(e))throw new Xt("Provided CBOR data is empty");let t=Qp(e),r=ef(e);return bt++,[t,r]}function tf(e,t){let r=Gn(e);if(r===1/0){let o=[],i=bn(t);for(;i!==jl;)o.push(t?.(i)??i),i=bn(t);return o}let n=new Array(r);for(let o=0;o<r;o++){let i=bn(t);n[o]=t?.(i)??i}return n}function rf(e){switch(e){case xt.False:return!1;case xt.True:return!0;case xt.Null:return null;case xt.Undefined:return;case xt.Break:return jl}throw new Xt(`Unrecognized simple type: ${e.toString(2)}`)}function nf(e,t){let r=Gn(e),n={};if(r===1/0){let[o,i]=Mi();for(;o!==be.Simple&&i!==xt.Break;){let s=na(i),a=bn(t);n[s]=t?.(a,s)??a,[o,i]=Mi()}return n}for(let o=0;o<r;o++){let[i,s]=Mi();if(i!==be.TextString)throw new Xt("Map keys must be text strings");let a=na(s),c=bn(t);n[a]=t?.(c,a)??c}return n}function Gn(e){if(e<=gt.Value)return e;switch(Vo=new DataView(Po.buffer,Po.byteOffset+bt),e){case gt.OneByte:return bt++,Vo.getUint8(0);case gt.TwoBytes:return bt+=2,Vo.getUint16(0,$n);case gt.FourBytes:return bt+=4,Vo.getUint32(0,$n);case gt.EightBytes:return bt+=8,Vo.getBigUint64(0,$n);case gt.Indefinite:return 1/0;default:throw new Xt(`Unsupported integer info: ${e.toString(2)}`)}}function of(e){let t=Gn(e);return typeof t=="number"?-1-t:-1n-t}function $l(e){let t=Gn(e);if(t>Number.MAX_SAFE_INTEGER)throw new Xt("Byte length is too large");let r=Number(t);return bt+=r,Po.slice(bt-r,bt)}function na(e){let t=$l(e);return Xp.decode(t)}function sf(e,t){let r=Gn(e);if(r===Ml)return bn(t);throw new Xt(`Unsupported tag: ${r}.`)}var Bo=class extends Error{constructor(t){super(t),this.name="SerializationError"}},af=2*1024,cf=100,lf=new TextEncoder;function Co(e){return e<<5}var et=new Uint8Array(af),yt=new DataView(et.buffer),xe=0,ra=[];function Gl(e,t){xe=0;let r=t?.(e)??e;return yf(Ml,r,t),et.slice(0,xe)}function oa(e,t){if(xe>et.length-cf&&(et=Kl(et,et.length*2),yt=new DataView(et.buffer)),e===!1||e===!0||e===null||e===void 0){pf(e);return}if(typeof e=="number"||typeof e=="bigint"){_f(e);return}if(typeof e=="string"){Wl(e);return}if(e instanceof Uint8Array){ql(e);return}if(e instanceof ArrayBuffer){ql(new Uint8Array(e));return}if(Array.isArray(e)){uf(e,t);return}if(typeof e=="object"){df(e,t);return}throw new Bo(`Unsupported type: ${typeof e}`)}function uf(e,t){Jn(be.Array,e.length),e.forEach((r,n)=>{oa(t?.(r,n.toString())??r,t)})}function df(e,t){ra=Object.entries(e),Jn(be.Map,ra.length),ra.forEach(([r,n])=>{Wl(r),oa(t?.(n,r)??n,t)})}function Jn(e,t){if(t<=Gp){yt.setUint8(xe++,Co(e)|Number(t));return}if(t<=Jp){yt.setUint8(xe++,Co(e)|gt.OneByte),yt.setUint8(xe,Number(t)),xe+=1;return}if(t<=zp){yt.setUint8(xe++,Co(e)|gt.TwoBytes),yt.setUint16(xe,Number(t),$n),xe+=2;return}if(t<=Wp){yt.setUint8(xe++,Co(e)|gt.FourBytes),yt.setUint32(xe,Number(t),$n),xe+=4;return}if(t<=Yp){yt.setUint8(xe++,Co(e)|gt.EightBytes),yt.setBigUint64(xe,BigInt(t),$n),xe+=8;return}throw new Bo(`Value too large to encode: ${t}`)}function pf(e){Jn(be.Simple,ff(e))}function ff(e){if(e===!1)return xt.False;if(e===!0)return xt.True;if(e===null)return xt.Null;if(e===void 0)return xt.Undefined;throw new Bo(`Unrecognized simple value: ${e.toString()}`)}function Jl(e,t){Jn(e,t.length),xe>et.length-t.length&&(et=Kl(et,et.length+t.length),yt=new DataView(et.buffer)),et.set(t,xe),xe+=t.length}function zl(e,t){Jn(e,t)}function hf(e){zl(be.UnsignedInteger,e)}function mf(e){zl(be.NegativeInteger,typeof e=="bigint"?-1n-e:-1-e)}function _f(e){e>=0?hf(e):mf(e)}function Wl(e){Jl(be.TextString,lf.encode(e))}function ql(e){Jl(be.ByteString,e)}function yf(e,t,r){Jn(be.Tag,e),oa(t,r)}function xf(e){return typeof e=="object"&&e!==null&&"toCborValue"in e}function Do(e){try{return Gl(e,t=>M.isPrincipal(t)?t.toUint8Array():zn.isExpiry(t)?t.toBigInt():xf(t)?t.toCborValue():t)}catch(t){throw z.fromCode(new bi(t,e))}}function Je(e){try{return Hl(e)}catch(t){throw z.fromCode(new xi(t,e))}}var ji={encode:Do,decode:Je};var Uo=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){let e=new Uint32Array(1);return window.crypto.getRandomValues(e),e[0]}if(typeof crypto<"u"&&crypto.getRandomValues){let e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var Qt;(function(e){e.Query="read",e.ReadState="read_state",e.Call="call"})(Qt||(Qt={}));var Ki;(function(e){e.Call="call"})(Ki||(Ki={}));var wn;(function(e){e.Query="query",e.ReadState="read_state"})(wn||(wn={}));function ko(){let e=new ArrayBuffer(16),t=new DataView(e),r=Uo(),n=Uo(),o=Uo(),i=Uo();return t.setUint32(0,r),t.setUint32(4,n),t.setUint32(8,o),t.setUint32(12,i),Object.assign(new Uint8Array(e),{__nonce__:void 0})}var Hi="__expiry__",sa=BigInt(1e3),bf=BigInt(1e6),Yl=BigInt(60),wf=BigInt(90)*sa;function Zl(e){return e/sa}function Tf(e){return Zl(e)/Yl}var zn=class e{constructor(t){this.__expiry__=t,this._isExpiry=!0}static fromDeltaInMilliseconds(t,r=0){let n=BigInt(t),o=BigInt(Date.now())+n+BigInt(r),i;return n<wf?i=Zl(o):i=Tf(o)*Yl,new e(i*sa*bf)}toBigInt(){return this.__expiry__}toHash(){return oe(this.__expiry__)}toString(){return this.__expiry__.toString()}toJSON(){return{[Hi]:this.toString()}}static fromJSON(t){let r=JSON.parse(t);if(r[Hi])try{let n=BigInt(r[Hi]);return new e(n)}catch(n){throw new z(new No(`Not a valid BigInt: ${n}`))}throw new z(new No(`The input does not contain the key ${Hi}`))}static isExpiry(t){return t instanceof e||typeof t=="object"&&t!==null&&"_isExpiry"in t&&t._isExpiry===!0&&"__expiry__"in t&&typeof t.__expiry__=="bigint"}};function aa(e=ko){return async t=>{let r=t.request.headers;t.request.headers=r,t.endpoint===Qt.Call&&(t.body.nonce=e())}}function $i(e){let t=[];return e.forEach((r,n)=>{t.push([n,r])}),t}var la=BigInt(0),Gi=BigInt(1);function Tn(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Er(e,t,r=""){let n=Ot(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,a=i?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return e}function Xl(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?la:BigInt("0x"+e)}function ze(e){return Xl(H(e))}function er(e){return fe(e),Xl(H(Uint8Array.from(e).reverse()))}function we(e,t){return Ne(e.toString(16).padStart(t*2,"0"))}function ua(e,t){return we(e,t).reverse()}function le(e,t,r){let n;if(typeof t=="string")try{n=Ne(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(Ot(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Ql(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function da(e){return Uint8Array.from(e)}var ca=e=>typeof e=="bigint"&&la<=e;function pa(e,t,r){return ca(e)&&ca(t)&&ca(r)&&t<=e&&e<r}function Ji(e,t,r,n){if(!pa(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function tr(e){let t;for(t=0;e>la;e>>=Gi,t+=1);return t}function eu(e,t){return e>>BigInt(t)&Gi}var wt=e=>(Gi<<BigInt(e))-Gi;function tu(e){return typeof e=="function"&&Number.isSafeInteger(e.outputLen)}function rr(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,i,s){let a=e[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(t).forEach(([o,i])=>n(o,i,!1)),Object.entries(r).forEach(([o,i])=>n(o,i,!0))}var Wn=()=>{throw new Error("not implemented")};function Rr(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var Ue=BigInt(0),Ee=BigInt(1),Nn=BigInt(2),nu=BigInt(3),ou=BigInt(4),iu=BigInt(5),Nf=BigInt(7),su=BigInt(8),Of=BigInt(9),au=BigInt(16);function se(e,t){let r=e%t;return r>=Ue?r:t+r}function Tt(e,t,r){let n=e;for(;t-- >Ue;)n*=n,n%=r;return n}function ru(e,t){if(e===Ue)throw new Error("invert: expected non-zero number");if(t<=Ue)throw new Error("invert: expected positive modulus, got "+t);let r=se(e,t),n=t,o=Ue,i=Ee,s=Ee,a=Ue;for(;r!==Ue;){let u=n/r,p=n%r,d=o-s*u,l=i-a*u;n=r,r=p,o=s,i=a,s=d,a=l}if(n!==Ee)throw new Error("invert: does not exist");return se(o,t)}function fa(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function cu(e,t){let r=(e.ORDER+Ee)/ou,n=e.pow(t,r);return fa(e,n,t),n}function Ef(e,t){let r=(e.ORDER-iu)/su,n=e.mul(t,Nn),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Nn),o),a=e.mul(i,e.sub(s,e.ONE));return fa(e,a,t),a}function Rf(e){let t=ke(e),r=lu(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Nf)/au;return(a,c)=>{let u=a.pow(c,s),p=a.mul(u,n),d=a.mul(u,o),l=a.mul(u,i),f=a.eql(a.sqr(p),c),h=a.eql(a.sqr(d),c);u=a.cmov(u,p,f),p=a.cmov(l,d,h);let m=a.eql(a.sqr(p),c),g=a.cmov(u,p,m);return fa(a,g,c),g}}function lu(e){if(e<nu)throw new Error("sqrt is not defined for small field");let t=e-Ee,r=0;for(;t%Nn===Ue;)t/=Nn,r++;let n=Nn,o=ke(e);for(;Lo(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return cu;let i=o.pow(n,t),s=(t+Ee)/Nn;return function(c,u){if(c.is0(u))return u;if(Lo(c,u)!==1)throw new Error("Cannot find square root");let p=r,d=c.mul(c.ONE,i),l=c.pow(u,t),f=c.pow(u,s);for(;!c.eql(l,c.ONE);){if(c.is0(l))return c.ZERO;let h=1,m=c.sqr(l);for(;!c.eql(m,c.ONE);)if(h++,m=c.sqr(m),h===p)throw new Error("Cannot find square root");let g=Ee<<BigInt(p-h-1),_=c.pow(d,g);p=h,d=c.sqr(_),l=c.mul(l,d),f=c.mul(f,_)}return f}}function vf(e){return e%ou===nu?cu:e%su===iu?Ef:e%au===Of?Rf(e):lu(e)}var nr=(e,t)=>(se(e,t)&Ee)===Ee,If=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function zi(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=If.reduce((n,o)=>(n[o]="function",n),t);return rr(e,r),e}function qo(e,t,r){if(r<Ue)throw new Error("invalid exponent, negatives unsupported");if(r===Ue)return e.ONE;if(r===Ee)return t;let n=e.ONE,o=t;for(;r>Ue;)r&Ee&&(n=e.mul(n,o)),o=e.sqr(o),r>>=Ee;return n}function nt(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,c)=>e.is0(a)?s:(n[c]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,c)=>e.is0(a)?s:(n[c]=e.mul(s,n[c]),e.mul(s,a)),i),n}function Lo(e,t){let r=(e.ORDER-Ee)/Nn,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function ha(e,t){t!==void 0&&Ds(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ke(e,t,r=!1,n={}){if(e<=Ue)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i,s=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(o=l.BITS),l.sqrt&&(i=l.sqrt),typeof l.isLE=="boolean"&&(r=l.isLE),typeof l.modFromBytes=="boolean"&&(s=l.modFromBytes),a=l.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:u}=ha(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,d=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:u,MASK:wt(c),ZERO:Ue,ONE:Ee,allowedLengths:a,create:l=>se(l,e),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return Ue<=l&&l<e},is0:l=>l===Ue,isValidNot0:l=>!d.is0(l)&&d.isValid(l),isOdd:l=>(l&Ee)===Ee,neg:l=>se(-l,e),eql:(l,f)=>l===f,sqr:l=>se(l*l,e),add:(l,f)=>se(l+f,e),sub:(l,f)=>se(l-f,e),mul:(l,f)=>se(l*f,e),pow:(l,f)=>qo(d,l,f),div:(l,f)=>se(l*ru(f,e),e),sqrN:l=>l*l,addN:(l,f)=>l+f,subN:(l,f)=>l-f,mulN:(l,f)=>l*f,inv:l=>ru(l,e),sqrt:i||(l=>(p||(p=vf(e)),p(d,l))),toBytes:l=>r?ua(l,u):we(l,u),fromBytes:(l,f=!0)=>{if(a){if(!a.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);let m=new Uint8Array(u);m.set(l,r?0:m.length-l.length),l=m}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let h=r?er(l):ze(l);if(s&&(h=se(h,e)),!f&&!d.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:l=>nt(d,l),cmov:(l,f,h)=>h?f:l});return Object.freeze(d)}function uu(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Wi(e){let t=uu(e);return t+Math.ceil(t/2)}function ma(e,t,r=!1){let n=e.length,o=uu(t),i=Wi(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?er(e):ze(e),a=se(s,t-Ee)+Ee;return r?ua(a,o):we(a,o)}var Yn=BigInt(0),On=BigInt(1);function Mo(e,t){let r=t.negate();return e?r:t}function ot(e,t){let r=nt(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function hu(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function _a(e,t){hu(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=wt(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function du(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),c=e>>s;a>n&&(a-=i,c+=On);let u=t*n,p=u+Math.abs(a)-1,d=a===0,l=a<0,f=t%2!==0;return{nextN:c,offset:p,isZero:d,isNeg:l,isNegF:f,offsetF:u}}function Sf(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Ff(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var ya=new WeakMap,mu=new WeakMap;function ga(e){return mu.get(e)||1}function pu(e){if(e!==Yn)throw new Error("invalid wNAF")}var Zn=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Yn;)r&On&&(n=n.add(o)),o=o.double(),r>>=On;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=_a(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let u=1;u<o;u++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=_a(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:u,isZero:p,isNeg:d,isNegF:l,offsetF:f}=du(n,a,s);n=c,p?i=i.add(Mo(l,r[f])):o=o.add(Mo(d,r[u]))}return pu(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=_a(t,this.bits);for(let s=0;s<i.windows&&n!==Yn;s++){let{nextN:a,offset:c,isZero:u,isNeg:p}=du(n,s,i);if(n=a,!u){let d=r[c];o=o.add(p?d.negate():d)}}return pu(n),o}getPrecomputes(t,r,n){let o=ya.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ya.set(r,o))),o}cached(t,r,n){let o=ga(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=ga(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){hu(r,this.bits),mu.set(t,r),ya.delete(t)}hasCache(t){return ga(t)!==1}};function _u(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>Yn||n>Yn;)r&On&&(i=i.add(o)),n&On&&(s=s.add(o)),o=o.double(),r>>=On,n>>=On;return{p1:i,p2:s}}function Xn(e,t,r,n){Sf(r,e),Ff(n,t);let o=r.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=e.ZERO,a=tr(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=wt(c),p=new Array(Number(u)+1).fill(s),d=Math.floor((t.BITS-1)/c)*c,l=s;for(let f=d;f>=0;f-=c){p.fill(s);for(let m=0;m<i;m++){let g=n[m],_=Number(g>>BigInt(f)&u);p[_]=p[_].add(r[m])}let h=s;for(let m=p.length-1,g=s;m>0;m--)g=g.add(p[m]),h=h.add(g);if(l=l.add(h),f!==0)for(let m=0;m<c;m++)l=l.double()}return l}function fu(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return zi(t),t}else return ke(e,{isLE:r})}function Yi(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Yn))throw new Error(`CURVE.${c} must be positive bigint`)}let o=fu(t.p,r.Fp,n),i=fu(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}var Vf=ze;function vr(e,t){if(jo(e),jo(t),e<0||e>=1<<8*t)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function Cf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function jo(e){if(!Number.isSafeInteger(e))throw new Error("number expected")}function yu(e){if(!Ot(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or string");return typeof e=="string"?ee(e):e}function Pf(e,t,r,n){fe(e),jo(r),t=yu(t),t.length>255&&(t=n(j(ee("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:i}=n,s=Math.ceil(r/o);if(r>65535||s>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=j(t,vr(t.length,1)),c=vr(0,i),u=vr(r,2),p=new Array(s),d=n(j(c,e,u,vr(0,1),a));p[0]=n(j(d,vr(1,1),a));for(let f=1;f<=s;f++){let h=[Cf(d,p[f-1]),vr(f+1,1),a];p[f]=n(j(...h))}return j(...p).slice(0,r)}function Bf(e,t,r,n,o){if(fe(e),jo(r),t=yu(t),t.length>255){let i=Math.ceil(2*n/8);t=o.create({dkLen:i}).update(ee("H2C-OVERSIZE-DST-")).update(t).digest()}if(r>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return o.create({dkLen:r}).update(e).update(vr(r,2)).update(t).update(vr(t.length,1)).digest()}function xa(e,t,r){rr(r,{p:"bigint",m:"number",k:"number",hash:"function"});let{p:n,k:o,m:i,hash:s,expand:a,DST:c}=r;if(!tu(r.hash))throw new Error("expected valid hash");fe(e),jo(t);let u=n.toString(2).length,p=Math.ceil((u+o)/8),d=t*i*p,l;if(a==="xmd")l=Pf(e,c,d,s);else if(a==="xof")l=Bf(e,c,d,o,s);else if(a==="_internal_pass")l=e;else throw new Error('expand must be "xmd" or "xof"');let f=new Array(t);for(let h=0;h<t;h++){let m=new Array(i);for(let g=0;g<i;g++){let _=p*(g+h*i),x=l.subarray(_,_+p);m[g]=se(Vf(x),n)}f[h]=m}return f}function ba(e,t){let r=t.map(n=>Array.from(n).reverse());return(n,o)=>{let[i,s,a,c]=r.map(d=>d.reduce((l,f)=>e.add(e.mul(l,n),f))),[u,p]=nt(e,[s,c],!0);return n=e.mul(i,u),o=e.mul(o,e.mul(a,p)),{x:n,y:o}}}var Df=ee("HashToScalar-");function wa(e,t,r){if(typeof t!="function")throw new Error("mapToCurve() must be defined");function n(i){return e.fromAffine(t(i))}function o(i){let s=i.clearCofactor();return s.equals(e.ZERO)?e.ZERO:(s.assertValidity(),s)}return{defaults:r,hashToCurve(i,s){let a=Object.assign({},r,s),c=xa(i,2,a),u=n(c[0]),p=n(c[1]);return o(u.add(p))},encodeToCurve(i,s){let a=r.encodeDST?{DST:r.encodeDST}:{},c=Object.assign({},r,a,s),u=xa(i,1,c),p=n(u[0]);return o(p)},mapToCurve(i){if(!Array.isArray(i))throw new Error("expected array of bigints");for(let s of i)if(typeof s!="bigint")throw new Error("expected array of bigints");return o(n(i))},hashToScalar(i,s){let a=e.Fn.ORDER,c=Object.assign({},r,{p:a,m:1,DST:Df},s);return xa(i,1,c)[0][0]}}}var gu=(e,t)=>(e+(e>=0?t:-t)/or)/t;function Uf(e,t,r){let[[n,o],[i,s]]=t,a=gu(s*e,r),c=gu(-o*e,r),u=e-a*n-c*i,p=-a*o-c*s,d=u<En,l=p<En;d&&(u=-u),l&&(p=-p);let f=wt(Math.ceil(tr(r)/2))+Le;if(u<En||u>=f||p<En||p>=f)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:u,k2neg:l,k2:p}}var En=BigInt(0),Le=BigInt(1),or=BigInt(2),Qn=BigInt(3),Ta=BigInt(4);function Ko(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=le("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function kf(e,t={}){let r=Yi("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:a}=i;rr(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Mf(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(S,b,N){let{x:F,y:B}=b.toAffine(),k=n.toBytes(F);if(Tn(N,"isCompressed"),N){p();let A=!n.isOdd(B);return j(Lf(A),k)}else return j(Uint8Array.of(4),k,n.toBytes(B))}function l(S){Er(S,void 0,"Point");let{publicKey:b,publicKeyUncompressed:N}=u,F=S.length,B=S[0],k=S.subarray(1);if(F===b&&(B===2||B===3)){let A=n.fromBytes(k);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let C=m(A),P;try{P=n.sqrt(C)}catch(te){let Q=te instanceof Error?": "+te.message:"";throw new Error("bad point: is not on curve, sqrt error"+Q)}p();let D=n.isOdd(P);return(B&1)===1!==D&&(P=n.neg(P)),{x:A,y:P}}else if(F===N&&B===4){let A=n.BYTES,C=n.fromBytes(k.subarray(0,A)),P=n.fromBytes(k.subarray(A,A*2));if(!g(C,P))throw new Error("bad point: is not on curve");return{x:C,y:P}}else throw new Error(`bad point: got length ${F}, expected compressed=${b} or uncompressed=${N}`)}let f=t.toBytes||d,h=t.fromBytes||l;function m(S){let b=n.sqr(S),N=n.mul(b,S);return n.add(n.add(N,n.mul(S,i.a)),i.b)}function g(S,b){let N=n.sqr(b),F=m(S);return n.eql(N,F)}if(!g(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let _=n.mul(n.pow(i.a,Qn),Ta),x=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(_,x)))throw new Error("bad curve params: a or b");function y(S,b,N=!1){if(!n.isValid(b)||N&&n.is0(b))throw new Error(`bad point coordinate ${S}`);return b}function T(S){if(!(S instanceof w))throw new Error("ProjectivePoint expected")}function E(S){if(!c||!c.basises)throw new Error("no endo");return Uf(S,c.basises,o.ORDER)}let O=Rr((S,b)=>{let{X:N,Y:F,Z:B}=S;if(n.eql(B,n.ONE))return{x:N,y:F};let k=S.is0();b==null&&(b=k?n.ONE:n.inv(B));let A=n.mul(N,b),C=n.mul(F,b),P=n.mul(B,b);if(k)return{x:n.ZERO,y:n.ZERO};if(!n.eql(P,n.ONE))throw new Error("invZ was invalid");return{x:A,y:C}}),R=Rr(S=>{if(S.is0()){if(t.allowInfinityPoint&&!n.is0(S.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:N}=S.toAffine();if(!n.isValid(b)||!n.isValid(N))throw new Error("bad point: x or y not field elements");if(!g(b,N))throw new Error("bad point: equation left != right");if(!S.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function I(S,b,N,F,B){return N=new w(n.mul(N.X,S),N.Y,N.Z),b=Mo(F,b),N=Mo(B,N),b.add(N)}class w{constructor(b,N,F){this.X=y("x",b),this.Y=y("y",N,!0),this.Z=y("z",F),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){let{x:N,y:F}=b||{};if(!b||!n.isValid(N)||!n.isValid(F))throw new Error("invalid affine point");if(b instanceof w)throw new Error("projective point not allowed");return n.is0(N)&&n.is0(F)?w.ZERO:new w(N,F,n.ONE)}static fromBytes(b){let N=w.fromAffine(h(Er(b,void 0,"point")));return N.assertValidity(),N}static fromHex(b){return w.fromBytes(le("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,N=!0){return V.createCache(this,b),N||this.multiply(Qn),this}assertValidity(){R(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){T(b);let{X:N,Y:F,Z:B}=this,{X:k,Y:A,Z:C}=b,P=n.eql(n.mul(N,C),n.mul(k,B)),D=n.eql(n.mul(F,C),n.mul(A,B));return P&&D}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:N}=i,F=n.mul(N,Qn),{X:B,Y:k,Z:A}=this,C=n.ZERO,P=n.ZERO,D=n.ZERO,U=n.mul(B,B),te=n.mul(k,k),Q=n.mul(A,A),$=n.mul(B,k);return $=n.add($,$),D=n.mul(B,A),D=n.add(D,D),C=n.mul(b,D),P=n.mul(F,Q),P=n.add(C,P),C=n.sub(te,P),P=n.add(te,P),P=n.mul(C,P),C=n.mul($,C),D=n.mul(F,D),Q=n.mul(b,Q),$=n.sub(U,Q),$=n.mul(b,$),$=n.add($,D),D=n.add(U,U),U=n.add(D,U),U=n.add(U,Q),U=n.mul(U,$),P=n.add(P,U),Q=n.mul(k,A),Q=n.add(Q,Q),U=n.mul(Q,$),C=n.sub(C,U),D=n.mul(Q,te),D=n.add(D,D),D=n.add(D,D),new w(C,P,D)}add(b){T(b);let{X:N,Y:F,Z:B}=this,{X:k,Y:A,Z:C}=b,P=n.ZERO,D=n.ZERO,U=n.ZERO,te=i.a,Q=n.mul(i.b,Qn),$=n.mul(N,k),ie=n.mul(F,A),pe=n.mul(B,C),Ae=n.add(N,F),re=n.add(k,A);Ae=n.mul(Ae,re),re=n.add($,ie),Ae=n.sub(Ae,re),re=n.add(N,B);let ce=n.add(k,C);return re=n.mul(re,ce),ce=n.add($,pe),re=n.sub(re,ce),ce=n.add(F,B),P=n.add(A,C),ce=n.mul(ce,P),P=n.add(ie,pe),ce=n.sub(ce,P),U=n.mul(te,re),P=n.mul(Q,pe),U=n.add(P,U),P=n.sub(ie,U),U=n.add(ie,U),D=n.mul(P,U),ie=n.add($,$),ie=n.add(ie,$),pe=n.mul(te,pe),re=n.mul(Q,re),ie=n.add(ie,pe),pe=n.sub($,pe),pe=n.mul(te,pe),re=n.add(re,pe),$=n.mul(ie,re),D=n.add(D,$),$=n.mul(ce,re),P=n.mul(Ae,P),P=n.sub(P,$),$=n.mul(Ae,ie),U=n.mul(ce,U),U=n.add(U,$),new w(P,D,U)}subtract(b){return this.add(b.negate())}is0(){return this.equals(w.ZERO)}multiply(b){let{endo:N}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let F,B,k=A=>V.cached(this,A,C=>ot(w,C));if(N){let{k1neg:A,k1:C,k2neg:P,k2:D}=E(b),{p:U,f:te}=k(C),{p:Q,f:$}=k(D);B=te.add($),F=I(N.beta,U,Q,A,P)}else{let{p:A,f:C}=k(b);F=A,B=C}return ot(w,[F,B])[0]}multiplyUnsafe(b){let{endo:N}=t,F=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===En||F.is0())return w.ZERO;if(b===Le)return F;if(V.hasCache(this))return this.multiply(b);if(N){let{k1neg:B,k1:k,k2neg:A,k2:C}=E(b),{p1:P,p2:D}=_u(w,F,k,C);return I(N.beta,P,D,B,A)}else return V.unsafe(F,b)}multiplyAndAddUnsafe(b,N,F){let B=this.multiplyUnsafe(N).add(b.multiplyUnsafe(F));return B.is0()?void 0:B}toAffine(b){return O(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return s===Le?!0:b?b(w,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:b}=t;return s===Le?this:b?b(w,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(b=!0){return Tn(b,"isCompressed"),this.assertValidity(),f(w,this,b)}toHex(b=!0){return H(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return ot(w,b)}static msm(b,N){return Xn(w,o,b,N)}static fromPrivateKey(b){return w.BASE.multiply(Ko(o,b))}}w.BASE=new w(i.Gx,i.Gy,n.ONE),w.ZERO=new w(n.ZERO,n.ONE,n.ZERO),w.Fp=n,w.Fn=o;let v=o.BITS,V=new Zn(w,t.endo?Math.ceil(v/2):v);return w.BASE.precompute(8),w}function Lf(e){return Uint8Array.of(e?2:3)}function qf(e,t){let r=e.ORDER,n=En;for(let h=r-Le;h%or===En;h/=or)n+=Le;let o=n,i=or<<o-Le-Le,s=i*or,a=(r-Le)/s,c=(a-Le)/or,u=s-Le,p=i,d=e.pow(t,a),l=e.pow(t,(a+Le)/or),f=(h,m)=>{let g=d,_=e.pow(m,u),x=e.sqr(_);x=e.mul(x,m);let y=e.mul(h,x);y=e.pow(y,c),y=e.mul(y,_),_=e.mul(y,m),x=e.mul(y,h);let T=e.mul(x,_);y=e.pow(T,p);let E=e.eql(y,e.ONE);_=e.mul(x,l),y=e.mul(T,g),x=e.cmov(_,x,E),T=e.cmov(y,T,E);for(let O=o;O>Le;O--){let R=O-or;R=or<<R-Le;let I=e.pow(T,R),w=e.eql(I,e.ONE);_=e.mul(x,g),g=e.mul(g,g),I=e.mul(T,g),x=e.cmov(_,x,w),T=e.cmov(I,T,w)}return{isValid:E,value:x}};if(e.ORDER%Ta===Qn){let h=(e.ORDER-Qn)/Ta,m=e.sqrt(e.neg(t));f=(g,_)=>{let x=e.sqr(_),y=e.mul(g,_);x=e.mul(x,y);let T=e.pow(x,h);T=e.mul(T,y);let E=e.mul(T,m),O=e.mul(e.sqr(T),_),R=e.eql(O,g),I=e.cmov(E,T,R);return{isValid:R,value:I}}}return f}function Na(e,t){zi(e);let{A:r,B:n,Z:o}=t;if(!e.isValid(r)||!e.isValid(n)||!e.isValid(o))throw new Error("mapToCurveSimpleSWU: invalid opts");let i=qf(e,o);if(!e.isOdd)throw new Error("Field does not have .isOdd()");return s=>{let a,c,u,p,d,l,f,h;a=e.sqr(s),a=e.mul(a,o),c=e.sqr(a),c=e.add(c,a),u=e.add(c,e.ONE),u=e.mul(u,n),p=e.cmov(o,e.neg(c),!e.eql(c,e.ZERO)),p=e.mul(p,r),c=e.sqr(u),l=e.sqr(p),d=e.mul(l,r),c=e.add(c,d),c=e.mul(c,u),l=e.mul(l,p),d=e.mul(l,n),c=e.add(c,d),f=e.mul(a,u);let{isValid:m,value:g}=i(c,l);h=e.mul(a,s),h=e.mul(h,g),f=e.cmov(f,u,m),h=e.cmov(h,g,m);let _=e.isOdd(s)===e.isOdd(h);h=e.cmov(e.neg(h),h,_);let x=nt(e,[p],!0)[0];return f=e.mul(f,x),{x:f,y:h}}}function Mf(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Oa(e){let{CURVE:t,curveOpts:r}=jf(e),n=kf(t,r);return Hf(e,n)}function jf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=ke(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),i={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:i}}function Kf(e,t,r){function n(o){let i=e.sqr(o),s=e.mul(i,o);return e.add(e.add(s,e.mul(o,t)),r)}return n}function Hf(e,t){let{Fp:r,Fn:n}=t;function o(s){return pa(s,Le,n.ORDER)}let i=Kf(r,e.a,e.b);return Object.assign({},{CURVE:e,Point:t,ProjectivePoint:t,normPrivateKeyToScalar:s=>Ko(n,s),weierstrassEquation:i,isWithinCurveOrder:o})}var $f=BigInt(0),Zi=BigInt(1),xu=BigInt(2),eo=BigInt(3);function Gf(e){let t=[];for(;e>Zi;e>>=Zi)(e&Zi)===$f?t.unshift(0):(e&eo)===eo?(t.unshift(-1),e+=Zi):t.unshift(1);return t}function Ea(e){if(!Array.isArray(e)||e.length===0)throw new Error("expected non-empty array")}function Jf(e,t,r,n){let{Fp2:o,Fp12:i}=e,{twistType:s,ateLoopSize:a,xNegative:c,postPrecompute:u}=n,p;if(s==="multiplicative")p=(y,T,E,O,R,I)=>i.mul014(O,y,o.mul(T,R),o.mul(E,I));else if(s==="divisive")p=(y,T,E,O,R,I)=>i.mul034(O,o.mul(E,I),o.mul(T,R),y);else throw new Error("bls: unknown twist type");let d=o.div(o.ONE,o.mul(o.ONE,xu));function l(y,T,E,O){let R=o.sqr(E),I=o.sqr(O),w=o.mulByB(o.mul(I,eo)),v=o.mul(w,eo),V=o.sub(o.sub(o.sqr(o.add(E,O)),I),R),S=o.sub(w,R),b=o.mul(o.sqr(T),eo),N=o.neg(V);return y.push([S,b,N]),T=o.mul(o.mul(o.mul(o.sub(R,v),T),E),d),E=o.sub(o.sqr(o.mul(o.add(R,v),d)),o.mul(o.sqr(w),eo)),O=o.mul(R,V),{Rx:T,Ry:E,Rz:O}}function f(y,T,E,O,R,I){let w=o.sub(E,o.mul(I,O)),v=o.sub(T,o.mul(R,O)),V=o.sub(o.mul(w,R),o.mul(v,I)),S=o.neg(w),b=v;y.push([V,S,b]);let N=o.sqr(v),F=o.mul(N,v),B=o.mul(N,T),k=o.add(o.sub(F,o.mul(B,xu)),o.mul(o.sqr(w),O));return T=o.mul(v,k),E=o.sub(o.mul(o.sub(B,k),w),o.mul(F,E)),O=o.mul(O,F),{Rx:T,Ry:E,Rz:O}}let h=Gf(a),m=Rr(y=>{let T=y,{x:E,y:O}=T.toAffine(),R=E,I=O,w=o.neg(O),v=R,V=I,S=o.ONE,b=[];for(let N of h){let F=[];({Rx:v,Ry:V,Rz:S}=l(F,v,V,S)),N&&({Rx:v,Ry:V,Rz:S}=f(F,v,V,S,R,N===-1?w:I)),b.push(F)}if(u){let N=b[b.length-1];u(v,V,S,R,I,f.bind(null,N))}return b});function g(y,T=!1){let E=i.ONE;if(y.length){let O=y[0][0].length;for(let R=0;R<O;R++){E=i.sqr(E);for(let[I,w,v]of y)for(let[V,S,b]of I[R])E=p(V,S,b,E,w,v)}}return c&&(E=i.conjugate(E)),T?i.finalExponentiate(E):E}function _(y,T=!0){let E=[];ot(t,y.map(({g1:O})=>O)),ot(r,y.map(({g2:O})=>O));for(let{g1:O,g2:R}of y){if(O.is0()||R.is0())throw new Error("pairing is not available for ZERO point");O.assertValidity(),R.assertValidity();let I=O.toAffine();E.push([m(R),I.x,I.y])}return g(E,T)}function x(y,T,E=!0){return _([{g1:y,g2:T}],E)}return{Fp12:i,millerLoopBatch:g,pairing:x,pairingBatch:_,calcPairingPrecomputes:m}}function bu(e,t,r,n,o){let{Fp12:i,pairingBatch:s}=e;function a(d){return d instanceof t.Point?d:t.Point.fromHex(d)}function c(d){return d instanceof r.Point?d:r.Point.fromHex(d)}function u(d){if(!(d instanceof r.Point))throw new Error(`expected valid message hashed to ${o?"G1":"G2"} curve`);return d}let p=o?(d,l)=>({g1:l,g2:d}):(d,l)=>({g1:d,g2:l});return{getPublicKey(d){let l=Ko(t.Point.Fn,d);return t.Point.BASE.multiply(l)},sign(d,l,f){if(f!=null)throw new Error("sign() expects 2 arguments");let h=Ko(t.Point.Fn,l);return u(d).assertValidity(),d.multiply(h)},verify(d,l,f,h){if(h!=null)throw new Error("verify() expects 3 arguments");d=c(d),f=a(f);let m=f.negate(),g=t.Point.BASE,_=u(l),x=d,y=s([p(m,_),p(g,x)]);return i.eql(y,i.ONE)},verifyBatch(d,l,f){if(Ea(l),f.length!==l.length)throw new Error("amount of public keys and messages should be equal");let h=c(d),m=l,g=f.map(a),_=new Map;for(let T=0;T<g.length;T++){let E=g[T],O=m[T],R=_.get(O);R===void 0&&(R=[],_.set(O,R)),R.push(E)}let x=[],y=t.Point.BASE;try{for(let[T,E]of _){let O=E.reduce((R,I)=>R.add(I));x.push(p(O,T))}return x.push(p(y.negate(),h)),i.eql(s(x),i.ONE)}catch{return!1}},aggregatePublicKeys(d){Ea(d),d=d.map(f=>a(f));let l=d.reduce((f,h)=>f.add(h),t.Point.ZERO);return l.assertValidity(),l},aggregateSignatures(d){Ea(d),d=d.map(f=>c(f));let l=d.reduce((f,h)=>f.add(h),r.Point.ZERO);return l.assertValidity(),l},hash(d,l){fe(d);let f=l?{DST:l}:void 0;return r.hashToCurve(d,f)},Signature:n}}function wu(e){let{Fp:t,Fr:r,Fp2:n,Fp6:o,Fp12:i}=e.fields,s=Oa(e.G1),a=Object.assign(s,wa(s.Point,e.G1.mapToCurve,{...e.htfDefaults,...e.G1.htfDefaults})),c=Oa(e.G2),u=Object.assign(c,wa(c.Point,e.G2.mapToCurve,{...e.htfDefaults,...e.G2.htfDefaults})),p=Jf(e.fields,a.Point,u.Point,{...e.params,postPrecompute:e.postPrecompute}),{millerLoopBatch:d,pairing:l,pairingBatch:f,calcPairingPrecomputes:h}=p,m=bu(p,a,u,e.G2.Signature,!1),g=bu(p,u,a,e.G1.ShortSignature,!0),_=e.randomBytes||Pn,x=()=>{let A=Wi(r.ORDER);return ma(_(A),r.ORDER)},y={randomSecretKey:x,randomPrivateKey:x,calcPairingPrecomputes:h},{ShortSignature:T}=e.G1,{Signature:E}=e.G2;function O(A,C){return A instanceof a.Point?A:g.hash(le("point",A),C?.DST)}function R(A,C){return A instanceof u.Point?A:m.hash(le("point",A),C?.DST)}function I(A){return m.getPublicKey(A).toBytes(!0)}function w(A){return g.getPublicKey(A).toBytes(!0)}function v(A,C,P){let D=R(A,P),U=m.sign(D,C);return A instanceof u.Point?U:E.toBytes(U)}function V(A,C,P){let D=O(A,P),U=g.sign(D,C);return A instanceof a.Point?U:T.toBytes(U)}function S(A,C,P,D){let U=R(C,D);return m.verify(A,U,P)}function b(A,C,P,D){let U=O(C,D);return g.verify(A,U,P)}function N(A){let C=m.aggregatePublicKeys(A);return A[0]instanceof a.Point?C:C.toBytes(!0)}function F(A){let C=m.aggregateSignatures(A);return A[0]instanceof u.Point?C:E.toBytes(C)}function B(A){let C=g.aggregateSignatures(A);return A[0]instanceof a.Point?C:T.toBytes(C)}function k(A,C,P,D){let U=C.map(te=>R(te,D));return m.verifyBatch(A,U,P)}return a.Point.BASE.precompute(4),{longSignatures:m,shortSignatures:g,millerLoopBatch:d,pairing:l,pairingBatch:f,verifyBatch:k,fields:{Fr:r,Fp:t,Fp2:n,Fp6:o,Fp12:i},params:{ateLoopSize:e.params.ateLoopSize,twistType:e.params.twistType,r:e.params.r,G1b:e.G1.b,G2b:e.G2.b},utils:y,getPublicKey:I,getPublicKeyForShortSignatures:w,sign:v,signShortSignature:V,verify:S,verifyShortSignature:b,aggregatePublicKeys:N,aggregateSignatures:F,aggregateShortSignatures:B,G1:a,G2:u,Signature:E,ShortSignature:T}}var Tu=BigInt(0),ir=BigInt(1),qe=BigInt(2),Nu=BigInt(3);function Aa(e,t,r,n,o=1,i){let s=BigInt(i===void 0?n:i),a=r**BigInt(n),c=[];for(let u=0;u<o;u++){let p=BigInt(u+1),d=[];for(let l=0,f=ir;l<n;l++){let h=(p*f-p)/s%a;d.push(e.pow(t,h)),f*=r}c.push(d)}return c}function Eu(e,t,r){let n=t.pow(r,(e.ORDER-ir)/Nu),o=t.pow(r,(e.ORDER-ir)/qe);function i(l,f){let h=t.mul(t.frobeniusMap(l,1),n),m=t.mul(t.frobeniusMap(f,1),o);return[h,m]}let s=t.pow(r,(e.ORDER**qe-ir)/Nu),a=t.pow(r,(e.ORDER**qe-ir)/qe);if(!t.eql(a,t.neg(t.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(l,f){return[t.mul(l,s),t.neg(f)]}let u=l=>(f,h)=>{let m=h.toAffine(),g=l(m.x,m.y);return f.fromAffine({x:g[0],y:g[1]})},p=u(i),d=u(c);return{psi:i,psi2:c,G2psi:p,G2psi2:d,PSI_X:n,PSI_Y:o,PSI2_X:s,PSI2_Y:a}}var Ou=(e,t)=>{if(t.length!==2)throw new Error("invalid tuple");let r=t.map(n=>e.create(n));return{c0:r[0],c1:r[1]}},Ra=class{constructor(t,r={}){this.MASK=ir;let n=t.ORDER,o=n*n;this.Fp=t,this.ORDER=o,this.BITS=tr(o),this.BYTES=Math.ceil(tr(o)/8),this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.Fp_NONRESIDUE=t.create(r.NONRESIDUE||BigInt(-1)),this.Fp_div2=t.div(t.ONE,qe),this.NONRESIDUE=Ou(t,r.FP2_NONRESIDUE),this.FROBENIUS_COEFFICIENTS=Aa(t,this.Fp_NONRESIDUE,t.ORDER,2)[0],this.mulByB=r.Fp2mulByB,Object.seal(this)}fromBigTuple(t){return Ou(this.Fp,t)}create(t){return t}isValid({c0:t,c1:r}){function n(o,i){return typeof o=="bigint"&&Tu<=o&&o<i}return n(t,this.ORDER)&&n(r,this.ORDER)}is0({c0:t,c1:r}){return this.Fp.is0(t)&&this.Fp.is0(r)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}eql({c0:t,c1:r},{c0:n,c1:o}){return this.Fp.eql(t,n)&&this.Fp.eql(r,o)}neg({c0:t,c1:r}){return{c0:this.Fp.neg(t),c1:this.Fp.neg(r)}}pow(t,r){return qo(this,t,r)}invertBatch(t){return nt(this,t)}add(t,r){let{c0:n,c1:o}=t,{c0:i,c1:s}=r;return{c0:this.Fp.add(n,i),c1:this.Fp.add(o,s)}}sub({c0:t,c1:r},{c0:n,c1:o}){return{c0:this.Fp.sub(t,n),c1:this.Fp.sub(r,o)}}mul({c0:t,c1:r},n){let{Fp:o}=this;if(typeof n=="bigint")return{c0:o.mul(t,n),c1:o.mul(r,n)};let{c0:i,c1:s}=n,a=o.mul(t,i),c=o.mul(r,s),u=o.sub(a,c),p=o.sub(o.mul(o.add(t,r),o.add(i,s)),o.add(a,c));return{c0:u,c1:p}}sqr({c0:t,c1:r}){let{Fp:n}=this,o=n.add(t,r),i=n.sub(t,r),s=n.add(t,t);return{c0:n.mul(o,i),c1:n.mul(s,r)}}addN(t,r){return this.add(t,r)}subN(t,r){return this.sub(t,r)}mulN(t,r){return this.mul(t,r)}sqrN(t){return this.sqr(t)}div(t,r){let{Fp:n}=this;return this.mul(t,typeof r=="bigint"?n.inv(n.create(r)):this.inv(r))}inv({c0:t,c1:r}){let{Fp:n}=this,o=n.inv(n.create(t*t+r*r));return{c0:n.mul(o,n.create(t)),c1:n.mul(o,n.create(-r))}}sqrt(t){let{Fp:r}=this,n=this,{c0:o,c1:i}=t;if(r.is0(i))return Lo(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 s=r.sqrt(r.sub(r.sqr(o),r.mul(r.sqr(i),this.Fp_NONRESIDUE))),a=r.mul(r.add(s,o),this.Fp_div2);Lo(r,a)===-1&&(a=r.sub(a,s));let u=r.sqrt(a),p=n.create({c0:u,c1:r.div(r.mul(i,this.Fp_div2),u)});if(!n.eql(n.sqr(p),t))throw new Error("Cannot find square root");let d=p,l=n.neg(d),{re:f,im:h}=n.reim(d),{re:m,im:g}=n.reim(l);return h>g||h===g&&f>m?d:l}isOdd(t){let{re:r,im:n}=this.reim(t),o=r%qe,i=r===Tu,s=n%qe;return BigInt(o||i&&s)==ir}fromBytes(t){let{Fp:r}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:r.fromBytes(t.subarray(0,r.BYTES)),c1:r.fromBytes(t.subarray(r.BYTES))}}toBytes({c0:t,c1:r}){return j(this.Fp.toBytes(t),this.Fp.toBytes(r))}cmov({c0:t,c1:r},{c0:n,c1:o},i){return{c0:this.Fp.cmov(t,n,i),c1:this.Fp.cmov(r,o,i)}}reim({c0:t,c1:r}){return{re:t,im:r}}Fp4Square(t,r){let n=this,o=n.sqr(t),i=n.sqr(r);return{first:n.add(n.mulByNonresidue(i),o),second:n.sub(n.sub(n.sqr(n.add(t,r)),o),i)}}mulByNonresidue({c0:t,c1:r}){return this.mul({c0:t,c1:r},this.NONRESIDUE)}frobeniusMap({c0:t,c1:r},n){return{c0:t,c1:this.Fp.mul(r,this.FROBENIUS_COEFFICIENTS[n%2])}}},va=class{constructor(t){this.MASK=ir,this.Fp2=t,this.ORDER=t.ORDER,this.BITS=3*t.BITS,this.BYTES=3*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO,c2:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO,c2:t.ZERO};let{Fp:r}=t,n=Aa(t,t.NONRESIDUE,r.ORDER,6,2,3);this.FROBENIUS_COEFFICIENTS_1=n[0],this.FROBENIUS_COEFFICIENTS_2=n[1],Object.seal(this)}add({c0:t,c1:r,c2:n},{c0:o,c1:i,c2:s}){let{Fp2:a}=this;return{c0:a.add(t,o),c1:a.add(r,i),c2:a.add(n,s)}}sub({c0:t,c1:r,c2:n},{c0:o,c1:i,c2:s}){let{Fp2:a}=this;return{c0:a.sub(t,o),c1:a.sub(r,i),c2:a.sub(n,s)}}mul({c0:t,c1:r,c2:n},o){let{Fp2:i}=this;if(typeof o=="bigint")return{c0:i.mul(t,o),c1:i.mul(r,o),c2:i.mul(n,o)};let{c0:s,c1:a,c2:c}=o,u=i.mul(t,s),p=i.mul(r,a),d=i.mul(n,c);return{c0:i.add(u,i.mulByNonresidue(i.sub(i.mul(i.add(r,n),i.add(a,c)),i.add(p,d)))),c1:i.add(i.sub(i.mul(i.add(t,r),i.add(s,a)),i.add(u,p)),i.mulByNonresidue(d)),c2:i.sub(i.add(p,i.mul(i.add(t,n),i.add(s,c))),i.add(u,d))}}sqr({c0:t,c1:r,c2:n}){let{Fp2:o}=this,i=o.sqr(t),s=o.mul(o.mul(t,r),qe),a=o.mul(o.mul(r,n),qe),c=o.sqr(n);return{c0:o.add(o.mulByNonresidue(a),i),c1:o.add(o.mulByNonresidue(c),s),c2:o.sub(o.sub(o.add(o.add(s,o.sqr(o.add(o.sub(t,r),n))),a),i),c)}}addN(t,r){return this.add(t,r)}subN(t,r){return this.sub(t,r)}mulN(t,r){return this.mul(t,r)}sqrN(t){return this.sqr(t)}create(t){return t}isValid({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return o.isValid(t)&&o.isValid(r)&&o.isValid(n)}is0({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return o.is0(t)&&o.is0(r)&&o.is0(n)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return{c0:o.neg(t),c1:o.neg(r),c2:o.neg(n)}}eql({c0:t,c1:r,c2:n},{c0:o,c1:i,c2:s}){let{Fp2:a}=this;return a.eql(t,o)&&a.eql(r,i)&&a.eql(n,s)}sqrt(t){return Wn()}div(t,r){let{Fp2:n}=this,{Fp:o}=n;return this.mul(t,typeof r=="bigint"?o.inv(o.create(r)):this.inv(r))}pow(t,r){return qo(this,t,r)}invertBatch(t){return nt(this,t)}inv({c0:t,c1:r,c2:n}){let{Fp2:o}=this,i=o.sub(o.sqr(t),o.mulByNonresidue(o.mul(n,r))),s=o.sub(o.mulByNonresidue(o.sqr(n)),o.mul(t,r)),a=o.sub(o.sqr(r),o.mul(t,n)),c=o.inv(o.add(o.mulByNonresidue(o.add(o.mul(n,s),o.mul(r,a))),o.mul(t,i)));return{c0:o.mul(c,i),c1:o.mul(c,s),c2:o.mul(c,a)}}fromBytes(t){let{Fp2:r}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);let n=r.BYTES;return{c0:r.fromBytes(t.subarray(0,n)),c1:r.fromBytes(t.subarray(n,n*2)),c2:r.fromBytes(t.subarray(2*n))}}toBytes({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return j(o.toBytes(t),o.toBytes(r),o.toBytes(n))}cmov({c0:t,c1:r,c2:n},{c0:o,c1:i,c2:s},a){let{Fp2:c}=this;return{c0:c.cmov(t,o,a),c1:c.cmov(r,i,a),c2:c.cmov(n,s,a)}}fromBigSix(t){let{Fp2:r}=this;if(!Array.isArray(t)||t.length!==6)throw new Error("invalid Fp6 usage");return{c0:r.fromBigTuple(t.slice(0,2)),c1:r.fromBigTuple(t.slice(2,4)),c2:r.fromBigTuple(t.slice(4,6))}}frobeniusMap({c0:t,c1:r,c2:n},o){let{Fp2:i}=this;return{c0:i.frobeniusMap(t,o),c1:i.mul(i.frobeniusMap(r,o),this.FROBENIUS_COEFFICIENTS_1[o%6]),c2:i.mul(i.frobeniusMap(n,o),this.FROBENIUS_COEFFICIENTS_2[o%6])}}mulByFp2({c0:t,c1:r,c2:n},o){let{Fp2:i}=this;return{c0:i.mul(t,o),c1:i.mul(r,o),c2:i.mul(n,o)}}mulByNonresidue({c0:t,c1:r,c2:n}){let{Fp2:o}=this;return{c0:o.mulByNonresidue(n),c1:t,c2:r}}mul1({c0:t,c1:r,c2:n},o){let{Fp2:i}=this;return{c0:i.mulByNonresidue(i.mul(n,o)),c1:i.mul(t,o),c2:i.mul(r,o)}}mul01({c0:t,c1:r,c2:n},o,i){let{Fp2:s}=this,a=s.mul(t,o),c=s.mul(r,i);return{c0:s.add(s.mulByNonresidue(s.sub(s.mul(s.add(r,n),i),c)),a),c1:s.sub(s.sub(s.mul(s.add(o,i),s.add(t,r)),a),c),c2:s.add(s.sub(s.mul(s.add(t,n),o),a),c)}}},Ia=class{constructor(t,r){this.MASK=ir;let{Fp2:n}=t,{Fp:o}=n;this.Fp6=t,this.ORDER=n.ORDER,this.BITS=2*t.BITS,this.BYTES=2*t.BYTES,this.isLE=t.isLE,this.ZERO={c0:t.ZERO,c1:t.ZERO},this.ONE={c0:t.ONE,c1:t.ZERO},this.FROBENIUS_COEFFICIENTS=Aa(n,n.NONRESIDUE,o.ORDER,12,1,6)[0],this.X_LEN=r.X_LEN,this.finalExponentiate=r.Fp12finalExponentiate}create(t){return t}isValid({c0:t,c1:r}){let{Fp6:n}=this;return n.isValid(t)&&n.isValid(r)}is0({c0:t,c1:r}){let{Fp6:n}=this;return n.is0(t)&&n.is0(r)}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}neg({c0:t,c1:r}){let{Fp6:n}=this;return{c0:n.neg(t),c1:n.neg(r)}}eql({c0:t,c1:r},{c0:n,c1:o}){let{Fp6:i}=this;return i.eql(t,n)&&i.eql(r,o)}sqrt(t){Wn()}inv({c0:t,c1:r}){let{Fp6:n}=this,o=n.inv(n.sub(n.sqr(t),n.mulByNonresidue(n.sqr(r))));return{c0:n.mul(t,o),c1:n.neg(n.mul(r,o))}}div(t,r){let{Fp6:n}=this,{Fp2:o}=n,{Fp:i}=o;return this.mul(t,typeof r=="bigint"?i.inv(i.create(r)):this.inv(r))}pow(t,r){return qo(this,t,r)}invertBatch(t){return nt(this,t)}add({c0:t,c1:r},{c0:n,c1:o}){let{Fp6:i}=this;return{c0:i.add(t,n),c1:i.add(r,o)}}sub({c0:t,c1:r},{c0:n,c1:o}){let{Fp6:i}=this;return{c0:i.sub(t,n),c1:i.sub(r,o)}}mul({c0:t,c1:r},n){let{Fp6:o}=this;if(typeof n=="bigint")return{c0:o.mul(t,n),c1:o.mul(r,n)};let{c0:i,c1:s}=n,a=o.mul(t,i),c=o.mul(r,s);return{c0:o.add(a,o.mulByNonresidue(c)),c1:o.sub(o.mul(o.add(t,r),o.add(i,s)),o.add(a,c))}}sqr({c0:t,c1:r}){let{Fp6:n}=this,o=n.mul(t,r);return{c0:n.sub(n.sub(n.mul(n.add(n.mulByNonresidue(r),t),n.add(t,r)),o),n.mulByNonresidue(o)),c1:n.add(o,o)}}addN(t,r){return this.add(t,r)}subN(t,r){return this.sub(t,r)}mulN(t,r){return this.mul(t,r)}sqrN(t){return this.sqr(t)}fromBytes(t){let{Fp6:r}=this;if(t.length!==this.BYTES)throw new Error("fromBytes invalid length="+t.length);return{c0:r.fromBytes(t.subarray(0,r.BYTES)),c1:r.fromBytes(t.subarray(r.BYTES))}}toBytes({c0:t,c1:r}){let{Fp6:n}=this;return j(n.toBytes(t),n.toBytes(r))}cmov({c0:t,c1:r},{c0:n,c1:o},i){let{Fp6:s}=this;return{c0:s.cmov(t,n,i),c1:s.cmov(r,o,i)}}fromBigTwelve(t){let{Fp6:r}=this;return{c0:r.fromBigSix(t.slice(0,6)),c1:r.fromBigSix(t.slice(6,12))}}frobeniusMap(t,r){let{Fp6:n}=this,{Fp2:o}=n,{c0:i,c1:s,c2:a}=n.frobeniusMap(t.c1,r),c=this.FROBENIUS_COEFFICIENTS[r%12];return{c0:n.frobeniusMap(t.c0,r),c1:n.create({c0:o.mul(i,c),c1:o.mul(s,c),c2:o.mul(a,c)})}}mulByFp2({c0:t,c1:r},n){let{Fp6:o}=this;return{c0:o.mulByFp2(t,n),c1:o.mulByFp2(r,n)}}conjugate({c0:t,c1:r}){return{c0:t,c1:this.Fp6.neg(r)}}mul014({c0:t,c1:r},n,o,i){let{Fp6:s}=this,{Fp2:a}=s,c=s.mul01(t,n,o),u=s.mul1(r,i);return{c0:s.add(s.mulByNonresidue(u),c),c1:s.sub(s.sub(s.mul01(s.add(r,t),n,a.add(o,i)),c),u)}}mul034({c0:t,c1:r},n,o,i){let{Fp6:s}=this,{Fp2:a}=s,c=s.create({c0:a.mul(t.c0,n),c1:a.mul(t.c1,n),c2:a.mul(t.c2,n)}),u=s.mul01(r,o,i),p=s.mul01(s.add(t,r),a.add(n,o),i);return{c0:s.add(s.mulByNonresidue(u),c),c1:s.sub(p,s.add(c,u))}}_cyclotomicSquare({c0:t,c1:r}){let{Fp6:n}=this,{Fp2:o}=n,{c0:i,c1:s,c2:a}=t,{c0:c,c1:u,c2:p}=r,{first:d,second:l}=o.Fp4Square(i,u),{first:f,second:h}=o.Fp4Square(c,a),{first:m,second:g}=o.Fp4Square(s,p),_=o.mulByNonresidue(g);return{c0:n.create({c0:o.add(o.mul(o.sub(d,i),qe),d),c1:o.add(o.mul(o.sub(f,s),qe),f),c2:o.add(o.mul(o.sub(m,a),qe),m)}),c1:n.create({c0:o.add(o.mul(o.add(_,c),qe),_),c1:o.add(o.mul(o.add(l,u),qe),l),c2:o.add(o.mul(o.add(h,p),qe),h)})}}_cyclotomicExp(t,r){let n=this.ONE;for(let o=this.X_LEN-1;o>=0;o--)n=this._cyclotomicSquare(n),eu(r,o)&&(n=this.mul(n,t));return n}};function Ru(e){let t=ke(e.ORDER),r=new Ra(t,e),n=new va(r),o=new Ia(n,e);return{Fp:t,Fp2:r,Fp6:n,Fp12:o}}var Fe=BigInt(0),Xi=BigInt(1),it=BigInt(2),Qi=BigInt(3),Ho=BigInt(4),Ir=BigInt("0xd201000000010000"),zf=tr(Ir),Rn={p:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),n:BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"),h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),a:Fe,b:Ho,Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")},Wf=ke(Rn.n,{modFromBytes:!0,isLE:!0}),{Fp:L,Fp2:J,Fp6:Yf,Fp12:Y}=Ru({ORDER:Rn.p,X_LEN:zf,FP2_NONRESIDUE:[Xi,Xi],Fp2mulByB:({c0:e,c1:t})=>{let r=L.mul(e,Ho),n=L.mul(t,Ho);return{c0:L.sub(r,n),c1:L.add(r,n)}},Fp12finalExponentiate:e=>{let t=Ir,r=Y.div(Y.frobeniusMap(e,6),e),n=Y.mul(Y.frobeniusMap(r,2),r),o=Y.conjugate(Y._cyclotomicExp(n,t)),i=Y.mul(Y.conjugate(Y._cyclotomicSquare(n)),o),s=Y.conjugate(Y._cyclotomicExp(i,t)),a=Y.conjugate(Y._cyclotomicExp(s,t)),c=Y.mul(Y.conjugate(Y._cyclotomicExp(a,t)),Y._cyclotomicSquare(o)),u=Y.conjugate(Y._cyclotomicExp(c,t)),p=Y.frobeniusMap(Y.mul(o,a),2),d=Y.frobeniusMap(Y.mul(s,n),3),l=Y.frobeniusMap(Y.mul(c,Y.conjugate(n)),1),f=Y.mul(Y.mul(u,Y.conjugate(i)),n);return Y.mul(Y.mul(Y.mul(p,d),l),f)}}),{G2psi:vu,G2psi2:Zf}=Eu(L,J,J.div(J.ONE,J.NONRESIDUE)),Sa=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:L.ORDER,m:2,k:128,expand:"xmd",hash:Se}),Ca={p:J.ORDER,n:Rn.n,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),a:J.ZERO,b:J.fromBigTuple([Ho,Ho]),Gx:J.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:J.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")])},es=$o(L.toBytes(Fe),{infinity:!0,compressed:!0});function ts(e){e=e.slice();let t=e[0]&224,r=!!(t>>7&1),n=!!(t>>6&1),o=!!(t>>5&1);return e[0]&=31,{compressed:r,infinity:n,sort:o,value:e}}function $o(e,t){if(e[0]&224)throw new Error("setMask: non-empty mask");return t.compressed&&(e[0]|=128),t.infinity&&(e[0]|=64),t.sort&&(e[0]|=32),e}function Xf(e,t,r){let{BYTES:n,ORDER:o}=L,i=t.is0(),{x:s,y:a}=t.toAffine();if(r){if(i)return es.slice();let c=!!(a*it/o);return $o(we(s,n),{compressed:!0,sort:c})}else return i?j(Uint8Array.of(64),new Uint8Array(2*n-1)):j(we(s,n),we(a,n))}function Fa(e){e.assertValidity();let{BYTES:t,ORDER:r}=L,{x:n,y:o}=e.toAffine();if(e.is0())return es.slice();let i=!!(o*it/r);return $o(we(n,t),{compressed:!0,sort:i})}function Qf(e){let{compressed:t,infinity:r,sort:n,value:o}=ts(e),{BYTES:i,ORDER:s}=L;if(o.length===48&&t){let a=ze(o),c=L.create(a&wt(L.BITS));if(r){if(c!==Fe)throw new Error("invalid G1 point: non-empty, at infinity, with compression");return{x:Fe,y:Fe}}let u=L.add(L.pow(c,Qi),L.create(Rn.b)),p=L.sqrt(u);if(!p)throw new Error("invalid G1 point: compressed point");return p*it/s!==BigInt(n)&&(p=L.neg(p)),{x:L.create(c),y:L.create(p)}}else if(o.length===96&&!t){let a=ze(o.subarray(0,i)),c=ze(o.subarray(i));if(r){if(a!==Fe||c!==Fe)throw new Error("G1: non-empty point at infinity");return Go.G1.Point.ZERO.toAffine()}return{x:L.create(a),y:L.create(c)}}else throw new Error("invalid G1 point: expected 48/96 bytes")}function Iu(e){let{infinity:t,sort:r,value:n}=ts(le("signatureHex",e,48)),o=L.ORDER,i=Go.G1.Point,s=ze(n);if(t)return i.ZERO;let a=L.create(s&wt(L.BITS)),c=L.add(L.pow(a,Qi),L.create(Rn.b)),u=L.sqrt(c);if(!u)throw new Error("invalid G1 point: compressed");let p=BigInt(r);u*it/o!==p&&(u=L.neg(u));let d=i.fromAffine({x:a,y:u});return d.assertValidity(),d}function eh(e,t,r){let{BYTES:n,ORDER:o}=L,i=t.is0(),{x:s,y:a}=t.toAffine();if(r){if(i)return j(es,we(Fe,n));let c=!!(a.c1===Fe?a.c0*it/o:a.c1*it/o);return j($o(we(s.c1,n),{compressed:!0,sort:c}),we(s.c0,n))}else{if(i)return j(Uint8Array.of(64),new Uint8Array(4*n-1));let{re:c,im:u}=J.reim(s),{re:p,im:d}=J.reim(a);return j(we(u,n),we(c,n),we(d,n),we(p,n))}}function Va(e){e.assertValidity();let{BYTES:t}=L;if(e.is0())return j(es,we(Fe,t));let{x:r,y:n}=e.toAffine(),{re:o,im:i}=J.reim(r),{re:s,im:a}=J.reim(n),u=!!((a>Fe?a*it:s*it)/L.ORDER&Xi),p=o;return j($o(we(i,t),{sort:u,compressed:!0}),we(p,t))}function th(e){let{BYTES:t,ORDER:r}=L,{compressed:n,infinity:o,sort:i,value:s}=ts(e);if(!n&&!o&&i||!n&&o&&i||i&&o&&n)throw new Error("invalid encoding flag: "+(e[0]&224));let a=(c,u,p)=>ze(c.slice(u,p));if(s.length===96&&n){if(o){if(s.reduce((h,m)=>h!==0?m+1:m,0)>0)throw new Error("invalid G2 point: compressed");return{x:J.ZERO,y:J.ZERO}}let c=a(s,0,t),u=a(s,t,2*t),p=J.create({c0:L.create(u),c1:L.create(c)}),d=J.add(J.pow(p,Qi),Ca.b),l=J.sqrt(d),f=l.c1===Fe?l.c0*it/r:l.c1*it/r?Xi:Fe;return l=i&&f>0?l:J.neg(l),{x:p,y:l}}else if(s.length===192&&!n){if(o){if(s.reduce((l,f)=>l!==0?f+1:f,0)>0)throw new Error("invalid G2 point: uncompressed");return{x:J.ZERO,y:J.ZERO}}let c=a(s,0*t,1*t),u=a(s,1*t,2*t),p=a(s,2*t,3*t),d=a(s,3*t,4*t);return{x:J.fromBigTuple([u,c]),y:J.fromBigTuple([d,p])}}else throw new Error("invalid G2 point: expected 96/192 bytes")}function Au(e){let{ORDER:t}=L,{infinity:r,sort:n,value:o}=ts(le("signatureHex",e)),i=Go.G2.Point,s=o.length/2;if(s!==48&&s!==96)throw new Error("invalid compressed signature length, expected 96/192 bytes");let a=ze(o.slice(0,s)),c=ze(o.slice(s));if(r)return i.ZERO;let u=L.create(a&wt(L.BITS)),p=L.create(c),d=J.create({c0:p,c1:u}),l=J.add(J.pow(d,Qi),Ca.b),f=J.sqrt(l);if(!f)throw new Error("Failed to find a square root");let{re:h,im:m}=J.reim(f),g=BigInt(n),_=m>Fe&&m*it/t!==g,x=m===Fe&&h*it/t!==g;(_||x)&&(f=J.neg(f));let y=i.fromAffine({x:d,y:f});return y.assertValidity(),y}var Go=wu({fields:{Fp:L,Fp2:J,Fp6:Yf,Fp12:Y,Fr:Wf},G1:{...Rn,Fp:L,htfDefaults:{...Sa,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(e,t)=>{let r=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),n=new e(L.mul(t.X,r),t.Y,t.Z);return t.multiplyUnsafe(Ir).negate().multiplyUnsafe(Ir).equals(n)},clearCofactor:(e,t)=>t.multiplyUnsafe(Ir).add(t),mapToCurve:sh,fromBytes:Qf,toBytes:Xf,ShortSignature:{fromBytes(e){return fe(e),Iu(e)},fromHex(e){return Iu(e)},toBytes(e){return Fa(e)},toRawBytes(e){return Fa(e)},toHex(e){return H(Fa(e))}}},G2:{...Ca,Fp:J,hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...Sa},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:ah,isTorsionFree:(e,t)=>t.multiplyUnsafe(Ir).negate().equals(vu(e,t)),clearCofactor:(e,t)=>{let r=Ir,n=t.multiplyUnsafe(r).negate(),o=vu(e,t),i=t.double();return i=Zf(e,i),i=i.subtract(o),o=n.add(o),o=o.multiplyUnsafe(r).negate(),i=i.add(o),i=i.subtract(n),i.subtract(t)},fromBytes:th,toBytes:eh,Signature:{fromBytes(e){return fe(e),Au(e)},fromHex(e){return Au(e)},toBytes(e){return Va(e)},toRawBytes(e){return Va(e)},toHex(e){return H(Va(e))}}},params:{ateLoopSize:Ir,r:Rn.n,xNegative:!0,twistType:"multiplicative"},htfDefaults:Sa,hash:Se}),rh=ba(J,[[["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(e=>e.map(t=>J.fromBigTuple(t.map(BigInt))))),nh=ba(L,[["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(e=>e.map(t=>BigInt(t)))),oh=Na(L,{A:L.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:L.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:L.create(BigInt(11))}),ih=Na(J,{A:J.create({c0:L.create(Fe),c1:L.create(BigInt(240))}),B:J.create({c0:L.create(BigInt(1012)),c1:L.create(BigInt(1012))}),Z:J.create({c0:L.create(BigInt(-2)),c1:L.create(BigInt(-1))})});function sh(e){let{x:t,y:r}=oh(L.create(e[0]));return nh(t,r)}function ah(e){let{x:t,y:r}=ih(J.fromBigTuple(e));return rh(t,r)}function Su(e,t,r){let n=typeof e=="string"?e:H(e),o=typeof t=="string"?t:H(t),i=typeof r=="string"?r:H(r);return Go.verifyShortSignature(o,i,n)}var lh=BigInt(1e6),Pa=e=>me(new _t(e)),to=e=>{let r=Pa(e)/lh;return new Date(Number(r))};var Fu=60*1e3,uh=60,dh=24,ph=dh*uh,fh=5,hh=5,mh=30*ph,Ie;(function(e){e[e.Empty=0]="Empty",e[e.Fork=1]="Fork",e[e.Labeled=2]="Labeled",e[e.Leaf=3]="Leaf",e[e.Pruned=4]="Pruned"})(Ie||(Ie={}));function _h(e,t){for(let r=0;r<e.length;r++)if(e[r]>t[r])return!0;return!1}var Ar=class e{#e=!1;#t=void 0;static async create(t){let r=e.createUnverified(t);return await r.verify(),r}static createUnverified(t){return new e(t.certificate,t.rootKey,t.canisterId,t.blsVerify??Su,t.maxAgeInMinutes,t.disableTimeVerification,t.agent)}constructor(t,r,n,o,i=fh,s=!1,a){this._rootKey=r,this._canisterId=n,this._blsVerify=o,this._maxAgeInMinutes=i,this.#e=s,this.cert=Je(t),a&&"getTimeDiffMsecs"in a&&"hasSyncedTime"in a&&"syncTime"in a&&(this.#t=a)}lookup_path(t){return In(t,this.cert.tree)}lookup_subtree(t){return os(t,this.cert.tree)}async verify(){let t=await rs(this.cert.tree),r=await this._checkDelegationAndGetKey(this.cert.delegation),n=this.cert.signature,o=gh(r),i=j(zo("ic-state-root"),t),s=Ve(this.lookup_path(["time"]));if(!s)throw ne.fromCode(new gr("Certificate does not contain a time"));if(!this.#e){let a=this.#t?.getTimeDiffMsecs()??0,c=this._maxAgeInMinutes*Fu,u=new Date,p=u.getTime()+a,d=p-c,l=p+hh*Fu,f=to(s),h=f.getTime()<d,m=f.getTime()>l;if((h||m)&&this.#t&&!this.#t.hasSyncedTime())return await this.#t.syncTime(this._canisterId),await this.verify();if(h)throw Pe.fromCode(new pn(this._maxAgeInMinutes,f,u,a,"past"));if(m)throw this.#t?.hasSyncedTime()?ge.fromCode(new Be("System time has been synced with the IC network, but certificate is still too far in the future.")):Pe.fromCode(new pn(5,f,u,a,"future"))}try{if(!await this._blsVerify(o,n,i))throw Pe.fromCode(new gr("Invalid signature"))}catch(a){throw Pe.fromCode(new gr("Signature verification failed",a))}}async _checkDelegationAndGetKey(t){if(!t)return this._rootKey;let r=e.createUnverified({certificate:t.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,disableTimeVerification:this.#e,maxAgeInMinutes:mh,agent:this.#t});if(r.cert.delegation)throw ne.fromCode(new mi);await r.verify();let n=t.subnet_id,o=M.fromUint8Array(n);if(!Ba({canisterId:this._canisterId,subnetId:o,tree:r.cert.tree}))throw Pe.fromCode(new Bn(this._canisterId,o));let s=Ve(r.lookup_path(["subnet",n,"public_key"]));if(!s)throw Pe.fromCode(new _i(`Could not find subnet key for subnet ID ${o.toText()}`));return s}},Jo=Ne("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),yh=96;function gh(e){let t=Jo.byteLength+yh;if(e.byteLength!==t)throw ne.fromCode(new Un(t,e.byteLength));let r=e.slice(0,Jo.byteLength);if(!xn(r,Jo))throw ne.fromCode(new yi(Jo,r));return e.slice(Jo.byteLength)}function Ve(e){if(e.status===We.Found&&e.value instanceof Uint8Array)return e.value}async function rs(e){switch(e[0]){case Ie.Empty:return Se(zo("ic-hashtree-empty"));case Ie.Pruned:return e[1];case Ie.Leaf:return Se(j(zo("ic-hashtree-leaf"),e[1]));case Ie.Labeled:return Se(j(zo("ic-hashtree-labeled"),e[1],await rs(e[2])));case Ie.Fork:return Se(j(zo("ic-hashtree-fork"),await rs(e[1]),await rs(e[2])));default:throw wr}}function zo(e){let t=new Uint8Array([e.length]),r=new TextEncoder().encode(e);return j(t,r)}function Vu(e){return typeof e[0]=="string"?ee(e[0]):e[0]}var We;(function(e){e.Unknown="Unknown",e.Absent="Absent",e.Found="Found",e.Error="Error"})(We||(We={}));var vn;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found"})(vn||(vn={}));var ae;(function(e){e.Absent="Absent",e.Unknown="Unknown",e.Found="Found",e.Less="Less",e.Greater="Greater"})(ae||(ae={}));function In(e,t){if(e.length===0)switch(t[0]){case Ie.Empty:return{status:We.Absent};case Ie.Leaf:{if(!t[1])throw ge.fromCode(new br("Invalid tree structure for leaf"));if(t[1]instanceof Uint8Array)return{status:We.Found,value:t[1].slice(t[1].byteOffset,t[1].byteLength+t[1].byteOffset)};throw wr}case Ie.Pruned:return{status:We.Unknown};case Ie.Labeled:case Ie.Fork:return{status:We.Error};default:throw wr}let r=Vu(e),n=Wo(r,t);switch(n.status){case ae.Found:return In(e.slice(1),n.value);case ae.Absent:case ae.Greater:case ae.Less:return{status:We.Absent};case ae.Unknown:return{status:We.Unknown};default:throw wr}}function os(e,t){if(e.length===0)return{status:vn.Found,value:t};let r=Vu(e),n=Wo(r,t);switch(n.status){case ae.Found:return os(e.slice(1),n.value);case ae.Unknown:return{status:vn.Unknown};case ae.Absent:case ae.Greater:case ae.Less:return{status:vn.Absent};default:throw wr}}function ns(e){switch(e[0]){case Ie.Empty:return[];case Ie.Fork:return ns(e[1]).concat(ns(e[2]));default:return[e]}}function Wo(e,t){switch(t[0]){case Ie.Labeled:return _h(e,t[1])?{status:ae.Greater}:xn(e,t[1])?{status:ae.Found,value:t[2]}:{status:ae.Less};case Ie.Fork:{let r=Wo(e,t[1]);switch(r.status){case ae.Greater:{let n=Wo(e,t[2]);return n.status===ae.Less?{status:ae.Absent}:n}case ae.Unknown:{let n=Wo(e,t[2]);return n.status===ae.Less?{status:ae.Unknown}:n}default:return r}}case Ie.Pruned:return{status:ae.Unknown};default:return{status:ae.Absent}}}function Ba(e){let{canisterId:t,subnetId:r,tree:n}=e,o=In(["subnet",r.toUint8Array(),"canister_ranges"],n);if(o.status!==We.Found)throw ne.fromCode(new Jt(`Could not find canister ranges for subnet ${r.toText()}`,o.status));if(!(o.value instanceof Uint8Array))throw ne.fromCode(new Dn(`Could not find canister ranges for subnet ${r.toText()}`));return Je(o.value).map(c=>[M.fromUint8Array(c[0]),M.fromUint8Array(c[1])]).some(c=>c[0].ltEq(t)&&c[1].gtEq(t))}var Da=async e=>{let{agent:t,paths:r,disableCertificateTimeVerification:n=!1}=e,o=M.from(e.canisterId),i=[...new Set(r)],s=new Map,a=i.map((c,u)=>{let p=bh(c,o);return(async()=>{try{if(t.rootKey===null)throw Oe.fromCode(new Rt);let d=t.rootKey,l=await t.readState(o,{paths:[p]}),f=await Ar.create({certificate:l.certificate,rootKey:d,canisterId:o,disableTimeVerification:n,agent:t}),h=(_,x)=>{if(x==="subnet"){let y=xh(l.certificate,o,d);return{path:x,data:y}}else return{path:x,data:Ve(_.lookup_path(p))}},{path:m,data:g}=h(f,i[u]);if(!g)console.warn(`Expected to find result for path ${m}, but instead found nothing.`),typeof m=="string"?s.set(m,null):s.set(m.key,null);else switch(m){case"time":{s.set(m,to(g));break}case"controllers":{s.set(m,wh(g));break}case"module_hash":{s.set(m,H(g));break}case"subnet":{s.set(m,g);break}case"candid":{s.set(m,new TextDecoder().decode(g));break}default:if(typeof m!="string"&&"key"in m&&"path"in m)switch(m.decodeStrategy){case"raw":s.set(m.key,g);break;case"leb128":{s.set(m.key,Pa(g));break}case"cbor":{s.set(m.key,Je(g));break}case"hex":{s.set(m.key,H(g));break}case"utf-8":s.set(m.key,new TextDecoder().decode(g))}}}catch(d){if(d instanceof ht&&(d.hasCode(gr)||d.hasCode(pn)))throw d;typeof c!="string"&&"key"in c&&"path"in c?s.set(c.key,null):s.set(c,null),console.group(),console.warn(`Expected to find result for path ${c}, but instead found nothing.`),console.warn(d),console.groupEnd()}})()});return await Promise.all(a),s},xh=(e,t,r)=>{if(!t._isPrincipal)throw z.fromCode(new Be("Invalid canisterId"));let n=Je(e),o=n.tree,i=n.delegation,s;if(i&&i.subnet_id?s=M.fromUint8Array(new Uint8Array(i.subnet_id)):!i&&typeof r<"u"?(s=M.selfAuthenticating(new Uint8Array(r)),i={subnet_id:s.toUint8Array(),certificate:new Uint8Array(0)}):(s=M.selfAuthenticating(M.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),i={subnet_id:s.toUint8Array(),certificate:new Uint8Array(0)}),!Ba({canisterId:t,subnetId:s,tree:o}))throw Pe.fromCode(new Bn(t,s));let c=os(["subnet",i.subnet_id,"node"],o);if(c.status!==vn.Found)throw ne.fromCode(new Jt("Node not found",c.status));if(c.value instanceof Uint8Array)throw ge.fromCode(new br("Invalid node tree"));let u=ns(c.value),p=new Map;return u.forEach(d=>{let l=M.from(d[1]).toText(),f=In(["public_key"],d[2]);if(f.status!==We.Found)throw ne.fromCode(new Jt("Public key not found",f.status));let h=f.value;if(h.byteLength!==44)throw ne.fromCode(new Un(44,h.byteLength));p.set(l,h)}),{subnetId:M.fromUint8Array(new Uint8Array(i.subnet_id)).toText(),nodeKeys:p}},bh=(e,t)=>{let r=t.toUint8Array();switch(e){case"time":return[ee("time")];case"controllers":return[ee("canister"),r,ee("controllers")];case"module_hash":return[ee("canister"),r,ee("module_hash")];case"subnet":return[ee("subnet")];case"candid":return[ee("canister"),r,ee("metadata"),ee("candid:service")];default:if("key"in e&&"path"in e)if(typeof e.path=="string"||e.path instanceof Uint8Array){let n=e.path,o=typeof n=="string"?ee(n):n;return[ee("canister"),r,ee("metadata"),o]}else return e.path}throw ge.fromCode(new Be(`Error while encoding your path for canister status. Please ensure that your path ${e} was formatted correctly.`))},wh=e=>Je(e).map(r=>M.fromUint8Array(r));var Sr=BigInt(0),Re=BigInt(1),Ua=BigInt(2),Th=BigInt(8);function Nh(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}function Oh(e,t={}){let r=Yi("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;rr(t,{},{uvRatio:"function"});let a=Ua<<BigInt(o.BYTES*8)-Re,c=g=>n.create(g),u=t.uvRatio||((g,_)=>{try{return{isValid:!0,value:n.sqrt(n.div(g,_))}}catch{return{isValid:!1,value:Sr}}});if(!Nh(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function p(g,_,x=!1){let y=x?Re:Sr;return Ji("coordinate "+g,_,y,a),_}function d(g){if(!(g instanceof h))throw new Error("ExtendedPoint expected")}let l=Rr((g,_)=>{let{X:x,Y:y,Z:T}=g,E=g.is0();_==null&&(_=E?Th:n.inv(T));let O=c(x*_),R=c(y*_),I=n.mul(T,_);if(E)return{x:Sr,y:Re};if(I!==Re)throw new Error("invZ was invalid");return{x:O,y:R}}),f=Rr(g=>{let{a:_,d:x}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:y,Y:T,Z:E,T:O}=g,R=c(y*y),I=c(T*T),w=c(E*E),v=c(w*w),V=c(R*_),S=c(w*c(V+I)),b=c(v+c(x*c(R*I)));if(S!==b)throw new Error("bad point: equation left != right (1)");let N=c(y*T),F=c(E*O);if(N!==F)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(_,x,y,T){this.X=p("x",_),this.Y=p("y",x),this.Z=p("z",y,!0),this.T=p("t",T),Object.freeze(this)}static CURVE(){return i}static fromAffine(_){if(_ instanceof h)throw new Error("extended point not allowed");let{x,y}=_||{};return p("x",x),p("y",y),new h(x,y,Re,c(x*y))}static fromBytes(_,x=!1){let y=n.BYTES,{a:T,d:E}=i;_=da(Er(_,y,"point")),Tn(x,"zip215");let O=da(_),R=_[y-1];O[y-1]=R&-129;let I=er(O),w=x?a:n.ORDER;Ji("point.y",I,Sr,w);let v=c(I*I),V=c(v-Re),S=c(E*v-T),{isValid:b,value:N}=u(V,S);if(!b)throw new Error("bad point: invalid y coordinate");let F=(N&Re)===Re,B=(R&128)!==0;if(!x&&N===Sr&&B)throw new Error("bad point: x=0 and x_0=1");return B!==F&&(N=c(-N)),h.fromAffine({x:N,y:I})}static fromHex(_,x=!1){return h.fromBytes(le("point",_),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(_=8,x=!0){return m.createCache(this,_),x||this.multiply(Ua),this}assertValidity(){f(this)}equals(_){d(_);let{X:x,Y:y,Z:T}=this,{X:E,Y:O,Z:R}=_,I=c(x*R),w=c(E*T),v=c(y*R),V=c(O*T);return I===w&&v===V}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:_}=i,{X:x,Y:y,Z:T}=this,E=c(x*x),O=c(y*y),R=c(Ua*c(T*T)),I=c(_*E),w=x+y,v=c(c(w*w)-E-O),V=I+O,S=V-R,b=I-O,N=c(v*S),F=c(V*b),B=c(v*b),k=c(S*V);return new h(N,F,k,B)}add(_){d(_);let{a:x,d:y}=i,{X:T,Y:E,Z:O,T:R}=this,{X:I,Y:w,Z:v,T:V}=_,S=c(T*I),b=c(E*w),N=c(R*y*V),F=c(O*v),B=c((T+E)*(I+w)-S-b),k=F-N,A=F+N,C=c(b-x*S),P=c(B*k),D=c(A*C),U=c(B*C),te=c(k*A);return new h(P,D,te,U)}subtract(_){return this.add(_.negate())}multiply(_){if(!o.isValidNot0(_))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:y}=m.cached(this,_,T=>ot(h,T));return ot(h,[x,y])[0]}multiplyUnsafe(_,x=h.ZERO){if(!o.isValid(_))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return _===Sr?h.ZERO:this.is0()||_===Re?this:m.unsafe(this,_,y=>ot(h,y),x)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(_){return l(this,_)}clearCofactor(){return s===Re?this:this.multiplyUnsafe(s)}toBytes(){let{x:_,y:x}=this.toAffine(),y=n.toBytes(x);return y[y.length-1]|=_&Re?128:0,y}toHex(){return H(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(_){return ot(h,_)}static msm(_,x){return Xn(h,o,_,x)}_setWindowSize(_){this.precompute(_)}toRawBytes(){return this.toBytes()}}h.BASE=new h(i.Gx,i.Gy,Re,c(i.Gx*i.Gy)),h.ZERO=new h(Sr,Re,Re,Sr),h.Fp=n,h.Fn=o;let m=new Zn(h,o.BITS);return h.BASE.precompute(8),h}var is=class{constructor(t){this.ep=t}static fromBytes(t){Wn()}static fromHex(t){Wn()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return H(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function Eh(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');rr(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,a=r.randomBytes||Pn,c=r.adjustScalarBytes||(w=>w),u=r.domain||((w,v,V)=>{if(Tn(V,"phflag"),v.length||V)throw new Error("Contexts/pre-hash are not supported");return w});function p(w){return s.create(er(w))}function d(w){let v=y.secretKey;w=le("private key",w,v);let V=le("hashed private key",t(w),2*v),S=c(V.slice(0,v)),b=V.slice(v,2*v),N=p(S);return{head:S,prefix:b,scalar:N}}function l(w){let{head:v,prefix:V,scalar:S}=d(w),b=o.multiply(S),N=b.toBytes();return{head:v,prefix:V,scalar:S,point:b,pointBytes:N}}function f(w){return l(w).pointBytes}function h(w=Uint8Array.of(),...v){let V=j(...v);return p(t(u(V,le("context",w),!!n)))}function m(w,v,V={}){w=le("message",w),n&&(w=n(w));let{prefix:S,scalar:b,pointBytes:N}=l(v),F=h(V.context,S,w),B=o.multiply(F).toBytes(),k=h(V.context,B,N,w),A=s.create(F+k*b);if(!s.isValid(A))throw new Error("sign failed: invalid s");let C=j(B,s.toBytes(A));return Er(C,y.signature,"result")}let g={zip215:!0};function _(w,v,V,S=g){let{context:b,zip215:N}=S,F=y.signature;w=le("signature",w,F),v=le("message",v),V=le("publicKey",V,y.publicKey),N!==void 0&&Tn(N,"zip215"),n&&(v=n(v));let B=F/2,k=w.subarray(0,B),A=er(w.subarray(B,F)),C,P,D;try{C=e.fromBytes(V,N),P=e.fromBytes(k,N),D=o.multiplyUnsafe(A)}catch{return!1}if(!N&&C.isSmallOrder())return!1;let U=h(b,P.toBytes(),C.toBytes(),v);return P.add(C.multiplyUnsafe(U)).subtract(D).clearCofactor().is0()}let x=i.BYTES,y={secretKey:x,publicKey:x,signature:2*x,seed:x};function T(w=a(y.seed)){return Er(w,y.seed,"seed")}function E(w){let v=I.randomSecretKey(w);return{secretKey:v,publicKey:f(v)}}function O(w){return Ot(w)&&w.length===s.BYTES}function R(w,v){try{return!!e.fromBytes(w,v)}catch{return!1}}let I={getExtendedPublicKey:l,randomSecretKey:T,isValidSecretKey:O,isValidPublicKey:R,toMontgomery(w){let{y:v}=e.fromBytes(w),V=y.publicKey,S=V===32;if(!S&&V!==57)throw new Error("only defined for 25519 and 448");let b=S?i.div(Re+v,Re-v):i.div(v-Re,v+Re);return i.toBytes(b)},toMontgomerySecret(w){let v=y.secretKey;Er(w,v);let V=t(w.subarray(0,v));return c(V).subarray(0,v)},randomPrivateKey:T,precompute(w=8,v=e.BASE){return v.precompute(w,!1)}};return Object.freeze({keygen:E,getPublicKey:f,sign:m,verify:_,utils:I,Point:e,lengths:y})}function Rh(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=ke(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},i={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:i}}function vh(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Cu(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Rh(e),i=Oh(t,r),s=Eh(i,n,o);return vh(e,s)}var Ih=BigInt(0),sr=BigInt(1),Pu=BigInt(2),ag=BigInt(3),Ah=BigInt(5),Sh=BigInt(8),ro=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Yo={p:ro,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Sh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Fh(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=ro,a=e*e%i*e%i,c=Tt(a,Pu,i)*a%i,u=Tt(c,sr,i)*e%i,p=Tt(u,Ah,i)*u%i,d=Tt(p,t,i)*p%i,l=Tt(d,r,i)*d%i,f=Tt(l,n,i)*l%i,h=Tt(f,o,i)*f%i,m=Tt(h,o,i)*f%i,g=Tt(m,t,i)*p%i;return{pow_p_5_8:Tt(g,Pu,i)*e%i,b2:a}}function Vh(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var ka=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ma(e,t){let r=ro,n=se(t*t*t,r),o=se(n*n*t,r),i=Fh(e*o).pow_p_5_8,s=se(e*n*i,r),a=se(t*s*s,r),c=s,u=se(s*ka,r),p=a===e,d=a===se(-e,r),l=a===se(-e*ka,r);return p&&(s=c),(d||l)&&(s=u),nr(s,r)&&(s=se(-s,r)),{isValid:p||d,value:s}}var Fr=ke(Yo.p,{isLE:!0}),Ch=ke(Yo.n,{isLE:!0}),Ph={...Yo,Fp:Fr,hash:il,adjustScalarBytes:Vh,uvRatio:Ma},Me=Cu(Ph);var La=ka,Bh=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Dh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Uh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),kh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Bu=e=>Ma(sr,e),Lh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),qa=e=>Me.Point.Fp.create(er(e)&Lh);function Du(e){let{d:t}=Yo,r=ro,n=_=>Fr.create(_),o=n(La*e*e),i=n((o+sr)*Uh),s=BigInt(-1),a=n((s-t*o)*n(o+t)),{isValid:c,value:u}=Ma(i,a),p=n(u*e);nr(p,r)||(p=n(-p)),c||(u=p),c||(s=o);let d=n(s*(o-sr)*kh-a),l=u*u,f=n((u+u)*a),h=n(d*Bh),m=n(sr-l),g=n(sr+l);return new Me.Point(n(f*g),n(m*h),n(h*g),n(f*m))}function qh(e){fe(e,64);let t=qa(e.subarray(0,32)),r=Du(t),n=qa(e.subarray(32,64)),o=Du(n);return new ar(r.add(o))}var ar=class e extends is{constructor(t){super(t)}static fromAffine(t){return new e(Me.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return qh(le("ristrettoHash",t,64))}static fromBytes(t){fe(t,32);let{a:r,d:n}=Yo,o=ro,i=T=>Fr.create(T),s=qa(t);if(!Ql(Fr.toBytes(s),t)||nr(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(sr+r*a),u=i(sr-r*a),p=i(c*c),d=i(u*u),l=i(r*n*p-d),{isValid:f,value:h}=Bu(i(l*d)),m=i(h*u),g=i(h*m*l),_=i((s+s)*m);nr(_,o)&&(_=i(-_));let x=i(c*g),y=i(_*x);if(!f||nr(y,o)||x===Ih)throw new Error("invalid ristretto255 encoding 2");return new e(new Me.Point(_,x,sr,y))}static fromHex(t){return e.fromBytes(le("ristrettoHex",t,32))}static msm(t,r){return Xn(e,Me.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,i=ro,s=g=>Fr.create(g),a=s(s(n+r)*s(n-r)),c=s(t*r),u=s(c*c),{value:p}=Bu(s(a*u)),d=s(p*a),l=s(p*c),f=s(d*l*o),h;if(nr(o*f,i)){let g=s(r*La),_=s(t*La);t=g,r=_,h=s(d*Dh)}else h=l;nr(t*f,i)&&(r=s(-r));let m=s((n-r)*h);return nr(m,i)&&(m=s(-m)),Fr.toBytes(m)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:i}=t.ep,s=u=>Fr.create(u),a=s(r*i)===s(n*o),c=s(n*i)===s(r*o);return a||c}is0(){return this.equals(e.ZERO)}};ar.BASE=new ar(Me.Point.BASE);ar.ZERO=new ar(Me.Point.ZERO);ar.Fp=Fr;ar.Fn=Ch;var Uu,ku,ss=class{static{Uu=Symbol.iterator,ku=Symbol.toStringTag}#e;#t;constructor(t={}){this[Uu]=this.entries.bind(this),this[ku]="ExpirableMap";let{source:r=[],expirationTime:n=600*1e3}=t,o=Date.now();this.#e=new Map([...r].map(([i,s])=>[i,{value:s,timestamp:o}])),this.#t=n}prune(){let t=Date.now();for(let[r,n]of this.#e.entries())t-n.timestamp>this.#t&&this.#e.delete(r);return this}set(t,r){this.prune();let n={value:r,timestamp:Date.now()};return this.#e.set(t,n),this}get(t){let r=this.#e.get(t);if(r!==void 0){if(Date.now()-r.timestamp>this.#t){this.#e.delete(t);return}return r.value}}clear(){this.#e.clear()}entries(){let t=this.#e.entries();return function*(){for(let[n,o]of t)yield[n,o.value]}()}values(){let t=this.#e.values();return function*(){for(let n of t)yield n.value}()}keys(){return this.#e.keys()}forEach(t,r){for(let[n,o]of this.#e.entries())t.call(r,o.value,n,this)}has(t){return this.#e.has(t)}delete(t){return this.#e.delete(t)}get size(){return this.#e.size}};var Lu=e=>{if(e<=127)return 1;if(e<=255)return 2;if(e<=65535)return 3;if(e<=16777215)return 4;throw z.fromCode(new go("Length too long (> 4 bytes)"))},qu=(e,t,r)=>{if(r<=127)return e[t]=r,1;if(r<=255)return e[t]=129,e[t+1]=r,2;if(r<=65535)return e[t]=130,e[t+1]=r>>8,e[t+2]=r,3;if(r<=16777215)return e[t]=131,e[t+1]=r>>16,e[t+2]=r>>8,e[t+3]=r,4;throw z.fromCode(new go("Length too long (> 4 bytes)"))},ja=(e,t)=>{if(e[t]<128)return 1;if(e[t]===128)throw z.fromCode(new mt("Invalid length 0"));if(e[t]===129)return 2;if(e[t]===130)return 3;if(e[t]===131)return 4;throw z.fromCode(new mt("Length too long (> 4 bytes)"))},Mh=(e,t)=>{let r=ja(e,t);if(r===1)return e[t];if(r===2)return e[t+1];if(r===3)return(e[t+1]<<8)+e[t+2];if(r===4)return(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];throw z.fromCode(new mt("Length too long (> 4 bytes)"))},Zo=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),An=Uint8Array.from([48,5,6,3,43,101,112]),pg=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]),fg=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 Sn(e,t){let r=2+Lu(e.byteLength+1),n=t.byteLength+r+e.byteLength,o=0,i=new Uint8Array(1+Lu(n)+n);return i[o++]=48,o+=qu(i,o,n),i.set(t,o),o+=t.byteLength,i[o++]=3,o+=qu(i,o,e.byteLength+1),i[o++]=0,i.set(new Uint8Array(e),o),i}var Fn=(e,t)=>{let r=0,n=(a,c)=>{if(o[r++]!==a)throw z.fromCode(new mt(`Expected ${c} at offset ${r}`))},o=new Uint8Array(e);if(n(48,"sequence"),r+=ja(o,r),!xn(o.slice(r,r+t.byteLength),t))throw z.fromCode(new mt("Not the expected OID."));r+=t.byteLength,n(3,"bit string");let i=Mh(o,r)-1;r+=ja(o,r),n(0,"0 padding");let s=o.slice(r);if(i!==s.length)throw z.fromCode(new gi(i,s.length));return s};var as=class e{static from(t){return this.fromDer(t.toDer())}static fromRaw(t){return new e(t)}static fromDer(t){return new e(this.derDecode(t))}static{this.RAW_KEY_LENGTH=32}static derEncode(t){return Sn(t,An)}static derDecode(t){let r=Fn(t,An);if(r.length!==this.RAW_KEY_LENGTH)throw z.fromCode(new mt("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(t){if(t.byteLength!==e.RAW_KEY_LENGTH)throw z.fromCode(new mt("An Ed25519 public key must be exactly 32 bytes long"));this.#e=t,this.#t=e.derEncode(t)}toDer(){return this.derKey}toRaw(){return this.rawKey}};var Ka=class{constructor(){this.observers=[]}subscribe(t){this.observers.push(t)}unsubscribe(t){this.observers=this.observers.filter(r=>r!==t)}notify(t,...r){this.observers.forEach(n=>n(t,...r))}},cs=class extends Ka{constructor(){super()}print(t,...r){this.notify({message:t,level:"info"},...r)}warn(t,...r){this.notify({message:t,level:"warn"},...r)}error(t,r,...n){this.notify({message:t,level:"error",error:r},...n)}};var ls=class e{#e;#t;#r;#c;#s;#u;#n;#o;#a=0;static{this.default={initialInterval:500,randomizationFactor:.5,multiplier:1.5,maxInterval:6e4,maxElapsedTime:9e5,maxIterations:10,date:Date}}constructor(t=e.default){let{initialInterval:r=500,randomizationFactor:n=.5,multiplier:o=1.5,maxInterval:i=6e4,maxElapsedTime:s=9e5,maxIterations:a=10,date:c=Date}=t;this.#e=r,this.#t=n,this.#r=o,this.#c=i,this.#o=c,this.#s=c.now(),this.#u=s,this.#n=a}get ellapsedTimeInMsec(){return this.#o.now()-this.#s}get currentInterval(){return this.#e}get count(){return this.#a}get randomValueFromInterval(){let t=this.#t*this.#e,r=this.#e-t,n=this.#e+t;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.#u||this.#a>=this.#n?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};var Vt;(function(e){e.Received="received",e.Processing="processing",e.Replied="replied",e.Rejected="rejected",e.Unknown="unknown",e.Done="done"})(Vt||(Vt={}));var Ga=60*1e3,jh=1e6,Kh=0,Hh="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae";var $h="ic0.app",Gh=".ic0.app",Jh="icp0.io",zh=".icp0.io",Wh="icp-api.io",Yh=".icp-api.io",Ha=200,Zh=202,Xh=404;function Qh(){let e;if(typeof window<"u")if(window.fetch)e=window.fetch.bind(window);else throw Oe.fromCode(new Ln("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)e=global.fetch.bind(global);else throw Oe.fromCode(new Ln("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&&(e=self.fetch.bind(self));if(e)return e;throw Oe.fromCode(new Ln("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context."))}function em(e){let t;if(e!==void 0)!e.match(/^[a-z]+:/)&&typeof window<"u"?t=new URL(window.location.protocol+"//"+e):t=new URL(e);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,i=o?.hostname,s;i&&typeof i=="string"&&(n.some(a=>i.endsWith(a))?s=i:s=r.find(a=>i.endsWith(a))),o&&s?t=new URL(`${o.protocol}//${s}${o.port?":"+o.port:""}`):t=new URL("https://icp-api.io")}return t.toString()}var cr=class e{#e;#t;#r;#c;#s;#u;#n;#o;#a;#x;#i;#d;#p;#l;get#N(){return this.#l*Ga}#f;#h;#m;#_;constructor(t={}){this.#e=null,this.#t=!1,this.#r=Kh,this.#c=!1,this.#s=null,this.#u=!1,this._isAgent=!0,this.config={},this.log=new cs,this.#f=[],this.#h=[],this.#m=new ss({expirationTime:5*Ga}),this.#_=!0,this.#w=(o,i)=>{if(this.#_===!1)return o;let{status:s,signatures:a=[],requestId:c}=o;for(let u of a){let{timestamp:p,identity:d}=u,l=M.fromUint8Array(d).toText(),f;if(s===fr.Replied){let{reply:x}=o;f=So({status:s,reply:x,timestamp:BigInt(p),request_id:c})}else if(s===fr.Rejected){let{reject_code:x,reject_message:y,error_code:T}=o;f=So({status:s,reject_code:x,reject_message:y,error_code:T,timestamp:BigInt(p),request_id:c})}else throw ge.fromCode(new Be(`Unknown status: ${s}`));let h=j(ea,f),m=i.nodeKeys.get(l);if(!m)throw ne.fromCode(new Ai);let g=as.fromDer(m).rawKey;if(Me.verify(u.signature,h,g))return o;throw Pe.fromCode(new Si(l))}return o},this.config=t,this.#o=t.fetch||Qh()||fetch.bind(global),this.#a=t.fetchOptions,this.#x=t.callOptions,this.#t=t.shouldFetchRootKey??!1,this.#u=t.shouldSyncTime??!1,t.rootKey?this.rootKey=t.rootKey:this.#t?this.rootKey=null:this.rootKey=Ne(Hh);let r=em(t.host);this.host=new URL(r),t.verifyQuerySignatures!==void 0&&(this.#_=t.verifyQuerySignatures),this.#d=t.retryTimes??3;let n=()=>new ls({maxIterations:this.#d});if(this.#p=t.backoffStrategy||n,this.host.hostname.endsWith(Gh)?this.host.hostname=$h:this.host.hostname.endsWith(zh)?this.host.hostname=Jh:this.host.hostname.endsWith(Yh)&&(this.host.hostname=Wh),t.credentials){let{name:o,password:i}=t.credentials;this.#i=`${o}${i?":"+i:""}`}if(this.#n=Promise.resolve(t.identity||new rt),t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes>5)throw z.fromCode(new hn("The maximum ingress expiry time is 5 minutes.",t.ingressExpiryInMinutes));if(t.ingressExpiryInMinutes&&t.ingressExpiryInMinutes<=0)throw z.fromCode(new hn("Ingress expiry time must be greater than 0.",t.ingressExpiryInMinutes));this.#l=t.ingressExpiryInMinutes||5,this.addTransform("update",aa(ko)),t.useQueryNonces&&this.addTransform("query",aa(ko)),t.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(t={}){return new this({...t})}static async create(t={}){let r=e.createSync(t);return await r.#g(),r}static async from(t){try{return"config"in t?await e.create(t.config):await e.create({fetch:t._fetch,fetchOptions:t._fetchOptions,callOptions:t._callOptions,host:t._host.toString(),identity:t._identity??void 0})}catch{throw z.fromCode(new Ri)}}isLocal(){let t=this.host.hostname;return t==="127.0.0.1"||t.endsWith("127.0.0.1")}addTransform(t,r,n=r.priority||0){if(t==="update"){let o=this.#h.findIndex(i=>(i.priority||0)<n);this.#h.splice(o>=0?o:this.#h.length,0,Object.assign(r,{priority:n}))}else if(t==="query"){let o=this.#f.findIndex(i=>(i.priority||0)<n);this.#f.splice(o>=0?o:this.#f.length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!this.#n)throw Oe.fromCode(new xr);return(await this.#n).getPrincipal()}async call(t,r,n){let o=r.callSync??!0,i=await(n??this.#n);if(!i)throw Oe.fromCode(new xr);let s=M.from(t),a=r.effectiveCanisterId?M.from(r.effectiveCanisterId):s;await this.#g(a);let c=i.getPrincipal(),u=$a(this.#l,this.#r),p={request_type:Ki.Call,canister_id:s,method_name:r.methodName,arg:r.arg,sender:c,ingress_expiry:u},d=await this._transform({request:{body:null,method:"POST",headers:{"Content-Type":"application/cbor",...this.#i?{Authorization:"Basic "+btoa(this.#i)}:{}}},endpoint:Qt.Call,body:p}),l;r?.nonce?l=f(r.nonce):d.body.nonce?l=f(d.body.nonce):l=void 0,p.nonce=l;function f(_){return Object.assign(_,{__nonce__:void 0})}d=await i.transformRequest(d);let h=Do(d.body),m=this.#p(),g=Zt(p);try{let y=o?()=>(this.log.print(`fetching "/api/v3/canister/${a.toText()}/call" with request:`,d),this.#o(""+new URL(`/api/v3/canister/${a.toText()}/call`,this.host),{...this.#x,...d.request,body:h})):()=>(this.log.print(`fetching "/api/v2/canister/${a.toText()}/call" with request:`,d),this.#o(""+new URL(`/api/v2/canister/${a.toText()}/call`,this.host),{...this.#x,...d.request,body:h})),{responseBodyBytes:T,...E}=await this.#y({requestFn:y,backoff:m,tries:0}),O=T.byteLength>0?Je(T):null;return{requestId:g,response:{...E,body:O},requestDetails:p}}catch(_){let x;if(_ instanceof ht){if(_.hasCode(bo))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(t,{...r,callSync:!1},n);if(_.hasCode(hn)&&!this.#c)return await this.syncTime(s),this.call(s,r,n);_.code.requestContext={requestId:g,senderPubKey:d.body.sender_pubkey,senderSignature:d.body.sender_sig,ingressExpiry:d.body.content.ingress_expiry},x=_}else x=ge.fromCode(new Be(_));throw this.log.error(`Error while making call: ${x.message}`,x),x}}async#b(t){let{ecid:r,transformedRequest:n,body:o,requestId:i,backoff:s,tries:a}=t,c=a===0?0:s.next();if(this.log.print(`fetching "/api/v2/canister/${r.toString()}/query" with tries:`,{tries:a,backoff:s,delay:c}),c===null)throw ge.fromCode(new fn(`Backoff strategy exhausted after ${a} attempts.`,i));c>0&&await new Promise(f=>setTimeout(f,c));let u;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===Ha)u={...Je(Hn(await f.arrayBuffer())),httpDetails:{ok:f.ok,status:f.status,statusText:f.statusText,headers:$i(f.headers)},requestId:i};else throw ne.fromCode(new xo(f.status,f.statusText,$i(f.headers),await f.text()))}catch(f){if(a<this.#d)return this.log.warn(`Caught exception while attempting to make query:
51
51
  ${f}
52
- Retrying query.`),await this.#b({...t,tries:a+1});throw f instanceof ot?f:Dn.fromCode(new qn(f))}if(!this.#_)return u;let p=u.signatures?.[0]?.timestamp;if(!p)throw te.fromCode(new Wo("Timestamp not found in query response. This suggests a malformed or malicious response."));let d=Number(BigInt(p)/BigInt(hh));if(Date.now()+this.#r-d>this.#N){if(a<this.#d)return this.log.warn("Timestamp is older than the max ingress expiry. Retrying query.",{requestId:i,signatureTimestampMs:d}),await this.#b({...t,tries:a+1});throw Ve.fromCode(new Ko(this.#l,i,a))}return u}async#y(t){let{requestFn:r,backoff:n,tries:o}=t,i=o===0?0:n.next();if(i===null)throw te.fromCode(new Er(`Retry strategy exhausted after ${o} attempts.`));i>0&&await new Promise(p=>setTimeout(p,i));let s,a=new Uint8Array;try{s=await r(),s.status===qa&&(a=cn(await s.clone().arrayBuffer()))}catch(p){if(o<this.#d)return this.log.warn(`Caught exception while attempting to make request:
52
+ Retrying query.`),await this.#b({...t,tries:a+1});throw f instanceof ht?f:yo.fromCode(new wo(f))}if(!this.#_)return u;let p=u.signatures?.[0]?.timestamp;if(!p)throw ne.fromCode(new vi("Timestamp not found in query response. This suggests a malformed or malicious response."));let d=Number(BigInt(p)/BigInt(jh));if(Date.now()+this.#r-d>this.#N){if(a<this.#d)return this.log.warn("Timestamp is older than the max ingress expiry. Retrying query.",{requestId:i,signatureTimestampMs:d}),await this.#b({...t,tries:a+1});throw Pe.fromCode(new wi(this.#l,i,a))}return u}async#y(t){let{requestFn:r,backoff:n,tries:o}=t,i=o===0?0:n.next();if(i===null)throw ne.fromCode(new fn(`Retry strategy exhausted after ${o} attempts.`));i>0&&await new Promise(p=>setTimeout(p,i));let s,a=new Uint8Array;try{s=await r(),s.status===Ha&&(a=Hn(await s.clone().arrayBuffer()))}catch(p){if(o<this.#d)return this.log.warn(`Caught exception while attempting to make request:
53
53
  ${p}
54
- Retrying request.`),await this.#y({requestFn:r,backoff:n,tries:o+1});throw Dn.fromCode(new qn(p))}let c=fi(s.headers);if(s.status===qa||s.status===Nh)return{ok:s.ok,status:s.status,statusText:s.statusText,responseBodyBytes:a,headers:c};let u=await s.text();if(s.status===Oh&&s.url.includes("api/v3"))throw te.fromCode(new Ln);if(u.startsWith("Invalid request expiry: "))throw z.fromCode(new Rr(u,this.#l));if(o<this.#d)return await this.#y({requestFn:r,backoff:n,tries:o+1});throw te.fromCode(new kn(s.status,s.statusText,c,u))}async query(t,r,n){let o=this.#p(),i=r.effectiveCanisterId?L.from(r.effectiveCanisterId):L.from(t);await this.#g(i),this.log.print(`ecid ${i.toString()}`),this.log.print(`canisterId ${t.toString()}`);let s,a=await(n??this.#n);if(!a)throw we.fromCode(new er);let c=L.from(t),u=a.getPrincipal(),p=Ma(this.#l,this.#r),d={request_type:Pr.Query,canister_id:c,method_name:r.methodName,arg:r.arg,sender:u,ingress_expiry:p},l=Dt(d);s=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#i?{Authorization:"Basic "+btoa(this.#i)}:{}}},endpoint:kt.Query,body:d}),s=await a.transformRequest(s);let f=to(s.body),h={canister:c.toText(),ecid:i,transformedRequest:s,body:f,requestId:l,backoff:o,tries:0},m=async()=>{let _=await this.#b(h);return{requestDetails:d,..._}},g=async()=>{let _=this.#m.get(i.toString());if(_)return _;await this.fetchSubnetKeys(i.toString());let x=this.#m.get(i.toString());if(!x)throw Ve.fromCode(new Yo);return x};try{if(!this.#_)return await m();let[_,x]=await Promise.all([m(),g()]);try{return this.#T(_,x)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),this.#m.delete(i.toString());let y=await g();return this.#T(_,y)}}catch(_){let x;throw _ instanceof ot?(_.code.requestContext={requestId:l,senderPubKey:s.body.sender_pubkey,senderSignature:s.body.sender_sig,ingressExpiry:s.body.content.ingress_expiry},x=_):x=me.fromCode(new Pe(_)),this.log.error(`Error while making query: ${x.message}`,x),x}}#T;async createReadStateRequest(t,r){await this.#g();let n=await(r??this.#n);if(!n)throw we.fromCode(new er);let o=n.getPrincipal(),i=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#i?{Authorization:"Basic "+btoa(this.#i)}:{}}},endpoint:kt.ReadState,body:{request_type:Pr.ReadState,paths:t.paths,sender:o,ingress_expiry:Ma(this.#l,this.#r)}});return n.transformRequest(i)}async readState(t,r,n,o){await this.#w();let i=L.from(t);function s(p){for(let d of p.paths){let[l,f]=d,h=new TextEncoder().encode("request_status");if(Fr(l,h))return f}}let a,c;if(o)a=o,c=Dt(a);else{c=s(r);let p=await this.#n;if(!p)throw we.fromCode(new er);a=await this.createReadStateRequest(r,p)}this.log.print(`fetching "/api/v2/canister/${i}/read_state" with request:`,a);let u=this.#p();try{let{responseBodyBytes:p}=await this.#y({requestFn:()=>this.#o(""+new URL(`/api/v2/canister/${i.toString()}/read_state`,this.host),{...this.#a,...a.request,body:to(a.body)}),backoff:u,tries:0}),d=Me(p);return this.log.print("Read state response:",d),d}catch(p){let d;throw p instanceof ot?(p.code.requestContext={requestId:c,senderPubKey:a.body.sender_pubkey,senderSignature:a.body.sender_sig,ingressExpiry:a.body.content.ingress_expiry},d=p):d=me.fromCode(new Pe(p)),this.log.error(`Error while making read state: ${d.message}`,d),d}}parseTimeFromResponse(t){let r;if(t.certificate){let n=Me(t.certificate);if(n&&"tree"in n)r=n.tree;else throw te.fromCode(new tr("Could not decode time from response"));let o=qr(["time"],r);if(o.status!==Ke.Found)throw te.fromCode(new Vt("Time was not found in the response or was not in its expected format.",o.status));if(!(o.value instanceof Uint8Array)&&!ArrayBuffer.isView(o))throw te.fromCode(new Qr("Time was not in its expected format."));let i=xn(o.value);return this.log.print("Time from response:",i),this.log.print("Time from response in milliseconds:",i.getTime()),i.getTime()}else this.log.warn("No certificate found in response");return 0}async syncTime(t){this.#s=this.#s??(async()=>{await this.#w();let r=Date.now();try{t||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let n=t??L.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),o=e.createSync({identity:new Ye,host:this.host.toString(),fetch:this.#o,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),s=(await Promise.all(Array(3).fill(null).map(async()=>{let c=(await Va({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);s>0&&(this.#r=s-r,this.#c=!0,this.log.notify({message:`Syncing time: offset of ${this.#r}`,level:"info"}))}catch(n){let o=n instanceof ot?n:me.fromCode(new Pe(n));throw this.log.error("Caught exception while attempting to sync time",o),o}})(),await this.#s.finally(()=>{this.#s=null})}async status(){let t=this.#i?{Authorization:"Basic "+btoa(this.#i)}:{};this.log.print('fetching "/api/v2/status"');let r=this.#p(),{responseBodyBytes:n}=await this.#y({backoff:r,requestFn:()=>this.#o(""+new URL("/api/v2/status",this.host),{headers:t,...this.#a}),tries:0});return Me(n)}async fetchRootKey(){return this.#e=this.#e??(async()=>{let t=await this.status();return this.rootKey=t.root_key,this.rootKey})(),await this.#e.finally(()=>{this.#e=null})}async#g(t){await Promise.all([this.#w(),this.#O(t)])}async#w(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#t)await this.fetchRootKey();else throw we.fromCode(new mt(this.#t))}async#O(t){this.#u&&!this.hasSyncedTime()&&await this.syncTime(t)}invalidateIdentity(){this.#n=null}replaceIdentity(t){this.#n=Promise.resolve(t)}async fetchSubnetKeys(t){let r=L.from(t);await this.#g(r);let o=(await Va({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(t){let r=Promise.resolve(t);if(t.endpoint===kt.Call)for(let n of this.#h)r=r.then(o=>n(o).then(i=>i||o));else for(let n of this.#f)r=r.then(o=>n(o).then(i=>i||o));return r}getTimeDiffMsecs(){return this.#r}hasSyncedTime(){return this.#c}};function Ma(e,t){let r=e*ja;return pn.fromDeltaInMilliseconds(r,t)}var vh=300*1e3;function wu(){return Vh(Ah(Ih(),1e3),Fh(1e3,1.2),Sh(vh))}function Ih(){let e=!0;return async()=>e?(e=!1,!0):!1}function Ah(e,t){return async(r,n,o)=>{if(await e(r,n,o))return new Promise(i=>setTimeout(i,t))}}function Sh(e){let t=Date.now()+e;return async(r,n,o)=>{if(Date.now()>t)throw te.fromCode(new Er(`Request timed out after ${e} msec`,n,o))}}function Fh(e,t){let r=e;return()=>new Promise(n=>setTimeout(()=>{r*=t,n()},r))}function Vh(...e){return async(t,r,n)=>{for(let o of e)await o(t,r,n)}}var Ou={preSignReadStateRequest:!1};function Eu(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ka(e,t){return e!==null&&typeof e=="object"&&Eu(e,t)}function Ch(e,t){return Eu(e,t)&&typeof e[t]=="function"}function Nu(e){return Ka(e,"body")&&Ka(e.body,"content")&&e.body.content.request_type===Pr.ReadState&&Ka(e.body.content,"ingress_expiry")&&typeof e.body.content.ingress_expiry=="object"&&e.body.content.ingress_expiry!==null&&Ch(e.body.content.ingress_expiry,"toHash")}async function $a(e,t,r,n={}){let o=[Q("request_status"),r],i,s;if(n.preSignReadStateRequest??!1?(s=await Bh({paths:[o],agent:e,pollingOptions:n}),i=await e.readState(t,{paths:[o]},void 0,s)):i=await e.readState(t,{paths:[o]}),e.rootKey==null)throw we.fromCode(new mt);let c=await ur.create({certificate:i.certificate,rootKey:e.rootKey,canisterId:t,blsVerify:n.blsVerify,agent:e}),u=Fe(c.lookup_path([...o,Q("status")])),p;switch(typeof u>"u"?p=Tt.Unknown:p=new TextDecoder().decode(u),p){case Tt.Replied:return{reply:Fe(c.lookup_path([...o,"reply"])),certificate:c};case Tt.Received:case Tt.Unknown:case Tt.Processing:{let d=n.strategy??wu();return await d(t,r,p),$a(e,t,r,{...n,strategy:d,request:s})}case Tt.Rejected:{let d=new Uint8Array(Fe(c.lookup_path([...o,"reject_code"])))[0],l=new TextDecoder().decode(Fe(c.lookup_path([...o,"reject_message"]))),f=Fe(c.lookup_path([...o,"error_code"])),h=f?new TextDecoder().decode(f):void 0;throw Xt.fromCode(new tn(r,d,l,h))}case Tt.Done:throw me.fromCode(new Go(r))}throw rr}async function Bh(e){let{paths:t,agent:r,pollingOptions:n}=e;if(n.request&&Nu(n.request))return n.request;let o=await r.createReadStateRequest?.({paths:t},void 0);if(!Nu(o))throw z.fromCode(new Qo(o));return o}var et=Symbol.for("ic-agent-metadata"),Vi=class e{static agentOf(t){return t[et].config.agent}static interfaceOf(t){return t[et].service}static canisterIdOf(t){return L.from(t[et].config.canisterId)}static createActorClass(t,r){let n=t({IDL:Sr});class o extends e{constructor(s){if(!s.canisterId)throw z.fromCode(new Mn(s.canisterId));let a=typeof s.canisterId=="string"?L.fromText(s.canisterId):s.canisterId;super({config:{...Ru,...s,canisterId:a},service:n});for(let[c,u]of n._fields)r?.httpDetails&&u.annotations.push(Ha),r?.certificate&&u.annotations.push(vu),this[c]=Uh(this,c,u,s.blsVerify)}}return o}static createActor(t,r){if(!r.canisterId)throw z.fromCode(new Mn(r.canisterId));return new(this.createActorClass(t))(r)}static createActorWithHttpDetails(t,r){return new(this.createActorClass(t,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(t,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(t,n))(r)}constructor(t){this[et]=Object.freeze(t)}};function Tn(e,t){let r=Sr.decode(e,t);switch(r.length){case 0:return;case 1:return r[0];default:return r}}var Ru={pollingOptions:Ou},Ha="http-details",vu="certificate";function Uh(e,t,r,n){let o;r.annotations.includes("query")||r.annotations.includes("composite_query")?o=async(s,...a)=>{s={...s,...e[et].config.queryTransform?.(t,a,{...e[et].config,...s})};let c=s.agent||e[et].config.agent||new $r,u=L.from(s.canisterId||e[et].config.canisterId),p=Sr.encode(r.argTypes,a),d=await c.query(u,{methodName:t,arg:p,effectiveCanisterId:s.effectiveCanisterId}),l={...d.httpDetails,requestDetails:d.requestDetails};switch(d.status){case zt.Rejected:{let f=new $o(d.requestId,d.reject_code,d.reject_message,d.error_code,d.signatures);throw f.callContext={canisterId:u,methodName:t,httpDetails:l},Xt.fromCode(f)}case zt.Replied:return r.annotations.includes(Ha)?{httpDetails:l,result:Tn(r.retTypes,d.reply.arg)}:Tn(r.retTypes,d.reply.arg)}}:o=async(s,...a)=>{s={...s,...e[et].config.callTransform?.(t,a,{...e[et].config,...s})};let c=s.agent||e[et].config.agent||$r.createSync(),{canisterId:u,effectiveCanisterId:p,pollingOptions:d}={...Ru,...e[et].config,...s},l=L.from(u),f=p!==void 0?L.from(p):l,h=Sr.encode(r.argTypes,a),{requestId:m,response:g,requestDetails:_}=await c.call(l,{methodName:t,arg:h,effectiveCanisterId:f,nonce:s.nonce}),x,y;if(Tc(g.body)){if(c.rootKey==null)throw we.fromCode(new mt);let R=g.body.certificate;y=await ur.create({certificate:R,rootKey:c.rootKey,canisterId:f,blsVerify:n,agent:c});let I=[Q("request_status"),m];switch(new TextDecoder().decode(Fe(y.lookup_path([...I,"status"])))){case"replied":x=Fe(y.lookup_path([...I,"reply"]));break;case"rejected":{let v=new Uint8Array(Fe(y.lookup_path([...I,"reject_code"])))[0],F=new TextDecoder().decode(Fe(y.lookup_path([...I,"reject_message"]))),S=Fe(y.lookup_path([...I,"error_code"])),b=S?new TextDecoder().decode(S):void 0,N=new tn(m,v,F,b);throw N.callContext={canisterId:l,methodName:t,httpDetails:g},Xt.fromCode(N)}}}else if(bc(g.body)){let{reject_code:R,reject_message:I,error_code:T}=g.body,v=new Ho(m,R,I,T);throw v.callContext={canisterId:l,methodName:t,httpDetails:g},Xt.fromCode(v)}if(g.status===202){let R={...d,blsVerify:n},I=await $a(c,f,m,R);y=I.certificate,x=I.reply}let w=r.annotations.includes(Ha),E=r.annotations.includes(vu),O={...g,requestDetails:_};if(x!==void 0)return w&&E?{httpDetails:O,certificate:y,result:Tn(r.retTypes,x)}:E?{certificate:y,result:Tn(r.retTypes,x)}:w?{httpDetails:O,result:Tn(r.retTypes,x)}:Tn(r.retTypes,x);{let R=new Pe(`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${r.retTypes.map(I=>I.display()).join(",")}].`);throw R.callContext={canisterId:l,methodName:t,httpDetails:O},me.fromCode(R)}};let i=(...s)=>o({},...s);return i.withOptions=s=>(...a)=>o(s,...a),i}var kh=(e=>(e[e.FractionalMoreThan8Decimals=0]="FractionalMoreThan8Decimals",e[e.InvalidFormat=1]="InvalidFormat",e[e.FractionalTooManyDecimals=2]="FractionalTooManyDecimals",e))(kh||{}),Sg=BigInt(1e8);var $=e=>e==null,X=e=>!$(e),Lh=e=>X(e)&&e!=="",Au=e=>!Lh(e);var qh=class extends Error{},xo=(e,t)=>{if(e==null)throw new qh(t)};var Hr=e=>new Uint8Array(e),Pi=e=>Array.from(e);var Su=({a:e,b:t})=>e.length===t.length&&e.every((r,n)=>r===t[n]);var Iu="abcdefghijklmnopqrstuvwxyz234567",go=Object.create(null);for(let e=0;e<Iu.length;e++)go[Iu[e]]=e;go[0]=go.o;go[1]=go.i;var Ci=e=>btoa(String.fromCharCode(...new Uint8Array(e)));var Fg=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]);var Ga="__bigint__",Ja="__principal__",za="__uint8array__",Fu=(e,t)=>typeof t=="bigint"?{[Ga]:`${t}`}:X(t)&&L.isPrincipal(t)?{[Ja]:L.from(t).toText()}:X(t)&&t instanceof Uint8Array?{[za]:Array.from(t)}:t,Vu=(e,t)=>{let r=n=>t[n];return X(t)&&typeof t=="object"&&Ga in t?BigInt(r(Ga)):X(t)&&typeof t=="object"&&Ja in t?L.fromText(r(Ja)):X(t)&&typeof t=="object"&&za in t?Uint8Array.from(r(za)):t};var ae=e=>X(e)?[e]:[],Ee=e=>e?.[0];var Mh=({authData:e})=>{if(e.byteLength<37)return{invalidAuthData:null};if(e.byteLength<53)return{invalidAuthData:null};let t=e.slice(37,53),r=jh({bytes:t});return"aaguid"in r?{aaguidBytes:t,aaguidText:r.aaguid}:{unknownProvider:null}},jh=({bytes:e})=>{if(e.length!==16)return{invalidBytes:null};let t=(e instanceof Uint8Array?Pi(e):e).map(r=>r.toString(16).padStart(2,"0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5");return t==="00000000-0000-0000-0000-000000000000"?{unknownProvider:null}:{aaguid:t}};function Kh(e){let t=new DataView(new ArrayBuffer(2)),r=e.slice(53,55);[...new Uint8Array(r)].forEach((o,i)=>t.setUint8(i,o));let n=t.getUint16(0);return e.slice(55+n)}function $h(e){return jr(e,yo)}var Hh=class{constructor(e){this._cose=e,this.#e=$h(e)}#e;toDer(){return this.#e}toRaw(){return new Uint8Array(this.#e)}},Uu=class{#e;#t;constructor({rawId:e,cose:t}){this.#e=e,this.#t=new Hh(t)}getPublicKey(){return this.#t}getCredentialId(){return this.#e}getCredentialIdText(){return Ci(this.#e)}},Gh=class extends Uu{#e;#t;constructor({authData:e,...t}){super(t);let r=Mh({authData:e});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}},Jh=class extends Uu{},zh=class extends Error{},Wh=class extends Error{},Yh=class extends Error{},Zh=class extends Error{},Xh=class extends Error{},Qh=class extends Error{},em=class extends Error{},Pu=class extends Error{};var tm={ECDSA_WITH_SHA256:-7,RSA_WITH_SHA256:-257},rm=6e4,ku=()=>window.crypto.getRandomValues(new Uint8Array(16)),nm=()=>ku(),om=()=>ku(),im=()=>{let{location:{href:e}}=window;try{let{hostname:t}=new URL(e);return t}catch{throw new zh}},Lu=({appId:e})=>e?.id??im(),sm=({appId:e,user:t}={})=>{let{document:{title:r}}=window,n=()=>({rp:{name:e?.name??r,id:Lu({appId:e})}}),o=()=>({user:{id:om(),name:t?.name??t?.displayName??r,displayName:t?.displayName??r}});return{attestation:"direct",challenge:nm(),...n(),...o(),pubKeyCredParams:Object.values(tm).map(i=>({type:"public-key",alg:i})),excludeCredentials:[],authenticatorSelection:{authenticatorAttachment:"platform",userVerification:"preferred",residentKey:"required",requireResidentKey:!0}}},am=(e={})=>({rpId:Lu(e),allowCredentials:[],userVerification:"required"}),Wa=async({fn:e,step:t,onProgress:r})=>{r?.({step:t,state:"in_progress"});try{let n=await e();return r?.({step:t,state:"success"}),n}catch(n){throw r?.({step:t,state:"error"}),n}},fr=(e=>(e[e.RequestingUserCredential=0]="RequestingUserCredential",e[e.FinalizingCredential=1]="FinalizingCredential",e[e.Signing=2]="Signing",e))(fr||{}),qu=({timeout:e})=>AbortSignal.timeout(e??rm),cm=async({challenge:e,credentialIds:t,passkeyOptions:r,timeout:n})=>await navigator.credentials.get({publicKey:{...am(r),challenge:e.buffer,allowCredentials:(t??[]).map(o=>({id:o.buffer,type:"public-key"}))},signal:qu({timeout:n})}),Cu=e=>{if(e.status!=="initialized")throw new Wh},Bu=e=>{if($(e))throw new Yh},Du=({type:e})=>{if(e!=="public-key")throw new Zh},Ya=class bo extends bt{#e;#t;constructor({onProgress:t,...r}){if(super(),this.#e=t,"retrievePublicKey"in r){let{retrievePublicKey:n}=r;this.#t={status:"pending",retrievePublicKey:n};return}this.#t=bo.#r({credential:new Gh(r)})}static#r({credential:t}){return{status:"initialized",credential:t}}static async createWithNewCredential({passkeyOptions:t,timeout:r,...n}={}){let o=await navigator.credentials.create({publicKey:sm(t),signal:qu({timeout:r})});Bu(o),Du(o);let{response:{attestationObject:i},rawId:s}=o;if($(i))throw new Xh;let{authData:a}=ui.decode(Hr(i)),c=Kh(a);return new bo({...n,rawId:Hr(s),cose:c,authData:a})}static async createWithExistingCredential(t){return new bo(t)}getPublicKey(){Cu(this.#t);let{credential:t}=this.#t;return t.getPublicKey()}getCredential(){Cu(this.#t);let{credential:t}=this.#t;return t}async sign(t){let r=await Wa({fn:async()=>{let n=await cm({challenge:t,...this.#t.status==="initialized"&&{credentialIds:[this.#t.credential.getCredentialId()]}});return Bu(n),Du(n),n},step:0,onProgress:this.#e});return await Wa({fn:async()=>{let{rawId:n}=r;if(this.#t.status==="initialized"){if(!Su({a:this.#t.credential.getCredentialId(),b:Hr(n)}))throw new Qh;return}let{retrievePublicKey:o}=this.#t,i=await o({credentialId:Hr(n)});this.#t=bo.#r({credential:new Jh({rawId:Hr(n),cose:i})})},step:1,onProgress:this.#e}),await Wa({fn:async()=>{let{response:n}=r,{clientDataJSON:o}=n,{authenticatorData:i,signature:s}="authenticatorData"in n&&"signature"in n?n:{};if($(i))throw new Pu;if($(s))throw new Pu;let a=ui.encode({authenticator_data:i,client_data_json:new TextDecoder().decode(o),signature:Hr(s)});if($(a))throw new em;return Object.assign(a,{__signature__:void 0}),a},step:2,onProgress:this.#e})}},lm=async()=>X(window.PublicKeyCredential)&&"isUserVerifyingPlatformAuthenticatorAvailable"in PublicKeyCredential?await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():!1;var wn=class{callbacks=[];populate(t){this.callbacks.forEach(({callback:r})=>r(t))}subscribe(t){let r=Symbol();return this.callbacks.push({id:r,callback:t}),()=>this.callbacks=this.callbacks.filter(({id:n})=>n!==r)}};var tt=class e extends wn{static instance;authUser=null;constructor(){super()}static getInstance(){return e.instance||(e.instance=new e),e.instance}set(t){this.authUser=t,this.populate(t)}get(){return this.authUser}subscribe(t){let r=super.subscribe(t);return t(this.authUser),r}reset(){this.authUser=null,this.populate(this.authUser)}};var Za=({message:e,detail:t})=>{let r=new CustomEvent(e,{detail:t,bubbles:!0});document.dispatchEvent(r)};var Nn="http://127.0.0.1:5987",Mu="rdmx6-jaaaa-aaaaa-aaadq-cai";var ju=async({identity:e,container:t})=>{let n=X(t)&&t!==!1?t===!0?Nn:t:"https://icp-api.io",o=X(t);return await $r.create({identity:e,shouldFetchRootKey:o,host:n})};var On=class e{static instance;#e=void 0;constructor(){}static getInstance(){return $(e.instance)&&(e.instance=new e),e.instance}async getAgent({identity:t,...r}){let n=t.getPrincipal().toText();if($(this.#e)||$(this.#e[n])){let o=await ju({identity:t,...r});return this.#e={...this.#e??{},[n]:o},o}return this.#e[n]}reset(){this.#e=null}};var En=class e{static instance;#e=void 0;constructor(){}static getInstance(){return $(e.instance)&&(e.instance=new e),e.instance}async getActor({satelliteId:t,identity:r,actorKey:n,...o}){let i=`${n}#${r.getPrincipal().toText()}#${t};`;if($(this.#e)||$(this.#e[i])){let s=await this.createActor({satelliteId:t,identity:r,...o});return this.#e={...this.#e??{},[i]:s},s}return this.#e[i]}reset(){this.#e=null}async createActor({idlFactory:t,satelliteId:r,...n}){let o=await On.getInstance().getAgent(n);return Vi.createActor(t,{agent:o,canisterId:r})}};var Ku=e=>(e.preventDefault(),e.returnValue="Are you sure you want to exit?"),um=()=>{window.addEventListener("beforeunload",Ku,{capture:!0})},dm=()=>{window.removeEventListener("beforeunload",Ku,{capture:!0})},Xa=async({fn:e})=>{try{return um(),await e()}finally{dm()}};var Ge=class e extends wn{static instance;env;constructor(){super()}static getInstance(){return e.instance||(e.instance=new e),e.instance}set(t){this.env=t,this.populate(t)}get(){return this.env}reset(){this.env=null}subscribe(t){let r=super.subscribe(t);return t(this.env),r}};var $u=BigInt(144e11),Hu=!1,Gu={width:576,height:576},Ju={width:424,height:576},zu={width:505,height:705},To="internetcomputer.org",Wu="ic0.app",Yu="id.ai";var Zu=async e=>{let t=new Blob([JSON.stringify(e,Fu)],{type:"application/json; charset=utf-8"});return new Uint8Array(await t.arrayBuffer())},Bi=async e=>{let t=new Blob([e instanceof Uint8Array?e:new Uint8Array(e)],{type:"application/json; charset=utf-8"});return JSON.parse(await t.text(),Vu)},Di=()=>typeof window<"u";var Ui=({width:e,height:t})=>{if(!Di()||$(window)||$(window.top))return;let{top:{innerWidth:r,innerHeight:n}}=window,o=n/2+screenY-t/2,i=r/2+screenX-e/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${e}, height=${t}, top=${o}, left=${i}`};function Xu(e){return e!==null&&typeof e=="object"}var wo=class e{static from(t){if(typeof t=="string"){let r=Te(t);return this.fromRaw(r)}else if(Xu(t)){let r=t;if(Xu(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(_t(n.buffer))}else{if(r instanceof ArrayBuffer)return this.fromRaw(_t(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(t){return new e(t)}static fromDer(t){return new e(this.derDecode(t))}static{this.RAW_KEY_LENGTH=32}static derEncode(t){let r=jr(t,Mr);return r.__derEncodedPublicKey__=void 0,r}static derDecode(t){let r=Kr(t,Mr);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(t){if(t.byteLength!==e.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");this.#e=t,this.#t=e.derEncode(t)}toDer(){return this.derKey}toRaw(){return this.rawKey}},Gr=class e extends bt{static generate(t){if(t&&t.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");t||(t=Le.utils.randomPrivateKey()),jc(t,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]=t[o];let n=Le.getPublicKey(r);return e.fromKeyPair(n,r)}static fromParsedJson(t){let[r,n]=t;return new e(wo.fromDer(Te(r)),Te(n))}static fromJSON(t){let r=JSON.parse(t);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(t)}`)}static fromKeyPair(t,r){return new e(wo.fromRaw(t),r)}static fromSecretKey(t){let r=Le.getPublicKey(t);return e.fromKeyPair(r,t)}#e;#t;constructor(t,r){super(),this.#e=wo.from(t),this.#t=r}toJSON(){return[K(this.#e.toDer()),K(this.#t)]}getKeyPair(){return{secretKey:this.#t,publicKey:this.#e}}getPublicKey(){return this.#e}async sign(t){let r=Le.sign(t,this.#t.slice(0,32));return Object.defineProperty(r,"__signature__",{enumerable:!1,value:void 0}),r}static verify(t,r,n){let[o,i,s]=[t,r,n].map(a=>(typeof a=="string"&&(a=Te(a)),_t(a)));return Le.verify(o,i,s)}};var Qa=class e extends Error{constructor(t){super(t),this.message=t,Object.setPrototypeOf(this,e.prototype)}};function Qu(e){if(typeof global<"u"&&global.crypto&&global.crypto.subtle)return global.crypto.subtle;if(e)return e;if(typeof crypto<"u"&&crypto.subtle)return crypto.subtle;throw new Qa("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 hr=class e extends bt{static async generate(t){let{extractable:r=!1,keyUsages:n=["sign","verify"],subtleCrypto:o}=t??{},i=Qu(o),s=await i.generateKey({name:"ECDSA",namedCurve:"P-256"},r,n),a=_t(await i.exportKey("spki",s.publicKey));return Object.assign(a,{__derEncodedPublicKey__:void 0}),new this(s,a,i)}static async fromKeyPair(t,r){let n=Qu(r),o=_t(await n.exportKey("spki",t.publicKey));return Object.assign(o,{__derEncodedPublicKey__:void 0}),new e(t,o,n)}constructor(t,r,n){super(),this._keyPair=t,this._derKey=r,this._subtleCrypto=n}getKeyPair(){return this._keyPair}getPublicKey(){let t=this._derKey,r=Object.create(this._keyPair.publicKey);return r.toDer=function(){return t},r}async sign(t){let r={name:"ECDSA",hash:{name:"SHA-256"}},n=_t(await this._subtleCrypto.sign(r,this._keyPair.privateKey,t));return Object.assign(n,{__signature__:void 0}),n}};var ki=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 L.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(t){this.#e=t}};function Li(e){return e instanceof Uint8Array?K(e):K(new Uint8Array(e))}function ec(e){if(typeof e!="string"||e.length<64)throw new Error("Invalid public key.");return Te(e)}var Rn=class{constructor(t,r,n){this.pubkey=t,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:Li(this.pubkey),...this.targets&&{targets:this.targets.map(t=>t.toHex())}}}};async function pm(e,t,r,n){let o=new Rn(t.toDer(),BigInt(+r)*BigInt(1e6),n),i=new Uint8Array([...Zs,...new Uint8Array(Dt({...o}))]),s=await e.sign(i);return{delegation:o,signature:s}}var Jr=class e{static async create(t,r,n=new Date(Date.now()+900*1e3),o={}){let i=await pm(t,r,n,o.targets);return new e([...o.previous?.delegations||[],i],o.previous?.publicKey||t.getPublicKey().toDer())}static fromJSON(t){let{publicKey:r,delegations:n}=typeof t=="string"?JSON.parse(t):t;if(!Array.isArray(n))throw new Error("Invalid delegations.");let o=n.map(i=>{let{delegation:s,signature:a}=i,{pubkey:c,expiration:u,targets:p}=s;if(p!==void 0&&!Array.isArray(p))throw new Error("Invalid targets.");return{delegation:new Rn(ec(c),BigInt("0x"+u),p&&p.map(d=>{if(typeof d!="string")throw new Error("Invalid target.");return L.fromHex(d)})),signature:ec(a)}});return new this(o,ec(r))}static fromDelegations(t,r){return new this(t,r)}constructor(t,r){this.delegations=t,this.publicKey=r}toJSON(){return{delegations:this.delegations.map(t=>{let{delegation:r,signature:n}=t,{targets:o}=r;return{delegation:{expiration:r.expiration.toString(16),pubkey:Li(r.pubkey),...o&&{targets:o.map(i=>i.toHex())}},signature:Li(n)}}),publicKey:Li(this.publicKey)}}},zr=class extends bt{static fromDelegation(t,r){return new this(t,r)}constructor(t,r){super(),this._inner=t,this._delegation=r}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(t){return this._inner.sign(t)}async transformRequest(t){let{body:r,...n}=t,o=await Dt(r);return{...n,body:{content:r,sender_sig:await this.sign(new Uint8Array([...Yn,...new Uint8Array(o)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}}}},No=class e extends ki{#e;get delegation(){return this.#e}constructor(t,r){super(t),this.#e=r}static fromDelegation(t,r){return new e(t,r)}};function tc(e,t){for(let{delegation:o}of e.delegations)if(+new Date(Number(o.expiration/BigInt(1e6)))<=+Date.now())return!1;let r=[],n=t?.scope;n&&(Array.isArray(n)?r.push(...n.map(o=>typeof o=="string"?L.fromText(o):o)):r.push(typeof n=="string"?L.fromText(n):n));for(let o of r){let i=o.toText();for(let{delegation:s}of e.delegations){if(s.targets===void 0)continue;let a=!0;for(let c of s.targets)if(c.toText()===i){a=!1;break}if(a)return!1}}return!0}var ed=["mousedown","mousemove","keydown","touchstart","wheel"],Oo=class e{callbacks=[];idleTimeout=600*1e3;timeoutID=void 0;static create(t={}){return new e(t)}constructor(t={}){let{onIdle:r,idleTimeout:n=600*1e3}=t||{};this.callbacks=r?[r]:[],this.idleTimeout=n;let o=this._resetTimer.bind(this);window.addEventListener("load",o,!0),ed.forEach(s=>{document.addEventListener(s,o,!0)});let i=(s,a)=>{let c;return(...u)=>{let p=this,d=()=>{c=void 0,s.apply(p,u)};clearTimeout(c),c=window.setTimeout(d,a)}};if(t?.captureScroll){let s=i(o,t?.scrollDebounce??100);window.addEventListener("scroll",s,!0)}o()}registerCallback(t){this.callbacks.push(t)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let t=this._resetTimer.bind(this);ed.forEach(r=>{document.removeEventListener(r,t,!0)}),this.callbacks.forEach(r=>{r()})}_resetTimer(){let t=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(t,this.idleTimeout)}};var fm=(e,t)=>t.some(r=>e instanceof r),td,rd;function hm(){return td||(td=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function mm(){return rd||(rd=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var nd=new WeakMap,nc=new WeakMap,od=new WeakMap,rc=new WeakMap,ic=new WeakMap;function _m(e){let t=new Promise((r,n)=>{let o=()=>{e.removeEventListener("success",i),e.removeEventListener("error",s)},i=()=>{r(wt(e.result)),o()},s=()=>{n(e.error),o()};e.addEventListener("success",i),e.addEventListener("error",s)});return t.then(r=>{r instanceof IDBCursor&&nd.set(r,e)}).catch(()=>{}),ic.set(t,e),t}function ym(e){if(nc.has(e))return;let t=new Promise((r,n)=>{let o=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",s),e.removeEventListener("abort",s)},i=()=>{r(),o()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),o()};e.addEventListener("complete",i),e.addEventListener("error",s),e.addEventListener("abort",s)});nc.set(e,t)}var oc={get(e,t,r){if(e instanceof IDBTransaction){if(t==="done")return nc.get(e);if(t==="objectStoreNames")return e.objectStoreNames||od.get(e);if(t==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return wt(e[t])},set(e,t,r){return e[t]=r,!0},has(e,t){return e instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in e}};function id(e){oc=e(oc)}function gm(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(t,...r){let n=e.call(qi(this),t,...r);return od.set(n,t.sort?t.sort():[t]),wt(n)}:mm().includes(e)?function(...t){return e.apply(qi(this),t),wt(nd.get(this))}:function(...t){return wt(e.apply(qi(this),t))}}function xm(e){return typeof e=="function"?gm(e):(e instanceof IDBTransaction&&ym(e),fm(e,hm())?new Proxy(e,oc):e)}function wt(e){if(e instanceof IDBRequest)return _m(e);if(rc.has(e))return rc.get(e);let t=xm(e);return t!==e&&(rc.set(e,t),ic.set(t,e)),t}var qi=e=>ic.get(e);function ad(e,t,{blocked:r,upgrade:n,blocking:o,terminated:i}={}){let s=indexedDB.open(e,t),a=wt(s);return n&&s.addEventListener("upgradeneeded",c=>{n(wt(s.result),c.oldVersion,c.newVersion,wt(s.transaction),c)}),r&&s.addEventListener("blocked",c=>r(c.oldVersion,c.newVersion,c)),a.then(c=>{i&&c.addEventListener("close",()=>i()),o&&c.addEventListener("versionchange",u=>o(u.oldVersion,u.newVersion,u))}).catch(()=>{}),a}var bm=["get","getKey","getAll","getAllKeys","count"],Tm=["put","add","delete","clear"],sc=new Map;function sd(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(sc.get(t))return sc.get(t);let r=t.replace(/FromIndex$/,""),n=t!==r,o=Tm.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(o||bm.includes(r)))return;let i=async function(s,...a){let c=this.transaction(s,o?"readwrite":"readonly"),u=c.store;return n&&(u=u.index(a.shift())),(await Promise.all([u[r](...a),o&&c.done]))[0]};return sc.set(t,i),i}id(e=>({...e,get:(t,r,n)=>sd(t,r)||e.get(t,r,n),has:(t,r)=>!!sd(t,r)||e.has(t,r)}));var cd="auth-client-db",ld="ic-keyval",wm=async(e=cd,t=ld,r)=>(globalThis.localStorage?.getItem(Je)&&(globalThis.localStorage.removeItem(Je),globalThis.localStorage.removeItem($e)),await ad(e,r,{upgrade:n=>{n.objectStoreNames.contains(t)&&n.clear(t),n.createObjectStore(t)}}));async function Nm(e,t,r){return await e.get(t,r)}async function Om(e,t,r,n){return await e.put(t,n,r)}async function Em(e,t,r){return await e.delete(t,r)}var Mi=class e{constructor(t,r){this._db=t,this._storeName=r}static async create(t){let{dbName:r=cd,storeName:n=ld,version:o=ud}=t??{},i=await wm(r,n,o);return new e(i,n)}async set(t,r){return await Om(this._db,this._storeName,t,r)}async get(t){return await Nm(this._db,this._storeName,t)??null}async remove(t){return await Em(this._db,this._storeName,t)}};var $e="identity",Je="delegation",dd="iv",ud=1,Eo=class{constructor(t="ic-",r){this.prefix=t,this._localStorage=r}get(t){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+t))}set(t,r){return this._getLocalStorage().setItem(this.prefix+t,r),Promise.resolve()}remove(t){return this._getLocalStorage().removeItem(this.prefix+t),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let t=globalThis.localStorage;if(!t)throw new Error("Could not find local storage.");return t}},Jt=class{#e;constructor(t){this.#e=t??{}}initializedDb;get _db(){return new Promise((t,r)=>{if(this.initializedDb){t(this.initializedDb);return}Mi.create(this.#e).then(n=>{this.initializedDb=n,t(n)}).catch(r)})}async get(t){return await(await this._db).get(t)}async set(t,r){await(await this._db).set(t,r)}async remove(t){await(await this._db).remove(t)}};var Rm=BigInt(1e9),vm=BigInt(3600),Im=Rm*vm,Am="https://identity.internetcomputer.org",Sm="#authorize",Fm=BigInt(8)*Im,ac="ECDSA",cc="Ed25519",Vm=500,ji="UserInterrupt",Ro=class e{constructor(t,r,n,o,i,s,a,c){this._identity=t,this._key=r,this._chain=n,this._storage=o,this.idleManager=i,this._createOptions=s,this._idpWindow=a,this._eventHandler=c,this._registerDefaultIdleCallback()}static async create(t={}){let r=t.storage??new Jt,n=t.keyType??ac,o=null;if(t.identity)o=t.identity;else{let c=await r.get($e);if(!c)try{let u=new Eo,p=await u.get(Je),d=await u.get($e);p&&d&&n===ac&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await r.set(Je,p),await r.set($e,d),c=p,await u.remove(Je),await u.remove($e))}catch(u){console.error(`error while attempting to recover localstorage: ${u}`)}if(c)try{typeof c=="object"?n===cc&&typeof c=="string"?o=Gr.fromJSON(c):o=await hr.fromKeyPair(c):typeof c=="string"&&(o=Gr.fromJSON(c))}catch{}}let i=new Ye,s=null;if(o)try{let c=await r.get(Je);if(typeof c=="object"&&c!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");t.identity?i=t.identity:c&&(s=Jr.fromJSON(c),tc(s)?"toDer"in o?i=No.fromDelegation(o,s):i=zr.fromDelegation(o,s):(await lc(r),o=null))}catch(c){console.error(c),await lc(r),o=null}let a;return t.idleOptions?.disableIdle?a=void 0:(s||t.identity)&&(a=Oo.create(t.idleOptions)),o||(n===cc?o=Gr.generate():(t.storage&&n===ac&&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 '${cc}' as the key type, as it can serialize to a string`),o=await hr.generate()),await pd(r,o)),new e(i,o,s,r,a,t)}_registerDefaultIdleCallback(){let t=this._createOptions?.idleOptions;!t?.onIdle&&!t?.disableDefaultIdleCallback&&this.idleManager?.registerCallback(()=>{this.logout(),location.reload()})}async _handleSuccess(t,r){let n=t.delegations.map(a=>({delegation:new Rn(a.delegation.pubkey,a.delegation.expiration,a.delegation.targets),signature:a.signature})),o=Jr.fromDelegations(n,t.userPublicKey),i=this._key;if(!i)return;this._chain=o,"toDer"in i?this._identity=No.fromDelegation(i,this._chain):this._identity=zr.fromDelegation(i,this._chain),this._idpWindow?.close();let s=this._createOptions?.idleOptions;!this.idleManager&&!s?.disableIdle&&(this.idleManager=Oo.create(s),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(Je,JSON.stringify(this._chain.toJSON())),await pd(this._storage,this._key),r?.(t)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null&&tc(this._chain)}async login(t){let r=Pm(this._createOptions?.loginOptions,t),n=r?.maxTimeToLive??Fm,o=new URL(r?.identityProvider?.toString()||Am);o.hash=Sm,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 i=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(ji,r?.onError):setTimeout(i,Vm))};i()}_getEventHandler(t,r){return async n=>{if(n.origin!==t.origin)return;let o=n.data;switch(o.kind){case"authorize-ready":{let i={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(i,t.origin);break}case"authorize-client-success":try{await this._handleSuccess(o,r?.onSuccess)}catch(i){this._handleFailure(i.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(o.text,r?.onError);break}}}_handleFailure(t,r){this._idpWindow?.close(),r?.(t),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(t={}){if(await lc(this._storage),this._identity=new Ye,this._chain=null,t.returnTo)try{window.history.pushState({},"",t.returnTo)}catch{window.location.href=t.returnTo}}};async function lc(e){await e.remove($e),await e.remove(Je),await e.remove(dd)}function Pm(e,t){if(!e&&!t)return;let r=e?.customValues||t?.customValues?{...e?.customValues,...t?.customValues}:void 0;return{...e,...t,customValues:r}}function Cm(e){if(e instanceof hr)return e.getKeyPair();if(e instanceof Gr)return JSON.stringify(e.toJSON());throw new Error("Unsupported key type")}async function pd(e,t){let r=Cm(t);await e.set($e,r)}var Nt=async({fn:e,step:t,onProgress:r})=>{r?.({step:t,state:"in_progress"});try{let n=await e();return r?.({step:t,state:"success"}),n}catch(n){throw r?.({step:t,state:"error"}),n}};var fd=(r=>(r[r.AuthorizingWithProvider=0]="AuthorizingWithProvider",r[r.CreatingOrRetrievingUser=1]="CreatingOrRetrievingUser",r))(fd||{});var Ki=class extends Error{},Wr=class extends Error{},$i=class extends Error{},Hi=class extends Error{},Gi=class extends Error{},Ji=class extends Error{},zi=class extends Error{},Wi=class extends Error{};var vn=class{async signIn({options:t,authClient:r,initAuth:n}){await Nt({fn:async()=>await this.#e({options:t,authClient:r}),step:0,onProgress:t?.onProgress}),await Nt({fn:async()=>await n({provider:this.id}),step:1,onProgress:t?.onProgress})}#e({options:t,authClient:r}){return new Promise(async(n,o)=>{if($(r)){o(new Wr("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}await r.login({onSuccess:n,onError:i=>{if(i===ji){o(new $i(i));return}o(new Ki(i))},maxTimeToLive:t?.maxTimeToLiveInNanoseconds??$u,allowPinAuthentication:t?.allowPin??Hu,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...this.signInOptions({windowed:t?.windowed})})})}};var Yi=class extends vn{#e;constructor({domain:t}){super(),this.#e=t}get id(){return"internet_identity"}signInOptions({windowed:t}){let n=(()=>{let i=Ge.getInstance().get()?.container;if($(i)||i===!1){let p=[To,Wu].includes(this.#e??To);return Au(this.#e)?`https://identity.${To}`:p?`https://identity.${this.#e??To}`:`https://${this.#e}`}let s=Ge.getInstance().get(),a=X(s)&&X(s?.internetIdentityId)?s.internetIdentityId:Mu,{host:c,protocol:u}=new URL(i===!0?Nn:i);return/apple/i.test(navigator?.vendor)?`${u}//${c}?canisterId=${a}`:`${u}//${a}.${c.replace("127.0.0.1","localhost")}`})();return{...t!==!1&&{windowOpenerFeatures:Ui((()=>{try{let{hostname:i}=new URL(n);return i.includes(Yu)}catch{return!1}})()?Ju:Gu)},identityProvider:n}}};var Zi=class extends vn{#e;#t;constructor({appName:t,logoUrl:r}){super(),this.#e=t,this.#t=r}get id(){return"nfid"}signInOptions({windowed:t}){return{...t!==!1&&{windowOpenerFeatures:Ui(zu)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#e)}&applicationLogo=${encodeURI(this.#t)}`}}};var Ot={certified:!1};var ce=e=>X(e)?e:Xi()??new Ye;var hd=({IDL:e})=>{let t=e.Variant({Heap:e.Null,Stable:e.Null}),r=e.Record({system_memory:e.Opt(t)}),n=e.Record({controllers:e.Vec(e.Principal),storage:e.Opt(r)}),o=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),i=e.Variant({OpenId:o}),s=e.Record({updated_at:e.Nat64,owner:e.Principal,data:e.Vec(e.Nat8),description:e.Opt(e.Text),created_at:e.Nat64,version:e.Opt(e.Nat64)}),a=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),c=e.Record({doc:s,delegation:a}),u=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),p=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),d=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),l=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,JwtVerify:p,GetOrFetchJwks:d,DeriveSeedFailed:e.Text}),f=e.Variant({PrepareDelegation:l,RegisterUser:e.Text}),h=e.Variant({Ok:c,Err:f}),m=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),g=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),_=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),x=e.Record({field:_,desc:e.Bool}),y=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),w=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(y),description:e.Opt(e.Text),created_at:e.Opt(y)}),E=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),O=e.Record({order:e.Opt(x),owner:e.Opt(e.Principal),matcher:e.Opt(w),paginate:e.Opt(E)}),R=e.Record({controllers:e.Vec(e.Principal)}),I=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),T=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,scope:I,expires_at:e.Opt(e.Nat64)}),v=e.Record({version:e.Opt(e.Nat64)}),F=e.Variant({Db:e.Null,Storage:e.Null}),S=e.Record({version:e.Opt(e.Nat64)}),b=e.Record({proposal_ids:e.Vec(e.Nat)}),N=e.Record({cycles:e.Nat,destination_id:e.Principal}),V=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),B=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),q=e.Record({key:V,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,B)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),A=e.Variant({Google:e.Null}),P=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),C=e.Record({delegation:e.Opt(P),client_id:e.Text}),U=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(A,C))}),k=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),ne=e.Record({allowed_callers:e.Vec(e.Principal)}),ee=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(U),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(k),rules:e.Opt(ne)}),J=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),he=e.Record({updated_at:e.Opt(e.Nat64),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(J)}),Re=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),ze=e.Variant({Deny:e.Null,Allow:e.Null}),le=e.Record({status_code:e.Nat16,location:e.Text}),be=e.Record({iframe:e.Opt(Re),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(J),raw_access:e.Opt(ze),redirects:e.Opt(e.Vec(e.Tuple(e.Text,le)))}),es=e.Record({db:e.Opt(he),authentication:e.Opt(ee),storage:be}),ts=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),rs=e.Variant({OpenId:ts}),ns=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),os=e.Record({signature:e.Vec(e.Nat8),delegation:ns}),is=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:p,GetOrFetchJwks:d,DeriveSeedFailed:e.Text}),ss=e.Variant({Ok:os,Err:is}),as=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),cs=e.Record({clear_existing_assets:e.Opt(e.Bool)}),ls=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),In=e.Variant({AssetsUpgrade:cs,SegmentsDeployment:ls}),Et=e.Record({status:as,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:In}),Rt=e.Variant({Controllers:e.Null,Private:e.Null,Public:e.Null,Managed:e.Null}),An=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),_r=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(t),updated_at:e.Nat64,max_size:e.Opt(e.Nat),read:Rt,created_at:e.Nat64,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(An),write:Rt,max_changes_per_user:e.Opt(e.Nat32)}),us=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),yr=e.Record({memory:t,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),ds=e.Variant({Callback:e.Record({token:yr,callback:e.Func([],[],["query"])})}),ps=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(ds),status_code:e.Nat16}),fs=e.Record({token:e.Opt(yr),body:e.Vec(e.Nat8)}),gr=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),xr=e.Record({batch_id:e.Nat}),hs=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,q)),items_length:e.Nat64}),ms=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),_s=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,s)),items_length:e.Nat64}),ys=e.Record({desc:e.Bool}),gs=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),xs=e.Record({order:e.Opt(ys),paginate:e.Opt(gs)}),bs=e.Record({proposal_id:e.Nat}),Ts=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(bs,Et)),items_length:e.Nat64}),ws=e.Record({include_system:e.Bool}),Ns=e.Record({matcher:e.Opt(ws)}),Os=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(e.Text,_r)),items_length:e.Nat64}),Es=e.Record({stable:e.Nat64,heap:e.Nat64}),Rs=e.Record({openid:e.Opt(U),version:e.Opt(e.Nat64),internet_identity:e.Opt(k),rules:e.Opt(ne)}),vs=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),scope:I,expires_at:e.Opt(e.Nat64)}),Is=e.Record({controller:vs,controllers:e.Vec(e.Principal)}),As=e.Record({version:e.Opt(e.Nat64),max_memory_size:e.Opt(J)}),Sn=e.Record({data:e.Vec(e.Nat8),description:e.Opt(e.Text),version:e.Opt(e.Nat64)}),Ss=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(t),max_size:e.Opt(e.Nat),read:Rt,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(An),write:Rt,max_changes_per_user:e.Opt(e.Nat32)}),Fs=e.Record({iframe:e.Opt(Re),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(J),raw_access:e.Opt(ze),redirects:e.Opt(e.Vec(e.Tuple(e.Text,le)))}),Fn=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),Vn=e.Record({chunk_id:e.Nat});return e.Service({authenticate:e.Func([i],[h],[]),commit_asset_upload:e.Func([m],[],[]),commit_proposal:e.Func([g],[e.Null],[]),commit_proposal_asset_upload:e.Func([m],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(m)],[],[]),count_assets:e.Func([e.Text,O],[e.Nat64],["query"]),count_collection_assets:e.Func([e.Text],[e.Nat64],["query"]),count_collection_docs:e.Func([e.Text],[e.Nat64],["query"]),count_docs:e.Func([e.Text,O],[e.Nat64],["query"]),count_proposals:e.Func([],[e.Nat64],["query"]),del_asset:e.Func([e.Text,e.Text],[],[]),del_assets:e.Func([e.Text],[],[]),del_controllers:e.Func([R],[e.Vec(e.Tuple(e.Principal,T))],[]),del_custom_domain:e.Func([e.Text],[],[]),del_doc:e.Func([e.Text,e.Text,v],[],[]),del_docs:e.Func([e.Text],[],[]),del_filtered_assets:e.Func([e.Text,O],[],[]),del_filtered_docs:e.Func([e.Text,O],[],[]),del_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[],[]),del_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,v))],[],[]),del_rule:e.Func([F,e.Text,S],[],[]),delete_proposal_assets:e.Func([b],[],[]),deposit_cycles:e.Func([N],[],[]),get_asset:e.Func([e.Text,e.Text],[e.Opt(q)],["query"]),get_auth_config:e.Func([],[e.Opt(ee)],["query"]),get_config:e.Func([],[es],[]),get_db_config:e.Func([],[e.Opt(he)],["query"]),get_delegation:e.Func([rs],[ss],["query"]),get_doc:e.Func([e.Text,e.Text],[e.Opt(s)],["query"]),get_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(q)))],["query"]),get_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(s)))],["query"]),get_proposal:e.Func([e.Nat],[e.Opt(Et)],["query"]),get_rule:e.Func([F,e.Text],[e.Opt(_r)],["query"]),get_storage_config:e.Func([],[be],["query"]),http_request:e.Func([us],[ps],["query"]),http_request_streaming_callback:e.Func([yr],[fs],["query"]),init_asset_upload:e.Func([gr],[xr],[]),init_proposal:e.Func([In],[e.Nat,Et],[]),init_proposal_asset_upload:e.Func([gr,e.Nat],[xr],[]),init_proposal_many_assets_upload:e.Func([e.Vec(gr),e.Nat],[e.Vec(e.Tuple(e.Text,xr))],[]),list_assets:e.Func([e.Text,O],[hs],["query"]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,T))],["query"]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,ms))],["query"]),list_docs:e.Func([e.Text,O],[_s],["query"]),list_proposals:e.Func([xs],[Ts],["query"]),list_rules:e.Func([F,Ns],[Os],["query"]),memory_size:e.Func([],[Es],["query"]),reject_proposal:e.Func([g],[e.Null],[]),set_auth_config:e.Func([Rs],[ee],[]),set_controllers:e.Func([Is],[e.Vec(e.Tuple(e.Principal,T))],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_db_config:e.Func([As],[he],[]),set_doc:e.Func([e.Text,e.Text,Sn],[s],[]),set_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,Sn))],[e.Vec(e.Tuple(e.Text,s))],[]),set_rule:e.Func([F,e.Text,Ss],[_r],[]),set_storage_config:e.Func([Fs],[be],[]),submit_proposal:e.Func([e.Nat],[e.Nat,Et],[]),switch_storage_system_memory:e.Func([],[],[]),upload_asset_chunk:e.Func([Fn],[Vn],[]),upload_proposal_asset_chunk:e.Func([Fn],[Vn],[])})},md=({IDL:e})=>{let t=e.Variant({Heap:e.Null,Stable:e.Null}),r=e.Record({system_memory:e.Opt(t)}),n=e.Record({controllers:e.Vec(e.Principal),storage:e.Opt(r)}),o=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),i=e.Variant({OpenId:o}),s=e.Record({updated_at:e.Nat64,owner:e.Principal,data:e.Vec(e.Nat8),description:e.Opt(e.Text),created_at:e.Nat64,version:e.Opt(e.Nat64)}),a=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),c=e.Record({doc:s,delegation:a}),u=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),p=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),d=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),l=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,JwtVerify:p,GetOrFetchJwks:d,DeriveSeedFailed:e.Text}),f=e.Variant({PrepareDelegation:l,RegisterUser:e.Text}),h=e.Variant({Ok:c,Err:f}),m=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),g=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),_=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),x=e.Record({field:_,desc:e.Bool}),y=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),w=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(y),description:e.Opt(e.Text),created_at:e.Opt(y)}),E=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),O=e.Record({order:e.Opt(x),owner:e.Opt(e.Principal),matcher:e.Opt(w),paginate:e.Opt(E)}),R=e.Record({controllers:e.Vec(e.Principal)}),I=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),T=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,scope:I,expires_at:e.Opt(e.Nat64)}),v=e.Record({version:e.Opt(e.Nat64)}),F=e.Variant({Db:e.Null,Storage:e.Null}),S=e.Record({version:e.Opt(e.Nat64)}),b=e.Record({proposal_ids:e.Vec(e.Nat)}),N=e.Record({cycles:e.Nat,destination_id:e.Principal}),V=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),B=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),q=e.Record({key:V,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,B)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),A=e.Variant({Google:e.Null}),P=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),C=e.Record({delegation:e.Opt(P),client_id:e.Text}),U=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(A,C))}),k=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),ne=e.Record({allowed_callers:e.Vec(e.Principal)}),ee=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(U),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(k),rules:e.Opt(ne)}),J=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),he=e.Record({updated_at:e.Opt(e.Nat64),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(J)}),Re=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),ze=e.Variant({Deny:e.Null,Allow:e.Null}),le=e.Record({status_code:e.Nat16,location:e.Text}),be=e.Record({iframe:e.Opt(Re),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(J),raw_access:e.Opt(ze),redirects:e.Opt(e.Vec(e.Tuple(e.Text,le)))}),es=e.Record({db:e.Opt(he),authentication:e.Opt(ee),storage:be}),ts=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),rs=e.Variant({OpenId:ts}),ns=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),os=e.Record({signature:e.Vec(e.Nat8),delegation:ns}),is=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:p,GetOrFetchJwks:d,DeriveSeedFailed:e.Text}),ss=e.Variant({Ok:os,Err:is}),as=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),cs=e.Record({clear_existing_assets:e.Opt(e.Bool)}),ls=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),In=e.Variant({AssetsUpgrade:cs,SegmentsDeployment:ls}),Et=e.Record({status:as,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:In}),Rt=e.Variant({Controllers:e.Null,Private:e.Null,Public:e.Null,Managed:e.Null}),An=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),_r=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(t),updated_at:e.Nat64,max_size:e.Opt(e.Nat),read:Rt,created_at:e.Nat64,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(An),write:Rt,max_changes_per_user:e.Opt(e.Nat32)}),us=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),yr=e.Record({memory:t,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),ds=e.Variant({Callback:e.Record({token:yr,callback:e.Func([],[],[])})}),ps=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(ds),status_code:e.Nat16}),fs=e.Record({token:e.Opt(yr),body:e.Vec(e.Nat8)}),gr=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),xr=e.Record({batch_id:e.Nat}),hs=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,q)),items_length:e.Nat64}),ms=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),_s=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,s)),items_length:e.Nat64}),ys=e.Record({desc:e.Bool}),gs=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),xs=e.Record({order:e.Opt(ys),paginate:e.Opt(gs)}),bs=e.Record({proposal_id:e.Nat}),Ts=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(bs,Et)),items_length:e.Nat64}),ws=e.Record({include_system:e.Bool}),Ns=e.Record({matcher:e.Opt(ws)}),Os=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(e.Text,_r)),items_length:e.Nat64}),Es=e.Record({stable:e.Nat64,heap:e.Nat64}),Rs=e.Record({openid:e.Opt(U),version:e.Opt(e.Nat64),internet_identity:e.Opt(k),rules:e.Opt(ne)}),vs=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),scope:I,expires_at:e.Opt(e.Nat64)}),Is=e.Record({controller:vs,controllers:e.Vec(e.Principal)}),As=e.Record({version:e.Opt(e.Nat64),max_memory_size:e.Opt(J)}),Sn=e.Record({data:e.Vec(e.Nat8),description:e.Opt(e.Text),version:e.Opt(e.Nat64)}),Ss=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(t),max_size:e.Opt(e.Nat),read:Rt,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(An),write:Rt,max_changes_per_user:e.Opt(e.Nat32)}),Fs=e.Record({iframe:e.Opt(Re),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(J),raw_access:e.Opt(ze),redirects:e.Opt(e.Vec(e.Tuple(e.Text,le)))}),Fn=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),Vn=e.Record({chunk_id:e.Nat});return e.Service({authenticate:e.Func([i],[h],[]),commit_asset_upload:e.Func([m],[],[]),commit_proposal:e.Func([g],[e.Null],[]),commit_proposal_asset_upload:e.Func([m],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(m)],[],[]),count_assets:e.Func([e.Text,O],[e.Nat64],[]),count_collection_assets:e.Func([e.Text],[e.Nat64],[]),count_collection_docs:e.Func([e.Text],[e.Nat64],[]),count_docs:e.Func([e.Text,O],[e.Nat64],[]),count_proposals:e.Func([],[e.Nat64],[]),del_asset:e.Func([e.Text,e.Text],[],[]),del_assets:e.Func([e.Text],[],[]),del_controllers:e.Func([R],[e.Vec(e.Tuple(e.Principal,T))],[]),del_custom_domain:e.Func([e.Text],[],[]),del_doc:e.Func([e.Text,e.Text,v],[],[]),del_docs:e.Func([e.Text],[],[]),del_filtered_assets:e.Func([e.Text,O],[],[]),del_filtered_docs:e.Func([e.Text,O],[],[]),del_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[],[]),del_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,v))],[],[]),del_rule:e.Func([F,e.Text,S],[],[]),delete_proposal_assets:e.Func([b],[],[]),deposit_cycles:e.Func([N],[],[]),get_asset:e.Func([e.Text,e.Text],[e.Opt(q)],[]),get_auth_config:e.Func([],[e.Opt(ee)],[]),get_config:e.Func([],[es],[]),get_db_config:e.Func([],[e.Opt(he)],[]),get_delegation:e.Func([rs],[ss],[]),get_doc:e.Func([e.Text,e.Text],[e.Opt(s)],[]),get_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(q)))],[]),get_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(s)))],[]),get_proposal:e.Func([e.Nat],[e.Opt(Et)],[]),get_rule:e.Func([F,e.Text],[e.Opt(_r)],[]),get_storage_config:e.Func([],[be],[]),http_request:e.Func([us],[ps],[]),http_request_streaming_callback:e.Func([yr],[fs],[]),init_asset_upload:e.Func([gr],[xr],[]),init_proposal:e.Func([In],[e.Nat,Et],[]),init_proposal_asset_upload:e.Func([gr,e.Nat],[xr],[]),init_proposal_many_assets_upload:e.Func([e.Vec(gr),e.Nat],[e.Vec(e.Tuple(e.Text,xr))],[]),list_assets:e.Func([e.Text,O],[hs],[]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,T))],[]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,ms))],[]),list_docs:e.Func([e.Text,O],[_s],[]),list_proposals:e.Func([xs],[Ts],[]),list_rules:e.Func([F,Ns],[Os],[]),memory_size:e.Func([],[Es],[]),reject_proposal:e.Func([g],[e.Null],[]),set_auth_config:e.Func([Rs],[ee],[]),set_controllers:e.Func([Is],[e.Vec(e.Tuple(e.Principal,T))],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_db_config:e.Func([As],[he],[]),set_doc:e.Func([e.Text,e.Text,Sn],[s],[]),set_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,Sn))],[e.Vec(e.Tuple(e.Text,s))],[]),set_rule:e.Func([F,e.Text,Ss],[_r],[]),set_storage_config:e.Func([Fs],[be],[]),submit_proposal:e.Func([e.Nat],[e.Nat,Et],[]),switch_storage_system_memory:e.Func([],[],[]),upload_asset_chunk:e.Func([Fn],[Vn],[]),upload_proposal_asset_chunk:e.Func([Fn],[Vn],[])})};var _d=({satelliteId:e,container:t})=>{let{satelliteId:r}=uc({satelliteId:e}),{container:n}=dc({container:t});if(X(n)&&n!==!1){let{host:o,protocol:i}=new URL(n===!0?Nn:n);return`${i}//${r??"unknown"}.${o.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},uc=({satelliteId:e})=>X(e)?{satelliteId:e}:Ge.getInstance().get()??{satelliteId:void 0},dc=({container:e})=>X(e)?{container:e}:Ge.getInstance().get()??{container:void 0};var xe=({satellite:e,options:{certified:t}})=>gd({idlFactory:t?md:hd,actorKey:`stock#${t?"update":"query"}`,...e}),yd=({idlFactory:e,...t})=>gd({idlFactory:e,actorKey:"extended#query",...t}),gd=async({satelliteId:e,container:t,...r})=>{let{satelliteId:n}=uc({satelliteId:e});xo(n,"No satellite ID defined. Did you initialize Juno?");let{container:o}=dc({container:t});return await En.getInstance().getActor({satelliteId:n,container:o,...r})};var xd=e=>{if($(e))return ae();switch(e.matcher){case"equal":return ae({Equal:e.timestamp});case"greaterThan":return ae({GreaterThan:e.timestamp});case"lessThan":return ae({LessThan:e.timestamp});case"between":return ae({Between:[e.timestamps.start,e.timestamps.end]});default:throw new Wi("Invalid list matcher for timestamp",e)}},mr=({matcher:e,paginate:t,order:r,owner:n})=>({matcher:$(e)?[]:[{key:ae(e.key),description:ae(e.description),created_at:xd(e.createdAt),updated_at:xd(e.updatedAt)}],paginate:ae($(t)?void 0:{start_after:ae(t.startAfter),limit:ae($(t.limit)?void 0:BigInt(t.limit))}),order:ae($(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:ae($(n)?void 0:typeof n=="string"?L.fromText(n):n)});var bd=async({data:e})=>{try{return await Bi(e)}catch(t){console.error("The data parsing has failed, mapping to undefined as a fallback.",t);return}};var pc=async e=>{let{data:t,version:r,description:n}=e;return{description:ae(n),data:await Zu(t),version:ae(r)}},fc=e=>{let{version:t}=e;return{version:ae(t)}},vo=async({doc:e,key:t})=>{let{owner:r,version:n,description:o,data:i,...s}=e;return{key:t,description:Ee(o),owner:r.toText(),data:await Bi(i),version:Ee(n),...s}};var Td=async({collection:e,key:t,...r})=>{let{get_doc:n}=await xe(r),o=Ee(await n(e,t));if(!$(o))return vo({doc:o,key:t})},wd=async({docs:e,...t})=>{let{get_many_docs:r}=await xe(t),n=e.map(({collection:s,key:a})=>[s,a]),o=await r(n),i=[];for(let[s,a]of o){let c=Ee(a);i.push(X(c)?await vo({key:s,doc:c}):void 0)}return i},Nd=async({collection:e,doc:t,...r})=>{let{set_doc:n}=await xe(r),{key:o}=t,i=await pc(t),s=await n(e,o,i);return await vo({key:o,doc:s})},Od=async({docs:e,...t})=>{let{set_many_docs:r}=await xe(t),n=[];for(let{collection:s,doc:a}of e){let{key:c}=a;n.push([s,c,await pc(a)])}let o=await r(n),i=[];for(let[s,a]of o)i.push(await vo({key:s,doc:a}));return i},Ed=async({collection:e,doc:t,...r})=>{let{del_doc:n}=await xe(r),{key:o}=t;return n(e,o,fc(t))},Rd=async({docs:e,...t})=>{let{del_many_docs:r}=await xe(t),n=e.map(({collection:o,doc:i})=>[o,i.key,fc(i)]);await r(n)},vd=async({collection:e,filter:t,...r})=>{let{del_filtered_docs:n}=await xe(r);return n(e,mr(t))},Id=async({collection:e,filter:t,...r})=>{let{list_docs:n}=await xe(r),{items:o,items_page:i,items_length:s,matches_length:a,matches_pages:c}=await n(e,mr(t)),u=[];for(let[p,d]of o){let{data:l,owner:f,description:h,version:m,...g}=d;u.push({key:p,description:Ee(h),owner:f.toText(),data:await bd({data:l}),version:Ee(m),...g})}return{items:u,items_length:s,items_page:Ee(i),matches_length:a,matches_pages:Ee(c)}},Ad=async({collection:e,filter:t,...r})=>{let{count_docs:n}=await xe(r);return n(e,mr(t))};var Qi=async({satellite:e,options:t,...r})=>{let n=ce(e?.identity);return await Td({...r,satellite:{...e,identity:n},options:t??Ot})},pT=async({satellite:e,options:t,...r})=>{let n=ce(e?.identity);return await wd({...r,satellite:{...e,identity:n},options:t??Ot})},Sd=async({satellite:e,...t})=>{let r=ce(e?.identity);return await Nd({...t,satellite:{...e,identity:r},options:{certified:!0}})},Fd=async({satellite:e,...t})=>{let r=ce(e?.identity);return await Od({...t,satellite:{...e,identity:r},options:{certified:!0}})},fT=async({satellite:e,...t})=>{let r=ce(e?.identity);return await Ed({...t,satellite:{...e,identity:r},options:{certified:!0}})},hT=async({satellite:e,...t})=>{let r=ce(e?.identity);return await Rd({...t,satellite:{...e,identity:r},options:{certified:!0}})},mT=async({satellite:e,filter:t,...r})=>{let n=ce(e?.identity);return await vd({...r,filter:t??{},satellite:{...e,identity:n},options:{certified:!0}})},_T=async({satellite:e,options:t,filter:r,...n})=>{let o=ce(e?.identity);return await Id({...n,filter:r??{},satellite:{...e,identity:o},options:t??Ot})},yT=async({satellite:e,options:t,filter:r,...n})=>{let o=ce(e?.identity);return await Ad({...n,filter:r??{},satellite:{...e,identity:o},options:t??Ot})};var Vd=async({delegationIdentity:e,passkeyIdentity:t,satelliteId:r})=>{let n=t.getCredential().getAAGUID(),[o,i]=await Fd({docs:[{collection:"#user",doc:{key:e.getPrincipal().toText(),data:{provider:"webauthn",providerData:{webauthn:{...X(n)&&{aaguid:Pi(n)}}}}}},{collection:"#user-webauthn",doc:{key:t.getCredential().getCredentialIdText(),data:{publicKey:t.getPublicKey().toRaw()}}}],satellite:{identity:e,satelliteId:r}});return o};var Pd=(i=>(i[i.RequestingUserCredential=0]="RequestingUserCredential",i[i.FinalizingCredential=1]="FinalizingCredential",i[i.Signing=2]="Signing",i[i.FinalizingSession=3]="FinalizingSession",i[i.RetrievingUser=4]="RetrievingUser",i))(Pd||{}),Cd=(s=>(s[s.CreatingUserCredential=0]="CreatingUserCredential",s[s.ValidatingUserCredential=1]="ValidatingUserCredential",s[s.FinalizingCredential=2]="FinalizingCredential",s[s.Signing=3]="Signing",s[s.FinalizingSession=4]="FinalizingSession",s[s.RegisteringUser=5]="RegisteringUser",s))(Cd||{});var Io=class{get id(){return"webauthn"}async signUp({options:{onProgress:t,maxTimeToLiveInMilliseconds:r,passkey:n}={},loadAuthWithUser:o}){let{satelliteId:i}=Ge.getInstance().get()??{satelliteId:void 0};if($(i))throw new Wr("Satellite ID not set. Have you initialized the Satellite?");let s=({step:m,state:g})=>{switch(m){case fr.RequestingUserCredential:t?.({step:1,state:g});break;case fr.FinalizingCredential:t?.({step:2,state:g});break;case fr.Signing:t?.({step:3,state:g});break}},c=await Nt({fn:async()=>await Ya.createWithNewCredential({onProgress:s,passkeyOptions:n}),step:0,onProgress:t}),{delegationIdentity:u,sessionKey:p}=await this.#e({identity:c,maxTimeToLiveInMilliseconds:r}),l=await Nt({fn:async()=>await Vd({delegationIdentity:u,passkeyIdentity:c,satelliteId:i}),step:5,onProgress:t});await Nt({fn:async()=>await this.#t({delegationIdentity:u,sessionKey:p}),step:4,onProgress:t}),await Nt({fn:async()=>await o({user:l}),step:5,onProgress:t})}async signIn({options:{onProgress:t,maxTimeToLiveInMilliseconds:r}={},loadAuth:n}){let{satelliteId:o}=Ge.getInstance().get()??{satelliteId:void 0};if($(o))throw new Wr("Satellite ID not set. Have you initialized the Satellite?");let i=async({credentialId:d})=>{let l=await Qi({collection:"#user-webauthn",key:Ci(d),options:{certified:!0},satellite:{identity:new Ye,satelliteId:o}});if($(l))throw new Gi("No public key found for the selected passkey.");let{data:f}=l,{publicKey:h}=f;return Kr(h,yo)},s=({step:d,state:l})=>{switch(d){case fr.RequestingUserCredential:t?.({step:0,state:l});break;case fr.FinalizingCredential:t?.({step:1,state:l});break;case fr.Signing:t?.({step:2,state:l});break}},a=await Ya.createWithExistingCredential({retrievePublicKey:i,onProgress:s}),{delegationIdentity:c,sessionKey:u}=await this.#e({identity:a,maxTimeToLiveInMilliseconds:r});await Nt({fn:async()=>await this.#t({delegationIdentity:c,sessionKey:u}),step:3,onProgress:t}),await Nt({fn:n,step:4,onProgress:t})}async#e({identity:t,maxTimeToLiveInMilliseconds:r}){let n=await hr.generate({extractable:!1}),o=r??144e5,i=await Jr.create(t,n.getPublicKey(),new Date(Date.now()+o));return{delegationIdentity:zr.fromDelegation(n,i),sessionKey:n}}async#t({sessionKey:t,delegationIdentity:r}){let n=new Jt;await Promise.all([n.set($e,t.getKeyPair()),n.set(Je,JSON.stringify(r.getDelegation().toJSON()))])}};var Ao=()=>Ro.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}}),Bd=async()=>(await new Jt().remove($e),await Ao());var hc=({error:e,type:t})=>typeof e=="string"?e.includes(t):e instanceof Error?e.message.includes(t):!1;var Dd="juno.datastore.error.user.cannot_update";var Ud=async({provider:e})=>{let{user:t,userId:r}=await mc();if(X(t))return t;try{return await Dm({userId:r,provider:e})}catch(n){if(hc({error:n,type:Dd})){let o=await kd({userId:r});if(X(o))return o}throw n}},mc=async()=>{let e=Xi();if($(e))throw new zi("No identity to initialize the user. Have you initialized Juno?");let t=e.getPrincipal().toText(),r=await kd({userId:t});return{userId:t,user:r}},kd=({userId:e})=>Qi({collection:"#user",key:e}),Dm=({userId:e,...t})=>Sd({collection:"#user",doc:{key:e,data:t}});var rt,_c=async()=>{await yc({fn:async()=>{let{user:t}=await mc();tt.getInstance().set(t??null)}})},Um=async({user:e})=>{await yc({fn:async()=>{tt.getInstance().set(e)}})},Ld=async({provider:e})=>{await yc({fn:async()=>{let r=await Ud({provider:e});tt.getInstance().set(r)}})},yc=async({fn:e})=>{if(rt=await Ao(),!await rt.isAuthenticated()){rt=await Bd();return}await e()},km=async e=>{let t=async()=>await qm(e);if(Object.values(e)[0].context?.windowGuard===!1){await t();return}await Xa({fn:t})},Lm=async e=>{let t=async()=>await Mm(e);if(Object.values(e)?.[0].context?.windowGuard===!1){await t();return}await Xa({fn:t})},qm=async e=>{if("webauthn"in e){let{webauthn:{options:t}}=e;await new Io().signIn({options:t,loadAuth:_c});return}if("nfid"in e){let{nfid:{options:t}}=e,{appName:r,logoUrl:n,...o}=t??{};await new Zi({appName:r,logoUrl:n}).signIn({options:o,authClient:rt,initAuth:Ld});return}if("internet_identity"in e){let{internet_identity:{options:t}}=e,{domain:r,...n}=t??{};await new Yi({domain:r}).signIn({options:n,authClient:rt,initAuth:Ld});return}throw new Hi("An unknown or unsupported provider was provided for sign-in.")},Mm=async e=>{if("webauthn"in e){let{webauthn:{options:t}}=e;await new Io().signUp({options:t,loadAuthWithUser:Um});return}throw new Ji("An unknown or unsupported provider was provided for sign-up.")},gc=async e=>{await jm(),rt=await Ao(),e?.windowReload!==!1&&window.location.reload()},jm=async()=>{await rt?.logout(),rt=null,tt.getInstance().reset(),En.getInstance().reset(),On.getInstance().reset()},Xi=()=>rt?.getIdentity(),Km=async()=>(rt??await Ao()).getIdentity(),$m=async()=>{let e=tt.getInstance().get();return $(e)||!(await rt?.isAuthenticated()??!1)?null:rt?.getIdentity()??null};var qd=e=>{let t=e===!0?"./workers/auth.worker.js":e,r=new Worker(t),n=async()=>{Za({message:"junoSignOutAuthTimer"}),await gc()};return r.onmessage=async({data:o})=>{let{msg:i,data:s}=o;switch(i){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":Za({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},tt.getInstance().subscribe(o=>{if($(o)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var Md=()=>{let e=()=>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??e():e()},jd=()=>{let e=()=>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??e():e()};var fw=async({idlFactory:e,satellite:t})=>{let r=ce(t?.identity);return await yd({idlFactory:e,...t,identity:r})};var Kd=async({asset:{data:e,headers:t,...r},actor:n,progress:o})=>{let{init_asset_upload:i,upload_asset_chunk:s,commit_asset_upload:a}=n,{batch_id:c}=await i(Hm(r));o?.onInitiatedBatch();let{chunkIds:u}=await zm({data:e,uploadFn:s,batchId:c});o?.onUploadedFileChunks(r.fullPath),await Jm({commitFn:a,batchId:c,data:e,headers:t,chunkIds:u}),o?.onCommittedBatch()};var Hm=({filename:e,collection:t,token:r,fullPath:n,encoding:o,description:i})=>({collection:t,full_path:n,name:e,token:ae(r),encoding_type:ae(o),description:ae(i)}),Gm=({batchId:e,chunkIds:t,headers:r,data:n})=>{let o=r.find(([i,s])=>i.toLowerCase()==="content-type")===void 0&&n.type!==void 0&&n.type!==""?[["Content-Type",n.type]]:void 0;return{batch_id:e,chunk_ids:t.map(({chunk_id:i})=>i),headers:[...r,...o??[]]}},Jm=async({commitFn:e,...t})=>{let r=Gm(t);await e(r)},zm=async({data:e,uploadFn:t,batchId:r})=>{let n=[],o=Di()?new Blob([await e.arrayBuffer()]):e,i=0n;for(let a=0;a<o.size;a+=19e5){let c=o.slice(a,a+19e5);n.push({batchId:r,chunk:c,uploadFn:t,orderId:i}),i++}let s=[];for await(let a of Wm({uploadChunks:n}))s=[...s,...a];return{chunkIds:s}};async function*Wm({uploadChunks:e,limit:t=12}){for(let r=0;r<e.length;r=r+t){let n=e.slice(r,r+t);yield await Promise.all(n.map(o=>Ym(o)))}}var Ym=async({batchId:e,chunk:t,uploadFn:r,orderId:n})=>r({batch_id:e,content:new Uint8Array(await t.arrayBuffer()),order_id:ae(n)});var $d=async({asset:e,...t})=>{let r=await xe(t);await Kd({actor:r,asset:e})},Hd=async({collection:e,filter:t,...r})=>{let{list_assets:n}=await xe(r),{items:o,items_length:i,items_page:s,matches_length:a,matches_pages:c}=await n(e,mr(t));return{items:o.map(([u,p])=>p),items_length:i,items_page:Ee(s),matches_length:a,matches_pages:Ee(c)}},Gd=async({collection:e,filter:t,...r})=>{let{count_assets:n}=await xe(r);return n(e,mr(t))},Jd=async({collection:e,fullPath:t,...r})=>(await xe(r)).del_asset(e,t),zd=async({assets:e,satellite:t})=>{let{del_many_assets:r}=await xe({satellite:t,options:{certified:!0}}),n=e.map(({collection:o,fullPath:i})=>[o,i]);await r(n)},Wd=async({collection:e,filter:t,...r})=>{let{del_filtered_assets:n}=await xe(r);return n(e,mr(t))},Yd=async({collection:e,fullPath:t,...r})=>{let{get_asset:n}=await xe(r);return Ee(await n(e,t))},Zd=async({assets:e,...t})=>{let{get_many_assets:r}=await xe(t),n=e.map(({collection:i,fullPath:s})=>[i,s]);return(await r(n)).map(([i,s])=>Ee(s))};var Xd=e=>btoa([...e].map(t=>String.fromCharCode(t)).join(""));var Sw=e=>Qd(e),Fw=e=>Qd({filename:e.data.name,...e}),Qd=async({filename:e,data:t,collection:r,headers:n=[],fullPath:o,token:i,satellite:s,encoding:a,description:c})=>{let u=ce(s?.identity),p=decodeURI(e),d=o??`/${r}/${p}`,l={...s,identity:u};return await $d({asset:{data:t,filename:p,collection:r,token:i,headers:n,fullPath:d,encoding:a,description:c},satellite:l,options:{certified:!0}}),{downloadUrl:ep({satellite:l,assetKey:{fullPath:d,token:i}}),fullPath:d,name:p}},Vw=async({collection:e,filter:t,satellite:r,options:n})=>{let o={...r,identity:ce(r?.identity)},{items:i,...s}=await Hd({collection:e,filter:t??{},satellite:o,options:n??Ot}),a=i.map(({key:{full_path:c,token:u,name:p,owner:d,description:l},headers:f,encodings:h,created_at:m,updated_at:g})=>{let _=Ee(u);return{fullPath:c,description:Ee(l),name:p,downloadUrl:ep({satellite:o,assetKey:{fullPath:c,token:_}}),token:_,headers:f,encodings:h.reduce((x,[y,{modified:w,sha256:E,total_length:O}])=>({...x,[y]:{modified:w,sha256:Xd(E),total_length:O}}),{}),owner:d.toText(),created_at:m,updated_at:g}});return{items:a,assets:a,...s}},Pw=async({collection:e,filter:t,satellite:r,options:n})=>{let o={...r,identity:ce(r?.identity)};return await Gd({collection:e,satellite:o,filter:t??{},options:n??Ot})},Cw=({collection:e,fullPath:t,satellite:r})=>Jd({collection:e,fullPath:t,satellite:{...r,identity:ce(r?.identity)},options:{certified:!0}}),Bw=({assets:e,satellite:t})=>zd({assets:e,satellite:{...t,identity:ce(t?.identity)},options:{certified:!0}}),Dw=async({collection:e,satellite:t,filter:r})=>{let n={...t,identity:ce(t?.identity)};return await Wd({collection:e,satellite:n,filter:r??{},options:{certified:!0}})},Uw=async({satellite:e,options:t,...r})=>{let n=ce(e?.identity);return await Yd({...r,satellite:{...e,identity:n},options:t??Ot})},kw=async({satellite:e,options:t,...r})=>{let n=ce(e?.identity);return await Zd({...r,satellite:{...e,identity:n},options:t??Ot})},ep=({assetKey:{fullPath:e,token:t},satellite:r})=>{let n={...r,identity:ce(r?.identity)};return`${_d(n)}${e}${X(t)?`?token=${t}`:""}`};var Zm=e=>{let t=e?.satelliteId??Md();xo(t,"Satellite ID is not configured. Juno cannot be initialized.");let r=e?.container??jd();return{satelliteId:t,internetIdentityId:e?.internetIdentityId,workers:e?.workers,container:r}},Jw=e=>Xm(e),Xm=async e=>{let t=Zm(e);Ge.getInstance().set(t),await _c();let r=t.workers?.auth!==void 0?qd(t.workers.auth):void 0;return[...r?[r]:[]]},Qm=e=>tt.getInstance().subscribe(e),zw=Qm;export{fd as AuthClientSignInProgressStep,zi as InitError,Yi as InternetIdentityProvider,Wi as ListError,Zi as NFIDProvider,Ki as SignInError,Wr as SignInInitError,Hi as SignInProviderNotSupportedError,$i as SignInUserInterruptError,Ji as SignUpProviderNotSupportedError,Pd as WebAuthnSignInProgressStep,Gi as WebAuthnSignInRetrievePublicKeyError,Cd as WebAuthnSignUpProgressStep,zw as authSubscribe,Pw as countAssets,yT as countDocs,Cw as deleteAsset,fT as deleteDoc,Dw as deleteFilteredAssets,mT as deleteFilteredDocs,Bw as deleteManyAssets,hT as deleteManyDocs,ep as downloadUrl,Uw as getAsset,Qi as getDoc,$m as getIdentityOnce,kw as getManyAssets,pT as getManyDocs,fw as getSatelliteExtendedActor,Jw as initJuno,Xm as initSatellite,lm as isWebAuthnAvailable,Vw as listAssets,_T as listDocs,Qm as onAuthStateChange,Sd as setDoc,Fd as setManyDocs,km as signIn,gc as signOut,Lm as signUp,Km as unsafeIdentity,Sw as uploadBlob,Fw as uploadFile};
54
+ Retrying request.`),await this.#y({requestFn:r,backoff:n,tries:o+1});throw yo.fromCode(new wo(p))}let c=$i(s.headers);if(s.status===Ha||s.status===Zh)return{ok:s.ok,status:s.status,statusText:s.statusText,responseBodyBytes:a,headers:c};let u=await s.text();if(s.status===Xh&&s.url.includes("api/v3"))throw ne.fromCode(new bo);if(u.startsWith("Invalid request expiry: "))throw z.fromCode(new hn(u,this.#l));if(o<this.#d)return await this.#y({requestFn:r,backoff:n,tries:o+1});throw ne.fromCode(new xo(s.status,s.statusText,c,u))}async query(t,r,n){let o=this.#p(),i=r.effectiveCanisterId?M.from(r.effectiveCanisterId):M.from(t);await this.#g(i),this.log.print(`ecid ${i.toString()}`),this.log.print(`canisterId ${t.toString()}`);let s,a=await(n??this.#n);if(!a)throw Oe.fromCode(new xr);let c=M.from(t),u=a.getPrincipal(),p=$a(this.#l,this.#r),d={request_type:wn.Query,canister_id:c,method_name:r.methodName,arg:r.arg,sender:u,ingress_expiry:p},l=Zt(d);s=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#i?{Authorization:"Basic "+btoa(this.#i)}:{}}},endpoint:Qt.Query,body:d}),s=await a.transformRequest(s);let f=Do(s.body),h={canister:c.toText(),ecid:i,transformedRequest:s,body:f,requestId:l,backoff:o,tries:0},m=async()=>{let _=await this.#b(h);return{requestDetails:d,..._}},g=async()=>{let _=this.#m.get(i.toString());if(_)return _;await this.fetchSubnetKeys(i.toString());let x=this.#m.get(i.toString());if(!x)throw Pe.fromCode(new Ii);return x};try{if(!this.#_)return await m();let[_,x]=await Promise.all([m(),g()]);try{return this.#w(_,x)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),this.#m.delete(i.toString());let y=await g();return this.#w(_,y)}}catch(_){let x;throw _ instanceof ht?(_.code.requestContext={requestId:l,senderPubKey:s.body.sender_pubkey,senderSignature:s.body.sender_sig,ingressExpiry:s.body.content.ingress_expiry},x=_):x=ge.fromCode(new Be(_)),this.log.error(`Error while making query: ${x.message}`,x),x}}#w;async createReadStateRequest(t,r){await this.#g();let n=await(r??this.#n);if(!n)throw Oe.fromCode(new xr);let o=n.getPrincipal(),i=await this._transform({request:{method:"POST",headers:{"Content-Type":"application/cbor",...this.#i?{Authorization:"Basic "+btoa(this.#i)}:{}}},endpoint:Qt.ReadState,body:{request_type:wn.ReadState,paths:t.paths,sender:o,ingress_expiry:$a(this.#l,this.#r)}});return n.transformRequest(i)}async readState(t,r,n,o){await this.#T();let i=M.from(t);function s(p){for(let d of p.paths){let[l,f]=d,h=new TextEncoder().encode("request_status");if(xn(l,h))return f}}let a,c;if(o)a=o,c=Zt(a);else{c=s(r);let p=await this.#n;if(!p)throw Oe.fromCode(new xr);a=await this.createReadStateRequest(r,p)}this.log.print(`fetching "/api/v2/canister/${i}/read_state" with request:`,a);let u=this.#p();try{let{responseBodyBytes:p}=await this.#y({requestFn:()=>this.#o(""+new URL(`/api/v2/canister/${i.toString()}/read_state`,this.host),{...this.#a,...a.request,body:Do(a.body)}),backoff:u,tries:0}),d=Je(p);return this.log.print("Read state response:",d),d}catch(p){let d;throw p instanceof ht?(p.code.requestContext={requestId:c,senderPubKey:a.body.sender_pubkey,senderSignature:a.body.sender_sig,ingressExpiry:a.body.content.ingress_expiry},d=p):d=ge.fromCode(new Be(p)),this.log.error(`Error while making read state: ${d.message}`,d),d}}parseTimeFromResponse(t){let r;if(t.certificate){let n=Je(t.certificate);if(n&&"tree"in n)r=n.tree;else throw ne.fromCode(new br("Could not decode time from response"));let o=In(["time"],r);if(o.status!==We.Found)throw ne.fromCode(new Jt("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 ne.fromCode(new Dn("Time was not in its expected format."));let i=to(o.value);return this.log.print("Time from response:",i),this.log.print("Time from response in milliseconds:",i.getTime()),i.getTime()}else this.log.warn("No certificate found in response");return 0}async syncTime(t){this.#s=this.#s??(async()=>{await this.#T();let r=Date.now();try{t||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let n=t??M.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),o=e.createSync({identity:new rt,host:this.host.toString(),fetch:this.#o,retryTimes:0,rootKey:this.rootKey??void 0,shouldSyncTime:!1}),s=(await Promise.all(Array(3).fill(null).map(async()=>{let c=(await Da({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);s>0&&(this.#r=s-r,this.#c=!0,this.log.notify({message:`Syncing time: offset of ${this.#r}`,level:"info"}))}catch(n){let o=n instanceof ht?n:ge.fromCode(new Be(n));throw this.log.error("Caught exception while attempting to sync time",o),o}})(),await this.#s.finally(()=>{this.#s=null})}async status(){let t=this.#i?{Authorization:"Basic "+btoa(this.#i)}:{};this.log.print('fetching "/api/v2/status"');let r=this.#p(),{responseBodyBytes:n}=await this.#y({backoff:r,requestFn:()=>this.#o(""+new URL("/api/v2/status",this.host),{headers:t,...this.#a}),tries:0});return Je(n)}async fetchRootKey(){return this.#e=this.#e??(async()=>{let t=await this.status();return this.rootKey=t.root_key,this.rootKey})(),await this.#e.finally(()=>{this.#e=null})}async#g(t){await Promise.all([this.#T(),this.#O(t)])}async#T(){if(!this.rootKey)if(this.rootKey===null&&this.host.toString()!=="https://icp-api.io"&&this.#t)await this.fetchRootKey();else throw Oe.fromCode(new Rt(this.#t))}async#O(t){this.#u&&!this.hasSyncedTime()&&await this.syncTime(t)}invalidateIdentity(){this.#n=null}replaceIdentity(t){this.#n=Promise.resolve(t)}async fetchSubnetKeys(t){let r=M.from(t);await this.#g(r);let o=(await Da({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(t){let r=Promise.resolve(t);if(t.endpoint===Qt.Call)for(let n of this.#h)r=r.then(o=>n(o).then(i=>i||o));else for(let n of this.#f)r=r.then(o=>n(o).then(i=>i||o));return r}getTimeDiffMsecs(){return this.#r}hasSyncedTime(){return this.#c}};function $a(e,t){let r=e*Ga;return zn.fromDeltaInMilliseconds(r,t)}var tm=300*1e3;function Mu(){return sm(nm(rm(),1e3),im(1e3,1.2),om(tm))}function rm(){let e=!0;return async()=>e?(e=!1,!0):!1}function nm(e,t){return async(r,n,o)=>{if(await e(r,n,o))return new Promise(i=>setTimeout(i,t))}}function om(e){let t=Date.now()+e;return async(r,n,o)=>{if(Date.now()>t)throw ne.fromCode(new fn(`Request timed out after ${e} msec`,n,o))}}function im(e,t){let r=e;return()=>new Promise(n=>setTimeout(()=>{r*=t,n()},r))}function sm(...e){return async(t,r,n)=>{for(let o of e)await o(t,r,n)}}var Ku={preSignReadStateRequest:!1};function Hu(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ja(e,t){return e!==null&&typeof e=="object"&&Hu(e,t)}function cm(e,t){return Hu(e,t)&&typeof e[t]=="function"}function ju(e){return Ja(e,"body")&&Ja(e.body,"content")&&e.body.content.request_type===wn.ReadState&&Ja(e.body.content,"ingress_expiry")&&typeof e.body.content.ingress_expiry=="object"&&e.body.content.ingress_expiry!==null&&cm(e.body.content.ingress_expiry,"toHash")}async function za(e,t,r,n={}){let o=[ee("request_status"),r],i,s;if(n.preSignReadStateRequest??!1?(s=await lm({paths:[o],agent:e,pollingOptions:n}),i=await e.readState(t,{paths:[o]},void 0,s)):i=await e.readState(t,{paths:[o]}),e.rootKey==null)throw Oe.fromCode(new Rt);let c=await Ar.create({certificate:i.certificate,rootKey:e.rootKey,canisterId:t,blsVerify:n.blsVerify,agent:e}),u=Ve(c.lookup_path([...o,ee("status")])),p;switch(typeof u>"u"?p=Vt.Unknown:p=new TextDecoder().decode(u),p){case Vt.Replied:return{reply:Ve(c.lookup_path([...o,"reply"])),certificate:c};case Vt.Received:case Vt.Unknown:case Vt.Processing:{let d=n.strategy??Mu();return await d(t,r,p),za(e,t,r,{...n,strategy:d,request:s})}case Vt.Rejected:{let d=new Uint8Array(Ve(c.lookup_path([...o,"reject_code"])))[0],l=new TextDecoder().decode(Ve(c.lookup_path([...o,"reject_message"]))),f=Ve(c.lookup_path([...o,"error_code"])),h=f?new TextDecoder().decode(f):void 0;throw yr.fromCode(new kn(r,d,l,h))}case Vt.Done:throw ge.fromCode(new Oi(r))}throw wr}async function lm(e){let{paths:t,agent:r,pollingOptions:n}=e;if(n.request&&ju(n.request))return n.request;let o=await r.createReadStateRequest?.({paths:t},void 0);if(!ju(o))throw z.fromCode(new Fi(o));return o}var st=Symbol.for("ic-agent-metadata"),oo=class e{static agentOf(t){return t[st].config.agent}static interfaceOf(t){return t[st].service}static canisterIdOf(t){return M.from(t[st].config.canisterId)}static createActorClass(t,r){let n=t({IDL:gn});class o extends e{constructor(s){if(!s.canisterId)throw z.fromCode(new To(s.canisterId));let a=typeof s.canisterId=="string"?M.fromText(s.canisterId):s.canisterId;super({config:{...$u,...s,canisterId:a},service:n});for(let[c,u]of n._fields)r?.httpDetails&&u.annotations.push(Wa),r?.certificate&&u.annotations.push(Gu),this[c]=dm(this,c,u,s.blsVerify)}}return o}static createActor(t,r){if(!r.canisterId)throw z.fromCode(new To(r.canisterId));return new(this.createActorClass(t))(r)}static createActorWithHttpDetails(t,r){return new(this.createActorClass(t,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(t,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(t,n))(r)}constructor(t){this[st]=Object.freeze(t)}};function no(e,t){let r=gn.decode(e,t);switch(r.length){case 0:return;case 1:return r[0];default:return r}}var $u={pollingOptions:Ku},Wa="http-details",Gu="certificate";function dm(e,t,r,n){let o;r.annotations.includes("query")||r.annotations.includes("composite_query")?o=async(s,...a)=>{s={...s,...e[st].config.queryTransform?.(t,a,{...e[st].config,...s})};let c=s.agent||e[st].config.agent||new cr,u=M.from(s.canisterId||e[st].config.canisterId),p=gn.encode(r.argTypes,a),d=await c.query(u,{methodName:t,arg:p,effectiveCanisterId:s.effectiveCanisterId}),l={...d.httpDetails,requestDetails:d.requestDetails};switch(d.status){case fr.Rejected:{let f=new Ti(d.requestId,d.reject_code,d.reject_message,d.error_code,d.signatures);throw f.callContext={canisterId:u,methodName:t,httpDetails:l},yr.fromCode(f)}case fr.Replied:return r.annotations.includes(Wa)?{httpDetails:l,result:no(r.retTypes,d.reply.arg)}:no(r.retTypes,d.reply.arg)}}:o=async(s,...a)=>{s={...s,...e[st].config.callTransform?.(t,a,{...e[st].config,...s})};let c=s.agent||e[st].config.agent||cr.createSync(),{canisterId:u,effectiveCanisterId:p,pollingOptions:d}={...$u,...e[st].config,...s},l=M.from(u),f=p!==void 0?M.from(p):l,h=gn.encode(r.argTypes,a),{requestId:m,response:g,requestDetails:_}=await c.call(l,{methodName:t,arg:h,effectiveCanisterId:f,nonce:s.nonce}),x,y;if(qc(g.body)){if(c.rootKey==null)throw Oe.fromCode(new Rt);let R=g.body.certificate;y=await Ar.create({certificate:R,rootKey:c.rootKey,canisterId:f,blsVerify:n,agent:c});let I=[ee("request_status"),m];switch(new TextDecoder().decode(Ve(y.lookup_path([...I,"status"])))){case"replied":x=Ve(y.lookup_path([...I,"reply"]));break;case"rejected":{let v=new Uint8Array(Ve(y.lookup_path([...I,"reject_code"])))[0],V=new TextDecoder().decode(Ve(y.lookup_path([...I,"reject_message"]))),S=Ve(y.lookup_path([...I,"error_code"])),b=S?new TextDecoder().decode(S):void 0,N=new kn(m,v,V,b);throw N.callContext={canisterId:l,methodName:t,httpDetails:g},yr.fromCode(N)}}}else if(Lc(g.body)){let{reject_code:R,reject_message:I,error_code:w}=g.body,v=new Ni(m,R,I,w);throw v.callContext={canisterId:l,methodName:t,httpDetails:g},yr.fromCode(v)}if(g.status===202){let R={...d,blsVerify:n},I=await za(c,f,m,R);y=I.certificate,x=I.reply}let T=r.annotations.includes(Wa),E=r.annotations.includes(Gu),O={...g,requestDetails:_};if(x!==void 0)return T&&E?{httpDetails:O,certificate:y,result:no(r.retTypes,x)}:E?{certificate:y,result:no(r.retTypes,x)}:T?{httpDetails:O,result:no(r.retTypes,x)}:no(r.retTypes,x);{let R=new Be(`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${r.retTypes.map(I=>I.display()).join(",")}].`);throw R.callContext={canisterId:l,methodName:t,httpDetails:O},ge.fromCode(R)}};let i=(...s)=>o({},...s);return i.withOptions=s=>(...a)=>o(s,...a),i}var pm=(e=>(e[e.FractionalMoreThan8Decimals=0]="FractionalMoreThan8Decimals",e[e.InvalidFormat=1]="InvalidFormat",e[e.FractionalTooManyDecimals=2]="FractionalTooManyDecimals",e))(pm||{}),Tx=BigInt(1e8);var q=e=>e==null,X=e=>!q(e),Qa=e=>X(e)&&e!=="",io=e=>!Qa(e);var fm=class extends Error{},Qo=(e,t)=>{if(e==null)throw new fm(t)};var lr=e=>new Uint8Array(e),us=e=>Array.from(e);var zu=({a:e,b:t})=>e.length===t.length&&e.every((r,n)=>r===t[n]);var Ju="abcdefghijklmnopqrstuvwxyz234567",Xo=Object.create(null);for(let e=0;e<Ju.length;e++)Xo[Ju[e]]=e;Xo[0]=Xo.o;Xo[1]=Xo.i;var Vr=e=>btoa(String.fromCharCode(...new Uint8Array(e))),Wu=e=>Uint8Array.from(atob(e),t=>t.charCodeAt(0)),Nx=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]);var Ya="__bigint__",Za="__principal__",Xa="__uint8array__",Yu=(e,t)=>typeof t=="bigint"?{[Ya]:`${t}`}:X(t)&&M.isPrincipal(t)?{[Za]:M.from(t).toText()}:X(t)&&t instanceof Uint8Array?{[Xa]:Array.from(t)}:t,Zu=(e,t)=>{let r=n=>t[n];return X(t)&&typeof t=="object"&&Ya in t?BigInt(r(Ya)):X(t)&&typeof t=="object"&&Za in t?M.fromText(r(Za)):X(t)&&typeof t=="object"&&Xa in t?Uint8Array.from(r(Xa)):t};var ue=e=>X(e)?[e]:[],ye=e=>e?.[0];var hm=({authData:e})=>{if(e.byteLength<37)return{invalidAuthData:null};if(e.byteLength<53)return{invalidAuthData:null};let t=e.slice(37,53),r=mm({bytes:t});return"aaguid"in r?{aaguidBytes:t,aaguidText:r.aaguid}:{unknownProvider:null}},mm=({bytes:e})=>{if(e.length!==16)return{invalidBytes:null};let t=(e instanceof Uint8Array?us(e):e).map(r=>r.toString(16).padStart(2,"0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/,"$1-$2-$3-$4-$5");return t==="00000000-0000-0000-0000-000000000000"?{unknownProvider:null}:{aaguid:t}};function _m(e){let t=new DataView(new ArrayBuffer(2)),r=e.slice(53,55);[...new Uint8Array(r)].forEach((o,i)=>t.setUint8(i,o));let n=t.getUint16(0);return e.slice(55+n)}function ym(e){return Sn(e,Zo)}var gm=class{constructor(e){this._cose=e,this.#e=ym(e)}#e;toDer(){return this.#e}toRaw(){return new Uint8Array(this.#e)}},rd=class{#e;#t;constructor({rawId:e,cose:t}){this.#e=e,this.#t=new gm(t)}getPublicKey(){return this.#t}getCredentialId(){return this.#e}getCredentialIdText(){return Vr(this.#e)}},xm=class extends rd{#e;#t;constructor({authData:e,...t}){super(t);let r=hm({authData:e});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}},bm=class extends rd{},wm=class extends Error{},Tm=class extends Error{},Nm=class extends Error{},Om=class extends Error{},Em=class extends Error{},Rm=class extends Error{},vm=class extends Error{},Xu=class extends Error{};var Im={ECDSA_WITH_SHA256:-7,RSA_WITH_SHA256:-257},Am=6e4,nd=()=>window.crypto.getRandomValues(new Uint8Array(16)),Sm=()=>nd(),Fm=()=>nd(),Vm=()=>{let{location:{href:e}}=window;try{let{hostname:t}=new URL(e);return t}catch{throw new wm}},od=({appId:e})=>e?.id??Vm(),Cm=({appId:e,user:t}={})=>{let{document:{title:r}}=window,n=()=>({rp:{name:e?.name??r,id:od({appId:e})}}),o=()=>({user:{id:Fm(),name:t?.name??t?.displayName??r,displayName:t?.displayName??r}});return{attestation:"direct",challenge:Sm(),...n(),...o(),pubKeyCredParams:Object.values(Im).map(i=>({type:"public-key",alg:i})),excludeCredentials:[],authenticatorSelection:{authenticatorAttachment:"platform",userVerification:"preferred",residentKey:"required",requireResidentKey:!0}}},Pm=(e={})=>({rpId:od(e),allowCredentials:[],userVerification:"required"}),ec=async({fn:e,step:t,onProgress:r})=>{r?.({step:t,state:"in_progress"});try{let n=await e();return r?.({step:t,state:"success"}),n}catch(n){throw r?.({step:t,state:"error"}),n}},Cr=(e=>(e[e.RequestingUserCredential=0]="RequestingUserCredential",e[e.FinalizingCredential=1]="FinalizingCredential",e[e.Signing=2]="Signing",e))(Cr||{}),id=({timeout:e})=>AbortSignal.timeout(e??Am),Bm=async({challenge:e,credentialIds:t,passkeyOptions:r,timeout:n})=>await navigator.credentials.get({publicKey:{...Pm(r),challenge:e.buffer,allowCredentials:(t??[]).map(o=>({id:o.buffer,type:"public-key"}))},signal:id({timeout:n})}),Qu=e=>{if(e.status!=="initialized")throw new Tm},ed=e=>{if(q(e))throw new Nm},td=({type:e})=>{if(e!=="public-key")throw new Om},tc=class ei extends Ft{#e;#t;constructor({onProgress:t,...r}){if(super(),this.#e=t,"retrievePublicKey"in r){let{retrievePublicKey:n}=r;this.#t={status:"pending",retrievePublicKey:n};return}this.#t=ei.#r({credential:new xm(r)})}static#r({credential:t}){return{status:"initialized",credential:t}}static async createWithNewCredential({passkeyOptions:t,timeout:r,...n}={}){let o=await navigator.credentials.create({publicKey:Cm(t),signal:id({timeout:r})});ed(o),td(o);let{response:{attestationObject:i},rawId:s}=o;if(q(i))throw new Em;let{authData:a}=ji.decode(lr(i)),c=_m(a);return new ei({...n,rawId:lr(s),cose:c,authData:a})}static async createWithExistingCredential(t){return new ei(t)}getPublicKey(){Qu(this.#t);let{credential:t}=this.#t;return t.getPublicKey()}getCredential(){Qu(this.#t);let{credential:t}=this.#t;return t}async sign(t){let r=await ec({fn:async()=>{let n=await Bm({challenge:t,...this.#t.status==="initialized"&&{credentialIds:[this.#t.credential.getCredentialId()]}});return ed(n),td(n),n},step:0,onProgress:this.#e});return await ec({fn:async()=>{let{rawId:n}=r;if(this.#t.status==="initialized"){if(!zu({a:this.#t.credential.getCredentialId(),b:lr(n)}))throw new Rm;return}let{retrievePublicKey:o}=this.#t,i=await o({credentialId:lr(n)});this.#t=ei.#r({credential:new bm({rawId:lr(n),cose:i})})},step:1,onProgress:this.#e}),await ec({fn:async()=>{let{response:n}=r,{clientDataJSON:o}=n,{authenticatorData:i,signature:s}="authenticatorData"in n&&"signature"in n?n:{};if(q(i))throw new Xu;if(q(s))throw new Xu;let a=ji.encode({authenticator_data:i,client_data_json:new TextDecoder().decode(o),signature:lr(s)});if(q(a))throw new vm;return Object.assign(a,{__signature__:void 0}),a},step:2,onProgress:this.#e})}},Dm=async()=>X(window.PublicKeyCredential)&&"isUserVerifyingPlatformAuthenticatorAvailable"in PublicKeyCredential?await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():!1;var so=class{callbacks=[];populate(t){this.callbacks.forEach(({callback:r})=>r(t))}subscribe(t){let r=Symbol();return this.callbacks.push({id:r,callback:t}),()=>this.callbacks=this.callbacks.filter(({id:n})=>n!==r)}};var je=class e extends so{static instance;authUser=null;constructor(){super()}static getInstance(){return e.instance||(e.instance=new e),e.instance}set(t){this.authUser=t,this.populate(t)}get(){return this.authUser}subscribe(t){let r=super.subscribe(t);return t(this.authUser),r}reset(){this.authUser=null,this.populate(this.authUser)}};var rc=({message:e,detail:t})=>{let r=new CustomEvent(e,{detail:t,bubbles:!0});document.dispatchEvent(r)};var ao="http://127.0.0.1:5987",sd="rdmx6-jaaaa-aaaaa-aaadq-cai";var ad=async({identity:e,container:t})=>{let n=X(t)&&t!==!1?t===!0?ao:t:"https://icp-api.io",o=X(t);return await cr.create({identity:e,shouldFetchRootKey:o,host:n})};var co=class e{static instance;#e=void 0;constructor(){}static getInstance(){return q(e.instance)&&(e.instance=new e),e.instance}async getAgent({identity:t,...r}){let n=t.getPrincipal().toText();if(q(this.#e)||q(this.#e[n])){let o=await ad({identity:t,...r});return this.#e={...this.#e??{},[n]:o},o}return this.#e[n]}reset(){this.#e=null}};var lo=class e{static instance;#e=void 0;constructor(){}static getInstance(){return q(e.instance)&&(e.instance=new e),e.instance}async getActor({satelliteId:t,identity:r,actorKey:n,...o}){let i=`${n}#${r.getPrincipal().toText()}#${t};`;if(q(this.#e)||q(this.#e[i])){let s=await this.createActor({satelliteId:t,identity:r,...o});return this.#e={...this.#e??{},[i]:s},s}return this.#e[i]}reset(){this.#e=null}async createActor({idlFactory:t,satelliteId:r,...n}){let o=await co.getInstance().getAgent(n);return oo.createActor(t,{agent:o,canisterId:r})}};function cd(e){return e!==null&&typeof e=="object"}var ti=class e{static from(t){if(typeof t=="string"){let r=Ne(t);return this.fromRaw(r)}else if(cd(t)){let r=t;if(cd(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(vt(n.buffer))}else{if(r instanceof ArrayBuffer)return this.fromRaw(vt(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(t){return new e(t)}static fromDer(t){return new e(this.derDecode(t))}static{this.RAW_KEY_LENGTH=32}static derEncode(t){let r=Sn(t,An);return r.__derEncodedPublicKey__=void 0,r}static derDecode(t){let r=Fn(t,An);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(t){if(t.byteLength!==e.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");this.#e=t,this.#t=e.derEncode(t)}toDer(){return this.derKey}toRaw(){return this.rawKey}},Nt=class e extends Ft{static generate(t){if(t&&t.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");t||(t=Me.utils.randomPrivateKey()),al(t,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]=t[o];let n=Me.getPublicKey(r);return e.fromKeyPair(n,r)}static fromParsedJson(t){let[r,n]=t;return new e(ti.fromDer(Ne(r)),Ne(n))}static fromJSON(t){let r=JSON.parse(t);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(t)}`)}static fromKeyPair(t,r){return new e(ti.fromRaw(t),r)}static fromSecretKey(t){let r=Me.getPublicKey(t);return e.fromKeyPair(r,t)}#e;#t;constructor(t,r){super(),this.#e=ti.from(t),this.#t=r}toJSON(){return[H(this.#e.toDer()),H(this.#t)]}getKeyPair(){return{secretKey:this.#t,publicKey:this.#e}}getPublicKey(){return this.#e}async sign(t){let r=Me.sign(t,this.#t.slice(0,32));return Object.defineProperty(r,"__signature__",{enumerable:!1,value:void 0}),r}static verify(t,r,n){let[o,i,s]=[t,r,n].map(a=>(typeof a=="string"&&(a=Ne(a)),vt(a)));return Me.verify(o,i,s)}};var nc=class e extends Error{constructor(t){super(t),this.message=t,Object.setPrototypeOf(this,e.prototype)}};function ld(e){if(typeof global<"u"&&global.crypto&&global.crypto.subtle)return global.crypto.subtle;if(e)return e;if(typeof crypto<"u"&&crypto.subtle)return crypto.subtle;throw new nc("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 Ct=class e extends Ft{static async generate(t){let{extractable:r=!1,keyUsages:n=["sign","verify"],subtleCrypto:o}=t??{},i=ld(o),s=await i.generateKey({name:"ECDSA",namedCurve:"P-256"},r,n),a=vt(await i.exportKey("spki",s.publicKey));return Object.assign(a,{__derEncodedPublicKey__:void 0}),new this(s,a,i)}static async fromKeyPair(t,r){let n=ld(r),o=vt(await n.exportKey("spki",t.publicKey));return Object.assign(o,{__derEncodedPublicKey__:void 0}),new e(t,o,n)}constructor(t,r,n){super(),this._keyPair=t,this._derKey=r,this._subtleCrypto=n}getKeyPair(){return this._keyPair}getPublicKey(){let t=this._derKey,r=Object.create(this._keyPair.publicKey);return r.toDer=function(){return t},r}async sign(t){let r={name:"ECDSA",hash:{name:"SHA-256"}},n=vt(await this._subtleCrypto.sign(r,this._keyPair.privateKey,t));return Object.assign(n,{__signature__:void 0}),n}};var ds=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 M.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(t){this.#e=t}};function ps(e){return e instanceof Uint8Array?H(e):H(new Uint8Array(e))}function oc(e){if(typeof e!="string"||e.length<64)throw new Error("Invalid public key.");return Ne(e)}var Pr=class{constructor(t,r,n){this.pubkey=t,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:ps(this.pubkey),...this.targets&&{targets:this.targets.map(t=>t.toHex())}}}};async function Um(e,t,r,n){let o=new Pr(t.toDer(),BigInt(+r)*BigInt(1e6),n),i=new Uint8Array([...ta,...new Uint8Array(Zt({...o}))]),s=await e.sign(i);return{delegation:o,signature:s}}var ur=class e{static async create(t,r,n=new Date(Date.now()+900*1e3),o={}){let i=await Um(t,r,n,o.targets);return new e([...o.previous?.delegations||[],i],o.previous?.publicKey||t.getPublicKey().toDer())}static fromJSON(t){let{publicKey:r,delegations:n}=typeof t=="string"?JSON.parse(t):t;if(!Array.isArray(n))throw new Error("Invalid delegations.");let o=n.map(i=>{let{delegation:s,signature:a}=i,{pubkey:c,expiration:u,targets:p}=s;if(p!==void 0&&!Array.isArray(p))throw new Error("Invalid targets.");return{delegation:new Pr(oc(c),BigInt("0x"+u),p&&p.map(d=>{if(typeof d!="string")throw new Error("Invalid target.");return M.fromHex(d)})),signature:oc(a)}});return new this(o,oc(r))}static fromDelegations(t,r){return new this(t,r)}constructor(t,r){this.delegations=t,this.publicKey=r}toJSON(){return{delegations:this.delegations.map(t=>{let{delegation:r,signature:n}=t,{targets:o}=r;return{delegation:{expiration:r.expiration.toString(16),pubkey:ps(r.pubkey),...o&&{targets:o.map(i=>i.toHex())}},signature:ps(n)}}),publicKey:ps(this.publicKey)}}},dr=class extends Ft{static fromDelegation(t,r){return new this(t,r)}constructor(t,r){super(),this._inner=t,this._delegation=r}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(t){return this._inner.sign(t)}async transformRequest(t){let{body:r,...n}=t,o=await Zt(r);return{...n,body:{content:r,sender_sig:await this.sign(new Uint8Array([...Fo,...new Uint8Array(o)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}}}},ri=class e extends ds{#e;get delegation(){return this.#e}constructor(t,r){super(t),this.#e=r}static fromDelegation(t,r){return new e(t,r)}};function ic(e,t){for(let{delegation:o}of e.delegations)if(+new Date(Number(o.expiration/BigInt(1e6)))<=+Date.now())return!1;let r=[],n=t?.scope;n&&(Array.isArray(n)?r.push(...n.map(o=>typeof o=="string"?M.fromText(o):o)):r.push(typeof n=="string"?M.fromText(n):n));for(let o of r){let i=o.toText();for(let{delegation:s}of e.delegations){if(s.targets===void 0)continue;let a=!0;for(let c of s.targets)if(c.toText()===i){a=!1;break}if(a)return!1}}return!0}var ud=["mousedown","mousemove","keydown","touchstart","wheel"],ni=class e{callbacks=[];idleTimeout=600*1e3;timeoutID=void 0;static create(t={}){return new e(t)}constructor(t={}){let{onIdle:r,idleTimeout:n=600*1e3}=t||{};this.callbacks=r?[r]:[],this.idleTimeout=n;let o=this._resetTimer.bind(this);window.addEventListener("load",o,!0),ud.forEach(s=>{document.addEventListener(s,o,!0)});let i=(s,a)=>{let c;return(...u)=>{let p=this,d=()=>{c=void 0,s.apply(p,u)};clearTimeout(c),c=window.setTimeout(d,a)}};if(t?.captureScroll){let s=i(o,t?.scrollDebounce??100);window.addEventListener("scroll",s,!0)}o()}registerCallback(t){this.callbacks.push(t)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let t=this._resetTimer.bind(this);ud.forEach(r=>{document.removeEventListener(r,t,!0)}),this.callbacks.forEach(r=>{r()})}_resetTimer(){let t=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(t,this.idleTimeout)}};var km=(e,t)=>t.some(r=>e instanceof r),dd,pd;function Lm(){return dd||(dd=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function qm(){return pd||(pd=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var fd=new WeakMap,ac=new WeakMap,hd=new WeakMap,sc=new WeakMap,lc=new WeakMap;function Mm(e){let t=new Promise((r,n)=>{let o=()=>{e.removeEventListener("success",i),e.removeEventListener("error",s)},i=()=>{r(Pt(e.result)),o()},s=()=>{n(e.error),o()};e.addEventListener("success",i),e.addEventListener("error",s)});return t.then(r=>{r instanceof IDBCursor&&fd.set(r,e)}).catch(()=>{}),lc.set(t,e),t}function jm(e){if(ac.has(e))return;let t=new Promise((r,n)=>{let o=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",s),e.removeEventListener("abort",s)},i=()=>{r(),o()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),o()};e.addEventListener("complete",i),e.addEventListener("error",s),e.addEventListener("abort",s)});ac.set(e,t)}var cc={get(e,t,r){if(e instanceof IDBTransaction){if(t==="done")return ac.get(e);if(t==="objectStoreNames")return e.objectStoreNames||hd.get(e);if(t==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return Pt(e[t])},set(e,t,r){return e[t]=r,!0},has(e,t){return e instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in e}};function md(e){cc=e(cc)}function Km(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(t,...r){let n=e.call(fs(this),t,...r);return hd.set(n,t.sort?t.sort():[t]),Pt(n)}:qm().includes(e)?function(...t){return e.apply(fs(this),t),Pt(fd.get(this))}:function(...t){return Pt(e.apply(fs(this),t))}}function Hm(e){return typeof e=="function"?Km(e):(e instanceof IDBTransaction&&jm(e),km(e,Lm())?new Proxy(e,cc):e)}function Pt(e){if(e instanceof IDBRequest)return Mm(e);if(sc.has(e))return sc.get(e);let t=Hm(e);return t!==e&&(sc.set(e,t),lc.set(t,e)),t}var fs=e=>lc.get(e);function yd(e,t,{blocked:r,upgrade:n,blocking:o,terminated:i}={}){let s=indexedDB.open(e,t),a=Pt(s);return n&&s.addEventListener("upgradeneeded",c=>{n(Pt(s.result),c.oldVersion,c.newVersion,Pt(s.transaction),c)}),r&&s.addEventListener("blocked",c=>r(c.oldVersion,c.newVersion,c)),a.then(c=>{i&&c.addEventListener("close",()=>i()),o&&c.addEventListener("versionchange",u=>o(u.oldVersion,u.newVersion,u))}).catch(()=>{}),a}var $m=["get","getKey","getAll","getAllKeys","count"],Gm=["put","add","delete","clear"],uc=new Map;function _d(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(uc.get(t))return uc.get(t);let r=t.replace(/FromIndex$/,""),n=t!==r,o=Gm.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(o||$m.includes(r)))return;let i=async function(s,...a){let c=this.transaction(s,o?"readwrite":"readonly"),u=c.store;return n&&(u=u.index(a.shift())),(await Promise.all([u[r](...a),o&&c.done]))[0]};return uc.set(t,i),i}md(e=>({...e,get:(t,r,n)=>_d(t,r)||e.get(t,r,n),has:(t,r)=>!!_d(t,r)||e.has(t,r)}));var gd="auth-client-db",xd="ic-keyval",Jm=async(e=gd,t=xd,r)=>(globalThis.localStorage?.getItem(Ke)&&(globalThis.localStorage.removeItem(Ke),globalThis.localStorage.removeItem(He)),await yd(e,r,{upgrade:n=>{n.objectStoreNames.contains(t)&&n.clear(t),n.createObjectStore(t)}}));async function zm(e,t,r){return await e.get(t,r)}async function Wm(e,t,r,n){return await e.put(t,n,r)}async function Ym(e,t,r){return await e.delete(t,r)}var hs=class e{constructor(t,r){this._db=t,this._storeName=r}static async create(t){let{dbName:r=gd,storeName:n=xd,version:o=bd}=t??{},i=await Jm(r,n,o);return new e(i,n)}async set(t,r){return await Wm(this._db,this._storeName,t,r)}async get(t){return await zm(this._db,this._storeName,t)??null}async remove(t){return await Ym(this._db,this._storeName,t)}};var He="identity",Ke="delegation",wd="iv",bd=1,oi=class{constructor(t="ic-",r){this.prefix=t,this._localStorage=r}get(t){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+t))}set(t,r){return this._getLocalStorage().setItem(this.prefix+t,r),Promise.resolve()}remove(t){return this._getLocalStorage().removeItem(this.prefix+t),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let t=globalThis.localStorage;if(!t)throw new Error("Could not find local storage.");return t}},Bt=class{#e;constructor(t){this.#e=t??{}}initializedDb;get _db(){return new Promise((t,r)=>{if(this.initializedDb){t(this.initializedDb);return}hs.create(this.#e).then(n=>{this.initializedDb=n,t(n)}).catch(r)})}async get(t){return await(await this._db).get(t)}async set(t,r){await(await this._db).set(t,r)}async remove(t){await(await this._db).remove(t)}};var Zm=BigInt(1e9),Xm=BigInt(3600),Qm=Zm*Xm,e_="https://identity.internetcomputer.org",t_="#authorize",r_=BigInt(8)*Qm,dc="ECDSA",pc="Ed25519",n_=500,ms="UserInterrupt",ii=class e{constructor(t,r,n,o,i,s,a,c){this._identity=t,this._key=r,this._chain=n,this._storage=o,this.idleManager=i,this._createOptions=s,this._idpWindow=a,this._eventHandler=c,this._registerDefaultIdleCallback()}static async create(t={}){let r=t.storage??new Bt,n=t.keyType??dc,o=null;if(t.identity)o=t.identity;else{let c=await r.get(He);if(!c)try{let u=new oi,p=await u.get(Ke),d=await u.get(He);p&&d&&n===dc&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await r.set(Ke,p),await r.set(He,d),c=p,await u.remove(Ke),await u.remove(He))}catch(u){console.error(`error while attempting to recover localstorage: ${u}`)}if(c)try{typeof c=="object"?n===pc&&typeof c=="string"?o=Nt.fromJSON(c):o=await Ct.fromKeyPair(c):typeof c=="string"&&(o=Nt.fromJSON(c))}catch{}}let i=new rt,s=null;if(o)try{let c=await r.get(Ke);if(typeof c=="object"&&c!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");t.identity?i=t.identity:c&&(s=ur.fromJSON(c),ic(s)?"toDer"in o?i=ri.fromDelegation(o,s):i=dr.fromDelegation(o,s):(await fc(r),o=null))}catch(c){console.error(c),await fc(r),o=null}let a;return t.idleOptions?.disableIdle?a=void 0:(s||t.identity)&&(a=ni.create(t.idleOptions)),o||(n===pc?o=Nt.generate():(t.storage&&n===dc&&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 '${pc}' as the key type, as it can serialize to a string`),o=await Ct.generate()),await Td(r,o)),new e(i,o,s,r,a,t)}_registerDefaultIdleCallback(){let t=this._createOptions?.idleOptions;!t?.onIdle&&!t?.disableDefaultIdleCallback&&this.idleManager?.registerCallback(()=>{this.logout(),location.reload()})}async _handleSuccess(t,r){let n=t.delegations.map(a=>({delegation:new Pr(a.delegation.pubkey,a.delegation.expiration,a.delegation.targets),signature:a.signature})),o=ur.fromDelegations(n,t.userPublicKey),i=this._key;if(!i)return;this._chain=o,"toDer"in i?this._identity=ri.fromDelegation(i,this._chain):this._identity=dr.fromDelegation(i,this._chain),this._idpWindow?.close();let s=this._createOptions?.idleOptions;!this.idleManager&&!s?.disableIdle&&(this.idleManager=ni.create(s),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(Ke,JSON.stringify(this._chain.toJSON())),await Td(this._storage,this._key),r?.(t)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null&&ic(this._chain)}async login(t){let r=o_(this._createOptions?.loginOptions,t),n=r?.maxTimeToLive??r_,o=new URL(r?.identityProvider?.toString()||e_);o.hash=t_,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 i=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(ms,r?.onError):setTimeout(i,n_))};i()}_getEventHandler(t,r){return async n=>{if(n.origin!==t.origin)return;let o=n.data;switch(o.kind){case"authorize-ready":{let i={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(i,t.origin);break}case"authorize-client-success":try{await this._handleSuccess(o,r?.onSuccess)}catch(i){this._handleFailure(i.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(o.text,r?.onError);break}}}_handleFailure(t,r){this._idpWindow?.close(),r?.(t),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(t={}){if(await fc(this._storage),this._identity=new rt,this._chain=null,t.returnTo)try{window.history.pushState({},"",t.returnTo)}catch{window.location.href=t.returnTo}}};async function fc(e){await e.remove(He),await e.remove(Ke),await e.remove(wd)}function o_(e,t){if(!e&&!t)return;let r=e?.customValues||t?.customValues?{...e?.customValues,...t?.customValues}:void 0;return{...e,...t,customValues:r}}function i_(e){if(e instanceof Ct)return e.getKeyPair();if(e instanceof Nt)return JSON.stringify(e.toJSON());throw new Error("Unsupported key type")}async function Td(e,t){let r=i_(t);await e.set(He,r)}var $e=class e{static#e;#t;constructor(){}static getInstance(){return q(this.#e)&&(this.#e=new e),this.#e}createAuthClient=async()=>(this.#t=await ii.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}}),this.#t);safeCreateAuthClient=async()=>(await new Bt().remove(He),await this.createAuthClient());getAuthClient=()=>this.#t;logout=async()=>{await this.#t?.logout(),this.#t=null};setAuthClientStorage=async({delegationChain:t,sessionKey:r})=>{let n=new Bt;await Promise.all([n.set(He,r.getKeyPair()),n.set(Ke,JSON.stringify(t.toJSON()))])}};var hc=async e=>{await s_(),await $e.getInstance().createAuthClient(),e?.windowReload!==!1&&window.location.reload()},s_=async()=>{await $e.getInstance().logout(),je.getInstance().reset(),lo.getInstance().reset(),co.getInstance().reset()};var Nd=e=>{let t=e===!0?"./workers/auth.worker.js":e,r=new Worker(t),n=async()=>{rc({message:"junoSignOutAuthTimer"}),await hc()};return r.onmessage=async({data:o})=>{let{msg:i,data:s}=o;switch(i){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":rc({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},je.getInstance().subscribe(o=>{if(q(o)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var si=async({fn:e})=>{let{createAuthClient:t,safeCreateAuthClient:r}=$e.getInstance();if(!await(await t()).isAuthenticated()){await r();return}await e()};var mc=({error:e,type:t})=>typeof e=="string"?e.includes(t):e instanceof Error?e.message.includes(t):!1;var Od="juno.datastore.error.user.cannot_update";var Dt={certified:!1};var _s=()=>$e.getInstance().getAuthClient()?.getIdentity(),a_=async()=>{let{getAuthClient:e,createAuthClient:t}=$e.getInstance();return(e()??await t()).getIdentity()},c_=async()=>{let e=je.getInstance().get();if(q(e))return null;let t=$e.getInstance().getAuthClient();return await t?.isAuthenticated()??!1?t?.getIdentity()??null:null};var de=e=>X(e)?e:_s()??new rt;var _c=({IDL:e})=>{let t=e.Variant({Heap:e.Null,Stable:e.Null}),r=e.Record({system_memory:e.Opt(t)}),n=e.Record({controllers:e.Vec(e.Principal),storage:e.Opt(r)}),o=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),i=e.Variant({OpenId:o}),s=e.Record({updated_at:e.Nat64,owner:e.Principal,data:e.Vec(e.Nat8),description:e.Opt(e.Text),created_at:e.Nat64,version:e.Opt(e.Nat64)}),a=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),c=e.Record({doc:s,delegation:a}),u=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),p=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),d=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),l=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,JwtVerify:p,GetOrFetchJwks:d,DeriveSeedFailed:e.Text}),f=e.Variant({PrepareDelegation:l,RegisterUser:e.Text}),h=e.Variant({Ok:c,Err:f}),m=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),g=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),_=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),x=e.Record({field:_,desc:e.Bool}),y=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),T=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(y),description:e.Opt(e.Text),created_at:e.Opt(y)}),E=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),O=e.Record({order:e.Opt(x),owner:e.Opt(e.Principal),matcher:e.Opt(T),paginate:e.Opt(E)}),R=e.Record({controllers:e.Vec(e.Principal)}),I=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),w=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,scope:I,expires_at:e.Opt(e.Nat64)}),v=e.Record({version:e.Opt(e.Nat64)}),V=e.Variant({Db:e.Null,Storage:e.Null}),S=e.Record({version:e.Opt(e.Nat64)}),b=e.Record({proposal_ids:e.Vec(e.Nat)}),N=e.Record({cycles:e.Nat,destination_id:e.Principal}),F=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),B=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),k=e.Record({key:F,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,B)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),A=e.Variant({Google:e.Null}),C=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),P=e.Record({delegation:e.Opt(C),client_id:e.Text}),D=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(A,P))}),U=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),te=e.Record({allowed_callers:e.Vec(e.Principal)}),Q=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(D),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(U),rules:e.Opt(te)}),$=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),ie=e.Record({updated_at:e.Opt(e.Nat64),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt($)}),pe=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),Ae=e.Variant({Deny:e.Null,Allow:e.Null}),re=e.Record({status_code:e.Nat16,location:e.Text}),ce=e.Record({iframe:e.Opt(pe),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt($),raw_access:e.Opt(Ae),redirects:e.Opt(e.Vec(e.Tuple(e.Text,re)))}),Dr=e.Record({db:e.Opt(ie),authentication:e.Opt(Q),storage:ce}),kt=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Ye=e.Variant({OpenId:kt}),Ur=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),kr=e.Record({signature:e.Vec(e.Nat8),delegation:Ur}),at=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:p,GetOrFetchJwks:d,DeriveSeedFailed:e.Text}),Lr=e.Variant({Ok:kr,Err:at}),qr=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),Mr=e.Record({clear_existing_assets:e.Opt(e.Bool)}),Lt=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),ct=e.Variant({AssetsUpgrade:Mr,SegmentsDeployment:Lt}),Ze=e.Record({status:qr,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:ct}),Xe=e.Variant({Controllers:e.Null,Private:e.Null,Public:e.Null,Managed:e.Null}),lt=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),ut=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(t),updated_at:e.Nat64,max_size:e.Opt(e.Nat),read:Xe,created_at:e.Nat64,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(lt),write:Xe,max_changes_per_user:e.Opt(e.Nat32)}),jr=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),dt=e.Record({memory:t,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),Kr=e.Variant({Callback:e.Record({token:dt,callback:e.Func([],[],["query"])})}),Hr=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(Kr),status_code:e.Nat16}),$r=e.Record({token:e.Opt(dt),body:e.Vec(e.Nat8)}),pt=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),Qe=e.Record({batch_id:e.Nat}),Gr=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,k)),items_length:e.Nat64}),Jr=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),zr=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,s)),items_length:e.Nat64}),Wr=e.Record({desc:e.Bool}),Yr=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),Zr=e.Record({order:e.Opt(Wr),paginate:e.Opt(Yr)}),Xr=e.Record({proposal_id:e.Nat}),Qr=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(Xr,Ze)),items_length:e.Nat64}),en=e.Record({include_system:e.Bool}),tn=e.Record({matcher:e.Opt(en)}),rn=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(e.Text,ut)),items_length:e.Nat64}),nn=e.Record({stable:e.Nat64,heap:e.Nat64}),qt=e.Record({openid:e.Opt(D),version:e.Opt(e.Nat64),internet_identity:e.Opt(U),rules:e.Opt(te)}),on=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),scope:I,expires_at:e.Opt(e.Nat64)}),sn=e.Record({controller:on,controllers:e.Vec(e.Principal)}),an=e.Record({version:e.Opt(e.Nat64),max_memory_size:e.Opt($)}),Mt=e.Record({data:e.Vec(e.Nat8),description:e.Opt(e.Text),version:e.Opt(e.Nat64)}),Ps=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(t),max_size:e.Opt(e.Nat),read:Xe,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(lt),write:Xe,max_changes_per_user:e.Opt(e.Nat32)}),Bs=e.Record({iframe:e.Opt(pe),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt($),raw_access:e.Opt(Ae),redirects:e.Opt(e.Vec(e.Tuple(e.Text,re)))}),po=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),fo=e.Record({chunk_id:e.Nat});return e.Service({authenticate:e.Func([i],[h],[]),commit_asset_upload:e.Func([m],[],[]),commit_proposal:e.Func([g],[e.Null],[]),commit_proposal_asset_upload:e.Func([m],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(m)],[],[]),count_assets:e.Func([e.Text,O],[e.Nat64],["query"]),count_collection_assets:e.Func([e.Text],[e.Nat64],["query"]),count_collection_docs:e.Func([e.Text],[e.Nat64],["query"]),count_docs:e.Func([e.Text,O],[e.Nat64],["query"]),count_proposals:e.Func([],[e.Nat64],["query"]),del_asset:e.Func([e.Text,e.Text],[],[]),del_assets:e.Func([e.Text],[],[]),del_controllers:e.Func([R],[e.Vec(e.Tuple(e.Principal,w))],[]),del_custom_domain:e.Func([e.Text],[],[]),del_doc:e.Func([e.Text,e.Text,v],[],[]),del_docs:e.Func([e.Text],[],[]),del_filtered_assets:e.Func([e.Text,O],[],[]),del_filtered_docs:e.Func([e.Text,O],[],[]),del_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[],[]),del_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,v))],[],[]),del_rule:e.Func([V,e.Text,S],[],[]),delete_proposal_assets:e.Func([b],[],[]),deposit_cycles:e.Func([N],[],[]),get_asset:e.Func([e.Text,e.Text],[e.Opt(k)],["query"]),get_auth_config:e.Func([],[e.Opt(Q)],["query"]),get_config:e.Func([],[Dr],[]),get_db_config:e.Func([],[e.Opt(ie)],["query"]),get_delegation:e.Func([Ye],[Lr],["query"]),get_doc:e.Func([e.Text,e.Text],[e.Opt(s)],["query"]),get_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(k)))],["query"]),get_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(s)))],["query"]),get_proposal:e.Func([e.Nat],[e.Opt(Ze)],["query"]),get_rule:e.Func([V,e.Text],[e.Opt(ut)],["query"]),get_storage_config:e.Func([],[ce],["query"]),http_request:e.Func([jr],[Hr],["query"]),http_request_streaming_callback:e.Func([dt],[$r],["query"]),init_asset_upload:e.Func([pt],[Qe],[]),init_proposal:e.Func([ct],[e.Nat,Ze],[]),init_proposal_asset_upload:e.Func([pt,e.Nat],[Qe],[]),init_proposal_many_assets_upload:e.Func([e.Vec(pt),e.Nat],[e.Vec(e.Tuple(e.Text,Qe))],[]),list_assets:e.Func([e.Text,O],[Gr],["query"]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,w))],["query"]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,Jr))],["query"]),list_docs:e.Func([e.Text,O],[zr],["query"]),list_proposals:e.Func([Zr],[Qr],["query"]),list_rules:e.Func([V,tn],[rn],["query"]),memory_size:e.Func([],[nn],["query"]),reject_proposal:e.Func([g],[e.Null],[]),set_auth_config:e.Func([qt],[Q],[]),set_controllers:e.Func([sn],[e.Vec(e.Tuple(e.Principal,w))],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_db_config:e.Func([an],[ie],[]),set_doc:e.Func([e.Text,e.Text,Mt],[s],[]),set_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,Mt))],[e.Vec(e.Tuple(e.Text,s))],[]),set_rule:e.Func([V,e.Text,Ps],[ut],[]),set_storage_config:e.Func([Bs],[ce],[]),submit_proposal:e.Func([e.Nat],[e.Nat,Ze],[]),switch_storage_system_memory:e.Func([],[],[]),upload_asset_chunk:e.Func([po],[fo],[]),upload_proposal_asset_chunk:e.Func([po],[fo],[])})},yc=({IDL:e})=>{let t=e.Variant({Heap:e.Null,Stable:e.Null}),r=e.Record({system_memory:e.Opt(t)}),n=e.Record({controllers:e.Vec(e.Principal),storage:e.Opt(r)}),o=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),i=e.Variant({OpenId:o}),s=e.Record({updated_at:e.Nat64,owner:e.Principal,data:e.Vec(e.Nat8),description:e.Opt(e.Text),created_at:e.Nat64,version:e.Opt(e.Nat64)}),a=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),c=e.Record({doc:s,delegation:a}),u=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),p=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),d=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),l=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,JwtVerify:p,GetOrFetchJwks:d,DeriveSeedFailed:e.Text}),f=e.Variant({PrepareDelegation:l,RegisterUser:e.Text}),h=e.Variant({Ok:c,Err:f}),m=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),g=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),_=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),x=e.Record({field:_,desc:e.Bool}),y=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),T=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(y),description:e.Opt(e.Text),created_at:e.Opt(y)}),E=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),O=e.Record({order:e.Opt(x),owner:e.Opt(e.Principal),matcher:e.Opt(T),paginate:e.Opt(E)}),R=e.Record({controllers:e.Vec(e.Principal)}),I=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),w=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,scope:I,expires_at:e.Opt(e.Nat64)}),v=e.Record({version:e.Opt(e.Nat64)}),V=e.Variant({Db:e.Null,Storage:e.Null}),S=e.Record({version:e.Opt(e.Nat64)}),b=e.Record({proposal_ids:e.Vec(e.Nat)}),N=e.Record({cycles:e.Nat,destination_id:e.Principal}),F=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),B=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),k=e.Record({key:F,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,B)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),A=e.Variant({Google:e.Null}),C=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),P=e.Record({delegation:e.Opt(C),client_id:e.Text}),D=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(A,P))}),U=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),te=e.Record({allowed_callers:e.Vec(e.Principal)}),Q=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(D),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(U),rules:e.Opt(te)}),$=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),ie=e.Record({updated_at:e.Opt(e.Nat64),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt($)}),pe=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),Ae=e.Variant({Deny:e.Null,Allow:e.Null}),re=e.Record({status_code:e.Nat16,location:e.Text}),ce=e.Record({iframe:e.Opt(pe),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt($),raw_access:e.Opt(Ae),redirects:e.Opt(e.Vec(e.Tuple(e.Text,re)))}),Dr=e.Record({db:e.Opt(ie),authentication:e.Opt(Q),storage:ce}),kt=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Ye=e.Variant({OpenId:kt}),Ur=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),kr=e.Record({signature:e.Vec(e.Nat8),delegation:Ur}),at=e.Variant({JwtFindProvider:u,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:p,GetOrFetchJwks:d,DeriveSeedFailed:e.Text}),Lr=e.Variant({Ok:kr,Err:at}),qr=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),Mr=e.Record({clear_existing_assets:e.Opt(e.Bool)}),Lt=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),ct=e.Variant({AssetsUpgrade:Mr,SegmentsDeployment:Lt}),Ze=e.Record({status:qr,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:ct}),Xe=e.Variant({Controllers:e.Null,Private:e.Null,Public:e.Null,Managed:e.Null}),lt=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),ut=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(t),updated_at:e.Nat64,max_size:e.Opt(e.Nat),read:Xe,created_at:e.Nat64,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(lt),write:Xe,max_changes_per_user:e.Opt(e.Nat32)}),jr=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),dt=e.Record({memory:t,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),Kr=e.Variant({Callback:e.Record({token:dt,callback:e.Func([],[],[])})}),Hr=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(Kr),status_code:e.Nat16}),$r=e.Record({token:e.Opt(dt),body:e.Vec(e.Nat8)}),pt=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),Qe=e.Record({batch_id:e.Nat}),Gr=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,k)),items_length:e.Nat64}),Jr=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),zr=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,s)),items_length:e.Nat64}),Wr=e.Record({desc:e.Bool}),Yr=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),Zr=e.Record({order:e.Opt(Wr),paginate:e.Opt(Yr)}),Xr=e.Record({proposal_id:e.Nat}),Qr=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(Xr,Ze)),items_length:e.Nat64}),en=e.Record({include_system:e.Bool}),tn=e.Record({matcher:e.Opt(en)}),rn=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(e.Text,ut)),items_length:e.Nat64}),nn=e.Record({stable:e.Nat64,heap:e.Nat64}),qt=e.Record({openid:e.Opt(D),version:e.Opt(e.Nat64),internet_identity:e.Opt(U),rules:e.Opt(te)}),on=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),scope:I,expires_at:e.Opt(e.Nat64)}),sn=e.Record({controller:on,controllers:e.Vec(e.Principal)}),an=e.Record({version:e.Opt(e.Nat64),max_memory_size:e.Opt($)}),Mt=e.Record({data:e.Vec(e.Nat8),description:e.Opt(e.Text),version:e.Opt(e.Nat64)}),Ps=e.Record({max_capacity:e.Opt(e.Nat32),memory:e.Opt(t),max_size:e.Opt(e.Nat),read:Xe,version:e.Opt(e.Nat64),mutable_permissions:e.Opt(e.Bool),rate_config:e.Opt(lt),write:Xe,max_changes_per_user:e.Opt(e.Nat32)}),Bs=e.Record({iframe:e.Opt(pe),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt($),raw_access:e.Opt(Ae),redirects:e.Opt(e.Vec(e.Tuple(e.Text,re)))}),po=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),fo=e.Record({chunk_id:e.Nat});return e.Service({authenticate:e.Func([i],[h],[]),commit_asset_upload:e.Func([m],[],[]),commit_proposal:e.Func([g],[e.Null],[]),commit_proposal_asset_upload:e.Func([m],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(m)],[],[]),count_assets:e.Func([e.Text,O],[e.Nat64],[]),count_collection_assets:e.Func([e.Text],[e.Nat64],[]),count_collection_docs:e.Func([e.Text],[e.Nat64],[]),count_docs:e.Func([e.Text,O],[e.Nat64],[]),count_proposals:e.Func([],[e.Nat64],[]),del_asset:e.Func([e.Text,e.Text],[],[]),del_assets:e.Func([e.Text],[],[]),del_controllers:e.Func([R],[e.Vec(e.Tuple(e.Principal,w))],[]),del_custom_domain:e.Func([e.Text],[],[]),del_doc:e.Func([e.Text,e.Text,v],[],[]),del_docs:e.Func([e.Text],[],[]),del_filtered_assets:e.Func([e.Text,O],[],[]),del_filtered_docs:e.Func([e.Text,O],[],[]),del_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[],[]),del_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,v))],[],[]),del_rule:e.Func([V,e.Text,S],[],[]),delete_proposal_assets:e.Func([b],[],[]),deposit_cycles:e.Func([N],[],[]),get_asset:e.Func([e.Text,e.Text],[e.Opt(k)],[]),get_auth_config:e.Func([],[e.Opt(Q)],[]),get_config:e.Func([],[Dr],[]),get_db_config:e.Func([],[e.Opt(ie)],[]),get_delegation:e.Func([Ye],[Lr],[]),get_doc:e.Func([e.Text,e.Text],[e.Opt(s)],[]),get_many_assets:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(k)))],[]),get_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text))],[e.Vec(e.Tuple(e.Text,e.Opt(s)))],[]),get_proposal:e.Func([e.Nat],[e.Opt(Ze)],[]),get_rule:e.Func([V,e.Text],[e.Opt(ut)],[]),get_storage_config:e.Func([],[ce],[]),http_request:e.Func([jr],[Hr],[]),http_request_streaming_callback:e.Func([dt],[$r],[]),init_asset_upload:e.Func([pt],[Qe],[]),init_proposal:e.Func([ct],[e.Nat,Ze],[]),init_proposal_asset_upload:e.Func([pt,e.Nat],[Qe],[]),init_proposal_many_assets_upload:e.Func([e.Vec(pt),e.Nat],[e.Vec(e.Tuple(e.Text,Qe))],[]),list_assets:e.Func([e.Text,O],[Gr],[]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,w))],[]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,Jr))],[]),list_docs:e.Func([e.Text,O],[zr],[]),list_proposals:e.Func([Zr],[Qr],[]),list_rules:e.Func([V,tn],[rn],[]),memory_size:e.Func([],[nn],[]),reject_proposal:e.Func([g],[e.Null],[]),set_auth_config:e.Func([qt],[Q],[]),set_controllers:e.Func([sn],[e.Vec(e.Tuple(e.Principal,w))],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_db_config:e.Func([an],[ie],[]),set_doc:e.Func([e.Text,e.Text,Mt],[s],[]),set_many_docs:e.Func([e.Vec(e.Tuple(e.Text,e.Text,Mt))],[e.Vec(e.Tuple(e.Text,s))],[]),set_rule:e.Func([V,e.Text,Ps],[ut],[]),set_storage_config:e.Func([Bs],[ce],[]),submit_proposal:e.Func([e.Nat],[e.Nat,Ze],[]),switch_storage_system_memory:e.Func([],[],[]),upload_asset_chunk:e.Func([po],[fo],[]),upload_proposal_asset_chunk:e.Func([po],[fo],[])})},l_=({IDL:e})=>{let t=e.Record({e8s:e.Nat64}),r=e.Record({mission_control_id:e.Principal,user:e.Principal}),n=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),o=e.Variant({OpenId:n}),i=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),s=e.Variant({Google:e.Null}),a=e.Record({name:e.Opt(e.Text),locale:e.Opt(e.Text),family_name:e.Opt(e.Text),email:e.Opt(e.Text),picture:e.Opt(e.Text),given_name:e.Opt(e.Text)}),c=e.Record({provider:s,data:a}),u=e.Variant({InternetIdentity:e.Null,OpenId:c}),p=e.Record({updated_at:e.Nat64,credits:t,mission_control_id:e.Opt(e.Principal),provider:e.Opt(u),owner:e.Principal,created_at:e.Nat64}),d=e.Record({delegation:i,mission_control:p}),l=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),f=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),h=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),m=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,JwtVerify:f,GetOrFetchJwks:h,DeriveSeedFailed:e.Text}),g=e.Variant({PrepareDelegation:m,RegisterUser:e.Text}),_=e.Variant({Ok:d,Err:g}),x=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),y=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),T=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),user:e.Principal}),E=e.Variant({Heap:e.Null,Stable:e.Null}),O=e.Record({system_memory:e.Opt(E)}),R=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),storage:e.Opt(O),user:e.Principal}),I=e.Record({controllers:e.Vec(e.Principal)}),w=e.Record({proposal_ids:e.Vec(e.Nat)}),v=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),V=e.Record({delegation:e.Opt(v),client_id:e.Text}),S=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(s,V))}),b=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),N=e.Record({allowed_callers:e.Vec(e.Principal)}),F=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(S),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(b),rules:e.Opt(N)}),B=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),k=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),A=e.Variant({Deny:e.Null,Allow:e.Null}),C=e.Record({status_code:e.Nat16,location:e.Text}),P=e.Record({iframe:e.Opt(B),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(k),raw_access:e.Opt(A),redirects:e.Opt(e.Vec(e.Tuple(e.Text,C)))}),D=e.Record({authentication:e.Opt(F),storage:P}),U=e.Record({user:e.Principal}),te=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Q=e.Variant({OpenId:te}),$=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),ie=e.Record({signature:e.Vec(e.Nat8),delegation:$}),pe=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:f,GetOrFetchJwks:h,DeriveSeedFailed:e.Text}),Ae=e.Variant({Ok:ie,Err:pe}),re=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),ce=e.Record({clear_existing_assets:e.Opt(e.Bool)}),Dr=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),kt=e.Variant({AssetsUpgrade:ce,SegmentsDeployment:Dr}),Ye=e.Record({status:re,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:kt}),Ur=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),kr=e.Variant({Heap:e.Null,Stable:e.Null}),at=e.Record({memory:kr,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),Lr=e.Variant({Callback:e.Record({token:at,callback:e.Func([],[],["query"])})}),qr=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(Lr),status_code:e.Nat16}),Mr=e.Record({token:e.Opt(at),body:e.Vec(e.Nat8)}),Lt=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),ct=e.Record({batch_id:e.Nat}),Ze=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),Xe=e.Record({field:Ze,desc:e.Bool}),lt=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),ut=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(lt),description:e.Opt(e.Text),created_at:e.Opt(lt)}),jr=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),dt=e.Record({order:e.Opt(Xe),owner:e.Opt(e.Principal),matcher:e.Opt(ut),paginate:e.Opt(jr)}),Kr=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),Hr=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),$r=e.Record({key:Kr,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,Hr)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),pt=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,$r)),items_length:e.Nat64}),Qe=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),Gr=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,scope:Qe,expires_at:e.Opt(e.Nat64)}),Jr=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),zr=e.Variant({Refunded:e.Null,Acknowledged:e.Null,Completed:e.Null}),Wr=e.Record({status:zr,updated_at:e.Nat64,block_index_payment:e.Nat64,mission_control_id:e.Opt(e.Principal),created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64)}),Yr=e.Record({desc:e.Bool}),Zr=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),Xr=e.Record({order:e.Opt(Yr),paginate:e.Opt(Zr)}),Qr=e.Record({proposal_id:e.Nat}),en=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(Qr,Ye)),items_length:e.Nat64}),tn=e.Record({openid:e.Opt(S),version:e.Opt(e.Nat64),internet_identity:e.Opt(b),rules:e.Opt(N)}),rn=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),scope:Qe,expires_at:e.Opt(e.Nat64)}),nn=e.Record({controller:rn,controllers:e.Vec(e.Principal)}),qt=e.Variant({Orbiter:e.Null,MissionControl:e.Null,Satellite:e.Null}),on=e.Record({iframe:e.Opt(B),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(k),raw_access:e.Opt(A),redirects:e.Opt(e.Vec(e.Tuple(e.Text,C)))}),sn=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),an=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),Mt=e.Record({chunk_id:e.Nat});return e.Service({add_credits:e.Func([e.Principal,t],[],[]),add_invitation_code:e.Func([e.Text],[],[]),assert_mission_control_center:e.Func([r],[],["query"]),authenticate:e.Func([o],[_],[]),commit_proposal:e.Func([x],[e.Null],[]),commit_proposal_asset_upload:e.Func([y],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(y)],[],[]),count_proposals:e.Func([],[e.Nat64],["query"]),create_orbiter:e.Func([T],[e.Principal],[]),create_satellite:e.Func([R],[e.Principal],[]),del_controllers:e.Func([I],[],[]),del_custom_domain:e.Func([e.Text],[],[]),delete_proposal_assets:e.Func([w],[],[]),get_auth_config:e.Func([],[e.Opt(F)],["query"]),get_config:e.Func([],[D],["query"]),get_create_orbiter_fee:e.Func([U],[e.Opt(t)],["query"]),get_create_satellite_fee:e.Func([U],[e.Opt(t)],["query"]),get_credits:e.Func([],[t],["query"]),get_delegation:e.Func([Q],[Ae],["query"]),get_proposal:e.Func([e.Nat],[e.Opt(Ye)],["query"]),get_storage_config:e.Func([],[P],["query"]),get_user_mission_control_center:e.Func([],[e.Opt(p)],["query"]),http_request:e.Func([Ur],[qr],["query"]),http_request_streaming_callback:e.Func([at],[Mr],["query"]),init_proposal:e.Func([kt],[e.Nat,Ye],[]),init_proposal_asset_upload:e.Func([Lt,e.Nat],[ct],[]),init_proposal_many_assets_upload:e.Func([e.Vec(Lt),e.Nat],[e.Vec(e.Tuple(e.Text,ct))],[]),init_user_mission_control_center:e.Func([],[p],[]),list_assets:e.Func([e.Text,dt],[pt],["query"]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,Gr))],["query"]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,Jr))],["query"]),list_payments:e.Func([],[e.Vec(e.Tuple(e.Nat64,Wr))],["query"]),list_proposals:e.Func([Xr],[en],["query"]),list_user_mission_control_centers:e.Func([],[e.Vec(e.Tuple(e.Principal,p))],["query"]),reject_proposal:e.Func([x],[e.Null],[]),set_auth_config:e.Func([tn],[F],[]),set_controllers:e.Func([nn],[],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_fee:e.Func([qt,t],[],[]),set_storage_config:e.Func([on],[P],[]),submit_proposal:e.Func([e.Nat],[e.Nat,Ye],[]),update_rate_config:e.Func([qt,sn],[],[]),upload_proposal_asset_chunk:e.Func([an],[Mt],[])})},u_=({IDL:e})=>{let t=e.Record({e8s:e.Nat64}),r=e.Record({mission_control_id:e.Principal,user:e.Principal}),n=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8)}),o=e.Variant({OpenId:n}),i=e.Record({user_key:e.Vec(e.Nat8),expiration:e.Nat64}),s=e.Variant({Google:e.Null}),a=e.Record({name:e.Opt(e.Text),locale:e.Opt(e.Text),family_name:e.Opt(e.Text),email:e.Opt(e.Text),picture:e.Opt(e.Text),given_name:e.Opt(e.Text)}),c=e.Record({provider:s,data:a}),u=e.Variant({InternetIdentity:e.Null,OpenId:c}),p=e.Record({updated_at:e.Nat64,credits:t,mission_control_id:e.Opt(e.Principal),provider:e.Opt(u),owner:e.Principal,created_at:e.Nat64}),d=e.Record({delegation:i,mission_control:p}),l=e.Variant({BadClaim:e.Text,BadSig:e.Text,NoMatchingProvider:e.Null}),f=e.Variant({WrongKeyType:e.Null,MissingKid:e.Null,BadClaim:e.Text,BadSig:e.Text,NoKeyForKid:e.Null}),h=e.Variant({InvalidConfig:e.Text,MissingKid:e.Null,BadClaim:e.Text,KeyNotFoundCooldown:e.Null,CertificateNotFound:e.Null,BadSig:e.Text,MissingLastAttempt:e.Text,KeyNotFound:e.Null,FetchFailed:e.Text}),m=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,JwtVerify:f,GetOrFetchJwks:h,DeriveSeedFailed:e.Text}),g=e.Variant({PrepareDelegation:m,RegisterUser:e.Text}),_=e.Variant({Ok:d,Err:g}),x=e.Record({sha256:e.Vec(e.Nat8),proposal_id:e.Nat}),y=e.Record({batch_id:e.Nat,headers:e.Vec(e.Tuple(e.Text,e.Text)),chunk_ids:e.Vec(e.Nat)}),T=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),user:e.Principal}),E=e.Variant({Heap:e.Null,Stable:e.Null}),O=e.Record({system_memory:e.Opt(E)}),R=e.Record({block_index:e.Opt(e.Nat64),subnet_id:e.Opt(e.Principal),storage:e.Opt(O),user:e.Principal}),I=e.Record({controllers:e.Vec(e.Principal)}),w=e.Record({proposal_ids:e.Vec(e.Nat)}),v=e.Record({targets:e.Opt(e.Vec(e.Principal)),max_time_to_live:e.Opt(e.Nat64)}),V=e.Record({delegation:e.Opt(v),client_id:e.Text}),S=e.Record({observatory_id:e.Opt(e.Principal),providers:e.Vec(e.Tuple(s,V))}),b=e.Record({derivation_origin:e.Opt(e.Text),external_alternative_origins:e.Opt(e.Vec(e.Text))}),N=e.Record({allowed_callers:e.Vec(e.Principal)}),F=e.Record({updated_at:e.Opt(e.Nat64),openid:e.Opt(S),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),internet_identity:e.Opt(b),rules:e.Opt(N)}),B=e.Variant({Deny:e.Null,AllowAny:e.Null,SameOrigin:e.Null}),k=e.Record({stable:e.Opt(e.Nat64),heap:e.Opt(e.Nat64)}),A=e.Variant({Deny:e.Null,Allow:e.Null}),C=e.Record({status_code:e.Nat16,location:e.Text}),P=e.Record({iframe:e.Opt(B),updated_at:e.Opt(e.Nat64),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),created_at:e.Opt(e.Nat64),version:e.Opt(e.Nat64),max_memory_size:e.Opt(k),raw_access:e.Opt(A),redirects:e.Opt(e.Vec(e.Tuple(e.Text,C)))}),D=e.Record({authentication:e.Opt(F),storage:P}),U=e.Record({user:e.Principal}),te=e.Record({jwt:e.Text,session_key:e.Vec(e.Nat8),salt:e.Vec(e.Nat8),expiration:e.Nat64}),Q=e.Variant({OpenId:te}),$=e.Record({pubkey:e.Vec(e.Nat8),targets:e.Opt(e.Vec(e.Principal)),expiration:e.Nat64}),ie=e.Record({signature:e.Vec(e.Nat8),delegation:$}),pe=e.Variant({JwtFindProvider:l,GetCachedJwks:e.Null,NoSuchDelegation:e.Null,JwtVerify:f,GetOrFetchJwks:h,DeriveSeedFailed:e.Text}),Ae=e.Variant({Ok:ie,Err:pe}),re=e.Variant({Initialized:e.Null,Failed:e.Null,Open:e.Null,Rejected:e.Null,Executed:e.Null,Accepted:e.Null}),ce=e.Record({clear_existing_assets:e.Opt(e.Bool)}),Dr=e.Record({orbiter:e.Opt(e.Text),mission_control_version:e.Opt(e.Text),satellite_version:e.Opt(e.Text)}),kt=e.Variant({AssetsUpgrade:ce,SegmentsDeployment:Dr}),Ye=e.Record({status:re,updated_at:e.Nat64,sha256:e.Opt(e.Vec(e.Nat8)),executed_at:e.Opt(e.Nat64),owner:e.Principal,created_at:e.Nat64,version:e.Opt(e.Nat64),proposal_type:kt}),Ur=e.Record({url:e.Text,method:e.Text,body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),certificate_version:e.Opt(e.Nat16)}),kr=e.Variant({Heap:e.Null,Stable:e.Null}),at=e.Record({memory:kr,token:e.Opt(e.Text),sha256:e.Opt(e.Vec(e.Nat8)),headers:e.Vec(e.Tuple(e.Text,e.Text)),index:e.Nat64,encoding_type:e.Text,full_path:e.Text}),Lr=e.Variant({Callback:e.Record({token:at,callback:e.Func([],[],[])})}),qr=e.Record({body:e.Vec(e.Nat8),headers:e.Vec(e.Tuple(e.Text,e.Text)),streaming_strategy:e.Opt(Lr),status_code:e.Nat16}),Mr=e.Record({token:e.Opt(at),body:e.Vec(e.Nat8)}),Lt=e.Record({token:e.Opt(e.Text),collection:e.Text,name:e.Text,description:e.Opt(e.Text),encoding_type:e.Opt(e.Text),full_path:e.Text}),ct=e.Record({batch_id:e.Nat}),Ze=e.Variant({UpdatedAt:e.Null,Keys:e.Null,CreatedAt:e.Null}),Xe=e.Record({field:Ze,desc:e.Bool}),lt=e.Variant({Equal:e.Nat64,Between:e.Tuple(e.Nat64,e.Nat64),GreaterThan:e.Nat64,LessThan:e.Nat64}),ut=e.Record({key:e.Opt(e.Text),updated_at:e.Opt(lt),description:e.Opt(e.Text),created_at:e.Opt(lt)}),jr=e.Record({start_after:e.Opt(e.Text),limit:e.Opt(e.Nat64)}),dt=e.Record({order:e.Opt(Xe),owner:e.Opt(e.Principal),matcher:e.Opt(ut),paginate:e.Opt(jr)}),Kr=e.Record({token:e.Opt(e.Text),collection:e.Text,owner:e.Principal,name:e.Text,description:e.Opt(e.Text),full_path:e.Text}),Hr=e.Record({modified:e.Nat64,sha256:e.Vec(e.Nat8),total_length:e.Nat}),$r=e.Record({key:Kr,updated_at:e.Nat64,encodings:e.Vec(e.Tuple(e.Text,Hr)),headers:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,version:e.Opt(e.Nat64)}),pt=e.Record({matches_pages:e.Opt(e.Nat64),matches_length:e.Nat64,items_page:e.Opt(e.Nat64),items:e.Vec(e.Tuple(e.Text,$r)),items_length:e.Nat64}),Qe=e.Variant({Write:e.Null,Admin:e.Null,Submit:e.Null}),Gr=e.Record({updated_at:e.Nat64,metadata:e.Vec(e.Tuple(e.Text,e.Text)),created_at:e.Nat64,scope:Qe,expires_at:e.Opt(e.Nat64)}),Jr=e.Record({updated_at:e.Nat64,created_at:e.Nat64,version:e.Opt(e.Nat64),bn_id:e.Opt(e.Text)}),zr=e.Variant({Refunded:e.Null,Acknowledged:e.Null,Completed:e.Null}),Wr=e.Record({status:zr,updated_at:e.Nat64,block_index_payment:e.Nat64,mission_control_id:e.Opt(e.Principal),created_at:e.Nat64,block_index_refunded:e.Opt(e.Nat64)}),Yr=e.Record({desc:e.Bool}),Zr=e.Record({start_after:e.Opt(e.Nat),limit:e.Opt(e.Nat)}),Xr=e.Record({order:e.Opt(Yr),paginate:e.Opt(Zr)}),Qr=e.Record({proposal_id:e.Nat}),en=e.Record({matches_length:e.Nat64,items:e.Vec(e.Tuple(Qr,Ye)),items_length:e.Nat64}),tn=e.Record({openid:e.Opt(S),version:e.Opt(e.Nat64),internet_identity:e.Opt(b),rules:e.Opt(N)}),rn=e.Record({metadata:e.Vec(e.Tuple(e.Text,e.Text)),scope:Qe,expires_at:e.Opt(e.Nat64)}),nn=e.Record({controller:rn,controllers:e.Vec(e.Principal)}),qt=e.Variant({Orbiter:e.Null,MissionControl:e.Null,Satellite:e.Null}),on=e.Record({iframe:e.Opt(B),rewrites:e.Vec(e.Tuple(e.Text,e.Text)),headers:e.Vec(e.Tuple(e.Text,e.Vec(e.Tuple(e.Text,e.Text)))),version:e.Opt(e.Nat64),max_memory_size:e.Opt(k),raw_access:e.Opt(A),redirects:e.Opt(e.Vec(e.Tuple(e.Text,C)))}),sn=e.Record({max_tokens:e.Nat64,time_per_token_ns:e.Nat64}),an=e.Record({content:e.Vec(e.Nat8),batch_id:e.Nat,order_id:e.Opt(e.Nat)}),Mt=e.Record({chunk_id:e.Nat});return e.Service({add_credits:e.Func([e.Principal,t],[],[]),add_invitation_code:e.Func([e.Text],[],[]),assert_mission_control_center:e.Func([r],[],[]),authenticate:e.Func([o],[_],[]),commit_proposal:e.Func([x],[e.Null],[]),commit_proposal_asset_upload:e.Func([y],[],[]),commit_proposal_many_assets_upload:e.Func([e.Vec(y)],[],[]),count_proposals:e.Func([],[e.Nat64],[]),create_orbiter:e.Func([T],[e.Principal],[]),create_satellite:e.Func([R],[e.Principal],[]),del_controllers:e.Func([I],[],[]),del_custom_domain:e.Func([e.Text],[],[]),delete_proposal_assets:e.Func([w],[],[]),get_auth_config:e.Func([],[e.Opt(F)],[]),get_config:e.Func([],[D],[]),get_create_orbiter_fee:e.Func([U],[e.Opt(t)],[]),get_create_satellite_fee:e.Func([U],[e.Opt(t)],[]),get_credits:e.Func([],[t],[]),get_delegation:e.Func([Q],[Ae],[]),get_proposal:e.Func([e.Nat],[e.Opt(Ye)],[]),get_storage_config:e.Func([],[P],[]),get_user_mission_control_center:e.Func([],[e.Opt(p)],[]),http_request:e.Func([Ur],[qr],[]),http_request_streaming_callback:e.Func([at],[Mr],[]),init_proposal:e.Func([kt],[e.Nat,Ye],[]),init_proposal_asset_upload:e.Func([Lt,e.Nat],[ct],[]),init_proposal_many_assets_upload:e.Func([e.Vec(Lt),e.Nat],[e.Vec(e.Tuple(e.Text,ct))],[]),init_user_mission_control_center:e.Func([],[p],[]),list_assets:e.Func([e.Text,dt],[pt],[]),list_controllers:e.Func([],[e.Vec(e.Tuple(e.Principal,Gr))],[]),list_custom_domains:e.Func([],[e.Vec(e.Tuple(e.Text,Jr))],[]),list_payments:e.Func([],[e.Vec(e.Tuple(e.Nat64,Wr))],[]),list_proposals:e.Func([Xr],[en],[]),list_user_mission_control_centers:e.Func([],[e.Vec(e.Tuple(e.Principal,p))],[]),reject_proposal:e.Func([x],[e.Null],[]),set_auth_config:e.Func([tn],[F],[]),set_controllers:e.Func([nn],[],[]),set_custom_domain:e.Func([e.Text,e.Opt(e.Text)],[],[]),set_fee:e.Func([qt,t],[],[]),set_storage_config:e.Func([on],[P],[]),submit_proposal:e.Func([e.Nat],[e.Nat,Ye],[]),update_rate_config:e.Func([qt,sn],[],[]),upload_proposal_asset_chunk:e.Func([an],[Mt],[])})};var d_=async({identity:e,host:t,localActor:r})=>await cr.create({identity:e,host:t,retryTimes:10,shouldFetchRootKey:r}),p_=async({agent:e,...t})=>e??await f_(t),f_=async({identity:e,container:t})=>{let r=X(t)&&t!==!1;return await d_({identity:e,host:r?t===!0?"http://127.0.0.1:5987":t:"https://icp-api.io",localActor:r})};var Ed=({satelliteId:e,certified:t=!1,...r})=>vd({canisterId:e,...r,idlFactory:t?yc:_c});var Rd=({consoleId:e,certified:t=!1,...r})=>vd({canisterId:e,...r,idlFactory:t?u_:l_}),vd=({canisterId:e,idlFactory:t,...r})=>{if(q(e))throw new Error("No canister ID provided.");return h_({canisterId:e,idlFactory:t,...r})},h_=async({canisterId:e,idlFactory:t,config:r,...n})=>{let o=await p_(n);return oo.createActor(t,{agent:o,canisterId:e,...r??{}})};var Ce=class e extends so{static instance;env;constructor(){super()}static getInstance(){return e.instance||(e.instance=new e),e.instance}set(t){this.env=t,this.populate(t)}get(){return this.env}reset(){this.env=null}subscribe(t){let r=super.subscribe(t);return t(this.env),r}};var Id=({satelliteId:e,container:t})=>{let{satelliteId:r}=gc({satelliteId:e}),{container:n}=xc({container:t});if(X(n)&&n!==!1){let{host:o,protocol:i}=new URL(n===!0?ao:n);return`${i}//${r??"unknown"}.${o.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},gc=({satelliteId:e})=>X(e)?{satelliteId:e}:Ce.getInstance().get()??{satelliteId:void 0},xc=({container:e})=>X(e)?{container:e}:Ce.getInstance().get()??{container:void 0};var Te=({satellite:e,options:{certified:t}})=>Sd({idlFactory:t?yc:_c,actorKey:`stock#${t?"update":"query"}`,...e}),Ad=({idlFactory:e,...t})=>Sd({idlFactory:e,actorKey:"extended#query",...t}),Sd=async({satelliteId:e,container:t,...r})=>{let{satelliteId:n}=gc({satelliteId:e});Qo(n,"No satellite ID defined. Did you initialize Juno?");let{container:o}=xc({container:t});return await lo.getInstance().getActor({satelliteId:n,container:o,...r})};var ys=class extends Error{},pr=class extends Error{},gs=class extends Error{},xs=class extends Error{},bs=class extends Error{},ws=class extends Error{},Ts=class extends Error{},Ns=class extends Error{},Os=class extends Error{};var Fd=e=>{if(q(e))return ue();switch(e.matcher){case"equal":return ue({Equal:e.timestamp});case"greaterThan":return ue({GreaterThan:e.timestamp});case"lessThan":return ue({LessThan:e.timestamp});case"between":return ue({Between:[e.timestamps.start,e.timestamps.end]});default:throw new Os("Invalid list matcher for timestamp",e)}},Br=({matcher:e,paginate:t,order:r,owner:n})=>({matcher:q(e)?[]:[{key:ue(e.key),description:ue(e.description),created_at:Fd(e.createdAt),updated_at:Fd(e.updatedAt)}],paginate:ue(q(t)?void 0:{start_after:ue(t.startAfter),limit:ue(q(t.limit)?void 0:BigInt(t.limit))}),order:ue(q(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:ue(q(n)?void 0:typeof n=="string"?M.fromText(n):n)});var Vd=async e=>{let t=new Blob([JSON.stringify(e,Yu)],{type:"application/json; charset=utf-8"});return new Uint8Array(await t.arrayBuffer())},Es=async e=>{let t=new Blob([e instanceof Uint8Array?e:new Uint8Array(e)],{type:"application/json; charset=utf-8"});return JSON.parse(await t.text(),Zu)},Rs=()=>typeof window<"u";var Cd=async({data:e})=>{try{return await Es(e)}catch(t){console.error("The data parsing has failed, mapping to undefined as a fallback.",t);return}};var bc=async e=>{let{data:t,version:r,description:n}=e;return{description:ue(n),data:await Vd(t),version:ue(r)}},wc=e=>{let{version:t}=e;return{version:ue(t)}},Vn=async({doc:e,key:t})=>{let{owner:r,version:n,description:o,data:i,...s}=e;return{key:t,description:ye(o),owner:r.toText(),data:await Es(i),version:ye(n),...s}};var Pd=async({collection:e,key:t,...r})=>{let{get_doc:n}=await Te(r),o=ye(await n(e,t));if(!q(o))return Vn({doc:o,key:t})},Bd=async({docs:e,...t})=>{let{get_many_docs:r}=await Te(t),n=e.map(({collection:s,key:a})=>[s,a]),o=await r(n),i=[];for(let[s,a]of o){let c=ye(a);i.push(X(c)?await Vn({key:s,doc:c}):void 0)}return i},Dd=async({collection:e,doc:t,...r})=>{let{set_doc:n}=await Te(r),{key:o}=t,i=await bc(t),s=await n(e,o,i);return await Vn({key:o,doc:s})},Ud=async({docs:e,...t})=>{let{set_many_docs:r}=await Te(t),n=[];for(let{collection:s,doc:a}of e){let{key:c}=a;n.push([s,c,await bc(a)])}let o=await r(n),i=[];for(let[s,a]of o)i.push(await Vn({key:s,doc:a}));return i},kd=async({collection:e,doc:t,...r})=>{let{del_doc:n}=await Te(r),{key:o}=t;return n(e,o,wc(t))},Ld=async({docs:e,...t})=>{let{del_many_docs:r}=await Te(t),n=e.map(({collection:o,doc:i})=>[o,i.key,wc(i)]);await r(n)},qd=async({collection:e,filter:t,...r})=>{let{del_filtered_docs:n}=await Te(r);return n(e,Br(t))},Md=async({collection:e,filter:t,...r})=>{let{list_docs:n}=await Te(r),{items:o,items_page:i,items_length:s,matches_length:a,matches_pages:c}=await n(e,Br(t)),u=[];for(let[p,d]of o){let{data:l,owner:f,description:h,version:m,...g}=d;u.push({key:p,description:ye(h),owner:f.toText(),data:await Cd({data:l}),version:ye(m),...g})}return{items:u,items_length:s,items_page:ye(i),matches_length:a,matches_pages:ye(c)}},jd=async({collection:e,filter:t,...r})=>{let{count_docs:n}=await Te(r);return n(e,Br(t))};var vs=async({satellite:e,options:t,...r})=>{let n=de(e?.identity);return await Pd({...r,satellite:{...e,identity:n},options:t??Dt})},nT=async({satellite:e,options:t,...r})=>{let n=de(e?.identity);return await Bd({...r,satellite:{...e,identity:n},options:t??Dt})},Kd=async({satellite:e,...t})=>{let r=de(e?.identity);return await Dd({...t,satellite:{...e,identity:r},options:{certified:!0}})},Hd=async({satellite:e,...t})=>{let r=de(e?.identity);return await Ud({...t,satellite:{...e,identity:r},options:{certified:!0}})},oT=async({satellite:e,...t})=>{let r=de(e?.identity);return await kd({...t,satellite:{...e,identity:r},options:{certified:!0}})},iT=async({satellite:e,...t})=>{let r=de(e?.identity);return await Ld({...t,satellite:{...e,identity:r},options:{certified:!0}})},sT=async({satellite:e,filter:t,...r})=>{let n=de(e?.identity);return await qd({...r,filter:t??{},satellite:{...e,identity:n},options:{certified:!0}})},aT=async({satellite:e,options:t,filter:r,...n})=>{let o=de(e?.identity);return await Md({...n,filter:r??{},satellite:{...e,identity:o},options:t??Dt})},cT=async({satellite:e,options:t,filter:r,...n})=>{let o=de(e?.identity);return await jd({...n,filter:r??{},satellite:{...e,identity:o},options:t??Dt})};var $d=async({provider:e})=>{let{user:t,userId:r}=await Tc();if(X(t))return t;try{return await m_({userId:r,provider:e})}catch(n){if(mc({error:n,type:Od})){let o=await Gd({userId:r});if(X(o))return o}throw n}},Tc=async()=>{let e=_s();if(q(e))throw new Ns("No identity to initialize the user. Have you initialized Juno?");let t=e.getPrincipal().toText(),r=await Gd({userId:t});return{userId:t,user:r}},Gd=({userId:e})=>vs({collection:"#user",key:e}),m_=({userId:e,...t})=>Kd({collection:"#user",doc:{key:e,data:t}});var Is=async()=>{await si({fn:async()=>{let{user:t}=await Tc();je.getInstance().set(t??null)}})},As=async({user:e})=>{await si({fn:async()=>{je.getInstance().set(e)}})};var Jd=()=>{let e=()=>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??e():e()},zd=()=>{let e=()=>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??e():e()},Wd=()=>{let e=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_GOOGLE_CLIENT_ID??import.meta.env?.PUBLIC_GOOGLE_CLIENT_ID:void 0;return typeof process<"u"&&typeof process.env<"u"?process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID??e():e()};var Yd=BigInt(144e11),Zd=!1,Xd={width:576,height:576},Qd={width:424,height:576};var ai="internetcomputer.org",ep="ic0.app",tp="id.ai";var rp=({width:e,height:t})=>{if(!Rs()||q(window)||q(window.top))return;let{top:{innerWidth:r,innerHeight:n}}=window,o=n/2+screenY-t/2,i=r/2+screenX-e/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${e}, height=${t}, top=${o}, left=${i}`};var Ut=async({fn:e,step:t,onProgress:r})=>{r?.({step:t,state:"in_progress"});try{let n=await e();return r?.({step:t,state:"success"}),n}catch(n){throw r?.({step:t,state:"error"}),n}};var np=(r=>(r[r.AuthorizingWithProvider=0]="AuthorizingWithProvider",r[r.CreatingOrRetrievingUser=1]="CreatingOrRetrievingUser",r))(np||{});var Ss=class{async signIn({options:t,authClient:r,initAuth:n}){await Ut({fn:async()=>await this.#e({options:t,authClient:r}),step:0,onProgress:t?.onProgress}),await Ut({fn:async()=>await n({provider:this.id}),step:1,onProgress:t?.onProgress})}#e({options:t,authClient:r}){return new Promise(async(n,o)=>{if(q(r)){o(new pr("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}await r.login({onSuccess:n,onError:i=>{if(i===ms){o(new gs(i));return}o(new ys(i))},maxTimeToLive:t?.maxTimeToLiveInNanoseconds??Yd,allowPinAuthentication:t?.allowPin??Zd,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...this.signInOptions({windowed:t?.windowed})})})}};var Fs=class extends Ss{#e;constructor({domain:t}){super(),this.#e=t}get id(){return"internet_identity"}signInOptions({windowed:t}){let n=(()=>{let i=Ce.getInstance().get()?.container;if(q(i)||i===!1){let p=[ai,ep].includes(this.#e??ai);return io(this.#e)?`https://identity.${ai}`:p?`https://identity.${this.#e??ai}`:`https://${this.#e}`}let s=Ce.getInstance().get(),a=X(s)&&X(s?.internetIdentityId)?s.internetIdentityId:sd,{host:c,protocol:u}=new URL(i===!0?ao:i);return/apple/i.test(navigator?.vendor)?`${u}//${c}?canisterId=${a}`:`${u}//${a}.${c.replace("127.0.0.1","localhost")}`})();return{...t!==!1&&{windowOpenerFeatures:rp((()=>{try{let{hostname:i}=new URL(n);return i.includes(tp)}catch{return!1}})()?Qd:Xd)},identityProvider:n}}};var Nc=class extends Error{},Oc=class extends Error{},Ec=class extends Error{},Rc=class extends Error{},vc=class extends Error{},Ic=class extends Error{},Ac=class extends Error{},Sc=class extends Error{},Fc=class extends Error{},Vc=class extends Error{};var op=({auth:e,identity:t})=>"satellite"in e?Ed({...e.satellite,identity:t}):Rd({...e.console,identity:t}),__=async({actorParams:e,args:t})=>{let{authenticate:r}=await op(e);return await r(t)},y_=async({actorParams:e,args:t})=>{let{get_delegation:r}=await op(e);return await r(t)},g_=({delegations:e,sessionKey:t})=>{let[r,n]=e,o=ur.fromDelegations(n,Uint8Array.from(r));return{identity:dr.fromDelegation(t,o),delegationChain:o,sessionKey:t}},Cc=async({jwt:e,context:t,auth:r})=>{let n=await Ct.generate({extractable:!1}),o=new Uint8Array(n.getPublicKey().toDer()),{delegations:i,data:s}=await x_({jwt:e,publicKey:o,context:t,auth:r});return{identity:g_({sessionKey:n,delegations:i}),data:s}},x_=async({jwt:e,publicKey:t,context:{caller:r,salt:n},auth:o})=>{let i=await __({args:{OpenId:{jwt:e,session_key:t,salt:n}},actorParams:{auth:o,identity:r}});if("Err"in i)throw new vc("Authentication failed",{cause:i});let{delegation:{user_key:s,expiration:a},...c}=i.Ok,u=await b_({jwt:e,context:{caller:r,salt:n},auth:o,publicKey:t,expiration:a}),{delegation:p,signature:d}=u,{pubkey:l,expiration:f,targets:h}=p;return{delegations:[s,[{delegation:new Pr(Uint8Array.from(l),f,ye(h)),signature:Uint8Array.from(d)}]],data:c}},b_=async({jwt:e,publicKey:t,context:{salt:r,caller:n},auth:o,expiration:i,maxRetries:s=5})=>{for(let a=0;a<s;a++){await new Promise(u=>{setInterval(u,1e3*a)});let c=await y_({args:{OpenId:{jwt:e,session_key:t,salt:r,expiration:i}},actorParams:{auth:o,identity:n}});if("Err"in c){let{Err:u}=c;if("NoSuchDelegation"in u||"GetCachedJwks"in u)continue;throw new Fc("Getting delegation failed",{cause:c})}return c.Ok}throw new Vc};var Pc="juno:auth:openid",Bc={authUrl:"https://accounts.google.com/o/oauth2/v2/auth",authScopes:["openid","profile","email"],configUrl:"https://accounts.google.com/gsi/fedcm.json"};var ip=e=>Vr(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),w_=()=>window.crypto.getRandomValues(new Uint8Array(32)),T_=async({salt:e,caller:t})=>{let r=t.getPrincipal().toUint8Array(),n=new Uint8Array(e.length+r.byteLength);n.set(e),n.set(r,e.length);let o=await window.crypto.subtle.digest("SHA-256",n);return ip(lr(o))},N_=async({caller:e})=>{let t=w_();return{nonce:await T_({salt:t,caller:e}),salt:t}},sp="__caller__",ap="__salt__",cp="__state__",O_=({caller:e,state:t,salt:r})=>{let n={[sp]:e.toJSON(),[ap]:Vr(r),[cp]:t};return JSON.stringify(n)},E_=e=>{let{[sp]:t,[ap]:r,[cp]:n}=JSON.parse(e);return{caller:Nt.fromParsedJson(t),salt:Wu(r),state:n}},R_=()=>ip(window.crypto.getRandomValues(new Uint8Array(12))),lp=async()=>{let e=Nt.generate(),{nonce:t,salt:r}=await N_({caller:e}),n=R_(),o=O_({caller:e,salt:r,state:n});return sessionStorage.setItem(Pc,o),{nonce:t,state:n}},up=()=>{let e=sessionStorage.getItem(Pc);if(q(e))throw new Oc;return E_(e)};var Dc=async e=>{let t=up();if("credentials"in e){let{credentials:{jwt:r},auth:n}=e;return await Cc({jwt:r,context:t,auth:n})}return await v_({...e,context:t})},v_=async({auth:e,context:t})=>{let{location:{hash:r}}=window;if(io(r)||!r.startsWith("#"))throw new Ic("No hash found in the current location URL");let n=new URLSearchParams(r.slice(1)),o=n.get("state"),i=n.get("id_token"),{state:s}=t;if(io(s)||o!==s)throw new Ac("The provided state is invalid",{cause:o});if(io(i))throw new Sc;return await Cc({jwt:i,auth:e,context:t})};var dp=({authUrl:e,clientId:t,nonce:r,loginHint:n,authScopes:o,state:i,redirectUrl:s})=>{let a=(()=>{try{return new URL(e)}catch{throw new Nc("Cannot parse authURL",{cause:e})}})();a.searchParams.set("client_id",t);let{location:{origin:c}}=window;a.searchParams.set("redirect_uri",s??c),a.searchParams.set("response_type","code id_token"),a.searchParams.set("scope",o.join(" ")),a.searchParams.set("state",i),a.searchParams.set("nonce",r),Qa(n)?a.searchParams.set("login_hint",n):a.searchParams.set("prompt","select_account"),window.location.href=a.toString()},pp=async({configUrl:e,clientId:t,nonce:r,loginHint:n,domainHint:o})=>{let i=await navigator.credentials.get({identity:{context:"use",providers:[{configURL:e,clientId:t,nonce:r,loginHint:n,domainHint:o}],mode:"active"},mediation:"required"});if(q(i))throw new Ec;let{type:s}=i;if(s!=="identity"||!("token"in i)||typeof i.token!="string")throw new Rc("Invalid credential received from FedCM API",{cause:i});let{token:a}=i;return{jwt:a}};async function Uc({google:e}){let t=await lp();if("credentials"in e){let{credentials:i}=e,{configUrl:s}=Bc;return await pp({...i,...t,configUrl:s})}let{redirect:r}=e,{authUrl:n,authScopes:o}=Bc;dp({...r,...t,authUrl:n,authScopes:o})}var I_=async()=>{let{satelliteId:e}=Ce.getInstance().get()??{satelliteId:void 0};if(q(e))throw new pr("Satellite ID not set. Have you initialized the Satellite?");let t=Ce.getInstance().get()?.container,{identity:{delegationChain:r,sessionKey:n,identity:o},data:{doc:i}}=await Dc({redirect:null,auth:{satellite:{satelliteId:e,container:t}}});await $e.getInstance().setAuthClientStorage({delegationChain:r,sessionKey:n});let s=await Vn({doc:i,key:o.getPrincipal().toText()});await As({user:s})};var fp=e=>(e.preventDefault(),e.returnValue="Are you sure you want to exit?"),A_=()=>{window.addEventListener("beforeunload",fp,{capture:!0})},S_=()=>{window.removeEventListener("beforeunload",fp,{capture:!0})},Vs=async({fn:e})=>{try{return A_(),await e()}finally{S_()}};var Cs=class{get id(){return"google"}async signIn({options:t={}}){let r=t?.redirect?.clientId??Wd();if(q(r))throw new bs;let{redirect:n}=t;await Uc({google:{redirect:{...n??{},clientId:r}}})}};var hp=async({delegationIdentity:e,passkeyIdentity:t,satelliteId:r})=>{let n=t.getCredential().getAAGUID(),[o,i]=await Hd({docs:[{collection:"#user",doc:{key:e.getPrincipal().toText(),data:{provider:"webauthn",providerData:{webauthn:{...X(n)&&{aaguid:us(n)}}}}}},{collection:"#user-webauthn",doc:{key:t.getCredential().getCredentialIdText(),data:{publicKey:t.getPublicKey().toRaw()}}}],satellite:{identity:e,satelliteId:r}});return o};var mp=(i=>(i[i.RequestingUserCredential=0]="RequestingUserCredential",i[i.FinalizingCredential=1]="FinalizingCredential",i[i.Signing=2]="Signing",i[i.FinalizingSession=3]="FinalizingSession",i[i.RetrievingUser=4]="RetrievingUser",i))(mp||{}),_p=(s=>(s[s.CreatingUserCredential=0]="CreatingUserCredential",s[s.ValidatingUserCredential=1]="ValidatingUserCredential",s[s.FinalizingCredential=2]="FinalizingCredential",s[s.Signing=3]="Signing",s[s.FinalizingSession=4]="FinalizingSession",s[s.RegisteringUser=5]="RegisteringUser",s))(_p||{});var uo=class{get id(){return"webauthn"}async signUp({options:{onProgress:t,maxTimeToLiveInMilliseconds:r,passkey:n}={},loadAuthWithUser:o}){let{satelliteId:i}=Ce.getInstance().get()??{satelliteId:void 0};if(q(i))throw new pr("Satellite ID not set. Have you initialized the Satellite?");let s=({step:m,state:g})=>{switch(m){case Cr.RequestingUserCredential:t?.({step:1,state:g});break;case Cr.FinalizingCredential:t?.({step:2,state:g});break;case Cr.Signing:t?.({step:3,state:g});break}},c=await Ut({fn:async()=>await tc.createWithNewCredential({onProgress:s,passkeyOptions:n}),step:0,onProgress:t}),{delegationIdentity:u,sessionKey:p}=await this.#e({identity:c,maxTimeToLiveInMilliseconds:r}),l=await Ut({fn:async()=>await hp({delegationIdentity:u,passkeyIdentity:c,satelliteId:i}),step:5,onProgress:t});await Ut({fn:async()=>await this.#t({delegationIdentity:u,sessionKey:p}),step:4,onProgress:t}),await Ut({fn:async()=>await o({user:l}),step:5,onProgress:t})}async signIn({options:{onProgress:t,maxTimeToLiveInMilliseconds:r}={},loadAuth:n}){let{satelliteId:o}=Ce.getInstance().get()??{satelliteId:void 0};if(q(o))throw new pr("Satellite ID not set. Have you initialized the Satellite?");let i=async({credentialId:d})=>{let l=await vs({collection:"#user-webauthn",key:Vr(d),options:{certified:!0},satellite:{identity:new rt,satelliteId:o}});if(q(l))throw new ws("No public key found for the selected passkey.");let{data:f}=l,{publicKey:h}=f;return Fn(h,Zo)},s=({step:d,state:l})=>{switch(d){case Cr.RequestingUserCredential:t?.({step:0,state:l});break;case Cr.FinalizingCredential:t?.({step:1,state:l});break;case Cr.Signing:t?.({step:2,state:l});break}},a=await tc.createWithExistingCredential({retrievePublicKey:i,onProgress:s}),{delegationIdentity:c,sessionKey:u}=await this.#e({identity:a,maxTimeToLiveInMilliseconds:r});await Ut({fn:async()=>await this.#t({delegationIdentity:c,sessionKey:u}),step:3,onProgress:t}),await Ut({fn:n,step:4,onProgress:t})}async#e({identity:t,maxTimeToLiveInMilliseconds:r}){let n=await Ct.generate({extractable:!1}),o=r??144e5,i=await ur.create(t,n.getPublicKey(),new Date(Date.now()+o));return{delegationIdentity:dr.fromDelegation(n,i),sessionKey:n}}async#t({sessionKey:t,delegationIdentity:r}){let n=new Bt;await Promise.all([n.set(He,t.getKeyPair()),n.set(Ke,JSON.stringify(r.getDelegation().toJSON()))])}};var V_=async({provider:e})=>{await si({fn:async()=>{let r=await $d({provider:e});je.getInstance().set(r)}})},C_=async e=>{let t=async()=>await P_(e);if(Object.values(e)[0].context?.windowGuard===!1){await t();return}await Vs({fn:t})},P_=async e=>{if("google"in e){let{google:{options:t}}=e;await new Cs().signIn({options:t});return}if("webauthn"in e){let{webauthn:{options:t}}=e;await new uo().signIn({options:t,loadAuth:Is});return}if("internet_identity"in e){let{internet_identity:{options:t}}=e,{domain:r,...n}=t??{};await new Fs({domain:r}).signIn({options:n,authClient:$e.getInstance().getAuthClient(),initAuth:V_});return}throw new xs("An unknown or unsupported provider was provided for sign-in.")};var B_=async e=>{let t=async()=>await D_(e);if(Object.values(e)?.[0].context?.windowGuard===!1){await t();return}await Vs({fn:t})},D_=async e=>{if("webauthn"in e){let{webauthn:{options:t}}=e;await new uo().signUp({options:t,loadAuthWithUser:As});return}throw new Ts("An unknown or unsupported provider was provided for sign-up.")};var AO=async({idlFactory:e,satellite:t})=>{let r=de(t?.identity);return await Ad({idlFactory:e,...t,identity:r})};var yp=async({asset:{data:e,headers:t,...r},actor:n,progress:o})=>{let{init_asset_upload:i,upload_asset_chunk:s,commit_asset_upload:a}=n,{batch_id:c}=await i(U_(r));o?.onInitiatedBatch();let{chunkIds:u}=await q_({data:e,uploadFn:s,batchId:c});o?.onUploadedFileChunks(r.fullPath),await L_({commitFn:a,batchId:c,data:e,headers:t,chunkIds:u}),o?.onCommittedBatch()};var U_=({filename:e,collection:t,token:r,fullPath:n,encoding:o,description:i})=>({collection:t,full_path:n,name:e,token:ue(r),encoding_type:ue(o),description:ue(i)}),k_=({batchId:e,chunkIds:t,headers:r,data:n})=>{let o=r.find(([i,s])=>i.toLowerCase()==="content-type")===void 0&&n.type!==void 0&&n.type!==""?[["Content-Type",n.type]]:void 0;return{batch_id:e,chunk_ids:t.map(({chunk_id:i})=>i),headers:[...r,...o??[]]}},L_=async({commitFn:e,...t})=>{let r=k_(t);await e(r)},q_=async({data:e,uploadFn:t,batchId:r})=>{let n=[],o=Rs()?new Blob([await e.arrayBuffer()]):e,i=0n;for(let a=0;a<o.size;a+=19e5){let c=o.slice(a,a+19e5);n.push({batchId:r,chunk:c,uploadFn:t,orderId:i}),i++}let s=[];for await(let a of M_({uploadChunks:n}))s=[...s,...a];return{chunkIds:s}};async function*M_({uploadChunks:e,limit:t=12}){for(let r=0;r<e.length;r=r+t){let n=e.slice(r,r+t);yield await Promise.all(n.map(o=>j_(o)))}}var j_=async({batchId:e,chunk:t,uploadFn:r,orderId:n})=>r({batch_id:e,content:new Uint8Array(await t.arrayBuffer()),order_id:ue(n)});var gp=async({asset:e,...t})=>{let r=await Te(t);await yp({actor:r,asset:e})},xp=async({collection:e,filter:t,...r})=>{let{list_assets:n}=await Te(r),{items:o,items_length:i,items_page:s,matches_length:a,matches_pages:c}=await n(e,Br(t));return{items:o.map(([u,p])=>p),items_length:i,items_page:ye(s),matches_length:a,matches_pages:ye(c)}},bp=async({collection:e,filter:t,...r})=>{let{count_assets:n}=await Te(r);return n(e,Br(t))},wp=async({collection:e,fullPath:t,...r})=>(await Te(r)).del_asset(e,t),Tp=async({assets:e,satellite:t})=>{let{del_many_assets:r}=await Te({satellite:t,options:{certified:!0}}),n=e.map(({collection:o,fullPath:i})=>[o,i]);await r(n)},Np=async({collection:e,filter:t,...r})=>{let{del_filtered_assets:n}=await Te(r);return n(e,Br(t))},Op=async({collection:e,fullPath:t,...r})=>{let{get_asset:n}=await Te(r);return ye(await n(e,t))},Ep=async({assets:e,...t})=>{let{get_many_assets:r}=await Te(t),n=e.map(({collection:i,fullPath:s})=>[i,s]);return(await r(n)).map(([i,s])=>ye(s))};var Rp=e=>btoa([...e].map(t=>String.fromCharCode(t)).join(""));var GO=e=>vp(e),JO=e=>vp({filename:e.data.name,...e}),vp=async({filename:e,data:t,collection:r,headers:n=[],fullPath:o,token:i,satellite:s,encoding:a,description:c})=>{let u=de(s?.identity),p=decodeURI(e),d=o??`/${r}/${p}`,l={...s,identity:u};return await gp({asset:{data:t,filename:p,collection:r,token:i,headers:n,fullPath:d,encoding:a,description:c},satellite:l,options:{certified:!0}}),{downloadUrl:Ip({satellite:l,assetKey:{fullPath:d,token:i}}),fullPath:d,name:p}},zO=async({collection:e,filter:t,satellite:r,options:n})=>{let o={...r,identity:de(r?.identity)},{items:i,...s}=await xp({collection:e,filter:t??{},satellite:o,options:n??Dt}),a=i.map(({key:{full_path:c,token:u,name:p,owner:d,description:l},headers:f,encodings:h,created_at:m,updated_at:g})=>{let _=ye(u);return{fullPath:c,description:ye(l),name:p,downloadUrl:Ip({satellite:o,assetKey:{fullPath:c,token:_}}),token:_,headers:f,encodings:h.reduce((x,[y,{modified:T,sha256:E,total_length:O}])=>({...x,[y]:{modified:T,sha256:Rp(E),total_length:O}}),{}),owner:d.toText(),created_at:m,updated_at:g}});return{items:a,assets:a,...s}},WO=async({collection:e,filter:t,satellite:r,options:n})=>{let o={...r,identity:de(r?.identity)};return await bp({collection:e,satellite:o,filter:t??{},options:n??Dt})},YO=({collection:e,fullPath:t,satellite:r})=>wp({collection:e,fullPath:t,satellite:{...r,identity:de(r?.identity)},options:{certified:!0}}),ZO=({assets:e,satellite:t})=>Tp({assets:e,satellite:{...t,identity:de(t?.identity)},options:{certified:!0}}),XO=async({collection:e,satellite:t,filter:r})=>{let n={...t,identity:de(t?.identity)};return await Np({collection:e,satellite:n,filter:r??{},options:{certified:!0}})},QO=async({satellite:e,options:t,...r})=>{let n=de(e?.identity);return await Op({...r,satellite:{...e,identity:n},options:t??Dt})},e6=async({satellite:e,options:t,...r})=>{let n=de(e?.identity);return await Ep({...r,satellite:{...e,identity:n},options:t??Dt})},Ip=({assetKey:{fullPath:e,token:t},satellite:r})=>{let n={...r,identity:de(r?.identity)};return`${Id(n)}${e}${X(t)?`?token=${t}`:""}`};var K_=e=>{let t=e?.satelliteId??Jd();Qo(t,"Satellite ID is not configured. Juno cannot be initialized.");let r=e?.container??zd();return{satelliteId:t,internetIdentityId:e?.internetIdentityId,workers:e?.workers,container:r}},l6=e=>H_(e),H_=async e=>{let t=K_(e);Ce.getInstance().set(t),await Is();let r=t.workers?.auth!==void 0?Nd(t.workers.auth):void 0;return[...r?[r]:[]]},$_=e=>je.getInstance().subscribe(e),u6=$_;export{np as AuthClientSignInProgressStep,Ns as InitError,Fs as InternetIdentityProvider,Os as ListError,ys as SignInError,pr as SignInInitError,bs as SignInMissingClientIdError,xs as SignInProviderNotSupportedError,gs as SignInUserInterruptError,Ts as SignUpProviderNotSupportedError,mp as WebAuthnSignInProgressStep,ws as WebAuthnSignInRetrievePublicKeyError,_p as WebAuthnSignUpProgressStep,u6 as authSubscribe,WO as countAssets,cT as countDocs,YO as deleteAsset,oT as deleteDoc,XO as deleteFilteredAssets,sT as deleteFilteredDocs,ZO as deleteManyAssets,iT as deleteManyDocs,Ip as downloadUrl,QO as getAsset,vs as getDoc,c_ as getIdentityOnce,e6 as getManyAssets,nT as getManyDocs,AO as getSatelliteExtendedActor,I_ as handleRedirectCallback,l6 as initJuno,H_ as initSatellite,Dm as isWebAuthnAvailable,zO as listAssets,aT as listDocs,$_ as onAuthStateChange,Kd as setDoc,Hd as setManyDocs,C_ as signIn,hc as signOut,B_ as signUp,a_ as unsafeIdentity,GO as uploadBlob,JO as uploadFile};
55
55
  /*! Bundled license information:
56
56
 
57
57
  @noble/hashes/esm/utils.js: