@junobuild/core-standalone 0.1.11 → 0.1.13

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.
@@ -0,0 +1,2 @@
1
+ import{v as a,w as b,x as c,y as d}from"./chunk-DCSQJUQP.js";export{a as CustomPath,d as encodePath,c as fetchNodeKeys,b as request};
2
+ //# sourceMappingURL=canisterStatus-OWQH6ZT5.js.map
@@ -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-TKCY5NA5.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:
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-REWHDUNS.js.map
53
+ //# sourceMappingURL=chunk-DCSQJUQP.js.map