canic-cli 0.286.0

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

`)}

export interface ${ol(t)}Service {
${n}
}
`}function ka(t,e){return vo(t,[e])}var Fe=t=>document.getElementById(t),yt=Fe("actors"),La=Fe("search"),Ro=Fe("notice"),Ee=(t,e="")=>Object.assign(document.createElement(t),{textContent:e}),sr=await(await fetch("/console.json")).json(),Ao=Fe("application");Number.isInteger(sr.app_port)&&sr.app_port>0&&sr.app_port<=65535&&(Ao.href="http://localhost:"+sr.app_port+"/",Ao.hidden=!1);var Ie=sr.connection,Co=sr.methods,on=sr.contracts??{},nn=new Map;function ja(){let t=yt.value;yt.replaceChildren(...Array.from(new Set([...Object.keys(Co),...Object.keys(Ie?.canisters??{}),...Object.keys(on)])).sort().map(e=>new Option(e,e))),[...yt.options].some(e=>e.value===t)&&(yt.value=t),Za()}function Ma(t,e){let r=nn.get(t)?.get(e);if(r)return r;let n=on[t]?.[e];if(!n)return;let{Root:o,...s}=n.request.schema,{Root:i,...c}=n.reply.schema;return{id:n.id,schemas:{...s,...c,Request:o,Response:i},request:n.request_limits,response:n.reply_limits}}function il(t){return{id:t.id,request:{k:"ref",name:"Request"},response:{k:"ref",name:"Response"},requestBytes:t.request.bytes,responseBytes:t.response.bytes,requestNodes:t.request.nodes,responseNodes:t.response.nodes,requestDepth:t.request.depth,responseDepth:t.response.depth}}function $a(t){let e=new URL(t.gateway);if(e.protocol!=="http:"||!["localhost","127.0.0.1","[::1]"].includes(e.hostname)||e.username||e.password||e.pathname!=="/"||e.search||e.hash)throw Error("Select a local simulator gateway.");let r=t.root_key,n=typeof r=="string"&&/^(?:[a-f\d]{2})+$/i.test(r)?Uint8Array.from(r.match(/../g),o=>parseInt(o,16)):Array.isArray(r)&&r.every(o=>Number.isInteger(o)&&o>=0&&o<=255)?Uint8Array.from(r):null;if(!n?.length)throw Error("Connection needs a pinned root key.");return{host:e.origin,rootKey:n,shouldFetchRootKey:!1,retryTimes:0}}var Pa=Fe("mode"),Er=Fe("history-list"),Va=Fe("clear-history");function Ha(){Fe("history-count").textContent=String(Er.childElementCount),Va.disabled=Er.childElementCount===0}function za(){Er.replaceChildren(),Ha()}Va.onclick=za;function Ka(t){return JSON.stringify(t,(e,r)=>typeof r=="bigint"?r+"n":r instanceof Uint8Array?{$hex:Ca(r)}:r,2)}function cl(t,e,r,n){let o=document.createElement("details"),i=new Date().toLocaleTimeString()+" \xB7 "+t+"."+e+" \xB7 "+r,c=Ee("summary",i+" \xB7 Pending");o.append(c,Ee("code",n));let a=Ee("li");a.append(o),Er.prepend(a),Er.childElementCount>50&&Er.lastElementChild.remove(),Ha();function f(u,d){let l=d.length>4096?d.slice(0,4096)+"\u2026":d;o.append(Ee("strong",u),Ee("pre",l))}return{request(u){f("Request",Ka(u))},finish(u,d){c.textContent=i+" \xB7 "+u,f(u,d)}}}function Da(t){let e=Ee("button","Copy TypeScript");return e.onclick=async()=>{try{await navigator.clipboard.writeText(t()),Ro.textContent="TypeScript copied."}catch{Ro.textContent="Clipboard access failed. Select the declaration or use Download TypeScript."}},e}function ti(){let t=La.value.trim().toLowerCase(),e=Pa.value,r=Fe("methods").querySelectorAll("details[data-mode]"),n=0;for(let o of r){let s=!e||o.dataset.mode===e||e==="query"&&o.dataset.mode==="composite_query";o.hidden=!(s&&o.dataset.name.toLowerCase().includes(t)),o.hidden||n++}Fe("no-matches").hidden=r.length===0||n>0}function Za(){let t=yt.value,e=Ie?.canisters?.[t];Fe("fleet").textContent=[Ie?.app,Ie?.fleet,Ie?.gateway].filter(Boolean).join(" / "),Fe("target").textContent=e??"No installed principal for this canister.";let r=Fe("methods");r.replaceChildren();let n=new Map((Co[t]??[]).map(i=>[i.name,i.mode]));for(let[i,c]of Object.entries(on[t]??{}))n.has(i)||n.set(i,c.mode);for(let i of nn.get(t)?.keys()??[])n.has(i)||n.set(i,"unknown");let o=[...n].sort(([i],[c])=>i.localeCompare(c)).map(([i,c])=>({name:i,mode:c,access:"application-defined",schemas:Ma(t,i)?.schemas}));if(o.length){let i=Ee("button","Download TypeScript");i.onclick=()=>{let a=URL.createObjectURL(new Blob([vo(t,o)],{type:"text/plain"}));Object.assign(document.createElement("a"),{href:a,download:t+".ts"}).click(),setTimeout(()=>URL.revokeObjectURL(a),1e3)};let c=Ee("div");c.className="actions",c.append(Da(()=>vo(t,o)),i),r.append(c)}else r.append(Ee("p","Load Wire contracts to inspect endpoints."));let s=Ee("p","No matching endpoints.");s.id="no-matches",r.append(s);for(let i of o){let c=Ee("details"),a=Ee("summary",i.name+" \xB7 "+i.mode);c.dataset.name=i.name,c.dataset.mode=i.mode,c.append(a),r.append(c),c.addEventListener("toggle",()=>{if(!(!c.open||c.children.length>1))try{if(!i.schemas){c.append(Ee("p","Load this endpoint\u2019s Wire manifest to inspect its request."));return}let f=Ma(t,i.name),u=ka(t,i);c.append(Ee("pre",u),Da(()=>u));let d=qa(f.schemas.Request,f.schemas);if(c.append(d.el),!e||!Ie?.gateway||!Ie?.root_key||!["query","composite_query","update"].includes(i.mode))return;let l=Ee("button",i.mode==="update"?"Send anonymous update":"Run anonymous query"),h=Ee("pre");h.hidden=!0,l.onclick=async()=>{l.disabled=!0,h.hidden=!1;let m=cl(t,i.name,i.mode,e);try{let b=Ra(il(f),f.schemas),p=d.read();m.request(p);let x=b.encodeRequest(p),g=await Bo.create({...$a(Ie),identity:new nr}),y=M.fromText(e);h.textContent="Waiting for reply\u2026";let O;if(i.mode==="update")O=(await g.update(y,{methodName:i.name,arg:x})).reply;else{let T=await g.query(y,{methodName:i.name,arg:x});if(T.status!=="replied")throw Error(T.reject_message);O=T.reply.arg}h.textContent=Ka(b.decodeResponse(new Uint8Array(O))),m.finish("Reply",h.textContent)}catch(b){h.textContent=String(b),m.finish("Error",h.textContent)}finally{l.disabled=!1}},c.append(l,h)}catch(f){c.append(Ee("p",String(f)))}})}ti()}function Ya(t,e){let r=Fe(t);r.onchange=async()=>{try{for(let n of r.files??[]){if(n.size>16*1024*1024)throw Error("File exceeds 16 MiB.");e(JSON.parse(await n.text()))}Ro.textContent="",ja()}catch(n){Ro.textContent=String(n)}r.value=""}}Ya("connection",t=>{if($a(t),!t.canisters||typeof t.canisters!="object")throw Error("Missing canister map.");for(let r of Object.values(t.canisters))M.fromText(String(r));let e=t.app===Ie?.app&&t.fleet===Ie?.fleet&&t.gateway===Ie?.gateway&&String(t.root_key)===String(Ie?.root_key)&&Object.keys({...Ie?.canisters,...t.canisters}).every(r=>t.canisters[r]===Ie?.canisters?.[r]);if(Ie=t,!e){za(),Ao.hidden=!0,Ao.removeAttribute("href");for(let r of Object.keys(Co))delete Co[r];on={},nn.clear()}});Ya("contracts",t=>{if(t.schemas&&t.endpoint){if(!yt.value)throw Error("Select a canister first.");let e=nn.get(yt.value)??new Map,r=n=>({...n.payload_limits,bytes:n.payload_limits.bytes+11});e.set(t.endpoint,{id:t.id,schemas:t.schemas,request:r(t.request),response:r(t.response)}),nn.set(yt.value,e)}else{for(let e of Object.values(t))for(let r of Object.values(e))if(!r.request?.schema?.Root||!r.reply?.schema?.Root)throw Error("Expected a Canic contracts.json inventory.");on=t}});yt.onchange=Za;La.oninput=ti;Pa.onchange=ti;ja();
/*! Bundled license information:

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

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

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

   END OF TERMS AND CONDITIONS

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

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

   Copyright [yyyy] [name of copyright owner]

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

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

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

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

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

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

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

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