@junobuild/core 0.0.40 → 0.0.42

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,27 +1,27 @@
1
- import{A as gr,a as An,b as Fo,c as ke,d as Tn,e as Bn,f as Sn,g as vn,h as On,i as B,j as ko,k as It,l as Rn,m as pe,n as qo,o as qe,p as K,q as bt,r as Pn,s as Nn,t as Pt,u as mr,v as Cn,w as Ie,x as he,y as ye,z as Un}from"./chunk-JJQEE5XI.js";var $n=An(je=>{"use strict";je.byteLength=Ho;je.toByteArray=$o;je.fromByteArray=Go;var dt=[],rt=[],Mo=typeof Uint8Array<"u"?Uint8Array:Array,Ar="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Kt=0,Hn=Ar.length;Kt<Hn;++Kt)dt[Kt]=Ar[Kt],rt[Ar.charCodeAt(Kt)]=Kt;var Kt,Hn;rt["-".charCodeAt(0)]=62;rt["_".charCodeAt(0)]=63;function jn(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 Ho(t){var e=jn(t),r=e[0],n=e[1];return(r+n)*3/4-n}function jo(t,e,r){return(e+r)*3/4-r}function $o(t){var e,r=jn(t),n=r[0],i=r[1],o=new Mo(jo(t,n,i)),s=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)e=rt[t.charCodeAt(c)]<<18|rt[t.charCodeAt(c+1)]<<12|rt[t.charCodeAt(c+2)]<<6|rt[t.charCodeAt(c+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=rt[t.charCodeAt(c)]<<2|rt[t.charCodeAt(c+1)]>>4,o[s++]=e&255),i===1&&(e=rt[t.charCodeAt(c)]<<10|rt[t.charCodeAt(c+1)]<<4|rt[t.charCodeAt(c+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Vo(t){return dt[t>>18&63]+dt[t>>12&63]+dt[t>>6&63]+dt[t&63]}function Wo(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(Vo(n));return i.join("")}function Go(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(Wo(t,s,s+o>a?a:s+o));return n===1?(e=t[r-1],i.push(dt[e>>2]+dt[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(dt[e>>10]+dt[e>>4&63]+dt[e<<2&63]+"=")),i.join("")}});var oi=An(Lt=>{"use strict";var Tr=$n(),Dt=ko(),Vn=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Lt.Buffer=d;Lt.SlowBuffer=Do;Lt.INSPECT_MAX_BYTES=50;var $e=2147483647;Lt.kMaxLength=$e;d.TYPED_ARRAY_SUPPORT=Yo();!d.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 Yo(){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(d.prototype,"parent",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.buffer}});Object.defineProperty(d.prototype,"offset",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.byteOffset}});function Et(t){if(t>$e)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,d.prototype),e}function d(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 Or(t)}return zn(t,e,r)}d.poolSize=8192;function zn(t,e,r){if(typeof t=="string")return Zo(t,e);if(ArrayBuffer.isView(t))return Jo(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(ft(t,ArrayBuffer)||t&&ft(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(ft(t,SharedArrayBuffer)||t&&ft(t.buffer,SharedArrayBuffer)))return Sr(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 d.from(n,e,r);let i=Xo(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return d.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)}d.from=function(t,e,r){return zn(t,e,r)};Object.setPrototypeOf(d.prototype,Uint8Array.prototype);Object.setPrototypeOf(d,Uint8Array);function Zn(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 zo(t,e,r){return Zn(t),t<=0?Et(t):e!==void 0?typeof r=="string"?Et(t).fill(e,r):Et(t).fill(e):Et(t)}d.alloc=function(t,e,r){return zo(t,e,r)};function Or(t){return Zn(t),Et(t<0?0:Rr(t)|0)}d.allocUnsafe=function(t){return Or(t)};d.allocUnsafeSlow=function(t){return Or(t)};function Zo(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!d.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=Jn(t,e)|0,n=Et(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function Br(t){let e=t.length<0?0:Rr(t.length)|0,r=Et(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Jo(t){if(ft(t,Uint8Array)){let e=new Uint8Array(t);return Sr(e.buffer,e.byteOffset,e.byteLength)}return Br(t)}function Sr(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,d.prototype),n}function Xo(t){if(d.isBuffer(t)){let e=Rr(t.length)|0,r=Et(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||Nr(t.length)?Et(0):Br(t);if(t.type==="Buffer"&&Array.isArray(t.data))return Br(t.data)}function Rr(t){if(t>=$e)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+$e.toString(16)+" bytes");return t|0}function Do(t){return+t!=t&&(t=0),d.alloc(+t)}d.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==d.prototype};d.compare=function(e,r){if(ft(e,Uint8Array)&&(e=d.from(e,e.offset,e.byteLength)),ft(r,Uint8Array)&&(r=d.from(r,r.offset,r.byteLength)),!d.isBuffer(e)||!d.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};d.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}};d.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return d.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=d.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let s=e[n];if(ft(s,Uint8Array))o+s.length>i.length?(d.isBuffer(s)||(s=d.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(d.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Jn(t,e){if(d.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||ft(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 vr(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return ii(t).length;default:if(i)return n?-1:vr(t).length;e=(""+e).toLowerCase(),i=!0}}d.byteLength=Jn;function Qo(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 cs(this,e,r);case"utf8":case"utf-8":return Dn(this,e,r);case"ascii":return ss(this,e,r);case"latin1":case"binary":return as(this,e,r);case"base64":return is(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ls(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}d.prototype._isBuffer=!0;function Mt(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}d.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)Mt(this,r,r+1);return this};d.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)Mt(this,r,r+3),Mt(this,r+1,r+2);return this};d.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)Mt(this,r,r+7),Mt(this,r+1,r+6),Mt(this,r+2,r+5),Mt(this,r+3,r+4);return this};d.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Dn(this,0,e):Qo.apply(this,arguments)};d.prototype.toLocaleString=d.prototype.toString;d.prototype.equals=function(e){if(!d.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:d.compare(this,e)===0};d.prototype.inspect=function(){let e="",r=Lt.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};Vn&&(d.prototype[Vn]=d.prototype.inspect);d.prototype.compare=function(e,r,n,i,o){if(ft(e,Uint8Array)&&(e=d.from(e,e.offset,e.byteLength)),!d.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,c=Math.min(s,a),l=this.slice(i,o),u=e.slice(r,n);for(let f=0;f<c;++f)if(l[f]!==u[f]){s=l[f],a=u[f];break}return s<a?-1:a<s?1:0};function Xn(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,Nr(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=d.from(e,n)),d.isBuffer(e))return e.length===0?-1:Wn(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):Wn(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Wn(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 c(u,f){return o===1?u[f]:u.readUInt16BE(f*o)}let l;if(i){let u=-1;for(l=r;l<s;l++)if(c(t,l)===c(e,u===-1?0:l-u)){if(u===-1&&(u=l),l-u+1===a)return u*o}else u!==-1&&(l-=l-u),u=-1}else for(r+a>s&&(r=s-a),l=r;l>=0;l--){let u=!0;for(let f=0;f<a;f++)if(c(t,l+f)!==c(e,f)){u=!1;break}if(u)return l}return-1}d.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};d.prototype.indexOf=function(e,r,n){return Xn(this,e,r,n,!0)};d.prototype.lastIndexOf=function(e,r,n){return Xn(this,e,r,n,!1)};function Lo(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(Nr(a))return s;t[r+s]=a}return s}function ts(t,e,r,n){return Ve(vr(e,t.length-r),t,r,n)}function es(t,e,r,n){return Ve(ps(e),t,r,n)}function rs(t,e,r,n){return Ve(ii(e),t,r,n)}function ns(t,e,r,n){return Ve(hs(e,t.length-r),t,r,n)}d.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 Lo(this,e,r,n);case"utf8":case"utf-8":return ts(this,e,r,n);case"ascii":case"latin1":case"binary":return es(this,e,r,n);case"base64":return rs(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ns(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function is(t,e,r){return e===0&&r===t.length?Tr.fromByteArray(t):Tr.fromByteArray(t.slice(e,r))}function Dn(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 c,l,u,f;switch(a){case 1:o<128&&(s=o);break;case 2:c=t[i+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(s=f));break;case 3:c=t[i+1],l=t[i+2],(c&192)===128&&(l&192)===128&&(f=(o&15)<<12|(c&63)<<6|l&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:c=t[i+1],l=t[i+2],u=t[i+3],(c&192)===128&&(l&192)===128&&(u&192)===128&&(f=(o&15)<<18|(c&63)<<12|(l&63)<<6|u&63,f>65535&&f<1114112&&(s=f))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return os(n)}var Gn=4096;function os(t){let e=t.length;if(e<=Gn)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Gn));return r}function ss(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 as(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 cs(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+=ys[t[o]];return i}function ls(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}d.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,d.prototype),i};function M(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")}d.prototype.readUintLE=d.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||M(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return i};d.prototype.readUintBE=d.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||M(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};d.prototype.readUint8=d.prototype.readUInt8=function(e,r){return e=e>>>0,r||M(e,1,this.length),this[e]};d.prototype.readUint16LE=d.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||M(e,2,this.length),this[e]|this[e+1]<<8};d.prototype.readUint16BE=d.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||M(e,2,this.length),this[e]<<8|this[e+1]};d.prototype.readUint32LE=d.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||M(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};d.prototype.readUint32BE=d.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||M(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};d.prototype.readBigUInt64LE=Ct(function(e){e=e>>>0,Qt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&me(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))});d.prototype.readBigUInt64BE=Ct(function(e){e=e>>>0,Qt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&me(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)});d.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||M(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};d.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||M(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};d.prototype.readInt8=function(e,r){return e=e>>>0,r||M(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};d.prototype.readInt16LE=function(e,r){e=e>>>0,r||M(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};d.prototype.readInt16BE=function(e,r){e=e>>>0,r||M(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};d.prototype.readInt32LE=function(e,r){return e=e>>>0,r||M(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};d.prototype.readInt32BE=function(e,r){return e=e>>>0,r||M(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};d.prototype.readBigInt64LE=Ct(function(e){e=e>>>0,Qt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&me(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)});d.prototype.readBigInt64BE=Ct(function(e){e=e>>>0,Qt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&me(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)});d.prototype.readFloatLE=function(e,r){return e=e>>>0,r||M(e,4,this.length),Dt.read(this,e,!0,23,4)};d.prototype.readFloatBE=function(e,r){return e=e>>>0,r||M(e,4,this.length),Dt.read(this,e,!1,23,4)};d.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||M(e,8,this.length),Dt.read(this,e,!0,52,8)};d.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||M(e,8,this.length),Dt.read(this,e,!1,52,8)};function Q(t,e,r,n,i,o){if(!d.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")}d.prototype.writeUintLE=d.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;Q(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};d.prototype.writeUintBE=d.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;Q(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};d.prototype.writeUint8=d.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,1,255,0),this[r]=e&255,r+1};d.prototype.writeUint16LE=d.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};d.prototype.writeUint16BE=d.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};d.prototype.writeUint32LE=d.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||Q(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};d.prototype.writeUint32BE=d.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||Q(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 Qn(t,e,r,n,i){ni(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 Ln(t,e,r,n,i){ni(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}d.prototype.writeBigUInt64LE=Ct(function(e,r=0){return Qn(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});d.prototype.writeBigUInt64BE=Ct(function(e,r=0){return Ln(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});d.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let c=Math.pow(2,8*n-1);Q(this,e,r,n,c-1,-c)}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};d.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let c=Math.pow(2,8*n-1);Q(this,e,r,n,c-1,-c)}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};d.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};d.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};d.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};d.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||Q(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};d.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||Q(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};d.prototype.writeBigInt64LE=Ct(function(e,r=0){return Qn(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});d.prototype.writeBigInt64BE=Ct(function(e,r=0){return Ln(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function ti(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 ei(t,e,r,n,i){return e=+e,r=r>>>0,i||ti(t,e,r,4,34028234663852886e22,-34028234663852886e22),Dt.write(t,e,r,n,23,4),r+4}d.prototype.writeFloatLE=function(e,r,n){return ei(this,e,r,!0,n)};d.prototype.writeFloatBE=function(e,r,n){return ei(this,e,r,!1,n)};function ri(t,e,r,n,i){return e=+e,r=r>>>0,i||ti(t,e,r,8,17976931348623157e292,-17976931348623157e292),Dt.write(t,e,r,n,52,8),r+8}d.prototype.writeDoubleLE=function(e,r,n){return ri(this,e,r,!0,n)};d.prototype.writeDoubleBE=function(e,r,n){return ri(this,e,r,!1,n)};d.prototype.copy=function(e,r,n,i){if(!d.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};d.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"&&!d.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=d.isBuffer(e)?e:d.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 Xt={};function Pr(t,e,r){Xt[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}`}}}Pr("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Pr("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);Pr("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=Yn(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=Yn(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Yn(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 us(t,e,r){Qt(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&me(e,t.length-(r+1))}function ni(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 Xt.ERR_OUT_OF_RANGE("value",a,t)}us(n,i,o)}function Qt(t,e){if(typeof t!="number")throw new Xt.ERR_INVALID_ARG_TYPE(e,"number",t)}function me(t,e,r){throw Math.floor(t)!==t?(Qt(t,r),new Xt.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new Xt.ERR_BUFFER_OUT_OF_BOUNDS:new Xt.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var ds=/[^+/0-9A-Za-z-_]/g;function fs(t){if(t=t.split("=")[0],t=t.trim().replace(ds,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function vr(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 ps(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function hs(t,e){let r,n,i,o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function ii(t){return Tr.toByteArray(fs(t))}function Ve(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 ft(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Nr(t){return t!==t}var ys=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 Ct(t){return typeof BigInt>"u"?ms:t}function ms(){throw new Error("BigInt not supported")}});var j=t=>t==null,Nt=t=>!j(t);var wr="__bigint__",xr="__principal__",br="__uint8array__",Io=(t,e)=>typeof e=="bigint"?{[wr]:`${e}`}:Nt(e)&&e instanceof B?{[xr]:e.toText()}:Nt(e)&&e instanceof Uint8Array?{[br]:Array.from(e)}:e,Ko=(t,e)=>{let r=n=>e[n];return Nt(e)&&typeof e=="object"&&wr in e?BigInt(r(wr)):Nt(e)&&typeof e=="object"&&xr in e?B.fromText(r(xr)):Nt(e)&&typeof e=="object"&&br in e?Uint8Array.from(r(br)):e},$=t=>Nt(t)?[t]:[],X=t=>t?.[0],Fn=async t=>{let e=new Blob([JSON.stringify(t,Io)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},Ke=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(),Ko)},Me=()=>typeof window<"u";var Jt=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 _t=class t extends Jt{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 _r=({message:t,detail:e})=>{let r=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(r)};var kn=BigInt(144e11),qn={width:576,height:576},In={width:505,height:705},Kn="internetcomputer.org";var D=class t extends Jt{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}localIdentity(){return this.get()?.localIdentityCanisterId!==void 0}subscribe(e){let r=super.subscribe(e);return e(this.env),r}};var Er=({width:t,height:e})=>{if(!Me()||j(window)||j(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 He=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let r=D.getInstance().localIdentity()?`http://${D.getInstance().get()?.localIdentityCanisterId}.localhost:8000`:`https://identity.${this.#t??Kn}`;return{...e!==!1&&{windowOpenerFeatures:Er(qn)},identityProvider:r}}},Mn=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:Er(In)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};var Vi=ke(oi());var We;(function(t){t[t.SysFatal=1]="SysFatal",t[t.SysTransient=2]="SysTransient",t[t.DestinationInvalid=3]="DestinationInvalid",t[t.CanisterReject=4]="CanisterReject",t[t.CanisterError=5]="CanisterError"})(We||(We={}));var gs=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},ws=new TextEncoder().encode(`
2
- ic-request`),At=class{getPrincipal(){return this._principal||(this._principal=B.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:r}=e,n=gs(e,["body"]),i=await Pt(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(qe(ws,i))}})}},Tt=class{getPrincipal(){return B.anonymous()}async transformRequest(e){return Object.assign(Object.assign({},e),{body:{content:e.body}})}};var si=ke(Cn());var ge=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){let t=new Uint32Array(1);return window.crypto.getRandomValues(t),t[0]}if(typeof crypto<"u"&&crypto.getRandomValues){let t=new Uint32Array(1);return crypto.getRandomValues(t),t[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var Ge;(function(t){t.Call="call"})(Ge||(Ge={}));function te(){let t=new ArrayBuffer(16),e=new DataView(t),r=ge(),n=ge(),i=ge(),o=ge();return e.setUint32(0,r),e.setUint32(4,n),e.setUint32(8,i),e.setUint32(12,o),t}var xs=BigInt(1e6),bs=60*1e3,Ht=class{constructor(e){let o=BigInt(Math.floor(Date.now()+e-bs))*xs/BigInt(1e9)/BigInt(60)*BigInt(60)*BigInt(1e9);this._value=o}toCBOR(){return si.value.u64(this._value.toString(16),16)}toHash(){return Rn(this._value)}};function Cr(t=te){return async e=>{let r=e.request.headers;e.request.headers=r,e.endpoint==="call"&&(e.body.nonce=t())}}function Ye(t){let e=[];return t.forEach((r,n)=>{e.push([n,r])}),e}var ze=class extends Error{constructor(e,r){super(e),this.response=r,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}};var Ze=BigInt(4294967295),Ur=BigInt(32);function ai(t,e=!1){return e?{h:Number(t&Ze),l:Number(t>>Ur&Ze)}:{h:Number(t>>Ur&Ze)|0,l:Number(t&Ze)|0}}function _s(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){let{h:o,l:s}=ai(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]}var Es=(t,e)=>BigInt(t>>>0)<<Ur|BigInt(e>>>0),As=(t,e,r)=>t>>>r,Ts=(t,e,r)=>t<<32-r|e>>>r,Bs=(t,e,r)=>t>>>r|e<<32-r,Ss=(t,e,r)=>t<<32-r|e>>>r,vs=(t,e,r)=>t<<64-r|e>>>r-32,Os=(t,e,r)=>t>>>r-32|e<<64-r,Rs=(t,e)=>e,Ps=(t,e)=>t,Ns=(t,e,r)=>t<<r|e>>>32-r,Cs=(t,e,r)=>e<<r|t>>>32-r,Us=(t,e,r)=>e<<r-32|t>>>64-r,Fs=(t,e,r)=>t<<r-32|e>>>64-r;function ks(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var qs=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Is=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ks=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ms=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,Hs=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),js=(t,e,r,n,i,o)=>e+r+n+i+o+(t/2**32|0)|0;var $s={fromBig:ai,split:_s,toBig:Es,shrSH:As,shrSL:Ts,rotrSH:Bs,rotrSL:Ss,rotrBH:vs,rotrBL:Os,rotr32H:Rs,rotr32L:Ps,rotlSH:Ns,rotlSL:Cs,rotlBH:Us,rotlBL:Fs,add:ks,add3L:qs,add3H:Is,add4L:Ks,add4H:Ms,add5H:js,add5L:Hs},_=$s;var[Vs,Ws]=(()=>_.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))))(),Ut=new Uint32Array(80),Ft=new Uint32Array(80),Fr=class extends On{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:r,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:h,Gh:y,Gl:g,Hh:w,Hl:A}=this;return[e,r,n,i,o,s,a,c,l,u,f,h,y,g,w,A]}set(e,r,n,i,o,s,a,c,l,u,f,h,y,g,w,A){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=y|0,this.Gl=g|0,this.Hh=w|0,this.Hl=A|0}process(e,r){for(let T=0;T<16;T++,r+=4)Ut[T]=e.getUint32(r),Ft[T]=e.getUint32(r+=4);for(let T=16;T<80;T++){let k=Ut[T-15]|0,E=Ft[T-15]|0,it=_.rotrSH(k,E,1)^_.rotrSH(k,E,8)^_.shrSH(k,E,7),vt=_.rotrSL(k,E,1)^_.rotrSL(k,E,8)^_.shrSL(k,E,7),G=Ut[T-2]|0,Y=Ft[T-2]|0,gt=_.rotrSH(G,Y,19)^_.rotrBH(G,Y,61)^_.shrSH(G,Y,6),lt=_.rotrSL(G,Y,19)^_.rotrBL(G,Y,61)^_.shrSL(G,Y,6),Ot=_.add4L(vt,lt,Ft[T-7],Ft[T-16]),wt=_.add4H(Ot,it,gt,Ut[T-7],Ut[T-16]);Ut[T]=wt|0,Ft[T]=Ot|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:y,Fl:g,Gh:w,Gl:A,Hh:S,Hl:N}=this;for(let T=0;T<80;T++){let k=_.rotrSH(f,h,14)^_.rotrSH(f,h,18)^_.rotrBH(f,h,41),E=_.rotrSL(f,h,14)^_.rotrSL(f,h,18)^_.rotrBL(f,h,41),it=f&y^~f&w,vt=h&g^~h&A,G=_.add5L(N,E,vt,Ws[T],Ft[T]),Y=_.add5H(G,S,k,it,Vs[T],Ut[T]),gt=G|0,lt=_.rotrSH(n,i,28)^_.rotrBH(n,i,34)^_.rotrBH(n,i,39),Ot=_.rotrSL(n,i,28)^_.rotrBL(n,i,34)^_.rotrBL(n,i,39),wt=n&o^n&a^o&a,fe=i&s^i&c^s&c;S=w|0,N=A|0,w=y|0,A=g|0,y=f|0,g=h|0,{h:f,l:h}=_.add(l|0,u|0,Y|0,gt|0),l=a|0,u=c|0,a=o|0,c=s|0,o=n|0,s=i|0;let zt=_.add3L(gt,Ot,fe);n=_.add3H(zt,Y,lt,wt),i=zt|0}({h:n,l:i}=_.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=_.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:c}=_.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=_.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=_.add(this.Eh|0,this.El|0,f|0,h|0),{h:y,l:g}=_.add(this.Fh|0,this.Fl|0,y|0,g|0),{h:w,l:A}=_.add(this.Gh|0,this.Gl|0,w|0,A|0),{h:S,l:N}=_.add(this.Hh|0,this.Hl|0,S|0,N|0),this.set(n,i,o,s,a,c,l,u,f,h,y,g,w,A,S,N)}roundClean(){Ut.fill(0),Ft.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var kr=Sn(()=>new Fr);var Vc=BigInt(0),Gs=BigInt(1),Ys=BigInt(2);function we(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var zs=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Je(t){if(!we(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=zs[t[r]];return e}function li(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}var Bt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function ci(t){if(t>=Bt._0&&t<=Bt._9)return t-Bt._0;if(t>=Bt._A&&t<=Bt._F)return t-(Bt._A-10);if(t>=Bt._a&&t<=Bt._f)return t-(Bt._a-10)}function ui(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=ci(t.charCodeAt(o)),a=ci(t.charCodeAt(o+1));if(s===void 0||a===void 0){let c=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[i]=s*16+a}return n}function di(t){return li(Je(t))}function ee(t){if(!we(t))throw new Error("Uint8Array expected");return li(Je(Uint8Array.from(t).reverse()))}function qr(t,e){return ui(t.toString(16).padStart(e*2,"0"))}function xe(t,e){return qr(t,e).reverse()}function pt(t,e,r){let n;if(typeof e=="string")try{n=ui(e)}catch(o){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${o}`)}else if(we(e))n=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(`${t} expected ${r} bytes, got ${i}`);return n}function Ir(...t){let e=0;for(let i=0;i<t.length;i++){let o=t[i];if(!we(o))throw new Error("Uint8Array expected");e+=o.length}let r=new Uint8Array(e),n=0;for(let i=0;i<t.length;i++){let o=t[i];r.set(o,n),n+=o.length}return r}var fi=t=>(Ys<<BigInt(t-1))-Gs;var Zs={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||we(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function re(t,e,r={}){let n=(i,o,s)=>{let a=Zs[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=t[i];if(!(s&&c===void 0)&&!a(c,t))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(r))n(i,o,!0);return t}var I=BigInt(0),F=BigInt(1),jt=BigInt(2),Xs=BigInt(3),Kr=BigInt(4),pi=BigInt(5),hi=BigInt(8),Ds=BigInt(9),Qs=BigInt(16);function q(t,e){let r=t%e;return r>=I?r:e+r}function Ls(t,e,r){if(r<=I||e<I)throw new Error("Expected power/modulo > 0");if(r===F)return I;let n=F;for(;e>I;)e&F&&(n=n*t%r),t=t*t%r,e>>=F;return n}function ot(t,e,r){let n=t;for(;e-- >I;)n*=n,n%=r;return n}function yi(t,e){if(t===I||e<=I)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=q(t,e),n=e,i=I,o=F,s=F,a=I;for(;r!==I;){let l=n/r,u=n%r,f=i-s*l,h=o-a*l;n=r,r=u,i=s,o=a,s=f,a=h}if(n!==F)throw new Error("invert: does not exist");return q(i,e)}function ta(t){let e=(t-F)/jt,r,n,i;for(r=t-F,n=0;r%jt===I;r/=jt,n++);for(i=jt;i<t&&Ls(i,e,t)!==t-F;i++);if(n===1){let s=(t+F)/Kr;return function(c,l){let u=c.pow(l,s);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let o=(r+F)/jt;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,i),r),f=a.pow(c,o),h=a.pow(c,r);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let y=1;for(let w=a.sqr(h);y<l&&!a.eql(w,a.ONE);y++)w=a.sqr(w);let g=a.pow(u,F<<BigInt(l-y-1));u=a.sqr(g),f=a.mul(f,g),h=a.mul(h,u),l=y}return f}}function ea(t){if(t%Kr===Xs){let e=(t+F)/Kr;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(t%hi===pi){let e=(t-pi)/hi;return function(n,i){let o=n.mul(i,jt),s=n.pow(o,e),a=n.mul(i,s),c=n.mul(n.mul(a,jt),s),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),i))throw new Error("Cannot find square root");return l}}return t%Qs,ta(t)}var mi=(t,e)=>(q(t,e)&F)===F,ra=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function gi(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=ra.reduce((n,i)=>(n[i]="function",n),e);return re(t,r)}function na(t,e,r){if(r<I)throw new Error("Expected power > 0");if(r===I)return t.ONE;if(r===F)return e;let n=t.ONE,i=e;for(;r>I;)r&F&&(n=t.mul(n,i)),i=t.sqr(i),r>>=F;return n}function ia(t,e){let r=new Array(e.length),n=e.reduce((o,s,a)=>t.is0(s)?o:(r[a]=o,t.mul(o,s)),t.ONE),i=t.inv(n);return e.reduceRight((o,s,a)=>t.is0(s)?o:(r[a]=t.mul(o,r[a]),t.mul(o,s)),i),r}function Mr(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function wi(t,e,r=!1,n={}){if(t<=I)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:i,nByteLength:o}=Mr(t,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=ea(t),a=Object.freeze({ORDER:t,BITS:i,BYTES:o,MASK:fi(i),ZERO:I,ONE:F,create:c=>q(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return I<=c&&c<t},is0:c=>c===I,isOdd:c=>(c&F)===F,neg:c=>q(-c,t),eql:(c,l)=>c===l,sqr:c=>q(c*c,t),add:(c,l)=>q(c+l,t),sub:(c,l)=>q(c-l,t),mul:(c,l)=>q(c*l,t),pow:(c,l)=>na(a,c,l),div:(c,l)=>q(c*yi(l,t),t),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>yi(c,t),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>ia(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>r?xe(c,o):qr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return r?ee(c):di(c)}});return Object.freeze(a)}function xi(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}var oa=BigInt(0),Hr=BigInt(1);function bi(t,e){let r=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:r,unsafeLadder(i,o){let s=t.ZERO,a=i;for(;o>oa;)o&Hr&&(s=s.add(a)),a=a.double(),o>>=Hr;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),c=[],l=i,u=l;for(let f=0;f<s;f++){u=l,c.push(u);for(let h=1;h<a;h++)u=u.add(l),c.push(u);l=u.double()}return c},wNAF(i,o,s){let{windows:a,windowSize:c}=n(i),l=t.ZERO,u=t.BASE,f=BigInt(2**i-1),h=2**i,y=BigInt(i);for(let g=0;g<a;g++){let w=g*c,A=Number(s&f);s>>=y,A>c&&(A-=h,s+=Hr);let S=w,N=w+Math.abs(A)-1,T=g%2!==0,k=A<0;A===0?u=u.add(r(T,o[S])):l=l.add(r(k,o[N]))}return{p:l,f:u}},wNAFCached(i,o,s,a){let c=i._WINDOW_SIZE||1,l=o.get(i);return l||(l=this.precomputeWindow(i,c),c!==1&&o.set(i,a(l))),this.wNAF(c,l,s)}}}function _i(t){return gi(t.Fp),re(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Mr(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var st=BigInt(0),L=BigInt(1),Xe=BigInt(2),sa=BigInt(8),aa={zip215:!0};function ca(t){let e=_i(t);return re(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function De(t){let e=ca(t),{Fp:r,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:c}=e,l=Xe<<BigInt(a*8)-L,u=r.create,f=e.uvRatio||((m,p)=>{try{return{isValid:!0,value:r.sqrt(m*r.inv(p))}}catch{return{isValid:!1,value:st}}}),h=e.adjustScalarBytes||(m=>m),y=e.domain||((m,p,x)=>{if(p.length||x)throw new Error("Contexts/pre-hash are not supported");return m}),g=m=>typeof m=="bigint"&&st<m,w=(m,p)=>g(m)&&g(p)&&m<p,A=m=>m===st||w(m,l);function S(m,p){if(w(m,p))return m;throw new Error(`Expected valid scalar < ${p}, got ${typeof m} ${m}`)}function N(m){return m===st?m:S(m,n)}let T=new Map;function k(m){if(!(m instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(p,x,b,v){if(this.ex=p,this.ey=x,this.ez=b,this.et=v,!A(p))throw new Error("x required");if(!A(x))throw new Error("y required");if(!A(b))throw new Error("z required");if(!A(v))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof E)throw new Error("extended point not allowed");let{x,y:b}=p||{};if(!A(x)||!A(b))throw new Error("invalid affine point");return new E(x,b,L,u(x*b))}static normalizeZ(p){let x=r.invertBatch(p.map(b=>b.ez));return p.map((b,v)=>b.toAffine(x[v])).map(E.fromAffine)}_setWindowSize(p){this._WINDOW_SIZE=p,T.delete(this)}assertValidity(){let{a:p,d:x}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:b,ey:v,ez:O,et:R}=this,U=u(b*b),P=u(v*v),C=u(O*O),V=u(C*C),Z=u(U*p),ut=u(C*u(Z+P)),J=u(V+u(x*u(U*P)));if(ut!==J)throw new Error("bad point: equation left != right (1)");let Rt=u(b*v),xt=u(O*R);if(Rt!==xt)throw new Error("bad point: equation left != right (2)")}equals(p){k(p);let{ex:x,ey:b,ez:v}=this,{ex:O,ey:R,ez:U}=p,P=u(x*U),C=u(O*v),V=u(b*U),Z=u(R*v);return P===C&&V===Z}is0(){return this.equals(E.ZERO)}negate(){return new E(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=e,{ex:x,ey:b,ez:v}=this,O=u(x*x),R=u(b*b),U=u(Xe*u(v*v)),P=u(p*O),C=x+b,V=u(u(C*C)-O-R),Z=P+R,ut=Z-U,J=P-R,Rt=u(V*ut),xt=u(Z*J),Ue=u(V*J),Fe=u(ut*Z);return new E(Rt,xt,Fe,Ue)}add(p){k(p);let{a:x,d:b}=e,{ex:v,ey:O,ez:R,et:U}=this,{ex:P,ey:C,ez:V,et:Z}=p;if(x===BigInt(-1)){let mn=u((O-v)*(C+P)),gn=u((O+v)*(C-P)),yr=u(gn-mn);if(yr===st)return this.double();let wn=u(R*Xe*Z),xn=u(U*Xe*V),bn=xn+wn,_n=gn+mn,En=xn-wn,Po=u(bn*yr),No=u(_n*En),Co=u(bn*En),Uo=u(yr*_n);return new E(Po,No,Uo,Co)}let ut=u(v*P),J=u(O*C),Rt=u(U*b*Z),xt=u(R*V),Ue=u((v+O)*(P+C)-ut-J),Fe=xt-Rt,hn=xt+Rt,yn=u(J-x*ut),So=u(Ue*Fe),vo=u(hn*yn),Oo=u(Ue*yn),Ro=u(Fe*hn);return new E(So,vo,Ro,Oo)}subtract(p){return this.add(p.negate())}wNAF(p){return G.wNAFCached(this,T,p,E.normalizeZ)}multiply(p){let{p:x,f:b}=this.wNAF(S(p,n));return E.normalizeZ([x,b])[0]}multiplyUnsafe(p){let x=N(p);return x===st?vt:this.equals(vt)||x===L?this:this.equals(it)?this.wNAF(x).p:G.unsafeLadder(this,x)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return G.unsafeLadder(this,n).is0()}toAffine(p){let{ex:x,ey:b,ez:v}=this,O=this.is0();p==null&&(p=O?sa:r.inv(v));let R=u(x*p),U=u(b*p),P=u(v*p);if(O)return{x:st,y:L};if(P!==L)throw new Error("invZ was invalid");return{x:R,y:U}}clearCofactor(){let{h:p}=e;return p===L?this:this.multiplyUnsafe(p)}static fromHex(p,x=!1){let{d:b,a:v}=e,O=r.BYTES;p=pt("pointHex",p,O);let R=p.slice(),U=p[O-1];R[O-1]=U&-129;let P=ee(R);P===st||(x?S(P,l):S(P,r.ORDER));let C=u(P*P),V=u(C-L),Z=u(b*C-v),{isValid:ut,value:J}=f(V,Z);if(!ut)throw new Error("Point.fromHex: invalid y coordinate");let Rt=(J&L)===L,xt=(U&128)!==0;if(!x&&J===st&&xt)throw new Error("Point.fromHex: x=0 and x_0=1");return xt!==Rt&&(J=u(-J)),E.fromAffine({x:J,y:P})}static fromPrivateKey(p){return lt(p).point}toRawBytes(){let{x:p,y:x}=this.toAffine(),b=xe(x,r.BYTES);return b[b.length-1]|=p&L?128:0,b}toHex(){return Je(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,L,u(e.Gx*e.Gy)),E.ZERO=new E(st,L,L,st);let{BASE:it,ZERO:vt}=E,G=bi(E,a*8);function Y(m){return q(m,n)}function gt(m){return Y(ee(m))}function lt(m){let p=a;m=pt("private key",m,p);let x=pt("hashed private key",o(m),2*p),b=h(x.slice(0,p)),v=x.slice(p,2*p),O=gt(b),R=it.multiply(O),U=R.toRawBytes();return{head:b,prefix:v,scalar:O,point:R,pointBytes:U}}function Ot(m){return lt(m).pointBytes}function wt(m=new Uint8Array,...p){let x=Ir(...p);return gt(o(y(x,pt("context",m),!!i)))}function fe(m,p,x={}){m=pt("message",m),i&&(m=i(m));let{prefix:b,scalar:v,pointBytes:O}=lt(p),R=wt(x.context,b,m),U=it.multiply(R).toRawBytes(),P=wt(x.context,U,O,m),C=Y(R+P*v);N(C);let V=Ir(U,xe(C,r.BYTES));return pt("result",V,a*2)}let zt=aa;function Zt(m,p,x,b=zt){let{context:v,zip215:O}=b,R=r.BYTES;m=pt("signature",m,2*R),p=pt("message",p),i&&(p=i(p));let U=ee(m.slice(R,2*R)),P,C,V;try{P=E.fromHex(x,O),C=E.fromHex(m.slice(0,R),O),V=it.multiplyUnsafe(U)}catch{return!1}if(!O&&P.isSmallOrder())return!1;let Z=wt(v,C.toRawBytes(),P.toRawBytes(),p);return C.add(P.multiplyUnsafe(Z)).subtract(V).clearCofactor().equals(E.ZERO)}return it._setWindowSize(8),{CURVE:e,getPublicKey:Ot,sign:fe,verify:Zt,ExtendedPoint:E,utils:{getExtendedPublicKey:lt,randomPrivateKey:()=>s(r.BYTES),precompute(m=8,p=E.BASE){return p._setWindowSize(m),p.multiply(BigInt(3)),p}}}}var $r=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ei=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),nl=BigInt(0),la=BigInt(1),jr=BigInt(2),ua=BigInt(5),Ai=BigInt(10),da=BigInt(20),fa=BigInt(40),Ti=BigInt(80);function pa(t){let e=$r,n=t*t%e*t%e,i=ot(n,jr,e)*n%e,o=ot(i,la,e)*t%e,s=ot(o,ua,e)*o%e,a=ot(s,Ai,e)*s%e,c=ot(a,da,e)*a%e,l=ot(c,fa,e)*c%e,u=ot(l,Ti,e)*l%e,f=ot(u,Ti,e)*l%e,h=ot(f,Ai,e)*s%e;return{pow_p_5_8:ot(h,jr,e)*t%e,b2:n}}function ha(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function ya(t,e){let r=$r,n=q(e*e*e,r),i=q(n*n*e,r),o=pa(t*i).pow_p_5_8,s=q(t*n*o,r),a=q(e*s*s,r),c=s,l=q(s*Ei,r),u=a===t,f=a===q(-t,r),h=a===q(-t*Ei,r);return u&&(s=c),(f||h)&&(s=l),mi(s,r)&&(s=q(-s,r)),{isValid:u||f,value:s}}var St=wi($r,void 0,!0),Vr={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:St,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:kr,randomBytes:vn,adjustScalarBytes:ha,uvRatio:ya},kt=De(Vr);function Bi(t,e,r){if(e.length>255)throw new Error("Context is too big");return Bn(Tn("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}var il=De({...Vr,domain:Bi}),ol=De({...Vr,domain:Bi,prehash:kr});var ma=(St.ORDER+BigInt(3))/BigInt(8),sl=St.pow(jr,ma),al=St.sqrt(St.neg(St.ONE)),cl=(St.ORDER-BigInt(5))/BigInt(8),ll=BigInt(486662);var ul=xi(St,St.neg(BigInt(486664)));var dl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),fl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),pl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),hl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var yl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Si=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},z=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)},W,be,vi,Oi,Qe=class{constructor(e={}){W.set(this,void 0),be.set(this,void 0),this[vi]=this.entries.bind(this),this[Oi]="ExpirableMap";let{source:r=[],expirationTime:n=10*60*1e3}=e,i=Date.now();Si(this,W,new Map([...r].map(([o,s])=>[o,{value:s,timestamp:i}])),"f"),Si(this,be,n,"f")}prune(){let e=Date.now();for(let[r,n]of z(this,W,"f").entries())e-n.timestamp>z(this,be,"f")&&z(this,W,"f").delete(r);return this}set(e,r){this.prune();let n={value:r,timestamp:Date.now()};return z(this,W,"f").set(e,n),this}get(e){let r=z(this,W,"f").get(e);if(r!==void 0){if(Date.now()-r.timestamp>z(this,be,"f")){z(this,W,"f").delete(e);return}return r.value}}clear(){z(this,W,"f").clear()}entries(){let e=z(this,W,"f").entries();return function*(){for(let[n,i]of e)yield[n,i.value]}()}values(){let e=z(this,W,"f").values();return function*(){for(let n of e)yield n.value}()}keys(){return z(this,W,"f").keys()}forEach(e,r){for(let[n,i]of z(this,W,"f").entries())e.call(r,i.value,n,this)}has(e){return z(this,W,"f").has(e)}delete(e){return z(this,W,"f").delete(e)}get size(){return z(this,W,"f").size}};W=new WeakMap,be=new WeakMap,vi=Symbol.iterator,Oi=Symbol.toStringTag;var Ri=t=>{if(t<=127)return 1;if(t<=255)return 2;if(t<=65535)return 3;if(t<=16777215)return 4;throw new Error("Length too long (> 4 bytes)")},Pi=(t,e,r)=>{if(r<=127)return t[e]=r,1;if(r<=255)return t[e]=129,t[e+1]=r,2;if(r<=65535)return t[e]=130,t[e+1]=r>>8,t[e+2]=r,3;if(r<=16777215)return t[e]=131,t[e+1]=r>>16,t[e+2]=r>>8,t[e+3]=r,4;throw new Error("Length too long (> 4 bytes)")},Wr=(t,e)=>{if(t[e]<128)return 1;if(t[e]===128)throw new Error("Invalid length 0");if(t[e]===129)return 2;if(t[e]===130)return 3;if(t[e]===131)return 4;throw new Error("Length too long (> 4 bytes)")},ga=(t,e)=>{let r=Wr(t,e);if(r===1)return t[e];if(r===2)return t[e+1];if(r===3)return(t[e+1]<<8)+t[e+2];if(r===4)return(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];throw new Error("Length too long (> 4 bytes)")},Ni=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),$t=Uint8Array.from([48,5,6,3,43,101,112]),xl=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);function ne(t,e){let r=2+Ri(t.byteLength+1),n=e.byteLength+r+t.byteLength,i=0,o=new Uint8Array(1+Ri(n)+n);return o[i++]=48,i+=Pi(o,i,n),o.set(e,i),i+=e.byteLength,o[i++]=3,i+=Pi(o,i,t.byteLength+1),o[i++]=0,o.set(new Uint8Array(t),i),o}var _e=(t,e)=>{let r=0,n=(a,c)=>{if(i[r++]!==a)throw new Error("Expected: "+c)},i=new Uint8Array(t);if(n(48,"sequence"),r+=Wr(i,r),!Pn(i.slice(r,r+e.byteLength),e))throw new Error("Not the expected OID.");r+=e.byteLength,n(3,"bit string");let o=ga(i,r)-1;r+=Wr(i,r),n(0,"0 padding");let s=i.slice(r);if(o!==s.length)throw new Error(`DER payload mismatch: Expected length ${o} actual length ${s.length}`);return s};var Ci=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},Ui=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)},Le,tr,Ee=class t{constructor(e){if(Le.set(this,void 0),tr.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");Ci(this,Le,e,"f"),Ci(this,tr,t.derEncode(e),"f")}static from(e){return this.fromDer(e.toDer())}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static derEncode(e){return ne(e,$t).buffer}static derDecode(e){let r=_e(e,$t);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}get rawKey(){return Ui(this,Le,"f")}get derKey(){return Ui(this,tr,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};Le=new WeakMap,tr=new WeakMap;Ee.RAW_KEY_LENGTH=32;var xa=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},H=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)},ie,oe,Vt,se,rr,ht;(function(t){t.Received="received",t.Processing="processing",t.Replied="replied",t.Rejected="rejected",t.Unknown="unknown",t.Done="done"})(ht||(ht={}));var er=5*60*1e3,ba="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae",_a="ic0.app",Ea=".ic0.app",Aa="icp0.io",Ta=".icp0.io",Ba="icp-api.io",Sa=".icp-api.io",Ae=class extends It{constructor(e){super(e),this.message=e}},ae=class extends It{constructor(e){super(e),this.message=e}};function va(){let t;if(typeof window<"u")if(window.fetch)t=window.fetch.bind(window);else throw new Ae("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present.");else if(typeof globalThis<"u")if(globalThis.fetch)t=globalThis.fetch.bind(globalThis);else throw new Ae("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available.");else typeof self<"u"&&self.fetch&&(t=self.fetch.bind(self));if(t)return t;throw new Ae("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context.")}var Te=class t{constructor(e={}){if(this.rootKey=bt(ba),this._timeDiffMsecs=0,this._rootKeyFetched=!1,this._isAgent=!0,ie.set(this,[]),oe.set(this,[]),Vt.set(this,new Qe({expirationTime:5*60*1e3})),se.set(this,!0),rr.set(this,(r,n)=>{if(H(this,se,"f")===!1)return r;if(!n)throw new ye("Invalid signature from replica signed query: no matching node key found.");let{status:i,signatures:o=[],requestId:s}=r,a=new TextEncoder().encode("\vic-response");for(let c of o){let{timestamp:l,identity:u}=c,f=B.fromUint8Array(u).toText(),h;if(i==="replied"){let{reply:S}=r;h=mr({status:i,reply:S,timestamp:BigInt(l),request_id:s})}else if(i==="rejected"){let{reject_code:S,reject_message:N,error_code:T}=r;h=mr({status:i,reject_code:S,reject_message:N,error_code:T,timestamp:BigInt(l),request_id:s})}else throw new Error(`Unknown status: ${i}`);let y=qe(a,new Uint8Array(h)),g=n?.nodeKeys.get(f);if(!g)throw new ye("Invalid signature from replica signed query: no matching node key found.");let w=Ee.fromDer(g).rawKey;if(kt.verify(c.signature,new Uint8Array(y),new Uint8Array(w)))return r;throw new ye(`Invalid signature from replica ${f} signed query.`)}return r}),e.source){if(!(e.source instanceof t))throw new Error("An Agent's source can only be another HttpAgent");this._identity=e.source._identity,this._fetch=e.source._fetch,this._host=e.source._host,this._credentials=e.source._credentials}else this._fetch=e.fetch||va()||fetch.bind(globalThis),this._fetchOptions=e.fetchOptions,this._callOptions=e.callOptions;if(e.host!==void 0)!e.host.match(/^[a-z]+:/)&&typeof window<"u"?this._host=new URL(window.location.protocol+"//"+e.host):this._host=new URL(e.host);else if(e.source!==void 0)this._host=e.source._host;else{let r=typeof window<"u"?window.location:void 0;r||(this._host=new URL("https://icp-api.io"),console.warn("Could not infer host from window.location, defaulting to mainnet gateway of https://icp-api.io. Please provide a host to the HttpAgent constructor to avoid this warning."));let n=["ic0.app","icp0.io","127.0.0.1","localhost"],i=r?.hostname,o;i&&typeof i=="string"&&(o=n.find(s=>i.endsWith(s))),r&&o?this._host=new URL(`${r.protocol}//${o}${r.port?":"+r.port:""}`):(this._host=new URL("https://icp-api.io"),console.warn("Could not infer host from window.location, defaulting to mainnet gateway of https://icp-api.io. Please provide a host to the HttpAgent constructor to avoid this warning."))}if(e.verifyQuerySignatures!==void 0&&xa(this,se,e.verifyQuerySignatures,"f"),this._retryTimes=e.retryTimes!==void 0&&e.retryTimes>=0?e.retryTimes:3,this._host.hostname.endsWith(Ea)?this._host.hostname=_a:this._host.hostname.endsWith(Ta)?this._host.hostname=Aa:this._host.hostname.endsWith(Sa)&&(this._host.hostname=Ba),e.credentials){let{name:r,password:n}=e.credentials;this._credentials=`${r}${n?":"+n:""}`}this._identity=Promise.resolve(e.identity||new Tt),this.addTransform("update",Cr(te)),e.useQueryNonces&&this.addTransform("query",Cr(te))}isLocal(){let e=this._host.hostname;return e==="127.0.0.1"||e.endsWith("127.0.0.1")}addTransform(e,r,n=r.priority||0){if(e==="update"){let i=H(this,oe,"f").findIndex(o=>(o.priority||0)<n);H(this,oe,"f").splice(i>=0?i:H(this,oe,"f").length,0,Object.assign(r,{priority:n}))}else if(e==="query"){let i=H(this,ie,"f").findIndex(o=>(o.priority||0)<n);H(this,ie,"f").splice(i>=0?i:H(this,ie,"f").length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!this._identity)throw new ae("This identity has expired due this application's security policy. Please refresh your authentication.");return(await this._identity).getPrincipal()}async call(e,r,n){let i=await(n!==void 0?await n:await this._identity);if(!i)throw new ae("This identity has expired due this application's security policy. Please refresh your authentication.");let o=B.from(e),s=r.effectiveCanisterId?B.from(r.effectiveCanisterId):o,a=i.getPrincipal()||B.anonymous(),c=new Ht(er);Math.abs(this._timeDiffMsecs)>1e3*30&&(c=new Ht(er+this._timeDiffMsecs));let l={request_type:Ge.Call,canister_id:o,method_name:r.methodName,arg:r.arg,sender:a,ingress_expiry:c},u=await this._transform({request:{body:null,method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{})},endpoint:"call",body:l});u=await i.transformRequest(u);let f=Ie(u.body),h=this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${s.toText()}/call`,this._host),Object.assign(Object.assign(Object.assign({},this._callOptions),u.request),{body:f}))),[y,g]=await Promise.all([h,Pt(l)]),w=await y.arrayBuffer(),A=y.status===200&&w.byteLength>0?he(w):null;return{requestId:g,response:{ok:y.ok,status:y.status,statusText:y.statusText,body:A,headers:Ye(y.headers)}}}async _requestAndRetry(e,r=0){let n;try{n=await e()}catch(s){if(this._retryTimes>r)return console.warn(`Caught exception while attempting to make request:
1
+ import{A as wr,a as Tn,b as Io,c as Ie,d as Bn,e as Sn,f as vn,g as On,h as Rn,i as B,j as qo,k as qt,l as Nn,m as he,n as Ko,o as qe,p as H,q as bt,r as Pn,s as Cn,t as Pt,u as gr,v as Un,w as Ke,x as ye,y as me,z as Fn}from"./chunk-JJQEE5XI.js";var Wn=Tn($e=>{"use strict";$e.byteLength=$o;$e.toByteArray=Wo;$e.fromByteArray=zo;var ft=[],nt=[],jo=typeof Uint8Array<"u"?Uint8Array:Array,Tr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Kt=0,$n=Tr.length;Kt<$n;++Kt)ft[Kt]=Tr[Kt],nt[Tr.charCodeAt(Kt)]=Kt;var Kt,$n;nt["-".charCodeAt(0)]=62;nt["_".charCodeAt(0)]=63;function Vn(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 $o(t){var e=Vn(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Vo(t,e,r){return(e+r)*3/4-r}function Wo(t){var e,r=Vn(t),n=r[0],i=r[1],o=new jo(Vo(t,n,i)),s=0,a=i>0?n-4:n,c;for(c=0;c<a;c+=4)e=nt[t.charCodeAt(c)]<<18|nt[t.charCodeAt(c+1)]<<12|nt[t.charCodeAt(c+2)]<<6|nt[t.charCodeAt(c+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=nt[t.charCodeAt(c)]<<2|nt[t.charCodeAt(c+1)]>>4,o[s++]=e&255),i===1&&(e=nt[t.charCodeAt(c)]<<10|nt[t.charCodeAt(c+1)]<<4|nt[t.charCodeAt(c+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function Go(t){return ft[t>>18&63]+ft[t>>12&63]+ft[t>>6&63]+ft[t&63]}function Yo(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(Go(n));return i.join("")}function zo(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,a=r-n;s<a;s+=o)i.push(Yo(t,s,s+o>a?a:s+o));return n===1?(e=t[r-1],i.push(ft[e>>2]+ft[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(ft[e>>10]+ft[e>>4&63]+ft[e<<2&63]+"=")),i.join("")}});var ai=Tn(te=>{"use strict";var Br=Wn(),Qt=qo(),Gn=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;te.Buffer=d;te.SlowBuffer=Lo;te.INSPECT_MAX_BYTES=50;var Ve=2147483647;te.kMaxLength=Ve;d.TYPED_ARRAY_SUPPORT=Zo();!d.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 Zo(){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(d.prototype,"parent",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.buffer}});Object.defineProperty(d.prototype,"offset",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.byteOffset}});function At(t){if(t>Ve)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,d.prototype),e}function d(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 Rr(t)}return Jn(t,e,r)}d.poolSize=8192;function Jn(t,e,r){if(typeof t=="string")return Do(t,e);if(ArrayBuffer.isView(t))return Xo(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(pt(t,ArrayBuffer)||t&&pt(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(pt(t,SharedArrayBuffer)||t&&pt(t.buffer,SharedArrayBuffer)))return vr(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 d.from(n,e,r);let i=Qo(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return d.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)}d.from=function(t,e,r){return Jn(t,e,r)};Object.setPrototypeOf(d.prototype,Uint8Array.prototype);Object.setPrototypeOf(d,Uint8Array);function Dn(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 Jo(t,e,r){return Dn(t),t<=0?At(t):e!==void 0?typeof r=="string"?At(t).fill(e,r):At(t).fill(e):At(t)}d.alloc=function(t,e,r){return Jo(t,e,r)};function Rr(t){return Dn(t),At(t<0?0:Nr(t)|0)}d.allocUnsafe=function(t){return Rr(t)};d.allocUnsafeSlow=function(t){return Rr(t)};function Do(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!d.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=Xn(t,e)|0,n=At(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function Sr(t){let e=t.length<0?0:Nr(t.length)|0,r=At(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Xo(t){if(pt(t,Uint8Array)){let e=new Uint8Array(t);return vr(e.buffer,e.byteOffset,e.byteLength)}return Sr(t)}function vr(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,d.prototype),n}function Qo(t){if(d.isBuffer(t)){let e=Nr(t.length)|0,r=At(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||Cr(t.length)?At(0):Sr(t);if(t.type==="Buffer"&&Array.isArray(t.data))return Sr(t.data)}function Nr(t){if(t>=Ve)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ve.toString(16)+" bytes");return t|0}function Lo(t){return+t!=t&&(t=0),d.alloc(+t)}d.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==d.prototype};d.compare=function(e,r){if(pt(e,Uint8Array)&&(e=d.from(e,e.offset,e.byteLength)),pt(r,Uint8Array)&&(r=d.from(r,r.offset,r.byteLength)),!d.isBuffer(e)||!d.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};d.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}};d.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return d.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=d.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let s=e[n];if(pt(s,Uint8Array))o+s.length>i.length?(d.isBuffer(s)||(s=d.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(d.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Xn(t,e){if(d.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||pt(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 Or(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return si(t).length;default:if(i)return n?-1:Or(t).length;e=(""+e).toLowerCase(),i=!0}}d.byteLength=Xn;function ts(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 us(this,e,r);case"utf8":case"utf-8":return Ln(this,e,r);case"ascii":return cs(this,e,r);case"latin1":case"binary":return ls(this,e,r);case"base64":return ss(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ds(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}d.prototype._isBuffer=!0;function Mt(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}d.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)Mt(this,r,r+1);return this};d.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)Mt(this,r,r+3),Mt(this,r+1,r+2);return this};d.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)Mt(this,r,r+7),Mt(this,r+1,r+6),Mt(this,r+2,r+5),Mt(this,r+3,r+4);return this};d.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Ln(this,0,e):ts.apply(this,arguments)};d.prototype.toLocaleString=d.prototype.toString;d.prototype.equals=function(e){if(!d.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:d.compare(this,e)===0};d.prototype.inspect=function(){let e="",r=te.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};Gn&&(d.prototype[Gn]=d.prototype.inspect);d.prototype.compare=function(e,r,n,i,o){if(pt(e,Uint8Array)&&(e=d.from(e,e.offset,e.byteLength)),!d.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,c=Math.min(s,a),l=this.slice(i,o),u=e.slice(r,n);for(let f=0;f<c;++f)if(l[f]!==u[f]){s=l[f],a=u[f];break}return s<a?-1:a<s?1:0};function Qn(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,Cr(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=d.from(e,n)),d.isBuffer(e))return e.length===0?-1:Yn(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):Yn(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Yn(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 c(u,f){return o===1?u[f]:u.readUInt16BE(f*o)}let l;if(i){let u=-1;for(l=r;l<s;l++)if(c(t,l)===c(e,u===-1?0:l-u)){if(u===-1&&(u=l),l-u+1===a)return u*o}else u!==-1&&(l-=l-u),u=-1}else for(r+a>s&&(r=s-a),l=r;l>=0;l--){let u=!0;for(let f=0;f<a;f++)if(c(t,l+f)!==c(e,f)){u=!1;break}if(u)return l}return-1}d.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};d.prototype.indexOf=function(e,r,n){return Qn(this,e,r,n,!0)};d.prototype.lastIndexOf=function(e,r,n){return Qn(this,e,r,n,!1)};function es(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(Cr(a))return s;t[r+s]=a}return s}function rs(t,e,r,n){return We(Or(e,t.length-r),t,r,n)}function ns(t,e,r,n){return We(ys(e),t,r,n)}function is(t,e,r,n){return We(si(e),t,r,n)}function os(t,e,r,n){return We(ms(e,t.length-r),t,r,n)}d.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 es(this,e,r,n);case"utf8":case"utf-8":return rs(this,e,r,n);case"ascii":case"latin1":case"binary":return ns(this,e,r,n);case"base64":return is(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return os(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ss(t,e,r){return e===0&&r===t.length?Br.fromByteArray(t):Br.fromByteArray(t.slice(e,r))}function Ln(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 c,l,u,f;switch(a){case 1:o<128&&(s=o);break;case 2:c=t[i+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(s=f));break;case 3:c=t[i+1],l=t[i+2],(c&192)===128&&(l&192)===128&&(f=(o&15)<<12|(c&63)<<6|l&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:c=t[i+1],l=t[i+2],u=t[i+3],(c&192)===128&&(l&192)===128&&(u&192)===128&&(f=(o&15)<<18|(c&63)<<12|(l&63)<<6|u&63,f>65535&&f<1114112&&(s=f))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return as(n)}var zn=4096;function as(t){let e=t.length;if(e<=zn)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=zn));return r}function cs(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 ls(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 us(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+=gs[t[o]];return i}function ds(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}d.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,d.prototype),i};function j(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")}d.prototype.readUintLE=d.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||j(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return i};d.prototype.readUintBE=d.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||j(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};d.prototype.readUint8=d.prototype.readUInt8=function(e,r){return e=e>>>0,r||j(e,1,this.length),this[e]};d.prototype.readUint16LE=d.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||j(e,2,this.length),this[e]|this[e+1]<<8};d.prototype.readUint16BE=d.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||j(e,2,this.length),this[e]<<8|this[e+1]};d.prototype.readUint32LE=d.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||j(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};d.prototype.readUint32BE=d.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||j(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};d.prototype.readBigUInt64LE=Ct(function(e){e=e>>>0,Lt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&ge(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))});d.prototype.readBigUInt64BE=Ct(function(e){e=e>>>0,Lt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&ge(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)});d.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||j(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};d.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||j(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};d.prototype.readInt8=function(e,r){return e=e>>>0,r||j(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};d.prototype.readInt16LE=function(e,r){e=e>>>0,r||j(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};d.prototype.readInt16BE=function(e,r){e=e>>>0,r||j(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};d.prototype.readInt32LE=function(e,r){return e=e>>>0,r||j(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};d.prototype.readInt32BE=function(e,r){return e=e>>>0,r||j(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};d.prototype.readBigInt64LE=Ct(function(e){e=e>>>0,Lt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&ge(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)});d.prototype.readBigInt64BE=Ct(function(e){e=e>>>0,Lt(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&ge(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)});d.prototype.readFloatLE=function(e,r){return e=e>>>0,r||j(e,4,this.length),Qt.read(this,e,!0,23,4)};d.prototype.readFloatBE=function(e,r){return e=e>>>0,r||j(e,4,this.length),Qt.read(this,e,!1,23,4)};d.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||j(e,8,this.length),Qt.read(this,e,!0,52,8)};d.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||j(e,8,this.length),Qt.read(this,e,!1,52,8)};function Q(t,e,r,n,i,o){if(!d.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")}d.prototype.writeUintLE=d.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;Q(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};d.prototype.writeUintBE=d.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;Q(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};d.prototype.writeUint8=d.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,1,255,0),this[r]=e&255,r+1};d.prototype.writeUint16LE=d.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};d.prototype.writeUint16BE=d.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};d.prototype.writeUint32LE=d.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||Q(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};d.prototype.writeUint32BE=d.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||Q(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 ti(t,e,r,n,i){oi(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 ei(t,e,r,n,i){oi(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}d.prototype.writeBigUInt64LE=Ct(function(e,r=0){return ti(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});d.prototype.writeBigUInt64BE=Ct(function(e,r=0){return ei(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});d.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let c=Math.pow(2,8*n-1);Q(this,e,r,n,c-1,-c)}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};d.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let c=Math.pow(2,8*n-1);Q(this,e,r,n,c-1,-c)}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};d.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};d.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};d.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||Q(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};d.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||Q(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};d.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||Q(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};d.prototype.writeBigInt64LE=Ct(function(e,r=0){return ti(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});d.prototype.writeBigInt64BE=Ct(function(e,r=0){return ei(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function ri(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 ni(t,e,r,n,i){return e=+e,r=r>>>0,i||ri(t,e,r,4,34028234663852886e22,-34028234663852886e22),Qt.write(t,e,r,n,23,4),r+4}d.prototype.writeFloatLE=function(e,r,n){return ni(this,e,r,!0,n)};d.prototype.writeFloatBE=function(e,r,n){return ni(this,e,r,!1,n)};function ii(t,e,r,n,i){return e=+e,r=r>>>0,i||ri(t,e,r,8,17976931348623157e292,-17976931348623157e292),Qt.write(t,e,r,n,52,8),r+8}d.prototype.writeDoubleLE=function(e,r,n){return ii(this,e,r,!0,n)};d.prototype.writeDoubleBE=function(e,r,n){return ii(this,e,r,!1,n)};d.prototype.copy=function(e,r,n,i){if(!d.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};d.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"&&!d.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=d.isBuffer(e)?e:d.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 Xt={};function Pr(t,e,r){Xt[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}`}}}Pr("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Pr("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);Pr("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=Zn(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=Zn(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Zn(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 fs(t,e,r){Lt(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&ge(e,t.length-(r+1))}function oi(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 Xt.ERR_OUT_OF_RANGE("value",a,t)}fs(n,i,o)}function Lt(t,e){if(typeof t!="number")throw new Xt.ERR_INVALID_ARG_TYPE(e,"number",t)}function ge(t,e,r){throw Math.floor(t)!==t?(Lt(t,r),new Xt.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new Xt.ERR_BUFFER_OUT_OF_BOUNDS:new Xt.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var ps=/[^+/0-9A-Za-z-_]/g;function hs(t){if(t=t.split("=")[0],t=t.trim().replace(ps,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function Or(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 ys(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function ms(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 si(t){return Br.toByteArray(hs(t))}function We(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 pt(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Cr(t){return t!==t}var gs=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 Ct(t){return typeof BigInt>"u"?ws:t}function ws(){throw new Error("BigInt not supported")}});var K=t=>t==null,q=t=>!K(t);var xr="__bigint__",_r="__principal__",br="__uint8array__",Mo=(t,e)=>typeof e=="bigint"?{[xr]:`${e}`}:q(e)&&e instanceof B?{[_r]:e.toText()}:q(e)&&e instanceof Uint8Array?{[br]:Array.from(e)}:e,Ho=(t,e)=>{let r=n=>e[n];return q(e)&&typeof e=="object"&&xr in e?BigInt(r(xr)):q(e)&&typeof e=="object"&&_r in e?B.fromText(r(_r)):q(e)&&typeof e=="object"&&br in e?Uint8Array.from(r(br)):e},V=t=>q(t)?[t]:[],X=t=>t?.[0],kn=async t=>{let e=new Blob([JSON.stringify(t,Mo)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},Me=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(),Ho)},He=()=>typeof window<"u";var Jt=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 Et=class t extends Jt{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 Er=({message:t,detail:e})=>{let r=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(r)};var In=BigInt(144e11),qn={width:576,height:576},Kn={width:505,height:705},Mn="internetcomputer.org";var Dt="http://127.0.0.1:5987",Hn="rdmx6-jaaaa-aaaaa-aaadq-cai";var L=class t extends Jt{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 Ar=({width:t,height:e})=>{if(!He()||K(window)||K(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 je=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let r=()=>{let n=L.getInstance().get()?.container;if(K(n)||n===!1)return`https://identity.${this.#t??Mn}`;let i=L.getInstance().get(),o=q(i)&&q(i?.internetIdentityId)?i.internetIdentityId:Hn,{host:s,protocol:a}=new URL(n===!0?Dt:n);return/apple/i.test(navigator?.vendor)?`${a}//${s}?canisterId=${o}`:`${a}//${o}.${s.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:Ar(qn)},identityProvider:r()}}},jn=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:Ar(Kn)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};var Gi=Ie(ai());var Ge;(function(t){t[t.SysFatal=1]="SysFatal",t[t.SysTransient=2]="SysTransient",t[t.DestinationInvalid=3]="DestinationInvalid",t[t.CanisterReject=4]="CanisterReject",t[t.CanisterError=5]="CanisterError"})(Ge||(Ge={}));var xs=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},_s=new TextEncoder().encode(`
2
+ ic-request`),Tt=class{getPrincipal(){return this._principal||(this._principal=B.selfAuthenticating(new Uint8Array(this.getPublicKey().toDer()))),this._principal}async transformRequest(e){let{body:r}=e,n=xs(e,["body"]),i=await Pt(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_pubkey:this.getPublicKey().toDer(),sender_sig:await this.sign(qe(_s,i))}})}},Bt=class{getPrincipal(){return B.anonymous()}async transformRequest(e){return Object.assign(Object.assign({},e),{body:{content:e.body}})}};var ci=Ie(Un());var we=()=>{if(typeof window<"u"&&window.crypto&&window.crypto.getRandomValues){let t=new Uint32Array(1);return window.crypto.getRandomValues(t),t[0]}if(typeof crypto<"u"&&crypto.getRandomValues){let t=new Uint32Array(1);return crypto.getRandomValues(t),t[0]}return typeof crypto<"u"&&crypto.randomInt?crypto.randomInt(0,4294967295):Math.floor(Math.random()*4294967295)};var Ye;(function(t){t.Call="call"})(Ye||(Ye={}));function ee(){let t=new ArrayBuffer(16),e=new DataView(t),r=we(),n=we(),i=we(),o=we();return e.setUint32(0,r),e.setUint32(4,n),e.setUint32(8,i),e.setUint32(12,o),t}var bs=BigInt(1e6),Es=60*1e3,Ht=class{constructor(e){let o=BigInt(Math.floor(Date.now()+e-Es))*bs/BigInt(1e9)/BigInt(60)*BigInt(60)*BigInt(1e9);this._value=o}toCBOR(){return ci.value.u64(this._value.toString(16),16)}toHash(){return Nn(this._value)}};function Ur(t=ee){return async e=>{let r=e.request.headers;e.request.headers=r,e.endpoint==="call"&&(e.body.nonce=t())}}function ze(t){let e=[];return t.forEach((r,n)=>{e.push([n,r])}),e}var Ze=class extends Error{constructor(e,r){super(e),this.response=r,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}};var Je=BigInt(4294967295),Fr=BigInt(32);function li(t,e=!1){return e?{h:Number(t&Je),l:Number(t>>Fr&Je)}:{h:Number(t>>Fr&Je)|0,l:Number(t&Je)|0}}function As(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){let{h:o,l:s}=li(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]}var Ts=(t,e)=>BigInt(t>>>0)<<Fr|BigInt(e>>>0),Bs=(t,e,r)=>t>>>r,Ss=(t,e,r)=>t<<32-r|e>>>r,vs=(t,e,r)=>t>>>r|e<<32-r,Os=(t,e,r)=>t<<32-r|e>>>r,Rs=(t,e,r)=>t<<64-r|e>>>r-32,Ns=(t,e,r)=>t>>>r-32|e<<64-r,Ps=(t,e)=>e,Cs=(t,e)=>t,Us=(t,e,r)=>t<<r|e>>>32-r,Fs=(t,e,r)=>e<<r|t>>>32-r,ks=(t,e,r)=>e<<r-32|t>>>64-r,Is=(t,e,r)=>t<<r-32|e>>>64-r;function qs(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var Ks=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ms=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Hs=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),js=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,$s=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),Vs=(t,e,r,n,i,o)=>e+r+n+i+o+(t/2**32|0)|0;var Ws={fromBig:li,split:As,toBig:Ts,shrSH:Bs,shrSL:Ss,rotrSH:vs,rotrSL:Os,rotrBH:Rs,rotrBL:Ns,rotr32H:Ps,rotr32L:Cs,rotlSH:Us,rotlSL:Fs,rotlBH:ks,rotlBL:Is,add:qs,add3L:Ks,add3H:Ms,add4L:Hs,add4H:js,add5H:Vs,add5L:$s},b=Ws;var[Gs,Ys]=(()=>b.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))))(),Ut=new Uint32Array(80),Ft=new Uint32Array(80),kr=class extends Rn{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:r,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:h,Gh:y,Gl:g,Hh:w,Hl:A}=this;return[e,r,n,i,o,s,a,c,l,u,f,h,y,g,w,A]}set(e,r,n,i,o,s,a,c,l,u,f,h,y,g,w,A){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=y|0,this.Gl=g|0,this.Hh=w|0,this.Hl=A|0}process(e,r){for(let T=0;T<16;T++,r+=4)Ut[T]=e.getUint32(r),Ft[T]=e.getUint32(r+=4);for(let T=16;T<80;T++){let k=Ut[T-15]|0,E=Ft[T-15]|0,ot=b.rotrSH(k,E,1)^b.rotrSH(k,E,8)^b.shrSH(k,E,7),Ot=b.rotrSL(k,E,1)^b.rotrSL(k,E,8)^b.shrSL(k,E,7),Y=Ut[T-2]|0,z=Ft[T-2]|0,wt=b.rotrSH(Y,z,19)^b.rotrBH(Y,z,61)^b.shrSH(Y,z,6),ut=b.rotrSL(Y,z,19)^b.rotrBL(Y,z,61)^b.shrSL(Y,z,6),Rt=b.add4L(Ot,ut,Ft[T-7],Ft[T-16]),xt=b.add4H(Rt,ot,wt,Ut[T-7],Ut[T-16]);Ut[T]=xt|0,Ft[T]=Rt|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:y,Fl:g,Gh:w,Gl:A,Hh:S,Hl:P}=this;for(let T=0;T<80;T++){let k=b.rotrSH(f,h,14)^b.rotrSH(f,h,18)^b.rotrBH(f,h,41),E=b.rotrSL(f,h,14)^b.rotrSL(f,h,18)^b.rotrBL(f,h,41),ot=f&y^~f&w,Ot=h&g^~h&A,Y=b.add5L(P,E,Ot,Ys[T],Ft[T]),z=b.add5H(Y,S,k,ot,Gs[T],Ut[T]),wt=Y|0,ut=b.rotrSH(n,i,28)^b.rotrBH(n,i,34)^b.rotrBH(n,i,39),Rt=b.rotrSL(n,i,28)^b.rotrBL(n,i,34)^b.rotrBL(n,i,39),xt=n&o^n&a^o&a,pe=i&s^i&c^s&c;S=w|0,P=A|0,w=y|0,A=g|0,y=f|0,g=h|0,{h:f,l:h}=b.add(l|0,u|0,z|0,wt|0),l=a|0,u=c|0,a=o|0,c=s|0,o=n|0,s=i|0;let zt=b.add3L(wt,Rt,pe);n=b.add3H(zt,z,ut,xt),i=zt|0}({h:n,l:i}=b.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=b.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:c}=b.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=b.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=b.add(this.Eh|0,this.El|0,f|0,h|0),{h:y,l:g}=b.add(this.Fh|0,this.Fl|0,y|0,g|0),{h:w,l:A}=b.add(this.Gh|0,this.Gl|0,w|0,A|0),{h:S,l:P}=b.add(this.Hh|0,this.Hl|0,S|0,P|0),this.set(n,i,o,s,a,c,l,u,f,h,y,g,w,A,S,P)}roundClean(){Ut.fill(0),Ft.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ir=vn(()=>new kr);var Zc=BigInt(0),zs=BigInt(1),Zs=BigInt(2);function xe(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var Js=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function De(t){if(!xe(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=Js[t[r]];return e}function di(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}var St={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function ui(t){if(t>=St._0&&t<=St._9)return t-St._0;if(t>=St._A&&t<=St._F)return t-(St._A-10);if(t>=St._a&&t<=St._f)return t-(St._a-10)}function fi(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=ui(t.charCodeAt(o)),a=ui(t.charCodeAt(o+1));if(s===void 0||a===void 0){let c=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[i]=s*16+a}return n}function pi(t){return di(De(t))}function re(t){if(!xe(t))throw new Error("Uint8Array expected");return di(De(Uint8Array.from(t).reverse()))}function qr(t,e){return fi(t.toString(16).padStart(e*2,"0"))}function _e(t,e){return qr(t,e).reverse()}function ht(t,e,r){let n;if(typeof e=="string")try{n=fi(e)}catch(o){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${o}`)}else if(xe(e))n=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(`${t} expected ${r} bytes, got ${i}`);return n}function Kr(...t){let e=0;for(let i=0;i<t.length;i++){let o=t[i];if(!xe(o))throw new Error("Uint8Array expected");e+=o.length}let r=new Uint8Array(e),n=0;for(let i=0;i<t.length;i++){let o=t[i];r.set(o,n),n+=o.length}return r}var hi=t=>(Zs<<BigInt(t-1))-zs;var Ds={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||xe(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function ne(t,e,r={}){let n=(i,o,s)=>{let a=Ds[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=t[i];if(!(s&&c===void 0)&&!a(c,t))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(r))n(i,o,!0);return t}var M=BigInt(0),F=BigInt(1),jt=BigInt(2),Qs=BigInt(3),Mr=BigInt(4),yi=BigInt(5),mi=BigInt(8),Ls=BigInt(9),ta=BigInt(16);function I(t,e){let r=t%e;return r>=M?r:e+r}function ea(t,e,r){if(r<=M||e<M)throw new Error("Expected power/modulo > 0");if(r===F)return M;let n=F;for(;e>M;)e&F&&(n=n*t%r),t=t*t%r,e>>=F;return n}function st(t,e,r){let n=t;for(;e-- >M;)n*=n,n%=r;return n}function gi(t,e){if(t===M||e<=M)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=I(t,e),n=e,i=M,o=F,s=F,a=M;for(;r!==M;){let l=n/r,u=n%r,f=i-s*l,h=o-a*l;n=r,r=u,i=s,o=a,s=f,a=h}if(n!==F)throw new Error("invert: does not exist");return I(i,e)}function ra(t){let e=(t-F)/jt,r,n,i;for(r=t-F,n=0;r%jt===M;r/=jt,n++);for(i=jt;i<t&&ea(i,e,t)!==t-F;i++);if(n===1){let s=(t+F)/Mr;return function(c,l){let u=c.pow(l,s);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let o=(r+F)/jt;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,i),r),f=a.pow(c,o),h=a.pow(c,r);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let y=1;for(let w=a.sqr(h);y<l&&!a.eql(w,a.ONE);y++)w=a.sqr(w);let g=a.pow(u,F<<BigInt(l-y-1));u=a.sqr(g),f=a.mul(f,g),h=a.mul(h,u),l=y}return f}}function na(t){if(t%Mr===Qs){let e=(t+F)/Mr;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(t%mi===yi){let e=(t-yi)/mi;return function(n,i){let o=n.mul(i,jt),s=n.pow(o,e),a=n.mul(i,s),c=n.mul(n.mul(a,jt),s),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),i))throw new Error("Cannot find square root");return l}}return t%ta,ra(t)}var wi=(t,e)=>(I(t,e)&F)===F,ia=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xi(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=ia.reduce((n,i)=>(n[i]="function",n),e);return ne(t,r)}function oa(t,e,r){if(r<M)throw new Error("Expected power > 0");if(r===M)return t.ONE;if(r===F)return e;let n=t.ONE,i=e;for(;r>M;)r&F&&(n=t.mul(n,i)),i=t.sqr(i),r>>=F;return n}function sa(t,e){let r=new Array(e.length),n=e.reduce((o,s,a)=>t.is0(s)?o:(r[a]=o,t.mul(o,s)),t.ONE),i=t.inv(n);return e.reduceRight((o,s,a)=>t.is0(s)?o:(r[a]=t.mul(o,r[a]),t.mul(o,s)),i),r}function Hr(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function _i(t,e,r=!1,n={}){if(t<=M)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:i,nByteLength:o}=Hr(t,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=na(t),a=Object.freeze({ORDER:t,BITS:i,BYTES:o,MASK:hi(i),ZERO:M,ONE:F,create:c=>I(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return M<=c&&c<t},is0:c=>c===M,isOdd:c=>(c&F)===F,neg:c=>I(-c,t),eql:(c,l)=>c===l,sqr:c=>I(c*c,t),add:(c,l)=>I(c+l,t),sub:(c,l)=>I(c-l,t),mul:(c,l)=>I(c*l,t),pow:(c,l)=>oa(a,c,l),div:(c,l)=>I(c*gi(l,t),t),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>gi(c,t),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>sa(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>r?_e(c,o):qr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return r?re(c):pi(c)}});return Object.freeze(a)}function bi(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}var aa=BigInt(0),jr=BigInt(1);function Ei(t,e){let r=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:r,unsafeLadder(i,o){let s=t.ZERO,a=i;for(;o>aa;)o&jr&&(s=s.add(a)),a=a.double(),o>>=jr;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),c=[],l=i,u=l;for(let f=0;f<s;f++){u=l,c.push(u);for(let h=1;h<a;h++)u=u.add(l),c.push(u);l=u.double()}return c},wNAF(i,o,s){let{windows:a,windowSize:c}=n(i),l=t.ZERO,u=t.BASE,f=BigInt(2**i-1),h=2**i,y=BigInt(i);for(let g=0;g<a;g++){let w=g*c,A=Number(s&f);s>>=y,A>c&&(A-=h,s+=jr);let S=w,P=w+Math.abs(A)-1,T=g%2!==0,k=A<0;A===0?u=u.add(r(T,o[S])):l=l.add(r(k,o[P]))}return{p:l,f:u}},wNAFCached(i,o,s,a){let c=i._WINDOW_SIZE||1,l=o.get(i);return l||(l=this.precomputeWindow(i,c),c!==1&&o.set(i,a(l))),this.wNAF(c,l,s)}}}function Ai(t){return xi(t.Fp),ne(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Hr(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var at=BigInt(0),tt=BigInt(1),Xe=BigInt(2),ca=BigInt(8),la={zip215:!0};function ua(t){let e=Ai(t);return ne(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Qe(t){let e=ua(t),{Fp:r,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:c}=e,l=Xe<<BigInt(a*8)-tt,u=r.create,f=e.uvRatio||((m,p)=>{try{return{isValid:!0,value:r.sqrt(m*r.inv(p))}}catch{return{isValid:!1,value:at}}}),h=e.adjustScalarBytes||(m=>m),y=e.domain||((m,p,x)=>{if(p.length||x)throw new Error("Contexts/pre-hash are not supported");return m}),g=m=>typeof m=="bigint"&&at<m,w=(m,p)=>g(m)&&g(p)&&m<p,A=m=>m===at||w(m,l);function S(m,p){if(w(m,p))return m;throw new Error(`Expected valid scalar < ${p}, got ${typeof m} ${m}`)}function P(m){return m===at?m:S(m,n)}let T=new Map;function k(m){if(!(m instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(p,x,_,v){if(this.ex=p,this.ey=x,this.ez=_,this.et=v,!A(p))throw new Error("x required");if(!A(x))throw new Error("y required");if(!A(_))throw new Error("z required");if(!A(v))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof E)throw new Error("extended point not allowed");let{x,y:_}=p||{};if(!A(x)||!A(_))throw new Error("invalid affine point");return new E(x,_,tt,u(x*_))}static normalizeZ(p){let x=r.invertBatch(p.map(_=>_.ez));return p.map((_,v)=>_.toAffine(x[v])).map(E.fromAffine)}_setWindowSize(p){this._WINDOW_SIZE=p,T.delete(this)}assertValidity(){let{a:p,d:x}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:_,ey:v,ez:O,et:R}=this,U=u(_*_),N=u(v*v),C=u(O*O),W=u(C*C),J=u(U*p),dt=u(C*u(J+N)),D=u(W+u(x*u(U*N)));if(dt!==D)throw new Error("bad point: equation left != right (1)");let Nt=u(_*v),_t=u(O*R);if(Nt!==_t)throw new Error("bad point: equation left != right (2)")}equals(p){k(p);let{ex:x,ey:_,ez:v}=this,{ex:O,ey:R,ez:U}=p,N=u(x*U),C=u(O*v),W=u(_*U),J=u(R*v);return N===C&&W===J}is0(){return this.equals(E.ZERO)}negate(){return new E(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=e,{ex:x,ey:_,ez:v}=this,O=u(x*x),R=u(_*_),U=u(Xe*u(v*v)),N=u(p*O),C=x+_,W=u(u(C*C)-O-R),J=N+R,dt=J-U,D=N-R,Nt=u(W*dt),_t=u(J*D),Fe=u(W*D),ke=u(dt*J);return new E(Nt,_t,ke,Fe)}add(p){k(p);let{a:x,d:_}=e,{ex:v,ey:O,ez:R,et:U}=this,{ex:N,ey:C,ez:W,et:J}=p;if(x===BigInt(-1)){let gn=u((O-v)*(C+N)),wn=u((O+v)*(C-N)),mr=u(wn-gn);if(mr===at)return this.double();let xn=u(R*Xe*J),_n=u(U*Xe*W),bn=_n+xn,En=wn+gn,An=_n-xn,Co=u(bn*mr),Uo=u(En*An),Fo=u(bn*An),ko=u(mr*En);return new E(Co,Uo,ko,Fo)}let dt=u(v*N),D=u(O*C),Nt=u(U*_*J),_t=u(R*W),Fe=u((v+O)*(N+C)-dt-D),ke=_t-Nt,yn=_t+Nt,mn=u(D-x*dt),Oo=u(Fe*ke),Ro=u(yn*mn),No=u(Fe*mn),Po=u(ke*yn);return new E(Oo,Ro,Po,No)}subtract(p){return this.add(p.negate())}wNAF(p){return Y.wNAFCached(this,T,p,E.normalizeZ)}multiply(p){let{p:x,f:_}=this.wNAF(S(p,n));return E.normalizeZ([x,_])[0]}multiplyUnsafe(p){let x=P(p);return x===at?Ot:this.equals(Ot)||x===tt?this:this.equals(ot)?this.wNAF(x).p:Y.unsafeLadder(this,x)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return Y.unsafeLadder(this,n).is0()}toAffine(p){let{ex:x,ey:_,ez:v}=this,O=this.is0();p==null&&(p=O?ca:r.inv(v));let R=u(x*p),U=u(_*p),N=u(v*p);if(O)return{x:at,y:tt};if(N!==tt)throw new Error("invZ was invalid");return{x:R,y:U}}clearCofactor(){let{h:p}=e;return p===tt?this:this.multiplyUnsafe(p)}static fromHex(p,x=!1){let{d:_,a:v}=e,O=r.BYTES;p=ht("pointHex",p,O);let R=p.slice(),U=p[O-1];R[O-1]=U&-129;let N=re(R);N===at||(x?S(N,l):S(N,r.ORDER));let C=u(N*N),W=u(C-tt),J=u(_*C-v),{isValid:dt,value:D}=f(W,J);if(!dt)throw new Error("Point.fromHex: invalid y coordinate");let Nt=(D&tt)===tt,_t=(U&128)!==0;if(!x&&D===at&&_t)throw new Error("Point.fromHex: x=0 and x_0=1");return _t!==Nt&&(D=u(-D)),E.fromAffine({x:D,y:N})}static fromPrivateKey(p){return ut(p).point}toRawBytes(){let{x:p,y:x}=this.toAffine(),_=_e(x,r.BYTES);return _[_.length-1]|=p&tt?128:0,_}toHex(){return De(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,tt,u(e.Gx*e.Gy)),E.ZERO=new E(at,tt,tt,at);let{BASE:ot,ZERO:Ot}=E,Y=Ei(E,a*8);function z(m){return I(m,n)}function wt(m){return z(re(m))}function ut(m){let p=a;m=ht("private key",m,p);let x=ht("hashed private key",o(m),2*p),_=h(x.slice(0,p)),v=x.slice(p,2*p),O=wt(_),R=ot.multiply(O),U=R.toRawBytes();return{head:_,prefix:v,scalar:O,point:R,pointBytes:U}}function Rt(m){return ut(m).pointBytes}function xt(m=new Uint8Array,...p){let x=Kr(...p);return wt(o(y(x,ht("context",m),!!i)))}function pe(m,p,x={}){m=ht("message",m),i&&(m=i(m));let{prefix:_,scalar:v,pointBytes:O}=ut(p),R=xt(x.context,_,m),U=ot.multiply(R).toRawBytes(),N=xt(x.context,U,O,m),C=z(R+N*v);P(C);let W=Kr(U,_e(C,r.BYTES));return ht("result",W,a*2)}let zt=la;function Zt(m,p,x,_=zt){let{context:v,zip215:O}=_,R=r.BYTES;m=ht("signature",m,2*R),p=ht("message",p),i&&(p=i(p));let U=re(m.slice(R,2*R)),N,C,W;try{N=E.fromHex(x,O),C=E.fromHex(m.slice(0,R),O),W=ot.multiplyUnsafe(U)}catch{return!1}if(!O&&N.isSmallOrder())return!1;let J=xt(v,C.toRawBytes(),N.toRawBytes(),p);return C.add(N.multiplyUnsafe(J)).subtract(W).clearCofactor().equals(E.ZERO)}return ot._setWindowSize(8),{CURVE:e,getPublicKey:Rt,sign:pe,verify:Zt,ExtendedPoint:E,utils:{getExtendedPublicKey:ut,randomPrivateKey:()=>s(r.BYTES),precompute(m=8,p=E.BASE){return p._setWindowSize(m),p.multiply(BigInt(3)),p}}}}var Vr=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ti=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),cl=BigInt(0),da=BigInt(1),$r=BigInt(2),fa=BigInt(5),Bi=BigInt(10),pa=BigInt(20),ha=BigInt(40),Si=BigInt(80);function ya(t){let e=Vr,n=t*t%e*t%e,i=st(n,$r,e)*n%e,o=st(i,da,e)*t%e,s=st(o,fa,e)*o%e,a=st(s,Bi,e)*s%e,c=st(a,pa,e)*a%e,l=st(c,ha,e)*c%e,u=st(l,Si,e)*l%e,f=st(u,Si,e)*l%e,h=st(f,Bi,e)*s%e;return{pow_p_5_8:st(h,$r,e)*t%e,b2:n}}function ma(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function ga(t,e){let r=Vr,n=I(e*e*e,r),i=I(n*n*e,r),o=ya(t*i).pow_p_5_8,s=I(t*n*o,r),a=I(e*s*s,r),c=s,l=I(s*Ti,r),u=a===t,f=a===I(-t,r),h=a===I(-t*Ti,r);return u&&(s=c),(f||h)&&(s=l),wi(s,r)&&(s=I(-s,r)),{isValid:u||f,value:s}}var vt=_i(Vr,void 0,!0),Wr={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:vt,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ir,randomBytes:On,adjustScalarBytes:ma,uvRatio:ga},kt=Qe(Wr);function vi(t,e,r){if(e.length>255)throw new Error("Context is too big");return Sn(Bn("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}var ll=Qe({...Wr,domain:vi}),ul=Qe({...Wr,domain:vi,prehash:Ir});var wa=(vt.ORDER+BigInt(3))/BigInt(8),dl=vt.pow($r,wa),fl=vt.sqrt(vt.neg(vt.ONE)),pl=(vt.ORDER-BigInt(5))/BigInt(8),hl=BigInt(486662);var yl=bi(vt,vt.neg(BigInt(486664)));var ml=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),gl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),wl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),xl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var _l=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Oi=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},Z=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)},G,be,Ri,Ni,Le=class{constructor(e={}){G.set(this,void 0),be.set(this,void 0),this[Ri]=this.entries.bind(this),this[Ni]="ExpirableMap";let{source:r=[],expirationTime:n=10*60*1e3}=e,i=Date.now();Oi(this,G,new Map([...r].map(([o,s])=>[o,{value:s,timestamp:i}])),"f"),Oi(this,be,n,"f")}prune(){let e=Date.now();for(let[r,n]of Z(this,G,"f").entries())e-n.timestamp>Z(this,be,"f")&&Z(this,G,"f").delete(r);return this}set(e,r){this.prune();let n={value:r,timestamp:Date.now()};return Z(this,G,"f").set(e,n),this}get(e){let r=Z(this,G,"f").get(e);if(r!==void 0){if(Date.now()-r.timestamp>Z(this,be,"f")){Z(this,G,"f").delete(e);return}return r.value}}clear(){Z(this,G,"f").clear()}entries(){let e=Z(this,G,"f").entries();return function*(){for(let[n,i]of e)yield[n,i.value]}()}values(){let e=Z(this,G,"f").values();return function*(){for(let n of e)yield n.value}()}keys(){return Z(this,G,"f").keys()}forEach(e,r){for(let[n,i]of Z(this,G,"f").entries())e.call(r,i.value,n,this)}has(e){return Z(this,G,"f").has(e)}delete(e){return Z(this,G,"f").delete(e)}get size(){return Z(this,G,"f").size}};G=new WeakMap,be=new WeakMap,Ri=Symbol.iterator,Ni=Symbol.toStringTag;var Pi=t=>{if(t<=127)return 1;if(t<=255)return 2;if(t<=65535)return 3;if(t<=16777215)return 4;throw new Error("Length too long (> 4 bytes)")},Ci=(t,e,r)=>{if(r<=127)return t[e]=r,1;if(r<=255)return t[e]=129,t[e+1]=r,2;if(r<=65535)return t[e]=130,t[e+1]=r>>8,t[e+2]=r,3;if(r<=16777215)return t[e]=131,t[e+1]=r>>16,t[e+2]=r>>8,t[e+3]=r,4;throw new Error("Length too long (> 4 bytes)")},Gr=(t,e)=>{if(t[e]<128)return 1;if(t[e]===128)throw new Error("Invalid length 0");if(t[e]===129)return 2;if(t[e]===130)return 3;if(t[e]===131)return 4;throw new Error("Length too long (> 4 bytes)")},xa=(t,e)=>{let r=Gr(t,e);if(r===1)return t[e];if(r===2)return t[e+1];if(r===3)return(t[e+1]<<8)+t[e+2];if(r===4)return(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];throw new Error("Length too long (> 4 bytes)")},Ui=Uint8Array.from([48,12,6,10,43,6,1,4,1,131,184,67,1,1]),$t=Uint8Array.from([48,5,6,3,43,101,112]),Tl=Uint8Array.from([48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,10]);function ie(t,e){let r=2+Pi(t.byteLength+1),n=e.byteLength+r+t.byteLength,i=0,o=new Uint8Array(1+Pi(n)+n);return o[i++]=48,i+=Ci(o,i,n),o.set(e,i),i+=e.byteLength,o[i++]=3,i+=Ci(o,i,t.byteLength+1),o[i++]=0,o.set(new Uint8Array(t),i),o}var Ee=(t,e)=>{let r=0,n=(a,c)=>{if(i[r++]!==a)throw new Error("Expected: "+c)},i=new Uint8Array(t);if(n(48,"sequence"),r+=Gr(i,r),!Pn(i.slice(r,r+e.byteLength),e))throw new Error("Not the expected OID.");r+=e.byteLength,n(3,"bit string");let o=xa(i,r)-1;r+=Gr(i,r),n(0,"0 padding");let s=i.slice(r);if(o!==s.length)throw new Error(`DER payload mismatch: Expected length ${o} actual length ${s.length}`);return s};var Fi=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},ki=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)},tr,er,Ae=class t{constructor(e){if(tr.set(this,void 0),er.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");Fi(this,tr,e,"f"),Fi(this,er,t.derEncode(e),"f")}static from(e){return this.fromDer(e.toDer())}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static derEncode(e){return ie(e,$t).buffer}static derDecode(e){let r=Ee(e,$t);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}get rawKey(){return ki(this,tr,"f")}get derKey(){return ki(this,er,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};tr=new WeakMap,er=new WeakMap;Ae.RAW_KEY_LENGTH=32;var ba=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},$=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)},oe,se,Vt,ae,nr,yt;(function(t){t.Received="received",t.Processing="processing",t.Replied="replied",t.Rejected="rejected",t.Unknown="unknown",t.Done="done"})(yt||(yt={}));var rr=5*60*1e3,Ea="308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100814c0e6ec71fab583b08bd81373c255c3c371b2e84863c98a4f1e08b74235d14fb5d9c0cd546d9685f913a0c0b2cc5341583bf4b4392e467db96d65b9bb4cb717112f8472e0d5a4d14505ffd7484b01291091c5f87b98883463f98091a0baaae",Aa="ic0.app",Ta=".ic0.app",Ba="icp0.io",Sa=".icp0.io",va="icp-api.io",Oa=".icp-api.io",Te=class extends qt{constructor(e){super(e),this.message=e}},ce=class extends qt{constructor(e){super(e),this.message=e}};function Ra(){let t;if(typeof window<"u")if(window.fetch)t=window.fetch.bind(window);else throw new Te("Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present.");else if(typeof globalThis<"u")if(globalThis.fetch)t=globalThis.fetch.bind(globalThis);else throw new Te("Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available.");else typeof self<"u"&&self.fetch&&(t=self.fetch.bind(self));if(t)return t;throw new Te("Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context.")}var Be=class t{constructor(e={}){if(this.rootKey=bt(Ea),this._timeDiffMsecs=0,this._rootKeyFetched=!1,this._isAgent=!0,oe.set(this,[]),se.set(this,[]),Vt.set(this,new Le({expirationTime:5*60*1e3})),ae.set(this,!0),nr.set(this,(r,n)=>{if($(this,ae,"f")===!1)return r;if(!n)throw new me("Invalid signature from replica signed query: no matching node key found.");let{status:i,signatures:o=[],requestId:s}=r,a=new TextEncoder().encode("\vic-response");for(let c of o){let{timestamp:l,identity:u}=c,f=B.fromUint8Array(u).toText(),h;if(i==="replied"){let{reply:S}=r;h=gr({status:i,reply:S,timestamp:BigInt(l),request_id:s})}else if(i==="rejected"){let{reject_code:S,reject_message:P,error_code:T}=r;h=gr({status:i,reject_code:S,reject_message:P,error_code:T,timestamp:BigInt(l),request_id:s})}else throw new Error(`Unknown status: ${i}`);let y=qe(a,new Uint8Array(h)),g=n?.nodeKeys.get(f);if(!g)throw new me("Invalid signature from replica signed query: no matching node key found.");let w=Ae.fromDer(g).rawKey;if(kt.verify(c.signature,new Uint8Array(y),new Uint8Array(w)))return r;throw new me(`Invalid signature from replica ${f} signed query.`)}return r}),e.source){if(!(e.source instanceof t))throw new Error("An Agent's source can only be another HttpAgent");this._identity=e.source._identity,this._fetch=e.source._fetch,this._host=e.source._host,this._credentials=e.source._credentials}else this._fetch=e.fetch||Ra()||fetch.bind(globalThis),this._fetchOptions=e.fetchOptions,this._callOptions=e.callOptions;if(e.host!==void 0)!e.host.match(/^[a-z]+:/)&&typeof window<"u"?this._host=new URL(window.location.protocol+"//"+e.host):this._host=new URL(e.host);else if(e.source!==void 0)this._host=e.source._host;else{let r=typeof window<"u"?window.location:void 0;r||(this._host=new URL("https://icp-api.io"),console.warn("Could not infer host from window.location, defaulting to mainnet gateway of https://icp-api.io. Please provide a host to the HttpAgent constructor to avoid this warning."));let n=["ic0.app","icp0.io","127.0.0.1","localhost"],i=r?.hostname,o;i&&typeof i=="string"&&(o=n.find(s=>i.endsWith(s))),r&&o?this._host=new URL(`${r.protocol}//${o}${r.port?":"+r.port:""}`):(this._host=new URL("https://icp-api.io"),console.warn("Could not infer host from window.location, defaulting to mainnet gateway of https://icp-api.io. Please provide a host to the HttpAgent constructor to avoid this warning."))}if(e.verifyQuerySignatures!==void 0&&ba(this,ae,e.verifyQuerySignatures,"f"),this._retryTimes=e.retryTimes!==void 0&&e.retryTimes>=0?e.retryTimes:3,this._host.hostname.endsWith(Ta)?this._host.hostname=Aa:this._host.hostname.endsWith(Sa)?this._host.hostname=Ba:this._host.hostname.endsWith(Oa)&&(this._host.hostname=va),e.credentials){let{name:r,password:n}=e.credentials;this._credentials=`${r}${n?":"+n:""}`}this._identity=Promise.resolve(e.identity||new Bt),this.addTransform("update",Ur(ee)),e.useQueryNonces&&this.addTransform("query",Ur(ee))}isLocal(){let e=this._host.hostname;return e==="127.0.0.1"||e.endsWith("127.0.0.1")}addTransform(e,r,n=r.priority||0){if(e==="update"){let i=$(this,se,"f").findIndex(o=>(o.priority||0)<n);$(this,se,"f").splice(i>=0?i:$(this,se,"f").length,0,Object.assign(r,{priority:n}))}else if(e==="query"){let i=$(this,oe,"f").findIndex(o=>(o.priority||0)<n);$(this,oe,"f").splice(i>=0?i:$(this,oe,"f").length,0,Object.assign(r,{priority:n}))}}async getPrincipal(){if(!this._identity)throw new ce("This identity has expired due this application's security policy. Please refresh your authentication.");return(await this._identity).getPrincipal()}async call(e,r,n){let i=await(n!==void 0?await n:await this._identity);if(!i)throw new ce("This identity has expired due this application's security policy. Please refresh your authentication.");let o=B.from(e),s=r.effectiveCanisterId?B.from(r.effectiveCanisterId):o,a=i.getPrincipal()||B.anonymous(),c=new Ht(rr);Math.abs(this._timeDiffMsecs)>1e3*30&&(c=new Ht(rr+this._timeDiffMsecs));let l={request_type:Ye.Call,canister_id:o,method_name:r.methodName,arg:r.arg,sender:a,ingress_expiry:c},u=await this._transform({request:{body:null,method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{})},endpoint:"call",body:l});u=await i.transformRequest(u);let f=Ke(u.body),h=this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${s.toText()}/call`,this._host),Object.assign(Object.assign(Object.assign({},this._callOptions),u.request),{body:f}))),[y,g]=await Promise.all([h,Pt(l)]),w=await y.arrayBuffer(),A=y.status===200&&w.byteLength>0?ye(w):null;return{requestId:g,response:{ok:y.ok,status:y.status,statusText:y.statusText,body:A,headers:ze(y.headers)}}}async _requestAndRetry(e,r=0){let n;try{n=await e()}catch(s){if(this._retryTimes>r)return console.warn(`Caught exception while attempting to make request:
3
3
  ${s}
4
4
  Retrying request.`),await this._requestAndRetry(e,r+1);throw s}if(n.ok)return n;let i=await n.clone().text(),o=`Server returned an error:
5
5
  Code: ${n.status} (${n.statusText})
6
6
  Body: ${i}
7
- `;if(this._retryTimes>r)return console.warn(o+" Retrying request."),await this._requestAndRetry(e,r+1);throw new ze(o,{ok:n.ok,status:n.status,statusText:n.statusText,headers:Ye(n.headers)})}async query(e,r,n){let i=async()=>{let c=await(n!==void 0?await n:await this._identity);if(!c)throw new ae("This identity has expired due this application's security policy. Please refresh your authentication.");let l=B.from(e),u=c?.getPrincipal()||B.anonymous(),f={request_type:"query",canister_id:l,method_name:r.methodName,arg:r.arg,sender:u,ingress_expiry:new Ht(er)},h=await Pt(f),y=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{})},endpoint:"read",body:f});y=await c?.transformRequest(y);let g=Ie(y.body),w=await this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${l.toText()}/query`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),y.request),{body:g}))),A=he(await w.arrayBuffer());return Object.assign(Object.assign({},A),{httpDetails:{ok:w.ok,status:w.status,statusText:w.statusText,headers:Ye(w.headers)},requestId:h})},o=async()=>{if(!H(this,se,"f"))return;let c=H(this,Vt,"f").get(e.toString());return c||(await this.fetchSubnetKeys(e.toString()),H(this,Vt,"f").get(e.toString()))},[s,a]=await Promise.all([i(),o()]);if(!H(this,se,"f"))return s;try{return H(this,rr,"f").call(this,s,a)}catch{console.warn("Query response verification failed. Retrying with fresh subnet keys."),H(this,Vt,"f").delete(e.toString()),await this.fetchSubnetKeys(e.toString());let l=H(this,Vt,"f").get(e.toString());if(!l)throw new ye("Invalid signature from replica signed query: no matching node key found.");return H(this,rr,"f").call(this,s,l)}}async createReadStateRequest(e,r){let n=await(r!==void 0?await r:await this._identity);if(!n)throw new ae("This identity has expired due this application's security policy. Please refresh your authentication.");let i=n?.getPrincipal()||B.anonymous(),o=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{})},endpoint:"read_state",body:{request_type:"read_state",paths:e.paths,sender:i,ingress_expiry:new Ht(er)}});return n?.transformRequest(o)}async readState(e,r,n,i){let o=typeof e=="string"?B.fromText(e):e,s=i??await this.createReadStateRequest(r,n),a=Ie(s.body),c=await this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${o}/read_state`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),s.request),{body:a})));if(!c.ok)throw new Error(`Server returned an error:
7
+ `;if(this._retryTimes>r)return console.warn(o+" Retrying request."),await this._requestAndRetry(e,r+1);throw new Ze(o,{ok:n.ok,status:n.status,statusText:n.statusText,headers:ze(n.headers)})}async query(e,r,n){let i=async()=>{let c=await(n!==void 0?await n:await this._identity);if(!c)throw new ce("This identity has expired due this application's security policy. Please refresh your authentication.");let l=B.from(e),u=c?.getPrincipal()||B.anonymous(),f={request_type:"query",canister_id:l,method_name:r.methodName,arg:r.arg,sender:u,ingress_expiry:new Ht(rr)},h=await Pt(f),y=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{})},endpoint:"read",body:f});y=await c?.transformRequest(y);let g=Ke(y.body),w=await this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${l.toText()}/query`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),y.request),{body:g}))),A=ye(await w.arrayBuffer());return Object.assign(Object.assign({},A),{httpDetails:{ok:w.ok,status:w.status,statusText:w.statusText,headers:ze(w.headers)},requestId:h})},o=async()=>{if(!$(this,ae,"f"))return;let c=$(this,Vt,"f").get(e.toString());return c||(await this.fetchSubnetKeys(e.toString()),$(this,Vt,"f").get(e.toString()))},[s,a]=await Promise.all([i(),o()]);if(!$(this,ae,"f"))return s;try{return $(this,nr,"f").call(this,s,a)}catch{console.warn("Query response verification failed. Retrying with fresh subnet keys."),$(this,Vt,"f").delete(e.toString()),await this.fetchSubnetKeys(e.toString());let l=$(this,Vt,"f").get(e.toString());if(!l)throw new me("Invalid signature from replica signed query: no matching node key found.");return $(this,nr,"f").call(this,s,l)}}async createReadStateRequest(e,r){let n=await(r!==void 0?await r:await this._identity);if(!n)throw new ce("This identity has expired due this application's security policy. Please refresh your authentication.");let i=n?.getPrincipal()||B.anonymous(),o=await this._transform({request:{method:"POST",headers:Object.assign({"Content-Type":"application/cbor"},this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{})},endpoint:"read_state",body:{request_type:"read_state",paths:e.paths,sender:i,ingress_expiry:new Ht(rr)}});return n?.transformRequest(o)}async readState(e,r,n,i){let o=typeof e=="string"?B.fromText(e):e,s=i??await this.createReadStateRequest(r,n),a=Ke(s.body),c=await this._requestAndRetry(()=>this._fetch(""+new URL(`/api/v2/canister/${o}/read_state`,this._host),Object.assign(Object.assign(Object.assign({},this._fetchOptions),s.request),{body:a})));if(!c.ok)throw new Error(`Server returned an error:
8
8
  Code: ${c.status} (${c.statusText})
9
9
  Body: ${await c.text()}
10
- `);return he(await c.arrayBuffer())}async syncTime(e){let r=await import("./canisterStatus-7J5OCF2I.js"),n=Date.now();try{e||console.log("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let o=(await r.request({canisterId:e??B.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),agent:this,paths:["time"]})).get("time");o&&(this._timeDiffMsecs=Number(o)-Number(n))}catch(i){console.error("Caught exception while attempting to sync time:",i)}}async status(){let e=this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{},r=await this._requestAndRetry(()=>this._fetch(""+new URL("/api/v2/status",this._host),Object.assign({headers:e},this._fetchOptions)));return he(await r.arrayBuffer())}async fetchRootKey(){return this._rootKeyFetched||(this.rootKey=(await this.status()).root_key,this._rootKeyFetched=!0),this.rootKey}invalidateIdentity(){this._identity=null}replaceIdentity(e){this._identity=Promise.resolve(e)}async fetchSubnetKeys(e){let r=B.from(e),i=(await gr({canisterId:r,paths:["subnet"],agent:this})).get("subnet");if(i&&typeof i=="object"&&"nodeKeys"in i)return H(this,Vt,"f").set(r.toText(),i),i}_transform(e){let r=Promise.resolve(e);if(e.endpoint==="call")for(let n of H(this,oe,"f"))r=r.then(i=>n(i).then(o=>o||i));else for(let n of H(this,ie,"f"))r=r.then(i=>n(i).then(o=>o||i));return r}};ie=new WeakMap,oe=new WeakMap,Vt=new WeakMap,se=new WeakMap,rr=new WeakMap;var Fi;(function(t){t.Error="err",t.GetPrincipal="gp",t.GetPrincipalResponse="gpr",t.Query="q",t.QueryResponse="qr",t.Call="c",t.CallResponse="cr",t.ReadState="rs",t.ReadStateResponse="rsr",t.Status="s",t.StatusResponse="sr"})(Fi||(Fi={}));function Gr(){let t=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.ic.agent:globalThis.ic.agent:window.ic.agent;if(!t)throw new Error("No Agent could be found.");return t}var nr={};Fo(nr,{backoff:()=>Mi,chain:()=>Hi,conditionalDelay:()=>Ii,defaultStrategy:()=>ki,maxAttempts:()=>Ra,once:()=>qi,throttle:()=>Pa,timeout:()=>Ki});var Oa=5*60*1e3;function ki(){return Hi(Ii(qi(),1e3),Mi(1e3,1.2),Ki(Oa))}function qi(){let t=!0;return async()=>t?(t=!1,!0):!1}function Ii(t,e){return async(r,n,i)=>{if(await t(r,n,i))return new Promise(o=>setTimeout(o,e))}}function Ra(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:
11
- Request ID: ${K(n)}
10
+ `);return ye(await c.arrayBuffer())}async syncTime(e){let r=await import("./canisterStatus-7J5OCF2I.js"),n=Date.now();try{e||console.log("Syncing time with the IC. No canisterId provided, so falling back to ryjl3-tyaaa-aaaaa-aaaba-cai");let o=(await r.request({canisterId:e??B.from("ryjl3-tyaaa-aaaaa-aaaba-cai"),agent:this,paths:["time"]})).get("time");o&&(this._timeDiffMsecs=Number(o)-Number(n))}catch(i){console.error("Caught exception while attempting to sync time:",i)}}async status(){let e=this._credentials?{Authorization:"Basic "+btoa(this._credentials)}:{},r=await this._requestAndRetry(()=>this._fetch(""+new URL("/api/v2/status",this._host),Object.assign({headers:e},this._fetchOptions)));return ye(await r.arrayBuffer())}async fetchRootKey(){return this._rootKeyFetched||(this.rootKey=(await this.status()).root_key,this._rootKeyFetched=!0),this.rootKey}invalidateIdentity(){this._identity=null}replaceIdentity(e){this._identity=Promise.resolve(e)}async fetchSubnetKeys(e){let r=B.from(e),i=(await wr({canisterId:r,paths:["subnet"],agent:this})).get("subnet");if(i&&typeof i=="object"&&"nodeKeys"in i)return $(this,Vt,"f").set(r.toText(),i),i}_transform(e){let r=Promise.resolve(e);if(e.endpoint==="call")for(let n of $(this,se,"f"))r=r.then(i=>n(i).then(o=>o||i));else for(let n of $(this,oe,"f"))r=r.then(i=>n(i).then(o=>o||i));return r}};oe=new WeakMap,se=new WeakMap,Vt=new WeakMap,ae=new WeakMap,nr=new WeakMap;var Ii;(function(t){t.Error="err",t.GetPrincipal="gp",t.GetPrincipalResponse="gpr",t.Query="q",t.QueryResponse="qr",t.Call="c",t.CallResponse="cr",t.ReadState="rs",t.ReadStateResponse="rsr",t.Status="s",t.StatusResponse="sr"})(Ii||(Ii={}));function Yr(){let t=typeof window>"u"?typeof globalThis>"u"?typeof self>"u"?void 0:self.ic.agent:globalThis.ic.agent:window.ic.agent;if(!t)throw new Error("No Agent could be found.");return t}var ir={};Io(ir,{backoff:()=>ji,chain:()=>$i,conditionalDelay:()=>Mi,defaultStrategy:()=>qi,maxAttempts:()=>Pa,once:()=>Ki,throttle:()=>Ca,timeout:()=>Hi});var Na=5*60*1e3;function qi(){return $i(Mi(Ki(),1e3),ji(1e3,1.2),Hi(Na))}function Ki(){let t=!0;return async()=>t?(t=!1,!0):!1}function Mi(t,e){return async(r,n,i)=>{if(await t(r,n,i))return new Promise(o=>setTimeout(o,e))}}function Pa(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:
11
+ Request ID: ${H(n)}
12
12
  Request status: ${i}
13
- `)}}function Pa(t){return()=>new Promise(e=>setTimeout(e,t))}function Ki(t){let e=Date.now()+t;return async(r,n,i)=>{if(Date.now()>e)throw new Error(`Request timed out after ${t} msec:
14
- Request ID: ${K(n)}
13
+ `)}}function Ca(t){return()=>new Promise(e=>setTimeout(e,t))}function Hi(t){let e=Date.now()+t;return async(r,n,i)=>{if(Date.now()>e)throw new Error(`Request timed out after ${t} msec:
14
+ Request ID: ${H(n)}
15
15
  Request status: ${i}
16
- `)}}function Mi(t,e){let r=t;return()=>new Promise(n=>setTimeout(()=>{r*=e,n()},r))}function Hi(...t){return async(e,r,n)=>{for(let i of t)await i(e,r,n)}}async function Yr(t,e,r,n,i,o){var s;let a=[new TextEncoder().encode("request_status"),r],c=i??await((s=t.createReadStateRequest)===null||s===void 0?void 0:s.call(t,{paths:[a]})),l=await t.readState(e,{paths:[a]},void 0,c);if(t.rootKey==null)throw new Error("Agent root key not initialized before polling");let u=await Un.create({certificate:l.certificate,rootKey:t.rootKey,canisterId:e,blsVerify:o}),f=u.lookup([...a,new TextEncoder().encode("status")]),h;switch(typeof f>"u"?h=ht.Unknown:h=new TextDecoder().decode(f),h){case ht.Replied:return u.lookup([...a,"reply"]);case ht.Received:case ht.Unknown:case ht.Processing:return await n(e,r,h),Yr(t,e,r,n,c);case ht.Rejected:{let y=new Uint8Array(u.lookup([...a,"reject_code"]))[0],g=new TextDecoder().decode(u.lookup([...a,"reject_message"]));throw new Error(`Call was rejected:
17
- Request ID: ${K(r)}
16
+ `)}}function ji(t,e){let r=t;return()=>new Promise(n=>setTimeout(()=>{r*=e,n()},r))}function $i(...t){return async(e,r,n)=>{for(let i of t)await i(e,r,n)}}async function zr(t,e,r,n,i,o){var s;let a=[new TextEncoder().encode("request_status"),r],c=i??await((s=t.createReadStateRequest)===null||s===void 0?void 0:s.call(t,{paths:[a]})),l=await t.readState(e,{paths:[a]},void 0,c);if(t.rootKey==null)throw new Error("Agent root key not initialized before polling");let u=await Fn.create({certificate:l.certificate,rootKey:t.rootKey,canisterId:e,blsVerify:o}),f=u.lookup([...a,new TextEncoder().encode("status")]),h;switch(typeof f>"u"?h=yt.Unknown:h=new TextDecoder().decode(f),h){case yt.Replied:return u.lookup([...a,"reply"]);case yt.Received:case yt.Unknown:case yt.Processing:return await n(e,r,h),zr(t,e,r,n,c);case yt.Rejected:{let y=new Uint8Array(u.lookup([...a,"reject_code"]))[0],g=new TextDecoder().decode(u.lookup([...a,"reject_message"]));throw new Error(`Call was rejected:
17
+ Request ID: ${H(r)}
18
18
  Reject code: ${y}
19
19
  Reject text: ${g}
20
- `)}case ht.Done:throw new Error(`Call was marked as done but we never saw the reply:
21
- Request ID: ${K(r)}
22
- `)}throw new Error("unreachable")}var ji=({IDL:t})=>{let e=t.Principal,r=t.Record({controllers:t.Vec(t.Principal),freezing_threshold:t.Nat,memory_allocation:t.Nat,compute_allocation:t.Nat}),n=t.Record({controllers:t.Opt(t.Vec(t.Principal)),freezing_threshold:t.Opt(t.Nat),memory_allocation:t.Opt(t.Nat),compute_allocation:t.Opt(t.Nat)}),i=t.Vec(t.Nat8);return t.Service({canister_status:t.Func([t.Record({canister_id:e})],[t.Record({status:t.Variant({stopped:t.Null,stopping:t.Null,running:t.Null}),memory_size:t.Nat,cycles:t.Nat,settings:r,module_hash:t.Opt(t.Vec(t.Nat8))})],[]),create_canister:t.Func([t.Record({settings:t.Opt(n)})],[t.Record({canister_id:e})],[]),delete_canister:t.Func([t.Record({canister_id:e})],[],[]),deposit_cycles:t.Func([t.Record({canister_id:e})],[],[]),install_code:t.Func([t.Record({arg:t.Vec(t.Nat8),wasm_module:i,mode:t.Variant({reinstall:t.Null,upgrade:t.Null,install:t.Null}),canister_id:e})],[],[]),provisional_create_canister_with_cycles:t.Func([t.Record({settings:t.Opt(n),amount:t.Opt(t.Nat)})],[t.Record({canister_id:e})],[]),provisional_top_up_canister:t.Func([t.Record({canister_id:e,amount:t.Nat})],[],[]),raw_rand:t.Func([],[t.Vec(t.Nat8)],[]),start_canister:t.Func([t.Record({canister_id:e})],[],[]),stop_canister:t.Func([t.Record({canister_id:e})],[],[]),uninstall_code:t.Func([t.Record({canister_id:e})],[],[]),update_settings:t.Func([t.Record({canister_id:t.Principal,settings:n})],[],[])})};var or=class extends It{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(`
23
- `)),this.canisterId=e,this.methodName=r,this.type=n,this.props=i}},zr=class extends or{constructor(e,r,n){var i;super(e,r,"query",{Status:n.status,Code:(i=We[n.reject_code])!==null&&i!==void 0?i:`Unknown Code "${n.reject_code}"`,Message:n.reject_message}),this.result=n}},Zr=class extends or{constructor(e,r,n,i){super(e,r,"update",Object.assign({"Request ID":K(n)},i.body?Object.assign(Object.assign({},i.body.error_code?{"Error code":i.body.error_code}:{}),{"Reject code":String(i.body.reject_code),"Reject message":i.body.reject_message}):{"HTTP status code":i.status.toString(),"HTTP status text":i.statusText})),this.requestId=n,this.response=i}},Jr;(function(t){t.Install="install",t.Reinstall="reinstall",t.Upgrade="upgrade"})(Jr||(Jr={}));var nt=Symbol.for("ic-agent-metadata"),Wt=class t{constructor(e){this[nt]=Object.freeze(e)}static agentOf(e){return e[nt].config.agent}static interfaceOf(e){return e[nt].service}static canisterIdOf(e){return B.from(e[nt].config.canisterId)}static async install(e,r){let n=e.mode===void 0?Jr.Install:e.mode,i=e.arg?[...new Uint8Array(e.arg)]:[],o=[...new Uint8Array(e.module)],s=typeof r.canisterId=="string"?B.fromText(r.canisterId):r.canisterId;await $i(r).install_code({mode:{[n]:null},arg:i,wasm_module:o,canister_id:s})}static async createCanister(e){let{canister_id:r}=await $i(e||{}).provisional_create_canister_with_cycles({amount:[],settings:[]});return r}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:pe});class i extends t{constructor(s){if(!s.canisterId)throw new It(`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"?B.fromText(s.canisterId):s.canisterId;super({config:Object.assign(Object.assign(Object.assign({},Wi),s),{canisterId:a}),service:n});for(let[c,l]of n._fields)r?.httpDetails&&l.annotations.push(Xr),this[c]=Ca(this,c,l,s.blsVerify)}}return i}static createActor(e,r){if(!r.canisterId)throw new It(`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)}};function ir(t,e){let r=pe.decode(t,Vi.Buffer.from(e));switch(r.length){case 0:return;case 1:return r[0];default:return r}}var Wi={pollingStrategyFactory:nr.defaultStrategy},Xr="http-details";function Ca(t,e,r,n){let i;r.annotations.includes("query")||r.annotations.includes("composite_query")?i=async(s,...a)=>{var c,l;s=Object.assign(Object.assign({},s),(l=(c=t[nt].config).queryTransform)===null||l===void 0?void 0:l.call(c,e,a,Object.assign(Object.assign({},t[nt].config),s)));let u=s.agent||t[nt].config.agent||Gr(),f=B.from(s.canisterId||t[nt].config.canisterId),h=pe.encode(r.argTypes,a),y=await u.query(f,{methodName:e,arg:h});switch(y.status){case"rejected":throw new zr(f,e,y);case"replied":return r.annotations.includes(Xr)?{httpDetails:y.httpDetails,result:ir(r.retTypes,y.reply.arg)}:ir(r.retTypes,y.reply.arg)}}:i=async(s,...a)=>{var c,l;s=Object.assign(Object.assign({},s),(l=(c=t[nt].config).callTransform)===null||l===void 0?void 0:l.call(c,e,a,Object.assign(Object.assign({},t[nt].config),s)));let u=s.agent||t[nt].config.agent||Gr(),{canisterId:f,effectiveCanisterId:h,pollingStrategyFactory:y}=Object.assign(Object.assign(Object.assign({},Wi),t[nt].config),s),g=B.from(f),w=h!==void 0?B.from(h):g,A=pe.encode(r.argTypes,a),{requestId:S,response:N}=await u.call(g,{methodName:e,arg:A,effectiveCanisterId:w});if(!N.ok||N.body)throw new Zr(g,e,S,N);let T=y(),k=await Yr(u,w,S,T,n),E=r.annotations.includes(Xr);if(k!==void 0)return E?{httpDetails:N,result:ir(r.retTypes,k)}:ir(r.retTypes,k);if(r.retTypes.length===0)return E?{httpDetails:N,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 $i(t){function e(r,n,i){let o=n[0],s=B.fromHex("");return o&&typeof o=="object"&&o.canister_id&&(s=B.from(o.canister_id)),{effectiveCanisterId:s}}return Wt.createActor(ji,Object.assign(Object.assign(Object.assign({},t),{canisterId:B.fromHex("")}),{callTransform:e,queryTransform:e}))}var cr=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},qt=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)},sr,ar,ce,le,Gt=class t{constructor(e){if(sr.set(this,void 0),ar.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");cr(this,sr,e,"f"),cr(this,ar,t.derEncode(e),"f")}static from(e){return this.fromDer(e.toDer())}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static derEncode(e){return ne(e,$t).buffer}static derDecode(e){let r=_e(e,$t);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}get rawKey(){return qt(this,sr,"f")}get derKey(){return qt(this,ar,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};sr=new WeakMap,ar=new WeakMap;Gt.RAW_KEY_LENGTH=32;var Yt=class t extends At{constructor(e,r){super(),ce.set(this,void 0),le.set(this,void 0),cr(this,ce,Gt.from(e),"f"),cr(this,le,new Uint8Array(r),"f")}static generate(e=new Uint8Array(32)){if(e&&e.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");e||(e=kt.utils.randomPrivateKey());let r=new Uint8Array(32);for(let i=0;i<32;i++)r[i]=new Uint8Array(e)[i];let n=kt.getPublicKey(r);return t.fromKeyPair(n,r)}static fromParsedJson(e){let[r,n]=e;return new t(Gt.fromDer(bt(r)),bt(n))}static fromJSON(e){let r=JSON.parse(e);if(Array.isArray(r)){if(typeof r[0]=="string"&&typeof r[1]=="string")return this.fromParsedJson([r[0],r[1]]);throw new Error("Deserialization error: JSON must have at least 2 items.")}throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(e)}`)}static fromKeyPair(e,r){return new t(Gt.fromRaw(e),r)}static fromSecretKey(e){let r=kt.getPublicKey(new Uint8Array(e));return t.fromKeyPair(r,e)}toJSON(){return[K(qt(this,ce,"f").toDer()),K(qt(this,le,"f"))]}getKeyPair(){return{secretKey:qt(this,le,"f"),publicKey:qt(this,ce,"f")}}getPublicKey(){return qt(this,ce,"f")}async sign(e){let r=new Uint8Array(e),n=Nn(kt.sign(r,qt(this,le,"f").slice(0,32)));return Object.defineProperty(n,"__signature__",{enumerable:!1,value:void 0}),n}static verify(e,r,n){let[i,o,s]=[e,r,n].map(a=>(typeof a=="string"&&(a=bt(a)),a instanceof Uint8Array&&(a=a.buffer),new Uint8Array(a)));return kt.verify(o,i,s)}};ce=new WeakMap,le=new WeakMap;var Dr=class t extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,t.prototype)}};function Gi(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 Dr("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 Be=class t extends At{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=Gi(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=Gi(r),i=await n.exportKey("spki",e.publicKey);return new t(e,i,n)}getKeyPair(){return this._keyPair}getPublicKey(){let e=this._derKey,r=Object.create(this._keyPair.publicKey);return r.toDer=function(){return e},r}async sign(e){let r={name:"ECDSA",hash:{name:"SHA-256"}};return this._keyPair.privateKey,await this._subtleCrypto.sign(r,this._keyPair.privateKey,e)}};var ue=ke(Cn()),Fa=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},ka=new TextEncoder().encode("ic-request-auth-delegation"),qa=new TextEncoder().encode(`
24
- ic-request`);function Qr(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return bt(t)}var de=class{constructor(e,r,n){this.pubkey=e,this.expiration=r,this.targets=n}toCBOR(){return ue.value.map(Object.assign({pubkey:ue.value.bytes(this.pubkey),expiration:ue.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:ue.value.array(this.targets.map(e=>ue.value.bytes(e.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:K(this.pubkey)},this.targets&&{targets:this.targets.map(e=>e.toHex())})}};async function Ia(t,e,r,n){let i=new de(e.toDer(),BigInt(+r)*BigInt(1e6),n),o=new Uint8Array([...ka,...new Uint8Array(Pt(i))]),s=await t.sign(o);return{delegation:i,signature:s}}var Se=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 Ia(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:c,expiration:l,targets:u}=s;if(u!==void 0&&!Array.isArray(u))throw new Error("Invalid targets.");return{delegation:new de(Qr(c),BigInt("0x"+l),u&&u.map(f=>{if(typeof f!="string")throw new Error("Invalid target.");return B.fromHex(f)})),signature:Qr(a)}});return new this(i,Qr(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:K(r.pubkey)},i&&{targets:i.map(o=>o.toHex())}),signature:K(n)}}),publicKey:K(this.publicKey)}}},ve=class extends At{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=Fa(e,["body"]),i=await Pt(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_sig:await this.sign(new Uint8Array([...qa,...new Uint8Array(i)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}};function Yi(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"?B.fromText(i):i)):r.push(typeof n=="string"?B.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 c of s.targets)if(c.toText()===o){a=!1;break}if(a)return!1}}return!0}var Ka=ke(qo());var zi;(function(t){t[t.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(zi||(zi={}));var Zi=["mousedown","mousemove","keydown","touchstart","wheel"],Oe=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),Zi.forEach(function(a){document.addEventListener(a,o,!0)});let s=(a,c)=>{let l;return(...u)=>{let f=this,h=function(){l=void 0,a.apply(f,u)};clearTimeout(l),l=window.setTimeout(h,c)}};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);Zi.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 Ma=(t,e)=>e.some(r=>t instanceof r),Ji,Xi;function Ha(){return Ji||(Ji=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function ja(){return Xi||(Xi=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var Di=new WeakMap,tn=new WeakMap,Qi=new WeakMap,Lr=new WeakMap,rn=new WeakMap;function $a(t){let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("success",o),t.removeEventListener("error",s)},o=()=>{r(yt(t.result)),i()},s=()=>{n(t.error),i()};t.addEventListener("success",o),t.addEventListener("error",s)});return e.then(r=>{r instanceof IDBCursor&&Di.set(r,t)}).catch(()=>{}),rn.set(e,t),e}function Va(t){if(tn.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)});tn.set(t,e)}var en={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return tn.get(t);if(e==="objectStoreNames")return t.objectStoreNames||Qi.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return yt(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 Li(t){en=t(en)}function Wa(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(lr(this),e,...r);return Qi.set(n,e.sort?e.sort():[e]),yt(n)}:ja().includes(t)?function(...e){return t.apply(lr(this),e),yt(Di.get(this))}:function(...e){return yt(t.apply(lr(this),e))}}function Ga(t){return typeof t=="function"?Wa(t):(t instanceof IDBTransaction&&Va(t),Ma(t,Ha())?new Proxy(t,en):t)}function yt(t){if(t instanceof IDBRequest)return $a(t);if(Lr.has(t))return Lr.get(t);let e=Ga(t);return e!==t&&(Lr.set(t,e),rn.set(e,t)),e}var lr=t=>rn.get(t);function eo(t,e,{blocked:r,upgrade:n,blocking:i,terminated:o}={}){let s=indexedDB.open(t,e),a=yt(s);return n&&s.addEventListener("upgradeneeded",c=>{n(yt(s.result),c.oldVersion,c.newVersion,yt(s.transaction),c)}),r&&s.addEventListener("blocked",c=>r(c.oldVersion,c.newVersion,c)),a.then(c=>{o&&c.addEventListener("close",()=>o()),i&&c.addEventListener("versionchange",l=>i(l.oldVersion,l.newVersion,l))}).catch(()=>{}),a}var Ya=["get","getKey","getAll","getAllKeys","count"],za=["put","add","delete","clear"],nn=new Map;function to(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(nn.get(e))return nn.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,i=za.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(i||Ya.includes(r)))return;let o=async function(s,...a){let c=this.transaction(s,i?"readwrite":"readonly"),l=c.store;return n&&(l=l.index(a.shift())),(await Promise.all([l[r](...a),i&&c.done]))[0]};return nn.set(e,o),o}Li(t=>({...t,get:(e,r,n)=>to(e,r)||t.get(e,r,n),has:(e,r)=>!!to(e,r)||t.has(e,r)}));var ro="auth-client-db",no="ic-keyval",Za=async(t=ro,e=no,r)=>(ur&&(localStorage!=null&&localStorage.getItem(at))&&(localStorage.removeItem(at),localStorage.removeItem(ct)),await eo(t,r,{upgrade:n=>{n.objectStoreNames,n.objectStoreNames.contains(e)&&n.clear(e),n.createObjectStore(e)}}));async function Ja(t,e,r){return await t.get(e,r)}async function Xa(t,e,r,n){return await t.put(e,n,r)}async function Da(t,e,r){return await t.delete(e,r)}var Re=class t{constructor(e,r){this._db=e,this._storeName=r}static async create(e){let{dbName:r=ro,storeName:n=no,version:i=1}=e??{},o=await Za(r,n,i);return new t(o,n)}async set(e,r){return await Xa(this._db,this._storeName,e,r)}async get(e){var r;return(r=await Ja(this._db,this._storeName,e))!==null&&r!==void 0?r:null}async remove(e){return await Da(this._db,this._storeName,e)}};var ct="identity",at="delegation",io="iv",Qa=1,ur=typeof window<"u",Pe=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}},Ne=class{get _db(){return new Promise(e=>{if(this.initializedDb){e(this.initializedDb);return}Re.create({version:Qa}).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)}};var La="https://identity.ic0.app",tc="#authorize",on="ECDSA",sn="Ed25519",ec=500,rc="UserInterrupt",dr=class{constructor(e,r,n,i,o,s,a,c){var l;this._identity=e,this._key=r,this._chain=n,this._storage=i,this.idleManager=o,this._createOptions=s,this._idpWindow=a,this._eventHandler=c;let u=this.logout.bind(this),f=s?.idleOptions;!f?.onIdle&&!f?.disableDefaultIdleCallback&&((l=this.idleManager)===null||l===void 0||l.registerCallback(()=>{u(),location.reload()}))}static async create(e={}){var r,n,i;let o=(r=e.storage)!==null&&r!==void 0?r:new Ne,s=(n=e.keyType)!==null&&n!==void 0?n:on,a=null;if(e.identity)a=e.identity;else{let f=await o.get(ct);if(!f&&ur)try{let h=new Pe,y=await h.get(at),g=await h.get(ct);y&&g&&s===on&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await o.set(at,y),await o.set(ct,g),f=y,await h.remove(at),await h.remove(ct))}catch(h){console.error("error while attempting to recover localstorage: "+h)}if(f)try{typeof f=="object"?s===sn&&typeof f=="string"?a=await Yt.fromJSON(f):a=await Be.fromKeyPair(f):typeof f=="string"&&(a=Yt.fromJSON(f))}catch{}}let c=new Tt,l=null;if(a)try{let f=await o.get(at);if(typeof f=="object"&&f!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?c=e.identity:f&&(l=Se.fromJSON(f),Yi(l)?c=ve.fromDelegation(a,l):(await an(o),a=null))}catch(f){console.error(f),await an(o),a=null}let u;return!((i=e.idleOptions)===null||i===void 0)&&i.disableIdle?u=void 0:(l||e.identity)&&(u=Oe.create(e.idleOptions)),a||(s===sn?(a=await Yt.generate(),await o.set(ct,JSON.stringify(a.toJSON()))):(e.storage&&s===on&&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 '${sn}' as the key type, as it can serialize to a string`),a=await Be.generate(),await o.set(ct,a.getKeyPair()))),new this(c,a,l,o,u,e)}async _handleSuccess(e,r){var n,i,o;let s=e.delegations.map(l=>({delegation:new de(l.delegation.pubkey,l.delegation.expiration,l.delegation.targets),signature:l.signature.buffer})),a=Se.fromDelegations(s,e.userPublicKey.buffer),c=this._key;if(c){if(this._chain=a,this._identity=ve.fromDelegation(c,this._chain),(n=this._idpWindow)===null||n===void 0||n.close(),!this.idleManager){let l=(i=this._createOptions)===null||i===void 0?void 0:i.idleOptions;this.idleManager=Oe.create(l),!l?.onIdle&&!l?.disableDefaultIdleCallback&&((o=this.idleManager)===null||o===void 0||o.registerCallback(()=>{this.logout(),location.reload()}))}this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(at,JSON.stringify(this._chain.toJSON())),r?.()}}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())||La);a.hash=tc,(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 c=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(rc,e?.onError):setTimeout(c,ec))};c()}_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 c={kind:"authorize-client",sessionPublicKey:new Uint8Array((i=this._key)===null||i===void 0?void 0:i.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,derivationOrigin:(o=r?.derivationOrigin)===null||o===void 0?void 0:o.toString()};(s=this._idpWindow)===null||s===void 0||s.postMessage(c,e.origin);break}case"authorize-client-success":try{await this._handleSuccess(a,r?.onSuccess)}catch(c){this._handleFailure(c.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 an(this._storage),this._identity=new Tt,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function an(t){await t.remove(ct),await t.remove(at),await t.remove(io)}var fr=()=>dr.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var oo=async({data:t})=>{try{return await Ke(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var cn=async t=>{let{data:e,updated_at:r,description:n}=t;return{description:$(n),data:await Fn(e),updated_at:$(r)}},ln=t=>{let{updated_at:e}=t;return{updated_at:$(e)}},Ce=async({doc:t,key:e})=>{let{owner:r,description:n,data:i,...o}=t;return{key:e,description:X(n),owner:r.toText(),data:await Ke(i),...o}};var pr=({matcher:t,paginate:e,order:r,owner:n})=>({matcher:j(t)?[]:[{key:$(t.key),description:$(t.description)}],paginate:$(j(e)?void 0:{start_after:$(e.startAfter),limit:$(j(e.limit)?void 0:BigInt(e.limit))}),order:$(j(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:$(j(n)?void 0:typeof n=="string"?B.fromText(n):n)});var so=({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.Record({controllers:t.Vec(t.Principal)}),n=t.Variant({Write:t.Null,Admin:t.Null}),i=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:n,expires_at:t.Opt(t.Nat64)}),o=t.Record({updated_at:t.Opt(t.Nat64)}),s=t.Variant({Db:t.Null,Storage:t.Null}),a=t.Record({cycles:t.Nat,destination_id:t.Principal}),c=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),l=t.Record({status_code:t.Nat16,location:t.Text}),u=t.Record({iframe:t.Opt(c),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),redirects:t.Opt(t.Vec(t.Tuple(t.Text,l)))}),f=t.Record({storage:u}),h=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64}),y=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)}),g=t.Variant({Heap:t.Null,Stable:t.Null}),w=t.Record({memory:g,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}),A=t.Variant({Callback:t.Record({token:w,callback:t.Func([],[],["query"])})}),S=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(A),status_code:t.Nat16}),N=t.Record({token:t.Opt(w),body:t.Vec(t.Nat8)}),T=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),k=t.Record({batch_id:t.Nat}),E=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),it=t.Record({field:E,desc:t.Bool}),vt=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),G=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),Y=t.Record({order:t.Opt(it),owner:t.Opt(t.Principal),matcher:t.Opt(vt),paginate:t.Opt(G)}),gt=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}),lt=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),Ot=t.Record({key:gt,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,lt)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64}),wt=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,Ot)),items_length:t.Nat64}),fe=t.Record({updated_at:t.Nat64,created_at:t.Nat64,bn_id:t.Opt(t.Text)}),zt=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,h)),items_length:t.Nat64}),Zt=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),pn=t.Record({memory:t.Opt(g),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:Zt,created_at:t.Nat64,mutable_permissions:t.Opt(t.Bool),write:Zt}),m=t.Record({stable:t.Nat64,heap:t.Nat64}),p=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:n,expires_at:t.Opt(t.Nat64)}),x=t.Record({controller:p,controllers:t.Vec(t.Principal)}),b=t.Record({updated_at:t.Opt(t.Nat64),data:t.Vec(t.Nat8),description:t.Opt(t.Text)}),v=t.Record({memory:t.Opt(g),updated_at:t.Opt(t.Nat64),max_size:t.Opt(t.Nat),read:Zt,mutable_permissions:t.Opt(t.Bool),write:Zt}),O=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),R=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([r],[t.Vec(t.Tuple(t.Principal,i))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,o],[],[]),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,o))],[],[]),del_rule:t.Func([s,t.Text,o],[],[]),deposit_cycles:t.Func([a],[],[]),get_config:t.Func([],[f],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(h)],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(h)))],["query"]),http_request:t.Func([y],[S],["query"]),http_request_streaming_callback:t.Func([w],[N],["query"]),init_asset_upload:t.Func([T],[k],[]),list_assets:t.Func([t.Text,Y],[wt],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,fe))],["query"]),list_docs:t.Func([t.Text,Y],[zt],["query"]),list_rules:t.Func([s],[t.Vec(t.Tuple(t.Text,pn))],["query"]),memory_size:t.Func([],[m],["query"]),set_config:t.Func([f],[],[]),set_controllers:t.Func([x],[t.Vec(t.Tuple(t.Principal,i))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_doc:t.Func([t.Text,t.Text,b],[h],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,b))],[t.Vec(t.Tuple(t.Text,h))],[]),set_rule:t.Func([s,t.Text,v],[],[]),upload_asset_chunk:t.Func([O],[R],[]),version:t.Func([],[t.Text],["query"])})};var ao=async({satelliteId:t,idlFactory:e,identity:r,fetch:n,env:i="prod"})=>{let o=i==="dev"||D.getInstance().localIdentity(),s=o?"http://127.0.0.1:8000/":"https://icp-api.io",a=new Te({identity:r,...s&&{host:s},...n&&{fetch:n}});return o&&await a.fetchRootKey(),Wt.createActor(e,{agent:a,canisterId:t})};var tt=async({satelliteId:t,...e})=>{let{satelliteId:r}=t!==void 0?{satelliteId:t}:D.getInstance().get()??{satelliteId:void 0};if(!r)throw new Error("No satellite principal defined.");return ao({satelliteId:r,idlFactory:so,...e})};var co=async({collection:t,key:e,satellite:r})=>{let n=await tt(r),i=X(await n.get_doc(t,e));if(!j(i))return Ce({doc:i,key:e})},lo=async({docs:t,satellite:e})=>{let{get_many_docs:r}=await tt(e),n=t.map(({collection:s,key:a})=>[s,a]),i=await r(n),o=[];for(let[s,a]of i){let c=X(a);o.push(Nt(c)?await Ce({key:s,doc:c}):void 0)}return o},uo=async({collection:t,doc:e,satellite:r})=>{let{set_doc:n}=await tt(r),{key:i}=e,o=await cn(e),s=await n(t,i,o);return await Ce({key:i,doc:s})},fo=async({docs:t,satellite:e})=>{let{set_many_docs:r}=await tt(e),n=[];for(let{collection:s,doc:a}of t){let{key:c}=a;n.push([s,c,await cn(a)])}let i=await r(n),o=[];for(let[s,a]of i)o.push(await Ce({key:s,doc:a}));return o},po=async({collection:t,doc:e,satellite:r})=>{let{del_doc:n}=await tt(r),{key:i}=e;return n(t,i,ln(e))},ho=async({docs:t,satellite:e})=>{let{del_many_docs:r}=await tt(e),n=t.map(({collection:i,doc:o})=>[i,o.key,ln(o)]);await r(n)},yo=async({collection:t,filter:e,satellite:r})=>{let n=await tt(r),{items:i,items_page:o,items_length:s,matches_length:a,matches_pages:c}=await n.list_docs(t,pr(e)),l=[];for(let[u,f]of i){let{data:h,owner:y,description:g,...w}=f;l.push({key:u,description:X(g),owner:y.toText(),data:await oo({data:h}),...w})}return{items:l,items_length:s,items_page:X(o),matches_length:a,matches_pages:X(c)}};var et=t=>t!==void 0?t:hr()??new Tt;var mo=async({satellite:t,...e})=>{let r=et(t?.identity);return co({...e,satellite:{...t,identity:r}})},Kd=async({satellite:t,...e})=>{let r=et(t?.identity);return lo({...e,satellite:{...t,identity:r}})},go=async({satellite:t,...e})=>{let r=et(t?.identity);return uo({...e,satellite:{...t,identity:r}})},Md=async({satellite:t,...e})=>{let r=et(t?.identity);return fo({...e,satellite:{...t,identity:r}})},Hd=async({satellite:t,...e})=>{let r=et(t?.identity);return po({...e,satellite:{...t,identity:r}})},jd=async({satellite:t,...e})=>{let r=et(t?.identity);return ho({...e,satellite:{...t,identity:r}})},$d=async({satellite:t,filter:e,...r})=>{let n=et(t?.identity);return yo({...r,filter:e??{},satellite:{...t,identity:n}})};var wo=async t=>{let e=hr();if(j(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let r=e.getPrincipal().toText(),n=await mo({collection:"#user",key:r});return j(n)?await nc({userId:r,provider:t}):n},nc=async({userId:t,...e})=>go({collection:"#user",doc:{key:t,data:e}});var mt,un=async t=>{if(mt=mt??await fr(),!(await mt?.isAuthenticated()??!1))return;let r=await wo(t);_t.getInstance().set(r)},ic=async t=>new Promise(async(e,r)=>{mt=mt??await fr();let n=t?.provider??new He({});await mt.login({onSuccess:async()=>{await un(n.id),e()},onError:i=>r(i),maxTimeToLive:t?.maxTimeToLive??kn,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...n.signInOptions({windowed:t?.windowed})})}),dn=async()=>{await mt?.logout(),mt=void 0,_t.getInstance().reset()},hr=()=>mt?.getIdentity(),oc=async()=>(mt??await fr()).getIdentity();var xo=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),n=async()=>{_r({message:"junoSignOutAuthTimer"}),await dn()};return r.onmessage=async({data:i})=>{let{msg:o,data:s}=i;switch(o){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":_r({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},_t.getInstance().subscribe(i=>{if(j(i)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var bo=async({data:t,filename:e,collection:r,headers:n,token:i,fullPath:o,encoding:s,description:a,satellite:c})=>{let l=await tt(c),{batch_id:u}=await l.init_asset_upload({collection:r,full_path:o,name:e,token:$(i),encoding_type:$(s),description:$(a)}),f=19e5,h=[],y=Me()?new Blob([await t.arrayBuffer()]):t,g=0n;for(let S=0;S<y.size;S+=f){let N=y.slice(S,S+f);h.push({batchId:u,chunk:N,actor:l,orderId:g}),g++}let w=[];for await(let S of sc({uploadChunks:h}))w=[...w,...S];let A=n.find(([S,N])=>S.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await l.commit_asset_upload({batch_id:u,chunk_ids:w.map(({chunk_id:S})=>S),headers:[...n,...A||[]]})};async function*sc({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(o=>ac(o)))}}var ac=async({batchId:t,chunk:e,actor:r,orderId:n})=>r.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:$(n)}),_o=async({collection:t,satellite:e,filter:r})=>{let n=await tt(e),{items:i,items_length:o,items_page:s,matches_length:a,matches_pages:c}=await n.list_assets(t,pr(r));return{items:i.map(([l,u])=>u),items_length:o,items_page:X(s),matches_length:a,matches_pages:X(c)}},Eo=async({collection:t,fullPath:e,satellite:r})=>(await tt(r)).del_asset(t,e),Ao=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await tt(e),n=t.map(({collection:i,fullPath:o})=>[i,o]);await r(n)};var To=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var fn=()=>{let t=D.getInstance().get()?.satelliteId??"unknown";return D.getInstance().localIdentity()?`http://${t}.localhost:8000`:`https://${t}.icp0.io`};var wf=async t=>Bo(t),xf=async t=>Bo({filename:t.data.name,...t}),Bo=async({filename:t,data:e,collection:r,headers:n=[],fullPath:i,token:o,satellite:s,encoding:a,description:c})=>{let l=et(s?.identity),u=decodeURI(t),f=i??`/${r}/${u}`;return await bo({data:e,filename:u,collection:r,token:o,headers:n,fullPath:f,encoding:a,satellite:{...s,identity:l},description:c}),{downloadUrl:`${fn()}${f}${o!==void 0?`?token=${o}`:""}`,fullPath:f,name:u}},bf=async({collection:t,satellite:e,filter:r})=>{let{items:n,...i}=await _o({collection:t,satellite:{...e,identity:et(e?.identity)},filter:r??{}}),o=fn();return{assets:n.map(({key:{full_path:s,token:a,name:c,owner:l,description:u},headers:f,encodings:h,created_at:y,updated_at:g})=>{let w=X(a);return{fullPath:s,description:X(u),name:c,downloadUrl:`${o}${s}${w!==void 0?`?token=${w}`:""}`,token:w,headers:f,encodings:h.reduce((A,[S,{modified:N,sha256:T,total_length:k}])=>({...A,[S]:{modified:N,sha256:To(T),total_length:k}}),{}),owner:l.toText(),created_at:y,updated_at:g}}),...i}},_f=async({collection:t,fullPath:e,satellite:r})=>Eo({collection:t,fullPath:e,satellite:{...r,identity:et(r?.identity)}}),Ef=async({assets:t,satellite:e})=>Ao({assets:t,satellite:{...e,identity:et(e?.identity)}});var Of=async t=>{D.getInstance().set(t),await un();let e=t.workers?.auth!==void 0?xo(t.workers.auth):void 0;return[...e?[e]:[]]},Rf=t=>_t.getInstance().subscribe(t);export{He as InternetIdentityProvider,Mn as NFIDProvider,Rf as authSubscribe,_f as deleteAsset,Hd as deleteDoc,Ef as deleteManyAssets,jd as deleteManyDocs,mo as getDoc,Kd as getManyDocs,Of as initJuno,bf as listAssets,$d as listDocs,go as setDoc,Md as setManyDocs,ic as signIn,dn as signOut,oc as unsafeIdentity,wf as uploadBlob,xf as uploadFile};
20
+ `)}case yt.Done:throw new Error(`Call was marked as done but we never saw the reply:
21
+ Request ID: ${H(r)}
22
+ `)}throw new Error("unreachable")}var Vi=({IDL:t})=>{let e=t.Principal,r=t.Record({controllers:t.Vec(t.Principal),freezing_threshold:t.Nat,memory_allocation:t.Nat,compute_allocation:t.Nat}),n=t.Record({controllers:t.Opt(t.Vec(t.Principal)),freezing_threshold:t.Opt(t.Nat),memory_allocation:t.Opt(t.Nat),compute_allocation:t.Opt(t.Nat)}),i=t.Vec(t.Nat8);return t.Service({canister_status:t.Func([t.Record({canister_id:e})],[t.Record({status:t.Variant({stopped:t.Null,stopping:t.Null,running:t.Null}),memory_size:t.Nat,cycles:t.Nat,settings:r,module_hash:t.Opt(t.Vec(t.Nat8))})],[]),create_canister:t.Func([t.Record({settings:t.Opt(n)})],[t.Record({canister_id:e})],[]),delete_canister:t.Func([t.Record({canister_id:e})],[],[]),deposit_cycles:t.Func([t.Record({canister_id:e})],[],[]),install_code:t.Func([t.Record({arg:t.Vec(t.Nat8),wasm_module:i,mode:t.Variant({reinstall:t.Null,upgrade:t.Null,install:t.Null}),canister_id:e})],[],[]),provisional_create_canister_with_cycles:t.Func([t.Record({settings:t.Opt(n),amount:t.Opt(t.Nat)})],[t.Record({canister_id:e})],[]),provisional_top_up_canister:t.Func([t.Record({canister_id:e,amount:t.Nat})],[],[]),raw_rand:t.Func([],[t.Vec(t.Nat8)],[]),start_canister:t.Func([t.Record({canister_id:e})],[],[]),stop_canister:t.Func([t.Record({canister_id:e})],[],[]),uninstall_code:t.Func([t.Record({canister_id:e})],[],[]),update_settings:t.Func([t.Record({canister_id:t.Principal,settings:n})],[],[])})};var sr=class extends qt{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(`
23
+ `)),this.canisterId=e,this.methodName=r,this.type=n,this.props=i}},Zr=class extends sr{constructor(e,r,n){var i;super(e,r,"query",{Status:n.status,Code:(i=Ge[n.reject_code])!==null&&i!==void 0?i:`Unknown Code "${n.reject_code}"`,Message:n.reject_message}),this.result=n}},Jr=class extends sr{constructor(e,r,n,i){super(e,r,"update",Object.assign({"Request ID":H(n)},i.body?Object.assign(Object.assign({},i.body.error_code?{"Error code":i.body.error_code}:{}),{"Reject code":String(i.body.reject_code),"Reject message":i.body.reject_message}):{"HTTP status code":i.status.toString(),"HTTP status text":i.statusText})),this.requestId=n,this.response=i}},Dr;(function(t){t.Install="install",t.Reinstall="reinstall",t.Upgrade="upgrade"})(Dr||(Dr={}));var it=Symbol.for("ic-agent-metadata"),Wt=class t{constructor(e){this[it]=Object.freeze(e)}static agentOf(e){return e[it].config.agent}static interfaceOf(e){return e[it].service}static canisterIdOf(e){return B.from(e[it].config.canisterId)}static async install(e,r){let n=e.mode===void 0?Dr.Install:e.mode,i=e.arg?[...new Uint8Array(e.arg)]:[],o=[...new Uint8Array(e.module)],s=typeof r.canisterId=="string"?B.fromText(r.canisterId):r.canisterId;await Wi(r).install_code({mode:{[n]:null},arg:i,wasm_module:o,canister_id:s})}static async createCanister(e){let{canister_id:r}=await Wi(e||{}).provisional_create_canister_with_cycles({amount:[],settings:[]});return r}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:he});class i extends t{constructor(s){if(!s.canisterId)throw new qt(`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"?B.fromText(s.canisterId):s.canisterId;super({config:Object.assign(Object.assign(Object.assign({},Yi),s),{canisterId:a}),service:n});for(let[c,l]of n._fields)r?.httpDetails&&l.annotations.push(Xr),this[c]=Fa(this,c,l,s.blsVerify)}}return i}static createActor(e,r){if(!r.canisterId)throw new qt(`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)}};function or(t,e){let r=he.decode(t,Gi.Buffer.from(e));switch(r.length){case 0:return;case 1:return r[0];default:return r}}var Yi={pollingStrategyFactory:ir.defaultStrategy},Xr="http-details";function Fa(t,e,r,n){let i;r.annotations.includes("query")||r.annotations.includes("composite_query")?i=async(s,...a)=>{var c,l;s=Object.assign(Object.assign({},s),(l=(c=t[it].config).queryTransform)===null||l===void 0?void 0:l.call(c,e,a,Object.assign(Object.assign({},t[it].config),s)));let u=s.agent||t[it].config.agent||Yr(),f=B.from(s.canisterId||t[it].config.canisterId),h=he.encode(r.argTypes,a),y=await u.query(f,{methodName:e,arg:h});switch(y.status){case"rejected":throw new Zr(f,e,y);case"replied":return r.annotations.includes(Xr)?{httpDetails:y.httpDetails,result:or(r.retTypes,y.reply.arg)}:or(r.retTypes,y.reply.arg)}}:i=async(s,...a)=>{var c,l;s=Object.assign(Object.assign({},s),(l=(c=t[it].config).callTransform)===null||l===void 0?void 0:l.call(c,e,a,Object.assign(Object.assign({},t[it].config),s)));let u=s.agent||t[it].config.agent||Yr(),{canisterId:f,effectiveCanisterId:h,pollingStrategyFactory:y}=Object.assign(Object.assign(Object.assign({},Yi),t[it].config),s),g=B.from(f),w=h!==void 0?B.from(h):g,A=he.encode(r.argTypes,a),{requestId:S,response:P}=await u.call(g,{methodName:e,arg:A,effectiveCanisterId:w});if(!P.ok||P.body)throw new Jr(g,e,S,P);let T=y(),k=await zr(u,w,S,T,n),E=r.annotations.includes(Xr);if(k!==void 0)return E?{httpDetails:P,result:or(r.retTypes,k)}:or(r.retTypes,k);if(r.retTypes.length===0)return E?{httpDetails:P,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 Wi(t){function e(r,n,i){let o=n[0],s=B.fromHex("");return o&&typeof o=="object"&&o.canister_id&&(s=B.from(o.canister_id)),{effectiveCanisterId:s}}return Wt.createActor(Vi,Object.assign(Object.assign(Object.assign({},t),{canisterId:B.fromHex("")}),{callTransform:e,queryTransform:e}))}var lr=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},It=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)},ar,cr,le,ue,Gt=class t{constructor(e){if(ar.set(this,void 0),cr.set(this,void 0),e.byteLength!==t.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");lr(this,ar,e,"f"),lr(this,cr,t.derEncode(e),"f")}static from(e){return this.fromDer(e.toDer())}static fromRaw(e){return new t(e)}static fromDer(e){return new t(this.derDecode(e))}static derEncode(e){return ie(e,$t).buffer}static derDecode(e){let r=Ee(e,$t);if(r.length!==this.RAW_KEY_LENGTH)throw new Error("An Ed25519 public key must be exactly 32bytes long");return r}get rawKey(){return It(this,ar,"f")}get derKey(){return It(this,cr,"f")}toDer(){return this.derKey}toRaw(){return this.rawKey}};ar=new WeakMap,cr=new WeakMap;Gt.RAW_KEY_LENGTH=32;var Yt=class t extends Tt{constructor(e,r){super(),le.set(this,void 0),ue.set(this,void 0),lr(this,le,Gt.from(e),"f"),lr(this,ue,new Uint8Array(r),"f")}static generate(e=new Uint8Array(32)){if(e&&e.length!==32)throw new Error("Ed25519 Seed needs to be 32 bytes long.");e||(e=kt.utils.randomPrivateKey());let r=new Uint8Array(32);for(let i=0;i<32;i++)r[i]=new Uint8Array(e)[i];let n=kt.getPublicKey(r);return t.fromKeyPair(n,r)}static fromParsedJson(e){let[r,n]=e;return new t(Gt.fromDer(bt(r)),bt(n))}static fromJSON(e){let r=JSON.parse(e);if(Array.isArray(r)){if(typeof r[0]=="string"&&typeof r[1]=="string")return this.fromParsedJson([r[0],r[1]]);throw new Error("Deserialization error: JSON must have at least 2 items.")}throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(e)}`)}static fromKeyPair(e,r){return new t(Gt.fromRaw(e),r)}static fromSecretKey(e){let r=kt.getPublicKey(new Uint8Array(e));return t.fromKeyPair(r,e)}toJSON(){return[H(It(this,le,"f").toDer()),H(It(this,ue,"f"))]}getKeyPair(){return{secretKey:It(this,ue,"f"),publicKey:It(this,le,"f")}}getPublicKey(){return It(this,le,"f")}async sign(e){let r=new Uint8Array(e),n=Cn(kt.sign(r,It(this,ue,"f").slice(0,32)));return Object.defineProperty(n,"__signature__",{enumerable:!1,value:void 0}),n}static verify(e,r,n){let[i,o,s]=[e,r,n].map(a=>(typeof a=="string"&&(a=bt(a)),a instanceof Uint8Array&&(a=a.buffer),new Uint8Array(a)));return kt.verify(o,i,s)}};le=new WeakMap,ue=new WeakMap;var Qr=class t extends Error{constructor(e){super(e),this.message=e,Object.setPrototypeOf(this,t.prototype)}};function zi(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 Qr("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 Se=class t extends Tt{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=zi(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=zi(r),i=await n.exportKey("spki",e.publicKey);return new t(e,i,n)}getKeyPair(){return this._keyPair}getPublicKey(){let e=this._derKey,r=Object.create(this._keyPair.publicKey);return r.toDer=function(){return e},r}async sign(e){let r={name:"ECDSA",hash:{name:"SHA-256"}};return this._keyPair.privateKey,await this._subtleCrypto.sign(r,this._keyPair.privateKey,e)}};var de=Ie(Un()),Ia=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},qa=new TextEncoder().encode("ic-request-auth-delegation"),Ka=new TextEncoder().encode(`
24
+ ic-request`);function Lr(t){if(typeof t!="string"||t.length<64)throw new Error("Invalid public key.");return bt(t)}var fe=class{constructor(e,r,n){this.pubkey=e,this.expiration=r,this.targets=n}toCBOR(){return de.value.map(Object.assign({pubkey:de.value.bytes(this.pubkey),expiration:de.value.u64(this.expiration.toString(16),16)},this.targets&&{targets:de.value.array(this.targets.map(e=>de.value.bytes(e.toUint8Array())))}))}toJSON(){return Object.assign({expiration:this.expiration.toString(16),pubkey:H(this.pubkey)},this.targets&&{targets:this.targets.map(e=>e.toHex())})}};async function Ma(t,e,r,n){let i=new fe(e.toDer(),BigInt(+r)*BigInt(1e6),n),o=new Uint8Array([...qa,...new Uint8Array(Pt(i))]),s=await t.sign(o);return{delegation:i,signature:s}}var ve=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 Ma(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:c,expiration:l,targets:u}=s;if(u!==void 0&&!Array.isArray(u))throw new Error("Invalid targets.");return{delegation:new fe(Lr(c),BigInt("0x"+l),u&&u.map(f=>{if(typeof f!="string")throw new Error("Invalid target.");return B.fromHex(f)})),signature:Lr(a)}});return new this(i,Lr(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:H(r.pubkey)},i&&{targets:i.map(o=>o.toHex())}),signature:H(n)}}),publicKey:H(this.publicKey)}}},Oe=class extends Tt{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=Ia(e,["body"]),i=await Pt(r);return Object.assign(Object.assign({},n),{body:{content:r,sender_sig:await this.sign(new Uint8Array([...Ka,...new Uint8Array(i)])),sender_delegation:this._delegation.delegations,sender_pubkey:this._delegation.publicKey}})}};function Zi(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"?B.fromText(i):i)):r.push(typeof n=="string"?B.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 c of s.targets)if(c.toText()===o){a=!1;break}if(a)return!1}}return!0}var Ha=Ie(Ko());var Ji;(function(t){t[t.ECDSA_WITH_SHA256=-7]="ECDSA_WITH_SHA256"})(Ji||(Ji={}));var Di=["mousedown","mousemove","keydown","touchstart","wheel"],Re=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),Di.forEach(function(a){document.addEventListener(a,o,!0)});let s=(a,c)=>{let l;return(...u)=>{let f=this,h=function(){l=void 0,a.apply(f,u)};clearTimeout(l),l=window.setTimeout(h,c)}};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);Di.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 ja=(t,e)=>e.some(r=>t instanceof r),Xi,Qi;function $a(){return Xi||(Xi=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Va(){return Qi||(Qi=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}var Li=new WeakMap,en=new WeakMap,to=new WeakMap,tn=new WeakMap,nn=new WeakMap;function Wa(t){let e=new Promise((r,n)=>{let i=()=>{t.removeEventListener("success",o),t.removeEventListener("error",s)},o=()=>{r(mt(t.result)),i()},s=()=>{n(t.error),i()};t.addEventListener("success",o),t.addEventListener("error",s)});return e.then(r=>{r instanceof IDBCursor&&Li.set(r,t)}).catch(()=>{}),nn.set(e,t),e}function Ga(t){if(en.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)});en.set(t,e)}var rn={get(t,e,r){if(t instanceof IDBTransaction){if(e==="done")return en.get(t);if(e==="objectStoreNames")return t.objectStoreNames||to.get(t);if(e==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return mt(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 eo(t){rn=t(rn)}function Ya(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...r){let n=t.call(ur(this),e,...r);return to.set(n,e.sort?e.sort():[e]),mt(n)}:Va().includes(t)?function(...e){return t.apply(ur(this),e),mt(Li.get(this))}:function(...e){return mt(t.apply(ur(this),e))}}function za(t){return typeof t=="function"?Ya(t):(t instanceof IDBTransaction&&Ga(t),ja(t,$a())?new Proxy(t,rn):t)}function mt(t){if(t instanceof IDBRequest)return Wa(t);if(tn.has(t))return tn.get(t);let e=za(t);return e!==t&&(tn.set(t,e),nn.set(e,t)),e}var ur=t=>nn.get(t);function no(t,e,{blocked:r,upgrade:n,blocking:i,terminated:o}={}){let s=indexedDB.open(t,e),a=mt(s);return n&&s.addEventListener("upgradeneeded",c=>{n(mt(s.result),c.oldVersion,c.newVersion,mt(s.transaction),c)}),r&&s.addEventListener("blocked",c=>r(c.oldVersion,c.newVersion,c)),a.then(c=>{o&&c.addEventListener("close",()=>o()),i&&c.addEventListener("versionchange",l=>i(l.oldVersion,l.newVersion,l))}).catch(()=>{}),a}var Za=["get","getKey","getAll","getAllKeys","count"],Ja=["put","add","delete","clear"],on=new Map;function ro(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(on.get(e))return on.get(e);let r=e.replace(/FromIndex$/,""),n=e!==r,i=Ja.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(i||Za.includes(r)))return;let o=async function(s,...a){let c=this.transaction(s,i?"readwrite":"readonly"),l=c.store;return n&&(l=l.index(a.shift())),(await Promise.all([l[r](...a),i&&c.done]))[0]};return on.set(e,o),o}eo(t=>({...t,get:(e,r,n)=>ro(e,r)||t.get(e,r,n),has:(e,r)=>!!ro(e,r)||t.has(e,r)}));var io="auth-client-db",oo="ic-keyval",Da=async(t=io,e=oo,r)=>(dr&&(localStorage!=null&&localStorage.getItem(ct))&&(localStorage.removeItem(ct),localStorage.removeItem(lt)),await no(t,r,{upgrade:n=>{n.objectStoreNames,n.objectStoreNames.contains(e)&&n.clear(e),n.createObjectStore(e)}}));async function Xa(t,e,r){return await t.get(e,r)}async function Qa(t,e,r,n){return await t.put(e,n,r)}async function La(t,e,r){return await t.delete(e,r)}var Ne=class t{constructor(e,r){this._db=e,this._storeName=r}static async create(e){let{dbName:r=io,storeName:n=oo,version:i=1}=e??{},o=await Da(r,n,i);return new t(o,n)}async set(e,r){return await Qa(this._db,this._storeName,e,r)}async get(e){var r;return(r=await Xa(this._db,this._storeName,e))!==null&&r!==void 0?r:null}async remove(e){return await La(this._db,this._storeName,e)}};var lt="identity",ct="delegation",so="iv",tc=1,dr=typeof window<"u",Pe=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}},Ce=class{get _db(){return new Promise(e=>{if(this.initializedDb){e(this.initializedDb);return}Ne.create({version:tc}).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)}};var ec="https://identity.ic0.app",rc="#authorize",sn="ECDSA",an="Ed25519",nc=500,ic="UserInterrupt",fr=class{constructor(e,r,n,i,o,s,a,c){var l;this._identity=e,this._key=r,this._chain=n,this._storage=i,this.idleManager=o,this._createOptions=s,this._idpWindow=a,this._eventHandler=c;let u=this.logout.bind(this),f=s?.idleOptions;!f?.onIdle&&!f?.disableDefaultIdleCallback&&((l=this.idleManager)===null||l===void 0||l.registerCallback(()=>{u(),location.reload()}))}static async create(e={}){var r,n,i;let o=(r=e.storage)!==null&&r!==void 0?r:new Ce,s=(n=e.keyType)!==null&&n!==void 0?n:sn,a=null;if(e.identity)a=e.identity;else{let f=await o.get(lt);if(!f&&dr)try{let h=new Pe,y=await h.get(ct),g=await h.get(lt);y&&g&&s===sn&&(console.log("Discovered an identity stored in localstorage. Migrating to IndexedDB"),await o.set(ct,y),await o.set(lt,g),f=y,await h.remove(ct),await h.remove(lt))}catch(h){console.error("error while attempting to recover localstorage: "+h)}if(f)try{typeof f=="object"?s===an&&typeof f=="string"?a=await Yt.fromJSON(f):a=await Se.fromKeyPair(f):typeof f=="string"&&(a=Yt.fromJSON(f))}catch{}}let c=new Bt,l=null;if(a)try{let f=await o.get(ct);if(typeof f=="object"&&f!==null)throw new Error("Delegation chain is incorrectly stored. A delegation chain should be stored as a string.");e.identity?c=e.identity:f&&(l=ve.fromJSON(f),Zi(l)?c=Oe.fromDelegation(a,l):(await cn(o),a=null))}catch(f){console.error(f),await cn(o),a=null}let u;return!((i=e.idleOptions)===null||i===void 0)&&i.disableIdle?u=void 0:(l||e.identity)&&(u=Re.create(e.idleOptions)),a||(s===an?(a=await Yt.generate(),await o.set(lt,JSON.stringify(a.toJSON()))):(e.storage&&s===sn&&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 '${an}' as the key type, as it can serialize to a string`),a=await Se.generate(),await o.set(lt,a.getKeyPair()))),new this(c,a,l,o,u,e)}async _handleSuccess(e,r){var n,i,o;let s=e.delegations.map(l=>({delegation:new fe(l.delegation.pubkey,l.delegation.expiration,l.delegation.targets),signature:l.signature.buffer})),a=ve.fromDelegations(s,e.userPublicKey.buffer),c=this._key;if(c){if(this._chain=a,this._identity=Oe.fromDelegation(c,this._chain),(n=this._idpWindow)===null||n===void 0||n.close(),!this.idleManager){let l=(i=this._createOptions)===null||i===void 0?void 0:i.idleOptions;this.idleManager=Re.create(l),!l?.onIdle&&!l?.disableDefaultIdleCallback&&((o=this.idleManager)===null||o===void 0||o.registerCallback(()=>{this.logout(),location.reload()}))}this._removeEventListener(),delete this._idpWindow,this._chain&&await this._storage.set(ct,JSON.stringify(this._chain.toJSON())),r?.()}}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())||ec);a.hash=rc,(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 c=()=>{this._idpWindow&&(this._idpWindow.closed?this._handleFailure(ic,e?.onError):setTimeout(c,nc))};c()}_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 c={kind:"authorize-client",sessionPublicKey:new Uint8Array((i=this._key)===null||i===void 0?void 0:i.getPublicKey().toDer()),maxTimeToLive:r?.maxTimeToLive,derivationOrigin:(o=r?.derivationOrigin)===null||o===void 0?void 0:o.toString()};(s=this._idpWindow)===null||s===void 0||s.postMessage(c,e.origin);break}case"authorize-client-success":try{await this._handleSuccess(a,r?.onSuccess)}catch(c){this._handleFailure(c.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 cn(this._storage),this._identity=new Bt,this._chain=null,e.returnTo)try{window.history.pushState({},"",e.returnTo)}catch{window.location.href=e.returnTo}}};async function cn(t){await t.remove(lt),await t.remove(ct),await t.remove(so)}var pr=()=>fr.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var ao=async({data:t})=>{try{return await Me(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var ln=async t=>{let{data:e,updated_at:r,description:n}=t;return{description:V(n),data:await kn(e),updated_at:V(r)}},un=t=>{let{updated_at:e}=t;return{updated_at:V(e)}},Ue=async({doc:t,key:e})=>{let{owner:r,description:n,data:i,...o}=t;return{key:e,description:X(n),owner:r.toText(),data:await Me(i),...o}};var hr=({matcher:t,paginate:e,order:r,owner:n})=>({matcher:K(t)?[]:[{key:V(t.key),description:V(t.description)}],paginate:V(K(e)?void 0:{start_after:V(e.startAfter),limit:V(K(e.limit)?void 0:BigInt(e.limit))}),order:V(K(r)?void 0:{desc:r.desc,field:r.field==="created_at"?{CreatedAt:null}:r.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:V(K(n)?void 0:typeof n=="string"?B.fromText(n):n)});var co=({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.Record({controllers:t.Vec(t.Principal)}),n=t.Variant({Write:t.Null,Admin:t.Null}),i=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:n,expires_at:t.Opt(t.Nat64)}),o=t.Record({updated_at:t.Opt(t.Nat64)}),s=t.Variant({Db:t.Null,Storage:t.Null}),a=t.Record({cycles:t.Nat,destination_id:t.Principal}),c=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),l=t.Record({status_code:t.Nat16,location:t.Text}),u=t.Record({iframe:t.Opt(c),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),redirects:t.Opt(t.Vec(t.Tuple(t.Text,l)))}),f=t.Record({storage:u}),h=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64}),y=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)}),g=t.Variant({Heap:t.Null,Stable:t.Null}),w=t.Record({memory:g,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}),A=t.Variant({Callback:t.Record({token:w,callback:t.Func([],[],["query"])})}),S=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(A),status_code:t.Nat16}),P=t.Record({token:t.Opt(w),body:t.Vec(t.Nat8)}),T=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),k=t.Record({batch_id:t.Nat}),E=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),ot=t.Record({field:E,desc:t.Bool}),Ot=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),Y=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),z=t.Record({order:t.Opt(ot),owner:t.Opt(t.Principal),matcher:t.Opt(Ot),paginate:t.Opt(Y)}),wt=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}),ut=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),Rt=t.Record({key:wt,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,ut)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64}),xt=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,Rt)),items_length:t.Nat64}),pe=t.Record({updated_at:t.Nat64,created_at:t.Nat64,bn_id:t.Opt(t.Text)}),zt=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,h)),items_length:t.Nat64}),Zt=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),hn=t.Record({memory:t.Opt(g),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:Zt,created_at:t.Nat64,mutable_permissions:t.Opt(t.Bool),write:Zt}),m=t.Record({stable:t.Nat64,heap:t.Nat64}),p=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:n,expires_at:t.Opt(t.Nat64)}),x=t.Record({controller:p,controllers:t.Vec(t.Principal)}),_=t.Record({updated_at:t.Opt(t.Nat64),data:t.Vec(t.Nat8),description:t.Opt(t.Text)}),v=t.Record({memory:t.Opt(g),updated_at:t.Opt(t.Nat64),max_size:t.Opt(t.Nat),read:Zt,mutable_permissions:t.Opt(t.Bool),write:Zt}),O=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),R=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([r],[t.Vec(t.Tuple(t.Principal,i))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,o],[],[]),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,o))],[],[]),del_rule:t.Func([s,t.Text,o],[],[]),deposit_cycles:t.Func([a],[],[]),get_config:t.Func([],[f],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(h)],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(h)))],["query"]),http_request:t.Func([y],[S],["query"]),http_request_streaming_callback:t.Func([w],[P],["query"]),init_asset_upload:t.Func([T],[k],[]),list_assets:t.Func([t.Text,z],[xt],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,pe))],["query"]),list_docs:t.Func([t.Text,z],[zt],["query"]),list_rules:t.Func([s],[t.Vec(t.Tuple(t.Text,hn))],["query"]),memory_size:t.Func([],[m],["query"]),set_config:t.Func([f],[],[]),set_controllers:t.Func([x],[t.Vec(t.Tuple(t.Principal,i))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_doc:t.Func([t.Text,t.Text,_],[h],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,_))],[t.Vec(t.Tuple(t.Text,h))],[]),set_rule:t.Func([s,t.Text,v],[],[]),upload_asset_chunk:t.Func([O],[R],[]),version:t.Func([],[t.Text],["query"])})};var lo=async({satelliteId:t,idlFactory:e,identity:r,fetch:n,container:i})=>{let s=q(i)&&i!==!1?i===!0?Dt:i:"https://icp-api.io",a=new Be({identity:r,host:s,...n&&{fetch:n}});return q(i)&&await a.fetchRootKey(),Wt.createActor(e,{agent:a,canisterId:t})};var et=async({satelliteId:t,container:e,...r})=>{let{satelliteId:n}=q(t)?{satelliteId:t}:L.getInstance().get()??{satelliteId:void 0},{container:i}=q(e)?{container:e}:L.getInstance().get()??{container:void 0};if(!n)throw new Error("No satellite principal defined.");return lo({satelliteId:n,container:i,idlFactory:co,...r})};var uo=async({collection:t,key:e,satellite:r})=>{let n=await et(r),i=X(await n.get_doc(t,e));if(!K(i))return Ue({doc:i,key:e})},fo=async({docs:t,satellite:e})=>{let{get_many_docs:r}=await et(e),n=t.map(({collection:s,key:a})=>[s,a]),i=await r(n),o=[];for(let[s,a]of i){let c=X(a);o.push(q(c)?await Ue({key:s,doc:c}):void 0)}return o},po=async({collection:t,doc:e,satellite:r})=>{let{set_doc:n}=await et(r),{key:i}=e,o=await ln(e),s=await n(t,i,o);return await Ue({key:i,doc:s})},ho=async({docs:t,satellite:e})=>{let{set_many_docs:r}=await et(e),n=[];for(let{collection:s,doc:a}of t){let{key:c}=a;n.push([s,c,await ln(a)])}let i=await r(n),o=[];for(let[s,a]of i)o.push(await Ue({key:s,doc:a}));return o},yo=async({collection:t,doc:e,satellite:r})=>{let{del_doc:n}=await et(r),{key:i}=e;return n(t,i,un(e))},mo=async({docs:t,satellite:e})=>{let{del_many_docs:r}=await et(e),n=t.map(({collection:i,doc:o})=>[i,o.key,un(o)]);await r(n)},go=async({collection:t,filter:e,satellite:r})=>{let n=await et(r),{items:i,items_page:o,items_length:s,matches_length:a,matches_pages:c}=await n.list_docs(t,hr(e)),l=[];for(let[u,f]of i){let{data:h,owner:y,description:g,...w}=f;l.push({key:u,description:X(g),owner:y.toText(),data:await ao({data:h}),...w})}return{items:l,items_length:s,items_page:X(o),matches_length:a,matches_pages:X(c)}};var rt=t=>t!==void 0?t:yr()??new Bt;var wo=async({satellite:t,...e})=>{let r=rt(t?.identity);return uo({...e,satellite:{...t,identity:r}})},Gd=async({satellite:t,...e})=>{let r=rt(t?.identity);return fo({...e,satellite:{...t,identity:r}})},xo=async({satellite:t,...e})=>{let r=rt(t?.identity);return po({...e,satellite:{...t,identity:r}})},Yd=async({satellite:t,...e})=>{let r=rt(t?.identity);return ho({...e,satellite:{...t,identity:r}})},zd=async({satellite:t,...e})=>{let r=rt(t?.identity);return yo({...e,satellite:{...t,identity:r}})},Zd=async({satellite:t,...e})=>{let r=rt(t?.identity);return mo({...e,satellite:{...t,identity:r}})},Jd=async({satellite:t,filter:e,...r})=>{let n=rt(t?.identity);return go({...r,filter:e??{},satellite:{...t,identity:n}})};var _o=async t=>{let e=yr();if(K(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let r=e.getPrincipal().toText(),n=await wo({collection:"#user",key:r});return K(n)?await oc({userId:r,provider:t}):n},oc=async({userId:t,...e})=>xo({collection:"#user",doc:{key:t,data:e}});var gt,dn=async t=>{if(gt=gt??await pr(),!(await gt?.isAuthenticated()??!1))return;let r=await _o(t);Et.getInstance().set(r)},sc=async t=>new Promise(async(e,r)=>{gt=gt??await pr();let n=t?.provider??new je({});await gt.login({onSuccess:async()=>{await dn(n.id),e()},onError:i=>r(i),maxTimeToLive:t?.maxTimeToLive??In,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...n.signInOptions({windowed:t?.windowed})})}),fn=async()=>{await gt?.logout(),gt=void 0,Et.getInstance().reset()},yr=()=>gt?.getIdentity(),ac=async()=>(gt??await pr()).getIdentity();var bo=t=>{let e=t===!0?"./workers/auth.worker.js":t,r=new Worker(e),n=async()=>{Er({message:"junoSignOutAuthTimer"}),await fn()};return r.onmessage=async({data:i})=>{let{msg:o,data:s}=i;switch(o){case"junoSignOutAuthTimer":await n();return;case"junoDelegationRemainingTime":Er({message:"junoDelegationRemainingTime",detail:s?.authRemainingTime});return}},Et.getInstance().subscribe(i=>{if(K(i)){r.postMessage({msg:"junoStopAuthTimer"});return}r.postMessage({msg:"junoStartAuthTimer"})})};var Eo=async({data:t,filename:e,collection:r,headers:n,token:i,fullPath:o,encoding:s,description:a,satellite:c})=>{let l=await et(c),{batch_id:u}=await l.init_asset_upload({collection:r,full_path:o,name:e,token:V(i),encoding_type:V(s),description:V(a)}),f=19e5,h=[],y=He()?new Blob([await t.arrayBuffer()]):t,g=0n;for(let S=0;S<y.size;S+=f){let P=y.slice(S,S+f);h.push({batchId:u,chunk:P,actor:l,orderId:g}),g++}let w=[];for await(let S of cc({uploadChunks:h}))w=[...w,...S];let A=n.find(([S,P])=>S.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await l.commit_asset_upload({batch_id:u,chunk_ids:w.map(({chunk_id:S})=>S),headers:[...n,...A||[]]})};async function*cc({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(o=>lc(o)))}}var lc=async({batchId:t,chunk:e,actor:r,orderId:n})=>r.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:V(n)}),Ao=async({collection:t,satellite:e,filter:r})=>{let n=await et(e),{items:i,items_length:o,items_page:s,matches_length:a,matches_pages:c}=await n.list_assets(t,hr(r));return{items:i.map(([l,u])=>u),items_length:o,items_page:X(s),matches_length:a,matches_pages:X(c)}},To=async({collection:t,fullPath:e,satellite:r})=>(await et(r)).del_asset(t,e),Bo=async({assets:t,satellite:e})=>{let{del_many_assets:r}=await et(e),n=t.map(({collection:i,fullPath:o})=>[i,o]);await r(n)};var So=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var pn=()=>{let t=L.getInstance().get()?.satelliteId??"unknown",e=L.getInstance().get()?.container;if(q(e)&&e!==!1){let{host:r,protocol:n}=new URL(e===!0?Dt:e);return`${n}//${t}.${r.replace("127.0.0.1","localhost")}`}return`https://${t}.icp0.io`};var vf=async t=>vo(t),Of=async t=>vo({filename:t.data.name,...t}),vo=async({filename:t,data:e,collection:r,headers:n=[],fullPath:i,token:o,satellite:s,encoding:a,description:c})=>{let l=rt(s?.identity),u=decodeURI(t),f=i??`/${r}/${u}`;return await Eo({data:e,filename:u,collection:r,token:o,headers:n,fullPath:f,encoding:a,satellite:{...s,identity:l},description:c}),{downloadUrl:`${pn()}${f}${o!==void 0?`?token=${o}`:""}`,fullPath:f,name:u}},Rf=async({collection:t,satellite:e,filter:r})=>{let{items:n,...i}=await Ao({collection:t,satellite:{...e,identity:rt(e?.identity)},filter:r??{}}),o=pn();return{assets:n.map(({key:{full_path:s,token:a,name:c,owner:l,description:u},headers:f,encodings:h,created_at:y,updated_at:g})=>{let w=X(a);return{fullPath:s,description:X(u),name:c,downloadUrl:`${o}${s}${w!==void 0?`?token=${w}`:""}`,token:w,headers:f,encodings:h.reduce((A,[S,{modified:P,sha256:T,total_length:k}])=>({...A,[S]:{modified:P,sha256:So(T),total_length:k}}),{}),owner:l.toText(),created_at:y,updated_at:g}}),...i}},Nf=async({collection:t,fullPath:e,satellite:r})=>To({collection:t,fullPath:e,satellite:{...r,identity:rt(r?.identity)}}),Pf=async({assets:t,satellite:e})=>Bo({assets:t,satellite:{...e,identity:rt(e?.identity)}});var qf=async t=>{L.getInstance().set(t),await dn();let e=t.workers?.auth!==void 0?bo(t.workers.auth):void 0;return[...e?[e]:[]]},Kf=t=>Et.getInstance().subscribe(t);export{je as InternetIdentityProvider,jn as NFIDProvider,Kf as authSubscribe,Nf as deleteAsset,zd as deleteDoc,Pf as deleteManyAssets,Zd as deleteManyDocs,wo as getDoc,Gd as getManyDocs,qf as initJuno,Rf as listAssets,Jd as listDocs,xo as setDoc,Yd as setManyDocs,sc as signIn,fn as signOut,ac as unsafeIdentity,vf as uploadBlob,Of as uploadFile};
25
25
  /*! Bundled license information:
26
26
 
27
27
  buffer/index.js: