@junobuild/core-standalone 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/canisterStatus-OWQH6ZT5.js +2 -0
- package/dist/browser/{chunk-REWHDUNS.js → chunk-DCSQJUQP.js} +2 -18
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +2 -2
- package/dist/declarations/satellite/satellite.did.d.ts +0 -2
- package/dist/declarations/satellite/satellite.factory.certified.did.js +1 -3
- package/dist/declarations/satellite/satellite.factory.did.js +1 -3
- package/dist/declarations/satellite/satellite.factory.did.mjs +1 -3
- package/dist/declarations/sputnik/sputnik.did.d.ts +0 -2
- package/dist/declarations/sputnik/sputnik.factory.certified.did.js +1 -3
- package/dist/declarations/sputnik/sputnik.factory.did.js +1 -3
- package/dist/node/index.mjs +1 -19
- package/dist/node/index.mjs.map +2 -2
- package/dist/workers/auth.worker.js +1 -16
- package/package.json +1 -1
- package/dist/browser/canisterStatus-TKCY5NA5.js +0 -2
- /package/dist/browser/{canisterStatus-TKCY5NA5.js.map → canisterStatus-OWQH6ZT5.js.map} +0 -0
- /package/dist/browser/{chunk-REWHDUNS.js.map → chunk-DCSQJUQP.js.map} +0 -0
|
@@ -14,7 +14,7 @@ variant ${t} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.displ
|
|
|
14
14
|
ic-request`),Qc=class{getPrincipal(){return this._principal||(this._principal=me.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:t}=e,n=gl(e,["body"]),i=gn(t);return Object.assign(Object.assign({},n),{body:{content:t,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(Qe(yl,i))}})}},An=class{getPrincipal(){return me.anonymous()}async transformRequest(e){return Object.assign(Object.assign({},e),{body:{content:e.body}})}};var eu=rn(ii());var Sn=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){let r=new Uint32Array(1);return window.crypto.getRandomValues(r),r[0]}if(typeof crypto<"u"&&crypto.getRandomValues){let r=new Uint32Array(1);return crypto.getRandomValues(r),r[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var ki;(function(r){r.Call="call"})(ki||(ki={}));function jr(){let r=new ArrayBuffer(16),e=new DataView(r),t=Sn(),n=Sn(),i=Sn(),s=Sn();return e.setUint32(0,t),e.setUint32(4,n),e.setUint32(8,i),e.setUint32(12,s),r}var Jc=BigInt(1e6),wl=60*1e3,Sr=class{constructor(e){if(e<90*1e3){let c=BigInt(Date.now()+e)*Jc/BigInt(1e9);this._value=c*BigInt(1e9);return}let s=BigInt(Math.floor(Date.now()+e-wl))*Jc/BigInt(1e9)/BigInt(60)*BigInt(60)*BigInt(1e9);this._value=s}toCBOR(){return eu.value.u64(this._value.toString(16),16)}toHash(){return Be(this._value)}};function Bo(r=jr){return async e=>{let t=e.request.headers;e.request.headers=t,e.endpoint==="call"&&(e.body.nonce=r())}}function Yr(r){let e=[];return r.forEach((t,n)=>{e.push([n,t])}),e}var zr=class extends Ue{constructor(e,t){super(e),this.response=t,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}},qi=class extends Ue{constructor(e,t,n,i,s,o){super(e),this.response=t,this.requestId=n,this.senderPubkey=i,this.senderSig=s,this.ingressExpiry=o,this.name="AgentCallError",Object.setPrototypeOf(this,new.target.prototype)}},Ci=class extends Ue{constructor(e,t,n,i,s,o){super(e),this.response=t,this.requestId=n,this.senderPubkey=i,this.senderSig=s,this.ingressExpiry=o,this.name="AgentQueryError",Object.setPrototypeOf(this,new.target.prototype)}},$i=class extends Ue{constructor(e,t,n,i,s,o){super(e),this.response=t,this.requestId=n,this.senderPubkey=i,this.senderSig=s,this.ingressExpiry=o,this.name="AgentReadStateError",Object.setPrototypeOf(this,new.target.prototype)}};var Hi=BigInt(4294967295),To=BigInt(32);function tu(r,e=!1){return e?{h:Number(r&Hi),l:Number(r>>To&Hi)}:{h:Number(r>>To&Hi)|0,l:Number(r&Hi)|0}}function bl(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:s,l:o}=tu(r[i],e);[t[i],n[i]]=[s,o]}return[t,n]}var xl=(r,e)=>BigInt(r>>>0)<<To|BigInt(e>>>0),_l=(r,e,t)=>r>>>t,El=(r,e,t)=>r<<32-t|e>>>t,vl=(r,e,t)=>r>>>t|e<<32-t,Il=(r,e,t)=>r<<32-t|e>>>t,Al=(r,e,t)=>r<<64-t|e>>>t-32,Sl=(r,e,t)=>r>>>t-32|e<<64-t,Bl=(r,e)=>e,Tl=(r,e)=>r,Nl=(r,e,t)=>r<<t|e>>>32-t,Rl=(r,e,t)=>e<<t|r>>>32-t,Ol=(r,e,t)=>e<<t-32|r>>>64-t,Ul=(r,e,t)=>r<<t-32|e>>>64-t;function Fl(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var Pl=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Ll=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Ml=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Dl=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,kl=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),ql=(r,e,t,n,i,s)=>e+t+n+i+s+(r/2**32|0)|0;var Cl={fromBig:tu,split:bl,toBig:xl,shrSH:_l,shrSL:El,rotrSH:vl,rotrSL:Il,rotrBH:Al,rotrBL:Sl,rotr32H:Bl,rotr32L:Tl,rotlSH:Nl,rotlSL:Rl,rotlBH:Ol,rotlBL:Ul,add:Fl,add3L:Pl,add3H:Ll,add4L:Ml,add4H:Dl,add5H:ql,add5L:kl},le=Cl;var[$l,Hl]=le.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),hr=new Uint32Array(80),dr=new Uint32Array(80),No=class extends Lr{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:i,Ch:s,Cl:o,Dh:c,Dl:a,Eh:h,El:p,Fh:g,Fl:w,Gh:x,Gl:f,Hh:N,Hl:T}=this;return[e,t,n,i,s,o,c,a,h,p,g,w,x,f,N,T]}set(e,t,n,i,s,o,c,a,h,p,g,w,x,f,N,T){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=c|0,this.Dl=a|0,this.Eh=h|0,this.El=p|0,this.Fh=g|0,this.Fl=w|0,this.Gh=x|0,this.Gl=f|0,this.Hh=N|0,this.Hl=T|0}process(e,t){for(let D=0;D<16;D++,t+=4)hr[D]=e.getUint32(t),dr[D]=e.getUint32(t+=4);for(let D=16;D<80;D++){let K=hr[D-15]|0,E=dr[D-15]|0,C=le.rotrSH(K,E,1)^le.rotrSH(K,E,8)^le.shrSH(K,E,7),G=le.rotrSL(K,E,1)^le.rotrSL(K,E,8)^le.shrSL(K,E,7),j=hr[D-2]|0,k=dr[D-2]|0,fe=le.rotrSH(j,k,19)^le.rotrBH(j,k,61)^le.shrSH(j,k,6),re=le.rotrSL(j,k,19)^le.rotrBL(j,k,61)^le.shrSL(j,k,6),te=le.add4L(G,re,dr[D-7],dr[D-16]),y=le.add4H(te,C,fe,hr[D-7],hr[D-16]);hr[D]=y|0,dr[D]=te|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:c,Cl:a,Dh:h,Dl:p,Eh:g,El:w,Fh:x,Fl:f,Gh:N,Gl:T,Hh:O,Hl:H}=this;for(let D=0;D<80;D++){let K=le.rotrSH(g,w,14)^le.rotrSH(g,w,18)^le.rotrBH(g,w,41),E=le.rotrSL(g,w,14)^le.rotrSL(g,w,18)^le.rotrBL(g,w,41),C=g&x^~g&N,G=w&f^~w&T,j=le.add5L(H,E,G,Hl[D],dr[D]),k=le.add5H(j,O,K,C,$l[D],hr[D]),fe=j|0,re=le.rotrSH(n,i,28)^le.rotrBH(n,i,34)^le.rotrBH(n,i,39),te=le.rotrSL(n,i,28)^le.rotrBL(n,i,34)^le.rotrBL(n,i,39),y=n&s^n&c^s&c,I=i&o^i&a^o&a;O=N|0,H=T|0,N=x|0,T=f|0,x=g|0,f=w|0,{h:g,l:w}=le.add(h|0,p|0,k|0,fe|0),h=c|0,p=a|0,c=s|0,a=o|0,s=n|0,o=i|0;let q=le.add3L(fe,te,I);n=le.add3H(q,k,re,y),i=q|0}({h:n,l:i}=le.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:s,l:o}=le.add(this.Bh|0,this.Bl|0,s|0,o|0),{h:c,l:a}=le.add(this.Ch|0,this.Cl|0,c|0,a|0),{h,l:p}=le.add(this.Dh|0,this.Dl|0,h|0,p|0),{h:g,l:w}=le.add(this.Eh|0,this.El|0,g|0,w|0),{h:x,l:f}=le.add(this.Fh|0,this.Fl|0,x|0,f|0),{h:N,l:T}=le.add(this.Gh|0,this.Gl|0,N|0,T|0),{h:O,l:H}=le.add(this.Hh|0,this.Hl|0,O|0,H|0),this.set(n,i,s,o,c,a,h,p,g,w,x,f,N,T,O,H)}roundClean(){hr.fill(0),dr.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ru=nn(()=>new No);var Rt=BigInt(0),ut=BigInt(1),Gi=BigInt(2),Gl=BigInt(8),Vl={zip215:!0};function jl(r){let e=Oi(r);return Tt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function nu(r){let e=jl(r),{Fp:t,n,prehash:i,hash:s,randomBytes:o,nByteLength:c,h:a}=e,h=Gi<<BigInt(c*8)-ut,p=t.create,g=kt(e.n,e.nBitLength),w=e.uvRatio||((F,P)=>{try{return{isValid:!0,value:t.sqrt(F*t.inv(P))}}catch{return{isValid:!1,value:Rt}}}),x=e.adjustScalarBytes||(F=>F),f=e.domain||((F,P,$)=>{if(sr("phflag",$),P.length||$)throw new Error("Contexts/pre-hash are not supported");return F});function N(F,P){Bt("coordinate "+F,P,Rt,h)}function T(F){if(!(F instanceof D))throw new Error("ExtendedPoint expected")}let O=Kt((F,P)=>{let{ex:$,ey:Z,ez:ue}=F,ce=F.is0();P==null&&(P=ce?Gl:t.inv(ue));let Y=p($*P),U=p(Z*P),d=p(ue*P);if(ce)return{x:Rt,y:ut};if(d!==ut)throw new Error("invZ was invalid");return{x:Y,y:U}}),H=Kt(F=>{let{a:P,d:$}=e;if(F.is0())throw new Error("bad point: ZERO");let{ex:Z,ey:ue,ez:ce,et:Y}=F,U=p(Z*Z),d=p(ue*ue),J=p(ce*ce),ee=p(J*J),ae=p(U*P),Q=p(J*p(ae+d)),u=p(ee+p($*p(U*d)));if(Q!==u)throw new Error("bad point: equation left != right (1)");let l=p(Z*ue),m=p(ce*Y);if(l!==m)throw new Error("bad point: equation left != right (2)");return!0});class D{constructor(P,$,Z,ue){this.ex=P,this.ey=$,this.ez=Z,this.et=ue,N("x",P),N("y",$),N("z",Z),N("t",ue),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(P){if(P instanceof D)throw new Error("extended point not allowed");let{x:$,y:Z}=P||{};return N("x",$),N("y",Z),new D($,Z,ut,p($*Z))}static normalizeZ(P){let $=t.invertBatch(P.map(Z=>Z.ez));return P.map((Z,ue)=>Z.toAffine($[ue])).map(D.fromAffine)}static msm(P,$){return Ri(D,g,P,$)}_setWindowSize(P){C.setWindowSize(this,P)}assertValidity(){H(this)}equals(P){T(P);let{ex:$,ey:Z,ez:ue}=this,{ex:ce,ey:Y,ez:U}=P,d=p($*U),J=p(ce*ue),ee=p(Z*U),ae=p(Y*ue);return d===J&&ee===ae}is0(){return this.equals(D.ZERO)}negate(){return new D(p(-this.ex),this.ey,this.ez,p(-this.et))}double(){let{a:P}=e,{ex:$,ey:Z,ez:ue}=this,ce=p($*$),Y=p(Z*Z),U=p(Gi*p(ue*ue)),d=p(P*ce),J=$+Z,ee=p(p(J*J)-ce-Y),ae=d+Y,Q=ae-U,u=d-Y,l=p(ee*Q),m=p(ae*u),S=p(ee*u),v=p(Q*ae);return new D(l,m,v,S)}add(P){T(P);let{a:$,d:Z}=e,{ex:ue,ey:ce,ez:Y,et:U}=this,{ex:d,ey:J,ez:ee,et:ae}=P;if($===BigInt(-1)){let V=p((ce-ue)*(J+d)),W=p((ce+ue)*(J-d)),ie=p(W-V);if(ie===Rt)return this.double();let de=p(Y*Gi*ae),Ee=p(U*Gi*ee),Ne=Ee+de,he=W+V,oe=Ee-de,ke=p(Ne*ie),Qt=p(he*oe),mr=p(Ne*oe),gr=p(ie*he);return new D(ke,Qt,gr,mr)}let Q=p(ue*d),u=p(ce*J),l=p(U*Z*ae),m=p(Y*ee),S=p((ue+ce)*(d+J)-Q-u),v=m-l,A=m+l,M=p(u-$*Q),b=p(S*v),B=p(A*M),L=p(S*M),R=p(v*A);return new D(b,B,R,L)}subtract(P){return this.add(P.negate())}wNAF(P){return C.wNAFCached(this,P,D.normalizeZ)}multiply(P){let $=P;Bt("scalar",$,ut,n);let{p:Z,f:ue}=this.wNAF($);return D.normalizeZ([Z,ue])[0]}multiplyUnsafe(P){let $=P;return Bt("scalar",$,Rt,n),$===Rt?E:this.equals(E)||$===ut?this:this.equals(K)?this.wNAF($).p:C.unsafeLadder(this,$)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return C.unsafeLadder(this,n).is0()}toAffine(P){return O(this,P)}clearCofactor(){let{h:P}=e;return P===ut?this:this.multiplyUnsafe(P)}static fromHex(P,$=!1){let{d:Z,a:ue}=e,ce=t.BYTES;P=He("pointHex",P,ce),sr("zip215",$);let Y=P.slice(),U=P[ce-1];Y[ce-1]=U&-129;let d=or(Y),J=$?h:t.ORDER;Bt("pointHex.y",d,Rt,J);let ee=p(d*d),ae=p(ee-ut),Q=p(Z*ee-ue),{isValid:u,value:l}=w(ae,Q);if(!u)throw new Error("Point.fromHex: invalid y coordinate");let m=(l&ut)===ut,S=(U&128)!==0;if(!$&&l===Rt&&S)throw new Error("Point.fromHex: x=0 and x_0=1");return S!==m&&(l=p(-l)),D.fromAffine({x:l,y:d})}static fromPrivateKey(P){return k(P).point}toRawBytes(){let{x:P,y:$}=this.toAffine(),Z=Ir($,t.BYTES);return Z[Z.length-1]|=P&ut?128:0,Z}toHex(){return St(this.toRawBytes())}}D.BASE=new D(e.Gx,e.Gy,ut,p(e.Gx*e.Gy)),D.ZERO=new D(Rt,ut,ut,Rt);let{BASE:K,ZERO:E}=D,C=Ni(D,c*8);function G(F){return Se(F,n)}function j(F){return G(or(F))}function k(F){let P=c;F=He("private key",F,P);let $=He("hashed private key",s(F),2*P),Z=x($.slice(0,P)),ue=$.slice(P,2*P),ce=j(Z),Y=K.multiply(ce),U=Y.toRawBytes();return{head:Z,prefix:ue,scalar:ce,point:Y,pointBytes:U}}function fe(F){return k(F).pointBytes}function re(F=new Uint8Array,...P){let $=Ie(...P);return j(s(f($,He("context",F),!!i)))}function te(F,P,$={}){F=He("message",F),i&&(F=i(F));let{prefix:Z,scalar:ue,pointBytes:ce}=k(P),Y=re($.context,Z,F),U=K.multiply(Y).toRawBytes(),d=re($.context,U,ce,F),J=G(Y+d*ue);Bt("signature.s",J,Rt,n);let ee=Ie(U,Ir(J,t.BYTES));return He("result",ee,c*2)}let y=Vl;function I(F,P,$,Z=y){let{context:ue,zip215:ce}=Z,Y=t.BYTES;F=He("signature",F,2*Y),P=He("message",P),ce!==void 0&&sr("zip215",ce),i&&(P=i(P));let U=or(F.slice(Y,2*Y)),d,J,ee;try{d=D.fromHex($,ce),J=D.fromHex(F.slice(0,Y),ce),ee=K.multiplyUnsafe(U)}catch{return!1}if(!ce&&d.isSmallOrder())return!1;let ae=re(ue,J.toRawBytes(),d.toRawBytes(),P);return J.add(d.multiplyUnsafe(ae)).subtract(ee).clearCofactor().equals(D.ZERO)}return K._setWindowSize(8),{CURVE:e,getPublicKey:fe,sign:te,verify:I,ExtendedPoint:D,utils:{getExtendedPublicKey:k,randomPrivateKey:()=>o(t.BYTES),precompute(F=8,P=D.BASE){return P._setWindowSize(F),P.multiply(BigInt(3)),P}}}}var Ro=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),iu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Xp=BigInt(0),Yl=BigInt(1),su=BigInt(2),Qp=BigInt(3),zl=BigInt(5),Kl=BigInt(8);function Zl(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),i=BigInt(80),s=Ro,c=r*r%s*r%s,a=Nt(c,su,s)*c%s,h=Nt(a,Yl,s)*r%s,p=Nt(h,zl,s)*h%s,g=Nt(p,e,s)*p%s,w=Nt(g,t,s)*g%s,x=Nt(w,n,s)*w%s,f=Nt(x,i,s)*x%s,N=Nt(f,i,s)*x%s,T=Nt(N,e,s)*p%s;return{pow_p_5_8:Nt(T,su,s)*r%s,b2:c}}function Wl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Xl(r,e){let t=Ro,n=Se(e*e*e,t),i=Se(n*n*e,t),s=Zl(r*i).pow_p_5_8,o=Se(r*n*s,t),c=Se(e*o*o,t),a=o,h=Se(o*iu,t),p=c===r,g=c===Se(-r,t),w=c===Se(-r*iu,t);return p&&(o=a),(g||w)&&(o=h),Mc(o,t)&&(o=Se(-o,t)),{isValid:p||g,value:o}}var Ql=kt(Ro,void 0,!0),Jl={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ql,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Kl,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ru,randomBytes:Cn,adjustScalarBytes:Wl,uvRatio:Xl},ou=nu(Jl);var au=function(r,e,t,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,t):i?i.value=t:e.set(r,t),t},st=function(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)},et,Bn,cu,uu,Vi=class{constructor(e={}){et.set(this,void 0),Bn.set(this,void 0),this[cu]=this.entries.bind(this),this[uu]="ExpirableMap";let{source:t=[],expirationTime:n=10*60*1e3}=e,i=Date.now();au(this,et,new Map([...t].map(([s,o])=>[s,{value:o,timestamp:i}])),"f"),au(this,Bn,n,"f")}prune(){let e=Date.now();for(let[t,n]of st(this,et,"f").entries())e-n.timestamp>st(this,Bn,"f")&&st(this,et,"f").delete(t);return this}set(e,t){this.prune();let n={value:t,timestamp:Date.now()};return st(this,et,"f").set(e,n),this}get(e){let t=st(this,et,"f").get(e);if(t!==void 0){if(Date.now()-t.timestamp>st(this,Bn,"f")){st(this,et,"f").delete(e);return}return t.value}}clear(){st(this,et,"f").clear()}entries(){let e=st(this,et,"f").entries();return function*(){for(let[n,i]of e)yield[n,i.value]}()}values(){let e=st(this,et,"f").values();return function*(){for(let n of e)yield n.value}()}keys(){return st(this,et,"f").keys()}forEach(e,t){for(let[n,i]of st(this,et,"f").entries())e.call(t,i.value,n,this)}has(e){return st(this,et,"f").has(e)}delete(e){return st(this,et,"f").delete(e)}get size(){return st(this,et,"f").size}};et=new WeakMap,Bn=new WeakMap,cu=Symbol.iterator,uu=Symbol.toStringTag;var fu=r=>{if(r<=127)return 1;if(r<=255)return 2;if(r<=65535)return 3;if(r<=16777215)return 4;throw new Error("Length too long (> 4 bytes)")},lu=(r,e,t)=>{if(t<=127)return r[e]=t,1;if(t<=255)return r[e]=129,r[e+1]=t,2;if(t<=65535)return r[e]=130,r[e+1]=t>>8,r[e+2]=t,3;if(t<=16777215)return r[e]=131,r[e+1]=t>>16,r[e+2]=t>>8,r[e+3]=t,4;throw new Error("Length too long (> 4 bytes)")},Oo=(r,e)=>{if(r[e]<128)return 1;if(r[e]===128)throw new Error("Invalid length 0");if(r[e]===129)return 2;if(r[e]===130)return 3;if(r[e]===131)return 4;throw new Error("Length too long (> 4 bytes)")},eh=(r,e)=>{let t=Oo(r,e);if(t===1)return r[e];if(t===2)return r[e+1];if(t===3)return(r[e+1]<<8)+r[e+2];if(t===4)return(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];throw new Error("Length too long (> 4 bytes)")},r1=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),Uo=Uint8Array.from([48,5,6,3,43,101,112]),n1=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);function hu(r,e){let t=2+fu(r.byteLength+1),n=e.byteLength+t+r.byteLength,i=0,s=new Uint8Array(1+fu(n)+n);return s[i++]=48,i+=lu(s,i,n),s.set(e,i),i+=e.byteLength,s[i++]=3,i+=lu(s,i,r.byteLength+1),s[i++]=0,s.set(new Uint8Array(r),i),s}var du=(r,e)=>{let t=0,n=(c,a)=>{if(i[t++]!==c)throw new Error("Expected: "+a)},i=new Uint8Array(r);if(n(48,"sequence"),t+=Oo(i,t),!br(i.slice(t,t+e.byteLength),e))throw new Error("Not the expected OID.");t+=e.byteLength,n(3,"bit string");let s=eh(i,t)-1;t+=Oo(i,t),n(0,"0 padding");let o=i.slice(t);if(s!==o.length)throw new Error(`DER payload mismatch: Expected length ${s} actual length ${o.length}`);return o};var pu=function(r,e,t,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,t):i?i.value=t:e.set(r,t),t},mu=function(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)},ji,Yi,Tn=class r{constructor(e){if(ji.set(this,void 0),Yi.set(this,void 0),e.byteLength!==r.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");pu(this,ji,e,"f"),pu(this,Yi,r.derEncode(e),"f")}static from(e){return this.fromDer(e.toDer())}static fromRaw(e){return new r(e)}static fromDer(e){return new r(this.derDecode(e))}static derEncode(e){return hu(e,Uo).buffer}static derDecode(e){let t=du(e,Uo);if(t.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return t}get rawKey(){return mu(this,ji,"f")}get derKey(){return mu(this,Yi,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};ji=new WeakMap,Yi=new WeakMap;Tn.RAW_KEY_LENGTH=32;var Fo=class{constructor(){this.observers=[]}subscribe(e){this.observers.push(e)}unsubscribe(e){this.observers=this.observers.filter(t=>t!==e)}notify(e,...t){this.observers.forEach(n=>n(e,...t))}},zi=class extends Fo{constructor(){super()}print(e,...t){this.notify({message:e,level:"info"},...t)}warn(e,...t){this.notify({message:e,level:"warn"},...t)}error(e,t,...n){this.notify({message:e,level:"error",error:t},...n)}};var qt=function(r,e,t,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,t):i?i.value=t:e.set(r,t),t},tt=function(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)},Ct,Ki,Zi,Wi,Xi,Qi,Ji,es,Kr;var Nn=class r{constructor(e=r.default){Ct.set(this,void 0),Ki.set(this,void 0),Zi.set(this,void 0),Wi.set(this,void 0),Xi.set(this,void 0),Qi.set(this,void 0),Ji.set(this,void 0),es.set(this,void 0),Kr.set(this,0);let{initialInterval:t=500,randomizationFactor:n=.5,multiplier:i=1.5,maxInterval:s=6e4,maxElapsedTime:o=9e5,maxIterations:c=10,date:a=Date}=e;qt(this,Ct,t,"f"),qt(this,Ki,n,"f"),qt(this,Zi,i,"f"),qt(this,Wi,s,"f"),qt(this,es,a,"f"),qt(this,Xi,a.now(),"f"),qt(this,Qi,o,"f"),qt(this,Ji,c,"f")}get ellapsedTimeInMsec(){return tt(this,es,"f").now()-tt(this,Xi,"f")}get currentInterval(){return tt(this,Ct,"f")}get count(){return tt(this,Kr,"f")}get randomValueFromInterval(){let e=tt(this,Ki,"f")*tt(this,Ct,"f"),t=tt(this,Ct,"f")-e,n=tt(this,Ct,"f")+e;return Math.random()*(n-t)+t}incrementCurrentInterval(){var e;return qt(this,Ct,Math.min(tt(this,Ct,"f")*tt(this,Zi,"f"),tt(this,Wi,"f")),"f"),qt(this,Kr,(e=tt(this,Kr,"f"),e++,e),"f"),tt(this,Ct,"f")}next(){return this.ellapsedTimeInMsec>=tt(this,Qi,"f")||tt(this,Kr,"f")>=tt(this,Ji,"f")?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};Ct=new WeakMap,Ki=new WeakMap,Zi=new WeakMap,Wi=new WeakMap,Xi=new WeakMap,Qi=new WeakMap,Ji=new WeakMap,es=new WeakMap,Kr=new WeakMap;Nn.default={initialInterval:500,randomizationFactor:.5,multiplier:1.5,maxInterval:6e4,maxElapsedTime:9e5,maxIterations:10,date:Date};var Xe=function(r,e,t,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(r,t):i?i.value=t:e.set(r,t),t},X=function(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)},rt,Br,en,$t,Wt,Qr,Rn,Zr,Ot,Ut,Tr,Nr,On,Wr,Xr,Rr,Ur,bu,rs,ns,Or,gu;(function(r){r.Received="received",r.Processing="processing",r.Replied="replied",r.Rejected="rejected",r.Unknown="unknown",r.Done="done"})(gu||(gu={}));var ts=60*1e3,th="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae",xu="aaaaa-aa",rh="ic0.app",nh=".ic0.app",ih="icp0.io",sh=".icp0.io",oh="icp-api.io",ah=".icp-api.io",Un=class extends Ue{constructor(e){super(e),this.message=e}},Jr=class extends Ue{constructor(e){super(e),this.message=e}};function ch(){let r;if(typeof window<"u")if(window.fetch)r=window.fetch.bind(window);else throw new Un("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present.");else if(typeof globalThis<"u")if(globalThis.fetch)r=globalThis.fetch.bind(globalThis);else throw new Un("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available.");else typeof self<"u"&&self.fetch&&(r=self.fetch.bind(self));if(r)return r;throw new Un("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context.")}function uh(r){let e;if(r!==void 0)!r.match(/^[a-z]+:/)&&typeof window<"u"?e=new URL(window.location.protocol+"//"+r):e=new URL(r);else{let t=["ic0.app","icp0.io","127.0.0.1","localhost"],n=[".github.dev",".gitpod.io"],i=typeof window<"u"?window.location:void 0,s=i?.hostname,o;s&&typeof s=="string"&&(n.some(c=>s.endsWith(c))?o=s:o=t.find(c=>s.endsWith(c))),i&&o?e=new URL(`${i.protocol}//${o}${i.port?":"+i.port:""}`):e=new URL("https://icp-api.io")}return e.toString()}var yu=class r{constructor(e={}){var t,n;rt.add(this),Br.set(this,null),en.set(this,!1),$t.set(this,void 0),Wt.set(this,void 0),Qr.set(this,void 0),Rn.set(this,void 0),Zr.set(this,0),Ot.set(this,void 0),Ut.set(this,void 0),Tr.set(this,void 0),Nr.set(this,void 0),this._isAgent=!0,this.config={},On.set(this,0),this.log=new zi,Wr.set(this,[]),Xr.set(this,[]),Rr.set(this,new Vi({expirationTime:5*60*1e3})),Ur.set(this,!0),ns.set(this,(o,c)=>{if(X(this,Ur,"f")===!1)return o;if(!c)throw new ht("Invalid signature from replica signed query: no matching node key found.");let{status:a,signatures:h=[],requestId:p}=o,g=new TextEncoder().encode("\vic-response");for(let w of h){let{timestamp:x,identity:f}=w,N=me.fromUint8Array(f).toText(),T;if(a==="replied"){let{reply:E}=o;T=yn({status:a,reply:E,timestamp:BigInt(x),request_id:p})}else if(a==="rejected"){let{reject_code:E,reject_message:C,error_code:G}=o;T=yn({status:a,reject_code:E,reject_message:C,error_code:G,timestamp:BigInt(x),request_id:p})}else throw new Error(`Unknown status: ${a}`);let O=Qe(g,new Uint8Array(T)),H=c?.nodeKeys.get(N);if(!H)throw new ht("Invalid signature from replica signed query: no matching node key found.");let D=Tn.fromDer(H).rawKey;if(ou.verify(w.signature,new Uint8Array(O),new Uint8Array(D)))return o;throw new ht(`Invalid signature from replica ${N} signed query.`)}return o}),this.config=e,Xe(this,Wt,e.fetch||ch()||fetch.bind(globalThis),"f"),Xe(this,Qr,e.fetchOptions,"f"),Xe(this,Rn,e.callOptions,"f"),Xe(this,en,(t=e.shouldFetchRootKey)!==null&&t!==void 0?t:!1,"f"),e.rootKey?this.rootKey=e.rootKey:X(this,en,"f")?this.rootKey=null:this.rootKey=wr(th);let i=uh(e.host);this.host=new URL(i),e.verifyQuerySignatures!==void 0&&Xe(this,Ur,e.verifyQuerySignatures,"f"),Xe(this,Ut,(n=e.retryTimes)!==null&&n!==void 0?n:3,"f");let s=()=>new Nn({maxIterations:X(this,Ut,"f")});if(Xe(this,Tr,e.backoffStrategy||s,"f"),this.host.hostname.endsWith(nh)?this.host.hostname=rh:this.host.hostname.endsWith(sh)?this.host.hostname=ih:this.host.hostname.endsWith(ah)&&(this.host.hostname=oh),e.credentials){let{name:o,password:c}=e.credentials;Xe(this,Ot,`${o}${c?":"+c:""}`,"f")}if(Xe(this,$t,Promise.resolve(e.identity||new An),"f"),e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes>5)throw new Ue(`The maximum ingress expiry time is 5 minutes. Provided ingress expiry time is ${e.ingressExpiryInMinutes} minutes.`);if(e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes<=0)throw new Ue(`Ingress expiry time must be greater than 0. Provided ingress expiry time is ${e.ingressExpiryInMinutes} minutes.`);Xe(this,Nr,e.ingressExpiryInMinutes||5,"f"),this.addTransform("update",Bo(jr)),e.useQueryNonces&&this.addTransform("query",Bo(jr)),e.logToConsole&&this.log.subscribe(o=>{o.level==="error"?console.error(o.message):o.level==="warn"?console.warn(o.message):console.log(o.message)})}get waterMark(){return X(this,On,"f")}static createSync(e={}){return new this(Object.assign({},e))}static async create(e={shouldFetchRootKey:!1}){let t=r.createSync(e),n=[t.syncTime()];return t.host.toString()!=="https://icp-api.io"&&e.shouldFetchRootKey&&n.push(t.fetchRootKey()),await Promise.all(n),t}static async from(e){var t;try{return"config"in e?await r.create(e.config):await r.create({fetch:e._fetch,fetchOptions:e._fetchOptions,callOptions:e._callOptions,host:e._host.toString(),identity:(t=e._identity)!==null&&t!==void 0?t:void 0})}catch{throw new Ue("Failed to create agent from provided agent")}}isLocal(){let e=this.host.hostname;return e==="127.0.0.1"||e.endsWith("127.0.0.1")}addTransform(e,t,n=t.priority||0){if(e==="update"){let i=X(this,Xr,"f").findIndex(s=>(s.priority||0)<n);X(this,Xr,"f").splice(i>=0?i:X(this,Xr,"f").length,0,Object.assign(t,{priority:n}))}else if(e==="query"){let i=X(this,Wr,"f").findIndex(s=>(s.priority||0)<n);X(this,Wr,"f").splice(i>=0?i:X(this,Wr,"f").length,0,Object.assign(t,{priority:n}))}}async getPrincipal(){if(!X(this,$t,"f"))throw new Jr("This identity has expired due this application's security policy. Please refresh your authentication.");return(await X(this,$t,"f")).getPrincipal()}async call(e,t,n){var i,s;await X(this,rt,"m",Or).call(this);let o=(i=t.callSync)!==null&&i!==void 0?i:!0,c=await(n!==void 0?await n:await X(this,$t,"f"));if(!c)throw new Jr("This identity has expired due this application's security policy. Please refresh your authentication.");let a=me.from(e),h=t.effectiveCanisterId?me.from(t.effectiveCanisterId):a,p=c.getPrincipal()||me.anonymous(),g=new Sr(X(this,Nr,"f")*ts);Math.abs(X(this,Zr,"f"))>1e3*30&&(g=new Sr(X(this,Nr,"f")*ts+X(this,Zr,"f")));let w={request_type:ki.Call,canister_id:a,method_name:t.methodName,arg:t.arg,sender:p,ingress_expiry:g},x=await this._transform({request:{body:null,method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},X(this,Ot,"f")?{Authorization:"Basic "+btoa(X(this,Ot,"f"))}:{})},endpoint:"call",body:w}),f=x.body.nonce?N(x.body.nonce):void 0;w.nonce=f;function N(D){return new Uint8Array(D)}x=await c.transformRequest(x);let T=oi(x.body),O=X(this,Tr,"f").call(this),H=gn(w);try{let D=()=>(this.log.print(`fetching "/api/v3/canister/${h.toText()}/call" with request:`,x),X(this,Wt,"f").call(this,""+new URL(`/api/v3/canister/${h.toText()}/call`,this.host),Object.assign(Object.assign(Object.assign({},X(this,Rn,"f")),x.request),{body:T}))),K=()=>(this.log.print(`fetching "/api/v2/canister/${h.toText()}/call" with request:`,x),X(this,Wt,"f").call(this,""+new URL(`/api/v2/canister/${h.toText()}/call`,this.host),Object.assign(Object.assign(Object.assign({},X(this,Rn,"f")),x.request),{body:T}))),C=await X(this,rt,"m",rs).call(this,{request:o?D:K,backoff:O,tries:0}),G=await C.arrayBuffer(),j=C.status===200&&G.byteLength>0?yt(G):null;if(j&&"certificate"in j){let k=await this.parseTimeFromResponse({certificate:j.certificate});Xe(this,On,k,"f")}return{requestId:H,response:{ok:C.ok,status:C.status,statusText:C.statusText,body:j,headers:Yr(C.headers)},requestDetails:w}}catch(D){if(D.message.includes("v3 api not supported."))return this.log.warn("v3 api not supported. Fall back to v2"),this.call(e,Object.assign(Object.assign({},t),{callSync:!1}),n);let K=`Error while making call: ${(s=D.message)!==null&&s!==void 0?s:String(D)}`,E=new qi(K,D,Fe(H),Fe(x.body.sender_pubkey),Fe(x.body.sender_sig),String(x.body.content.ingress_expiry._value));throw this.log.error(K,E),E}}async query(e,t,n){var i,s,o,c;await X(this,rt,"m",Or).call(this);let a=X(this,Tr,"f").call(this),h=t.effectiveCanisterId?me.from(t.effectiveCanisterId):me.from(e);this.log.print(`ecid ${h.toString()}`),this.log.print(`canisterId ${e.toString()}`);let p,g,w=await(n!==void 0?n:X(this,$t,"f"));if(!w)throw new Jr("This identity has expired due this application's security policy. Please refresh your authentication.");let x=me.from(e),f=w?.getPrincipal()||me.anonymous(),N={request_type:"query",canister_id:x,method_name:t.methodName,arg:t.arg,sender:f,ingress_expiry:new Sr(X(this,Nr,"f")*ts)},T=gn(N);p=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},X(this,Ot,"f")?{Authorization:"Basic "+btoa(X(this,Ot,"f"))}:{})},endpoint:"read",body:N}),p=await w?.transformRequest(p);let O=oi(p.body),H={canister:x.toText(),ecid:h,transformedRequest:p,body:O,requestId:T,backoff:a,tries:0},D=async()=>({requestDetails:N,query:await X(this,rt,"m",bu).call(this,H)}),K=async()=>{if(!X(this,Ur,"f"))return;let E=X(this,Rr,"f").get(h.toString());return E||(await this.fetchSubnetKeys(h.toString()),X(this,Rr,"f").get(h.toString()))};try{let[E,C]=await Promise.all([D(),K()]);g=E;let{requestDetails:G,query:j}=g,k=Object.assign(Object.assign({},j),{requestDetails:G});if(this.log.print("Query response:",k),!X(this,Ur,"f"))return k;try{return X(this,ns,"f").call(this,k,C)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),X(this,Rr,"f").delete(e.toString()),await this.fetchSubnetKeys(h.toString());let re=X(this,Rr,"f").get(e.toString());if(!re)throw new ht("Invalid signature from replica signed query: no matching node key found.");return X(this,ns,"f").call(this,k,re)}}catch(E){let C=`Error while making call: ${(i=E.message)!==null&&i!==void 0?i:String(E)}`,G=new Ci(C,E,String(T),Fe((s=p?.body)===null||s===void 0?void 0:s.sender_pubkey),Fe((o=p?.body)===null||o===void 0?void 0:o.sender_sig),String((c=p?.body)===null||c===void 0?void 0:c.content.ingress_expiry._value));throw this.log.error(C,G),G}}async createReadStateRequest(e,t){await X(this,rt,"m",Or).call(this);let n=await(t!==void 0?await t:await X(this,$t,"f"));if(!n)throw new Jr("This identity has expired due this application's security policy. Please refresh your authentication.");let i=n?.getPrincipal()||me.anonymous(),s=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},X(this,Ot,"f")?{Authorization:"Basic "+btoa(X(this,Ot,"f"))}:{})},endpoint:"read_state",body:{request_type:"read_state",paths:e.paths,sender:i,ingress_expiry:new Sr(X(this,Nr,"f")*ts)}});return n?.transformRequest(s)}async readState(e,t,n,i){var s,o,c,a;function h(N){for(let T of N.paths){let[O,H]=T,D=new TextEncoder().encode("request_status");if(br(O,D))return H}}let p=h(t);await X(this,rt,"m",Or).call(this);let g=typeof e=="string"?me.fromText(e):e,w=i??await this.createReadStateRequest(t,n),x=oi(w.body);this.log.print(`fetching "/api/v2/canister/${g}/read_state" with request:`,w);let f=X(this,Tr,"f").call(this);try{let N=await X(this,rt,"m",rs).call(this,{request:()=>X(this,Wt,"f").call(this,""+new URL(`/api/v2/canister/${g.toString()}/read_state`,this.host),Object.assign(Object.assign(Object.assign({},X(this,Qr,"f")),w.request),{body:x})),backoff:f,tries:0});if(!N.ok)throw new Error(`Server returned an error:
|
|
15
15
|
Code: ${N.status} (${N.statusText})
|
|
16
16
|
Body: ${await N.text()}
|
|
17
|
-
`);let T=yt(await N.arrayBuffer());this.log.print("Read state response:",T);let O=await this.parseTimeFromResponse(T);return O>0&&(this.log.print("Read state response time:",O),Xe(this,On,O,"f")),T}catch(N){let T=`Caught exception while attempting to read state: ${(s=N.message)!==null&&s!==void 0?s:String(N)}`,O=new $i(T,N,String(p),Fe((o=w?.body)===null||o===void 0?void 0:o.sender_pubkey),Fe((c=w?.body)===null||c===void 0?void 0:c.sender_sig),String((a=w?.body)===null||a===void 0?void 0:a.content.ingress_expiry._value));throw this.log.error(T,O),O}}async parseTimeFromResponse(e){let t;if(e.certificate){let n=yt(e.certificate);if(n&&"tree"in n)t=n.tree;else throw new Error("Could not decode time from response");let i=pr(["time"],t);if(i.status!==De.Found)throw new Error("Time was not found in the response or was not in its expected format.");if(!(i.value instanceof ArrayBuffer)&&!ArrayBuffer.isView(i))throw new Error("Time was not found in the response or was not in its expected format.");let s=Vr(ys(i.value));return this.log.print("Time from response:",s),this.log.print("Time from response in milliseconds:",Number(s)),Number(s)}else this.log.warn("No certificate found in response");return 0}async syncTime(e){await X(this,rt,"m",Or).call(this);let t=await import("./canisterStatus-
|
|
17
|
+
`);let T=yt(await N.arrayBuffer());this.log.print("Read state response:",T);let O=await this.parseTimeFromResponse(T);return O>0&&(this.log.print("Read state response time:",O),Xe(this,On,O,"f")),T}catch(N){let T=`Caught exception while attempting to read state: ${(s=N.message)!==null&&s!==void 0?s:String(N)}`,O=new $i(T,N,String(p),Fe((o=w?.body)===null||o===void 0?void 0:o.sender_pubkey),Fe((c=w?.body)===null||c===void 0?void 0:c.sender_sig),String((a=w?.body)===null||a===void 0?void 0:a.content.ingress_expiry._value));throw this.log.error(T,O),O}}async parseTimeFromResponse(e){let t;if(e.certificate){let n=yt(e.certificate);if(n&&"tree"in n)t=n.tree;else throw new Error("Could not decode time from response");let i=pr(["time"],t);if(i.status!==De.Found)throw new Error("Time was not found in the response or was not in its expected format.");if(!(i.value instanceof ArrayBuffer)&&!ArrayBuffer.isView(i))throw new Error("Time was not found in the response or was not in its expected format.");let s=Vr(ys(i.value));return this.log.print("Time from response:",s),this.log.print("Time from response in milliseconds:",Number(s)),Number(s)}else this.log.warn("No certificate found in response");return 0}async syncTime(e){await X(this,rt,"m",Or).call(this);let t=await import("./canisterStatus-OWQH6ZT5.js"),n=Date.now();try{e||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let i=r.createSync({identity:new An,host:this.host.toString(),fetch:X(this,Wt,"f"),retryTimes:0}),o=(await t.request({canisterId:e??me.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),agent:i,paths:["time"]})).get("time");o&&(Xe(this,Zr,Number(o)-Number(n),"f"),this.log.notify({message:`Syncing time: offset of ${X(this,Zr,"f")}`,level:"info"}))}catch(i){this.log.error("Caught exception while attempting to sync time",i)}}async status(){let e=X(this,Ot,"f")?{Authorization:"Basic "+btoa(X(this,Ot,"f"))}:{};this.log.print('fetching "/api/v2/status"');let t=X(this,Tr,"f").call(this),n=await X(this,rt,"m",rs).call(this,{backoff:t,request:()=>X(this,Wt,"f").call(this,""+new URL("/api/v2/status",this.host),Object.assign({headers:e},X(this,Qr,"f"))),tries:0});return yt(await n.arrayBuffer())}async fetchRootKey(){let e;return X(this,Br,"f")?e=await X(this,Br,"f"):(Xe(this,Br,new Promise((t,n)=>{this.status().then(i=>{let s=i.root_key;this.rootKey=s,t(s)}).catch(n)}),"f"),e=await X(this,Br,"f")),Xe(this,Br,null,"f"),e}invalidateIdentity(){Xe(this,$t,null,"f")}replaceIdentity(e){Xe(this,$t,Promise.resolve(e),"f")}async fetchSubnetKeys(e){await X(this,rt,"m",Or).call(this);let t=me.from(e),i=(await wu({canisterId:t,paths:["subnet"],agent:this})).get("subnet");if(i&&typeof i=="object"&&"nodeKeys"in i)return X(this,Rr,"f").set(t.toText(),i),i}_transform(e){let t=Promise.resolve(e);if(e.endpoint==="call")for(let n of X(this,Xr,"f"))t=t.then(i=>n(i).then(s=>s||i));else for(let n of X(this,Wr,"f"))t=t.then(i=>n(i).then(s=>s||i));return t}};Br=new WeakMap,en=new WeakMap,$t=new WeakMap,Wt=new WeakMap,Qr=new WeakMap,Rn=new WeakMap,Zr=new WeakMap,Ot=new WeakMap,Ut=new WeakMap,Tr=new WeakMap,Nr=new WeakMap,On=new WeakMap,Wr=new WeakMap,Xr=new WeakMap,Rr=new WeakMap,Ur=new WeakMap,ns=new WeakMap,rt=new WeakSet,bu=async function r(e){var t,n;let{ecid:i,transformedRequest:s,body:o,requestId:c,backoff:a,tries:h}=e,p=h===0?0:a.next();if(this.log.print(`fetching "/api/v2/canister/${i.toString()}/query" with tries:`,{tries:h,backoff:a,delay:p}),p===null)throw new Ue(`Timestamp failed to pass the watermark after retrying the configured ${X(this,Ut,"f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);p>0&&await new Promise(f=>setTimeout(f,p));let g;try{this.log.print(`fetching "/api/v2/canister/${i.toString()}/query" with request:`,s);let f=await X(this,Wt,"f").call(this,""+new URL(`/api/v2/canister/${i.toString()}/query`,this.host),Object.assign(Object.assign(Object.assign({},X(this,Qr,"f")),s.request),{body:o}));if(f.status===200){let N=yt(await f.arrayBuffer());g=Object.assign(Object.assign({},N),{httpDetails:{ok:f.ok,status:f.status,statusText:f.statusText,headers:Yr(f.headers)},requestId:c})}else throw new zr(`Gateway returned an error:
|
|
18
18
|
Code: ${f.status} (${f.statusText})
|
|
19
19
|
Body: ${await f.text()}
|
|
20
20
|
`,{ok:f.ok,status:f.status,statusText:f.statusText,headers:Yr(f.headers)})}catch(f){if(h<X(this,Ut,"f"))return this.log.warn(`Caught exception while attempting to make query:
|
|
@@ -40,30 +40,14 @@ ieee754/index.js:
|
|
|
40
40
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
41
41
|
|
|
42
42
|
@noble/curves/esm/abstract/utils.js:
|
|
43
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
44
|
-
|
|
45
43
|
@noble/curves/esm/abstract/modular.js:
|
|
46
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
47
|
-
|
|
48
44
|
@noble/curves/esm/abstract/curve.js:
|
|
49
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
50
|
-
|
|
51
45
|
@noble/curves/esm/abstract/weierstrass.js:
|
|
52
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
53
|
-
|
|
54
46
|
@noble/curves/esm/abstract/bls.js:
|
|
55
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
56
|
-
|
|
57
47
|
@noble/curves/esm/abstract/tower.js:
|
|
58
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
59
|
-
|
|
60
48
|
@noble/curves/esm/bls12-381.js:
|
|
61
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
62
|
-
|
|
63
49
|
@noble/curves/esm/abstract/edwards.js:
|
|
64
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
65
|
-
|
|
66
50
|
@noble/curves/esm/ed25519.js:
|
|
67
51
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
68
52
|
*/
|
|
69
|
-
//# sourceMappingURL=chunk-
|
|
53
|
+
//# sourceMappingURL=chunk-DCSQJUQP.js.map
|
package/dist/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{A as Zt,B as It,C as Me,D,E as Dt,F as $e,a as Nr,b as Wi,c as Ve,d as Gi,e as Rr,f as _,g as S,h as I,i as Or,j as Sr,k as vr,l as Xt,m as Ke,n as Bt,o as Yi,p as je,q as st,r as ft,s as zi,t as Qt,u as M,z as mt}from"./chunk-REWHDUNS.js";var Ur=Nr(Lt=>{"use strict";Lt.byteLength=Qi;Lt.toByteArray=Ii;Lt.fromByteArray=to;var H=[],F=[],Xi=typeof Uint8Array<"u"?Uint8Array:Array,qe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(at=0,Pr=qe.length;at<Pr;++at)H[at]=qe[at],F[qe.charCodeAt(at)]=at;var at,Pr;F[45]=62;F[95]=63;function Br(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function Qi(t){var e=Br(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Zi(t,e,r){return(e+r)*3/4-r}function Ii(t){var e,r=Br(t),n=r[0],i=r[1],o=new Xi(Zi(t,n,i)),s=0,a=i>0?n-4:n,l;for(l=0;l<a;l+=4)e=F[t.charCodeAt(l)]<<18|F[t.charCodeAt(l+1)]<<12|F[t.charCodeAt(l+2)]<<6|F[t.charCodeAt(l+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=F[t.charCodeAt(l)]<<2|F[t.charCodeAt(l+1)]>>4,o[s++]=e&255),i===1&&(e=F[t.charCodeAt(l)]<<10|F[t.charCodeAt(l+1)]<<4|F[t.charCodeAt(l+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Di(t){return H[t>>18&63]+H[t>>12&63]+H[t>>6&63]+H[t&63]}function Li(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(Di(n));return i.join("")}function to(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(Li(t,s,s+o>a?a:s+o));return n===1?(e=t[r-1],i.push(H[e>>2]+H[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(H[e>>10]+H[e>>4&63]+H[e<<2&63]+"=")),i.join("")}});var Qr=Nr(gt=>{"use strict";var He=Ur(),yt=Gi(),kr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;gt.Buffer=c;gt.SlowBuffer=so;gt.INSPECT_MAX_BYTES=50;var te=2147483647;gt.kMaxLength=te;c.TYPED_ARRAY_SUPPORT=eo();!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function eo(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}});Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function X(t){if(t>te)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,c.prototype),e}function c(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Ye(t)}return Kr(t,e,r)}c.poolSize=8192;function Kr(t,e,r){if(typeof t=="string")return no(t,e);if(ArrayBuffer.isView(t))return io(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(J(t,ArrayBuffer)||t&&J(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(J(t,SharedArrayBuffer)||t&&J(t.buffer,SharedArrayBuffer)))return We(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return c.from(n,e,r);let i=oo(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return c.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}c.from=function(t,e,r){return Kr(t,e,r)};Object.setPrototypeOf(c.prototype,Uint8Array.prototype);Object.setPrototypeOf(c,Uint8Array);function jr(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function ro(t,e,r){return jr(t),t<=0?X(t):e!==void 0?typeof r=="string"?X(t).fill(e,r):X(t).fill(e):X(t)}c.alloc=function(t,e,r){return ro(t,e,r)};function Ye(t){return jr(t),X(t<0?0:ze(t)|0)}c.allocUnsafe=function(t){return Ye(t)};c.allocUnsafeSlow=function(t){return Ye(t)};function no(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!c.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=Mr(t,e)|0,n=X(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function Je(t){let e=t.length<0?0:ze(t.length)|0,r=X(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function io(t){if(J(t,Uint8Array)){let e=new Uint8Array(t);return We(e.buffer,e.byteOffset,e.byteLength)}return Je(t)}function We(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,c.prototype),n}function oo(t){if(c.isBuffer(t)){let e=ze(t.length)|0,r=X(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||Qe(t.length)?X(0):Je(t);if(t.type==="Buffer"&&Array.isArray(t.data))return Je(t.data)}function ze(t){if(t>=te)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+te.toString(16)+" bytes");return t|0}function so(t){return+t!=t&&(t=0),c.alloc(+t)}c.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==c.prototype};c.compare=function(e,r){if(J(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),J(r,Uint8Array)&&(r=c.from(r,r.offset,r.byteLength)),!c.isBuffer(e)||!c.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};c.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return c.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=c.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let s=e[n];if(J(s,Uint8Array))o+s.length>i.length?(c.isBuffer(s)||(s=c.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(c.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Mr(t,e){if(c.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||J(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Ge(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Xr(t).length;default:if(i)return n?-1:Ge(t).length;e=(""+e).toLowerCase(),i=!0}}c.byteLength=Mr;function ao(t,e,r){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return go(this,e,r);case"utf8":case"utf-8":return qr(this,e,r);case"ascii":return yo(this,e,r);case"latin1":case"binary":return _o(this,e,r);case"base64":return mo(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return wo(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}c.prototype._isBuffer=!0;function ct(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}c.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)ct(this,r,r+1);return this};c.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)ct(this,r,r+3),ct(this,r+1,r+2);return this};c.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)ct(this,r,r+7),ct(this,r+1,r+6),ct(this,r+2,r+5),ct(this,r+3,r+4);return this};c.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?qr(this,0,e):ao.apply(this,arguments)};c.prototype.toLocaleString=c.prototype.toString;c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:c.compare(this,e)===0};c.prototype.inspect=function(){let e="",r=gt.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};kr&&(c.prototype[kr]=c.prototype.inspect);c.prototype.compare=function(e,r,n,i,o){if(J(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-r,l=Math.min(s,a),u=this.slice(i,o),p=e.slice(r,n);for(let d=0;d<l;++d)if(u[d]!==p[d]){s=u[d],a=p[d];break}return s<a?-1:a<s?1:0};function $r(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,Qe(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=c.from(e,n)),c.isBuffer(e))return e.length===0?-1:Fr(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):Fr(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Fr(t,e,r,n,i){let o=1,s=t.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,a/=2,r/=2}function l(p,d){return o===1?p[d]:p.readUInt16BE(d*o)}let u;if(i){let p=-1;for(u=r;u<s;u++)if(l(t,u)===l(e,p===-1?0:u-p)){if(p===-1&&(p=u),u-p+1===a)return p*o}else p!==-1&&(u-=u-p),p=-1}else for(r+a>s&&(r=s-a),u=r;u>=0;u--){let p=!0;for(let d=0;d<a;d++)if(l(t,u+d)!==l(e,d)){p=!1;break}if(p)return u}return-1}c.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};c.prototype.indexOf=function(e,r,n){return $r(this,e,r,n,!0)};c.prototype.lastIndexOf=function(e,r,n){return $r(this,e,r,n,!1)};function co(t,e,r,n){r=Number(r)||0;let i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(Qe(a))return s;t[r+s]=a}return s}function lo(t,e,r,n){return ee(Ge(e,t.length-r),t,r,n)}function uo(t,e,r,n){return ee(Eo(e),t,r,n)}function po(t,e,r,n){return ee(Xr(e),t,r,n)}function fo(t,e,r,n){return ee(To(e,t.length-r),t,r,n)}c.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return co(this,e,r,n);case"utf8":case"utf-8":return lo(this,e,r,n);case"ascii":case"latin1":case"binary":return uo(this,e,r,n);case"base64":return po(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return fo(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function mo(t,e,r){return e===0&&r===t.length?He.fromByteArray(t):He.fromByteArray(t.slice(e,r))}function qr(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let o=t[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=r){let l,u,p,d;switch(a){case 1:o<128&&(s=o);break;case 2:l=t[i+1],(l&192)===128&&(d=(o&31)<<6|l&63,d>127&&(s=d));break;case 3:l=t[i+1],u=t[i+2],(l&192)===128&&(u&192)===128&&(d=(o&15)<<12|(l&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:l=t[i+1],u=t[i+2],p=t[i+3],(l&192)===128&&(u&192)===128&&(p&192)===128&&(d=(o&15)<<18|(l&63)<<12|(u&63)<<6|p&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return ho(n)}var Cr=4096;function ho(t){let e=t.length;if(e<=Cr)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Cr));return r}function yo(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function _o(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function go(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=e;o<r;++o)i+=No[t[o]];return i}function wo(t,e,r){let n=t.slice(e,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}c.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let i=this.subarray(e,r);return Object.setPrototypeOf(i,c.prototype),i};function N(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||N(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return i};c.prototype.readUintBE=c.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||N(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};c.prototype.readUint8=c.prototype.readUInt8=function(e,r){return e=e>>>0,r||N(e,1,this.length),this[e]};c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||N(e,2,this.length),this[e]|this[e+1]<<8};c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||N(e,2,this.length),this[e]<<8|this[e+1]};c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||N(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||N(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};c.prototype.readBigUInt64LE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Ut(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});c.prototype.readBigUInt64BE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Ut(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});c.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||N(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};c.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||N(e,r,this.length);let i=r,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};c.prototype.readInt8=function(e,r){return e=e>>>0,r||N(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};c.prototype.readInt16LE=function(e,r){e=e>>>0,r||N(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};c.prototype.readInt16BE=function(e,r){e=e>>>0,r||N(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};c.prototype.readInt32LE=function(e,r){return e=e>>>0,r||N(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};c.prototype.readInt32BE=function(e,r){return e=e>>>0,r||N(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};c.prototype.readBigInt64LE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Ut(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});c.prototype.readBigInt64BE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Ut(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});c.prototype.readFloatLE=function(e,r){return e=e>>>0,r||N(e,4,this.length),yt.read(this,e,!0,23,4)};c.prototype.readFloatBE=function(e,r){return e=e>>>0,r||N(e,4,this.length),yt.read(this,e,!1,23,4)};c.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||N(e,8,this.length),yt.read(this,e,!0,52,8)};c.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||N(e,8,this.length),yt.read(this,e,!1,52,8)};function U(t,e,r,n,i,o){if(!c.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;U(this,e,r,n,a,0)}let o=1,s=0;for(this[r]=e&255;++s<n&&(o*=256);)this[r+s]=e/o&255;return r+n};c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;U(this,e,r,n,a,0)}let o=n-1,s=1;for(this[r+o]=e&255;--o>=0&&(s*=256);)this[r+o]=e/s&255;return r+n};c.prototype.writeUint8=c.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,1,255,0),this[r]=e&255,r+1};c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function Hr(t,e,r,n,i){zr(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,r}function Jr(t,e,r,n,i){zr(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s=s>>8,t[r+2]=s,s=s>>8,t[r+1]=s,s=s>>8,t[r]=s,r+8}c.prototype.writeBigUInt64LE=L(function(e,r=0){return Hr(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeBigUInt64BE=L(function(e,r=0){return Jr(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);U(this,e,r,n,l-1,-l)}let o=0,s=1,a=0;for(this[r]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[r+o-1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};c.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);U(this,e,r,n,l-1,-l)}let o=n-1,s=1,a=0;for(this[r+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[r+o+1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};c.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};c.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};c.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};c.prototype.writeBigInt64LE=L(function(e,r=0){return Hr(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});c.prototype.writeBigInt64BE=L(function(e,r=0){return Jr(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Wr(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Gr(t,e,r,n,i){return e=+e,r=r>>>0,i||Wr(t,e,r,4,34028234663852886e22,-34028234663852886e22),yt.write(t,e,r,n,23,4),r+4}c.prototype.writeFloatLE=function(e,r,n){return Gr(this,e,r,!0,n)};c.prototype.writeFloatBE=function(e,r,n){return Gr(this,e,r,!1,n)};function Yr(t,e,r,n,i){return e=+e,r=r>>>0,i||Wr(t,e,r,8,17976931348623157e292,-17976931348623157e292),yt.write(t,e,r,n,52,8),r+8}c.prototype.writeDoubleLE=function(e,r,n){return Yr(this,e,r,!0,n)};c.prototype.writeDoubleBE=function(e,r,n){return Yr(this,e,r,!1,n)};c.prototype.copy=function(e,r,n,i){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};c.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!c.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=r;o<n;++o)this[o]=e;else{let s=c.isBuffer(e)?e:c.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=s[o%a]}return this};var ht={};function Xe(t,e,r){ht[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}Xe("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Xe("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);Xe("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=Vr(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=Vr(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Vr(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function xo(t,e,r){_t(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&Ut(e,t.length-(r+1))}function zr(t,e,r,n,i,o){if(t>r||t<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${r}${s}`,new ht.ERR_OUT_OF_RANGE("value",a,t)}xo(n,i,o)}function _t(t,e){if(typeof t!="number")throw new ht.ERR_INVALID_ARG_TYPE(e,"number",t)}function Ut(t,e,r){throw Math.floor(t)!==t?(_t(t,r),new ht.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new ht.ERR_BUFFER_OUT_OF_BOUNDS:new ht.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var bo=/[^+/0-9A-Za-z-_]/g;function Ao(t){if(t=t.split("=")[0],t=t.trim().replace(bo,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function Ge(t,e){e=e||1/0;let r,n=t.length,i=null,o=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function Eo(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function To(t,e){let r,n,i,o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Xr(t){return He.toByteArray(Ao(t))}function ee(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function J(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Qe(t){return t!==t}var No=function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function L(t){return typeof BigInt>"u"?Ro:t}function Ro(){throw new Error("BigInt not supported")}});var nn=Ve(Qr());var ne={};Wi(ne,{backoff:()=>Lr,chain:()=>tn,conditionalDelay:()=>Ir,defaultStrategy:()=>re,maxAttempts:()=>So,once:()=>Zr,throttle:()=>vo,timeout:()=>Dr});var Oo=5*60*1e3;function re(){return tn(Ir(Zr(),1e3),Lr(1e3,1.2),Dr(Oo))}function Zr(){let t=!0;return async()=>t?(t=!1,!0):!1}function Ir(t,e){return async(r,n,i)=>{if(await t(r,n,i))return new Promise(o=>setTimeout(o,e))}}function So(t){let e=t;return async(r,n,i)=>{if(--e<=0)throw new Error(`Failed to retrieve a reply for request after ${t} attempts:
|
|
1
|
+
import{A as Zt,B as It,C as Me,D,E as Dt,F as $e,a as Nr,b as Wi,c as Ve,d as Gi,e as Rr,f as _,g as S,h as I,i as Or,j as Sr,k as vr,l as Xt,m as Ke,n as Bt,o as Yi,p as je,q as st,r as ft,s as zi,t as Qt,u as M,z as mt}from"./chunk-DCSQJUQP.js";var Ur=Nr(Lt=>{"use strict";Lt.byteLength=Qi;Lt.toByteArray=Ii;Lt.fromByteArray=to;var H=[],F=[],Xi=typeof Uint8Array<"u"?Uint8Array:Array,qe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(at=0,Pr=qe.length;at<Pr;++at)H[at]=qe[at],F[qe.charCodeAt(at)]=at;var at,Pr;F[45]=62;F[95]=63;function Br(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function Qi(t){var e=Br(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Zi(t,e,r){return(e+r)*3/4-r}function Ii(t){var e,r=Br(t),n=r[0],i=r[1],o=new Xi(Zi(t,n,i)),s=0,a=i>0?n-4:n,l;for(l=0;l<a;l+=4)e=F[t.charCodeAt(l)]<<18|F[t.charCodeAt(l+1)]<<12|F[t.charCodeAt(l+2)]<<6|F[t.charCodeAt(l+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=F[t.charCodeAt(l)]<<2|F[t.charCodeAt(l+1)]>>4,o[s++]=e&255),i===1&&(e=F[t.charCodeAt(l)]<<10|F[t.charCodeAt(l+1)]<<4|F[t.charCodeAt(l+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Di(t){return H[t>>18&63]+H[t>>12&63]+H[t>>6&63]+H[t&63]}function Li(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(Di(n));return i.join("")}function to(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(Li(t,s,s+o>a?a:s+o));return n===1?(e=t[r-1],i.push(H[e>>2]+H[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(H[e>>10]+H[e>>4&63]+H[e<<2&63]+"=")),i.join("")}});var Qr=Nr(gt=>{"use strict";var He=Ur(),yt=Gi(),kr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;gt.Buffer=c;gt.SlowBuffer=so;gt.INSPECT_MAX_BYTES=50;var te=2147483647;gt.kMaxLength=te;c.TYPED_ARRAY_SUPPORT=eo();!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function eo(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}});Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function X(t){if(t>te)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,c.prototype),e}function c(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Ye(t)}return Kr(t,e,r)}c.poolSize=8192;function Kr(t,e,r){if(typeof t=="string")return no(t,e);if(ArrayBuffer.isView(t))return io(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(J(t,ArrayBuffer)||t&&J(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(J(t,SharedArrayBuffer)||t&&J(t.buffer,SharedArrayBuffer)))return We(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return c.from(n,e,r);let i=oo(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return c.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}c.from=function(t,e,r){return Kr(t,e,r)};Object.setPrototypeOf(c.prototype,Uint8Array.prototype);Object.setPrototypeOf(c,Uint8Array);function jr(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function ro(t,e,r){return jr(t),t<=0?X(t):e!==void 0?typeof r=="string"?X(t).fill(e,r):X(t).fill(e):X(t)}c.alloc=function(t,e,r){return ro(t,e,r)};function Ye(t){return jr(t),X(t<0?0:ze(t)|0)}c.allocUnsafe=function(t){return Ye(t)};c.allocUnsafeSlow=function(t){return Ye(t)};function no(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!c.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=Mr(t,e)|0,n=X(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function Je(t){let e=t.length<0?0:ze(t.length)|0,r=X(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function io(t){if(J(t,Uint8Array)){let e=new Uint8Array(t);return We(e.buffer,e.byteOffset,e.byteLength)}return Je(t)}function We(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,c.prototype),n}function oo(t){if(c.isBuffer(t)){let e=ze(t.length)|0,r=X(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||Qe(t.length)?X(0):Je(t);if(t.type==="Buffer"&&Array.isArray(t.data))return Je(t.data)}function ze(t){if(t>=te)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+te.toString(16)+" bytes");return t|0}function so(t){return+t!=t&&(t=0),c.alloc(+t)}c.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==c.prototype};c.compare=function(e,r){if(J(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),J(r,Uint8Array)&&(r=c.from(r,r.offset,r.byteLength)),!c.isBuffer(e)||!c.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};c.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return c.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=c.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let s=e[n];if(J(s,Uint8Array))o+s.length>i.length?(c.isBuffer(s)||(s=c.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(c.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Mr(t,e){if(c.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||J(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Ge(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Xr(t).length;default:if(i)return n?-1:Ge(t).length;e=(""+e).toLowerCase(),i=!0}}c.byteLength=Mr;function ao(t,e,r){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return go(this,e,r);case"utf8":case"utf-8":return qr(this,e,r);case"ascii":return yo(this,e,r);case"latin1":case"binary":return _o(this,e,r);case"base64":return mo(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return wo(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}c.prototype._isBuffer=!0;function ct(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}c.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)ct(this,r,r+1);return this};c.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)ct(this,r,r+3),ct(this,r+1,r+2);return this};c.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)ct(this,r,r+7),ct(this,r+1,r+6),ct(this,r+2,r+5),ct(this,r+3,r+4);return this};c.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?qr(this,0,e):ao.apply(this,arguments)};c.prototype.toLocaleString=c.prototype.toString;c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:c.compare(this,e)===0};c.prototype.inspect=function(){let e="",r=gt.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};kr&&(c.prototype[kr]=c.prototype.inspect);c.prototype.compare=function(e,r,n,i,o){if(J(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-r,l=Math.min(s,a),u=this.slice(i,o),p=e.slice(r,n);for(let d=0;d<l;++d)if(u[d]!==p[d]){s=u[d],a=p[d];break}return s<a?-1:a<s?1:0};function $r(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,Qe(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=c.from(e,n)),c.isBuffer(e))return e.length===0?-1:Fr(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):Fr(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Fr(t,e,r,n,i){let o=1,s=t.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,a/=2,r/=2}function l(p,d){return o===1?p[d]:p.readUInt16BE(d*o)}let u;if(i){let p=-1;for(u=r;u<s;u++)if(l(t,u)===l(e,p===-1?0:u-p)){if(p===-1&&(p=u),u-p+1===a)return p*o}else p!==-1&&(u-=u-p),p=-1}else for(r+a>s&&(r=s-a),u=r;u>=0;u--){let p=!0;for(let d=0;d<a;d++)if(l(t,u+d)!==l(e,d)){p=!1;break}if(p)return u}return-1}c.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};c.prototype.indexOf=function(e,r,n){return $r(this,e,r,n,!0)};c.prototype.lastIndexOf=function(e,r,n){return $r(this,e,r,n,!1)};function co(t,e,r,n){r=Number(r)||0;let i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(Qe(a))return s;t[r+s]=a}return s}function lo(t,e,r,n){return ee(Ge(e,t.length-r),t,r,n)}function uo(t,e,r,n){return ee(Eo(e),t,r,n)}function po(t,e,r,n){return ee(Xr(e),t,r,n)}function fo(t,e,r,n){return ee(To(e,t.length-r),t,r,n)}c.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return co(this,e,r,n);case"utf8":case"utf-8":return lo(this,e,r,n);case"ascii":case"latin1":case"binary":return uo(this,e,r,n);case"base64":return po(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return fo(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function mo(t,e,r){return e===0&&r===t.length?He.fromByteArray(t):He.fromByteArray(t.slice(e,r))}function qr(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let o=t[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=r){let l,u,p,d;switch(a){case 1:o<128&&(s=o);break;case 2:l=t[i+1],(l&192)===128&&(d=(o&31)<<6|l&63,d>127&&(s=d));break;case 3:l=t[i+1],u=t[i+2],(l&192)===128&&(u&192)===128&&(d=(o&15)<<12|(l&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:l=t[i+1],u=t[i+2],p=t[i+3],(l&192)===128&&(u&192)===128&&(p&192)===128&&(d=(o&15)<<18|(l&63)<<12|(u&63)<<6|p&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return ho(n)}var Cr=4096;function ho(t){let e=t.length;if(e<=Cr)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Cr));return r}function yo(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function _o(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function go(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=e;o<r;++o)i+=No[t[o]];return i}function wo(t,e,r){let n=t.slice(e,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}c.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let i=this.subarray(e,r);return Object.setPrototypeOf(i,c.prototype),i};function N(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||N(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return i};c.prototype.readUintBE=c.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||N(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};c.prototype.readUint8=c.prototype.readUInt8=function(e,r){return e=e>>>0,r||N(e,1,this.length),this[e]};c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||N(e,2,this.length),this[e]|this[e+1]<<8};c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||N(e,2,this.length),this[e]<<8|this[e+1]};c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||N(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||N(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};c.prototype.readBigUInt64LE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Ut(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});c.prototype.readBigUInt64BE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Ut(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});c.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||N(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};c.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||N(e,r,this.length);let i=r,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};c.prototype.readInt8=function(e,r){return e=e>>>0,r||N(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};c.prototype.readInt16LE=function(e,r){e=e>>>0,r||N(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};c.prototype.readInt16BE=function(e,r){e=e>>>0,r||N(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};c.prototype.readInt32LE=function(e,r){return e=e>>>0,r||N(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};c.prototype.readInt32BE=function(e,r){return e=e>>>0,r||N(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};c.prototype.readBigInt64LE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Ut(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});c.prototype.readBigInt64BE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Ut(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});c.prototype.readFloatLE=function(e,r){return e=e>>>0,r||N(e,4,this.length),yt.read(this,e,!0,23,4)};c.prototype.readFloatBE=function(e,r){return e=e>>>0,r||N(e,4,this.length),yt.read(this,e,!1,23,4)};c.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||N(e,8,this.length),yt.read(this,e,!0,52,8)};c.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||N(e,8,this.length),yt.read(this,e,!1,52,8)};function U(t,e,r,n,i,o){if(!c.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;U(this,e,r,n,a,0)}let o=1,s=0;for(this[r]=e&255;++s<n&&(o*=256);)this[r+s]=e/o&255;return r+n};c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;U(this,e,r,n,a,0)}let o=n-1,s=1;for(this[r+o]=e&255;--o>=0&&(s*=256);)this[r+o]=e/s&255;return r+n};c.prototype.writeUint8=c.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,1,255,0),this[r]=e&255,r+1};c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function Hr(t,e,r,n,i){zr(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,r}function Jr(t,e,r,n,i){zr(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s=s>>8,t[r+2]=s,s=s>>8,t[r+1]=s,s=s>>8,t[r]=s,r+8}c.prototype.writeBigUInt64LE=L(function(e,r=0){return Hr(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeBigUInt64BE=L(function(e,r=0){return Jr(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);U(this,e,r,n,l-1,-l)}let o=0,s=1,a=0;for(this[r]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[r+o-1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};c.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);U(this,e,r,n,l-1,-l)}let o=n-1,s=1,a=0;for(this[r+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[r+o+1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};c.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};c.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};c.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||U(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};c.prototype.writeBigInt64LE=L(function(e,r=0){return Hr(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});c.prototype.writeBigInt64BE=L(function(e,r=0){return Jr(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Wr(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Gr(t,e,r,n,i){return e=+e,r=r>>>0,i||Wr(t,e,r,4,34028234663852886e22,-34028234663852886e22),yt.write(t,e,r,n,23,4),r+4}c.prototype.writeFloatLE=function(e,r,n){return Gr(this,e,r,!0,n)};c.prototype.writeFloatBE=function(e,r,n){return Gr(this,e,r,!1,n)};function Yr(t,e,r,n,i){return e=+e,r=r>>>0,i||Wr(t,e,r,8,17976931348623157e292,-17976931348623157e292),yt.write(t,e,r,n,52,8),r+8}c.prototype.writeDoubleLE=function(e,r,n){return Yr(this,e,r,!0,n)};c.prototype.writeDoubleBE=function(e,r,n){return Yr(this,e,r,!1,n)};c.prototype.copy=function(e,r,n,i){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};c.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!c.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=r;o<n;++o)this[o]=e;else{let s=c.isBuffer(e)?e:c.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=s[o%a]}return this};var ht={};function Xe(t,e,r){ht[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}Xe("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Xe("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);Xe("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=Vr(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=Vr(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Vr(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function xo(t,e,r){_t(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&Ut(e,t.length-(r+1))}function zr(t,e,r,n,i,o){if(t>r||t<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${r}${s}`,new ht.ERR_OUT_OF_RANGE("value",a,t)}xo(n,i,o)}function _t(t,e){if(typeof t!="number")throw new ht.ERR_INVALID_ARG_TYPE(e,"number",t)}function Ut(t,e,r){throw Math.floor(t)!==t?(_t(t,r),new ht.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new ht.ERR_BUFFER_OUT_OF_BOUNDS:new ht.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var bo=/[^+/0-9A-Za-z-_]/g;function Ao(t){if(t=t.split("=")[0],t=t.trim().replace(bo,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function Ge(t,e){e=e||1/0;let r,n=t.length,i=null,o=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function Eo(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function To(t,e){let r,n,i,o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Xr(t){return He.toByteArray(Ao(t))}function ee(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function J(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Qe(t){return t!==t}var No=function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function L(t){return typeof BigInt>"u"?Ro:t}function Ro(){throw new Error("BigInt not supported")}});var nn=Ve(Qr());var ne={};Wi(ne,{backoff:()=>Lr,chain:()=>tn,conditionalDelay:()=>Ir,defaultStrategy:()=>re,maxAttempts:()=>So,once:()=>Zr,throttle:()=>vo,timeout:()=>Dr});var Oo=5*60*1e3;function re(){return tn(Ir(Zr(),1e3),Lr(1e3,1.2),Dr(Oo))}function Zr(){let t=!0;return async()=>t?(t=!1,!0):!1}function Ir(t,e){return async(r,n,i)=>{if(await t(r,n,i))return new Promise(o=>setTimeout(o,e))}}function So(t){let e=t;return async(r,n,i)=>{if(--e<=0)throw new Error(`Failed to retrieve a reply for request after ${t} attempts:
|
|
2
2
|
Request ID: ${S(n)}
|
|
3
3
|
Request status: ${i}
|
|
4
4
|
`)}}function vo(t){return()=>new Promise(e=>setTimeout(e,t))}function Dr(t){let e=Date.now()+t;return async(r,n,i)=>{if(Date.now()>e)throw new Error(`Request timed out after ${t} msec:
|
|
@@ -12,7 +12,7 @@ import{A as Zt,B as It,C as Me,D,E as Dt,F as $e,a as Nr,b as Wi,c as Ve,d as Gi
|
|
|
12
12
|
Request ID: ${S(r)}
|
|
13
13
|
`)}throw new Error("unreachable")}var en=({IDL:t})=>{let e=t.Variant({mainnet:t.Null,testnet:t.Null}),r=t.Text,n=t.Record({network:e,address:r,min_confirmations:t.Opt(t.Nat32)}),i=t.Nat64,o=i,s=t.Nat32,a=t.Record({start_height:s,end_height:t.Opt(s),network:e}),l=t.Vec(t.Nat8),u=t.Record({tip_height:s,block_headers:t.Vec(l)}),p=t.Record({network:e}),d=t.Nat64,f=t.Vec(d),y=t.Record({network:e,filter:t.Opt(t.Variant({page:t.Vec(t.Nat8),min_confirmations:t.Nat32})),address:r}),x=t.Vec(t.Nat8),v=t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32}),k=t.Record({height:t.Nat32,value:i,outpoint:v}),g=t.Record({next_page:t.Opt(t.Vec(t.Nat8)),tip_height:s,tip_block_hash:x,utxos:t.Vec(k)}),E=t.Record({transaction:t.Vec(t.Nat8),network:e}),m=t.Principal,P=t.Record({canister_id:m,num_requested_changes:t.Opt(t.Nat64)}),O=t.Variant({from_user:t.Record({user_id:t.Principal}),from_canister:t.Record({canister_version:t.Opt(t.Nat64),canister_id:t.Principal})}),V=t.Vec(t.Nat8),dt=t.Variant({creation:t.Record({controllers:t.Vec(t.Principal)}),code_deployment:t.Record({mode:t.Variant({reinstall:t.Null,upgrade:t.Null,install:t.Null}),module_hash:t.Vec(t.Nat8)}),load_snapshot:t.Record({canister_version:t.Nat64,taken_at_timestamp:t.Nat64,snapshot_id:V}),controllers_change:t.Record({controllers:t.Vec(t.Principal)}),code_uninstall:t.Null}),pt=t.Record({timestamp_nanos:t.Nat64,canister_version:t.Nat64,origin:O,details:dt}),K=t.Record({controllers:t.Vec(t.Principal),module_hash:t.Opt(t.Vec(t.Nat8)),recent_changes:t.Vec(pt),total_num_changes:t.Nat64}),B=t.Record({canister_id:m}),j=t.Variant({controllers:t.Null,public:t.Null,allowed_viewers:t.Vec(t.Principal)}),it=t.Record({freezing_threshold:t.Nat,controllers:t.Vec(t.Principal),reserved_cycles_limit:t.Nat,log_visibility:j,wasm_memory_limit:t.Nat,memory_allocation:t.Nat,compute_allocation:t.Nat}),Z=t.Record({status:t.Variant({stopped:t.Null,stopping:t.Null,running:t.Null}),memory_size:t.Nat,cycles:t.Nat,settings:it,query_stats:t.Record({response_payload_bytes_total:t.Nat,num_instructions_total:t.Nat,num_calls_total:t.Nat,request_payload_bytes_total:t.Nat}),idle_cycles_burned_per_day:t.Nat,module_hash:t.Opt(t.Vec(t.Nat8)),reserved_cycles:t.Nat}),ot=t.Record({canister_id:m}),z=t.Record({freezing_threshold:t.Opt(t.Nat),controllers:t.Opt(t.Vec(t.Principal)),reserved_cycles_limit:t.Opt(t.Nat),log_visibility:t.Opt(j),wasm_memory_limit:t.Opt(t.Nat),memory_allocation:t.Opt(t.Nat),compute_allocation:t.Opt(t.Nat)}),Re=t.Record({settings:t.Opt(z),sender_canister_version:t.Opt(t.Nat64)}),St=t.Record({canister_id:m}),Oe=t.Record({canister_id:m}),Se=t.Record({canister_id:m,snapshot_id:V}),ve=t.Record({canister_id:m}),Wt=t.Variant({secp256k1:t.Null}),Pe=t.Record({key_id:t.Record({name:t.Text,curve:Wt}),canister_id:t.Opt(m),derivation_path:t.Vec(t.Vec(t.Nat8))}),Be=t.Record({public_key:t.Vec(t.Nat8),chain_code:t.Vec(t.Nat8)}),Ue=t.Record({canister_id:m}),ke=t.Record({idx:t.Nat64,timestamp_nanos:t.Nat64,content:t.Vec(t.Nat8)}),Fe=t.Record({canister_log_records:t.Vec(ke)}),Gt=t.Record({value:t.Text,name:t.Text}),vt=t.Record({status:t.Nat,body:t.Vec(t.Nat8),headers:t.Vec(Gt)}),Yt=t.Record({url:t.Text,method:t.Variant({get:t.Null,head:t.Null,post:t.Null}),max_response_bytes:t.Opt(t.Nat64),body:t.Opt(t.Vec(t.Nat8)),transform:t.Opt(t.Record({function:t.Func([t.Record({context:t.Vec(t.Nat8),response:vt})],[vt],["query"]),context:t.Vec(t.Nat8)})),headers:t.Vec(Gt)}),zt=t.Variant({reinstall:t.Null,upgrade:t.Opt(t.Record({wasm_memory_persistence:t.Opt(t.Variant({keep:t.Null,replace:t.Null})),skip_pre_upgrade:t.Opt(t.Bool)})),install:t.Null}),Pt=t.Record({hash:t.Vec(t.Nat8)}),Ce=t.Record({arg:t.Vec(t.Nat8),wasm_module_hash:t.Vec(t.Nat8),mode:zt,chunk_hashes_list:t.Vec(Pt),target_canister:m,store_canister:t.Opt(m),sender_canister_version:t.Opt(t.Nat64)}),fi=t.Vec(t.Nat8),mi=t.Record({arg:t.Vec(t.Nat8),wasm_module:fi,mode:zt,canister_id:m,sender_canister_version:t.Opt(t.Nat64)}),hi=t.Record({canister_id:m}),Er=t.Record({id:V,total_size:t.Nat64,taken_at_timestamp:t.Nat64}),yi=t.Vec(Er),_i=t.Record({canister_id:m,sender_canister_version:t.Opt(t.Nat64),snapshot_id:V}),gi=t.Record({start_at_timestamp_nanos:t.Nat64,subnet_id:t.Principal}),wi=t.Record({num_block_failures_total:t.Nat64,node_id:t.Principal,num_blocks_proposed_total:t.Nat64}),xi=t.Vec(t.Record({timestamp_nanos:t.Nat64,node_metrics:t.Vec(wi)})),bi=t.Record({settings:t.Opt(z),specified_id:t.Opt(m),amount:t.Opt(t.Nat),sender_canister_version:t.Opt(t.Nat64)}),Ai=t.Record({canister_id:m}),Ei=t.Record({canister_id:m,amount:t.Nat}),Ti=t.Vec(t.Nat8),Tr=t.Variant({ed25519:t.Null,bip340secp256k1:t.Null}),Ni=t.Record({key_id:t.Record({algorithm:Tr,name:t.Text}),canister_id:t.Opt(m),derivation_path:t.Vec(t.Vec(t.Nat8))}),Ri=t.Record({public_key:t.Vec(t.Nat8),chain_code:t.Vec(t.Nat8)}),Oi=t.Record({key_id:t.Record({name:t.Text,curve:Wt}),derivation_path:t.Vec(t.Vec(t.Nat8)),message_hash:t.Vec(t.Nat8)}),Si=t.Record({signature:t.Vec(t.Nat8)}),vi=t.Variant({bip341:t.Record({merkle_root_hash:t.Vec(t.Nat8)})}),Pi=t.Record({aux:t.Opt(vi),key_id:t.Record({algorithm:Tr,name:t.Text}),derivation_path:t.Vec(t.Vec(t.Nat8)),message:t.Vec(t.Nat8)}),Bi=t.Record({signature:t.Vec(t.Nat8)}),Ui=t.Record({canister_id:m}),ki=t.Record({canister_id:m}),Fi=t.Record({canister_id:m}),Ci=t.Vec(Pt),Vi=t.Record({subnet_id:t.Principal}),Ki=t.Record({replica_version:t.Text}),ji=t.Record({replace_snapshot:t.Opt(V),canister_id:m}),Mi=Er,$i=t.Record({canister_id:m,sender_canister_version:t.Opt(t.Nat64)}),qi=t.Record({canister_id:t.Principal,settings:z,sender_canister_version:t.Opt(t.Nat64)}),Hi=t.Record({chunk:t.Vec(t.Nat8),canister_id:t.Principal}),Ji=Pt;return t.Service({bitcoin_get_balance:t.Func([n],[o],[]),bitcoin_get_block_headers:t.Func([a],[u],[]),bitcoin_get_current_fee_percentiles:t.Func([p],[f],[]),bitcoin_get_utxos:t.Func([y],[g],[]),bitcoin_send_transaction:t.Func([E],[],[]),canister_info:t.Func([P],[K],[]),canister_status:t.Func([B],[Z],[]),clear_chunk_store:t.Func([ot],[],[]),create_canister:t.Func([Re],[St],[]),delete_canister:t.Func([Oe],[],[]),delete_canister_snapshot:t.Func([Se],[],[]),deposit_cycles:t.Func([ve],[],[]),ecdsa_public_key:t.Func([Pe],[Be],[]),fetch_canister_logs:t.Func([Ue],[Fe],["query"]),http_request:t.Func([Yt],[vt],[]),install_chunked_code:t.Func([Ce],[],[]),install_code:t.Func([mi],[],[]),list_canister_snapshots:t.Func([hi],[yi],[]),load_canister_snapshot:t.Func([_i],[],[]),node_metrics_history:t.Func([gi],[xi],[]),provisional_create_canister_with_cycles:t.Func([bi],[Ai],[]),provisional_top_up_canister:t.Func([Ei],[],[]),raw_rand:t.Func([],[Ti],[]),schnorr_public_key:t.Func([Ni],[Ri],[]),sign_with_ecdsa:t.Func([Oi],[Si],[]),sign_with_schnorr:t.Func([Pi],[Bi],[]),start_canister:t.Func([Ui],[],[]),stop_canister:t.Func([ki],[],[]),stored_chunks:t.Func([Fi],[Ci],[]),subnet_info:t.Func([Vi],[Ki],[]),take_canister_snapshot:t.Func([ji],[Mi],[]),uninstall_code:t.Func([$i],[],[]),update_settings:t.Func([qi],[],[]),upload_chunk:t.Func([Hi],[Ji],[])})};var ie=class extends Xt{constructor(e,r,n,i){super(["Call failed:",` Canister: ${e.toText()}`,` Method: ${r} (${n})`,...Object.getOwnPropertyNames(i).map(o=>` "${o}": ${JSON.stringify(i[o])}`)].join(`
|
|
14
14
|
`)),this.canisterId=e,this.methodName=r,this.type=n,this.props=i}},Ie=class extends ie{constructor(e,r,n){var i;super(e,r,"query",{Status:n.status,Code:(i=Rr[n.reject_code])!==null&&i!==void 0?i:`Unknown Code "${n.reject_code}"`,Message:n.reject_message}),this.result=n}},oe=class extends ie{constructor(e,r,n,i,o,s,a){super(e,r,"update",Object.assign({"Request ID":S(n)},i.body?Object.assign(Object.assign({},a?{"Error code":a}:{}),{"Reject code":String(o),"Reject message":s}):{"HTTP status code":i.status.toString(),"HTTP status text":i.statusText})),this.requestId=n,this.response=i,this.reject_code=o,this.reject_message=s,this.error_code=a}},C=Symbol.for("ic-agent-metadata"),tt=class t{constructor(e){this[C]=Object.freeze(e)}static agentOf(e){return e[C].config.agent}static interfaceOf(e){return e[C].service}static canisterIdOf(e){return _.from(e[C].config.canisterId)}static async install(e,r){let n=e.mode===void 0?{install:null}:e.mode,i=e.arg?[...new Uint8Array(e.arg)]:[],o=[...new Uint8Array(e.module)],s=typeof r.canisterId=="string"?_.fromText(r.canisterId):r.canisterId;await rn(r).install_code({mode:n,arg:i,wasm_module:o,canister_id:s,sender_canister_version:[]})}static async createCanister(e,r){function n(o){return[{controllers:o.controllers?[o.controllers]:[],compute_allocation:o.compute_allocation?[o.compute_allocation]:[],freezing_threshold:o.freezing_threshold?[o.freezing_threshold]:[],memory_allocation:o.memory_allocation?[o.memory_allocation]:[],reserved_cycles_limit:[],log_visibility:[],wasm_memory_limit:[]}]}let{canister_id:i}=await rn(e||{}).provisional_create_canister_with_cycles({amount:[],settings:n(r||{}),specified_id:[],sender_canister_version:[]});return i}static async createAndInstallCanister(e,r,n){let i=await this.createCanister(n);return await this.install(Object.assign({},r),Object.assign(Object.assign({},n),{canisterId:i})),this.createActor(e,Object.assign(Object.assign({},n),{canisterId:i}))}static createActorClass(e,r){let n=e({IDL:Bt});class i extends t{constructor(s){if(!s.canisterId)throw new Xt(`Canister ID is required, but received ${typeof s.canisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`);let a=typeof s.canisterId=="string"?_.fromText(s.canisterId):s.canisterId;super({config:Object.assign(Object.assign(Object.assign({},on),s),{canisterId:a}),service:n});for(let[l,u]of n._fields)r?.httpDetails&&u.annotations.push(De),r?.certificate&&u.annotations.push(sn),this[l]=Bo(this,l,u,s.blsVerify)}}return i}static createActor(e,r){if(!r.canisterId)throw new Xt(`Canister ID is required, but received ${typeof r.canisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`);return new(this.createActorClass(e))(r)}static createActorWithHttpDetails(e,r){return new(this.createActorClass(e,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(e,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(e,n))(r)}};function wt(t,e){let r=Bt.decode(t,nn.Buffer.from(e));switch(r.length){case 0:return;case 1:return r[0];default:return r}}var on={pollingStrategyFactory:ne.defaultStrategy},De="http-details",sn="certificate";function Bo(t,e,r,n){let i;r.annotations.includes("query")||r.annotations.includes("composite_query")?i=async(s,...a)=>{var l,u;s=Object.assign(Object.assign({},s),(u=(l=t[C].config).queryTransform)===null||u===void 0?void 0:u.call(l,e,a,Object.assign(Object.assign({},t[C].config),s)));let p=s.agent||t[C].config.agent||$e(),d=_.from(s.canisterId||t[C].config.canisterId),f=Bt.encode(r.argTypes,a),y=await p.query(d,{methodName:e,arg:f,effectiveCanisterId:s.effectiveCanisterId}),x=Object.assign(Object.assign({},y.httpDetails),{requestDetails:y.requestDetails});switch(y.status){case"rejected":throw new Ie(d,e,y);case"replied":return r.annotations.includes(De)?{httpDetails:x,result:wt(r.retTypes,y.reply.arg)}:wt(r.retTypes,y.reply.arg)}}:i=async(s,...a)=>{var l,u;s=Object.assign(Object.assign({},s),(u=(l=t[C].config).callTransform)===null||u===void 0?void 0:u.call(l,e,a,Object.assign(Object.assign({},t[C].config),s)));let p=s.agent||t[C].config.agent||$e(),{canisterId:d,effectiveCanisterId:f,pollingStrategyFactory:y}=Object.assign(Object.assign(Object.assign({},on),t[C].config),s),x=_.from(d),v=f!==void 0?_.from(f):x,k=Bt.encode(r.argTypes,a),{requestId:g,response:E,requestDetails:m}=await p.call(x,{methodName:e,arg:k,effectiveCanisterId:v}),P,O;if(E.body&&E.body.certificate){if(p.rootKey==null)throw new Error("Agent is missing root key");let K=E.body.certificate;O=await Qt.create({certificate:Ke(K),rootKey:p.rootKey,canisterId:_.from(d),blsVerify:n});let B=[new TextEncoder().encode("request_status"),g];switch(new TextDecoder().decode(M(O.lookup([...B,"status"])))){case"replied":P=M(O.lookup([...B,"reply"]));break;case"rejected":{let it=new Uint8Array(M(O.lookup([...B,"reject_code"])))[0],Z=new TextDecoder().decode(M(O.lookup([...B,"reject_message"]))),ot=M(O.lookup([...B,"error_code"])),z=ot?new TextDecoder().decode(ot):void 0;throw new oe(x,e,g,E,it,Z,z)}}}else if(E.body&&"reject_message"in E.body){let{reject_code:K,reject_message:B,error_code:j}=E.body;throw new oe(x,e,g,E,K,B,j)}if(E.status===202){let K=y(),B=await Ze(p,v,g,K,n);O=B.certificate,P=B.reply}let V=r.annotations.includes(De),dt=r.annotations.includes(sn),pt=Object.assign(Object.assign({},E),{requestDetails:m});if(P!==void 0)return V&&dt?{httpDetails:pt,certificate:O,result:wt(r.retTypes,P)}:dt?{certificate:O,result:wt(r.retTypes,P)}:V?{httpDetails:pt,result:wt(r.retTypes,P)}:wt(r.retTypes,P);if(r.retTypes.length===0)return V?{httpDetails:E,result:void 0}:void 0;throw new Error(`Call was returned undefined, but type [${r.retTypes.join(",")}].`)};let o=(...s)=>i({},...s);return o.withOptions=s=>(...a)=>i(s,...a),o}function rn(t){function e(r,n){if(t.effectiveCanisterId)return{effectiveCanisterId:_.from(t.effectiveCanisterId)};let i=n[0],o=_.fromHex("");return i&&typeof i=="object"&&i.target_canister&&r==="install_chunked_code"&&(o=_.from(i.target_canister)),i&&typeof i=="object"&&i.canister_id&&(o=_.from(i.canister_id)),{effectiveCanisterId:o}}return tt.createActor(en,Object.assign(Object.assign(Object.assign({},t),{canisterId:_.fromHex("")}),{callTransform:e,queryTransform:e}))}var ko=(t=>(t[t.FractionalMoreThan8Decimals=0]="FractionalMoreThan8Decimals",t[t.InvalidFormat=1]="InvalidFormat",t[t.FractionalTooManyDecimals=2]="FractionalTooManyDecimals",t))(ko||{}),ca=BigInt(1e8);var h=t=>t==null,w=t=>!h(t);var Fo=class extends Error{},se=(t,e)=>{if(t==null)throw new Fo(e)};var an="abcdefghijklmnopqrstuvwxyz234567",kt=Object.create(null);for(let t=0;t<an.length;t++)kt[an[t]]=t;kt[0]=kt.o;kt[1]=kt.i;var da=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);var b=t=>w(t)?[t]:[],R=t=>t?.[0];var Le="__bigint__",tr="__principal__",er="__uint8array__",cn=(t,e)=>typeof e=="bigint"?{[Le]:`${e}`}:w(e)&&e instanceof _?{[tr]:e.toText()}:w(e)&&e instanceof Uint8Array?{[er]:Array.from(e)}:e,ln=(t,e)=>{let r=n=>e[n];return w(e)&&typeof e=="object"&&Le in e?BigInt(r(Le)):w(e)&&typeof e=="object"&&tr in e?_.fromText(r(tr)):w(e)&&typeof e=="object"&&er in e?Uint8Array.from(r(er)):e};var xt=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:r})=>r(e))}subscribe(e){let r=Symbol();return this.callbacks.push({id:r,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:n})=>n!==r)}};var Q=class t extends xt{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let r=super.subscribe(e);return e(this.authUser),r}reset(){this.authUser=null,this.populate(this.authUser)}};var rr=({message:t,detail:e})=>{let r=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(r)};var le=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},et=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},ae,ce,bt,At;function un(t){return t!==null&&typeof t=="object"}var lt=class t{constructor(e){if(ae.set(this,void 0),ce.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");le(this,ae,e,"f"),le(this,ce,t.derEncode(e),"f")}static from(e){if(typeof e=="string"){let r=I(e);return this.fromRaw(r)}else if(un(e)){let r=e;if(un(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(vr(n.buffer))}else{if(r instanceof ArrayBuffer)return this.fromRaw(r);if("rawKey"in r)return this.fromRaw(r.rawKey);if("derKey"in r)return this.fromDer(r.derKey);if("toDer"in r)return this.fromDer(r.toDer())}}throw new Error("Cannot construct Ed25519PublicKey from the provided key.")}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static derEncode(e){let r=It(e,Zt).buffer;return r.__derEncodedPublicKey__=void 0,r}static derDecode(e){let r=Me(e,Zt);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}get rawKey(){return et(this,ae,"f")}get derKey(){return et(this,ce,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};ae=new WeakMap,ce=new WeakMap;lt.RAW_KEY_LENGTH=32;var ut=class t extends st{constructor(e,r){super(),bt.set(this,void 0),At.set(this,void 0),le(this,bt,lt.from(e),"f"),le(this,At,new Uint8Array(r),"f")}static generate(e){if(e&&e.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");e||(e=mt.utils.randomPrivateKey()),Or(e,new Uint8Array(new Array(32).fill(0)))&&console.warn("Seed is all zeros. This is not a secure seed. Please provide a seed with sufficient entropy if this is a production environment.");let r=new Uint8Array(32);for(let i=0;i<32;i++)r[i]=new Uint8Array(e)[i];let n=mt.getPublicKey(r);return t.fromKeyPair(n,r)}static fromParsedJson(e){let[r,n]=e;return new t(lt.fromDer(I(r)),I(n))}static fromJSON(e){let r=JSON.parse(e);if(Array.isArray(r)){if(typeof r[0]=="string"&&typeof r[1]=="string")return this.fromParsedJson([r[0],r[1]]);throw new Error("Deserialization error: JSON must have at least 2 items.")}throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(e)}`)}static fromKeyPair(e,r){return new t(lt.fromRaw(e),r)}static fromSecretKey(e){let r=mt.getPublicKey(new Uint8Array(e));return t.fromKeyPair(r,e)}toJSON(){return[S(et(this,bt,"f").toDer()),S(et(this,At,"f"))]}getKeyPair(){return{secretKey:et(this,At,"f"),publicKey:et(this,bt,"f")}}getPublicKey(){return et(this,bt,"f")}async sign(e){let r=new Uint8Array(e),n=Sr(mt.sign(r,et(this,At,"f").slice(0,32)));return Object.defineProperty(n,"__signature__",{enumerable:!1,value:void 0}),n}static verify(e,r,n){let[i,o,s]=[e,r,n].map(a=>(typeof a=="string"&&(a=I(a)),a instanceof Uint8Array&&(a=a.buffer),new Uint8Array(a)));return mt.verify(o,i,s)}};bt=new WeakMap,At=new WeakMap;var nr=class t extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,t.prototype)}};function dn(t){if(typeof globalThis<"u"&&globalThis.crypto&&globalThis.crypto.subtle)return globalThis.crypto.subtle;if(t)return t;if(typeof crypto<"u"&&crypto.subtle)return crypto.subtle;throw new nr("Global crypto was not available and none was provided. Please inlcude a SubtleCrypto implementation. See https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto")}var Ft=class t extends st{constructor(e,r,n){super(),this._keyPair=e,this._derKey=r,this._subtleCrypto=n}static async generate(e){let{extractable:r=!1,keyUsages:n=["sign","verify"],subtleCrypto:i}=e??{},o=dn(i),s=await o.generateKey({name:"ECDSA",namedCurve:"P-256"},r,n),a=await o.exportKey("spki",s.publicKey);return new this(s,a,o)}static async fromKeyPair(e,r){let n=dn(r),i=await n.exportKey("spki",e.publicKey);return new t(e,i,n)}getKeyPair(){return this._keyPair}getPublicKey(){let e=this._derKey,r=Object.create(this._keyPair.publicKey);return r.toDer=function(){return e},r}async sign(e){let r={name:"ECDSA",hash:{name:"SHA-256"}};return await this._subtleCrypto.sign(r,this._keyPair.privateKey,e)}};var Et=Ve(zi());var Co=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},Ct=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},rt,ue=class{constructor(e){rt.set(this,void 0),Co(this,rt,e,"f")}get rawKey(){return Ct(this,rt,"f").rawKey}get derKey(){return Ct(this,rt,"f").derKey}toDer(){return Ct(this,rt,"f").toDer()}getPublicKey(){return Ct(this,rt,"f")}getPrincipal(){return _.from(Ct(this,rt,"f").rawKey)}transformRequest(){return Promise.reject("Not implemented. You are attempting to use a partial identity to sign calls, but this identity only has access to the public key.To sign calls, use a DelegationIdentity instead.")}};rt=new WeakMap;var Vo=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},Ko=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},jo=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},de,Mo=new TextEncoder().encode("ic-request-auth-delegation"),$o=new TextEncoder().encode(`
|
|
15
|
-
ic-request`);function ir(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return I(t)}var Tt=class{constructor(e,r,n){this.pubkey=e,this.expiration=r,this.targets=n}toCBOR(){return Et.value.map(Object.assign({pubkey:Et.value.bytes(this.pubkey),expiration:Et.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:Et.value.array(this.targets.map(e=>Et.value.bytes(e.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:S(this.pubkey)},this.targets&&{targets:this.targets.map(e=>e.toHex())})}};async function qo(t,e,r,n){let i=new Tt(e.toDer(),BigInt(+r)*BigInt(1e6),n),o=new Uint8Array([...Mo,...new Uint8Array(je(Object.assign({},i)))]),s=await t.sign(o);return{delegation:i,signature:s}}var Vt=class t{constructor(e,r){this.delegations=e,this.publicKey=r}static async create(e,r,n=new Date(Date.now()+15*60*1e3),i={}){var o,s;let a=await qo(e,r,n,i.targets);return new t([...((o=i.previous)===null||o===void 0?void 0:o.delegations)||[],a],((s=i.previous)===null||s===void 0?void 0:s.publicKey)||e.getPublicKey().toDer())}static fromJSON(e){let{publicKey:r,delegations:n}=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(n))throw new Error("Invalid delegations.");let i=n.map(o=>{let{delegation:s,signature:a}=o,{pubkey:l,expiration:u,targets:p}=s;if(p!==void 0&&!Array.isArray(p))throw new Error("Invalid targets.");return{delegation:new Tt(ir(l),BigInt("0x"+u),p&&p.map(d=>{if(typeof d!="string")throw new Error("Invalid target.");return _.fromHex(d)})),signature:ir(a)}});return new this(i,ir(r))}static fromDelegations(e,r){return new this(e,r)}toJSON(){return{delegations:this.delegations.map(e=>{let{delegation:r,signature:n}=e,{targets:i}=r;return{delegation:Object.assign({expiration:r.expiration.toString(16),pubkey:S(r.pubkey)},i&&{targets:i.map(o=>o.toHex())}),signature:S(n)}}),publicKey:S(this.publicKey)}}},Kt=class extends st{constructor(e,r){super(),this._inner=e,this._delegation=r}static fromDelegation(e,r){return new this(e,r)}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(e){return this._inner.sign(e)}async transformRequest(e){let{body:r}=e,n=jo(e,["body"]),i=await je(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_sig:await this.sign(new Uint8Array([...$o,...new Uint8Array(i)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}},jt=class t extends ue{constructor(e,r){super(e),de.set(this,void 0),Vo(this,de,r,"f")}get delegation(){return Ko(this,de,"f")}static fromDelegation(e,r){return new t(e,r)}};de=new WeakMap;function pn(t,e){for(let{delegation:i}of t.delegations)if(+new Date(Number(i.expiration/BigInt(1e6)))<=+Date.now())return!1;let r=[],n=e?.scope;n&&(Array.isArray(n)?r.push(...n.map(i=>typeof i=="string"?_.fromText(i):i)):r.push(typeof n=="string"?_.fromText(n):n));for(let i of r){let o=i.toText();for(let{delegation:s}of t.delegations){if(s.targets===void 0)continue;let a=!0;for(let l of s.targets)if(l.toText()===o){a=!1;break}if(a)return!1}}return!0}var Jo=Ve(Yi());var fn;(function(t){t[t.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(fn||(fn={}));var mn=["mousedown","mousemove","keydown","touchstart","wheel"],Mt=class{constructor(e={}){var r;this.callbacks=[],this.idleTimeout=10*60*1e3,this.timeoutID=void 0;let{onIdle:n,idleTimeout:i=10*60*1e3}=e||{};this.callbacks=n?[n]:[],this.idleTimeout=i;let o=this._resetTimer.bind(this);window.addEventListener("load",o,!0),mn.forEach(function(a){document.addEventListener(a,o,!0)});let s=(a,l)=>{let u;return(...p)=>{let d=this,f=function(){u=void 0,a.apply(d,p)};clearTimeout(u),u=window.setTimeout(f,l)}};if(e?.captureScroll){let a=s(o,(r=e?.scrollDebounce)!==null&&r!==void 0?r:100);window.addEventListener("scroll",a,!0)}o()}static create(e={}){return new this(e)}registerCallback(e){this.callbacks.push(e)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let e=this._resetTimer.bind(this);mn.forEach(function(r){document.removeEventListener(r,e,!0)}),this.callbacks.forEach(r=>r())}_resetTimer(){let e=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(e,this.idleTimeout)}};var Wo=(t,e)=>e.some(r=>t instanceof r),hn,yn;function Go(){return hn||(hn=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Yo(){return yn||(yn=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var _n=new WeakMap,sr=new WeakMap,gn=new WeakMap,or=new WeakMap,cr=new WeakMap;function zo(t){let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("success",o),t.removeEventListener("error",s)},o=()=>{r(W(t.result)),i()},s=()=>{n(t.error),i()};t.addEventListener("success",o),t.addEventListener("error",s)});return e.then(r=>{r instanceof IDBCursor&&_n.set(r,t)}).catch(()=>{}),cr.set(e,t),e}function Xo(t){if(sr.has(t))return;let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("complete",o),t.removeEventListener("error",s),t.removeEventListener("abort",s)},o=()=>{r(),i()},s=()=>{n(t.error||new DOMException("AbortError","AbortError")),i()};t.addEventListener("complete",o),t.addEventListener("error",s),t.addEventListener("abort",s)});sr.set(t,e)}var ar={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return sr.get(t);if(e==="objectStoreNames")return t.objectStoreNames||gn.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return W(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function wn(t){ar=t(ar)}function Qo(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(pe(this),e,...r);return gn.set(n,e.sort?e.sort():[e]),W(n)}:Yo().includes(t)?function(...e){return t.apply(pe(this),e),W(_n.get(this))}:function(...e){return W(t.apply(pe(this),e))}}function Zo(t){return typeof t=="function"?Qo(t):(t instanceof IDBTransaction&&Xo(t),Wo(t,Go())?new Proxy(t,ar):t)}function W(t){if(t instanceof IDBRequest)return zo(t);if(or.has(t))return or.get(t);let e=Zo(t);return e!==t&&(or.set(t,e),cr.set(e,t)),e}var pe=t=>cr.get(t);function bn(t,e,{blocked:r,upgrade:n,blocking:i,terminated:o}={}){let s=indexedDB.open(t,e),a=W(s);return n&&s.addEventListener("upgradeneeded",l=>{n(W(s.result),l.oldVersion,l.newVersion,W(s.transaction),l)}),r&&s.addEventListener("blocked",l=>r(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),i&&l.addEventListener("versionchange",u=>i(u.oldVersion,u.newVersion,u))}).catch(()=>{}),a}var Io=["get","getKey","getAll","getAllKeys","count"],Do=["put","add","delete","clear"],lr=new Map;function xn(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(lr.get(e))return lr.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,i=Do.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(i||Io.includes(r)))return;let o=async function(s,...a){let l=this.transaction(s,i?"readwrite":"readonly"),u=l.store;return n&&(u=u.index(a.shift())),(await Promise.all([u[r](...a),i&&l.done]))[0]};return lr.set(e,o),o}wn(t=>({...t,get:(e,r,n)=>xn(e,r)||t.get(e,r,n),has:(e,r)=>!!xn(e,r)||t.has(e,r)}));var An="auth-client-db",En="ic-keyval",Lo=async(t=An,e=En,r)=>(fe&&(localStorage!=null&&localStorage.getItem($))&&(localStorage.removeItem($),localStorage.removeItem(q)),await bn(t,r,{upgrade:n=>{n.objectStoreNames.contains(e)&&n.clear(e),n.createObjectStore(e)}}));async function ts(t,e,r){return await t.get(e,r)}async function es(t,e,r,n){return await t.put(e,n,r)}async function rs(t,e,r){return await t.delete(e,r)}var $t=class t{constructor(e,r){this._db=e,this._storeName=r}static async create(e){let{dbName:r=An,storeName:n=En,version:i=Tn}=e??{},o=await Lo(r,n,i);return new t(o,n)}async set(e,r){return await es(this._db,this._storeName,e,r)}async get(e){var r;return(r=await ts(this._db,this._storeName,e))!==null&&r!==void 0?r:null}async remove(e){return await rs(this._db,this._storeName,e)}};var ns=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},is=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},me,q="identity",$="delegation",Nn="iv",Tn=1,fe=typeof window<"u",qt=class{constructor(e="ic-",r){this.prefix=e,this._localStorage=r}get(e){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+e))}set(e,r){return this._getLocalStorage().setItem(this.prefix+e,r),Promise.resolve()}remove(e){return this._getLocalStorage().removeItem(this.prefix+e),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let e=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.localStorage:globalThis.localStorage:window.localStorage;if(!e)throw new Error("Could not find local storage.");return e}},Ht=class{constructor(e){me.set(this,void 0),ns(this,me,e??{},"f")}get _db(){return new Promise(e=>{if(this.initializedDb){e(this.initializedDb);return}$t.create(is(this,me,"f")).then(r=>{this.initializedDb=r,e(r)})})}async get(e){return await(await this._db).get(e)}async set(e,r){await(await this._db).set(e,r)}async remove(e){await(await this._db).remove(e)}};me=new WeakMap;var os="https://identity.ic0.app",ss="#authorize",ur="ECDSA",dr="Ed25519",as=500,fr="UserInterrupt",he=class{constructor(e,r,n,i,o,s,a,l){this._identity=e,this._key=r,this._chain=n,this._storage=i,this.idleManager=o,this._createOptions=s,this._idpWindow=a,this._eventHandler=l,this._registerDefaultIdleCallback()}static async create(e={}){var r,n,i;let o=(r=e.storage)!==null&&r!==void 0?r:new Ht,s=(n=e.keyType)!==null&&n!==void 0?n:ur,a=null;if(e.identity)a=e.identity;else{let d=await o.get(q);if(!d&&fe)try{let f=new qt,y=await f.get($),x=await f.get(q);y&&x&&s===ur&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await o.set($,y),await o.set(q,x),d=y,await f.remove($),await f.remove(q))}catch(f){console.error("error while attempting to recover localstorage: "+f)}if(d)try{typeof d=="object"?s===dr&&typeof d=="string"?a=await ut.fromJSON(d):a=await Ft.fromKeyPair(d):typeof d=="string"&&(a=ut.fromJSON(d))}catch{}}let l=new ft,u=null;if(a)try{let d=await o.get($);if(typeof d=="object"&&d!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?l=e.identity:d&&(u=Vt.fromJSON(d),pn(u)?"toDer"in a?l=jt.fromDelegation(a,u):l=Kt.fromDelegation(a,u):(await pr(o),a=null))}catch(d){console.error(d),await pr(o),a=null}let p;return!((i=e.idleOptions)===null||i===void 0)&&i.disableIdle?p=void 0:(u||e.identity)&&(p=Mt.create(e.idleOptions)),a||(s===dr?(a=await ut.generate(),await o.set(q,JSON.stringify(a.toJSON()))):(e.storage&&s===ur&&console.warn(`You are using a custom storage provider that may not support CryptoKey storage. If you are using a custom storage provider that does not support CryptoKey storage, you should use '${dr}' as the key type, as it can serialize to a string`),a=await Ft.generate(),await o.set(q,a.getKeyPair()))),new this(l,a,u,o,p,e)}_registerDefaultIdleCallback(){var e,r;let n=(e=this._createOptions)===null||e===void 0?void 0:e.idleOptions;!n?.onIdle&&!n?.disableDefaultIdleCallback&&((r=this.idleManager)===null||r===void 0||r.registerCallback(()=>{this.logout(),location.reload()}))}async _handleSuccess(e,r){var n,i;let o=e.delegations.map(u=>({delegation:new Tt(u.delegation.pubkey,u.delegation.expiration,u.delegation.targets),signature:u.signature.buffer})),s=Vt.fromDelegations(o,e.userPublicKey.buffer),a=this._key;if(!a)return;this._chain=s,"toDer"in a?this._identity=jt.fromDelegation(a,this._chain):this._identity=Kt.fromDelegation(a,this._chain),(n=this._idpWindow)===null||n===void 0||n.close();let l=(i=this._createOptions)===null||i===void 0?void 0:i.idleOptions;!this.idleManager&&!l?.disableIdle&&(this.idleManager=Mt.create(l),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set($,JSON.stringify(this._chain.toJSON())),r?.(e)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null}async login(e){var r,n,i,o;let s=BigInt(8)*BigInt(36e11),a=new URL(((r=e?.identityProvider)===null||r===void 0?void 0:r.toString())||os);a.hash=ss,(n=this._idpWindow)===null||n===void 0||n.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(a,Object.assign({maxTimeToLive:(i=e?.maxTimeToLive)!==null&&i!==void 0?i:s},e)),window.addEventListener("message",this._eventHandler),this._idpWindow=(o=window.open(a.toString(),"idpWindow",e?.windowOpenerFeatures))!==null&&o!==void 0?o:void 0;let l=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(fr,e?.onError):setTimeout(l,as))};l()}_getEventHandler(e,r){return async n=>{var i,o,s;if(n.origin!==e.origin)return;let a=n.data;switch(a.kind){case"authorize-ready":{let l=Object.assign({kind:"authorize-client",sessionPublicKey:new Uint8Array((i=this._key)===null||i===void 0?void 0:i.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,allowPinAuthentication:r?.allowPinAuthentication,derivationOrigin:(o=r?.derivationOrigin)===null||o===void 0?void 0:o.toString()},r?.customValues);(s=this._idpWindow)===null||s===void 0||s.postMessage(l,e.origin);break}case"authorize-client-success":try{await this._handleSuccess(a,r?.onSuccess)}catch(l){this._handleFailure(l.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(a.text,r?.onError);break;default:break}}}_handleFailure(e,r){var n;(n=this._idpWindow)===null||n===void 0||n.close(),r?.(e),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(e={}){if(await pr(this._storage),this._identity=new ft,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function pr(t){await t.remove(q),await t.remove($),await t.remove(Nn)}var Rn=BigInt(144e11),On=!1,Sn={width:576,height:576},vn={width:505,height:705},Pn="internetcomputer.org";var Nt="http://127.0.0.1:5987",Bn="rdmx6-jaaaa-aaaaa-aaadq-cai";var G=class t extends xt{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let r=super.subscribe(e);return e(this.env),r}};var Un=async t=>{let e=new Blob([JSON.stringify(t,cn)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},ye=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),ln)},_e=()=>typeof window<"u";var mr=({width:t,height:e})=>{if(!_e()||h(window)||h(window.top))return;let{top:{innerWidth:r,innerHeight:n}}=window,i=n/2+screenY-e/2,o=r/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${o}`};var ge=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let r=()=>{let n=G.getInstance().get()?.container;if(h(n)||n===!1)return`https://identity.${this.#t??Pn}`;let i=G.getInstance().get(),o=w(i)&&w(i?.internetIdentityId)?i.internetIdentityId:Bn,{host:s,protocol:a}=new URL(n===!0?Nt:n);return/apple/i.test(navigator?.vendor)?`${a}//${s}?canisterId=${o}`:`${a}//${o}.${s.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:mr(Sn)},identityProvider:r()}}},kn=class{#t;#e;constructor({appName:e,logoUrl:r}){this.#t=e,this.#e=r}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:mr(vn)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};var Rt=class t{static instance;#t=void 0;constructor(){}static getInstance(){return h(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...r}){let n=e.getPrincipal().toText();if(h(this.#t)||h(this.#t[n])){let i=await this.createAgent({identity:e,...r});return this.#t={...this.#t??{},[n]:i},i}return this.#t[n]}reset(){this.#t=null}async createAgent({identity:e,fetch:r,container:n}){let o=w(n)&&n!==!1?n===!0?Nt:n:"https://icp-api.io",s=w(n);return await Dt.create({identity:e,shouldFetchRootKey:s,host:o,...r&&{fetch:r}})}};var Ot=class t{static instance;#t=void 0;constructor(){}static getInstance(){return h(t.instance)&&(t.instance=new t),t.instance}async getActor({satelliteId:e,identity:r,buildType:n,...i}){let o=`${n}#${r.getPrincipal().toText()}#${e};`;if(h(this.#t)||h(this.#t[o])){let s=await this.createActor({satelliteId:e,identity:r,...i});return this.#t={...this.#t??{},[o]:s},s}return this.#t[o]}reset(){this.#t=null}async createActor({idlFactory:e,satelliteId:r,...n}){let i=await Rt.getInstance().getAgent(n);return tt.createActor(e,{agent:i,canisterId:r})}};var we=class extends Error{},xe=class extends Error{},be=class extends Error{},Ae=class extends Error{},Ee=class extends Error{};var Te=()=>he.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var hr="juno.datastore.error.user.cannot_update";var yr=({error:t,type:e})=>typeof t=="string"?t.includes(e):t instanceof Error?t.message.includes(e):!1;var Fn=async({data:t})=>{try{return await ye(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var _r=async t=>{let{data:e,version:r,description:n}=t;return{description:b(n),data:await Un(e),version:b(r)}},gr=t=>{let{version:e}=t;return{version:b(e)}},Jt=async({doc:t,key:e})=>{let{owner:r,version:n,description:i,data:o,...s}=t;return{key:e,description:R(i),owner:r.toText(),data:await ye(o),version:R(n),...s}};var Cn=t=>{if(h(t))return b();switch(t.matcher){case"equal":return b({Equal:t.timestamp});case"greaterThan":return b({GreaterThan:t.timestamp});case"lessThan":return b({LessThan:t.timestamp});case"between":return b({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Ee("Invalid list matcher for timestamp",t)}},nt=({matcher:t,paginate:e,order:r,owner:n})=>({matcher:h(t)?[]:[{key:b(t.key),description:b(t.description),created_at:Cn(t.createdAt),updated_at:Cn(t.updatedAt)}],paginate:b(h(e)?void 0:{start_after:b(e.startAfter),limit:b(h(e.limit)?void 0:BigInt(e.limit))}),order:b(h(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:b(h(n)?void 0:typeof n=="string"?_.fromText(n):n)});var Vn=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),r=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),n=t.Record({field:r,desc:t.Bool}),i=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),o=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(i),description:t.Opt(t.Text),created_at:t.Opt(i)}),s=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),a=t.Record({order:t.Opt(n),owner:t.Opt(t.Principal),matcher:t.Opt(o),paginate:t.Opt(s)}),l=t.Record({controllers:t.Vec(t.Principal)}),u=t.Variant({Write:t.Null,Admin:t.Null}),p=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:u,expires_at:t.Opt(t.Nat64)}),d=t.Record({version:t.Opt(t.Nat64)}),f=t.Variant({Db:t.Null,Storage:t.Null}),y=t.Record({version:t.Opt(t.Nat64)}),x=t.Record({cycles:t.Nat,destination_id:t.Principal}),v=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),k=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),g=t.Record({key:v,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,k)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),E=t.Record({derivation_origin:t.Opt(t.Text),external_alternative_origins:t.Opt(t.Vec(t.Text))}),m=t.Record({internet_identity:t.Opt(E)}),P=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),O=t.Record({max_memory_size:t.Opt(P)}),V=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),dt=t.Variant({Deny:t.Null,Allow:t.Null}),pt=t.Record({status_code:t.Nat16,location:t.Text}),K=t.Record({iframe:t.Opt(V),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),max_memory_size:t.Opt(P),raw_access:t.Opt(dt),redirects:t.Opt(t.Vec(t.Tuple(t.Text,pt)))}),B=t.Record({db:t.Opt(O),authentication:t.Opt(m),storage:K}),j=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),it=t.Variant({Heap:t.Null,Stable:t.Null}),Z=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),ot=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),z=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(it),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:Z,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(ot),write:Z,max_changes_per_user:t.Opt(t.Nat32)}),Re=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),St=t.Record({memory:it,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),Oe=t.Variant({Callback:t.Record({token:St,callback:t.Func([],[],["query"])})}),Se=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Oe),status_code:t.Nat16}),ve=t.Record({token:t.Opt(St),body:t.Vec(t.Nat8)}),Wt=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),Pe=t.Record({batch_id:t.Nat}),Be=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,g)),items_length:t.Nat64}),Ue=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),ke=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,j)),items_length:t.Nat64}),Fe=t.Record({stable:t.Nat64,heap:t.Nat64}),Gt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:u,expires_at:t.Opt(t.Nat64)}),vt=t.Record({controller:Gt,controllers:t.Vec(t.Principal)}),Yt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),zt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(it),max_size:t.Opt(t.Nat),read:Z,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(ot),write:Z,max_changes_per_user:t.Opt(t.Nat32)}),Pt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Ce=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text,a],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,a],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([l],[t.Vec(t.Tuple(t.Principal,p))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,d],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,a],[],[]),del_filtered_docs:t.Func([t.Text,a],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,d))],[],[]),del_rule:t.Func([f,t.Text,y],[],[]),deposit_cycles:t.Func([x],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(g)],["query"]),get_auth_config:t.Func([],[t.Opt(m)],["query"]),get_config:t.Func([],[B],[]),get_db_config:t.Func([],[t.Opt(O)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(j)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(g)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(j)))],["query"]),get_rule:t.Func([f,t.Text],[t.Opt(z)],["query"]),get_storage_config:t.Func([],[K],["query"]),http_request:t.Func([Re],[Se],["query"]),http_request_streaming_callback:t.Func([St],[ve],["query"]),init_asset_upload:t.Func([Wt],[Pe],[]),list_assets:t.Func([t.Text,a],[Be],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,p))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Ue))],["query"]),list_docs:t.Func([t.Text,a],[ke],["query"]),list_rules:t.Func([f],[t.Vec(t.Tuple(t.Text,z))],["query"]),memory_size:t.Func([],[Fe],["query"]),set_auth_config:t.Func([m],[],[]),set_controllers:t.Func([vt],[t.Vec(t.Tuple(t.Principal,p))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([O],[],[]),set_doc:t.Func([t.Text,t.Text,Yt],[j],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,Yt))],[t.Vec(t.Tuple(t.Text,j))],[]),set_rule:t.Func([f,t.Text,zt],[z],[]),set_storage_config:t.Func([K],[],[]),upload_asset_chunk:t.Func([Pt],[Ce],[]),version:t.Func([],[t.Text],["query"])})};var Kn=({satelliteId:t,container:e})=>{let{satelliteId:r}=wr({satelliteId:t}),{container:n}=xr({container:e});if(w(n)&&n!==!1){let{host:i,protocol:o}=new URL(n===!0?Nt:n);return`${o}//${r??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},wr=({satelliteId:t})=>w(t)?{satelliteId:t}:G.getInstance().get()??{satelliteId:void 0},xr=({container:t})=>w(t)?{container:t}:G.getInstance().get()??{container:void 0};var T=t=>Mn({idlFactory:Vn,buildType:"stock",...t}),jn=({idlFactory:t,...e})=>Mn({idlFactory:t,buildType:"extended",...e}),Mn=async({satelliteId:t,container:e,...r})=>{let{satelliteId:n}=wr({satelliteId:t});se(n,"No satellite ID defined. Did you initialize Juno?");let{container:i}=xr({container:e});return await Ot.getInstance().getActor({satelliteId:n,container:i,...r})};var $n=async({collection:t,key:e,satellite:r})=>{let{get_doc:n}=await T(r),i=R(await n(t,e));if(!h(i))return Jt({doc:i,key:e})},qn=async({docs:t,satellite:e})=>{let{get_many_docs:r}=await T(e),n=t.map(({collection:s,key:a})=>[s,a]),i=await r(n),o=[];for(let[s,a]of i){let l=R(a);o.push(w(l)?await Jt({key:s,doc:l}):void 0)}return o},Hn=async({collection:t,doc:e,satellite:r})=>{let{set_doc:n}=await T(r),{key:i}=e,o=await _r(e),s=await n(t,i,o);return await Jt({key:i,doc:s})},Jn=async({docs:t,satellite:e})=>{let{set_many_docs:r}=await T(e),n=[];for(let{collection:s,doc:a}of t){let{key:l}=a;n.push([s,l,await _r(a)])}let i=await r(n),o=[];for(let[s,a]of i)o.push(await Jt({key:s,doc:a}));return o},Wn=async({collection:t,doc:e,satellite:r})=>{let{del_doc:n}=await T(r),{key:i}=e;return n(t,i,gr(e))},Gn=async({docs:t,satellite:e})=>{let{del_many_docs:r}=await T(e),n=t.map(({collection:i,doc:o})=>[i,o.key,gr(o)]);await r(n)},Yn=async({collection:t,filter:e,satellite:r})=>{let{del_filtered_docs:n}=await T(r);return n(t,nt(e))},zn=async({collection:t,filter:e,satellite:r})=>{let{list_docs:n}=await T(r),{items:i,items_page:o,items_length:s,matches_length:a,matches_pages:l}=await n(t,nt(e)),u=[];for(let[p,d]of i){let{data:f,owner:y,description:x,version:v,...k}=d;u.push({key:p,description:R(x),owner:y.toText(),data:await Fn({data:f}),version:R(v),...k})}return{items:u,items_length:s,items_page:R(o),matches_length:a,matches_pages:R(l)}},Xn=async({collection:t,filter:e,satellite:r})=>{let{count_docs:n}=await T(r);return n(t,nt(e))};var A=t=>t!==void 0?t:Ne()??new ft;var Qn=async({satellite:t,...e})=>{let r=A(t?.identity);return await $n({...e,satellite:{...t,identity:r}})},kl=async({satellite:t,...e})=>{let r=A(t?.identity);return await qn({...e,satellite:{...t,identity:r}})},Zn=async({satellite:t,...e})=>{let r=A(t?.identity);return await Hn({...e,satellite:{...t,identity:r}})},Fl=async({satellite:t,...e})=>{let r=A(t?.identity);return await Jn({...e,satellite:{...t,identity:r}})},Cl=async({satellite:t,...e})=>{let r=A(t?.identity);return await Wn({...e,satellite:{...t,identity:r}})},Vl=async({satellite:t,...e})=>{let r=A(t?.identity);return await Gn({...e,satellite:{...t,identity:r}})},Kl=async({satellite:t,filter:e,...r})=>{let n=A(t?.identity);return await Yn({...r,filter:e??{},satellite:{...t,identity:n}})},jl=async({satellite:t,filter:e,...r})=>{let n=A(t?.identity);return await zn({...r,filter:e??{},satellite:{...t,identity:n}})},Ml=async({satellite:t,filter:e,...r})=>{let n=A(t?.identity);return await Xn({...r,filter:e??{},satellite:{...t,identity:n}})};var In=async t=>{let e=Ne();if(h(e))throw new Ae("No identity to initialize the user. Have you initialized Juno?");let r=e.getPrincipal().toText(),n=()=>Qn({collection:"#user",key:r}),i=await n();if(w(i))return i;try{return await cs({userId:r,provider:t})}catch(o){if(yr({error:o,type:hr})){let s=await n();if(w(s))return s}throw o}},cs=({userId:t,...e})=>Zn({collection:"#user",doc:{key:t,data:e}});var Y,br=async t=>{if(Y=Y??await Te(),!(await Y?.isAuthenticated()??!1))return;let r=await In(t);Q.getInstance().set(r)},ls=t=>new Promise(async(e,r)=>{if(h(Y)){r(new xe("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}let n=t?.provider??new ge({});await Y.login({onSuccess:async()=>{await br(n.id),e()},onError:i=>{if(i===fr){r(new be(i));return}r(new we(i))},maxTimeToLive:t?.maxTimeToLive??Rn,allowPinAuthentication:t?.allowPin??On,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...n.signInOptions({windowed:t?.windowed})})}),Ar=async()=>{await Y?.logout(),Y=null,Q.getInstance().reset(),Ot.getInstance().reset(),Rt.getInstance().reset(),Y=await Te()},Ne=()=>Y?.getIdentity(),us=async()=>(Y??await Te()).getIdentity();var Dn=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),n=async()=>{rr({message:"junoSignOutAuthTimer"}),await Ar()};return r.onmessage=async({data:i})=>{let{msg:o,data:s}=i;switch(o){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":rr({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},Q.getInstance().subscribe(i=>{if(h(i)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var Ln=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_SATELLITE_ID??t():t()},ti=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_CONTAINER??t():t()};var pu=async({idlFactory:t,satellite:e})=>{let r=A(e?.identity);return await jn({idlFactory:t,...e,identity:r})};var ei=async({asset:{data:t,filename:e,collection:r,headers:n,token:i,fullPath:o,encoding:s,description:a},actor:l,init_asset_upload:u})=>{let{batch_id:p}=await u({collection:r,full_path:o,name:e,token:b(i),encoding_type:b(s),description:b(a)}),d=19e5,f=[],y=_e()?new Blob([await t.arrayBuffer()]):t,x=0n;for(let g=0;g<y.size;g+=d){let E=y.slice(g,g+d);f.push({batchId:p,chunk:E,actor:l,orderId:x}),x++}let v=[];for await(let g of ds({uploadChunks:f}))v=[...v,...g];let k=n.find(([g,E])=>g.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await l.commit_asset_upload({batch_id:p,chunk_ids:v.map(({chunk_id:g})=>g),headers:[...n,...k??[]]})};async function*ds({uploadChunks:t,limit:e=12}){for(let r=0;r<t.length;r=r+e){let n=t.slice(r,r+e);yield await Promise.all(n.map(i=>ps(i)))}}var ps=async({batchId:t,chunk:e,actor:r,orderId:n})=>r.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:b(n)});var ri=async({satellite:t,...e})=>{let r=await T(t);await ei({actor:r,asset:e,init_asset_upload:async i=>await r.init_asset_upload(i)})},ni=async({collection:t,satellite:e,filter:r})=>{let{list_assets:n}=await T(e),{items:i,items_length:o,items_page:s,matches_length:a,matches_pages:l}=await n(t,nt(r));return{items:i.map(([u,p])=>p),items_length:o,items_page:R(s),matches_length:a,matches_pages:R(l)}},ii=async({collection:t,satellite:e,filter:r})=>{let{count_assets:n}=await T(e);return n(t,nt(r))},oi=async({collection:t,fullPath:e,satellite:r})=>(await T(r)).del_asset(t,e),si=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await T(e),n=t.map(({collection:i,fullPath:o})=>[i,o]);await r(n)},ai=async({collection:t,satellite:e,filter:r})=>{let{del_filtered_assets:n}=await T(e);return n(t,nt(r))},ci=async({collection:t,fullPath:e,satellite:r})=>{let{get_asset:n}=await T(r);return R(await n(t,e))},li=async({assets:t,satellite:e})=>{let{get_many_assets:r}=await T(e),n=t.map(({collection:o,fullPath:s})=>[o,s]);return(await r(n)).map(([o,s])=>R(s))};var ui=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Su=t=>di(t),vu=t=>di({filename:t.data.name,...t}),di=async({filename:t,data:e,collection:r,headers:n=[],fullPath:i,token:o,satellite:s,encoding:a,description:l})=>{let u=A(s?.identity),p=decodeURI(t),d=i??`/${r}/${p}`,f={...s,identity:u};return await ri({data:e,filename:p,collection:r,token:o,headers:n,fullPath:d,encoding:a,satellite:f,description:l}),{downloadUrl:pi({satellite:f,assetKey:{fullPath:d,token:o}}),fullPath:d,name:p}},Pu=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:A(e?.identity)},{items:i,...o}=await ni({collection:t,satellite:n,filter:r??{}}),s=i.map(({key:{full_path:a,token:l,name:u,owner:p,description:d},headers:f,encodings:y,created_at:x,updated_at:v})=>{let k=R(l);return{fullPath:a,description:R(d),name:u,downloadUrl:pi({satellite:n,assetKey:{fullPath:a,token:k}}),token:k,headers:f,encodings:y.reduce((g,[E,{modified:m,sha256:P,total_length:O}])=>({...g,[E]:{modified:m,sha256:ui(P),total_length:O}}),{}),owner:p.toText(),created_at:x,updated_at:v}});return{items:s,assets:s,...o}},Bu=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:A(e?.identity)};return await ii({collection:t,satellite:n,filter:r??{}})},Uu=({collection:t,fullPath:e,satellite:r})=>oi({collection:t,fullPath:e,satellite:{...r,identity:A(r?.identity)}}),ku=({assets:t,satellite:e})=>si({assets:t,satellite:{...e,identity:A(e?.identity)}}),Fu=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:A(e?.identity)};return await ai({collection:t,satellite:n,filter:r??{}})},Cu=async({satellite:t,...e})=>{let r=A(t?.identity);return await ci({...e,satellite:{...t,identity:r}})},Vu=async({satellite:t,...e})=>{let r=A(t?.identity);return await li({...e,satellite:{...t,identity:r}})},pi=({assetKey:{fullPath:t,token:e},satellite:r})=>{let n={...r,identity:A(r?.identity)};return`${Kn(n)}${t}${w(e)?`?token=${e}`:""}`};var fs=t=>{let e=t?.satelliteId??Ln();se(e,"Satellite ID is not configured. Juno cannot be initialized.");let r=t?.container??ti();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:r}},Wu=t=>ms(t),ms=async t=>{let e=fs(t);G.getInstance().set(e),await br();let r=e.workers?.auth!==void 0?Dn(e.workers.auth):void 0;return[...r?[r]:[]]},Gu=t=>Q.getInstance().subscribe(t);export{Ae as InitError,ge as InternetIdentityProvider,Ee as ListError,kn as NFIDProvider,we as SignInError,xe as SignInInitError,be as SignInUserInterruptError,Gu as authSubscribe,Bu as countAssets,Ml as countDocs,Uu as deleteAsset,Cl as deleteDoc,Fu as deleteFilteredAssets,Kl as deleteFilteredDocs,ku as deleteManyAssets,Vl as deleteManyDocs,pi as downloadUrl,Cu as getAsset,Qn as getDoc,Vu as getManyAssets,kl as getManyDocs,pu as getSatelliteExtendedActor,Wu as initJuno,ms as initSatellite,Pu as listAssets,jl as listDocs,Zn as setDoc,Fl as setManyDocs,ls as signIn,Ar as signOut,us as unsafeIdentity,Su as uploadBlob,vu as uploadFile};
|
|
15
|
+
ic-request`);function ir(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return I(t)}var Tt=class{constructor(e,r,n){this.pubkey=e,this.expiration=r,this.targets=n}toCBOR(){return Et.value.map(Object.assign({pubkey:Et.value.bytes(this.pubkey),expiration:Et.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:Et.value.array(this.targets.map(e=>Et.value.bytes(e.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:S(this.pubkey)},this.targets&&{targets:this.targets.map(e=>e.toHex())})}};async function qo(t,e,r,n){let i=new Tt(e.toDer(),BigInt(+r)*BigInt(1e6),n),o=new Uint8Array([...Mo,...new Uint8Array(je(Object.assign({},i)))]),s=await t.sign(o);return{delegation:i,signature:s}}var Vt=class t{constructor(e,r){this.delegations=e,this.publicKey=r}static async create(e,r,n=new Date(Date.now()+15*60*1e3),i={}){var o,s;let a=await qo(e,r,n,i.targets);return new t([...((o=i.previous)===null||o===void 0?void 0:o.delegations)||[],a],((s=i.previous)===null||s===void 0?void 0:s.publicKey)||e.getPublicKey().toDer())}static fromJSON(e){let{publicKey:r,delegations:n}=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(n))throw new Error("Invalid delegations.");let i=n.map(o=>{let{delegation:s,signature:a}=o,{pubkey:l,expiration:u,targets:p}=s;if(p!==void 0&&!Array.isArray(p))throw new Error("Invalid targets.");return{delegation:new Tt(ir(l),BigInt("0x"+u),p&&p.map(d=>{if(typeof d!="string")throw new Error("Invalid target.");return _.fromHex(d)})),signature:ir(a)}});return new this(i,ir(r))}static fromDelegations(e,r){return new this(e,r)}toJSON(){return{delegations:this.delegations.map(e=>{let{delegation:r,signature:n}=e,{targets:i}=r;return{delegation:Object.assign({expiration:r.expiration.toString(16),pubkey:S(r.pubkey)},i&&{targets:i.map(o=>o.toHex())}),signature:S(n)}}),publicKey:S(this.publicKey)}}},Kt=class extends st{constructor(e,r){super(),this._inner=e,this._delegation=r}static fromDelegation(e,r){return new this(e,r)}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(e){return this._inner.sign(e)}async transformRequest(e){let{body:r}=e,n=jo(e,["body"]),i=await je(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_sig:await this.sign(new Uint8Array([...$o,...new Uint8Array(i)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}},jt=class t extends ue{constructor(e,r){super(e),de.set(this,void 0),Vo(this,de,r,"f")}get delegation(){return Ko(this,de,"f")}static fromDelegation(e,r){return new t(e,r)}};de=new WeakMap;function pn(t,e){for(let{delegation:i}of t.delegations)if(+new Date(Number(i.expiration/BigInt(1e6)))<=+Date.now())return!1;let r=[],n=e?.scope;n&&(Array.isArray(n)?r.push(...n.map(i=>typeof i=="string"?_.fromText(i):i)):r.push(typeof n=="string"?_.fromText(n):n));for(let i of r){let o=i.toText();for(let{delegation:s}of t.delegations){if(s.targets===void 0)continue;let a=!0;for(let l of s.targets)if(l.toText()===o){a=!1;break}if(a)return!1}}return!0}var Jo=Ve(Yi());var fn;(function(t){t[t.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(fn||(fn={}));var mn=["mousedown","mousemove","keydown","touchstart","wheel"],Mt=class{constructor(e={}){var r;this.callbacks=[],this.idleTimeout=10*60*1e3,this.timeoutID=void 0;let{onIdle:n,idleTimeout:i=10*60*1e3}=e||{};this.callbacks=n?[n]:[],this.idleTimeout=i;let o=this._resetTimer.bind(this);window.addEventListener("load",o,!0),mn.forEach(function(a){document.addEventListener(a,o,!0)});let s=(a,l)=>{let u;return(...p)=>{let d=this,f=function(){u=void 0,a.apply(d,p)};clearTimeout(u),u=window.setTimeout(f,l)}};if(e?.captureScroll){let a=s(o,(r=e?.scrollDebounce)!==null&&r!==void 0?r:100);window.addEventListener("scroll",a,!0)}o()}static create(e={}){return new this(e)}registerCallback(e){this.callbacks.push(e)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let e=this._resetTimer.bind(this);mn.forEach(function(r){document.removeEventListener(r,e,!0)}),this.callbacks.forEach(r=>r())}_resetTimer(){let e=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(e,this.idleTimeout)}};var Wo=(t,e)=>e.some(r=>t instanceof r),hn,yn;function Go(){return hn||(hn=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Yo(){return yn||(yn=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var _n=new WeakMap,sr=new WeakMap,gn=new WeakMap,or=new WeakMap,cr=new WeakMap;function zo(t){let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("success",o),t.removeEventListener("error",s)},o=()=>{r(W(t.result)),i()},s=()=>{n(t.error),i()};t.addEventListener("success",o),t.addEventListener("error",s)});return e.then(r=>{r instanceof IDBCursor&&_n.set(r,t)}).catch(()=>{}),cr.set(e,t),e}function Xo(t){if(sr.has(t))return;let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("complete",o),t.removeEventListener("error",s),t.removeEventListener("abort",s)},o=()=>{r(),i()},s=()=>{n(t.error||new DOMException("AbortError","AbortError")),i()};t.addEventListener("complete",o),t.addEventListener("error",s),t.addEventListener("abort",s)});sr.set(t,e)}var ar={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return sr.get(t);if(e==="objectStoreNames")return t.objectStoreNames||gn.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return W(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function wn(t){ar=t(ar)}function Qo(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(pe(this),e,...r);return gn.set(n,e.sort?e.sort():[e]),W(n)}:Yo().includes(t)?function(...e){return t.apply(pe(this),e),W(_n.get(this))}:function(...e){return W(t.apply(pe(this),e))}}function Zo(t){return typeof t=="function"?Qo(t):(t instanceof IDBTransaction&&Xo(t),Wo(t,Go())?new Proxy(t,ar):t)}function W(t){if(t instanceof IDBRequest)return zo(t);if(or.has(t))return or.get(t);let e=Zo(t);return e!==t&&(or.set(t,e),cr.set(e,t)),e}var pe=t=>cr.get(t);function bn(t,e,{blocked:r,upgrade:n,blocking:i,terminated:o}={}){let s=indexedDB.open(t,e),a=W(s);return n&&s.addEventListener("upgradeneeded",l=>{n(W(s.result),l.oldVersion,l.newVersion,W(s.transaction),l)}),r&&s.addEventListener("blocked",l=>r(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),i&&l.addEventListener("versionchange",u=>i(u.oldVersion,u.newVersion,u))}).catch(()=>{}),a}var Io=["get","getKey","getAll","getAllKeys","count"],Do=["put","add","delete","clear"],lr=new Map;function xn(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(lr.get(e))return lr.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,i=Do.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(i||Io.includes(r)))return;let o=async function(s,...a){let l=this.transaction(s,i?"readwrite":"readonly"),u=l.store;return n&&(u=u.index(a.shift())),(await Promise.all([u[r](...a),i&&l.done]))[0]};return lr.set(e,o),o}wn(t=>({...t,get:(e,r,n)=>xn(e,r)||t.get(e,r,n),has:(e,r)=>!!xn(e,r)||t.has(e,r)}));var An="auth-client-db",En="ic-keyval",Lo=async(t=An,e=En,r)=>(fe&&(localStorage!=null&&localStorage.getItem($))&&(localStorage.removeItem($),localStorage.removeItem(q)),await bn(t,r,{upgrade:n=>{n.objectStoreNames.contains(e)&&n.clear(e),n.createObjectStore(e)}}));async function ts(t,e,r){return await t.get(e,r)}async function es(t,e,r,n){return await t.put(e,n,r)}async function rs(t,e,r){return await t.delete(e,r)}var $t=class t{constructor(e,r){this._db=e,this._storeName=r}static async create(e){let{dbName:r=An,storeName:n=En,version:i=Tn}=e??{},o=await Lo(r,n,i);return new t(o,n)}async set(e,r){return await es(this._db,this._storeName,e,r)}async get(e){var r;return(r=await ts(this._db,this._storeName,e))!==null&&r!==void 0?r:null}async remove(e){return await rs(this._db,this._storeName,e)}};var ns=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},is=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},me,q="identity",$="delegation",Nn="iv",Tn=1,fe=typeof window<"u",qt=class{constructor(e="ic-",r){this.prefix=e,this._localStorage=r}get(e){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+e))}set(e,r){return this._getLocalStorage().setItem(this.prefix+e,r),Promise.resolve()}remove(e){return this._getLocalStorage().removeItem(this.prefix+e),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let e=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.localStorage:globalThis.localStorage:window.localStorage;if(!e)throw new Error("Could not find local storage.");return e}},Ht=class{constructor(e){me.set(this,void 0),ns(this,me,e??{},"f")}get _db(){return new Promise(e=>{if(this.initializedDb){e(this.initializedDb);return}$t.create(is(this,me,"f")).then(r=>{this.initializedDb=r,e(r)})})}async get(e){return await(await this._db).get(e)}async set(e,r){await(await this._db).set(e,r)}async remove(e){await(await this._db).remove(e)}};me=new WeakMap;var os="https://identity.ic0.app",ss="#authorize",ur="ECDSA",dr="Ed25519",as=500,fr="UserInterrupt",he=class{constructor(e,r,n,i,o,s,a,l){this._identity=e,this._key=r,this._chain=n,this._storage=i,this.idleManager=o,this._createOptions=s,this._idpWindow=a,this._eventHandler=l,this._registerDefaultIdleCallback()}static async create(e={}){var r,n,i;let o=(r=e.storage)!==null&&r!==void 0?r:new Ht,s=(n=e.keyType)!==null&&n!==void 0?n:ur,a=null;if(e.identity)a=e.identity;else{let d=await o.get(q);if(!d&&fe)try{let f=new qt,y=await f.get($),x=await f.get(q);y&&x&&s===ur&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await o.set($,y),await o.set(q,x),d=y,await f.remove($),await f.remove(q))}catch(f){console.error("error while attempting to recover localstorage: "+f)}if(d)try{typeof d=="object"?s===dr&&typeof d=="string"?a=await ut.fromJSON(d):a=await Ft.fromKeyPair(d):typeof d=="string"&&(a=ut.fromJSON(d))}catch{}}let l=new ft,u=null;if(a)try{let d=await o.get($);if(typeof d=="object"&&d!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?l=e.identity:d&&(u=Vt.fromJSON(d),pn(u)?"toDer"in a?l=jt.fromDelegation(a,u):l=Kt.fromDelegation(a,u):(await pr(o),a=null))}catch(d){console.error(d),await pr(o),a=null}let p;return!((i=e.idleOptions)===null||i===void 0)&&i.disableIdle?p=void 0:(u||e.identity)&&(p=Mt.create(e.idleOptions)),a||(s===dr?(a=await ut.generate(),await o.set(q,JSON.stringify(a.toJSON()))):(e.storage&&s===ur&&console.warn(`You are using a custom storage provider that may not support CryptoKey storage. If you are using a custom storage provider that does not support CryptoKey storage, you should use '${dr}' as the key type, as it can serialize to a string`),a=await Ft.generate(),await o.set(q,a.getKeyPair()))),new this(l,a,u,o,p,e)}_registerDefaultIdleCallback(){var e,r;let n=(e=this._createOptions)===null||e===void 0?void 0:e.idleOptions;!n?.onIdle&&!n?.disableDefaultIdleCallback&&((r=this.idleManager)===null||r===void 0||r.registerCallback(()=>{this.logout(),location.reload()}))}async _handleSuccess(e,r){var n,i;let o=e.delegations.map(u=>({delegation:new Tt(u.delegation.pubkey,u.delegation.expiration,u.delegation.targets),signature:u.signature.buffer})),s=Vt.fromDelegations(o,e.userPublicKey.buffer),a=this._key;if(!a)return;this._chain=s,"toDer"in a?this._identity=jt.fromDelegation(a,this._chain):this._identity=Kt.fromDelegation(a,this._chain),(n=this._idpWindow)===null||n===void 0||n.close();let l=(i=this._createOptions)===null||i===void 0?void 0:i.idleOptions;!this.idleManager&&!l?.disableIdle&&(this.idleManager=Mt.create(l),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set($,JSON.stringify(this._chain.toJSON())),r?.(e)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null}async login(e){var r,n,i,o;let s=BigInt(8)*BigInt(36e11),a=new URL(((r=e?.identityProvider)===null||r===void 0?void 0:r.toString())||os);a.hash=ss,(n=this._idpWindow)===null||n===void 0||n.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(a,Object.assign({maxTimeToLive:(i=e?.maxTimeToLive)!==null&&i!==void 0?i:s},e)),window.addEventListener("message",this._eventHandler),this._idpWindow=(o=window.open(a.toString(),"idpWindow",e?.windowOpenerFeatures))!==null&&o!==void 0?o:void 0;let l=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(fr,e?.onError):setTimeout(l,as))};l()}_getEventHandler(e,r){return async n=>{var i,o,s;if(n.origin!==e.origin)return;let a=n.data;switch(a.kind){case"authorize-ready":{let l=Object.assign({kind:"authorize-client",sessionPublicKey:new Uint8Array((i=this._key)===null||i===void 0?void 0:i.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,allowPinAuthentication:r?.allowPinAuthentication,derivationOrigin:(o=r?.derivationOrigin)===null||o===void 0?void 0:o.toString()},r?.customValues);(s=this._idpWindow)===null||s===void 0||s.postMessage(l,e.origin);break}case"authorize-client-success":try{await this._handleSuccess(a,r?.onSuccess)}catch(l){this._handleFailure(l.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(a.text,r?.onError);break;default:break}}}_handleFailure(e,r){var n;(n=this._idpWindow)===null||n===void 0||n.close(),r?.(e),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(e={}){if(await pr(this._storage),this._identity=new ft,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function pr(t){await t.remove(q),await t.remove($),await t.remove(Nn)}var Rn=BigInt(144e11),On=!1,Sn={width:576,height:576},vn={width:505,height:705},Pn="internetcomputer.org";var Nt="http://127.0.0.1:5987",Bn="rdmx6-jaaaa-aaaaa-aaadq-cai";var G=class t extends xt{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let r=super.subscribe(e);return e(this.env),r}};var Un=async t=>{let e=new Blob([JSON.stringify(t,cn)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},ye=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),ln)},_e=()=>typeof window<"u";var mr=({width:t,height:e})=>{if(!_e()||h(window)||h(window.top))return;let{top:{innerWidth:r,innerHeight:n}}=window,i=n/2+screenY-e/2,o=r/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${o}`};var ge=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let r=()=>{let n=G.getInstance().get()?.container;if(h(n)||n===!1)return`https://identity.${this.#t??Pn}`;let i=G.getInstance().get(),o=w(i)&&w(i?.internetIdentityId)?i.internetIdentityId:Bn,{host:s,protocol:a}=new URL(n===!0?Nt:n);return/apple/i.test(navigator?.vendor)?`${a}//${s}?canisterId=${o}`:`${a}//${o}.${s.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:mr(Sn)},identityProvider:r()}}},kn=class{#t;#e;constructor({appName:e,logoUrl:r}){this.#t=e,this.#e=r}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:mr(vn)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};var Rt=class t{static instance;#t=void 0;constructor(){}static getInstance(){return h(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...r}){let n=e.getPrincipal().toText();if(h(this.#t)||h(this.#t[n])){let i=await this.createAgent({identity:e,...r});return this.#t={...this.#t??{},[n]:i},i}return this.#t[n]}reset(){this.#t=null}async createAgent({identity:e,fetch:r,container:n}){let o=w(n)&&n!==!1?n===!0?Nt:n:"https://icp-api.io",s=w(n);return await Dt.create({identity:e,shouldFetchRootKey:s,host:o,...r&&{fetch:r}})}};var Ot=class t{static instance;#t=void 0;constructor(){}static getInstance(){return h(t.instance)&&(t.instance=new t),t.instance}async getActor({satelliteId:e,identity:r,buildType:n,...i}){let o=`${n}#${r.getPrincipal().toText()}#${e};`;if(h(this.#t)||h(this.#t[o])){let s=await this.createActor({satelliteId:e,identity:r,...i});return this.#t={...this.#t??{},[o]:s},s}return this.#t[o]}reset(){this.#t=null}async createActor({idlFactory:e,satelliteId:r,...n}){let i=await Rt.getInstance().getAgent(n);return tt.createActor(e,{agent:i,canisterId:r})}};var we=class extends Error{},xe=class extends Error{},be=class extends Error{},Ae=class extends Error{},Ee=class extends Error{};var Te=()=>he.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var hr="juno.datastore.error.user.cannot_update";var yr=({error:t,type:e})=>typeof t=="string"?t.includes(e):t instanceof Error?t.message.includes(e):!1;var Fn=async({data:t})=>{try{return await ye(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var _r=async t=>{let{data:e,version:r,description:n}=t;return{description:b(n),data:await Un(e),version:b(r)}},gr=t=>{let{version:e}=t;return{version:b(e)}},Jt=async({doc:t,key:e})=>{let{owner:r,version:n,description:i,data:o,...s}=t;return{key:e,description:R(i),owner:r.toText(),data:await ye(o),version:R(n),...s}};var Cn=t=>{if(h(t))return b();switch(t.matcher){case"equal":return b({Equal:t.timestamp});case"greaterThan":return b({GreaterThan:t.timestamp});case"lessThan":return b({LessThan:t.timestamp});case"between":return b({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Ee("Invalid list matcher for timestamp",t)}},nt=({matcher:t,paginate:e,order:r,owner:n})=>({matcher:h(t)?[]:[{key:b(t.key),description:b(t.description),created_at:Cn(t.createdAt),updated_at:Cn(t.updatedAt)}],paginate:b(h(e)?void 0:{start_after:b(e.startAfter),limit:b(h(e.limit)?void 0:BigInt(e.limit))}),order:b(h(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:b(h(n)?void 0:typeof n=="string"?_.fromText(n):n)});var Vn=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),r=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),n=t.Record({field:r,desc:t.Bool}),i=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),o=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(i),description:t.Opt(t.Text),created_at:t.Opt(i)}),s=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),a=t.Record({order:t.Opt(n),owner:t.Opt(t.Principal),matcher:t.Opt(o),paginate:t.Opt(s)}),l=t.Record({controllers:t.Vec(t.Principal)}),u=t.Variant({Write:t.Null,Admin:t.Null}),p=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:u,expires_at:t.Opt(t.Nat64)}),d=t.Record({version:t.Opt(t.Nat64)}),f=t.Variant({Db:t.Null,Storage:t.Null}),y=t.Record({version:t.Opt(t.Nat64)}),x=t.Record({cycles:t.Nat,destination_id:t.Principal}),v=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),k=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),g=t.Record({key:v,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,k)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),E=t.Record({derivation_origin:t.Opt(t.Text),external_alternative_origins:t.Opt(t.Vec(t.Text))}),m=t.Record({internet_identity:t.Opt(E)}),P=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),O=t.Record({max_memory_size:t.Opt(P)}),V=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),dt=t.Variant({Deny:t.Null,Allow:t.Null}),pt=t.Record({status_code:t.Nat16,location:t.Text}),K=t.Record({iframe:t.Opt(V),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),max_memory_size:t.Opt(P),raw_access:t.Opt(dt),redirects:t.Opt(t.Vec(t.Tuple(t.Text,pt)))}),B=t.Record({db:t.Opt(O),authentication:t.Opt(m),storage:K}),j=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),it=t.Variant({Heap:t.Null,Stable:t.Null}),Z=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),ot=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),z=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(it),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:Z,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(ot),write:Z,max_changes_per_user:t.Opt(t.Nat32)}),Re=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),St=t.Record({memory:it,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),Oe=t.Variant({Callback:t.Record({token:St,callback:t.Func([],[],["query"])})}),Se=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Oe),status_code:t.Nat16}),ve=t.Record({token:t.Opt(St),body:t.Vec(t.Nat8)}),Wt=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),Pe=t.Record({batch_id:t.Nat}),Be=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,g)),items_length:t.Nat64}),Ue=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),ke=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,j)),items_length:t.Nat64}),Fe=t.Record({stable:t.Nat64,heap:t.Nat64}),Gt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:u,expires_at:t.Opt(t.Nat64)}),vt=t.Record({controller:Gt,controllers:t.Vec(t.Principal)}),Yt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),zt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(it),max_size:t.Opt(t.Nat),read:Z,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(ot),write:Z,max_changes_per_user:t.Opt(t.Nat32)}),Pt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Ce=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text,a],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,a],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([l],[t.Vec(t.Tuple(t.Principal,p))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,d],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,a],[],[]),del_filtered_docs:t.Func([t.Text,a],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,d))],[],[]),del_rule:t.Func([f,t.Text,y],[],[]),deposit_cycles:t.Func([x],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(g)],["query"]),get_auth_config:t.Func([],[t.Opt(m)],["query"]),get_config:t.Func([],[B],[]),get_db_config:t.Func([],[t.Opt(O)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(j)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(g)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(j)))],["query"]),get_rule:t.Func([f,t.Text],[t.Opt(z)],["query"]),get_storage_config:t.Func([],[K],["query"]),http_request:t.Func([Re],[Se],["query"]),http_request_streaming_callback:t.Func([St],[ve],["query"]),init_asset_upload:t.Func([Wt],[Pe],[]),list_assets:t.Func([t.Text,a],[Be],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,p))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Ue))],["query"]),list_docs:t.Func([t.Text,a],[ke],["query"]),list_rules:t.Func([f],[t.Vec(t.Tuple(t.Text,z))],["query"]),memory_size:t.Func([],[Fe],["query"]),set_auth_config:t.Func([m],[],[]),set_controllers:t.Func([vt],[t.Vec(t.Tuple(t.Principal,p))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([O],[],[]),set_doc:t.Func([t.Text,t.Text,Yt],[j],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,Yt))],[t.Vec(t.Tuple(t.Text,j))],[]),set_rule:t.Func([f,t.Text,zt],[z],[]),set_storage_config:t.Func([K],[],[]),upload_asset_chunk:t.Func([Pt],[Ce],[])})};var Kn=({satelliteId:t,container:e})=>{let{satelliteId:r}=wr({satelliteId:t}),{container:n}=xr({container:e});if(w(n)&&n!==!1){let{host:i,protocol:o}=new URL(n===!0?Nt:n);return`${o}//${r??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},wr=({satelliteId:t})=>w(t)?{satelliteId:t}:G.getInstance().get()??{satelliteId:void 0},xr=({container:t})=>w(t)?{container:t}:G.getInstance().get()??{container:void 0};var T=t=>Mn({idlFactory:Vn,buildType:"stock",...t}),jn=({idlFactory:t,...e})=>Mn({idlFactory:t,buildType:"extended",...e}),Mn=async({satelliteId:t,container:e,...r})=>{let{satelliteId:n}=wr({satelliteId:t});se(n,"No satellite ID defined. Did you initialize Juno?");let{container:i}=xr({container:e});return await Ot.getInstance().getActor({satelliteId:n,container:i,...r})};var $n=async({collection:t,key:e,satellite:r})=>{let{get_doc:n}=await T(r),i=R(await n(t,e));if(!h(i))return Jt({doc:i,key:e})},qn=async({docs:t,satellite:e})=>{let{get_many_docs:r}=await T(e),n=t.map(({collection:s,key:a})=>[s,a]),i=await r(n),o=[];for(let[s,a]of i){let l=R(a);o.push(w(l)?await Jt({key:s,doc:l}):void 0)}return o},Hn=async({collection:t,doc:e,satellite:r})=>{let{set_doc:n}=await T(r),{key:i}=e,o=await _r(e),s=await n(t,i,o);return await Jt({key:i,doc:s})},Jn=async({docs:t,satellite:e})=>{let{set_many_docs:r}=await T(e),n=[];for(let{collection:s,doc:a}of t){let{key:l}=a;n.push([s,l,await _r(a)])}let i=await r(n),o=[];for(let[s,a]of i)o.push(await Jt({key:s,doc:a}));return o},Wn=async({collection:t,doc:e,satellite:r})=>{let{del_doc:n}=await T(r),{key:i}=e;return n(t,i,gr(e))},Gn=async({docs:t,satellite:e})=>{let{del_many_docs:r}=await T(e),n=t.map(({collection:i,doc:o})=>[i,o.key,gr(o)]);await r(n)},Yn=async({collection:t,filter:e,satellite:r})=>{let{del_filtered_docs:n}=await T(r);return n(t,nt(e))},zn=async({collection:t,filter:e,satellite:r})=>{let{list_docs:n}=await T(r),{items:i,items_page:o,items_length:s,matches_length:a,matches_pages:l}=await n(t,nt(e)),u=[];for(let[p,d]of i){let{data:f,owner:y,description:x,version:v,...k}=d;u.push({key:p,description:R(x),owner:y.toText(),data:await Fn({data:f}),version:R(v),...k})}return{items:u,items_length:s,items_page:R(o),matches_length:a,matches_pages:R(l)}},Xn=async({collection:t,filter:e,satellite:r})=>{let{count_docs:n}=await T(r);return n(t,nt(e))};var A=t=>t!==void 0?t:Ne()??new ft;var Qn=async({satellite:t,...e})=>{let r=A(t?.identity);return await $n({...e,satellite:{...t,identity:r}})},kl=async({satellite:t,...e})=>{let r=A(t?.identity);return await qn({...e,satellite:{...t,identity:r}})},Zn=async({satellite:t,...e})=>{let r=A(t?.identity);return await Hn({...e,satellite:{...t,identity:r}})},Fl=async({satellite:t,...e})=>{let r=A(t?.identity);return await Jn({...e,satellite:{...t,identity:r}})},Cl=async({satellite:t,...e})=>{let r=A(t?.identity);return await Wn({...e,satellite:{...t,identity:r}})},Vl=async({satellite:t,...e})=>{let r=A(t?.identity);return await Gn({...e,satellite:{...t,identity:r}})},Kl=async({satellite:t,filter:e,...r})=>{let n=A(t?.identity);return await Yn({...r,filter:e??{},satellite:{...t,identity:n}})},jl=async({satellite:t,filter:e,...r})=>{let n=A(t?.identity);return await zn({...r,filter:e??{},satellite:{...t,identity:n}})},Ml=async({satellite:t,filter:e,...r})=>{let n=A(t?.identity);return await Xn({...r,filter:e??{},satellite:{...t,identity:n}})};var In=async t=>{let e=Ne();if(h(e))throw new Ae("No identity to initialize the user. Have you initialized Juno?");let r=e.getPrincipal().toText(),n=()=>Qn({collection:"#user",key:r}),i=await n();if(w(i))return i;try{return await cs({userId:r,provider:t})}catch(o){if(yr({error:o,type:hr})){let s=await n();if(w(s))return s}throw o}},cs=({userId:t,...e})=>Zn({collection:"#user",doc:{key:t,data:e}});var Y,br=async t=>{if(Y=Y??await Te(),!(await Y?.isAuthenticated()??!1))return;let r=await In(t);Q.getInstance().set(r)},ls=t=>new Promise(async(e,r)=>{if(h(Y)){r(new xe("No client is ready to perform a sign-in. Have you initialized the Satellite?"));return}let n=t?.provider??new ge({});await Y.login({onSuccess:async()=>{await br(n.id),e()},onError:i=>{if(i===fr){r(new be(i));return}r(new we(i))},maxTimeToLive:t?.maxTimeToLive??Rn,allowPinAuthentication:t?.allowPin??On,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...n.signInOptions({windowed:t?.windowed})})}),Ar=async()=>{await Y?.logout(),Y=null,Q.getInstance().reset(),Ot.getInstance().reset(),Rt.getInstance().reset(),Y=await Te()},Ne=()=>Y?.getIdentity(),us=async()=>(Y??await Te()).getIdentity();var Dn=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),n=async()=>{rr({message:"junoSignOutAuthTimer"}),await Ar()};return r.onmessage=async({data:i})=>{let{msg:o,data:s}=i;switch(o){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":rr({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},Q.getInstance().subscribe(i=>{if(h(i)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var Ln=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_SATELLITE_ID??t():t()},ti=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_CONTAINER??t():t()};var pu=async({idlFactory:t,satellite:e})=>{let r=A(e?.identity);return await jn({idlFactory:t,...e,identity:r})};var ei=async({asset:{data:t,filename:e,collection:r,headers:n,token:i,fullPath:o,encoding:s,description:a},actor:l,init_asset_upload:u})=>{let{batch_id:p}=await u({collection:r,full_path:o,name:e,token:b(i),encoding_type:b(s),description:b(a)}),d=19e5,f=[],y=_e()?new Blob([await t.arrayBuffer()]):t,x=0n;for(let g=0;g<y.size;g+=d){let E=y.slice(g,g+d);f.push({batchId:p,chunk:E,actor:l,orderId:x}),x++}let v=[];for await(let g of ds({uploadChunks:f}))v=[...v,...g];let k=n.find(([g,E])=>g.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await l.commit_asset_upload({batch_id:p,chunk_ids:v.map(({chunk_id:g})=>g),headers:[...n,...k??[]]})};async function*ds({uploadChunks:t,limit:e=12}){for(let r=0;r<t.length;r=r+e){let n=t.slice(r,r+e);yield await Promise.all(n.map(i=>ps(i)))}}var ps=async({batchId:t,chunk:e,actor:r,orderId:n})=>r.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:b(n)});var ri=async({satellite:t,...e})=>{let r=await T(t);await ei({actor:r,asset:e,init_asset_upload:async i=>await r.init_asset_upload(i)})},ni=async({collection:t,satellite:e,filter:r})=>{let{list_assets:n}=await T(e),{items:i,items_length:o,items_page:s,matches_length:a,matches_pages:l}=await n(t,nt(r));return{items:i.map(([u,p])=>p),items_length:o,items_page:R(s),matches_length:a,matches_pages:R(l)}},ii=async({collection:t,satellite:e,filter:r})=>{let{count_assets:n}=await T(e);return n(t,nt(r))},oi=async({collection:t,fullPath:e,satellite:r})=>(await T(r)).del_asset(t,e),si=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await T(e),n=t.map(({collection:i,fullPath:o})=>[i,o]);await r(n)},ai=async({collection:t,satellite:e,filter:r})=>{let{del_filtered_assets:n}=await T(e);return n(t,nt(r))},ci=async({collection:t,fullPath:e,satellite:r})=>{let{get_asset:n}=await T(r);return R(await n(t,e))},li=async({assets:t,satellite:e})=>{let{get_many_assets:r}=await T(e),n=t.map(({collection:o,fullPath:s})=>[o,s]);return(await r(n)).map(([o,s])=>R(s))};var ui=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Su=t=>di(t),vu=t=>di({filename:t.data.name,...t}),di=async({filename:t,data:e,collection:r,headers:n=[],fullPath:i,token:o,satellite:s,encoding:a,description:l})=>{let u=A(s?.identity),p=decodeURI(t),d=i??`/${r}/${p}`,f={...s,identity:u};return await ri({data:e,filename:p,collection:r,token:o,headers:n,fullPath:d,encoding:a,satellite:f,description:l}),{downloadUrl:pi({satellite:f,assetKey:{fullPath:d,token:o}}),fullPath:d,name:p}},Pu=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:A(e?.identity)},{items:i,...o}=await ni({collection:t,satellite:n,filter:r??{}}),s=i.map(({key:{full_path:a,token:l,name:u,owner:p,description:d},headers:f,encodings:y,created_at:x,updated_at:v})=>{let k=R(l);return{fullPath:a,description:R(d),name:u,downloadUrl:pi({satellite:n,assetKey:{fullPath:a,token:k}}),token:k,headers:f,encodings:y.reduce((g,[E,{modified:m,sha256:P,total_length:O}])=>({...g,[E]:{modified:m,sha256:ui(P),total_length:O}}),{}),owner:p.toText(),created_at:x,updated_at:v}});return{items:s,assets:s,...o}},Bu=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:A(e?.identity)};return await ii({collection:t,satellite:n,filter:r??{}})},Uu=({collection:t,fullPath:e,satellite:r})=>oi({collection:t,fullPath:e,satellite:{...r,identity:A(r?.identity)}}),ku=({assets:t,satellite:e})=>si({assets:t,satellite:{...e,identity:A(e?.identity)}}),Fu=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:A(e?.identity)};return await ai({collection:t,satellite:n,filter:r??{}})},Cu=async({satellite:t,...e})=>{let r=A(t?.identity);return await ci({...e,satellite:{...t,identity:r}})},Vu=async({satellite:t,...e})=>{let r=A(t?.identity);return await li({...e,satellite:{...t,identity:r}})},pi=({assetKey:{fullPath:t,token:e},satellite:r})=>{let n={...r,identity:A(r?.identity)};return`${Kn(n)}${t}${w(e)?`?token=${e}`:""}`};var fs=t=>{let e=t?.satelliteId??Ln();se(e,"Satellite ID is not configured. Juno cannot be initialized.");let r=t?.container??ti();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:r}},Wu=t=>ms(t),ms=async t=>{let e=fs(t);G.getInstance().set(e),await br();let r=e.workers?.auth!==void 0?Dn(e.workers.auth):void 0;return[...r?[r]:[]]},Gu=t=>Q.getInstance().subscribe(t);export{Ae as InitError,ge as InternetIdentityProvider,Ee as ListError,kn as NFIDProvider,we as SignInError,xe as SignInInitError,be as SignInUserInterruptError,Gu as authSubscribe,Bu as countAssets,Ml as countDocs,Uu as deleteAsset,Cl as deleteDoc,Fu as deleteFilteredAssets,Kl as deleteFilteredDocs,ku as deleteManyAssets,Vl as deleteManyDocs,pi as downloadUrl,Cu as getAsset,Qn as getDoc,Vu as getManyAssets,kl as getManyDocs,pu as getSatelliteExtendedActor,Wu as initJuno,ms as initSatellite,Pu as listAssets,jl as listDocs,Zn as setDoc,Fl as setManyDocs,ls as signIn,Ar as signOut,us as unsafeIdentity,Su as uploadBlob,vu as uploadFile};
|
|
16
16
|
/*! Bundled license information:
|
|
17
17
|
|
|
18
18
|
buffer/index.js:
|