@junobuild/core 0.0.60 → 0.0.61-next-2024-09-15
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-Y5DRSSOV.js +2 -0
- package/dist/browser/chunk-DMT35GPT.js +49 -0
- package/dist/browser/chunk-DMT35GPT.js.map +7 -0
- package/dist/browser/index.js +22 -22
- package/dist/browser/index.js.map +4 -4
- package/dist/node/index.mjs +34 -31
- package/dist/node/index.mjs.map +4 -4
- package/dist/types/api/actor.api.d.ts +7 -1
- package/dist/types/index.d.ts +7 -6
- package/dist/types/services/factory.services.d.ts +8 -0
- package/dist/types/stores/actor.store.d.ts +21 -0
- package/dist/types/stores/agent.store.d.ts +13 -0
- package/dist/types/types/build.types.d.ts +5 -0
- package/dist/workers/auth.worker.js +12 -12
- package/dist/workers/auth.worker.js.map +3 -3
- package/package.json +6 -6
- package/dist/browser/canisterStatus-APCJZWVG.js +0 -2
- package/dist/browser/chunk-3YVZN56F.js +0 -46
- package/dist/browser/chunk-3YVZN56F.js.map +0 -7
- package/dist/types/utils/actor.utils.d.ts +0 -6
- /package/dist/browser/{canisterStatus-APCJZWVG.js.map → canisterStatus-Y5DRSSOV.js.map} +0 -0
package/dist/browser/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import{A as rn,B as Ct,C as nn,D as ie,E as ni,F as on,G as pt,H as ht,I as ii,J as oi,K as si,L as ai,M as ci,N as Se,O as li,P as Re,Q as ui,R as di,T as sn,a as Zn,b as ds,c as nr,d as Qn,e as In,f as Dn,g as S,h as fs,i as nt,j as Ln,k as ve,l as ps,m as ir,n as $,o as bt,p as or,q as ti,r as sr,s as Vt,t as en,u as ei,v as ar,w as ne,x as cr,y as ri,z as lr}from"./chunk-3YVZN56F.js";var Ti=Zn(pr=>{"use strict";pr.byteLength=gs;pr.toByteArray=xs;pr.fromByteArray=Ts;var Tt=[],lt=[],ws=typeof Uint8Array<"u"?Uint8Array:Array,fn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(zt=0,bi=fn.length;zt<bi;++zt)Tt[zt]=fn[zt],lt[fn.charCodeAt(zt)]=zt;var zt,bi;lt[45]=62;lt[95]=63;function Ei(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function gs(t){var e=Ei(t),r=e[0],n=e[1];return(r+n)*3/4-n}function _s(t,e,r){return(e+r)*3/4-r}function xs(t){var e,r=Ei(t),n=r[0],i=r[1],o=new ws(_s(t,n,i)),s=0,a=i>0?n-4:n,l;for(l=0;l<a;l+=4)e=lt[t.charCodeAt(l)]<<18|lt[t.charCodeAt(l+1)]<<12|lt[t.charCodeAt(l+2)]<<6|lt[t.charCodeAt(l+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=lt[t.charCodeAt(l)]<<2|lt[t.charCodeAt(l+1)]>>4,o[s++]=e&255),i===1&&(e=lt[t.charCodeAt(l)]<<10|lt[t.charCodeAt(l+1)]<<4|lt[t.charCodeAt(l+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function bs(t){return Tt[t>>18&63]+Tt[t>>12&63]+Tt[t>>6&63]+Tt[t&63]}function Es(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(bs(n));return i.join("")}function Ts(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(Es(t,s,s+o>a?a:s+o));return n===1?(e=t[r-1],i.push(Tt[e>>2]+Tt[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(Tt[e>>10]+Tt[e>>4&63]+Tt[e<<2&63]+"=")),i.join("")}});var qi=Zn(ue=>{"use strict";var pn=Ti(),ce=fs(),Ai=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;ue.Buffer=u;ue.SlowBuffer=Ns;ue.INSPECT_MAX_BYTES=50;var hr=2147483647;ue.kMaxLength=hr;u.TYPED_ARRAY_SUPPORT=As();!u.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function As(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}});Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function Ft(t){if(t>hr)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return wn(t)}return Oi(t,e,r)}u.poolSize=8192;function Oi(t,e,r){if(typeof t=="string")return Ss(t,e);if(ArrayBuffer.isView(t))return Rs(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(At(t,ArrayBuffer)||t&&At(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(At(t,SharedArrayBuffer)||t&&At(t.buffer,SharedArrayBuffer)))return mn(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return u.from(n,e,r);let i=Os(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return u.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}u.from=function(t,e,r){return Oi(t,e,r)};Object.setPrototypeOf(u.prototype,Uint8Array.prototype);Object.setPrototypeOf(u,Uint8Array);function Ni(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function vs(t,e,r){return Ni(t),t<=0?Ft(t):e!==void 0?typeof r=="string"?Ft(t).fill(e,r):Ft(t).fill(e):Ft(t)}u.alloc=function(t,e,r){return vs(t,e,r)};function wn(t){return Ni(t),Ft(t<0?0:gn(t)|0)}u.allocUnsafe=function(t){return wn(t)};u.allocUnsafeSlow=function(t){return wn(t)};function Ss(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=Bi(t,e)|0,n=Ft(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function hn(t){let e=t.length<0?0:gn(t.length)|0,r=Ft(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Rs(t){if(At(t,Uint8Array)){let e=new Uint8Array(t);return mn(e.buffer,e.byteOffset,e.byteLength)}return hn(t)}function mn(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,u.prototype),n}function Os(t){if(u.isBuffer(t)){let e=gn(t.length)|0,r=Ft(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||xn(t.length)?Ft(0):hn(t);if(t.type==="Buffer"&&Array.isArray(t.data))return hn(t.data)}function gn(t){if(t>=hr)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+hr.toString(16)+" bytes");return t|0}function Ns(t){return+t!=t&&(t=0),u.alloc(+t)}u.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==u.prototype};u.compare=function(e,r){if(At(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),At(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),!u.isBuffer(e)||!u.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};u.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};u.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return u.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=u.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let s=e[n];if(At(s,Uint8Array))o+s.length>i.length?(u.isBuffer(s)||(s=u.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(u.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Bi(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||At(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return yn(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return ji(t).length;default:if(i)return n?-1:yn(t).length;e=(""+e).toLowerCase(),i=!0}}u.byteLength=Bi;function Bs(t,e,r){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return qs(this,e,r);case"utf8":case"utf-8":return Ci(this,e,r);case"ascii":return Vs(this,e,r);case"latin1":case"binary":return js(this,e,r);case"base64":return Ms(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Hs(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}u.prototype._isBuffer=!0;function Yt(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}u.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)Yt(this,r,r+1);return this};u.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)Yt(this,r,r+3),Yt(this,r+1,r+2);return this};u.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)Yt(this,r,r+7),Yt(this,r+1,r+6),Yt(this,r+2,r+5),Yt(this,r+3,r+4);return this};u.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Ci(this,0,e):Bs.apply(this,arguments)};u.prototype.toLocaleString=u.prototype.toString;u.prototype.equals=function(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:u.compare(this,e)===0};u.prototype.inspect=function(){let e="",r=ue.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};Ai&&(u.prototype[Ai]=u.prototype.inspect);u.prototype.compare=function(e,r,n,i,o){if(At(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-r,l=Math.min(s,a),d=this.slice(i,o),c=e.slice(r,n);for(let f=0;f<l;++f)if(d[f]!==c[f]){s=d[f],a=c[f];break}return s<a?-1:a<s?1:0};function Pi(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,xn(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=u.from(e,n)),u.isBuffer(e))return e.length===0?-1:vi(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):vi(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function vi(t,e,r,n,i){let o=1,s=t.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,a/=2,r/=2}function l(c,f){return o===1?c[f]:c.readUInt16BE(f*o)}let d;if(i){let c=-1;for(d=r;d<s;d++)if(l(t,d)===l(e,c===-1?0:d-c)){if(c===-1&&(c=d),d-c+1===a)return c*o}else c!==-1&&(d-=d-c),c=-1}else for(r+a>s&&(r=s-a),d=r;d>=0;d--){let c=!0;for(let f=0;f<a;f++)if(l(t,d+f)!==l(e,f)){c=!1;break}if(c)return d}return-1}u.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};u.prototype.indexOf=function(e,r,n){return Pi(this,e,r,n,!0)};u.prototype.lastIndexOf=function(e,r,n){return Pi(this,e,r,n,!1)};function Ps(t,e,r,n){r=Number(r)||0;let i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(xn(a))return s;t[r+s]=a}return s}function Cs(t,e,r,n){return mr(yn(e,t.length-r),t,r,n)}function ks(t,e,r,n){return mr(zs(e),t,r,n)}function Fs(t,e,r,n){return mr(ji(e),t,r,n)}function Us(t,e,r,n){return mr(Ys(e,t.length-r),t,r,n)}u.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return Ps(this,e,r,n);case"utf8":case"utf-8":return Cs(this,e,r,n);case"ascii":case"latin1":case"binary":return ks(this,e,r,n);case"base64":return Fs(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Us(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Ms(t,e,r){return e===0&&r===t.length?pn.fromByteArray(t):pn.fromByteArray(t.slice(e,r))}function Ci(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let o=t[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=r){let l,d,c,f;switch(a){case 1:o<128&&(s=o);break;case 2:l=t[i+1],(l&192)===128&&(f=(o&31)<<6|l&63,f>127&&(s=f));break;case 3:l=t[i+1],d=t[i+2],(l&192)===128&&(d&192)===128&&(f=(o&15)<<12|(l&63)<<6|d&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:l=t[i+1],d=t[i+2],c=t[i+3],(l&192)===128&&(d&192)===128&&(c&192)===128&&(f=(o&15)<<18|(l&63)<<12|(d&63)<<6|c&63,f>65535&&f<1114112&&(s=f))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return Ks(n)}var Si=4096;function Ks(t){let e=t.length;if(e<=Si)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Si));return r}function Vs(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function js(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function qs(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=e;o<r;++o)i+=Js[t[o]];return i}function Hs(t,e,r){let n=t.slice(e,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}u.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let i=this.subarray(e,r);return Object.setPrototypeOf(i,u.prototype),i};function z(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||z(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return i};u.prototype.readUintBE=u.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||z(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};u.prototype.readUint8=u.prototype.readUInt8=function(e,r){return e=e>>>0,r||z(e,1,this.length),this[e]};u.prototype.readUint16LE=u.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||z(e,2,this.length),this[e]|this[e+1]<<8};u.prototype.readUint16BE=u.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||z(e,2,this.length),this[e]<<8|this[e+1]};u.prototype.readUint32LE=u.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||z(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};u.prototype.readUint32BE=u.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||z(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};u.prototype.readBigUInt64LE=jt(function(e){e=e>>>0,le(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Oe(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});u.prototype.readBigUInt64BE=jt(function(e){e=e>>>0,le(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Oe(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});u.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||z(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};u.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||z(e,r,this.length);let i=r,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};u.prototype.readInt8=function(e,r){return e=e>>>0,r||z(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};u.prototype.readInt16LE=function(e,r){e=e>>>0,r||z(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};u.prototype.readInt16BE=function(e,r){e=e>>>0,r||z(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};u.prototype.readInt32LE=function(e,r){return e=e>>>0,r||z(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};u.prototype.readInt32BE=function(e,r){return e=e>>>0,r||z(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};u.prototype.readBigInt64LE=jt(function(e){e=e>>>0,le(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Oe(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});u.prototype.readBigInt64BE=jt(function(e){e=e>>>0,le(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Oe(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});u.prototype.readFloatLE=function(e,r){return e=e>>>0,r||z(e,4,this.length),ce.read(this,e,!0,23,4)};u.prototype.readFloatBE=function(e,r){return e=e>>>0,r||z(e,4,this.length),ce.read(this,e,!1,23,4)};u.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||z(e,8,this.length),ce.read(this,e,!0,52,8)};u.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||z(e,8,this.length),ce.read(this,e,!1,52,8)};function it(t,e,r,n,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;it(this,e,r,n,a,0)}let o=1,s=0;for(this[r]=e&255;++s<n&&(o*=256);)this[r+s]=e/o&255;return r+n};u.prototype.writeUintBE=u.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;it(this,e,r,n,a,0)}let o=n-1,s=1;for(this[r+o]=e&255;--o>=0&&(s*=256);)this[r+o]=e/s&255;return r+n};u.prototype.writeUint8=u.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,1,255,0),this[r]=e&255,r+1};u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function ki(t,e,r,n,i){Vi(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,r}function Fi(t,e,r,n,i){Vi(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s=s>>8,t[r+2]=s,s=s>>8,t[r+1]=s,s=s>>8,t[r]=s,r+8}u.prototype.writeBigUInt64LE=jt(function(e,r=0){return ki(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});u.prototype.writeBigUInt64BE=jt(function(e,r=0){return Fi(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});u.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);it(this,e,r,n,l-1,-l)}let o=0,s=1,a=0;for(this[r]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[r+o-1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};u.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);it(this,e,r,n,l-1,-l)}let o=n-1,s=1,a=0;for(this[r+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[r+o+1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};u.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};u.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};u.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};u.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};u.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||it(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};u.prototype.writeBigInt64LE=jt(function(e,r=0){return ki(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});u.prototype.writeBigInt64BE=jt(function(e,r=0){return Fi(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ui(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Mi(t,e,r,n,i){return e=+e,r=r>>>0,i||Ui(t,e,r,4,34028234663852886e22,-34028234663852886e22),ce.write(t,e,r,n,23,4),r+4}u.prototype.writeFloatLE=function(e,r,n){return Mi(this,e,r,!0,n)};u.prototype.writeFloatBE=function(e,r,n){return Mi(this,e,r,!1,n)};function Ki(t,e,r,n,i){return e=+e,r=r>>>0,i||Ui(t,e,r,8,17976931348623157e292,-17976931348623157e292),ce.write(t,e,r,n,52,8),r+8}u.prototype.writeDoubleLE=function(e,r,n){return Ki(this,e,r,!0,n)};u.prototype.writeDoubleBE=function(e,r,n){return Ki(this,e,r,!1,n)};u.prototype.copy=function(e,r,n,i){if(!u.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};u.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!u.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=r;o<n;++o)this[o]=e;else{let s=u.isBuffer(e)?e:u.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=s[o%a]}return this};var ae={};function _n(t,e,r){ae[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}_n("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);_n("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);_n("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=Ri(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=Ri(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Ri(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function Ws(t,e,r){le(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&Oe(e,t.length-(r+1))}function Vi(t,e,r,n,i,o){if(t>r||t<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${r}${s}`,new ae.ERR_OUT_OF_RANGE("value",a,t)}Ws(n,i,o)}function le(t,e){if(typeof t!="number")throw new ae.ERR_INVALID_ARG_TYPE(e,"number",t)}function Oe(t,e,r){throw Math.floor(t)!==t?(le(t,r),new ae.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new ae.ERR_BUFFER_OUT_OF_BOUNDS:new ae.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var $s=/[^+/0-9A-Za-z-_]/g;function Gs(t){if(t=t.split("=")[0],t=t.trim().replace($s,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function yn(t,e){e=e||1/0;let r,n=t.length,i=null,o=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function zs(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function Ys(t,e){let r,n,i,o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function ji(t){return pn.toByteArray(Gs(t))}function mr(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function At(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function xn(t){return t!==t}var Js=function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function jt(t){return typeof BigInt>"u"?Xs:t}function Xs(){throw new Error("BigInt not supported")}});var V=t=>t==null,H=t=>!V(t),hs=class extends Error{},ur=(t,e)=>{if(V(t))throw new hs(e)},an="__bigint__",cn="__principal__",ln="__uint8array__",ms=(t,e)=>typeof e=="bigint"?{[an]:`${e}`}:H(e)&&e instanceof S?{[cn]:e.toText()}:H(e)&&e instanceof Uint8Array?{[ln]:Array.from(e)}:e,ys=(t,e)=>{let r=n=>e[n];return H(e)&&typeof e=="object"&&an in e?BigInt(r(an)):H(e)&&typeof e=="object"&&cn in e?S.fromText(r(cn)):H(e)&&typeof e=="object"&&ln in e?Uint8Array.from(r(ln)):e},J=t=>H(t)?[t]:[],G=t=>t?.[0],fi=async t=>{let e=new Blob([JSON.stringify(t,ms)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},dr=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),ys)},pi=()=>typeof window<"u";var oe=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:r})=>r(e))}subscribe(e){let r=Symbol();return this.callbacks.push({id:r,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:n})=>n!==r)}};var kt=class t extends oe{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let r=super.subscribe(e);return e(this.authUser),r}reset(){this.authUser=null,this.populate(this.authUser)}};var un=({message:t,detail:e})=>{let r=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(r)};var hi=BigInt(144e11),mi=!1,yi={width:576,height:576},wi={width:505,height:705},gi="internetcomputer.org";var se="http://127.0.0.1:5987",_i="rdmx6-jaaaa-aaaaa-aaadq-cai";var Et=class t extends oe{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let r=super.subscribe(e);return e(this.env),r}};var dn=({width:t,height:e})=>{if(!pi()||V(window)||V(window.top))return;let{top:{innerWidth:r,innerHeight:n}}=window,i=n/2+screenY-e/2,o=r/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${o}`};var fr=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let r=()=>{let n=Et.getInstance().get()?.container;if(V(n)||n===!1)return`https://identity.${this.#t??gi}`;let i=Et.getInstance().get(),o=H(i)&&H(i?.internetIdentityId)?i.internetIdentityId:_i,{host:s,protocol:a}=new URL(n===!0?se:n);return/apple/i.test(navigator?.vendor)?`${a}//${s}?canisterId=${o}`:`${a}//${o}.${s.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:dn(yi)},identityProvider:r()}}},xi=class{#t;#e;constructor({appName:e,logoUrl:r}){this.#t=e,this.#e=r}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:dn(wi)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};var fo=nr(qi());var yr;(function(t){t[t.SysFatal=1]="SysFatal",t[t.SysTransient=2]="SysTransient",t[t.DestinationInvalid=3]="DestinationInvalid",t[t.CanisterReject=4]="CanisterReject",t[t.CanisterError=5]="CanisterError"})(yr||(yr={}));var Zs=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Qs=new TextEncoder().encode(`
|
|
2
|
-
ic-request`),Ut=class{getPrincipal(){return this._principal||(this._principal=S.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:r}=e,n=Zs(e,["body"]),i=await Vt(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(ir(Qs,i))}})}},Mt=class{getPrincipal(){return S.anonymous()}async transformRequest(e){return Object.assign(Object.assign({},e),{body:{content:e.body}})}};var Hi=nr(ei());var Ne=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){let t=new Uint32Array(1);return window.crypto.getRandomValues(t),t[0]}if(typeof crypto<"u"&&crypto.getRandomValues){let t=new Uint32Array(1);return crypto.getRandomValues(t),t[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var wr;(function(t){t.Call="call"})(wr||(wr={}));function de(){let t=new ArrayBuffer(16),e=new DataView(t),r=Ne(),n=Ne(),i=Ne(),o=Ne();return e.setUint32(0,r),e.setUint32(4,n),e.setUint32(8,i),e.setUint32(12,o),t}var Is=BigInt(1e6),Ds=60*1e3,Jt=class{constructor(e){let o=BigInt(Math.floor(Date.now()+e-Ds))*Is/BigInt(1e9)/BigInt(60)*BigInt(60)*BigInt(1e9);this._value=o}toCBOR(){return Hi.value.u64(this._value.toString(16),16)}toHash(){return Ln(this._value)}};function bn(t=de){return async e=>{let r=e.request.headers;e.request.headers=r,e.endpoint==="call"&&(e.body.nonce=t())}}function Be(t){let e=[];return t.forEach((r,n)=>{e.push([n,r])}),e}var Pe=class extends nt{constructor(e,r){super(e),this.response=r,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}};var gr=BigInt(4294967295),En=BigInt(32);function Wi(t,e=!1){return e?{h:Number(t&gr),l:Number(t>>En&gr)}:{h:Number(t>>En&gr)|0,l:Number(t&gr)|0}}function Ls(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){let{h:o,l:s}=Wi(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]}var ta=(t,e)=>BigInt(t>>>0)<<En|BigInt(e>>>0),ea=(t,e,r)=>t>>>r,ra=(t,e,r)=>t<<32-r|e>>>r,na=(t,e,r)=>t>>>r|e<<32-r,ia=(t,e,r)=>t<<32-r|e>>>r,oa=(t,e,r)=>t<<64-r|e>>>r-32,sa=(t,e,r)=>t>>>r-32|e<<64-r,aa=(t,e)=>e,ca=(t,e)=>t,la=(t,e,r)=>t<<r|e>>>32-r,ua=(t,e,r)=>e<<r|t>>>32-r,da=(t,e,r)=>e<<r-32|t>>>64-r,fa=(t,e,r)=>t<<r-32|e>>>64-r;function pa(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var ha=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),ma=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ya=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),wa=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,ga=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),_a=(t,e,r,n,i,o)=>e+r+n+i+o+(t/2**32|0)|0;var xa={fromBig:Wi,split:Ls,toBig:ta,shrSH:ea,shrSL:ra,rotrSH:na,rotrSL:ia,rotrBH:oa,rotrBL:sa,rotr32H:aa,rotr32L:ca,rotlSH:la,rotlSL:ua,rotlBH:da,rotlBL:fa,add:pa,add3L:ha,add3H:ma,add4L:ya,add4H:wa,add5H:_a,add5L:ga},A=xa;var[ba,Ea]=A.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(t=>BigInt(t))),qt=new Uint32Array(80),Ht=new Uint32Array(80),Tn=class extends Dn{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:r,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:l,Eh:d,El:c,Fh:f,Fl:h,Gh:w,Gl:m,Hh:g,Hl:v}=this;return[e,r,n,i,o,s,a,l,d,c,f,h,w,m,g,v]}set(e,r,n,i,o,s,a,l,d,c,f,h,w,m,g,v){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=l|0,this.Eh=d|0,this.El=c|0,this.Fh=f|0,this.Fl=h|0,this.Gh=w|0,this.Gl=m|0,this.Hh=g|0,this.Hl=v|0}process(e,r){for(let E=0;E<16;E++,r+=4)qt[E]=e.getUint32(r),Ht[E]=e.getUint32(r+=4);for(let E=16;E<80;E++){let C=qt[E-15]|0,U=Ht[E-15]|0,j=A.rotrSH(C,U,1)^A.rotrSH(C,U,8)^A.shrSH(C,U,7),tt=A.rotrSL(C,U,1)^A.rotrSL(C,U,8)^A.shrSL(C,U,7),K=qt[E-2]|0,q=Ht[E-2]|0,et=A.rotrSH(K,q,19)^A.rotrBH(K,q,61)^A.shrSH(K,q,6),st=A.rotrSL(K,q,19)^A.rotrBL(K,q,61)^A.shrSL(K,q,6),xt=A.add4L(tt,st,Ht[E-7],Ht[E-16]),dt=A.add4H(xt,j,et,qt[E-7],qt[E-16]);qt[E]=dt|0,Ht[E]=xt|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:l,Dh:d,Dl:c,Eh:f,El:h,Fh:w,Fl:m,Gh:g,Gl:v,Hh:R,Hl:_}=this;for(let E=0;E<80;E++){let C=A.rotrSH(f,h,14)^A.rotrSH(f,h,18)^A.rotrBH(f,h,41),U=A.rotrSL(f,h,14)^A.rotrSL(f,h,18)^A.rotrBL(f,h,41),j=f&w^~f&g,tt=h&m^~h&v,K=A.add5L(_,U,tt,Ea[E],Ht[E]),q=A.add5H(K,R,C,j,ba[E],qt[E]),et=K|0,st=A.rotrSH(n,i,28)^A.rotrBH(n,i,34)^A.rotrBH(n,i,39),xt=A.rotrSL(n,i,28)^A.rotrBL(n,i,34)^A.rotrBL(n,i,39),dt=n&o^n&a^o&a,Kt=i&s^i&l^s&l;R=g|0,_=v|0,g=w|0,v=m|0,w=f|0,m=h|0,{h:f,l:h}=A.add(d|0,c|0,q|0,et|0),d=a|0,c=l|0,a=o|0,l=s|0,o=n|0,s=i|0;let b=A.add3L(et,xt,Kt);n=A.add3H(b,q,st,dt),i=b|0}({h:n,l:i}=A.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=A.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l}=A.add(this.Ch|0,this.Cl|0,a|0,l|0),{h:d,l:c}=A.add(this.Dh|0,this.Dl|0,d|0,c|0),{h:f,l:h}=A.add(this.Eh|0,this.El|0,f|0,h|0),{h:w,l:m}=A.add(this.Fh|0,this.Fl|0,w|0,m|0),{h:g,l:v}=A.add(this.Gh|0,this.Gl|0,g|0,v|0),{h:R,l:_}=A.add(this.Hh|0,this.Hl|0,R|0,_|0),this.set(n,i,o,s,a,l,d,c,f,h,w,m,g,v,R,_)}roundClean(){qt.fill(0),Ht.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 $i=Qn(()=>new Tn);var mt=BigInt(0),ot=BigInt(1),_r=BigInt(2),Ta=BigInt(8),Aa={zip215:!0};function va(t){let e=ai(t);return ni(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Gi(t){let e=va(t),{Fp:r,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:l}=e,d=_r<<BigInt(a*8)-ot,c=r.create,f=e.uvRatio||((b,p)=>{try{return{isValid:!0,value:r.sqrt(b*r.inv(p))}}catch{return{isValid:!1,value:mt}}}),h=e.adjustScalarBytes||(b=>b),w=e.domain||((b,p,x)=>{if(cr("phflag",x),p.length||x)throw new Error("Contexts/pre-hash are not supported");return b});function m(b,p){ie("coordinate "+b,p,mt,d)}function g(b){if(!(b instanceof _))throw new Error("ExtendedPoint expected")}let v=on((b,p)=>{let{ex:x,ey:T,ez:O}=b,N=b.is0();p==null&&(p=N?Ta:r.inv(O));let P=c(x*p),k=c(T*p),B=c(O*p);if(N)return{x:mt,y:ot};if(B!==ot)throw new Error("invZ was invalid");return{x:P,y:k}}),R=on(b=>{let{a:p,d:x}=e;if(b.is0())throw new Error("bad point: ZERO");let{ex:T,ey:O,ez:N,et:P}=b,k=c(T*T),B=c(O*O),F=c(N*N),M=c(F*F),W=c(k*p),rt=c(F*c(W+B)),D=c(M+c(x*c(k*B)));if(rt!==D)throw new Error("bad point: equation left != right (1)");let Z=c(T*O),ct=c(N*P);if(Z!==ct)throw new Error("bad point: equation left != right (2)");return!0});class _{constructor(p,x,T,O){this.ex=p,this.ey=x,this.ez=T,this.et=O,m("x",p),m("y",x),m("z",T),m("t",O),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof _)throw new Error("extended point not allowed");let{x,y:T}=p||{};return m("x",x),m("y",T),new _(x,T,ot,c(x*T))}static normalizeZ(p){let x=r.invertBatch(p.map(T=>T.ez));return p.map((T,O)=>T.toAffine(x[O])).map(_.fromAffine)}_setWindowSize(p){U.setWindowSize(this,p)}assertValidity(){R(this)}equals(p){g(p);let{ex:x,ey:T,ez:O}=this,{ex:N,ey:P,ez:k}=p,B=c(x*k),F=c(N*O),M=c(T*k),W=c(P*O);return B===F&&M===W}is0(){return this.equals(_.ZERO)}negate(){return new _(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){let{a:p}=e,{ex:x,ey:T,ez:O}=this,N=c(x*x),P=c(T*T),k=c(_r*c(O*O)),B=c(p*N),F=x+T,M=c(c(F*F)-N-P),W=B+P,rt=W-k,D=B-P,Z=c(M*rt),ct=c(W*D),ft=c(M*D),re=c(rt*W);return new _(Z,ct,re,ft)}add(p){g(p);let{a:x,d:T}=e,{ex:O,ey:N,ez:P,et:k}=this,{ex:B,ey:F,ez:M,et:W}=p;if(x===BigInt(-1)){let Ie=c((N-O)*(F+B)),De=c((N+O)*(F-B)),Ae=c(De-Ie);if(Ae===mt)return this.double();let Le=c(P*_r*W),tr=c(k*_r*M),er=tr+Le,rr=De+Ie,Xn=tr-Le,as=c(er*Ae),cs=c(rr*Xn),ls=c(er*Xn),us=c(Ae*rr);return new _(as,cs,us,ls)}let rt=c(O*B),D=c(N*F),Z=c(k*T*W),ct=c(P*M),ft=c((O+N)*(B+F)-rt-D),re=ct-Z,Ze=ct+Z,Qe=c(D-x*rt),Ir=c(ft*re),Dr=c(Ze*Qe),Lr=c(ft*Qe),tn=c(re*Ze);return new _(Ir,Dr,tn,Lr)}subtract(p){return this.add(p.negate())}wNAF(p){return U.wNAFCached(this,p,_.normalizeZ)}multiply(p){let x=p;ie("scalar",x,ot,n);let{p:T,f:O}=this.wNAF(x);return _.normalizeZ([T,O])[0]}multiplyUnsafe(p){let x=p;return ie("scalar",x,mt,n),x===mt?C:this.equals(C)||x===ot?this:this.equals(E)?this.wNAF(x).p:U.unsafeLadder(this,x)}isSmallOrder(){return this.multiplyUnsafe(l).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(p){return v(this,p)}clearCofactor(){let{h:p}=e;return p===ot?this:this.multiplyUnsafe(p)}static fromHex(p,x=!1){let{d:T,a:O}=e,N=r.BYTES;p=Ct("pointHex",p,N),cr("zip215",x);let P=p.slice(),k=p[N-1];P[N-1]=k&-129;let B=lr(P),F=x?d:r.ORDER;ie("pointHex.y",B,mt,F);let M=c(B*B),W=c(M-ot),rt=c(T*M-O),{isValid:D,value:Z}=f(W,rt);if(!D)throw new Error("Point.fromHex: invalid y coordinate");let ct=(Z&ot)===ot,ft=(k&128)!==0;if(!x&&Z===mt&&ft)throw new Error("Point.fromHex: x=0 and x_0=1");return ft!==ct&&(Z=c(-Z)),_.fromAffine({x:Z,y:B})}static fromPrivateKey(p){return K(p).point}toRawBytes(){let{x:p,y:x}=this.toAffine(),T=rn(x,r.BYTES);return T[T.length-1]|=p&ot?128:0,T}toHex(){return ri(this.toRawBytes())}}_.BASE=new _(e.Gx,e.Gy,ot,c(e.Gx*e.Gy)),_.ZERO=new _(mt,ot,ot,mt);let{BASE:E,ZERO:C}=_,U=si(_,a*8);function j(b){return pt(b,n)}function tt(b){return j(lr(b))}function K(b){let p=a;b=Ct("private key",b,p);let x=Ct("hashed private key",o(b),2*p),T=h(x.slice(0,p)),O=x.slice(p,2*p),N=tt(T),P=E.multiply(N),k=P.toRawBytes();return{head:T,prefix:O,scalar:N,point:P,pointBytes:k}}function q(b){return K(b).pointBytes}function et(b=new Uint8Array,...p){let x=nn(...p);return tt(o(w(x,Ct("context",b),!!i)))}function st(b,p,x={}){b=Ct("message",b),i&&(b=i(b));let{prefix:T,scalar:O,pointBytes:N}=K(p),P=et(x.context,T,b),k=E.multiply(P).toRawBytes(),B=et(x.context,k,N,b),F=j(P+B*O);ie("signature.s",F,mt,n);let M=nn(k,rn(F,r.BYTES));return Ct("result",M,a*2)}let xt=Aa;function dt(b,p,x,T=xt){let{context:O,zip215:N}=T,P=r.BYTES;b=Ct("signature",b,2*P),p=Ct("message",p),N!==void 0&&cr("zip215",N),i&&(p=i(p));let k=lr(b.slice(P,2*P)),B,F,M;try{B=_.fromHex(x,N),F=_.fromHex(b.slice(0,P),N),M=E.multiplyUnsafe(k)}catch{return!1}if(!N&&B.isSmallOrder())return!1;let W=et(O,F.toRawBytes(),B.toRawBytes(),p);return F.add(B.multiplyUnsafe(W)).subtract(M).clearCofactor().equals(_.ZERO)}return E._setWindowSize(8),{CURVE:e,getPublicKey:q,sign:st,verify:dt,ExtendedPoint:_,utils:{getExtendedPublicKey:K,randomPrivateKey:()=>s(r.BYTES),precompute(b=8,p=_.BASE){return p._setWindowSize(b),p.multiply(BigInt(3)),p}}}}var An=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),zi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Cl=BigInt(0),Sa=BigInt(1),Yi=BigInt(2),kl=BigInt(3),Ra=BigInt(5),Oa=BigInt(8);function Na(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),i=BigInt(80),o=An,a=t*t%o*t%o,l=ht(a,Yi,o)*a%o,d=ht(l,Sa,o)*t%o,c=ht(d,Ra,o)*d%o,f=ht(c,e,o)*c%o,h=ht(f,r,o)*f%o,w=ht(h,n,o)*h%o,m=ht(w,i,o)*w%o,g=ht(m,i,o)*w%o,v=ht(g,e,o)*c%o;return{pow_p_5_8:ht(v,Yi,o)*t%o,b2:a}}function Ba(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function Pa(t,e){let r=An,n=pt(e*e*e,r),i=pt(n*n*e,r),o=Na(t*i).pow_p_5_8,s=pt(t*n*o,r),a=pt(e*s*s,r),l=s,d=pt(s*zi,r),c=a===t,f=a===pt(-t,r),h=a===pt(-t*zi,r);return c&&(s=l),(f||h)&&(s=d),ii(s,r)&&(s=pt(-s,r)),{isValid:c||f,value:s}}var Ca=oi(An,void 0,!0),ka={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ca,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Oa,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:$i,randomBytes:In,adjustScalarBytes:Ba,uvRatio:Pa},Wt=Gi(ka);var Ji=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},L=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Q,Ce,Xi,Zi,xr=class{constructor(e={}){Q.set(this,void 0),Ce.set(this,void 0),this[Xi]=this.entries.bind(this),this[Zi]="ExpirableMap";let{source:r=[],expirationTime:n=10*60*1e3}=e,i=Date.now();Ji(this,Q,new Map([...r].map(([o,s])=>[o,{value:s,timestamp:i}])),"f"),Ji(this,Ce,n,"f")}prune(){let e=Date.now();for(let[r,n]of L(this,Q,"f").entries())e-n.timestamp>L(this,Ce,"f")&&L(this,Q,"f").delete(r);return this}set(e,r){this.prune();let n={value:r,timestamp:Date.now()};return L(this,Q,"f").set(e,n),this}get(e){let r=L(this,Q,"f").get(e);if(r!==void 0){if(Date.now()-r.timestamp>L(this,Ce,"f")){L(this,Q,"f").delete(e);return}return r.value}}clear(){L(this,Q,"f").clear()}entries(){let e=L(this,Q,"f").entries();return function*(){for(let[n,i]of e)yield[n,i.value]}()}values(){let e=L(this,Q,"f").values();return function*(){for(let n of e)yield n.value}()}keys(){return L(this,Q,"f").keys()}forEach(e,r){for(let[n,i]of L(this,Q,"f").entries())e.call(r,i.value,n,this)}has(e){return L(this,Q,"f").has(e)}delete(e){return L(this,Q,"f").delete(e)}get size(){return L(this,Q,"f").size}};Q=new WeakMap,Ce=new WeakMap,Xi=Symbol.iterator,Zi=Symbol.toStringTag;var Qi=t=>{if(t<=127)return 1;if(t<=255)return 2;if(t<=65535)return 3;if(t<=16777215)return 4;throw new Error("Length too long (> 4 bytes)")},Ii=(t,e,r)=>{if(r<=127)return t[e]=r,1;if(r<=255)return t[e]=129,t[e+1]=r,2;if(r<=65535)return t[e]=130,t[e+1]=r>>8,t[e+2]=r,3;if(r<=16777215)return t[e]=131,t[e+1]=r>>16,t[e+2]=r>>8,t[e+3]=r,4;throw new Error("Length too long (> 4 bytes)")},vn=(t,e)=>{if(t[e]<128)return 1;if(t[e]===128)throw new Error("Invalid length 0");if(t[e]===129)return 2;if(t[e]===130)return 3;if(t[e]===131)return 4;throw new Error("Length too long (> 4 bytes)")},Fa=(t,e)=>{let r=vn(t,e);if(r===1)return t[e];if(r===2)return t[e+1];if(r===3)return(t[e+1]<<8)+t[e+2];if(r===4)return(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];throw new Error("Length too long (> 4 bytes)")},Di=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),Xt=Uint8Array.from([48,5,6,3,43,101,112]),Kl=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);function fe(t,e){let r=2+Qi(t.byteLength+1),n=e.byteLength+r+t.byteLength,i=0,o=new Uint8Array(1+Qi(n)+n);return o[i++]=48,i+=Ii(o,i,n),o.set(e,i),i+=e.byteLength,o[i++]=3,i+=Ii(o,i,t.byteLength+1),o[i++]=0,o.set(new Uint8Array(t),i),o}var ke=(t,e)=>{let r=0,n=(a,l)=>{if(i[r++]!==a)throw new Error("Expected: "+l)},i=new Uint8Array(t);if(n(48,"sequence"),r+=vn(i,r),!or(i.slice(r,r+e.byteLength),e))throw new Error("Not the expected OID.");r+=e.byteLength,n(3,"bit string");let o=Fa(i,r)-1;r+=vn(i,r),n(0,"0 padding");let s=i.slice(r);if(o!==s.length)throw new Error(`DER payload mismatch: Expected length ${o} actual length ${s.length}`);return s};var Li=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},to=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},br,Er,Fe=class t{constructor(e){if(br.set(this,void 0),Er.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");Li(this,br,e,"f"),Li(this,Er,t.derEncode(e),"f")}static from(e){return this.fromDer(e.toDer())}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static derEncode(e){return fe(e,Xt).buffer}static derDecode(e){let r=ke(e,Xt);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}get rawKey(){return to(this,br,"f")}get derKey(){return to(this,Er,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};br=new WeakMap,Er=new WeakMap;Fe.RAW_KEY_LENGTH=32;var Sn=class{constructor(){this.observers=[]}subscribe(e){this.observers.push(e)}unsubscribe(e){this.observers=this.observers.filter(r=>r!==e)}notify(e,...r){this.observers.forEach(n=>n(e,...r))}},Tr=class extends Sn{constructor(){super()}print(e,...r){this.notify({message:e,level:"info"},...r)}warn(e,...r){this.notify({message:e,level:"warn"},...r)}error(e,r,...n){this.notify({message:e,level:"error",error:r},...n)}};var vt=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},I=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},St,Ar,vr,Sr,Rr,Or,Nr,Br,pe;var Ue=class t{constructor(e=t.default){St.set(this,void 0),Ar.set(this,void 0),vr.set(this,void 0),Sr.set(this,void 0),Rr.set(this,void 0),Or.set(this,void 0),Nr.set(this,void 0),Br.set(this,void 0),pe.set(this,0);let{initialInterval:r=500,randomizationFactor:n=.5,multiplier:i=1.5,maxInterval:o=6e4,maxElapsedTime:s=9e5,maxIterations:a=10,date:l=Date}=e;vt(this,St,r,"f"),vt(this,Ar,n,"f"),vt(this,vr,i,"f"),vt(this,Sr,o,"f"),vt(this,Br,l,"f"),vt(this,Rr,l.now(),"f"),vt(this,Or,s,"f"),vt(this,Nr,a,"f")}get ellapsedTimeInMsec(){return I(this,Br,"f").now()-I(this,Rr,"f")}get currentInterval(){return I(this,St,"f")}get count(){return I(this,pe,"f")}get randomValueFromInterval(){let e=I(this,Ar,"f")*I(this,St,"f"),r=I(this,St,"f")-e,n=I(this,St,"f")+e;return Math.random()*(n-r)+r}incrementCurrentInterval(){var e;return vt(this,St,Math.min(I(this,St,"f")*I(this,vr,"f"),I(this,Sr,"f")),"f"),vt(this,pe,(e=I(this,pe,"f"),e++,e),"f"),I(this,St,"f")}next(){return this.ellapsedTimeInMsec>=I(this,Or,"f")||I(this,pe,"f")>=I(this,Nr,"f")?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};St=new WeakMap,Ar=new WeakMap,vr=new WeakMap,Sr=new WeakMap,Rr=new WeakMap,Or=new WeakMap,Nr=new WeakMap,Br=new WeakMap,pe=new WeakMap;Ue.default={initialInterval:500,randomizationFactor:.5,multiplier:1.5,maxInterval:6e4,maxElapsedTime:9e5,maxIterations:10,date:Date};var at=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},y=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Ot,Rt,It,ye,Cr,Me,yt,kr,wt,Zt,Fr,he,me,Qt,Dt,eo,Ur,Mr,Nt;(function(t){t.Received="received",t.Processing="processing",t.Replied="replied",t.Rejected="rejected",t.Unknown="unknown",t.Done="done"})(Nt||(Nt={}));var Pr=5*60*1e3,Ma="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae";var Ka="ic0.app",Va=".ic0.app",ja="icp0.io",qa=".icp0.io",Ha="icp-api.io",Wa=".icp-api.io",Ke=class extends nt{constructor(e){super(e),this.message=e}},we=class extends nt{constructor(e){super(e),this.message=e}};function $a(){let t;if(typeof window<"u")if(window.fetch)t=window.fetch.bind(window);else throw new Ke("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)t=globalThis.fetch.bind(globalThis);else throw new Ke("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&&(t=self.fetch.bind(self));if(t)return t;throw new Ke("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context.")}function Ga(t){let e;if(t!==void 0)!t.match(/^[a-z]+:/)&&typeof window<"u"?e=new URL(window.location.protocol+"//"+t):e=new URL(t);else{let r=["ic0.app","icp0.io","127.0.0.1","localhost"],n=[".github.dev",".gitpod.io"],i=typeof window<"u"?window.location:void 0,o=i?.hostname,s;o&&typeof o=="string"&&(n.some(a=>o.endsWith(a))?s=o:s=r.find(a=>o.endsWith(a))),i&&s?e=new URL(`${i.protocol}//${s}${i.port?":"+i.port:""}`):e=new URL("https://icp-api.io")}return e.toString()}var Ve=class t{constructor(e={}){var r;Ot.add(this),this.rootKey=bt(Ma),Rt.set(this,void 0),It.set(this,void 0),ye.set(this,void 0),Cr.set(this,void 0),Me.set(this,0),yt.set(this,void 0),kr.set(this,!1),wt.set(this,void 0),Zt.set(this,void 0),this._isAgent=!0,this.config={},Fr.set(this,0),this.log=new Tr,he.set(this,[]),me.set(this,[]),Qt.set(this,new xr({expirationTime:5*60*1e3})),Dt.set(this,!0),Mr.set(this,(o,s)=>{if(y(this,Dt,"f")===!1)return o;if(!s)throw new Se("Invalid signature from replica signed query: no matching node key found.");let{status:a,signatures:l=[],requestId:d}=o,c=new TextEncoder().encode("\vic-response");for(let f of l){let{timestamp:h,identity:w}=f,m=S.fromUint8Array(w).toText(),g;if(a==="replied"){let{reply:C}=o;g=en({status:a,reply:C,timestamp:BigInt(h),request_id:d})}else if(a==="rejected"){let{reject_code:C,reject_message:U,error_code:j}=o;g=en({status:a,reject_code:C,reject_message:U,error_code:j,timestamp:BigInt(h),request_id:d})}else throw new Error(`Unknown status: ${a}`);let v=ir(c,new Uint8Array(g)),R=s?.nodeKeys.get(m);if(!R)throw new Se("Invalid signature from replica signed query: no matching node key found.");let _=Fe.fromDer(R).rawKey;if(Wt.verify(f.signature,new Uint8Array(v),new Uint8Array(_)))return o;throw new Se(`Invalid signature from replica ${m} signed query.`)}return o}),this.config=e,at(this,It,e.fetch||$a()||fetch.bind(globalThis),"f"),at(this,ye,e.fetchOptions,"f"),at(this,Cr,e.callOptions,"f");let n=Ga(e.host);this.host=new URL(n),e.verifyQuerySignatures!==void 0&&at(this,Dt,e.verifyQuerySignatures,"f"),at(this,wt,(r=e.retryTimes)!==null&&r!==void 0?r:3,"f");let i=()=>new Ue({maxIterations:y(this,wt,"f")});if(at(this,Zt,e.backoffStrategy||i,"f"),this.host.hostname.endsWith(Va)?this.host.hostname=Ka:this.host.hostname.endsWith(qa)?this.host.hostname=ja:this.host.hostname.endsWith(Wa)&&(this.host.hostname=Ha),e.credentials){let{name:o,password:s}=e.credentials;at(this,yt,`${o}${s?":"+s:""}`,"f")}at(this,Rt,Promise.resolve(e.identity||new Mt),"f"),this.addTransform("update",bn(de)),e.useQueryNonces&&this.addTransform("query",bn(de)),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 y(this,Fr,"f")}static createSync(e={}){return new this(Object.assign({},e))}static async create(e={shouldFetchRootKey:!1}){let r=t.createSync(e),n=[r.syncTime()];return r.host.toString()!=="https://icp-api.io"&&e.shouldFetchRootKey&&n.push(r.fetchRootKey()),await Promise.all(n),r}static async from(e){var r;try{return"config"in e?await t.create(e.config):await t.create({fetch:e._fetch,fetchOptions:e._fetchOptions,callOptions:e._callOptions,host:e._host.toString(),identity:(r=e._identity)!==null&&r!==void 0?r:void 0})}catch{throw new nt("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,r,n=r.priority||0){if(e==="update"){let i=y(this,me,"f").findIndex(o=>(o.priority||0)<n);y(this,me,"f").splice(i>=0?i:y(this,me,"f").length,0,Object.assign(r,{priority:n}))}else if(e==="query"){let i=y(this,he,"f").findIndex(o=>(o.priority||0)<n);y(this,he,"f").splice(i>=0?i:y(this,he,"f").length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!y(this,Rt,"f"))throw new we("This identity has expired due this application's security policy. Please refresh your authentication.");return(await y(this,Rt,"f")).getPrincipal()}async call(e,r,n){let i=await(n!==void 0?await n:await y(this,Rt,"f"));if(!i)throw new we("This identity has expired due this application's security policy. Please refresh your authentication.");let o=S.from(e),s=r.effectiveCanisterId?S.from(r.effectiveCanisterId):o,a=i.getPrincipal()||S.anonymous(),l=new Jt(Pr);Math.abs(y(this,Me,"f"))>1e3*30&&(l=new Jt(Pr+y(this,Me,"f")));let d={request_type:wr.Call,canister_id:o,method_name:r.methodName,arg:r.arg,sender:a,ingress_expiry:l},c=await this._transform({request:{body:null,method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},y(this,yt,"f")?{Authorization:"Basic "+btoa(y(this,yt,"f"))}:{})},endpoint:"call",body:d}),f=c.body.nonce?h(c.body.nonce):void 0;d.nonce=f;function h(C){return new Uint8Array(C)}c=await i.transformRequest(c);let w=ar(c.body);this.log.print(`fetching "/api/v2/canister/${s.toText()}/call" with request:`,c);let m=y(this,Zt,"f").call(this),g=y(this,Ot,"m",Ur).call(this,{request:()=>y(this,It,"f").call(this,""+new URL(`/api/v2/canister/${s.toText()}/call`,this.host),Object.assign(Object.assign(Object.assign({},y(this,Cr,"f")),c.request),{body:w})),backoff:m,tries:0}),[v,R]=await Promise.all([g,Vt(d)]),_=await v.arrayBuffer(),E=v.status===200&&_.byteLength>0?ne(_):null;return{requestId:R,response:{ok:v.ok,status:v.status,statusText:v.statusText,body:E,headers:Be(v.headers)},requestDetails:d}}async query(e,r,n){let i=y(this,Zt,"f").call(this),o=r.effectiveCanisterId?S.from(r.effectiveCanisterId):S.from(e);this.log.print(`ecid ${o.toString()}`),this.log.print(`canisterId ${e.toString()}`);let s=async()=>{let w=await(n!==void 0?await n:await y(this,Rt,"f"));if(!w)throw new we("This identity has expired due this application's security policy. Please refresh your authentication.");let m=S.from(e),g=w?.getPrincipal()||S.anonymous(),v={request_type:"query",canister_id:m,method_name:r.methodName,arg:r.arg,sender:g,ingress_expiry:new Jt(Pr)},R=await Vt(v),_=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},y(this,yt,"f")?{Authorization:"Basic "+btoa(y(this,yt,"f"))}:{})},endpoint:"read",body:v});_=await w?.transformRequest(_);let E=ar(_.body),C={canister:m.toText(),ecid:o,transformedRequest:_,body:E,requestId:R,backoff:i,tries:0};return{requestDetails:v,query:await y(this,Ot,"m",eo).call(this,C)}},a=async()=>{if(!y(this,Dt,"f"))return;let w=y(this,Qt,"f").get(o.toString());return w||(await this.fetchSubnetKeys(o.toString()),y(this,Qt,"f").get(o.toString()))},[l,d]=await Promise.all([s(),a()]),{requestDetails:c,query:f}=l,h=Object.assign(Object.assign({},f),{requestDetails:c});if(this.log.print("Query response:",h),!y(this,Dt,"f"))return h;try{return y(this,Mr,"f").call(this,h,d)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),y(this,Qt,"f").delete(e.toString()),await this.fetchSubnetKeys(o.toString());let m=y(this,Qt,"f").get(e.toString());if(!m)throw new Se("Invalid signature from replica signed query: no matching node key found.");return y(this,Mr,"f").call(this,h,m)}}async createReadStateRequest(e,r){let n=await(r!==void 0?await r:await y(this,Rt,"f"));if(!n)throw new we("This identity has expired due this application's security policy. Please refresh your authentication.");let i=n?.getPrincipal()||S.anonymous(),o=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},y(this,yt,"f")?{Authorization:"Basic "+btoa(y(this,yt,"f"))}:{})},endpoint:"read_state",body:{request_type:"read_state",paths:e.paths,sender:i,ingress_expiry:new Jt(Pr)}});return n?.transformRequest(o)}async readState(e,r,n,i){let o=typeof e=="string"?S.fromText(e):e,s=i??await this.createReadStateRequest(r,n),a=ar(s.body);this.log.print(`fetching "/api/v2/canister/${o}/read_state" with request:`,s);let l=y(this,Zt,"f").call(this),d=await y(this,Ot,"m",Ur).call(this,{request:()=>y(this,It,"f").call(this,""+new URL(`/api/v2/canister/${o.toString()}/read_state`,this.host),Object.assign(Object.assign(Object.assign({},y(this,ye,"f")),s.request),{body:a})),backoff:l,tries:0});if(!d.ok)throw new Error(`Server returned an error:
|
|
1
|
+
import{A as gr,B as gn,C as kt,D as wn,E as se,F as yi,G as _n,H as pt,I as ht,J as gi,K as wr,L as wi,M as _i,N as xi,O as bi,P as ke,Q as _r,R as Ht,S as Ei,T as Ti,V as xn,a as ci,b as bs,c as dr,d as li,e as ui,f as di,g as T,h as Es,i as z,j as mn,k as fi,l as Ce,m as Ts,n as fr,o as Y,p as xt,q as pr,r as pi,s as hr,t as qt,u as yn,v as hi,w as mr,x as oe,y as yr,z as mi}from"./chunk-DMT35GPT.js";var Ui=ci(Tr=>{"use strict";Tr.byteLength=Os;Tr.toByteArray=Bs;Tr.fromByteArray=ks;var Et=[],lt=[],Rs=typeof Uint8Array<"u"?Uint8Array:Array,Sn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Zt=0,ki=Sn.length;Zt<ki;++Zt)Et[Zt]=Sn[Zt],lt[Sn.charCodeAt(Zt)]=Zt;var Zt,ki;lt[45]=62;lt[95]=63;function Fi(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function Os(t){var e=Fi(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Ns(t,e,r){return(e+r)*3/4-r}function Bs(t){var e,r=Fi(t),n=r[0],i=r[1],o=new Rs(Ns(t,n,i)),s=0,a=i>0?n-4:n,l;for(l=0;l<a;l+=4)e=lt[t.charCodeAt(l)]<<18|lt[t.charCodeAt(l+1)]<<12|lt[t.charCodeAt(l+2)]<<6|lt[t.charCodeAt(l+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=lt[t.charCodeAt(l)]<<2|lt[t.charCodeAt(l+1)]>>4,o[s++]=e&255),i===1&&(e=lt[t.charCodeAt(l)]<<10|lt[t.charCodeAt(l+1)]<<4|lt[t.charCodeAt(l+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Ps(t){return Et[t>>18&63]+Et[t>>12&63]+Et[t>>6&63]+Et[t&63]}function Cs(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(Ps(n));return i.join("")}function ks(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(Cs(t,s,s+o>a?a:s+o));return n===1?(e=t[r-1],i.push(Et[e>>2]+Et[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(Et[e>>10]+Et[e>>4&63]+Et[e<<2&63]+"=")),i.join("")}});var Di=ci(fe=>{"use strict";var Rn=Ui(),ue=Es(),Mi=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;fe.Buffer=u;fe.SlowBuffer=js;fe.INSPECT_MAX_BYTES=50;var Ar=2147483647;fe.kMaxLength=Ar;u.TYPED_ARRAY_SUPPORT=Fs();!u.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Fs(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}});Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function Ut(t){if(t>Ar)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Pn(t)}return qi(t,e,r)}u.poolSize=8192;function qi(t,e,r){if(typeof t=="string")return Ms(t,e);if(ArrayBuffer.isView(t))return Vs(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(Tt(t,ArrayBuffer)||t&&Tt(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Tt(t,SharedArrayBuffer)||t&&Tt(t.buffer,SharedArrayBuffer)))return Nn(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return u.from(n,e,r);let i=Ks(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return u.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}u.from=function(t,e,r){return qi(t,e,r)};Object.setPrototypeOf(u.prototype,Uint8Array.prototype);Object.setPrototypeOf(u,Uint8Array);function Hi(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function Us(t,e,r){return Hi(t),t<=0?Ut(t):e!==void 0?typeof r=="string"?Ut(t).fill(e,r):Ut(t).fill(e):Ut(t)}u.alloc=function(t,e,r){return Us(t,e,r)};function Pn(t){return Hi(t),Ut(t<0?0:Cn(t)|0)}u.allocUnsafe=function(t){return Pn(t)};u.allocUnsafeSlow=function(t){return Pn(t)};function Ms(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=$i(t,e)|0,n=Ut(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function On(t){let e=t.length<0?0:Cn(t.length)|0,r=Ut(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Vs(t){if(Tt(t,Uint8Array)){let e=new Uint8Array(t);return Nn(e.buffer,e.byteOffset,e.byteLength)}return On(t)}function Nn(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,u.prototype),n}function Ks(t){if(u.isBuffer(t)){let e=Cn(t.length)|0,r=Ut(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||Fn(t.length)?Ut(0):On(t);if(t.type==="Buffer"&&Array.isArray(t.data))return On(t.data)}function Cn(t){if(t>=Ar)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ar.toString(16)+" bytes");return t|0}function js(t){return+t!=t&&(t=0),u.alloc(+t)}u.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==u.prototype};u.compare=function(e,r){if(Tt(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),Tt(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),!u.isBuffer(e)||!u.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};u.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};u.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return u.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=u.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let s=e[n];if(Tt(s,Uint8Array))o+s.length>i.length?(u.isBuffer(s)||(s=u.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(u.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function $i(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Tt(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Bn(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Ii(t).length;default:if(i)return n?-1:Bn(t).length;e=(""+e).toLowerCase(),i=!0}}u.byteLength=$i;function qs(t,e,r){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return Qs(this,e,r);case"utf8":case"utf-8":return Gi(this,e,r);case"ascii":return Xs(this,e,r);case"latin1":case"binary":return Zs(this,e,r);case"base64":return Ys(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Is(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}u.prototype._isBuffer=!0;function Qt(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}u.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)Qt(this,r,r+1);return this};u.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)Qt(this,r,r+3),Qt(this,r+1,r+2);return this};u.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)Qt(this,r,r+7),Qt(this,r+1,r+6),Qt(this,r+2,r+5),Qt(this,r+3,r+4);return this};u.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Gi(this,0,e):qs.apply(this,arguments)};u.prototype.toLocaleString=u.prototype.toString;u.prototype.equals=function(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:u.compare(this,e)===0};u.prototype.inspect=function(){let e="",r=fe.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};Mi&&(u.prototype[Mi]=u.prototype.inspect);u.prototype.compare=function(e,r,n,i,o){if(Tt(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-r,l=Math.min(s,a),d=this.slice(i,o),c=e.slice(r,n);for(let f=0;f<l;++f)if(d[f]!==c[f]){s=d[f],a=c[f];break}return s<a?-1:a<s?1:0};function Wi(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,Fn(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=u.from(e,n)),u.isBuffer(e))return e.length===0?-1:Vi(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):Vi(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Vi(t,e,r,n,i){let o=1,s=t.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,a/=2,r/=2}function l(c,f){return o===1?c[f]:c.readUInt16BE(f*o)}let d;if(i){let c=-1;for(d=r;d<s;d++)if(l(t,d)===l(e,c===-1?0:d-c)){if(c===-1&&(c=d),d-c+1===a)return c*o}else c!==-1&&(d-=d-c),c=-1}else for(r+a>s&&(r=s-a),d=r;d>=0;d--){let c=!0;for(let f=0;f<a;f++)if(l(t,d+f)!==l(e,f)){c=!1;break}if(c)return d}return-1}u.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};u.prototype.indexOf=function(e,r,n){return Wi(this,e,r,n,!0)};u.prototype.lastIndexOf=function(e,r,n){return Wi(this,e,r,n,!1)};function Hs(t,e,r,n){r=Number(r)||0;let i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(Fn(a))return s;t[r+s]=a}return s}function $s(t,e,r,n){return vr(Bn(e,t.length-r),t,r,n)}function Ws(t,e,r,n){return vr(ea(e),t,r,n)}function Gs(t,e,r,n){return vr(Ii(e),t,r,n)}function zs(t,e,r,n){return vr(ra(e,t.length-r),t,r,n)}u.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return Hs(this,e,r,n);case"utf8":case"utf-8":return $s(this,e,r,n);case"ascii":case"latin1":case"binary":return Ws(this,e,r,n);case"base64":return Gs(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return zs(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Ys(t,e,r){return e===0&&r===t.length?Rn.fromByteArray(t):Rn.fromByteArray(t.slice(e,r))}function Gi(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let o=t[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=r){let l,d,c,f;switch(a){case 1:o<128&&(s=o);break;case 2:l=t[i+1],(l&192)===128&&(f=(o&31)<<6|l&63,f>127&&(s=f));break;case 3:l=t[i+1],d=t[i+2],(l&192)===128&&(d&192)===128&&(f=(o&15)<<12|(l&63)<<6|d&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:l=t[i+1],d=t[i+2],c=t[i+3],(l&192)===128&&(d&192)===128&&(c&192)===128&&(f=(o&15)<<18|(l&63)<<12|(d&63)<<6|c&63,f>65535&&f<1114112&&(s=f))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return Js(n)}var Ki=4096;function Js(t){let e=t.length;if(e<=Ki)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Ki));return r}function Xs(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function Zs(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function Qs(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=e;o<r;++o)i+=na[t[o]];return i}function Is(t,e,r){let n=t.slice(e,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}u.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let i=this.subarray(e,r);return Object.setPrototypeOf(i,u.prototype),i};function X(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||X(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return i};u.prototype.readUintBE=u.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||X(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};u.prototype.readUint8=u.prototype.readUInt8=function(e,r){return e=e>>>0,r||X(e,1,this.length),this[e]};u.prototype.readUint16LE=u.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||X(e,2,this.length),this[e]|this[e+1]<<8};u.prototype.readUint16BE=u.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||X(e,2,this.length),this[e]<<8|this[e+1]};u.prototype.readUint32LE=u.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||X(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};u.prototype.readUint32BE=u.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||X(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};u.prototype.readBigUInt64LE=$t(function(e){e=e>>>0,de(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fe(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});u.prototype.readBigUInt64BE=$t(function(e){e=e>>>0,de(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fe(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});u.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||X(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};u.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||X(e,r,this.length);let i=r,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};u.prototype.readInt8=function(e,r){return e=e>>>0,r||X(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};u.prototype.readInt16LE=function(e,r){e=e>>>0,r||X(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};u.prototype.readInt16BE=function(e,r){e=e>>>0,r||X(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};u.prototype.readInt32LE=function(e,r){return e=e>>>0,r||X(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};u.prototype.readInt32BE=function(e,r){return e=e>>>0,r||X(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};u.prototype.readBigInt64LE=$t(function(e){e=e>>>0,de(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fe(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});u.prototype.readBigInt64BE=$t(function(e){e=e>>>0,de(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Fe(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});u.prototype.readFloatLE=function(e,r){return e=e>>>0,r||X(e,4,this.length),ue.read(this,e,!0,23,4)};u.prototype.readFloatBE=function(e,r){return e=e>>>0,r||X(e,4,this.length),ue.read(this,e,!1,23,4)};u.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||X(e,8,this.length),ue.read(this,e,!0,52,8)};u.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||X(e,8,this.length),ue.read(this,e,!1,52,8)};function st(t,e,r,n,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;st(this,e,r,n,a,0)}let o=1,s=0;for(this[r]=e&255;++s<n&&(o*=256);)this[r+s]=e/o&255;return r+n};u.prototype.writeUintBE=u.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;st(this,e,r,n,a,0)}let o=n-1,s=1;for(this[r+o]=e&255;--o>=0&&(s*=256);)this[r+o]=e/s&255;return r+n};u.prototype.writeUint8=u.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,1,255,0),this[r]=e&255,r+1};u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function zi(t,e,r,n,i){Qi(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,r}function Yi(t,e,r,n,i){Qi(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s=s>>8,t[r+2]=s,s=s>>8,t[r+1]=s,s=s>>8,t[r]=s,r+8}u.prototype.writeBigUInt64LE=$t(function(e,r=0){return zi(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});u.prototype.writeBigUInt64BE=$t(function(e,r=0){return Yi(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});u.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);st(this,e,r,n,l-1,-l)}let o=0,s=1,a=0;for(this[r]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[r+o-1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};u.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);st(this,e,r,n,l-1,-l)}let o=n-1,s=1,a=0;for(this[r+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[r+o+1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};u.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};u.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};u.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};u.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};u.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||st(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};u.prototype.writeBigInt64LE=$t(function(e,r=0){return zi(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});u.prototype.writeBigInt64BE=$t(function(e,r=0){return Yi(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ji(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Xi(t,e,r,n,i){return e=+e,r=r>>>0,i||Ji(t,e,r,4,34028234663852886e22,-34028234663852886e22),ue.write(t,e,r,n,23,4),r+4}u.prototype.writeFloatLE=function(e,r,n){return Xi(this,e,r,!0,n)};u.prototype.writeFloatBE=function(e,r,n){return Xi(this,e,r,!1,n)};function Zi(t,e,r,n,i){return e=+e,r=r>>>0,i||Ji(t,e,r,8,17976931348623157e292,-17976931348623157e292),ue.write(t,e,r,n,52,8),r+8}u.prototype.writeDoubleLE=function(e,r,n){return Zi(this,e,r,!0,n)};u.prototype.writeDoubleBE=function(e,r,n){return Zi(this,e,r,!1,n)};u.prototype.copy=function(e,r,n,i){if(!u.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};u.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!u.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=r;o<n;++o)this[o]=e;else{let s=u.isBuffer(e)?e:u.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=s[o%a]}return this};var le={};function kn(t,e,r){le[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}kn("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);kn("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);kn("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=ji(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=ji(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function ji(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function Ds(t,e,r){de(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&Fe(e,t.length-(r+1))}function Qi(t,e,r,n,i,o){if(t>r||t<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${r}${s}`,new le.ERR_OUT_OF_RANGE("value",a,t)}Ds(n,i,o)}function de(t,e){if(typeof t!="number")throw new le.ERR_INVALID_ARG_TYPE(e,"number",t)}function Fe(t,e,r){throw Math.floor(t)!==t?(de(t,r),new le.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new le.ERR_BUFFER_OUT_OF_BOUNDS:new le.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var Ls=/[^+/0-9A-Za-z-_]/g;function ta(t){if(t=t.split("=")[0],t=t.trim().replace(Ls,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function Bn(t,e){e=e||1/0;let r,n=t.length,i=null,o=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function ea(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function ra(t,e){let r,n,i,o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Ii(t){return Rn.toByteArray(ta(t))}function vr(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function Tt(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Fn(t){return t!==t}var na=function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function $t(t){return typeof BigInt>"u"?ia:t}function ia(){throw new Error("BigInt not supported")}});var U=t=>t==null,$=t=>!U(t),As=class extends Error{},xr=(t,e)=>{if(U(t))throw new As(e)},bn="__bigint__",En="__principal__",Tn="__uint8array__",vs=(t,e)=>typeof e=="bigint"?{[bn]:`${e}`}:$(e)&&e instanceof T?{[En]:e.toText()}:$(e)&&e instanceof Uint8Array?{[Tn]:Array.from(e)}:e,Ss=(t,e)=>{let r=n=>e[n];return $(e)&&typeof e=="object"&&bn in e?BigInt(r(bn)):$(e)&&typeof e=="object"&&En in e?T.fromText(r(En)):$(e)&&typeof e=="object"&&Tn in e?Uint8Array.from(r(Tn)):e},Q=t=>$(t)?[t]:[],J=t=>t?.[0],Ai=async t=>{let e=new Blob([JSON.stringify(t,vs)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},br=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),Ss)},vi=()=>typeof window<"u";var ae=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:r})=>r(e))}subscribe(e){let r=Symbol();return this.callbacks.push({id:r,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:n})=>n!==r)}};var Ft=class t extends ae{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let r=super.subscribe(e);return e(this.authUser),r}reset(){this.authUser=null,this.populate(this.authUser)}};var An=({message:t,detail:e})=>{let r=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(r)};var Si=BigInt(144e11),Ri=!1,Oi={width:576,height:576},Ni={width:505,height:705},Bi="internetcomputer.org";var ce="http://127.0.0.1:5987",Pi="rdmx6-jaaaa-aaaaa-aaadq-cai";var bt=class t extends ae{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let r=super.subscribe(e);return e(this.env),r}};var vn=({width:t,height:e})=>{if(!vi()||U(window)||U(window.top))return;let{top:{innerWidth:r,innerHeight:n}}=window,i=n/2+screenY-e/2,o=r/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${o}`};var Er=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let r=()=>{let n=bt.getInstance().get()?.container;if(U(n)||n===!1)return`https://identity.${this.#t??Bi}`;let i=bt.getInstance().get(),o=$(i)&&$(i?.internetIdentityId)?i.internetIdentityId:Pi,{host:s,protocol:a}=new URL(n===!0?ce:n);return/apple/i.test(navigator?.vendor)?`${a}//${s}?canisterId=${o}`:`${a}//${o}.${s.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:vn(Oi)},identityProvider:r()}}},Ci=class{#t;#e;constructor({appName:e,logoUrl:r}){this.#t=e,this.#e=r}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:vn(Ni)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};var Ao=dr(Di());var Sr;(function(t){t[t.SysFatal=1]="SysFatal",t[t.SysTransient=2]="SysTransient",t[t.DestinationInvalid=3]="DestinationInvalid",t[t.CanisterReject=4]="CanisterReject",t[t.CanisterError=5]="CanisterError"})(Sr||(Sr={}));var oa=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},sa=new TextEncoder().encode(`
|
|
2
|
+
ic-request`),Mt=class{getPrincipal(){return this._principal||(this._principal=T.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:r}=e,n=oa(e,["body"]),i=await qt(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(fr(sa,i))}})}},Vt=class{getPrincipal(){return T.anonymous()}async transformRequest(e){return Object.assign(Object.assign({},e),{body:{content:e.body}})}};var Li=dr(hi());var Ue=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){let t=new Uint32Array(1);return window.crypto.getRandomValues(t),t[0]}if(typeof crypto<"u"&&crypto.getRandomValues){let t=new Uint32Array(1);return crypto.getRandomValues(t),t[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var Rr;(function(t){t.Call="call"})(Rr||(Rr={}));function pe(){let t=new ArrayBuffer(16),e=new DataView(t),r=Ue(),n=Ue(),i=Ue(),o=Ue();return e.setUint32(0,r),e.setUint32(4,n),e.setUint32(8,i),e.setUint32(12,o),t}var aa=BigInt(1e6),ca=60*1e3,Kt=class{constructor(e){let o=BigInt(Math.floor(Date.now()+e-ca))*aa/BigInt(1e9)/BigInt(60)*BigInt(60)*BigInt(1e9);this._value=o}toCBOR(){return Li.value.u64(this._value.toString(16),16)}toHash(){return fi(this._value)}};function Un(t=pe){return async e=>{let r=e.request.headers;e.request.headers=r,e.endpoint==="call"&&(e.body.nonce=t())}}function he(t){let e=[];return t.forEach((r,n)=>{e.push([n,r])}),e}var me=class extends z{constructor(e,r){super(e),this.response=r,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}},Or=class extends z{constructor(e,r,n){super(e),this.name="ReplicaTimeError",this.replicaTime=r,this.agent=n,Object.setPrototypeOf(this,new.target.prototype)}};var Nr=BigInt(4294967295),Mn=BigInt(32);function to(t,e=!1){return e?{h:Number(t&Nr),l:Number(t>>Mn&Nr)}:{h:Number(t>>Mn&Nr)|0,l:Number(t&Nr)|0}}function la(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){let{h:o,l:s}=to(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]}var ua=(t,e)=>BigInt(t>>>0)<<Mn|BigInt(e>>>0),da=(t,e,r)=>t>>>r,fa=(t,e,r)=>t<<32-r|e>>>r,pa=(t,e,r)=>t>>>r|e<<32-r,ha=(t,e,r)=>t<<32-r|e>>>r,ma=(t,e,r)=>t<<64-r|e>>>r-32,ya=(t,e,r)=>t>>>r-32|e<<64-r,ga=(t,e)=>e,wa=(t,e)=>t,_a=(t,e,r)=>t<<r|e>>>32-r,xa=(t,e,r)=>e<<r|t>>>32-r,ba=(t,e,r)=>e<<r-32|t>>>64-r,Ea=(t,e,r)=>t<<r-32|e>>>64-r;function Ta(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var Aa=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),va=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Sa=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ra=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,Oa=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),Na=(t,e,r,n,i,o)=>e+r+n+i+o+(t/2**32|0)|0;var Ba={fromBig:to,split:la,toBig:ua,shrSH:da,shrSL:fa,rotrSH:pa,rotrSL:ha,rotrBH:ma,rotrBL:ya,rotr32H:ga,rotr32L:wa,rotlSH:_a,rotlSL:xa,rotlBH:ba,rotlBL:Ea,add:Ta,add3L:Aa,add3H:va,add4L:Sa,add4H:Ra,add5H:Na,add5L:Oa},A=Ba;var[Pa,Ca]=A.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(t=>BigInt(t))),Wt=new Uint32Array(80),Gt=new Uint32Array(80),Vn=class extends di{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:r,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:l,Eh:d,El:c,Fh:f,Fl:h,Gh:m,Gl:y,Hh:_,Hl:N}=this;return[e,r,n,i,o,s,a,l,d,c,f,h,m,y,_,N]}set(e,r,n,i,o,s,a,l,d,c,f,h,m,y,_,N){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=l|0,this.Eh=d|0,this.El=c|0,this.Fh=f|0,this.Fl=h|0,this.Gh=m|0,this.Gl=y|0,this.Hh=_|0,this.Hl=N|0}process(e,r){for(let w=0;w<16;w++,r+=4)Wt[w]=e.getUint32(r),Gt[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let v=Wt[w-15]|0,O=Gt[w-15]|0,j=A.rotrSH(v,O,1)^A.rotrSH(v,O,8)^A.shrSH(v,O,7),Z=A.rotrSL(v,O,1)^A.rotrSL(v,O,8)^A.shrSL(v,O,7),V=Wt[w-2]|0,K=Gt[w-2]|0,D=A.rotrSH(V,K,19)^A.rotrBH(V,K,61)^A.shrSH(V,K,6),q=A.rotrSL(V,K,19)^A.rotrBL(V,K,61)^A.shrSL(V,K,6),dt=A.add4L(Z,q,Gt[w-7],Gt[w-16]),ft=A.add4H(dt,j,D,Wt[w-7],Wt[w-16]);Wt[w]=ft|0,Gt[w]=dt|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:l,Dh:d,Dl:c,Eh:f,El:h,Fh:m,Fl:y,Gh:_,Gl:N,Hh:S,Hl:R}=this;for(let w=0;w<80;w++){let v=A.rotrSH(f,h,14)^A.rotrSH(f,h,18)^A.rotrBH(f,h,41),O=A.rotrSL(f,h,14)^A.rotrSL(f,h,18)^A.rotrBL(f,h,41),j=f&m^~f&_,Z=h&y^~h&N,V=A.add5L(R,O,Z,Ca[w],Gt[w]),K=A.add5H(V,S,v,j,Pa[w],Wt[w]),D=V|0,q=A.rotrSH(n,i,28)^A.rotrBH(n,i,34)^A.rotrBH(n,i,39),dt=A.rotrSL(n,i,28)^A.rotrBL(n,i,34)^A.rotrBL(n,i,39),ft=n&o^n&a^o&a,Pt=i&s^i&l^s&l;S=_|0,R=N|0,_=m|0,N=y|0,m=f|0,y=h|0,{h:f,l:h}=A.add(d|0,c|0,K|0,D|0),d=a|0,c=l|0,a=o|0,l=s|0,o=n|0,s=i|0;let jt=A.add3L(D,dt,Pt);n=A.add3H(jt,K,q,ft),i=jt|0}({h:n,l:i}=A.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=A.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l}=A.add(this.Ch|0,this.Cl|0,a|0,l|0),{h:d,l:c}=A.add(this.Dh|0,this.Dl|0,d|0,c|0),{h:f,l:h}=A.add(this.Eh|0,this.El|0,f|0,h|0),{h:m,l:y}=A.add(this.Fh|0,this.Fl|0,m|0,y|0),{h:_,l:N}=A.add(this.Gh|0,this.Gl|0,_|0,N|0),{h:S,l:R}=A.add(this.Hh|0,this.Hl|0,S|0,R|0),this.set(n,i,o,s,a,l,d,c,f,h,m,y,_,N,S,R)}roundClean(){Wt.fill(0),Gt.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 eo=li(()=>new Vn);var mt=BigInt(0),at=BigInt(1),Br=BigInt(2),ka=BigInt(8),Fa={zip215:!0};function Ua(t){let e=xi(t);return yi(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function ro(t){let e=Ua(t),{Fp:r,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:l}=e,d=Br<<BigInt(a*8)-at,c=r.create,f=wr(e.n,e.nBitLength),h=e.uvRatio||((b,p)=>{try{return{isValid:!0,value:r.sqrt(b*r.inv(p))}}catch{return{isValid:!1,value:mt}}}),m=e.adjustScalarBytes||(b=>b),y=e.domain||((b,p,x)=>{if(yr("phflag",x),p.length||x)throw new Error("Contexts/pre-hash are not supported");return b});function _(b,p){se("coordinate "+b,p,mt,d)}function N(b){if(!(b instanceof w))throw new Error("ExtendedPoint expected")}let S=_n((b,p)=>{let{ex:x,ey:E,ez:B}=b,P=b.is0();p==null&&(p=P?ka:r.inv(B));let C=c(x*p),F=c(E*p),k=c(B*p);if(P)return{x:mt,y:at};if(k!==at)throw new Error("invZ was invalid");return{x:C,y:F}}),R=_n(b=>{let{a:p,d:x}=e;if(b.is0())throw new Error("bad point: ZERO");let{ex:E,ey:B,ez:P,et:C}=b,F=c(E*E),k=c(B*B),M=c(P*P),H=c(M*M),G=c(F*p),rt=c(M*c(G+k)),ot=c(H+c(x*c(F*k)));if(rt!==ot)throw new Error("bad point: equation left != right (1)");let L=c(E*B),ct=c(P*C);if(L!==ct)throw new Error("bad point: equation left != right (2)");return!0});class w{constructor(p,x,E,B){this.ex=p,this.ey=x,this.ez=E,this.et=B,_("x",p),_("y",x),_("z",E),_("t",B),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof w)throw new Error("extended point not allowed");let{x,y:E}=p||{};return _("x",x),_("y",E),new w(x,E,at,c(x*E))}static normalizeZ(p){let x=r.invertBatch(p.map(E=>E.ez));return p.map((E,B)=>E.toAffine(x[B])).map(w.fromAffine)}static msm(p,x){return _i(w,f,p,x)}_setWindowSize(p){j.setWindowSize(this,p)}assertValidity(){R(this)}equals(p){N(p);let{ex:x,ey:E,ez:B}=this,{ex:P,ey:C,ez:F}=p,k=c(x*F),M=c(P*B),H=c(E*F),G=c(C*B);return k===M&&H===G}is0(){return this.equals(w.ZERO)}negate(){return new w(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){let{a:p}=e,{ex:x,ey:E,ez:B}=this,P=c(x*x),C=c(E*E),F=c(Br*c(B*B)),k=c(p*P),M=x+E,H=c(c(M*M)-P-C),G=k+C,rt=G-F,ot=k-C,L=c(H*rt),ct=c(G*ot),Ct=c(H*ot),ie=c(rt*G);return new w(L,ct,ie,Ct)}add(p){N(p);let{a:x,d:E}=e,{ex:B,ey:P,ez:C,et:F}=this,{ex:k,ey:M,ez:H,et:G}=p;if(x===BigInt(-1)){let ir=c((P-B)*(M+k)),or=c((P+B)*(M-k)),Pe=c(or-ir);if(Pe===mt)return this.double();let sr=c(C*Br*G),ar=c(F*Br*H),cr=ar+sr,lr=or+ir,ur=ar-sr,fn=c(cr*Pe),pn=c(lr*ur),hn=c(cr*ur),xs=c(Pe*lr);return new w(fn,pn,xs,hn)}let rt=c(B*k),ot=c(P*M),L=c(F*E*G),ct=c(C*H),Ct=c((B+P)*(k+M)-rt-ot),ie=ct-L,er=ct+L,rr=c(ot-x*rt),nr=c(Ct*ie),ln=c(er*rr),un=c(Ct*rr),dn=c(ie*er);return new w(nr,ln,dn,un)}subtract(p){return this.add(p.negate())}wNAF(p){return j.wNAFCached(this,p,w.normalizeZ)}multiply(p){let x=p;se("scalar",x,at,n);let{p:E,f:B}=this.wNAF(x);return w.normalizeZ([E,B])[0]}multiplyUnsafe(p){let x=p;return se("scalar",x,mt,n),x===mt?O:this.equals(O)||x===at?this:this.equals(v)?this.wNAF(x).p:j.unsafeLadder(this,x)}isSmallOrder(){return this.multiplyUnsafe(l).is0()}isTorsionFree(){return j.unsafeLadder(this,n).is0()}toAffine(p){return S(this,p)}clearCofactor(){let{h:p}=e;return p===at?this:this.multiplyUnsafe(p)}static fromHex(p,x=!1){let{d:E,a:B}=e,P=r.BYTES;p=kt("pointHex",p,P),yr("zip215",x);let C=p.slice(),F=p[P-1];C[P-1]=F&-129;let k=gr(C),M=x?d:r.ORDER;se("pointHex.y",k,mt,M);let H=c(k*k),G=c(H-at),rt=c(E*H-B),{isValid:ot,value:L}=h(G,rt);if(!ot)throw new Error("Point.fromHex: invalid y coordinate");let ct=(L&at)===at,Ct=(F&128)!==0;if(!x&&L===mt&&Ct)throw new Error("Point.fromHex: x=0 and x_0=1");return Ct!==ct&&(L=c(-L)),w.fromAffine({x:L,y:k})}static fromPrivateKey(p){return K(p).point}toRawBytes(){let{x:p,y:x}=this.toAffine(),E=gn(x,r.BYTES);return E[E.length-1]|=p&at?128:0,E}toHex(){return mi(this.toRawBytes())}}w.BASE=new w(e.Gx,e.Gy,at,c(e.Gx*e.Gy)),w.ZERO=new w(mt,at,at,mt);let{BASE:v,ZERO:O}=w,j=wi(w,a*8);function Z(b){return pt(b,n)}function V(b){return Z(gr(b))}function K(b){let p=a;b=kt("private key",b,p);let x=kt("hashed private key",o(b),2*p),E=m(x.slice(0,p)),B=x.slice(p,2*p),P=V(E),C=v.multiply(P),F=C.toRawBytes();return{head:E,prefix:B,scalar:P,point:C,pointBytes:F}}function D(b){return K(b).pointBytes}function q(b=new Uint8Array,...p){let x=wn(...p);return V(o(y(x,kt("context",b),!!i)))}function dt(b,p,x={}){b=kt("message",b),i&&(b=i(b));let{prefix:E,scalar:B,pointBytes:P}=K(p),C=q(x.context,E,b),F=v.multiply(C).toRawBytes(),k=q(x.context,F,P,b),M=Z(C+k*B);se("signature.s",M,mt,n);let H=wn(F,gn(M,r.BYTES));return kt("result",H,a*2)}let ft=Fa;function Pt(b,p,x,E=ft){let{context:B,zip215:P}=E,C=r.BYTES;b=kt("signature",b,2*C),p=kt("message",p),P!==void 0&&yr("zip215",P),i&&(p=i(p));let F=gr(b.slice(C,2*C)),k,M,H;try{k=w.fromHex(x,P),M=w.fromHex(b.slice(0,C),P),H=v.multiplyUnsafe(F)}catch{return!1}if(!P&&k.isSmallOrder())return!1;let G=q(B,M.toRawBytes(),k.toRawBytes(),p);return M.add(k.multiplyUnsafe(G)).subtract(H).clearCofactor().equals(w.ZERO)}return v._setWindowSize(8),{CURVE:e,getPublicKey:D,sign:dt,verify:Pt,ExtendedPoint:w,utils:{getExtendedPublicKey:K,randomPrivateKey:()=>s(r.BYTES),precompute(b=8,p=w.BASE){return p._setWindowSize(b),p.multiply(BigInt(3)),p}}}}var Kn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),no=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),$l=BigInt(0),Ma=BigInt(1),io=BigInt(2),Wl=BigInt(3),Va=BigInt(5),Ka=BigInt(8);function ja(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),i=BigInt(80),o=Kn,a=t*t%o*t%o,l=ht(a,io,o)*a%o,d=ht(l,Ma,o)*t%o,c=ht(d,Va,o)*d%o,f=ht(c,e,o)*c%o,h=ht(f,r,o)*f%o,m=ht(h,n,o)*h%o,y=ht(m,i,o)*m%o,_=ht(y,i,o)*m%o,N=ht(_,e,o)*c%o;return{pow_p_5_8:ht(N,io,o)*t%o,b2:a}}function qa(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function Ha(t,e){let r=Kn,n=pt(e*e*e,r),i=pt(n*n*e,r),o=ja(t*i).pow_p_5_8,s=pt(t*n*o,r),a=pt(e*s*s,r),l=s,d=pt(s*no,r),c=a===t,f=a===pt(-t,r),h=a===pt(-t*no,r);return c&&(s=l),(f||h)&&(s=d),gi(s,r)&&(s=pt(-s,r)),{isValid:c||f,value:s}}var $a=wr(Kn,void 0,!0),Wa={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:$a,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Ka,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:eo,randomBytes:ui,adjustScalarBytes:qa,uvRatio:Ha},zt=ro(Wa);var oo=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},nt=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},tt,Me,so,ao,Pr=class{constructor(e={}){tt.set(this,void 0),Me.set(this,void 0),this[so]=this.entries.bind(this),this[ao]="ExpirableMap";let{source:r=[],expirationTime:n=10*60*1e3}=e,i=Date.now();oo(this,tt,new Map([...r].map(([o,s])=>[o,{value:s,timestamp:i}])),"f"),oo(this,Me,n,"f")}prune(){let e=Date.now();for(let[r,n]of nt(this,tt,"f").entries())e-n.timestamp>nt(this,Me,"f")&&nt(this,tt,"f").delete(r);return this}set(e,r){this.prune();let n={value:r,timestamp:Date.now()};return nt(this,tt,"f").set(e,n),this}get(e){let r=nt(this,tt,"f").get(e);if(r!==void 0){if(Date.now()-r.timestamp>nt(this,Me,"f")){nt(this,tt,"f").delete(e);return}return r.value}}clear(){nt(this,tt,"f").clear()}entries(){let e=nt(this,tt,"f").entries();return function*(){for(let[n,i]of e)yield[n,i.value]}()}values(){let e=nt(this,tt,"f").values();return function*(){for(let n of e)yield n.value}()}keys(){return nt(this,tt,"f").keys()}forEach(e,r){for(let[n,i]of nt(this,tt,"f").entries())e.call(r,i.value,n,this)}has(e){return nt(this,tt,"f").has(e)}delete(e){return nt(this,tt,"f").delete(e)}get size(){return nt(this,tt,"f").size}};tt=new WeakMap,Me=new WeakMap,so=Symbol.iterator,ao=Symbol.toStringTag;var co=t=>{if(t<=127)return 1;if(t<=255)return 2;if(t<=65535)return 3;if(t<=16777215)return 4;throw new Error("Length too long (> 4 bytes)")},lo=(t,e,r)=>{if(r<=127)return t[e]=r,1;if(r<=255)return t[e]=129,t[e+1]=r,2;if(r<=65535)return t[e]=130,t[e+1]=r>>8,t[e+2]=r,3;if(r<=16777215)return t[e]=131,t[e+1]=r>>16,t[e+2]=r>>8,t[e+3]=r,4;throw new Error("Length too long (> 4 bytes)")},jn=(t,e)=>{if(t[e]<128)return 1;if(t[e]===128)throw new Error("Invalid length 0");if(t[e]===129)return 2;if(t[e]===130)return 3;if(t[e]===131)return 4;throw new Error("Length too long (> 4 bytes)")},Ga=(t,e)=>{let r=jn(t,e);if(r===1)return t[e];if(r===2)return t[e+1];if(r===3)return(t[e+1]<<8)+t[e+2];if(r===4)return(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];throw new Error("Length too long (> 4 bytes)")},uo=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),It=Uint8Array.from([48,5,6,3,43,101,112]),Jl=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);function ye(t,e){let r=2+co(t.byteLength+1),n=e.byteLength+r+t.byteLength,i=0,o=new Uint8Array(1+co(n)+n);return o[i++]=48,i+=lo(o,i,n),o.set(e,i),i+=e.byteLength,o[i++]=3,i+=lo(o,i,t.byteLength+1),o[i++]=0,o.set(new Uint8Array(t),i),o}var Ve=(t,e)=>{let r=0,n=(a,l)=>{if(i[r++]!==a)throw new Error("Expected: "+l)},i=new Uint8Array(t);if(n(48,"sequence"),r+=jn(i,r),!pr(i.slice(r,r+e.byteLength),e))throw new Error("Not the expected OID.");r+=e.byteLength,n(3,"bit string");let o=Ga(i,r)-1;r+=jn(i,r),n(0,"0 padding");let s=i.slice(r);if(o!==s.length)throw new Error(`DER payload mismatch: Expected length ${o} actual length ${s.length}`);return s};var fo=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},po=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Cr,kr,Ke=class t{constructor(e){if(Cr.set(this,void 0),kr.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");fo(this,Cr,e,"f"),fo(this,kr,t.derEncode(e),"f")}static from(e){return this.fromDer(e.toDer())}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static derEncode(e){return ye(e,It).buffer}static derDecode(e){let r=Ve(e,It);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}get rawKey(){return po(this,Cr,"f")}get derKey(){return po(this,kr,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};Cr=new WeakMap,kr=new WeakMap;Ke.RAW_KEY_LENGTH=32;var qn=class{constructor(){this.observers=[]}subscribe(e){this.observers.push(e)}unsubscribe(e){this.observers=this.observers.filter(r=>r!==e)}notify(e,...r){this.observers.forEach(n=>n(e,...r))}},Fr=class extends qn{constructor(){super()}print(e,...r){this.notify({message:e,level:"info"},...r)}warn(e,...r){this.notify({message:e,level:"warn"},...r)}error(e,r,...n){this.notify({message:e,level:"error",error:r},...n)}};var At=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},et=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},vt,Ur,Mr,Vr,Kr,jr,qr,Hr,ge;var je=class t{constructor(e=t.default){vt.set(this,void 0),Ur.set(this,void 0),Mr.set(this,void 0),Vr.set(this,void 0),Kr.set(this,void 0),jr.set(this,void 0),qr.set(this,void 0),Hr.set(this,void 0),ge.set(this,0);let{initialInterval:r=500,randomizationFactor:n=.5,multiplier:i=1.5,maxInterval:o=6e4,maxElapsedTime:s=9e5,maxIterations:a=10,date:l=Date}=e;At(this,vt,r,"f"),At(this,Ur,n,"f"),At(this,Mr,i,"f"),At(this,Vr,o,"f"),At(this,Hr,l,"f"),At(this,Kr,l.now(),"f"),At(this,jr,s,"f"),At(this,qr,a,"f")}get ellapsedTimeInMsec(){return et(this,Hr,"f").now()-et(this,Kr,"f")}get currentInterval(){return et(this,vt,"f")}get count(){return et(this,ge,"f")}get randomValueFromInterval(){let e=et(this,Ur,"f")*et(this,vt,"f"),r=et(this,vt,"f")-e,n=et(this,vt,"f")+e;return Math.random()*(n-r)+r}incrementCurrentInterval(){var e;return At(this,vt,Math.min(et(this,vt,"f")*et(this,Mr,"f"),et(this,Vr,"f")),"f"),At(this,ge,(e=et(this,ge,"f"),e++,e),"f"),et(this,vt,"f")}next(){return this.ellapsedTimeInMsec>=et(this,jr,"f")||et(this,ge,"f")>=et(this,qr,"f")?null:(this.incrementCurrentInterval(),this.randomValueFromInterval)}};vt=new WeakMap,Ur=new WeakMap,Mr=new WeakMap,Vr=new WeakMap,Kr=new WeakMap,jr=new WeakMap,qr=new WeakMap,Hr=new WeakMap,ge=new WeakMap;je.default={initialInterval:500,randomizationFactor:.5,multiplier:1.5,maxInterval:6e4,maxElapsedTime:9e5,maxIterations:10,date:Date};var ho=t=>{let[e,r]=t.split("UTC"),n=e.trim().split(" ").reverse(),i=`${n[1]} ${n[0]} UTC`,o=r.trim().split(" ").reverse(),s=`${o[1]} ${o[0]} UTC`;return new Date(i)};var it=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},g=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Rt,St,Yt,be,qe,yt,$r,gt,Dt,He,Wr,Gr,_e,xe,Lt,te,mo,zr,Yr,$e,Ot;(function(t){t.Received="received",t.Processing="processing",t.Replied="replied",t.Rejected="rejected",t.Unknown="unknown",t.Done="done"})(Ot||(Ot={}));var we=5*60*1e3,Ya="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae";var Ja="ic0.app",Xa=".ic0.app",Za="icp0.io",Qa=".icp0.io",Ia="icp-api.io",Da=".icp-api.io",We=class extends z{constructor(e){super(e),this.message=e}},Ee=class extends z{constructor(e){super(e),this.message=e}};function La(){let t;if(typeof window<"u")if(window.fetch)t=window.fetch.bind(window);else throw new We("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)t=globalThis.fetch.bind(globalThis);else throw new We("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&&(t=self.fetch.bind(self));if(t)return t;throw new We("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context.")}function tc(t){let e;if(t!==void 0)!t.match(/^[a-z]+:/)&&typeof window<"u"?e=new URL(window.location.protocol+"//"+t):e=new URL(t);else{let r=["ic0.app","icp0.io","127.0.0.1","localhost"],n=[".github.dev",".gitpod.io"],i=typeof window<"u"?window.location:void 0,o=i?.hostname,s;o&&typeof o=="string"&&(n.some(a=>o.endsWith(a))?s=o:s=r.find(a=>o.endsWith(a))),i&&s?e=new URL(`${i.protocol}//${s}${i.port?":"+i.port:""}`):e=new URL("https://icp-api.io")}return e.toString()}var Ge=class t{constructor(e={}){var r;Rt.add(this),St.set(this,void 0),Yt.set(this,void 0),be.set(this,void 0),qe.set(this,void 0),yt.set(this,void 0),$r.set(this,!1),gt.set(this,void 0),Dt.set(this,void 0),this._isAgent=!0,this.config={},He.set(this,0),Wr.set(this,new Date(Date.now())),Gr.set(this,new Date(Date.now())),this.log=new Fr,_e.set(this,[]),xe.set(this,[]),Lt.set(this,new Pr({expirationTime:5*60*1e3})),te.set(this,!0),Yr.set(this,(o,s)=>{if(g(this,te,"f")===!1)return o;if(!s)throw new ke("Invalid signature from replica signed query: no matching node key found.");let{status:a,signatures:l=[],requestId:d}=o,c=new TextEncoder().encode("\vic-response");for(let f of l){let{timestamp:h,identity:m}=f,y=T.fromUint8Array(m).toText(),_;if(a==="replied"){let{reply:v}=o;_=yn({status:a,reply:v,timestamp:BigInt(h),request_id:d})}else if(a==="rejected"){let{reject_code:v,reject_message:O,error_code:j}=o;_=yn({status:a,reject_code:v,reject_message:O,error_code:j,timestamp:BigInt(h),request_id:d})}else throw new Error(`Unknown status: ${a}`);let N=fr(c,new Uint8Array(_)),S=s?.nodeKeys.get(y);if(!S)throw new ke("Invalid signature from replica signed query: no matching node key found.");let R=Ke.fromDer(S).rawKey;if(zt.verify(f.signature,new Uint8Array(N),new Uint8Array(R)))return o;throw new ke(`Invalid signature from replica ${y} signed query.`)}return o}),$e.set(this,o=>{let s=o.message;if(s?.includes("ingress_expiry")){let a=ho(s);throw new Or(s,a,this)}}),this.config=e,it(this,Yt,e.fetch||La()||fetch.bind(globalThis),"f"),it(this,be,e.fetchOptions,"f"),it(this,qe,e.callOptions,"f"),this.rootKey=e.rootKey?e.rootKey:xt(Ya);let n=tc(e.host);this.host=new URL(n),e.verifyQuerySignatures!==void 0&&it(this,te,e.verifyQuerySignatures,"f"),it(this,gt,(r=e.retryTimes)!==null&&r!==void 0?r:3,"f");let i=()=>new je({maxIterations:g(this,gt,"f")});if(it(this,Dt,e.backoffStrategy||i,"f"),this.host.hostname.endsWith(Xa)?this.host.hostname=Ja:this.host.hostname.endsWith(Qa)?this.host.hostname=Za:this.host.hostname.endsWith(Da)&&(this.host.hostname=Ia),e.credentials){let{name:o,password:s}=e.credentials;it(this,yt,`${o}${s?":"+s:""}`,"f")}it(this,St,Promise.resolve(e.identity||new Vt),"f"),this.addTransform("update",Un(pe)),e.useQueryNonces&&this.addTransform("query",Un(pe)),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 replicaTime(){let e=Date.now()-g(this,Wr,"f").getTime();return new Date(g(this,Gr,"f").getTime()+e)}set replicaTime(e){it(this,Wr,new Date(Date.now()),"f"),it(this,Gr,e,"f")}get waterMark(){return g(this,He,"f")}static createSync(e={}){return new this(Object.assign({},e))}static async create(e={shouldFetchRootKey:!1}){let r=t.createSync(e),n=[r.syncTime()];return r.host.toString()!=="https://icp-api.io"&&e.shouldFetchRootKey&&n.push(r.fetchRootKey()),await Promise.all(n),r}static async from(e){var r;try{return"config"in e?await t.create(e.config):await t.create({fetch:e._fetch,fetchOptions:e._fetchOptions,callOptions:e._callOptions,host:e._host.toString(),identity:(r=e._identity)!==null&&r!==void 0?r:void 0})}catch{throw new z("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,r,n=r.priority||0){if(e==="update"){let i=g(this,xe,"f").findIndex(o=>(o.priority||0)<n);g(this,xe,"f").splice(i>=0?i:g(this,xe,"f").length,0,Object.assign(r,{priority:n}))}else if(e==="query"){let i=g(this,_e,"f").findIndex(o=>(o.priority||0)<n);g(this,_e,"f").splice(i>=0?i:g(this,_e,"f").length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!g(this,St,"f"))throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");return(await g(this,St,"f")).getPrincipal()}async call(e,r,n){var i;let o=(i=r.callSync)!==null&&i!==void 0?i:!0,s=await(n!==void 0?await n:await g(this,St,"f"));if(!s)throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");let a=T.from(e),l=r.effectiveCanisterId?T.from(r.effectiveCanisterId):a,d=s.getPrincipal()||T.anonymous(),c=new Kt(we),f=this.replicaTime&&this.replicaTime.getTime()-Date.now();Math.abs(f)>1e3*30&&(c=new Kt(we+f));let h={request_type:Rr.Call,canister_id:a,method_name:r.methodName,arg:r.arg,sender:d,ingress_expiry:c},m=await this._transform({request:{body:null,method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},g(this,yt,"f")?{Authorization:"Basic "+btoa(g(this,yt,"f"))}:{})},endpoint:"call",body:h}),y=m.body.nonce?_(m.body.nonce):void 0;h.nonce=y;function _(R){return new Uint8Array(R)}m=await s.transformRequest(m);let N=mr(m.body),S=g(this,Dt,"f").call(this);try{let R=()=>(this.log.print(`fetching "/api/v3/canister/${l.toText()}/call" with request:`,m),g(this,Yt,"f").call(this,""+new URL(`/api/v3/canister/${l.toText()}/call`,this.host),Object.assign(Object.assign(Object.assign({},g(this,qe,"f")),m.request),{body:N}))),w=()=>(this.log.print(`fetching "/api/v2/canister/${l.toText()}/call" with request:`,m),g(this,Yt,"f").call(this,""+new URL(`/api/v2/canister/${l.toText()}/call`,this.host),Object.assign(Object.assign(Object.assign({},g(this,qe,"f")),m.request),{body:N}))),v=g(this,Rt,"m",zr).call(this,{request:o?R:w,backoff:S,tries:0}),[O,j]=await Promise.all([v,qt(h)]),Z=await O.arrayBuffer(),V=O.status===200&&Z.byteLength>0?oe(Z):null;if(V?.certificate){let K=await this.parseTimeFromResponse({certificate:V.certificate});it(this,He,K,"f")}return{requestId:j,response:{ok:O.ok,status:O.status,statusText:O.statusText,body:V,headers:he(O.headers)},requestDetails:h}}catch(R){if(R.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({},r),{callSync:!1}),n);throw this.log.error("Error while making call:",R),R}}async query(e,r,n){let i=g(this,Dt,"f").call(this),o=r.effectiveCanisterId?T.from(r.effectiveCanisterId):T.from(e);this.log.print(`ecid ${o.toString()}`),this.log.print(`canisterId ${e.toString()}`);let s=async()=>{let m=await(n!==void 0?await n:await g(this,St,"f"));if(!m)throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");let y=T.from(e),_=m?.getPrincipal()||T.anonymous(),N=new Kt(we),S=this.replicaTime&&this.replicaTime.getTime()-Date.now();Math.abs(S)>1e3*30&&(N=new Kt(we+S));let R={request_type:"query",canister_id:y,method_name:r.methodName,arg:r.arg,sender:_,ingress_expiry:N},w=await qt(R),v=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},g(this,yt,"f")?{Authorization:"Basic "+btoa(g(this,yt,"f"))}:{})},endpoint:"read",body:R});v=await m?.transformRequest(v);let O=mr(v.body),j={canister:y.toText(),ecid:o,transformedRequest:v,body:O,requestId:w,backoff:i,tries:0};return{requestDetails:R,query:await g(this,Rt,"m",mo).call(this,j)}},a=async()=>{if(!g(this,te,"f"))return;let m=g(this,Lt,"f").get(o.toString());return m||(await this.fetchSubnetKeys(o.toString()),g(this,Lt,"f").get(o.toString()))},[l,d]=await Promise.all([s(),a()]),{requestDetails:c,query:f}=l,h=Object.assign(Object.assign({},f),{requestDetails:c});if(this.log.print("Query response:",h),!g(this,te,"f"))return h;try{return g(this,Yr,"f").call(this,h,d)}catch{this.log.warn("Query response verification failed. Retrying with fresh subnet keys."),g(this,Lt,"f").delete(e.toString()),await this.fetchSubnetKeys(o.toString());let y=g(this,Lt,"f").get(e.toString());if(!y)throw new ke("Invalid signature from replica signed query: no matching node key found.");return g(this,Yr,"f").call(this,h,y)}}async createReadStateRequest(e,r){let n=await(r!==void 0?await r:await g(this,St,"f"));if(!n)throw new Ee("This identity has expired due this application's security policy. Please refresh your authentication.");let i=n?.getPrincipal()||T.anonymous(),o=new Kt(we),s=this.replicaTime&&this.replicaTime.getTime()-Date.now();Math.abs(s)>1e3*30&&(o=new Kt(we+s));let a=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},g(this,yt,"f")?{Authorization:"Basic "+btoa(g(this,yt,"f"))}:{})},endpoint:"read_state",body:{request_type:"read_state",paths:e.paths,sender:i,ingress_expiry:o}});return n?.transformRequest(a)}async readState(e,r,n,i){let o=typeof e=="string"?T.fromText(e):e,s=i??await this.createReadStateRequest(r,n),a=mr(s.body);this.log.print(`fetching "/api/v2/canister/${o}/read_state" with request:`,s);let l=g(this,Dt,"f").call(this);try{let d=await g(this,Rt,"m",zr).call(this,{request:()=>g(this,Yt,"f").call(this,""+new URL(`/api/v2/canister/${o.toString()}/read_state`,this.host),Object.assign(Object.assign(Object.assign({},g(this,be,"f")),s.request),{body:a})),backoff:l,tries:0});if(!d.ok)throw new Error(`Server returned an error:
|
|
3
3
|
Code: ${d.status} (${d.statusText})
|
|
4
4
|
Body: ${await d.text()}
|
|
5
|
-
`);let c=
|
|
6
|
-
Code: ${
|
|
7
|
-
Body: ${await
|
|
8
|
-
`,{ok:
|
|
9
|
-
${
|
|
10
|
-
Retrying query.`),await
|
|
5
|
+
`);let c=oe(await d.arrayBuffer());this.log.print("Read state response:",c);let f=await this.parseTimeFromResponse(c);return f>0&&(this.log.print("Read state response time:",f),it(this,He,f,"f")),c}catch(d){g(this,$e,"f").call(this,d)}throw new z("Failed to read state")}async parseTimeFromResponse(e){let r;if(e.certificate){let n=oe(e.certificate);if(n&&"tree"in n)r=n.tree;else throw new Error("Could not decode time from response");let i=Ti(["time"],r);if(i.status!==Ei.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 o=bi(hr(i.value));return this.log.print("Time from response:",o),this.log.print("Time from response in milliseconds:",Number(o)),Number(o)}else this.log.warn("No certificate found in response");return 0}async syncTime(e){let r=await import("./canisterStatus-Y5DRSSOV.js");try{e||this.log.print("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let i=(await r.request({canisterId:e??T.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),agent:this,paths:["time"]})).get("time");i&&(this.replicaTime=new Date(Number(i)))}catch(n){this.log.error("Caught exception while attempting to sync time",n)}}async status(){let e=g(this,yt,"f")?{Authorization:"Basic "+btoa(g(this,yt,"f"))}:{};this.log.print('fetching "/api/v2/status"');let r=g(this,Dt,"f").call(this),n=await g(this,Rt,"m",zr).call(this,{backoff:r,request:()=>g(this,Yt,"f").call(this,""+new URL("/api/v2/status",this.host),Object.assign({headers:e},g(this,be,"f"))),tries:0});return oe(await n.arrayBuffer())}async fetchRootKey(){if(!g(this,$r,"f")){let e=await this.status();this.rootKey=e.root_key,it(this,$r,!0,"f")}return this.rootKey}invalidateIdentity(){it(this,St,null,"f")}replaceIdentity(e){it(this,St,Promise.resolve(e),"f")}async fetchSubnetKeys(e){let r=T.from(e),i=(await xn({canisterId:r,paths:["subnet"],agent:this})).get("subnet");if(i&&typeof i=="object"&&"nodeKeys"in i)return g(this,Lt,"f").set(r.toText(),i),i}_transform(e){let r=Promise.resolve(e);if(e.endpoint==="call")for(let n of g(this,xe,"f"))r=r.then(i=>n(i).then(o=>o||i));else for(let n of g(this,_e,"f"))r=r.then(i=>n(i).then(o=>o||i));return r}};St=new WeakMap,Yt=new WeakMap,be=new WeakMap,qe=new WeakMap,yt=new WeakMap,$r=new WeakMap,gt=new WeakMap,Dt=new WeakMap,He=new WeakMap,Wr=new WeakMap,Gr=new WeakMap,_e=new WeakMap,xe=new WeakMap,Lt=new WeakMap,te=new WeakMap,Yr=new WeakMap,$e=new WeakMap,Rt=new WeakSet,mo=async function t(e){var r,n;let{ecid:i,transformedRequest:o,body:s,requestId:a,backoff:l,tries:d}=e,c=d===0?0:l.next();if(this.log.print(`fetching "/api/v2/canister/${i.toString()}/query" with tries:`,{tries:d,backoff:l,delay:c}),c===null)throw new z(`Timestamp failed to pass the watermark after retrying the configured ${g(this,gt,"f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);c>0&&await new Promise(y=>setTimeout(y,c));let f;try{this.log.print(`fetching "/api/v2/canister/${i.toString()}/query" with request:`,o);let y=await g(this,Yt,"f").call(this,""+new URL(`/api/v2/canister/${i.toString()}/query`,this.host),Object.assign(Object.assign(Object.assign({},g(this,be,"f")),o.request),{body:s}));if(y.status===200){let _=oe(await y.arrayBuffer());f=Object.assign(Object.assign({},_),{httpDetails:{ok:y.ok,status:y.status,statusText:y.statusText,headers:he(y.headers)},requestId:a})}else throw new me(`Gateway returned an error:
|
|
6
|
+
Code: ${y.status} (${y.statusText})
|
|
7
|
+
Body: ${await y.text()}
|
|
8
|
+
`,{ok:y.ok,status:y.status,statusText:y.statusText,headers:he(y.headers)})}catch(y){if(this.log.error("Caught exception while attempting to read state",y),g(this,$e,"f").call(this,y),d<g(this,gt,"f"))return this.log.warn(`Caught exception while attempting to make query:
|
|
9
|
+
${y}
|
|
10
|
+
Retrying query.`),await g(this,Rt,"m",t).call(this,Object.assign(Object.assign({},e),{tries:d+1}));throw y}let h=(n=(r=f.signatures)===null||r===void 0?void 0:r[0])===null||n===void 0?void 0:n.timestamp;if(!g(this,te,"f"))return f;if(!h)throw new Error("Timestamp not found in query response. This suggests a malformed or malicious response.");let m=Number(BigInt(h)/BigInt(1e6));if(this.log.print("watermark and timestamp",{waterMark:this.waterMark,timestamp:m}),Number(this.waterMark)>m){let y=new z("Timestamp is below the watermark. Retrying query.");if(this.log.error("Timestamp is below",y,{timestamp:h,waterMark:this.waterMark}),d<g(this,gt,"f"))return await g(this,Rt,"m",t).call(this,Object.assign(Object.assign({},e),{tries:d+1}));throw new z(`Timestamp failed to pass the watermark after retrying the configured ${g(this,gt,"f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`)}return f},zr=async function t(e){let{request:r,backoff:n,tries:i}=e,o=i===0?0:n.next();if(o===null)throw new z(`Timestamp failed to pass the watermark after retrying the configured ${g(this,gt,"f")} times. We cannot guarantee the integrity of the response since it could be a replay attack.`);o>0&&await new Promise(d=>setTimeout(d,o));let s;try{s=await r()}catch(d){if(g(this,gt,"f")>i)return this.log.warn(`Caught exception while attempting to make request:
|
|
11
11
|
${d}
|
|
12
|
-
Retrying request.`),await
|
|
12
|
+
Retrying request.`),await g(this,Rt,"m",t).call(this,{request:r,backoff:n,tries:i+1});throw d}if(s.ok)return s;let a=await s.clone().text();s.status===400&&a.includes("ingress_expiry")&&g(this,$e,"f").call(this,new z(a));let l=`Server returned an error:
|
|
13
13
|
Code: ${s.status} (${s.statusText})
|
|
14
14
|
Body: ${a}
|
|
15
|
-
`;if(i<
|
|
16
|
-
Request ID: ${
|
|
15
|
+
`;if(s.status===404&&s.url.includes("api/v3"))throw new me("v3 api not supported. Fall back to v2",{ok:s.ok,status:s.status,statusText:s.statusText,headers:he(s.headers)});if(i<g(this,gt,"f"))return await g(this,Rt,"m",t).call(this,{request:r,backoff:n,tries:i+1});throw new me(l,{ok:s.ok,status:s.status,statusText:s.statusText,headers:he(s.headers)})};var yo;(function(t){t.Error="err",t.GetPrincipal="gp",t.GetPrincipalResponse="gpr",t.Query="q",t.QueryResponse="qr",t.Call="c",t.CallResponse="cr",t.ReadState="rs",t.ReadStateResponse="rsr",t.Status="s",t.StatusResponse="sr"})(yo||(yo={}));function Hn(){let t=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.ic.agent:globalThis.ic.agent:window.ic.agent;if(!t)throw new Error("No Agent could be found.");return t}var Xr={};bs(Xr,{backoff:()=>xo,chain:()=>bo,conditionalDelay:()=>wo,defaultStrategy:()=>Jr,maxAttempts:()=>rc,once:()=>go,throttle:()=>nc,timeout:()=>_o});var ec=5*60*1e3;function Jr(){return bo(wo(go(),1e3),xo(1e3,1.2),_o(ec))}function go(){let t=!0;return async()=>t?(t=!1,!0):!1}function wo(t,e){return async(r,n,i)=>{if(await t(r,n,i))return new Promise(o=>setTimeout(o,e))}}function rc(t){let e=t;return async(r,n,i)=>{if(--e<=0)throw new Error(`Failed to retrieve a reply for request after ${t} attempts:
|
|
16
|
+
Request ID: ${Y(n)}
|
|
17
17
|
Request status: ${i}
|
|
18
|
-
`)}}function
|
|
19
|
-
Request ID: ${
|
|
18
|
+
`)}}function nc(t){return()=>new Promise(e=>setTimeout(e,t))}function _o(t){let e=Date.now()+t;return async(r,n,i)=>{if(Date.now()>e)throw new Error(`Request timed out after ${t} msec:
|
|
19
|
+
Request ID: ${Y(n)}
|
|
20
20
|
Request status: ${i}
|
|
21
|
-
`)}}function
|
|
22
|
-
Request ID: ${
|
|
23
|
-
Reject code: ${
|
|
24
|
-
Reject text: ${
|
|
25
|
-
`)}case
|
|
26
|
-
Request ID: ${
|
|
27
|
-
`)}throw new Error("unreachable")}var
|
|
28
|
-
`)),this.canisterId=e,this.methodName=r,this.type=n,this.props=i}},Nn=class extends Vr{constructor(e,r,n){var i;super(e,r,"query",{Status:n.status,Code:(i=yr[n.reject_code])!==null&&i!==void 0?i:`Unknown Code "${n.reject_code}"`,Message:n.reject_message}),this.result=n}},Bn=class extends Vr{constructor(e,r,n,i){super(e,r,"update",Object.assign({"Request ID":$(n)},i.body?Object.assign(Object.assign({},i.body.error_code?{"Error code":i.body.error_code}:{}),{"Reject code":String(i.body.reject_code),"Reject message":i.body.reject_message}):{"HTTP status code":i.status.toString(),"HTTP status text":i.statusText})),this.requestId=n,this.response=i}},ut=Symbol.for("ic-agent-metadata"),Lt=class t{constructor(e){this[ut]=Object.freeze(e)}static agentOf(e){return e[ut].config.agent}static interfaceOf(e){return e[ut].service}static canisterIdOf(e){return S.from(e[ut].config.canisterId)}static async install(e,r){let n=e.mode===void 0?{install:null}:e.mode,i=e.arg?[...new Uint8Array(e.arg)]:[],o=[...new Uint8Array(e.module)],s=typeof r.canisterId=="string"?S.fromText(r.canisterId):r.canisterId;await uo(r).install_code({mode:n,arg:i,wasm_module:o,canister_id:s,sender_canister_version:[]})}static async createCanister(e,r){function n(o){return[{controllers:o.controllers?[o.controllers]:[],compute_allocation:o.compute_allocation?[o.compute_allocation]:[],freezing_threshold:o.freezing_threshold?[o.freezing_threshold]:[],memory_allocation:o.memory_allocation?[o.memory_allocation]:[],reserved_cycles_limit:[],log_visibility:[],wasm_memory_limit:[]}]}let{canister_id:i}=await uo(e||{}).provisional_create_canister_with_cycles({amount:[],settings:n(r||{}),specified_id:[],sender_canister_version:[]});return i}static async createAndInstallCanister(e,r,n){let i=await this.createCanister(n);return await this.install(Object.assign({},r),Object.assign(Object.assign({},n),{canisterId:i})),this.createActor(e,Object.assign(Object.assign({},n),{canisterId:i}))}static createActorClass(e,r){let n=e({IDL:ve});class i extends t{constructor(s){if(!s.canisterId)throw new nt(`Canister ID is required, but received ${typeof s.canisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`);let a=typeof s.canisterId=="string"?S.fromText(s.canisterId):s.canisterId;super({config:Object.assign(Object.assign(Object.assign({},po),s),{canisterId:a}),service:n});for(let[l,d]of n._fields)r?.httpDetails&&d.annotations.push(Pn),r?.certificate&&d.annotations.push(ho),this[l]=Za(this,l,d,s.blsVerify)}}return i}static createActor(e,r){if(!r.canisterId)throw new nt(`Canister ID is required, but received ${typeof r.canisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`);return new(this.createActorClass(e))(r)}static createActorWithHttpDetails(e,r){return new(this.createActorClass(e,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(e,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(e,n))(r)}};function ge(t,e){let r=ve.decode(t,fo.Buffer.from(e));switch(r.length){case 0:return;case 1:return r[0];default:return r}}var po={pollingStrategyFactory:Kr.defaultStrategy},Pn="http-details",ho="certificate";function Za(t,e,r,n){let i;r.annotations.includes("query")||r.annotations.includes("composite_query")?i=async(s,...a)=>{var l,d;s=Object.assign(Object.assign({},s),(d=(l=t[ut].config).queryTransform)===null||d===void 0?void 0:d.call(l,e,a,Object.assign(Object.assign({},t[ut].config),s)));let c=s.agent||t[ut].config.agent||Rn(),f=S.from(s.canisterId||t[ut].config.canisterId),h=ve.encode(r.argTypes,a),w=await c.query(f,{methodName:e,arg:h,effectiveCanisterId:s.effectiveCanisterId}),m=Object.assign(Object.assign({},w.httpDetails),{requestDetails:w.requestDetails});switch(w.status){case"rejected":throw new Nn(f,e,w);case"replied":return r.annotations.includes(Pn)?{httpDetails:m,result:ge(r.retTypes,w.reply.arg)}:ge(r.retTypes,w.reply.arg)}}:i=async(s,...a)=>{var l,d;s=Object.assign(Object.assign({},s),(d=(l=t[ut].config).callTransform)===null||d===void 0?void 0:d.call(l,e,a,Object.assign(Object.assign({},t[ut].config),s)));let c=s.agent||t[ut].config.agent||Rn(),{canisterId:f,effectiveCanisterId:h,pollingStrategyFactory:w}=Object.assign(Object.assign(Object.assign({},po),t[ut].config),s),m=S.from(f),g=h!==void 0?S.from(h):m,v=ve.encode(r.argTypes,a),{requestId:R,response:_,requestDetails:E}=await c.call(m,{methodName:e,arg:v,effectiveCanisterId:g});if(!_.ok||_.body)throw new Bn(m,e,R,_);let C=w(),{certificate:U,reply:j}=await On(c,g,R,C,n),tt=r.annotations.includes(Pn),K=r.annotations.includes(ho),q=Object.assign(Object.assign({},_),{requestDetails:E});if(j!==void 0)return tt&&K?{httpDetails:q,certificate:U,result:ge(r.retTypes,j)}:K?{certificate:U,result:ge(r.retTypes,j)}:tt?{httpDetails:q,result:ge(r.retTypes,j)}:ge(r.retTypes,j);if(r.retTypes.length===0)return tt?{httpDetails:_,result:void 0}:void 0;throw new Error(`Call was returned undefined, but type [${r.retTypes.join(",")}].`)};let o=(...s)=>i({},...s);return o.withOptions=s=>(...a)=>i(s,...a),o}function uo(t){function e(r,n){if(t.effectiveCanisterId)return{effectiveCanisterId:S.from(t.effectiveCanisterId)};let i=n[0],o=S.fromHex("");return i&&typeof i=="object"&&i.canister_id&&(o=S.from(i.canister_id)),{effectiveCanisterId:o}}return Lt.createActor(lo,Object.assign(Object.assign(Object.assign({},t),{canisterId:S.fromHex("")}),{callTransform:e,queryTransform:e}))}var Hr=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},$t=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},jr,qr,_e,xe;function mo(t){return t!==null&&typeof t=="object"}var te=class t{constructor(e){if(jr.set(this,void 0),qr.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");Hr(this,jr,e,"f"),Hr(this,qr,t.derEncode(e),"f")}static from(e){if(typeof e=="string"){let r=bt(e);return this.fromRaw(r)}else if(mo(e)){let r=e;if(mo(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(sr(n.buffer))}else{if(r instanceof ArrayBuffer)return this.fromRaw(r);if("rawKey"in r)return this.fromRaw(r.rawKey);if("derKey"in r)return this.fromDer(r.derKey);if("toDer"in r)return this.fromDer(r.toDer())}}throw new Error("Cannot construct Ed25519PublicKey from the provided key.")}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static derEncode(e){let r=fe(e,Xt).buffer;return r.__derEncodedPublicKey__=void 0,r}static derDecode(e){let r=ke(e,Xt);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}get rawKey(){return $t(this,jr,"f")}get derKey(){return $t(this,qr,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};jr=new WeakMap,qr=new WeakMap;te.RAW_KEY_LENGTH=32;var ee=class t extends Ut{constructor(e,r){super(),_e.set(this,void 0),xe.set(this,void 0),Hr(this,_e,te.from(e),"f"),Hr(this,xe,new Uint8Array(r),"f")}static generate(e){if(e&&e.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");e||(e=Wt.utils.randomPrivateKey()),or(e,new Uint8Array(new Array(32).fill(0)))&&console.warn("Seed is all zeros. This is not a secure seed. Please provide a seed with sufficient entropy if this is a production environment.");let r=new Uint8Array(32);for(let i=0;i<32;i++)r[i]=new Uint8Array(e)[i];let n=Wt.getPublicKey(r);return t.fromKeyPair(n,r)}static fromParsedJson(e){let[r,n]=e;return new t(te.fromDer(bt(r)),bt(n))}static fromJSON(e){let r=JSON.parse(e);if(Array.isArray(r)){if(typeof r[0]=="string"&&typeof r[1]=="string")return this.fromParsedJson([r[0],r[1]]);throw new Error("Deserialization error: JSON must have at least 2 items.")}throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(e)}`)}static fromKeyPair(e,r){return new t(te.fromRaw(e),r)}static fromSecretKey(e){let r=Wt.getPublicKey(new Uint8Array(e));return t.fromKeyPair(r,e)}toJSON(){return[$($t(this,_e,"f").toDer()),$($t(this,xe,"f"))]}getKeyPair(){return{secretKey:$t(this,xe,"f"),publicKey:$t(this,_e,"f")}}getPublicKey(){return $t(this,_e,"f")}async sign(e){let r=new Uint8Array(e),n=ti(Wt.sign(r,$t(this,xe,"f").slice(0,32)));return Object.defineProperty(n,"__signature__",{enumerable:!1,value:void 0}),n}static verify(e,r,n){let[i,o,s]=[e,r,n].map(a=>(typeof a=="string"&&(a=bt(a)),a instanceof Uint8Array&&(a=a.buffer),new Uint8Array(a)));return Wt.verify(o,i,s)}};_e=new WeakMap,xe=new WeakMap;var Cn=class t extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,t.prototype)}};function yo(t){if(typeof globalThis<"u"&&globalThis.crypto&&globalThis.crypto.subtle)return globalThis.crypto.subtle;if(t)return t;if(typeof crypto<"u"&&crypto.subtle)return crypto.subtle;throw new Cn("Global crypto was not available and none was provided. Please inlcude a SubtleCrypto implementation. See https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto")}var je=class t extends Ut{constructor(e,r,n){super(),this._keyPair=e,this._derKey=r,this._subtleCrypto=n}static async generate(e){let{extractable:r=!1,keyUsages:n=["sign","verify"],subtleCrypto:i}=e??{},o=yo(i),s=await o.generateKey({name:"ECDSA",namedCurve:"P-256"},r,n),a=await o.exportKey("spki",s.publicKey);return new this(s,a,o)}static async fromKeyPair(e,r){let n=yo(r),i=await n.exportKey("spki",e.publicKey);return new t(e,i,n)}getKeyPair(){return this._keyPair}getPublicKey(){let e=this._derKey,r=Object.create(this._keyPair.publicKey);return r.toDer=function(){return e},r}async sign(e){let r={name:"ECDSA",hash:{name:"SHA-256"}};return this._keyPair.privateKey,await this._subtleCrypto.sign(r,this._keyPair.privateKey,e)}};var be=nr(ei());var Ia=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},qe=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Gt,Wr=class{constructor(e){Gt.set(this,void 0),Ia(this,Gt,e,"f")}get rawKey(){return qe(this,Gt,"f").rawKey}get derKey(){return qe(this,Gt,"f").derKey}toDer(){return qe(this,Gt,"f").toDer()}getPublicKey(){return qe(this,Gt,"f")}getPrincipal(){return S.from(qe(this,Gt,"f").rawKey)}transformRequest(){return Promise.reject("Not implemented. You are attempting to use a partial identity to sign calls, but this identity only has access to the public key.To sign calls, use a DelegationIdentity instead.")}};Gt=new WeakMap;var Da=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},La=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},tc=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},$r,ec=new TextEncoder().encode("ic-request-auth-delegation"),rc=new TextEncoder().encode(`
|
|
29
|
-
ic-request`);function kn(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return bt(t)}var Ee=class{constructor(e,r,n){this.pubkey=e,this.expiration=r,this.targets=n}toCBOR(){return be.value.map(Object.assign({pubkey:be.value.bytes(this.pubkey),expiration:be.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:be.value.array(this.targets.map(e=>be.value.bytes(e.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:$(this.pubkey)},this.targets&&{targets:this.targets.map(e=>e.toHex())})}};async function nc(t,e,r,n){let i=new Ee(e.toDer(),BigInt(+r)*BigInt(1e6),n),o=new Uint8Array([...ec,...new Uint8Array(Vt(i))]),s=await t.sign(o);return{delegation:i,signature:s}}var He=class t{constructor(e,r){this.delegations=e,this.publicKey=r}static async create(e,r,n=new Date(Date.now()+15*60*1e3),i={}){var o,s;let a=await nc(e,r,n,i.targets);return new t([...((o=i.previous)===null||o===void 0?void 0:o.delegations)||[],a],((s=i.previous)===null||s===void 0?void 0:s.publicKey)||e.getPublicKey().toDer())}static fromJSON(e){let{publicKey:r,delegations:n}=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(n))throw new Error("Invalid delegations.");let i=n.map(o=>{let{delegation:s,signature:a}=o,{pubkey:l,expiration:d,targets:c}=s;if(c!==void 0&&!Array.isArray(c))throw new Error("Invalid targets.");return{delegation:new Ee(kn(l),BigInt("0x"+d),c&&c.map(f=>{if(typeof f!="string")throw new Error("Invalid target.");return S.fromHex(f)})),signature:kn(a)}});return new this(i,kn(r))}static fromDelegations(e,r){return new this(e,r)}toJSON(){return{delegations:this.delegations.map(e=>{let{delegation:r,signature:n}=e,{targets:i}=r;return{delegation:Object.assign({expiration:r.expiration.toString(16),pubkey:$(r.pubkey)},i&&{targets:i.map(o=>o.toHex())}),signature:$(n)}}),publicKey:$(this.publicKey)}}},We=class extends Ut{constructor(e,r){super(),this._inner=e,this._delegation=r}static fromDelegation(e,r){return new this(e,r)}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(e){return this._inner.sign(e)}async transformRequest(e){let{body:r}=e,n=tc(e,["body"]),i=await Vt(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_sig:await this.sign(new Uint8Array([...rc,...new Uint8Array(i)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}},$e=class t extends Wr{constructor(e,r){super(e),$r.set(this,void 0),Da(this,$r,r,"f")}get delegation(){return La(this,$r,"f")}static fromDelegation(e,r){return new t(e,r)}};$r=new WeakMap;function wo(t,e){for(let{delegation:i}of t.delegations)if(+new Date(Number(i.expiration/BigInt(1e6)))<=+Date.now())return!1;let r=[],n=e?.scope;n&&(Array.isArray(n)?r.push(...n.map(i=>typeof i=="string"?S.fromText(i):i)):r.push(typeof n=="string"?S.fromText(n):n));for(let i of r){let o=i.toText();for(let{delegation:s}of t.delegations){if(s.targets===void 0)continue;let a=!0;for(let l of s.targets)if(l.toText()===o){a=!1;break}if(a)return!1}}return!0}var ic=nr(ps());var go;(function(t){t[t.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(go||(go={}));var _o=["mousedown","mousemove","keydown","touchstart","wheel"],Ge=class{constructor(e={}){var r;this.callbacks=[],this.idleTimeout=10*60*1e3,this.timeoutID=void 0;let{onIdle:n,idleTimeout:i=10*60*1e3}=e||{};this.callbacks=n?[n]:[],this.idleTimeout=i;let o=this._resetTimer.bind(this);window.addEventListener("load",o,!0),_o.forEach(function(a){document.addEventListener(a,o,!0)});let s=(a,l)=>{let d;return(...c)=>{let f=this,h=function(){d=void 0,a.apply(f,c)};clearTimeout(d),d=window.setTimeout(h,l)}};if(e?.captureScroll){let a=s(o,(r=e?.scrollDebounce)!==null&&r!==void 0?r:100);window.addEventListener("scroll",a,!0)}o()}static create(e={}){return new this(e)}registerCallback(e){this.callbacks.push(e)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let e=this._resetTimer.bind(this);_o.forEach(function(r){document.removeEventListener(r,e,!0)}),this.callbacks.forEach(r=>r())}_resetTimer(){let e=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(e,this.idleTimeout)}};var oc=(t,e)=>e.some(r=>t instanceof r),xo,bo;function sc(){return xo||(xo=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function ac(){return bo||(bo=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var Eo=new WeakMap,Un=new WeakMap,To=new WeakMap,Fn=new WeakMap,Kn=new WeakMap;function cc(t){let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("success",o),t.removeEventListener("error",s)},o=()=>{r(Bt(t.result)),i()},s=()=>{n(t.error),i()};t.addEventListener("success",o),t.addEventListener("error",s)});return e.then(r=>{r instanceof IDBCursor&&Eo.set(r,t)}).catch(()=>{}),Kn.set(e,t),e}function lc(t){if(Un.has(t))return;let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("complete",o),t.removeEventListener("error",s),t.removeEventListener("abort",s)},o=()=>{r(),i()},s=()=>{n(t.error||new DOMException("AbortError","AbortError")),i()};t.addEventListener("complete",o),t.addEventListener("error",s),t.addEventListener("abort",s)});Un.set(t,e)}var Mn={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return Un.get(t);if(e==="objectStoreNames")return t.objectStoreNames||To.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return Bt(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function Ao(t){Mn=t(Mn)}function uc(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(Gr(this),e,...r);return To.set(n,e.sort?e.sort():[e]),Bt(n)}:ac().includes(t)?function(...e){return t.apply(Gr(this),e),Bt(Eo.get(this))}:function(...e){return Bt(t.apply(Gr(this),e))}}function dc(t){return typeof t=="function"?uc(t):(t instanceof IDBTransaction&&lc(t),oc(t,sc())?new Proxy(t,Mn):t)}function Bt(t){if(t instanceof IDBRequest)return cc(t);if(Fn.has(t))return Fn.get(t);let e=dc(t);return e!==t&&(Fn.set(t,e),Kn.set(e,t)),e}var Gr=t=>Kn.get(t);function So(t,e,{blocked:r,upgrade:n,blocking:i,terminated:o}={}){let s=indexedDB.open(t,e),a=Bt(s);return n&&s.addEventListener("upgradeneeded",l=>{n(Bt(s.result),l.oldVersion,l.newVersion,Bt(s.transaction),l)}),r&&s.addEventListener("blocked",l=>r(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),i&&l.addEventListener("versionchange",d=>i(d.oldVersion,d.newVersion,d))}).catch(()=>{}),a}var fc=["get","getKey","getAll","getAllKeys","count"],pc=["put","add","delete","clear"],Vn=new Map;function vo(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(Vn.get(e))return Vn.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,i=pc.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(i||fc.includes(r)))return;let o=async function(s,...a){let l=this.transaction(s,i?"readwrite":"readonly"),d=l.store;return n&&(d=d.index(a.shift())),(await Promise.all([d[r](...a),i&&l.done]))[0]};return Vn.set(e,o),o}Ao(t=>({...t,get:(e,r,n)=>vo(e,r)||t.get(e,r,n),has:(e,r)=>!!vo(e,r)||t.has(e,r)}));var Ro="auth-client-db",Oo="ic-keyval",hc=async(t=Ro,e=Oo,r)=>(zr&&(localStorage!=null&&localStorage.getItem(gt))&&(localStorage.removeItem(gt),localStorage.removeItem(_t)),await So(t,r,{upgrade:n=>{n.objectStoreNames,n.objectStoreNames.contains(e)&&n.clear(e),n.createObjectStore(e)}}));async function mc(t,e,r){return await t.get(e,r)}async function yc(t,e,r,n){return await t.put(e,n,r)}async function wc(t,e,r){return await t.delete(e,r)}var ze=class t{constructor(e,r){this._db=e,this._storeName=r}static async create(e){let{dbName:r=Ro,storeName:n=Oo,version:i=No}=e??{},o=await hc(r,n,i);return new t(o,n)}async set(e,r){return await yc(this._db,this._storeName,e,r)}async get(e){var r;return(r=await mc(this._db,this._storeName,e))!==null&&r!==void 0?r:null}async remove(e){return await wc(this._db,this._storeName,e)}};var gc=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},_c=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Yr,_t="identity",gt="delegation",Bo="iv",No=1,zr=typeof window<"u",Ye=class{constructor(e="ic-",r){this.prefix=e,this._localStorage=r}get(e){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+e))}set(e,r){return this._getLocalStorage().setItem(this.prefix+e,r),Promise.resolve()}remove(e){return this._getLocalStorage().removeItem(this.prefix+e),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let e=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.localStorage:globalThis.localStorage:window.localStorage;if(!e)throw new Error("Could not find local storage.");return e}},Je=class{constructor(e){Yr.set(this,void 0),gc(this,Yr,e??{},"f")}get _db(){return new Promise(e=>{if(this.initializedDb){e(this.initializedDb);return}ze.create(_c(this,Yr,"f")).then(r=>{this.initializedDb=r,e(r)})})}async get(e){return await(await this._db).get(e)}async set(e,r){await(await this._db).set(e,r)}async remove(e){await(await this._db).remove(e)}};Yr=new WeakMap;var xc="https://identity.ic0.app",bc="#authorize",jn="ECDSA",qn="Ed25519",Ec=500,Tc="UserInterrupt",Jr=class{constructor(e,r,n,i,o,s,a,l){this._identity=e,this._key=r,this._chain=n,this._storage=i,this.idleManager=o,this._createOptions=s,this._idpWindow=a,this._eventHandler=l,this._registerDefaultIdleCallback()}static async create(e={}){var r,n,i;let o=(r=e.storage)!==null&&r!==void 0?r:new Je,s=(n=e.keyType)!==null&&n!==void 0?n:jn,a=null;if(e.identity)a=e.identity;else{let f=await o.get(_t);if(!f&&zr)try{let h=new Ye,w=await h.get(gt),m=await h.get(_t);w&&m&&s===jn&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await o.set(gt,w),await o.set(_t,m),f=w,await h.remove(gt),await h.remove(_t))}catch(h){console.error("error while attempting to recover localstorage: "+h)}if(f)try{typeof f=="object"?s===qn&&typeof f=="string"?a=await ee.fromJSON(f):a=await je.fromKeyPair(f):typeof f=="string"&&(a=ee.fromJSON(f))}catch{}}let l=new Mt,d=null;if(a)try{let f=await o.get(gt);if(typeof f=="object"&&f!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?l=e.identity:f&&(d=He.fromJSON(f),wo(d)?"toDer"in a?l=$e.fromDelegation(a,d):l=We.fromDelegation(a,d):(await Hn(o),a=null))}catch(f){console.error(f),await Hn(o),a=null}let c;return!((i=e.idleOptions)===null||i===void 0)&&i.disableIdle?c=void 0:(d||e.identity)&&(c=Ge.create(e.idleOptions)),a||(s===qn?(a=await ee.generate(),await o.set(_t,JSON.stringify(a.toJSON()))):(e.storage&&s===jn&&console.warn(`You are using a custom storage provider that may not support CryptoKey storage. If you are using a custom storage provider that does not support CryptoKey storage, you should use '${qn}' as the key type, as it can serialize to a string`),a=await je.generate(),await o.set(_t,a.getKeyPair()))),new this(l,a,d,o,c,e)}_registerDefaultIdleCallback(){var e,r;let n=(e=this._createOptions)===null||e===void 0?void 0:e.idleOptions;!n?.onIdle&&!n?.disableDefaultIdleCallback&&((r=this.idleManager)===null||r===void 0||r.registerCallback(()=>{this.logout(),location.reload()}))}async _handleSuccess(e,r){var n,i;let o=e.delegations.map(d=>({delegation:new Ee(d.delegation.pubkey,d.delegation.expiration,d.delegation.targets),signature:d.signature.buffer})),s=He.fromDelegations(o,e.userPublicKey.buffer),a=this._key;if(!a)return;this._chain=s,"toDer"in a?this._identity=$e.fromDelegation(a,this._chain):this._identity=We.fromDelegation(a,this._chain),(n=this._idpWindow)===null||n===void 0||n.close();let l=(i=this._createOptions)===null||i===void 0?void 0:i.idleOptions;!this.idleManager&&!l?.disableIdle&&(this.idleManager=Ge.create(l),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(gt,JSON.stringify(this._chain.toJSON())),r?.(e)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null}async login(e){var r,n,i,o;let s=BigInt(8)*BigInt(36e11),a=new URL(((r=e?.identityProvider)===null||r===void 0?void 0:r.toString())||xc);a.hash=bc,(n=this._idpWindow)===null||n===void 0||n.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(a,Object.assign({maxTimeToLive:(i=e?.maxTimeToLive)!==null&&i!==void 0?i:s},e)),window.addEventListener("message",this._eventHandler),this._idpWindow=(o=window.open(a.toString(),"idpWindow",e?.windowOpenerFeatures))!==null&&o!==void 0?o:void 0;let l=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(Tc,e?.onError):setTimeout(l,Ec))};l()}_getEventHandler(e,r){return async n=>{var i,o,s;if(n.origin!==e.origin){console.warn(`WARNING: expected origin '${e.origin}', got '${n.origin}' (ignoring)`);return}let a=n.data;switch(a.kind){case"authorize-ready":{let l=Object.assign({kind:"authorize-client",sessionPublicKey:new Uint8Array((i=this._key)===null||i===void 0?void 0:i.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,allowPinAuthentication:r?.allowPinAuthentication,derivationOrigin:(o=r?.derivationOrigin)===null||o===void 0?void 0:o.toString()},r?.customValues);(s=this._idpWindow)===null||s===void 0||s.postMessage(l,e.origin);break}case"authorize-client-success":try{await this._handleSuccess(a,r?.onSuccess)}catch(l){this._handleFailure(l.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(a.text,r?.onError);break;default:break}}}_handleFailure(e,r){var n;(n=this._idpWindow)===null||n===void 0||n.close(),r?.(e),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(e={}){if(await Hn(this._storage),this._identity=new Mt,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function Hn(t){await t.remove(_t),await t.remove(gt),await t.remove(Bo)}var Xr=()=>Jr.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var Po=async({data:t})=>{try{return await dr(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var Wn=async t=>{let{data:e,version:r,description:n}=t;return{description:J(n),data:await fi(e),version:J(r)}},$n=t=>{let{version:e}=t;return{version:J(e)}},Xe=async({doc:t,key:e})=>{let{owner:r,version:n,description:i,data:o,...s}=t;return{key:e,description:G(i),owner:r.toText(),data:await dr(o),version:G(n),...s}};var Co=t=>{if(V(t))return J();switch(t.matcher){case"equal":return J({Equal:t.timestamp});case"greaterThan":return J({GreaterThan:t.timestamp});case"lessThan":return J({LessThan:t.timestamp});case"between":return J({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Error("Invalid list matcher for timestamp",t)}},Te=({matcher:t,paginate:e,order:r,owner:n})=>({matcher:V(t)?[]:[{key:J(t.key),description:J(t.description),created_at:Co(t.createdAt),updated_at:Co(t.updatedAt)}],paginate:J(V(e)?void 0:{start_after:J(e.startAfter),limit:J(V(e.limit)?void 0:BigInt(e.limit))}),order:J(V(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:J(V(n)?void 0:typeof n=="string"?S.fromText(n):n)});var ko=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),r=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),n=t.Record({field:r,desc:t.Bool}),i=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),o=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(i),description:t.Opt(t.Text),created_at:t.Opt(i)}),s=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),a=t.Record({order:t.Opt(n),owner:t.Opt(t.Principal),matcher:t.Opt(o),paginate:t.Opt(s)}),l=t.Record({controllers:t.Vec(t.Principal)}),d=t.Variant({Write:t.Null,Admin:t.Null}),c=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:d,expires_at:t.Opt(t.Nat64)}),f=t.Record({version:t.Opt(t.Nat64)}),h=t.Variant({Db:t.Null,Storage:t.Null}),w=t.Record({version:t.Opt(t.Nat64)}),m=t.Record({cycles:t.Nat,destination_id:t.Principal}),g=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),v=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),R=t.Record({key:g,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,v)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),_=t.Record({derivation_origin:t.Opt(t.Text)}),E=t.Record({internet_identity:t.Opt(_)}),C=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),U=t.Record({max_memory_size:t.Opt(C)}),j=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),tt=t.Variant({Deny:t.Null,Allow:t.Null}),K=t.Record({status_code:t.Nat16,location:t.Text}),q=t.Record({iframe:t.Opt(j),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),max_memory_size:t.Opt(C),raw_access:t.Opt(tt),redirects:t.Opt(t.Vec(t.Tuple(t.Text,K)))}),et=t.Record({db:t.Opt(U),authentication:t.Opt(E),storage:q}),st=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),xt=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),dt=t.Variant({Heap:t.Null,Stable:t.Null}),Kt=t.Record({memory:dt,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),b=t.Variant({Callback:t.Record({token:Kt,callback:t.Func([],[],["query"])})}),p=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(b),status_code:t.Nat16}),x=t.Record({token:t.Opt(Kt),body:t.Vec(t.Nat8)}),T=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),O=t.Record({batch_id:t.Nat}),N=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,R)),items_length:t.Nat64}),P=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),k=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,st)),items_length:t.Nat64}),B=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),F=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(dt),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:B,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:B}),M=t.Record({stable:t.Nat64,heap:t.Nat64}),W=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:d,expires_at:t.Opt(t.Nat64)}),rt=t.Record({controller:W,controllers:t.Vec(t.Principal)}),D=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),Z=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(dt),max_size:t.Opt(t.Nat),read:B,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:B}),ct=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),ft=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text,a],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,a],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([l],[t.Vec(t.Tuple(t.Principal,c))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,f],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,f))],[],[]),del_rule:t.Func([h,t.Text,w],[],[]),deposit_cycles:t.Func([m],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(R)],["query"]),get_auth_config:t.Func([],[t.Opt(E)],["query"]),get_config:t.Func([],[et],[]),get_db_config:t.Func([],[t.Opt(U)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(st)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(R)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(st)))],["query"]),get_storage_config:t.Func([],[q],["query"]),http_request:t.Func([xt],[p],["query"]),http_request_streaming_callback:t.Func([Kt],[x],["query"]),init_asset_upload:t.Func([T],[O],[]),list_assets:t.Func([t.Text,a],[N],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,c))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,P))],["query"]),list_docs:t.Func([t.Text,a],[k],["query"]),list_rules:t.Func([h],[t.Vec(t.Tuple(t.Text,F))],["query"]),memory_size:t.Func([],[M],["query"]),set_auth_config:t.Func([E],[],[]),set_controllers:t.Func([rt],[t.Vec(t.Tuple(t.Principal,c))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([U],[],[]),set_doc:t.Func([t.Text,t.Text,D],[st],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,D))],[t.Vec(t.Tuple(t.Text,st))],[]),set_rule:t.Func([h,t.Text,Z],[],[]),set_storage_config:t.Func([q],[],[]),upload_asset_chunk:t.Func([ct],[ft],[]),version:t.Func([],[t.Text],["query"])})};var Fo=async({satelliteId:t,idlFactory:e,identity:r,fetch:n,container:i})=>{let s=H(i)&&i!==!1?i===!0?se:i:"https://icp-api.io",a=H(i),l=await Ve.create({identity:r,shouldFetchRootKey:a,host:s,...n&&{fetch:n}});return Lt.createActor(e,{agent:l,canisterId:t})};var Uo=({satelliteId:t,container:e})=>{let{satelliteId:r}=Gn({satelliteId:t}),{container:n}=zn({container:e});if(H(n)&&n!==!1){let{host:i,protocol:o}=new URL(n===!0?se:n);return`${o}//${r??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},Gn=({satelliteId:t})=>H(t)?{satelliteId:t}:Et.getInstance().get()??{satelliteId:void 0},zn=({container:t})=>H(t)?{container:t}:Et.getInstance().get()??{container:void 0};var X=async({satelliteId:t,container:e,...r})=>{let{satelliteId:n}=Gn({satelliteId:t});ur(n,"No satellite ID defined. Did you initialize Juno?");let{container:i}=zn({container:e});return Fo({satelliteId:n,container:i,idlFactory:ko,...r})};var Mo=async({collection:t,key:e,satellite:r})=>{let{get_doc:n}=await X(r),i=G(await n(t,e));if(!V(i))return Xe({doc:i,key:e})},Ko=async({docs:t,satellite:e})=>{let{get_many_docs:r}=await X(e),n=t.map(({collection:s,key:a})=>[s,a]),i=await r(n),o=[];for(let[s,a]of i){let l=G(a);o.push(H(l)?await Xe({key:s,doc:l}):void 0)}return o},Vo=async({collection:t,doc:e,satellite:r})=>{let{set_doc:n}=await X(r),{key:i}=e,o=await Wn(e),s=await n(t,i,o);return await Xe({key:i,doc:s})},jo=async({docs:t,satellite:e})=>{let{set_many_docs:r}=await X(e),n=[];for(let{collection:s,doc:a}of t){let{key:l}=a;n.push([s,l,await Wn(a)])}let i=await r(n),o=[];for(let[s,a]of i)o.push(await Xe({key:s,doc:a}));return o},qo=async({collection:t,doc:e,satellite:r})=>{let{del_doc:n}=await X(r),{key:i}=e;return n(t,i,$n(e))},Ho=async({docs:t,satellite:e})=>{let{del_many_docs:r}=await X(e),n=t.map(({collection:i,doc:o})=>[i,o.key,$n(o)]);await r(n)},Wo=async({collection:t,filter:e,satellite:r})=>{let{list_docs:n}=await X(r),{items:i,items_page:o,items_length:s,matches_length:a,matches_pages:l}=await n(t,Te(e)),d=[];for(let[c,f]of i){let{data:h,owner:w,description:m,version:g,...v}=f;d.push({key:c,description:G(m),owner:w.toText(),data:await Po({data:h}),version:G(g),...v})}return{items:d,items_length:s,items_page:G(o),matches_length:a,matches_pages:G(l)}},$o=async({collection:t,filter:e,satellite:r})=>{let{count_docs:n}=await X(r);return n(t,Te(e))};var Y=t=>t!==void 0?t:Zr()??new Mt;var Go=async({satellite:t,...e})=>{let r=Y(t?.identity);return Mo({...e,satellite:{...t,identity:r}})},Ef=async({satellite:t,...e})=>{let r=Y(t?.identity);return Ko({...e,satellite:{...t,identity:r}})},zo=async({satellite:t,...e})=>{let r=Y(t?.identity);return Vo({...e,satellite:{...t,identity:r}})},Tf=async({satellite:t,...e})=>{let r=Y(t?.identity);return jo({...e,satellite:{...t,identity:r}})},Af=async({satellite:t,...e})=>{let r=Y(t?.identity);return qo({...e,satellite:{...t,identity:r}})},vf=async({satellite:t,...e})=>{let r=Y(t?.identity);return Ho({...e,satellite:{...t,identity:r}})},Sf=async({satellite:t,filter:e,...r})=>{let n=Y(t?.identity);return Wo({...r,filter:e??{},satellite:{...t,identity:n}})},Rf=async({satellite:t,filter:e,...r})=>{let n=Y(t?.identity);return $o({...r,filter:e??{},satellite:{...t,identity:n}})};var Yo=async t=>{let e=Zr();if(V(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let r=e.getPrincipal().toText(),n=await Go({collection:"#user",key:r});return V(n)?await Ac({userId:r,provider:t}):n},Ac=async({userId:t,...e})=>zo({collection:"#user",doc:{key:t,data:e}});var Pt,Yn=async t=>{if(Pt=Pt??await Xr(),!(await Pt?.isAuthenticated()??!1))return;let r=await Yo(t);kt.getInstance().set(r)},vc=async t=>new Promise(async(e,r)=>{Pt=Pt??await Xr();let n=t?.provider??new fr({});await Pt.login({onSuccess:async()=>{await Yn(n.id),e()},onError:i=>r(i),maxTimeToLive:t?.maxTimeToLive??hi,allowPinAuthentication:t?.allowPin??mi,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...n.signInOptions({windowed:t?.windowed})})}),Jn=async()=>{await Pt?.logout(),Pt=void 0,kt.getInstance().reset()},Zr=()=>Pt?.getIdentity(),Sc=async()=>(Pt??await Xr()).getIdentity();var Jo=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),n=async()=>{un({message:"junoSignOutAuthTimer"}),await Jn()};return r.onmessage=async({data:i})=>{let{msg:o,data:s}=i;switch(o){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":un({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},kt.getInstance().subscribe(i=>{if(V(i)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var Xo=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_SATELLITE_ID??t():t()},Zo=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_CONTAINER??t():t()};var Rc=t=>t==null,Oc=t=>!Rc(t),Qr=t=>Oc(t)?[t]:[],Nc=()=>typeof window<"u",Qo=async({asset:{data:t,filename:e,collection:r,headers:n,token:i,fullPath:o,encoding:s,description:a},actor:l,init_asset_upload:d})=>{let{batch_id:c}=await d({collection:r,full_path:o,name:e,token:Qr(i),encoding_type:Qr(s),description:Qr(a)}),f=19e5,h=[],w=Nc()?new Blob([await t.arrayBuffer()]):t,m=0n;for(let R=0;R<w.size;R+=f){let _=w.slice(R,R+f);h.push({batchId:c,chunk:_,actor:l,orderId:m}),m++}let g=[];for await(let R of Bc({uploadChunks:h}))g=[...g,...R];let v=n.find(([R,_])=>R.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await l.commit_asset_upload({batch_id:c,chunk_ids:g.map(({chunk_id:R})=>R),headers:[...n,...v||[]]})};async function*Bc({uploadChunks:t,limit:e=12}){for(let r=0;r<t.length;r=r+e){let n=t.slice(r,r+e);yield await Promise.all(n.map(i=>Pc(i)))}}var Pc=async({batchId:t,chunk:e,actor:r,orderId:n})=>r.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:Qr(n)});var Io=async({satellite:t,...e})=>{let r=await X(t);await Qo({actor:r,asset:e,init_asset_upload:async i=>await r.init_asset_upload(i)})},Do=async({collection:t,satellite:e,filter:r})=>{let{list_assets:n}=await X(e),{items:i,items_length:o,items_page:s,matches_length:a,matches_pages:l}=await n(t,Te(r));return{items:i.map(([d,c])=>c),items_length:o,items_page:G(s),matches_length:a,matches_pages:G(l)}},Lo=async({collection:t,satellite:e,filter:r})=>{let{count_assets:n}=await X(e);return n(t,Te(r))},ts=async({collection:t,fullPath:e,satellite:r})=>(await X(r)).del_asset(t,e),es=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await X(e),n=t.map(({collection:i,fullPath:o})=>[i,o]);await r(n)},rs=async({collection:t,fullPath:e,satellite:r})=>{let{get_asset:n}=await X(r);return G(await n(t,e))},ns=async({assets:t,satellite:e})=>{let{get_many_assets:r}=await X(e),n=t.map(({collection:o,fullPath:s})=>[o,s]);return(await r(n)).map(([o,s])=>G(s))};var is=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var op=async t=>os(t),sp=async t=>os({filename:t.data.name,...t}),os=async({filename:t,data:e,collection:r,headers:n=[],fullPath:i,token:o,satellite:s,encoding:a,description:l})=>{let d=Y(s?.identity),c=decodeURI(t),f=i??`/${r}/${c}`,h={...s,identity:d};return await Io({data:e,filename:c,collection:r,token:o,headers:n,fullPath:f,encoding:a,satellite:h,description:l}),{downloadUrl:ss({satellite:h,assetKey:{fullPath:f,token:o}}),fullPath:f,name:c}},ap=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:Y(e?.identity)},{items:i,...o}=await Do({collection:t,satellite:n,filter:r??{}}),s=i.map(({key:{full_path:a,token:l,name:d,owner:c,description:f},headers:h,encodings:w,created_at:m,updated_at:g})=>{let v=G(l);return{fullPath:a,description:G(f),name:d,downloadUrl:ss({satellite:n,assetKey:{fullPath:a,token:v}}),token:v,headers:h,encodings:w.reduce((R,[_,{modified:E,sha256:C,total_length:U}])=>({...R,[_]:{modified:E,sha256:is(C),total_length:U}}),{}),owner:c.toText(),created_at:m,updated_at:g}});return{items:s,assets:s,...o}},cp=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:Y(e?.identity)};return Lo({collection:t,satellite:n,filter:r??{}})},lp=async({collection:t,fullPath:e,satellite:r})=>ts({collection:t,fullPath:e,satellite:{...r,identity:Y(r?.identity)}}),up=async({assets:t,satellite:e})=>es({assets:t,satellite:{...e,identity:Y(e?.identity)}}),dp=async({satellite:t,...e})=>{let r=Y(t?.identity);return rs({...e,satellite:{...t,identity:r}})},fp=async({satellite:t,...e})=>{let r=Y(t?.identity);return ns({...e,satellite:{...t,identity:r}})},ss=({assetKey:{fullPath:t,token:e},satellite:r})=>{let n={...r,identity:Y(r?.identity)};return`${Uo(n)}${t}${H(e)?`?token=${e}`:""}`};var Cc=t=>{let e=t?.satelliteId??Xo();ur(e,"Satellite ID is not configured. Juno cannot be initialized.");let r=t?.container??Zo();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:r}},xp=async t=>kc(t),kc=async t=>{let e=Cc(t);Et.getInstance().set(e),await Yn();let r=e.workers?.auth!==void 0?Jo(e.workers.auth):void 0;return[...r?[r]:[]]},bp=t=>kt.getInstance().subscribe(t);export{fr as InternetIdentityProvider,xi as NFIDProvider,bp as authSubscribe,cp as countAssets,Rf as countDocs,lp as deleteAsset,Af as deleteDoc,up as deleteManyAssets,vf as deleteManyDocs,ss as downloadUrl,dp as getAsset,Go as getDoc,fp as getManyAssets,Ef as getManyDocs,xp as initJuno,kc as initSatellite,ap as listAssets,Sf as listDocs,zo as setDoc,Tf as setManyDocs,vc as signIn,Jn as signOut,Sc as unsafeIdentity,op as uploadBlob,sp as uploadFile};
|
|
21
|
+
`)}}function xo(t,e){let r=t;return()=>new Promise(n=>setTimeout(()=>{r*=e,n()},r))}function bo(...t){return async(e,r,n)=>{for(let i of t)await i(e,r,n)}}async function $n(t,e,r,n=Jr(),i,o){var s;let a=[new TextEncoder().encode("request_status"),r],l=i??await((s=t.createReadStateRequest)===null||s===void 0?void 0:s.call(t,{paths:[a]})),d=await t.readState(e,{paths:[a]},void 0,l);if(t.rootKey==null)throw new Error("Agent root key not initialized before polling");let c=t?.replicaTime?t?.replicaTime:void 0,f=await _r.create({certificate:d.certificate,rootKey:t.rootKey,canisterId:e,certTime:c,blsVerify:o}),h=Ht(f.lookup([...a,new TextEncoder().encode("status")])),m;switch(typeof h>"u"?m=Ot.Unknown:m=new TextDecoder().decode(h),m){case Ot.Replied:return{reply:Ht(f.lookup([...a,"reply"])),certificate:f};case Ot.Received:case Ot.Unknown:case Ot.Processing:return await n(e,r,m),$n(t,e,r,n,l,o);case Ot.Rejected:{let y=new Uint8Array(Ht(f.lookup([...a,"reject_code"])))[0],_=new TextDecoder().decode(Ht(f.lookup([...a,"reject_message"])));throw new Error(`Call was rejected:
|
|
22
|
+
Request ID: ${Y(r)}
|
|
23
|
+
Reject code: ${y}
|
|
24
|
+
Reject text: ${_}
|
|
25
|
+
`)}case Ot.Done:throw new Error(`Call was marked as done but we never saw the reply:
|
|
26
|
+
Request ID: ${Y(r)}
|
|
27
|
+
`)}throw new Error("unreachable")}var Eo=({IDL:t})=>{let e=t.Variant({mainnet:t.Null,testnet:t.Null}),r=t.Text,n=t.Record({network:e,address:r,min_confirmations:t.Opt(t.Nat32)}),i=t.Nat64,o=i,s=t.Record({network:e}),a=t.Nat64,l=t.Vec(a),d=t.Record({network:e,filter:t.Opt(t.Variant({page:t.Vec(t.Nat8),min_confirmations:t.Nat32})),address:r}),c=t.Vec(t.Nat8),f=t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32}),h=t.Record({height:t.Nat32,value:i,outpoint:f}),m=t.Record({next_page:t.Opt(t.Vec(t.Nat8)),tip_height:t.Nat32,tip_block_hash:c,utxos:t.Vec(h)}),y=t.Record({transaction:t.Vec(t.Nat8),network:e}),_=t.Principal,N=t.Record({canister_id:_,num_requested_changes:t.Opt(t.Nat64)}),S=t.Variant({from_user:t.Record({user_id:t.Principal}),from_canister:t.Record({canister_version:t.Opt(t.Nat64),canister_id:t.Principal})}),R=t.Variant({creation:t.Record({controllers:t.Vec(t.Principal)}),code_deployment:t.Record({mode:t.Variant({reinstall:t.Null,upgrade:t.Null,install:t.Null}),module_hash:t.Vec(t.Nat8)}),controllers_change:t.Record({controllers:t.Vec(t.Principal)}),code_uninstall:t.Null}),w=t.Record({timestamp_nanos:t.Nat64,canister_version:t.Nat64,origin:S,details:R}),v=t.Record({controllers:t.Vec(t.Principal),module_hash:t.Opt(t.Vec(t.Nat8)),recent_changes:t.Vec(w),total_num_changes:t.Nat64}),O=t.Record({canister_id:_}),j=t.Variant({controllers:t.Null,public:t.Null}),Z=t.Record({freezing_threshold:t.Nat,controllers:t.Vec(t.Principal),reserved_cycles_limit:t.Nat,log_visibility:j,wasm_memory_limit:t.Nat,memory_allocation:t.Nat,compute_allocation:t.Nat}),V=t.Record({status:t.Variant({stopped:t.Null,stopping:t.Null,running:t.Null}),memory_size:t.Nat,cycles:t.Nat,settings:Z,query_stats:t.Record({response_payload_bytes_total:t.Nat,num_instructions_total:t.Nat,num_calls_total:t.Nat,request_payload_bytes_total:t.Nat}),idle_cycles_burned_per_day:t.Nat,module_hash:t.Opt(t.Vec(t.Nat8)),reserved_cycles:t.Nat}),K=t.Record({canister_id:_}),D=t.Record({freezing_threshold:t.Opt(t.Nat),controllers:t.Opt(t.Vec(t.Principal)),reserved_cycles_limit:t.Opt(t.Nat),log_visibility:t.Opt(j),wasm_memory_limit:t.Opt(t.Nat),memory_allocation:t.Opt(t.Nat),compute_allocation:t.Opt(t.Nat)}),q=t.Record({settings:t.Opt(D),sender_canister_version:t.Opt(t.Nat64)}),dt=t.Record({canister_id:_}),ft=t.Record({canister_id:_}),Pt=t.Record({canister_id:_}),jt=t.Variant({secp256k1:t.Null}),b=t.Record({key_id:t.Record({name:t.Text,curve:jt}),canister_id:t.Opt(_),derivation_path:t.Vec(t.Vec(t.Nat8))}),p=t.Record({public_key:t.Vec(t.Nat8),chain_code:t.Vec(t.Nat8)}),x=t.Record({canister_id:_}),E=t.Record({idx:t.Nat64,timestamp_nanos:t.Nat64,content:t.Vec(t.Nat8)}),B=t.Record({canister_log_records:t.Vec(E)}),P=t.Record({value:t.Text,name:t.Text}),C=t.Record({status:t.Nat,body:t.Vec(t.Nat8),headers:t.Vec(P)}),F=t.Record({url:t.Text,method:t.Variant({get:t.Null,head:t.Null,post:t.Null}),max_response_bytes:t.Opt(t.Nat64),body:t.Opt(t.Vec(t.Nat8)),transform:t.Opt(t.Record({function:t.Func([t.Record({context:t.Vec(t.Nat8),response:C})],[C],["query"]),context:t.Vec(t.Nat8)})),headers:t.Vec(P)}),k=t.Variant({reinstall:t.Null,upgrade:t.Opt(t.Record({wasm_memory_persistence:t.Opt(t.Variant({keep:t.Null,replace:t.Null})),skip_pre_upgrade:t.Opt(t.Bool)})),install:t.Null}),M=t.Record({hash:t.Vec(t.Nat8)}),H=t.Record({arg:t.Vec(t.Nat8),wasm_module_hash:t.Vec(t.Nat8),mode:k,chunk_hashes_list:t.Vec(M),target_canister:_,store_canister:t.Opt(_),sender_canister_version:t.Opt(t.Nat64)}),G=t.Vec(t.Nat8),rt=t.Record({arg:t.Vec(t.Nat8),wasm_module:G,mode:k,canister_id:_,sender_canister_version:t.Opt(t.Nat64)}),ot=t.Record({start_at_timestamp_nanos:t.Nat64,subnet_id:t.Principal}),L=t.Record({num_block_failures_total:t.Nat64,node_id:t.Principal,num_blocks_proposed_total:t.Nat64}),ct=t.Vec(t.Record({timestamp_nanos:t.Nat64,node_metrics:t.Vec(L)})),Ct=t.Record({settings:t.Opt(D),specified_id:t.Opt(_),amount:t.Opt(t.Nat),sender_canister_version:t.Opt(t.Nat64)}),ie=t.Record({canister_id:_}),er=t.Record({canister_id:_,amount:t.Nat}),rr=t.Vec(t.Nat8),nr=t.Variant({ed25519:t.Null,bip340secp256k1:t.Null}),ln=t.Record({key_id:t.Record({algorithm:nr,name:t.Text}),canister_id:t.Opt(_),derivation_path:t.Vec(t.Vec(t.Nat8))}),un=t.Record({public_key:t.Vec(t.Nat8),chain_code:t.Vec(t.Nat8)}),dn=t.Record({key_id:t.Record({name:t.Text,curve:jt}),derivation_path:t.Vec(t.Vec(t.Nat8)),message_hash:t.Vec(t.Nat8)}),ir=t.Record({signature:t.Vec(t.Nat8)}),or=t.Record({key_id:t.Record({algorithm:nr,name:t.Text}),derivation_path:t.Vec(t.Vec(t.Nat8)),message:t.Vec(t.Nat8)}),Pe=t.Record({signature:t.Vec(t.Nat8)}),sr=t.Record({canister_id:_}),ar=t.Record({canister_id:_}),cr=t.Record({canister_id:_}),lr=t.Vec(M),ur=t.Record({canister_id:_,sender_canister_version:t.Opt(t.Nat64)}),fn=t.Record({canister_id:t.Principal,settings:D,sender_canister_version:t.Opt(t.Nat64)}),pn=t.Record({chunk:t.Vec(t.Nat8),canister_id:t.Principal}),hn=M;return t.Service({bitcoin_get_balance:t.Func([n],[o],[]),bitcoin_get_current_fee_percentiles:t.Func([s],[l],[]),bitcoin_get_utxos:t.Func([d],[m],[]),bitcoin_send_transaction:t.Func([y],[],[]),canister_info:t.Func([N],[v],[]),canister_status:t.Func([O],[V],[]),clear_chunk_store:t.Func([K],[],[]),create_canister:t.Func([q],[dt],[]),delete_canister:t.Func([ft],[],[]),deposit_cycles:t.Func([Pt],[],[]),ecdsa_public_key:t.Func([b],[p],[]),fetch_canister_logs:t.Func([x],[B],["query"]),http_request:t.Func([F],[C],[]),install_chunked_code:t.Func([H],[],[]),install_code:t.Func([rt],[],[]),node_metrics_history:t.Func([ot],[ct],[]),provisional_create_canister_with_cycles:t.Func([Ct],[ie],[]),provisional_top_up_canister:t.Func([er],[],[]),raw_rand:t.Func([],[rr],[]),schnorr_public_key:t.Func([ln],[un],[]),sign_with_ecdsa:t.Func([dn],[ir],[]),sign_with_schnorr:t.Func([or],[Pe],[]),start_canister:t.Func([sr],[],[]),stop_canister:t.Func([ar],[],[]),stored_chunks:t.Func([cr],[lr],[]),uninstall_code:t.Func([ur],[],[]),update_settings:t.Func([fn],[],[]),upload_chunk:t.Func([pn],[hn],[])})};var Zr=class extends z{constructor(e,r,n,i){super(["Call failed:",` Canister: ${e.toText()}`,` Method: ${r} (${n})`,...Object.getOwnPropertyNames(i).map(o=>` "${o}": ${JSON.stringify(i[o])}`)].join(`
|
|
28
|
+
`)),this.canisterId=e,this.methodName=r,this.type=n,this.props=i}},Wn=class extends Zr{constructor(e,r,n){var i;super(e,r,"query",{Status:n.status,Code:(i=Sr[n.reject_code])!==null&&i!==void 0?i:`Unknown Code "${n.reject_code}"`,Message:n.reject_message}),this.result=n}},Gn=class extends Zr{constructor(e,r,n,i){super(e,r,"update",Object.assign({"Request ID":Y(n)},i.body?Object.assign(Object.assign({},i.body.error_code?{"Error code":i.body.error_code}:{}),{"Reject code":String(i.body.reject_code),"Reject message":i.body.reject_message}):{"HTTP status code":i.status.toString(),"HTTP status text":i.statusText})),this.requestId=n,this.response=i}},ut=Symbol.for("ic-agent-metadata"),ee=class t{constructor(e){this[ut]=Object.freeze(e)}static agentOf(e){return e[ut].config.agent}static interfaceOf(e){return e[ut].service}static canisterIdOf(e){return T.from(e[ut].config.canisterId)}static async install(e,r){let n=e.mode===void 0?{install:null}:e.mode,i=e.arg?[...new Uint8Array(e.arg)]:[],o=[...new Uint8Array(e.module)],s=typeof r.canisterId=="string"?T.fromText(r.canisterId):r.canisterId;await To(r).install_code({mode:n,arg:i,wasm_module:o,canister_id:s,sender_canister_version:[]})}static async createCanister(e,r){function n(o){return[{controllers:o.controllers?[o.controllers]:[],compute_allocation:o.compute_allocation?[o.compute_allocation]:[],freezing_threshold:o.freezing_threshold?[o.freezing_threshold]:[],memory_allocation:o.memory_allocation?[o.memory_allocation]:[],reserved_cycles_limit:[],log_visibility:[],wasm_memory_limit:[]}]}let{canister_id:i}=await To(e||{}).provisional_create_canister_with_cycles({amount:[],settings:n(r||{}),specified_id:[],sender_canister_version:[]});return i}static async createAndInstallCanister(e,r,n){let i=await this.createCanister(n);return await this.install(Object.assign({},r),Object.assign(Object.assign({},n),{canisterId:i})),this.createActor(e,Object.assign(Object.assign({},n),{canisterId:i}))}static createActorClass(e,r){let n=e({IDL:Ce});class i extends t{constructor(s){if(!s.canisterId)throw new z(`Canister ID is required, but received ${typeof s.canisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`);let a=typeof s.canisterId=="string"?T.fromText(s.canisterId):s.canisterId;super({config:Object.assign(Object.assign(Object.assign({},vo),s),{canisterId:a}),service:n});for(let[l,d]of n._fields)r?.httpDetails&&d.annotations.push(zn),r?.certificate&&d.annotations.push(So),this[l]=oc(this,l,d,s.blsVerify)}}return i}static createActor(e,r){if(!r.canisterId)throw new z(`Canister ID is required, but received ${typeof r.canisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`);return new(this.createActorClass(e))(r)}static createActorWithHttpDetails(e,r){return new(this.createActorClass(e,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(e,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(e,n))(r)}};function Te(t,e){let r=Ce.decode(t,Ao.Buffer.from(e));switch(r.length){case 0:return;case 1:return r[0];default:return r}}var vo={pollingStrategyFactory:Xr.defaultStrategy},zn="http-details",So="certificate";function oc(t,e,r,n){let i;r.annotations.includes("query")||r.annotations.includes("composite_query")?i=async(s,...a)=>{var l,d;s=Object.assign(Object.assign({},s),(d=(l=t[ut].config).queryTransform)===null||d===void 0?void 0:d.call(l,e,a,Object.assign(Object.assign({},t[ut].config),s)));let c=s.agent||t[ut].config.agent||Hn(),f=T.from(s.canisterId||t[ut].config.canisterId),h=Ce.encode(r.argTypes,a),m=await c.query(f,{methodName:e,arg:h,effectiveCanisterId:s.effectiveCanisterId}),y=Object.assign(Object.assign({},m.httpDetails),{requestDetails:m.requestDetails});switch(m.status){case"rejected":throw new Wn(f,e,m);case"replied":return r.annotations.includes(zn)?{httpDetails:y,result:Te(r.retTypes,m.reply.arg)}:Te(r.retTypes,m.reply.arg)}}:i=async(s,...a)=>{var l,d;s=Object.assign(Object.assign({},s),(d=(l=t[ut].config).callTransform)===null||d===void 0?void 0:d.call(l,e,a,Object.assign(Object.assign({},t[ut].config),s)));let c=s.agent||t[ut].config.agent||Hn(),{canisterId:f,effectiveCanisterId:h,pollingStrategyFactory:m}=Object.assign(Object.assign(Object.assign({},vo),t[ut].config),s),y=T.from(f),_=h!==void 0?T.from(h):y,N=Ce.encode(r.argTypes,a);if(c.rootKey==null)throw new z("Agent root key not initialized before making call");let{requestId:S,response:R,requestDetails:w}=await c.call(y,{methodName:e,arg:N,effectiveCanisterId:_}),v,O,j=c.replicaTime?c.replicaTime:void 0;if(R.body&&R.body.certificate){let D=R.body.certificate;O=await _r.create({certificate:mn(D),rootKey:c.rootKey,canisterId:T.from(f),certTime:j});let q=[new TextEncoder().encode("request_status"),S];switch(new TextDecoder().decode(Ht(O.lookup([...q,"status"])))){case"replied":v=Ht(O.lookup([...q,"reply"]));break;case"rejected":throw new Gn(y,e,S,R)}}if(R.status===202){let D=m(),q=await $n(c,_,S,D,n);O=q.certificate,v=q.reply}let Z=r.annotations.includes(zn),V=r.annotations.includes(So),K=Object.assign(Object.assign({},R),{requestDetails:w});if(v!==void 0)return Z&&V?{httpDetails:K,certificate:O,result:Te(r.retTypes,v)}:V?{certificate:O,result:Te(r.retTypes,v)}:Z?{httpDetails:K,result:Te(r.retTypes,v)}:Te(r.retTypes,v);if(r.retTypes.length===0)return Z?{httpDetails:R,result:void 0}:void 0;throw new Error(`Call was returned undefined, but type [${r.retTypes.join(",")}].`)};let o=(...s)=>i({},...s);return o.withOptions=s=>(...a)=>i(s,...a),o}function To(t){function e(r,n){if(t.effectiveCanisterId)return{effectiveCanisterId:T.from(t.effectiveCanisterId)};let i=n[0],o=T.fromHex("");return i&&typeof i=="object"&&i.canister_id&&(o=T.from(i.canister_id)),{effectiveCanisterId:o}}return ee.createActor(Eo,Object.assign(Object.assign(Object.assign({},t),{canisterId:T.fromHex("")}),{callTransform:e,queryTransform:e}))}var Ae=class t{static instance;#t=void 0;constructor(){}static getInstance(){return U(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...r}){let n=e.getPrincipal().toText();if(U(this.#t)||U(this.#t[n])){let i=await this.createAgent({identity:e,...r});return this.#t={...this.#t??{},[n]:i},i}return this.#t[n]}reset(){this.#t=null}async createAgent({identity:e,fetch:r,container:n}){let o=$(n)&&n!==!1?n===!0?ce:n:"https://icp-api.io",s=$(n);return await Ge.create({identity:e,shouldFetchRootKey:s,host:o,...r&&{fetch:r}})}};var ve=class t{static instance;#t=void 0;constructor(){}static getInstance(){return U(t.instance)&&(t.instance=new t),t.instance}async getActor({satelliteId:e,identity:r,buildType:n,...i}){let o=`${n}#${r.getPrincipal().toText()}#${e};`;if(U(this.#t)||U(this.#t[o])){let s=await this.createActor({satelliteId:e,identity:r,...i});return this.#t={...this.#t??{},[o]:s},s}return this.#t[o]}reset(){this.#t=null}async createActor({idlFactory:e,satelliteId:r,...n}){let i=await Ae.getInstance().getAgent(n);return ee.createActor(e,{agent:i,canisterId:r})}};var Dr=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},Jt=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Qr,Ir,Se,Re;function Ro(t){return t!==null&&typeof t=="object"}var re=class t{constructor(e){if(Qr.set(this,void 0),Ir.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");Dr(this,Qr,e,"f"),Dr(this,Ir,t.derEncode(e),"f")}static from(e){if(typeof e=="string"){let r=xt(e);return this.fromRaw(r)}else if(Ro(e)){let r=e;if(Ro(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(hr(n.buffer))}else{if(r instanceof ArrayBuffer)return this.fromRaw(r);if("rawKey"in r)return this.fromRaw(r.rawKey);if("derKey"in r)return this.fromDer(r.derKey);if("toDer"in r)return this.fromDer(r.toDer())}}throw new Error("Cannot construct Ed25519PublicKey from the provided key.")}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static derEncode(e){let r=ye(e,It).buffer;return r.__derEncodedPublicKey__=void 0,r}static derDecode(e){let r=Ve(e,It);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}get rawKey(){return Jt(this,Qr,"f")}get derKey(){return Jt(this,Ir,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};Qr=new WeakMap,Ir=new WeakMap;re.RAW_KEY_LENGTH=32;var ne=class t extends Mt{constructor(e,r){super(),Se.set(this,void 0),Re.set(this,void 0),Dr(this,Se,re.from(e),"f"),Dr(this,Re,new Uint8Array(r),"f")}static generate(e){if(e&&e.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");e||(e=zt.utils.randomPrivateKey()),pr(e,new Uint8Array(new Array(32).fill(0)))&&console.warn("Seed is all zeros. This is not a secure seed. Please provide a seed with sufficient entropy if this is a production environment.");let r=new Uint8Array(32);for(let i=0;i<32;i++)r[i]=new Uint8Array(e)[i];let n=zt.getPublicKey(r);return t.fromKeyPair(n,r)}static fromParsedJson(e){let[r,n]=e;return new t(re.fromDer(xt(r)),xt(n))}static fromJSON(e){let r=JSON.parse(e);if(Array.isArray(r)){if(typeof r[0]=="string"&&typeof r[1]=="string")return this.fromParsedJson([r[0],r[1]]);throw new Error("Deserialization error: JSON must have at least 2 items.")}throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(e)}`)}static fromKeyPair(e,r){return new t(re.fromRaw(e),r)}static fromSecretKey(e){let r=zt.getPublicKey(new Uint8Array(e));return t.fromKeyPair(r,e)}toJSON(){return[Y(Jt(this,Se,"f").toDer()),Y(Jt(this,Re,"f"))]}getKeyPair(){return{secretKey:Jt(this,Re,"f"),publicKey:Jt(this,Se,"f")}}getPublicKey(){return Jt(this,Se,"f")}async sign(e){let r=new Uint8Array(e),n=pi(zt.sign(r,Jt(this,Re,"f").slice(0,32)));return Object.defineProperty(n,"__signature__",{enumerable:!1,value:void 0}),n}static verify(e,r,n){let[i,o,s]=[e,r,n].map(a=>(typeof a=="string"&&(a=xt(a)),a instanceof Uint8Array&&(a=a.buffer),new Uint8Array(a)));return zt.verify(o,i,s)}};Se=new WeakMap,Re=new WeakMap;var Yn=class t extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,t.prototype)}};function Oo(t){if(typeof globalThis<"u"&&globalThis.crypto&&globalThis.crypto.subtle)return globalThis.crypto.subtle;if(t)return t;if(typeof crypto<"u"&&crypto.subtle)return crypto.subtle;throw new Yn("Global crypto was not available and none was provided. Please inlcude a SubtleCrypto implementation. See https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto")}var ze=class t extends Mt{constructor(e,r,n){super(),this._keyPair=e,this._derKey=r,this._subtleCrypto=n}static async generate(e){let{extractable:r=!1,keyUsages:n=["sign","verify"],subtleCrypto:i}=e??{},o=Oo(i),s=await o.generateKey({name:"ECDSA",namedCurve:"P-256"},r,n),a=await o.exportKey("spki",s.publicKey);return new this(s,a,o)}static async fromKeyPair(e,r){let n=Oo(r),i=await n.exportKey("spki",e.publicKey);return new t(e,i,n)}getKeyPair(){return this._keyPair}getPublicKey(){let e=this._derKey,r=Object.create(this._keyPair.publicKey);return r.toDer=function(){return e},r}async sign(e){let r={name:"ECDSA",hash:{name:"SHA-256"}};return await this._subtleCrypto.sign(r,this._keyPair.privateKey,e)}};var Oe=dr(hi());var ac=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},Ye=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Xt,Lr=class{constructor(e){Xt.set(this,void 0),ac(this,Xt,e,"f")}get rawKey(){return Ye(this,Xt,"f").rawKey}get derKey(){return Ye(this,Xt,"f").derKey}toDer(){return Ye(this,Xt,"f").toDer()}getPublicKey(){return Ye(this,Xt,"f")}getPrincipal(){return T.from(Ye(this,Xt,"f").rawKey)}transformRequest(){return Promise.reject("Not implemented. You are attempting to use a partial identity to sign calls, but this identity only has access to the public key.To sign calls, use a DelegationIdentity instead.")}};Xt=new WeakMap;var cc=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},lc=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},uc=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},tn,dc=new TextEncoder().encode("ic-request-auth-delegation"),fc=new TextEncoder().encode(`
|
|
29
|
+
ic-request`);function Jn(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return xt(t)}var Ne=class{constructor(e,r,n){this.pubkey=e,this.expiration=r,this.targets=n}toCBOR(){return Oe.value.map(Object.assign({pubkey:Oe.value.bytes(this.pubkey),expiration:Oe.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:Oe.value.array(this.targets.map(e=>Oe.value.bytes(e.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:Y(this.pubkey)},this.targets&&{targets:this.targets.map(e=>e.toHex())})}};async function pc(t,e,r,n){let i=new Ne(e.toDer(),BigInt(+r)*BigInt(1e6),n),o=new Uint8Array([...dc,...new Uint8Array(qt(i))]),s=await t.sign(o);return{delegation:i,signature:s}}var Je=class t{constructor(e,r){this.delegations=e,this.publicKey=r}static async create(e,r,n=new Date(Date.now()+15*60*1e3),i={}){var o,s;let a=await pc(e,r,n,i.targets);return new t([...((o=i.previous)===null||o===void 0?void 0:o.delegations)||[],a],((s=i.previous)===null||s===void 0?void 0:s.publicKey)||e.getPublicKey().toDer())}static fromJSON(e){let{publicKey:r,delegations:n}=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(n))throw new Error("Invalid delegations.");let i=n.map(o=>{let{delegation:s,signature:a}=o,{pubkey:l,expiration:d,targets:c}=s;if(c!==void 0&&!Array.isArray(c))throw new Error("Invalid targets.");return{delegation:new Ne(Jn(l),BigInt("0x"+d),c&&c.map(f=>{if(typeof f!="string")throw new Error("Invalid target.");return T.fromHex(f)})),signature:Jn(a)}});return new this(i,Jn(r))}static fromDelegations(e,r){return new this(e,r)}toJSON(){return{delegations:this.delegations.map(e=>{let{delegation:r,signature:n}=e,{targets:i}=r;return{delegation:Object.assign({expiration:r.expiration.toString(16),pubkey:Y(r.pubkey)},i&&{targets:i.map(o=>o.toHex())}),signature:Y(n)}}),publicKey:Y(this.publicKey)}}},Xe=class extends Mt{constructor(e,r){super(),this._inner=e,this._delegation=r}static fromDelegation(e,r){return new this(e,r)}getDelegation(){return this._delegation}getPublicKey(){return{derKey:this._delegation.publicKey,toDer:()=>this._delegation.publicKey}}sign(e){return this._inner.sign(e)}async transformRequest(e){let{body:r}=e,n=uc(e,["body"]),i=await qt(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_sig:await this.sign(new Uint8Array([...fc,...new Uint8Array(i)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}},Ze=class t extends Lr{constructor(e,r){super(e),tn.set(this,void 0),cc(this,tn,r,"f")}get delegation(){return lc(this,tn,"f")}static fromDelegation(e,r){return new t(e,r)}};tn=new WeakMap;function No(t,e){for(let{delegation:i}of t.delegations)if(+new Date(Number(i.expiration/BigInt(1e6)))<=+Date.now())return!1;let r=[],n=e?.scope;n&&(Array.isArray(n)?r.push(...n.map(i=>typeof i=="string"?T.fromText(i):i)):r.push(typeof n=="string"?T.fromText(n):n));for(let i of r){let o=i.toText();for(let{delegation:s}of t.delegations){if(s.targets===void 0)continue;let a=!0;for(let l of s.targets)if(l.toText()===o){a=!1;break}if(a)return!1}}return!0}var hc=dr(Ts());var Bo;(function(t){t[t.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(Bo||(Bo={}));var Po=["mousedown","mousemove","keydown","touchstart","wheel"],Qe=class{constructor(e={}){var r;this.callbacks=[],this.idleTimeout=10*60*1e3,this.timeoutID=void 0;let{onIdle:n,idleTimeout:i=10*60*1e3}=e||{};this.callbacks=n?[n]:[],this.idleTimeout=i;let o=this._resetTimer.bind(this);window.addEventListener("load",o,!0),Po.forEach(function(a){document.addEventListener(a,o,!0)});let s=(a,l)=>{let d;return(...c)=>{let f=this,h=function(){d=void 0,a.apply(f,c)};clearTimeout(d),d=window.setTimeout(h,l)}};if(e?.captureScroll){let a=s(o,(r=e?.scrollDebounce)!==null&&r!==void 0?r:100);window.addEventListener("scroll",a,!0)}o()}static create(e={}){return new this(e)}registerCallback(e){this.callbacks.push(e)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let e=this._resetTimer.bind(this);Po.forEach(function(r){document.removeEventListener(r,e,!0)}),this.callbacks.forEach(r=>r())}_resetTimer(){let e=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(e,this.idleTimeout)}};var mc=(t,e)=>e.some(r=>t instanceof r),Co,ko;function yc(){return Co||(Co=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function gc(){return ko||(ko=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var Fo=new WeakMap,Zn=new WeakMap,Uo=new WeakMap,Xn=new WeakMap,In=new WeakMap;function wc(t){let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("success",o),t.removeEventListener("error",s)},o=()=>{r(Nt(t.result)),i()},s=()=>{n(t.error),i()};t.addEventListener("success",o),t.addEventListener("error",s)});return e.then(r=>{r instanceof IDBCursor&&Fo.set(r,t)}).catch(()=>{}),In.set(e,t),e}function _c(t){if(Zn.has(t))return;let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("complete",o),t.removeEventListener("error",s),t.removeEventListener("abort",s)},o=()=>{r(),i()},s=()=>{n(t.error||new DOMException("AbortError","AbortError")),i()};t.addEventListener("complete",o),t.addEventListener("error",s),t.addEventListener("abort",s)});Zn.set(t,e)}var Qn={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return Zn.get(t);if(e==="objectStoreNames")return t.objectStoreNames||Uo.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return Nt(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function Mo(t){Qn=t(Qn)}function xc(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(en(this),e,...r);return Uo.set(n,e.sort?e.sort():[e]),Nt(n)}:gc().includes(t)?function(...e){return t.apply(en(this),e),Nt(Fo.get(this))}:function(...e){return Nt(t.apply(en(this),e))}}function bc(t){return typeof t=="function"?xc(t):(t instanceof IDBTransaction&&_c(t),mc(t,yc())?new Proxy(t,Qn):t)}function Nt(t){if(t instanceof IDBRequest)return wc(t);if(Xn.has(t))return Xn.get(t);let e=bc(t);return e!==t&&(Xn.set(t,e),In.set(e,t)),e}var en=t=>In.get(t);function Ko(t,e,{blocked:r,upgrade:n,blocking:i,terminated:o}={}){let s=indexedDB.open(t,e),a=Nt(s);return n&&s.addEventListener("upgradeneeded",l=>{n(Nt(s.result),l.oldVersion,l.newVersion,Nt(s.transaction),l)}),r&&s.addEventListener("blocked",l=>r(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),i&&l.addEventListener("versionchange",d=>i(d.oldVersion,d.newVersion,d))}).catch(()=>{}),a}var Ec=["get","getKey","getAll","getAllKeys","count"],Tc=["put","add","delete","clear"],Dn=new Map;function Vo(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(Dn.get(e))return Dn.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,i=Tc.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(i||Ec.includes(r)))return;let o=async function(s,...a){let l=this.transaction(s,i?"readwrite":"readonly"),d=l.store;return n&&(d=d.index(a.shift())),(await Promise.all([d[r](...a),i&&l.done]))[0]};return Dn.set(e,o),o}Mo(t=>({...t,get:(e,r,n)=>Vo(e,r)||t.get(e,r,n),has:(e,r)=>!!Vo(e,r)||t.has(e,r)}));var jo="auth-client-db",qo="ic-keyval",Ac=async(t=jo,e=qo,r)=>(rn&&(localStorage!=null&&localStorage.getItem(wt))&&(localStorage.removeItem(wt),localStorage.removeItem(_t)),await Ko(t,r,{upgrade:n=>{n.objectStoreNames.contains(e)&&n.clear(e),n.createObjectStore(e)}}));async function vc(t,e,r){return await t.get(e,r)}async function Sc(t,e,r,n){return await t.put(e,n,r)}async function Rc(t,e,r){return await t.delete(e,r)}var Ie=class t{constructor(e,r){this._db=e,this._storeName=r}static async create(e){let{dbName:r=jo,storeName:n=qo,version:i=Ho}=e??{},o=await Ac(r,n,i);return new t(o,n)}async set(e,r){return await Sc(this._db,this._storeName,e,r)}async get(e){var r;return(r=await vc(this._db,this._storeName,e))!==null&&r!==void 0?r:null}async remove(e){return await Rc(this._db,this._storeName,e)}};var Oc=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},Nc=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},nn,_t="identity",wt="delegation",$o="iv",Ho=1,rn=typeof window<"u",De=class{constructor(e="ic-",r){this.prefix=e,this._localStorage=r}get(e){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+e))}set(e,r){return this._getLocalStorage().setItem(this.prefix+e,r),Promise.resolve()}remove(e){return this._getLocalStorage().removeItem(this.prefix+e),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let e=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.localStorage:globalThis.localStorage:window.localStorage;if(!e)throw new Error("Could not find local storage.");return e}},Le=class{constructor(e){nn.set(this,void 0),Oc(this,nn,e??{},"f")}get _db(){return new Promise(e=>{if(this.initializedDb){e(this.initializedDb);return}Ie.create(Nc(this,nn,"f")).then(r=>{this.initializedDb=r,e(r)})})}async get(e){return await(await this._db).get(e)}async set(e,r){await(await this._db).set(e,r)}async remove(e){await(await this._db).remove(e)}};nn=new WeakMap;var Bc="https://identity.ic0.app",Pc="#authorize",Ln="ECDSA",ti="Ed25519",Cc=500,kc="UserInterrupt",on=class{constructor(e,r,n,i,o,s,a,l){this._identity=e,this._key=r,this._chain=n,this._storage=i,this.idleManager=o,this._createOptions=s,this._idpWindow=a,this._eventHandler=l,this._registerDefaultIdleCallback()}static async create(e={}){var r,n,i;let o=(r=e.storage)!==null&&r!==void 0?r:new Le,s=(n=e.keyType)!==null&&n!==void 0?n:Ln,a=null;if(e.identity)a=e.identity;else{let f=await o.get(_t);if(!f&&rn)try{let h=new De,m=await h.get(wt),y=await h.get(_t);m&&y&&s===Ln&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await o.set(wt,m),await o.set(_t,y),f=m,await h.remove(wt),await h.remove(_t))}catch(h){console.error("error while attempting to recover localstorage: "+h)}if(f)try{typeof f=="object"?s===ti&&typeof f=="string"?a=await ne.fromJSON(f):a=await ze.fromKeyPair(f):typeof f=="string"&&(a=ne.fromJSON(f))}catch{}}let l=new Vt,d=null;if(a)try{let f=await o.get(wt);if(typeof f=="object"&&f!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?l=e.identity:f&&(d=Je.fromJSON(f),No(d)?"toDer"in a?l=Ze.fromDelegation(a,d):l=Xe.fromDelegation(a,d):(await ei(o),a=null))}catch(f){console.error(f),await ei(o),a=null}let c;return!((i=e.idleOptions)===null||i===void 0)&&i.disableIdle?c=void 0:(d||e.identity)&&(c=Qe.create(e.idleOptions)),a||(s===ti?(a=await ne.generate(),await o.set(_t,JSON.stringify(a.toJSON()))):(e.storage&&s===Ln&&console.warn(`You are using a custom storage provider that may not support CryptoKey storage. If you are using a custom storage provider that does not support CryptoKey storage, you should use '${ti}' as the key type, as it can serialize to a string`),a=await ze.generate(),await o.set(_t,a.getKeyPair()))),new this(l,a,d,o,c,e)}_registerDefaultIdleCallback(){var e,r;let n=(e=this._createOptions)===null||e===void 0?void 0:e.idleOptions;!n?.onIdle&&!n?.disableDefaultIdleCallback&&((r=this.idleManager)===null||r===void 0||r.registerCallback(()=>{this.logout(),location.reload()}))}async _handleSuccess(e,r){var n,i;let o=e.delegations.map(d=>({delegation:new Ne(d.delegation.pubkey,d.delegation.expiration,d.delegation.targets),signature:d.signature.buffer})),s=Je.fromDelegations(o,e.userPublicKey.buffer),a=this._key;if(!a)return;this._chain=s,"toDer"in a?this._identity=Ze.fromDelegation(a,this._chain):this._identity=Xe.fromDelegation(a,this._chain),(n=this._idpWindow)===null||n===void 0||n.close();let l=(i=this._createOptions)===null||i===void 0?void 0:i.idleOptions;!this.idleManager&&!l?.disableIdle&&(this.idleManager=Qe.create(l),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(wt,JSON.stringify(this._chain.toJSON())),r?.(e)}getIdentity(){return this._identity}async isAuthenticated(){return!this.getIdentity().getPrincipal().isAnonymous()&&this._chain!==null}async login(e){var r,n,i,o;let s=BigInt(8)*BigInt(36e11),a=new URL(((r=e?.identityProvider)===null||r===void 0?void 0:r.toString())||Bc);a.hash=Pc,(n=this._idpWindow)===null||n===void 0||n.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(a,Object.assign({maxTimeToLive:(i=e?.maxTimeToLive)!==null&&i!==void 0?i:s},e)),window.addEventListener("message",this._eventHandler),this._idpWindow=(o=window.open(a.toString(),"idpWindow",e?.windowOpenerFeatures))!==null&&o!==void 0?o:void 0;let l=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(kc,e?.onError):setTimeout(l,Cc))};l()}_getEventHandler(e,r){return async n=>{var i,o,s;if(n.origin!==e.origin){console.warn(`WARNING: expected origin '${e.origin}', got '${n.origin}' (ignoring)`);return}let a=n.data;switch(a.kind){case"authorize-ready":{let l=Object.assign({kind:"authorize-client",sessionPublicKey:new Uint8Array((i=this._key)===null||i===void 0?void 0:i.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,allowPinAuthentication:r?.allowPinAuthentication,derivationOrigin:(o=r?.derivationOrigin)===null||o===void 0?void 0:o.toString()},r?.customValues);(s=this._idpWindow)===null||s===void 0||s.postMessage(l,e.origin);break}case"authorize-client-success":try{await this._handleSuccess(a,r?.onSuccess)}catch(l){this._handleFailure(l.message,r?.onError)}break;case"authorize-client-failure":this._handleFailure(a.text,r?.onError);break;default:break}}}_handleFailure(e,r){var n;(n=this._idpWindow)===null||n===void 0||n.close(),r?.(e),this._removeEventListener(),delete this._idpWindow}_removeEventListener(){this._eventHandler&&window.removeEventListener("message",this._eventHandler),this._eventHandler=void 0}async logout(e={}){if(await ei(this._storage),this._identity=new Vt,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function ei(t){await t.remove(_t),await t.remove(wt),await t.remove($o)}var sn=()=>on.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var Wo=async({data:t})=>{try{return await br(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var ri=async t=>{let{data:e,version:r,description:n}=t;return{description:Q(n),data:await Ai(e),version:Q(r)}},ni=t=>{let{version:e}=t;return{version:Q(e)}},tr=async({doc:t,key:e})=>{let{owner:r,version:n,description:i,data:o,...s}=t;return{key:e,description:J(i),owner:r.toText(),data:await br(o),version:J(n),...s}};var Go=t=>{if(U(t))return Q();switch(t.matcher){case"equal":return Q({Equal:t.timestamp});case"greaterThan":return Q({GreaterThan:t.timestamp});case"lessThan":return Q({LessThan:t.timestamp});case"between":return Q({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Error("Invalid list matcher for timestamp",t)}},Be=({matcher:t,paginate:e,order:r,owner:n})=>({matcher:U(t)?[]:[{key:Q(t.key),description:Q(t.description),created_at:Go(t.createdAt),updated_at:Go(t.updatedAt)}],paginate:Q(U(e)?void 0:{start_after:Q(e.startAfter),limit:Q(U(e.limit)?void 0:BigInt(e.limit))}),order:Q(U(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:Q(U(n)?void 0:typeof n=="string"?T.fromText(n):n)});var zo=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),r=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),n=t.Record({field:r,desc:t.Bool}),i=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),o=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(i),description:t.Opt(t.Text),created_at:t.Opt(i)}),s=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),a=t.Record({order:t.Opt(n),owner:t.Opt(t.Principal),matcher:t.Opt(o),paginate:t.Opt(s)}),l=t.Record({controllers:t.Vec(t.Principal)}),d=t.Variant({Write:t.Null,Admin:t.Null}),c=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:d,expires_at:t.Opt(t.Nat64)}),f=t.Record({version:t.Opt(t.Nat64)}),h=t.Variant({Db:t.Null,Storage:t.Null}),m=t.Record({version:t.Opt(t.Nat64)}),y=t.Record({cycles:t.Nat,destination_id:t.Principal}),_=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),N=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),S=t.Record({key:_,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,N)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),R=t.Record({derivation_origin:t.Opt(t.Text)}),w=t.Record({internet_identity:t.Opt(R)}),v=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),O=t.Record({max_memory_size:t.Opt(v)}),j=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),Z=t.Variant({Deny:t.Null,Allow:t.Null}),V=t.Record({status_code:t.Nat16,location:t.Text}),K=t.Record({iframe:t.Opt(j),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),max_memory_size:t.Opt(v),raw_access:t.Opt(Z),redirects:t.Opt(t.Vec(t.Tuple(t.Text,V)))}),D=t.Record({db:t.Opt(O),authentication:t.Opt(w),storage:K}),q=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),dt=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),ft=t.Variant({Heap:t.Null,Stable:t.Null}),Pt=t.Record({memory:ft,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),jt=t.Variant({Callback:t.Record({token:Pt,callback:t.Func([],[],["query"])})}),b=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(jt),status_code:t.Nat16}),p=t.Record({token:t.Opt(Pt),body:t.Vec(t.Nat8)}),x=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),E=t.Record({batch_id:t.Nat}),B=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,S)),items_length:t.Nat64}),P=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),C=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,q)),items_length:t.Nat64}),F=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),k=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(ft),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:F,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:F}),M=t.Record({stable:t.Nat64,heap:t.Nat64}),H=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:d,expires_at:t.Opt(t.Nat64)}),G=t.Record({controller:H,controllers:t.Vec(t.Principal)}),rt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),ot=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(ft),max_size:t.Opt(t.Nat),read:F,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:F}),L=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),ct=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text,a],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,a],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([l],[t.Vec(t.Tuple(t.Principal,c))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,f],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,f))],[],[]),del_rule:t.Func([h,t.Text,m],[],[]),deposit_cycles:t.Func([y],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(S)],["query"]),get_auth_config:t.Func([],[t.Opt(w)],["query"]),get_config:t.Func([],[D],[]),get_db_config:t.Func([],[t.Opt(O)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(q)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(S)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(q)))],["query"]),get_storage_config:t.Func([],[K],["query"]),http_request:t.Func([dt],[b],["query"]),http_request_streaming_callback:t.Func([Pt],[p],["query"]),init_asset_upload:t.Func([x],[E],[]),list_assets:t.Func([t.Text,a],[B],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,c))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,P))],["query"]),list_docs:t.Func([t.Text,a],[C],["query"]),list_rules:t.Func([h],[t.Vec(t.Tuple(t.Text,k))],["query"]),memory_size:t.Func([],[M],["query"]),set_auth_config:t.Func([w],[],[]),set_controllers:t.Func([G],[t.Vec(t.Tuple(t.Principal,c))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([O],[],[]),set_doc:t.Func([t.Text,t.Text,rt],[q],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,rt))],[t.Vec(t.Tuple(t.Text,q))],[]),set_rule:t.Func([h,t.Text,ot],[],[]),set_storage_config:t.Func([K],[],[]),upload_asset_chunk:t.Func([L],[ct],[]),version:t.Func([],[t.Text],["query"])})};var Yo=({satelliteId:t,container:e})=>{let{satelliteId:r}=ii({satelliteId:t}),{container:n}=oi({container:e});if($(n)&&n!==!1){let{host:i,protocol:o}=new URL(n===!0?ce:n);return`${o}//${r??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},ii=({satelliteId:t})=>$(t)?{satelliteId:t}:bt.getInstance().get()??{satelliteId:void 0},oi=({container:t})=>$(t)?{container:t}:bt.getInstance().get()??{container:void 0};var I=async t=>Xo({idlFactory:zo,buildType:"stock",...t}),Jo=async({idlFactory:t,...e})=>Xo({idlFactory:t,buildType:"extended",...e}),Xo=async({satelliteId:t,container:e,...r})=>{let{satelliteId:n}=ii({satelliteId:t});xr(n,"No satellite ID defined. Did you initialize Juno?");let{container:i}=oi({container:e});return await ve.getInstance().getActor({satelliteId:n,container:i,...r})};var Zo=async({collection:t,key:e,satellite:r})=>{let{get_doc:n}=await I(r),i=J(await n(t,e));if(!U(i))return tr({doc:i,key:e})},Qo=async({docs:t,satellite:e})=>{let{get_many_docs:r}=await I(e),n=t.map(({collection:s,key:a})=>[s,a]),i=await r(n),o=[];for(let[s,a]of i){let l=J(a);o.push($(l)?await tr({key:s,doc:l}):void 0)}return o},Io=async({collection:t,doc:e,satellite:r})=>{let{set_doc:n}=await I(r),{key:i}=e,o=await ri(e),s=await n(t,i,o);return await tr({key:i,doc:s})},Do=async({docs:t,satellite:e})=>{let{set_many_docs:r}=await I(e),n=[];for(let{collection:s,doc:a}of t){let{key:l}=a;n.push([s,l,await ri(a)])}let i=await r(n),o=[];for(let[s,a]of i)o.push(await tr({key:s,doc:a}));return o},Lo=async({collection:t,doc:e,satellite:r})=>{let{del_doc:n}=await I(r),{key:i}=e;return n(t,i,ni(e))},ts=async({docs:t,satellite:e})=>{let{del_many_docs:r}=await I(e),n=t.map(({collection:i,doc:o})=>[i,o.key,ni(o)]);await r(n)},es=async({collection:t,filter:e,satellite:r})=>{let{list_docs:n}=await I(r),{items:i,items_page:o,items_length:s,matches_length:a,matches_pages:l}=await n(t,Be(e)),d=[];for(let[c,f]of i){let{data:h,owner:m,description:y,version:_,...N}=f;d.push({key:c,description:J(y),owner:m.toText(),data:await Wo({data:h}),version:J(_),...N})}return{items:d,items_length:s,items_page:J(o),matches_length:a,matches_pages:J(l)}},rs=async({collection:t,filter:e,satellite:r})=>{let{count_docs:n}=await I(r);return n(t,Be(e))};var W=t=>t!==void 0?t:an()??new Vt;var ns=async({satellite:t,...e})=>{let r=W(t?.identity);return Zo({...e,satellite:{...t,identity:r}})},qf=async({satellite:t,...e})=>{let r=W(t?.identity);return Qo({...e,satellite:{...t,identity:r}})},is=async({satellite:t,...e})=>{let r=W(t?.identity);return Io({...e,satellite:{...t,identity:r}})},Hf=async({satellite:t,...e})=>{let r=W(t?.identity);return Do({...e,satellite:{...t,identity:r}})},$f=async({satellite:t,...e})=>{let r=W(t?.identity);return Lo({...e,satellite:{...t,identity:r}})},Wf=async({satellite:t,...e})=>{let r=W(t?.identity);return ts({...e,satellite:{...t,identity:r}})},Gf=async({satellite:t,filter:e,...r})=>{let n=W(t?.identity);return es({...r,filter:e??{},satellite:{...t,identity:n}})},zf=async({satellite:t,filter:e,...r})=>{let n=W(t?.identity);return rs({...r,filter:e??{},satellite:{...t,identity:n}})};var os=async t=>{let e=an();if(U(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let r=e.getPrincipal().toText(),n=await ns({collection:"#user",key:r});return U(n)?await Fc({userId:r,provider:t}):n},Fc=async({userId:t,...e})=>is({collection:"#user",doc:{key:t,data:e}});var Bt,si=async t=>{if(Bt=Bt??await sn(),!(await Bt?.isAuthenticated()??!1))return;let r=await os(t);Ft.getInstance().set(r)},Uc=async t=>new Promise(async(e,r)=>{Bt=Bt??await sn();let n=t?.provider??new Er({});await Bt.login({onSuccess:async()=>{await si(n.id),e()},onError:i=>r(i),maxTimeToLive:t?.maxTimeToLive??Si,allowPinAuthentication:t?.allowPin??Ri,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...n.signInOptions({windowed:t?.windowed})})}),ai=async()=>{await Bt?.logout(),Bt=void 0,Ft.getInstance().reset(),ve.getInstance().reset(),Ae.getInstance().reset()},an=()=>Bt?.getIdentity(),Mc=async()=>(Bt??await sn()).getIdentity();var ss=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),n=async()=>{An({message:"junoSignOutAuthTimer"}),await ai()};return r.onmessage=async({data:i})=>{let{msg:o,data:s}=i;switch(o){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":An({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},Ft.getInstance().subscribe(i=>{if(U(i)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var as=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_SATELLITE_ID??t():t()},cs=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_CONTAINER??t():t()};var pp=async({idlFactory:t,satellite:e})=>{let r=W(e?.identity);return Jo({idlFactory:t,...e,identity:r})};var Vc=t=>t==null,Kc=t=>!Vc(t),cn=t=>Kc(t)?[t]:[],jc=()=>typeof window<"u",ls=async({asset:{data:t,filename:e,collection:r,headers:n,token:i,fullPath:o,encoding:s,description:a},actor:l,init_asset_upload:d})=>{let{batch_id:c}=await d({collection:r,full_path:o,name:e,token:cn(i),encoding_type:cn(s),description:cn(a)}),f=19e5,h=[],m=jc()?new Blob([await t.arrayBuffer()]):t,y=0n;for(let S=0;S<m.size;S+=f){let R=m.slice(S,S+f);h.push({batchId:c,chunk:R,actor:l,orderId:y}),y++}let _=[];for await(let S of qc({uploadChunks:h}))_=[..._,...S];let N=n.find(([S,R])=>S.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await l.commit_asset_upload({batch_id:c,chunk_ids:_.map(({chunk_id:S})=>S),headers:[...n,...N||[]]})};async function*qc({uploadChunks:t,limit:e=12}){for(let r=0;r<t.length;r=r+e){let n=t.slice(r,r+e);yield await Promise.all(n.map(i=>Hc(i)))}}var Hc=async({batchId:t,chunk:e,actor:r,orderId:n})=>r.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:cn(n)});var us=async({satellite:t,...e})=>{let r=await I(t);await ls({actor:r,asset:e,init_asset_upload:async i=>await r.init_asset_upload(i)})},ds=async({collection:t,satellite:e,filter:r})=>{let{list_assets:n}=await I(e),{items:i,items_length:o,items_page:s,matches_length:a,matches_pages:l}=await n(t,Be(r));return{items:i.map(([d,c])=>c),items_length:o,items_page:J(s),matches_length:a,matches_pages:J(l)}},fs=async({collection:t,satellite:e,filter:r})=>{let{count_assets:n}=await I(e);return n(t,Be(r))},ps=async({collection:t,fullPath:e,satellite:r})=>(await I(r)).del_asset(t,e),hs=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await I(e),n=t.map(({collection:i,fullPath:o})=>[i,o]);await r(n)},ms=async({collection:t,fullPath:e,satellite:r})=>{let{get_asset:n}=await I(r);return J(await n(t,e))},ys=async({assets:t,satellite:e})=>{let{get_many_assets:r}=await I(e),n=t.map(({collection:o,fullPath:s})=>[o,s]);return(await r(n)).map(([o,s])=>J(s))};var gs=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Np=async t=>ws(t),Bp=async t=>ws({filename:t.data.name,...t}),ws=async({filename:t,data:e,collection:r,headers:n=[],fullPath:i,token:o,satellite:s,encoding:a,description:l})=>{let d=W(s?.identity),c=decodeURI(t),f=i??`/${r}/${c}`,h={...s,identity:d};return await us({data:e,filename:c,collection:r,token:o,headers:n,fullPath:f,encoding:a,satellite:h,description:l}),{downloadUrl:_s({satellite:h,assetKey:{fullPath:f,token:o}}),fullPath:f,name:c}},Pp=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:W(e?.identity)},{items:i,...o}=await ds({collection:t,satellite:n,filter:r??{}}),s=i.map(({key:{full_path:a,token:l,name:d,owner:c,description:f},headers:h,encodings:m,created_at:y,updated_at:_})=>{let N=J(l);return{fullPath:a,description:J(f),name:d,downloadUrl:_s({satellite:n,assetKey:{fullPath:a,token:N}}),token:N,headers:h,encodings:m.reduce((S,[R,{modified:w,sha256:v,total_length:O}])=>({...S,[R]:{modified:w,sha256:gs(v),total_length:O}}),{}),owner:c.toText(),created_at:y,updated_at:_}});return{items:s,assets:s,...o}},Cp=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:W(e?.identity)};return fs({collection:t,satellite:n,filter:r??{}})},kp=async({collection:t,fullPath:e,satellite:r})=>ps({collection:t,fullPath:e,satellite:{...r,identity:W(r?.identity)}}),Fp=async({assets:t,satellite:e})=>hs({assets:t,satellite:{...e,identity:W(e?.identity)}}),Up=async({satellite:t,...e})=>{let r=W(t?.identity);return ms({...e,satellite:{...t,identity:r}})},Mp=async({satellite:t,...e})=>{let r=W(t?.identity);return ys({...e,satellite:{...t,identity:r}})},_s=({assetKey:{fullPath:t,token:e},satellite:r})=>{let n={...r,identity:W(r?.identity)};return`${Yo(n)}${t}${$(e)?`?token=${e}`:""}`};var $c=t=>{let e=t?.satelliteId??as();xr(e,"Satellite ID is not configured. Juno cannot be initialized.");let r=t?.container??cs();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:r}},Gp=async t=>Wc(t),Wc=async t=>{let e=$c(t);bt.getInstance().set(e),await si();let r=e.workers?.auth!==void 0?ss(e.workers.auth):void 0;return[...r?[r]:[]]},zp=t=>Ft.getInstance().subscribe(t);export{Er as InternetIdentityProvider,Ci as NFIDProvider,zp as authSubscribe,Cp as countAssets,zf as countDocs,kp as deleteAsset,$f as deleteDoc,Fp as deleteManyAssets,Wf as deleteManyDocs,_s as downloadUrl,Up as getAsset,ns as getDoc,Mp as getManyAssets,qf as getManyDocs,pp as getSatelliteExtendedActor,Gp as initJuno,Wc as initSatellite,Pp as listAssets,Gf as listDocs,is as setDoc,Hf as setManyDocs,Uc as signIn,ai as signOut,Mc as unsafeIdentity,Np as uploadBlob,Bp as uploadFile};
|
|
30
30
|
/*! Bundled license information:
|
|
31
31
|
|
|
32
32
|
buffer/index.js:
|