@junobuild/core-standalone 0.1.0 → 0.1.1
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-5OKD4GZC.js +2 -0
- package/dist/browser/{chunk-F6RH4LLT.js → chunk-YQER5335.js} +3 -3
- package/dist/browser/{chunk-F6RH4LLT.js.map → chunk-YQER5335.js.map} +3 -3
- package/dist/browser/index.js +13 -13
- package/dist/browser/index.js.map +4 -4
- package/dist/node/index.mjs +29 -29
- package/dist/node/index.mjs.map +4 -4
- package/package.json +2 -1
- package/dist/browser/canisterStatus-MTFHSECX.js +0 -2
- /package/dist/browser/{canisterStatus-MTFHSECX.js.map → canisterStatus-5OKD4GZC.js.map} +0 -0
|
@@ -14,7 +14,7 @@ variant ${t} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.displ
|
|
|
14
14
|
ic-request`),Yc=class{getPrincipal(){return this._principal||(this._principal=me.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:t}=e,n=fl(e,["body"]),i=await hn(t);return Object.assign(Object.assign({},n),{body:{content:t,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(Ke(ll,i))}})}},Pi=class{getPrincipal(){return me.anonymous()}async transformRequest(e){return Object.assign(Object.assign({},e),{body:{content:e.body}})}};var Zc=Xr(ei());var _n=()=>{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 Li;(function(r){r.Call="call"})(Li||(Li={}));function Gr(){let r=new ArrayBuffer(16),e=new DataView(r),t=_n(),n=_n(),i=_n(),s=_n();return e.setUint32(0,t),e.setUint32(4,n),e.setUint32(8,i),e.setUint32(12,s),r}var zc=BigInt(1e6),hl=60*1e3,lr=class{constructor(e){if(e<90*1e3){let c=BigInt(Date.now()+e)*zc/BigInt(1e9);this._value=c*BigInt(1e9);return}let s=BigInt(Math.floor(Date.now()+e-hl))*zc/BigInt(1e9)/BigInt(60)*BigInt(60)*BigInt(1e9);this._value=s}toCBOR(){return Zc.value.u64(this._value.toString(16),16)}toHash(){return Se(this._value)}};function _o(r=Gr){return async e=>{let t=e.request.headers;e.request.headers=t,e.endpoint==="call"&&(e.body.nonce=r())}}function Hr(r){let e=[];return r.forEach((t,n)=>{e.push([n,t])}),e}var Vr=class extends Ye{constructor(e,t){super(e),this.response=t,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}};var Mi=BigInt(4294967295),Eo=BigInt(32);function Wc(r,e=!1){return e?{h:Number(r&Mi),l:Number(r>>Eo&Mi)}:{h:Number(r>>Eo&Mi)|0,l:Number(r&Mi)|0}}function dl(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}=Wc(r[i],e);[t[i],n[i]]=[s,o]}return[t,n]}var pl=(r,e)=>BigInt(r>>>0)<<Eo|BigInt(e>>>0),ml=(r,e,t)=>r>>>t,gl=(r,e,t)=>r<<32-t|e>>>t,bl=(r,e,t)=>r>>>t|e<<32-t,wl=(r,e,t)=>r<<32-t|e>>>t,yl=(r,e,t)=>r<<64-t|e>>>t-32,xl=(r,e,t)=>r>>>t-32|e<<64-t,_l=(r,e)=>e,El=(r,e)=>r,vl=(r,e,t)=>r<<t|e>>>32-t,Il=(r,e,t)=>e<<t|r>>>32-t,Al=(r,e,t)=>e<<t-32|r>>>64-t,Bl=(r,e,t)=>r<<t-32|e>>>64-t;function Sl(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var Tl=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Nl=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Rl=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Ol=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,Ul=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),Fl=(r,e,t,n,i,s)=>e+t+n+i+s+(r/2**32|0)|0;var Pl={fromBig:Wc,split:dl,toBig:pl,shrSH:ml,shrSL:gl,rotrSH:bl,rotrSL:wl,rotrBH:yl,rotrBL:xl,rotr32H:_l,rotr32L:El,rotlSH:vl,rotlSL:Il,rotlBH:Al,rotlBL:Bl,add:Sl,add3L:Tl,add3H:Nl,add4L:Rl,add4H:Ol,add5H:Fl,add5L:Ul},le=Pl;var[Ll,Ml]=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),vo=class extends Ur{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:p,El:m,Fh:g,Fl:y,Gh:_,Gl:f,Hh:P,Hl:T}=this;return[e,t,n,i,s,o,c,a,p,m,g,y,_,f,P,T]}set(e,t,n,i,s,o,c,a,p,m,g,y,_,f,P,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=p|0,this.El=m|0,this.Fh=g|0,this.Fl=y|0,this.Gh=_|0,this.Gl=f|0,this.Hh=P|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 Y=hr[D-15]|0,I=dr[D-15]|0,G=le.rotrSH(Y,I,1)^le.rotrSH(Y,I,8)^le.shrSH(Y,I,7),j=le.rotrSL(Y,I,1)^le.rotrSL(Y,I,8)^le.shrSL(Y,I,7),Z=hr[D-2]|0,k=dr[D-2]|0,fe=le.rotrSH(Z,k,19)^le.rotrBH(Z,k,61)^le.shrSH(Z,k,6),re=le.rotrSL(Z,k,19)^le.rotrBL(Z,k,61)^le.shrSL(Z,k,6),te=le.add4L(j,re,dr[D-7],dr[D-16]),b=le.add4H(te,G,fe,hr[D-7],hr[D-16]);hr[D]=b|0,dr[D]=te|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:c,Cl:a,Dh:p,Dl:m,Eh:g,El:y,Fh:_,Fl:f,Gh:P,Gl:T,Hh:F,Hl:$}=this;for(let D=0;D<80;D++){let Y=le.rotrSH(g,y,14)^le.rotrSH(g,y,18)^le.rotrBH(g,y,41),I=le.rotrSL(g,y,14)^le.rotrSL(g,y,18)^le.rotrBL(g,y,41),G=g&_^~g&P,j=y&f^~y&T,Z=le.add5L($,I,j,Ml[D],dr[D]),k=le.add5H(Z,F,Y,G,Ll[D],hr[D]),fe=Z|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),b=n&s^n&c^s&c,v=i&o^i&a^o&a;F=P|0,$=T|0,P=_|0,T=f|0,_=g|0,f=y|0,{h:g,l:y}=le.add(p|0,m|0,k|0,fe|0),p=c|0,m=a|0,c=s|0,a=o|0,s=n|0,o=i|0;let q=le.add3L(fe,te,v);n=le.add3H(q,k,re,b),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:p,l:m}=le.add(this.Dh|0,this.Dl|0,p|0,m|0),{h:g,l:y}=le.add(this.Eh|0,this.El|0,g|0,y|0),{h:_,l:f}=le.add(this.Fh|0,this.Fl|0,_|0,f|0),{h:P,l:T}=le.add(this.Gh|0,this.Gl|0,P|0,T|0),{h:F,l:$}=le.add(this.Hh|0,this.Hl|0,F|0,$|0),this.set(n,i,s,o,c,a,p,m,g,y,_,f,P,T,F,$)}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 Kc=Qr(()=>new vo);var Nt=BigInt(0),at=BigInt(1),Di=BigInt(2),Dl=BigInt(8),kl={zip215:!0};function ql(r){let e=Si(r);return St(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Xc(r){let e=ql(r),{Fp:t,n,prehash:i,hash:s,randomBytes:o,nByteLength:c,h:a}=e,p=Di<<BigInt(c*8)-at,m=t.create,g=Dt(e.n,e.nBitLength),y=e.uvRatio||((O,U)=>{try{return{isValid:!0,value:t.sqrt(O*t.inv(U))}}catch{return{isValid:!1,value:Nt}}}),_=e.adjustScalarBytes||(O=>O),f=e.domain||((O,U,C)=>{if(ir("phflag",C),U.length||C)throw new Error("Contexts/pre-hash are not supported");return O});function P(O,U){Bt("coordinate "+O,U,Nt,p)}function T(O){if(!(O instanceof D))throw new Error("ExtendedPoint expected")}let F=Zt((O,U)=>{let{ex:C,ey:W,ez:ue}=O,ce=O.is0();U==null&&(U=ce?Dl:t.inv(ue));let V=m(C*U),R=m(W*U),h=m(ue*U);if(ce)return{x:Nt,y:at};if(h!==at)throw new Error("invZ was invalid");return{x:V,y:R}}),$=Zt(O=>{let{a:U,d:C}=e;if(O.is0())throw new Error("bad point: ZERO");let{ex:W,ey:ue,ez:ce,et:V}=O,R=m(W*W),h=m(ue*ue),Q=m(ce*ce),J=m(Q*Q),ae=m(R*U),X=m(Q*m(ae+h)),u=m(J+m(C*m(R*h)));if(X!==u)throw new Error("bad point: equation left != right (1)");let l=m(W*ue),d=m(ce*V);if(l!==d)throw new Error("bad point: equation left != right (2)");return!0});class D{constructor(U,C,W,ue){this.ex=U,this.ey=C,this.ez=W,this.et=ue,P("x",U),P("y",C),P("z",W),P("t",ue),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(U){if(U instanceof D)throw new Error("extended point not allowed");let{x:C,y:W}=U||{};return P("x",C),P("y",W),new D(C,W,at,m(C*W))}static normalizeZ(U){let C=t.invertBatch(U.map(W=>W.ez));return U.map((W,ue)=>W.toAffine(C[ue])).map(D.fromAffine)}static msm(U,C){return Bi(D,g,U,C)}_setWindowSize(U){G.setWindowSize(this,U)}assertValidity(){$(this)}equals(U){T(U);let{ex:C,ey:W,ez:ue}=this,{ex:ce,ey:V,ez:R}=U,h=m(C*R),Q=m(ce*ue),J=m(W*R),ae=m(V*ue);return h===Q&&J===ae}is0(){return this.equals(D.ZERO)}negate(){return new D(m(-this.ex),this.ey,this.ez,m(-this.et))}double(){let{a:U}=e,{ex:C,ey:W,ez:ue}=this,ce=m(C*C),V=m(W*W),R=m(Di*m(ue*ue)),h=m(U*ce),Q=C+W,J=m(m(Q*Q)-ce-V),ae=h+V,X=ae-R,u=h-V,l=m(J*X),d=m(ae*u),B=m(J*u),E=m(X*ae);return new D(l,d,E,B)}add(U){T(U);let{a:C,d:W}=e,{ex:ue,ey:ce,ez:V,et:R}=this,{ex:h,ey:Q,ez:J,et:ae}=U;if(C===BigInt(-1)){let H=m((ce-ue)*(Q+h)),K=m((ce+ue)*(Q-h)),ie=m(K-H);if(ie===Nt)return this.double();let de=m(V*Di*ae),Ee=m(R*Di*J),Ne=Ee+de,he=K+H,oe=Ee-de,Me=m(Ne*ie),Xt=m(he*oe),gr=m(Ne*oe),br=m(ie*he);return new D(Me,Xt,br,gr)}let X=m(ue*h),u=m(ce*Q),l=m(R*W*ae),d=m(V*J),B=m((ue+ce)*(h+Q)-X-u),E=d-l,A=d+l,M=m(u-C*X),w=m(B*E),S=m(A*M),L=m(B*M),N=m(E*A);return new D(w,S,N,L)}subtract(U){return this.add(U.negate())}wNAF(U){return G.wNAFCached(this,U,D.normalizeZ)}multiply(U){let C=U;Bt("scalar",C,at,n);let{p:W,f:ue}=this.wNAF(C);return D.normalizeZ([W,ue])[0]}multiplyUnsafe(U){let C=U;return Bt("scalar",C,Nt,n),C===Nt?I:this.equals(I)||C===at?this:this.equals(Y)?this.wNAF(C).p:G.unsafeLadder(this,C)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return G.unsafeLadder(this,n).is0()}toAffine(U){return F(this,U)}clearCofactor(){let{h:U}=e;return U===at?this:this.multiplyUnsafe(U)}static fromHex(U,C=!1){let{d:W,a:ue}=e,ce=t.BYTES;U=Ce("pointHex",U,ce),ir("zip215",C);let V=U.slice(),R=U[ce-1];V[ce-1]=R&-129;let h=sr(V),Q=C?p:t.ORDER;Bt("pointHex.y",h,Nt,Q);let J=m(h*h),ae=m(J-at),X=m(W*J-ue),{isValid:u,value:l}=y(ae,X);if(!u)throw new Error("Point.fromHex: invalid y coordinate");let d=(l&at)===at,B=(R&128)!==0;if(!C&&l===Nt&&B)throw new Error("Point.fromHex: x=0 and x_0=1");return B!==d&&(l=m(-l)),D.fromAffine({x:l,y:h})}static fromPrivateKey(U){return k(U).point}toRawBytes(){let{x:U,y:C}=this.toAffine(),W=Ir(C,t.BYTES);return W[W.length-1]|=U&at?128:0,W}toHex(){return At(this.toRawBytes())}}D.BASE=new D(e.Gx,e.Gy,at,m(e.Gx*e.Gy)),D.ZERO=new D(Nt,at,at,Nt);let{BASE:Y,ZERO:I}=D,G=Ai(D,c*8);function j(O){return Be(O,n)}function Z(O){return j(sr(O))}function k(O){let U=c;O=Ce("private key",O,U);let C=Ce("hashed private key",s(O),2*U),W=_(C.slice(0,U)),ue=C.slice(U,2*U),ce=Z(W),V=Y.multiply(ce),R=V.toRawBytes();return{head:W,prefix:ue,scalar:ce,point:V,pointBytes:R}}function fe(O){return k(O).pointBytes}function re(O=new Uint8Array,...U){let C=Ie(...U);return Z(s(f(C,Ce("context",O),!!i)))}function te(O,U,C={}){O=Ce("message",O),i&&(O=i(O));let{prefix:W,scalar:ue,pointBytes:ce}=k(U),V=re(C.context,W,O),R=Y.multiply(V).toRawBytes(),h=re(C.context,R,ce,O),Q=j(V+h*ue);Bt("signature.s",Q,Nt,n);let J=Ie(R,Ir(Q,t.BYTES));return Ce("result",J,c*2)}let b=kl;function v(O,U,C,W=b){let{context:ue,zip215:ce}=W,V=t.BYTES;O=Ce("signature",O,2*V),U=Ce("message",U),ce!==void 0&&ir("zip215",ce),i&&(U=i(U));let R=sr(O.slice(V,2*V)),h,Q,J;try{h=D.fromHex(C,ce),Q=D.fromHex(O.slice(0,V),ce),J=Y.multiplyUnsafe(R)}catch{return!1}if(!ce&&h.isSmallOrder())return!1;let ae=re(ue,Q.toRawBytes(),h.toRawBytes(),U);return Q.add(h.multiplyUnsafe(ae)).subtract(J).clearCofactor().equals(D.ZERO)}return Y._setWindowSize(8),{CURVE:e,getPublicKey:fe,sign:te,verify:v,ExtendedPoint:D,utils:{getExtendedPublicKey:k,randomPrivateKey:()=>o(t.BYTES),precompute(O=8,U=D.BASE){return U._setWindowSize(O),U.multiply(BigInt(3)),U}}}}var Io=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Qc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Vp=BigInt(0),Cl=BigInt(1),Jc=BigInt(2),jp=BigInt(3),$l=BigInt(5),Gl=BigInt(8);function Hl(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),i=BigInt(80),s=Io,c=r*r%s*r%s,a=Tt(c,Jc,s)*c%s,p=Tt(a,Cl,s)*r%s,m=Tt(p,$l,s)*p%s,g=Tt(m,e,s)*m%s,y=Tt(g,t,s)*g%s,_=Tt(y,n,s)*y%s,f=Tt(_,i,s)*_%s,P=Tt(f,i,s)*_%s,T=Tt(P,e,s)*m%s;return{pow_p_5_8:Tt(T,Jc,s)*r%s,b2:c}}function Vl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function jl(r,e){let t=Io,n=Be(e*e*e,t),i=Be(n*n*e,t),s=Hl(r*i).pow_p_5_8,o=Be(r*n*s,t),c=Be(e*o*o,t),a=o,p=Be(o*Qc,t),m=c===r,g=c===Be(-r,t),y=c===Be(-r*Qc,t);return m&&(o=a),(g||y)&&(o=p),Rc(o,t)&&(o=Be(-o,t)),{isValid:m||g,value:o}}var Yl=Dt(Io,void 0,!0),zl={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Yl,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Gl,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Kc,randomBytes:Mn,adjustScalarBytes:Vl,uvRatio:jl},eu=Xc(zl);var tu=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},rt=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)},Qe,En,ru,nu,ki=class{constructor(e={}){Qe.set(this,void 0),En.set(this,void 0),this[ru]=this.entries.bind(this),this[nu]="ExpirableMap";let{source:t=[],expirationTime:n=10*60*1e3}=e,i=Date.now();tu(this,Qe,new Map([...t].map(([s,o])=>[s,{value:o,timestamp:i}])),"f"),tu(this,En,n,"f")}prune(){let e=Date.now();for(let[t,n]of rt(this,Qe,"f").entries())e-n.timestamp>rt(this,En,"f")&&rt(this,Qe,"f").delete(t);return this}set(e,t){this.prune();let n={value:t,timestamp:Date.now()};return rt(this,Qe,"f").set(e,n),this}get(e){let t=rt(this,Qe,"f").get(e);if(t!==void 0){if(Date.now()-t.timestamp>rt(this,En,"f")){rt(this,Qe,"f").delete(e);return}return t.value}}clear(){rt(this,Qe,"f").clear()}entries(){let e=rt(this,Qe,"f").entries();return function*(){for(let[n,i]of e)yield[n,i.value]}()}values(){let e=rt(this,Qe,"f").values();return function*(){for(let n of e)yield n.value}()}keys(){return rt(this,Qe,"f").keys()}forEach(e,t){for(let[n,i]of rt(this,Qe,"f").entries())e.call(t,i.value,n,this)}has(e){return rt(this,Qe,"f").has(e)}delete(e){return rt(this,Qe,"f").delete(e)}get size(){return rt(this,Qe,"f").size}};Qe=new WeakMap,En=new WeakMap,ru=Symbol.iterator,nu=Symbol.toStringTag;var iu=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)")},su=(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)")},Ao=(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)")},Zl=(r,e)=>{let t=Ao(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)")},Wp=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),Bo=Uint8Array.from([48,5,6,3,43,101,112]),Kp=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);function ou(r,e){let t=2+iu(r.byteLength+1),n=e.byteLength+t+r.byteLength,i=0,s=new Uint8Array(1+iu(n)+n);return s[i++]=48,i+=su(s,i,n),s.set(e,i),i+=e.byteLength,s[i++]=3,i+=su(s,i,r.byteLength+1),s[i++]=0,s.set(new Uint8Array(r),i),s}var au=(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+=Ao(i,t),!tn(i.slice(t,t+e.byteLength),e))throw new Error("Not the expected OID.");t+=e.byteLength,n(3,"bit string");let s=Zl(i,t)-1;t+=Ao(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 cu=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},uu=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)},qi,Ci,vn=class r{constructor(e){if(qi.set(this,void 0),Ci.set(this,void 0),e.byteLength!==r.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");cu(this,qi,e,"f"),cu(this,Ci,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 ou(e,Bo).buffer}static derDecode(e){let t=au(e,Bo);if(t.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return t}get rawKey(){return uu(this,qi,"f")}get derKey(){return uu(this,Ci,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};qi=new WeakMap,Ci=new WeakMap;vn.RAW_KEY_LENGTH=32;var So=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))}},$i=class extends So{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 kt=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},Je=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)},qt,Gi,Hi,Vi,ji,Yi,zi,Zi,jr;var In=class r{constructor(e=r.default){qt.set(this,void 0),Gi.set(this,void 0),Hi.set(this,void 0),Vi.set(this,void 0),ji.set(this,void 0),Yi.set(this,void 0),zi.set(this,void 0),Zi.set(this,void 0),jr.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;kt(this,qt,t,"f"),kt(this,Gi,n,"f"),kt(this,Hi,i,"f"),kt(this,Vi,s,"f"),kt(this,Zi,a,"f"),kt(this,ji,a.now(),"f"),kt(this,Yi,o,"f"),kt(this,zi,c,"f")}get ellapsedTimeInMsec(){return Je(this,Zi,"f").now()-Je(this,ji,"f")}get currentInterval(){return Je(this,qt,"f")}get count(){return Je(this,jr,"f")}get randomValueFromInterval(){let e=Je(this,Gi,"f")*Je(this,qt,"f"),t=Je(this,qt,"f")-e,n=Je(this,qt,"f")+e;return Math.random()*(n-t)+t}incrementCurrentInterval(){var e;return kt(this,qt,Math.min(Je(this,qt,"f")*Je(this,Hi,"f"),Je(this,Vi,"f")),"f"),kt(this,jr,(e=Je(this,jr,"f"),e++,e),"f"),Je(this,qt,"f")}next(){return this.ellapsedTimeInMsec>=Je(this,Yi,"f")||Je(this,jr,"f")>=Je(this,zi,"f")?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};qt=new WeakMap,Gi=new WeakMap,Hi=new WeakMap,Vi=new WeakMap,ji=new WeakMap,Yi=new WeakMap,zi=new WeakMap,Zi=new WeakMap,jr=new WeakMap;In.default={initialInterval:500,randomizationFactor:.5,multiplier:1.5,maxInterval:6e4,maxElapsedTime:9e5,maxIterations:10,date:Date};var nt=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},ee=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)},$t,Ct,pr,Zr,An,Bn,Rt,Ki,Ot,Br,Sr,Sn,Yr,zr,Tr,Nr,du,Xi,Qi,fu;(function(r){r.Received="received",r.Processing="processing",r.Replied="replied",r.Rejected="rejected",r.Unknown="unknown",r.Done="done"})(fu||(fu={}));var Wi=60*1e3,Kl="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae",pu="aaaaa-aa",Xl="ic0.app",Ql=".ic0.app",Jl="icp0.io",eh=".icp0.io",th="icp-api.io",rh=".icp-api.io",Tn=class extends Ye{constructor(e){super(e),this.message=e}},Wr=class extends Ye{constructor(e){super(e),this.message=e}};function nh(){let r;if(typeof window<"u")if(window.fetch)r=window.fetch.bind(window);else throw new Tn("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 Tn("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 Tn("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context.")}function ih(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 lu=class r{constructor(e={}){var t;$t.add(this),Ct.set(this,void 0),pr.set(this,void 0),Zr.set(this,void 0),An.set(this,void 0),Bn.set(this,0),Rt.set(this,void 0),Ki.set(this,!1),Ot.set(this,void 0),Br.set(this,void 0),Sr.set(this,void 0),this._isAgent=!0,this.config={},Sn.set(this,0),this.log=new $i,Yr.set(this,[]),zr.set(this,[]),Tr.set(this,new ki({expirationTime:5*60*1e3})),Nr.set(this,!0),Qi.set(this,(s,o)=>{if(ee(this,Nr,"f")===!1)return s;if(!o)throw new lt("Invalid signature from replica signed query: no matching node key found.");let{status:c,signatures:a=[],requestId:p}=s,m=new TextEncoder().encode("\vic-response");for(let g of a){let{timestamp:y,identity:_}=g,f=me.fromUint8Array(_).toText(),P;if(c==="replied"){let{reply:Y}=s;P=dn({status:c,reply:Y,timestamp:BigInt(y),request_id:p})}else if(c==="rejected"){let{reject_code:Y,reject_message:I,error_code:G}=s;P=dn({status:c,reject_code:Y,reject_message:I,error_code:G,timestamp:BigInt(y),request_id:p})}else throw new Error(`Unknown status: ${c}`);let T=Ke(m,new Uint8Array(P)),F=o?.nodeKeys.get(f);if(!F)throw new lt("Invalid signature from replica signed query: no matching node key found.");let $=vn.fromDer(F).rawKey;if(eu.verify(g.signature,new Uint8Array(T),new Uint8Array($)))return s;throw new lt(`Invalid signature from replica ${f} signed query.`)}return s}),this.config=e,nt(this,pr,e.fetch||nh()||fetch.bind(globalThis),"f"),nt(this,Zr,e.fetchOptions,"f"),nt(this,An,e.callOptions,"f"),this.rootKey=e.rootKey?e.rootKey:yr(Kl);let n=ih(e.host);this.host=new URL(n),e.verifyQuerySignatures!==void 0&&nt(this,Nr,e.verifyQuerySignatures,"f"),nt(this,Ot,(t=e.retryTimes)!==null&&t!==void 0?t:3,"f");let i=()=>new In({maxIterations:ee(this,Ot,"f")});if(nt(this,Br,e.backoffStrategy||i,"f"),this.host.hostname.endsWith(Ql)?this.host.hostname=Xl:this.host.hostname.endsWith(eh)?this.host.hostname=Jl:this.host.hostname.endsWith(rh)&&(this.host.hostname=th),e.credentials){let{name:s,password:o}=e.credentials;nt(this,Rt,`${s}${o?":"+o:""}`,"f")}if(nt(this,Ct,Promise.resolve(e.identity||new Pi),"f"),e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes>5)throw new Ye(`The maximum ingress expiry time is 5 minutes. Provided ingress expiry time is ${e.ingressExpiryInMinutes} minutes.`);if(e.ingressExpiryInMinutes&&e.ingressExpiryInMinutes<=0)throw new Ye(`Ingress expiry time must be greater than 0. Provided ingress expiry time is ${e.ingressExpiryInMinutes} minutes.`);nt(this,Sr,e.ingressExpiryInMinutes||5,"f"),this.addTransform("update",_o(Gr)),e.useQueryNonces&&this.addTransform("query",_o(Gr)),e.logToConsole&&this.log.subscribe(s=>{s.level==="error"?console.error(s.message):s.level==="warn"?console.warn(s.message):console.log(s.message)})}get waterMark(){return ee(this,Sn,"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 Ye("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=ee(this,zr,"f").findIndex(s=>(s.priority||0)<n);ee(this,zr,"f").splice(i>=0?i:ee(this,zr,"f").length,0,Object.assign(t,{priority:n}))}else if(e==="query"){let i=ee(this,Yr,"f").findIndex(s=>(s.priority||0)<n);ee(this,Yr,"f").splice(i>=0?i:ee(this,Yr,"f").length,0,Object.assign(t,{priority:n}))}}async getPrincipal(){if(!ee(this,Ct,"f"))throw new Wr("This identity has expired due this application's security policy. Please refresh your authentication.");return(await ee(this,Ct,"f")).getPrincipal()}async call(e,t,n){var i;let s=(i=t.callSync)!==null&&i!==void 0?i:!0,o=await(n!==void 0?await n:await ee(this,Ct,"f"));if(!o)throw new Wr("This identity has expired due this application's security policy. Please refresh your authentication.");let c=me.from(e),a=t.effectiveCanisterId?me.from(t.effectiveCanisterId):c,p=o.getPrincipal()||me.anonymous(),m=new lr(ee(this,Sr,"f")*Wi);Math.abs(ee(this,Bn,"f"))>1e3*30&&(m=new lr(ee(this,Sr,"f")*Wi+ee(this,Bn,"f")));let g={request_type:Li.Call,canister_id:c,method_name:t.methodName,arg:t.arg,sender:p,ingress_expiry:m},y=await this._transform({request:{body:null,method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},ee(this,Rt,"f")?{Authorization:"Basic "+btoa(ee(this,Rt,"f"))}:{})},endpoint:"call",body:g}),_=y.body.nonce?f(y.body.nonce):void 0;g.nonce=_;function f(F){return new Uint8Array(F)}y=await o.transformRequest(y);let P=ri(y.body),T=ee(this,Br,"f").call(this);try{let F=()=>(this.log.print(`fetching "/api/v3/canister/${a.toText()}/call" with request:`,y),ee(this,pr,"f").call(this,""+new URL(`/api/v3/canister/${a.toText()}/call`,this.host),Object.assign(Object.assign(Object.assign({},ee(this,An,"f")),y.request),{body:P}))),$=()=>(this.log.print(`fetching "/api/v2/canister/${a.toText()}/call" with request:`,y),ee(this,pr,"f").call(this,""+new URL(`/api/v2/canister/${a.toText()}/call`,this.host),Object.assign(Object.assign(Object.assign({},ee(this,An,"f")),y.request),{body:P}))),D=ee(this,$t,"m",Xi).call(this,{request:s?F:$,backoff:T,tries:0}),[Y,I]=await Promise.all([D,hn(g)]),G=await Y.arrayBuffer(),j=Y.status===200&&G.byteLength>0?gt(G):null;if(j&&"certificate"in j){let Z=await this.parseTimeFromResponse({certificate:j.certificate});nt(this,Sn,Z,"f")}return{requestId:I,response:{ok:Y.ok,status:Y.status,statusText:Y.statusText,body:j,headers:Hr(Y.headers)},requestDetails:g}}catch(F){if(F.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);throw this.log.error("Error while making call:",F),F}}async query(e,t,n){let i=ee(this,Br,"f").call(this),s=t.effectiveCanisterId?me.from(t.effectiveCanisterId):me.from(e);this.log.print(`ecid ${s.toString()}`),this.log.print(`canisterId ${e.toString()}`);let o=async()=>{let _=await(n!==void 0?n:ee(this,Ct,"f"));if(!_)throw new Wr("This identity has expired due this application's security policy. Please refresh your authentication.");let f=me.from(e),P=_?.getPrincipal()||me.anonymous(),T={request_type:"query",canister_id:f,method_name:t.methodName,arg:t.arg,sender:P,ingress_expiry:new lr(ee(this,Sr,"f")*Wi)},F=await hn(T),$=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},ee(this,Rt,"f")?{Authorization:"Basic "+btoa(ee(this,Rt,"f"))}:{})},endpoint:"read",body:T});$=await _?.transformRequest($);let D=ri($.body),Y={canister:f.toText(),ecid:s,transformedRequest:$,body:D,requestId:F,backoff:i,tries:0};return{requestDetails:T,query:await ee(this,$t,"m",du).call(this,Y)}},c=async()=>{if(!ee(this,Nr,"f"))return;let _=ee(this,Tr,"f").get(s.toString());return _||(await this.fetchSubnetKeys(s.toString()),ee(this,Tr,"f").get(s.toString()))},[a,p]=await Promise.all([o(),c()]),{requestDetails:m,query:g}=a,y=Object.assign(Object.assign({},g),{requestDetails:m});if(this.log.print("Query response:",y),!ee(this,Nr,"f"))return y;try{return ee(this,Qi,"f").call(this,y,p)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),ee(this,Tr,"f").delete(e.toString()),await this.fetchSubnetKeys(s.toString());let f=ee(this,Tr,"f").get(e.toString());if(!f)throw new lt("Invalid signature from replica signed query: no matching node key found.");return ee(this,Qi,"f").call(this,y,f)}}async createReadStateRequest(e,t){let n=await(t!==void 0?await t:await ee(this,Ct,"f"));if(!n)throw new Wr("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"},ee(this,Rt,"f")?{Authorization:"Basic "+btoa(ee(this,Rt,"f"))}:{})},endpoint:"read_state",body:{request_type:"read_state",paths:e.paths,sender:i,ingress_expiry:new lr(ee(this,Sr,"f")*Wi)}});return n?.transformRequest(s)}async readState(e,t,n,i){let s=typeof e=="string"?me.fromText(e):e,o=i??await this.createReadStateRequest(t,n),c=Object.assign(Object.assign({},o.body),{ingress_expiry:new lr(3e5)}),a=ri(c);this.log.print(`fetching "/api/v2/canister/${s}/read_state" with request:`,o);let p=ee(this,Br,"f").call(this);try{let m=await ee(this,$t,"m",Xi).call(this,{request:()=>ee(this,pr,"f").call(this,""+new URL(`/api/v2/canister/${s.toString()}/read_state`,this.host),Object.assign(Object.assign(Object.assign({},ee(this,Zr,"f")),o.request),{body:a})),backoff:p,tries:0});if(!m.ok)throw new Error(`Server returned an error:
|
|
15
15
|
Code: ${m.status} (${m.statusText})
|
|
16
16
|
Body: ${await m.text()}
|
|
17
|
-
`);let g=gt(await m.arrayBuffer());this.log.print("Read state response:",g);let y=await this.parseTimeFromResponse(g);return y>0&&(this.log.print("Read state response time:",y),nt(this,Sn,y,"f")),g}catch(m){throw this.log.error("Caught exception while attempting to read state",m),m}}async parseTimeFromResponse(e){let t;if(e.certificate){let n=gt(e.certificate);if(n&&"tree"in n)t=n.tree;else throw new Error("Could not decode time from response");let i=mr(["time"],t);if(i.status!==Le.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=$r(ls(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){let t=await import("./canisterStatus-
|
|
17
|
+
`);let g=gt(await m.arrayBuffer());this.log.print("Read state response:",g);let y=await this.parseTimeFromResponse(g);return y>0&&(this.log.print("Read state response time:",y),nt(this,Sn,y,"f")),g}catch(m){throw this.log.error("Caught exception while attempting to read state",m),m}}async parseTimeFromResponse(e){let t;if(e.certificate){let n=gt(e.certificate);if(n&&"tree"in n)t=n.tree;else throw new Error("Could not decode time from response");let i=mr(["time"],t);if(i.status!==Le.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=$r(ls(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){let t=await import("./canisterStatus-5OKD4GZC.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 s=(await t.request({canisterId:e??me.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),agent:this,paths:["time"]})).get("time");s&&nt(this,Bn,Number(s)-Number(n),"f")}catch(i){this.log.error("Caught exception while attempting to sync time",i)}}async status(){let e=ee(this,Rt,"f")?{Authorization:"Basic "+btoa(ee(this,Rt,"f"))}:{};this.log.print('fetching "/api/v2/status"');let t=ee(this,Br,"f").call(this),n=await ee(this,$t,"m",Xi).call(this,{backoff:t,request:()=>ee(this,pr,"f").call(this,""+new URL("/api/v2/status",this.host),Object.assign({headers:e},ee(this,Zr,"f"))),tries:0});return gt(await n.arrayBuffer())}async fetchRootKey(){if(!ee(this,Ki,"f")){let e=await this.status();this.rootKey=e.root_key,nt(this,Ki,!0,"f")}return this.rootKey}invalidateIdentity(){nt(this,Ct,null,"f")}replaceIdentity(e){nt(this,Ct,Promise.resolve(e),"f")}async fetchSubnetKeys(e){let t=me.from(e),i=(await hu({canisterId:t,paths:["subnet"],agent:this})).get("subnet");if(i&&typeof i=="object"&&"nodeKeys"in i)return ee(this,Tr,"f").set(t.toText(),i),i}_transform(e){let t=Promise.resolve(e);if(e.endpoint==="call")for(let n of ee(this,zr,"f"))t=t.then(i=>n(i).then(s=>s||i));else for(let n of ee(this,Yr,"f"))t=t.then(i=>n(i).then(s=>s||i));return t}};Ct=new WeakMap,pr=new WeakMap,Zr=new WeakMap,An=new WeakMap,Bn=new WeakMap,Rt=new WeakMap,Ki=new WeakMap,Ot=new WeakMap,Br=new WeakMap,Sr=new WeakMap,Sn=new WeakMap,Yr=new WeakMap,zr=new WeakMap,Tr=new WeakMap,Nr=new WeakMap,Qi=new WeakMap,$t=new WeakSet,du=async function r(e){var t,n;let{ecid:i,transformedRequest:s,body:o,requestId:c,backoff:a,tries:p}=e,m=p===0?0:a.next();if(this.log.print(`fetching "/api/v2/canister/${i.toString()}/query" with tries:`,{tries:p,backoff:a,delay:m}),m===null)throw new Ye(`Timestamp failed to pass the watermark after retrying the configured ${ee(this,Ot,"f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);m>0&&await new Promise(f=>setTimeout(f,m));let g;try{this.log.print(`fetching "/api/v2/canister/${i.toString()}/query" with request:`,s);let f=await ee(this,pr,"f").call(this,""+new URL(`/api/v2/canister/${i.toString()}/query`,this.host),Object.assign(Object.assign(Object.assign({},ee(this,Zr,"f")),s.request),{body:o}));if(f.status===200){let P=gt(await f.arrayBuffer());g=Object.assign(Object.assign({},P),{httpDetails:{ok:f.ok,status:f.status,statusText:f.statusText,headers:Hr(f.headers)},requestId:c})}else throw new Vr(`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:Hr(f.headers)})}catch(f){if(p<ee(this,Ot,"f"))return this.log.warn(`Caught exception while attempting to make query:
|
|
@@ -24,7 +24,7 @@ ic-request`),Yc=class{getPrincipal(){return this._principal||(this._principal=me
|
|
|
24
24
|
Retrying request.`),await ee(this,$t,"m",r).call(this,{request:t,backoff:n,tries:i+1});throw p}if(o.ok)return o;let c=await o.clone().text(),a=`Server returned an error:
|
|
25
25
|
Code: ${o.status} (${o.statusText})
|
|
26
26
|
Body: ${c}
|
|
27
|
-
`;if(o.status===404&&o.url.includes("api/v3"))throw new Vr("v3 api not supported. Fall back to v2",{ok:o.ok,status:o.status,statusText:o.statusText,headers:Hr(o.headers)});if(i<ee(this,Ot,"f"))return await ee(this,$t,"m",r).call(this,{request:t,backoff:n,tries:i+1});throw new Vr(a,{ok:o.ok,status:o.status,statusText:o.statusText,headers:Hr(o.headers)})};var mu;(function(r){r.Error="err",r.GetPrincipal="gp",r.GetPrincipalResponse="gpr",r.Query="q",r.QueryResponse="qr",r.Call="c",r.CallResponse="cr",r.ReadState="rs",r.ReadStateResponse="rsr",r.Status="s",r.StatusResponse="sr"})(mu||(mu={}));function A1(){let r=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.ic.agent:globalThis.ic.agent:window.ic.agent;if(!r)throw new Error("No Agent could be found.");return r}var lt=class extends Ye{constructor(e){super(`Invalid certificate: ${e}`)}},ht;(function(r){r[r.Empty=0]="Empty",r[r.Fork=1]="Fork",r[r.Labeled=2]="Labeled",r[r.Leaf=3]="Leaf",r[r.Pruned=4]="Pruned"})(ht||(ht={}));function sh(r,e){let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<t.length;i++)if(t[i]>n[i])return!0;return!1}var ts=class r{constructor(e,t,n,i,s=5){this._rootKey=t,this._canisterId=n,this._blsVerify=i,this._maxAgeInMinutes=s,this.cert=gt(new Uint8Array(e))}static async create(e){let t=r.createUnverified(e);return await t.verify(),t}static createUnverified(e){let t=e.blsVerify;return t||(t=jc),new r(e.certificate,e.rootKey,e.canisterId,t,e.maxAgeInMinutes)}lookup(e){return mr(e,this.cert.tree)}lookup_label(e){return this.lookup([e])}async verify(){let e=await Ji(this.cert.tree),t=await this._checkDelegationAndGetKey(this.cert.delegation),n=this.cert.signature,i=ah(t),s=Ke(Rn("ic-state-root"),e),o=!1,c=rs(this.lookup(["time"]));if(!c)throw new lt("Certificate does not contain a time");let a=5*60*1e3,p=this._maxAgeInMinutes*60*1e3,m=Date.now(),g=m-p,y=m+a,_=$r(c);if(_.getTime()<g)throw new lt(`Certificate is signed more than ${this._maxAgeInMinutes} minutes in the past. Certificate time: `+_.toISOString()+" Current time: "+new Date(m).toISOString());if(_.getTime()>y)throw new lt("Certificate is signed more than 5 minutes in the future. Certificate time: "+_.toISOString()+" Current time: "+new Date(m).toISOString());try{o=await this._blsVerify(new Uint8Array(i),new Uint8Array(n),new Uint8Array(s))}catch{o=!1}if(!o)throw new lt("Signature verification failed")}async _checkDelegationAndGetKey(e){if(!e)return this._rootKey;let t=await r.createUnverified({certificate:e.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,maxAgeInMinutes:1/0});if(t.cert.delegation)throw new lt("Delegation certificates cannot be nested");if(await t.verify(),this._canisterId.toString()!==pu&&!To({canisterId:this._canisterId,subnetId:me.fromUint8Array(new Uint8Array(e.subnet_id)),tree:t.cert.tree}))throw new lt(`Canister ${this._canisterId} not in range of delegations for subnet 0x${ct(e.subnet_id)}`);let n=rs(t.lookup(["subnet",e.subnet_id,"public_key"]));if(!n)throw new Error(`Could not find subnet key for subnet 0x${ct(e.subnet_id)}`);return n}},Nn=yr("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),oh=96;function ah(r){let e=Nn.byteLength+oh;if(r.byteLength!==e)throw new TypeError(`BLS DER-encoded public key must be ${e} bytes long`);let t=r.slice(0,Nn.byteLength);if(!tn(t,Nn))throw new TypeError(`BLS DER-encoded public key is invalid. Expect the following prefix: ${Nn}, but get ${t}`);return r.slice(Nn.byteLength)}function rs(r){if(r.status===Le.Found){if(r.value instanceof ArrayBuffer)return r.value;if(r.value instanceof Uint8Array)return r.value.buffer}}async function Ji(r){switch(r[0]){case ht.Empty:return bt(Rn("ic-hashtree-empty"));case ht.Pruned:return r[1];case ht.Leaf:return bt(Ke(Rn("ic-hashtree-leaf"),r[1]));case ht.Labeled:return bt(Ke(Rn("ic-hashtree-labeled"),r[1],await Ji(r[2])));case ht.Fork:return bt(Ke(Rn("ic-hashtree-fork"),await Ji(r[1]),await Ji(r[2])));default:throw new Error("unreachable")}}function Rn(r){let e=new Uint8Array([r.length]),t=new TextEncoder().encode(r);return Ke(e,t)}var Le;(function(r){r.Unknown="unknown",r.Absent="absent",r.Found="found"})(Le||(Le={}));var Kt;(function(r){r.Less="less",r.Greater="greater"})(Kt||(Kt={}));function mr(r,e){if(r.length===0)switch(e[0]){case ht.Leaf:{if(!e[1])throw new Error("Invalid tree structure for leaf");return e[1]instanceof ArrayBuffer?{status:Le.Found,value:e[1]}:e[1]instanceof Uint8Array?{status:Le.Found,value:e[1].buffer}:{status:Le.Found,value:e[1]}}default:return{status:Le.Found,value:e}}let t=typeof r[0]=="string"?new TextEncoder().encode(r[0]):r[0],n=es(t,e);switch(n.status){case Le.Found:return mr(r.slice(1),n.value);case Kt.Greater:case Kt.Less:return{status:Le.Absent};default:return n}}function ns(r){switch(r[0]){case ht.Empty:return[];case ht.Fork:return ns(r[1]).concat(ns(r[2]));default:return[r]}}function es(r,e){switch(e[0]){case ht.Labeled:return sh(r,e[1])?{status:Kt.Greater}:tn(r,e[1])?{status:Le.Found,value:e[2]}:{status:Kt.Less};case ht.Fork:let t=es(r,e[1]);switch(t.status){case Kt.Greater:{let n=es(r,e[2]);return n.status===Kt.Less?{status:Le.Absent}:n}case Le.Unknown:{let n=es(r,e[2]);return n.status===Kt.Less?{status:Le.Unknown}:n}default:return t}case ht.Pruned:return{status:Le.Unknown};default:return{status:Le.Absent}}}function To(r){let{canisterId:e,subnetId:t,tree:n}=r,i=mr(["subnet",t.toUint8Array(),"canister_ranges"],n);if(i.status!==Le.Found||!(i.value instanceof ArrayBuffer))throw new Error(`Could not find canister ranges for subnet ${t}`);return gt(i.value).map(a=>[me.fromUint8Array(a[0]),me.fromUint8Array(a[1])]).some(a=>a[0].ltEq(e)&&a[1].gtEq(e))}var gu=class{constructor(e,t,n){this.key=e,this.path=t,this.decodeStrategy=n}},hu=async r=>{let{agent:e,paths:t}=r,n=me.from(r.canisterId),i=[...new Set(t)],s=i.map(a=>bu(a,n)),o=new Map,c=i.map((a,p)=>(async()=>{var m;try{let g=await e.readState(n,{paths:[s[p]]}),y=await ts.create({certificate:g.certificate,rootKey:e.rootKey,canisterId:n}),_=(T,F)=>{if(F==="subnet"){let $=ch(g.certificate,n,e.rootKey);return{path:F,data:$}}else return{path:F,data:rs(T.lookup(bu(F,n)))}},{path:f,data:P}=_(y,i[p]);if(!P)console.warn(`Expected to find result for path ${f}, but instead found nothing.`),typeof f=="string"?o.set(f,null):o.set(f.key,null);else switch(f){case"time":{o.set(f,$r(P));break}case"controllers":{o.set(f,fh(P));break}case"module_hash":{o.set(f,wu(P));break}case"subnet":{o.set(f,P);break}case"candid":{o.set(f,new TextDecoder().decode(P));break}default:if(typeof f!="string"&&"key"in f&&"path"in f)switch(f.decodeStrategy){case"raw":o.set(f.key,P);break;case"leb128":{o.set(f.key,xo(P));break}case"cbor":{o.set(f.key,yu(P));break}case"hex":{o.set(f.key,wu(P));break}case"utf-8":o.set(f.key,uh(P))}}}catch(g){if(!((m=g?.message)===null||m===void 0)&&m.includes("Invalid certificate"))throw new Ye(g.message);typeof a!="string"&&"key"in a&&"path"in a?o.set(a.key,null):o.set(a,null),console.group(),console.warn(`Expected to find result for path ${a}, but instead found nothing.`),console.warn(g),console.groupEnd()}})());return await Promise.all(c),o},ch=(r,e,t)=>{if(!e._isPrincipal)throw new Error("Invalid canisterId");let n=gt(new Uint8Array(r)),i=n.tree,s=n.delegation,o;if(s&&s.subnet_id?o=me.fromUint8Array(new Uint8Array(s.subnet_id)):!s&&typeof t<"u"?(o=me.selfAuthenticating(new Uint8Array(t)),s={subnet_id:o.toUint8Array(),certificate:new ArrayBuffer(0)}):(o=me.selfAuthenticating(me.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),s={subnet_id:o.toUint8Array(),certificate:new ArrayBuffer(0)}),!To({canisterId:e,subnetId:o,tree:i}))throw new Error("Canister not in range");let a=mr(["subnet",s.subnet_id,"node"],i);if(a.status!==Le.Found)throw new Error("Node not found");if(a.value instanceof ArrayBuffer)throw new Error("Invalid node tree");let p=ns(a.value),m=new Map;return p.forEach(g=>{let y=me.from(new Uint8Array(g[1])).toText(),_=mr(["public_key"],g[2]);if(_.status!==Le.Found)throw new Error("Public key not found");let f=_.value;if(f.byteLength!==44)throw new Error("Invalid public key length");m.set(y,f)}),{subnetId:me.fromUint8Array(new Uint8Array(s.subnet_id)).toText(),nodeKeys:m}},bu=(r,e)=>{let t=new TextEncoder,n=s=>new DataView(t.encode(s).buffer).buffer,i=new DataView(e.toUint8Array().buffer).buffer;switch(r){case"time":return[n("time")];case"controllers":return[n("canister"),i,n("controllers")];case"module_hash":return[n("canister"),i,n("module_hash")];case"subnet":return[n("subnet")];case"candid":return[n("canister"),i,n("metadata"),n("candid:service")];default:if("key"in r&&"path"in r)if(typeof r.path=="string"||r.path instanceof ArrayBuffer){let s=r.path,o=typeof s=="string"?n(s):s;return[n("canister"),i,n("metadata"),o]}else return r.path}throw new Error(`An unexpeected error was encountered while encoding your path for canister status. Please ensure that your path, ${r} was formatted correctly.`)},wu=r=>ct(r),yu=r=>gt(r),uh=r=>new TextDecoder().decode(r),fh=r=>yu(r).map(t=>me.fromUint8Array(new Uint8Array(t)));export{je as a,is as b,Xr as c,
|
|
27
|
+
`;if(o.status===404&&o.url.includes("api/v3"))throw new Vr("v3 api not supported. Fall back to v2",{ok:o.ok,status:o.status,statusText:o.statusText,headers:Hr(o.headers)});if(i<ee(this,Ot,"f"))return await ee(this,$t,"m",r).call(this,{request:t,backoff:n,tries:i+1});throw new Vr(a,{ok:o.ok,status:o.status,statusText:o.statusText,headers:Hr(o.headers)})};var mu;(function(r){r.Error="err",r.GetPrincipal="gp",r.GetPrincipalResponse="gpr",r.Query="q",r.QueryResponse="qr",r.Call="c",r.CallResponse="cr",r.ReadState="rs",r.ReadStateResponse="rsr",r.Status="s",r.StatusResponse="sr"})(mu||(mu={}));function A1(){let r=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.ic.agent:globalThis.ic.agent:window.ic.agent;if(!r)throw new Error("No Agent could be found.");return r}var lt=class extends Ye{constructor(e){super(`Invalid certificate: ${e}`)}},ht;(function(r){r[r.Empty=0]="Empty",r[r.Fork=1]="Fork",r[r.Labeled=2]="Labeled",r[r.Leaf=3]="Leaf",r[r.Pruned=4]="Pruned"})(ht||(ht={}));function sh(r,e){let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<t.length;i++)if(t[i]>n[i])return!0;return!1}var ts=class r{constructor(e,t,n,i,s=5){this._rootKey=t,this._canisterId=n,this._blsVerify=i,this._maxAgeInMinutes=s,this.cert=gt(new Uint8Array(e))}static async create(e){let t=r.createUnverified(e);return await t.verify(),t}static createUnverified(e){let t=e.blsVerify;return t||(t=jc),new r(e.certificate,e.rootKey,e.canisterId,t,e.maxAgeInMinutes)}lookup(e){return mr(e,this.cert.tree)}lookup_label(e){return this.lookup([e])}async verify(){let e=await Ji(this.cert.tree),t=await this._checkDelegationAndGetKey(this.cert.delegation),n=this.cert.signature,i=ah(t),s=Ke(Rn("ic-state-root"),e),o=!1,c=rs(this.lookup(["time"]));if(!c)throw new lt("Certificate does not contain a time");let a=5*60*1e3,p=this._maxAgeInMinutes*60*1e3,m=Date.now(),g=m-p,y=m+a,_=$r(c);if(_.getTime()<g)throw new lt(`Certificate is signed more than ${this._maxAgeInMinutes} minutes in the past. Certificate time: `+_.toISOString()+" Current time: "+new Date(m).toISOString());if(_.getTime()>y)throw new lt("Certificate is signed more than 5 minutes in the future. Certificate time: "+_.toISOString()+" Current time: "+new Date(m).toISOString());try{o=await this._blsVerify(new Uint8Array(i),new Uint8Array(n),new Uint8Array(s))}catch{o=!1}if(!o)throw new lt("Signature verification failed")}async _checkDelegationAndGetKey(e){if(!e)return this._rootKey;let t=await r.createUnverified({certificate:e.certificate,rootKey:this._rootKey,canisterId:this._canisterId,blsVerify:this._blsVerify,maxAgeInMinutes:1/0});if(t.cert.delegation)throw new lt("Delegation certificates cannot be nested");if(await t.verify(),this._canisterId.toString()!==pu&&!To({canisterId:this._canisterId,subnetId:me.fromUint8Array(new Uint8Array(e.subnet_id)),tree:t.cert.tree}))throw new lt(`Canister ${this._canisterId} not in range of delegations for subnet 0x${ct(e.subnet_id)}`);let n=rs(t.lookup(["subnet",e.subnet_id,"public_key"]));if(!n)throw new Error(`Could not find subnet key for subnet 0x${ct(e.subnet_id)}`);return n}},Nn=yr("308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"),oh=96;function ah(r){let e=Nn.byteLength+oh;if(r.byteLength!==e)throw new TypeError(`BLS DER-encoded public key must be ${e} bytes long`);let t=r.slice(0,Nn.byteLength);if(!tn(t,Nn))throw new TypeError(`BLS DER-encoded public key is invalid. Expect the following prefix: ${Nn}, but get ${t}`);return r.slice(Nn.byteLength)}function rs(r){if(r.status===Le.Found){if(r.value instanceof ArrayBuffer)return r.value;if(r.value instanceof Uint8Array)return r.value.buffer}}async function Ji(r){switch(r[0]){case ht.Empty:return bt(Rn("ic-hashtree-empty"));case ht.Pruned:return r[1];case ht.Leaf:return bt(Ke(Rn("ic-hashtree-leaf"),r[1]));case ht.Labeled:return bt(Ke(Rn("ic-hashtree-labeled"),r[1],await Ji(r[2])));case ht.Fork:return bt(Ke(Rn("ic-hashtree-fork"),await Ji(r[1]),await Ji(r[2])));default:throw new Error("unreachable")}}function Rn(r){let e=new Uint8Array([r.length]),t=new TextEncoder().encode(r);return Ke(e,t)}var Le;(function(r){r.Unknown="unknown",r.Absent="absent",r.Found="found"})(Le||(Le={}));var Kt;(function(r){r.Less="less",r.Greater="greater"})(Kt||(Kt={}));function mr(r,e){if(r.length===0)switch(e[0]){case ht.Leaf:{if(!e[1])throw new Error("Invalid tree structure for leaf");return e[1]instanceof ArrayBuffer?{status:Le.Found,value:e[1]}:e[1]instanceof Uint8Array?{status:Le.Found,value:e[1].buffer}:{status:Le.Found,value:e[1]}}default:return{status:Le.Found,value:e}}let t=typeof r[0]=="string"?new TextEncoder().encode(r[0]):r[0],n=es(t,e);switch(n.status){case Le.Found:return mr(r.slice(1),n.value);case Kt.Greater:case Kt.Less:return{status:Le.Absent};default:return n}}function ns(r){switch(r[0]){case ht.Empty:return[];case ht.Fork:return ns(r[1]).concat(ns(r[2]));default:return[r]}}function es(r,e){switch(e[0]){case ht.Labeled:return sh(r,e[1])?{status:Kt.Greater}:tn(r,e[1])?{status:Le.Found,value:e[2]}:{status:Kt.Less};case ht.Fork:let t=es(r,e[1]);switch(t.status){case Kt.Greater:{let n=es(r,e[2]);return n.status===Kt.Less?{status:Le.Absent}:n}case Le.Unknown:{let n=es(r,e[2]);return n.status===Kt.Less?{status:Le.Unknown}:n}default:return t}case ht.Pruned:return{status:Le.Unknown};default:return{status:Le.Absent}}}function To(r){let{canisterId:e,subnetId:t,tree:n}=r,i=mr(["subnet",t.toUint8Array(),"canister_ranges"],n);if(i.status!==Le.Found||!(i.value instanceof ArrayBuffer))throw new Error(`Could not find canister ranges for subnet ${t}`);return gt(i.value).map(a=>[me.fromUint8Array(a[0]),me.fromUint8Array(a[1])]).some(a=>a[0].ltEq(e)&&a[1].gtEq(e))}var gu=class{constructor(e,t,n){this.key=e,this.path=t,this.decodeStrategy=n}},hu=async r=>{let{agent:e,paths:t}=r,n=me.from(r.canisterId),i=[...new Set(t)],s=i.map(a=>bu(a,n)),o=new Map,c=i.map((a,p)=>(async()=>{var m;try{let g=await e.readState(n,{paths:[s[p]]}),y=await ts.create({certificate:g.certificate,rootKey:e.rootKey,canisterId:n}),_=(T,F)=>{if(F==="subnet"){let $=ch(g.certificate,n,e.rootKey);return{path:F,data:$}}else return{path:F,data:rs(T.lookup(bu(F,n)))}},{path:f,data:P}=_(y,i[p]);if(!P)console.warn(`Expected to find result for path ${f}, but instead found nothing.`),typeof f=="string"?o.set(f,null):o.set(f.key,null);else switch(f){case"time":{o.set(f,$r(P));break}case"controllers":{o.set(f,fh(P));break}case"module_hash":{o.set(f,wu(P));break}case"subnet":{o.set(f,P);break}case"candid":{o.set(f,new TextDecoder().decode(P));break}default:if(typeof f!="string"&&"key"in f&&"path"in f)switch(f.decodeStrategy){case"raw":o.set(f.key,P);break;case"leb128":{o.set(f.key,xo(P));break}case"cbor":{o.set(f.key,yu(P));break}case"hex":{o.set(f.key,wu(P));break}case"utf-8":o.set(f.key,uh(P))}}}catch(g){if(!((m=g?.message)===null||m===void 0)&&m.includes("Invalid certificate"))throw new Ye(g.message);typeof a!="string"&&"key"in a&&"path"in a?o.set(a.key,null):o.set(a,null),console.group(),console.warn(`Expected to find result for path ${a}, but instead found nothing.`),console.warn(g),console.groupEnd()}})());return await Promise.all(c),o},ch=(r,e,t)=>{if(!e._isPrincipal)throw new Error("Invalid canisterId");let n=gt(new Uint8Array(r)),i=n.tree,s=n.delegation,o;if(s&&s.subnet_id?o=me.fromUint8Array(new Uint8Array(s.subnet_id)):!s&&typeof t<"u"?(o=me.selfAuthenticating(new Uint8Array(t)),s={subnet_id:o.toUint8Array(),certificate:new ArrayBuffer(0)}):(o=me.selfAuthenticating(me.fromText("tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe").toUint8Array()),s={subnet_id:o.toUint8Array(),certificate:new ArrayBuffer(0)}),!To({canisterId:e,subnetId:o,tree:i}))throw new Error("Canister not in range");let a=mr(["subnet",s.subnet_id,"node"],i);if(a.status!==Le.Found)throw new Error("Node not found");if(a.value instanceof ArrayBuffer)throw new Error("Invalid node tree");let p=ns(a.value),m=new Map;return p.forEach(g=>{let y=me.from(new Uint8Array(g[1])).toText(),_=mr(["public_key"],g[2]);if(_.status!==Le.Found)throw new Error("Public key not found");let f=_.value;if(f.byteLength!==44)throw new Error("Invalid public key length");m.set(y,f)}),{subnetId:me.fromUint8Array(new Uint8Array(s.subnet_id)).toText(),nodeKeys:m}},bu=(r,e)=>{let t=new TextEncoder,n=s=>new DataView(t.encode(s).buffer).buffer,i=new DataView(e.toUint8Array().buffer).buffer;switch(r){case"time":return[n("time")];case"controllers":return[n("canister"),i,n("controllers")];case"module_hash":return[n("canister"),i,n("module_hash")];case"subnet":return[n("subnet")];case"candid":return[n("canister"),i,n("metadata"),n("candid:service")];default:if("key"in r&&"path"in r)if(typeof r.path=="string"||r.path instanceof ArrayBuffer){let s=r.path,o=typeof s=="string"?n(s):s;return[n("canister"),i,n("metadata"),o]}else return r.path}throw new Error(`An unexpeected error was encountered while encoding your path for canister status. Please ensure that your path, ${r} was formatted correctly.`)},wu=r=>ct(r),yu=r=>gt(r),uh=r=>new TextDecoder().decode(r),fh=r=>yu(r).map(t=>me.fromUint8Array(new Uint8Array(t)));export{je as a,is as b,Xr as c,aa as d,us as e,me as f,ct as g,yr as h,tn as i,en as j,ls as k,Ye as l,Ys as m,Xs as n,Ps as o,hn as p,Yc as q,Pi as r,ei as s,lr as t,ts as u,rs as v,gu as w,hu as x,ch as y,bu as z,eu as A,Bo as B,ou as C,au as D,fu as E,lu as F,A1 as G};
|
|
28
28
|
/*!
|
|
29
29
|
* The buffer module from node.js, for the browser.
|
|
30
30
|
*
|
|
@@ -66,4 +66,4 @@ ieee754/index.js:
|
|
|
66
66
|
@noble/curves/esm/ed25519.js:
|
|
67
67
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
68
68
|
*/
|
|
69
|
-
//# sourceMappingURL=chunk-
|
|
69
|
+
//# sourceMappingURL=chunk-YQER5335.js.map
|