@junobuild/core-peer 2.2.0 → 2.2.1-next-2025-10-22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { type AuthClient } from '@dfinity/auth-client';
1
+ import { type AuthClient } from '@icp-sdk/auth/client';
2
2
  import { type AuthClientSignInOptions } from '../types/auth-client';
3
3
  import type { Provider } from '../types/provider';
4
4
  /**
@@ -26,7 +26,7 @@ export interface AuthProviderSignInOptions {
26
26
  windowOpenerFeatures?: string;
27
27
  }
28
28
  /**
29
- * Abstract base class for all authentication providers that integrate with the `@dfinity/auth-client`.
29
+ * Abstract base class for all authentication providers that integrate with the `@icp-sdk/auth/client`.
30
30
  *
31
31
  * @abstract
32
32
  * @class AuthClientProvider
@@ -1,4 +1,4 @@
1
- import type { Identity } from '@dfinity/agent';
1
+ import type { Identity } from '@icp-sdk/core/agent';
2
2
  import type { SignInOptions, SignOutOptions, SignUpOptions } from '../types/auth';
3
3
  import type { Provider } from '../types/provider';
4
4
  /**
@@ -1,4 +1,4 @@
1
- import type { Identity } from '@dfinity/agent';
1
+ import type { Identity } from '@icp-sdk/core/agent';
2
2
  import type { WebAuthnIdentity, WebAuthnNewCredential } from '@junobuild/ic-client/webauthn';
3
3
  import type { Environment } from '../../core/types/env';
4
4
  import type { User } from '../types/user';
@@ -1,3 +1,3 @@
1
- import { AuthClient } from '@dfinity/auth-client';
1
+ import { AuthClient } from '@icp-sdk/auth/client';
2
2
  export declare const createAuthClient: () => Promise<AuthClient>;
3
3
  export declare const resetAuthClient: () => Promise<AuthClient>;
@@ -1,5 +1,5 @@
1
- import type { ActorMethod, ActorSubclass } from '@dfinity/agent';
2
- import type { IDL } from '@dfinity/candid';
1
+ import type { ActorMethod, ActorSubclass } from '@icp-sdk/core/agent';
2
+ import type { IDL } from '@icp-sdk/core/candid';
3
3
  import { type SatelliteActor } from '@junobuild/ic-client/actor';
4
4
  import type { CallOptions } from '../types/call-options';
5
5
  import type { SatelliteContext } from '../types/satellite';
@@ -1,2 +1,2 @@
1
- import { type Identity } from '@dfinity/agent';
1
+ import { type Identity } from '@icp-sdk/core/agent';
2
2
  export declare const getAnyIdentity: (identity?: Identity) => Identity;
@@ -1,4 +1,4 @@
1
- import { HttpAgent } from '@dfinity/agent';
1
+ import { HttpAgent } from '@icp-sdk/core/agent';
2
2
  import type { SatelliteContext } from '../types/satellite';
3
3
  export type CreateAgentParams = Required<Pick<SatelliteContext, 'identity'>> & Pick<SatelliteContext, 'container'>;
4
4
  export declare const createAgent: ({ identity, container }: CreateAgentParams) => Promise<HttpAgent>;
@@ -1,5 +1,5 @@
1
- import { type ActorMethod, type ActorSubclass } from '@dfinity/agent';
2
- import type { IDL } from '@dfinity/candid';
1
+ import { type ActorMethod, type ActorSubclass } from '@icp-sdk/core/agent';
2
+ import type { IDL } from '@icp-sdk/core/candid';
3
3
  import type { ActorKey } from '../types/actor';
4
4
  import type { SatelliteContext } from '../types/satellite';
5
5
  type ActorParams = {
@@ -1,4 +1,4 @@
1
- import type { Agent } from '@dfinity/agent';
1
+ import type { Agent } from '@icp-sdk/core/agent';
2
2
  import { type CreateAgentParams } from './_agent.factory';
3
3
  export declare class AgentStore {
4
4
  #private;
@@ -1,4 +1,4 @@
1
- import type { Principal } from '@dfinity/principal';
1
+ import type { Principal } from '@icp-sdk/core/principal';
2
2
  /**
3
3
  * Represents the results of a list call.
4
4
  * @template T - The type of items in the list.
@@ -1,4 +1,4 @@
1
- import type { Identity } from '@dfinity/agent';
1
+ import type { Identity } from '@icp-sdk/core/agent';
2
2
  /**
3
3
  * Configuration options for connecting to a satellite.
4
4
  * @interface
@@ -1,5 +1,5 @@
1
- import type { ActorMethod, ActorSubclass } from '@dfinity/agent';
2
- import type { IDL } from '@dfinity/candid';
1
+ import type { ActorMethod, ActorSubclass } from '@icp-sdk/core/agent';
2
+ import type { IDL } from '@icp-sdk/core/candid';
3
3
  import type { SatelliteOptions } from '../../core/types/satellite';
4
4
  /**
5
5
  * Returns an extended satellite actor instance using the provided IDL factory and satellite options.
@@ -1,14 +1,14 @@
1
- "use strict";(()=>{var Qt="abcdefghijklmnopqrstuvwxyz234567",St=Object.create(null);for(let e=0;e<Qt.length;e++)St[Qt[e]]=e;St[0]=St.o;St[1]=St.i;function pr(e){let t=0,r=0,n="";function o(s){return t<0?r|=s>>-t:r=s<<t&248,t>3?(t-=8,1):(t<4&&(n+=Qt[r>>3],t+=5),0)}for(let s=0;s<e.length;)s+=o(e[s]);return n+(t<0?Qt[r>>3]:"")}function yr(e){let t=0,r=0,n=new Uint8Array(e.length*4/3|0),o=0;function s(i){let a=St[i.toLowerCase()];if(a===void 0)throw new Error(`Invalid character: ${JSON.stringify(i)}`);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 i of e)s(i);return n.slice(0,o)}var Un=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 gr(e){let t=-1;for(let r=0;r<e.length;r++){let o=(e[r]^t)&255;t=Un[o]^t>>>8}return(t^-1)>>>0}var mt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function wt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ee(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function $(e,...t){if(!wt(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 _e(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 mr(e,t){$(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Et(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ee(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function F(e,t){return e<<32-t|e>>>t}var wr=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Mn=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function v(e){if($(e),wr)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Mn[e[r]];return t}var tt={_0:48,_9:57,A:65,F:70,a:97,f:102};function br(e){if(e>=tt._0&&e<=tt._9)return e-tt._0;if(e>=tt.A&&e<=tt.F)return e-(tt.A-10);if(e>=tt.a&&e<=tt.f)return e-(tt.a-10)}function q(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(wr)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,s=0;o<r;o++,s+=2){let i=br(e.charCodeAt(s)),a=br(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ie(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Be(e){return typeof e=="string"&&(e=Ie(e)),$(e),e}function G(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];$(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var te=class{};function re(e){let t=n=>e().update(Be(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Ae(e=32){if(mt&&typeof mt.getRandomValues=="function")return mt.getRandomValues(new Uint8Array(e));if(mt&&typeof mt.randomBytes=="function")return Uint8Array.from(mt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function jn(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function Er(e,t,r){return e&t^~e&r}function _r(e,t,r){return e&t^e&r^t&r}var Ct=class extends te{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=ee(this.buffer)}update(t){_e(this),t=Be(t),$(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=ee(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){_e(this),mr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Et(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;jn(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=ee(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,l[d],s)}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:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},et=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),rt=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var N=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var ne=BigInt(4294967295),Ir=BigInt(32);function qn(e,t=!1){return t?{h:Number(e&ne),l:Number(e>>Ir&ne)}:{h:Number(e>>Ir&ne)|0,l:Number(e&ne)|0}}function Br(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=qn(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Se=(e,t,r)=>e>>>r,Oe=(e,t,r)=>e<<32-r|t>>>r,_t=(e,t,r)=>e>>>r|t<<32-r,It=(e,t,r)=>e<<32-r|t>>>r,Pt=(e,t,r)=>e<<64-r|t>>>r-32,Rt=(e,t,r)=>e>>>r-32|t<<64-r;function W(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ar=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Sr=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Or=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Tr=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,vr=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Dr=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Kn=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]),at=new Uint32Array(64),oe=class extends Ct{constructor(t=32){super(64,t,8,!1),this.A=et[0]|0,this.B=et[1]|0,this.C=et[2]|0,this.D=et[3]|0,this.E=et[4]|0,this.F=et[5]|0,this.G=et[6]|0,this.H=et[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let d=0;d<16;d++,r+=4)at[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let f=at[d-15],p=at[d-2],x=F(f,7)^F(f,18)^f>>>3,b=F(p,17)^F(p,19)^p>>>10;at[d]=b+at[d-7]+x+at[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let d=0;d<64;d++){let f=F(a,6)^F(a,11)^F(a,25),p=l+f+Er(a,c,u)+Kn[d]+at[d]|0,b=(F(n,2)^F(n,13)^F(n,22))+_r(n,o,s)|0;l=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){Et(at)}destroy(){this.set(0,0,0,0,0,0,0,0),Et(this.buffer)}},Te=class extends oe{constructor(){super(28),this.A=rt[0]|0,this.B=rt[1]|0,this.C=rt[2]|0,this.D=rt[3]|0,this.E=rt[4]|0,this.F=rt[5]|0,this.G=rt[6]|0,this.H=rt[7]|0}},Lr=Br(["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))),kn=Lr[0],Vn=Lr[1],ft=new Uint32Array(80),ut=new Uint32Array(80),ve=class extends Ct{constructor(t=64){super(128,t,16,!1),this.Ah=N[0]|0,this.Al=N[1]|0,this.Bh=N[2]|0,this.Bl=N[3]|0,this.Ch=N[4]|0,this.Cl=N[5]|0,this.Dh=N[6]|0,this.Dl=N[7]|0,this.Eh=N[8]|0,this.El=N[9]|0,this.Fh=N[10]|0,this.Fl=N[11]|0,this.Gh=N[12]|0,this.Gl=N[13]|0,this.Hh=N[14]|0,this.Hl=N[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:d,Fl:f,Gh:p,Gl:x,Hh:b,Hl:E}=this;return[t,r,n,o,s,i,a,c,u,l,d,f,p,x,b,E]}set(t,r,n,o,s,i,a,c,u,l,d,f,p,x,b,E){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=d|0,this.Fl=f|0,this.Gh=p|0,this.Gl=x|0,this.Hh=b|0,this.Hl=E|0}process(t,r){for(let y=0;y<16;y++,r+=4)ft[y]=t.getUint32(r),ut[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let I=ft[y-15]|0,A=ut[y-15]|0,D=_t(I,A,1)^_t(I,A,8)^Se(I,A,7),L=It(I,A,1)^It(I,A,8)^Oe(I,A,7),B=ft[y-2]|0,g=ut[y-2]|0,m=_t(B,g,19)^Pt(B,g,61)^Se(B,g,6),_=It(B,g,19)^Rt(B,g,61)^Oe(B,g,6),S=Or(L,_,ut[y-7],ut[y-16]),T=Tr(S,D,m,ft[y-7],ft[y-16]);ft[y]=T|0,ut[y]=S|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:d,El:f,Fh:p,Fl:x,Gh:b,Gl:E,Hh:h,Hl:w}=this;for(let y=0;y<80;y++){let I=_t(d,f,14)^_t(d,f,18)^Pt(d,f,41),A=It(d,f,14)^It(d,f,18)^Rt(d,f,41),D=d&p^~d&b,L=f&x^~f&E,B=vr(w,A,L,Vn[y],ut[y]),g=Dr(B,h,I,D,kn[y],ft[y]),m=B|0,_=_t(n,o,28)^Pt(n,o,34)^Pt(n,o,39),S=It(n,o,28)^Rt(n,o,34)^Rt(n,o,39),T=n&s^n&a^s&a,O=o&i^o&c^i&c;h=b|0,w=E|0,b=p|0,E=x|0,p=d|0,x=f|0,{h:d,l:f}=W(u|0,l|0,g|0,m|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let P=Ar(m,S,O);n=Sr(P,g,_,T),o=P|0}({h:n,l:o}=W(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=W(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=W(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=W(this.Dh|0,this.Dl|0,u|0,l|0),{h:d,l:f}=W(this.Eh|0,this.El|0,d|0,f|0),{h:p,l:x}=W(this.Fh|0,this.Fl|0,p|0,x|0),{h:b,l:E}=W(this.Gh|0,this.Gl|0,b|0,E|0),{h,l:w}=W(this.Hh|0,this.Hl|0,h|0,w|0),this.set(n,o,s,i,a,c,u,l,d,f,p,x,b,E,h,w)}roundClean(){Et(ft,ut)}destroy(){Et(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var dt=re(()=>new oe),Cr=re(()=>new Te),Pr=re(()=>new ve);var se="__principal__",$n=2,Rr=4,Gn="aaaaa-aa",Z=class e{static anonymous(){return new this(new Uint8Array([Rr]))}static managementCanister(){return this.fromText(Gn)}static selfAuthenticating(t){let r=Cr(t);return new this(new Uint8Array([...r,$n]))}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(q(t))}static fromText(t){let r=t;if(t.includes(se)){let i=JSON.parse(t);se in i&&(r=i[se])}let n=r.toLowerCase().replace(/-/g,""),o=yr(n);o=o.slice(4,o.length);let s=new this(o);if(s.toText()!==r)throw new Error(`Principal "${s.toText()}" does not have a valid checksum (original value "${r}" may not be a valid Principal ID).`);return s}static fromUint8Array(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]===Rr}toUint8Array(){return this._arr}toHex(){return v(this._arr).toUpperCase()}toText(){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,gr(this._arr));let n=new Uint8Array(t),o=new Uint8Array([...n,...this._arr]),i=pr(o).match(/.{1,5}/g);if(!i)throw new Error;return i.join("-")}toString(){return this.toText()}toJSON(){return{[se]: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 De;(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"})(De||(De={}));var Ot=class{constructor(t=!1){this.isCertified=t}toString(){let t=this.toErrorMessage();return this.requestContext&&(t+=`
1
+ "use strict";(()=>{var Ie="abcdefghijklmnopqrstuvwxyz234567",Ft=Object.create(null);for(let e=0;e<Ie.length;e++)Ft[Ie[e]]=e;Ft[0]=Ft.o;Ft[1]=Ft.i;function Xr(e){let t=0,r=0,n="";function o(s){return t<0?r|=s>>-t:r=s<<t&248,t>3?(t-=8,1):(t<4&&(n+=Ie[r>>3],t+=5),0)}for(let s=0;s<e.length;)s+=o(e[s]);return n+(t<0?Ie[r>>3]:"")}function Qr(e){let t=0,r=0,n=new Uint8Array(e.length*4/3|0),o=0;function s(i){let c=Ft[i.toLowerCase()];if(c===void 0)throw new Error(`Invalid character: ${JSON.stringify(i)}`);c<<=3,r|=c>>>t,t+=5,t>=8&&(n[o++]=r,t-=8,t>0?r=c<<5-t&255:r=0)}for(let i of e)s(i);return n.slice(0,o)}var Do=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 tn(e){let t=-1;for(let r=0;r<e.length;r++){let o=(e[r]^t)&255;t=Do[o]^t>>>8}return(t^-1)>>>0}var Nt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ut(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Xe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function X(e,...t){if(!Ut(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 Qe(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 rn(e,t){X(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Se(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function et(e,t){return e<<32-t|e>>>t}var nn=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Po=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function L(e){if(X(e),nn)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Po[e[r]];return t}var ft={_0:48,_9:57,A:65,F:70,a:97,f:102};function en(e){if(e>=ft._0&&e<=ft._9)return e-ft._0;if(e>=ft.A&&e<=ft.F)return e-(ft.A-10);if(e>=ft.a&&e<=ft.f)return e-(ft.a-10)}function Y(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(nn)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,s=0;o<r;o++,s+=2){let i=en(e.charCodeAt(s)),c=en(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function tr(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function er(e){return typeof e=="string"&&(e=tr(e)),X(e),e}function Q(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];X(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Te=class{};function Oe(e){let t=n=>e().update(er(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function rr(e=32){if(Nt&&typeof Nt.getRandomValues=="function")return Nt.getRandomValues(new Uint8Array(e));if(Nt&&typeof Nt.randomBytes=="function")return Uint8Array.from(Nt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Lo(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function on(e,t,r){return e&t^~e&r}function sn(e,t,r){return e&t^e&r^t&r}var ee=class extends Te{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=Se(this.buffer)}update(t){Qe(this),t=er(t),X(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Se(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Qe(this),rn(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;Lo(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Se(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)c.setUint32(4*d,l[d],s)}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:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ut=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),dt=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var q=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ae=BigInt(4294967295),an=BigInt(32);function No(e,t=!1){return t?{h:Number(e&Ae),l:Number(e>>an&Ae)}:{h:Number(e>>an&Ae)|0,l:Number(e&Ae)|0}}function cn(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=No(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var nr=(e,t,r)=>e>>>r,or=(e,t,r)=>e<<32-r|t>>>r,jt=(e,t,r)=>e>>>r|t<<32-r,Ht=(e,t,r)=>e<<32-r|t>>>r,re=(e,t,r)=>e<<64-r|t>>>r-32,ne=(e,t,r)=>e>>>r-32|t<<64-r;function st(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var fn=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),un=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,dn=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ln=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,hn=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),pn=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Mo=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]),_t=new Uint32Array(64),Be=class extends ee{constructor(t=32){super(64,t,8,!1),this.A=ut[0]|0,this.B=ut[1]|0,this.C=ut[2]|0,this.D=ut[3]|0,this.E=ut[4]|0,this.F=ut[5]|0,this.G=ut[6]|0,this.H=ut[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let d=0;d<16;d++,r+=4)_t[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let f=_t[d-15],x=_t[d-2],p=et(f,7)^et(f,18)^f>>>3,b=et(x,17)^et(x,19)^x>>>10;_t[d]=b+_t[d-7]+p+_t[d-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let d=0;d<64;d++){let f=et(c,6)^et(c,11)^et(c,25),x=l+f+on(c,a,u)+Mo[d]+_t[d]|0,b=(et(n,2)^et(n,13)^et(n,22))+sn(n,o,s)|0;l=u,u=a,a=c,c=i+x|0,i=s,s=o,o=n,n=x+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){Mt(_t)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},sr=class extends Be{constructor(){super(28),this.A=dt[0]|0,this.B=dt[1]|0,this.C=dt[2]|0,this.D=dt[3]|0,this.E=dt[4]|0,this.F=dt[5]|0,this.G=dt[6]|0,this.H=dt[7]|0}},xn=cn(["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))),jo=xn[0],Ho=xn[1],It=new Uint32Array(80),Tt=new Uint32Array(80),ir=class extends ee{constructor(t=64){super(128,t,16,!1),this.Ah=q[0]|0,this.Al=q[1]|0,this.Bh=q[2]|0,this.Bl=q[3]|0,this.Ch=q[4]|0,this.Cl=q[5]|0,this.Dh=q[6]|0,this.Dl=q[7]|0,this.Eh=q[8]|0,this.El=q[9]|0,this.Fh=q[10]|0,this.Fl=q[11]|0,this.Gh=q[12]|0,this.Gl=q[13]|0,this.Hh=q[14]|0,this.Hl=q[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:d,Fl:f,Gh:x,Gl:p,Hh:b,Hl:E}=this;return[t,r,n,o,s,i,c,a,u,l,d,f,x,p,b,E]}set(t,r,n,o,s,i,c,a,u,l,d,f,x,p,b,E){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=d|0,this.Fl=f|0,this.Gh=x|0,this.Gl=p|0,this.Hh=b|0,this.Hl=E|0}process(t,r){for(let g=0;g<16;g++,r+=4)It[g]=t.getUint32(r),Tt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let I=It[g-15]|0,S=Tt[g-15]|0,D=jt(I,S,1)^jt(I,S,8)^nr(I,S,7),P=Ht(I,S,1)^Ht(I,S,8)^or(I,S,7),T=It[g-2]|0,m=Tt[g-2]|0,y=jt(T,m,19)^re(T,m,61)^nr(T,m,6),_=Ht(T,m,19)^ne(T,m,61)^or(T,m,6),O=dn(P,_,Tt[g-7],Tt[g-16]),B=ln(O,D,y,It[g-7],It[g-16]);It[g]=B|0,Tt[g]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:d,El:f,Fh:x,Fl:p,Gh:b,Gl:E,Hh:h,Hl:w}=this;for(let g=0;g<80;g++){let I=jt(d,f,14)^jt(d,f,18)^re(d,f,41),S=Ht(d,f,14)^Ht(d,f,18)^ne(d,f,41),D=d&x^~d&b,P=f&p^~f&E,T=hn(w,S,P,Ho[g],Tt[g]),m=pn(T,h,I,D,jo[g],It[g]),y=T|0,_=jt(n,o,28)^re(n,o,34)^re(n,o,39),O=Ht(n,o,28)^ne(n,o,34)^ne(n,o,39),B=n&s^n&c^s&c,A=o&i^o&a^i&a;h=b|0,w=E|0,b=x|0,E=p|0,x=d|0,p=f|0,{h:d,l:f}=st(u|0,l|0,m|0,y|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let M=fn(y,O,A);n=un(M,m,_,B),o=M|0}({h:n,l:o}=st(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=st(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=st(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=st(this.Dh|0,this.Dl|0,u|0,l|0),{h:d,l:f}=st(this.Eh|0,this.El|0,d|0,f|0),{h:x,l:p}=st(this.Fh|0,this.Fl|0,x|0,p|0),{h:b,l:E}=st(this.Gh|0,this.Gl|0,b|0,E|0),{h,l:w}=st(this.Hh|0,this.Hl|0,h|0,w|0),this.set(n,o,s,i,c,a,u,l,d,f,x,p,b,E,h,w)}roundClean(){Mt(It,Tt)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var St=Oe(()=>new Be),gn=Oe(()=>new sr),mn=Oe(()=>new ir);var ve="__principal__",qo=2,bn=4,Ko="aaaaa-aa",F=class e{static anonymous(){return new this(new Uint8Array([bn]))}static managementCanister(){return this.fromText(Ko)}static selfAuthenticating(t){let r=gn(t);return new this(new Uint8Array([...r,qo]))}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(Y(t))}static fromText(t){let r=t;if(t.includes(ve)){let i=JSON.parse(t);ve in i&&(r=i[ve])}let n=r.toLowerCase().replace(/-/g,""),o=Qr(n);o=o.slice(4,o.length);let s=new this(o);if(s.toText()!==r)throw new Error(`Principal "${s.toText()}" does not have a valid checksum (original value "${r}" may not be a valid Principal ID).`);return s}static fromUint8Array(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]===bn}toUint8Array(){return this._arr}toHex(){return L(this._arr).toUpperCase()}toText(){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,tn(this._arr));let n=new Uint8Array(t),o=new Uint8Array([...n,...this._arr]),i=Xr(o).match(/.{1,5}/g);if(!i)throw new Error;return i.join("-")}toString(){return this.toText()}toJSON(){return{[ve]: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 ar;(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"})(ar||(ar={}));var $t=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?v(this.requestContext.requestId):"undefined"}
4
- Sender pubkey (hex): ${v(this.requestContext.senderPubKey)}
5
- Sender signature (hex): ${v(this.requestContext.senderSignature)}
3
+ Request ID (hex): ${this.requestContext.requestId?L(this.requestContext.requestId):"undefined"}
4
+ Sender pubkey (hex): ${L(this.requestContext.senderPubKey)}
5
+ Sender signature (hex): ${L(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}},Le=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}`}},Ce=class extends Le{static fromCode(t){return new this(t)}};var H=class e extends Ce{constructor(t){super(t,De.Input),this.name="InputError",Object.setPrototypeOf(this,e.prototype)}};var ie=class e extends Ot{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}`}},lt=class e extends Ot{constructor(t){super(),this.error=t,this.name="DerDecodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to decode DER: ${this.error}`}},Nt=class e extends Ot{constructor(t){super(),this.error=t,this.name="DerEncodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to encode DER: ${this.error}`}};var ce=class e extends Ot{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}`}};var gs=new Error("unreachable");var ae=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=X(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 X(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?X(e.buffer):new Uint8Array(e)}function Pe(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 Nr(e,t){return Pe(e,t)===0}function Ur(e){let t=BigInt(e);if(e<=0)throw new RangeError("Input must be positive");return t.toString(2).length-1}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:Ur(e))+1,r=new ae(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 Ne(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?Ne(e.buffer):new Uint8Array(e)}function Mr(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 Ue(e){if(typeof e=="string")return jr(e);if(typeof e=="number")return dt(Re(e));if(e instanceof Uint8Array||ArrayBuffer.isView(e))return dt(Ne(e));if(Array.isArray(e)){let t=e.map(Ue);return dt(G(...t))}else{if(e&&typeof e=="object"&&e._isPrincipal)return dt(e.toUint8Array());if(typeof e=="object"&&e!==null&&typeof e.toHash=="function")return Ue(e.toHash());if(typeof e=="object")return qr(e);if(typeof e=="bigint")return dt(Re(e))}throw H.fromCode(new ce(e))}var jr=e=>{let t=new TextEncoder().encode(e);return dt(t)};function Ut(e){return qr(e)}function qr(e){let n=Object.entries(e).filter(([,i])=>i!==void 0).map(([i,a])=>{let c=jr(i),u=Ue(a);return[c,u]}).sort(([i],[a])=>Pe(i,a)),o=G(...n.map(i=>G(...i)));return dt(o)}var Mt=new TextEncoder().encode(`
11
- ic-request`),Yn=new TextEncoder().encode("\vic-response"),Me=new TextEncoder().encode("ic-request-auth-delegation");var ht=class{getPrincipal(){return this._principal||(this._principal=Z.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(t){let{body:r,...n}=t,o=Ut(r);return{...n,body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(G(Mt,o))}}}},jt=class{getPrincipal(){return Z.anonymous()}async transformRequest(t){return{...t,body:{content:t.body}}}};var He=BigInt(0),qe=BigInt(1);function fe(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function qt(e,t,r=""){let n=wt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function Hr(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?He:BigInt("0x"+e)}function Kr(e){return Hr(v(e))}function xt(e){return $(e),Hr(v(Uint8Array.from(e).reverse()))}function Ke(e,t){return q(e.toString(16).padStart(t*2,"0"))}function kr(e,t){return Ke(e,t).reverse()}function K(e,t,r){let n;if(typeof t=="string")try{n=q(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(wt(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 Vr(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 ke(e){return Uint8Array.from(e)}var je=e=>typeof e=="bigint"&&He<=e;function Fn(e,t,r){return je(e)&&je(t)&&je(r)&&t<=e&&e<r}function Ve(e,t,r,n){if(!Fn(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function $r(e){let t;for(t=0;e>He;e>>=qe,t+=1);return t}var Ht=e=>(qe<<BigInt(e))-qe;function Kt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var $e=()=>{throw new Error("not implemented")};function Ge(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var M=BigInt(0),U=BigInt(1),Bt=BigInt(2),Fr=BigInt(3),Zr=BigInt(4),zr=BigInt(5),Zn=BigInt(7),Wr=BigInt(8),zn=BigInt(9),Xr=BigInt(16);function C(e,t){let r=e%t;return r>=M?r:t+r}function z(e,t,r){let n=e;for(;t-- >M;)n*=n,n%=r;return n}function Gr(e,t){if(e===M)throw new Error("invert: expected non-zero number");if(t<=M)throw new Error("invert: expected positive modulus, got "+t);let r=C(e,t),n=t,o=M,s=U,i=U,a=M;for(;r!==M;){let u=n/r,l=n%r,d=o-i*u,f=s-a*u;n=r,r=l,o=i,s=a,i=d,a=f}if(n!==U)throw new Error("invert: does not exist");return C(o,t)}function Ye(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Jr(e,t){let r=(e.ORDER+U)/Zr,n=e.pow(t,r);return Ye(e,n,t),n}function Wn(e,t){let r=(e.ORDER-zr)/Wr,n=e.mul(t,Bt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Bt),o),a=e.mul(s,e.sub(i,e.ONE));return Ye(e,a,t),a}function Xn(e){let t=ot(e),r=Qr(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Zn)/Xr;return(a,c)=>{let u=a.pow(c,i),l=a.mul(u,n),d=a.mul(u,o),f=a.mul(u,s),p=a.eql(a.sqr(l),c),x=a.eql(a.sqr(d),c);u=a.cmov(u,l,p),l=a.cmov(f,d,x);let b=a.eql(a.sqr(l),c),E=a.cmov(u,l,b);return Ye(a,E,c),E}}function Qr(e){if(e<Fr)throw new Error("sqrt is not defined for small field");let t=e-U,r=0;for(;t%Bt===M;)t/=Bt,r++;let n=Bt,o=ot(e);for(;Yr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Jr;let s=o.pow(n,t),i=(t+U)/Bt;return function(c,u){if(c.is0(u))return u;if(Yr(c,u)!==1)throw new Error("Cannot find square root");let l=r,d=c.mul(c.ONE,s),f=c.pow(u,t),p=c.pow(u,i);for(;!c.eql(f,c.ONE);){if(c.is0(f))return c.ZERO;let x=1,b=c.sqr(f);for(;!c.eql(b,c.ONE);)if(x++,b=c.sqr(b),x===l)throw new Error("Cannot find square root");let E=U<<BigInt(l-x-1),h=c.pow(d,E);l=x,d=c.sqr(h),f=c.mul(f,d),p=c.mul(p,h)}return p}}function Jn(e){return e%Zr===Fr?Jr:e%Wr===zr?Wn:e%Xr===zn?Xn(e):Qr(e)}var nt=(e,t)=>(C(e,t)&U)===U,Qn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function tn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Qn.reduce((n,o)=>(n[o]="function",n),t);return Kt(e,r),e}function to(e,t,r){if(r<M)throw new Error("invalid exponent, negatives unsupported");if(r===M)return e.ONE;if(r===U)return t;let n=e.ONE,o=t;for(;r>M;)r&U&&(n=e.mul(n,o)),o=e.sqr(o),r>>=U;return n}function ue(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Yr(e,t){let r=(e.ORDER-U)/Bt,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function en(e,t){t!==void 0&&Ee(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ot(e,t,r=!1,n={}){if(e<=M)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),a=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:u}=en(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l,d=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:u,MASK:Ht(c),ZERO:M,ONE:U,allowedLengths:a,create:f=>C(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return M<=f&&f<e},is0:f=>f===M,isValidNot0:f=>!d.is0(f)&&d.isValid(f),isOdd:f=>(f&U)===U,neg:f=>C(-f,e),eql:(f,p)=>f===p,sqr:f=>C(f*f,e),add:(f,p)=>C(f+p,e),sub:(f,p)=>C(f-p,e),mul:(f,p)=>C(f*p,e),pow:(f,p)=>to(d,f,p),div:(f,p)=>C(f*Gr(p,e),e),sqrN:f=>f*f,addN:(f,p)=>f+p,subN:(f,p)=>f-p,mulN:(f,p)=>f*p,inv:f=>Gr(f,e),sqrt:s||(f=>(l||(l=Jn(e)),l(d,f))),toBytes:f=>r?kr(f,u):Ke(f,u),fromBytes:(f,p=!0)=>{if(a){if(!a.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);let b=new Uint8Array(u);b.set(f,r?0:b.length-f.length),f=b}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let x=r?xt(f):Kr(f);if(i&&(x=C(x,e)),!p&&!d.isValid(x))throw new Error("invalid field element: outside of range 0..ORDER");return x},invertBatch:f=>ue(d,f),cmov:(f,p,x)=>x?p:f});return Object.freeze(d)}var de=BigInt(0),We=BigInt(1);function rn(e,t){let r=t.negate();return e?r:t}function kt(e,t){let r=ue(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function cn(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Fe(e,t){cn(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Ht(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function nn(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=We);let u=t*n,l=u+Math.abs(a)-1,d=a===0,f=a<0,p=t%2!==0;return{nextN:c,offset:l,isZero:d,isNeg:f,isNegF:p,offsetF:u}}function eo(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 ro(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 Ze=new WeakMap,an=new WeakMap;function ze(e){return an.get(e)||1}function on(e){if(e!==de)throw new Error("invalid wNAF")}var le=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>de;)r&We&&(n=n.add(o)),o=o.double(),r>>=We;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Fe(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Fe(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:d,isNegF:f,offsetF:p}=nn(n,a,i);n=c,l?s=s.add(rn(f,r[p])):o=o.add(rn(d,r[u]))}return on(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Fe(t,this.bits);for(let i=0;i<s.windows&&n!==de;i++){let{nextN:a,offset:c,isZero:u,isNeg:l}=nn(n,i,s);if(n=a,!u){let d=r[c];o=o.add(l?d.negate():d)}}return on(n),o}getPrecomputes(t,r,n){let o=Ze.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Ze.set(r,o))),o}cached(t,r,n){let o=ze(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=ze(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){cn(r,this.bits),an.set(t,r),Ze.delete(t)}hasCache(t){return ze(t)!==1}};function he(e,t,r,n){eo(r,e),ro(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=$r(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=Ht(c),l=new Array(Number(u)+1).fill(i),d=Math.floor((t.BITS-1)/c)*c,f=i;for(let p=d;p>=0;p-=c){l.fill(i);for(let b=0;b<s;b++){let E=n[b],h=Number(E>>BigInt(p)&u);l[h]=l[h].add(r[b])}let x=i;for(let b=l.length-1,E=i;b>0;b--)E=E.add(l[b]),x=x.add(E);if(f=f.add(x),p!==0)for(let b=0;b<c;b++)f=f.double()}return f}function sn(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return tn(t),t}else return ot(e,{isLE:r})}function fn(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>de))throw new Error(`CURVE.${c} must be positive bigint`)}let o=sn(t.p,r.Fp,n),s=sn(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:s}}var pt=BigInt(0),R=BigInt(1),Xe=BigInt(2),no=BigInt(8);function oo(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function so(e,t={}){let r=fn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;Kt(t,{},{uvRatio:"function"});let a=Xe<<BigInt(o.BYTES*8)-R,c=E=>n.create(E),u=t.uvRatio||((E,h)=>{try{return{isValid:!0,value:n.sqrt(n.div(E,h))}}catch{return{isValid:!1,value:pt}}});if(!oo(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(E,h,w=!1){let y=w?R:pt;return Ve("coordinate "+E,h,y,a),h}function d(E){if(!(E instanceof x))throw new Error("ExtendedPoint expected")}let f=Ge((E,h)=>{let{X:w,Y:y,Z:I}=E,A=E.is0();h==null&&(h=A?no:n.inv(I));let D=c(w*h),L=c(y*h),B=n.mul(I,h);if(A)return{x:pt,y:R};if(B!==R)throw new Error("invZ was invalid");return{x:D,y:L}}),p=Ge(E=>{let{a:h,d:w}=s;if(E.is0())throw new Error("bad point: ZERO");let{X:y,Y:I,Z:A,T:D}=E,L=c(y*y),B=c(I*I),g=c(A*A),m=c(g*g),_=c(L*h),S=c(g*c(_+B)),T=c(m+c(w*c(L*B)));if(S!==T)throw new Error("bad point: equation left != right (1)");let O=c(y*I),P=c(A*D);if(O!==P)throw new Error("bad point: equation left != right (2)");return!0});class x{constructor(h,w,y,I){this.X=l("x",h),this.Y=l("y",w),this.Z=l("z",y,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){if(h instanceof x)throw new Error("extended point not allowed");let{x:w,y}=h||{};return l("x",w),l("y",y),new x(w,y,R,c(w*y))}static fromBytes(h,w=!1){let y=n.BYTES,{a:I,d:A}=s;h=ke(qt(h,y,"point")),fe(w,"zip215");let D=ke(h),L=h[y-1];D[y-1]=L&-129;let B=xt(D),g=w?a:n.ORDER;Ve("point.y",B,pt,g);let m=c(B*B),_=c(m-R),S=c(A*m-I),{isValid:T,value:O}=u(_,S);if(!T)throw new Error("bad point: invalid y coordinate");let P=(O&R)===R,j=(L&128)!==0;if(!w&&O===pt&&j)throw new Error("bad point: x=0 and x_0=1");return j!==P&&(O=c(-O)),x.fromAffine({x:O,y:B})}static fromHex(h,w=!1){return x.fromBytes(K("point",h),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,w=!0){return b.createCache(this,h),w||this.multiply(Xe),this}assertValidity(){p(this)}equals(h){d(h);let{X:w,Y:y,Z:I}=this,{X:A,Y:D,Z:L}=h,B=c(w*L),g=c(A*I),m=c(y*L),_=c(D*I);return B===g&&m===_}is0(){return this.equals(x.ZERO)}negate(){return new x(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:h}=s,{X:w,Y:y,Z:I}=this,A=c(w*w),D=c(y*y),L=c(Xe*c(I*I)),B=c(h*A),g=w+y,m=c(c(g*g)-A-D),_=B+D,S=_-L,T=B-D,O=c(m*S),P=c(_*T),j=c(m*T),ct=c(S*_);return new x(O,P,ct,j)}add(h){d(h);let{a:w,d:y}=s,{X:I,Y:A,Z:D,T:L}=this,{X:B,Y:g,Z:m,T:_}=h,S=c(I*B),T=c(A*g),O=c(L*y*_),P=c(D*m),j=c((I+A)*(B+g)-S-T),ct=P-O,bt=P+O,Q=c(T-w*S),Lt=c(j*ct),Jt=c(bt*Q),we=c(j*Q),xr=c(ct*bt);return new x(Lt,Jt,xr,we)}subtract(h){return this.add(h.negate())}multiply(h){if(!o.isValidNot0(h))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:w,f:y}=b.cached(this,h,I=>kt(x,I));return kt(x,[w,y])[0]}multiplyUnsafe(h,w=x.ZERO){if(!o.isValid(h))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return h===pt?x.ZERO:this.is0()||h===R?this:b.unsafe(this,h,y=>kt(x,y),w)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return b.unsafe(this,s.n).is0()}toAffine(h){return f(this,h)}clearCofactor(){return i===R?this:this.multiplyUnsafe(i)}toBytes(){let{x:h,y:w}=this.toAffine(),y=n.toBytes(w);return y[y.length-1]|=h&R?128:0,y}toHex(){return v(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(h){return kt(x,h)}static msm(h,w){return he(x,o,h,w)}_setWindowSize(h){this.precompute(h)}toRawBytes(){return this.toBytes()}}x.BASE=new x(s.Gx,s.Gy,R,c(s.Gx*s.Gy)),x.ZERO=new x(pt,R,R,pt),x.Fp=n,x.Fn=o;let b=new le(x,o.BITS);return x.BASE.precompute(8),x}var xe=class{constructor(t){this.ep=t}static fromBytes(t){$e()}static fromHex(t){$e()}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 v(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 io(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Kt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||Ae,c=r.adjustScalarBytes||(g=>g),u=r.domain||((g,m,_)=>{if(fe(_,"phflag"),m.length||_)throw new Error("Contexts/pre-hash are not supported");return g});function l(g){return i.create(xt(g))}function d(g){let m=y.secretKey;g=K("private key",g,m);let _=K("hashed private key",t(g),2*m),S=c(_.slice(0,m)),T=_.slice(m,2*m),O=l(S);return{head:S,prefix:T,scalar:O}}function f(g){let{head:m,prefix:_,scalar:S}=d(g),T=o.multiply(S),O=T.toBytes();return{head:m,prefix:_,scalar:S,point:T,pointBytes:O}}function p(g){return f(g).pointBytes}function x(g=Uint8Array.of(),...m){let _=G(...m);return l(t(u(_,K("context",g),!!n)))}function b(g,m,_={}){g=K("message",g),n&&(g=n(g));let{prefix:S,scalar:T,pointBytes:O}=f(m),P=x(_.context,S,g),j=o.multiply(P).toBytes(),ct=x(_.context,j,O,g),bt=i.create(P+ct*T);if(!i.isValid(bt))throw new Error("sign failed: invalid s");let Q=G(j,i.toBytes(bt));return qt(Q,y.signature,"result")}let E={zip215:!0};function h(g,m,_,S=E){let{context:T,zip215:O}=S,P=y.signature;g=K("signature",g,P),m=K("message",m),_=K("publicKey",_,y.publicKey),O!==void 0&&fe(O,"zip215"),n&&(m=n(m));let j=P/2,ct=g.subarray(0,j),bt=xt(g.subarray(j,P)),Q,Lt,Jt;try{Q=e.fromBytes(_,O),Lt=e.fromBytes(ct,O),Jt=o.multiplyUnsafe(bt)}catch{return!1}if(!O&&Q.isSmallOrder())return!1;let we=x(T,Lt.toBytes(),Q.toBytes(),m);return Lt.add(Q.multiplyUnsafe(we)).subtract(Jt).clearCofactor().is0()}let w=s.BYTES,y={secretKey:w,publicKey:w,signature:2*w,seed:w};function I(g=a(y.seed)){return qt(g,y.seed,"seed")}function A(g){let m=B.randomSecretKey(g);return{secretKey:m,publicKey:p(m)}}function D(g){return wt(g)&&g.length===i.BYTES}function L(g,m){try{return!!e.fromBytes(g,m)}catch{return!1}}let B={getExtendedPublicKey:f,randomSecretKey:I,isValidSecretKey:D,isValidPublicKey:L,toMontgomery(g){let{y:m}=e.fromBytes(g),_=y.publicKey,S=_===32;if(!S&&_!==57)throw new Error("only defined for 25519 and 448");let T=S?s.div(R+m,R-m):s.div(m-R,m+R);return s.toBytes(T)},toMontgomerySecret(g){let m=y.secretKey;qt(g,m);let _=t(g.subarray(0,m));return c(_).subarray(0,m)},randomPrivateKey:I,precompute(g=8,m=e.BASE){return m.precompute(g,!1)}};return Object.freeze({keygen:A,getPublicKey:p,sign:b,verify:h,utils:B,Point:e,lengths:y})}function co(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=ot(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function ao(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function un(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=co(e),s=so(t,r),i=io(s,n,o);return ao(e,i)}var fo=BigInt(0),st=BigInt(1),dn=BigInt(2),oi=BigInt(3),uo=BigInt(5),lo=BigInt(8),Tt=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Vt={p:Tt,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:lo,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ho(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Tt,a=e*e%s*e%s,c=z(a,dn,s)*a%s,u=z(c,st,s)*e%s,l=z(u,uo,s)*u%s,d=z(l,t,s)*l%s,f=z(d,r,s)*d%s,p=z(f,n,s)*f%s,x=z(p,o,s)*p%s,b=z(x,o,s)*p%s,E=z(b,t,s)*l%s;return{pow_p_5_8:z(E,dn,s)*e%s,b2:a}}function xo(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Je=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function er(e,t){let r=Tt,n=C(t*t*t,r),o=C(n*n*t,r),s=ho(e*o).pow_p_5_8,i=C(e*n*s,r),a=C(t*i*i,r),c=i,u=C(i*Je,r),l=a===e,d=a===C(-e,r),f=a===C(-e*Je,r);return l&&(i=c),(d||f)&&(i=u),nt(i,r)&&(i=C(-i,r)),{isValid:l||d,value:i}}var yt=ot(Vt.p,{isLE:!0}),po=ot(Vt.n,{isLE:!0}),yo={...Vt,Fp:yt,hash:Pr,adjustScalarBytes:xo,uvRatio:er},k=un(yo);var Qe=Je,go=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),bo=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),mo=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),wo=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ln=e=>er(st,e),Eo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),tr=e=>k.Point.Fp.create(xt(e)&Eo);function hn(e){let{d:t}=Vt,r=Tt,n=h=>yt.create(h),o=n(Qe*e*e),s=n((o+st)*mo),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=er(s,a),l=n(u*e);nt(l,r)||(l=n(-l)),c||(u=l),c||(i=o);let d=n(i*(o-st)*wo-a),f=u*u,p=n((u+u)*a),x=n(d*go),b=n(st-f),E=n(st+f);return new k.Point(n(p*E),n(b*x),n(x*E),n(p*b))}function _o(e){$(e,64);let t=tr(e.subarray(0,32)),r=hn(t),n=tr(e.subarray(32,64)),o=hn(n);return new it(r.add(o))}var it=class e extends xe{constructor(t){super(t)}static fromAffine(t){return new e(k.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return _o(K("ristrettoHash",t,64))}static fromBytes(t){$(t,32);let{a:r,d:n}=Vt,o=Tt,s=I=>yt.create(I),i=tr(t);if(!Vr(yt.toBytes(i),t)||nt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(st+r*a),u=s(st-r*a),l=s(c*c),d=s(u*u),f=s(r*n*l-d),{isValid:p,value:x}=ln(s(f*d)),b=s(x*u),E=s(x*b*f),h=s((i+i)*b);nt(h,o)&&(h=s(-h));let w=s(c*E),y=s(h*w);if(!p||nt(y,o)||w===fo)throw new Error("invalid ristretto255 encoding 2");return new e(new k.Point(h,w,st,y))}static fromHex(t){return e.fromBytes(K("ristrettoHex",t,32))}static msm(t,r){return he(e,k.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Tt,i=E=>yt.create(E),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:l}=ln(i(a*u)),d=i(l*a),f=i(l*c),p=i(d*f*o),x;if(nt(o*p,s)){let E=i(r*Qe),h=i(t*Qe);t=E,r=h,x=i(d*bo)}else x=f;nt(t*p,s)&&(r=i(-r));let b=i((n-r)*x);return nt(b,s)&&(b=i(-b)),yt.toBytes(b)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>yt.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};it.BASE=new it(k.Point.BASE);it.ZERO=new it(k.Point.ZERO);it.Fp=yt;it.Fn=po;var xn=e=>{if(e<=127)return 1;if(e<=255)return 2;if(e<=65535)return 3;if(e<=16777215)return 4;throw H.fromCode(new Nt("Length too long (> 4 bytes)"))},pn=(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 H.fromCode(new Nt("Length too long (> 4 bytes)"))},rr=(e,t)=>{if(e[t]<128)return 1;if(e[t]===128)throw H.fromCode(new lt("Invalid length 0"));if(e[t]===129)return 2;if(e[t]===130)return 3;if(e[t]===131)return 4;throw H.fromCode(new lt("Length too long (> 4 bytes)"))},Io=(e,t)=>{let r=rr(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 H.fromCode(new lt("Length too long (> 4 bytes)"))},ai=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),nr=Uint8Array.from([48,5,6,3,43,101,112]),fi=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]),ui=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 yn(e,t){let r=2+xn(e.byteLength+1),n=t.byteLength+r+e.byteLength,o=0,s=new Uint8Array(1+xn(n)+n);return s[o++]=48,o+=pn(s,o,n),s.set(t,o),o+=t.byteLength,s[o++]=3,o+=pn(s,o,e.byteLength+1),s[o++]=0,s.set(new Uint8Array(e),o),s}var gn=(e,t)=>{let r=0,n=(a,c)=>{if(o[r++]!==a)throw H.fromCode(new lt(`Expected ${c} at offset ${r}`))},o=new Uint8Array(e);if(n(48,"sequence"),r+=rr(o,r),!Mr(o.slice(r,r+t.byteLength),t))throw H.fromCode(new lt("Not the expected OID."));r+=t.byteLength,n(3,"bit string");let s=Io(o,r)-1;r+=rr(o,r),n(0,"0 padding");let i=o.slice(r);if(s!==i.length)throw H.fromCode(new ie(s,i.length));return i};function bn(e){return e!==null&&typeof e=="object"}var $t=class e{static from(t){if(typeof t=="string"){let r=q(t);return this.fromRaw(r)}else if(bn(t)){let r=t;if(bn(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(X(n.buffer))}else{if(r instanceof ArrayBuffer)return this.fromRaw(X(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=yn(t,nr);return r.__derEncodedPublicKey__=void 0,r}static derDecode(t){let r=gn(t,nr);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}#t;get rawKey(){return this.#t}#e;get derKey(){return this.#e}constructor(t){if(t.byteLength!==e.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");this.#t=t,this.#e=e.derEncode(t)}toDer(){return this.derKey}toRaw(){return this.rawKey}},vt=class e extends ht{static generate(t){if(t&&t.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");t||(t=k.utils.randomPrivateKey()),Nr(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=k.getPublicKey(r);return e.fromKeyPair(n,r)}static fromParsedJson(t){let[r,n]=t;return new e($t.fromDer(q(r)),q(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($t.fromRaw(t),r)}static fromSecretKey(t){let r=k.getPublicKey(t);return e.fromKeyPair(r,t)}#t;#e;constructor(t,r){super(),this.#t=$t.from(t),this.#e=r}toJSON(){return[v(this.#t.toDer()),v(this.#e)]}getKeyPair(){return{secretKey:this.#e,publicKey:this.#t}}getPublicKey(){return this.#t}async sign(t){let r=k.sign(t,this.#e.slice(0,32));return Object.defineProperty(r,"__signature__",{enumerable:!1,value:void 0}),r}static verify(t,r,n){let[o,s,i]=[t,r,n].map(a=>(typeof a=="string"&&(a=q(a)),X(a)));return k.verify(o,s,i)}};var or=class e extends Error{constructor(t){super(t),this.message=t,Object.setPrototypeOf(this,e.prototype)}};function mn(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 or("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 Gt=class e extends ht{static async generate(t){let{extractable:r=!1,keyUsages:n=["sign","verify"],subtleCrypto:o}=t??{},s=mn(o),i=await s.generateKey({name:"ECDSA",namedCurve:"P-256"},r,n),a=X(await s.exportKey("spki",i.publicKey));return Object.assign(a,{__derEncodedPublicKey__:void 0}),new this(i,a,s)}static async fromKeyPair(t,r){let n=mn(r),o=X(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=X(await this._subtleCrypto.sign(r,this._keyPair.privateKey,t));return Object.assign(n,{__signature__:void 0}),n}};var pe=class{#t;get rawKey(){return this.#t.rawKey}get derKey(){return this.#t.derKey}toDer(){return this.#t.toDer()}getPublicKey(){return this.#t}getPrincipal(){if(!this.#t.rawKey)throw new Error("Cannot get principal from a public key without a raw key.");return Z.fromUint8Array(new Uint8Array(this.#t.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.#t=t}};function sr(e){if(typeof e!="string"||e.length<64)throw new Error("Invalid public key.");return q(e)}var Dt=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:v(this.pubkey),...this.targets&&{targets:this.targets.map(t=>t.toHex())}}}};async function Bo(e,t,r,n){let o=new Dt(t.toDer(),BigInt(+r)*BigInt(1e6),n),s=new Uint8Array([...Me,...new Uint8Array(Ut({...o}))]),i=await e.sign(s);return{delegation:o,signature:i}}var At=class e{static async create(t,r,n=new Date(Date.now()+900*1e3),o={}){let s=await Bo(t,r,n,o.targets);return new e([...o.previous?.delegations||[],s],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(s=>{let{delegation:i,signature:a}=s,{pubkey:c,expiration:u,targets:l}=i;if(l!==void 0&&!Array.isArray(l))throw new Error("Invalid targets.");return{delegation:new Dt(sr(c),BigInt("0x"+u),l&&l.map(d=>{if(typeof d!="string")throw new Error("Invalid target.");return Z.fromHex(d)})),signature:sr(a)}});return new this(o,sr(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:v(r.pubkey),...o&&{targets:o.map(s=>s.toHex())}},signature:v(n)}}),publicKey:v(this.publicKey)}}},Yt=class extends ht{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 Ut(r);return{...n,body:{content:r,sender_sig:await this.sign(new Uint8Array([...Mt,...new Uint8Array(o)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}}}},Ft=class e extends pe{#t;get delegation(){return this.#t}constructor(t,r){super(t),this.#t=r}static fromDelegation(t,r){return new e(t,r)}};function Zt(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"?Z.fromText(o):o)):r.push(typeof n=="string"?Z.fromText(n):n));for(let o of r){let s=o.toText();for(let{delegation:i}of e.delegations){if(i.targets===void 0)continue;let a=!0;for(let c of i.targets)if(c.toText()===s){a=!1;break}if(a)return!1}}return!0}var wn=["mousedown","mousemove","keydown","touchstart","wheel"],zt=class{callbacks=[];idleTimeout=600*1e3;timeoutID=void 0;static create(t={}){return new this(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),wn.forEach(function(i){document.addEventListener(i,o,!0)});let s=(i,a)=>{let c;return(...u)=>{let l=this,d=function(){c=void 0,i.apply(l,u)};clearTimeout(c),c=window.setTimeout(d,a)}};if(t?.captureScroll){let i=s(o,t?.scrollDebounce??100);window.addEventListener("scroll",i,!0)}o()}registerCallback(t){this.callbacks.push(t)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let t=this._resetTimer.bind(this);wn.forEach(function(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 Ao=(e,t)=>t.some(r=>e instanceof r),En,_n;function So(){return En||(En=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Oo(){return _n||(_n=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var In=new WeakMap,cr=new WeakMap,Bn=new WeakMap,ir=new WeakMap,fr=new WeakMap;function To(e){let t=new Promise((r,n)=>{let o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{r(J(e.result)),o()},i=()=>{n(e.error),o()};e.addEventListener("success",s),e.addEventListener("error",i)});return t.then(r=>{r instanceof IDBCursor&&In.set(r,e)}).catch(()=>{}),fr.set(t,e),t}function vo(e){if(cr.has(e))return;let t=new Promise((r,n)=>{let o=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",i),e.removeEventListener("abort",i)},s=()=>{r(),o()},i=()=>{n(e.error||new DOMException("AbortError","AbortError")),o()};e.addEventListener("complete",s),e.addEventListener("error",i),e.addEventListener("abort",i)});cr.set(e,t)}var ar={get(e,t,r){if(e instanceof IDBTransaction){if(t==="done")return cr.get(e);if(t==="objectStoreNames")return e.objectStoreNames||Bn.get(e);if(t==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return J(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 An(e){ar=e(ar)}function Do(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(t,...r){let n=e.call(ye(this),t,...r);return Bn.set(n,t.sort?t.sort():[t]),J(n)}:Oo().includes(e)?function(...t){return e.apply(ye(this),t),J(In.get(this))}:function(...t){return J(e.apply(ye(this),t))}}function Lo(e){return typeof e=="function"?Do(e):(e instanceof IDBTransaction&&vo(e),Ao(e,So())?new Proxy(e,ar):e)}function J(e){if(e instanceof IDBRequest)return To(e);if(ir.has(e))return ir.get(e);let t=Lo(e);return t!==e&&(ir.set(e,t),fr.set(t,e)),t}var ye=e=>fr.get(e);function On(e,t,{blocked:r,upgrade:n,blocking:o,terminated:s}={}){let i=indexedDB.open(e,t),a=J(i);return n&&i.addEventListener("upgradeneeded",c=>{n(J(i.result),c.oldVersion,c.newVersion,J(i.transaction),c)}),r&&i.addEventListener("blocked",c=>r(c.oldVersion,c.newVersion,c)),a.then(c=>{s&&c.addEventListener("close",()=>s()),o&&c.addEventListener("versionchange",u=>o(u.oldVersion,u.newVersion,u))}).catch(()=>{}),a}var Co=["get","getKey","getAll","getAllKeys","count"],Po=["put","add","delete","clear"],ur=new Map;function Sn(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(ur.get(t))return ur.get(t);let r=t.replace(/FromIndex$/,""),n=t!==r,o=Po.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(o||Co.includes(r)))return;let s=async function(i,...a){let c=this.transaction(i,o?"readwrite":"readonly"),u=c.store;return n&&(u=u.index(a.shift())),(await Promise.all([u[r](...a),o&&c.done]))[0]};return ur.set(t,s),s}An(e=>({...e,get:(t,r,n)=>Sn(t,r)||e.get(t,r,n),has:(t,r)=>!!Sn(t,r)||e.has(t,r)}));var Tn="auth-client-db",vn="ic-keyval",Ro=async(e=Tn,t=vn,r)=>(ge&&localStorage?.getItem(V)&&(localStorage.removeItem(V),localStorage.removeItem(Y)),await On(e,r,{upgrade:n=>{n.objectStoreNames.contains(t)&&n.clear(t),n.createObjectStore(t)}}));async function No(e,t,r){return await e.get(t,r)}async function Uo(e,t,r,n){return await e.put(t,n,r)}async function Mo(e,t,r){return await e.delete(t,r)}var Wt=class e{_db;_storeName;static async create(t){let{dbName:r=Tn,storeName:n=vn,version:o=Dn}=t??{},s=await Ro(r,n,o);return new e(s,n)}constructor(t,r){this._db=t,this._storeName=r}async set(t,r){return await Uo(this._db,this._storeName,t,r)}async get(t){return await No(this._db,this._storeName,t)??null}async remove(t){return await Mo(this._db,this._storeName,t)}};var Y="identity",V="delegation",Ln="iv",Dn=1,ge=typeof window<"u",Xt=class{prefix;_localStorage;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=typeof window>"u"?typeof global>"u"?typeof self>"u"?void 0:self.localStorage:global.localStorage:window.localStorage;if(!t)throw new Error("Could not find local storage.");return t}},gt=class{#t;constructor(t){this.#t=t??{}}initializedDb;get _db(){return new Promise(t=>{if(this.initializedDb){t(this.initializedDb);return}Wt.create(this.#t).then(r=>{this.initializedDb=r,t(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 jo=BigInt(1e9),qo=BigInt(3600),Ho=jo*qo,Ko="https://identity.internetcomputer.org",ko="#authorize",Vo=BigInt(8)*Ho,dr="ECDSA",lr="Ed25519",$o=500,Go="UserInterrupt",be=class{_identity;_key;_chain;_storage;idleManager;_createOptions;_idpWindow;_eventHandler;static async create(t={}){let r=t.storage??new gt,n=t.keyType??dr,o=null;if(t.identity)o=t.identity;else{let c=await r.get(Y);if(!c&&ge)try{let u=new Xt,l=await u.get(V),d=await u.get(Y);l&&d&&n===dr&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await r.set(V,l),await r.set(Y,d),c=l,await u.remove(V),await u.remove(Y))}catch(u){console.error("error while attempting to recover localstorage: "+u)}if(c)try{typeof c=="object"?n===lr&&typeof c=="string"?o=vt.fromJSON(c):o=await Gt.fromKeyPair(c):typeof c=="string"&&(o=vt.fromJSON(c))}catch{}}let s=new jt,i=null;if(o)try{let c=await r.get(V);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?s=t.identity:c&&(i=At.fromJSON(c),Zt(i)?"toDer"in o?s=Ft.fromDelegation(o,i):s=Yt.fromDelegation(o,i):(await hr(r),o=null))}catch(c){console.error(c),await hr(r),o=null}let a;return t.idleOptions?.disableIdle?a=void 0:(i||t.identity)&&(a=zt.create(t.idleOptions)),o||(n===lr?(o=vt.generate(),await r.set(Y,JSON.stringify(o.toJSON()))):(t.storage&&n===dr&&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 '${lr}' as the key type, as it can serialize to a string`),o=await Gt.generate(),await r.set(Y,o.getKeyPair()))),new this(s,o,i,r,a,t)}constructor(t,r,n,o,s,i,a,c){this._identity=t,this._key=r,this._chain=n,this._storage=o,this.idleManager=s,this._createOptions=i,this._idpWindow=a,this._eventHandler=c,this._registerDefaultIdleCallback()}_registerDefaultIdleCallback(){let 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 Dt(a.delegation.pubkey,a.delegation.expiration,a.delegation.targets),signature:a.signature})),o=At.fromDelegations(n,t.userPublicKey),s=this._key;if(!s)return;this._chain=o,"toDer"in s?this._identity=Ft.fromDelegation(s,this._chain):this._identity=Yt.fromDelegation(s,this._chain),this._idpWindow?.close();let i=this._createOptions?.idleOptions;!this.idleManager&&!i?.disableIdle&&(this.idleManager=zt.create(i),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(V,JSON.stringify(this._chain.toJSON())),r?.(t)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null&&Zt(this._chain)}async login(t){let r=Yo(this._createOptions?.loginOptions,t),n=r?.maxTimeToLive??Vo,o=new URL(r?.identityProvider?.toString()||Ko);o.hash=ko,this._idpWindow?.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(o,{maxTimeToLive:n,...r}),window.addEventListener("message",this._eventHandler),this._idpWindow=window.open(o.toString(),"idpWindow",r?.windowOpenerFeatures)??void 0;let s=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(Go,r?.onError):setTimeout(s,$o))};s()}_getEventHandler(t,r){return async n=>{if(n.origin!==t.origin)return;let o=n.data;switch(o.kind){case"authorize-ready":{let s={kind:"authorize-client",sessionPublicKey:new Uint8Array(this._key?.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,allowPinAuthentication:r?.allowPinAuthentication,derivationOrigin:r?.derivationOrigin?.toString(),...r?.customValues};this._idpWindow?.postMessage(s,t.origin);break}case"authorize-client-success":try{await this._handleSuccess(o,r?.onSuccess)}catch(s){this._handleFailure(s.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(o.text,r?.onError);break;default:break}}}_handleFailure(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 hr(this._storage),this._identity=new jt,this._chain=null,t.returnTo)try{window.history.pushState({},"",t.returnTo)}catch{window.location.href=t.returnTo}}};async function hr(e){await e.remove(Y),await e.remove(V),await e.remove(Ln)}function Yo(e,t){if(!e&&!t)return;let r=e?.customValues||t?.customValues?{...e?.customValues,...t?.customValues}:void 0;return{...e,...t,customValues:r}}var lc=BigInt(144e11);var Cn=1e3;var Pn=()=>be.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var Rn=({data:e})=>{let{msg:t}=e;switch(t){case"junoStartAuthTimer":Fo();return;case"junoStopAuthTimer":Nn();return}},me,Fo=()=>me=setInterval(async()=>await Zo(),Cn),Nn=()=>{me&&(clearInterval(me),me=void 0)},Zo=async()=>{let[e,t]=await Promise.all([zo(),Wo()]);if(e&&t.valid&&t.delegation!==null){Jo(t.delegation);return}Xo()},zo=async()=>(await Pn()).isAuthenticated(),Wo=async()=>{let t=await new gt().get(V),r=t!==null?At.fromJSON(t):null;return{valid:r!==null&&Zt(r),delegation:r}},Xo=()=>{Nn(),postMessage({msg:"junoSignOutAuthTimer"})},Jo=e=>{let t=e.delegations[0]?.delegation.expiration;if(t===void 0)return;let r=new Date(Number(t/BigInt(1e6))).getTime()-Date.now();postMessage({msg:"junoDelegationRemainingTime",data:{authRemainingTime:r}})};onmessage=e=>{Rn(e)};})();
10
+ HTTP details: ${JSON.stringify(this.callContext.httpDetails,null,2)}`),t}},cr=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}`}},fr=class extends cr{static fromCode(t){return new this(t)}};var Z=class e extends fr{constructor(t){super(t,ar.Input),this.name="InputError",Object.setPrototypeOf(this,e.prototype)}};var Re=class e extends $t{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}`}},Ot=class e extends $t{constructor(t){super(),this.error=t,this.name="DerDecodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to decode DER: ${this.error}`}},oe=class e extends $t{constructor(t){super(),this.error=t,this.name="DerEncodeErrorCode",Object.setPrototypeOf(this,e.prototype)}toErrorMessage(){return`Failed to encode DER: ${this.error}`}};var Ce=class e extends $t{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}`}};var pi=new Error("unreachable");var De=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=it(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 it(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?it(e.buffer):new Uint8Array(e)}function ur(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 yn(e,t){return ur(e,t)===0}function wn(e){let t=BigInt(e);if(e<=0)throw new RangeError("Input must be positive");return t.toString(2).length-1}function dr(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:wn(e))+1,r=new De(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 lr(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?lr(e.buffer):new Uint8Array(e)}function En(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 hr(e){if(typeof e=="string")return _n(e);if(typeof e=="number")return St(dr(e));if(e instanceof Uint8Array||ArrayBuffer.isView(e))return St(lr(e));if(Array.isArray(e)){let t=e.map(hr);return St(Q(...t))}else{if(e&&typeof e=="object"&&e._isPrincipal)return St(e.toUint8Array());if(typeof e=="object"&&e!==null&&typeof e.toHash=="function")return hr(e.toHash());if(typeof e=="object")return In(e);if(typeof e=="bigint")return St(dr(e))}throw Z.fromCode(new Ce(e))}var _n=e=>{let t=new TextEncoder().encode(e);return St(t)};function se(e){return In(e)}function In(e){let n=Object.entries(e).filter(([,i])=>i!==void 0).map(([i,c])=>{let a=_n(i),u=hr(c);return[a,u]}).sort(([i],[c])=>ur(i,c)),o=Q(...n.map(i=>Q(...i)));return St(o)}var ie=new TextEncoder().encode(`
11
+ ic-request`),ko=new TextEncoder().encode("\vic-response"),pr=new TextEncoder().encode("ic-request-auth-delegation");var At=class{getPrincipal(){return this._principal||(this._principal=F.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(t){let{body:r,...n}=t,o=se(r);return{...n,body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(Q(ie,o))}}}},ae=class{getPrincipal(){return F.anonymous()}async transformRequest(t){return{...t,body:{content:t.body}}}};var mr=BigInt(0),gr=BigInt(1);function Pe(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function ce(e,t,r=""){let n=Ut(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function Tn(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?mr:BigInt("0x"+e)}function Sn(e){return Tn(L(e))}function Bt(e){return X(e),Tn(L(Uint8Array.from(e).reverse()))}function br(e,t){return Y(e.toString(16).padStart(t*2,"0"))}function On(e,t){return br(e,t).reverse()}function z(e,t,r){let n;if(typeof t=="string")try{n=Y(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ut(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 An(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 yr(e){return Uint8Array.from(e)}var xr=e=>typeof e=="bigint"&&mr<=e;function Vo(e,t,r){return xr(e)&&xr(t)&&xr(r)&&t<=e&&e<r}function wr(e,t,r,n){if(!Vo(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Bn(e){let t;for(t=0;e>mr;e>>=gr,t+=1);return t}var fe=e=>(gr<<BigInt(e))-gr;function ue(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Er=()=>{throw new Error("not implemented")};function _r(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var V=BigInt(0),K=BigInt(1),qt=BigInt(2),Cn=BigInt(3),Dn=BigInt(4),Pn=BigInt(5),Fo=BigInt(7),Ln=BigInt(8),$o=BigInt(9),Nn=BigInt(16);function N(e,t){let r=e%t;return r>=V?r:t+r}function rt(e,t,r){let n=e;for(;t-- >V;)n*=n,n%=r;return n}function vn(e,t){if(e===V)throw new Error("invert: expected non-zero number");if(t<=V)throw new Error("invert: expected positive modulus, got "+t);let r=N(e,t),n=t,o=V,s=K,i=K,c=V;for(;r!==V;){let u=n/r,l=n%r,d=o-i*u,f=s-c*u;n=r,r=l,o=i,s=c,i=d,c=f}if(n!==K)throw new Error("invert: does not exist");return N(o,t)}function Ir(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Un(e,t){let r=(e.ORDER+K)/Dn,n=e.pow(t,r);return Ir(e,n,t),n}function Go(e,t){let r=(e.ORDER-Pn)/Ln,n=e.mul(t,qt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,qt),o),c=e.mul(s,e.sub(i,e.ONE));return Ir(e,c,t),c}function Wo(e){let t=ht(e),r=Mn(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Fo)/Nn;return(c,a)=>{let u=c.pow(a,i),l=c.mul(u,n),d=c.mul(u,o),f=c.mul(u,s),x=c.eql(c.sqr(l),a),p=c.eql(c.sqr(d),a);u=c.cmov(u,l,x),l=c.cmov(f,d,p);let b=c.eql(c.sqr(l),a),E=c.cmov(u,l,b);return Ir(c,E,a),E}}function Mn(e){if(e<Cn)throw new Error("sqrt is not defined for small field");let t=e-K,r=0;for(;t%qt===V;)t/=qt,r++;let n=qt,o=ht(e);for(;Rn(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Un;let s=o.pow(n,t),i=(t+K)/qt;return function(a,u){if(a.is0(u))return u;if(Rn(a,u)!==1)throw new Error("Cannot find square root");let l=r,d=a.mul(a.ONE,s),f=a.pow(u,t),x=a.pow(u,i);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let p=1,b=a.sqr(f);for(;!a.eql(b,a.ONE);)if(p++,b=a.sqr(b),p===l)throw new Error("Cannot find square root");let E=K<<BigInt(l-p-1),h=a.pow(d,E);l=p,d=a.sqr(h),f=a.mul(f,d),x=a.mul(x,h)}return x}}function Yo(e){return e%Dn===Cn?Un:e%Ln===Pn?Go:e%Nn===$o?Wo(e):Mn(e)}var lt=(e,t)=>(N(e,t)&K)===K,Zo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function jn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Zo.reduce((n,o)=>(n[o]="function",n),t);return ue(e,r),e}function zo(e,t,r){if(r<V)throw new Error("invalid exponent, negatives unsupported");if(r===V)return e.ONE;if(r===K)return t;let n=e.ONE,o=t;for(;r>V;)r&K&&(n=e.mul(n,o)),o=e.sqr(o),r>>=K;return n}function Le(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Rn(e,t){let r=(e.ORDER-K)/qt,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Hn(e,t){t!==void 0&&Xe(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ht(e,t,r=!1,n={}){if(e<=V)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),c=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=Hn(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l,d=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:fe(a),ZERO:V,ONE:K,allowedLengths:c,create:f=>N(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return V<=f&&f<e},is0:f=>f===V,isValidNot0:f=>!d.is0(f)&&d.isValid(f),isOdd:f=>(f&K)===K,neg:f=>N(-f,e),eql:(f,x)=>f===x,sqr:f=>N(f*f,e),add:(f,x)=>N(f+x,e),sub:(f,x)=>N(f-x,e),mul:(f,x)=>N(f*x,e),pow:(f,x)=>zo(d,f,x),div:(f,x)=>N(f*vn(x,e),e),sqrN:f=>f*f,addN:(f,x)=>f+x,subN:(f,x)=>f-x,mulN:(f,x)=>f*x,inv:f=>vn(f,e),sqrt:s||(f=>(l||(l=Yo(e)),l(d,f))),toBytes:f=>r?On(f,u):br(f,u),fromBytes:(f,x=!0)=>{if(c){if(!c.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+f.length);let b=new Uint8Array(u);b.set(f,r?0:b.length-f.length),f=b}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let p=r?Bt(f):Sn(f);if(i&&(p=N(p,e)),!x&&!d.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:f=>Le(d,f),cmov:(f,x,p)=>p?x:f});return Object.freeze(d)}var Ne=BigInt(0),Ar=BigInt(1);function qn(e,t){let r=t.negate();return e?r:t}function de(e,t){let r=Le(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Fn(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Tr(e,t){Fn(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=fe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Kn(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=Ar);let u=t*n,l=u+Math.abs(c)-1,d=c===0,f=c<0,x=t%2!==0;return{nextN:a,offset:l,isZero:d,isNeg:f,isNegF:x,offsetF:u}}function Jo(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 Xo(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 Sr=new WeakMap,$n=new WeakMap;function Or(e){return $n.get(e)||1}function kn(e){if(e!==Ne)throw new Error("invalid wNAF")}var Ue=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>Ne;)r&Ar&&(n=n.add(o)),o=o.double(),r>>=Ar;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Tr(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Tr(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:l,isNeg:d,isNegF:f,offsetF:x}=Kn(n,c,i);n=a,l?s=s.add(qn(f,r[x])):o=o.add(qn(d,r[u]))}return kn(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Tr(t,this.bits);for(let i=0;i<s.windows&&n!==Ne;i++){let{nextN:c,offset:a,isZero:u,isNeg:l}=Kn(n,i,s);if(n=c,!u){let d=r[a];o=o.add(l?d.negate():d)}}return kn(n),o}getPrecomputes(t,r,n){let o=Sr.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Sr.set(r,o))),o}cached(t,r,n){let o=Or(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Or(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Fn(r,this.bits),$n.set(t,r),Sr.delete(t)}hasCache(t){return Or(t)!==1}};function Me(e,t,r,n){Jo(r,e),Xo(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Bn(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=fe(a),l=new Array(Number(u)+1).fill(i),d=Math.floor((t.BITS-1)/a)*a,f=i;for(let x=d;x>=0;x-=a){l.fill(i);for(let b=0;b<s;b++){let E=n[b],h=Number(E>>BigInt(x)&u);l[h]=l[h].add(r[b])}let p=i;for(let b=l.length-1,E=i;b>0;b--)E=E.add(l[b]),p=p.add(E);if(f=f.add(p),x!==0)for(let b=0;b<a;b++)f=f.double()}return f}function Vn(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return jn(t),t}else return ht(e,{isLE:r})}function Gn(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 a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Ne))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Vn(t.p,r.Fp,n),s=Vn(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var vt=BigInt(0),j=BigInt(1),Br=BigInt(2),Qo=BigInt(8);function ts(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function es(e,t={}){let r=Gn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ue(t,{},{uvRatio:"function"});let c=Br<<BigInt(o.BYTES*8)-j,a=E=>n.create(E),u=t.uvRatio||((E,h)=>{try{return{isValid:!0,value:n.sqrt(n.div(E,h))}}catch{return{isValid:!1,value:vt}}});if(!ts(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(E,h,w=!1){let g=w?j:vt;return wr("coordinate "+E,h,g,c),h}function d(E){if(!(E instanceof p))throw new Error("ExtendedPoint expected")}let f=_r((E,h)=>{let{X:w,Y:g,Z:I}=E,S=E.is0();h==null&&(h=S?Qo:n.inv(I));let D=a(w*h),P=a(g*h),T=n.mul(I,h);if(S)return{x:vt,y:j};if(T!==j)throw new Error("invZ was invalid");return{x:D,y:P}}),x=_r(E=>{let{a:h,d:w}=s;if(E.is0())throw new Error("bad point: ZERO");let{X:g,Y:I,Z:S,T:D}=E,P=a(g*g),T=a(I*I),m=a(S*S),y=a(m*m),_=a(P*h),O=a(m*a(_+T)),B=a(y+a(w*a(P*T)));if(O!==B)throw new Error("bad point: equation left != right (1)");let A=a(g*I),M=a(S*D);if(A!==M)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(h,w,g,I){this.X=l("x",h),this.Y=l("y",w),this.Z=l("z",g,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){if(h instanceof p)throw new Error("extended point not allowed");let{x:w,y:g}=h||{};return l("x",w),l("y",g),new p(w,g,j,a(w*g))}static fromBytes(h,w=!1){let g=n.BYTES,{a:I,d:S}=s;h=yr(ce(h,g,"point")),Pe(w,"zip215");let D=yr(h),P=h[g-1];D[g-1]=P&-129;let T=Bt(D),m=w?c:n.ORDER;wr("point.y",T,vt,m);let y=a(T*T),_=a(y-j),O=a(S*y-I),{isValid:B,value:A}=u(_,O);if(!B)throw new Error("bad point: invalid y coordinate");let M=(A&j)===j,W=(P&128)!==0;if(!w&&A===vt&&W)throw new Error("bad point: x=0 and x_0=1");return W!==M&&(A=a(-A)),p.fromAffine({x:A,y:T})}static fromHex(h,w=!1){return p.fromBytes(z("point",h),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,w=!0){return b.createCache(this,h),w||this.multiply(Br),this}assertValidity(){x(this)}equals(h){d(h);let{X:w,Y:g,Z:I}=this,{X:S,Y:D,Z:P}=h,T=a(w*P),m=a(S*I),y=a(g*P),_=a(D*I);return T===m&&y===_}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:h}=s,{X:w,Y:g,Z:I}=this,S=a(w*w),D=a(g*g),P=a(Br*a(I*I)),T=a(h*S),m=w+g,y=a(a(m*m)-S-D),_=T+D,O=_-P,B=T-D,A=a(y*O),M=a(_*B),W=a(y*B),Et=a(O*_);return new p(A,M,Et,W)}add(h){d(h);let{a:w,d:g}=s,{X:I,Y:S,Z:D,T:P}=this,{X:T,Y:m,Z:y,T:_}=h,O=a(I*T),B=a(S*m),A=a(P*g*_),M=a(D*y),W=a((I+S)*(T+m)-O-B),Et=M-A,Lt=M+A,ct=a(B-w*O),te=a(W*Et),_e=a(Lt*ct),Je=a(W*ct),Jr=a(Et*Lt);return new p(te,_e,Jr,Je)}subtract(h){return this.add(h.negate())}multiply(h){if(!o.isValidNot0(h))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:w,f:g}=b.cached(this,h,I=>de(p,I));return de(p,[w,g])[0]}multiplyUnsafe(h,w=p.ZERO){if(!o.isValid(h))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return h===vt?p.ZERO:this.is0()||h===j?this:b.unsafe(this,h,g=>de(p,g),w)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return b.unsafe(this,s.n).is0()}toAffine(h){return f(this,h)}clearCofactor(){return i===j?this:this.multiplyUnsafe(i)}toBytes(){let{x:h,y:w}=this.toAffine(),g=n.toBytes(w);return g[g.length-1]|=h&j?128:0,g}toHex(){return L(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(h){return de(p,h)}static msm(h,w){return Me(p,o,h,w)}_setWindowSize(h){this.precompute(h)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,j,a(s.Gx*s.Gy)),p.ZERO=new p(vt,j,j,vt),p.Fp=n,p.Fn=o;let b=new Ue(p,o.BITS);return p.BASE.precompute(8),p}var je=class{constructor(t){this.ep=t}static fromBytes(t){Er()}static fromHex(t){Er()}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 L(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 rs(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ue(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||rr,a=r.adjustScalarBytes||(m=>m),u=r.domain||((m,y,_)=>{if(Pe(_,"phflag"),y.length||_)throw new Error("Contexts/pre-hash are not supported");return m});function l(m){return i.create(Bt(m))}function d(m){let y=g.secretKey;m=z("private key",m,y);let _=z("hashed private key",t(m),2*y),O=a(_.slice(0,y)),B=_.slice(y,2*y),A=l(O);return{head:O,prefix:B,scalar:A}}function f(m){let{head:y,prefix:_,scalar:O}=d(m),B=o.multiply(O),A=B.toBytes();return{head:y,prefix:_,scalar:O,point:B,pointBytes:A}}function x(m){return f(m).pointBytes}function p(m=Uint8Array.of(),...y){let _=Q(...y);return l(t(u(_,z("context",m),!!n)))}function b(m,y,_={}){m=z("message",m),n&&(m=n(m));let{prefix:O,scalar:B,pointBytes:A}=f(y),M=p(_.context,O,m),W=o.multiply(M).toBytes(),Et=p(_.context,W,A,m),Lt=i.create(M+Et*B);if(!i.isValid(Lt))throw new Error("sign failed: invalid s");let ct=Q(W,i.toBytes(Lt));return ce(ct,g.signature,"result")}let E={zip215:!0};function h(m,y,_,O=E){let{context:B,zip215:A}=O,M=g.signature;m=z("signature",m,M),y=z("message",y),_=z("publicKey",_,g.publicKey),A!==void 0&&Pe(A,"zip215"),n&&(y=n(y));let W=M/2,Et=m.subarray(0,W),Lt=Bt(m.subarray(W,M)),ct,te,_e;try{ct=e.fromBytes(_,A),te=e.fromBytes(Et,A),_e=o.multiplyUnsafe(Lt)}catch{return!1}if(!A&&ct.isSmallOrder())return!1;let Je=p(B,te.toBytes(),ct.toBytes(),y);return te.add(ct.multiplyUnsafe(Je)).subtract(_e).clearCofactor().is0()}let w=s.BYTES,g={secretKey:w,publicKey:w,signature:2*w,seed:w};function I(m=c(g.seed)){return ce(m,g.seed,"seed")}function S(m){let y=T.randomSecretKey(m);return{secretKey:y,publicKey:x(y)}}function D(m){return Ut(m)&&m.length===i.BYTES}function P(m,y){try{return!!e.fromBytes(m,y)}catch{return!1}}let T={getExtendedPublicKey:f,randomSecretKey:I,isValidSecretKey:D,isValidPublicKey:P,toMontgomery(m){let{y}=e.fromBytes(m),_=g.publicKey,O=_===32;if(!O&&_!==57)throw new Error("only defined for 25519 and 448");let B=O?s.div(j+y,j-y):s.div(y-j,y+j);return s.toBytes(B)},toMontgomerySecret(m){let y=g.secretKey;ce(m,y);let _=t(m.subarray(0,y));return a(_).subarray(0,y)},randomPrivateKey:I,precompute(m=8,y=e.BASE){return y.precompute(m,!1)}};return Object.freeze({keygen:S,getPublicKey:x,sign:b,verify:h,utils:T,Point:e,lengths:g})}function ns(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=ht(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function os(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Wn(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=ns(e),s=es(t,r),i=rs(s,n,o);return os(e,i)}var ss=BigInt(0),pt=BigInt(1),Yn=BigInt(2),ea=BigInt(3),is=BigInt(5),as=BigInt(8),Gt=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),le={p:Gt,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:as,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function cs(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Gt,c=e*e%s*e%s,a=rt(c,Yn,s)*c%s,u=rt(a,pt,s)*e%s,l=rt(u,is,s)*u%s,d=rt(l,t,s)*l%s,f=rt(d,r,s)*d%s,x=rt(f,n,s)*f%s,p=rt(x,o,s)*x%s,b=rt(p,o,s)*x%s,E=rt(b,t,s)*l%s;return{pow_p_5_8:rt(E,Yn,s)*e%s,b2:c}}function fs(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var vr=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Dr(e,t){let r=Gt,n=N(t*t*t,r),o=N(n*n*t,r),s=cs(e*o).pow_p_5_8,i=N(e*n*s,r),c=N(t*i*i,r),a=i,u=N(i*vr,r),l=c===e,d=c===N(-e,r),f=c===N(-e*vr,r);return l&&(i=a),(d||f)&&(i=u),lt(i,r)&&(i=N(-i,r)),{isValid:l||d,value:i}}var Rt=ht(le.p,{isLE:!0}),us=ht(le.n,{isLE:!0}),ds={...le,Fp:Rt,hash:mn,adjustScalarBytes:fs,uvRatio:Dr},J=Wn(ds);var Rr=vr,ls=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),hs=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ps=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),xs=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Zn=e=>Dr(pt,e),gs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Cr=e=>J.Point.Fp.create(Bt(e)&gs);function zn(e){let{d:t}=le,r=Gt,n=h=>Rt.create(h),o=n(Rr*e*e),s=n((o+pt)*ps),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=Dr(s,c),l=n(u*e);lt(l,r)||(l=n(-l)),a||(u=l),a||(i=o);let d=n(i*(o-pt)*xs-c),f=u*u,x=n((u+u)*c),p=n(d*ls),b=n(pt-f),E=n(pt+f);return new J.Point(n(x*E),n(b*p),n(p*E),n(x*b))}function ms(e){X(e,64);let t=Cr(e.subarray(0,32)),r=zn(t),n=Cr(e.subarray(32,64)),o=zn(n);return new xt(r.add(o))}var xt=class e extends je{constructor(t){super(t)}static fromAffine(t){return new e(J.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return ms(z("ristrettoHash",t,64))}static fromBytes(t){X(t,32);let{a:r,d:n}=le,o=Gt,s=I=>Rt.create(I),i=Cr(t);if(!An(Rt.toBytes(i),t)||lt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(pt+r*c),u=s(pt-r*c),l=s(a*a),d=s(u*u),f=s(r*n*l-d),{isValid:x,value:p}=Zn(s(f*d)),b=s(p*u),E=s(p*b*f),h=s((i+i)*b);lt(h,o)&&(h=s(-h));let w=s(a*E),g=s(h*w);if(!x||lt(g,o)||w===ss)throw new Error("invalid ristretto255 encoding 2");return new e(new J.Point(h,w,pt,g))}static fromHex(t){return e.fromBytes(z("ristrettoHex",t,32))}static msm(t,r){return Me(e,J.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Gt,i=E=>Rt.create(E),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:l}=Zn(i(c*u)),d=i(l*c),f=i(l*a),x=i(d*f*o),p;if(lt(o*x,s)){let E=i(r*Rr),h=i(t*Rr);t=E,r=h,p=i(d*hs)}else p=f;lt(t*x,s)&&(r=i(-r));let b=i((n-r)*p);return lt(b,s)&&(b=i(-b)),Rt.toBytes(b)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>Rt.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};xt.BASE=new xt(J.Point.BASE);xt.ZERO=new xt(J.Point.ZERO);xt.Fp=Rt;xt.Fn=us;var Jn=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 oe("Length too long (> 4 bytes)"))},Xn=(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 oe("Length too long (> 4 bytes)"))},Pr=(e,t)=>{if(e[t]<128)return 1;if(e[t]===128)throw Z.fromCode(new Ot("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 Ot("Length too long (> 4 bytes)"))},bs=(e,t)=>{let r=Pr(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 Ot("Length too long (> 4 bytes)"))},sa=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),Lr=Uint8Array.from([48,5,6,3,43,101,112]),ia=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]),aa=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 Qn(e,t){let r=2+Jn(e.byteLength+1),n=t.byteLength+r+e.byteLength,o=0,s=new Uint8Array(1+Jn(n)+n);return s[o++]=48,o+=Xn(s,o,n),s.set(t,o),o+=t.byteLength,s[o++]=3,o+=Xn(s,o,e.byteLength+1),s[o++]=0,s.set(new Uint8Array(e),o),s}var to=(e,t)=>{let r=0,n=(c,a)=>{if(o[r++]!==c)throw Z.fromCode(new Ot(`Expected ${a} at offset ${r}`))},o=new Uint8Array(e);if(n(48,"sequence"),r+=Pr(o,r),!En(o.slice(r,r+t.byteLength),t))throw Z.fromCode(new Ot("Not the expected OID."));r+=t.byteLength,n(3,"bit string");let s=bs(o,r)-1;r+=Pr(o,r),n(0,"0 padding");let i=o.slice(r);if(s!==i.length)throw Z.fromCode(new Re(s,i.length));return i};function eo(e){return e!==null&&typeof e=="object"}var he=class e{static from(t){if(typeof t=="string"){let r=Y(t);return this.fromRaw(r)}else if(eo(t)){let r=t;if(eo(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(it(n.buffer))}else{if(r instanceof ArrayBuffer)return this.fromRaw(it(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=Qn(t,Lr);return r.__derEncodedPublicKey__=void 0,r}static derDecode(t){let r=to(t,Lr);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}#t;get rawKey(){return this.#t}#e;get derKey(){return this.#e}constructor(t){if(t.byteLength!==e.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");this.#t=t,this.#e=e.derEncode(t)}toDer(){return this.derKey}toRaw(){return this.rawKey}},Kt=class e extends At{static generate(t){if(t&&t.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");t||(t=J.utils.randomPrivateKey()),yn(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=J.getPublicKey(r);return e.fromKeyPair(n,r)}static fromParsedJson(t){let[r,n]=t;return new e(he.fromDer(Y(r)),Y(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(he.fromRaw(t),r)}static fromSecretKey(t){let r=J.getPublicKey(t);return e.fromKeyPair(r,t)}#t;#e;constructor(t,r){super(),this.#t=he.from(t),this.#e=r}toJSON(){return[L(this.#t.toDer()),L(this.#e)]}getKeyPair(){return{secretKey:this.#e,publicKey:this.#t}}getPublicKey(){return this.#t}async sign(t){let r=J.sign(t,this.#e.slice(0,32));return Object.defineProperty(r,"__signature__",{enumerable:!1,value:void 0}),r}static verify(t,r,n){let[o,s,i]=[t,r,n].map(c=>(typeof c=="string"&&(c=Y(c)),it(c)));return J.verify(o,s,i)}};var Nr=class e extends Error{constructor(t){super(t),this.message=t,Object.setPrototypeOf(this,e.prototype)}};function ro(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 Nr("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 Wt=class e extends At{static async generate(t){let{extractable:r=!1,keyUsages:n=["sign","verify"],subtleCrypto:o}=t??{},s=ro(o),i=await s.generateKey({name:"ECDSA",namedCurve:"P-256"},r,n),c=it(await s.exportKey("spki",i.publicKey));return Object.assign(c,{__derEncodedPublicKey__:void 0}),new this(i,c,s)}static async fromKeyPair(t,r){let n=ro(r),o=it(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=it(await this._subtleCrypto.sign(r,this._keyPair.privateKey,t));return Object.assign(n,{__signature__:void 0}),n}};var He=class{#t;get rawKey(){return this.#t.rawKey}get derKey(){return this.#t.derKey}toDer(){return this.#t.toDer()}getPublicKey(){return this.#t}getPrincipal(){if(!this.#t.rawKey)throw new Error("Cannot get principal from a public key without a raw key.");return F.fromUint8Array(new Uint8Array(this.#t.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.#t=t}};function qe(e){return e instanceof Uint8Array?L(e):L(new Uint8Array(e))}function Ur(e){if(typeof e!="string"||e.length<64)throw new Error("Invalid public key.");return Y(e)}var Ct=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:qe(this.pubkey),...this.targets&&{targets:this.targets.map(t=>t.toHex())}}}};async function ys(e,t,r,n){let o=new Ct(t.toDer(),BigInt(+r)*BigInt(1e6),n),s=new Uint8Array([...pr,...new Uint8Array(se({...o}))]),i=await e.sign(s);return{delegation:o,signature:i}}var gt=class e{static async create(t,r,n=new Date(Date.now()+900*1e3),o={}){let s=await ys(t,r,n,o.targets);return new e([...o.previous?.delegations||[],s],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(s=>{let{delegation:i,signature:c}=s,{pubkey:a,expiration:u,targets:l}=i;if(l!==void 0&&!Array.isArray(l))throw new Error("Invalid targets.");return{delegation:new Ct(Ur(a),BigInt("0x"+u),l&&l.map(d=>{if(typeof d!="string")throw new Error("Invalid target.");return F.fromHex(d)})),signature:Ur(c)}});return new this(o,Ur(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:qe(r.pubkey),...o&&{targets:o.map(s=>s.toHex())}},signature:qe(n)}}),publicKey:qe(this.publicKey)}}},Yt=class extends At{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 se(r);return{...n,body:{content:r,sender_sig:await this.sign(new Uint8Array([...ie,...new Uint8Array(o)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}}}},Zt=class e extends He{#t;get delegation(){return this.#t}constructor(t,r){super(t),this.#t=r}static fromDelegation(t,r){return new e(t,r)}};function pe(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"?F.fromText(o):o)):r.push(typeof n=="string"?F.fromText(n):n));for(let o of r){let s=o.toText();for(let{delegation:i}of e.delegations){if(i.targets===void 0)continue;let c=!0;for(let a of i.targets)if(a.toText()===s){c=!1;break}if(c)return!1}}return!0}var mt=e=>{if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(e,"base64");if(typeof globalThis.atob<"u")return Uint8Array.from(globalThis.atob(e),t=>t.charCodeAt(0));throw Error("Could not decode base64 string")},zt=e=>{if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(e).toString("base64");if(typeof globalThis.btoa<"u")return btoa(Array.from({length:Math.ceil(e.byteLength/1e5)}).map((t,r)=>String.fromCharCode(...new Uint8Array(e.slice(r*1e5,(r+1)*1e5)))).join(""));throw Error("Could not encode base64 string")};var Jt=function(e,t,r,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(e,r):o?o.value=r:t.set(e,r),r},C=function(e,t,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(e):n?n.value:t.get(e)},k,bt,Xt,Ke,Vt=class e extends Error{constructor(t){super(t.message),Object.setPrototypeOf(this,e.prototype),this.code=t.code,this.data=t.data}},no=e=>new Vt({code:4e3,message:e instanceof Error?e.message:"Network error"}),kt=e=>{if("error"in e)throw new Vt(e.error);if("result"in e)return e.result;throw new Vt({code:4e3,message:"Invalid response"})},Ve=class{constructor(t){k.set(this,void 0),bt.set(this,void 0),Xt.set(this,void 0),Ke.set(this,void 0),Jt(this,k,Object.assign({autoCloseTransportChannel:!0,closeTransportChannelAfter:200,crypto:globalThis.crypto},t),"f")}get transport(){return C(this,k,"f").transport}async openChannel(){if(clearTimeout(C(this,Ke,"f")),C(this,Xt,"f")&&await C(this,Xt,"f"),C(this,bt,"f")&&!C(this,bt,"f").closed)return C(this,bt,"f");let t=C(this,k,"f").transport.establishChannel();return Jt(this,Xt,t.then(()=>{}).catch(()=>{}),"f"),Jt(this,bt,void 0,"f"),Jt(this,bt,await t.catch(r=>{throw no(r)}),"f"),Jt(this,Xt,void 0,"f"),C(this,bt,"f")}async closeChannel(){var t;await((t=C(this,bt,"f"))===null||t===void 0?void 0:t.close())}async transformRequest(t){return C(this,k,"f").derivationOrigin?Object.assign(Object.assign({},t),{params:Object.assign(Object.assign({},t.params),{icrc95DerivationOrigin:C(this,k,"f").derivationOrigin})}):t}async sendRequest(t){let r=await this.openChannel();return new Promise(async(n,o)=>{let s=r.addEventListener("response",async c=>{c.id===t.id&&(s(),i(),n(c),C(this,k,"f").autoCloseTransportChannel&&Jt(this,Ke,setTimeout(()=>{r.closed||r.close()},C(this,k,"f").closeTransportChannelAfter),"f"))}),i=r.addEventListener("close",()=>{s(),i(),o(new Vt({code:4e3,message:"Channel was closed before a response was received"}))});try{await r.send(await this.transformRequest(t))}catch(c){s(),i(),o(no(c))}})}async supportedStandards(){let t=await this.sendRequest({id:C(this,k,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc25_supported_standards"});return kt(t).supportedStandards}async requestPermissions(t){let r=await this.sendRequest({id:C(this,k,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc25_request_permissions",params:{scopes:t}});return kt(r).scopes}async permissions(){let t=await this.sendRequest({id:C(this,k,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc25_permissions"});return kt(t).scopes}async accounts(){let t=await this.sendRequest({id:C(this,k,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc27_accounts"});return kt(t).accounts.map(({owner:n,subaccount:o})=>({owner:F.fromText(n),subaccount:o===void 0?void 0:mt(o)}))}async delegation(t){var r;let n=await this.sendRequest({id:C(this,k,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc34_delegation",params:{publicKey:zt(t.publicKey),targets:(r=t.targets)===null||r===void 0?void 0:r.map(s=>s.toText()),maxTimeToLive:t.maxTimeToLive===void 0?void 0:String(t.maxTimeToLive)}}),o=kt(n);return gt.fromDelegations(o.signerDelegation.map(s=>{var i;return{delegation:new Ct(mt(s.delegation.pubkey),BigInt(s.delegation.expiration),(i=s.delegation.targets)===null||i===void 0?void 0:i.map(c=>F.fromText(c))),signature:mt(s.signature)}}),mt(o.publicKey))}async callCanister(t){let r=await this.sendRequest({id:C(this,k,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc49_call_canister",params:{canisterId:t.canisterId.toText(),sender:t.sender.toText(),method:t.method,arg:zt(t.arg),nonce:t.nonce?zt(t.nonce):void 0}}),n=kt(r),o=mt(n.contentMap),s=mt(n.certificate);return{contentMap:o,certificate:s}}async batchCallCanister(t){var r;let n=await this.sendRequest({id:C(this,k,"f").crypto.randomUUID(),jsonrpc:"2.0",method:"icrc112_batch_call_canister",params:{sender:t.sender.toText(),validationCanisterId:(r=t.validationCanisterId)===null||r===void 0?void 0:r.toText(),requests:t.requests.map(s=>s.map(i=>({canisterId:i.canisterId.toText(),method:i.method,arg:zt(i.arg),nonce:i.nonce?zt(i.nonce):void 0})))}}),o=kt(n);if(t.requests.length!==o.responses.length||t.requests.some((s,i)=>s.length!==o.responses[i].length))throw new Vt({code:4e3,message:"Invalid batch call canister response, structure does not match request structure"});return o.responses.map(s=>s.map(i=>({result:{contentMap:mt(i.contentMap),certificate:mt(i.certificate)}})))}};k=new WeakMap,bt=new WeakMap,Xt=new WeakMap,Ke=new WeakMap;var oo=e=>typeof e=="object"&&!!e&&"jsonrpc"in e&&e.jsonrpc==="2.0",so=e=>oo(e)&&"method"in e&&typeof e.method=="string",Fe=e=>oo(e)&&"id"in e&&(typeof e.id=="string"||typeof e.id=="number");var Mr=function(e,t,r,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(e,r):o?o.value=r:t.set(e,r),r},v=function(e,t,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(e):n?n.value:t.get(e)},xe,H,Qt,ge,$e=class{constructor(t){xe.set(this,new Set),H.set(this,void 0),Qt.set(this,!1),ge.set(this,[]),Mr(this,H,Object.assign({signerStatus:"ready",window:globalThis.window,manageFocus:!0},t),"f")}get closed(){return v(this,Qt,"f")}addEventListener(...[t,r]){switch(t){case"close":return v(this,xe,"f").add(r),()=>{v(this,xe,"f").delete(r)};case"response":let n=async o=>{o.source!==v(this,H,"f").signerWindow||o.origin!==v(this,H,"f").signerOrigin||!Fe(o.data)||r(o.data)};return v(this,H,"f").window.addEventListener("message",n),()=>{v(this,H,"f").window.removeEventListener("message",n)}}}async send(t){if(v(this,Qt,"f"))throw new yt("Communication channel is closed");if(v(this,H,"f").signerStatus==="pending"){v(this,ge,"f").push(t);return}v(this,H,"f").signerWindow.postMessage(t,v(this,H,"f").signerOrigin),v(this,H,"f").manageFocus&&v(this,H,"f").signerWindow.focus()}async close(){v(this,Qt,"f")||(Mr(this,Qt,!0,"f"),v(this,H,"f").signerWindow.close(),v(this,H,"f").manageFocus&&v(this,H,"f").window.focus(),v(this,xe,"f").forEach(t=>t()))}changeStatus(t){if(v(this,H,"f").signerStatus=t,t==="ready"){let r=v(this,ge,"f");Mr(this,ge,[],"f"),r.forEach((n,o)=>{v(this,H,"f").signerWindow.postMessage(n,v(this,H,"f").signerOrigin)})}}};xe=new WeakMap,H=new WeakMap,Qt=new WeakMap,ge=new WeakMap;var io=e=>{try{let t=new URL(e);return t.protocol==="https:"||t.hostname==="127.0.0.1"||t.hostname.split(".").slice(-1)[0]==="localhost"}catch{return!1}};var qr=function(e,t,r,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(e,r):o?o.value=r:t.set(e,r),r},R=function(e,t,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(e):n?n.value:t.get(e)},Dt,U,me,co,ao,jr,Hr,Ge=class{constructor(t){Dt.add(this),U.set(this,void 0),me.set(this,void 0),qr(this,U,Object.assign({establishTimeout:1e4,pendingTimeout:3e5,disconnectTimeout:2e3,statusPollingRate:300,window:globalThis.window,crypto:globalThis.crypto},t),"f"),R(this,Dt,"m",co).call(this)}};U=new WeakMap,me=new WeakMap,Dt=new WeakSet,co=function(){let t=[],r=()=>{let i=R(this,U,"f").crypto.randomUUID();return t.push(i),i},n=R(this,Dt,"m",jr).call(this,i=>{"result"in i.data&&t.includes(i.data.id)&&(t=[],n(),clearInterval(s),clearTimeout(o),qr(this,me,i.data.result,"f"),R(this,U,"f").onEstablish(i.origin,i.data.result),R(this,Dt,"m",ao).call(this,i.origin,i.data.result))}),o=setTimeout(()=>{n(),clearInterval(s),R(this,U,"f").onEstablishTimeout()},R(this,U,"f").establishTimeout),s=setInterval(()=>R(this,Dt,"m",Hr).call(this,r()),R(this,U,"f").statusPollingRate)},ao=function(t,r){let n,o,s=[],i=l=>{let d=s.findIndex(f=>f.id===l);return d>-1&&s.splice(d,1),d>-1},c=()=>{let l=R(this,U,"f").crypto.randomUUID(),d=new Date().getTime();return s=s.filter(f=>d-R(this,U,"f").disconnectTimeout>f.time),s.push({id:l,time:d}),l},a=l=>{clearTimeout(o),o=setTimeout(()=>{u(),clearInterval(n),R(this,U,"f").onDisconnect()},l==="pending"?R(this,U,"f").pendingTimeout:R(this,U,"f").disconnectTimeout)},u=R(this,Dt,"m",jr).call(this,l=>{"result"in l.data&&l.origin===t&&i(l.data.id)&&(a(l.data.result),R(this,me,"f")!==l.data.result&&(qr(this,me,l.data.result,"f"),R(this,U,"f").onStatusChange(l.data.result)))});a(r),n=setInterval(()=>R(this,Dt,"m",Hr).call(this,c()),R(this,U,"f").statusPollingRate)},jr=function(t){let r=n=>{(n.source===R(this,U,"f").signerWindow&&Fe(n.data)&&"result"in n.data&&n.data.result==="pending"||n.data.result==="ready")&&t(n)};return R(this,U,"f").window.addEventListener("message",r),()=>R(this,U,"f").window.removeEventListener("message",r)},Hr=function(t){R(this,U,"f").signerWindow.postMessage({jsonrpc:"2.0",id:t,method:"icrc29_status"},"*")};var $=function(e,t,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(e):n?n.value:t.get(e)},be,nt,ws,fo,Kr,uo;nt=new WeakMap,be=new WeakSet,ws=function(){let t=$(this,be,"m",Kr).call(this,n=>{n.source&&(t(),clearTimeout(r),$(this,nt,"f").onEstablish(n.origin,n.source),$(this,be,"m",fo).call(this,n.origin,n.source))}),r=setTimeout(()=>{t(),$(this,nt,"f").onEstablishTimeout()},$(this,nt,"f").establishTimeout)},fo=function(t,r){let n,o=()=>{clearTimeout(n),n=setTimeout(()=>{s(),$(this,nt,"f").onDisconnect()},$(this,nt,"f").disconnectTimeout)};o();let s=$(this,be,"m",Kr).call(this,i=>{i.origin===t&&i.source===r&&i.data.id!==void 0&&(o(),$(this,be,"m",uo).call(this,i.data.id,i.origin,i.source))})},Kr=function(t){let r=n=>{so(n.data)&&n.data.method==="icrc29_status"&&(!$(this,nt,"f").allowedOrigin||$(this,nt,"f").allowedOrigin===n.origin)&&t(n)};return $(this,nt,"f").window.addEventListener("message",r),()=>$(this,nt,"f").window.removeEventListener("message",r)},uo=function(t,r,n){n.postMessage({jsonrpc:"2.0",id:t,result:$(this,nt,"f").status},r)};var Es=function(e,t,r,n,o){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?o.call(e,r):o?o.value=r:t.set(e,r),r},wt=function(e,t,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(e):n?n.value:t.get(e)},tt,_s="https://github.com/slide-computer/signer-js/blob/main/packages/signer-web/README.md#channels-must-be-established-in-a-click-handler",yt=class e extends Error{constructor(t){super(t),Object.setPrototypeOf(this,e.prototype)}},kr=!1;globalThis.window&&(globalThis.window.addEventListener("click",()=>kr=!0,!0),globalThis.window.addEventListener("click",()=>kr=!1));var We=class{constructor(t){if(tt.set(this,void 0),!io(t.url))throw new yt("Invalid signer RPC url");Es(this,tt,Object.assign({windowOpenerFeatures:"",window:globalThis.window,establishTimeout:12e4,pendingTimeout:3e5,disconnectTimeout:2e3,statusPollingRate:300,crypto:globalThis.crypto,manageFocus:!0,closeOnEstablishTimeout:!0,closeOnPendingTimeout:!0,detectNonClickEstablishment:!0},t),"f")}async establishChannel(){if(wt(this,tt,"f").detectNonClickEstablishment&&!kr)throw new yt(`Signer window should not be opened outside of click handler, see: ${_s}`);let t=wt(this,tt,"f").window.open(wt(this,tt,"f").url,`${new URL(wt(this,tt,"f").url).origin}-signer-window`,wt(this,tt,"f").windowOpenerFeatures);if(!t)throw new yt("Signer window could not be opened");return new Promise((r,n)=>{let o;new Ge(Object.assign(Object.assign({},wt(this,tt,"f")),{signerWindow:t,onEstablish:(s,i)=>{o=new $e(Object.assign(Object.assign({},wt(this,tt,"f")),{signerOrigin:s,signerWindow:t,signerStatus:i})),r(o)},onEstablishTimeout:()=>{wt(this,tt,"f").closeOnEstablishTimeout&&t.close(),n(new yt("Communication channel could not be established within a reasonable time"))},onPendingTimeout:()=>{wt(this,tt,"f").closeOnPendingTimeout&&t.close(),n(new yt("Communication channel was pending for too long"))},onDisconnect:()=>o.close(),onStatusChange:s=>o.changeStatus(s)}))})}};tt=new WeakMap;var lo=["mousedown","mousemove","keydown","touchstart","wheel"],ye=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),lo.forEach(i=>{document.addEventListener(i,o,!0)});let s=(i,c)=>{let a;return(...u)=>{let l=this,d=()=>{a=void 0,i.apply(l,u)};clearTimeout(a),a=window.setTimeout(d,c)}};if(t?.captureScroll){let i=s(o,t?.scrollDebounce??100);window.addEventListener("scroll",i,!0)}o()}registerCallback(t){this.callbacks.push(t)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let t=this._resetTimer.bind(this);lo.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 Is=(e,t)=>t.some(r=>e instanceof r),ho,po;function Ts(){return ho||(ho=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Ss(){return po||(po=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var xo=new WeakMap,Fr=new WeakMap,go=new WeakMap,Vr=new WeakMap,Gr=new WeakMap;function Os(e){let t=new Promise((r,n)=>{let o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{r(at(e.result)),o()},i=()=>{n(e.error),o()};e.addEventListener("success",s),e.addEventListener("error",i)});return t.then(r=>{r instanceof IDBCursor&&xo.set(r,e)}).catch(()=>{}),Gr.set(t,e),t}function As(e){if(Fr.has(e))return;let t=new Promise((r,n)=>{let o=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",i),e.removeEventListener("abort",i)},s=()=>{r(),o()},i=()=>{n(e.error||new DOMException("AbortError","AbortError")),o()};e.addEventListener("complete",s),e.addEventListener("error",i),e.addEventListener("abort",i)});Fr.set(e,t)}var $r={get(e,t,r){if(e instanceof IDBTransaction){if(t==="done")return Fr.get(e);if(t==="objectStoreNames")return e.objectStoreNames||go.get(e);if(t==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return at(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 mo(e){$r=e($r)}function Bs(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(t,...r){let n=e.call(Ye(this),t,...r);return go.set(n,t.sort?t.sort():[t]),at(n)}:Ss().includes(e)?function(...t){return e.apply(Ye(this),t),at(xo.get(this))}:function(...t){return at(e.apply(Ye(this),t))}}function vs(e){return typeof e=="function"?Bs(e):(e instanceof IDBTransaction&&As(e),Is(e,Ts())?new Proxy(e,$r):e)}function at(e){if(e instanceof IDBRequest)return Os(e);if(Vr.has(e))return Vr.get(e);let t=vs(e);return t!==e&&(Vr.set(e,t),Gr.set(t,e)),t}var Ye=e=>Gr.get(e);function yo(e,t,{blocked:r,upgrade:n,blocking:o,terminated:s}={}){let i=indexedDB.open(e,t),c=at(i);return n&&i.addEventListener("upgradeneeded",a=>{n(at(i.result),a.oldVersion,a.newVersion,at(i.transaction),a)}),r&&i.addEventListener("blocked",a=>r(a.oldVersion,a.newVersion,a)),c.then(a=>{s&&a.addEventListener("close",()=>s()),o&&a.addEventListener("versionchange",u=>o(u.oldVersion,u.newVersion,u))}).catch(()=>{}),c}var Rs=["get","getKey","getAll","getAllKeys","count"],Cs=["put","add","delete","clear"],Wr=new Map;function bo(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(Wr.get(t))return Wr.get(t);let r=t.replace(/FromIndex$/,""),n=t!==r,o=Cs.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(o||Rs.includes(r)))return;let s=async function(i,...c){let a=this.transaction(i,o?"readwrite":"readonly"),u=a.store;return n&&(u=u.index(c.shift())),(await Promise.all([u[r](...c),o&&a.done]))[0]};return Wr.set(t,s),s}mo(e=>({...e,get:(t,r,n)=>bo(t,r)||e.get(t,r,n),has:(t,r)=>!!bo(t,r)||e.has(t,r)}));var wo="auth-client-db",Eo="ic-keyval",Ds=async(e=wo,t=Eo,r)=>(globalThis.localStorage?.getItem(G)&&(globalThis.localStorage.removeItem(G),globalThis.localStorage.removeItem(ot)),await yo(e,r,{upgrade:n=>{n.objectStoreNames.contains(t)&&n.clear(t),n.createObjectStore(t)}}));async function Ps(e,t,r){return await e.get(t,r)}async function Ls(e,t,r,n){return await e.put(t,n,r)}async function Ns(e,t,r){return await e.delete(t,r)}var Ze=class e{constructor(t,r){this._db=t,this._storeName=r}static async create(t){let{dbName:r=wo,storeName:n=Eo,version:o=_o}=t??{},s=await Ds(r,n,o);return new e(s,n)}async set(t,r){return await Ls(this._db,this._storeName,t,r)}async get(t){return await Ps(this._db,this._storeName,t)??null}async remove(t){return await Ns(this._db,this._storeName,t)}};var ot="identity",G="delegation",Io="iv",_o=1,we=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}},Pt=class{#t;constructor(t){this.#t=t??{}}initializedDb;get _db(){return new Promise((t,r)=>{if(this.initializedDb){t(this.initializedDb);return}Ze.create(this.#t).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 Us=BigInt(1e9),Ms=BigInt(3600),js=Us*Ms,Hs="https://identity.internetcomputer.org",qs="#authorize",Ks="https://id.ai/authorize",To=BigInt(8)*js,Yr="ECDSA",Zr="Ed25519",ks=500,Ao="UserInterrupt",Ee=class e{constructor(t,r,n,o,s,i,c,a){this._identity=t,this._key=r,this._chain=n,this._storage=o,this.idleManager=s,this._createOptions=i,this._idpWindow=c,this._eventHandler=a,this._registerDefaultIdleCallback()}_signer=void 0;static async create(t={}){let r=t.storage??new Pt,n=t.keyType??Yr,o=null;if(t.identity)o=t.identity;else{let a=await r.get(ot);if(!a)try{let u=new we,l=await u.get(G),d=await u.get(ot);l&&d&&n===Yr&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await r.set(G,l),await r.set(ot,d),a=l,await u.remove(G),await u.remove(ot))}catch(u){console.error(`error while attempting to recover localstorage: ${u}`)}if(a)try{typeof a=="object"?n===Zr&&typeof a=="string"?o=Kt.fromJSON(a):o=await Wt.fromKeyPair(a):typeof a=="string"&&(o=Kt.fromJSON(a))}catch{}}let s=new ae,i=null;if(o)try{let a=await r.get(G);if(typeof a=="object"&&a!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");t.identity?s=t.identity:a&&(i=gt.fromJSON(a),pe(i)?"toDer"in o?s=Zt.fromDelegation(o,i):s=Yt.fromDelegation(o,i):(await zr(r),o=null))}catch(a){console.error(a),await zr(r),o=null}let c;return t.idleOptions?.disableIdle?c=void 0:(i||t.identity)&&(c=ye.create(t.idleOptions)),o||(n===Zr?o=Kt.generate():(t.storage&&n===Yr&&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 '${Zr}' as the key type, as it can serialize to a string`),o=await Wt.generate()),await Oo(r,o)),new e(s,o,i,r,c,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(c=>({delegation:new Ct(c.delegation.pubkey,c.delegation.expiration,c.delegation.targets),signature:c.signature})),o=gt.fromDelegations(n,t.userPublicKey),s=this._key;if(!s)return;this._chain=o,"toDer"in s?this._identity=Zt.fromDelegation(s,this._chain):this._identity=Yt.fromDelegation(s,this._chain),this._idpWindow?.close();let i=this._createOptions?.idleOptions;!this.idleManager&&!i?.disableIdle&&(this.idleManager=ye.create(i),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(G,JSON.stringify(this._chain.toJSON())),await Oo(this._storage,this._key),r?.(t)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null&&pe(this._chain)}async login(t){let r=So(this._createOptions?.loginOptions,t),n=r?.maxTimeToLive??To,o=new URL(r?.identityProvider?.toString()||Hs);o.hash=qs,this._idpWindow?.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(o,{maxTimeToLive:n,...r}),window.addEventListener("message",this._eventHandler),this._idpWindow=window.open(o.toString(),"idpWindow",r?.windowOpenerFeatures)??void 0;let s=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(Ao,r?.onError):setTimeout(s,ks))};s()}async loginWithIcrc29(t){let r=So(this._createOptions?.loginOptions,t),n=r?.maxTimeToLive??To,o=new URL(r?.identityProvider?.toString()||Ks);this._signer?.closeChannel();let s=new We({url:o.toString(),windowOpenerFeatures:r?.windowOpenerFeatures});this._signer=new Ve({transport:s,derivationOrigin:r?.derivationOrigin?.toString()});let i=this._key;if(!i)return;let c=await this._signer.delegation({publicKey:this._key.getPublicKey().toDer(),maxTimeToLive:n});this._chain=c,"toDer"in i?this._identity=Zt.fromDelegation(i,this._chain):this._identity=Yt.fromDelegation(i,this._chain),this._chain&&await this._storage.set(G,JSON.stringify(this._chain.toJSON())),t?.onSuccess?.({kind:"authorize-client-success",delegations:c.delegations,userPublicKey:this._key?.getPublicKey().toDer(),authnMethod:"passkey"})}_getEventHandler(t,r){return async n=>{if(n.origin!==t.origin)return;let o=n.data;switch(o.kind){case"authorize-ready":{let s={kind:"authorize-client",sessionPublicKey:new Uint8Array(this._key?.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,allowPinAuthentication:r?.allowPinAuthentication,derivationOrigin:r?.derivationOrigin?.toString(),...r?.customValues};this._idpWindow?.postMessage(s,t.origin);break}case"authorize-client-success":try{await this._handleSuccess(o,r?.onSuccess)}catch(s){this._handleFailure(s.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(o.text,r?.onError);break}}}_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 zr(this._storage),this._identity=new ae,this._chain=null,t.returnTo)try{window.history.pushState({},"",t.returnTo)}catch{window.location.href=t.returnTo}}};async function zr(e){await e.remove(ot),await e.remove(G),await e.remove(Io)}function So(e,t){if(!e&&!t)return;let r=e?.customValues||t?.customValues?{...e?.customValues,...t?.customValues}:void 0;return{...e,...t,customValues:r}}function Vs(e){if(e instanceof Wt)return e.getKeyPair();if(e instanceof Kt)return JSON.stringify(e.toJSON());throw new Error("Unsupported key type")}async function Oo(e,t){let r=Vs(t);await e.set(ot,r)}var gf=BigInt(144e11);var Bo=1e3;var vo=()=>Ee.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var Ro=({data:e})=>{let{msg:t}=e;switch(t){case"junoStartAuthTimer":Fs();return;case"junoStopAuthTimer":Co();return}},ze,Fs=()=>ze=setInterval(async()=>await $s(),Bo),Co=()=>{ze&&(clearInterval(ze),ze=void 0)},$s=async()=>{let[e,t]=await Promise.all([Gs(),Ws()]);if(e&&t.valid&&t.delegation!==null){Zs(t.delegation);return}Ys()},Gs=async()=>(await vo()).isAuthenticated(),Ws=async()=>{let t=await new Pt().get(G),r=t!==null?gt.fromJSON(t):null;return{valid:r!==null&&pe(r),delegation:r}},Ys=()=>{Co(),postMessage({msg:"junoSignOutAuthTimer"})},Zs=e=>{let t=e.delegations[0]?.delegation.expiration;if(t===void 0)return;let r=new Date(Number(t/BigInt(1e6))).getTime()-Date.now();postMessage({msg:"junoDelegationRemainingTime",data:{authRemainingTime:r}})};onmessage=e=>{Ro(e)};})();
12
12
  /*! Bundled license information:
13
13
 
14
14
  @noble/hashes/esm/utils.js: