@junobuild/core 0.0.62 → 0.0.63

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.
@@ -1,18 +1,18 @@
1
- import{A as pt,B as Xt,C as Zt,D as Be,E as I,F as Fe,G as ke,a as hr,b as gi,c as Oe,d as g,e as _i,f as yr,g as N,h as Q,i as mr,j as gr,k as _r,l as Rt,m as Pe,n as Bt,o as wi,p as Re,q as rt,r as Ft,s as xi,t as wr,u as Jt,v as V}from"./chunk-F6RH4LLT.js";var Br=hr(Lt=>{"use strict";Lt.byteLength=vi;Lt.toByteArray=Si;Lt.fromByteArray=Ri;var q=[],k=[],Ai=typeof Uint8Array<"u"?Uint8Array:Array,je="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(nt=0,Pr=je.length;nt<Pr;++nt)q[nt]=je[nt],k[je.charCodeAt(nt)]=nt;var nt,Pr;k[45]=62;k[95]=63;function Rr(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 vi(t){var e=Rr(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Ni(t,e,r){return(e+r)*3/4-r}function Si(t){var e,r=Rr(t),n=r[0],i=r[1],o=new Ai(Ni(t,n,i)),s=0,a=i>0?n-4:n,l;for(l=0;l<a;l+=4)e=k[t.charCodeAt(l)]<<18|k[t.charCodeAt(l+1)]<<12|k[t.charCodeAt(l+2)]<<6|k[t.charCodeAt(l+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=k[t.charCodeAt(l)]<<2|k[t.charCodeAt(l+1)]>>4,o[s++]=e&255),i===1&&(e=k[t.charCodeAt(l)]<<10|k[t.charCodeAt(l+1)]<<4|k[t.charCodeAt(l+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Oi(t){return q[t>>18&63]+q[t>>12&63]+q[t>>6&63]+q[t&63]}function Pi(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(Oi(n));return i.join("")}function Ri(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(Pi(t,s,s+o>a?a:s+o));return n===1?(e=t[r-1],i.push(q[e>>2]+q[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(q[e>>10]+q[e>>4&63]+q[e<<2&63]+"=")),i.join("")}});var Xr=hr(_t=>{"use strict";var $e=Br(),mt=_i(),Fr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;_t.Buffer=c;_t.SlowBuffer=Vi;_t.INSPECT_MAX_BYTES=50;var te=2147483647;_t.kMaxLength=te;c.TYPED_ARRAY_SUPPORT=Bi();!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Bi(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}});Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function J(t){if(t>te)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,c.prototype),e}function c(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Ge(t)}return Vr(t,e,r)}c.poolSize=8192;function Vr(t,e,r){if(typeof t=="string")return ki(t,e);if(ArrayBuffer.isView(t))return Ci(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(H(t,ArrayBuffer)||t&&H(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(H(t,SharedArrayBuffer)||t&&H(t.buffer,SharedArrayBuffer)))return He(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return c.from(n,e,r);let i=Ui(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return c.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}c.from=function(t,e,r){return Vr(t,e,r)};Object.setPrototypeOf(c.prototype,Uint8Array.prototype);Object.setPrototypeOf(c,Uint8Array);function Kr(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 Fi(t,e,r){return Kr(t),t<=0?J(t):e!==void 0?typeof r=="string"?J(t).fill(e,r):J(t).fill(e):J(t)}c.alloc=function(t,e,r){return Fi(t,e,r)};function Ge(t){return Kr(t),J(t<0?0:Ye(t)|0)}c.allocUnsafe=function(t){return Ge(t)};c.allocUnsafeSlow=function(t){return Ge(t)};function ki(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!c.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=Mr(t,e)|0,n=J(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function qe(t){let e=t.length<0?0:Ye(t.length)|0,r=J(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Ci(t){if(H(t,Uint8Array)){let e=new Uint8Array(t);return He(e.buffer,e.byteOffset,e.byteLength)}return qe(t)}function He(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,c.prototype),n}function Ui(t){if(c.isBuffer(t)){let e=Ye(t.length)|0,r=J(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||Je(t.length)?J(0):qe(t);if(t.type==="Buffer"&&Array.isArray(t.data))return qe(t.data)}function Ye(t){if(t>=te)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+te.toString(16)+" bytes");return t|0}function Vi(t){return+t!=t&&(t=0),c.alloc(+t)}c.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==c.prototype};c.compare=function(e,r){if(H(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),H(r,Uint8Array)&&(r=c.from(r,r.offset,r.byteLength)),!c.isBuffer(e)||!c.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};c.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return c.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=c.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let s=e[n];if(H(s,Uint8Array))o+s.length>i.length?(c.isBuffer(s)||(s=c.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(c.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Mr(t,e){if(c.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||H(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 We(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Jr(t).length;default:if(i)return n?-1:We(t).length;e=(""+e).toLowerCase(),i=!0}}c.byteLength=Mr;function Ki(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 Ji(this,e,r);case"utf8":case"utf-8":return $r(this,e,r);case"ascii":return Yi(this,e,r);case"latin1":case"binary":return zi(this,e,r);case"base64":return Wi(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Xi(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}c.prototype._isBuffer=!0;function it(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}c.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)it(this,r,r+1);return this};c.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)it(this,r,r+3),it(this,r+1,r+2);return this};c.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)it(this,r,r+7),it(this,r+1,r+6),it(this,r+2,r+5),it(this,r+3,r+4);return this};c.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?$r(this,0,e):Ki.apply(this,arguments)};c.prototype.toLocaleString=c.prototype.toString;c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:c.compare(this,e)===0};c.prototype.inspect=function(){let e="",r=_t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};Fr&&(c.prototype[Fr]=c.prototype.inspect);c.prototype.compare=function(e,r,n,i,o){if(H(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-r,l=Math.min(s,a),u=this.slice(i,o),p=e.slice(r,n);for(let d=0;d<l;++d)if(u[d]!==p[d]){s=u[d],a=p[d];break}return s<a?-1:a<s?1:0};function jr(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,Je(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=c.from(e,n)),c.isBuffer(e))return e.length===0?-1:kr(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):kr(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function kr(t,e,r,n,i){let o=1,s=t.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,a/=2,r/=2}function l(p,d){return o===1?p[d]:p.readUInt16BE(d*o)}let u;if(i){let p=-1;for(u=r;u<s;u++)if(l(t,u)===l(e,p===-1?0:u-p)){if(p===-1&&(p=u),u-p+1===a)return p*o}else p!==-1&&(u-=u-p),p=-1}else for(r+a>s&&(r=s-a),u=r;u>=0;u--){let p=!0;for(let d=0;d<a;d++)if(l(t,u+d)!==l(e,d)){p=!1;break}if(p)return u}return-1}c.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};c.prototype.indexOf=function(e,r,n){return jr(this,e,r,n,!0)};c.prototype.lastIndexOf=function(e,r,n){return jr(this,e,r,n,!1)};function Mi(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(Je(a))return s;t[r+s]=a}return s}function ji(t,e,r,n){return ee(We(e,t.length-r),t,r,n)}function $i(t,e,r,n){return ee(Di(e),t,r,n)}function qi(t,e,r,n){return ee(Jr(e),t,r,n)}function Hi(t,e,r,n){return ee(Li(e,t.length-r),t,r,n)}c.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return Mi(this,e,r,n);case"utf8":case"utf-8":return ji(this,e,r,n);case"ascii":case"latin1":case"binary":return $i(this,e,r,n);case"base64":return qi(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Hi(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Wi(t,e,r){return e===0&&r===t.length?$e.fromByteArray(t):$e.fromByteArray(t.slice(e,r))}function $r(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let o=t[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=r){let l,u,p,d;switch(a){case 1:o<128&&(s=o);break;case 2:l=t[i+1],(l&192)===128&&(d=(o&31)<<6|l&63,d>127&&(s=d));break;case 3:l=t[i+1],u=t[i+2],(l&192)===128&&(u&192)===128&&(d=(o&15)<<12|(l&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:l=t[i+1],u=t[i+2],p=t[i+3],(l&192)===128&&(u&192)===128&&(p&192)===128&&(d=(o&15)<<18|(l&63)<<12|(u&63)<<6|p&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return Gi(n)}var Cr=4096;function Gi(t){let e=t.length;if(e<=Cr)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Cr));return r}function Yi(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 zi(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 Ji(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+=to[t[o]];return i}function Xi(t,e,r){let n=t.slice(e,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}c.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let i=this.subarray(e,r);return Object.setPrototypeOf(i,c.prototype),i};function A(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||A(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return i};c.prototype.readUintBE=c.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||A(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};c.prototype.readUint8=c.prototype.readUInt8=function(e,r){return e=e>>>0,r||A(e,1,this.length),this[e]};c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||A(e,2,this.length),this[e]|this[e+1]<<8};c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||A(e,2,this.length),this[e]<<8|this[e+1]};c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||A(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||A(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};c.prototype.readBigUInt64LE=D(function(e){e=e>>>0,gt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&kt(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});c.prototype.readBigUInt64BE=D(function(e){e=e>>>0,gt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&kt(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});c.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||A(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};c.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||A(e,r,this.length);let i=r,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};c.prototype.readInt8=function(e,r){return e=e>>>0,r||A(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};c.prototype.readInt16LE=function(e,r){e=e>>>0,r||A(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};c.prototype.readInt16BE=function(e,r){e=e>>>0,r||A(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};c.prototype.readInt32LE=function(e,r){return e=e>>>0,r||A(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};c.prototype.readInt32BE=function(e,r){return e=e>>>0,r||A(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};c.prototype.readBigInt64LE=D(function(e){e=e>>>0,gt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&kt(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});c.prototype.readBigInt64BE=D(function(e){e=e>>>0,gt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&kt(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});c.prototype.readFloatLE=function(e,r){return e=e>>>0,r||A(e,4,this.length),mt.read(this,e,!0,23,4)};c.prototype.readFloatBE=function(e,r){return e=e>>>0,r||A(e,4,this.length),mt.read(this,e,!1,23,4)};c.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||A(e,8,this.length),mt.read(this,e,!0,52,8)};c.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||A(e,8,this.length),mt.read(this,e,!1,52,8)};function B(t,e,r,n,i,o){if(!c.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;B(this,e,r,n,a,0)}let o=1,s=0;for(this[r]=e&255;++s<n&&(o*=256);)this[r+s]=e/o&255;return r+n};c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;B(this,e,r,n,a,0)}let o=n-1,s=1;for(this[r+o]=e&255;--o>=0&&(s*=256);)this[r+o]=e/s&255;return r+n};c.prototype.writeUint8=c.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||B(this,e,r,1,255,0),this[r]=e&255,r+1};c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||B(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||B(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||B(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||B(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 qr(t,e,r,n,i){zr(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,r}function Hr(t,e,r,n,i){zr(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s=s>>8,t[r+2]=s,s=s>>8,t[r+1]=s,s=s>>8,t[r]=s,r+8}c.prototype.writeBigUInt64LE=D(function(e,r=0){return qr(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeBigUInt64BE=D(function(e,r=0){return Hr(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);B(this,e,r,n,l-1,-l)}let o=0,s=1,a=0;for(this[r]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[r+o-1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};c.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let l=Math.pow(2,8*n-1);B(this,e,r,n,l-1,-l)}let o=n-1,s=1,a=0;for(this[r+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[r+o+1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+n};c.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||B(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};c.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||B(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||B(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||B(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};c.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||B(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};c.prototype.writeBigInt64LE=D(function(e,r=0){return qr(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});c.prototype.writeBigInt64BE=D(function(e,r=0){return Hr(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Wr(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Gr(t,e,r,n,i){return e=+e,r=r>>>0,i||Wr(t,e,r,4,34028234663852886e22,-34028234663852886e22),mt.write(t,e,r,n,23,4),r+4}c.prototype.writeFloatLE=function(e,r,n){return Gr(this,e,r,!0,n)};c.prototype.writeFloatBE=function(e,r,n){return Gr(this,e,r,!1,n)};function Yr(t,e,r,n,i){return e=+e,r=r>>>0,i||Wr(t,e,r,8,17976931348623157e292,-17976931348623157e292),mt.write(t,e,r,n,52,8),r+8}c.prototype.writeDoubleLE=function(e,r,n){return Yr(this,e,r,!0,n)};c.prototype.writeDoubleBE=function(e,r,n){return Yr(this,e,r,!1,n)};c.prototype.copy=function(e,r,n,i){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};c.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!c.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=r;o<n;++o)this[o]=e;else{let s=c.isBuffer(e)?e:c.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=s[o%a]}return this};var yt={};function ze(t,e,r){yt[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}`}}}ze("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);ze("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);ze("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=Ur(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=Ur(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Ur(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 Zi(t,e,r){gt(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&kt(e,t.length-(r+1))}function zr(t,e,r,n,i,o){if(t>r||t<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${r}${s}`,new yt.ERR_OUT_OF_RANGE("value",a,t)}Zi(n,i,o)}function gt(t,e){if(typeof t!="number")throw new yt.ERR_INVALID_ARG_TYPE(e,"number",t)}function kt(t,e,r){throw Math.floor(t)!==t?(gt(t,r),new yt.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new yt.ERR_BUFFER_OUT_OF_BOUNDS:new yt.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var Qi=/[^+/0-9A-Za-z-_]/g;function Ii(t){if(t=t.split("=")[0],t=t.trim().replace(Qi,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function We(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 Di(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function Li(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 Jr(t){return $e.toByteArray(Ii(t))}function ee(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function H(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Je(t){return t!==t}var to=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 D(t){return typeof BigInt>"u"?eo:t}function eo(){throw new Error("BigInt not supported")}});var y=t=>t==null,b=t=>!y(t),bi=class extends Error{},Qt=(t,e)=>{if(y(t))throw new bi(e)},Ce="__bigint__",Ue="__principal__",Ve="__uint8array__",Ei=(t,e)=>typeof e=="bigint"?{[Ce]:`${e}`}:b(e)&&e instanceof g?{[Ue]:e.toText()}:b(e)&&e instanceof Uint8Array?{[Ve]:Array.from(e)}:e,Ti=(t,e)=>{let r=n=>e[n];return b(e)&&typeof e=="object"&&Ce in e?BigInt(r(Ce)):b(e)&&typeof e=="object"&&Ue in e?g.fromText(r(Ue)):b(e)&&typeof e=="object"&&Ve in e?Uint8Array.from(r(Ve)):e},S=t=>b(t)?[t]:[],T=t=>t?.[0],xr=async t=>{let e=new Blob([JSON.stringify(t,Ei)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},It=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(),Ti)},br=()=>typeof window<"u";var ft=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 z=class t extends ft{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 Ke=({message:t,detail:e})=>{let r=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(r)};var Er=BigInt(144e11),Tr=!1,Ar={width:576,height:576},vr={width:505,height:705},Nr="internetcomputer.org";var ht="http://127.0.0.1:5987",Sr="rdmx6-jaaaa-aaaaa-aaadq-cai";var $=class t extends ft{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 Me=({width:t,height:e})=>{if(!br()||y(window)||y(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 Dt=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let r=()=>{let n=$.getInstance().get()?.container;if(y(n)||n===!1)return`https://identity.${this.#t??Nr}`;let i=$.getInstance().get(),o=b(i)&&b(i?.internetIdentityId)?i.internetIdentityId:Sr,{host:s,protocol:a}=new URL(n===!0?ht:n);return/apple/i.test(navigator?.vendor)?`${a}//${s}?canisterId=${o}`:`${a}//${o}.${s.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:Me(Ar)},identityProvider:r()}}},Or=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:Me(vr)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};var rn=Oe(Xr());var ne={};gi(ne,{backoff:()=>Dr,chain:()=>Lr,conditionalDelay:()=>Qr,defaultStrategy:()=>re,maxAttempts:()=>no,once:()=>Zr,throttle:()=>io,timeout:()=>Ir});var ro=5*60*1e3;function re(){return Lr(Qr(Zr(),1e3),Dr(1e3,1.2),Ir(ro))}function Zr(){let t=!0;return async()=>t?(t=!1,!0):!1}function Qr(t,e){return async(r,n,i)=>{if(await t(r,n,i))return new Promise(o=>setTimeout(o,e))}}function no(t){let e=t;return async(r,n,i)=>{if(--e<=0)throw new Error(`Failed to retrieve a reply for request after ${t} attempts:
2
- Request ID: ${N(n)}
3
- Request status: ${i}
4
- `)}}function io(t){return()=>new Promise(e=>setTimeout(e,t))}function Ir(t){let e=Date.now()+t;return async(r,n,i)=>{if(Date.now()>e)throw new Error(`Request timed out after ${t} msec:
5
- Request ID: ${N(n)}
6
- Request status: ${i}
7
- `)}}function Dr(t,e){let r=t;return()=>new Promise(n=>setTimeout(()=>{r*=e,n()},r))}function Lr(...t){return async(e,r,n)=>{for(let i of t)await i(e,r,n)}}async function Xe(t,e,r,n=re(),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]}));l.body.content.ingress_expiry=new wr(3e5);let u=await t.readState(e,{paths:[a]},void 0,l);if(t.rootKey==null)throw new Error("Agent root key not initialized before polling");let p=await Jt.create({certificate:u.certificate,rootKey:t.rootKey,canisterId:e,blsVerify:o}),d=V(p.lookup([...a,new TextEncoder().encode("status")])),f;switch(typeof d>"u"?f=I.Unknown:f=new TextDecoder().decode(d),f){case I.Replied:return{reply:V(p.lookup([...a,"reply"])),certificate:p};case I.Received:case I.Unknown:case I.Processing:return await n(e,r,f),Xe(t,e,r,n,l,o);case I.Rejected:{let m=new Uint8Array(V(p.lookup([...a,"reject_code"])))[0],w=new TextDecoder().decode(V(p.lookup([...a,"reject_message"])));throw new Error(`Call was rejected:
8
- Request ID: ${N(r)}
1
+ import{A as ft,B as Xt,C as Zt,D as Fe,E as D,F as ke,G as Ce,a as yr,b as wn,c as Oe,d as g,e as xn,f as mr,g as S,h as I,i as gr,j as _r,k as wr,l as Rt,m as Re,n as Bt,o as bn,p as Be,q as ot,r as Ft,s as En,t as xr,u as Jt,v as V}from"./chunk-F6RH4LLT.js";var Fr=yr(Lt=>{"use strict";Lt.byteLength=Sn;Lt.toByteArray=On;Lt.fromByteArray=Fn;var q=[],k=[],Nn=typeof Uint8Array<"u"?Uint8Array:Array,$e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(st=0,Rr=$e.length;st<Rr;++st)q[st]=$e[st],k[$e.charCodeAt(st)]=st;var st,Rr;k[45]=62;k[95]=63;function Br(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var i=r===e?0:4-r%4;return[r,i]}function Sn(t){var e=Br(t),r=e[0],i=e[1];return(r+i)*3/4-i}function Pn(t,e,r){return(e+r)*3/4-r}function On(t){var e,r=Br(t),i=r[0],n=r[1],o=new Nn(Pn(t,i,n)),s=0,a=n>0?i-4:i,l;for(l=0;l<a;l+=4)e=k[t.charCodeAt(l)]<<18|k[t.charCodeAt(l+1)]<<12|k[t.charCodeAt(l+2)]<<6|k[t.charCodeAt(l+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return n===2&&(e=k[t.charCodeAt(l)]<<2|k[t.charCodeAt(l+1)]>>4,o[s++]=e&255),n===1&&(e=k[t.charCodeAt(l)]<<10|k[t.charCodeAt(l+1)]<<4|k[t.charCodeAt(l+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Rn(t){return q[t>>18&63]+q[t>>12&63]+q[t>>6&63]+q[t&63]}function Bn(t,e,r){for(var i,n=[],o=e;o<r;o+=3)i=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),n.push(Rn(i));return n.join("")}function Fn(t){for(var e,r=t.length,i=r%3,n=[],o=16383,s=0,a=r-i;s<a;s+=o)n.push(Bn(t,s,s+o>a?a:s+o));return i===1?(e=t[r-1],n.push(q[e>>2]+q[e<<4&63]+"==")):i===2&&(e=(t[r-2]<<8)+t[r-1],n.push(q[e>>10]+q[e>>4&63]+q[e<<2&63]+"=")),n.join("")}});var Zr=yr(wt=>{"use strict";var qe=Fr(),gt=xn(),kr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;wt.Buffer=c;wt.SlowBuffer=Mn;wt.INSPECT_MAX_BYTES=50;var te=2147483647;wt.kMaxLength=te;c.TYPED_ARRAY_SUPPORT=kn();!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function kn(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}});Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function J(t){if(t>te)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,c.prototype),e}function c(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Ye(t)}return Kr(t,e,r)}c.poolSize=8192;function Kr(t,e,r){if(typeof t=="string")return Un(t,e);if(ArrayBuffer.isView(t))return Vn(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(H(t,ArrayBuffer)||t&&H(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(H(t,SharedArrayBuffer)||t&&H(t.buffer,SharedArrayBuffer)))return We(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=t.valueOf&&t.valueOf();if(i!=null&&i!==t)return c.from(i,e,r);let n=Kn(t);if(n)return n;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return c.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}c.from=function(t,e,r){return Kr(t,e,r)};Object.setPrototypeOf(c.prototype,Uint8Array.prototype);Object.setPrototypeOf(c,Uint8Array);function Mr(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 Cn(t,e,r){return Mr(t),t<=0?J(t):e!==void 0?typeof r=="string"?J(t).fill(e,r):J(t).fill(e):J(t)}c.alloc=function(t,e,r){return Cn(t,e,r)};function Ye(t){return Mr(t),J(t<0?0:ze(t)|0)}c.allocUnsafe=function(t){return Ye(t)};c.allocUnsafeSlow=function(t){return Ye(t)};function Un(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!c.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=jr(t,e)|0,i=J(r),n=i.write(t,e);return n!==r&&(i=i.slice(0,n)),i}function He(t){let e=t.length<0?0:ze(t.length)|0,r=J(e);for(let i=0;i<e;i+=1)r[i]=t[i]&255;return r}function Vn(t){if(H(t,Uint8Array)){let e=new Uint8Array(t);return We(e.buffer,e.byteOffset,e.byteLength)}return He(t)}function We(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let i;return e===void 0&&r===void 0?i=new Uint8Array(t):r===void 0?i=new Uint8Array(t,e):i=new Uint8Array(t,e,r),Object.setPrototypeOf(i,c.prototype),i}function Kn(t){if(c.isBuffer(t)){let e=ze(t.length)|0,r=J(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||Xe(t.length)?J(0):He(t);if(t.type==="Buffer"&&Array.isArray(t.data))return He(t.data)}function ze(t){if(t>=te)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+te.toString(16)+" bytes");return t|0}function Mn(t){return+t!=t&&(t=0),c.alloc(+t)}c.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==c.prototype};c.compare=function(e,r){if(H(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),H(r,Uint8Array)&&(r=c.from(r,r.offset,r.byteLength)),!c.isBuffer(e)||!c.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let i=e.length,n=r.length;for(let o=0,s=Math.min(i,n);o<s;++o)if(e[o]!==r[o]){i=e[o],n=r[o];break}return i<n?-1:n<i?1:0};c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};c.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return c.alloc(0);let i;if(r===void 0)for(r=0,i=0;i<e.length;++i)r+=e[i].length;let n=c.allocUnsafe(r),o=0;for(i=0;i<e.length;++i){let s=e[i];if(H(s,Uint8Array))o+s.length>n.length?(c.isBuffer(s)||(s=c.from(s)),s.copy(n,o)):Uint8Array.prototype.set.call(n,s,o);else if(c.isBuffer(s))s.copy(n,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return n};function jr(t,e){if(c.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||H(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,i=arguments.length>2&&arguments[2]===!0;if(!i&&r===0)return 0;let n=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Ge(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Xr(t).length;default:if(n)return i?-1:Ge(t).length;e=(""+e).toLowerCase(),n=!0}}c.byteLength=jr;function jn(t,e,r){let i=!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 Zn(this,e,r);case"utf8":case"utf-8":return qr(this,e,r);case"ascii":return Jn(this,e,r);case"latin1":case"binary":return Xn(this,e,r);case"base64":return Yn(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Qn(this,e,r);default:if(i)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),i=!0}}c.prototype._isBuffer=!0;function at(t,e,r){let i=t[e];t[e]=t[r],t[r]=i}c.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)at(this,r,r+1);return this};c.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)at(this,r,r+3),at(this,r+1,r+2);return this};c.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)at(this,r,r+7),at(this,r+1,r+6),at(this,r+2,r+5),at(this,r+3,r+4);return this};c.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?qr(this,0,e):jn.apply(this,arguments)};c.prototype.toLocaleString=c.prototype.toString;c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:c.compare(this,e)===0};c.prototype.inspect=function(){let e="",r=wt.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};kr&&(c.prototype[kr]=c.prototype.inspect);c.prototype.compare=function(e,r,i,n,o){if(H(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),i===void 0&&(i=e?e.length:0),n===void 0&&(n=0),o===void 0&&(o=this.length),r<0||i>e.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=i)return 0;if(n>=o)return-1;if(r>=i)return 1;if(r>>>=0,i>>>=0,n>>>=0,o>>>=0,this===e)return 0;let s=o-n,a=i-r,l=Math.min(s,a),u=this.slice(n,o),p=e.slice(r,i);for(let d=0;d<l;++d)if(u[d]!==p[d]){s=u[d],a=p[d];break}return s<a?-1:a<s?1:0};function $r(t,e,r,i,n){if(t.length===0)return-1;if(typeof r=="string"?(i=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,Xe(r)&&(r=n?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(n)return-1;r=t.length-1}else if(r<0)if(n)r=0;else return-1;if(typeof e=="string"&&(e=c.from(e,i)),c.isBuffer(e))return e.length===0?-1:Cr(t,e,r,i,n);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?n?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):Cr(t,[e],r,i,n);throw new TypeError("val must be string, number or Buffer")}function Cr(t,e,r,i,n){let o=1,s=t.length,a=e.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,a/=2,r/=2}function l(p,d){return o===1?p[d]:p.readUInt16BE(d*o)}let u;if(n){let p=-1;for(u=r;u<s;u++)if(l(t,u)===l(e,p===-1?0:u-p)){if(p===-1&&(p=u),u-p+1===a)return p*o}else p!==-1&&(u-=u-p),p=-1}else for(r+a>s&&(r=s-a),u=r;u>=0;u--){let p=!0;for(let d=0;d<a;d++)if(l(t,u+d)!==l(e,d)){p=!1;break}if(p)return u}return-1}c.prototype.includes=function(e,r,i){return this.indexOf(e,r,i)!==-1};c.prototype.indexOf=function(e,r,i){return $r(this,e,r,i,!0)};c.prototype.lastIndexOf=function(e,r,i){return $r(this,e,r,i,!1)};function $n(t,e,r,i){r=Number(r)||0;let n=t.length-r;i?(i=Number(i),i>n&&(i=n)):i=n;let o=e.length;i>o/2&&(i=o/2);let s;for(s=0;s<i;++s){let a=parseInt(e.substr(s*2,2),16);if(Xe(a))return s;t[r+s]=a}return s}function qn(t,e,r,i){return ee(Ge(e,t.length-r),t,r,i)}function Hn(t,e,r,i){return ee(to(e),t,r,i)}function Wn(t,e,r,i){return ee(Xr(e),t,r,i)}function Gn(t,e,r,i){return ee(eo(e,t.length-r),t,r,i)}c.prototype.write=function(e,r,i,n){if(r===void 0)n="utf8",i=this.length,r=0;else if(i===void 0&&typeof r=="string")n=r,i=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(i)?(i=i>>>0,n===void 0&&(n="utf8")):(n=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((i===void 0||i>o)&&(i=o),e.length>0&&(i<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let s=!1;for(;;)switch(n){case"hex":return $n(this,e,r,i);case"utf8":case"utf-8":return qn(this,e,r,i);case"ascii":case"latin1":case"binary":return Hn(this,e,r,i);case"base64":return Wn(this,e,r,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Gn(this,e,r,i);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}};c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Yn(t,e,r){return e===0&&r===t.length?qe.fromByteArray(t):qe.fromByteArray(t.slice(e,r))}function qr(t,e,r){r=Math.min(t.length,r);let i=[],n=e;for(;n<r;){let o=t[n],s=null,a=o>239?4:o>223?3:o>191?2:1;if(n+a<=r){let l,u,p,d;switch(a){case 1:o<128&&(s=o);break;case 2:l=t[n+1],(l&192)===128&&(d=(o&31)<<6|l&63,d>127&&(s=d));break;case 3:l=t[n+1],u=t[n+2],(l&192)===128&&(u&192)===128&&(d=(o&15)<<12|(l&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:l=t[n+1],u=t[n+2],p=t[n+3],(l&192)===128&&(u&192)===128&&(p&192)===128&&(d=(o&15)<<18|(l&63)<<12|(u&63)<<6|p&63,d>65535&&d<1114112&&(s=d))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,i.push(s>>>10&1023|55296),s=56320|s&1023),i.push(s),n+=a}return zn(i)}var Ur=4096;function zn(t){let e=t.length;if(e<=Ur)return String.fromCharCode.apply(String,t);let r="",i=0;for(;i<e;)r+=String.fromCharCode.apply(String,t.slice(i,i+=Ur));return r}function Jn(t,e,r){let i="";r=Math.min(t.length,r);for(let n=e;n<r;++n)i+=String.fromCharCode(t[n]&127);return i}function Xn(t,e,r){let i="";r=Math.min(t.length,r);for(let n=e;n<r;++n)i+=String.fromCharCode(t[n]);return i}function Zn(t,e,r){let i=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>i)&&(r=i);let n="";for(let o=e;o<r;++o)n+=ro[t[o]];return n}function Qn(t,e,r){let i=t.slice(e,r),n="";for(let o=0;o<i.length-1;o+=2)n+=String.fromCharCode(i[o]+i[o+1]*256);return n}c.prototype.slice=function(e,r){let i=this.length;e=~~e,r=r===void 0?i:~~r,e<0?(e+=i,e<0&&(e=0)):e>i&&(e=i),r<0?(r+=i,r<0&&(r=0)):r>i&&(r=i),r<e&&(r=e);let n=this.subarray(e,r);return Object.setPrototypeOf(n,c.prototype),n};function v(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(e,r,i){e=e>>>0,r=r>>>0,i||v(e,r,this.length);let n=this[e],o=1,s=0;for(;++s<r&&(o*=256);)n+=this[e+s]*o;return n};c.prototype.readUintBE=c.prototype.readUIntBE=function(e,r,i){e=e>>>0,r=r>>>0,i||v(e,r,this.length);let n=this[e+--r],o=1;for(;r>0&&(o*=256);)n+=this[e+--r]*o;return n};c.prototype.readUint8=c.prototype.readUInt8=function(e,r){return e=e>>>0,r||v(e,1,this.length),this[e]};c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||v(e,2,this.length),this[e]|this[e+1]<<8};c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||v(e,2,this.length),this[e]<<8|this[e+1]};c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||v(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||v(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};c.prototype.readBigUInt64LE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],i=this[e+7];(r===void 0||i===void 0)&&kt(e,this.length-8);let n=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+i*2**24;return BigInt(n)+(BigInt(o)<<BigInt(32))});c.prototype.readBigUInt64BE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],i=this[e+7];(r===void 0||i===void 0)&&kt(e,this.length-8);let n=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+i;return(BigInt(n)<<BigInt(32))+BigInt(o)});c.prototype.readIntLE=function(e,r,i){e=e>>>0,r=r>>>0,i||v(e,r,this.length);let n=this[e],o=1,s=0;for(;++s<r&&(o*=256);)n+=this[e+s]*o;return o*=128,n>=o&&(n-=Math.pow(2,8*r)),n};c.prototype.readIntBE=function(e,r,i){e=e>>>0,r=r>>>0,i||v(e,r,this.length);let n=r,o=1,s=this[e+--n];for(;n>0&&(o*=256);)s+=this[e+--n]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};c.prototype.readInt8=function(e,r){return e=e>>>0,r||v(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};c.prototype.readInt16LE=function(e,r){e=e>>>0,r||v(e,2,this.length);let i=this[e]|this[e+1]<<8;return i&32768?i|4294901760:i};c.prototype.readInt16BE=function(e,r){e=e>>>0,r||v(e,2,this.length);let i=this[e+1]|this[e]<<8;return i&32768?i|4294901760:i};c.prototype.readInt32LE=function(e,r){return e=e>>>0,r||v(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};c.prototype.readInt32BE=function(e,r){return e=e>>>0,r||v(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};c.prototype.readBigInt64LE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],i=this[e+7];(r===void 0||i===void 0)&&kt(e,this.length-8);let n=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(i<<24);return(BigInt(n)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});c.prototype.readBigInt64BE=L(function(e){e=e>>>0,_t(e,"offset");let r=this[e],i=this[e+7];(r===void 0||i===void 0)&&kt(e,this.length-8);let n=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i)});c.prototype.readFloatLE=function(e,r){return e=e>>>0,r||v(e,4,this.length),gt.read(this,e,!0,23,4)};c.prototype.readFloatBE=function(e,r){return e=e>>>0,r||v(e,4,this.length),gt.read(this,e,!1,23,4)};c.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||v(e,8,this.length),gt.read(this,e,!0,52,8)};c.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||v(e,8,this.length),gt.read(this,e,!1,52,8)};function B(t,e,r,i,n,o){if(!c.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>n||e<o)throw new RangeError('"value" argument is out of bounds');if(r+i>t.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,r,i,n){if(e=+e,r=r>>>0,i=i>>>0,!n){let a=Math.pow(2,8*i)-1;B(this,e,r,i,a,0)}let o=1,s=0;for(this[r]=e&255;++s<i&&(o*=256);)this[r+s]=e/o&255;return r+i};c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,r,i,n){if(e=+e,r=r>>>0,i=i>>>0,!n){let a=Math.pow(2,8*i)-1;B(this,e,r,i,a,0)}let o=i-1,s=1;for(this[r+o]=e&255;--o>=0&&(s*=256);)this[r+o]=e/s&255;return r+i};c.prototype.writeUint8=c.prototype.writeUInt8=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,1,255,0),this[r]=e&255,r+1};c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function Hr(t,e,r,i,n){Jr(e,i,n,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 Wr(t,e,r,i,n){Jr(e,i,n,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s=s>>8,t[r+2]=s,s=s>>8,t[r+1]=s,s=s>>8,t[r]=s,r+8}c.prototype.writeBigUInt64LE=L(function(e,r=0){return Hr(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeBigUInt64BE=L(function(e,r=0){return Wr(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeIntLE=function(e,r,i,n){if(e=+e,r=r>>>0,!n){let l=Math.pow(2,8*i-1);B(this,e,r,i,l-1,-l)}let o=0,s=1,a=0;for(this[r]=e&255;++o<i&&(s*=256);)e<0&&a===0&&this[r+o-1]!==0&&(a=1),this[r+o]=(e/s>>0)-a&255;return r+i};c.prototype.writeIntBE=function(e,r,i,n){if(e=+e,r=r>>>0,!n){let l=Math.pow(2,8*i-1);B(this,e,r,i,l-1,-l)}let o=i-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+i};c.prototype.writeInt8=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};c.prototype.writeInt16LE=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};c.prototype.writeInt16BE=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};c.prototype.writeInt32LE=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};c.prototype.writeInt32BE=function(e,r,i){return e=+e,r=r>>>0,i||B(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};c.prototype.writeBigInt64LE=L(function(e,r=0){return Hr(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});c.prototype.writeBigInt64BE=L(function(e,r=0){return Wr(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Gr(t,e,r,i,n,o){if(r+i>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Yr(t,e,r,i,n){return e=+e,r=r>>>0,n||Gr(t,e,r,4,34028234663852886e22,-34028234663852886e22),gt.write(t,e,r,i,23,4),r+4}c.prototype.writeFloatLE=function(e,r,i){return Yr(this,e,r,!0,i)};c.prototype.writeFloatBE=function(e,r,i){return Yr(this,e,r,!1,i)};function zr(t,e,r,i,n){return e=+e,r=r>>>0,n||Gr(t,e,r,8,17976931348623157e292,-17976931348623157e292),gt.write(t,e,r,i,52,8),r+8}c.prototype.writeDoubleLE=function(e,r,i){return zr(this,e,r,!0,i)};c.prototype.writeDoubleBE=function(e,r,i){return zr(this,e,r,!1,i)};c.prototype.copy=function(e,r,i,n){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),!n&&n!==0&&(n=this.length),r>=e.length&&(r=e.length),r||(r=0),n>0&&n<i&&(n=i),n===i||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-r<n-i&&(n=e.length-r+i);let o=n-i;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,i,n):Uint8Array.prototype.set.call(e,this.subarray(i,n),r),o};c.prototype.fill=function(e,r,i,n){if(typeof e=="string"){if(typeof r=="string"?(n=r,r=0,i=this.length):typeof i=="string"&&(n=i,i=this.length),n!==void 0&&typeof n!="string")throw new TypeError("encoding must be a string");if(typeof n=="string"&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(e.length===1){let s=e.charCodeAt(0);(n==="utf8"&&s<128||n==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<i)throw new RangeError("Out of range index");if(i<=r)return this;r=r>>>0,i=i===void 0?this.length:i>>>0,e||(e=0);let o;if(typeof e=="number")for(o=r;o<i;++o)this[o]=e;else{let s=c.isBuffer(e)?e:c.from(e,n),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<i-r;++o)this[o+r]=s[o%a]}return this};var mt={};function Je(t,e,r){mt[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(n){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:n,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}Je("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Je("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);Je("ERR_OUT_OF_RANGE",function(t,e,r){let i=`The value of "${t}" is out of range.`,n=r;return Number.isInteger(r)&&Math.abs(r)>2**32?n=Vr(String(r)):typeof r=="bigint"&&(n=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(n=Vr(n)),n+="n"),i+=` It must be ${e}. Received ${n}`,i},RangeError);function Vr(t){let e="",r=t.length,i=t[0]==="-"?1:0;for(;r>=i+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function In(t,e,r){_t(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&kt(e,t.length-(r+1))}function Jr(t,e,r,i,n,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 mt.ERR_OUT_OF_RANGE("value",a,t)}In(i,n,o)}function _t(t,e){if(typeof t!="number")throw new mt.ERR_INVALID_ARG_TYPE(e,"number",t)}function kt(t,e,r){throw Math.floor(t)!==t?(_t(t,r),new mt.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new mt.ERR_BUFFER_OUT_OF_BOUNDS:new mt.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var Dn=/[^+/0-9A-Za-z-_]/g;function Ln(t){if(t=t.split("=")[0],t=t.trim().replace(Dn,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function Ge(t,e){e=e||1/0;let r,i=t.length,n=null,o=[];for(let s=0;s<i;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!n){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===i){(e-=3)>-1&&o.push(239,191,189);continue}n=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),n=r;continue}r=(n-55296<<10|r-56320)+65536}else n&&(e-=3)>-1&&o.push(239,191,189);if(n=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 to(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function eo(t,e){let r,i,n,o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),i=r>>8,n=r%256,o.push(n),o.push(i);return o}function Xr(t){return qe.toByteArray(Ln(t))}function ee(t,e,r,i){let n;for(n=0;n<i&&!(n+r>=e.length||n>=t.length);++n)e[n+r]=t[n];return n}function H(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Xe(t){return t!==t}var ro=function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let i=r*16;for(let n=0;n<16;++n)e[i+n]=t[r]+t[n]}return e}();function L(t){return typeof BigInt>"u"?io:t}function io(){throw new Error("BigInt not supported")}});var y=t=>t==null,E=t=>!y(t),An=class extends Error{},Qt=(t,e)=>{if(y(t))throw new An(e)},Ue="__bigint__",Ve="__principal__",Ke="__uint8array__",Tn=(t,e)=>typeof e=="bigint"?{[Ue]:`${e}`}:E(e)&&e instanceof g?{[Ve]:e.toText()}:E(e)&&e instanceof Uint8Array?{[Ke]:Array.from(e)}:e,vn=(t,e)=>{let r=i=>e[i];return E(e)&&typeof e=="object"&&Ue in e?BigInt(r(Ue)):E(e)&&typeof e=="object"&&Ve in e?g.fromText(r(Ve)):E(e)&&typeof e=="object"&&Ke in e?Uint8Array.from(r(Ke)):e},P=t=>E(t)?[t]:[],T=t=>t?.[0],br=async t=>{let e=new Blob([JSON.stringify(t,Tn)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},It=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(),vn)},Er=()=>typeof window<"u";var ht=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:i})=>i!==r)}};var z=class t extends ht{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 Me=({message:t,detail:e})=>{let r=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(r)};var Ar=BigInt(144e11),Tr=!1,vr={width:576,height:576},Nr={width:505,height:705},Sr="internetcomputer.org";var yt="http://127.0.0.1:5987",Pr="rdmx6-jaaaa-aaaaa-aaadq-cai";var $=class t extends ht{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 je=({width:t,height:e})=>{if(!Er()||y(window)||y(window.top))return;let{top:{innerWidth:r,innerHeight:i}}=window,n=i/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=${n}, left=${o}`};var Dt=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let r=()=>{let i=$.getInstance().get()?.container;if(y(i)||i===!1)return`https://identity.${this.#t??Sr}`;let n=$.getInstance().get(),o=E(n)&&E(n?.internetIdentityId)?n.internetIdentityId:Pr,{host:s,protocol:a}=new URL(i===!0?yt:i);return/apple/i.test(navigator?.vendor)?`${a}//${s}?canisterId=${o}`:`${a}//${o}.${s.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:je(vr)},identityProvider:r()}}},Or=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:je(Nr)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};var ii=Oe(Zr());var ie={};wn(ie,{backoff:()=>Lr,chain:()=>ti,conditionalDelay:()=>Ir,defaultStrategy:()=>re,maxAttempts:()=>oo,once:()=>Qr,throttle:()=>so,timeout:()=>Dr});var no=5*60*1e3;function re(){return ti(Ir(Qr(),1e3),Lr(1e3,1.2),Dr(no))}function Qr(){let t=!0;return async()=>t?(t=!1,!0):!1}function Ir(t,e){return async(r,i,n)=>{if(await t(r,i,n))return new Promise(o=>setTimeout(o,e))}}function oo(t){let e=t;return async(r,i,n)=>{if(--e<=0)throw new Error(`Failed to retrieve a reply for request after ${t} attempts:
2
+ Request ID: ${S(i)}
3
+ Request status: ${n}
4
+ `)}}function so(t){return()=>new Promise(e=>setTimeout(e,t))}function Dr(t){let e=Date.now()+t;return async(r,i,n)=>{if(Date.now()>e)throw new Error(`Request timed out after ${t} msec:
5
+ Request ID: ${S(i)}
6
+ Request status: ${n}
7
+ `)}}function Lr(t,e){let r=t;return()=>new Promise(i=>setTimeout(()=>{r*=e,i()},r))}function ti(...t){return async(e,r,i)=>{for(let n of t)await n(e,r,i)}}async function Ze(t,e,r,i=re(),n,o){var s;let a=[new TextEncoder().encode("request_status"),r],l=n??await((s=t.createReadStateRequest)===null||s===void 0?void 0:s.call(t,{paths:[a]}));l.body.content.ingress_expiry=new xr(3e5);let u=await t.readState(e,{paths:[a]},void 0,l);if(t.rootKey==null)throw new Error("Agent root key not initialized before polling");let p=await Jt.create({certificate:u.certificate,rootKey:t.rootKey,canisterId:e,blsVerify:o}),d=V(p.lookup([...a,new TextEncoder().encode("status")])),f;switch(typeof d>"u"?f=D.Unknown:f=new TextDecoder().decode(d),f){case D.Replied:return{reply:V(p.lookup([...a,"reply"])),certificate:p};case D.Received:case D.Unknown:case D.Processing:return await i(e,r,f),Ze(t,e,r,i,l,o);case D.Rejected:{let m=new Uint8Array(V(p.lookup([...a,"reject_code"])))[0],w=new TextDecoder().decode(V(p.lookup([...a,"reject_message"])));throw new Error(`Call was rejected:
8
+ Request ID: ${S(r)}
9
9
  Reject code: ${m}
10
10
  Reject text: ${w}
11
- `)}case I.Done:throw new Error(`Call was marked as done but we never saw the reply:
12
- Request ID: ${N(r)}
13
- `)}throw new Error("unreachable")}var tn=({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),u=t.Record({network:e,filter:t.Opt(t.Variant({page:t.Vec(t.Nat8),min_confirmations:t.Nat32})),address:r}),p=t.Vec(t.Nat8),d=t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32}),f=t.Record({height:t.Nat32,value:i,outpoint:d}),m=t.Record({next_page:t.Opt(t.Vec(t.Nat8)),tip_height:t.Nat32,tip_block_hash:p,utxos:t.Vec(f)}),w=t.Record({transaction:t.Vec(t.Nat8),network:e}),h=t.Principal,F=t.Record({canister_id:h,num_requested_changes:t.Opt(t.Nat64)}),_=t.Variant({from_user:t.Record({user_id:t.Principal}),from_canister:t.Record({canister_version:t.Opt(t.Nat64),canister_id:t.Principal})}),x=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}),Y=t.Record({timestamp_nanos:t.Nat64,canister_version:t.Nat64,origin:_,details:x}),R=t.Record({controllers:t.Vec(t.Principal),module_hash:t.Opt(t.Vec(t.Nat8)),recent_changes:t.Vec(Y),total_num_changes:t.Nat64}),v=t.Record({canister_id:h}),X=t.Variant({controllers:t.Null,public:t.Null}),ct=t.Record({freezing_threshold:t.Nat,controllers:t.Vec(t.Principal),reserved_cycles_limit:t.Nat,log_visibility:X,wasm_memory_limit:t.Nat,memory_allocation:t.Nat,compute_allocation:t.Nat}),lt=t.Record({status:t.Variant({stopped:t.Null,stopping:t.Null,running:t.Null}),memory_size:t.Nat,cycles:t.Nat,settings:ct,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}),U=t.Record({canister_id:h}),P=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(X),wasm_memory_limit:t.Opt(t.Nat),memory_allocation:t.Opt(t.Nat),compute_allocation:t.Opt(t.Nat)}),j=t.Record({settings:t.Opt(P),sender_canister_version:t.Opt(t.Nat64)}),St=t.Record({canister_id:h}),et=t.Record({canister_id:h}),Z=t.Record({canister_id:h}),ut=t.Variant({secp256k1:t.Null}),_e=t.Record({key_id:t.Record({name:t.Text,curve:ut}),canister_id:t.Opt(h),derivation_path:t.Vec(t.Vec(t.Nat8))}),we=t.Record({public_key:t.Vec(t.Nat8),chain_code:t.Vec(t.Nat8)}),xe=t.Record({canister_id:h}),be=t.Record({idx:t.Nat64,timestamp_nanos:t.Nat64,content:t.Vec(t.Nat8)}),Ee=t.Record({canister_log_records:t.Vec(be)}),Gt=t.Record({value:t.Text,name:t.Text}),Ot=t.Record({status:t.Nat,body:t.Vec(t.Nat8),headers:t.Vec(Gt)}),dt=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:Ot})],[Ot],["query"]),context:t.Vec(t.Nat8)})),headers:t.Vec(Gt)}),Yt=t.Variant({reinstall:t.Null,upgrade:t.Opt(t.Record({wasm_memory_persistence:t.Opt(t.Variant({keep:t.Null,replace:t.Null})),skip_pre_upgrade:t.Opt(t.Bool)})),install:t.Null}),Pt=t.Record({hash:t.Vec(t.Nat8)}),Te=t.Record({arg:t.Vec(t.Nat8),wasm_module_hash:t.Vec(t.Nat8),mode:Yt,chunk_hashes_list:t.Vec(Pt),target_canister:h,store_canister:t.Opt(h),sender_canister_version:t.Opt(t.Nat64)}),Ae=t.Vec(t.Nat8),zt=t.Record({arg:t.Vec(t.Nat8),wasm_module:Ae,mode:Yt,canister_id:h,sender_canister_version:t.Opt(t.Nat64)}),ve=t.Record({start_at_timestamp_nanos:t.Nat64,subnet_id:t.Principal}),Ne=t.Record({num_block_failures_total:t.Nat64,node_id:t.Principal,num_blocks_proposed_total:t.Nat64}),Se=t.Vec(t.Record({timestamp_nanos:t.Nat64,node_metrics:t.Vec(Ne)})),Ln=t.Record({settings:t.Opt(P),specified_id:t.Opt(h),amount:t.Opt(t.Nat),sender_canister_version:t.Opt(t.Nat64)}),ti=t.Record({canister_id:h}),ei=t.Record({canister_id:h,amount:t.Nat}),ri=t.Vec(t.Nat8),fr=t.Variant({ed25519:t.Null,bip340secp256k1:t.Null}),ni=t.Record({key_id:t.Record({algorithm:fr,name:t.Text}),canister_id:t.Opt(h),derivation_path:t.Vec(t.Vec(t.Nat8))}),ii=t.Record({public_key:t.Vec(t.Nat8),chain_code:t.Vec(t.Nat8)}),oi=t.Record({key_id:t.Record({name:t.Text,curve:ut}),derivation_path:t.Vec(t.Vec(t.Nat8)),message_hash:t.Vec(t.Nat8)}),si=t.Record({signature:t.Vec(t.Nat8)}),ai=t.Record({key_id:t.Record({algorithm:fr,name:t.Text}),derivation_path:t.Vec(t.Vec(t.Nat8)),message:t.Vec(t.Nat8)}),ci=t.Record({signature:t.Vec(t.Nat8)}),li=t.Record({canister_id:h}),ui=t.Record({canister_id:h}),di=t.Record({canister_id:h}),pi=t.Vec(Pt),fi=t.Record({canister_id:h,sender_canister_version:t.Opt(t.Nat64)}),hi=t.Record({canister_id:t.Principal,settings:P,sender_canister_version:t.Opt(t.Nat64)}),yi=t.Record({chunk:t.Vec(t.Nat8),canister_id:t.Principal}),mi=Pt;return t.Service({bitcoin_get_balance:t.Func([n],[o],[]),bitcoin_get_current_fee_percentiles:t.Func([s],[l],[]),bitcoin_get_utxos:t.Func([u],[m],[]),bitcoin_send_transaction:t.Func([w],[],[]),canister_info:t.Func([F],[R],[]),canister_status:t.Func([v],[lt],[]),clear_chunk_store:t.Func([U],[],[]),create_canister:t.Func([j],[St],[]),delete_canister:t.Func([et],[],[]),deposit_cycles:t.Func([Z],[],[]),ecdsa_public_key:t.Func([_e],[we],[]),fetch_canister_logs:t.Func([xe],[Ee],["query"]),http_request:t.Func([dt],[Ot],[]),install_chunked_code:t.Func([Te],[],[]),install_code:t.Func([zt],[],[]),node_metrics_history:t.Func([ve],[Se],[]),provisional_create_canister_with_cycles:t.Func([Ln],[ti],[]),provisional_top_up_canister:t.Func([ei],[],[]),raw_rand:t.Func([],[ri],[]),schnorr_public_key:t.Func([ni],[ii],[]),sign_with_ecdsa:t.Func([oi],[si],[]),sign_with_schnorr:t.Func([ai],[ci],[]),start_canister:t.Func([li],[],[]),stop_canister:t.Func([ui],[],[]),stored_chunks:t.Func([di],[pi],[]),uninstall_code:t.Func([fi],[],[]),update_settings:t.Func([hi],[],[]),upload_chunk:t.Func([yi],[mi],[])})};var ie=class extends Rt{constructor(e,r,n,i){super(["Call failed:",` Canister: ${e.toText()}`,` Method: ${r} (${n})`,...Object.getOwnPropertyNames(i).map(o=>` "${o}": ${JSON.stringify(i[o])}`)].join(`
14
- `)),this.canisterId=e,this.methodName=r,this.type=n,this.props=i}},Ze=class extends ie{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}},oe=class extends ie{constructor(e,r,n,i,o,s,a){super(e,r,"update",Object.assign({"Request ID":N(n)},i.body?Object.assign(Object.assign({},a?{"Error code":a}:{}),{"Reject code":String(o),"Reject message":s}):{"HTTP status code":i.status.toString(),"HTTP status text":i.statusText})),this.requestId=n,this.response=i,this.reject_code=o,this.reject_message=s,this.error_code=a}},C=Symbol.for("ic-agent-metadata"),ot=class t{constructor(e){this[C]=Object.freeze(e)}static agentOf(e){return e[C].config.agent}static interfaceOf(e){return e[C].service}static canisterIdOf(e){return g.from(e[C].config.canisterId)}static async install(e,r){let n=e.mode===void 0?{install:null}:e.mode,i=e.arg?[...new Uint8Array(e.arg)]:[],o=[...new Uint8Array(e.module)],s=typeof r.canisterId=="string"?g.fromText(r.canisterId):r.canisterId;await en(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 en(e||{}).provisional_create_canister_with_cycles({amount:[],settings:n(r||{}),specified_id:[],sender_canister_version:[]});return i}static async createAndInstallCanister(e,r,n){let i=await this.createCanister(n);return await this.install(Object.assign({},r),Object.assign(Object.assign({},n),{canisterId:i})),this.createActor(e,Object.assign(Object.assign({},n),{canisterId:i}))}static createActorClass(e,r){let n=e({IDL:Bt});class i extends t{constructor(s){if(!s.canisterId)throw new Rt(`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"?g.fromText(s.canisterId):s.canisterId;super({config:Object.assign(Object.assign(Object.assign({},nn),s),{canisterId:a}),service:n});for(let[l,u]of n._fields)r?.httpDetails&&u.annotations.push(Qe),r?.certificate&&u.annotations.push(on),this[l]=ao(this,l,u,s.blsVerify)}}return i}static createActor(e,r){if(!r.canisterId)throw new Rt(`Canister ID is required, but received ${typeof r.canisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`);return new(this.createActorClass(e))(r)}static createActorWithHttpDetails(e,r){return new(this.createActorClass(e,{httpDetails:!0}))(r)}static createActorWithExtendedDetails(e,r,n={httpDetails:!0,certificate:!0}){return new(this.createActorClass(e,n))(r)}};function wt(t,e){let r=Bt.decode(t,rn.Buffer.from(e));switch(r.length){case 0:return;case 1:return r[0];default:return r}}var nn={pollingStrategyFactory:ne.defaultStrategy},Qe="http-details",on="certificate";function ao(t,e,r,n){let i;r.annotations.includes("query")||r.annotations.includes("composite_query")?i=async(s,...a)=>{var l,u;s=Object.assign(Object.assign({},s),(u=(l=t[C].config).queryTransform)===null||u===void 0?void 0:u.call(l,e,a,Object.assign(Object.assign({},t[C].config),s)));let p=s.agent||t[C].config.agent||ke(),d=g.from(s.canisterId||t[C].config.canisterId),f=Bt.encode(r.argTypes,a),m=await p.query(d,{methodName:e,arg:f,effectiveCanisterId:s.effectiveCanisterId}),w=Object.assign(Object.assign({},m.httpDetails),{requestDetails:m.requestDetails});switch(m.status){case"rejected":throw new Ze(d,e,m);case"replied":return r.annotations.includes(Qe)?{httpDetails:w,result:wt(r.retTypes,m.reply.arg)}:wt(r.retTypes,m.reply.arg)}}:i=async(s,...a)=>{var l,u;s=Object.assign(Object.assign({},s),(u=(l=t[C].config).callTransform)===null||u===void 0?void 0:u.call(l,e,a,Object.assign(Object.assign({},t[C].config),s)));let p=s.agent||t[C].config.agent||ke(),{canisterId:d,effectiveCanisterId:f,pollingStrategyFactory:m}=Object.assign(Object.assign(Object.assign({},nn),t[C].config),s),w=g.from(d),h=f!==void 0?g.from(f):w,F=Bt.encode(r.argTypes,a);if(p.rootKey==null)throw new Rt("Agent root key not initialized before making call");let{requestId:_,response:x,requestDetails:Y}=await p.call(w,{methodName:e,arg:F,effectiveCanisterId:h}),R,v;if(x.body&&x.body.certificate){let U=x.body.certificate;v=await Jt.create({certificate:Pe(U),rootKey:p.rootKey,canisterId:g.from(d),blsVerify:n});let P=[new TextEncoder().encode("request_status"),_];switch(new TextDecoder().decode(V(v.lookup([...P,"status"])))){case"replied":R=V(v.lookup([...P,"reply"]));break;case"rejected":{let St=new Uint8Array(V(v.lookup([...P,"reject_code"])))[0],et=new TextDecoder().decode(V(v.lookup([...P,"reject_message"]))),Z=V(v.lookup([...P,"error_code"])),ut=Z?new TextDecoder().decode(Z):void 0;throw new oe(w,e,_,x,St,et,ut)}}}else if(x.body&&"reject_message"in x.body){let{reject_code:U,reject_message:P,error_code:j}=x.body;throw new oe(w,e,_,x,U,P,j)}if(x.status===202){let U=m(),P=await Xe(p,h,_,U,n);v=P.certificate,R=P.reply}let X=r.annotations.includes(Qe),ct=r.annotations.includes(on),lt=Object.assign(Object.assign({},x),{requestDetails:Y});if(R!==void 0)return X&&ct?{httpDetails:lt,certificate:v,result:wt(r.retTypes,R)}:ct?{certificate:v,result:wt(r.retTypes,R)}:X?{httpDetails:lt,result:wt(r.retTypes,R)}:wt(r.retTypes,R);if(r.retTypes.length===0)return X?{httpDetails:x,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 en(t){function e(r,n){if(t.effectiveCanisterId)return{effectiveCanisterId:g.from(t.effectiveCanisterId)};let i=n[0],o=g.fromHex("");return i&&typeof i=="object"&&i.canister_id&&(o=g.from(i.canister_id)),{effectiveCanisterId:o}}return ot.createActor(tn,Object.assign(Object.assign(Object.assign({},t),{canisterId:g.fromHex("")}),{callTransform:e,queryTransform:e}))}var xt=class t{static instance;#t=void 0;constructor(){}static getInstance(){return y(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...r}){let n=e.getPrincipal().toText();if(y(this.#t)||y(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=b(n)&&n!==!1?n===!0?ht:n:"https://icp-api.io",s=b(n);return await Fe.create({identity:e,shouldFetchRootKey:s,host:o,...r&&{fetch:r}})}};var bt=class t{static instance;#t=void 0;constructor(){}static getInstance(){return y(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(y(this.#t)||y(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 xt.getInstance().getAgent(n);return ot.createActor(e,{agent:i,canisterId:r})}};var ce=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)},se,ae,Et,Tt;function sn(t){return t!==null&&typeof t=="object"}var st=class t{constructor(e){if(se.set(this,void 0),ae.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");ce(this,se,e,"f"),ce(this,ae,t.derEncode(e),"f")}static from(e){if(typeof e=="string"){let r=Q(e);return this.fromRaw(r)}else if(sn(e)){let r=e;if(sn(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let n=r;return this.fromRaw(_r(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=Zt(e,Xt).buffer;return r.__derEncodedPublicKey__=void 0,r}static derDecode(e){let r=Be(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 L(this,se,"f")}get derKey(){return L(this,ae,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};se=new WeakMap,ae=new WeakMap;st.RAW_KEY_LENGTH=32;var at=class t extends rt{constructor(e,r){super(),Et.set(this,void 0),Tt.set(this,void 0),ce(this,Et,st.from(e),"f"),ce(this,Tt,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=pt.utils.randomPrivateKey()),mr(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=pt.getPublicKey(r);return t.fromKeyPair(n,r)}static fromParsedJson(e){let[r,n]=e;return new t(st.fromDer(Q(r)),Q(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(st.fromRaw(e),r)}static fromSecretKey(e){let r=pt.getPublicKey(new Uint8Array(e));return t.fromKeyPair(r,e)}toJSON(){return[N(L(this,Et,"f").toDer()),N(L(this,Tt,"f"))]}getKeyPair(){return{secretKey:L(this,Tt,"f"),publicKey:L(this,Et,"f")}}getPublicKey(){return L(this,Et,"f")}async sign(e){let r=new Uint8Array(e),n=gr(pt.sign(r,L(this,Tt,"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=Q(a)),a instanceof Uint8Array&&(a=a.buffer),new Uint8Array(a)));return pt.verify(o,i,s)}};Et=new WeakMap,Tt=new WeakMap;var Ie=class t extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,t.prototype)}};function an(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 Ie("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 Ct=class t extends rt{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=an(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=an(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 At=Oe(xi());var lo=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},Ut=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,le=class{constructor(e){tt.set(this,void 0),lo(this,tt,e,"f")}get rawKey(){return Ut(this,tt,"f").rawKey}get derKey(){return Ut(this,tt,"f").derKey}toDer(){return Ut(this,tt,"f").toDer()}getPublicKey(){return Ut(this,tt,"f")}getPrincipal(){return g.from(Ut(this,tt,"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.")}};tt=new WeakMap;var uo=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)},fo=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},ue,ho=new TextEncoder().encode("ic-request-auth-delegation"),yo=new TextEncoder().encode(`
15
- ic-request`);function De(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return Q(t)}var vt=class{constructor(e,r,n){this.pubkey=e,this.expiration=r,this.targets=n}toCBOR(){return At.value.map(Object.assign({pubkey:At.value.bytes(this.pubkey),expiration:At.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:At.value.array(this.targets.map(e=>At.value.bytes(e.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:N(this.pubkey)},this.targets&&{targets:this.targets.map(e=>e.toHex())})}};async function mo(t,e,r,n){let i=new vt(e.toDer(),BigInt(+r)*BigInt(1e6),n),o=new Uint8Array([...ho,...new Uint8Array(Re(i))]),s=await t.sign(o);return{delegation:i,signature:s}}var Vt=class t{constructor(e,r){this.delegations=e,this.publicKey=r}static async create(e,r,n=new Date(Date.now()+15*60*1e3),i={}){var o,s;let a=await mo(e,r,n,i.targets);return new t([...((o=i.previous)===null||o===void 0?void 0:o.delegations)||[],a],((s=i.previous)===null||s===void 0?void 0:s.publicKey)||e.getPublicKey().toDer())}static fromJSON(e){let{publicKey:r,delegations:n}=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(n))throw new Error("Invalid delegations.");let i=n.map(o=>{let{delegation:s,signature:a}=o,{pubkey:l,expiration:u,targets:p}=s;if(p!==void 0&&!Array.isArray(p))throw new Error("Invalid targets.");return{delegation:new vt(De(l),BigInt("0x"+u),p&&p.map(d=>{if(typeof d!="string")throw new Error("Invalid target.");return g.fromHex(d)})),signature:De(a)}});return new this(i,De(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:N(r.pubkey)},i&&{targets:i.map(o=>o.toHex())}),signature:N(n)}}),publicKey:N(this.publicKey)}}},Kt=class extends rt{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=fo(e,["body"]),i=await Re(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_sig:await this.sign(new Uint8Array([...yo,...new Uint8Array(i)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}},Mt=class t extends le{constructor(e,r){super(e),ue.set(this,void 0),uo(this,ue,r,"f")}get delegation(){return po(this,ue,"f")}static fromDelegation(e,r){return new t(e,r)}};ue=new WeakMap;function cn(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"?g.fromText(i):i)):r.push(typeof n=="string"?g.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 _o=Oe(wi());var ln;(function(t){t[t.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(ln||(ln={}));var un=["mousedown","mousemove","keydown","touchstart","wheel"],jt=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),un.forEach(function(a){document.addEventListener(a,o,!0)});let s=(a,l)=>{let u;return(...p)=>{let d=this,f=function(){u=void 0,a.apply(d,p)};clearTimeout(u),u=window.setTimeout(f,l)}};if(e?.captureScroll){let a=s(o,(r=e?.scrollDebounce)!==null&&r!==void 0?r:100);window.addEventListener("scroll",a,!0)}o()}static create(e={}){return new this(e)}registerCallback(e){this.callbacks.push(e)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let e=this._resetTimer.bind(this);un.forEach(function(r){document.removeEventListener(r,e,!0)}),this.callbacks.forEach(r=>r())}_resetTimer(){let e=this.exit.bind(this);window.clearTimeout(this.timeoutID),this.timeoutID=window.setTimeout(e,this.idleTimeout)}};var wo=(t,e)=>e.some(r=>t instanceof r),dn,pn;function xo(){return dn||(dn=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function bo(){return pn||(pn=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var fn=new WeakMap,tr=new WeakMap,hn=new WeakMap,Le=new WeakMap,rr=new WeakMap;function Eo(t){let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("success",o),t.removeEventListener("error",s)},o=()=>{r(W(t.result)),i()},s=()=>{n(t.error),i()};t.addEventListener("success",o),t.addEventListener("error",s)});return e.then(r=>{r instanceof IDBCursor&&fn.set(r,t)}).catch(()=>{}),rr.set(e,t),e}function To(t){if(tr.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)});tr.set(t,e)}var er={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return tr.get(t);if(e==="objectStoreNames")return t.objectStoreNames||hn.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return W(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function yn(t){er=t(er)}function Ao(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(de(this),e,...r);return hn.set(n,e.sort?e.sort():[e]),W(n)}:bo().includes(t)?function(...e){return t.apply(de(this),e),W(fn.get(this))}:function(...e){return W(t.apply(de(this),e))}}function vo(t){return typeof t=="function"?Ao(t):(t instanceof IDBTransaction&&To(t),wo(t,xo())?new Proxy(t,er):t)}function W(t){if(t instanceof IDBRequest)return Eo(t);if(Le.has(t))return Le.get(t);let e=vo(t);return e!==t&&(Le.set(t,e),rr.set(e,t)),e}var de=t=>rr.get(t);function gn(t,e,{blocked:r,upgrade:n,blocking:i,terminated:o}={}){let s=indexedDB.open(t,e),a=W(s);return n&&s.addEventListener("upgradeneeded",l=>{n(W(s.result),l.oldVersion,l.newVersion,W(s.transaction),l)}),r&&s.addEventListener("blocked",l=>r(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),i&&l.addEventListener("versionchange",u=>i(u.oldVersion,u.newVersion,u))}).catch(()=>{}),a}var No=["get","getKey","getAll","getAllKeys","count"],So=["put","add","delete","clear"],nr=new Map;function mn(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(nr.get(e))return nr.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,i=So.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(i||No.includes(r)))return;let o=async function(s,...a){let l=this.transaction(s,i?"readwrite":"readonly"),u=l.store;return n&&(u=u.index(a.shift())),(await Promise.all([u[r](...a),i&&l.done]))[0]};return nr.set(e,o),o}yn(t=>({...t,get:(e,r,n)=>mn(e,r)||t.get(e,r,n),has:(e,r)=>!!mn(e,r)||t.has(e,r)}));var _n="auth-client-db",wn="ic-keyval",Oo=async(t=_n,e=wn,r)=>(pe&&(localStorage!=null&&localStorage.getItem(K))&&(localStorage.removeItem(K),localStorage.removeItem(M)),await gn(t,r,{upgrade:n=>{n.objectStoreNames.contains(e)&&n.clear(e),n.createObjectStore(e)}}));async function Po(t,e,r){return await t.get(e,r)}async function Ro(t,e,r,n){return await t.put(e,n,r)}async function Bo(t,e,r){return await t.delete(e,r)}var $t=class t{constructor(e,r){this._db=e,this._storeName=r}static async create(e){let{dbName:r=_n,storeName:n=wn,version:i=xn}=e??{},o=await Oo(r,n,i);return new t(o,n)}async set(e,r){return await Ro(this._db,this._storeName,e,r)}async get(e){var r;return(r=await Po(this._db,this._storeName,e))!==null&&r!==void 0?r:null}async remove(e){return await Bo(this._db,this._storeName,e)}};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},ko=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},fe,M="identity",K="delegation",bn="iv",xn=1,pe=typeof window<"u",qt=class{constructor(e="ic-",r){this.prefix=e,this._localStorage=r}get(e){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+e))}set(e,r){return this._getLocalStorage().setItem(this.prefix+e,r),Promise.resolve()}remove(e){return this._getLocalStorage().removeItem(this.prefix+e),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let e=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.localStorage:globalThis.localStorage:window.localStorage;if(!e)throw new Error("Could not find local storage.");return e}},Ht=class{constructor(e){fe.set(this,void 0),Fo(this,fe,e??{},"f")}get _db(){return new Promise(e=>{if(this.initializedDb){e(this.initializedDb);return}$t.create(ko(this,fe,"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)}};fe=new WeakMap;var Co="https://identity.ic0.app",Uo="#authorize",ir="ECDSA",or="Ed25519",Vo=500,Ko="UserInterrupt",he=class{constructor(e,r,n,i,o,s,a,l){this._identity=e,this._key=r,this._chain=n,this._storage=i,this.idleManager=o,this._createOptions=s,this._idpWindow=a,this._eventHandler=l,this._registerDefaultIdleCallback()}static async create(e={}){var r,n,i;let o=(r=e.storage)!==null&&r!==void 0?r:new Ht,s=(n=e.keyType)!==null&&n!==void 0?n:ir,a=null;if(e.identity)a=e.identity;else{let d=await o.get(M);if(!d&&pe)try{let f=new qt,m=await f.get(K),w=await f.get(M);m&&w&&s===ir&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await o.set(K,m),await o.set(M,w),d=m,await f.remove(K),await f.remove(M))}catch(f){console.error("error while attempting to recover localstorage: "+f)}if(d)try{typeof d=="object"?s===or&&typeof d=="string"?a=await at.fromJSON(d):a=await Ct.fromKeyPair(d):typeof d=="string"&&(a=at.fromJSON(d))}catch{}}let l=new Ft,u=null;if(a)try{let d=await o.get(K);if(typeof d=="object"&&d!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?l=e.identity:d&&(u=Vt.fromJSON(d),cn(u)?"toDer"in a?l=Mt.fromDelegation(a,u):l=Kt.fromDelegation(a,u):(await sr(o),a=null))}catch(d){console.error(d),await sr(o),a=null}let p;return!((i=e.idleOptions)===null||i===void 0)&&i.disableIdle?p=void 0:(u||e.identity)&&(p=jt.create(e.idleOptions)),a||(s===or?(a=await at.generate(),await o.set(M,JSON.stringify(a.toJSON()))):(e.storage&&s===ir&&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 '${or}' as the key type, as it can serialize to a string`),a=await Ct.generate(),await o.set(M,a.getKeyPair()))),new this(l,a,u,o,p,e)}_registerDefaultIdleCallback(){var e,r;let n=(e=this._createOptions)===null||e===void 0?void 0:e.idleOptions;!n?.onIdle&&!n?.disableDefaultIdleCallback&&((r=this.idleManager)===null||r===void 0||r.registerCallback(()=>{this.logout(),location.reload()}))}async _handleSuccess(e,r){var n,i;let o=e.delegations.map(u=>({delegation:new vt(u.delegation.pubkey,u.delegation.expiration,u.delegation.targets),signature:u.signature.buffer})),s=Vt.fromDelegations(o,e.userPublicKey.buffer),a=this._key;if(!a)return;this._chain=s,"toDer"in a?this._identity=Mt.fromDelegation(a,this._chain):this._identity=Kt.fromDelegation(a,this._chain),(n=this._idpWindow)===null||n===void 0||n.close();let l=(i=this._createOptions)===null||i===void 0?void 0:i.idleOptions;!this.idleManager&&!l?.disableIdle&&(this.idleManager=jt.create(l),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(K,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())||Co);a.hash=Uo,(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(Ko,e?.onError):setTimeout(l,Vo))};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 sr(this._storage),this._identity=new Ft,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function sr(t){await t.remove(M),await t.remove(K),await t.remove(bn)}var ye=()=>he.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var En=async({data:t})=>{try{return await It(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var ar=async t=>{let{data:e,version:r,description:n}=t;return{description:S(n),data:await xr(e),version:S(r)}},cr=t=>{let{version:e}=t;return{version:S(e)}},Wt=async({doc:t,key:e})=>{let{owner:r,version:n,description:i,data:o,...s}=t;return{key:e,description:T(i),owner:r.toText(),data:await It(o),version:T(n),...s}};var Tn=t=>{if(y(t))return S();switch(t.matcher){case"equal":return S({Equal:t.timestamp});case"greaterThan":return S({GreaterThan:t.timestamp});case"lessThan":return S({LessThan:t.timestamp});case"between":return S({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Error("Invalid list matcher for timestamp",t)}},Nt=({matcher:t,paginate:e,order:r,owner:n})=>({matcher:y(t)?[]:[{key:S(t.key),description:S(t.description),created_at:Tn(t.createdAt),updated_at:Tn(t.updatedAt)}],paginate:S(y(e)?void 0:{start_after:S(e.startAfter),limit:S(y(e.limit)?void 0:BigInt(e.limit))}),order:S(y(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:S(y(n)?void 0:typeof n=="string"?g.fromText(n):n)});var An=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),r=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),n=t.Record({field:r,desc:t.Bool}),i=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),o=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(i),description:t.Opt(t.Text),created_at:t.Opt(i)}),s=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),a=t.Record({order:t.Opt(n),owner:t.Opt(t.Principal),matcher:t.Opt(o),paginate:t.Opt(s)}),l=t.Record({controllers:t.Vec(t.Principal)}),u=t.Variant({Write:t.Null,Admin:t.Null}),p=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:u,expires_at:t.Opt(t.Nat64)}),d=t.Record({version:t.Opt(t.Nat64)}),f=t.Variant({Db:t.Null,Storage:t.Null}),m=t.Record({version:t.Opt(t.Nat64)}),w=t.Record({cycles:t.Nat,destination_id:t.Principal}),h=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}),F=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),_=t.Record({key:h,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,F)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),x=t.Record({derivation_origin:t.Opt(t.Text)}),Y=t.Record({internet_identity:t.Opt(x)}),R=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),v=t.Record({max_memory_size:t.Opt(R)}),X=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),ct=t.Variant({Deny:t.Null,Allow:t.Null}),lt=t.Record({status_code:t.Nat16,location:t.Text}),U=t.Record({iframe:t.Opt(X),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(R),raw_access:t.Opt(ct),redirects:t.Opt(t.Vec(t.Tuple(t.Text,lt)))}),P=t.Record({db:t.Opt(v),authentication:t.Opt(Y),storage:U}),j=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),St=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)}),et=t.Variant({Heap:t.Null,Stable:t.Null}),Z=t.Record({memory:et,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}),ut=t.Variant({Callback:t.Record({token:Z,callback:t.Func([],[],["query"])})}),_e=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(ut),status_code:t.Nat16}),we=t.Record({token:t.Opt(Z),body:t.Vec(t.Nat8)}),xe=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}),be=t.Record({batch_id:t.Nat}),Ee=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,_)),items_length:t.Nat64}),Gt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),Ot=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,j)),items_length:t.Nat64}),dt=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),Yt=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(et),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:dt,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:dt}),Pt=t.Record({stable:t.Nat64,heap:t.Nat64}),Te=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:u,expires_at:t.Opt(t.Nat64)}),Ae=t.Record({controller:Te,controllers:t.Vec(t.Principal)}),zt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),ve=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(et),max_size:t.Opt(t.Nat),read:dt,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:dt}),Ne=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Se=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text,a],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,a],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([l],[t.Vec(t.Tuple(t.Principal,p))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,d],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,d))],[],[]),del_rule:t.Func([f,t.Text,m],[],[]),deposit_cycles:t.Func([w],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(_)],["query"]),get_auth_config:t.Func([],[t.Opt(Y)],["query"]),get_config:t.Func([],[P],[]),get_db_config:t.Func([],[t.Opt(v)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(j)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(_)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(j)))],["query"]),get_storage_config:t.Func([],[U],["query"]),http_request:t.Func([St],[_e],["query"]),http_request_streaming_callback:t.Func([Z],[we],["query"]),init_asset_upload:t.Func([xe],[be],[]),list_assets:t.Func([t.Text,a],[Ee],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,p))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Gt))],["query"]),list_docs:t.Func([t.Text,a],[Ot],["query"]),list_rules:t.Func([f],[t.Vec(t.Tuple(t.Text,Yt))],["query"]),memory_size:t.Func([],[Pt],["query"]),set_auth_config:t.Func([Y],[],[]),set_controllers:t.Func([Ae],[t.Vec(t.Tuple(t.Principal,p))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([v],[],[]),set_doc:t.Func([t.Text,t.Text,zt],[j],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,zt))],[t.Vec(t.Tuple(t.Text,j))],[]),set_rule:t.Func([f,t.Text,ve],[],[]),set_storage_config:t.Func([U],[],[]),upload_asset_chunk:t.Func([Ne],[Se],[]),version:t.Func([],[t.Text],["query"])})};var vn=({satelliteId:t,container:e})=>{let{satelliteId:r}=lr({satelliteId:t}),{container:n}=ur({container:e});if(b(n)&&n!==!1){let{host:i,protocol:o}=new URL(n===!0?ht:n);return`${o}//${r??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},lr=({satelliteId:t})=>b(t)?{satelliteId:t}:$.getInstance().get()??{satelliteId:void 0},ur=({container:t})=>b(t)?{container:t}:$.getInstance().get()??{container:void 0};var O=async t=>Sn({idlFactory:An,buildType:"stock",...t}),Nn=async({idlFactory:t,...e})=>Sn({idlFactory:t,buildType:"extended",...e}),Sn=async({satelliteId:t,container:e,...r})=>{let{satelliteId:n}=lr({satelliteId:t});Qt(n,"No satellite ID defined. Did you initialize Juno?");let{container:i}=ur({container:e});return await bt.getInstance().getActor({satelliteId:n,container:i,...r})};var On=async({collection:t,key:e,satellite:r})=>{let{get_doc:n}=await O(r),i=T(await n(t,e));if(!y(i))return Wt({doc:i,key:e})},Pn=async({docs:t,satellite:e})=>{let{get_many_docs:r}=await O(e),n=t.map(({collection:s,key:a})=>[s,a]),i=await r(n),o=[];for(let[s,a]of i){let l=T(a);o.push(b(l)?await Wt({key:s,doc:l}):void 0)}return o},Rn=async({collection:t,doc:e,satellite:r})=>{let{set_doc:n}=await O(r),{key:i}=e,o=await ar(e),s=await n(t,i,o);return await Wt({key:i,doc:s})},Bn=async({docs:t,satellite:e})=>{let{set_many_docs:r}=await O(e),n=[];for(let{collection:s,doc:a}of t){let{key:l}=a;n.push([s,l,await ar(a)])}let i=await r(n),o=[];for(let[s,a]of i)o.push(await Wt({key:s,doc:a}));return o},Fn=async({collection:t,doc:e,satellite:r})=>{let{del_doc:n}=await O(r),{key:i}=e;return n(t,i,cr(e))},kn=async({docs:t,satellite:e})=>{let{del_many_docs:r}=await O(e),n=t.map(({collection:i,doc:o})=>[i,o.key,cr(o)]);await r(n)},Cn=async({collection:t,filter:e,satellite:r})=>{let{list_docs:n}=await O(r),{items:i,items_page:o,items_length:s,matches_length:a,matches_pages:l}=await n(t,Nt(e)),u=[];for(let[p,d]of i){let{data:f,owner:m,description:w,version:h,...F}=d;u.push({key:p,description:T(w),owner:m.toText(),data:await En({data:f}),version:T(h),...F})}return{items:u,items_length:s,items_page:T(o),matches_length:a,matches_pages:T(l)}},Un=async({collection:t,filter:e,satellite:r})=>{let{count_docs:n}=await O(r);return n(t,Nt(e))};var E=t=>t!==void 0?t:me()??new Ft;var Vn=async({satellite:t,...e})=>{let r=E(t?.identity);return On({...e,satellite:{...t,identity:r}})},Bc=async({satellite:t,...e})=>{let r=E(t?.identity);return Pn({...e,satellite:{...t,identity:r}})},Kn=async({satellite:t,...e})=>{let r=E(t?.identity);return Rn({...e,satellite:{...t,identity:r}})},Fc=async({satellite:t,...e})=>{let r=E(t?.identity);return Bn({...e,satellite:{...t,identity:r}})},kc=async({satellite:t,...e})=>{let r=E(t?.identity);return Fn({...e,satellite:{...t,identity:r}})},Cc=async({satellite:t,...e})=>{let r=E(t?.identity);return kn({...e,satellite:{...t,identity:r}})},Uc=async({satellite:t,filter:e,...r})=>{let n=E(t?.identity);return Cn({...r,filter:e??{},satellite:{...t,identity:n}})},Vc=async({satellite:t,filter:e,...r})=>{let n=E(t?.identity);return Un({...r,filter:e??{},satellite:{...t,identity:n}})};var Mn=async t=>{let e=me();if(y(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let r=e.getPrincipal().toText(),n=await Vn({collection:"#user",key:r});return y(n)?await Mo({userId:r,provider:t}):n},Mo=async({userId:t,...e})=>Kn({collection:"#user",doc:{key:t,data:e}});var G,dr=async t=>{if(G=G??await ye(),!(await G?.isAuthenticated()??!1))return;let r=await Mn(t);z.getInstance().set(r)},jo=async t=>new Promise(async(e,r)=>{G=G??await ye();let n=t?.provider??new Dt({});await G.login({onSuccess:async()=>{await dr(n.id),e()},onError:i=>r(i),maxTimeToLive:t?.maxTimeToLive??Er,allowPinAuthentication:t?.allowPin??Tr,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...n.signInOptions({windowed:t?.windowed})})}),pr=async()=>{await G?.logout(),G=void 0,z.getInstance().reset(),bt.getInstance().reset(),xt.getInstance().reset()},me=()=>G?.getIdentity(),$o=async()=>(G??await ye()).getIdentity();var jn=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),n=async()=>{Ke({message:"junoSignOutAuthTimer"}),await pr()};return r.onmessage=async({data:i})=>{let{msg:o,data:s}=i;switch(o){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":Ke({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},z.getInstance().subscribe(i=>{if(y(i)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var $n=()=>{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()},qn=()=>{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 il=async({idlFactory:t,satellite:e})=>{let r=E(e?.identity);return Nn({idlFactory:t,...e,identity:r})};var qo=t=>t==null,Ho=t=>!qo(t),ge=t=>Ho(t)?[t]:[],Wo=()=>typeof window<"u",Hn=async({asset:{data:t,filename:e,collection:r,headers:n,token:i,fullPath:o,encoding:s,description:a},actor:l,init_asset_upload:u})=>{let{batch_id:p}=await u({collection:r,full_path:o,name:e,token:ge(i),encoding_type:ge(s),description:ge(a)}),d=19e5,f=[],m=Wo()?new Blob([await t.arrayBuffer()]):t,w=0n;for(let _=0;_<m.size;_+=d){let x=m.slice(_,_+d);f.push({batchId:p,chunk:x,actor:l,orderId:w}),w++}let h=[];for await(let _ of Go({uploadChunks:f}))h=[...h,..._];let F=n.find(([_,x])=>_.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await l.commit_asset_upload({batch_id:p,chunk_ids:h.map(({chunk_id:_})=>_),headers:[...n,...F||[]]})};async function*Go({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=>Yo(i)))}}var Yo=async({batchId:t,chunk:e,actor:r,orderId:n})=>r.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:ge(n)});var Wn=async({satellite:t,...e})=>{let r=await O(t);await Hn({actor:r,asset:e,init_asset_upload:async i=>await r.init_asset_upload(i)})},Gn=async({collection:t,satellite:e,filter:r})=>{let{list_assets:n}=await O(e),{items:i,items_length:o,items_page:s,matches_length:a,matches_pages:l}=await n(t,Nt(r));return{items:i.map(([u,p])=>p),items_length:o,items_page:T(s),matches_length:a,matches_pages:T(l)}},Yn=async({collection:t,satellite:e,filter:r})=>{let{count_assets:n}=await O(e);return n(t,Nt(r))},zn=async({collection:t,fullPath:e,satellite:r})=>(await O(r)).del_asset(t,e),Jn=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await O(e),n=t.map(({collection:i,fullPath:o})=>[i,o]);await r(n)},Xn=async({collection:t,fullPath:e,satellite:r})=>{let{get_asset:n}=await O(r);return T(await n(t,e))},Zn=async({assets:t,satellite:e})=>{let{get_many_assets:r}=await O(e),n=t.map(({collection:o,fullPath:s})=>[o,s]);return(await r(n)).map(([o,s])=>T(s))};var Qn=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var xl=async t=>In(t),bl=async t=>In({filename:t.data.name,...t}),In=async({filename:t,data:e,collection:r,headers:n=[],fullPath:i,token:o,satellite:s,encoding:a,description:l})=>{let u=E(s?.identity),p=decodeURI(t),d=i??`/${r}/${p}`,f={...s,identity:u};return await Wn({data:e,filename:p,collection:r,token:o,headers:n,fullPath:d,encoding:a,satellite:f,description:l}),{downloadUrl:Dn({satellite:f,assetKey:{fullPath:d,token:o}}),fullPath:d,name:p}},El=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:E(e?.identity)},{items:i,...o}=await Gn({collection:t,satellite:n,filter:r??{}}),s=i.map(({key:{full_path:a,token:l,name:u,owner:p,description:d},headers:f,encodings:m,created_at:w,updated_at:h})=>{let F=T(l);return{fullPath:a,description:T(d),name:u,downloadUrl:Dn({satellite:n,assetKey:{fullPath:a,token:F}}),token:F,headers:f,encodings:m.reduce((_,[x,{modified:Y,sha256:R,total_length:v}])=>({..._,[x]:{modified:Y,sha256:Qn(R),total_length:v}}),{}),owner:p.toText(),created_at:w,updated_at:h}});return{items:s,assets:s,...o}},Tl=async({collection:t,satellite:e,filter:r})=>{let n={...e,identity:E(e?.identity)};return Yn({collection:t,satellite:n,filter:r??{}})},Al=async({collection:t,fullPath:e,satellite:r})=>zn({collection:t,fullPath:e,satellite:{...r,identity:E(r?.identity)}}),vl=async({assets:t,satellite:e})=>Jn({assets:t,satellite:{...e,identity:E(e?.identity)}}),Nl=async({satellite:t,...e})=>{let r=E(t?.identity);return Xn({...e,satellite:{...t,identity:r}})},Sl=async({satellite:t,...e})=>{let r=E(t?.identity);return Zn({...e,satellite:{...t,identity:r}})},Dn=({assetKey:{fullPath:t,token:e},satellite:r})=>{let n={...r,identity:E(r?.identity)};return`${vn(n)}${t}${b(e)?`?token=${e}`:""}`};var zo=t=>{let e=t?.satelliteId??$n();Qt(e,"Satellite ID is not configured. Juno cannot be initialized.");let r=t?.container??qn();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:r}},Ul=async t=>Jo(t),Jo=async t=>{let e=zo(t);$.getInstance().set(e),await dr();let r=e.workers?.auth!==void 0?jn(e.workers.auth):void 0;return[...r?[r]:[]]},Vl=t=>z.getInstance().subscribe(t);export{Dt as InternetIdentityProvider,Or as NFIDProvider,Vl as authSubscribe,Tl as countAssets,Vc as countDocs,Al as deleteAsset,kc as deleteDoc,vl as deleteManyAssets,Cc as deleteManyDocs,Dn as downloadUrl,Nl as getAsset,Vn as getDoc,Sl as getManyAssets,Bc as getManyDocs,il as getSatelliteExtendedActor,Ul as initJuno,Jo as initSatellite,El as listAssets,Uc as listDocs,Kn as setDoc,Fc as setManyDocs,jo as signIn,pr as signOut,$o as unsafeIdentity,xl as uploadBlob,bl as uploadFile};
11
+ `)}case D.Done:throw new Error(`Call was marked as done but we never saw the reply:
12
+ Request ID: ${S(r)}
13
+ `)}throw new Error("unreachable")}var ei=({IDL:t})=>{let e=t.Variant({mainnet:t.Null,testnet:t.Null}),r=t.Text,i=t.Record({network:e,address:r,min_confirmations:t.Opt(t.Nat32)}),n=t.Nat64,o=n,s=t.Record({network:e}),a=t.Nat64,l=t.Vec(a),u=t.Record({network:e,filter:t.Opt(t.Variant({page:t.Vec(t.Nat8),min_confirmations:t.Nat32})),address:r}),p=t.Vec(t.Nat8),d=t.Record({txid:t.Vec(t.Nat8),vout:t.Nat32}),f=t.Record({height:t.Nat32,value:n,outpoint:d}),m=t.Record({next_page:t.Opt(t.Vec(t.Nat8)),tip_height:t.Nat32,tip_block_hash:p,utxos:t.Vec(f)}),w=t.Record({transaction:t.Vec(t.Nat8),network:e}),h=t.Principal,F=t.Record({canister_id:h,num_requested_changes:t.Opt(t.Nat64)}),_=t.Variant({from_user:t.Record({user_id:t.Principal}),from_canister:t.Record({canister_version:t.Opt(t.Nat64),canister_id:t.Principal})}),b=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}),Y=t.Record({timestamp_nanos:t.Nat64,canister_version:t.Nat64,origin:_,details:b}),R=t.Record({controllers:t.Vec(t.Principal),module_hash:t.Opt(t.Vec(t.Nat8)),recent_changes:t.Vec(Y),total_num_changes:t.Nat64}),N=t.Record({canister_id:h}),X=t.Variant({controllers:t.Null,public:t.Null}),dt=t.Record({freezing_threshold:t.Nat,controllers:t.Vec(t.Principal),reserved_cycles_limit:t.Nat,log_visibility:X,wasm_memory_limit:t.Nat,memory_allocation:t.Nat,compute_allocation:t.Nat}),pt=t.Record({status:t.Variant({stopped:t.Null,stopping:t.Null,running:t.Null}),memory_size:t.Nat,cycles:t.Nat,settings:dt,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}),U=t.Record({canister_id:h}),O=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(X),wasm_memory_limit:t.Opt(t.Nat),memory_allocation:t.Opt(t.Nat),compute_allocation:t.Opt(t.Nat)}),j=t.Record({settings:t.Opt(O),sender_canister_version:t.Opt(t.Nat64)}),it=t.Record({canister_id:h}),Z=t.Record({canister_id:h}),nt=t.Record({canister_id:h}),Q=t.Variant({secp256k1:t.Null}),_e=t.Record({key_id:t.Record({name:t.Text,curve:Q}),canister_id:t.Opt(h),derivation_path:t.Vec(t.Vec(t.Nat8))}),St=t.Record({public_key:t.Vec(t.Nat8),chain_code:t.Vec(t.Nat8)}),we=t.Record({canister_id:h}),xe=t.Record({idx:t.Nat64,timestamp_nanos:t.Nat64,content:t.Vec(t.Nat8)}),be=t.Record({canister_log_records:t.Vec(xe)}),Gt=t.Record({value:t.Text,name:t.Text}),Pt=t.Record({status:t.Nat,body:t.Vec(t.Nat8),headers:t.Vec(Gt)}),Ee=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:Pt})],[Pt],["query"]),context:t.Vec(t.Nat8)})),headers:t.Vec(Gt)}),Yt=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}),Ot=t.Record({hash:t.Vec(t.Nat8)}),Ae=t.Record({arg:t.Vec(t.Nat8),wasm_module_hash:t.Vec(t.Nat8),mode:Yt,chunk_hashes_list:t.Vec(Ot),target_canister:h,store_canister:t.Opt(h),sender_canister_version:t.Opt(t.Nat64)}),Te=t.Vec(t.Nat8),ve=t.Record({arg:t.Vec(t.Nat8),wasm_module:Te,mode:Yt,canister_id:h,sender_canister_version:t.Opt(t.Nat64)}),zt=t.Record({start_at_timestamp_nanos:t.Nat64,subnet_id:t.Principal}),Ne=t.Record({num_block_failures_total:t.Nat64,node_id:t.Principal,num_blocks_proposed_total:t.Nat64}),Se=t.Vec(t.Record({timestamp_nanos:t.Nat64,node_metrics:t.Vec(Ne)})),Pe=t.Record({settings:t.Opt(O),specified_id:t.Opt(h),amount:t.Opt(t.Nat),sender_canister_version:t.Opt(t.Nat64)}),en=t.Record({canister_id:h}),rn=t.Record({canister_id:h,amount:t.Nat}),nn=t.Vec(t.Nat8),hr=t.Variant({ed25519:t.Null,bip340secp256k1:t.Null}),on=t.Record({key_id:t.Record({algorithm:hr,name:t.Text}),canister_id:t.Opt(h),derivation_path:t.Vec(t.Vec(t.Nat8))}),sn=t.Record({public_key:t.Vec(t.Nat8),chain_code:t.Vec(t.Nat8)}),an=t.Record({key_id:t.Record({name:t.Text,curve:Q}),derivation_path:t.Vec(t.Vec(t.Nat8)),message_hash:t.Vec(t.Nat8)}),cn=t.Record({signature:t.Vec(t.Nat8)}),ln=t.Record({key_id:t.Record({algorithm:hr,name:t.Text}),derivation_path:t.Vec(t.Vec(t.Nat8)),message:t.Vec(t.Nat8)}),un=t.Record({signature:t.Vec(t.Nat8)}),dn=t.Record({canister_id:h}),pn=t.Record({canister_id:h}),fn=t.Record({canister_id:h}),hn=t.Vec(Ot),yn=t.Record({canister_id:h,sender_canister_version:t.Opt(t.Nat64)}),mn=t.Record({canister_id:t.Principal,settings:O,sender_canister_version:t.Opt(t.Nat64)}),gn=t.Record({chunk:t.Vec(t.Nat8),canister_id:t.Principal}),_n=Ot;return t.Service({bitcoin_get_balance:t.Func([i],[o],[]),bitcoin_get_current_fee_percentiles:t.Func([s],[l],[]),bitcoin_get_utxos:t.Func([u],[m],[]),bitcoin_send_transaction:t.Func([w],[],[]),canister_info:t.Func([F],[R],[]),canister_status:t.Func([N],[pt],[]),clear_chunk_store:t.Func([U],[],[]),create_canister:t.Func([j],[it],[]),delete_canister:t.Func([Z],[],[]),deposit_cycles:t.Func([nt],[],[]),ecdsa_public_key:t.Func([_e],[St],[]),fetch_canister_logs:t.Func([we],[be],["query"]),http_request:t.Func([Ee],[Pt],[]),install_chunked_code:t.Func([Ae],[],[]),install_code:t.Func([ve],[],[]),node_metrics_history:t.Func([zt],[Se],[]),provisional_create_canister_with_cycles:t.Func([Pe],[en],[]),provisional_top_up_canister:t.Func([rn],[],[]),raw_rand:t.Func([],[nn],[]),schnorr_public_key:t.Func([on],[sn],[]),sign_with_ecdsa:t.Func([an],[cn],[]),sign_with_schnorr:t.Func([ln],[un],[]),start_canister:t.Func([dn],[],[]),stop_canister:t.Func([pn],[],[]),stored_chunks:t.Func([fn],[hn],[]),uninstall_code:t.Func([yn],[],[]),update_settings:t.Func([mn],[],[]),upload_chunk:t.Func([gn],[_n],[])})};var ne=class extends Rt{constructor(e,r,i,n){super(["Call failed:",` Canister: ${e.toText()}`,` Method: ${r} (${i})`,...Object.getOwnPropertyNames(n).map(o=>` "${o}": ${JSON.stringify(n[o])}`)].join(`
14
+ `)),this.canisterId=e,this.methodName=r,this.type=i,this.props=n}},Qe=class extends ne{constructor(e,r,i){var n;super(e,r,"query",{Status:i.status,Code:(n=mr[i.reject_code])!==null&&n!==void 0?n:`Unknown Code "${i.reject_code}"`,Message:i.reject_message}),this.result=i}},oe=class extends ne{constructor(e,r,i,n,o,s,a){super(e,r,"update",Object.assign({"Request ID":S(i)},n.body?Object.assign(Object.assign({},a?{"Error code":a}:{}),{"Reject code":String(o),"Reject message":s}):{"HTTP status code":n.status.toString(),"HTTP status text":n.statusText})),this.requestId=i,this.response=n,this.reject_code=o,this.reject_message=s,this.error_code=a}},C=Symbol.for("ic-agent-metadata"),ct=class t{constructor(e){this[C]=Object.freeze(e)}static agentOf(e){return e[C].config.agent}static interfaceOf(e){return e[C].service}static canisterIdOf(e){return g.from(e[C].config.canisterId)}static async install(e,r){let i=e.mode===void 0?{install:null}:e.mode,n=e.arg?[...new Uint8Array(e.arg)]:[],o=[...new Uint8Array(e.module)],s=typeof r.canisterId=="string"?g.fromText(r.canisterId):r.canisterId;await ri(r).install_code({mode:i,arg:n,wasm_module:o,canister_id:s,sender_canister_version:[]})}static async createCanister(e,r){function i(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:n}=await ri(e||{}).provisional_create_canister_with_cycles({amount:[],settings:i(r||{}),specified_id:[],sender_canister_version:[]});return n}static async createAndInstallCanister(e,r,i){let n=await this.createCanister(i);return await this.install(Object.assign({},r),Object.assign(Object.assign({},i),{canisterId:n})),this.createActor(e,Object.assign(Object.assign({},i),{canisterId:n}))}static createActorClass(e,r){let i=e({IDL:Bt});class n extends t{constructor(s){if(!s.canisterId)throw new Rt(`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"?g.fromText(s.canisterId):s.canisterId;super({config:Object.assign(Object.assign(Object.assign({},ni),s),{canisterId:a}),service:i});for(let[l,u]of i._fields)r?.httpDetails&&u.annotations.push(Ie),r?.certificate&&u.annotations.push(oi),this[l]=lo(this,l,u,s.blsVerify)}}return n}static createActor(e,r){if(!r.canisterId)throw new Rt(`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,i={httpDetails:!0,certificate:!0}){return new(this.createActorClass(e,i))(r)}};function xt(t,e){let r=Bt.decode(t,ii.Buffer.from(e));switch(r.length){case 0:return;case 1:return r[0];default:return r}}var ni={pollingStrategyFactory:ie.defaultStrategy},Ie="http-details",oi="certificate";function lo(t,e,r,i){let n;r.annotations.includes("query")||r.annotations.includes("composite_query")?n=async(s,...a)=>{var l,u;s=Object.assign(Object.assign({},s),(u=(l=t[C].config).queryTransform)===null||u===void 0?void 0:u.call(l,e,a,Object.assign(Object.assign({},t[C].config),s)));let p=s.agent||t[C].config.agent||Ce(),d=g.from(s.canisterId||t[C].config.canisterId),f=Bt.encode(r.argTypes,a),m=await p.query(d,{methodName:e,arg:f,effectiveCanisterId:s.effectiveCanisterId}),w=Object.assign(Object.assign({},m.httpDetails),{requestDetails:m.requestDetails});switch(m.status){case"rejected":throw new Qe(d,e,m);case"replied":return r.annotations.includes(Ie)?{httpDetails:w,result:xt(r.retTypes,m.reply.arg)}:xt(r.retTypes,m.reply.arg)}}:n=async(s,...a)=>{var l,u;s=Object.assign(Object.assign({},s),(u=(l=t[C].config).callTransform)===null||u===void 0?void 0:u.call(l,e,a,Object.assign(Object.assign({},t[C].config),s)));let p=s.agent||t[C].config.agent||Ce(),{canisterId:d,effectiveCanisterId:f,pollingStrategyFactory:m}=Object.assign(Object.assign(Object.assign({},ni),t[C].config),s),w=g.from(d),h=f!==void 0?g.from(f):w,F=Bt.encode(r.argTypes,a);if(p.rootKey==null)throw new Rt("Agent root key not initialized before making call");let{requestId:_,response:b,requestDetails:Y}=await p.call(w,{methodName:e,arg:F,effectiveCanisterId:h}),R,N;if(b.body&&b.body.certificate){let U=b.body.certificate;N=await Jt.create({certificate:Re(U),rootKey:p.rootKey,canisterId:g.from(d),blsVerify:i});let O=[new TextEncoder().encode("request_status"),_];switch(new TextDecoder().decode(V(N.lookup([...O,"status"])))){case"replied":R=V(N.lookup([...O,"reply"]));break;case"rejected":{let it=new Uint8Array(V(N.lookup([...O,"reject_code"])))[0],Z=new TextDecoder().decode(V(N.lookup([...O,"reject_message"]))),nt=V(N.lookup([...O,"error_code"])),Q=nt?new TextDecoder().decode(nt):void 0;throw new oe(w,e,_,b,it,Z,Q)}}}else if(b.body&&"reject_message"in b.body){let{reject_code:U,reject_message:O,error_code:j}=b.body;throw new oe(w,e,_,b,U,O,j)}if(b.status===202){let U=m(),O=await Ze(p,h,_,U,i);N=O.certificate,R=O.reply}let X=r.annotations.includes(Ie),dt=r.annotations.includes(oi),pt=Object.assign(Object.assign({},b),{requestDetails:Y});if(R!==void 0)return X&&dt?{httpDetails:pt,certificate:N,result:xt(r.retTypes,R)}:dt?{certificate:N,result:xt(r.retTypes,R)}:X?{httpDetails:pt,result:xt(r.retTypes,R)}:xt(r.retTypes,R);if(r.retTypes.length===0)return X?{httpDetails:b,result:void 0}:void 0;throw new Error(`Call was returned undefined, but type [${r.retTypes.join(",")}].`)};let o=(...s)=>n({},...s);return o.withOptions=s=>(...a)=>n(s,...a),o}function ri(t){function e(r,i){if(t.effectiveCanisterId)return{effectiveCanisterId:g.from(t.effectiveCanisterId)};let n=i[0],o=g.fromHex("");return n&&typeof n=="object"&&n.canister_id&&(o=g.from(n.canister_id)),{effectiveCanisterId:o}}return ct.createActor(ei,Object.assign(Object.assign(Object.assign({},t),{canisterId:g.fromHex("")}),{callTransform:e,queryTransform:e}))}var bt=class t{static instance;#t=void 0;constructor(){}static getInstance(){return y(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...r}){let i=e.getPrincipal().toText();if(y(this.#t)||y(this.#t[i])){let n=await this.createAgent({identity:e,...r});return this.#t={...this.#t??{},[i]:n},n}return this.#t[i]}reset(){this.#t=null}async createAgent({identity:e,fetch:r,container:i}){let o=E(i)&&i!==!1?i===!0?yt:i:"https://icp-api.io",s=E(i);return await ke.create({identity:e,shouldFetchRootKey:s,host:o,...r&&{fetch:r}})}};var Et=class t{static instance;#t=void 0;constructor(){}static getInstance(){return y(t.instance)&&(t.instance=new t),t.instance}async getActor({satelliteId:e,identity:r,buildType:i,...n}){let o=`${i}#${r.getPrincipal().toText()}#${e};`;if(y(this.#t)||y(this.#t[o])){let s=await this.createActor({satelliteId:e,identity:r,...n});return this.#t={...this.#t??{},[o]:s},s}return this.#t[o]}reset(){this.#t=null}async createActor({idlFactory:e,satelliteId:r,...i}){let n=await bt.getInstance().getAgent(i);return ct.createActor(e,{agent:n,canisterId:r})}};var ce=function(t,e,r,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(t,r):n?n.value=r:e.set(t,r),r},tt=function(t,e,r,i){if(r==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?i:r==="a"?i.call(t):i?i.value:e.get(t)},se,ae,At,Tt;function si(t){return t!==null&&typeof t=="object"}var lt=class t{constructor(e){if(se.set(this,void 0),ae.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");ce(this,se,e,"f"),ce(this,ae,t.derEncode(e),"f")}static from(e){if(typeof e=="string"){let r=I(e);return this.fromRaw(r)}else if(si(e)){let r=e;if(si(r)&&Object.hasOwnProperty.call(r,"__derEncodedPublicKey__"))return this.fromDer(r);if(ArrayBuffer.isView(r)){let i=r;return this.fromRaw(wr(i.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=Zt(e,Xt).buffer;return r.__derEncodedPublicKey__=void 0,r}static derDecode(e){let r=Fe(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 tt(this,se,"f")}get derKey(){return tt(this,ae,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};se=new WeakMap,ae=new WeakMap;lt.RAW_KEY_LENGTH=32;var ut=class t extends ot{constructor(e,r){super(),At.set(this,void 0),Tt.set(this,void 0),ce(this,At,lt.from(e),"f"),ce(this,Tt,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=ft.utils.randomPrivateKey()),gr(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 n=0;n<32;n++)r[n]=new Uint8Array(e)[n];let i=ft.getPublicKey(r);return t.fromKeyPair(i,r)}static fromParsedJson(e){let[r,i]=e;return new t(lt.fromDer(I(r)),I(i))}static fromJSON(e){let r=JSON.parse(e);if(Array.isArray(r)){if(typeof r[0]=="string"&&typeof r[1]=="string")return this.fromParsedJson([r[0],r[1]]);throw new Error("Deserialization error: JSON must have at least 2 items.")}throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(e)}`)}static fromKeyPair(e,r){return new t(lt.fromRaw(e),r)}static fromSecretKey(e){let r=ft.getPublicKey(new Uint8Array(e));return t.fromKeyPair(r,e)}toJSON(){return[S(tt(this,At,"f").toDer()),S(tt(this,Tt,"f"))]}getKeyPair(){return{secretKey:tt(this,Tt,"f"),publicKey:tt(this,At,"f")}}getPublicKey(){return tt(this,At,"f")}async sign(e){let r=new Uint8Array(e),i=_r(ft.sign(r,tt(this,Tt,"f").slice(0,32)));return Object.defineProperty(i,"__signature__",{enumerable:!1,value:void 0}),i}static verify(e,r,i){let[n,o,s]=[e,r,i].map(a=>(typeof a=="string"&&(a=I(a)),a instanceof Uint8Array&&(a=a.buffer),new Uint8Array(a)));return ft.verify(o,n,s)}};At=new WeakMap,Tt=new WeakMap;var De=class t extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,t.prototype)}};function ai(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 De("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 Ct=class t extends ot{constructor(e,r,i){super(),this._keyPair=e,this._derKey=r,this._subtleCrypto=i}static async generate(e){let{extractable:r=!1,keyUsages:i=["sign","verify"],subtleCrypto:n}=e??{},o=ai(n),s=await o.generateKey({name:"ECDSA",namedCurve:"P-256"},r,i),a=await o.exportKey("spki",s.publicKey);return new this(s,a,o)}static async fromKeyPair(e,r){let i=ai(r),n=await i.exportKey("spki",e.publicKey);return new t(e,n,i)}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 vt=Oe(En());var po=function(t,e,r,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(t,r):n?n.value=r:e.set(t,r),r},Ut=function(t,e,r,i){if(r==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?i:r==="a"?i.call(t):i?i.value:e.get(t)},et,le=class{constructor(e){et.set(this,void 0),po(this,et,e,"f")}get rawKey(){return Ut(this,et,"f").rawKey}get derKey(){return Ut(this,et,"f").derKey}toDer(){return Ut(this,et,"f").toDer()}getPublicKey(){return Ut(this,et,"f")}getPrincipal(){return g.from(Ut(this,et,"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.")}};et=new WeakMap;var fo=function(t,e,r,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(t,r):n?n.value=r:e.set(t,r),r},ho=function(t,e,r,i){if(r==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?i:r==="a"?i.call(t):i?i.value:e.get(t)},yo=function(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(t);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(t,i[n])&&(r[i[n]]=t[i[n]]);return r},ue,mo=new TextEncoder().encode("ic-request-auth-delegation"),go=new TextEncoder().encode(`
15
+ ic-request`);function Le(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return I(t)}var Nt=class{constructor(e,r,i){this.pubkey=e,this.expiration=r,this.targets=i}toCBOR(){return vt.value.map(Object.assign({pubkey:vt.value.bytes(this.pubkey),expiration:vt.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:vt.value.array(this.targets.map(e=>vt.value.bytes(e.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:S(this.pubkey)},this.targets&&{targets:this.targets.map(e=>e.toHex())})}};async function _o(t,e,r,i){let n=new Nt(e.toDer(),BigInt(+r)*BigInt(1e6),i),o=new Uint8Array([...mo,...new Uint8Array(Be(n))]),s=await t.sign(o);return{delegation:n,signature:s}}var Vt=class t{constructor(e,r){this.delegations=e,this.publicKey=r}static async create(e,r,i=new Date(Date.now()+15*60*1e3),n={}){var o,s;let a=await _o(e,r,i,n.targets);return new t([...((o=n.previous)===null||o===void 0?void 0:o.delegations)||[],a],((s=n.previous)===null||s===void 0?void 0:s.publicKey)||e.getPublicKey().toDer())}static fromJSON(e){let{publicKey:r,delegations:i}=typeof e=="string"?JSON.parse(e):e;if(!Array.isArray(i))throw new Error("Invalid delegations.");let n=i.map(o=>{let{delegation:s,signature:a}=o,{pubkey:l,expiration:u,targets:p}=s;if(p!==void 0&&!Array.isArray(p))throw new Error("Invalid targets.");return{delegation:new Nt(Le(l),BigInt("0x"+u),p&&p.map(d=>{if(typeof d!="string")throw new Error("Invalid target.");return g.fromHex(d)})),signature:Le(a)}});return new this(n,Le(r))}static fromDelegations(e,r){return new this(e,r)}toJSON(){return{delegations:this.delegations.map(e=>{let{delegation:r,signature:i}=e,{targets:n}=r;return{delegation:Object.assign({expiration:r.expiration.toString(16),pubkey:S(r.pubkey)},n&&{targets:n.map(o=>o.toHex())}),signature:S(i)}}),publicKey:S(this.publicKey)}}},Kt=class extends ot{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,i=yo(e,["body"]),n=await Be(r);return Object.assign(Object.assign({},i),{body:{content:r,sender_sig:await this.sign(new Uint8Array([...go,...new Uint8Array(n)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}},Mt=class t extends le{constructor(e,r){super(e),ue.set(this,void 0),fo(this,ue,r,"f")}get delegation(){return ho(this,ue,"f")}static fromDelegation(e,r){return new t(e,r)}};ue=new WeakMap;function ci(t,e){for(let{delegation:n}of t.delegations)if(+new Date(Number(n.expiration/BigInt(1e6)))<=+Date.now())return!1;let r=[],i=e?.scope;i&&(Array.isArray(i)?r.push(...i.map(n=>typeof n=="string"?g.fromText(n):n)):r.push(typeof i=="string"?g.fromText(i):i));for(let n of r){let o=n.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 xo=Oe(bn());var li;(function(t){t[t.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(li||(li={}));var ui=["mousedown","mousemove","keydown","touchstart","wheel"],jt=class{constructor(e={}){var r;this.callbacks=[],this.idleTimeout=10*60*1e3,this.timeoutID=void 0;let{onIdle:i,idleTimeout:n=10*60*1e3}=e||{};this.callbacks=i?[i]:[],this.idleTimeout=n;let o=this._resetTimer.bind(this);window.addEventListener("load",o,!0),ui.forEach(function(a){document.addEventListener(a,o,!0)});let s=(a,l)=>{let u;return(...p)=>{let d=this,f=function(){u=void 0,a.apply(d,p)};clearTimeout(u),u=window.setTimeout(f,l)}};if(e?.captureScroll){let a=s(o,(r=e?.scrollDebounce)!==null&&r!==void 0?r:100);window.addEventListener("scroll",a,!0)}o()}static create(e={}){return new this(e)}registerCallback(e){this.callbacks.push(e)}exit(){clearTimeout(this.timeoutID),window.removeEventListener("load",this._resetTimer,!0);let e=this._resetTimer.bind(this);ui.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 bo=(t,e)=>e.some(r=>t instanceof r),di,pi;function Eo(){return di||(di=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Ao(){return pi||(pi=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var fi=new WeakMap,er=new WeakMap,hi=new WeakMap,tr=new WeakMap,ir=new WeakMap;function To(t){let e=new Promise((r,i)=>{let n=()=>{t.removeEventListener("success",o),t.removeEventListener("error",s)},o=()=>{r(W(t.result)),n()},s=()=>{i(t.error),n()};t.addEventListener("success",o),t.addEventListener("error",s)});return e.then(r=>{r instanceof IDBCursor&&fi.set(r,t)}).catch(()=>{}),ir.set(e,t),e}function vo(t){if(er.has(t))return;let e=new Promise((r,i)=>{let n=()=>{t.removeEventListener("complete",o),t.removeEventListener("error",s),t.removeEventListener("abort",s)},o=()=>{r(),n()},s=()=>{i(t.error||new DOMException("AbortError","AbortError")),n()};t.addEventListener("complete",o),t.addEventListener("error",s),t.addEventListener("abort",s)});er.set(t,e)}var rr={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return er.get(t);if(e==="objectStoreNames")return t.objectStoreNames||hi.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return W(t[e])},set(t,e,r){return t[e]=r,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function yi(t){rr=t(rr)}function No(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let i=t.call(de(this),e,...r);return hi.set(i,e.sort?e.sort():[e]),W(i)}:Ao().includes(t)?function(...e){return t.apply(de(this),e),W(fi.get(this))}:function(...e){return W(t.apply(de(this),e))}}function So(t){return typeof t=="function"?No(t):(t instanceof IDBTransaction&&vo(t),bo(t,Eo())?new Proxy(t,rr):t)}function W(t){if(t instanceof IDBRequest)return To(t);if(tr.has(t))return tr.get(t);let e=So(t);return e!==t&&(tr.set(t,e),ir.set(e,t)),e}var de=t=>ir.get(t);function gi(t,e,{blocked:r,upgrade:i,blocking:n,terminated:o}={}){let s=indexedDB.open(t,e),a=W(s);return i&&s.addEventListener("upgradeneeded",l=>{i(W(s.result),l.oldVersion,l.newVersion,W(s.transaction),l)}),r&&s.addEventListener("blocked",l=>r(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),n&&l.addEventListener("versionchange",u=>n(u.oldVersion,u.newVersion,u))}).catch(()=>{}),a}var Po=["get","getKey","getAll","getAllKeys","count"],Oo=["put","add","delete","clear"],nr=new Map;function mi(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(nr.get(e))return nr.get(e);let r=e.replace(/FromIndex$/,""),i=e!==r,n=Oo.includes(r);if(!(r in(i?IDBIndex:IDBObjectStore).prototype)||!(n||Po.includes(r)))return;let o=async function(s,...a){let l=this.transaction(s,n?"readwrite":"readonly"),u=l.store;return i&&(u=u.index(a.shift())),(await Promise.all([u[r](...a),n&&l.done]))[0]};return nr.set(e,o),o}yi(t=>({...t,get:(e,r,i)=>mi(e,r)||t.get(e,r,i),has:(e,r)=>!!mi(e,r)||t.has(e,r)}));var _i="auth-client-db",wi="ic-keyval",Ro=async(t=_i,e=wi,r)=>(pe&&(localStorage!=null&&localStorage.getItem(K))&&(localStorage.removeItem(K),localStorage.removeItem(M)),await gi(t,r,{upgrade:i=>{i.objectStoreNames.contains(e)&&i.clear(e),i.createObjectStore(e)}}));async function Bo(t,e,r){return await t.get(e,r)}async function Fo(t,e,r,i){return await t.put(e,i,r)}async function ko(t,e,r){return await t.delete(e,r)}var $t=class t{constructor(e,r){this._db=e,this._storeName=r}static async create(e){let{dbName:r=_i,storeName:i=wi,version:n=xi}=e??{},o=await Ro(r,i,n);return new t(o,i)}async set(e,r){return await Fo(this._db,this._storeName,e,r)}async get(e){var r;return(r=await Bo(this._db,this._storeName,e))!==null&&r!==void 0?r:null}async remove(e){return await ko(this._db,this._storeName,e)}};var Co=function(t,e,r,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(t,r):n?n.value=r:e.set(t,r),r},Uo=function(t,e,r,i){if(r==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?i:r==="a"?i.call(t):i?i.value:e.get(t)},fe,M="identity",K="delegation",bi="iv",xi=1,pe=typeof window<"u",qt=class{constructor(e="ic-",r){this.prefix=e,this._localStorage=r}get(e){return Promise.resolve(this._getLocalStorage().getItem(this.prefix+e))}set(e,r){return this._getLocalStorage().setItem(this.prefix+e,r),Promise.resolve()}remove(e){return this._getLocalStorage().removeItem(this.prefix+e),Promise.resolve()}_getLocalStorage(){if(this._localStorage)return this._localStorage;let e=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.localStorage:globalThis.localStorage:window.localStorage;if(!e)throw new Error("Could not find local storage.");return e}},Ht=class{constructor(e){fe.set(this,void 0),Co(this,fe,e??{},"f")}get _db(){return new Promise(e=>{if(this.initializedDb){e(this.initializedDb);return}$t.create(Uo(this,fe,"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)}};fe=new WeakMap;var Vo="https://identity.ic0.app",Ko="#authorize",or="ECDSA",sr="Ed25519",Mo=500,jo="UserInterrupt",he=class{constructor(e,r,i,n,o,s,a,l){this._identity=e,this._key=r,this._chain=i,this._storage=n,this.idleManager=o,this._createOptions=s,this._idpWindow=a,this._eventHandler=l,this._registerDefaultIdleCallback()}static async create(e={}){var r,i,n;let o=(r=e.storage)!==null&&r!==void 0?r:new Ht,s=(i=e.keyType)!==null&&i!==void 0?i:or,a=null;if(e.identity)a=e.identity;else{let d=await o.get(M);if(!d&&pe)try{let f=new qt,m=await f.get(K),w=await f.get(M);m&&w&&s===or&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await o.set(K,m),await o.set(M,w),d=m,await f.remove(K),await f.remove(M))}catch(f){console.error("error while attempting to recover localstorage: "+f)}if(d)try{typeof d=="object"?s===sr&&typeof d=="string"?a=await ut.fromJSON(d):a=await Ct.fromKeyPair(d):typeof d=="string"&&(a=ut.fromJSON(d))}catch{}}let l=new Ft,u=null;if(a)try{let d=await o.get(K);if(typeof d=="object"&&d!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?l=e.identity:d&&(u=Vt.fromJSON(d),ci(u)?"toDer"in a?l=Mt.fromDelegation(a,u):l=Kt.fromDelegation(a,u):(await ar(o),a=null))}catch(d){console.error(d),await ar(o),a=null}let p;return!((n=e.idleOptions)===null||n===void 0)&&n.disableIdle?p=void 0:(u||e.identity)&&(p=jt.create(e.idleOptions)),a||(s===sr?(a=await ut.generate(),await o.set(M,JSON.stringify(a.toJSON()))):(e.storage&&s===or&&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 '${sr}' as the key type, as it can serialize to a string`),a=await Ct.generate(),await o.set(M,a.getKeyPair()))),new this(l,a,u,o,p,e)}_registerDefaultIdleCallback(){var e,r;let i=(e=this._createOptions)===null||e===void 0?void 0:e.idleOptions;!i?.onIdle&&!i?.disableDefaultIdleCallback&&((r=this.idleManager)===null||r===void 0||r.registerCallback(()=>{this.logout(),location.reload()}))}async _handleSuccess(e,r){var i,n;let o=e.delegations.map(u=>({delegation:new Nt(u.delegation.pubkey,u.delegation.expiration,u.delegation.targets),signature:u.signature.buffer})),s=Vt.fromDelegations(o,e.userPublicKey.buffer),a=this._key;if(!a)return;this._chain=s,"toDer"in a?this._identity=Mt.fromDelegation(a,this._chain):this._identity=Kt.fromDelegation(a,this._chain),(i=this._idpWindow)===null||i===void 0||i.close();let l=(n=this._createOptions)===null||n===void 0?void 0:n.idleOptions;!this.idleManager&&!l?.disableIdle&&(this.idleManager=jt.create(l),this._registerDefaultIdleCallback()),this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(K,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,i,n,o;let s=BigInt(8)*BigInt(36e11),a=new URL(((r=e?.identityProvider)===null||r===void 0?void 0:r.toString())||Vo);a.hash=Ko,(i=this._idpWindow)===null||i===void 0||i.close(),this._removeEventListener(),this._eventHandler=this._getEventHandler(a,Object.assign({maxTimeToLive:(n=e?.maxTimeToLive)!==null&&n!==void 0?n: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(jo,e?.onError):setTimeout(l,Mo))};l()}_getEventHandler(e,r){return async i=>{var n,o,s;if(i.origin!==e.origin){console.warn(`WARNING: expected origin '${e.origin}', got '${i.origin}' (ignoring)`);return}let a=i.data;switch(a.kind){case"authorize-ready":{let l=Object.assign({kind:"authorize-client",sessionPublicKey:new Uint8Array((n=this._key)===null||n===void 0?void 0:n.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 i;(i=this._idpWindow)===null||i===void 0||i.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 ar(this._storage),this._identity=new Ft,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function ar(t){await t.remove(M),await t.remove(K),await t.remove(bi)}var ye=()=>he.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var Ei=async({data:t})=>{try{return await It(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var cr=async t=>{let{data:e,version:r,description:i}=t;return{description:P(i),data:await br(e),version:P(r)}},lr=t=>{let{version:e}=t;return{version:P(e)}},Wt=async({doc:t,key:e})=>{let{owner:r,version:i,description:n,data:o,...s}=t;return{key:e,description:T(n),owner:r.toText(),data:await It(o),version:T(i),...s}};var Ai=t=>{if(y(t))return P();switch(t.matcher){case"equal":return P({Equal:t.timestamp});case"greaterThan":return P({GreaterThan:t.timestamp});case"lessThan":return P({LessThan:t.timestamp});case"between":return P({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Error("Invalid list matcher for timestamp",t)}},rt=({matcher:t,paginate:e,order:r,owner:i})=>({matcher:y(t)?[]:[{key:P(t.key),description:P(t.description),created_at:Ai(t.createdAt),updated_at:Ai(t.updatedAt)}],paginate:P(y(e)?void 0:{start_after:P(e.startAfter),limit:P(y(e.limit)?void 0:BigInt(e.limit))}),order:P(y(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:P(y(i)?void 0:typeof i=="string"?g.fromText(i):i)});var Ti=({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}),i=t.Record({field:r,desc:t.Bool}),n=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(n),description:t.Opt(t.Text),created_at:t.Opt(n)}),s=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),a=t.Record({order:t.Opt(i),owner:t.Opt(t.Principal),matcher:t.Opt(o),paginate:t.Opt(s)}),l=t.Record({controllers:t.Vec(t.Principal)}),u=t.Variant({Write:t.Null,Admin:t.Null}),p=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:u,expires_at:t.Opt(t.Nat64)}),d=t.Record({version:t.Opt(t.Nat64)}),f=t.Variant({Db:t.Null,Storage:t.Null}),m=t.Record({version:t.Opt(t.Nat64)}),w=t.Record({cycles:t.Nat,destination_id:t.Principal}),h=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}),F=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),_=t.Record({key:h,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,F)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),b=t.Record({derivation_origin:t.Opt(t.Text)}),Y=t.Record({internet_identity:t.Opt(b)}),R=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),N=t.Record({max_memory_size:t.Opt(R)}),X=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),dt=t.Variant({Deny:t.Null,Allow:t.Null}),pt=t.Record({status_code:t.Nat16,location:t.Text}),U=t.Record({iframe:t.Opt(X),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(R),raw_access:t.Opt(dt),redirects:t.Opt(t.Vec(t.Tuple(t.Text,pt)))}),O=t.Record({db:t.Opt(N),authentication:t.Opt(Y),storage:U}),j=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),it=t.Variant({Heap:t.Null,Stable:t.Null}),Z=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),nt=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),Q=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(it),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:Z,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(nt),write:Z}),_e=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),St=t.Record({memory:it,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),we=t.Variant({Callback:t.Record({token:St,callback:t.Func([],[],["query"])})}),xe=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(we),status_code:t.Nat16}),be=t.Record({token:t.Opt(St),body:t.Vec(t.Nat8)}),Gt=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}),Pt=t.Record({batch_id:t.Nat}),Ee=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,_)),items_length:t.Nat64}),Yt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),Ot=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,j)),items_length:t.Nat64}),Ae=t.Record({stable:t.Nat64,heap:t.Nat64}),Te=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:u,expires_at:t.Opt(t.Nat64)}),ve=t.Record({controller:Te,controllers:t.Vec(t.Principal)}),zt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),Ne=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(it),max_size:t.Opt(t.Nat),read:Z,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(nt),write:Z}),Se=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Pe=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text,a],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,a],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([l],[t.Vec(t.Tuple(t.Principal,p))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,d],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,a],[],[]),del_filtered_docs:t.Func([t.Text,a],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,d))],[],[]),del_rule:t.Func([f,t.Text,m],[],[]),deposit_cycles:t.Func([w],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(_)],["query"]),get_auth_config:t.Func([],[t.Opt(Y)],["query"]),get_config:t.Func([],[O],[]),get_db_config:t.Func([],[t.Opt(N)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(j)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(_)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(j)))],["query"]),get_rule:t.Func([f,t.Text],[t.Opt(Q)],["query"]),get_storage_config:t.Func([],[U],["query"]),http_request:t.Func([_e],[xe],["query"]),http_request_streaming_callback:t.Func([St],[be],["query"]),init_asset_upload:t.Func([Gt],[Pt],[]),list_assets:t.Func([t.Text,a],[Ee],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,p))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Yt))],["query"]),list_docs:t.Func([t.Text,a],[Ot],["query"]),list_rules:t.Func([f],[t.Vec(t.Tuple(t.Text,Q))],["query"]),memory_size:t.Func([],[Ae],["query"]),set_auth_config:t.Func([Y],[],[]),set_controllers:t.Func([ve],[t.Vec(t.Tuple(t.Principal,p))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([N],[],[]),set_doc:t.Func([t.Text,t.Text,zt],[j],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,zt))],[t.Vec(t.Tuple(t.Text,j))],[]),set_rule:t.Func([f,t.Text,Ne],[Q],[]),set_storage_config:t.Func([U],[],[]),upload_asset_chunk:t.Func([Se],[Pe],[]),version:t.Func([],[t.Text],["query"])})};var vi=({satelliteId:t,container:e})=>{let{satelliteId:r}=ur({satelliteId:t}),{container:i}=dr({container:e});if(E(i)&&i!==!1){let{host:n,protocol:o}=new URL(i===!0?yt:i);return`${o}//${r??"unknown"}.${n.replace("127.0.0.1","localhost")}`}return`https://${r??"unknown"}.icp0.io`},ur=({satelliteId:t})=>E(t)?{satelliteId:t}:$.getInstance().get()??{satelliteId:void 0},dr=({container:t})=>E(t)?{container:t}:$.getInstance().get()??{container:void 0};var A=t=>Si({idlFactory:Ti,buildType:"stock",...t}),Ni=({idlFactory:t,...e})=>Si({idlFactory:t,buildType:"extended",...e}),Si=async({satelliteId:t,container:e,...r})=>{let{satelliteId:i}=ur({satelliteId:t});Qt(i,"No satellite ID defined. Did you initialize Juno?");let{container:n}=dr({container:e});return await Et.getInstance().getActor({satelliteId:i,container:n,...r})};var Pi=async({collection:t,key:e,satellite:r})=>{let{get_doc:i}=await A(r),n=T(await i(t,e));if(!y(n))return Wt({doc:n,key:e})},Oi=async({docs:t,satellite:e})=>{let{get_many_docs:r}=await A(e),i=t.map(({collection:s,key:a})=>[s,a]),n=await r(i),o=[];for(let[s,a]of n){let l=T(a);o.push(E(l)?await Wt({key:s,doc:l}):void 0)}return o},Ri=async({collection:t,doc:e,satellite:r})=>{let{set_doc:i}=await A(r),{key:n}=e,o=await cr(e),s=await i(t,n,o);return await Wt({key:n,doc:s})},Bi=async({docs:t,satellite:e})=>{let{set_many_docs:r}=await A(e),i=[];for(let{collection:s,doc:a}of t){let{key:l}=a;i.push([s,l,await cr(a)])}let n=await r(i),o=[];for(let[s,a]of n)o.push(await Wt({key:s,doc:a}));return o},Fi=async({collection:t,doc:e,satellite:r})=>{let{del_doc:i}=await A(r),{key:n}=e;return i(t,n,lr(e))},ki=async({docs:t,satellite:e})=>{let{del_many_docs:r}=await A(e),i=t.map(({collection:n,doc:o})=>[n,o.key,lr(o)]);await r(i)},Ci=async({collection:t,filter:e,satellite:r})=>{let{del_filtered_docs:i}=await A(r);return i(t,rt(e))},Ui=async({collection:t,filter:e,satellite:r})=>{let{list_docs:i}=await A(r),{items:n,items_page:o,items_length:s,matches_length:a,matches_pages:l}=await i(t,rt(e)),u=[];for(let[p,d]of n){let{data:f,owner:m,description:w,version:h,...F}=d;u.push({key:p,description:T(w),owner:m.toText(),data:await Ei({data:f}),version:T(h),...F})}return{items:u,items_length:s,items_page:T(o),matches_length:a,matches_pages:T(l)}},Vi=async({collection:t,filter:e,satellite:r})=>{let{count_docs:i}=await A(r);return i(t,rt(e))};var x=t=>t!==void 0?t:me()??new Ft;var Ki=async({satellite:t,...e})=>{let r=x(t?.identity);return await Pi({...e,satellite:{...t,identity:r}})},kc=async({satellite:t,...e})=>{let r=x(t?.identity);return await Oi({...e,satellite:{...t,identity:r}})},Mi=async({satellite:t,...e})=>{let r=x(t?.identity);return await Ri({...e,satellite:{...t,identity:r}})},Cc=async({satellite:t,...e})=>{let r=x(t?.identity);return await Bi({...e,satellite:{...t,identity:r}})},Uc=async({satellite:t,...e})=>{let r=x(t?.identity);return await Fi({...e,satellite:{...t,identity:r}})},Vc=async({satellite:t,...e})=>{let r=x(t?.identity);return await ki({...e,satellite:{...t,identity:r}})},Kc=async({satellite:t,filter:e,...r})=>{let i=x(t?.identity);return await Ci({...r,filter:e??{},satellite:{...t,identity:i}})},Mc=async({satellite:t,filter:e,...r})=>{let i=x(t?.identity);return await Ui({...r,filter:e??{},satellite:{...t,identity:i}})},jc=async({satellite:t,filter:e,...r})=>{let i=x(t?.identity);return await Vi({...r,filter:e??{},satellite:{...t,identity:i}})};var ji=async t=>{let e=me();if(y(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let r=e.getPrincipal().toText(),i=await Ki({collection:"#user",key:r});return y(i)?await $o({userId:r,provider:t}):i},$o=({userId:t,...e})=>Mi({collection:"#user",doc:{key:t,data:e}});var G,pr=async t=>{if(G=G??await ye(),!(await G?.isAuthenticated()??!1))return;let r=await ji(t);z.getInstance().set(r)},qo=t=>new Promise(async(e,r)=>{G=G??await ye();let i=t?.provider??new Dt({});await G.login({onSuccess:async()=>{await pr(i.id),e()},onError:n=>r(n),maxTimeToLive:t?.maxTimeToLive??Ar,allowPinAuthentication:t?.allowPin??Tr,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...i.signInOptions({windowed:t?.windowed})})}),fr=async()=>{await G?.logout(),G=void 0,z.getInstance().reset(),Et.getInstance().reset(),bt.getInstance().reset()},me=()=>G?.getIdentity(),Ho=async()=>(G??await ye()).getIdentity();var $i=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),i=async()=>{Me({message:"junoSignOutAuthTimer"}),await fr()};return r.onmessage=async({data:n})=>{let{msg:o,data:s}=n;switch(o){case"junoSignOutAuthTimer":await i();return;case"junoDelegationRemainingTime":Me({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},z.getInstance().subscribe(n=>{if(y(n)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var qi=()=>{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()},Hi=()=>{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 al=async({idlFactory:t,satellite:e})=>{let r=x(e?.identity);return await Ni({idlFactory:t,...e,identity:r})};var Wo=t=>t==null,Go=t=>!Wo(t),ge=t=>Go(t)?[t]:[],Yo=()=>typeof window<"u",Wi=async({asset:{data:t,filename:e,collection:r,headers:i,token:n,fullPath:o,encoding:s,description:a},actor:l,init_asset_upload:u})=>{let{batch_id:p}=await u({collection:r,full_path:o,name:e,token:ge(n),encoding_type:ge(s),description:ge(a)}),d=19e5,f=[],m=Yo()?new Blob([await t.arrayBuffer()]):t,w=0n;for(let _=0;_<m.size;_+=d){let b=m.slice(_,_+d);f.push({batchId:p,chunk:b,actor:l,orderId:w}),w++}let h=[];for await(let _ of zo({uploadChunks:f}))h=[...h,..._];let F=i.find(([_,b])=>_.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await l.commit_asset_upload({batch_id:p,chunk_ids:h.map(({chunk_id:_})=>_),headers:[...i,...F||[]]})};async function*zo({uploadChunks:t,limit:e=12}){for(let r=0;r<t.length;r=r+e){let i=t.slice(r,r+e);yield await Promise.all(i.map(n=>Jo(n)))}}var Jo=async({batchId:t,chunk:e,actor:r,orderId:i})=>r.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:ge(i)});var Gi=async({satellite:t,...e})=>{let r=await A(t);await Wi({actor:r,asset:e,init_asset_upload:async n=>await r.init_asset_upload(n)})},Yi=async({collection:t,satellite:e,filter:r})=>{let{list_assets:i}=await A(e),{items:n,items_length:o,items_page:s,matches_length:a,matches_pages:l}=await i(t,rt(r));return{items:n.map(([u,p])=>p),items_length:o,items_page:T(s),matches_length:a,matches_pages:T(l)}},zi=async({collection:t,satellite:e,filter:r})=>{let{count_assets:i}=await A(e);return i(t,rt(r))},Ji=async({collection:t,fullPath:e,satellite:r})=>(await A(r)).del_asset(t,e),Xi=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await A(e),i=t.map(({collection:n,fullPath:o})=>[n,o]);await r(i)},Zi=async({collection:t,satellite:e,filter:r})=>{let{del_filtered_assets:i}=await A(e);return i(t,rt(r))},Qi=async({collection:t,fullPath:e,satellite:r})=>{let{get_asset:i}=await A(r);return T(await i(t,e))},Ii=async({assets:t,satellite:e})=>{let{get_many_assets:r}=await A(e),i=t.map(({collection:o,fullPath:s})=>[o,s]);return(await r(i)).map(([o,s])=>T(s))};var Di=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Al=t=>Li(t),Tl=t=>Li({filename:t.data.name,...t}),Li=async({filename:t,data:e,collection:r,headers:i=[],fullPath:n,token:o,satellite:s,encoding:a,description:l})=>{let u=x(s?.identity),p=decodeURI(t),d=n??`/${r}/${p}`,f={...s,identity:u};return await Gi({data:e,filename:p,collection:r,token:o,headers:i,fullPath:d,encoding:a,satellite:f,description:l}),{downloadUrl:tn({satellite:f,assetKey:{fullPath:d,token:o}}),fullPath:d,name:p}},vl=async({collection:t,satellite:e,filter:r})=>{let i={...e,identity:x(e?.identity)},{items:n,...o}=await Yi({collection:t,satellite:i,filter:r??{}}),s=n.map(({key:{full_path:a,token:l,name:u,owner:p,description:d},headers:f,encodings:m,created_at:w,updated_at:h})=>{let F=T(l);return{fullPath:a,description:T(d),name:u,downloadUrl:tn({satellite:i,assetKey:{fullPath:a,token:F}}),token:F,headers:f,encodings:m.reduce((_,[b,{modified:Y,sha256:R,total_length:N}])=>({..._,[b]:{modified:Y,sha256:Di(R),total_length:N}}),{}),owner:p.toText(),created_at:w,updated_at:h}});return{items:s,assets:s,...o}},Nl=async({collection:t,satellite:e,filter:r})=>{let i={...e,identity:x(e?.identity)};return await zi({collection:t,satellite:i,filter:r??{}})},Sl=({collection:t,fullPath:e,satellite:r})=>Ji({collection:t,fullPath:e,satellite:{...r,identity:x(r?.identity)}}),Pl=({assets:t,satellite:e})=>Xi({assets:t,satellite:{...e,identity:x(e?.identity)}}),Ol=async({collection:t,satellite:e,filter:r})=>{let i={...e,identity:x(e?.identity)};return await Zi({collection:t,satellite:i,filter:r??{}})},Rl=async({satellite:t,...e})=>{let r=x(t?.identity);return await Qi({...e,satellite:{...t,identity:r}})},Bl=async({satellite:t,...e})=>{let r=x(t?.identity);return await Ii({...e,satellite:{...t,identity:r}})},tn=({assetKey:{fullPath:t,token:e},satellite:r})=>{let i={...r,identity:x(r?.identity)};return`${vi(i)}${t}${E(e)?`?token=${e}`:""}`};var Xo=t=>{let e=t?.satelliteId??qi();Qt(e,"Satellite ID is not configured. Juno cannot be initialized.");let r=t?.container??Hi();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:r}},jl=t=>Zo(t),Zo=async t=>{let e=Xo(t);$.getInstance().set(e),await pr();let r=e.workers?.auth!==void 0?$i(e.workers.auth):void 0;return[...r?[r]:[]]},$l=t=>z.getInstance().subscribe(t);export{Dt as InternetIdentityProvider,Or as NFIDProvider,$l as authSubscribe,Nl as countAssets,jc as countDocs,Sl as deleteAsset,Uc as deleteDoc,Ol as deleteFilteredAssets,Kc as deleteFilteredDocs,Pl as deleteManyAssets,Vc as deleteManyDocs,tn as downloadUrl,Rl as getAsset,Ki as getDoc,Bl as getManyAssets,kc as getManyDocs,al as getSatelliteExtendedActor,jl as initJuno,Zo as initSatellite,vl as listAssets,Mc as listDocs,Mi as setDoc,Cc as setManyDocs,qo as signIn,fr as signOut,Ho as unsafeIdentity,Al as uploadBlob,Tl as uploadFile};
16
16
  /*! Bundled license information:
17
17
 
18
18
  buffer/index.js: