shogun-button-react 6.9.8 → 6.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- var e;e=e=>(()=>{var t={526(e,t){t.byteLength=function(e){var t=a(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,i=a(e),s=i[0],c=i[1],u=new o(function(e,t,n){return 3*(t+n)/4-n}(0,s,c)),l=0,f=c>0?s-4:s;for(n=0;n<f;n+=4)t=r[e.charCodeAt(n)]<<18|r[e.charCodeAt(n+1)]<<12|r[e.charCodeAt(n+2)]<<6|r[e.charCodeAt(n+3)],u[l++]=t>>16&255,u[l++]=t>>8&255,u[l++]=255&t;return 2===c&&(t=r[e.charCodeAt(n)]<<2|r[e.charCodeAt(n+1)]>>4,u[l++]=255&t),1===c&&(t=r[e.charCodeAt(n)]<<10|r[e.charCodeAt(n+1)]<<4|r[e.charCodeAt(n+2)]>>2,u[l++]=t>>8&255,u[l++]=255&t),u},t.fromByteArray=function(e){for(var t,r=e.length,o=r%3,i=[],s=16383,a=0,c=r-o;a<c;a+=s)i.push(u(e,a,a+s>c?c:a+s));return 1===o?(t=e[r-1],i.push(n[t>>2]+n[t<<4&63]+"==")):2===o&&(t=(e[r-2]<<8)+e[r-1],i.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"=")),i.join("")};for(var n=[],r=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)n[s]=i[s],r[i.charCodeAt(s)]=s;function a(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function c(e){return n[e>>18&63]+n[e>>12&63]+n[e>>6&63]+n[63&e]}function u(e,t,n){for(var r,o=[],i=t;i<n;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(c(r));return o.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},287(e,t,n){const r=n(526),o=n(251),i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.hp=c,t.IS=50;const s=2147483647;function a(e){if(e>s)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,c.prototype),t}function c(e,t,n){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return u(e,t,n)}function u(e,t,n){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!c.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const n=0|g(e,t);let r=a(n);const o=r.write(e,t);return o!==n&&(r=r.slice(0,o)),r}(e,t);if(ArrayBuffer.isView(e))return function(e){if(J(e,Uint8Array)){const t=new Uint8Array(e);return d(t.buffer,t.byteOffset,t.byteLength)}return h(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(J(e,ArrayBuffer)||e&&J(e.buffer,ArrayBuffer))return d(e,t,n);if("undefined"!=typeof SharedArrayBuffer&&(J(e,SharedArrayBuffer)||e&&J(e.buffer,SharedArrayBuffer)))return d(e,t,n);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const r=e.valueOf&&e.valueOf();if(null!=r&&r!==e)return c.from(r,t,n);const o=function(e){if(c.isBuffer(e)){const t=0|p(e.length),n=a(t);return 0===n.length||e.copy(n,0,0,t),n}return void 0!==e.length?"number"!=typeof e.length||Q(e.length)?a(0):h(e):"Buffer"===e.type&&Array.isArray(e.data)?h(e.data):void 0}(e);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return c.from(e[Symbol.toPrimitive]("string"),t,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return l(e),a(e<0?0:0|p(e))}function h(e){const t=e.length<0?0:0|p(e.length),n=a(t);for(let r=0;r<t;r+=1)n[r]=255&e[r];return n}function d(e,t,n){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(n||0))throw new RangeError('"length" is outside of buffer bounds');let r;return r=void 0===t&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,t):new Uint8Array(e,t,n),Object.setPrototypeOf(r,c.prototype),r}function p(e){if(e>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|e}function g(e,t){if(c.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||J(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const n=e.length,r=arguments.length>2&&!0===arguments[2];if(!r&&0===n)return 0;let o=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return W(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return $(e).length;default:if(o)return r?-1:W(e).length;t=(""+t).toLowerCase(),o=!0}}function y(e,t,n){let r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return N(this,t,n);case"utf8":case"utf-8":return I(this,t,n);case"ascii":return C(this,t,n);case"latin1":case"binary":return O(this,t,n);case"base64":return S(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function m(e,t,n){const r=e[t];e[t]=e[n],e[n]=r}function w(e,t,n,r,o){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),Q(n=+n)&&(n=o?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof t&&(t=c.from(t,r)),c.isBuffer(t))return 0===t.length?-1:b(e,t,n,r,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):b(e,[t],n,r,o);throw new TypeError("val must be string, number or Buffer")}function b(e,t,n,r,o){let i,s=1,a=e.length,c=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,n/=2}function u(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){let r=-1;for(i=n;i<a;i++)if(u(e,i)===u(t,-1===r?0:i-r)){if(-1===r&&(r=i),i-r+1===c)return r*s}else-1!==r&&(i-=i-r),r=-1}else for(n+c>a&&(n=a-c),i=n;i>=0;i--){let n=!0;for(let r=0;r<c;r++)if(u(e,i+r)!==u(t,r)){n=!1;break}if(n)return i}return-1}function v(e,t,n,r){n=Number(n)||0;const o=e.length-n;r?(r=Number(r))>o&&(r=o):r=o;const i=t.length;let s;for(r>i/2&&(r=i/2),s=0;s<r;++s){const r=parseInt(t.substr(2*s,2),16);if(Q(r))return s;e[n+s]=r}return s}function E(e,t,n,r){return q(W(t,e.length-n),e,n,r)}function A(e,t,n,r){return q(function(e){const t=[];for(let n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function x(e,t,n,r){return q($(t),e,n,r)}function k(e,t,n,r){return q(function(e,t){let n,r,o;const i=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)n=e.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}(t,e.length-n),e,n,r)}function S(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function I(e,t,n){n=Math.min(e.length,n);const r=[];let o=t;for(;o<n;){const t=e[o];let i=null,s=t>239?4:t>223?3:t>191?2:1;if(o+s<=n){let n,r,a,c;switch(s){case 1:t<128&&(i=t);break;case 2:n=e[o+1],128==(192&n)&&(c=(31&t)<<6|63&n,c>127&&(i=c));break;case 3:n=e[o+1],r=e[o+2],128==(192&n)&&128==(192&r)&&(c=(15&t)<<12|(63&n)<<6|63&r,c>2047&&(c<55296||c>57343)&&(i=c));break;case 4:n=e[o+1],r=e[o+2],a=e[o+3],128==(192&n)&&128==(192&r)&&128==(192&a)&&(c=(15&t)<<18|(63&n)<<12|(63&r)<<6|63&a,c>65535&&c<1114112&&(i=c))}}null===i?(i=65533,s=1):i>65535&&(i-=65536,r.push(i>>>10&1023|55296),i=56320|1023&i),r.push(i),o+=s}return function(e){const t=e.length;if(t<=P)return String.fromCharCode.apply(String,e);let n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=P));return n}(r)}c.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){return!1}}(),c.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||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."),Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}}),c.poolSize=8192,c.from=function(e,t,n){return u(e,t,n)},Object.setPrototypeOf(c.prototype,Uint8Array.prototype),Object.setPrototypeOf(c,Uint8Array),c.alloc=function(e,t,n){return function(e,t,n){return l(e),e<=0?a(e):void 0!==t?"string"==typeof n?a(e).fill(t,n):a(e).fill(t):a(e)}(e,t,n)},c.allocUnsafe=function(e){return f(e)},c.allocUnsafeSlow=function(e){return f(e)},c.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==c.prototype},c.compare=function(e,t){if(J(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),J(t,Uint8Array)&&(t=c.from(t,t.offset,t.byteLength)),!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,r=t.length;for(let o=0,i=Math.min(n,r);o<i;++o)if(e[o]!==t[o]){n=e[o],r=t[o];break}return n<r?-1:r<n?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);let n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;const r=c.allocUnsafe(t);let o=0;for(n=0;n<e.length;++n){let t=e[n];if(J(t,Uint8Array))o+t.length>r.length?(c.isBuffer(t)||(t=c.from(t)),t.copy(r,o)):Uint8Array.prototype.set.call(r,t,o);else{if(!c.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(r,o)}o+=t.length}return r},c.byteLength=g,c.prototype._isBuffer=!0,c.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)m(this,t,t+1);return this},c.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)m(this,t,t+3),m(this,t+1,t+2);return this},c.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)m(this,t,t+7),m(this,t+1,t+6),m(this,t+2,t+5),m(this,t+3,t+4);return this},c.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?I(this,0,e):y.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){let e="";const n=t.IS;return e=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(e+=" ... "),"<Buffer "+e+">"},i&&(c.prototype[i]=c.prototype.inspect),c.prototype.compare=function(e,t,n,r,o){if(J(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),t<0||n>e.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&t>=n)return 0;if(r>=o)return-1;if(t>=n)return 1;if(this===e)return 0;let i=(o>>>=0)-(r>>>=0),s=(n>>>=0)-(t>>>=0);const a=Math.min(i,s),u=this.slice(r,o),l=e.slice(t,n);for(let e=0;e<a;++e)if(u[e]!==l[e]){i=u[e],s=l[e];break}return i<s?-1:s<i?1:0},c.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},c.prototype.indexOf=function(e,t,n){return w(this,e,t,n,!0)},c.prototype.lastIndexOf=function(e,t,n){return w(this,e,t,n,!1)},c.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(n)?(n>>>=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}const o=this.length-t;if((void 0===n||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");let i=!1;for(;;)switch(r){case"hex":return v(this,e,t,n);case"utf8":case"utf-8":return E(this,e,t,n);case"ascii":case"latin1":case"binary":return A(this,e,t,n);case"base64":return x(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,e,t,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const P=4096;function C(e,t,n){let r="";n=Math.min(e.length,n);for(let o=t;o<n;++o)r+=String.fromCharCode(127&e[o]);return r}function O(e,t,n){let r="";n=Math.min(e.length,n);for(let o=t;o<n;++o)r+=String.fromCharCode(e[o]);return r}function N(e,t,n){const r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);let o="";for(let r=t;r<n;++r)o+=Z[e[r]];return o}function B(e,t,n){const r=e.slice(t,n);let o="";for(let e=0;e<r.length-1;e+=2)o+=String.fromCharCode(r[e]+256*r[e+1]);return o}function T(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function R(e,t,n,r,o,i){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function U(e,t,n,r,o){H(t,r,o,e,n,7);let i=Number(t&BigInt(4294967295));e[n++]=i,i>>=8,e[n++]=i,i>>=8,e[n++]=i,i>>=8,e[n++]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[n++]=s,s>>=8,e[n++]=s,s>>=8,e[n++]=s,s>>=8,e[n++]=s,n}function D(e,t,n,r,o){H(t,r,o,e,n,7);let i=Number(t&BigInt(4294967295));e[n+7]=i,i>>=8,e[n+6]=i,i>>=8,e[n+5]=i,i>>=8,e[n+4]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[n+3]=s,s>>=8,e[n+2]=s,s>>=8,e[n+1]=s,s>>=8,e[n]=s,n+8}function L(e,t,n,r,o,i){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function F(e,t,n,r,i){return t=+t,n>>>=0,i||L(e,0,n,4),o.write(e,t,n,r,23,4),n+4}function _(e,t,n,r,i){return t=+t,n>>>=0,i||L(e,0,n,8),o.write(e,t,n,r,52,8),n+8}c.prototype.slice=function(e,t){const n=this.length;(e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e);const r=this.subarray(e,t);return Object.setPrototypeOf(r,c.prototype),r},c.prototype.readUintLE=c.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||T(e,t,this.length);let r=this[e],o=1,i=0;for(;++i<t&&(o*=256);)r+=this[e+i]*o;return r},c.prototype.readUintBE=c.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||T(e,t,this.length);let r=this[e+--t],o=1;for(;t>0&&(o*=256);)r+=this[e+--t]*o;return r},c.prototype.readUint8=c.prototype.readUInt8=function(e,t){return e>>>=0,t||T(e,1,this.length),this[e]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,t){return e>>>=0,t||T(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,t){return e>>>=0,t||T(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,t){return e>>>=0,t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,t){return e>>>=0,t||T(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readBigUInt64LE=Y(function(e){z(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||K(e,this.length-8);const r=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,o=this[++e]+256*this[++e]+65536*this[++e]+n*2**24;return BigInt(r)+(BigInt(o)<<BigInt(32))}),c.prototype.readBigUInt64BE=Y(function(e){z(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||K(e,this.length-8);const r=t*2**24+65536*this[++e]+256*this[++e]+this[++e],o=this[++e]*2**24+65536*this[++e]+256*this[++e]+n;return(BigInt(r)<<BigInt(32))+BigInt(o)}),c.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||T(e,t,this.length);let r=this[e],o=1,i=0;for(;++i<t&&(o*=256);)r+=this[e+i]*o;return o*=128,r>=o&&(r-=Math.pow(2,8*t)),r},c.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||T(e,t,this.length);let r=t,o=1,i=this[e+--r];for(;r>0&&(o*=256);)i+=this[e+--r]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i},c.prototype.readInt8=function(e,t){return e>>>=0,t||T(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){e>>>=0,t||T(e,2,this.length);const n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt16BE=function(e,t){e>>>=0,t||T(e,2,this.length);const n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt32LE=function(e,t){return e>>>=0,t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return e>>>=0,t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readBigInt64LE=Y(function(e){z(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||K(e,this.length-8);const r=this[e+4]+256*this[e+5]+65536*this[e+6]+(n<<24);return(BigInt(r)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)}),c.prototype.readBigInt64BE=Y(function(e){z(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||K(e,this.length-8);const r=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(r)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+n)}),c.prototype.readFloatLE=function(e,t){return e>>>=0,t||T(e,4,this.length),o.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return e>>>=0,t||T(e,4,this.length),o.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return e>>>=0,t||T(e,8,this.length),o.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return e>>>=0,t||T(e,8,this.length),o.read(this,e,!1,52,8)},c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||R(this,e,t,n,Math.pow(2,8*n)-1,0);let o=1,i=0;for(this[t]=255&e;++i<n&&(o*=256);)this[t+i]=e/o&255;return t+n},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||R(this,e,t,n,Math.pow(2,8*n)-1,0);let o=n-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+n},c.prototype.writeUint8=c.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,1,255,0),this[t]=255&e,t+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigUInt64LE=Y(function(e,t=0){return U(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=Y(function(e,t=0){return D(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t>>>=0,!r){const r=Math.pow(2,8*n-1);R(this,e,t,n,r-1,-r)}let o=0,i=1,s=0;for(this[t]=255&e;++o<n&&(i*=256);)e<0&&0===s&&0!==this[t+o-1]&&(s=1),this[t+o]=(e/i|0)-s&255;return t+n},c.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t>>>=0,!r){const r=Math.pow(2,8*n-1);R(this,e,t,n,r-1,-r)}let o=n-1,i=1,s=0;for(this[t+o]=255&e;--o>=0&&(i*=256);)e<0&&0===s&&0!==this[t+o+1]&&(s=1),this[t+o]=(e/i|0)-s&255;return t+n},c.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},c.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigInt64LE=Y(function(e,t=0){return U(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=Y(function(e,t=0){return D(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeFloatLE=function(e,t,n){return F(this,e,t,!0,n)},c.prototype.writeFloatBE=function(e,t,n){return F(this,e,t,!1,n)},c.prototype.writeDoubleLE=function(e,t,n){return _(this,e,t,!0,n)},c.prototype.writeDoubleBE=function(e,t,n){return _(this,e,t,!1,n)},c.prototype.copy=function(e,t,n,r){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);const o=r-n;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,n,r):Uint8Array.prototype.set.call(e,this.subarray(n,r),t),o},c.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!c.isEncoding(r))throw new TypeError("Unknown encoding: "+r);if(1===e.length){const t=e.charCodeAt(0);("utf8"===r&&t<128||"latin1"===r)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;let o;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(o=t;o<n;++o)this[o]=e;else{const i=c.isBuffer(e)?e:c.from(e,r),s=i.length;if(0===s)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-t;++o)this[o+t]=i[o%s]}return this};const M={};function j(e,t,n){M[e]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function G(e){let t="",n=e.length;const r="-"===e[0]?1:0;for(;n>=r+4;n-=3)t=`_${e.slice(n-3,n)}${t}`;return`${e.slice(0,n)}${t}`}function H(e,t,n,r,o,i){if(e>n||e<t){const r="bigint"==typeof t?"n":"";let o;throw o=i>3?0===t||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(i+1)}${r}`:`>= -(2${r} ** ${8*(i+1)-1}${r}) and < 2 ** ${8*(i+1)-1}${r}`:`>= ${t}${r} and <= ${n}${r}`,new M.ERR_OUT_OF_RANGE("value",o,e)}!function(e,t,n){z(t,"offset"),void 0!==e[t]&&void 0!==e[t+n]||K(t,e.length-(n+1))}(r,o,i)}function z(e,t){if("number"!=typeof e)throw new M.ERR_INVALID_ARG_TYPE(t,"number",e)}function K(e,t,n){if(Math.floor(e)!==e)throw z(e,n),new M.ERR_OUT_OF_RANGE(n||"offset","an integer",e);if(t<0)throw new M.ERR_BUFFER_OUT_OF_BOUNDS;throw new M.ERR_OUT_OF_RANGE(n||"offset",`>= ${n?1:0} and <= ${t}`,e)}j("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),j("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),j("ERR_OUT_OF_RANGE",function(e,t,n){let r=`The value of "${e}" is out of range.`,o=n;return Number.isInteger(n)&&Math.abs(n)>2**32?o=G(String(n)):"bigint"==typeof n&&(o=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(o=G(o)),o+="n"),r+=` It must be ${t}. Received ${o}`,r},RangeError);const V=/[^+/0-9A-Za-z-_]/g;function W(e,t){let n;t=t||1/0;const r=e.length;let o=null;const i=[];for(let s=0;s<r;++s){if(n=e.charCodeAt(s),n>55295&&n<57344){if(!o){if(n>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(t-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((t-=1)<0)break;i.push(n)}else if(n<2048){if((t-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function $(e){return r.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(V,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function q(e,t,n,r){let o;for(o=0;o<r&&!(o+n>=t.length||o>=e.length);++o)t[o+n]=e[o];return o}function J(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Q(e){return e!=e}const Z=function(){const e="0123456789abcdef",t=new Array(256);for(let n=0;n<16;++n){const r=16*n;for(let o=0;o<16;++o)t[r+o]=e[n]+e[o]}return t}();function Y(e){return"undefined"==typeof BigInt?X:e}function X(){throw new Error("BigInt not supported")}},208(e,t,n){n.d(t,{A:()=>a});var r=n(601),o=n.n(r),i=n(314),s=n.n(i)()(o());s.push([e.id,'/* Base styles */\n:root {\n --shogun-primary: #3b82f6;\n --shogun-primary-hover: #2563eb;\n --shogun-secondary: #6b7280;\n --shogun-success: #10b981;\n --shogun-danger: #ef4444;\n --shogun-warning: #f59e0b;\n --shogun-text: #1f2937;\n --shogun-text-secondary: #6b7280;\n --shogun-bg: #ffffff;\n --shogun-bg-secondary: #f3f4f6;\n --shogun-border: #e5e7eb;\n --shogun-border-radius: 12px;\n --shogun-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);\n --shogun-transition: all 0.2s ease;\n --shogun-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;\n}\n\n/* Dark mode support */\n@media (prefers-color-scheme: dark) {\n :root {\n --shogun-text: #f3f4f6;\n --shogun-text-secondary: #9ca3af;\n --shogun-bg: #1f2937;\n --shogun-bg-secondary: #374151;\n --shogun-border: #4b5563;\n }\n}\n\n/* Connect Button */\n.shogun-connect-button {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n background-color: var(--shogun-primary);\n color: white;\n border: none;\n border-radius: var(--shogun-border-radius);\n padding: 10px 16px;\n font-family: var(--shogun-font);\n font-weight: 600;\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n box-shadow: var(--shogun-shadow);\n}\n\n.shogun-connect-button:hover {\n background-color: var(--shogun-primary-hover);\n}\n\n.shogun-connect-button:focus {\n outline: none;\n box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);\n}\n\n/* Logged in state */\n.shogun-logged-in-container {\n position: relative;\n}\n\n.shogun-dropdown {\n position: relative;\n}\n\n.shogun-button.shogun-logged-in {\n display: flex;\n align-items: center;\n gap: 8px;\n background-color: var(--shogun-bg-secondary);\n color: var(--shogun-text);\n border: 1px solid var(--shogun-border);\n border-radius: var(--shogun-border-radius);\n padding: 8px 12px;\n font-family: var(--shogun-font);\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n}\n\n.shogun-button.shogun-logged-in:hover {\n background-color: var(--shogun-bg);\n}\n\n.shogun-avatar {\n width: 24px;\n height: 24px;\n background-color: var(--shogun-primary);\n color: white;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n font-weight: 600;\n font-size: 12px;\n}\n\n.shogun-username {\n font-weight: 500;\n}\n\n.shogun-dropdown-menu {\n position: absolute;\n top: calc(100% + 8px);\n right: 0;\n background-color: var(--shogun-bg);\n border: 1px solid var(--shogun-border);\n border-radius: var(--shogun-border-radius);\n box-shadow: var(--shogun-shadow);\n width: 240px;\n z-index: 9999;\n overflow: hidden;\n animation: shogun-dropdown-fade 0.2s ease;\n}\n\n@keyframes shogun-dropdown-fade {\n from {\n opacity: 0;\n transform: translateY(-8px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n.shogun-dropdown-header {\n padding: 16px;\n border-bottom: 1px solid var(--shogun-border);\n display: flex;\n align-items: center;\n gap: 12px;\n}\n\n.shogun-avatar-large {\n width: 40px;\n height: 40px;\n background-color: var(--shogun-primary);\n color: white;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n font-weight: 600;\n font-size: 16px;\n}\n\n.shogun-user-info {\n display: flex;\n flex-direction: column;\n}\n\n.shogun-username-full {\n font-weight: 600;\n color: var(--shogun-text);\n font-size: 14px;\n}\n\n.shogun-dropdown-item {\n padding: 12px 16px;\n display: flex;\n align-items: center;\n gap: 12px;\n color: var(--shogun-text);\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n}\n\n.shogun-dropdown-item:hover {\n background-color: var(--shogun-bg-secondary);\n}\n\n/* Modal */\n.shogun-modal-overlay {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: rgba(0, 0, 0, 0.5);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 1000;\n animation: shogun-fade-in 0.2s ease;\n}\n\n@keyframes shogun-fade-in {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n\n.shogun-modal {\n background-color: var(--shogun-bg);\n border-radius: var(--shogun-border-radius);\n box-shadow: var(--shogun-shadow);\n width: 90%;\n max-width: 400px;\n max-height: 90vh;\n overflow-y: auto;\n animation: shogun-scale-in 0.2s ease;\n}\n\n@keyframes shogun-scale-in {\n from {\n opacity: 0;\n transform: scale(0.95);\n }\n to {\n opacity: 1;\n transform: scale(1);\n }\n}\n\n.shogun-modal-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding: 16px 20px;\n border-bottom: 1px solid var(--shogun-border);\n}\n\n.shogun-modal-header h2 {\n margin: 0;\n font-size: 1.5rem;\n font-weight: 600;\n color: var(--shogun-text);\n text-align: center;\n width: 100%;\n}\n\n.shogun-close-button {\n background: none;\n border: none;\n cursor: pointer;\n color: var(--shogun-text-secondary);\n padding: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 50%;\n transition: var(--shogun-transition);\n}\n\n.shogun-close-button:hover {\n background-color: var(--shogun-bg-secondary);\n color: var(--shogun-text);\n}\n\n.shogun-modal-content {\n padding: 20px;\n}\n\n/* Auth options */\n.shogun-auth-options {\n display: flex;\n flex-direction: column;\n gap: 12px;\n margin-bottom: 24px;\n}\n\n.shogun-auth-option-button {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 12px;\n background-color: var(--shogun-bg);\n color: var(--shogun-text);\n border: 1px solid var(--shogun-border);\n border-radius: var(--shogun-border-radius);\n padding: 12px 16px;\n font-family: var(--shogun-font);\n font-weight: 500;\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n width: 100%;\n}\n\n.shogun-auth-option-button:hover {\n background-color: var(--shogun-bg-secondary);\n}\n\n.shogun-auth-option-button:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n}\n\n.shogun-google-button {\n border-color: #4285F4;\n}\n\n/* Divider */\n.shogun-divider {\n display: flex;\n align-items: center;\n margin: 20px 0;\n color: var(--shogun-text-secondary);\n font-size: 14px;\n}\n\n.shogun-divider::before,\n.shogun-divider::after {\n content: "";\n flex: 1;\n border-bottom: 1px solid var(--shogun-border);\n}\n\n.shogun-divider span {\n padding: 0 10px;\n}\n\n/* Form */\n.shogun-auth-form {\n display: flex;\n flex-direction: column;\n gap: 16px;\n}\n\n.shogun-form-group {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.shogun-form-group label {\n display: flex;\n align-items: center;\n gap: 8px;\n font-size: 14px;\n font-weight: 500;\n color: var(--shogun-text);\n}\n\n.shogun-form-group input {\n padding: 12px;\n border: 1px solid var(--shogun-border);\n border-radius: var(--shogun-border-radius);\n background-color: var(--shogun-bg);\n color: var(--shogun-text);\n font-size: 14px;\n transition: var(--shogun-transition);\n}\n\n.shogun-form-group input:focus {\n outline: none;\n border-color: var(--shogun-primary);\n box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);\n}\n\n.shogun-submit-button {\n background-color: var(--shogun-primary);\n color: white;\n border: none;\n border-radius: var(--shogun-border-radius);\n padding: 12px 16px;\n font-family: var(--shogun-font);\n font-weight: 600;\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n margin-top: 8px;\n}\n\n.shogun-submit-button:hover:not(:disabled) {\n background-color: var(--shogun-primary-hover);\n}\n\n.shogun-submit-button:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n}\n\n/* Footer */\n.shogun-form-footer {\n margin-top: 20px;\n text-align: center;\n font-size: 14px;\n color: var(--shogun-text-secondary);\n}\n\n.shogun-toggle-mode {\n background: none;\n border: none;\n color: var(--shogun-primary);\n font-weight: 600;\n cursor: pointer;\n padding: 0;\n margin-left: 4px;\n transition: var(--shogun-transition);\n}\n\n.shogun-toggle-mode:hover {\n text-decoration: underline;\n}\n\n.shogun-toggle-mode:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n}\n\n/* Error message */\n.shogun-error-message {\n background-color: rgba(239, 68, 68, 0.1);\n color: var(--shogun-danger);\n padding: 12px;\n border-radius: var(--shogun-border-radius);\n margin-bottom: 16px;\n font-size: 14px;\n border: 1px solid rgba(239, 68, 68, 0.2);\n}\n\n.shogun-back-button {\n background: none;\n border: none;\n color: var(--shogun-text-secondary);\n cursor: pointer;\n font-size: 14px;\n margin-bottom: 16px;\n padding: 4px;\n display: flex;\n align-items: center;\n gap: 4px;\n font-weight: 500;\n transition: color 0.2s ease;\n}\n\n.shogun-back-button:hover {\n color: var(--shogun-text);\n}\n\n.shogun-prominent-toggle {\n font-weight: 600;\n color: var(--shogun-primary);\n padding: 8px 16px;\n margin-top: 16px;\n border: none;\n border-radius: 6px;\n background-color: transparent;\n transition: all 0.2s ease;\n}\n\n.shogun-prominent-toggle:hover {\n text-decoration: underline;\n}\n\n/* Redundant dark theme styles removed */ \n\n/* Advanced Options Toggle */\n.shogun-advanced-toggle {\n margin: 8px 0;\n}\n\n.shogun-toggle-advanced {\n background: none;\n border: none;\n color: var(--shogun-text-secondary);\n font-size: 13px;\n cursor: pointer;\n padding: 6px 0;\n display: flex;\n align-items: center;\n gap: 4px;\n font-weight: 500;\n transition: color 0.2s ease;\n}\n\n.shogun-toggle-advanced:hover {\n color: var(--shogun-primary);\n}\n\n/* Advanced Options Container */\n.shogun-advanced-options {\n background-color: var(--shogun-bg-secondary);\n padding: 12px;\n border-radius: var(--shogun-border-radius);\n border: 1px dashed var(--shogun-border);\n}\n\n/* Field Hint */\n.shogun-field-hint {\n font-size: 12px;\n color: var(--shogun-text-secondary);\n margin-top: 4px;\n font-style: italic;\n}',""]);const a=s},314(e){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n="",r=void 0!==t[5];return t[4]&&(n+="@supports (".concat(t[4],") {")),t[2]&&(n+="@media ".concat(t[2]," {")),r&&(n+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),n+=e(t),r&&(n+="}"),t[2]&&(n+="}"),t[4]&&(n+="}"),n}).join("")},t.i=function(e,n,r,o,i){"string"==typeof e&&(e=[[null,e,void 0]]);var s={};if(r)for(var a=0;a<this.length;a++){var c=this[a][0];null!=c&&(s[c]=!0)}for(var u=0;u<e.length;u++){var l=[].concat(e[u]);r&&s[l[0]]||(void 0!==i&&(void 0===l[5]||(l[1]="@layer".concat(l[5].length>0?" ".concat(l[5]):""," {").concat(l[1],"}")),l[5]=i),n&&(l[2]?(l[1]="@media ".concat(l[2]," {").concat(l[1],"}"),l[2]=n):l[2]=n),o&&(l[4]?(l[1]="@supports (".concat(l[4],") {").concat(l[1],"}"),l[4]=o):l[4]="".concat(o)),t.push(l))}},t}},601(e){e.exports=function(e){return e[1]}},251(e,t){t.read=function(e,t,n,r,o){var i,s,a=8*o-r-1,c=(1<<a)-1,u=c>>1,l=-7,f=n?o-1:0,h=n?-1:1,d=e[t+f];for(f+=h,i=d&(1<<-l)-1,d>>=-l,l+=a;l>0;i=256*i+e[t+f],f+=h,l-=8);for(s=i&(1<<-l)-1,i>>=-l,l+=r;l>0;s=256*s+e[t+f],f+=h,l-=8);if(0===i)i=1-u;else{if(i===c)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,r),i-=u}return(d?-1:1)*s*Math.pow(2,i-r)},t.write=function(e,t,n,r,o,i){var s,a,c,u=8*i-o-1,l=(1<<u)-1,f=l>>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:i-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+f>=1?h/c:h*Math.pow(2,1-f))*c>=2&&(s++,c/=2),s+f>=l?(a=0,s=l):s+f>=1?(a=(t*c-1)*Math.pow(2,o),s+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,o),s=0));o>=8;e[n+d]=255&a,d+=p,a/=256,o-=8);for(s=s<<o|a,u+=o;u>0;e[n+d]=255&s,d+=p,s/=256,u-=8);e[n+d-p]|=128*g}},606(e){var t,n,r=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}function s(e){if(t===setTimeout)return setTimeout(e,0);if((t===o||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:o}catch(e){t=o}try{n="function"==typeof clearTimeout?clearTimeout:i}catch(e){n=i}}();var a,c=[],u=!1,l=-1;function f(){u&&a&&(u=!1,a.length?c=a.concat(c):l=-1,c.length&&h())}function h(){if(!u){var e=s(f);u=!0;for(var t=c.length;t;){for(a=c,c=[];++l<t;)a&&a[l].run();l=-1,t=c.length}a=null,u=!1,function(e){if(n===clearTimeout)return clearTimeout(e);if((n===i||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(e);try{return n(e)}catch(t){try{return n.call(null,e)}catch(t){return n.call(this,e)}}}(e)}}function d(e,t){this.fun=e,this.array=t}function p(){}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new d(e,t)),1!==c.length||u||s(h)},d.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=p,r.addListener=p,r.once=p,r.off=p,r.removeListener=p,r.removeAllListeners=p,r.emit=p,r.prependListener=p,r.prependOnceListener=p,r.listeners=function(e){return[]},r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},937(e,t,n){n(167)},167(e,t,n){e=n.nmd(e),function(){function t(e,r){return r?n(132)(e):e.slice?t[o(e)]:function(n,r){e(n={exports:{}}),t[o(r)]=n.exports};function o(e){return e.split("/").slice(-1).toString().replace(".js","")}}var r=e;t(function(e){String.random=function(e,t){var n="";for(e=e||24,t=t||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";e-- >0;)n+=t.charAt(Math.floor(Math.random()*t.length));return n},String.match=function(e,t){var n,r;return"string"==typeof e&&("string"==typeof t&&(t={"=":t}),e===(n=(t=t||{})["="]||t["*"]||t[">"]||t["<"])||r===t["="]&&(n=t["*"]||t[">"],e.slice(0,(n||"").length)===n||r===t["*"]&&(r!==t[">"]&&r!==t["<"]?e>=t[">"]&&e<=t["<"]:r!==t[">"]&&e>=t[">"]||r!==t["<"]&&e<=t["<"])))},String.hash=function(e,t){if("string"==typeof e){if(t=t||0,!e.length)return t;for(var n=0,r=e.length;n<r;++n)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t}};var t,n,r,o,i,s,a=Object.prototype.hasOwnProperty;Object.plain=function(e){return!!e&&(e instanceof Object&&e.constructor===Object||"Object"===Object.prototype.toString.call(e).match(/^\[object (\w+)\]$/)[1])},Object.empty=function(e,t){for(var n in e)if(a.call(e,n)&&(!t||-1==t.indexOf(n)))return!1;return!0},Object.keys=Object.keys||function(e){var t=[];for(var n in e)a.call(e,n)&&t.push(n);return t},n=setTimeout,r=0,o=0,i=typeof setImmediate!=""+t&&setImmediate||function(e,r){return typeof MessageChannel==""+t?n:((e=new MessageChannel).port1.onmessage=function(e){""==e.data&&r()},function(t){r=t,e.port2.postMessage("")})}(),s=n.check=n.check||typeof performance!=""+t&&performance||{now:function(){return+new Date}},n.hold=n.hold||9,n.poll=n.poll||function(e){n.hold>=s.now()-r&&o++<3333?e():i(function(){r=s.now(),e()},o=0)},function(){var e,t=setTimeout,n=t.turn=t.turn||function(e){1==r.push(e)&&o(s)},r=n.s=[],o=t.poll,i=0,s=function(){(e=r[i++])&&e(),i!=r.length&&99!=i||(r=n.s=r.slice(i),i=0),r.length&&o(s)}}(),function(){var e,t=setTimeout,n=t.turn;(t.each=t.each||function(t,r,o,i){i=i||9,function s(a,c,u){if(c=(a=(t||[]).splice(0,i)).length){for(var l=0;l<c&&e===(u=r(a[l]));l++);if(e===u)return void n(s)}o&&o(u)}()})()}()})(t,"./shim"),t(function(e){e.exports=function e(t,n,r){if(!t)return{to:e};var o="function"==typeof n;if(t=(this.tag||(this.tag={}))[t]||o&&(this.tag[t]={tag:t,to:e._={next:function(e){var t;(t=this.to)&&t.next(e)}}}),o){var i={off:e.off||(e.off=function(){if(this.next===e._.next)return!0;this===this.the.last&&(this.the.last=this.back),this.to.back=this.back,this.next=e._.next,this.back.to=this.to,this.the.last===this.the&&delete this.on.tag[this.the.tag]}),to:e._,next:n,the:t,on:this,as:r};return(i.back=t.last||t).to=i,t.last=i}return(t=t.to)&&void 0!==n&&t.next(n),t}})(t,"./onto"),t(function(e){var t=setTimeout,n=t.Book||(t.Book=function(e){var t=function(e,n){var r,o=t.all[e];return void 0===n?o&&o.is||t.get(o||e):o?((r=o.page)&&(r.size+=d(n)-d(o.is),r.text=""),o.text="",o.is=n,t):t.set(e,n)};return t.list=[{from:e,size:(e||"").length,substring:y,toString:m,book:t,get:t,read:u}],t.page=o,t.set=l,t.get=i,t.all={},t}),r=4096;function o(e){var t=this,n=t.list,r=a(e,n,t.parse),o=n[r];return"string"==typeof o&&(n[r]=o={size:-1,first:t.parse?t.parse(o):o,substring:y,toString:m,book:t,get:t,read:u}),o}function i(e){if(e){if(void 0!==e.is)return e.is;if(t=this.all[e])return t.is;var t,n=this.page(e);if(n&&n.from)return s(e,n)}}function s(e,t){var r,o,i,u,l=t.book;return(r=c(t))&&(o=r[s.i=u=a(e,r,n.decode)]),o&&e==o.word?(l.all[e]=o).is:("string"!=typeof o&&(o=r[s.i=u+=1]),o&&e==o.word?(l.all[e]=o).is:(i=f(o),e==n.decode(i[0])||(i=f(o=r[s.i=u+=1]),e==n.decode(i[0]))?(o=r[u]=l.all[e]={word:""+e,is:n.decode(i[1]),page:t,substring:p,toString:g}).is:void 0))}function a(e,t,n){n=n||a.no||(a.no=function(e){return e});for(var r,o=t,i=0,s=(e=""+e,o.length),c=s/2;(e<(r=(n(o[c|=0])||"").substring())||(n(o[c+1])||"").substring()<=e)&&c!=i;)c+=r<=e?(s-(i=c))/2:-((s=c)-i)/2;return c}function c(e,t,n){return"string"!=typeof e.from?e.from:e.from=f(t=t||e.from||"")}function u(e){e=e||function(e){return e};for(var t,n=0,r=w(this),o=[],i=this.book.parse||function(){};t=r[n++];)o.push(e(this.get(t=t.word||i(t)||t),t,this));return o}function l(e,t){var n=this,o=n.all[e];if(o)return n(e,t);var i=n.page(e=""+e);return i&&i.from&&(n.get(e),n.all[e])?n(e,t):(o=n.all[e]={word:e,is:t,page:i,substring:p,toString:g},i.first=i.first<e?i.first:e,i.limbo||(i.limbo=[]),i.limbo.push(o),n(e,t),i.size+=d(e)+d(t),(n.PAGE||r)<i.size&&function(e,t){for(var n,r=w(e),o=r.length/2|0,i=o,s={first:r[i].substring(),size:0,substring:y,toString:m,book:t,get:t,read:u},c=s.from=[];n=r[o++];)c.push(n),s.size+=(n.is||"").length||1,n.page=s;e.from=e.from.slice(0,i),e.size-=s.size,t.list.splice(a(s.first,t.list)+1,0,s),t.split&&t.split(s,e)}(i,n),n)}function f(e){return h((e=e||"").substring(1,e.length-1).split(e[0]),e[0])}function h(e,t){var n,r;return 0>(n=e.indexOf(""))?e:""==e[0]&&1==e.length||(r=n+2+parseInt((r=e[n+1]).substring(0,r.indexOf('"'))||r))!=r?[]:(e[n]=e.slice(n,r).join(t||"|"),e.slice(0,n+1).concat(h(e.slice(r),t)))}function d(e){return(e||"").length||1}function p(e,t){return this.word}function g(){return this.text=this.text||":"+n.encode(this.word)+":"+n.encode(this.is)+":"}function y(e,t){return(this.first||this.word||n.decode((c(this)||"")[0]||"")).substring(e,t)}function m(){return this.text=this.text||((e=this).limbo&&w(e),"string"==typeof e.from?e.from:"|"+(e.from||[]).join("|")+"|");var e}function w(e,t){var r=e.from="string"==typeof e.from?f(e.from):e.from||[];return(t=t||e.limbo)?function(e,t){t=t||e.limbo||[],e.limbo=null;for(var n,r=0,o=e.from;n=t[r++];)s(n.word,e)?o[s.i]=n:o.push(n);return o}(e).sort(function(e,t){return(e.word||n.decode(""+e))<(t.word||n.decode(""+t))?-1:1}):r}n.slot=f,n.encode=function(e,t,r){switch(t=t||"|",r=r||String.fromCharCode(32),typeof e){case"string":for(var o=e.indexOf(t),i=0;-1!=o;)i++,o=e.indexOf(t,o+1);return(i?t+i:"")+'"'+e;case"number":return e<0?""+e:"+"+e;case"boolean":return e?"+":"-";case"object":if(!e)return" ";for(var s,a=Object.keys(e).sort(),c=(o=0,t);s=a[o++];)c+=r+n.encode(s,t,r)+r+n.encode(e[s],t,r)+r+t;return c}},n.decode=function(e,t){if(t=t||"|","string"==typeof e){switch(e){case" ":return null;case"-":return!1;case"+":return!0}switch(e[0]){case"-":case"+":return parseFloat(e);case'"':return e.slice(1)}return e.slice(e.indexOf('"')+1)}},n.hash=function(e,t){if("string"==typeof e){if(t=t||0,!e.length)return t;for(var n=0,r=e.length;n<r;++n)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t}};try{e.exports=n}catch(e){}})(t,"./book"),t(function(e){e.exports=function(e){return null===e||"string"==typeof e||"boolean"==typeof e||"number"==typeof e&&e!=1/0&&e!=-1/0&&e==e||!!e&&"string"==typeof e["#"]&&1===Object.keys(e).length&&e["#"]}})(t,"./valid"),t(function(e){function n(){var e=+new Date;return a<e?(i=0,a=e+n.drift):a=e+(i+=1)/s+n.drift}t("./shim"),n.drift=0;var r,o=-1/0,i=0,s=999,a=o;n.is=function(e,t,n){var r=t&&e&&e._&&e._[">"]||n;if(r)return"number"==typeof(r=r[t])?r:o},n.ify=function(e,t,n,o,i){(e=e||{})._=e._||{},i&&(e._["#"]=i);var s=e._[">"]||(e._[">"]={});return r!==t&&"_"!==t&&("number"==typeof n&&(s[t]=n),r!==o&&(e[t]=o)),e},e.exports=n})(t,"./state"),t(function(e){t("./shim"),e.exports=function(e){var t={s:{}},n=t.s;e=e||{max:999,age:9e3},t.check=function(e){return!!n[e]&&r(e)};var r=t.track=function(o){var i=n[o]||(n[o]={});return i.was=t.now=+new Date,t.to||(t.to=setTimeout(t.drop,e.age+9)),r.ed&&r.ed(o),i};return t.drop=function(r){t.to=null,t.now=+new Date;var o=Object.keys(n);console.STAT&&console.STAT(t.now,+new Date-t.now,"dup drop keys"),setTimeout.each(o,function(o){var i=n[o];i&&(r||e.age)>t.now-i.was||delete n[o]},0,99)},t}})(t,"./dup"),t(function(e){t("./onto"),e.exports=function(e,t){if(this.on){var r=(this.opt||{}).lack||9e3;if("function"!=typeof e){if(!e)return;var o=e["#"]||e,i=(this.tag||"")[o];if(!i)return;return t&&(i=this.on(o,t),clearTimeout(i.err),i.err=setTimeout(function(){i.off()},r)),!0}if(o=t&&t["#"]||n(9),!e)return o;var s=this.on(o,e,t);return s.err=s.err||setTimeout(function(){s.off(),s.next({err:"Error: No ACK yet.",lack:!0})},r),o}};var n=String.random||function(){return Math.random().toString(36).slice(2)}})(t,"./ask"),t(function(e){function n(e){return e instanceof n?(this._={$:this}).$:this instanceof n?n.create(this._={$:this,opt:e}):new n(e)}n.is=function(e){return e instanceof n||e&&e._&&e===e._.$||!1},n.version=.202,n.chain=n.prototype,n.chain.toJSON=function(){},t("./shim"),n.valid=t("./valid"),n.state=t("./state"),n.on=t("./onto"),n.dup=t("./dup"),n.ask=t("./ask"),function(){function e(r){if(r)if(r.out!==e){var o,i=this.as,c=i.at||i,u=c.$,l=c.dup,f=r.DBG;if((o=r["#"])||(o=r["#"]=a(9)),!l.check(o)){if(l.track(o),o=r._,r._="function"==typeof o?o:function(){},r.$&&r.$===(r.$._||"").$||(r.$=u),r["@"]&&!r.put&&function(e){var t,n=e["@"]||"";if(t=n._)t.acks=(t.acks||0)+1,(t.err=e.err)&&(e["@"]=t["#"],s(t)),t.ok=e.ok||t.ok,t.stop||t.crack||(t.crack=t.match&&t.match.push(function(){d(t)})),d(t);else{var r=(r=e.$)&&(r=r._)&&(r=r.root)&&(r=r.dup);if(!(r=r.check(n)))return;e["@"]=r["#"]||e["@"]}}(r),!c.ask(r["@"],r)){if(f&&(f.u=+new Date),r.put)return void t(r);r.get&&n.on.get(r,u)}f&&(f.uc=+new Date),this.to.next(r),f&&(f.ua=+new Date),r.nts||r.NTS||(r.out=e,c.on("out",r),f&&(f.ue=+new Date))}}else this.to.next(r)}function t(t){if(t){var n=t._||"",i=n.root=((n.$=t.$||"")._||"").root;if(t["@"]&&n.faith&&!n.miss)return t.out=e,void i.on("out",t);n.latch=i.hatch,n.match=i.hatch=[];var a=t.put,l=n.DBG=t.DBG,f=+new Date;if(p=p||f,!a["#"]||!a["."]){l&&(l.p=f),n["#"]=t["#"],n.msg=t,n.all=0,n.stun=1;var h=Object.keys(a);console.STAT&&console.STAT(f,((l||n).pk=+new Date)-f,"put sort");var d,m,w,b,E,A,x,k=0;!function e(i){if(d!=k){if(d=k,!(w=h[k]))return console.STAT&&console.STAT(f,((l||n).pd=+new Date)-f,"put"),void s(n);(b=a[w])?(x=b._)?w!==x["#"]?A=g+y(w)+"soul not same.":(E=x[">"])||(A=g+y(w)+"no state."):A=g+y(w)+"no meta.":A=g+y(w)+"no node.",m=Object.keys(b||{})}if(A)return t.err=n.err=A,void s(n);var p,S=0;for(i=i||0;i++<9&&(p=m[S++]);)if("_"!==p){var I=b[p],P=E[p];if(o===P){A=g+y(p)+"on"+y(w)+"no state.";break}if(!u(I)){A=g+y(p)+"on"+y(w)+"bad "+typeof I+y(I);break}r(I,p,w,P,t),++v}(m=m.slice(S)).length?c(e):(++k,m=null,e(i))}()}}}function r(e,t,n,o,i){var s,a=i._||"",c=a.root,u=c.graph,f=u[n]||h,d=l(f,t,1),p=f[t],g=a.DBG;(s=console.STAT)&&(u[n]&&p||(s.has=(s.has||0)+1));var y=b();if(o>y)return setTimeout(function(){r(e,t,n,o,i)},(s=o-y)>w?w:s),void(console.STAT&&console.STAT((g||a).Hf=+new Date,s,"future"));if(!(o<d)&&(a.faith||o!==d||!(e===p||m(e)<=m(p))||a.miss)){a.stun++;var v=i["#"]+a.all++,E={toString:function(){return v},_:a};E.toJSON=E.toString,c.dup.track(E)["#"]=i["#"],g&&(g.ph=g.ph||+new Date),c.on("put",{"#":E,"@":i["@"],put:{"#":n,".":t,":":e,">":o},ok:i.ok,_:a})}}function i(e){var t;(t=(e._||"").DBG)&&(t.pa=+new Date,t.pm=t.pm||+new Date);var n,r=this.as,o=r.graph,i=e._,a=e.put,c=a["#"],u=a["."],l=a[":"],h=a[">"];e["#"],(n=i.msg)&&(n=n.put)&&(n=n[c])&&f(n,u,h,l,c),o[c]=f(o[c],u,h,l,c),(n=(r.next||"")[c])&&n.on("in",e),s(i),this.to.next(e)}function s(t,n){var r;if(!t.stop&&(t.err||!(0<--t.stun))&&(t.stop=1,r=t.root)){var o=t.match;o.end=1,o===r.hatch&&(!(o=t.latch)||o.end?delete r.hatch:r.hatch=o),t.hatch&&t.hatch(),setTimeout.each(t.match,function(e){e&&e()}),!(n=t.msg)||t.err||n.err||(n.out=e,t.root.on("out",n),E())}}function d(e){e&&e.root&&(e.stun||e.acks!==e.all||e.root.on("in",{"@":e["#"],err:e.err,ok:e.err?o:e.ok||{"":1}}))}n.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||n.on,t.ask=t.ask||n.ask,t.dup=t.dup||n.dup();var r=t.$.opt(t.opt);return t.once||(t.on("in",e,t),t.on("out",e,t),t.on("put",i,t),n.on("create",t),t.on("create",t)),t.once=1,r},n.on.put=t;var p,g="Error: Invalid graph!",y=function(e){return" '"+(""+e).slice(0,9)+"...' "},m=JSON.stringify,w=2147483647,b=n.state,v=0,E=function(){v>999&&v/-(p-(p=+new Date))>1&&(n.window&&console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query."),E=function(){v=0})}}(),function(){function e(e,t){var n=+new Date,r=e._||{},i=r.DBG=e.DBG,s=e["#"],c=a(9),u=Object.keys(t||"").sort(),h=((t||"")._||"")["#"],d=(u.length,e.$._.root),p=t===d.graph[h];console.STAT&&console.STAT(n,((i||r).gk=+new Date)-n,"got keys"),t&&function e(){n=+new Date;for(var r,g,y,m=0,w={};m<9&&(r=u[m++]);)f(w,r,l(t,r),t[r],h);u=u.slice(m),(g={})[h]=w,w=g,p&&((y=function(){}).ram=y.faith=!0),g=u.length,console.STAT&&console.STAT(n,-(n-(n=+new Date)),"got copied some"),i&&(i.ga=+new Date),d.on("in",{"@":s,"#":c,put:w,"%":g?c=a(9):o,$:d.$,_:y,DBG:i}),console.STAT&&console.STAT(n,+new Date-n,"got in"),g&&setTimeout.turn(e)}(),t||d.on("in",{"@":e["#"]})}n.on.get=function(t,n){var r=n._,i=t.get,s=i["#"],a=r.graph[s],c=i["."],u=(r.next||(r.next={}))[s],h=(t._||{}).DBG=t.DBG;if(h&&(h.g=+new Date),!a)return r.on("get",t);if(c){if(("string"!=typeof c||o===a[c])&&!((u||"").next||"")[c])return void r.on("get",t);a=f({},c,l(a,c),a[c],s)}a&&e(t,a),r.on("get",t)},n.on.get.ack=e}(),n.chain.opt=function(e){e=e||{};var t=this._,r=e.peers||e;return Object.plain(e)||(e={}),Object.plain(t.opt)||(t.opt=e),"string"==typeof r&&(r=[r]),Object.plain(t.opt.peers)||(t.opt.peers={}),r instanceof Array&&(e.peers={},r.forEach(function(n){var r={};r.id=r.url=n,e.peers[n]=t.opt.peers[n]=t.opt.peers[n]||r})),s(e,function e(t){var n=this[t];this&&this.hasOwnProperty(t)||"string"==typeof n||Object.empty(n)?this[t]=n:(!n||n.constructor===Object||n instanceof Array)&&s(n,e)}),t.opt.from=e,n.on("opt",t),t.opt.uuid=t.opt.uuid||function(e){return n.state().toString(36).replace(".","")+String.random(e||12)},this};var o,i,s=function(e,t){Object.keys(e).forEach(t,e)},a=String.random,c=setTimeout.turn,u=n.valid,l=n.state.is,f=n.state.ify,h={};n.log=function(){return!n.log.off&&i.log.apply(i,arguments),[].slice.call(arguments).join(" ")},n.log.once=function(e,t,r){return(r=n.log.once)[e]=r[e]||0,r[e]++||n.log(t)},"undefined"!=typeof globalThis&&"undefined"==typeof window&&"undefined"!=typeof WorkerGlobalScope?(globalThis.GUN=globalThis.Gun=n).window=globalThis:"undefined"!=typeof window&&((window.GUN=window.Gun=n).window=window);try{void 0!==r&&(r.exports=n)}catch(e){}e.exports=n,(n.window||{}).console=(n.window||{}).console||{log:function(){}},(i=console).only=function(e,t){return i.only.i&&e===i.only.i&&i.only.i++&&(i.log.apply(i,arguments)||t)}})(t,"./root"),t(function(e){t("./root").chain.back=function(e,t){if(-1===(e=e||1)||1/0===e)return this._.root.$;if(1===e)return(this._.back||this._).$;var o=this._;if("string"==typeof e&&(e=e.split(".")),e instanceof Array){for(var i=0,s=e.length,a=o;i<s;i++)a=(a||r)[e[i]];return n!==a?t?this:a:(a=o.back)?a.$.back(e,t):void 0}if("function"==typeof e){var c;for(a={back:o};(a=a.back)&&n===(c=e(a,t)););return c}return"number"==typeof e?(o.back||o).$.back(e-1):this};var n,r={}})(t,"./back"),t(function(e){var n=t("./root");function r(e,t){if(t=t||this.as||e.$._,(!e.$$||this===n.on)&&e.put&&!t.soul){var r=e.put||"",o=r["="]||r[":"],i=t.root,s=i.$.get(r["#"]).get(r["."])._;if("string"==typeof(o=u(o))){if(!(s.echo||(s.echo={}))[t.id]||(i.pass||"")[t.id]){if(a=i.pass){if(a[o+t.id])return;a[o+t.id]=1}(s.echo||(s.echo={}))[t.id]=t,t.has&&(t.link=o);var a,c=i.$.get(s.link=o)._;(c.echo||(c.echo={}))[s.id]=s,((a=t.ask||"")[""]||t.lex)&&c.on("out",{get:{"#":o}}),setTimeout.each(Object.keys(a),function(e,t){e&&(t=a[e])&&t.on("out",{get:{"#":o,".":e}})},0,99)}}else this===n.on&&((s.echo||(s.echo={}))[t.id]=t)}}function o(e,t){var n,r,i=e.put||"",a=s!==i["="]?i["="]:i[":"],c=t.root;if(s===a){if(t.soul&&s!==t.put)return;if(r=(e.$$||e.$||"")._||"",e["@"]&&(s!==r.put||s!==t.put))return;return(n=t.link||e.linked)&&delete(c.$.get(n)._.echo||"")[t.id],t.has&&(t.link=null),t.put=s,void setTimeout.each(Object.keys(t.next||""),function(e,r){(r=t.next[e])&&(n&&delete(c.$.get(n).get(e)._.echo||"")[r.id],r.on("in",{get:e,put:s,$:r.$}))},0,99)}t.soul||e.$$||(n=u(a),r=e.$._||"",(n!==r.link&&(!t.has||r.link)||(c.pass||"")[t.id]&&"string"!=typeof n)&&(delete(r.echo||"")[t.id],o({get:t.get,put:s,$:e.$,linked:e.linked=e.linked||r.link},t)))}function i(e,t){var r=this.as,o=r.$._,i=(o.root,r.get||""),a=(e.put||"")[i["#"]]||"";if(!e.put||"string"==typeof i["."]&&s===a[i["."]]){if(s!==o.put)return;if(!o.soul&&!o.has)return;return o.ack=(o.ack||0)+1,void o.on("in",{get:o.get,put:o.put=s,$:o.$,"@":e["@"]})}(e._||{}).miss=1,n.on.put(e)}n.chain.chain=function(e){var t,r=this,o=r._,i=new(e||r).constructor(r),s=i._;return s.root=t=o.root,s.id=++t.once,s.back=r._,s.on=n.on,s.on("in",n.on.in,s),s.on("out",n.on.out,s),i},n.on.out=function(e){var t,n,r=this.as,o=r.back,a=r.root;if(e.$||(e.$=r.$),this.to.next(e),!r.err){if(t=e.get){if(a.pass&&(a.pass[r.id]=r),r.lex&&Object.keys(r.lex).forEach(function(e){n[e]=r.lex[e]},n=e.get=e.get||{}),t["#"]||r.soul){if(t["#"]=t["#"]||r.soul,e["#"]||(e["#"]=c(9)),o=a.$.get(t["#"])._,t=t["."]){if(l(o.put,t)&&(n=o.ask&&o.ask[t],(o.ask||(o.ask={}))[t]=o.$.get(t)._,o.on("in",{get:t,put:{"#":o.soul,".":t,":":o.put[t],">":h(a.graph[o.soul],t)}}),n))return}else{if(n=o.ask&&o.ask[""],(o.ask||(o.ask={}))[""]=o,s!==o.put&&(o.on("in",o),n))return;e.$=o.$}return a.ask(i,e),a.on("in",e)}if(t["."])return r.get?(e={get:{".":r.get},$:r.$},(o.ask||(o.ask={}))[r.get]=e.$._,o.on("out",e)):(e={get:r.lex?e.get:{},$:r.$},o.on("out",e));if((r.ask||(r.ask={}))[""]=r,r.get)return t["."]=r.get,(o.ask||(o.ask={}))[r.get]=e.$._,o.on("out",e)}return o.on("out",e)}r.on("in",{put:r.put=s,$:r.$})},n.on.in=function(e,t){var n,i=(t=t||this.as).root,c=e.$||(e.$=t.$),l=(c||"")._||a,f=e.put||"",p=f["#"],g=f["."],y=s!==f["="]?f["="]:f[":"],m=f[">"]||-1/0;if(s!==e.put&&(s===f["#"]||s===f["."]||s===f[":"]&&s===f["="]||s===f[">"]))return u(f)?void t.on("in",{$:l.back.$,put:{"#":p=l.back.soul,".":g=l.has||l.get,"=":f,">":h(l.back.put,g)},via:e}):(p=((f||"")._||"")["#"])?(c=t.root.$.get(p),setTimeout.each(Object.keys(f).sort(),function(n){"_"!=n&&s!==(m=h(f,n))&&t.on("in",{$:c,put:{"#":p,".":n,"=":f[n],">":m},VIA:e})})):void console.log("chain not yet supported for",f,"...",e,t);(e.seen||"")[t.id]||((e.seen||(e.seen=function(){}))[t.id]=t,t!==l&&(Object.keys(e).forEach(function(t){f[t]=e[t]},f={}),f.get=t.get||f.get,t.soul||t.has?l.soul&&(f.$=t.$,f.$$=f.$$||l.$):f.$$$=f.$$$||t.$,e=f),o(e,t),(t.soul||e.$$)&&m>=h(i.graph[p],g)&&((f=i.$.get(p)._).put=d(f.put,g,m,y,p)),!l.soul&&m>=h(i.graph[p],g)&&(n=(i.$.get(p)._.next||"")[g])&&(n.put=y,"string"==typeof(f=u(y))&&(n.put=i.$.get(f)._.put||y)),this.to&&this.to.next(e),t.any&&setTimeout.each(Object.keys(t.any),function(n){(n=t.any[n])&&n(e)},0,99),t.echo&&setTimeout.each(Object.keys(t.echo),function(n){(n=t.echo[n])&&n.on("in",e)},0,99),((e.$$||"")._||l).soul&&(n=t.next)&&(n=n[g])&&(f={},Object.keys(e).forEach(function(t){f[t]=e[t]}),f.$=(e.$$||e.$).get(f.get=g),delete f.$$,delete f.$$$,n.on("in",f)),r(e,t))},n.on.link=r,n.on.unlink=o;var s,a={},c=String.random,u=n.valid,l=function(e,t){return e&&Object.prototype.hasOwnProperty.call(e,t)},f=n.state,h=f.is,d=f.ify})(t,"./chain"),t(function(e){var n=t("./root");function r(e){var t=this.at||this.on;if(!e||t.soul||t.has)return this.off();if(e=(e=(e=e.$||e)._||e).id){var n;if(t.map,(n=this.seen||(this.seen={}))[e])return!0;n[e]=!0}}n.chain.get=function(e,t,a){var c,u;if("string"==typeof e){if(0==e.length)return(c=this.chain())._.err={err:n.log("0 length key!",e)},t&&t.call(c,c._.err),c;(c=((f=this._).next||i)[e])||(c=e&&function(e,t){var n=t._,r=n.next,o=t.chain()._;return r||(r=n.next={}),r[o.get=e]=o,t===n.root.$?o.soul=e:(n.soul||n.has)&&(o.has=e),o}(e,this)),c=c&&c.$}else{if("function"==typeof e){if(!0===t)return function(e,t,r,i){var s,a=e._,c=0;(s=a.soul||a.link)?t(s,i,a):a.jam?a.jam.push([t,i]):(a.jam=[[t,i]],e.get(function(e,t){if(!(o===e.put&&!a.root.opt.super&&(s=Object.keys(a.root.opt.peers).length)&&++c<=s)){t.rid(e);var r,i=(i=e.$)&&i._||{},u=0;for(s=a.jam,delete a.jam;r=s[u++];){var l=r[0];r=r[1],l&&l(i.link||i.soul||n.valid(e.put)||((e.put||{})._||{})["#"],r,e,t)}}},{out:{get:{".":!0}}}))}(this,e,0,a),this;var l,f=(c=this)._,h=t||{},d=f.root;h.at=f,h.ok=e;var p={};function g(e,t,r){if(!g.stun&&(!(i=d.pass)||i[l])){var i,s=e.$._,a=(e.$$||"")._,c=(a||s).put,u=!s.has&&!s.soul,y={};if((u||o===c)&&(c=o===((i=e.put)||"")["="]?o===(i||"")[":"]?i:i[":"]:i["="]),"string"==typeof(i=n.valid(c))&&(c=o===(i=d.$.get(i)._.put)?h.not?o:c:i),!h.not||o!==c){if(o===h.stun){if((i=d.stun)&&i.on&&(f.$.back(function(e){if(i.on(""+e.id,y={}),(y.run||0)<g.id)return y}),!y.run&&i.on(""+s.id,y={}),!y.run&&a&&i.on(""+a.id,y={}),g.id>y.run&&(y.stun&&!y.stun.end||(y.stun=i.on("stun"),y.stun=y.stun&&y.stun.last),y.stun&&!y.stun.end)))return void((y.stun.add||(y.stun.add={}))[l]=function(){g(e,t,1)});if(o===c&&(r=0),(i=d.hatch)&&!i.end&&o===h.hatch&&!r){if(p[s.$._.id])return;return p[s.$._.id]=1,void i.push(function(){g(e,t,1)})}p={}}if(d.pass){if(d.pass[l+s.id])return;d.pass[l+s.id]=1}h.on?h.ok.call(s.$,c,s.get,e,t||g):h.v2020?h.ok(e,t||g):(Object.keys(e).forEach(function(t){i[t]=e[t]},i={}),(e=i).put=c,h.ok.call(h.as,e,t||g))}}}return g.at=f,(f.any||(f.any={}))[l=String.random(7)]=g,g.off=function(){g.stun=1,f.any&&delete f.any[l]},g.rid=r,g.id=h.run||++d.once,u=d.pass,(d.pass={})[l]=1,h.out=h.out||{get:{}},f.on("out",h.out),d.pass=u,c}if("number"==typeof e)return this.get(""+e,t,a);if("string"==typeof(u=s(e)))return this.get(u,t,a);(u=this.get.next)&&(c=u(this,e))}return c?(t&&"function"==typeof t&&c.get(t,a),c):((c=this.chain())._.err={err:n.log("Invalid get request!",e)},t&&t.call(c,c._.err),c)};var o,i={},s=n.valid})(t,"./get"),t(function(e){var n=t("./root");function r(e,t){if(t){t=(t._||"").id||t;var r,o=e.root.stun||(e.root.stun={on:n.on}),i={};e.stun||(e.stun=o.on("stun",function(){})),(r=o.on(""+t))&&r.the.last.next(i),i.run>=e.run||o.on(""+t,function(t){if(e.stun.end)return this.off(),void this.to.next(t);t.run=t.run||e.run,t.stun=t.stun||e.stun})}}function o(e){if(e.err)o.end(e.stun,e.root);else if(!e.todo.length&&!e.end&&Object.empty(e.wait)){e.end=1;var t,r=e.$.back(-1)._,i=r.root,s=r.ask(function(t){i.on("ack",t),t.err&&!t.lack&&n.log(t),++a>(e.acks||0)&&this.off(),e.ack&&e.ack(t,this)},e.opt),a=0,c=e.stun;(t=function(){c&&(o.end(c,i),setTimeout.each(Object.keys(c=c.add||""),function(e){(e=c[e])&&e()}))}).hatch=t,e.ack&&!e.ok&&(e.ok=e.acks||9),e.via._.on("out",{put:e.out=e.graph,ok:e.ok&&{"@":e.ok+1},opt:e.opt,"#":s,_:t})}}n.chain.put=function(e,t,s){var l=this,f=l._,h=f.root;(s=s||{}).root=f.root,s.run||(s.run=h.once),r(s,f.id),s.ack=s.ack||t,s.via=s.via||l,s.data=s.data||e,s.soul||(s.soul=f.soul||"string"==typeof t&&t);var d=s.state=s.state||n.state();return"function"==typeof e?(e(function(e){s.data=e,l.put(i,i,s)}),l):s.soul?(s.$=h.$.get(s.soul),s.todo=[{it:s.data,ref:s.$}],s.turn=s.turn||a,s.ran=s.ran||o,function e(){var t,i,a,l,f,h=s.todo,p=h.pop(),g=p.it;if(p.ref&&p.ref._.id,r(s,p.ref),(l=p.todo)&&(g=g[i=l.pop()],l.length&&h.push(p)),i&&(h.path||(h.path=[])).push(i),!(t=c(g))&&!(f=n.is(g))){if(!Object.plain(g))return void o.err(s,"Invalid data: "+function(e,t){return e&&(t=e.constructor)&&t.name||typeof e}(g)+" at "+(s.via.back(function(e){e.get&&l.push(e.get)},l=[])||l.join("."))+"."+(h.path||[]).join("."));for(var y=s.seen||(s.seen=[]),m=y.length;m--;)if(g===(l=y[m]).it){t=g=l.link;break}}if(i&&t)p.node=u(p.node,i,d,g);else{if(!s.seen)return void o.err(s,"Data at root of graph must be a node (an object).");s.seen.push(a={it:g,link:{},todo:f?[]:Object.keys(g).sort().reverse(),path:(h.path||[]).slice(),up:p}),p.node=u(p.node,i,d,a.link),!f&&a.todo.length&&h.push(a);var w=s.seen.length;function b(e,t){var n=a.link["#"];t&&(t.off(),t.rid(e));var o=n||e.soul||(l=(e.$$||e.$)._||"").soul||l.link||((l=l.put||"")._||"")["#"]||l["#"]||((l=e.put||"")&&e.$$?l["#"]:(l["="]||l[":"]||"")["#"]);!n&&r(s,e.$),o||p.link["#"]?(o||(o=[],(e.$$||e.$).back(function(e){if(l=e.soul||e.link)return o.push(l);o.push(e.get)}),o=o.reverse().join("/")),a.link["#"]=o,!f&&(((s.graph||(s.graph={}))[o]=a.node||(a.node={_:{}}))._["#"]=o),delete s.wait[w],a.wait&&setTimeout.each(a.wait,function(e){e&&e()}),s.ran(s)):(p.wait||(p.wait=[])).push(function(){b(e,t)})}(s.wait||(s.wait={}))[w]="",l=(a.ref=f?g:i?p.ref.get(i):p.ref)._,(l=g&&(g._||"")["#"]||l.soul||l.link)?b({soul:l}):a.ref.get(b,{run:s.run,v2020:1,out:{get:{".":" "}}})}if(!h.length)return s.ran(s);s.turn(e)}(),l):(function(e){var t,n=e.via._;e.via=e.via.back(function(n){if(n.soul||!n.get)return n.$;t=e.data,(e.data={})[n.get]=t}),e.via&&e.via._.soul||(e.via=n.root.$.get(((e.data||"")._||"")["#"]||n.$.back("opt.uuid")())),e.via.put(e.data,e.ack,e)}(s),l)},o.end=function(e,t){e.end=s,e.the.to===e&&e===e.the.last&&delete t.stun,e.off()},o.err=function(e,t){(e.ack||s).call(e,e.out={err:e.err=n.log(t)}),e.ran(e)};var i,s=function(){},a=setTimeout.turn,c=n.valid,u=n.state.ify})(t,"./put"),t(function(e){var n=t("./root");t("./chain"),t("./back"),t("./put"),t("./get"),e.exports=n})(t,"./core"),t(function(e){var n=t("./root");t("./shim"),t("./onto"),t("./book"),t("./valid"),t("./state"),t("./dup"),t("./ask"),t("./core"),t("./on"),t("./map"),t("./set"),t("./mesh"),t("./websocket"),t("./localStorage"),e.exports=n})(t,"./index"),t(function(e){var n,r=t("./root");r.chain.on=function(e,t,n,r){var o,i=this,s=i._;if(s.root,"string"==typeof e)return t?(o=s.on(e,t,n||s,r),n&&n.$&&(n.subs||(n.subs=[])).push(o),i):s.on(e);var a=t;return(a=!0===a?{change:!0}:a||{}).not=1,a.on=1,i.get(e,a),i},r.chain.once=function(e,t){if(t=t||{},!e)return function(e,t,n){return r.log.once("valonce","Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),(n=e.chain())._.nix=e.once(function(e,t){n._.on("in",this._)}),n._.lex=e._.lex,n}(this);var o,i=this,s=i._,a=s.root,c=(s.put,String.random(7));return i.get(function(i,u,l,f){var h=this,d=h._,p=d.one||(d.one={});function g(y){d.has||d.soul||(d={put:i,get:u}),n===(o=d.put)&&(o=((l.$$||"")._||"").put),"string"!=typeof r.valid(o)||(o=a.$.get(o)._.put)!==n||y?f.stun||""!==p[c]&&(p[c]="",(s.soul||s.has)&&f.off(),e.call(h,o,d.get),clearTimeout(p[c])):p[c]=setTimeout(function(){g(1)},t.wait||99)}f.stun||""!==p[c]&&(!0!==(o=r.valid(i))?"string"!=typeof o&&(clearTimeout((s.one||"")[c]),clearTimeout(p[c]),p[c]=setTimeout(g,t.wait||99)):g())},{on:1}),i},r.chain.off=function(){var e,t=this._,n=t.back;if(n)return t.ack=0,(e=n.next)&&e[t.get]&&delete e[t.get],(e=n.any)&&(delete n.any,n.any={}),(e=n.ask)&&delete e[t.get],(e=n.put)&&delete e[t.get],(e=t.soul)&&delete n.root.graph[e],(e=t.map)&&Object.keys(e).forEach(function(t,r){(r=e[t]).link&&n.root.$.get(r.link).off()}),(e=t.next)&&Object.keys(e).forEach(function(t,n){e[t].$.off()}),t.on("off",{}),this}})(t,"./on"),t(function(e){var n=t("./root"),r=n.chain.get.next;function o(e){this.to.next(e);var t,r=this.as,o=e.$._,i=e.put;(o.soul||e.$$)&&((t=r.lex)&&!String.match(e.get||(i||"")["."],t["."]||t["#"]||t)||n.on.link(e,r))}n.chain.get.next=function(e,t){var n;return Object.plain(t)?(n=((n=t["#"])||"")["="]||n)?e.get(n):((n=e.chain()._).lex=t,e.on("in",function(e){String.match(e.get||(e.put||"")["."],t["."]||t["#"]||t)&&n.on("in",e),this.to.next(e)}),n.$):(r||s)(e,t)},n.chain.map=function(e,t,r){var a,c,u=this,l=u._;return Object.plain(e)&&(a=e["."]?e:{".":e},e=i),e?(n.log.once("mapfn","Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),c=u.chain(),u.map().on(function(t,r,o,a){var u=(e||s).call(this,t,r,o,a);if(i!==u){if(t===u)return c._.on("in",o);if(n.is(u))return c._.on("in",u._);var l={};Object.keys(o.put).forEach(function(e){l[e]=o.put[e]},l),l["="]=u,c._.on("in",{get:r,put:l})}}),c):((c=l.each)||((l.each=c=u.chain())._.lex=a||c._.lex||l.lex,c._.nix=u.back("nix"),u.on("in",o,c._)),c)};var i,s=function(){}})(t,"./map"),t(function(e){var n=t("./root");n.chain.set=function(e,t,r){var o,i,s=this,a=s.back(-1);return t=t||function(){},(r=r||{}).item=r.item||e,(o=((e||"")._||"")["#"])&&((e={})["#"]=o),"string"==typeof(i=n.valid(e))?s.get(o=i).put(e,t,r):n.is(e)?(s.put(function(r){e.get(function(e,o,a){if(!e)return t.call(s,{err:n.log('Only a node can be linked! Not "'+a.put+'"!')});(i={})[e]={"#":e},r(i)},!0)}),e):(Object.plain(e)&&(e=a.get(o=s.back("opt.uuid")()).put(e)),s.get(o||a.back("opt.uuid")(7)).put(e,t,r))}})(t,"./set"),t(function(e){t("./shim");var n,r=function(){},o=JSON.parseAsync||function(e,t,n){var r=+new Date;try{t(void 0,JSON.parse(e,n),i.sucks(+new Date-r))}catch(e){t(e)}},i=JSON.stringifyAsync||function(e,t,n,r){var o=+new Date;try{t(void 0,JSON.stringify(e,n,r),i.sucks(+new Date-o))}catch(e){t(e)}};i.sucks=function(e){e>99&&(console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."),i.sucks=r)};try{e.exports=function(e){var t=function(){},r=e.opt||{};r.log=r.log||console.log,r.gap=r.gap||r.wait||0,r.max=r.max||.3*(r.memory?999*r.memory*999:3e8),r.pack=r.pack||.01*r.max*.01,r.puff=r.puff||9;var s=setTimeout.turn||setTimeout,a=e.dup,c=a.check,u=a.track,l=(new Date,t.hear=function(e,n){if(e){if(r.max<=e.length)return t.say({dam:"!",err:"Message too big!"},n);t===this&&(l.d+=e.length||0,++l.c);var i,a=n.SH=+new Date,c=e[0];return"["===c?(o(e,function(e,o){if(e||!o)return t.say({dam:"!",err:"DAM JSON parse error."},n);console.STAT&&console.STAT(+new Date,o.length,"# on hear batch");var i=r.puff;!function e(){for(var r,a=+new Date,c=0;c<i&&(r=o[c++]);)t.hear(r,n);o=o.slice(c),console.STAT&&console.STAT(a,+new Date-a,"hear loop"),f(n),o.length&&s(e,0)}()}),void(e="")):"{"===c||(e["#"]||Object.plain(e))&&(i=e)?i?l.one(i,n,a):void o(e,function(e,r){if(e||!r)return t.say({dam:"!",err:"DAM JSON parse error."},n);l.one(r,n,a)}):void 0}});function f(e){var t=e.batch,n="string"==typeof t;if(n&&(t+="]"),e.batch=e.tail=null,t&&!(n?3>t.length:!t.length)){if(!n)try{t=1===t.length?t[0]:JSON.stringify(t)}catch(e){return r.log("DAM JSON stringify error",e)}t&&h(t,e)}}function h(e,n){try{var r=n.wire;n.say?n.say(e):r.send&&r.send(e),t.say.d+=e.length||0,++t.say.c}catch(t){(n.queue=n.queue||[]).push(e)}}l.one=function(n,r,o){var i,s,l,f,h;if(n.DBG&&(n.DBG=h={DBG:n.DBG}),h&&(h.h=o),h&&(h.hp=+new Date),(i=n["#"])||(i=n["#"]=String.random(9)),!((l=c(i))||(s=n["##"])&&(l=n["@"]||n.get&&i)&&a.check(f=l+s))){if((n._=function(){}).via=t.leap=r,(l=n["><"])&&"string"==typeof l&&l.slice(0,99).split(",").forEach(function(e){this[e]=1},n._.yo={}),l=n.dam)return(u(i)||{}).via=r,void((l=t.hear[l])&&l(n,r,e));(l=n.ok)&&(n._.near=l["/"]),o=+new Date,h&&(h.is=o),r.SI=i,u.ed=function(e){i===e&&(u.ed=0,(e=a.s[i])&&(e.via=r,n.get&&(e.it=n)))},e.on("in",t.last=n),h&&(h.hd=+new Date),console.STAT&&console.STAT(o,+new Date-o,n.get?"msg get":n.put?"msg put":"msg"),u(i),f&&u(f),t.leap=t.last=null}},l.c=l.d=0,function(){var e,o=0;function l(e,t){var n;return t instanceof Object?(Object.keys(t).sort().forEach(d,{to:n={},on:t}),n):t}function d(e){this.to[e]=this.on[e]}t.hash=function(e,n){var r,o,a,c=+new Date;i(e.put,function i(u,l){var f=(o||(o=a=l||"")).slice(0,32768);r=String.hash(f,r),(o=o.slice(32768))?s(i,0):(console.STAT&&console.STAT(c,+new Date-c,"say json+hash"),e._.$put=a,e["##"]=r,t.say(e,n),delete e._.$put)},l)},t.say=function(i,c){var l;if((l=this)&&(l=l.to)&&l.next&&l.next(i),!i)return!1;var d,p,g,y=i["@"],m=i._||(i._=function(){}),w=i.DBG,b=+new Date;if(m.y=m.y||b,c||w&&(w.y=b),(d=i["#"])||(d=i["#"]=String.random(9)),!e&&u(d),(p=i["##"])||n===i.put||m.via||!y){if(!c&&y&&(c=(l=a.s[y])&&(l.via||(l=l.it)&&(l=l._)&&l.via)||(l=t.last)&&y===l["#"]&&t.leap),!c&&y){if(a.s[y])return;return console.STAT&&console.STAT(+new Date,++o,"total no peer to ack to"),!1}if(y&&!i.put&&!p&&((a.s[y]||"").it||"")["##"])return!1;if(!c&&t.way)return t.way(i);if(w&&(w.yh=+new Date),g=m.raw){if(w&&(w.yr=+new Date),!c||!c.id){if(!Object.plain(c||r.peers))return!1;b=+new Date,r.puff;var v=r.peers,E=Object.keys(c||r.peers||{});return console.STAT&&console.STAT(b,+new Date-b,"peer keys"),void function n(){var r=+new Date;e=1;var o=m.raw;m.raw=g;for(var a,l=0;l<9&&(a=(E||"")[l++]);)(a=v[a]||(c||"")[a])&&t.say(i,a);m.raw=o,e=0,E=E.slice(l),console.STAT&&console.STAT(r,+new Date-r,"say loop"),E.length&&(s(n,0),y&&u(y))}()}if(!c.wire&&t.wire&&t.wire(c),d!==c.last){if(c.last=d,c===m.via)return!1;if((l=m.yo)&&(l[c.url]||l[c.pid]||l[c.id]))return!1;if(console.STAT&&console.STAT(b,((w||m).yp=+new Date)-(m.y||b),"say prep"),!e&&y&&u(y),c.batch){if(c.tail=(l=c.tail||0)+g.length,c.tail<=r.pack)return void(c.batch+=(l?",":"")+g);f(c)}c.batch="[";var A=+new Date;setTimeout(function(){console.STAT&&console.STAT(A,+new Date-A,"0ms TO"),f(c)},r.gap),h(g,c),console.STAT&&y===c.SI&&console.STAT(b,+new Date-c.SH,"say ack")}}else t.raw(i,c)}else t.hash(i,c)},t.say.c=t.say.d=0,t.raw=function(e,o){if(!e)return"";var s,u,l=e._||{};if(u=l.raw)return u;if("string"==typeof e)return e;var f=e["##"],h=e["@"];if(f&&h){if(!l.via&&c(h+f))return!1;if(u=(a.s[h]||"").it){if(f===u["##"])return!1;u["##"]||(u["##"]=f)}}if(!e.dam&&!e["@"]){var d=0,p=[];for(var g in u=r.peers){var y=u[g];if(p.push(y.url||y.pid||y.id),++d>6)break}d>1&&(e["><"]=p.join())}if(e.put&&(u=e.ok)&&(e.ok={"@":(u["@"]||1)-1,"/":u["/"]==e._.near?t.near:u["/"]}),s=l.$put)return u={},Object.keys(e).forEach(function(t){u[t]=e[t]}),u.put=":])([:",void i(u,function(e,t){if(!e){var r=+new Date;u=t.indexOf('"put":":])([:"'),m(n,t=t.slice(0,u+6)+s+t.slice(u+14)),console.STAT&&console.STAT(r,+new Date-r,"say slice")}});function m(n,r){n||(l.raw=r,t.say(e,o))}i(e,m)}}(),t.near=0,t.hi=function(n){var o;n.wire?(n.id?r.peers[n.url||n.id]=n:(o=n.id=n.id||n.url||String.random(9),t.say({dam:"?",pid:e.opt.pid},r.peers[o]=n),delete a.s[n.last]),n.met||(t.near++,n.met=+new Date,e.on("hi",n)),o=n.queue,n.queue=[],setTimeout.each(o||[],function(e){h(e,n)},0,9)):t.wire(n.length&&{url:n,id:n}||n)},t.bye=function(n){n.met&&--t.near,delete n.met,e.on("bye",n);var r=+new Date;r-=n.met||r,t.bye.time=((t.bye.time||r)+r)/2},t.hear["!"]=function(e,t){r.log("Error:",e.err)},t.hear["?"]=function(e,n){e.pid&&(n.pid||(n.pid=e.pid),e["@"])||(t.say({dam:"?",pid:r.pid,"@":e["#"]},n),delete a.s[n.last])},t.hear.mob=function(e,n){if(e.peers){var r=Object.keys(e.peers),o=r[Math.random()*r.length|0];o&&(t.bye(n),t.hi(o))}},e.on("create",function(e){e.opt.pid=e.opt.pid||String.random(9),this.to.next(e),e.on("out",t.say)}),e.on("bye",function(e,t){e=r.peers[e.id||e]||e,this.to.next(e),e.bye?e.bye():(t=e.wire)&&t.close&&t.close(),delete r.peers[e.id],e.wire=null});var d={};return e.on("bye",function(e,n){this.to.next(e),(n=console.STAT)&&(n.peers=t.near),(n=e.url)&&(d[n]=!0,setTimeout(function(){delete d[n]},r.lack||9e3))}),e.on("hi",function(n,o){if(this.to.next(n),(o=console.STAT)&&(o.peers=t.near),!r.super){var i=Object.keys(e.next||"");i.length>9999&&!console.SUBS&&console.log(console.SUBS="Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`."),setTimeout.each(i,function(o){var i=e.next[o];r.super||(i.ask||"")[""]?t.say({get:{"#":o}},n):setTimeout.each(Object.keys(i.ask||""),function(r){r&&t.say({"##":String.hash((e.graph[o]||"")[r]),get:{"#":o,".":r}},n)})})}}),t}}catch(e){}})(t,"./mesh"),t(function(e){var n=t("./root");n.Mesh=t("./mesh"),n.on("opt",function(e){if(this.to.next(e),!e.once){var t=e.opt;if(!1!==t.WebSocket){var r=n.window||{},o=t.WebSocket||r.WebSocket||r.webkitWebSocket||r.mozWebSocket;if(o){t.WebSocket=o;var i=t.mesh=t.mesh||n.Mesh(e),s=i.wire||t.wire;i.wire=t.wire=u,setTimeout(function(){!t.super&&e.on("out",{dam:"hi"})},1);var a=1998,c=""+void 0!=typeof document&&document}}}function u(e){try{if(!e||!e.url)return s&&s(e);var n=e.url.replace(/^http/,"ws"),r=e.wire=new t.WebSocket(n);return r.onclose=function(){l(e),t.mesh.bye(e)},r.onerror=function(t){l(e)},r.onopen=function(){t.mesh.hi(e)},r.onmessage=function(n){n&&t.mesh.hear(n.data||n,e)},r}catch(n){t.mesh.bye(e)}}function l(e){clearTimeout(e.defer),t.peers[e.url]&&(c&&e.retry<=0||(e.retry=(e.retry||t.retry+1||60)-(-e.tried+(e.tried=+new Date)<4*a?1:0),e.defer=setTimeout(function t(){if(c&&c.hidden)return setTimeout(t,a);u(e)},a)))}})})(t,"./websocket"),t(function(e){if("undefined"!=typeof Gun){var t;try{t=(Gun.window||function(){}).localStorage}catch(e){}t||(Gun.log("Warning: No localStorage exists to persist data to!"),t={setItem:function(e,t){this[e]=t},removeItem:function(e){delete this[e]},getItem:function(e){return this[e]}}),JSON.parseAsync;var n=JSON.stringifyAsync||function(e,t,n,r){try{t(void 0,JSON.stringify(e,n,r))}catch(e){t(e)}};Gun.on("create",function e(r){this.to.next(r);var o,i,s,a,c=r.opt,u=(r.graph,[]);if(!1!==c.localStorage){c.prefix=c.file||"gun/";try{o=e[c.prefix]=e[c.prefix]||JSON.parse(s=t.getItem(c.prefix))||{}}catch(t){o=e[c.prefix]={}}s=(s||"").length,r.on("get",function(e){this.to.next(e);var t,n,r,i=e.get;i&&(t=i["#"])&&((n=o[t]||void 0)&&(r=i["."])&&!Object.plain(r)&&(n=Gun.state.ify({},r,Gun.state.is(n,r),n[r],t)),Gun.on.get.ack(e,n))}),r.on("put",function(e){this.to.next(e);var t=e.put,n=t["#"],c=t["."],f=e["#"],h=e.ok||"";o[n]=Gun.state.ify(o[n],c,t[">"],t[":"],n),a&&s>4999880?r.on("in",{"@":f,err:"localStorage max!"}):(e["@"]||e._.via&&!(Math.random()<h["@"]/h["/"])||u.push(f),i||(i=setTimeout(l,9+s/333)))})}function l(){if(u.length||!((setTimeout.turn||"").s||"").length){var e=u;clearTimeout(i),i=!1,u=[],n(o,function(n,i){try{!n&&t.setItem(c.prefix,i)}catch(e){n=a=e||"localStorage failure"}n&&(Gun.log(n+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),r.on("localStorage:error",{err:n,get:c.prefix,put:o})),s=i.length,setTimeout.each(e,function(e){r.on("in",{"@":e,err:n,ok:0})},0,99)})}else setTimeout(l,99)}})}})(t,"./localStorage")}(),function(){if(""+A!=typeof Gun){var e=function(e){console.warn("Warning! Deprecated internal utility will break in next version:",e)},t=Gun;t.fn=t.fn||{is:function(t){return e("fn"),!!t&&"function"==typeof t}},t.bi=t.bi||{is:function(t){return e("bi"),t instanceof Boolean||"boolean"==typeof t}},t.num=t.num||{is:function(t){return e("num"),!r(t)&&(t-parseFloat(t)+1>=0||1/0===t||-1/0===t)}},t.text=t.text||{is:function(t){return e("text"),"string"==typeof t}},t.text.ify=t.text.ify||function(n){return e("text.ify"),t.text.is(n)?n:"undefined"!=typeof JSON?JSON.stringify(n):n&&n.toString?n.toString():n},t.text.random=t.text.random||function(t,n){e("text.random");var r="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";t>0;)r+=n.charAt(Math.floor(Math.random()*n.length)),t--;return r},t.text.match=t.text.match||function(t,n){var r,o;return e("text.match"),"string"==typeof t&&("string"==typeof n&&(n={"=":n}),t===(r=(n=n||{})["="]||n["*"]||n[">"]||n["<"])||o===n["="]&&(r=n["*"]||n[">"]||n["<"],t.slice(0,(r||"").length)===r||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},t.text.hash=t.text.hash||function(t,n){if(e("text.hash"),"string"==typeof t){if(n=n||0,!t.length)return n;for(var r=0,o=t.length;r<o;++r)n=(n<<5)-n+t.charCodeAt(r),n|=0;return n}},t.list=t.list||{is:function(t){return e("list"),t instanceof Array}},t.list.slit=t.list.slit||Array.prototype.slice,t.list.sort=t.list.sort||function(t){return e("list.sort"),function(e,n){return e&&n?(e=e[t])<(n=n[t])?-1:e>n?1:0:0}},t.list.map=t.list.map||function(t,n,r){return e("list.map"),s(t,n,r)},t.list.index=1,t.obj=t.boj||{is:function(t){return e("obj"),!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])}},t.obj.put=t.obj.put||function(t,n,r){return e("obj.put"),(t||{})[n]=r,t},t.obj.has=t.obj.has||function(t,n){return e("obj.has"),t&&Object.prototype.hasOwnProperty.call(t,n)},t.obj.del=t.obj.del||function(t,n){if(e("obj.del"),t)return t[n]=null,delete t[n],t},t.obj.as=t.obj.as||function(t,n,r,o){return e("obj.as"),t[n]=t[n]||(o===r?{}:r)},t.obj.ify=t.obj.ify||function(t){if(e("obj.ify"),o(t))return t;try{t=JSON.parse(t)}catch(e){t={}}return t},function(){function n(e,t){i(this,t)&&void 0!==this[t]||(this[t]=e)}t.obj.to=t.obj.to||function(t,r){return e("obj.to"),s(t,n,r=r||{}),r}}(),t.obj.copy=t.obj.copy||function(t){return e("obj.copy"),t?JSON.parse(JSON.stringify(t)):t},function(){function n(e,t){var n=this.n;if(!n||!(t===n||o(n)&&i(n,t)))return void 0!==t||void 0}t.obj.empty=t.obj.empty||function(t,r){return e("obj.empty"),!t||!s(t,n,{n:r})}}(),function(){function n(e,t){if(2===arguments.length)return n.r=n.r||{},void(n.r[e]=t);n.r=n.r||[],n.r.push(e)}var s,a=Object.keys;Object.keys=Object.keys||function(e){return s(e,function(e,t,n){n(t)})},t.obj.map=s=t.obj.map||function(s,c,u){e("obj.map");var l,f,h,d,p,g=0,y="function"==typeof c;if(n.r=l,a&&o(s)&&(d=a(s),p=!0),u=u||{},r(s)||d)for(f=(d||s).length;g<f;g++){var m=g+t.list.index;if(y){if((h=p?c.call(u,s[d[g]],d[g],n):c.call(u,s[g],m,n))!==l)return h}else if(c===s[p?d[g]:g])return d?d[g]:m}else for(g in s)if(y){if(i(s,g)&&(h=u?c.call(u,s[g],g,n):c(s[g],g,n))!==l)return h}else if(c===s[g])return g;return y?n.r:t.list.index?0:-1}}(),t.time=t.time||{},t.time.is=t.time.is||function(t){return e("time"),t?t instanceof Date:+(new Date).getTime()};var n=t.fn.is,r=t.list.is,o=(E=t.obj).is,i=E.has,s=E.map,a={is:function(t){return e("val.is"),t!==A&&(null===t||t!==1/0&&(!!(f(t)||u(t)||l(t))||a.link.is(t)||!1))}};a.link=a.rel={_:"#"},function(){function t(e,t){var n=this;return n.id?n.id=!1:t==c&&f(e)?void(n.id=e):n.id=!1}a.link.is=function(n){if(e("val.link.is"),n&&n[c]&&!n._&&o(n)){var r={};if(s(n,t,r),r.id)return r.id}return!1}}(),a.link.ify=function(t){return e("val.link.ify"),h({},c,t)},t.obj.has._=".";var c=a.link._,u=t.bi.is,l=t.num.is,f=t.text.is,h=(o=(E=t.obj).is,E.put);s=E.map,t.val=t.val||a;var d={_:"_",soul:function(t,n){return e("node.soul"),t&&t._&&t._[n||y]}};d.soul.ify=function(t,n){return e("node.soul.ify"),n="string"==typeof n?{soul:n}:n||{},(t=t||{})._=t._||{},t._[y]=n.soul||t._[y]||g(),t},d.soul._=a.link._,function(){function t(e,t){if(t!==d._)return!a.is(e)||void(this.cb&&this.cb.call(this.as,e,t,this.n,this.s))}d.is=function(n,r,i){var a;return e("node.is"),!!o(n)&&!!(a=d.soul(n))&&!s(n,t,{as:i,cb:r,s:a,n})}}(),function(){function t(e,t){var n,r=this.o;r.map?void 0===(n=r.map.call(this.as,e,""+t,r.node))?p(r.node,t):r.node&&(r.node[t]=n):a.is(e)&&(r.node[t]=e)}d.ify=function(n,r,o){return e("node.ify"),r?"string"==typeof r?r={soul:r}:"function"==typeof r&&(r={map:r}):r={},r.map&&(r.node=r.map.call(o,n,A,r.node||{})),(r.node=d.soul.ify(r.node||{},r))&&s(n,t,{o:r,as:o}),r.node}}(),o=(E=t.obj).is;var p=E.del,g=(s=E.map,t.text.random),y=d.soul._;t.node=t.node||d;var m=t.state;m.lex=function(){return e("state.lex"),m().toString(36).replace(".","")},m.to=function(t,n,r){e("state.to");var i=(t||{})[n];return o(i)&&(i=w(i)),m.ify(r,n,m.is(t,n),i,d.soul(t))},function(){function t(e,t){b!==t&&m.ify(this.o,t,this.s)}m.map=function(r,a,c){var u;e("state.map");var f=o(f=r||a)?f:null;return r=n(r=r||a)?r:null,f&&!r?(a=l(a)?a:m(),f[b]=f[b]||{},s(f,t,{o:f,s:a}),f):(c=c||o(a)?a:u,a=l(a)?a:m(),function(e,n,o,s){if(!r)return t.call({o,s:a},e,n),e;r.call(c||this||{},e,n,o,s),i(o,n)&&u===o[n]||t.call({o,s:a},e,n)})}}(),(E=t.obj).as,i=E.has,o=E.is,s=E.map;var w=E.copy,b=(l=t.num.is,n=t.fn.is,d._),v={};!function(){function t(e,t){if(!e||t!==d.soul(e)||!d.is(e,this.fn,this.as))return!0;this.cb&&(n.n=e,n.as=this.as,this.cb.call(n.as,e,t,n))}function n(e){e&&d.is(n.n,e,n.as)}v.is=function(n,r,i,a){return e("graph.is"),!(!n||!o(n)||x(n)||s(n,t,{cb:r,fn:i,as:a}))}}(),function(){function n(e,t){var n;return(n=function(e,t){for(var n,r=e.seen,o=r.length;o--;)if(n=r[o],t.obj===n.obj)return n;r.push(t)}(e,t))?n:(t.env=e,t.soul=s,d.ify(t.obj,r,t)&&(t.link=t.link||a.link.ify(d.soul(t.node)),t.obj!==e.shell&&(e.graph[a.link.is(t.link)]=t.node)),t)}function r(e,t,r){var o,s,u=this,l=u.env;if(d._===t&&i(e,a.link._))return r._;if(o=c(e,t,r,u,l)){if(t||(u.node=u.node||r||{},i(e,d._)&&d.soul(e)&&(u.node._=w(e._)),u.node=d.soul.ify(u.node,a.link.is(u.link)),u.link=u.link||a.link.ify(d.soul(u.node))),(s=l.map)&&(s.call(l.as||{},e,t,r,u),i(r,t))){if(e=r[t],A===e)return void p(r,t);if(!(o=c(e,t,r,u,l)))return}if(!t)return u.node;if(!0===o)return e;if((s=n(l,{obj:e,path:u.path.concat(t)})).node)return s.link}}function s(e){var t=this,n=a.link.is(t.link),r=t.env.graph;t.link=t.link||a.link.ify(e),t.link[a.link._]=e,t.node&&t.node[d._]&&(t.node[d._][a.link._]=e),i(r,n)&&(r[e]=r[n],p(r,n))}function c(e,n,r,i,s){var u;return!!a.is(e)||(o(e)?1:(u=s.invalid)?c(e=u.call(s.as||{},e,n,r),n,r,i,s):(s.err="Invalid value at '"+i.path.concat(n).join(".")+"'!",void(t.list.is(e)&&(s.err+=" Use `.set(item)` instead of an Array."))))}v.ify=function(t,r,o){e("graph.ify");var i={path:[],obj:t};return r?"string"==typeof r?r={soul:r}:"function"==typeof r&&(r.map=r):r={},"string"==typeof o&&(r.soul=r.soul||o,o=A),r.soul&&(i.link=a.link.ify(r.soul)),r.shell=(o||{}).shell,r.graph=r.graph||{},r.seen=r.seen||[],r.as=r.as||o,n(r,i),r.root=i.node,r.graph}}(),v.node=function(t){e("graph.node");var n=d.soul(t);if(n)return h({},n,t)},function(){function t(e,t){var n,r;if(d._!==t)(n=a.link.is(e))?(r=this.opt.seen[n])?this.obj[t]=r:this.obj[t]=this.opt.seen[n]=v.to(this.graph,n,this.opt):this.obj[t]=e;else{if(x(e,a.link._))return;this.obj[t]=w(e)}}v.to=function(n,r,o){if(e("graph.to"),n){var i={};return o=o||{seen:{}},s(n[r],t,{obj:i,graph:n,opt:o}),i}}}(),n=t.fn.is,o=(E=t.obj).is,p=E.del,i=E.has;var E,A,x=E.empty;h=E.put,s=E.map,w=E.copy,t.graph=t.graph||v}}()},853(e,t,n){!function(){function t(e){(e=e||{}).log=e.log||console.log,e.file=String(e.file||"radata");var r=(t.has||(t.has={}))[e.file];if(r)return r;function s(e){return encodeURIComponent(e).replace(/\*/g,"%2A")}e.max=e.max||.3*(e.memory?999*e.memory*999:3e8),e.until=e.until||e.wait||250,e.batch=e.batch||1e4,e.chunk=e.chunk||1048576,e.code=e.code||{},e.code.from=e.code.from||"!",e.jsonify=!0;var a=""+m==typeof setImmediate?setTimeout:setImmediate,c=setTimeout.turn||a,u=i.object,l=0;if(!e.store)return e.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");if(!e.store.put)return e.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");if(!e.store.get)return e.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");e.store.list,n(60);var f=JSON.parseAsync||function(e,t,n){try{t(void 0,JSON.parse(e,n))}catch(e){t(e)}},h=(JSON.stringifyAsync,function(e,t,n,r,o){if("function"==typeof t){var i=n||{};return n=t,void h.read(e,n,i,o||r)}h.save(e,t,n,r,o)});h.save=function(t,n,r,o,a){var c,u,l={key:t,find:function(t){var n;l.file=t||(t=e.code.from),a&&(a=a[t]=a[t]||{}),a&&(a.sf=a.sf||+new Date),(n=h.disk[t])?l.mix(m,n):h.parse(t,l.mix,m,a)},mix:function(s,c){if(a&&(a.sml=+new Date),a&&(a.sm=a.sm||+new Date),l.err=s||l.err)r(s);else{var u,f=l.file=(c||"").file||l.file;if(!c&&f!==e.code.from)return h.find.bad(f),void h.save(t,n,r,o);(c=h.disk[f]||(h.disk[f]=c||i())).file||(c.file=f),e.compare&&(n=e.compare(c(t),n,t,f),m===n)?r(s,-1):((l.disk=c)(t,n),o&&((u=(u=c.tags||(c.tags={}))[o]||(u[o]=h.tags[o]||(h.tags[o]={})))[f]||(u[f]=h.one[o]||(h.one[o]=r)),r=null),a&&(a.st=a.st||+new Date),c.Q?r&&c.Q.push(r):(c.Q=r?[r]:[],c.to=setTimeout(l.write,e.until)))}},write:function(){a&&(a.sto=a.sto||+new Date);var e=c=l.file,t=l.disk;u=l.q=t.Q,l.tags=t.tags,delete t.Q,delete h.disk[e],delete t.tags,h.write(e,t,l.ack,m,a)},ack:function(e,t){var n,r;for(var o in a&&(a.sa=a.sa||+new Date),a&&(a.sal=u.length),h.tags)if(h.tags.hasOwnProperty(o)){var i=h.tags[o];if(!((r=h.disk[c])&&(r=r.tags)&&r[i])){var f;for(var d in n=i[c],delete i[c],i)if(i.hasOwnProperty(d)){f=!0;break}f||(delete h.tags[i],n&&n(e,t))}}!u&&(u="");for(var p=u.length,g=0,y=+new Date;g<p;g++)(n=u[g])&&n(e,t);console.STAT&&console.STAT(y,+new Date-y,"rad acks",s(l.file)),console.STAT&&console.STAT(y,u.length,"rad acks #",s(l.file))}};r||(r=function(e,t){}),h.find(t,l.find)},h.disk={},h.one={},h.tags={};var d,p,g,y=0;h.write=function(n,r,o,a,c){if(r){a="object"==typeof a?a:{force:a};var u,f,d=function(){};d.text="",d.file=n=r.file||(r.file=n),n?(d.write=function(){var t=r.raw=d.text;h.disk[n=r.file||d.file||n]=r;var i=+new Date;c&&(c.wd=i),h.find.add(n,function(a){c&&(c.wa=+new Date),a?o(a):e.store.put(s(n),t,function(e,t){c&&(c.wp=+new Date),console.STAT&&console.STAT(i,l=+new Date-i,"wrote disk",JSON.stringify(n),++y,"total all writes."),o(e,t||1),r.Q||delete h.disk[n]})})},d.split=function(){var e=+new Date;c&&(c.wf=e),d.text="",d.count||(d.count=0,i.map(r,function(){d.count++})),c&&(c.wfc=d.count),d.limit=Math.ceil(d.count/2);var t=d.count;return d.count=0,c&&(c.wf1=+new Date),d.sub=i(),i.map(r,d.slice,{reverse:1}),c&&(c.wf2=+new Date),h.write(d.end,d.sub,function(e,t){if(e)return o(e);c&&(c.wf3=+new Date),d.hub=i(),i.map(r,d.stop),c&&(c.wf4=+new Date),h.write(r.file,d.hub,o,a)},a),c&&(c.wf5=+new Date),console.STAT&&console.STAT(e,+new Date-e,"rad split",s(r.file),t),!0},d.slice=function(e,t){if(d.sub(d.end=t,e),d.limit<=++d.count)return!0},d.stop=function(e,t){if(t>=d.end)return!0;d.hub(t,e)},d.both=function(e,t){c&&(c.wfd=+new Date),f?o(e||f):u?o(e,t):(u=!0,f=e)},d.each=function(n,r,i,s){if(m!==n&&d.count++,e.max<=(n||"").length)return o("Data too big!"),!0;var c=t.encode(s.length)+"#"+t.encode(i)+(m===n?"":":"+t.encode(n))+"\n";if(e.chunk<d.text.length+c.length&&1<d.count&&!a.force)return d.split();d.text+=c},e.jsonify?h.write.jsonify(d,r,o,a,c):i.map(r,d.each,!0)||d.write()):o("What file?")}else o("No radix!")},h.write.jsonify=function(t,n,r,o,s){var a,c=+new Date;s&&(s.w=c);try{a=JSON.stringify(n.$)}catch(e){return void r("Cannot radisk!")}if(s&&(s.ws=+new Date),console.STAT&&console.STAT(c,+new Date-c,"rad stringified JSON"),e.chunk<a.length&&!o.force){var u=0;if(i.map(n,function(){if(u++)return!0}),u>1)return t.split()}t.text=a,t.write()},h.range=function(e,t){if(e&&t){if(m===t.start&&m===t.end)return e;if(m!==(n=e)&&(!n||"object"!=typeof n))return e;var n,r=i();return i.map(e,function(e,t){r(t,e)},t),r("")}},h.read=function(t,n,r,o){r=r||{};var u={key:t,find:function(t){var n;u.file=t||(t=e.code.from),o&&(o=o[t]=o[t]||{}),o&&(o.rf=o.rf||+new Date),(n=h.disk[u.file=t])?u.check(m,n):h.parse(t,u.check,m,o)},get:function(s,c,l){if(o&&(o.rgl=+new Date),o&&(o.rg=o.rg||+new Date),u.err=s||u.err)n(s);else{var f=u.file=(c||"").file||u.file;if(!c&&f!==e.code.from)return h.find.bad(f),void h.read(t,n,r);if(c=h.disk[f]||(h.disk[f]=c)){c.file||(c.file=f);var d=h.range(c(t),r);if(o&&(o.rr=+new Date),r.unit=c.unit,r.chunks=(r.chunks||0)+1,r.parsed=(r.parsed||0)+((l||"").parsed||r.chunks*e.chunk),r.more=1,r.next=m,i.map(h.list,function(e,t){if(e&&f!==t)return r.next=t,1},r.reverse?{reverse:1,end:f}:{start:f}),o&&(o.rl=+new Date),r.next||(r.more=0),r.next&&(!r.reverse&&(t<r.next&&0!=r.next.indexOf(t)||m!==r.end&&(r.end||"￿")<r.next)&&(r.more=0),r.reverse&&(t>r.next&&0!=t.indexOf(r.next)||m!==r.start&&(r.start||"")>r.next&&f<=r.start)&&(r.more=0)),r.more){if(d&&n(u.err,d,r),!(r.parsed>=r.limit)){var p=+new Date;o&&(o.rm=p);var g=r.next;a(function(){console.STAT&&console.STAT(p,+new Date-p,"rad more"),h.parse(g,u.check)},0)}}else n(u.err,d,r)}else n(f===e.code.from?m:"No file!")}},check:function(t,n,r){if(u.get(t,n,r),n&&!n.check){n.check=1;var o=+new Date;(r||(r={})).file||(r.file=u.file),i.map(n,function(t,n){h.find(n,function(o){if((o||(o=e.code.from))!==r.file){var i=(""+Math.random()).slice(-3);c(function(){h.save(n,t,function e(a,c){a?h.save(n,t,e):console.STAT&&console.STAT("MISLOCATED DATA CORRECTED",i,s(n),s(r.file),s(o))})},0)}})}),console.STAT&&console.STAT(o,+new Date-o,"rad check")}}};h.find(t||(r.reverse?r.end||"":r.start||""),u.find)},d=0,p={},g=String.fromCharCode(31),h.parse=function(n,r,o,a){var u;if(!n)return r();if(u=p[n])u.push(r);else{u=p[n]=[r];var y=function(){},w={file:n};(y.disk=i()).file=n,y.read=function(t,r){if(a&&(a.rpg=+new Date),console.STAT&&console.STAT(b,+new Date-b,"read disk",JSON.stringify(n),++d,"total all parses."),(y.err=t)||(y.not=!r))return delete p[n],void y.map(u,y.ack);if("string"!=typeof r){try{e.max<=r.length?y.err="Chunk too big!":r=r.toString()}catch(e){y.err=e}if(y.err)return delete p[n],void y.map(u,y.ack)}w.parsed=r.length,a&&(a.rpl=w.parsed),a&&(a.rpa=u.length),b=+new Date,e.jsonify||"{"===r[0]?f(r,function(e,t){return e?"{"===r[0]?(delete p[n],y.err="JSON error!",void y.map(u,y.ack)):void y.radec(e,r):(delete p[n],y.disk.$=t,console.STAT&&(l=+new Date-b)>9&&console.STAT(b,l,"rad parsed JSON"),a&&(a.rpd=+new Date),void y.map(u,y.ack))}):y.radec(t,r)},y.map=function(){if(u&&u.length){for(var e,t=+new Date,r=y.err,o=y.not?m:y.disk,i=0;i<9&&(e=u[i++]);)e(r,o,w);console.STAT&&console.STAT(t,+new Date-t,"rad packs",s(n)),console.STAT&&console.STAT(t,i,"rad packs #",s(n)),(u=u.slice(i)).length&&c(y.map,0)}},y.ack=function(e){e&&(y.err||y.not?e(y.err,m,w):e(m,y.disk,w))},y.radec=function(e,t){delete p[n],b=+new Date;var r,o,i,s=y.split(t),a=[];if(!s||0!==s[1])return y.err="File '"+n+"' does not have root radix! ",void y.map(u,y.ack);for(;s;)o=i=m,r=s[1],"#"==(s=y.split(s[2])||"")[0]&&(o=s[1],r<=(a=a.slice(0,r)).length&&a.push(o)),"\n"!=(s=y.split(s[2])||"")[0]&&("="!=s[0]&&":"!=s[0]||(i=s[1]),m!==o&&m!==i&&y.disk(a.join(""),i),s=y.split(s[2]));console.STAT&&console.STAT(b,+new Date-b,"parsed RAD"),y.map(u,y.ack)},y.split=function(e){if(e){var n,r,o=[],i={};if(n=e.indexOf(g),e[n])return r=e.slice(0,n),o[0]=r,o[1]=t.decode(e.slice(n),i),o[2]=e.slice(n+i.i),o}},h.disk&&(o||(o=(h.disk[n]||"").raw));var b=+new Date;if(a&&(a.rp=b),o)return c(function(){y.read(m,o)},0);e.store.get(s(n),y.read)}},function(){var t,n,r=String.fromCharCode(28);function o(n,a){if(n)return e.log("list",n),void setTimeout(function(){h.parse(r,o)},1e3);a?s(a):(t=t||a||i(),e.store.list?e.store.list(function(e){e?h.find.add(e,w):s(t)}):s(t))}function s(e,o){(t=t||e).file=r,o=n,n=null,u(o,function(e){h.find(e[0],e[1])})}h.find=function(s,a){if(!t)return n?void n.push([s,a]):(n=[[s,a]],void h.parse(r,o));i.map(h.list=t,function(e,t){if(e)return a(t)||!0},{reverse:1,end:s})||a(e.code.from)},h.find.add=function(e,n){t(e)||e===r?n(m,1):(t(e,1),n.found=(n.found||0)+1,h.write(r,t,function(e,t){e?n(e):(n.found=(n.found||0)-1,0===n.found&&n(m,1))},!0))},h.find.bad=function(e,n){t(e,0),h.write(r,t,n||w)}}();try{!o.window&&n(182)(h)}catch(e){}var m,w=function(){};return t.has[e.file]=h,h}var r;r=String.fromCharCode(31),t.encode=function(e,t,n){var o=n=n||r;if("string"==typeof e){for(var i=e.indexOf(n);-1!=i;)o+=n,i=e.indexOf(n,i+1);return o+'"'+e+n}return e&&e["#"]&&1==Object.keys(e).length?o+"#"+void 0+o:"number"==typeof e?o+"+"+(e||0)+o:null===e?o+" "+o:!0===e?o+"+"+o:!1===e?o+"-"+o:void 0},t.decode=function(e,t,n){var o,i,s,a=-1,c=0;if((n=n||r)===e[0]){for(;n===e[++a];)++c;for(s=e[i=c]||!0;--c>=0;)a=e.indexOf(n,a+1);return-1==a&&(a=e.length),o=e.slice(i+1,a),t&&(t.i=a+1),'"'===s?o:"#"===s?{"#":o}:"+"===s?0===o.length||parseFloat(o):" "===s?null:"-"!==s&&void 0}};var o="undefined"!=typeof window&&window.Gun?window.Gun:n(167),i="undefined"!=typeof window&&window.Radix?window.Radix:n(483);t.Radix=i,((t,n)=>{try{e.exports=n}catch(e){}"undefined"!=typeof window&&(window[t]=window[t]||n)})("Radisk",t)}()},483(e){!function(){function t(){var e=function(o,s,a){if(e.unit=0,a||n===s||(e.last=""+o<e.last?e.last:""+o,delete(e.$||{})[i]),a=a||e.$||(e.$={}),!o&&Object.keys(a).length)return a;for(var c,u,l=0,f=(o=""+o).length-1,h=o[l];!(c=a[h])&&l<f;)h+=o[++l];if(c){if(l!=f)return n!==s&&delete c[i],e(o.slice(++l),s,c||(c={}));if(n===s)return n===(u=c[""])?c:(e.unit=1)&&u;c[""]=s}else{if(!r(a,function(e,r){var i=0,c="";if((r||"").length)for(;r[i]==o[i];)c+=r[i++];if(c){if(n===s){if(i<=f)return;return(u||(u={}))[r.slice(i)]=e,e}var l={};return l[r.slice(i)]=e,""===(i=o.slice(i))?l[""]=s:(l[i]={})[""]=s,a[c]=l,t.debug&&"undefined"==""+c&&console.log(0,c),delete a[r],!0}})){if(n===s)return;(a[h]||(a[h]={}))[""]=s,t.debug&&"undefined"==""+h&&console.log(1,h)}if(n===s)return u}};return e}t.map=function e(r,s,a,c){try{c=c||[];var u="function"==typeof r?r.$||{}:r;if(!u)return;if("string"==typeof u){if(t.debug)throw["BUG:",r,s,a,c];return}var l,f=(u[i]||o).sort||(u[i]=function e(){return e.sort=Object.keys(u).sort(),e}()).sort;(l=(a=!0===a?{branch:!0}:a||{}).reverse)&&(f=f.slice(0).reverse());for(var h=a.start,d=a.end,p=0,g=f.length;p<g;p++){var y,m,w,b=f[p],v=u[b];if(v&&""!==b&&i!==b&&"undefined"!==b&&((m=c.slice(0)).push(b),w=m.join(""),!(n!==h&&w<(h||"").slice(0,w.length)||n!==d&&(d||"￿")<w))){if(l&&(y=e(v,s,a,m),n!==y))return y;if(n!==(y=v[""])){var E=1;if(n!==h&&w<(h||"")&&(E=0),n!==d&&w>(d||"￿")&&(E=0),E&&(y=s(y,w,b,c),n!==y))return y}else if(a.branch&&(y=s(n,w,b,c),n!==y))return y;if(c=m,!l&&(y=e(v,s,a,c),n!==y))return y;c.pop()}}}catch(e){console.error(e)}},function(t,n){"undefined"!=typeof window&&(window[t]=window[t]||n);try{e.exports=n}catch(e){}}("Radix",t);var n,r=t.object=function(e,t,r){for(var o in e)if(e.hasOwnProperty(o)&&(r=t(e[o],o))!==n)return r},o={},i=String.fromCharCode(24)}()},182(e,t,n){e.exports=function(e){var t=n(483);e.find("a",function(){var n,r,o=[];t.map(e.list,function(e,t){t.indexOf("%1B")+1&&e&&o.push([t,e])}),o.length&&console.log("\n! ! ! WARNING ! ! !\nRAD v0.2020.x has detected OLD v0.2019.x data & automatically migrating. Automatic migration will be turned OFF in future versions! If you are just developing/testing, we recommend you reset your data. Please contact us if you have any concerns.\nThis message should only log once."),o.forEach(function(t){n=t[0],r=t[1],e.list(decodeURIComponent(n),r),e.list(n,0)}),n&&e.find.bad(n)})}},502(e,t,n){!function(){function t(e){(e=e||{}).file=String(e.file||"radata");var n=t[e.file],r=null;if(n)return console.log("Warning: reusing same IndexedDB store and options as 1st."),t[e.file];n=t[e.file]=function(){};try{e.indexedDB=e.indexedDB||t.indexedDB||indexedDB}catch(e){}try{if(!e.indexedDB||"file:"==location.protocol){var o=n.d||(n.d={});return n.put=function(e,t,n){o[e]=t,setTimeout(function(){n(null,1)},250)},n.get=function(e,t){setTimeout(function(){t(null,o[e]||void 0)},5)},console.log("Warning: No indexedDB exists to persist data to!"),n}}catch(e){}return n.start=function(){var t=indexedDB.open(e.file,1);t.onupgradeneeded=function(t){t.target.result.createObjectStore(e.file)},t.onsuccess=function(){r=t.result},t.onerror=function(e){console.log(e||1)}},n.start(),n.put=function(t,o,i){if(r){var s=r.transaction([e.file],"readwrite"),a=s.objectStore(e.file),c=a.put(o,""+t);c.onsuccess=a.onsuccess=s.onsuccess=function(){i(null,1)},c.onabort=a.onabort=s.onabort=function(e){i(e||"put.tx.abort")},c.onerror=a.onerror=s.onerror=function(e){i(e||"put.tx.error")}}else setTimeout(function(){n.put(t,o,i)},1)},n.get=function(t,o){if(r){var i=r.transaction([e.file],"readonly").objectStore(e.file).get(""+t);i.onsuccess=function(){o(null,i.result)},i.onabort=function(e){o(e||4)},i.onerror=function(e){o(e||5)}}else setTimeout(function(){n.get(t,o)},9)},setInterval(function(){r&&r.close(),r=null,n.start()},15e3),n}if("undefined"!=typeof window)(t.window=window).RindexedDB=t,t.indexedDB=window.indexedDB;else try{e.exports=t}catch(e){}try{(t.window.Gun||n(167)).on("create",function(e){this.to.next(e),e.opt.store=e.opt.store||t(e.opt)})}catch(e){}}()},888(e,t,n){var r=n(606),o="undefined"!=typeof window?window.Gun:n(167);o.on("create",function(e){o.TESTING&&(e.opt.file="radatatest"),this.to.next(e);var t,i=e.opt;if(!1!==i.rad&&!1!==i.radisk&&(t+""==typeof r||"false"!=""+(r.env||"").RAD)){var s=o.window&&o.window.Radisk||n(853),a=s.Radix,c=s(i),u=String.fromCharCode(27),l=0;e.on("put",function(t){if(this.to.next(t),!(t._||"").rad){var n=t["#"],r=t.put,o=r["#"],i=r["."],s=r[":"],a=r[">"],l=(t._||"").DBG;l&&(l.sp=l.sp||+new Date);var f=(t._||"").RPS||((t._||"").RPS=+new Date);c(o+u+i,{":":s,">":a},function(t,r){l&&(l.spd=l.spd||+new Date),console.STAT&&console.STAT(f,+new Date-f,"put"),t?e.on("in",{"@":n,err:t,DBG:l}):e.on("in",{"@":n,ok:r,DBG:l})},!1,l&&(l.r=l.r||{})),l&&(l.sps=l.sps||+new Date)}}),Object.empty,e.on("get",function(n){this.to.next(n);var r=(n._||"").DBG=n.DBG;r&&(r.sg=+new Date);var h,d,p,g,y=n["#"],m=n.get,w=n.get["#"],b=n.get["."]||"",v={};if("string"==typeof w?d=w:w&&(t!==(p=w["*"])&&(v.limit=g=1),t!==w[">"]&&(v.start=w[">"]),t!==w["<"]&&(v.end=w["<"]),d=g?""+p:p||w["="],g=null),d&&!v.limit&&("string"==typeof b?d=d+u+(v.atom=b):b&&(t!==b[">"]&&(v.start=b[">"],v.limit=1),t!==b["<"]&&(v.end=b["<"],v.limit=1),t!==(p=b["*"])&&(v.limit=g=1),d&&(d=d+u+(g?""+(p||""):p||(v.atom=b["="]||""))))),((p=m["%"])||v.limit)&&(v.limit=p<=(v.pack||1e5)?p:1),(b["-"]||(w||{})["-"]||m["-"])&&(v.reverse=!0),(p=(e.next||"")[w])&&p.put)if(v.atom){if((p=(p.next||"")[v.atom])&&p.root&&p.root.graph&&p.root.graph[w]&&p.root.graph[w][v.atom])return}else if(p&&p.rad)return;var E=o.state(),A=+new Date,x=0;function k(e,t,n,r){if(x++,e){var i=(t=(d+t).split(u)).slice(0,1)[0];if(t=t.slice(-1)[0],v.limit&&v.limit<=v.count)return!0;var a,c,l=i,f=t;if("string"!=typeof e)return a=e[":"],c=e[">"],(h=h||{})[l]=o.state.ify(h[l],f,c,a,l),void(v.count=(v.count||0)+((a||"").length||9));v.count=(v.count||0)+e.length;var p=e.lastIndexOf(">"),g=s.decode(e.slice(p+1),null,u);e=s.decode(e.slice(0,p),null,u),(h=h||{})[i]=o.state.ify(h[i],t,g,e,i)}}r&&(r.sgm=A),c(d||"",function(n,s,c){r&&(r.sgr=+new Date),r&&(r.sgi=c);try{i.store.stats.get.time[f%50]=+new Date-A,++f,i.store.stats.get.count++,n&&(i.store.stats.get.err=n)}catch(e){}var p,g;if(console.STAT&&console.STAT(A,+new Date-A,"got",JSON.stringify(d)),A=+new Date,(c=c||"").unit&&s&&t!==(p=s[":"])&&t!==(g=s[">"])){var S=d.split(u),I=S[0],P=S[1];(h=h||{})[I]=o.state.ify(h[I],P,g,p,I),e.$.get(I).get(P)._.rad=E}else s&&("string"!=typeof s&&(v.atom?s=t:a.map(s,k,v)),!h&&s&&k(s,""),!v.atom&&!b&"string"==typeof w&&!v.limit&&!v.more&&(e.$.get(w)._.rad=E));r&&(r.sgp=+new Date),console.STAT&&(l=+new Date-A)>9&&(console.STAT(A,l,"got prep time"),console.STAT(A,x,"got prep #")),x=0,A=+new Date;var C=function(){};C.faith=!0,C.rad=m,e.on("in",{"@":y,put:h,"%":c.more?1:t,err:n||t,_:C,DBG:r}),console.STAT&&(l=+new Date-A)>9&&console.STAT(A,l,"got emit",Object.keys(h||{}).length),h=t},v,r&&(r.r=r.r||{})),r&&(r.sgd=+new Date),console.STAT&&(l=+new Date-A)>9&&console.STAT(A,l,"get call")}),o.valid,(i.store||{}).stats={get:{time:{},count:0},put:{time:{},count:0}};var f=0}})},670(e,t,n){var r="undefined"!=typeof window?window.Gun:n(167);r.chain.promise=function(e){var t=this;return e=e||function(e){return e},new Promise(function(e,n){t.once(function(t,n){e({put:t,get:n,gun:this})})}).then(e)},r.chain.then=function(e){var t=this,n=new Promise((e,n)=>{t.once(function(t,n){e(t,n)})});return e?n.then(e):n}},968(e,t,n){!function(){var e="undefined"!=typeof window?window.Gun:n(167);e.on("opt",function(t){this.to.next(t);var r=t.opt;if(!t.once&&e.Mesh&&!1!==r.RTCPeerConnection){var o;"undefined"!=typeof window&&(o=window),void 0!==n.g&&(o=n.g),o=o||{};var i=r.RTCPeerConnection||o.RTCPeerConnection||o.webkitRTCPeerConnection||o.mozRTCPeerConnection,s=r.RTCSessionDescription||o.RTCSessionDescription||o.webkitRTCSessionDescription||o.mozRTCSessionDescription,a=r.RTCIceCandidate||o.RTCIceCandidate||o.webkitRTCIceCandidate||o.mozRTCIceCandidate;if(i&&s&&a){r.RTCPeerConnection=i,r.RTCSessionDescription=s,r.RTCIceCandidate=a,r.rtc=r.rtc||{iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun.sipgate.net:3478"}]},r.rtc.dataChannel=r.rtc.dataChannel||{ordered:!1,maxRetransmits:2},r.rtc.sdp=r.rtc.sdp||{mandatory:{OfferToReceiveAudio:!1,OfferToReceiveVideo:!1}},r.rtc.max=r.rtc.max||55,r.rtc.room=r.rtc.room||e.window&&(location.hash.slice(1)||location.pathname.slice(1)),r.announce=function(e){r.rtc.start=+new Date,t.$.get("/RTC/"+r.rtc.room+"<?99").get("+").put(r.pid,function(e){e.ok&&e.ok.rtc&&u(e)},{acks:r.rtc.max}).on(function(e,t,n){e===r.pid||r.rtc.start>n.put[">"]||u({"#":""+n["#"],ok:{rtc:{id:e}}})})};var c=r.mesh=r.mesh||e.Mesh(t);t.on("create",function(e){this.to.next(e),setTimeout(r.announce,1)})}}function u(e){if(this&&this.off&&this.off(),e.ok){var n,o,i=e.ok.rtc;if(i&&i.id&&i.id!==r.pid){if(o=i.answer){if(!(n=r.peers[i.id]||u[i.id])||n.remoteSet)return;return o.sdp=o.sdp.replace(/\\r\\n/g,"\r\n"),n.setRemoteDescription(n.remoteSet=new r.RTCSessionDescription(o))}if(o=i.candidate)return(n=r.peers[i.id]||u[i.id]||u({ok:{rtc:{id:i.id}}})).addIceCandidate(new r.RTCIceCandidate(o));if(!u[i.id]){(n=new r.RTCPeerConnection(r.rtc)).id=i.id;var s=n.wire=n.createDataChannel("dc",r.rtc.dataChannel);return u[i.id]=n,s.to=setTimeout(function(){delete u[i.id]},6e4),s.onclose=function(){c.bye(n)},s.onerror=function(e){},s.onopen=function(e){delete u[i.id],c.hi(n)},s.onmessage=function(e){e&&c.hear(e.data||e,n)},n.onicecandidate=function(n){n.candidate&&t.on("out",{"@":e["#"],ok:{rtc:{candidate:n.candidate,id:r.pid}}})},n.ondatachannel=function(e){var t=e.channel;t.onmessage=s.onmessage,t.onopen=s.onopen,t.onclose=s.onclose},(o=i.offer)?(i.offer.sdp=i.offer.sdp.replace(/\\r\\n/g,"\r\n"),n.setRemoteDescription(new r.RTCSessionDescription(o)),void n.createAnswer(function(o){n.setLocalDescription(o),t.on("out",{"@":e["#"],ok:{rtc:{answer:o,id:r.pid}}})},function(){},r.rtc.sdp)):(n.createOffer(function(o){n.setLocalDescription(o),t.on("out",{"@":e["#"],"#":t.ask(u),ok:{rtc:{offer:o,id:r.pid}}})},function(){},r.rtc.sdp),n)}}}}})}()},60(e){!function(){var t,n={},r=setTimeout.turn||typeof setImmediate!=""+t&&setImmediate||setTimeout;function o(e){var t=parseFloat(e);return isNaN(t)?"true"==(e=e.trim())||"false"!=e&&("null"==e?null:void 0):t}n.parseAsync=function(e,n,i,s){if("string"==typeof e){var a={i:0,text:e,done:n,l:e.length,up:[]};s=s||32768,function n(){for(var i,c,u=a.text,l=a.i,f=a.l,h=0,d=a.w;h++<s;){var p=u[l++];if(l>f){a.end=!0;break}if(d){for(l=u.indexOf('"',l-1),p=u[l],c=0;"\\"==u[l-++c];);c=!(c%2),i=i||c,'"'!=p||c||(d=t,c=a.s,a.a?(c=u.slice(a.sl,l),(i||1+c.indexOf("\\"))&&(c=JSON.parse('"'+c+'"')),a.at instanceof Array?a.at.push(a.s=c):(a.at||(a.end=h=s,c=t),(a.at||{})[a.s]=a.s=c),a.s=t):(a.s=u.slice(a.sl,l),(i||1+a.s.indexOf("\\"))&&(a.s=JSON.parse('"'+a.s+'"'))),a.a=i=t),++l}else switch(p){case'"':a.sl=l,d=!0;break;case":":a.ai=l,a.a=!0;break;case",":(a.a||a.at instanceof Array)&&(c=u.slice(a.ai,l-1))&&t!==(c=o(c))&&(a.at instanceof Array?a.at.push(c):a.at[a.s]=c),a.a=t,a.at instanceof Array&&(a.a=!0,a.ai=l);break;case"{":a.up.push(a.at||(a.at={})),a.at instanceof Array?a.at.push(a.at={}):t!==(c=a.s)&&(a.at[c]=a.at={}),a.a=t;break;case"}":a.a&&(c=u.slice(a.ai,l-1))&&t!==(c=o(c))&&(a.at instanceof Array?a.at.push(c):(a.at||(a.end=h=s,c=t),(a.at||{})[a.s]=c)),a.a=t,a.at=a.up.pop();break;case"[":t!==(c=a.s)?(a.up.push(a.at),a.at[c]=a.at=[]):a.at||a.up.push(a.at=[]),a.a=!0,a.ai=l;break;case"]":a.a&&(c=u.slice(a.ai,l-1))&&t!==(c=o(c))&&(a.at instanceof Array?a.at.push(c):a.at[a.s]=c),a.a=t,a.at=a.up.pop()}}if(a.s=t,a.i=l,a.w=d,a.end){if(c=a.at,t===c)try{c=JSON.parse(e)}catch(e){return a.done(e)}a.done(t,c)}else r(n)}()}else try{n(t,JSON.parse(e))}catch(e){n(e)}},n.stringifyAsync=function(e,n,o,i,s){(s=s||{}).text=s.text||"",s.up=[s.at={d:e}],s.done=n,s.i=0;var a=0;!function e(){var n,o=s.at,i=o.d,c="";switch(o.i&&o.i-o.j>0&&(c+=","),t!==(n=o.k)&&(c+=JSON.stringify(n)+":"),typeof i){case"boolean":c+=""+i;break;case"string":c+=JSON.stringify(i);break;case"number":c+=isNaN(i)?"null":i;break;case"object":if(!i){c+="null";break}if(i instanceof Array){c+="[",(o={i:-1,as:i,up:o,j:0}).l=i.length,s.up.push(s.at=o);break}if("function"!=typeof(i||"").toJSON){c+="{",(o={i:-1,ok:Object.keys(i).sort(),as:i,up:o,j:0}).l=o.ok.length,s.up.push(s.at=o);break}if(n=i.toJSON()){c+=n;break}case"function":if(o.as instanceof Array){c+="null";break}default:c="",o.j++}for(s.text+=c;1+o.i>=o.l;)s.text+=o.ok?"}":"]",o=s.at=o.up;if(++o.i<o.l)return(n=o.ok)?o.d=o.as[o.k=n[o.i]]:o.d=o.as[o.i],++a<9?e():(a=0,void r(e));s.done(t,s.text)}()},typeof window!=""+t&&(window.YSON=n);try{e.exports=n}catch(e){}typeof JSON!=""+t&&(JSON.parseAsync=n.parseAsync,JSON.stringifyAsync=n.stringifyAsync)}()},66(e,t,n){e=n.nmd(e);var r=n(287).hp;!function(){function t(e,r){return r?n(132)(e):e.slice?t[o(e)]:function(n,r){e(n={exports:{}}),t[o(r)]=n.exports};function o(e){return e.split("/").slice(-1).toString().replace(".js","")}}var o=e;t(function(e){e.window="undefined"!=typeof globalThis&&"undefined"==typeof window&&"undefined"!=typeof WorkerGlobalScope?globalThis:"undefined"!=typeof window?window:void 0;var t=(e.window||e).SEA||{};(t.window=e.window)&&(t.window.SEA=t);try{void 0+""!=typeof o&&(o.exports=t)}catch(e){}e.exports=t})(t,"./root"),t(function(e){var n=t("./root");try{n.window&&location.protocol.indexOf("s")<0&&location.host.indexOf("localhost")<0&&!/^127\.\d+\.\d+\.\d+$/.test(location.hostname)&&location.protocol.indexOf("blob:")<0&&location.protocol.indexOf("file:")<0&&"null"!=location.origin&&(console.warn("HTTPS needed for WebCrypto in SEA, redirecting..."),location.protocol="https:")}catch(e){}})(t,"./https"),t(function(e){var o;if(o+""==typeof btoa){if(o+""==typeof r)try{n.g.Buffer=t("buffer",1).Buffer}catch(e){console.log("Please `npm install buffer` or add it to your package.json !")}n.g.btoa=function(e){return r.from(e,"binary").toString("base64")},n.g.atob=function(e){return r.from(e,"base64").toString("binary")}}})(t,"./base64"),t(function(e){function n(){}t("./base64"),Object.assign(n,{from:Array.from}),n.prototype=Object.create(Array.prototype),n.prototype.toString=function(e,t,n){e=e||"utf8",t=t||0;const r=this.length;if("hex"===e){const e=new Uint8Array(this);return[...Array((n&&n+1||r)-t).keys()].map(n=>e[n+t].toString(16).padStart(2,"0")).join("")}return"utf8"===e?Array.from({length:(n||r)-t},(e,n)=>String.fromCharCode(this[n+t])).join(""):"base64"===e?btoa(this):void 0},e.exports=n})(t,"./array"),t(function(e){t("./base64");var n=t("./array");function r(...e){return console.warn("new SafeBuffer() is depreciated, please use SafeBuffer.from()"),r.from(...e)}r.prototype=Object.create(Array.prototype),Object.assign(r,{from(){if(!Object.keys(arguments).length||null==arguments[0])throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.");const e=arguments[0];let t;if("string"==typeof e){const r=arguments[1]||"utf8";if("hex"===r){const r=e.match(/([\da-fA-F]{2})/g).map(e=>parseInt(e,16));if(!r||!r.length)throw new TypeError("Invalid first argument for type 'hex'.");t=n.from(r)}else if("utf8"===r||"binary"===r){const r=e.length,o=new Uint16Array(r);Array.from({length:r},(t,n)=>o[n]=e.charCodeAt(n)),t=n.from(o)}else if("base64"===r){const r=atob(e),o=r.length,i=new Uint8Array(o);Array.from({length:o},(e,t)=>i[t]=r.charCodeAt(t)),t=n.from(i)}else"binary"===r?t=n.from(e):console.info("SafeBuffer.from unknown encoding: "+r);return t}if(e.byteLength,e.byteLength?e.byteLength:e.length){let t;return e instanceof ArrayBuffer&&(t=new Uint8Array(e)),n.from(t||e)}},alloc:(e,t=0)=>n.from(new Uint8Array(Array.from({length:e},()=>t))),allocUnsafe:e=>n.from(new Uint8Array(Array.from({length:e}))),concat(e){if(!Array.isArray(e))throw new TypeError("First argument must be Array containing ArrayBuffer or Uint8Array instances.");return n.from(e.reduce((e,t)=>e.concat(Array.from(t)),[]))}}),r.prototype.from=r.from,r.prototype.toString=n.prototype.toString,e.exports=r})(t,"./buffer"),t(function(e){const n=t("./root"),r={Buffer:t("./buffer")};var i={};if(JSON.parseAsync=JSON.parseAsync||function(e,t,n){try{t(void 0,JSON.parse(e,n))}catch(e){t(e)}},JSON.stringifyAsync=JSON.stringifyAsync||function(e,t,n,r){try{t(void 0,JSON.stringify(e,n,r))}catch(e){t(e)}},r.parse=function(e,t){return new Promise(function(n,r){JSON.parseAsync(e,function(e,t){e?r(e):n(t)},t)})},r.stringify=function(e,t,n){return new Promise(function(r,o){JSON.stringifyAsync(e,function(e,t){e?o(e):r(t)},t,n)})},n.window&&(r.crypto=n.window.crypto||n.window.msCrypto,r.subtle=(r.crypto||i).subtle||(r.crypto||i).webkitSubtle,r.TextEncoder=n.window.TextEncoder,r.TextDecoder=n.window.TextDecoder,r.random=e=>r.Buffer.from(r.crypto.getRandomValues(new Uint8Array(r.Buffer.alloc(e))))),!r.TextDecoder){const{TextEncoder:e,TextDecoder:n}=t((void 0+""==typeof o?".":"")+"./lib/text-encoding",1);r.TextDecoder=n,r.TextEncoder=e}if(!r.crypto)try{var s=t("crypto",1);Object.assign(r,{crypto:s,random:e=>r.Buffer.from(s.randomBytes(e))});const{Crypto:e}=t("@peculiar/webcrypto",1);r.ossl=r.subtle=new e({directory:"ossl"}).subtle}catch(e){console.log("Please `npm install @peculiar/webcrypto` or add it to your package.json !")}e.exports=r})(t,"./shim"),t(function(e){var n=t("./root"),r=t("./shim"),o={pbkdf2:{hash:{name:"SHA-256"},iter:1e5,ks:64},ecdsa:{pair:{name:"ECDSA",namedCurve:"P-256"},sign:{name:"ECDSA",hash:{name:"SHA-256"}}},ecdh:{name:"ECDH",namedCurve:"P-256"},jwk:function(e,t){var n={kty:"EC",crv:"P-256",x:(e=e.split("."))[0],y:e[1],ext:!0};return n.key_ops=t?["sign"]:["verify"],t&&(n.d=t),n},keyToJwk:function(e){return{kty:"oct",k:e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,""),ext:!1,alg:"A256GCM"}},recall:{validity:43200,hook:function(e){return e}},check:function(e){return"string"==typeof e&&"SEA{"===e.slice(0,4)},parse:async function(e){try{var t="string"==typeof e;return t&&"SEA{"===e.slice(0,4)&&(e=e.slice(3)),t?await r.parse(e):e}catch(e){}return e}};n.opt=o,e.exports=o})(t,"./settings"),t(function(e){var n=t("./shim");e.exports=async function(e,t){var r="string"==typeof e?e:await n.stringify(e),o=await n.subtle.digest({name:t||"SHA-256"},(new n.TextEncoder).encode(r));return n.Buffer.from(o)}})(t,"./sha256"),t(function(e){const n=t("./shim"),r=n.subtle,o=n.ossl?n.ossl:r;e.exports=e=>o.digest({name:"SHA-1"},new ArrayBuffer(e))})(t,"./sha1"),t(function(e){var n=t("./root"),r=t("./shim"),o=t("./settings"),i=t("./sha256");n.work=n.work||(async(e,t,s,a)=>{try{var c=(t||{}).epub||t;if(a=a||{},c instanceof Function&&(s=c,c=void 0),e instanceof ArrayBuffer&&(e=new Uint8Array(e),e=new r.TextDecoder("utf-8").decode(e)),e="string"==typeof e?e:await r.stringify(e),"sha"===(a.name||"").toLowerCase().slice(0,3)){var u=r.Buffer.from(await i(e,a.name),"binary").toString(a.encode||"base64");if(s)try{s(u)}catch(e){console.log(e)}return u}"number"==typeof c&&(c=c.toString()),"number"==typeof a.salt&&(a.salt=a.salt.toString()),c=c||r.random(9);var l=await(r.ossl||r.subtle).importKey("raw",(new r.TextEncoder).encode(e),{name:a.name||"PBKDF2"},!1,["deriveBits"]),f=await(r.ossl||r.subtle).deriveBits({name:a.name||"PBKDF2",iterations:a.iterations||o.pbkdf2.iter,salt:(new r.TextEncoder).encode(a.salt||c),hash:a.hash||o.pbkdf2.hash},l,a.length||8*o.pbkdf2.ks);e=r.random(e.length);var h=r.Buffer.from(f,"binary").toString(a.encode||"base64");if(s)try{s(h)}catch(e){console.log(e)}return h}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(s&&s())}}),e.exports=n.work})(t,"./work"),t(function(e){var n=t("./root"),r=t("./shim");const o=BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),i=BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),s=BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),a=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),c={x:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),y:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")};function u(e,t){return(e%t+t)%t}function l(e,t){return function(e,t,n){if(n===BigInt(1))return BigInt(0);e=u(e,n);let r=BigInt(1),o=t;for(;o>BigInt(0);){const t=o&BigInt(1),i=u(r*e,n);r=t?i:r,o>>=BigInt(1),e=u(e*e,n)}return r}(e,t-BigInt(2),t)}function f(e){if(!e)return!1;const{x:t,y:n}=e;return u(n*n,i)===u(u(u(t*t,i)*t,i)+u(s*t,i)+a,i)}function h(e,t){if(null===e)return t;if(null===t)return e;if(e.x===t.x&&0n===u(e.y+t.y,i))return null;let n=e.x===t.x&&e.y===t.y?u((3n*u(e.x**2n,i)+s)*l(2n*e.y,i),i):u(u(t.y-e.y,i)*l(u(t.x-e.x,i),i),i);const r=u(n**2n-e.x-t.x,i);return{x:r,y:u(n*u(e.x-r,i)-e.y,i)}}function d(e,t){let n=null,r=t;for(let t=0;t<256;t++){const o=e>>BigInt(t)&1n,i=h(n,r);n=o?i:n,r=h(r,r)}return n}n.pair=n.pair||(async(e,t)=>{try{t=t||{};const n=r.subtle,s=r.ossl||n;let a={};const l=e=>{if("string"!=typeof e||0===e.length)throw new Error("Invalid base64 input: must be non-empty string");const t=e.replace(/-/g,"+").replace(/_/g,"/");if(!/^[A-Za-z0-9+/]*={0,2}$/.test(t))throw new Error("Invalid base64 characters detected");try{const e=t.padEnd(4*Math.ceil(t.length/4),"="),n=r.Buffer.from(e,"base64").toString("hex");if(n.length>64)throw new Error("Decoded value exceeds 256 bits for P-256");return BigInt("0x"+n)}catch(e){if(e.message.includes("256 bits"))throw e;throw new Error("Invalid base64 decoding: "+e.message)}},p=e=>{const t=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");if(e<0n||e>t)throw new Error("Invalid BigInt: must be 0 <= n <= 2^256-1");const n=e.toString(16).padStart(64,"0");if(n.length>64)throw new Error("BigInt too large for P-256: exceeds 256 bits");return r.Buffer.from(n,"hex").toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")},g=(e,t)=>{if(e<=0n||e>=o)throw new Error((t||"Private key")+" out of range");return e},y=e=>{g(e,"Private key");const t=d(e,c);if(!f(t))throw new Error("Invalid point generated");return p(t.x)+"."+p(t.y)},m=e=>{if(!e||"string"!=typeof e)throw new Error("Invalid pub format: must be string");const t=e.split(".");if(2!==t.length)throw new Error("Invalid pub format: must be x.y");const n={x:l(t[0]),y:l(t[1])};if(n.x>=i||n.y>=i)throw new Error("Invalid public key: out of range");if(!f(n))throw new Error("Invalid public key: not on curve");return n},w=e=>{if(!e||!f(e))throw new Error("Invalid point: not on curve");return p(e.x)+"."+p(e.y)},b=e=>{const t=new r.TextEncoder;return"string"==typeof e?t.encode(e).buffer:e instanceof ArrayBuffer?e:e&&void 0!==e.byteLength?e.buffer||e:null},v=async(e,t)=>{const i=new r.TextEncoder,s=b(e);if(!s)throw new Error("Invalid seed");const a=new Uint8Array(s.byteLength+i.encode(t).buffer.byteLength);a.set(new Uint8Array(s),0),a.set(new Uint8Array(i.encode(t).buffer),s.byteLength);let c=await n.digest("SHA-256",a.buffer),u=0;for(;u<100;){let e=BigInt("0x"+Array.from(new Uint8Array(c)).map(e=>e.toString(16).padStart(2,"0")).join(""));if(e>0n&&e<o)return e;const t=new Uint8Array(4);new DataView(t.buffer).setUint32(0,u,!0);const r=new Uint8Array(c.byteLength+t.byteLength);r.set(new Uint8Array(c),0),r.set(t,c.byteLength),c=await n.digest("SHA-256",r.buffer),u++}throw new Error("Failed to generate valid private key after 100 attempts")},E=async(e,t,i)=>{const s=new r.TextEncoder,a=b(e);if(!a)throw new Error("Invalid seed");const c=null!=i?t+i:t,u=s.encode(c).buffer,l=new Uint8Array(a.byteLength+u.byteLength);l.set(new Uint8Array(u),0),l.set(new Uint8Array(a),u.byteLength);let f=await n.digest("SHA-256",l.buffer),h=0;for(;h<100;){const e=BigInt("0x"+Array.from(new Uint8Array(f)).map(e=>e.toString(16).padStart(2,"0")).join(""));if(e>0n&&e<o)return e;const t=new Uint8Array(4);new DataView(t.buffer).setUint32(0,h,!0);const r=new Uint8Array(f.byteLength+t.byteLength);r.set(new Uint8Array(f),0),r.set(t,f.byteLength),f=await n.digest("SHA-256",r.buffer),h++}throw new Error("Failed to derive scalar after 100 attempts")},A=async(e,t,n)=>E(e,t,0===n?null:n),x=async(e,n)=>{for(let r=0;r<100;r++){const i=u(e+await A(t.seed,n,r),o);if(0n!==i)return{derivedPriv:i,attempt:r}}throw new Error("Failed to derive non-zero private key")},k=async(e,n)=>{for(let r=0;r<100;r++){const o=h(e,d(await A(t.seed,n,r),c));if(o)return o}throw new Error("Failed to derive valid public key")};if(t.seed&&(t.priv||t.epriv||t.pub||t.epub)){if(a={},t.priv){const e=g(l(t.priv),"Private key"),n=(await x(e,"SEA.DERIVE|sign|")).derivedPriv,r=d(n,c);a.priv=p(n),a.pub=w(r)}if(t.epriv){const e=g(l(t.epriv),"Encryption private key"),n=(await x(e,"SEA.DERIVE|encrypt|")).derivedPriv,r=d(n,c);a.epriv=p(n),a.epub=w(r)}if(t.pub){const e=m(t.pub),n=await k(e,"SEA.DERIVE|sign|");a.pub=w(n)}if(t.epub){const e=m(t.epub),n=await k(e,"SEA.DERIVE|encrypt|");a.epub=w(n)}}else if(t.priv){const e=g(l(t.priv),"Private key");if(a={priv:t.priv,pub:y(e)},t.epriv){const e=g(l(t.epriv),"Encryption private key");a.epriv=t.epriv,a.epub=y(e)}else try{const e=await s.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"]).then(async e=>({epriv:(await s.exportKey("jwk",e.privateKey)).d,epub:(await s.exportKey("jwk",e.publicKey)).x+"."+(await s.exportKey("jwk",e.publicKey)).y}));a.epriv=e.epriv,a.epub=e.epub}catch(e){}}else if(t.epriv){const e=g(l(t.epriv),"Encryption private key");if(a={epriv:t.epriv,epub:y(e)},t.priv){const e=g(l(t.priv),"Private key");a.priv=t.priv,a.pub=y(e)}else{const e=await n.generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign","verify"]).then(async e=>({priv:(await n.exportKey("jwk",e.privateKey)).d,pub:(await n.exportKey("jwk",e.publicKey)).x+"."+(await n.exportKey("jwk",e.publicKey)).y}));a.priv=e.priv,a.pub=e.pub}}else if(t.seed){const e=await v(t.seed,"-sign"),n=await v(t.seed,"-encrypt");a={priv:p(e),pub:y(e),epriv:p(n),epub:y(n)}}else{const e=await n.generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign","verify"]).then(async e=>({priv:(await n.exportKey("jwk",e.privateKey)).d,pub:(await n.exportKey("jwk",e.publicKey)).x+"."+(await n.exportKey("jwk",e.publicKey)).y}));a={pub:e.pub,priv:e.priv};try{const e=await s.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"]).then(async e=>({epriv:(await s.exportKey("jwk",e.privateKey)).d,epub:(await s.exportKey("jwk",e.publicKey)).x+"."+(await s.exportKey("jwk",e.publicKey)).y}));a.epub=e.epub,a.epriv=e.epriv}catch(e){}}if(e)try{e(a)}catch(e){}return a}catch(t){if(n.err=t,n.throw)throw t;if(e)try{e()}catch(e){}throw new Error("Key generation failed: "+(t.message||"Unknown error"))}}),e.exports=n.pair})(t,"./pair"),t(function(e){var n,r=t("./root"),o=t("./shim"),i=t("./settings"),s=t("./sha256");async function a(e,t,n){try{if(t.raw||(e="SEA"+await o.stringify(e)),n)try{n(e)}catch(e){}return e}catch(t){return e}}r.sign=r.sign||(async(e,t,c,u)=>{try{if(u=u||{},n===e)throw"`undefined` not allowed.";if(!(t||u).priv&&"function"!=typeof t){if(!r.I)throw"No signing key.";t=await r.I(null,{what:e,how:"sign",why:u.why})}var l=await i.parse(e),f=u.check=u.check||l;if(r.verify&&(i.check(f)||f&&f.s&&f.m)&&n!==await r.verify(f,t))return a(await i.parse(f),u,c);if("function"==typeof t){var h=await t(e);return h.authenticatorData?async function(e,t,r,i){var s={m:t,s:e.signature?o.Buffer.from(e.signature,"binary").toString(r.encode||"base64"):n,a:o.Buffer.from(e.authenticatorData,"binary").toString("base64"),c:o.Buffer.from(e.clientDataJSON,"binary").toString("base64")};if(!s.s||!s.a||!s.c)throw"WebAuthn signature invalid";return a(s,r,i)}(h,l,u,c):a({m:l,s:"string"==typeof h?h:h.signature&&o.Buffer.from(h.signature,"binary").toString(u.encode||"base64")},u,c)}return async function(e,t,n,r){var c=i.jwk(e.pub,e.priv);if(!c)throw"Invalid key pair";var u=await s(t),l=await(o.ossl||o.subtle).importKey("jwk",c,i.ecdsa.pair,!1,["sign"]).then(e=>(o.ossl||o.subtle).sign(i.ecdsa.sign,e,new Uint8Array(u))).catch(()=>{throw"SEA signature failed"});return a({m:t,s:o.Buffer.from(l,"binary").toString(n.encode||"base64")},n,r)}(t,l,u,c)}catch(e){if(r.err=e,r.throw)throw e;return void(c&&c())}}),e.exports=r.sign})(t,"./sign"),t(function(e){var n=t("./root"),r=t("./shim"),o=t("./settings"),i=t("./sha256");n.verify=n.verify||(async(e,t,s,a)=>{try{var c=await o.parse(e);if(!1===t)return s?s(await o.parse(c.m)):await o.parse(c.m);a=a||{};var u=t.pub||t,[l,f]=u.split(".");try{var h=await(r.ossl||r.subtle).importKey("jwk",{kty:"EC",crv:"P-256",x:l,y:f,ext:!0,key_ops:["verify"]},{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]),d=await i(c.m),p=new Uint8Array(r.Buffer.from(c.s||"",a.encode||"base64")),g=c.a&&c.c?await async function(e,t,n){var o=new Uint8Array(r.Buffer.from(e.a,"base64")),i=r.Buffer.from(e.c,"base64").toString("utf8"),s=(new TextEncoder).encode(e.m),a=btoa(String.fromCharCode(...new Uint8Array(s))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");if(JSON.parse(i).challenge!==a)throw"Challenge verification failed";var c=await(r.ossl||r.subtle).digest({name:"SHA-256"},(new TextEncoder).encode(i)),u=new Uint8Array(o.length+c.byteLength);if(u.set(o),u.set(new Uint8Array(c),o.length),48!==n[0])throw"Invalid DER signature format";for(var l=2,f=new Uint8Array(64),h=0;h<2;h++){var d=n[l+1];0===n[l+=2]&&(l++,d--);var p=new Uint8Array(32).fill(0);p.set(n.slice(l,l+d),32-d),f.set(p,32*h),l+=d}return(r.ossl||r.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},t,f,u)}(c,h,p):await async function(e,t,n,o){return(r.ossl||r.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},t,n,new Uint8Array(o))}(0,h,p,d);if(!g)throw"Signature did not match";var y=await o.parse(c.m);if("string"==typeof c.m&&c.m.startsWith("SEA{")){if(s)try{s(c.m)}catch(e){}return c.m}if(y&&"object"==typeof y&&"string"==typeof y.ct&&"string"==typeof y.iv&&"string"==typeof y.s){var m="SEA"+JSON.stringify(y);if(s)try{s(m)}catch(e){}return m}if(s)try{s(y)}catch(e){}return y}catch(r){return n.opt.fallback?await n.opt.fall_verify(e,t,s,a):void(s&&s())}}catch(e){if(n.err=e,n.throw)throw e;return void(s&&s())}}),e.exports=n.verify;var s={};n.opt.slow_leak=e=>{if(s[e])return s[e];var t=o.jwk(e);return s[e]=(r.ossl||r.subtle).importKey("jwk",t,{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]),s[e]},n.opt.fall_verify=async function(e,t,s,a,c){if(c===n.opt.fallback)throw"Signature did not match";var u=e||"";e=n.opt.unpack(e)||e;var l=await o.parse(e),f=await n.opt.slow_leak(t.pub||t),h=!c||c<=n.opt.fallback?r.Buffer.from(await r.subtle.digest({name:"SHA-256"},(new r.TextEncoder).encode(await o.parse(l.m)))):await i(l.m);try{var d=r.Buffer.from(l.s,a.encode||"base64"),p=new Uint8Array(d),g=await(r.ossl||r.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},f,p,new Uint8Array(h));if(!g)throw""}catch(e){try{if(d=r.Buffer.from(l.s,"utf8"),p=new Uint8Array(d),!(g=await(r.ossl||r.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},f,p,new Uint8Array(h))))throw""}catch(e){throw"Signature did not match."}}var y=g?await o.parse(l.m):void 0;if(n.opt.fall_soul=u["#"],n.opt.fall_key=u["."],n.opt.fall_val=e,n.opt.fall_state=u[">"],s)try{s(y)}catch(e){console.log(e)}return y},n.opt.fallback=2})(t,"./verify"),t(function(e){var n=t("./shim"),r=t("./settings"),o=t("./sha256");e.exports=async(e,t,i)=>{i=i||{};const s=e+(t||n.random(8)).toString("utf8"),a=n.Buffer.from(await o(s),"binary"),c=r.keyToJwk(a);return await n.subtle.importKey("jwk",c,{name:"AES-GCM"},!1,["encrypt","decrypt"])}})(t,"./aeskey"),t(function(e){var n=t("./root"),r=t("./shim"),o=(t("./settings"),t("./aeskey"));n.encrypt=n.encrypt||(async(e,t,i,s)=>{try{s=s||{};var a=(t||s).epriv||t;if(void 0===e)throw"`undefined` not allowed.";if(!a){if(!n.I)throw"No encryption key.";a=(t=await n.I(null,{what:e,how:"encrypt",why:s.why})).epriv||t}var c="string"==typeof e?e:await r.stringify(e),u={s:r.random(9),iv:r.random(15)},l=await o(a,u.s,s).then(e=>r.subtle.encrypt({name:s.name||"AES-GCM",iv:new Uint8Array(u.iv)},e,(new r.TextEncoder).encode(c))),f={ct:r.Buffer.from(l,"binary").toString(s.encode||"base64"),iv:u.iv.toString(s.encode||"base64"),s:u.s.toString(s.encode||"base64")};if(s.raw||(f="SEA"+await r.stringify(f)),i)try{i(f)}catch(e){console.log(e)}return f}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(i&&i())}}),e.exports=n.encrypt})(t,"./encrypt"),t(function(e){var n=t("./root"),r=t("./shim"),o=t("./settings"),i=t("./aeskey");n.decrypt=n.decrypt||(async(e,t,s,a)=>{try{a=a||{};var c=(t||a).epriv||t;if(!c){if(!n.I)throw"No decryption key.";c=(t=await n.I(null,{what:e,how:"decrypt",why:a.why})).epriv||t}var u,l,f,h=await o.parse(e);try{u=r.Buffer.from(h.s,a.encode||"base64"),l=r.Buffer.from(h.iv,a.encode||"base64"),f=r.Buffer.from(h.ct,a.encode||"base64");var d=await i(c,u,a).then(e=>r.subtle.decrypt({name:a.name||"AES-GCM",iv:new Uint8Array(l),tagLength:128},e,new Uint8Array(f)))}catch(r){if("utf8"===a.encode)throw"Could not decrypt";if(n.opt.fallback)return a.encode="utf8",await n.decrypt(e,t,s,a)}var p=await o.parse(new r.TextDecoder("utf8").decode(d));if(s)try{s(p)}catch(e){console.log(e)}return p}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(s&&s())}}),e.exports=n.decrypt})(t,"./decrypt"),t(function(e){var n=t("./root"),r=t("./shim");t("./settings"),n.secret=n.secret||(async(e,t,i,s)=>{try{if(s=s||{},!t||!t.epriv||!t.epub){if(!n.I)throw"No secret mix.";t=await n.I(null,{what:e,how:"secret",why:s.why})}var a=e.epub||e,c=t.epub,u=t.epriv,l=r.ossl||r.subtle,f=o(a),h=Object.assign({public:await l.importKey(...f,!0,[])},{name:"ECDH",namedCurve:"P-256"}),d=o(c,u),p=await l.importKey(...d,!1,["deriveBits"]).then(async e=>{var t=await l.deriveBits(h,e,256),n=new Uint8Array(t),r=await l.importKey("raw",n,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]);return l.exportKey("jwk",r).then(({k:e})=>e)});if(i)try{i(p)}catch(e){console.log(e)}return p}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(i&&i())}});var o=(e,t)=>{var[n,r]=e.split("."),o=t?{d:t}:{};return["jwk",Object.assign(o,{x:n,y:r,kty:"EC",crv:"P-256",ext:!0}),{name:"ECDH",namedCurve:"P-256"}]};e.exports=n.secret})(t,"./secret"),t(function(e){var n=t("./root");n.certify=n.certify||(async(e,t={},r,o,i={})=>{try{if(e=(()=>{var t=[];if(e){if(("string"==typeof e||Array.isArray(e))&&e.indexOf("*")>-1)return"*";if("string"==typeof e)return e;if(Array.isArray(e)){if(1===e.length&&e[0])return"object"==typeof e[0]&&e[0].pub?e[0].pub:"string"==typeof e[0]?e[0]:null;e.map(e=>{"string"==typeof e?t.push(e):"object"==typeof e&&e.pub&&t.push(e.pub)})}return"object"==typeof e&&e.pub?e.pub:t.length>0?t:null}})(),!e)return console.log("No certificant found.");const a=!i.expiry||"number"!=typeof i.expiry&&"string"!=typeof i.expiry?null:parseFloat(i.expiry),c=(t||{}).read?t.read:null,u=(t||{}).write?t.write:"string"==typeof t||Array.isArray(t)||t["+"]||t["#"]||t["."]||t["="]||t["*"]||t[">"]||t["<"]?t:null,l=(i||{}).block||(i||{}).blacklist||(i||{}).ban||{},f=l.read&&("string"==typeof l.read||(l.read||{})["#"])?l.read:null,h="string"==typeof l?l:l.write&&("string"==typeof l.write||l.write["#"])?l.write:null;if(!c&&!u)return console.log("No policy found.");const d=JSON.stringify({c:e,...a?{e:a}:{},...c?{r:c}:{},...u?{w:u}:{},...f?{rb:f}:{},...h?{wb:h}:{}});var s=await n.sign(d,r,null,{raw:1});if(i.raw||(s="SEA"+JSON.stringify(s)),o)try{o(s)}catch(e){console.log(e)}return s}catch(e){if(n.err=e,n.throw)throw e;return void(o&&o())}}),e.exports=n.certify})(t,"./certify"),t(function(e){var n=t("./shim"),r=t("./root");r.work=t("./work"),r.sign=t("./sign"),r.verify=t("./verify"),r.encrypt=t("./encrypt"),r.decrypt=t("./decrypt"),r.certify=t("./certify"),r.random=r.random||n.random,r.Buffer=r.Buffer||t("./buffer"),r.keyid=r.keyid||(async e=>{try{const t=n.Buffer.concat(e.replace(/-/g,"+").replace(/_/g,"/").split(".").map(e=>n.Buffer.from(e,"base64"))),r=n.Buffer.concat([n.Buffer.from([153,t.length/256,t.length%256]),t]),o=await sha1hash(r),i=n.Buffer.from(o,"binary");return i.toString("hex",i.length-8)}catch(e){throw console.log(e),e}}),((r.window||{}).GUN||{}).SEA=r,e.exports=r})(t,"./sea"),t(function(e){var n,r=t("./sea");function i(e){this._={$:this}}function s(){return n.state().toString(36).replace(".","")}n=r.window?r.window.GUN||{chain:{}}:t((void 0+""==typeof o?".":"")+"./gun",1),r.GUN=n,i.prototype=function(){function e(){}return e.prototype=n.chain,new e}(),i.prototype.constructor=i,n.chain.user=function(e){var t,n=this.back(-1);if(e)return e=r.opt.pub((e._||"")["#"])||e,n.get("~"+e);if(t=n.back("user"))return t;var o=n=n._,a=o.opt.uuid||s;return(o=(t=o.user=this.chain(new i))._).opt={},o.opt.uuid=function(e){var t=a(),r=n.user;return r&&(r=r.is)&&(r=r.pub)?(t="~"+r+"/"+t,e&&e.call&&e(null,t),t):t},t},n.User=i,i.GUN=n,i.SEA=n.SEA=r,e.exports=i})(t,"./user"),t(function(e){var n;(""+n!=typeof GUN?GUN||{chain:{}}:t((""+n==typeof o?".":"")+"./gun",1)).chain.then=function(e,t){var n=this,r=new Promise(function(e,r){n.once(e,t)});return e?r.then(e):r}})(t,"./then"),t(function(e){var n=t("./user"),r=n.SEA,o=n.GUN,i=function(){};n.prototype.create=function(...e){var t,n="object"==typeof e[0]&&(e[0].pub||e[0].epub)?e[0]:"object"==typeof e[1]&&(e[1].pub||e[1].epub)?e[1]:null,s=n&&(n.pub||n.epub)?n.pub:"string"==typeof e[0]?e[0]:null,a=n&&(n.pub||n.epub)?n:s&&"string"==typeof e[1]?e[1]:null,c=e.filter(e=>"function"==typeof e)[0]||null,u=e&&e.length>1&&"object"==typeof e[e.length-1]?e[e.length-1]:{},l=this,f=l._,h=l.back(-1);if(c=c||i,!1!==(u=u||{}).check&&(s||(t="No user."),(a||"").length<8&&(t="Password too short!"),t))return c({err:o.log(t)}),l;if(f.ing)return(c||i)({err:o.log("User is already being created or authenticated!"),wait:!0}),l;f.ing=!0;var d={a:function(e){if(d.pubs=e,e&&!u.already){var t={err:o.log("User already created!")};return f.ing=!1,(c||i)(t),void l.leave()}d.salt=String.random(64),r.work(a,d.salt,d.b)},b:function(e){d.proof=e,n?d.c(n):r.pair(d.c)},c:function(e){var t;d.pair=e||{},(t=f.root.user)&&(t._.sea=e,t.is={pub:e.pub,epub:e.epub,alias:s}),d.data={pub:e.pub},d.d()},d:function(){d.data.alias=s,d.e()},e:function(){d.data.epub=d.pair.epub,r.encrypt({priv:d.pair.priv,epriv:d.pair.epriv},d.proof,d.f,{raw:1})},f:function(e){d.data.auth=JSON.stringify({ek:e,s:d.salt}),d.g(d.data.auth)},g:function(e){var t;d.data.auth=d.data.auth||e,h.get(t="~"+d.pair.pub).put(d.data).on(d.h);var n={};n[t]={"#":t},h.get("~@"+s).put(n).get(t).on(d.i)},h:function(e,t,n,r){r.off(),d.h.ok=1,d.i()},i:function(e,t,r,o){o&&(d.i.ok=1,o.off()),d.h.ok&&d.i.ok&&(f.ing=!1,c({ok:0,pub:d.pair.pub}),i===c&&(n?l.auth(n):l.auth(s,a)))}};return h.get("~@"+s).once(d.a),l},n.prototype.leave=function(e,t){var n=this.back(-1)._.user;if(n&&(delete n.is,delete n._.is,delete n._.sea),r.window)try{var o={};delete(o=r.window.sessionStorage).recall,delete o.pair}catch(e){}return this}})(t,"./create"),t(function(e){var n=t("./user"),r=n.SEA,o=n.GUN,i=function(){};function s(e){if("string"!=typeof e)return e;try{e=JSON.parse(e)}catch(t){e={}}return e}n.prototype.auth=function(...e){var t="object"==typeof e[0]&&(e[0].pub||e[0].epub)?e[0]:"object"==typeof e[1]&&(e[1].pub||e[1].epub)?e[1]:null,n=t||"string"!=typeof e[0]?null:e[0],a=!n&&(!t||t.priv&&t.epriv)||"string"!=typeof e[1]?null:e[1],c=e.filter(e=>"function"==typeof e)[0]||null,u=e&&e.length>1&&"object"==typeof e[e.length-1]?e[e.length-1]:{},l="number"==typeof u.retries?u.retries:9,f=this,h=f._,d=f.back(-1);if(h.ing)return(c||i)({err:o.log("User is already being created or authenticated!"),wait:!0}),f;h.ing=!0;var p,g={a:function(e){if(!e)return g.b();if(!e.pub){var t=[];return Object.keys(e).forEach(function(n){"_"!=n&&t.push(e[n])}),g.b(t)}if(g.name)return g.f(e);g.c((g.data=e).auth)},b:function(e){var t=(g.list=(g.list||[]).concat(e||[])).shift();if(p===t)return g.name?g.err("Your user account is not published for dApps to access, please consider syncing it online, or allowing local access by adding your device as a peer."):n&&l--?void d.get("~@"+n).once(g.a):g.err("Wrong user or password.");d.get(t).once(g.a)},c:function(e){return p===e?g.b():"string"==typeof e?g.c(s(e)):void r.work(a,(g.auth=e).s,g.d,g.enc)},d:function(e){r.decrypt(g.auth.ek,e,g.e,g.enc)},e:function(e){if(p===e)return g.enc?(g.enc=null,g.b()):(g.enc={encode:"utf8"},g.c(g.auth));g.half=e,g.f(g.data)},f:function(e){var t=g.half||{},n=g.data||{};g.g(g.lol={pub:e.pub||n.pub,epub:e.epub||n.epub,priv:e.priv||t.priv,epriv:e.epriv||t.epriv})},g:function(e){if(!e||!e.pub||!e.epub)return g.b();g.pair=e;var t=d._.user,l=t._,y=(l.tag,l.opt);(l=t._=d.get("~"+e.pub)._).opt=y,t.is={pub:e.pub,epub:e.epub,alias:n||e.pub},l.sea=g.pair,h.ing=!1;try{a&&p==(s(h.root.graph["~"+e.pub].auth)||"")[":"]&&(u.shuffle=u.change=a)}catch(e){}if(u.change?g.z():(c||i)(l),r.window&&(f.back("user")._.opt||u).remember)try{var m={};(m=r.window.sessionStorage).recall=!0,m.pair=JSON.stringify(e)}catch(e){}try{d._.tag.auth?d._.on("auth",l):setTimeout(function(){d._.on("auth",l)},1)}catch(e){o.log("Your 'auth' callback crashed with:",e)}},h:function(e){return e?((n=e.alias)||(n=e.alias="~"+t.pub),e.auth?(t=null,void g.c((g.data=e).auth)):g.g(t)):g.b()},z:function(){g.salt=String.random(64),r.work(u.change,g.salt,g.y)},y:function(e){r.encrypt({priv:g.pair.priv,epriv:g.pair.epriv},e,g.x,{raw:1})},x:function(e){g.w(JSON.stringify({ek:e,s:g.salt}))},w:function(e){if(u.shuffle){console.log("migrate core account from UTF8 & shuffle");var t={};Object.keys(g.data).forEach(function(e){t[e]=g.data[e]}),delete t._,t.auth=e,d.get("~"+g.pair.pub).put(t)}d.get("~"+g.pair.pub).get("auth").put(e,c||i)},err:function(e){var t={err:o.log(e||"User cannot be found!")};h.ing=!1,(c||i)(t)},plugin:function(e){if(!(g.name=e))return g.err();var t=[e];"~"!==e[0]&&(t[1]="~"+e,t[2]="~@"+e),g.b(t)}};return t?t.priv&&t.epriv?g.g(t):d.get("~"+t.pub).once(g.h):n?d.get("~@"+n).once(g.a):n||a||r.name(g.plugin),f}})(t,"./auth"),t(function(e){var n=t("./user"),r=n.SEA;n.GUN,n.prototype.recall=function(e,t){var n=this,o=n.back(-1);if((e=e||{})&&e.sessionStorage){if(r.window)try{var i;(i=r.window.sessionStorage)&&(o._.opt.remember=!0,(n.back("user")._.opt||e).remember=!0,(i.recall||i.pair)&&o.user().auth(JSON.parse(i.pair),t))}catch(e){}return n}return n}})(t,"./recall"),t(function(e){var n=t("./user"),r=n.SEA,o=n.GUN,i=function(){};n.prototype.pair=function(){var e,t=this;try{e=new Proxy({DANGER:"☠"},{get:function(e,n,r){if(t.is&&(t._||"").sea)return t._.sea[n]}})}catch(e){}return e},n.prototype.delete=async function(e,t,n){console.log("user.delete() IS DEPRECATED AND WILL BE MOVED TO A MODULE!!!");var r=this,s=(r.back(-1),r.back("user"));try{s.auth(e,t,function(e){(s.is||{}).pub,s.map().once(function(){this.put(null)}),s.leave(),(n||i)({ok:0})})}catch(e){o.log("User.delete failed! Error:",e)}return r},n.prototype.alive=async function(){console.log("user.alive() IS DEPRECATED!!!");const e=this.back(-1);try{return await authRecall(e),e._.user._}catch(e){const t="No session!";throw o.log(t),{err:t}}},n.prototype.trust=async function(e){console.log("`.trust` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!"),o.is(e)&&e.get("pub").get((e,t)=>{console.log(e,t)}),e.get("trust").get(path).put(theirPubkey)},n.prototype.grant=function(e,t){console.log("`.grant` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!");var n=this,o=n.back(-1).user(),i=o._.sea,s="";return n.back(function(e){e.is||(s+=e.get||"")}),async function(){var n,a=await o.get("grant").get(i.pub).get(s).then();(a=await r.decrypt(a,i))||(a=r.random(16).toString(),n=await r.encrypt(a,i),o.get("grant").get(i.pub).get(s).put(n));var c=e.get("pub").then(),u=e.get("epub").then();c=await c,u=await u;var l=await r.secret(u,i);n=await r.encrypt(a,l),o.get("grant").get(c).get(s).put(n,t)}(),n},n.prototype.secret=function(e,t){console.log("`.secret` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!");var n=this,o=n.back(-1).user(),i=o.pair(),s="";return n.back(function(e){e.is||(s+=e.get||"")}),async function(){var a,c=await o.get("trust").get(i.pub).get(s).then();(c=await r.decrypt(c,i))||(c=r.random(16).toString(),a=await r.encrypt(c,i),o.get("trust").get(i.pub).get(s).put(a)),a=await r.encrypt(e,c),n.put(a,t)}(),n},e.exports=n})(t,"./share"),t(function(e){var n,r=t("./sea"),i=t("./settings"),s=(r.window||"").GUN||t((""+n==typeof o?".":"")+"./gun",1);function a(e){var t,n=this,o=n.as,i=e.put,c=i["#"],u=i["."],l=i[":"],f=i[">"],h=e["#"];if(c&&u)if((e._||"").faith&&(o.opt||"").faith&&"function"==typeof e._)r.opt.pack(i,function(t){r.verify(t,!1,function(t){i["="]=r.opt.unpack(t),n.to.next(e)})});else{var d=function(t){o.on("in",{"@":h,err:e.err=t})};(e._||"").DBG&&((e._||"").DBG.c=+new Date),0<=c.indexOf("<?")&&(t=parseFloat(c.split("<?")[1]||""))&&f<s.state()-1e3*t?(t=e._)&&t.stun&&t.stun--:"~@"!==c?"~@"!==c.slice(0,2)?(t=r.opt.pub(c))?a.pub(n,e,l,u,c,o,d,o.user||"",t):0<=c.indexOf("#")?a.hash(n,e,l,u,c,o,d):a.any(n,e,l,u,c,o,d,o.user||""):a.pubs(n,e,l,u,c,o,d):a.alias(n,e,l,u,c,o,d)}}s.on("opt",function(e){e.sea||(e.sea={own:{}},e.on("put",a,e)),this.to.next(e)}),a.hash=function(e,t,n,o,i,s,a){var c=o.split("#").pop();r.work(n,null,function(n){var r=function(e){for(var t=atob(e),n=[],r=0;r<t.length;r++){var o=t.charCodeAt(r).toString(16);n.push(1===o.length?"0"+o:o)}return n.join("")}(n),o=n.slice(-20),i=r.slice(-20);if([n,o,r,i].some(e=>e.endsWith(c)))return e.to.next(t);a("Data hash not same as hash!")},{name:"SHA-256"})},a.alias=function(e,t,n,r,o,i,s){return n?"~@"+r===u(n)?e.to.next(t):void s("Alias not same!"):s("Data must exist!")},a.pubs=function(e,t,n,r,o,i,s){return n?r===u(n)?e.to.next(t):void s("Alias not same!"):s("Alias must exist!")},a.pub=async function(e,t,o,a,c,l,f,h,d){var p;const g=(o,i,u)=>{if(o.m&&o.s&&i&&d)return r.verify(o,d,r=>{if(n!==r&&n!==r.e&&t.put[">"]&&t.put[">"]>parseFloat(r.e))return f("Certificate expired.");if(n!==r&&r.c&&r.w&&(r.c===i||r.c.indexOf("*")>-1||r.c.indexOf(i)>-1)){let t=c.indexOf("/")>-1?c.replace(c.substring(0,c.indexOf("/")+1),""):"";String.match=String.match||s.text.match;const n=Array.isArray(r.w)?r.w:"object"==typeof r.w||"string"==typeof r.w?[r.w]:[];for(const s of n)if(String.match(t,s["#"])&&String.match(a,s["."])||!s["."]&&String.match(t,s["#"])||!s["#"]&&String.match(a,s["."])||String.match(t?t+"/"+a:a,s["#"]||s)){if(s["+"]&&s["+"].indexOf("*")>-1&&t&&-1==t.indexOf(i)&&-1==a.indexOf(i))return f(`Path "${t}" or key "${a}" must contain string "${i}".`);if(r.wb&&("string"==typeof r.wb||(r.wb||{})["#"])){var o=e.as.root.$.back(-1);return"string"==typeof r.wb&&"~"!==r.wb.slice(0,1)&&(o=o.get("~"+d)),o.get(r.wb).get(i).once(e=>!e||1!==e&&!0!==e?u(r):f(`Certificant ${i} blocked.`))}return u(r)}return f("Certificate verification fail.")}})},y=()=>{JSON.stringifyAsync(t.put[":"],function(n,r){return n?f(n||"Stringify error."):(t.put[":"]=r,e.to.next(t))})},m=(t._.msg||{}).opt||{},w=m.authenticator||(h._||{}).sea,b=m.authenticator?m.pub||(h.is||{}).pub||d:(h.is||{}).pub,v=m.cert;delete m.authenticator,delete m.pub;const E=await i.parse(o)||{};if("pub"===a&&"~"+d===c)return o===d?e.to.next(t):f("Account not same!");!h.is&&!w||!b||E["*"]||E["+"]||!(d===b||d!==b&&v)?r.opt.pack(t.put,o=>{r.verify(o,E["*"]||d,function(o){var i;return o=r.opt.unpack(o),n===o?f("Unverified data."):((i=u(o))&&d===r.opt.pub(i)&&((l.sea.own[i]=l.sea.own[i]||{})[d]=1),E["+"]&&E["+"].m&&E["+"].s&&E["*"]?void g(E["+"],E["*"],n=>(t.put["="]=o,e.to.next(t))):(t.put["="]=o,e.to.next(t)))})}):r.opt.pack(t.put,e=>{if(!w)return f("Missing authenticator");r.sign(e,w,async function(e){if(n===e)return f(r.err||"Signature fail.");if(!e.m||!e.s)return f("Invalid signature format");if(t.put[":"]={":":p=r.opt.unpack(e.m),"~":e.s},t.put["="]=p,d===b)return(p=u(o))&&((l.sea.own[p]=l.sea.own[p]||{})[d]=1),void y();if(d!==b&&v){const e=await i.parse(v);e&&e.m&&e.s&&g(e,b,n=>{t.put[":"]["+"]=e,t.put[":"]["*"]=b,y()})}},{raw:1})})},a.any=function(e,t,n,r,o,i,s,a){if(i.opt.secure)return s("Soul missing public key at '"+r+"'.");i.on("secure",function(t){if(this.off(),!i.opt.secure)return e.to.next(t);s("Data cannot be changed.")}).on.on("secure",t)};var c=s.valid,u=function(e,t){return"string"==typeof(t=c(e))&&t},l=((s.state||"").ify,/[^\w_-]/);r.opt.pub=function(e){if(e&&(e=e.split("~"))&&(e=e[1])&&(e=e.split(l).slice(0,2))&&2==e.length&&"@"!==(e[0]||"")[0])return e.slice(0,2).join(".")},r.opt.stringy=function(e){},r.opt.pack=function(e,t,o,i,a){var c,u;if(r.opt.check(e))return t(e);e&&e["#"]&&e["."]&&e[">"]&&(c=e[":"],u=1),JSON.parseAsync(u?c:e,function(r,c){var u=n!==(c||"")[":"]&&(c||"")["~"];t(u?{m:{"#":a||e["#"],".":o||e["."],":":(c||"")[":"],">":e[">"]||s.state.is(i,o)},s:u}:e)})};var f=r.opt;r.opt.unpack=function(e,t,o){var i;if(n!==e){if(e&&n!==(i=e[":"]))return i;if(t=t||f.fall_key,!o&&f.fall_val&&((o={})[t]=f.fall_val),t&&o){if(e===o[t])return e;if(!r.opt.check(o[t]))return e;var a=o&&o._&&o._["#"]||f.fall_soul,c=s.state.is(o,t)||f.fall_state;return e&&4===e.length&&a===e[0]&&t===e[1]&&h(c)===h(e[3])?e[2]:c<r.opt.shuffle_attack?e:void 0}}},r.opt.shuffle_attack=15463296e5;var h=Math.floor})(t,"./index")}()},132(e){function t(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=132,e.exports=t},72(e){var t=[];function n(e){for(var n=-1,r=0;r<t.length;r++)if(t[r].identifier===e){n=r;break}return n}function r(e,r){for(var i={},s=[],a=0;a<e.length;a++){var c=e[a],u=r.base?c[0]+r.base:c[0],l=i[u]||0,f="".concat(u," ").concat(l);i[u]=l+1;var h=n(f),d={css:c[1],media:c[2],sourceMap:c[3],supports:c[4],layer:c[5]};if(-1!==h)t[h].references++,t[h].updater(d);else{var p=o(d,r);r.byIndex=a,t.splice(a,0,{identifier:f,updater:p,references:1})}s.push(f)}return s}function o(e,t){var n=t.domAPI(t);return n.update(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap&&t.supports===e.supports&&t.layer===e.layer)return;n.update(e=t)}else n.remove()}}e.exports=function(e,o){var i=r(e=e||[],o=o||{});return function(e){e=e||[];for(var s=0;s<i.length;s++){var a=n(i[s]);t[a].references--}for(var c=r(e,o),u=0;u<i.length;u++){var l=n(i[u]);0===t[l].references&&(t[l].updater(),t.splice(l,1))}i=c}}},659(e){var t={};e.exports=function(e,n){var r=function(e){if(void 0===t[e]){var n=document.querySelector(e);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}t[e]=n}return t[e]}(e);if(!r)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");r.appendChild(n)}},540(e){e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},56(e,t,n){e.exports=function(e){var t=n.nc;t&&e.setAttribute("nonce",t)}},825(e){e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=e.insertStyleElement(e);return{update:function(n){!function(e,t,n){var r="";n.supports&&(r+="@supports (".concat(n.supports,") {")),n.media&&(r+="@media ".concat(n.media," {"));var o=void 0!==n.layer;o&&(r+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),r+=n.css,o&&(r+="}"),n.media&&(r+="}"),n.supports&&(r+="}");var i=n.sourceMap;i&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),t.styleTagTransform(r,e,t.options)}(t,e,n)},remove:function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(t)}}}},113(e){e.exports=function(e,t){if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}},442(t){t.exports=e},809(e,t,n){n.r(t),n.d(t,{decFrom:()=>y,decrypt:()=>p,encFor:()=>g,encrypt:()=>d,generatePairFromMnemonic:()=>I,generatePairFromSeed:()=>S,getShortHash:()=>v,hashObj:()=>w,hashText:()=>m,isHash:()=>h,randomUUID:()=>k,safeHash:()=>E,safeJSONParse:()=>x,secret:()=>b,unsafeHash:()=>A});const r={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let o;const i=new Uint8Array(16),s=[];for(let e=0;e<256;++e)s.push((e+256).toString(16).slice(1));const a=function(e,t,n){if(r.randomUUID&&!t&&!e)return r.randomUUID();const a=(e=e||{}).random??e.rng?.()??function(){if(!o){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");o=crypto.getRandomValues.bind(crypto)}return o(i)}();if(a.length<16)throw new Error("Random bytes length must be >= 16");if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t){if((n=n||0)<0||n+16>t.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=a[e];return t}return function(e,t=0){return(s[e[t+0]]+s[e[t+1]]+s[e[t+2]]+s[e[t+3]]+"-"+s[e[t+4]]+s[e[t+5]]+"-"+s[e[t+6]]+s[e[t+7]]+"-"+s[e[t+8]]+s[e[t+9]]+"-"+s[e[t+10]]+s[e[t+11]]+s[e[t+12]]+s[e[t+13]]+s[e[t+14]]+s[e[t+15]]).toLowerCase()}(a)};var c=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},u=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},l=null;function f(){return l||(n.g.SEA?l=n.g.SEA:globalThis.Gun&&globalThis.Gun.SEA?l=globalThis.Gun.SEA:"undefined"!=typeof window&&window.Gun&&window.Gun.SEA?l=window.Gun.SEA:n.g.Gun&&n.g.Gun.SEA?l=n.g.Gun.SEA:globalThis.SEA?l=globalThis.SEA:"undefined"!=typeof window&&window.SEA?l=window.SEA:null)}function h(e){return!("string"!=typeof e||0===e.length||(44!==e.length||!e.endsWith("="))&&!e.includes("-"))}function d(e,t){return c(this,void 0,void 0,function(){var n,r,o,i;return u(this,function(s){switch(s.label){case 0:if(!(n=f())||!n.encrypt)throw new Error("SEA not available");s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n.encrypt(e,t)];case 2:if("SEA not available"===(r=s.sent()))throw new Error("SEA not available");return[2,r];case 3:throw o=s.sent(),i=o instanceof Error?o:new Error(String(o)),new Error("SEA encryption failed: ".concat(i.message));case 4:return[2]}})})}function p(e,t){return c(this,void 0,void 0,function(){var n,r,o,i;return u(this,function(s){switch(s.label){case 0:if(!(n=f())||!n.decrypt)throw new Error("SEA not available");s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n.decrypt(e,t)];case 2:if("SEA not available"===(r=s.sent()))throw new Error("SEA not available");return[2,r];case 3:throw o=s.sent(),i=o instanceof Error?o:new Error(String(o)),new Error("SEA decryption failed: ".concat(i.message));case 4:return[2]}})})}function g(e,t,n){return c(this,void 0,void 0,function(){var r,o;return u(this,function(i){switch(i.label){case 0:if(!(r=f())||!r.secret||!r.encrypt)return[2,"encrypted-data"];i.label=1;case 1:return i.trys.push([1,4,,5]),[4,r.secret(n.epub,t)];case 2:return o=i.sent(),[4,r.encrypt(e,o)];case 3:return[2,i.sent()];case 4:return i.sent(),[2,"encrypted-data"];case 5:return[2]}})})}function y(e,t,n){return c(this,void 0,void 0,function(){var r,o;return u(this,function(i){switch(i.label){case 0:if(!(r=f())||!r.secret||!r.decrypt)return[2,"decrypted-data"];i.label=1;case 1:return i.trys.push([1,4,,5]),[4,r.secret(t.epub,n)];case 2:return o=i.sent(),[4,r.decrypt(e,o)];case 3:return[2,i.sent()];case 4:return i.sent(),[2,"decrypted-data"];case 5:return[2]}})})}function m(e){return c(this,void 0,void 0,function(){var t,n;return u(this,function(r){switch(r.label){case 0:if(!(t=f())||!t.work)throw new Error("SEA not available");r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.work(e,null,null,{name:"SHA-256"})];case 2:if("SEA not available"===(n=r.sent()))throw new Error("SEA not available");return[2,n];case 3:throw r.sent(),new Error("SEA not available");case 4:return[2]}})})}function w(e){return c(this,void 0,void 0,function(){var t;return u(this,function(n){switch(n.label){case 0:return[4,m(t="string"==typeof e?e:JSON.stringify(e))];case 1:return[2,{hash:n.sent(),hashed:t}]}})})}function b(e,t){return c(this,void 0,void 0,function(){return u(this,function(n){switch(n.label){case 0:return[4,f().secret(e,t)];case 1:return[2,n.sent()]}})})}function v(e,t){return c(this,void 0,void 0,function(){return u(this,function(n){switch(n.label){case 0:return[4,f().work(e,null,null,{name:"PBKDF2",encode:"hex",salt:void 0!==t?t:""})];case 1:return[2,(n.sent()||"").substring(0,8)]}})})}function E(e){return null==e?e:""===e?"":e.replace(/-/g,"_").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,".")}function A(e){if(null==e)return e;if(""===e)return"";var t=e;return(t=t.replace(/_/g,"-").replace(/\./g,"=")).replace(/-/g,"+")}function x(e,t){if(void 0===t&&(t={}),void 0!==e){if(null===e)return null;if(""===e)return"";if("object"==typeof e)return e;try{return JSON.parse(e)}catch(e){return t}}}function k(){var e=null===globalThis||void 0===globalThis?void 0:globalThis.crypto;if(null==e?void 0:e.randomUUID)return e.randomUUID();try{if(null==e?void 0:e.getRandomValues){var t=new Uint8Array(16);e.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128;var n=Array.from(t).map(function(e){return e.toString(16).padStart(2,"0")}).join("");return"".concat(n.slice(0,8),"-").concat(n.slice(8,12),"-").concat(n.slice(12,16),"-").concat(n.slice(16,20),"-").concat(n.slice(20))}}catch(e){}return a()}function S(e){return c(this,void 0,void 0,function(){var t,n,r;return u(this,function(o){switch(o.label){case 0:if(!(t=f())||!t.pair)throw new Error("SEA not available");o.label=1;case 1:return o.trys.push([1,3,,4]),[4,t.pair(null,{seed:e})];case 2:return(r=o.sent())&&r.pub&&r.priv?[2,r]:[3,4];case 3:return o.sent(),[3,4];case 4:return[4,t.work(e,"shogun-seed-salt",null,{name:"SHA-256"})];case 5:n=o.sent(),o.label=6;case 6:return o.trys.push([6,8,,9]),[4,t.pair(null,{seed:n})];case 7:return(r=o.sent())&&r.pub&&r.priv?[2,r]:[3,9];case 8:return o.sent(),[3,9];case 9:throw new Error("Deterministic key generation not supported by this Gun version")}})})}function I(e,t){return c(this,void 0,void 0,function(){return u(this,function(n){if(!e||e.split(" ").length<12)throw new Error("Invalid mnemonic: must be at least 12 words");return[2,S("".concat(e.trim(),":").concat(t.trim()))]})})}}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={id:e,loaded:!1,exports:{}};return t[e](i,i.exports,r),i.loaded=!0,i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),r.nc=void 0;var o={};r.r(o),r.d(o,{ShogunButton:()=>be,ShogunButtonProvider:()=>ae,shogunConnector:()=>DP,useShogun:()=>se});var i={};r.r(i),r.d(i,{OG:()=>rd,My:()=>qh,Ph:()=>Zh,lX:()=>Yh,Id:()=>nd,fg:()=>sd,qj:()=>td,aT:()=>Qh,lq:()=>Xh,z:()=>ed,Q5:()=>cd});var s=r(442),a=r.n(s),c=function(e,t){return c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},c(e,t)};function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}c(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function l(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function f(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function h(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function d(e){return"function"==typeof e}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var p,g,y=(p=function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map(function(e,t){return t+1+") "+e.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}},(g=p(function(e){Error.call(e),e.stack=(new Error).stack})).prototype=Object.create(Error.prototype),g.prototype.constructor=g,g);function m(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var w=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=l(i),a=s.next();!a.done;a=s.next())a.value.remove(this)}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var c=this.initialTeardown;if(d(c))try{c()}catch(e){o=e instanceof y?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var p=l(u),g=p.next();!g.done;g=p.next()){var m=g.value;try{v(m)}catch(e){o=null!=o?o:[],e instanceof y?o=h(h([],f(o)),f(e.errors)):o.push(e)}}}catch(e){n={error:e}}finally{try{g&&!g.done&&(r=p.return)&&r.call(p)}finally{if(n)throw n.error}}}if(o)throw new y(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)v(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&m(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&m(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();function b(e){return e instanceof w||e&&"closed"in e&&d(e.remove)&&d(e.add)&&d(e.unsubscribe)}function v(e){d(e)?e():e.unsubscribe()}w.EMPTY;var E=null,A=null,x=void 0,k=!1,S=!1,I={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=I.delegate;return(null==o?void 0:o.setTimeout)?o.setTimeout.apply(o,h([e,t],f(n))):setTimeout.apply(void 0,h([e,t],f(n)))},clearTimeout:function(e){var t=I.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function P(){}var C=O("C",void 0,void 0);function O(e,t,n){return{kind:e,value:t,error:n}}var N=null,B=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,b(t)&&t.add(n)):n.destination=_,n}return u(t,e),t.create=function(e,t,n){return new D(e,t,n)},t.prototype.next=function(e){this.isStopped?F(function(e){return O("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?F(O("E",void 0,e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?F(C,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(w),T=Function.prototype.bind;function R(e,t){return T.call(e,t)}var U=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){L(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){L(e)}else L(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){L(e)}},e}(),D=function(e){function t(t,n,r){var o,i,s=e.call(this)||this;return d(t)||!t?o={next:null!=t?t:void 0,error:null!=n?n:void 0,complete:null!=r?r:void 0}:s&&S?((i=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},o={next:t.next&&R(t.next,i),error:t.error&&R(t.error,i),complete:t.complete&&R(t.complete,i)}):o=t,s.destination=new U(o),s}return u(t,e),t}(B);function L(e){var t;k?(t=e,k&&N&&(N.errorThrown=!0,N.error=t)):function(e){I.setTimeout(function(){if(!E)throw e;E(e)})}(e)}function F(e,t){var n=A;n&&I.setTimeout(function(){return n(e,t)})}var _={closed:!0,next:P,error:function(e){throw e},complete:P},M="function"==typeof Symbol&&Symbol.observable||"@@observable";function j(e){return e}var G=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof B||function(e){return e&&d(e.next)&&d(e.error)&&d(e.complete)}(r)&&b(r)?e:new D(e,t,n);return function(e){if(k){var t=!N;if(t&&(N={errorThrown:!1,error:null}),e(),t){var n=N,r=n.errorThrown,o=n.error;if(N=null,r)throw o}}else e()}(function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))}),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=H(t))(function(t,r){var o=new D({next:function(t){try{e(t)}catch(e){r(e),o.unsubscribe()}},error:r,complete:t});n.subscribe(o)})},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[M]=function(){return this},e.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return(0===(n=e).length?j:1===n.length?n[0]:function(e){return n.reduce(function(e,t){return t(e)},e)})(this);var n},e.prototype.toPromise=function(e){var t=this;return new(e=H(e))(function(e,n){var r;t.subscribe(function(e){return r=e},function(e){return n(e)},function(){return e(r)})})},e.create=function(t){return new e(t)},e}();function H(e){var t;return null!==(t=null!=e?e:x)&&void 0!==t?t:Promise}var z=r(72),K=r.n(z),V=r(825),W=r.n(V),$=r(659),q=r.n($),J=r(56),Q=r.n(J),Z=r(540),Y=r.n(Z),X=r(113),ee=r.n(X),te=r(208),ne={};function re(e){return e&&"function"==typeof e.isLoggedIn&&void 0!==e.gun}ne.styleTagTransform=ee(),ne.setAttributes=Q(),ne.insert=q().bind(null,"head"),ne.domAPI=W(),ne.insertStyleElement=Y(),K()(te.A,ne),te.A&&te.A.locals&&te.A.locals;const oe={core:null,options:{},isLoggedIn:!1,userPub:null,username:null,login:async()=>({}),signUp:async()=>({}),logout:()=>{},observe:()=>new G,setProvider:()=>!1,hasPlugin:()=>!1,getPlugin:()=>{},exportGunPair:async()=>"",importGunPair:async()=>!1,gunPlugin:null,put:async()=>{},get:()=>null,remove:async()=>{},completePendingSignup:()=>{},hasPendingSignup:!1,setHasPendingSignup:e=>{}},ie=(0,s.createContext)(oe),se=()=>(0,s.useContext)(ie);function ae({children:e,core:t,options:n,onLoginSuccess:r,onSignupSuccess:o,onError:i}){const[c,u]=(0,s.useState)(!1),[l,f]=(0,s.useState)(null),[h,d]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1);(0,s.useEffect)(()=>{var e,n;if(!t)return;let r=!1,o=null;re(t)&&(r=t.isLoggedIn(),r&&(o=null===(n=null===(e=t.gun.user())||void 0===e?void 0:e.is)||void 0===n?void 0:n.pub)),r&&o&&(u(!0),f(o),d(o.slice(0,8)+"..."))},[t]);const y=a().useCallback(e=>{var n;if(!t)return new G;const r=(null==t?void 0:t.rx)||(null===(n=null==t?void 0:t.db)||void 0===n?void 0:n.rx);return r&&"function"==typeof r.observe?r.observe(e):new G},[t]),m=a().useCallback(async(e,...n)=>{var o,s;try{if(!t)throw new Error("SDK not initialized");let a,c,l=e;switch(e){case"password":if(c=n[0],console.log(`[DEBUG] ShogunButton: Calling core.login for username: ${c}`),!re(t))throw new Error("Unsupported core type");a=await t.login(n[0],n[1]),console.log("[DEBUG] ShogunButton: core.login result:",a);break;case"pair":const e=n[0];if(!e||"object"!=typeof e)throw new Error("Invalid pair data provided");if(!re(t))throw new Error("Pair authentication requires ShogunCore");a=await new Promise((n,r)=>{t.gun.user().auth(e,t=>{if(t.err)return void r(new Error(`Pair authentication failed: ${t.err}`));const o=t.pub||e.pub,i=t.alias||`user_${null==o?void 0:o.substring(0,8)}`;n({success:!0,userPub:o,alias:i,method:"pair"})})}),c=a.alias,l="pair";break;case"webauthn":if(c=n[0],!re(t))throw new Error("WebAuthn requires ShogunCore");{const e=t.getPlugin("webauthn");if(!e)throw new Error("WebAuthn plugin not available");a=await e.login(c)}break;case"web3":if(!re(t))throw new Error("Web3 requires ShogunCore");{const e=t.getPlugin("web3");if(!e)throw new Error("Web3 plugin not available");const n=await e.connectMetaMask();if(!n.success||!n.address)throw new Error(n.error||"Failed to connect wallet.");c=n.address,a=await e.login(n.address)}break;case"nostr":if(!re(t))throw new Error("Nostr requires ShogunCore");{const e=t.getPlugin("nostr");if(!e)throw new Error("Nostr plugin not available");const n=await e.connectBitcoinWallet();if(!n||!n.success)throw new Error((null==n?void 0:n.error)||"Connessione al wallet Bitcoin fallita");const r=n.address;if(!r)throw new Error("Nessuna chiave pubblica ottenuta");c=r,a=await e.login(r)}break;case"challenge":if(c=n[0],!c)throw new Error("Username required for challenge login");if(!re(t))throw new Error("Challenge auth requires ShogunCore");{const e=t.getPlugin("challenge");if(!e)throw new Error("Challenge plugin not available");a=await e.login(c),l="challenge"}break;case"seed":c=n[0];const r=n[1];if(!c||!r)throw new Error("Username and seed phrase are required");if(!re(t))throw new Error("Seed authentication requires ShogunCore");a=await t.loginWithSeed(c,r),l="seed";break;default:throw new Error("Unsupported login method")}if(a.success){let e=a.userPub||"";!e&&re(t)&&(e=(null===(s=null===(o=t.gun.user())||void 0===o?void 0:o.is)||void 0===s?void 0:s.pub)||"");const n=a.alias||c||e.slice(0,8)+"...";u(!0),f(e),d(n),null==r||r({userPub:e,username:n,authMethod:l})}else null==i||i(a.error||"Login failed");return a}catch(e){return null==i||i(e.message||"Error during login"),{success:!1,error:e.message}}},[t,r,i]),w=a().useCallback(async(e,...n)=>{var r,s,a;try{if(!t)throw new Error("SDK not initialized");let c,l,h=e;switch(e){case"password":if(l=n[0],n[1]!==n[2])throw new Error("Passwords do not match");console.log(`[DEBUG] ShogunButton: Calling core.signUp for username: ${l}`),console.log("[DEBUG] ShogunButton: core object:",t);try{if(console.log("[DEBUG] ShogunButton: About to call core.signUp..."),!re(t))throw new Error("Unsupported core type");c=await t.signUp(n[0],n[1]),console.log("[DEBUG] ShogunButton: core.signUp completed successfully"),console.log("[DEBUG] ShogunButton: core.signUp result:",c)}catch(e){throw console.error("[DEBUG] ShogunButton: core.signUp error:",e),e}break;case"webauthn":{l="string"==typeof n[0]?n[0].trim():"";const e=n.length>1&&"object"==typeof n[1]&&null!==n[1]?n[1]:{};if(!l)throw new Error("Username is required for WebAuthn registration");if(!re(t))throw new Error("WebAuthn requires ShogunCore");{const n=t.getPlugin("webauthn");if(!n)throw new Error("WebAuthn plugin not available");const o={};e.seedPhrase?(o.seedPhrase=e.seedPhrase.trim(),o.generateSeedPhrase=null!==(r=e.generateSeedPhrase)&&void 0!==r&&r):"boolean"==typeof e.generateSeedPhrase&&(o.generateSeedPhrase=e.generateSeedPhrase),void 0!==o.generateSeedPhrase||o.seedPhrase||(o.generateSeedPhrase=!0),c=await n.signUp(l,o)}break}case"web3":if(!re(t))throw new Error("Web3 requires ShogunCore");{const e=t.getPlugin("web3");if(!e)throw new Error("Web3 plugin not available");const n=await e.connectMetaMask();if(!n.success||!n.address)throw new Error(n.error||"Failed to connect wallet.");l=n.address,c=await e.signUp(n.address)}break;case"nostr":if(!re(t))throw new Error("Nostr requires ShogunCore");{const e=t.getPlugin("nostr");if(!e)throw new Error("Nostr plugin not available");const n=await e.connectBitcoinWallet();if(!n||!n.success)throw new Error((null==n?void 0:n.error)||"Connessione al wallet Bitcoin fallita");const r=n.address;if(!r)throw new Error("Nessuna chiave pubblica ottenuta");l=r,c=await e.signUp(r)}break;default:throw new Error("Unsupported signup method")}if(c.success){let e=c.userPub||"";!e&&re(t)&&(e=(null===(a=null===(s=t.gun.user())||void 0===s?void 0:s.is)||void 0===a?void 0:a.pub)||"");const n=c.alias||l||e.slice(0,8)+"...";u(!0),f(e),d(n);const r={userPub:e,username:n,seedPhrase:c.seedPhrase,authMethod:h},i=Boolean(c.seedPhrase||c.trapdoor);g(i),null==o||o(r)}else null==i||i(c.error);return c}catch(e){return null==i||i(e.message||"Error during registration"),{success:!1,error:e.message}}},[t,o,i]),b=a().useCallback(()=>{re(t)&&t.logout(),u(!1),f(null),d(null)},[t]),v=a().useCallback(e=>{var n;if(!t)return!1;try{let r=null;if(e&&e.connection&&e.connection.url?r=e.connection.url:"string"==typeof e&&(r=e),r){const e=(null===(n=null==t?void 0:t.db)||void 0===n?void 0:n.gun)||(null==t?void 0:t.gun);if(e&&"function"==typeof e.opt)try{return e.opt({peers:[r]}),!0}catch(e){return console.error("Error adding peer via gun.opt:",e),!1}}return!1}catch(e){return console.error("Error setting provider:",e),!1}},[t]),E=a().useCallback(e=>!!re(t)&&t.hasPlugin(e),[t]),A=a().useCallback(e=>{if(re(t))return t.getPlugin(e)},[t]),x=a().useCallback(async e=>{if(!t)throw new Error("SDK not initialized");if(!c)throw new Error("User not authenticated");try{const t=sessionStorage.getItem("gun/pair")||sessionStorage.getItem("pair");if(!t)throw new Error("No Gun pair available for current user");let n=JSON.stringify(t);return e&&e.trim()&&(window.SEA&&window.SEA.encrypt?n=await window.SEA.encrypt(n,e):console.warn("SEA encryption not available, exporting unencrypted")),n}catch(e){throw new Error(`Failed to export Gun pair: ${e.message}`)}},[t,c]),k=a().useCallback(async(e,n)=>{if(!t)throw new Error("SDK not initialized");try{let t=e;if(n&&n.trim())if(window.SEA&&window.SEA.decrypt){if(t=await window.SEA.decrypt(e,n),!t)throw new Error("Failed to decrypt pair data - wrong password?")}else console.warn("SEA decryption not available, assuming unencrypted data");const r=JSON.parse(t);if(!(r.pub&&r.priv&&r.epub&&r.epriv))throw new Error("Invalid pair structure - missing required keys");return(await m("pair",r)).success}catch(e){throw new Error(`Failed to import Gun pair: ${e.message}`)}},[t,m]),S=a().useCallback(()=>{g(!1)},[g]),I=a().useMemo(()=>({core:t,options:n,isLoggedIn:c,userPub:l,username:h,login:m,signUp:w,logout:b,observe:y,hasPlugin:E,getPlugin:A,exportGunPair:x,importGunPair:k,setProvider:v,gunPlugin:null,completePendingSignup:S,hasPendingSignup:p,setHasPendingSignup:g,put:async(e,n)=>{if(re(t)){if(!t.gun)throw new Error("Gun instance not available");return new Promise((r,o)=>{t.gun.get(e).put(n,e=>{e.err?o(new Error(e.err)):r()})})}throw new Error("Core not available")},get:e=>re(t)&&t.gun?t.gun.get(e):null,remove:async e=>{if(re(t)){if(!t.gun)throw new Error("Gun instance not available");return new Promise((n,r)=>{t.gun.get(e).put(null,e=>{e.err?r(new Error(e.err)):n()})})}throw new Error("Core not available")}}),[t,n,c,l,h,m,w,b,y,E,A,x,k,null,S,p,g]);return a().createElement(ie.Provider,{value:I},e)}const ce=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M21 12V7H5a2 2 0 0 1 0-4h14v4"}),a().createElement("path",{d:"M3 5v14a2 2 0 0 0 2 2h16v-5"}),a().createElement("path",{d:"M18 12a2 2 0 0 0 0 4h4v-4Z"})),ue=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("circle",{cx:"7.5",cy:"15.5",r:"5.5"}),a().createElement("path",{d:"m21 2-9.6 9.6"}),a().createElement("path",{d:"m15.5 7.5 3 3L22 7l-3-3"})),le=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M19.5 4.5 15 9l-3-3-4.5 4.5L9 12l-1.5 1.5L12 18l4.5-4.5L15 12l1.5-1.5L21 6l-1.5-1.5Z"}),a().createElement("path",{d:"M12 12 6 6l-1.5 1.5L9 12l-4.5 4.5L6 18l6-6Z"})),fe=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M7 11v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1h-4"}),a().createElement("path",{d:"M14 4V2a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h2"})),he=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),a().createElement("polyline",{points:"16 17 21 12 16 7"}),a().createElement("line",{x1:"21",y1:"12",x2:"9",y2:"12"})),de=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),a().createElement("circle",{cx:"12",cy:"7",r:"4"})),pe=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),a().createElement("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})),ge=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),a().createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"})),ye=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),a().createElement("polyline",{points:"14,2 14,8 20,8"}),a().createElement("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),a().createElement("line",{x1:"12",y1:"17",x2:"12",y2:"9"})),me=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})),we=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),a().createElement("polyline",{points:"14,2 14,8 20,8"}),a().createElement("line",{x1:"12",y1:"11",x2:"12",y2:"21"}),a().createElement("polyline",{points:"16,15 12,11 8,15"})),be=(()=>{const e=()=>{const{isLoggedIn:e,username:t,logout:n,login:r,signUp:o,core:i,options:c,exportGunPair:u,importGunPair:l,hasPlugin:f,hasPendingSignup:h,setHasPendingSignup:d}=se(),[p,g]=(0,s.useState)(!1),[y,m]=(0,s.useState)(""),[w,b]=(0,s.useState)(""),[v,E]=(0,s.useState)(""),[A,x]=(0,s.useState)("login"),[k,S]=(0,s.useState)("options"),[I,P]=(0,s.useState)(""),[C,O]=(0,s.useState)(!1),[N,B]=(0,s.useState)(!1),[T,R]=(0,s.useState)(""),[U,D]=(0,s.useState)(""),[L,F]=(0,s.useState)(""),[_,M]=(0,s.useState)(""),[j,G]=(0,s.useState)(!1),[H,z]=(0,s.useState)(!1),[K,V]=(0,s.useState)(""),[W,$]=(0,s.useState)(""),[q,J]=(0,s.useState)(""),Q=(0,s.useRef)(null);if((0,s.useEffect)(()=>{const e=e=>{Q.current&&!Q.current.contains(e.target)&&B(!1)};if(N)return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[N]),(0,s.useEffect)(()=>{h&&(g(!0),"webauthn-signup-result"!==k&&K&&S("webauthn-signup-result"))},[h,k,K]),e&&t&&!p)return a().createElement("div",{className:"shogun-logged-in-container"},a().createElement("div",{className:"shogun-dropdown",ref:Q},a().createElement("button",{className:"shogun-button shogun-logged-in",onClick:()=>B(!N)},a().createElement("div",{className:"shogun-avatar"},t.substring(0,2).toUpperCase()),a().createElement("span",{className:"shogun-username"},t.length>12?`${t.substring(0,6)}...${t.substring(t.length-4)}`:t)),N&&a().createElement("div",{className:"shogun-dropdown-menu"},a().createElement("div",{className:"shogun-dropdown-header"},a().createElement("div",{className:"shogun-avatar-large"},t.substring(0,2).toUpperCase()),a().createElement("div",{className:"shogun-user-info"},a().createElement("span",{className:"shogun-username-full"},t.length>20?`${t.substring(0,10)}...${t.substring(t.length-6)}`:t))),a().createElement("div",{className:"shogun-dropdown-item",onClick:()=>{B(!1),S("export"),g(!0)}},a().createElement(we,null),a().createElement("span",null,"Export Pair")),a().createElement("div",{className:"shogun-dropdown-item",onClick:n},a().createElement(he,null),a().createElement("span",null,"Disconnect")))));const Z=async(e,...t)=>{console.log(`[DEBUG] handleAuth called with method: ${e}, formMode: ${A}, args:`,t),P(""),O(!0);try{const n="login"===A?r:o;console.log(`[DEBUG] handleAuth calling action: ${n.name}, method: ${e}`);const i=await n(e,...t);console.log("[DEBUG] handleAuth result:",i),i&&!i.success&&i.error?P(i.error):i&&i.redirectUrl?window.location.href=i.redirectUrl:"signup"===A&&"webauthn"===e&&i&&i.success&&i.seedPhrase?(V(i.seedPhrase),G(!1),S("webauthn-signup-result")):g(!1)}catch(e){P(e.message||"An unexpected error occurred.")}finally{O(!1)}},Y=()=>{m(""),b(""),E(""),P(""),O(!1),S("options"),R(""),D(""),F(""),M(""),G(!1),z(!1),V(""),$(""),J("")},X=()=>{P(""),g(!1),d(!1)},ee=()=>{Y(),S("options"),x(e=>"login"===e?"signup":"login")};return a().createElement(a().Fragment,null,a().createElement("button",{className:"shogun-connect-button",onClick:()=>{Y(),S("options"),g(!0)}},a().createElement(ce,null),a().createElement("span",null,"Login / Sign Up")),p&&a().createElement("div",{className:"shogun-modal-overlay",onClick:X},a().createElement("div",{className:"shogun-modal",onClick:e=>e.stopPropagation()},a().createElement("div",{className:"shogun-modal-header"},a().createElement("h2",null,"export"===k?"Export Gun Pair":"import"===k?"Import Gun Pair":"webauthn-username"===k?"WebAuthn":"seed-login"===k?"Login with Seed":"login"===A?"Login":"Sign Up"),a().createElement("button",{className:"shogun-close-button",onClick:X,"aria-label":"Close"},a().createElement(ge,null))),a().createElement("div",{className:"shogun-modal-content"},I&&a().createElement("div",{className:"shogun-error-message"},I),"options"===k&&a().createElement(a().Fragment,null,a().createElement("div",{className:"shogun-auth-options"},!1!==c.showMetamask&&f("web3")&&a().createElement("div",{className:"shogun-auth-option-group"},a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>Z("web3"),disabled:C},a().createElement(ce,null),"login"===A?"Login with MetaMask":"Signup with MetaMask")),!1!==c.showWebauthn&&f("webauthn")&&a().createElement("div",{className:"shogun-auth-option-group"},a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>{f("webauthn")?S("webauthn-username"):P("WebAuthn is not supported in your browser")},disabled:C},a().createElement(fe,null),"login"===A?"Login with WebAuthn":"Signup with WebAuthn")),!1!==c.showNostr&&f("nostr")&&a().createElement("div",{className:"shogun-auth-option-group"},a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>Z("nostr"),disabled:C},a().createElement(le,null),"login"===A?"Login with Nostr":"Signup with Nostr")),!1!==c.showChallenge&&f("challenge")&&a().createElement("div",{className:"shogun-auth-option-group"},a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>{f("challenge")?S("challenge-username"):P("Challenge plugin not available")},disabled:C},a().createElement(me,null),"login"===A?"Login with Challenge":"Signup with Challenge (N/A)")),a().createElement("div",{className:"shogun-divider"},a().createElement("span",null,"or")),a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>S("password"),disabled:C},a().createElement(pe,null),"login"===A?"Login with Password":"Signup with Password"),!1!==c.showSeedLogin&&"login"===A&&a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>S("seed-login"),disabled:C},a().createElement(ue,null),"Login with Seed phrase"),"login"===A&&a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>S("import"),disabled:C},a().createElement(ye,null),"Import Gun Pair")),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{type:"button",className:"shogun-toggle-mode shogun-prominent-toggle",onClick:ee,disabled:C},"login"===A?"Don't have an account? Sign up":"Already have an account? Log in"))),"seed-login"===k&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"Login with Seed Phrase"),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"seed-username"},a().createElement(de,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"seed-username",value:y,onChange:e=>m(e.target.value),disabled:C,required:!0,placeholder:"Enter your username",autoFocus:!0})),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"seed-mnemonic"},a().createElement(ue,null),a().createElement("span",null,"Seed Phrase (12/24 words)")),a().createElement("textarea",{id:"seed-mnemonic",value:q,onChange:e=>J(e.target.value),disabled:C,required:!0,placeholder:"Enter your seed phrase...",rows:3,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"1px solid #ccc",borderRadius:"4px"}})),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{P(""),O(!0);try{if(!y.trim())throw new Error("Please enter your username");if(!q.trim())throw new Error("Please enter your seed phrase");await Z("seed",y.trim(),q.trim()),g(!1)}catch(e){P(e.message||"Seed login failed")}finally{O(!1)}},disabled:C||!y.trim()||!q.trim()},C?"Processing...":"Login with Seed"),a().createElement("button",{type:"button",className:"shogun-back-button",onClick:()=>S("options"),disabled:C},"Back")),"password"===k&&a().createElement(a().Fragment,null,a().createElement("button",{className:"shogun-back-button",onClick:()=>S("options")},"← Back"),a().createElement("form",{onSubmit:async e=>{e.preventDefault(),console.log(`[DEBUG] handleSubmit called, formMode: ${A}, username: ${y}`),P(""),O(!0);try{if("signup"===A){const e=await o("password",y,w,v);e&&e.success?g(!1):e&&e.error&&P(e.error)}else await Z("password",y,w)}catch(e){P(e.message||"An unexpected error occurred.")}finally{O(!1)}},className:"shogun-auth-form"},a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"username"},a().createElement(de,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"username",value:y,onChange:e=>m(e.target.value),disabled:C,required:!0,placeholder:"Enter your username"})),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"password"},a().createElement(pe,null),a().createElement("span",null,"Password")),a().createElement("input",{type:"password",id:"password",value:w,onChange:e=>b(e.target.value),disabled:C,required:!0,placeholder:"Enter your password"})),"signup"===A&&a().createElement(a().Fragment,null,a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"passwordConfirm"},a().createElement(ue,null),a().createElement("span",null,"Confirm Password")),a().createElement("input",{type:"password",id:"passwordConfirm",value:v,onChange:e=>E(e.target.value),disabled:C,required:!0,placeholder:"Confirm your password"}))),a().createElement("button",{type:"submit",className:"shogun-submit-button",disabled:C},C?"Processing...":"login"===A?"Sign In":"Create Account"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{type:"button",className:"shogun-toggle-mode shogun-prominent-toggle",onClick:ee,disabled:C},"login"===A?"Don't have an account? Sign up":"Already have an account? Log in")))),"export"===k&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"Export Gun Pair"),a().createElement("div",{style:{backgroundColor:"#f0f9ff",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #0ea5e9"}},a().createElement("p",{style:{fontSize:"14px",color:"#0c4a6e",margin:"0",fontWeight:"500"}},"🔒 Backup Your Account"),a().createElement("p",{style:{fontSize:"13px",color:"#075985",margin:"4px 0 0 0"}},"Export your Gun pair to backup your account. You can use this to login from another device or restore access if needed.")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"exportPassword"},a().createElement(pe,null),a().createElement("span",null,"Encryption Password (optional but recommended)")),a().createElement("input",{type:"password",id:"exportPassword",value:T,onChange:e=>R(e.target.value),disabled:C,placeholder:"Leave empty to export unencrypted"})),_&&a().createElement("div",{className:"shogun-form-group"},a().createElement("label",null,"Your Gun Pair (copy this safely):"),j&&a().createElement("div",{style:{backgroundColor:"#dcfce7",color:"#166534",padding:"8px 12px",borderRadius:"4px",marginBottom:"8px",fontSize:"14px",border:"1px solid #22c55e"}},"✅ Copied to clipboard successfully!"),a().createElement("textarea",{value:_,readOnly:!0,rows:6,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"1px solid #ccc",borderRadius:"4px"}}),!navigator.clipboard&&a().createElement("p",{style:{fontSize:"12px",color:"#666",marginTop:"8px"}},"⚠️ Auto-copy not available. Please manually copy the text above.")),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{P(""),O(!0);try{const e=await u(T||void 0);M(e),navigator.clipboard&&(await navigator.clipboard.writeText(e),G(!0),setTimeout(()=>G(!1),3e3))}catch(e){P(e.message||"Failed to export pair")}finally{O(!1)}},disabled:C},C?"Exporting...":"Export Pair"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{className:"shogun-toggle-mode",onClick:()=>{e?(g(!1),R(""),M("")):(S("options"),R(""),M(""))},disabled:C},"Back"))),"import"===k&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"Import Gun Pair"),a().createElement("div",{style:{backgroundColor:"#fef3c7",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #f59e0b"}},a().createElement("p",{style:{fontSize:"14px",color:"#92400e",margin:"0",fontWeight:"500"}},"🔑 Restore Your Account"),a().createElement("p",{style:{fontSize:"13px",color:"#a16207",margin:"4px 0 0 0"}},"Import a Gun pair to login with your existing account from another device. Make sure you have your backup data ready.")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"importPairData"},a().createElement(ye,null),a().createElement("span",null,"Gun Pair Data")),a().createElement("textarea",{id:"importPairData",value:L,onChange:e=>F(e.target.value),disabled:C,placeholder:"Paste your Gun pair JSON here...",rows:6,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"1px solid #ccc",borderRadius:"4px"}})),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"importPassword"},a().createElement(pe,null),a().createElement("span",null,"Decryption Password (if encrypted)")),a().createElement("input",{type:"password",id:"importPassword",value:U,onChange:e=>D(e.target.value),disabled:C,placeholder:"Enter password if pair was encrypted"})),H&&a().createElement("div",{style:{backgroundColor:"#dcfce7",color:"#166534",padding:"12px",borderRadius:"8px",marginBottom:"16px",fontSize:"14px",border:"1px solid #22c55e",textAlign:"center"}},"✅ Pair imported successfully! Logging you in..."),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{P(""),O(!0);try{if(!L.trim())throw new Error("Please enter pair data");if(!await l(L,U||void 0))throw new Error("Failed to import pair");z(!0),setTimeout(()=>{g(!1),z(!1)},1500)}catch(e){P(e.message||"Failed to import pair")}finally{O(!1)}},disabled:C||H},C?"Importing...":H?"Success!":"Import and Login"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{className:"shogun-toggle-mode",onClick:()=>{S("options"),D(""),F("")},disabled:C},"Back to Login Options"))),"webauthn-username"===k&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"login"===A?"Login with WebAuthn":"Sign Up with WebAuthn"),a().createElement("div",{style:{backgroundColor:"#f0f9ff",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #0ea5e9"}},a().createElement("p",{style:{fontSize:"14px",color:"#0c4a6e",margin:"0",fontWeight:"500"}},"🔑 WebAuthn Authentication"),a().createElement("p",{style:{fontSize:"13px",color:"#075985",margin:"4px 0 0 0"}},"Please enter your username to continue with WebAuthn"," ","login"===A?"login":"registration",".")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"username"},a().createElement(de,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"username",value:y,onChange:e=>m(e.target.value),disabled:C,required:!0,placeholder:"Enter your username",autoFocus:!0})),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:()=>Z("webauthn",y),disabled:C||!y.trim()},C?"Processing...":"Continue with WebAuthn"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{type:"button",className:"shogun-back-button",onClick:()=>S("options"),disabled:C},"← Back to Options"),"login"===A&&a().createElement("button",{type:"button",className:"shogun-toggle-mode",onClick:()=>S("webauthn-recovery"),disabled:C},"Restore with Recovery Code"))),"webauthn-recovery"===k&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"Restore WebAuthn Account"),a().createElement("div",{style:{backgroundColor:"#fef3c7",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #f59e0b"}},a().createElement("p",{style:{fontSize:"14px",color:"#92400e",margin:"0",fontWeight:"500"}},"⚠️ Recovery Required"),a().createElement("p",{style:{fontSize:"13px",color:"#a16207",margin:"4px 0 0 0"}},"Enter the username and recovery code saved during signup to restore access on this device.")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"recoveryUsername"},a().createElement(de,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"recoveryUsername",value:y,onChange:e=>m(e.target.value),disabled:C,placeholder:"Enter your username",autoFocus:!0})),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"recoverySeed"},a().createElement(ue,null),a().createElement("span",null,"Recovery Code")),a().createElement("textarea",{id:"recoverySeed",value:W,onChange:e=>$(e.target.value),disabled:C,placeholder:"Enter your WebAuthn seed phrase...",rows:4,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"1px solid #f59e0b",borderRadius:"4px",backgroundColor:"#fffbeb"}})),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{P(""),O(!0);try{const e=y.trim(),t=W.trim();if(!e)throw new Error("Please enter your username");if(!t)throw new Error("Please enter your recovery code");if(!re(i))throw new Error("WebAuthn recovery requires ShogunCore");const n=await o("webauthn",e,{seedPhrase:t,generateSeedPhrase:!1});if(!n||!n.success)throw new Error((null==n?void 0:n.error)||"Failed to restore account");const r=n.seedPhrase||t;V(r),$(""),G(!1),S("webauthn-signup-result")}catch(e){P(e.message||"Failed to restore WebAuthn account")}finally{O(!1)}},disabled:C},C?"Restoring...":"Restore Account"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{type:"button",className:"shogun-back-button",onClick:()=>{P(""),S("webauthn-username")},disabled:C},"← Back to WebAuthn"))),"webauthn-signup-result"===k&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"WebAuthn Account Created!"),a().createElement("div",{style:{backgroundColor:"#fef3c7",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #f59e0b"}},a().createElement("p",{style:{fontSize:"14px",color:"#92400e",margin:"0",fontWeight:"500"}},"⚠️ Important: Save Your Recovery Code"),a().createElement("p",{style:{fontSize:"13px",color:"#a16207",margin:"4px 0 0 0"}},"This seed phrase lets you add new devices or recover your WebAuthn account. Keep it private and store it securely.")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",null,"Your WebAuthn Recovery Code (Seed Phrase):"),a().createElement("textarea",{value:K,readOnly:!0,rows:4,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"2px solid #f59e0b",borderRadius:"4px",backgroundColor:"#fffbeb"}}),a().createElement("button",{type:"button",className:"shogun-submit-button",style:{marginTop:"8px"},onClick:async()=>{navigator.clipboard&&K&&(await navigator.clipboard.writeText(K),G(!0),setTimeout(()=>G(!1),3e3))},disabled:!K},j?"✅ Copied!":"📋 Copy Recovery Code"),!navigator.clipboard&&a().createElement("p",{style:{fontSize:"12px",color:"#666",marginTop:"8px"}},"⚠️ Please manually copy the code above for safekeeping.")),a().createElement("div",{style:{backgroundColor:"#dcfce7",color:"#166534",padding:"12px",borderRadius:"8px",marginTop:"16px",fontSize:"14px",border:"1px solid #22c55e",textAlign:"center"}},"✅ You're now logged in with WebAuthn!"),a().createElement("button",{type:"button",className:"shogun-submit-button",style:{marginTop:"16px"},onClick:()=>{P(""),Y(),g(!1),d(!1)}},"Close and Start Using App")),"challenge-username"===k&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"challenge-username"},a().createElement(de,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"challenge-username",value:y,onChange:e=>m(e.target.value),disabled:C,required:!0,placeholder:"Enter your username",autoFocus:!0})),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{P(""),O(!0);try{if(!y.trim())throw new Error("Please enter your username");await Z("challenge",y),g(!1)}catch(e){P(e.message||"Challenge login failed")}finally{O(!1)}},disabled:C},C?"Processing...":"Continue"),a().createElement("button",{type:"button",className:"shogun-back-button",onClick:()=>S("options"),disabled:C},"Back"))))))};return e.displayName="ShogunButton",Object.assign(e,{Provider:ae,useShogun:se})})();var ve=r(287),Ee=r(287).hp;"undefined"!=typeof window&&(window.process||(window.process={env:{}}),window.global||(window.global=window));var Ae=function(e){"undefined"!=typeof window&&(window.Buffer=e,window.global=window.global||window,window.global.Buffer=e),"undefined"!=typeof globalThis&&(globalThis.Buffer=e)};"undefined"!=typeof window&&window.Buffer&&void 0===Ee?Ae(window.Buffer):"undefined"!=typeof globalThis&&void 0===Ee&&Ae(ve.hp);var xe,ke=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Se(e,t,n,r){return{type:e,code:t,message:n,originalError:r,timestamp:Date.now()}}!function(e){e.AUTHENTICATION="AuthenticationError",e.AUTHORIZATION="AuthorizationError",e.VALIDATION="ValidationError",e.NETWORK="NetworkError",e.DATABASE="DatabaseError",e.WALLET="WalletError",e.STORAGE="StorageError",e.ENCRYPTION="EncryptionError",e.SIGNATURE="SignatureError",e.ENVIRONMENT="EnvironmentError",e.SECURITY="SecurityError",e.GUN="GunError",e.STEALTH="StealthError",e.WEBAUTHN="WebAuthnError",e.PLUGIN="PluginError",e.UNKNOWN="UnknownError",e.CONNECTOR="ConnectorError",e.GENERAL="GeneralError",e.CONTRACT="ContractError",e.BIP32="BIP32Error",e.ETHEREUM="EthereumError",e.BITCOIN="BitcoinError"}(xe||(xe={}));var Ie=function(){function e(){}return e.setExternalLogger=function(e){this.externalLogger=e},e.handleError=function(e){if(e.type!==xe.AUTHENTICATION&&e.type!==xe.AUTHORIZATION&&e.type!==xe.SECURITY||"undefined"!=typeof console&&console.error&&console.error("[".concat(e.type,"] ").concat(e.code,": ").concat(e.message)),this.errors.push(e),this.errors.length>this.maxErrors&&(this.errors=this.errors.slice(-this.maxErrors)),this.externalLogger)try{this.externalLogger(e)}catch(e){console.error("Failed to send error to external logger:",e)}this.listeners.forEach(function(t){try{t(e)}catch(e){}})},e.handle=function(e,t,n,r,o){void 0===o&&(o="error");var i=n;console.log("[".concat(e,"] ").concat(t,": ").concat(i));var s=Se(e,t,i,r);return this.handleError(s),s},e.handleAndThrow=function(e,t,n,r){throw this.handle(e,t,n,r)},e.getRecentErrors=function(e){return void 0===e&&(e=10),this.errors.slice(-Math.min(e,this.errors.length))},e.addListener=function(e){this.listeners.push(e)},e.removeListener=function(e){var t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)},e.notifyListeners=function(e){var t,n;try{for(var r=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.listeners),o=r.next();!o.done;o=r.next()){var i=o.value;try{i(e)}catch(e){console.error("Error in error listener: ".concat(e))}}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}},e.formatError=function(e){if(!e)return"Unknown error";if(e instanceof Error)return"".concat(e.name,": ").concat(e.message);if("string"==typeof e)return e;if("object"==typeof e)try{return JSON.stringify(e)}catch(t){return"Object: ".concat(Object.prototype.toString.call(e))}return String(e)},e.withRetry=function(e,t,n){return r=this,o=arguments,s=function(e,t,n,r,o){var i,s,a,c;return void 0===r&&(r=3),void 0===o&&(o=1e3),ke(this,function(u){switch(u.label){case 0:s=function(t){var n,s,a;return ke(this,function(c){switch(c.label){case 0:return c.trys.push([0,2,,5]),n={},[4,e()];case 1:return[2,(n.value=c.sent(),n)];case 2:return s=c.sent(),i=s,a=o*t,t<r?(console.log("Retrying operation after ".concat(a,"ms (attempt ").concat(t,"/").concat(r,")")),[4,new Promise(function(e){return setTimeout(e,a)})]):[3,4];case 3:c.sent(),c.label=4;case 4:return[3,5];case 5:return[2]}})},a=1,u.label=1;case 1:return a<=r?[5,s(a)]:[3,4];case 2:if("object"==typeof(c=u.sent()))return[2,c.value];u.label=3;case 3:return a++,[3,1];case 4:if(this.handle(t,n,"Operation failed after ".concat(r," attempts"),i),i instanceof Error)throw new Error(i.message);throw new Error(this.formatError(i))}})},new((i=void 0)||(i=Promise))(function(e,t){function n(e){try{c(s.next(e))}catch(e){t(e)}}function a(e){try{c(s.throw(e))}catch(e){t(e)}}function c(t){var r;t.done?e(t.value):(r=t.value,r instanceof i?r:new i(function(e){e(r)})).then(n,a)}c((s=s.apply(r,o||[])).next())});var r,o,i,s},e.clearErrors=function(){this.errors=[]},e.errors=[],e.maxErrors=100,e.listeners=[],e.externalLogger=null,e}(),Pe=function(){function e(){this.events=new Map}return e.prototype.on=function(e,t){var n;this.events.has(e)||this.events.set(e,[]),null===(n=this.events.get(e))||void 0===n||n.push(t)},e.prototype.emit=function(e,t){return!!this.events.has(e)&&((this.events.get(e)||[]).forEach(function(n){try{n(t)}catch(t){var r=t instanceof Error?t:new Error(String(t));console.error("Error in event listener for ".concat(String(e),":"),r)}}),!0)},e.prototype.off=function(e,t){if(this.events.has(e)){var n=this.events.get(e)||[],r=n.indexOf(t);-1!==r&&(n.splice(r,1),0===n.length?this.events.delete(e):this.events.set(e,n))}},e.prototype.once=function(e,t){var n=this,r=function(o){t(o),n.off(e,r)};this.on(e,r)},e.prototype.removeAllListeners=function(e){e?this.events.delete(e):this.events.clear()},e}(),Ce=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Oe=function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.core=null,t}return Ce(t,e),t.prototype.initialize=function(e){this.core=e},t.prototype.destroy=function(){try{this.emit("destroyed",{name:this.name,version:this.version}),this.core=null}catch(e){console.error("[".concat(this.name,"] Error during plugin destruction:"),e)}},t.prototype.assertInitialized=function(){if(!this.core)throw new Error("Plugin ".concat(this.name," not initialized"));return this.core},t}(Pe);const Ne="6.16.0";function Be(e,t,n){const r=t.split("|").map(e=>e.trim());for(let n=0;n<r.length;n++)switch(t){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof e===t)return}const o=new Error(`invalid value for type ${t}`);throw o.code="INVALID_ARGUMENT",o.argument=`value.${n}`,o.value=e,o}async function Te(e){const t=Object.keys(e);return(await Promise.all(t.map(t=>Promise.resolve(e[t])))).reduce((e,n,r)=>(e[t[r]]=n,e),{})}function Re(e,t,n){for(let r in t){let o=t[r];const i=n?n[r]:null;i&&Be(o,i,r),Object.defineProperty(e,r,{enumerable:!0,value:o,writable:!1})}}function Ue(e,t){if(null==e)return"null";if(null==t&&(t=new Set),"object"==typeof e){if(t.has(e))return"[Circular]";t.add(e)}if(Array.isArray(e))return"[ "+e.map(e=>Ue(e,t)).join(", ")+" ]";if(e instanceof Uint8Array){const t="0123456789abcdef";let n="0x";for(let r=0;r<e.length;r++)n+=t[e[r]>>4],n+=t[15&e[r]];return n}if("object"==typeof e&&"function"==typeof e.toJSON)return Ue(e.toJSON(),t);switch(typeof e){case"boolean":case"number":case"symbol":return e.toString();case"bigint":return BigInt(e).toString();case"string":return JSON.stringify(e);case"object":{const n=Object.keys(e);return n.sort(),"{ "+n.map(n=>`${Ue(n,t)}: ${Ue(e[n],t)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function De(e,t){return e&&e.code===t}function Le(e){return De(e,"CALL_EXCEPTION")}function Fe(e,t,n){let r,o=e;{const r=[];if(n){if("message"in n||"code"in n||"name"in n)throw new Error(`value will overwrite populated values: ${Ue(n)}`);for(const e in n){if("shortMessage"===e)continue;const t=n[e];r.push(e+"="+Ue(t))}}r.push(`code=${t}`),r.push(`version=${Ne}`),r.length&&(e+=" ("+r.join(", ")+")")}switch(t){case"INVALID_ARGUMENT":r=new TypeError(e);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":r=new RangeError(e);break;default:r=new Error(e)}return Re(r,{code:t}),n&&Object.assign(r,n),null==r.shortMessage&&Re(r,{shortMessage:o}),r}function _e(e,t,n,r){if(!e)throw Fe(t,n,r)}function Me(e,t,n,r){_e(e,t,"INVALID_ARGUMENT",{argument:n,value:r})}function je(e,t,n){null==n&&(n=""),n&&(n=": "+n),_e(e>=t,"missing argument"+n,"MISSING_ARGUMENT",{count:e,expectedCount:t}),_e(e<=t,"too many arguments"+n,"UNEXPECTED_ARGUMENT",{count:e,expectedCount:t})}const Ge=["NFD","NFC","NFKD","NFKC"].reduce((e,t)=>{try{if("test"!=="test".normalize(t))throw new Error("bad");if("NFD"===t){if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken")}e.push(t)}catch(e){}return e},[]);function He(e){_e(Ge.indexOf(e)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:e}})}function ze(e,t,n){if(null==n&&(n=""),e!==t){let e=n,t="new";n&&(e+=".",t+=" "+n),_e(!1,`private constructor; use ${e}from* methods`,"UNSUPPORTED_OPERATION",{operation:t})}}function Ke(e,t,n){if(e instanceof Uint8Array)return n?new Uint8Array(e):e;if("string"==typeof e&&e.length%2==0&&e.match(/^0x[0-9a-f]*$/i)){const t=new Uint8Array((e.length-2)/2);let n=2;for(let r=0;r<t.length;r++)t[r]=parseInt(e.substring(n,n+2),16),n+=2;return t}Me(!1,"invalid BytesLike value",t||"value",e)}function Ve(e,t){return Ke(e,t,!1)}function We(e,t){return Ke(e,t,!0)}function $e(e,t){return!("string"!=typeof e||!e.match(/^0x[0-9A-Fa-f]*$/)||"number"==typeof t&&e.length!==2+2*t||!0===t&&e.length%2!=0)}function qe(e){return $e(e,!0)||e instanceof Uint8Array}const Je="0123456789abcdef";function Qe(e){const t=Ve(e);let n="0x";for(let e=0;e<t.length;e++){const r=t[e];n+=Je[(240&r)>>4]+Je[15&r]}return n}function Ze(e){return"0x"+e.map(e=>Qe(e).substring(2)).join("")}function Ye(e){return $e(e,!0)?(e.length-2)/2:Ve(e).length}function Xe(e,t,n){const r=Ve(e);return null!=n&&n>r.length&&_e(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:r,length:r.length,offset:n}),Qe(r.slice(null==t?0:t,null==n?r.length:n))}function et(e,t,n){const r=Ve(e);_e(t>=r.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(r),length:t,offset:t+1});const o=new Uint8Array(t);return o.fill(0),n?o.set(r,t-r.length):o.set(r,0),Qe(o)}function tt(e,t){return et(e,t,!0)}function nt(e,t,n,r,o){if("BAD_PREFIX"===e||"UNEXPECTED_CONTINUE"===e){let e=0;for(let r=t+1;r<n.length&&n[r]>>6==2;r++)e++;return e}return"OVERRUN"===e?n.length-t-1:0}const rt=Object.freeze({error:function(e,t,n,r,o){Me(!1,`invalid codepoint at offset ${t}; ${e}`,"bytes",n)},ignore:nt,replace:function(e,t,n,r,o){return"OVERLONG"===e?(Me("number"==typeof o,"invalid bad code point for replacement","badCodepoint",o),r.push(o),0):(r.push(65533),nt(e,t,n))}});function ot(e,t){Me("string"==typeof e,"invalid string value","str",e),null!=t&&(He(t),e=e.normalize(t));let n=[];for(let t=0;t<e.length;t++){const r=e.charCodeAt(t);if(r<128)n.push(r);else if(r<2048)n.push(r>>6|192),n.push(63&r|128);else if(55296==(64512&r)){t++;const o=e.charCodeAt(t);Me(t<e.length&&56320==(64512&o),"invalid surrogate pair","str",e);const i=65536+((1023&r)<<10)+(1023&o);n.push(i>>18|240),n.push(i>>12&63|128),n.push(i>>6&63|128),n.push(63&i|128)}else n.push(r>>12|224),n.push(r>>6&63|128),n.push(63&r|128)}return new Uint8Array(n)}function it(e,t){return function(e,t){null==t&&(t=rt.error);const n=Ve(e,"bytes"),r=[];let o=0;for(;o<n.length;){const e=n[o++];if(!(e>>7)){r.push(e);continue}let i=null,s=null;if(192==(224&e))i=1,s=127;else if(224==(240&e))i=2,s=2047;else{if(240!=(248&e)){o+=t(128==(192&e)?"UNEXPECTED_CONTINUE":"BAD_PREFIX",o-1,n,r);continue}i=3,s=65535}if(o-1+i>=n.length){o+=t("OVERRUN",o-1,n,r);continue}let a=e&(1<<8-i-1)-1;for(let e=0;e<i;e++){let e=n[o];if(128!=(192&e)){o+=t("MISSING_CONTINUE",o,n,r),a=null;break}a=a<<6|63&e,o++}null!==a&&(a>1114111?o+=t("OUT_OF_RANGE",o-1-i,n,r,a):a>=55296&&a<=57343?o+=t("UTF16_SURROGATE",o-1-i,n,r,a):a<=s?o+=t("OVERLONG",o-1-i,n,r,a):r.push(a))}return r}(e,t).map(e=>e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode(55296+(e>>10&1023),56320+(1023&e)))).join("")}function st(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function at(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function ct(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");st(e.outputLen),st(e.blockLen)}function ut(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function lt(e,t){at(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const ft="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,ht=e=>e instanceof Uint8Array,dt=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),pt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),gt=(e,t)=>e<<32-t|e>>>t;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const yt=async()=>{};async function mt(e,t,n){let r=Date.now();for(let o=0;o<e;o++){n(o);const e=Date.now()-r;e>=0&&e<t||(await yt(),r+=e)}}function wt(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!ht(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class bt{clone(){return this._cloneInto()}}const vt={}.toString;function Et(e,t){if(void 0!==t&&"[object Object]"!==vt.call(t))throw new Error("Options should be object or undefined");return Object.assign(e,t)}function At(e){const t=t=>e().update(wt(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function xt(e=32){if(ft&&"function"==typeof ft.getRandomValues)return ft.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}class kt extends bt{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ct(e);const n=wt(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),o.fill(0)}update(e){return ut(this),this.iHash.update(e),this}digestInto(e){ut(this),at(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const St=(e,t,n)=>new kt(e,t).update(n).digest();function It(e,t,n,r){const{c:o,dkLen:i,DK:s,PRF:a,PRFSalt:c}=function(e,t,n,r){ct(e);const o=Et({dkLen:32,asyncTick:10},r),{c:i,dkLen:s,asyncTick:a}=o;if(st(i),st(s),st(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");const c=wt(t),u=wt(n),l=new Uint8Array(s),f=St.create(e,c),h=f._cloneInto().update(u);return{c:i,dkLen:s,asyncTick:a,DK:l,PRF:f,PRFSalt:h}}(e,t,n,r);let u;const l=new Uint8Array(4),f=pt(l),h=new Uint8Array(a.outputLen);for(let e=1,t=0;t<i;e++,t+=a.outputLen){const n=s.subarray(t,t+a.outputLen);f.setInt32(0,e,!1),(u=c._cloneInto(u)).update(l).digestInto(h),n.set(h.subarray(0,n.length));for(let e=1;e<o;e++){a._cloneInto(u).update(h).digestInto(h);for(let e=0;e<n.length;e++)n[e]^=h[e]}}return function(e,t,n,r,o){return e.destroy(),t.destroy(),r&&r.destroy(),o.fill(0),n}(a,c,s,u,h)}St.create=(e,t)=>new kt(e,t);class Pt extends bt{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=pt(this.buffer)}update(e){ut(this);const{view:t,buffer:n,blockLen:r}=this,o=(e=wt(e)).length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=pt(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ut(this),lt(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=pt(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.length=r,e.pos=s,e.finished=o,e.destroyed=i,r%t&&e.buffer.set(n),e}}const Ct=(e,t,n)=>e&t^~e&n,Ot=(e,t,n)=>e&t^e&n^t&n,Nt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Bt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Tt=new Uint32Array(64);class Rt extends Pt{constructor(){super(64,32,8,!1),this.A=0|Bt[0],this.B=0|Bt[1],this.C=0|Bt[2],this.D=0|Bt[3],this.E=0|Bt[4],this.F=0|Bt[5],this.G=0|Bt[6],this.H=0|Bt[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)Tt[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Tt[e-15],n=Tt[e-2],r=gt(t,7)^gt(t,18)^t>>>3,o=gt(n,17)^gt(n,19)^n>>>10;Tt[e]=o+Tt[e-7]+r+Tt[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(gt(s,6)^gt(s,11)^gt(s,25))+Ct(s,a,c)+Nt[e]+Tt[e]|0,l=(gt(n,2)^gt(n,13)^gt(n,22))+Ot(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){Tt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const Ut=At(()=>new Rt),Dt=BigInt(2**32-1),Lt=BigInt(32);function Ft(e,t=!1){return t?{h:Number(e&Dt),l:Number(e>>Lt&Dt)}:{h:0|Number(e>>Lt&Dt),l:0|Number(e&Dt)}}function _t(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const{h:i,l:s}=Ft(e[o],t);[n[o],r[o]]=[i,s]}return[n,r]}const Mt=(e,t,n)=>e<<n|t>>>32-n,jt=(e,t,n)=>t<<n|e>>>32-n,Gt=(e,t,n)=>t<<n-32|e>>>64-n,Ht=(e,t,n)=>e<<n-32|t>>>64-n,zt={fromBig:Ft,split:_t,toBig:(e,t)=>BigInt(e>>>0)<<Lt|BigInt(t>>>0),shrSH:(e,t,n)=>e>>>n,shrSL:(e,t,n)=>e<<32-n|t>>>n,rotrSH:(e,t,n)=>e>>>n|t<<32-n,rotrSL:(e,t,n)=>e<<32-n|t>>>n,rotrBH:(e,t,n)=>e<<64-n|t>>>n-32,rotrBL:(e,t,n)=>e>>>n-32|t<<64-n,rotr32H:(e,t)=>t,rotr32L:(e,t)=>e,rotlSH:Mt,rotlSL:jt,rotlBH:Gt,rotlBL:Ht,add:function(e,t,n,r){const o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:0|o}},add3L:(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),add3H:(e,t,n,r)=>t+n+r+(e/2**32|0)|0,add4L:(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),add4H:(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,add5H:(e,t,n,r,o,i)=>t+n+r+o+i+(e/2**32|0)|0,add5L:(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0)},[Kt,Vt]=(()=>zt.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(e=>BigInt(e))))(),Wt=new Uint32Array(80),$t=new Uint32Array(80);class qt extends Pt{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(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:o,Cl:i,Dh:s,Dl:a,Eh:c,El:u,Fh:l,Fl:f,Gh:h,Gl:d,Hh:p,Hl:g}=this;return[e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g]}set(e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|o,this.Cl=0|i,this.Dh=0|s,this.Dl=0|a,this.Eh=0|c,this.El=0|u,this.Fh=0|l,this.Fl=0|f,this.Gh=0|h,this.Gl=0|d,this.Hh=0|p,this.Hl=0|g}process(e,t){for(let n=0;n<16;n++,t+=4)Wt[n]=e.getUint32(t),$t[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|Wt[e-15],n=0|$t[e-15],r=zt.rotrSH(t,n,1)^zt.rotrSH(t,n,8)^zt.shrSH(t,n,7),o=zt.rotrSL(t,n,1)^zt.rotrSL(t,n,8)^zt.shrSL(t,n,7),i=0|Wt[e-2],s=0|$t[e-2],a=zt.rotrSH(i,s,19)^zt.rotrBH(i,s,61)^zt.shrSH(i,s,6),c=zt.rotrSL(i,s,19)^zt.rotrBL(i,s,61)^zt.shrSL(i,s,6),u=zt.add4L(o,c,$t[e-7],$t[e-16]),l=zt.add4H(u,r,a,Wt[e-7],Wt[e-16]);Wt[e]=0|l,$t[e]=0|u}let{Ah:n,Al:r,Bh:o,Bl:i,Ch:s,Cl:a,Dh:c,Dl:u,Eh:l,El:f,Fh:h,Fl:d,Gh:p,Gl:g,Hh:y,Hl:m}=this;for(let e=0;e<80;e++){const t=zt.rotrSH(l,f,14)^zt.rotrSH(l,f,18)^zt.rotrBH(l,f,41),w=zt.rotrSL(l,f,14)^zt.rotrSL(l,f,18)^zt.rotrBL(l,f,41),b=l&h^~l&p,v=f&d^~f&g,E=zt.add5L(m,w,v,Vt[e],$t[e]),A=zt.add5H(E,y,t,b,Kt[e],Wt[e]),x=0|E,k=zt.rotrSH(n,r,28)^zt.rotrBH(n,r,34)^zt.rotrBH(n,r,39),S=zt.rotrSL(n,r,28)^zt.rotrBL(n,r,34)^zt.rotrBL(n,r,39),I=n&o^n&s^o&s,P=r&i^r&a^i&a;y=0|p,m=0|g,p=0|h,g=0|d,h=0|l,d=0|f,({h:l,l:f}=zt.add(0|c,0|u,0|A,0|x)),c=0|s,u=0|a,s=0|o,a=0|i,o=0|n,i=0|r;const C=zt.add3L(x,S,P);n=zt.add3H(C,A,k,I),r=0|C}({h:n,l:r}=zt.add(0|this.Ah,0|this.Al,0|n,0|r)),({h:o,l:i}=zt.add(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:a}=zt.add(0|this.Ch,0|this.Cl,0|s,0|a)),({h:c,l:u}=zt.add(0|this.Dh,0|this.Dl,0|c,0|u)),({h:l,l:f}=zt.add(0|this.Eh,0|this.El,0|l,0|f)),({h,l:d}=zt.add(0|this.Fh,0|this.Fl,0|h,0|d)),({h:p,l:g}=zt.add(0|this.Gh,0|this.Gl,0|p,0|g)),({h:y,l:m}=zt.add(0|this.Hh,0|this.Hl,0|y,0|m)),this.set(n,r,o,i,s,a,c,u,l,f,h,d,p,g,y,m)}roundClean(){Wt.fill(0),$t.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)}}const Jt=At(()=>new qt),Qt=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r.g)return r.g;throw new Error("unable to locate global object")}(),Zt=Qt.crypto||Qt.msCrypto;function Yt(e){switch(e){case"sha256":return Ut.create();case"sha512":return Jt.create()}Me(!1,"invalid hashing algorithm name","algorithm",e)}const Xt=function(e){return Yt("sha256").update(e).digest()},en=function(e){return Yt("sha512").update(e).digest()};let tn=Xt,nn=en,rn=!1,on=!1;function sn(e){const t=Ve(e,"data");return Qe(tn(t))}function an(e){const t=Ve(e,"data");return Qe(nn(t))}sn._=Xt,sn.lock=function(){rn=!0},sn.register=function(e){if(rn)throw new Error("sha256 is locked");tn=e},Object.freeze(sn),an._=en,an.lock=function(){on=!0},an.register=function(e){if(on)throw new Error("sha512 is locked");nn=e},Object.freeze(sn);const[cn,un,ln]=[[],[],[]],fn=BigInt(0),hn=BigInt(1),dn=BigInt(2),pn=BigInt(7),gn=BigInt(256),yn=BigInt(113);for(let e=0,t=hn,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],cn.push(2*(5*r+n)),un.push((e+1)*(e+2)/2%64);let o=fn;for(let e=0;e<7;e++)t=(t<<hn^(t>>pn)*yn)%gn,t&dn&&(o^=hn<<(hn<<BigInt(e))-hn);ln.push(o)}const[mn,wn]=_t(ln,!0),bn=(e,t,n)=>n>32?Gt(e,t,n):Mt(e,t,n),vn=(e,t,n)=>n>32?Ht(e,t,n):jt(e,t,n);class En extends bt{constructor(e,t,n,r=!1,o=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,st(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=dt(this.state)}keccak(){!function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,o=(t+2)%10,i=n[o],s=n[o+1],a=bn(i,s,1)^n[r],c=vn(i,s,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],o=e[3];for(let n=0;n<24;n++){const r=un[n],i=bn(t,o,r),s=vn(t,o,r),a=cn[n];t=e[a],o=e[a+1],e[a]=i,e[a+1]=s}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=mn[r],e[1]^=wn[r]}n.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){ut(this);const{blockLen:t,state:n}=this,r=(e=wt(e)).length;for(let o=0;o<r;){const i=Math.min(t-this.pos,r-o);for(let t=0;t<i;t++)n[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){ut(this,!1),at(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,o=e.length;r<o;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,o-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return st(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(lt(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:o,enableXOF:i}=this;return e||(e=new En(t,n,r,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const An=((e,t,n)=>At(()=>new En(t,e,n)))(1,136,32);let xn=!1;const kn=function(e){return An(e)};let Sn=kn;function In(e){const t=Ve(e,"data");return Qe(Sn(t))}var Pn;In._=kn,In.lock=function(){xn=!0},In.register=function(e){if(xn)throw new TypeError("keccak256 is locked");Sn=e},Object.freeze(In),function(e){e.DEVICE_REGISTERED="deviceRegistered",e.DEVICE_REMOVED="deviceRemoved",e.AUTHENTICATION_SUCCESS="authenticationSuccess",e.AUTHENTICATION_FAILED="authenticationFailed",e.ERROR="error"}(Pn||(Pn={}));const Cn="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function On(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Nn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Bn(e,...t){if(!On(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Tn(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");Nn(e.outputLen),Nn(e.blockLen)}function Rn(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Un(e,t){Bn(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Dn(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Ln(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Fn(e,t){return e<<32-t|e>>>t}function _n(e,t){return e<<t|e>>>32-t>>>0}function Mn(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const jn=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=Mn(e[t]);return e},Gn=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),Hn=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function zn(e){if(Bn(e),Gn)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=Hn[e[n]];return t}function Kn(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Vn(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(Gn)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,o=0;t<n;t++,o+=2){const n=Kn(e.charCodeAt(o)),i=Kn(e.charCodeAt(o+1));if(void 0===n||void 0===i){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}r[t]=16*n+i}return r}function Wn(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}function $n(e){return"string"==typeof e&&(e=Wn(e)),Bn(e),e}function qn(e){return"string"==typeof e&&(e=Wn(e)),Bn(e),e}function Jn(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];Bn(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const o=e[t];n.set(o,r),r+=o.length}return n}class Qn{}function Zn(e){const t=t=>e().update($n(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Yn(e=32){if(Cn&&"function"==typeof Cn.getRandomValues)return Cn.getRandomValues(new Uint8Array(e));if(Cn&&"function"==typeof Cn.randomBytes)return Uint8Array.from(Cn.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Xn(e,t,n){return e&t^~e&n}function er(e,t,n){return e&t^e&n^t&n}class tr extends Qn{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Ln(this.buffer)}update(e){Rn(this),Bn(e=$n(e));const{view:t,buffer:n,blockLen:r}=this,o=e.length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=Ln(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Rn(this),Un(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,Dn(this.buffer.subarray(i)),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=Ln(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const nr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),rr=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),or=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),ir=BigInt(2**32-1),sr=BigInt(32);function ar(e,t=!1){return t?{h:Number(e&ir),l:Number(e>>sr&ir)}:{h:0|Number(e>>sr&ir),l:0|Number(e&ir)}}function cr(e,t=!1){const n=e.length;let r=new Uint32Array(n),o=new Uint32Array(n);for(let i=0;i<n;i++){const{h:n,l:s}=ar(e[i],t);[r[i],o[i]]=[n,s]}return[r,o]}const ur=(e,t,n)=>e>>>n,lr=(e,t,n)=>e<<32-n|t>>>n,fr=(e,t,n)=>e>>>n|t<<32-n,hr=(e,t,n)=>e<<32-n|t>>>n,dr=(e,t,n)=>e<<64-n|t>>>n-32,pr=(e,t,n)=>e>>>n-32|t<<64-n;function gr(e,t,n,r){const o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:0|o}}const yr=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),mr=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,wr=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),br=(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,vr=(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0),Er=(e,t,n,r,o,i)=>t+n+r+o+i+(e/2**32|0)|0,Ar=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),xr=new Uint32Array(64);class kr extends tr{constructor(e=32){super(64,e,8,!1),this.A=0|nr[0],this.B=0|nr[1],this.C=0|nr[2],this.D=0|nr[3],this.E=0|nr[4],this.F=0|nr[5],this.G=0|nr[6],this.H=0|nr[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)xr[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=xr[e-15],n=xr[e-2],r=Fn(t,7)^Fn(t,18)^t>>>3,o=Fn(n,17)^Fn(n,19)^n>>>10;xr[e]=o+xr[e-7]+r+xr[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(Fn(s,6)^Fn(s,11)^Fn(s,25))+Xn(s,a,c)+Ar[e]+xr[e]|0,l=(Fn(n,2)^Fn(n,13)^Fn(n,22))+er(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){Dn(xr)}destroy(){this.set(0,0,0,0,0,0,0,0),Dn(this.buffer)}}const Sr=(()=>cr(["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(e=>BigInt(e))))(),Ir=(()=>Sr[0])(),Pr=(()=>Sr[1])(),Cr=new Uint32Array(80),Or=new Uint32Array(80);class Nr extends tr{constructor(e=64){super(128,e,16,!1),this.Ah=0|or[0],this.Al=0|or[1],this.Bh=0|or[2],this.Bl=0|or[3],this.Ch=0|or[4],this.Cl=0|or[5],this.Dh=0|or[6],this.Dl=0|or[7],this.Eh=0|or[8],this.El=0|or[9],this.Fh=0|or[10],this.Fl=0|or[11],this.Gh=0|or[12],this.Gl=0|or[13],this.Hh=0|or[14],this.Hl=0|or[15]}get(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:o,Cl:i,Dh:s,Dl:a,Eh:c,El:u,Fh:l,Fl:f,Gh:h,Gl:d,Hh:p,Hl:g}=this;return[e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g]}set(e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|o,this.Cl=0|i,this.Dh=0|s,this.Dl=0|a,this.Eh=0|c,this.El=0|u,this.Fh=0|l,this.Fl=0|f,this.Gh=0|h,this.Gl=0|d,this.Hh=0|p,this.Hl=0|g}process(e,t){for(let n=0;n<16;n++,t+=4)Cr[n]=e.getUint32(t),Or[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|Cr[e-15],n=0|Or[e-15],r=fr(t,n,1)^fr(t,n,8)^ur(t,0,7),o=hr(t,n,1)^hr(t,n,8)^lr(t,n,7),i=0|Cr[e-2],s=0|Or[e-2],a=fr(i,s,19)^dr(i,s,61)^ur(i,0,6),c=hr(i,s,19)^pr(i,s,61)^lr(i,s,6),u=wr(o,c,Or[e-7],Or[e-16]),l=br(u,r,a,Cr[e-7],Cr[e-16]);Cr[e]=0|l,Or[e]=0|u}let{Ah:n,Al:r,Bh:o,Bl:i,Ch:s,Cl:a,Dh:c,Dl:u,Eh:l,El:f,Fh:h,Fl:d,Gh:p,Gl:g,Hh:y,Hl:m}=this;for(let e=0;e<80;e++){const t=fr(l,f,14)^fr(l,f,18)^dr(l,f,41),w=hr(l,f,14)^hr(l,f,18)^pr(l,f,41),b=l&h^~l&p,v=vr(m,w,f&d^~f&g,Pr[e],Or[e]),E=Er(v,y,t,b,Ir[e],Cr[e]),A=0|v,x=fr(n,r,28)^dr(n,r,34)^dr(n,r,39),k=hr(n,r,28)^pr(n,r,34)^pr(n,r,39),S=n&o^n&s^o&s,I=r&i^r&a^i&a;y=0|p,m=0|g,p=0|h,g=0|d,h=0|l,d=0|f,({h:l,l:f}=gr(0|c,0|u,0|E,0|A)),c=0|s,u=0|a,s=0|o,a=0|i,o=0|n,i=0|r;const P=yr(A,k,I);n=mr(P,E,x,S),r=0|P}({h:n,l:r}=gr(0|this.Ah,0|this.Al,0|n,0|r)),({h:o,l:i}=gr(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:a}=gr(0|this.Ch,0|this.Cl,0|s,0|a)),({h:c,l:u}=gr(0|this.Dh,0|this.Dl,0|c,0|u)),({h:l,l:f}=gr(0|this.Eh,0|this.El,0|l,0|f)),({h,l:d}=gr(0|this.Fh,0|this.Fl,0|h,0|d)),({h:p,l:g}=gr(0|this.Gh,0|this.Gl,0|p,0|g)),({h:y,l:m}=gr(0|this.Hh,0|this.Hl,0|y,0|m)),this.set(n,r,o,i,s,a,c,u,l,f,h,d,p,g,y,m)}roundClean(){Dn(Cr,Or)}destroy(){Dn(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class Br extends Nr{constructor(){super(48),this.Ah=0|rr[0],this.Al=0|rr[1],this.Bh=0|rr[2],this.Bl=0|rr[3],this.Ch=0|rr[4],this.Cl=0|rr[5],this.Dh=0|rr[6],this.Dl=0|rr[7],this.Eh=0|rr[8],this.El=0|rr[9],this.Fh=0|rr[10],this.Fl=0|rr[11],this.Gh=0|rr[12],this.Gl=0|rr[13],this.Hh=0|rr[14],this.Hl=0|rr[15]}}const Tr=Zn(()=>new kr),Rr=Zn(()=>new Nr),Ur=Zn(()=>new Br);class Dr extends Qn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Tn(e);const n=$n(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),Dn(o)}update(e){return Rn(this),this.iHash.update(e),this}digestInto(e){Rn(this),Bn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Lr=(e,t,n)=>new Dr(e,t).update(n).digest();Lr.create=(e,t)=>new Dr(e,t);const Fr=BigInt(0),_r=BigInt(1);function Mr(e,t=""){if("boolean"!=typeof e)throw new Error((t&&`"${t}"`)+"expected boolean, got type="+typeof e);return e}function jr(e,t,n=""){const r=On(e),o=e?.length,i=void 0!==t;if(!r||i&&o!==t)throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(i?` of length ${t}`:"")+", got "+(r?`length=${o}`:"type="+typeof e));return e}function Gr(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function Hr(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?Fr:BigInt("0x"+e)}function zr(e){return Hr(zn(e))}function Kr(e){return Bn(e),Hr(zn(Uint8Array.from(e).reverse()))}function Vr(e,t){return Vn(e.toString(16).padStart(2*t,"0"))}function Wr(e,t){return Vr(e,t).reverse()}function $r(e,t,n){let r;if("string"==typeof t)try{r=Vn(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!On(t))throw new Error(e+" must be hex string or Uint8Array");r=Uint8Array.from(t)}const o=r.length;if("number"==typeof n&&o!==n)throw new Error(e+" of length "+n+" expected, got "+o);return r}const qr=e=>"bigint"==typeof e&&Fr<=e;function Jr(e){let t;for(t=0;e>Fr;e>>=_r,t+=1);return t}const Qr=e=>(_r<<BigInt(e))-_r;function Zr(e,t,n={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function r(t,n,r){const o=e[t];if(r&&void 0===o)return;const i=typeof o;if(i!==n||null===o)throw new Error(`param "${t}" is invalid: expected ${n}, got ${i}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function Yr(e){const t=new WeakMap;return(n,...r)=>{const o=t.get(n);if(void 0!==o)return o;const i=e(n,...r);return t.set(n,i),i}}const Xr=BigInt(0),eo=BigInt(1),to=BigInt(2),no=BigInt(3),ro=BigInt(4),oo=BigInt(5),io=BigInt(7),so=BigInt(8),ao=BigInt(9),co=BigInt(16);function uo(e,t){const n=e%t;return n>=Xr?n:t+n}function lo(e,t,n){let r=e;for(;t-- >Xr;)r*=r,r%=n;return r}function fo(e,t){if(e===Xr)throw new Error("invert: expected non-zero number");if(t<=Xr)throw new Error("invert: expected positive modulus, got "+t);let n=uo(e,t),r=t,o=Xr,i=eo,s=eo,a=Xr;for(;n!==Xr;){const e=r/n,t=r%n,c=o-s*e,u=i-a*e;r=n,n=t,o=s,i=a,s=c,a=u}if(r!==eo)throw new Error("invert: does not exist");return uo(o,t)}function ho(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function po(e,t){const n=(e.ORDER+eo)/ro,r=e.pow(t,n);return ho(e,r,t),r}function go(e,t){const n=(e.ORDER-oo)/so,r=e.mul(t,to),o=e.pow(r,n),i=e.mul(t,o),s=e.mul(e.mul(i,to),o),a=e.mul(i,e.sub(s,e.ONE));return ho(e,a,t),a}function yo(e){if(e<no)throw new Error("sqrt is not defined for small field");let t=e-eo,n=0;for(;t%to===Xr;)t/=to,n++;let r=to;const o=Eo(e);for(;1===bo(o,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return po;let i=o.pow(r,t);const s=(t+eo)/to;return function(e,r){if(e.is0(r))return r;if(1!==bo(e,r))throw new Error("Cannot find square root");let o=n,a=e.mul(e.ONE,i),c=e.pow(r,t),u=e.pow(r,s);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===o)throw new Error("Cannot find square root");const r=eo<<BigInt(o-t-1),i=e.pow(a,r);o=t,a=e.sqr(i),c=e.mul(c,a),u=e.mul(u,i)}return u}}const mo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function wo(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),o=t.reduce((t,n,o)=>e.is0(n)?t:(r[o]=t,e.mul(t,n)),e.ONE),i=e.inv(o);return t.reduceRight((t,n,o)=>e.is0(n)?t:(r[o]=e.mul(t,r[o]),e.mul(t,n)),i),r}function bo(e,t){const n=(e.ORDER-eo)/to,r=e.pow(t,n),o=e.eql(r,e.ONE),i=e.eql(r,e.ZERO),s=e.eql(r,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function vo(e,t){void 0!==t&&Nn(t);const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Eo(e,t,n=!1,r={}){if(e<=Xr)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i,s,a=!1;if("object"==typeof t&&null!=t){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const e=t;e.BITS&&(o=e.BITS),e.sqrt&&(i=e.sqrt),"boolean"==typeof e.isLE&&(n=e.isLE),"boolean"==typeof e.modFromBytes&&(a=e.modFromBytes),s=e.allowedLengths}else"number"==typeof t&&(o=t),r.sqrt&&(i=r.sqrt);const{nBitLength:c,nByteLength:u}=vo(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const f=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:u,MASK:Qr(c),ZERO:Xr,ONE:eo,allowedLengths:s,create:t=>uo(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return Xr<=t&&t<e},is0:e=>e===Xr,isValidNot0:e=>!f.is0(e)&&f.isValid(e),isOdd:e=>(e&eo)===eo,neg:t=>uo(-t,e),eql:(e,t)=>e===t,sqr:t=>uo(t*t,e),add:(t,n)=>uo(t+n,e),sub:(t,n)=>uo(t-n,e),mul:(t,n)=>uo(t*n,e),pow:(e,t)=>function(e,t,n){if(n<Xr)throw new Error("invalid exponent, negatives unsupported");if(n===Xr)return e.ONE;if(n===eo)return t;let r=e.ONE,o=t;for(;n>Xr;)n&eo&&(r=e.mul(r,o)),o=e.sqr(o),n>>=eo;return r}(f,e,t),div:(t,n)=>uo(t*fo(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>fo(t,e),sqrt:i||(t=>{return l||(l=(n=e)%ro===no?po:n%so===oo?go:n%co===ao?function(e){const t=Eo(e),n=yo(e),r=n(t,t.neg(t.ONE)),o=n(t,r),i=n(t,t.neg(r)),s=(e+io)/co;return(e,t)=>{let n=e.pow(t,s),a=e.mul(n,r);const c=e.mul(n,o),u=e.mul(n,i),l=e.eql(e.sqr(a),t),f=e.eql(e.sqr(c),t);n=e.cmov(n,a,l),a=e.cmov(u,c,f);const h=e.eql(e.sqr(a),t),d=e.cmov(n,a,h);return ho(e,d,t),d}}(n):yo(n)),l(f,t);var n}),toBytes:e=>n?Wr(e,u):Vr(e,u),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>u)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);const e=new Uint8Array(u);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+t.length);let o=n?Kr(t):zr(t);if(a&&(o=uo(o,e)),!r&&!f.isValid(o))throw new Error("invalid field element: outside of range 0..ORDER");return o},invertBatch:e=>wo(f,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(f)}function Ao(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function xo(e){const t=Ao(e);return t+Math.ceil(t/2)}const ko=BigInt(0),So=BigInt(1);function Io(e,t){const n=t.negate();return e?n:t}function Po(e,t){const n=wo(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Co(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Oo(e,t){Co(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:Qr(e),maxNumber:n,shiftBy:BigInt(e)}}function No(e,t,n){const{windowSize:r,mask:o,maxNumber:i,shiftBy:s}=n;let a=Number(e&o),c=e>>s;a>r&&(a-=i,c+=So);const u=t*r;return{nextN:c,offset:u+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:u}}const Bo=new WeakMap,To=new WeakMap;function Ro(e){return To.get(e)||1}function Uo(e){if(e!==ko)throw new Error("invalid wNAF")}class Do{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>ko;)t&So&&(n=n.add(r)),r=r.double(),t>>=So;return n}precomputeWindow(e,t){const{windows:n,windowSize:r}=Oo(t,this.bits),o=[];let i=e,s=i;for(let e=0;e<n;e++){s=i,o.push(s);for(let e=1;e<r;e++)s=s.add(i),o.push(s);i=s.double()}return o}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,o=this.BASE;const i=Oo(e,this.bits);for(let e=0;e<i.windows;e++){const{nextN:s,offset:a,isZero:c,isNeg:u,isNegF:l,offsetF:f}=No(n,e,i);n=s,c?o=o.add(Io(l,t[f])):r=r.add(Io(u,t[a]))}return Uo(n),{p:r,f:o}}wNAFUnsafe(e,t,n,r=this.ZERO){const o=Oo(e,this.bits);for(let e=0;e<o.windows&&n!==ko;e++){const{nextN:i,offset:s,isZero:a,isNeg:c}=No(n,e,o);if(n=i,!a){const e=t[s];r=r.add(c?e.negate():e)}}return Uo(n),r}getPrecomputes(e,t,n){let r=Bo.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Bo.set(t,r))),r}cached(e,t,n){const r=Ro(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){const o=Ro(e);return 1===o?this._unsafeLadder(e,t,r):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),t,r)}createCache(e,t){Co(t,this.bits),To.set(e,t),Bo.delete(e)}hasCache(e){return 1!==Ro(e)}}function Lo(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){Zr(e,mo.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return Eo(e,{isLE:n})}const Fo=(e,t)=>(e+(e>=0?t:-t)/Ko)/t;function _o(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Mo(e,t){const n={};for(let r of Object.keys(t))n[r]=void 0===e[r]?t[r]:e[r];return Mr(n.lowS,"lowS"),Mr(n.prehash,"prehash"),void 0!==n.format&&_o(n.format),n}class jo extends Error{constructor(e=""){super(e)}}const Go={Err:jo,_tlv:{encode:(e,t)=>{const{Err:n}=Go;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");const r=t.length/2,o=Gr(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");const i=r>127?Gr(o.length/2|128):"";return Gr(e)+i+o+t},decode(e,t){const{Err:n}=Go;let r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");const o=t[r++];let i=0;if(128&o){const e=127&o;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)i=i<<8|e;if(r+=e,i<128)throw new n("tlv.decode(long): not minimal encoding")}else i=o;const s=t.subarray(r,r+i);if(s.length!==i)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+i)}}},_int:{encode(e){const{Err:t}=Go;if(e<Ho)throw new t("integer: negative integers are not allowed");let n=Gr(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){const{Err:t}=Go;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return zr(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=Go,o=$r("signature",e),{v:i,l:s}=r.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,i),{v:u,l}=r.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(e){const{_tlv:t,_int:n}=Go,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},Ho=BigInt(0),zo=BigInt(1),Ko=BigInt(2),Vo=BigInt(3),Wo=BigInt(4);function $o(e,t){const{BYTES:n}=e;let r;if("bigint"==typeof t)r=t;else{let o=$r("private key",t);try{r=e.fromBytes(o)}catch(e){throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function qo(e,t={}){const n=function(e,t,n={},r){if(void 0===r&&(r="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const n=t[e];if(!("bigint"==typeof n&&n>ko))throw new Error(`CURVE.${e} must be positive bigint`)}const o=Lo(t.p,n.Fp,r),i=Lo(t.n,n.Fn,r),s=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const e of s)if(!o.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:i}}("weierstrass",e,t),{Fp:r,Fn:o}=n;let i=n.CURVE;const{h:s,n:a}=i;Zr(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=t;if(c&&(!r.is0(i.a)||"bigint"!=typeof c.beta||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Qo(r,o);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const f=t.toBytes||function(e,t,n){const{x:o,y:i}=t.toAffine(),s=r.toBytes(o);return Mr(n,"isCompressed"),n?(l(),Jn(Jo(!r.isOdd(i)),s)):Jn(Uint8Array.of(4),s,r.toBytes(i))},h=t.fromBytes||function(e){jr(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:n}=u,o=e.length,i=e[0],s=e.subarray(1);if(o!==t||2!==i&&3!==i){if(o===n&&4===i){const e=r.BYTES,t=r.fromBytes(s.subarray(0,e)),n=r.fromBytes(s.subarray(e,2*e));if(!p(t,n))throw new Error("bad point: is not on curve");return{x:t,y:n}}throw new Error(`bad point: got length ${o}, expected compressed=${t} or uncompressed=${n}`)}{const e=r.fromBytes(s);if(!r.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=d(e);let n;try{n=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}return l(),!(1&~i)!==r.isOdd(n)&&(n=r.neg(n)),{x:e,y:n}}};function d(e){const t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,i.a)),i.b)}function p(e,t){const n=r.sqr(t),o=d(e);return r.eql(n,o)}if(!p(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const g=r.mul(r.pow(i.a,Vo),Wo),y=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(g,y)))throw new Error("bad curve params: a or b");function m(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function w(e){if(!(e instanceof x))throw new Error("ProjectivePoint expected")}function b(e){if(!c||!c.basises)throw new Error("no endo");return function(e,t,n){const[[r,o],[i,s]]=t,a=Fo(s*e,n),c=Fo(-o*e,n);let u=e-a*r-c*i,l=-a*o-c*s;const f=u<Ho,h=l<Ho;f&&(u=-u),h&&(l=-l);const d=Qr(Math.ceil(Jr(n)/2))+zo;if(u<Ho||u>=d||l<Ho||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:u,k2neg:h,k2:l}}(e,c.basises,o.ORDER)}const v=Yr((e,t)=>{const{X:n,Y:o,Z:i}=e;if(r.eql(i,r.ONE))return{x:n,y:o};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(i));const a=r.mul(n,t),c=r.mul(o,t),u=r.mul(i,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw new Error("invZ was invalid");return{x:a,y:c}}),E=Yr(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:n,y:o}=e.toAffine();if(!r.isValid(n)||!r.isValid(o))throw new Error("bad point: x or y not field elements");if(!p(n,o))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(e,t,n,o,i){return n=new x(r.mul(n.X,e),n.Y,n.Z),t=Io(o,t),n=Io(i,n),t.add(n)}class x{constructor(e,t,n){this.X=m("x",e),this.Y=m("y",t,!0),this.Z=m("z",n),Object.freeze(this)}static CURVE(){return i}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof x)throw new Error("projective point not allowed");return r.is0(t)&&r.is0(n)?x.ZERO:new x(t,n,r.ONE)}static fromBytes(e){const t=x.fromAffine(h(jr(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return x.fromBytes($r("pointHex",e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return S.createCache(this,e),t||this.multiply(Vo),this}assertValidity(){E(this)}hasEvenY(){const{y:e}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(e)}equals(e){w(e);const{X:t,Y:n,Z:o}=this,{X:i,Y:s,Z:a}=e,c=r.eql(r.mul(t,a),r.mul(i,o)),u=r.eql(r.mul(n,a),r.mul(s,o));return c&&u}negate(){return new x(this.X,r.neg(this.Y),this.Z)}double(){const{a:e,b:t}=i,n=r.mul(t,Vo),{X:o,Y:s,Z:a}=this;let c=r.ZERO,u=r.ZERO,l=r.ZERO,f=r.mul(o,o),h=r.mul(s,s),d=r.mul(a,a),p=r.mul(o,s);return p=r.add(p,p),l=r.mul(o,a),l=r.add(l,l),c=r.mul(e,l),u=r.mul(n,d),u=r.add(c,u),c=r.sub(h,u),u=r.add(h,u),u=r.mul(c,u),c=r.mul(p,c),l=r.mul(n,l),d=r.mul(e,d),p=r.sub(f,d),p=r.mul(e,p),p=r.add(p,l),l=r.add(f,f),f=r.add(l,f),f=r.add(f,d),f=r.mul(f,p),u=r.add(u,f),d=r.mul(s,a),d=r.add(d,d),f=r.mul(d,p),c=r.sub(c,f),l=r.mul(d,h),l=r.add(l,l),l=r.add(l,l),new x(c,u,l)}add(e){w(e);const{X:t,Y:n,Z:o}=this,{X:s,Y:a,Z:c}=e;let u=r.ZERO,l=r.ZERO,f=r.ZERO;const h=i.a,d=r.mul(i.b,Vo);let p=r.mul(t,s),g=r.mul(n,a),y=r.mul(o,c),m=r.add(t,n),b=r.add(s,a);m=r.mul(m,b),b=r.add(p,g),m=r.sub(m,b),b=r.add(t,o);let v=r.add(s,c);return b=r.mul(b,v),v=r.add(p,y),b=r.sub(b,v),v=r.add(n,o),u=r.add(a,c),v=r.mul(v,u),u=r.add(g,y),v=r.sub(v,u),f=r.mul(h,b),u=r.mul(d,y),f=r.add(u,f),u=r.sub(g,f),f=r.add(g,f),l=r.mul(u,f),g=r.add(p,p),g=r.add(g,p),y=r.mul(h,y),b=r.mul(d,b),g=r.add(g,y),y=r.sub(p,y),y=r.mul(h,y),b=r.add(b,y),p=r.mul(g,b),l=r.add(l,p),p=r.mul(v,b),u=r.mul(m,u),u=r.sub(u,p),p=r.mul(m,g),f=r.mul(v,f),f=r.add(f,p),new x(u,l,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(x.ZERO)}multiply(e){const{endo:n}=t;if(!o.isValidNot0(e))throw new Error("invalid scalar: out of range");let r,i;const s=e=>S.cached(this,e,e=>Po(x,e));if(n){const{k1neg:t,k1:o,k2neg:a,k2:c}=b(e),{p:u,f:l}=s(o),{p:f,f:h}=s(c);i=l.add(h),r=A(n.beta,u,f,t,a)}else{const{p:t,f:n}=s(e);r=t,i=n}return Po(x,[r,i])[0]}multiplyUnsafe(e){const{endo:n}=t,r=this;if(!o.isValid(e))throw new Error("invalid scalar: out of range");if(e===Ho||r.is0())return x.ZERO;if(e===zo)return r;if(S.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:o,k2neg:i,k2:s}=b(e),{p1:a,p2:c}=function(e,t,n,r){let o=t,i=e.ZERO,s=e.ZERO;for(;n>ko||r>ko;)n&So&&(i=i.add(o)),r&So&&(s=s.add(o)),o=o.double(),n>>=So,r>>=So;return{p1:i,p2:s}}(x,r,o,s);return A(n.beta,a,c,t,i)}return S.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return v(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===zo||(e?e(x,this):S.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===zo?this:e?e(x,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return Mr(e,"isCompressed"),this.assertValidity(),f(x,this,e)}toHex(e=!0){return zn(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return Po(x,e)}static msm(e,t){return function(e,t,n,r){(function(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})})(n,e),function(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}(r,t);const o=n.length,i=r.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");const s=e.ZERO,a=Jr(BigInt(o));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=Qr(c),l=new Array(Number(u)+1).fill(s);let f=s;for(let e=Math.floor((t.BITS-1)/c)*c;e>=0;e-=c){l.fill(s);for(let t=0;t<i;t++){const o=r[t],i=Number(o>>BigInt(e)&u);l[i]=l[i].add(n[t])}let t=s;for(let e=l.length-1,n=s;e>0;e--)n=n.add(l[e]),t=t.add(n);if(f=f.add(t),0!==e)for(let e=0;e<c;e++)f=f.double()}return f}(x,o,e,t)}static fromPrivateKey(e){return x.BASE.multiply($o(o,e))}}x.BASE=new x(i.Gx,i.Gy,r.ONE),x.ZERO=new x(r.ZERO,r.ONE,r.ZERO),x.Fp=r,x.Fn=o;const k=o.BITS,S=new Do(x,t.endo?Math.ceil(k/2):k);return x.BASE.precompute(8),x}function Jo(e){return Uint8Array.of(e?2:3)}function Qo(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Zo(e,t,n={}){Tn(t),Zr(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Yn,o=n.hmac||((e,...n)=>Lr(t,e,Jn(...n))),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d}=function(e,t={}){const{Fn:n}=e,r=t.randomBytes||Yn,o=Object.assign(Qo(e.Fp,n),{seed:xo(n.ORDER)});function i(e){try{return!!$o(n,e)}catch(e){return!1}}function s(e=r(o.seed)){return function(e,t,n=!1){const r=e.length,o=Ao(t),i=xo(t);if(r<16||r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);const s=uo(n?Kr(e):zr(e),t-eo)+eo;return n?Wr(s,o):Vr(s,o)}(jr(e,o.seed,"seed"),n.ORDER)}function a(t,r=!0){return e.BASE.multiply($o(n,t)).toBytes(r)}function c(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const{secretKey:r,publicKey:i,publicKeyUncompressed:s}=o;if(n.allowedLengths||r===i)return;const a=$r("key",t).length;return a===i||a===s}const u={isValidSecretKey:i,isValidPublicKey:function(t,n){const{publicKey:r,publicKeyUncompressed:i}=o;try{const o=t.length;return!(!0===n&&o!==r||!1===n&&o!==i||!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:s,isValidPrivateKey:i,randomPrivateKey:s,normPrivateKeyToScalar:e=>$o(n,e),precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};return Object.freeze({getPublicKey:a,getSharedSecret:function(t,r,o=!0){if(!0===c(t))throw new Error("first arg must be private key");if(!1===c(r))throw new Error("second arg must be public key");const i=$o(n,t);return e.fromHex(r).multiply(i).toBytes(o)},keygen:function(e){const t=s(e);return{secretKey:t,publicKey:a(t)}},Point:e,utils:u,lengths:o})}(e,n),p={prehash:!1,lowS:"boolean"==typeof n.lowS&&n.lowS,format:void 0,extraEntropy:!1},g="compact";function y(e){return e>a>>zo}function m(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}class w{constructor(e,t,n){this.r=m("r",e),this.s=m("s",t),null!=n&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=g){let n;if(function(e,t){_o(t);const n=d.signature;jr(e,"compact"===t?n:"recovered"===t?n+1:void 0,`${t} signature`)}(e,t),"der"===t){const{r:t,s:n}=Go.toSig(jr(e));return new w(t,n)}"recovered"===t&&(n=e[0],t="compact",e=e.subarray(1));const r=s.BYTES,o=e.subarray(0,r),i=e.subarray(r,2*r);return new w(s.fromBytes(o),s.fromBytes(i),n)}static fromHex(e,t){return this.fromBytes(Vn(e),t)}addRecoveryBit(e){return new w(this.r,this.s,e)}recoverPublicKey(t){const n=i.ORDER,{r,s:o,recovery:c}=this;if(null==c||![0,1,2,3].includes(c))throw new Error("recovery id invalid");if(a*Ko<n&&c>1)throw new Error("recovery id is ambiguous for h>1 curve");const u=2===c||3===c?r+a:r;if(!i.isValid(u))throw new Error("recovery id 2 or 3 invalid");const l=i.toBytes(u),f=e.fromBytes(Jn(Jo(!(1&c)),l)),h=s.inv(u),d=v($r("msgHash",t)),p=s.create(-d*h),g=s.create(o*h),y=e.BASE.multiplyUnsafe(p).add(f.multiplyUnsafe(g));if(y.is0())throw new Error("point at infinify");return y.assertValidity(),y}hasHighS(){return y(this.s)}toBytes(e=g){if(_o(e),"der"===e)return Vn(Go.hexFromSig(this));const t=s.toBytes(this.r),n=s.toBytes(this.s);if("recovered"===e){if(null==this.recovery)throw new Error("recovery bit must be present");return Jn(Uint8Array.of(this.recovery),t,n)}return Jn(t,n)}toHex(e){return zn(this.toBytes(e))}assertValidity(){}static fromCompact(e){return w.fromBytes($r("sig",e),"compact")}static fromDER(e){return w.fromBytes($r("sig",e),"der")}normalizeS(){return this.hasHighS()?new w(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return zn(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return zn(this.toBytes("compact"))}}const b=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=zr(e),n=8*e.length-c;return n>0?t>>BigInt(n):t},v=n.bits2int_modN||function(e){return s.create(b(e))},E=Qr(c);function A(e){return function(e,t,n,r){if(!function(e,t,n){return qr(e)&&qr(t)&&qr(n)&&t<=e&&e<n}(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}("num < 2^"+c,e,Ho,E),s.toBytes(e)}function x(e,n){return jr(e,void 0,"message"),n?jr(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d,Point:e,sign:function(n,i,a={}){n=$r("message",n);const{seed:c,k2sig:u}=function(t,n,o){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");const{lowS:i,prehash:a,extraEntropy:c}=Mo(o,p);t=x(t,a);const u=v(t),l=$o(s,n),f=[A(l),A(u)];if(null!=c&&!1!==c){const e=!0===c?r(d.secretKey):c;f.push($r("extraEntropy",e))}const h=Jn(...f),g=u;return{seed:h,k2sig:function(t){const n=b(t);if(!s.isValidNot0(n))return;const r=s.inv(n),o=e.BASE.multiply(n).toAffine(),a=s.create(o.x);if(a===Ho)return;const c=s.create(r*s.create(g+a*l));if(c===Ho)return;let u=(o.x===a?0:2)|Number(o.y&zo),f=c;return i&&y(c)&&(f=s.neg(c),u^=1),new w(a,f,u)}}}(n,i,a),l=function(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");const r=e=>new Uint8Array(e),o=e=>Uint8Array.of(e);let i=r(e),s=r(e),a=0;const c=()=>{i.fill(1),s.fill(0),a=0},u=(...e)=>n(s,i,...e),l=(e=r(0))=>{s=u(o(0),e),i=u(),0!==e.length&&(s=u(o(1),e),i=u())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){i=u();const t=i.slice();n.push(t),e+=i.length}return Jn(...n)};return(e,t)=>{let n;for(c(),l(e);!(n=t(f()));)l();return c(),n}}(t.outputLen,s.BYTES,o);return l(c,u)},verify:function(t,n,r,o={}){const{lowS:i,prehash:a,format:c}=Mo(o,p);if(r=$r("publicKey",r),n=x($r("message",n),a),"strict"in o)throw new Error("options.strict was renamed to lowS");const u=void 0===c?function(e){let t;const n="string"==typeof e||On(e),r=!n&&null!==e&&"object"==typeof e&&"bigint"==typeof e.r&&"bigint"==typeof e.s;if(!n&&!r)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)t=new w(e.r,e.s);else if(n){try{t=w.fromBytes($r("sig",e),"der")}catch(e){if(!(e instanceof Go.Err))throw e}if(!t)try{t=w.fromBytes($r("sig",e),"compact")}catch(e){return!1}}return t||!1}(t):w.fromBytes($r("sig",t),c);if(!1===u)return!1;try{const t=e.fromBytes(r);if(i&&u.hasHighS())return!1;const{r:o,s:a}=u,c=v(n),l=s.inv(a),f=s.create(c*l),h=s.create(o*l),d=e.BASE.multiplyUnsafe(f).add(t.multiplyUnsafe(h));return!d.is0()&&s.create(d.x)===o}catch(e){return!1}},recoverPublicKey:function(e,t,n={}){const{prehash:r}=Mo(n,p);return t=x(t,r),w.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:w,hash:t})}function Yo(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:o}=function(e){const{CURVE:t,curveOpts:n}=function(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:Eo(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}(e);return function(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,vo(n.Fn.ORDER,n.Fn.BITS))})}(e,Zo(qo(t,n),r,o))}function Xo(e,t){const n=t=>Yo({...e,hash:t});return{...n(t),create:n}}const ei={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},ti={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},ni={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},ri=Eo(ei.p),oi=Eo(ti.p),ii=Eo(ni.p),si=Xo({...ei,Fp:ri,lowS:!1},Tr);Xo({...ti,Fp:oi,lowS:!1},Ur),Xo({...ni,Fp:ii,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},Rr);const ai=si,ci={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ui={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},li=BigInt(2),fi=Eo(ci.p,{sqrt:function(e){const t=ci.p,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=lo(l,n,t)*l%t,h=lo(f,n,t)*l%t,d=lo(h,li,t)*u%t,p=lo(d,o,t)*d%t,g=lo(p,i,t)*p%t,y=lo(g,a,t)*g%t,m=lo(y,c,t)*y%t,w=lo(m,a,t)*g%t,b=lo(w,n,t)*l%t,v=lo(b,s,t)*p%t,E=lo(v,r,t)*u%t,A=lo(E,li,t);if(!fi.eql(fi.sqr(A),e))throw new Error("Cannot find square root");return A}}),hi=Xo({...ci,Fp:fi,lowS:!0,endo:ui},Tr),di=Tr;const pi=BigInt(0),gi=BigInt(1),yi=BigInt(2),mi=BigInt(7),wi=BigInt(256),bi=BigInt(113),vi=[],Ei=[],Ai=[];for(let e=0,t=gi,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],vi.push(2*(5*r+n)),Ei.push((e+1)*(e+2)/2%64);let o=pi;for(let e=0;e<7;e++)t=(t<<gi^(t>>mi)*bi)%wi,t&yi&&(o^=gi<<(gi<<BigInt(e))-gi);Ai.push(o)}const xi=cr(Ai,!0),ki=xi[0],Si=xi[1],Ii=(e,t,n)=>n>32?((e,t,n)=>t<<n-32|e>>>64-n)(e,t,n):((e,t,n)=>e<<n|t>>>32-n)(e,t,n),Pi=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);class Ci extends Qn{constructor(e,t,n,r=!1,o=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=o,Nn(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var i;this.state=new Uint8Array(200),this.state32=(i=this.state,new Uint32Array(i.buffer,i.byteOffset,Math.floor(i.byteLength/4)))}clone(){return this._cloneInto()}keccak(){jn(this.state32),function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,o=(t+2)%10,i=n[o],s=n[o+1],a=Ii(i,s,1)^n[r],c=Pi(i,s,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],o=e[3];for(let n=0;n<24;n++){const r=Ei[n],i=Ii(t,o,r),s=Pi(t,o,r),a=vi[n];t=e[a],o=e[a+1],e[a]=i,e[a+1]=s}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=ki[r],e[1]^=Si[r]}Dn(n)}(this.state32,this.rounds),jn(this.state32),this.posOut=0,this.pos=0}update(e){Rn(this),Bn(e=$n(e));const{blockLen:t,state:n}=this,r=e.length;for(let o=0;o<r;){const i=Math.min(t-this.pos,r-o);for(let t=0;t<i;t++)n[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){Rn(this,!1),Bn(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,o=e.length;r<o;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,o-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Nn(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Un(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,Dn(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:o,enableXOF:i}=this;return e||(e=new Ci(t,n,r,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const Oi=(()=>{return e=1,t=136,n=32,Zn(()=>new Ci(t,e,n));var e,t,n})(),Ni=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Bi=(()=>Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)))(),Ti=(()=>Bi.map(e=>(9*e+5)%16))(),Ri=(()=>{const e=[[Bi],[Ti]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Ni[e]));return e})(),Ui=(()=>Ri[0])(),Di=(()=>Ri[1])(),Li=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),Fi=Ui.map((e,t)=>e.map(e=>Li[t][e])),_i=Di.map((e,t)=>e.map(e=>Li[t][e])),Mi=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),ji=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Gi(e,t,n,r){return 0===e?t^n^r:1===e?t&n|~t&r:2===e?(t|~n)^r:3===e?t&r|n&~r:t^(n|~r)}const Hi=new Uint32Array(16);class zi extends tr{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:n,h3:r,h4:o}=this;return[e,t,n,r,o]}set(e,t,n,r,o){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|o}process(e,t){for(let n=0;n<16;n++,t+=4)Hi[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,o=0|this.h1,i=o,s=0|this.h2,a=s,c=0|this.h3,u=c,l=0|this.h4,f=l;for(let e=0;e<5;e++){const t=4-e,h=Mi[e],d=ji[e],p=Ui[e],g=Di[e],y=Fi[e],m=_i[e];for(let t=0;t<16;t++){const r=_n(n+Gi(e,o,s,c)+Hi[p[t]]+h,y[t])+l|0;n=l,l=c,c=0|_n(s,10),s=o,o=r}for(let e=0;e<16;e++){const n=_n(r+Gi(t,i,a,u)+Hi[g[e]]+d,m[e])+f|0;r=f,f=u,u=0|_n(a,10),a=i,i=n}}this.set(this.h1+s+u|0,this.h2+c+f|0,this.h3+l+r|0,this.h4+n+i|0,this.h0+o+a|0)}roundClean(){Dn(Hi)}destroy(){this.destroyed=!0,Dn(this.buffer),this.set(0,0,0,0,0)}}const Ki=Zn(()=>new zi);var Vi=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},Wi=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},$i=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s};function qi(e,t){return Vi(this,arguments,void 0,function(e,t,n){var r,o,i,s,a,c,u,l,f,h,d,p,g,y,m,w,b,v,E,A,x,k,S,I=this;return void 0===n&&(n={}),Wi(this,function(P){switch(P.label){case 0:if(r=new TextEncoder,o=e?"string"==typeof e?r.encode(Zi(e)):e:crypto.getRandomValues(new Uint8Array(32)),i=t?(Array.isArray(t)?t:[t]).map(function(e){return Zi(e.toString())}):[],s=r.encode(i.join("|")),(a=new Uint8Array(o.length+s.length)).set(o),a.set(s,o.length),a.length<16)throw new Error("Insufficient input entropy (".concat(a.length,")"));return c="v1",u={},l=n.includeP256,f=void 0===l||l,h=n.includeSecp256k1Bitcoin,d=void 0===h||h,p=n.includeSecp256k1Ethereum,g=void 0===p||p,f?(y=[{label:"signing",type:"pub/priv"},{label:"encryption",type:"epub/epriv"}],[4,Promise.all(y.map(function(e){return Vi(I,[e],void 0,function(e){var t,n,o=e.label;return Wi(this,function(e){switch(e.label){case 0:return t=r.encode("".concat(o,"-").concat(c)),[4,Yi(a,t)];case 1:if(n=e.sent(),!ai.utils.isValidPrivateKey(n))throw new Error("Invalid private key for ".concat(o));return[2,{pub:Qi(ai.getPublicKey(n,!1)),priv:Ji(n)}]}})})}))]):[3,2];case 1:m=$i.apply(void 0,[P.sent(),2]),w=m[0],b=m[1],u.pub=w.pub,u.priv=w.priv,u.epub=b.pub,u.epriv=b.priv,P.label=2;case 2:return d?(v=r.encode("secp256k1-bitcoin-".concat(c)),[4,Yi(a,v)]):[3,4];case 3:if(E=P.sent(),!hi.utils.isValidPrivateKey(E))throw new Error("Invalid secp256k1 private key for Bitcoin");A=hi.getPublicKey(E,!0),u.secp256k1Bitcoin={privateKey:es(E),publicKey:es(A),address:ns(A)},P.label=4;case 4:return g?(x=r.encode("secp256k1-ethereum-".concat(c)),[4,Yi(a,x)]):[3,6];case 5:if(k=P.sent(),!hi.utils.isValidPrivateKey(k))throw new Error("Invalid secp256k1 private key for Ethereum");S=hi.getPublicKey(k,!1),u.secp256k1Ethereum={privateKey:"0x"+es(k),publicKey:"0x"+es(S),address:(C=S,O=C.slice(1),N=Oi(O),B=N.slice(-20),"0x"+es(B))},P.label=6;case 6:return[2,u]}var C,O,N,B})})}function Ji(e){for(var t=[],n=0;n<e.length;n++)t.push(String.fromCharCode(e[n]));return btoa(t.join("")).replace(/\//g,"_").replace(/=/g,"").replace(/\+/g,"-")}function Qi(e){if(4!==e[0])throw new Error("Invalid uncompressed public key format");return[Ji(e.slice(1,33)),Ji(e.slice(33,65))].join(".")}function Zi(e){return e.normalize("NFC").trim()}function Yi(e,t){return Vi(this,arguments,void 0,function(e,t,n){var r,o,i,s;return void 0===n&&(n=3e5),Wi(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,crypto.subtle.importKey("raw",e,{name:"PBKDF2"},!1,["deriveBits"])];case 1:return r=a.sent(),[4,crypto.subtle.deriveBits({name:"PBKDF2",salt:t,iterations:n,hash:"SHA-256"},r,256)];case 2:return o=a.sent(),[2,Xi(new Uint8Array(o))];case 3:return a.sent(),i=e instanceof Uint8Array?e:new Uint8Array(e),s=function(e,t,n,r){const{c:o,dkLen:i,DK:s,PRF:a,PRFSalt:c}=function(e,t,n,r){Tn(e);const o=function(e,t){if(void 0!==t&&"[object Object]"!=={}.toString.call(t))throw new Error("options should be object or undefined");return Object.assign({dkLen:32,asyncTick:10},t)}(0,r),{c:i,dkLen:s,asyncTick:a}=o;if(Nn(i),Nn(s),Nn(a),i<1)throw new Error("iterations (c) should be >= 1");const c=qn(t),u=qn(n),l=new Uint8Array(s),f=Lr.create(e,c),h=f._cloneInto().update(u);return{c:i,dkLen:s,asyncTick:a,DK:l,PRF:f,PRFSalt:h}}(e,t,n,r);let u;const l=new Uint8Array(4),f=Ln(l),h=new Uint8Array(a.outputLen);for(let e=1,t=0;t<i;e++,t+=a.outputLen){const n=s.subarray(t,t+a.outputLen);f.setInt32(0,e,!1),(u=c._cloneInto(u)).update(l).digestInto(h),n.set(h.subarray(0,n.length));for(let e=1;e<o;e++){a._cloneInto(u).update(h).digestInto(h);for(let e=0;e<n.length;e++)n[e]^=h[e]}}return function(e,t,n,r,o){return e.destroy(),t.destroy(),r&&r.destroy(),Dn(o),n}(a,c,s,u,h)}(di,i,t,{c:n,dkLen:32}),[2,Xi(s)];case 4:return[2]}})})}function Xi(e){e.every(function(e){return 0===e})&&(e[0]=1);for(var t=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,186,174,220,230]),n=!0,r=0;r<32;r++){if(e[r]<t[r]){n=!1;break}if(e[r]>t[r])break}return n&&(e[31]=229),(e.every(function(e){return 0===e})||e.every(function(e){return 1===e}))&&(e.fill(0),e[0]=1,e[31]=255),e}function es(e){return Array.from(e).map(function(e){return e.toString(16).padStart(2,"0")}).join("")}var ts="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function ns(e){var t=di(e),n=Ki(t),r=new Uint8Array(21);r[0]=0,r.set(n,1);var o=di(di(r)),i=new Uint8Array(25);return i.set(r),i.set(o.slice(0,4),21),function(e){if(0===e.length)return"";for(var t=0,n=0;n<e.length&&0===e[n];n++)t++;var r=[0];for(n=t;n<e.length;n++){for(var o=e[n],i=0;i<r.length;i++)o+=r[i]<<8,r[i]=o%58,o=o/58|0;for(;o>0;)r.push(o%58),o=o/58|0}var s="";for(n=0;n<t;n++)s+=ts[0];for(n=r.length-1;n>=0;n--)s+=ts[r[n]];return s}(i)}const rs="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function os(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function is(e,...t){if(!((n=e)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function ss(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");os(e.outputLen),os(e.blockLen)}function as(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function cs(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function us(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ls(e,t){return e<<32-t|e>>>t}function fs(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}function hs(e){return"string"==typeof e&&(e=fs(e)),is(e),e}function ds(e){return"string"==typeof e&&(e=fs(e)),is(e),e}class ps{}function gs(e){const t=t=>e().update(hs(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}class ys extends ps{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ss(e);const n=hs(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),cs(o)}update(e){return as(this),this.iHash.update(e),this}digestInto(e){as(this),is(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const ms=(e,t,n)=>new ys(e,t).update(n).digest();function ws(e,t,n){return e&t^~e&n}function bs(e,t,n){return e&t^e&n^t&n}ms.create=(e,t)=>new ys(e,t);class vs extends ps{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=us(this.buffer)}update(e){as(this),is(e=hs(e));const{view:t,buffer:n,blockLen:r}=this,o=e.length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=us(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){as(this),function(e,t){is(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,cs(this.buffer.subarray(i)),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=us(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const Es=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),As=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),xs=BigInt(2**32-1),ks=BigInt(32);function Ss(e,t=!1){return t?{h:Number(e&xs),l:Number(e>>ks&xs)}:{h:0|Number(e>>ks&xs),l:0|Number(e&xs)}}const Is=(e,t,n)=>e>>>n,Ps=(e,t,n)=>e<<32-n|t>>>n,Cs=(e,t,n)=>e>>>n|t<<32-n,Os=(e,t,n)=>e<<32-n|t>>>n,Ns=(e,t,n)=>e<<64-n|t>>>n-32,Bs=(e,t,n)=>e>>>n-32|t<<64-n;function Ts(e,t,n,r){const o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:0|o}}const Rs=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Us=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Ds=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Ls=(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,Fs=(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0),_s=(e,t,n,r,o,i)=>t+n+r+o+i+(e/2**32|0)|0,Ms=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),js=new Uint32Array(64);class Gs extends vs{constructor(e=32){super(64,e,8,!1),this.A=0|Es[0],this.B=0|Es[1],this.C=0|Es[2],this.D=0|Es[3],this.E=0|Es[4],this.F=0|Es[5],this.G=0|Es[6],this.H=0|Es[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)js[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=js[e-15],n=js[e-2],r=ls(t,7)^ls(t,18)^t>>>3,o=ls(n,17)^ls(n,19)^n>>>10;js[e]=o+js[e-7]+r+js[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(ls(s,6)^ls(s,11)^ls(s,25))+ws(s,a,c)+Ms[e]+js[e]|0,l=(ls(n,2)^ls(n,13)^ls(n,22))+bs(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){cs(js)}destroy(){this.set(0,0,0,0,0,0,0,0),cs(this.buffer)}}const Hs=(()=>function(e,t=!1){const n=e.length;let r=new Uint32Array(n),o=new Uint32Array(n);for(let i=0;i<n;i++){const{h:n,l:s}=Ss(e[i],t);[r[i],o[i]]=[n,s]}return[r,o]}(["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(e=>BigInt(e))))(),zs=(()=>Hs[0])(),Ks=(()=>Hs[1])(),Vs=new Uint32Array(80),Ws=new Uint32Array(80);class $s extends vs{constructor(e=64){super(128,e,16,!1),this.Ah=0|As[0],this.Al=0|As[1],this.Bh=0|As[2],this.Bl=0|As[3],this.Ch=0|As[4],this.Cl=0|As[5],this.Dh=0|As[6],this.Dl=0|As[7],this.Eh=0|As[8],this.El=0|As[9],this.Fh=0|As[10],this.Fl=0|As[11],this.Gh=0|As[12],this.Gl=0|As[13],this.Hh=0|As[14],this.Hl=0|As[15]}get(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:o,Cl:i,Dh:s,Dl:a,Eh:c,El:u,Fh:l,Fl:f,Gh:h,Gl:d,Hh:p,Hl:g}=this;return[e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g]}set(e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|o,this.Cl=0|i,this.Dh=0|s,this.Dl=0|a,this.Eh=0|c,this.El=0|u,this.Fh=0|l,this.Fl=0|f,this.Gh=0|h,this.Gl=0|d,this.Hh=0|p,this.Hl=0|g}process(e,t){for(let n=0;n<16;n++,t+=4)Vs[n]=e.getUint32(t),Ws[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|Vs[e-15],n=0|Ws[e-15],r=Cs(t,n,1)^Cs(t,n,8)^Is(t,0,7),o=Os(t,n,1)^Os(t,n,8)^Ps(t,n,7),i=0|Vs[e-2],s=0|Ws[e-2],a=Cs(i,s,19)^Ns(i,s,61)^Is(i,0,6),c=Os(i,s,19)^Bs(i,s,61)^Ps(i,s,6),u=Ds(o,c,Ws[e-7],Ws[e-16]),l=Ls(u,r,a,Vs[e-7],Vs[e-16]);Vs[e]=0|l,Ws[e]=0|u}let{Ah:n,Al:r,Bh:o,Bl:i,Ch:s,Cl:a,Dh:c,Dl:u,Eh:l,El:f,Fh:h,Fl:d,Gh:p,Gl:g,Hh:y,Hl:m}=this;for(let e=0;e<80;e++){const t=Cs(l,f,14)^Cs(l,f,18)^Ns(l,f,41),w=Os(l,f,14)^Os(l,f,18)^Bs(l,f,41),b=l&h^~l&p,v=Fs(m,w,f&d^~f&g,Ks[e],Ws[e]),E=_s(v,y,t,b,zs[e],Vs[e]),A=0|v,x=Cs(n,r,28)^Ns(n,r,34)^Ns(n,r,39),k=Os(n,r,28)^Bs(n,r,34)^Bs(n,r,39),S=n&o^n&s^o&s,I=r&i^r&a^i&a;y=0|p,m=0|g,p=0|h,g=0|d,h=0|l,d=0|f,({h:l,l:f}=Ts(0|c,0|u,0|E,0|A)),c=0|s,u=0|a,s=0|o,a=0|i,o=0|n,i=0|r;const P=Rs(A,k,I);n=Us(P,E,x,S),r=0|P}({h:n,l:r}=Ts(0|this.Ah,0|this.Al,0|n,0|r)),({h:o,l:i}=Ts(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:a}=Ts(0|this.Ch,0|this.Cl,0|s,0|a)),({h:c,l:u}=Ts(0|this.Dh,0|this.Dl,0|c,0|u)),({h:l,l:f}=Ts(0|this.Eh,0|this.El,0|l,0|f)),({h,l:d}=Ts(0|this.Fh,0|this.Fl,0|h,0|d)),({h:p,l:g}=Ts(0|this.Gh,0|this.Gl,0|p,0|g)),({h:y,l:m}=Ts(0|this.Hh,0|this.Hl,0|y,0|m)),this.set(n,r,o,i,s,a,c,u,l,f,h,d,p,g,y,m)}roundClean(){cs(Vs,Ws)}destroy(){cs(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const qs=gs(()=>new Gs),Js=gs(()=>new $s);function Qs(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Zs(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function Ys(e){if("function"!=typeof e)throw new Error("function expected");return!0}function Xs(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function ea(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function ta(e){if(!Array.isArray(e))throw new Error("array expected")}function na(e,t){if(!Zs(!0,t))throw new Error(`${e}: array of strings expected`)}function ra(e,t){if(!Zs(!1,t))throw new Error(`${e}: array of numbers expected`)}function oa(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function ia(e){const t="string"==typeof e?e.split(""):e,n=t.length;na("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(ta(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(ta(t),t.map(t=>{Xs("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function sa(e=""){return Xs("join",e),{encode:t=>(na("join.decode",t),t.join(e)),decode:t=>(Xs("join.decode",t),t.split(e))}}function aa(e,t="="){return ea(e),Xs("padding",t),{encode(n){for(na("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){na("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding");return n.slice(0,r)}}}function ca(e){return Ys(e),{encode:e=>e,decode:t=>e(t)}}function ua(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(ta(e),!e.length)return[];let r=0;const o=[],i=Array.from(e,e=>{if(ea(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=i.length;for(;;){let e=0,a=!0;for(let o=r;o<s;o++){const s=i[o],c=t*e,u=c+s;if(!Number.isSafeInteger(u)||c/t!==e||u-s!==c)throw new Error("convertRadix: carry overflow");const l=u/n;e=u%n;const f=Math.floor(l);if(i[o]=f,!Number.isSafeInteger(f)||f*n+e!==u)throw new Error("convertRadix: carry overflow");a&&(f?a=!1:r=o)}if(o.push(e),a)break}for(let t=0;t<e.length-1&&0===e[t];t++)o.push(0);return o.reverse()}const la=(e,t)=>0===t?e:la(t,e%t),fa=(e,t)=>e+(t-la(e,t)),ha=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function da(e,t,n,r){if(ta(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(fa(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${fa(t,n)}`);let o=0,i=0;const s=ha[t],a=ha[n]-1,c=[];for(const r of e){if(ea(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<<t|r,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=ha[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<<n-i&a,!r&&i>=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}function pa(e){return ea(e),{encode:t=>{if(!Qs(t))throw new Error("radix.encode input should be Uint8Array");return ua(Array.from(t),256,e)},decode:t=>(ra("radix.decode",t),Uint8Array.from(ua(t,e,256)))}}function ga(e,t=!1){if(ea(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(fa(8,e)>32||fa(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Qs(n))throw new Error("radix2.encode input should be Uint8Array");return da(Array.from(n),8,e,!t)},decode:n=>(ra("radix2.decode",n),Uint8Array.from(da(n,e,8,t)))}}function ya(e){return Ys(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const ma={alphabet:ia,chain:oa,checksum:function(e,t){return ea(e),Ys(t),{encode(n){if(!Qs(n))throw new Error("checksum.encode: input should be Uint8Array");const r=t(n).slice(0,e),o=new Uint8Array(n.length+e);return o.set(n),o.set(r,n.length),o},decode(n){if(!Qs(n))throw new Error("checksum.decode: input should be Uint8Array");const r=n.slice(0,-e),o=n.slice(-e),i=t(r).slice(0,e);for(let t=0;t<e;t++)if(i[t]!==o[t])throw new Error("Invalid checksum");return r}}},convertRadix:ua,convertRadix2:da,radix:pa,radix2:ga,join:sa,padding:aa},wa=(oa(ga(4),ia("0123456789ABCDEF"),sa("")),oa(ga(5),ia("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),aa(5),sa("")),oa(ga(5),ia("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),sa("")),oa(ga(5),ia("0123456789ABCDEFGHIJKLMNOPQRSTUV"),aa(5),sa("")),oa(ga(5),ia("0123456789ABCDEFGHIJKLMNOPQRSTUV"),sa("")),oa(ga(5),ia("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),sa(""),ca(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()),ba=(wa||oa(ga(6),ia("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),aa(6),sa("")),oa(ga(6),ia("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),sa("")),wa||oa(ga(6),ia("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),aa(6),sa("")),oa(ga(6),ia("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),sa("")),e=>oa(pa(58),ia(e),sa(""))),va=(ba("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),ba("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),ba("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),oa(ia("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),sa(""))),Ea=[996825010,642813549,513874426,1027748829,705979059];function Aa(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Ea.length;e++)1==(t>>e&1)&&(n^=Ea[e]);return n}function xa(e,t,n=1){const r=e.length;let o=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);o=Aa(o)^n>>5}o=Aa(o);for(let t=0;t<r;t++)o=Aa(o)^31&e.charCodeAt(t);for(let e of t)o=Aa(o)^e;for(let e=0;e<6;e++)o=Aa(o);return o^=n,va.encode(da([o%ha[30]],30,5,!1))}function ka(e){const t="bech32"===e?1:734539939,n=ga(5),r=n.decode,o=n.encode,i=ya(r);function s(e,n,r=90){Xs("bech32.encode prefix",e),Qs(n)&&(n=Array.from(n)),ra("bech32.encode",n);const o=e.length;if(0===o)throw new TypeError(`Invalid prefix length ${o}`);const i=o+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);const s=e.toLowerCase(),a=xa(s,n,t);return`${s}1${va.encode(n)}${a}`}function a(e,n=90){Xs("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);const o=e.toLowerCase();if(e!==o&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=o.lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const s=o.slice(0,i),a=o.slice(i+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const c=va.decode(a).slice(0,-6),u=xa(s,c,t);if(!a.endsWith(u))throw new Error(`Invalid checksum in ${e}: expected "${u}"`);return{prefix:s,words:c}}return{encode:s,decode:a,encodeFromBytes:function(e,t){return s(e,o(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:ya(a),fromWords:r,fromWordsUnsafe:i,toWords:o}}function Sa(e){if("string"!=typeof e)throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function Ia(e){const t=Sa(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}function Pa(e){is(e,16,20,24,28,32)}ka("bech32"),ka("bech32m"),(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)()||oa(ga(4),ia("0123456789abcdef"),sa(""),ca(e=>{if("string"!=typeof e||e.length%2!=0)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const Ca=e=>{const t=8-e.length/4;return new Uint8Array([qs(e)[0]>>t<<t])};function Oa(e){if(!Array.isArray(e)||2048!==e.length||"string"!=typeof e[0])throw new Error("Wordlist: expected array of 2048 strings");return e.forEach(e=>{if("string"!=typeof e)throw new Error("wordlist: non-string element: "+e)}),ma.chain(ma.checksum(1,Ca),ma.radix2(11,!0),ma.alphabet(e))}function Na(e,t=""){return function(e,t,n){const{c:r,dkLen:o,DK:i,PRF:s,PRFSalt:a}=function(e,t,n,r){ss(e);const o=function(e,t){if(void 0!==t&&"[object Object]"!=={}.toString.call(t))throw new Error("options should be object or undefined");return Object.assign({dkLen:32,asyncTick:10},t)}(0,r),{c:i,dkLen:s,asyncTick:a}=o;if(os(i),os(s),os(a),i<1)throw new Error("iterations (c) should be >= 1");const c=ds(t),u=ds(n),l=new Uint8Array(s),f=ms.create(e,c),h=f._cloneInto().update(u);return{c:i,dkLen:s,asyncTick:a,DK:l,PRF:f,PRFSalt:h}}(e,t,n,{c:2048,dkLen:64});let c;const u=new Uint8Array(4),l=us(u),f=new Uint8Array(s.outputLen);for(let e=1,t=0;t<o;e++,t+=s.outputLen){const n=i.subarray(t,t+s.outputLen);l.setInt32(0,e,!1),(c=a._cloneInto(c)).update(u).digestInto(f),n.set(f.subarray(0,n.length));for(let e=1;e<r;e++){s._cloneInto(c).update(f).digestInto(f);for(let e=0;e<n.length;e++)n[e]^=f[e]}}return function(e,t,n,r,o){return e.destroy(),t.destroy(),r&&r.destroy(),cs(o),n}(s,a,i,c,f)}(Js,Ia(e).nfkd,(e=>Sa("mnemonic"+e))(t))}const Ba="abandon\nability\nable\nabout\nabove\nabsent\nabsorb\nabstract\nabsurd\nabuse\naccess\naccident\naccount\naccuse\nachieve\nacid\nacoustic\nacquire\nacross\nact\naction\nactor\nactress\nactual\nadapt\nadd\naddict\naddress\nadjust\nadmit\nadult\nadvance\nadvice\naerobic\naffair\nafford\nafraid\nagain\nage\nagent\nagree\nahead\naim\nair\nairport\naisle\nalarm\nalbum\nalcohol\nalert\nalien\nall\nalley\nallow\nalmost\nalone\nalpha\nalready\nalso\nalter\nalways\namateur\namazing\namong\namount\namused\nanalyst\nanchor\nancient\nanger\nangle\nangry\nanimal\nankle\nannounce\nannual\nanother\nanswer\nantenna\nantique\nanxiety\nany\napart\napology\nappear\napple\napprove\napril\narch\narctic\narea\narena\nargue\narm\narmed\narmor\narmy\naround\narrange\narrest\narrive\narrow\nart\nartefact\nartist\nartwork\nask\naspect\nassault\nasset\nassist\nassume\nasthma\nathlete\natom\nattack\nattend\nattitude\nattract\nauction\naudit\naugust\naunt\nauthor\nauto\nautumn\naverage\navocado\navoid\nawake\naware\naway\nawesome\nawful\nawkward\naxis\nbaby\nbachelor\nbacon\nbadge\nbag\nbalance\nbalcony\nball\nbamboo\nbanana\nbanner\nbar\nbarely\nbargain\nbarrel\nbase\nbasic\nbasket\nbattle\nbeach\nbean\nbeauty\nbecause\nbecome\nbeef\nbefore\nbegin\nbehave\nbehind\nbelieve\nbelow\nbelt\nbench\nbenefit\nbest\nbetray\nbetter\nbetween\nbeyond\nbicycle\nbid\nbike\nbind\nbiology\nbird\nbirth\nbitter\nblack\nblade\nblame\nblanket\nblast\nbleak\nbless\nblind\nblood\nblossom\nblouse\nblue\nblur\nblush\nboard\nboat\nbody\nboil\nbomb\nbone\nbonus\nbook\nboost\nborder\nboring\nborrow\nboss\nbottom\nbounce\nbox\nboy\nbracket\nbrain\nbrand\nbrass\nbrave\nbread\nbreeze\nbrick\nbridge\nbrief\nbright\nbring\nbrisk\nbroccoli\nbroken\nbronze\nbroom\nbrother\nbrown\nbrush\nbubble\nbuddy\nbudget\nbuffalo\nbuild\nbulb\nbulk\nbullet\nbundle\nbunker\nburden\nburger\nburst\nbus\nbusiness\nbusy\nbutter\nbuyer\nbuzz\ncabbage\ncabin\ncable\ncactus\ncage\ncake\ncall\ncalm\ncamera\ncamp\ncan\ncanal\ncancel\ncandy\ncannon\ncanoe\ncanvas\ncanyon\ncapable\ncapital\ncaptain\ncar\ncarbon\ncard\ncargo\ncarpet\ncarry\ncart\ncase\ncash\ncasino\ncastle\ncasual\ncat\ncatalog\ncatch\ncategory\ncattle\ncaught\ncause\ncaution\ncave\nceiling\ncelery\ncement\ncensus\ncentury\ncereal\ncertain\nchair\nchalk\nchampion\nchange\nchaos\nchapter\ncharge\nchase\nchat\ncheap\ncheck\ncheese\nchef\ncherry\nchest\nchicken\nchief\nchild\nchimney\nchoice\nchoose\nchronic\nchuckle\nchunk\nchurn\ncigar\ncinnamon\ncircle\ncitizen\ncity\ncivil\nclaim\nclap\nclarify\nclaw\nclay\nclean\nclerk\nclever\nclick\nclient\ncliff\nclimb\nclinic\nclip\nclock\nclog\nclose\ncloth\ncloud\nclown\nclub\nclump\ncluster\nclutch\ncoach\ncoast\ncoconut\ncode\ncoffee\ncoil\ncoin\ncollect\ncolor\ncolumn\ncombine\ncome\ncomfort\ncomic\ncommon\ncompany\nconcert\nconduct\nconfirm\ncongress\nconnect\nconsider\ncontrol\nconvince\ncook\ncool\ncopper\ncopy\ncoral\ncore\ncorn\ncorrect\ncost\ncotton\ncouch\ncountry\ncouple\ncourse\ncousin\ncover\ncoyote\ncrack\ncradle\ncraft\ncram\ncrane\ncrash\ncrater\ncrawl\ncrazy\ncream\ncredit\ncreek\ncrew\ncricket\ncrime\ncrisp\ncritic\ncrop\ncross\ncrouch\ncrowd\ncrucial\ncruel\ncruise\ncrumble\ncrunch\ncrush\ncry\ncrystal\ncube\nculture\ncup\ncupboard\ncurious\ncurrent\ncurtain\ncurve\ncushion\ncustom\ncute\ncycle\ndad\ndamage\ndamp\ndance\ndanger\ndaring\ndash\ndaughter\ndawn\nday\ndeal\ndebate\ndebris\ndecade\ndecember\ndecide\ndecline\ndecorate\ndecrease\ndeer\ndefense\ndefine\ndefy\ndegree\ndelay\ndeliver\ndemand\ndemise\ndenial\ndentist\ndeny\ndepart\ndepend\ndeposit\ndepth\ndeputy\nderive\ndescribe\ndesert\ndesign\ndesk\ndespair\ndestroy\ndetail\ndetect\ndevelop\ndevice\ndevote\ndiagram\ndial\ndiamond\ndiary\ndice\ndiesel\ndiet\ndiffer\ndigital\ndignity\ndilemma\ndinner\ndinosaur\ndirect\ndirt\ndisagree\ndiscover\ndisease\ndish\ndismiss\ndisorder\ndisplay\ndistance\ndivert\ndivide\ndivorce\ndizzy\ndoctor\ndocument\ndog\ndoll\ndolphin\ndomain\ndonate\ndonkey\ndonor\ndoor\ndose\ndouble\ndove\ndraft\ndragon\ndrama\ndrastic\ndraw\ndream\ndress\ndrift\ndrill\ndrink\ndrip\ndrive\ndrop\ndrum\ndry\nduck\ndumb\ndune\nduring\ndust\ndutch\nduty\ndwarf\ndynamic\neager\neagle\nearly\nearn\nearth\neasily\neast\neasy\necho\necology\neconomy\nedge\nedit\neducate\neffort\negg\neight\neither\nelbow\nelder\nelectric\nelegant\nelement\nelephant\nelevator\nelite\nelse\nembark\nembody\nembrace\nemerge\nemotion\nemploy\nempower\nempty\nenable\nenact\nend\nendless\nendorse\nenemy\nenergy\nenforce\nengage\nengine\nenhance\nenjoy\nenlist\nenough\nenrich\nenroll\nensure\nenter\nentire\nentry\nenvelope\nepisode\nequal\nequip\nera\nerase\nerode\nerosion\nerror\nerupt\nescape\nessay\nessence\nestate\neternal\nethics\nevidence\nevil\nevoke\nevolve\nexact\nexample\nexcess\nexchange\nexcite\nexclude\nexcuse\nexecute\nexercise\nexhaust\nexhibit\nexile\nexist\nexit\nexotic\nexpand\nexpect\nexpire\nexplain\nexpose\nexpress\nextend\nextra\neye\neyebrow\nfabric\nface\nfaculty\nfade\nfaint\nfaith\nfall\nfalse\nfame\nfamily\nfamous\nfan\nfancy\nfantasy\nfarm\nfashion\nfat\nfatal\nfather\nfatigue\nfault\nfavorite\nfeature\nfebruary\nfederal\nfee\nfeed\nfeel\nfemale\nfence\nfestival\nfetch\nfever\nfew\nfiber\nfiction\nfield\nfigure\nfile\nfilm\nfilter\nfinal\nfind\nfine\nfinger\nfinish\nfire\nfirm\nfirst\nfiscal\nfish\nfit\nfitness\nfix\nflag\nflame\nflash\nflat\nflavor\nflee\nflight\nflip\nfloat\nflock\nfloor\nflower\nfluid\nflush\nfly\nfoam\nfocus\nfog\nfoil\nfold\nfollow\nfood\nfoot\nforce\nforest\nforget\nfork\nfortune\nforum\nforward\nfossil\nfoster\nfound\nfox\nfragile\nframe\nfrequent\nfresh\nfriend\nfringe\nfrog\nfront\nfrost\nfrown\nfrozen\nfruit\nfuel\nfun\nfunny\nfurnace\nfury\nfuture\ngadget\ngain\ngalaxy\ngallery\ngame\ngap\ngarage\ngarbage\ngarden\ngarlic\ngarment\ngas\ngasp\ngate\ngather\ngauge\ngaze\ngeneral\ngenius\ngenre\ngentle\ngenuine\ngesture\nghost\ngiant\ngift\ngiggle\nginger\ngiraffe\ngirl\ngive\nglad\nglance\nglare\nglass\nglide\nglimpse\nglobe\ngloom\nglory\nglove\nglow\nglue\ngoat\ngoddess\ngold\ngood\ngoose\ngorilla\ngospel\ngossip\ngovern\ngown\ngrab\ngrace\ngrain\ngrant\ngrape\ngrass\ngravity\ngreat\ngreen\ngrid\ngrief\ngrit\ngrocery\ngroup\ngrow\ngrunt\nguard\nguess\nguide\nguilt\nguitar\ngun\ngym\nhabit\nhair\nhalf\nhammer\nhamster\nhand\nhappy\nharbor\nhard\nharsh\nharvest\nhat\nhave\nhawk\nhazard\nhead\nhealth\nheart\nheavy\nhedgehog\nheight\nhello\nhelmet\nhelp\nhen\nhero\nhidden\nhigh\nhill\nhint\nhip\nhire\nhistory\nhobby\nhockey\nhold\nhole\nholiday\nhollow\nhome\nhoney\nhood\nhope\nhorn\nhorror\nhorse\nhospital\nhost\nhotel\nhour\nhover\nhub\nhuge\nhuman\nhumble\nhumor\nhundred\nhungry\nhunt\nhurdle\nhurry\nhurt\nhusband\nhybrid\nice\nicon\nidea\nidentify\nidle\nignore\nill\nillegal\nillness\nimage\nimitate\nimmense\nimmune\nimpact\nimpose\nimprove\nimpulse\ninch\ninclude\nincome\nincrease\nindex\nindicate\nindoor\nindustry\ninfant\ninflict\ninform\ninhale\ninherit\ninitial\ninject\ninjury\ninmate\ninner\ninnocent\ninput\ninquiry\ninsane\ninsect\ninside\ninspire\ninstall\nintact\ninterest\ninto\ninvest\ninvite\ninvolve\niron\nisland\nisolate\nissue\nitem\nivory\njacket\njaguar\njar\njazz\njealous\njeans\njelly\njewel\njob\njoin\njoke\njourney\njoy\njudge\njuice\njump\njungle\njunior\njunk\njust\nkangaroo\nkeen\nkeep\nketchup\nkey\nkick\nkid\nkidney\nkind\nkingdom\nkiss\nkit\nkitchen\nkite\nkitten\nkiwi\nknee\nknife\nknock\nknow\nlab\nlabel\nlabor\nladder\nlady\nlake\nlamp\nlanguage\nlaptop\nlarge\nlater\nlatin\nlaugh\nlaundry\nlava\nlaw\nlawn\nlawsuit\nlayer\nlazy\nleader\nleaf\nlearn\nleave\nlecture\nleft\nleg\nlegal\nlegend\nleisure\nlemon\nlend\nlength\nlens\nleopard\nlesson\nletter\nlevel\nliar\nliberty\nlibrary\nlicense\nlife\nlift\nlight\nlike\nlimb\nlimit\nlink\nlion\nliquid\nlist\nlittle\nlive\nlizard\nload\nloan\nlobster\nlocal\nlock\nlogic\nlonely\nlong\nloop\nlottery\nloud\nlounge\nlove\nloyal\nlucky\nluggage\nlumber\nlunar\nlunch\nluxury\nlyrics\nmachine\nmad\nmagic\nmagnet\nmaid\nmail\nmain\nmajor\nmake\nmammal\nman\nmanage\nmandate\nmango\nmansion\nmanual\nmaple\nmarble\nmarch\nmargin\nmarine\nmarket\nmarriage\nmask\nmass\nmaster\nmatch\nmaterial\nmath\nmatrix\nmatter\nmaximum\nmaze\nmeadow\nmean\nmeasure\nmeat\nmechanic\nmedal\nmedia\nmelody\nmelt\nmember\nmemory\nmention\nmenu\nmercy\nmerge\nmerit\nmerry\nmesh\nmessage\nmetal\nmethod\nmiddle\nmidnight\nmilk\nmillion\nmimic\nmind\nminimum\nminor\nminute\nmiracle\nmirror\nmisery\nmiss\nmistake\nmix\nmixed\nmixture\nmobile\nmodel\nmodify\nmom\nmoment\nmonitor\nmonkey\nmonster\nmonth\nmoon\nmoral\nmore\nmorning\nmosquito\nmother\nmotion\nmotor\nmountain\nmouse\nmove\nmovie\nmuch\nmuffin\nmule\nmultiply\nmuscle\nmuseum\nmushroom\nmusic\nmust\nmutual\nmyself\nmystery\nmyth\nnaive\nname\nnapkin\nnarrow\nnasty\nnation\nnature\nnear\nneck\nneed\nnegative\nneglect\nneither\nnephew\nnerve\nnest\nnet\nnetwork\nneutral\nnever\nnews\nnext\nnice\nnight\nnoble\nnoise\nnominee\nnoodle\nnormal\nnorth\nnose\nnotable\nnote\nnothing\nnotice\nnovel\nnow\nnuclear\nnumber\nnurse\nnut\noak\nobey\nobject\noblige\nobscure\nobserve\nobtain\nobvious\noccur\nocean\noctober\nodor\noff\noffer\noffice\noften\noil\nokay\nold\nolive\nolympic\nomit\nonce\none\nonion\nonline\nonly\nopen\nopera\nopinion\noppose\noption\norange\norbit\norchard\norder\nordinary\norgan\norient\noriginal\norphan\nostrich\nother\noutdoor\nouter\noutput\noutside\noval\noven\nover\nown\nowner\noxygen\noyster\nozone\npact\npaddle\npage\npair\npalace\npalm\npanda\npanel\npanic\npanther\npaper\nparade\nparent\npark\nparrot\nparty\npass\npatch\npath\npatient\npatrol\npattern\npause\npave\npayment\npeace\npeanut\npear\npeasant\npelican\npen\npenalty\npencil\npeople\npepper\nperfect\npermit\nperson\npet\nphone\nphoto\nphrase\nphysical\npiano\npicnic\npicture\npiece\npig\npigeon\npill\npilot\npink\npioneer\npipe\npistol\npitch\npizza\nplace\nplanet\nplastic\nplate\nplay\nplease\npledge\npluck\nplug\nplunge\npoem\npoet\npoint\npolar\npole\npolice\npond\npony\npool\npopular\nportion\nposition\npossible\npost\npotato\npottery\npoverty\npowder\npower\npractice\npraise\npredict\nprefer\nprepare\npresent\npretty\nprevent\nprice\npride\nprimary\nprint\npriority\nprison\nprivate\nprize\nproblem\nprocess\nproduce\nprofit\nprogram\nproject\npromote\nproof\nproperty\nprosper\nprotect\nproud\nprovide\npublic\npudding\npull\npulp\npulse\npumpkin\npunch\npupil\npuppy\npurchase\npurity\npurpose\npurse\npush\nput\npuzzle\npyramid\nquality\nquantum\nquarter\nquestion\nquick\nquit\nquiz\nquote\nrabbit\nraccoon\nrace\nrack\nradar\nradio\nrail\nrain\nraise\nrally\nramp\nranch\nrandom\nrange\nrapid\nrare\nrate\nrather\nraven\nraw\nrazor\nready\nreal\nreason\nrebel\nrebuild\nrecall\nreceive\nrecipe\nrecord\nrecycle\nreduce\nreflect\nreform\nrefuse\nregion\nregret\nregular\nreject\nrelax\nrelease\nrelief\nrely\nremain\nremember\nremind\nremove\nrender\nrenew\nrent\nreopen\nrepair\nrepeat\nreplace\nreport\nrequire\nrescue\nresemble\nresist\nresource\nresponse\nresult\nretire\nretreat\nreturn\nreunion\nreveal\nreview\nreward\nrhythm\nrib\nribbon\nrice\nrich\nride\nridge\nrifle\nright\nrigid\nring\nriot\nripple\nrisk\nritual\nrival\nriver\nroad\nroast\nrobot\nrobust\nrocket\nromance\nroof\nrookie\nroom\nrose\nrotate\nrough\nround\nroute\nroyal\nrubber\nrude\nrug\nrule\nrun\nrunway\nrural\nsad\nsaddle\nsadness\nsafe\nsail\nsalad\nsalmon\nsalon\nsalt\nsalute\nsame\nsample\nsand\nsatisfy\nsatoshi\nsauce\nsausage\nsave\nsay\nscale\nscan\nscare\nscatter\nscene\nscheme\nschool\nscience\nscissors\nscorpion\nscout\nscrap\nscreen\nscript\nscrub\nsea\nsearch\nseason\nseat\nsecond\nsecret\nsection\nsecurity\nseed\nseek\nsegment\nselect\nsell\nseminar\nsenior\nsense\nsentence\nseries\nservice\nsession\nsettle\nsetup\nseven\nshadow\nshaft\nshallow\nshare\nshed\nshell\nsheriff\nshield\nshift\nshine\nship\nshiver\nshock\nshoe\nshoot\nshop\nshort\nshoulder\nshove\nshrimp\nshrug\nshuffle\nshy\nsibling\nsick\nside\nsiege\nsight\nsign\nsilent\nsilk\nsilly\nsilver\nsimilar\nsimple\nsince\nsing\nsiren\nsister\nsituate\nsix\nsize\nskate\nsketch\nski\nskill\nskin\nskirt\nskull\nslab\nslam\nsleep\nslender\nslice\nslide\nslight\nslim\nslogan\nslot\nslow\nslush\nsmall\nsmart\nsmile\nsmoke\nsmooth\nsnack\nsnake\nsnap\nsniff\nsnow\nsoap\nsoccer\nsocial\nsock\nsoda\nsoft\nsolar\nsoldier\nsolid\nsolution\nsolve\nsomeone\nsong\nsoon\nsorry\nsort\nsoul\nsound\nsoup\nsource\nsouth\nspace\nspare\nspatial\nspawn\nspeak\nspecial\nspeed\nspell\nspend\nsphere\nspice\nspider\nspike\nspin\nspirit\nsplit\nspoil\nsponsor\nspoon\nsport\nspot\nspray\nspread\nspring\nspy\nsquare\nsqueeze\nsquirrel\nstable\nstadium\nstaff\nstage\nstairs\nstamp\nstand\nstart\nstate\nstay\nsteak\nsteel\nstem\nstep\nstereo\nstick\nstill\nsting\nstock\nstomach\nstone\nstool\nstory\nstove\nstrategy\nstreet\nstrike\nstrong\nstruggle\nstudent\nstuff\nstumble\nstyle\nsubject\nsubmit\nsubway\nsuccess\nsuch\nsudden\nsuffer\nsugar\nsuggest\nsuit\nsummer\nsun\nsunny\nsunset\nsuper\nsupply\nsupreme\nsure\nsurface\nsurge\nsurprise\nsurround\nsurvey\nsuspect\nsustain\nswallow\nswamp\nswap\nswarm\nswear\nsweet\nswift\nswim\nswing\nswitch\nsword\nsymbol\nsymptom\nsyrup\nsystem\ntable\ntackle\ntag\ntail\ntalent\ntalk\ntank\ntape\ntarget\ntask\ntaste\ntattoo\ntaxi\nteach\nteam\ntell\nten\ntenant\ntennis\ntent\nterm\ntest\ntext\nthank\nthat\ntheme\nthen\ntheory\nthere\nthey\nthing\nthis\nthought\nthree\nthrive\nthrow\nthumb\nthunder\nticket\ntide\ntiger\ntilt\ntimber\ntime\ntiny\ntip\ntired\ntissue\ntitle\ntoast\ntobacco\ntoday\ntoddler\ntoe\ntogether\ntoilet\ntoken\ntomato\ntomorrow\ntone\ntongue\ntonight\ntool\ntooth\ntop\ntopic\ntopple\ntorch\ntornado\ntortoise\ntoss\ntotal\ntourist\ntoward\ntower\ntown\ntoy\ntrack\ntrade\ntraffic\ntragic\ntrain\ntransfer\ntrap\ntrash\ntravel\ntray\ntreat\ntree\ntrend\ntrial\ntribe\ntrick\ntrigger\ntrim\ntrip\ntrophy\ntrouble\ntruck\ntrue\ntruly\ntrumpet\ntrust\ntruth\ntry\ntube\ntuition\ntumble\ntuna\ntunnel\nturkey\nturn\nturtle\ntwelve\ntwenty\ntwice\ntwin\ntwist\ntwo\ntype\ntypical\nugly\numbrella\nunable\nunaware\nuncle\nuncover\nunder\nundo\nunfair\nunfold\nunhappy\nuniform\nunique\nunit\nuniverse\nunknown\nunlock\nuntil\nunusual\nunveil\nupdate\nupgrade\nuphold\nupon\nupper\nupset\nurban\nurge\nusage\nuse\nused\nuseful\nuseless\nusual\nutility\nvacant\nvacuum\nvague\nvalid\nvalley\nvalve\nvan\nvanish\nvapor\nvarious\nvast\nvault\nvehicle\nvelvet\nvendor\nventure\nvenue\nverb\nverify\nversion\nvery\nvessel\nveteran\nviable\nvibrant\nvicious\nvictory\nvideo\nview\nvillage\nvintage\nviolin\nvirtual\nvirus\nvisa\nvisit\nvisual\nvital\nvivid\nvocal\nvoice\nvoid\nvolcano\nvolume\nvote\nvoyage\nwage\nwagon\nwait\nwalk\nwall\nwalnut\nwant\nwarfare\nwarm\nwarrior\nwash\nwasp\nwaste\nwater\nwave\nway\nwealth\nweapon\nwear\nweasel\nweather\nweb\nwedding\nweekend\nweird\nwelcome\nwest\nwet\nwhale\nwhat\nwheat\nwheel\nwhen\nwhere\nwhip\nwhisper\nwide\nwidth\nwife\nwild\nwill\nwin\nwindow\nwine\nwing\nwink\nwinner\nwinter\nwire\nwisdom\nwise\nwish\nwitness\nwolf\nwoman\nwonder\nwood\nwool\nword\nwork\nworld\nworry\nworth\nwrap\nwreck\nwrestle\nwrist\nwrite\nwrong\nyard\nyear\nyellow\nyou\nyoung\nyouth\nzebra\nzero\nzone\nzoo".split("\n");function Ta(e){try{return function(e,t){try{!function(e,t){const{words:n}=Ia(e);Pa(Oa(t).decode(n))}(e,t)}catch(e){return!1}return!0}(e,Ba)}catch(e){return!1}}function Ra(e,t){var n=function(e,t){if(!Ta(e))throw new Error("Invalid mnemonic seed phrase");return Na(e,"shogun-".concat(t))}(e,t),r=function(e){return zn(di(e))}(n);return{password:r,seed:n}}var Ua=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Da=function(){return Da=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Da.apply(this,arguments)},La=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},Fa=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},_a={rpName:"Shogun Wallet",timeout:6e4,userVerification:"required",attestation:"none",authenticatorAttachment:void 0,requireResidentKey:!1},Ma=function(e){function t(t,n){var r,o=e.call(this)||this;return o.abortController=null,o.gunInstance=t,o.credential=null,o.config=Da(Da(Da({},_a),n),{rpId:null!==(r=null==n?void 0:n.rpId)&&void 0!==r?r:"undefined"!=typeof window&&window.location&&window.location.hostname?window.location.hostname.split(":")[0]:"localhost"}),o}return Ua(t,e),t.prototype.validateUsername=function(e){if(!e||"string"!=typeof e)throw new Error("Username must be a non-empty string");if(e.length<3||e.length>64)throw new Error("Username must be between ".concat(3," and ").concat(64," characters"));if(!/^[a-zA-Z0-9_-]+$/.test(e))throw new Error("Username can only contain letters, numbers, underscores and hyphens")},t.prototype.createAccount=function(e,t){return La(this,arguments,void 0,function(e,t,n){var r,o,i,s,a,c,u,l;return void 0===n&&(n=!1),Fa(this,function(n){switch(n.label){case 0:n.trys.push([0,5,,6]),this.validateUsername(e),r=3,o=null,i=function(n){var i,a;return Fa(this,function(c){switch(c.label){case 0:return c.trys.push([0,2,,5]),[4,s.generateCredentials(e,t,!1)];case 1:return(i=c.sent()).success?(s.emit(Pn.DEVICE_REGISTERED,{type:Pn.DEVICE_REGISTERED,data:{username:e},timestamp:Date.now()}),[2,{value:i}]):(o=new Error(null!==(l=i.error)&&void 0!==l?l:"Unknown error"),[3,5]);case 2:return a=c.sent(),o=a,n<r?[4,new Promise(function(e){return setTimeout(e,1e3*n)})]:[3,4];case 3:return c.sent(),[2,"continue"];case 4:return[3,5];case 5:return[2]}})},s=this,a=1,n.label=1;case 1:return a<=r?[5,i(a)]:[3,4];case 2:if("object"==typeof(c=n.sent()))return[2,c.value];n.label=3;case 3:return a++,[3,1];case 4:throw o||new Error("Failed to create account after retries");case 5:throw u=n.sent(),this.emit(Pn.ERROR,{type:Pn.ERROR,data:{error:u.message},timestamp:Date.now()}),u;case 6:return[2]}})})},t.prototype.authenticateUser=function(e,t){return La(this,arguments,void 0,function(e,t,n){var r,o,i,s,a,c,u,l,f,h,d,p=this;return void 0===n&&(n={}),Fa(this,function(g){switch(g.label){case 0:if(g.trys.push([0,5,,6]),this.validateUsername(e),!t)return r=new Error("No WebAuthn credentials found for this username"),Ie.handle(xe.WEBAUTHN,"NO_CREDENTIALS",r.message,r),[2,{success:!1,error:r.message}];this.abortAuthentication(),this.abortController=new AbortController,o=n.timeout||this.config.timeout,i=setTimeout(function(){var e;return null===(e=p.abortController)||void 0===e?void 0:e.abort()},o),g.label=1;case 1:return g.trys.push([1,,3,4]),s=this.generateChallenge(e),a={challenge:s,allowCredentials:[],timeout:o,userVerification:n.userVerification||this.config.userVerification,rpId:this.config.rpId},[4,navigator.credentials.get({publicKey:a,signal:this.abortController.signal})];case 2:if(!(c=g.sent()))throw new Error("WebAuthn verification failed");return u=this.generateCredentialsFromSalt(e,t).password,l=this.getDeviceInfo(c.id),f={success:!0,username:e,password:u,credentialId:this.bufferToBase64(c.rawId),deviceInfo:l},this.emit(Pn.AUTHENTICATION_SUCCESS,{type:Pn.AUTHENTICATION_SUCCESS,data:{username:e,deviceInfo:l},timestamp:Date.now()}),[2,f];case 3:return clearTimeout(i),this.abortController=null,[7];case 4:return[3,6];case 5:return h=g.sent(),d=h instanceof Error?h.message:"Unknown WebAuthn error",this.emit(Pn.AUTHENTICATION_FAILED,{type:Pn.AUTHENTICATION_FAILED,data:{username:e,error:d},timestamp:Date.now()}),Ie.handle(xe.WEBAUTHN,"AUTH_ERROR",d,h),[2,{success:!1,error:d}];case 6:return[2]}})})},t.prototype.abortAuthentication=function(){this.abortController&&(this.abortController.abort(),this.abortController=null)},t.prototype.getDeviceInfo=function(e){var t=this.getPlatformInfo();return{deviceId:e,timestamp:Date.now(),name:t.name,platform:t.platform,lastUsed:Date.now()}},t.prototype.getPlatformInfo=function(){if("undefined"==typeof navigator)return{name:"unknown",platform:"unknown"};var e=navigator.platform,t=navigator.userAgent;return/iPhone|iPad|iPod/.test(e)?{name:"iOS Device",platform:e}:/Android/.test(t)?{name:"Android Device",platform:e}:/Win/.test(e)?{name:"Windows Device",platform:e}:/Mac/.test(e)?{name:"Mac Device",platform:e}:/Linux/.test(e)?{name:"Linux Device",platform:e}:{name:"Unknown Device",platform:e}},t.prototype.generateChallenge=function(e){var t=Date.now().toString(),n=this.getRandomBytes(32),r="".concat(e,"-").concat(t,"-").concat(this.uint8ArrayToHex(n));return(new TextEncoder).encode(r)},t.prototype.getRandomBytes=function(e){if("undefined"!=typeof window&&window.crypto)return window.crypto.getRandomValues(new Uint8Array(e));throw new Error("No cryptographic implementation available")},t.prototype.uint8ArrayToHex=function(e){return Array.from(e).map(function(e){return e.toString(16).padStart(2,"0")}).join("")},t.prototype.bufferToBase64=function(e){var t=new Uint8Array(e).reduce(function(e,t){return e+String.fromCharCode(t)},"");return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")},t.prototype.generateCredentialsFromSalt=function(e,t){return{password:sn(ot(e+t))}},t.prototype.isSupported=function(){return"undefined"!=typeof window&&void 0!==window.PublicKeyCredential},t.prototype.createCredential=function(e){return La(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c;return Fa(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),t=crypto.getRandomValues(new Uint8Array(32)),n=(new TextEncoder).encode(e),r={challenge:t,rp:Da({name:this.config.rpName||"Shogun Wallet"},this.config.rpId&&"localhost"!==this.config.rpId&&{id:this.config.rpId}),user:{id:n,name:e,displayName:e},pubKeyCredParams:[{type:"public-key",alg:-7}],timeout:this.config.timeout,attestation:this.config.attestation,authenticatorSelection:{authenticatorAttachment:this.config.authenticatorAttachment,userVerification:this.config.userVerification,requireResidentKey:this.config.requireResidentKey}},[4,navigator.credentials.create({publicKey:r})];case 1:if(!(o=u.sent()))throw new Error("Credential creation failed");return s={id:(i=o).id,rawId:i.rawId,type:i.type,response:{clientDataJSON:i.response.clientDataJSON},getClientExtensionResults:i.getClientExtensionResults},"attestationObject"in i.response&&(s.response.attestationObject=i.response.attestationObject),this.credential=s,[2,s];case 2:throw a=u.sent(),console.error("Detailed error in credential creation:",a),c=a instanceof Error?a.message:"Unknown error",new Error("Error creating credentials: ".concat(c));case 3:return[2]}})})},t.prototype.generateCredentials=function(e,t){return La(this,arguments,void 0,function(e,t,n){var r,o,i,s,a,c,u,l;return void 0===n&&(n=!1),Fa(this,function(t){switch(t.label){case 0:return t.trys.push([0,7,,8]),n?[4,this.verifyCredential(e)]:[3,3];case 1:return(r=t.sent()).success&&r.credentialId?[4,ja(e,r.credentialId)]:[2,{success:!1,username:e,key:void 0,credentialId:"",error:r.error,publicKey:null}];case 2:return a=t.sent(),[2,{success:!0,username:e,key:a,credentialId:r.credentialId,publicKey:null}];case 3:return[4,this.createCredential(e)];case 4:return o=t.sent(),i=o.id,s=null,(null===(l=null==o?void 0:o.response)||void 0===l?void 0:l.getPublicKey)&&(s=o.response.getPublicKey()),[4,ja(e,i)];case 5:return a=t.sent(),[2,{success:!0,username:e,key:a,credentialId:i,publicKey:s}];case 6:return[3,8];case 7:return c=t.sent(),console.error("Error in generateCredentials:",c),u=c instanceof Error?c.message:"Unknown error during WebAuthn operation",[2,{success:!1,username:e,key:void 0,credentialId:"",error:u,publicKey:null}];case 8:return[2]}})})},t.prototype.verifyCredential=function(e){return La(this,void 0,void 0,function(){var t,n,r,o,i;return Fa(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=crypto.getRandomValues(new Uint8Array(32)),n=Da({challenge:t,timeout:this.config.timeout,userVerification:this.config.userVerification},"localhost"!==this.config.rpId&&{rpId:this.config.rpId}),(null===(i=this.credential)||void 0===i?void 0:i.rawId)&&(n.allowCredentials=[{id:this.credential.rawId,type:"public-key"}]),[4,navigator.credentials.get({publicKey:n})];case 1:return(r=s.sent())?[2,{success:!0,credentialId:r.id,username:e}]:[2,{success:!1,error:"Credential verification failed"}];case 2:return o=s.sent(),console.error("Error verifying credentials:",o),[2,{success:!1,error:o instanceof Error?o.message:"Unknown error verifying credentials"}];case 3:return[2]}})})},t.prototype.removeDevice=function(e,t,n){return La(this,void 0,void 0,function(){var e;return Fa(this,function(r){return n&&n.credentials&&n.credentials[t]?((e=Da({},n)).credentials&&delete e.credentials[t],[2,{success:!0,updatedCredentials:e}]):[2,{success:!1}]})})},t.prototype.sign=function(e){return La(this,void 0,void 0,function(){var t,n,r,o,i,s;return Fa(this,function(a){switch(a.label){case 0:return t=JSON.stringify(e),n=ot(t),r=sn(n),o=Ve(r),i={challenge:o,rpId:this.config.rpId,userVerification:this.config.userVerification,timeout:this.config.timeout},(null===(s=this.credential)||void 0===s?void 0:s.rawId)&&(i.allowCredentials=[{id:this.credential.rawId,type:"public-key"}]),[4,navigator.credentials.get({publicKey:i})];case 1:return[2,a.sent()]}})})},t}(Pe);function ja(e,t){return La(this,arguments,void 0,function(e,t,n){var r,o,i,s;return void 0===n&&(n=!1),Fa(this,function(a){switch(a.label){case 0:return n?(r=Ra(t,e),o=r.password,r.seed,[4,qi(o,e,{includeP256:!0})]):[3,2];case 1:case 3:return[2,a.sent()];case 2:return i=In(ot(t)),s="".concat(e,"_").concat(t),[4,qi(i,s,{includeP256:!0})]}})})}"undefined"!=typeof window?window.Webauthn=Ma:void 0!==r.g&&(r.g.Webauthn=Ma);var Ga=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},Ha=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},za=function(e){for(var t=new Uint8Array(e),n=[],r=0;r<t.length;r++)n.push(String.fromCharCode(t[r]));return btoa(n.join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")},Ka=function(){function e(e){this.credentials=new Map,this.webauthn=e||new Ma}return e.prototype.createSigningCredential=function(e){return Ga(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c,u,l,f,h;return Ha(this,function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),[4,navigator.credentials.create({publicKey:{challenge:crypto.getRandomValues(new Uint8Array(32)),rp:{id:"localhost"===window.location.hostname?"localhost":window.location.hostname,name:"Shogun Wallet"},user:{id:(new TextEncoder).encode(e),name:e,displayName:e},pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-25},{type:"public-key",alg:-257}],authenticatorSelection:{userVerification:"preferred"},timeout:6e4,attestation:"none"}})];case 1:if(!(t=d.sent()))throw new Error("Failed to create WebAuthn credential");if(n=t.response,!(r=n.getPublicKey()))throw new Error("Failed to get public key from credential");return o=new Uint8Array(r),i=o.slice(27,59),s=o.slice(59,91),a=za(i),c=za(s),u="".concat(a,".").concat(c),l=In(ot(t.id)),f={id:t.id,rawId:t.rawId,publicKey:{x:a,y:c},pub:u,hashedCredentialId:l},this.credentials.set(t.id,f),[2,f];case 2:throw h=d.sent(),console.error("Error creating signing credential:",h),new Error("Failed to create signing credential: ".concat(h.message));case 3:return[2]}})})},e.prototype.createAuthenticator=function(e){var t=this,n=this.credentials.get(e);if(!n)throw new Error("Credential ".concat(e," not found"));return function(e){return Ga(t,void 0,void 0,function(){var t,r,o,i;return Ha(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=(new TextEncoder).encode(JSON.stringify(e)),r={challenge:t,rpId:"localhost"===window.location.hostname?"localhost":window.location.hostname,userVerification:"preferred",allowCredentials:[{type:"public-key",id:n.rawId}],timeout:6e4},[4,navigator.credentials.get({publicKey:r})];case 1:if(!(o=s.sent()))throw new Error("WebAuthn assertion failed");return[2,o.response];case 2:throw i=s.sent(),console.error("WebAuthn assertion error:",i),i;case 3:return[2]}})})}},e.prototype.createDerivedKeyPair=function(e,t,n){return Ga(this,void 0,void 0,function(){var t,r,o;return Ha(this,function(i){switch(i.label){case 0:if(!(t=this.credentials.get(e)))throw new Error("Credential ".concat(e," not found"));i.label=1;case 1:return i.trys.push([1,3,,4]),[4,qi(t.hashedCredentialId,n,{includeP256:!0})];case 2:return[2,{pub:(r=i.sent()).pub,priv:r.priv,epub:r.epub,epriv:r.epriv}];case 3:throw o=i.sent(),console.error("Error deriving keys from WebAuthn credential:",o),o;case 4:return[2]}})})},e.prototype.createGunUser=function(e,t,n){return Ga(this,void 0,void 0,function(){var r,o,i,s=this;return Ha(this,function(a){switch(a.label){case 0:if(!(r=this.credentials.get(e)))throw new Error("Credential ".concat(e," not found"));a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.createDerivedKeyPair(e,t)];case 2:return o=a.sent(),[2,new Promise(function(t){n.user().create(o,function(i){i.err?n.user().auth(o,function(n){if(n.err)t({success:!1,error:n.err});else{var o=n.pub;r.gunUserPub=o,s.credentials.set(e,r),t({success:!0,userPub:o})}}):n.user().auth(o,function(n){if(n.err)t({success:!1,error:n.err});else{var o=n.pub;r.gunUserPub=o,s.credentials.set(e,r),t({success:!0,userPub:o})}})})})];case 3:return i=a.sent(),console.error("Error creating Gun user:",i),[2,{success:!1,error:i.message}];case 4:return[2]}})})},e.prototype.signWithDerivedKeys=function(e,t,n,r){return Ga(this,void 0,void 0,function(){var o,i,s,a,c,u,l;return Ha(this,function(f){switch(f.label){case 0:return f.trys.push([0,3,,4]),[4,this.createAuthenticator(t)(e)];case 1:return f.sent(),[4,this.createDerivedKeyPair(t,n,r)];case 2:return o=f.sent(),i=JSON.stringify(e),s=di((new TextEncoder).encode(i)),a=function(e){for(e=e.replace(/-/g,"+").replace(/_/g,"/");e.length%4;)e+="=";var t=atob(e);return new Uint8Array(t.split("").map(function(e){return e.charCodeAt(0)}))}(o.priv),c=ai.sign(s,a),u={m:i,s:za(c.toCompactRawBytes())},[2,"SEA"+JSON.stringify(u)];case 3:throw l=f.sent(),console.error("Error signing with derived keys:",l),l;case 4:return[2]}})})},e.prototype.getGunUserPub=function(e){var t=this.credentials.get(e);return null==t?void 0:t.gunUserPub},e.prototype.getHashedCredentialId=function(e){var t=this.credentials.get(e);return null==t?void 0:t.hashedCredentialId},e.prototype.verifyConsistency=function(e,t,n){return Ga(this,void 0,void 0,function(){var r;return Ha(this,function(o){switch(o.label){case 0:return this.credentials.get(e)?[4,this.createDerivedKeyPair(e,t)]:[2,{consistent:!1}];case 1:return r=o.sent(),[2,{consistent:!n||r.pub===n,actualUserPub:r.pub,expectedUserPub:n}]}})})},e.prototype.getCredential=function(e){return this.credentials.get(e)},e.prototype.listCredentials=function(){return Array.from(this.credentials.values())},e.prototype.removeCredential=function(e){return this.credentials.delete(e)},e}(),Va=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Wa=function(){return Wa=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Wa.apply(this,arguments)},$a=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},qa=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Ja=function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.name="webauthn",t.version="1.0.0",t.description="Provides WebAuthn authentication functionality for ShogunCore",t.webauthn=null,t.signer=null,t}return Va(t,e),t.prototype.initialize=function(t){e.prototype.initialize.call(this,t),"undefined"!=typeof window?this.isSupported()?(this.webauthn=new Ma(t.gun),this.signer=new Ka(this.webauthn),console.log("[webauthnPlugin] WebAuthn plugin initialized with signer support")):console.warn("[webauthnPlugin] WebAuthn not supported in this environment"):console.warn("[webauthnPlugin] WebAuthn plugin disabled - not in browser environment")},t.prototype.destroy=function(){this.webauthn=null,this.signer=null,e.prototype.destroy.call(this),console.log("[webauthnPlugin] WebAuthn plugin destroyed")},t.prototype.assertWebauthn=function(){if(this.assertInitialized(),!this.webauthn)throw new Error("WebAuthn module not initialized");return this.webauthn},t.prototype.assertSigner=function(){if(this.assertInitialized(),!this.signer)throw new Error("WebAuthn signer not initialized");return this.signer},t.prototype.generatePairFromCredentials=function(e){return $a(this,void 0,void 0,function(){var t;return qa(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.assertSigner().createDerivedKeyPair(e.credentialId,e.username)];case 1:return[2,n.sent()];case 2:return t=n.sent(),console.error("Error generating pair from WebAuthn credentials:",t),[2,null];case 3:return[2]}})})},t.prototype.isSupported=function(){return"undefined"!=typeof window&&void 0!==window.PublicKeyCredential&&(this.webauthn?this.webauthn.isSupported():void 0!==window.PublicKeyCredential)},t.prototype.generateCredentials=function(e,t){return $a(this,arguments,void 0,function(e,t,n){return void 0===n&&(n=!1),qa(this,function(r){return[2,this.assertWebauthn().generateCredentials(e,t,n)]})})},t.prototype.createAccount=function(e,t){return $a(this,arguments,void 0,function(e,t,n){return void 0===n&&(n=!1),qa(this,function(r){return[2,this.assertWebauthn().createAccount(e,t,n)]})})},t.prototype.authenticateUser=function(e,t,n){return $a(this,void 0,void 0,function(){return qa(this,function(r){return[2,this.assertWebauthn().authenticateUser(e,t,n)]})})},t.prototype.abortAuthentication=function(){this.assertWebauthn().abortAuthentication()},t.prototype.removeDevice=function(e,t,n){return $a(this,void 0,void 0,function(){return qa(this,function(r){return[2,this.assertWebauthn().removeDevice(e,t,n)]})})},t.prototype.createSigningCredential=function(e){return $a(this,void 0,void 0,function(){var t,n;return qa(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),"function"!=typeof(t=this.assertWebauthn()).createSigningCredential?[3,2]:[4,t.createSigningCredential(e)];case 1:case 3:return[2,r.sent()];case 2:return[4,this.assertSigner().createSigningCredential(e)];case 4:throw n=r.sent(),console.error("Error creating signing credential: ".concat(n.message)),n;case 5:return[2]}})})},t.prototype.createAuthenticator=function(e){try{var t=this.assertWebauthn();return"function"==typeof t.createAuthenticator?t.createAuthenticator(e):this.assertSigner().createAuthenticator(e)}catch(e){throw console.error("Error creating authenticator: ".concat(e.message)),e}},t.prototype.createDerivedKeyPair=function(e,t,n){return $a(this,void 0,void 0,function(){var r,o;return qa(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(r=this.assertWebauthn()).createDerivedKeyPair?[3,2]:[4,r.createDerivedKeyPair(e,t,n)];case 1:case 3:return[2,i.sent()];case 2:return[4,this.assertSigner().createDerivedKeyPair(e,t,n)];case 4:throw o=i.sent(),console.error("Error creating derived key pair: ".concat(o.message)),o;case 5:return[2]}})})},t.prototype.signWithDerivedKeys=function(e,t,n,r){return $a(this,void 0,void 0,function(){var o,i;return qa(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),"function"!=typeof(o=this.assertWebauthn()).signWithDerivedKeys?[3,2]:[4,o.signWithDerivedKeys(e,t,n,r)];case 1:case 3:return[2,s.sent()];case 2:return[4,this.assertSigner().signWithDerivedKeys(e,t,n,r)];case 4:throw i=s.sent(),console.error("Error signing with derived keys: ".concat(i.message)),i;case 5:return[2]}})})},t.prototype.getSigningCredential=function(e){var t=this.assertWebauthn();return"function"==typeof t.getSigningCredential?t.getSigningCredential(e):this.assertSigner().getCredential(e)},t.prototype.listSigningCredentials=function(){var e=this.assertWebauthn();return"function"==typeof e.listSigningCredentials?e.listSigningCredentials():this.assertSigner().listCredentials()},t.prototype.removeSigningCredential=function(e){var t=this.assertWebauthn();return"function"==typeof t.removeSigningCredential?t.removeSigningCredential(e):this.assertSigner().removeCredential(e)},t.prototype.createGunUserFromSigningCredential=function(e,t){return $a(this,void 0,void 0,function(){var n,r,o;return qa(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(n=this.assertWebauthn()).createGunUserFromSigningCredential?[3,2]:[4,n.createGunUserFromSigningCredential(e,t)];case 1:case 3:return[2,i.sent()];case 2:return r=this.assertInitialized(),[4,this.assertSigner().createGunUser(e,t,r.gun)];case 4:throw o=i.sent(),console.error("Error creating Gun user from signing credential: ".concat(o.message)),o;case 5:return[2]}})})},t.prototype.getGunUserPubFromSigningCredential=function(e){var t=this.assertWebauthn();return"function"==typeof t.getGunUserPubFromSigningCredential?t.getGunUserPubFromSigningCredential(e):this.assertSigner().getGunUserPub(e)},t.prototype.getHashedCredentialId=function(e){var t=this.assertWebauthn();return"function"==typeof t.getHashedCredentialId?t.getHashedCredentialId(e):this.assertSigner().getHashedCredentialId(e)},t.prototype.verifyConsistency=function(e,t,n){return $a(this,void 0,void 0,function(){var r,o;return qa(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(r=this.assertWebauthn()).verifyConsistency?[3,2]:[4,r.verifyConsistency(e,t,n)];case 1:case 3:return[2,i.sent()];case 2:return[4,this.assertSigner().verifyConsistency(e,t,n)];case 4:return o=i.sent(),console.error("Error verifying consistency: ".concat(o.message)),[2,{consistent:!1}];case 5:return[2]}})})},t.prototype.setupConsistentOneshotSigning=function(e){return $a(this,void 0,void 0,function(){var t,n,r,o,i;return qa(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),"function"!=typeof(t=this.assertWebauthn()).setupConsistentOneshotSigning?[3,2]:[4,t.setupConsistentOneshotSigning(e)];case 1:return[2,s.sent()];case 2:return[4,this.createSigningCredential(e)];case 3:return n=s.sent(),r=this.createAuthenticator(n.id),[4,this.createGunUserFromSigningCredential(n.id,e)];case 4:return o=s.sent(),[2,{credential:n,authenticator:r,gunUser:o,pub:n.pub,hashedCredentialId:n.hashedCredentialId}];case 5:throw i=s.sent(),console.error("Error setting up consistent oneshot signing: ".concat(i.message)),i;case 6:return[2]}})})},t.prototype.login=function(e){return $a(this,void 0,void 0,function(){var t,n,r,o,i,s=this;return qa(this,function(a){switch(a.label){case 0:if(a.trys.push([0,5,,6]),t=this.assertInitialized(),!e)throw new Error("Username required for WebAuthn login");if(!this.isSupported())throw new Error("WebAuthn is not supported by this browser");return[4,this.generateCredentials(e,null,!0)];case 1:if(!(null==(n=a.sent())?void 0:n.success)||!n.key)throw new Error((null==n?void 0:n.error)||"WebAuthn verification failed");return t.setAuthMethod("webauthn"),t.authenticate?(r=function(){return $a(s,void 0,void 0,function(){return qa(this,function(e){return[2,n]})})},[4,t.authenticate(e,r,null===(i=n.key)||void 0===i?void 0:i.pub)]):[3,3];case 2:case 4:return[2,a.sent()];case 3:return[4,t.login(e,"",n.key)];case 5:return o=a.sent(),console.error("Error during WebAuthn login: ".concat(o)),Ie.handle(xe.WEBAUTHN,"WEBAUTHN_LOGIN_ERROR",o.message||"Error during WebAuthn login",o),[2,{success:!1,error:o.message||"Error during WebAuthn login"}];case 6:return[2]}})})},t.prototype.signUp=function(e,t){return $a(this,void 0,void 0,function(){var n,r,o,i,s,a,c,u,l,f;return qa(this,function(h){switch(h.label){case 0:if(h.trys.push([0,11,,12]),n=this.assertInitialized(),!e)throw new Error("Username required for WebAuthn registration");if(!this.isSupported())throw new Error("WebAuthn is not supported by this browser");if(r=void 0,o=!1!==(null==t?void 0:t.generateSeedPhrase),null==t?void 0:t.seedPhrase){if(!Ta(t.seedPhrase))throw new Error("Invalid seed phrase provided");r=t.seedPhrase}else o&&(r=function(e,t=128){if(os(t),t%32!=0||t>256)throw new TypeError("Invalid entropy");return function(e,t){return Pa(e),Oa(t).encode(e).join((e=>"あいこくしん"===e[0])(t)?" ":" ")}(function(e=32){if(rs&&"function"==typeof rs.getRandomValues)return rs.getRandomValues(new Uint8Array(e));if(rs&&"function"==typeof rs.randomBytes)return Uint8Array.from(rs.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}(t/8),e)}(Ba,128),console.log("[webauthnPlugin] Generated seed phrase for multi-device support"));return i=void 0,r?(Ra(r,e).password,[4,ja(e,r,!0)]):[3,6];case 1:s=h.sent(),i={pub:s.pub,priv:s.priv,epub:s.epub,epriv:s.epriv},h.label=2;case 2:return h.trys.push([2,4,,5]),[4,this.generateCredentials(e,null,!1)];case 3:return(null==(c=h.sent())?void 0:c.success)&&console.log("[webauthnPlugin] Created passkey for device-bound login"),[3,5];case 4:return a=h.sent(),console.warn("[webauthnPlugin] Could not create passkey, seed-only mode:",a),[3,5];case 5:return[3,9];case 6:return[4,this.generateCredentials(e,null,!1)];case 7:if(!(null==(c=h.sent())?void 0:c.success))throw new Error((null==c?void 0:c.error)||"Unable to generate WebAuthn credentials");return[4,this.assertWebauthn().authenticateUser(e,c.credentialId,{userVerification:"required"})];case 8:if(!(u=h.sent()).success)throw new Error(u.error||"WebAuthn verification required to complete registration");if(!c.key)throw new Error("Failed to generate SEA pair from WebAuthn credentials");i=c.key,h.label=9;case 9:return n.setAuthMethod("webauthn"),[4,n.signUp(e,void 0,i)];case 10:return l=h.sent(),r&&o?[2,Wa(Wa({},l),{message:r?"🔑 IMPORTANT: Save your 12-word seed phrase to access your account from other devices!":l.message,seedPhrase:r})]:[2,l];case 11:return f=h.sent(),console.error("Error during WebAuthn registration: ".concat(f)),Ie.handle(xe.WEBAUTHN,"WEBAUTHN_SIGNUP_ERROR",f.message||"Error during WebAuthn registration",f),[2,{success:!1,error:f.message||"Error during WebAuthn registration"}];case 12:return[2]}})})},t.prototype.importFromSeed=function(e,t){return $a(this,void 0,void 0,function(){var n,r;return qa(this,function(o){switch(o.label){case 0:if(o.trys.push([0,2,,3]),!e)throw new Error("Username required");if(!Ta(n=t.toLowerCase().trim().replace(/\s+/g," ").replace(/[^\w\s]/g,"")))throw new Error("Invalid seed phrase. Please check and try again.");return console.log("[webauthnPlugin] Importing account from seed phrase"),[4,this.signUp(e,{seedPhrase:n,generateSeedPhrase:!1})];case 1:return[2,o.sent()];case 2:return r=o.sent(),console.error("Error importing from seed: ".concat(r.message)),Ie.handle(xe.WEBAUTHN,"WEBAUTHN_IMPORT_ERROR",r.message||"Error importing from seed phrase",r),[2,{success:!1,error:r.message||"Error importing from seed phrase"}];case 3:return[2]}})})},t.prototype.getSeedPhrase=function(e){return $a(this,void 0,void 0,function(){return qa(this,function(e){return console.warn("[webauthnPlugin] Seed phrases are not stored for security reasons"),console.warn("[webauthnPlugin] Users must save their seed phrase during registration"),[2,null]})})},t}(Oe);const Qa=BigInt(0),Za=BigInt(1),Ya=9007199254740991;function Xa(e,t){let n=tc(e,"value");const r=BigInt(ic(t,"width")),o=Za<<r-Za;return n<Qa?(n=-n,_e(n<=o,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:e}),(~n&(Za<<r)-Za)+Za):(_e(n<o,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:e}),n)}function ec(e,t){const n=nc(e,"value"),r=BigInt(ic(t,"bits"));return n&(Za<<r)-Za}function tc(e,t){switch(typeof e){case"bigint":return e;case"number":return Me(Number.isInteger(e),"underflow",t||"value",e),Me(e>=-Ya&&e<=Ya,"overflow",t||"value",e),BigInt(e);case"string":try{if(""===e)throw new Error("empty string");return"-"===e[0]&&"-"!==e[1]?-BigInt(e.substring(1)):BigInt(e)}catch(n){Me(!1,`invalid BigNumberish string: ${n.message}`,t||"value",e)}}Me(!1,"invalid BigNumberish value",t||"value",e)}function nc(e,t){const n=tc(e,t);return _e(n>=Qa,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:e}),n}const rc="0123456789abcdef";function oc(e){if(e instanceof Uint8Array){let t="0x0";for(const n of e)t+=rc[n>>4],t+=rc[15&n];return BigInt(t)}return tc(e)}function ic(e,t){switch(typeof e){case"bigint":return Me(e>=-Ya&&e<=Ya,"overflow",t||"value",e),Number(e);case"number":return Me(Number.isInteger(e),"underflow",t||"value",e),Me(e>=-Ya&&e<=Ya,"overflow",t||"value",e),e;case"string":try{if(""===e)throw new Error("empty string");return ic(BigInt(e),t)}catch(n){Me(!1,`invalid numeric string: ${n.message}`,t||"value",e)}}Me(!1,"invalid numeric value",t||"value",e)}function sc(e,t){const n=nc(e,"value");let r=n.toString(16);if(null==t)r.length%2&&(r="0"+r);else{const o=ic(t,"width");if(0===o&&n===Qa)return"0x";for(_e(2*o>=r.length,`value exceeds width (${o} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:e});r.length<2*o;)r="0"+r}return"0x"+r}function ac(e,t){const n=nc(e,"value");if(n===Qa){const e=null!=t?ic(t,"width"):0;return new Uint8Array(e)}let r=n.toString(16);if(r.length%2&&(r="0"+r),null!=t){const n=ic(t,"width");for(;r.length<2*n;)r="00"+r;_e(2*n===r.length,`value exceeds width (${n} bytes)`,"NUMERIC_FAULT",{operation:"toBeArray",fault:"overflow",value:e})}const o=new Uint8Array(r.length/2);for(let e=0;e<o.length;e++){const t=2*e;o[e]=parseInt(r.substring(t,t+2),16)}return o}function cc(e){let t=Qe(qe(e)?e:ac(e)).substring(2);for(;t.startsWith("0");)t=t.substring(1);return""===t&&(t="0"),"0x"+t}const uc=32,lc=new Uint8Array(uc),fc=["then"],hc={},dc=new WeakMap;function pc(e){return dc.get(e)}function gc(e,t){dc.set(e,t)}function yc(e,t){const n=new Error(`deferred error during ABI decoding triggered accessing ${e}`);throw n.error=t,n}function mc(e,t,n){return e.indexOf(null)>=0?t.map((e,t)=>e instanceof wc?mc(pc(e),e,n):e):e.reduce((e,r,o)=>{let i=t.getValue(r);return r in e||(n&&i instanceof wc&&(i=mc(pc(i),i,n)),e[r]=i),e},{})}class wc extends Array{#e;constructor(...e){const t=e[0];let n=e[1],r=(e[2]||[]).slice(),o=!0;t!==hc&&(n=e,r=[],o=!1),super(n.length),n.forEach((e,t)=>{this[t]=e});const i=r.reduce((e,t)=>("string"==typeof t&&e.set(t,(e.get(t)||0)+1),e),new Map);if(gc(this,Object.freeze(n.map((e,t)=>{const n=r[t];return null!=n&&1===i.get(n)?n:null}))),this.#e=[],null==this.#e&&this.#e,!o)return;Object.freeze(this);const s=new Proxy(this,{get:(e,t,n)=>{if("string"==typeof t){if(t.match(/^[0-9]+$/)){const n=ic(t,"%index");if(n<0||n>=this.length)throw new RangeError("out of result range");const r=e[n];return r instanceof Error&&yc(`index ${n}`,r),r}if(fc.indexOf(t)>=0)return Reflect.get(e,t,n);const r=e[t];if(r instanceof Function)return function(...t){return r.apply(this===n?e:this,t)};if(!(t in e))return e.getValue.apply(this===n?e:this,[t])}return Reflect.get(e,t,n)}});return gc(s,pc(this)),s}toArray(e){const t=[];return this.forEach((n,r)=>{n instanceof Error&&yc(`index ${r}`,n),e&&n instanceof wc&&(n=n.toArray(e)),t.push(n)}),t}toObject(e){const t=pc(this);return t.reduce((n,r,o)=>(_e(null!=r,`value at index ${o} unnamed`,"UNSUPPORTED_OPERATION",{operation:"toObject()"}),mc(t,this,e)),{})}slice(e,t){null==e&&(e=0),e<0&&(e+=this.length)<0&&(e=0),null==t&&(t=this.length),t<0&&(t+=this.length)<0&&(t=0),t>this.length&&(t=this.length);const n=pc(this),r=[],o=[];for(let i=e;i<t;i++)r.push(this[i]),o.push(n[i]);return new wc(hc,r,o)}filter(e,t){const n=pc(this),r=[],o=[];for(let i=0;i<this.length;i++){const s=this[i];s instanceof Error&&yc(`index ${i}`,s),e.call(t,s,i,this)&&(r.push(s),o.push(n[i]))}return new wc(hc,r,o)}map(e,t){const n=[];for(let r=0;r<this.length;r++){const o=this[r];o instanceof Error&&yc(`index ${r}`,o),n.push(e.call(t,o,r,this))}return n}getValue(e){const t=pc(this).indexOf(e);if(-1===t)return;const n=this[t];return n instanceof Error&&yc(`property ${JSON.stringify(e)}`,n.error),n}static fromItems(e,t){return new wc(hc,e,t)}}function bc(e){let t=ac(e);return _e(t.length<=uc,"value out-of-bounds","BUFFER_OVERRUN",{buffer:t,length:uc,offset:t.length}),t.length!==uc&&(t=We(Ze([lc.slice(t.length%uc),t]))),t}class vc{name;type;localName;dynamic;constructor(e,t,n,r){Re(this,{name:e,type:t,localName:n,dynamic:r},{name:"string",type:"string",localName:"string",dynamic:"boolean"})}_throwError(e,t){Me(!1,e,this.localName,t)}}class Ec{#t;#n;constructor(){this.#t=[],this.#n=0}get data(){return Ze(this.#t)}get length(){return this.#n}#r(e){return this.#t.push(e),this.#n+=e.length,e.length}appendWriter(e){return this.#r(We(e.data))}writeBytes(e){let t=We(e);const n=t.length%uc;return n&&(t=We(Ze([t,lc.slice(n)]))),this.#r(t)}writeValue(e){return this.#r(bc(e))}writeUpdatableValue(){const e=this.#t.length;return this.#t.push(lc),this.#n+=uc,t=>{this.#t[e]=bc(t)}}}class Ac{allowLoose;#t;#o;#i;#s;#a;constructor(e,t,n){Re(this,{allowLoose:!!t}),this.#t=We(e),this.#i=0,this.#s=null,this.#a=null!=n?n:1024,this.#o=0}get data(){return Qe(this.#t)}get dataLength(){return this.#t.length}get consumed(){return this.#o}get bytes(){return new Uint8Array(this.#t)}#c(e){if(this.#s)return this.#s.#c(e);this.#i+=e,_e(this.#a<1||this.#i<=this.#a*this.dataLength,`compressed ABI data exceeds inflation ratio of ${this.#a} ( see: https://github.com/ethers-io/ethers.js/issues/4537 )`,"BUFFER_OVERRUN",{buffer:We(this.#t),offset:this.#o,length:e,info:{bytesRead:this.#i,dataLength:this.dataLength}})}#u(e,t,n){let r=Math.ceil(t/uc)*uc;return this.#o+r>this.#t.length&&(this.allowLoose&&n&&this.#o+t<=this.#t.length?r=t:_e(!1,"data out-of-bounds","BUFFER_OVERRUN",{buffer:We(this.#t),length:this.#t.length,offset:this.#o+r})),this.#t.slice(this.#o,this.#o+r)}subReader(e){const t=new Ac(this.#t.slice(this.#o+e),this.allowLoose,this.#a);return t.#s=this,t}readBytes(e,t){let n=this.#u(0,e,!!t);return this.#c(e),this.#o+=n.length,n.slice(0,e)}readValue(){return oc(this.readBytes(uc))}readIndex(){return ic(oc(this.readBytes(uc)))}}const xc=BigInt(0),kc=BigInt(36);function Sc(e){const t=(e=e.toLowerCase()).substring(2).split(""),n=new Uint8Array(40);for(let e=0;e<40;e++)n[e]=t[e].charCodeAt(0);const r=Ve(In(n));for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&(t[e]=t[e].toUpperCase()),(15&r[e>>1])>=8&&(t[e+1]=t[e+1].toUpperCase());return"0x"+t.join("")}const Ic={};for(let e=0;e<10;e++)Ic[String(e)]=String(e);for(let e=0;e<26;e++)Ic[String.fromCharCode(65+e)]=String(10+e);const Pc=function(){const e={};for(let t=0;t<36;t++)e["0123456789abcdefghijklmnopqrstuvwxyz"[t]]=BigInt(t);return e}();function Cc(e){if(Me("string"==typeof e,"invalid address","address",e),e.match(/^(0x)?[0-9a-fA-F]{40}$/)){e.startsWith("0x")||(e="0x"+e);const t=Sc(e);return Me(!e.match(/([A-F].*[a-f])|([a-f].*[A-F])/)||t===e,"bad address checksum","address",e),t}if(e.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){Me(e.substring(2,4)===function(e){let t=(e=(e=e.toUpperCase()).substring(4)+e.substring(0,2)+"00").split("").map(e=>Ic[e]).join("");for(;t.length>=15;){let e=t.substring(0,15);t=parseInt(e,10)%97+t.substring(e.length)}let n=String(98-parseInt(t,10)%97);for(;n.length<2;)n="0"+n;return n}(e),"bad icap checksum","address",e);let t=function(e){e=e.toLowerCase();let t=xc;for(let n=0;n<e.length;n++)t=t*kc+Pc[e[n]];return t}(e.substring(4)).toString(16);for(;t.length<40;)t="0"+t;return Sc("0x"+t)}Me(!1,"invalid address","address",e)}const Oc={};function Nc(e,t){let n=!1;return t<0&&(n=!0,t*=-1),new Rc(Oc,`${n?"":"u"}int${t}`,e,{signed:n,width:t})}function Bc(e,t){return new Rc(Oc,`bytes${t||""}`,e,{size:t})}const Tc=Symbol.for("_ethers_typed");class Rc{type;value;#l;_typedSymbol;constructor(e,t,n,r){null==r&&(r=null),ze(Oc,e,"Typed"),Re(this,{_typedSymbol:Tc,type:t,value:n}),this.#l=r,this.format()}format(){if("array"===this.type)throw new Error("");if("dynamicArray"===this.type)throw new Error("");return"tuple"===this.type?`tuple(${this.value.map(e=>e.format()).join(",")})`:this.type}defaultValue(){return 0}minValue(){return 0}maxValue(){return 0}isBigInt(){return!!this.type.match(/^u?int[0-9]+$/)}isData(){return this.type.startsWith("bytes")}isString(){return"string"===this.type}get tupleName(){if("tuple"!==this.type)throw TypeError("not a tuple");return this.#l}get arrayLength(){if("array"!==this.type)throw TypeError("not an array");return!0===this.#l?-1:!1===this.#l?this.value.length:null}static from(e,t){return new Rc(Oc,e,t)}static uint8(e){return Nc(e,8)}static uint16(e){return Nc(e,16)}static uint24(e){return Nc(e,24)}static uint32(e){return Nc(e,32)}static uint40(e){return Nc(e,40)}static uint48(e){return Nc(e,48)}static uint56(e){return Nc(e,56)}static uint64(e){return Nc(e,64)}static uint72(e){return Nc(e,72)}static uint80(e){return Nc(e,80)}static uint88(e){return Nc(e,88)}static uint96(e){return Nc(e,96)}static uint104(e){return Nc(e,104)}static uint112(e){return Nc(e,112)}static uint120(e){return Nc(e,120)}static uint128(e){return Nc(e,128)}static uint136(e){return Nc(e,136)}static uint144(e){return Nc(e,144)}static uint152(e){return Nc(e,152)}static uint160(e){return Nc(e,160)}static uint168(e){return Nc(e,168)}static uint176(e){return Nc(e,176)}static uint184(e){return Nc(e,184)}static uint192(e){return Nc(e,192)}static uint200(e){return Nc(e,200)}static uint208(e){return Nc(e,208)}static uint216(e){return Nc(e,216)}static uint224(e){return Nc(e,224)}static uint232(e){return Nc(e,232)}static uint240(e){return Nc(e,240)}static uint248(e){return Nc(e,248)}static uint256(e){return Nc(e,256)}static uint(e){return Nc(e,256)}static int8(e){return Nc(e,-8)}static int16(e){return Nc(e,-16)}static int24(e){return Nc(e,-24)}static int32(e){return Nc(e,-32)}static int40(e){return Nc(e,-40)}static int48(e){return Nc(e,-48)}static int56(e){return Nc(e,-56)}static int64(e){return Nc(e,-64)}static int72(e){return Nc(e,-72)}static int80(e){return Nc(e,-80)}static int88(e){return Nc(e,-88)}static int96(e){return Nc(e,-96)}static int104(e){return Nc(e,-104)}static int112(e){return Nc(e,-112)}static int120(e){return Nc(e,-120)}static int128(e){return Nc(e,-128)}static int136(e){return Nc(e,-136)}static int144(e){return Nc(e,-144)}static int152(e){return Nc(e,-152)}static int160(e){return Nc(e,-160)}static int168(e){return Nc(e,-168)}static int176(e){return Nc(e,-176)}static int184(e){return Nc(e,-184)}static int192(e){return Nc(e,-192)}static int200(e){return Nc(e,-200)}static int208(e){return Nc(e,-208)}static int216(e){return Nc(e,-216)}static int224(e){return Nc(e,-224)}static int232(e){return Nc(e,-232)}static int240(e){return Nc(e,-240)}static int248(e){return Nc(e,-248)}static int256(e){return Nc(e,-256)}static int(e){return Nc(e,-256)}static bytes1(e){return Bc(e,1)}static bytes2(e){return Bc(e,2)}static bytes3(e){return Bc(e,3)}static bytes4(e){return Bc(e,4)}static bytes5(e){return Bc(e,5)}static bytes6(e){return Bc(e,6)}static bytes7(e){return Bc(e,7)}static bytes8(e){return Bc(e,8)}static bytes9(e){return Bc(e,9)}static bytes10(e){return Bc(e,10)}static bytes11(e){return Bc(e,11)}static bytes12(e){return Bc(e,12)}static bytes13(e){return Bc(e,13)}static bytes14(e){return Bc(e,14)}static bytes15(e){return Bc(e,15)}static bytes16(e){return Bc(e,16)}static bytes17(e){return Bc(e,17)}static bytes18(e){return Bc(e,18)}static bytes19(e){return Bc(e,19)}static bytes20(e){return Bc(e,20)}static bytes21(e){return Bc(e,21)}static bytes22(e){return Bc(e,22)}static bytes23(e){return Bc(e,23)}static bytes24(e){return Bc(e,24)}static bytes25(e){return Bc(e,25)}static bytes26(e){return Bc(e,26)}static bytes27(e){return Bc(e,27)}static bytes28(e){return Bc(e,28)}static bytes29(e){return Bc(e,29)}static bytes30(e){return Bc(e,30)}static bytes31(e){return Bc(e,31)}static bytes32(e){return Bc(e,32)}static address(e){return new Rc(Oc,"address",e)}static bool(e){return new Rc(Oc,"bool",!!e)}static bytes(e){return new Rc(Oc,"bytes",e)}static string(e){return new Rc(Oc,"string",e)}static array(e,t){throw new Error("not implemented yet")}static tuple(e,t){throw new Error("not implemented yet")}static overrides(e){return new Rc(Oc,"overrides",Object.assign({},e))}static isTyped(e){return e&&"object"==typeof e&&"_typedSymbol"in e&&e._typedSymbol===Tc}static dereference(e,t){if(Rc.isTyped(e)){if(e.type!==t)throw new Error(`invalid type: expecetd ${t}, got ${e.type}`);return e.value}return e}}class Uc extends vc{constructor(e){super("address","address",e,!1)}defaultValue(){return"0x0000000000000000000000000000000000000000"}encode(e,t){let n=Rc.dereference(t,"string");try{n=Cc(n)}catch(e){return this._throwError(e.message,t)}return e.writeValue(n)}decode(e){return Cc(sc(e.readValue(),20))}}class Dc extends vc{coder;constructor(e){super(e.name,e.type,"_",e.dynamic),this.coder=e}defaultValue(){return this.coder.defaultValue()}encode(e,t){return this.coder.encode(e,t)}decode(e){return this.coder.decode(e)}}function Lc(e,t,n){let r=[];if(Array.isArray(n))r=n;else if(n&&"object"==typeof n){let e={};r=t.map(t=>{const r=t.localName;return _e(r,"cannot encode object for signature with missing names","INVALID_ARGUMENT",{argument:"values",info:{coder:t},value:n}),_e(!e[r],"cannot encode object for signature with duplicate names","INVALID_ARGUMENT",{argument:"values",info:{coder:t},value:n}),e[r]=!0,n[r]})}else Me(!1,"invalid tuple value","tuple",n);Me(t.length===r.length,"types/value length mismatch","tuple",n);let o=new Ec,i=new Ec,s=[];t.forEach((e,t)=>{let n=r[t];if(e.dynamic){let t=i.length;e.encode(i,n);let r=o.writeUpdatableValue();s.push(e=>{r(e+t)})}else e.encode(o,n)}),s.forEach(e=>{e(o.length)});let a=e.appendWriter(o);return a+=e.appendWriter(i),a}function Fc(e,t){let n=[],r=[],o=e.subReader(0);return t.forEach(t=>{let i=null;if(t.dynamic){let n=e.readIndex(),r=o.subReader(n);try{i=t.decode(r)}catch(e){if(De(e,"BUFFER_OVERRUN"))throw e;i=e,i.baseType=t.name,i.name=t.localName,i.type=t.type}}else try{i=t.decode(e)}catch(e){if(De(e,"BUFFER_OVERRUN"))throw e;i=e,i.baseType=t.name,i.name=t.localName,i.type=t.type}if(null==i)throw new Error("investigate");n.push(i),r.push(t.localName||null)}),wc.fromItems(n,r)}class _c extends vc{coder;length;constructor(e,t,n){super("array",e.type+"["+(t>=0?t:"")+"]",n,-1===t||e.dynamic),Re(this,{coder:e,length:t})}defaultValue(){const e=this.coder.defaultValue(),t=[];for(let n=0;n<this.length;n++)t.push(e);return t}encode(e,t){const n=Rc.dereference(t,"array");Array.isArray(n)||this._throwError("expected array value",n);let r=this.length;-1===r&&(r=n.length,e.writeValue(n.length)),je(n.length,r,"coder array"+(this.localName?" "+this.localName:""));let o=[];for(let e=0;e<n.length;e++)o.push(this.coder);return Lc(e,o,n)}decode(e){let t=this.length;-1===t&&(t=e.readIndex(),_e(t*uc<=e.dataLength,"insufficient data length","BUFFER_OVERRUN",{buffer:e.bytes,offset:t*uc,length:e.dataLength}));let n=[];for(let e=0;e<t;e++)n.push(new Dc(this.coder));return Fc(e,n)}}class Mc extends vc{constructor(e){super("bool","bool",e,!1)}defaultValue(){return!1}encode(e,t){const n=Rc.dereference(t,"bool");return e.writeValue(n?1:0)}decode(e){return!!e.readValue()}}class jc extends vc{constructor(e,t){super(e,e,t,!0)}defaultValue(){return"0x"}encode(e,t){t=We(t);let n=e.writeValue(t.length);return n+=e.writeBytes(t),n}decode(e){return e.readBytes(e.readIndex(),!0)}}class Gc extends jc{constructor(e){super("bytes",e)}decode(e){return Qe(super.decode(e))}}class Hc extends vc{size;constructor(e,t){let n="bytes"+String(e);super(n,n,t,!1),Re(this,{size:e},{size:"number"})}defaultValue(){return"0x0000000000000000000000000000000000000000000000000000000000000000".substring(0,2+2*this.size)}encode(e,t){let n=We(Rc.dereference(t,this.type));return n.length!==this.size&&this._throwError("incorrect data length",t),e.writeBytes(n)}decode(e){return Qe(e.readBytes(this.size))}}const zc=new Uint8Array([]);class Kc extends vc{constructor(e){super("null","",e,!1)}defaultValue(){return null}encode(e,t){return null!=t&&this._throwError("not null",t),e.writeBytes(zc)}decode(e){return e.readBytes(0),null}}const Vc=BigInt(0),Wc=BigInt(1),$c=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");class qc extends vc{size;signed;constructor(e,t,n){const r=(t?"int":"uint")+8*e;super(r,r,n,!1),Re(this,{size:e,signed:t},{size:"number",signed:"boolean"})}defaultValue(){return 0}encode(e,t){let n=tc(Rc.dereference(t,this.type)),r=ec($c,256);if(this.signed){let e=ec(r,8*this.size-1);(n>e||n<-(e+Wc))&&this._throwError("value out-of-bounds",t),n=Xa(n,256)}else(n<Vc||n>ec(r,8*this.size))&&this._throwError("value out-of-bounds",t);return e.writeValue(n)}decode(e){let t=ec(e.readValue(),8*this.size);return this.signed&&(t=function(e,t){const n=nc(e,"value"),r=BigInt(ic(t,"width"));return _e(n>>r===Qa,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:e}),n>>r-Za?-((~n&(Za<<r)-Za)+Za):n}(t,8*this.size)),t}}class Jc extends jc{constructor(e){super("string",e)}defaultValue(){return""}encode(e,t){return super.encode(e,ot(Rc.dereference(t,"string")))}decode(e){return it(super.decode(e))}}class Qc extends vc{coders;constructor(e,t){let n=!1;const r=[];e.forEach(e=>{e.dynamic&&(n=!0),r.push(e.type)}),super("tuple","tuple("+r.join(",")+")",t,n),Re(this,{coders:Object.freeze(e.slice())})}defaultValue(){const e=[];this.coders.forEach(t=>{e.push(t.defaultValue())});const t=this.coders.reduce((e,t)=>{const n=t.localName;return n&&(e[n]||(e[n]=0),e[n]++),e},{});return this.coders.forEach((n,r)=>{let o=n.localName;o&&1===t[o]&&("length"===o&&(o="_length"),null==e[o]&&(e[o]=e[r]))}),Object.freeze(e)}encode(e,t){const n=Rc.dereference(t,"tuple");return Lc(e,this.coders,n)}decode(e){return Fc(e,this.coders)}}function Zc(e){return In(ot(e))}function Yc(e){const t=new Set;return e.forEach(e=>t.add(e)),Object.freeze(t)}const Xc=Yc("external public payable override".split(" ")),eu="constant external internal payable private public pure view override",tu=Yc(eu.split(" ")),nu="constructor error event fallback function receive struct",ru=Yc(nu.split(" ")),ou="calldata memory storage payable indexed",iu=Yc(ou.split(" ")),su=Yc([nu,ou,"tuple returns",eu].join(" ").split(" ")),au={"(":"OPEN_PAREN",")":"CLOSE_PAREN","[":"OPEN_BRACKET","]":"CLOSE_BRACKET",",":"COMMA","@":"AT"},cu=new RegExp("^(\\s*)"),uu=new RegExp("^([0-9]+)"),lu=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)"),fu=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)$"),hu=new RegExp("^(address|bool|bytes([0-9]*)|string|u?int([0-9]*))$");class du{#o;#f;get offset(){return this.#o}get length(){return this.#f.length-this.#o}constructor(e){this.#o=0,this.#f=e.slice()}clone(){return new du(this.#f)}reset(){this.#o=0}#h(e=0,t=0){return new du(this.#f.slice(e,t).map(t=>Object.freeze(Object.assign({},t,{match:t.match-e,linkBack:t.linkBack-e,linkNext:t.linkNext-e}))))}popKeyword(e){const t=this.peek();if("KEYWORD"!==t.type||!e.has(t.text))throw new Error(`expected keyword ${t.text}`);return this.pop().text}popType(e){if(this.peek().type!==e){const t=this.peek();throw new Error(`expected ${e}; got ${t.type} ${JSON.stringify(t.text)}`)}return this.pop().text}popParen(){const e=this.peek();if("OPEN_PAREN"!==e.type)throw new Error("bad start");const t=this.#h(this.#o+1,e.match+1);return this.#o=e.match+1,t}popParams(){const e=this.peek();if("OPEN_PAREN"!==e.type)throw new Error("bad start");const t=[];for(;this.#o<e.match-1;){const e=this.peek().linkNext;t.push(this.#h(this.#o+1,e)),this.#o=e}return this.#o=e.match+1,t}peek(){if(this.#o>=this.#f.length)throw new Error("out-of-bounds");return this.#f[this.#o]}peekKeyword(e){const t=this.peekType("KEYWORD");return null!=t&&e.has(t)?t:null}peekType(e){if(0===this.length)return null;const t=this.peek();return t.type===e?t.text:null}pop(){const e=this.peek();return this.#o++,e}toString(){const e=[];for(let t=this.#o;t<this.#f.length;t++){const n=this.#f[t];e.push(`${n.type}:${n.text}`)}return`<TokenString ${e.join(" ")}>`}}function pu(e){const t=[],n=t=>{const n=i<e.length?JSON.stringify(e[i]):"$EOI";throw new Error(`invalid token ${n} at ${i}: ${t}`)};let r=[],o=[],i=0;for(;i<e.length;){let s=e.substring(i),a=s.match(cu);a&&(i+=a[1].length,s=e.substring(i));const c={depth:r.length,linkBack:-1,linkNext:-1,match:-1,type:"",text:"",offset:i,value:-1};t.push(c);let u=au[s[0]]||"";if(u){if(c.type=u,c.text=s[0],i++,"OPEN_PAREN"===u)r.push(t.length-1),o.push(t.length-1);else if("CLOSE_PAREN"==u)0===r.length&&n("no matching open bracket"),c.match=r.pop(),t[c.match].match=t.length-1,c.depth--,c.linkBack=o.pop(),t[c.linkBack].linkNext=t.length-1;else if("COMMA"===u)c.linkBack=o.pop(),t[c.linkBack].linkNext=t.length-1,o.push(t.length-1);else if("OPEN_BRACKET"===u)c.type="BRACKET";else if("CLOSE_BRACKET"===u){let e=t.pop().text;if(t.length>0&&"NUMBER"===t[t.length-1].type){const n=t.pop().text;e=n+e,t[t.length-1].value=ic(n)}if(0===t.length||"BRACKET"!==t[t.length-1].type)throw new Error("missing opening bracket");t[t.length-1].text+=e}}else if(a=s.match(lu),a){if(c.text=a[1],i+=c.text.length,su.has(c.text)){c.type="KEYWORD";continue}if(c.text.match(hu)){c.type="TYPE";continue}c.type="ID"}else{if(a=s.match(uu),!a)throw new Error(`unexpected token ${JSON.stringify(s[0])} at position ${i}`);c.text=a[1],c.type="NUMBER",i+=c.text.length}}return new du(t.map(e=>Object.freeze(e)))}function gu(e,t){let n=[];for(const r in t.keys())e.has(r)&&n.push(r);if(n.length>1)throw new Error(`conflicting types: ${n.join(", ")}`)}function yu(e,t){if(t.peekKeyword(ru)){const n=t.pop().text;if(n!==e)throw new Error(`expected ${e}, got ${n}`)}return t.popType("ID")}function mu(e,t){const n=new Set;for(;;){const r=e.peekType("KEYWORD");if(null==r||t&&!t.has(r))break;if(e.pop(),n.has(r))throw new Error(`duplicate keywords: ${JSON.stringify(r)}`);n.add(r)}return Object.freeze(n)}function wu(e){let t=mu(e,tu);return gu(t,Yc("constant payable nonpayable".split(" "))),gu(t,Yc("pure view payable nonpayable".split(" "))),t.has("view")?"view":t.has("pure")?"pure":t.has("payable")?"payable":t.has("nonpayable")?"nonpayable":t.has("constant")?"view":"nonpayable"}function bu(e,t){return e.popParams().map(e=>Ru.from(e,t))}function vu(e){if(e.peekType("AT")){if(e.pop(),e.peekType("NUMBER"))return tc(e.pop().text);throw new Error("invalid gas")}return null}function Eu(e){if(e.length)throw new Error(`unexpected tokens at offset ${e.offset}: ${e.toString()}`)}const Au=new RegExp(/^(.*)\[([0-9]*)\]$/);function xu(e){const t=e.match(hu);if(Me(t,"invalid type","type",e),"uint"===e)return"uint256";if("int"===e)return"int256";if(t[2]){const n=parseInt(t[2]);Me(0!==n&&n<=32,"invalid bytes length","type",e)}else if(t[3]){const n=parseInt(t[3]);Me(0!==n&&n<=256&&n%8==0,"invalid numeric width","type",e)}return e}const ku={},Su=Symbol.for("_ethers_internal"),Iu="_ParamTypeInternal",Pu="_ErrorInternal",Cu="_EventInternal",Ou="_ConstructorInternal",Nu="_FallbackInternal",Bu="_FunctionInternal",Tu="_StructInternal";class Ru{name;type;baseType;indexed;components;arrayLength;arrayChildren;constructor(e,t,n,r,o,i,s,a){if(ze(e,ku,"ParamType"),Object.defineProperty(this,Su,{value:Iu}),i&&(i=Object.freeze(i.slice())),"array"===r){if(null==s||null==a)throw new Error("")}else if(null!=s||null!=a)throw new Error("");if("tuple"===r){if(null==i)throw new Error("")}else if(null!=i)throw new Error("");Re(this,{name:t,type:n,baseType:r,indexed:o,components:i,arrayLength:s,arrayChildren:a})}format(e){if(null==e&&(e="sighash"),"json"===e){const t=this.name||"";if(this.isArray()){const e=JSON.parse(this.arrayChildren.format("json"));return e.name=t,e.type+=`[${this.arrayLength<0?"":String(this.arrayLength)}]`,JSON.stringify(e)}const n={type:"tuple"===this.baseType?"tuple":this.type,name:t};return"boolean"==typeof this.indexed&&(n.indexed=this.indexed),this.isTuple()&&(n.components=this.components.map(t=>JSON.parse(t.format(e)))),JSON.stringify(n)}let t="";return this.isArray()?(t+=this.arrayChildren.format(e),t+=`[${this.arrayLength<0?"":String(this.arrayLength)}]`):this.isTuple()?t+="("+this.components.map(t=>t.format(e)).join("full"===e?", ":",")+")":t+=this.type,"sighash"!==e&&(!0===this.indexed&&(t+=" indexed"),"full"===e&&this.name&&(t+=" "+this.name)),t}isArray(){return"array"===this.baseType}isTuple(){return"tuple"===this.baseType}isIndexable(){return null!=this.indexed}walk(e,t){if(this.isArray()){if(!Array.isArray(e))throw new Error("invalid array value");if(-1!==this.arrayLength&&e.length!==this.arrayLength)throw new Error("array is wrong length");const n=this;return e.map(e=>n.arrayChildren.walk(e,t))}if(this.isTuple()){if(!Array.isArray(e))throw new Error("invalid tuple value");if(e.length!==this.components.length)throw new Error("array is wrong length");const n=this;return e.map((e,r)=>n.components[r].walk(e,t))}return t(this.type,e)}#d(e,t,n,r){if(this.isArray()){if(!Array.isArray(t))throw new Error("invalid array value");if(-1!==this.arrayLength&&t.length!==this.arrayLength)throw new Error("array is wrong length");const o=this.arrayChildren,i=t.slice();return i.forEach((t,r)=>{o.#d(e,t,n,e=>{i[r]=e})}),void r(i)}if(this.isTuple()){const o=this.components;let i;if(Array.isArray(t))i=t.slice();else{if(null==t||"object"!=typeof t)throw new Error("invalid tuple value");i=o.map(e=>{if(!e.name)throw new Error("cannot use object value with unnamed components");if(!(e.name in t))throw new Error(`missing value for component ${e.name}`);return t[e.name]})}if(i.length!==this.components.length)throw new Error("array is wrong length");return i.forEach((t,r)=>{o[r].#d(e,t,n,e=>{i[r]=e})}),void r(i)}const o=n(this.type,t);o.then?e.push(async function(){r(await o)}()):r(o)}async walkAsync(e,t){const n=[],r=[e];return this.#d(n,e,t,e=>{r[0]=e}),n.length&&await Promise.all(n),r[0]}static from(e,t){if(Ru.isParamType(e))return e;if("string"==typeof e)try{return Ru.from(pu(e),t)}catch(t){Me(!1,"invalid param type","obj",e)}else if(e instanceof du){let n="",r="",o=null;mu(e,Yc(["tuple"])).has("tuple")||e.peekType("OPEN_PAREN")?(r="tuple",o=e.popParams().map(e=>Ru.from(e)),n=`tuple(${o.map(e=>e.format()).join(",")})`):(n=xu(e.popType("TYPE")),r=n);let i=null,s=null;for(;e.length&&e.peekType("BRACKET");){const t=e.pop();i=new Ru(ku,"",n,r,null,o,s,i),s=t.value,n+=t.text,r="array",o=null}let a=null;if(mu(e,iu).has("indexed")){if(!t)throw new Error("");a=!0}const c=e.peekType("ID")?e.pop().text:"";if(e.length)throw new Error("leftover tokens");return new Ru(ku,c,n,r,a,o,s,i)}const n=e.name;Me(!n||"string"==typeof n&&n.match(fu),"invalid name","obj.name",n);let r=e.indexed;null!=r&&(Me(t,"parameter cannot be indexed","obj.indexed",e.indexed),r=!!r);let o=e.type,i=o.match(Au);if(i){const t=parseInt(i[2]||"-1"),s=Ru.from({type:i[1],components:e.components});return new Ru(ku,n||"",o,"array",r,null,t,s)}if("tuple"===o||o.startsWith("tuple(")||o.startsWith("(")){const t=null!=e.components?e.components.map(e=>Ru.from(e)):null;return new Ru(ku,n||"",o,"tuple",r,t,null,null)}return o=xu(e.type),new Ru(ku,n||"",o,o,r,null,null,null)}static isParamType(e){return e&&e[Su]===Iu}}class Uu{type;inputs;constructor(e,t,n){ze(e,ku,"Fragment"),Re(this,{type:t,inputs:n=Object.freeze(n.slice())})}static from(e){if("string"==typeof e){try{Uu.from(JSON.parse(e))}catch(e){}return Uu.from(pu(e))}if(e instanceof du)switch(e.peekKeyword(ru)){case"constructor":return Mu.from(e);case"error":return Fu.from(e);case"event":return _u.from(e);case"fallback":case"receive":return ju.from(e);case"function":return Gu.from(e);case"struct":return Hu.from(e)}else if("object"==typeof e){switch(e.type){case"constructor":return Mu.from(e);case"error":return Fu.from(e);case"event":return _u.from(e);case"fallback":case"receive":return ju.from(e);case"function":return Gu.from(e);case"struct":return Hu.from(e)}_e(!1,`unsupported type: ${e.type}`,"UNSUPPORTED_OPERATION",{operation:"Fragment.from"})}Me(!1,"unsupported frgament object","obj",e)}static isConstructor(e){return Mu.isFragment(e)}static isError(e){return Fu.isFragment(e)}static isEvent(e){return _u.isFragment(e)}static isFunction(e){return Gu.isFragment(e)}static isStruct(e){return Hu.isFragment(e)}}class Du extends Uu{name;constructor(e,t,n,r){super(e,t,r),Me("string"==typeof n&&n.match(fu),"invalid identifier","name",n),r=Object.freeze(r.slice()),Re(this,{name:n})}}function Lu(e,t){return"("+t.map(t=>t.format(e)).join("full"===e?", ":",")+")"}class Fu extends Du{constructor(e,t,n){super(e,"error",t,n),Object.defineProperty(this,Su,{value:Pu})}get selector(){return Zc(this.format("sighash")).substring(0,10)}format(e){if(null==e&&(e="sighash"),"json"===e)return JSON.stringify({type:"error",name:this.name,inputs:this.inputs.map(t=>JSON.parse(t.format(e)))});const t=[];return"sighash"!==e&&t.push("error"),t.push(this.name+Lu(e,this.inputs)),t.join(" ")}static from(e){if(Fu.isFragment(e))return e;if("string"==typeof e)return Fu.from(pu(e));if(e instanceof du){const t=yu("error",e),n=bu(e);return Eu(e),new Fu(ku,t,n)}return new Fu(ku,e.name,e.inputs?e.inputs.map(Ru.from):[])}static isFragment(e){return e&&e[Su]===Pu}}class _u extends Du{anonymous;constructor(e,t,n,r){super(e,"event",t,n),Object.defineProperty(this,Su,{value:Cu}),Re(this,{anonymous:r})}get topicHash(){return Zc(this.format("sighash"))}format(e){if(null==e&&(e="sighash"),"json"===e)return JSON.stringify({type:"event",anonymous:this.anonymous,name:this.name,inputs:this.inputs.map(t=>JSON.parse(t.format(e)))});const t=[];return"sighash"!==e&&t.push("event"),t.push(this.name+Lu(e,this.inputs)),"sighash"!==e&&this.anonymous&&t.push("anonymous"),t.join(" ")}static getTopicHash(e,t){return t=(t||[]).map(e=>Ru.from(e)),new _u(ku,e,t,!1).topicHash}static from(e){if(_u.isFragment(e))return e;if("string"==typeof e)try{return _u.from(pu(e))}catch(t){Me(!1,"invalid event fragment","obj",e)}else if(e instanceof du){const t=yu("event",e),n=bu(e,!0),r=!!mu(e,Yc(["anonymous"])).has("anonymous");return Eu(e),new _u(ku,t,n,r)}return new _u(ku,e.name,e.inputs?e.inputs.map(e=>Ru.from(e,!0)):[],!!e.anonymous)}static isFragment(e){return e&&e[Su]===Cu}}class Mu extends Uu{payable;gas;constructor(e,t,n,r,o){super(e,t,n),Object.defineProperty(this,Su,{value:Ou}),Re(this,{payable:r,gas:o})}format(e){if(_e(null!=e&&"sighash"!==e,"cannot format a constructor for sighash","UNSUPPORTED_OPERATION",{operation:"format(sighash)"}),"json"===e)return JSON.stringify({type:"constructor",stateMutability:this.payable?"payable":"undefined",payable:this.payable,gas:null!=this.gas?this.gas:void 0,inputs:this.inputs.map(t=>JSON.parse(t.format(e)))});const t=[`constructor${Lu(e,this.inputs)}`];return this.payable&&t.push("payable"),null!=this.gas&&t.push(`@${this.gas.toString()}`),t.join(" ")}static from(e){if(Mu.isFragment(e))return e;if("string"==typeof e)try{return Mu.from(pu(e))}catch(t){Me(!1,"invalid constuctor fragment","obj",e)}else if(e instanceof du){mu(e,Yc(["constructor"]));const t=bu(e),n=!!mu(e,Xc).has("payable"),r=vu(e);return Eu(e),new Mu(ku,"constructor",t,n,r)}return new Mu(ku,"constructor",e.inputs?e.inputs.map(Ru.from):[],!!e.payable,null!=e.gas?e.gas:null)}static isFragment(e){return e&&e[Su]===Ou}}class ju extends Uu{payable;constructor(e,t,n){super(e,"fallback",t),Object.defineProperty(this,Su,{value:Nu}),Re(this,{payable:n})}format(e){const t=0===this.inputs.length?"receive":"fallback";if("json"===e){const e=this.payable?"payable":"nonpayable";return JSON.stringify({type:t,stateMutability:e})}return`${t}()${this.payable?" payable":""}`}static from(e){if(ju.isFragment(e))return e;if("string"==typeof e)try{return ju.from(pu(e))}catch(t){Me(!1,"invalid fallback fragment","obj",e)}else if(e instanceof du){const t=e.toString();if(Me(e.peekKeyword(Yc(["fallback","receive"])),"type must be fallback or receive","obj",t),"receive"===e.popKeyword(Yc(["fallback","receive"]))){const t=bu(e);return Me(0===t.length,"receive cannot have arguments","obj.inputs",t),mu(e,Yc(["payable"])),Eu(e),new ju(ku,[],!0)}let n=bu(e);n.length?Me(1===n.length&&"bytes"===n[0].type,"invalid fallback inputs","obj.inputs",n.map(e=>e.format("minimal")).join(", ")):n=[Ru.from("bytes")];const r=wu(e);if(Me("nonpayable"===r||"payable"===r,"fallback cannot be constants","obj.stateMutability",r),mu(e,Yc(["returns"])).has("returns")){const t=bu(e);Me(1===t.length&&"bytes"===t[0].type,"invalid fallback outputs","obj.outputs",t.map(e=>e.format("minimal")).join(", "))}return Eu(e),new ju(ku,n,"payable"===r)}if("receive"===e.type)return new ju(ku,[],!0);if("fallback"===e.type){const t=[Ru.from("bytes")],n="payable"===e.stateMutability;return new ju(ku,t,n)}Me(!1,"invalid fallback description","obj",e)}static isFragment(e){return e&&e[Su]===Nu}}class Gu extends Du{constant;outputs;stateMutability;payable;gas;constructor(e,t,n,r,o,i){super(e,"function",t,r),Object.defineProperty(this,Su,{value:Bu}),Re(this,{constant:"view"===n||"pure"===n,gas:i,outputs:o=Object.freeze(o.slice()),payable:"payable"===n,stateMutability:n})}get selector(){return Zc(this.format("sighash")).substring(0,10)}format(e){if(null==e&&(e="sighash"),"json"===e)return JSON.stringify({type:"function",name:this.name,constant:this.constant,stateMutability:"nonpayable"!==this.stateMutability?this.stateMutability:void 0,payable:this.payable,gas:null!=this.gas?this.gas:void 0,inputs:this.inputs.map(t=>JSON.parse(t.format(e))),outputs:this.outputs.map(t=>JSON.parse(t.format(e)))});const t=[];return"sighash"!==e&&t.push("function"),t.push(this.name+Lu(e,this.inputs)),"sighash"!==e&&("nonpayable"!==this.stateMutability&&t.push(this.stateMutability),this.outputs&&this.outputs.length&&(t.push("returns"),t.push(Lu(e,this.outputs))),null!=this.gas&&t.push(`@${this.gas.toString()}`)),t.join(" ")}static getSelector(e,t){return t=(t||[]).map(e=>Ru.from(e)),new Gu(ku,e,"view",t,[],null).selector}static from(e){if(Gu.isFragment(e))return e;if("string"==typeof e)try{return Gu.from(pu(e))}catch(t){Me(!1,"invalid function fragment","obj",e)}else if(e instanceof du){const t=yu("function",e),n=bu(e),r=wu(e);let o=[];mu(e,Yc(["returns"])).has("returns")&&(o=bu(e));const i=vu(e);return Eu(e),new Gu(ku,t,r,n,o,i)}let t=e.stateMutability;return null==t&&(t="payable","boolean"==typeof e.constant?(t="view",e.constant||(t="payable","boolean"!=typeof e.payable||e.payable||(t="nonpayable"))):"boolean"!=typeof e.payable||e.payable||(t="nonpayable")),new Gu(ku,e.name,t,e.inputs?e.inputs.map(Ru.from):[],e.outputs?e.outputs.map(Ru.from):[],null!=e.gas?e.gas:null)}static isFragment(e){return e&&e[Su]===Bu}}class Hu extends Du{constructor(e,t,n){super(e,"struct",t,n),Object.defineProperty(this,Su,{value:Tu})}format(){throw new Error("@TODO")}static from(e){if("string"==typeof e)try{return Hu.from(pu(e))}catch(t){Me(!1,"invalid struct fragment","obj",e)}else if(e instanceof du){const t=yu("struct",e),n=bu(e);return Eu(e),new Hu(ku,t,n)}return new Hu(ku,e.name,e.inputs?e.inputs.map(Ru.from):[])}static isFragment(e){return e&&e[Su]===Tu}}const zu=new Map;zu.set(0,"GENERIC_PANIC"),zu.set(1,"ASSERT_FALSE"),zu.set(17,"OVERFLOW"),zu.set(18,"DIVIDE_BY_ZERO"),zu.set(33,"ENUM_RANGE_ERROR"),zu.set(34,"BAD_STORAGE_DATA"),zu.set(49,"STACK_UNDERFLOW"),zu.set(50,"ARRAY_RANGE_ERROR"),zu.set(65,"OUT_OF_MEMORY"),zu.set(81,"UNINITIALIZED_FUNCTION_CALL");const Ku=new RegExp(/^bytes([0-9]*)$/),Vu=new RegExp(/^(u?int)([0-9]*)$/);let Wu=null,$u=1024;class qu{#p(e){if(e.isArray())return new _c(this.#p(e.arrayChildren),e.arrayLength,e.name);if(e.isTuple())return new Qc(e.components.map(e=>this.#p(e)),e.name);switch(e.baseType){case"address":return new Uc(e.name);case"bool":return new Mc(e.name);case"string":return new Jc(e.name);case"bytes":return new Gc(e.name);case"":return new Kc(e.name)}let t=e.type.match(Vu);if(t){let n=parseInt(t[2]||"256");return Me(0!==n&&n<=256&&n%8==0,"invalid "+t[1]+" bit length","param",e),new qc(n/8,"int"===t[1],e.name)}if(t=e.type.match(Ku),t){let n=parseInt(t[1]);return Me(0!==n&&n<=32,"invalid bytes length","param",e),new Hc(n,e.name)}Me(!1,"invalid type","type",e.type)}getDefaultValue(e){const t=e.map(e=>this.#p(Ru.from(e)));return new Qc(t,"_").defaultValue()}encode(e,t){je(t.length,e.length,"types/values length mismatch");const n=e.map(e=>this.#p(Ru.from(e))),r=new Qc(n,"_"),o=new Ec;return r.encode(o,t),o.data}decode(e,t,n){const r=e.map(e=>this.#p(Ru.from(e)));return new Qc(r,"_").decode(new Ac(t,n,$u))}static _setDefaultMaxInflation(e){Me("number"==typeof e&&Number.isInteger(e),"invalid defaultMaxInflation factor","value",e),$u=e}static defaultAbiCoder(){return null==Wu&&(Wu=new qu),Wu}static getBuiltinCallException(e,t,n){return function(e,t,n,r){let o="missing revert data",i=null,s=null;if(n){o="execution reverted";const e=Ve(n);if(n=Qe(n),0===e.length)o+=" (no data present; likely require(false) occurred",i="require(false)";else if(e.length%32!=4)o+=" (could not decode reason; invalid data length)";else if("0x08c379a0"===Qe(e.slice(0,4)))try{i=r.decode(["string"],e.slice(4))[0],s={signature:"Error(string)",name:"Error",args:[i]},o+=`: ${JSON.stringify(i)}`}catch(e){o+=" (could not decode reason; invalid string data)"}else if("0x4e487b71"===Qe(e.slice(0,4)))try{const t=Number(r.decode(["uint256"],e.slice(4))[0]);s={signature:"Panic(uint256)",name:"Panic",args:[t]},i=`Panic due to ${zu.get(t)||"UNKNOWN"}(${t})`,o+=`: ${i}`}catch(e){o+=" (could not decode panic code)"}else o+=" (unknown custom error)"}const a={to:t.to?Cc(t.to):null,data:t.data||"0x"};return t.from&&(a.from=Cc(t.from)),Fe(o,"CALL_EXCEPTION",{action:e,data:n,reason:i,transaction:a,invocation:null,revert:s})}(e,t,n,qu.defaultAbiCoder())}}function Ju(e){return e&&"function"==typeof e.getAddress}async function Qu(e,t){const n=await t;return null!=n&&"0x0000000000000000000000000000000000000000"!==n||(_e("string"!=typeof e,"unconfigured name","UNCONFIGURED_NAME",{value:e}),Me(!1,"invalid AddressLike value; did not resolve to a value address","target",e)),Cc(n)}function Zu(e,t){return"string"==typeof e?e.match(/^0x[0-9a-f]{40}$/i)?Cc(e):(_e(null!=t,"ENS resolution requires a provider","UNSUPPORTED_OPERATION",{operation:"resolveName"}),Qu(e,t.resolveName(e))):Ju(e)?Qu(e,e.getAddress()):e&&"function"==typeof e.then?Qu(e,e):void Me(!1,"unsupported addressable value","target",e)}const Yu=new Uint8Array(32);Yu.fill(0);const Xu=BigInt(-1),el=BigInt(0),tl=BigInt(1),nl=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),rl=sc(tl,32),ol=sc(el,32),il={name:"string",version:"string",chainId:"uint256",verifyingContract:"address",salt:"bytes32"},sl=["name","version","chainId","verifyingContract","salt"];function al(e){return function(t){return Me("string"==typeof t,`invalid domain value for ${JSON.stringify(e)}`,`domain.${e}`,t),t}}const cl={name:al("name"),version:al("version"),chainId:function(e){const t=tc(e,"domain.chainId");return Me(t>=0,"invalid chain ID","domain.chainId",e),Number.isSafeInteger(t)?Number(t):cc(t)},verifyingContract:function(e){try{return Cc(e).toLowerCase()}catch(e){}Me(!1,'invalid domain value "verifyingContract"',"domain.verifyingContract",e)},salt:function(e){const t=Ve(e,"domain.salt");return Me(32===t.length,'invalid domain value "salt"',"domain.salt",e),Qe(t)}};function ul(e){{const t=e.match(/^(u?)int(\d+)$/);if(t){const n=""===t[1],r=parseInt(t[2]);Me(r%8==0&&0!==r&&r<=256&&t[2]===String(r),"invalid numeric width","type",e);const o=ec(nl,n?r-1:r),i=n?(o+tl)*Xu:el;return function(t){const r=tc(t,"value");return Me(r>=i&&r<=o,`value out-of-bounds for ${e}`,"value",r),sc(n?Xa(r,256):r,32)}}}{const t=e.match(/^bytes(\d+)$/);if(t){const n=parseInt(t[1]);return Me(0!==n&&n<=32&&t[1]===String(n),"invalid bytes width","type",e),function(t){return Me(Ve(t).length===n,`invalid length for ${e}`,"value",t),function(e){const t=Ve(e),n=t.length%32;return n?Ze([t,Yu.slice(n)]):Qe(t)}(t)}}}switch(e){case"address":return function(e){return tt(Cc(e),32)};case"bool":return function(e){return e?rl:ol};case"bytes":return function(e){return In(e)};case"string":return function(e){return Zc(e)}}return null}function ll(e,t){return`${e}(${t.map(({name:e,type:t})=>t+" "+e).join(",")})`}function fl(e){const t=e.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);return t?{base:t[1],index:t[2]+t[4],array:{base:t[1],prefix:t[1]+t[2],count:t[5]?parseInt(t[5]):-1}}:{base:e}}class hl{primaryType;#g;get types(){return JSON.parse(this.#g)}#y;#m;constructor(e){this.#y=new Map,this.#m=new Map;const t=new Map,n=new Map,r=new Map,o={};Object.keys(e).forEach(i=>{o[i]=e[i].map(({name:t,type:n})=>{let{base:r,index:o}=fl(n);return"int"!==r||e.int||(r="int256"),"uint"!==r||e.uint||(r="uint256"),{name:t,type:r+(o||"")}}),t.set(i,new Set),n.set(i,[]),r.set(i,new Set)}),this.#g=JSON.stringify(o);for(const r in o){const i=new Set;for(const s of o[r]){Me(!i.has(s.name),`duplicate variable name ${JSON.stringify(s.name)} in ${JSON.stringify(r)}`,"types",e),i.add(s.name);const o=fl(s.type).base;Me(o!==r,`circular type reference to ${JSON.stringify(o)}`,"types",e),ul(o)||(Me(n.has(o),`unknown type ${JSON.stringify(o)}`,"types",e),n.get(o).push(r),t.get(r).add(o))}}const i=Array.from(n.keys()).filter(e=>0===n.get(e).length);Me(0!==i.length,"missing primary type","types",e),Me(1===i.length,`ambiguous primary types or unused types: ${i.map(e=>JSON.stringify(e)).join(", ")}`,"types",e),Re(this,{primaryType:i[0]}),function o(i,s){Me(!s.has(i),`circular type reference to ${JSON.stringify(i)}`,"types",e),s.add(i);for(const e of t.get(i))if(n.has(e)){o(e,s);for(const t of s)r.get(t).add(e)}s.delete(i)}(this.primaryType,new Set);for(const[e,t]of r){const n=Array.from(t);n.sort(),this.#y.set(e,ll(e,o[e])+n.map(e=>ll(e,o[e])).join(""))}}getEncoder(e){let t=this.#m.get(e);return t||(t=this.#w(e),this.#m.set(e,t)),t}#w(e){{const t=ul(e);if(t)return t}const t=fl(e).array;if(t){const e=t.prefix,n=this.getEncoder(e);return r=>{Me(-1===t.count||t.count===r.length,`array length mismatch; expected length ${t.count}`,"value",r);let o=r.map(n);return this.#y.has(e)&&(o=o.map(In)),In(Ze(o))}}const n=this.types[e];if(n){const t=Zc(this.#y.get(e));return e=>{const r=n.map(({name:t,type:n})=>{const r=this.getEncoder(n)(e[t]);return this.#y.has(n)?In(r):r});return r.unshift(t),Ze(r)}}Me(!1,`unknown type: ${e}`,"type",e)}encodeType(e){const t=this.#y.get(e);return Me(t,`unknown type: ${JSON.stringify(e)}`,"name",e),t}encodeData(e,t){return this.getEncoder(e)(t)}hashStruct(e,t){return In(this.encodeData(e,t))}encode(e){return this.encodeData(this.primaryType,e)}hash(e){return this.hashStruct(this.primaryType,e)}_visit(e,t,n){if(ul(e))return n(e,t);const r=fl(e).array;if(r)return Me(-1===r.count||r.count===t.length,`array length mismatch; expected length ${r.count}`,"value",t),t.map(e=>this._visit(r.prefix,e,n));const o=this.types[e];if(o)return o.reduce((e,{name:r,type:o})=>(e[r]=this._visit(o,t[r],n),e),{});Me(!1,`unknown type: ${e}`,"type",e)}visit(e,t){return this._visit(this.primaryType,e,t)}static from(e){return new hl(e)}static getPrimaryType(e){return hl.from(e).primaryType}static hashStruct(e,t,n){return hl.from(t).hashStruct(e,n)}static hashDomain(e){const t=[];for(const n in e){if(null==e[n])continue;const r=il[n];Me(r,`invalid typed-data domain key: ${JSON.stringify(n)}`,"domain",e),t.push({name:n,type:r})}return t.sort((e,t)=>sl.indexOf(e.name)-sl.indexOf(t.name)),hl.hashStruct("EIP712Domain",{EIP712Domain:t},e)}static encode(e,t,n){return Ze(["0x1901",hl.hashDomain(e),hl.from(t).hash(n)])}static hash(e,t,n){return In(hl.encode(e,t,n))}static async resolveNames(e,t,n,r){e=Object.assign({},e);for(const t in e)null==e[t]&&delete e[t];const o={};e.verifyingContract&&!$e(e.verifyingContract,20)&&(o[e.verifyingContract]="0x");const i=hl.from(t);i.visit(n,(e,t)=>("address"!==e||$e(t,20)||(o[t]="0x"),t));for(const e in o)o[e]=await r(e);return e.verifyingContract&&o[e.verifyingContract]&&(e.verifyingContract=o[e.verifyingContract]),{domain:e,value:n=i.visit(n,(e,t)=>"address"===e&&o[t]?o[t]:t)}}static getPayload(e,t,n){hl.hashDomain(e);const r={},o=[];sl.forEach(t=>{const n=e[t];null!=n&&(r[t]=cl[t](n),o.push({name:t,type:il[t]}))});const i=hl.from(t);t=i.types;const s=Object.assign({},t);return Me(null==s.EIP712Domain,"types must not contain EIP712Domain type","types.EIP712Domain",t),s.EIP712Domain=o,i.encode(n),{types:s,domain:r,primaryType:i.primaryType,message:i.visit(n,(e,t)=>{if(e.match(/^bytes(\d*)/))return Qe(Ve(t));if(e.match(/^u?int/))return tc(t).toString();switch(e){case"address":return t.toLowerCase();case"bool":return!!t;case"string":return Me("string"==typeof t,"invalid string","value",t),t}Me(!1,"unsupported type","type",e)})}}}function dl(e,t){return{address:Cc(e),storageKeys:t.map((e,t)=>(Me($e(e,32),"invalid slot",`storageKeys[${t}]`,e),e.toLowerCase()))}}function pl(e){if(Array.isArray(e))return e.map((t,n)=>Array.isArray(t)?(Me(2===t.length,"invalid slot set",`value[${n}]`,t),dl(t[0],t[1])):(Me(null!=t&&"object"==typeof t,"invalid address-slot set","value",e),dl(t.address,t.storageKeys)));Me(null!=e&&"object"==typeof e,"invalid access list","value",e);const t=Object.keys(e).map(t=>{const n=e[t].reduce((e,t)=>(e[t]=!0,e),{});return dl(t,Object.keys(n).sort())});return t.sort((e,t)=>e.address.localeCompare(t.address)),t}const gl="0x0000000000000000000000000000000000000000000000000000000000000000",yl=BigInt(0),ml=BigInt(1),wl=BigInt(2),bl=BigInt(27),vl=BigInt(28),El=BigInt(35),Al=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),xl=Al/wl,kl=Symbol.for("nodejs.util.inspect.custom"),Sl={};function Il(e){return tt(ac(e),32)}class Pl{#b;#v;#E;#A;get r(){return this.#b}set r(e){Me(32===Ye(e),"invalid r","value",e),this.#b=Qe(e)}get s(){return Me(parseInt(this.#v.substring(0,3))<8,"non-canonical s; use ._s","s",this.#v),this.#v}set s(e){Me(32===Ye(e),"invalid s","value",e),this.#v=Qe(e)}get _s(){return this.#v}isValid(){return BigInt(this.#v)<=xl}get v(){return this.#E}set v(e){const t=ic(e,"value");Me(27===t||28===t,"invalid v","v",e),this.#E=t}get networkV(){return this.#A}get legacyChainId(){const e=this.networkV;return null==e?null:Pl.getChainId(e)}get yParity(){return 27===this.v?0:1}get yParityAndS(){const e=Ve(this.s);return this.yParity&&(e[0]|=128),Qe(e)}get compactSerialized(){return Ze([this.r,this.yParityAndS])}get serialized(){return Ze([this.r,this.s,this.yParity?"0x1c":"0x1b"])}constructor(e,t,n,r){ze(e,Sl,"Signature"),this.#b=t,this.#v=n,this.#E=r,this.#A=null}getCanonical(){if(this.isValid())return this;const e=Al-BigInt(this._s),t=55-this.v,n=new Pl(Sl,this.r,Il(e),t);return this.networkV&&(n.#A=this.networkV),n}clone(){const e=new Pl(Sl,this.r,this._s,this.v);return this.networkV&&(e.#A=this.networkV),e}toJSON(){const e=this.networkV;return{_type:"signature",networkV:null!=e?e.toString():null,r:this.r,s:this._s,v:this.v}}[kl](){return this.toString()}toString(){return this.isValid()?`Signature { r: ${this.r}, s: ${this._s}, v: ${this.v} }`:`Signature { r: ${this.r}, s: ${this._s}, v: ${this.v}, valid: false }`}static getChainId(e){const t=tc(e,"v");return t==bl||t==vl?yl:(Me(t>=El,"invalid EIP-155 v","v",e),(t-El)/wl)}static getChainIdV(e,t){return tc(e)*wl+BigInt(35+t-27)}static getNormalizedV(e){const t=tc(e);return t===yl||t===bl?27:t===ml||t===vl?28:(Me(t>=El,"invalid v","v",e),t&ml?27:28)}static from(e){function t(t,n){Me(t,n,"signature",e)}if(null==e)return new Pl(Sl,gl,gl,27);if("string"==typeof e){const n=Ve(e,"signature");if(64===n.length){const e=Qe(n.slice(0,32)),t=n.slice(32,64),r=128&t[0]?28:27;return t[0]&=127,new Pl(Sl,e,Qe(t),r)}if(65===n.length){const e=Qe(n.slice(0,32)),t=Qe(n.slice(32,64)),r=Pl.getNormalizedV(n[64]);return new Pl(Sl,e,t,r)}t(!1,"invalid raw signature length")}if(e instanceof Pl)return e.clone();const n=e.r;t(null!=n,"missing r");const r=Il(n),o=function(e,n){if(null!=e)return Il(e);if(null!=n){t($e(n,32),"invalid yParityAndS");const e=Ve(n);return e[0]&=127,Qe(e)}t(!1,"missing s")}(e.s,e.yParityAndS),{networkV:i,v:s}=function(e,n,r){if(null!=e){const t=tc(e);return{networkV:t>=El?t:void 0,v:Pl.getNormalizedV(t)}}if(null!=n)return t($e(n,32),"invalid yParityAndS"),{v:128&Ve(n)[0]?28:27};if(null!=r){switch(ic(r,"sig.yParity")){case 0:return{v:27};case 1:return{v:28}}t(!1,"invalid yParity")}t(!1,"missing v")}(e.v,e.yParityAndS,e.yParity),a=new Pl(Sl,r,o,s);return i&&(a.#A=i),t(null==e.yParity||ic(e.yParity,"sig.yParity")===a.yParity,"yParity mismatch"),t(null==e.yParityAndS||e.yParityAndS===a.yParityAndS,"yParityAndS mismatch"),a}}function Cl(e){return{address:Cc(e.address),nonce:tc(null!=e.nonce?e.nonce:0),chainId:tc(null!=e.chainId?e.chainId:0),signature:Pl.from(e.signature)}}function Ol(e){return async function(t,n){_e(null==n||!n.cancelled,"request cancelled before sending","CANCELLED");const r=t.url.split(":")[0].toLowerCase();_e("http"===r||"https"===r,`unsupported protocol ${r}`,"UNSUPPORTED_OPERATION",{info:{protocol:r},operation:"request"}),_e("https"===r||!t.credentials||t.allowInsecureAuthentication,"insecure authorized connections unsupported","UNSUPPORTED_OPERATION",{operation:"request"});let o=null;const i=new AbortController,s=setTimeout(()=>{o=Fe("request timeout","TIMEOUT"),i.abort()},t.timeout);n&&n.addListener(()=>{o=Fe("request cancelled","CANCELLED"),i.abort()});const a=Object.assign({},e,{method:t.method,headers:new Headers(Array.from(t)),body:t.body||void 0,signal:i.signal});let c;try{c=await fetch(t.url,a)}catch(e){if(clearTimeout(s),o)throw o;throw e}clearTimeout(s);const u={};c.headers.forEach((e,t)=>{u[t.toLowerCase()]=e});const l=await c.arrayBuffer(),f=null==l?null:new Uint8Array(l);return{statusCode:c.status,statusMessage:c.statusText,headers:u,body:f}}}Ol({});let Nl=Ol();const Bl=new RegExp("^data:([^;:]*)?(;base64)?,(.*)$","i"),Tl=new RegExp("^ipfs://(ipfs/)?(.*)$","i");let Rl=!1;async function Ul(e,t){try{const t=e.match(Bl);if(!t)throw new Error("invalid data");return new Gl(200,"OK",{"content-type":t[1]||"text/plain"},t[2]?function(e){e=atob(e);const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return Ve(t)}(t[3]):ot(t[3].replace(/%([0-9a-f][0-9a-f])/gi,(e,t)=>String.fromCharCode(parseInt(t,16)))))}catch(t){return new Gl(599,"BAD REQUEST (invalid data: URI)",{},null,new jl(e))}}function Dl(e){return async function(t,n){try{const n=t.match(Tl);if(!n)throw new Error("invalid link");return new jl(`${e}${n[2]}`)}catch(e){return new Gl(599,"BAD REQUEST (invalid IPFS URI)",{},null,new jl(t))}}}const Ll={data:Ul,ipfs:Dl("https://gateway.ipfs.io/ipfs/")},Fl=new WeakMap;class _l{#x;#k;constructor(e){this.#x=[],this.#k=!1,Fl.set(e,()=>{if(!this.#k){this.#k=!0;for(const e of this.#x)setTimeout(()=>{e()},0);this.#x=[]}})}addListener(e){_e(!this.#k,"singal already cancelled","UNSUPPORTED_OPERATION",{operation:"fetchCancelSignal.addCancelListener"}),this.#x.push(e)}get cancelled(){return this.#k}checkSignal(){_e(!this.cancelled,"cancelled","CANCELLED",{})}}function Ml(e){if(null==e)throw new Error("missing signal; should not happen");return e.checkSignal(),e}class jl{#S;#I;#P;#C;#O;#N;#B;#T;#R;#U;#D;#L;#F;#_;#M;get url(){return this.#N}set url(e){this.#N=String(e)}get body(){return null==this.#B?null:new Uint8Array(this.#B)}set body(e){if(null==e)this.#B=void 0,this.#T=void 0;else if("string"==typeof e)this.#B=ot(e),this.#T="text/plain";else if(e instanceof Uint8Array)this.#B=e,this.#T="application/octet-stream";else{if("object"!=typeof e)throw new Error("invalid body");this.#B=ot(JSON.stringify(e)),this.#T="application/json"}}hasBody(){return null!=this.#B}get method(){return this.#C?this.#C:this.hasBody()?"POST":"GET"}set method(e){null==e&&(e=""),this.#C=String(e).toUpperCase()}get headers(){const e=Object.assign({},this.#P);return this.#R&&(e.authorization=`Basic ${function(e){const t=Ve(e);let n="";for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)}(ot(this.#R))}`),this.allowGzip&&(e["accept-encoding"]="gzip"),null==e["content-type"]&&this.#T&&(e["content-type"]=this.#T),this.body&&(e["content-length"]=String(this.body.length)),e}getHeader(e){return this.headers[e.toLowerCase()]}setHeader(e,t){this.#P[String(e).toLowerCase()]=String(t)}clearHeaders(){this.#P={}}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const r=t[n++];return{value:[r,e[r]],done:!1}}return{value:void 0,done:!0}}}}get credentials(){return this.#R||null}setCredentials(e,t){Me(!e.match(/:/),"invalid basic authentication username","username","[REDACTED]"),this.#R=`${e}:${t}`}get allowGzip(){return this.#I}set allowGzip(e){this.#I=!!e}get allowInsecureAuthentication(){return!!this.#S}set allowInsecureAuthentication(e){this.#S=!!e}get timeout(){return this.#O}set timeout(e){Me(e>=0,"timeout must be non-zero","timeout",e),this.#O=e}get preflightFunc(){return this.#U||null}set preflightFunc(e){this.#U=e}get processFunc(){return this.#D||null}set processFunc(e){this.#D=e}get retryFunc(){return this.#L||null}set retryFunc(e){this.#L=e}get getUrlFunc(){return this.#M||Nl}set getUrlFunc(e){this.#M=e}constructor(e){this.#N=String(e),this.#S=!1,this.#I=!0,this.#P={},this.#C="",this.#O=3e5,this.#_={slotInterval:250,maxAttempts:12},this.#M=null}toString(){return`<FetchRequest method=${JSON.stringify(this.method)} url=${JSON.stringify(this.url)} headers=${JSON.stringify(this.headers)} body=${this.#B?Qe(this.#B):"null"}>`}setThrottleParams(e){null!=e.slotInterval&&(this.#_.slotInterval=e.slotInterval),null!=e.maxAttempts&&(this.#_.maxAttempts=e.maxAttempts)}async#j(e,t,n,r,o){if(e>=this.#_.maxAttempts)return o.makeServerError("exceeded maximum retry limit");_e(Hl()<=t,"timeout","TIMEOUT",{operation:"request.send",reason:"timeout",request:r}),n>0&&await function(e){return new Promise(t=>setTimeout(t,e))}(n);let i=this.clone();const s=(i.url.split(":")[0]||"").toLowerCase();if(s in Ll){const e=await Ll[s](i.url,Ml(r.#F));if(e instanceof Gl){let t=e;if(this.processFunc){Ml(r.#F);try{t=await this.processFunc(i,t)}catch(e){null!=e.throttle&&"number"==typeof e.stall||t.makeServerError("error in post-processing function",e).assertOk()}}return t}i=e}this.preflightFunc&&(i=await this.preflightFunc(i));const a=await this.getUrlFunc(i,Ml(r.#F));let c=new Gl(a.statusCode,a.statusMessage,a.headers,a.body,r);if(301===c.statusCode||302===c.statusCode){try{const n=c.headers.location||"";return i.redirect(n).#j(e+1,t,0,r,c)}catch(e){}return c}if(429===c.statusCode&&(null==this.retryFunc||await this.retryFunc(i,c,e))){const n=c.headers["retry-after"];let o=this.#_.slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return"string"==typeof n&&n.match(/^[1-9][0-9]*$/)&&(o=parseInt(n)),i.clone().#j(e+1,t,o,r,c)}if(this.processFunc){Ml(r.#F);try{c=await this.processFunc(i,c)}catch(n){null!=n.throttle&&"number"==typeof n.stall||c.makeServerError("error in post-processing function",n).assertOk();let o=this.#_.slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return n.stall>=0&&(o=n.stall),i.clone().#j(e+1,t,o,r,c)}}return c}send(){return _e(null==this.#F,"request already sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.send"}),this.#F=new _l(this),this.#j(0,Hl()+this.timeout,0,this,new Gl(0,"",{},null,this))}cancel(){_e(null!=this.#F,"request has not been sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.cancel"});const e=Fl.get(this);if(!e)throw new Error("missing signal; should not happen");e()}redirect(e){const t=this.url.split(":")[0].toLowerCase(),n=e.split(":")[0].toLowerCase();_e("GET"===this.method&&("https"!==t||"http"!==n)&&e.match(/^https?:/),"unsupported redirect","UNSUPPORTED_OPERATION",{operation:`redirect(${this.method} ${JSON.stringify(this.url)} => ${JSON.stringify(e)})`});const r=new jl(e);return r.method="GET",r.allowGzip=this.allowGzip,r.timeout=this.timeout,r.#P=Object.assign({},this.#P),this.#B&&(r.#B=new Uint8Array(this.#B)),r.#T=this.#T,r}clone(){const e=new jl(this.url);return e.#C=this.#C,this.#B&&(e.#B=this.#B),e.#T=this.#T,e.#P=Object.assign({},this.#P),e.#R=this.#R,this.allowGzip&&(e.allowGzip=!0),e.timeout=this.timeout,this.allowInsecureAuthentication&&(e.allowInsecureAuthentication=!0),e.#U=this.#U,e.#D=this.#D,e.#L=this.#L,e.#_=Object.assign({},this.#_),e.#M=this.#M,e}static lockConfig(){Rl=!0}static getGateway(e){return Ll[e.toLowerCase()]||null}static registerGateway(e,t){if("http"===(e=e.toLowerCase())||"https"===e)throw new Error(`cannot intercept ${e}; use registerGetUrl`);if(Rl)throw new Error("gateways locked");Ll[e]=t}static registerGetUrl(e){if(Rl)throw new Error("gateways locked");Nl=e}static createGetUrlFunc(e){return Ol(e)}static createDataGateway(){return Ul}static createIpfsGatewayFunc(e){return Dl(e)}}class Gl{#G;#H;#P;#B;#z;#K;toString(){return`<FetchResponse status=${this.statusCode} body=${this.#B?Qe(this.#B):"null"}>`}get statusCode(){return this.#G}get statusMessage(){return this.#H}get headers(){return Object.assign({},this.#P)}get body(){return null==this.#B?null:new Uint8Array(this.#B)}get bodyText(){try{return null==this.#B?"":it(this.#B)}catch(e){_e(!1,"response body is not valid UTF-8 data","UNSUPPORTED_OPERATION",{operation:"bodyText",info:{response:this}})}}get bodyJson(){try{return JSON.parse(this.bodyText)}catch(e){_e(!1,"response body is not valid JSON","UNSUPPORTED_OPERATION",{operation:"bodyJson",info:{response:this}})}}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const r=t[n++];return{value:[r,e[r]],done:!1}}return{value:void 0,done:!0}}}}constructor(e,t,n,r,o){this.#G=e,this.#H=t,this.#P=Object.keys(n).reduce((e,t)=>(e[t.toLowerCase()]=String(n[t]),e),{}),this.#B=null==r?null:new Uint8Array(r),this.#z=o||null,this.#K={message:""}}makeServerError(e,t){let n;n=e?`CLIENT ESCALATED SERVER ERROR (${this.statusCode} ${this.statusMessage}; ${e})`:`CLIENT ESCALATED SERVER ERROR (${e=`${this.statusCode} ${this.statusMessage}`})`;const r=new Gl(599,n,this.headers,this.body,this.#z||void 0);return r.#K={message:e,error:t},r}throwThrottleError(e,t){null==t?t=-1:Me(Number.isInteger(t)&&t>=0,"invalid stall timeout","stall",t);const n=new Error(e||"throttling requests");throw Re(n,{stall:t,throttle:!0}),n}getHeader(e){return this.headers[e.toLowerCase()]}hasBody(){return null!=this.#B}get request(){return this.#z}ok(){return""===this.#K.message&&this.statusCode>=200&&this.statusCode<300}assertOk(){if(this.ok())return;let{message:e,error:t}=this.#K;""===e&&(e=`server response ${this.statusCode} ${this.statusMessage}`);let n=null;this.request&&(n=this.request.url);let r=null;try{this.#B&&(r=it(this.#B))}catch(e){}_e(!1,e,"SERVER_ERROR",{request:this.request||"unknown request",response:this,error:t,info:{requestUrl:n,responseBody:r,responseStatus:`${this.statusCode} ${this.statusMessage}`}})}}function Hl(){return(new Date).getTime()}const zl="0x0000000000000000000000000000000000000000";class Kl{fragment;name;signature;topic;args;constructor(e,t,n){const r=e.name,o=e.format();Re(this,{fragment:e,name:r,signature:o,topic:t,args:n})}}class Vl{fragment;name;args;signature;selector;value;constructor(e,t,n,r){const o=e.name,i=e.format();Re(this,{fragment:e,name:o,args:n,signature:i,selector:t,value:r})}}class Wl{fragment;name;args;signature;selector;constructor(e,t,n){const r=e.name,o=e.format();Re(this,{fragment:e,name:r,args:n,signature:o,selector:t})}}class $l{hash;_isIndexed;static isIndexed(e){return!(!e||!e._isIndexed)}constructor(e){Re(this,{hash:e,_isIndexed:!0})}}const ql={0:"generic panic",1:"assert(false)",17:"arithmetic overflow",18:"division or modulo by zero",33:"enum overflow",34:"invalid encoded storage byte array accessed",49:"out-of-bounds array access; popping on an empty array",50:"out-of-bounds access of an array or bytesN",65:"out of memory",81:"uninitialized function"},Jl={"0x08c379a0":{signature:"Error(string)",name:"Error",inputs:["string"],reason:e=>`reverted with reason string ${JSON.stringify(e)}`},"0x4e487b71":{signature:"Panic(uint256)",name:"Panic",inputs:["uint256"],reason:e=>{let t="unknown panic code";return e>=0&&e<=255&&ql[e.toString()]&&(t=ql[e.toString()]),`reverted with panic code 0x${e.toString(16)} (${t})`}}};class Ql{fragments;deploy;fallback;receive;#V;#W;#$;#q;constructor(e){let t=[];t="string"==typeof e?JSON.parse(e):e,this.#$=new Map,this.#V=new Map,this.#W=new Map;const n=[];for(const e of t)try{n.push(Uu.from(e))}catch(t){console.log(`[Warning] Invalid Fragment ${JSON.stringify(e)}:`,t.message)}Re(this,{fragments:Object.freeze(n)});let r=null,o=!1;this.#q=this.getAbiCoder(),this.fragments.forEach((e,t)=>{let n;switch(e.type){case"constructor":return this.deploy?void console.log("duplicate definition - constructor"):void Re(this,{deploy:e});case"fallback":return void(0===e.inputs.length?o=!0:(Me(!r||e.payable!==r.payable,"conflicting fallback fragments",`fragments[${t}]`,e),r=e,o=r.payable));case"function":n=this.#$;break;case"event":n=this.#W;break;case"error":n=this.#V;break;default:return}const i=e.format();n.has(i)||n.set(i,e)}),this.deploy||Re(this,{deploy:Mu.from("constructor()")}),Re(this,{fallback:r,receive:o})}format(e){const t=e?"minimal":"full",n=this.fragments.map(e=>e.format(t));return n}formatJson(){const e=this.fragments.map(e=>e.format("json"));return JSON.stringify(e.map(e=>JSON.parse(e)))}getAbiCoder(){return qu.defaultAbiCoder()}#J(e,t,n){if($e(e)){const t=e.toLowerCase();for(const e of this.#$.values())if(t===e.selector)return e;return null}if(-1===e.indexOf("(")){const r=[];for(const[t,n]of this.#$)t.split("(")[0]===e&&r.push(n);if(t){const e=t.length>0?t[t.length-1]:null;let n=t.length,o=!0;Rc.isTyped(e)&&"overrides"===e.type&&(o=!1,n--);for(let e=r.length-1;e>=0;e--){const t=r[e].inputs.length;t===n||o&&t===n-1||r.splice(e,1)}for(let e=r.length-1;e>=0;e--){const n=r[e].inputs;for(let o=0;o<t.length;o++)if(Rc.isTyped(t[o])){if(o>=n.length){if("overrides"===t[o].type)continue;r.splice(e,1);break}if(t[o].type!==n[o].baseType){r.splice(e,1);break}}}}if(1===r.length&&t&&t.length!==r[0].inputs.length){const e=t[t.length-1];(null==e||Array.isArray(e)||"object"!=typeof e)&&r.splice(0,1)}return 0===r.length?null:(r.length>1&&n&&Me(!1,`ambiguous function description (i.e. matches ${r.map(e=>JSON.stringify(e.format())).join(", ")})`,"key",e),r[0])}return this.#$.get(Gu.from(e).format())||null}getFunctionName(e){const t=this.#J(e,null,!1);return Me(t,"no matching function","key",e),t.name}hasFunction(e){return!!this.#J(e,null,!1)}getFunction(e,t){return this.#J(e,t||null,!0)}forEachFunction(e){const t=Array.from(this.#$.keys());t.sort((e,t)=>e.localeCompare(t));for(let n=0;n<t.length;n++){const r=t[n];e(this.#$.get(r),n)}}#Q(e,t,n){if($e(e)){const t=e.toLowerCase();for(const e of this.#W.values())if(t===e.topicHash)return e;return null}if(-1===e.indexOf("(")){const r=[];for(const[t,n]of this.#W)t.split("(")[0]===e&&r.push(n);if(t){for(let e=r.length-1;e>=0;e--)r[e].inputs.length<t.length&&r.splice(e,1);for(let e=r.length-1;e>=0;e--){const n=r[e].inputs;for(let o=0;o<t.length;o++)if(Rc.isTyped(t[o])&&t[o].type!==n[o].baseType){r.splice(e,1);break}}}return 0===r.length?null:(r.length>1&&n&&Me(!1,`ambiguous event description (i.e. matches ${r.map(e=>JSON.stringify(e.format())).join(", ")})`,"key",e),r[0])}return this.#W.get(_u.from(e).format())||null}getEventName(e){const t=this.#Q(e,null,!1);return Me(t,"no matching event","key",e),t.name}hasEvent(e){return!!this.#Q(e,null,!1)}getEvent(e,t){return this.#Q(e,t||null,!0)}forEachEvent(e){const t=Array.from(this.#W.keys());t.sort((e,t)=>e.localeCompare(t));for(let n=0;n<t.length;n++){const r=t[n];e(this.#W.get(r),n)}}getError(e,t){if($e(e)){const t=e.toLowerCase();if(Jl[t])return Fu.from(Jl[t].signature);for(const e of this.#V.values())if(t===e.selector)return e;return null}if(-1===e.indexOf("(")){const t=[];for(const[n,r]of this.#V)n.split("(")[0]===e&&t.push(r);return 0===t.length?"Error"===e?Fu.from("error Error(string)"):"Panic"===e?Fu.from("error Panic(uint256)"):null:(t.length>1&&Me(!1,`ambiguous error description (i.e. ${t.map(e=>JSON.stringify(e.format())).join(", ")})`,"name",e),t[0])}if("Error(string)"===(e=Fu.from(e).format()))return Fu.from("error Error(string)");if("Panic(uint256)"===e)return Fu.from("error Panic(uint256)");return this.#V.get(e)||null}forEachError(e){const t=Array.from(this.#V.keys());t.sort((e,t)=>e.localeCompare(t));for(let n=0;n<t.length;n++){const r=t[n];e(this.#V.get(r),n)}}_decodeParams(e,t){return this.#q.decode(e,t)}_encodeParams(e,t){return this.#q.encode(e,t)}encodeDeploy(e){return this._encodeParams(this.deploy.inputs,e||[])}decodeErrorResult(e,t){if("string"==typeof e){const t=this.getError(e);Me(t,"unknown error","fragment",e),e=t}return Me(Xe(t,0,4)===e.selector,`data signature does not match error ${e.name}.`,"data",t),this._decodeParams(e.inputs,Xe(t,4))}encodeErrorResult(e,t){if("string"==typeof e){const t=this.getError(e);Me(t,"unknown error","fragment",e),e=t}return Ze([e.selector,this._encodeParams(e.inputs,t||[])])}decodeFunctionData(e,t){if("string"==typeof e){const t=this.getFunction(e);Me(t,"unknown function","fragment",e),e=t}return Me(Xe(t,0,4)===e.selector,`data signature does not match function ${e.name}.`,"data",t),this._decodeParams(e.inputs,Xe(t,4))}encodeFunctionData(e,t){if("string"==typeof e){const t=this.getFunction(e);Me(t,"unknown function","fragment",e),e=t}return Ze([e.selector,this._encodeParams(e.inputs,t||[])])}decodeFunctionResult(e,t){if("string"==typeof e){const t=this.getFunction(e);Me(t,"unknown function","fragment",e),e=t}let n="invalid length for result data";const r=We(t);if(r.length%32==0)try{return this.#q.decode(e.outputs,r)}catch(e){n="could not decode result data"}_e(!1,n,"BAD_DATA",{value:Qe(r),info:{method:e.name,signature:e.format()}})}makeError(e,t){const n=Ve(e,"data"),r=qu.getBuiltinCallException("call",t,n);if(r.message.startsWith("execution reverted (unknown custom error)")){const e=Qe(n.slice(0,4)),t=this.getError(e);if(t)try{const e=this.#q.decode(t.inputs,n.slice(4));r.revert={name:t.name,signature:t.format(),args:e},r.reason=r.revert.signature,r.message=`execution reverted: ${r.reason}`}catch(e){r.message="execution reverted (coult not decode custom error)"}}const o=this.parseTransaction(t);return o&&(r.invocation={method:o.name,signature:o.signature,args:o.args}),r}encodeFunctionResult(e,t){if("string"==typeof e){const t=this.getFunction(e);Me(t,"unknown function","fragment",e),e=t}return Qe(this.#q.encode(e.outputs,t||[]))}encodeFilterTopics(e,t){if("string"==typeof e){const t=this.getEvent(e);Me(t,"unknown event","eventFragment",e),e=t}_e(t.length<=e.inputs.length,`too many arguments for ${e.format()}`,"UNEXPECTED_ARGUMENT",{count:t.length,expectedCount:e.inputs.length});const n=[];e.anonymous||n.push(e.topicHash);const r=(e,t)=>"string"===e.type?Zc(t):"bytes"===e.type?In(Qe(t)):("bool"===e.type&&"boolean"==typeof t?t=t?"0x01":"0x00":e.type.match(/^u?int/)?t=sc(t):e.type.match(/^bytes/)?t=et(t,32,!1):"address"===e.type&&this.#q.encode(["address"],[t]),tt(Qe(t),32));for(t.forEach((t,o)=>{const i=e.inputs[o];i.indexed?null==t?n.push(null):"array"===i.baseType||"tuple"===i.baseType?Me(!1,"filtering with tuples or arrays not supported","contract."+i.name,t):Array.isArray(t)?n.push(t.map(e=>r(i,e))):n.push(r(i,t)):Me(null==t,"cannot filter non-indexed parameters; must be null","contract."+i.name,t)});n.length&&null===n[n.length-1];)n.pop();return n}encodeEventLog(e,t){if("string"==typeof e){const t=this.getEvent(e);Me(t,"unknown event","eventFragment",e),e=t}const n=[],r=[],o=[];return e.anonymous||n.push(e.topicHash),Me(t.length===e.inputs.length,"event arguments/values mismatch","values",t),e.inputs.forEach((e,i)=>{const s=t[i];if(e.indexed)if("string"===e.type)n.push(Zc(s));else if("bytes"===e.type)n.push(In(s));else{if("tuple"===e.baseType||"array"===e.baseType)throw new Error("not implemented");n.push(this.#q.encode([e.type],[s]))}else r.push(e),o.push(s)}),{data:this.#q.encode(r,o),topics:n}}decodeEventLog(e,t,n){if("string"==typeof e){const t=this.getEvent(e);Me(t,"unknown event","eventFragment",e),e=t}if(null!=n&&!e.anonymous){const t=e.topicHash;Me($e(n[0],32)&&n[0].toLowerCase()===t,"fragment/topic mismatch","topics[0]",n[0]),n=n.slice(1)}const r=[],o=[],i=[];e.inputs.forEach((e,t)=>{e.indexed?"string"===e.type||"bytes"===e.type||"tuple"===e.baseType||"array"===e.baseType?(r.push(Ru.from({type:"bytes32",name:e.name})),i.push(!0)):(r.push(e),i.push(!1)):(o.push(e),i.push(!1))});const s=null!=n?this.#q.decode(r,Ze(n)):null,a=this.#q.decode(o,t,!0),c=[],u=[];let l=0,f=0;return e.inputs.forEach((e,t)=>{let n=null;if(e.indexed)if(null==s)n=new $l(null);else if(i[t])n=new $l(s[f++]);else try{n=s[f++]}catch(e){n=e}else try{n=a[l++]}catch(e){n=e}c.push(n),u.push(e.name||null)}),wc.fromItems(c,u)}parseTransaction(e){const t=Ve(e.data,"tx.data"),n=tc(null!=e.value?e.value:0,"tx.value"),r=this.getFunction(Qe(t.slice(0,4)));if(!r)return null;const o=this.#q.decode(r.inputs,t.slice(4));return new Vl(r,r.selector,o,n)}parseCallResult(e){throw new Error("@TODO")}parseLog(e){const t=this.getEvent(e.topics[0]);return!t||t.anonymous?null:new Kl(t,t.topicHash,this.decodeEventLog(t,e.data,e.topics))}parseError(e){const t=Qe(e),n=this.getError(Xe(t,0,4));if(!n)return null;const r=this.#q.decode(n.inputs,Xe(t,4));return new Wl(n,n.selector,r)}static from(e){return e instanceof Ql?e:"string"==typeof e?new Ql(JSON.parse(e)):"function"==typeof e.formatJson?new Ql(e.formatJson()):"function"==typeof e.format?new Ql(e.format("json")):new Ql(e)}}const Zl=BigInt(0);function Yl(e){return null==e?null:e}function Xl(e){return null==e?null:e.toString()}class ef{gasPrice;maxFeePerGas;maxPriorityFeePerGas;constructor(e,t,n){Re(this,{gasPrice:Yl(e),maxFeePerGas:Yl(t),maxPriorityFeePerGas:Yl(n)})}toJSON(){const{gasPrice:e,maxFeePerGas:t,maxPriorityFeePerGas:n}=this;return{_type:"FeeData",gasPrice:Xl(e),maxFeePerGas:Xl(t),maxPriorityFeePerGas:Xl(n)}}}function tf(e){const t={};e.to&&(t.to=e.to),e.from&&(t.from=e.from),e.data&&(t.data=Qe(e.data));const n="chainId,gasLimit,gasPrice,maxFeePerBlobGas,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);for(const r of n)r in e&&null!=e[r]&&(t[r]=tc(e[r],`request.${r}`));const r="type,nonce".split(/,/);for(const n of r)n in e&&null!=e[n]&&(t[n]=ic(e[n],`request.${n}`));return e.accessList&&(t.accessList=pl(e.accessList)),e.authorizationList&&(t.authorizationList=e.authorizationList.slice()),"blockTag"in e&&(t.blockTag=e.blockTag),"enableCcipRead"in e&&(t.enableCcipRead=!!e.enableCcipRead),"customData"in e&&(t.customData=e.customData),"blobVersionedHashes"in e&&e.blobVersionedHashes&&(t.blobVersionedHashes=e.blobVersionedHashes.slice()),"kzg"in e&&(t.kzg=e.kzg),"blobWrapperVersion"in e&&(t.blobWrapperVersion=e.blobWrapperVersion),"blobs"in e&&e.blobs&&(t.blobs=e.blobs.map(e=>qe(e)?Qe(e):Object.assign({},e))),t}class nf{provider;number;hash;timestamp;parentHash;parentBeaconBlockRoot;nonce;difficulty;gasLimit;gasUsed;stateRoot;receiptsRoot;blobGasUsed;excessBlobGas;miner;prevRandao;extraData;baseFeePerGas;#Z;constructor(e,t){this.#Z=e.transactions.map(e=>"string"!=typeof e?new sf(e,t):e),Re(this,{provider:t,hash:Yl(e.hash),number:e.number,timestamp:e.timestamp,parentHash:e.parentHash,parentBeaconBlockRoot:e.parentBeaconBlockRoot,nonce:e.nonce,difficulty:e.difficulty,gasLimit:e.gasLimit,gasUsed:e.gasUsed,blobGasUsed:e.blobGasUsed,excessBlobGas:e.excessBlobGas,miner:e.miner,prevRandao:Yl(e.prevRandao),extraData:e.extraData,baseFeePerGas:Yl(e.baseFeePerGas),stateRoot:e.stateRoot,receiptsRoot:e.receiptsRoot})}get transactions(){return this.#Z.map(e=>"string"==typeof e?e:e.hash)}get prefetchedTransactions(){const e=this.#Z.slice();return 0===e.length?[]:(_e("object"==typeof e[0],"transactions were not prefetched with block request","UNSUPPORTED_OPERATION",{operation:"transactionResponses()"}),e)}toJSON(){const{baseFeePerGas:e,difficulty:t,extraData:n,gasLimit:r,gasUsed:o,hash:i,miner:s,prevRandao:a,nonce:c,number:u,parentHash:l,parentBeaconBlockRoot:f,stateRoot:h,receiptsRoot:d,timestamp:p,transactions:g}=this;return{_type:"Block",baseFeePerGas:Xl(e),difficulty:Xl(t),extraData:n,gasLimit:Xl(r),gasUsed:Xl(o),blobGasUsed:Xl(this.blobGasUsed),excessBlobGas:Xl(this.excessBlobGas),hash:i,miner:s,prevRandao:a,nonce:c,number:u,parentHash:l,timestamp:p,parentBeaconBlockRoot:f,stateRoot:h,receiptsRoot:d,transactions:g}}[Symbol.iterator](){let e=0;const t=this.transactions;return{next:()=>e<this.length?{value:t[e++],done:!1}:{value:void 0,done:!0}}}get length(){return this.#Z.length}get date(){return null==this.timestamp?null:new Date(1e3*this.timestamp)}async getTransaction(e){let t;if("number"==typeof e)t=this.#Z[e];else{const n=e.toLowerCase();for(const e of this.#Z){if("string"==typeof e){if(e!==n)continue;t=e;break}if(e.hash===n){t=e;break}}}if(null==t)throw new Error("no such tx");return"string"==typeof t?await this.provider.getTransaction(t):t}getPrefetchedTransaction(e){const t=this.prefetchedTransactions;if("number"==typeof e)return t[e];e=e.toLowerCase();for(const n of t)if(n.hash===e)return n;Me(!1,"no matching transaction","indexOrHash",e)}isMined(){return!!this.hash}isLondon(){return!!this.baseFeePerGas}orphanedEvent(){if(!this.isMined())throw new Error("");return{orphan:"drop-block",hash:this.hash,number:this.number}}}class rf{provider;transactionHash;blockHash;blockNumber;removed;address;data;topics;index;transactionIndex;constructor(e,t){this.provider=t;const n=Object.freeze(e.topics.slice());Re(this,{transactionHash:e.transactionHash,blockHash:e.blockHash,blockNumber:e.blockNumber,removed:e.removed,address:e.address,data:e.data,topics:n,index:e.index,transactionIndex:e.transactionIndex})}toJSON(){const{address:e,blockHash:t,blockNumber:n,data:r,index:o,removed:i,topics:s,transactionHash:a,transactionIndex:c}=this;return{_type:"log",address:e,blockHash:t,blockNumber:n,data:r,index:o,removed:i,topics:s,transactionHash:a,transactionIndex:c}}async getBlock(){const e=await this.provider.getBlock(this.blockHash);return _e(!!e,"failed to find transaction","UNKNOWN_ERROR",{}),e}async getTransaction(){const e=await this.provider.getTransaction(this.transactionHash);return _e(!!e,"failed to find transaction","UNKNOWN_ERROR",{}),e}async getTransactionReceipt(){const e=await this.provider.getTransactionReceipt(this.transactionHash);return _e(!!e,"failed to find transaction receipt","UNKNOWN_ERROR",{}),e}removedEvent(){return{orphan:"drop-log",log:{transactionHash:(e=this).transactionHash,blockHash:e.blockHash,blockNumber:e.blockNumber,address:e.address,data:e.data,topics:Object.freeze(e.topics.slice()),index:e.index}};var e}}class of{provider;to;from;contractAddress;hash;index;blockHash;blockNumber;logsBloom;gasUsed;blobGasUsed;cumulativeGasUsed;gasPrice;blobGasPrice;type;status;root;#Y;constructor(e,t){this.#Y=Object.freeze(e.logs.map(e=>new rf(e,t)));let n=Zl;null!=e.effectiveGasPrice?n=e.effectiveGasPrice:null!=e.gasPrice&&(n=e.gasPrice),Re(this,{provider:t,to:e.to,from:e.from,contractAddress:e.contractAddress,hash:e.hash,index:e.index,blockHash:e.blockHash,blockNumber:e.blockNumber,logsBloom:e.logsBloom,gasUsed:e.gasUsed,cumulativeGasUsed:e.cumulativeGasUsed,blobGasUsed:e.blobGasUsed,gasPrice:n,blobGasPrice:e.blobGasPrice,type:e.type,status:e.status,root:e.root})}get logs(){return this.#Y}toJSON(){const{to:e,from:t,contractAddress:n,hash:r,index:o,blockHash:i,blockNumber:s,logsBloom:a,logs:c,status:u,root:l}=this;return{_type:"TransactionReceipt",blockHash:i,blockNumber:s,contractAddress:n,cumulativeGasUsed:Xl(this.cumulativeGasUsed),from:t,gasPrice:Xl(this.gasPrice),blobGasUsed:Xl(this.blobGasUsed),blobGasPrice:Xl(this.blobGasPrice),gasUsed:Xl(this.gasUsed),hash:r,index:o,logs:c,logsBloom:a,root:l,status:u,to:e}}get length(){return this.logs.length}[Symbol.iterator](){let e=0;return{next:()=>e<this.length?{value:this.logs[e++],done:!1}:{value:void 0,done:!0}}}get fee(){return this.gasUsed*this.gasPrice}async getBlock(){const e=await this.provider.getBlock(this.blockHash);if(null==e)throw new Error("TODO");return e}async getTransaction(){const e=await this.provider.getTransaction(this.hash);if(null==e)throw new Error("TODO");return e}async getResult(){return await this.provider.getTransactionResult(this.hash)}async confirmations(){return await this.provider.getBlockNumber()-this.blockNumber+1}removedEvent(){return cf(this)}reorderedEvent(e){return _e(!e||e.isMined(),"unmined 'other' transction cannot be orphaned","UNSUPPORTED_OPERATION",{operation:"reorderedEvent(other)"}),af(this,e)}}class sf{provider;blockNumber;blockHash;index;hash;type;to;from;nonce;gasLimit;gasPrice;maxPriorityFeePerGas;maxFeePerGas;maxFeePerBlobGas;data;value;chainId;signature;accessList;blobVersionedHashes;authorizationList;#X;constructor(e,t){this.provider=t,this.blockNumber=null!=e.blockNumber?e.blockNumber:null,this.blockHash=null!=e.blockHash?e.blockHash:null,this.hash=e.hash,this.index=e.index,this.type=e.type,this.from=e.from,this.to=e.to||null,this.gasLimit=e.gasLimit,this.nonce=e.nonce,this.data=e.data,this.value=e.value,this.gasPrice=e.gasPrice,this.maxPriorityFeePerGas=null!=e.maxPriorityFeePerGas?e.maxPriorityFeePerGas:null,this.maxFeePerGas=null!=e.maxFeePerGas?e.maxFeePerGas:null,this.maxFeePerBlobGas=null!=e.maxFeePerBlobGas?e.maxFeePerBlobGas:null,this.chainId=e.chainId,this.signature=e.signature,this.accessList=null!=e.accessList?e.accessList:null,this.blobVersionedHashes=null!=e.blobVersionedHashes?e.blobVersionedHashes:null,this.authorizationList=null!=e.authorizationList?e.authorizationList:null,this.#X=-1}toJSON(){const{blockNumber:e,blockHash:t,index:n,hash:r,type:o,to:i,from:s,nonce:a,data:c,signature:u,accessList:l,blobVersionedHashes:f}=this;return{_type:"TransactionResponse",accessList:l,blockNumber:e,blockHash:t,blobVersionedHashes:f,chainId:Xl(this.chainId),data:c,from:s,gasLimit:Xl(this.gasLimit),gasPrice:Xl(this.gasPrice),hash:r,maxFeePerGas:Xl(this.maxFeePerGas),maxPriorityFeePerGas:Xl(this.maxPriorityFeePerGas),maxFeePerBlobGas:Xl(this.maxFeePerBlobGas),nonce:a,signature:u,to:i,index:n,type:o,value:Xl(this.value)}}async getBlock(){let e=this.blockNumber;if(null==e){const t=await this.getTransaction();t&&(e=t.blockNumber)}if(null==e)return null;const t=this.provider.getBlock(e);if(null==t)throw new Error("TODO");return t}async getTransaction(){return this.provider.getTransaction(this.hash)}async confirmations(){if(null==this.blockNumber){const{tx:e,blockNumber:t}=await Te({tx:this.getTransaction(),blockNumber:this.provider.getBlockNumber()});return null==e||null==e.blockNumber?0:t-e.blockNumber+1}return await this.provider.getBlockNumber()-this.blockNumber+1}async wait(e,t){const n=null==e?1:e,r=null==t?0:t;let o=this.#X,i=-1,s=-1===o;const a=async()=>{if(s)return null;const{blockNumber:e,nonce:t}=await Te({blockNumber:this.provider.getBlockNumber(),nonce:this.provider.getTransactionCount(this.from)});if(t<this.nonce)return void(o=e);if(s)return null;const r=await this.getTransaction();if(!r||null==r.blockNumber)for(-1===i&&(i=o-3,i<this.#X&&(i=this.#X));i<=e;){if(s)return null;const t=await this.provider.getBlock(i,!0);if(null==t)return;for(const e of t)if(e===this.hash)return;for(let r=0;r<t.length;r++){const i=await t.getTransaction(r);if(i.from===this.from&&i.nonce===this.nonce){if(s)return null;const t=await this.provider.getTransactionReceipt(i.hash);if(null==t)return;if(e-t.blockNumber+1<n)return;let r="replaced";i.data===this.data&&i.to===this.to&&i.value===this.value?r="repriced":"0x"===i.data&&i.from===i.to&&i.value===Zl&&(r="cancelled"),_e(!1,"transaction was replaced","TRANSACTION_REPLACED",{cancelled:"replaced"===r||"cancelled"===r,reason:r,replacement:i.replaceableTransaction(o),hash:i.hash,receipt:t})}}i++}},c=e=>{if(null==e||0!==e.status)return e;_e(!1,"transaction execution reverted","CALL_EXCEPTION",{action:"sendTransaction",data:null,reason:null,invocation:null,revert:null,transaction:{to:e.to,from:e.from,data:""},receipt:e})},u=await this.provider.getTransactionReceipt(this.hash);if(0===n)return c(u);if(u){if(1===n||await u.confirmations()>=n)return c(u)}else if(await a(),0===n)return null;const l=new Promise((e,t)=>{const i=[],u=()=>{i.forEach(e=>e())};if(i.push(()=>{s=!0}),r>0){const e=setTimeout(()=>{u(),t(Fe("wait for transaction timeout","TIMEOUT"))},r);i.push(()=>{clearTimeout(e)})}const l=async r=>{if(await r.confirmations()>=n){u();try{e(c(r))}catch(e){t(e)}}};if(i.push(()=>{this.provider.off(this.hash,l)}),this.provider.on(this.hash,l),o>=0){const e=async()=>{try{await a()}catch(e){if(De(e,"TRANSACTION_REPLACED"))return u(),void t(e)}s||this.provider.once("block",e)};i.push(()=>{this.provider.off("block",e)}),this.provider.once("block",e)}});return await l}isMined(){return null!=this.blockHash}isLegacy(){return 0===this.type}isBerlin(){return 1===this.type}isLondon(){return 2===this.type}isCancun(){return 3===this.type}removedEvent(){return _e(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),cf(this)}reorderedEvent(e){return _e(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),_e(!e||e.isMined(),"unmined 'other' transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),af(this,e)}replaceableTransaction(e){Me(Number.isInteger(e)&&e>=0,"invalid startBlock","startBlock",e);const t=new sf(this,this.provider);return t.#X=e,t}}function af(e,t){return{orphan:"reorder-transaction",tx:e,other:t}}function cf(e){return{orphan:"drop-transaction",tx:e}}class uf{filter;emitter;#ee;constructor(e,t,n){this.#ee=t,Re(this,{emitter:e,filter:n})}async removeListener(){null!=this.#ee&&await this.emitter.off(this.filter,this.#ee)}}class lf extends rf{interface;fragment;args;constructor(e,t,n){super(e,e.provider),Re(this,{args:t.decodeEventLog(n,e.data,e.topics),fragment:n,interface:t})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}class ff extends rf{error;constructor(e,t){super(e,e.provider),Re(this,{error:t})}}class hf extends of{#te;constructor(e,t,n){super(n,t),this.#te=e}get logs(){return super.logs.map(e=>{const t=e.topics.length?this.#te.getEvent(e.topics[0]):null;if(t)try{return new lf(e,this.#te,t)}catch(t){return new ff(e,t)}return e})}}class df extends sf{#te;constructor(e,t,n){super(n,t),this.#te=e}async wait(e,t){const n=await super.wait(e,t);return null==n?null:new hf(this.#te,this.provider,n)}}class pf extends uf{log;constructor(e,t,n,r){super(e,t,n),Re(this,{log:r})}async getBlock(){return await this.log.getBlock()}async getTransaction(){return await this.log.getTransaction()}async getTransactionReceipt(){return await this.log.getTransactionReceipt()}}class gf extends pf{constructor(e,t,n,r,o){super(e,t,n,new lf(o,e.interface,r)),Re(this,{args:e.interface.decodeEventLog(r,this.log.data,this.log.topics),fragment:r})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}const yf=BigInt(0);function mf(e){return e&&"function"==typeof e.call}function wf(e){return e&&"function"==typeof e.estimateGas}function bf(e){return e&&"function"==typeof e.resolveName}function vf(e){return e&&"function"==typeof e.sendTransaction}function Ef(e){if(null!=e){if(bf(e))return e;if(e.provider)return e.provider}}class Af{#ne;fragment;constructor(e,t,n){if(Re(this,{fragment:t}),t.inputs.length<n.length)throw new Error("too many arguments");const r=xf(e.runner,"resolveName"),o=bf(r)?r:null;this.#ne=async function(){const r=await Promise.all(t.inputs.map((e,t)=>null==n[t]?null:e.walkAsync(n[t],(e,t)=>"address"===e?Array.isArray(t)?Promise.all(t.map(e=>Zu(e,o))):Zu(t,o):t)));return e.interface.encodeFilterTopics(t,r)}()}getTopicFilter(){return this.#ne}}function xf(e,t){return null==e?null:"function"==typeof e[t]?e:e.provider&&"function"==typeof e.provider[t]?e.provider:null}function kf(e){return null==e?null:e.provider||null}async function Sf(e,t){const n=Rc.dereference(e,"overrides");Me("object"==typeof n,"invalid overrides parameter","overrides",e);const r=tf(n);return Me(null==r.to||(t||[]).indexOf("to")>=0,"cannot override to","overrides.to",r.to),Me(null==r.data||(t||[]).indexOf("data")>=0,"cannot override data","overrides.data",r.data),r.from&&(r.from=r.from),r}function If(e){const t=async function(t){const n=await Sf(t,["data"]);n.to=await e.getAddress(),n.from&&(n.from=await Zu(n.from,Ef(e.runner)));const r=e.interface,o=tc(n.value||yf,"overrides.value")===yf,i="0x"===(n.data||"0x");return!r.fallback||r.fallback.payable||!r.receive||i||o||Me(!1,"cannot send data to receive or send value to non-payable fallback","overrides",t),Me(r.fallback||i,"cannot send data to receive-only contract","overrides.data",n.data),Me(r.receive||r.fallback&&r.fallback.payable||o,"cannot send value to non-payable fallback","overrides.value",n.value),Me(r.fallback||i,"cannot send data to receive-only contract","overrides.data",n.data),n},n=async function(n){const r=e.runner;_e(vf(r),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const o=await r.sendTransaction(await t(n)),i=kf(e.runner);return new df(e.interface,i,o)},r=async e=>await n(e);return Re(r,{_contract:e,estimateGas:async function(n){const r=xf(e.runner,"estimateGas");return _e(wf(r),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await r.estimateGas(await t(n))},populateTransaction:t,send:n,staticCall:async function(n){const r=xf(e.runner,"call");_e(mf(r),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const o=await t(n);try{return await r.call(o)}catch(t){if(Le(t)&&t.data)throw e.interface.makeError(t.data,o);throw t}}}),r}const Pf=Symbol.for("_ethersInternal_contract"),Cf=new WeakMap;function Of(e){return Cf.get(e[Pf])}async function Nf(e,t){let n,r=null;if(Array.isArray(t)){const r=function(t){if($e(t,32))return t;const n=e.interface.getEvent(t);return Me(n,"unknown fragment","name",t),n.topicHash};n=t.map(e=>null==e?null:Array.isArray(e)?e.map(r):r(e))}else"*"===t?n=[null]:"string"==typeof t?$e(t,32)?n=[t]:(r=e.interface.getEvent(t),Me(r,"unknown fragment","event",t),n=[r.topicHash]):(o=t)&&"object"==typeof o&&"getTopicFilter"in o&&"function"==typeof o.getTopicFilter&&o.fragment?n=await t.getTopicFilter():"fragment"in t?(r=t.fragment,n=[r.topicHash]):Me(!1,"unknown event name","event",t);var o;return n=n.map(e=>{if(null==e)return null;if(Array.isArray(e)){const t=Array.from(new Set(e.map(e=>e.toLowerCase())).values());return 1===t.length?t[0]:(t.sort(),t)}return e.toLowerCase()}),{fragment:r,tag:n.map(e=>null==e?"null":Array.isArray(e)?e.join("|"):e).join("&"),topics:n}}async function Bf(e,t){const{subs:n}=Of(e);return n.get((await Nf(e,t)).tag)||null}async function Tf(e,t,n){const r=kf(e.runner);_e(r,"contract runner does not support subscribing","UNSUPPORTED_OPERATION",{operation:t});const{fragment:o,tag:i,topics:s}=await Nf(e,n),{addr:a,subs:c}=Of(e);let u=c.get(i);if(!u){const t={address:a||e,topics:s},l=t=>{let r=o;if(null==r)try{r=e.interface.getEvent(t.topics[0])}catch(e){}if(r){const i=r,s=o?e.interface.decodeEventLog(o,t.data,t.topics):[];Uf(e,n,s,r=>new gf(e,r,n,i,t))}else Uf(e,n,[],r=>new pf(e,r,n,t))};let f=[];u={tag:i,listeners:[],start:()=>{f.length||f.push(r.on(t,l))},stop:async()=>{if(0==f.length)return;let e=f;f=[],await Promise.all(e),r.off(t,l)}},c.set(i,u)}return u}let Rf=Promise.resolve();async function Uf(e,t,n,r){try{await Rf}catch(e){}const o=async function(e,t,n,r){await Rf;const o=await Bf(e,t);if(!o)return!1;const i=o.listeners.length;return o.listeners=o.listeners.filter(({listener:t,once:o})=>{const i=Array.from(n);r&&i.push(r(o?null:t));try{t.call(e,...i)}catch(e){}return!o}),0===o.listeners.length&&(o.stop(),Of(e).subs.delete(o.tag)),i>0}(e,t,n,r);return Rf=o,await o}const Df=["then"];class Lf{target;interface;runner;filters;[Pf];fallback;constructor(e,t,n,r){Me("string"==typeof e||Ju(e),"invalid value for Contract target","target",e),null==n&&(n=null);const o=Ql.from(t);let i;Re(this,{target:e,runner:n,interface:o}),Object.defineProperty(this,Pf,{value:{}});let s=null,a=null;if(r){const e=kf(n);a=new df(this.interface,e,r)}let c=new Map;if("string"==typeof e)if($e(e))s=e,i=Promise.resolve(e);else{const t=xf(n,"resolveName");if(!bf(t))throw Fe("contract runner does not support name resolution","UNSUPPORTED_OPERATION",{operation:"resolveName"});i=t.resolveName(e).then(t=>{if(null==t)throw Fe("an ENS name used for a contract target must be correctly configured","UNCONFIGURED_NAME",{value:e});return Of(this).addr=t,t})}else i=e.getAddress().then(e=>{if(null==e)throw new Error("TODO");return Of(this).addr=e,e});var u;u={addrPromise:i,addr:s,deployTx:a,subs:c},Cf.set(this[Pf],u);const l=new Proxy({},{get:(e,t,n)=>{if("symbol"==typeof t||Df.indexOf(t)>=0)return Reflect.get(e,t,n);try{return this.getEvent(t)}catch(e){if(!De(e,"INVALID_ARGUMENT")||"key"!==e.argument)throw e}},has:(e,t)=>Df.indexOf(t)>=0?Reflect.has(e,t):Reflect.has(e,t)||this.interface.hasEvent(String(t))});return Re(this,{filters:l}),Re(this,{fallback:o.receive||o.fallback?If(this):null}),new Proxy(this,{get:(e,t,n)=>{if("symbol"==typeof t||t in e||Df.indexOf(t)>=0)return Reflect.get(e,t,n);try{return e.getFunction(t)}catch(e){if(!De(e,"INVALID_ARGUMENT")||"key"!==e.argument)throw e}},has:(e,t)=>"symbol"==typeof t||t in e||Df.indexOf(t)>=0?Reflect.has(e,t):e.interface.hasFunction(t)})}connect(e){return new Lf(this.target,this.interface,e)}attach(e){return new Lf(e,this.interface,this.runner)}async getAddress(){return await Of(this).addrPromise}async getDeployedCode(){const e=kf(this.runner);_e(e,"runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"getDeployedCode"});const t=await e.getCode(await this.getAddress());return"0x"===t?null:t}async waitForDeployment(){const e=this.deploymentTransaction();if(e)return await e.wait(),this;if(null!=await this.getDeployedCode())return this;const t=kf(this.runner);return _e(null!=t,"contract runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"waitForDeployment"}),new Promise((e,n)=>{const r=async()=>{try{if(null!=await this.getDeployedCode())return e(this);t.once("block",r)}catch(e){n(e)}};r()})}deploymentTransaction(){return Of(this).deployTx}getFunction(e){return"string"!=typeof e&&(e=e.format()),function(e,t){const n=function(...n){const r=e.interface.getFunction(t,n);return _e(r,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t,args:n}}),r},r=async function(...t){const r=n(...t);let o={};if(r.inputs.length+1===t.length&&(o=await Sf(t.pop()),o.from&&(o.from=await Zu(o.from,Ef(e.runner)))),r.inputs.length!==t.length)throw new Error("internal error: fragment inputs doesn't match arguments; should not happen");const i=await async function(e,t,n){const r=xf(e,"resolveName"),o=bf(r)?r:null;return await Promise.all(t.map((e,t)=>e.walkAsync(n[t],(e,t)=>(t=Rc.dereference(t,e),"address"===e?Zu(t,o):t))))}(e.runner,r.inputs,t);return Object.assign({},o,await Te({to:e.getAddress(),data:e.interface.encodeFunctionData(r,i)}))},o=async function(...e){const t=await s(...e);return 1===t.length?t[0]:t},i=async function(...t){const n=e.runner;_e(vf(n),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const o=await n.sendTransaction(await r(...t)),i=kf(e.runner);return new df(e.interface,i,o)},s=async function(...t){const o=xf(e.runner,"call");_e(mf(o),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const i=await r(...t);let s="0x";try{s=await o.call(i)}catch(t){if(Le(t)&&t.data)throw e.interface.makeError(t.data,i);throw t}const a=n(...t);return e.interface.decodeFunctionResult(a,s)},a=async(...e)=>n(...e).constant?await o(...e):await i(...e);return Re(a,{name:e.interface.getFunctionName(t),_contract:e,_key:t,getFragment:n,estimateGas:async function(...t){const n=xf(e.runner,"estimateGas");return _e(wf(n),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await n.estimateGas(await r(...t))},populateTransaction:r,send:i,staticCall:o,staticCallResult:s}),Object.defineProperty(a,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=e.interface.getFunction(t);return _e(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t}}),n}}),a}(this,e)}getEvent(e){return"string"!=typeof e&&(e=e.format()),function(e,t){const n=function(...n){const r=e.interface.getEvent(t,n);return _e(r,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t,args:n}}),r},r=function(...t){return new Af(e,n(...t),t)};return Re(r,{name:e.interface.getEventName(t),_contract:e,_key:t,getFragment:n}),Object.defineProperty(r,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=e.interface.getEvent(t);return _e(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t}}),n}}),r}(this,e)}async queryTransaction(e){throw new Error("@TODO")}async queryFilter(e,t,n){null==t&&(t=0),null==n&&(n="latest");const{addr:r,addrPromise:o}=Of(this),i=r||await o,{fragment:s,topics:a}=await Nf(this,e),c={address:i,topics:a,fromBlock:t,toBlock:n},u=kf(this.runner);return _e(u,"contract runner does not have a provider","UNSUPPORTED_OPERATION",{operation:"queryFilter"}),(await u.getLogs(c)).map(e=>{let t=s;if(null==t)try{t=this.interface.getEvent(e.topics[0])}catch(e){}if(t)try{return new lf(e,this.interface,t)}catch(t){return new ff(e,t)}return new rf(e,u)})}async on(e,t){const n=await Tf(this,"on",e);return n.listeners.push({listener:t,once:!1}),n.start(),this}async once(e,t){const n=await Tf(this,"once",e);return n.listeners.push({listener:t,once:!0}),n.start(),this}async emit(e,...t){return await Uf(this,e,t,null)}async listenerCount(e){if(e){const t=await Bf(this,e);return t?t.listeners.length:0}const{subs:t}=Of(this);let n=0;for(const{listeners:e}of t.values())n+=e.length;return n}async listeners(e){if(e){const t=await Bf(this,e);return t?t.listeners.map(({listener:e})=>e):[]}const{subs:t}=Of(this);let n=[];for(const{listeners:e}of t.values())n=n.concat(e.map(({listener:e})=>e));return n}async off(e,t){const n=await Bf(this,e);if(!n)return this;if(t){const e=n.listeners.map(({listener:e})=>e).indexOf(t);e>=0&&n.listeners.splice(e,1)}return null!=t&&0!==n.listeners.length||(n.stop(),Of(this).subs.delete(n.tag)),this}async removeAllListeners(e){if(e){const t=await Bf(this,e);if(!t)return this;t.stop(),Of(this).subs.delete(t.tag)}else{const{subs:e}=Of(this);for(const{tag:t,stop:n}of e.values())n(),e.delete(t)}return this}async addListener(e,t){return await this.on(e,t)}async removeListener(e,t){return await this.off(e,t)}static buildClass(e){return class extends Lf{constructor(t,n=null){super(t,e,n)}}}static from(e,t,n){return null==n&&(n=null),new this(e,t,n)}}class Ff extends(function(){return Lf}()){}const _f=new Map([[8217,"apostrophe"],[8260,"fraction slash"],[12539,"middle dot"]]);function Mf(e){return function(e){let t=0;return()=>e[t++]}(function(e){let t=0;function n(){return e[t++]<<8|e[t++]}let r=n(),o=1,i=[0,1];for(let e=1;e<r;e++)i.push(o+=n());let s=n(),a=t;t+=s;let c=0,u=0;function l(){return 0==c&&(u=u<<8|e[t++],c=8),u>>--c&1}const f=2**31,h=f>>>1,d=h>>1,p=f-1;let g=0;for(let e=0;e<31;e++)g=g<<1|l();let y=[],m=0,w=f;for(;;){let e=Math.floor(((g-m+1)*o-1)/w),t=0,n=r;for(;n-t>1;){let r=t+n>>>1;e<i[r]?n=r:t=r}if(0==t)break;y.push(t);let s=m+Math.floor(w*i[t]/o),a=m+Math.floor(w*i[t+1]/o)-1;for(;0==((s^a)&h);)g=g<<1&p|l(),s=s<<1&p,a=a<<1&p|1;for(;s&~a&d;)g=g&h|g<<1&p>>>1|l(),s=s<<1^h,a=(a^h)<<1|h|1;m=s,w=1+a-s}let b=r-4;return y.map(t=>{switch(t-b){case 3:return b+65792+(e[a++]<<16|e[a++]<<8|e[a++]);case 2:return b+256+(e[a++]<<8|e[a++]);case 1:return b+e[a++];default:return t-1}})}(function(e){let t=[];[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"].forEach((e,n)=>t[e.charCodeAt(0)]=n);let n=e.length,r=new Uint8Array(6*n>>3);for(let o=0,i=0,s=0,a=0;o<n;o++)a=a<<6|t[e.charCodeAt(o)],s+=6,s>=8&&(r[i++]=a>>(s-=8));return r}(e)))}function jf(e){return 1&e?~e>>1:e>>1}function Gf(e,t){let n=Array(e);for(let r=0,o=0;r<e;r++)n[r]=o+=jf(t());return n}function Hf(e,t=0){let n=[];for(;;){let r=e(),o=e();if(!o)break;t+=r;for(let e=0;e<o;e++)n.push(t+e);t+=o+1}return n}function zf(e){return Vf(()=>{let t=Hf(e);if(t.length)return t})}function Kf(e){let t=[];for(;;){let n=e();if(0==n)break;t.push($f(n,e))}for(;;){let n=e()-1;if(n<0)break;t.push(qf(n,e))}return t.flat()}function Vf(e){let t=[];for(;;){let n=e(t.length);if(!n)break;t.push(n)}return t}function Wf(e,t,n){let r=Array(e).fill().map(()=>[]);for(let o=0;o<t;o++)Gf(e,n).forEach((e,t)=>r[t].push(e));return r}function $f(e,t){let n=1+t(),r=t(),o=Vf(t);return Wf(o.length,1+e,t).flatMap((e,t)=>{let[i,...s]=e;return Array(o[t]).fill().map((e,t)=>{let o=t*r;return[i+t*n,s.map(e=>e+o)]})})}function qf(e,t){return Wf(1+t(),1+e,t).map(e=>[e[0],e.slice(1)])}function Jf(e){return`{${function(e){return e.toString(16).toUpperCase().padStart(2,"0")}(e)}}`}function Qf(e){let t=e.length;if(t<4096)return String.fromCodePoint(...e);let n=[];for(let r=0;r<t;)n.push(String.fromCodePoint(...e.slice(r,r+=4096)));return n.join("")}function Zf(e,t){let n=e.length,r=n-t.length;for(let o=0;0==r&&o<n;o++)r=e[o]-t[o];return r}const Yf=44032,Xf=4352,eh=4449,th=4519;function nh(e){return e>>24&255}function rh(e){return 16777215&e}let oh,ih,sh,ah;function ch(e){return e>=Yf&&e<55204}function uh(e,t){if(e>=Xf&&e<4371&&t>=eh&&t<4470)return Yf+588*(e-Xf)+28*(t-eh);if(ch(e)&&t>th&&t<4547&&(e-Yf)%28==0)return e+(t-th);{let n=ah.get(e);return n&&(n=n.get(t),n)?n:-1}}function lh(e){oh||function(){let e=Mf("AEUDTAHBCFQATQDRADAAcgAgADQAFAAsABQAHwAOACQADQARAAoAFwAHABIACAAPAAUACwAFAAwABAAQAAMABwAEAAoABQAIAAIACgABAAQAFAALAAIACwABAAIAAQAHAAMAAwAEAAsADAAMAAwACgANAA0AAwAKAAkABAAdAAYAZwDSAdsDJgC0CkMB8xhZAqfoC190UGcThgBurwf7PT09Pb09AjgJum8OjDllxHYUKXAPxzq6tABAxgK8ysUvWAgMPT09PT09PSs6LT2HcgWXWwFLoSMEEEl5RFVMKvO0XQ8ExDdJMnIgsj26PTQyy8FfEQ8AY8IPAGcEbwRwBHEEcgRzBHQEdQR2BHcEeAR6BHsEfAR+BIAEgfndBQoBYgULAWIFDAFiBNcE2ATZBRAFEQUvBdALFAsVDPcNBw13DYcOMA4xDjMB4BllHI0B2grbAMDpHLkQ7QHVAPRNQQFnGRUEg0yEB2uaJF8AJpIBpob5AERSMAKNoAXqaQLUBMCzEiACnwRZEkkVsS7tANAsBG0RuAQLEPABv9HICTUBXigPZwRBApMDOwAamhtaABqEAY8KvKx3LQ4ArAB8UhwEBAVSagD8AEFZADkBIadVj2UMUgx5Il4ANQC9AxIB1BlbEPMAs30CGxlXAhwZKQIECBc6EbsCoxngzv7UzRQA8M0BawL6ZwkN7wABAD33OQRcsgLJCjMCjqUChtw/km+NAsXPAoP2BT84PwURAK0RAvptb6cApQS/OMMey5HJS84UdxpxTPkCogVFITaTOwERAK5pAvkNBOVyA7q3BKlOJSALAgUIBRcEdASpBXqzABXFSWZOawLCOqw//AolCZdvv3dSBkEQGyelEPcMMwG1ATsN7UvYBPEGOwTJH30ZGQ/NlZwIpS3dDO0m4y6hgFoj9SqDBe1L9DzdC01RaA9ZC2UJ4zpjgU4DIQENIosK3Q05CG0Q8wrJaw3lEUUHOQPVSZoApQcBCxEdNRW1JhBirAsJOXcG+xr2C48mrxMpevwF0xohBk0BKRr/AM8u54WwWjFcHE9fBgMLJSPHFKhQIA0lQLd4SBobBxUlqQKRQ3BKh1E2HpMh9jw9DWYuE1F8B/U8BRlPC4E8nkarRQ4R0j6NPUgiSUwsBDV/LC8niwnPD4UMuXxyAVkJIQmxDHETMREXN8UIOQcZLZckJxUIIUaVYJoE958D8xPRAwsFPwlBBxMDtRwtEy4VKQUNgSTXAvM21S6zAo9WgAEXBcsPJR/fEFBH4A7pCJsCZQODJesALRUhABcimwhDYwBfj9hTBS7LCMdqbCN0A2cU52ERcweRDlcHpxwzFb8c4XDIXguGCCijrwlbAXUJmQFfBOMICTVbjKAgQWdTi1gYmyBhQT9d/AIxDGUVn0S9h3gCiw9rEhsBNQFzBzkNAQJ3Ee0RaxCVCOuGBDW1M/g6JQRPIYMgEQonA09szgsnJvkM+GkBoxJiAww0PXfuZ6tgtiQX/QcZMsVBYCHxC5JPzQycGsEYQlQuGeQHvwPzGvMn6kFXBf8DowMTOk0z7gS9C2kIiwk/AEkOoxcH1xhqCnGM0AExiwG3mQNXkYMCb48GNwcLAGcLhwV55QAdAqcIowAFAM8DVwA5Aq0HnQAZAIVBAT0DJy8BIeUCjwOTCDHLAZUvAfMpBBvDDBUA9zduSgLDsQKAamaiBd1YAo4CSTUBTSUEBU5HUQOvceEA2wBLBhPfRwEVq0rLGuNDAd9vKwDHAPsABTUHBUEBzQHzbQC3AV8LMQmis7UBTekpAIMAFWsB1wKJAN0ANQB/8QFTAE0FWfkF0wJPSQERMRgrV2EBuwMfATMBDQB5BsuNpckHHwRtB9MCEBsV4QLvLge1AQMi3xPNQsUCvd5VoWACZIECYkJbTa9bNyACofcCaJgCZgkCn4Q4GwsCZjsCZiYEbgR/A38TA36SOQY5dxc5gjojIwJsHQIyNjgKAm3HAm2u74ozZ0UrAWcA3gDhAEoFB5gMjQD+C8IADbUCdy8CdqI/AnlLQwJ4uh1c20WuRtcCfD8CesgCfQkCfPAFWQUgSABIfWMkAoFtAoAAAoAFAn+uSVhKWxUXSswC0QEC0MxLJwOITwOH5kTFkTIC8qFdAwMDrkvOTC0lA89NTE2vAos/AorYwRsHHUNnBbcCjjcCjlxAl4ECjtkCjlx4UbRTNQpS1FSFApP7ApMMAOkAHFUeVa9V0AYsGymVhjLheGZFOzkCl58C77JYIagAWSUClo8ClnycAKlZrFoJgU0AOwKWtQKWTlxEXNECmcsCmWRcyl0HGQKcmznCOp0CnBYCn5sCnriKAB0PMSoPAp3xAp6SALU9YTRh7wKe0wKgbgGpAp6fHwKeTqVjyGQnJSsCJ68CJn4CoPsCoEwCot0CocQCpi8Cpc4Cp/8AfQKn8mh8aLEAA0lqHGrRAqzjAqyuAq1nAq0CAlcdAlXcArHh1wMfTmyXArK9DQKy6Bds4G1jbUhfAyXNArZcOz9ukAMpRQK4XgK5RxUCuSp3cDZw4QK9GQK72nCWAzIRAr6IcgIDM3ECvhpzInNPAsPLAsMEc4J0SzVFdOADPKcDPJoDPb8CxXwCxkcCxhCJAshpUQLIRALJTwLJLgJknQLd0nh5YXiueSVL0AMYo2cCAmH0GfOVJHsLXpJeuxECz2sCz2wvS1PS8xOfAMatAs9zASnqA04SfksFAtwnAtuKAtJPA1JcA1NfAQEDVYyAiT8AyxbtYEWCHILTgs6DjQLaxwLZ3oQQhEmnPAOGpQAvA2QOhnFZ+QBVAt9lAt64c3cC4i/tFAHzMCcB9JsB8tKHAuvzAulweQLq+QLq5AD5RwG5Au6JAuuclqqXAwLuPwOF4Jh5cOBxoQLzAwBpA44WmZMC9xMDkW4DkocC95gC+dkC+GaaHJqruzebHgOdgwL++gEbADmfHJ+zAwWNA6ZqA6bZANHFAwZqoYiiBQkDDEkCwAA/AwDhQRdTARHzA2sHl2cFAJMtK7evvdsBiZkUfxEEOQH7KQUhDp0JnwCS/SlXxQL3AZ0AtwW5AG8LbUEuFCaNLgFDAYD8AbUmAHUDDgRtACwCFgyhAAAKAj0CagPdA34EkQEgRQUhfAoABQBEABMANhICdwEABdUDa+8KxQIA9wqfJ7+xt+UBkSFBQgHpFH8RNMCJAAQAGwBaAkUChIsABjpTOpSNbQC4Oo860ACNOME63AClAOgAywE6gTo7Ofw5+Tt2iTpbO56JOm85GAFWATMBbAUvNV01njWtNWY1dTW2NcU1gjWRNdI14TWeNa017jX9NbI1wTYCNhE1xjXVNhY2JzXeNe02LjY9Ni41LSE2OjY9Njw2yTcIBJA8VzY4Nt03IDcPNsogN4k3MAoEsDxnNiQ3GTdsOo03IULUQwdC4EMLHA8PCZsobShRVQYA6X8A6bABFCnXAukBowC9BbcAbwNzBL8MDAMMAQgDAAkKCwsLCQoGBAVVBI/DvwDz9b29kaUCb0QtsRTNLt4eGBcSHAMZFhYZEhYEARAEBUEcQRxBHEEcQRxBHEEaQRxBHEFCSTxBPElISUhBNkM2QTYbNklISVmBVIgBFLWZAu0BhQCjBcEAbykBvwGJAaQcEZ0ePCklMAAhMvAIMAL54gC7Bm8EescjzQMpARQpKgDUABavAj626xQAJP0A3etzuf4NNRA7efy2Z9NQrCnC0OSyANz5BBIbJ5IFDR6miIavYS6tprjjmuKebxm5C74Q225X1pkaYYPb6f1DK4k3xMEBb9S2WMjEibTNWhsRJIA+vwNVEiXTE5iXs/wezV66oFLfp9NZGYW+Gk19J2+bCT6Ye2w6LDYdgzKMUabk595eLBCXANz9HUpWbATq9vqXVx9XDg+Pc9Xp4+bsS005SVM/BJBM4687WUuf+Uj9dEi8aDNaPxtpbDxcG1THTImUMZq4UCaaNYpsVqraNyKLJXDYsFZ/5jl7bLRtO88t7P3xZaAxhb5OdPMXqsSkp1WCieG8jXm1U99+blvLlXzPCS+M93VnJCiK+09LfaSaBAVBomyDgJua8dfUzR7ga34IvR2Nvj+A9heJ6lsl1KG4NkI1032Cnff1m1wof2B9oHJK4bi6JkEdSqeNeiuo6QoZZincoc73/TH9SXF8sCE7XyuYyW8WSgbGFCjPV0ihLKhdPs08Tx82fYAkLLc4I2wdl4apY7GU5lHRFzRWJep7Ww3wbeA3qmd59/86P4xuNaqDpygXt6M85glSBHOCGgJDnt+pN9bK7HApMguX6+06RZNjzVmcZJ+wcUrJ9//bpRNxNuKpNl9uFds+S9tdx7LaM5ZkIrPj6nIU9mnbFtVbs9s/uLgl8MVczAwet+iOEzzBlYW7RCMgE6gyNLeq6+1tIx4dpgZnd0DksJS5f+JNDpwwcPNXaaVspq1fbQajOrJgK0ofKtJ1Ne90L6VO4MOl5S886p7u6xo7OLjG8TGL+HU1JXGJgppg4nNbNJ5nlzSpuPYy21JUEcUA94PoFiZfjZue+QnyQ80ekOuZVkxx4g+cvhJfHgNl4hy1/a6+RKcKlar/J29y//EztlbVPHVUeQ1zX86eQVAjR/M3dA9w4W8LfaXp4EgM85wOWasli837PzVMOnsLzR+k3o75/lRPAJSE1xAKQzEi5v10ke+VBvRt1cwQRMd+U5mLCTGVd6XiZtgBG5cDi0w22GKcVNvHiu5LQbZEDVtz0onn7k5+heuKXVsZtSzilkLRAUmjMXEMB3J9YC50XBxPiz53SC+EhnPl9WsKCv92SM/OFFIMJZYfl0WW8tIO3UxYcwdMAj7FSmgrsZ2aAZO03BOhP1bNNZItyXYQFTpC3SG1VuPDqH9GkiCDmE+JwxyIVSO5siDErAOpEXFgjy6PQtOVDj+s6e1r8heWVvmZnTciuf4EiNZzCAd7SOMhXERIOlsHIMG399i9aLTy3m2hRLZjJVDNLS53iGIK11dPqQt0zBDyg6qc7YqkDm2M5Ve6dCWCaCbTXX2rToaIgz6+zh4lYUi/+6nqcFMAkQJKHYLK0wYk5N9szV6xihDbDDFr45lN1K4aCXBq/FitPSud9gLt5ZVn+ZqGX7cwm2z5EGMgfFpIFyhGGuDPmso6TItTMwny+7uPnLCf4W6goFQFV0oQSsc9VfMmVLcLr6ZetDZbaSFTLqnSO/bIPjA3/zAUoqgGFAEQS4IhuMzEp2I3jJzbzkk/IEmyax+rhZTwd6f+CGtwPixu8IvzACquPWPREu9ZvGkUzpRwvRRuaNN6cr0W1wWits9ICdYJ7ltbgMiSL3sTPeufgNcVqMVWFkCPDH4jG2jA0XcVgQj62Cb29v9f/z/+2KbYvIv/zzjpQAPkliaVDzNrW57TZ/ZOyZD0nlfMmAIBIAGAI0D3k/mdN4xr9v85ZbZbbqfH2jGd5hUqNZWwl5SPfoGmfElmazUIeNL1j/mkF7VNAzTq4jNt8JoQ11NQOcmhprXoxSxfRGJ9LDEOAQ+dmxAQH90iti9e2u/MoeuaGcDTHoC+xsmEeWmxEKefQuIzHbpw5Tc5cEocboAD09oipWQhtTO1wivf/O+DRe2rpl/E9wlrzBorjJsOeG1B/XPW4EaJEFdNlECEZga5ZoGRHXgYouGRuVkm8tDESiEyFNo+3s5M5puSdTyUL2llnINVHEt91XUNW4ewdMgJ4boJfEyt/iY5WXqbA+A2Fkt5Z0lutiWhe9nZIyIUjyXDC3UsaG1t+eNx6z4W/OYoTB7A6x+dNSTOi9AInctbESqm5gvOLww7OWXPrmHwVZasrl4eD113pm+JtT7JVOvnCXqdzzdTRHgJ0PiGTFYW5Gvt9R9LD6Lzfs0v/TZZHSmyVNq7viIHE6DBK7Qp07Iz55EM8SYtQvZf/obBniTWi5C2/ovHfw4VndkE5XYdjOhCMRjDeOEfXeN/CwfGduiUIfsoFeUxXeQXba7c7972XNv8w+dTjjUM0QeNAReW+J014dKAD/McQYXT7c0GQPIkn3Ll6R7gGjuiQoZD0TEeEqQpKoZ15g/0OPQI17QiSv9AUROa/V/TQN3dvLArec3RrsYlvBm1b8LWzltdugsC50lNKYLEp2a+ZZYqPejULRlOJh5zj/LVMyTDvwKhMxxwuDkxJ1QpoNI0OTWLom4Z71SNzI9TV1iXJrIu9Wcnd+MCaAw8o1jSXd94YU/1gnkrC9BUEOtQvEIQ7g0i6h+KL2JKk8Ydl7HruvgWMSAmNe+LshGhV4qnWHhO9/RIPQzY1tHRj2VqOyNsDpK0cww+56AdDC4gsWwY0XxoucIWIqs/GcwnWqlaT0KPr8mbK5U94/301i1WLt4YINTVvCFBrFZbIbY8eycOdeJ2teD5IfPLCRg7jjcFTwlMFNl9zdh/o3E/hHPwj7BWg0MU09pPrBLbrCgm54A6H+I6v27+jL5gkjWg/iYdks9jbfVP5y/n0dlgWEMlKasl7JvFZd56LfybW1eeaVO0gxTfXZwD8G4SI116yx7UKVRgui6Ya1YpixqXeNLc8IxtAwCU5IhwQgn+NqHnRaDv61CxKhOq4pOX7M6pkA+Pmpd4j1vn6ACUALoLLc4vpXci8VidLxzm7qFBe7s+quuJs6ETYmnpgS3LwSZxPIltgBDXz8M1k/W2ySNv2f9/NPhxLGK2D21dkHeSGmenRT3Yqcdl0m/h3OYr8V+lXNYGf8aCCpd4bWjE4QIPj7vUKN4Nrfs7ML6Y2OyS830JCnofg/k7lpFpt4SqZc5HGg1HCOrHvOdC8bP6FGDbE/VV0mX4IakzbdS/op+Kt3G24/8QbBV7y86sGSQ/vZzU8FXs7u6jIvwchsEP2BpIhW3G8uWNwa3HmjfH/ZjhhCWvluAcF+nMf14ClKg5hGgtPLJ98ueNAkc5Hs2WZlk2QHvfreCK1CCGO6nMZVSb99VM/ajr8WHTte9JSmkXq/i/U943HEbdzW6Re/S88dKgg8pGOLlAeNiqrcLkUR3/aClFpMXcOUP3rmETcWSfMXZE3TUOi8i+fqRnTYLflVx/Vb/6GJ7eIRZUA6k3RYR3iFSK9c4iDdNwJuZL2FKz/IK5VimcNWEqdXjSoxSgmF0UPlDoUlNrPcM7ftmA8Y9gKiqKEHuWN+AZRIwtVSxye2Kf8rM3lhJ5XcBXU9n4v0Oy1RU2M+4qM8AQPVwse8ErNSob5oFPWxuqZnVzo1qB/IBxkM3EVUKFUUlO3e51259GgNcJbCmlvrdjtoTW7rChm1wyCKzpCTwozUUEOIcWLneRLgMXh+SjGSFkAllzbGS5HK7LlfCMRNRDSvbQPjcXaenNYxCvu2Qyznz6StuxVj66SgI0T8B6/sfHAJYZaZ78thjOSIFumNWLQbeZixDCCC+v0YBtkxiBB3jefHqZ/dFHU+crbj6OvS1x/JDD7vlm7zOVPwpUC01nhxZuY/63E7g");oh=new Map(zf(e).flatMap((e,t)=>e.map(e=>[e,t+1<<24]))),ih=new Set(Hf(e)),sh=new Map,ah=new Map;for(let[t,n]of Kf(e)){if(!ih.has(t)&&2==n.length){let[e,r]=n,o=ah.get(e);o||(o=new Map,ah.set(e,o)),o.set(r,t)}sh.set(t,n.reverse())}}();let t=[],n=[],r=!1;function o(e){let n=oh.get(e);n&&(r=!0,e|=n),t.push(e)}for(let r of e)for(;;){if(r<128)t.push(r);else if(ch(r)){let e=r-Yf,t=e%588/28|0,n=e%28;o(Xf+(e/588|0)),o(eh+t),n>0&&o(th+n)}else{let e=sh.get(r);e?n.push(...e):o(r)}if(!n.length)break;r=n.pop()}if(r&&t.length>1){let e=nh(t[0]);for(let n=1;n<t.length;n++){let r=nh(t[n]);if(0==r||e<=r){e=r;continue}let o=n-1;for(;;){let n=t[o+1];if(t[o+1]=t[o],t[o]=n,!o)break;if(e=nh(t[--o]),e<=r)break}e=nh(t[n])}}return t}function fh(e){return lh(e).map(rh)}function hh(e){return function(e){let t=[],n=[],r=-1,o=0;for(let i of e){let e=nh(i),s=rh(i);if(-1==r)0==e?r=s:t.push(s);else if(o>0&&o>=e)0==e?(t.push(r,...n),n.length=0,r=s):n.push(s),o=e;else{let i=uh(r,s);i>=0?r=i:0==o&&0==e?(t.push(r),r=s):(n.push(s),o=e)}}return r>=0&&t.push(r,...n),t}(lh(e))}const dh=e=>Array.from(e);function ph(e,t){return e.P.has(t)||e.Q.has(t)}class gh extends Array{get is_emoji(){return!0}}let yh,mh,wh,bh,vh,Eh,Ah,xh,kh,Sh,Ih,Ph;function Ch(){if(yh)return;let e=Mf("AEEUdwmgDS8BxQKKAP4BOgDjATAAngDUAIMAoABoAOAAagCOAEQAhABMAHIAOwA9ACsANgAmAGIAHgAuACgAJwAXAC0AGgAjAB8ALwAUACkAEgAeAAkAGwARABkAFgA5ACgALQArADcAFQApABAAHgAiABAAGgAeABMAGAUhBe8BFxREN8sF2wC5AK5HAW8ArQkDzQCuhzc3NzcBP68NEfMABQdHBuw5BV8FYAA9MzkI9r4ZBg7QyQAWA9CeOwLNCjcCjqkChuA/lm+RAsXTAoP6ASfnEQDytQFJAjWVCkeXAOsA6godAB/cwdAUE0WlBCN/AQUCQRjFD/MRBjHxDQSJbw0jBzUAswBxme+tnIcAYwabAysG8QAjAEMMmxcDqgPKQyDXCMMxA7kUQwD3NXOrAKmFIAAfBC0D3x4BJQDBGdUFAhEgVD8JnwmQJiNWYUzrg0oAGwAUAB0AFnNcACkAFgBP9h3gPfsDOWDKneY2ChglX1UDYD30ABsAFAAdABZzIGRAnwDD8wAjAEEMzRbDqgMB2sAFYwXqAtCnAsS4AwpUJKRtFHsadUz9AMMVbwLpABM1NJEX0ZkCgYMBEyMAxRVvAukAEzUBUFAtmUwSAy4DBTER33EftQHfSwB5MxJ/AjkWKQLzL8E/cwBB6QH9LQDPDtO9ASNriQC5DQANAwCK21EFI91zHwCoL9kBqQcHBwcHKzUDowBvAQohPvU3fAQgHwCyAc8CKQMA5zMSezr7ULgFmDp/LzVQBgEGAi8FYQVgt8AFcTtlQhpCWEmfe5tmZ6IAExsDzQ8t+X8rBKtTAltbAn0jsy8Bl6utPWMDTR8Ei2kRANkDBrNHNysDBzECQWUAcwFpJ3kAiyUhAJ0BUb8AL3EfAbfNAz81KUsFWwF3YQZtAm0A+VEfAzEJDQBRSQCzAQBlAHsAM70GD/v3IZWHBwARKQAxALsjTwHZAeMPEzmXgIHwABIAGQA8AEUAQDt3gdvIEGcQZAkGTRFMdEIVEwK0D64L7REdDNkq09PgADSxB/MDWwfzA1sDWwfzB/MDWwfzA1sDWwNbA1scEvAi28gQZw9QBHUFlgWTBN4IiyZREYkHMAjaVBV0JhxPA00BBCMtSSQ7mzMTJUpMFE0LCAQ2SmyvfUADTzGzVP2QqgPTMlc5dAkGHnkSqAAyD3skNb1OhnpPcagKU0+2tYdJak5vAsY6sEAACikJm2/Dd1YGRRAfJ6kQ+ww3AbkBPw3xS9wE9QY/BM0fgRkdD9GVoAipLeEM8SbnLqWAXiP5KocF8Uv4POELUVFsD10LaQnnOmeBUgMlAREijwrhDT0IcRD3Cs1vDekRSQc9A9lJngCpBwULFR05FbkmFGKwCw05ewb/GvoLkyazEy17AAXXGiUGUQEtGwMA0y7rhbRaNVwgT2MGBwspI8sUrFAkDSlAu3hMGh8HGSWtApVDdEqLUToelyH6PEENai4XUYAH+TwJGVMLhTyiRq9FEhHWPpE9TCJNTDAEOYMsMyePCdMPiQy9fHYBXQklCbUMdRM1ERs3yQg9Bx0xlygnGQglRplgngT7owP3E9UDDwVDCUUHFwO5HDETMhUtBRGBKNsC9zbZLrcCk1aEARsFzw8pH+MQVEfkDu0InwJpA4cl7wAxFSUAGyKfCEdnAGOP3FMJLs8Iy2pwI3gDaxTrZRF3B5UOWwerHDcVwxzlcMxeD4YMKKezCV8BeQmdAWME5wgNNV+MpCBFZ1eLXBifIGVBQ14AAjUMaRWjRMGHfAKPD28SHwE5AXcHPQ0FAnsR8RFvEJkI74YINbkz/DopBFMhhyAVCisDU2zSCysm/Qz8bQGnEmYDEDRBd/Jnr2C6KBgBBx0yyUFkIfULlk/RDKAaxRhGVDIZ6AfDA/ca9yfuQVsGAwOnBxc6UTPyBMELbQiPCUMATQ6nGwfbGG4KdYzUATWPAbudA1uVhwJzkwY7Bw8Aaw+LBX3pACECqwinAAkA0wNbAD0CsQehAB0AiUUBQQMrMwEl6QKTA5cINc8BmTMB9y0EH8cMGQD7O25OAsO1AoBuZqYF4VwCkgJNOQFRKQQJUktVA7N15QDfAE8GF+NLARmvTs8e50cB43MvAMsA/wAJOQcJRQHRAfdxALsBYws1Caa3uQFR7S0AhwAZbwHbAo0A4QA5AIP1AVcAUQVd/QXXAlNNARU1HC9bZQG/AyMBNwERAH0Gz5GpzQsjBHEH1wIQHxXlAu8yB7kFAyLjE9FCyQK94lkAMhoKPAqrCqpgX2Q3CjV2PVQAEh+sPss/UgVVO1c7XDtXO1w7VztcO1c7XDtXO1wDm8Pmw+YKcF9JYe8Mqg3YRMw6TRPfYFVgNhPMLbsUxRXSJVoZQRrAJwkl6FUNDwgt12Y0CDA0eRfAAEMpbINFY4oeNApPHOtTlVT8LR8AtUumM7MNsBsZREQFS3XxYi4WEgomAmSFAmJGX1GzAV83JAKh+wJonAJmDQKfiDgfDwJmPwJmKgRyBIMDfxcDfpY5Cjl7GzmGOicnAmwhAjI6OA4CbcsCbbLzjgM3a0kvAWsA4gDlAE4JB5wMkQECD8YAEbkCdzMCdqZDAnlPRwJ4viFg30WyRvcCfEMCeswCfQ0CfPRIBEiBZygALxlJXEpfGRtK0ALRBQLQ0EsrA4hTA4fqRMmRNgLypV0HAwOyS9JMMSkH001QTbMCi0MCitzFHwshR2sJuwKOOwKOYESbhQKO3QKOYHxRuFM5AQ5S2FSJApP/ApMQAO0AIFUiVbNV1AosHymZijLleGpFPz0Cl6MC77ZYJawAXSkClpMCloCgAK1ZsFoNhVEAPwKWuQKWUlxIXNUCmc8CmWhczl0LHQKcnznGOqECnBoCn58CnryOACETNS4TAp31Ap6WALlBYThh8wKe1wKgcgGtAp6jIwKeUqljzGQrKS8CJ7MCJoICoP8CoFDbAqYzAqXSAqgDAIECp/ZogGi1AAdNaiBq1QKs5wKssgKtawKtBgJXIQJV4AKx5dsDH1JsmwKywRECsuwbbORtZ21MYwMl0QK2YD9DbpQDKUkCuGICuUsZArkue3A6cOUCvR0DLbYDMhUCvoxyBgMzdQK+HnMmc1MCw88CwwhzhnRPOUl05AM8qwEDPJ4DPcMCxYACxksCxhSNAshtVQLISALJUwLJMgJkoQLd1nh9ZXiyeSlL1AMYp2cGAmH4GfeVKHsPXpZevxUCz28Cz3AzT1fW9xejAMqxAs93AS3uA04Wfk8JAtwrAtuOAtJTA1JgA1NjAQUDVZCAjUMEzxrxZEl5A4LSg5EC2ssC2eKEFIRNp0ADhqkAMwNkEoZ1Xf0AWQLfaQLevHd7AuIz7RgB8zQrAfSfAfLWiwLr9wLpdH0DAur9AuroAP1LAb0C7o0C66CWrpcHAu5DA4XkmH1w5HGlAvMHAG0DjhqZlwL3FwORcgOSiwL3nAL53QL4apogmq+/O5siA52HAv7+AR8APZ8gAZ+3AwWRA6ZuA6bdANXJAwZuoYyiCQ0DDE0BEwEjB3EGZb1rCQC/BG/DFY8etxEAG3k9ACcDNxJRA42DAWcrJQCM8wAlAOanC6OVCLsGI6fJBgCvBRnDBvElRUYFFoAFcD9GSDNCKUK8X3kZX8QAls0FOgCQVCGbwTsuYDoZutcONxjOGJHJ/gVfBWAFXwVgBWsFYAVfBWAFXwVgBV8FYAVfBWBOHQjfjW8KCgoKbF7xMwTRA7kGN8PDAMMEr8MA70gxFroFTj5xPnhCR0K+X30/X/AAWBkzswCNBsxzzASm70aCRS4rDDMeLz49fnXfcsH5GcoscQFz13Y4HwVnBXLJycnACNdRYwgICAqEXoWTxgA7P4kACxbZBu21Kw0AjMsTAwkVAOVtJUUsJ1JCuULESUArXy9gPi9AKwnJRQYKTD9LPoA+iT54PnkCkULEUUpDX9NWV3JVEjQAc1w3A3IBE3YnX+g7QiMJb6MKaiszRCUuQrNCxDPMCcwEX9EWJzYREBEEBwIHKn6l33JCNVIfybPJtAltydPUCmhBZw/tEKsZAJOVJU1CLRuxbUHOQAo7P0s+eEJHHA8SJVRPdGM0NVrpvBoKhfUlM0JHHGUQUhEWO1xLSj8MO0ucNAqJIzVCRxv9EFsqKyA4OQgNj2nwZgp5ZNFgE2A1K3YHS2AhQQojJmC7DgpzGG1WYFUZCQYHZO9gHWCdYIVgu2BTYJlwFh8GvRbcXbG8YgtDHrMBwzPVyQonHQgkCyYBgQJ0Ajc4nVqIAwGSCsBPIgDsK3SWEtIVBa5N8gGjAo+kVwVIZwD/AEUSCDweX4ITrRQsJ8K3TwBXFDwEAB0TvzVcAtoTS20RIwDgVgZ9BBImYgA5AL4Coi8LFnezOkCnIQFjAY4KBAPh9RcGsgZSBsEAJctdsWIRu2kTkQstRw7DAcMBKgpPBGIGMDAwKCYnKTQaLg4AKRSVAFwCdl+YUZ0JdicFD3lPAdt1F9ZZKCGxuE3yBxkFVGcA/wBFEgiCBwAOLHQSjxOtQDg1z7deFRMAZ8QTAGtKb1ApIiPHADkAvgKiLy1DFtYCmBiDAlDDWNB0eo7fpaMO/aEVRRv0ATEQZBIODyMEAc8JQhCbDRgzFD4TAEMAu9YBCgCsAOkAm5I3ABwAYxvONnR+MhXJAxgKQyxL2+kkJhMbhQKDBMkSsvF0AD9BNQ6uQC7WqSQHwxEAEEIu1hkhAH2z4iQPwyJPHNWpdyYBRSpnJALzoBAEVPPsH20MxA0CCEQKRgAFyAtFAlMNwwjEDUQJRArELtapMg7DDZgJIw+TGukEIwvDFkMAqAtDEMMMBhioe+QAO3MMRAACrgnEBSPY9Q0FDnbSBoMAB8MSYxkSxAEJAPIJAAB8FWMOFtMc/HcXwxhDAC7DAvOowwAewwJdKDKHAAHDAALrFUQVwwAbwyvzpWMWv8wA/ABpAy++bcYDUKPD0KhDCwKmJ1MAAmMA5+UZwxAagwipBRL/eADfw6fDGOMCGsOjk3l6BwOpo4sAEsMOGxMAA5sAbcMOAAvDp0MJGkMDwgipnNIPAwfIqUMGAOGDAAPzABXDAAcDAAnDAGmTABrDAA7DChjDjnEWAwABYwAOcwAuUyYABsMAF8MIKQANUgC6wy4AA8MADqMq8wCyYgAcIwAB8wqpAAXOCx0V4wAHowBCwwEKAGnDAAuDAB3DAAjDCakABdIAbqcZ3QCZCCkABdIAAAFDAAfjAB2jCCkABqIACYMAGzMAbSMA5sOIAAhjAAhDABTDBAkpAAbSAOOTAAlDC6kOzPtnAAdDAG6kQFAATwAKwwwAA0MACbUDPwAHIwAZgwACE6cDAAojAApDAAoDp/MGwwAJIwADEwAQQwgAFEMAEXMAD5MADfMADcMAGRMOFiMAFUMAbqMWuwHDAMIAE0MLAGkzEgDhUwACQwAEWgAXgwUjAAbYABjDBSYBgzBaAEFNALcQBxUMegAwMngBrA0IZgJ0KxQHBREPd1N0ZzKRJwaIHAZqNT4DqQq8BwngAB4DAwt2AX56T1ocKQNXAh1GATQGC3tOxYNagkgAMQA5CQADAQEAWxLjAIOYNAEzAH7tFRk6TglSAF8NAAlYAQ+S1ACAQwQorQBiAN4dAJ1wPyeTANVzuQDX3AIeEMp9eyMgXiUAEdkBkJizKltbVVAaRMqRAAEAhyQ/SDEz6BmfVwB6ATEsOClKIRcDOF0E/832AFNt5AByAnkCRxGCOs94NjXdAwINGBonDBwPALW2AwICAgAAAAAAAAYDBQMDARrUAwAtAAAAAgEGBgYGBgYFBQUFBQUEBQYHCAkEBQUFBQQAAAICAAAAIgCNAJAAlT0A6gC7ANwApEQAwgCyAK0AqADuAKYA2gCjAOcBCAEDAMcAgQBiANIA1AEDAN4A8gCQAKkBMQDqAN8A3AsBCQ8yO9ra2tq8xuLT1tRJOB0BUgFcNU0BWgFpAWgBWwFMUUlLbhMBUxsNEAs6PhMOACcUKy0vMj5AQENDQ0RFFEYGJFdXV1dZWVhZL1pbXVxcI2NnZ2ZoZypsbnZ1eHh4eHh4enp6enp6enp6enp8fH18e2IARPIASQCaAHgAMgBm+ACOAFcAVwA3AnbvAIsABfj4AGQAk/IAnwBPAGIAZP//sACFAIUAaQBWALEAJAC2AIMCQAJDAPwA5wD+AP4A6AD/AOkA6QDoAOYALwJ7AVEBQAE+AVQBPgE+AT4BOQE4ATgBOAEcAVgXADEQCAEAUx8SHgsdHhYAjgCWAKYAUQBqIAIxAHYAbwCXAxUDJzIDIUlGTzEAkQJPAMcCVwKkAMAClgKWApYClgKWApYCiwKWApYClgKWApYClgKVApUCmAKgApcClgKWApQClAKUApQCkgKVAnUB1AKXAp8ClgKWApUeAIETBQD+DQOfAmECOh8BVBg9AuIZEjMbAU4/G1WZAXusRAFpYQEFA0FPAQYAmTEeIJdyADFoAHEANgCRA5zMk/C2jGINwjMWygIZCaXdfDILBCs5dAE7YnQBugDlhoiHhoiGiYqKhouOjIaNkI6Ij4qQipGGkoaThpSSlYaWhpeKmIaZhpqGm4aci52QnoqfhuIC4XTpAt90AIp0LHSoAIsAdHQEQwRABEIERQRDBEkERgRBBEcESQRIBEQERgRJAJ5udACrA490ALxuAQ10ANFZdHQA13QCFHQA/mJ0AP4BIQD+APwA/AD9APwDhGZ03ASMK23HAP4A/AD8AP0A/CR0dACRYnQA/gCRASEA/gCRAvQA/gCRA4RmdNwEjCttxyR0AP9idAEhAP4A/gD8APwA/QD8AP8A/AD8AP0A/AOEZnTcBIwrbcckdHQAkWJ0ASEA/gCRAP4AkQL0AP4AkQOEZnTcBIwrbcckdAJLAT50AlIBQXQCU8l0dAJfdHQDpgL0A6YDpgOnA6cDpwOnA4RmdNwEjCttxyR0dACRYnQBIQOmAJEDpgCRAvQDpgCRA4RmdNwEjCttxyR0BDh0AJEEOQCRDpU5dSgCADR03gV2CwArdAEFAM5iCnR0AF1iAAYcOgp0dACRCnQAXAEIwWZ0CnRmdHQAkWZ0CnRmdEXgAFF03gp0dEY0tlT2u3SOAQTwscwhjZZKrhYcBSfFp9XNbKiVDOD2b+cpe4/Z17mQnbtzzhaeQtE2GGj0IDNTjRUSyTxxw/RPHW/+vS7d1NfRt9z9QPZg4X7QFfhCnkvgNPIItOsC2eV6hPannZNHlZ9xrwZXIMOlu3jSoQSq78WEjwLjw1ELSlF1aBvfzwk5ZX7AUvQzjPQKbDuQ+sm4wNOp4A6AdVuRS0t1y/DZpg4R6m7FNjM9HgvW7Bi88zaMjOo6lM8wtBBdj8LP4ylv3zCXPhebMKJc066o9sF71oFW/8JXu86HJbwDID5lzw5GWLR/LhT0Qqnp2JQxNZNfcbLIzPy+YypqRm/lBmGmex+82+PisxUumSeJkALIT6rJezxMH+CTJmQtt5uwTVbL3ptmjDUQzlSIvWi8Tl7ng1NpuRn1Ng4n14Qc+3Iil7OwkvNWogLSPkn3pihIFytyIGmMhOe3n1tWsuMy9BdKyqF4Z3v2SgggTL9KVvMXPnCbRe+oOuFFP3HejBG/w9gvmfNYvg6JuWia2lcSSN1uIjBktzoIazOHPJZ7kKHPz8mRWVdW3lA8WGF9dQF6Bm673boov3BUWDU2JNcahR23GtfHKLOz/viZ+rYnZFaIznXO67CYEJ1fXuTRpZhYZkKe54xeoagkNGLs+NTZHE0rX45/XvQ2RGADX6vcAvdxIUBV27wxGm2zjZo4X3ILgAlrOFheuZ6wtsvaIj4yLY7qqawlliaIcrz2G+c3vscAnCkCuMzMmZvMfu9lLwTvfX+3cVSyPdN9ZwgDZhfjRgNJcLiJ67b9xx8JHswprbiE3v9UphotAPIgnXVIN5KmMc0piXhc6cChPnN+MRhG9adtdttQTTwSIpl8I4/j//d3sz1326qTBTpPRM/Hgh3kzqEXs8ZAk4ErQhNO8hzrQ0DLkWMA/N+91tn2MdOJnWC2FCZehkQrwzwbKOjhvZsbM95QoeL9skYyMf4srVPVJSgg7pOLUtr/n9eT99oe9nLtFRpjA9okV2Kj8h9k5HaC0oivRD8VyXkJ81tcd4fHNXPCfloIQasxsuO18/46dR2jgul/UIet2G0kRvnyONMKhHs6J26FEoqSqd+rfYjeEGwHWVDpX1fh1jBBcKGMqRepju9Y00mDVHC+Xdij/j44rKfvfjGinNs1jO/0F3jB83XCDINN/HB84axlP+3E/klktRo+vl3U/aiyMJbIodE1XSsDn6UAzIoMtUObY2+k/4gY/l+AkZJ5Sj2vQrkyLm3FoxjhDX+31UXBFf9XrAH31fFqoBmDEZvhvvpnZ87N+oZEu7U9O/nnk+QWj3x8uyoRbEnf+O5UMr9i0nHP38IF5AvzrBW8YWBUR0mIAzIvndQq9N3v/Jto3aPjPXUPl8ASdPPyAp7jENf8bk7VMM9ol9XGmlBmeDMuGqt+WzuL6CXAxXjIhCPM5vACchgMJ/8XBGLO/D1isVvGhwwHHr1DLaI5mn2Jr/b1pUD90uciDaS8cXNDzCWvNmT/PhQe5e8nTnnnkt8Ds/SIjibcum/fqDhKopxAY8AkSrPn+IGDEKOO+U3XOP6djFs2H5N9+orhOahiQk5KnEUWa+CzkVzhp8bMHRbg81qhjjXuIKbHjSLSIBKWqockGtKinY+z4/RdBUF6pcc3JmnlxVcNgrI4SEzKUZSwcD2QCyxzKve+gAmg6ZuSRkpPFa6mfThu7LJNu3H5K42uCpNvPAsoedolKV/LHe/eJ+BbaG5MG0NaSGVPRUmNFMFFSSpXEcXwbVh7UETOZZtoVNRGOIbbkig3McEtR68cG0RZAoJevWYo7Dg/lZ1CQzblWeUvVHmr8fY4Nqd9JJiH/zEX24mJviH60fAyFr0A3c4bC1j3yZU60VgJxXn8JgJXLUIsiBnmKmMYz+7yBQFBvqb2eYnuW59joZBf56/wXvWIR4R8wTmV80i1mZy+S4+BUES+hzjk0uXpC///z/IlqHZ1monzlXp8aCfhGKMti73FI1KbL1q6IKO4fuBuZ59gagjn5xU79muMpHXg6S+e+gDM/U9BKLHbl9l6o8czQKl4RUkJJiqftQG2i3BMg/TQlUYFkJDYBOOvAugYuzYSDnZbDDd/aSd9x0Oe6F+bJcHfl9+gp6L5/TgA+BdFFovbfCrQ40s5vMPw8866pNX8zyFGeFWdxIpPVp9Rg1UPOVFbFZrvaFq/YAzHQgqMWpahMYfqHpmwXfHL1/kpYmGuHFwT55mQu0dylfNuq2Oq0hTMCPwqfxnuBIPLXfci4Y1ANy+1CUipQxld/izVh16WyG2Q0CQQ9NqtAnx1HCHwDj7sYxOSB0wopZSnOzxQOcExmxrVTF2BkOthVpGfuhaGECfCJpJKpjnihY+xOT2QJxN61+9K6QSqtv2Shr82I3jgJrqBg0wELFZPjvHpvzTtaJnLK6Vb97Yn933koO/saN7fsjwNKzp4l2lJVx2orjCGzC/4ZL4zCver6aQYtC5sdoychuFE6ufOiog+VWi5UDkbmvmtah/3aArEBIi39s5ILUnlFLgilcGuz9CQshEY7fw2ouoILAYPVT/gyAIq3TFAIwVsl+ktkRz/qGfnCDGrm5gsl/l9QdvCWGsjPz3dU7XuqKfdUrr/6XIgjp4rey6AJBmCmUJMjITHVdFb5m1p+dLMCL8t55zD42cmftmLEJC0Da04YiRCVUBLLa8D071/N5UBNBXDh0LFsmhV/5B5ExOB4j3WVG/S3lfK5o+V6ELHvy6RR9n4ac+VsK4VE4yphPvV+kG9FegTBH4ZRXL2HytUHCduJazB/KykjfetYxOXTLws267aGOd+I+JhKP//+VnXmS90OD/jvLcVu0asyqcuYN1mSb6XTlCkqv1vigZPIYwNF/zpWcT1GR/6aEIRjkh0yhg4LXJfaGobYJTY4JI58KiAKgmmgAKWdl5nYCeLqavRJGQNuYuZtZFGx+IkI4w4NS2xwbetNMunOjBu/hmKCI/w7tfiiyUd//4rbTeWt4izBY8YvGIN6vyKYmP/8X8wHKCeN+WRcKM70+tXKNGyevU9H2Dg5BsljnTf8YbsJ1TmMs74Ce2XlHisleguhyeg44rQOHZuw/6HTkhnnurK2d62q6yS7210SsAIaR+jXMQA+svkrLpsUY+F30Uw89uOdGAR6vo4FIME0EfVVeHTu6eKicfhSqOeXJhbftcd08sWEnNUL1C9fnprTgd83IMut8onVUF0hvqzZfHduPjbjwEXIcoYmy+P6tcJZHmeOv6VrvEdkHDJecjHuHeWANe79VG662qTjA/HCvumVv3qL+LrOcpqGps2ZGwQdFJ7PU4iuyRlBrwfO+xnPyr47s2cXVbWzAyznDiBGjCM3ksxjjqM62GE9C8f5U38kB3VjtabKp/nRdvMESPGDG90bWRLAt1Qk5DyLuazRR1YzdC1c+hZXvAWV8xA72S4A8B67vjVhbba3MMop293FeEXpe7zItMWrJG/LOH9ByOXmYnNJfjmfuX9KbrpgLOba4nZ+fl8Gbdv/ihv+6wFGKHCYrVwmhFC0J3V2bn2tIB1wCc1CST3d3X2OyxhguXcs4sm679UngzofuSeBewMFJboIQHbUh/m2JhW2hG9DIvG2t7yZIzKBTz9wBtnNC+2pCRYhSIuQ1j8xsz5VvqnyUIthvuoyyu7fNIrg/KQUVmGQaqkqZk/Vx5b33/gsEs8yX7SC1J+NV4icz6bvIE7C5G6McBaI8rVg56q5QBJWxn/87Q1sPK4+sQa8fLU5gXo4paaq4cOcQ4wR0VBHPGjKh+UlPCbA1nLXyEUX45qZ8J7/Ln4FPJE2TdzD0Z8MLSNQiykMMmSyOCiFfy84Rq60emYB2vD09KjYwsoIpeDcBDTElBbXxND72yhd9pC/1CMid/5HUMvAL27OtcIJDzNKpRPNqPOpyt2aPGz9QWIs9hQ9LiX5s8m9hjTUu/f7MyIatjjd+tSfQ3ufZxPpmJhTaBtZtKLUcfOCUqADuO+QoH8B9v6U+P0HV1GLQmtoNFTb3s74ivZgjES0qfK+8RdGgBbcCMSy8eBvh98+et1KIFqSe1KQPyXULBMTsIYnysIwiZBJYdI20vseV+wuJkcqGemehKjaAb9L57xZm3g2zX0bZ2xk/fU+bCo7TlnbW7JuF1YdURo/2Gw7VclDG1W7LOtas2LX4upifZ/23rzpsnY/ALfRgrcWP5hYmV9VxVOQA1fZvp9F2UNU+7d7xRyVm5wiLp3/0dlV7vdw1PMiZrbDAYzIVqEjRY2YU03sJhPnlwIPcZUG5ltL6S8XCxU1eYS5cjr34veBmXAvy7yN4ZjArIG0dfD/5UpBNlX1ZPoxJOwyqRi3wQWtOzd4oNKh0LkoTm8cwqgIfKhqqGOhwo71I+zXnMemTv2B2AUzABWyFztGgGULjDDzWYwJUVBTjKCn5K2QGMK1CQT7SzziOjo+BhAmqBjzuc3xYym2eedGeOIRJVyTwDw37iCMe4g5Vbnsb5ZBdxOAnMT7HU4DHpxWGuQ7GeiY30Cpbvzss55+5Km1YsbD5ea3NI9QNYIXol5apgSu9dZ8f8xS5dtHpido5BclDuLWY4lhik0tbJa07yJhH0BOyEut/GRbYTS6RfiTYWGMCkNpfSHi7HvdiTglEVHKZXaVhezH4kkXiIvKopYAlPusftpE4a5IZwvw1x/eLvoDIh/zpo9FiQInsTb2SAkKHV42XYBjpJDg4374XiVb3ws4qM0s9eSQ5HzsMU4OZJKuopFjBM+dAZEl8RUMx5uU2N486Kr141tVsGQfGjORYMCJAMsxELeNT4RmWjRcpdTGBwcx6XN9drWqPmJzcrGrH4+DRc7+n1w3kPZwu0BkNr6hQrqgo7JTB9A5kdJ/H7P4cWBMwsmuixAzJB3yrQpnGIq90lxAXLzDCdn1LPibsRt7rHNjgQBklRgPZ8vTbjXdgXrTWQsK5MdrXXQVPp0Rinq3frzZKJ0qD6Qhc40VzAraUXlob1gvkhK3vpmHgI6FRlQZNx6eRqkp0zy4AQlX813fAPtL3jMRaitGFFjo0zmErloC+h+YYdVQ6k4F/epxAoF0BmqEoKNTt6j4vQZNQ2BoqF9Vj53TOIoNmDiu9Xp15RkIgQIGcoLpfoIbenzpGUAtqFJp5W+LLnx38jHeECTJ/navKY1NWfN0sY1T8/pB8kIH3DU3DX+u6W3YwpypBMYOhbSxGjq84RZ84fWJow8pyHqn4S/9J15EcCMsXqrfwyd9mhiu3+rEo9pPpoJkdZqHjra4NvzFwuThNKy6hao/SlLw3ZADUcUp3w3SRVfW2rhl80zOgTYnKE0Hs2qp1J6H3xqPqIkvUDRMFDYyRbsFI3M9MEyovPk8rlw7/0a81cDVLmBsR2ze2pBuKb23fbeZC0uXoIvDppfTwIDxk1Oq2dGesGc+oJXWJLGkOha3CX+DUnzgAp9HGH9RsPZN63Hn4RMA5eSVhPHO+9RcRb/IOgtW31V1Q5IPGtoxPjC+MEJbVlIMYADd9aHYWUIQKopuPOHmoqSkubnAKnzgKHqgIOfW5RdAgotN6BN+O2ZYHkuemLnvQ8U9THVrS1RtLmKbcC7PeeDsYznvqzeg6VCNwmr0Yyx1wnLjyT84BZz3EJyCptD3yeueAyDWIs0L2qs/VQ3HUyqfrja0V1LdDzqAikeWuV4sc7RLIB69jEIBjCkyZedoUHqCrOvShVzyd73OdrJW0hPOuQv2qOoHDc9xVb6Yu6uq3Xqp2ZaH46A7lzevbxQEmfrzvAYSJuZ4WDk1Hz3QX1LVdiUK0EvlAGAYlG3Md30r7dcPN63yqBCIj25prpvZP0nI4+EgWoFG95V596CurXpKRBGRjQlHCvy5Ib/iW8nZJWwrET3mgd6mEhfP4KCuaLjopWs7h+MdXFdIv8dHQJgg1xi1eYqB0uDYjxwVmri0Sv5XKut/onqapC+FQiC2C1lvYJ9MVco6yDYsS3AANUfMtvtbYI2hfwZatiSsnoUeMZd34GVjkMMKA+XnjJpXgRW2SHTZplVowPmJsvXy6w3cfO1AK2dvtZEKTkC/TY9LFiKHCG0DnrMQdGm2lzlBHM9iEYynH2UcVMhUEjsc0oDBTgo2ZSQ1gzkAHeWeBXYFjYLuuf8yzTCy7/RFR81WDjXMbq2BOH5dURnxo6oivmxL3cKzKInlZkD31nvpHB9Kk7GfcfE1t+1V64b9LtgeJGlpRFxQCAqWJ5DoY77ski8gsOEOr2uywZaoO/NGa0X0y1pNQHBi3b2SUGNpcZxDT7rLbBf1FSnQ8guxGW3W+36BW0gBje4DOz6Ba6SVk0xiKgt+q2JOFyr4SYfnu+Ic1QZYIuwHBrgzr6UvOcSCzPTOo7D6IC4ISeS7zkl4h+2VoeHpnG/uWR3+ysNgPcOIXQbv0n4mr3BwQcdKJxgPSeyuP/z1Jjg4e9nUvoXegqQVIE30EHx5GHv+FAVUNTowYDJgyFhf5IvlYmEqRif6+WN1MkEJmDcQITx9FX23a4mxy1AQRsOHO/+eImX9l8EMJI3oPWzVXxSOeHU1dUWYr2uAA7AMb+vAEZSbU3qob9ibCyXeypEMpZ6863o6QPqlqGHZkuWABSTVNd4cOh9hv3qEpSx2Zy/DJMP6cItEmiBJ5PFqQnDEIt3NrA3COlOSgz43D7gpNFNJ5MBh4oFzhDPiglC2ypsNU4ISywY2erkyb1NC3Qh/IfWj0eDgZI4/ln8WPfBsT3meTjq1Uqt1E7Zl/qftqkx6aM9KueMCekSnMrcHj1CqTWWzEzPsZGcDe3Ue4Ws+XFYVxNbOFF8ezkvQGR6ZOtOLU2lQEnMBStx47vE6Pb7AYMBRj2OOfZXfisjJnpTfSNjo6sZ6qSvNxZNmDeS7Gk3yYyCk1HtKN2UnhMIjOXUzAqDv90lx9O/q/AT1ZMnit5XQe9wmQxnE/WSH0CqZ9/2Hy+Sfmpeg8RwsHI5Z8kC8H293m/LHVVM/BA7HaTJYg5Enk7M/xWpq0192ACfBai2LA/qrCjCr6Dh1BIMzMXINBmX96MJ5Hn2nxln/RXPFhwHxUmSV0EV2V0jm86/dxxuYSU1W7sVkEbN9EzkG0QFwPhyHKyb3t+Fj5WoUUTErcazE/N6EW6Lvp0d//SDPj7EV9UdJN+Amnf3Wwk3A0SlJ9Z00yvXZ7n3z70G47Hfsow8Wq1JXcfwnA+Yxa5mFsgV464KKP4T31wqIgzFPd3eCe3j5ory5fBF2hgCFyVFrLzI9eetNXvM7oQqyFgDo4CTp/hDV9NMX9JDHQ/nyHTLvZLNLF6ftn2OxjGm8+PqOwhxnPHWipkE/8wbtyri80Sr7pMNkQGMfo4ZYK9OcCC4ESVFFbLMIvlxSoRqWie0wxqnLfcLSXMSpMMQEJYDVObYsXIQNv4TGNwjq1kvT1UOkicTrG3IaBZ3XdScS3u8sgeZPVpOLkbiF940FjbCeNRINNvDbd01EPBrTCPpm12m43ze1bBB59Ia6Ovhnur/Nvx3IxwSWol+3H2qfCJR8df6aQf4v6WiONxkK+IqT4pKQrZK/LplgDI/PJZbOep8dtbV7oCr6CgfpWa8NczOkPx81iSHbsNhVSJBOtrLIMrL31LK9TqHqAbAHe0RLmmV806kRLDLNEhUEJfm9u0sxpkL93Zgd6rw+tqBfTMi59xqXHLXSHwSbSBl0EK0+loECOPtrl+/nsaFe197di4yUgoe4jKoAJDXc6DGDjrQOoFDWZJ9HXwt8xDrQP+7aRwWKWI1GF8s8O4KzxWBBcwnl3vnl1Oez3oh6Ea1vjR7/z7DDTrFtqU2W/KAEzAuXDNZ7MY73MF216dzdSbWmUp4lcm7keJfWaMHgut9x5C9mj66Z0lJ+yhsjVvyiWrfk1lzPOTdhG15Y7gQlXtacvI7qv/XNSscDwqkgwHT/gUsD5yB7LdRRvJxQGYINn9hTpodKFVSTPrtGvyQw+HlRFXIkodErAGu9Iy1YpfSPc3jkFh5CX3lPxv7aqjE/JAfTIpEjGb/H7MO0e2vsViSW1qa/Lmi4/n4DEI3g7lYrcanspDfEpKkdV1OjSLOy0BCUqVoECaB55vs06rXl4jqmLsPsFM/7vYJ0vrBhDCm/00A/H81l1uekJ/6Lml3Hb9+NKiLqATJmDpyzfYZFHumEjC662L0Bwkxi7E9U4cQA0XMVDuMYAIeLMPgQaMVOd8fmt5SflFIfuBoszeAw7ow5gXPE2Y/yBc/7jExARUf/BxIHQBF5Sn3i61w4z5xJdCyO1F1X3+3ax+JSvMeZ7S6QSKp1Fp/sjYz6Z+VgCZzibGeEoujryfMulH7Rai5kAft9ebcW50DyJr2uo2z97mTWIu45YsSnNSMrrNUuG1XsYBtD9TDYzQffKB87vWbkM4EbPAFgoBV4GQS+vtFDUqOFAoi1nTtmIOvg38N4hT2Sn8r8clmBCXspBlMBYTnrqFJGBT3wZOzAyJDre9dHH7+x7qaaKDOB4UQALD5ecS0DE4obubQEiuJZ0EpBVpLuYcce8Aa4PYd/V4DLDAJBYKQPCWTcrEaZ5HYbJi11Gd6hjGom1ii18VHYnG28NKpkz2UKVPxlhYSp8uZr367iOmoy7zsxehW9wzcy2zG0a80PBMCRQMb32hnaHeOR8fnNDzZhaNYhkOdDsBUZ3loDMa1YP0uS0cjUP3b/6DBlqmZOeNABDsLl5BI5QJups8uxAuWJdkUB/pO6Zax6tsg7fN5mjjDgMGngO+DPcKqiHIDbFIGudxtPTIyDi9SFMKBDcfdGQRv41q1AqmxgkVfJMnP8w/Bc7N9/TR6C7mGObFqFkIEom8sKi2xYqJLTCHK7cxzaZvqODo22c3wisBCP4HeAgcRbNPAsBkNRhSmD48dHupdBRw4mIvtS5oeF6zeT1KMCyhMnmhpkFAGWnGscoNkwvQ8ZM5lE/vgTHFYL99OuNxdFBxTEDd5v2qLR8y9WkXsWgG6kZNndFG+pO/UAkOCipqIhL3hq7cRSdrCq7YhUsTocEcnaFa6nVkhnSeRYUA1YO0z5itF9Sly3VlxYDw239TJJH6f3EUfYO5lb7bcFcz8Bp7Oo8QmnsUHOz/fagVUBtKEw1iT88j+aKkv8cscKNkMxjYr8344D1kFoZ7/td1W6LCNYN594301tUGRmFjAzeRg5vyoM1F6+bJZ/Q54jN/k8SFd3DxPTYaAUsivsBfgTn7Mx8H2SpPt4GOdYRnEJOH6jHM2p6SgB0gzIRq6fHxGMmSmqaPCmlfwxiuloaVIitLGN8wie2CDWhkzLoCJcODh7KIOAqbHEvXdUxaS4TTTs07Clzj/6GmVs9kiZDerMxEnhUB6QQPlcfqkG9882RqHoLiHGBoHfQuXIsAG8GTAtao2KVwRnvvam8jo1e312GQAKWEa4sUVEAMG4G6ckcONDwRcg1e2D3+ohXgY4UAWF8wHKQMrSnzCgfFpsxh+aHXMGtPQroQasRY4U6UdG0rz1Vjbka0MekOGRZQEvqQFlxseFor8zWFgHek3v29+WqN6gaK5gZOTOMZzpQIC1201LkMCXild3vWXSc5UX9xcFYfbRPzGFa1FDcPfPB/jUEq/FeGt419CI3YmBlVoHsa4KdcwQP5ZSwHHhFJ7/Ph/Rap/4vmG91eDwPP0lDfCDRCLszTqfzM71xpmiKi2HwS4WlqvGNwtvwF5Dqpn6KTq8ax00UMPkxDcZrEEEsIvHiUXXEphdb4GB4FymlPwBz4Gperqq5pW7TQ6/yNRhW8VT5NhuP0udlxo4gILq5ZxAZk8ZGh3g4CqxJlPKY7AQxupfUcVpWT5VItp1+30UqoyP4wWsRo3olRRgkWZZ2ZN6VC3OZFeXB8NbnUrSdikNptD1QiGuKkr8EmSR/AK9Rw+FF3s5uwuPbvHGiPeFOViltMK7AUaOsq9+x9cndk3iJEE5LKZRlWJbKOZweROzmPNVPkjE3K/TyA57Rs68TkZ3MR8akKpm7cFjnjPd/DdkWjgYoKHSr5Wu5ssoBYU4acRs5g2DHxUmdq8VXOXRbunD8QN0LhgkssgahcdoYsNvuXGUK/KXD/7oFb+VGdhqIn02veuM5bLudJOc2Ky0GMaG4W/xWBxIJcL7yliJOXOpx0AkBqUgzlDczmLT4iILXDxxtRR1oZa2JWFgiAb43obrJnG/TZC2KSK2wqOzRZTXavZZFMb1f3bXvVaNaK828w9TO610gk8JNf3gMfETzXXsbcvRGCG9JWQZ6+cDPqc4466Yo2RcKH+PILeKOqtnlbInR3MmBeGG3FH10yzkybuqEC2HSQwpA0An7d9+73BkDUTm30bZmoP/RGbgFN+GrCOfADgqr0WbI1a1okpFms8iHYw9hm0zUvlEMivBRxModrbJJ+9/p3jUdQQ9BCtQdxnOGrT5dzRUmw0593/mbRSdBg0nRvRZM5/E16m7ZHmDEtWhwvfdZCZ8J8M12W0yRMszXamWfQTwIZ4ayYktrnscQuWr8idp3PjT2eF/jmtdhIfcpMnb+IfZY2FebW6UY/AK3jP4u3Tu4zE4qlnQgLFbM19EBIsNf7KhjdbqQ/D6yiDb+NlEi2SKD+ivXVUK8ib0oBo366gXkR8ZxGjpJIDcEgZPa9TcYe0TIbiPl/rPUQDu3XBJ9X/GNq3FAUsKsll57DzaGMrjcT+gctp+9MLYXCq+sqP81eVQ0r9lt+gcQfZbACRbEjvlMskztZG8gbC8Qn9tt26Q7y7nDrbZq/LEz7kR6Jc6pg3N9rVX8Y5MJrGlML9p9lU4jbTkKqCveeZUJjHB03m2KRKR2TytoFkTXOLg7keU1s1lrPMQJpoOKLuAAC+y1HlJucU6ysB5hsXhvSPPLq5J7JtnqHKZ4vYjC4Vy8153QY+6780xDuGARsGbOs1WqzH0QS765rnSKEbbKlkO8oI/VDwUd0is13tKpqILu1mDJFNy/iJAWcvDgjxvusIT+PGz3ST/J9r9Mtfd0jpaGeiLYIqXc7DiHSS8TcjFVksi66PEkxW1z6ujbLLUGNNYnzOWpH8BZGK4bCK7iR+MbIv8ncDAz1u4StN3vTTzewr9IQjk9wxFxn+6N1ddKs0vffJiS08N3a4G1SVrlZ97Q/M+8G9fe5AP6d9/Qq4WRnORVhofPIKEdCr3llspUfE0oKIIYoByBRPh+bX1HLS3JWGJRhIvE1aW4NTd8ePi4Z+kXb+Z8snYfSNcqijhAgVsx4RCM54cXUiYkjeBmmC4ajOHrChoELscJJC7+9jjMjw5BagZKlgRMiSNYz7h7vvZIoQqbtQmspc0cUk1G/73iXtSpROl5wtLgQi0mW2Ex8i3WULhcggx6E1LMVHUsdc9GHI1PH3U2Ko0PyGdn9KdVOLm7FPBui0i9a0HpA60MsewVE4z8CAt5d401Gv6zXlIT5Ybit1VIA0FCs7wtvYreru1fUyW3oLAZ/+aTnZrOcYRNVA8spoRtlRoWflsRClFcgzkqiHOrf0/SVw+EpVaFlJ0g4Kxq1MMOmiQdpMNpte8lMMQqm6cIFXlnGbfJllysKDi+0JJMotkqgIxOSQgU9dn/lWkeVf8nUm3iwX2Nl3WDw9i6AUK3vBAbZZrcJpDQ/N64AVwjT07Jef30GSSmtNu2WlW7YoyW2FlWfZFQUwk867EdLYKk9VG6JgEnBiBxkY7LMo4YLQJJlAo9l/oTvJkSARDF/XtyAzM8O2t3eT/iXa6wDN3WewNmQHdPfsxChU/KtLG2Mn8i4ZqKdSlIaBZadxJmRzVS/o4yA65RTSViq60oa395Lqw0pzY4SipwE0SXXsKV+GZraGSkr/RW08wPRvqvSUkYBMA9lPx4m24az+IHmCbXA+0faxTRE9wuGeO06DIXa6QlKJ3puIyiuAVfPr736vzo2pBirS+Vxel3TMm3JKhz9o2ZoRvaFVpIkykb0Hcm4oHFBMcNSNj7/4GJt43ogonY2Vg4nsDQIWxAcorpXACzgBqQPjYsE/VUpXpwNManEru4NwMCFPkXvMoqvoeLN3qyu/N1eWEHttMD65v19l/0kH2mR35iv/FI+yjoHJ9gPMz67af3Mq/BoWXqu3rphiWMXVkmnPSEkpGpUI2h1MThideGFEOK6YZHPwYzMBvpNC7+ZHxPb7epfefGyIB4JzO9DTNEYnDLVVHdQyvOEVefrk6Uv5kTQYVYWWdqrdcIl7yljwwIWdfQ/y+2QB3eR/qxYObuYyB4gTbo2in4PzarU1sO9nETkmj9/AoxDA+JM3GMqQtJR4jtduHtnoCLxd1gQUscHRB/MoRYIEsP2pDZ9KvHgtlk1iTbWWbHhohwFEYX7y51fUV2nuUmnoUcqnWIQAAgl9LTVX+Bc0QGNEhChxHR4YjfE51PUdGfsSFE6ck7BL3/hTf9jLq4G1IafINxOLKeAtO7quulYvH5YOBc+zX7CrMgWnW47/jfRsWnJjYYoE7xMfWV2HN2iyIqLI");const t=()=>Hf(e),n=()=>new Set(t()),r=(e,t)=>t.forEach(t=>e.add(t));yh=new Map(Kf(e)),mh=n(),wh=t(),bh=new Set(t().map(e=>wh[e])),wh=new Set(wh),vh=n(),Eh=n();let o=zf(e),i=e();const s=()=>{let e=new Set;return t().forEach(t=>r(e,o[t])),r(e,t()),e};Ah=Vf(t=>{let n=Vf(e).map(e=>e+96);if(n.length){let r=t>=i;return n[0]-=32,n=Qf(n),r&&(n=`Restricted[${n}]`),{N:n,P:s(),Q:s(),M:!e(),R:r}}}),xh=n(),kh=new Map;let a=t().concat(dh(xh)).sort((e,t)=>e-t);a.forEach((t,n)=>{let r=e(),o=a[n]=r?a[n-r]:{V:[],M:new Map};o.V.push(t),xh.has(t)||kh.set(t,o)});for(let{V:e,M:t}of new Set(kh.values())){let n=[];for(let t of e){let e=Ah.filter(e=>ph(e,t)),o=n.find(({G:t})=>e.some(e=>t.has(e)));o||(o={G:new Set,V:[]},n.push(o)),o.V.push(t),r(o.G,e)}let o=n.flatMap(e=>dh(e.G));for(let{G:e,V:r}of n){let n=new Set(o.filter(t=>!e.has(t)));for(let e of r)t.set(e,n)}}Sh=new Set;let c=new Set;const u=e=>Sh.has(e)?c.add(e):Sh.add(e);for(let e of Ah){for(let t of e.P)u(t);for(let t of e.Q)u(t)}for(let e of Sh)kh.has(e)||c.has(e)||kh.set(e,1);r(Sh,fh(Sh)),Ih=function(e){let t=[],n=Hf(e);return function e({S:n,B:r},o,i){if(!(4&n&&i===o[o.length-1])){2&n&&(i=o[o.length-1]),1&n&&t.push(o);for(let t of r)for(let n of t.Q)e(t,[...o,n],i)}}(function t(r){let o=e(),i=Vf(()=>{let r=Hf(e).map(e=>n[e]);if(r.length)return t(r)});return{S:o,B:i,Q:r}}([]),[]),t}(e).map(e=>gh.from(e)).sort(Zf),Ph=new Map;for(let e of Ih){let t=[Ph];for(let n of e){let e=t.map(e=>{let t=e.get(n);return t||(t=new Map,e.set(n,t)),t});65039===n?t.push(...e):t=e}for(let n of t)n.V=e}}function Oh(e){return(Th(e)?"":`${Nh(Bh([e]))} `)+Jf(e)}function Nh(e){return`"${e}"‎`}function Bh(e,t=1/0,n=Jf){let r=[];var o;o=e[0],Ch(),wh.has(o)&&r.push("◌"),e.length>t&&(t>>=1,e=[...e.slice(0,t),8230,...e.slice(-t)]);let i=0,s=e.length;for(let t=0;t<s;t++){let o=e[t];Th(o)&&(r.push(Qf(e.slice(i,t))),r.push(n(o)),i=t+1)}return r.push(Qf(e.slice(i,s))),r.join("")}function Th(e){return Ch(),vh.has(e)}function Rh(e,t,n){if(!e)return[];Ch();let r=0;return e.split(".").map(e=>{let o=function(e){let t=[];for(let n=0,r=e.length;n<r;){let r=e.codePointAt(n);n+=r<65536?1:2,t.push(r)}return t}(e),i={input:o,offset:r};r+=o.length+1;try{let e,r=i.tokens=function(e,t,n){let r=[],o=[];for(e=e.slice().reverse();e.length;){let i=_h(e);if(i)o.length&&(r.push(t(o)),o=[]),r.push(n(i));else{let t=e.pop();if(Sh.has(t))o.push(t);else{let e=yh.get(t);if(e)o.push(...e);else if(!mh.has(t))throw Uh(t)}}}return o.length&&r.push(t(o)),r}(o,t,n),s=r.length;if(!s)throw new Error("empty label");let a=i.output=r.flat();if(function(e){for(let t=e.lastIndexOf(95);t>0;)if(95!==e[--t])throw new Error("underscore allowed only at start")}(a),!(i.emoji=s>1||r[0].is_emoji)&&a.every(e=>e<128))!function(e){if(e.length>=4&&45==e[2]&&45==e[3])throw new Error(`invalid label extension: "${Qf(e.slice(0,4))}"`)}(a),e="ASCII";else{let t=r.flatMap(e=>e.is_emoji?[]:e);if(t.length){if(wh.has(a[0]))throw Lh("leading combining mark");for(let e=1;e<s;e++){let t=r[e];if(!t.is_emoji&&wh.has(t[0]))throw Lh(`emoji + combining mark: "${Qf(r[e-1])} + ${Bh([t[0]])}"`)}!function(e){let t=e[0],n=_f.get(t);if(n)throw Lh(`leading ${n}`);let r=e.length,o=-1;for(let i=1;i<r;i++){t=e[i];let r=_f.get(t);if(r){if(o==i)throw Lh(`${n} + ${r}`);o=i+1,n=r}}if(o==r)throw Lh(`trailing ${n}`)}(a);let n=dh(new Set(t)),[o]=function(e){let t=Ah;for(let n of e){let e=t.filter(e=>ph(e,n));if(!e.length)throw Ah.some(e=>ph(e,n))?Dh(t[0],n):Uh(n);if(t=e,1==e.length)break}return t}(n);!function(e,t){for(let n of t)if(!ph(e,n))throw Dh(e,n);if(e.M){let e=fh(t);for(let t=1,n=e.length;t<n;t++)if(bh.has(e[t])){let r=t+1;for(let o;r<n&&bh.has(o=e[r]);r++)for(let n=t;n<r;n++)if(e[n]==o)throw new Error(`duplicate non-spacing marks: ${Oh(o)}`);if(r-t>4)throw new Error(`excessive non-spacing marks: ${Nh(Bh(e.slice(t-1,r)))} (${r-t}/4)`);t=r}}}(o,t),function(e,t){let n,r=[];for(let e of t){let t=kh.get(e);if(1===t)return;if(t){let r=t.M.get(e);if(n=n?n.filter(e=>r.has(e)):dh(r),!n.length)return}else r.push(e)}if(n)for(let t of n)if(r.every(e=>ph(t,e)))throw new Error(`whole-script confusable: ${e.N}/${t.N}`)}(o,n),e=o.N}else e="Emoji"}i.type=e}catch(e){i.error=e}return i})}function Uh(e){return new Error(`disallowed character: ${Oh(e)}`)}function Dh(e,t){let n=Oh(t),r=Ah.find(e=>e.P.has(t));return r&&(n=`${r.N} ${n}`),new Error(`illegal mixture: ${e.N} + ${n}`)}function Lh(e){return new Error(`illegal placement: ${e}`)}function Fh(e){return e.filter(e=>65039!=e)}function _h(e,t){let n,r=Ph,o=e.length;for(;o&&(r=r.get(e[--o]),r);){let{V:i}=r;i&&(n=i,t&&t.push(...e.slice(o).reverse()),e.length=o)}return n}const Mh=new Uint8Array(32);function jh(e){return Me(0!==e.length,"invalid ENS name; empty component","comp",e),e}function Gh(e){const t=ot(function(e){try{if(0===e.length)throw new Error("empty label");return function(e){return function(e){return e.map(({input:t,error:n,output:r})=>{if(n){let r=n.message;throw new Error(1==e.length?r:`Invalid label ${Nh(Bh(t,63))}: ${r}`)}return Qf(r)}).join(".")}(Rh(e,hh,Fh))}(e)}catch(t){Me(!1,`invalid ENS name (${t.message})`,"name",e)}}(e)),n=[];if(0===e.length)return n;let r=0;for(let e=0;e<t.length;e++)46===t[e]&&(n.push(jh(t.slice(r,e))),r=e+1);return Me(r<t.length,"invalid ENS name; empty component","name",e),n.push(jh(t.slice(r))),n}function Hh(e){Me("string"==typeof e,"invalid ENS name; not a string","name",e),Me(e.length,"invalid ENS name (empty label)","name",e);let t=Mh;const n=Gh(e);for(;n.length;)t=In(Ze([t,In(n.pop())]));return Qe(t)}function zh(e,t){const n=null!=t?t:63;return Me(n<=255,"DNS encoded label cannot exceed 255","length",n),Qe(Ze(Gh(e).map(t=>{Me(t.length<=n,`label ${JSON.stringify(e)} exceeds ${n} bytes`,"name",e);const r=new Uint8Array(t.length+1);return r.set(t,1),r[0]=r.length-1,r})))+"00"}Mh.fill(0),BigInt(0);const Kh=BigInt(1),Vh=BigInt(2),Wh=e=>e instanceof Uint8Array,$h=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function qh(e){if(!Wh(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=$h[e[n]];return t}function Jh(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function Qh(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let t=0;t<n.length;t++){const r=2*t,o=e.slice(r,r+2),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[t]=i}return n}function Zh(e){return Jh(qh(e))}function Yh(e){if(!Wh(e))throw new Error("Uint8Array expected");return Jh(qh(Uint8Array.from(e).reverse()))}function Xh(e,t){return Qh(e.toString(16).padStart(2*t,"0"))}function ed(e,t){return Xh(e,t).reverse()}function td(e,t,n){let r;if("string"==typeof t)try{r=Qh(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!Wh(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const o=r.length;if("number"==typeof n&&o!==n)throw new Error(`${e} expected ${n} bytes, got ${o}`);return r}function nd(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!Wh(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const rd=e=>(Vh<<BigInt(e-1))-Kh,od=e=>new Uint8Array(e),id=e=>Uint8Array.from(e);function sd(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=od(e),o=od(e),i=0;const s=()=>{r.fill(1),o.fill(0),i=0},a=(...e)=>n(o,r,...e),c=(e=od())=>{o=a(id([0]),e),r=a(),0!==e.length&&(o=a(id([1]),e),r=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=a();const t=r.slice();n.push(t),e+=r.length}return nd(...n)};return(e,t)=>{let n;for(s(),c(e);!(n=t(u()));)c();return s(),n}}const ad={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function cd(e,t,n={}){const r=(t,n,r)=>{const o=ad[n];if("function"!=typeof o)throw new Error(`Invalid validator "${n}", expected function`);const i=e[t];if(!(r&&void 0===i||o(i,e)))throw new Error(`Invalid param ${String(t)}=${i} (${typeof i}), expected ${n}`)};for(const[e,n]of Object.entries(t))r(e,n,!1);for(const[e,t]of Object.entries(n))r(e,t,!0);return e}const ud=BigInt(0),ld=BigInt(1),fd=BigInt(2),hd=BigInt(3),dd=BigInt(4),pd=BigInt(5),gd=BigInt(8);function yd(e,t){const n=e%t;return n>=ud?n:t+n}function md(e,t,n){if(n<=ud||t<ud)throw new Error("Expected power/modulo > 0");if(n===ld)return ud;let r=ld;for(;t>ud;)t&ld&&(r=r*e%n),e=e*e%n,t>>=ld;return r}function wd(e,t,n){let r=e;for(;t-- >ud;)r*=r,r%=n;return r}function bd(e,t){if(e===ud||t<=ud)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=yd(e,t),r=t,o=ud,i=ld,s=ld,a=ud;for(;n!==ud;){const e=r/n,t=r%n,c=o-s*e,u=i-a*e;r=n,n=t,o=s,i=a,s=c,a=u}if(r!==ld)throw new Error("invert: does not exist");return yd(o,t)}BigInt(9),BigInt(16);const vd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ed(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Ad(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function xd(e){const t=Ad(e);return t+Math.ceil(t/2)}const kd=BigInt(0),Sd=BigInt(1);function Id(e){return cd(e.Fp,vd.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),cd(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ed(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}const{Ph:Pd,aT:Cd}=i,Od={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=Od;if(e.length<2||2!==e[0])throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Pd(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Od,n="string"==typeof e?Cd(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:o,l:i}=Od._parseInt(n.subarray(2)),{d:s,l:a}=Od._parseInt(i);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:o,s}},hexFromSig(e){const t=e=>8&Number.parseInt(e[0],16)?"00"+e:e,n=e=>{const t=e.toString(16);return 1&t.length?`0${t}`:t},r=t(n(e.s)),o=t(n(e.r)),i=r.length/2,s=o.length/2,a=n(i),c=n(s);return`30${n(s+i+4)}02${c}${o}02${a}${r}`}},Nd=BigInt(0),Bd=BigInt(1),Td=(BigInt(2),BigInt(3));function Rd(e){const t=function(e){const t=Id(e);return cd(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:n,n:r}=t,o=n.BYTES+1,i=2*n.BYTES+1;function s(e){return yd(e,r)}function a(e){return bd(e,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=function(e){const t=function(e){const t=Id(e);cd(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:o}=t;if(n){if(!r.eql(o,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:n}=t,r=t.toBytes||((e,t,r)=>{const o=t.toAffine();return nd(Uint8Array.from([4]),n.toBytes(o.x),n.toBytes(o.y))}),o=t.fromBytes||(e=>{const t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function i(e){const{a:r,b:o}=t,i=n.sqr(e),s=n.mul(i,e);return n.add(n.add(s,n.mul(e,r)),o)}if(!n.eql(n.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function s(e){return"bigint"==typeof e&&Nd<e&&e<t.n}function a(e){if(!s(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:o,n:i}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=qh(e)),"string"!=typeof e||!n.includes(e.length))throw new Error("Invalid key");e=e.padStart(2*r,"0")}let s;try{s="bigint"==typeof e?e:Zh(td("private key",e,r))}catch(t){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return o&&(s=yd(s,i)),a(s),s}const u=new Map;function l(e){if(!(e instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(e,t,r){if(this.px=e,this.py=t,this.pz=r,null==e||!n.isValid(e))throw new Error("x required");if(null==t||!n.isValid(t))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof f)throw new Error("projective point not allowed");const o=e=>n.eql(e,n.ZERO);return o(t)&&o(r)?f.ZERO:new f(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)}static fromHex(e){const t=f.fromAffine(o(td("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return f.BASE.multiply(c(e))}_setWindowSize(e){this._WINDOW_SIZE=e,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:e,y:r}=this.toAffine();if(!n.isValid(e)||!n.isValid(r))throw new Error("bad point: x or y not FE");const o=n.sqr(r),s=i(e);if(!n.eql(o,s))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){l(e);const{px:t,py:r,pz:o}=this,{px:i,py:s,pz:a}=e,c=n.eql(n.mul(t,a),n.mul(i,o)),u=n.eql(n.mul(r,a),n.mul(s,o));return c&&u}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,o=n.mul(r,Td),{px:i,py:s,pz:a}=this;let c=n.ZERO,u=n.ZERO,l=n.ZERO,h=n.mul(i,i),d=n.mul(s,s),p=n.mul(a,a),g=n.mul(i,s);return g=n.add(g,g),l=n.mul(i,a),l=n.add(l,l),c=n.mul(e,l),u=n.mul(o,p),u=n.add(c,u),c=n.sub(d,u),u=n.add(d,u),u=n.mul(c,u),c=n.mul(g,c),l=n.mul(o,l),p=n.mul(e,p),g=n.sub(h,p),g=n.mul(e,g),g=n.add(g,l),l=n.add(h,h),h=n.add(l,h),h=n.add(h,p),h=n.mul(h,g),u=n.add(u,h),p=n.mul(s,a),p=n.add(p,p),h=n.mul(p,g),c=n.sub(c,h),l=n.mul(p,d),l=n.add(l,l),l=n.add(l,l),new f(c,u,l)}add(e){l(e);const{px:r,py:o,pz:i}=this,{px:s,py:a,pz:c}=e;let u=n.ZERO,h=n.ZERO,d=n.ZERO;const p=t.a,g=n.mul(t.b,Td);let y=n.mul(r,s),m=n.mul(o,a),w=n.mul(i,c),b=n.add(r,o),v=n.add(s,a);b=n.mul(b,v),v=n.add(y,m),b=n.sub(b,v),v=n.add(r,i);let E=n.add(s,c);return v=n.mul(v,E),E=n.add(y,w),v=n.sub(v,E),E=n.add(o,i),u=n.add(a,c),E=n.mul(E,u),u=n.add(m,w),E=n.sub(E,u),d=n.mul(p,v),u=n.mul(g,w),d=n.add(u,d),u=n.sub(m,d),d=n.add(m,d),h=n.mul(u,d),m=n.add(y,y),m=n.add(m,y),w=n.mul(p,w),v=n.mul(g,v),m=n.add(m,w),w=n.sub(y,w),w=n.mul(p,w),v=n.add(v,w),y=n.mul(m,v),h=n.add(h,y),y=n.mul(E,v),u=n.mul(b,u),u=n.sub(u,y),y=n.mul(b,m),d=n.mul(E,d),d=n.add(d,y),new f(u,h,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(f.ZERO)}wNAF(e){return d.wNAFCached(this,u,e,e=>{const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)})}multiplyUnsafe(e){const r=f.ZERO;if(e===Nd)return r;if(a(e),e===Bd)return this;const{endo:o}=t;if(!o)return d.unsafeLadder(this,e);let{k1neg:i,k1:s,k2neg:c,k2:u}=o.splitScalar(e),l=r,h=r,p=this;for(;s>Nd||u>Nd;)s&Bd&&(l=l.add(p)),u&Bd&&(h=h.add(p)),p=p.double(),s>>=Bd,u>>=Bd;return i&&(l=l.negate()),c&&(h=h.negate()),h=new f(n.mul(h.px,o.beta),h.py,h.pz),l.add(h)}multiply(e){a(e);let r,o,i=e;const{endo:s}=t;if(s){const{k1neg:e,k1:t,k2neg:a,k2:c}=s.splitScalar(i);let{p:u,f:l}=this.wNAF(t),{p:h,f:p}=this.wNAF(c);u=d.constTimeNegate(e,u),h=d.constTimeNegate(a,h),h=new f(n.mul(h.px,s.beta),h.py,h.pz),r=u.add(h),o=l.add(p)}else{const{p:e,f:t}=this.wNAF(i);r=e,o=t}return f.normalizeZ([r,o])[0]}multiplyAndAddUnsafe(e,t,n){const r=f.BASE,o=(e,t)=>t!==Nd&&t!==Bd&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),i=o(this,t).add(o(e,n));return i.is0()?void 0:i}toAffine(e){const{px:t,py:r,pz:o}=this,i=this.is0();null==e&&(e=i?n.ONE:n.inv(o));const s=n.mul(t,e),a=n.mul(r,e),c=n.mul(o,e);if(i)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:s,y:a}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===Bd)return!0;if(n)return n(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:n}=t;return e===Bd?this:n?n(f,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(f,this,e)}toHex(e=!0){return qh(this.toRawBytes(e))}}f.BASE=new f(t.Gx,t.Gy,n.ONE),f.ZERO=new f(n.ZERO,n.ONE,n.ZERO);const h=t.nBitLength,d=function(e,t){const n=(e,t)=>{const n=t.negate();return e?n:t},r=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:n,unsafeLadder(t,n){let r=e.ZERO,o=t;for(;n>kd;)n&Sd&&(r=r.add(o)),o=o.double(),n>>=Sd;return r},precomputeWindow(e,t){const{windows:n,windowSize:o}=r(t),i=[];let s=e,a=s;for(let e=0;e<n;e++){a=s,i.push(a);for(let e=1;e<o;e++)a=a.add(s),i.push(a);s=a.double()}return i},wNAF(t,o,i){const{windows:s,windowSize:a}=r(t);let c=e.ZERO,u=e.BASE;const l=BigInt(2**t-1),f=2**t,h=BigInt(t);for(let e=0;e<s;e++){const t=e*a;let r=Number(i&l);i>>=h,r>a&&(r-=f,i+=Sd);const s=t,d=t+Math.abs(r)-1,p=e%2!=0,g=r<0;0===r?u=u.add(n(p,o[s])):c=c.add(n(g,o[d]))}return{p:c,f:u}},wNAFCached(e,t,n,r){const o=e._WINDOW_SIZE||1;let i=t.get(e);return i||(i=this.precomputeWindow(e,o),1!==o&&t.set(e,r(i))),this.wNAF(o,i,n)}}}(f,t.endo?Math.ceil(h/2):h);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}({...t,toBytes(e,t,r){const o=t.toAffine(),i=n.toBytes(o.x),s=nd;return r?s(Uint8Array.from([t.hasEvenY()?2:3]),i):s(Uint8Array.from([4]),i,n.toBytes(o.y))},fromBytes(e){const t=e.length,r=e[0],s=e.subarray(1);if(t!==o||2!==r&&3!==r){if(t===i&&4===r)return{x:n.fromBytes(s.subarray(0,n.BYTES)),y:n.fromBytes(s.subarray(n.BYTES,2*n.BYTES))};throw new Error(`Point of length ${t} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}{const e=Zh(s);if(!(Nd<(a=e)&&a<n.ORDER))throw new Error("Point is not on curve");const t=l(e);let o=n.sqrt(t);return!(1&~r)!=((o&Bd)===Bd)&&(o=n.neg(o)),{x:e,y:o}}var a}}),h=e=>qh(Xh(e,t.nByteLength));function d(e){return e>r>>Bd}const p=(e,t,n)=>Zh(e.slice(t,n));class g{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=td("compactSignature",e,2*n),new g(p(e,0,n),p(e,n,2*n))}static fromDER(e){const{r:t,s:n}=Od.toSig(td("DER",e));return new g(t,n)}assertValidity(){if(!f(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!f(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(e){return new g(this.r,this.s,e)}recoverPublicKey(e){const{r,s:o,recovery:i}=this,u=b(td("msgHash",e));if(null==i||![0,1,2,3].includes(i))throw new Error("recovery id invalid");const l=2===i||3===i?r+t.n:r;if(l>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const f=1&i?"03":"02",d=c.fromHex(f+h(l)),p=a(l),g=s(-u*p),y=s(o*p),m=c.BASE.multiplyAndAddUnsafe(d,g,y);if(!m)throw new Error("point at infinify");return m.assertValidity(),m}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Qh(this.toDERHex())}toDERHex(){return Od.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Qh(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const y={isValidPrivateKey(e){try{return u(e),!0}catch(e){return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const e=xd(t.n);return function(e,t,n=!1){const r=e.length,o=Ad(t),i=xd(t);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const s=yd(n?Zh(e):Yh(e),t-ld)+ld;return n?ed(s,o):Xh(s,o)}(t.randomBytes(e),t.n)},precompute:(e=8,t=c.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function m(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===o||r===i:n?r===2*o||r===2*i:e instanceof c}const w=t.bits2int||function(e){const n=Zh(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},b=t.bits2int_modN||function(e){return s(w(e))},v=rd(t.nBitLength);function E(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(Nd<=e&&e<v))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Xh(e,t.nByteLength)}const A={lowS:t.lowS,prehash:!1},x={lowS:t.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return c.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(m(e))throw new Error("first arg must be private key");if(!m(t))throw new Error("second arg must be public key");return c.fromHex(t).multiply(u(e)).toRawBytes(n)},sign:function(e,r,o=A){const{seed:i,k2sig:l}=function(e,r,o=A){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");const{hash:i,randomBytes:l}=t;let{lowS:h,prehash:p,extraEntropy:y}=o;null==h&&(h=!0),e=td("msgHash",e),p&&(e=td("prehashed msgHash",i(e)));const m=b(e),v=u(r),x=[E(v),E(m)];if(null!=y){const e=!0===y?l(n.BYTES):y;x.push(td("extraEntropy",e))}const k=nd(...x),S=m;return{seed:k,k2sig:function(e){const t=w(e);if(!f(t))return;const n=a(t),r=c.BASE.multiply(t).toAffine(),o=s(r.x);if(o===Nd)return;const i=s(n*s(S+o*v));if(i===Nd)return;let u=(r.x===o?0:2)|Number(r.y&Bd),l=i;return h&&d(i)&&(l=function(e){return d(e)?s(-e):e}(i),u^=1),new g(o,l,u)}}}(e,r,o),h=t;return sd(h.hash.outputLen,h.nByteLength,h.hmac)(i,l)},verify:function(e,n,r,o=x){const i=e;if(n=td("msgHash",n),r=td("publicKey",r),"strict"in o)throw new Error("options.strict was renamed to lowS");const{lowS:u,prehash:l}=o;let f,h;try{if("string"==typeof i||i instanceof Uint8Array)try{f=g.fromDER(i)}catch(e){if(!(e instanceof Od.Err))throw e;f=g.fromCompact(i)}else{if("object"!=typeof i||"bigint"!=typeof i.r||"bigint"!=typeof i.s)throw new Error("PARSE");{const{r:e,s:t}=i;f=new g(e,t)}}h=c.fromHex(r)}catch(e){if("PARSE"===e.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(u&&f.hasHighS())return!1;l&&(n=t.hash(n));const{r:d,s:p}=f,y=b(n),m=a(p),w=s(y*m),v=s(d*m),E=c.BASE.multiplyAndAddUnsafe(h,w,v)?.toAffine();return!!E&&s(E.x)===d},ProjectivePoint:c,Signature:g,utils:y}}function Ud(e){return{hash:e,hmac:(t,...n)=>St(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!ht(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:xt}}BigInt(4);const Dd=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ld=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Fd=BigInt(1),_d=BigInt(2),Md=(e,t)=>(e+t/_d)/t;const jd=function(e,t,n=!1,r={}){if(e<=ud)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:o,nByteLength:i}=Ed(e,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=function(e){if(e%dd===hd){const t=(e+ld)/dd;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%gd===pd){const t=(e-pd)/gd;return function(e,n){const r=e.mul(n,fd),o=e.pow(r,t),i=e.mul(n,o),s=e.mul(e.mul(i,fd),o),a=e.mul(i,e.sub(s,e.ONE));if(!e.eql(e.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-ld)/fd;let n,r,o;for(n=e-ld,r=0;n%fd===ud;n/=fd,r++);for(o=fd;o<e&&md(o,t,e)!==e-ld;o++);if(1===r){const t=(e+ld)/dd;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const i=(n+ld)/fd;return function(e,s){if(e.pow(s,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,c=e.pow(e.mul(e.ONE,o),n),u=e.pow(s,i),l=e.pow(s,n);for(;!e.eql(l,e.ONE);){if(e.eql(l,e.ZERO))return e.ZERO;let t=1;for(let n=e.sqr(l);t<a&&!e.eql(n,e.ONE);t++)n=e.sqr(n);const n=e.pow(c,ld<<BigInt(a-t-1));c=e.sqr(n),u=e.mul(u,n),l=e.mul(l,c),a=t}return u}}(e)}(e),a=Object.freeze({ORDER:e,BITS:o,BYTES:i,MASK:rd(o),ZERO:ud,ONE:ld,create:t=>yd(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return ud<=t&&t<e},is0:e=>e===ud,isOdd:e=>(e&ld)===ld,neg:t=>yd(-t,e),eql:(e,t)=>e===t,sqr:t=>yd(t*t,e),add:(t,n)=>yd(t+n,e),sub:(t,n)=>yd(t-n,e),mul:(t,n)=>yd(t*n,e),pow:(e,t)=>function(e,t,n){if(n<ud)throw new Error("Expected power > 0");if(n===ud)return e.ONE;if(n===ld)return t;let r=e.ONE,o=t;for(;n>ud;)n&ld&&(r=e.mul(r,o)),o=e.sqr(o),n>>=ld;return r}(a,e,t),div:(t,n)=>yd(t*bd(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>bd(t,e),sqrt:r.sqrt||(e=>s(a,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce((t,r,o)=>e.is0(r)?t:(n[o]=t,e.mul(t,r)),e.ONE),o=e.inv(r);return t.reduceRight((t,r,o)=>e.is0(r)?t:(n[o]=e.mul(t,n[o]),e.mul(t,r)),o),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?ed(e,i):Xh(e,i),fromBytes:e=>{if(e.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${e.length}`);return n?Yh(e):Zh(e)}});return Object.freeze(a)}(Dd,void 0,void 0,{sqrt:function(e){const t=Dd,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=wd(l,n,t)*l%t,h=wd(f,n,t)*l%t,d=wd(h,_d,t)*u%t,p=wd(d,o,t)*d%t,g=wd(p,i,t)*p%t,y=wd(g,a,t)*g%t,m=wd(y,c,t)*y%t,w=wd(m,a,t)*g%t,b=wd(w,n,t)*l%t,v=wd(b,s,t)*p%t,E=wd(v,r,t)*u%t,A=wd(E,_d,t);if(!jd.eql(jd.sqr(A),e))throw new Error("Cannot find square root");return A}}),Gd=function(e,t){const n=t=>Rd({...e,...Ud(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:jd,n:Ld,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=Ld,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Fd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),a=Md(i*e,t),c=Md(-r*e,t);let u=yd(e-a*n-c*o,t),l=yd(-a*r-c*i,t);const f=u>s,h=l>s;if(f&&(u=t-u),h&&(l=t-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},Ut);BigInt(0),Gd.ProjectivePoint;class Hd{#re;constructor(e){Me(32===Ye(e),"invalid private key","privateKey","[REDACTED]"),this.#re=Qe(e)}get privateKey(){return this.#re}get publicKey(){return Hd.computePublicKey(this.#re)}get compressedPublicKey(){return Hd.computePublicKey(this.#re,!0)}sign(e){Me(32===Ye(e),"invalid digest length","digest",e);const t=Gd.sign(We(e),We(this.#re),{lowS:!0});return Pl.from({r:sc(t.r,32),s:sc(t.s,32),v:t.recovery?28:27})}computeSharedSecret(e){const t=Hd.computePublicKey(e);return Qe(Gd.getSharedSecret(We(this.#re),Ve(t),!1))}static computePublicKey(e,t){let n=Ve(e,"key");if(32===n.length)return Qe(Gd.getPublicKey(n,!!t));if(64===n.length){const e=new Uint8Array(65);e[0]=4,e.set(n,1),n=e}return Qe(Gd.ProjectivePoint.fromHex(n).toRawBytes(t))}static recoverPublicKey(e,t){Me(32===Ye(e),"invalid digest length","digest",e);const n=Pl.from(t);let r=Gd.Signature.fromCompact(We(Ze([n.r,n.s])));r=r.addRecoveryBit(n.yParity);const o=r.recoverPublicKey(We(e));return Me(null!=o,"invalid signature for digest","signature",t),"0x"+o.toHex(!1)}static addPoints(e,t,n){const r=Gd.ProjectivePoint.fromHex(Hd.computePublicKey(e).substring(2)),o=Gd.ProjectivePoint.fromHex(Hd.computePublicKey(t).substring(2));return"0x"+r.add(o).toHex(!!n)}}function zd(e){let t=e.toString(16);for(;t.length<2;)t="0"+t;return"0x"+t}function Kd(e,t,n){let r=0;for(let o=0;o<n;o++)r=256*r+e[t+o];return r}function Vd(e,t,n,r){const o=[];for(;n<t+1+r;){const i=Wd(e,n);o.push(i.result),_e((n+=i.consumed)<=t+1+r,"child data too short","BUFFER_OVERRUN",{buffer:e,length:r,offset:t})}return{consumed:1+r,result:o}}function Wd(e,t){_e(0!==e.length,"data too short","BUFFER_OVERRUN",{buffer:e,length:0,offset:1});const n=t=>{_e(t<=e.length,"data short segment too short","BUFFER_OVERRUN",{buffer:e,length:e.length,offset:t})};if(e[t]>=248){const r=e[t]-247;n(t+1+r);const o=Kd(e,t+1,r);return n(t+1+r+o),Vd(e,t,t+1+r,r+o)}if(e[t]>=192){const r=e[t]-192;return n(t+1+r),Vd(e,t,t+1,r)}if(e[t]>=184){const r=e[t]-183;n(t+1+r);const o=Kd(e,t+1,r);return n(t+1+r+o),{consumed:1+r+o,result:Qe(e.slice(t+1+r,t+1+r+o))}}if(e[t]>=128){const r=e[t]-128;return n(t+1+r),{consumed:1+r,result:Qe(e.slice(t+1,t+1+r))}}return{consumed:1,result:zd(e[t])}}function $d(e){const t=Ve(e,"data"),n=Wd(t,0);return Me(n.consumed===t.length,"unexpected junk after rlp payload","data",e),n.result}function qd(e){const t=[];for(;e;)t.unshift(255&e),e>>=8;return t}function Jd(e){if(Array.isArray(e)){let t=[];if(e.forEach(function(e){t=t.concat(Jd(e))}),t.length<=55)return t.unshift(192+t.length),t;const n=qd(t.length);return n.unshift(247+n.length),n.concat(t)}const t=Array.prototype.slice.call(Ve(e,"object"));if(1===t.length&&t[0]<=127)return t;if(t.length<=55)return t.unshift(128+t.length),t;const n=qd(t.length);return n.unshift(183+n.length),n.concat(t)}const Qd="0123456789abcdef";function Zd(e){let t="0x";for(const n of Jd(e))t+=Qd[n>>4],t+=Qd[15&n];return t}function Yd(e){let t;return t="string"==typeof e?Hd.computePublicKey(e,!1):e.publicKey,Cc(In("0x"+t.substring(4)).substring(26))}function Xd(e,t){return Yd(Hd.recoverPublicKey(e,t))}const ep=BigInt(0),tp=BigInt(2),np=BigInt(27),rp=BigInt(28),op=BigInt(35),ip=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),sp=Symbol.for("nodejs.util.inspect.custom"),ap=131072,cp=128;function up(e,t){let n=e.toString(16);for(;n.length<2;)n="0"+n;return n+=sn(t).substring(4),"0x"+n}function lp(e){return"0x"===e?null:Cc(e)}function fp(e,t){try{return pl(e)}catch(n){Me(!1,n.message,t,e)}}function hp(e,t){try{if(!Array.isArray(e))throw new Error("authorizationList: invalid array");const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(!Array.isArray(r))throw new Error(`authorization[${n}]: invalid array`);if(6!==r.length)throw new Error(`authorization[${n}]: wrong length`);if(!r[1])throw new Error(`authorization[${n}]: null address`);t.push({address:lp(r[1]),nonce:pp(r[2],"nonce"),chainId:pp(r[0],"chainId"),signature:Pl.from({yParity:dp(r[3],"yParity"),r:tt(r[4],32),s:tt(r[5],32)})})}return t}catch(n){Me(!1,n.message,t,e)}}function dp(e,t){return"0x"===e?0:ic(e,t)}function pp(e,t){if("0x"===e)return ep;const n=tc(e,t);return Me(n<=ip,"value exceeds uint size",t,n),n}function gp(e,t){const n=tc(e,"value"),r=ac(n);return Me(r.length<=32,"value too large",`tx.${t}`,n),r}function yp(e){return pl(e).map(e=>[e.address,e.storageKeys])}function mp(e,t){Me(Array.isArray(e),`invalid ${t}`,"value",e);for(let t=0;t<e.length;t++)Me($e(e[t],32),"invalid ${ param } hash",`value[${t}]`,e[t]);return e}function wp(e,t){let n;try{if(n=dp(t[0],"yParity"),0!==n&&1!==n)throw new Error("bad yParity")}catch(e){Me(!1,"invalid yParity","yParity",t[0])}const r=tt(t[1],32),o=tt(t[2],32),i=Pl.from({r,s:o,yParity:n});e.signature=i}class bp{#oe;#ie;#t;#se;#ae;#ce;#ue;#le;#fe;#he;#de;#pe;#ge;#ye;#me;#we;#be;#ve;get type(){return this.#oe}set type(e){switch(e){case null:this.#oe=null;break;case 0:case"legacy":this.#oe=0;break;case 1:case"berlin":case"eip-2930":this.#oe=1;break;case 2:case"london":case"eip-1559":this.#oe=2;break;case 3:case"cancun":case"eip-4844":this.#oe=3;break;case 4:case"pectra":case"eip-7702":this.#oe=4;break;default:Me(!1,"unsupported transaction type","type",e)}}get typeName(){switch(this.type){case 0:return"legacy";case 1:return"eip-2930";case 2:return"eip-1559";case 3:return"eip-4844";case 4:return"eip-7702"}return null}get to(){const e=this.#ie;return null==e&&3===this.type?zl:e}set to(e){this.#ie=null==e?null:Cc(e)}get nonce(){return this.#se}set nonce(e){this.#se=ic(e,"value")}get gasLimit(){return this.#ae}set gasLimit(e){this.#ae=tc(e)}get gasPrice(){const e=this.#ce;return null!=e||0!==this.type&&1!==this.type?e:ep}set gasPrice(e){this.#ce=null==e?null:tc(e,"gasPrice")}get maxPriorityFeePerGas(){const e=this.#ue;return null==e?2===this.type||3===this.type?ep:null:e}set maxPriorityFeePerGas(e){this.#ue=null==e?null:tc(e,"maxPriorityFeePerGas")}get maxFeePerGas(){const e=this.#le;return null==e?2===this.type||3===this.type?ep:null:e}set maxFeePerGas(e){this.#le=null==e?null:tc(e,"maxFeePerGas")}get data(){return this.#t}set data(e){this.#t=Qe(e)}get value(){return this.#fe}set value(e){this.#fe=tc(e,"value")}get chainId(){return this.#he}set chainId(e){this.#he=tc(e)}get signature(){return this.#de||null}set signature(e){this.#de=null==e?null:Pl.from(e)}isValid(){const e=this.signature;if(e&&!e.isValid())return!1;const t=this.authorizationList;if(t)for(const e of t)if(!e.signature.isValid())return!1;return!0}get accessList(){const e=this.#pe||null;return null==e?1===this.type||2===this.type||3===this.type?[]:null:e}set accessList(e){this.#pe=null==e?null:pl(e)}get authorizationList(){const e=this.#be||null;return null==e&&4===this.type?[]:e}set authorizationList(e){this.#be=null==e?null:e.map(e=>Cl(e))}get maxFeePerBlobGas(){const e=this.#ge;return null==e&&3===this.type?ep:e}set maxFeePerBlobGas(e){this.#ge=null==e?null:tc(e,"maxFeePerBlobGas")}get blobVersionedHashes(){let e=this.#ye;return null==e&&3===this.type?[]:e}set blobVersionedHashes(e){if(null!=e){Me(Array.isArray(e),"blobVersionedHashes must be an Array","value",e),e=e.slice();for(let t=0;t<e.length;t++)Me($e(e[t],32),"invalid blobVersionedHash",`value[${t}]`,e[t])}this.#ye=e}get blobs(){return null==this.#we?null:this.#we.map(e=>Object.assign({},e))}set blobs(e){if(null==e)return void(this.#we=null);const t=[],n=[];for(let r=0;r<e.length;r++){const o=e[r];if(qe(o)){_e(this.#me,"adding a raw blob requires a KZG library","UNSUPPORTED_OPERATION",{operation:"set blobs()"});let e=Ve(o);if(Me(e.length<=ap,"blob is too large",`blobs[${r}]`,o),e.length!==ap){const t=new Uint8Array(ap);t.set(e),e=t}const i=this.#me.blobToKzgCommitment(e),s=Qe(this.#me.computeBlobKzgProof(e,i));t.push({data:Qe(e),commitment:Qe(i),proof:s}),n.push(up(1,i))}else{const e=Qe(o.data),r=Qe(o.commitment),i=Qe(o.proof);t.push({data:e,commitment:r,proof:i}),n.push(up(1,r))}}this.#we=t,this.#ye=n}get kzg(){return this.#me}set kzg(e){this.#me=null==e?null:function(e){return{blobToKzgCommitment:t=>{if("computeBlobProof"in e){if("blobToKzgCommitment"in e&&"function"==typeof e.blobToKzgCommitment)return Ve(e.blobToKzgCommitment(Qe(t)))}else if("blobToKzgCommitment"in e&&"function"==typeof e.blobToKzgCommitment)return Ve(e.blobToKzgCommitment(t));if("blobToKZGCommitment"in e&&"function"==typeof e.blobToKZGCommitment)return Ve(e.blobToKZGCommitment(Qe(t)));Me(!1,"unsupported KZG library","kzg",e)},computeBlobKzgProof:(t,n)=>"computeBlobProof"in e&&"function"==typeof e.computeBlobProof?Ve(e.computeBlobProof(Qe(t),Qe(n))):"computeBlobKzgProof"in e&&"function"==typeof e.computeBlobKzgProof?e.computeBlobKzgProof(t,n):"computeBlobKZGProof"in e&&"function"==typeof e.computeBlobKZGProof?Ve(e.computeBlobKZGProof(Qe(t),Qe(n))):void Me(!1,"unsupported KZG library","kzg",e)}}(e)}get blobWrapperVersion(){return this.#ve}set blobWrapperVersion(e){this.#ve=e}constructor(){this.#oe=null,this.#ie=null,this.#se=0,this.#ae=ep,this.#ce=null,this.#ue=null,this.#le=null,this.#t="0x",this.#fe=ep,this.#he=ep,this.#de=null,this.#pe=null,this.#ge=null,this.#ye=null,this.#me=null,this.#we=null,this.#be=null,this.#ve=null}get hash(){return null==this.signature?null:In(this.#Ee(!0,!1))}get unsignedHash(){return In(this.unsignedSerialized)}get from(){return null==this.signature?null:Xd(this.unsignedHash,this.signature.getCanonical())}get fromPublicKey(){return null==this.signature?null:Hd.recoverPublicKey(this.unsignedHash,this.signature.getCanonical())}isSigned(){return null!=this.signature}#Ee(e,t){_e(!e||null!=this.signature,"cannot serialize unsigned transaction; maybe you meant .unsignedSerialized","UNSUPPORTED_OPERATION",{operation:".serialized"});const n=e?this.signature:null;switch(this.inferType()){case 0:return function(e,t){const n=[gp(e.nonce,"nonce"),gp(e.gasPrice||0,"gasPrice"),gp(e.gasLimit,"gasLimit"),e.to||"0x",gp(e.value,"value"),e.data];let r=ep;if(e.chainId!=ep)r=tc(e.chainId,"tx.chainId"),Me(!t||null==t.networkV||t.legacyChainId===r,"tx.chainId/sig.v mismatch","sig",t);else if(e.signature){const t=e.signature.legacyChainId;null!=t&&(r=t)}if(!t)return r!==ep&&(n.push(ac(r)),n.push("0x"),n.push("0x")),Zd(n);let o=BigInt(27+t.yParity);return r!==ep?o=Pl.getChainIdV(r,t.v):BigInt(t.v)!==o&&Me(!1,"tx.chainId/sig.v mismatch","sig",t),n.push(ac(o)),n.push(ac(t.r)),n.push(ac(t._s)),Zd(n)}(this,n);case 1:return function(e,t){const n=[gp(e.chainId,"chainId"),gp(e.nonce,"nonce"),gp(e.gasPrice||0,"gasPrice"),gp(e.gasLimit,"gasLimit"),e.to||"0x",gp(e.value,"value"),e.data,yp(e.accessList||[])];return t&&(n.push(gp(t.yParity,"recoveryParam")),n.push(ac(t.r)),n.push(ac(t.s))),Ze(["0x01",Zd(n)])}(this,n);case 2:return function(e,t){const n=[gp(e.chainId,"chainId"),gp(e.nonce,"nonce"),gp(e.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),gp(e.maxFeePerGas||0,"maxFeePerGas"),gp(e.gasLimit,"gasLimit"),e.to||"0x",gp(e.value,"value"),e.data,yp(e.accessList||[])];return t&&(n.push(gp(t.yParity,"yParity")),n.push(ac(t.r)),n.push(ac(t.s))),Ze(["0x02",Zd(n)])}(this,n);case 3:return function(e,t,n){const r=[gp(e.chainId,"chainId"),gp(e.nonce,"nonce"),gp(e.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),gp(e.maxFeePerGas||0,"maxFeePerGas"),gp(e.gasLimit,"gasLimit"),e.to||zl,gp(e.value,"value"),e.data,yp(e.accessList||[]),gp(e.maxFeePerBlobGas||0,"maxFeePerBlobGas"),mp(e.blobVersionedHashes||[],"blobVersionedHashes")];if(t&&(r.push(gp(t.yParity,"yParity")),r.push(ac(t.r)),r.push(ac(t.s)),n)){if(null!=e.blobWrapperVersion){const t=ac(e.blobWrapperVersion),o=[];for(const{proof:e}of n){const t=Ve(e),n=t.length/cp;for(let e=0;e<t.length;e+=n)o.push(t.subarray(e,e+n))}return Ze(["0x03",Zd([r,t,n.map(e=>e.data),n.map(e=>e.commitment),o])])}return Ze(["0x03",Zd([r,n.map(e=>e.data),n.map(e=>e.commitment),n.map(e=>e.proof)])])}return Ze(["0x03",Zd(r)])}(this,n,t?this.blobs:null);case 4:return function(e,t){const n=[gp(e.chainId,"chainId"),gp(e.nonce,"nonce"),gp(e.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),gp(e.maxFeePerGas||0,"maxFeePerGas"),gp(e.gasLimit,"gasLimit"),e.to||"0x",gp(e.value,"value"),e.data,yp(e.accessList||[]),(r=e.authorizationList||[],r.map(e=>[gp(e.chainId,"chainId"),e.address,gp(e.nonce,"nonce"),gp(e.signature.yParity,"yParity"),ac(e.signature.r),ac(e.signature._s)]))];var r;return t&&(n.push(gp(t.yParity,"yParity")),n.push(ac(t.r)),n.push(ac(t.s))),Ze(["0x04",Zd(n)])}(this,n)}_e(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:".serialized"})}get serialized(){return this.#Ee(!0,!0)}get unsignedSerialized(){return this.#Ee(!1,!1)}inferType(){const e=this.inferTypes();return e.indexOf(2)>=0?2:e.pop()}inferTypes(){const e=null!=this.gasPrice,t=null!=this.maxFeePerGas||null!=this.maxPriorityFeePerGas,n=null!=this.accessList,r=null!=this.#ge||this.#ye;null!=this.maxFeePerGas&&null!=this.maxPriorityFeePerGas&&_e(this.maxFeePerGas>=this.maxPriorityFeePerGas,"priorityFee cannot be more than maxFee","BAD_DATA",{value:this}),_e(!t||0!==this.type&&1!==this.type,"transaction type cannot have maxFeePerGas or maxPriorityFeePerGas","BAD_DATA",{value:this}),_e(0!==this.type||!n,"legacy transaction cannot have accessList","BAD_DATA",{value:this});const o=[];return null!=this.type?o.push(this.type):this.authorizationList&&this.authorizationList.length?o.push(4):t?o.push(2):e?(o.push(1),n||o.push(0)):n?(o.push(1),o.push(2)):(r&&this.to||(o.push(0),o.push(1),o.push(2)),o.push(3)),o.sort(),o}isLegacy(){return 0===this.type}isBerlin(){return 1===this.type}isLondon(){return 2===this.type}isCancun(){return 3===this.type}clone(){return bp.from(this)}toJSON(){const e=e=>null==e?null:e.toString();return{type:this.type,to:this.to,data:this.data,nonce:this.nonce,gasLimit:e(this.gasLimit),gasPrice:e(this.gasPrice),maxPriorityFeePerGas:e(this.maxPriorityFeePerGas),maxFeePerGas:e(this.maxFeePerGas),value:e(this.value),chainId:e(this.chainId),sig:this.signature?this.signature.toJSON():null,accessList:this.accessList}}[sp](){return this.toString()}toString(){const e=[],t=t=>{let n=this[t];"string"==typeof n&&(n=JSON.stringify(n)),e.push(`${t}: ${n}`)};this.type&&t("type"),t("to"),t("data"),t("nonce"),t("gasLimit"),t("value"),null!=this.chainId&&t("chainId"),this.signature&&(t("from"),e.push(`signature: ${this.signature.toString()}`));const n=this.authorizationList;if(n){const t=[];for(const e of n){const n=[];n.push(`address: ${JSON.stringify(e.address)}`),null!=e.nonce&&n.push(`nonce: ${e.nonce}`),null!=e.chainId&&n.push(`chainId: ${e.chainId}`),e.signature&&n.push(`signature: ${e.signature.toString()}`),t.push(`Authorization { ${n.join(", ")} }`)}e.push(`authorizations: [ ${t.join(", ")} ]`)}return`Transaction { ${e.join(", ")} }`}static from(e){if(null==e)return new bp;if("string"==typeof e){const t=Ve(e);if(t[0]>=127)return bp.from(function(e){const t=$d(e);Me(Array.isArray(t)&&(9===t.length||6===t.length),"invalid field count for legacy transaction","data",e);const n={type:0,nonce:dp(t[0],"nonce"),gasPrice:pp(t[1],"gasPrice"),gasLimit:pp(t[2],"gasLimit"),to:lp(t[3]),value:pp(t[4],"value"),data:Qe(t[5]),chainId:ep};if(6===t.length)return n;const r=pp(t[6],"v"),o=pp(t[7],"r"),i=pp(t[8],"s");if(o===ep&&i===ep)n.chainId=r;else{let e=(r-op)/tp;e<ep&&(e=ep),n.chainId=e,Me(e!==ep||r===np||r===rp,"non-canonical legacy v","v",t[6]),n.signature=Pl.from({r:tt(t[7],32),s:tt(t[8],32),v:r})}return n}(t));switch(t[0]){case 1:return bp.from(function(e){const t=$d(Ve(e).slice(1));Me(Array.isArray(t)&&(8===t.length||11===t.length),"invalid field count for transaction type: 1","data",Qe(e));const n={type:1,chainId:pp(t[0],"chainId"),nonce:dp(t[1],"nonce"),gasPrice:pp(t[2],"gasPrice"),gasLimit:pp(t[3],"gasLimit"),to:lp(t[4]),value:pp(t[5],"value"),data:Qe(t[6]),accessList:fp(t[7],"accessList")};return 8===t.length||wp(n,t.slice(8)),n}(t));case 2:return bp.from(function(e){const t=$d(Ve(e).slice(1));Me(Array.isArray(t)&&(9===t.length||12===t.length),"invalid field count for transaction type: 2","data",Qe(e));const n={type:2,chainId:pp(t[0],"chainId"),nonce:dp(t[1],"nonce"),maxPriorityFeePerGas:pp(t[2],"maxPriorityFeePerGas"),maxFeePerGas:pp(t[3],"maxFeePerGas"),gasPrice:null,gasLimit:pp(t[4],"gasLimit"),to:lp(t[5]),value:pp(t[6],"value"),data:Qe(t[7]),accessList:fp(t[8],"accessList")};return 9===t.length||wp(n,t.slice(9)),n}(t));case 3:return bp.from(function(e){let t=$d(Ve(e).slice(1)),n="3",r=null,o=null;if(4===t.length&&Array.isArray(t[0])){n="3 (network format)";const e=t[1],r=t[2],i=t[3];Me(Array.isArray(e),"invalid network format: blobs not an array","fields[1]",e),Me(Array.isArray(r),"invalid network format: commitments not an array","fields[2]",r),Me(Array.isArray(i),"invalid network format: proofs not an array","fields[3]",i),Me(e.length===r.length,"invalid network format: blobs/commitments length mismatch","fields",t),Me(e.length===i.length,"invalid network format: blobs/proofs length mismatch","fields",t),o=[];for(let n=0;n<t[1].length;n++)o.push({data:e[n],commitment:r[n],proof:i[n]});t=t[0]}else if(5===t.length&&Array.isArray(t[0])){n="3 (EIP-7594 network format)",r=ic(t[1]);const e=t[2],i=t[3],s=t[4];Me(1===r,`unsupported EIP-7594 network format version: ${r}`,"fields[1]",r),Me(Array.isArray(e),"invalid EIP-7594 network format: blobs not an array","fields[2]",e),Me(Array.isArray(i),"invalid EIP-7594 network format: commitments not an array","fields[3]",i),Me(Array.isArray(s),"invalid EIP-7594 network format: proofs not an array","fields[4]",s),Me(e.length===i.length,"invalid network format: blobs/commitments length mismatch","fields",t),Me(e.length*cp===s.length,"invalid network format: blobs/proofs length mismatch","fields",t),o=[];for(let t=0;t<e.length;t++){const n=[];for(let e=0;e<cp;e++)n.push(s[t*cp+e]);o.push({data:e[t],commitment:i[t],proof:Ze(n)})}t=t[0]}Me(Array.isArray(t)&&(11===t.length||14===t.length),`invalid field count for transaction type: ${n}`,"data",Qe(e));const i={type:3,chainId:pp(t[0],"chainId"),nonce:dp(t[1],"nonce"),maxPriorityFeePerGas:pp(t[2],"maxPriorityFeePerGas"),maxFeePerGas:pp(t[3],"maxFeePerGas"),gasPrice:null,gasLimit:pp(t[4],"gasLimit"),to:lp(t[5]),value:pp(t[6],"value"),data:Qe(t[7]),accessList:fp(t[8],"accessList"),maxFeePerBlobGas:pp(t[9],"maxFeePerBlobGas"),blobVersionedHashes:t[10],blobWrapperVersion:r};o&&(i.blobs=o),Me(null!=i.to,`invalid address for transaction type: ${n}`,"data",e),Me(Array.isArray(i.blobVersionedHashes),"invalid blobVersionedHashes: must be an array","data",e);for(let t=0;t<i.blobVersionedHashes.length;t++)Me($e(i.blobVersionedHashes[t],32),`invalid blobVersionedHash at index ${t}: must be length 32`,"data",e);return 11===t.length||wp(i,t.slice(11)),i}(t));case 4:return bp.from(function(e){const t=$d(Ve(e).slice(1));Me(Array.isArray(t)&&(10===t.length||13===t.length),"invalid field count for transaction type: 4","data",Qe(e));const n={type:4,chainId:pp(t[0],"chainId"),nonce:dp(t[1],"nonce"),maxPriorityFeePerGas:pp(t[2],"maxPriorityFeePerGas"),maxFeePerGas:pp(t[3],"maxFeePerGas"),gasPrice:null,gasLimit:pp(t[4],"gasLimit"),to:lp(t[5]),value:pp(t[6],"value"),data:Qe(t[7]),accessList:fp(t[8],"accessList"),authorizationList:hp(t[9],"authorizationList")};return 10===t.length||wp(n,t.slice(10)),n}(t))}_e(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:"from"})}const t=new bp;return null!=e.type&&(t.type=e.type),null!=e.to&&(t.to=e.to),null!=e.nonce&&(t.nonce=e.nonce),null!=e.gasLimit&&(t.gasLimit=e.gasLimit),null!=e.gasPrice&&(t.gasPrice=e.gasPrice),null!=e.maxPriorityFeePerGas&&(t.maxPriorityFeePerGas=e.maxPriorityFeePerGas),null!=e.maxFeePerGas&&(t.maxFeePerGas=e.maxFeePerGas),null!=e.maxFeePerBlobGas&&(t.maxFeePerBlobGas=e.maxFeePerBlobGas),null!=e.data&&(t.data=e.data),null!=e.value&&(t.value=e.value),null!=e.chainId&&(t.chainId=e.chainId),null!=e.signature&&(t.signature=Pl.from(e.signature)),null!=e.accessList&&(t.accessList=e.accessList),null!=e.authorizationList&&(t.authorizationList=e.authorizationList),null!=e.blobVersionedHashes&&(t.blobVersionedHashes=e.blobVersionedHashes),null!=e.kzg&&(t.kzg=e.kzg),null!=e.blobWrapperVersion&&(t.blobWrapperVersion=e.blobWrapperVersion),null!=e.blobs&&(t.blobs=e.blobs),null!=e.hash&&(Me(t.isSigned(),"unsigned transaction cannot define '.hash'","tx",e),Me(t.hash===e.hash,"hash mismatch","tx",e)),null!=e.from&&(Me(t.isSigned(),"unsigned transaction cannot define '.from'","tx",e),Me(t.from.toLowerCase()===(e.from||"").toLowerCase(),"from mismatch","tx",e)),t}}const vp="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";let Ep=null;function Ap(e){if(null==Ep){Ep={};for(let e=0;e<58;e++)Ep[vp[e]]=BigInt(e)}const t=Ep[e];return Me(null!=t,"invalid base58 value","letter",e),t}const xp=BigInt(0),kp=BigInt(58);function Sp(e){const t=Ve(e);let n=oc(t),r="";for(;n;)r=vp[Number(n%kp)]+r,n/=kp;for(let e=0;e<t.length&&!t[e];e++)r=vp[0]+r;return r}function Ip(e){return e.match(/^ipfs:\/\/ipfs\//i)?e=e.substring(12):e.match(/^ipfs:\/\//i)?e=e.substring(7):Me(!1,"unsupported IPFS format","link",e),`https://gateway.ipfs.io/ipfs/${e}`}class Pp{name;constructor(e){Re(this,{name:e})}connect(e){return this}supportsCoinType(e){return!1}async encodeAddress(e,t){throw new Error("unsupported coin")}async decodeAddress(e,t){throw new Error("unsupported coin")}}const Cp=new RegExp("^(ipfs)://(.*)$","i"),Op=[new RegExp("^(https)://(.*)$","i"),new RegExp("^(data):(.*)$","i"),Cp,new RegExp("^eip155:[0-9]+/(erc[0-9]+):(.*)$","i")];class Np{provider;address;name;#Ae;#xe;constructor(e,t,n){Re(this,{provider:e,address:t,name:n}),this.#Ae=null,this.#xe=new Ff(t,["function supportsInterface(bytes4) view returns (bool)","function resolve(bytes, bytes) view returns (bytes)","function addr(bytes32) view returns (address)","function addr(bytes32, uint) view returns (bytes)","function text(bytes32, string) view returns (string)","function contenthash(bytes32) view returns (bytes)"],e)}async supportsWildcard(){return null==this.#Ae&&(this.#Ae=(async()=>{try{return await this.#xe.supportsInterface("0x9061b923")}catch(e){if(De(e,"CALL_EXCEPTION"))return!1;throw this.#Ae=null,e}})()),await this.#Ae}async#ke(e,t){t=(t||[]).slice();const n=this.#xe.interface;t.unshift(Hh(this.name));let r=null;await this.supportsWildcard()&&(r=n.getFunction(e),_e(r,"missing fragment","UNKNOWN_ERROR",{info:{funcName:e}}),t=[zh(this.name,255),n.encodeFunctionData(r,t)],e="resolve(bytes,bytes)"),t.push({enableCcipRead:!0});try{const o=await this.#xe[e](...t);return r?n.decodeFunctionResult(r,o)[0]:o}catch(e){if(!De(e,"CALL_EXCEPTION"))throw e}return null}async getAddress(e){if(null==e&&(e=60),60===e)try{const e=await this.#ke("addr(bytes32)");return null==e||e===zl?null:e}catch(e){if(De(e,"CALL_EXCEPTION"))return null;throw e}if(e>=0&&e<2147483648){let t=e+2147483648;const n=await this.#ke("addr(bytes32,uint)",[t]);if($e(n,20))return Cc(n)}let t=null;for(const n of this.provider.plugins)if(n instanceof Pp&&n.supportsCoinType(e)){t=n;break}if(null==t)return null;const n=await this.#ke("addr(bytes32,uint)",[e]);if(null==n||"0x"===n)return null;const r=await t.decodeAddress(e,n);if(null!=r)return r;_e(!1,"invalid coin data","UNSUPPORTED_OPERATION",{operation:`getAddress(${e})`,info:{coinType:e,data:n}})}async getText(e){const t=await this.#ke("text(bytes32,string)",[e]);return null==t||"0x"===t?null:t}async getContentHash(){const e=await this.#ke("contenthash(bytes32)");if(null==e||"0x"===e)return null;const t=e.match(/^0x(e3010170|e5010172)(([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f]*))$/);if(t){const e="e3010170"===t[1]?"ipfs":"ipns",n=parseInt(t[4],16);if(t[5].length===2*n)return`${e}://${Sp("0x"+t[2])}`}const n=e.match(/^0xe40101fa011b20([0-9a-f]*)$/);if(n&&64===n[1].length)return`bzz://${n[1]}`;_e(!1,"invalid or unsupported content hash data","UNSUPPORTED_OPERATION",{operation:"getContentHash()",info:{data:e}})}async getAvatar(){return(await this._getAvatar()).url}async _getAvatar(){const e=[{type:"name",value:this.name}];try{const t=await this.getText("avatar");if(null==t)return e.push({type:"!avatar",value:""}),{url:null,linkage:e};e.push({type:"avatar",value:t});for(let n=0;n<Op.length;n++){const r=t.match(Op[n]);if(null==r)continue;const o=r[1].toLowerCase();switch(o){case"https":case"data":return e.push({type:"url",value:t}),{linkage:e,url:t};case"ipfs":{const n=Ip(t);return e.push({type:"ipfs",value:t}),e.push({type:"url",value:n}),{linkage:e,url:n}}case"erc721":case"erc1155":{const n="erc721"===o?"tokenURI(uint256)":"uri(uint256)";e.push({type:o,value:t});const i=await this.getAddress();if(null==i)return e.push({type:"!owner",value:""}),{url:null,linkage:e};const s=(r[2]||"").split("/");if(2!==s.length)return e.push({type:`!${o}caip`,value:r[2]||""}),{url:null,linkage:e};const a=s[1],c=new Ff(s[0],["function tokenURI(uint) view returns (string)","function ownerOf(uint) view returns (address)","function uri(uint) view returns (string)","function balanceOf(address, uint256) view returns (uint)"],this.provider);if("erc721"===o){const t=await c.ownerOf(a);if(i!==t)return e.push({type:"!owner",value:t}),{url:null,linkage:e};e.push({type:"owner",value:t})}else if("erc1155"===o){const t=await c.balanceOf(i,a);if(!t)return e.push({type:"!balance",value:"0"}),{url:null,linkage:e};e.push({type:"balance",value:t.toString()})}let u=await c[n](a);if(null==u||"0x"===u)return e.push({type:"!metadata-url",value:""}),{url:null,linkage:e};e.push({type:"metadata-url-base",value:u}),"erc1155"===o&&(u=u.replace("{id}",sc(a,32).substring(2)),e.push({type:"metadata-url-expanded",value:u})),u.match(/^ipfs:/i)&&(u=Ip(u)),e.push({type:"metadata-url",value:u});let l={};const f=await new jl(u).send();f.assertOk();try{l=f.bodyJson}catch(t){try{e.push({type:"!metadata",value:f.bodyText})}catch(t){const n=f.body;return n&&e.push({type:"!metadata",value:Qe(n)}),{url:null,linkage:e}}return{url:null,linkage:e}}if(!l)return e.push({type:"!metadata",value:""}),{url:null,linkage:e};e.push({type:"metadata",value:JSON.stringify(l)});let h=l.image;if("string"!=typeof h)return e.push({type:"!imageUrl",value:""}),{url:null,linkage:e};if(h.match(/^(https:\/\/|data:)/i));else{if(null==h.match(Cp))return e.push({type:"!imageUrl-ipfs",value:h}),{url:null,linkage:e};e.push({type:"imageUrl-ipfs",value:h}),h=Ip(h)}return e.push({type:"url",value:h}),{linkage:e,url:h}}}}}catch(e){}return{linkage:e,url:null}}static async getEnsAddress(e){const t=await e.getNetwork(),n=t.getPlugin("org.ethers.plugins.network.Ens");return _e(n,"network does not support ENS","UNSUPPORTED_OPERATION",{operation:"getEnsAddress",info:{network:t}}),n.address}static async#Se(e,t){const n=await Np.getEnsAddress(e);try{const r=new Ff(n,["function resolver(bytes32) view returns (address)"],e),o=await r.resolver(Hh(t),{enableCcipRead:!0});return o===zl?null:o}catch(e){throw e}}static async fromName(e,t){let n=t;for(;;){if(""===n||"."===n)return null;if("eth"!==t&&"eth"===n)return null;const r=await Np.#Se(e,n);if(null!=r){const o=new Np(e,r,t);return n===t||await o.supportsWildcard()?o:null}n=n.split(".").slice(1).join(".")}}}const Bp=BigInt(0);function Tp(e,t){return function(n){return null==n?t:e(n)}}function Rp(e,t){return n=>{if(t&&null==n)return null;if(!Array.isArray(n))throw new Error("not an array");return n.map(t=>e(t))}}function Up(e,t){return n=>{const r={};for(const o in e){let i=o;if(t&&o in t&&!(i in n))for(const e of t[o])if(e in n){i=e;break}try{const t=e[o](n[i]);void 0!==t&&(r[o]=t)}catch(e){_e(!1,`invalid value for value.${o} (${e instanceof Error?e.message:"not-an-error"})`,"BAD_DATA",{value:n})}}return r}}function Dp(e){return Me($e(e,!0),"invalid data","value",e),e}function Lp(e){return Me($e(e,32),"invalid hash","value",e),e}const Fp=Up({address:Cc,blockHash:Lp,blockNumber:ic,data:Dp,index:ic,removed:Tp(function(e){switch(e){case!0:case"true":return!0;case!1:case"false":return!1}Me(!1,`invalid boolean; ${JSON.stringify(e)}`,"value",e)},!1),topics:Rp(Lp),transactionHash:Lp,transactionIndex:ic},{index:["logIndex"]}),_p=Up({hash:Tp(Lp),parentHash:Lp,parentBeaconBlockRoot:Tp(Lp,null),number:ic,timestamp:ic,nonce:Tp(Dp),difficulty:tc,gasLimit:tc,gasUsed:tc,stateRoot:Tp(Lp,null),receiptsRoot:Tp(Lp,null),blobGasUsed:Tp(tc,null),excessBlobGas:Tp(tc,null),miner:Tp(Cc),prevRandao:Tp(Lp,null),extraData:Dp,baseFeePerGas:Tp(tc)},{prevRandao:["mixHash"]}),Mp=Up({transactionIndex:ic,blockNumber:ic,transactionHash:Lp,address:Cc,topics:Rp(Lp),data:Dp,index:ic,blockHash:Lp},{index:["logIndex"]}),jp=Up({to:Tp(Cc,null),from:Tp(Cc,null),contractAddress:Tp(Cc,null),index:ic,root:Tp(Qe),gasUsed:tc,blobGasUsed:Tp(tc,null),logsBloom:Tp(Dp),blockHash:Lp,hash:Lp,logs:Rp(function(e){return Mp(e)}),blockNumber:ic,cumulativeGasUsed:tc,effectiveGasPrice:Tp(tc),blobGasPrice:Tp(tc,null),status:Tp(ic),type:Tp(ic,0)},{effectiveGasPrice:["gasPrice"],hash:["transactionHash"],index:["transactionIndex"]});function Gp(e){e.to&&tc(e.to)===Bp&&(e.to="0x0000000000000000000000000000000000000000");const t=Up({hash:Lp,index:Tp(ic,void 0),type:e=>"0x"===e||null==e?0:ic(e),accessList:Tp(pl,null),blobVersionedHashes:Tp(Rp(Lp,!0),null),authorizationList:Tp(Rp(e=>{let t;if(e.signature)t=e.signature;else{let n=e.yParity;"0x1b"===n?n=0:"0x1c"===n&&(n=1),t=Object.assign({},e,{yParity:n})}return{address:Cc(e.address),chainId:tc(e.chainId),nonce:tc(e.nonce),signature:Pl.from(t)}},!1),null),blockHash:Tp(Lp,null),blockNumber:Tp(ic,null),transactionIndex:Tp(ic,null),from:Cc,gasPrice:Tp(tc),maxPriorityFeePerGas:Tp(tc),maxFeePerGas:Tp(tc),maxFeePerBlobGas:Tp(tc,null),gasLimit:tc,to:Tp(Cc,null),value:tc,nonce:ic,data:Dp,creates:Tp(Cc,null),chainId:Tp(tc,null)},{data:["input"],gasLimit:["gas"],index:["transactionIndex"]})(e);if(null==t.to&&null==t.creates&&(t.creates=function(e){const t=Cc(e.from);let n=tc(e.nonce,"tx.nonce").toString(16);return n="0"===n?"0x":n.length%2?"0x0"+n:"0x"+n,Cc(Xe(In(Zd([t,n])),12))}(t)),1!==e.type&&2!==e.type||null!=e.accessList||(t.accessList=[]),e.signature?t.signature=Pl.from(e.signature):t.signature=Pl.from(e),null==t.chainId){const e=t.signature.legacyChainId;null!=e&&(t.chainId=e)}return t.blockHash&&tc(t.blockHash)===Bp&&(t.blockHash=null),t}class Hp{name;constructor(e){Re(this,{name:e})}clone(){return new Hp(this.name)}}class zp extends Hp{effectiveBlock;txBase;txCreate;txDataZero;txDataNonzero;txAccessListStorageKey;txAccessListAddress;constructor(e,t){null==e&&(e=0),super(`org.ethers.network.plugins.GasCost#${e||0}`);const n={effectiveBlock:e};function r(e,r){let o=(t||{})[e];null==o&&(o=r),Me("number"==typeof o,`invalud value for ${e}`,"costs",t),n[e]=o}r("txBase",21e3),r("txCreate",32e3),r("txDataZero",4),r("txDataNonzero",16),r("txAccessListStorageKey",1900),r("txAccessListAddress",2400),Re(this,n)}clone(){return new zp(this.effectiveBlock,this)}}class Kp extends Hp{address;targetNetwork;constructor(e,t){super("org.ethers.plugins.network.Ens"),Re(this,{address:e||"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",targetNetwork:null==t?1:t})}clone(){return new Kp(this.address,this.targetNetwork)}}class Vp extends Hp{#N;#Ie;get url(){return this.#N}get processFunc(){return this.#Ie}constructor(e,t){super("org.ethers.plugins.network.FetchUrlFeeDataPlugin"),this.#N=e,this.#Ie=t}clone(){return this}}const Wp=new Map;class $p{#Pe;#he;#Ce;constructor(e,t){this.#Pe=e,this.#he=tc(t),this.#Ce=new Map}toJSON(){return{name:this.name,chainId:String(this.chainId)}}get name(){return this.#Pe}set name(e){this.#Pe=e}get chainId(){return this.#he}set chainId(e){this.#he=tc(e,"chainId")}matches(e){if(null==e)return!1;if("string"==typeof e){try{return this.chainId===tc(e)}catch(e){}return this.name===e}if("number"==typeof e||"bigint"==typeof e){try{return this.chainId===tc(e)}catch(e){}return!1}if("object"==typeof e){if(null!=e.chainId){try{return this.chainId===tc(e.chainId)}catch(e){}return!1}return null!=e.name&&this.name===e.name}return!1}get plugins(){return Array.from(this.#Ce.values())}attachPlugin(e){if(this.#Ce.get(e.name))throw new Error(`cannot replace existing plugin: ${e.name} `);return this.#Ce.set(e.name,e.clone()),this}getPlugin(e){return this.#Ce.get(e)||null}getPlugins(e){return this.plugins.filter(t=>t.name.split("#")[0]===e)}clone(){const e=new $p(this.name,this.chainId);return this.plugins.forEach(t=>{e.attachPlugin(t.clone())}),e}computeIntrinsicGas(e){const t=this.getPlugin("org.ethers.plugins.network.GasCost")||new zp;let n=t.txBase;if(null==e.to&&(n+=t.txCreate),e.data)for(let r=2;r<e.data.length;r+=2)"00"===e.data.substring(r,r+2)?n+=t.txDataZero:n+=t.txDataNonzero;if(e.accessList){const r=pl(e.accessList);for(const e in r)n+=t.txAccessListAddress+t.txAccessListStorageKey*r[e].storageKeys.length}return n}static from(e){if(function(){function e(e,t,n){const r=function(){const r=new $p(e,t);return null!=n.ensNetwork&&r.attachPlugin(new Kp(null,n.ensNetwork)),r.attachPlugin(new zp),(n.plugins||[]).forEach(e=>{r.attachPlugin(e)}),r};$p.register(e,r),$p.register(t,r),n.altNames&&n.altNames.forEach(e=>{$p.register(e,r)})}Qp||(Qp=!0,e("mainnet",1,{ensNetwork:1,altNames:["homestead"]}),e("ropsten",3,{ensNetwork:3}),e("rinkeby",4,{ensNetwork:4}),e("goerli",5,{ensNetwork:5}),e("kovan",42,{ensNetwork:42}),e("sepolia",11155111,{ensNetwork:11155111}),e("holesky",17e3,{ensNetwork:17e3}),e("classic",61,{}),e("classicKotti",6,{}),e("arbitrum",42161,{ensNetwork:1}),e("arbitrum-goerli",421613,{}),e("arbitrum-sepolia",421614,{}),e("base",8453,{ensNetwork:1}),e("base-goerli",84531,{}),e("base-sepolia",84532,{}),e("bnb",56,{ensNetwork:1}),e("bnbt",97,{}),e("filecoin",314,{}),e("filecoin-calibration",314159,{}),e("linea",59144,{ensNetwork:1}),e("linea-goerli",59140,{}),e("linea-sepolia",59141,{}),e("matic",137,{ensNetwork:1,plugins:[Jp("https://gasstation.polygon.technology/v2")]}),e("matic-amoy",80002,{}),e("matic-mumbai",80001,{altNames:["maticMumbai","maticmum"],plugins:[Jp("https://gasstation-testnet.polygon.technology/v2")]}),e("optimism",10,{ensNetwork:1,plugins:[]}),e("optimism-goerli",420,{}),e("optimism-sepolia",11155420,{}),e("xdai",100,{ensNetwork:1}))}(),null==e)return $p.from("mainnet");if("number"==typeof e&&(e=BigInt(e)),"string"==typeof e||"bigint"==typeof e){const t=Wp.get(e);if(t)return t();if("bigint"==typeof e)return new $p("unknown",e);Me(!1,"unknown network","network",e)}if("function"==typeof e.clone)return e.clone();if("object"==typeof e){Me("string"==typeof e.name&&"number"==typeof e.chainId,"invalid network object name or chainId","network",e);const t=new $p(e.name,e.chainId);return(e.ensAddress||null!=e.ensNetwork)&&t.attachPlugin(new Kp(e.ensAddress,e.ensNetwork)),t}Me(!1,"invalid network","network",e)}static register(e,t){"number"==typeof e&&(e=BigInt(e));const n=Wp.get(e);n&&Me(!1,`conflicting network for ${JSON.stringify(n.name)}`,"nameOrChainId",e),Wp.set(e,t)}}function qp(e,t){const n=String(e);if(!n.match(/^[0-9.]+$/))throw new Error(`invalid gwei value: ${e}`);const r=n.split(".");if(1===r.length&&r.push(""),2!==r.length)throw new Error(`invalid gwei value: ${e}`);for(;r[1].length<t;)r[1]+="0";if(r[1].length>9){let e=BigInt(r[1].substring(0,9));r[1].substring(9).match(/^0+$/)||e++,r[1]=e.toString()}return BigInt(r[0]+r[1])}function Jp(e){return new Vp(e,async(e,t,n)=>{let r;n.setHeader("User-Agent","ethers");try{const[t,o]=await Promise.all([n.send(),e()]);r=t;const i=r.bodyJson.standard;return{gasPrice:o.gasPrice,maxFeePerGas:qp(i.maxFee,9),maxPriorityFeePerGas:qp(i.maxPriorityFee,9)}}catch(e){_e(!1,`error encountered with polygon gas station (${JSON.stringify(n.url)})`,"SERVER_ERROR",{request:n,response:r,error:e})}})}let Qp=!1;function Zp(e){return JSON.parse(JSON.stringify(e))}class Yp{#Oe;#Ne;#Be;#Te;constructor(e){this.#Oe=e,this.#Ne=null,this.#Be=4e3,this.#Te=-2}get pollingInterval(){return this.#Be}set pollingInterval(e){this.#Be=e}async#Re(){try{const e=await this.#Oe.getBlockNumber();if(-2===this.#Te)return void(this.#Te=e);if(e!==this.#Te){for(let t=this.#Te+1;t<=e;t++){if(null==this.#Ne)return;await this.#Oe.emit("block",t)}this.#Te=e}}catch(e){}null!=this.#Ne&&(this.#Ne=this.#Oe._setTimeout(this.#Re.bind(this),this.#Be))}start(){this.#Ne||(this.#Ne=this.#Oe._setTimeout(this.#Re.bind(this),this.#Be),this.#Re())}stop(){this.#Ne&&(this.#Oe._clearTimeout(this.#Ne),this.#Ne=null)}pause(e){this.stop(),e&&(this.#Te=-2)}resume(){this.start()}}class Xp{#Oe;#Re;#Ue;constructor(e){this.#Oe=e,this.#Ue=!1,this.#Re=e=>{this._poll(e,this.#Oe)}}async _poll(e,t){throw new Error("sub-classes must override this")}start(){this.#Ue||(this.#Ue=!0,this.#Re(-2),this.#Oe.on("block",this.#Re))}stop(){this.#Ue&&(this.#Ue=!1,this.#Oe.off("block",this.#Re))}pause(e){this.stop()}resume(){this.start()}}class eg extends Xp{#De;#Le;constructor(e,t){super(e),this.#De=t,this.#Le=-2}pause(e){e&&(this.#Le=-2),super.pause(e)}async _poll(e,t){const n=await t.getBlock(this.#De);null!=n&&(-2===this.#Le?this.#Le=n.number:n.number>this.#Le&&(t.emit(this.#De,n.number),this.#Le=n.number))}}class tg extends Xp{#ne;constructor(e,t){super(e),this.#ne=Zp(t)}async _poll(e,t){throw new Error("@TODO")}}class ng extends Xp{#Fe;constructor(e,t){super(e),this.#Fe=t}async _poll(e,t){const n=await t.getTransactionReceipt(this.#Fe);n&&t.emit(this.#Fe,n)}}class rg{#Oe;#ne;#Ne;#Ue;#Te;constructor(e,t){this.#Oe=e,this.#ne=Zp(t),this.#Ne=this.#Re.bind(this),this.#Ue=!1,this.#Te=-2}async#Re(e){if(-2===this.#Te)return;const t=Zp(this.#ne);t.fromBlock=this.#Te+1,t.toBlock=e;const n=await this.#Oe.getLogs(t);if(0!==n.length)for(const e of n)this.#Oe.emit(this.#ne,e),this.#Te=e.blockNumber;else this.#Te<e-60&&(this.#Te=e-60)}start(){this.#Ue||(this.#Ue=!0,-2===this.#Te&&this.#Oe.getBlockNumber().then(e=>{this.#Te=e}),this.#Oe.on("block",this.#Ne))}stop(){this.#Ue&&(this.#Ue=!1,this.#Oe.off("block",this.#Ne))}pause(e){this.stop(),e&&(this.#Te=-2)}resume(){this.start()}}const og=BigInt(2);function ig(e){return e&&"function"==typeof e.then}function sg(e,t){return e+":"+JSON.stringify(t,(e,t)=>{if(null==t)return"null";if("bigint"==typeof t)return`bigint:${t.toString()}`;if("string"==typeof t)return t.toLowerCase();if("object"==typeof t&&!Array.isArray(t)){const e=Object.keys(t);return e.sort(),e.reduce((e,n)=>(e[n]=t[n],e),{})}return t})}class ag{name;constructor(e){Re(this,{name:e})}start(){}stop(){}pause(e){}resume(){}}function cg(e){return(e=Array.from(new Set(e).values())).sort(),e}async function ug(e,t){if(null==e)throw new Error("invalid event");if(Array.isArray(e)&&(e={topics:e}),"string"==typeof e)switch(e){case"block":case"debug":case"error":case"finalized":case"network":case"pending":case"safe":return{type:e,tag:e}}if($e(e,32)){const t=e.toLowerCase();return{type:"transaction",tag:sg("tx",{hash:t}),hash:t}}if(e.orphan){const t=e;return{type:"orphan",tag:sg("orphan",t),filter:(n=t,JSON.parse(JSON.stringify(n)))}}var n;if(e.address||e.topics){const n=e,r={topics:(n.topics||[]).map(e=>null==e?null:Array.isArray(e)?cg(e.map(e=>e.toLowerCase())):e.toLowerCase())};if(n.address){const e=[],o=[],i=n=>{$e(n)?e.push(n):o.push((async()=>{e.push(await Zu(n,t))})())};Array.isArray(n.address)?n.address.forEach(i):i(n.address),o.length&&await Promise.all(o),r.address=cg(e.map(e=>e.toLowerCase()))}return{filter:r,tag:sg("event",r),type:"event"}}Me(!1,"unknown ProviderEvent","event",e)}function lg(){return(new Date).getTime()}const fg={cacheTimeout:250,pollingInterval:4e3};class hg{#_e;#Ce;#Me;#je;#Ge;#He;#ze;#Ke;#Ve;#We;#$e;#l;constructor(e,t){if(this.#l=Object.assign({},fg,t||{}),"any"===e)this.#He=!0,this.#Ge=null;else if(e){const t=$p.from(e);this.#He=!1,this.#Ge=Promise.resolve(t),setTimeout(()=>{this.emit("network",t,null)},0)}else this.#He=!1,this.#Ge=null;this.#Ke=-1,this.#ze=new Map,this.#_e=new Map,this.#Ce=new Map,this.#Me=null,this.#je=!1,this.#Ve=1,this.#We=new Map,this.#$e=!1}get pollingInterval(){return this.#l.pollingInterval}get provider(){return this}get plugins(){return Array.from(this.#Ce.values())}attachPlugin(e){if(this.#Ce.get(e.name))throw new Error(`cannot replace existing plugin: ${e.name} `);return this.#Ce.set(e.name,e.connect(this)),this}getPlugin(e){return this.#Ce.get(e)||null}get disableCcipRead(){return this.#$e}set disableCcipRead(e){this.#$e=!!e}async#qe(e){const t=this.#l.cacheTimeout;if(t<0)return await this._perform(e);const n=sg(e.method,e);let r=this.#ze.get(n);return r||(r=this._perform(e),this.#ze.set(n,r),setTimeout(()=>{this.#ze.get(n)===r&&this.#ze.delete(n)},t)),await r}async ccipReadFetch(e,t,n){if(this.disableCcipRead||0===n.length||null==e.to)return null;const r=e.to.toLowerCase(),o=t.toLowerCase(),i=[];for(let t=0;t<n.length;t++){const s=n[t],a=s.replace("{sender}",r).replace("{data}",o),c=new jl(a);-1===s.indexOf("{data}")&&(c.body={data:o,sender:r}),this.emit("debug",{action:"sendCcipReadFetchRequest",request:c,index:t,urls:n});let u,l="unknown error";try{u=await c.send()}catch(e){i.push(e.message),this.emit("debug",{action:"receiveCcipReadFetchError",request:c,result:{error:e}});continue}try{const e=u.bodyJson;if(e.data)return this.emit("debug",{action:"receiveCcipReadFetchResult",request:c,result:e}),e.data;e.message&&(l=e.message),this.emit("debug",{action:"receiveCcipReadFetchError",request:c,result:e})}catch(e){}_e(u.statusCode<400||u.statusCode>=500,`response not found during CCIP fetch: ${l}`,"OFFCHAIN_FAULT",{reason:"404_MISSING_RESOURCE",transaction:e,info:{url:s,errorMessage:l}}),i.push(l)}_e(!1,`error encountered during CCIP fetch: ${i.map(e=>JSON.stringify(e)).join(", ")}`,"OFFCHAIN_FAULT",{reason:"500_SERVER_ERROR",transaction:e,info:{urls:n,errorMessages:i}})}_wrapBlock(e,t){return new nf(function(e){const t=_p(e);return t.transactions=e.transactions.map(e=>"string"==typeof e?e:Gp(e)),t}(e),this)}_wrapLog(e,t){return new rf(function(e){return Fp(e)}(e),this)}_wrapTransactionReceipt(e,t){return new of(function(e){return jp(e)}(e),this)}_wrapTransactionResponse(e,t){return new sf(Gp(e),this)}_detectNetwork(){_e(!1,"sub-classes must implement this","UNSUPPORTED_OPERATION",{operation:"_detectNetwork"})}async _perform(e){_e(!1,`unsupported method: ${e.method}`,"UNSUPPORTED_OPERATION",{operation:e.method,info:e})}async getBlockNumber(){const e=ic(await this.#qe({method:"getBlockNumber"}),"%response");return this.#Ke>=0&&(this.#Ke=e),e}_getAddress(e){return Zu(e,this)}_getBlockTag(e){if(null==e)return"latest";switch(e){case"earliest":return"0x0";case"finalized":case"latest":case"pending":case"safe":return e}return $e(e)?$e(e,32)?e:cc(e):("bigint"==typeof e&&(e=ic(e,"blockTag")),"number"==typeof e?e>=0?cc(e):this.#Ke>=0?cc(this.#Ke+e):this.getBlockNumber().then(t=>cc(t+e)):void Me(!1,"invalid blockTag","blockTag",e))}_getFilter(e){const t=(e.topics||[]).map(e=>null==e?null:Array.isArray(e)?cg(e.map(e=>e.toLowerCase())):e.toLowerCase()),n="blockHash"in e?e.blockHash:void 0,r=(e,r,o)=>{let i;switch(e.length){case 0:break;case 1:i=e[0];break;default:e.sort(),i=e}if(n&&(null!=r||null!=o))throw new Error("invalid filter");const s={};return i&&(s.address=i),t.length&&(s.topics=t),r&&(s.fromBlock=r),o&&(s.toBlock=o),n&&(s.blockHash=n),s};let o,i,s=[];if(e.address)if(Array.isArray(e.address))for(const t of e.address)s.push(this._getAddress(t));else s.push(this._getAddress(e.address));return"fromBlock"in e&&(o=this._getBlockTag(e.fromBlock)),"toBlock"in e&&(i=this._getBlockTag(e.toBlock)),s.filter(e=>"string"!=typeof e).length||null!=o&&"string"!=typeof o||null!=i&&"string"!=typeof i?Promise.all([Promise.all(s),o,i]).then(e=>r(e[0],e[1],e[2])):r(s,o,i)}_getTransactionRequest(e){const t=tf(e),n=[];if(["to","from"].forEach(e=>{if(null==t[e])return;const r=Zu(t[e],this);ig(r)?n.push(async function(){t[e]=await r}()):t[e]=r}),null!=t.blockTag){const e=this._getBlockTag(t.blockTag);ig(e)?n.push(async function(){t.blockTag=await e}()):t.blockTag=e}return n.length?async function(){return await Promise.all(n),t}():t}async getNetwork(){if(null==this.#Ge){const e=(async()=>{try{const e=await this._detectNetwork();return this.emit("network",e,null),e}catch(t){throw this.#Ge===e&&(this.#Ge=null),t}})();return this.#Ge=e,(await e).clone()}const e=this.#Ge,[t,n]=await Promise.all([e,this._detectNetwork()]);return t.chainId!==n.chainId&&(this.#He?(this.emit("network",n,t),this.#Ge===e&&(this.#Ge=Promise.resolve(n))):_e(!1,`network changed: ${t.chainId} => ${n.chainId} `,"NETWORK_ERROR",{event:"changed"})),t.clone()}async getFeeData(){const e=await this.getNetwork(),t=async()=>{const{_block:t,gasPrice:n,priorityFee:r}=await Te({_block:this.#Je("latest",!1),gasPrice:(async()=>{try{return tc(await this.#qe({method:"getGasPrice"}),"%response")}catch(e){}return null})(),priorityFee:(async()=>{try{return tc(await this.#qe({method:"getPriorityFee"}),"%response")}catch(e){}return null})()});let o=null,i=null;const s=this._wrapBlock(t,e);return s&&s.baseFeePerGas&&(i=null!=r?r:BigInt("1000000000"),o=s.baseFeePerGas*og+i),new ef(n,o,i)},n=e.getPlugin("org.ethers.plugins.network.FetchUrlFeeDataPlugin");if(n){const e=new jl(n.url),r=await n.processFunc(t,this,e);return new ef(r.gasPrice,r.maxFeePerGas,r.maxPriorityFeePerGas)}return await t()}async estimateGas(e){let t=this._getTransactionRequest(e);return ig(t)&&(t=await t),tc(await this.#qe({method:"estimateGas",transaction:t}),"%response")}async#Qe(e,t,n){_e(n<10,"CCIP read exceeded maximum redirections","OFFCHAIN_FAULT",{reason:"TOO_MANY_REDIRECTS",transaction:Object.assign({},e,{blockTag:t,enableCcipRead:!0})});const r=tf(e);try{return Qe(await this._perform({method:"call",transaction:r,blockTag:t}))}catch(e){if(!this.disableCcipRead&&Le(e)&&e.data&&n>=0&&"latest"===t&&null!=r.to&&"0x556f1830"===Xe(e.data,0,4)){const o=e.data,i=await Zu(r.to,this);let s;try{s=function(e){const t={sender:"",urls:[],calldata:"",selector:"",extraData:"",errorArgs:[]};_e(Ye(e)>=160,"insufficient OffchainLookup data","OFFCHAIN_FAULT",{reason:"insufficient OffchainLookup data"});const n=Xe(e,0,32);_e(Xe(n,0,12)===Xe(bg,0,12),"corrupt OffchainLookup sender","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup sender"}),t.sender=Xe(n,12);try{const n=[],r=ic(Xe(e,32,64)),o=ic(Xe(e,r,r+32)),i=Xe(e,r+32);for(let e=0;e<o;e++){const t=dg(i,32*e);if(null==t)throw new Error("abort");n.push(t)}t.urls=n}catch(e){_e(!1,"corrupt OffchainLookup urls","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup urls"})}try{const n=pg(e,64);if(null==n)throw new Error("abort");t.calldata=n}catch(e){_e(!1,"corrupt OffchainLookup calldata","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup calldata"})}_e(Xe(e,100,128)===Xe(bg,0,28),"corrupt OffchainLookup callbaackSelector","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup callbaackSelector"}),t.selector=Xe(e,96,100);try{const n=pg(e,128);if(null==n)throw new Error("abort");t.extraData=n}catch(e){_e(!1,"corrupt OffchainLookup extraData","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup extraData"})}return t.errorArgs="sender,urls,calldata,selector,extraData".split(/,/).map(e=>t[e]),t}(Xe(e.data,4))}catch(e){_e(!1,e.message,"OFFCHAIN_FAULT",{reason:"BAD_DATA",transaction:r,info:{data:o}})}_e(s.sender.toLowerCase()===i.toLowerCase(),"CCIP Read sender mismatch","CALL_EXCEPTION",{action:"call",data:o,reason:"OffchainLookup",transaction:r,invocation:null,revert:{signature:"OffchainLookup(address,string[],bytes,bytes4,bytes)",name:"OffchainLookup",args:s.errorArgs}});const a=await this.ccipReadFetch(r,s.calldata,s.urls);_e(null!=a,"CCIP Read failed to fetch data","OFFCHAIN_FAULT",{reason:"FETCH_FAILED",transaction:r,info:{data:e.data,errorArgs:s.errorArgs}});const c={to:i,data:Ze([s.selector,wg([a,s.extraData])])};this.emit("debug",{action:"sendCcipReadCall",transaction:c});try{const e=await this.#Qe(c,t,n+1);return this.emit("debug",{action:"receiveCcipReadCallResult",transaction:Object.assign({},c),result:e}),e}catch(e){throw this.emit("debug",{action:"receiveCcipReadCallError",transaction:Object.assign({},c),error:e}),e}}throw e}}async#Ze(e){const{value:t}=await Te({network:this.getNetwork(),value:e});return t}async call(e){const{tx:t,blockTag:n}=await Te({tx:this._getTransactionRequest(e),blockTag:this._getBlockTag(e.blockTag)});return await this.#Ze(this.#Qe(t,n,e.enableCcipRead?0:-1))}async#Ye(e,t,n){let r=this._getAddress(t),o=this._getBlockTag(n);return"string"==typeof r&&"string"==typeof o||([r,o]=await Promise.all([r,o])),await this.#Ze(this.#qe(Object.assign(e,{address:r,blockTag:o})))}async getBalance(e,t){return tc(await this.#Ye({method:"getBalance"},e,t),"%response")}async getTransactionCount(e,t){return ic(await this.#Ye({method:"getTransactionCount"},e,t),"%response")}async getCode(e,t){return Qe(await this.#Ye({method:"getCode"},e,t))}async getStorage(e,t,n){const r=tc(t,"position");return Qe(await this.#Ye({method:"getStorage",position:r},e,n))}async broadcastTransaction(e){const{blockNumber:t,hash:n,network:r}=await Te({blockNumber:this.getBlockNumber(),hash:this._perform({method:"broadcastTransaction",signedTransaction:e}),network:this.getNetwork()}),o=bp.from(e);if(o.hash!==n)throw new Error("@TODO: the returned hash did not match");return this._wrapTransactionResponse(o,r).replaceableTransaction(t)}async#Je(e,t){if($e(e,32))return await this.#qe({method:"getBlock",blockHash:e,includeTransactions:t});let n=this._getBlockTag(e);return"string"!=typeof n&&(n=await n),await this.#qe({method:"getBlock",blockTag:n,includeTransactions:t})}async getBlock(e,t){const{network:n,params:r}=await Te({network:this.getNetwork(),params:this.#Je(e,!!t)});return null==r?null:this._wrapBlock(r,n)}async getTransaction(e){const{network:t,params:n}=await Te({network:this.getNetwork(),params:this.#qe({method:"getTransaction",hash:e})});return null==n?null:this._wrapTransactionResponse(n,t)}async getTransactionReceipt(e){const{network:t,params:n}=await Te({network:this.getNetwork(),params:this.#qe({method:"getTransactionReceipt",hash:e})});if(null==n)return null;if(null==n.gasPrice&&null==n.effectiveGasPrice){const t=await this.#qe({method:"getTransaction",hash:e});if(null==t)throw new Error("report this; could not find tx or effectiveGasPrice");n.effectiveGasPrice=t.gasPrice}return this._wrapTransactionReceipt(n,t)}async getTransactionResult(e){const{result:t}=await Te({network:this.getNetwork(),result:this.#qe({method:"getTransactionResult",hash:e})});return null==t?null:Qe(t)}async getLogs(e){let t=this._getFilter(e);ig(t)&&(t=await t);const{network:n,params:r}=await Te({network:this.getNetwork(),params:this.#qe({method:"getLogs",filter:t})});return r.map(e=>this._wrapLog(e,n))}_getProvider(e){_e(!1,"provider cannot connect to target network","UNSUPPORTED_OPERATION",{operation:"_getProvider()"})}async getResolver(e){return await Np.fromName(this,e)}async getAvatar(e){const t=await this.getResolver(e);return t?await t.getAvatar():null}async resolveName(e){const t=await this.getResolver(e);return t?await t.getAddress():null}async lookupAddress(e){const t=Hh((e=Cc(e)).substring(2).toLowerCase()+".addr.reverse");try{const n=await Np.getEnsAddress(this),r=new Ff(n,["function resolver(bytes32) view returns (address)"],this),o=await r.resolver(t);if(null==o||o===zl)return null;const i=new Ff(o,["function name(bytes32) view returns (string)"],this),s=await i.name(t);return await this.resolveName(s)!==e?null:s}catch(e){if(De(e,"BAD_DATA")&&"0x"===e.value)return null;if(De(e,"CALL_EXCEPTION"))return null;throw e}}async waitForTransaction(e,t,n){const r=null!=t?t:1;return 0===r?this.getTransactionReceipt(e):new Promise(async(t,o)=>{let i=null;const s=async n=>{try{const o=await this.getTransactionReceipt(e);if(null!=o&&n-o.blockNumber+1>=r)return t(o),void(i&&(clearTimeout(i),i=null))}catch(e){console.log("EEE",e)}this.once("block",s)};null!=n&&(i=setTimeout(()=>{null!=i&&(i=null,this.off("block",s),o(Fe("timeout","TIMEOUT",{reason:"timeout"})))},n)),s(await this.getBlockNumber())})}async waitForBlock(e){_e(!1,"not implemented yet","NOT_IMPLEMENTED",{operation:"waitForBlock"})}_clearTimeout(e){const t=this.#We.get(e);t&&(t.timer&&clearTimeout(t.timer),this.#We.delete(e))}_setTimeout(e,t){null==t&&(t=0);const n=this.#Ve++,r=()=>{this.#We.delete(n),e()};if(this.paused)this.#We.set(n,{timer:null,func:r,time:t});else{const e=setTimeout(r,t);this.#We.set(n,{timer:e,func:r,time:lg()})}return n}_forEachSubscriber(e){for(const t of this.#_e.values())e(t.subscriber)}_getSubscriber(e){switch(e.type){case"debug":case"error":case"network":return new ag(e.type);case"block":{const e=new Yp(this);return e.pollingInterval=this.pollingInterval,e}case"safe":case"finalized":return new eg(this,e.type);case"event":return new rg(this,e.filter);case"transaction":return new ng(this,e.hash);case"orphan":return new tg(this,e.filter)}throw new Error(`unsupported event: ${e.type}`)}_recoverSubscriber(e,t){for(const n of this.#_e.values())if(n.subscriber===e){n.started&&n.subscriber.stop(),n.subscriber=t,n.started&&t.start(),null!=this.#Me&&t.pause(this.#Me);break}}async#Xe(e,t){let n=await ug(e,this);return"event"===n.type&&t&&t.length>0&&!0===t[0].removed&&(n=await ug({orphan:"drop-log",log:t[0]},this)),this.#_e.get(n.tag)||null}async#et(e){const t=await ug(e,this),n=t.tag;let r=this.#_e.get(n);return r||(r={subscriber:this._getSubscriber(t),tag:n,addressableMap:new WeakMap,nameMap:new Map,started:!1,listeners:[]},this.#_e.set(n,r)),r}async on(e,t){const n=await this.#et(e);return n.listeners.push({listener:t,once:!1}),n.started||(n.subscriber.start(),n.started=!0,null!=this.#Me&&n.subscriber.pause(this.#Me)),this}async once(e,t){const n=await this.#et(e);return n.listeners.push({listener:t,once:!0}),n.started||(n.subscriber.start(),n.started=!0,null!=this.#Me&&n.subscriber.pause(this.#Me)),this}async emit(e,...t){const n=await this.#Xe(e,t);if(!n||0===n.listeners.length)return!1;const r=n.listeners.length;return n.listeners=n.listeners.filter(({listener:n,once:r})=>{const o=new uf(this,r?null:n,e);try{n.call(this,...t,o)}catch(e){}return!r}),0===n.listeners.length&&(n.started&&n.subscriber.stop(),this.#_e.delete(n.tag)),r>0}async listenerCount(e){if(e){const t=await this.#Xe(e);return t?t.listeners.length:0}let t=0;for(const{listeners:e}of this.#_e.values())t+=e.length;return t}async listeners(e){if(e){const t=await this.#Xe(e);return t?t.listeners.map(({listener:e})=>e):[]}let t=[];for(const{listeners:e}of this.#_e.values())t=t.concat(e.map(({listener:e})=>e));return t}async off(e,t){const n=await this.#Xe(e);if(!n)return this;if(t){const e=n.listeners.map(({listener:e})=>e).indexOf(t);e>=0&&n.listeners.splice(e,1)}return t&&0!==n.listeners.length||(n.started&&n.subscriber.stop(),this.#_e.delete(n.tag)),this}async removeAllListeners(e){if(e){const{tag:t,started:n,subscriber:r}=await this.#et(e);n&&r.stop(),this.#_e.delete(t)}else for(const[e,{started:t,subscriber:n}]of this.#_e)t&&n.stop(),this.#_e.delete(e);return this}async addListener(e,t){return await this.on(e,t)}async removeListener(e,t){return this.off(e,t)}get destroyed(){return this.#je}destroy(){this.removeAllListeners();for(const e of this.#We.keys())this._clearTimeout(e);this.#je=!0}get paused(){return null!=this.#Me}set paused(e){!!e!==this.paused&&(this.paused?this.resume():this.pause(!1))}pause(e){if(this.#Ke=-1,null!=this.#Me){if(this.#Me==!!e)return;_e(!1,"cannot change pause type; resume first","UNSUPPORTED_OPERATION",{operation:"pause"})}this._forEachSubscriber(t=>t.pause(e)),this.#Me=!!e;for(const e of this.#We.values())e.timer&&clearTimeout(e.timer),e.time=lg()-e.time}resume(){if(null!=this.#Me){this._forEachSubscriber(e=>e.resume()),this.#Me=null;for(const e of this.#We.values()){let t=e.time;t<0&&(t=0),e.time=lg(),setTimeout(e.func,t)}}}}function dg(e,t){try{const n=pg(e,t);if(n)return it(n)}catch(e){}return null}function pg(e,t){if("0x"===e)return null;try{const n=ic(Xe(e,t,t+32)),r=ic(Xe(e,n,n+32));return Xe(e,n+32,n+32+r)}catch(e){}return null}function gg(e){const t=ac(e);if(t.length>32)throw new Error("internal; should not happen");const n=new Uint8Array(32);return n.set(t,32-t.length),n}function yg(e){if(e.length%32==0)return e;const t=new Uint8Array(32*Math.ceil(e.length/32));return t.set(e),t}const mg=new Uint8Array([]);function wg(e){const t=[];let n=0;for(let r=0;r<e.length;r++)t.push(mg),n+=32;for(let r=0;r<e.length;r++){const o=Ve(e[r]);t[r]=gg(n),t.push(gg(o.length)),t.push(yg(o)),n+=32+32*Math.ceil(o.length/32)}return Ze(t)}const bg="0x0000000000000000000000000000000000000000000000000000000000000000";function vg(e,t){if(e.provider)return e.provider;_e(!1,"missing provider","UNSUPPORTED_OPERATION",{operation:t})}async function Eg(e,t){let n=tf(t);if(null!=n.to&&(n.to=Zu(n.to,e)),null!=n.from){const t=n.from;n.from=Promise.all([e.getAddress(),Zu(t,e)]).then(([e,t])=>(Me(e.toLowerCase()===t.toLowerCase(),"transaction from mismatch","tx.from",t),e))}else n.from=e.getAddress();return await Te(n)}class Ag{provider;constructor(e){Re(this,{provider:e||null})}async getNonce(e){return vg(this,"getTransactionCount").getTransactionCount(await this.getAddress(),e)}async populateCall(e){return await Eg(this,e)}async populateTransaction(e){const t=vg(this,"populateTransaction"),n=await Eg(this,e);null==n.nonce&&(n.nonce=await this.getNonce("pending")),null==n.gasLimit&&(n.gasLimit=await this.estimateGas(n));const r=await this.provider.getNetwork();null!=n.chainId?Me(tc(n.chainId)===r.chainId,"transaction chainId mismatch","tx.chainId",e.chainId):n.chainId=r.chainId;const o=null!=n.maxFeePerGas||null!=n.maxPriorityFeePerGas;if(null==n.gasPrice||2!==n.type&&!o?0!==n.type&&1!==n.type||!o||Me(!1,"pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas","tx",e):Me(!1,"eip-1559 transaction do not support gasPrice","tx",e),2!==n.type&&null!=n.type||null==n.maxFeePerGas||null==n.maxPriorityFeePerGas)if(0===n.type||1===n.type){const e=await t.getFeeData();_e(null!=e.gasPrice,"network does not support gasPrice","UNSUPPORTED_OPERATION",{operation:"getGasPrice"}),null==n.gasPrice&&(n.gasPrice=e.gasPrice)}else{const e=await t.getFeeData();if(null==n.type)if(null!=e.maxFeePerGas&&null!=e.maxPriorityFeePerGas)if(n.authorizationList&&n.authorizationList.length?n.type=4:n.type=2,null!=n.gasPrice){const e=n.gasPrice;delete n.gasPrice,n.maxFeePerGas=e,n.maxPriorityFeePerGas=e}else null==n.maxFeePerGas&&(n.maxFeePerGas=e.maxFeePerGas),null==n.maxPriorityFeePerGas&&(n.maxPriorityFeePerGas=e.maxPriorityFeePerGas);else null!=e.gasPrice?(_e(!o,"network does not support EIP-1559","UNSUPPORTED_OPERATION",{operation:"populateTransaction"}),null==n.gasPrice&&(n.gasPrice=e.gasPrice),n.type=0):_e(!1,"failed to get consistent fee data","UNSUPPORTED_OPERATION",{operation:"signer.getFeeData"});else 2!==n.type&&3!==n.type&&4!==n.type||(null==n.maxFeePerGas&&(n.maxFeePerGas=e.maxFeePerGas),null==n.maxPriorityFeePerGas&&(n.maxPriorityFeePerGas=e.maxPriorityFeePerGas))}else n.type=2;return await Te(n)}async populateAuthorization(e){const t=Object.assign({},e);return null==t.chainId&&(t.chainId=(await vg(this,"getNetwork").getNetwork()).chainId),null==t.nonce&&(t.nonce=await this.getNonce()),t}async estimateGas(e){return vg(this,"estimateGas").estimateGas(await this.populateCall(e))}async call(e){return vg(this,"call").call(await this.populateCall(e))}async resolveName(e){const t=vg(this,"resolveName");return await t.resolveName(e)}async sendTransaction(e){const t=vg(this,"sendTransaction"),n=await this.populateTransaction(e);delete n.from;const r=bp.from(n);return await t.broadcastTransaction(await this.signTransaction(r))}authorize(e){_e(!1,"authorization not implemented for this signer","UNSUPPORTED_OPERATION",{operation:"authorize"})}}class xg extends Ag{address;constructor(e,t){super(t),Re(this,{address:e})}async getAddress(){return this.address}connect(e){return new xg(this.address,e)}#tt(e,t){_e(!1,`VoidSigner cannot sign ${e}`,"UNSUPPORTED_OPERATION",{operation:t})}async signTransaction(e){this.#tt("transactions","signTransaction")}async signMessage(e){this.#tt("messages","signMessage")}async signTypedData(e,t,n){this.#tt("typed-data","signTypedData")}}class kg{#Oe;#nt;#Ne;#Ue;#rt;#ot;constructor(e){this.#Oe=e,this.#nt=null,this.#Ne=this.#Re.bind(this),this.#Ue=!1,this.#rt=null,this.#ot=!1}_subscribe(e){throw new Error("subclasses must override this")}_emitResults(e,t){throw new Error("subclasses must override this")}_recover(e){throw new Error("subclasses must override this")}async#Re(e){try{null==this.#nt&&(this.#nt=this._subscribe(this.#Oe));let e=null;try{e=await this.#nt}catch(e){if(!De(e,"UNSUPPORTED_OPERATION")||"eth_newFilter"!==e.operation)throw e}if(null==e)return this.#nt=null,void this.#Oe._recoverSubscriber(this,this._recover(this.#Oe));const t=await this.#Oe.getNetwork();if(this.#rt||(this.#rt=t),this.#rt.chainId!==t.chainId)throw new Error("chaid changed");if(this.#ot)return;const n=await this.#Oe.send("eth_getFilterChanges",[e]);await this._emitResults(this.#Oe,n)}catch(e){console.log("@TODO",e)}this.#Oe.once("block",this.#Ne)}#it(){const e=this.#nt;e&&(this.#nt=null,e.then(e=>{this.#Oe.destroyed||this.#Oe.send("eth_uninstallFilter",[e])}))}start(){this.#Ue||(this.#Ue=!0,this.#Re(-2))}stop(){this.#Ue&&(this.#Ue=!1,this.#ot=!0,this.#it(),this.#Oe.off("block",this.#Ne))}pause(e){e&&this.#it(),this.#Oe.off("block",this.#Ne)}resume(){this.start()}}class Sg extends kg{#st;constructor(e,t){var n;super(e),this.#st=(n=t,JSON.parse(JSON.stringify(n)))}_recover(e){return new rg(e,this.#st)}async _subscribe(e){return await e.send("eth_newFilter",[this.#st])}async _emitResults(e,t){for(const n of t)e.emit(this.#st,e._wrapLog(n,e._network))}}class Ig extends kg{async _subscribe(e){return await e.send("eth_newPendingTransactionFilter",[])}async _emitResults(e,t){for(const n of t)e.emit("pending",n)}}const Pg="bigint,boolean,function,number,string,symbol".split(/,/g);function Cg(e){if(null==e||Pg.indexOf(typeof e)>=0)return e;if("function"==typeof e.getAddress)return e;if(Array.isArray(e))return e.map(Cg);if("object"==typeof e)return Object.keys(e).reduce((t,n)=>(t[n]=e[n],t),{});throw new Error(`should not happen: ${e} (${typeof e})`)}function Og(e){return new Promise(t=>{setTimeout(t,e)})}function Ng(e){return e?e.toLowerCase():e}function Bg(e){return e&&"number"==typeof e.pollingInterval}const Tg={polling:!1,staticNetwork:null,batchStallTime:10,batchMaxSize:1<<20,batchMaxCount:100,cacheTimeout:250,pollingInterval:4e3};class Rg extends Ag{address;constructor(e,t){super(e),Re(this,{address:t=Cc(t)})}connect(e){_e(!1,"cannot reconnect JsonRpcSigner","UNSUPPORTED_OPERATION",{operation:"signer.connect"})}async getAddress(){return this.address}async populateTransaction(e){return await this.populateCall(e)}async sendUncheckedTransaction(e){const t=Cg(e),n=[];if(t.from){const r=t.from;n.push((async()=>{const n=await Zu(r,this.provider);Me(null!=n&&n.toLowerCase()===this.address.toLowerCase(),"from address mismatch","transaction",e),t.from=n})())}else t.from=this.address;if(null==t.gasLimit&&n.push((async()=>{t.gasLimit=await this.provider.estimateGas({...t,from:this.address})})()),null!=t.to){const e=t.to;n.push((async()=>{t.to=await Zu(e,this.provider)})())}n.length&&await Promise.all(n);const r=this.provider.getRpcTransaction(t);return this.provider.send("eth_sendTransaction",[r])}async sendTransaction(e){const t=await this.provider.getBlockNumber(),n=await this.sendUncheckedTransaction(e);return await new Promise((e,r)=>{const o=[1e3,100];let i=0;const s=async()=>{try{const r=await this.provider.getTransaction(n);if(null!=r)return void e(r.replaceableTransaction(t))}catch(e){if(De(e,"CANCELLED")||De(e,"BAD_DATA")||De(e,"NETWORK_ERROR")||De(e,"UNSUPPORTED_OPERATION"))return null==e.info&&(e.info={}),e.info.sendTransactionHash=n,void r(e);if(De(e,"INVALID_ARGUMENT")&&(i++,null==e.info&&(e.info={}),e.info.sendTransactionHash=n,i>10))return void r(e);this.provider.emit("error",Fe("failed to fetch transation after sending (will try again)","UNKNOWN_ERROR",{error:e}))}this.provider._setTimeout(()=>{s()},o.pop()||4e3)};s()})}async signTransaction(e){const t=Cg(e);if(t.from){const n=await Zu(t.from,this.provider);Me(null!=n&&n.toLowerCase()===this.address.toLowerCase(),"from address mismatch","transaction",e),t.from=n}else t.from=this.address;const n=this.provider.getRpcTransaction(t);return await this.provider.send("eth_signTransaction",[n])}async signMessage(e){const t="string"==typeof e?ot(e):e;return await this.provider.send("personal_sign",[Qe(t),this.address.toLowerCase()])}async signTypedData(e,t,n){const r=Cg(n),o=await hl.resolveNames(e,t,r,async e=>{const t=await Zu(e);return Me(null!=t,"TypedData does not support null address","value",e),t});return await this.provider.send("eth_signTypedData_v4",[this.address.toLowerCase(),JSON.stringify(hl.getPayload(o.domain,t,o.value))])}async unlock(e){return this.provider.send("personal_unlockAccount",[this.address.toLowerCase(),e,null])}async _legacySignMessage(e){const t="string"==typeof e?ot(e):e;return await this.provider.send("eth_sign",[this.address.toLowerCase(),Qe(t)])}}class Ug extends hg{#l;#at;#ct;#ut;#lt;#rt;#ft;#ht(){if(this.#ut)return;const e=1===this._getOption("batchMaxCount")?0:this._getOption("batchStallTime");this.#ut=setTimeout(()=>{this.#ut=null;const e=this.#ct;for(this.#ct=[];e.length;){const t=[e.shift()];for(;e.length&&t.length!==this.#l.batchMaxCount;)if(t.push(e.shift()),JSON.stringify(t.map(e=>e.payload)).length>this.#l.batchMaxSize){e.unshift(t.pop());break}(async()=>{const e=1===t.length?t[0].payload:t.map(e=>e.payload);this.emit("debug",{action:"sendRpcPayload",payload:e});try{const n=await this._send(e);this.emit("debug",{action:"receiveRpcResult",result:n});for(const{resolve:e,reject:r,payload:o}of t){if(this.destroyed){r(Fe("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:o.method}));continue}const t=n.filter(e=>e.id===o.id)[0];if(null==t){const e=Fe("missing response for request","BAD_DATA",{value:n,info:{payload:o}});this.emit("error",e),r(e);continue}"error"in t?r(this.getRpcError(o,t)):e(t.result)}}catch(e){this.emit("debug",{action:"receiveRpcError",error:e});for(const{reject:n}of t)n(e)}})()}},e)}constructor(e,t){super(e,t),this.#at=1,this.#l=Object.assign({},Tg,t||{}),this.#ct=[],this.#ut=null,this.#rt=null,this.#ft=null;{let e=null;const t=new Promise(t=>{e=t});this.#lt={promise:t,resolve:e}}const n=this._getOption("staticNetwork");"boolean"==typeof n?(Me(!n||"any"!==e,"staticNetwork cannot be used on special network 'any'","options",t),n&&null!=e&&(this.#rt=$p.from(e))):n&&(Me(null==e||n.matches(e),"staticNetwork MUST match network object","options",t),this.#rt=n)}_getOption(e){return this.#l[e]}get _network(){return _e(this.#rt,"network is not available yet","NETWORK_ERROR"),this.#rt}async _perform(e){if("call"===e.method||"estimateGas"===e.method){let t=e.transaction;if(t&&null!=t.type&&tc(t.type)&&null==t.maxFeePerGas&&null==t.maxPriorityFeePerGas){const n=await this.getFeeData();null==n.maxFeePerGas&&null==n.maxPriorityFeePerGas&&(e=Object.assign({},e,{transaction:Object.assign({},t,{type:void 0})}))}}const t=this.getRpcRequest(e);return null!=t?await this.send(t.method,t.args):super._perform(e)}async _detectNetwork(){const e=this._getOption("staticNetwork");if(e){if(!0!==e)return e;if(this.#rt)return this.#rt}return this.#ft?await this.#ft:this.ready?(this.#ft=(async()=>{try{const e=$p.from(tc(await this.send("eth_chainId",[])));return this.#ft=null,e}catch(e){throw this.#ft=null,e}})(),await this.#ft):(this.#ft=(async()=>{const e={id:this.#at++,method:"eth_chainId",params:[],jsonrpc:"2.0"};let t;this.emit("debug",{action:"sendRpcPayload",payload:e});try{t=(await this._send(e))[0],this.#ft=null}catch(e){throw this.#ft=null,this.emit("debug",{action:"receiveRpcError",error:e}),e}if(this.emit("debug",{action:"receiveRpcResult",result:t}),"result"in t)return $p.from(tc(t.result));throw this.getRpcError(e,t)})(),await this.#ft)}_start(){null!=this.#lt&&null!=this.#lt.resolve&&(this.#lt.resolve(),this.#lt=null,(async()=>{for(;null==this.#rt&&!this.destroyed;)try{this.#rt=await this._detectNetwork()}catch(e){if(this.destroyed)break;console.log("JsonRpcProvider failed to detect network and cannot start up; retry in 1s (perhaps the URL is wrong or the node is not started)"),this.emit("error",Fe("failed to bootstrap network detection","NETWORK_ERROR",{event:"initial-network-discovery",info:{error:e}})),await Og(1e3)}this.#ht()})())}async _waitUntilReady(){if(null!=this.#lt)return await this.#lt.promise}_getSubscriber(e){return"pending"===e.type?new Ig(this):"event"===e.type?this._getOption("polling")?new rg(this,e.filter):new Sg(this,e.filter):"orphan"===e.type&&"drop-log"===e.filter.orphan?new ag("orphan"):super._getSubscriber(e)}get ready(){return null==this.#lt}getRpcTransaction(e){const t={};return["chainId","gasLimit","gasPrice","type","maxFeePerGas","maxPriorityFeePerGas","nonce","value"].forEach(n=>{if(null==e[n])return;let r=n;"gasLimit"===n&&(r="gas"),t[r]=cc(tc(e[n],`tx.${n}`))}),["from","to","data"].forEach(n=>{null!=e[n]&&(t[n]=Qe(e[n]))}),e.accessList&&(t.accessList=pl(e.accessList)),e.blobVersionedHashes&&(t.blobVersionedHashes=e.blobVersionedHashes.map(e=>e.toLowerCase())),e.authorizationList&&(t.authorizationList=e.authorizationList.map(e=>{const t=Cl(e);return{address:t.address,nonce:cc(t.nonce),chainId:cc(t.chainId),yParity:cc(t.signature.yParity),r:cc(t.signature.r),s:cc(t.signature.s)}})),t}getRpcRequest(e){switch(e.method){case"chainId":return{method:"eth_chainId",args:[]};case"getBlockNumber":return{method:"eth_blockNumber",args:[]};case"getGasPrice":return{method:"eth_gasPrice",args:[]};case"getPriorityFee":return{method:"eth_maxPriorityFeePerGas",args:[]};case"getBalance":return{method:"eth_getBalance",args:[Ng(e.address),e.blockTag]};case"getTransactionCount":return{method:"eth_getTransactionCount",args:[Ng(e.address),e.blockTag]};case"getCode":return{method:"eth_getCode",args:[Ng(e.address),e.blockTag]};case"getStorage":return{method:"eth_getStorageAt",args:[Ng(e.address),"0x"+e.position.toString(16),e.blockTag]};case"broadcastTransaction":return{method:"eth_sendRawTransaction",args:[e.signedTransaction]};case"getBlock":if("blockTag"in e)return{method:"eth_getBlockByNumber",args:[e.blockTag,!!e.includeTransactions]};if("blockHash"in e)return{method:"eth_getBlockByHash",args:[e.blockHash,!!e.includeTransactions]};break;case"getTransaction":return{method:"eth_getTransactionByHash",args:[e.hash]};case"getTransactionReceipt":return{method:"eth_getTransactionReceipt",args:[e.hash]};case"call":return{method:"eth_call",args:[this.getRpcTransaction(e.transaction),e.blockTag]};case"estimateGas":return{method:"eth_estimateGas",args:[this.getRpcTransaction(e.transaction)]};case"getLogs":return e.filter&&null!=e.filter.address&&(Array.isArray(e.filter.address)?e.filter.address=e.filter.address.map(Ng):e.filter.address=Ng(e.filter.address)),{method:"eth_getLogs",args:[e.filter]}}return null}getRpcError(e,t){const{method:n}=e,{error:r}=t;if("eth_estimateGas"===n&&r.message){const t=r.message;if(!t.match(/revert/i)&&t.match(/insufficient funds/i))return Fe("insufficient funds","INSUFFICIENT_FUNDS",{transaction:e.params[0],info:{payload:e,error:r}});if(t.match(/nonce/i)&&t.match(/too low/i))return Fe("nonce has already been used","NONCE_EXPIRED",{transaction:e.params[0],info:{payload:e,error:r}})}if("eth_call"===n||"eth_estimateGas"===n){const t=Fg(r),o=qu.getBuiltinCallException("eth_call"===n?"call":"estimateGas",e.params[0],t?t.data:null);return o.info={error:r,payload:e},o}const o=JSON.stringify(function(e){const t=[];return _g(e,t),t}(r));if("string"==typeof r.message&&r.message.match(/user denied|ethers-user-denied/i))return Fe("user rejected action","ACTION_REJECTED",{action:{eth_sign:"signMessage",personal_sign:"signMessage",eth_signTypedData_v4:"signTypedData",eth_signTransaction:"signTransaction",eth_sendTransaction:"sendTransaction",eth_requestAccounts:"requestAccess",wallet_requestAccounts:"requestAccess"}[n]||"unknown",reason:"rejected",info:{payload:e,error:r}});if("eth_sendRawTransaction"===n||"eth_sendTransaction"===n){const t=e.params[0];if(o.match(/insufficient funds|base fee exceeds gas limit/i))return Fe("insufficient funds for intrinsic transaction cost","INSUFFICIENT_FUNDS",{transaction:t,info:{error:r}});if(o.match(/nonce/i)&&o.match(/too low/i))return Fe("nonce has already been used","NONCE_EXPIRED",{transaction:t,info:{error:r}});if(o.match(/replacement transaction/i)&&o.match(/underpriced/i))return Fe("replacement fee too low","REPLACEMENT_UNDERPRICED",{transaction:t,info:{error:r}});if(o.match(/only replay-protected/i))return Fe("legacy pre-eip-155 transactions not supported","UNSUPPORTED_OPERATION",{operation:n,info:{transaction:t,info:{error:r}}})}let i=!!o.match(/the method .* does not exist/i);return i||r&&r.details&&r.details.startsWith("Unauthorized method:")&&(i=!0),i?Fe("unsupported operation","UNSUPPORTED_OPERATION",{operation:e.method,info:{error:r,payload:e}}):Fe("could not coalesce error","UNKNOWN_ERROR",{error:r,payload:e})}send(e,t){if(this.destroyed)return Promise.reject(Fe("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:e}));const n=this.#at++,r=new Promise((r,o)=>{this.#ct.push({resolve:r,reject:o,payload:{method:e,params:t,id:n,jsonrpc:"2.0"}})});return this.#ht(),r}async getSigner(e){null==e&&(e=0);const t=this.send("eth_accounts",[]);if("number"==typeof e){const n=await t;if(e>=n.length)throw new Error("no such account");return new Rg(this,n[e])}const{accounts:n}=await Te({network:this.getNetwork(),accounts:t});e=Cc(e);for(const t of n)if(Cc(t)===e)return new Rg(this,e);throw new Error("invalid account")}async listAccounts(){return(await this.send("eth_accounts",[])).map(e=>new Rg(this,e))}destroy(){this.#ut&&(clearTimeout(this.#ut),this.#ut=null);for(const{payload:e,reject:t}of this.#ct)t(Fe("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:e.method}));this.#ct=[],super.destroy()}}class Dg extends Ug{#dt;constructor(e,t){super(e,t);let n=this._getOption("pollingInterval");null==n&&(n=Tg.pollingInterval),this.#dt=n}_getSubscriber(e){const t=super._getSubscriber(e);return Bg(t)&&(t.pollingInterval=this.#dt),t}get pollingInterval(){return this.#dt}set pollingInterval(e){if(!Number.isInteger(e)||e<0)throw new Error("invalid interval");this.#dt=e,this._forEachSubscriber(e=>{Bg(e)&&(e.pollingInterval=this.#dt)})}}class Lg extends Dg{#pt;constructor(e,t,n){null==e&&(e="http://localhost:8545"),super(t,n),this.#pt="string"==typeof e?new jl(e):e.clone()}_getConnection(){return this.#pt.clone()}async send(e,t){return await this._start(),await super.send(e,t)}async _send(e){const t=this._getConnection();t.body=JSON.stringify(e),t.setHeader("content-type","application/json");const n=await t.send();n.assertOk();let r=n.bodyJson;return Array.isArray(r)||(r=[r]),r}}function Fg(e){if(null==e)return null;if("string"==typeof e.message&&e.message.match(/revert/i)&&$e(e.data))return{message:e.message,data:e.data};if("object"==typeof e){for(const t in e){const n=Fg(e[t]);if(n)return n}return null}if("string"==typeof e)try{return Fg(JSON.parse(e))}catch(e){}return null}function _g(e,t){if(null!=e){if("string"==typeof e.message&&t.push(e.message),"object"==typeof e)for(const n in e)_g(e[n],t);if("string"==typeof e)try{return _g(JSON.parse(e),t)}catch(e){}}}class Mg extends Dg{#z;#gt;constructor(e,t,n){const r=Object.assign({},null!=n?n:{},{batchMaxCount:1});Me(e&&e.request,"invalid EIP-1193 provider","ethereum",e),super(t,r),this.#gt=null,n&&n.providerInfo&&(this.#gt=n.providerInfo),this.#z=async(t,n)=>{const r={method:t,params:n};this.emit("debug",{action:"sendEip1193Request",payload:r});try{const t=await e.request(r);return this.emit("debug",{action:"receiveEip1193Result",result:t}),t}catch(e){const t=new Error(e.message);throw t.code=e.code,t.data=e.data,t.payload=r,this.emit("debug",{action:"receiveEip1193Error",error:t}),t}}}get providerInfo(){return this.#gt}async send(e,t){return await this._start(),await super.send(e,t)}async _send(e){Me(!Array.isArray(e),"EIP-1193 does not support batch request","payload",e);try{const t=await this.#z(e.method,e.params||[]);return[{id:e.id,result:t}]}catch(t){return[{id:e.id,error:{code:t.code,data:t.data,message:t.message}}]}}getRpcError(e,t){switch((t=JSON.parse(JSON.stringify(t))).error.code||-1){case 4001:t.error.message=`ethers-user-denied: ${t.error.message}`;break;case 4200:t.error.message=`ethers-unsupported: ${t.error.message}`}return super.getRpcError(e,t)}async hasSigner(e){null==e&&(e=0);const t=await this.send("eth_accounts",[]);return"number"==typeof e?t.length>e:(e=e.toLowerCase(),0!==t.filter(t=>t.toLowerCase()===e).length)}async getSigner(e){if(null==e&&(e=0),!await this.hasSigner(e))try{await this.#z("eth_requestAccounts",[])}catch(e){const t=e.payload;throw this.getRpcError(t,{id:t.id,error:e})}return await super.getSigner(e)}static async discover(e){if(null==e&&(e={}),e.provider)return new Mg(e.provider);const t=e.window?e.window:"undefined"!=typeof window?window:null;if(null==t)return null;const n=e.anyProvider;if(n&&t.ethereum)return new Mg(t.ethereum);if(!("addEventListener"in t&&"dispatchEvent"in t&&"removeEventListener"in t))return null;const r=e.timeout?e.timeout:300;return 0===r?null:await new Promise((o,i)=>{let s=[];const a=e=>{s.push(e.detail),n&&c()},c=()=>{if(clearTimeout(u),s.length)if(e&&e.filter){const t=e.filter(s.map(e=>Object.assign({},e.info)));if(null==t)o(null);else if(t instanceof Mg)o(t);else{let e=null;if(t.uuid){const n=s.filter(e=>t.uuid===e.info.uuid);e=n[0]}if(e){const{provider:t,info:n}=e;o(new Mg(t,void 0,{providerInfo:n}))}else i(Fe("filter returned unknown info","UNSUPPORTED_OPERATION",{value:t}))}}else{const{provider:e,info:t}=s[0];o(new Mg(e,void 0,{providerInfo:t}))}else o(null);t.removeEventListener("eip6963:announceProvider",a)},u=setTimeout(()=>{c()},r);t.addEventListener("eip6963:announceProvider",a),t.dispatchEvent(new Event("eip6963:requestProvider"))})}}function jg(e){return"string"==typeof e&&(e=ot(e)),In(Ze([ot("Ethereum Signed Message:\n"),ot(String(e.length)),e]))}function Gg(e,t){return Xd(jg(e),t)}class Hg extends Ag{address;#yt;constructor(e,t){super(t),Me(e&&"function"==typeof e.sign,"invalid private key","privateKey","[ REDACTED ]"),this.#yt=e,Re(this,{address:Yd(this.signingKey.publicKey)})}get signingKey(){return this.#yt}get privateKey(){return this.signingKey.privateKey}async getAddress(){return this.address}connect(e){return new Hg(this.#yt,e)}async signTransaction(e){e=tf(e);const{to:t,from:n}=await Te({to:e.to?Zu(e.to,this):void 0,from:e.from?Zu(e.from,this):void 0});null!=t&&(e.to=t),null!=n&&(e.from=n),null!=e.from&&(Me(Cc(e.from)===this.address,"transaction from address mismatch","tx.from",e.from),delete e.from);const r=bp.from(e);return r.signature=this.signingKey.sign(r.unsignedHash),r.serialized}async signMessage(e){return this.signMessageSync(e)}signMessageSync(e){return this.signingKey.sign(jg(e)).serialized}authorizeSync(e){Me("string"==typeof e.address,"invalid address for authorizeSync","auth.address",e);const t=this.signingKey.sign(function(e){return Me("string"==typeof e.address,"invalid address for hashAuthorization","auth.address",e),In(Ze(["0x05",Zd([null!=e.chainId?ac(e.chainId):"0x",Cc(e.address),null!=e.nonce?ac(e.nonce):"0x"])]))}(e));return Object.assign({},{address:Cc(e.address),nonce:tc(e.nonce||0),chainId:tc(e.chainId||0)},{signature:t})}async authorize(e){return e=Object.assign({},e,{address:await Zu(e.address,this)}),this.authorizeSync(await this.populateAuthorization(e))}async signTypedData(e,t,n){const r=await hl.resolveNames(e,t,n,async e=>{_e(null!=this.provider,"cannot resolve ENS names without a provider","UNSUPPORTED_OPERATION",{operation:"resolveName",info:{name:e}});const t=await this.provider.resolveName(e);return _e(null!=t,"unconfigured ENS name","UNCONFIGURED_NAME",{value:e}),t});return this.signingKey.sign(hl.hash(r.domain,t,r.value)).serialized}}let zg=!1;const Kg=function(e,t,n){return function(e,t){const n={sha256:Ut,sha512:Jt}[e];return Me(null!=n,"invalid hmac algorithm","algorithm",e),St.create(n,t)}(e,t).update(n).digest()};let Vg=Kg;function Wg(e,t,n){const r=Ve(t,"key"),o=Ve(n,"data");return Qe(Vg(e,r,o))}Wg._=Kg,Wg.lock=function(){zg=!0},Wg.register=function(e){if(zg)throw new Error("computeHmac is locked");Vg=e},Object.freeze(Wg);const $g=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),qg=Uint8Array.from({length:16},(e,t)=>t),Jg=qg.map(e=>(9*e+5)%16);let Qg=[qg],Zg=[Jg];for(let e=0;e<4;e++)for(let t of[Qg,Zg])t.push(t[e].map(e=>$g[e]));const Yg=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>new Uint8Array(e)),Xg=Qg.map((e,t)=>e.map(e=>Yg[t][e])),ey=Zg.map((e,t)=>e.map(e=>Yg[t][e])),ty=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),ny=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),ry=(e,t)=>e<<t|e>>>32-t;function oy(e,t,n,r){return 0===e?t^n^r:1===e?t&n|~t&r:2===e?(t|~n)^r:3===e?t&r|n&~r:t^(n|~r)}const iy=new Uint32Array(16);class sy extends Pt{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:n,h3:r,h4:o}=this;return[e,t,n,r,o]}set(e,t,n,r,o){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|o}process(e,t){for(let n=0;n<16;n++,t+=4)iy[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,o=0|this.h1,i=o,s=0|this.h2,a=s,c=0|this.h3,u=c,l=0|this.h4,f=l;for(let e=0;e<5;e++){const t=4-e,h=ty[e],d=ny[e],p=Qg[e],g=Zg[e],y=Xg[e],m=ey[e];for(let t=0;t<16;t++){const r=ry(n+oy(e,o,s,c)+iy[p[t]]+h,y[t])+l|0;n=l,l=c,c=0|ry(s,10),s=o,o=r}for(let e=0;e<16;e++){const n=ry(r+oy(t,i,a,u)+iy[g[e]]+d,m[e])+f|0;r=f,f=u,u=0|ry(a,10),a=i,i=n}}this.set(this.h1+s+u|0,this.h2+c+f|0,this.h3+l+r|0,this.h4+n+i|0,this.h0+o+a|0)}roundClean(){iy.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const ay=At(()=>new sy);let cy=!1;const uy=function(e){return ay(e)};let ly=uy;function fy(e){const t=Ve(e,"data");return Qe(ly(t))}fy._=uy,fy.lock=function(){cy=!0},fy.register=function(e){if(cy)throw new TypeError("ripemd160 is locked");ly=e},Object.freeze(fy);let hy=!1;const dy=function(e){return new Uint8Array(function(e){_e(null!=Zt,"platform does not support secure random numbers","UNSUPPORTED_OPERATION",{operation:"randomBytes"}),Me(Number.isInteger(e)&&e>0&&e<=1024,"invalid length","length",e);const t=new Uint8Array(e);return Zt.getRandomValues(t),t}(e))};let py=dy;function gy(e){return py(e)}gy._=dy,gy.lock=function(){hy=!0},gy.register=function(e){if(hy)throw new Error("randomBytes is locked");py=e},Object.freeze(gy);const yy=/^[a-z]*$/i;function my(e,t){let n=97;return e.reduce((e,r)=>(r===t?n++:r.match(yy)?e.push(String.fromCharCode(n)+r):(n=97,e.push(r)),e),[])}class wy{locale;constructor(e){Re(this,{locale:e})}split(e){return e.toLowerCase().split(/\s+/g)}join(e){return e.join(" ")}}class by extends wy{#t;#mt;constructor(e,t,n){super(e),this.#t=t,this.#mt=n,this.#wt=null}get _data(){return this.#t}_decodeWords(){return Me("0"===(e=this.#t)[0],"unsupported auwl data","data",e),function(e,t){for(let n=28;n>=0;n--)e=e.split(" !#$%&'()*+,-./<=>?@[]^_`{|}~"[n]).join(t.substring(2*n,2*n+2));const n=[],r=e.replace(/(:|([0-9])|([A-Z][a-z]*))/g,(e,t,r,o)=>{if(r)for(let e=parseInt(r);e>=0;e--)n.push(";");else n.push(t.toLowerCase());return""});if(r)throw new Error(`leftovers: ${JSON.stringify(r)}`);return my(my(n,";"),":")}(e.substring(59),e.substring(1,59));var e}#wt;#bt(){if(null==this.#wt){const e=this._decodeWords();if(Zc(e.join("\n")+"\n")!==this.#mt)throw new Error(`BIP39 Wordlist for ${this.locale} FAILED`);this.#wt=e}return this.#wt}getWord(e){const t=this.#bt();return Me(e>=0&&e<t.length,`invalid word index: ${e}`,"index",e),t[e]}getWordIndex(e){return this.#bt().indexOf(e)}}let vy=null;class Ey extends by{constructor(){super("en","0erleonalorenseinceregesticitStanvetearctssi#ch2Athck&tneLl0And#Il.yLeOutO=S|S%b/ra@SurdU'0Ce[Cid|CountCu'Hie=IdOu,-Qui*Ro[TT]T%T*[Tu$0AptDD-tD*[Ju,M.UltV<)Vi)0Rob-0FairF%dRaid0A(EEntRee0Ead0MRRp%tS!_rmBumCoholErtI&LLeyLowMo,O}PhaReadySoT Ways0A>urAz(gOngOuntU'd0Aly,Ch%Ci|G G!GryIm$K!Noun)Nu$O` Sw T&naTiqueXietyY1ArtOlogyPe?P!Pro=Ril1ChCt-EaEnaGueMMedM%MyOundR<+Re,Ri=RowTTefa@Ti,Tw%k0KPe@SaultSetSi,SumeThma0H!>OmTa{T&dT.udeTra@0Ct]D.Gu,NtTh%ToTumn0Era+OcadoOid0AkeA*AyEsomeFulKw?d0Is:ByChel%C#D+GL<)Lc#y~MbooN<aNn RRelyRga(R*lSeS-SketTt!3A^AnAutyCau'ComeEfF%eG(Ha=H(dLie=LowLtN^Nef./TrayTt Twe&Y#d3Cyc!DKeNdOlogyRdR`Tt _{AdeAmeAnketA,EakE[IndOodO[omOu'UeUrUsh_rdAtDyIlMbNeNusOkO,Rd R(gRrowSsTtomUn)XY_{etA(AndA[A=EadEezeI{Id+IefIghtIngIskOccoliOk&OnzeOomO` OwnUsh2Bb!DdyD+tFf$oIldLbLkL!tNd!Nk Rd&Rg R,SS(e[SyTt Y Zz:Bba+B(B!CtusGeKe~LmM aMpNN$N)lNdyNn#NoeNvasNy#Pab!P.$Pta(RRb#RdRgoRpetRryRtSeShS(o/!Su$TT$ogT^Teg%yTt!UghtU'Ut]Ve3Il(gL yM|NsusNturyRe$Rta(_irAlkAmp]An+AosApt Ar+A'AtEapE{Ee'EfErryE,I{&IefIldIm}yOi)Oo'R#-U{!UnkUrn0G?Nnam#Rc!Tiz&TyVil_imApArifyAwAyE<ErkEv I{I|IffImbIn-IpO{OgO'O`OudOwnUbUmpU, Ut^_^A,C#utDeFfeeIlInL!@L%LumnMb(eMeMf%tM-Mm#Mp<yNc tNdu@NfirmNg*[N}@Nsid NtrolNv()OkOlPp PyR$ReRnR*@/Tt#U^UntryUp!Ur'Us(V Yo>_{Ad!AftAmA}AshAt AwlAzyEamEd.EekEwI{etImeIspIt-OpO[Ou^OwdUci$UelUi'Umb!Un^UshYY,$2BeLtu*PPbo?dRiousRr|Rta(R=Sh]/omTe3C!:DMa+MpN)Ng R(gShUght WnY3AlBa>BrisCadeCemb CideCl(eC%a>C*a'ErF&'F(eFyG*eLayLiv M<dMi'Ni$Nti,NyP?tP&dPos.P`PutyRi=ScribeS tSignSkSpair/royTailTe@VelopVi)Vo>3AgramAlAm#dAryCeE'lEtFf G.$Gn.yLemmaNn NosaurRe@RtSag*eScov Sea'ShSmi[S%d Splay/<)V tVideV%)Zzy5Ct%Cum|G~Lph(Ma(Na>NkeyN%OrSeUb!Ve_ftAg#AmaA,-AwEamE[IftIllInkIpI=OpUmY2CkMbNeR(g/T^Ty1Arf1Nam-:G G!RlyRnR`Sily/Sy1HoOlogyOnomy0GeItUca>1F%t0G1GhtTh 2BowD E@r-Eg<tEm|Eph<tEvat%I>Se0B?kBodyBra)Er+Ot]PloyPow Pty0Ab!A@DD![D%'EmyErgyF%)Ga+G(eH<)JoyLi,OughR-hRollSu*T Ti*TryVelope1Isode0U$Uip0AA'OdeOs]R%Upt0CapeSayS&)Ta>0Ern$H-s1Id&)IlOkeOl=1A@Amp!Ce[Ch<+C.eCludeCu'Ecu>Erci'Hau,Hib.I!I,ItOt-P<dPe@Pi*Pla(Po'P*[T&dTra0EEbrow:Br-CeCultyDeIntI`~L'MeMilyMousNNcyNtasyRmSh]TT$Th TigueUltV%.e3Atu*Bru?yD $EEdElMa!N)/iv$T^V W3B Ct]EldGu*LeLmLt N$NdNeNg NishReRmR,Sc$ShTT}[X_gAmeAshAtAv%EeIghtIpOatO{O%Ow UidUshY_mCusGIlLd~owOdOtR)Re,R+tRkRtu}RumRw?dSsil/ UndX_gi!AmeEqu|EshI&dIn+OgOntO,OwnOz&U.2ElNNnyRna)RyTu*:D+tInLaxy~ yMePRa+Rba+Rd&Rl-Rm|SSpTeTh U+Ze3N $NiusN*Nt!Nu(e/u*2O,0AntFtGg!Ng RaffeRlVe_dAn)A*A[IdeImp'ObeOomOryO=OwUe_tDde[LdOdO'RillaSpelSsipV nWn_bA)A(AntApeA[Av.yEatE&IdIefItOc yOupOwUnt_rdE[IdeIltIt?N3M:B.IrLfMm M, NdPpyRb%RdRshR=,TVeWkZ?d3AdAl`ArtAvyD+hogIght~oLmetLpNRo3Dd&Gh~NtPRe/%y5BbyCkeyLdLeLiday~owMeNeyOdPeRnRr%R'Sp.$/TelUrV 5BGeM<Mb!M%Nd*dNgryNtRd!RryRtSb<d3Brid:1EOn0EaEntifyLe2N%e4LLeg$L}[0A+Ita>M&'Mu}Pa@Po'Pro=Pul'0ChCludeComeC*a'DexD-a>Do%Du,ryF<tFl-tF%mHa!H .Iti$Je@JuryMa>N Noc|PutQuiryS<eSe@SideSpi*/$lTa@T e,ToVe,V.eVol=3On0L<dOla>Sue0Em1Ory:CketGu?RZz3AlousAns~yWel9BInKeUr}yY5D+I)MpNg!Ni%Nk/:Ng?oo3EnEpT^upY3CkDD}yNdNgdomSsTT^&TeTt&Wi4EeIfeO{Ow:BBelB%Dd DyKeMpNgua+PtopR+T T(UghUndryVaWWnWsu.Y Zy3Ad AfArnA=Ctu*FtGG$G&dIsu*M#NdNg`NsOp?dSs#Tt Vel3ArB tyBr?yC&'FeFtGhtKeMbM.NkOnQuid/Tt!VeZ?d5AdAnB, C$CkG-NelyNgOpTt yUdUn+VeY$5CkyGga+Mb N?N^Xury3R-s:Ch(eDG-G}tIdIlInJ%KeMm$NNa+Nda>NgoNs]Nu$P!Rb!R^Rg(R(eRketRria+SkSs/ T^T i$ThTrixTt XimumZe3AdowAnAsu*AtCh<-D$DiaLodyLtMb M%yNt]NuRcyR+R.RryShSsa+T$Thod3Dd!DnightLk~]M-NdNimumN%Nu>Rac!Rr%S ySs/akeXXedXtu*5Bi!DelDifyMM|N.%NkeyN, N`OnR$ReRn(gSqu.oTh T]T%Unta(U'VeVie5ChFf(LeLtiplySc!SeumShroomS-/Tu$3Self/ yTh:I=MePk(Rrow/yT]Tu*3ArCkEdGati=G!@I` PhewR=/TTw%kUtr$V WsXt3CeGht5B!I'M(eeOd!Rm$R`SeTab!TeTh(gTi)VelW5C!?Mb R'T:K0EyJe@Li+Scu*S =Ta(Vious0CurE<Tob 0Or1FF Fi)T&2L1Ay0DI=Ymp-0It0CeEI#L(eLy1EnEraIn]Po'T]1An+B.Ch?dD D(?yG<I|Ig($Ph<0Tr-h0H 0Tdo%T TputTside0AlEnEr0NN 0Yg&0/ 0O}:CtDd!GeIrLa)LmNdaNelN-N` P RadeR|RkRrotRtySsT^ThTi|TrolTt nU'VeYm|3A)AnutArAs<tL-<NN$tyNcilOp!Pp Rfe@Rm.Rs#T2O}OtoRa'Ys-$0AnoCn-Ctu*E)GGe#~LotNkO} Pe/olT^Zza_)A}tA,-A>AyEa'Ed+U{UgUn+2EmEtIntL?LeLi)NdNyOlPul?Rt]S.]Ssib!/TatoTt yV tyWd W _@i)Ai'Ed-tEf Epa*Es|EttyEv|I)IdeIm?yIntI%.yIs#Iva>IzeOb!mO)[Odu)Of.OgramOje@Omo>OofOp tyOsp O>@OudOvide2Bl-Dd(g~LpL'Mpk(N^PilPpyR^a'R.yRpo'R'ShTZz!3Ramid:99Al.yAntumArt E,]I{ItIzO>:Bb.Cco#CeCkD?DioIlInI'~yMpN^NdomN+PidReTeTh V&WZ%3AdyAlAs#BelBuildC$lCei=CipeC%dCyc!Du)F!@F%mFu'G]G*tGul?Je@LaxLea'LiefLyMa(Memb M(dMo=Nd NewNtOp&PairPeatPla)P%tQui*ScueSemb!Si,Sour)Sp#'SultTi*T*atTurnUn]Ve$ViewW?d2Y`m0BBb#CeChDeD+F!GhtGidNgOtPp!SkTu$V$V 5AdA,BotBu,CketM<)OfOkieOmSeTa>UghUndU>Y$5Bb DeGLeNNwayR$:DDd!D}[FeIlLadLm#L#LtLu>MeMp!NdTisfyToshiU)Usa+VeY1A!AnA*Att E}HemeHoolI&)I[%sOrp]OutRapRe&RiptRub1AAr^As#AtC#dC*tCt]Cur.yEdEkGm|Le@~M(?Ni%N'Nt&)RiesRvi)Ss]Tt!TupV&_dowAftAllowA*EdEllEriffIeldIftI}IpIv O{OeOotOpOrtOuld O=RimpRugUff!Y0Bl(gCkDeE+GhtGnL|Lk~yLv Mil?Mp!N)NgR&/ Tua>XZe1A>Et^IIllInIrtUll0AbAmEepEnd I)IdeIghtImOg<OtOwUsh0AllArtI!OkeOo`0A{AkeApIffOw0ApCc Ci$CkDaFtL?Ldi LidLut]L=Me#eNgOnRryRtUlUndUpUr)U`0A)A*Ati$AwnEakEci$EedEllEndH eI)Id IkeInIr.L.OilOns%O#OrtOtRayReadR(gY0Ua*UeezeUir*l_b!AdiumAffA+AirsAmpAndArtA>AyEakEelEmEpE*oI{IllIngO{Oma^O}OolOryO=Ra>gyReetRikeR#gRugg!Ud|UffUmb!Y!0Bje@Bm.BwayC)[ChDd&Ff G?G+,ItMm NNnyN'tP PplyP*meReRfa)R+Rpri'RroundR=ySpe@/a(1AllowAmpApArmE?EetIftImIngIt^Ord1MbolMptomRup/em:B!Ck!GIlL|LkNkPeR+tSk/eTtooXi3A^Am~NN<tNnisNtRm/Xt_nkAtEmeEnE%yE*EyIngIsOughtReeRi=RowUmbUnd 0CketDeG LtMb MeNyPRedSsueT!5A,BaccoDayDdl EGe` I!tK&MatoM%rowNeNgueNightOlO`PP-Pp!R^RnadoRtoi'SsT$Uri,W?dW WnY_{AdeAff-Ag-A(Ansf ApAshA=lAyEatEeEndI$IbeI{Igg ImIpOphyOub!U{UeUlyUmpetU,U`Y2BeIt]Mb!NaN}lRkeyRnRt!1El=EntyI)InI,O1PeP-$:5Ly5B*lla0Ab!Awa*C!Cov D DoFairFoldHappyIf%mIqueItIv 'KnownLo{TilUsu$Veil1Da>GradeHoldOnP Set1B<Ge0A+EEdEfulE![U$0Il.y:C<tCuumGueLidL!yL=NNishP%Rious/Ult3H-!L=tNd%Ntu*NueRbRifyRs]RyS'lT <3Ab!Br<tCiousCt%yDeoEw~a+Nta+Ol(Rtu$RusSaS.Su$T$Vid5C$I)IdLc<oLumeTeYa+:GeG#ItLk~LnutNtRfa*RmRri%ShSp/eT VeY3Al`Ap#ArA'lA` BDd(gEk&dIrdLcome/T_!AtEatEelEnE*IpIsp 0DeD`FeLd~NNdowNeNgNkNn Nt ReSdomSeShT}[5LfM<Nd OdOlRdRkRldRryR`_pE{E,!I,I>Ong::Rd3Ar~ow9UUngU`:3BraRo9NeO","0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60")}static wordlist(){return null==vy&&(vy=new Ey),vy}}let Ay=!1;const xy=function(e,t,n,r,o){return function(e,t,n,r,o){const i={sha256:Ut,sha512:Jt}[o];return Me(null!=i,"invalid pbkdf2 algorithm","algorithm",o),It(i,e,t,{c:n,dkLen:r})}(e,t,n,r,o)};let ky=xy;function Sy(e,t,n,r,o){const i=Ve(e,"password"),s=Ve(t,"salt");return Qe(ky(i,s,n,r,o))}function Iy(e){return(1<<e)-1<<8-e&255}function Py(e){return(1<<e)-1&255}function Cy(e,t){He("NFKD"),null==t&&(t=Ey.wordlist());const n=t.split(e);Me(n.length%3==0&&n.length>=12&&n.length<=24,"invalid mnemonic length","mnemonic","[ REDACTED ]");const r=new Uint8Array(Math.ceil(11*n.length/8));let o=0;for(let e=0;e<n.length;e++){let i=t.getWordIndex(n[e].normalize("NFKD"));Me(i>=0,`invalid mnemonic word at index ${e}`,"mnemonic","[ REDACTED ]");for(let e=0;e<11;e++)i&1<<10-e&&(r[o>>3]|=1<<7-o%8),o++}const i=32*n.length/3,s=Iy(n.length/3);return Me((Ve(sn(r.slice(0,i/8)))[0]&s)===(r[r.length-1]&s),"invalid mnemonic checksum","mnemonic","[ REDACTED ]"),Qe(r.slice(0,i/8))}function Oy(e,t){Me(e.length%4==0&&e.length>=16&&e.length<=32,"invalid entropy size","entropy","[ REDACTED ]"),null==t&&(t=Ey.wordlist());const n=[0];let r=11;for(let t=0;t<e.length;t++)r>8?(n[n.length-1]<<=8,n[n.length-1]|=e[t],r-=8):(n[n.length-1]<<=r,n[n.length-1]|=e[t]>>8-r,n.push(e[t]&Py(8-r)),r+=3);const o=e.length/4,i=parseInt(sn(e).substring(2,4),16)&Iy(o);return n[n.length-1]<<=o,n[n.length-1]|=i>>8-o,t.join(n.map(e=>t.getWord(e)))}Sy._=xy,Sy.lock=function(){Ay=!0},Sy.register=function(e){if(Ay)throw new Error("pbkdf2 is locked");ky=e},Object.freeze(Sy);const Ny={};class By{phrase;password;wordlist;entropy;constructor(e,t,n,r,o){null==r&&(r=""),null==o&&(o=Ey.wordlist()),ze(e,Ny,"Mnemonic"),Re(this,{phrase:n,password:r,wordlist:o,entropy:t})}computeSeed(){const e=ot("mnemonic"+this.password,"NFKD");return Sy(ot(this.phrase,"NFKD"),e,2048,64,"sha512")}static fromPhrase(e,t,n){const r=Cy(e,n);return e=Oy(Ve(r),n),new By(Ny,r,e,t,n)}static fromEntropy(e,t,n){const r=Ve(e,"entropy"),o=Oy(r,n);return new By(Ny,Qe(r),o,t,n)}static entropyToPhrase(e,t){return Oy(Ve(e,"entropy"),t)}static phraseToEntropy(e,t){return Cy(e,t)}static isValidMnemonic(e,t){try{return Cy(e,t),!0}catch(e){}return!1}}var Ty,Ry,Uy,Dy=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)},Ly=function(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n};const Fy={16:10,24:12,32:14},_y=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],My=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],jy=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],Gy=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],Hy=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],zy=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],Ky=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],Vy=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],Wy=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],$y=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239e3,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],qy=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998e3,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],Jy=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],Qy=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],Zy=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239e3,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],Yy=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998e3,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function Xy(e){const t=[];for(let n=0;n<e.length;n+=4)t.push(e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3]);return t}class em{get key(){return Dy(this,Ty,"f").slice()}constructor(e){if(Ty.set(this,void 0),Ry.set(this,void 0),Uy.set(this,void 0),!(this instanceof em))throw Error("AES must be instanitated with `new`");Ly(this,Ty,new Uint8Array(e),"f");const t=Fy[this.key.length];if(null==t)throw new TypeError("invalid key size (must be 16, 24 or 32 bytes)");Ly(this,Uy,[],"f"),Ly(this,Ry,[],"f");for(let e=0;e<=t;e++)Dy(this,Uy,"f").push([0,0,0,0]),Dy(this,Ry,"f").push([0,0,0,0]);const n=4*(t+1),r=this.key.length/4,o=Xy(this.key);let i;for(let e=0;e<r;e++)i=e>>2,Dy(this,Uy,"f")[i][e%4]=o[e],Dy(this,Ry,"f")[t-i][e%4]=o[e];let s,a=0,c=r;for(;c<n;){if(s=o[r-1],o[0]^=My[s>>16&255]<<24^My[s>>8&255]<<16^My[255&s]<<8^My[s>>24&255]^_y[a]<<24,a+=1,8!=r)for(let e=1;e<r;e++)o[e]^=o[e-1];else{for(let e=1;e<r/2;e++)o[e]^=o[e-1];s=o[r/2-1],o[r/2]^=My[255&s]^My[s>>8&255]<<8^My[s>>16&255]<<16^My[s>>24&255]<<24;for(let e=r/2+1;e<r;e++)o[e]^=o[e-1]}let e,i,u=0;for(;u<r&&c<n;)e=c>>2,i=c%4,Dy(this,Uy,"f")[e][i]=o[u],Dy(this,Ry,"f")[t-e][i]=o[u++],c++}for(let e=1;e<t;e++)for(let t=0;t<4;t++)s=Dy(this,Ry,"f")[e][t],Dy(this,Ry,"f")[e][t]=Jy[s>>24&255]^Qy[s>>16&255]^Zy[s>>8&255]^Yy[255&s]}encrypt(e){if(16!=e.length)throw new TypeError("invalid plaintext size (must be 16 bytes)");const t=Dy(this,Uy,"f").length-1,n=[0,0,0,0];let r=Xy(e);for(let e=0;e<4;e++)r[e]^=Dy(this,Uy,"f")[0][e];for(let e=1;e<t;e++){for(let t=0;t<4;t++)n[t]=Gy[r[t]>>24&255]^Hy[r[(t+1)%4]>>16&255]^zy[r[(t+2)%4]>>8&255]^Ky[255&r[(t+3)%4]]^Dy(this,Uy,"f")[e][t];r=n.slice()}const o=new Uint8Array(16);let i=0;for(let e=0;e<4;e++)i=Dy(this,Uy,"f")[t][e],o[4*e]=255&(My[r[e]>>24&255]^i>>24),o[4*e+1]=255&(My[r[(e+1)%4]>>16&255]^i>>16),o[4*e+2]=255&(My[r[(e+2)%4]>>8&255]^i>>8),o[4*e+3]=255&(My[255&r[(e+3)%4]]^i);return o}decrypt(e){if(16!=e.length)throw new TypeError("invalid ciphertext size (must be 16 bytes)");const t=Dy(this,Ry,"f").length-1,n=[0,0,0,0];let r=Xy(e);for(let e=0;e<4;e++)r[e]^=Dy(this,Ry,"f")[0][e];for(let e=1;e<t;e++){for(let t=0;t<4;t++)n[t]=Vy[r[t]>>24&255]^Wy[r[(t+3)%4]>>16&255]^$y[r[(t+2)%4]>>8&255]^qy[255&r[(t+1)%4]]^Dy(this,Ry,"f")[e][t];r=n.slice()}const o=new Uint8Array(16);let i=0;for(let e=0;e<4;e++)i=Dy(this,Ry,"f")[t][e],o[4*e]=255&(jy[r[e]>>24&255]^i>>24),o[4*e+1]=255&(jy[r[(e+3)%4]>>16&255]^i>>16),o[4*e+2]=255&(jy[r[(e+2)%4]>>8&255]^i>>8),o[4*e+3]=255&(jy[255&r[(e+1)%4]]^i);return o}}Ty=new WeakMap,Ry=new WeakMap,Uy=new WeakMap;class tm{constructor(e,t,n){if(n&&!(this instanceof n))throw new Error(`${e} must be instantiated with "new"`);Object.defineProperties(this,{aes:{enumerable:!0,value:new em(t)},name:{enumerable:!0,value:e}})}}var nm,rm,om=function(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n},im=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class sm extends tm{constructor(e,t){if(super("ECC",e,sm),nm.set(this,void 0),rm.set(this,void 0),t){if(t.length%16)throw new TypeError("invalid iv size (must be 16 bytes)");om(this,nm,new Uint8Array(t),"f")}else om(this,nm,new Uint8Array(16),"f");om(this,rm,this.iv,"f")}get iv(){return new Uint8Array(im(this,nm,"f"))}encrypt(e){if(e.length%16)throw new TypeError("invalid plaintext size (must be multiple of 16 bytes)");const t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){for(let t=0;t<16;t++)im(this,rm,"f")[t]^=e[n+t];om(this,rm,this.aes.encrypt(im(this,rm,"f")),"f"),t.set(im(this,rm,"f"),n)}return t}decrypt(e){if(e.length%16)throw new TypeError("invalid ciphertext size (must be multiple of 16 bytes)");const t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){const r=this.aes.decrypt(e.subarray(n,n+16));for(let o=0;o<16;o++)t[n+o]=r[o]^im(this,rm,"f")[o],im(this,rm,"f")[o]=e[n+o]}return t}}nm=new WeakMap,rm=new WeakMap,new WeakMap,new WeakMap,new WeakSet;var am,cm,um,lm=function(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n},fm=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class hm extends tm{constructor(e,t){super("CTR",e,hm),am.set(this,void 0),cm.set(this,void 0),um.set(this,void 0),lm(this,um,new Uint8Array(16),"f"),fm(this,um,"f").fill(0),lm(this,am,fm(this,um,"f"),"f"),lm(this,cm,16,"f"),null==t&&(t=1),"number"==typeof t?this.setCounterValue(t):this.setCounterBytes(t)}get counter(){return new Uint8Array(fm(this,um,"f"))}setCounterValue(e){if(!Number.isInteger(e)||e<0||e>Number.MAX_SAFE_INTEGER)throw new TypeError("invalid counter initial integer value");for(let t=15;t>=0;--t)fm(this,um,"f")[t]=e%256,e=Math.floor(e/256)}setCounterBytes(e){if(16!==e.length)throw new TypeError("invalid counter initial Uint8Array value length");fm(this,um,"f").set(e)}increment(){for(let e=15;e>=0;e--){if(255!==fm(this,um,"f")[e]){fm(this,um,"f")[e]++;break}fm(this,um,"f")[e]=0}}encrypt(e){var t,n;const r=new Uint8Array(e);for(let e=0;e<r.length;e++)16===fm(this,cm,"f")&&(lm(this,am,this.aes.encrypt(fm(this,um,"f")),"f"),lm(this,cm,0,"f"),this.increment()),r[e]^=fm(this,am,"f")[(lm(this,cm,(n=fm(this,cm,"f"),t=n++,n),"f"),t)];return r}decrypt(e){return this.encrypt(e)}}am=new WeakMap,cm=new WeakMap,um=new WeakMap,new WeakMap,new WeakMap,new WeakMap;const dm=(e,t)=>e<<t|e>>>32-t;function pm(e,t,n,r,o,i){let s=e[t++]^n[r++],a=e[t++]^n[r++],c=e[t++]^n[r++],u=e[t++]^n[r++],l=e[t++]^n[r++],f=e[t++]^n[r++],h=e[t++]^n[r++],d=e[t++]^n[r++],p=e[t++]^n[r++],g=e[t++]^n[r++],y=e[t++]^n[r++],m=e[t++]^n[r++],w=e[t++]^n[r++],b=e[t++]^n[r++],v=e[t++]^n[r++],E=e[t++]^n[r++],A=s,x=a,k=c,S=u,I=l,P=f,C=h,O=d,N=p,B=g,T=y,R=m,U=w,D=b,L=v,F=E;for(let e=0;e<8;e+=2)I^=dm(A+U|0,7),N^=dm(I+A|0,9),U^=dm(N+I|0,13),A^=dm(U+N|0,18),B^=dm(P+x|0,7),D^=dm(B+P|0,9),x^=dm(D+B|0,13),P^=dm(x+D|0,18),L^=dm(T+C|0,7),k^=dm(L+T|0,9),C^=dm(k+L|0,13),T^=dm(C+k|0,18),S^=dm(F+R|0,7),O^=dm(S+F|0,9),R^=dm(O+S|0,13),F^=dm(R+O|0,18),x^=dm(A+S|0,7),k^=dm(x+A|0,9),S^=dm(k+x|0,13),A^=dm(S+k|0,18),C^=dm(P+I|0,7),O^=dm(C+P|0,9),I^=dm(O+C|0,13),P^=dm(I+O|0,18),R^=dm(T+B|0,7),N^=dm(R+T|0,9),B^=dm(N+R|0,13),T^=dm(B+N|0,18),U^=dm(F+L|0,7),D^=dm(U+F|0,9),L^=dm(D+U|0,13),F^=dm(L+D|0,18);o[i++]=s+A|0,o[i++]=a+x|0,o[i++]=c+k|0,o[i++]=u+S|0,o[i++]=l+I|0,o[i++]=f+P|0,o[i++]=h+C|0,o[i++]=d+O|0,o[i++]=p+N|0,o[i++]=g+B|0,o[i++]=y+T|0,o[i++]=m+R|0,o[i++]=w+U|0,o[i++]=b+D|0,o[i++]=v+L|0,o[i++]=E+F|0}function gm(e,t,n,r,o){let i=r+0,s=r+16*o;for(let r=0;r<16;r++)n[s+r]=e[t+16*(2*o-1)+r];for(let r=0;r<o;r++,i+=16,t+=16)pm(n,s,e,t,n,i),r>0&&(s+=16),pm(n,i,e,t+=16,n,s)}function ym(e,t,n){const r=Et({dkLen:32,asyncTick:10,maxmem:1073742848},n),{N:o,r:i,p:s,dkLen:a,asyncTick:c,maxmem:u,onProgress:l}=r;if(st(o),st(i),st(s),st(a),st(c),st(u),void 0!==l&&"function"!=typeof l)throw new Error("progressCb should be function");const f=128*i,h=f/4;if(o<=1||o&o-1||o>=2**(f/8)||o>2**32)throw new Error("Scrypt: N must be larger than 1, a power of 2, less than 2^(128 * r / 8) and less than 2^32");if(s<0||s>137438953440/f)throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(a<0||a>137438953440)throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");const d=f*(o+s);if(d>u)throw new Error(`Scrypt: parameters too large, ${d} (128 * r * (N + p)) > ${u} (maxmem)`);const p=It(Ut,e,t,{c:1,dkLen:f*s}),g=dt(p),y=dt(new Uint8Array(f*o)),m=dt(new Uint8Array(f));let w=()=>{};if(l){const e=2*o*s,t=Math.max(Math.floor(e/1e4),1);let n=0;w=()=>{n++,!l||n%t&&n!==e||l(n/e)}}return{N:o,r:i,p:s,dkLen:a,blockSize32:h,V:y,B32:g,B:p,tmp:m,blockMixCb:w,asyncTick:c}}function mm(e,t,n,r,o){const i=It(Ut,e,n,{c:1,dkLen:t});return n.fill(0),r.fill(0),o.fill(0),i}let wm=!1,bm=!1;const vm=async function(e,t,n,r,o,i,s){return await async function(e,t,n){const{N:r,r:o,p:i,dkLen:s,blockSize32:a,V:c,B32:u,B:l,tmp:f,blockMixCb:h,asyncTick:d}=ym(e,t,n);for(let e=0;e<i;e++){const t=a*e;for(let e=0;e<a;e++)c[e]=u[t+e];let n=0;await mt(r-1,d,()=>{gm(c,n,c,n+=a,o),h()}),gm(c,(r-1)*a,u,t,o),h(),await mt(r,d,()=>{const e=u[t+a-16]%r;for(let n=0;n<a;n++)f[n]=u[t+n]^c[e*a+n];gm(f,0,u,t,o),h()})}return mm(e,s,l,c,f)}(e,t,{N:n,r,p:o,dkLen:i,onProgress:s})},Em=function(e,t,n,r,o,i){return function(e,t,n){const{N:r,r:o,p:i,dkLen:s,blockSize32:a,V:c,B32:u,B:l,tmp:f,blockMixCb:h}=ym(e,t,n);for(let e=0;e<i;e++){const t=a*e;for(let e=0;e<a;e++)c[e]=u[t+e];for(let e=0,t=0;e<r-1;e++)gm(c,t,c,t+=a,o),h();gm(c,(r-1)*a,u,t,o),h();for(let e=0;e<r;e++){const e=u[t+a-16]%r;for(let n=0;n<a;n++)f[n]=u[t+n]^c[e*a+n];gm(f,0,u,t,o),h()}}return mm(e,s,l,c,f)}(e,t,{N:n,r,p:o,dkLen:i})};let Am=vm,xm=Em;async function km(e,t,n,r,o,i,s){const a=Ve(e,"passwd"),c=Ve(t,"salt");return Qe(await Am(a,c,n,r,o,i,s))}function Sm(e,t,n,r,o,i){const s=Ve(e,"passwd"),a=Ve(t,"salt");return Qe(xm(s,a,n,r,o,i))}function Im(e){const t=Ve(e,"randomBytes");t[6]=15&t[6]|64,t[8]=63&t[8]|128;const n=Qe(t);return[n.substring(2,10),n.substring(10,14),n.substring(14,18),n.substring(18,22),n.substring(22,34)].join("-")}function Pm(e){return"string"!=typeof e||e.startsWith("0x")||(e="0x"+e),We(e)}function Cm(e,t){for(e=String(e);e.length<t;)e="0"+e;return e}function Om(e){return"string"==typeof e?ot(e,"NFKC"):We(e)}function Nm(e,t){const n=t.match(/^([a-z0-9$_.-]*)(:([a-z]+))?(!)?$/i);Me(null!=n,"invalid path","path",t);const r=n[1],o=n[3],i="!"===n[4];let s=e;for(const e of r.toLowerCase().split(".")){if(Array.isArray(s)){if(!e.match(/^[0-9]+$/))break;s=s[parseInt(e)]}else if("object"==typeof s){let t=null;for(const n in s)if(n.toLowerCase()===e){t=s[n];break}s=t}else s=null;if(null==s)break}if(Me(!i||null!=s,"missing required value","path",r),o&&null!=s){if("int"===o){if("string"==typeof s&&s.match(/^-?[0-9]+$/))return parseInt(s);if(Number.isSafeInteger(s))return s}if("number"===o&&"string"==typeof s&&s.match(/^-?[0-9.]*$/))return parseFloat(s);if("data"===o&&"string"==typeof s)return Pm(s);if("array"===o&&Array.isArray(s))return s;if(o===typeof s)return s;Me(!1,`wrong type found for ${o} `,"path",r)}return s}km._=vm,km.lock=function(){bm=!0},km.register=function(e){if(bm)throw new Error("scrypt is locked");Am=e},Object.freeze(km),Sm._=Em,Sm.lock=function(){wm=!0},Sm.register=function(e){if(wm)throw new Error("scryptSync is locked");xm=e},Object.freeze(Sm);const Bm="m/44'/60'/0'/0/0";function Tm(e){try{const t=JSON.parse(e);if(3===(null!=t.version?parseInt(t.version):0))return!0}catch(e){}return!1}function Rm(e,t){const n=Ve(t),r=Nm(e,"crypto.ciphertext:data!");Me(Qe(In(Ze([n.slice(16,32),r]))).substring(2)===Nm(e,"crypto.mac:string!").toLowerCase(),"incorrect password","password","[ REDACTED ]");const o=function(e,t,n){if("aes-128-ctr"===Nm(e,"crypto.cipher:string")){const r=Nm(e,"crypto.cipherparams.iv:data!");return Qe(new hm(t,r).decrypt(n))}_e(!1,"unsupported cipher","UNSUPPORTED_OPERATION",{operation:"decrypt"})}(e,n.slice(0,16),r),i=Yd(o);if(e.address){let t=e.address.toLowerCase();t.startsWith("0x")||(t="0x"+t),Me(Cc(t)===i,"keystore address/privateKey mismatch","address",e.address)}const s={address:i,privateKey:o};if("0.1"===Nm(e,"x-ethers.version:string")){const t=n.slice(32,64),r=Nm(e,"x-ethers.mnemonicCiphertext:data!"),o=Nm(e,"x-ethers.mnemonicCounter:data!"),i=new hm(t,o);s.mnemonic={path:Nm(e,"x-ethers.path:string")||Bm,locale:Nm(e,"x-ethers.locale:string")||"en",entropy:Qe(Ve(i.decrypt(r)))}}return s}function Um(e){const t=Nm(e,"crypto.kdf:string");if(t&&"string"==typeof t){if("scrypt"===t.toLowerCase()){const n=Nm(e,"crypto.kdfparams.salt:data!"),r=Nm(e,"crypto.kdfparams.n:int!"),o=Nm(e,"crypto.kdfparams.r:int!"),i=Nm(e,"crypto.kdfparams.p:int!");Me(r>0&&!(r&r-1),"invalid kdf.N","kdf.N",r),Me(o>0&&i>0,"invalid kdf","kdf",t);const s=Nm(e,"crypto.kdfparams.dklen:int!");return Me(32===s,"invalid kdf.dklen","kdf.dflen",s),{name:"scrypt",salt:n,N:r,r:o,p:i,dkLen:64}}if("pbkdf2"===t.toLowerCase()){const t=Nm(e,"crypto.kdfparams.salt:data!"),n=Nm(e,"crypto.kdfparams.prf:string!"),r=n.split("-").pop();Me("sha256"===r||"sha512"===r,"invalid kdf.pdf","kdf.pdf",n);const o=Nm(e,"crypto.kdfparams.c:int!"),i=Nm(e,"crypto.kdfparams.dklen:int!");return Me(32===i,"invalid kdf.dklen","kdf.dklen",i),{name:"pbkdf2",salt:t,count:o,dkLen:i,algorithm:r}}}Me(!1,"unsupported key-derivation function","kdf",t)}function Dm(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function Lm(e){const t=null!=e.salt?Ve(e.salt,"options.salt"):gy(32);let n=1<<17,r=8,o=1;return e.scrypt&&(e.scrypt.N&&(n=e.scrypt.N),e.scrypt.r&&(r=e.scrypt.r),e.scrypt.p&&(o=e.scrypt.p)),Me("number"==typeof n&&n>0&&Number.isSafeInteger(n)&&(BigInt(n)&BigInt(n-1))===BigInt(0),"invalid scrypt N parameter","options.N",n),Me("number"==typeof r&&r>0&&Number.isSafeInteger(r),"invalid scrypt r parameter","options.r",r),Me("number"==typeof o&&o>0&&Number.isSafeInteger(o),"invalid scrypt p parameter","options.p",o),{name:"scrypt",dkLen:32,salt:t,N:n,r,p:o}}function Fm(e,t,n,r){const o=Ve(n.privateKey,"privateKey"),i=null!=r.iv?Ve(r.iv,"options.iv"):gy(16);Me(16===i.length,"invalid options.iv length","options.iv",r.iv);const s=null!=r.uuid?Ve(r.uuid,"options.uuid"):gy(16);Me(16===s.length,"invalid options.uuid length","options.uuid",r.iv);const a=e.slice(0,16),c=e.slice(16,32),u=Ve(new hm(a,i).encrypt(o)),l=In(Ze([c,u])),f={address:n.address.substring(2).toLowerCase(),id:Im(s),version:3,Crypto:{cipher:"aes-128-ctr",cipherparams:{iv:Qe(i).substring(2)},ciphertext:Qe(u).substring(2),kdf:"scrypt",kdfparams:{salt:Qe(t.salt).substring(2),n:t.N,dklen:32,p:t.p,r:t.r},mac:l.substring(2)}};if(n.mnemonic){const t=null!=r.client?r.client:`ethers/${Ne}`,o=n.mnemonic.path||Bm,i=n.mnemonic.locale||"en",s=e.slice(32,64),a=Ve(n.mnemonic.entropy,"account.mnemonic.entropy"),c=gy(16),u=Ve(new hm(s,c).encrypt(a)),l=new Date,h="UTC--"+l.getUTCFullYear()+"-"+Cm(l.getUTCMonth()+1,2)+"-"+Cm(l.getUTCDate(),2)+"T"+Cm(l.getUTCHours(),2)+"-"+Cm(l.getUTCMinutes(),2)+"-"+Cm(l.getUTCSeconds(),2)+".0Z--"+f.address;f["x-ethers"]={client:t,gethFilename:h,path:o,locale:i,mnemonicCounter:Qe(c).substring(2),mnemonicCiphertext:Qe(u).substring(2),version:"0.1"}}return JSON.stringify(f)}function _m(e,t,n){null==n&&(n={});const r=Om(t),o=Lm(n);return Fm(Ve(Sm(r,o.salt,o.N,o.r,o.p,64)),o,e,n)}async function Mm(e,t,n){null==n&&(n={});const r=Om(t),o=Lm(n);return Fm(Ve(await km(r,o.salt,o.N,o.r,o.p,64,n.progressCallback)),o,e,n)}const jm="m/44'/60'/0'/0/0",Gm=new Uint8Array([66,105,116,99,111,105,110,32,115,101,101,100]),Hm=2147483648,zm=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");function Km(e,t){let n="";for(;e;)n="0123456789abcdef"[e%16]+n,e=Math.trunc(e/16);for(;n.length<2*t;)n="0"+n;return"0x"+n}function Vm(e){const t=Ve(e);return Sp(Ze([t,Xe(sn(sn(t)),0,4)]))}const Wm={};function $m(e,t,n,r){const o=new Uint8Array(37);e&Hm?(_e(null!=r,"cannot derive child of neutered node","UNSUPPORTED_OPERATION",{operation:"deriveChild"}),o.set(Ve(r),1)):o.set(Ve(n));for(let t=24;t>=0;t-=8)o[33+(t>>3)]=e>>24-t&255;const i=Ve(Wg("sha512",t,o));return{IL:i.slice(0,32),IR:i.slice(32)}}function qm(e,t){const n=t.split("/");Me(n.length>0,"invalid path","path",t),"m"===n[0]&&(Me(0===e.depth,`cannot derive root path (i.e. path starting with "m/") for a node at non-zero depth ${e.depth}`,"path",t),n.shift());let r=e;for(let e=0;e<n.length;e++){const t=n[e];if(t.match(/^[0-9]+'$/)){const n=parseInt(t.substring(0,t.length-1));Me(n<Hm,"invalid path index",`path[${e}]`,t),r=r.deriveChild(Hm+n)}else if(t.match(/^[0-9]+$/)){const n=parseInt(t);Me(n<Hm,"invalid path index",`path[${e}]`,t),r=r.deriveChild(n)}else Me(!1,"invalid path component",`path[${e}]`,t)}return r}class Jm extends Hg{publicKey;fingerprint;parentFingerprint;mnemonic;chainCode;path;index;depth;constructor(e,t,n,r,o,i,s,a,c){super(t,c),ze(e,Wm,"HDNodeWallet"),Re(this,{publicKey:t.compressedPublicKey}),Re(this,{parentFingerprint:n,fingerprint:Xe(fy(sn(this.publicKey)),0,4),chainCode:r,path:o,index:i,depth:s}),Re(this,{mnemonic:a})}connect(e){return new Jm(Wm,this.signingKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.mnemonic,e)}#vt(){const e={address:this.address,privateKey:this.privateKey},t=this.mnemonic;return this.path&&t&&"en"===t.wordlist.locale&&""===t.password&&(e.mnemonic={path:this.path,locale:"en",entropy:t.entropy}),e}async encrypt(e,t){return await Mm(this.#vt(),e,{progressCallback:t})}encryptSync(e){return _m(this.#vt(),e)}get extendedKey(){return _e(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),Vm(Ze(["0x0488ADE4",Km(this.depth,1),this.parentFingerprint,Km(this.index,4),this.chainCode,Ze(["0x00",this.privateKey])]))}hasPath(){return null!=this.path}neuter(){return new Qm(Wm,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.provider)}deriveChild(e){const t=ic(e,"index");Me(t<=4294967295,"invalid index","index",t);let n=this.path;n&&(n+="/"+(2147483647&t),t&Hm&&(n+="'"));const{IR:r,IL:o}=$m(t,this.chainCode,this.publicKey,this.privateKey),i=new Hd(sc((oc(o)+BigInt(this.privateKey))%zm,32));return new Jm(Wm,i,this.fingerprint,Qe(r),n,t,this.depth+1,this.mnemonic,this.provider)}derivePath(e){return qm(this,e)}static#Et(e,t){Me(qe(e),"invalid seed","seed","[REDACTED]");const n=Ve(e,"seed");Me(n.length>=16&&n.length<=64,"invalid seed","seed","[REDACTED]");const r=Ve(Wg("sha512",Gm,n)),o=new Hd(Qe(r.slice(0,32)));return new Jm(Wm,o,"0x00000000",Qe(r.slice(32)),"m",0,0,t,null)}static fromExtendedKey(e){const t=ac(function(e){let t=xp;for(let n=0;n<e.length;n++)t*=kp,t+=Ap(e[n]);return t}(e));Me(82===t.length||Vm(t.slice(0,78))===e,"invalid extended key","extendedKey","[ REDACTED ]");const n=t[4],r=Qe(t.slice(5,9)),o=parseInt(Qe(t.slice(9,13)).substring(2),16),i=Qe(t.slice(13,45)),s=t.slice(45,78);switch(Qe(t.slice(0,4))){case"0x0488b21e":case"0x043587cf":{const e=Qe(s);return new Qm(Wm,Yd(e),e,r,i,null,o,n,null)}case"0x0488ade4":case"0x04358394 ":if(0!==s[0])break;return new Jm(Wm,new Hd(s.slice(1)),r,i,null,o,n,null,null)}Me(!1,"invalid extended key prefix","extendedKey","[ REDACTED ]")}static createRandom(e,t,n){null==e&&(e=""),null==t&&(t=jm),null==n&&(n=Ey.wordlist());const r=By.fromEntropy(gy(16),e,n);return Jm.#Et(r.computeSeed(),r).derivePath(t)}static fromMnemonic(e,t){return t||(t=jm),Jm.#Et(e.computeSeed(),e).derivePath(t)}static fromPhrase(e,t,n,r){null==t&&(t=""),null==n&&(n=jm),null==r&&(r=Ey.wordlist());const o=By.fromPhrase(e,t,r);return Jm.#Et(o.computeSeed(),o).derivePath(n)}static fromSeed(e){return Jm.#Et(e,null)}}class Qm extends xg{publicKey;fingerprint;parentFingerprint;chainCode;path;index;depth;constructor(e,t,n,r,o,i,s,a,c){super(t,c),ze(e,Wm,"HDNodeVoidWallet"),Re(this,{publicKey:n}),Re(this,{publicKey:n,fingerprint:Xe(fy(sn(n)),0,4),parentFingerprint:r,chainCode:o,path:i,index:s,depth:a})}connect(e){return new Qm(Wm,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,e)}get extendedKey(){return _e(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),Vm(Ze(["0x0488B21E",Km(this.depth,1),this.parentFingerprint,Km(this.index,4),this.chainCode,this.publicKey]))}hasPath(){return null!=this.path}deriveChild(e){const t=ic(e,"index");Me(t<=4294967295,"invalid index","index",t);let n=this.path;n&&(n+="/"+(2147483647&t),t&Hm&&(n+="'"));const{IR:r,IL:o}=$m(t,this.chainCode,this.publicKey,null),i=Hd.addPoints(o,this.publicKey,!0),s=Yd(i);return new Qm(Wm,s,i,this.fingerprint,Qe(r),n,t,this.depth+1,this.provider)}derivePath(e){return qm(this,e)}}function Zm(e){try{if(JSON.parse(e).encseed)return!0}catch(e){}return!1}function Ym(e,t){const n=JSON.parse(e),r=Om(t),o=Cc(Nm(n,"ethaddr:string!")),i=Pm(Nm(n,"encseed:string!"));Me(i&&i.length%16==0,"invalid encseed","json",e);const s=Ve(Sy(r,r,2e3,32,"sha256")).slice(0,16),a=i.slice(0,16),c=i.slice(16),u=function(e){if(e.length<16)throw new TypeError("PKCS#7 invalid length");const t=e[e.length-1];if(t>16)throw new TypeError("PKCS#7 padding byte out of range");const n=e.length-t;for(let r=0;r<t;r++)if(e[n+r]!==t)throw new TypeError("PKCS#7 invalid padding byte");return new Uint8Array(e.subarray(0,n))}(Ve(new sm(s,a).decrypt(c)));let l="";for(let e=0;e<u.length;e++)l+=String.fromCharCode(u[e]);return{address:o,privateKey:Zc(l)}}function Xm(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}class ew extends Hg{constructor(e,t){"string"!=typeof e||e.startsWith("0x")||(e="0x"+e),super("string"==typeof e?new Hd(e):e,t)}connect(e){return new ew(this.signingKey,e)}async encrypt(e,t){const n={address:this.address,privateKey:this.privateKey};return await Mm(n,e,{progressCallback:t})}encryptSync(e){return _m({address:this.address,privateKey:this.privateKey},e)}static#At(e){if(Me(e,"invalid JSON wallet","json","[ REDACTED ]"),"mnemonic"in e&&e.mnemonic&&"en"===e.mnemonic.locale){const t=By.fromEntropy(e.mnemonic.entropy),n=Jm.fromMnemonic(t,e.mnemonic.path);if(n.address===e.address&&n.privateKey===e.privateKey)return n;console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key")}const t=new ew(e.privateKey);return Me(t.address===e.address,"address/privateKey mismatch","json","[ REDACTED ]"),t}static async fromEncryptedJson(e,t,n){let r=null;return Tm(e)?r=await async function(e,t,n){const r=JSON.parse(e),o=Om(t),i=Um(r);if("pbkdf2"===i.name){n&&(n(0),await Dm(0));const{salt:e,count:t,dkLen:s,algorithm:a}=i,c=Sy(o,e,t,s,a);return n&&(n(1),await Dm(0)),Rm(r,c)}_e("scrypt"===i.name,"cannot be reached","UNKNOWN_ERROR",{params:i});const{salt:s,N:a,r:c,p:u,dkLen:l}=i;return Rm(r,await km(o,s,a,c,u,l,n))}(e,t,n):Zm(e)&&(n&&(n(0),await Xm(0)),r=Ym(e,t),n&&(n(1),await Xm(0))),ew.#At(r)}static fromEncryptedJsonSync(e,t){let n=null;return Tm(e)?n=function(e,t){const n=JSON.parse(e),r=Om(t),o=Um(n);if("pbkdf2"===o.name){const{salt:e,count:t,dkLen:i,algorithm:s}=o;return Rm(n,Sy(r,e,t,i,s))}_e("scrypt"===o.name,"cannot be reached","UNKNOWN_ERROR",{params:o});const{salt:i,N:s,r:a,p:c,dkLen:u}=o;return Rm(n,Sm(r,i,s,a,c,u))}(e,t):Zm(e)?n=Ym(e,t):Me(!1,"invalid JSON wallet","json","[ REDACTED ]"),ew.#At(n)}static createRandom(e){const t=Jm.createRandom();return e?t.connect(e):t}static fromPhrase(e,t){const n=Jm.fromPhrase(e);return t?n.connect(t):n}}var tw=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),nw=function(){return nw=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},nw.apply(this,arguments)},rw=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},ow=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},iw=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},sw=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return n.MESSAGE_TO_SIGN="I Love Shogun!",n.DEFAULT_CONFIG={cacheDuration:18e5,maxRetries:3,retryDelay:1e3,timeout:6e4},n.signatureCache=new Map,n.provider=null,n.customProvider=null,n.customWallet=null,n.config=nw(nw({},n.DEFAULT_CONFIG),t),n.initProvider(),n.setupEventListeners(),n}return tw(t,e),t.prototype.initProvider=function(){if("undefined"!=typeof window)try{var e=this.getAvailableEthereumProvider();e?this.provider=new Mg(e):console.warn("No compatible Ethereum provider found")}catch(e){console.error("Failed to initialize BrowserProvider",e)}else console.warn("Window object not available (non-browser environment)")},t.prototype.getAvailableEthereumProvider=function(){var e,t;if("undefined"!=typeof window){var n=[{source:function(){return window._ethereumProviders&&window._ethereumProviders[0]},name:"Registry Primary"},{source:function(){return window.ethereum},name:"Standard ethereum"},{source:function(){var e;return null===(e=window.web3)||void 0===e?void 0:e.currentProvider},name:"Legacy web3"},{source:function(){return window.metamask},name:"MetaMask specific"},{source:function(){var e,t;return null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.providers)||void 0===t?void 0:t.find(function(e){return e.isMetaMask})},name:"MetaMask from providers array"},{source:function(){var e,t;return null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.providers)||void 0===t?void 0:t[0]},name:"First provider in array"},{source:function(){var e,t;return null===(t=null===(e=window.enkrypt)||void 0===e?void 0:e.providers)||void 0===t?void 0:t.ethereum},name:"Enkrypt"},{source:function(){return window.coinbaseWalletExtension},name:"Coinbase"},{source:function(){return window.trustWallet},name:"Trust Wallet"},{source:function(){return Array.isArray(window._ethereumProviders)?window._ethereumProviders.find(function(e){return!e._isProxy}):void 0},name:"Registry non-proxy"}];try{for(var r=iw(n),o=r.next();!o.done;o=r.next()){var i=o.value,s=i.source,a=i.name;try{var c=s();if(c&&"function"==typeof c.request)return c}catch(e){console.warn("Error checking provider ".concat(a,":"),e);continue}}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}console.warn("No compatible Ethereum provider found")}},t.prototype.setupProvider=function(){return rw(this,void 0,void 0,function(){var e;return ow(this,function(t){try{"undefined"!=typeof window?(e=this.getAvailableEthereumProvider())?this.provider=new Mg(e):console.warn("No compatible Ethereum provider found"):console.warn("Window object not available (non-browser environment)")}catch(e){console.error("Failed to initialize BrowserProvider",e)}return[2]})})},t.prototype.setupEventListeners=function(){var e=this;if(this.provider){this.provider.on("network",function(t,n){e.emit("chainChanged",t)});try{var t=this.getAvailableEthereumProvider();(null==t?void 0:t.on)&&(t.on("accountsChanged",function(t){e.emit("accountsChanged",t)}),t.on("chainChanged",function(t){e.emit("chainChanged",{chainId:t})}))}catch(e){console.warn("Failed to setup account change listeners",e)}}},t.prototype.cleanup=function(){this.provider&&this.provider.removeAllListeners(),this.removeAllListeners()},t.prototype.getCachedSignature=function(e){var t=this.signatureCache.get(e);return t?Date.now()-t.timestamp>this.config.cacheDuration?(this.signatureCache.delete(e),null):!t.signature||"string"!=typeof t.signature||t.signature.length<16?(console.warn("Invalid cached signature for address ".concat(e," (length: ").concat(t.signature?t.signature.length:0,"), deleting from cache.")),this.signatureCache.delete(e),null):t.signature:null},t.prototype.cacheSignature=function(e,t){this.signatureCache.set(e,{signature:t,timestamp:Date.now(),address:e})},t.prototype.validateAddress=function(e){if(!e)throw new Error("Address not provided");try{var t=String(e).trim().toLowerCase();if(!function(e){try{return Cc(e),!0}catch(e){}return!1}(t))throw new Error("Invalid address format");return Cc(t)}catch(e){throw Ie.handle(xe.VALIDATION,"INVALID_ADDRESS","Invalid Ethereum address provided",e),e}},t.prototype.connectMetaMask=function(){return rw(this,void 0,void 0,function(){var e,t,n,r,o,i,s,a,c,u=this;return ow(this,function(l){switch(l.label){case 0:if(l.trys.push([0,19,,20]),!this.provider&&(this.initProvider(),!this.provider))throw new Error("MetaMask is not available. Please install MetaMask extension.");if(!(e=this.getAvailableEthereumProvider()))throw new Error("No compatible Ethereum provider found");t=[],l.label=1;case 1:return l.trys.push([1,3,,10]),[4,e.request({method:"eth_requestAccounts"})];case 2:return t=l.sent(),[3,10];case 3:if(n=l.sent(),console.warn("First account request failed, trying window.ethereum:",n),!window.ethereum||window.ethereum===e)return[3,8];l.label=4;case 4:return l.trys.push([4,6,,7]),[4,window.ethereum.request({method:"eth_requestAccounts"})];case 5:return t=l.sent(),[3,7];case 6:throw r=l.sent(),console.error("All account request methods failed",r),new Error("User denied account access");case 7:return[3,9];case 8:throw new Error("User denied account access");case 9:return[3,10];case 10:!t||t.length,o=1,l.label=11;case 11:if(!(o<=this.config.maxRetries))return[3,18];l.label=12;case 12:return l.trys.push([12,15,,17]),[4,this.provider.getSigner()];case 13:return[4,l.sent().getAddress()];case 14:if(!(i=l.sent()))throw console.error("No address returned from signer"),new Error("No address returned from signer");return this.emit("connected",{address:i}),[2,{success:!0,address:i}];case 15:if(s=l.sent(),console.error("Attempt ".concat(o," failed:"),s),o===this.config.maxRetries)throw s;return[4,new Promise(function(e){return setTimeout(e,u.config.retryDelay)})];case 16:return l.sent(),[3,17];case 17:return o++,[3,11];case 18:throw new Error("Failed to get signer after all attempts");case 19:return a=l.sent(),console.error("Failed to connect to MetaMask:",a),Ie.handle(xe.WEBAUTHN,"METAMASK_CONNECTION_ERROR",null!==(c=a.message)&&void 0!==c?c:"Unknown error while connecting to MetaMask",a),[2,{success:!1,error:a.message}];case 20:return[2]}})})},t.prototype.generateCredentials=function(e){return rw(this,void 0,void 0,function(){var t,n,r,o,i,s;return ow(this,function(a){switch(a.label){case 0:if(a.trys.push([0,5,,6]),t=this.validateAddress(e),n=this.getCachedSignature(t))return[2,this.generateCredentialsFromSignature(t,n)];r=void 0,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.requestSignatureWithTimeout(t,this.MESSAGE_TO_SIGN,this.config.timeout)];case 2:return r=a.sent(),[3,4];case 3:throw o=a.sent(),console.warn("Failed to get signature: ".concat(o,". Using fallback method.")),o;case 4:return this.cacheSignature(t,r),[2,this.generateCredentialsFromSignature(t,r)];case 5:throw i=a.sent(),Ie.handle(xe.WEBAUTHN,"CREDENTIALS_GENERATION_ERROR",null!==(s=i.message)&&void 0!==s?s:"Error generating MetaMask credentials",i),i;case 6:return[2]}})})},t.prototype.generateCredentialsFromSignature=function(e,t){return rw(this,void 0,void 0,function(){var n,r;return ow(this,function(o){switch(o.label){case 0:return n=In(ot(e)),r="".concat(e,"_").concat(t),[4,qi(n,r,{includeP256:!0})];case 1:return[2,o.sent()]}})})},t.prototype.generateFallbackCredentials=function(e){console.warn("Using fallback credentials generation for address:",e);var t=In(ot(e+"fallback"));return{username:e.toLowerCase(),password:t,message:this.MESSAGE_TO_SIGN,signature:t}},t.isMetaMaskAvailable=function(){var e,t;if("undefined"==typeof window)return!1;var n=[function(){return window.ethereum},function(){var e;return null===(e=window.web3)||void 0===e?void 0:e.currentProvider},function(){return window.metamask},function(){var e;return null===(e=window._ethereumProviders)||void 0===e?void 0:e[0]}];try{for(var r=iw(n),o=r.next();!o.done;o=r.next()){var i=o.value;try{var s=i();if(s&&"function"==typeof s.request)return!0}catch(e){}}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}return!1},t.prototype.requestSignatureWithTimeout=function(e,t,n){var r=this;return void 0===n&&(n=3e4),new Promise(function(o,i){var s=setTimeout(function(){i(new Error("Signature request timed out"))},n),a=function(){clearTimeout(s)};rw(r,void 0,void 0,function(){var n,r,s,c;return ow(this,function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),[4,this.provider.getSigner()];case 1:return[4,(n=u.sent()).getAddress()];case 2:if((r=u.sent()).toLowerCase()!==e.toLowerCase())throw new Error("Signer address (".concat(r,") does not match expected address (").concat(e,")"));return[4,n.signMessage(t)];case 3:return s=u.sent(),a(),o(s),[3,5];case 4:return c=u.sent(),console.error("Failed to request signature:",c),l=c,a(),i(l),[3,5];case 5:return[2]}var l})})})},t.prototype.isAvailable=function(){return t.isMetaMaskAvailable()},t.prototype.setCustomProvider=function(e,t){var n;try{this.customProvider=new Lg(e),this.customWallet=new ew(t,this.customProvider)}catch(e){throw new Error("Error configuring provider: ".concat(null!==(n=e.message)&&void 0!==n?n:"Unknown error"))}},t.prototype.getSigner=function(){return rw(this,void 0,void 0,function(){var e;return ow(this,function(t){switch(t.label){case 0:if(t.trys.push([0,2,,3]),this.customWallet)return[2,this.customWallet];if(this.provider||this.initProvider(),!this.provider)throw new Error("Provider not initialized");return[4,this.provider.getSigner()];case 1:return[2,t.sent()];case 2:throw e=t.sent(),new Error("Unable to get Ethereum signer: ".concat(e.message||"Unknown error"));case 3:return[2]}})})},t.prototype.getProvider=function(){return rw(this,void 0,void 0,function(){return ow(this,function(e){return this.customProvider?[2,this.customProvider]:(this.provider||this.initProvider(),[2,this.provider])})})},t.prototype.generatePassword=function(e){return rw(this,void 0,void 0,function(){return ow(this,function(t){if(!e)throw new Error("Invalid signature");return[2,In(ot(e)).slice(2,66)]})})},t.prototype.verifySignature=function(e,t){return rw(this,void 0,void 0,function(){return ow(this,function(n){if(!e||!t)throw new Error("Invalid message or signature");try{return[2,Gg(e,t)]}catch(e){throw new Error("Invalid message or signature")}})})},t.prototype.getEthereumSigner=function(){return rw(this,void 0,void 0,function(){var e,n,r;return ow(this,function(o){switch(o.label){case 0:if(!t.isMetaMaskAvailable())throw new Error("MetaMask not found. Please install MetaMask to continue.");o.label=1;case 1:return o.trys.push([1,3,,4]),[4,(e=window.ethereum).request({method:"eth_requestAccounts"})];case 2:return o.sent(),[2,new Mg(e).getSigner()];case 3:throw n=o.sent(),new Error("Error accessing MetaMask: ".concat(null!==(r=n.message)&&void 0!==r?r:"Unknown error"));case 4:return[2]}})})},t}(Pe);"undefined"!=typeof window?window.Web3Connector=sw:void 0!==r.g&&(r.g.Web3Connector=sw);var aw=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},cw=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},uw=function(){function e(e){this.credentials=new Map,this.MESSAGE_TO_SIGN="I Love Shogun!",this.web3Connector=e||new sw}return e.prototype.createSigningCredential=function(e){return aw(this,void 0,void 0,function(){var t,n,r,o,i,s;return cw(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),t=Cc(e.toLowerCase()),[4,this.requestSignature(t)];case 1:return n=a.sent(),r="".concat(t.toLowerCase()),o=In(ot("".concat(t.toLowerCase(),":shogun-web3"))),i={address:t,signature:n,message:this.MESSAGE_TO_SIGN,username:r,password:o},this.credentials.set(t.toLowerCase(),i),[2,i];case 2:throw s=a.sent(),console.error("Error creating Web3 signing credential:",s),new Error("Failed to create Web3 signing credential: ".concat(s.message));case 3:return[2]}})})},e.prototype.requestSignature=function(e){return aw(this,void 0,void 0,function(){var t,n,r;return cw(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,this.web3Connector.getSigner()];case 1:return[4,(t=o.sent()).getAddress()];case 2:if((n=o.sent()).toLowerCase()!==e.toLowerCase())throw new Error("Signer address (".concat(n,") does not match expected address (").concat(e,")"));return[4,t.signMessage(this.MESSAGE_TO_SIGN)];case 3:return[2,o.sent()];case 4:throw r=o.sent(),console.error("Failed to request signature:",r),r;case 5:return[2]}})})},e.prototype.createAuthenticator=function(e){var t=this;if(!this.credentials.get(e.toLowerCase()))throw new Error("Credential for address ".concat(e," not found"));return function(n){return aw(t,void 0,void 0,function(){var t,r,o;return cw(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),[4,this.web3Connector.getSigner()];case 1:return[4,(t=i.sent()).getAddress()];case 2:if(i.sent().toLowerCase()!==e.toLowerCase())throw new Error("Address mismatch during authentication");return r=JSON.stringify(n),[4,t.signMessage(r)];case 3:return[2,i.sent()];case 4:throw o=i.sent(),console.error("Web3 authentication error:",o),o;case 5:return[2]}})})}},e.prototype.createDerivedKeyPair=function(e,t){return aw(this,void 0,void 0,function(){return cw(this,function(n){return[2,this.createDerivedKeyPairFromAddress(e,t)]})})},e.prototype.authenticateWithExistingPair=function(e,t){return aw(this,void 0,void 0,function(){var n,r;return cw(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),console.log("🔧 Web3Signer - authenticating with deterministic pair for address:",e),[4,this.createDerivedKeyPairFromAddress(e)];case 1:return n=o.sent(),console.log("🔧 Web3Signer - deterministic pair created, attempting auth with GunDB"),[2,new Promise(function(e){t.user().auth(n,function(t){if(t.err)console.log("🔧 Web3Signer - auth failed:",t.err),e({success:!1,error:t.err});else{var n=t.pub;console.log("🔧 Web3Signer - auth successful, userPub:",n?n.slice(0,8)+"...":"null"),e({success:!0,userPub:n})}})})];case 2:return r=o.sent(),console.error("Error authenticating with deterministic pair:",r),[2,{success:!1,error:r.message}];case 3:return[2]}})})},e.prototype.createDerivedKeyPairFromAddress=function(e,t){return aw(this,void 0,void 0,function(){var n,r,o,i;return cw(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),n=Cc(e.toLowerCase()),r=In(ot("".concat(n.toLowerCase(),":shogun-web3"))),console.log("🔧 Web3Signer - generating deterministic pair for address:",n),[4,qi(r,t,{includeP256:!0})];case 1:return[2,{pub:(o=s.sent()).pub,priv:o.priv,epub:o.epub,epriv:o.epriv}];case 2:throw i=s.sent(),console.error("Error creating derived key pair from address:",i),i;case 3:return[2]}})})},e.prototype.createGunUser=function(e,t){return aw(this,void 0,void 0,function(){var n,r;return cw(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),console.log("🔧 Web3Signer - creating Gun user with deterministic pair for address:",e),[4,this.createDerivedKeyPairFromAddress(e)];case 1:return n=o.sent(),[2,new Promise(function(e){t.user().create(n,function(r){r.err?(console.log("🔧 Web3Signer - user creation failed, trying auth:",r.err),t.user().auth(n,function(t){if(t.err)console.log("🔧 Web3Signer - auth also failed:",t.err),e({success:!1,error:t.err});else{var n=t.pub;console.log("🔧 Web3Signer - auth successful, userPub:",n?n.slice(0,8)+"...":"null"),e({success:!0,userPub:n})}})):(console.log("🔧 Web3Signer - user created successfully, now logging in"),t.user().auth(n,function(t){if(t.err)console.log("🔧 Web3Signer - login after creation failed:",t.err),e({success:!1,error:t.err});else{var n=t.pub;console.log("🔧 Web3Signer - login successful, userPub:",n?n.slice(0,8)+"...":"null"),e({success:!0,userPub:n})}}))})})];case 2:return r=o.sent(),console.error("Error creating Gun user:",r),[2,{success:!1,error:r.message}];case 3:return[2]}})})},e.prototype.signWithDerivedKeys=function(e,t,n){return aw(this,void 0,void 0,function(){var r,o,i,s,a;return cw(this,function(c){switch(c.label){case 0:return c.trys.push([0,4,,5]),[4,this.createAuthenticator(t)(e)];case 1:return c.sent(),[4,this.createDerivedKeyPair(t,n)];case 2:return r=c.sent(),In(ot(o=JSON.stringify(e))),[4,new ew(r.priv).signMessage(o)];case 3:return i=c.sent(),s={m:o,s:i},[2,"SEA"+JSON.stringify(s)];case 4:throw a=c.sent(),console.error("Error signing with derived keys:",a),a;case 5:return[2]}})})},e.prototype.getGunUserPub=function(e){return aw(this,void 0,void 0,function(){var t;return cw(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.createDerivedKeyPairFromAddress(e)];case 1:return[2,n.sent().pub];case 2:return t=n.sent(),console.error("Error getting Gun user pub:",t),[2,void 0];case 3:return[2]}})})},e.prototype.getPassword=function(e){try{var t=Cc(e.toLowerCase());return In(ot("".concat(t.toLowerCase(),":shogun-web3")))}catch(e){return void console.error("Error getting password:",e)}},e.prototype.verifyConsistency=function(e,t){return aw(this,void 0,void 0,function(){var n,r;return cw(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.createDerivedKeyPairFromAddress(e)];case 1:return n=o.sent(),[2,{consistent:!t||n.pub===t,actualUserPub:n.pub,expectedUserPub:t}];case 2:return r=o.sent(),console.error("Error verifying consistency:",r),[2,{consistent:!1}];case 3:return[2]}})})},e.prototype.getCredential=function(e){return this.credentials.get(e.toLowerCase())},e.prototype.listCredentials=function(){return Array.from(this.credentials.values())},e.prototype.removeCredential=function(e){return this.credentials.delete(e.toLowerCase())},e}(),lw=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),fw=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},hw=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},dw=function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.name="web3",t.version="1.0.0",t.description="Provides Ethereum wallet connection and authentication for ShogunCore",t.Web3=null,t.signer=null,t}return lw(t,e),t.prototype.initialize=function(t){e.prototype.initialize.call(this,t),this.Web3=new sw,this.signer=new uw(this.Web3)},t.prototype.destroy=function(){this.Web3&&this.Web3.cleanup(),this.Web3=null,this.signer=null,e.prototype.destroy.call(this)},t.prototype.assertMetaMask=function(){if(this.assertInitialized(),!this.Web3)throw new Error("Web3 module not initialized");return this.Web3},t.prototype.assertSigner=function(){if(this.assertInitialized(),!this.signer)throw new Error("Web3 signer not initialized");return this.signer},t.prototype.isAvailable=function(){return this.assertMetaMask().isAvailable()},t.prototype.connectMetaMask=function(){return fw(this,void 0,void 0,function(){return hw(this,function(e){return[2,this.assertMetaMask().connectMetaMask()]})})},t.prototype.generateCredentials=function(e){return fw(this,void 0,void 0,function(){return hw(this,function(t){return[2,this.assertMetaMask().generateCredentials(e)]})})},t.prototype.cleanup=function(){this.assertMetaMask().cleanup()},t.prototype.setCustomProvider=function(e,t){this.assertMetaMask().setCustomProvider(e,t)},t.prototype.getSigner=function(){return fw(this,void 0,void 0,function(){return hw(this,function(e){return[2,this.assertMetaMask().getSigner()]})})},t.prototype.getProvider=function(){return fw(this,void 0,void 0,function(){return hw(this,function(e){return[2,this.assertMetaMask().getProvider()]})})},t.prototype.generatePassword=function(e){return fw(this,void 0,void 0,function(){return hw(this,function(t){return[2,this.assertMetaMask().generatePassword(e)]})})},t.prototype.verifySignature=function(e,t){return fw(this,void 0,void 0,function(){return hw(this,function(n){return[2,this.assertMetaMask().verifySignature(e,t)]})})},t.prototype.createSigningCredential=function(e){return fw(this,void 0,void 0,function(){var t,n;return hw(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),"function"!=typeof(t=this.assertMetaMask()).createSigningCredential?[3,2]:[4,t.createSigningCredential(e)];case 1:case 3:return[2,r.sent()];case 2:return[4,this.assertSigner().createSigningCredential(e)];case 4:throw n=r.sent(),console.error("Error creating Web3 signing credential: ".concat(n.message)),n;case 5:return[2]}})})},t.prototype.createAuthenticator=function(e){try{var t=this.assertMetaMask();return"function"==typeof t.createAuthenticator?t.createAuthenticator(e):this.assertSigner().createAuthenticator(e)}catch(e){throw console.error("Error creating Web3 authenticator: ".concat(e.message)),e}},t.prototype.createDerivedKeyPair=function(e,t){return fw(this,void 0,void 0,function(){var n,r;return hw(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(n=this.assertMetaMask()).createDerivedKeyPair?[3,2]:[4,n.createDerivedKeyPair(e,t)];case 1:case 3:return[2,o.sent()];case 2:return[4,this.assertSigner().createDerivedKeyPair(e,t)];case 4:throw r=o.sent(),console.error("Error creating derived key pair: ".concat(r.message)),r;case 5:return[2]}})})},t.prototype.signWithDerivedKeys=function(e,t,n){return fw(this,void 0,void 0,function(){var r,o;return hw(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(r=this.assertMetaMask()).signWithDerivedKeys?[3,2]:[4,r.signWithDerivedKeys(e,t,n)];case 1:case 3:return[2,i.sent()];case 2:return[4,this.assertSigner().signWithDerivedKeys(e,t,n)];case 4:throw o=i.sent(),console.error("Error signing with derived keys: ".concat(o.message)),o;case 5:return[2]}})})},t.prototype.getSigningCredential=function(e){var t=this.assertMetaMask();return"function"==typeof t.getSigningCredential?t.getSigningCredential(e):this.assertSigner().getCredential(e)},t.prototype.listSigningCredentials=function(){var e=this.assertMetaMask();return"function"==typeof e.listSigningCredentials?e.listSigningCredentials():this.assertSigner().listCredentials()},t.prototype.removeSigningCredential=function(e){var t=this.assertMetaMask();return"function"==typeof t.removeSigningCredential?t.removeSigningCredential(e):this.assertSigner().removeCredential(e)},t.prototype.createGunUserFromSigningCredential=function(e){return fw(this,void 0,void 0,function(){var t,n,r,o,i,s;return hw(this,function(a){switch(a.label){case 0:return a.trys.push([0,5,,6]),console.log("🔧 createGunUserFromSigningCredential called with address:",e),"function"!=typeof(t=this.assertMetaMask()).createGunUserFromSigningCredential?[3,2]:(console.log("🔧 Using connector's createGunUserFromSigningCredential"),[4,t.createGunUserFromSigningCredential(e)]);case 1:return n=a.sent(),console.log("🔧 Connector result:",n),[2,n];case 2:return console.log("🔧 Using fallback createGunUser"),r=this.assertInitialized(),console.log("🔧 Attempting authentication with deterministic pair"),[4,this.assertSigner().authenticateWithExistingPair(e,r.gun)];case 3:return(o=a.sent()).success?(console.log("🔧 Authentication successful with existing user"),[2,o]):(console.log("🔧 Authentication failed, creating new user"),[4,this.assertSigner().createGunUser(e,r.gun)]);case 4:return i=a.sent(),console.log("🔧 User creation result:",i),[2,i];case 5:throw s=a.sent(),console.error("Error creating Gun user from Web3 signing credential: ".concat(s.message)),s;case 6:return[2]}})})},t.prototype.getGunUserPubFromSigningCredential=function(e){return fw(this,void 0,void 0,function(){var t;return hw(this,function(n){switch(n.label){case 0:return"function"!=typeof(t=this.assertMetaMask()).getGunUserPubFromSigningCredential?[3,2]:[4,t.getGunUserPubFromSigningCredential(e)];case 1:case 3:return[2,n.sent()];case 2:return[4,this.assertSigner().getGunUserPub(e)]}})})},t.prototype.getPassword=function(e){var t=this.assertMetaMask();return"function"==typeof t.getPassword?t.getPassword(e):this.assertSigner().getPassword(e)},t.prototype.verifyConsistency=function(e,t){return fw(this,void 0,void 0,function(){var n,r;return hw(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(n=this.assertMetaMask()).verifyConsistency?[3,2]:[4,n.verifyConsistency(e,t)];case 1:case 3:return[2,o.sent()];case 2:return[4,this.assertSigner().verifyConsistency(e,t)];case 4:return r=o.sent(),console.error("Error verifying Web3 consistency: ".concat(r.message)),[2,{consistent:!1}];case 5:return[2]}})})},t.prototype.setupConsistentOneshotSigning=function(e){return fw(this,void 0,void 0,function(){var t,n,r,o,i;return hw(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),"function"!=typeof(t=this.assertMetaMask()).setupConsistentOneshotSigning?[3,2]:[4,t.setupConsistentOneshotSigning(e)];case 1:return[2,s.sent()];case 2:return[4,this.createSigningCredential(e)];case 3:return n=s.sent(),r=this.createAuthenticator(e),[4,this.createGunUserFromSigningCredential(e)];case 4:return o=s.sent(),[2,{credential:n,authenticator:r,gunUser:o,username:e,password:"web3-generated-password"}];case 5:throw i=s.sent(),console.error("Error setting up consistent Web3 oneshot signing: ".concat(i.message)),i;case 6:return[2]}})})},t.prototype.login=function(e){return fw(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c,u,l,f;return hw(this,function(h){switch(h.label){case 0:if(h.trys.push([0,4,,5]),t=this.assertInitialized(),!e)throw Se(xe.VALIDATION,"ADDRESS_REQUIRED","Ethereum address required for Web3 login");if(!this.isAvailable())throw Se(xe.ENVIRONMENT,"WEB3_UNAVAILABLE","Web3 is not available in the browser");return console.log("🔧 Web3 login - starting login for address:",e),this.getSigningCredential(e)?(console.log("🔧 Web3 login - found existing credential, using it"),[4,this.createGunUserFromSigningCredential(e)]):[3,2];case 1:if(n=h.sent(),console.log("🔧 Web3 login - existing credential result:",n),n.success&&n.userPub)return t.setAuthMethod("web3"),r={success:!0,user:{userPub:n.userPub,username:e},userPub:n.userPub},console.log("🔧 Web3 login - returning result:",{success:r.success,userPub:r.userPub?r.userPub.slice(0,8)+"...":"null",username:null===(l=r.user)||void 0===l?void 0:l.username}),t.emit("auth:login",{userPub:n.userPub||"",username:e,method:"web3"}),[2,r];h.label=2;case 2:return console.log("🔧 Web3 login - no existing credential, creating new one"),[4,this.setupConsistentOneshotSigning(e)];case 3:if(o=h.sent().gunUser,console.log("🔧 Web3 login - setupConsistentOneshotSigning result:",{gunUser:o,address:e}),!o.success)throw Se(xe.AUTHENTICATION,"WEB3_LOGIN_FAILED",o.error||"Failed to log in with Web3 credentials");return console.log("🔧 Web3 login - gunUser success, userPub:",o.userPub?o.userPub.slice(0,8)+"...":"null"),t.setAuthMethod("web3"),i={success:!0,user:{userPub:o.userPub,username:e},userPub:o.userPub},console.log("🔧 Web3 login - returning result:",{success:i.success,userPub:i.userPub?i.userPub.slice(0,8)+"...":"null",username:null===(f=i.user)||void 0===f?void 0:f.username}),t.emit("auth:login",{userPub:o.userPub||"",username:e,method:"web3"}),[2,i];case 4:return s=h.sent(),a=(null==s?void 0:s.type)||xe.AUTHENTICATION,c=(null==s?void 0:s.code)||"WEB3_LOGIN_ERROR",u=(null==s?void 0:s.message)||"Unknown error during Web3 login",Ie.handle(a,c,u,s),[2,{success:!1,error:u}];case 5:return[2]}})})},t.prototype.signUp=function(e){return fw(this,void 0,void 0,function(){var t,n,r,o,i,s;return hw(this,function(a){switch(a.label){case 0:if(a.trys.push([0,2,,3]),t=this.assertInitialized(),!e)throw Se(xe.VALIDATION,"ADDRESS_REQUIRED","Ethereum address required for Web3 registration");if(!this.isAvailable())throw Se(xe.ENVIRONMENT,"WEB3_UNAVAILABLE","Web3 is not available in the browser");return[4,this.setupConsistentOneshotSigning(e)];case 1:if(!(n=a.sent().gunUser).success)throw Se(xe.AUTHENTICATION,"WEB3_SIGNUP_FAILED",n.error||"Failed to sign up with Web3 credentials");return t.setAuthMethod("web3"),[2,{success:!0,user:{userPub:n.userPub,username:e},userPub:n.userPub}];case 2:return r=a.sent(),o=(null==r?void 0:r.type)||xe.AUTHENTICATION,i=(null==r?void 0:r.code)||"WEB3_SIGNUP_ERROR",s=(null==r?void 0:r.message)||"Unknown error during Web3 registration",Ie.handle(o,i,s,r),[2,{success:!1,error:s}];case 3:return[2]}})})},t}(Oe);function pw(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function gw(e,t=""){if(!Number.isSafeInteger(e)||e<0)throw new Error(`${t&&`"${t}" `}expected integer >= 0, got ${e}`)}function yw(e,t,n=""){const r=pw(e),o=e?.length,i=void 0!==t;if(!r||i&&o!==t)throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(i?` of length ${t}`:"")+", got "+(r?`length=${o}`:"type="+typeof e));return e}function mw(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash must wrapped by utils.createHasher");gw(e.outputLen),gw(e.blockLen)}function ww(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function bw(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function vw(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ew(e,t){return e<<32-t|e>>>t}const Aw=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),xw=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function kw(e){if(yw(e),Aw)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=xw[e[n]];return t}function Sw(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Iw(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(Aw)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,o=0;t<n;t++,o+=2){const n=Sw(e.charCodeAt(o)),i=Sw(e.charCodeAt(o+1));if(void 0===n||void 0===i){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}r[t]=16*n+i}return r}function Pw(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];yw(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const o=e[t];n.set(o,r),r+=o.length}return n}function Cw(e,t={}){const n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function Ow(e=32){const t="object"==typeof globalThis?globalThis.crypto:null;if("function"!=typeof t?.getRandomValues)throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}const Nw=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Bw(e,t,n){return e&t^~e&n}function Tw(e,t,n){return e&t^e&n^t&n}class Rw{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=vw(this.buffer)}update(e){ww(this),yw(e);const{view:t,buffer:n,blockLen:r}=this,o=e.length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=vw(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ww(this),function(e,t){yw(e,void 0,"digestInto() output");const n=t.outputLen;if(e.length<n)throw new Error('"digestInto() output" expected to be of length >='+n)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,bw(this.buffer.subarray(i)),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;n.setBigUint64(r-8,BigInt(8*this.length),o),this.process(n,0);const s=vw(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const Uw=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Dw=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Lw=new Uint32Array(64);class Fw extends Rw{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)Lw[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Lw[e-15],n=Lw[e-2],r=Ew(t,7)^Ew(t,18)^t>>>3,o=Ew(n,17)^Ew(n,19)^n>>>10;Lw[e]=o+Lw[e-7]+r+Lw[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(Ew(s,6)^Ew(s,11)^Ew(s,25))+Bw(s,a,c)+Dw[e]+Lw[e]|0,l=(Ew(n,2)^Ew(n,13)^Ew(n,22))+Tw(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){bw(Lw)}destroy(){this.set(0,0,0,0,0,0,0,0),bw(this.buffer)}}class _w extends Fw{A=0|Uw[0];B=0|Uw[1];C=0|Uw[2];D=0|Uw[3];E=0|Uw[4];F=0|Uw[5];G=0|Uw[6];H=0|Uw[7];constructor(){super(32)}}const Mw=Cw(()=>new _w,Nw(1)),jw=BigInt(0),Gw=BigInt(1);function Hw(e,t=""){if("boolean"!=typeof e)throw new Error((t&&`"${t}" `)+"expected boolean, got type="+typeof e);return e}function zw(e){if("bigint"==typeof e){if(!Qw(e))throw new Error("positive bigint expected, got "+e)}else gw(e);return e}function Kw(e){const t=zw(e).toString(16);return 1&t.length?"0"+t:t}function Vw(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?jw:BigInt("0x"+e)}function Ww(e){return Vw(kw(e))}function $w(e){return Vw(kw(function(e){return Uint8Array.from(e)}(yw(e)).reverse()))}function qw(e,t){gw(t);const n=Iw((e=zw(e)).toString(16).padStart(2*t,"0"));if(n.length!==t)throw new Error("number too large");return n}function Jw(e,t){return qw(e,t).reverse()}const Qw=e=>"bigint"==typeof e&&jw<=e;const Zw=e=>(Gw<<BigInt(e))-Gw;function Yw(e,t={},n={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");const r=(t,n)=>Object.entries(t).forEach(([t,r])=>function(t,n,r){const o=e[t];if(r&&void 0===o)return;const i=typeof o;if(i!==n||null===o)throw new Error(`param "${t}" is invalid: expected ${n}, got ${i}`)}(t,r,n));r(t,!1),r(n,!0)}function Xw(e){const t=new WeakMap;return(n,...r)=>{const o=t.get(n);if(void 0!==o)return o;const i=e(n,...r);return t.set(n,i),i}}const eb=BigInt(0),tb=BigInt(1),nb=BigInt(2),rb=BigInt(3),ob=BigInt(4),ib=BigInt(5),sb=BigInt(7),ab=BigInt(8),cb=BigInt(9),ub=BigInt(16);function lb(e,t){const n=e%t;return n>=eb?n:t+n}function fb(e,t,n){let r=e;for(;t-- >eb;)r*=r,r%=n;return r}function hb(e,t){if(e===eb)throw new Error("invert: expected non-zero number");if(t<=eb)throw new Error("invert: expected positive modulus, got "+t);let n=lb(e,t),r=t,o=eb,i=tb,s=tb,a=eb;for(;n!==eb;){const e=r/n,t=r%n,c=o-s*e,u=i-a*e;r=n,n=t,o=s,i=a,s=c,a=u}if(r!==tb)throw new Error("invert: does not exist");return lb(o,t)}function db(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function pb(e,t){const n=(e.ORDER+tb)/ob,r=e.pow(t,n);return db(e,r,t),r}function gb(e,t){const n=(e.ORDER-ib)/ab,r=e.mul(t,nb),o=e.pow(r,n),i=e.mul(t,o),s=e.mul(e.mul(i,nb),o),a=e.mul(i,e.sub(s,e.ONE));return db(e,a,t),a}function yb(e){if(e<rb)throw new Error("sqrt is not defined for small field");let t=e-tb,n=0;for(;t%nb===eb;)t/=nb,n++;let r=nb;const o=Eb(e);for(;1===bb(o,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return pb;let i=o.pow(r,t);const s=(t+tb)/nb;return function(e,r){if(e.is0(r))return r;if(1!==bb(e,r))throw new Error("Cannot find square root");let o=n,a=e.mul(e.ONE,i),c=e.pow(r,t),u=e.pow(r,s);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===o)throw new Error("Cannot find square root");const r=tb<<BigInt(o-t-1),i=e.pow(a,r);o=t,a=e.sqr(i),c=e.mul(c,a),u=e.mul(u,i)}return u}}const mb=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function wb(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),o=t.reduce((t,n,o)=>e.is0(n)?t:(r[o]=t,e.mul(t,n)),e.ONE),i=e.inv(o);return t.reduceRight((t,n,o)=>e.is0(n)?t:(r[o]=e.mul(t,r[o]),e.mul(t,n)),i),r}function bb(e,t){const n=(e.ORDER-tb)/nb,r=e.pow(t,n),o=e.eql(r,e.ONE),i=e.eql(r,e.ZERO),s=e.eql(r,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}class vb{ORDER;BITS;BYTES;isLE;ZERO=eb;ONE=tb;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=eb)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,null!=t&&"object"==typeof t&&("number"==typeof t.BITS&&(n=t.BITS),"function"==typeof t.sqrt&&(this.sqrt=t.sqrt),"boolean"==typeof t.isLE&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),"boolean"==typeof t.modFromBytes&&(this._mod=t.modFromBytes));const{nBitLength:r,nByteLength:o}=function(e,t){void 0!==t&&gw(t);const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=r,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return lb(e,this.ORDER)}isValid(e){if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return eb<=e&&e<this.ORDER}is0(e){return e===eb}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&tb)===tb}neg(e){return lb(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return lb(e*e,this.ORDER)}add(e,t){return lb(e+t,this.ORDER)}sub(e,t){return lb(e-t,this.ORDER)}mul(e,t){return lb(e*t,this.ORDER)}pow(e,t){return function(e,t,n){if(n<eb)throw new Error("invalid exponent, negatives unsupported");if(n===eb)return e.ONE;if(n===tb)return t;let r=e.ONE,o=t;for(;n>eb;)n&tb&&(r=e.mul(r,o)),o=e.sqr(o),n>>=tb;return r}(this,e,t)}div(e,t){return lb(e*hb(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return hb(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=(t=this.ORDER)%ob===rb?pb:t%ab===ib?gb:t%ub===cb?function(e){const t=Eb(e),n=yb(e),r=n(t,t.neg(t.ONE)),o=n(t,r),i=n(t,t.neg(r)),s=(e+sb)/ub;return(e,t)=>{let n=e.pow(t,s),a=e.mul(n,r);const c=e.mul(n,o),u=e.mul(n,i),l=e.eql(e.sqr(a),t),f=e.eql(e.sqr(c),t);n=e.cmov(n,a,l),a=e.cmov(u,c,f);const h=e.eql(e.sqr(a),t),d=e.cmov(n,a,h);return db(e,d,t),d}}(t):yb(t)),this._sqrt(this,e);var t}toBytes(e){return this.isLE?Jw(e,this.BYTES):qw(e,this.BYTES)}fromBytes(e,t=!1){yw(e);const{_lengths:n,BYTES:r,isLE:o,ORDER:i,_mod:s}=this;if(n){if(!n.includes(e.length)||e.length>r)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);const t=new Uint8Array(r);t.set(e,o?0:t.length-e.length),e=t}if(e.length!==r)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+e.length);let a=o?$w(e):Ww(e);if(s&&(a=lb(a,i)),!t&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return wb(this,e)}cmov(e,t,n){return n?t:e}}function Eb(e,t={}){return new vb(e,t)}function Ab(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function xb(e){const t=Ab(e);return t+Math.ceil(t/2)}function kb(e,t,n=!1){yw(e);const r=e.length,o=Ab(t),i=xb(t);if(r<16||r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);const s=lb(n?$w(e):Ww(e),t-tb)+tb;return n?Jw(s,o):qw(s,o)}const Sb=BigInt(0),Ib=BigInt(1);function Pb(e,t){const n=t.negate();return e?n:t}function Cb(e,t){const n=wb(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Ob(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Nb(e,t){Ob(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:Zw(e),maxNumber:n,shiftBy:BigInt(e)}}function Bb(e,t,n){const{windowSize:r,mask:o,maxNumber:i,shiftBy:s}=n;let a=Number(e&o),c=e>>s;a>r&&(a-=i,c+=Ib);const u=t*r;return{nextN:c,offset:u+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:u}}const Tb=new WeakMap,Rb=new WeakMap;function Ub(e){return Rb.get(e)||1}function Db(e){if(e!==Sb)throw new Error("invalid wNAF")}class Lb{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>Sb;)t&Ib&&(n=n.add(r)),r=r.double(),t>>=Ib;return n}precomputeWindow(e,t){const{windows:n,windowSize:r}=Nb(t,this.bits),o=[];let i=e,s=i;for(let e=0;e<n;e++){s=i,o.push(s);for(let e=1;e<r;e++)s=s.add(i),o.push(s);i=s.double()}return o}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,o=this.BASE;const i=Nb(e,this.bits);for(let e=0;e<i.windows;e++){const{nextN:s,offset:a,isZero:c,isNeg:u,isNegF:l,offsetF:f}=Bb(n,e,i);n=s,c?o=o.add(Pb(l,t[f])):r=r.add(Pb(u,t[a]))}return Db(n),{p:r,f:o}}wNAFUnsafe(e,t,n,r=this.ZERO){const o=Nb(e,this.bits);for(let e=0;e<o.windows&&n!==Sb;e++){const{nextN:i,offset:s,isZero:a,isNeg:c}=Bb(n,e,o);if(n=i,!a){const e=t[s];r=r.add(c?e.negate():e)}}return Db(n),r}getPrecomputes(e,t,n){let r=Tb.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Tb.set(t,r))),r}cached(e,t,n){const r=Ub(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){const o=Ub(e);return 1===o?this._unsafeLadder(e,t,r):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),t,r)}createCache(e,t){Ob(t,this.bits),Rb.set(e,t),Tb.delete(e)}hasCache(e){return 1!==Ub(e)}}function Fb(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){Yw(e,mb.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return Eb(e,{isLE:n})}function _b(e,t){return function(n){const r=e(n);return{secretKey:r,publicKey:t(r)}}}class Mb{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(mw(e),yw(t,void 0,"key"),this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),bw(r)}update(e){return ww(this),this.iHash.update(e),this}digestInto(e){ww(this),yw(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const jb=(e,t,n)=>new Mb(e,t).update(n).digest();jb.create=(e,t)=>new Mb(e,t);const Gb=(e,t)=>(e+(e>=0?t:-t)/qb)/t;function Hb(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function zb(e,t){const n={};for(let r of Object.keys(t))n[r]=void 0===e[r]?t[r]:e[r];return Hw(n.lowS,"lowS"),Hw(n.prehash,"prehash"),void 0!==n.format&&Hb(n.format),n}class Kb extends Error{constructor(e=""){super(e)}}const Vb={Err:Kb,_tlv:{encode:(e,t)=>{const{Err:n}=Vb;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");const r=t.length/2,o=Kw(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");const i=r>127?Kw(o.length/2|128):"";return Kw(e)+i+o+t},decode(e,t){const{Err:n}=Vb;let r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");const o=t[r++];let i=0;if(128&o){const e=127&o;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)i=i<<8|e;if(r+=e,i<128)throw new n("tlv.decode(long): not minimal encoding")}else i=o;const s=t.subarray(r,r+i);if(s.length!==i)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+i)}}},_int:{encode(e){const{Err:t}=Vb;if(e<Wb)throw new t("integer: negative integers are not allowed");let n=Kw(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){const{Err:t}=Vb;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return Ww(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=Vb,o=yw(e,void 0,"signature"),{v:i,l:s}=r.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,i),{v:u,l}=r.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(e){const{_tlv:t,_int:n}=Vb,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},Wb=BigInt(0),$b=BigInt(1),qb=BigInt(2),Jb=BigInt(3),Qb=BigInt(4);function Zb(e,t={}){const n=function(e,t,n={},r){if(void 0===r&&(r="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const n=t[e];if(!("bigint"==typeof n&&n>Sb))throw new Error(`CURVE.${e} must be positive bigint`)}const o=Fb(t.p,n.Fp,r),i=Fb(t.n,n.Fn,r),s=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const e of s)if(!o.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:i}}("weierstrass",e,t),{Fp:r,Fn:o}=n;let i=n.CURVE;const{h:s,n:a}=i;Yw(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:c}=t;if(c&&(!r.is0(i.a)||"bigint"!=typeof c.beta||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Xb(r,o);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const f=t.toBytes||function(e,t,n){const{x:o,y:i}=t.toAffine(),s=r.toBytes(o);return Hw(n,"isCompressed"),n?(l(),Pw(Yb(!r.isOdd(i)),s)):Pw(Uint8Array.of(4),s,r.toBytes(i))},h=t.fromBytes||function(e){yw(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:n}=u,o=e.length,i=e[0],s=e.subarray(1);if(o!==t||2!==i&&3!==i){if(o===n&&4===i){const e=r.BYTES,t=r.fromBytes(s.subarray(0,e)),n=r.fromBytes(s.subarray(e,2*e));if(!p(t,n))throw new Error("bad point: is not on curve");return{x:t,y:n}}throw new Error(`bad point: got length ${o}, expected compressed=${t} or uncompressed=${n}`)}{const e=r.fromBytes(s);if(!r.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=d(e);let n;try{n=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}return l(),!(1&~i)!==r.isOdd(n)&&(n=r.neg(n)),{x:e,y:n}}};function d(e){const t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,i.a)),i.b)}function p(e,t){const n=r.sqr(t),o=d(e);return r.eql(n,o)}if(!p(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const g=r.mul(r.pow(i.a,Jb),Qb),y=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(g,y)))throw new Error("bad curve params: a or b");function m(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function w(e){if(!(e instanceof x))throw new Error("Weierstrass Point expected")}function b(e){if(!c||!c.basises)throw new Error("no endo");return function(e,t,n){const[[r,o],[i,s]]=t,a=Gb(s*e,n),c=Gb(-o*e,n);let u=e-a*r-c*i,l=-a*o-c*s;const f=u<Wb,h=l<Wb;f&&(u=-u),h&&(l=-l);const d=Zw(Math.ceil(function(e){let t;for(t=0;e>jw;e>>=Gw,t+=1);return t}(n)/2))+$b;if(u<Wb||u>=d||l<Wb||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:u,k2neg:h,k2:l}}(e,c.basises,o.ORDER)}const v=Xw((e,t)=>{const{X:n,Y:o,Z:i}=e;if(r.eql(i,r.ONE))return{x:n,y:o};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(i));const a=r.mul(n,t),c=r.mul(o,t),u=r.mul(i,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw new Error("invZ was invalid");return{x:a,y:c}}),E=Xw(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:n,y:o}=e.toAffine();if(!r.isValid(n)||!r.isValid(o))throw new Error("bad point: x or y not field elements");if(!p(n,o))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(e,t,n,o,i){return n=new x(r.mul(n.X,e),n.Y,n.Z),t=Pb(o,t),n=Pb(i,n),t.add(n)}class x{static BASE=new x(i.Gx,i.Gy,r.ONE);static ZERO=new x(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=o;X;Y;Z;constructor(e,t,n){this.X=m("x",e),this.Y=m("y",t,!0),this.Z=m("z",n),Object.freeze(this)}static CURVE(){return i}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof x)throw new Error("projective point not allowed");return r.is0(t)&&r.is0(n)?x.ZERO:new x(t,n,r.ONE)}static fromBytes(e){const t=x.fromAffine(h(yw(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return x.fromBytes(Iw(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return S.createCache(this,e),t||this.multiply(Jb),this}assertValidity(){E(this)}hasEvenY(){const{y:e}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(e)}equals(e){w(e);const{X:t,Y:n,Z:o}=this,{X:i,Y:s,Z:a}=e,c=r.eql(r.mul(t,a),r.mul(i,o)),u=r.eql(r.mul(n,a),r.mul(s,o));return c&&u}negate(){return new x(this.X,r.neg(this.Y),this.Z)}double(){const{a:e,b:t}=i,n=r.mul(t,Jb),{X:o,Y:s,Z:a}=this;let c=r.ZERO,u=r.ZERO,l=r.ZERO,f=r.mul(o,o),h=r.mul(s,s),d=r.mul(a,a),p=r.mul(o,s);return p=r.add(p,p),l=r.mul(o,a),l=r.add(l,l),c=r.mul(e,l),u=r.mul(n,d),u=r.add(c,u),c=r.sub(h,u),u=r.add(h,u),u=r.mul(c,u),c=r.mul(p,c),l=r.mul(n,l),d=r.mul(e,d),p=r.sub(f,d),p=r.mul(e,p),p=r.add(p,l),l=r.add(f,f),f=r.add(l,f),f=r.add(f,d),f=r.mul(f,p),u=r.add(u,f),d=r.mul(s,a),d=r.add(d,d),f=r.mul(d,p),c=r.sub(c,f),l=r.mul(d,h),l=r.add(l,l),l=r.add(l,l),new x(c,u,l)}add(e){w(e);const{X:t,Y:n,Z:o}=this,{X:s,Y:a,Z:c}=e;let u=r.ZERO,l=r.ZERO,f=r.ZERO;const h=i.a,d=r.mul(i.b,Jb);let p=r.mul(t,s),g=r.mul(n,a),y=r.mul(o,c),m=r.add(t,n),b=r.add(s,a);m=r.mul(m,b),b=r.add(p,g),m=r.sub(m,b),b=r.add(t,o);let v=r.add(s,c);return b=r.mul(b,v),v=r.add(p,y),b=r.sub(b,v),v=r.add(n,o),u=r.add(a,c),v=r.mul(v,u),u=r.add(g,y),v=r.sub(v,u),f=r.mul(h,b),u=r.mul(d,y),f=r.add(u,f),u=r.sub(g,f),f=r.add(g,f),l=r.mul(u,f),g=r.add(p,p),g=r.add(g,p),y=r.mul(h,y),b=r.mul(d,b),g=r.add(g,y),y=r.sub(p,y),y=r.mul(h,y),b=r.add(b,y),p=r.mul(g,b),l=r.add(l,p),p=r.mul(v,b),u=r.mul(m,u),u=r.sub(u,p),p=r.mul(m,g),f=r.mul(v,f),f=r.add(f,p),new x(u,l,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(x.ZERO)}multiply(e){const{endo:n}=t;if(!o.isValidNot0(e))throw new Error("invalid scalar: out of range");let r,i;const s=e=>S.cached(this,e,e=>Cb(x,e));if(n){const{k1neg:t,k1:o,k2neg:a,k2:c}=b(e),{p:u,f:l}=s(o),{p:f,f:h}=s(c);i=l.add(h),r=A(n.beta,u,f,t,a)}else{const{p:t,f:n}=s(e);r=t,i=n}return Cb(x,[r,i])[0]}multiplyUnsafe(e){const{endo:n}=t,r=this;if(!o.isValid(e))throw new Error("invalid scalar: out of range");if(e===Wb||r.is0())return x.ZERO;if(e===$b)return r;if(S.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:o,k2neg:i,k2:s}=b(e),{p1:a,p2:c}=function(e,t,n,r){let o=t,i=e.ZERO,s=e.ZERO;for(;n>Sb||r>Sb;)n&Ib&&(i=i.add(o)),r&Ib&&(s=s.add(o)),o=o.double(),n>>=Ib,r>>=Ib;return{p1:i,p2:s}}(x,r,o,s);return A(n.beta,a,c,t,i)}return S.unsafe(r,e)}toAffine(e){return v(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===$b||(e?e(x,this):S.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===$b?this:e?e(x,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return Hw(e,"isCompressed"),this.assertValidity(),f(x,this,e)}toHex(e=!0){return kw(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const k=o.BITS,S=new Lb(x,t.endo?Math.ceil(k/2):k);return x.BASE.precompute(8),x}function Yb(e){return Uint8Array.of(e?2:3)}function Xb(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ev(e,t,n={}){mw(t),Yw(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=(n=Object.assign({},n)).randomBytes||Ow,o=n.hmac||((e,n)=>jb(t,e,n)),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d}=function(e,t={}){const{Fn:n}=e,r=t.randomBytes||Ow,o=Object.assign(Xb(e.Fp,n),{seed:xb(n.ORDER)});function i(e=r(o.seed)){return kb(yw(e,o.seed,"seed"),n.ORDER)}function s(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function a(e){const{secretKey:t,publicKey:r,publicKeyUncompressed:i}=o;if(!pw(e))return;if("_lengths"in n&&n._lengths||t===r)return;const s=yw(e,void 0,"key").length;return s===r||s===i}const c={isValidSecretKey:function(e){try{const t=n.fromBytes(e);return n.isValidNot0(t)}catch(e){return!1}},isValidPublicKey:function(t,n){const{publicKey:r,publicKeyUncompressed:i}=o;try{const o=t.length;return!(!0===n&&o!==r||!1===n&&o!==i||!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:i},u=_b(i,s);return Object.freeze({getPublicKey:s,getSharedSecret:function(t,r,o=!0){if(!0===a(t))throw new Error("first arg must be private key");if(!1===a(r))throw new Error("second arg must be public key");const i=n.fromBytes(t);return e.fromBytes(r).multiply(i).toBytes(o)},keygen:u,Point:e,utils:c,lengths:o})}(e,n),p={prehash:!0,lowS:"boolean"!=typeof n.lowS||n.lowS,format:"compact",extraEntropy:!1},g=a*qb<i.ORDER;function y(e){return e>a>>$b}function m(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function w(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function b(e,t){Hb(t);const n=d.signature;return yw(e,"compact"===t?n:"recovered"===t?n+1:void 0)}class v{r;s;recovery;constructor(e,t,n){if(this.r=m("r",e),this.s=m("s",t),null!=n){if(w(),![0,1,2,3].includes(n))throw new Error("invalid recovery id");this.recovery=n}Object.freeze(this)}static fromBytes(e,t=p.format){let n;if(b(e,t),"der"===t){const{r:t,s:n}=Vb.toSig(yw(e));return new v(t,n)}"recovered"===t&&(n=e[0],t="compact",e=e.subarray(1));const r=d.signature/2,o=e.subarray(0,r),i=e.subarray(r,2*r);return new v(s.fromBytes(o),s.fromBytes(i),n)}static fromHex(e,t){return this.fromBytes(Iw(e),t)}assertRecovery(){const{recovery:e}=this;if(null==e)throw new Error("invalid recovery id: must be present");return e}addRecoveryBit(e){return new v(this.r,this.s,e)}recoverPublicKey(t){const{r:n,s:r}=this,o=this.assertRecovery(),c=2===o||3===o?n+a:n;if(!i.isValid(c))throw new Error("invalid recovery id: sig.r+curve.n != R.x");const u=i.toBytes(c),l=e.fromBytes(Pw(Yb(!(1&o)),u)),f=s.inv(c),h=A(yw(t,void 0,"msgHash")),d=s.create(-h*f),p=s.create(r*f),g=e.BASE.multiplyUnsafe(d).add(l.multiplyUnsafe(p));if(g.is0())throw new Error("invalid recovery: point at infinify");return g.assertValidity(),g}hasHighS(){return y(this.s)}toBytes(e=p.format){if(Hb(e),"der"===e)return Iw(Vb.hexFromSig(this));const{r:t,s:n}=this,r=s.toBytes(t),o=s.toBytes(n);return"recovered"===e?(w(),Pw(Uint8Array.of(this.assertRecovery()),r,o)):Pw(r,o)}toHex(e){return kw(this.toBytes(e))}}const E=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=Ww(e),n=8*e.length-c;return n>0?t>>BigInt(n):t},A=n.bits2int_modN||function(e){return s.create(E(e))},x=Zw(c);function k(e){return function(e,t,n,r){if(!function(e,t,n){return Qw(e)&&Qw(t)&&Qw(n)&&t<=e&&e<n}(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}("num < 2^"+c,e,Wb,x),s.toBytes(e)}function S(e,n){return yw(e,void 0,"message"),n?yw(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d,Point:e,sign:function(n,i,a={}){const{seed:c,k2sig:u}=function(t,n,o){const{lowS:i,prehash:a,extraEntropy:c}=zb(o,p);t=S(t,a);const u=A(t),l=s.fromBytes(n);if(!s.isValidNot0(l))throw new Error("invalid private key");const f=[k(l),k(u)];if(null!=c&&!1!==c){const e=!0===c?r(d.secretKey):c;f.push(yw(e,void 0,"extraEntropy"))}const h=Pw(...f),m=u;return{seed:h,k2sig:function(t){const n=E(t);if(!s.isValidNot0(n))return;const r=s.inv(n),o=e.BASE.multiply(n).toAffine(),a=s.create(o.x);if(a===Wb)return;const c=s.create(r*s.create(m+a*l));if(c===Wb)return;let u=(o.x===a?0:2)|Number(o.y&$b),f=c;return i&&y(c)&&(f=s.neg(c),u^=1),new v(a,f,g?void 0:u)}}}(n,i,a),l=function(e,t,n){if(gw(e,"hashLen"),gw(t,"qByteLen"),"function"!=typeof n)throw new Error("hmacFn must be a function");const r=e=>new Uint8Array(e),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1);let a=r(e),c=r(e),u=0;const l=()=>{a.fill(1),c.fill(0),u=0},f=(...e)=>n(c,Pw(a,...e)),h=(e=o)=>{c=f(i,e),a=f(),0!==e.length&&(c=f(s,e),a=f())},d=()=>{if(u++>=1e3)throw new Error("drbg: tried max amount of iterations");let e=0;const n=[];for(;e<t;){a=f();const t=a.slice();n.push(t),e+=a.length}return Pw(...n)};return(e,t)=>{let n;for(l(),h(e);!(n=t(d()));)h();return l(),n}}(t.outputLen,s.BYTES,o);return l(c,u).toBytes(a.format)},verify:function(t,n,r,o={}){const{lowS:i,prehash:a,format:c}=zb(o,p);if(r=yw(r,void 0,"publicKey"),n=S(n,a),!pw(t))throw new Error("verify expects Uint8Array signature"+(t instanceof v?", use sig.toBytes()":""));b(t,c);try{const o=v.fromBytes(t,c),a=e.fromBytes(r);if(i&&o.hasHighS())return!1;const{r:u,s:l}=o,f=A(n),h=s.inv(l),d=s.create(f*h),p=s.create(u*h),g=e.BASE.multiplyUnsafe(d).add(a.multiplyUnsafe(p));return!g.is0()&&s.create(g.x)===u}catch(e){return!1}},recoverPublicKey:function(e,t,n={}){const{prehash:r}=zb(n,p);return t=S(t,r),v.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:v,hash:t})}const tv={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},nv={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},rv=BigInt(0),ov=BigInt(2),iv=Eb(tv.p,{sqrt:function(e){const t=tv.p,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=fb(l,n,t)*l%t,h=fb(f,n,t)*l%t,d=fb(h,ov,t)*u%t,p=fb(d,o,t)*d%t,g=fb(p,i,t)*p%t,y=fb(g,a,t)*g%t,m=fb(y,c,t)*y%t,w=fb(m,a,t)*g%t,b=fb(w,n,t)*l%t,v=fb(b,s,t)*p%t,E=fb(v,r,t)*u%t,A=fb(E,ov,t);if(!iv.eql(iv.sqr(A),e))throw new Error("Cannot find square root");return A}}),sv=Zb(tv,{Fp:iv,endo:nv}),av=ev(sv,Mw),cv={};function uv(e,...t){let n=cv[e];if(void 0===n){const t=Mw((r=e,Uint8Array.from(r,(e,t)=>{const n=e.charCodeAt(0);if(1!==e.length||n>127)throw new Error(`string contains non-ASCII character "${r[t]}" with code ${n} at position ${t}`);return n})));n=Pw(t,t),cv[e]=n}var r;return Mw(Pw(n,...t))}const lv=e=>e.toBytes(!0).slice(1),fv=e=>e%ov===rv;function hv(e){const{Fn:t,BASE:n}=sv,r=t.fromBytes(e),o=n.multiply(r);return{scalar:fv(o.y)?r:t.neg(r),bytes:lv(o)}}function dv(e){const t=iv;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x ≥ p");const n=t.create(e*e),r=t.create(n*e+BigInt(7));let o=t.sqrt(r);fv(o)||(o=t.neg(o));const i=sv.fromAffine({x:e,y:o});return i.assertValidity(),i}const pv=Ww;function gv(...e){return sv.Fn.create(pv(uv("BIP0340/challenge",...e)))}function yv(e){return hv(e).bytes}function mv(e,t,n=Ow(32)){const{Fn:r}=sv,o=yw(e,void 0,"message"),{bytes:i,scalar:s}=hv(t),a=yw(n,32,"auxRand"),c=r.toBytes(s^pv(uv("BIP0340/aux",a))),u=uv("BIP0340/nonce",c,i,o),{bytes:l,scalar:f}=hv(u),h=gv(l,i,o),d=new Uint8Array(64);if(d.set(l,0),d.set(r.toBytes(r.create(f+h*s)),32),!wv(d,o,i))throw new Error("sign: Invalid signature produced");return d}function wv(e,t,n){const{Fp:r,Fn:o,BASE:i}=sv,s=yw(e,64,"signature"),a=yw(t,void 0,"message"),c=yw(n,32,"publicKey");try{const e=dv(pv(c)),t=pv(s.subarray(0,32));if(!r.isValidNot0(t))return!1;const n=pv(s.subarray(32,64));if(!o.isValidNot0(n))return!1;const u=gv(o.toBytes(t),lv(e),a),l=i.multiplyUnsafe(n).add(e.multiplyUnsafe(o.neg(u))),{x:f,y:h}=l.toAffine();return!(l.is0()||!fv(h)||f!==t)}catch(e){return!1}}const bv=(()=>{const e=(e=Ow(48))=>kb(e,tv.n);return{keygen:_b(e,yv),getPublicKey:yv,sign:mv,verify:wv,Point:sv,utils:{randomSecretKey:e,taggedHash:uv,lift_x:dv,pointToBytes:lv},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();function vv(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Ev(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function Av(e){if("function"!=typeof e)throw new Error("function expected");return!0}function xv(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function kv(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Sv(e){if(!Array.isArray(e))throw new Error("array expected")}function Iv(e,t){if(!Ev(!0,t))throw new Error(`${e}: array of strings expected`)}function Pv(e,t){if(!Ev(!1,t))throw new Error(`${e}: array of numbers expected`)}function Cv(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function Ov(e){const t="string"==typeof e?e.split(""):e,n=t.length;Iv("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(Sv(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(Sv(t),t.map(t=>{xv("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function Nv(e=""){return xv("join",e),{encode:t=>(Iv("join.decode",t),t.join(e)),decode:t=>(xv("join.decode",t),t.split(e))}}function Bv(e,t="="){return kv(e),xv("padding",t),{encode(n){for(Iv("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){Iv("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding");return n.slice(0,r)}}}function Tv(e){return Av(e),{encode:e=>e,decode:t=>e(t)}}function Rv(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(Sv(e),!e.length)return[];let r=0;const o=[],i=Array.from(e,e=>{if(kv(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=i.length;for(;;){let e=0,a=!0;for(let o=r;o<s;o++){const s=i[o],c=t*e,u=c+s;if(!Number.isSafeInteger(u)||c/t!==e||u-s!==c)throw new Error("convertRadix: carry overflow");const l=u/n;e=u%n;const f=Math.floor(l);if(i[o]=f,!Number.isSafeInteger(f)||f*n+e!==u)throw new Error("convertRadix: carry overflow");a&&(f?a=!1:r=o)}if(o.push(e),a)break}for(let t=0;t<e.length-1&&0===e[t];t++)o.push(0);return o.reverse()}const Uv=(e,t)=>0===t?e:Uv(t,e%t),Dv=(e,t)=>e+(t-Uv(e,t)),Lv=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Fv(e,t,n,r){if(Sv(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Dv(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Dv(t,n)}`);let o=0,i=0;const s=Lv[t],a=Lv[n]-1,c=[];for(const r of e){if(kv(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<<t|r,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=Lv[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<<n-i&a,!r&&i>=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}function _v(e,t=!1){if(kv(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Dv(8,e)>32||Dv(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!vv(n))throw new Error("radix2.encode input should be Uint8Array");return Fv(Array.from(n),8,e,!t)},decode:n=>(Pv("radix2.decode",n),Uint8Array.from(Fv(n,e,8,t)))}}function Mv(e){return Av(e),function(...t){try{return e.apply(null,t)}catch(e){}}}Cv(_v(4),Ov("0123456789ABCDEF"),Nv("")),Cv(_v(5),Ov("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Bv(5),Nv(""));const jv=(Cv(_v(5),Ov("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Nv("")),Cv(_v(5),Ov("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Bv(5),Nv("")),Cv(_v(5),Ov("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Nv("")),Cv(_v(5),Ov("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),Nv(""),Tv(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()),Gv=jv?{encode:e=>(function(e){if(!vv(e))throw new Error("Uint8Array expected")}(e),e.toBase64()),decode:e=>((e,t)=>{xv("base64",e);const n=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,r=t?"base64url":"base64";if(e.length>0&&!n.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:r,lastChunkHandling:"strict"})})(e,!1)}:Cv(_v(6),Ov("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Bv(6),Nv("")),Hv=(Cv(_v(6),Ov("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Nv("")),jv||Cv(_v(6),Ov("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Bv(6),Nv("")),Cv(_v(6),Ov("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Nv("")),e=>{return Cv((kv(t=58),{encode:e=>{if(!vv(e))throw new Error("radix.encode input should be Uint8Array");return Rv(Array.from(e),256,t)},decode:e=>(Pv("radix.decode",e),Uint8Array.from(Rv(e,t,256)))}),Ov(e),Nv(""));var t}),zv=(Hv("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Hv("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Hv("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),Cv(Ov("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Nv(""))),Kv=[996825010,642813549,513874426,1027748829,705979059];function Vv(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Kv.length;e++)1==(t>>e&1)&&(n^=Kv[e]);return n}function Wv(e,t,n=1){const r=e.length;let o=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);o=Vv(o)^n>>5}o=Vv(o);for(let t=0;t<r;t++)o=Vv(o)^31&e.charCodeAt(t);for(let e of t)o=Vv(o)^e;for(let e=0;e<6;e++)o=Vv(o);return o^=n,zv.encode(Fv([o%Lv[30]],30,5,!1))}function $v(e){const t="bech32"===e?1:734539939,n=_v(5),r=n.decode,o=n.encode,i=Mv(r);function s(e,n,r=90){xv("bech32.encode prefix",e),vv(n)&&(n=Array.from(n)),Pv("bech32.encode",n);const o=e.length;if(0===o)throw new TypeError(`Invalid prefix length ${o}`);const i=o+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);const s=e.toLowerCase(),a=Wv(s,n,t);return`${s}1${zv.encode(n)}${a}`}function a(e,n=90){xv("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);const o=e.toLowerCase();if(e!==o&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=o.lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const s=o.slice(0,i),a=o.slice(i+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const c=zv.decode(a).slice(0,-6),u=Wv(s,c,t);if(!a.endsWith(u))throw new Error(`Invalid checksum in ${e}: expected "${u}"`);return{prefix:s,words:c}}return{encode:s,decode:a,encodeFromBytes:function(e,t){return s(e,o(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Mv(a),fromWords:r,fromWordsUnsafe:i,toWords:o}}const qv=$v("bech32");function Jv(e){if("boolean"!=typeof e)throw new Error(`boolean expected, not ${e}`)}function Qv(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Zv(e,t,n=""){const r=(o=e)instanceof Uint8Array||ArrayBuffer.isView(o)&&"Uint8Array"===o.constructor.name;var o;const i=e?.length,s=void 0!==t;if(!r||s&&i!==t)throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(s?` of length ${t}`:"")+", got "+(r?`length=${i}`:"type="+typeof e));return e}function Yv(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Xv(e,t){Zv(e,void 0,"output");const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function eE(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function tE(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function nE(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}$v("bech32m"),(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)()||Cv(_v(4),Ov("0123456789abcdef"),Nv(""),Tv(e=>{if("string"!=typeof e||e.length%2!=0)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const rE=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])();function oE(e,t){if(function(e,t){return e.buffer===t.buffer&&e.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<e.byteOffset+e.byteLength}(e,t)&&e.byteOffset<t.byteOffset)throw new Error("complex overlap of input and output is not supported")}function iE(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n}const sE=(e,t)=>{function n(n,...r){if(Zv(n,void 0,"key"),!rE)throw new Error("Non little-endian hardware is not yet supported");void 0!==e.nonceLength&&Zv(r[0],e.varSizeNonce?void 0:e.nonceLength,"nonce");const o=e.tagLength;o&&void 0!==r[1]&&Zv(r[1],void 0,"AAD");const i=t(n,...r),s=(e,t)=>{if(void 0!==t){if(2!==e)throw new Error("cipher output not supported");Zv(t,void 0,"output")}};let a=!1;const c={encrypt(e,t){if(a)throw new Error("cannot encrypt() twice with same key + nonce");return a=!0,Zv(e),s(i.encrypt.length,t),i.encrypt(e,t)},decrypt(e,t){if(Zv(e),o&&e.length<o)throw new Error('"ciphertext" expected length bigger than tagLength='+o);return s(i.decrypt.length,t),i.decrypt(e,t)}};return c}return Object.assign(n,e),n};function aE(e,t,n=!0){if(void 0===t)return new Uint8Array(e);if(t.length!==e)throw new Error('"output" expected Uint8Array of length '+e+", got: "+t.length);if(n&&!cE(t))throw new Error("invalid output, must be aligned");return t}function cE(e){return e.byteOffset%4==0}function uE(e){return Uint8Array.from(e)}const lE=16,fE=new Uint8Array(16),hE=eE(fE),dE=(e,t,n,r)=>({s3:n<<31|r>>>1,s2:t<<31|n>>>1,s1:e<<31|t>>>1,s0:e>>>1^225<<24&-(1&r)}),pE=e=>(e>>>0&255)<<24|(e>>>8&255)<<16|(e>>>16&255)<<8|e>>>24&255;class gE{blockLen=lE;outputLen=lE;s0=0;s1=0;s2=0;s3=0;finished=!1;t;W;windowSize;constructor(e,t){Zv(e,16,"key");const n=nE(e=uE(e));let r=n.getUint32(0,!1),o=n.getUint32(4,!1),i=n.getUint32(8,!1),s=n.getUint32(12,!1);const a=[];for(let e=0;e<128;e++)a.push({s0:pE(r),s1:pE(o),s2:pE(i),s3:pE(s)}),({s0:r,s1:o,s2:i,s3:s}=dE(r,o,i,s));const c=(e=>e>65536?8:e>1024?4:2)(t||1024);if(![1,2,4,8].includes(c))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=c;const u=128/c,l=this.windowSize=2**c,f=[];for(let e=0;e<u;e++)for(let t=0;t<l;t++){let n=0,r=0,o=0,i=0;for(let s=0;s<c;s++){if(!(t>>>c-s-1&1))continue;const{s0:u,s1:l,s2:f,s3:h}=a[c*e+s];n^=u,r^=l,o^=f,i^=h}f.push({s0:n,s1:r,s2:o,s3:i})}this.t=f}_updateBlock(e,t,n,r){e^=this.s0,t^=this.s1,n^=this.s2,r^=this.s3;const{W:o,t:i,windowSize:s}=this;let a=0,c=0,u=0,l=0;const f=(1<<o)-1;let h=0;for(const d of[e,t,n,r])for(let e=0;e<4;e++){const t=d>>>8*e&255;for(let e=8/o-1;e>=0;e--){const n=t>>>o*e&f,{s0:r,s1:d,s2:p,s3:g}=i[h*s+n];a^=r,c^=d,u^=p,l^=g,h+=1}}this.s0=a,this.s1=c,this.s2=u,this.s3=l}update(e){Yv(this),Zv(e);const t=eE(e=uE(e)),n=Math.floor(e.length/lE),r=e.length%lE;for(let e=0;e<n;e++)this._updateBlock(t[4*e+0],t[4*e+1],t[4*e+2],t[4*e+3]);return r&&(fE.set(e.subarray(n*lE)),this._updateBlock(hE[0],hE[1],hE[2],hE[3]),tE(hE)),this}destroy(){const{t:e}=this;for(const t of e)t.s0=0,t.s1=0,t.s2=0,t.s3=0}digestInto(e){Yv(this),Xv(e,this),this.finished=!0;const{s0:t,s1:n,s2:r,s3:o}=this,i=eE(e);return i[0]=t,i[1]=n,i[2]=r,i[3]=o,e}digest(){const e=new Uint8Array(lE);return this.digestInto(e),this.destroy(),e}}class yE extends gE{constructor(e,t){Zv(e);const n=function(e){e.reverse();const t=1&e[15];let n=0;for(let t=0;t<e.length;t++){const r=e[t];e[t]=r>>>1|n,n=(1&r)<<7}return e[0]^=225&-t,e}(uE(e));super(n,t),tE(n)}update(e){Yv(this),Zv(e);const t=eE(e=uE(e)),n=e.length%lE,r=Math.floor(e.length/lE);for(let e=0;e<r;e++)this._updateBlock(pE(t[4*e+3]),pE(t[4*e+2]),pE(t[4*e+1]),pE(t[4*e+0]));return n&&(fE.set(e.subarray(r*lE)),this._updateBlock(pE(hE[3]),pE(hE[2]),pE(hE[1]),pE(hE[0])),tE(hE)),this}digestInto(e){Yv(this),Xv(e,this),this.finished=!0;const{s0:t,s1:n,s2:r,s3:o}=this,i=eE(e);return i[0]=t,i[1]=n,i[2]=r,i[3]=o,e.reverse()}}function mE(e){const t=(t,n)=>e(n,t.length).update(t).digest(),n=e(new Uint8Array(16),0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=(t,n)=>e(t,n),t}mE((e,t)=>new gE(e,t)),mE((e,t)=>new yE(e,t));const wE=16;function bE(e){if(![16,24,32].includes(e.length))throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length='+e.length)}function vE(e){return e<<1^283&-(e>>7)}function EE(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(1&t),e=vE(e);return n}const AE=(()=>{const e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=vE(n))e[t]=n;const t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=255&(r^r>>4^r>>5^r>>6^r>>7^99)}return tE(e),t})(),xE=AE.map((e,t)=>AE.indexOf(t)),kE=e=>e<<24|e>>>8,SE=e=>e<<8|e>>>24;function IE(e,t){if(256!==e.length)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((n,r)=>t(e[r])),r=n.map(SE),o=r.map(SE),i=o.map(SE),s=new Uint32Array(65536),a=new Uint32Array(65536),c=new Uint16Array(65536);for(let t=0;t<256;t++)for(let u=0;u<256;u++){const l=256*t+u;s[l]=n[t]^r[u],a[l]=o[t]^i[u],c[l]=e[t]<<8|e[u]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:o,T3:i,T01:s,T23:a}}const PE=IE(AE,e=>EE(e,3)<<24|e<<16|e<<8|EE(e,2)),CE=IE(xE,e=>EE(e,11)<<24|EE(e,13)<<16|EE(e,9)<<8|EE(e,14)),OE=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=vE(n))e[t]=n;return e})();function NE(e){Zv(e);const t=e.length;bE(e);const{sbox2:n}=PE,r=[];cE(e)||r.push(e=uE(e));const o=eE(e),i=o.length,s=e=>TE(n,e,e,e,e),a=new Uint32Array(t+28);a.set(o);for(let e=i;e<a.length;e++){let t=a[e-1];e%i===0?t=s(kE(t))^OE[e/i-1]:i>6&&e%i===4&&(t=s(t)),a[e]=a[e-i]^t}return tE(...r),a}function BE(e,t,n,r,o,i){return e[n<<8&65280|r>>>8&255]^t[o>>>8&65280|i>>>24&255]}function TE(e,t,n,r,o){return e[255&t|65280&n]|e[r>>>16&255|o>>>16&65280]<<16}function RE(e,t,n,r,o){const{sbox2:i,T01:s,T23:a}=PE;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];const u=e.length/4-2;for(let i=0;i<u;i++){const i=e[c++]^BE(s,a,t,n,r,o),u=e[c++]^BE(s,a,n,r,o,t),l=e[c++]^BE(s,a,r,o,t,n),f=e[c++]^BE(s,a,o,t,n,r);t=i,n=u,r=l,o=f}return{s0:e[c++]^TE(i,t,n,r,o),s1:e[c++]^TE(i,n,r,o,t),s2:e[c++]^TE(i,r,o,t,n),s3:e[c++]^TE(i,o,t,n,r)}}function UE(e,t,n,r,o){const{sbox2:i,T01:s,T23:a}=CE;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];const u=e.length/4-2;for(let i=0;i<u;i++){const i=e[c++]^BE(s,a,t,o,r,n),u=e[c++]^BE(s,a,n,t,o,r),l=e[c++]^BE(s,a,r,n,t,o),f=e[c++]^BE(s,a,o,r,n,t);t=i,n=u,r=l,o=f}return{s0:e[c++]^TE(i,t,o,r,n),s1:e[c++]^TE(i,n,t,o,r),s2:e[c++]^TE(i,r,n,t,o),s3:e[c++]^TE(i,o,r,n,t)}}const DE=sE({blockSize:16,nonceLength:16},function(e,t,n={}){const r=!n.disablePadding;return{encrypt(n,o){const i=NE(e),{b:s,o:a,out:c}=function(e,t,n){Zv(e);let r=e.length;const o=r%wE;if(!t&&0!==o)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");cE(e)||(e=uE(e));const i=eE(e);if(t){let e=wE-o;e||(e=wE),r+=e}return oE(e,n=aE(r,n)),{b:i,o:eE(n),out:n}}(n,r,o);let u=t;const l=[i];cE(u)||l.push(u=uE(u));const f=eE(u);let h=f[0],d=f[1],p=f[2],g=f[3],y=0;for(;y+4<=s.length;)h^=s[y+0],d^=s[y+1],p^=s[y+2],g^=s[y+3],({s0:h,s1:d,s2:p,s3:g}=RE(i,h,d,p,g)),a[y++]=h,a[y++]=d,a[y++]=p,a[y++]=g;if(r){const e=function(e){const t=new Uint8Array(16),n=eE(t);t.set(e);const r=wE-e.length;for(let e=wE-r;e<wE;e++)t[e]=r;return n}(n.subarray(4*y));h^=e[0],d^=e[1],p^=e[2],g^=e[3],({s0:h,s1:d,s2:p,s3:g}=RE(i,h,d,p,g)),a[y++]=h,a[y++]=d,a[y++]=p,a[y++]=g}return tE(...l),c},decrypt(n,o){!function(e){if(Zv(e),e.length%wE!==0)throw new Error("aes-(cbc/ecb).decrypt ciphertext should consist of blocks with size 16")}(n);const i=function(e){const t=NE(e),n=t.slice(),r=t.length,{sbox2:o}=PE,{T0:i,T1:s,T2:a,T3:c}=CE;for(let e=0;e<r;e+=4)for(let o=0;o<4;o++)n[e+o]=t[r-e-4+o];tE(t);for(let e=4;e<r-4;e++){const t=n[e],r=TE(o,t,t,t,t);n[e]=i[255&r]^s[r>>>8&255]^a[r>>>16&255]^c[r>>>24]}return n}(e);let s=t;const a=[i];cE(s)||a.push(s=uE(s));const c=eE(s);o=aE(n.length,o),cE(n)||a.push(n=uE(n)),oE(n,o);const u=eE(n),l=eE(o);let f=c[0],h=c[1],d=c[2],p=c[3];for(let e=0;e+4<=u.length;){const t=f,n=h,r=d,o=p;f=u[e+0],h=u[e+1],d=u[e+2],p=u[e+3];const{s0:s,s1:a,s2:c,s3:g}=UE(i,f,h,d,p);l[e++]=s^t,l[e++]=a^n,l[e++]=c^r,l[e++]=g^o}return tE(...a),function(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error("aes/pcks5: wrong padding");const o=e.subarray(0,-r);for(let t=0;t<r;t++)if(e[n-t-1]!==r)throw new Error("aes/pcks5: wrong padding");return o}(o,r)}}});const LE=e=>Uint8Array.from(e.split(""),e=>e.charCodeAt(0)),FE=LE("expand 16-byte k"),_E=LE("expand 32-byte k"),ME=eE(FE),jE=eE(_E);function GE(e,t){return e<<t|e>>>32-t}function HE(e){return e.byteOffset%4==0}const zE=2**32-1,KE=Uint32Array.of();function VE(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:i,rounds:s}=function(e,t){if(null==t||"object"!=typeof t)throw new Error("options must be defined");return Object.assign({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t)}(0,t);if("function"!=typeof e)throw new Error("core must be a function");return Qv(o),Qv(s),Jv(i),Jv(n),(t,a,c,u,l=0)=>{Zv(t,void 0,"key"),Zv(a,void 0,"nonce"),Zv(c,void 0,"data");const f=c.length;if(void 0===u&&(u=new Uint8Array(f)),Zv(u,void 0,"output"),Qv(l),l<0||l>=zE)throw new Error("arx: counter overflow");if(u.length<f)throw new Error(`arx: output (${u.length}) is shorter than data (${f})`);const h=[];let d,p,g=t.length;if(32===g)h.push(d=uE(t)),p=jE;else{if(16!==g||!n)throw Zv(t,32,"arx key"),new Error("invalid key size");d=new Uint8Array(32),d.set(t),d.set(t,16),p=ME,h.push(d)}HE(a)||h.push(a=uE(a));const y=eE(d);if(r){if(24!==a.length)throw new Error("arx: extended nonce must be 24 bytes");r(p,y,eE(a.subarray(0,16)),y),a=a.subarray(16)}const m=16-o;if(m!==a.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(12!==m){const e=new Uint8Array(12);e.set(a,i?0:12-a.length),a=e,h.push(a)}const w=eE(a);return function(e,t,n,r,o,i,s,a){const c=o.length,u=new Uint8Array(64),l=eE(u),f=HE(o)&&HE(i),h=f?eE(o):KE,d=f?eE(i):KE;for(let p=0;p<c;s++){if(e(t,n,r,l,s,a),s>=zE)throw new Error("arx: counter overflow");const g=Math.min(64,c-p);if(f&&64===g){const e=p/4;if(p%4!=0)throw new Error("arx: invalid block position");for(let t,n=0;n<16;n++)t=e+n,d[t]=h[t]^l[n];p+=64;continue}for(let e,t=0;t<g;t++)e=p+t,i[e]=o[e]^u[t];p+=g}}(e,p,y,w,c,u,l,s),tE(...h),u}}function WE(e,t){return 255&e[t++]|(255&e[t++])<<8}class $E{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;constructor(e){const t=WE(e=uE(Zv(e,32,"key")),0),n=WE(e,2),r=WE(e,4),o=WE(e,6),i=WE(e,8),s=WE(e,10),a=WE(e,12),c=WE(e,14);this.r[0]=8191&t,this.r[1]=8191&(t>>>13|n<<3),this.r[2]=7939&(n>>>10|r<<6),this.r[3]=8191&(r>>>7|o<<9),this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,this.r[6]=8191&(i>>>14|s<<2),this.r[7]=8065&(s>>>11|a<<5),this.r[8]=8191&(a>>>8|c<<8),this.r[9]=c>>>5&127;for(let t=0;t<8;t++)this.pad[t]=WE(e,16+2*t)}process(e,t,n=!1){const r=n?0:2048,{h:o,r:i}=this,s=i[0],a=i[1],c=i[2],u=i[3],l=i[4],f=i[5],h=i[6],d=i[7],p=i[8],g=i[9],y=WE(e,t+0),m=WE(e,t+2),w=WE(e,t+4),b=WE(e,t+6),v=WE(e,t+8),E=WE(e,t+10),A=WE(e,t+12),x=WE(e,t+14);let k=o[0]+(8191&y),S=o[1]+(8191&(y>>>13|m<<3)),I=o[2]+(8191&(m>>>10|w<<6)),P=o[3]+(8191&(w>>>7|b<<9)),C=o[4]+(8191&(b>>>4|v<<12)),O=o[5]+(v>>>1&8191),N=o[6]+(8191&(v>>>14|E<<2)),B=o[7]+(8191&(E>>>11|A<<5)),T=o[8]+(8191&(A>>>8|x<<8)),R=o[9]+(x>>>5|r),U=0,D=U+k*s+S*(5*g)+I*(5*p)+P*(5*d)+C*(5*h);U=D>>>13,D&=8191,D+=O*(5*f)+N*(5*l)+B*(5*u)+T*(5*c)+R*(5*a),U+=D>>>13,D&=8191;let L=U+k*a+S*s+I*(5*g)+P*(5*p)+C*(5*d);U=L>>>13,L&=8191,L+=O*(5*h)+N*(5*f)+B*(5*l)+T*(5*u)+R*(5*c),U+=L>>>13,L&=8191;let F=U+k*c+S*a+I*s+P*(5*g)+C*(5*p);U=F>>>13,F&=8191,F+=O*(5*d)+N*(5*h)+B*(5*f)+T*(5*l)+R*(5*u),U+=F>>>13,F&=8191;let _=U+k*u+S*c+I*a+P*s+C*(5*g);U=_>>>13,_&=8191,_+=O*(5*p)+N*(5*d)+B*(5*h)+T*(5*f)+R*(5*l),U+=_>>>13,_&=8191;let M=U+k*l+S*u+I*c+P*a+C*s;U=M>>>13,M&=8191,M+=O*(5*g)+N*(5*p)+B*(5*d)+T*(5*h)+R*(5*f),U+=M>>>13,M&=8191;let j=U+k*f+S*l+I*u+P*c+C*a;U=j>>>13,j&=8191,j+=O*s+N*(5*g)+B*(5*p)+T*(5*d)+R*(5*h),U+=j>>>13,j&=8191;let G=U+k*h+S*f+I*l+P*u+C*c;U=G>>>13,G&=8191,G+=O*a+N*s+B*(5*g)+T*(5*p)+R*(5*d),U+=G>>>13,G&=8191;let H=U+k*d+S*h+I*f+P*l+C*u;U=H>>>13,H&=8191,H+=O*c+N*a+B*s+T*(5*g)+R*(5*p),U+=H>>>13,H&=8191;let z=U+k*p+S*d+I*h+P*f+C*l;U=z>>>13,z&=8191,z+=O*u+N*c+B*a+T*s+R*(5*g),U+=z>>>13,z&=8191;let K=U+k*g+S*p+I*d+P*h+C*f;U=K>>>13,K&=8191,K+=O*l+N*u+B*c+T*a+R*s,U+=K>>>13,K&=8191,U=(U<<2)+U|0,U=U+D|0,D=8191&U,U>>>=13,L+=U,o[0]=D,o[1]=L,o[2]=F,o[3]=_,o[4]=M,o[5]=j,o[6]=G,o[7]=H,o[8]=z,o[9]=K}finalize(){const{h:e,pad:t}=this,n=new Uint16Array(10);let r=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=r,r=e[t]>>>13,e[t]&=8191;e[0]+=5*r,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(let t=1;t<10;t++)n[t]=e[t]+r,r=n[t]>>>13,n[t]&=8191;n[9]-=8192;let o=(1^r)-1;for(let e=0;e<10;e++)n[e]&=o;o=~o;for(let t=0;t<10;t++)e[t]=e[t]&o|n[t];e[0]=65535&(e[0]|e[1]<<13),e[1]=65535&(e[1]>>>3|e[2]<<10),e[2]=65535&(e[2]>>>6|e[3]<<7),e[3]=65535&(e[3]>>>9|e[4]<<4),e[4]=65535&(e[4]>>>12|e[5]<<1|e[6]<<14),e[5]=65535&(e[6]>>>2|e[7]<<11),e[6]=65535&(e[7]>>>5|e[8]<<8),e[7]=65535&(e[8]>>>8|e[9]<<5);let i=e[0]+t[0];e[0]=65535&i;for(let n=1;n<8;n++)i=(e[n]+t[n]|0)+(i>>>16)|0,e[n]=65535&i;tE(n)}update(e){Yv(this),Zv(e),e=uE(e);const{buffer:t,blockLen:n}=this,r=e.length;for(let o=0;o<r;){const i=Math.min(n-this.pos,r-o);if(i!==n)t.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(t,0,!1),this.pos=0);else for(;n<=r-o;o+=n)this.process(e,o)}return this}destroy(){tE(this.h,this.r,this.buffer,this.pad)}digestInto(e){Yv(this),Xv(e,this),this.finished=!0;const{buffer:t,h:n}=this;let{pos:r}=this;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();let o=0;for(let t=0;t<8;t++)e[o++]=n[t]>>>0,e[o++]=n[t]>>>8;return e}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}}const qE=(()=>function(e){const t=(t,n)=>e(n).update(t).digest(),n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t}(e=>new $E(e)))();function JE(e,t,n,r,o,i=20){let s=e[0],a=e[1],c=e[2],u=e[3],l=t[0],f=t[1],h=t[2],d=t[3],p=t[4],g=t[5],y=t[6],m=t[7],w=o,b=n[0],v=n[1],E=n[2],A=s,x=a,k=c,S=u,I=l,P=f,C=h,O=d,N=p,B=g,T=y,R=m,U=w,D=b,L=v,F=E;for(let e=0;e<i;e+=2)A=A+I|0,U=GE(U^A,16),N=N+U|0,I=GE(I^N,12),A=A+I|0,U=GE(U^A,8),N=N+U|0,I=GE(I^N,7),x=x+P|0,D=GE(D^x,16),B=B+D|0,P=GE(P^B,12),x=x+P|0,D=GE(D^x,8),B=B+D|0,P=GE(P^B,7),k=k+C|0,L=GE(L^k,16),T=T+L|0,C=GE(C^T,12),k=k+C|0,L=GE(L^k,8),T=T+L|0,C=GE(C^T,7),S=S+O|0,F=GE(F^S,16),R=R+F|0,O=GE(O^R,12),S=S+O|0,F=GE(F^S,8),R=R+F|0,O=GE(O^R,7),A=A+P|0,F=GE(F^A,16),T=T+F|0,P=GE(P^T,12),A=A+P|0,F=GE(F^A,8),T=T+F|0,P=GE(P^T,7),x=x+C|0,U=GE(U^x,16),R=R+U|0,C=GE(C^R,12),x=x+C|0,U=GE(U^x,8),R=R+U|0,C=GE(C^R,7),k=k+O|0,D=GE(D^k,16),N=N+D|0,O=GE(O^N,12),k=k+O|0,D=GE(D^k,8),N=N+D|0,O=GE(O^N,7),S=S+I|0,L=GE(L^S,16),B=B+L|0,I=GE(I^B,12),S=S+I|0,L=GE(L^S,8),B=B+L|0,I=GE(I^B,7);let _=0;r[_++]=s+A|0,r[_++]=a+x|0,r[_++]=c+k|0,r[_++]=u+S|0,r[_++]=l+I|0,r[_++]=f+P|0,r[_++]=h+C|0,r[_++]=d+O|0,r[_++]=p+N|0,r[_++]=g+B|0,r[_++]=y+T|0,r[_++]=m+R|0,r[_++]=w+U|0,r[_++]=b+D|0,r[_++]=v+L|0,r[_++]=E+F|0}const QE=VE(JE,{counterRight:!1,counterLength:4,allowShortKeys:!1}),ZE=VE(JE,{counterRight:!1,counterLength:8,extendNonceFn:function(e,t,n,r){let o=e[0],i=e[1],s=e[2],a=e[3],c=t[0],u=t[1],l=t[2],f=t[3],h=t[4],d=t[5],p=t[6],g=t[7],y=n[0],m=n[1],w=n[2],b=n[3];for(let e=0;e<20;e+=2)o=o+c|0,y=GE(y^o,16),h=h+y|0,c=GE(c^h,12),o=o+c|0,y=GE(y^o,8),h=h+y|0,c=GE(c^h,7),i=i+u|0,m=GE(m^i,16),d=d+m|0,u=GE(u^d,12),i=i+u|0,m=GE(m^i,8),d=d+m|0,u=GE(u^d,7),s=s+l|0,w=GE(w^s,16),p=p+w|0,l=GE(l^p,12),s=s+l|0,w=GE(w^s,8),p=p+w|0,l=GE(l^p,7),a=a+f|0,b=GE(b^a,16),g=g+b|0,f=GE(f^g,12),a=a+f|0,b=GE(b^a,8),g=g+b|0,f=GE(f^g,7),o=o+u|0,b=GE(b^o,16),p=p+b|0,u=GE(u^p,12),o=o+u|0,b=GE(b^o,8),p=p+b|0,u=GE(u^p,7),i=i+l|0,y=GE(y^i,16),g=g+y|0,l=GE(l^g,12),i=i+l|0,y=GE(y^i,8),g=g+y|0,l=GE(l^g,7),s=s+f|0,m=GE(m^s,16),h=h+m|0,f=GE(f^h,12),s=s+f|0,m=GE(m^s,8),h=h+m|0,f=GE(f^h,7),a=a+c|0,w=GE(w^a,16),d=d+w|0,c=GE(c^d,12),a=a+c|0,w=GE(w^a,8),d=d+w|0,c=GE(c^d,7);let v=0;r[v++]=o,r[v++]=i,r[v++]=s,r[v++]=a,r[v++]=y,r[v++]=m,r[v++]=w,r[v++]=b},allowShortKeys:!1}),YE=new Uint8Array(16),XE=(e,t)=>{e.update(t);const n=t.length%16;n&&e.update(YE.subarray(n))},eA=new Uint8Array(32);function tA(e,t,n,r,o){void 0!==o&&Zv(o,void 0,"AAD");const i=e(t,n,eA),s=function(e,t,n){Jv(n);const r=new Uint8Array(16),o=nE(r);return o.setBigUint64(0,BigInt(t),n),o.setBigUint64(8,BigInt(e),n),r}(r.length,o?o.length:0,!0),a=qE.create(i);o&&XE(a,o),XE(a,r),a.update(s);const c=a.digest();return tE(i,s),c}const nA=e=>(t,n,r)=>({encrypt(o,i){const s=o.length;(i=aE(s+16,i,!1)).set(o);const a=i.subarray(0,-16);e(t,n,a,a,1);const c=tA(e,t,n,a,r);return i.set(c,s),tE(c),i},decrypt(o,i){i=aE(o.length-16,i,!1);const s=o.subarray(0,-16),a=o.subarray(-16),c=tA(e,t,n,s,r);if(!iE(a,c))throw new Error("invalid tag");return i.set(o.subarray(0,-16)),e(t,n,i,i,1),tE(c),i}});nA(QE),nA(ZE);const rA=Uint8Array.of(0),oA=Uint8Array.of();var iA=Object.defineProperty,sA=(e,t)=>{for(var n in t)iA(e,n,{get:t[n],enumerable:!0})},aA=Symbol("verified");function cA(e){if(!(e instanceof Object))return!1;if("number"!=typeof e.kind)return!1;if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if("string"!=typeof e.pubkey)return!1;if(!e.pubkey.match(/^[a-f0-9]{64}$/))return!1;if(!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let e=0;e<n.length;e++)if("string"!=typeof n[e])return!1}return!0}var uA={};sA(uA,{binarySearch:()=>gA,bytesToHex:()=>kw,hexToBytes:()=>Iw,insertEventIntoAscendingList:()=>pA,insertEventIntoDescendingList:()=>dA,mergeReverseSortedLists:()=>yA,normalizeURL:()=>hA,utf8Decoder:()=>lA,utf8Encoder:()=>fA});var lA=new TextDecoder("utf-8"),fA=new TextEncoder;function hA(e){try{-1===e.indexOf("://")&&(e="wss://"+e);let t=new URL(e);return"http:"===t.protocol?t.protocol="ws:":"https:"===t.protocol&&(t.protocol="wss:"),t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),("80"===t.port&&"ws:"===t.protocol||"443"===t.port&&"wss:"===t.protocol)&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch(t){throw new Error(`Invalid URL: ${e}`)}}function dA(e,t){const[n,r]=gA(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:e.created_at-t.created_at);return r||e.splice(n,0,t),e}function pA(e,t){const[n,r]=gA(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:t.created_at-e.created_at);return r||e.splice(n,0,t),e}function gA(e,t){let n=0,r=e.length-1;for(;n<=r;){const o=Math.floor((n+r)/2),i=t(e[o]);if(0===i)return[o,!0];i<0?r=o-1:n=o+1}return[n,!1]}function yA(e,t){const n=new Array(e.length+t.length);n.length=0;let r=0,o=0,i=[];for(;r<e.length&&o<t.length;){let s;if(e[r]?.created_at>t[o]?.created_at?(s=e[r],r++):(s=t[o],o++),n.length>0&&n[n.length-1].created_at===s.created_at){if(i.includes(s.id))continue}else i.length=0;n.push(s),i.push(s.id)}for(;r<e.length;){const t=e[r];if(r++,n.length>0&&n[n.length-1].created_at===t.created_at){if(i.includes(t.id))continue}else i.length=0;n.push(t),i.push(t.id)}for(;o<t.length;){const e=t[o];if(o++,n.length>0&&n[n.length-1].created_at===e.created_at){if(i.includes(e.id))continue}else i.length=0;n.push(e),i.push(e.id)}return n}function mA(e){return kw(Mw(fA.encode(function(e){if(!cA(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}(e))))}var wA=new class{generateSecretKey(){return bv.utils.randomSecretKey()}getPublicKey(e){return kw(bv.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=kw(bv.getPublicKey(t)),n.id=mA(n),n.sig=kw(bv.sign(Iw(mA(n)),t)),n[aA]=!0,n}verifyEvent(e){if("boolean"==typeof e[aA])return e[aA];try{const t=mA(e);if(t!==e.id)return e[aA]=!1,!1;const n=bv.verify(Iw(e.sig),Iw(t),Iw(e.pubkey));return e[aA]=n,n}catch(t){return e[aA]=!1,!1}}},bA=wA.generateSecretKey,vA=wA.getPublicKey,EA=wA.finalizeEvent,AA=wA.verifyEvent;function xA(e){return e<1e4&&0!==e&&3!==e}function kA(e){return 0===e||3===e||1e4<=e&&e<2e4}function SA(e){return 2e4<=e&&e<3e4}function IA(e){return 3e4<=e&&e<4e4}function PA(e){return xA(e)?"regular":kA(e)?"replaceable":SA(e)?"ephemeral":IA(e)?"parameterized":"unknown"}function CA(e,t){const n=t instanceof Array?t:[t];return cA(e)&&n.includes(e.kind)||!1}sA({},{Application:()=>Xx,BadgeAward:()=>FA,BadgeDefinition:()=>Wx,BlockedRelaysList:()=>Sx,BlossomServerList:()=>Tx,BookmarkList:()=>Ax,Bookmarksets:()=>zx,Calendar:()=>sk,CalendarEventRSVP:()=>ak,ChannelCreation:()=>$A,ChannelHideMessage:()=>QA,ChannelMessage:()=>JA,ChannelMetadata:()=>qA,ChannelMuteUser:()=>ZA,ChatMessage:()=>_A,ClassifiedListing:()=>nk,ClientAuth:()=>Dx,Comment:()=>nx,CommunitiesList:()=>xx,CommunityDefinition:()=>fk,CommunityPostApproval:()=>lx,Contacts:()=>TA,CreateOrUpdateProduct:()=>Jx,CreateOrUpdateStall:()=>qx,Curationsets:()=>Kx,Date:()=>ok,DirectMessageRelaysList:()=>Nx,DraftClassifiedListing:()=>rk,DraftLong:()=>Zx,Emojisets:()=>Yx,EncryptedDirectMessage:()=>RA,EventDeletion:()=>UA,FavoriteRelays:()=>Px,FileMessage:()=>HA,FileMetadata:()=>tx,FileServerPreference:()=>Bx,Followsets:()=>jx,ForumThread:()=>MA,GenericRepost:()=>zA,Genericlists:()=>Gx,GiftWrap:()=>XA,GroupMetadata:()=>hk,HTTPAuth:()=>Mx,Handlerinformation:()=>lk,Handlerrecommendation:()=>uk,Highlights:()=>mx,InterestsList:()=>Cx,Interestsets:()=>$x,JobFeedback:()=>dx,JobRequest:()=>fx,JobResult:()=>hx,Label:()=>ux,LightningPubRPC:()=>Ux,LiveChatMessage:()=>rx,LiveEvent:()=>ek,LongFormArticle:()=>Qx,Metadata:()=>OA,Mutelist:()=>bx,NWCWalletInfo:()=>Rx,NWCWalletRequest:()=>Lx,NWCWalletResponse:()=>Fx,NormalVideo:()=>VA,NostrConnect:()=>_x,OpenTimestamps:()=>YA,Photo:()=>KA,Pinlist:()=>vx,Poll:()=>ex,PollResponse:()=>wx,PrivateDirectMessage:()=>GA,ProblemTracker:()=>sx,ProfileBadges:()=>Vx,PublicChatsList:()=>kx,Reaction:()=>LA,RecommendRelay:()=>BA,RelayList:()=>Ex,RelayReview:()=>ck,Relaysets:()=>Hx,Report:()=>ax,Reporting:()=>cx,Repost:()=>DA,Seal:()=>jA,SearchRelaysList:()=>Ix,ShortTextNote:()=>NA,ShortVideo:()=>WA,Time:()=>ik,UserEmojiList:()=>Ox,UserStatuses:()=>tk,Voice:()=>ox,VoiceComment:()=>ix,Zap:()=>yx,ZapGoal:()=>px,ZapRequest:()=>gx,classifyKind:()=>PA,isAddressableKind:()=>IA,isEphemeralKind:()=>SA,isKind:()=>CA,isRegularKind:()=>xA,isReplaceableKind:()=>kA});var OA=0,NA=1,BA=2,TA=3,RA=4,UA=5,DA=6,LA=7,FA=8,_A=9,MA=11,jA=13,GA=14,HA=15,zA=16,KA=20,VA=21,WA=22,$A=40,qA=41,JA=42,QA=43,ZA=44,YA=1040,XA=1059,ex=1068,tx=1063,nx=1111,rx=1311,ox=1222,ix=1244,sx=1971,ax=1984,cx=1984,ux=1985,lx=4550,fx=5999,hx=6999,dx=7e3,px=9041,gx=9734,yx=9735,mx=9802,wx=1018,bx=1e4,vx=10001,Ex=10002,Ax=10003,xx=10004,kx=10005,Sx=10006,Ix=10007,Px=10012,Cx=10015,Ox=10030,Nx=10050,Bx=10096,Tx=10063,Rx=13194,Ux=21e3,Dx=22242,Lx=23194,Fx=23195,_x=24133,Mx=27235,jx=3e4,Gx=30001,Hx=30002,zx=30003,Kx=30004,Vx=30008,Wx=30009,$x=30015,qx=30017,Jx=30018,Qx=30023,Zx=30024,Yx=30030,Xx=30078,ek=30311,tk=30315,nk=30402,rk=30403,ok=31922,ik=31923,sk=31924,ak=31925,ck=31987,uk=31989,lk=31990,fk=34550,hk=39e3;function dk(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,o=e.slice(r).indexOf('"')+r+1;return e.slice(o,o+64)}function pk(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,o=e.slice(r),i=Math.min(o.indexOf(","),o.indexOf("}"));return parseInt(o.slice(0,i),10)}function gk(e){let t=e.slice(0,22).indexOf('"EVENT"');if(-1===t)return null;let n=e.slice(t+7+1).indexOf('"');if(-1===n)return null;let r=t+7+1+n,o=e.slice(r+1,80).indexOf('"');if(-1===o)return null;let i=r+1+o;return e.slice(r+1,i)}function yk(e,t){return t===dk(e,"id")}function mk(e,t){return t===dk(e,"pubkey")}function wk(e,t){return t===pk(e,"kind")}function bk(e,t){return{kind:Dx,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}sA({},{getHex64:()=>dk,getInt:()=>pk,getSubscriptionId:()=>gk,matchEventId:()=>yk,matchEventKind:()=>wk,matchEventPubkey:()=>mk}),sA({},{makeAuthEvent:()=>bk}),Error;try{WebSocket}catch{}try{WebSocket}catch{}sA({},{BECH32_REGEX:()=>Ak,Bech32MaxSize:()=>Ek,NostrTypeGuard:()=>vk,decode:()=>kk,decodeNostrURI:()=>xk,encodeBytes:()=>Nk,naddrEncode:()=>Rk,neventEncode:()=>Tk,noteEncode:()=>Ck,nprofileEncode:()=>Bk,npubEncode:()=>Pk,nsecEncode:()=>Ik});var vk={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Ek=5e3,Ak=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function xk(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),kk(e)}catch(e){return{type:"invalid",data:null}}}function kk(e){let{prefix:t,words:n}=qv.decode(e,Ek),r=new Uint8Array(qv.fromWords(n));switch(t){case"nprofile":{let e=Sk(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nprofile");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:kw(e[0][0]),relays:e[1]?e[1].map(e=>lA.decode(e)):[]}}}case"nevent":{let e=Sk(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nevent");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");if(e[2]&&32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(e[3]&&4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:kw(e[0][0]),relays:e[1]?e[1].map(e=>lA.decode(e)):[],author:e[2]?.[0]?kw(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(kw(e[3][0]),16):void 0}}}case"naddr":{let e=Sk(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for naddr");if(!e[2]?.[0])throw new Error("missing TLV 2 for naddr");if(32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(!e[3]?.[0])throw new Error("missing TLV 3 for naddr");if(4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:lA.decode(e[0][0]),pubkey:kw(e[2][0]),kind:parseInt(kw(e[3][0]),16),relays:e[1]?e[1].map(e=>lA.decode(e)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:kw(r)};default:throw new Error(`unknown prefix ${t}`)}}function Sk(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],o=n.slice(2,2+r);if(n=n.slice(2+r),o.length<r)throw new Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(o)}return t}function Ik(e){return Nk("nsec",e)}function Pk(e){return Nk("npub",Iw(e))}function Ck(e){return Nk("note",Iw(e))}function Ok(e,t){let n=qv.toWords(t);return qv.encode(e,n,Ek)}function Nk(e,t){return Ok(e,t)}function Bk(e){return Ok("nprofile",Uk({0:[Iw(e.pubkey)],1:(e.relays||[]).map(e=>fA.encode(e))}))}function Tk(e){let t;return void 0!==e.kind&&(t=function(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=255&e,t}(e.kind)),Ok("nevent",Uk({0:[Iw(e.id)],1:(e.relays||[]).map(e=>fA.encode(e)),2:e.author?[Iw(e.author)]:[],3:t?[new Uint8Array(t)]:[]}))}function Rk(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),Ok("naddr",Uk({0:[fA.encode(e.identifier)],1:(e.relays||[]).map(e=>fA.encode(e)),2:[Iw(e.pubkey)],3:[new Uint8Array(t)]}))}function Uk(e){let t=[];return Object.entries(e).reverse().forEach(([e,n])=>{n.forEach(n=>{let r=new Uint8Array(n.length+2);r.set([parseInt(e)],0),r.set([n.length],1),r.set(n,2),t.push(r)})}),Pw(...t)}function Dk(e,t,n){const r=e instanceof Uint8Array?e:Iw(e),o=Fk(av.getSharedSecret(r,Iw("02"+t)));let i=Uint8Array.from(Ow(16)),s=fA.encode(n),a=DE(o,i).encrypt(s);return`${Gv.encode(new Uint8Array(a))}?iv=${Gv.encode(new Uint8Array(i.buffer))}`}function Lk(e,t,n){const r=e instanceof Uint8Array?e:Iw(e);let[o,i]=n.split("?iv="),s=Fk(av.getSharedSecret(r,Iw("02"+t))),a=Gv.decode(i),c=Gv.decode(o),u=DE(s,a).decrypt(c);return lA.decode(u)}function Fk(e){return e.slice(1,33)}sA({},{decrypt:()=>Lk,encrypt:()=>Dk}),sA({},{NIP05_REGEX:()=>Mk,isNip05:()=>jk,isValid:()=>Kk,queryProfile:()=>zk,searchDomain:()=>Hk,useFetchImplementation:()=>Gk});var _k,Mk=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,jk=e=>Mk.test(e||"");try{_k=fetch}catch(e){}function Gk(e){_k=e}async function Hk(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await _k(n,{redirect:"manual"});if(200!==r.status)throw Error("Wrong response code");return(await r.json()).names}catch(e){return{}}}async function zk(e){const t=e.match(Mk);if(!t)return null;const[,n="_",r]=t;try{const e=`https://${r}/.well-known/nostr.json?name=${n}`,t=await _k(e,{redirect:"manual"});if(200!==t.status)throw Error("Wrong response code");const o=await t.json(),i=o.names[n];return i?{pubkey:i,relays:o.relays?.[i]}:null}catch(e){return null}}async function Kk(e,t){const n=await zk(t);return!!n&&n.pubkey===e}function Vk(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let o=e.tags.length-1;o>=0;o--){const i=e.tags[o];if("e"===i[0]&&i[1]){const[e,o,s,a,c]=i,u={id:o,relays:s?[s]:[],author:c};if("root"===a){t.root=u;continue}if("reply"===a){t.reply=u;continue}if("mention"===a){t.mentions.push(u);continue}n?r=u:n=u,t.mentions.push(u);continue}if("q"===i[0]&&i[1]){const[e,n,r]=i;t.quotes.push({id:n,relays:r?[r]:[]})}"p"===i[0]&&i[1]&&t.profiles.push({pubkey:i[1],relays:i[2]?[i[2]]:[]})}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(e=>{if(!e)return;let n=t.mentions.indexOf(e);if(-1!==n&&t.mentions.splice(n,1),e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays?.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t.mentions.forEach(e=>{if(e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t}sA({},{parse:()=>Vk}),sA({},{fetchRelayInformation:()=>$k,useFetchImplementation:()=>Wk});try{fetch}catch{}function Wk(e){}async function $k(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}function qk(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(0!==r){t+=Math.clz32(r);break}t+=32}return t}function Jk(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(0!==r){t+=Math.clz32(r)-24;break}t+=8}return t}function Qk(e,t){let n=0;const r=e,o=["nonce",n.toString(),t.toString()];for(r.tags.push(o);;){const e=Math.floor((new Date).getTime()/1e3);e!==r.created_at&&(n=0,r.created_at=e),o[1]=(++n).toString();const i=Mw(fA.encode(JSON.stringify([0,r.pubkey,r.created_at,r.kind,r.tags,r.content])));if(Jk(i)>=t){r.id=kw(i);break}}return r}sA({},{getPow:()=>qk,minePow:()=>Qk}),sA({},{unwrapEvent:()=>vS,unwrapManyEvents:()=>ES,wrapEvent:()=>wS,wrapManyEvents:()=>bS}),sA({},{createRumor:()=>fS,createSeal:()=>hS,createWrap:()=>dS,unwrapEvent:()=>yS,unwrapManyEvents:()=>mS,wrapEvent:()=>pS,wrapManyEvents:()=>gS}),sA({},{decrypt:()=>oS,encrypt:()=>rS,getConversationKey:()=>Xk,v2:()=>iS});var Zk=1,Yk=65535;function Xk(e,t){const n=av.getSharedSecret(e,Iw("02"+t)).subarray(1,33);return r=Mw,o=n,i=fA.encode("nip44-v2"),mw(r),void 0===i&&(i=new Uint8Array(r.outputLen)),jb(r,i,o);var r,o,i}function eS(e,t){const n=function(e,t,n,r=32){mw(e),gw(r,"length");const o=e.outputLen;if(r>255*o)throw new Error("Length must be <= 255*HashLen");const i=Math.ceil(r/o);void 0===n?n=oA:yw(n,void 0,"info");const s=new Uint8Array(i*o),a=jb.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let e=0;e<i;e++)rA[0]=e+1,c.update(0===e?oA:u).update(n).update(rA).digestInto(u),s.set(u,o*e),a._cloneInto(c);return a.destroy(),c.destroy(),bw(u,rA),s.slice(0,r)}(Mw,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function tS(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function nS(e,t,n){if(32!==n.length)throw new Error("AAD associated data must be 32 bytes");const r=Pw(n,t);return jb(Mw,e,r)}function rS(e,t,n=Ow(32)){const{chacha_key:r,chacha_nonce:o,hmac_key:i}=eS(t,n),s=function(e){const t=fA.encode(e),n=t.length;return Pw(function(e){if(!Number.isSafeInteger(e)||e<Zk||e>Yk)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}(n),t,new Uint8Array(tS(n)-n))}(e),a=QE(r,o,s),c=nS(i,a,n);return Gv.encode(Pw(new Uint8Array([2]),n,a,c))}function oS(e,t){const{nonce:n,ciphertext:r,mac:o}=function(e){if("string"!=typeof e)throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if("#"===e[0])throw new Error("unknown encryption version");let n;try{n=Gv.decode(e)}catch(e){throw new Error("invalid base64: "+e.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const o=n[0];if(2!==o)throw new Error("unknown encryption version "+o);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}(e),{chacha_key:i,chacha_nonce:s,hmac_key:a}=eS(t,n);if(!iE(nS(a,r,n),o))throw new Error("invalid MAC");return function(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<Zk||t>Yk||n.length!==t||e.length!==2+tS(t))throw new Error("invalid padding");return lA.decode(n)}(QE(i,s,r))}var iS={utils:{getConversationKey:Xk,calcPaddedLen:tS},encrypt:rS,decrypt:oS},sS=()=>Math.round(Date.now()/1e3),aS=()=>Math.round(sS()-172800*Math.random()),cS=(e,t)=>Xk(e,t),uS=(e,t,n)=>rS(JSON.stringify(e),cS(t,n)),lS=(e,t)=>JSON.parse(oS(e.content,cS(t,e.pubkey)));function fS(e,t){const n={created_at:sS(),content:"",tags:[],...e,pubkey:vA(t)};return n.id=mA(n),n}function hS(e,t,n){return EA({kind:jA,content:uS(e,t,n),created_at:aS(),tags:[]},t)}function dS(e,t){const n=bA();return EA({kind:XA,content:uS(e,n,t),created_at:aS(),tags:[["p",t]]},n)}function pS(e,t,n){return dS(hS(fS(e,t),t,n),n)}function gS(e,t,n){if(!n||0===n.length)throw new Error("At least one recipient is required.");const r=vA(t),o=[pS(e,t,r)];return n.forEach(n=>{o.push(pS(e,t,n))}),o}function yS(e,t){const n=lS(e,t);return lS(n,t)}function mS(e,t){let n=[];return e.forEach(e=>{n.push(yS(e,t))}),n.sort((e,t)=>e.created_at-t.created_at),n}function wS(e,t,n,r,o){const i=function(e,t,n,r){const o={created_at:Math.ceil(Date.now()/1e3),kind:GA,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:e,relayUrl:t})=>{o.tags.push(t?["p",e,t]:["p",e])}),r&&o.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&o.tags.push(["subject",n]),o}(t,n,r,o);return pS(i,e,t.publicKey)}function bS(e,t,n,r,o){if(!t||0===t.length)throw new Error("At least one recipient is required.");return[{publicKey:vA(e)},...t].map(t=>wS(e,t,n,r,o))}var vS=yS,ES=mS;function AS(e,t,n,r){let o;const i=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===NA?o=DA:(o=zA,i.push(["k",String(t.kind)])),EA({kind:o,tags:i,content:""===e.content||t.tags?.find(e=>"-"===e[0])?"":JSON.stringify(t),created_at:e.created_at},r)}function xS(e){if(![DA,zA].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const o=e.tags[r];o.length>=2&&("e"===o[0]&&void 0===t?t=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==t?{id:t[1],relays:[t[2],n?.[2]].filter(e=>"string"==typeof e),author:n?.[1]}:void 0}function kS(e,{skipVerification:t}={}){const n=xS(e);if(void 0===n||""===e.content)return;let r;try{r=JSON.parse(e.content)}catch(e){return}return r.id===n.id&&(t||AA(r))?r:void 0}sA({},{finishRepostEvent:()=>AS,getRepostedEvent:()=>kS,getRepostedEventPointer:()=>xS}),sA({},{NOSTR_URI_REGEX:()=>SS,parse:()=>PS,test:()=>IS});var SS=new RegExp(`nostr:(${Ak.source})`);function IS(e){return"string"==typeof e&&new RegExp(`^${SS.source}$`).test(e)}function PS(e){const t=e.match(new RegExp(`^${SS.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:kk(t[1])}}function CS(e,t,n){const r=t.tags.filter(e=>e.length>=2&&("e"===e[0]||"p"===e[0]));return EA({...e,kind:LA,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function OS(e){if(e.kind!==LA)return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const o=e.tags[r];o.length>=2&&("e"===o[0]&&void 0===t?t=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==t&&void 0!==n?{id:t[1],relays:[t[2],n[2]].filter(e=>void 0!==e),author:n[1]}:void 0}sA({},{finishReactionEvent:()=>CS,getReactedEventPointer:()=>OS}),sA({},{parse:()=>RS});var NS=/\W/m,BS=/[^\w\/] |[^\w\/]$|$|,| /m,TS=42;function*RS(e){let t=[];if("string"!=typeof e){for(let n=0;n<e.tags.length;n++){const r=e.tags[n];"emoji"===r[0]&&r.length>=3&&t.push({type:"emoji",shortcode:r[1],url:r[2]})}e=e.content}const n=e.length;let r=0,o=0;e:for(;o<n;){const i=e.indexOf(":",o),s=e.indexOf("#",o);if(-1===i&&-1===s)break e;if(-1===i||s>=0&&s<i){if(0===s||e[s-1].match(NS)){const t=e.slice(s+1,s+TS).match(NS),i=t?s+1+t.index:n;yield{type:"text",text:e.slice(r,s)},yield{type:"hashtag",value:e.slice(s+1,i)},o=i,r=o;continue e}o=s+1}else if("nostr"===e.slice(i-5,i)){const t=e.slice(i+60).match(NS),s=t?i+60+t.index:n;try{let t,{data:n,type:a}=kk(e.slice(i+1,s));switch(a){case"npub":t={pubkey:n};break;case"note":t={id:n};break;case"nsec":o=s+1;continue;default:t=n}r!==i-5&&(yield{type:"text",text:e.slice(r,i-5)}),yield{type:"reference",pointer:t},o=s,r=o;continue e}catch(e){o=i+1;continue e}}else if("https"===e.slice(i-5,i)||"http"===e.slice(i-4,i)){const t=e.slice(i+4).match(BS),s=t?i+4+t.index:n,a="s"===e[i-1]?5:4;try{let t=new URL(e.slice(i-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid url");if(r!==i-a&&(yield{type:"text",text:e.slice(r,i-a)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(t.pathname)){yield{type:"image",url:t.toString()},o=s,r=o;continue e}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(t.pathname)){yield{type:"video",url:t.toString()},o=s,r=o;continue e}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(t.pathname)){yield{type:"audio",url:t.toString()},o=s,r=o;continue e}yield{type:"url",url:t.toString()},o=s,r=o;continue e}catch(e){o=s+1;continue e}}else{if("wss"!==e.slice(i-3,i)&&"ws"!==e.slice(i-2,i)){for(let n=0;n<t.length;n++){const s=t[n];if(":"===e[i+s.shortcode.length+1]&&e.slice(i+1,i+s.shortcode.length+1)===s.shortcode){r!==i&&(yield{type:"text",text:e.slice(r,i)}),yield s,o=i+s.shortcode.length+2,r=o;continue e}}o=i+1;continue e}{const t=e.slice(i+4).match(BS),s=t?i+4+t.index:n,a="s"===e[i-1]?3:2;try{let t=new URL(e.slice(i-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid ws url");r!==i-a&&(yield{type:"text",text:e.slice(r,i-a)}),yield{type:"relay",url:t.toString()},o=s,r=o;continue e}catch(e){o=s+1;continue e}}}}r!==n&&(yield{type:"text",text:e.slice(r)})}sA({},{channelCreateEvent:()=>US,channelHideMessageEvent:()=>FS,channelMessageEvent:()=>LS,channelMetadataEvent:()=>DS,channelMuteUserEvent:()=>_S});var US=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return EA({kind:$A,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},DS=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return EA({kind:qA,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},LS=(e,t)=>{const n=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&n.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),EA({kind:JA,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},FS=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return EA({kind:QA,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},_S=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return EA({kind:ZA,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)};sA({},{EMOJI_SHORTCODE_REGEX:()=>GS,matchAll:()=>zS,regex:()=>HS,replaceAll:()=>KS});var MS,jS,GS=/:(\w+):/,HS=()=>new RegExp(`\\B${GS.source}\\B`,"g");function*zS(e){const t=e.matchAll(HS());for(const e of t)try{const[t,n]=e;yield{shortcode:t,name:n,start:e.index,end:e.index+t.length}}catch(e){}}function KS(e,t){return e.replaceAll(HS(),(e,n)=>t({shortcode:e,name:n}))}sA({},{useFetchImplementation:()=>VS,validateGithub:()=>WS});try{MS=fetch}catch{}function VS(e){MS=e}async function WS(e,t,n){try{return await(await MS(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch(e){return!1}}function $S(e){const{host:t,pathname:n,searchParams:r}=new URL(e),o=n||t,i=r.get("relay"),s=r.get("secret");if(!o||!i||!s)throw new Error("invalid connection string");return{pubkey:o,relay:i,secret:s}}async function qS(e,t,n){const r={method:"pay_invoice",params:{invoice:n}},o=Dk(t,e,JSON.stringify(r)),i={kind:Lx,created_at:Math.round(Date.now()/1e3),content:o,tags:[["p",e]]};return EA(i,t)}function JS(e){return e=(e=e.trim().toLowerCase()).normalize("NFKC"),Array.from(e).map(e=>/\p{Letter}/u.test(e)||/\p{Number}/u.test(e)?e:"-").join("")}sA({},{makeNwcRequestEvent:()=>qS,parseConnectionString:()=>$S}),sA({},{normalizeIdentifier:()=>JS}),sA({},{getSatoshisAmountFromBolt11:()=>tI,getZapEndpoint:()=>ZS,makeZapReceipt:()=>eI,makeZapRequest:()=>YS,useFetchImplementation:()=>QS,validateZapRequest:()=>XS});try{jS=fetch}catch{}function QS(e){jS=e}async function ZS(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(r){let[e,n]=r.split("@");t=new URL(`/.well-known/lnurlp/${e}`,`https://${n}`).toString()}else{if(!n)return null;{let{words:e}=qv.decode(n,1e3),r=qv.fromWords(e);t=lA.decode(r)}}let o=await jS(t),i=await o.json();if(i.allowsNostr&&i.nostrPubkey)return i.callback}catch(e){}return null}function YS(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),kA(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(IA(e.event.kind)){let n=e.event.tags.find(([e,t])=>"d"===e&&t);if(!n)throw new Error("d tag not found or is empty");const r=["a",`${e.event.kind}:${e.event.pubkey}:${n[1]}`];t.tags.push(r)}t.tags.push(["k",e.event.kind.toString()])}return t}function XS(e){let t;try{t=JSON.parse(e)}catch(e){return"Invalid zap request JSON."}if(!cA(t))return"Zap request is not a valid Nostr event.";if(!AA(t))return"Invalid signature on zap request.";let n=t.tags.find(([e,t])=>"p"===e&&t);if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=t.tags.find(([e,t])=>"e"===e&&t);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([e,t])=>"relays"===e&&t)?null:"Zap request doesn't have a 'relays' tag."}function eI({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let o=JSON.parse(e),i=o.tags.filter(([e])=>"e"===e||"p"===e||"a"===e),s={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...i,["P",o.pubkey],["bolt11",n],["description",e]]};return t&&s.tags.push(["preimage",t]),s}function tI(e){if(e.length<50)return 0;const t=(e=e.substring(0,50)).lastIndexOf("1");if(-1===t)return 0;const n=e.substring(0,t);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const o=r[r.length-1],i=o.charCodeAt(0)-"0".charCodeAt(0),s=i>=0&&i<=9;let a=r.length-1;if(s&&a++,a<1)return 0;const c=parseInt(r.substring(0,a));switch(o){case"m":return 1e5*c;case"u":return 100*c;case"n":return c/10;case"p":return c/1e4;default:return 1e8*c}}sA({},{Negentropy:()=>uI,NegentropyStorageVector:()=>cI,NegentropySync:()=>hI});var nI=32,rI=class{_raw;length;constructor(e){"number"==typeof e?(this._raw=new Uint8Array(e),this.length=0):e instanceof Uint8Array?(this._raw=new Uint8Array(e),this.length=e.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(e){if(e instanceof rI&&(e=e.unwrap()),"number"!=typeof e.length)throw Error("bad length");const t=e.length+this.length;if(this.capacity<t){const e=this._raw,n=Math.max(2*this.capacity,t);this._raw=new Uint8Array(n),this._raw.set(e)}this._raw.set(e,this.length),this.length+=e.length}shift(){const e=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,e}shiftN(e=1){const t=this._raw.subarray(0,e);return this._raw=this._raw.subarray(e),this.length-=e,t}};function oI(e){let t=0;for(;;){if(0===e.length)throw Error("parse ends prematurely");let n=e.shift();if(t=t<<7|127&n,!(128&n))break}return t}function iI(e){if(0===e)return new rI(new Uint8Array([0]));let t=[];for(;0!==e;)t.push(127&e),e>>>=7;t.reverse();for(let e=0;e<t.length-1;e++)t[e]|=128;return new rI(new Uint8Array(t))}function sI(e,t){if(e.length<t)throw Error("parse ends prematurely");return e.shiftN(t)}var aI=class{buf;constructor(){this.setToZero()}setToZero(){this.buf=new Uint8Array(nI)}add(e){let t=0,n=0,r=new DataView(this.buf.buffer),o=new DataView(e.buffer);for(let e=0;e<8;e++){let i=4*e,s=r.getUint32(i,!0);s+=t,s+=o.getUint32(i,!0),s>4294967295&&(n=1),r.setUint32(i,4294967295&s,!0),t=n,n=0}}negate(){let e=new DataView(this.buf.buffer);for(let t=0;t<8;t++){let n=4*t;e.setUint32(n,~e.getUint32(n,!0))}let t=new Uint8Array(nI);t[0]=1,this.add(t)}getFingerprint(e){let t=new rI;return t.extend(this.buf),t.extend(iI(e)),Mw(t.unwrap()).subarray(0,16)}},cI=class{items;sealed;constructor(){this.items=[],this.sealed=!1}insert(e,t){if(this.sealed)throw Error("already sealed");const n=Iw(t);if(n.byteLength!==nI)throw Error("bad id size for added item");this.items.push({timestamp:e,id:n})}seal(){if(this.sealed)throw Error("already sealed");this.sealed=!0,this.items.sort(fI);for(let e=1;e<this.items.length;e++)if(0===fI(this.items[e-1],this.items[e]))throw Error("duplicate item inserted")}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(e){if(this._checkSealed(),e>=this.items.length)throw Error("out of range");return this.items[e]}iterate(e,t,n){this._checkSealed(),this._checkBounds(e,t);for(let r=e;r<t&&n(this.items[r],r);++r);}findLowerBound(e,t,n){return this._checkSealed(),this._checkBounds(e,t),this._binarySearch(this.items,e,t,e=>fI(e,n)<0)}fingerprint(e,t){let n=new aI;return n.setToZero(),this.iterate(e,t,e=>(n.add(e.id),!0)),n.getFingerprint(t-e)}_checkSealed(){if(!this.sealed)throw Error("not sealed")}_checkBounds(e,t){if(e>t||t>this.items.length)throw Error("bad range")}_binarySearch(e,t,n,r){let o=n-t;for(;o>0;){let n=t,i=Math.floor(o/2);n+=i,r(e[n])?(t=++n,o-=i+1):o=i}return t}},uI=class{storage;frameSizeLimit;lastTimestampIn;lastTimestampOut;constructor(e,t=6e4){if(t<4096)throw Error("frameSizeLimit too small");this.storage=e,this.frameSizeLimit=t,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(e,t){return{timestamp:e,id:t||new Uint8Array(0)}}initiate(){let e=new rI;return e.extend(new Uint8Array([97])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),e),kw(e.unwrap())}reconcile(e,t,n){const r=new rI(Iw(e));this.lastTimestampIn=this.lastTimestampOut=0;let o=new rI;o.extend(new Uint8Array([97]));let i=sI(r,1)[0];if(i<96||i>111)throw Error("invalid negentropy protocol version byte");if(97!==i)throw Error("unsupported negentropy protocol version requested: "+(i-96));let s=this.storage.size(),a=this._bound(0),c=0,u=!1;for(;0!==r.length;){let e=new rI,i=()=>{u&&(u=!1,e.extend(this.encodeBound(a)),e.extend(iI(0)))},l=this.decodeBound(r),f=oI(r),h=c,d=this.storage.findLowerBound(c,s,l);if(0===f)u=!0;else if(1===f)0!==lI(sI(r,16),this.storage.fingerprint(h,d))?(i(),this.splitRange(h,d,l,e)):u=!0;else{if(2!==f)throw Error("unexpected mode");{let e=oI(r),o={};for(let t=0;t<e;t++){let e=sI(r,nI);o[kw(e)]=e}if(u=!0,this.storage.iterate(h,d,e=>{let n=e.id;const r=kw(n);return o[r]?delete o[kw(n)]:t?.(r),!0}),n)for(let e of Object.values(o))n(kw(e))}}if(this.exceededFrameSizeLimit(o.length+e.length)){let e=this.storage.fingerprint(d,s);o.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),o.extend(iI(1)),o.extend(e);break}o.extend(e),c=d,a=l}return 1===o.length?null:kw(o.unwrap())}splitRange(e,t,n,r){let o=t-e;if(o<32)r.extend(this.encodeBound(n)),r.extend(iI(2)),r.extend(iI(o)),this.storage.iterate(e,t,e=>(r.extend(e.id),!0));else{let i=Math.floor(o/16),s=o%16,a=e;for(let e=0;e<16;e++){let o,c=i+(e<s?1:0),u=this.storage.fingerprint(a,a+c);if(a+=c,a===t)o=n;else{let e,t;this.storage.iterate(a-1,a+1,(n,r)=>(r===a-1?e=n:t=n,!0)),o=this.getMinimalBound(e,t)}r.extend(this.encodeBound(o)),r.extend(iI(1)),r.extend(u)}}}exceededFrameSizeLimit(e){return e>this.frameSizeLimit-200}decodeTimestampIn(e){let t=oI(e);return t=0===t?Number.MAX_VALUE:t-1,this.lastTimestampIn===Number.MAX_VALUE||t===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(t+=this.lastTimestampIn,this.lastTimestampIn=t,t)}decodeBound(e){let t=this.decodeTimestampIn(e),n=oI(e);if(n>nI)throw Error("bound key too long");return{timestamp:t,id:sI(e,n)}}encodeTimestampOut(e){if(e===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,iI(0);let t=e;return e-=this.lastTimestampOut,this.lastTimestampOut=t,iI(e+1)}encodeBound(e){let t=new rI;return t.extend(this.encodeTimestampOut(e.timestamp)),t.extend(iI(e.id.length)),t.extend(e.id),t}getMinimalBound(e,t){if(t.timestamp!==e.timestamp)return this._bound(t.timestamp);{let n=0,r=t.id,o=e.id;for(let e=0;e<nI&&r[e]===o[e];e++)n++;return this._bound(t.timestamp,t.id.subarray(0,n+1))}}};function lI(e,t){for(let n=0;n<e.byteLength;n++){if(e[n]<t[n])return-1;if(e[n]>t[n])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function fI(e,t){return e.timestamp===t.timestamp?lI(e.id,t.id):e.timestamp-t.timestamp}var hI=class{relay;storage;neg;filter;subscription;onhave;onneed;constructor(e,t,n,r={}){this.relay=e,this.storage=t,this.neg=new uI(t),this.onhave=r.onhave,this.onneed=r.onneed,this.filter=n,this.subscription=this.relay.prepareSubscription([{}],{label:r.label||"negentropy"}),this.subscription.oncustom=e=>{switch(e[0]){case"NEG-MSG":e.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${e}`);try{const t=this.neg.reconcile(e[2],this.onhave,this.onneed);t?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${t}"]`):(this.close(),r.onclose?.())}catch(e){console.error("negentropy reconcile error:",e),r?.onclose?.(`reconcile error: ${e}`)}break;case"NEG-CLOSE":{const t=e[2];console.warn("negentropy error:",t),r.onclose?.(t);break}case"NEG-ERR":r.onclose?.()}}}async start(){const e=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${e}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}};sA({},{getToken:()=>pI,hashPayload:()=>EI,unpackEventFromToken:()=>yI,validateEvent:()=>xI,validateEventKind:()=>wI,validateEventMethodTag:()=>vI,validateEventPayloadTag:()=>AI,validateEventTimestamp:()=>mI,validateEventUrlTag:()=>bI,validateToken:()=>gI});var dI="Nostr ";async function pI(e,t,n,r=!1,o){const i={kind:Mx,tags:[["u",e],["method",t]],created_at:Math.round((new Date).getTime()/1e3),content:""};o&&i.tags.push(["payload",EI(o)]);const s=await n(i);return(r?dI:"")+Gv.encode(fA.encode(JSON.stringify(s)))}async function gI(e,t,n){const r=await yI(e).catch(e=>{throw e});return await xI(r,t,n).catch(e=>{throw e})}async function yI(e){if(!e)throw new Error("Missing token");e=e.replace(dI,"");const t=lA.decode(Gv.decode(e));if(!t||0===t.length||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function mI(e){return!!e.created_at&&Math.round((new Date).getTime()/1e3)-e.created_at<60}function wI(e){return e.kind===Mx}function bI(e,t){const n=e.tags.find(e=>"u"===e[0]);return!!n&&n.length>0&&n[1]===t}function vI(e,t){const n=e.tags.find(e=>"method"===e[0]);return!!n&&n.length>0&&n[1].toLowerCase()===t.toLowerCase()}function EI(e){return kw(Mw(fA.encode(JSON.stringify(e))))}function AI(e,t){const n=e.tags.find(e=>"payload"===e[0]);if(!n)return!1;const r=EI(t);return n.length>0&&n[1]===r}async function xI(e,t,n,r){if(!AA(e))throw new Error("Invalid nostr event, signature invalid");if(!wI(e))throw new Error("Invalid nostr event, kind invalid");if(!mI(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!bI(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!vI(e,n))throw new Error("Invalid nostr event, method tag invalid");if(Boolean(r)&&"object"==typeof r&&Object.keys(r).length>0&&!AI(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}r(287).hp;var kI=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),SI=function(){return SI=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},SI.apply(this,arguments)},II=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},PI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},CI="I Love Shogun!",OI=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return n.DEFAULT_CONFIG={cacheDuration:864e5,maxRetries:3,retryDelay:1e3,timeout:6e4,network:"mainnet",useApi:!1},n.signatureCache=new Map,n.connectedAddress=null,n.connectedType=null,n.manualKeyPair=null,n.config=SI(SI({},n.DEFAULT_CONFIG),t),n.setupEventListeners(),n}return kI(t,e),t.prototype.setupEventListeners=function(){},t.prototype.clearSignatureCache=function(e){if(e){this.signatureCache.delete(e);try{var t="shogun_bitcoin_sig_".concat(e);localStorage.removeItem(t),console.log("Cleared signature cache for address: ".concat(e.substring(0,10),"..."))}catch(e){console.error("Error clearing signature cache from localStorage:",e)}}else{this.signatureCache.clear();try{for(var n=[],r=0;r<localStorage.length;r++){var o=localStorage.key(r);o&&o.startsWith("shogun_bitcoin_sig_")&&n.push(o)}n.forEach(function(e){return localStorage.removeItem(e)}),console.log("Cleared all signature caches (".concat(n.length," entries)"))}catch(e){console.error("Error clearing all signature caches from localStorage:",e)}}},t.prototype.isNostrExtensionAvailable=function(){return"undefined"!=typeof window&&!!window.nostr},t.prototype.isAvailable=function(){return this.isNostrExtensionAvailable()||null!==this.manualKeyPair},t.prototype.connectWallet=function(){return II(this,arguments,void 0,function(e){var t,n;return void 0===e&&(e="nostr"),PI(this,function(r){switch(r.label){case 0:console.log("Connecting to Bitcoin wallet via ".concat(e,"...")),r.label=1;case 1:switch(r.trys.push([1,10,,11]),t=void 0,e){case"alby":return[3,2];case"nostr":return[3,4];case"manual":return[3,6]}return[3,8];case 2:return console.log("[nostrConnector] Alby is deprecated, redirecting to Nostr"),[4,this.connectNostr()];case 3:return t=r.sent(),[3,9];case 4:return[4,this.connectNostr()];case 5:return t=r.sent(),[3,9];case 6:return[4,this.connectManual()];case 7:return t=r.sent(),[3,9];case 8:throw new Error("Unsupported wallet type: ".concat(e));case 9:return t.success&&t.address&&(this.connectedAddress=t.address,this.connectedType=e,console.log("Successfully connected to ".concat(e," wallet: ").concat(t.address)),this.emit("wallet_connected",{address:t.address,type:this.connectedType})),[2,t];case 10:return n=r.sent(),console.error("Error connecting to ".concat(e," wallet:"),n),[2,{success:!1,error:n.message||"Failed to connect to wallet"}];case 11:return[2]}})})},t.prototype.connectNostr=function(){return II(this,void 0,void 0,function(){var e,t,n;return PI(this,function(r){switch(r.label){case 0:if(!this.isNostrExtensionAvailable())return[2,{success:!1,error:"Nostr extension is not available. Please install a Nostr compatible extension like nos2x, Alby, or Coracle."}];r.label=1;case 1:return r.trys.push([1,3,,4]),console.log("[nostrConnector] Attempting to connect to Nostr extension..."),[4,window.nostr.getPublicKey()];case 2:if(!(e=r.sent()))throw new Error("Could not get public key from Nostr extension");return console.log("[nostrConnector] Successfully connected to Nostr extension: ".concat(e.substring(0,10),"...")),this.connectedAddress=e,this.connectedType="nostr",this.emit("connected",{address:e,type:"nostr"}),t="nostr_".concat(e.substring(0,10)),[2,{success:!0,address:e,username:t,extensionType:"nostr"}];case 3:throw n=r.sent(),console.error("[nostrConnector] Nostr connection error:",n),n.message&&n.message.includes("User rejected")?new Error("Nostr connection was rejected by the user"):n.message&&n.message.includes("not available")?new Error("Nostr extension is not available or not properly installed"):new Error("Nostr connection error: ".concat(n.message));case 4:return[2]}})})},t.prototype.connectManual=function(){return II(this,void 0,void 0,function(){var e;return PI(this,function(t){return this.manualKeyPair?(this.connectedAddress=this.manualKeyPair.address,this.connectedType="manual",this.emit("connected",{address:this.manualKeyPair.address,type:"manual"}),e="btc_".concat(this.manualKeyPair.address.substring(0,10)),[2,{success:!0,address:this.manualKeyPair.address,username:e,extensionType:"manual"}]):[2,{success:!1,error:"No manual key pair configured. Use setKeyPair() first."}]})})},t.prototype.setKeyPair=function(e){this.manualKeyPair=e,e.address&&(this.connectedAddress=e.address,this.connectedType="manual")},t.prototype.generateCredentials=function(e,t,n){return II(this,void 0,void 0,function(){var r,o,i,s;return PI(this,function(a){switch(a.label){case 0:return u={id:e},r="web3"==(c="nostr")&&u.id?"web3_".concat(u.id.toLowerCase()):u.id?"nostr_".concat(u.id):u.email&&(l=u.email)&&"string"==typeof l&&/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(l)?"".concat(c,"_").concat(u.email.split("@")[0]):u.name?"".concat(c,"_").concat(u.name.replace(/\s+/g,"_")):u.id?"".concat(c,"_").concat(u.id):"".concat(c,"_user"),o=In(ot(e)),i="".concat(r,"_").concat(e,"_").concat(n,"_").concat(t),[4,qi(o,i,{includeP256:!0})];case 1:return s=a.sent(),[2,{username:r,key:s,message:n,signature:t}]}var c,u,l})})},t.prototype.generatePassword=function(e){return II(this,void 0,void 0,function(){return PI(this,function(t){if(!e)throw new Error("Invalid signature");try{return[2,sn(ot(e.toLowerCase().replace(/[^a-f0-9]/g,"")))]}catch(e){throw console.error("Error generating password:",e),new Error("Failed to generate password from signature")}})})},t.prototype.verifySignature=function(e,t,n){return II(this,void 0,void 0,function(){var r,o,i,s;return PI(this,function(a){try{if(r="object"==typeof n?n.address||JSON.stringify(n):String(n),console.log("Verifying signature for address: ".concat(r)),!t||!e||!r)return console.error("Invalid message, signature, or address for verification"),[2,!1];if("nostr"===this.connectedType||"alby"===this.connectedType)try{return o=SI(SI({},i={kind:1,created_at:0,tags:[],content:e,pubkey:r}),{id:mA(i),sig:t}),[2,AA(o)]}catch(e){return console.error("Error in Nostr signature verification:",e),[2,!1]}else if("manual"===this.connectedType&&this.manualKeyPair){if(console.log("[nostrConnector] Manual verification for keypair"),!this.manualKeyPair.privateKey)return console.error("Manual verification failed: private key is missing."),[2,!1];try{return s=SI(SI({},i={kind:1,created_at:0,tags:[],content:e,pubkey:r}),{id:mA(i),sig:t}),[2,AA(s)]}catch(e){return console.error("Error in manual signature verification:",e),[2,!1]}}return console.warn("No specific verification method available, signature cannot be fully verified"),[2,!1]}catch(e){return console.error("Error verifying signature:",e),[2,!1]}})})},t.prototype.getConnectedAddress=function(){return this.connectedAddress},t.prototype.getConnectedType=function(){return this.connectedType},t.prototype.requestSignature=function(e,t){return II(this,void 0,void 0,function(){var n,r,o,i,s,a,c,u;return PI(this,function(l){switch(l.label){case 0:if(!this.connectedType)throw new Error("No wallet connected");l.label=1;case 1:switch(l.trys.push([1,8,,9]),this.connectedType){case"alby":case"nostr":return[3,2];case"manual":return[3,4]}return[3,6];case 2:if("alby"===this.connectedType&&console.warn("Alby is deprecated, using Nostr functionality for signature request"),console.log("[nostrConnector] Requesting Nostr signature for message:",t),!window.nostr)throw new Error("Nostr extension not available");return r=SI(SI({},n={kind:1,created_at:0,tags:[],content:t,pubkey:e}),{id:mA(n),sig:""}),[4,window.nostr.signEvent(r)];case 3:return o=l.sent(),console.log("Received Nostr signature:",o.sig.substring(0,20)+"..."),[2,o.sig];case 4:if(console.log("[nostrConnector] Using manual key pair for signature"),!this.manualKeyPair||!this.manualKeyPair.privateKey)throw new Error("No manual key pair available or private key missing");return i={kind:1,created_at:0,tags:[],content:t,pubkey:this.manualKeyPair.address},s=SI(SI({},i),{id:mA(i),sig:""}),a=uA.hexToBytes(this.manualKeyPair.privateKey),[4,EA(s,a)];case 5:return c=l.sent(),console.log("Generated manual signature:",c.sig.substring(0,20)+"..."),[2,c.sig];case 6:throw new Error("Unsupported wallet type: ".concat(this.connectedType));case 7:return[3,9];case 8:throw u=l.sent(),console.error("Error requesting signature:",u),new Error("Failed to get signature: ".concat(u.message));case 9:return[2]}})})},t.prototype.cleanup=function(){this.removeAllListeners(),this.connectedAddress=null,this.connectedType=null,this.manualKeyPair=null},t}(Pe);function NI(e,t,n){return II(this,void 0,void 0,function(){var t;return PI(this,function(r){switch(r.label){case 0:return t="".concat(e,"_").concat(n),[4,qi(e,t,{includeP256:!0})];case 1:return[2,r.sent()]}})})}"undefined"!=typeof window?window.NostrConnector=OI:void 0!==r.g&&(r.g.NostrConnector=OI);var BI,TI,RI=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},UI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},DI=function(){function e(e){this.credentials=new Map,this.MESSAGE_TO_SIGN="I Love Shogun!",this.nostrConnector=e||new OI}return e.prototype.createSigningCredential=function(e){return RI(this,void 0,void 0,function(){var t,n,r,o,i,s;return UI(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),t=this.validateAddress(e),[4,this.generateDeterministicSignature(t)];case 1:return n=a.sent(),r="".concat(t.toLowerCase()),[4,this.generatePassword(n)];case 2:return o=a.sent(),i={address:t,signature:n,message:this.MESSAGE_TO_SIGN,username:r,password:o},this.credentials.set(t.toLowerCase(),i),[2,i];case 3:throw s=a.sent(),console.error("Error creating Nostr signing credential:",s),new Error("Failed to create Nostr signing credential: ".concat(s.message));case 4:return[2]}})})},e.prototype.validateAddress=function(e){if(!e)throw new Error("Address not provided");try{var t=String(e).trim();if(!/^(npub1|[0-9a-f]{64}|bc1|[13])[a-zA-HJ-NP-Z0-9]{25,59}$/.test(t)&&t.length<10)throw new Error("Invalid Nostr/Bitcoin address format");return t}catch(e){throw new Error("Invalid Nostr/Bitcoin address provided")}},e.prototype.generateDeterministicSignature=function(e){return RI(this,void 0,void 0,function(){var t,n,r,o,i,s;return UI(this,function(a){for(t="".concat(e,"_").concat(this.MESSAGE_TO_SIGN,"_shogun_deterministic"),n="",r=0,o=0;o<t.length;o++)i=t.charCodeAt(o),r=31*r+i&4294967295,o%4==3&&(n+=r.toString(16).padStart(8,"0"));for(;n.length<128;)r=31*r+n.length&4294967295,n+=r.toString(16).padStart(8,"0");return(s=(s=n.substring(0,128)).toLowerCase().replace(/[^0-9a-f]/g,"0")).length<128?s=s.padEnd(128,"0"):s.length>128&&(s=s.substring(0,128)),[2,s]})})},e.prototype.generatePassword=function(e){return RI(this,void 0,void 0,function(){return UI(this,function(t){if(!e)throw new Error("Invalid signature");try{return[2,sn(ot(e.toLowerCase().replace(/[^a-f0-9]/g,"")))]}catch(e){throw console.error("Error generating password:",e),new Error("Failed to generate password from signature")}})})},e.prototype.createAuthenticator=function(e){var t=this,n=this.credentials.get(e.toLowerCase());if(!n)throw new Error("Credential for address ".concat(e," not found"));return function(e){return RI(t,void 0,void 0,function(){var t,r;return UI(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),t=JSON.stringify(e),[4,this.signData(t,n)];case 1:return[2,o.sent()];case 2:throw r=o.sent(),console.error("Nostr authentication error:",r),r;case 3:return[2]}})})}},e.prototype.signData=function(e,t){return RI(this,void 0,void 0,function(){var n;return UI(this,function(r){return n="".concat(t.signature,"_").concat(e),[2,this.generateDeterministicSignature(n)]})})},e.prototype.createDerivedKeyPair=function(e,t){return RI(this,void 0,void 0,function(){var n,r,o;return UI(this,function(i){switch(i.label){case 0:if(!(n=this.credentials.get(e.toLowerCase())))throw new Error("Credential for address ".concat(e," not found"));i.label=1;case 1:return i.trys.push([1,3,,4]),[4,qi(n.password,t,{includeP256:!0})];case 2:return[2,{pub:(r=i.sent()).pub,priv:r.priv,epub:r.epub,epriv:r.epriv}];case 3:throw o=i.sent(),console.error("Error deriving keys from Nostr credential:",o),o;case 4:return[2]}})})},e.prototype.createGunUser=function(e,t){return RI(this,void 0,void 0,function(){var n,r,o,i=this;return UI(this,function(s){switch(s.label){case 0:if(!(n=this.credentials.get(e.toLowerCase())))throw new Error("Credential for address ".concat(e," not found"));s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.createDerivedKeyPair(e)];case 2:return r=s.sent(),[2,new Promise(function(o){t.user().create(r,function(s){s.err?t.user().auth(r,function(t){if(t.err)o({success:!1,error:t.err});else{var r=t.pub;n.gunUserPub=r,i.credentials.set(e.toLowerCase(),n),o({success:!0,userPub:r})}}):t.user().auth(r,function(t){if(t.err)o({success:!1,error:t.err});else{var r=t.pub;n.gunUserPub=r,i.credentials.set(e.toLowerCase(),n),o({success:!0,userPub:r})}})})})];case 3:return o=s.sent(),console.error("Error creating Gun user:",o),[2,{success:!1,error:o.message}];case 4:return[2]}})})},e.prototype.signWithDerivedKeys=function(e,t,n){return RI(this,void 0,void 0,function(){var r,o,i,s,a;return UI(this,function(c){switch(c.label){case 0:return c.trys.push([0,4,,5]),[4,this.createAuthenticator(t)(e)];case 1:return c.sent(),[4,this.createDerivedKeyPair(t,n)];case 2:return r=c.sent(),o=JSON.stringify(e),[4,this.generateDeterministicSignature("".concat(r.priv,"_").concat(o))];case 3:return i=c.sent(),s={m:o,s:i},[2,"SEA"+JSON.stringify(s)];case 4:throw a=c.sent(),console.error("Error signing with derived keys:",a),a;case 5:return[2]}})})},e.prototype.getGunUserPub=function(e){var t=this.credentials.get(e.toLowerCase());return null==t?void 0:t.gunUserPub},e.prototype.getPassword=function(e){var t=this.credentials.get(e.toLowerCase());return null==t?void 0:t.password},e.prototype.verifyConsistency=function(e,t){return RI(this,void 0,void 0,function(){var n;return UI(this,function(r){switch(r.label){case 0:return this.credentials.get(e.toLowerCase())?[4,this.createDerivedKeyPair(e)]:[2,{consistent:!1}];case 1:return n=r.sent(),[2,{consistent:!t||n.pub===t,actualUserPub:n.pub,expectedUserPub:t}]}})})},e.prototype.getCredential=function(e){return this.credentials.get(e.toLowerCase())},e.prototype.listCredentials=function(){return Array.from(this.credentials.values())},e.prototype.removeCredential=function(e){return this.credentials.delete(e.toLowerCase())},e}(),LI=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),FI=function(){return FI=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},FI.apply(this,arguments)},_I=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},MI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},jI=function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.name="nostr",t.version="1.0.0",t.description="Provides Bitcoin wallet connection and authentication for ShogunCore",t.bitcoinConnector=null,t.signer=null,t}return LI(t,e),t.prototype.initialize=function(t){e.prototype.initialize.call(this,t),this.bitcoinConnector=new OI,this.signer=new DI(this.bitcoinConnector)},t.prototype.destroy=function(){this.bitcoinConnector&&this.bitcoinConnector.cleanup(),this.bitcoinConnector=null,this.signer=null,e.prototype.destroy.call(this)},t.prototype.assertBitcoinConnector=function(){if(this.assertInitialized(),!this.bitcoinConnector)throw new Error("Bitcoin wallet module not initialized");return this.bitcoinConnector},t.prototype.assertSigner=function(){if(this.assertInitialized(),!this.signer)throw new Error("Nostr signer not initialized");return this.signer},t.prototype.isAvailable=function(){return this.assertBitcoinConnector().isAvailable()},t.prototype.isNostrExtensionAvailable=function(){return this.assertBitcoinConnector().isNostrExtensionAvailable()},t.prototype.connectNostrWallet=function(){return _I(this,void 0,void 0,function(){var e,t;return MI(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.isNostrExtensionAvailable()?[4,this.connectBitcoinWallet("nostr")]:[2,{success:!1,error:"Nostr extension not available. Please install a Nostr extension like nos2x, Alby, or Coracle."}];case 1:return(e=n.sent()).success,[2,e];case 2:return t=n.sent(),console.error("[nostrConnectorPlugin] Error connecting to Nostr wallet:",t),[2,{success:!1,error:t.message||"Unknown error connecting to Nostr wallet"}];case 3:return[2]}})})},t.prototype.connectBitcoinWallet=function(){return _I(this,arguments,void 0,function(e){return void 0===e&&(e="nostr"),MI(this,function(t){return"alby"===e&&(e="nostr"),[2,this.assertBitcoinConnector().connectWallet(e)]})})},t.prototype.generateCredentials=function(e,t,n){return _I(this,void 0,void 0,function(){return MI(this,function(r){return[2,this.assertBitcoinConnector().generateCredentials(e,t,n)]})})},t.prototype.cleanup=function(){this.assertBitcoinConnector().cleanup()},t.prototype.verifySignature=function(e,t,n){return _I(this,void 0,void 0,function(){return MI(this,function(r){return[2,this.assertBitcoinConnector().verifySignature(e,t,n)]})})},t.prototype.generatePassword=function(e){return _I(this,void 0,void 0,function(){return MI(this,function(t){return[2,this.assertBitcoinConnector().generatePassword(e)]})})},t.prototype.createSigningCredential=function(e){return _I(this,void 0,void 0,function(){var t,n;return MI(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),"function"!=typeof(t=this.assertBitcoinConnector()).createSigningCredential?[3,2]:[4,t.createSigningCredential(e)];case 1:case 3:return[2,r.sent()];case 2:return[4,this.assertSigner().createSigningCredential(e)];case 4:throw n=r.sent(),console.error("Error creating Nostr signing credential: ".concat(n.message)),n;case 5:return[2]}})})},t.prototype.createAuthenticator=function(e){try{var t=this.assertBitcoinConnector();return"function"==typeof t.createAuthenticator?t.createAuthenticator(e):this.assertSigner().createAuthenticator(e)}catch(e){throw console.error("Error creating Nostr authenticator: ".concat(e.message)),e}},t.prototype.createDerivedKeyPair=function(e,t){return _I(this,void 0,void 0,function(){var n,r;return MI(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(n=this.assertBitcoinConnector()).createDerivedKeyPair?[3,2]:[4,n.createDerivedKeyPair(e,t)];case 1:case 3:return[2,o.sent()];case 2:return[4,this.assertSigner().createDerivedKeyPair(e,t)];case 4:throw r=o.sent(),console.error("Error creating derived key pair: ".concat(r.message)),r;case 5:return[2]}})})},t.prototype.signWithDerivedKeys=function(e,t,n){return _I(this,void 0,void 0,function(){var r,o;return MI(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(r=this.assertBitcoinConnector()).signWithDerivedKeys?[3,2]:[4,r.signWithDerivedKeys(e,t,n)];case 1:case 3:return[2,i.sent()];case 2:return[4,this.assertSigner().signWithDerivedKeys(e,t,n)];case 4:throw o=i.sent(),console.error("Error signing with derived keys: ".concat(o.message)),o;case 5:return[2]}})})},t.prototype.getSigningCredential=function(e){var t=this.assertBitcoinConnector();return"function"==typeof t.getSigningCredential?t.getSigningCredential(e):this.assertSigner().getCredential(e)},t.prototype.listSigningCredentials=function(){var e=this.assertBitcoinConnector();return"function"==typeof e.listSigningCredentials?e.listSigningCredentials():this.assertSigner().listCredentials()},t.prototype.removeSigningCredential=function(e){var t=this.assertBitcoinConnector();return"function"==typeof t.removeSigningCredential?t.removeSigningCredential(e):this.assertSigner().removeCredential(e)},t.prototype.createGunUserFromSigningCredential=function(e){return _I(this,void 0,void 0,function(){var t,n,r;return MI(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(t=this.assertBitcoinConnector()).createGunUserFromSigningCredential?[3,2]:[4,t.createGunUserFromSigningCredential(e)];case 1:case 3:return[2,o.sent()];case 2:return n=this.assertInitialized(),[4,this.assertSigner().createGunUser(e,n.gun)];case 4:throw r=o.sent(),console.error("Error creating Gun user from Nostr signing credential: ".concat(r.message)),r;case 5:return[2]}})})},t.prototype.getGunUserPubFromSigningCredential=function(e){var t=this.assertBitcoinConnector();return"function"==typeof t.getGunUserPubFromSigningCredential?t.getGunUserPubFromSigningCredential(e):this.assertSigner().getGunUserPub(e)},t.prototype.getPassword=function(e){var t=this.assertBitcoinConnector();return"function"==typeof t.getPassword?t.getPassword(e):this.assertSigner().getPassword(e)},t.prototype.verifyConsistency=function(e,t){return _I(this,void 0,void 0,function(){var n,r;return MI(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(n=this.assertBitcoinConnector()).verifyConsistency?[3,2]:[4,n.verifyConsistency(e,t)];case 1:case 3:return[2,o.sent()];case 2:return[4,this.assertSigner().verifyConsistency(e,t)];case 4:return r=o.sent(),console.error("Error verifying Nostr consistency: ".concat(r.message)),[2,{consistent:!1}];case 5:return[2]}})})},t.prototype.setupConsistentOneshotSigning=function(e){return _I(this,void 0,void 0,function(){var t,n,r,o,i;return MI(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),"function"!=typeof(t=this.assertBitcoinConnector()).setupConsistentOneshotSigning?[3,2]:[4,t.setupConsistentOneshotSigning(e)];case 1:return[2,s.sent()];case 2:return[4,this.createSigningCredential(e)];case 3:return n=s.sent(),r=this.createAuthenticator(e),[4,this.createGunUserFromSigningCredential(e)];case 4:return o=s.sent(),[2,{credential:n,authenticator:r,gunUser:o,username:n.username,password:n.password}];case 5:throw i=s.sent(),console.error("Error setting up consistent Nostr oneshot signing: ".concat(i.message)),i;case 6:return[2]}})})},t.prototype.login=function(e){return _I(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c,u,l;return MI(this,function(f){switch(f.label){case 0:if(f.trys.push([0,6,,7]),t=this.assertInitialized(),!e)throw Se(xe.VALIDATION,"ADDRESS_REQUIRED","Bitcoin address required for login");if(!this.isAvailable())throw Se(xe.ENVIRONMENT,"BITCOIN_WALLET_UNAVAILABLE","No Bitcoin wallet available in the browser");return n=CI,[4,this.assertBitcoinConnector().requestSignature(e,n)];case 1:return r=f.sent(),[4,this.generateCredentials(e,r,n)];case 2:if(!((null==(o=f.sent())?void 0:o.username)&&(null==o?void 0:o.key)&&o.message&&o.signature))throw Se(xe.AUTHENTICATION,"CREDENTIAL_GENERATION_FAILED","Bitcoin wallet credentials not generated correctly or signature missing");return[4,this.verifySignature(o.message,o.signature,e)];case 3:if(!f.sent())throw console.error("Signature verification failed for address: ".concat(e)),Se(xe.SECURITY,"SIGNATURE_VERIFICATION_FAILED","Bitcoin wallet signature verification failed");return[4,NI(e,0,n)];case 4:return i=f.sent(),t.setAuthMethod("nostr"),[4,t.login(o.username,"",i)];case 5:if(!(s=f.sent()).success)throw Se(xe.AUTHENTICATION,"BITCOIN_LOGIN_FAILED",s.error||"Failed to log in with Bitcoin credentials");return t.emit("auth:login",{userPub:s.userPub||"",username:o.username,method:"nostr"}),[2,s];case 6:return a=f.sent(),c=(null==a?void 0:a.type)||xe.AUTHENTICATION,u=(null==a?void 0:a.code)||"BITCOIN_LOGIN_ERROR",l=(null==a?void 0:a.message)||"Unknown error during Bitcoin wallet login",Ie.handle(c,u,l,a),[2,{success:!1,error:l}];case 7:return[2]}})})},t.prototype.signUp=function(e){return _I(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c,u,l,f;return MI(this,function(h){switch(h.label){case 0:if(h.trys.push([0,11,,12]),t=this.assertInitialized(),!e)throw Se(xe.VALIDATION,"ADDRESS_REQUIRED","Bitcoin address required for signup");if(!this.isAvailable())throw Se(xe.ENVIRONMENT,"BITCOIN_WALLET_UNAVAILABLE","No Bitcoin wallet available in the browser");return n=CI,[4,this.assertBitcoinConnector().requestSignature(e,n)];case 1:return r=h.sent(),[4,this.generateCredentials(e,r,n)];case 2:if(!((null==(o=h.sent())?void 0:o.username)&&(null==o?void 0:o.key)&&o.message&&o.signature))throw Se(xe.AUTHENTICATION,"CREDENTIAL_GENERATION_FAILED","Bitcoin wallet credentials not generated correctly or signature missing");return[4,this.verifySignature(o.message,o.signature,e)];case 3:if(!h.sent())throw console.error("Signature verification failed for address: ".concat(e)),Se(xe.SECURITY,"SIGNATURE_VERIFICATION_FAILED","Bitcoin wallet signature verification failed");return[4,NI(e,0,n)];case 4:return i=h.sent(),t.setAuthMethod("nostr"),[4,t.signUp(o.username,void 0,i)];case 5:return(s=h.sent()).success?[4,t.login(o.username,"",i)]:[3,7];case 6:return(a=h.sent()).success?(console.log("Bitcoin wallet registration and login completed for user: ".concat(o.username)),t.emit("auth:signup",{userPub:a.userPub||"",username:o.username,method:"nostr"}),[2,FI({},a)]):[2,FI(FI({},s),{error:"User created but login failed"})];case 7:return s.error&&s.error.toLowerCase().includes("exist")?[4,t.login(o.username,"",i)]:[3,9];case 8:return a=h.sent(),[2,FI({},a)];case 9:return[2,s];case 10:return[3,12];case 11:return c=h.sent(),u=(null==c?void 0:c.type)||xe.AUTHENTICATION,l=(null==c?void 0:c.code)||"BITCOIN_SIGNUP_ERROR",f=(null==c?void 0:c.message)||"Unknown error during Bitcoin wallet signup",Ie.handle(u,l,f,c),[2,{success:!1,error:f}];case 12:return[2]}})})},t.prototype.loginWithBitcoinWallet=function(e){return _I(this,void 0,void 0,function(){return MI(this,function(t){return[2,this.login(e)]})})},t.prototype.signUpWithBitcoinWallet=function(e){return _I(this,void 0,void 0,function(){return MI(this,function(t){return[2,this.signUp(e)]})})},t}(Oe);!function(e){e.Authentication="authentication",e.Wallet="wallet",e.Privacy="privacy",e.Identity="identity",e.Utility="utility",e.Messages="messages",e.Other="other"}(BI||(BI={})),function(e){e.WebAuthn="webauthn",e.Web3="web3",e.Nostr="nostr",e.Challenge="challenge"}(TI||(TI={}));var GI=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),HI=function(){return HI=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},HI.apply(this,arguments)},zI=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},KI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},VI=(function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.name="challenge",t.version="1.0.0",t.description="Challenge-response authentication using Gun SEA signatures",t._category=BI.Authentication,t.config={serverUrl:"",challengeEndpoint:"/login-challenge",verifyEndpoint:"/login-verify",timeout:1e4},t}GI(t,e),t.prototype.configure=function(e){this.config=HI(HI({},this.config),e)},t.prototype.getSEA=function(){var e,t,n=this.core;if(n){var r=null===(e=n.db)||void 0===e?void 0:e.sea;if(r)return r}return(null===(t=globalThis.Gun)||void 0===t?void 0:t.SEA)?globalThis.Gun.SEA:globalThis.SEA?globalThis.SEA:null},t.prototype.requestChallenge=function(e,t,n){return zI(this,void 0,void 0,function(){var r,o,i,s,a,c,u,l;return KI(this,function(f){switch(f.label){case 0:r=this.config.challengeEndpoint||"/login-challenge",o="".concat(e).concat(r),i=new AbortController,s=setTimeout(function(){return i.abort()},this.config.timeout||1e4),f.label=1;case 1:return f.trys.push([1,6,,7]),[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:t,password:n}),signal:i.signal})];case 2:return a=f.sent(),clearTimeout(s),a.ok?[3,4]:[4,a.json().catch(function(){return{error:"Request failed"}})];case 3:throw c=f.sent(),new Error(c.error||"Challenge request failed: ".concat(a.status));case 4:return[4,a.json()];case 5:if(!(u=f.sent()).success)throw new Error(u.error||"Challenge request rejected by server");return[2,{challengeId:u.challengeId,challenge:u.challenge,pub:u.pub,expiresAt:u.expiresAt}];case 6:if(l=f.sent(),clearTimeout(s),"AbortError"===l.name)throw new Error("Challenge request timed out");throw l;case 7:return[2]}})})},t.prototype.signChallenge=function(e,t){return zI(this,void 0,void 0,function(){var n,r;return KI(this,function(o){switch(o.label){case 0:if(!(n=this.getSEA())||!n.sign)throw new Error("SEA not available for challenge signing");return[4,n.sign(e,t)];case 1:if(!(r=o.sent()))throw new Error("Failed to sign challenge");return[2,r]}})})},t.prototype.verifyChallenge=function(e,t,n){return zI(this,void 0,void 0,function(){var r;return KI(this,function(o){switch(o.label){case 0:if(!(r=this.getSEA())||!r.verify)throw new Error("SEA not available for challenge verification");return[4,r.verify(e,t)];case 1:return[2,o.sent()===n]}})})},t.prototype.login=function(e,t,n,r){return zI(this,void 0,void 0,function(){var o,i,s,a,c,u,l,f,h;return KI(this,function(d){switch(d.label){case 0:return d.trys.push([0,5,,6]),[4,this.requestChallenge(e,t,n)];case 1:return o=d.sent(),[4,this.signChallenge(o.challenge,r)];case 2:return i=d.sent(),s=this.config.verifyEndpoint||"/login-verify",a="".concat(e).concat(s),c=new AbortController,u=setTimeout(function(){return c.abort()},this.config.timeout||1e4),[4,fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({challengeId:o.challengeId,signedChallenge:i}),signal:c.signal})];case 3:return l=d.sent(),clearTimeout(u),[4,l.json()];case 4:return(f=d.sent()).success?(h={success:!0,userPub:f.pub,username:f.username||t,sessionToken:f.token,authMethod:"challenge"},this.core&&this.core.emit("auth:login",{userPub:f.pub,method:"password",username:f.username||t}),[2,h]):[2,{success:!1,error:f.error||"Challenge verification failed"}];case 5:return[2,{success:!1,error:d.sent().message||"Challenge-response login failed"}];case 6:return[2]}})})}}(Oe),r(937),r(66),r(670),r(483),r(853),r(888),r(502),r(968),r(809)),WI=function(){return WI=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},WI.apply(this,arguments)},$I=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},qI=function(){function e(e){this.plugins=new Map,this.core=e}return e.prototype.register=function(e){try{if(!e.name)return void("undefined"!=typeof console&&console.error&&console.error("Plugin registration failed: Plugin must have a name"));if(this.plugins.has(e.name))return void("undefined"!=typeof console&&console.warn&&console.warn('Plugin "'.concat(e.name,'" is already registered. Skipping.')));e.initialize(this.core),this.plugins.set(e.name,e),this.core.emit("plugin:registered",{name:e.name,version:e.version||"unknown",category:e._category||"unknown"})}catch(t){"undefined"!=typeof console&&console.error&&console.error('Error registering plugin "'.concat(e.name,'":'),t)}},e.prototype.unregister=function(e){try{var t=this.plugins.get(e);if(!t)return"undefined"!=typeof console&&console.warn&&console.warn('Plugin "'.concat(e,'" not found for unregistration')),!1;if("function"==typeof t.destroy)try{t.destroy()}catch(t){"undefined"!=typeof console&&console.error&&console.error('Error destroying plugin "'.concat(e,'":'),t)}return this.plugins.delete(e),this.core.emit("plugin:unregistered",{name:t.name}),!0}catch(t){return"undefined"!=typeof console&&console.error&&console.error('Error unregistering plugin "'.concat(e,'":'),t),!1}},e.prototype.getPlugin=function(e){if(e&&"string"==typeof e){var t=this.plugins.get(e);if(t)return t;"undefined"!=typeof console&&console.warn&&console.warn('Plugin "'.concat(e,'" not found'))}else"undefined"!=typeof console&&console.warn&&console.warn("Invalid plugin name provided to getPlugin")},e.prototype.getPluginsInfo=function(){var e=[];return this.plugins.forEach(function(t){e.push({name:t.name,version:t.version||"unknown",category:t._category,description:t.description})}),e},e.prototype.getPluginCount=function(){return this.plugins.size},e.prototype.getPluginsInitializationStatus=function(){var e={};return this.plugins.forEach(function(t,n){try{"function"==typeof t.assertInitialized?(t.assertInitialized(),e[n]={initialized:!0}):e[n]={initialized:!!t.core,error:t.core?void 0:"No core reference found"}}catch(t){e[n]={initialized:!1,error:t instanceof Error?t.message:String(t)}}}),e},e.prototype.validatePluginSystem=function(){var e=this.getPluginsInitializationStatus(),t=Object.keys(e).length,n=Object.values(e).filter(function(e){return e.initialized}).length,r=Object.entries(e).filter(function(e){var t=$I(e,2);return t[0],!t[1].initialized}).map(function(e){var t=$I(e,2),n=t[0];return t[1],n}),o=[];return 0===t&&o.push("No plugins registered"),r.length>0&&o.push("Failed plugins: ".concat(r.join(", "))),{totalPlugins:t,initializedPlugins:n,failedPlugins:r,warnings:o}},e.prototype.reinitializeFailedPlugins=function(){var e=this,t=this.getPluginsInitializationStatus(),n=Object.entries(t).filter(function(e){var t=$I(e,2);return t[0],!t[1].initialized}).map(function(e){var t=$I(e,2),n=t[0];return t[1],n}),r=[],o=[];return n.forEach(function(t){try{var n=e.plugins.get(t);if(!n)return void o.push({name:t,error:"Plugin not found"});n.initialize(e.core),r.push(t)}catch(e){var i=e instanceof Error?e.message:String(e);o.push({name:t,error:i}),"undefined"!=typeof console&&console.error&&console.error("[PluginManager] Failed to reinitialize plugin ".concat(t,":"),e)}}),{success:r,failed:o}},e.prototype.checkPluginCompatibility=function(){var e=[],t=[],n=[];return this.plugins.forEach(function(r){var o={name:r.name,version:r.version||"unknown"};if("function"==typeof r.getCompatibilityInfo)try{var i=r.getCompatibilityInfo();i&&i.compatible?e.push(o):t.push(WI(WI({},o),{reason:(null==i?void 0:i.reason)||"Unknown compatibility issue"}))}catch(e){n.push(o)}else n.push(o)}),{compatible:e,incompatible:t,unknown:n}},e.prototype.getPluginSystemDebugInfo=function(){var e=this.getPluginsInfo(),t=this.getPluginsInitializationStatus(),n=e.map(function(e){var n,r;return WI(WI({},e),{initialized:(null===(n=t[e.name])||void 0===n?void 0:n.initialized)||!1,error:null===(r=t[e.name])||void 0===r?void 0:r.error})});return{shogunCoreVersion:"^1.6.6",totalPlugins:this.getPluginCount(),plugins:n,initializationStatus:t,validation:this.validatePluginSystem(),compatibility:this.checkPluginCompatibility()}},e.prototype.hasPlugin=function(e){return this.plugins.has(e)},e.prototype.getPluginsByCategory=function(e){var t=[];return this.plugins.forEach(function(n){n._category===e&&t.push(n)}),t},e}(),JI=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},QI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},ZI=function(){function e(e){this.core=e}return e.prototype.isLoggedIn=function(){return this.core.db.isLoggedIn()},e.prototype.logout=function(){try{if(!this.isLoggedIn())return;this.core.db.logout(),this.core.emit("auth:logout")}catch(e){Ie.handle(xe.AUTHENTICATION,"LOGOUT_FAILED",e instanceof Error?e.message:"Error during logout",e)}},e.prototype.login=function(e,t,n){return JI(this,void 0,void 0,function(){var r,o,i,s,a,c,u,l;return QI(this,function(f){switch(f.label){case 0:return f.trys.push([0,2,,3]),this.currentAuthMethod||(this.currentAuthMethod="password"),[4,this.core.db.login(e,t,n)];case 1:return(r=f.sent()).success?((o=null===(a=null===(s=this.core.user)||void 0===s?void 0:s._)||void 0===a?void 0:a.sea)&&(r.sea=o),this.core.emit("auth:login",{userPub:null!==(c=r.userPub)&&void 0!==c?c:"",method:"pair"===this.currentAuthMethod?"password":this.currentAuthMethod||"password"})):r.error=r.error||"Wrong user or password",[2,r];case 2:return i=f.sent(),Ie.handle(xe.AUTHENTICATION,"LOGIN_FAILED",null!==(u=i.message)&&void 0!==u?u:"Unknown error during login",i),[2,{success:!1,error:null!==(l=i.message)&&void 0!==l?l:"Unknown error during login"}];case 3:return[2]}})})},e.prototype.loginWithPair=function(e,t){return JI(this,void 0,void 0,function(){var n,r,o,i,s,a,c,u;return QI(this,function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),t&&t.pub&&t.priv&&t.epub&&t.epriv?[4,this.core.db.loginWithPair(e,t)]:[2,{success:!1,error:"Invalid pair structure - missing required keys"}];case 1:return(n=l.sent()).success?((r=null===(s=null===(i=this.core.user)||void 0===i?void 0:i._)||void 0===s?void 0:s.sea)&&(n.sea=r),this.currentAuthMethod="pair",this.core.emit("auth:login",{userPub:null!==(a=n.userPub)&&void 0!==a?a:"",method:"pair",username:e})):n.error=n.error||"Authentication failed with provided pair",[2,n];case 2:return o=l.sent(),Ie.handle(xe.AUTHENTICATION,"PAIR_LOGIN_FAILED",null!==(c=o.message)&&void 0!==c?c:"Unknown error during pair login",o),[2,{success:!1,error:null!==(u=o.message)&&void 0!==u?u:"Unknown error during pair login"}];case 3:return[2]}})})},e.prototype.loginWithSeed=function(e,t){return JI(this,void 0,void 0,function(){var n,r,o;return QI(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),Ta(t)?[4,(0,VI.generatePairFromMnemonic)(t,e)]:[2,{success:!1,error:"Invalid seed phrase"}];case 1:return n=i.sent(),[4,this.loginWithPair(e,n)];case 2:return(r=i.sent()).success&&this.core,[2,r];case 3:return[2,{success:!1,error:(o=i.sent())instanceof Error?o.message:String(o)}];case 4:return[2]}})})},e.prototype.signUp=function(e,t,n){return JI(this,void 0,void 0,function(){var r,o;return QI(this,function(i){switch(i.label){case 0:if(i.trys.push([0,2,,3]),!this.core.db)throw new Error("Database not initialized");if(!(n||t&&""!==t.trim()))throw new Error("Password is required for password-based signup");return[4,this.core.db.signUp(e,t||"",n)];case 1:return(r=i.sent()).success?(this.currentAuthMethod=n?"web3":"password",this.core.emit("auth:signup",{userPub:r.userPub,username:e,method:this.currentAuthMethod}),this.core.emit("debug",{action:"signup_success",userPub:r.userPub,method:this.currentAuthMethod})):this.core.emit("debug",{action:"signup_failed",error:r.error,username:e}),[2,r];case 2:return o=i.sent(),"undefined"!=typeof console&&console.error&&console.error("Error during registration for user ".concat(e,":"),o),this.core.emit("debug",{action:"signup_error",error:o instanceof Error?o.message:String(o),username:e}),[2,{success:!1,error:"Registration failed: ".concat(o instanceof Error?o.message:String(o))}];case 3:return[2]}})})},e.prototype.setAuthMethod=function(e){this.currentAuthMethod=e},e.prototype.getAuthMethod=function(){return this.currentAuthMethod},e.prototype.getAuthenticationMethod=function(e){var t=this;switch(e){case"webauthn":return this.core.getPlugin("webauthn");case"web3":return this.core.getPlugin("web3");case"nostr":return this.core.getPlugin("nostr");default:return{name:"password",version:"1.0.0",initialize:function(){},login:function(e,n){return JI(t,void 0,void 0,function(){return QI(this,function(t){switch(t.label){case 0:return[4,this.login(e,n||"")];case 1:return[2,t.sent()]}})})},signUp:function(e,n){return JI(t,void 0,void 0,function(){var t,r,o;return QI(this,function(i){switch(i.label){case 0:if(r=(t=n||{}).password,(o=t.confirm)&&r!==o)throw new Error("Password and confirm password do not match");return[4,this.signUp(e,r||"")];case 1:return[2,i.sent()]}})})}}}},e}(),YI=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),XI=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return YI(t,e),t.prototype.emit=function(t,n){return e.prototype.emit.call(this,t,n)},t.prototype.on=function(t,n){e.prototype.on.call(this,t,n)},t.prototype.off=function(t,n){e.prototype.off.call(this,t,n)},t}(Pe),eP=function(){function e(){this.eventEmitter=new XI}return e.prototype.emit=function(e,t){return this.eventEmitter.emit(e,t)},e.prototype.on=function(e,t){return this.eventEmitter.on(e,t),this},e.prototype.once=function(e,t){return this.eventEmitter.once(e,t),this},e.prototype.off=function(e,t){return this.eventEmitter.off(e,t),this},e.prototype.removeAllListeners=function(e){return this.eventEmitter.removeAllListeners(e),this},e.prototype.getEventEmitter=function(){return this.eventEmitter},e}(),tP=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},nP=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},rP=function(){function e(e){if(void 0===e&&(e=!1),this.store=new Map,this.silent=e,this.isTestMode=!1,this.useLocalStorage=!1,this.isTestMode)this.useLocalStorage=!1;else if("undefined"!=typeof localStorage)try{var t="_shogun_test";localStorage.setItem(t,t),localStorage.removeItem(t),this.useLocalStorage=!0,this.silent||console.log("ShogunStorage: localStorage enabled");var n=localStorage.getItem("shogun_keypair");n&&this.store.set("keypair",JSON.parse(n))}catch(e){this.useLocalStorage=!1,this.silent||console.log("ShogunStorage: localStorage error:",e.message)}}return e.prototype.getPair=function(){return tP(this,void 0,void 0,function(){return nP(this,function(e){return[2,this.getPairSync()]})})},e.prototype.getPairSync=function(){return this.store.get("keypair")||null},e.prototype.setPair=function(e){return tP(this,void 0,void 0,function(){return nP(this,function(t){if(this.store.set("keypair",e),this.useLocalStorage)try{localStorage.setItem("shogun_keypair",JSON.stringify(e))}catch(e){this.isTestMode||console.error("Error saving data to localStorage:",e)}return[2]})})},e.prototype.clearAll=function(){if(this.store.clear(),this.useLocalStorage)try{localStorage.removeItem("shogun_keypair")}catch(e){this.isTestMode||console.error("Error removing data from localStorage:",e)}},e.prototype.getItem=function(e){var t=this.store.get(e);return void 0===t?null:t},e.prototype.setItem=function(e,t){if(this.store.set(e,t),this.useLocalStorage)try{localStorage.setItem(e,"string"==typeof t?t:JSON.stringify(t))}catch(t){this.isTestMode||console.error("Error saving ".concat(e," to localStorage:"),t)}},e.prototype.removeItem=function(e){if(this.store.delete(e),this.useLocalStorage)try{localStorage.removeItem(e)}catch(t){this.isTestMode||console.error("Error removing ".concat(e," from localStorage:"),t)}},e}();var oP=function(e){function t(t,n,r,o,i,s){var a=e.call(this,t)||this;return a.onFinalize=i,a.shouldUnsubscribe=s,a._next=n?function(e){try{n(e)}catch(e){t.error(e)}}:e.prototype._next,a._error=o?function(e){try{o(e)}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._error,a._complete=r?function(){try{r()}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,a}return u(t,e),t.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;e.prototype.unsubscribe.call(this),!n&&(null===(t=this.onFinalize)||void 0===t||t.call(this))}},t}(B);function iP(e,t){return void 0===t&&(t=j),e=null!=e?e:sP,function(e){return function(t){if(function(e){return d(null==e?void 0:e.lift)}(t))return t.lift(function(t){try{return e(t,this)}catch(e){this.error(e)}});throw new TypeError("Unable to lift unknown Observable type")}}(function(n,r){var o,i=!0;n.subscribe(new oP(r,function(n){var s=t(n);!i&&e(o,s)||(i=!1,o=s,r.next(n))},void 0,void 0,void 0))})}function sP(e,t){return e===t}function aP(e,t){if(e===t)return!0;if(null===e||"object"!=typeof e||null===t||"object"!=typeof t)return!1;if(e.constructor!==t.constructor)return!1;if(Array.isArray(e)){var n=e.length;if(n!==t.length)return!1;for(var r=0;r<n;r++)if(!aP(e[r],t[r]))return!1;return!0}var o=Object.keys(e),i=Object.keys(t);if(o.length!==i.length)return!1;for(r=0;r<o.length;r++){var s=o[r];if(!Object.prototype.hasOwnProperty.call(t,s))return!1;if(!aP(e[s],t[s]))return!1}return!0}var cP=function(){function e(e){this.gun=e,this.user=e.user()}return e.prototype.getUser=function(){return this.user},e.prototype.getUserPub=function(){var e;return null===(e=this.user.is)||void 0===e?void 0:e.pub},e.prototype.observe=function(e){var t=this;return new G(function(n){var r;if(Array.isArray(e)){r=t.gun.get(e[0]);for(var o=1;o<e.length;o++)r=r.get(e[o])}else r="string"==typeof e?t.gun.get(e):e;var i=r.on(function(e,t){if(null!=e)if("object"==typeof e&&null!==e){var r=uP(e);n.next(r)}else n.next(e);else n.next(null)});return function(){i&&"function"==typeof i&&i(),r.off()}}).pipe(iP(function(e,t){return aP(e,t)}))},e.prototype.match=function(e,t){var n=this;return new G(function(r){if(!e)return r.next([]),void r.complete();var o="string"==typeof e?n.gun.get(e):e,i={},s=o.map().on(function(e,n){if("_"!==n&&e)if(!t||t(e)){var o="object"==typeof e?uP(e):e;i[n]=o,r.next(Object.values(i))}else i[n]&&(delete i[n],r.next(Object.values(i)))});return function(){s&&"function"==typeof s&&s(),o.off()}})},e.prototype.put=function(e,t){var n=this;return new G(function(r){var o=function(e,t){e.put(t,function(e){e.err?r.error(new Error(e.err)):(r.next(t),r.complete())})};if("string"==typeof e||Array.isArray(e)){var i=void 0;if(Array.isArray(e)){i=n.gun.get(e[0]);for(var s=1;s<e.length;s++)i=i.get(e[s])}else i=n.gun.get(e);o(i,t)}else o(n.gun,e)})},e.prototype.putCompat=function(e,t){var n=this;return new G(function(r){n.gun.put(e,function(n){t&&t(n),n.err?r.error(new Error(n.err)):(r.next(e),r.complete())})})},e.prototype.set=function(e,t){var n=this;return new G(function(r){var o=function(e,t){e.set(t,function(e){e.err?r.error(new Error(e.err)):(r.next(t),r.complete())})};if("string"==typeof e||Array.isArray(e)){var i=void 0;if(Array.isArray(e)){i=n.gun.get(e[0]);for(var s=1;s<e.length;s++)i=i.get(e[s])}else i=n.gun.get(e);o(i,t)}else o(n.gun,e)})},e.prototype.setCompat=function(e,t){var n=this;return new G(function(r){n.gun.set(e,function(n){t&&t(n),n.err?r.error(new Error(n.err)):(r.next(e),r.complete())})})},e.prototype.once=function(e){var t;return t="string"==typeof e?this.gun.get(e):e||this.gun,new G(function(e){t.once(function(t){if(null==t)return e.next(null),void e.complete();var n="object"==typeof t?uP(t):t;e.next(n),e.complete()})})},e.prototype.compute=function(e,t){var n=this,r=e.map(function(e){return"string"==typeof e?n.observe(e):e});return new G(function(n){var o=new Array(e.length).fill(void 0),i=new Array(e.length).fill(!1),s=r.map(function(e,r){return e.subscribe({next:function(e){if(o[r]=e,o.every(function(e){return void 0!==e}))try{var i=t.apply(void 0,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(o),!1));n.next(i)}catch(e){n.error(e)}},error:function(e){return n.error(e)},complete:function(){i[r]=!0,i.every(function(e){return e})&&n.complete()}})});return function(){s.forEach(function(e){return e.unsubscribe()})}})},e.prototype.userPut=function(e,t,n){var r=this;return new G(function(o){var i=r.gun.user();"string"==typeof e?i.get(e).put(t,function(e){n&&n(e),e.err?o.error(new Error(e.err)):(o.next(t),o.complete())}):i.put(e,function(t){n&&n(t),t.err?o.error(new Error(t.err)):(o.next(e),o.complete())})})},e.prototype.userSet=function(e,t,n){var r=this;return new G(function(o){var i=r.gun.user();"string"==typeof e?i.get(e).set(t,function(e){n&&n(e),e.err?o.error(new Error(e.err)):(o.next(t),o.complete())}):i.set(e,function(t){n&&n(t),t.err?o.error(new Error(t.err)):(o.next(e),o.complete())})})},e.prototype.userOnce=function(e,t){var n=this;return new G(function(r){var o=n.gun.user();(e?o.get(e):o).once(function(e,n){t&&t(n),n&&n.err?r.error(new Error(n.err)):(r.next(e),r.complete())})})},e.prototype.userGet=function(e){return this.observe(this.gun.user().get(e))},e.prototype.observeUser=function(e){return e?this.observe(this.gun.user().get(e)):this.observe(this.gun.user().get("~"))},e.prototype.removeGunMeta=function(e){return uP(e)},e}();function uP(e){if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(var t=e.length,n=new Array(t),r=0;r<t;r++){var o=e[r];n[r]=o&&"object"==typeof o?uP(o):o}return n}var i={};for(var s in e)"_"!==s&&"#"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&(o=e[s],i[s]=o&&"object"==typeof o?uP(o):o);return i}var lP,fP=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),hP=function(e){function t(t){var n=e.call(this,t)||this;return n.name="GunError",n}return fP(t,e),t}(Error),dP=function(e){function t(t){var n=e.call(this,t)||this;return n.name="AuthError",n}return fP(t,e),t}(hP),pP=(fP(function(e){void 0===e&&(e="Credenziali non valide");var t=lP.call(this,e)||this;return t.name="InvalidCredentials",t},lP=dP),function(e){fP(function(t){void 0===t&&(t="Utente già esistente");var n=e.call(this,t)||this;return n.name="UserExists",n},e)}(dP),function(e){fP(function(t){void 0===t&&(t="Timeout durante l'operazione");var n=e.call(this,t)||this;return n.name="TimeoutError",n},e)}(hP),function(e){fP(function(t){void 0===t&&(t="Autenticazione multipla in corso");var n=e.call(this,t)||this;return n.name="MultipleAuthError",n},e)}(dP),function(e){fP(function(){return null!==e&&e.apply(this,arguments)||this},e)}(hP),function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})}),gP=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},yP=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},mP=8,wP=1024,bP=64,vP=function(){function e(e,t,n){var r;if(this.user=null,this.onAuthCallbacks=[],this._isDestroyed=!1,this.prefix="",this.ev={},this.eventEmitter=new Pe,this.core=t,!e)throw new Error("Gun instance is required but was not provided");if("function"!=typeof e.user)throw new Error("Gun instance is invalid: gun.user is not a function");this.gun=e,this.user=this.gun.user().recall({sessionStorage:!0}),this.subscribeToAuthEvents(),this.crypto=VI,this.sea=n||null,this.sea||(this.gun.SEA?this.sea=this.gun.SEA:(null===(r=globalThis.Gun)||void 0===r?void 0:r.SEA)?this.sea=globalThis.Gun.SEA:globalThis.SEA&&(this.sea=globalThis.SEA)),this._rxjs=new cP(this.gun),this.usernamesNode=this.gun.get("usernames"),console.log("[DB] DataBase initialization completed")}return e.prototype.initialize=function(){},e.prototype.subscribeToAuthEvents=function(){var e=this;this.gun.on("auth",function(t){var n;t.err?console.error("[DB] Auth event error:",t.err):e.notifyAuthListeners((null===(n=t.sea)||void 0===n?void 0:n.pub)||"")})},e.prototype.notifyAuthListeners=function(e){var t=this.gun.user();this.onAuthCallbacks.forEach(function(e){return e(t)})},e.prototype.onAuth=function(e){var t=this;this.onAuthCallbacks.push(e);var n=this.gun.user();return n&&n.is&&e(n),function(){var n=t.onAuthCallbacks.indexOf(e);-1!==n&&t.onAuthCallbacks.splice(n,1)}},e.prototype.isLoggedIn=function(){try{var e=this.gun.user();return!!(e&&e.is&&e.is.pub)}catch(e){return!1}},e.prototype.restoreSession=function(){return pP(this,void 0,void 0,function(){var e,t,n,r,o,i;return gP(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),"undefined"==typeof sessionStorage?[2,{success:!1,error:"sessionStorage not available"}]:(e=sessionStorage.getItem("gunSessionData"))?!(t=JSON.parse(e)).version||t.version<2?(sessionStorage.removeItem("gunSessionData"),[2,{success:!1,error:"Legacy session expired"}]):t.encrypted&&t.integrity&&t.salt&&t.pub?[4,this.sea.work(t.encrypted,null,null,{name:"SHA-256"})]:[2,{success:!1,error:"Invalid encrypted session format"}]:[2,{success:!1,error:"No saved session"}];case 1:return s.sent()!==t.integrity?(sessionStorage.removeItem("gunSessionData"),[2,{success:!1,error:"Session integrity check failed"}]):[4,this.deriveSessionKey(t.username,t.salt,t.pub)];case 2:return n=s.sent(),[4,this.sea.decrypt(t.encrypted,n)];case 3:return(r=s.sent())?r.pub!==t.pub?[2,{success:!1,error:"Session public key mismatch"}]:r.expiresAt&&Date.now()>r.expiresAt?(sessionStorage.removeItem("gunSessionData"),[2,{success:!1,error:"Session expired"}]):(o=this.gun.user()).is&&o.is.pub===t.pub?(this.user=o,[2,{success:!0,userPub:t.pub}]):[2,{success:!1,error:"Session verification failed"}]:(sessionStorage.removeItem("gunSessionData"),[2,{success:!1,error:"Session decryption failed"}]);case 4:return i=s.sent(),console.error("[DB] Restore session error:",i),[2,{success:!1,error:String(i)}];case 5:return[2]}})})},e.prototype.logout=function(){try{var e=!!this.user,t=this.gun.user();t&&t.is&&t.leave(),this.user=null,"undefined"!=typeof sessionStorage&&sessionStorage.removeItem("gunSessionData"),e&&this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:logout",void 0)}catch(e){console.error("[DB] Error during logout:",e)}},e.prototype.validatePasswordStrength=function(e){return e.length<mP?{valid:!1,error:"Password must be at least ".concat(mP," characters long")}:e.length>wP?{valid:!1,error:"Password must be ".concat(wP," characters or fewer")}:/[A-Z]/.test(e)?/[a-z]/.test(e)?/[0-9]/.test(e)?/[!@#$%^&*()_+\-=[\]{}|;':",./<>?]/.test(e)?{valid:!0}:{valid:!1,error:"Password must contain at least one special character"}:{valid:!1,error:"Password must contain at least one number"}:{valid:!1,error:"Password must contain at least one lowercase letter"}:{valid:!1,error:"Password must contain at least one uppercase letter"}},e.prototype.validateSignupCredentials=function(e,t,n){return!e||e.length<1?{valid:!1,error:"Username must be more than 0 characters long"}:e.length>bP?{valid:!1,error:"Username must be ".concat(bP," characters or fewer")}:/^[a-zA-Z0-9._-]+$/.test(e)?n?n.pub&&n.priv&&n.epub&&n.epriv?{valid:!0}:{valid:!1,error:"Invalid pair provided"}:this.validatePasswordStrength(t):{valid:!1,error:"Username can only contain letters, numbers, dots, underscores, and hyphens"}},e.prototype.ensureAliasAvailable=function(e){return pP(this,arguments,void 0,function(e,t){return void 0===t&&(t=5e3),gP(this,function(n){switch(n.label){case 0:return[4,this.isAliasAvailable(e,t)];case 1:if(!n.sent())throw new Error('Alias "'.concat(e,'" is already registered in Gun'));return[2]}})})},e.prototype.isAliasAvailable=function(e){return pP(this,arguments,void 0,function(e,t){var n,r=this;return void 0===t&&(t=5e3),gP(this,function(o){if("string"!=typeof e||!e.trim())throw new Error("Alias must be a non-empty string");return n=e.trim().toLowerCase(),[2,new Promise(function(e,o){var i=!1,s=setTimeout(function(){i||(i=!0,o(new Error("Timeout while checking alias availability")))},t);r.usernamesNode.get(n).once(function(t){i||(i=!0,clearTimeout(s),e(!t))})})]})})},e.prototype.isAliasTaken=function(e){return pP(this,void 0,void 0,function(){var t=this;return gP(this,function(n){return[2,new Promise(function(n,r){t.gun.get("~@".concat(e)).once(function(e){n(!!e)})})]})})},e.prototype.registerAlias=function(e,t){return pP(this,arguments,void 0,function(e,t,n){var r,o,i=this;return void 0===n&&(n=5e3),gP(this,function(s){switch(s.label){case 0:if(!e||!e.trim())throw new Error("Alias must be provided for registration");if(!t)throw new Error("userPub must be provided for alias registration");return r=e.trim().toLowerCase(),[4,this.isAliasAvailable(r,n).catch(function(e){throw console.error("[DB] Alias availability check failed:",e),e})];case 1:return o=s.sent(),[4,this.isAliasTaken(r)];case 2:if(s.sent())throw new Error('Alias "'.concat(r,'" is already taken'));if(!o)throw new Error('Alias "'.concat(r,'" is no longer available for registration'));return[4,new Promise(function(e,o){var s=!1,a=setTimeout(function(){s||(s=!0,o(new Error("Timeout while registering alias")))},n);i.usernamesNode.get(r).put(t,function(t){s||(s=!0,clearTimeout(a),t&&t.err?o(new Error(String(t.err))):e())})}).catch(function(e){throw console.error("[DB] Failed to register alias:",e),e})];case 3:return s.sent(),[2]}})})},e.prototype.resetAuthState=function(){try{var e=this.gun.user();if(e&&e._){var t=e._;t.ing=!1,t.auth=null,t.act=null,t.auth&&(t.auth=null)}try{e.leave()}catch(e){}this.user=null}catch(e){}},e.prototype.buildLoginResult=function(e,t){var n,r,o=null===(r=null===(n=this.gun.user())||void 0===n?void 0:n._)||void 0===r?void 0:r.sea;return{success:!0,userPub:t,username:e,sea:o?{pub:o.pub,priv:o.priv,epub:o.epub,epriv:o.epriv}:void 0}},e.prototype.getDeviceSecret=function(){try{if("undefined"==typeof localStorage)return"";var e="shogun_device_secret",t=localStorage.getItem(e);if(!t){t=this.crypto.randomUUID();try{localStorage.setItem(e,t)}catch(e){console.warn("[DB] Failed to save device secret to localStorage",e)}}return t}catch(e){return""}},e.prototype.deriveSessionKey=function(e,t,n){return pP(this,void 0,void 0,function(){var r,o;return gP(this,function(i){switch(i.label){case 0:if(!this.sea)throw new Error("SEA not available");return r=this.getDeviceSecret(),o="".concat(e,":").concat(t,":").concat(n,":").concat(r),[4,this.sea.work(o,null,null,{name:"SHA-256"})];case 1:return[2,i.sent()]}})})},e.prototype.saveCredentials=function(e){return pP(this,void 0,void 0,function(){var t,n,r,o,i,s,a;return gP(this,function(c){switch(c.label){case 0:return c.trys.push([0,6,,7]),"undefined"==typeof sessionStorage?[3,5]:this.sea?[4,this.sea.work(this.crypto.randomUUID(),null,null,{name:"SHA-256"})]:[2];case 1:return t=c.sent(),[4,this.deriveSessionKey(e.alias,t,e.userPub)];case 2:return n=c.sent(),r={username:e.alias,pair:e.pair,pub:e.userPub,expiresAt:Date.now()+6048e5},[4,this.sea.encrypt(r,n)];case 3:return o=c.sent(),[4,this.sea.work(o,null,null,{name:"SHA-256"})];case 4:i=c.sent(),s={version:2,username:e.alias,pub:e.userPub,salt:t,encrypted:o,integrity:i},sessionStorage.setItem("gunSessionData",JSON.stringify(s)),c.label=5;case 5:return[3,7];case 6:return a=c.sent(),console.error("[DB] Error saving credentials:",a),[3,7];case 7:return[2]}})})},e.prototype.signUp=function(e,t,n){return pP(this,void 0,void 0,function(){var r,o,i,s,a,c=this;return gP(this,function(u){switch(u.label){case 0:if(!(r=this.validateSignupCredentials(e,t,n)).valid)return[2,{success:!1,error:r.error}];if(this.resetAuthState(),o=e.trim().toLowerCase(),i=this.gun.user(),!n)return[3,4];u.label=1;case 1:return u.trys.push([1,3,,4]),[4,new Promise(function(e){var t=!1;i.auth(n,function(r){return pP(c,void 0,void 0,function(){var s,a,c,u,l,f;return gP(this,function(h){switch(h.label){case 0:return t?[2]:(t=!0,r.err?(e({success:!1,error:r.err}),[2]):(s=null===(u=null==i?void 0:i.is)||void 0===u?void 0:u.pub)?(this.user=i,a=null===(l=null==i?void 0:i.is)||void 0===l?void 0:l.alias,c=null===(f=null==i?void 0:i._)||void 0===f?void 0:f.sea,[4,this.saveCredentials({alias:a||o,pair:null!=n?n:c,userPub:s})]):(this.resetAuthState(),e({success:!1,error:"No userPub available"}),[2]));case 1:return h.sent(),this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:signup",{userPub:s,username:o,method:"pair"}),e(this.buildLoginResult(a||o,s)),[2]}})})})})];case 2:return(s=u.sent())&&s.success?[2,s]:[3,4];case 3:return u.sent(),[3,4];case 4:return u.trys.push([4,6,,7]),[4,this.ensureAliasAvailable(o)];case 5:return u.sent(),[3,7];case 6:return[2,{success:!1,error:(a=u.sent())instanceof Error?a.message:String(a)}];case 7:return[4,new Promise(function(e){var r=!1;i.create(o,t,function(s){if(!r){if(s.err||void 0!==s.ok&&0!==s.ok)return r=!0,c.resetAuthState(),void e({success:!1,error:s.err||"Signup failed"});if(!s.pub)return r=!0,c.resetAuthState(),void e({success:!1,error:"No userPub available from signup"});i.auth(o,t,function(t){return pP(c,void 0,void 0,function(){var s,a,c,u,l,f,h,d,p;return gP(this,function(g){switch(g.label){case 0:if(r)return[2];if(r=!0,t.err)return this.resetAuthState(),e({success:!1,error:t.err||"Authentication after signup failed"}),[2];if(!(s=null===(f=null==i?void 0:i.is)||void 0===f?void 0:f.pub))return this.resetAuthState(),e({success:!1,error:"User not authenticated after signup"}),[2];this.user=i,a=null===(h=null==i?void 0:i.is)||void 0===h?void 0:h.alias,c=null===(d=null==i?void 0:i._)||void 0===d?void 0:d.sea,g.label=1;case 1:return g.trys.push([1,3,,4]),[4,this.saveCredentials({alias:a||o,pair:null!=n?n:c,userPub:s})];case 2:case 3:return g.sent(),[3,4];case 4:return g.trys.push([4,6,,7]),[4,this.registerAlias(a||o,s)];case 5:return g.sent(),[3,7];case 6:return u=g.sent(),console.error("[DB] Alias registration failed:",u),[3,7];case 7:return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:signup",{userPub:s,username:o,method:n?"pair":"password"}),l=null===(p=null==i?void 0:i._)||void 0===p?void 0:p.sea,e({success:!0,userPub:s,username:o,isNewUser:!0,sea:l?{pub:l.pub,priv:l.priv,epub:l.epub,epriv:l.epriv}:void 0}),[2]}})})})}})})];case 8:return[2,u.sent()]}})})},e.prototype.login=function(e,t,n){return pP(this,void 0,void 0,function(){var r,o,i=this;return gP(this,function(s){return this.resetAuthState(),r=e.trim().toLowerCase(),o=this.gun.user(),[2,new Promise(function(e){n?o.auth(n,function(t){return pP(i,void 0,void 0,function(){var i,s,a,c,u,l;return gP(this,function(f){switch(f.label){case 0:if(t.err)return this.resetAuthState(),e({success:!1,error:t.err}),[2];if(!(i=null===(c=null==o?void 0:o.is)||void 0===c?void 0:c.pub))return this.resetAuthState(),e({success:!1,error:"No userPub available"}),[2];this.user=o,s=null===(u=null==o?void 0:o.is)||void 0===u?void 0:u.alias,a=null===(l=null==o?void 0:o._)||void 0===l?void 0:l.sea,f.label=1;case 1:return f.trys.push([1,3,,4]),[4,this.saveCredentials({alias:s||r,pair:null!=n?n:a,userPub:i})];case 2:case 3:return f.sent(),[3,4];case 4:return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:login",{userPub:i,username:s||r,method:"pair"}),e(this.buildLoginResult(s||r,i)),[2]}})})}):o.auth(r,t,function(t){return pP(i,void 0,void 0,function(){var i,s,a,c,u,l;return gP(this,function(f){switch(f.label){case 0:if(t.err)return this.resetAuthState(),e({success:!1,error:t.err}),[2];if(!(i=null===(c=null==o?void 0:o.is)||void 0===c?void 0:c.pub))return this.resetAuthState(),e({success:!1,error:"No userPub available"}),[2];this.user=o,s=null===(u=null==o?void 0:o.is)||void 0===u?void 0:u.alias,a=null===(l=null==o?void 0:o._)||void 0===l?void 0:l.sea,f.label=1;case 1:return f.trys.push([1,3,,4]),[4,this.saveCredentials({alias:s||r,pair:null!=n?n:a,userPub:i})];case 2:case 3:return f.sent(),[3,4];case 4:return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:login",{userPub:i,username:s||r,method:"password"}),e(this.buildLoginResult(s||r,i)),[2]}})})})})]})})},e.prototype.getCurrentUser=function(){try{var e=this.gun.user();return e&&e.is&&e.is.pub?{pub:e.is.pub,user:e}:null}catch(e){return null}},e.prototype.getUserPub=function(){var e;try{var t=this.gun.user();return(null===(e=null==t?void 0:t.is)||void 0===e?void 0:e.pub)||null}catch(e){return null}},e.prototype.loginWithPair=function(e,t){return pP(this,void 0,void 0,function(){var n,r,o=this;return gP(this,function(i){return t&&t.pub&&t.priv&&t.epub&&t.epriv?e.length>bP?[2,{success:!1,error:"Username must be ".concat(bP," characters or fewer")}]:(this.resetAuthState(),n=e.trim().toLowerCase(),r=this.gun.user(),console.log("[DB] Login with pair for username:",n),[2,new Promise(function(e){r.auth(t,function(i){return pP(o,void 0,void 0,function(){var o,s,a,c,u,l;return gP(this,function(f){switch(f.label){case 0:if(i.err)return this.resetAuthState(),e({success:!1,error:i.err}),[2];if(!(o=null===(c=null==r?void 0:r.is)||void 0===c?void 0:c.pub))return this.resetAuthState(),e({success:!1,error:"No userPub available"}),[2];this.user=r,s=null===(u=null==r?void 0:r.is)||void 0===u?void 0:u.alias,a=null===(l=null==r?void 0:r._)||void 0===l?void 0:l.sea,f.label=1;case 1:return f.trys.push([1,3,,4]),[4,this.saveCredentials({alias:s||n,pair:null!=t?t:a,userPub:o})];case 2:case 3:return f.sent(),[3,4];case 4:return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:login",{userPub:o,username:s||n,method:"pair"}),e(this.buildLoginResult(s||n,o)),[2]}})})})})]):[2,{success:!1,error:"Invalid pair structure - missing required keys"}]})})},e.prototype.loginWithPairLegacy=function(e,t){return pP(this,void 0,void 0,function(){return gP(this,function(n){return[2,this.login(e,"",t)]})})},e.prototype.rx=function(){return this._rxjs},e.prototype._timeout=function(e){return pP(this,void 0,void 0,function(){return gP(this,function(t){return[2,new Promise(function(t){return setTimeout(t,e)})]})})},e.prototype.Off=function(e){void 0===e&&(e="default"),this.ev[e]&&this.ev[e].handler?this.ev[e].handler.off():this.ev[e]={handler:null}},e.prototype.Listen=function(e,t,n){void 0===n&&(n=this.prefix);var r=(e="".concat(n).concat(e)).split("/"),o=this.gun;r.forEach(function(e){o=o.get(e)}),o.map().once(function(e){t(e)})},e.prototype.On=function(e,t,n,r,o){var i=this;void 0===n&&(n="default"),void 0===r&&(r=!0),void 0===o&&(o=this.prefix);var s=(e="".concat(o).concat(e)).split("/"),a=this.gun;s.forEach(function(e){a=a.get(e)}),a.on(function(e,r,o,s){i.ev[n]={handler:s},e&&t(JSON.parse(JSON.stringify(e)))},{change:r})},e.prototype.addContentAdressing=function(e,t){var n=this;return"object"==typeof t&&(t=JSON.stringify(t)),new Promise(function(r,o){n.sea.work(t,null,void 0,{name:"SHA-256"}).then(function(i){i?n.gun.get("".concat(e)).get(i).put(t,function(e){r(e)}):o(new Error("Hash generation failed"))}).catch(o)})},e.prototype.userGet=function(e,t,n){void 0===t&&(t=1),void 0===n&&(n=this.prefix);var r=this.getUserPub();return r?(e="~".concat(r,"/").concat(e),this.Get(e,t,n)):Promise.resolve(void 0)},e.prototype.userLoad=function(e,t,n,r){void 0===t&&(t=!1),void 0===n&&(n=1),void 0===r&&(r=this.prefix);var o=this.getUserPub();return o?(e="~".concat(o,"/").concat(e),this.Load(e,t,n,r)):Promise.resolve({data:{},err:[{path:e,err:"User not logged in"}]})},e.prototype.Get=function(e,t,n){var r=this;void 0===t&&(t=1),void 0===n&&(n=this.prefix);var o=e,i=(e="".concat(n).concat(e)).split("/"),s=this.gun;return i.forEach(function(e){s=s.get(e)}),new Promise(function(i,a){setTimeout(function(){a({err:"timeout",ket:"TIMEOUT, Possibly Data : ".concat(e," is corrupt"),data:{},"#":e})},5e3),s.once(function(s){return pP(r,void 0,void 0,function(){var r,c;return gP(this,function(u){switch(u.label){case 0:return s?(s=JSON.parse(JSON.stringify(s)),i(s),[3,8]):[3,1];case 1:return t?[4,this._timeout(1e3)]:[3,7];case 2:u.sent(),u.label=3;case 3:return u.trys.push([3,5,,6]),[4,this.Get(o,t-1,n)];case 4:return r=u.sent(),i(r),[3,6];case 5:return c=u.sent(),a(c),[3,6];case 6:return[3,8];case 7:a({err:"notfound",ket:"Data Not Found, Data : ".concat(e," is undefined"),data:{},"#":e}),u.label=8;case 8:return[2]}})})})})},e.prototype.userPut=function(e,t,n,r){var o=this;return void 0===n&&(n=!1),void 0===r&&(r=this.prefix),new Promise(function(i,s){var a=o.getUserPub();a?(e="~".concat(a,"/").concat(e),o.Put(e,t,n,r).then(i).catch(s)):s({err:new Error("User Belum Login"),ok:void 0})})},e.prototype._randomAlphaNumeric=function(e){for(var t="",n=0;n<e;n++)t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return t},e.prototype.Set=function(e,t,n,r,o){var i=this;return void 0===n&&(n=!1),void 0===r&&(r=this.prefix),void 0===o&&(o=void 0),new Promise(function(s,a){var c=i._randomAlphaNumeric(30);t.id=c,i.Put("".concat(e,"/").concat(c),t,n,r,o).then(function(e){s(e)}).catch(function(e){a(e)})})},e.prototype.Put=function(e,t,n,r,o){var i,s;void 0===n&&(n=!1),void 0===r&&(r=this.prefix),void 0===o&&(o=void 0);var a=(e="".concat(r).concat(e)).split("/"),c=this.gun;a.forEach(function(e){c=c.get(e)}),void 0===t&&(t={t:"_"});var u=[],l={data:[],error:[]};if("object"==typeof t&&null!==t)try{for(var f=yP(Object.keys(t)),h=f.next();!h.done;h=f.next()){var d=h.value;if(Object.hasOwnProperty.call(t,d)){var p=t[d];"object"==typeof p&&(delete t[d],u.push(this.Put("".concat(e,"/").concat(d),p,n).then(function(e){return l.data=l.data.concat(e.data),l.error=l.error.concat(e.error),e.data[0]})))}}}catch(e){i={error:e}}finally{try{h&&!h.done&&(s=f.return)&&s.call(f)}finally{if(i)throw i.error}}return new Promise(function(n,r){Promise.allSettled(u).then(function(){t&&0===Object.keys(t).length?n(l):(setTimeout(function(){l.error.push({err:Error("TIMEOUT, Failed to put Data"),ok:e}),n(l)},2e3),c.put(t,function(t){void 0===t.err?l.data.push(t):l.error.push({err:Error(JSON.stringify(t)),ok:e}),n(l)},o))}).catch(function(t){l.error.push({err:Error(JSON.stringify(t)),ok:e}),n(l)})})},e.prototype.purge=function(e){var t=this;return new Promise(function(n,r){t.Get(e).then(function(o){var i,s,a=JSON.parse(JSON.stringify(o));if("object"==typeof a&&null!==a)try{for(var c=yP(Object.keys(a)),u=c.next();!u.done;u=c.next()){var l=u.value;"_"!=l&&">"!=l&&"#"!=l&&":"!=l&&(a[l]=null)}}catch(e){i={error:e}}finally{try{u&&!u.done&&(s=c.return)&&s.call(c)}finally{if(i)throw i.error}}t.Put(e,a).then(function(){n("OK")}).catch(function(e){console.log(e),r(JSON.stringify(e))})}).catch(r)})},e.prototype.userDel=function(e,t){var n=this;return void 0===t&&(t=!0),new Promise(function(r,o){var i=n.getUserPub();if(!i)return o(new Error("User not logged in"));e="~".concat(i,"/").concat(e),n.Del(e,t).then(function(e){r(e)}).catch(function(e){o(e)})})},e.prototype.Del=function(e,t,n){var r=this;return void 0===t&&(t=!0),void 0===n&&(n=""),new Promise(function(o,i){try{var s,a=e.split("/"),c=r.gun;s=t?null:a[0].indexOf("~")>=0?r.gun.user().get("newNode").set({t:"_"}):r.gun.get("newNode").set({t:"_"}),a.forEach(function(e){c=c.get(e)}),n?c.put(s,function(e){void 0===e.err?o({data:[{ok:"ok",err:void 0}],error:[]}):i({data:[{ok:"",err:e.err}],error:[]})},{opt:{cert:n}}):c.put(s,function(e){void 0===e.err?o({data:[{ok:"ok",err:void 0}],error:[]}):i({data:[{ok:"",err:e.err}],error:[]})})}catch(e){i(e)}})},e.prototype.Load=function(e,t,n,r){var o=this;return void 0===t&&(t=!1),void 0===n&&(n=1),void 0===r&&(r=this.prefix),new Promise(function(i,s){var a=[],c={data:{},err:[]};o.Get(e,n,r).then(function(n){var r,s;if("object"==typeof n&&null!==n){var u,l=function(r){"_"!=r&&"#"!=r&&">"!=r&&("object"==typeof(u="object"==typeof n?n[r]:n)?a.push(o.Load("".concat(e,"/").concat(r),t).then(function(e){c.data[r]=e}).catch(function(e){c.err.push(e)})):c.data[r]=u)};try{for(var f=yP(Object.keys(n)),h=f.next();!h.done;h=f.next())l(h.value)}catch(e){r={error:e}}finally{try{h&&!h.done&&(s=f.return)&&s.call(f)}finally{if(r)throw r.error}}}Promise.allSettled(a).then(function(){i(c)}).catch(function(e){c.err.push(e),i(c)})}).catch(function(e){c.err.push(e),i(c)})})},e.prototype.generatePublicCert=function(){var e=this;return new Promise(function(t,n){var r,o,i=e.getUserPub(),s=null===(o=null===(r=e.gun.user())||void 0===r?void 0:r._)||void 0===o?void 0:o.sea;i&&s?e.sea.certify("*",[{"*":"chat-with","+":"*"}],s,null,{}).then(function(t){return e.userPut("chat-cert",t)}).then(function(e){return t(e)}).catch(n):n("User belum Login")})},e.prototype.destroy=function(){if(!this._isDestroyed){if(console.log("[DB] Destroying DataBase instance..."),this._isDestroyed=!0,this.onAuthCallbacks.length=0,this.eventEmitter.removeAllListeners(),this.user){try{this.user.leave()}catch(e){}this.user=null}this._rxjs=void 0,console.log("[DB] DataBase instance destroyed")}},e.prototype.aggressiveAuthCleanup=function(){console.log("🧹 Performing aggressive auth cleanup..."),this.resetAuthState(),this.logout(),console.log("✓ Aggressive auth cleanup completed")},e.prototype.on=function(e,t){this.eventEmitter.on(e,t)},e.prototype.off=function(e,t){this.eventEmitter.off(e,t)},e.prototype.once=function(e,t){this.eventEmitter.once(e,t)},e.prototype.emit=function(e,t){return this.eventEmitter.emit(e,t)},e}(),EP=function(){function e(e){this.holster=e,this.user=e.user()}return e.prototype.getUser=function(){return this.user},e.prototype.getUserPub=function(){var e;return null===(e=this.user.is)||void 0===e?void 0:e.pub},e.prototype.observe=function(e){var t=this;return new G(function(n){var r;if(Array.isArray(e)){r=t.holster.get(e[0]);for(var o=1;o<e.length;o++)r=r.next(e[o])}else r="string"==typeof e?t.holster.get(e):e;var i=r.on(function(e){if(null!=e)if("object"==typeof e&&null!==e){var r=t.removeHolsterMeta(e);n.next(r)}else n.next(e);else n.next(null)});return function(){i&&"function"==typeof i?i():r.off()}}).pipe(iP(function(e,t){return aP(e,t)}))},e.prototype.match=function(e,t){var n=this;return new G(function(r){if(!e)return r.next([]),void r.complete();var o="string"==typeof e?n.holster.get(e):e,i={},s=o.on(function(e,o){if("_"!==o&&e){var s=o||String(Object.keys(i).length);if(!t||t(e)){var a="object"==typeof e?n.removeHolsterMeta(e):e;i[s]=a,r.next(Object.values(i))}else i[s]&&(delete i[s],r.next(Object.values(i)))}});return function(){s&&"function"==typeof s?s():o.off()}})},e.prototype.put=function(e,t){var n=this;return new G(function(r){var o=function(e,t){e.put(t,function(e){e&&e.err?r.error(new Error(e.err)):(r.next(t),r.complete())})};if("string"==typeof e||Array.isArray(e)){var i=void 0;if(Array.isArray(e)){i=n.holster.get(e[0]);for(var s=1;s<e.length;s++)i=i.next(e[s])}else i=n.holster.get(e);o(i,t)}else o(n.holster,e)})},e.prototype.once=function(e){var t,n=this;return t="string"==typeof e?this.holster.get(e):e||this.holster,new G(function(e){var r=!1,o=function(t){if(!r){if(r=!0,null==t)return e.next(null),void e.complete();var o="object"==typeof t?n.removeHolsterMeta(t):t;e.next(o),e.complete()}};t.on(o),setTimeout(function(){t.off(o)},0)})},e.prototype.compute=function(e,t){var n=this,r=e.map(function(e){return"string"==typeof e?n.observe(e):e});return new G(function(n){var o=new Array(e.length).fill(void 0),i=new Array(e.length).fill(!1),s=r.map(function(e,r){return e.subscribe({next:function(e){if(o[r]=e,o.every(function(e){return void 0!==e}))try{var i=t.apply(void 0,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(o),!1));n.next(i)}catch(e){n.error(e)}},error:function(e){return n.error(e)},complete:function(){i[r]=!0,i.every(function(e){return e})&&n.complete()}})});return function(){s.forEach(function(e){return e.unsubscribe()})}})},e.prototype.userPut=function(e,t,n){var r=this;return new G(function(o){var i=r.holster.user();"string"==typeof e?i.get(e).put(t,function(e){n&&n(e),e&&e.err?o.error(new Error(e.err)):(o.next(t),o.complete())}):i.put(e,function(t){n&&n(t),t&&t.err?o.error(new Error(t.err)):(o.next(e),o.complete())})})},e.prototype.userGet=function(e){return this.observe(this.holster.user().get(e))},e.prototype.observeUser=function(e){var t=this.holster.user();return e?this.observe(t.get(e)):this.observe(t.get("~"))},e.prototype.removeHolsterMeta=function(e){if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(var t=e.length,n=new Array(t),r=0;r<t;r++){var o=e[r];n[r]=o&&"object"==typeof o?this.removeHolsterMeta(o):o}return n}var i={},s=Object.keys(e);for(r=0;r<s.length;r++){var a=s[r];"_"===a||a.startsWith("~")||(o=e[a],i[a]=o&&"object"==typeof o?this.removeHolsterMeta(o):o)}return i},e}(),AP=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},xP=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},kP=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},SP=8,IP=1024,PP=64,CP=function(){function e(e,t,n){var r;if(this.user=null,this.prefix="",this.ev={},this.onAuthCallbacks=[],this._isDestroyed=!1,this.authPollInterval=null,this.lastUserState=null,this.eventEmitter=new Pe,this.core=t,!e)throw new Error("Holster instance is required but was not provided");if("function"!=typeof e.user)throw new Error("Holster instance is invalid: holster.user is not a function");this.holster=e;var o=this.holster.user();o.recall(),this.user=o.is?o:null,this.subscribeToAuthEvents(),this.crypto=VI,this.sea=n||null,this.sea||(this.holster.SEA?this.sea=this.holster.SEA:(null===(r=globalThis.Holster)||void 0===r?void 0:r.SEA)?this.sea=globalThis.Holster.SEA:globalThis.SEA&&(this.sea=globalThis.SEA)),this._rxjs=new EP(this.holster),this.usernamesNode=this.holster.get("usernames"),console.log("[DB] DataBaseHolster initialization completed")}return e.prototype.initialize=function(){},e.prototype.subscribeToAuthEvents=function(){var e=this;this.authPollInterval=setInterval(function(){var t=e.holster.user().is;if(t!==e.lastUserState){var n=e.lastUserState;e.lastUserState=t,t?(e.notifyAuthListeners(t.pub||""),e.core&&"function"==typeof e.core.emit&&!n&&e.core.emit("auth:login",{userPub:t.pub||"",username:t.username||"",method:"password"})):(e.notifyAuthListeners(""),e.core&&"function"==typeof e.core.emit&&n&&e.core.emit("auth:logout",void 0))}},100)},e.prototype.notifyAuthListeners=function(e){var t=this.holster.user();this.onAuthCallbacks.forEach(function(e){return e(t)})},e.prototype.onAuth=function(e){var t=this;this.onAuthCallbacks.push(e);var n=this.holster.user();return n&&n.is&&e(n),function(){var n=t.onAuthCallbacks.indexOf(e);-1!==n&&t.onAuthCallbacks.splice(n,1)}},e.prototype.isLoggedIn=function(){try{var e=this.holster.user();return!!(e&&e.is&&e.is.pub)}catch(e){return!1}},e.prototype.restoreSession=function(){try{if("undefined"==typeof sessionStorage)return{success:!1,error:"sessionStorage not available"};var e=sessionStorage.getItem("gunSessionData");if(!e)return{success:!1,error:"No saved session"};var t=JSON.parse(e);if(!t.userPub)return{success:!1,error:"Invalid session data"};if(t.expiresAt&&Date.now()>t.expiresAt)return sessionStorage.removeItem("gunSessionData"),{success:!1,error:"Session expired"};var n=this.holster.user();return n.is&&n.is.pub===t.userPub?(this.user=n,{success:!0,userPub:t.userPub}):{success:!1,error:"Session verification failed"}}catch(e){return{success:!1,error:String(e)}}},e.prototype.logout=function(){try{var e=!!this.user,t=this.holster.user();t&&t.is&&t.leave(),this.user=null,"undefined"!=typeof sessionStorage&&sessionStorage.removeItem("gunSessionData"),e&&this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:logout",void 0)}catch(e){console.error("[DB] Error during logout:",e)}},e.prototype.validatePasswordStrength=function(e){return e.length<SP?{valid:!1,error:"Password must be at least ".concat(SP," characters long")}:e.length>IP?{valid:!1,error:"Password must be ".concat(IP," characters or fewer")}:/[A-Z]/.test(e)?/[a-z]/.test(e)?/[0-9]/.test(e)?/[!@#$%^&*()_+\-=[\]{}|;':",./<>?]/.test(e)?{valid:!0}:{valid:!1,error:"Password must contain at least one special character"}:{valid:!1,error:"Password must contain at least one number"}:{valid:!1,error:"Password must contain at least one lowercase letter"}:{valid:!1,error:"Password must contain at least one uppercase letter"}},e.prototype.validateSignupCredentials=function(e,t,n){return!e||e.length<1?{valid:!1,error:"Username must be more than 0 characters long"}:e.length>PP?{valid:!1,error:"Username must be ".concat(PP," characters or fewer")}:/^[a-zA-Z0-9._-]+$/.test(e)?n?n.pub&&n.priv&&n.epub&&n.epriv?{valid:!0}:{valid:!1,error:"Invalid pair provided"}:this.validatePasswordStrength(t):{valid:!1,error:"Username can only contain letters, numbers, dots, underscores, and hyphens"}},e.prototype.ensureAliasAvailable=function(e){return AP(this,arguments,void 0,function(e,t){return void 0===t&&(t=5e3),xP(this,function(n){switch(n.label){case 0:return[4,this.isAliasAvailable(e,t)];case 1:if(!n.sent())throw new Error('Alias "'.concat(e,'" is already registered in Holster'));return[2]}})})},e.prototype.isAliasAvailable=function(e){return AP(this,arguments,void 0,function(e,t){var n,r=this;return void 0===t&&(t=5e3),xP(this,function(o){if("string"!=typeof e||!e.trim())throw new Error("Alias must be a non-empty string");return n=e.trim().toLowerCase(),[2,new Promise(function(e,o){var i=!1,s=setTimeout(function(){i||(i=!0,e(!0))},t);r.holster.get("~@".concat(n)).next(null,null,function(t){i||(i=!0,clearTimeout(s),e(!t))})})]})})},e.prototype.isAliasTaken=function(e){return AP(this,void 0,void 0,function(){var t=this;return xP(this,function(n){return[2,new Promise(function(n,r){t.holster.get("~@".concat(e)).next(null,null,function(e){n(!!e)})})]})})},e.prototype.registerAlias=function(e,t){return AP(this,arguments,void 0,function(e,t,n){var r,o,i=this;return void 0===n&&(n=5e3),xP(this,function(s){switch(s.label){case 0:if(!e||!e.trim())throw new Error("Alias must be provided for registration");if(!t)throw new Error("userPub must be provided for alias registration");return r=e.trim().toLowerCase(),[4,this.isAliasAvailable(r,n).catch(function(e){throw console.error("[DB] Alias availability check failed:",e),e})];case 1:return o=s.sent(),[4,this.isAliasTaken(r)];case 2:if(s.sent())throw new Error('Alias "'.concat(r,'" is already taken'));if(!o)throw new Error('Alias "'.concat(r,'" is no longer available for registration'));return[4,new Promise(function(e,o){var s=!1,a=setTimeout(function(){s||(s=!0,o(new Error("Timeout while registering alias")))},n);i.usernamesNode.next(r,null,null).put(t,function(t){s||(s=!0,clearTimeout(a),t&&"string"==typeof t&&t.startsWith("error")?o(new Error(t)):e())})}).catch(function(e){throw console.error("[DB] Failed to register alias:",e),e})];case 3:return s.sent(),[2]}})})},e.prototype.resetAuthState=function(){try{var e=this.holster.user();e&&e.is&&e.leave(),this.user=null}catch(e){}},e.prototype.buildLoginResult=function(e,t){var n=this.holster.user().is;return{success:!0,userPub:t,username:e,sea:n?{pub:n.pub,priv:n.priv,epub:n.epub,epriv:n.epriv}:void 0}},e.prototype.saveCredentials=function(e){try{if("undefined"!=typeof sessionStorage){var t={username:e.alias,pair:e.pair,userPub:e.userPub,timestamp:Date.now(),expiresAt:Date.now()+6048e5};sessionStorage.setItem("gunSessionData",JSON.stringify(t))}}catch(e){console.error("[DB] Error saving credentials:",e)}},e.prototype.signUp=function(e,t,n){return AP(this,void 0,void 0,function(){var r,o,i,s,a=this;return xP(this,function(c){switch(c.label){case 0:if(!(r=this.validateSignupCredentials(e,t,n)).valid)return[2,{success:!1,error:r.error}];if(this.resetAuthState(),o=e.trim().toLowerCase(),i=this.holster.user(),n)return[2,{success:!1,error:"Pair-based signup not yet supported with Holster"}];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,this.ensureAliasAvailable(o)];case 2:return c.sent(),[3,4];case 3:return[2,{success:!1,error:(s=c.sent())instanceof Error?s.message:String(s)}];case 4:return[4,new Promise(function(e){var n=!1;i.create(o,t,function(r){if(!n)return r&&null!==r?(n=!0,a.resetAuthState(),void e({success:!1,error:r||"Signup failed"})):void i.auth(o,t,function(t){return AP(a,void 0,void 0,function(){var r,s,a,c,u;return xP(this,function(l){switch(l.label){case 0:if(n)return[2];if(n=!0,t&&null!==t)return this.resetAuthState(),e({success:!1,error:t||"Authentication after signup failed"}),[2];if(!(r=null===(c=null==i?void 0:i.is)||void 0===c?void 0:c.pub))return this.resetAuthState(),e({success:!1,error:"User not authenticated after signup"}),[2];this.user=i,s=(null===(u=null==i?void 0:i.is)||void 0===u?void 0:u.username)||o;try{this.saveCredentials({alias:s||o,pair:{pub:i.is.pub,priv:i.is.priv,epub:i.is.epub,epriv:i.is.epriv},userPub:r})}catch(e){}l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.registerAlias(s||o,r)];case 2:return l.sent(),[3,4];case 3:return a=l.sent(),console.error("[DB] Alias registration failed:",a),[3,4];case 4:return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:signup",{userPub:r,username:o,method:"password"}),e({success:!0,userPub:r,username:o,isNewUser:!0,sea:i.is?{pub:i.is.pub,priv:i.is.priv,epub:i.is.epub,epriv:i.is.epriv}:void 0}),[2]}})})})})})];case 5:return[2,c.sent()]}})})},e.prototype.login=function(e,t,n){return AP(this,void 0,void 0,function(){var r,o,i=this;return xP(this,function(s){return this.resetAuthState(),r=e.trim().toLowerCase(),o=this.holster.user(),[2,new Promise(function(e){n?e({success:!1,error:"Pair-based login not yet supported with Holster"}):o.auth(r,t,function(t){var n,s;if(t&&null!==t)return i.resetAuthState(),void e({success:!1,error:t});var a=null===(n=null==o?void 0:o.is)||void 0===n?void 0:n.pub;if(!a)return i.resetAuthState(),void e({success:!1,error:"No userPub available"});i.user=o;var c=(null===(s=null==o?void 0:o.is)||void 0===s?void 0:s.username)||r;try{i.saveCredentials({alias:c||r,pair:{pub:o.is.pub,priv:o.is.priv,epub:o.is.epub,epriv:o.is.epriv},userPub:a})}catch(e){}e(i.buildLoginResult(c||r,a))})})]})})},e.prototype.getCurrentUser=function(){try{var e=this.holster.user();return e&&e.is&&e.is.pub?{pub:e.is.pub,user:e}:null}catch(e){return null}},e.prototype.getUserPub=function(){var e;try{var t=this.holster.user();return(null===(e=null==t?void 0:t.is)||void 0===e?void 0:e.pub)||null}catch(e){return null}},e.prototype.loginWithPair=function(e,t){return AP(this,void 0,void 0,function(){var n,r,o=this;return xP(this,function(i){return t&&t.pub&&t.priv&&t.epub&&t.epriv?(this.resetAuthState(),n=e.trim().toLowerCase(),r=this.holster.user(),!n||n.length<1?[2,{success:!1,error:"Username must be more than 0 characters long"}]:n.length>PP?[2,{success:!1,error:"Username must be ".concat(PP," characters or fewer")}]:/^[a-zA-Z0-9._-]+$/.test(n)?this.sea?this.holster.wire?[2,new Promise(function(e){return AP(o,void 0,void 0,function(){var o,i,s,a,c=this;return xP(this,function(u){switch(u.label){case 0:o="~"+t.pub,i="~@"+n,u.label=1;case 1:return u.trys.push([1,5,,6]),[4,this.isAliasAvailable(n)];case 2:return u.sent()?[3,4]:[4,new Promise(function(e){c.usernamesNode.next(n,null,function(t){e(t||null)})})];case 3:return(s=u.sent())&&s!==t.pub?(e({success:!1,error:"Username exists but public key doesn't match"}),[2]):(this.holster.wire.get({"#":o,".":["username","pub","epub"]},function(s){if(!s.err&&s.put&&s.put[o]){r.is={username:n,pub:t.pub,epub:t.epub,priv:t.priv,epriv:t.epriv},c.user=r;try{c.saveCredentials({alias:n,pair:t,userPub:t.pub})}catch(e){}e(c.buildLoginResult(n,t.pub))}else c.createUserWithPair(n,t,o,i,e)},{wait:5e3}),[2]);case 4:return this.createUserWithPair(n,t,o,i,e),[3,6];case 5:return a=u.sent(),e({success:!1,error:"Error checking username: ".concat(a.message||a)}),[3,6];case 6:return[2]}})})})]:[2,{success:!1,error:"Holster wire not available"}]:[2,{success:!1,error:"SEA cryptography not available"}]:[2,{success:!1,error:"Username can only contain letters, numbers, dots, underscores, and hyphens"}]):[2,{success:!1,error:"Invalid pair structure - missing required keys"}]})})},e.prototype.createUserWithPair=function(e,t,n,r,o){return AP(this,void 0,void 0,function(){var i,s,a,c,u,l,f=this;return xP(this,function(h){switch(h.label){case 0:i=this.holster.user(),h.label=1;case 1:return h.trys.push([1,4,,5]),[4,this.ensureAliasAvailable(e)];case 2:return h.sent(),s=Date.now(),[4,this.sea.signTimestamp(s,t)];case 3:return a=h.sent(),c={username:e,pub:t.pub,epub:t.epub},u=this.createGraph(n,c,a,t.pub,s),this.holster.wire.put(u,function(s){var a;if(s)o({success:!1,error:"Error creating user: ".concat(s)});else{var c=((a={})[n]={"#":n},a),u=f.createGraph(r,c,null,null,null);f.holster.wire.put(u,function(n){return AP(f,void 0,void 0,function(){var r;return xP(this,function(s){switch(s.label){case 0:if(n)return o({success:!1,error:"Error creating username mapping: ".concat(n)}),[2];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.registerAlias(e,t.pub)];case 2:return s.sent(),[3,4];case 3:return r=s.sent(),console.error("[DB] Alias registration failed:",r),[3,4];case 4:i.is={username:e,pub:t.pub,epub:t.epub,priv:t.priv,epriv:t.epriv},this.user=i;try{this.saveCredentials({alias:e,pair:t,userPub:t.pub})}catch(e){}return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:signup",{userPub:t.pub,username:e,method:"pair"}),o(this.buildLoginResult(e,t.pub)),[2]}})})})}}),[3,5];case 4:return l=h.sent(),o({success:!1,error:"Error during user creation: ".concat(l.message||l)}),[3,5];case 5:return[2]}})})},e.prototype.createGraph=function(e,t,n,r,o){var i,s,a,c=((i={})[e]={_:{"#":e,">":{}}},i);try{for(var u=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.entries(t)),l=u.next();!l.done;l=u.next()){var f=kP(l.value,2),h=f[0],d=f[1];"_"!==h&&"_holster_user_public_key"!==h&&"_holster_user_signature"!==h&&(c[e][h]=d,c[e]._[">"][h]=o||Date.now())}}catch(e){s={error:e}}finally{try{l&&!l.done&&(a=u.return)&&a.call(u)}finally{if(s)throw s.error}}return n&&r&&o&&(c[e]._.s={},"string"==typeof n&&(c[e]._.s[o]=n),c[e]._holster_user_public_key=r,c[e]._[">"]._holster_user_public_key=o),c},e.prototype.loginWithPairLegacy=function(e,t){return AP(this,void 0,void 0,function(){return xP(this,function(n){return[2,this.loginWithPair(e,t)]})})},e.prototype.rx=function(){return this._rxjs},e.prototype.destroy=function(){if(!this._isDestroyed){if(console.log("[DB] Destroying DataBaseHolster instance..."),this._isDestroyed=!0,this.authPollInterval&&(clearInterval(this.authPollInterval),this.authPollInterval=null),this.onAuthCallbacks.length=0,this.eventEmitter.removeAllListeners(),this.user){try{this.user.leave()}catch(e){}this.user=null}this._rxjs=void 0,console.log("[DB] DataBaseHolster instance destroyed")}},e.prototype.aggressiveAuthCleanup=function(){console.log("🧹 Performing aggressive auth cleanup..."),this.resetAuthState(),this.logout(),console.log("✓ Aggressive auth cleanup completed")},e.prototype.on=function(e,t){this.eventEmitter.on(e,t)},e.prototype.off=function(e,t){this.eventEmitter.off(e,t)},e.prototype.once=function(e,t){this.eventEmitter.once(e,t)},e.prototype.emit=function(e,t){return this.eventEmitter.emit(e,t)},e.prototype._timeout=function(e){return AP(this,void 0,void 0,function(){return xP(this,function(t){return[2,new Promise(function(t){return setTimeout(t,e)})]})})},e.prototype.Off=function(e){void 0===e&&(e="default"),console.warn("Off not implemented in DataBaseHolster")},e.prototype.Listen=function(e,t,n){void 0===n&&(n=this.prefix),console.warn("Listen not implemented in DataBaseHolster")},e.prototype.On=function(e,t,n,r,o){void 0===n&&(n="default"),void 0===r&&(r=!0),void 0===o&&(o=this.prefix),console.warn("On not implemented in DataBaseHolster")},e.prototype.addContentAdressing=function(e,t){return Promise.reject(new Error("addContentAdressing not implemented in DataBaseHolster"))},e.prototype.userGet=function(e,t,n){return void 0===t&&(t=1),void 0===n&&(n=this.prefix),Promise.reject(new Error("userGet not implemented in DataBaseHolster"))},e.prototype.userLoad=function(e,t,n,r){return void 0===t&&(t=!1),void 0===n&&(n=1),void 0===r&&(r=this.prefix),Promise.reject(new Error("userLoad not implemented in DataBaseHolster"))},e.prototype.Get=function(e,t,n){return void 0===t&&(t=1),void 0===n&&(n=this.prefix),Promise.reject(new Error("Get not implemented in DataBaseHolster"))},e.prototype.userPut=function(e,t,n,r){return void 0===n&&(n=!1),void 0===r&&(r=this.prefix),Promise.reject(new Error("userPut not implemented in DataBaseHolster"))},e.prototype.Set=function(e,t,n,r,o){return void 0===n&&(n=!1),void 0===r&&(r=this.prefix),void 0===o&&(o=void 0),Promise.reject(new Error("Set not implemented in DataBaseHolster"))},e.prototype.Put=function(e,t,n,r,o){return void 0===n&&(n=!1),void 0===r&&(r=this.prefix),void 0===o&&(o=void 0),Promise.reject(new Error("Put not implemented in DataBaseHolster"))},e.prototype.purge=function(e){return Promise.reject(new Error("purge not implemented in DataBaseHolster"))},e.prototype.userDel=function(e,t){return void 0===t&&(t=!0),Promise.reject(new Error("userDel not implemented in DataBaseHolster"))},e.prototype.Del=function(e,t,n){return void 0===t&&(t=!0),void 0===n&&(n=""),Promise.reject(new Error("Del not implemented in DataBaseHolster"))},e.prototype.Load=function(e,t,n,r){return void 0===t&&(t=!1),void 0===n&&(n=1),void 0===r&&(r=this.prefix),Promise.reject(new Error("Load not implemented in DataBaseHolster"))},e.prototype.generatePublicCert=function(){return Promise.reject(new Error("generatePublicCert not implemented in DataBaseHolster"))},Object.defineProperty(e.prototype,"gun",{get:function(){return this.createGunProxy()},enumerable:!1,configurable:!0}),e.prototype.createGunProxy=function(){var e=this,t=function(e){return{get:function(n){var r=e.next(n);return t(r)},put:function(n,r){return e.put(n,r),t(e)},once:function(n){var r=!1,o=null,i=function(t){r||(r=!0,n(t),o?(o(),o=null):e.off&&e.off(i))};if(e.on){var s=e.on(i);"function"==typeof s&&(o=s)}return t(e)},on:function(t){return e.on(t),function(){return e.off(t)}},off:function(n){return e.off(n),t(e)},map:function(){return t(e)},then:function(n){var r=!1,o=function(e){r||(r=!0,n(e))};return e.on(o),setTimeout(function(){e.off(o)},0),t(e)}}};return{get:function(n){var r=e.holster.get(n);return t(r)},user:function(){return e.holster.user()},SEA:e.holster.SEA,on:function(t,n){"auth"===t&&e.onAuth(n)},off:function(t,n){if("auth"===t){var r=e.onAuthCallbacks.indexOf(n);r>-1&&e.onAuthCallbacks.splice(r,1)}}}},e}(),OP=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},NP=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},BP=function(){function e(e){this.core=e}return e.prototype.initialize=function(e){return OP(this,void 0,void 0,function(){var t=this;return NP(this,function(n){return"undefined"==typeof console&&(r.g.console={log:function(){},warn:function(){},error:function(){},info:function(){},debug:function(){}}),this.core.storage=new rP(e.silent),Ie.addListener(function(e){t.core.emit("error",{action:e.code,message:e.message,type:e.type})}),this.initializeGun(e),this.initializeGunUser(),this.setupGunEventForwarding(),this.setupWalletDerivation(),e.holsterInstance?this.core.rx=new EP(this.core.gun):this.core.rx=new cP(this.core.gun),this.registerBuiltinPlugins(e),this.initializeDb(),[2]})})},e.prototype.initializeGun=function(e){if(e.holsterInstance)return this.initializeHolster(e);try{if(!e.gunInstance)throw new Error("Either gunInstance or holsterInstance is required but neither was provided");if("object"!=typeof e.gunInstance)throw new Error("Gun instance must be an object, received: ".concat(typeof e.gunInstance));if("function"!=typeof e.gunInstance.user)throw new Error("Gun instance is invalid: gun.user is not a function. Received gun.user type: ".concat(typeof e.gunInstance.user));if("function"!=typeof e.gunInstance.get)throw new Error("Gun instance is invalid: gun.get is not a function. Received gun.get type: ".concat(typeof e.gunInstance.get));if("function"!=typeof e.gunInstance.on)throw new Error("Gun instance is invalid: gun.on is not a function. Received gun.on type: ".concat(typeof e.gunInstance.on));console.log("Using provided Gun instance:",e.gunInstance),this.core._gun=e.gunInstance}catch(e){throw"undefined"!=typeof console&&console.error&&console.error("Error validating Gun instance:",e),new Error("Failed to validate Gun instance: ".concat(e))}try{var t=this.resolveSEA(this.core._gun,!1);return this.core.db=new vP(this.core._gun,this.core,t),!0}catch(e){throw"undefined"!=typeof console&&console.error&&console.error("Error initializing DataBase:",e),new Error("Failed to initialize DataBase: ".concat(e))}},e.prototype.resolveSEA=function(e,t){var n=e.SEA||null;if(n)return n;var o=t?"Holster":"Gun",i=globalThis,s="undefined"!=typeof window?window:{},a=void 0!==r.g?r.g:{};return s[o]&&s[o].SEA?n=s[o].SEA:i[o]&&i[o].SEA?n=i[o].SEA:a[o]&&a[o].SEA?n=a[o].SEA:i.SEA?n=i.SEA:s.SEA&&(n=s.SEA),n},e.prototype.initializeHolster=function(e){try{if(!e.holsterInstance)throw new Error("Holster instance is required but was not provided");if("object"!=typeof e.holsterInstance)throw new Error("Holster instance must be an object, received: ".concat(typeof e.holsterInstance));if("function"!=typeof e.holsterInstance.user)throw new Error("Holster instance is invalid: holster.user is not a function. Received holster.user type: ".concat(typeof e.holsterInstance.user));if("function"!=typeof e.holsterInstance.get)throw new Error("Holster instance is invalid: holster.get is not a function. Received holster.get type: ".concat(typeof e.holsterInstance.get));console.log("Using provided Holster instance:",e.holsterInstance),this.core._gun=e.holsterInstance}catch(e){throw"undefined"!=typeof console&&console.error&&console.error("Error validating Holster instance:",e),new Error("Failed to validate Holster instance: ".concat(e))}try{var t=this.resolveSEA(this.core._gun,!0);return this.core.db=new CP(this.core._gun,this.core,t),!0}catch(e){throw"undefined"!=typeof console&&console.error&&console.error("Error initializing DataBaseHolster:",e),new Error("Failed to initialize DataBaseHolster: ".concat(e))}},e.prototype.isHolster=function(){return"function"==typeof this.core.gun.next||!(!this.core.db||"DataBaseHolster"!==this.core.db.constructor.name)},e.prototype.initializeGunUser=function(){var e=this;try{var t=this.core.gun.user();"function"==typeof t.recall?t.recall.length>0?this.core._user=t.recall({sessionStorage:!0}):(t.recall(),this.core._user=t.is?t:null):this.core._user=t}catch(e){throw"undefined"!=typeof console&&console.error&&console.error("Error initializing user:",e),new Error("Failed to initialize user: ".concat(e))}if(this.isHolster())"undefined"!=typeof console&&console.log&&console.log("[CoreInitializer] Using Holster - auth events handled via DataBaseHolster polling");else if("function"==typeof this.core.gun.on)try{this.core.gun.on("auth",function(t){var n,r=e.core.gun.user();"function"==typeof r.recall?r.recall.length>0?e.core._user=r.recall({sessionStorage:!0}):(r.recall(),e.core._user=r.is?r:null):e.core._user=r,e.core.emit("auth:login",{userPub:t.pub||(null===(n=t.is)||void 0===n?void 0:n.pub),method:"password"})})}catch(e){"undefined"!=typeof console&&console.warn&&console.warn("[CoreInitializer] Failed to register auth event listener:",e)}},e.prototype.setupGunEventForwarding=function(){var e=this;["gun:put","gun:get","gun:set","gun:remove"].forEach(function(t){e.core.db.on(t,function(n){e.core.emit(t,n)})}),["gun:peer:add","gun:peer:remove","gun:peer:connect","gun:peer:disconnect"].forEach(function(t){e.core.db.on(t,function(n){e.core.emit(t,n)})})},e.prototype.setupWalletDerivation=function(){var e=this;if(this.isHolster())this.core.db&&"function"==typeof this.core.db.onAuth&&this.core.db.onAuth(function(t){return OP(e,void 0,void 0,function(){var e,n,r,o,i;return NP(this,function(s){switch(s.label){case 0:return t.is?(e=null===(o=t.is)||void 0===o?void 0:o.epriv,n=null===(i=t.is)||void 0===i?void 0:i.epub,e&&n?(r=this.core,[4,qi(e,n,{includeSecp256k1Bitcoin:!0,includeSecp256k1Ethereum:!0})]):[3,2]):[2];case 1:r.wallets=s.sent(),s.label=2;case 2:return[2]}})})});else if("function"==typeof this.core.gun.on)try{this.core.gun.on("auth",function(t){return OP(e,void 0,void 0,function(){var e,n,r,o,i,s,a,c,u;return NP(this,function(l){switch(l.label){case 0:return t.is?(e=(null===(i=null===(o=t._)||void 0===o?void 0:o.sea)||void 0===i?void 0:i.epriv)||(null===(s=t.is)||void 0===s?void 0:s.epriv),n=(null===(c=null===(a=t._)||void 0===a?void 0:a.sea)||void 0===c?void 0:c.epub)||(null===(u=t.is)||void 0===u?void 0:u.epub),e&&n?(r=this.core,[4,qi(e,n,{includeSecp256k1Bitcoin:!0,includeSecp256k1Ethereum:!0})]):[3,2]):[2];case 1:r.wallets=l.sent(),l.label=2;case 2:return[2]}})})})}catch(e){"undefined"!=typeof console&&console.warn&&console.warn("[CoreInitializer] Failed to register wallet derivation listener:",e)}},e.prototype.registerBuiltinPlugins=function(e){try{if(e.webauthn){"undefined"!=typeof console&&console.warn&&console.warn("WebAuthn plugin will be registered with provided configuration");var t=new Ja;"function"==typeof t.configure&&t.configure(e.webauthn),this.core.pluginManager.register(t)}if(e.web3){"undefined"!=typeof console&&console.warn&&console.warn("Web3 plugin will be registered with provided configuration");var n=new dw;"function"==typeof n.configure&&n.configure(e.web3),this.core.pluginManager.register(n)}if(e.nostr){"undefined"!=typeof console&&console.warn&&console.warn("Nostr plugin will be registered with provided configuration");var r=new jI;"function"==typeof r.configure&&r.configure(e.nostr),this.core.pluginManager.register(r)}}catch(e){"undefined"!=typeof console&&console.error&&console.error("Error registering builtin plugins:",e)}},e.prototype.initializeDb=function(){try{return this.core.db.initialize(),this.core.emit("debug",{action:"core_initialized",timestamp:Date.now()}),!0}catch(e){return"undefined"!=typeof console&&console.error&&console.error("Error during Shogun Core initialization:",e),!1}},e}(),TP=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},RP=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},UP=function(){function e(e){this._user=null,this.config=e,this.eventManager=new eP,this.pluginManager=new qI(this),this.authManager=new ZI(this),this.coreInitializer=new BP(this),this.coreInitializer.initialize(e).catch(function(e){"undefined"!=typeof console&&console.warn&&console.warn("Error during async initialization:",e)})}return Object.defineProperty(e.prototype,"gun",{get:function(){return this._gun},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"user",{get:function(){return this._user},enumerable:!1,configurable:!0}),e.prototype.getCurrentUser=function(){return this.db?this.db.getCurrentUser():null},e.prototype.register=function(e){this.pluginManager.register(e)},e.prototype.unregister=function(e){this.pluginManager.unregister(e)},e.prototype.getPlugin=function(e){return this.pluginManager.getPlugin(e)},e.prototype.getPluginsInfo=function(){return this.pluginManager.getPluginsInfo()},e.prototype.getPluginCount=function(){return this.pluginManager.getPluginCount()},e.prototype.getPluginsInitializationStatus=function(){return this.pluginManager.getPluginsInitializationStatus()},e.prototype.validatePluginSystem=function(){return this.pluginManager.validatePluginSystem()},e.prototype.reinitializeFailedPlugins=function(){return this.pluginManager.reinitializeFailedPlugins()},e.prototype.checkPluginCompatibility=function(){return this.pluginManager.checkPluginCompatibility()},e.prototype.getPluginSystemDebugInfo=function(){return this.pluginManager.getPluginSystemDebugInfo()},e.prototype.hasPlugin=function(e){return this.pluginManager.hasPlugin(e)},e.prototype.getPluginsByCategory=function(e){return this.pluginManager.getPluginsByCategory(e)},e.prototype.getAuthenticationMethod=function(e){return this.authManager.getAuthenticationMethod(e)},e.prototype.getRecentErrors=function(e){return void 0===e&&(e=10),Ie.getRecentErrors(e)},e.prototype.isLoggedIn=function(){return this.authManager.isLoggedIn()},e.prototype.logout=function(){this.authManager.logout()},e.prototype.login=function(e,t,n){return TP(this,void 0,void 0,function(){return RP(this,function(r){return[2,this.authManager.login(e,t,n)]})})},e.prototype.loginWithPair=function(e,t){return TP(this,void 0,void 0,function(){return RP(this,function(n){return[2,this.authManager.loginWithPair(e,t)]})})},e.prototype.loginWithSeed=function(e,t){return TP(this,void 0,void 0,function(){return RP(this,function(n){return[2,this.authManager.loginWithSeed(e,t)]})})},e.prototype.signUp=function(e,t,n){return TP(this,void 0,void 0,function(){return RP(this,function(r){return[2,this.authManager.signUp(e,t,n)]})})},e.prototype.emit=function(e,t){return this.eventManager.emit(e,t)},e.prototype.on=function(e,t){return this.eventManager.on(e,t),this},e.prototype.once=function(e,t){return this.eventManager.once(e,t),this},e.prototype.off=function(e,t){return this.eventManager.off(e,t),this},e.prototype.removeAllListeners=function(e){return this.eventManager.removeAllListeners(e),this},e.prototype.setAuthMethod=function(e){this.authManager.setAuthMethod(e)},e.prototype.getAuthMethod=function(){return this.authManager.getAuthMethod()},e.prototype.saveCredentials=function(e){return TP(this,void 0,void 0,function(){return RP(this,function(t){try{this.storage.setItem("userCredentials",JSON.stringify(e))}catch(e){"undefined"!=typeof console&&console.warn&&console.warn("Failed to save credentials to storage"),"undefined"!=typeof console&&console.error&&console.error("Error saving credentials:",e)}return[2]})})},e.prototype.getIsLoggedIn=function(){return!(!this.user||!this.user.is)},e.API_VERSION="^6.2.1",e}();async function DP(e){const{gunInstance:t,appName:n,timeouts:r,webauthn:o,nostr:i,web3:s,challenge:a,showWebauthn:c,showNostr:u,showMetamask:l,showChallenge:f,darkMode:h,enableGunDebug:d=!0,enableConnectionMonitoring:p=!0,defaultPageSize:g=20,connectionTimeout:y=1e4,debounceInterval:m=100,crypto:w,...b}=e;let v=null,E=null;return E=t,v=new UP({gunInstance:E,webauthn:(null==o?void 0:o.enabled)?{enabled:!0,rpName:n||"Shogun App",rpId:"undefined"!=typeof window?window.location.hostname:"localhost"}:void 0,web3:(null==s?void 0:s.enabled)?{enabled:!0}:void 0,nostr:(null==i?void 0:i.enabled)?{enabled:!0}:void 0,challenge:(null==a?void 0:a.enabled)?{enabled:!0}:void 0,timeouts:r,silent:!1}),console.log("[DEBUG] ShogunConnector: ShogunCore initialized with gunInstance"),{core:v,options:e,setProvider:e=>{var t;if(!v)return!1;try{let n=null;if(e&&e.connection&&e.connection.url?n=e.connection.url:"string"==typeof e&&(n=e),n){const e=(null===(t=null==v?void 0:v.db)||void 0===t?void 0:t.gun)||(null==v?void 0:v.gun);if(e&&"function"==typeof e.opt)try{return e.opt({peers:[n]}),!0}catch(e){return console.error("Error adding peer via gun.opt:",e),!1}}return!1}catch(e){return console.error("Error setting provider:",e),!1}},getCurrentProviderUrl:()=>{var e;const t=(null===(e=null==v?void 0:v.db)||void 0===e?void 0:e.gun)||(null==v?void 0:v.gun);try{const e=t&&t.back?t.back("opt.peers"):void 0,n=e&&"object"==typeof e?Object.keys(e):[];return n.length>0?n[0]:null}catch{return null}},registerPlugin:e=>{if(v&&"function"==typeof v.register)try{return v.register(e),!0}catch(t){return console.error(`Error registering plugin: ${e.name}`,t),!1}return!1},hasPlugin:e=>!!v&&v.hasPlugin(e),gunPlugin:null}}return"undefined"!=typeof window&&(window.Shogun=function(e){return new UP(e)}),o})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ShogunButtonReact=e(require("react")):this.ShogunButtonReact=e(this.React);
2
+ var e;e=e=>(()=>{var t={526(e,t){t.byteLength=function(e){var t=a(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,i=a(e),s=i[0],c=i[1],u=new o(function(e,t,n){return 3*(t+n)/4-n}(0,s,c)),l=0,f=c>0?s-4:s;for(n=0;n<f;n+=4)t=r[e.charCodeAt(n)]<<18|r[e.charCodeAt(n+1)]<<12|r[e.charCodeAt(n+2)]<<6|r[e.charCodeAt(n+3)],u[l++]=t>>16&255,u[l++]=t>>8&255,u[l++]=255&t;return 2===c&&(t=r[e.charCodeAt(n)]<<2|r[e.charCodeAt(n+1)]>>4,u[l++]=255&t),1===c&&(t=r[e.charCodeAt(n)]<<10|r[e.charCodeAt(n+1)]<<4|r[e.charCodeAt(n+2)]>>2,u[l++]=t>>8&255,u[l++]=255&t),u},t.fromByteArray=function(e){for(var t,r=e.length,o=r%3,i=[],s=16383,a=0,c=r-o;a<c;a+=s)i.push(u(e,a,a+s>c?c:a+s));return 1===o?(t=e[r-1],i.push(n[t>>2]+n[t<<4&63]+"==")):2===o&&(t=(e[r-2]<<8)+e[r-1],i.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"=")),i.join("")};for(var n=[],r=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)n[s]=i[s],r[i.charCodeAt(s)]=s;function a(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function c(e){return n[e>>18&63]+n[e>>12&63]+n[e>>6&63]+n[63&e]}function u(e,t,n){for(var r,o=[],i=t;i<n;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(c(r));return o.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},287(e,t,n){const r=n(526),o=n(251),i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.hp=c,t.IS=50;const s=2147483647;function a(e){if(e>s)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,c.prototype),t}function c(e,t,n){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return u(e,t,n)}function u(e,t,n){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!c.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const n=0|g(e,t);let r=a(n);const o=r.write(e,t);return o!==n&&(r=r.slice(0,o)),r}(e,t);if(ArrayBuffer.isView(e))return function(e){if(J(e,Uint8Array)){const t=new Uint8Array(e);return d(t.buffer,t.byteOffset,t.byteLength)}return h(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(J(e,ArrayBuffer)||e&&J(e.buffer,ArrayBuffer))return d(e,t,n);if("undefined"!=typeof SharedArrayBuffer&&(J(e,SharedArrayBuffer)||e&&J(e.buffer,SharedArrayBuffer)))return d(e,t,n);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const r=e.valueOf&&e.valueOf();if(null!=r&&r!==e)return c.from(r,t,n);const o=function(e){if(c.isBuffer(e)){const t=0|p(e.length),n=a(t);return 0===n.length||e.copy(n,0,0,t),n}return void 0!==e.length?"number"!=typeof e.length||Q(e.length)?a(0):h(e):"Buffer"===e.type&&Array.isArray(e.data)?h(e.data):void 0}(e);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return c.from(e[Symbol.toPrimitive]("string"),t,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return l(e),a(e<0?0:0|p(e))}function h(e){const t=e.length<0?0:0|p(e.length),n=a(t);for(let r=0;r<t;r+=1)n[r]=255&e[r];return n}function d(e,t,n){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(n||0))throw new RangeError('"length" is outside of buffer bounds');let r;return r=void 0===t&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,t):new Uint8Array(e,t,n),Object.setPrototypeOf(r,c.prototype),r}function p(e){if(e>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|e}function g(e,t){if(c.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||J(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const n=e.length,r=arguments.length>2&&!0===arguments[2];if(!r&&0===n)return 0;let o=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return W(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return $(e).length;default:if(o)return r?-1:W(e).length;t=(""+t).toLowerCase(),o=!0}}function y(e,t,n){let r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return N(this,t,n);case"utf8":case"utf-8":return I(this,t,n);case"ascii":return O(this,t,n);case"latin1":case"binary":return T(this,t,n);case"base64":return S(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function m(e,t,n){const r=e[t];e[t]=e[n],e[n]=r}function w(e,t,n,r,o){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),Q(n=+n)&&(n=o?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof t&&(t=c.from(t,r)),c.isBuffer(t))return 0===t.length?-1:b(e,t,n,r,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):b(e,[t],n,r,o);throw new TypeError("val must be string, number or Buffer")}function b(e,t,n,r,o){let i,s=1,a=e.length,c=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,n/=2}function u(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){let r=-1;for(i=n;i<a;i++)if(u(e,i)===u(t,-1===r?0:i-r)){if(-1===r&&(r=i),i-r+1===c)return r*s}else-1!==r&&(i-=i-r),r=-1}else for(n+c>a&&(n=a-c),i=n;i>=0;i--){let n=!0;for(let r=0;r<c;r++)if(u(e,i+r)!==u(t,r)){n=!1;break}if(n)return i}return-1}function v(e,t,n,r){n=Number(n)||0;const o=e.length-n;r?(r=Number(r))>o&&(r=o):r=o;const i=t.length;let s;for(r>i/2&&(r=i/2),s=0;s<r;++s){const r=parseInt(t.substr(2*s,2),16);if(Q(r))return s;e[n+s]=r}return s}function E(e,t,n,r){return q(W(t,e.length-n),e,n,r)}function A(e,t,n,r){return q(function(e){const t=[];for(let n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function x(e,t,n,r){return q($(t),e,n,r)}function k(e,t,n,r){return q(function(e,t){let n,r,o;const i=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)n=e.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}(t,e.length-n),e,n,r)}function S(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function I(e,t,n){n=Math.min(e.length,n);const r=[];let o=t;for(;o<n;){const t=e[o];let i=null,s=t>239?4:t>223?3:t>191?2:1;if(o+s<=n){let n,r,a,c;switch(s){case 1:t<128&&(i=t);break;case 2:n=e[o+1],128==(192&n)&&(c=(31&t)<<6|63&n,c>127&&(i=c));break;case 3:n=e[o+1],r=e[o+2],128==(192&n)&&128==(192&r)&&(c=(15&t)<<12|(63&n)<<6|63&r,c>2047&&(c<55296||c>57343)&&(i=c));break;case 4:n=e[o+1],r=e[o+2],a=e[o+3],128==(192&n)&&128==(192&r)&&128==(192&a)&&(c=(15&t)<<18|(63&n)<<12|(63&r)<<6|63&a,c>65535&&c<1114112&&(i=c))}}null===i?(i=65533,s=1):i>65535&&(i-=65536,r.push(i>>>10&1023|55296),i=56320|1023&i),r.push(i),o+=s}return function(e){const t=e.length;if(t<=C)return String.fromCharCode.apply(String,e);let n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=C));return n}(r)}c.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){return!1}}(),c.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||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."),Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}}),c.poolSize=8192,c.from=function(e,t,n){return u(e,t,n)},Object.setPrototypeOf(c.prototype,Uint8Array.prototype),Object.setPrototypeOf(c,Uint8Array),c.alloc=function(e,t,n){return function(e,t,n){return l(e),e<=0?a(e):void 0!==t?"string"==typeof n?a(e).fill(t,n):a(e).fill(t):a(e)}(e,t,n)},c.allocUnsafe=function(e){return f(e)},c.allocUnsafeSlow=function(e){return f(e)},c.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==c.prototype},c.compare=function(e,t){if(J(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),J(t,Uint8Array)&&(t=c.from(t,t.offset,t.byteLength)),!c.isBuffer(e)||!c.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,r=t.length;for(let o=0,i=Math.min(n,r);o<i;++o)if(e[o]!==t[o]){n=e[o],r=t[o];break}return n<r?-1:r<n?1:0},c.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return c.alloc(0);let n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;const r=c.allocUnsafe(t);let o=0;for(n=0;n<e.length;++n){let t=e[n];if(J(t,Uint8Array))o+t.length>r.length?(c.isBuffer(t)||(t=c.from(t)),t.copy(r,o)):Uint8Array.prototype.set.call(r,t,o);else{if(!c.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(r,o)}o+=t.length}return r},c.byteLength=g,c.prototype._isBuffer=!0,c.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)m(this,t,t+1);return this},c.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)m(this,t,t+3),m(this,t+1,t+2);return this},c.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)m(this,t,t+7),m(this,t+1,t+6),m(this,t+2,t+5),m(this,t+3,t+4);return this},c.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?I(this,0,e):y.apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){let e="";const n=t.IS;return e=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(e+=" ... "),"<Buffer "+e+">"},i&&(c.prototype[i]=c.prototype.inspect),c.prototype.compare=function(e,t,n,r,o){if(J(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),t<0||n>e.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&t>=n)return 0;if(r>=o)return-1;if(t>=n)return 1;if(this===e)return 0;let i=(o>>>=0)-(r>>>=0),s=(n>>>=0)-(t>>>=0);const a=Math.min(i,s),u=this.slice(r,o),l=e.slice(t,n);for(let e=0;e<a;++e)if(u[e]!==l[e]){i=u[e],s=l[e];break}return i<s?-1:s<i?1:0},c.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},c.prototype.indexOf=function(e,t,n){return w(this,e,t,n,!0)},c.prototype.lastIndexOf=function(e,t,n){return w(this,e,t,n,!1)},c.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(n)?(n>>>=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}const o=this.length-t;if((void 0===n||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");let i=!1;for(;;)switch(r){case"hex":return v(this,e,t,n);case"utf8":case"utf-8":return E(this,e,t,n);case"ascii":case"latin1":case"binary":return A(this,e,t,n);case"base64":return x(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,e,t,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const C=4096;function O(e,t,n){let r="";n=Math.min(e.length,n);for(let o=t;o<n;++o)r+=String.fromCharCode(127&e[o]);return r}function T(e,t,n){let r="";n=Math.min(e.length,n);for(let o=t;o<n;++o)r+=String.fromCharCode(e[o]);return r}function N(e,t,n){const r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);let o="";for(let r=t;r<n;++r)o+=Z[e[r]];return o}function P(e,t,n){const r=e.slice(t,n);let o="";for(let e=0;e<r.length-1;e+=2)o+=String.fromCharCode(r[e]+256*r[e+1]);return o}function B(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function R(e,t,n,r,o,i){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function U(e,t,n,r,o){H(t,r,o,e,n,7);let i=Number(t&BigInt(4294967295));e[n++]=i,i>>=8,e[n++]=i,i>>=8,e[n++]=i,i>>=8,e[n++]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[n++]=s,s>>=8,e[n++]=s,s>>=8,e[n++]=s,s>>=8,e[n++]=s,n}function D(e,t,n,r,o){H(t,r,o,e,n,7);let i=Number(t&BigInt(4294967295));e[n+7]=i,i>>=8,e[n+6]=i,i>>=8,e[n+5]=i,i>>=8,e[n+4]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[n+3]=s,s>>=8,e[n+2]=s,s>>=8,e[n+1]=s,s>>=8,e[n]=s,n+8}function L(e,t,n,r,o,i){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function F(e,t,n,r,i){return t=+t,n>>>=0,i||L(e,0,n,4),o.write(e,t,n,r,23,4),n+4}function _(e,t,n,r,i){return t=+t,n>>>=0,i||L(e,0,n,8),o.write(e,t,n,r,52,8),n+8}c.prototype.slice=function(e,t){const n=this.length;(e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e);const r=this.subarray(e,t);return Object.setPrototypeOf(r,c.prototype),r},c.prototype.readUintLE=c.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||B(e,t,this.length);let r=this[e],o=1,i=0;for(;++i<t&&(o*=256);)r+=this[e+i]*o;return r},c.prototype.readUintBE=c.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||B(e,t,this.length);let r=this[e+--t],o=1;for(;t>0&&(o*=256);)r+=this[e+--t]*o;return r},c.prototype.readUint8=c.prototype.readUInt8=function(e,t){return e>>>=0,t||B(e,1,this.length),this[e]},c.prototype.readUint16LE=c.prototype.readUInt16LE=function(e,t){return e>>>=0,t||B(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUint16BE=c.prototype.readUInt16BE=function(e,t){return e>>>=0,t||B(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUint32LE=c.prototype.readUInt32LE=function(e,t){return e>>>=0,t||B(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUint32BE=c.prototype.readUInt32BE=function(e,t){return e>>>=0,t||B(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readBigUInt64LE=Y(function(e){z(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||V(e,this.length-8);const r=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,o=this[++e]+256*this[++e]+65536*this[++e]+n*2**24;return BigInt(r)+(BigInt(o)<<BigInt(32))}),c.prototype.readBigUInt64BE=Y(function(e){z(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||V(e,this.length-8);const r=t*2**24+65536*this[++e]+256*this[++e]+this[++e],o=this[++e]*2**24+65536*this[++e]+256*this[++e]+n;return(BigInt(r)<<BigInt(32))+BigInt(o)}),c.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||B(e,t,this.length);let r=this[e],o=1,i=0;for(;++i<t&&(o*=256);)r+=this[e+i]*o;return o*=128,r>=o&&(r-=Math.pow(2,8*t)),r},c.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||B(e,t,this.length);let r=t,o=1,i=this[e+--r];for(;r>0&&(o*=256);)i+=this[e+--r]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i},c.prototype.readInt8=function(e,t){return e>>>=0,t||B(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){e>>>=0,t||B(e,2,this.length);const n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt16BE=function(e,t){e>>>=0,t||B(e,2,this.length);const n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt32LE=function(e,t){return e>>>=0,t||B(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return e>>>=0,t||B(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readBigInt64LE=Y(function(e){z(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||V(e,this.length-8);const r=this[e+4]+256*this[e+5]+65536*this[e+6]+(n<<24);return(BigInt(r)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)}),c.prototype.readBigInt64BE=Y(function(e){z(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||V(e,this.length-8);const r=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(r)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+n)}),c.prototype.readFloatLE=function(e,t){return e>>>=0,t||B(e,4,this.length),o.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return e>>>=0,t||B(e,4,this.length),o.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return e>>>=0,t||B(e,8,this.length),o.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return e>>>=0,t||B(e,8,this.length),o.read(this,e,!1,52,8)},c.prototype.writeUintLE=c.prototype.writeUIntLE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||R(this,e,t,n,Math.pow(2,8*n)-1,0);let o=1,i=0;for(this[t]=255&e;++i<n&&(o*=256);)this[t+i]=e/o&255;return t+n},c.prototype.writeUintBE=c.prototype.writeUIntBE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||R(this,e,t,n,Math.pow(2,8*n)-1,0);let o=n-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+n},c.prototype.writeUint8=c.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,1,255,0),this[t]=255&e,t+1},c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigUInt64LE=Y(function(e,t=0){return U(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeBigUInt64BE=Y(function(e,t=0){return D(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),c.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t>>>=0,!r){const r=Math.pow(2,8*n-1);R(this,e,t,n,r-1,-r)}let o=0,i=1,s=0;for(this[t]=255&e;++o<n&&(i*=256);)e<0&&0===s&&0!==this[t+o-1]&&(s=1),this[t+o]=(e/i|0)-s&255;return t+n},c.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t>>>=0,!r){const r=Math.pow(2,8*n-1);R(this,e,t,n,r-1,-r)}let o=n-1,i=1,s=0;for(this[t+o]=255&e;--o>=0&&(i*=256);)e<0&&0===s&&0!==this[t+o+1]&&(s=1),this[t+o]=(e/i|0)-s&255;return t+n},c.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},c.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||R(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeBigInt64LE=Y(function(e,t=0){return U(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeBigInt64BE=Y(function(e,t=0){return D(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),c.prototype.writeFloatLE=function(e,t,n){return F(this,e,t,!0,n)},c.prototype.writeFloatBE=function(e,t,n){return F(this,e,t,!1,n)},c.prototype.writeDoubleLE=function(e,t,n){return _(this,e,t,!0,n)},c.prototype.writeDoubleBE=function(e,t,n){return _(this,e,t,!1,n)},c.prototype.copy=function(e,t,n,r){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);const o=r-n;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,n,r):Uint8Array.prototype.set.call(e,this.subarray(n,r),t),o},c.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!c.isEncoding(r))throw new TypeError("Unknown encoding: "+r);if(1===e.length){const t=e.charCodeAt(0);("utf8"===r&&t<128||"latin1"===r)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;let o;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(o=t;o<n;++o)this[o]=e;else{const i=c.isBuffer(e)?e:c.from(e,r),s=i.length;if(0===s)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-t;++o)this[o+t]=i[o%s]}return this};const M={};function G(e,t,n){M[e]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function j(e){let t="",n=e.length;const r="-"===e[0]?1:0;for(;n>=r+4;n-=3)t=`_${e.slice(n-3,n)}${t}`;return`${e.slice(0,n)}${t}`}function H(e,t,n,r,o,i){if(e>n||e<t){const r="bigint"==typeof t?"n":"";let o;throw o=i>3?0===t||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(i+1)}${r}`:`>= -(2${r} ** ${8*(i+1)-1}${r}) and < 2 ** ${8*(i+1)-1}${r}`:`>= ${t}${r} and <= ${n}${r}`,new M.ERR_OUT_OF_RANGE("value",o,e)}!function(e,t,n){z(t,"offset"),void 0!==e[t]&&void 0!==e[t+n]||V(t,e.length-(n+1))}(r,o,i)}function z(e,t){if("number"!=typeof e)throw new M.ERR_INVALID_ARG_TYPE(t,"number",e)}function V(e,t,n){if(Math.floor(e)!==e)throw z(e,n),new M.ERR_OUT_OF_RANGE(n||"offset","an integer",e);if(t<0)throw new M.ERR_BUFFER_OUT_OF_BOUNDS;throw new M.ERR_OUT_OF_RANGE(n||"offset",`>= ${n?1:0} and <= ${t}`,e)}G("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),G("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),G("ERR_OUT_OF_RANGE",function(e,t,n){let r=`The value of "${e}" is out of range.`,o=n;return Number.isInteger(n)&&Math.abs(n)>2**32?o=j(String(n)):"bigint"==typeof n&&(o=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(o=j(o)),o+="n"),r+=` It must be ${t}. Received ${o}`,r},RangeError);const K=/[^+/0-9A-Za-z-_]/g;function W(e,t){let n;t=t||1/0;const r=e.length;let o=null;const i=[];for(let s=0;s<r;++s){if(n=e.charCodeAt(s),n>55295&&n<57344){if(!o){if(n>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(t-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((t-=1)<0)break;i.push(n)}else if(n<2048){if((t-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function $(e){return r.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(K,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function q(e,t,n,r){let o;for(o=0;o<r&&!(o+n>=t.length||o>=e.length);++o)t[o+n]=e[o];return o}function J(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Q(e){return e!=e}const Z=function(){const e="0123456789abcdef",t=new Array(256);for(let n=0;n<16;++n){const r=16*n;for(let o=0;o<16;++o)t[r+o]=e[n]+e[o]}return t}();function Y(e){return"undefined"==typeof BigInt?X:e}function X(){throw new Error("BigInt not supported")}},208(e,t,n){n.d(t,{A:()=>a});var r=n(601),o=n.n(r),i=n(314),s=n.n(i)()(o());s.push([e.id,'/* Base styles */\n:root {\n --shogun-primary: #3b82f6;\n --shogun-primary-hover: #2563eb;\n --shogun-secondary: #6b7280;\n --shogun-success: #10b981;\n --shogun-danger: #ef4444;\n --shogun-warning: #f59e0b;\n --shogun-text: #1f2937;\n --shogun-text-secondary: #6b7280;\n --shogun-bg: #ffffff;\n --shogun-bg-secondary: #f3f4f6;\n --shogun-border: #e5e7eb;\n --shogun-border-radius: 12px;\n --shogun-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);\n --shogun-transition: all 0.2s ease;\n --shogun-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;\n}\n\n/* Dark mode support */\n@media (prefers-color-scheme: dark) {\n :root {\n --shogun-text: #f3f4f6;\n --shogun-text-secondary: #9ca3af;\n --shogun-bg: #1f2937;\n --shogun-bg-secondary: #374151;\n --shogun-border: #4b5563;\n }\n}\n\n/* Connect Button */\n.shogun-connect-button {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n background-color: var(--shogun-primary);\n color: white;\n border: none;\n border-radius: var(--shogun-border-radius);\n padding: 10px 16px;\n font-family: var(--shogun-font);\n font-weight: 600;\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n box-shadow: var(--shogun-shadow);\n}\n\n.shogun-connect-button:hover {\n background-color: var(--shogun-primary-hover);\n}\n\n.shogun-connect-button:focus {\n outline: none;\n box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);\n}\n\n/* Logged in state */\n.shogun-logged-in-container {\n position: relative;\n}\n\n.shogun-dropdown {\n position: relative;\n}\n\n.shogun-button.shogun-logged-in {\n display: flex;\n align-items: center;\n gap: 8px;\n background-color: var(--shogun-bg-secondary);\n color: var(--shogun-text);\n border: 1px solid var(--shogun-border);\n border-radius: var(--shogun-border-radius);\n padding: 8px 12px;\n font-family: var(--shogun-font);\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n}\n\n.shogun-button.shogun-logged-in:hover {\n background-color: var(--shogun-bg);\n}\n\n.shogun-avatar {\n width: 24px;\n height: 24px;\n background-color: var(--shogun-primary);\n color: white;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n font-weight: 600;\n font-size: 12px;\n}\n\n.shogun-username {\n font-weight: 500;\n}\n\n.shogun-dropdown-menu {\n position: absolute;\n top: calc(100% + 8px);\n right: 0;\n background-color: var(--shogun-bg);\n border: 1px solid var(--shogun-border);\n border-radius: var(--shogun-border-radius);\n box-shadow: var(--shogun-shadow);\n width: 240px;\n z-index: 9999;\n overflow: hidden;\n animation: shogun-dropdown-fade 0.2s ease;\n}\n\n@keyframes shogun-dropdown-fade {\n from {\n opacity: 0;\n transform: translateY(-8px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n.shogun-dropdown-header {\n padding: 16px;\n border-bottom: 1px solid var(--shogun-border);\n display: flex;\n align-items: center;\n gap: 12px;\n}\n\n.shogun-avatar-large {\n width: 40px;\n height: 40px;\n background-color: var(--shogun-primary);\n color: white;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n font-weight: 600;\n font-size: 16px;\n}\n\n.shogun-user-info {\n display: flex;\n flex-direction: column;\n}\n\n.shogun-username-full {\n font-weight: 600;\n color: var(--shogun-text);\n font-size: 14px;\n}\n\n.shogun-dropdown-item {\n padding: 12px 16px;\n display: flex;\n align-items: center;\n gap: 12px;\n color: var(--shogun-text);\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n}\n\n.shogun-dropdown-item:hover {\n background-color: var(--shogun-bg-secondary);\n}\n\n/* Modal */\n.shogun-modal-overlay {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: rgba(0, 0, 0, 0.5);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 1000;\n animation: shogun-fade-in 0.2s ease;\n}\n\n@keyframes shogun-fade-in {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n\n.shogun-modal {\n background-color: var(--shogun-bg);\n border-radius: var(--shogun-border-radius);\n box-shadow: var(--shogun-shadow);\n width: 90%;\n max-width: 400px;\n max-height: 90vh;\n overflow-y: auto;\n animation: shogun-scale-in 0.2s ease;\n}\n\n@keyframes shogun-scale-in {\n from {\n opacity: 0;\n transform: scale(0.95);\n }\n to {\n opacity: 1;\n transform: scale(1);\n }\n}\n\n.shogun-modal-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding: 16px 20px;\n border-bottom: 1px solid var(--shogun-border);\n}\n\n.shogun-modal-header h2 {\n margin: 0;\n font-size: 1.5rem;\n font-weight: 600;\n color: var(--shogun-text);\n text-align: center;\n width: 100%;\n}\n\n.shogun-close-button {\n background: none;\n border: none;\n cursor: pointer;\n color: var(--shogun-text-secondary);\n padding: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 50%;\n transition: var(--shogun-transition);\n}\n\n.shogun-close-button:hover {\n background-color: var(--shogun-bg-secondary);\n color: var(--shogun-text);\n}\n\n.shogun-modal-content {\n padding: 20px;\n}\n\n/* Auth options */\n.shogun-auth-options {\n display: flex;\n flex-direction: column;\n gap: 12px;\n margin-bottom: 24px;\n}\n\n.shogun-auth-option-button {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 12px;\n background-color: var(--shogun-bg);\n color: var(--shogun-text);\n border: 1px solid var(--shogun-border);\n border-radius: var(--shogun-border-radius);\n padding: 12px 16px;\n font-family: var(--shogun-font);\n font-weight: 500;\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n width: 100%;\n}\n\n.shogun-auth-option-button:hover {\n background-color: var(--shogun-bg-secondary);\n}\n\n.shogun-auth-option-button:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n}\n\n.shogun-google-button {\n border-color: #4285F4;\n}\n\n/* Divider */\n.shogun-divider {\n display: flex;\n align-items: center;\n margin: 20px 0;\n color: var(--shogun-text-secondary);\n font-size: 14px;\n}\n\n.shogun-divider::before,\n.shogun-divider::after {\n content: "";\n flex: 1;\n border-bottom: 1px solid var(--shogun-border);\n}\n\n.shogun-divider span {\n padding: 0 10px;\n}\n\n/* Form */\n.shogun-auth-form {\n display: flex;\n flex-direction: column;\n gap: 16px;\n}\n\n.shogun-form-group {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.shogun-form-group label {\n display: flex;\n align-items: center;\n gap: 8px;\n font-size: 14px;\n font-weight: 500;\n color: var(--shogun-text);\n}\n\n.shogun-form-group input {\n padding: 12px;\n border: 1px solid var(--shogun-border);\n border-radius: var(--shogun-border-radius);\n background-color: var(--shogun-bg);\n color: var(--shogun-text);\n font-size: 14px;\n transition: var(--shogun-transition);\n}\n\n.shogun-form-group input:focus {\n outline: none;\n border-color: var(--shogun-primary);\n box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);\n}\n\n.shogun-submit-button {\n background-color: var(--shogun-primary);\n color: white;\n border: none;\n border-radius: var(--shogun-border-radius);\n padding: 12px 16px;\n font-family: var(--shogun-font);\n font-weight: 600;\n font-size: 14px;\n cursor: pointer;\n transition: var(--shogun-transition);\n margin-top: 8px;\n}\n\n.shogun-submit-button:hover:not(:disabled) {\n background-color: var(--shogun-primary-hover);\n}\n\n.shogun-submit-button:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n}\n\n/* Footer */\n.shogun-form-footer {\n margin-top: 20px;\n text-align: center;\n font-size: 14px;\n color: var(--shogun-text-secondary);\n}\n\n.shogun-toggle-mode {\n background: none;\n border: none;\n color: var(--shogun-primary);\n font-weight: 600;\n cursor: pointer;\n padding: 0;\n margin-left: 4px;\n transition: var(--shogun-transition);\n}\n\n.shogun-toggle-mode:hover {\n text-decoration: underline;\n}\n\n.shogun-toggle-mode:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n}\n\n/* Error message */\n.shogun-error-message {\n background-color: rgba(239, 68, 68, 0.1);\n color: var(--shogun-danger);\n padding: 12px;\n border-radius: var(--shogun-border-radius);\n margin-bottom: 16px;\n font-size: 14px;\n border: 1px solid rgba(239, 68, 68, 0.2);\n}\n\n.shogun-back-button {\n background: none;\n border: none;\n color: var(--shogun-text-secondary);\n cursor: pointer;\n font-size: 14px;\n margin-bottom: 16px;\n padding: 4px;\n display: flex;\n align-items: center;\n gap: 4px;\n font-weight: 500;\n transition: color 0.2s ease;\n}\n\n.shogun-back-button:hover {\n color: var(--shogun-text);\n}\n\n.shogun-prominent-toggle {\n font-weight: 600;\n color: var(--shogun-primary);\n padding: 8px 16px;\n margin-top: 16px;\n border: none;\n border-radius: 6px;\n background-color: transparent;\n transition: all 0.2s ease;\n}\n\n.shogun-prominent-toggle:hover {\n text-decoration: underline;\n}\n\n/* Redundant dark theme styles removed */ \n\n/* Advanced Options Toggle */\n.shogun-advanced-toggle {\n margin: 8px 0;\n}\n\n.shogun-toggle-advanced {\n background: none;\n border: none;\n color: var(--shogun-text-secondary);\n font-size: 13px;\n cursor: pointer;\n padding: 6px 0;\n display: flex;\n align-items: center;\n gap: 4px;\n font-weight: 500;\n transition: color 0.2s ease;\n}\n\n.shogun-toggle-advanced:hover {\n color: var(--shogun-primary);\n}\n\n/* Advanced Options Container */\n.shogun-advanced-options {\n background-color: var(--shogun-bg-secondary);\n padding: 12px;\n border-radius: var(--shogun-border-radius);\n border: 1px dashed var(--shogun-border);\n}\n\n/* Field Hint */\n.shogun-field-hint {\n font-size: 12px;\n color: var(--shogun-text-secondary);\n margin-top: 4px;\n font-style: italic;\n}',""]);const a=s},314(e){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n="",r=void 0!==t[5];return t[4]&&(n+="@supports (".concat(t[4],") {")),t[2]&&(n+="@media ".concat(t[2]," {")),r&&(n+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),n+=e(t),r&&(n+="}"),t[2]&&(n+="}"),t[4]&&(n+="}"),n}).join("")},t.i=function(e,n,r,o,i){"string"==typeof e&&(e=[[null,e,void 0]]);var s={};if(r)for(var a=0;a<this.length;a++){var c=this[a][0];null!=c&&(s[c]=!0)}for(var u=0;u<e.length;u++){var l=[].concat(e[u]);r&&s[l[0]]||(void 0!==i&&(void 0===l[5]||(l[1]="@layer".concat(l[5].length>0?" ".concat(l[5]):""," {").concat(l[1],"}")),l[5]=i),n&&(l[2]?(l[1]="@media ".concat(l[2]," {").concat(l[1],"}"),l[2]=n):l[2]=n),o&&(l[4]?(l[1]="@supports (".concat(l[4],") {").concat(l[1],"}"),l[4]=o):l[4]="".concat(o)),t.push(l))}},t}},601(e){e.exports=function(e){return e[1]}},229(e,t,n){n(827)},827(e,t,n){e=n.nmd(e),function(){function t(e,r){return r?n(736)(e):e.slice?t[o(e)]:function(n,r){e(n={exports:{}}),t[o(r)]=n.exports};function o(e){return e.split("/").slice(-1).toString().replace(".js","")}}var r=e;t(function(e){String.random=function(e,t){var n="";for(e=e||24,t=t||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";e-- >0;)n+=t.charAt(Math.floor(Math.random()*t.length));return n},String.match=function(e,t){var n,r;return"string"==typeof e&&("string"==typeof t&&(t={"=":t}),e===(n=(t=t||{})["="]||t["*"]||t[">"]||t["<"])||r===t["="]&&(n=t["*"]||t[">"],e.slice(0,(n||"").length)===n||r===t["*"]&&(r!==t[">"]&&r!==t["<"]?e>=t[">"]&&e<=t["<"]:r!==t[">"]&&e>=t[">"]||r!==t["<"]&&e<=t["<"])))},String.hash=function(e,t){if("string"==typeof e){if(t=t||0,!e.length)return t;for(var n=0,r=e.length;n<r;++n)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t}};var t,n,r,o,i,s,a=Object.prototype.hasOwnProperty;Object.plain=function(e){return!!e&&(e instanceof Object&&e.constructor===Object||"Object"===Object.prototype.toString.call(e).match(/^\[object (\w+)\]$/)[1])},Object.empty=function(e,t){for(var n in e)if(a.call(e,n)&&(!t||-1==t.indexOf(n)))return!1;return!0},Object.keys=Object.keys||function(e){var t=[];for(var n in e)a.call(e,n)&&t.push(n);return t},n=setTimeout,r=0,o=0,i=typeof setImmediate!=""+t&&setImmediate||function(e,r){return typeof MessageChannel==""+t?n:((e=new MessageChannel).port1.onmessage=function(e){""==e.data&&r()},function(t){r=t,e.port2.postMessage("")})}(),s=n.check=n.check||typeof performance!=""+t&&performance||{now:function(){return+new Date}},n.hold=n.hold||9,n.poll=n.poll||function(e){n.hold>=s.now()-r&&o++<3333?e():i(function(){r=s.now(),e()},o=0)},function(){var e,t=setTimeout,n=t.turn=t.turn||function(e){1==r.push(e)&&o(s)},r=n.s=[],o=t.poll,i=0,s=function(){(e=r[i++])&&e(),i!=r.length&&99!=i||(r=n.s=r.slice(i),i=0),r.length&&o(s)}}(),function(){var e,t=setTimeout,n=t.turn;(t.each=t.each||function(t,r,o,i){i=i||9,function s(a,c,u){if(c=(a=(t||[]).splice(0,i)).length){for(var l=0;l<c&&e===(u=r(a[l]));l++);if(e===u)return void n(s)}o&&o(u)}()})()}()})(t,"./shim"),t(function(e){e.exports=function e(t,n,r){if(!t)return{to:e};var o="function"==typeof n;if(t=(this.tag||(this.tag={}))[t]||o&&(this.tag[t]={tag:t,to:e._={next:function(e){var t;(t=this.to)&&t.next(e)}}}),o){var i={off:e.off||(e.off=function(){if(this.next===e._.next)return!0;this===this.the.last&&(this.the.last=this.back),this.to.back=this.back,this.next=e._.next,this.back.to=this.to,this.the.last===this.the&&delete this.on.tag[this.the.tag]}),to:e._,next:n,the:t,on:this,as:r};return(i.back=t.last||t).to=i,t.last=i}return(t=t.to)&&void 0!==n&&t.next(n),t}})(t,"./onto"),t(function(e){var t=setTimeout,n=t.Book||(t.Book=function(e){var t=function(e,n){var r,o=t.all[e];return void 0===n?o&&o.is||t.get(o||e):o?((r=o.page)&&(r.size+=d(n)-d(o.is),r.text=""),o.text="",o.is=n,t):t.set(e,n)};return t.list=[{from:e,size:(e||"").length,substring:y,toString:m,book:t,get:t,read:u}],t.page=o,t.set=l,t.get=i,t.all={},t}),r=4096;function o(e){var t=this,n=t.list,r=a(e,n,t.parse),o=n[r];return"string"==typeof o&&(n[r]=o={size:-1,first:t.parse?t.parse(o):o,substring:y,toString:m,book:t,get:t,read:u}),o}function i(e){if(e){if(void 0!==e.is)return e.is;if(t=this.all[e])return t.is;var t,n=this.page(e);if(n&&n.from)return s(e,n)}}function s(e,t){var r,o,i,u,l=t.book;return(r=c(t))&&(o=r[s.i=u=a(e,r,n.decode)]),o&&e==o.word?(l.all[e]=o).is:("string"!=typeof o&&(o=r[s.i=u+=1]),o&&e==o.word?(l.all[e]=o).is:(i=f(o),e==n.decode(i[0])||(i=f(o=r[s.i=u+=1]),e==n.decode(i[0]))?(o=r[u]=l.all[e]={word:""+e,is:n.decode(i[1]),page:t,substring:p,toString:g}).is:void 0))}function a(e,t,n){n=n||a.no||(a.no=function(e){return e});for(var r,o=t,i=0,s=(e=""+e,o.length),c=s/2;(e<(r=(n(o[c|=0])||"").substring())||(n(o[c+1])||"").substring()<=e)&&c!=i;)c+=r<=e?(s-(i=c))/2:-((s=c)-i)/2;return c}function c(e,t,n){return"string"!=typeof e.from?e.from:e.from=f(t=t||e.from||"")}function u(e){e=e||function(e){return e};for(var t,n=0,r=w(this),o=[],i=this.book.parse||function(){};t=r[n++];)o.push(e(this.get(t=t.word||i(t)||t),t,this));return o}function l(e,t){var n=this,o=n.all[e];if(o)return n(e,t);var i=n.page(e=""+e);return i&&i.from&&(n.get(e),n.all[e])?n(e,t):(o=n.all[e]={word:e,is:t,page:i,substring:p,toString:g},i.first=i.first<e?i.first:e,i.limbo||(i.limbo=[]),i.limbo.push(o),n(e,t),i.size+=d(e)+d(t),(n.PAGE||r)<i.size&&function(e,t){for(var n,r=w(e),o=r.length/2|0,i=o,s={first:r[i].substring(),size:0,substring:y,toString:m,book:t,get:t,read:u},c=s.from=[];n=r[o++];)c.push(n),s.size+=(n.is||"").length||1,n.page=s;e.from=e.from.slice(0,i),e.size-=s.size,t.list.splice(a(s.first,t.list)+1,0,s),t.split&&t.split(s,e)}(i,n),n)}function f(e){return h((e=e||"").substring(1,e.length-1).split(e[0]),e[0])}function h(e,t){var n,r;return 0>(n=e.indexOf(""))?e:""==e[0]&&1==e.length||(r=n+2+parseInt((r=e[n+1]).substring(0,r.indexOf('"'))||r))!=r?[]:(e[n]=e.slice(n,r).join(t||"|"),e.slice(0,n+1).concat(h(e.slice(r),t)))}function d(e){return(e||"").length||1}function p(e,t){return this.word}function g(){return this.text=this.text||":"+n.encode(this.word)+":"+n.encode(this.is)+":"}function y(e,t){return(this.first||this.word||n.decode((c(this)||"")[0]||"")).substring(e,t)}function m(){return this.text=this.text||((e=this).limbo&&w(e),"string"==typeof e.from?e.from:"|"+(e.from||[]).join("|")+"|");var e}function w(e,t){var r=e.from="string"==typeof e.from?f(e.from):e.from||[];return(t=t||e.limbo)?function(e,t){t=t||e.limbo||[],e.limbo=null;for(var n,r=0,o=e.from;n=t[r++];)s(n.word,e)?o[s.i]=n:o.push(n);return o}(e).sort(function(e,t){return(e.word||n.decode(""+e))<(t.word||n.decode(""+t))?-1:1}):r}n.slot=f,n.encode=function(e,t,r){switch(t=t||"|",r=r||String.fromCharCode(32),typeof e){case"string":for(var o=e.indexOf(t),i=0;-1!=o;)i++,o=e.indexOf(t,o+1);return(i?t+i:"")+'"'+e;case"number":return e<0?""+e:"+"+e;case"boolean":return e?"+":"-";case"object":if(!e)return" ";for(var s,a=Object.keys(e).sort(),c=(o=0,t);s=a[o++];)c+=r+n.encode(s,t,r)+r+n.encode(e[s],t,r)+r+t;return c}},n.decode=function(e,t){if(t=t||"|","string"==typeof e){switch(e){case" ":return null;case"-":return!1;case"+":return!0}switch(e[0]){case"-":case"+":return parseFloat(e);case'"':return e.slice(1)}return e.slice(e.indexOf('"')+1)}},n.hash=function(e,t){if("string"==typeof e){if(t=t||0,!e.length)return t;for(var n=0,r=e.length;n<r;++n)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t}};try{e.exports=n}catch(e){}})(t,"./book"),t(function(e){e.exports=function(e){return null===e||"string"==typeof e||"boolean"==typeof e||"number"==typeof e&&e!=1/0&&e!=-1/0&&e==e||!!e&&"string"==typeof e["#"]&&1===Object.keys(e).length&&e["#"]}})(t,"./valid"),t(function(e){function n(){var e=+new Date;return a<e?(i=0,a=e+n.drift):a=e+(i+=1)/s+n.drift}t("./shim"),n.drift=0;var r,o=-1/0,i=0,s=999,a=o;n.is=function(e,t,n){var r=t&&e&&e._&&e._[">"]||n;if(r)return"number"==typeof(r=r[t])?r:o},n.ify=function(e,t,n,o,i){(e=e||{})._=e._||{},i&&(e._["#"]=i);var s=e._[">"]||(e._[">"]={});return r!==t&&"_"!==t&&("number"==typeof n&&(s[t]=n),r!==o&&(e[t]=o)),e},e.exports=n})(t,"./state"),t(function(e){t("./shim"),e.exports=function(e){var t={s:{}},n=t.s;e=e||{max:999,age:9e3},t.check=function(e){return!!n[e]&&r(e)};var r=t.track=function(o){var i=n[o]||(n[o]={});return i.was=t.now=+new Date,t.to||(t.to=setTimeout(t.drop,e.age+9)),r.ed&&r.ed(o),i};return t.drop=function(r){t.to=null,t.now=+new Date;var o=Object.keys(n);console.STAT&&console.STAT(t.now,+new Date-t.now,"dup drop keys"),setTimeout.each(o,function(o){var i=n[o];i&&(r||e.age)>t.now-i.was||delete n[o]},0,99)},t}})(t,"./dup"),t(function(e){t("./onto"),e.exports=function(e,t){if(this.on){var r=(this.opt||{}).lack||9e3;if("function"!=typeof e){if(!e)return;var o=e["#"]||e,i=(this.tag||"")[o];if(!i)return;return t&&(i=this.on(o,t),clearTimeout(i.err),i.err=setTimeout(function(){i.off()},r)),!0}if(o=t&&t["#"]||n(9),!e)return o;var s=this.on(o,e,t);return s.err=s.err||setTimeout(function(){s.off(),s.next({err:"Error: No ACK yet.",lack:!0})},r),o}};var n=String.random||function(){return Math.random().toString(36).slice(2)}})(t,"./ask"),t(function(e){function n(e){return e instanceof n?(this._={$:this}).$:this instanceof n?n.create(this._={$:this,opt:e}):new n(e)}n.is=function(e){return e instanceof n||e&&e._&&e===e._.$||!1},n.version=.202,n.chain=n.prototype,n.chain.toJSON=function(){},t("./shim"),n.valid=t("./valid"),n.state=t("./state"),n.on=t("./onto"),n.dup=t("./dup"),n.ask=t("./ask"),function(){function e(r){if(r)if(r.out!==e){var o,i=this.as,c=i.at||i,u=c.$,l=c.dup,f=r.DBG;if((o=r["#"])||(o=r["#"]=a(9)),!l.check(o)){if(l.track(o),o=r._,r._="function"==typeof o?o:function(){},r.$&&r.$===(r.$._||"").$||(r.$=u),r["@"]&&!r.put&&function(e){var t,n=e["@"]||"";if(t=n._)t.acks=(t.acks||0)+1,(t.err=e.err)&&(e["@"]=t["#"],s(t)),t.ok=e.ok||t.ok,t.stop||t.crack||(t.crack=t.match&&t.match.push(function(){d(t)})),d(t);else{var r=(r=e.$)&&(r=r._)&&(r=r.root)&&(r=r.dup);if(!(r=r.check(n)))return;e["@"]=r["#"]||e["@"]}}(r),!c.ask(r["@"],r)){if(f&&(f.u=+new Date),r.put)return void t(r);r.get&&n.on.get(r,u)}f&&(f.uc=+new Date),this.to.next(r),f&&(f.ua=+new Date),r.nts||r.NTS||(r.out=e,c.on("out",r),f&&(f.ue=+new Date))}}else this.to.next(r)}function t(t){if(t){var n=t._||"",i=n.root=((n.$=t.$||"")._||"").root;if(t["@"]&&n.faith&&!n.miss)return t.out=e,void i.on("out",t);n.latch=i.hatch,n.match=i.hatch=[];var a=t.put,l=n.DBG=t.DBG,f=+new Date;if(v=v||f,!a["#"]||!a["."]){l&&(l.p=f),n["#"]=t["#"],n.msg=t,n.all=0,n.stun=1;var h=Object.keys(a);console.STAT&&console.STAT(f,((l||n).pk=+new Date)-f,"put sort");var d,y,m,w,b,A,x,k=0;!function e(i){if(d!=k){if(d=k,!(m=h[k]))return console.STAT&&console.STAT(f,((l||n).pd=+new Date)-f,"put"),void s(n);(w=a[m])?(x=w._)?m!==x["#"]?A=p+g(m)+"soul not same.":(b=x[">"])||(A=p+g(m)+"no state."):A=p+g(m)+"no meta.":A=p+g(m)+"no node.",y=Object.keys(w||{})}if(A)return t.err=n.err=A,void s(n);var v,S=0;for(i=i||0;i++<9&&(v=y[S++]);)if("_"!==v){var I=w[v],C=b[v];if(o===C){A=p+g(v)+"on"+g(m)+"no state.";break}if(!u(I)){A=p+g(v)+"on"+g(m)+"bad "+typeof I+g(I);break}r(I,v,m,C,t),++E}(y=y.slice(S)).length?c(e):(++k,y=null,e(i))}()}}}function r(e,t,n,o,i){var a,c=i._||"",u=c.root,f=u.graph,v=f[n]||h,E=l(v,t,1),A=v[t],x=c.DBG;(a=console.STAT)&&(f[n]&&A||(a.has=(a.has||0)+1));var k=w();if(o>k)return(a=o-k)>b.max?(i.err=c.err=p+g(t)+"on"+g(n)+"state too far in future.",s(c),void d(c)):(setTimeout(function(){r(e,t,n,o,i)},a>m?m:a),void(console.STAT&&console.STAT((x||c).Hf=+new Date,a,"future")));if(!(o<E)&&(c.faith||o!==E||!(e===A||y(e)<=y(A))||c.miss)){c.stun++;var S=i["#"]+c.all++,I={toString:function(){return S},_:c};I.toJSON=I.toString,u.dup.track(I)["#"]=i["#"],x&&(x.ph=x.ph||+new Date),u.on("put",{"#":I,"@":i["@"],put:{"#":n,".":t,":":e,">":o},ok:i.ok,_:c})}}function i(e){var t;(t=(e._||"").DBG)&&(t.pa=+new Date,t.pm=t.pm||+new Date);var n,r=this.as,o=r.graph,i=e._,a=e.put,c=a["#"],u=a["."],l=a[":"],h=a[">"];e["#"],(n=i.msg)&&(n=n.put)&&(n=n[c])&&f(n,u,h,l,c),o[c]=f(o[c],u,h,l,c),(n=(r.next||"")[c])&&n.on("in",e),s(i),this.to.next(e)}function s(t,n){var r;if(!t.stop&&(!(0<--t.stun)||t.err)&&(t.stop=1,r=t.root)){var o=t.match;o.end=1,o===r.hatch&&(!(o=t.latch)||o.end?delete r.hatch:r.hatch=o),t.hatch&&t.hatch(),setTimeout.each(t.match,function(e){e&&e()}),!(n=t.msg)||t.err||n.err||(n.out=e,t.root.on("out",n),A())}}function d(e){e&&e.root&&(e.stun||(e.acks||0)!==e.all||e.root.on("in",{"@":e["#"],err:e.err,ok:e.err?o:e.ok||{"":1}}))}n.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||n.on,t.ask=t.ask||n.ask,t.dup=t.dup||n.dup();var r=t.$.opt(t.opt);return t.once||(t.on("in",e,t),t.on("out",e,t),t.on("put",i,t),n.on("create",t),t.on("create",t)),t.once=1,r},n.on.put=t;var p="Error: Invalid graph!",g=function(e){return" '"+(""+e).slice(0,9)+"...' "},y=JSON.stringify,m=2147483647,w=n.state,b=r;b.max=6048e5;var v,E=0,A=function(){E>999&&E/-(v-(v=+new Date))>1&&(n.window&&console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query."),A=function(){E=0})}}(),function(){function e(e,t){var n=+new Date,r=e._||{},i=r.DBG=e.DBG,s=e["#"],c=a(9),u=Object.keys(t||"").sort(),h=((t||"")._||"")["#"],d=(u.length,e.$._.root),p=t===d.graph[h];console.STAT&&console.STAT(n,((i||r).gk=+new Date)-n,"got keys"),t&&function e(){n=+new Date;for(var r,g,y,m=0,w={};m<9&&(r=u[m++]);)f(w,r,l(t,r),t[r],h);u=u.slice(m),(g={})[h]=w,w=g,p&&((y=function(){}).ram=y.faith=!0),g=u.length,console.STAT&&console.STAT(n,-(n-(n=+new Date)),"got copied some"),i&&(i.ga=+new Date),d.on("in",{"@":s,"#":c,put:w,"%":g?c=a(9):o,$:d.$,_:y,DBG:i}),console.STAT&&console.STAT(n,+new Date-n,"got in"),g&&setTimeout.turn(e)}(),t||d.on("in",{"@":e["#"]})}n.on.get=function(t,n){var r=n._,i=t.get,s=i["#"],a=r.graph[s],c=i["."],u=(r.next||(r.next={}))[s],h=(t._||{}).DBG=t.DBG;if(h&&(h.g=+new Date),!a)return r.on("get",t);if(c){if(("string"!=typeof c||o===a[c])&&!((u||"").next||"")[c])return void r.on("get",t);a=f({},c,l(a,c),a[c],s)}a&&e(t,a),r.on("get",t)},n.on.get.ack=e}(),n.chain.opt=function(e){e=e||{};var t=this._,r=e.peers||e;return Object.plain(e)||(e={}),Object.plain(t.opt)||(t.opt=e),"string"==typeof r&&(r=[r]),Object.plain(t.opt.peers)||(t.opt.peers={}),r instanceof Array&&(e.peers={},r.forEach(function(n){var r={};r.id=r.url=n,e.peers[n]=t.opt.peers[n]=t.opt.peers[n]||r})),s(e,function e(t){var n=this[t];this&&this.hasOwnProperty(t)||"string"==typeof n||Object.empty(n)?this[t]=n:(!n||n.constructor===Object||n instanceof Array)&&s(n,e)}),t.opt.from=e,n.on("opt",t),t.opt.uuid=t.opt.uuid||function(e){return n.state().toString(36).replace(".","")+String.random(e||12)},this};var o,i,s=function(e,t){Object.keys(e).forEach(t,e)},a=String.random,c=setTimeout.turn,u=n.valid,l=n.state.is,f=n.state.ify,h={};n.log=function(){return!n.log.off&&i.log.apply(i,arguments),[].slice.call(arguments).join(" ")},n.log.once=function(e,t,r){return(r=n.log.once)[e]=r[e]||0,r[e]++||n.log(t)},"undefined"!=typeof globalThis&&"undefined"==typeof window&&"undefined"!=typeof WorkerGlobalScope?(globalThis.GUN=globalThis.Gun=n).window=globalThis:"undefined"!=typeof window&&((window.GUN=window.Gun=n).window=window),(globalThis.GUN=globalThis.Gun=n).globalThis=globalThis;try{void 0!==r&&(r.exports=n)}catch(e){}e.exports=n,(n.window||{}).console=(n.window||{}).console||{log:function(){}},(i=console).only=function(e,t){return i.only.i&&e===i.only.i&&i.only.i++&&(i.log.apply(i,arguments)||t)}})(t,"./root"),t(function(e){t("./root").chain.back=function(e,t){if(-1===(e=e||1)||1/0===e)return this._.root.$;if(1===e)return(this._.back||this._).$;var o=this._;if("string"==typeof e&&(e=e.split(".")),e instanceof Array){for(var i=0,s=e.length,a=o;i<s;i++)a=(a||r)[e[i]];return n!==a?t?this:a:(a=o.back)?a.$.back(e,t):void 0}if("function"==typeof e){var c;for(a={back:o};(a=a.back)&&n===(c=e(a,t)););return c}return"number"==typeof e?(o.back||o).$.back(e-1):this};var n,r={}})(t,"./back"),t(function(e){var n=t("./root");function r(e,t){if(t=t||this.as||e.$._,(!e.$$||this===n.on)&&e.put&&!t.soul){var r=e.put||"",o=r["="]||r[":"],i=t.root,s=p(i,r["#"]).get(r["."])._;if("string"==typeof(o=u(o))){if(!(s.echo||(s.echo={}))[t.id]||(i.pass||"")[t.id]){if(a=i.pass){if(a[o+t.id])return;a[o+t.id]=1}(s.echo||(s.echo={}))[t.id]=t,t.has&&(t.link=o);var a,c=p(i,s.link=o)._;(c.echo||(c.echo={}))[s.id]=s,((a=t.ask||"")[""]||t.lex)&&c.on("out",{get:{"#":o}}),setTimeout.each(Object.keys(a),function(e,t){e&&(t=a[e])&&t.on("out",{get:{"#":o,".":e}})},0,99)}}else this===n.on&&((s.echo||(s.echo={}))[t.id]=t)}}function o(e,t){var n,r,i=e.put||"",a=s!==i["="]?i["="]:i[":"],c=t.root;if(s===a){if(t.soul&&s!==t.put)return;if(r=(e.$$||e.$||"")._||"",e["@"]&&(s!==r.put||s!==t.put))return;return(n=t.link||e.linked)&&delete(p(c,n)._.echo||"")[t.id],t.has&&(t.link=null),t.put=s,void setTimeout.each(Object.keys(t.next||""),function(e,r){(r=t.next[e])&&(n&&delete(p(c,n).get(e)._.echo||"")[r.id],r.on("in",{get:e,put:s,$:r.$}))},0,99)}t.soul||e.$$||(n=u(a),r=e.$._||"",(n!==r.link&&(!t.has||r.link)||(c.pass||"")[t.id]&&"string"!=typeof n)&&(delete(r.echo||"")[t.id],o({get:t.get,put:s,$:e.$,linked:e.linked=e.linked||r.link},t)))}function i(e,t){var r=this.as,o=r.$._,i=(o.root,r.get||""),a=(e.put||"")[i["#"]]||"";if(!e.put||"string"==typeof i["."]&&s===a[i["."]]){if(s!==o.put)return;if(!o.soul&&!o.has)return;return o.ack=(o.ack||0)+1,void o.on("in",{get:o.get,put:o.put=s,$:o.$,"@":e["@"]})}(e._||{}).miss=1,n.on.put(e)}n.chain.chain=function(e){var t,r=this,o=r._,i=new(e||r).constructor(r),s=i._;return s.root=t=o.root,s.id=++t.once,s.back=r._,s.on=n.on,s.on("in",n.on.in,s),s.on("out",n.on.out,s),i},n.on.out=function(e){var t,n,r=this.as,o=r.back,a=r.root;if(e.$||(e.$=r.$),this.to.next(e),!r.err){if(t=e.get){if(a.pass&&(a.pass[r.id]=r),r.lex&&Object.keys(r.lex).forEach(function(e){n[e]=r.lex[e]},n=e.get=e.get||{}),t["#"]||r.soul){if(t["#"]=t["#"]||r.soul,e["#"]||(e["#"]=c(9)),o=p(a,t["#"])._,t=t["."]){if(l(o.put,t)&&(n=o.ask&&o.ask[t],(o.ask||(o.ask={}))[t]=o.$.get(t)._,o.on("in",{get:t,put:{"#":o.soul,".":t,":":o.put[t],">":h(a.graph[o.soul],t)}}),n))return}else{if(n=o.ask&&o.ask[""],(o.ask||(o.ask={}))[""]=o,s!==o.put&&(o.on("in",o),n))return;e.$=o.$}return a.ask(i,e),a.on("in",e)}if(t["."])return r.get?(e={get:{".":r.get},$:r.$},(o.ask||(o.ask={}))[r.get]=e.$._,o.on("out",e)):(e={get:r.lex?e.get:{},$:r.$},o.on("out",e));if((r.ask||(r.ask={}))[""]=r,r.get)return t["."]=r.get,(o.ask||(o.ask={}))[r.get]=e.$._,o.on("out",e)}return o.on("out",e)}r.on("in",{put:r.put=s,$:r.$})},n.on.in=function(e,t){var n,i=(t=t||this.as).root,c=e.$||(e.$=t.$),l=(c||"")._||a,f=e.put||"",g=f["#"],y=f["."],m=s!==f["="]?f["="]:f[":"],w=f[">"]||-1/0;if(s!==e.put&&(s===f["#"]||s===f["."]||s===f[":"]&&s===f["="]||s===f[">"]))return u(f)?void t.on("in",{$:l.back.$,put:{"#":g=l.back.soul,".":y=l.has||l.get,"=":f,">":h(l.back.put,y)},via:e}):(g=((f||"")._||"")["#"])?(c=p(t.root,g),setTimeout.each(Object.keys(f).sort(),function(n){"_"!=n&&s!==(w=h(f,n))&&t.on("in",{$:c,put:{"#":g,".":n,"=":f[n],">":w},VIA:e})})):void console.log("chain not yet supported for",f,"...",e,t);(e.seen||"")[t.id]||((e.seen||(e.seen=function(){}))[t.id]=t,t!==l&&(Object.keys(e).forEach(function(t){f[t]=e[t]},f={}),f.get=t.get||f.get,t.soul||t.has?l.soul&&(f.$=t.$,f.$$=f.$$||l.$):f.$$$=f.$$$||t.$,e=f),o(e,t),(t.soul||e.$$)&&w>=h(i.graph[g],y)&&((f=p(i,g)._).put=d(f.put,y,w,m,g)),!l.soul&&w>=h(i.graph[g],y)&&(n=(p(i,g)._.next||"")[y])&&(n.put=m,"string"==typeof(f=u(m))&&(n.put=p(i,f)._.put||m)),this.to&&this.to.next(e),t.any&&setTimeout.each(Object.keys(t.any),function(n){(n=t.any[n])&&n(e)},0,99),t.echo&&setTimeout.each(Object.keys(t.echo),function(n){(n=t.echo[n])&&n.on("in",e)},0,99),((e.$$||"")._||l).soul&&(n=t.next)&&(n=n[y])&&(f={},Object.keys(e).forEach(function(t){f[t]=e[t]}),f.$=(e.$$||e.$).get(f.get=y),delete f.$$,delete f.$$$,n.on("in",f)),r(e,t))},n.on.link=r,n.on.unlink=o;var s,a={},c=String.random,u=n.valid,l=function(e,t){return e&&Object.prototype.hasOwnProperty.call(e,t)},f=n.state,h=f.is,d=f.ify;function p(e,t){e._sl=1;var n=e.$.get(t);return e._sl=0,n}})(t,"./chain"),t(function(e){var n=t("./root");function r(e){var t=this.at||this.on;if(!e||t.soul||t.has)return this.off();if(e=(e=(e=e.$||e)._||e).id){var n;if(t.map,(n=this.seen||(this.seen={}))[e])return!0;n[e]=!0}}n.chain.get=function(e,t,a){var c,u;if("string"==typeof e){if(0==e.length)return(c=this.chain())._.err={err:n.log("0 length key!",e)},t&&t.call(c,c._.err),c;var l=this,f=(w=l._).next||i;if(l===w.root.$&&e.indexOf("/")>=0&&!w.root._sl&&!w.root.graph[e]){for(var h=e.split("/"),d=0,p=l._,g=1;d<h.length;){if(!(p.next||{})[h[d]]){g=0;break}p=p.next[h[d++]].$._}if(g){var y=l;for(d=0;d<h.length;)y=y.get(h[d++]);return y}}(c=f[e])||(c=e&&function(e,t){var n=t._,r=n.next,o=t.chain()._;return r||(r=n.next={}),r[o.get=e]=o,t===n.root.$?o.soul=e:(n.soul||n.has)&&(o.has=e),o}(e,l)),c=c&&c.$}else{if("function"==typeof e){if(!0===t)return function(e,t,r,i){var s,a=e._,c=0;(s=a.soul||a.link)?t(s,i,a):a.jam?a.jam.push([t,i]):(a.jam=[[t,i]],e.get(function(e,t){if(!(o===e.put&&!a.root.opt.super&&(s=Object.keys(a.root.opt.peers).length)&&++c<=s)){t.rid(e);var r,i=(i=e.$)&&i._||{},u=0;for(s=a.jam,delete a.jam;r=s[u++];){var l=r[0];r=r[1],l&&l(i.link||i.soul||n.valid(e.put)||((e.put||{})._||{})["#"],r,e,t)}}},{out:{get:{".":!0}}}))}(this,e,0,a),this;var m,w=(c=this)._,b=t||{},v=w.root;b.at=w,b.ok=e;var E={};function A(e,t,r){if(!A.stun&&(!(i=v.pass)||i[m])){var i,s=e.$._,a=(e.$$||"")._,c=(a||s).put,u=!s.has&&!s.soul,l={};if((u||o===c)&&(c=o===((i=e.put)||"")["="]?o===(i||"")[":"]?i:i[":"]:i["="]),"string"==typeof(i=n.valid(c))&&(c=o===(i=v.$.get(i)._.put)?b.not?o:c:i),!b.not||o!==c){if(o===b.stun){if((i=v.stun)&&i.on&&(w.$.back(function(e){if(i.on(""+e.id,l={}),(l.run||0)<A.id)return l}),!l.run&&i.on(""+s.id,l={}),!l.run&&a&&i.on(""+a.id,l={}),A.id>l.run&&(l.stun&&!l.stun.end||(l.stun=i.on("stun"),l.stun=l.stun&&l.stun.last),l.stun&&!l.stun.end)))return void((l.stun.add||(l.stun.add={}))[m]=function(){A(e,t,1)});if(o===c&&(r=0),(i=v.hatch)&&!i.end&&o===b.hatch&&!r){if(E[s.$._.id])return;return E[s.$._.id]=1,void i.push(function(){A(e,t,1)})}E={}}if(v.pass){if(v.pass[m+s.id])return;v.pass[m+s.id]=1}b.on?b.ok.call(s.$,c,s.get,e,t||A):b.v2020?b.ok(e,t||A):(Object.keys(e).forEach(function(t){i[t]=e[t]},i={}),(e=i).put=c,b.ok.call(b.as,e,t||A))}}}return A.at=w,(w.any||(w.any={}))[m=String.random(7)]=A,A.off=function(){A.stun=1,w.any&&delete w.any[m]},A.rid=r,A.id=b.run||++v.once,u=v.pass,(v.pass={})[m]=1,b.out=b.out||{get:{}},w.on("out",b.out),v.pass=u,c}if("number"==typeof e)return this.get(""+e,t,a);if("string"==typeof(u=s(e)))return this.get(u,t,a);(u=this.get.next)&&(c=u(this,e))}return c?(t&&"function"==typeof t&&c.get(t,a),c):((c=this.chain())._.err={err:n.log("Invalid get request!",e)},t&&t.call(c,c._.err),c)};var o,i={},s=n.valid})(t,"./get"),t(function(e){var n=t("./root");function r(e,t){if(t){t=(t._||"").id||t;var r,o=e.root.stun||(e.root.stun={on:n.on}),i={};e.stun||(e.stun=o.on("stun",function(){})),(r=o.on(""+t))&&r.the.last.next(i),i.run>=e.run||o.on(""+t,function(t){if(e.stun.end)return this.off(),void this.to.next(t);t.run=t.run||e.run,t.stun=t.stun||e.stun})}}function o(e){if(e.err)o.end(e.stun,e.root);else if(!e.todo.length&&!e.end&&Object.empty(e.wait)){e.end=1;var t,r=e.$.back(-1)._,i=r.root,s=r.ask(function(t){i.on("ack",t),t.err&&!t.lack&&n.log(t),++a>(e.acks||0)&&this.off(),e.ack&&e.ack(t,this)},e.opt),a=0,c=e.stun;(t=function(){c&&(o.end(c,i),setTimeout.each(Object.keys(c=c.add||""),function(e){(e=c[e])&&e()}))}).hatch=t,e.ack&&!e.ok&&(e.ok=e.acks||9),e.via._.on("out",{put:e.out=e.graph,ok:e.ok&&{"@":e.ok+1},opt:e.opt,"#":s,_:t})}}n.chain.put=function(e,t,s){var l=this,f=l._,h=f.root;(s=s||{}).root=f.root,s.run||(s.run=h.once),r(s,f.id),s.ack=s.ack||t,s.via=s.via||l,s.data=s.data||e,s.soul||(s.soul=f.soul||"string"==typeof t&&t);var d=s.state=s.state||n.state();return"function"==typeof e?(e(function(e){s.data=e,l.put(i,i,s)}),l):s.soul?(s.$=h.$.get(s.soul),s.todo=[{it:s.data,ref:s.$}],s.turn=s.turn||a,s.ran=s.ran||o,function e(){var t,i,a,l,f,h=s.todo,p=h.pop(),g=p.it;if(p.ref&&p.ref._.id,r(s,p.ref),(l=p.todo)&&(g=g[i=l.pop()],l.length&&h.push(p)),i&&(h.path||(h.path=[])).push(i),!(t=c(g))&&!(f=n.is(g))){if(!Object.plain(g))return void o.err(s,"Invalid data: "+function(e,t){return e&&(t=e.constructor)&&t.name||typeof e}(g)+" at "+(s.via.back(function(e){e.get&&l.push(e.get)},l=[])||l.join("."))+"."+(h.path||[]).join("."));for(var y=s.seen||(s.seen=[]),m=y.length;m--;)if(g===(l=y[m]).it){t=g=l.link;break}}if(i&&t)p.node=u(p.node,i,d,g);else{if(!s.seen)return void o.err(s,"Data at root of graph must be a node (an object).");s.seen.push(a={it:g,link:{},todo:f?[]:Object.keys(g).sort().reverse(),path:(h.path||[]).slice(),up:p}),p.node=u(p.node,i,d,a.link),!f&&a.todo.length&&h.push(a);var w=s.seen.length;function b(e,t){var n=a.link["#"];t&&(t.off(),t.rid(e));var o=n||e.soul||(l=(e.$$||e.$)._||"").soul||l.link||((l=l.put||"")._||"")["#"]||l["#"]||((l=e.put||"")&&e.$$?l["#"]:(l["="]||l[":"]||"")["#"]);!n&&r(s,e.$),o||p.link["#"]?(o||(o=[],(e.$$||e.$).back(function(e){if(l=e.soul||e.link)return o.push(l);o.push(e.get)}),o=o.reverse().join("/")),a.link["#"]=o,!f&&(((s.graph||(s.graph={}))[o]=a.node||(a.node={_:{}}))._["#"]=o),delete s.wait[w],a.wait&&setTimeout.each(a.wait,function(e){e&&e()}),s.ran(s)):(p.wait||(p.wait=[])).push(function(){b(e,t)})}(s.wait||(s.wait={}))[w]="",l=(a.ref=f?g:i?p.ref.get(i):p.ref)._,(l=g&&(g._||"")["#"]||l.soul||l.link)?b({soul:l}):a.ref.get(b,{run:s.run,v2020:1,out:{get:{".":" "}}})}if(!h.length)return s.ran(s);s.turn(e)}(),l):(function(e){var t,n=e.via._;e.via=e.via.back(function(n){if(n.soul||!n.get)return n.$;t=e.data,(e.data={})[n.get]=t}),e.via&&e.via._.soul||(e.via=n.root.$.get(((e.data||"")._||"")["#"]||n.$.back("opt.uuid")())),e.via.put(e.data,e.ack,e)}(s),l)},o.end=function(e,t){e.end=s,e.the.to===e&&e===e.the.last&&delete t.stun,e.off()},o.err=function(e,t){(e.ack||s).call(e,e.out={err:e.err=n.log(t)}),e.ran(e)};var i,s=function(){},a=setTimeout.turn,c=n.valid,u=n.state.ify})(t,"./put"),t(function(e){var n=t("./root");t("./chain"),t("./back"),t("./put"),t("./get"),e.exports=n})(t,"./core"),t(function(e){var n=t("./root");t("./shim"),t("./onto"),t("./book"),t("./valid"),t("./state"),t("./dup"),t("./ask"),t("./core"),t("./on"),t("./map"),t("./set"),t("./mesh"),t("./websocket"),t("./localStorage"),e.exports=n})(t,"./index"),t(function(e){var n,r=t("./root");r.chain.on=function(e,t,n,r){var o,i=this,s=i._;if(s.root,"string"==typeof e)return t?(o=s.on(e,t,n||s,r),n&&n.$&&(n.subs||(n.subs=[])).push(o),i):s.on(e);var a=t;return(a=!0===a?{change:!0}:a||{}).not=1,a.on=1,i.get(e,a),i},r.chain.once=function(e,t){if(t=t||{},!e)return function(e,t,n){return r.log.once("valonce","Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),(n=e.chain())._.nix=e.once(function(e,t){n._.on("in",this._)}),n._.lex=e._.lex,n}(this);var o,i=this,s=i._,a=s.root,c=(s.put,String.random(7));return i.get(function(i,u,l,f){var h=this,d=h._,p=d.one||(d.one={});function g(y){d.has||d.soul||(d={put:i,get:u}),n===(o=d.put)&&(o=((l.$$||"")._||"").put),"string"!=typeof r.valid(o)||(o=a.$.get(o)._.put)!==n||y?f.stun||""!==p[c]&&(p[c]="",(s.soul||s.has)&&f.off(),e.call(h,o,d.get),clearTimeout(p[c])):p[c]=setTimeout(function(){g(1)},t.wait||99)}f.stun||""!==p[c]&&(!0!==(o=r.valid(i))?"string"!=typeof o&&(clearTimeout((s.one||"")[c]),clearTimeout(p[c]),p[c]=setTimeout(g,t.wait||99)):g())},{on:1}),i},r.chain.off=function(){var e,t=this._,n=t.back;if(n)return t.ack=0,(e=n.next)&&e[t.get]&&delete e[t.get],(e=n.any)&&(delete n.any,n.any={}),(e=n.ask)&&delete e[t.get],(e=n.put)&&delete e[t.get],(e=t.soul)&&delete n.root.graph[e],(e=t.map)&&Object.keys(e).forEach(function(t,r){(r=e[t]).link&&n.root.$.get(r.link).off()}),(e=t.next)&&Object.keys(e).forEach(function(t,n){e[t].$.off()}),t.on("off",{}),this}})(t,"./on"),t(function(e){var n=t("./root"),r=n.chain.get.next;function o(e){this.to.next(e);var t,r=this.as,o=e.$._,i=e.put;(o.soul||e.$$)&&((t=r.lex)&&!String.match(e.get||(i||"")["."],t["."]||t["#"]||t)||n.on.link(e,r))}n.chain.get.next=function(e,t){var n;return Object.plain(t)?(n=((n=t["#"])||"")["="]||n)?e.get(n):((n=e.chain()._).lex=t,e.on("in",function(e){String.match(e.get||(e.put||"")["."],t["."]||t["#"]||t)&&n.on("in",e),this.to.next(e)}),n.$):(r||s)(e,t)},n.chain.map=function(e,t,r){var a,c,u=this,l=u._;return Object.plain(e)&&(a=e["."]?e:{".":e},e=i),e?(n.log.once("mapfn","Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),c=u.chain(),u.map().on(function(t,r,o,a){var u=(e||s).call(this,t,r,o,a);if(i!==u){if(t===u)return c._.on("in",o);if(n.is(u))return c._.on("in",u._);var l={};Object.keys(o.put).forEach(function(e){l[e]=o.put[e]},l),l["="]=u,c._.on("in",{get:r,put:l})}}),c):((c=l.each)||((l.each=c=u.chain())._.lex=a||c._.lex||l.lex,c._.nix=u.back("nix"),u.on("in",o,c._)),c)};var i,s=function(){}})(t,"./map"),t(function(e){var n=t("./root");n.chain.set=function(e,t,r){var o,i,s=this,a=s.back(-1);return t=t||function(){},(r=r||{}).item=r.item||e,(o=((e||"")._||"")["#"])&&((e={})["#"]=o),"string"==typeof(i=n.valid(e))?s.get(o=i).put(e,t,r):n.is(e)?(s.put(function(r){e.get(function(e,o,a){if(!e)return t.call(s,{err:n.log('Only a node can be linked! Not "'+a.put+'"!')});(i={})[e]={"#":e},r(i)},!0)}),e):(Object.plain(e)&&(e=a.get(o=s.back("opt.uuid")()).put(e)),s.get(o||a.back("opt.uuid")(7)).put(e,t,r))}})(t,"./set"),t(function(e){t("./shim");var n,r=function(){},o=JSON.parseAsync||function(e,t,n){var r=+new Date;try{t(void 0,JSON.parse(e,n),i.sucks(+new Date-r))}catch(e){t(e)}},i=JSON.stringifyAsync||function(e,t,n,r){var o=+new Date;try{t(void 0,JSON.stringify(e,n,r),i.sucks(+new Date-o))}catch(e){t(e)}};i.sucks=function(e){e>99&&(console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."),i.sucks=r)};try{e.exports=function(e){var t=function(){},r=e.opt||{};r.log=r.log||console.log,r.gap=r.gap||r.wait||0,r.max=r.max||.3*(r.memory?999*r.memory*999:3e8),r.pack=r.pack||.01*r.max*.01,r.puff=r.puff||9;var s=setTimeout.turn||setTimeout,a=e.dup,c=a.check,u=a.track,l=(new Date,t.hear=function(e,n){if(e){if(r.max<=e.length)return t.say({dam:"!",err:"Message too big!"},n);t===this&&(l.d+=e.length||0,++l.c);var i,a=n.SH=+new Date,c=e[0];return"["===c?(o(e,function(e,o){if(e||!o)return t.say({dam:"!",err:"DAM JSON parse error."},n);console.STAT&&console.STAT(+new Date,o.length,"# on hear batch");var i=r.puff;!function e(){for(var r,a=+new Date,c=0;c<i&&(r=o[c++]);)t.hear(r,n);o=o.slice(c),console.STAT&&console.STAT(a,+new Date-a,"hear loop"),f(n),o.length&&s(e,0)}()}),void(e="")):"{"===c||(e["#"]||Object.plain(e))&&(i=e)?i?l.one(i,n,a):void o(e,function(e,r){if(e||!r)return t.say({dam:"!",err:"DAM JSON parse error."},n);l.one(r,n,a)}):void 0}});function f(e){var t=e.batch,n="string"==typeof t;if(n&&(t+="]"),e.batch=e.tail=null,t&&!(n?3>t.length:!t.length)){if(!n)try{t=1===t.length?t[0]:JSON.stringify(t)}catch(e){return r.log("DAM JSON stringify error",e)}t&&h(t,e)}}function h(e,n){try{var r=n.wire;n.say?n.say(e):r.send&&r.send(e),t.say.d+=e.length||0,++t.say.c}catch(t){(n.queue=n.queue||[]).push(e)}}l.one=function(n,r,o){var i,s,l,f,h;if(n.DBG&&(n.DBG=h={DBG:n.DBG}),h&&(h.h=o),h&&(h.hp=+new Date),(i=n["#"])||(i=n["#"]=String.random(9)),!((l=c(i))||(s=n["##"])&&(l=n["@"]||n.get&&i)&&a.check(f=l+s))){if((n._=function(){}).via=t.leap=r,(l=n["><"])&&"string"==typeof l&&l.slice(0,99).split(",").forEach(function(e){this[e]=1},n._.yo={}),l=n.dam)return(u(i)||{}).via=r,void((l=t.hear[l])&&l(n,r,e));(l=n.ok)&&(n._.near=l["/"]),o=+new Date,h&&(h.is=o),r.SI=i,u.ed=function(e){i===e&&(u.ed=0,(e=a.s[i])&&(e.via=r,n.get&&(e.it=n)))},e.on("in",t.last=n),h&&(h.hd=+new Date),console.STAT&&console.STAT(o,+new Date-o,n.get?"msg get":n.put?"msg put":"msg"),u(i),f&&u(f),t.leap=t.last=null}},l.c=l.d=0,function(){var e,o=0;function l(e,t){var n;return t instanceof Object?(Object.keys(t).sort().forEach(d,{to:n={},on:t}),n):t}function d(e){this.to[e]=this.on[e]}t.hash=function(e,n){var r,o,a,c=+new Date;i(e.put,function i(u,l){var f=(o||(o=a=l||"")).slice(0,32768);r=String.hash(f,r),(o=o.slice(32768))?s(i,0):(console.STAT&&console.STAT(c,+new Date-c,"say json+hash"),e._.$put=a,e["##"]=r,t.say(e,n),delete e._.$put)},l)},t.say=function(i,c){var l;if((l=this)&&(l=l.to)&&l.next&&l.next(i),!i)return!1;var d,p,g,y=i["@"],m=i._||(i._=function(){}),w=i.DBG,b=+new Date;if(m.y=m.y||b,c||w&&(w.y=b),(d=i["#"])||(d=i["#"]=String.random(9)),!e&&u(d),(p=i["##"])||n===i.put||m.via||!y){if(!c&&y&&(c=(l=a.s[y])&&(l.via||(l=l.it)&&(l=l._)&&l.via)||(l=t.last)&&y===l["#"]&&t.leap),!c&&y){if(a.s[y])return;return console.STAT&&console.STAT(+new Date,++o,"total no peer to ack to"),!1}if(y&&!i.put&&!p&&((a.s[y]||"").it||"")["##"])return!1;if(!c&&t.way)return t.way(i);if(w&&(w.yh=+new Date),g=m.raw){if(w&&(w.yr=+new Date),!c||!c.id){if(!Object.plain(c||r.peers))return!1;b=+new Date,r.puff;var v=r.peers,E=Object.keys(c||r.peers||{});return console.STAT&&console.STAT(b,+new Date-b,"peer keys"),void function n(){var r=+new Date;e=1;var o=m.raw;m.raw=g;for(var a,l=0;l<9&&(a=(E||"")[l++]);)(a=v[a]||(c||"")[a])&&t.say(i,a);m.raw=o,e=0,E=E.slice(l),console.STAT&&console.STAT(r,+new Date-r,"say loop"),E.length&&(s(n,0),y&&u(y))}()}if(!c.wire&&t.wire&&t.wire(c),d!==c.last){if(c.last=d,c===m.via)return!1;if((l=m.yo)&&(l[c.url]||l[c.pid]||l[c.id]))return!1;if(console.STAT&&console.STAT(b,((w||m).yp=+new Date)-(m.y||b),"say prep"),!e&&y&&u(y),c.batch){if(c.tail=(l=c.tail||0)+g.length,c.tail<=r.pack)return void(c.batch+=(l?",":"")+g);f(c)}c.batch="[";var A=+new Date;setTimeout(function(){console.STAT&&console.STAT(A,+new Date-A,"0ms TO"),f(c)},r.gap),h(g,c),console.STAT&&y===c.SI&&console.STAT(b,+new Date-c.SH,"say ack")}}else t.raw(i,c)}else t.hash(i,c)},t.say.c=t.say.d=0,t.raw=function(e,o){if(!e)return"";var s,u,l=e._||{};if(u=l.raw)return u;if("string"==typeof e)return e;var f=e["##"],h=e["@"];if(f&&h){if(!l.via&&c(h+f))return!1;if(u=(a.s[h]||"").it){if(f===u["##"])return!1;u["##"]||(u["##"]=f)}}if(!e.dam&&!e["@"]){var d=0,p=[];for(var g in u=r.peers){var y=u[g];if(p.push(y.url||y.pid||y.id),++d>6)break}d>1&&(e["><"]=p.join())}if(e.put&&(u=e.ok)&&(e.ok={"@":(u["@"]||1)-1,"/":u["/"]==e._.near?t.near:u["/"]}),s=l.$put)return u={},Object.keys(e).forEach(function(t){u[t]=e[t]}),u.put=":])([:",void i(u,function(e,t){if(!e){var r=+new Date;u=t.indexOf('"put":":])([:"'),m(n,t=t.slice(0,u+6)+s+t.slice(u+14)),console.STAT&&console.STAT(r,+new Date-r,"say slice")}});function m(n,r){n||(l.raw=r,t.say(e,o))}i(e,m)}}(),t.near=0,t.hi=function(n){var o;n.wire?(n.id?r.peers[n.url||n.id]=n:(o=n.id=n.id||n.url||String.random(9),t.say({dam:"?",pid:e.opt.pid},r.peers[o]=n),delete a.s[n.last]),n.met||(t.near++,n.met=+new Date,e.on("hi",n)),o=n.queue,n.queue=[],setTimeout.each(o||[],function(e){h(e,n)},0,9)):t.wire(n.length&&{url:n,id:n}||n)},t.bye=function(n){n.met&&--t.near,delete n.met,e.on("bye",n);var r=+new Date;r-=n.met||r,t.bye.time=((t.bye.time||r)+r)/2},t.hear["!"]=function(e,t){r.log("Error:",e.err)},t.hear["?"]=function(e,n){e.pid&&(n.pid||(n.pid=e.pid),e["@"])||(t.say({dam:"?",pid:r.pid,"@":e["#"]},n),delete a.s[n.last])},t.hear.mob=function(e,n){if(e.peers){var r=Object.keys(e.peers),o=r[Math.random()*r.length|0];o&&(t.bye(n),t.hi(o))}},e.on("create",function(e){e.opt.pid=e.opt.pid||String.random(9),this.to.next(e),e.on("out",t.say)}),e.on("bye",function(e,t){e=r.peers[e.id||e]||e,this.to.next(e),e.bye?e.bye():(t=e.wire)&&t.close&&t.close(),delete r.peers[e.id],e.wire=null});var d={};return e.on("bye",function(e,n){this.to.next(e),(n=console.STAT)&&(n.peers=t.near),(n=e.url)&&(d[n]=!0,setTimeout(function(){delete d[n]},r.lack||9e3))}),e.on("hi",function(n,o){if(this.to.next(n),(o=console.STAT)&&(o.peers=t.near),!r.super){var i=Object.keys(e.next||"");i.length>9999&&!console.SUBS&&console.log(console.SUBS="Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`."),setTimeout.each(i,function(o){var i=e.next[o];r.super||(i.ask||"")[""]?t.say({get:{"#":o}},n):setTimeout.each(Object.keys(i.ask||""),function(r){r&&t.say({"##":String.hash((e.graph[o]||"")[r]),get:{"#":o,".":r}},n)})})}}),t}}catch(e){}})(t,"./mesh"),t(function(e){var n=t("./root");n.Mesh=t("./mesh"),n.on("opt",function(e){if(this.to.next(e),!e.once){var t=e.opt;if(!1!==t.WebSocket){var r=n.window||{},o=t.WebSocket||r.WebSocket||r.webkitWebSocket||r.mozWebSocket;if(o){t.WebSocket=o;var i=t.mesh=t.mesh||n.Mesh(e),s=i.wire||t.wire;i.wire=t.wire=u,setTimeout(function(){!t.super&&e.on("out",{dam:"hi"})},1);var a=1998,c=""+void 0!=typeof document&&document}}}function u(e){try{if(!e||!e.url)return s&&s(e);var n=e.url.replace(/^http/,"ws"),r=e.wire=new t.WebSocket(n);return r.onclose=function(){l(e),t.mesh.bye(e)},r.onerror=function(t){l(e)},r.onopen=function(){t.mesh.hi(e)},r.onmessage=function(n){n&&t.mesh.hear(n.data||n,e)},r}catch(n){t.mesh.bye(e)}}function l(e){clearTimeout(e.defer),t.peers[e.url]&&(c&&e.retry<=0||(e.retry=(e.retry||t.retry+1||60)-(-e.tried+(e.tried=+new Date)<4*a?1:0),e.defer=setTimeout(function t(){if(c&&c.hidden)return setTimeout(t,a);u(e)},a)))}})})(t,"./websocket"),t(function(e){if("undefined"!=typeof Gun){var t;try{t=(Gun.window||function(){}).localStorage}catch(e){}t||(Gun.log("Warning: No localStorage exists to persist data to!"),t={setItem:function(e,t){this[e]=t},removeItem:function(e){delete this[e]},getItem:function(e){return this[e]}}),JSON.parseAsync;var n=JSON.stringifyAsync||function(e,t,n,r){try{t(void 0,JSON.stringify(e,n,r))}catch(e){t(e)}};Gun.on("create",function e(r){this.to.next(r);var o,i,s,a,c=r.opt,u=(r.graph,[]);if(!1!==c.localStorage){c.prefix=c.file||"gun/";try{o=e[c.prefix]=e[c.prefix]||JSON.parse(s=t.getItem(c.prefix))||{}}catch(t){o=e[c.prefix]={}}s=(s||"").length,r.on("get",function(e){this.to.next(e);var t,n,r,i=e.get;i&&(t=i["#"])&&((n=o[t]||void 0)&&(r=i["."])&&!Object.plain(r)&&(n=Gun.state.ify({},r,Gun.state.is(n,r),n[r],t)),Gun.on.get.ack(e,n))}),r.on("put",function(e){this.to.next(e);var t=e.put,n=t["#"],c=t["."],f=e["#"],h=e.ok||"";o[n]=Gun.state.ify(o[n],c,t[">"],t[":"],n),a&&s>4999880?r.on("in",{"@":f,err:"localStorage max!"}):(e["@"]||e._.via&&!(Math.random()<h["@"]/h["/"])||u.push(f),i||(i=setTimeout(l,9+s/333)))})}function l(){if(u.length||!((setTimeout.turn||"").s||"").length){var e=u;clearTimeout(i),i=!1,u=[],n(o,function(n,i){try{!n&&t.setItem(c.prefix,i)}catch(e){n=a=e||"localStorage failure"}n&&(Gun.log(n+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),r.on("localStorage:error",{err:n,get:c.prefix,put:o})),s=i.length,setTimeout.each(e,function(e){r.on("in",{"@":e,err:n,ok:0})},0,99)})}else setTimeout(l,99)}})}})(t,"./localStorage")}(),function(){if(""+A!=typeof Gun){var e=function(e){console.warn("Warning! Deprecated internal utility will break in next version:",e)},t=Gun;t.fn=t.fn||{is:function(t){return e("fn"),!!t&&"function"==typeof t}},t.bi=t.bi||{is:function(t){return e("bi"),t instanceof Boolean||"boolean"==typeof t}},t.num=t.num||{is:function(t){return e("num"),!r(t)&&(t-parseFloat(t)+1>=0||1/0===t||-1/0===t)}},t.text=t.text||{is:function(t){return e("text"),"string"==typeof t}},t.text.ify=t.text.ify||function(n){return e("text.ify"),t.text.is(n)?n:"undefined"!=typeof JSON?JSON.stringify(n):n&&n.toString?n.toString():n},t.text.random=t.text.random||function(t,n){e("text.random");var r="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";t>0;)r+=n.charAt(Math.floor(Math.random()*n.length)),t--;return r},t.text.match=t.text.match||function(t,n){var r,o;return e("text.match"),"string"==typeof t&&("string"==typeof n&&(n={"=":n}),t===(r=(n=n||{})["="]||n["*"]||n[">"]||n["<"])||o===n["="]&&(r=n["*"]||n[">"]||n["<"],t.slice(0,(r||"").length)===r||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},t.text.hash=t.text.hash||function(t,n){if(e("text.hash"),"string"==typeof t){if(n=n||0,!t.length)return n;for(var r=0,o=t.length;r<o;++r)n=(n<<5)-n+t.charCodeAt(r),n|=0;return n}},t.list=t.list||{is:function(t){return e("list"),t instanceof Array}},t.list.slit=t.list.slit||Array.prototype.slice,t.list.sort=t.list.sort||function(t){return e("list.sort"),function(e,n){return e&&n?(e=e[t])<(n=n[t])?-1:e>n?1:0:0}},t.list.map=t.list.map||function(t,n,r){return e("list.map"),s(t,n,r)},t.list.index=1,t.obj=t.boj||{is:function(t){return e("obj"),!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])}},t.obj.put=t.obj.put||function(t,n,r){return e("obj.put"),(t||{})[n]=r,t},t.obj.has=t.obj.has||function(t,n){return e("obj.has"),t&&Object.prototype.hasOwnProperty.call(t,n)},t.obj.del=t.obj.del||function(t,n){if(e("obj.del"),t)return t[n]=null,delete t[n],t},t.obj.as=t.obj.as||function(t,n,r,o){return e("obj.as"),t[n]=t[n]||(o===r?{}:r)},t.obj.ify=t.obj.ify||function(t){if(e("obj.ify"),o(t))return t;try{t=JSON.parse(t)}catch(e){t={}}return t},function(){function n(e,t){i(this,t)&&void 0!==this[t]||(this[t]=e)}t.obj.to=t.obj.to||function(t,r){return e("obj.to"),s(t,n,r=r||{}),r}}(),t.obj.copy=t.obj.copy||function(t){return e("obj.copy"),t?JSON.parse(JSON.stringify(t)):t},function(){function n(e,t){var n=this.n;if(!n||!(t===n||o(n)&&i(n,t)))return void 0!==t||void 0}t.obj.empty=t.obj.empty||function(t,r){return e("obj.empty"),!t||!s(t,n,{n:r})}}(),function(){function n(e,t){if(2===arguments.length)return n.r=n.r||{},void(n.r[e]=t);n.r=n.r||[],n.r.push(e)}var s,a=Object.keys;Object.keys=Object.keys||function(e){return s(e,function(e,t,n){n(t)})},t.obj.map=s=t.obj.map||function(s,c,u){e("obj.map");var l,f,h,d,p,g=0,y="function"==typeof c;if(n.r=l,a&&o(s)&&(d=a(s),p=!0),u=u||{},r(s)||d)for(f=(d||s).length;g<f;g++){var m=g+t.list.index;if(y){if((h=p?c.call(u,s[d[g]],d[g],n):c.call(u,s[g],m,n))!==l)return h}else if(c===s[p?d[g]:g])return d?d[g]:m}else for(g in s)if(y){if(i(s,g)&&(h=u?c.call(u,s[g],g,n):c(s[g],g,n))!==l)return h}else if(c===s[g])return g;return y?n.r:t.list.index?0:-1}}(),t.time=t.time||{},t.time.is=t.time.is||function(t){return e("time"),t?t instanceof Date:+(new Date).getTime()};var n=t.fn.is,r=t.list.is,o=(E=t.obj).is,i=E.has,s=E.map,a={is:function(t){return e("val.is"),t!==A&&(null===t||t!==1/0&&(!!(f(t)||u(t)||l(t))||a.link.is(t)||!1))}};a.link=a.rel={_:"#"},function(){function t(e,t){var n=this;return n.id?n.id=!1:t==c&&f(e)?void(n.id=e):n.id=!1}a.link.is=function(n){if(e("val.link.is"),n&&n[c]&&!n._&&o(n)){var r={};if(s(n,t,r),r.id)return r.id}return!1}}(),a.link.ify=function(t){return e("val.link.ify"),h({},c,t)},t.obj.has._=".";var c=a.link._,u=t.bi.is,l=t.num.is,f=t.text.is,h=(o=(E=t.obj).is,E.put);s=E.map,t.val=t.val||a;var d={_:"_",soul:function(t,n){return e("node.soul"),t&&t._&&t._[n||y]}};d.soul.ify=function(t,n){return e("node.soul.ify"),n="string"==typeof n?{soul:n}:n||{},(t=t||{})._=t._||{},t._[y]=n.soul||t._[y]||g(),t},d.soul._=a.link._,function(){function t(e,t){if(t!==d._)return!a.is(e)||void(this.cb&&this.cb.call(this.as,e,t,this.n,this.s))}d.is=function(n,r,i){var a;return e("node.is"),!!o(n)&&!!(a=d.soul(n))&&!s(n,t,{as:i,cb:r,s:a,n})}}(),function(){function t(e,t){var n,r=this.o;r.map?void 0===(n=r.map.call(this.as,e,""+t,r.node))?p(r.node,t):r.node&&(r.node[t]=n):a.is(e)&&(r.node[t]=e)}d.ify=function(n,r,o){return e("node.ify"),r?"string"==typeof r?r={soul:r}:"function"==typeof r&&(r={map:r}):r={},r.map&&(r.node=r.map.call(o,n,A,r.node||{})),(r.node=d.soul.ify(r.node||{},r))&&s(n,t,{o:r,as:o}),r.node}}(),o=(E=t.obj).is;var p=E.del,g=(s=E.map,t.text.random),y=d.soul._;t.node=t.node||d;var m=t.state;m.lex=function(){return e("state.lex"),m().toString(36).replace(".","")},m.to=function(t,n,r){e("state.to");var i=(t||{})[n];return o(i)&&(i=w(i)),m.ify(r,n,m.is(t,n),i,d.soul(t))},function(){function t(e,t){b!==t&&m.ify(this.o,t,this.s)}m.map=function(r,a,c){var u;e("state.map");var f=o(f=r||a)?f:null;return r=n(r=r||a)?r:null,f&&!r?(a=l(a)?a:m(),f[b]=f[b]||{},s(f,t,{o:f,s:a}),f):(c=c||o(a)?a:u,a=l(a)?a:m(),function(e,n,o,s){if(!r)return t.call({o,s:a},e,n),e;r.call(c||this||{},e,n,o,s),i(o,n)&&u===o[n]||t.call({o,s:a},e,n)})}}(),(E=t.obj).as,i=E.has,o=E.is,s=E.map;var w=E.copy,b=(l=t.num.is,n=t.fn.is,d._),v={};!function(){function t(e,t){if(!e||t!==d.soul(e)||!d.is(e,this.fn,this.as))return!0;this.cb&&(n.n=e,n.as=this.as,this.cb.call(n.as,e,t,n))}function n(e){e&&d.is(n.n,e,n.as)}v.is=function(n,r,i,a){return e("graph.is"),!(!n||!o(n)||x(n)||s(n,t,{cb:r,fn:i,as:a}))}}(),function(){function n(e,t){var n;return(n=function(e,t){for(var n,r=e.seen,o=r.length;o--;)if(n=r[o],t.obj===n.obj)return n;r.push(t)}(e,t))?n:(t.env=e,t.soul=s,d.ify(t.obj,r,t)&&(t.link=t.link||a.link.ify(d.soul(t.node)),t.obj!==e.shell&&(e.graph[a.link.is(t.link)]=t.node)),t)}function r(e,t,r){var o,s,u=this,l=u.env;if(d._===t&&i(e,a.link._))return r._;if(o=c(e,t,r,u,l)){if(t||(u.node=u.node||r||{},i(e,d._)&&d.soul(e)&&(u.node._=w(e._)),u.node=d.soul.ify(u.node,a.link.is(u.link)),u.link=u.link||a.link.ify(d.soul(u.node))),(s=l.map)&&(s.call(l.as||{},e,t,r,u),i(r,t))){if(e=r[t],A===e)return void p(r,t);if(!(o=c(e,t,r,u,l)))return}if(!t)return u.node;if(!0===o)return e;if((s=n(l,{obj:e,path:u.path.concat(t)})).node)return s.link}}function s(e){var t=this,n=a.link.is(t.link),r=t.env.graph;t.link=t.link||a.link.ify(e),t.link[a.link._]=e,t.node&&t.node[d._]&&(t.node[d._][a.link._]=e),i(r,n)&&(r[e]=r[n],p(r,n))}function c(e,n,r,i,s){var u;return!!a.is(e)||(o(e)?1:(u=s.invalid)?c(e=u.call(s.as||{},e,n,r),n,r,i,s):(s.err="Invalid value at '"+i.path.concat(n).join(".")+"'!",void(t.list.is(e)&&(s.err+=" Use `.set(item)` instead of an Array."))))}v.ify=function(t,r,o){e("graph.ify");var i={path:[],obj:t};return r?"string"==typeof r?r={soul:r}:"function"==typeof r&&(r.map=r):r={},"string"==typeof o&&(r.soul=r.soul||o,o=A),r.soul&&(i.link=a.link.ify(r.soul)),r.shell=(o||{}).shell,r.graph=r.graph||{},r.seen=r.seen||[],r.as=r.as||o,n(r,i),r.root=i.node,r.graph}}(),v.node=function(t){e("graph.node");var n=d.soul(t);if(n)return h({},n,t)},function(){function t(e,t){var n,r;if(d._!==t)(n=a.link.is(e))?(r=this.opt.seen[n])?this.obj[t]=r:this.obj[t]=this.opt.seen[n]=v.to(this.graph,n,this.opt):this.obj[t]=e;else{if(x(e,a.link._))return;this.obj[t]=w(e)}}v.to=function(n,r,o){if(e("graph.to"),n){var i={};return o=o||{seen:{}},s(n[r],t,{obj:i,graph:n,opt:o}),i}}}(),n=t.fn.is,o=(E=t.obj).is,p=E.del,i=E.has;var E,A,x=E.empty;h=E.put,s=E.map,w=E.copy,t.graph=t.graph||v}}()},617(e,t,n){!function(){function t(e){(e=e||{}).log=e.log||console.log,e.file=String(e.file||"radata");var r=(t.has||(t.has={}))[e.file];if(r)return r;function s(e){return encodeURIComponent(e).replace(/\*/g,"%2A")}e.max=e.max||.3*(e.memory?999*e.memory*999:3e8),e.until=e.until||e.wait||250,e.batch=e.batch||1e4,e.chunk=e.chunk||1048576,e.code=e.code||{},e.code.from=e.code.from||"!",e.jsonify=!0;var a=""+m==typeof setImmediate?setTimeout:setImmediate,c=setTimeout.turn||a,u=i.object,l=0;if(!e.store)return e.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");if(!e.store.put)return e.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");if(!e.store.get)return e.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");e.store.list,n(968);var f=JSON.parseAsync||function(e,t,n){try{t(void 0,JSON.parse(e,n))}catch(e){t(e)}},h=(JSON.stringifyAsync,function(e,t,n,r,o){if("function"==typeof t){var i=n||{};return n=t,void h.read(e,n,i,o||r)}h.save(e,t,n,r,o)});h.save=function(t,n,r,o,a){var c,u,l={key:t,find:function(t){var n;l.file=t||(t=e.code.from),a&&(a=a[t]=a[t]||{}),a&&(a.sf=a.sf||+new Date),(n=h.disk[t])?l.mix(m,n):h.parse(t,l.mix,m,a)},mix:function(s,c){if(a&&(a.sml=+new Date),a&&(a.sm=a.sm||+new Date),l.err=s||l.err)r(s);else{var u,f=l.file=(c||"").file||l.file;if(!c&&f!==e.code.from)return h.find.bad(f),void h.save(t,n,r,o);(c=h.disk[f]||(h.disk[f]=c||i())).file||(c.file=f),e.compare&&(n=e.compare(c(t),n,t,f),m===n)?r(s,-1):((l.disk=c)(t,n),o&&((u=(u=c.tags||(c.tags={}))[o]||(u[o]=h.tags[o]||(h.tags[o]={})))[f]||(u[f]=h.one[o]||(h.one[o]=r)),r=null),a&&(a.st=a.st||+new Date),c.Q?r&&c.Q.push(r):(c.Q=r?[r]:[],c.to=setTimeout(l.write,e.until)))}},write:function(){a&&(a.sto=a.sto||+new Date);var e=c=l.file,t=l.disk;u=l.q=t.Q,l.tags=t.tags,delete t.Q,delete h.disk[e],delete t.tags,h.write(e,t,l.ack,m,a)},ack:function(e,t){var n,r;for(var o in a&&(a.sa=a.sa||+new Date),a&&(a.sal=u.length),h.tags)if(h.tags.hasOwnProperty(o)){var i=h.tags[o];if(!((r=h.disk[c])&&(r=r.tags)&&r[i])){var f;for(var d in n=i[c],delete i[c],i)if(i.hasOwnProperty(d)){f=!0;break}f||(delete h.tags[i],n&&n(e,t))}}!u&&(u="");for(var p=u.length,g=0,y=+new Date;g<p;g++)(n=u[g])&&n(e,t);console.STAT&&console.STAT(y,+new Date-y,"rad acks",s(l.file)),console.STAT&&console.STAT(y,u.length,"rad acks #",s(l.file))}};r||(r=function(e,t){}),h.find(t,l.find)},h.disk={},h.one={},h.tags={};var d,p,g,y=0;h.write=function(n,r,o,a,c){if(r){a="object"==typeof a?a:{force:a};var u,f,d=function(){};d.text="",d.file=n=r.file||(r.file=n),n?(d.write=function(){var t=r.raw=d.text;h.disk[n=r.file||d.file||n]=r;var i=+new Date;c&&(c.wd=i),h.find.add(n,function(a){c&&(c.wa=+new Date),a?o(a):e.store.put(s(n),t,function(e,t){c&&(c.wp=+new Date),console.STAT&&console.STAT(i,l=+new Date-i,"wrote disk",JSON.stringify(n),++y,"total all writes."),o(e,t||1),r.Q||delete h.disk[n]})})},d.split=function(){var e=+new Date;c&&(c.wf=e),d.text="",d.count||(d.count=0,i.map(r,function(){d.count++})),c&&(c.wfc=d.count),d.limit=Math.ceil(d.count/2);var t=d.count;return d.count=0,c&&(c.wf1=+new Date),d.sub=i(),i.map(r,d.slice,{reverse:1}),c&&(c.wf2=+new Date),h.write(d.end,d.sub,function(e,t){if(e)return o(e);c&&(c.wf3=+new Date),d.hub=i(),i.map(r,d.stop),c&&(c.wf4=+new Date),h.write(r.file,d.hub,o,a)},a),c&&(c.wf5=+new Date),console.STAT&&console.STAT(e,+new Date-e,"rad split",s(r.file),t),!0},d.slice=function(e,t){if(d.sub(d.end=t,e),d.limit<=++d.count)return!0},d.stop=function(e,t){if(t>=d.end)return!0;d.hub(t,e)},d.both=function(e,t){c&&(c.wfd=+new Date),f?o(e||f):u?o(e,t):(u=!0,f=e)},d.each=function(n,r,i,s){if(m!==n&&d.count++,e.max<=(n||"").length)return o("Data too big!"),!0;var c=t.encode(s.length)+"#"+t.encode(i)+(m===n?"":":"+t.encode(n))+"\n";if(e.chunk<d.text.length+c.length&&1<d.count&&!a.force)return d.split();d.text+=c},e.jsonify?h.write.jsonify(d,r,o,a,c):i.map(r,d.each,!0)||d.write()):o("What file?")}else o("No radix!")},h.write.jsonify=function(t,n,r,o,s){var a,c=+new Date;s&&(s.w=c);try{a=JSON.stringify(n.$)}catch(e){return void r("Cannot radisk!")}if(s&&(s.ws=+new Date),console.STAT&&console.STAT(c,+new Date-c,"rad stringified JSON"),e.chunk<a.length&&!o.force){var u=0;if(i.map(n,function(){if(u++)return!0}),u>1)return t.split()}t.text=a,t.write()},h.range=function(e,t){if(e&&t){if(m===t.start&&m===t.end)return e;if(m!==(n=e)&&(!n||"object"!=typeof n))return e;var n,r=i();return i.map(e,function(e,t){r(t,e)},t),r("")}},h.read=function(t,n,r,o){r=r||{};var u={key:t,find:function(t){var n;u.file=t||(t=e.code.from),o&&(o=o[t]=o[t]||{}),o&&(o.rf=o.rf||+new Date),(n=h.disk[u.file=t])?u.check(m,n):h.parse(t,u.check,m,o)},get:function(s,c,l){if(o&&(o.rgl=+new Date),o&&(o.rg=o.rg||+new Date),u.err=s||u.err)n(s);else{var f=u.file=(c||"").file||u.file;if(!c&&f!==e.code.from)return h.find.bad(f),void h.read(t,n,r);if(c=h.disk[f]||(h.disk[f]=c)){c.file||(c.file=f);var d=h.range(c(t),r);if(o&&(o.rr=+new Date),r.unit=c.unit,r.chunks=(r.chunks||0)+1,r.parsed=(r.parsed||0)+((l||"").parsed||r.chunks*e.chunk),r.more=1,r.next=m,i.map(h.list,function(e,t){if(e&&f!==t)return r.next=t,1},r.reverse?{reverse:1,end:f}:{start:f}),o&&(o.rl=+new Date),r.next||(r.more=0),r.next&&(!r.reverse&&(t<r.next&&0!=r.next.indexOf(t)||m!==r.end&&(r.end||"￿")<r.next)&&(r.more=0),r.reverse&&(t>r.next&&0!=t.indexOf(r.next)||m!==r.start&&(r.start||"")>r.next&&f<=r.start)&&(r.more=0)),r.more){if(d&&n(u.err,d,r),!(r.parsed>=r.limit)){var p=+new Date;o&&(o.rm=p);var g=r.next;a(function(){console.STAT&&console.STAT(p,+new Date-p,"rad more"),h.parse(g,u.check)},0)}}else n(u.err,d,r)}else n(f===e.code.from?m:"No file!")}},check:function(t,n,r){if(u.get(t,n,r),n&&!n.check){n.check=1;var o=+new Date;(r||(r={})).file||(r.file=u.file),i.map(n,function(t,n){h.find(n,function(o){if((o||(o=e.code.from))!==r.file){var i=(""+Math.random()).slice(-3);c(function(){h.save(n,t,function e(a,c){a?h.save(n,t,e):console.STAT&&console.STAT("MISLOCATED DATA CORRECTED",i,s(n),s(r.file),s(o))})},0)}})}),console.STAT&&console.STAT(o,+new Date-o,"rad check")}}};h.find(t||(r.reverse?r.end||"":r.start||""),u.find)},d=0,p={},g=String.fromCharCode(31),h.parse=function(n,r,o,a){var u;if(!n)return r();if(u=p[n])u.push(r);else{u=p[n]=[r];var y=function(){},w={file:n};(y.disk=i()).file=n,y.read=function(t,r){if(a&&(a.rpg=+new Date),console.STAT&&console.STAT(b,+new Date-b,"read disk",JSON.stringify(n),++d,"total all parses."),(y.err=t)||(y.not=!r))return delete p[n],void y.map(u,y.ack);if("string"!=typeof r){try{e.max<=r.length?y.err="Chunk too big!":r=r.toString()}catch(e){y.err=e}if(y.err)return delete p[n],void y.map(u,y.ack)}w.parsed=r.length,a&&(a.rpl=w.parsed),a&&(a.rpa=u.length),b=+new Date,e.jsonify||"{"===r[0]?f(r,function(e,t){return e?"{"===r[0]?(delete p[n],y.err="JSON error!",void y.map(u,y.ack)):void y.radec(e,r):(delete p[n],y.disk.$=t,console.STAT&&(l=+new Date-b)>9&&console.STAT(b,l,"rad parsed JSON"),a&&(a.rpd=+new Date),void y.map(u,y.ack))}):y.radec(t,r)},y.map=function(){if(u&&u.length){for(var e,t=+new Date,r=y.err,o=y.not?m:y.disk,i=0;i<9&&(e=u[i++]);)e(r,o,w);console.STAT&&console.STAT(t,+new Date-t,"rad packs",s(n)),console.STAT&&console.STAT(t,i,"rad packs #",s(n)),(u=u.slice(i)).length&&c(y.map,0)}},y.ack=function(e){e&&(y.err||y.not?e(y.err,m,w):e(m,y.disk,w))},y.radec=function(e,t){delete p[n],b=+new Date;var r,o,i,s=y.split(t),a=[];if(!s||0!==s[1])return y.err="File '"+n+"' does not have root radix! ",void y.map(u,y.ack);for(;s;)o=i=m,r=s[1],"#"==(s=y.split(s[2])||"")[0]&&(o=s[1],r<=(a=a.slice(0,r)).length&&a.push(o)),"\n"!=(s=y.split(s[2])||"")[0]&&("="!=s[0]&&":"!=s[0]||(i=s[1]),m!==o&&m!==i&&y.disk(a.join(""),i),s=y.split(s[2]));console.STAT&&console.STAT(b,+new Date-b,"parsed RAD"),y.map(u,y.ack)},y.split=function(e){if(e){var n,r,o=[],i={};if(n=e.indexOf(g),e[n])return r=e.slice(0,n),o[0]=r,o[1]=t.decode(e.slice(n),i),o[2]=e.slice(n+i.i),o}},h.disk&&(o||(o=(h.disk[n]||"").raw));var b=+new Date;if(a&&(a.rp=b),o)return c(function(){y.read(m,o)},0);e.store.get(s(n),y.read)}},function(){var t,n,r=String.fromCharCode(28);function o(n,a){if(n)return e.log("list",n),void setTimeout(function(){h.parse(r,o)},1e3);a?s(a):(t=t||a||i(),e.store.list?e.store.list(function(e){e?h.find.add(e,w):s(t)}):s(t))}function s(e,o){(t=t||e).file=r,o=n,n=null,u(o,function(e){h.find(e[0],e[1])})}h.find=function(s,a){if(!t)return n?void n.push([s,a]):(n=[[s,a]],void h.parse(r,o));i.map(h.list=t,function(e,t){if(e)return a(t)||!0},{reverse:1,end:s})||a(e.code.from)},h.find.add=function(e,n){t(e)||e===r?n(m,1):(t(e,1),n.found=(n.found||0)+1,h.write(r,t,function(e,t){e?n(e):(n.found=(n.found||0)-1,0===n.found&&n(m,1))},!0))},h.find.bad=function(e,n){t(e,0),h.write(r,t,n||w)}}();try{!o.globalThis&&n(418)(h)}catch(e){}var m,w=function(){};return t.has[e.file]=h,h}var r;r=String.fromCharCode(31),t.encode=function(e,t,n){var o=n=n||r;if("string"==typeof e){for(var i=e.indexOf(n);-1!=i;)o+=n,i=e.indexOf(n,i+1);return o+'"'+e+n}return e&&e["#"]&&1==Object.keys(e).length?o+"#"+void 0+o:"number"==typeof e?o+"+"+(e||0)+o:null===e?o+" "+o:!0===e?o+"+"+o:!1===e?o+"-"+o:void 0},t.decode=function(e,t,n){var o,i,s,a=-1,c=0;if((n=n||r)===e[0]){for(;n===e[++a];)++c;for(s=e[i=c]||!0;--c>=0;)a=e.indexOf(n,a+1);return-1==a&&(a=e.length),o=e.slice(i+1,a),t&&(t.i=a+1),'"'===s?o:"#"===s?{"#":o}:"+"===s?0===o.length||parseFloat(o):" "===s?null:"-"!==s&&void 0}};var o="undefined"!=typeof globalThis&&globalThis.Gun?globalThis.Gun:n(827),i="undefined"!=typeof globalThis&&globalThis.Radix?globalThis.Radix:n(719);t.Radix=i,((t,n)=>{try{e.exports=n}catch(e){}"undefined"!=typeof globalThis&&(globalThis[t]=globalThis[t]||n)})("Radisk",t)}()},719(e){!function(){function t(){var e=function(o,s,a){if(e.unit=0,a||n===s||(e.last=""+o<e.last?e.last:""+o,delete(e.$||{})[i]),a=a||e.$||(e.$={}),!o&&Object.keys(a).length)return a;for(var c,u,l=0,f=(o=""+o).length-1,h=o[l];!(c=a[h])&&l<f;)h+=o[++l];if(c){if(l!=f)return n!==s&&delete c[i],e(o.slice(++l),s,c||(c={}));if(n===s)return n===(u=c[""])?c:(e.unit=1)&&u;c[""]=s}else{if(!r(a,function(e,r){var i=0,c="";if((r||"").length)for(;r[i]==o[i];)c+=r[i++];if(c){if(n===s){if(i<=f)return;return(u||(u={}))[r.slice(i)]=e,e}var l={};return l[r.slice(i)]=e,""===(i=o.slice(i))?l[""]=s:(l[i]={})[""]=s,a[c]=l,t.debug&&"undefined"==""+c&&console.log(0,c),delete a[r],!0}})){if(n===s)return;(a[h]||(a[h]={}))[""]=s,t.debug&&"undefined"==""+h&&console.log(1,h)}if(n===s)return u}};return e}t.map=function e(r,s,a,c){try{c=c||[];var u="function"==typeof r?r.$||{}:r;if(!u)return;if("string"==typeof u){if(t.debug)throw["BUG:",r,s,a,c];return}var l,f=(u[i]||o).sort||(u[i]=function e(){return e.sort=Object.keys(u).sort(),e}()).sort;(l=(a=!0===a?{branch:!0}:a||{}).reverse)&&(f=f.slice(0).reverse());for(var h=a.start,d=a.end,p=0,g=f.length;p<g;p++){var y,m,w,b=f[p],v=u[b];if(v&&""!==b&&i!==b&&"undefined"!==b&&((m=c.slice(0)).push(b),w=m.join(""),!(n!==h&&w<(h||"").slice(0,w.length)||n!==d&&(d||"￿")<w))){if(l&&(y=e(v,s,a,m),n!==y))return y;if(n!==(y=v[""])){var E=1;if(n!==h&&w<(h||"")&&(E=0),n!==d&&w>(d||"￿")&&(E=0),E&&(y=s(y,w,b,c),n!==y))return y}else if(a.branch&&(y=s(n,w,b,c),n!==y))return y;if(c=m,!l&&(y=e(v,s,a,c),n!==y))return y;c.pop()}}}catch(e){console.error(e)}},function(t,n){"undefined"!=typeof globalThis&&(globalThis[t]=globalThis[t]||n);try{e.exports=n}catch(e){}}("Radix",t);var n,r=t.object=function(e,t,r){for(var o in e)if(e.hasOwnProperty(o)&&(r=t(e[o],o))!==n)return r},o={},i=String.fromCharCode(24)}()},418(e,t,n){e.exports=function(e){var t=n(719);e.find("a",function(){var n,r,o=[];t.map(e.list,function(e,t){t.indexOf("%1B")+1&&e&&o.push([t,e])}),o.length&&console.log("\n! ! ! WARNING ! ! !\nRAD v0.2020.x has detected OLD v0.2019.x data & automatically migrating. Automatic migration will be turned OFF in future versions! If you are just developing/testing, we recommend you reset your data. Please contact us if you have any concerns.\nThis message should only log once."),o.forEach(function(t){n=t[0],r=t[1],e.list(decodeURIComponent(n),r),e.list(n,0)}),n&&e.find.bad(n)})}},402(e,t,n){!function(){function t(e){(e=e||{}).file=String(e.file||"radata");var n=t[e.file],r=null;if(n)return console.log("Warning: reusing same IndexedDB store and options as 1st."),t[e.file];n=t[e.file]=function(){};try{e.indexedDB=e.indexedDB||t.indexedDB||indexedDB}catch(e){}try{if(!e.indexedDB||"file:"==location.protocol){var o=n.d||(n.d={});return n.put=function(e,t,n){o[e]=t,setTimeout(function(){n(null,1)},250)},n.get=function(e,t){setTimeout(function(){t(null,o[e]||void 0)},5)},console.log("Warning: No indexedDB exists to persist data to!"),n}}catch(e){}return n.start=function(){var t=indexedDB.open(e.file,1);t.onupgradeneeded=function(t){t.target.result.createObjectStore(e.file)},t.onsuccess=function(){r=t.result},t.onerror=function(e){console.log(e||1)}},n.start(),n.put=function(t,o,i){if(r){var s=r.transaction([e.file],"readwrite"),a=s.objectStore(e.file),c=a.put(o,""+t);c.onsuccess=a.onsuccess=s.onsuccess=function(){i(null,1)},c.onabort=a.onabort=s.onabort=function(e){i(e||"put.tx.abort")},c.onerror=a.onerror=s.onerror=function(e){i(e||"put.tx.error")}}else setTimeout(function(){n.put(t,o,i)},1)},n.get=function(t,o){if(r){var i=r.transaction([e.file],"readonly").objectStore(e.file).get(""+t);i.onsuccess=function(){o(null,i.result)},i.onabort=function(e){o(e||4)},i.onerror=function(e){o(e||5)}}else setTimeout(function(){n.get(t,o)},9)},setInterval(function(){r&&r.close(),r=null,n.start()},15e3),n}if("undefined"!=typeof globalThis)(t.globalThis=globalThis).RindexedDB=t,t.indexedDB=globalThis.indexedDB;else try{e.exports=t}catch(e){}try{(t.globalThis.Gun||n(827)).on("create",function(e){e.opt.store=e.opt.store||t(e.opt),this.to.next(e)})}catch(e){}}()},924(e,t,n){var r=n(606),o="undefined"!=typeof globalThis?globalThis.Gun:n(827);o.on("create",function(e){o.TESTING&&(e.opt.file="radatatest"),this.to.next(e);var t,i=e.opt;if(!1!==i.rad&&!1!==i.radisk&&(t+""==typeof r||"false"!=""+(r.env||"").RAD)){var s=o.globalThis&&o.globalThis.Radisk||n(617),a=s.Radix,c=s(i),u=String.fromCharCode(27);if("function"==typeof c){var l=0;e.on("put",function(t){if(this.to.next(t),!(t._||"").rad){var n=t["#"],r=t.put,o=r["#"],i=r["."],s=r[":"],a=r[">"],l=(t._||"").DBG;l&&(l.sp=l.sp||+new Date);var f=(t._||"").RPS||((t._||"").RPS=+new Date);c(o+u+i,{":":s,">":a},function(t,r){l&&(l.spd=l.spd||+new Date),console.STAT&&console.STAT(f,+new Date-f,"put"),t?e.on("in",{"@":n,err:t,DBG:l}):e.on("in",{"@":n,ok:r,DBG:l})},!1,l&&(l.r=l.r||{})),l&&(l.sps=l.sps||+new Date)}}),Object.empty,e.on("get",function(n){this.to.next(n);var r=(n._||"").DBG=n.DBG;r&&(r.sg=+new Date);var h,d,p,g,y=n["#"],m=n.get,w=n.get["#"],b=n.get["."]||"",v={};if("string"==typeof w?d=w:w&&(t!==(p=w["*"])&&(v.limit=g=1),t!==w[">"]&&(v.start=w[">"]),t!==w["<"]&&(v.end=w["<"]),d=g?""+p:p||w["="],g=null),d&&!v.limit&&("string"==typeof b?d=d+u+(v.atom=b):b&&(t!==b[">"]&&(v.start=b[">"],v.limit=1),t!==b["<"]&&(v.end=b["<"],v.limit=1),t!==(p=b["*"])&&(v.limit=g=1),d&&(d=d+u+(g?""+(p||""):p||(v.atom=b["="]||""))))),((p=m["%"])||v.limit)&&(v.limit=p<=(v.pack||1e5)?p:1),(b["-"]||(w||{})["-"]||m["-"])&&(v.reverse=!0),(p=(e.next||"")[w])&&p.put)if(v.atom){if((p=(p.next||"")[v.atom])&&p.root&&p.root.graph&&p.root.graph[w]&&p.root.graph[w][v.atom])return}else if(p&&p.rad)return;var E=o.state(),A=+new Date,x=0;function k(e,t,n,r){if(x++,e){var i=(t=(d+t).split(u)).slice(0,1)[0];if(t=t.slice(-1)[0],v.limit&&v.limit<=v.count)return!0;var a,c,l=i,f=t;if("string"!=typeof e)return a=e[":"],c=e[">"],(h=h||{})[l]=o.state.ify(h[l],f,c,a,l),void(v.count=(v.count||0)+((a||"").length||9));v.count=(v.count||0)+e.length;var p=e.lastIndexOf(">"),g=s.decode(e.slice(p+1),null,u);e=s.decode(e.slice(0,p),null,u),(h=h||{})[i]=o.state.ify(h[i],t,g,e,i)}}r&&(r.sgm=A),c(d||"",function(n,s,c){r&&(r.sgr=+new Date),r&&(r.sgi=c);try{i.store.stats.get.time[f%50]=+new Date-A,++f,i.store.stats.get.count++,n&&(i.store.stats.get.err=n)}catch(e){}var p,g;if(console.STAT&&console.STAT(A,+new Date-A,"got",JSON.stringify(d)),A=+new Date,(c=c||"").unit&&s&&t!==(p=s[":"])&&t!==(g=s[">"])){var S=d.split(u),I=S[0],C=S[1];(h=h||{})[I]=o.state.ify(h[I],C,g,p,I),e.$.get(I).get(C)._.rad=E}else s&&("string"!=typeof s&&(v.atom?s=t:a.map(s,k,v)),!h&&s&&k(s,""),!v.atom&&!b&"string"==typeof w&&!v.limit&&!v.more&&(e.$.get(w)._.rad=E));r&&(r.sgp=+new Date),console.STAT&&(l=+new Date-A)>9&&(console.STAT(A,l,"got prep time"),console.STAT(A,x,"got prep #")),x=0,A=+new Date;var O=function(){};O.faith=!0,O.rad=m,e.on("in",{"@":y,put:h,"%":c.more?1:t,err:n||t,_:O,DBG:r}),console.STAT&&(l=+new Date-A)>9&&console.STAT(A,l,"got emit",Object.keys(h||{}).length),h=t},v,r&&(r.r=r.r||{})),r&&(r.sgd=+new Date),console.STAT&&(l=+new Date-A)>9&&console.STAT(A,l,"get call")}),o.valid,(i.store||{}).stats={get:{time:{},count:0},put:{time:{},count:0}};var f=0}}})},410(e,t,n){var r="undefined"!=typeof globalThis?globalThis.Gun:n(827);r.chain.promise=function(e){var t=this;return e=e||function(e){return e},new Promise(function(e,n){t.once(function(t,n){e({put:t,get:n,gun:this})})}).then(e)},r.chain.then=function(e){var t=this,n=new Promise((e,n)=>{t.once(function(t,n){e(t,n)})});return e?n.then(e):n}},140(e,t,n){!function(){var e="undefined"!=typeof globalThis?globalThis.Gun:n(827);e.on("opt",function(t){this.to.next(t);var r=t.opt;if(!t.once&&Gun.Mesh&&!1!==r.RTCPeerConnection){var o;"undefined"!=typeof globalThis&&(o=globalThis),void 0!==n.g&&(o=n.g),o=o||{};var i=r.RTCPeerConnection||o.RTCPeerConnection||o.webkitRTCPeerConnection||o.mozRTCPeerConnection,s=r.RTCSessionDescription||o.RTCSessionDescription||o.webkitRTCSessionDescription||o.mozRTCSessionDescription,a=r.RTCIceCandidate||o.RTCIceCandidate||o.webkitRTCIceCandidate||o.mozRTCIceCandidate;if(i&&s&&a){r.RTCPeerConnection=i,r.RTCSessionDescription=s,r.RTCIceCandidate=a,r.rtc=r.rtc||{iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun.sipgate.net:3478"}]},r.rtc.dataChannel=r.rtc.dataChannel||{ordered:!1,maxRetransmits:2},r.rtc.sdp=r.rtc.sdp||{mandatory:{OfferToReceiveAudio:!1,OfferToReceiveVideo:!1}},r.rtc.max=r.rtc.max||55,r.rtc.room=r.rtc.room||e.globalThis&&(location.hash.slice(1)||location.pathname.slice(1)),r.announce=function(e){r.rtc.start=+new Date,t.$.get("/RTC/"+r.rtc.room+"<?99").get("+").put(r.pid,function(e){e.ok&&e.ok.rtc&&u(e)},{acks:r.rtc.max}).on(function(e,t,n){e===r.pid||r.rtc.start>n.put[">"]||u({"#":""+n["#"],ok:{rtc:{id:e}}})})};var c=r.mesh=r.mesh||Gun.Mesh(t);t.on("create",function(e){this.to.next(e),setTimeout(r.announce,1)})}}function u(e){if(this&&this.off&&this.off(),e.ok){var n,o,i=e.ok.rtc;if(i&&i.id&&i.id!==r.pid){if(o=i.answer){if(!(n=r.peers[i.id]||u[i.id])||n.remoteSet)return;return o.sdp=o.sdp.replace(/\\r\\n/g,"\r\n"),n.setRemoteDescription(n.remoteSet=new r.RTCSessionDescription(o))}if(o=i.candidate)return(n=r.peers[i.id]||u[i.id]||u({ok:{rtc:{id:i.id}}})).addIceCandidate(new r.RTCIceCandidate(o));if(!u[i.id]){(n=new r.RTCPeerConnection(r.rtc)).id=i.id;var s=n.wire=n.createDataChannel("dc",r.rtc.dataChannel);return u[i.id]=n,s.to=setTimeout(function(){delete u[i.id]},6e4),s.onclose=function(){c.bye(n)},s.onerror=function(e){},s.onopen=function(e){delete u[i.id],c.hi(n)},s.onmessage=function(e){e&&c.hear(e.data||e,n)},n.onicecandidate=function(n){n.candidate&&t.on("out",{"@":e["#"],ok:{rtc:{candidate:n.candidate,id:r.pid}}})},n.ondatachannel=function(e){var t=e.channel;t.onmessage=s.onmessage,t.onopen=s.onopen,t.onclose=s.onclose},(o=i.offer)?(i.offer.sdp=i.offer.sdp.replace(/\\r\\n/g,"\r\n"),n.setRemoteDescription(new r.RTCSessionDescription(o)),void n.createAnswer(function(o){n.setLocalDescription(o),t.on("out",{"@":e["#"],ok:{rtc:{answer:o,id:r.pid}}})},function(){},r.rtc.sdp)):(n.createOffer(function(o){n.setLocalDescription(o),t.on("out",{"@":e["#"],"#":t.ask(u),ok:{rtc:{offer:o,id:r.pid}}})},function(){},r.rtc.sdp),n)}}}}})}()},968(e){!function(){var t,n={},r=setTimeout.turn||typeof setImmediate!=""+t&&setImmediate||setTimeout;function o(e){var t=parseFloat(e);return isNaN(t)?"true"==(e=e.trim())||"false"!=e&&("null"==e?null:void 0):t}n.parseAsync=function(e,n,i,s){if("string"==typeof e){var a={i:0,text:e,done:n,l:e.length,up:[]};s=s||32768,function n(){for(var i,c,u=a.text,l=a.i,f=a.l,h=0,d=a.w;h++<s;){var p=u[l++];if(l>f){a.end=!0;break}if(d){for(l=u.indexOf('"',l-1),p=u[l],c=0;"\\"==u[l-++c];);c=!(c%2),i=i||c,'"'!=p||c||(d=t,c=a.s,a.a?(c=u.slice(a.sl,l),(i||1+c.indexOf("\\"))&&(c=JSON.parse('"'+c+'"')),a.at instanceof Array?a.at.push(a.s=c):(a.at||(a.end=h=s,c=t),(a.at||{})[a.s]=a.s=c),a.s=t):(a.s=u.slice(a.sl,l),(i||1+a.s.indexOf("\\"))&&(a.s=JSON.parse('"'+a.s+'"'))),a.a=i=t),++l}else switch(p){case'"':a.sl=l,d=!0;break;case":":a.ai=l,a.a=!0;break;case",":(a.a||a.at instanceof Array)&&(c=u.slice(a.ai,l-1))&&t!==(c=o(c))&&(a.at instanceof Array?a.at.push(c):a.at[a.s]=c),a.a=t,a.at instanceof Array&&(a.a=!0,a.ai=l);break;case"{":a.up.push(a.at||(a.at={})),a.at instanceof Array?a.at.push(a.at={}):t!==(c=a.s)&&(a.at[c]=a.at={}),a.a=t;break;case"}":a.a&&(c=u.slice(a.ai,l-1))&&t!==(c=o(c))&&(a.at instanceof Array?a.at.push(c):(a.at||(a.end=h=s,c=t),(a.at||{})[a.s]=c)),a.a=t,a.at=a.up.pop();break;case"[":t!==(c=a.s)?(a.up.push(a.at),a.at[c]=a.at=[]):a.at||a.up.push(a.at=[]),a.a=!0,a.ai=l;break;case"]":a.a&&(c=u.slice(a.ai,l-1))&&t!==(c=o(c))&&(a.at instanceof Array?a.at.push(c):a.at[a.s]=c),a.a=t,a.at=a.up.pop()}}if(a.s=t,a.i=l,a.w=d,a.end){if(c=a.at,t===c)try{c=JSON.parse(e)}catch(e){return a.done(e)}a.done(t,c)}else r(n)}()}else try{n(t,JSON.parse(e))}catch(e){n(e)}},n.stringifyAsync=function(e,n,o,i,s){(s=s||{}).text=s.text||"",s.up=[s.at={d:e}],s.done=n,s.i=0;var a=0;!function e(){var n,o=s.at,i=o.d,c="";switch(o.i&&o.i-o.j>0&&(c+=","),t!==(n=o.k)&&(c+=JSON.stringify(n)+":"),typeof i){case"boolean":c+=""+i;break;case"string":c+=JSON.stringify(i);break;case"number":c+=isNaN(i)?"null":i;break;case"object":if(!i){c+="null";break}if(i instanceof Array){c+="[",(o={i:-1,as:i,up:o,j:0}).l=i.length,s.up.push(s.at=o);break}if("function"!=typeof(i||"").toJSON){c+="{",(o={i:-1,ok:Object.keys(i).sort(),as:i,up:o,j:0}).l=o.ok.length,s.up.push(s.at=o);break}if(n=i.toJSON()){c+=n;break}case"function":if(o.as instanceof Array){c+="null";break}default:c="",o.j++}for(s.text+=c;1+o.i>=o.l;)s.text+=o.ok?"}":"]",o=s.at=o.up;if(++o.i<o.l)return(n=o.ok)?o.d=o.as[o.k=n[o.i]]:o.d=o.as[o.i],++a<9?e():(a=0,void r(e));s.done(t,s.text)}()},typeof globalThis!=""+t&&(globalThis.YSON=n);try{e.exports=n}catch(e){}typeof JSON!=""+t&&(JSON.parseAsync=n.parseAsync,JSON.stringifyAsync=n.stringifyAsync)}()},30(e,t,n){e=n.nmd(e);var r=n(287).hp;!function(){function t(e,r){return r?n(736)(e):e.slice?t[o(e)]:function(n,r){e(n={exports:{}}),t[o(r)]=n.exports};function o(e){return e.split("/").slice(-1).toString().replace(".js","")}}var o=e;t(function(e){e.window="undefined"!=typeof globalThis&&"undefined"==typeof window&&"undefined"!=typeof WorkerGlobalScope?globalThis:"undefined"!=typeof window?window:void 0;var t=(e.window||e).SEA||{};(t.window=e.window)&&(t.window.SEA=t);try{void 0+""!=typeof o&&(o.exports=t)}catch(e){}e.exports=t})(t,"./root"),t(function(e){var n=t("./root");try{n.window&&location.protocol.indexOf("s")<0&&location.host.indexOf("localhost")<0&&!/^127\.\d+\.\d+\.\d+$/.test(location.hostname)&&location.protocol.indexOf("blob:")<0&&location.protocol.indexOf("file:")<0&&"null"!=location.origin&&(console.warn("HTTPS needed for WebCrypto in SEA, redirecting..."),location.protocol="https:")}catch(e){}})(t,"./https"),t(function(e){var o,i="undefined"!=typeof globalThis?globalThis:void 0!==n.g?n.g:"undefined"!=typeof window?window:this,s={};if(s.btoa=o+""!=typeof i.btoa&&i.btoa,s.atob=o+""!=typeof i.atob&&i.atob,o+""==typeof r)try{i.Buffer=t("buffer",1).Buffer}catch(e){console.log("Please `npm install buffer` or add it to your package.json !")}if(o+""!=typeof r)return i.btoa=function(e){return r.from(e,"binary").toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},void(i.atob=function(e){for(var t=e.replace(/-/g,"+").replace(/_/g,"/");t.length%4;)t+="=";return r.from(t,"base64").toString("binary")});s.btoa&&(i.btoa=function(e){return s.btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}),s.atob&&(i.atob=function(e){for(var t=e.replace(/-/g,"+").replace(/_/g,"/");t.length%4;)t+="=";return s.atob(t)})})(t,"./base64"),t(function(e){function n(){}t("./base64"),Object.assign(n,{from:Array.from}),n.prototype=Object.create(Array.prototype),n.prototype.toString=function(e,t,n){e=e||"utf8",t=t||0;const r=this.length;if("hex"===e){const e=new Uint8Array(this);return[...Array((n&&n+1||r)-t).keys()].map(n=>e[n+t].toString(16).padStart(2,"0")).join("")}return"utf8"===e?Array.from({length:(n||r)-t},(e,n)=>String.fromCharCode(this[n+t])).join(""):"base64"===e?btoa(this):void 0},e.exports=n})(t,"./array"),t(function(e){t("./base64");var n=t("./array");function r(...e){return console.warn("new SafeBuffer() is depreciated, please use SafeBuffer.from()"),r.from(...e)}r.prototype=Object.create(Array.prototype),Object.assign(r,{from(){if(!Object.keys(arguments).length||null==arguments[0])throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.");const e=arguments[0];let t;if("string"==typeof e){const r=arguments[1]||"utf8";if("hex"===r){const r=e.match(/([\da-fA-F]{2})/g).map(e=>parseInt(e,16));if(!r||!r.length)throw new TypeError("Invalid first argument for type 'hex'.");t=n.from(r)}else if("utf8"===r||"binary"===r){const r=e.length,o=new Uint16Array(r);Array.from({length:r},(t,n)=>o[n]=e.charCodeAt(n)),t=n.from(o)}else if("base64"===r){const r=atob(e),o=r.length,i=new Uint8Array(o);Array.from({length:o},(e,t)=>i[t]=r.charCodeAt(t)),t=n.from(i)}else"binary"===r?t=n.from(e):console.info("SafeBuffer.from unknown encoding: "+r);return t}if(e.byteLength,e.byteLength?e.byteLength:e.length){let t;return e instanceof ArrayBuffer&&(t=new Uint8Array(e)),n.from(t||e)}},alloc:(e,t=0)=>n.from(new Uint8Array(Array.from({length:e},()=>t))),allocUnsafe:e=>n.from(new Uint8Array(Array.from({length:e}))),concat(e){if(!Array.isArray(e))throw new TypeError("First argument must be Array containing ArrayBuffer or Uint8Array instances.");return n.from(e.reduce((e,t)=>e.concat(Array.from(t)),[]))}}),r.prototype.from=r.from,r.prototype.toString=n.prototype.toString,e.exports=r})(t,"./buffer"),t(function(e){const n=t("./root"),r={Buffer:t("./buffer")};var i={};if(JSON.parseAsync=JSON.parseAsync||function(e,t,n){try{t(void 0,JSON.parse(e,n))}catch(e){t(e)}},JSON.stringifyAsync=JSON.stringifyAsync||function(e,t,n,r){try{t(void 0,JSON.stringify(e,n,r))}catch(e){t(e)}},r.parse=function(e,t){return new Promise(function(n,r){JSON.parseAsync(e,function(e,t){e?r(e):n(t)},t)})},r.stringify=function(e,t,n){return new Promise(function(r,o){JSON.stringifyAsync(e,function(e,t){e?o(e):r(t)},t,n)})},n.window&&(r.crypto=n.window.crypto||n.window.msCrypto,r.subtle=(r.crypto||i).subtle||(r.crypto||i).webkitSubtle,r.TextEncoder=n.window.TextEncoder,r.TextDecoder=n.window.TextDecoder,r.random=e=>r.Buffer.from(r.crypto.getRandomValues(new Uint8Array(r.Buffer.alloc(e))))),!r.TextDecoder){const{TextEncoder:e,TextDecoder:n}=t((void 0+""==typeof o?".":"")+"./lib/text-encoding",1);r.TextDecoder=n,r.TextEncoder=e}if(!r.crypto)try{var s=t("crypto",1);Object.assign(r,{crypto:s,random:e=>r.Buffer.from(s.randomBytes(e))});const{Crypto:e}=t("@peculiar/webcrypto",1);r.ossl=r.subtle=new e({directory:"ossl"}).subtle}catch(e){console.log("Please `npm install @peculiar/webcrypto` or add it to your package.json !")}e.exports=r})(t,"./shim"),t(function(e){for(var n=t("./root"),r=t("./shim"),o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",i={},s=0;s<62;s++)i[o[s]]=s;function a(e){if("bigint"!=typeof e||e<0n)throw new Error("biToB62: input must be non-negative BigInt");for(var t="",n=e;n>0n;)t=o[Number(n%62n)]+t,n/=62n;for(;t.length<44;)t="0"+t;if(t.length>44)throw new Error("biToB62: value too large for 44-char base62");return t}function c(e){if("string"!=typeof e||44!==e.length)throw new Error("b62ToBI: expected 44-char base62 string, got "+(e&&e.length));if(!/^[A-Za-z0-9]+$/.test(e))throw new Error("b62ToBI: invalid base62 characters");for(var t=0n,n=0;n<e.length;n++){var r=i[e[n]];if(void 0===r)throw new Error("b62ToBI: unknown char "+e[n]);t=62n*t+BigInt(r)}return t}function u(e){var t=c(e).toString(16).padStart(64,"0");return r.Buffer.from(t,"hex").toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var l={biToB62:a,b62ToBI:c,b64ToB62:function(e){if("string"!=typeof e||!e)throw new Error("b64ToB62: input must be non-empty string");var t=r.Buffer.from(atob(e),"binary").toString("hex");return a(BigInt("0x"+(t||"0")))},b62ToB64:u,pubToJwkXY:function(e){if("string"!=typeof e)throw new Error("pubToJwkXY: pub must be a string");if(87===e.length&&"."===e[43]){var t=e.split(".");if(2!==t.length)throw new Error("pubToJwkXY: invalid old pub format");return{x:t[0],y:t[1]}}if(88===e.length&&/^[A-Za-z0-9]{88}$/.test(e))return{x:u(e.slice(0,44)),y:u(e.slice(44))};throw new Error("pubToJwkXY: unrecognised pub format (length="+e.length+")")},bufToB62:function(e){for(var t="",n=0;n<e.length;n+=32){for(var r=Math.min(n+32,e.length),o="",i=0;i<32-(r-n);i++)o+="00";for(var s=n;s<r;s++)o+=("0"+e[s].toString(16)).slice(-2);t+=a(BigInt("0x"+o))}return t},PUB_LEN:44};n.base62=l,e.exports=l})(t,"./base62"),t(function(e){var n=t("./root"),r=t("./shim"),o=n.base62,i={pbkdf2:{hash:{name:"SHA-256"},iter:1e5,ks:64},ecdsa:{pair:{name:"ECDSA",namedCurve:"P-256"},sign:{name:"ECDSA",hash:{name:"SHA-256"}}},ecdh:{name:"ECDH",namedCurve:"P-256"},jwk:function(e,t){var n=o.pubToJwkXY(e),r={kty:"EC",crv:"P-256",x:n.x,y:n.y,ext:!0};return r.key_ops=t?["sign"]:["verify"],t&&(r.d=44===t.length&&/^[A-Za-z0-9]{44}$/.test(t)?o.b62ToB64(t):t),r},keyToJwk:function(e){return{kty:"oct",k:e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,""),ext:!1,alg:"A256GCM"}},recall:{validity:43200,hook:function(e){return e}},check:function(e){return"string"==typeof e&&"SEA{"===e.slice(0,4)},parse:async function(e){try{var t="string"==typeof e;return t&&"SEA{"===e.slice(0,4)&&(e=e.slice(3)),t?await r.parse(e):e}catch(e){}return e}};n.opt=i,e.exports=i})(t,"./settings"),t(function(e){var n=t("./shim");e.exports=async function(e,t){var r="string"==typeof e?e:await n.stringify(e),o=await n.subtle.digest({name:t||"SHA-256"},(new n.TextEncoder).encode(r));return n.Buffer.from(o)}})(t,"./sha256"),t(function(e){const n=t("./shim"),r=n.subtle,o=n.ossl?n.ossl:r;e.exports=e=>o.digest({name:"SHA-1"},new ArrayBuffer(e))})(t,"./sha1"),t(function(e){var n=t("./root"),r=t("./shim"),o=t("./settings"),i=t("./sha256");n.work=n.work||(async(e,t,s,a)=>{try{var c=(t||{}).epub||t,u=(a=a||{}).encode||"base62",l=n.base62;if(c instanceof Function&&(s=c,c=void 0),e instanceof ArrayBuffer&&(e=new Uint8Array(e),e=new r.TextDecoder("utf-8").decode(e)),e="string"==typeof e?e:await r.stringify(e),"sha"===(a.name||"").toLowerCase().slice(0,3)){var f=r.Buffer.from(await i(e,a.name),"binary");if(f="base62"===u?l.bufToB62(f):"base64"===u?btoa(String.fromCharCode(...new Uint8Array(f))):f.toString(u),s)try{s(f)}catch(e){console.log(e)}return f}"number"==typeof c&&(c=c.toString()),"number"==typeof a.salt&&(a.salt=a.salt.toString()),c=c||r.random(9);var h=await(r.ossl||r.subtle).importKey("raw",(new r.TextEncoder).encode(e),{name:a.name||"PBKDF2"},!1,["deriveBits"]),d=await(r.ossl||r.subtle).deriveBits({name:a.name||"PBKDF2",iterations:a.iterations||o.pbkdf2.iter,salt:(new r.TextEncoder).encode(a.salt||c),hash:a.hash||o.pbkdf2.hash},h,a.length||8*o.pbkdf2.ks);e=r.random(e.length);var p=r.Buffer.from(d,"binary");if(p="base62"===u?l.bufToB62(p):"base64"===u?btoa(String.fromCharCode(...new Uint8Array(p))):p.toString(u),s)try{s(p)}catch(e){console.log(e)}return p}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(s&&s())}}),e.exports=n.work})(t,"./work"),t(function(e){var n=t("./root"),r=t("./shim"),o=n.base62;const i=BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),s=BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),a=BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),c=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),u={x:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),y:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")};function l(e,t){return(e%t+t)%t}function f(e,t){return function(e,t,n){if(n===BigInt(1))return BigInt(0);e=l(e,n);let r=BigInt(1),o=t;for(;o>BigInt(0);){const t=o&BigInt(1),i=l(r*e,n);r=t?i:r,o>>=BigInt(1),e=l(e*e,n)}return r}(e,t-BigInt(2),t)}function h(e){if(!e)return!1;const{x:t,y:n}=e;return l(n*n,s)===l(l(l(t*t,s)*t,s)+l(a*t,s)+c,s)}function d(e,t){if(null===e)return t;if(null===t)return e;if(e.x===t.x&&0n===l(e.y+t.y,s))return null;let n=e.x===t.x&&e.y===t.y?l((3n*l(e.x**2n,s)+a)*f(2n*e.y,s),s):l(l(t.y-e.y,s)*f(l(t.x-e.x,s),s),s);const r=l(n**2n-e.x-t.x,s);return{x:r,y:l(n*l(e.x-r,s)-e.y,s)}}function p(e,t){let n=null,r=t;for(let t=0;t<256;t++){const o=e>>BigInt(t)&1n,i=d(n,r);n=o?i:n,r=d(r,r)}return n}n.pair=n.pair||(async(e,t)=>{try{t=t||{};const n=r.subtle,a=r.ossl||n;let c={};const f=e=>{if("string"!=typeof e||0===e.length)throw new Error("Invalid base64 input: must be non-empty string");if(!/^[A-Za-z0-9_-]*={0,2}$/.test(e))throw new Error("Invalid base64 characters detected");try{const t=r.Buffer.from(atob(e),"binary").toString("hex");if(t.length>64)throw new Error("Decoded value exceeds 256 bits for P-256");return BigInt("0x"+t)}catch(e){if(e.message.includes("256 bits"))throw e;throw new Error("Invalid base64 decoding: "+e.message)}},g=e=>"string"==typeof e&&44===e.length&&/^[A-Za-z0-9]{44}$/.test(e)?o.b62ToBI(e):f(e),y=(e,t)=>{if(e<=0n||e>=i)throw new Error((t||"Private key")+" out of range");return e},m=e=>{y(e,"Private key");const t=p(e,u);if(!h(t))throw new Error("Invalid point generated");return o.biToB62(t.x)+o.biToB62(t.y)},w=e=>{if(!e||"string"!=typeof e)throw new Error("Invalid pub format: must be string");const t=o.pubToJwkXY(e),n={x:f(t.x),y:f(t.y)};if(n.x>=s||n.y>=s)throw new Error("Invalid public key: out of range");if(!h(n))throw new Error("Invalid public key: not on curve");return n},b=e=>{if(!e||!h(e))throw new Error("Invalid point: not on curve");return o.biToB62(e.x)+o.biToB62(e.y)},v=e=>{const t=new r.TextEncoder;return"string"==typeof e?t.encode(e).buffer:e instanceof ArrayBuffer?e:e&&void 0!==e.byteLength?e.buffer||e:null},E=async(e,t)=>{const o=new r.TextEncoder,s=v(e);if(!s)throw new Error("Invalid seed");const a=new Uint8Array(s.byteLength+o.encode(t).buffer.byteLength);a.set(new Uint8Array(s),0),a.set(new Uint8Array(o.encode(t).buffer),s.byteLength);let c=await n.digest("SHA-256",a.buffer),u=0;for(;u<100;){let e=BigInt("0x"+Array.from(new Uint8Array(c)).map(e=>e.toString(16).padStart(2,"0")).join(""));if(e>0n&&e<i)return e;const t=new Uint8Array(4);new DataView(t.buffer).setUint32(0,u,!0);const r=new Uint8Array(c.byteLength+t.byteLength);r.set(new Uint8Array(c),0),r.set(t,c.byteLength),c=await n.digest("SHA-256",r.buffer),u++}throw new Error("Failed to generate valid private key after 100 attempts")},A=async(e,t,o)=>{const s=new r.TextEncoder,a=v(e);if(!a)throw new Error("Invalid seed");const c=null!=o?t+o:t,u=s.encode(c).buffer,l=new Uint8Array(a.byteLength+u.byteLength);l.set(new Uint8Array(u),0),l.set(new Uint8Array(a),u.byteLength);let f=await n.digest("SHA-256",l.buffer),h=0;for(;h<100;){const e=BigInt("0x"+Array.from(new Uint8Array(f)).map(e=>e.toString(16).padStart(2,"0")).join(""));if(e>0n&&e<i)return e;const t=new Uint8Array(4);new DataView(t.buffer).setUint32(0,h,!0);const r=new Uint8Array(f.byteLength+t.byteLength);r.set(new Uint8Array(f),0),r.set(t,f.byteLength),f=await n.digest("SHA-256",r.buffer),h++}throw new Error("Failed to derive scalar after 100 attempts")},x=async(e,t,n)=>A(e,t,0===n?null:n),k=async(e,n)=>{for(let r=0;r<100;r++){const o=l(e+await x(t.seed,n,r),i);if(0n!==o)return{derivedPriv:o,attempt:r}}throw new Error("Failed to derive non-zero private key")},S=async(e,n)=>{for(let r=0;r<100;r++){const o=d(e,p(await x(t.seed,n,r),u));if(o)return o}throw new Error("Failed to derive valid public key")};if(t.seed&&(t.priv||t.epriv||t.pub||t.epub)){if(c={},t.priv){const e=y(g(t.priv),"Private key"),n=(await k(e,"SEA.DERIVE|sign|")).derivedPriv,r=p(n,u);c.priv=o.biToB62(n),c.pub=b(r)}if(t.epriv){const e=y(g(t.epriv),"Encryption private key"),n=(await k(e,"SEA.DERIVE|encrypt|")).derivedPriv,r=p(n,u);c.epriv=o.biToB62(n),c.epub=b(r)}if(t.pub){const e=w(t.pub),n=await S(e,"SEA.DERIVE|sign|");c.pub=b(n)}if(t.epub){const e=w(t.epub),n=await S(e,"SEA.DERIVE|encrypt|");c.epub=b(n)}}else if(t.priv){const e=y(g(t.priv),"Private key");if(c={priv:t.priv,pub:m(e)},t.epriv){const e=y(g(t.epriv),"Encryption private key");c.epriv=t.epriv,c.epub=m(e)}else try{const e=await a.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"]).then(async e=>({epriv:o.b64ToB62((await a.exportKey("jwk",e.privateKey)).d),epub:o.b64ToB62((await a.exportKey("jwk",e.publicKey)).x)+o.b64ToB62((await a.exportKey("jwk",e.publicKey)).y)}));c.epriv=e.epriv,c.epub=e.epub}catch(e){}}else if(t.epriv){const e=y(g(t.epriv),"Encryption private key");if(c={epriv:t.epriv,epub:m(e)},t.priv){const e=y(g(t.priv),"Private key");c.priv=t.priv,c.pub=m(e)}else{const e=await n.generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign","verify"]).then(async e=>({priv:o.b64ToB62((await n.exportKey("jwk",e.privateKey)).d),pub:o.b64ToB62((await n.exportKey("jwk",e.publicKey)).x)+o.b64ToB62((await n.exportKey("jwk",e.publicKey)).y)}));c.priv=e.priv,c.pub=e.pub}}else if(t.seed){const e=await E(t.seed,"-sign"),n=await E(t.seed,"-encrypt");c={priv:o.biToB62(e),pub:m(e),epriv:o.biToB62(n),epub:m(n)}}else{const e=await n.generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign","verify"]).then(async e=>({priv:o.b64ToB62((await n.exportKey("jwk",e.privateKey)).d),pub:o.b64ToB62((await n.exportKey("jwk",e.publicKey)).x)+o.b64ToB62((await n.exportKey("jwk",e.publicKey)).y)}));c={pub:e.pub,priv:e.priv};try{const e=await a.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"]).then(async e=>({epriv:o.b64ToB62((await a.exportKey("jwk",e.privateKey)).d),epub:o.b64ToB62((await a.exportKey("jwk",e.publicKey)).x)+o.b64ToB62((await a.exportKey("jwk",e.publicKey)).y)}));c.epub=e.epub,c.epriv=e.epriv}catch(e){}}if(e)try{e(c)}catch(e){}return c}catch(t){if(n.err=t,n.throw)throw t;if(e)try{e()}catch(e){}throw new Error("Key generation failed: "+(t.message||"Unknown error"))}}),e.exports=n.pair})(t,"./pair"),t(function(e){var n,r=t("./root"),o=t("./shim"),i=t("./settings"),s=t("./sha256");async function a(e,t,n){try{if(t.raw||(e="SEA"+await o.stringify(e)),n)try{n(e)}catch(e){}return e}catch(t){return e}}r.sign=r.sign||(async(e,t,c,u)=>{try{if(u=u||{},n===e)throw"`undefined` not allowed.";if(!(t||u).priv&&"function"!=typeof t){if(!r.I)throw"No signing key.";t=await r.I(null,{what:e,how:"sign",why:u.why})}var l=await i.parse(e),f=u.check=u.check||l;if(r.verify&&(i.check(f)||f&&f.s&&f.m)&&n!==await r.verify(f,t))return a(await i.parse(f),u,c);if("function"==typeof t){var h=await t(e);return h.authenticatorData?async function(e,t,r,i){var s={m:t,s:e.signature?o.Buffer.from(e.signature,"binary").toString(r.encode||"base64"):n,a:o.Buffer.from(e.authenticatorData,"binary").toString("base64"),c:o.Buffer.from(e.clientDataJSON,"binary").toString("base64")};if(!s.s||!s.a||!s.c)throw"WebAuthn signature invalid";return a(s,r,i)}(h,l,u,c):a({m:l,s:"string"==typeof h?h:h.signature&&o.Buffer.from(h.signature,"binary").toString(u.encode||"base64")},u,c)}return async function(e,t,n,r){var c=i.jwk(e.pub,e.priv);if(!c)throw"Invalid key pair";var u=await s(t),l=await(o.ossl||o.subtle).importKey("jwk",c,i.ecdsa.pair,!1,["sign"]).then(e=>(o.ossl||o.subtle).sign(i.ecdsa.sign,e,new Uint8Array(u))).catch(()=>{throw"SEA signature failed"});return a({m:t,s:o.Buffer.from(l,"binary").toString(n.encode||"base64")},n,r)}(t,l,u,c)}catch(e){if(r.err=e,r.throw)throw e;return void(c&&c())}}),e.exports=r.sign})(t,"./sign"),t(function(e){var n=t("./root"),r=t("./shim"),o=t("./settings"),i=t("./sha256"),s=n.base62;n.verify=n.verify||(async(e,t,a,c)=>{try{var u=await o.parse(e);if(!1===t)return a?a(await o.parse(u.m)):await o.parse(u.m);c=c||{};var l=t.pub||t,f=s.pubToJwkXY(l),h=f.x,d=f.y;try{var p=await(r.ossl||r.subtle).importKey("jwk",{kty:"EC",crv:"P-256",x:h,y:d,ext:!0,key_ops:["verify"]},{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]),g=await i(u.m),y=new Uint8Array(r.Buffer.from(u.s||"",c.encode||"base64")),m=u.a&&u.c?await async function(e,t,n){var o=new Uint8Array(r.Buffer.from(e.a,"base64")),i=r.Buffer.from(e.c,"base64").toString("utf8"),s=(new TextEncoder).encode(e.m),a=btoa(String.fromCharCode(...new Uint8Array(s))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");if(JSON.parse(i).challenge!==a)throw"Challenge verification failed";var c=await(r.ossl||r.subtle).digest({name:"SHA-256"},(new TextEncoder).encode(i)),u=new Uint8Array(o.length+c.byteLength);if(u.set(o),u.set(new Uint8Array(c),o.length),48!==n[0])throw"Invalid DER signature format";for(var l=2,f=new Uint8Array(64),h=0;h<2;h++){var d=n[l+1];0===n[l+=2]&&(l++,d--);var p=new Uint8Array(32).fill(0);p.set(n.slice(l,l+d),32-d),f.set(p,32*h),l+=d}return(r.ossl||r.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},t,f,u)}(u,p,y):await async function(e,t,n,o){return(r.ossl||r.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},t,n,new Uint8Array(o))}(0,p,y,g);if(!m)throw"Signature did not match";var w=await o.parse(u.m);if("string"==typeof u.m&&u.m.startsWith("SEA{")){if(a)try{a(u.m)}catch(e){}return u.m}if(w&&"object"==typeof w&&"string"==typeof w.ct&&"string"==typeof w.iv&&"string"==typeof w.s){var b="SEA"+JSON.stringify(w);if(a)try{a(b)}catch(e){}return b}if(a)try{a(w)}catch(e){}return w}catch(r){return n.opt.fallback?await n.opt.fall_verify(e,t,a,c):void(a&&a())}}catch(e){if(n.err=e,n.throw)throw e;return void(a&&a())}}),e.exports=n.verify;var a={};n.opt.slow_leak=e=>{if(a[e])return a[e];var t=o.jwk(e);return a[e]=(r.ossl||r.subtle).importKey("jwk",t,{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]),a[e]},n.opt.fall_verify=async function(e,t,s,a,c){if(c===n.opt.fallback)throw"Signature did not match";var u=e||"";e=n.opt.unpack(e)||e;var l=await o.parse(e),f=await n.opt.slow_leak(t.pub||t),h=!c||c<=n.opt.fallback?r.Buffer.from(await r.subtle.digest({name:"SHA-256"},(new r.TextEncoder).encode(await o.parse(l.m)))):await i(l.m);try{var d=r.Buffer.from(l.s,a.encode||"base64"),p=new Uint8Array(d),g=await(r.ossl||r.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},f,p,new Uint8Array(h));if(!g)throw""}catch(e){try{if(d=r.Buffer.from(l.s,"utf8"),p=new Uint8Array(d),!(g=await(r.ossl||r.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},f,p,new Uint8Array(h))))throw""}catch(e){throw"Signature did not match."}}var y=g?await o.parse(l.m):void 0;if(n.opt.fall_soul=u["#"],n.opt.fall_key=u["."],n.opt.fall_val=e,n.opt.fall_state=u[">"],s)try{s(y)}catch(e){console.log(e)}return y},n.opt.fallback=2})(t,"./verify"),t(function(e){var n=t("./shim"),r=t("./settings"),o=t("./sha256");e.exports=async(e,t,i)=>{i=i||{};const s=e+(t||n.random(8)).toString("utf8"),a=n.Buffer.from(await o(s),"binary"),c=r.keyToJwk(a);return await n.subtle.importKey("jwk",c,{name:"AES-GCM"},!1,["encrypt","decrypt"])}})(t,"./aeskey"),t(function(e){var n=t("./root"),r=t("./shim"),o=(t("./settings"),t("./aeskey"));n.encrypt=n.encrypt||(async(e,t,i,s)=>{try{s=s||{};var a=(t||s).epriv||t;if(void 0===e)throw"`undefined` not allowed.";if(!a){if(!n.I)throw"No encryption key.";a=(t=await n.I(null,{what:e,how:"encrypt",why:s.why})).epriv||t}var c="string"==typeof e?e:await r.stringify(e),u={s:r.random(9),iv:r.random(15)},l=await o(a,u.s,s).then(e=>r.subtle.encrypt({name:s.name||"AES-GCM",iv:new Uint8Array(u.iv)},e,(new r.TextEncoder).encode(c))),f={ct:r.Buffer.from(l,"binary").toString(s.encode||"base64"),iv:u.iv.toString(s.encode||"base64"),s:u.s.toString(s.encode||"base64")};if(s.raw||(f="SEA"+await r.stringify(f)),i)try{i(f)}catch(e){console.log(e)}return f}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(i&&i())}}),e.exports=n.encrypt})(t,"./encrypt"),t(function(e){var n=t("./root"),r=t("./shim"),o=t("./settings"),i=t("./aeskey");n.decrypt=n.decrypt||(async(e,t,s,a)=>{try{a=a||{};var c=(t||a).epriv||t;if(!c){if(!n.I)throw"No decryption key.";c=(t=await n.I(null,{what:e,how:"decrypt",why:a.why})).epriv||t}var u,l,f,h=await o.parse(e);try{u=r.Buffer.from(h.s,a.encode||"base64"),l=r.Buffer.from(h.iv,a.encode||"base64"),f=r.Buffer.from(h.ct,a.encode||"base64");var d=await i(c,u,a).then(e=>r.subtle.decrypt({name:a.name||"AES-GCM",iv:new Uint8Array(l),tagLength:128},e,new Uint8Array(f)))}catch(r){if("utf8"===a.encode)throw"Could not decrypt";if(n.opt.fallback)return a.encode="utf8",await n.decrypt(e,t,s,a)}var p=await o.parse(new r.TextDecoder("utf8").decode(d));if(s)try{s(p)}catch(e){console.log(e)}return p}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(s&&s())}}),e.exports=n.decrypt})(t,"./decrypt"),t(function(e){var n=t("./root"),r=t("./shim"),o=(t("./settings"),n.base62);n.secret=n.secret||(async(e,t,o,s)=>{try{if(s=s||{},!t||!t.epriv||!t.epub){if(!n.I)throw"No secret mix.";t=await n.I(null,{what:e,how:"secret",why:s.why})}var a=e.epub||e,c=t.epub,u=t.epriv,l=r.ossl||r.subtle,f=i(a),h=Object.assign({public:await l.importKey(...f,!0,[])},{name:"ECDH",namedCurve:"P-256"}),d=i(c,u),p=await l.importKey(...d,!1,["deriveBits"]).then(async e=>{var t=await l.deriveBits(h,e,256),n=new Uint8Array(t),r=await l.importKey("raw",n,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]);return l.exportKey("jwk",r).then(({k:e})=>e)});if(o)try{o(p)}catch(e){console.log(e)}return p}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(o&&o())}});var i=(e,t)=>{var n=o.pubToJwkXY(e),r=n.x,i=n.y,s=t?44===t.length&&/^[A-Za-z0-9]{44}$/.test(t)?o.b62ToB64(t):t:void 0,a=s?{d:s}:{};return["jwk",Object.assign(a,{x:r,y:i,kty:"EC",crv:"P-256",ext:!0}),{name:"ECDH",namedCurve:"P-256"}]};e.exports=n.secret})(t,"./secret"),t(function(e){var n=t("./root");n.certify=n.certify||(async(e,t={},r,o,i={})=>{try{if(e=(()=>{var t=[];if(e){if(("string"==typeof e||Array.isArray(e))&&e.indexOf("*")>-1)return"*";if("string"==typeof e)return e;if(Array.isArray(e)){if(1===e.length&&e[0])return"object"==typeof e[0]&&e[0].pub?e[0].pub:"string"==typeof e[0]?e[0]:null;e.map(e=>{"string"==typeof e?t.push(e):"object"==typeof e&&e.pub&&t.push(e.pub)})}return"object"==typeof e&&e.pub?e.pub:t.length>0?t:null}})(),!e)return console.log("No certificant found.");const a=!i.expiry||"number"!=typeof i.expiry&&"string"!=typeof i.expiry?null:parseFloat(i.expiry),c=(t||{}).read?t.read:null,u=(t||{}).write?t.write:"string"==typeof t||Array.isArray(t)||t["+"]||t["#"]||t["."]||t["="]||t["*"]||t[">"]||t["<"]?t:null,l=(i||{}).block||(i||{}).blacklist||(i||{}).ban||{},f=l.read&&("string"==typeof l.read||(l.read||{})["#"])?l.read:null,h="string"==typeof l?l:l.write&&("string"==typeof l.write||l.write["#"])?l.write:null;if(!c&&!u)return console.log("No policy found.");const d=JSON.stringify({c:e,...a?{e:a}:{},...c?{r:c}:{},...u?{w:u}:{},...f?{rb:f}:{},...h?{wb:h}:{}});var s=await n.sign(d,r,null,{raw:1});if(i.raw||(s="SEA"+JSON.stringify(s)),o)try{o(s)}catch(e){console.log(e)}return s}catch(e){if(n.err=e,n.throw)throw e;return void(o&&o())}}),e.exports=n.certify})(t,"./certify"),t(function(e){var n=t("./shim"),r=t("./sha1"),o=t("./root");o.work=t("./work"),o.sign=t("./sign"),o.verify=t("./verify"),o.encrypt=t("./encrypt"),o.decrypt=t("./decrypt"),o.certify=t("./certify"),o.random=o.random||n.random,o.Buffer=o.Buffer||t("./buffer"),o.keyid=o.keyid||(async e=>{try{var t=o.base62.pubToJwkXY(e);const i=n.Buffer.concat([t.x,t.y].map(e=>n.Buffer.from(atob(e.replace(/-/g,"+").replace(/_/g,"/")),"binary"))),s=n.Buffer.concat([n.Buffer.from([153,i.length/256,i.length%256]),i]),a=await r(s),c=n.Buffer.from(a,"binary");return c.toString("hex",c.length-8)}catch(e){throw console.log(e),e}}),((o.window||{}).GUN||{}).SEA=o,e.exports=o})(t,"./sea"),t(function(e){var n,r=t("./sea");function i(e){this._={$:this}}function s(){return n.state().toString(36).replace(".","")}n=r.window?r.window.GUN||{chain:{}}:t((void 0+""==typeof o?".":"")+"./gun",1),r.GUN=n,i.prototype=function(){function e(){}return e.prototype=n.chain,new e}(),i.prototype.constructor=i,n.chain.user=function(e){var t,n=this.back(-1);if(e)return e=r.opt.pub((e._||"")["#"])||e,n.get("~"+e);if(t=n.back("user"))return t;var o=n=n._,a=o.opt.uuid||s;return(o=(t=o.user=this.chain(new i))._).opt={},o.opt.uuid=function(e){var t=a(),r=n.user;return r&&(r=r.is)&&(r=r.pub)?(t="~"+r+"/"+t,e&&e.call&&e(null,t),t):t},t},n.User=i,i.GUN=n,i.SEA=n.SEA=r,e.exports=i})(t,"./user"),t(function(e){var n;(""+n!=typeof GUN?GUN||{chain:{}}:t((""+n==typeof o?".":"")+"./gun",1)).chain.then=function(e,t){var n=this,r=new Promise(function(e,r){n.once(e,t)});return e?r.then(e):r}})(t,"./then"),t(function(e){var n=t("./user"),r=n.SEA,o=n.GUN,i=function(){};n.prototype.create=function(...e){var t,n="object"==typeof e[0]&&(e[0].pub||e[0].epub)?e[0]:"object"==typeof e[1]&&(e[1].pub||e[1].epub)?e[1]:null,s=n&&(n.pub||n.epub)?n.pub:"string"==typeof e[0]?e[0]:null,a=n&&(n.pub||n.epub)?n:s&&"string"==typeof e[1]?e[1]:null,c=e.filter(e=>"function"==typeof e)[0]||null,u=e&&e.length>1&&"object"==typeof e[e.length-1]?e[e.length-1]:{},l=this,f=l._,h=l.back(-1);if(c=c||i,!1!==(u=u||{}).check&&(s||(t="No user."),(a||"").length<8&&(t="Password too short!"),t))return c({err:o.log(t)}),l;if(f.ing)return(c||i)({err:o.log("User is already being created or authenticated!"),wait:!0}),l;f.ing=!0;var d={a:function(e){if(d.pubs=e,e&&!u.already){var t={err:o.log("User already created!")};return f.ing=!1,(c||i)(t),void l.leave()}d.salt=String.random(64),r.work(a,d.salt,d.b)},b:function(e){d.proof=e,n?d.c(n):r.pair(d.c)},c:function(e){var t;d.pair=e||{},(t=f.root.user)&&(t._.sea=e,t.is={pub:e.pub,epub:e.epub,alias:s}),d.data={pub:e.pub},d.d()},d:function(){d.data.alias=s,d.e()},e:function(){d.data.epub=d.pair.epub,r.encrypt({priv:d.pair.priv,epriv:d.pair.epriv},d.proof,d.f,{raw:1})},f:function(e){d.data.auth=JSON.stringify({ek:e,s:d.salt}),d.g(d.data.auth)},g:function(e){var t;d.data.auth=d.data.auth||e,h.get(t="~"+d.pair.pub).put(d.data).on(d.h);var n={};n[t]={"#":t},h.get("~@"+s).put(n).get(t).on(d.i)},h:function(e,t,n,r){r.off(),d.h.ok=1,d.i()},i:function(e,t,r,o){o&&(d.i.ok=1,o.off()),d.h.ok&&d.i.ok&&(f.ing=!1,c({ok:0,pub:d.pair.pub}),i===c&&(n?l.auth(n):l.auth(s,a)))}};return h.get("~@"+s).once(d.a),l},n.prototype.leave=function(e,t){var n=this.back(-1)._.user;if(n&&(delete n.is,delete n._.is,delete n._.sea),r.window)try{var o={};delete(o=r.window.sessionStorage).recall,delete o.pair}catch(e){}return this}})(t,"./create"),t(function(e){var n=t("./user"),r=n.SEA,o=n.GUN,i=function(){};function s(e){if("string"!=typeof e)return e;try{e=JSON.parse(e)}catch(t){e={}}return e}n.prototype.auth=function(...e){var t="object"==typeof e[0]&&(e[0].pub||e[0].epub)?e[0]:"object"==typeof e[1]&&(e[1].pub||e[1].epub)?e[1]:null,n=t||"string"!=typeof e[0]?null:e[0],a=!n&&(!t||t.priv&&t.epriv)||"string"!=typeof e[1]?null:e[1],c=e.filter(e=>"function"==typeof e)[0]||null,u=e&&e.length>1&&"object"==typeof e[e.length-1]?e[e.length-1]:{},l="number"==typeof u.retries?u.retries:9,f=this,h=f._,d=f.back(-1);if(h.ing)return(c||i)({err:o.log("User is already being created or authenticated!"),wait:!0}),f;h.ing=!0;var p,g={a:function(e){if(!e)return g.b();if(!e.pub){var t=[];return Object.keys(e).forEach(function(n){"_"!=n&&t.push(e[n])}),g.b(t)}if(g.name)return g.f(e);g.c((g.data=e).auth)},b:function(e){var t=(g.list=(g.list||[]).concat(e||[])).shift();if(p===t)return g.name?g.err("Your user account is not published for dApps to access, please consider syncing it online, or allowing local access by adding your device as a peer."):n&&l--?(g.enc=p,g.legacy=!1,g.base64=!1,void d.get("~@"+n).once(g.a)):g.err("Wrong user or password.");d.get(t).once(g.a)},c:function(e){return p===e?g.b():"string"==typeof e?"SEA{"===e.slice(0,4)?void r.opt.parse(e).then(function(t){if(!t||!t.m)return g.c(s(e));var n=Array.isArray(t.m)?t.m[2]:t.m;g.c(s(n))}):g.c(s(e)):void r.work(a,(g.auth=e).s,g.d,g.enc)},d:function(e){g.proof=e,r.decrypt(g.auth.ek,e,g.e,g.enc)},e:function(e){if(p===e){if(!g.enc)return g.enc={encode:"utf8"},g.c(g.auth);if(!g.base64)return g.base64=!0,g.enc={encode:"base64"},g.c(g.auth);if(!g.legacy&&g.proof){g.legacy=!0;for(var t=g.proof.replace(/-/g,"+").replace(/_/g,"/");t.length%4;)t+="=";return r.decrypt(g.auth.ek,t,g.e,{encode:"base64"})}return g.enc=null,g.b()}g.half=e,g.f(g.data)},f:function(e){var t=g.half||{},n=g.data||{};g.g(g.lol={pub:e.pub||n.pub,epub:e.epub||n.epub,priv:e.priv||t.priv,epriv:e.epriv||t.epriv})},g:function(e){if(!e||!e.pub||!e.epub)return g.b();g.pair=e;var t=d._.user,l=t._,y=(l.tag,l.opt);(l=t._=d.get("~"+e.pub)._).opt=y,t.is={pub:e.pub,epub:e.epub,alias:n||e.pub},l.sea=g.pair,h.ing=!1;try{a&&p==(s(h.root.graph["~"+e.pub].auth)||"")[":"]&&(u.shuffle=u.change=a)}catch(e){}if(u.change?g.z():(c||i)(l),r.window&&(f.back("user")._.opt||u).remember)try{var m={};(m=r.window.sessionStorage).recall=!0,m.pair=JSON.stringify(e)}catch(e){}try{d._.tag.auth?d._.on("auth",l):setTimeout(function(){d._.on("auth",l)},1)}catch(e){o.log("Your 'auth' callback crashed with:",e)}},h:function(e){return e?((n=e.alias)||(n=e.alias="~"+t.pub),e.auth?(t=null,void g.c((g.data=e).auth)):g.g(t)):g.b()},z:function(){g.salt=String.random(64),r.work(u.change,g.salt,g.y)},y:function(e){r.encrypt({priv:g.pair.priv,epriv:g.pair.epriv},e,g.x,{raw:1})},x:function(e){g.w(JSON.stringify({ek:e,s:g.salt}))},w:function(e){if(u.shuffle){console.log("migrate core account from UTF8 & shuffle");var t={};Object.keys(g.data).forEach(function(e){t[e]=g.data[e]}),delete t._,t.auth=e,d.get("~"+g.pair.pub).put(t)}d.get("~"+g.pair.pub).get("auth").put(e,c||i)},err:function(e){var t={err:o.log(e||"User cannot be found!")};h.ing=!1,(c||i)(t)},plugin:function(e){if(!(g.name=e))return g.err();var t=[e];"~"!==e[0]&&(t[1]="~"+e,t[2]="~@"+e),g.b(t)}};return t?t.priv&&t.epriv?g.g(t):d.get("~"+t.pub).once(g.h):n?d.get("~@"+n).once(g.a):n||a||r.name(g.plugin),f}})(t,"./auth"),t(function(e){var n=t("./user"),r=n.SEA;n.GUN,n.prototype.recall=function(e,t){var n=this,o=n.back(-1);if((e=e||{})&&e.sessionStorage){if(r.window)try{var i;(i=r.window.sessionStorage)&&(o._.opt.remember=!0,(n.back("user")._.opt||e).remember=!0,(i.recall||i.pair)&&o.user().auth(JSON.parse(i.pair),t))}catch(e){}return n}return n}})(t,"./recall"),t(function(e){var n=t("./user"),r=n.SEA,o=n.GUN,i=function(){};n.prototype.pair=function(){var e,t=this;try{e=new Proxy({DANGER:"☠"},{get:function(e,n,r){if(t.is&&(t._||"").sea)return t._.sea[n]}})}catch(e){}return e},n.prototype.delete=async function(e,t,n){console.log("user.delete() IS DEPRECATED AND WILL BE MOVED TO A MODULE!!!");var r=this,s=(r.back(-1),r.back("user"));try{s.auth(e,t,function(e){(s.is||{}).pub,s.map().once(function(){this.put(null)}),s.leave(),(n||i)({ok:0})})}catch(e){o.log("User.delete failed! Error:",e)}return r},n.prototype.alive=async function(){console.log("user.alive() IS DEPRECATED!!!");const e=this.back(-1);try{return await authRecall(e),e._.user._}catch(e){const t="No session!";throw o.log(t),{err:t}}},n.prototype.trust=async function(e){console.log("`.trust` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!"),o.is(e)&&e.get("pub").get((e,t)=>{console.log(e,t)}),e.get("trust").get(path).put(theirPubkey)},n.prototype.grant=function(e,t){console.log("`.grant` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!");var n=this,o=n.back(-1).user(),i=o._.sea,s="";return n.back(function(e){e.is||(s+=e.get||"")}),async function(){var n,a=await o.get("grant").get(i.pub).get(s).then();(a=await r.decrypt(a,i))||(a=r.random(16).toString(),n=await r.encrypt(a,i),o.get("grant").get(i.pub).get(s).put(n));var c=e.get("pub").then(),u=e.get("epub").then();c=await c,u=await u;var l=await r.secret(u,i);n=await r.encrypt(a,l),o.get("grant").get(c).get(s).put(n,t)}(),n},n.prototype.secret=function(e,t){console.log("`.secret` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!");var n=this,o=n.back(-1).user(),i=o.pair(),s="";return n.back(function(e){e.is||(s+=e.get||"")}),async function(){var a,c=await o.get("trust").get(i.pub).get(s).then();(c=await r.decrypt(c,i))||(c=r.random(16).toString(),a=await r.encrypt(c,i),o.get("trust").get(i.pub).get(s).put(a)),a=await r.encrypt(e,c),n.put(a,t)}(),n},e.exports=n})(t,"./share"),t(function(e){var n,r=t("./sea"),i=t("./settings"),s=(r.window||"").GUN||t((""+n==typeof o?".":"")+"./gun",1);function a(e){var t,n=this,o=n.as,i=e.put,s=i["#"],c=i["."],u=i[":"],l=i[">"],f=e["#"];if(s&&c)if((e._||"").faith&&(o.opt||"").faith&&"function"==typeof e._)a.pipe.faith({eve:n,msg:e,put:i,at:o});else{var h=function(t){o.on("in",{"@":f,err:e.err=t})};(e._||"").DBG&&((e._||"").DBG.c=+new Date);var d={eve:n,msg:e,at:o,put:i,soul:s,key:c,val:u,state:l,id:f,no:h,pub:null},p=[a.pipe.forget];"~@"===s?p.push(a.pipe.alias):"~@"===s.slice(0,2)?p.push(a.pipe.pubs):"~"===s||"~/"===s.slice(0,2)?p.push(a.pipe.shard):(t=r.opt.pub(s))?(d.pub=t,p.push(a.pipe.pub)):0<=s.indexOf("#")?p.push(a.pipe.hash):p.push(a.pipe.any);for(var g=p[1],y=0;y<a.plugins.length;y++)a.plugins[y](d,p);if(g&&p.indexOf(g)<0)return h("Security stage removed.");a.run(p,d)}}s.on("opt",function(e){e.sea||(e.sea={own:{}},e.on("put",a,e)),this.to.next(e)}),a.run=function(e,t){var n=t.no,r=0,o=function(){if(!(r>=e.length)){var i=e[r++],s=!1;try{i(t,function(){s||(s=!0,o())},n)}catch(e){n(e&&e.message||String(e))}}};o()},a.pipe={faith:function(e,t,n){var o=e.eve,i=e.msg,s=e.put;e.at,r.opt.pack(s,function(e){r.verify(e,!1,function(e){s["="]=r.opt.unpack(e),o.to.next(i)})})},forget:function(e,t,n){var r,o=e.soul,i=e.state,a=e.msg;0<=o.indexOf("<?")&&(r=parseFloat(o.split("<?")[1]||""))&&i<s.state()-1e3*r?(r=a._)&&r.stun&&r.stun--:t()},alias:function(e,t,n){a.alias(e.eve,e.msg,e.val,e.key,e.soul,e.at,n)},pubs:function(e,t,n){a.pubs(e.eve,e.msg,e.val,e.key,e.soul,e.at,n)},shard:function(e,t,n){a.shard(e.eve,e.msg,e.val,e.key,e.soul,e.at,n,e.at.user||"")},pub:function(e,t,n){a.pub(e.eve,e.msg,e.val,e.key,e.soul,e.at,n,e.at.user||"",e.pub)},hash:function(e,t,n){a.hash(e.eve,e.msg,e.val,e.key,e.soul,e.at,n)},any:function(e,t,n){a.any(e.eve,e.msg,e.val,e.key,e.soul,e.at,n,e.at.user||"")}},Object.freeze(a.pipe),a.plugins=[],a.use=function(e){a.plugins.push(e)},a.hash=function(e,t,n,o,i,s,a,c){var u=o.split("#").pop();if(c=c||function(){e.to.next(t)},!u||u===o)return c();r.work(n,null,function(e){var t=function(e){for(var t=atob(e),n=[],r=0;r<t.length;r++){var o=t.charCodeAt(r).toString(16);n.push(1===o.length?"0"+o:o)}return n.join("")}(e),n=e.slice(-20),r=t.slice(-20);if([e,n,t,r].some(e=>e.endsWith(u)))return c();a("Data hash not same as hash!")},{name:"SHA-256"})},a.alias=function(e,t,n,r,o,i,s){return n?"~@"+r===u(n)?e.to.next(t):void s("Alias not same!"):s("Data must exist!")},a.pubs=function(e,t,n,r,o,i,s){return n?r===u(n)?e.to.next(t):void s("Alias not same!"):s("Alias must exist!")},a.$sh={pub:88,cut:2,min:1,root:"~",pre:"~/",bad:/[^0-9a-zA-Z]/},a.$sh.max=Math.ceil(a.$sh.pub/a.$sh.cut),a.$seg=function(e,t){if("string"==typeof e&&e){if(t){if(e.length<a.$sh.min||e.length>a.$sh.cut)return}else if(e.length!==a.$sh.cut)return;if(!a.$sh.bad.test(e))return 1}},a.$path=function(e){if(a.$sh.root===e)return[];if(a.$sh.pre===(e||"").slice(0,2)&&!("/"===e.slice(-1)||0<=e.indexOf("//"))){for(var t,n=e.slice(2).split("/"),r=0;r<n.length;r++)if(t=n[r],!a.$seg(t))return;return n}},a.$kid=function(e,t){return a.$sh.root===e?a.$sh.pre+t:e+"/"+t},a.$pub=function(e,t){var n=a.$path(e);if(n)return n.join("")+t},a.$leaf=function(e,t){var n=a.$pub(e,t);if(n&&n.length===a.$sh.pub&&r.opt.pub("~"+n)===n)return n},a.$sea=function(e,t,n){var r=(e._.msg||{}).opt||{},o=e._.sea||function(){var t=Object.assign({},r);try{Object.defineProperty(e._,"sea",{value:t,enumerable:!1,configurable:!0,writable:!0})}catch(n){e._.sea=t}return t}(),i=o.authenticator||(t._||{}).sea,s=o.authenticator?o.pub||(t.is||{}).pub||n:(t.is||{}).pub;return e._.done||(delete r.authenticator,delete r.pub,e._.done=!0),{opt:o,authenticator:i,upub:s}},a.shard=async function(e,t,o,s,c,l,f,h){var d,p,g,y,m=a.$path(c),w=u(o);if(!m)return f("Invalid shard soul path.");if(!a.$seg(s,1))return f("Invalid shard key.");if(m.length+1>a.$sh.max)return f("Invalid shard depth.");if(p=a.$leaf(c,s)){if(!w)return f("Shard leaf value must be a link.");if(w!=="~"+p)return f("Shard leaf link must point to ~pub.");var b=a.$sea(t,h,p),v=b.authenticator,E=b.upub||(v||{}).pub;return v?E!==p?f("Shard leaf authenticator pub mismatch."):void a.auth(t,f,v,function(n){if(u(n)!==w)return f("Shard leaf signed payload mismatch.");t.put["="]={"#":w},a.next(e,t,f)}):f("Shard leaf requires authenticator.")}d=a.$kid(c,s);var A=a.$pub(c,s);if(g=w?{}:await i.parse(o)||{},!(y=g&&"object"==typeof g?g["*"]:void 0)){if(!w)return f("Shard intermediate value must be link.");if(w!==d)return f("Invalid shard link target.");var x=a.$sea(t,h),k=x.authenticator;return y=x.upub||(k||{}).pub,k?"string"!=typeof y||y.length!==a.$sh.pub?f("Invalid shard intermediate pub."):r.opt.pub("~"+y)!==y?f("Invalid shard intermediate pub format."):0!==y.indexOf(A)?f("Shard pub prefix mismatch."):void a.auth(t,f,k,function(n){if(u(n)!==d)return f("Shard intermediate signed payload mismatch.");t.put[":"]["*"]=y,t.put["="]={"#":d},a.next(e,t,f)}):f("Shard intermediate requires authenticator.")}var S=((l.graph||{})[c]||{})[s];if(S){var I=await i.parse(S);if(I&&u(I[":"])===d)return t.put["="]={"#":d},e.to.next(t)}return"string"!=typeof y||y.length!==a.$sh.pub?f("Invalid shard intermediate pub."):r.opt.pub("~"+y)!==y?f("Invalid shard intermediate pub format."):0!==y.indexOf(A)?f("Shard pub prefix mismatch."):u(g[":"])!==d?f("Invalid shard link target."):void r.opt.pack(t.put,function(o){r.verify(o,y,function(o){return o=r.opt.unpack(o),n===o?f("Invalid shard intermediate signature."):u(o)!==d?f("Shard intermediate payload mismatch."):(t.put["="]=o,void e.to.next(t))})})},a.$vfy=function(e,t,o,i,a,c,u,l,f){if((u||"").m&&(u||"").s&&l&&a)return r.verify(u,a,r=>{if(n!==r&&n!==r.e&&t.put[">"]&&t.put[">"]>parseFloat(r.e))return c("Certificate expired.");if(n!==r&&r.c&&r.w&&(r.c===l||r.c.indexOf("*")>-1||r.c.indexOf(l)>-1)){var u=i.indexOf("/")>-1?i.replace(i.substring(0,i.indexOf("/")+1),""):"";String.match=String.match||s.text.match;var h=Array.isArray(r.w)?r.w:"object"==typeof r.w||"string"==typeof r.w?[r.w]:[];for(const t of h)if(String.match(u,t["#"])&&String.match(o,t["."])||!t["."]&&String.match(u,t["#"])||!t["#"]&&String.match(o,t["."])||String.match(u?u+"/"+o:o,t["#"]||t)){if(t["+"]&&t["+"].indexOf("*")>-1&&u&&-1==u.indexOf(l)&&-1==o.indexOf(l))return c(`Path "${u}" or key "${o}" must contain string "${l}".`);if(r.wb&&("string"==typeof r.wb||(r.wb||{})["#"])){var d=e.as.root.$.back(-1);return"string"==typeof r.wb&&"~"!==r.wb.slice(0,1)&&(d=d.get("~"+a)),d.get(r.wb).get(l).once(e=>!e||1!==e&&!0!==e?f(r):c(`Certificant ${l} blocked.`))}return f(r)}return c("Certificate verification fail.")}})},a.next=function(e,t,n){JSON.stringifyAsync(t.put[":"],function(r,o){return r?n(r||"Stringify error."):(t.put[":"]=o,e.to.next(t))})},a.guard=function(e,t,n,r,o,i,s,c){if(0>n.indexOf("#"))return c();a.hash(e,t,s,n,r,o,i,c)},a.auth=function(e,t,o,i){r.opt.pack(e.put,s=>{if(!o)return t("Missing authenticator");r.sign(s,o,async function(o){if(n===o)return t(r.err||"Signature fail.");if(!o.m||!o.s)return t("Invalid signature format");var s=r.opt.unpack(o.m);e.put[":"]={":":s,"~":o.s},e.put["="]=s,i(s)},{raw:1})})},a.$tag=async function(e,t,n,r,o){const s=await i.parse(t);s&&s.m&&s.s&&r(s,n,t=>{e.put[":"]["+"]=s,e.put[":"]["*"]=n,o()})},a.pass=function(e,t,n,r,o){return n["+"]&&n["+"].m&&n["+"].s&&n["*"]?o(n["+"],n["*"],n=>(t.put["="]=r,e.to.next(t))):(t.put["="]=r,e.to.next(t))},a.pub=async function(e,t,o,s,c,l,f,h,d,p){var g;p=p||{};const y=(n,r,o)=>a.$vfy(e,t,s,c,d,f,n,r,o),m=()=>a.next(e,t,f),w=a.$sea(t,h,d),b=w.opt,v=w.authenticator,E=w.upub,A=p.nocert?n:b.cert,x=function(e){return n===p.want||e===p.want?1:void f(p.err||"Unexpected payload.")},k=await i.parse(o)||{},S=function(n,r){a.guard(e,t,s,c,l,f,n,r)},I=async function(){return d===E?((g=u(o))&&((l.sea.own[g]=l.sea.own[g]||{})[d]=1),void m()):d!==E&&A?a.$tag(t,A,E,y,m):void 0};if("pub"===s&&"~"+d===c)return o===d?e.to.next(t):f("Account not same!");!h.is&&!v||!E||k["*"]||k["+"]||!(d===E||d!==E&&A)?r.opt.pack(t.put,o=>{r.verify(o,k["*"]||d,function(o){var i;if(o=r.opt.unpack(o),n===o)return f("Unverified data.");x(o)&&((i=u(o))&&d===r.opt.pub(i)&&((l.sea.own[i]=l.sea.own[i]||{})[d]=1),S(o,function(){!function(n){a.pass(e,t,k,n,y)}(o)}))})}):a.auth(t,f,v,function(e){x(e)&&S(e,I)})},a.any=function(e,t,n,r,o,i,s,a){if(i.opt.secure)return s("Soul missing public key at '"+r+"'.");i.on("secure",function(t){if(this.off(),!i.opt.secure)return e.to.next(t);s("Data cannot be changed.")}).on.on("secure",t)};var c=s.valid,u=function(e,t){return"string"==typeof(t=c(e))&&t},l=((s.state||"").ify,/[^\w_-]/);r.opt.pub=function(e){if(e&&(e=e.split("~")[1])&&"@"!==(e[0]||"")[0]){if(/^[A-Za-z0-9]{88}/.test(e))return e.slice(0,88);var t=e.split(l).slice(0,2);if(t&&2===t.length)return t.slice(0,2).join(".")}},r.opt.stringy=function(e){},r.opt.pack=function(e,t,o,i,a){var c,u;if(r.opt.check(e))return t(e);e&&e["#"]&&e["."]&&e[">"]&&(c=e[":"],u=1),JSON.parseAsync(u?c:e,function(r,c){var u=n!==(c||"")[":"]&&(c||"")["~"];t(u?{m:{"#":a||e["#"],".":o||e["."],":":(c||"")[":"],">":e[">"]||s.state.is(i,o)},s:u}:e)})};var f=r.opt;r.opt.unpack=function(e,t,o){var i;if(n!==e){if(e&&n!==(i=e[":"]))return i;if(t=t||f.fall_key,!o&&f.fall_val&&((o={})[t]=f.fall_val),t&&o){if(e===o[t])return e;if(!r.opt.check(o[t]))return e;var a=o&&o._&&o._["#"]||f.fall_soul,c=s.state.is(o,t)||f.fall_state;return e&&4===e.length&&a===e[0]&&t===e[1]&&h(c)===h(e[3])?e[2]:c<r.opt.shuffle_attack?e:void 0}}},r.opt.shuffle_attack=15463296e5;var h=Math.floor})(t,"./index")}()},736(e){function t(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=736,e.exports=t},251(e,t){t.read=function(e,t,n,r,o){var i,s,a=8*o-r-1,c=(1<<a)-1,u=c>>1,l=-7,f=n?o-1:0,h=n?-1:1,d=e[t+f];for(f+=h,i=d&(1<<-l)-1,d>>=-l,l+=a;l>0;i=256*i+e[t+f],f+=h,l-=8);for(s=i&(1<<-l)-1,i>>=-l,l+=r;l>0;s=256*s+e[t+f],f+=h,l-=8);if(0===i)i=1-u;else{if(i===c)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,r),i-=u}return(d?-1:1)*s*Math.pow(2,i-r)},t.write=function(e,t,n,r,o,i){var s,a,c,u=8*i-o-1,l=(1<<u)-1,f=l>>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:i-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+f>=1?h/c:h*Math.pow(2,1-f))*c>=2&&(s++,c/=2),s+f>=l?(a=0,s=l):s+f>=1?(a=(t*c-1)*Math.pow(2,o),s+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,o),s=0));o>=8;e[n+d]=255&a,d+=p,a/=256,o-=8);for(s=s<<o|a,u+=o;u>0;e[n+d]=255&s,d+=p,s/=256,u-=8);e[n+d-p]|=128*g}},606(e){var t,n,r=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}function s(e){if(t===setTimeout)return setTimeout(e,0);if((t===o||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:o}catch(e){t=o}try{n="function"==typeof clearTimeout?clearTimeout:i}catch(e){n=i}}();var a,c=[],u=!1,l=-1;function f(){u&&a&&(u=!1,a.length?c=a.concat(c):l=-1,c.length&&h())}function h(){if(!u){var e=s(f);u=!0;for(var t=c.length;t;){for(a=c,c=[];++l<t;)a&&a[l].run();l=-1,t=c.length}a=null,u=!1,function(e){if(n===clearTimeout)return clearTimeout(e);if((n===i||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(e);try{return n(e)}catch(t){try{return n.call(null,e)}catch(t){return n.call(this,e)}}}(e)}}function d(e,t){this.fun=e,this.array=t}function p(){}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new d(e,t)),1!==c.length||u||s(h)},d.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=p,r.addListener=p,r.once=p,r.off=p,r.removeListener=p,r.removeAllListeners=p,r.emit=p,r.prependListener=p,r.prependOnceListener=p,r.listeners=function(e){return[]},r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},72(e){var t=[];function n(e){for(var n=-1,r=0;r<t.length;r++)if(t[r].identifier===e){n=r;break}return n}function r(e,r){for(var i={},s=[],a=0;a<e.length;a++){var c=e[a],u=r.base?c[0]+r.base:c[0],l=i[u]||0,f="".concat(u," ").concat(l);i[u]=l+1;var h=n(f),d={css:c[1],media:c[2],sourceMap:c[3],supports:c[4],layer:c[5]};if(-1!==h)t[h].references++,t[h].updater(d);else{var p=o(d,r);r.byIndex=a,t.splice(a,0,{identifier:f,updater:p,references:1})}s.push(f)}return s}function o(e,t){var n=t.domAPI(t);return n.update(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap&&t.supports===e.supports&&t.layer===e.layer)return;n.update(e=t)}else n.remove()}}e.exports=function(e,o){var i=r(e=e||[],o=o||{});return function(e){e=e||[];for(var s=0;s<i.length;s++){var a=n(i[s]);t[a].references--}for(var c=r(e,o),u=0;u<i.length;u++){var l=n(i[u]);0===t[l].references&&(t[l].updater(),t.splice(l,1))}i=c}}},659(e){var t={};e.exports=function(e,n){var r=function(e){if(void 0===t[e]){var n=document.querySelector(e);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}t[e]=n}return t[e]}(e);if(!r)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");r.appendChild(n)}},540(e){e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},675(e,t,n){e.exports=function(e){var t=n.nc;t&&e.setAttribute("nonce",t)}},825(e){e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=e.insertStyleElement(e);return{update:function(n){!function(e,t,n){var r="";n.supports&&(r+="@supports (".concat(n.supports,") {")),n.media&&(r+="@media ".concat(n.media," {"));var o=void 0!==n.layer;o&&(r+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),r+=n.css,o&&(r+="}"),n.media&&(r+="}"),n.supports&&(r+="}");var i=n.sourceMap;i&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),t.styleTagTransform(r,e,t.options)}(t,e,n)},remove:function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(t)}}}},113(e){e.exports=function(e,t){if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}},442(t){t.exports=e},809(e,t,n){n.r(t),n.d(t,{decFrom:()=>y,decrypt:()=>p,encFor:()=>g,encrypt:()=>d,generatePairFromMnemonic:()=>I,generatePairFromSeed:()=>S,getShortHash:()=>v,hashObj:()=>w,hashText:()=>m,isHash:()=>h,randomUUID:()=>k,safeHash:()=>E,safeJSONParse:()=>x,secret:()=>b,unsafeHash:()=>A});const r={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let o;const i=new Uint8Array(16),s=[];for(let e=0;e<256;++e)s.push((e+256).toString(16).slice(1));const a=function(e,t,n){if(r.randomUUID&&!t&&!e)return r.randomUUID();const a=(e=e||{}).random??e.rng?.()??function(){if(!o){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");o=crypto.getRandomValues.bind(crypto)}return o(i)}();if(a.length<16)throw new Error("Random bytes length must be >= 16");if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t){if((n=n||0)<0||n+16>t.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=a[e];return t}return function(e,t=0){return(s[e[t+0]]+s[e[t+1]]+s[e[t+2]]+s[e[t+3]]+"-"+s[e[t+4]]+s[e[t+5]]+"-"+s[e[t+6]]+s[e[t+7]]+"-"+s[e[t+8]]+s[e[t+9]]+"-"+s[e[t+10]]+s[e[t+11]]+s[e[t+12]]+s[e[t+13]]+s[e[t+14]]+s[e[t+15]]).toLowerCase()}(a)};var c=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},u=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},l=null;function f(){return l||(n.g.SEA?l=n.g.SEA:globalThis.Gun&&globalThis.Gun.SEA?l=globalThis.Gun.SEA:"undefined"!=typeof window&&window.Gun&&window.Gun.SEA?l=window.Gun.SEA:n.g.Gun&&n.g.Gun.SEA?l=n.g.Gun.SEA:globalThis.SEA?l=globalThis.SEA:"undefined"!=typeof window&&window.SEA?l=window.SEA:null)}function h(e){return!("string"!=typeof e||0===e.length||(44!==e.length||!e.endsWith("="))&&!e.includes("-"))}function d(e,t){return c(this,void 0,void 0,function(){var n,r,o,i;return u(this,function(s){switch(s.label){case 0:if(!(n=f())||!n.encrypt)throw new Error("SEA not available");s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n.encrypt(e,t)];case 2:if("SEA not available"===(r=s.sent()))throw new Error("SEA not available");return[2,r];case 3:throw o=s.sent(),i=o instanceof Error?o:new Error(String(o)),new Error("SEA encryption failed: ".concat(i.message));case 4:return[2]}})})}function p(e,t){return c(this,void 0,void 0,function(){var n,r,o,i;return u(this,function(s){switch(s.label){case 0:if(!(n=f())||!n.decrypt)throw new Error("SEA not available");s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n.decrypt(e,t)];case 2:if("SEA not available"===(r=s.sent()))throw new Error("SEA not available");return[2,r];case 3:throw o=s.sent(),i=o instanceof Error?o:new Error(String(o)),new Error("SEA decryption failed: ".concat(i.message));case 4:return[2]}})})}function g(e,t,n){return c(this,void 0,void 0,function(){var r,o;return u(this,function(i){switch(i.label){case 0:if(!(r=f())||!r.secret||!r.encrypt)return[2,"encrypted-data"];i.label=1;case 1:return i.trys.push([1,4,,5]),[4,r.secret(n.epub,t)];case 2:return o=i.sent(),[4,r.encrypt(e,o)];case 3:return[2,i.sent()];case 4:return i.sent(),[2,"encrypted-data"];case 5:return[2]}})})}function y(e,t,n){return c(this,void 0,void 0,function(){var r,o;return u(this,function(i){switch(i.label){case 0:if(!(r=f())||!r.secret||!r.decrypt)return[2,"decrypted-data"];i.label=1;case 1:return i.trys.push([1,4,,5]),[4,r.secret(t.epub,n)];case 2:return o=i.sent(),[4,r.decrypt(e,o)];case 3:return[2,i.sent()];case 4:return i.sent(),[2,"decrypted-data"];case 5:return[2]}})})}function m(e){return c(this,void 0,void 0,function(){var t,n;return u(this,function(r){switch(r.label){case 0:if(!(t=f())||!t.work)throw new Error("SEA not available");r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.work(e,null,null,{name:"SHA-256"})];case 2:if("SEA not available"===(n=r.sent()))throw new Error("SEA not available");return[2,n];case 3:throw r.sent(),new Error("SEA not available");case 4:return[2]}})})}function w(e){return c(this,void 0,void 0,function(){var t;return u(this,function(n){switch(n.label){case 0:return[4,m(t="string"==typeof e?e:JSON.stringify(e))];case 1:return[2,{hash:n.sent(),hashed:t}]}})})}function b(e,t){return c(this,void 0,void 0,function(){return u(this,function(n){switch(n.label){case 0:return[4,f().secret(e,t)];case 1:return[2,n.sent()]}})})}function v(e,t){return c(this,void 0,void 0,function(){return u(this,function(n){switch(n.label){case 0:return[4,f().work(e,null,null,{name:"PBKDF2",encode:"hex",salt:void 0!==t?t:""})];case 1:return[2,(n.sent()||"").substring(0,8)]}})})}function E(e){return null==e?e:""===e?"":e.replace(/-/g,"_").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,".")}function A(e){if(null==e)return e;if(""===e)return"";var t=e;return(t=t.replace(/_/g,"-").replace(/\./g,"=")).replace(/-/g,"+")}function x(e,t){if(void 0===t&&(t={}),void 0!==e){if(null===e)return null;if(""===e)return"";if("object"==typeof e)return e;try{return JSON.parse(e)}catch(e){return t}}}function k(){var e=null===globalThis||void 0===globalThis?void 0:globalThis.crypto;if(null==e?void 0:e.randomUUID)return e.randomUUID();try{if(null==e?void 0:e.getRandomValues){var t=new Uint8Array(16);e.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128;var n=Array.from(t).map(function(e){return e.toString(16).padStart(2,"0")}).join("");return"".concat(n.slice(0,8),"-").concat(n.slice(8,12),"-").concat(n.slice(12,16),"-").concat(n.slice(16,20),"-").concat(n.slice(20))}}catch(e){}return a()}function S(e){return c(this,void 0,void 0,function(){var t,n,r;return u(this,function(o){switch(o.label){case 0:if(!(t=f())||!t.pair)throw new Error("SEA not available");o.label=1;case 1:return o.trys.push([1,3,,4]),[4,t.pair(null,{seed:e})];case 2:return(r=o.sent())&&r.pub&&r.priv?[2,r]:[3,4];case 3:return o.sent(),[3,4];case 4:return[4,t.work(e,"shogun-seed-salt",null,{name:"SHA-256"})];case 5:n=o.sent(),o.label=6;case 6:return o.trys.push([6,8,,9]),[4,t.pair(null,{seed:n})];case 7:return(r=o.sent())&&r.pub&&r.priv?[2,r]:[3,9];case 8:return o.sent(),[3,9];case 9:throw new Error("Deterministic key generation not supported by this Gun version")}})})}function I(e,t){return c(this,void 0,void 0,function(){return u(this,function(n){if(!e||e.split(" ").length<12)throw new Error("Invalid mnemonic: must be at least 12 words");return[2,S("".concat(e.trim(),":").concat(t.trim()))]})})}}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={id:e,loaded:!1,exports:{}};return t[e](i,i.exports,r),i.loaded=!0,i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),r.nc=void 0;var o={};r.r(o),r.d(o,{ShogunButton:()=>F,ShogunButtonProvider:()=>S,shogunConnector:()=>VI,useShogun:()=>k});var i={};r.r(i),r.d(i,{OG:()=>Ch,My:()=>wh,Ph:()=>Eh,lX:()=>Ah,Id:()=>Ih,fg:()=>Nh,qj:()=>Sh,aT:()=>vh,lq:()=>xh,z:()=>kh,Q5:()=>Bh});var s=r(442),a=r.n(s),c=r(72),u=r.n(c),l=r(825),f=r.n(l),h=r(659),d=r.n(h),p=r(675),g=r.n(p),y=r(540),m=r.n(y),w=r(113),b=r.n(w),v=r(208),E={};function A(e){return e&&"function"==typeof e.isLoggedIn&&void 0!==e.gun}E.styleTagTransform=b(),E.setAttributes=g(),E.insert=d().bind(null,"head"),E.domAPI=f(),E.insertStyleElement=m(),u()(v.A,E),v.A&&v.A.locals&&v.A.locals;const x=(0,s.createContext)({core:null,options:{},isLoggedIn:!1,userPub:null,username:null,login:async()=>({}),signUp:async()=>({}),logout:()=>{},setProvider:()=>!1,hasPlugin:()=>!1,getPlugin:()=>{},exportGunPair:async()=>"",importGunPair:async()=>!1,gunPlugin:null,put:async()=>{},get:()=>null,remove:async()=>{},completePendingSignup:()=>{},hasPendingSignup:!1,setHasPendingSignup:e=>{}}),k=()=>(0,s.useContext)(x);function S({children:e,core:t,options:n,onLoginSuccess:r,onSignupSuccess:o,onError:i}){const[c,u]=(0,s.useState)(!1),[l,f]=(0,s.useState)(null),[h,d]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1);(0,s.useEffect)(()=>{var e,n;if(!t)return;let r=!1,o=null;A(t)&&(r=t.isLoggedIn(),r&&(o=null===(n=null===(e=t.gun.user())||void 0===e?void 0:e.is)||void 0===n?void 0:n.pub)),r&&o&&(u(!0),f(o),d(o.slice(0,8)+"..."))},[t]);const y=a().useCallback(async(e,...n)=>{var o,s;try{if(!t)throw new Error("SDK not initialized");let a,c,l=e;switch(e){case"password":if(c=n[0],console.log(`[DEBUG] ShogunButton: Calling core.login for username: ${c}`),!A(t))throw new Error("Unsupported core type");a=await t.login(n[0],n[1]),console.log("[DEBUG] ShogunButton: core.login result:",a);break;case"pair":const e=n[0];if(!e||"object"!=typeof e)throw new Error("Invalid pair data provided");if(!A(t))throw new Error("Pair authentication requires ShogunCore");a=await new Promise((n,r)=>{t.gun.user().auth(e,t=>{if(t.err)return void r(new Error(`Pair authentication failed: ${t.err}`));const o=t.pub||e.pub,i=t.alias||`user_${null==o?void 0:o.substring(0,8)}`;n({success:!0,userPub:o,alias:i,method:"pair"})})}),c=a.alias,l="pair";break;case"webauthn":if(c=n[0],!A(t))throw new Error("WebAuthn requires ShogunCore");{const e=t.getPlugin("webauthn");if(!e)throw new Error("WebAuthn plugin not available");a=await e.login(c)}break;case"web3":if(!A(t))throw new Error("Web3 requires ShogunCore");{const e=t.getPlugin("web3");if(!e)throw new Error("Web3 plugin not available");const n=await e.connectMetaMask();if(!n.success||!n.address)throw new Error(n.error||"Failed to connect wallet.");c=n.address,a=await e.login(n.address)}break;case"nostr":if(!A(t))throw new Error("Nostr requires ShogunCore");{const e=t.getPlugin("nostr");if(!e)throw new Error("Nostr plugin not available");const n=await e.connectBitcoinWallet();if(!n||!n.success)throw new Error((null==n?void 0:n.error)||"Connessione al wallet Bitcoin fallita");const r=n.address;if(!r)throw new Error("Nessuna chiave pubblica ottenuta");c=r,a=await e.login(r)}break;case"challenge":if(c=n[0],!c)throw new Error("Username required for challenge login");if(!A(t))throw new Error("Challenge auth requires ShogunCore");{const e=t.getPlugin("challenge");if(!e)throw new Error("Challenge plugin not available");a=await e.login(c),l="challenge"}break;case"seed":c=n[0];const r=n[1];if(!c||!r)throw new Error("Username and seed phrase are required");if(!A(t))throw new Error("Seed authentication requires ShogunCore");a=await t.loginWithSeed(c,r),l="seed";break;default:throw new Error("Unsupported login method")}if(a.success){let e=a.userPub||"";!e&&A(t)&&(e=(null===(s=null===(o=t.gun.user())||void 0===o?void 0:o.is)||void 0===s?void 0:s.pub)||"");const n=a.alias||c||e.slice(0,8)+"...";u(!0),f(e),d(n),null==r||r({userPub:e,username:n,authMethod:l})}else null==i||i(a.error||"Login failed");return a}catch(e){return null==i||i(e.message||"Error during login"),{success:!1,error:e.message}}},[t,r,i]),m=a().useCallback(async(e,...n)=>{var r,s,a;try{if(!t)throw new Error("SDK not initialized");let c,l,h=e;switch(e){case"password":if(l=n[0],n[1]!==n[2])throw new Error("Passwords do not match");console.log(`[DEBUG] ShogunButton: Calling core.signUp for username: ${l}`),console.log("[DEBUG] ShogunButton: core object:",t);try{if(console.log("[DEBUG] ShogunButton: About to call core.signUp..."),!A(t))throw new Error("Unsupported core type");c=await t.signUp(n[0],n[1]),console.log("[DEBUG] ShogunButton: core.signUp completed successfully"),console.log("[DEBUG] ShogunButton: core.signUp result:",c)}catch(e){throw console.error("[DEBUG] ShogunButton: core.signUp error:",e),e}break;case"webauthn":{l="string"==typeof n[0]?n[0].trim():"";const e=n.length>1&&"object"==typeof n[1]&&null!==n[1]?n[1]:{};if(!l)throw new Error("Username is required for WebAuthn registration");if(!A(t))throw new Error("WebAuthn requires ShogunCore");{const n=t.getPlugin("webauthn");if(!n)throw new Error("WebAuthn plugin not available");const o={};e.seedPhrase?(o.seedPhrase=e.seedPhrase.trim(),o.generateSeedPhrase=null!==(r=e.generateSeedPhrase)&&void 0!==r&&r):"boolean"==typeof e.generateSeedPhrase&&(o.generateSeedPhrase=e.generateSeedPhrase),void 0!==o.generateSeedPhrase||o.seedPhrase||(o.generateSeedPhrase=!0),c=await n.signUp(l,o)}break}case"web3":if(!A(t))throw new Error("Web3 requires ShogunCore");{const e=t.getPlugin("web3");if(!e)throw new Error("Web3 plugin not available");const n=await e.connectMetaMask();if(!n.success||!n.address)throw new Error(n.error||"Failed to connect wallet.");l=n.address,c=await e.signUp(n.address)}break;case"nostr":if(!A(t))throw new Error("Nostr requires ShogunCore");{const e=t.getPlugin("nostr");if(!e)throw new Error("Nostr plugin not available");const n=await e.connectBitcoinWallet();if(!n||!n.success)throw new Error((null==n?void 0:n.error)||"Connessione al wallet Bitcoin fallita");const r=n.address;if(!r)throw new Error("Nessuna chiave pubblica ottenuta");l=r,c=await e.signUp(r)}break;default:throw new Error("Unsupported signup method")}if(c.success){let e=c.userPub||"";!e&&A(t)&&(e=(null===(a=null===(s=t.gun.user())||void 0===s?void 0:s.is)||void 0===a?void 0:a.pub)||"");const n=c.alias||l||e.slice(0,8)+"...";u(!0),f(e),d(n);const r={userPub:e,username:n,seedPhrase:c.seedPhrase,authMethod:h},i=Boolean(c.seedPhrase||c.trapdoor);g(i),null==o||o(r)}else null==i||i(c.error);return c}catch(e){return null==i||i(e.message||"Error during registration"),{success:!1,error:e.message}}},[t,o,i]),w=a().useCallback(()=>{A(t)&&t.logout(),u(!1),f(null),d(null)},[t]),b=a().useCallback(e=>{var n;if(!t)return!1;try{let r=null;if(e&&e.connection&&e.connection.url?r=e.connection.url:"string"==typeof e&&(r=e),r){const e=(null===(n=null==t?void 0:t.db)||void 0===n?void 0:n.gun)||(null==t?void 0:t.gun);if(e&&"function"==typeof e.opt)try{return e.opt({peers:[r]}),!0}catch(e){return console.error("Error adding peer via gun.opt:",e),!1}}return!1}catch(e){return console.error("Error setting provider:",e),!1}},[t]),v=a().useCallback(e=>!!A(t)&&t.hasPlugin(e),[t]),E=a().useCallback(e=>{if(A(t))return t.getPlugin(e)},[t]),k=a().useCallback(async e=>{if(!t)throw new Error("SDK not initialized");if(!c)throw new Error("User not authenticated");try{const t=sessionStorage.getItem("gun/pair")||sessionStorage.getItem("pair");if(!t)throw new Error("No Gun pair available for current user");let n=JSON.stringify(t);return e&&e.trim()&&(window.SEA&&window.SEA.encrypt?n=await window.SEA.encrypt(n,e):console.warn("SEA encryption not available, exporting unencrypted")),n}catch(e){throw new Error(`Failed to export Gun pair: ${e.message}`)}},[t,c]),S=a().useCallback(async(e,n)=>{if(!t)throw new Error("SDK not initialized");try{let t=e;if(n&&n.trim())if(window.SEA&&window.SEA.decrypt){if(t=await window.SEA.decrypt(e,n),!t)throw new Error("Failed to decrypt pair data - wrong password?")}else console.warn("SEA decryption not available, assuming unencrypted data");const r=JSON.parse(t);if(!(r.pub&&r.priv&&r.epub&&r.epriv))throw new Error("Invalid pair structure - missing required keys");return(await y("pair",r)).success}catch(e){throw new Error(`Failed to import Gun pair: ${e.message}`)}},[t,y]),I=a().useCallback(()=>{g(!1)},[g]),C=a().useMemo(()=>({core:t,options:n,isLoggedIn:c,userPub:l,username:h,login:y,signUp:m,logout:w,hasPlugin:v,getPlugin:E,exportGunPair:k,importGunPair:S,setProvider:b,gunPlugin:null,completePendingSignup:I,hasPendingSignup:p,setHasPendingSignup:g,put:async(e,n)=>{if(A(t)){if(!t.gun)throw new Error("Gun instance not available");return new Promise((r,o)=>{t.gun.get(e).put(n,e=>{e.err?o(new Error(e.err)):r()})})}throw new Error("Core not available")},get:e=>A(t)&&t.gun?t.gun.get(e):null,remove:async e=>{if(A(t)){if(!t.gun)throw new Error("Gun instance not available");return new Promise((n,r)=>{t.gun.get(e).put(null,e=>{e.err?r(new Error(e.err)):n()})})}throw new Error("Core not available")}}),[t,n,c,l,h,y,m,w,v,E,k,S,null,I,p,g]);return a().createElement(x.Provider,{value:C},e)}const I=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M21 12V7H5a2 2 0 0 1 0-4h14v4"}),a().createElement("path",{d:"M3 5v14a2 2 0 0 0 2 2h16v-5"}),a().createElement("path",{d:"M18 12a2 2 0 0 0 0 4h4v-4Z"})),C=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("circle",{cx:"7.5",cy:"15.5",r:"5.5"}),a().createElement("path",{d:"m21 2-9.6 9.6"}),a().createElement("path",{d:"m15.5 7.5 3 3L22 7l-3-3"})),O=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M19.5 4.5 15 9l-3-3-4.5 4.5L9 12l-1.5 1.5L12 18l4.5-4.5L15 12l1.5-1.5L21 6l-1.5-1.5Z"}),a().createElement("path",{d:"M12 12 6 6l-1.5 1.5L9 12l-4.5 4.5L6 18l6-6Z"})),T=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M7 11v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1h-4"}),a().createElement("path",{d:"M14 4V2a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h2"})),N=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),a().createElement("polyline",{points:"16 17 21 12 16 7"}),a().createElement("line",{x1:"21",y1:"12",x2:"9",y2:"12"})),P=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),a().createElement("circle",{cx:"12",cy:"7",r:"4"})),B=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),a().createElement("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})),R=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),a().createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"})),U=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),a().createElement("polyline",{points:"14,2 14,8 20,8"}),a().createElement("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),a().createElement("line",{x1:"12",y1:"17",x2:"12",y2:"9"})),D=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})),L=()=>a().createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},a().createElement("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),a().createElement("polyline",{points:"14,2 14,8 20,8"}),a().createElement("line",{x1:"12",y1:"11",x2:"12",y2:"21"}),a().createElement("polyline",{points:"16,15 12,11 8,15"})),F=(()=>{const e=()=>{const{isLoggedIn:e,username:t,logout:n,login:r,signUp:o,core:i,options:c,exportGunPair:u,importGunPair:l,hasPlugin:f,hasPendingSignup:h,setHasPendingSignup:d}=k(),[p,g]=(0,s.useState)(!1),[y,m]=(0,s.useState)(""),[w,b]=(0,s.useState)(""),[v,E]=(0,s.useState)(""),[x,S]=(0,s.useState)("login"),[F,_]=(0,s.useState)("options"),[M,G]=(0,s.useState)(""),[j,H]=(0,s.useState)(!1),[z,V]=(0,s.useState)(!1),[K,W]=(0,s.useState)(""),[$,q]=(0,s.useState)(""),[J,Q]=(0,s.useState)(""),[Z,Y]=(0,s.useState)(""),[X,ee]=(0,s.useState)(!1),[te,ne]=(0,s.useState)(!1),[re,oe]=(0,s.useState)(""),[ie,se]=(0,s.useState)(""),[ae,ce]=(0,s.useState)(""),ue=(0,s.useRef)(null);if((0,s.useEffect)(()=>{const e=e=>{ue.current&&!ue.current.contains(e.target)&&V(!1)};if(z)return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[z]),(0,s.useEffect)(()=>{h&&(g(!0),"webauthn-signup-result"!==F&&re&&_("webauthn-signup-result"))},[h,F,re]),e&&t&&!p)return a().createElement("div",{className:"shogun-logged-in-container"},a().createElement("div",{className:"shogun-dropdown",ref:ue},a().createElement("button",{className:"shogun-button shogun-logged-in",onClick:()=>V(!z)},a().createElement("div",{className:"shogun-avatar"},t.substring(0,2).toUpperCase()),a().createElement("span",{className:"shogun-username"},t.length>12?`${t.substring(0,6)}...${t.substring(t.length-4)}`:t)),z&&a().createElement("div",{className:"shogun-dropdown-menu"},a().createElement("div",{className:"shogun-dropdown-header"},a().createElement("div",{className:"shogun-avatar-large"},t.substring(0,2).toUpperCase()),a().createElement("div",{className:"shogun-user-info"},a().createElement("span",{className:"shogun-username-full"},t.length>20?`${t.substring(0,10)}...${t.substring(t.length-6)}`:t))),a().createElement("div",{className:"shogun-dropdown-item",onClick:()=>{V(!1),_("export"),g(!0)}},a().createElement(L,null),a().createElement("span",null,"Export Pair")),a().createElement("div",{className:"shogun-dropdown-item",onClick:n},a().createElement(N,null),a().createElement("span",null,"Disconnect")))));const le=async(e,...t)=>{console.log(`[DEBUG] handleAuth called with method: ${e}, formMode: ${x}, args:`,t),G(""),H(!0);try{const n="login"===x?r:o;console.log(`[DEBUG] handleAuth calling action: ${n.name}, method: ${e}`);const i=await n(e,...t);console.log("[DEBUG] handleAuth result:",i),i&&!i.success&&i.error?G(i.error):i&&i.redirectUrl?window.location.href=i.redirectUrl:"signup"===x&&"webauthn"===e&&i&&i.success&&i.seedPhrase?(oe(i.seedPhrase),ee(!1),_("webauthn-signup-result")):g(!1)}catch(e){G(e.message||"An unexpected error occurred.")}finally{H(!1)}},fe=()=>{m(""),b(""),E(""),G(""),H(!1),_("options"),W(""),q(""),Q(""),Y(""),ee(!1),ne(!1),oe(""),se(""),ce("")},he=()=>{G(""),g(!1),d(!1)},de=()=>{fe(),_("options"),S(e=>"login"===e?"signup":"login")};return a().createElement(a().Fragment,null,a().createElement("button",{className:"shogun-connect-button",onClick:()=>{fe(),_("options"),g(!0)}},a().createElement(I,null),a().createElement("span",null,"Login / Sign Up")),p&&a().createElement("div",{className:"shogun-modal-overlay",onClick:he},a().createElement("div",{className:"shogun-modal",onClick:e=>e.stopPropagation()},a().createElement("div",{className:"shogun-modal-header"},a().createElement("h2",null,"export"===F?"Export Gun Pair":"import"===F?"Import Gun Pair":"webauthn-username"===F?"WebAuthn":"seed-login"===F?"Login with Seed":"login"===x?"Login":"Sign Up"),a().createElement("button",{className:"shogun-close-button",onClick:he,"aria-label":"Close"},a().createElement(R,null))),a().createElement("div",{className:"shogun-modal-content"},M&&a().createElement("div",{className:"shogun-error-message"},M),"options"===F&&a().createElement(a().Fragment,null,a().createElement("div",{className:"shogun-auth-options"},!1!==c.showMetamask&&f("web3")&&a().createElement("div",{className:"shogun-auth-option-group"},a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>le("web3"),disabled:j},a().createElement(I,null),"login"===x?"Login with MetaMask":"Signup with MetaMask")),!1!==c.showWebauthn&&f("webauthn")&&a().createElement("div",{className:"shogun-auth-option-group"},a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>{f("webauthn")?_("webauthn-username"):G("WebAuthn is not supported in your browser")},disabled:j},a().createElement(T,null),"login"===x?"Login with WebAuthn":"Signup with WebAuthn")),!1!==c.showNostr&&f("nostr")&&a().createElement("div",{className:"shogun-auth-option-group"},a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>le("nostr"),disabled:j},a().createElement(O,null),"login"===x?"Login with Nostr":"Signup with Nostr")),!1!==c.showChallenge&&f("challenge")&&a().createElement("div",{className:"shogun-auth-option-group"},a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>{f("challenge")?_("challenge-username"):G("Challenge plugin not available")},disabled:j},a().createElement(D,null),"login"===x?"Login with Challenge":"Signup with Challenge (N/A)")),a().createElement("div",{className:"shogun-divider"},a().createElement("span",null,"or")),a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>_("password"),disabled:j},a().createElement(B,null),"login"===x?"Login with Password":"Signup with Password"),!1!==c.showSeedLogin&&"login"===x&&a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>_("seed-login"),disabled:j},a().createElement(C,null),"Login with Seed phrase"),"login"===x&&a().createElement("button",{type:"button",className:"shogun-auth-option-button",onClick:()=>_("import"),disabled:j},a().createElement(U,null),"Import Gun Pair")),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{type:"button",className:"shogun-toggle-mode shogun-prominent-toggle",onClick:de,disabled:j},"login"===x?"Don't have an account? Sign up":"Already have an account? Log in"))),"seed-login"===F&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"Login with Seed Phrase"),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"seed-username"},a().createElement(P,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"seed-username",value:y,onChange:e=>m(e.target.value),disabled:j,required:!0,placeholder:"Enter your username",autoFocus:!0})),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"seed-mnemonic"},a().createElement(C,null),a().createElement("span",null,"Seed Phrase (12/24 words)")),a().createElement("textarea",{id:"seed-mnemonic",value:ae,onChange:e=>ce(e.target.value),disabled:j,required:!0,placeholder:"Enter your seed phrase...",rows:3,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"1px solid #ccc",borderRadius:"4px"}})),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{G(""),H(!0);try{if(!y.trim())throw new Error("Please enter your username");if(!ae.trim())throw new Error("Please enter your seed phrase");await le("seed",y.trim(),ae.trim()),g(!1)}catch(e){G(e.message||"Seed login failed")}finally{H(!1)}},disabled:j||!y.trim()||!ae.trim()},j?"Processing...":"Login with Seed"),a().createElement("button",{type:"button",className:"shogun-back-button",onClick:()=>_("options"),disabled:j},"Back")),"password"===F&&a().createElement(a().Fragment,null,a().createElement("button",{className:"shogun-back-button",onClick:()=>_("options")},"← Back"),a().createElement("form",{onSubmit:async e=>{e.preventDefault(),console.log(`[DEBUG] handleSubmit called, formMode: ${x}, username: ${y}`),G(""),H(!0);try{if("signup"===x){const e=await o("password",y,w,v);e&&e.success?g(!1):e&&e.error&&G(e.error)}else await le("password",y,w)}catch(e){G(e.message||"An unexpected error occurred.")}finally{H(!1)}},className:"shogun-auth-form"},a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"username"},a().createElement(P,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"username",value:y,onChange:e=>m(e.target.value),disabled:j,required:!0,placeholder:"Enter your username"})),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"password"},a().createElement(B,null),a().createElement("span",null,"Password")),a().createElement("input",{type:"password",id:"password",value:w,onChange:e=>b(e.target.value),disabled:j,required:!0,placeholder:"Enter your password"})),"signup"===x&&a().createElement(a().Fragment,null,a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"passwordConfirm"},a().createElement(C,null),a().createElement("span",null,"Confirm Password")),a().createElement("input",{type:"password",id:"passwordConfirm",value:v,onChange:e=>E(e.target.value),disabled:j,required:!0,placeholder:"Confirm your password"}))),a().createElement("button",{type:"submit",className:"shogun-submit-button",disabled:j},j?"Processing...":"login"===x?"Sign In":"Create Account"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{type:"button",className:"shogun-toggle-mode shogun-prominent-toggle",onClick:de,disabled:j},"login"===x?"Don't have an account? Sign up":"Already have an account? Log in")))),"export"===F&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"Export Gun Pair"),a().createElement("div",{style:{backgroundColor:"#f0f9ff",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #0ea5e9"}},a().createElement("p",{style:{fontSize:"14px",color:"#0c4a6e",margin:"0",fontWeight:"500"}},"🔒 Backup Your Account"),a().createElement("p",{style:{fontSize:"13px",color:"#075985",margin:"4px 0 0 0"}},"Export your Gun pair to backup your account. You can use this to login from another device or restore access if needed.")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"exportPassword"},a().createElement(B,null),a().createElement("span",null,"Encryption Password (optional but recommended)")),a().createElement("input",{type:"password",id:"exportPassword",value:K,onChange:e=>W(e.target.value),disabled:j,placeholder:"Leave empty to export unencrypted"})),Z&&a().createElement("div",{className:"shogun-form-group"},a().createElement("label",null,"Your Gun Pair (copy this safely):"),X&&a().createElement("div",{style:{backgroundColor:"#dcfce7",color:"#166534",padding:"8px 12px",borderRadius:"4px",marginBottom:"8px",fontSize:"14px",border:"1px solid #22c55e"}},"✅ Copied to clipboard successfully!"),a().createElement("textarea",{value:Z,readOnly:!0,rows:6,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"1px solid #ccc",borderRadius:"4px"}}),!navigator.clipboard&&a().createElement("p",{style:{fontSize:"12px",color:"#666",marginTop:"8px"}},"⚠️ Auto-copy not available. Please manually copy the text above.")),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{G(""),H(!0);try{const e=await u(K||void 0);Y(e),navigator.clipboard&&(await navigator.clipboard.writeText(e),ee(!0),setTimeout(()=>ee(!1),3e3))}catch(e){G(e.message||"Failed to export pair")}finally{H(!1)}},disabled:j},j?"Exporting...":"Export Pair"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{className:"shogun-toggle-mode",onClick:()=>{e?(g(!1),W(""),Y("")):(_("options"),W(""),Y(""))},disabled:j},"Back"))),"import"===F&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"Import Gun Pair"),a().createElement("div",{style:{backgroundColor:"#fef3c7",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #f59e0b"}},a().createElement("p",{style:{fontSize:"14px",color:"#92400e",margin:"0",fontWeight:"500"}},"🔑 Restore Your Account"),a().createElement("p",{style:{fontSize:"13px",color:"#a16207",margin:"4px 0 0 0"}},"Import a Gun pair to login with your existing account from another device. Make sure you have your backup data ready.")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"importPairData"},a().createElement(U,null),a().createElement("span",null,"Gun Pair Data")),a().createElement("textarea",{id:"importPairData",value:J,onChange:e=>Q(e.target.value),disabled:j,placeholder:"Paste your Gun pair JSON here...",rows:6,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"1px solid #ccc",borderRadius:"4px"}})),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"importPassword"},a().createElement(B,null),a().createElement("span",null,"Decryption Password (if encrypted)")),a().createElement("input",{type:"password",id:"importPassword",value:$,onChange:e=>q(e.target.value),disabled:j,placeholder:"Enter password if pair was encrypted"})),te&&a().createElement("div",{style:{backgroundColor:"#dcfce7",color:"#166534",padding:"12px",borderRadius:"8px",marginBottom:"16px",fontSize:"14px",border:"1px solid #22c55e",textAlign:"center"}},"✅ Pair imported successfully! Logging you in..."),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{G(""),H(!0);try{if(!J.trim())throw new Error("Please enter pair data");if(!await l(J,$||void 0))throw new Error("Failed to import pair");ne(!0),setTimeout(()=>{g(!1),ne(!1)},1500)}catch(e){G(e.message||"Failed to import pair")}finally{H(!1)}},disabled:j||te},j?"Importing...":te?"Success!":"Import and Login"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{className:"shogun-toggle-mode",onClick:()=>{_("options"),q(""),Q("")},disabled:j},"Back to Login Options"))),"webauthn-username"===F&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"login"===x?"Login with WebAuthn":"Sign Up with WebAuthn"),a().createElement("div",{style:{backgroundColor:"#f0f9ff",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #0ea5e9"}},a().createElement("p",{style:{fontSize:"14px",color:"#0c4a6e",margin:"0",fontWeight:"500"}},"🔑 WebAuthn Authentication"),a().createElement("p",{style:{fontSize:"13px",color:"#075985",margin:"4px 0 0 0"}},"Please enter your username to continue with WebAuthn"," ","login"===x?"login":"registration",".")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"username"},a().createElement(P,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"username",value:y,onChange:e=>m(e.target.value),disabled:j,required:!0,placeholder:"Enter your username",autoFocus:!0})),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:()=>le("webauthn",y),disabled:j||!y.trim()},j?"Processing...":"Continue with WebAuthn"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{type:"button",className:"shogun-back-button",onClick:()=>_("options"),disabled:j},"← Back to Options"),"login"===x&&a().createElement("button",{type:"button",className:"shogun-toggle-mode",onClick:()=>_("webauthn-recovery"),disabled:j},"Restore with Recovery Code"))),"webauthn-recovery"===F&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"Restore WebAuthn Account"),a().createElement("div",{style:{backgroundColor:"#fef3c7",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #f59e0b"}},a().createElement("p",{style:{fontSize:"14px",color:"#92400e",margin:"0",fontWeight:"500"}},"⚠️ Recovery Required"),a().createElement("p",{style:{fontSize:"13px",color:"#a16207",margin:"4px 0 0 0"}},"Enter the username and recovery code saved during signup to restore access on this device.")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"recoveryUsername"},a().createElement(P,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"recoveryUsername",value:y,onChange:e=>m(e.target.value),disabled:j,placeholder:"Enter your username",autoFocus:!0})),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"recoverySeed"},a().createElement(C,null),a().createElement("span",null,"Recovery Code")),a().createElement("textarea",{id:"recoverySeed",value:ie,onChange:e=>se(e.target.value),disabled:j,placeholder:"Enter your WebAuthn seed phrase...",rows:4,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"1px solid #f59e0b",borderRadius:"4px",backgroundColor:"#fffbeb"}})),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{G(""),H(!0);try{const e=y.trim(),t=ie.trim();if(!e)throw new Error("Please enter your username");if(!t)throw new Error("Please enter your recovery code");if(!A(i))throw new Error("WebAuthn recovery requires ShogunCore");const n=await o("webauthn",e,{seedPhrase:t,generateSeedPhrase:!1});if(!n||!n.success)throw new Error((null==n?void 0:n.error)||"Failed to restore account");const r=n.seedPhrase||t;oe(r),se(""),ee(!1),_("webauthn-signup-result")}catch(e){G(e.message||"Failed to restore WebAuthn account")}finally{H(!1)}},disabled:j},j?"Restoring...":"Restore Account"),a().createElement("div",{className:"shogun-form-footer"},a().createElement("button",{type:"button",className:"shogun-back-button",onClick:()=>{G(""),_("webauthn-username")},disabled:j},"← Back to WebAuthn"))),"webauthn-signup-result"===F&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("h3",null,"WebAuthn Account Created!"),a().createElement("div",{style:{backgroundColor:"#fef3c7",padding:"12px",borderRadius:"8px",marginBottom:"16px",border:"1px solid #f59e0b"}},a().createElement("p",{style:{fontSize:"14px",color:"#92400e",margin:"0",fontWeight:"500"}},"⚠️ Important: Save Your Recovery Code"),a().createElement("p",{style:{fontSize:"13px",color:"#a16207",margin:"4px 0 0 0"}},"This seed phrase lets you add new devices or recover your WebAuthn account. Keep it private and store it securely.")),a().createElement("div",{className:"shogun-form-group"},a().createElement("label",null,"Your WebAuthn Recovery Code (Seed Phrase):"),a().createElement("textarea",{value:re,readOnly:!0,rows:4,style:{fontFamily:"monospace",fontSize:"12px",width:"100%",padding:"8px",border:"2px solid #f59e0b",borderRadius:"4px",backgroundColor:"#fffbeb"}}),a().createElement("button",{type:"button",className:"shogun-submit-button",style:{marginTop:"8px"},onClick:async()=>{navigator.clipboard&&re&&(await navigator.clipboard.writeText(re),ee(!0),setTimeout(()=>ee(!1),3e3))},disabled:!re},X?"✅ Copied!":"📋 Copy Recovery Code"),!navigator.clipboard&&a().createElement("p",{style:{fontSize:"12px",color:"#666",marginTop:"8px"}},"⚠️ Please manually copy the code above for safekeeping.")),a().createElement("div",{style:{backgroundColor:"#dcfce7",color:"#166534",padding:"12px",borderRadius:"8px",marginTop:"16px",fontSize:"14px",border:"1px solid #22c55e",textAlign:"center"}},"✅ You're now logged in with WebAuthn!"),a().createElement("button",{type:"button",className:"shogun-submit-button",style:{marginTop:"16px"},onClick:()=>{G(""),fe(),g(!1),d(!1)}},"Close and Start Using App")),"challenge-username"===F&&a().createElement("div",{className:"shogun-auth-form"},a().createElement("div",{className:"shogun-form-group"},a().createElement("label",{htmlFor:"challenge-username"},a().createElement(P,null),a().createElement("span",null,"Username")),a().createElement("input",{type:"text",id:"challenge-username",value:y,onChange:e=>m(e.target.value),disabled:j,required:!0,placeholder:"Enter your username",autoFocus:!0})),a().createElement("button",{type:"button",className:"shogun-submit-button",onClick:async()=>{G(""),H(!0);try{if(!y.trim())throw new Error("Please enter your username");await le("challenge",y),g(!1)}catch(e){G(e.message||"Challenge login failed")}finally{H(!1)}},disabled:j},j?"Processing...":"Continue"),a().createElement("button",{type:"button",className:"shogun-back-button",onClick:()=>_("options"),disabled:j},"Back"))))))};return e.displayName="ShogunButton",Object.assign(e,{Provider:S,useShogun:k})})();var _=r(287),M=r(287).hp;"undefined"!=typeof window&&(window.process||(window.process={env:{}}),window.global||(window.global=window));var G=function(e){"undefined"!=typeof window&&(window.Buffer=e,window.global=window.global||window,window.global.Buffer=e),"undefined"!=typeof globalThis&&(globalThis.Buffer=e)};"undefined"!=typeof window&&window.Buffer&&void 0===M?G(window.Buffer):"undefined"!=typeof globalThis&&void 0===M&&G(_.hp);var j,H=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function z(e,t,n,r){return{type:e,code:t,message:n,originalError:r,timestamp:Date.now()}}!function(e){e.AUTHENTICATION="AuthenticationError",e.AUTHORIZATION="AuthorizationError",e.VALIDATION="ValidationError",e.NETWORK="NetworkError",e.DATABASE="DatabaseError",e.WALLET="WalletError",e.STORAGE="StorageError",e.ENCRYPTION="EncryptionError",e.SIGNATURE="SignatureError",e.ENVIRONMENT="EnvironmentError",e.SECURITY="SecurityError",e.GUN="GunError",e.STEALTH="StealthError",e.WEBAUTHN="WebAuthnError",e.PLUGIN="PluginError",e.UNKNOWN="UnknownError",e.CONNECTOR="ConnectorError",e.GENERAL="GeneralError",e.CONTRACT="ContractError",e.BIP32="BIP32Error",e.ETHEREUM="EthereumError",e.BITCOIN="BitcoinError"}(j||(j={}));var V,K=function(){function e(){}return e.setExternalLogger=function(e){this.externalLogger=e},e.handleError=function(e){if(e.type!==j.AUTHENTICATION&&e.type!==j.AUTHORIZATION&&e.type!==j.SECURITY||"undefined"!=typeof console&&console.error&&console.error("[".concat(e.type,"] ").concat(e.code,": ").concat(e.message)),this.errors.push(e),this.errors.length>this.maxErrors&&(this.errors=this.errors.slice(-this.maxErrors)),this.externalLogger)try{this.externalLogger(e)}catch(e){console.error("Failed to send error to external logger:",e)}this.listeners.forEach(function(t){try{t(e)}catch(e){}})},e.handle=function(e,t,n,r,o){void 0===o&&(o="error");var i=n;console.log("[".concat(e,"] ").concat(t,": ").concat(i));var s=z(e,t,i,r);return this.handleError(s),s},e.handleAndThrow=function(e,t,n,r){throw this.handle(e,t,n,r)},e.getRecentErrors=function(e){return void 0===e&&(e=10),this.errors.slice(-Math.min(e,this.errors.length))},e.addListener=function(e){this.listeners.push(e)},e.removeListener=function(e){var t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)},e.notifyListeners=function(e){var t,n;try{for(var r=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.listeners),o=r.next();!o.done;o=r.next()){var i=o.value;try{i(e)}catch(e){console.error("Error in error listener: ".concat(e))}}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}},e.formatError=function(e){if(!e)return"Unknown error";if(e instanceof Error)return"".concat(e.name,": ").concat(e.message);if("string"==typeof e)return e;if("object"==typeof e)try{return JSON.stringify(e)}catch(t){return"Object: ".concat(Object.prototype.toString.call(e))}return String(e)},e.withRetry=function(e,t,n){return r=this,o=arguments,s=function(e,t,n,r,o){var i,s,a,c;return void 0===r&&(r=3),void 0===o&&(o=1e3),H(this,function(u){switch(u.label){case 0:s=function(t){var n,s,a;return H(this,function(c){switch(c.label){case 0:return c.trys.push([0,2,,5]),n={},[4,e()];case 1:return[2,(n.value=c.sent(),n)];case 2:return s=c.sent(),i=s,a=o*t,t<r?(console.log("Retrying operation after ".concat(a,"ms (attempt ").concat(t,"/").concat(r,")")),[4,new Promise(function(e){return setTimeout(e,a)})]):[3,4];case 3:c.sent(),c.label=4;case 4:return[3,5];case 5:return[2]}})},a=1,u.label=1;case 1:return a<=r?[5,s(a)]:[3,4];case 2:if("object"==typeof(c=u.sent()))return[2,c.value];u.label=3;case 3:return a++,[3,1];case 4:if(this.handle(t,n,"Operation failed after ".concat(r," attempts"),i),i instanceof Error)throw new Error(i.message);throw new Error(this.formatError(i))}})},new((i=void 0)||(i=Promise))(function(e,t){function n(e){try{c(s.next(e))}catch(e){t(e)}}function a(e){try{c(s.throw(e))}catch(e){t(e)}}function c(t){var r;t.done?e(t.value):(r=t.value,r instanceof i?r:new i(function(e){e(r)})).then(n,a)}c((s=s.apply(r,o||[])).next())});var r,o,i,s},e.clearErrors=function(){this.errors=[]},e.errors=[],e.maxErrors=100,e.listeners=[],e.externalLogger=null,e}(),W=function(){function e(){this.events=new Map}return e.prototype.on=function(e,t){var n;this.events.has(e)||this.events.set(e,[]),null===(n=this.events.get(e))||void 0===n||n.push(t)},e.prototype.emit=function(e,t){return!!this.events.has(e)&&((this.events.get(e)||[]).forEach(function(n){try{n(t)}catch(t){var r=t instanceof Error?t:new Error(String(t));console.error("Error in event listener for ".concat(String(e),":"),r)}}),!0)},e.prototype.off=function(e,t){if(this.events.has(e)){var n=this.events.get(e)||[],r=n.indexOf(t);-1!==r&&(n.splice(r,1),0===n.length?this.events.delete(e):this.events.set(e,n))}},e.prototype.once=function(e,t){var n=this,r=function(o){t(o),n.off(e,r)};this.on(e,r)},e.prototype.removeAllListeners=function(e){e?this.events.delete(e):this.events.clear()},e}(),$=(V=function(e,t){return V=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},V(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}V(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),q=function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.core=null,t}return $(t,e),t.prototype.initialize=function(e){this.core=e},t.prototype.destroy=function(){try{this.emit("destroyed",{name:this.name,version:this.version}),this.core=null}catch(e){console.error("[".concat(this.name,"] Error during plugin destruction:"),e)}},t.prototype.assertInitialized=function(){if(!this.core)throw new Error("Plugin ".concat(this.name," not initialized"));return this.core},t}(W);const J="6.16.0";function Q(e,t,n){const r=t.split("|").map(e=>e.trim());for(let n=0;n<r.length;n++)switch(t){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof e===t)return}const o=new Error(`invalid value for type ${t}`);throw o.code="INVALID_ARGUMENT",o.argument=`value.${n}`,o.value=e,o}async function Z(e){const t=Object.keys(e);return(await Promise.all(t.map(t=>Promise.resolve(e[t])))).reduce((e,n,r)=>(e[t[r]]=n,e),{})}function Y(e,t,n){for(let r in t){let o=t[r];const i=n?n[r]:null;i&&Q(o,i,r),Object.defineProperty(e,r,{enumerable:!0,value:o,writable:!1})}}function X(e,t){if(null==e)return"null";if(null==t&&(t=new Set),"object"==typeof e){if(t.has(e))return"[Circular]";t.add(e)}if(Array.isArray(e))return"[ "+e.map(e=>X(e,t)).join(", ")+" ]";if(e instanceof Uint8Array){const t="0123456789abcdef";let n="0x";for(let r=0;r<e.length;r++)n+=t[e[r]>>4],n+=t[15&e[r]];return n}if("object"==typeof e&&"function"==typeof e.toJSON)return X(e.toJSON(),t);switch(typeof e){case"boolean":case"number":case"symbol":return e.toString();case"bigint":return BigInt(e).toString();case"string":return JSON.stringify(e);case"object":{const n=Object.keys(e);return n.sort(),"{ "+n.map(n=>`${X(n,t)}: ${X(e[n],t)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function ee(e,t){return e&&e.code===t}function te(e){return ee(e,"CALL_EXCEPTION")}function ne(e,t,n){let r,o=e;{const r=[];if(n){if("message"in n||"code"in n||"name"in n)throw new Error(`value will overwrite populated values: ${X(n)}`);for(const e in n){if("shortMessage"===e)continue;const t=n[e];r.push(e+"="+X(t))}}r.push(`code=${t}`),r.push(`version=${J}`),r.length&&(e+=" ("+r.join(", ")+")")}switch(t){case"INVALID_ARGUMENT":r=new TypeError(e);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":r=new RangeError(e);break;default:r=new Error(e)}return Y(r,{code:t}),n&&Object.assign(r,n),null==r.shortMessage&&Y(r,{shortMessage:o}),r}function re(e,t,n,r){if(!e)throw ne(t,n,r)}function oe(e,t,n,r){re(e,t,"INVALID_ARGUMENT",{argument:n,value:r})}function ie(e,t,n){null==n&&(n=""),n&&(n=": "+n),re(e>=t,"missing argument"+n,"MISSING_ARGUMENT",{count:e,expectedCount:t}),re(e<=t,"too many arguments"+n,"UNEXPECTED_ARGUMENT",{count:e,expectedCount:t})}const se=["NFD","NFC","NFKD","NFKC"].reduce((e,t)=>{try{if("test"!=="test".normalize(t))throw new Error("bad");if("NFD"===t){if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken")}e.push(t)}catch(e){}return e},[]);function ae(e){re(se.indexOf(e)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:e}})}function ce(e,t,n){if(null==n&&(n=""),e!==t){let e=n,t="new";n&&(e+=".",t+=" "+n),re(!1,`private constructor; use ${e}from* methods`,"UNSUPPORTED_OPERATION",{operation:t})}}function ue(e,t,n){if(e instanceof Uint8Array)return n?new Uint8Array(e):e;if("string"==typeof e&&e.length%2==0&&e.match(/^0x[0-9a-f]*$/i)){const t=new Uint8Array((e.length-2)/2);let n=2;for(let r=0;r<t.length;r++)t[r]=parseInt(e.substring(n,n+2),16),n+=2;return t}oe(!1,"invalid BytesLike value",t||"value",e)}function le(e,t){return ue(e,t,!1)}function fe(e,t){return ue(e,t,!0)}function he(e,t){return!("string"!=typeof e||!e.match(/^0x[0-9A-Fa-f]*$/)||"number"==typeof t&&e.length!==2+2*t||!0===t&&e.length%2!=0)}function de(e){return he(e,!0)||e instanceof Uint8Array}const pe="0123456789abcdef";function ge(e){const t=le(e);let n="0x";for(let e=0;e<t.length;e++){const r=t[e];n+=pe[(240&r)>>4]+pe[15&r]}return n}function ye(e){return"0x"+e.map(e=>ge(e).substring(2)).join("")}function me(e){return he(e,!0)?(e.length-2)/2:le(e).length}function we(e,t,n){const r=le(e);return null!=n&&n>r.length&&re(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:r,length:r.length,offset:n}),ge(r.slice(null==t?0:t,null==n?r.length:n))}function be(e,t,n){const r=le(e);re(t>=r.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(r),length:t,offset:t+1});const o=new Uint8Array(t);return o.fill(0),n?o.set(r,t-r.length):o.set(r,0),ge(o)}function ve(e,t){return be(e,t,!0)}function Ee(e,t,n,r,o){if("BAD_PREFIX"===e||"UNEXPECTED_CONTINUE"===e){let e=0;for(let r=t+1;r<n.length&&n[r]>>6==2;r++)e++;return e}return"OVERRUN"===e?n.length-t-1:0}const Ae=Object.freeze({error:function(e,t,n,r,o){oe(!1,`invalid codepoint at offset ${t}; ${e}`,"bytes",n)},ignore:Ee,replace:function(e,t,n,r,o){return"OVERLONG"===e?(oe("number"==typeof o,"invalid bad code point for replacement","badCodepoint",o),r.push(o),0):(r.push(65533),Ee(e,t,n))}});function xe(e,t){oe("string"==typeof e,"invalid string value","str",e),null!=t&&(ae(t),e=e.normalize(t));let n=[];for(let t=0;t<e.length;t++){const r=e.charCodeAt(t);if(r<128)n.push(r);else if(r<2048)n.push(r>>6|192),n.push(63&r|128);else if(55296==(64512&r)){t++;const o=e.charCodeAt(t);oe(t<e.length&&56320==(64512&o),"invalid surrogate pair","str",e);const i=65536+((1023&r)<<10)+(1023&o);n.push(i>>18|240),n.push(i>>12&63|128),n.push(i>>6&63|128),n.push(63&i|128)}else n.push(r>>12|224),n.push(r>>6&63|128),n.push(63&r|128)}return new Uint8Array(n)}function ke(e,t){return function(e,t){null==t&&(t=Ae.error);const n=le(e,"bytes"),r=[];let o=0;for(;o<n.length;){const e=n[o++];if(!(e>>7)){r.push(e);continue}let i=null,s=null;if(192==(224&e))i=1,s=127;else if(224==(240&e))i=2,s=2047;else{if(240!=(248&e)){o+=t(128==(192&e)?"UNEXPECTED_CONTINUE":"BAD_PREFIX",o-1,n,r);continue}i=3,s=65535}if(o-1+i>=n.length){o+=t("OVERRUN",o-1,n,r);continue}let a=e&(1<<8-i-1)-1;for(let e=0;e<i;e++){let e=n[o];if(128!=(192&e)){o+=t("MISSING_CONTINUE",o,n,r),a=null;break}a=a<<6|63&e,o++}null!==a&&(a>1114111?o+=t("OUT_OF_RANGE",o-1-i,n,r,a):a>=55296&&a<=57343?o+=t("UTF16_SURROGATE",o-1-i,n,r,a):a<=s?o+=t("OVERLONG",o-1-i,n,r,a):r.push(a))}return r}(e,t).map(e=>e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode(55296+(e>>10&1023),56320+(1023&e)))).join("")}function Se(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Ie(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Ce(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Se(e.outputLen),Se(e.blockLen)}function Oe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Te(e,t){Ie(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Ne="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,Pe=e=>e instanceof Uint8Array,Be=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),Re=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Ue=(e,t)=>e<<32-t|e>>>t;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const De=async()=>{};async function Le(e,t,n){let r=Date.now();for(let o=0;o<e;o++){n(o);const e=Date.now()-r;e>=0&&e<t||(await De(),r+=e)}}function Fe(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!Pe(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class _e{clone(){return this._cloneInto()}}const Me={}.toString;function Ge(e,t){if(void 0!==t&&"[object Object]"!==Me.call(t))throw new Error("Options should be object or undefined");return Object.assign(e,t)}function je(e){const t=t=>e().update(Fe(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function He(e=32){if(Ne&&"function"==typeof Ne.getRandomValues)return Ne.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}class ze extends _e{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ce(e);const n=Fe(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),o.fill(0)}update(e){return Oe(this),this.iHash.update(e),this}digestInto(e){Oe(this),Ie(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Ve=(e,t,n)=>new ze(e,t).update(n).digest();function Ke(e,t,n,r){const{c:o,dkLen:i,DK:s,PRF:a,PRFSalt:c}=function(e,t,n,r){Ce(e);const o=Ge({dkLen:32,asyncTick:10},r),{c:i,dkLen:s,asyncTick:a}=o;if(Se(i),Se(s),Se(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");const c=Fe(t),u=Fe(n),l=new Uint8Array(s),f=Ve.create(e,c),h=f._cloneInto().update(u);return{c:i,dkLen:s,asyncTick:a,DK:l,PRF:f,PRFSalt:h}}(e,t,n,r);let u;const l=new Uint8Array(4),f=Re(l),h=new Uint8Array(a.outputLen);for(let e=1,t=0;t<i;e++,t+=a.outputLen){const n=s.subarray(t,t+a.outputLen);f.setInt32(0,e,!1),(u=c._cloneInto(u)).update(l).digestInto(h),n.set(h.subarray(0,n.length));for(let e=1;e<o;e++){a._cloneInto(u).update(h).digestInto(h);for(let e=0;e<n.length;e++)n[e]^=h[e]}}return function(e,t,n,r,o){return e.destroy(),t.destroy(),r&&r.destroy(),o.fill(0),n}(a,c,s,u,h)}Ve.create=(e,t)=>new ze(e,t);class We extends _e{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Re(this.buffer)}update(e){Oe(this);const{view:t,buffer:n,blockLen:r}=this,o=(e=Fe(e)).length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=Re(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Oe(this),Te(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=Re(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.length=r,e.pos=s,e.finished=o,e.destroyed=i,r%t&&e.buffer.set(n),e}}const $e=(e,t,n)=>e&t^~e&n,qe=(e,t,n)=>e&t^e&n^t&n,Je=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Qe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ze=new Uint32Array(64);class Ye extends We{constructor(){super(64,32,8,!1),this.A=0|Qe[0],this.B=0|Qe[1],this.C=0|Qe[2],this.D=0|Qe[3],this.E=0|Qe[4],this.F=0|Qe[5],this.G=0|Qe[6],this.H=0|Qe[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)Ze[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Ze[e-15],n=Ze[e-2],r=Ue(t,7)^Ue(t,18)^t>>>3,o=Ue(n,17)^Ue(n,19)^n>>>10;Ze[e]=o+Ze[e-7]+r+Ze[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(Ue(s,6)^Ue(s,11)^Ue(s,25))+$e(s,a,c)+Je[e]+Ze[e]|0,l=(Ue(n,2)^Ue(n,13)^Ue(n,22))+qe(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){Ze.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const Xe=je(()=>new Ye),et=BigInt(2**32-1),tt=BigInt(32);function nt(e,t=!1){return t?{h:Number(e&et),l:Number(e>>tt&et)}:{h:0|Number(e>>tt&et),l:0|Number(e&et)}}function rt(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const{h:i,l:s}=nt(e[o],t);[n[o],r[o]]=[i,s]}return[n,r]}const ot=(e,t,n)=>e<<n|t>>>32-n,it=(e,t,n)=>t<<n|e>>>32-n,st=(e,t,n)=>t<<n-32|e>>>64-n,at=(e,t,n)=>e<<n-32|t>>>64-n,ct={fromBig:nt,split:rt,toBig:(e,t)=>BigInt(e>>>0)<<tt|BigInt(t>>>0),shrSH:(e,t,n)=>e>>>n,shrSL:(e,t,n)=>e<<32-n|t>>>n,rotrSH:(e,t,n)=>e>>>n|t<<32-n,rotrSL:(e,t,n)=>e<<32-n|t>>>n,rotrBH:(e,t,n)=>e<<64-n|t>>>n-32,rotrBL:(e,t,n)=>e>>>n-32|t<<64-n,rotr32H:(e,t)=>t,rotr32L:(e,t)=>e,rotlSH:ot,rotlSL:it,rotlBH:st,rotlBL:at,add:function(e,t,n,r){const o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:0|o}},add3L:(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),add3H:(e,t,n,r)=>t+n+r+(e/2**32|0)|0,add4L:(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),add4H:(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,add5H:(e,t,n,r,o,i)=>t+n+r+o+i+(e/2**32|0)|0,add5L:(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0)},[ut,lt]=(()=>ct.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(e=>BigInt(e))))(),ft=new Uint32Array(80),ht=new Uint32Array(80);class dt extends We{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(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:o,Cl:i,Dh:s,Dl:a,Eh:c,El:u,Fh:l,Fl:f,Gh:h,Gl:d,Hh:p,Hl:g}=this;return[e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g]}set(e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|o,this.Cl=0|i,this.Dh=0|s,this.Dl=0|a,this.Eh=0|c,this.El=0|u,this.Fh=0|l,this.Fl=0|f,this.Gh=0|h,this.Gl=0|d,this.Hh=0|p,this.Hl=0|g}process(e,t){for(let n=0;n<16;n++,t+=4)ft[n]=e.getUint32(t),ht[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|ft[e-15],n=0|ht[e-15],r=ct.rotrSH(t,n,1)^ct.rotrSH(t,n,8)^ct.shrSH(t,n,7),o=ct.rotrSL(t,n,1)^ct.rotrSL(t,n,8)^ct.shrSL(t,n,7),i=0|ft[e-2],s=0|ht[e-2],a=ct.rotrSH(i,s,19)^ct.rotrBH(i,s,61)^ct.shrSH(i,s,6),c=ct.rotrSL(i,s,19)^ct.rotrBL(i,s,61)^ct.shrSL(i,s,6),u=ct.add4L(o,c,ht[e-7],ht[e-16]),l=ct.add4H(u,r,a,ft[e-7],ft[e-16]);ft[e]=0|l,ht[e]=0|u}let{Ah:n,Al:r,Bh:o,Bl:i,Ch:s,Cl:a,Dh:c,Dl:u,Eh:l,El:f,Fh:h,Fl:d,Gh:p,Gl:g,Hh:y,Hl:m}=this;for(let e=0;e<80;e++){const t=ct.rotrSH(l,f,14)^ct.rotrSH(l,f,18)^ct.rotrBH(l,f,41),w=ct.rotrSL(l,f,14)^ct.rotrSL(l,f,18)^ct.rotrBL(l,f,41),b=l&h^~l&p,v=f&d^~f&g,E=ct.add5L(m,w,v,lt[e],ht[e]),A=ct.add5H(E,y,t,b,ut[e],ft[e]),x=0|E,k=ct.rotrSH(n,r,28)^ct.rotrBH(n,r,34)^ct.rotrBH(n,r,39),S=ct.rotrSL(n,r,28)^ct.rotrBL(n,r,34)^ct.rotrBL(n,r,39),I=n&o^n&s^o&s,C=r&i^r&a^i&a;y=0|p,m=0|g,p=0|h,g=0|d,h=0|l,d=0|f,({h:l,l:f}=ct.add(0|c,0|u,0|A,0|x)),c=0|s,u=0|a,s=0|o,a=0|i,o=0|n,i=0|r;const O=ct.add3L(x,S,C);n=ct.add3H(O,A,k,I),r=0|O}({h:n,l:r}=ct.add(0|this.Ah,0|this.Al,0|n,0|r)),({h:o,l:i}=ct.add(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:a}=ct.add(0|this.Ch,0|this.Cl,0|s,0|a)),({h:c,l:u}=ct.add(0|this.Dh,0|this.Dl,0|c,0|u)),({h:l,l:f}=ct.add(0|this.Eh,0|this.El,0|l,0|f)),({h,l:d}=ct.add(0|this.Fh,0|this.Fl,0|h,0|d)),({h:p,l:g}=ct.add(0|this.Gh,0|this.Gl,0|p,0|g)),({h:y,l:m}=ct.add(0|this.Hh,0|this.Hl,0|y,0|m)),this.set(n,r,o,i,s,a,c,u,l,f,h,d,p,g,y,m)}roundClean(){ft.fill(0),ht.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const pt=je(()=>new dt),gt=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r.g)return r.g;throw new Error("unable to locate global object")}(),yt=gt.crypto||gt.msCrypto;function mt(e){switch(e){case"sha256":return Xe.create();case"sha512":return pt.create()}oe(!1,"invalid hashing algorithm name","algorithm",e)}const wt=function(e){return mt("sha256").update(e).digest()},bt=function(e){return mt("sha512").update(e).digest()};let vt=wt,Et=bt,At=!1,xt=!1;function kt(e){const t=le(e,"data");return ge(vt(t))}function St(e){const t=le(e,"data");return ge(Et(t))}kt._=wt,kt.lock=function(){At=!0},kt.register=function(e){if(At)throw new Error("sha256 is locked");vt=e},Object.freeze(kt),St._=bt,St.lock=function(){xt=!0},St.register=function(e){if(xt)throw new Error("sha512 is locked");Et=e},Object.freeze(kt);const[It,Ct,Ot]=[[],[],[]],Tt=BigInt(0),Nt=BigInt(1),Pt=BigInt(2),Bt=BigInt(7),Rt=BigInt(256),Ut=BigInt(113);for(let e=0,t=Nt,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],It.push(2*(5*r+n)),Ct.push((e+1)*(e+2)/2%64);let o=Tt;for(let e=0;e<7;e++)t=(t<<Nt^(t>>Bt)*Ut)%Rt,t&Pt&&(o^=Nt<<(Nt<<BigInt(e))-Nt);Ot.push(o)}const[Dt,Lt]=rt(Ot,!0),Ft=(e,t,n)=>n>32?st(e,t,n):ot(e,t,n),_t=(e,t,n)=>n>32?at(e,t,n):it(e,t,n);class Mt extends _e{constructor(e,t,n,r=!1,o=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Se(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=Be(this.state)}keccak(){!function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,o=(t+2)%10,i=n[o],s=n[o+1],a=Ft(i,s,1)^n[r],c=_t(i,s,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],o=e[3];for(let n=0;n<24;n++){const r=Ct[n],i=Ft(t,o,r),s=_t(t,o,r),a=It[n];t=e[a],o=e[a+1],e[a]=i,e[a+1]=s}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=Dt[r],e[1]^=Lt[r]}n.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){Oe(this);const{blockLen:t,state:n}=this,r=(e=Fe(e)).length;for(let o=0;o<r;){const i=Math.min(t-this.pos,r-o);for(let t=0;t<i;t++)n[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){Oe(this,!1),Ie(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,o=e.length;r<o;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,o-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Se(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Te(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:o,enableXOF:i}=this;return e||(e=new Mt(t,n,r,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const Gt=((e,t,n)=>je(()=>new Mt(t,e,n)))(1,136,32);let jt=!1;const Ht=function(e){return Gt(e)};let zt=Ht;function Vt(e){const t=le(e,"data");return ge(zt(t))}var Kt;Vt._=Ht,Vt.lock=function(){jt=!0},Vt.register=function(e){if(jt)throw new TypeError("keccak256 is locked");zt=e},Object.freeze(Vt),function(e){e.DEVICE_REGISTERED="deviceRegistered",e.DEVICE_REMOVED="deviceRemoved",e.AUTHENTICATION_SUCCESS="authenticationSuccess",e.AUTHENTICATION_FAILED="authenticationFailed",e.ERROR="error"}(Kt||(Kt={}));const Wt="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function $t(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function qt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Jt(e,...t){if(!$t(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Qt(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");qt(e.outputLen),qt(e.blockLen)}function Zt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Yt(e,t){Jt(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Xt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function en(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function tn(e,t){return e<<32-t|e>>>t}function nn(e,t){return e<<t|e>>>32-t>>>0}function rn(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const on=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=rn(e[t]);return e},sn=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),an=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function cn(e){if(Jt(e),sn)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=an[e[n]];return t}function un(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function ln(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(sn)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,o=0;t<n;t++,o+=2){const n=un(e.charCodeAt(o)),i=un(e.charCodeAt(o+1));if(void 0===n||void 0===i){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}r[t]=16*n+i}return r}function fn(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}function hn(e){return"string"==typeof e&&(e=fn(e)),Jt(e),e}function dn(e){return"string"==typeof e&&(e=fn(e)),Jt(e),e}function pn(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];Jt(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const o=e[t];n.set(o,r),r+=o.length}return n}class gn{}function yn(e){const t=t=>e().update(hn(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function mn(e=32){if(Wt&&"function"==typeof Wt.getRandomValues)return Wt.getRandomValues(new Uint8Array(e));if(Wt&&"function"==typeof Wt.randomBytes)return Uint8Array.from(Wt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function wn(e,t,n){return e&t^~e&n}function bn(e,t,n){return e&t^e&n^t&n}class vn extends gn{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=en(this.buffer)}update(e){Zt(this),Jt(e=hn(e));const{view:t,buffer:n,blockLen:r}=this,o=e.length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=en(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Zt(this),Yt(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,Xt(this.buffer.subarray(i)),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=en(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const En=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),An=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),xn=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),kn=BigInt(2**32-1),Sn=BigInt(32);function In(e,t=!1){return t?{h:Number(e&kn),l:Number(e>>Sn&kn)}:{h:0|Number(e>>Sn&kn),l:0|Number(e&kn)}}function Cn(e,t=!1){const n=e.length;let r=new Uint32Array(n),o=new Uint32Array(n);for(let i=0;i<n;i++){const{h:n,l:s}=In(e[i],t);[r[i],o[i]]=[n,s]}return[r,o]}const On=(e,t,n)=>e>>>n,Tn=(e,t,n)=>e<<32-n|t>>>n,Nn=(e,t,n)=>e>>>n|t<<32-n,Pn=(e,t,n)=>e<<32-n|t>>>n,Bn=(e,t,n)=>e<<64-n|t>>>n-32,Rn=(e,t,n)=>e>>>n-32|t<<64-n;function Un(e,t,n,r){const o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:0|o}}const Dn=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Ln=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Fn=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),_n=(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,Mn=(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0),Gn=(e,t,n,r,o,i)=>t+n+r+o+i+(e/2**32|0)|0,jn=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Hn=new Uint32Array(64);class zn extends vn{constructor(e=32){super(64,e,8,!1),this.A=0|En[0],this.B=0|En[1],this.C=0|En[2],this.D=0|En[3],this.E=0|En[4],this.F=0|En[5],this.G=0|En[6],this.H=0|En[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)Hn[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Hn[e-15],n=Hn[e-2],r=tn(t,7)^tn(t,18)^t>>>3,o=tn(n,17)^tn(n,19)^n>>>10;Hn[e]=o+Hn[e-7]+r+Hn[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(tn(s,6)^tn(s,11)^tn(s,25))+wn(s,a,c)+jn[e]+Hn[e]|0,l=(tn(n,2)^tn(n,13)^tn(n,22))+bn(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){Xt(Hn)}destroy(){this.set(0,0,0,0,0,0,0,0),Xt(this.buffer)}}const Vn=(()=>Cn(["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(e=>BigInt(e))))(),Kn=(()=>Vn[0])(),Wn=(()=>Vn[1])(),$n=new Uint32Array(80),qn=new Uint32Array(80);class Jn extends vn{constructor(e=64){super(128,e,16,!1),this.Ah=0|xn[0],this.Al=0|xn[1],this.Bh=0|xn[2],this.Bl=0|xn[3],this.Ch=0|xn[4],this.Cl=0|xn[5],this.Dh=0|xn[6],this.Dl=0|xn[7],this.Eh=0|xn[8],this.El=0|xn[9],this.Fh=0|xn[10],this.Fl=0|xn[11],this.Gh=0|xn[12],this.Gl=0|xn[13],this.Hh=0|xn[14],this.Hl=0|xn[15]}get(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:o,Cl:i,Dh:s,Dl:a,Eh:c,El:u,Fh:l,Fl:f,Gh:h,Gl:d,Hh:p,Hl:g}=this;return[e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g]}set(e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|o,this.Cl=0|i,this.Dh=0|s,this.Dl=0|a,this.Eh=0|c,this.El=0|u,this.Fh=0|l,this.Fl=0|f,this.Gh=0|h,this.Gl=0|d,this.Hh=0|p,this.Hl=0|g}process(e,t){for(let n=0;n<16;n++,t+=4)$n[n]=e.getUint32(t),qn[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|$n[e-15],n=0|qn[e-15],r=Nn(t,n,1)^Nn(t,n,8)^On(t,0,7),o=Pn(t,n,1)^Pn(t,n,8)^Tn(t,n,7),i=0|$n[e-2],s=0|qn[e-2],a=Nn(i,s,19)^Bn(i,s,61)^On(i,0,6),c=Pn(i,s,19)^Rn(i,s,61)^Tn(i,s,6),u=Fn(o,c,qn[e-7],qn[e-16]),l=_n(u,r,a,$n[e-7],$n[e-16]);$n[e]=0|l,qn[e]=0|u}let{Ah:n,Al:r,Bh:o,Bl:i,Ch:s,Cl:a,Dh:c,Dl:u,Eh:l,El:f,Fh:h,Fl:d,Gh:p,Gl:g,Hh:y,Hl:m}=this;for(let e=0;e<80;e++){const t=Nn(l,f,14)^Nn(l,f,18)^Bn(l,f,41),w=Pn(l,f,14)^Pn(l,f,18)^Rn(l,f,41),b=l&h^~l&p,v=Mn(m,w,f&d^~f&g,Wn[e],qn[e]),E=Gn(v,y,t,b,Kn[e],$n[e]),A=0|v,x=Nn(n,r,28)^Bn(n,r,34)^Bn(n,r,39),k=Pn(n,r,28)^Rn(n,r,34)^Rn(n,r,39),S=n&o^n&s^o&s,I=r&i^r&a^i&a;y=0|p,m=0|g,p=0|h,g=0|d,h=0|l,d=0|f,({h:l,l:f}=Un(0|c,0|u,0|E,0|A)),c=0|s,u=0|a,s=0|o,a=0|i,o=0|n,i=0|r;const C=Dn(A,k,I);n=Ln(C,E,x,S),r=0|C}({h:n,l:r}=Un(0|this.Ah,0|this.Al,0|n,0|r)),({h:o,l:i}=Un(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:a}=Un(0|this.Ch,0|this.Cl,0|s,0|a)),({h:c,l:u}=Un(0|this.Dh,0|this.Dl,0|c,0|u)),({h:l,l:f}=Un(0|this.Eh,0|this.El,0|l,0|f)),({h,l:d}=Un(0|this.Fh,0|this.Fl,0|h,0|d)),({h:p,l:g}=Un(0|this.Gh,0|this.Gl,0|p,0|g)),({h:y,l:m}=Un(0|this.Hh,0|this.Hl,0|y,0|m)),this.set(n,r,o,i,s,a,c,u,l,f,h,d,p,g,y,m)}roundClean(){Xt($n,qn)}destroy(){Xt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class Qn extends Jn{constructor(){super(48),this.Ah=0|An[0],this.Al=0|An[1],this.Bh=0|An[2],this.Bl=0|An[3],this.Ch=0|An[4],this.Cl=0|An[5],this.Dh=0|An[6],this.Dl=0|An[7],this.Eh=0|An[8],this.El=0|An[9],this.Fh=0|An[10],this.Fl=0|An[11],this.Gh=0|An[12],this.Gl=0|An[13],this.Hh=0|An[14],this.Hl=0|An[15]}}const Zn=yn(()=>new zn),Yn=yn(()=>new Jn),Xn=yn(()=>new Qn);class er extends gn{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Qt(e);const n=hn(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),Xt(o)}update(e){return Zt(this),this.iHash.update(e),this}digestInto(e){Zt(this),Jt(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const tr=(e,t,n)=>new er(e,t).update(n).digest();tr.create=(e,t)=>new er(e,t);const nr=BigInt(0),rr=BigInt(1);function or(e,t=""){if("boolean"!=typeof e)throw new Error((t&&`"${t}"`)+"expected boolean, got type="+typeof e);return e}function ir(e,t,n=""){const r=$t(e),o=e?.length,i=void 0!==t;if(!r||i&&o!==t)throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(i?` of length ${t}`:"")+", got "+(r?`length=${o}`:"type="+typeof e));return e}function sr(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function ar(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?nr:BigInt("0x"+e)}function cr(e){return ar(cn(e))}function ur(e){return Jt(e),ar(cn(Uint8Array.from(e).reverse()))}function lr(e,t){return ln(e.toString(16).padStart(2*t,"0"))}function fr(e,t){return lr(e,t).reverse()}function hr(e,t,n){let r;if("string"==typeof t)try{r=ln(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!$t(t))throw new Error(e+" must be hex string or Uint8Array");r=Uint8Array.from(t)}const o=r.length;if("number"==typeof n&&o!==n)throw new Error(e+" of length "+n+" expected, got "+o);return r}const dr=e=>"bigint"==typeof e&&nr<=e;function pr(e){let t;for(t=0;e>nr;e>>=rr,t+=1);return t}const gr=e=>(rr<<BigInt(e))-rr;function yr(e,t,n={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function r(t,n,r){const o=e[t];if(r&&void 0===o)return;const i=typeof o;if(i!==n||null===o)throw new Error(`param "${t}" is invalid: expected ${n}, got ${i}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function mr(e){const t=new WeakMap;return(n,...r)=>{const o=t.get(n);if(void 0!==o)return o;const i=e(n,...r);return t.set(n,i),i}}const wr=BigInt(0),br=BigInt(1),vr=BigInt(2),Er=BigInt(3),Ar=BigInt(4),xr=BigInt(5),kr=BigInt(7),Sr=BigInt(8),Ir=BigInt(9),Cr=BigInt(16);function Or(e,t){const n=e%t;return n>=wr?n:t+n}function Tr(e,t,n){let r=e;for(;t-- >wr;)r*=r,r%=n;return r}function Nr(e,t){if(e===wr)throw new Error("invert: expected non-zero number");if(t<=wr)throw new Error("invert: expected positive modulus, got "+t);let n=Or(e,t),r=t,o=wr,i=br,s=br,a=wr;for(;n!==wr;){const e=r/n,t=r%n,c=o-s*e,u=i-a*e;r=n,n=t,o=s,i=a,s=c,a=u}if(r!==br)throw new Error("invert: does not exist");return Or(o,t)}function Pr(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function Br(e,t){const n=(e.ORDER+br)/Ar,r=e.pow(t,n);return Pr(e,r,t),r}function Rr(e,t){const n=(e.ORDER-xr)/Sr,r=e.mul(t,vr),o=e.pow(r,n),i=e.mul(t,o),s=e.mul(e.mul(i,vr),o),a=e.mul(i,e.sub(s,e.ONE));return Pr(e,a,t),a}function Ur(e){if(e<Er)throw new Error("sqrt is not defined for small field");let t=e-br,n=0;for(;t%vr===wr;)t/=vr,n++;let r=vr;const o=Mr(e);for(;1===Fr(o,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return Br;let i=o.pow(r,t);const s=(t+br)/vr;return function(e,r){if(e.is0(r))return r;if(1!==Fr(e,r))throw new Error("Cannot find square root");let o=n,a=e.mul(e.ONE,i),c=e.pow(r,t),u=e.pow(r,s);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===o)throw new Error("Cannot find square root");const r=br<<BigInt(o-t-1),i=e.pow(a,r);o=t,a=e.sqr(i),c=e.mul(c,a),u=e.mul(u,i)}return u}}const Dr=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Lr(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),o=t.reduce((t,n,o)=>e.is0(n)?t:(r[o]=t,e.mul(t,n)),e.ONE),i=e.inv(o);return t.reduceRight((t,n,o)=>e.is0(n)?t:(r[o]=e.mul(t,r[o]),e.mul(t,n)),i),r}function Fr(e,t){const n=(e.ORDER-br)/vr,r=e.pow(t,n),o=e.eql(r,e.ONE),i=e.eql(r,e.ZERO),s=e.eql(r,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function _r(e,t){void 0!==t&&qt(t);const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Mr(e,t,n=!1,r={}){if(e<=wr)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i,s,a=!1;if("object"==typeof t&&null!=t){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const e=t;e.BITS&&(o=e.BITS),e.sqrt&&(i=e.sqrt),"boolean"==typeof e.isLE&&(n=e.isLE),"boolean"==typeof e.modFromBytes&&(a=e.modFromBytes),s=e.allowedLengths}else"number"==typeof t&&(o=t),r.sqrt&&(i=r.sqrt);const{nBitLength:c,nByteLength:u}=_r(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const f=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:u,MASK:gr(c),ZERO:wr,ONE:br,allowedLengths:s,create:t=>Or(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return wr<=t&&t<e},is0:e=>e===wr,isValidNot0:e=>!f.is0(e)&&f.isValid(e),isOdd:e=>(e&br)===br,neg:t=>Or(-t,e),eql:(e,t)=>e===t,sqr:t=>Or(t*t,e),add:(t,n)=>Or(t+n,e),sub:(t,n)=>Or(t-n,e),mul:(t,n)=>Or(t*n,e),pow:(e,t)=>function(e,t,n){if(n<wr)throw new Error("invalid exponent, negatives unsupported");if(n===wr)return e.ONE;if(n===br)return t;let r=e.ONE,o=t;for(;n>wr;)n&br&&(r=e.mul(r,o)),o=e.sqr(o),n>>=br;return r}(f,e,t),div:(t,n)=>Or(t*Nr(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Nr(t,e),sqrt:i||(t=>{return l||(l=(n=e)%Ar===Er?Br:n%Sr===xr?Rr:n%Cr===Ir?function(e){const t=Mr(e),n=Ur(e),r=n(t,t.neg(t.ONE)),o=n(t,r),i=n(t,t.neg(r)),s=(e+kr)/Cr;return(e,t)=>{let n=e.pow(t,s),a=e.mul(n,r);const c=e.mul(n,o),u=e.mul(n,i),l=e.eql(e.sqr(a),t),f=e.eql(e.sqr(c),t);n=e.cmov(n,a,l),a=e.cmov(u,c,f);const h=e.eql(e.sqr(a),t),d=e.cmov(n,a,h);return Pr(e,d,t),d}}(n):Ur(n)),l(f,t);var n}),toBytes:e=>n?fr(e,u):lr(e,u),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>u)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);const e=new Uint8Array(u);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+t.length);let o=n?ur(t):cr(t);if(a&&(o=Or(o,e)),!r&&!f.isValid(o))throw new Error("invalid field element: outside of range 0..ORDER");return o},invertBatch:e=>Lr(f,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(f)}function Gr(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function jr(e){const t=Gr(e);return t+Math.ceil(t/2)}const Hr=BigInt(0),zr=BigInt(1);function Vr(e,t){const n=t.negate();return e?n:t}function Kr(e,t){const n=Lr(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Wr(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function $r(e,t){Wr(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:gr(e),maxNumber:n,shiftBy:BigInt(e)}}function qr(e,t,n){const{windowSize:r,mask:o,maxNumber:i,shiftBy:s}=n;let a=Number(e&o),c=e>>s;a>r&&(a-=i,c+=zr);const u=t*r;return{nextN:c,offset:u+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:u}}const Jr=new WeakMap,Qr=new WeakMap;function Zr(e){return Qr.get(e)||1}function Yr(e){if(e!==Hr)throw new Error("invalid wNAF")}class Xr{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>Hr;)t&zr&&(n=n.add(r)),r=r.double(),t>>=zr;return n}precomputeWindow(e,t){const{windows:n,windowSize:r}=$r(t,this.bits),o=[];let i=e,s=i;for(let e=0;e<n;e++){s=i,o.push(s);for(let e=1;e<r;e++)s=s.add(i),o.push(s);i=s.double()}return o}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,o=this.BASE;const i=$r(e,this.bits);for(let e=0;e<i.windows;e++){const{nextN:s,offset:a,isZero:c,isNeg:u,isNegF:l,offsetF:f}=qr(n,e,i);n=s,c?o=o.add(Vr(l,t[f])):r=r.add(Vr(u,t[a]))}return Yr(n),{p:r,f:o}}wNAFUnsafe(e,t,n,r=this.ZERO){const o=$r(e,this.bits);for(let e=0;e<o.windows&&n!==Hr;e++){const{nextN:i,offset:s,isZero:a,isNeg:c}=qr(n,e,o);if(n=i,!a){const e=t[s];r=r.add(c?e.negate():e)}}return Yr(n),r}getPrecomputes(e,t,n){let r=Jr.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Jr.set(t,r))),r}cached(e,t,n){const r=Zr(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){const o=Zr(e);return 1===o?this._unsafeLadder(e,t,r):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),t,r)}createCache(e,t){Wr(t,this.bits),Qr.set(e,t),Jr.delete(e)}hasCache(e){return 1!==Zr(e)}}function eo(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){yr(e,Dr.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return Mr(e,{isLE:n})}const to=(e,t)=>(e+(e>=0?t:-t)/co)/t;function no(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ro(e,t){const n={};for(let r of Object.keys(t))n[r]=void 0===e[r]?t[r]:e[r];return or(n.lowS,"lowS"),or(n.prehash,"prehash"),void 0!==n.format&&no(n.format),n}class oo extends Error{constructor(e=""){super(e)}}const io={Err:oo,_tlv:{encode:(e,t)=>{const{Err:n}=io;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");const r=t.length/2,o=sr(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");const i=r>127?sr(o.length/2|128):"";return sr(e)+i+o+t},decode(e,t){const{Err:n}=io;let r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");const o=t[r++];let i=0;if(128&o){const e=127&o;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)i=i<<8|e;if(r+=e,i<128)throw new n("tlv.decode(long): not minimal encoding")}else i=o;const s=t.subarray(r,r+i);if(s.length!==i)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+i)}}},_int:{encode(e){const{Err:t}=io;if(e<so)throw new t("integer: negative integers are not allowed");let n=sr(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){const{Err:t}=io;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return cr(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=io,o=hr("signature",e),{v:i,l:s}=r.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,i),{v:u,l}=r.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(e){const{_tlv:t,_int:n}=io,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},so=BigInt(0),ao=BigInt(1),co=BigInt(2),uo=BigInt(3),lo=BigInt(4);function fo(e,t){const{BYTES:n}=e;let r;if("bigint"==typeof t)r=t;else{let o=hr("private key",t);try{r=e.fromBytes(o)}catch(e){throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function ho(e,t={}){const n=function(e,t,n={},r){if(void 0===r&&(r="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const n=t[e];if(!("bigint"==typeof n&&n>Hr))throw new Error(`CURVE.${e} must be positive bigint`)}const o=eo(t.p,n.Fp,r),i=eo(t.n,n.Fn,r),s=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const e of s)if(!o.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:i}}("weierstrass",e,t),{Fp:r,Fn:o}=n;let i=n.CURVE;const{h:s,n:a}=i;yr(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=t;if(c&&(!r.is0(i.a)||"bigint"!=typeof c.beta||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=go(r,o);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const f=t.toBytes||function(e,t,n){const{x:o,y:i}=t.toAffine(),s=r.toBytes(o);return or(n,"isCompressed"),n?(l(),pn(po(!r.isOdd(i)),s)):pn(Uint8Array.of(4),s,r.toBytes(i))},h=t.fromBytes||function(e){ir(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:n}=u,o=e.length,i=e[0],s=e.subarray(1);if(o!==t||2!==i&&3!==i){if(o===n&&4===i){const e=r.BYTES,t=r.fromBytes(s.subarray(0,e)),n=r.fromBytes(s.subarray(e,2*e));if(!p(t,n))throw new Error("bad point: is not on curve");return{x:t,y:n}}throw new Error(`bad point: got length ${o}, expected compressed=${t} or uncompressed=${n}`)}{const e=r.fromBytes(s);if(!r.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=d(e);let n;try{n=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}return l(),!(1&~i)!==r.isOdd(n)&&(n=r.neg(n)),{x:e,y:n}}};function d(e){const t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,i.a)),i.b)}function p(e,t){const n=r.sqr(t),o=d(e);return r.eql(n,o)}if(!p(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const g=r.mul(r.pow(i.a,uo),lo),y=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(g,y)))throw new Error("bad curve params: a or b");function m(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function w(e){if(!(e instanceof x))throw new Error("ProjectivePoint expected")}function b(e){if(!c||!c.basises)throw new Error("no endo");return function(e,t,n){const[[r,o],[i,s]]=t,a=to(s*e,n),c=to(-o*e,n);let u=e-a*r-c*i,l=-a*o-c*s;const f=u<so,h=l<so;f&&(u=-u),h&&(l=-l);const d=gr(Math.ceil(pr(n)/2))+ao;if(u<so||u>=d||l<so||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:u,k2neg:h,k2:l}}(e,c.basises,o.ORDER)}const v=mr((e,t)=>{const{X:n,Y:o,Z:i}=e;if(r.eql(i,r.ONE))return{x:n,y:o};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(i));const a=r.mul(n,t),c=r.mul(o,t),u=r.mul(i,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw new Error("invZ was invalid");return{x:a,y:c}}),E=mr(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:n,y:o}=e.toAffine();if(!r.isValid(n)||!r.isValid(o))throw new Error("bad point: x or y not field elements");if(!p(n,o))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(e,t,n,o,i){return n=new x(r.mul(n.X,e),n.Y,n.Z),t=Vr(o,t),n=Vr(i,n),t.add(n)}class x{constructor(e,t,n){this.X=m("x",e),this.Y=m("y",t,!0),this.Z=m("z",n),Object.freeze(this)}static CURVE(){return i}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof x)throw new Error("projective point not allowed");return r.is0(t)&&r.is0(n)?x.ZERO:new x(t,n,r.ONE)}static fromBytes(e){const t=x.fromAffine(h(ir(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return x.fromBytes(hr("pointHex",e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return S.createCache(this,e),t||this.multiply(uo),this}assertValidity(){E(this)}hasEvenY(){const{y:e}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(e)}equals(e){w(e);const{X:t,Y:n,Z:o}=this,{X:i,Y:s,Z:a}=e,c=r.eql(r.mul(t,a),r.mul(i,o)),u=r.eql(r.mul(n,a),r.mul(s,o));return c&&u}negate(){return new x(this.X,r.neg(this.Y),this.Z)}double(){const{a:e,b:t}=i,n=r.mul(t,uo),{X:o,Y:s,Z:a}=this;let c=r.ZERO,u=r.ZERO,l=r.ZERO,f=r.mul(o,o),h=r.mul(s,s),d=r.mul(a,a),p=r.mul(o,s);return p=r.add(p,p),l=r.mul(o,a),l=r.add(l,l),c=r.mul(e,l),u=r.mul(n,d),u=r.add(c,u),c=r.sub(h,u),u=r.add(h,u),u=r.mul(c,u),c=r.mul(p,c),l=r.mul(n,l),d=r.mul(e,d),p=r.sub(f,d),p=r.mul(e,p),p=r.add(p,l),l=r.add(f,f),f=r.add(l,f),f=r.add(f,d),f=r.mul(f,p),u=r.add(u,f),d=r.mul(s,a),d=r.add(d,d),f=r.mul(d,p),c=r.sub(c,f),l=r.mul(d,h),l=r.add(l,l),l=r.add(l,l),new x(c,u,l)}add(e){w(e);const{X:t,Y:n,Z:o}=this,{X:s,Y:a,Z:c}=e;let u=r.ZERO,l=r.ZERO,f=r.ZERO;const h=i.a,d=r.mul(i.b,uo);let p=r.mul(t,s),g=r.mul(n,a),y=r.mul(o,c),m=r.add(t,n),b=r.add(s,a);m=r.mul(m,b),b=r.add(p,g),m=r.sub(m,b),b=r.add(t,o);let v=r.add(s,c);return b=r.mul(b,v),v=r.add(p,y),b=r.sub(b,v),v=r.add(n,o),u=r.add(a,c),v=r.mul(v,u),u=r.add(g,y),v=r.sub(v,u),f=r.mul(h,b),u=r.mul(d,y),f=r.add(u,f),u=r.sub(g,f),f=r.add(g,f),l=r.mul(u,f),g=r.add(p,p),g=r.add(g,p),y=r.mul(h,y),b=r.mul(d,b),g=r.add(g,y),y=r.sub(p,y),y=r.mul(h,y),b=r.add(b,y),p=r.mul(g,b),l=r.add(l,p),p=r.mul(v,b),u=r.mul(m,u),u=r.sub(u,p),p=r.mul(m,g),f=r.mul(v,f),f=r.add(f,p),new x(u,l,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(x.ZERO)}multiply(e){const{endo:n}=t;if(!o.isValidNot0(e))throw new Error("invalid scalar: out of range");let r,i;const s=e=>S.cached(this,e,e=>Kr(x,e));if(n){const{k1neg:t,k1:o,k2neg:a,k2:c}=b(e),{p:u,f:l}=s(o),{p:f,f:h}=s(c);i=l.add(h),r=A(n.beta,u,f,t,a)}else{const{p:t,f:n}=s(e);r=t,i=n}return Kr(x,[r,i])[0]}multiplyUnsafe(e){const{endo:n}=t,r=this;if(!o.isValid(e))throw new Error("invalid scalar: out of range");if(e===so||r.is0())return x.ZERO;if(e===ao)return r;if(S.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:o,k2neg:i,k2:s}=b(e),{p1:a,p2:c}=function(e,t,n,r){let o=t,i=e.ZERO,s=e.ZERO;for(;n>Hr||r>Hr;)n&zr&&(i=i.add(o)),r&zr&&(s=s.add(o)),o=o.double(),n>>=zr,r>>=zr;return{p1:i,p2:s}}(x,r,o,s);return A(n.beta,a,c,t,i)}return S.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return v(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===ao||(e?e(x,this):S.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===ao?this:e?e(x,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return or(e,"isCompressed"),this.assertValidity(),f(x,this,e)}toHex(e=!0){return cn(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return Kr(x,e)}static msm(e,t){return function(e,t,n,r){(function(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})})(n,e),function(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}(r,t);const o=n.length,i=r.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");const s=e.ZERO,a=pr(BigInt(o));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=gr(c),l=new Array(Number(u)+1).fill(s);let f=s;for(let e=Math.floor((t.BITS-1)/c)*c;e>=0;e-=c){l.fill(s);for(let t=0;t<i;t++){const o=r[t],i=Number(o>>BigInt(e)&u);l[i]=l[i].add(n[t])}let t=s;for(let e=l.length-1,n=s;e>0;e--)n=n.add(l[e]),t=t.add(n);if(f=f.add(t),0!==e)for(let e=0;e<c;e++)f=f.double()}return f}(x,o,e,t)}static fromPrivateKey(e){return x.BASE.multiply(fo(o,e))}}x.BASE=new x(i.Gx,i.Gy,r.ONE),x.ZERO=new x(r.ZERO,r.ONE,r.ZERO),x.Fp=r,x.Fn=o;const k=o.BITS,S=new Xr(x,t.endo?Math.ceil(k/2):k);return x.BASE.precompute(8),x}function po(e){return Uint8Array.of(e?2:3)}function go(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function yo(e,t,n={}){Qt(t),yr(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||mn,o=n.hmac||((e,...n)=>tr(t,e,pn(...n))),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d}=function(e,t={}){const{Fn:n}=e,r=t.randomBytes||mn,o=Object.assign(go(e.Fp,n),{seed:jr(n.ORDER)});function i(e){try{return!!fo(n,e)}catch(e){return!1}}function s(e=r(o.seed)){return function(e,t,n=!1){const r=e.length,o=Gr(t),i=jr(t);if(r<16||r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);const s=Or(n?ur(e):cr(e),t-br)+br;return n?fr(s,o):lr(s,o)}(ir(e,o.seed,"seed"),n.ORDER)}function a(t,r=!0){return e.BASE.multiply(fo(n,t)).toBytes(r)}function c(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const{secretKey:r,publicKey:i,publicKeyUncompressed:s}=o;if(n.allowedLengths||r===i)return;const a=hr("key",t).length;return a===i||a===s}const u={isValidSecretKey:i,isValidPublicKey:function(t,n){const{publicKey:r,publicKeyUncompressed:i}=o;try{const o=t.length;return!(!0===n&&o!==r||!1===n&&o!==i||!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:s,isValidPrivateKey:i,randomPrivateKey:s,normPrivateKeyToScalar:e=>fo(n,e),precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};return Object.freeze({getPublicKey:a,getSharedSecret:function(t,r,o=!0){if(!0===c(t))throw new Error("first arg must be private key");if(!1===c(r))throw new Error("second arg must be public key");const i=fo(n,t);return e.fromHex(r).multiply(i).toBytes(o)},keygen:function(e){const t=s(e);return{secretKey:t,publicKey:a(t)}},Point:e,utils:u,lengths:o})}(e,n),p={prehash:!1,lowS:"boolean"==typeof n.lowS&&n.lowS,format:void 0,extraEntropy:!1},g="compact";function y(e){return e>a>>ao}function m(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}class w{constructor(e,t,n){this.r=m("r",e),this.s=m("s",t),null!=n&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=g){let n;if(function(e,t){no(t);const n=d.signature;ir(e,"compact"===t?n:"recovered"===t?n+1:void 0,`${t} signature`)}(e,t),"der"===t){const{r:t,s:n}=io.toSig(ir(e));return new w(t,n)}"recovered"===t&&(n=e[0],t="compact",e=e.subarray(1));const r=s.BYTES,o=e.subarray(0,r),i=e.subarray(r,2*r);return new w(s.fromBytes(o),s.fromBytes(i),n)}static fromHex(e,t){return this.fromBytes(ln(e),t)}addRecoveryBit(e){return new w(this.r,this.s,e)}recoverPublicKey(t){const n=i.ORDER,{r,s:o,recovery:c}=this;if(null==c||![0,1,2,3].includes(c))throw new Error("recovery id invalid");if(a*co<n&&c>1)throw new Error("recovery id is ambiguous for h>1 curve");const u=2===c||3===c?r+a:r;if(!i.isValid(u))throw new Error("recovery id 2 or 3 invalid");const l=i.toBytes(u),f=e.fromBytes(pn(po(!(1&c)),l)),h=s.inv(u),d=v(hr("msgHash",t)),p=s.create(-d*h),g=s.create(o*h),y=e.BASE.multiplyUnsafe(p).add(f.multiplyUnsafe(g));if(y.is0())throw new Error("point at infinify");return y.assertValidity(),y}hasHighS(){return y(this.s)}toBytes(e=g){if(no(e),"der"===e)return ln(io.hexFromSig(this));const t=s.toBytes(this.r),n=s.toBytes(this.s);if("recovered"===e){if(null==this.recovery)throw new Error("recovery bit must be present");return pn(Uint8Array.of(this.recovery),t,n)}return pn(t,n)}toHex(e){return cn(this.toBytes(e))}assertValidity(){}static fromCompact(e){return w.fromBytes(hr("sig",e),"compact")}static fromDER(e){return w.fromBytes(hr("sig",e),"der")}normalizeS(){return this.hasHighS()?new w(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return cn(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return cn(this.toBytes("compact"))}}const b=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=cr(e),n=8*e.length-c;return n>0?t>>BigInt(n):t},v=n.bits2int_modN||function(e){return s.create(b(e))},E=gr(c);function A(e){return function(e,t,n,r){if(!function(e,t,n){return dr(e)&&dr(t)&&dr(n)&&t<=e&&e<n}(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}("num < 2^"+c,e,so,E),s.toBytes(e)}function x(e,n){return ir(e,void 0,"message"),n?ir(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d,Point:e,sign:function(n,i,a={}){n=hr("message",n);const{seed:c,k2sig:u}=function(t,n,o){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");const{lowS:i,prehash:a,extraEntropy:c}=ro(o,p);t=x(t,a);const u=v(t),l=fo(s,n),f=[A(l),A(u)];if(null!=c&&!1!==c){const e=!0===c?r(d.secretKey):c;f.push(hr("extraEntropy",e))}const h=pn(...f),g=u;return{seed:h,k2sig:function(t){const n=b(t);if(!s.isValidNot0(n))return;const r=s.inv(n),o=e.BASE.multiply(n).toAffine(),a=s.create(o.x);if(a===so)return;const c=s.create(r*s.create(g+a*l));if(c===so)return;let u=(o.x===a?0:2)|Number(o.y&ao),f=c;return i&&y(c)&&(f=s.neg(c),u^=1),new w(a,f,u)}}}(n,i,a),l=function(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");const r=e=>new Uint8Array(e),o=e=>Uint8Array.of(e);let i=r(e),s=r(e),a=0;const c=()=>{i.fill(1),s.fill(0),a=0},u=(...e)=>n(s,i,...e),l=(e=r(0))=>{s=u(o(0),e),i=u(),0!==e.length&&(s=u(o(1),e),i=u())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){i=u();const t=i.slice();n.push(t),e+=i.length}return pn(...n)};return(e,t)=>{let n;for(c(),l(e);!(n=t(f()));)l();return c(),n}}(t.outputLen,s.BYTES,o);return l(c,u)},verify:function(t,n,r,o={}){const{lowS:i,prehash:a,format:c}=ro(o,p);if(r=hr("publicKey",r),n=x(hr("message",n),a),"strict"in o)throw new Error("options.strict was renamed to lowS");const u=void 0===c?function(e){let t;const n="string"==typeof e||$t(e),r=!n&&null!==e&&"object"==typeof e&&"bigint"==typeof e.r&&"bigint"==typeof e.s;if(!n&&!r)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)t=new w(e.r,e.s);else if(n){try{t=w.fromBytes(hr("sig",e),"der")}catch(e){if(!(e instanceof io.Err))throw e}if(!t)try{t=w.fromBytes(hr("sig",e),"compact")}catch(e){return!1}}return t||!1}(t):w.fromBytes(hr("sig",t),c);if(!1===u)return!1;try{const t=e.fromBytes(r);if(i&&u.hasHighS())return!1;const{r:o,s:a}=u,c=v(n),l=s.inv(a),f=s.create(c*l),h=s.create(o*l),d=e.BASE.multiplyUnsafe(f).add(t.multiplyUnsafe(h));return!d.is0()&&s.create(d.x)===o}catch(e){return!1}},recoverPublicKey:function(e,t,n={}){const{prehash:r}=ro(n,p);return t=x(t,r),w.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:w,hash:t})}function mo(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:o}=function(e){const{CURVE:t,curveOpts:n}=function(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:Mr(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}(e);return function(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,_r(n.Fn.ORDER,n.Fn.BITS))})}(e,yo(ho(t,n),r,o))}function wo(e,t){const n=t=>mo({...e,hash:t});return{...n(t),create:n}}const bo={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},vo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},Eo={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},Ao=Mr(bo.p),xo=Mr(vo.p),ko=Mr(Eo.p),So=wo({...bo,Fp:Ao,lowS:!1},Zn);wo({...vo,Fp:xo,lowS:!1},Xn),wo({...Eo,Fp:ko,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},Yn);const Io=So,Co={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Oo={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},To=BigInt(2),No=Mr(Co.p,{sqrt:function(e){const t=Co.p,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=Tr(l,n,t)*l%t,h=Tr(f,n,t)*l%t,d=Tr(h,To,t)*u%t,p=Tr(d,o,t)*d%t,g=Tr(p,i,t)*p%t,y=Tr(g,a,t)*g%t,m=Tr(y,c,t)*y%t,w=Tr(m,a,t)*g%t,b=Tr(w,n,t)*l%t,v=Tr(b,s,t)*p%t,E=Tr(v,r,t)*u%t,A=Tr(E,To,t);if(!No.eql(No.sqr(A),e))throw new Error("Cannot find square root");return A}}),Po=wo({...Co,Fp:No,lowS:!0,endo:Oo},Zn),Bo=Zn;const Ro=BigInt(0),Uo=BigInt(1),Do=BigInt(2),Lo=BigInt(7),Fo=BigInt(256),_o=BigInt(113),Mo=[],Go=[],jo=[];for(let e=0,t=Uo,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Mo.push(2*(5*r+n)),Go.push((e+1)*(e+2)/2%64);let o=Ro;for(let e=0;e<7;e++)t=(t<<Uo^(t>>Lo)*_o)%Fo,t&Do&&(o^=Uo<<(Uo<<BigInt(e))-Uo);jo.push(o)}const Ho=Cn(jo,!0),zo=Ho[0],Vo=Ho[1],Ko=(e,t,n)=>n>32?((e,t,n)=>t<<n-32|e>>>64-n)(e,t,n):((e,t,n)=>e<<n|t>>>32-n)(e,t,n),Wo=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);class $o extends gn{constructor(e,t,n,r=!1,o=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=o,qt(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var i;this.state=new Uint8Array(200),this.state32=(i=this.state,new Uint32Array(i.buffer,i.byteOffset,Math.floor(i.byteLength/4)))}clone(){return this._cloneInto()}keccak(){on(this.state32),function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,o=(t+2)%10,i=n[o],s=n[o+1],a=Ko(i,s,1)^n[r],c=Wo(i,s,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],o=e[3];for(let n=0;n<24;n++){const r=Go[n],i=Ko(t,o,r),s=Wo(t,o,r),a=Mo[n];t=e[a],o=e[a+1],e[a]=i,e[a+1]=s}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=zo[r],e[1]^=Vo[r]}Xt(n)}(this.state32,this.rounds),on(this.state32),this.posOut=0,this.pos=0}update(e){Zt(this),Jt(e=hn(e));const{blockLen:t,state:n}=this,r=e.length;for(let o=0;o<r;){const i=Math.min(t-this.pos,r-o);for(let t=0;t<i;t++)n[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){Zt(this,!1),Jt(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,o=e.length;r<o;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,o-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return qt(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Yt(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,Xt(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:o,enableXOF:i}=this;return e||(e=new $o(t,n,r,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const qo=(()=>{return e=1,t=136,n=32,yn(()=>new $o(t,e,n));var e,t,n})(),Jo=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Qo=(()=>Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)))(),Zo=(()=>Qo.map(e=>(9*e+5)%16))(),Yo=(()=>{const e=[[Qo],[Zo]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Jo[e]));return e})(),Xo=(()=>Yo[0])(),ei=(()=>Yo[1])(),ti=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),ni=Xo.map((e,t)=>e.map(e=>ti[t][e])),ri=ei.map((e,t)=>e.map(e=>ti[t][e])),oi=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),ii=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function si(e,t,n,r){return 0===e?t^n^r:1===e?t&n|~t&r:2===e?(t|~n)^r:3===e?t&r|n&~r:t^(n|~r)}const ai=new Uint32Array(16);class ci extends vn{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:n,h3:r,h4:o}=this;return[e,t,n,r,o]}set(e,t,n,r,o){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|o}process(e,t){for(let n=0;n<16;n++,t+=4)ai[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,o=0|this.h1,i=o,s=0|this.h2,a=s,c=0|this.h3,u=c,l=0|this.h4,f=l;for(let e=0;e<5;e++){const t=4-e,h=oi[e],d=ii[e],p=Xo[e],g=ei[e],y=ni[e],m=ri[e];for(let t=0;t<16;t++){const r=nn(n+si(e,o,s,c)+ai[p[t]]+h,y[t])+l|0;n=l,l=c,c=0|nn(s,10),s=o,o=r}for(let e=0;e<16;e++){const n=nn(r+si(t,i,a,u)+ai[g[e]]+d,m[e])+f|0;r=f,f=u,u=0|nn(a,10),a=i,i=n}}this.set(this.h1+s+u|0,this.h2+c+f|0,this.h3+l+r|0,this.h4+n+i|0,this.h0+o+a|0)}roundClean(){Xt(ai)}destroy(){this.destroyed=!0,Xt(this.buffer),this.set(0,0,0,0,0)}}const ui=yn(()=>new ci);var li=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},fi=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},hi=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s};function di(e,t){return li(this,arguments,void 0,function(e,t,n){var r,o,i,s,a,c,u,l,f,h,d,p,g,y,m,w,b,v,E,A,x,k,S,I=this;return void 0===n&&(n={}),fi(this,function(C){switch(C.label){case 0:if(r=new TextEncoder,o=e?"string"==typeof e?r.encode(yi(e)):e:crypto.getRandomValues(new Uint8Array(32)),i=t?(Array.isArray(t)?t:[t]).map(function(e){return yi(e.toString())}):[],s=r.encode(i.join("|")),(a=new Uint8Array(o.length+s.length)).set(o),a.set(s,o.length),a.length<16)throw new Error("Insufficient input entropy (".concat(a.length,")"));return c="v1",u={},l=n.includeP256,f=void 0===l||l,h=n.includeSecp256k1Bitcoin,d=void 0===h||h,p=n.includeSecp256k1Ethereum,g=void 0===p||p,f?(y=[{label:"signing",type:"pub/priv"},{label:"encryption",type:"epub/epriv"}],[4,Promise.all(y.map(function(e){return li(I,[e],void 0,function(e){var t,n,o=e.label;return fi(this,function(e){switch(e.label){case 0:return t=r.encode("".concat(o,"-").concat(c)),[4,mi(a,t)];case 1:if(n=e.sent(),!Io.utils.isValidPrivateKey(n))throw new Error("Invalid private key for ".concat(o));return[2,{pub:gi(Io.getPublicKey(n,!1)),priv:pi(n)}]}})})}))]):[3,2];case 1:m=hi.apply(void 0,[C.sent(),2]),w=m[0],b=m[1],u.pub=w.pub,u.priv=w.priv,u.epub=b.pub,u.epriv=b.priv,C.label=2;case 2:return d?(v=r.encode("secp256k1-bitcoin-".concat(c)),[4,mi(a,v)]):[3,4];case 3:if(E=C.sent(),!Po.utils.isValidPrivateKey(E))throw new Error("Invalid secp256k1 private key for Bitcoin");A=Po.getPublicKey(E,!0),u.secp256k1Bitcoin={privateKey:bi(E),publicKey:bi(A),address:Ei(A)},C.label=4;case 4:return g?(x=r.encode("secp256k1-ethereum-".concat(c)),[4,mi(a,x)]):[3,6];case 5:if(k=C.sent(),!Po.utils.isValidPrivateKey(k))throw new Error("Invalid secp256k1 private key for Ethereum");S=Po.getPublicKey(k,!1),u.secp256k1Ethereum={privateKey:"0x"+bi(k),publicKey:"0x"+bi(S),address:(O=S,T=O.slice(1),N=qo(T),P=N.slice(-20),"0x"+bi(P))},C.label=6;case 6:return[2,u]}var O,T,N,P})})}function pi(e){for(var t=[],n=0;n<e.length;n++)t.push(String.fromCharCode(e[n]));return btoa(t.join("")).replace(/\//g,"_").replace(/=/g,"").replace(/\+/g,"-")}function gi(e){if(4!==e[0])throw new Error("Invalid uncompressed public key format");return[pi(e.slice(1,33)),pi(e.slice(33,65))].join(".")}function yi(e){return e.normalize("NFC").trim()}function mi(e,t){return li(this,arguments,void 0,function(e,t,n){var r,o,i,s;return void 0===n&&(n=3e5),fi(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,crypto.subtle.importKey("raw",e,{name:"PBKDF2"},!1,["deriveBits"])];case 1:return r=a.sent(),[4,crypto.subtle.deriveBits({name:"PBKDF2",salt:t,iterations:n,hash:"SHA-256"},r,256)];case 2:return o=a.sent(),[2,wi(new Uint8Array(o))];case 3:return a.sent(),i=e instanceof Uint8Array?e:new Uint8Array(e),s=function(e,t,n,r){const{c:o,dkLen:i,DK:s,PRF:a,PRFSalt:c}=function(e,t,n,r){Qt(e);const o=function(e,t){if(void 0!==t&&"[object Object]"!=={}.toString.call(t))throw new Error("options should be object or undefined");return Object.assign({dkLen:32,asyncTick:10},t)}(0,r),{c:i,dkLen:s,asyncTick:a}=o;if(qt(i),qt(s),qt(a),i<1)throw new Error("iterations (c) should be >= 1");const c=dn(t),u=dn(n),l=new Uint8Array(s),f=tr.create(e,c),h=f._cloneInto().update(u);return{c:i,dkLen:s,asyncTick:a,DK:l,PRF:f,PRFSalt:h}}(e,t,n,r);let u;const l=new Uint8Array(4),f=en(l),h=new Uint8Array(a.outputLen);for(let e=1,t=0;t<i;e++,t+=a.outputLen){const n=s.subarray(t,t+a.outputLen);f.setInt32(0,e,!1),(u=c._cloneInto(u)).update(l).digestInto(h),n.set(h.subarray(0,n.length));for(let e=1;e<o;e++){a._cloneInto(u).update(h).digestInto(h);for(let e=0;e<n.length;e++)n[e]^=h[e]}}return function(e,t,n,r,o){return e.destroy(),t.destroy(),r&&r.destroy(),Xt(o),n}(a,c,s,u,h)}(Bo,i,t,{c:n,dkLen:32}),[2,wi(s)];case 4:return[2]}})})}function wi(e){e.every(function(e){return 0===e})&&(e[0]=1);for(var t=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,186,174,220,230]),n=!0,r=0;r<32;r++){if(e[r]<t[r]){n=!1;break}if(e[r]>t[r])break}return n&&(e[31]=229),(e.every(function(e){return 0===e})||e.every(function(e){return 1===e}))&&(e.fill(0),e[0]=1,e[31]=255),e}function bi(e){return Array.from(e).map(function(e){return e.toString(16).padStart(2,"0")}).join("")}var vi="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function Ei(e){var t=Bo(e),n=ui(t),r=new Uint8Array(21);r[0]=0,r.set(n,1);var o=Bo(Bo(r)),i=new Uint8Array(25);return i.set(r),i.set(o.slice(0,4),21),function(e){if(0===e.length)return"";for(var t=0,n=0;n<e.length&&0===e[n];n++)t++;var r=[0];for(n=t;n<e.length;n++){for(var o=e[n],i=0;i<r.length;i++)o+=r[i]<<8,r[i]=o%58,o=o/58|0;for(;o>0;)r.push(o%58),o=o/58|0}var s="";for(n=0;n<t;n++)s+=vi[0];for(n=r.length-1;n>=0;n--)s+=vi[r[n]];return s}(i)}const Ai="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function xi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ki(e,...t){if(!((n=e)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Si(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");xi(e.outputLen),xi(e.blockLen)}function Ii(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ci(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Oi(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ti(e,t){return e<<32-t|e>>>t}const Ni=async()=>{};async function Pi(e,t,n){let r=Date.now();for(let o=0;o<e;o++){n(o);const e=Date.now()-r;e>=0&&e<t||(await Ni(),r+=e)}}function Bi(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}function Ri(e){return"string"==typeof e&&(e=Bi(e)),ki(e),e}function Ui(e){return"string"==typeof e&&(e=Bi(e)),ki(e),e}class Di{}function Li(e){const t=t=>e().update(Ri(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}class Fi extends Di{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Si(e);const n=Ri(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),Ci(o)}update(e){return Ii(this),this.iHash.update(e),this}digestInto(e){Ii(this),ki(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const _i=(e,t,n)=>new Fi(e,t).update(n).digest();function Mi(e,t,n){return e&t^~e&n}function Gi(e,t,n){return e&t^e&n^t&n}_i.create=(e,t)=>new Fi(e,t);class ji extends Di{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Oi(this.buffer)}update(e){Ii(this),ki(e=Ri(e));const{view:t,buffer:n,blockLen:r}=this,o=e.length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=Oi(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ii(this),function(e,t){ki(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,Ci(this.buffer.subarray(i)),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=Oi(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const Hi=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),zi=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Vi=BigInt(2**32-1),Ki=BigInt(32);function Wi(e,t=!1){return t?{h:Number(e&Vi),l:Number(e>>Ki&Vi)}:{h:0|Number(e>>Ki&Vi),l:0|Number(e&Vi)}}const $i=(e,t,n)=>e>>>n,qi=(e,t,n)=>e<<32-n|t>>>n,Ji=(e,t,n)=>e>>>n|t<<32-n,Qi=(e,t,n)=>e<<32-n|t>>>n,Zi=(e,t,n)=>e<<64-n|t>>>n-32,Yi=(e,t,n)=>e>>>n-32|t<<64-n;function Xi(e,t,n,r){const o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:0|o}}const es=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),ts=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,ns=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),rs=(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0,os=(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0),is=(e,t,n,r,o,i)=>t+n+r+o+i+(e/2**32|0)|0,ss=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),as=new Uint32Array(64);class cs extends ji{constructor(e=32){super(64,e,8,!1),this.A=0|Hi[0],this.B=0|Hi[1],this.C=0|Hi[2],this.D=0|Hi[3],this.E=0|Hi[4],this.F=0|Hi[5],this.G=0|Hi[6],this.H=0|Hi[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)as[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=as[e-15],n=as[e-2],r=Ti(t,7)^Ti(t,18)^t>>>3,o=Ti(n,17)^Ti(n,19)^n>>>10;as[e]=o+as[e-7]+r+as[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(Ti(s,6)^Ti(s,11)^Ti(s,25))+Mi(s,a,c)+ss[e]+as[e]|0,l=(Ti(n,2)^Ti(n,13)^Ti(n,22))+Gi(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){Ci(as)}destroy(){this.set(0,0,0,0,0,0,0,0),Ci(this.buffer)}}const us=(()=>function(e,t=!1){const n=e.length;let r=new Uint32Array(n),o=new Uint32Array(n);for(let i=0;i<n;i++){const{h:n,l:s}=Wi(e[i],t);[r[i],o[i]]=[n,s]}return[r,o]}(["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(e=>BigInt(e))))(),ls=(()=>us[0])(),fs=(()=>us[1])(),hs=new Uint32Array(80),ds=new Uint32Array(80);class ps extends ji{constructor(e=64){super(128,e,16,!1),this.Ah=0|zi[0],this.Al=0|zi[1],this.Bh=0|zi[2],this.Bl=0|zi[3],this.Ch=0|zi[4],this.Cl=0|zi[5],this.Dh=0|zi[6],this.Dl=0|zi[7],this.Eh=0|zi[8],this.El=0|zi[9],this.Fh=0|zi[10],this.Fl=0|zi[11],this.Gh=0|zi[12],this.Gl=0|zi[13],this.Hh=0|zi[14],this.Hl=0|zi[15]}get(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:o,Cl:i,Dh:s,Dl:a,Eh:c,El:u,Fh:l,Fl:f,Gh:h,Gl:d,Hh:p,Hl:g}=this;return[e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g]}set(e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|o,this.Cl=0|i,this.Dh=0|s,this.Dl=0|a,this.Eh=0|c,this.El=0|u,this.Fh=0|l,this.Fl=0|f,this.Gh=0|h,this.Gl=0|d,this.Hh=0|p,this.Hl=0|g}process(e,t){for(let n=0;n<16;n++,t+=4)hs[n]=e.getUint32(t),ds[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|hs[e-15],n=0|ds[e-15],r=Ji(t,n,1)^Ji(t,n,8)^$i(t,0,7),o=Qi(t,n,1)^Qi(t,n,8)^qi(t,n,7),i=0|hs[e-2],s=0|ds[e-2],a=Ji(i,s,19)^Zi(i,s,61)^$i(i,0,6),c=Qi(i,s,19)^Yi(i,s,61)^qi(i,s,6),u=ns(o,c,ds[e-7],ds[e-16]),l=rs(u,r,a,hs[e-7],hs[e-16]);hs[e]=0|l,ds[e]=0|u}let{Ah:n,Al:r,Bh:o,Bl:i,Ch:s,Cl:a,Dh:c,Dl:u,Eh:l,El:f,Fh:h,Fl:d,Gh:p,Gl:g,Hh:y,Hl:m}=this;for(let e=0;e<80;e++){const t=Ji(l,f,14)^Ji(l,f,18)^Zi(l,f,41),w=Qi(l,f,14)^Qi(l,f,18)^Yi(l,f,41),b=l&h^~l&p,v=os(m,w,f&d^~f&g,fs[e],ds[e]),E=is(v,y,t,b,ls[e],hs[e]),A=0|v,x=Ji(n,r,28)^Zi(n,r,34)^Zi(n,r,39),k=Qi(n,r,28)^Yi(n,r,34)^Yi(n,r,39),S=n&o^n&s^o&s,I=r&i^r&a^i&a;y=0|p,m=0|g,p=0|h,g=0|d,h=0|l,d=0|f,({h:l,l:f}=Xi(0|c,0|u,0|E,0|A)),c=0|s,u=0|a,s=0|o,a=0|i,o=0|n,i=0|r;const C=es(A,k,I);n=ts(C,E,x,S),r=0|C}({h:n,l:r}=Xi(0|this.Ah,0|this.Al,0|n,0|r)),({h:o,l:i}=Xi(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:a}=Xi(0|this.Ch,0|this.Cl,0|s,0|a)),({h:c,l:u}=Xi(0|this.Dh,0|this.Dl,0|c,0|u)),({h:l,l:f}=Xi(0|this.Eh,0|this.El,0|l,0|f)),({h,l:d}=Xi(0|this.Fh,0|this.Fl,0|h,0|d)),({h:p,l:g}=Xi(0|this.Gh,0|this.Gl,0|p,0|g)),({h:y,l:m}=Xi(0|this.Hh,0|this.Hl,0|y,0|m)),this.set(n,r,o,i,s,a,c,u,l,f,h,d,p,g,y,m)}roundClean(){Ci(hs,ds)}destroy(){Ci(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const gs=Li(()=>new cs),ys=Li(()=>new ps);function ms(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function ws(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function bs(e){if("function"!=typeof e)throw new Error("function expected");return!0}function vs(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function Es(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function As(e){if(!Array.isArray(e))throw new Error("array expected")}function xs(e,t){if(!ws(!0,t))throw new Error(`${e}: array of strings expected`)}function ks(e,t){if(!ws(!1,t))throw new Error(`${e}: array of numbers expected`)}function Ss(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function Is(e){const t="string"==typeof e?e.split(""):e,n=t.length;xs("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(As(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(As(t),t.map(t=>{vs("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function Cs(e=""){return vs("join",e),{encode:t=>(xs("join.decode",t),t.join(e)),decode:t=>(vs("join.decode",t),t.split(e))}}function Os(e,t="="){return Es(e),vs("padding",t),{encode(n){for(xs("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){xs("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding");return n.slice(0,r)}}}function Ts(e){return bs(e),{encode:e=>e,decode:t=>e(t)}}function Ns(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(As(e),!e.length)return[];let r=0;const o=[],i=Array.from(e,e=>{if(Es(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=i.length;for(;;){let e=0,a=!0;for(let o=r;o<s;o++){const s=i[o],c=t*e,u=c+s;if(!Number.isSafeInteger(u)||c/t!==e||u-s!==c)throw new Error("convertRadix: carry overflow");const l=u/n;e=u%n;const f=Math.floor(l);if(i[o]=f,!Number.isSafeInteger(f)||f*n+e!==u)throw new Error("convertRadix: carry overflow");a&&(f?a=!1:r=o)}if(o.push(e),a)break}for(let t=0;t<e.length-1&&0===e[t];t++)o.push(0);return o.reverse()}const Ps=(e,t)=>0===t?e:Ps(t,e%t),Bs=(e,t)=>e+(t-Ps(e,t)),Rs=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Us(e,t,n,r){if(As(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Bs(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Bs(t,n)}`);let o=0,i=0;const s=Rs[t],a=Rs[n]-1,c=[];for(const r of e){if(Es(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<<t|r,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=Rs[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<<n-i&a,!r&&i>=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}function Ds(e){return Es(e),{encode:t=>{if(!ms(t))throw new Error("radix.encode input should be Uint8Array");return Ns(Array.from(t),256,e)},decode:t=>(ks("radix.decode",t),Uint8Array.from(Ns(t,e,256)))}}function Ls(e,t=!1){if(Es(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Bs(8,e)>32||Bs(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!ms(n))throw new Error("radix2.encode input should be Uint8Array");return Us(Array.from(n),8,e,!t)},decode:n=>(ks("radix2.decode",n),Uint8Array.from(Us(n,e,8,t)))}}function Fs(e){return bs(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const _s={alphabet:Is,chain:Ss,checksum:function(e,t){return Es(e),bs(t),{encode(n){if(!ms(n))throw new Error("checksum.encode: input should be Uint8Array");const r=t(n).slice(0,e),o=new Uint8Array(n.length+e);return o.set(n),o.set(r,n.length),o},decode(n){if(!ms(n))throw new Error("checksum.decode: input should be Uint8Array");const r=n.slice(0,-e),o=n.slice(-e),i=t(r).slice(0,e);for(let t=0;t<e;t++)if(i[t]!==o[t])throw new Error("Invalid checksum");return r}}},convertRadix:Ns,convertRadix2:Us,radix:Ds,radix2:Ls,join:Cs,padding:Os},Ms=(Ss(Ls(4),Is("0123456789ABCDEF"),Cs("")),Ss(Ls(5),Is("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Os(5),Cs("")),Ss(Ls(5),Is("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Cs("")),Ss(Ls(5),Is("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Os(5),Cs("")),Ss(Ls(5),Is("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Cs("")),Ss(Ls(5),Is("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),Cs(""),Ts(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()),Gs=(Ms||Ss(Ls(6),Is("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Os(6),Cs("")),Ss(Ls(6),Is("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Cs("")),Ms||Ss(Ls(6),Is("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Os(6),Cs("")),Ss(Ls(6),Is("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Cs("")),e=>Ss(Ds(58),Is(e),Cs(""))),js=(Gs("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Gs("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Gs("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),Ss(Is("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Cs(""))),Hs=[996825010,642813549,513874426,1027748829,705979059];function zs(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Hs.length;e++)1==(t>>e&1)&&(n^=Hs[e]);return n}function Vs(e,t,n=1){const r=e.length;let o=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);o=zs(o)^n>>5}o=zs(o);for(let t=0;t<r;t++)o=zs(o)^31&e.charCodeAt(t);for(let e of t)o=zs(o)^e;for(let e=0;e<6;e++)o=zs(o);return o^=n,js.encode(Us([o%Rs[30]],30,5,!1))}function Ks(e){const t="bech32"===e?1:734539939,n=Ls(5),r=n.decode,o=n.encode,i=Fs(r);function s(e,n,r=90){vs("bech32.encode prefix",e),ms(n)&&(n=Array.from(n)),ks("bech32.encode",n);const o=e.length;if(0===o)throw new TypeError(`Invalid prefix length ${o}`);const i=o+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);const s=e.toLowerCase(),a=Vs(s,n,t);return`${s}1${js.encode(n)}${a}`}function a(e,n=90){vs("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);const o=e.toLowerCase();if(e!==o&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=o.lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const s=o.slice(0,i),a=o.slice(i+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const c=js.decode(a).slice(0,-6),u=Vs(s,c,t);if(!a.endsWith(u))throw new Error(`Invalid checksum in ${e}: expected "${u}"`);return{prefix:s,words:c}}return{encode:s,decode:a,encodeFromBytes:function(e,t){return s(e,o(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Fs(a),fromWords:r,fromWordsUnsafe:i,toWords:o}}function Ws(e){if("string"!=typeof e)throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function $s(e){const t=Ws(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}function qs(e){ki(e,16,20,24,28,32)}Ks("bech32"),Ks("bech32m"),(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)()||Ss(Ls(4),Is("0123456789abcdef"),Cs(""),Ts(e=>{if("string"!=typeof e||e.length%2!=0)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const Js=e=>{const t=8-e.length/4;return new Uint8Array([gs(e)[0]>>t<<t])};function Qs(e){if(!Array.isArray(e)||2048!==e.length||"string"!=typeof e[0])throw new Error("Wordlist: expected array of 2048 strings");return e.forEach(e=>{if("string"!=typeof e)throw new Error("wordlist: non-string element: "+e)}),_s.chain(_s.checksum(1,Js),_s.radix2(11,!0),_s.alphabet(e))}function Zs(e,t=""){return async function(e,t,n){const{c:r,dkLen:o,asyncTick:i,DK:s,PRF:a,PRFSalt:c}=function(e,t,n,r){Si(e);const o=function(e,t){if(void 0!==t&&"[object Object]"!=={}.toString.call(t))throw new Error("options should be object or undefined");return Object.assign({dkLen:32,asyncTick:10},t)}(0,r),{c:i,dkLen:s,asyncTick:a}=o;if(xi(i),xi(s),xi(a),i<1)throw new Error("iterations (c) should be >= 1");const c=Ui(t),u=Ui(n),l=new Uint8Array(s),f=_i.create(e,c),h=f._cloneInto().update(u);return{c:i,dkLen:s,asyncTick:a,DK:l,PRF:f,PRFSalt:h}}(e,t,n,{c:2048,dkLen:64});let u;const l=new Uint8Array(4),f=Oi(l),h=new Uint8Array(a.outputLen);for(let e=1,t=0;t<o;e++,t+=a.outputLen){const n=s.subarray(t,t+a.outputLen);f.setInt32(0,e,!1),(u=c._cloneInto(u)).update(l).digestInto(h),n.set(h.subarray(0,n.length)),await Pi(r-1,i,()=>{a._cloneInto(u).update(h).digestInto(h);for(let e=0;e<n.length;e++)n[e]^=h[e]})}return function(e,t,n,r,o){return e.destroy(),t.destroy(),r&&r.destroy(),Ci(o),n}(a,c,s,u,h)}(ys,$s(e).nfkd,(e=>Ws("mnemonic"+e))(t))}const Ys="abandon\nability\nable\nabout\nabove\nabsent\nabsorb\nabstract\nabsurd\nabuse\naccess\naccident\naccount\naccuse\nachieve\nacid\nacoustic\nacquire\nacross\nact\naction\nactor\nactress\nactual\nadapt\nadd\naddict\naddress\nadjust\nadmit\nadult\nadvance\nadvice\naerobic\naffair\nafford\nafraid\nagain\nage\nagent\nagree\nahead\naim\nair\nairport\naisle\nalarm\nalbum\nalcohol\nalert\nalien\nall\nalley\nallow\nalmost\nalone\nalpha\nalready\nalso\nalter\nalways\namateur\namazing\namong\namount\namused\nanalyst\nanchor\nancient\nanger\nangle\nangry\nanimal\nankle\nannounce\nannual\nanother\nanswer\nantenna\nantique\nanxiety\nany\napart\napology\nappear\napple\napprove\napril\narch\narctic\narea\narena\nargue\narm\narmed\narmor\narmy\naround\narrange\narrest\narrive\narrow\nart\nartefact\nartist\nartwork\nask\naspect\nassault\nasset\nassist\nassume\nasthma\nathlete\natom\nattack\nattend\nattitude\nattract\nauction\naudit\naugust\naunt\nauthor\nauto\nautumn\naverage\navocado\navoid\nawake\naware\naway\nawesome\nawful\nawkward\naxis\nbaby\nbachelor\nbacon\nbadge\nbag\nbalance\nbalcony\nball\nbamboo\nbanana\nbanner\nbar\nbarely\nbargain\nbarrel\nbase\nbasic\nbasket\nbattle\nbeach\nbean\nbeauty\nbecause\nbecome\nbeef\nbefore\nbegin\nbehave\nbehind\nbelieve\nbelow\nbelt\nbench\nbenefit\nbest\nbetray\nbetter\nbetween\nbeyond\nbicycle\nbid\nbike\nbind\nbiology\nbird\nbirth\nbitter\nblack\nblade\nblame\nblanket\nblast\nbleak\nbless\nblind\nblood\nblossom\nblouse\nblue\nblur\nblush\nboard\nboat\nbody\nboil\nbomb\nbone\nbonus\nbook\nboost\nborder\nboring\nborrow\nboss\nbottom\nbounce\nbox\nboy\nbracket\nbrain\nbrand\nbrass\nbrave\nbread\nbreeze\nbrick\nbridge\nbrief\nbright\nbring\nbrisk\nbroccoli\nbroken\nbronze\nbroom\nbrother\nbrown\nbrush\nbubble\nbuddy\nbudget\nbuffalo\nbuild\nbulb\nbulk\nbullet\nbundle\nbunker\nburden\nburger\nburst\nbus\nbusiness\nbusy\nbutter\nbuyer\nbuzz\ncabbage\ncabin\ncable\ncactus\ncage\ncake\ncall\ncalm\ncamera\ncamp\ncan\ncanal\ncancel\ncandy\ncannon\ncanoe\ncanvas\ncanyon\ncapable\ncapital\ncaptain\ncar\ncarbon\ncard\ncargo\ncarpet\ncarry\ncart\ncase\ncash\ncasino\ncastle\ncasual\ncat\ncatalog\ncatch\ncategory\ncattle\ncaught\ncause\ncaution\ncave\nceiling\ncelery\ncement\ncensus\ncentury\ncereal\ncertain\nchair\nchalk\nchampion\nchange\nchaos\nchapter\ncharge\nchase\nchat\ncheap\ncheck\ncheese\nchef\ncherry\nchest\nchicken\nchief\nchild\nchimney\nchoice\nchoose\nchronic\nchuckle\nchunk\nchurn\ncigar\ncinnamon\ncircle\ncitizen\ncity\ncivil\nclaim\nclap\nclarify\nclaw\nclay\nclean\nclerk\nclever\nclick\nclient\ncliff\nclimb\nclinic\nclip\nclock\nclog\nclose\ncloth\ncloud\nclown\nclub\nclump\ncluster\nclutch\ncoach\ncoast\ncoconut\ncode\ncoffee\ncoil\ncoin\ncollect\ncolor\ncolumn\ncombine\ncome\ncomfort\ncomic\ncommon\ncompany\nconcert\nconduct\nconfirm\ncongress\nconnect\nconsider\ncontrol\nconvince\ncook\ncool\ncopper\ncopy\ncoral\ncore\ncorn\ncorrect\ncost\ncotton\ncouch\ncountry\ncouple\ncourse\ncousin\ncover\ncoyote\ncrack\ncradle\ncraft\ncram\ncrane\ncrash\ncrater\ncrawl\ncrazy\ncream\ncredit\ncreek\ncrew\ncricket\ncrime\ncrisp\ncritic\ncrop\ncross\ncrouch\ncrowd\ncrucial\ncruel\ncruise\ncrumble\ncrunch\ncrush\ncry\ncrystal\ncube\nculture\ncup\ncupboard\ncurious\ncurrent\ncurtain\ncurve\ncushion\ncustom\ncute\ncycle\ndad\ndamage\ndamp\ndance\ndanger\ndaring\ndash\ndaughter\ndawn\nday\ndeal\ndebate\ndebris\ndecade\ndecember\ndecide\ndecline\ndecorate\ndecrease\ndeer\ndefense\ndefine\ndefy\ndegree\ndelay\ndeliver\ndemand\ndemise\ndenial\ndentist\ndeny\ndepart\ndepend\ndeposit\ndepth\ndeputy\nderive\ndescribe\ndesert\ndesign\ndesk\ndespair\ndestroy\ndetail\ndetect\ndevelop\ndevice\ndevote\ndiagram\ndial\ndiamond\ndiary\ndice\ndiesel\ndiet\ndiffer\ndigital\ndignity\ndilemma\ndinner\ndinosaur\ndirect\ndirt\ndisagree\ndiscover\ndisease\ndish\ndismiss\ndisorder\ndisplay\ndistance\ndivert\ndivide\ndivorce\ndizzy\ndoctor\ndocument\ndog\ndoll\ndolphin\ndomain\ndonate\ndonkey\ndonor\ndoor\ndose\ndouble\ndove\ndraft\ndragon\ndrama\ndrastic\ndraw\ndream\ndress\ndrift\ndrill\ndrink\ndrip\ndrive\ndrop\ndrum\ndry\nduck\ndumb\ndune\nduring\ndust\ndutch\nduty\ndwarf\ndynamic\neager\neagle\nearly\nearn\nearth\neasily\neast\neasy\necho\necology\neconomy\nedge\nedit\neducate\neffort\negg\neight\neither\nelbow\nelder\nelectric\nelegant\nelement\nelephant\nelevator\nelite\nelse\nembark\nembody\nembrace\nemerge\nemotion\nemploy\nempower\nempty\nenable\nenact\nend\nendless\nendorse\nenemy\nenergy\nenforce\nengage\nengine\nenhance\nenjoy\nenlist\nenough\nenrich\nenroll\nensure\nenter\nentire\nentry\nenvelope\nepisode\nequal\nequip\nera\nerase\nerode\nerosion\nerror\nerupt\nescape\nessay\nessence\nestate\neternal\nethics\nevidence\nevil\nevoke\nevolve\nexact\nexample\nexcess\nexchange\nexcite\nexclude\nexcuse\nexecute\nexercise\nexhaust\nexhibit\nexile\nexist\nexit\nexotic\nexpand\nexpect\nexpire\nexplain\nexpose\nexpress\nextend\nextra\neye\neyebrow\nfabric\nface\nfaculty\nfade\nfaint\nfaith\nfall\nfalse\nfame\nfamily\nfamous\nfan\nfancy\nfantasy\nfarm\nfashion\nfat\nfatal\nfather\nfatigue\nfault\nfavorite\nfeature\nfebruary\nfederal\nfee\nfeed\nfeel\nfemale\nfence\nfestival\nfetch\nfever\nfew\nfiber\nfiction\nfield\nfigure\nfile\nfilm\nfilter\nfinal\nfind\nfine\nfinger\nfinish\nfire\nfirm\nfirst\nfiscal\nfish\nfit\nfitness\nfix\nflag\nflame\nflash\nflat\nflavor\nflee\nflight\nflip\nfloat\nflock\nfloor\nflower\nfluid\nflush\nfly\nfoam\nfocus\nfog\nfoil\nfold\nfollow\nfood\nfoot\nforce\nforest\nforget\nfork\nfortune\nforum\nforward\nfossil\nfoster\nfound\nfox\nfragile\nframe\nfrequent\nfresh\nfriend\nfringe\nfrog\nfront\nfrost\nfrown\nfrozen\nfruit\nfuel\nfun\nfunny\nfurnace\nfury\nfuture\ngadget\ngain\ngalaxy\ngallery\ngame\ngap\ngarage\ngarbage\ngarden\ngarlic\ngarment\ngas\ngasp\ngate\ngather\ngauge\ngaze\ngeneral\ngenius\ngenre\ngentle\ngenuine\ngesture\nghost\ngiant\ngift\ngiggle\nginger\ngiraffe\ngirl\ngive\nglad\nglance\nglare\nglass\nglide\nglimpse\nglobe\ngloom\nglory\nglove\nglow\nglue\ngoat\ngoddess\ngold\ngood\ngoose\ngorilla\ngospel\ngossip\ngovern\ngown\ngrab\ngrace\ngrain\ngrant\ngrape\ngrass\ngravity\ngreat\ngreen\ngrid\ngrief\ngrit\ngrocery\ngroup\ngrow\ngrunt\nguard\nguess\nguide\nguilt\nguitar\ngun\ngym\nhabit\nhair\nhalf\nhammer\nhamster\nhand\nhappy\nharbor\nhard\nharsh\nharvest\nhat\nhave\nhawk\nhazard\nhead\nhealth\nheart\nheavy\nhedgehog\nheight\nhello\nhelmet\nhelp\nhen\nhero\nhidden\nhigh\nhill\nhint\nhip\nhire\nhistory\nhobby\nhockey\nhold\nhole\nholiday\nhollow\nhome\nhoney\nhood\nhope\nhorn\nhorror\nhorse\nhospital\nhost\nhotel\nhour\nhover\nhub\nhuge\nhuman\nhumble\nhumor\nhundred\nhungry\nhunt\nhurdle\nhurry\nhurt\nhusband\nhybrid\nice\nicon\nidea\nidentify\nidle\nignore\nill\nillegal\nillness\nimage\nimitate\nimmense\nimmune\nimpact\nimpose\nimprove\nimpulse\ninch\ninclude\nincome\nincrease\nindex\nindicate\nindoor\nindustry\ninfant\ninflict\ninform\ninhale\ninherit\ninitial\ninject\ninjury\ninmate\ninner\ninnocent\ninput\ninquiry\ninsane\ninsect\ninside\ninspire\ninstall\nintact\ninterest\ninto\ninvest\ninvite\ninvolve\niron\nisland\nisolate\nissue\nitem\nivory\njacket\njaguar\njar\njazz\njealous\njeans\njelly\njewel\njob\njoin\njoke\njourney\njoy\njudge\njuice\njump\njungle\njunior\njunk\njust\nkangaroo\nkeen\nkeep\nketchup\nkey\nkick\nkid\nkidney\nkind\nkingdom\nkiss\nkit\nkitchen\nkite\nkitten\nkiwi\nknee\nknife\nknock\nknow\nlab\nlabel\nlabor\nladder\nlady\nlake\nlamp\nlanguage\nlaptop\nlarge\nlater\nlatin\nlaugh\nlaundry\nlava\nlaw\nlawn\nlawsuit\nlayer\nlazy\nleader\nleaf\nlearn\nleave\nlecture\nleft\nleg\nlegal\nlegend\nleisure\nlemon\nlend\nlength\nlens\nleopard\nlesson\nletter\nlevel\nliar\nliberty\nlibrary\nlicense\nlife\nlift\nlight\nlike\nlimb\nlimit\nlink\nlion\nliquid\nlist\nlittle\nlive\nlizard\nload\nloan\nlobster\nlocal\nlock\nlogic\nlonely\nlong\nloop\nlottery\nloud\nlounge\nlove\nloyal\nlucky\nluggage\nlumber\nlunar\nlunch\nluxury\nlyrics\nmachine\nmad\nmagic\nmagnet\nmaid\nmail\nmain\nmajor\nmake\nmammal\nman\nmanage\nmandate\nmango\nmansion\nmanual\nmaple\nmarble\nmarch\nmargin\nmarine\nmarket\nmarriage\nmask\nmass\nmaster\nmatch\nmaterial\nmath\nmatrix\nmatter\nmaximum\nmaze\nmeadow\nmean\nmeasure\nmeat\nmechanic\nmedal\nmedia\nmelody\nmelt\nmember\nmemory\nmention\nmenu\nmercy\nmerge\nmerit\nmerry\nmesh\nmessage\nmetal\nmethod\nmiddle\nmidnight\nmilk\nmillion\nmimic\nmind\nminimum\nminor\nminute\nmiracle\nmirror\nmisery\nmiss\nmistake\nmix\nmixed\nmixture\nmobile\nmodel\nmodify\nmom\nmoment\nmonitor\nmonkey\nmonster\nmonth\nmoon\nmoral\nmore\nmorning\nmosquito\nmother\nmotion\nmotor\nmountain\nmouse\nmove\nmovie\nmuch\nmuffin\nmule\nmultiply\nmuscle\nmuseum\nmushroom\nmusic\nmust\nmutual\nmyself\nmystery\nmyth\nnaive\nname\nnapkin\nnarrow\nnasty\nnation\nnature\nnear\nneck\nneed\nnegative\nneglect\nneither\nnephew\nnerve\nnest\nnet\nnetwork\nneutral\nnever\nnews\nnext\nnice\nnight\nnoble\nnoise\nnominee\nnoodle\nnormal\nnorth\nnose\nnotable\nnote\nnothing\nnotice\nnovel\nnow\nnuclear\nnumber\nnurse\nnut\noak\nobey\nobject\noblige\nobscure\nobserve\nobtain\nobvious\noccur\nocean\noctober\nodor\noff\noffer\noffice\noften\noil\nokay\nold\nolive\nolympic\nomit\nonce\none\nonion\nonline\nonly\nopen\nopera\nopinion\noppose\noption\norange\norbit\norchard\norder\nordinary\norgan\norient\noriginal\norphan\nostrich\nother\noutdoor\nouter\noutput\noutside\noval\noven\nover\nown\nowner\noxygen\noyster\nozone\npact\npaddle\npage\npair\npalace\npalm\npanda\npanel\npanic\npanther\npaper\nparade\nparent\npark\nparrot\nparty\npass\npatch\npath\npatient\npatrol\npattern\npause\npave\npayment\npeace\npeanut\npear\npeasant\npelican\npen\npenalty\npencil\npeople\npepper\nperfect\npermit\nperson\npet\nphone\nphoto\nphrase\nphysical\npiano\npicnic\npicture\npiece\npig\npigeon\npill\npilot\npink\npioneer\npipe\npistol\npitch\npizza\nplace\nplanet\nplastic\nplate\nplay\nplease\npledge\npluck\nplug\nplunge\npoem\npoet\npoint\npolar\npole\npolice\npond\npony\npool\npopular\nportion\nposition\npossible\npost\npotato\npottery\npoverty\npowder\npower\npractice\npraise\npredict\nprefer\nprepare\npresent\npretty\nprevent\nprice\npride\nprimary\nprint\npriority\nprison\nprivate\nprize\nproblem\nprocess\nproduce\nprofit\nprogram\nproject\npromote\nproof\nproperty\nprosper\nprotect\nproud\nprovide\npublic\npudding\npull\npulp\npulse\npumpkin\npunch\npupil\npuppy\npurchase\npurity\npurpose\npurse\npush\nput\npuzzle\npyramid\nquality\nquantum\nquarter\nquestion\nquick\nquit\nquiz\nquote\nrabbit\nraccoon\nrace\nrack\nradar\nradio\nrail\nrain\nraise\nrally\nramp\nranch\nrandom\nrange\nrapid\nrare\nrate\nrather\nraven\nraw\nrazor\nready\nreal\nreason\nrebel\nrebuild\nrecall\nreceive\nrecipe\nrecord\nrecycle\nreduce\nreflect\nreform\nrefuse\nregion\nregret\nregular\nreject\nrelax\nrelease\nrelief\nrely\nremain\nremember\nremind\nremove\nrender\nrenew\nrent\nreopen\nrepair\nrepeat\nreplace\nreport\nrequire\nrescue\nresemble\nresist\nresource\nresponse\nresult\nretire\nretreat\nreturn\nreunion\nreveal\nreview\nreward\nrhythm\nrib\nribbon\nrice\nrich\nride\nridge\nrifle\nright\nrigid\nring\nriot\nripple\nrisk\nritual\nrival\nriver\nroad\nroast\nrobot\nrobust\nrocket\nromance\nroof\nrookie\nroom\nrose\nrotate\nrough\nround\nroute\nroyal\nrubber\nrude\nrug\nrule\nrun\nrunway\nrural\nsad\nsaddle\nsadness\nsafe\nsail\nsalad\nsalmon\nsalon\nsalt\nsalute\nsame\nsample\nsand\nsatisfy\nsatoshi\nsauce\nsausage\nsave\nsay\nscale\nscan\nscare\nscatter\nscene\nscheme\nschool\nscience\nscissors\nscorpion\nscout\nscrap\nscreen\nscript\nscrub\nsea\nsearch\nseason\nseat\nsecond\nsecret\nsection\nsecurity\nseed\nseek\nsegment\nselect\nsell\nseminar\nsenior\nsense\nsentence\nseries\nservice\nsession\nsettle\nsetup\nseven\nshadow\nshaft\nshallow\nshare\nshed\nshell\nsheriff\nshield\nshift\nshine\nship\nshiver\nshock\nshoe\nshoot\nshop\nshort\nshoulder\nshove\nshrimp\nshrug\nshuffle\nshy\nsibling\nsick\nside\nsiege\nsight\nsign\nsilent\nsilk\nsilly\nsilver\nsimilar\nsimple\nsince\nsing\nsiren\nsister\nsituate\nsix\nsize\nskate\nsketch\nski\nskill\nskin\nskirt\nskull\nslab\nslam\nsleep\nslender\nslice\nslide\nslight\nslim\nslogan\nslot\nslow\nslush\nsmall\nsmart\nsmile\nsmoke\nsmooth\nsnack\nsnake\nsnap\nsniff\nsnow\nsoap\nsoccer\nsocial\nsock\nsoda\nsoft\nsolar\nsoldier\nsolid\nsolution\nsolve\nsomeone\nsong\nsoon\nsorry\nsort\nsoul\nsound\nsoup\nsource\nsouth\nspace\nspare\nspatial\nspawn\nspeak\nspecial\nspeed\nspell\nspend\nsphere\nspice\nspider\nspike\nspin\nspirit\nsplit\nspoil\nsponsor\nspoon\nsport\nspot\nspray\nspread\nspring\nspy\nsquare\nsqueeze\nsquirrel\nstable\nstadium\nstaff\nstage\nstairs\nstamp\nstand\nstart\nstate\nstay\nsteak\nsteel\nstem\nstep\nstereo\nstick\nstill\nsting\nstock\nstomach\nstone\nstool\nstory\nstove\nstrategy\nstreet\nstrike\nstrong\nstruggle\nstudent\nstuff\nstumble\nstyle\nsubject\nsubmit\nsubway\nsuccess\nsuch\nsudden\nsuffer\nsugar\nsuggest\nsuit\nsummer\nsun\nsunny\nsunset\nsuper\nsupply\nsupreme\nsure\nsurface\nsurge\nsurprise\nsurround\nsurvey\nsuspect\nsustain\nswallow\nswamp\nswap\nswarm\nswear\nsweet\nswift\nswim\nswing\nswitch\nsword\nsymbol\nsymptom\nsyrup\nsystem\ntable\ntackle\ntag\ntail\ntalent\ntalk\ntank\ntape\ntarget\ntask\ntaste\ntattoo\ntaxi\nteach\nteam\ntell\nten\ntenant\ntennis\ntent\nterm\ntest\ntext\nthank\nthat\ntheme\nthen\ntheory\nthere\nthey\nthing\nthis\nthought\nthree\nthrive\nthrow\nthumb\nthunder\nticket\ntide\ntiger\ntilt\ntimber\ntime\ntiny\ntip\ntired\ntissue\ntitle\ntoast\ntobacco\ntoday\ntoddler\ntoe\ntogether\ntoilet\ntoken\ntomato\ntomorrow\ntone\ntongue\ntonight\ntool\ntooth\ntop\ntopic\ntopple\ntorch\ntornado\ntortoise\ntoss\ntotal\ntourist\ntoward\ntower\ntown\ntoy\ntrack\ntrade\ntraffic\ntragic\ntrain\ntransfer\ntrap\ntrash\ntravel\ntray\ntreat\ntree\ntrend\ntrial\ntribe\ntrick\ntrigger\ntrim\ntrip\ntrophy\ntrouble\ntruck\ntrue\ntruly\ntrumpet\ntrust\ntruth\ntry\ntube\ntuition\ntumble\ntuna\ntunnel\nturkey\nturn\nturtle\ntwelve\ntwenty\ntwice\ntwin\ntwist\ntwo\ntype\ntypical\nugly\numbrella\nunable\nunaware\nuncle\nuncover\nunder\nundo\nunfair\nunfold\nunhappy\nuniform\nunique\nunit\nuniverse\nunknown\nunlock\nuntil\nunusual\nunveil\nupdate\nupgrade\nuphold\nupon\nupper\nupset\nurban\nurge\nusage\nuse\nused\nuseful\nuseless\nusual\nutility\nvacant\nvacuum\nvague\nvalid\nvalley\nvalve\nvan\nvanish\nvapor\nvarious\nvast\nvault\nvehicle\nvelvet\nvendor\nventure\nvenue\nverb\nverify\nversion\nvery\nvessel\nveteran\nviable\nvibrant\nvicious\nvictory\nvideo\nview\nvillage\nvintage\nviolin\nvirtual\nvirus\nvisa\nvisit\nvisual\nvital\nvivid\nvocal\nvoice\nvoid\nvolcano\nvolume\nvote\nvoyage\nwage\nwagon\nwait\nwalk\nwall\nwalnut\nwant\nwarfare\nwarm\nwarrior\nwash\nwasp\nwaste\nwater\nwave\nway\nwealth\nweapon\nwear\nweasel\nweather\nweb\nwedding\nweekend\nweird\nwelcome\nwest\nwet\nwhale\nwhat\nwheat\nwheel\nwhen\nwhere\nwhip\nwhisper\nwide\nwidth\nwife\nwild\nwill\nwin\nwindow\nwine\nwing\nwink\nwinner\nwinter\nwire\nwisdom\nwise\nwish\nwitness\nwolf\nwoman\nwonder\nwood\nwool\nword\nwork\nworld\nworry\nworth\nwrap\nwreck\nwrestle\nwrist\nwrite\nwrong\nyard\nyear\nyellow\nyou\nyoung\nyouth\nzebra\nzero\nzone\nzoo".split("\n");var Xs=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},ea=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function ta(e){try{return function(e,t){try{!function(e,t){const{words:n}=$s(e);qs(Qs(t).decode(n))}(e,t)}catch(e){return!1}return!0}(e,Ys)}catch(e){return!1}}function na(e,t){return Xs(this,void 0,void 0,function(){var n;return ea(this,function(r){if(!ta(e))throw new Error("Invalid mnemonic seed phrase");return n="shogun-".concat(t),[2,Zs(e,n)]})})}function ra(e,t){return Xs(this,void 0,void 0,function(){var n,r;return ea(this,function(o){switch(o.label){case 0:return[4,na(e,t)];case 1:return n=o.sent(),r=function(e){return cn(Bo(e))}(n),[2,{password:r,seed:n}]}})})}var oa=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ia=function(){return ia=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},ia.apply(this,arguments)},sa=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},aa=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},ca={rpName:"Shogun Wallet",timeout:6e4,userVerification:"required",attestation:"none",authenticatorAttachment:void 0,requireResidentKey:!1},ua=function(e){function t(t,n){var r,o=e.call(this)||this;return o.abortController=null,o.gunInstance=t,o.credential=null,o.config=ia(ia(ia({},ca),n),{rpId:null!==(r=null==n?void 0:n.rpId)&&void 0!==r?r:"undefined"!=typeof window&&window.location&&window.location.hostname?window.location.hostname.split(":")[0]:"localhost"}),o}return oa(t,e),t.prototype.validateUsername=function(e){if(!e||"string"!=typeof e)throw new Error("Username must be a non-empty string");if(e.length<3||e.length>64)throw new Error("Username must be between ".concat(3," and ").concat(64," characters"));if(!/^[a-zA-Z0-9_-]+$/.test(e))throw new Error("Username can only contain letters, numbers, underscores and hyphens")},t.prototype.createAccount=function(e,t){return sa(this,arguments,void 0,function(e,t,n){var r,o,i,s,a,c,u,l;return void 0===n&&(n=!1),aa(this,function(n){switch(n.label){case 0:n.trys.push([0,5,,6]),this.validateUsername(e),r=3,o=null,i=function(n){var i,a;return aa(this,function(c){switch(c.label){case 0:return c.trys.push([0,2,,5]),[4,s.generateCredentials(e,t,!1)];case 1:return(i=c.sent()).success?(s.emit(Kt.DEVICE_REGISTERED,{type:Kt.DEVICE_REGISTERED,data:{username:e},timestamp:Date.now()}),[2,{value:i}]):(o=new Error(null!==(l=i.error)&&void 0!==l?l:"Unknown error"),[3,5]);case 2:return a=c.sent(),o=a,n<r?[4,new Promise(function(e){return setTimeout(e,1e3*n)})]:[3,4];case 3:return c.sent(),[2,"continue"];case 4:return[3,5];case 5:return[2]}})},s=this,a=1,n.label=1;case 1:return a<=r?[5,i(a)]:[3,4];case 2:if("object"==typeof(c=n.sent()))return[2,c.value];n.label=3;case 3:return a++,[3,1];case 4:throw o||new Error("Failed to create account after retries");case 5:throw u=n.sent(),this.emit(Kt.ERROR,{type:Kt.ERROR,data:{error:u.message},timestamp:Date.now()}),u;case 6:return[2]}})})},t.prototype.authenticateUser=function(e,t){return sa(this,arguments,void 0,function(e,t,n){var r,o,i,s,a,c,u,l,f,h,d,p=this;return void 0===n&&(n={}),aa(this,function(g){switch(g.label){case 0:if(g.trys.push([0,5,,6]),this.validateUsername(e),!t)return r=new Error("No WebAuthn credentials found for this username"),K.handle(j.WEBAUTHN,"NO_CREDENTIALS",r.message,r),[2,{success:!1,error:r.message}];this.abortAuthentication(),this.abortController=new AbortController,o=n.timeout||this.config.timeout,i=setTimeout(function(){var e;return null===(e=p.abortController)||void 0===e?void 0:e.abort()},o),g.label=1;case 1:return g.trys.push([1,,3,4]),s=this.generateChallenge(e),a={challenge:s,allowCredentials:[],timeout:o,userVerification:n.userVerification||this.config.userVerification,rpId:this.config.rpId},[4,navigator.credentials.get({publicKey:a,signal:this.abortController.signal})];case 2:if(!(c=g.sent()))throw new Error("WebAuthn verification failed");return u=this.generateCredentialsFromSalt(e,t).password,l=this.getDeviceInfo(c.id),f={success:!0,username:e,password:u,credentialId:this.bufferToBase64(c.rawId),deviceInfo:l},this.emit(Kt.AUTHENTICATION_SUCCESS,{type:Kt.AUTHENTICATION_SUCCESS,data:{username:e,deviceInfo:l},timestamp:Date.now()}),[2,f];case 3:return clearTimeout(i),this.abortController=null,[7];case 4:return[3,6];case 5:return h=g.sent(),d=h instanceof Error?h.message:"Unknown WebAuthn error",this.emit(Kt.AUTHENTICATION_FAILED,{type:Kt.AUTHENTICATION_FAILED,data:{username:e,error:d},timestamp:Date.now()}),K.handle(j.WEBAUTHN,"AUTH_ERROR",d,h),[2,{success:!1,error:d}];case 6:return[2]}})})},t.prototype.abortAuthentication=function(){this.abortController&&(this.abortController.abort(),this.abortController=null)},t.prototype.getDeviceInfo=function(e){var t=this.getPlatformInfo();return{deviceId:e,timestamp:Date.now(),name:t.name,platform:t.platform,lastUsed:Date.now()}},t.prototype.getPlatformInfo=function(){if("undefined"==typeof navigator)return{name:"unknown",platform:"unknown"};var e=navigator.platform,t=navigator.userAgent;return/iPhone|iPad|iPod/.test(e)?{name:"iOS Device",platform:e}:/Android/.test(t)?{name:"Android Device",platform:e}:/Win/.test(e)?{name:"Windows Device",platform:e}:/Mac/.test(e)?{name:"Mac Device",platform:e}:/Linux/.test(e)?{name:"Linux Device",platform:e}:{name:"Unknown Device",platform:e}},t.prototype.generateChallenge=function(e){var t=Date.now().toString(),n=this.getRandomBytes(32),r="".concat(e,"-").concat(t,"-").concat(this.uint8ArrayToHex(n));return(new TextEncoder).encode(r)},t.prototype.getRandomBytes=function(e){if("undefined"!=typeof window&&window.crypto)return window.crypto.getRandomValues(new Uint8Array(e));throw new Error("No cryptographic implementation available")},t.prototype.uint8ArrayToHex=function(e){return Array.from(e).map(function(e){return e.toString(16).padStart(2,"0")}).join("")},t.prototype.bufferToBase64=function(e){var t=new Uint8Array(e).reduce(function(e,t){return e+String.fromCharCode(t)},"");return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")},t.prototype.generateCredentialsFromSalt=function(e,t){return{password:kt(xe(e+t))}},t.prototype.isSupported=function(){return"undefined"!=typeof window&&void 0!==window.PublicKeyCredential},t.prototype.createCredential=function(e){return sa(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c;return aa(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),t=crypto.getRandomValues(new Uint8Array(32)),n=(new TextEncoder).encode(e),r={challenge:t,rp:ia({name:this.config.rpName||"Shogun Wallet"},this.config.rpId&&"localhost"!==this.config.rpId&&{id:this.config.rpId}),user:{id:n,name:e,displayName:e},pubKeyCredParams:[{type:"public-key",alg:-7}],timeout:this.config.timeout,attestation:this.config.attestation,authenticatorSelection:{authenticatorAttachment:this.config.authenticatorAttachment,userVerification:this.config.userVerification,requireResidentKey:this.config.requireResidentKey}},[4,navigator.credentials.create({publicKey:r})];case 1:if(!(o=u.sent()))throw new Error("Credential creation failed");return s={id:(i=o).id,rawId:i.rawId,type:i.type,response:{clientDataJSON:i.response.clientDataJSON},getClientExtensionResults:i.getClientExtensionResults},"attestationObject"in i.response&&(s.response.attestationObject=i.response.attestationObject),this.credential=s,[2,s];case 2:throw a=u.sent(),console.error("Detailed error in credential creation:",a),c=a instanceof Error?a.message:"Unknown error",new Error("Error creating credentials: ".concat(c));case 3:return[2]}})})},t.prototype.generateCredentials=function(e,t){return sa(this,arguments,void 0,function(e,t,n){var r,o,i,s,a,c,u,l;return void 0===n&&(n=!1),aa(this,function(t){switch(t.label){case 0:return t.trys.push([0,7,,8]),n?[4,this.verifyCredential(e)]:[3,3];case 1:return(r=t.sent()).success&&r.credentialId?[4,la(e,r.credentialId)]:[2,{success:!1,username:e,key:void 0,credentialId:"",error:r.error,publicKey:null}];case 2:return a=t.sent(),[2,{success:!0,username:e,key:a,credentialId:r.credentialId,publicKey:null}];case 3:return[4,this.createCredential(e)];case 4:return o=t.sent(),i=o.id,s=null,(null===(l=null==o?void 0:o.response)||void 0===l?void 0:l.getPublicKey)&&(s=o.response.getPublicKey()),[4,la(e,i)];case 5:return a=t.sent(),[2,{success:!0,username:e,key:a,credentialId:i,publicKey:s}];case 6:return[3,8];case 7:return c=t.sent(),console.error("Error in generateCredentials:",c),u=c instanceof Error?c.message:"Unknown error during WebAuthn operation",[2,{success:!1,username:e,key:void 0,credentialId:"",error:u,publicKey:null}];case 8:return[2]}})})},t.prototype.verifyCredential=function(e){return sa(this,void 0,void 0,function(){var t,n,r,o,i;return aa(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=crypto.getRandomValues(new Uint8Array(32)),n=ia({challenge:t,timeout:this.config.timeout,userVerification:this.config.userVerification},"localhost"!==this.config.rpId&&{rpId:this.config.rpId}),(null===(i=this.credential)||void 0===i?void 0:i.rawId)&&(n.allowCredentials=[{id:this.credential.rawId,type:"public-key"}]),[4,navigator.credentials.get({publicKey:n})];case 1:return(r=s.sent())?[2,{success:!0,credentialId:r.id,username:e}]:[2,{success:!1,error:"Credential verification failed"}];case 2:return o=s.sent(),console.error("Error verifying credentials:",o),[2,{success:!1,error:o instanceof Error?o.message:"Unknown error verifying credentials"}];case 3:return[2]}})})},t.prototype.removeDevice=function(e,t,n){return sa(this,void 0,void 0,function(){var e;return aa(this,function(r){return n&&n.credentials&&n.credentials[t]?((e=ia({},n)).credentials&&delete e.credentials[t],[2,{success:!0,updatedCredentials:e}]):[2,{success:!1}]})})},t.prototype.sign=function(e){return sa(this,void 0,void 0,function(){var t,n,r,o,i,s;return aa(this,function(a){switch(a.label){case 0:return t=JSON.stringify(e),n=xe(t),r=kt(n),o=le(r),i={challenge:o,rpId:this.config.rpId,userVerification:this.config.userVerification,timeout:this.config.timeout},(null===(s=this.credential)||void 0===s?void 0:s.rawId)&&(i.allowCredentials=[{id:this.credential.rawId,type:"public-key"}]),[4,navigator.credentials.get({publicKey:i})];case 1:return[2,a.sent()]}})})},t}(W);function la(e,t){return sa(this,arguments,void 0,function(e,t,n){var r,o,i,s;return void 0===n&&(n=!1),aa(this,function(a){switch(a.label){case 0:return n?[4,ra(t,e)]:[3,3];case 1:return r=a.sent(),o=r.password,r.seed,[4,di(o,e,{includeP256:!0})];case 2:case 4:return[2,a.sent()];case 3:return i=Vt(xe(t)),s="".concat(e,"_").concat(t),[4,di(i,s,{includeP256:!0})]}})})}"undefined"!=typeof window?window.Webauthn=ua:void 0!==r.g&&(r.g.Webauthn=ua);var fa=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},ha=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},da=function(e){for(var t=new Uint8Array(e),n=[],r=0;r<t.length;r++)n.push(String.fromCharCode(t[r]));return btoa(n.join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")},pa=function(){function e(e){this.credentials=new Map,this.webauthn=e||new ua}return e.prototype.createSigningCredential=function(e){return fa(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c,u,l,f,h;return ha(this,function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),[4,navigator.credentials.create({publicKey:{challenge:crypto.getRandomValues(new Uint8Array(32)),rp:{id:"localhost"===window.location.hostname?"localhost":window.location.hostname,name:"Shogun Wallet"},user:{id:(new TextEncoder).encode(e),name:e,displayName:e},pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-25},{type:"public-key",alg:-257}],authenticatorSelection:{userVerification:"preferred"},timeout:6e4,attestation:"none"}})];case 1:if(!(t=d.sent()))throw new Error("Failed to create WebAuthn credential");if(n=t.response,!(r=n.getPublicKey()))throw new Error("Failed to get public key from credential");return o=new Uint8Array(r),i=o.slice(27,59),s=o.slice(59,91),a=da(i),c=da(s),u="".concat(a,".").concat(c),l=Vt(xe(t.id)),f={id:t.id,rawId:t.rawId,publicKey:{x:a,y:c},pub:u,hashedCredentialId:l},this.credentials.set(t.id,f),[2,f];case 2:throw h=d.sent(),console.error("Error creating signing credential:",h),new Error("Failed to create signing credential: ".concat(h.message));case 3:return[2]}})})},e.prototype.createAuthenticator=function(e){var t=this,n=this.credentials.get(e);if(!n)throw new Error("Credential ".concat(e," not found"));return function(e){return fa(t,void 0,void 0,function(){var t,r,o,i;return ha(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=(new TextEncoder).encode(JSON.stringify(e)),r={challenge:t,rpId:"localhost"===window.location.hostname?"localhost":window.location.hostname,userVerification:"preferred",allowCredentials:[{type:"public-key",id:n.rawId}],timeout:6e4},[4,navigator.credentials.get({publicKey:r})];case 1:if(!(o=s.sent()))throw new Error("WebAuthn assertion failed");return[2,o.response];case 2:throw i=s.sent(),console.error("WebAuthn assertion error:",i),i;case 3:return[2]}})})}},e.prototype.createDerivedKeyPair=function(e,t,n){return fa(this,void 0,void 0,function(){var t,r,o;return ha(this,function(i){switch(i.label){case 0:if(!(t=this.credentials.get(e)))throw new Error("Credential ".concat(e," not found"));i.label=1;case 1:return i.trys.push([1,3,,4]),[4,di(t.hashedCredentialId,n,{includeP256:!0})];case 2:return[2,{pub:(r=i.sent()).pub,priv:r.priv,epub:r.epub,epriv:r.epriv}];case 3:throw o=i.sent(),console.error("Error deriving keys from WebAuthn credential:",o),o;case 4:return[2]}})})},e.prototype.createGunUser=function(e,t,n){return fa(this,void 0,void 0,function(){var r,o,i,s=this;return ha(this,function(a){switch(a.label){case 0:if(!(r=this.credentials.get(e)))throw new Error("Credential ".concat(e," not found"));a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.createDerivedKeyPair(e,t)];case 2:return o=a.sent(),[2,new Promise(function(t){n.user().create(o,function(i){i.err?n.user().auth(o,function(n){if(n.err)t({success:!1,error:n.err});else{var o=n.pub;r.gunUserPub=o,s.credentials.set(e,r),t({success:!0,userPub:o})}}):n.user().auth(o,function(n){if(n.err)t({success:!1,error:n.err});else{var o=n.pub;r.gunUserPub=o,s.credentials.set(e,r),t({success:!0,userPub:o})}})})})];case 3:return i=a.sent(),console.error("Error creating Gun user:",i),[2,{success:!1,error:i.message}];case 4:return[2]}})})},e.prototype.signWithDerivedKeys=function(e,t,n,r){return fa(this,void 0,void 0,function(){var o,i,s,a,c,u,l;return ha(this,function(f){switch(f.label){case 0:return f.trys.push([0,3,,4]),[4,this.createAuthenticator(t)(e)];case 1:return f.sent(),[4,this.createDerivedKeyPair(t,n,r)];case 2:return o=f.sent(),i=JSON.stringify(e),s=Bo((new TextEncoder).encode(i)),a=function(e){for(e=e.replace(/-/g,"+").replace(/_/g,"/");e.length%4;)e+="=";var t=atob(e);return new Uint8Array(t.split("").map(function(e){return e.charCodeAt(0)}))}(o.priv),c=Io.sign(s,a),u={m:i,s:da(c.toCompactRawBytes())},[2,"SEA"+JSON.stringify(u)];case 3:throw l=f.sent(),console.error("Error signing with derived keys:",l),l;case 4:return[2]}})})},e.prototype.getGunUserPub=function(e){var t=this.credentials.get(e);return null==t?void 0:t.gunUserPub},e.prototype.getHashedCredentialId=function(e){var t=this.credentials.get(e);return null==t?void 0:t.hashedCredentialId},e.prototype.verifyConsistency=function(e,t,n){return fa(this,void 0,void 0,function(){var r;return ha(this,function(o){switch(o.label){case 0:return this.credentials.get(e)?[4,this.createDerivedKeyPair(e,t)]:[2,{consistent:!1}];case 1:return r=o.sent(),[2,{consistent:!n||r.pub===n,actualUserPub:r.pub,expectedUserPub:n}]}})})},e.prototype.getCredential=function(e){return this.credentials.get(e)},e.prototype.listCredentials=function(){return Array.from(this.credentials.values())},e.prototype.removeCredential=function(e){return this.credentials.delete(e)},e}(),ga=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ya=function(){return ya=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},ya.apply(this,arguments)},ma=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},wa=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},ba=function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.name="webauthn",t.version="1.0.0",t.description="Provides WebAuthn authentication functionality for ShogunCore",t.webauthn=null,t.signer=null,t}return ga(t,e),t.prototype.initialize=function(t){e.prototype.initialize.call(this,t),"undefined"!=typeof window?this.isSupported()?(this.webauthn=new ua(t.gun),this.signer=new pa(this.webauthn),console.log("[webauthnPlugin] WebAuthn plugin initialized with signer support")):console.warn("[webauthnPlugin] WebAuthn not supported in this environment"):console.warn("[webauthnPlugin] WebAuthn plugin disabled - not in browser environment")},t.prototype.destroy=function(){this.webauthn=null,this.signer=null,e.prototype.destroy.call(this),console.log("[webauthnPlugin] WebAuthn plugin destroyed")},t.prototype.assertWebauthn=function(){if(this.assertInitialized(),!this.webauthn)throw new Error("WebAuthn module not initialized");return this.webauthn},t.prototype.assertSigner=function(){if(this.assertInitialized(),!this.signer)throw new Error("WebAuthn signer not initialized");return this.signer},t.prototype.generatePairFromCredentials=function(e){return ma(this,void 0,void 0,function(){var t;return wa(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.assertSigner().createDerivedKeyPair(e.credentialId,e.username)];case 1:return[2,n.sent()];case 2:return t=n.sent(),console.error("Error generating pair from WebAuthn credentials:",t),[2,null];case 3:return[2]}})})},t.prototype.isSupported=function(){return"undefined"!=typeof window&&void 0!==window.PublicKeyCredential&&(this.webauthn?this.webauthn.isSupported():void 0!==window.PublicKeyCredential)},t.prototype.generateCredentials=function(e,t){return ma(this,arguments,void 0,function(e,t,n){return void 0===n&&(n=!1),wa(this,function(r){return[2,this.assertWebauthn().generateCredentials(e,t,n)]})})},t.prototype.createAccount=function(e,t){return ma(this,arguments,void 0,function(e,t,n){return void 0===n&&(n=!1),wa(this,function(r){return[2,this.assertWebauthn().createAccount(e,t,n)]})})},t.prototype.authenticateUser=function(e,t,n){return ma(this,void 0,void 0,function(){return wa(this,function(r){return[2,this.assertWebauthn().authenticateUser(e,t,n)]})})},t.prototype.abortAuthentication=function(){this.assertWebauthn().abortAuthentication()},t.prototype.removeDevice=function(e,t,n){return ma(this,void 0,void 0,function(){return wa(this,function(r){return[2,this.assertWebauthn().removeDevice(e,t,n)]})})},t.prototype.createSigningCredential=function(e){return ma(this,void 0,void 0,function(){var t,n;return wa(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),"function"!=typeof(t=this.assertWebauthn()).createSigningCredential?[3,2]:[4,t.createSigningCredential(e)];case 1:case 3:return[2,r.sent()];case 2:return[4,this.assertSigner().createSigningCredential(e)];case 4:throw n=r.sent(),console.error("Error creating signing credential: ".concat(n.message)),n;case 5:return[2]}})})},t.prototype.createAuthenticator=function(e){try{var t=this.assertWebauthn();return"function"==typeof t.createAuthenticator?t.createAuthenticator(e):this.assertSigner().createAuthenticator(e)}catch(e){throw console.error("Error creating authenticator: ".concat(e.message)),e}},t.prototype.createDerivedKeyPair=function(e,t,n){return ma(this,void 0,void 0,function(){var r,o;return wa(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(r=this.assertWebauthn()).createDerivedKeyPair?[3,2]:[4,r.createDerivedKeyPair(e,t,n)];case 1:case 3:return[2,i.sent()];case 2:return[4,this.assertSigner().createDerivedKeyPair(e,t,n)];case 4:throw o=i.sent(),console.error("Error creating derived key pair: ".concat(o.message)),o;case 5:return[2]}})})},t.prototype.signWithDerivedKeys=function(e,t,n,r){return ma(this,void 0,void 0,function(){var o,i;return wa(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),"function"!=typeof(o=this.assertWebauthn()).signWithDerivedKeys?[3,2]:[4,o.signWithDerivedKeys(e,t,n,r)];case 1:case 3:return[2,s.sent()];case 2:return[4,this.assertSigner().signWithDerivedKeys(e,t,n,r)];case 4:throw i=s.sent(),console.error("Error signing with derived keys: ".concat(i.message)),i;case 5:return[2]}})})},t.prototype.getSigningCredential=function(e){var t=this.assertWebauthn();return"function"==typeof t.getSigningCredential?t.getSigningCredential(e):this.assertSigner().getCredential(e)},t.prototype.listSigningCredentials=function(){var e=this.assertWebauthn();return"function"==typeof e.listSigningCredentials?e.listSigningCredentials():this.assertSigner().listCredentials()},t.prototype.removeSigningCredential=function(e){var t=this.assertWebauthn();return"function"==typeof t.removeSigningCredential?t.removeSigningCredential(e):this.assertSigner().removeCredential(e)},t.prototype.createGunUserFromSigningCredential=function(e,t){return ma(this,void 0,void 0,function(){var n,r,o;return wa(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(n=this.assertWebauthn()).createGunUserFromSigningCredential?[3,2]:[4,n.createGunUserFromSigningCredential(e,t)];case 1:case 3:return[2,i.sent()];case 2:return r=this.assertInitialized(),[4,this.assertSigner().createGunUser(e,t,r.gun)];case 4:throw o=i.sent(),console.error("Error creating Gun user from signing credential: ".concat(o.message)),o;case 5:return[2]}})})},t.prototype.getGunUserPubFromSigningCredential=function(e){var t=this.assertWebauthn();return"function"==typeof t.getGunUserPubFromSigningCredential?t.getGunUserPubFromSigningCredential(e):this.assertSigner().getGunUserPub(e)},t.prototype.getHashedCredentialId=function(e){var t=this.assertWebauthn();return"function"==typeof t.getHashedCredentialId?t.getHashedCredentialId(e):this.assertSigner().getHashedCredentialId(e)},t.prototype.verifyConsistency=function(e,t,n){return ma(this,void 0,void 0,function(){var r,o;return wa(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(r=this.assertWebauthn()).verifyConsistency?[3,2]:[4,r.verifyConsistency(e,t,n)];case 1:case 3:return[2,i.sent()];case 2:return[4,this.assertSigner().verifyConsistency(e,t,n)];case 4:return o=i.sent(),console.error("Error verifying consistency: ".concat(o.message)),[2,{consistent:!1}];case 5:return[2]}})})},t.prototype.setupConsistentOneshotSigning=function(e){return ma(this,void 0,void 0,function(){var t,n,r,o,i;return wa(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),"function"!=typeof(t=this.assertWebauthn()).setupConsistentOneshotSigning?[3,2]:[4,t.setupConsistentOneshotSigning(e)];case 1:return[2,s.sent()];case 2:return[4,this.createSigningCredential(e)];case 3:return n=s.sent(),r=this.createAuthenticator(n.id),[4,this.createGunUserFromSigningCredential(n.id,e)];case 4:return o=s.sent(),[2,{credential:n,authenticator:r,gunUser:o,pub:n.pub,hashedCredentialId:n.hashedCredentialId}];case 5:throw i=s.sent(),console.error("Error setting up consistent oneshot signing: ".concat(i.message)),i;case 6:return[2]}})})},t.prototype.login=function(e){return ma(this,void 0,void 0,function(){var t,n,r,o,i,s=this;return wa(this,function(a){switch(a.label){case 0:if(a.trys.push([0,5,,6]),t=this.assertInitialized(),!e)throw new Error("Username required for WebAuthn login");if(!this.isSupported())throw new Error("WebAuthn is not supported by this browser");return[4,this.generateCredentials(e,null,!0)];case 1:if(!(null==(n=a.sent())?void 0:n.success)||!n.key)throw new Error((null==n?void 0:n.error)||"WebAuthn verification failed");return t.setAuthMethod("webauthn"),t.authenticate?(r=function(){return ma(s,void 0,void 0,function(){return wa(this,function(e){return[2,n]})})},[4,t.authenticate(e,r,null===(i=n.key)||void 0===i?void 0:i.pub)]):[3,3];case 2:case 4:return[2,a.sent()];case 3:return[4,t.login(e,"",n.key)];case 5:return o=a.sent(),console.error("Error during WebAuthn login: ".concat(o)),K.handle(j.WEBAUTHN,"WEBAUTHN_LOGIN_ERROR",o.message||"Error during WebAuthn login",o),[2,{success:!1,error:o.message||"Error during WebAuthn login"}];case 6:return[2]}})})},t.prototype.signUp=function(e,t){return ma(this,void 0,void 0,function(){var n,r,o,i,s,a,c,u,l,f;return wa(this,function(h){switch(h.label){case 0:if(h.trys.push([0,12,,13]),n=this.assertInitialized(),!e)throw new Error("Username required for WebAuthn registration");if(!this.isSupported())throw new Error("WebAuthn is not supported by this browser");if(r=void 0,o=!1!==(null==t?void 0:t.generateSeedPhrase),null==t?void 0:t.seedPhrase){if(!ta(t.seedPhrase))throw new Error("Invalid seed phrase provided");r=t.seedPhrase}else o&&(r=function(e,t=128){if(xi(t),t%32!=0||t>256)throw new TypeError("Invalid entropy");return function(e,t){return qs(e),Qs(t).encode(e).join((e=>"あいこくしん"===e[0])(t)?" ":" ")}(function(e=32){if(Ai&&"function"==typeof Ai.getRandomValues)return Ai.getRandomValues(new Uint8Array(e));if(Ai&&"function"==typeof Ai.randomBytes)return Uint8Array.from(Ai.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}(t/8),e)}(Ys,128),console.log("[webauthnPlugin] Generated seed phrase for multi-device support"));return i=void 0,r?[4,ra(r,e)]:[3,7];case 1:return h.sent().password,[4,la(e,r,!0)];case 2:s=h.sent(),i={pub:s.pub,priv:s.priv,epub:s.epub,epriv:s.epriv},h.label=3;case 3:return h.trys.push([3,5,,6]),[4,this.generateCredentials(e,null,!1)];case 4:return(null==(c=h.sent())?void 0:c.success)&&console.log("[webauthnPlugin] Created passkey for device-bound login"),[3,6];case 5:return a=h.sent(),console.warn("[webauthnPlugin] Could not create passkey, seed-only mode:",a),[3,6];case 6:return[3,10];case 7:return[4,this.generateCredentials(e,null,!1)];case 8:if(!(null==(c=h.sent())?void 0:c.success))throw new Error((null==c?void 0:c.error)||"Unable to generate WebAuthn credentials");return[4,this.assertWebauthn().authenticateUser(e,c.credentialId,{userVerification:"required"})];case 9:if(!(u=h.sent()).success)throw new Error(u.error||"WebAuthn verification required to complete registration");if(!c.key)throw new Error("Failed to generate SEA pair from WebAuthn credentials");i=c.key,h.label=10;case 10:return n.setAuthMethod("webauthn"),[4,n.signUp(e,void 0,i)];case 11:return l=h.sent(),r&&o?[2,ya(ya({},l),{message:r?"🔑 IMPORTANT: Save your 12-word seed phrase to access your account from other devices!":l.message,seedPhrase:r})]:[2,l];case 12:return f=h.sent(),console.error("Error during WebAuthn registration: ".concat(f)),K.handle(j.WEBAUTHN,"WEBAUTHN_SIGNUP_ERROR",f.message||"Error during WebAuthn registration",f),[2,{success:!1,error:f.message||"Error during WebAuthn registration"}];case 13:return[2]}})})},t.prototype.importFromSeed=function(e,t){return ma(this,void 0,void 0,function(){var n,r;return wa(this,function(o){switch(o.label){case 0:if(o.trys.push([0,2,,3]),!e)throw new Error("Username required");if(!ta(n=t.toLowerCase().trim().replace(/\s+/g," ").replace(/[^\w\s]/g,"")))throw new Error("Invalid seed phrase. Please check and try again.");return console.log("[webauthnPlugin] Importing account from seed phrase"),[4,this.signUp(e,{seedPhrase:n,generateSeedPhrase:!1})];case 1:return[2,o.sent()];case 2:return r=o.sent(),console.error("Error importing from seed: ".concat(r.message)),K.handle(j.WEBAUTHN,"WEBAUTHN_IMPORT_ERROR",r.message||"Error importing from seed phrase",r),[2,{success:!1,error:r.message||"Error importing from seed phrase"}];case 3:return[2]}})})},t.prototype.getSeedPhrase=function(e){return ma(this,void 0,void 0,function(){return wa(this,function(e){return console.warn("[webauthnPlugin] Seed phrases are not stored for security reasons"),console.warn("[webauthnPlugin] Users must save their seed phrase during registration"),[2,null]})})},t}(q);const va=BigInt(0),Ea=BigInt(1),Aa=9007199254740991;function xa(e,t){let n=Sa(e,"value");const r=BigInt(Ta(t,"width")),o=Ea<<r-Ea;return n<va?(n=-n,re(n<=o,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:e}),(~n&(Ea<<r)-Ea)+Ea):(re(n<o,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:e}),n)}function ka(e,t){const n=Ia(e,"value"),r=BigInt(Ta(t,"bits"));return n&(Ea<<r)-Ea}function Sa(e,t){switch(typeof e){case"bigint":return e;case"number":return oe(Number.isInteger(e),"underflow",t||"value",e),oe(e>=-Aa&&e<=Aa,"overflow",t||"value",e),BigInt(e);case"string":try{if(""===e)throw new Error("empty string");return"-"===e[0]&&"-"!==e[1]?-BigInt(e.substring(1)):BigInt(e)}catch(n){oe(!1,`invalid BigNumberish string: ${n.message}`,t||"value",e)}}oe(!1,"invalid BigNumberish value",t||"value",e)}function Ia(e,t){const n=Sa(e,t);return re(n>=va,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:e}),n}const Ca="0123456789abcdef";function Oa(e){if(e instanceof Uint8Array){let t="0x0";for(const n of e)t+=Ca[n>>4],t+=Ca[15&n];return BigInt(t)}return Sa(e)}function Ta(e,t){switch(typeof e){case"bigint":return oe(e>=-Aa&&e<=Aa,"overflow",t||"value",e),Number(e);case"number":return oe(Number.isInteger(e),"underflow",t||"value",e),oe(e>=-Aa&&e<=Aa,"overflow",t||"value",e),e;case"string":try{if(""===e)throw new Error("empty string");return Ta(BigInt(e),t)}catch(n){oe(!1,`invalid numeric string: ${n.message}`,t||"value",e)}}oe(!1,"invalid numeric value",t||"value",e)}function Na(e,t){const n=Ia(e,"value");let r=n.toString(16);if(null==t)r.length%2&&(r="0"+r);else{const o=Ta(t,"width");if(0===o&&n===va)return"0x";for(re(2*o>=r.length,`value exceeds width (${o} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:e});r.length<2*o;)r="0"+r}return"0x"+r}function Pa(e,t){const n=Ia(e,"value");if(n===va){const e=null!=t?Ta(t,"width"):0;return new Uint8Array(e)}let r=n.toString(16);if(r.length%2&&(r="0"+r),null!=t){const n=Ta(t,"width");for(;r.length<2*n;)r="00"+r;re(2*n===r.length,`value exceeds width (${n} bytes)`,"NUMERIC_FAULT",{operation:"toBeArray",fault:"overflow",value:e})}const o=new Uint8Array(r.length/2);for(let e=0;e<o.length;e++){const t=2*e;o[e]=parseInt(r.substring(t,t+2),16)}return o}function Ba(e){let t=ge(de(e)?e:Pa(e)).substring(2);for(;t.startsWith("0");)t=t.substring(1);return""===t&&(t="0"),"0x"+t}const Ra=32,Ua=new Uint8Array(Ra),Da=["then"],La={},Fa=new WeakMap;function _a(e){return Fa.get(e)}function Ma(e,t){Fa.set(e,t)}function Ga(e,t){const n=new Error(`deferred error during ABI decoding triggered accessing ${e}`);throw n.error=t,n}function ja(e,t,n){return e.indexOf(null)>=0?t.map((e,t)=>e instanceof Ha?ja(_a(e),e,n):e):e.reduce((e,r,o)=>{let i=t.getValue(r);return r in e||(n&&i instanceof Ha&&(i=ja(_a(i),i,n)),e[r]=i),e},{})}class Ha extends Array{#e;constructor(...e){const t=e[0];let n=e[1],r=(e[2]||[]).slice(),o=!0;t!==La&&(n=e,r=[],o=!1),super(n.length),n.forEach((e,t)=>{this[t]=e});const i=r.reduce((e,t)=>("string"==typeof t&&e.set(t,(e.get(t)||0)+1),e),new Map);if(Ma(this,Object.freeze(n.map((e,t)=>{const n=r[t];return null!=n&&1===i.get(n)?n:null}))),this.#e=[],null==this.#e&&this.#e,!o)return;Object.freeze(this);const s=new Proxy(this,{get:(e,t,n)=>{if("string"==typeof t){if(t.match(/^[0-9]+$/)){const n=Ta(t,"%index");if(n<0||n>=this.length)throw new RangeError("out of result range");const r=e[n];return r instanceof Error&&Ga(`index ${n}`,r),r}if(Da.indexOf(t)>=0)return Reflect.get(e,t,n);const r=e[t];if(r instanceof Function)return function(...t){return r.apply(this===n?e:this,t)};if(!(t in e))return e.getValue.apply(this===n?e:this,[t])}return Reflect.get(e,t,n)}});return Ma(s,_a(this)),s}toArray(e){const t=[];return this.forEach((n,r)=>{n instanceof Error&&Ga(`index ${r}`,n),e&&n instanceof Ha&&(n=n.toArray(e)),t.push(n)}),t}toObject(e){const t=_a(this);return t.reduce((n,r,o)=>(re(null!=r,`value at index ${o} unnamed`,"UNSUPPORTED_OPERATION",{operation:"toObject()"}),ja(t,this,e)),{})}slice(e,t){null==e&&(e=0),e<0&&(e+=this.length)<0&&(e=0),null==t&&(t=this.length),t<0&&(t+=this.length)<0&&(t=0),t>this.length&&(t=this.length);const n=_a(this),r=[],o=[];for(let i=e;i<t;i++)r.push(this[i]),o.push(n[i]);return new Ha(La,r,o)}filter(e,t){const n=_a(this),r=[],o=[];for(let i=0;i<this.length;i++){const s=this[i];s instanceof Error&&Ga(`index ${i}`,s),e.call(t,s,i,this)&&(r.push(s),o.push(n[i]))}return new Ha(La,r,o)}map(e,t){const n=[];for(let r=0;r<this.length;r++){const o=this[r];o instanceof Error&&Ga(`index ${r}`,o),n.push(e.call(t,o,r,this))}return n}getValue(e){const t=_a(this).indexOf(e);if(-1===t)return;const n=this[t];return n instanceof Error&&Ga(`property ${JSON.stringify(e)}`,n.error),n}static fromItems(e,t){return new Ha(La,e,t)}}function za(e){let t=Pa(e);return re(t.length<=Ra,"value out-of-bounds","BUFFER_OVERRUN",{buffer:t,length:Ra,offset:t.length}),t.length!==Ra&&(t=fe(ye([Ua.slice(t.length%Ra),t]))),t}class Va{name;type;localName;dynamic;constructor(e,t,n,r){Y(this,{name:e,type:t,localName:n,dynamic:r},{name:"string",type:"string",localName:"string",dynamic:"boolean"})}_throwError(e,t){oe(!1,e,this.localName,t)}}class Ka{#t;#n;constructor(){this.#t=[],this.#n=0}get data(){return ye(this.#t)}get length(){return this.#n}#r(e){return this.#t.push(e),this.#n+=e.length,e.length}appendWriter(e){return this.#r(fe(e.data))}writeBytes(e){let t=fe(e);const n=t.length%Ra;return n&&(t=fe(ye([t,Ua.slice(n)]))),this.#r(t)}writeValue(e){return this.#r(za(e))}writeUpdatableValue(){const e=this.#t.length;return this.#t.push(Ua),this.#n+=Ra,t=>{this.#t[e]=za(t)}}}class Wa{allowLoose;#t;#o;#i;#s;#a;constructor(e,t,n){Y(this,{allowLoose:!!t}),this.#t=fe(e),this.#i=0,this.#s=null,this.#a=null!=n?n:1024,this.#o=0}get data(){return ge(this.#t)}get dataLength(){return this.#t.length}get consumed(){return this.#o}get bytes(){return new Uint8Array(this.#t)}#c(e){if(this.#s)return this.#s.#c(e);this.#i+=e,re(this.#a<1||this.#i<=this.#a*this.dataLength,`compressed ABI data exceeds inflation ratio of ${this.#a} ( see: https://github.com/ethers-io/ethers.js/issues/4537 )`,"BUFFER_OVERRUN",{buffer:fe(this.#t),offset:this.#o,length:e,info:{bytesRead:this.#i,dataLength:this.dataLength}})}#u(e,t,n){let r=Math.ceil(t/Ra)*Ra;return this.#o+r>this.#t.length&&(this.allowLoose&&n&&this.#o+t<=this.#t.length?r=t:re(!1,"data out-of-bounds","BUFFER_OVERRUN",{buffer:fe(this.#t),length:this.#t.length,offset:this.#o+r})),this.#t.slice(this.#o,this.#o+r)}subReader(e){const t=new Wa(this.#t.slice(this.#o+e),this.allowLoose,this.#a);return t.#s=this,t}readBytes(e,t){let n=this.#u(0,e,!!t);return this.#c(e),this.#o+=n.length,n.slice(0,e)}readValue(){return Oa(this.readBytes(Ra))}readIndex(){return Ta(Oa(this.readBytes(Ra)))}}const $a=BigInt(0),qa=BigInt(36);function Ja(e){const t=(e=e.toLowerCase()).substring(2).split(""),n=new Uint8Array(40);for(let e=0;e<40;e++)n[e]=t[e].charCodeAt(0);const r=le(Vt(n));for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&(t[e]=t[e].toUpperCase()),(15&r[e>>1])>=8&&(t[e+1]=t[e+1].toUpperCase());return"0x"+t.join("")}const Qa={};for(let e=0;e<10;e++)Qa[String(e)]=String(e);for(let e=0;e<26;e++)Qa[String.fromCharCode(65+e)]=String(10+e);const Za=function(){const e={};for(let t=0;t<36;t++)e["0123456789abcdefghijklmnopqrstuvwxyz"[t]]=BigInt(t);return e}();function Ya(e){if(oe("string"==typeof e,"invalid address","address",e),e.match(/^(0x)?[0-9a-fA-F]{40}$/)){e.startsWith("0x")||(e="0x"+e);const t=Ja(e);return oe(!e.match(/([A-F].*[a-f])|([a-f].*[A-F])/)||t===e,"bad address checksum","address",e),t}if(e.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){oe(e.substring(2,4)===function(e){let t=(e=(e=e.toUpperCase()).substring(4)+e.substring(0,2)+"00").split("").map(e=>Qa[e]).join("");for(;t.length>=15;){let e=t.substring(0,15);t=parseInt(e,10)%97+t.substring(e.length)}let n=String(98-parseInt(t,10)%97);for(;n.length<2;)n="0"+n;return n}(e),"bad icap checksum","address",e);let t=function(e){e=e.toLowerCase();let t=$a;for(let n=0;n<e.length;n++)t=t*qa+Za[e[n]];return t}(e.substring(4)).toString(16);for(;t.length<40;)t="0"+t;return Ja("0x"+t)}oe(!1,"invalid address","address",e)}const Xa={};function ec(e,t){let n=!1;return t<0&&(n=!0,t*=-1),new rc(Xa,`${n?"":"u"}int${t}`,e,{signed:n,width:t})}function tc(e,t){return new rc(Xa,`bytes${t||""}`,e,{size:t})}const nc=Symbol.for("_ethers_typed");class rc{type;value;#l;_typedSymbol;constructor(e,t,n,r){null==r&&(r=null),ce(Xa,e,"Typed"),Y(this,{_typedSymbol:nc,type:t,value:n}),this.#l=r,this.format()}format(){if("array"===this.type)throw new Error("");if("dynamicArray"===this.type)throw new Error("");return"tuple"===this.type?`tuple(${this.value.map(e=>e.format()).join(",")})`:this.type}defaultValue(){return 0}minValue(){return 0}maxValue(){return 0}isBigInt(){return!!this.type.match(/^u?int[0-9]+$/)}isData(){return this.type.startsWith("bytes")}isString(){return"string"===this.type}get tupleName(){if("tuple"!==this.type)throw TypeError("not a tuple");return this.#l}get arrayLength(){if("array"!==this.type)throw TypeError("not an array");return!0===this.#l?-1:!1===this.#l?this.value.length:null}static from(e,t){return new rc(Xa,e,t)}static uint8(e){return ec(e,8)}static uint16(e){return ec(e,16)}static uint24(e){return ec(e,24)}static uint32(e){return ec(e,32)}static uint40(e){return ec(e,40)}static uint48(e){return ec(e,48)}static uint56(e){return ec(e,56)}static uint64(e){return ec(e,64)}static uint72(e){return ec(e,72)}static uint80(e){return ec(e,80)}static uint88(e){return ec(e,88)}static uint96(e){return ec(e,96)}static uint104(e){return ec(e,104)}static uint112(e){return ec(e,112)}static uint120(e){return ec(e,120)}static uint128(e){return ec(e,128)}static uint136(e){return ec(e,136)}static uint144(e){return ec(e,144)}static uint152(e){return ec(e,152)}static uint160(e){return ec(e,160)}static uint168(e){return ec(e,168)}static uint176(e){return ec(e,176)}static uint184(e){return ec(e,184)}static uint192(e){return ec(e,192)}static uint200(e){return ec(e,200)}static uint208(e){return ec(e,208)}static uint216(e){return ec(e,216)}static uint224(e){return ec(e,224)}static uint232(e){return ec(e,232)}static uint240(e){return ec(e,240)}static uint248(e){return ec(e,248)}static uint256(e){return ec(e,256)}static uint(e){return ec(e,256)}static int8(e){return ec(e,-8)}static int16(e){return ec(e,-16)}static int24(e){return ec(e,-24)}static int32(e){return ec(e,-32)}static int40(e){return ec(e,-40)}static int48(e){return ec(e,-48)}static int56(e){return ec(e,-56)}static int64(e){return ec(e,-64)}static int72(e){return ec(e,-72)}static int80(e){return ec(e,-80)}static int88(e){return ec(e,-88)}static int96(e){return ec(e,-96)}static int104(e){return ec(e,-104)}static int112(e){return ec(e,-112)}static int120(e){return ec(e,-120)}static int128(e){return ec(e,-128)}static int136(e){return ec(e,-136)}static int144(e){return ec(e,-144)}static int152(e){return ec(e,-152)}static int160(e){return ec(e,-160)}static int168(e){return ec(e,-168)}static int176(e){return ec(e,-176)}static int184(e){return ec(e,-184)}static int192(e){return ec(e,-192)}static int200(e){return ec(e,-200)}static int208(e){return ec(e,-208)}static int216(e){return ec(e,-216)}static int224(e){return ec(e,-224)}static int232(e){return ec(e,-232)}static int240(e){return ec(e,-240)}static int248(e){return ec(e,-248)}static int256(e){return ec(e,-256)}static int(e){return ec(e,-256)}static bytes1(e){return tc(e,1)}static bytes2(e){return tc(e,2)}static bytes3(e){return tc(e,3)}static bytes4(e){return tc(e,4)}static bytes5(e){return tc(e,5)}static bytes6(e){return tc(e,6)}static bytes7(e){return tc(e,7)}static bytes8(e){return tc(e,8)}static bytes9(e){return tc(e,9)}static bytes10(e){return tc(e,10)}static bytes11(e){return tc(e,11)}static bytes12(e){return tc(e,12)}static bytes13(e){return tc(e,13)}static bytes14(e){return tc(e,14)}static bytes15(e){return tc(e,15)}static bytes16(e){return tc(e,16)}static bytes17(e){return tc(e,17)}static bytes18(e){return tc(e,18)}static bytes19(e){return tc(e,19)}static bytes20(e){return tc(e,20)}static bytes21(e){return tc(e,21)}static bytes22(e){return tc(e,22)}static bytes23(e){return tc(e,23)}static bytes24(e){return tc(e,24)}static bytes25(e){return tc(e,25)}static bytes26(e){return tc(e,26)}static bytes27(e){return tc(e,27)}static bytes28(e){return tc(e,28)}static bytes29(e){return tc(e,29)}static bytes30(e){return tc(e,30)}static bytes31(e){return tc(e,31)}static bytes32(e){return tc(e,32)}static address(e){return new rc(Xa,"address",e)}static bool(e){return new rc(Xa,"bool",!!e)}static bytes(e){return new rc(Xa,"bytes",e)}static string(e){return new rc(Xa,"string",e)}static array(e,t){throw new Error("not implemented yet")}static tuple(e,t){throw new Error("not implemented yet")}static overrides(e){return new rc(Xa,"overrides",Object.assign({},e))}static isTyped(e){return e&&"object"==typeof e&&"_typedSymbol"in e&&e._typedSymbol===nc}static dereference(e,t){if(rc.isTyped(e)){if(e.type!==t)throw new Error(`invalid type: expecetd ${t}, got ${e.type}`);return e.value}return e}}class oc extends Va{constructor(e){super("address","address",e,!1)}defaultValue(){return"0x0000000000000000000000000000000000000000"}encode(e,t){let n=rc.dereference(t,"string");try{n=Ya(n)}catch(e){return this._throwError(e.message,t)}return e.writeValue(n)}decode(e){return Ya(Na(e.readValue(),20))}}class ic extends Va{coder;constructor(e){super(e.name,e.type,"_",e.dynamic),this.coder=e}defaultValue(){return this.coder.defaultValue()}encode(e,t){return this.coder.encode(e,t)}decode(e){return this.coder.decode(e)}}function sc(e,t,n){let r=[];if(Array.isArray(n))r=n;else if(n&&"object"==typeof n){let e={};r=t.map(t=>{const r=t.localName;return re(r,"cannot encode object for signature with missing names","INVALID_ARGUMENT",{argument:"values",info:{coder:t},value:n}),re(!e[r],"cannot encode object for signature with duplicate names","INVALID_ARGUMENT",{argument:"values",info:{coder:t},value:n}),e[r]=!0,n[r]})}else oe(!1,"invalid tuple value","tuple",n);oe(t.length===r.length,"types/value length mismatch","tuple",n);let o=new Ka,i=new Ka,s=[];t.forEach((e,t)=>{let n=r[t];if(e.dynamic){let t=i.length;e.encode(i,n);let r=o.writeUpdatableValue();s.push(e=>{r(e+t)})}else e.encode(o,n)}),s.forEach(e=>{e(o.length)});let a=e.appendWriter(o);return a+=e.appendWriter(i),a}function ac(e,t){let n=[],r=[],o=e.subReader(0);return t.forEach(t=>{let i=null;if(t.dynamic){let n=e.readIndex(),r=o.subReader(n);try{i=t.decode(r)}catch(e){if(ee(e,"BUFFER_OVERRUN"))throw e;i=e,i.baseType=t.name,i.name=t.localName,i.type=t.type}}else try{i=t.decode(e)}catch(e){if(ee(e,"BUFFER_OVERRUN"))throw e;i=e,i.baseType=t.name,i.name=t.localName,i.type=t.type}if(null==i)throw new Error("investigate");n.push(i),r.push(t.localName||null)}),Ha.fromItems(n,r)}class cc extends Va{coder;length;constructor(e,t,n){super("array",e.type+"["+(t>=0?t:"")+"]",n,-1===t||e.dynamic),Y(this,{coder:e,length:t})}defaultValue(){const e=this.coder.defaultValue(),t=[];for(let n=0;n<this.length;n++)t.push(e);return t}encode(e,t){const n=rc.dereference(t,"array");Array.isArray(n)||this._throwError("expected array value",n);let r=this.length;-1===r&&(r=n.length,e.writeValue(n.length)),ie(n.length,r,"coder array"+(this.localName?" "+this.localName:""));let o=[];for(let e=0;e<n.length;e++)o.push(this.coder);return sc(e,o,n)}decode(e){let t=this.length;-1===t&&(t=e.readIndex(),re(t*Ra<=e.dataLength,"insufficient data length","BUFFER_OVERRUN",{buffer:e.bytes,offset:t*Ra,length:e.dataLength}));let n=[];for(let e=0;e<t;e++)n.push(new ic(this.coder));return ac(e,n)}}class uc extends Va{constructor(e){super("bool","bool",e,!1)}defaultValue(){return!1}encode(e,t){const n=rc.dereference(t,"bool");return e.writeValue(n?1:0)}decode(e){return!!e.readValue()}}class lc extends Va{constructor(e,t){super(e,e,t,!0)}defaultValue(){return"0x"}encode(e,t){t=fe(t);let n=e.writeValue(t.length);return n+=e.writeBytes(t),n}decode(e){return e.readBytes(e.readIndex(),!0)}}class fc extends lc{constructor(e){super("bytes",e)}decode(e){return ge(super.decode(e))}}class hc extends Va{size;constructor(e,t){let n="bytes"+String(e);super(n,n,t,!1),Y(this,{size:e},{size:"number"})}defaultValue(){return"0x0000000000000000000000000000000000000000000000000000000000000000".substring(0,2+2*this.size)}encode(e,t){let n=fe(rc.dereference(t,this.type));return n.length!==this.size&&this._throwError("incorrect data length",t),e.writeBytes(n)}decode(e){return ge(e.readBytes(this.size))}}const dc=new Uint8Array([]);class pc extends Va{constructor(e){super("null","",e,!1)}defaultValue(){return null}encode(e,t){return null!=t&&this._throwError("not null",t),e.writeBytes(dc)}decode(e){return e.readBytes(0),null}}const gc=BigInt(0),yc=BigInt(1),mc=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");class wc extends Va{size;signed;constructor(e,t,n){const r=(t?"int":"uint")+8*e;super(r,r,n,!1),Y(this,{size:e,signed:t},{size:"number",signed:"boolean"})}defaultValue(){return 0}encode(e,t){let n=Sa(rc.dereference(t,this.type)),r=ka(mc,256);if(this.signed){let e=ka(r,8*this.size-1);(n>e||n<-(e+yc))&&this._throwError("value out-of-bounds",t),n=xa(n,256)}else(n<gc||n>ka(r,8*this.size))&&this._throwError("value out-of-bounds",t);return e.writeValue(n)}decode(e){let t=ka(e.readValue(),8*this.size);return this.signed&&(t=function(e,t){const n=Ia(e,"value"),r=BigInt(Ta(t,"width"));return re(n>>r===va,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:e}),n>>r-Ea?-((~n&(Ea<<r)-Ea)+Ea):n}(t,8*this.size)),t}}class bc extends lc{constructor(e){super("string",e)}defaultValue(){return""}encode(e,t){return super.encode(e,xe(rc.dereference(t,"string")))}decode(e){return ke(super.decode(e))}}class vc extends Va{coders;constructor(e,t){let n=!1;const r=[];e.forEach(e=>{e.dynamic&&(n=!0),r.push(e.type)}),super("tuple","tuple("+r.join(",")+")",t,n),Y(this,{coders:Object.freeze(e.slice())})}defaultValue(){const e=[];this.coders.forEach(t=>{e.push(t.defaultValue())});const t=this.coders.reduce((e,t)=>{const n=t.localName;return n&&(e[n]||(e[n]=0),e[n]++),e},{});return this.coders.forEach((n,r)=>{let o=n.localName;o&&1===t[o]&&("length"===o&&(o="_length"),null==e[o]&&(e[o]=e[r]))}),Object.freeze(e)}encode(e,t){const n=rc.dereference(t,"tuple");return sc(e,this.coders,n)}decode(e){return ac(e,this.coders)}}function Ec(e){return Vt(xe(e))}function Ac(e){const t=new Set;return e.forEach(e=>t.add(e)),Object.freeze(t)}const xc=Ac("external public payable override".split(" ")),kc="constant external internal payable private public pure view override",Sc=Ac(kc.split(" ")),Ic="constructor error event fallback function receive struct",Cc=Ac(Ic.split(" ")),Oc="calldata memory storage payable indexed",Tc=Ac(Oc.split(" ")),Nc=Ac([Ic,Oc,"tuple returns",kc].join(" ").split(" ")),Pc={"(":"OPEN_PAREN",")":"CLOSE_PAREN","[":"OPEN_BRACKET","]":"CLOSE_BRACKET",",":"COMMA","@":"AT"},Bc=new RegExp("^(\\s*)"),Rc=new RegExp("^([0-9]+)"),Uc=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)"),Dc=new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)$"),Lc=new RegExp("^(address|bool|bytes([0-9]*)|string|u?int([0-9]*))$");class Fc{#o;#f;get offset(){return this.#o}get length(){return this.#f.length-this.#o}constructor(e){this.#o=0,this.#f=e.slice()}clone(){return new Fc(this.#f)}reset(){this.#o=0}#h(e=0,t=0){return new Fc(this.#f.slice(e,t).map(t=>Object.freeze(Object.assign({},t,{match:t.match-e,linkBack:t.linkBack-e,linkNext:t.linkNext-e}))))}popKeyword(e){const t=this.peek();if("KEYWORD"!==t.type||!e.has(t.text))throw new Error(`expected keyword ${t.text}`);return this.pop().text}popType(e){if(this.peek().type!==e){const t=this.peek();throw new Error(`expected ${e}; got ${t.type} ${JSON.stringify(t.text)}`)}return this.pop().text}popParen(){const e=this.peek();if("OPEN_PAREN"!==e.type)throw new Error("bad start");const t=this.#h(this.#o+1,e.match+1);return this.#o=e.match+1,t}popParams(){const e=this.peek();if("OPEN_PAREN"!==e.type)throw new Error("bad start");const t=[];for(;this.#o<e.match-1;){const e=this.peek().linkNext;t.push(this.#h(this.#o+1,e)),this.#o=e}return this.#o=e.match+1,t}peek(){if(this.#o>=this.#f.length)throw new Error("out-of-bounds");return this.#f[this.#o]}peekKeyword(e){const t=this.peekType("KEYWORD");return null!=t&&e.has(t)?t:null}peekType(e){if(0===this.length)return null;const t=this.peek();return t.type===e?t.text:null}pop(){const e=this.peek();return this.#o++,e}toString(){const e=[];for(let t=this.#o;t<this.#f.length;t++){const n=this.#f[t];e.push(`${n.type}:${n.text}`)}return`<TokenString ${e.join(" ")}>`}}function _c(e){const t=[],n=t=>{const n=i<e.length?JSON.stringify(e[i]):"$EOI";throw new Error(`invalid token ${n} at ${i}: ${t}`)};let r=[],o=[],i=0;for(;i<e.length;){let s=e.substring(i),a=s.match(Bc);a&&(i+=a[1].length,s=e.substring(i));const c={depth:r.length,linkBack:-1,linkNext:-1,match:-1,type:"",text:"",offset:i,value:-1};t.push(c);let u=Pc[s[0]]||"";if(u){if(c.type=u,c.text=s[0],i++,"OPEN_PAREN"===u)r.push(t.length-1),o.push(t.length-1);else if("CLOSE_PAREN"==u)0===r.length&&n("no matching open bracket"),c.match=r.pop(),t[c.match].match=t.length-1,c.depth--,c.linkBack=o.pop(),t[c.linkBack].linkNext=t.length-1;else if("COMMA"===u)c.linkBack=o.pop(),t[c.linkBack].linkNext=t.length-1,o.push(t.length-1);else if("OPEN_BRACKET"===u)c.type="BRACKET";else if("CLOSE_BRACKET"===u){let e=t.pop().text;if(t.length>0&&"NUMBER"===t[t.length-1].type){const n=t.pop().text;e=n+e,t[t.length-1].value=Ta(n)}if(0===t.length||"BRACKET"!==t[t.length-1].type)throw new Error("missing opening bracket");t[t.length-1].text+=e}}else if(a=s.match(Uc),a){if(c.text=a[1],i+=c.text.length,Nc.has(c.text)){c.type="KEYWORD";continue}if(c.text.match(Lc)){c.type="TYPE";continue}c.type="ID"}else{if(a=s.match(Rc),!a)throw new Error(`unexpected token ${JSON.stringify(s[0])} at position ${i}`);c.text=a[1],c.type="NUMBER",i+=c.text.length}}return new Fc(t.map(e=>Object.freeze(e)))}function Mc(e,t){let n=[];for(const r in t.keys())e.has(r)&&n.push(r);if(n.length>1)throw new Error(`conflicting types: ${n.join(", ")}`)}function Gc(e,t){if(t.peekKeyword(Cc)){const n=t.pop().text;if(n!==e)throw new Error(`expected ${e}, got ${n}`)}return t.popType("ID")}function jc(e,t){const n=new Set;for(;;){const r=e.peekType("KEYWORD");if(null==r||t&&!t.has(r))break;if(e.pop(),n.has(r))throw new Error(`duplicate keywords: ${JSON.stringify(r)}`);n.add(r)}return Object.freeze(n)}function Hc(e){let t=jc(e,Sc);return Mc(t,Ac("constant payable nonpayable".split(" "))),Mc(t,Ac("pure view payable nonpayable".split(" "))),t.has("view")?"view":t.has("pure")?"pure":t.has("payable")?"payable":t.has("nonpayable")?"nonpayable":t.has("constant")?"view":"nonpayable"}function zc(e,t){return e.popParams().map(e=>ru.from(e,t))}function Vc(e){if(e.peekType("AT")){if(e.pop(),e.peekType("NUMBER"))return Sa(e.pop().text);throw new Error("invalid gas")}return null}function Kc(e){if(e.length)throw new Error(`unexpected tokens at offset ${e.offset}: ${e.toString()}`)}const Wc=new RegExp(/^(.*)\[([0-9]*)\]$/);function $c(e){const t=e.match(Lc);if(oe(t,"invalid type","type",e),"uint"===e)return"uint256";if("int"===e)return"int256";if(t[2]){const n=parseInt(t[2]);oe(0!==n&&n<=32,"invalid bytes length","type",e)}else if(t[3]){const n=parseInt(t[3]);oe(0!==n&&n<=256&&n%8==0,"invalid numeric width","type",e)}return e}const qc={},Jc=Symbol.for("_ethers_internal"),Qc="_ParamTypeInternal",Zc="_ErrorInternal",Yc="_EventInternal",Xc="_ConstructorInternal",eu="_FallbackInternal",tu="_FunctionInternal",nu="_StructInternal";class ru{name;type;baseType;indexed;components;arrayLength;arrayChildren;constructor(e,t,n,r,o,i,s,a){if(ce(e,qc,"ParamType"),Object.defineProperty(this,Jc,{value:Qc}),i&&(i=Object.freeze(i.slice())),"array"===r){if(null==s||null==a)throw new Error("")}else if(null!=s||null!=a)throw new Error("");if("tuple"===r){if(null==i)throw new Error("")}else if(null!=i)throw new Error("");Y(this,{name:t,type:n,baseType:r,indexed:o,components:i,arrayLength:s,arrayChildren:a})}format(e){if(null==e&&(e="sighash"),"json"===e){const t=this.name||"";if(this.isArray()){const e=JSON.parse(this.arrayChildren.format("json"));return e.name=t,e.type+=`[${this.arrayLength<0?"":String(this.arrayLength)}]`,JSON.stringify(e)}const n={type:"tuple"===this.baseType?"tuple":this.type,name:t};return"boolean"==typeof this.indexed&&(n.indexed=this.indexed),this.isTuple()&&(n.components=this.components.map(t=>JSON.parse(t.format(e)))),JSON.stringify(n)}let t="";return this.isArray()?(t+=this.arrayChildren.format(e),t+=`[${this.arrayLength<0?"":String(this.arrayLength)}]`):this.isTuple()?t+="("+this.components.map(t=>t.format(e)).join("full"===e?", ":",")+")":t+=this.type,"sighash"!==e&&(!0===this.indexed&&(t+=" indexed"),"full"===e&&this.name&&(t+=" "+this.name)),t}isArray(){return"array"===this.baseType}isTuple(){return"tuple"===this.baseType}isIndexable(){return null!=this.indexed}walk(e,t){if(this.isArray()){if(!Array.isArray(e))throw new Error("invalid array value");if(-1!==this.arrayLength&&e.length!==this.arrayLength)throw new Error("array is wrong length");const n=this;return e.map(e=>n.arrayChildren.walk(e,t))}if(this.isTuple()){if(!Array.isArray(e))throw new Error("invalid tuple value");if(e.length!==this.components.length)throw new Error("array is wrong length");const n=this;return e.map((e,r)=>n.components[r].walk(e,t))}return t(this.type,e)}#d(e,t,n,r){if(this.isArray()){if(!Array.isArray(t))throw new Error("invalid array value");if(-1!==this.arrayLength&&t.length!==this.arrayLength)throw new Error("array is wrong length");const o=this.arrayChildren,i=t.slice();return i.forEach((t,r)=>{o.#d(e,t,n,e=>{i[r]=e})}),void r(i)}if(this.isTuple()){const o=this.components;let i;if(Array.isArray(t))i=t.slice();else{if(null==t||"object"!=typeof t)throw new Error("invalid tuple value");i=o.map(e=>{if(!e.name)throw new Error("cannot use object value with unnamed components");if(!(e.name in t))throw new Error(`missing value for component ${e.name}`);return t[e.name]})}if(i.length!==this.components.length)throw new Error("array is wrong length");return i.forEach((t,r)=>{o[r].#d(e,t,n,e=>{i[r]=e})}),void r(i)}const o=n(this.type,t);o.then?e.push(async function(){r(await o)}()):r(o)}async walkAsync(e,t){const n=[],r=[e];return this.#d(n,e,t,e=>{r[0]=e}),n.length&&await Promise.all(n),r[0]}static from(e,t){if(ru.isParamType(e))return e;if("string"==typeof e)try{return ru.from(_c(e),t)}catch(t){oe(!1,"invalid param type","obj",e)}else if(e instanceof Fc){let n="",r="",o=null;jc(e,Ac(["tuple"])).has("tuple")||e.peekType("OPEN_PAREN")?(r="tuple",o=e.popParams().map(e=>ru.from(e)),n=`tuple(${o.map(e=>e.format()).join(",")})`):(n=$c(e.popType("TYPE")),r=n);let i=null,s=null;for(;e.length&&e.peekType("BRACKET");){const t=e.pop();i=new ru(qc,"",n,r,null,o,s,i),s=t.value,n+=t.text,r="array",o=null}let a=null;if(jc(e,Tc).has("indexed")){if(!t)throw new Error("");a=!0}const c=e.peekType("ID")?e.pop().text:"";if(e.length)throw new Error("leftover tokens");return new ru(qc,c,n,r,a,o,s,i)}const n=e.name;oe(!n||"string"==typeof n&&n.match(Dc),"invalid name","obj.name",n);let r=e.indexed;null!=r&&(oe(t,"parameter cannot be indexed","obj.indexed",e.indexed),r=!!r);let o=e.type,i=o.match(Wc);if(i){const t=parseInt(i[2]||"-1"),s=ru.from({type:i[1],components:e.components});return new ru(qc,n||"",o,"array",r,null,t,s)}if("tuple"===o||o.startsWith("tuple(")||o.startsWith("(")){const t=null!=e.components?e.components.map(e=>ru.from(e)):null;return new ru(qc,n||"",o,"tuple",r,t,null,null)}return o=$c(e.type),new ru(qc,n||"",o,o,r,null,null,null)}static isParamType(e){return e&&e[Jc]===Qc}}class ou{type;inputs;constructor(e,t,n){ce(e,qc,"Fragment"),Y(this,{type:t,inputs:n=Object.freeze(n.slice())})}static from(e){if("string"==typeof e){try{ou.from(JSON.parse(e))}catch(e){}return ou.from(_c(e))}if(e instanceof Fc)switch(e.peekKeyword(Cc)){case"constructor":return uu.from(e);case"error":return au.from(e);case"event":return cu.from(e);case"fallback":case"receive":return lu.from(e);case"function":return fu.from(e);case"struct":return hu.from(e)}else if("object"==typeof e){switch(e.type){case"constructor":return uu.from(e);case"error":return au.from(e);case"event":return cu.from(e);case"fallback":case"receive":return lu.from(e);case"function":return fu.from(e);case"struct":return hu.from(e)}re(!1,`unsupported type: ${e.type}`,"UNSUPPORTED_OPERATION",{operation:"Fragment.from"})}oe(!1,"unsupported frgament object","obj",e)}static isConstructor(e){return uu.isFragment(e)}static isError(e){return au.isFragment(e)}static isEvent(e){return cu.isFragment(e)}static isFunction(e){return fu.isFragment(e)}static isStruct(e){return hu.isFragment(e)}}class iu extends ou{name;constructor(e,t,n,r){super(e,t,r),oe("string"==typeof n&&n.match(Dc),"invalid identifier","name",n),r=Object.freeze(r.slice()),Y(this,{name:n})}}function su(e,t){return"("+t.map(t=>t.format(e)).join("full"===e?", ":",")+")"}class au extends iu{constructor(e,t,n){super(e,"error",t,n),Object.defineProperty(this,Jc,{value:Zc})}get selector(){return Ec(this.format("sighash")).substring(0,10)}format(e){if(null==e&&(e="sighash"),"json"===e)return JSON.stringify({type:"error",name:this.name,inputs:this.inputs.map(t=>JSON.parse(t.format(e)))});const t=[];return"sighash"!==e&&t.push("error"),t.push(this.name+su(e,this.inputs)),t.join(" ")}static from(e){if(au.isFragment(e))return e;if("string"==typeof e)return au.from(_c(e));if(e instanceof Fc){const t=Gc("error",e),n=zc(e);return Kc(e),new au(qc,t,n)}return new au(qc,e.name,e.inputs?e.inputs.map(ru.from):[])}static isFragment(e){return e&&e[Jc]===Zc}}class cu extends iu{anonymous;constructor(e,t,n,r){super(e,"event",t,n),Object.defineProperty(this,Jc,{value:Yc}),Y(this,{anonymous:r})}get topicHash(){return Ec(this.format("sighash"))}format(e){if(null==e&&(e="sighash"),"json"===e)return JSON.stringify({type:"event",anonymous:this.anonymous,name:this.name,inputs:this.inputs.map(t=>JSON.parse(t.format(e)))});const t=[];return"sighash"!==e&&t.push("event"),t.push(this.name+su(e,this.inputs)),"sighash"!==e&&this.anonymous&&t.push("anonymous"),t.join(" ")}static getTopicHash(e,t){return t=(t||[]).map(e=>ru.from(e)),new cu(qc,e,t,!1).topicHash}static from(e){if(cu.isFragment(e))return e;if("string"==typeof e)try{return cu.from(_c(e))}catch(t){oe(!1,"invalid event fragment","obj",e)}else if(e instanceof Fc){const t=Gc("event",e),n=zc(e,!0),r=!!jc(e,Ac(["anonymous"])).has("anonymous");return Kc(e),new cu(qc,t,n,r)}return new cu(qc,e.name,e.inputs?e.inputs.map(e=>ru.from(e,!0)):[],!!e.anonymous)}static isFragment(e){return e&&e[Jc]===Yc}}class uu extends ou{payable;gas;constructor(e,t,n,r,o){super(e,t,n),Object.defineProperty(this,Jc,{value:Xc}),Y(this,{payable:r,gas:o})}format(e){if(re(null!=e&&"sighash"!==e,"cannot format a constructor for sighash","UNSUPPORTED_OPERATION",{operation:"format(sighash)"}),"json"===e)return JSON.stringify({type:"constructor",stateMutability:this.payable?"payable":"undefined",payable:this.payable,gas:null!=this.gas?this.gas:void 0,inputs:this.inputs.map(t=>JSON.parse(t.format(e)))});const t=[`constructor${su(e,this.inputs)}`];return this.payable&&t.push("payable"),null!=this.gas&&t.push(`@${this.gas.toString()}`),t.join(" ")}static from(e){if(uu.isFragment(e))return e;if("string"==typeof e)try{return uu.from(_c(e))}catch(t){oe(!1,"invalid constuctor fragment","obj",e)}else if(e instanceof Fc){jc(e,Ac(["constructor"]));const t=zc(e),n=!!jc(e,xc).has("payable"),r=Vc(e);return Kc(e),new uu(qc,"constructor",t,n,r)}return new uu(qc,"constructor",e.inputs?e.inputs.map(ru.from):[],!!e.payable,null!=e.gas?e.gas:null)}static isFragment(e){return e&&e[Jc]===Xc}}class lu extends ou{payable;constructor(e,t,n){super(e,"fallback",t),Object.defineProperty(this,Jc,{value:eu}),Y(this,{payable:n})}format(e){const t=0===this.inputs.length?"receive":"fallback";if("json"===e){const e=this.payable?"payable":"nonpayable";return JSON.stringify({type:t,stateMutability:e})}return`${t}()${this.payable?" payable":""}`}static from(e){if(lu.isFragment(e))return e;if("string"==typeof e)try{return lu.from(_c(e))}catch(t){oe(!1,"invalid fallback fragment","obj",e)}else if(e instanceof Fc){const t=e.toString();if(oe(e.peekKeyword(Ac(["fallback","receive"])),"type must be fallback or receive","obj",t),"receive"===e.popKeyword(Ac(["fallback","receive"]))){const t=zc(e);return oe(0===t.length,"receive cannot have arguments","obj.inputs",t),jc(e,Ac(["payable"])),Kc(e),new lu(qc,[],!0)}let n=zc(e);n.length?oe(1===n.length&&"bytes"===n[0].type,"invalid fallback inputs","obj.inputs",n.map(e=>e.format("minimal")).join(", ")):n=[ru.from("bytes")];const r=Hc(e);if(oe("nonpayable"===r||"payable"===r,"fallback cannot be constants","obj.stateMutability",r),jc(e,Ac(["returns"])).has("returns")){const t=zc(e);oe(1===t.length&&"bytes"===t[0].type,"invalid fallback outputs","obj.outputs",t.map(e=>e.format("minimal")).join(", "))}return Kc(e),new lu(qc,n,"payable"===r)}if("receive"===e.type)return new lu(qc,[],!0);if("fallback"===e.type){const t=[ru.from("bytes")],n="payable"===e.stateMutability;return new lu(qc,t,n)}oe(!1,"invalid fallback description","obj",e)}static isFragment(e){return e&&e[Jc]===eu}}class fu extends iu{constant;outputs;stateMutability;payable;gas;constructor(e,t,n,r,o,i){super(e,"function",t,r),Object.defineProperty(this,Jc,{value:tu}),Y(this,{constant:"view"===n||"pure"===n,gas:i,outputs:o=Object.freeze(o.slice()),payable:"payable"===n,stateMutability:n})}get selector(){return Ec(this.format("sighash")).substring(0,10)}format(e){if(null==e&&(e="sighash"),"json"===e)return JSON.stringify({type:"function",name:this.name,constant:this.constant,stateMutability:"nonpayable"!==this.stateMutability?this.stateMutability:void 0,payable:this.payable,gas:null!=this.gas?this.gas:void 0,inputs:this.inputs.map(t=>JSON.parse(t.format(e))),outputs:this.outputs.map(t=>JSON.parse(t.format(e)))});const t=[];return"sighash"!==e&&t.push("function"),t.push(this.name+su(e,this.inputs)),"sighash"!==e&&("nonpayable"!==this.stateMutability&&t.push(this.stateMutability),this.outputs&&this.outputs.length&&(t.push("returns"),t.push(su(e,this.outputs))),null!=this.gas&&t.push(`@${this.gas.toString()}`)),t.join(" ")}static getSelector(e,t){return t=(t||[]).map(e=>ru.from(e)),new fu(qc,e,"view",t,[],null).selector}static from(e){if(fu.isFragment(e))return e;if("string"==typeof e)try{return fu.from(_c(e))}catch(t){oe(!1,"invalid function fragment","obj",e)}else if(e instanceof Fc){const t=Gc("function",e),n=zc(e),r=Hc(e);let o=[];jc(e,Ac(["returns"])).has("returns")&&(o=zc(e));const i=Vc(e);return Kc(e),new fu(qc,t,r,n,o,i)}let t=e.stateMutability;return null==t&&(t="payable","boolean"==typeof e.constant?(t="view",e.constant||(t="payable","boolean"!=typeof e.payable||e.payable||(t="nonpayable"))):"boolean"!=typeof e.payable||e.payable||(t="nonpayable")),new fu(qc,e.name,t,e.inputs?e.inputs.map(ru.from):[],e.outputs?e.outputs.map(ru.from):[],null!=e.gas?e.gas:null)}static isFragment(e){return e&&e[Jc]===tu}}class hu extends iu{constructor(e,t,n){super(e,"struct",t,n),Object.defineProperty(this,Jc,{value:nu})}format(){throw new Error("@TODO")}static from(e){if("string"==typeof e)try{return hu.from(_c(e))}catch(t){oe(!1,"invalid struct fragment","obj",e)}else if(e instanceof Fc){const t=Gc("struct",e),n=zc(e);return Kc(e),new hu(qc,t,n)}return new hu(qc,e.name,e.inputs?e.inputs.map(ru.from):[])}static isFragment(e){return e&&e[Jc]===nu}}const du=new Map;du.set(0,"GENERIC_PANIC"),du.set(1,"ASSERT_FALSE"),du.set(17,"OVERFLOW"),du.set(18,"DIVIDE_BY_ZERO"),du.set(33,"ENUM_RANGE_ERROR"),du.set(34,"BAD_STORAGE_DATA"),du.set(49,"STACK_UNDERFLOW"),du.set(50,"ARRAY_RANGE_ERROR"),du.set(65,"OUT_OF_MEMORY"),du.set(81,"UNINITIALIZED_FUNCTION_CALL");const pu=new RegExp(/^bytes([0-9]*)$/),gu=new RegExp(/^(u?int)([0-9]*)$/);let yu=null,mu=1024;class wu{#p(e){if(e.isArray())return new cc(this.#p(e.arrayChildren),e.arrayLength,e.name);if(e.isTuple())return new vc(e.components.map(e=>this.#p(e)),e.name);switch(e.baseType){case"address":return new oc(e.name);case"bool":return new uc(e.name);case"string":return new bc(e.name);case"bytes":return new fc(e.name);case"":return new pc(e.name)}let t=e.type.match(gu);if(t){let n=parseInt(t[2]||"256");return oe(0!==n&&n<=256&&n%8==0,"invalid "+t[1]+" bit length","param",e),new wc(n/8,"int"===t[1],e.name)}if(t=e.type.match(pu),t){let n=parseInt(t[1]);return oe(0!==n&&n<=32,"invalid bytes length","param",e),new hc(n,e.name)}oe(!1,"invalid type","type",e.type)}getDefaultValue(e){const t=e.map(e=>this.#p(ru.from(e)));return new vc(t,"_").defaultValue()}encode(e,t){ie(t.length,e.length,"types/values length mismatch");const n=e.map(e=>this.#p(ru.from(e))),r=new vc(n,"_"),o=new Ka;return r.encode(o,t),o.data}decode(e,t,n){const r=e.map(e=>this.#p(ru.from(e)));return new vc(r,"_").decode(new Wa(t,n,mu))}static _setDefaultMaxInflation(e){oe("number"==typeof e&&Number.isInteger(e),"invalid defaultMaxInflation factor","value",e),mu=e}static defaultAbiCoder(){return null==yu&&(yu=new wu),yu}static getBuiltinCallException(e,t,n){return function(e,t,n,r){let o="missing revert data",i=null,s=null;if(n){o="execution reverted";const e=le(n);if(n=ge(n),0===e.length)o+=" (no data present; likely require(false) occurred",i="require(false)";else if(e.length%32!=4)o+=" (could not decode reason; invalid data length)";else if("0x08c379a0"===ge(e.slice(0,4)))try{i=r.decode(["string"],e.slice(4))[0],s={signature:"Error(string)",name:"Error",args:[i]},o+=`: ${JSON.stringify(i)}`}catch(e){o+=" (could not decode reason; invalid string data)"}else if("0x4e487b71"===ge(e.slice(0,4)))try{const t=Number(r.decode(["uint256"],e.slice(4))[0]);s={signature:"Panic(uint256)",name:"Panic",args:[t]},i=`Panic due to ${du.get(t)||"UNKNOWN"}(${t})`,o+=`: ${i}`}catch(e){o+=" (could not decode panic code)"}else o+=" (unknown custom error)"}const a={to:t.to?Ya(t.to):null,data:t.data||"0x"};return t.from&&(a.from=Ya(t.from)),ne(o,"CALL_EXCEPTION",{action:e,data:n,reason:i,transaction:a,invocation:null,revert:s})}(e,t,n,wu.defaultAbiCoder())}}function bu(e){return e&&"function"==typeof e.getAddress}async function vu(e,t){const n=await t;return null!=n&&"0x0000000000000000000000000000000000000000"!==n||(re("string"!=typeof e,"unconfigured name","UNCONFIGURED_NAME",{value:e}),oe(!1,"invalid AddressLike value; did not resolve to a value address","target",e)),Ya(n)}function Eu(e,t){return"string"==typeof e?e.match(/^0x[0-9a-f]{40}$/i)?Ya(e):(re(null!=t,"ENS resolution requires a provider","UNSUPPORTED_OPERATION",{operation:"resolveName"}),vu(e,t.resolveName(e))):bu(e)?vu(e,e.getAddress()):e&&"function"==typeof e.then?vu(e,e):void oe(!1,"unsupported addressable value","target",e)}const Au=new Uint8Array(32);Au.fill(0);const xu=BigInt(-1),ku=BigInt(0),Su=BigInt(1),Iu=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Cu=Na(Su,32),Ou=Na(ku,32),Tu={name:"string",version:"string",chainId:"uint256",verifyingContract:"address",salt:"bytes32"},Nu=["name","version","chainId","verifyingContract","salt"];function Pu(e){return function(t){return oe("string"==typeof t,`invalid domain value for ${JSON.stringify(e)}`,`domain.${e}`,t),t}}const Bu={name:Pu("name"),version:Pu("version"),chainId:function(e){const t=Sa(e,"domain.chainId");return oe(t>=0,"invalid chain ID","domain.chainId",e),Number.isSafeInteger(t)?Number(t):Ba(t)},verifyingContract:function(e){try{return Ya(e).toLowerCase()}catch(e){}oe(!1,'invalid domain value "verifyingContract"',"domain.verifyingContract",e)},salt:function(e){const t=le(e,"domain.salt");return oe(32===t.length,'invalid domain value "salt"',"domain.salt",e),ge(t)}};function Ru(e){{const t=e.match(/^(u?)int(\d+)$/);if(t){const n=""===t[1],r=parseInt(t[2]);oe(r%8==0&&0!==r&&r<=256&&t[2]===String(r),"invalid numeric width","type",e);const o=ka(Iu,n?r-1:r),i=n?(o+Su)*xu:ku;return function(t){const r=Sa(t,"value");return oe(r>=i&&r<=o,`value out-of-bounds for ${e}`,"value",r),Na(n?xa(r,256):r,32)}}}{const t=e.match(/^bytes(\d+)$/);if(t){const n=parseInt(t[1]);return oe(0!==n&&n<=32&&t[1]===String(n),"invalid bytes width","type",e),function(t){return oe(le(t).length===n,`invalid length for ${e}`,"value",t),function(e){const t=le(e),n=t.length%32;return n?ye([t,Au.slice(n)]):ge(t)}(t)}}}switch(e){case"address":return function(e){return ve(Ya(e),32)};case"bool":return function(e){return e?Cu:Ou};case"bytes":return function(e){return Vt(e)};case"string":return function(e){return Ec(e)}}return null}function Uu(e,t){return`${e}(${t.map(({name:e,type:t})=>t+" "+e).join(",")})`}function Du(e){const t=e.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);return t?{base:t[1],index:t[2]+t[4],array:{base:t[1],prefix:t[1]+t[2],count:t[5]?parseInt(t[5]):-1}}:{base:e}}class Lu{primaryType;#g;get types(){return JSON.parse(this.#g)}#y;#m;constructor(e){this.#y=new Map,this.#m=new Map;const t=new Map,n=new Map,r=new Map,o={};Object.keys(e).forEach(i=>{o[i]=e[i].map(({name:t,type:n})=>{let{base:r,index:o}=Du(n);return"int"!==r||e.int||(r="int256"),"uint"!==r||e.uint||(r="uint256"),{name:t,type:r+(o||"")}}),t.set(i,new Set),n.set(i,[]),r.set(i,new Set)}),this.#g=JSON.stringify(o);for(const r in o){const i=new Set;for(const s of o[r]){oe(!i.has(s.name),`duplicate variable name ${JSON.stringify(s.name)} in ${JSON.stringify(r)}`,"types",e),i.add(s.name);const o=Du(s.type).base;oe(o!==r,`circular type reference to ${JSON.stringify(o)}`,"types",e),Ru(o)||(oe(n.has(o),`unknown type ${JSON.stringify(o)}`,"types",e),n.get(o).push(r),t.get(r).add(o))}}const i=Array.from(n.keys()).filter(e=>0===n.get(e).length);oe(0!==i.length,"missing primary type","types",e),oe(1===i.length,`ambiguous primary types or unused types: ${i.map(e=>JSON.stringify(e)).join(", ")}`,"types",e),Y(this,{primaryType:i[0]}),function o(i,s){oe(!s.has(i),`circular type reference to ${JSON.stringify(i)}`,"types",e),s.add(i);for(const e of t.get(i))if(n.has(e)){o(e,s);for(const t of s)r.get(t).add(e)}s.delete(i)}(this.primaryType,new Set);for(const[e,t]of r){const n=Array.from(t);n.sort(),this.#y.set(e,Uu(e,o[e])+n.map(e=>Uu(e,o[e])).join(""))}}getEncoder(e){let t=this.#m.get(e);return t||(t=this.#w(e),this.#m.set(e,t)),t}#w(e){{const t=Ru(e);if(t)return t}const t=Du(e).array;if(t){const e=t.prefix,n=this.getEncoder(e);return r=>{oe(-1===t.count||t.count===r.length,`array length mismatch; expected length ${t.count}`,"value",r);let o=r.map(n);return this.#y.has(e)&&(o=o.map(Vt)),Vt(ye(o))}}const n=this.types[e];if(n){const t=Ec(this.#y.get(e));return e=>{const r=n.map(({name:t,type:n})=>{const r=this.getEncoder(n)(e[t]);return this.#y.has(n)?Vt(r):r});return r.unshift(t),ye(r)}}oe(!1,`unknown type: ${e}`,"type",e)}encodeType(e){const t=this.#y.get(e);return oe(t,`unknown type: ${JSON.stringify(e)}`,"name",e),t}encodeData(e,t){return this.getEncoder(e)(t)}hashStruct(e,t){return Vt(this.encodeData(e,t))}encode(e){return this.encodeData(this.primaryType,e)}hash(e){return this.hashStruct(this.primaryType,e)}_visit(e,t,n){if(Ru(e))return n(e,t);const r=Du(e).array;if(r)return oe(-1===r.count||r.count===t.length,`array length mismatch; expected length ${r.count}`,"value",t),t.map(e=>this._visit(r.prefix,e,n));const o=this.types[e];if(o)return o.reduce((e,{name:r,type:o})=>(e[r]=this._visit(o,t[r],n),e),{});oe(!1,`unknown type: ${e}`,"type",e)}visit(e,t){return this._visit(this.primaryType,e,t)}static from(e){return new Lu(e)}static getPrimaryType(e){return Lu.from(e).primaryType}static hashStruct(e,t,n){return Lu.from(t).hashStruct(e,n)}static hashDomain(e){const t=[];for(const n in e){if(null==e[n])continue;const r=Tu[n];oe(r,`invalid typed-data domain key: ${JSON.stringify(n)}`,"domain",e),t.push({name:n,type:r})}return t.sort((e,t)=>Nu.indexOf(e.name)-Nu.indexOf(t.name)),Lu.hashStruct("EIP712Domain",{EIP712Domain:t},e)}static encode(e,t,n){return ye(["0x1901",Lu.hashDomain(e),Lu.from(t).hash(n)])}static hash(e,t,n){return Vt(Lu.encode(e,t,n))}static async resolveNames(e,t,n,r){e=Object.assign({},e);for(const t in e)null==e[t]&&delete e[t];const o={};e.verifyingContract&&!he(e.verifyingContract,20)&&(o[e.verifyingContract]="0x");const i=Lu.from(t);i.visit(n,(e,t)=>("address"!==e||he(t,20)||(o[t]="0x"),t));for(const e in o)o[e]=await r(e);return e.verifyingContract&&o[e.verifyingContract]&&(e.verifyingContract=o[e.verifyingContract]),{domain:e,value:n=i.visit(n,(e,t)=>"address"===e&&o[t]?o[t]:t)}}static getPayload(e,t,n){Lu.hashDomain(e);const r={},o=[];Nu.forEach(t=>{const n=e[t];null!=n&&(r[t]=Bu[t](n),o.push({name:t,type:Tu[t]}))});const i=Lu.from(t);t=i.types;const s=Object.assign({},t);return oe(null==s.EIP712Domain,"types must not contain EIP712Domain type","types.EIP712Domain",t),s.EIP712Domain=o,i.encode(n),{types:s,domain:r,primaryType:i.primaryType,message:i.visit(n,(e,t)=>{if(e.match(/^bytes(\d*)/))return ge(le(t));if(e.match(/^u?int/))return Sa(t).toString();switch(e){case"address":return t.toLowerCase();case"bool":return!!t;case"string":return oe("string"==typeof t,"invalid string","value",t),t}oe(!1,"unsupported type","type",e)})}}}function Fu(e,t){return{address:Ya(e),storageKeys:t.map((e,t)=>(oe(he(e,32),"invalid slot",`storageKeys[${t}]`,e),e.toLowerCase()))}}function _u(e){if(Array.isArray(e))return e.map((t,n)=>Array.isArray(t)?(oe(2===t.length,"invalid slot set",`value[${n}]`,t),Fu(t[0],t[1])):(oe(null!=t&&"object"==typeof t,"invalid address-slot set","value",e),Fu(t.address,t.storageKeys)));oe(null!=e&&"object"==typeof e,"invalid access list","value",e);const t=Object.keys(e).map(t=>{const n=e[t].reduce((e,t)=>(e[t]=!0,e),{});return Fu(t,Object.keys(n).sort())});return t.sort((e,t)=>e.address.localeCompare(t.address)),t}const Mu="0x0000000000000000000000000000000000000000000000000000000000000000",Gu=BigInt(0),ju=BigInt(1),Hu=BigInt(2),zu=BigInt(27),Vu=BigInt(28),Ku=BigInt(35),Wu=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),$u=Wu/Hu,qu=Symbol.for("nodejs.util.inspect.custom"),Ju={};function Qu(e){return ve(Pa(e),32)}class Zu{#b;#v;#E;#A;get r(){return this.#b}set r(e){oe(32===me(e),"invalid r","value",e),this.#b=ge(e)}get s(){return oe(parseInt(this.#v.substring(0,3))<8,"non-canonical s; use ._s","s",this.#v),this.#v}set s(e){oe(32===me(e),"invalid s","value",e),this.#v=ge(e)}get _s(){return this.#v}isValid(){return BigInt(this.#v)<=$u}get v(){return this.#E}set v(e){const t=Ta(e,"value");oe(27===t||28===t,"invalid v","v",e),this.#E=t}get networkV(){return this.#A}get legacyChainId(){const e=this.networkV;return null==e?null:Zu.getChainId(e)}get yParity(){return 27===this.v?0:1}get yParityAndS(){const e=le(this.s);return this.yParity&&(e[0]|=128),ge(e)}get compactSerialized(){return ye([this.r,this.yParityAndS])}get serialized(){return ye([this.r,this.s,this.yParity?"0x1c":"0x1b"])}constructor(e,t,n,r){ce(e,Ju,"Signature"),this.#b=t,this.#v=n,this.#E=r,this.#A=null}getCanonical(){if(this.isValid())return this;const e=Wu-BigInt(this._s),t=55-this.v,n=new Zu(Ju,this.r,Qu(e),t);return this.networkV&&(n.#A=this.networkV),n}clone(){const e=new Zu(Ju,this.r,this._s,this.v);return this.networkV&&(e.#A=this.networkV),e}toJSON(){const e=this.networkV;return{_type:"signature",networkV:null!=e?e.toString():null,r:this.r,s:this._s,v:this.v}}[qu](){return this.toString()}toString(){return this.isValid()?`Signature { r: ${this.r}, s: ${this._s}, v: ${this.v} }`:`Signature { r: ${this.r}, s: ${this._s}, v: ${this.v}, valid: false }`}static getChainId(e){const t=Sa(e,"v");return t==zu||t==Vu?Gu:(oe(t>=Ku,"invalid EIP-155 v","v",e),(t-Ku)/Hu)}static getChainIdV(e,t){return Sa(e)*Hu+BigInt(35+t-27)}static getNormalizedV(e){const t=Sa(e);return t===Gu||t===zu?27:t===ju||t===Vu?28:(oe(t>=Ku,"invalid v","v",e),t&ju?27:28)}static from(e){function t(t,n){oe(t,n,"signature",e)}if(null==e)return new Zu(Ju,Mu,Mu,27);if("string"==typeof e){const n=le(e,"signature");if(64===n.length){const e=ge(n.slice(0,32)),t=n.slice(32,64),r=128&t[0]?28:27;return t[0]&=127,new Zu(Ju,e,ge(t),r)}if(65===n.length){const e=ge(n.slice(0,32)),t=ge(n.slice(32,64)),r=Zu.getNormalizedV(n[64]);return new Zu(Ju,e,t,r)}t(!1,"invalid raw signature length")}if(e instanceof Zu)return e.clone();const n=e.r;t(null!=n,"missing r");const r=Qu(n),o=function(e,n){if(null!=e)return Qu(e);if(null!=n){t(he(n,32),"invalid yParityAndS");const e=le(n);return e[0]&=127,ge(e)}t(!1,"missing s")}(e.s,e.yParityAndS),{networkV:i,v:s}=function(e,n,r){if(null!=e){const t=Sa(e);return{networkV:t>=Ku?t:void 0,v:Zu.getNormalizedV(t)}}if(null!=n)return t(he(n,32),"invalid yParityAndS"),{v:128&le(n)[0]?28:27};if(null!=r){switch(Ta(r,"sig.yParity")){case 0:return{v:27};case 1:return{v:28}}t(!1,"invalid yParity")}t(!1,"missing v")}(e.v,e.yParityAndS,e.yParity),a=new Zu(Ju,r,o,s);return i&&(a.#A=i),t(null==e.yParity||Ta(e.yParity,"sig.yParity")===a.yParity,"yParity mismatch"),t(null==e.yParityAndS||e.yParityAndS===a.yParityAndS,"yParityAndS mismatch"),a}}function Yu(e){return{address:Ya(e.address),nonce:Sa(null!=e.nonce?e.nonce:0),chainId:Sa(null!=e.chainId?e.chainId:0),signature:Zu.from(e.signature)}}function Xu(e){return async function(t,n){re(null==n||!n.cancelled,"request cancelled before sending","CANCELLED");const r=t.url.split(":")[0].toLowerCase();re("http"===r||"https"===r,`unsupported protocol ${r}`,"UNSUPPORTED_OPERATION",{info:{protocol:r},operation:"request"}),re("https"===r||!t.credentials||t.allowInsecureAuthentication,"insecure authorized connections unsupported","UNSUPPORTED_OPERATION",{operation:"request"});let o=null;const i=new AbortController,s=setTimeout(()=>{o=ne("request timeout","TIMEOUT"),i.abort()},t.timeout);n&&n.addListener(()=>{o=ne("request cancelled","CANCELLED"),i.abort()});const a=Object.assign({},e,{method:t.method,headers:new Headers(Array.from(t)),body:t.body||void 0,signal:i.signal});let c;try{c=await fetch(t.url,a)}catch(e){if(clearTimeout(s),o)throw o;throw e}clearTimeout(s);const u={};c.headers.forEach((e,t)=>{u[t.toLowerCase()]=e});const l=await c.arrayBuffer(),f=null==l?null:new Uint8Array(l);return{statusCode:c.status,statusMessage:c.statusText,headers:u,body:f}}}Xu({});let el=Xu();const tl=new RegExp("^data:([^;:]*)?(;base64)?,(.*)$","i"),nl=new RegExp("^ipfs://(ipfs/)?(.*)$","i");let rl=!1;async function ol(e,t){try{const t=e.match(tl);if(!t)throw new Error("invalid data");return new fl(200,"OK",{"content-type":t[1]||"text/plain"},t[2]?function(e){e=atob(e);const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return le(t)}(t[3]):xe(t[3].replace(/%([0-9a-f][0-9a-f])/gi,(e,t)=>String.fromCharCode(parseInt(t,16)))))}catch(t){return new fl(599,"BAD REQUEST (invalid data: URI)",{},null,new ll(e))}}function il(e){return async function(t,n){try{const n=t.match(nl);if(!n)throw new Error("invalid link");return new ll(`${e}${n[2]}`)}catch(e){return new fl(599,"BAD REQUEST (invalid IPFS URI)",{},null,new ll(t))}}}const sl={data:ol,ipfs:il("https://gateway.ipfs.io/ipfs/")},al=new WeakMap;class cl{#x;#k;constructor(e){this.#x=[],this.#k=!1,al.set(e,()=>{if(!this.#k){this.#k=!0;for(const e of this.#x)setTimeout(()=>{e()},0);this.#x=[]}})}addListener(e){re(!this.#k,"singal already cancelled","UNSUPPORTED_OPERATION",{operation:"fetchCancelSignal.addCancelListener"}),this.#x.push(e)}get cancelled(){return this.#k}checkSignal(){re(!this.cancelled,"cancelled","CANCELLED",{})}}function ul(e){if(null==e)throw new Error("missing signal; should not happen");return e.checkSignal(),e}class ll{#S;#I;#C;#O;#T;#N;#P;#B;#R;#U;#D;#L;#F;#_;#M;get url(){return this.#N}set url(e){this.#N=String(e)}get body(){return null==this.#P?null:new Uint8Array(this.#P)}set body(e){if(null==e)this.#P=void 0,this.#B=void 0;else if("string"==typeof e)this.#P=xe(e),this.#B="text/plain";else if(e instanceof Uint8Array)this.#P=e,this.#B="application/octet-stream";else{if("object"!=typeof e)throw new Error("invalid body");this.#P=xe(JSON.stringify(e)),this.#B="application/json"}}hasBody(){return null!=this.#P}get method(){return this.#O?this.#O:this.hasBody()?"POST":"GET"}set method(e){null==e&&(e=""),this.#O=String(e).toUpperCase()}get headers(){const e=Object.assign({},this.#C);return this.#R&&(e.authorization=`Basic ${function(e){const t=le(e);let n="";for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)}(xe(this.#R))}`),this.allowGzip&&(e["accept-encoding"]="gzip"),null==e["content-type"]&&this.#B&&(e["content-type"]=this.#B),this.body&&(e["content-length"]=String(this.body.length)),e}getHeader(e){return this.headers[e.toLowerCase()]}setHeader(e,t){this.#C[String(e).toLowerCase()]=String(t)}clearHeaders(){this.#C={}}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const r=t[n++];return{value:[r,e[r]],done:!1}}return{value:void 0,done:!0}}}}get credentials(){return this.#R||null}setCredentials(e,t){oe(!e.match(/:/),"invalid basic authentication username","username","[REDACTED]"),this.#R=`${e}:${t}`}get allowGzip(){return this.#I}set allowGzip(e){this.#I=!!e}get allowInsecureAuthentication(){return!!this.#S}set allowInsecureAuthentication(e){this.#S=!!e}get timeout(){return this.#T}set timeout(e){oe(e>=0,"timeout must be non-zero","timeout",e),this.#T=e}get preflightFunc(){return this.#U||null}set preflightFunc(e){this.#U=e}get processFunc(){return this.#D||null}set processFunc(e){this.#D=e}get retryFunc(){return this.#L||null}set retryFunc(e){this.#L=e}get getUrlFunc(){return this.#M||el}set getUrlFunc(e){this.#M=e}constructor(e){this.#N=String(e),this.#S=!1,this.#I=!0,this.#C={},this.#O="",this.#T=3e5,this.#_={slotInterval:250,maxAttempts:12},this.#M=null}toString(){return`<FetchRequest method=${JSON.stringify(this.method)} url=${JSON.stringify(this.url)} headers=${JSON.stringify(this.headers)} body=${this.#P?ge(this.#P):"null"}>`}setThrottleParams(e){null!=e.slotInterval&&(this.#_.slotInterval=e.slotInterval),null!=e.maxAttempts&&(this.#_.maxAttempts=e.maxAttempts)}async#G(e,t,n,r,o){if(e>=this.#_.maxAttempts)return o.makeServerError("exceeded maximum retry limit");re(hl()<=t,"timeout","TIMEOUT",{operation:"request.send",reason:"timeout",request:r}),n>0&&await function(e){return new Promise(t=>setTimeout(t,e))}(n);let i=this.clone();const s=(i.url.split(":")[0]||"").toLowerCase();if(s in sl){const e=await sl[s](i.url,ul(r.#F));if(e instanceof fl){let t=e;if(this.processFunc){ul(r.#F);try{t=await this.processFunc(i,t)}catch(e){null!=e.throttle&&"number"==typeof e.stall||t.makeServerError("error in post-processing function",e).assertOk()}}return t}i=e}this.preflightFunc&&(i=await this.preflightFunc(i));const a=await this.getUrlFunc(i,ul(r.#F));let c=new fl(a.statusCode,a.statusMessage,a.headers,a.body,r);if(301===c.statusCode||302===c.statusCode){try{const n=c.headers.location||"";return i.redirect(n).#G(e+1,t,0,r,c)}catch(e){}return c}if(429===c.statusCode&&(null==this.retryFunc||await this.retryFunc(i,c,e))){const n=c.headers["retry-after"];let o=this.#_.slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return"string"==typeof n&&n.match(/^[1-9][0-9]*$/)&&(o=parseInt(n)),i.clone().#G(e+1,t,o,r,c)}if(this.processFunc){ul(r.#F);try{c=await this.processFunc(i,c)}catch(n){null!=n.throttle&&"number"==typeof n.stall||c.makeServerError("error in post-processing function",n).assertOk();let o=this.#_.slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return n.stall>=0&&(o=n.stall),i.clone().#G(e+1,t,o,r,c)}}return c}send(){return re(null==this.#F,"request already sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.send"}),this.#F=new cl(this),this.#G(0,hl()+this.timeout,0,this,new fl(0,"",{},null,this))}cancel(){re(null!=this.#F,"request has not been sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.cancel"});const e=al.get(this);if(!e)throw new Error("missing signal; should not happen");e()}redirect(e){const t=this.url.split(":")[0].toLowerCase(),n=e.split(":")[0].toLowerCase();re("GET"===this.method&&("https"!==t||"http"!==n)&&e.match(/^https?:/),"unsupported redirect","UNSUPPORTED_OPERATION",{operation:`redirect(${this.method} ${JSON.stringify(this.url)} => ${JSON.stringify(e)})`});const r=new ll(e);return r.method="GET",r.allowGzip=this.allowGzip,r.timeout=this.timeout,r.#C=Object.assign({},this.#C),this.#P&&(r.#P=new Uint8Array(this.#P)),r.#B=this.#B,r}clone(){const e=new ll(this.url);return e.#O=this.#O,this.#P&&(e.#P=this.#P),e.#B=this.#B,e.#C=Object.assign({},this.#C),e.#R=this.#R,this.allowGzip&&(e.allowGzip=!0),e.timeout=this.timeout,this.allowInsecureAuthentication&&(e.allowInsecureAuthentication=!0),e.#U=this.#U,e.#D=this.#D,e.#L=this.#L,e.#_=Object.assign({},this.#_),e.#M=this.#M,e}static lockConfig(){rl=!0}static getGateway(e){return sl[e.toLowerCase()]||null}static registerGateway(e,t){if("http"===(e=e.toLowerCase())||"https"===e)throw new Error(`cannot intercept ${e}; use registerGetUrl`);if(rl)throw new Error("gateways locked");sl[e]=t}static registerGetUrl(e){if(rl)throw new Error("gateways locked");el=e}static createGetUrlFunc(e){return Xu(e)}static createDataGateway(){return ol}static createIpfsGatewayFunc(e){return il(e)}}class fl{#j;#H;#C;#P;#z;#V;toString(){return`<FetchResponse status=${this.statusCode} body=${this.#P?ge(this.#P):"null"}>`}get statusCode(){return this.#j}get statusMessage(){return this.#H}get headers(){return Object.assign({},this.#C)}get body(){return null==this.#P?null:new Uint8Array(this.#P)}get bodyText(){try{return null==this.#P?"":ke(this.#P)}catch(e){re(!1,"response body is not valid UTF-8 data","UNSUPPORTED_OPERATION",{operation:"bodyText",info:{response:this}})}}get bodyJson(){try{return JSON.parse(this.bodyText)}catch(e){re(!1,"response body is not valid JSON","UNSUPPORTED_OPERATION",{operation:"bodyJson",info:{response:this}})}}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const r=t[n++];return{value:[r,e[r]],done:!1}}return{value:void 0,done:!0}}}}constructor(e,t,n,r,o){this.#j=e,this.#H=t,this.#C=Object.keys(n).reduce((e,t)=>(e[t.toLowerCase()]=String(n[t]),e),{}),this.#P=null==r?null:new Uint8Array(r),this.#z=o||null,this.#V={message:""}}makeServerError(e,t){let n;n=e?`CLIENT ESCALATED SERVER ERROR (${this.statusCode} ${this.statusMessage}; ${e})`:`CLIENT ESCALATED SERVER ERROR (${e=`${this.statusCode} ${this.statusMessage}`})`;const r=new fl(599,n,this.headers,this.body,this.#z||void 0);return r.#V={message:e,error:t},r}throwThrottleError(e,t){null==t?t=-1:oe(Number.isInteger(t)&&t>=0,"invalid stall timeout","stall",t);const n=new Error(e||"throttling requests");throw Y(n,{stall:t,throttle:!0}),n}getHeader(e){return this.headers[e.toLowerCase()]}hasBody(){return null!=this.#P}get request(){return this.#z}ok(){return""===this.#V.message&&this.statusCode>=200&&this.statusCode<300}assertOk(){if(this.ok())return;let{message:e,error:t}=this.#V;""===e&&(e=`server response ${this.statusCode} ${this.statusMessage}`);let n=null;this.request&&(n=this.request.url);let r=null;try{this.#P&&(r=ke(this.#P))}catch(e){}re(!1,e,"SERVER_ERROR",{request:this.request||"unknown request",response:this,error:t,info:{requestUrl:n,responseBody:r,responseStatus:`${this.statusCode} ${this.statusMessage}`}})}}function hl(){return(new Date).getTime()}const dl="0x0000000000000000000000000000000000000000";class pl{fragment;name;signature;topic;args;constructor(e,t,n){const r=e.name,o=e.format();Y(this,{fragment:e,name:r,signature:o,topic:t,args:n})}}class gl{fragment;name;args;signature;selector;value;constructor(e,t,n,r){const o=e.name,i=e.format();Y(this,{fragment:e,name:o,args:n,signature:i,selector:t,value:r})}}class yl{fragment;name;args;signature;selector;constructor(e,t,n){const r=e.name,o=e.format();Y(this,{fragment:e,name:r,args:n,signature:o,selector:t})}}class ml{hash;_isIndexed;static isIndexed(e){return!(!e||!e._isIndexed)}constructor(e){Y(this,{hash:e,_isIndexed:!0})}}const wl={0:"generic panic",1:"assert(false)",17:"arithmetic overflow",18:"division or modulo by zero",33:"enum overflow",34:"invalid encoded storage byte array accessed",49:"out-of-bounds array access; popping on an empty array",50:"out-of-bounds access of an array or bytesN",65:"out of memory",81:"uninitialized function"},bl={"0x08c379a0":{signature:"Error(string)",name:"Error",inputs:["string"],reason:e=>`reverted with reason string ${JSON.stringify(e)}`},"0x4e487b71":{signature:"Panic(uint256)",name:"Panic",inputs:["uint256"],reason:e=>{let t="unknown panic code";return e>=0&&e<=255&&wl[e.toString()]&&(t=wl[e.toString()]),`reverted with panic code 0x${e.toString(16)} (${t})`}}};class vl{fragments;deploy;fallback;receive;#K;#W;#$;#q;constructor(e){let t=[];t="string"==typeof e?JSON.parse(e):e,this.#$=new Map,this.#K=new Map,this.#W=new Map;const n=[];for(const e of t)try{n.push(ou.from(e))}catch(t){console.log(`[Warning] Invalid Fragment ${JSON.stringify(e)}:`,t.message)}Y(this,{fragments:Object.freeze(n)});let r=null,o=!1;this.#q=this.getAbiCoder(),this.fragments.forEach((e,t)=>{let n;switch(e.type){case"constructor":return this.deploy?void console.log("duplicate definition - constructor"):void Y(this,{deploy:e});case"fallback":return void(0===e.inputs.length?o=!0:(oe(!r||e.payable!==r.payable,"conflicting fallback fragments",`fragments[${t}]`,e),r=e,o=r.payable));case"function":n=this.#$;break;case"event":n=this.#W;break;case"error":n=this.#K;break;default:return}const i=e.format();n.has(i)||n.set(i,e)}),this.deploy||Y(this,{deploy:uu.from("constructor()")}),Y(this,{fallback:r,receive:o})}format(e){const t=e?"minimal":"full",n=this.fragments.map(e=>e.format(t));return n}formatJson(){const e=this.fragments.map(e=>e.format("json"));return JSON.stringify(e.map(e=>JSON.parse(e)))}getAbiCoder(){return wu.defaultAbiCoder()}#J(e,t,n){if(he(e)){const t=e.toLowerCase();for(const e of this.#$.values())if(t===e.selector)return e;return null}if(-1===e.indexOf("(")){const r=[];for(const[t,n]of this.#$)t.split("(")[0]===e&&r.push(n);if(t){const e=t.length>0?t[t.length-1]:null;let n=t.length,o=!0;rc.isTyped(e)&&"overrides"===e.type&&(o=!1,n--);for(let e=r.length-1;e>=0;e--){const t=r[e].inputs.length;t===n||o&&t===n-1||r.splice(e,1)}for(let e=r.length-1;e>=0;e--){const n=r[e].inputs;for(let o=0;o<t.length;o++)if(rc.isTyped(t[o])){if(o>=n.length){if("overrides"===t[o].type)continue;r.splice(e,1);break}if(t[o].type!==n[o].baseType){r.splice(e,1);break}}}}if(1===r.length&&t&&t.length!==r[0].inputs.length){const e=t[t.length-1];(null==e||Array.isArray(e)||"object"!=typeof e)&&r.splice(0,1)}return 0===r.length?null:(r.length>1&&n&&oe(!1,`ambiguous function description (i.e. matches ${r.map(e=>JSON.stringify(e.format())).join(", ")})`,"key",e),r[0])}return this.#$.get(fu.from(e).format())||null}getFunctionName(e){const t=this.#J(e,null,!1);return oe(t,"no matching function","key",e),t.name}hasFunction(e){return!!this.#J(e,null,!1)}getFunction(e,t){return this.#J(e,t||null,!0)}forEachFunction(e){const t=Array.from(this.#$.keys());t.sort((e,t)=>e.localeCompare(t));for(let n=0;n<t.length;n++){const r=t[n];e(this.#$.get(r),n)}}#Q(e,t,n){if(he(e)){const t=e.toLowerCase();for(const e of this.#W.values())if(t===e.topicHash)return e;return null}if(-1===e.indexOf("(")){const r=[];for(const[t,n]of this.#W)t.split("(")[0]===e&&r.push(n);if(t){for(let e=r.length-1;e>=0;e--)r[e].inputs.length<t.length&&r.splice(e,1);for(let e=r.length-1;e>=0;e--){const n=r[e].inputs;for(let o=0;o<t.length;o++)if(rc.isTyped(t[o])&&t[o].type!==n[o].baseType){r.splice(e,1);break}}}return 0===r.length?null:(r.length>1&&n&&oe(!1,`ambiguous event description (i.e. matches ${r.map(e=>JSON.stringify(e.format())).join(", ")})`,"key",e),r[0])}return this.#W.get(cu.from(e).format())||null}getEventName(e){const t=this.#Q(e,null,!1);return oe(t,"no matching event","key",e),t.name}hasEvent(e){return!!this.#Q(e,null,!1)}getEvent(e,t){return this.#Q(e,t||null,!0)}forEachEvent(e){const t=Array.from(this.#W.keys());t.sort((e,t)=>e.localeCompare(t));for(let n=0;n<t.length;n++){const r=t[n];e(this.#W.get(r),n)}}getError(e,t){if(he(e)){const t=e.toLowerCase();if(bl[t])return au.from(bl[t].signature);for(const e of this.#K.values())if(t===e.selector)return e;return null}if(-1===e.indexOf("(")){const t=[];for(const[n,r]of this.#K)n.split("(")[0]===e&&t.push(r);return 0===t.length?"Error"===e?au.from("error Error(string)"):"Panic"===e?au.from("error Panic(uint256)"):null:(t.length>1&&oe(!1,`ambiguous error description (i.e. ${t.map(e=>JSON.stringify(e.format())).join(", ")})`,"name",e),t[0])}if("Error(string)"===(e=au.from(e).format()))return au.from("error Error(string)");if("Panic(uint256)"===e)return au.from("error Panic(uint256)");return this.#K.get(e)||null}forEachError(e){const t=Array.from(this.#K.keys());t.sort((e,t)=>e.localeCompare(t));for(let n=0;n<t.length;n++){const r=t[n];e(this.#K.get(r),n)}}_decodeParams(e,t){return this.#q.decode(e,t)}_encodeParams(e,t){return this.#q.encode(e,t)}encodeDeploy(e){return this._encodeParams(this.deploy.inputs,e||[])}decodeErrorResult(e,t){if("string"==typeof e){const t=this.getError(e);oe(t,"unknown error","fragment",e),e=t}return oe(we(t,0,4)===e.selector,`data signature does not match error ${e.name}.`,"data",t),this._decodeParams(e.inputs,we(t,4))}encodeErrorResult(e,t){if("string"==typeof e){const t=this.getError(e);oe(t,"unknown error","fragment",e),e=t}return ye([e.selector,this._encodeParams(e.inputs,t||[])])}decodeFunctionData(e,t){if("string"==typeof e){const t=this.getFunction(e);oe(t,"unknown function","fragment",e),e=t}return oe(we(t,0,4)===e.selector,`data signature does not match function ${e.name}.`,"data",t),this._decodeParams(e.inputs,we(t,4))}encodeFunctionData(e,t){if("string"==typeof e){const t=this.getFunction(e);oe(t,"unknown function","fragment",e),e=t}return ye([e.selector,this._encodeParams(e.inputs,t||[])])}decodeFunctionResult(e,t){if("string"==typeof e){const t=this.getFunction(e);oe(t,"unknown function","fragment",e),e=t}let n="invalid length for result data";const r=fe(t);if(r.length%32==0)try{return this.#q.decode(e.outputs,r)}catch(e){n="could not decode result data"}re(!1,n,"BAD_DATA",{value:ge(r),info:{method:e.name,signature:e.format()}})}makeError(e,t){const n=le(e,"data"),r=wu.getBuiltinCallException("call",t,n);if(r.message.startsWith("execution reverted (unknown custom error)")){const e=ge(n.slice(0,4)),t=this.getError(e);if(t)try{const e=this.#q.decode(t.inputs,n.slice(4));r.revert={name:t.name,signature:t.format(),args:e},r.reason=r.revert.signature,r.message=`execution reverted: ${r.reason}`}catch(e){r.message="execution reverted (coult not decode custom error)"}}const o=this.parseTransaction(t);return o&&(r.invocation={method:o.name,signature:o.signature,args:o.args}),r}encodeFunctionResult(e,t){if("string"==typeof e){const t=this.getFunction(e);oe(t,"unknown function","fragment",e),e=t}return ge(this.#q.encode(e.outputs,t||[]))}encodeFilterTopics(e,t){if("string"==typeof e){const t=this.getEvent(e);oe(t,"unknown event","eventFragment",e),e=t}re(t.length<=e.inputs.length,`too many arguments for ${e.format()}`,"UNEXPECTED_ARGUMENT",{count:t.length,expectedCount:e.inputs.length});const n=[];e.anonymous||n.push(e.topicHash);const r=(e,t)=>"string"===e.type?Ec(t):"bytes"===e.type?Vt(ge(t)):("bool"===e.type&&"boolean"==typeof t?t=t?"0x01":"0x00":e.type.match(/^u?int/)?t=Na(t):e.type.match(/^bytes/)?t=be(t,32,!1):"address"===e.type&&this.#q.encode(["address"],[t]),ve(ge(t),32));for(t.forEach((t,o)=>{const i=e.inputs[o];i.indexed?null==t?n.push(null):"array"===i.baseType||"tuple"===i.baseType?oe(!1,"filtering with tuples or arrays not supported","contract."+i.name,t):Array.isArray(t)?n.push(t.map(e=>r(i,e))):n.push(r(i,t)):oe(null==t,"cannot filter non-indexed parameters; must be null","contract."+i.name,t)});n.length&&null===n[n.length-1];)n.pop();return n}encodeEventLog(e,t){if("string"==typeof e){const t=this.getEvent(e);oe(t,"unknown event","eventFragment",e),e=t}const n=[],r=[],o=[];return e.anonymous||n.push(e.topicHash),oe(t.length===e.inputs.length,"event arguments/values mismatch","values",t),e.inputs.forEach((e,i)=>{const s=t[i];if(e.indexed)if("string"===e.type)n.push(Ec(s));else if("bytes"===e.type)n.push(Vt(s));else{if("tuple"===e.baseType||"array"===e.baseType)throw new Error("not implemented");n.push(this.#q.encode([e.type],[s]))}else r.push(e),o.push(s)}),{data:this.#q.encode(r,o),topics:n}}decodeEventLog(e,t,n){if("string"==typeof e){const t=this.getEvent(e);oe(t,"unknown event","eventFragment",e),e=t}if(null!=n&&!e.anonymous){const t=e.topicHash;oe(he(n[0],32)&&n[0].toLowerCase()===t,"fragment/topic mismatch","topics[0]",n[0]),n=n.slice(1)}const r=[],o=[],i=[];e.inputs.forEach((e,t)=>{e.indexed?"string"===e.type||"bytes"===e.type||"tuple"===e.baseType||"array"===e.baseType?(r.push(ru.from({type:"bytes32",name:e.name})),i.push(!0)):(r.push(e),i.push(!1)):(o.push(e),i.push(!1))});const s=null!=n?this.#q.decode(r,ye(n)):null,a=this.#q.decode(o,t,!0),c=[],u=[];let l=0,f=0;return e.inputs.forEach((e,t)=>{let n=null;if(e.indexed)if(null==s)n=new ml(null);else if(i[t])n=new ml(s[f++]);else try{n=s[f++]}catch(e){n=e}else try{n=a[l++]}catch(e){n=e}c.push(n),u.push(e.name||null)}),Ha.fromItems(c,u)}parseTransaction(e){const t=le(e.data,"tx.data"),n=Sa(null!=e.value?e.value:0,"tx.value"),r=this.getFunction(ge(t.slice(0,4)));if(!r)return null;const o=this.#q.decode(r.inputs,t.slice(4));return new gl(r,r.selector,o,n)}parseCallResult(e){throw new Error("@TODO")}parseLog(e){const t=this.getEvent(e.topics[0]);return!t||t.anonymous?null:new pl(t,t.topicHash,this.decodeEventLog(t,e.data,e.topics))}parseError(e){const t=ge(e),n=this.getError(we(t,0,4));if(!n)return null;const r=this.#q.decode(n.inputs,we(t,4));return new yl(n,n.selector,r)}static from(e){return e instanceof vl?e:"string"==typeof e?new vl(JSON.parse(e)):"function"==typeof e.formatJson?new vl(e.formatJson()):"function"==typeof e.format?new vl(e.format("json")):new vl(e)}}const El=BigInt(0);function Al(e){return null==e?null:e}function xl(e){return null==e?null:e.toString()}class kl{gasPrice;maxFeePerGas;maxPriorityFeePerGas;constructor(e,t,n){Y(this,{gasPrice:Al(e),maxFeePerGas:Al(t),maxPriorityFeePerGas:Al(n)})}toJSON(){const{gasPrice:e,maxFeePerGas:t,maxPriorityFeePerGas:n}=this;return{_type:"FeeData",gasPrice:xl(e),maxFeePerGas:xl(t),maxPriorityFeePerGas:xl(n)}}}function Sl(e){const t={};e.to&&(t.to=e.to),e.from&&(t.from=e.from),e.data&&(t.data=ge(e.data));const n="chainId,gasLimit,gasPrice,maxFeePerBlobGas,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/);for(const r of n)r in e&&null!=e[r]&&(t[r]=Sa(e[r],`request.${r}`));const r="type,nonce".split(/,/);for(const n of r)n in e&&null!=e[n]&&(t[n]=Ta(e[n],`request.${n}`));return e.accessList&&(t.accessList=_u(e.accessList)),e.authorizationList&&(t.authorizationList=e.authorizationList.slice()),"blockTag"in e&&(t.blockTag=e.blockTag),"enableCcipRead"in e&&(t.enableCcipRead=!!e.enableCcipRead),"customData"in e&&(t.customData=e.customData),"blobVersionedHashes"in e&&e.blobVersionedHashes&&(t.blobVersionedHashes=e.blobVersionedHashes.slice()),"kzg"in e&&(t.kzg=e.kzg),"blobWrapperVersion"in e&&(t.blobWrapperVersion=e.blobWrapperVersion),"blobs"in e&&e.blobs&&(t.blobs=e.blobs.map(e=>de(e)?ge(e):Object.assign({},e))),t}class Il{provider;number;hash;timestamp;parentHash;parentBeaconBlockRoot;nonce;difficulty;gasLimit;gasUsed;stateRoot;receiptsRoot;blobGasUsed;excessBlobGas;miner;prevRandao;extraData;baseFeePerGas;#Z;constructor(e,t){this.#Z=e.transactions.map(e=>"string"!=typeof e?new Tl(e,t):e),Y(this,{provider:t,hash:Al(e.hash),number:e.number,timestamp:e.timestamp,parentHash:e.parentHash,parentBeaconBlockRoot:e.parentBeaconBlockRoot,nonce:e.nonce,difficulty:e.difficulty,gasLimit:e.gasLimit,gasUsed:e.gasUsed,blobGasUsed:e.blobGasUsed,excessBlobGas:e.excessBlobGas,miner:e.miner,prevRandao:Al(e.prevRandao),extraData:e.extraData,baseFeePerGas:Al(e.baseFeePerGas),stateRoot:e.stateRoot,receiptsRoot:e.receiptsRoot})}get transactions(){return this.#Z.map(e=>"string"==typeof e?e:e.hash)}get prefetchedTransactions(){const e=this.#Z.slice();return 0===e.length?[]:(re("object"==typeof e[0],"transactions were not prefetched with block request","UNSUPPORTED_OPERATION",{operation:"transactionResponses()"}),e)}toJSON(){const{baseFeePerGas:e,difficulty:t,extraData:n,gasLimit:r,gasUsed:o,hash:i,miner:s,prevRandao:a,nonce:c,number:u,parentHash:l,parentBeaconBlockRoot:f,stateRoot:h,receiptsRoot:d,timestamp:p,transactions:g}=this;return{_type:"Block",baseFeePerGas:xl(e),difficulty:xl(t),extraData:n,gasLimit:xl(r),gasUsed:xl(o),blobGasUsed:xl(this.blobGasUsed),excessBlobGas:xl(this.excessBlobGas),hash:i,miner:s,prevRandao:a,nonce:c,number:u,parentHash:l,timestamp:p,parentBeaconBlockRoot:f,stateRoot:h,receiptsRoot:d,transactions:g}}[Symbol.iterator](){let e=0;const t=this.transactions;return{next:()=>e<this.length?{value:t[e++],done:!1}:{value:void 0,done:!0}}}get length(){return this.#Z.length}get date(){return null==this.timestamp?null:new Date(1e3*this.timestamp)}async getTransaction(e){let t;if("number"==typeof e)t=this.#Z[e];else{const n=e.toLowerCase();for(const e of this.#Z){if("string"==typeof e){if(e!==n)continue;t=e;break}if(e.hash===n){t=e;break}}}if(null==t)throw new Error("no such tx");return"string"==typeof t?await this.provider.getTransaction(t):t}getPrefetchedTransaction(e){const t=this.prefetchedTransactions;if("number"==typeof e)return t[e];e=e.toLowerCase();for(const n of t)if(n.hash===e)return n;oe(!1,"no matching transaction","indexOrHash",e)}isMined(){return!!this.hash}isLondon(){return!!this.baseFeePerGas}orphanedEvent(){if(!this.isMined())throw new Error("");return{orphan:"drop-block",hash:this.hash,number:this.number}}}class Cl{provider;transactionHash;blockHash;blockNumber;removed;address;data;topics;index;transactionIndex;constructor(e,t){this.provider=t;const n=Object.freeze(e.topics.slice());Y(this,{transactionHash:e.transactionHash,blockHash:e.blockHash,blockNumber:e.blockNumber,removed:e.removed,address:e.address,data:e.data,topics:n,index:e.index,transactionIndex:e.transactionIndex})}toJSON(){const{address:e,blockHash:t,blockNumber:n,data:r,index:o,removed:i,topics:s,transactionHash:a,transactionIndex:c}=this;return{_type:"log",address:e,blockHash:t,blockNumber:n,data:r,index:o,removed:i,topics:s,transactionHash:a,transactionIndex:c}}async getBlock(){const e=await this.provider.getBlock(this.blockHash);return re(!!e,"failed to find transaction","UNKNOWN_ERROR",{}),e}async getTransaction(){const e=await this.provider.getTransaction(this.transactionHash);return re(!!e,"failed to find transaction","UNKNOWN_ERROR",{}),e}async getTransactionReceipt(){const e=await this.provider.getTransactionReceipt(this.transactionHash);return re(!!e,"failed to find transaction receipt","UNKNOWN_ERROR",{}),e}removedEvent(){return{orphan:"drop-log",log:{transactionHash:(e=this).transactionHash,blockHash:e.blockHash,blockNumber:e.blockNumber,address:e.address,data:e.data,topics:Object.freeze(e.topics.slice()),index:e.index}};var e}}class Ol{provider;to;from;contractAddress;hash;index;blockHash;blockNumber;logsBloom;gasUsed;blobGasUsed;cumulativeGasUsed;gasPrice;blobGasPrice;type;status;root;#Y;constructor(e,t){this.#Y=Object.freeze(e.logs.map(e=>new Cl(e,t)));let n=El;null!=e.effectiveGasPrice?n=e.effectiveGasPrice:null!=e.gasPrice&&(n=e.gasPrice),Y(this,{provider:t,to:e.to,from:e.from,contractAddress:e.contractAddress,hash:e.hash,index:e.index,blockHash:e.blockHash,blockNumber:e.blockNumber,logsBloom:e.logsBloom,gasUsed:e.gasUsed,cumulativeGasUsed:e.cumulativeGasUsed,blobGasUsed:e.blobGasUsed,gasPrice:n,blobGasPrice:e.blobGasPrice,type:e.type,status:e.status,root:e.root})}get logs(){return this.#Y}toJSON(){const{to:e,from:t,contractAddress:n,hash:r,index:o,blockHash:i,blockNumber:s,logsBloom:a,logs:c,status:u,root:l}=this;return{_type:"TransactionReceipt",blockHash:i,blockNumber:s,contractAddress:n,cumulativeGasUsed:xl(this.cumulativeGasUsed),from:t,gasPrice:xl(this.gasPrice),blobGasUsed:xl(this.blobGasUsed),blobGasPrice:xl(this.blobGasPrice),gasUsed:xl(this.gasUsed),hash:r,index:o,logs:c,logsBloom:a,root:l,status:u,to:e}}get length(){return this.logs.length}[Symbol.iterator](){let e=0;return{next:()=>e<this.length?{value:this.logs[e++],done:!1}:{value:void 0,done:!0}}}get fee(){return this.gasUsed*this.gasPrice}async getBlock(){const e=await this.provider.getBlock(this.blockHash);if(null==e)throw new Error("TODO");return e}async getTransaction(){const e=await this.provider.getTransaction(this.hash);if(null==e)throw new Error("TODO");return e}async getResult(){return await this.provider.getTransactionResult(this.hash)}async confirmations(){return await this.provider.getBlockNumber()-this.blockNumber+1}removedEvent(){return Pl(this)}reorderedEvent(e){return re(!e||e.isMined(),"unmined 'other' transction cannot be orphaned","UNSUPPORTED_OPERATION",{operation:"reorderedEvent(other)"}),Nl(this,e)}}class Tl{provider;blockNumber;blockHash;index;hash;type;to;from;nonce;gasLimit;gasPrice;maxPriorityFeePerGas;maxFeePerGas;maxFeePerBlobGas;data;value;chainId;signature;accessList;blobVersionedHashes;authorizationList;#X;constructor(e,t){this.provider=t,this.blockNumber=null!=e.blockNumber?e.blockNumber:null,this.blockHash=null!=e.blockHash?e.blockHash:null,this.hash=e.hash,this.index=e.index,this.type=e.type,this.from=e.from,this.to=e.to||null,this.gasLimit=e.gasLimit,this.nonce=e.nonce,this.data=e.data,this.value=e.value,this.gasPrice=e.gasPrice,this.maxPriorityFeePerGas=null!=e.maxPriorityFeePerGas?e.maxPriorityFeePerGas:null,this.maxFeePerGas=null!=e.maxFeePerGas?e.maxFeePerGas:null,this.maxFeePerBlobGas=null!=e.maxFeePerBlobGas?e.maxFeePerBlobGas:null,this.chainId=e.chainId,this.signature=e.signature,this.accessList=null!=e.accessList?e.accessList:null,this.blobVersionedHashes=null!=e.blobVersionedHashes?e.blobVersionedHashes:null,this.authorizationList=null!=e.authorizationList?e.authorizationList:null,this.#X=-1}toJSON(){const{blockNumber:e,blockHash:t,index:n,hash:r,type:o,to:i,from:s,nonce:a,data:c,signature:u,accessList:l,blobVersionedHashes:f}=this;return{_type:"TransactionResponse",accessList:l,blockNumber:e,blockHash:t,blobVersionedHashes:f,chainId:xl(this.chainId),data:c,from:s,gasLimit:xl(this.gasLimit),gasPrice:xl(this.gasPrice),hash:r,maxFeePerGas:xl(this.maxFeePerGas),maxPriorityFeePerGas:xl(this.maxPriorityFeePerGas),maxFeePerBlobGas:xl(this.maxFeePerBlobGas),nonce:a,signature:u,to:i,index:n,type:o,value:xl(this.value)}}async getBlock(){let e=this.blockNumber;if(null==e){const t=await this.getTransaction();t&&(e=t.blockNumber)}if(null==e)return null;const t=this.provider.getBlock(e);if(null==t)throw new Error("TODO");return t}async getTransaction(){return this.provider.getTransaction(this.hash)}async confirmations(){if(null==this.blockNumber){const{tx:e,blockNumber:t}=await Z({tx:this.getTransaction(),blockNumber:this.provider.getBlockNumber()});return null==e||null==e.blockNumber?0:t-e.blockNumber+1}return await this.provider.getBlockNumber()-this.blockNumber+1}async wait(e,t){const n=null==e?1:e,r=null==t?0:t;let o=this.#X,i=-1,s=-1===o;const a=async()=>{if(s)return null;const{blockNumber:e,nonce:t}=await Z({blockNumber:this.provider.getBlockNumber(),nonce:this.provider.getTransactionCount(this.from)});if(t<this.nonce)return void(o=e);if(s)return null;const r=await this.getTransaction();if(!r||null==r.blockNumber)for(-1===i&&(i=o-3,i<this.#X&&(i=this.#X));i<=e;){if(s)return null;const t=await this.provider.getBlock(i,!0);if(null==t)return;for(const e of t)if(e===this.hash)return;for(let r=0;r<t.length;r++){const i=await t.getTransaction(r);if(i.from===this.from&&i.nonce===this.nonce){if(s)return null;const t=await this.provider.getTransactionReceipt(i.hash);if(null==t)return;if(e-t.blockNumber+1<n)return;let r="replaced";i.data===this.data&&i.to===this.to&&i.value===this.value?r="repriced":"0x"===i.data&&i.from===i.to&&i.value===El&&(r="cancelled"),re(!1,"transaction was replaced","TRANSACTION_REPLACED",{cancelled:"replaced"===r||"cancelled"===r,reason:r,replacement:i.replaceableTransaction(o),hash:i.hash,receipt:t})}}i++}},c=e=>{if(null==e||0!==e.status)return e;re(!1,"transaction execution reverted","CALL_EXCEPTION",{action:"sendTransaction",data:null,reason:null,invocation:null,revert:null,transaction:{to:e.to,from:e.from,data:""},receipt:e})},u=await this.provider.getTransactionReceipt(this.hash);if(0===n)return c(u);if(u){if(1===n||await u.confirmations()>=n)return c(u)}else if(await a(),0===n)return null;const l=new Promise((e,t)=>{const i=[],u=()=>{i.forEach(e=>e())};if(i.push(()=>{s=!0}),r>0){const e=setTimeout(()=>{u(),t(ne("wait for transaction timeout","TIMEOUT"))},r);i.push(()=>{clearTimeout(e)})}const l=async r=>{if(await r.confirmations()>=n){u();try{e(c(r))}catch(e){t(e)}}};if(i.push(()=>{this.provider.off(this.hash,l)}),this.provider.on(this.hash,l),o>=0){const e=async()=>{try{await a()}catch(e){if(ee(e,"TRANSACTION_REPLACED"))return u(),void t(e)}s||this.provider.once("block",e)};i.push(()=>{this.provider.off("block",e)}),this.provider.once("block",e)}});return await l}isMined(){return null!=this.blockHash}isLegacy(){return 0===this.type}isBerlin(){return 1===this.type}isLondon(){return 2===this.type}isCancun(){return 3===this.type}removedEvent(){return re(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),Pl(this)}reorderedEvent(e){return re(this.isMined(),"unmined transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),re(!e||e.isMined(),"unmined 'other' transaction canot be orphaned","UNSUPPORTED_OPERATION",{operation:"removeEvent()"}),Nl(this,e)}replaceableTransaction(e){oe(Number.isInteger(e)&&e>=0,"invalid startBlock","startBlock",e);const t=new Tl(this,this.provider);return t.#X=e,t}}function Nl(e,t){return{orphan:"reorder-transaction",tx:e,other:t}}function Pl(e){return{orphan:"drop-transaction",tx:e}}class Bl{filter;emitter;#ee;constructor(e,t,n){this.#ee=t,Y(this,{emitter:e,filter:n})}async removeListener(){null!=this.#ee&&await this.emitter.off(this.filter,this.#ee)}}class Rl extends Cl{interface;fragment;args;constructor(e,t,n){super(e,e.provider),Y(this,{args:t.decodeEventLog(n,e.data,e.topics),fragment:n,interface:t})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}class Ul extends Cl{error;constructor(e,t){super(e,e.provider),Y(this,{error:t})}}class Dl extends Ol{#te;constructor(e,t,n){super(n,t),this.#te=e}get logs(){return super.logs.map(e=>{const t=e.topics.length?this.#te.getEvent(e.topics[0]):null;if(t)try{return new Rl(e,this.#te,t)}catch(t){return new Ul(e,t)}return e})}}class Ll extends Tl{#te;constructor(e,t,n){super(n,t),this.#te=e}async wait(e,t){const n=await super.wait(e,t);return null==n?null:new Dl(this.#te,this.provider,n)}}class Fl extends Bl{log;constructor(e,t,n,r){super(e,t,n),Y(this,{log:r})}async getBlock(){return await this.log.getBlock()}async getTransaction(){return await this.log.getTransaction()}async getTransactionReceipt(){return await this.log.getTransactionReceipt()}}class _l extends Fl{constructor(e,t,n,r,o){super(e,t,n,new Rl(o,e.interface,r)),Y(this,{args:e.interface.decodeEventLog(r,this.log.data,this.log.topics),fragment:r})}get eventName(){return this.fragment.name}get eventSignature(){return this.fragment.format()}}const Ml=BigInt(0);function Gl(e){return e&&"function"==typeof e.call}function jl(e){return e&&"function"==typeof e.estimateGas}function Hl(e){return e&&"function"==typeof e.resolveName}function zl(e){return e&&"function"==typeof e.sendTransaction}function Vl(e){if(null!=e){if(Hl(e))return e;if(e.provider)return e.provider}}class Kl{#ne;fragment;constructor(e,t,n){if(Y(this,{fragment:t}),t.inputs.length<n.length)throw new Error("too many arguments");const r=Wl(e.runner,"resolveName"),o=Hl(r)?r:null;this.#ne=async function(){const r=await Promise.all(t.inputs.map((e,t)=>null==n[t]?null:e.walkAsync(n[t],(e,t)=>"address"===e?Array.isArray(t)?Promise.all(t.map(e=>Eu(e,o))):Eu(t,o):t)));return e.interface.encodeFilterTopics(t,r)}()}getTopicFilter(){return this.#ne}}function Wl(e,t){return null==e?null:"function"==typeof e[t]?e:e.provider&&"function"==typeof e.provider[t]?e.provider:null}function $l(e){return null==e?null:e.provider||null}async function ql(e,t){const n=rc.dereference(e,"overrides");oe("object"==typeof n,"invalid overrides parameter","overrides",e);const r=Sl(n);return oe(null==r.to||(t||[]).indexOf("to")>=0,"cannot override to","overrides.to",r.to),oe(null==r.data||(t||[]).indexOf("data")>=0,"cannot override data","overrides.data",r.data),r.from&&(r.from=r.from),r}function Jl(e){const t=async function(t){const n=await ql(t,["data"]);n.to=await e.getAddress(),n.from&&(n.from=await Eu(n.from,Vl(e.runner)));const r=e.interface,o=Sa(n.value||Ml,"overrides.value")===Ml,i="0x"===(n.data||"0x");return!r.fallback||r.fallback.payable||!r.receive||i||o||oe(!1,"cannot send data to receive or send value to non-payable fallback","overrides",t),oe(r.fallback||i,"cannot send data to receive-only contract","overrides.data",n.data),oe(r.receive||r.fallback&&r.fallback.payable||o,"cannot send value to non-payable fallback","overrides.value",n.value),oe(r.fallback||i,"cannot send data to receive-only contract","overrides.data",n.data),n},n=async function(n){const r=e.runner;re(zl(r),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const o=await r.sendTransaction(await t(n)),i=$l(e.runner);return new Ll(e.interface,i,o)},r=async e=>await n(e);return Y(r,{_contract:e,estimateGas:async function(n){const r=Wl(e.runner,"estimateGas");return re(jl(r),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await r.estimateGas(await t(n))},populateTransaction:t,send:n,staticCall:async function(n){const r=Wl(e.runner,"call");re(Gl(r),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const o=await t(n);try{return await r.call(o)}catch(t){if(te(t)&&t.data)throw e.interface.makeError(t.data,o);throw t}}}),r}const Ql=Symbol.for("_ethersInternal_contract"),Zl=new WeakMap;function Yl(e){return Zl.get(e[Ql])}async function Xl(e,t){let n,r=null;if(Array.isArray(t)){const r=function(t){if(he(t,32))return t;const n=e.interface.getEvent(t);return oe(n,"unknown fragment","name",t),n.topicHash};n=t.map(e=>null==e?null:Array.isArray(e)?e.map(r):r(e))}else"*"===t?n=[null]:"string"==typeof t?he(t,32)?n=[t]:(r=e.interface.getEvent(t),oe(r,"unknown fragment","event",t),n=[r.topicHash]):(o=t)&&"object"==typeof o&&"getTopicFilter"in o&&"function"==typeof o.getTopicFilter&&o.fragment?n=await t.getTopicFilter():"fragment"in t?(r=t.fragment,n=[r.topicHash]):oe(!1,"unknown event name","event",t);var o;return n=n.map(e=>{if(null==e)return null;if(Array.isArray(e)){const t=Array.from(new Set(e.map(e=>e.toLowerCase())).values());return 1===t.length?t[0]:(t.sort(),t)}return e.toLowerCase()}),{fragment:r,tag:n.map(e=>null==e?"null":Array.isArray(e)?e.join("|"):e).join("&"),topics:n}}async function ef(e,t){const{subs:n}=Yl(e);return n.get((await Xl(e,t)).tag)||null}async function tf(e,t,n){const r=$l(e.runner);re(r,"contract runner does not support subscribing","UNSUPPORTED_OPERATION",{operation:t});const{fragment:o,tag:i,topics:s}=await Xl(e,n),{addr:a,subs:c}=Yl(e);let u=c.get(i);if(!u){const t={address:a||e,topics:s},l=t=>{let r=o;if(null==r)try{r=e.interface.getEvent(t.topics[0])}catch(e){}if(r){const i=r,s=o?e.interface.decodeEventLog(o,t.data,t.topics):[];rf(e,n,s,r=>new _l(e,r,n,i,t))}else rf(e,n,[],r=>new Fl(e,r,n,t))};let f=[];u={tag:i,listeners:[],start:()=>{f.length||f.push(r.on(t,l))},stop:async()=>{if(0==f.length)return;let e=f;f=[],await Promise.all(e),r.off(t,l)}},c.set(i,u)}return u}let nf=Promise.resolve();async function rf(e,t,n,r){try{await nf}catch(e){}const o=async function(e,t,n,r){await nf;const o=await ef(e,t);if(!o)return!1;const i=o.listeners.length;return o.listeners=o.listeners.filter(({listener:t,once:o})=>{const i=Array.from(n);r&&i.push(r(o?null:t));try{t.call(e,...i)}catch(e){}return!o}),0===o.listeners.length&&(o.stop(),Yl(e).subs.delete(o.tag)),i>0}(e,t,n,r);return nf=o,await o}const of=["then"];class sf{target;interface;runner;filters;[Ql];fallback;constructor(e,t,n,r){oe("string"==typeof e||bu(e),"invalid value for Contract target","target",e),null==n&&(n=null);const o=vl.from(t);let i;Y(this,{target:e,runner:n,interface:o}),Object.defineProperty(this,Ql,{value:{}});let s=null,a=null;if(r){const e=$l(n);a=new Ll(this.interface,e,r)}let c=new Map;if("string"==typeof e)if(he(e))s=e,i=Promise.resolve(e);else{const t=Wl(n,"resolveName");if(!Hl(t))throw ne("contract runner does not support name resolution","UNSUPPORTED_OPERATION",{operation:"resolveName"});i=t.resolveName(e).then(t=>{if(null==t)throw ne("an ENS name used for a contract target must be correctly configured","UNCONFIGURED_NAME",{value:e});return Yl(this).addr=t,t})}else i=e.getAddress().then(e=>{if(null==e)throw new Error("TODO");return Yl(this).addr=e,e});var u;u={addrPromise:i,addr:s,deployTx:a,subs:c},Zl.set(this[Ql],u);const l=new Proxy({},{get:(e,t,n)=>{if("symbol"==typeof t||of.indexOf(t)>=0)return Reflect.get(e,t,n);try{return this.getEvent(t)}catch(e){if(!ee(e,"INVALID_ARGUMENT")||"key"!==e.argument)throw e}},has:(e,t)=>of.indexOf(t)>=0?Reflect.has(e,t):Reflect.has(e,t)||this.interface.hasEvent(String(t))});return Y(this,{filters:l}),Y(this,{fallback:o.receive||o.fallback?Jl(this):null}),new Proxy(this,{get:(e,t,n)=>{if("symbol"==typeof t||t in e||of.indexOf(t)>=0)return Reflect.get(e,t,n);try{return e.getFunction(t)}catch(e){if(!ee(e,"INVALID_ARGUMENT")||"key"!==e.argument)throw e}},has:(e,t)=>"symbol"==typeof t||t in e||of.indexOf(t)>=0?Reflect.has(e,t):e.interface.hasFunction(t)})}connect(e){return new sf(this.target,this.interface,e)}attach(e){return new sf(e,this.interface,this.runner)}async getAddress(){return await Yl(this).addrPromise}async getDeployedCode(){const e=$l(this.runner);re(e,"runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"getDeployedCode"});const t=await e.getCode(await this.getAddress());return"0x"===t?null:t}async waitForDeployment(){const e=this.deploymentTransaction();if(e)return await e.wait(),this;if(null!=await this.getDeployedCode())return this;const t=$l(this.runner);return re(null!=t,"contract runner does not support .provider","UNSUPPORTED_OPERATION",{operation:"waitForDeployment"}),new Promise((e,n)=>{const r=async()=>{try{if(null!=await this.getDeployedCode())return e(this);t.once("block",r)}catch(e){n(e)}};r()})}deploymentTransaction(){return Yl(this).deployTx}getFunction(e){return"string"!=typeof e&&(e=e.format()),function(e,t){const n=function(...n){const r=e.interface.getFunction(t,n);return re(r,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t,args:n}}),r},r=async function(...t){const r=n(...t);let o={};if(r.inputs.length+1===t.length&&(o=await ql(t.pop()),o.from&&(o.from=await Eu(o.from,Vl(e.runner)))),r.inputs.length!==t.length)throw new Error("internal error: fragment inputs doesn't match arguments; should not happen");const i=await async function(e,t,n){const r=Wl(e,"resolveName"),o=Hl(r)?r:null;return await Promise.all(t.map((e,t)=>e.walkAsync(n[t],(e,t)=>(t=rc.dereference(t,e),"address"===e?Eu(t,o):t))))}(e.runner,r.inputs,t);return Object.assign({},o,await Z({to:e.getAddress(),data:e.interface.encodeFunctionData(r,i)}))},o=async function(...e){const t=await s(...e);return 1===t.length?t[0]:t},i=async function(...t){const n=e.runner;re(zl(n),"contract runner does not support sending transactions","UNSUPPORTED_OPERATION",{operation:"sendTransaction"});const o=await n.sendTransaction(await r(...t)),i=$l(e.runner);return new Ll(e.interface,i,o)},s=async function(...t){const o=Wl(e.runner,"call");re(Gl(o),"contract runner does not support calling","UNSUPPORTED_OPERATION",{operation:"call"});const i=await r(...t);let s="0x";try{s=await o.call(i)}catch(t){if(te(t)&&t.data)throw e.interface.makeError(t.data,i);throw t}const a=n(...t);return e.interface.decodeFunctionResult(a,s)},a=async(...e)=>n(...e).constant?await o(...e):await i(...e);return Y(a,{name:e.interface.getFunctionName(t),_contract:e,_key:t,getFragment:n,estimateGas:async function(...t){const n=Wl(e.runner,"estimateGas");return re(jl(n),"contract runner does not support gas estimation","UNSUPPORTED_OPERATION",{operation:"estimateGas"}),await n.estimateGas(await r(...t))},populateTransaction:r,send:i,staticCall:o,staticCallResult:s}),Object.defineProperty(a,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=e.interface.getFunction(t);return re(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t}}),n}}),a}(this,e)}getEvent(e){return"string"!=typeof e&&(e=e.format()),function(e,t){const n=function(...n){const r=e.interface.getEvent(t,n);return re(r,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t,args:n}}),r},r=function(...t){return new Kl(e,n(...t),t)};return Y(r,{name:e.interface.getEventName(t),_contract:e,_key:t,getFragment:n}),Object.defineProperty(r,"fragment",{configurable:!1,enumerable:!0,get:()=>{const n=e.interface.getEvent(t);return re(n,"no matching fragment","UNSUPPORTED_OPERATION",{operation:"fragment",info:{key:t}}),n}}),r}(this,e)}async queryTransaction(e){throw new Error("@TODO")}async queryFilter(e,t,n){null==t&&(t=0),null==n&&(n="latest");const{addr:r,addrPromise:o}=Yl(this),i=r||await o,{fragment:s,topics:a}=await Xl(this,e),c={address:i,topics:a,fromBlock:t,toBlock:n},u=$l(this.runner);return re(u,"contract runner does not have a provider","UNSUPPORTED_OPERATION",{operation:"queryFilter"}),(await u.getLogs(c)).map(e=>{let t=s;if(null==t)try{t=this.interface.getEvent(e.topics[0])}catch(e){}if(t)try{return new Rl(e,this.interface,t)}catch(t){return new Ul(e,t)}return new Cl(e,u)})}async on(e,t){const n=await tf(this,"on",e);return n.listeners.push({listener:t,once:!1}),n.start(),this}async once(e,t){const n=await tf(this,"once",e);return n.listeners.push({listener:t,once:!0}),n.start(),this}async emit(e,...t){return await rf(this,e,t,null)}async listenerCount(e){if(e){const t=await ef(this,e);return t?t.listeners.length:0}const{subs:t}=Yl(this);let n=0;for(const{listeners:e}of t.values())n+=e.length;return n}async listeners(e){if(e){const t=await ef(this,e);return t?t.listeners.map(({listener:e})=>e):[]}const{subs:t}=Yl(this);let n=[];for(const{listeners:e}of t.values())n=n.concat(e.map(({listener:e})=>e));return n}async off(e,t){const n=await ef(this,e);if(!n)return this;if(t){const e=n.listeners.map(({listener:e})=>e).indexOf(t);e>=0&&n.listeners.splice(e,1)}return null!=t&&0!==n.listeners.length||(n.stop(),Yl(this).subs.delete(n.tag)),this}async removeAllListeners(e){if(e){const t=await ef(this,e);if(!t)return this;t.stop(),Yl(this).subs.delete(t.tag)}else{const{subs:e}=Yl(this);for(const{tag:t,stop:n}of e.values())n(),e.delete(t)}return this}async addListener(e,t){return await this.on(e,t)}async removeListener(e,t){return await this.off(e,t)}static buildClass(e){return class extends sf{constructor(t,n=null){super(t,e,n)}}}static from(e,t,n){return null==n&&(n=null),new this(e,t,n)}}class af extends(function(){return sf}()){}const cf=new Map([[8217,"apostrophe"],[8260,"fraction slash"],[12539,"middle dot"]]);function uf(e){return function(e){let t=0;return()=>e[t++]}(function(e){let t=0;function n(){return e[t++]<<8|e[t++]}let r=n(),o=1,i=[0,1];for(let e=1;e<r;e++)i.push(o+=n());let s=n(),a=t;t+=s;let c=0,u=0;function l(){return 0==c&&(u=u<<8|e[t++],c=8),u>>--c&1}const f=2**31,h=f>>>1,d=h>>1,p=f-1;let g=0;for(let e=0;e<31;e++)g=g<<1|l();let y=[],m=0,w=f;for(;;){let e=Math.floor(((g-m+1)*o-1)/w),t=0,n=r;for(;n-t>1;){let r=t+n>>>1;e<i[r]?n=r:t=r}if(0==t)break;y.push(t);let s=m+Math.floor(w*i[t]/o),a=m+Math.floor(w*i[t+1]/o)-1;for(;0==((s^a)&h);)g=g<<1&p|l(),s=s<<1&p,a=a<<1&p|1;for(;s&~a&d;)g=g&h|g<<1&p>>>1|l(),s=s<<1^h,a=(a^h)<<1|h|1;m=s,w=1+a-s}let b=r-4;return y.map(t=>{switch(t-b){case 3:return b+65792+(e[a++]<<16|e[a++]<<8|e[a++]);case 2:return b+256+(e[a++]<<8|e[a++]);case 1:return b+e[a++];default:return t-1}})}(function(e){let t=[];[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"].forEach((e,n)=>t[e.charCodeAt(0)]=n);let n=e.length,r=new Uint8Array(6*n>>3);for(let o=0,i=0,s=0,a=0;o<n;o++)a=a<<6|t[e.charCodeAt(o)],s+=6,s>=8&&(r[i++]=a>>(s-=8));return r}(e)))}function lf(e){return 1&e?~e>>1:e>>1}function ff(e,t){let n=Array(e);for(let r=0,o=0;r<e;r++)n[r]=o+=lf(t());return n}function hf(e,t=0){let n=[];for(;;){let r=e(),o=e();if(!o)break;t+=r;for(let e=0;e<o;e++)n.push(t+e);t+=o+1}return n}function df(e){return gf(()=>{let t=hf(e);if(t.length)return t})}function pf(e){let t=[];for(;;){let n=e();if(0==n)break;t.push(mf(n,e))}for(;;){let n=e()-1;if(n<0)break;t.push(wf(n,e))}return t.flat()}function gf(e){let t=[];for(;;){let n=e(t.length);if(!n)break;t.push(n)}return t}function yf(e,t,n){let r=Array(e).fill().map(()=>[]);for(let o=0;o<t;o++)ff(e,n).forEach((e,t)=>r[t].push(e));return r}function mf(e,t){let n=1+t(),r=t(),o=gf(t);return yf(o.length,1+e,t).flatMap((e,t)=>{let[i,...s]=e;return Array(o[t]).fill().map((e,t)=>{let o=t*r;return[i+t*n,s.map(e=>e+o)]})})}function wf(e,t){return yf(1+t(),1+e,t).map(e=>[e[0],e.slice(1)])}function bf(e){return`{${function(e){return e.toString(16).toUpperCase().padStart(2,"0")}(e)}}`}function vf(e){let t=e.length;if(t<4096)return String.fromCodePoint(...e);let n=[];for(let r=0;r<t;)n.push(String.fromCodePoint(...e.slice(r,r+=4096)));return n.join("")}function Ef(e,t){let n=e.length,r=n-t.length;for(let o=0;0==r&&o<n;o++)r=e[o]-t[o];return r}const Af=44032,xf=4352,kf=4449,Sf=4519;function If(e){return e>>24&255}function Cf(e){return 16777215&e}let Of,Tf,Nf,Pf;function Bf(e){return e>=Af&&e<55204}function Rf(e,t){if(e>=xf&&e<4371&&t>=kf&&t<4470)return Af+588*(e-xf)+28*(t-kf);if(Bf(e)&&t>Sf&&t<4547&&(e-Af)%28==0)return e+(t-Sf);{let n=Pf.get(e);return n&&(n=n.get(t),n)?n:-1}}function Uf(e){Of||function(){let e=uf("AEUDTAHBCFQATQDRADAAcgAgADQAFAAsABQAHwAOACQADQARAAoAFwAHABIACAAPAAUACwAFAAwABAAQAAMABwAEAAoABQAIAAIACgABAAQAFAALAAIACwABAAIAAQAHAAMAAwAEAAsADAAMAAwACgANAA0AAwAKAAkABAAdAAYAZwDSAdsDJgC0CkMB8xhZAqfoC190UGcThgBurwf7PT09Pb09AjgJum8OjDllxHYUKXAPxzq6tABAxgK8ysUvWAgMPT09PT09PSs6LT2HcgWXWwFLoSMEEEl5RFVMKvO0XQ8ExDdJMnIgsj26PTQyy8FfEQ8AY8IPAGcEbwRwBHEEcgRzBHQEdQR2BHcEeAR6BHsEfAR+BIAEgfndBQoBYgULAWIFDAFiBNcE2ATZBRAFEQUvBdALFAsVDPcNBw13DYcOMA4xDjMB4BllHI0B2grbAMDpHLkQ7QHVAPRNQQFnGRUEg0yEB2uaJF8AJpIBpob5AERSMAKNoAXqaQLUBMCzEiACnwRZEkkVsS7tANAsBG0RuAQLEPABv9HICTUBXigPZwRBApMDOwAamhtaABqEAY8KvKx3LQ4ArAB8UhwEBAVSagD8AEFZADkBIadVj2UMUgx5Il4ANQC9AxIB1BlbEPMAs30CGxlXAhwZKQIECBc6EbsCoxngzv7UzRQA8M0BawL6ZwkN7wABAD33OQRcsgLJCjMCjqUChtw/km+NAsXPAoP2BT84PwURAK0RAvptb6cApQS/OMMey5HJS84UdxpxTPkCogVFITaTOwERAK5pAvkNBOVyA7q3BKlOJSALAgUIBRcEdASpBXqzABXFSWZOawLCOqw//AolCZdvv3dSBkEQGyelEPcMMwG1ATsN7UvYBPEGOwTJH30ZGQ/NlZwIpS3dDO0m4y6hgFoj9SqDBe1L9DzdC01RaA9ZC2UJ4zpjgU4DIQENIosK3Q05CG0Q8wrJaw3lEUUHOQPVSZoApQcBCxEdNRW1JhBirAsJOXcG+xr2C48mrxMpevwF0xohBk0BKRr/AM8u54WwWjFcHE9fBgMLJSPHFKhQIA0lQLd4SBobBxUlqQKRQ3BKh1E2HpMh9jw9DWYuE1F8B/U8BRlPC4E8nkarRQ4R0j6NPUgiSUwsBDV/LC8niwnPD4UMuXxyAVkJIQmxDHETMREXN8UIOQcZLZckJxUIIUaVYJoE958D8xPRAwsFPwlBBxMDtRwtEy4VKQUNgSTXAvM21S6zAo9WgAEXBcsPJR/fEFBH4A7pCJsCZQODJesALRUhABcimwhDYwBfj9hTBS7LCMdqbCN0A2cU52ERcweRDlcHpxwzFb8c4XDIXguGCCijrwlbAXUJmQFfBOMICTVbjKAgQWdTi1gYmyBhQT9d/AIxDGUVn0S9h3gCiw9rEhsBNQFzBzkNAQJ3Ee0RaxCVCOuGBDW1M/g6JQRPIYMgEQonA09szgsnJvkM+GkBoxJiAww0PXfuZ6tgtiQX/QcZMsVBYCHxC5JPzQycGsEYQlQuGeQHvwPzGvMn6kFXBf8DowMTOk0z7gS9C2kIiwk/AEkOoxcH1xhqCnGM0AExiwG3mQNXkYMCb48GNwcLAGcLhwV55QAdAqcIowAFAM8DVwA5Aq0HnQAZAIVBAT0DJy8BIeUCjwOTCDHLAZUvAfMpBBvDDBUA9zduSgLDsQKAamaiBd1YAo4CSTUBTSUEBU5HUQOvceEA2wBLBhPfRwEVq0rLGuNDAd9vKwDHAPsABTUHBUEBzQHzbQC3AV8LMQmis7UBTekpAIMAFWsB1wKJAN0ANQB/8QFTAE0FWfkF0wJPSQERMRgrV2EBuwMfATMBDQB5BsuNpckHHwRtB9MCEBsV4QLvLge1AQMi3xPNQsUCvd5VoWACZIECYkJbTa9bNyACofcCaJgCZgkCn4Q4GwsCZjsCZiYEbgR/A38TA36SOQY5dxc5gjojIwJsHQIyNjgKAm3HAm2u74ozZ0UrAWcA3gDhAEoFB5gMjQD+C8IADbUCdy8CdqI/AnlLQwJ4uh1c20WuRtcCfD8CesgCfQkCfPAFWQUgSABIfWMkAoFtAoAAAoAFAn+uSVhKWxUXSswC0QEC0MxLJwOITwOH5kTFkTIC8qFdAwMDrkvOTC0lA89NTE2vAos/AorYwRsHHUNnBbcCjjcCjlxAl4ECjtkCjlx4UbRTNQpS1FSFApP7ApMMAOkAHFUeVa9V0AYsGymVhjLheGZFOzkCl58C77JYIagAWSUClo8ClnycAKlZrFoJgU0AOwKWtQKWTlxEXNECmcsCmWRcyl0HGQKcmznCOp0CnBYCn5sCnriKAB0PMSoPAp3xAp6SALU9YTRh7wKe0wKgbgGpAp6fHwKeTqVjyGQnJSsCJ68CJn4CoPsCoEwCot0CocQCpi8Cpc4Cp/8AfQKn8mh8aLEAA0lqHGrRAqzjAqyuAq1nAq0CAlcdAlXcArHh1wMfTmyXArK9DQKy6Bds4G1jbUhfAyXNArZcOz9ukAMpRQK4XgK5RxUCuSp3cDZw4QK9GQK72nCWAzIRAr6IcgIDM3ECvhpzInNPAsPLAsMEc4J0SzVFdOADPKcDPJoDPb8CxXwCxkcCxhCJAshpUQLIRALJTwLJLgJknQLd0nh5YXiueSVL0AMYo2cCAmH0GfOVJHsLXpJeuxECz2sCz2wvS1PS8xOfAMatAs9zASnqA04SfksFAtwnAtuKAtJPA1JcA1NfAQEDVYyAiT8AyxbtYEWCHILTgs6DjQLaxwLZ3oQQhEmnPAOGpQAvA2QOhnFZ+QBVAt9lAt64c3cC4i/tFAHzMCcB9JsB8tKHAuvzAulweQLq+QLq5AD5RwG5Au6JAuuclqqXAwLuPwOF4Jh5cOBxoQLzAwBpA44WmZMC9xMDkW4DkocC95gC+dkC+GaaHJqruzebHgOdgwL++gEbADmfHJ+zAwWNA6ZqA6bZANHFAwZqoYiiBQkDDEkCwAA/AwDhQRdTARHzA2sHl2cFAJMtK7evvdsBiZkUfxEEOQH7KQUhDp0JnwCS/SlXxQL3AZ0AtwW5AG8LbUEuFCaNLgFDAYD8AbUmAHUDDgRtACwCFgyhAAAKAj0CagPdA34EkQEgRQUhfAoABQBEABMANhICdwEABdUDa+8KxQIA9wqfJ7+xt+UBkSFBQgHpFH8RNMCJAAQAGwBaAkUChIsABjpTOpSNbQC4Oo860ACNOME63AClAOgAywE6gTo7Ofw5+Tt2iTpbO56JOm85GAFWATMBbAUvNV01njWtNWY1dTW2NcU1gjWRNdI14TWeNa017jX9NbI1wTYCNhE1xjXVNhY2JzXeNe02LjY9Ni41LSE2OjY9Njw2yTcIBJA8VzY4Nt03IDcPNsogN4k3MAoEsDxnNiQ3GTdsOo03IULUQwdC4EMLHA8PCZsobShRVQYA6X8A6bABFCnXAukBowC9BbcAbwNzBL8MDAMMAQgDAAkKCwsLCQoGBAVVBI/DvwDz9b29kaUCb0QtsRTNLt4eGBcSHAMZFhYZEhYEARAEBUEcQRxBHEEcQRxBHEEaQRxBHEFCSTxBPElISUhBNkM2QTYbNklISVmBVIgBFLWZAu0BhQCjBcEAbykBvwGJAaQcEZ0ePCklMAAhMvAIMAL54gC7Bm8EescjzQMpARQpKgDUABavAj626xQAJP0A3etzuf4NNRA7efy2Z9NQrCnC0OSyANz5BBIbJ5IFDR6miIavYS6tprjjmuKebxm5C74Q225X1pkaYYPb6f1DK4k3xMEBb9S2WMjEibTNWhsRJIA+vwNVEiXTE5iXs/wezV66oFLfp9NZGYW+Gk19J2+bCT6Ye2w6LDYdgzKMUabk595eLBCXANz9HUpWbATq9vqXVx9XDg+Pc9Xp4+bsS005SVM/BJBM4687WUuf+Uj9dEi8aDNaPxtpbDxcG1THTImUMZq4UCaaNYpsVqraNyKLJXDYsFZ/5jl7bLRtO88t7P3xZaAxhb5OdPMXqsSkp1WCieG8jXm1U99+blvLlXzPCS+M93VnJCiK+09LfaSaBAVBomyDgJua8dfUzR7ga34IvR2Nvj+A9heJ6lsl1KG4NkI1032Cnff1m1wof2B9oHJK4bi6JkEdSqeNeiuo6QoZZincoc73/TH9SXF8sCE7XyuYyW8WSgbGFCjPV0ihLKhdPs08Tx82fYAkLLc4I2wdl4apY7GU5lHRFzRWJep7Ww3wbeA3qmd59/86P4xuNaqDpygXt6M85glSBHOCGgJDnt+pN9bK7HApMguX6+06RZNjzVmcZJ+wcUrJ9//bpRNxNuKpNl9uFds+S9tdx7LaM5ZkIrPj6nIU9mnbFtVbs9s/uLgl8MVczAwet+iOEzzBlYW7RCMgE6gyNLeq6+1tIx4dpgZnd0DksJS5f+JNDpwwcPNXaaVspq1fbQajOrJgK0ofKtJ1Ne90L6VO4MOl5S886p7u6xo7OLjG8TGL+HU1JXGJgppg4nNbNJ5nlzSpuPYy21JUEcUA94PoFiZfjZue+QnyQ80ekOuZVkxx4g+cvhJfHgNl4hy1/a6+RKcKlar/J29y//EztlbVPHVUeQ1zX86eQVAjR/M3dA9w4W8LfaXp4EgM85wOWasli837PzVMOnsLzR+k3o75/lRPAJSE1xAKQzEi5v10ke+VBvRt1cwQRMd+U5mLCTGVd6XiZtgBG5cDi0w22GKcVNvHiu5LQbZEDVtz0onn7k5+heuKXVsZtSzilkLRAUmjMXEMB3J9YC50XBxPiz53SC+EhnPl9WsKCv92SM/OFFIMJZYfl0WW8tIO3UxYcwdMAj7FSmgrsZ2aAZO03BOhP1bNNZItyXYQFTpC3SG1VuPDqH9GkiCDmE+JwxyIVSO5siDErAOpEXFgjy6PQtOVDj+s6e1r8heWVvmZnTciuf4EiNZzCAd7SOMhXERIOlsHIMG399i9aLTy3m2hRLZjJVDNLS53iGIK11dPqQt0zBDyg6qc7YqkDm2M5Ve6dCWCaCbTXX2rToaIgz6+zh4lYUi/+6nqcFMAkQJKHYLK0wYk5N9szV6xihDbDDFr45lN1K4aCXBq/FitPSud9gLt5ZVn+ZqGX7cwm2z5EGMgfFpIFyhGGuDPmso6TItTMwny+7uPnLCf4W6goFQFV0oQSsc9VfMmVLcLr6ZetDZbaSFTLqnSO/bIPjA3/zAUoqgGFAEQS4IhuMzEp2I3jJzbzkk/IEmyax+rhZTwd6f+CGtwPixu8IvzACquPWPREu9ZvGkUzpRwvRRuaNN6cr0W1wWits9ICdYJ7ltbgMiSL3sTPeufgNcVqMVWFkCPDH4jG2jA0XcVgQj62Cb29v9f/z/+2KbYvIv/zzjpQAPkliaVDzNrW57TZ/ZOyZD0nlfMmAIBIAGAI0D3k/mdN4xr9v85ZbZbbqfH2jGd5hUqNZWwl5SPfoGmfElmazUIeNL1j/mkF7VNAzTq4jNt8JoQ11NQOcmhprXoxSxfRGJ9LDEOAQ+dmxAQH90iti9e2u/MoeuaGcDTHoC+xsmEeWmxEKefQuIzHbpw5Tc5cEocboAD09oipWQhtTO1wivf/O+DRe2rpl/E9wlrzBorjJsOeG1B/XPW4EaJEFdNlECEZga5ZoGRHXgYouGRuVkm8tDESiEyFNo+3s5M5puSdTyUL2llnINVHEt91XUNW4ewdMgJ4boJfEyt/iY5WXqbA+A2Fkt5Z0lutiWhe9nZIyIUjyXDC3UsaG1t+eNx6z4W/OYoTB7A6x+dNSTOi9AInctbESqm5gvOLww7OWXPrmHwVZasrl4eD113pm+JtT7JVOvnCXqdzzdTRHgJ0PiGTFYW5Gvt9R9LD6Lzfs0v/TZZHSmyVNq7viIHE6DBK7Qp07Iz55EM8SYtQvZf/obBniTWi5C2/ovHfw4VndkE5XYdjOhCMRjDeOEfXeN/CwfGduiUIfsoFeUxXeQXba7c7972XNv8w+dTjjUM0QeNAReW+J014dKAD/McQYXT7c0GQPIkn3Ll6R7gGjuiQoZD0TEeEqQpKoZ15g/0OPQI17QiSv9AUROa/V/TQN3dvLArec3RrsYlvBm1b8LWzltdugsC50lNKYLEp2a+ZZYqPejULRlOJh5zj/LVMyTDvwKhMxxwuDkxJ1QpoNI0OTWLom4Z71SNzI9TV1iXJrIu9Wcnd+MCaAw8o1jSXd94YU/1gnkrC9BUEOtQvEIQ7g0i6h+KL2JKk8Ydl7HruvgWMSAmNe+LshGhV4qnWHhO9/RIPQzY1tHRj2VqOyNsDpK0cww+56AdDC4gsWwY0XxoucIWIqs/GcwnWqlaT0KPr8mbK5U94/301i1WLt4YINTVvCFBrFZbIbY8eycOdeJ2teD5IfPLCRg7jjcFTwlMFNl9zdh/o3E/hHPwj7BWg0MU09pPrBLbrCgm54A6H+I6v27+jL5gkjWg/iYdks9jbfVP5y/n0dlgWEMlKasl7JvFZd56LfybW1eeaVO0gxTfXZwD8G4SI116yx7UKVRgui6Ya1YpixqXeNLc8IxtAwCU5IhwQgn+NqHnRaDv61CxKhOq4pOX7M6pkA+Pmpd4j1vn6ACUALoLLc4vpXci8VidLxzm7qFBe7s+quuJs6ETYmnpgS3LwSZxPIltgBDXz8M1k/W2ySNv2f9/NPhxLGK2D21dkHeSGmenRT3Yqcdl0m/h3OYr8V+lXNYGf8aCCpd4bWjE4QIPj7vUKN4Nrfs7ML6Y2OyS830JCnofg/k7lpFpt4SqZc5HGg1HCOrHvOdC8bP6FGDbE/VV0mX4IakzbdS/op+Kt3G24/8QbBV7y86sGSQ/vZzU8FXs7u6jIvwchsEP2BpIhW3G8uWNwa3HmjfH/ZjhhCWvluAcF+nMf14ClKg5hGgtPLJ98ueNAkc5Hs2WZlk2QHvfreCK1CCGO6nMZVSb99VM/ajr8WHTte9JSmkXq/i/U943HEbdzW6Re/S88dKgg8pGOLlAeNiqrcLkUR3/aClFpMXcOUP3rmETcWSfMXZE3TUOi8i+fqRnTYLflVx/Vb/6GJ7eIRZUA6k3RYR3iFSK9c4iDdNwJuZL2FKz/IK5VimcNWEqdXjSoxSgmF0UPlDoUlNrPcM7ftmA8Y9gKiqKEHuWN+AZRIwtVSxye2Kf8rM3lhJ5XcBXU9n4v0Oy1RU2M+4qM8AQPVwse8ErNSob5oFPWxuqZnVzo1qB/IBxkM3EVUKFUUlO3e51259GgNcJbCmlvrdjtoTW7rChm1wyCKzpCTwozUUEOIcWLneRLgMXh+SjGSFkAllzbGS5HK7LlfCMRNRDSvbQPjcXaenNYxCvu2Qyznz6StuxVj66SgI0T8B6/sfHAJYZaZ78thjOSIFumNWLQbeZixDCCC+v0YBtkxiBB3jefHqZ/dFHU+crbj6OvS1x/JDD7vlm7zOVPwpUC01nhxZuY/63E7g");Of=new Map(df(e).flatMap((e,t)=>e.map(e=>[e,t+1<<24]))),Tf=new Set(hf(e)),Nf=new Map,Pf=new Map;for(let[t,n]of pf(e)){if(!Tf.has(t)&&2==n.length){let[e,r]=n,o=Pf.get(e);o||(o=new Map,Pf.set(e,o)),o.set(r,t)}Nf.set(t,n.reverse())}}();let t=[],n=[],r=!1;function o(e){let n=Of.get(e);n&&(r=!0,e|=n),t.push(e)}for(let r of e)for(;;){if(r<128)t.push(r);else if(Bf(r)){let e=r-Af,t=e%588/28|0,n=e%28;o(xf+(e/588|0)),o(kf+t),n>0&&o(Sf+n)}else{let e=Nf.get(r);e?n.push(...e):o(r)}if(!n.length)break;r=n.pop()}if(r&&t.length>1){let e=If(t[0]);for(let n=1;n<t.length;n++){let r=If(t[n]);if(0==r||e<=r){e=r;continue}let o=n-1;for(;;){let n=t[o+1];if(t[o+1]=t[o],t[o]=n,!o)break;if(e=If(t[--o]),e<=r)break}e=If(t[n])}}return t}function Df(e){return Uf(e).map(Cf)}function Lf(e){return function(e){let t=[],n=[],r=-1,o=0;for(let i of e){let e=If(i),s=Cf(i);if(-1==r)0==e?r=s:t.push(s);else if(o>0&&o>=e)0==e?(t.push(r,...n),n.length=0,r=s):n.push(s),o=e;else{let i=Rf(r,s);i>=0?r=i:0==o&&0==e?(t.push(r),r=s):(n.push(s),o=e)}}return r>=0&&t.push(r,...n),t}(Uf(e))}const Ff=e=>Array.from(e);function _f(e,t){return e.P.has(t)||e.Q.has(t)}class Mf extends Array{get is_emoji(){return!0}}let Gf,jf,Hf,zf,Vf,Kf,Wf,$f,qf,Jf,Qf,Zf;function Yf(){if(Gf)return;let e=uf("AEEUdwmgDS8BxQKKAP4BOgDjATAAngDUAIMAoABoAOAAagCOAEQAhABMAHIAOwA9ACsANgAmAGIAHgAuACgAJwAXAC0AGgAjAB8ALwAUACkAEgAeAAkAGwARABkAFgA5ACgALQArADcAFQApABAAHgAiABAAGgAeABMAGAUhBe8BFxREN8sF2wC5AK5HAW8ArQkDzQCuhzc3NzcBP68NEfMABQdHBuw5BV8FYAA9MzkI9r4ZBg7QyQAWA9CeOwLNCjcCjqkChuA/lm+RAsXTAoP6ASfnEQDytQFJAjWVCkeXAOsA6godAB/cwdAUE0WlBCN/AQUCQRjFD/MRBjHxDQSJbw0jBzUAswBxme+tnIcAYwabAysG8QAjAEMMmxcDqgPKQyDXCMMxA7kUQwD3NXOrAKmFIAAfBC0D3x4BJQDBGdUFAhEgVD8JnwmQJiNWYUzrg0oAGwAUAB0AFnNcACkAFgBP9h3gPfsDOWDKneY2ChglX1UDYD30ABsAFAAdABZzIGRAnwDD8wAjAEEMzRbDqgMB2sAFYwXqAtCnAsS4AwpUJKRtFHsadUz9AMMVbwLpABM1NJEX0ZkCgYMBEyMAxRVvAukAEzUBUFAtmUwSAy4DBTER33EftQHfSwB5MxJ/AjkWKQLzL8E/cwBB6QH9LQDPDtO9ASNriQC5DQANAwCK21EFI91zHwCoL9kBqQcHBwcHKzUDowBvAQohPvU3fAQgHwCyAc8CKQMA5zMSezr7ULgFmDp/LzVQBgEGAi8FYQVgt8AFcTtlQhpCWEmfe5tmZ6IAExsDzQ8t+X8rBKtTAltbAn0jsy8Bl6utPWMDTR8Ei2kRANkDBrNHNysDBzECQWUAcwFpJ3kAiyUhAJ0BUb8AL3EfAbfNAz81KUsFWwF3YQZtAm0A+VEfAzEJDQBRSQCzAQBlAHsAM70GD/v3IZWHBwARKQAxALsjTwHZAeMPEzmXgIHwABIAGQA8AEUAQDt3gdvIEGcQZAkGTRFMdEIVEwK0D64L7REdDNkq09PgADSxB/MDWwfzA1sDWwfzB/MDWwfzA1sDWwNbA1scEvAi28gQZw9QBHUFlgWTBN4IiyZREYkHMAjaVBV0JhxPA00BBCMtSSQ7mzMTJUpMFE0LCAQ2SmyvfUADTzGzVP2QqgPTMlc5dAkGHnkSqAAyD3skNb1OhnpPcagKU0+2tYdJak5vAsY6sEAACikJm2/Dd1YGRRAfJ6kQ+ww3AbkBPw3xS9wE9QY/BM0fgRkdD9GVoAipLeEM8SbnLqWAXiP5KocF8Uv4POELUVFsD10LaQnnOmeBUgMlAREijwrhDT0IcRD3Cs1vDekRSQc9A9lJngCpBwULFR05FbkmFGKwCw05ewb/GvoLkyazEy17AAXXGiUGUQEtGwMA0y7rhbRaNVwgT2MGBwspI8sUrFAkDSlAu3hMGh8HGSWtApVDdEqLUToelyH6PEENai4XUYAH+TwJGVMLhTyiRq9FEhHWPpE9TCJNTDAEOYMsMyePCdMPiQy9fHYBXQklCbUMdRM1ERs3yQg9Bx0xlygnGQglRplgngT7owP3E9UDDwVDCUUHFwO5HDETMhUtBRGBKNsC9zbZLrcCk1aEARsFzw8pH+MQVEfkDu0InwJpA4cl7wAxFSUAGyKfCEdnAGOP3FMJLs8Iy2pwI3gDaxTrZRF3B5UOWwerHDcVwxzlcMxeD4YMKKezCV8BeQmdAWME5wgNNV+MpCBFZ1eLXBifIGVBQ14AAjUMaRWjRMGHfAKPD28SHwE5AXcHPQ0FAnsR8RFvEJkI74YINbkz/DopBFMhhyAVCisDU2zSCysm/Qz8bQGnEmYDEDRBd/Jnr2C6KBgBBx0yyUFkIfULlk/RDKAaxRhGVDIZ6AfDA/ca9yfuQVsGAwOnBxc6UTPyBMELbQiPCUMATQ6nGwfbGG4KdYzUATWPAbudA1uVhwJzkwY7Bw8Aaw+LBX3pACECqwinAAkA0wNbAD0CsQehAB0AiUUBQQMrMwEl6QKTA5cINc8BmTMB9y0EH8cMGQD7O25OAsO1AoBuZqYF4VwCkgJNOQFRKQQJUktVA7N15QDfAE8GF+NLARmvTs8e50cB43MvAMsA/wAJOQcJRQHRAfdxALsBYws1Caa3uQFR7S0AhwAZbwHbAo0A4QA5AIP1AVcAUQVd/QXXAlNNARU1HC9bZQG/AyMBNwERAH0Gz5GpzQsjBHEH1wIQHxXlAu8yB7kFAyLjE9FCyQK94lkAMhoKPAqrCqpgX2Q3CjV2PVQAEh+sPss/UgVVO1c7XDtXO1w7VztcO1c7XDtXO1wDm8Pmw+YKcF9JYe8Mqg3YRMw6TRPfYFVgNhPMLbsUxRXSJVoZQRrAJwkl6FUNDwgt12Y0CDA0eRfAAEMpbINFY4oeNApPHOtTlVT8LR8AtUumM7MNsBsZREQFS3XxYi4WEgomAmSFAmJGX1GzAV83JAKh+wJonAJmDQKfiDgfDwJmPwJmKgRyBIMDfxcDfpY5Cjl7GzmGOicnAmwhAjI6OA4CbcsCbbLzjgM3a0kvAWsA4gDlAE4JB5wMkQECD8YAEbkCdzMCdqZDAnlPRwJ4viFg30WyRvcCfEMCeswCfQ0CfPRIBEiBZygALxlJXEpfGRtK0ALRBQLQ0EsrA4hTA4fqRMmRNgLypV0HAwOyS9JMMSkH001QTbMCi0MCitzFHwshR2sJuwKOOwKOYESbhQKO3QKOYHxRuFM5AQ5S2FSJApP/ApMQAO0AIFUiVbNV1AosHymZijLleGpFPz0Cl6MC77ZYJawAXSkClpMCloCgAK1ZsFoNhVEAPwKWuQKWUlxIXNUCmc8CmWhczl0LHQKcnznGOqECnBoCn58CnryOACETNS4TAp31Ap6WALlBYThh8wKe1wKgcgGtAp6jIwKeUqljzGQrKS8CJ7MCJoICoP8CoFDbAqYzAqXSAqgDAIECp/ZogGi1AAdNaiBq1QKs5wKssgKtawKtBgJXIQJV4AKx5dsDH1JsmwKywRECsuwbbORtZ21MYwMl0QK2YD9DbpQDKUkCuGICuUsZArkue3A6cOUCvR0DLbYDMhUCvoxyBgMzdQK+HnMmc1MCw88CwwhzhnRPOUl05AM8qwEDPJ4DPcMCxYACxksCxhSNAshtVQLISALJUwLJMgJkoQLd1nh9ZXiyeSlL1AMYp2cGAmH4GfeVKHsPXpZevxUCz28Cz3AzT1fW9xejAMqxAs93AS3uA04Wfk8JAtwrAtuOAtJTA1JgA1NjAQUDVZCAjUMEzxrxZEl5A4LSg5EC2ssC2eKEFIRNp0ADhqkAMwNkEoZ1Xf0AWQLfaQLevHd7AuIz7RgB8zQrAfSfAfLWiwLr9wLpdH0DAur9AuroAP1LAb0C7o0C66CWrpcHAu5DA4XkmH1w5HGlAvMHAG0DjhqZlwL3FwORcgOSiwL3nAL53QL4apogmq+/O5siA52HAv7+AR8APZ8gAZ+3AwWRA6ZuA6bdANXJAwZuoYyiCQ0DDE0BEwEjB3EGZb1rCQC/BG/DFY8etxEAG3k9ACcDNxJRA42DAWcrJQCM8wAlAOanC6OVCLsGI6fJBgCvBRnDBvElRUYFFoAFcD9GSDNCKUK8X3kZX8QAls0FOgCQVCGbwTsuYDoZutcONxjOGJHJ/gVfBWAFXwVgBWsFYAVfBWAFXwVgBV8FYAVfBWBOHQjfjW8KCgoKbF7xMwTRA7kGN8PDAMMEr8MA70gxFroFTj5xPnhCR0K+X30/X/AAWBkzswCNBsxzzASm70aCRS4rDDMeLz49fnXfcsH5GcoscQFz13Y4HwVnBXLJycnACNdRYwgICAqEXoWTxgA7P4kACxbZBu21Kw0AjMsTAwkVAOVtJUUsJ1JCuULESUArXy9gPi9AKwnJRQYKTD9LPoA+iT54PnkCkULEUUpDX9NWV3JVEjQAc1w3A3IBE3YnX+g7QiMJb6MKaiszRCUuQrNCxDPMCcwEX9EWJzYREBEEBwIHKn6l33JCNVIfybPJtAltydPUCmhBZw/tEKsZAJOVJU1CLRuxbUHOQAo7P0s+eEJHHA8SJVRPdGM0NVrpvBoKhfUlM0JHHGUQUhEWO1xLSj8MO0ucNAqJIzVCRxv9EFsqKyA4OQgNj2nwZgp5ZNFgE2A1K3YHS2AhQQojJmC7DgpzGG1WYFUZCQYHZO9gHWCdYIVgu2BTYJlwFh8GvRbcXbG8YgtDHrMBwzPVyQonHQgkCyYBgQJ0Ajc4nVqIAwGSCsBPIgDsK3SWEtIVBa5N8gGjAo+kVwVIZwD/AEUSCDweX4ITrRQsJ8K3TwBXFDwEAB0TvzVcAtoTS20RIwDgVgZ9BBImYgA5AL4Coi8LFnezOkCnIQFjAY4KBAPh9RcGsgZSBsEAJctdsWIRu2kTkQstRw7DAcMBKgpPBGIGMDAwKCYnKTQaLg4AKRSVAFwCdl+YUZ0JdicFD3lPAdt1F9ZZKCGxuE3yBxkFVGcA/wBFEgiCBwAOLHQSjxOtQDg1z7deFRMAZ8QTAGtKb1ApIiPHADkAvgKiLy1DFtYCmBiDAlDDWNB0eo7fpaMO/aEVRRv0ATEQZBIODyMEAc8JQhCbDRgzFD4TAEMAu9YBCgCsAOkAm5I3ABwAYxvONnR+MhXJAxgKQyxL2+kkJhMbhQKDBMkSsvF0AD9BNQ6uQC7WqSQHwxEAEEIu1hkhAH2z4iQPwyJPHNWpdyYBRSpnJALzoBAEVPPsH20MxA0CCEQKRgAFyAtFAlMNwwjEDUQJRArELtapMg7DDZgJIw+TGukEIwvDFkMAqAtDEMMMBhioe+QAO3MMRAACrgnEBSPY9Q0FDnbSBoMAB8MSYxkSxAEJAPIJAAB8FWMOFtMc/HcXwxhDAC7DAvOowwAewwJdKDKHAAHDAALrFUQVwwAbwyvzpWMWv8wA/ABpAy++bcYDUKPD0KhDCwKmJ1MAAmMA5+UZwxAagwipBRL/eADfw6fDGOMCGsOjk3l6BwOpo4sAEsMOGxMAA5sAbcMOAAvDp0MJGkMDwgipnNIPAwfIqUMGAOGDAAPzABXDAAcDAAnDAGmTABrDAA7DChjDjnEWAwABYwAOcwAuUyYABsMAF8MIKQANUgC6wy4AA8MADqMq8wCyYgAcIwAB8wqpAAXOCx0V4wAHowBCwwEKAGnDAAuDAB3DAAjDCakABdIAbqcZ3QCZCCkABdIAAAFDAAfjAB2jCCkABqIACYMAGzMAbSMA5sOIAAhjAAhDABTDBAkpAAbSAOOTAAlDC6kOzPtnAAdDAG6kQFAATwAKwwwAA0MACbUDPwAHIwAZgwACE6cDAAojAApDAAoDp/MGwwAJIwADEwAQQwgAFEMAEXMAD5MADfMADcMAGRMOFiMAFUMAbqMWuwHDAMIAE0MLAGkzEgDhUwACQwAEWgAXgwUjAAbYABjDBSYBgzBaAEFNALcQBxUMegAwMngBrA0IZgJ0KxQHBREPd1N0ZzKRJwaIHAZqNT4DqQq8BwngAB4DAwt2AX56T1ocKQNXAh1GATQGC3tOxYNagkgAMQA5CQADAQEAWxLjAIOYNAEzAH7tFRk6TglSAF8NAAlYAQ+S1ACAQwQorQBiAN4dAJ1wPyeTANVzuQDX3AIeEMp9eyMgXiUAEdkBkJizKltbVVAaRMqRAAEAhyQ/SDEz6BmfVwB6ATEsOClKIRcDOF0E/832AFNt5AByAnkCRxGCOs94NjXdAwINGBonDBwPALW2AwICAgAAAAAAAAYDBQMDARrUAwAtAAAAAgEGBgYGBgYFBQUFBQUEBQYHCAkEBQUFBQQAAAICAAAAIgCNAJAAlT0A6gC7ANwApEQAwgCyAK0AqADuAKYA2gCjAOcBCAEDAMcAgQBiANIA1AEDAN4A8gCQAKkBMQDqAN8A3AsBCQ8yO9ra2tq8xuLT1tRJOB0BUgFcNU0BWgFpAWgBWwFMUUlLbhMBUxsNEAs6PhMOACcUKy0vMj5AQENDQ0RFFEYGJFdXV1dZWVhZL1pbXVxcI2NnZ2ZoZypsbnZ1eHh4eHh4enp6enp6enp6enp8fH18e2IARPIASQCaAHgAMgBm+ACOAFcAVwA3AnbvAIsABfj4AGQAk/IAnwBPAGIAZP//sACFAIUAaQBWALEAJAC2AIMCQAJDAPwA5wD+AP4A6AD/AOkA6QDoAOYALwJ7AVEBQAE+AVQBPgE+AT4BOQE4ATgBOAEcAVgXADEQCAEAUx8SHgsdHhYAjgCWAKYAUQBqIAIxAHYAbwCXAxUDJzIDIUlGTzEAkQJPAMcCVwKkAMAClgKWApYClgKWApYCiwKWApYClgKWApYClgKVApUCmAKgApcClgKWApQClAKUApQCkgKVAnUB1AKXAp8ClgKWApUeAIETBQD+DQOfAmECOh8BVBg9AuIZEjMbAU4/G1WZAXusRAFpYQEFA0FPAQYAmTEeIJdyADFoAHEANgCRA5zMk/C2jGINwjMWygIZCaXdfDILBCs5dAE7YnQBugDlhoiHhoiGiYqKhouOjIaNkI6Ij4qQipGGkoaThpSSlYaWhpeKmIaZhpqGm4aci52QnoqfhuIC4XTpAt90AIp0LHSoAIsAdHQEQwRABEIERQRDBEkERgRBBEcESQRIBEQERgRJAJ5udACrA490ALxuAQ10ANFZdHQA13QCFHQA/mJ0AP4BIQD+APwA/AD9APwDhGZ03ASMK23HAP4A/AD8AP0A/CR0dACRYnQA/gCRASEA/gCRAvQA/gCRA4RmdNwEjCttxyR0AP9idAEhAP4A/gD8APwA/QD8AP8A/AD8AP0A/AOEZnTcBIwrbcckdHQAkWJ0ASEA/gCRAP4AkQL0AP4AkQOEZnTcBIwrbcckdAJLAT50AlIBQXQCU8l0dAJfdHQDpgL0A6YDpgOnA6cDpwOnA4RmdNwEjCttxyR0dACRYnQBIQOmAJEDpgCRAvQDpgCRA4RmdNwEjCttxyR0BDh0AJEEOQCRDpU5dSgCADR03gV2CwArdAEFAM5iCnR0AF1iAAYcOgp0dACRCnQAXAEIwWZ0CnRmdHQAkWZ0CnRmdEXgAFF03gp0dEY0tlT2u3SOAQTwscwhjZZKrhYcBSfFp9XNbKiVDOD2b+cpe4/Z17mQnbtzzhaeQtE2GGj0IDNTjRUSyTxxw/RPHW/+vS7d1NfRt9z9QPZg4X7QFfhCnkvgNPIItOsC2eV6hPannZNHlZ9xrwZXIMOlu3jSoQSq78WEjwLjw1ELSlF1aBvfzwk5ZX7AUvQzjPQKbDuQ+sm4wNOp4A6AdVuRS0t1y/DZpg4R6m7FNjM9HgvW7Bi88zaMjOo6lM8wtBBdj8LP4ylv3zCXPhebMKJc066o9sF71oFW/8JXu86HJbwDID5lzw5GWLR/LhT0Qqnp2JQxNZNfcbLIzPy+YypqRm/lBmGmex+82+PisxUumSeJkALIT6rJezxMH+CTJmQtt5uwTVbL3ptmjDUQzlSIvWi8Tl7ng1NpuRn1Ng4n14Qc+3Iil7OwkvNWogLSPkn3pihIFytyIGmMhOe3n1tWsuMy9BdKyqF4Z3v2SgggTL9KVvMXPnCbRe+oOuFFP3HejBG/w9gvmfNYvg6JuWia2lcSSN1uIjBktzoIazOHPJZ7kKHPz8mRWVdW3lA8WGF9dQF6Bm673boov3BUWDU2JNcahR23GtfHKLOz/viZ+rYnZFaIznXO67CYEJ1fXuTRpZhYZkKe54xeoagkNGLs+NTZHE0rX45/XvQ2RGADX6vcAvdxIUBV27wxGm2zjZo4X3ILgAlrOFheuZ6wtsvaIj4yLY7qqawlliaIcrz2G+c3vscAnCkCuMzMmZvMfu9lLwTvfX+3cVSyPdN9ZwgDZhfjRgNJcLiJ67b9xx8JHswprbiE3v9UphotAPIgnXVIN5KmMc0piXhc6cChPnN+MRhG9adtdttQTTwSIpl8I4/j//d3sz1326qTBTpPRM/Hgh3kzqEXs8ZAk4ErQhNO8hzrQ0DLkWMA/N+91tn2MdOJnWC2FCZehkQrwzwbKOjhvZsbM95QoeL9skYyMf4srVPVJSgg7pOLUtr/n9eT99oe9nLtFRpjA9okV2Kj8h9k5HaC0oivRD8VyXkJ81tcd4fHNXPCfloIQasxsuO18/46dR2jgul/UIet2G0kRvnyONMKhHs6J26FEoqSqd+rfYjeEGwHWVDpX1fh1jBBcKGMqRepju9Y00mDVHC+Xdij/j44rKfvfjGinNs1jO/0F3jB83XCDINN/HB84axlP+3E/klktRo+vl3U/aiyMJbIodE1XSsDn6UAzIoMtUObY2+k/4gY/l+AkZJ5Sj2vQrkyLm3FoxjhDX+31UXBFf9XrAH31fFqoBmDEZvhvvpnZ87N+oZEu7U9O/nnk+QWj3x8uyoRbEnf+O5UMr9i0nHP38IF5AvzrBW8YWBUR0mIAzIvndQq9N3v/Jto3aPjPXUPl8ASdPPyAp7jENf8bk7VMM9ol9XGmlBmeDMuGqt+WzuL6CXAxXjIhCPM5vACchgMJ/8XBGLO/D1isVvGhwwHHr1DLaI5mn2Jr/b1pUD90uciDaS8cXNDzCWvNmT/PhQe5e8nTnnnkt8Ds/SIjibcum/fqDhKopxAY8AkSrPn+IGDEKOO+U3XOP6djFs2H5N9+orhOahiQk5KnEUWa+CzkVzhp8bMHRbg81qhjjXuIKbHjSLSIBKWqockGtKinY+z4/RdBUF6pcc3JmnlxVcNgrI4SEzKUZSwcD2QCyxzKve+gAmg6ZuSRkpPFa6mfThu7LJNu3H5K42uCpNvPAsoedolKV/LHe/eJ+BbaG5MG0NaSGVPRUmNFMFFSSpXEcXwbVh7UETOZZtoVNRGOIbbkig3McEtR68cG0RZAoJevWYo7Dg/lZ1CQzblWeUvVHmr8fY4Nqd9JJiH/zEX24mJviH60fAyFr0A3c4bC1j3yZU60VgJxXn8JgJXLUIsiBnmKmMYz+7yBQFBvqb2eYnuW59joZBf56/wXvWIR4R8wTmV80i1mZy+S4+BUES+hzjk0uXpC///z/IlqHZ1monzlXp8aCfhGKMti73FI1KbL1q6IKO4fuBuZ59gagjn5xU79muMpHXg6S+e+gDM/U9BKLHbl9l6o8czQKl4RUkJJiqftQG2i3BMg/TQlUYFkJDYBOOvAugYuzYSDnZbDDd/aSd9x0Oe6F+bJcHfl9+gp6L5/TgA+BdFFovbfCrQ40s5vMPw8866pNX8zyFGeFWdxIpPVp9Rg1UPOVFbFZrvaFq/YAzHQgqMWpahMYfqHpmwXfHL1/kpYmGuHFwT55mQu0dylfNuq2Oq0hTMCPwqfxnuBIPLXfci4Y1ANy+1CUipQxld/izVh16WyG2Q0CQQ9NqtAnx1HCHwDj7sYxOSB0wopZSnOzxQOcExmxrVTF2BkOthVpGfuhaGECfCJpJKpjnihY+xOT2QJxN61+9K6QSqtv2Shr82I3jgJrqBg0wELFZPjvHpvzTtaJnLK6Vb97Yn933koO/saN7fsjwNKzp4l2lJVx2orjCGzC/4ZL4zCver6aQYtC5sdoychuFE6ufOiog+VWi5UDkbmvmtah/3aArEBIi39s5ILUnlFLgilcGuz9CQshEY7fw2ouoILAYPVT/gyAIq3TFAIwVsl+ktkRz/qGfnCDGrm5gsl/l9QdvCWGsjPz3dU7XuqKfdUrr/6XIgjp4rey6AJBmCmUJMjITHVdFb5m1p+dLMCL8t55zD42cmftmLEJC0Da04YiRCVUBLLa8D071/N5UBNBXDh0LFsmhV/5B5ExOB4j3WVG/S3lfK5o+V6ELHvy6RR9n4ac+VsK4VE4yphPvV+kG9FegTBH4ZRXL2HytUHCduJazB/KykjfetYxOXTLws267aGOd+I+JhKP//+VnXmS90OD/jvLcVu0asyqcuYN1mSb6XTlCkqv1vigZPIYwNF/zpWcT1GR/6aEIRjkh0yhg4LXJfaGobYJTY4JI58KiAKgmmgAKWdl5nYCeLqavRJGQNuYuZtZFGx+IkI4w4NS2xwbetNMunOjBu/hmKCI/w7tfiiyUd//4rbTeWt4izBY8YvGIN6vyKYmP/8X8wHKCeN+WRcKM70+tXKNGyevU9H2Dg5BsljnTf8YbsJ1TmMs74Ce2XlHisleguhyeg44rQOHZuw/6HTkhnnurK2d62q6yS7210SsAIaR+jXMQA+svkrLpsUY+F30Uw89uOdGAR6vo4FIME0EfVVeHTu6eKicfhSqOeXJhbftcd08sWEnNUL1C9fnprTgd83IMut8onVUF0hvqzZfHduPjbjwEXIcoYmy+P6tcJZHmeOv6VrvEdkHDJecjHuHeWANe79VG662qTjA/HCvumVv3qL+LrOcpqGps2ZGwQdFJ7PU4iuyRlBrwfO+xnPyr47s2cXVbWzAyznDiBGjCM3ksxjjqM62GE9C8f5U38kB3VjtabKp/nRdvMESPGDG90bWRLAt1Qk5DyLuazRR1YzdC1c+hZXvAWV8xA72S4A8B67vjVhbba3MMop293FeEXpe7zItMWrJG/LOH9ByOXmYnNJfjmfuX9KbrpgLOba4nZ+fl8Gbdv/ihv+6wFGKHCYrVwmhFC0J3V2bn2tIB1wCc1CST3d3X2OyxhguXcs4sm679UngzofuSeBewMFJboIQHbUh/m2JhW2hG9DIvG2t7yZIzKBTz9wBtnNC+2pCRYhSIuQ1j8xsz5VvqnyUIthvuoyyu7fNIrg/KQUVmGQaqkqZk/Vx5b33/gsEs8yX7SC1J+NV4icz6bvIE7C5G6McBaI8rVg56q5QBJWxn/87Q1sPK4+sQa8fLU5gXo4paaq4cOcQ4wR0VBHPGjKh+UlPCbA1nLXyEUX45qZ8J7/Ln4FPJE2TdzD0Z8MLSNQiykMMmSyOCiFfy84Rq60emYB2vD09KjYwsoIpeDcBDTElBbXxND72yhd9pC/1CMid/5HUMvAL27OtcIJDzNKpRPNqPOpyt2aPGz9QWIs9hQ9LiX5s8m9hjTUu/f7MyIatjjd+tSfQ3ufZxPpmJhTaBtZtKLUcfOCUqADuO+QoH8B9v6U+P0HV1GLQmtoNFTb3s74ivZgjES0qfK+8RdGgBbcCMSy8eBvh98+et1KIFqSe1KQPyXULBMTsIYnysIwiZBJYdI20vseV+wuJkcqGemehKjaAb9L57xZm3g2zX0bZ2xk/fU+bCo7TlnbW7JuF1YdURo/2Gw7VclDG1W7LOtas2LX4upifZ/23rzpsnY/ALfRgrcWP5hYmV9VxVOQA1fZvp9F2UNU+7d7xRyVm5wiLp3/0dlV7vdw1PMiZrbDAYzIVqEjRY2YU03sJhPnlwIPcZUG5ltL6S8XCxU1eYS5cjr34veBmXAvy7yN4ZjArIG0dfD/5UpBNlX1ZPoxJOwyqRi3wQWtOzd4oNKh0LkoTm8cwqgIfKhqqGOhwo71I+zXnMemTv2B2AUzABWyFztGgGULjDDzWYwJUVBTjKCn5K2QGMK1CQT7SzziOjo+BhAmqBjzuc3xYym2eedGeOIRJVyTwDw37iCMe4g5Vbnsb5ZBdxOAnMT7HU4DHpxWGuQ7GeiY30Cpbvzss55+5Km1YsbD5ea3NI9QNYIXol5apgSu9dZ8f8xS5dtHpido5BclDuLWY4lhik0tbJa07yJhH0BOyEut/GRbYTS6RfiTYWGMCkNpfSHi7HvdiTglEVHKZXaVhezH4kkXiIvKopYAlPusftpE4a5IZwvw1x/eLvoDIh/zpo9FiQInsTb2SAkKHV42XYBjpJDg4374XiVb3ws4qM0s9eSQ5HzsMU4OZJKuopFjBM+dAZEl8RUMx5uU2N486Kr141tVsGQfGjORYMCJAMsxELeNT4RmWjRcpdTGBwcx6XN9drWqPmJzcrGrH4+DRc7+n1w3kPZwu0BkNr6hQrqgo7JTB9A5kdJ/H7P4cWBMwsmuixAzJB3yrQpnGIq90lxAXLzDCdn1LPibsRt7rHNjgQBklRgPZ8vTbjXdgXrTWQsK5MdrXXQVPp0Rinq3frzZKJ0qD6Qhc40VzAraUXlob1gvkhK3vpmHgI6FRlQZNx6eRqkp0zy4AQlX813fAPtL3jMRaitGFFjo0zmErloC+h+YYdVQ6k4F/epxAoF0BmqEoKNTt6j4vQZNQ2BoqF9Vj53TOIoNmDiu9Xp15RkIgQIGcoLpfoIbenzpGUAtqFJp5W+LLnx38jHeECTJ/navKY1NWfN0sY1T8/pB8kIH3DU3DX+u6W3YwpypBMYOhbSxGjq84RZ84fWJow8pyHqn4S/9J15EcCMsXqrfwyd9mhiu3+rEo9pPpoJkdZqHjra4NvzFwuThNKy6hao/SlLw3ZADUcUp3w3SRVfW2rhl80zOgTYnKE0Hs2qp1J6H3xqPqIkvUDRMFDYyRbsFI3M9MEyovPk8rlw7/0a81cDVLmBsR2ze2pBuKb23fbeZC0uXoIvDppfTwIDxk1Oq2dGesGc+oJXWJLGkOha3CX+DUnzgAp9HGH9RsPZN63Hn4RMA5eSVhPHO+9RcRb/IOgtW31V1Q5IPGtoxPjC+MEJbVlIMYADd9aHYWUIQKopuPOHmoqSkubnAKnzgKHqgIOfW5RdAgotN6BN+O2ZYHkuemLnvQ8U9THVrS1RtLmKbcC7PeeDsYznvqzeg6VCNwmr0Yyx1wnLjyT84BZz3EJyCptD3yeueAyDWIs0L2qs/VQ3HUyqfrja0V1LdDzqAikeWuV4sc7RLIB69jEIBjCkyZedoUHqCrOvShVzyd73OdrJW0hPOuQv2qOoHDc9xVb6Yu6uq3Xqp2ZaH46A7lzevbxQEmfrzvAYSJuZ4WDk1Hz3QX1LVdiUK0EvlAGAYlG3Md30r7dcPN63yqBCIj25prpvZP0nI4+EgWoFG95V596CurXpKRBGRjQlHCvy5Ib/iW8nZJWwrET3mgd6mEhfP4KCuaLjopWs7h+MdXFdIv8dHQJgg1xi1eYqB0uDYjxwVmri0Sv5XKut/onqapC+FQiC2C1lvYJ9MVco6yDYsS3AANUfMtvtbYI2hfwZatiSsnoUeMZd34GVjkMMKA+XnjJpXgRW2SHTZplVowPmJsvXy6w3cfO1AK2dvtZEKTkC/TY9LFiKHCG0DnrMQdGm2lzlBHM9iEYynH2UcVMhUEjsc0oDBTgo2ZSQ1gzkAHeWeBXYFjYLuuf8yzTCy7/RFR81WDjXMbq2BOH5dURnxo6oivmxL3cKzKInlZkD31nvpHB9Kk7GfcfE1t+1V64b9LtgeJGlpRFxQCAqWJ5DoY77ski8gsOEOr2uywZaoO/NGa0X0y1pNQHBi3b2SUGNpcZxDT7rLbBf1FSnQ8guxGW3W+36BW0gBje4DOz6Ba6SVk0xiKgt+q2JOFyr4SYfnu+Ic1QZYIuwHBrgzr6UvOcSCzPTOo7D6IC4ISeS7zkl4h+2VoeHpnG/uWR3+ysNgPcOIXQbv0n4mr3BwQcdKJxgPSeyuP/z1Jjg4e9nUvoXegqQVIE30EHx5GHv+FAVUNTowYDJgyFhf5IvlYmEqRif6+WN1MkEJmDcQITx9FX23a4mxy1AQRsOHO/+eImX9l8EMJI3oPWzVXxSOeHU1dUWYr2uAA7AMb+vAEZSbU3qob9ibCyXeypEMpZ6863o6QPqlqGHZkuWABSTVNd4cOh9hv3qEpSx2Zy/DJMP6cItEmiBJ5PFqQnDEIt3NrA3COlOSgz43D7gpNFNJ5MBh4oFzhDPiglC2ypsNU4ISywY2erkyb1NC3Qh/IfWj0eDgZI4/ln8WPfBsT3meTjq1Uqt1E7Zl/qftqkx6aM9KueMCekSnMrcHj1CqTWWzEzPsZGcDe3Ue4Ws+XFYVxNbOFF8ezkvQGR6ZOtOLU2lQEnMBStx47vE6Pb7AYMBRj2OOfZXfisjJnpTfSNjo6sZ6qSvNxZNmDeS7Gk3yYyCk1HtKN2UnhMIjOXUzAqDv90lx9O/q/AT1ZMnit5XQe9wmQxnE/WSH0CqZ9/2Hy+Sfmpeg8RwsHI5Z8kC8H293m/LHVVM/BA7HaTJYg5Enk7M/xWpq0192ACfBai2LA/qrCjCr6Dh1BIMzMXINBmX96MJ5Hn2nxln/RXPFhwHxUmSV0EV2V0jm86/dxxuYSU1W7sVkEbN9EzkG0QFwPhyHKyb3t+Fj5WoUUTErcazE/N6EW6Lvp0d//SDPj7EV9UdJN+Amnf3Wwk3A0SlJ9Z00yvXZ7n3z70G47Hfsow8Wq1JXcfwnA+Yxa5mFsgV464KKP4T31wqIgzFPd3eCe3j5ory5fBF2hgCFyVFrLzI9eetNXvM7oQqyFgDo4CTp/hDV9NMX9JDHQ/nyHTLvZLNLF6ftn2OxjGm8+PqOwhxnPHWipkE/8wbtyri80Sr7pMNkQGMfo4ZYK9OcCC4ESVFFbLMIvlxSoRqWie0wxqnLfcLSXMSpMMQEJYDVObYsXIQNv4TGNwjq1kvT1UOkicTrG3IaBZ3XdScS3u8sgeZPVpOLkbiF940FjbCeNRINNvDbd01EPBrTCPpm12m43ze1bBB59Ia6Ovhnur/Nvx3IxwSWol+3H2qfCJR8df6aQf4v6WiONxkK+IqT4pKQrZK/LplgDI/PJZbOep8dtbV7oCr6CgfpWa8NczOkPx81iSHbsNhVSJBOtrLIMrL31LK9TqHqAbAHe0RLmmV806kRLDLNEhUEJfm9u0sxpkL93Zgd6rw+tqBfTMi59xqXHLXSHwSbSBl0EK0+loECOPtrl+/nsaFe197di4yUgoe4jKoAJDXc6DGDjrQOoFDWZJ9HXwt8xDrQP+7aRwWKWI1GF8s8O4KzxWBBcwnl3vnl1Oez3oh6Ea1vjR7/z7DDTrFtqU2W/KAEzAuXDNZ7MY73MF216dzdSbWmUp4lcm7keJfWaMHgut9x5C9mj66Z0lJ+yhsjVvyiWrfk1lzPOTdhG15Y7gQlXtacvI7qv/XNSscDwqkgwHT/gUsD5yB7LdRRvJxQGYINn9hTpodKFVSTPrtGvyQw+HlRFXIkodErAGu9Iy1YpfSPc3jkFh5CX3lPxv7aqjE/JAfTIpEjGb/H7MO0e2vsViSW1qa/Lmi4/n4DEI3g7lYrcanspDfEpKkdV1OjSLOy0BCUqVoECaB55vs06rXl4jqmLsPsFM/7vYJ0vrBhDCm/00A/H81l1uekJ/6Lml3Hb9+NKiLqATJmDpyzfYZFHumEjC662L0Bwkxi7E9U4cQA0XMVDuMYAIeLMPgQaMVOd8fmt5SflFIfuBoszeAw7ow5gXPE2Y/yBc/7jExARUf/BxIHQBF5Sn3i61w4z5xJdCyO1F1X3+3ax+JSvMeZ7S6QSKp1Fp/sjYz6Z+VgCZzibGeEoujryfMulH7Rai5kAft9ebcW50DyJr2uo2z97mTWIu45YsSnNSMrrNUuG1XsYBtD9TDYzQffKB87vWbkM4EbPAFgoBV4GQS+vtFDUqOFAoi1nTtmIOvg38N4hT2Sn8r8clmBCXspBlMBYTnrqFJGBT3wZOzAyJDre9dHH7+x7qaaKDOB4UQALD5ecS0DE4obubQEiuJZ0EpBVpLuYcce8Aa4PYd/V4DLDAJBYKQPCWTcrEaZ5HYbJi11Gd6hjGom1ii18VHYnG28NKpkz2UKVPxlhYSp8uZr367iOmoy7zsxehW9wzcy2zG0a80PBMCRQMb32hnaHeOR8fnNDzZhaNYhkOdDsBUZ3loDMa1YP0uS0cjUP3b/6DBlqmZOeNABDsLl5BI5QJups8uxAuWJdkUB/pO6Zax6tsg7fN5mjjDgMGngO+DPcKqiHIDbFIGudxtPTIyDi9SFMKBDcfdGQRv41q1AqmxgkVfJMnP8w/Bc7N9/TR6C7mGObFqFkIEom8sKi2xYqJLTCHK7cxzaZvqODo22c3wisBCP4HeAgcRbNPAsBkNRhSmD48dHupdBRw4mIvtS5oeF6zeT1KMCyhMnmhpkFAGWnGscoNkwvQ8ZM5lE/vgTHFYL99OuNxdFBxTEDd5v2qLR8y9WkXsWgG6kZNndFG+pO/UAkOCipqIhL3hq7cRSdrCq7YhUsTocEcnaFa6nVkhnSeRYUA1YO0z5itF9Sly3VlxYDw239TJJH6f3EUfYO5lb7bcFcz8Bp7Oo8QmnsUHOz/fagVUBtKEw1iT88j+aKkv8cscKNkMxjYr8344D1kFoZ7/td1W6LCNYN594301tUGRmFjAzeRg5vyoM1F6+bJZ/Q54jN/k8SFd3DxPTYaAUsivsBfgTn7Mx8H2SpPt4GOdYRnEJOH6jHM2p6SgB0gzIRq6fHxGMmSmqaPCmlfwxiuloaVIitLGN8wie2CDWhkzLoCJcODh7KIOAqbHEvXdUxaS4TTTs07Clzj/6GmVs9kiZDerMxEnhUB6QQPlcfqkG9882RqHoLiHGBoHfQuXIsAG8GTAtao2KVwRnvvam8jo1e312GQAKWEa4sUVEAMG4G6ckcONDwRcg1e2D3+ohXgY4UAWF8wHKQMrSnzCgfFpsxh+aHXMGtPQroQasRY4U6UdG0rz1Vjbka0MekOGRZQEvqQFlxseFor8zWFgHek3v29+WqN6gaK5gZOTOMZzpQIC1201LkMCXild3vWXSc5UX9xcFYfbRPzGFa1FDcPfPB/jUEq/FeGt419CI3YmBlVoHsa4KdcwQP5ZSwHHhFJ7/Ph/Rap/4vmG91eDwPP0lDfCDRCLszTqfzM71xpmiKi2HwS4WlqvGNwtvwF5Dqpn6KTq8ax00UMPkxDcZrEEEsIvHiUXXEphdb4GB4FymlPwBz4Gperqq5pW7TQ6/yNRhW8VT5NhuP0udlxo4gILq5ZxAZk8ZGh3g4CqxJlPKY7AQxupfUcVpWT5VItp1+30UqoyP4wWsRo3olRRgkWZZ2ZN6VC3OZFeXB8NbnUrSdikNptD1QiGuKkr8EmSR/AK9Rw+FF3s5uwuPbvHGiPeFOViltMK7AUaOsq9+x9cndk3iJEE5LKZRlWJbKOZweROzmPNVPkjE3K/TyA57Rs68TkZ3MR8akKpm7cFjnjPd/DdkWjgYoKHSr5Wu5ssoBYU4acRs5g2DHxUmdq8VXOXRbunD8QN0LhgkssgahcdoYsNvuXGUK/KXD/7oFb+VGdhqIn02veuM5bLudJOc2Ky0GMaG4W/xWBxIJcL7yliJOXOpx0AkBqUgzlDczmLT4iILXDxxtRR1oZa2JWFgiAb43obrJnG/TZC2KSK2wqOzRZTXavZZFMb1f3bXvVaNaK828w9TO610gk8JNf3gMfETzXXsbcvRGCG9JWQZ6+cDPqc4466Yo2RcKH+PILeKOqtnlbInR3MmBeGG3FH10yzkybuqEC2HSQwpA0An7d9+73BkDUTm30bZmoP/RGbgFN+GrCOfADgqr0WbI1a1okpFms8iHYw9hm0zUvlEMivBRxModrbJJ+9/p3jUdQQ9BCtQdxnOGrT5dzRUmw0593/mbRSdBg0nRvRZM5/E16m7ZHmDEtWhwvfdZCZ8J8M12W0yRMszXamWfQTwIZ4ayYktrnscQuWr8idp3PjT2eF/jmtdhIfcpMnb+IfZY2FebW6UY/AK3jP4u3Tu4zE4qlnQgLFbM19EBIsNf7KhjdbqQ/D6yiDb+NlEi2SKD+ivXVUK8ib0oBo366gXkR8ZxGjpJIDcEgZPa9TcYe0TIbiPl/rPUQDu3XBJ9X/GNq3FAUsKsll57DzaGMrjcT+gctp+9MLYXCq+sqP81eVQ0r9lt+gcQfZbACRbEjvlMskztZG8gbC8Qn9tt26Q7y7nDrbZq/LEz7kR6Jc6pg3N9rVX8Y5MJrGlML9p9lU4jbTkKqCveeZUJjHB03m2KRKR2TytoFkTXOLg7keU1s1lrPMQJpoOKLuAAC+y1HlJucU6ysB5hsXhvSPPLq5J7JtnqHKZ4vYjC4Vy8153QY+6780xDuGARsGbOs1WqzH0QS765rnSKEbbKlkO8oI/VDwUd0is13tKpqILu1mDJFNy/iJAWcvDgjxvusIT+PGz3ST/J9r9Mtfd0jpaGeiLYIqXc7DiHSS8TcjFVksi66PEkxW1z6ujbLLUGNNYnzOWpH8BZGK4bCK7iR+MbIv8ncDAz1u4StN3vTTzewr9IQjk9wxFxn+6N1ddKs0vffJiS08N3a4G1SVrlZ97Q/M+8G9fe5AP6d9/Qq4WRnORVhofPIKEdCr3llspUfE0oKIIYoByBRPh+bX1HLS3JWGJRhIvE1aW4NTd8ePi4Z+kXb+Z8snYfSNcqijhAgVsx4RCM54cXUiYkjeBmmC4ajOHrChoELscJJC7+9jjMjw5BagZKlgRMiSNYz7h7vvZIoQqbtQmspc0cUk1G/73iXtSpROl5wtLgQi0mW2Ex8i3WULhcggx6E1LMVHUsdc9GHI1PH3U2Ko0PyGdn9KdVOLm7FPBui0i9a0HpA60MsewVE4z8CAt5d401Gv6zXlIT5Ybit1VIA0FCs7wtvYreru1fUyW3oLAZ/+aTnZrOcYRNVA8spoRtlRoWflsRClFcgzkqiHOrf0/SVw+EpVaFlJ0g4Kxq1MMOmiQdpMNpte8lMMQqm6cIFXlnGbfJllysKDi+0JJMotkqgIxOSQgU9dn/lWkeVf8nUm3iwX2Nl3WDw9i6AUK3vBAbZZrcJpDQ/N64AVwjT07Jef30GSSmtNu2WlW7YoyW2FlWfZFQUwk867EdLYKk9VG6JgEnBiBxkY7LMo4YLQJJlAo9l/oTvJkSARDF/XtyAzM8O2t3eT/iXa6wDN3WewNmQHdPfsxChU/KtLG2Mn8i4ZqKdSlIaBZadxJmRzVS/o4yA65RTSViq60oa395Lqw0pzY4SipwE0SXXsKV+GZraGSkr/RW08wPRvqvSUkYBMA9lPx4m24az+IHmCbXA+0faxTRE9wuGeO06DIXa6QlKJ3puIyiuAVfPr736vzo2pBirS+Vxel3TMm3JKhz9o2ZoRvaFVpIkykb0Hcm4oHFBMcNSNj7/4GJt43ogonY2Vg4nsDQIWxAcorpXACzgBqQPjYsE/VUpXpwNManEru4NwMCFPkXvMoqvoeLN3qyu/N1eWEHttMD65v19l/0kH2mR35iv/FI+yjoHJ9gPMz67af3Mq/BoWXqu3rphiWMXVkmnPSEkpGpUI2h1MThideGFEOK6YZHPwYzMBvpNC7+ZHxPb7epfefGyIB4JzO9DTNEYnDLVVHdQyvOEVefrk6Uv5kTQYVYWWdqrdcIl7yljwwIWdfQ/y+2QB3eR/qxYObuYyB4gTbo2in4PzarU1sO9nETkmj9/AoxDA+JM3GMqQtJR4jtduHtnoCLxd1gQUscHRB/MoRYIEsP2pDZ9KvHgtlk1iTbWWbHhohwFEYX7y51fUV2nuUmnoUcqnWIQAAgl9LTVX+Bc0QGNEhChxHR4YjfE51PUdGfsSFE6ck7BL3/hTf9jLq4G1IafINxOLKeAtO7quulYvH5YOBc+zX7CrMgWnW47/jfRsWnJjYYoE7xMfWV2HN2iyIqLI");const t=()=>hf(e),n=()=>new Set(t()),r=(e,t)=>t.forEach(t=>e.add(t));Gf=new Map(pf(e)),jf=n(),Hf=t(),zf=new Set(t().map(e=>Hf[e])),Hf=new Set(Hf),Vf=n(),Kf=n();let o=df(e),i=e();const s=()=>{let e=new Set;return t().forEach(t=>r(e,o[t])),r(e,t()),e};Wf=gf(t=>{let n=gf(e).map(e=>e+96);if(n.length){let r=t>=i;return n[0]-=32,n=vf(n),r&&(n=`Restricted[${n}]`),{N:n,P:s(),Q:s(),M:!e(),R:r}}}),$f=n(),qf=new Map;let a=t().concat(Ff($f)).sort((e,t)=>e-t);a.forEach((t,n)=>{let r=e(),o=a[n]=r?a[n-r]:{V:[],M:new Map};o.V.push(t),$f.has(t)||qf.set(t,o)});for(let{V:e,M:t}of new Set(qf.values())){let n=[];for(let t of e){let e=Wf.filter(e=>_f(e,t)),o=n.find(({G:t})=>e.some(e=>t.has(e)));o||(o={G:new Set,V:[]},n.push(o)),o.V.push(t),r(o.G,e)}let o=n.flatMap(e=>Ff(e.G));for(let{G:e,V:r}of n){let n=new Set(o.filter(t=>!e.has(t)));for(let e of r)t.set(e,n)}}Jf=new Set;let c=new Set;const u=e=>Jf.has(e)?c.add(e):Jf.add(e);for(let e of Wf){for(let t of e.P)u(t);for(let t of e.Q)u(t)}for(let e of Jf)qf.has(e)||c.has(e)||qf.set(e,1);r(Jf,Df(Jf)),Qf=function(e){let t=[],n=hf(e);return function e({S:n,B:r},o,i){if(!(4&n&&i===o[o.length-1])){2&n&&(i=o[o.length-1]),1&n&&t.push(o);for(let t of r)for(let n of t.Q)e(t,[...o,n],i)}}(function t(r){let o=e(),i=gf(()=>{let r=hf(e).map(e=>n[e]);if(r.length)return t(r)});return{S:o,B:i,Q:r}}([]),[]),t}(e).map(e=>Mf.from(e)).sort(Ef),Zf=new Map;for(let e of Qf){let t=[Zf];for(let n of e){let e=t.map(e=>{let t=e.get(n);return t||(t=new Map,e.set(n,t)),t});65039===n?t.push(...e):t=e}for(let n of t)n.V=e}}function Xf(e){return(nh(e)?"":`${eh(th([e]))} `)+bf(e)}function eh(e){return`"${e}"‎`}function th(e,t=1/0,n=bf){let r=[];var o;o=e[0],Yf(),Hf.has(o)&&r.push("◌"),e.length>t&&(t>>=1,e=[...e.slice(0,t),8230,...e.slice(-t)]);let i=0,s=e.length;for(let t=0;t<s;t++){let o=e[t];nh(o)&&(r.push(vf(e.slice(i,t))),r.push(n(o)),i=t+1)}return r.push(vf(e.slice(i,s))),r.join("")}function nh(e){return Yf(),Vf.has(e)}function rh(e,t,n){if(!e)return[];Yf();let r=0;return e.split(".").map(e=>{let o=function(e){let t=[];for(let n=0,r=e.length;n<r;){let r=e.codePointAt(n);n+=r<65536?1:2,t.push(r)}return t}(e),i={input:o,offset:r};r+=o.length+1;try{let e,r=i.tokens=function(e,t,n){let r=[],o=[];for(e=e.slice().reverse();e.length;){let i=ch(e);if(i)o.length&&(r.push(t(o)),o=[]),r.push(n(i));else{let t=e.pop();if(Jf.has(t))o.push(t);else{let e=Gf.get(t);if(e)o.push(...e);else if(!jf.has(t))throw oh(t)}}}return o.length&&r.push(t(o)),r}(o,t,n),s=r.length;if(!s)throw new Error("empty label");let a=i.output=r.flat();if(function(e){for(let t=e.lastIndexOf(95);t>0;)if(95!==e[--t])throw new Error("underscore allowed only at start")}(a),!(i.emoji=s>1||r[0].is_emoji)&&a.every(e=>e<128))!function(e){if(e.length>=4&&45==e[2]&&45==e[3])throw new Error(`invalid label extension: "${vf(e.slice(0,4))}"`)}(a),e="ASCII";else{let t=r.flatMap(e=>e.is_emoji?[]:e);if(t.length){if(Hf.has(a[0]))throw sh("leading combining mark");for(let e=1;e<s;e++){let t=r[e];if(!t.is_emoji&&Hf.has(t[0]))throw sh(`emoji + combining mark: "${vf(r[e-1])} + ${th([t[0]])}"`)}!function(e){let t=e[0],n=cf.get(t);if(n)throw sh(`leading ${n}`);let r=e.length,o=-1;for(let i=1;i<r;i++){t=e[i];let r=cf.get(t);if(r){if(o==i)throw sh(`${n} + ${r}`);o=i+1,n=r}}if(o==r)throw sh(`trailing ${n}`)}(a);let n=Ff(new Set(t)),[o]=function(e){let t=Wf;for(let n of e){let e=t.filter(e=>_f(e,n));if(!e.length)throw Wf.some(e=>_f(e,n))?ih(t[0],n):oh(n);if(t=e,1==e.length)break}return t}(n);!function(e,t){for(let n of t)if(!_f(e,n))throw ih(e,n);if(e.M){let e=Df(t);for(let t=1,n=e.length;t<n;t++)if(zf.has(e[t])){let r=t+1;for(let o;r<n&&zf.has(o=e[r]);r++)for(let n=t;n<r;n++)if(e[n]==o)throw new Error(`duplicate non-spacing marks: ${Xf(o)}`);if(r-t>4)throw new Error(`excessive non-spacing marks: ${eh(th(e.slice(t-1,r)))} (${r-t}/4)`);t=r}}}(o,t),function(e,t){let n,r=[];for(let e of t){let t=qf.get(e);if(1===t)return;if(t){let r=t.M.get(e);if(n=n?n.filter(e=>r.has(e)):Ff(r),!n.length)return}else r.push(e)}if(n)for(let t of n)if(r.every(e=>_f(t,e)))throw new Error(`whole-script confusable: ${e.N}/${t.N}`)}(o,n),e=o.N}else e="Emoji"}i.type=e}catch(e){i.error=e}return i})}function oh(e){return new Error(`disallowed character: ${Xf(e)}`)}function ih(e,t){let n=Xf(t),r=Wf.find(e=>e.P.has(t));return r&&(n=`${r.N} ${n}`),new Error(`illegal mixture: ${e.N} + ${n}`)}function sh(e){return new Error(`illegal placement: ${e}`)}function ah(e){return e.filter(e=>65039!=e)}function ch(e,t){let n,r=Zf,o=e.length;for(;o&&(r=r.get(e[--o]),r);){let{V:i}=r;i&&(n=i,t&&t.push(...e.slice(o).reverse()),e.length=o)}return n}const uh=new Uint8Array(32);function lh(e){return oe(0!==e.length,"invalid ENS name; empty component","comp",e),e}function fh(e){const t=xe(function(e){try{if(0===e.length)throw new Error("empty label");return function(e){return function(e){return e.map(({input:t,error:n,output:r})=>{if(n){let r=n.message;throw new Error(1==e.length?r:`Invalid label ${eh(th(t,63))}: ${r}`)}return vf(r)}).join(".")}(rh(e,Lf,ah))}(e)}catch(t){oe(!1,`invalid ENS name (${t.message})`,"name",e)}}(e)),n=[];if(0===e.length)return n;let r=0;for(let e=0;e<t.length;e++)46===t[e]&&(n.push(lh(t.slice(r,e))),r=e+1);return oe(r<t.length,"invalid ENS name; empty component","name",e),n.push(lh(t.slice(r))),n}function hh(e){oe("string"==typeof e,"invalid ENS name; not a string","name",e),oe(e.length,"invalid ENS name (empty label)","name",e);let t=uh;const n=fh(e);for(;n.length;)t=Vt(ye([t,Vt(n.pop())]));return ge(t)}function dh(e,t){const n=null!=t?t:63;return oe(n<=255,"DNS encoded label cannot exceed 255","length",n),ge(ye(fh(e).map(t=>{oe(t.length<=n,`label ${JSON.stringify(e)} exceeds ${n} bytes`,"name",e);const r=new Uint8Array(t.length+1);return r.set(t,1),r[0]=r.length-1,r})))+"00"}uh.fill(0),BigInt(0);const ph=BigInt(1),gh=BigInt(2),yh=e=>e instanceof Uint8Array,mh=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function wh(e){if(!yh(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=mh[e[n]];return t}function bh(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function vh(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let t=0;t<n.length;t++){const r=2*t,o=e.slice(r,r+2),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[t]=i}return n}function Eh(e){return bh(wh(e))}function Ah(e){if(!yh(e))throw new Error("Uint8Array expected");return bh(wh(Uint8Array.from(e).reverse()))}function xh(e,t){return vh(e.toString(16).padStart(2*t,"0"))}function kh(e,t){return xh(e,t).reverse()}function Sh(e,t,n){let r;if("string"==typeof t)try{r=vh(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!yh(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const o=r.length;if("number"==typeof n&&o!==n)throw new Error(`${e} expected ${n} bytes, got ${o}`);return r}function Ih(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!yh(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const Ch=e=>(gh<<BigInt(e-1))-ph,Oh=e=>new Uint8Array(e),Th=e=>Uint8Array.from(e);function Nh(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=Oh(e),o=Oh(e),i=0;const s=()=>{r.fill(1),o.fill(0),i=0},a=(...e)=>n(o,r,...e),c=(e=Oh())=>{o=a(Th([0]),e),r=a(),0!==e.length&&(o=a(Th([1]),e),r=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=a();const t=r.slice();n.push(t),e+=r.length}return Ih(...n)};return(e,t)=>{let n;for(s(),c(e);!(n=t(u()));)c();return s(),n}}const Ph={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function Bh(e,t,n={}){const r=(t,n,r)=>{const o=Ph[n];if("function"!=typeof o)throw new Error(`Invalid validator "${n}", expected function`);const i=e[t];if(!(r&&void 0===i||o(i,e)))throw new Error(`Invalid param ${String(t)}=${i} (${typeof i}), expected ${n}`)};for(const[e,n]of Object.entries(t))r(e,n,!1);for(const[e,t]of Object.entries(n))r(e,t,!0);return e}const Rh=BigInt(0),Uh=BigInt(1),Dh=BigInt(2),Lh=BigInt(3),Fh=BigInt(4),_h=BigInt(5),Mh=BigInt(8);function Gh(e,t){const n=e%t;return n>=Rh?n:t+n}function jh(e,t,n){if(n<=Rh||t<Rh)throw new Error("Expected power/modulo > 0");if(n===Uh)return Rh;let r=Uh;for(;t>Rh;)t&Uh&&(r=r*e%n),e=e*e%n,t>>=Uh;return r}function Hh(e,t,n){let r=e;for(;t-- >Rh;)r*=r,r%=n;return r}function zh(e,t){if(e===Rh||t<=Rh)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Gh(e,t),r=t,o=Rh,i=Uh,s=Uh,a=Rh;for(;n!==Rh;){const e=r/n,t=r%n,c=o-s*e,u=i-a*e;r=n,n=t,o=s,i=a,s=c,a=u}if(r!==Uh)throw new Error("invert: does not exist");return Gh(o,t)}BigInt(9),BigInt(16);const Vh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Kh(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Wh(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function $h(e){const t=Wh(e);return t+Math.ceil(t/2)}const qh=BigInt(0),Jh=BigInt(1);function Qh(e){return Bh(e.Fp,Vh.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),Bh(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Kh(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}const{Ph:Zh,aT:Yh}=i,Xh={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=Xh;if(e.length<2||2!==e[0])throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Zh(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Xh,n="string"==typeof e?Yh(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:o,l:i}=Xh._parseInt(n.subarray(2)),{d:s,l:a}=Xh._parseInt(i);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:o,s}},hexFromSig(e){const t=e=>8&Number.parseInt(e[0],16)?"00"+e:e,n=e=>{const t=e.toString(16);return 1&t.length?`0${t}`:t},r=t(n(e.s)),o=t(n(e.r)),i=r.length/2,s=o.length/2,a=n(i),c=n(s);return`30${n(s+i+4)}02${c}${o}02${a}${r}`}},ed=BigInt(0),td=BigInt(1),nd=(BigInt(2),BigInt(3));function rd(e){const t=function(e){const t=Qh(e);return Bh(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:n,n:r}=t,o=n.BYTES+1,i=2*n.BYTES+1;function s(e){return Gh(e,r)}function a(e){return zh(e,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=function(e){const t=function(e){const t=Qh(e);Bh(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:o}=t;if(n){if(!r.eql(o,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:n}=t,r=t.toBytes||((e,t,r)=>{const o=t.toAffine();return Ih(Uint8Array.from([4]),n.toBytes(o.x),n.toBytes(o.y))}),o=t.fromBytes||(e=>{const t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function i(e){const{a:r,b:o}=t,i=n.sqr(e),s=n.mul(i,e);return n.add(n.add(s,n.mul(e,r)),o)}if(!n.eql(n.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function s(e){return"bigint"==typeof e&&ed<e&&e<t.n}function a(e){if(!s(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:o,n:i}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=wh(e)),"string"!=typeof e||!n.includes(e.length))throw new Error("Invalid key");e=e.padStart(2*r,"0")}let s;try{s="bigint"==typeof e?e:Eh(Sh("private key",e,r))}catch(t){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return o&&(s=Gh(s,i)),a(s),s}const u=new Map;function l(e){if(!(e instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(e,t,r){if(this.px=e,this.py=t,this.pz=r,null==e||!n.isValid(e))throw new Error("x required");if(null==t||!n.isValid(t))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof f)throw new Error("projective point not allowed");const o=e=>n.eql(e,n.ZERO);return o(t)&&o(r)?f.ZERO:new f(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)}static fromHex(e){const t=f.fromAffine(o(Sh("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return f.BASE.multiply(c(e))}_setWindowSize(e){this._WINDOW_SIZE=e,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:e,y:r}=this.toAffine();if(!n.isValid(e)||!n.isValid(r))throw new Error("bad point: x or y not FE");const o=n.sqr(r),s=i(e);if(!n.eql(o,s))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){l(e);const{px:t,py:r,pz:o}=this,{px:i,py:s,pz:a}=e,c=n.eql(n.mul(t,a),n.mul(i,o)),u=n.eql(n.mul(r,a),n.mul(s,o));return c&&u}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,o=n.mul(r,nd),{px:i,py:s,pz:a}=this;let c=n.ZERO,u=n.ZERO,l=n.ZERO,h=n.mul(i,i),d=n.mul(s,s),p=n.mul(a,a),g=n.mul(i,s);return g=n.add(g,g),l=n.mul(i,a),l=n.add(l,l),c=n.mul(e,l),u=n.mul(o,p),u=n.add(c,u),c=n.sub(d,u),u=n.add(d,u),u=n.mul(c,u),c=n.mul(g,c),l=n.mul(o,l),p=n.mul(e,p),g=n.sub(h,p),g=n.mul(e,g),g=n.add(g,l),l=n.add(h,h),h=n.add(l,h),h=n.add(h,p),h=n.mul(h,g),u=n.add(u,h),p=n.mul(s,a),p=n.add(p,p),h=n.mul(p,g),c=n.sub(c,h),l=n.mul(p,d),l=n.add(l,l),l=n.add(l,l),new f(c,u,l)}add(e){l(e);const{px:r,py:o,pz:i}=this,{px:s,py:a,pz:c}=e;let u=n.ZERO,h=n.ZERO,d=n.ZERO;const p=t.a,g=n.mul(t.b,nd);let y=n.mul(r,s),m=n.mul(o,a),w=n.mul(i,c),b=n.add(r,o),v=n.add(s,a);b=n.mul(b,v),v=n.add(y,m),b=n.sub(b,v),v=n.add(r,i);let E=n.add(s,c);return v=n.mul(v,E),E=n.add(y,w),v=n.sub(v,E),E=n.add(o,i),u=n.add(a,c),E=n.mul(E,u),u=n.add(m,w),E=n.sub(E,u),d=n.mul(p,v),u=n.mul(g,w),d=n.add(u,d),u=n.sub(m,d),d=n.add(m,d),h=n.mul(u,d),m=n.add(y,y),m=n.add(m,y),w=n.mul(p,w),v=n.mul(g,v),m=n.add(m,w),w=n.sub(y,w),w=n.mul(p,w),v=n.add(v,w),y=n.mul(m,v),h=n.add(h,y),y=n.mul(E,v),u=n.mul(b,u),u=n.sub(u,y),y=n.mul(b,m),d=n.mul(E,d),d=n.add(d,y),new f(u,h,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(f.ZERO)}wNAF(e){return d.wNAFCached(this,u,e,e=>{const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)})}multiplyUnsafe(e){const r=f.ZERO;if(e===ed)return r;if(a(e),e===td)return this;const{endo:o}=t;if(!o)return d.unsafeLadder(this,e);let{k1neg:i,k1:s,k2neg:c,k2:u}=o.splitScalar(e),l=r,h=r,p=this;for(;s>ed||u>ed;)s&td&&(l=l.add(p)),u&td&&(h=h.add(p)),p=p.double(),s>>=td,u>>=td;return i&&(l=l.negate()),c&&(h=h.negate()),h=new f(n.mul(h.px,o.beta),h.py,h.pz),l.add(h)}multiply(e){a(e);let r,o,i=e;const{endo:s}=t;if(s){const{k1neg:e,k1:t,k2neg:a,k2:c}=s.splitScalar(i);let{p:u,f:l}=this.wNAF(t),{p:h,f:p}=this.wNAF(c);u=d.constTimeNegate(e,u),h=d.constTimeNegate(a,h),h=new f(n.mul(h.px,s.beta),h.py,h.pz),r=u.add(h),o=l.add(p)}else{const{p:e,f:t}=this.wNAF(i);r=e,o=t}return f.normalizeZ([r,o])[0]}multiplyAndAddUnsafe(e,t,n){const r=f.BASE,o=(e,t)=>t!==ed&&t!==td&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),i=o(this,t).add(o(e,n));return i.is0()?void 0:i}toAffine(e){const{px:t,py:r,pz:o}=this,i=this.is0();null==e&&(e=i?n.ONE:n.inv(o));const s=n.mul(t,e),a=n.mul(r,e),c=n.mul(o,e);if(i)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:s,y:a}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===td)return!0;if(n)return n(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:n}=t;return e===td?this:n?n(f,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(f,this,e)}toHex(e=!0){return wh(this.toRawBytes(e))}}f.BASE=new f(t.Gx,t.Gy,n.ONE),f.ZERO=new f(n.ZERO,n.ONE,n.ZERO);const h=t.nBitLength,d=function(e,t){const n=(e,t)=>{const n=t.negate();return e?n:t},r=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:n,unsafeLadder(t,n){let r=e.ZERO,o=t;for(;n>qh;)n&Jh&&(r=r.add(o)),o=o.double(),n>>=Jh;return r},precomputeWindow(e,t){const{windows:n,windowSize:o}=r(t),i=[];let s=e,a=s;for(let e=0;e<n;e++){a=s,i.push(a);for(let e=1;e<o;e++)a=a.add(s),i.push(a);s=a.double()}return i},wNAF(t,o,i){const{windows:s,windowSize:a}=r(t);let c=e.ZERO,u=e.BASE;const l=BigInt(2**t-1),f=2**t,h=BigInt(t);for(let e=0;e<s;e++){const t=e*a;let r=Number(i&l);i>>=h,r>a&&(r-=f,i+=Jh);const s=t,d=t+Math.abs(r)-1,p=e%2!=0,g=r<0;0===r?u=u.add(n(p,o[s])):c=c.add(n(g,o[d]))}return{p:c,f:u}},wNAFCached(e,t,n,r){const o=e._WINDOW_SIZE||1;let i=t.get(e);return i||(i=this.precomputeWindow(e,o),1!==o&&t.set(e,r(i))),this.wNAF(o,i,n)}}}(f,t.endo?Math.ceil(h/2):h);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}({...t,toBytes(e,t,r){const o=t.toAffine(),i=n.toBytes(o.x),s=Ih;return r?s(Uint8Array.from([t.hasEvenY()?2:3]),i):s(Uint8Array.from([4]),i,n.toBytes(o.y))},fromBytes(e){const t=e.length,r=e[0],s=e.subarray(1);if(t!==o||2!==r&&3!==r){if(t===i&&4===r)return{x:n.fromBytes(s.subarray(0,n.BYTES)),y:n.fromBytes(s.subarray(n.BYTES,2*n.BYTES))};throw new Error(`Point of length ${t} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}{const e=Eh(s);if(!(ed<(a=e)&&a<n.ORDER))throw new Error("Point is not on curve");const t=l(e);let o=n.sqrt(t);return!(1&~r)!=((o&td)===td)&&(o=n.neg(o)),{x:e,y:o}}var a}}),h=e=>wh(xh(e,t.nByteLength));function d(e){return e>r>>td}const p=(e,t,n)=>Eh(e.slice(t,n));class g{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=Sh("compactSignature",e,2*n),new g(p(e,0,n),p(e,n,2*n))}static fromDER(e){const{r:t,s:n}=Xh.toSig(Sh("DER",e));return new g(t,n)}assertValidity(){if(!f(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!f(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(e){return new g(this.r,this.s,e)}recoverPublicKey(e){const{r,s:o,recovery:i}=this,u=b(Sh("msgHash",e));if(null==i||![0,1,2,3].includes(i))throw new Error("recovery id invalid");const l=2===i||3===i?r+t.n:r;if(l>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const f=1&i?"03":"02",d=c.fromHex(f+h(l)),p=a(l),g=s(-u*p),y=s(o*p),m=c.BASE.multiplyAndAddUnsafe(d,g,y);if(!m)throw new Error("point at infinify");return m.assertValidity(),m}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return vh(this.toDERHex())}toDERHex(){return Xh.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return vh(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const y={isValidPrivateKey(e){try{return u(e),!0}catch(e){return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const e=$h(t.n);return function(e,t,n=!1){const r=e.length,o=Wh(t),i=$h(t);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const s=Gh(n?Eh(e):Ah(e),t-Uh)+Uh;return n?kh(s,o):xh(s,o)}(t.randomBytes(e),t.n)},precompute:(e=8,t=c.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function m(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===o||r===i:n?r===2*o||r===2*i:e instanceof c}const w=t.bits2int||function(e){const n=Eh(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},b=t.bits2int_modN||function(e){return s(w(e))},v=Ch(t.nBitLength);function E(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(ed<=e&&e<v))throw new Error(`bigint expected < 2^${t.nBitLength}`);return xh(e,t.nByteLength)}const A={lowS:t.lowS,prehash:!1},x={lowS:t.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return c.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(m(e))throw new Error("first arg must be private key");if(!m(t))throw new Error("second arg must be public key");return c.fromHex(t).multiply(u(e)).toRawBytes(n)},sign:function(e,r,o=A){const{seed:i,k2sig:l}=function(e,r,o=A){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");const{hash:i,randomBytes:l}=t;let{lowS:h,prehash:p,extraEntropy:y}=o;null==h&&(h=!0),e=Sh("msgHash",e),p&&(e=Sh("prehashed msgHash",i(e)));const m=b(e),v=u(r),x=[E(v),E(m)];if(null!=y){const e=!0===y?l(n.BYTES):y;x.push(Sh("extraEntropy",e))}const k=Ih(...x),S=m;return{seed:k,k2sig:function(e){const t=w(e);if(!f(t))return;const n=a(t),r=c.BASE.multiply(t).toAffine(),o=s(r.x);if(o===ed)return;const i=s(n*s(S+o*v));if(i===ed)return;let u=(r.x===o?0:2)|Number(r.y&td),l=i;return h&&d(i)&&(l=function(e){return d(e)?s(-e):e}(i),u^=1),new g(o,l,u)}}}(e,r,o),h=t;return Nh(h.hash.outputLen,h.nByteLength,h.hmac)(i,l)},verify:function(e,n,r,o=x){const i=e;if(n=Sh("msgHash",n),r=Sh("publicKey",r),"strict"in o)throw new Error("options.strict was renamed to lowS");const{lowS:u,prehash:l}=o;let f,h;try{if("string"==typeof i||i instanceof Uint8Array)try{f=g.fromDER(i)}catch(e){if(!(e instanceof Xh.Err))throw e;f=g.fromCompact(i)}else{if("object"!=typeof i||"bigint"!=typeof i.r||"bigint"!=typeof i.s)throw new Error("PARSE");{const{r:e,s:t}=i;f=new g(e,t)}}h=c.fromHex(r)}catch(e){if("PARSE"===e.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(u&&f.hasHighS())return!1;l&&(n=t.hash(n));const{r:d,s:p}=f,y=b(n),m=a(p),w=s(y*m),v=s(d*m),E=c.BASE.multiplyAndAddUnsafe(h,w,v)?.toAffine();return!!E&&s(E.x)===d},ProjectivePoint:c,Signature:g,utils:y}}function od(e){return{hash:e,hmac:(t,...n)=>Ve(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!Pe(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:He}}BigInt(4);const id=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),sd=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ad=BigInt(1),cd=BigInt(2),ud=(e,t)=>(e+t/cd)/t;const ld=function(e,t,n=!1,r={}){if(e<=Rh)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:o,nByteLength:i}=Kh(e,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=function(e){if(e%Fh===Lh){const t=(e+Uh)/Fh;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%Mh===_h){const t=(e-_h)/Mh;return function(e,n){const r=e.mul(n,Dh),o=e.pow(r,t),i=e.mul(n,o),s=e.mul(e.mul(i,Dh),o),a=e.mul(i,e.sub(s,e.ONE));if(!e.eql(e.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-Uh)/Dh;let n,r,o;for(n=e-Uh,r=0;n%Dh===Rh;n/=Dh,r++);for(o=Dh;o<e&&jh(o,t,e)!==e-Uh;o++);if(1===r){const t=(e+Uh)/Fh;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const i=(n+Uh)/Dh;return function(e,s){if(e.pow(s,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,c=e.pow(e.mul(e.ONE,o),n),u=e.pow(s,i),l=e.pow(s,n);for(;!e.eql(l,e.ONE);){if(e.eql(l,e.ZERO))return e.ZERO;let t=1;for(let n=e.sqr(l);t<a&&!e.eql(n,e.ONE);t++)n=e.sqr(n);const n=e.pow(c,Uh<<BigInt(a-t-1));c=e.sqr(n),u=e.mul(u,n),l=e.mul(l,c),a=t}return u}}(e)}(e),a=Object.freeze({ORDER:e,BITS:o,BYTES:i,MASK:Ch(o),ZERO:Rh,ONE:Uh,create:t=>Gh(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return Rh<=t&&t<e},is0:e=>e===Rh,isOdd:e=>(e&Uh)===Uh,neg:t=>Gh(-t,e),eql:(e,t)=>e===t,sqr:t=>Gh(t*t,e),add:(t,n)=>Gh(t+n,e),sub:(t,n)=>Gh(t-n,e),mul:(t,n)=>Gh(t*n,e),pow:(e,t)=>function(e,t,n){if(n<Rh)throw new Error("Expected power > 0");if(n===Rh)return e.ONE;if(n===Uh)return t;let r=e.ONE,o=t;for(;n>Rh;)n&Uh&&(r=e.mul(r,o)),o=e.sqr(o),n>>=Uh;return r}(a,e,t),div:(t,n)=>Gh(t*zh(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>zh(t,e),sqrt:r.sqrt||(e=>s(a,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce((t,r,o)=>e.is0(r)?t:(n[o]=t,e.mul(t,r)),e.ONE),o=e.inv(r);return t.reduceRight((t,r,o)=>e.is0(r)?t:(n[o]=e.mul(t,n[o]),e.mul(t,r)),o),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?kh(e,i):xh(e,i),fromBytes:e=>{if(e.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${e.length}`);return n?Ah(e):Eh(e)}});return Object.freeze(a)}(id,void 0,void 0,{sqrt:function(e){const t=id,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=Hh(l,n,t)*l%t,h=Hh(f,n,t)*l%t,d=Hh(h,cd,t)*u%t,p=Hh(d,o,t)*d%t,g=Hh(p,i,t)*p%t,y=Hh(g,a,t)*g%t,m=Hh(y,c,t)*y%t,w=Hh(m,a,t)*g%t,b=Hh(w,n,t)*l%t,v=Hh(b,s,t)*p%t,E=Hh(v,r,t)*u%t,A=Hh(E,cd,t);if(!ld.eql(ld.sqr(A),e))throw new Error("Cannot find square root");return A}}),fd=function(e,t){const n=t=>rd({...e,...od(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:ld,n:sd,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=sd,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-ad*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),a=ud(i*e,t),c=ud(-r*e,t);let u=Gh(e-a*n-c*o,t),l=Gh(-a*r-c*i,t);const f=u>s,h=l>s;if(f&&(u=t-u),h&&(l=t-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},Xe);BigInt(0),fd.ProjectivePoint;class hd{#re;constructor(e){oe(32===me(e),"invalid private key","privateKey","[REDACTED]"),this.#re=ge(e)}get privateKey(){return this.#re}get publicKey(){return hd.computePublicKey(this.#re)}get compressedPublicKey(){return hd.computePublicKey(this.#re,!0)}sign(e){oe(32===me(e),"invalid digest length","digest",e);const t=fd.sign(fe(e),fe(this.#re),{lowS:!0});return Zu.from({r:Na(t.r,32),s:Na(t.s,32),v:t.recovery?28:27})}computeSharedSecret(e){const t=hd.computePublicKey(e);return ge(fd.getSharedSecret(fe(this.#re),le(t),!1))}static computePublicKey(e,t){let n=le(e,"key");if(32===n.length)return ge(fd.getPublicKey(n,!!t));if(64===n.length){const e=new Uint8Array(65);e[0]=4,e.set(n,1),n=e}return ge(fd.ProjectivePoint.fromHex(n).toRawBytes(t))}static recoverPublicKey(e,t){oe(32===me(e),"invalid digest length","digest",e);const n=Zu.from(t);let r=fd.Signature.fromCompact(fe(ye([n.r,n.s])));r=r.addRecoveryBit(n.yParity);const o=r.recoverPublicKey(fe(e));return oe(null!=o,"invalid signature for digest","signature",t),"0x"+o.toHex(!1)}static addPoints(e,t,n){const r=fd.ProjectivePoint.fromHex(hd.computePublicKey(e).substring(2)),o=fd.ProjectivePoint.fromHex(hd.computePublicKey(t).substring(2));return"0x"+r.add(o).toHex(!!n)}}function dd(e){let t=e.toString(16);for(;t.length<2;)t="0"+t;return"0x"+t}function pd(e,t,n){let r=0;for(let o=0;o<n;o++)r=256*r+e[t+o];return r}function gd(e,t,n,r){const o=[];for(;n<t+1+r;){const i=yd(e,n);o.push(i.result),re((n+=i.consumed)<=t+1+r,"child data too short","BUFFER_OVERRUN",{buffer:e,length:r,offset:t})}return{consumed:1+r,result:o}}function yd(e,t){re(0!==e.length,"data too short","BUFFER_OVERRUN",{buffer:e,length:0,offset:1});const n=t=>{re(t<=e.length,"data short segment too short","BUFFER_OVERRUN",{buffer:e,length:e.length,offset:t})};if(e[t]>=248){const r=e[t]-247;n(t+1+r);const o=pd(e,t+1,r);return n(t+1+r+o),gd(e,t,t+1+r,r+o)}if(e[t]>=192){const r=e[t]-192;return n(t+1+r),gd(e,t,t+1,r)}if(e[t]>=184){const r=e[t]-183;n(t+1+r);const o=pd(e,t+1,r);return n(t+1+r+o),{consumed:1+r+o,result:ge(e.slice(t+1+r,t+1+r+o))}}if(e[t]>=128){const r=e[t]-128;return n(t+1+r),{consumed:1+r,result:ge(e.slice(t+1,t+1+r))}}return{consumed:1,result:dd(e[t])}}function md(e){const t=le(e,"data"),n=yd(t,0);return oe(n.consumed===t.length,"unexpected junk after rlp payload","data",e),n.result}function wd(e){const t=[];for(;e;)t.unshift(255&e),e>>=8;return t}function bd(e){if(Array.isArray(e)){let t=[];if(e.forEach(function(e){t=t.concat(bd(e))}),t.length<=55)return t.unshift(192+t.length),t;const n=wd(t.length);return n.unshift(247+n.length),n.concat(t)}const t=Array.prototype.slice.call(le(e,"object"));if(1===t.length&&t[0]<=127)return t;if(t.length<=55)return t.unshift(128+t.length),t;const n=wd(t.length);return n.unshift(183+n.length),n.concat(t)}const vd="0123456789abcdef";function Ed(e){let t="0x";for(const n of bd(e))t+=vd[n>>4],t+=vd[15&n];return t}function Ad(e){let t;return t="string"==typeof e?hd.computePublicKey(e,!1):e.publicKey,Ya(Vt("0x"+t.substring(4)).substring(26))}function xd(e,t){return Ad(hd.recoverPublicKey(e,t))}const kd=BigInt(0),Sd=BigInt(2),Id=BigInt(27),Cd=BigInt(28),Od=BigInt(35),Td=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Nd=Symbol.for("nodejs.util.inspect.custom"),Pd=131072,Bd=128;function Rd(e,t){let n=e.toString(16);for(;n.length<2;)n="0"+n;return n+=kt(t).substring(4),"0x"+n}function Ud(e){return"0x"===e?null:Ya(e)}function Dd(e,t){try{return _u(e)}catch(n){oe(!1,n.message,t,e)}}function Ld(e,t){try{if(!Array.isArray(e))throw new Error("authorizationList: invalid array");const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(!Array.isArray(r))throw new Error(`authorization[${n}]: invalid array`);if(6!==r.length)throw new Error(`authorization[${n}]: wrong length`);if(!r[1])throw new Error(`authorization[${n}]: null address`);t.push({address:Ud(r[1]),nonce:_d(r[2],"nonce"),chainId:_d(r[0],"chainId"),signature:Zu.from({yParity:Fd(r[3],"yParity"),r:ve(r[4],32),s:ve(r[5],32)})})}return t}catch(n){oe(!1,n.message,t,e)}}function Fd(e,t){return"0x"===e?0:Ta(e,t)}function _d(e,t){if("0x"===e)return kd;const n=Sa(e,t);return oe(n<=Td,"value exceeds uint size",t,n),n}function Md(e,t){const n=Sa(e,"value"),r=Pa(n);return oe(r.length<=32,"value too large",`tx.${t}`,n),r}function Gd(e){return _u(e).map(e=>[e.address,e.storageKeys])}function jd(e,t){oe(Array.isArray(e),`invalid ${t}`,"value",e);for(let t=0;t<e.length;t++)oe(he(e[t],32),"invalid ${ param } hash",`value[${t}]`,e[t]);return e}function Hd(e,t){let n;try{if(n=Fd(t[0],"yParity"),0!==n&&1!==n)throw new Error("bad yParity")}catch(e){oe(!1,"invalid yParity","yParity",t[0])}const r=ve(t[1],32),o=ve(t[2],32),i=Zu.from({r,s:o,yParity:n});e.signature=i}class zd{#oe;#ie;#t;#se;#ae;#ce;#ue;#le;#fe;#he;#de;#pe;#ge;#ye;#me;#we;#be;#ve;get type(){return this.#oe}set type(e){switch(e){case null:this.#oe=null;break;case 0:case"legacy":this.#oe=0;break;case 1:case"berlin":case"eip-2930":this.#oe=1;break;case 2:case"london":case"eip-1559":this.#oe=2;break;case 3:case"cancun":case"eip-4844":this.#oe=3;break;case 4:case"pectra":case"eip-7702":this.#oe=4;break;default:oe(!1,"unsupported transaction type","type",e)}}get typeName(){switch(this.type){case 0:return"legacy";case 1:return"eip-2930";case 2:return"eip-1559";case 3:return"eip-4844";case 4:return"eip-7702"}return null}get to(){const e=this.#ie;return null==e&&3===this.type?dl:e}set to(e){this.#ie=null==e?null:Ya(e)}get nonce(){return this.#se}set nonce(e){this.#se=Ta(e,"value")}get gasLimit(){return this.#ae}set gasLimit(e){this.#ae=Sa(e)}get gasPrice(){const e=this.#ce;return null!=e||0!==this.type&&1!==this.type?e:kd}set gasPrice(e){this.#ce=null==e?null:Sa(e,"gasPrice")}get maxPriorityFeePerGas(){const e=this.#ue;return null==e?2===this.type||3===this.type?kd:null:e}set maxPriorityFeePerGas(e){this.#ue=null==e?null:Sa(e,"maxPriorityFeePerGas")}get maxFeePerGas(){const e=this.#le;return null==e?2===this.type||3===this.type?kd:null:e}set maxFeePerGas(e){this.#le=null==e?null:Sa(e,"maxFeePerGas")}get data(){return this.#t}set data(e){this.#t=ge(e)}get value(){return this.#fe}set value(e){this.#fe=Sa(e,"value")}get chainId(){return this.#he}set chainId(e){this.#he=Sa(e)}get signature(){return this.#de||null}set signature(e){this.#de=null==e?null:Zu.from(e)}isValid(){const e=this.signature;if(e&&!e.isValid())return!1;const t=this.authorizationList;if(t)for(const e of t)if(!e.signature.isValid())return!1;return!0}get accessList(){const e=this.#pe||null;return null==e?1===this.type||2===this.type||3===this.type?[]:null:e}set accessList(e){this.#pe=null==e?null:_u(e)}get authorizationList(){const e=this.#be||null;return null==e&&4===this.type?[]:e}set authorizationList(e){this.#be=null==e?null:e.map(e=>Yu(e))}get maxFeePerBlobGas(){const e=this.#ge;return null==e&&3===this.type?kd:e}set maxFeePerBlobGas(e){this.#ge=null==e?null:Sa(e,"maxFeePerBlobGas")}get blobVersionedHashes(){let e=this.#ye;return null==e&&3===this.type?[]:e}set blobVersionedHashes(e){if(null!=e){oe(Array.isArray(e),"blobVersionedHashes must be an Array","value",e),e=e.slice();for(let t=0;t<e.length;t++)oe(he(e[t],32),"invalid blobVersionedHash",`value[${t}]`,e[t])}this.#ye=e}get blobs(){return null==this.#we?null:this.#we.map(e=>Object.assign({},e))}set blobs(e){if(null==e)return void(this.#we=null);const t=[],n=[];for(let r=0;r<e.length;r++){const o=e[r];if(de(o)){re(this.#me,"adding a raw blob requires a KZG library","UNSUPPORTED_OPERATION",{operation:"set blobs()"});let e=le(o);if(oe(e.length<=Pd,"blob is too large",`blobs[${r}]`,o),e.length!==Pd){const t=new Uint8Array(Pd);t.set(e),e=t}const i=this.#me.blobToKzgCommitment(e),s=ge(this.#me.computeBlobKzgProof(e,i));t.push({data:ge(e),commitment:ge(i),proof:s}),n.push(Rd(1,i))}else{const e=ge(o.data),r=ge(o.commitment),i=ge(o.proof);t.push({data:e,commitment:r,proof:i}),n.push(Rd(1,r))}}this.#we=t,this.#ye=n}get kzg(){return this.#me}set kzg(e){this.#me=null==e?null:function(e){return{blobToKzgCommitment:t=>{if("computeBlobProof"in e){if("blobToKzgCommitment"in e&&"function"==typeof e.blobToKzgCommitment)return le(e.blobToKzgCommitment(ge(t)))}else if("blobToKzgCommitment"in e&&"function"==typeof e.blobToKzgCommitment)return le(e.blobToKzgCommitment(t));if("blobToKZGCommitment"in e&&"function"==typeof e.blobToKZGCommitment)return le(e.blobToKZGCommitment(ge(t)));oe(!1,"unsupported KZG library","kzg",e)},computeBlobKzgProof:(t,n)=>"computeBlobProof"in e&&"function"==typeof e.computeBlobProof?le(e.computeBlobProof(ge(t),ge(n))):"computeBlobKzgProof"in e&&"function"==typeof e.computeBlobKzgProof?e.computeBlobKzgProof(t,n):"computeBlobKZGProof"in e&&"function"==typeof e.computeBlobKZGProof?le(e.computeBlobKZGProof(ge(t),ge(n))):void oe(!1,"unsupported KZG library","kzg",e)}}(e)}get blobWrapperVersion(){return this.#ve}set blobWrapperVersion(e){this.#ve=e}constructor(){this.#oe=null,this.#ie=null,this.#se=0,this.#ae=kd,this.#ce=null,this.#ue=null,this.#le=null,this.#t="0x",this.#fe=kd,this.#he=kd,this.#de=null,this.#pe=null,this.#ge=null,this.#ye=null,this.#me=null,this.#we=null,this.#be=null,this.#ve=null}get hash(){return null==this.signature?null:Vt(this.#Ee(!0,!1))}get unsignedHash(){return Vt(this.unsignedSerialized)}get from(){return null==this.signature?null:xd(this.unsignedHash,this.signature.getCanonical())}get fromPublicKey(){return null==this.signature?null:hd.recoverPublicKey(this.unsignedHash,this.signature.getCanonical())}isSigned(){return null!=this.signature}#Ee(e,t){re(!e||null!=this.signature,"cannot serialize unsigned transaction; maybe you meant .unsignedSerialized","UNSUPPORTED_OPERATION",{operation:".serialized"});const n=e?this.signature:null;switch(this.inferType()){case 0:return function(e,t){const n=[Md(e.nonce,"nonce"),Md(e.gasPrice||0,"gasPrice"),Md(e.gasLimit,"gasLimit"),e.to||"0x",Md(e.value,"value"),e.data];let r=kd;if(e.chainId!=kd)r=Sa(e.chainId,"tx.chainId"),oe(!t||null==t.networkV||t.legacyChainId===r,"tx.chainId/sig.v mismatch","sig",t);else if(e.signature){const t=e.signature.legacyChainId;null!=t&&(r=t)}if(!t)return r!==kd&&(n.push(Pa(r)),n.push("0x"),n.push("0x")),Ed(n);let o=BigInt(27+t.yParity);return r!==kd?o=Zu.getChainIdV(r,t.v):BigInt(t.v)!==o&&oe(!1,"tx.chainId/sig.v mismatch","sig",t),n.push(Pa(o)),n.push(Pa(t.r)),n.push(Pa(t._s)),Ed(n)}(this,n);case 1:return function(e,t){const n=[Md(e.chainId,"chainId"),Md(e.nonce,"nonce"),Md(e.gasPrice||0,"gasPrice"),Md(e.gasLimit,"gasLimit"),e.to||"0x",Md(e.value,"value"),e.data,Gd(e.accessList||[])];return t&&(n.push(Md(t.yParity,"recoveryParam")),n.push(Pa(t.r)),n.push(Pa(t.s))),ye(["0x01",Ed(n)])}(this,n);case 2:return function(e,t){const n=[Md(e.chainId,"chainId"),Md(e.nonce,"nonce"),Md(e.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),Md(e.maxFeePerGas||0,"maxFeePerGas"),Md(e.gasLimit,"gasLimit"),e.to||"0x",Md(e.value,"value"),e.data,Gd(e.accessList||[])];return t&&(n.push(Md(t.yParity,"yParity")),n.push(Pa(t.r)),n.push(Pa(t.s))),ye(["0x02",Ed(n)])}(this,n);case 3:return function(e,t,n){const r=[Md(e.chainId,"chainId"),Md(e.nonce,"nonce"),Md(e.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),Md(e.maxFeePerGas||0,"maxFeePerGas"),Md(e.gasLimit,"gasLimit"),e.to||dl,Md(e.value,"value"),e.data,Gd(e.accessList||[]),Md(e.maxFeePerBlobGas||0,"maxFeePerBlobGas"),jd(e.blobVersionedHashes||[],"blobVersionedHashes")];if(t&&(r.push(Md(t.yParity,"yParity")),r.push(Pa(t.r)),r.push(Pa(t.s)),n)){if(null!=e.blobWrapperVersion){const t=Pa(e.blobWrapperVersion),o=[];for(const{proof:e}of n){const t=le(e),n=t.length/Bd;for(let e=0;e<t.length;e+=n)o.push(t.subarray(e,e+n))}return ye(["0x03",Ed([r,t,n.map(e=>e.data),n.map(e=>e.commitment),o])])}return ye(["0x03",Ed([r,n.map(e=>e.data),n.map(e=>e.commitment),n.map(e=>e.proof)])])}return ye(["0x03",Ed(r)])}(this,n,t?this.blobs:null);case 4:return function(e,t){const n=[Md(e.chainId,"chainId"),Md(e.nonce,"nonce"),Md(e.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),Md(e.maxFeePerGas||0,"maxFeePerGas"),Md(e.gasLimit,"gasLimit"),e.to||"0x",Md(e.value,"value"),e.data,Gd(e.accessList||[]),(r=e.authorizationList||[],r.map(e=>[Md(e.chainId,"chainId"),e.address,Md(e.nonce,"nonce"),Md(e.signature.yParity,"yParity"),Pa(e.signature.r),Pa(e.signature._s)]))];var r;return t&&(n.push(Md(t.yParity,"yParity")),n.push(Pa(t.r)),n.push(Pa(t.s))),ye(["0x04",Ed(n)])}(this,n)}re(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:".serialized"})}get serialized(){return this.#Ee(!0,!0)}get unsignedSerialized(){return this.#Ee(!1,!1)}inferType(){const e=this.inferTypes();return e.indexOf(2)>=0?2:e.pop()}inferTypes(){const e=null!=this.gasPrice,t=null!=this.maxFeePerGas||null!=this.maxPriorityFeePerGas,n=null!=this.accessList,r=null!=this.#ge||this.#ye;null!=this.maxFeePerGas&&null!=this.maxPriorityFeePerGas&&re(this.maxFeePerGas>=this.maxPriorityFeePerGas,"priorityFee cannot be more than maxFee","BAD_DATA",{value:this}),re(!t||0!==this.type&&1!==this.type,"transaction type cannot have maxFeePerGas or maxPriorityFeePerGas","BAD_DATA",{value:this}),re(0!==this.type||!n,"legacy transaction cannot have accessList","BAD_DATA",{value:this});const o=[];return null!=this.type?o.push(this.type):this.authorizationList&&this.authorizationList.length?o.push(4):t?o.push(2):e?(o.push(1),n||o.push(0)):n?(o.push(1),o.push(2)):(r&&this.to||(o.push(0),o.push(1),o.push(2)),o.push(3)),o.sort(),o}isLegacy(){return 0===this.type}isBerlin(){return 1===this.type}isLondon(){return 2===this.type}isCancun(){return 3===this.type}clone(){return zd.from(this)}toJSON(){const e=e=>null==e?null:e.toString();return{type:this.type,to:this.to,data:this.data,nonce:this.nonce,gasLimit:e(this.gasLimit),gasPrice:e(this.gasPrice),maxPriorityFeePerGas:e(this.maxPriorityFeePerGas),maxFeePerGas:e(this.maxFeePerGas),value:e(this.value),chainId:e(this.chainId),sig:this.signature?this.signature.toJSON():null,accessList:this.accessList}}[Nd](){return this.toString()}toString(){const e=[],t=t=>{let n=this[t];"string"==typeof n&&(n=JSON.stringify(n)),e.push(`${t}: ${n}`)};this.type&&t("type"),t("to"),t("data"),t("nonce"),t("gasLimit"),t("value"),null!=this.chainId&&t("chainId"),this.signature&&(t("from"),e.push(`signature: ${this.signature.toString()}`));const n=this.authorizationList;if(n){const t=[];for(const e of n){const n=[];n.push(`address: ${JSON.stringify(e.address)}`),null!=e.nonce&&n.push(`nonce: ${e.nonce}`),null!=e.chainId&&n.push(`chainId: ${e.chainId}`),e.signature&&n.push(`signature: ${e.signature.toString()}`),t.push(`Authorization { ${n.join(", ")} }`)}e.push(`authorizations: [ ${t.join(", ")} ]`)}return`Transaction { ${e.join(", ")} }`}static from(e){if(null==e)return new zd;if("string"==typeof e){const t=le(e);if(t[0]>=127)return zd.from(function(e){const t=md(e);oe(Array.isArray(t)&&(9===t.length||6===t.length),"invalid field count for legacy transaction","data",e);const n={type:0,nonce:Fd(t[0],"nonce"),gasPrice:_d(t[1],"gasPrice"),gasLimit:_d(t[2],"gasLimit"),to:Ud(t[3]),value:_d(t[4],"value"),data:ge(t[5]),chainId:kd};if(6===t.length)return n;const r=_d(t[6],"v"),o=_d(t[7],"r"),i=_d(t[8],"s");if(o===kd&&i===kd)n.chainId=r;else{let e=(r-Od)/Sd;e<kd&&(e=kd),n.chainId=e,oe(e!==kd||r===Id||r===Cd,"non-canonical legacy v","v",t[6]),n.signature=Zu.from({r:ve(t[7],32),s:ve(t[8],32),v:r})}return n}(t));switch(t[0]){case 1:return zd.from(function(e){const t=md(le(e).slice(1));oe(Array.isArray(t)&&(8===t.length||11===t.length),"invalid field count for transaction type: 1","data",ge(e));const n={type:1,chainId:_d(t[0],"chainId"),nonce:Fd(t[1],"nonce"),gasPrice:_d(t[2],"gasPrice"),gasLimit:_d(t[3],"gasLimit"),to:Ud(t[4]),value:_d(t[5],"value"),data:ge(t[6]),accessList:Dd(t[7],"accessList")};return 8===t.length||Hd(n,t.slice(8)),n}(t));case 2:return zd.from(function(e){const t=md(le(e).slice(1));oe(Array.isArray(t)&&(9===t.length||12===t.length),"invalid field count for transaction type: 2","data",ge(e));const n={type:2,chainId:_d(t[0],"chainId"),nonce:Fd(t[1],"nonce"),maxPriorityFeePerGas:_d(t[2],"maxPriorityFeePerGas"),maxFeePerGas:_d(t[3],"maxFeePerGas"),gasPrice:null,gasLimit:_d(t[4],"gasLimit"),to:Ud(t[5]),value:_d(t[6],"value"),data:ge(t[7]),accessList:Dd(t[8],"accessList")};return 9===t.length||Hd(n,t.slice(9)),n}(t));case 3:return zd.from(function(e){let t=md(le(e).slice(1)),n="3",r=null,o=null;if(4===t.length&&Array.isArray(t[0])){n="3 (network format)";const e=t[1],r=t[2],i=t[3];oe(Array.isArray(e),"invalid network format: blobs not an array","fields[1]",e),oe(Array.isArray(r),"invalid network format: commitments not an array","fields[2]",r),oe(Array.isArray(i),"invalid network format: proofs not an array","fields[3]",i),oe(e.length===r.length,"invalid network format: blobs/commitments length mismatch","fields",t),oe(e.length===i.length,"invalid network format: blobs/proofs length mismatch","fields",t),o=[];for(let n=0;n<t[1].length;n++)o.push({data:e[n],commitment:r[n],proof:i[n]});t=t[0]}else if(5===t.length&&Array.isArray(t[0])){n="3 (EIP-7594 network format)",r=Ta(t[1]);const e=t[2],i=t[3],s=t[4];oe(1===r,`unsupported EIP-7594 network format version: ${r}`,"fields[1]",r),oe(Array.isArray(e),"invalid EIP-7594 network format: blobs not an array","fields[2]",e),oe(Array.isArray(i),"invalid EIP-7594 network format: commitments not an array","fields[3]",i),oe(Array.isArray(s),"invalid EIP-7594 network format: proofs not an array","fields[4]",s),oe(e.length===i.length,"invalid network format: blobs/commitments length mismatch","fields",t),oe(e.length*Bd===s.length,"invalid network format: blobs/proofs length mismatch","fields",t),o=[];for(let t=0;t<e.length;t++){const n=[];for(let e=0;e<Bd;e++)n.push(s[t*Bd+e]);o.push({data:e[t],commitment:i[t],proof:ye(n)})}t=t[0]}oe(Array.isArray(t)&&(11===t.length||14===t.length),`invalid field count for transaction type: ${n}`,"data",ge(e));const i={type:3,chainId:_d(t[0],"chainId"),nonce:Fd(t[1],"nonce"),maxPriorityFeePerGas:_d(t[2],"maxPriorityFeePerGas"),maxFeePerGas:_d(t[3],"maxFeePerGas"),gasPrice:null,gasLimit:_d(t[4],"gasLimit"),to:Ud(t[5]),value:_d(t[6],"value"),data:ge(t[7]),accessList:Dd(t[8],"accessList"),maxFeePerBlobGas:_d(t[9],"maxFeePerBlobGas"),blobVersionedHashes:t[10],blobWrapperVersion:r};o&&(i.blobs=o),oe(null!=i.to,`invalid address for transaction type: ${n}`,"data",e),oe(Array.isArray(i.blobVersionedHashes),"invalid blobVersionedHashes: must be an array","data",e);for(let t=0;t<i.blobVersionedHashes.length;t++)oe(he(i.blobVersionedHashes[t],32),`invalid blobVersionedHash at index ${t}: must be length 32`,"data",e);return 11===t.length||Hd(i,t.slice(11)),i}(t));case 4:return zd.from(function(e){const t=md(le(e).slice(1));oe(Array.isArray(t)&&(10===t.length||13===t.length),"invalid field count for transaction type: 4","data",ge(e));const n={type:4,chainId:_d(t[0],"chainId"),nonce:Fd(t[1],"nonce"),maxPriorityFeePerGas:_d(t[2],"maxPriorityFeePerGas"),maxFeePerGas:_d(t[3],"maxFeePerGas"),gasPrice:null,gasLimit:_d(t[4],"gasLimit"),to:Ud(t[5]),value:_d(t[6],"value"),data:ge(t[7]),accessList:Dd(t[8],"accessList"),authorizationList:Ld(t[9],"authorizationList")};return 10===t.length||Hd(n,t.slice(10)),n}(t))}re(!1,"unsupported transaction type","UNSUPPORTED_OPERATION",{operation:"from"})}const t=new zd;return null!=e.type&&(t.type=e.type),null!=e.to&&(t.to=e.to),null!=e.nonce&&(t.nonce=e.nonce),null!=e.gasLimit&&(t.gasLimit=e.gasLimit),null!=e.gasPrice&&(t.gasPrice=e.gasPrice),null!=e.maxPriorityFeePerGas&&(t.maxPriorityFeePerGas=e.maxPriorityFeePerGas),null!=e.maxFeePerGas&&(t.maxFeePerGas=e.maxFeePerGas),null!=e.maxFeePerBlobGas&&(t.maxFeePerBlobGas=e.maxFeePerBlobGas),null!=e.data&&(t.data=e.data),null!=e.value&&(t.value=e.value),null!=e.chainId&&(t.chainId=e.chainId),null!=e.signature&&(t.signature=Zu.from(e.signature)),null!=e.accessList&&(t.accessList=e.accessList),null!=e.authorizationList&&(t.authorizationList=e.authorizationList),null!=e.blobVersionedHashes&&(t.blobVersionedHashes=e.blobVersionedHashes),null!=e.kzg&&(t.kzg=e.kzg),null!=e.blobWrapperVersion&&(t.blobWrapperVersion=e.blobWrapperVersion),null!=e.blobs&&(t.blobs=e.blobs),null!=e.hash&&(oe(t.isSigned(),"unsigned transaction cannot define '.hash'","tx",e),oe(t.hash===e.hash,"hash mismatch","tx",e)),null!=e.from&&(oe(t.isSigned(),"unsigned transaction cannot define '.from'","tx",e),oe(t.from.toLowerCase()===(e.from||"").toLowerCase(),"from mismatch","tx",e)),t}}const Vd="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";let Kd=null;function Wd(e){if(null==Kd){Kd={};for(let e=0;e<58;e++)Kd[Vd[e]]=BigInt(e)}const t=Kd[e];return oe(null!=t,"invalid base58 value","letter",e),t}const $d=BigInt(0),qd=BigInt(58);function Jd(e){const t=le(e);let n=Oa(t),r="";for(;n;)r=Vd[Number(n%qd)]+r,n/=qd;for(let e=0;e<t.length&&!t[e];e++)r=Vd[0]+r;return r}function Qd(e){return e.match(/^ipfs:\/\/ipfs\//i)?e=e.substring(12):e.match(/^ipfs:\/\//i)?e=e.substring(7):oe(!1,"unsupported IPFS format","link",e),`https://gateway.ipfs.io/ipfs/${e}`}class Zd{name;constructor(e){Y(this,{name:e})}connect(e){return this}supportsCoinType(e){return!1}async encodeAddress(e,t){throw new Error("unsupported coin")}async decodeAddress(e,t){throw new Error("unsupported coin")}}const Yd=new RegExp("^(ipfs)://(.*)$","i"),Xd=[new RegExp("^(https)://(.*)$","i"),new RegExp("^(data):(.*)$","i"),Yd,new RegExp("^eip155:[0-9]+/(erc[0-9]+):(.*)$","i")];class ep{provider;address;name;#Ae;#xe;constructor(e,t,n){Y(this,{provider:e,address:t,name:n}),this.#Ae=null,this.#xe=new af(t,["function supportsInterface(bytes4) view returns (bool)","function resolve(bytes, bytes) view returns (bytes)","function addr(bytes32) view returns (address)","function addr(bytes32, uint) view returns (bytes)","function text(bytes32, string) view returns (string)","function contenthash(bytes32) view returns (bytes)"],e)}async supportsWildcard(){return null==this.#Ae&&(this.#Ae=(async()=>{try{return await this.#xe.supportsInterface("0x9061b923")}catch(e){if(ee(e,"CALL_EXCEPTION"))return!1;throw this.#Ae=null,e}})()),await this.#Ae}async#ke(e,t){t=(t||[]).slice();const n=this.#xe.interface;t.unshift(hh(this.name));let r=null;await this.supportsWildcard()&&(r=n.getFunction(e),re(r,"missing fragment","UNKNOWN_ERROR",{info:{funcName:e}}),t=[dh(this.name,255),n.encodeFunctionData(r,t)],e="resolve(bytes,bytes)"),t.push({enableCcipRead:!0});try{const o=await this.#xe[e](...t);return r?n.decodeFunctionResult(r,o)[0]:o}catch(e){if(!ee(e,"CALL_EXCEPTION"))throw e}return null}async getAddress(e){if(null==e&&(e=60),60===e)try{const e=await this.#ke("addr(bytes32)");return null==e||e===dl?null:e}catch(e){if(ee(e,"CALL_EXCEPTION"))return null;throw e}if(e>=0&&e<2147483648){let t=e+2147483648;const n=await this.#ke("addr(bytes32,uint)",[t]);if(he(n,20))return Ya(n)}let t=null;for(const n of this.provider.plugins)if(n instanceof Zd&&n.supportsCoinType(e)){t=n;break}if(null==t)return null;const n=await this.#ke("addr(bytes32,uint)",[e]);if(null==n||"0x"===n)return null;const r=await t.decodeAddress(e,n);if(null!=r)return r;re(!1,"invalid coin data","UNSUPPORTED_OPERATION",{operation:`getAddress(${e})`,info:{coinType:e,data:n}})}async getText(e){const t=await this.#ke("text(bytes32,string)",[e]);return null==t||"0x"===t?null:t}async getContentHash(){const e=await this.#ke("contenthash(bytes32)");if(null==e||"0x"===e)return null;const t=e.match(/^0x(e3010170|e5010172)(([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f]*))$/);if(t){const e="e3010170"===t[1]?"ipfs":"ipns",n=parseInt(t[4],16);if(t[5].length===2*n)return`${e}://${Jd("0x"+t[2])}`}const n=e.match(/^0xe40101fa011b20([0-9a-f]*)$/);if(n&&64===n[1].length)return`bzz://${n[1]}`;re(!1,"invalid or unsupported content hash data","UNSUPPORTED_OPERATION",{operation:"getContentHash()",info:{data:e}})}async getAvatar(){return(await this._getAvatar()).url}async _getAvatar(){const e=[{type:"name",value:this.name}];try{const t=await this.getText("avatar");if(null==t)return e.push({type:"!avatar",value:""}),{url:null,linkage:e};e.push({type:"avatar",value:t});for(let n=0;n<Xd.length;n++){const r=t.match(Xd[n]);if(null==r)continue;const o=r[1].toLowerCase();switch(o){case"https":case"data":return e.push({type:"url",value:t}),{linkage:e,url:t};case"ipfs":{const n=Qd(t);return e.push({type:"ipfs",value:t}),e.push({type:"url",value:n}),{linkage:e,url:n}}case"erc721":case"erc1155":{const n="erc721"===o?"tokenURI(uint256)":"uri(uint256)";e.push({type:o,value:t});const i=await this.getAddress();if(null==i)return e.push({type:"!owner",value:""}),{url:null,linkage:e};const s=(r[2]||"").split("/");if(2!==s.length)return e.push({type:`!${o}caip`,value:r[2]||""}),{url:null,linkage:e};const a=s[1],c=new af(s[0],["function tokenURI(uint) view returns (string)","function ownerOf(uint) view returns (address)","function uri(uint) view returns (string)","function balanceOf(address, uint256) view returns (uint)"],this.provider);if("erc721"===o){const t=await c.ownerOf(a);if(i!==t)return e.push({type:"!owner",value:t}),{url:null,linkage:e};e.push({type:"owner",value:t})}else if("erc1155"===o){const t=await c.balanceOf(i,a);if(!t)return e.push({type:"!balance",value:"0"}),{url:null,linkage:e};e.push({type:"balance",value:t.toString()})}let u=await c[n](a);if(null==u||"0x"===u)return e.push({type:"!metadata-url",value:""}),{url:null,linkage:e};e.push({type:"metadata-url-base",value:u}),"erc1155"===o&&(u=u.replace("{id}",Na(a,32).substring(2)),e.push({type:"metadata-url-expanded",value:u})),u.match(/^ipfs:/i)&&(u=Qd(u)),e.push({type:"metadata-url",value:u});let l={};const f=await new ll(u).send();f.assertOk();try{l=f.bodyJson}catch(t){try{e.push({type:"!metadata",value:f.bodyText})}catch(t){const n=f.body;return n&&e.push({type:"!metadata",value:ge(n)}),{url:null,linkage:e}}return{url:null,linkage:e}}if(!l)return e.push({type:"!metadata",value:""}),{url:null,linkage:e};e.push({type:"metadata",value:JSON.stringify(l)});let h=l.image;if("string"!=typeof h)return e.push({type:"!imageUrl",value:""}),{url:null,linkage:e};if(h.match(/^(https:\/\/|data:)/i));else{if(null==h.match(Yd))return e.push({type:"!imageUrl-ipfs",value:h}),{url:null,linkage:e};e.push({type:"imageUrl-ipfs",value:h}),h=Qd(h)}return e.push({type:"url",value:h}),{linkage:e,url:h}}}}}catch(e){}return{linkage:e,url:null}}static async getEnsAddress(e){const t=await e.getNetwork(),n=t.getPlugin("org.ethers.plugins.network.Ens");return re(n,"network does not support ENS","UNSUPPORTED_OPERATION",{operation:"getEnsAddress",info:{network:t}}),n.address}static async#Se(e,t){const n=await ep.getEnsAddress(e);try{const r=new af(n,["function resolver(bytes32) view returns (address)"],e),o=await r.resolver(hh(t),{enableCcipRead:!0});return o===dl?null:o}catch(e){throw e}}static async fromName(e,t){let n=t;for(;;){if(""===n||"."===n)return null;if("eth"!==t&&"eth"===n)return null;const r=await ep.#Se(e,n);if(null!=r){const o=new ep(e,r,t);return n===t||await o.supportsWildcard()?o:null}n=n.split(".").slice(1).join(".")}}}const tp=BigInt(0);function np(e,t){return function(n){return null==n?t:e(n)}}function rp(e,t){return n=>{if(t&&null==n)return null;if(!Array.isArray(n))throw new Error("not an array");return n.map(t=>e(t))}}function op(e,t){return n=>{const r={};for(const o in e){let i=o;if(t&&o in t&&!(i in n))for(const e of t[o])if(e in n){i=e;break}try{const t=e[o](n[i]);void 0!==t&&(r[o]=t)}catch(e){re(!1,`invalid value for value.${o} (${e instanceof Error?e.message:"not-an-error"})`,"BAD_DATA",{value:n})}}return r}}function ip(e){return oe(he(e,!0),"invalid data","value",e),e}function sp(e){return oe(he(e,32),"invalid hash","value",e),e}const ap=op({address:Ya,blockHash:sp,blockNumber:Ta,data:ip,index:Ta,removed:np(function(e){switch(e){case!0:case"true":return!0;case!1:case"false":return!1}oe(!1,`invalid boolean; ${JSON.stringify(e)}`,"value",e)},!1),topics:rp(sp),transactionHash:sp,transactionIndex:Ta},{index:["logIndex"]}),cp=op({hash:np(sp),parentHash:sp,parentBeaconBlockRoot:np(sp,null),number:Ta,timestamp:Ta,nonce:np(ip),difficulty:Sa,gasLimit:Sa,gasUsed:Sa,stateRoot:np(sp,null),receiptsRoot:np(sp,null),blobGasUsed:np(Sa,null),excessBlobGas:np(Sa,null),miner:np(Ya),prevRandao:np(sp,null),extraData:ip,baseFeePerGas:np(Sa)},{prevRandao:["mixHash"]}),up=op({transactionIndex:Ta,blockNumber:Ta,transactionHash:sp,address:Ya,topics:rp(sp),data:ip,index:Ta,blockHash:sp},{index:["logIndex"]}),lp=op({to:np(Ya,null),from:np(Ya,null),contractAddress:np(Ya,null),index:Ta,root:np(ge),gasUsed:Sa,blobGasUsed:np(Sa,null),logsBloom:np(ip),blockHash:sp,hash:sp,logs:rp(function(e){return up(e)}),blockNumber:Ta,cumulativeGasUsed:Sa,effectiveGasPrice:np(Sa),blobGasPrice:np(Sa,null),status:np(Ta),type:np(Ta,0)},{effectiveGasPrice:["gasPrice"],hash:["transactionHash"],index:["transactionIndex"]});function fp(e){e.to&&Sa(e.to)===tp&&(e.to="0x0000000000000000000000000000000000000000");const t=op({hash:sp,index:np(Ta,void 0),type:e=>"0x"===e||null==e?0:Ta(e),accessList:np(_u,null),blobVersionedHashes:np(rp(sp,!0),null),authorizationList:np(rp(e=>{let t;if(e.signature)t=e.signature;else{let n=e.yParity;"0x1b"===n?n=0:"0x1c"===n&&(n=1),t=Object.assign({},e,{yParity:n})}return{address:Ya(e.address),chainId:Sa(e.chainId),nonce:Sa(e.nonce),signature:Zu.from(t)}},!1),null),blockHash:np(sp,null),blockNumber:np(Ta,null),transactionIndex:np(Ta,null),from:Ya,gasPrice:np(Sa),maxPriorityFeePerGas:np(Sa),maxFeePerGas:np(Sa),maxFeePerBlobGas:np(Sa,null),gasLimit:Sa,to:np(Ya,null),value:Sa,nonce:Ta,data:ip,creates:np(Ya,null),chainId:np(Sa,null)},{data:["input"],gasLimit:["gas"],index:["transactionIndex"]})(e);if(null==t.to&&null==t.creates&&(t.creates=function(e){const t=Ya(e.from);let n=Sa(e.nonce,"tx.nonce").toString(16);return n="0"===n?"0x":n.length%2?"0x0"+n:"0x"+n,Ya(we(Vt(Ed([t,n])),12))}(t)),1!==e.type&&2!==e.type||null!=e.accessList||(t.accessList=[]),e.signature?t.signature=Zu.from(e.signature):t.signature=Zu.from(e),null==t.chainId){const e=t.signature.legacyChainId;null!=e&&(t.chainId=e)}return t.blockHash&&Sa(t.blockHash)===tp&&(t.blockHash=null),t}class hp{name;constructor(e){Y(this,{name:e})}clone(){return new hp(this.name)}}class dp extends hp{effectiveBlock;txBase;txCreate;txDataZero;txDataNonzero;txAccessListStorageKey;txAccessListAddress;constructor(e,t){null==e&&(e=0),super(`org.ethers.network.plugins.GasCost#${e||0}`);const n={effectiveBlock:e};function r(e,r){let o=(t||{})[e];null==o&&(o=r),oe("number"==typeof o,`invalud value for ${e}`,"costs",t),n[e]=o}r("txBase",21e3),r("txCreate",32e3),r("txDataZero",4),r("txDataNonzero",16),r("txAccessListStorageKey",1900),r("txAccessListAddress",2400),Y(this,n)}clone(){return new dp(this.effectiveBlock,this)}}class pp extends hp{address;targetNetwork;constructor(e,t){super("org.ethers.plugins.network.Ens"),Y(this,{address:e||"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",targetNetwork:null==t?1:t})}clone(){return new pp(this.address,this.targetNetwork)}}class gp extends hp{#N;#Ie;get url(){return this.#N}get processFunc(){return this.#Ie}constructor(e,t){super("org.ethers.plugins.network.FetchUrlFeeDataPlugin"),this.#N=e,this.#Ie=t}clone(){return this}}const yp=new Map;class mp{#Ce;#he;#Oe;constructor(e,t){this.#Ce=e,this.#he=Sa(t),this.#Oe=new Map}toJSON(){return{name:this.name,chainId:String(this.chainId)}}get name(){return this.#Ce}set name(e){this.#Ce=e}get chainId(){return this.#he}set chainId(e){this.#he=Sa(e,"chainId")}matches(e){if(null==e)return!1;if("string"==typeof e){try{return this.chainId===Sa(e)}catch(e){}return this.name===e}if("number"==typeof e||"bigint"==typeof e){try{return this.chainId===Sa(e)}catch(e){}return!1}if("object"==typeof e){if(null!=e.chainId){try{return this.chainId===Sa(e.chainId)}catch(e){}return!1}return null!=e.name&&this.name===e.name}return!1}get plugins(){return Array.from(this.#Oe.values())}attachPlugin(e){if(this.#Oe.get(e.name))throw new Error(`cannot replace existing plugin: ${e.name} `);return this.#Oe.set(e.name,e.clone()),this}getPlugin(e){return this.#Oe.get(e)||null}getPlugins(e){return this.plugins.filter(t=>t.name.split("#")[0]===e)}clone(){const e=new mp(this.name,this.chainId);return this.plugins.forEach(t=>{e.attachPlugin(t.clone())}),e}computeIntrinsicGas(e){const t=this.getPlugin("org.ethers.plugins.network.GasCost")||new dp;let n=t.txBase;if(null==e.to&&(n+=t.txCreate),e.data)for(let r=2;r<e.data.length;r+=2)"00"===e.data.substring(r,r+2)?n+=t.txDataZero:n+=t.txDataNonzero;if(e.accessList){const r=_u(e.accessList);for(const e in r)n+=t.txAccessListAddress+t.txAccessListStorageKey*r[e].storageKeys.length}return n}static from(e){if(function(){function e(e,t,n){const r=function(){const r=new mp(e,t);return null!=n.ensNetwork&&r.attachPlugin(new pp(null,n.ensNetwork)),r.attachPlugin(new dp),(n.plugins||[]).forEach(e=>{r.attachPlugin(e)}),r};mp.register(e,r),mp.register(t,r),n.altNames&&n.altNames.forEach(e=>{mp.register(e,r)})}vp||(vp=!0,e("mainnet",1,{ensNetwork:1,altNames:["homestead"]}),e("ropsten",3,{ensNetwork:3}),e("rinkeby",4,{ensNetwork:4}),e("goerli",5,{ensNetwork:5}),e("kovan",42,{ensNetwork:42}),e("sepolia",11155111,{ensNetwork:11155111}),e("holesky",17e3,{ensNetwork:17e3}),e("classic",61,{}),e("classicKotti",6,{}),e("arbitrum",42161,{ensNetwork:1}),e("arbitrum-goerli",421613,{}),e("arbitrum-sepolia",421614,{}),e("base",8453,{ensNetwork:1}),e("base-goerli",84531,{}),e("base-sepolia",84532,{}),e("bnb",56,{ensNetwork:1}),e("bnbt",97,{}),e("filecoin",314,{}),e("filecoin-calibration",314159,{}),e("linea",59144,{ensNetwork:1}),e("linea-goerli",59140,{}),e("linea-sepolia",59141,{}),e("matic",137,{ensNetwork:1,plugins:[bp("https://gasstation.polygon.technology/v2")]}),e("matic-amoy",80002,{}),e("matic-mumbai",80001,{altNames:["maticMumbai","maticmum"],plugins:[bp("https://gasstation-testnet.polygon.technology/v2")]}),e("optimism",10,{ensNetwork:1,plugins:[]}),e("optimism-goerli",420,{}),e("optimism-sepolia",11155420,{}),e("xdai",100,{ensNetwork:1}))}(),null==e)return mp.from("mainnet");if("number"==typeof e&&(e=BigInt(e)),"string"==typeof e||"bigint"==typeof e){const t=yp.get(e);if(t)return t();if("bigint"==typeof e)return new mp("unknown",e);oe(!1,"unknown network","network",e)}if("function"==typeof e.clone)return e.clone();if("object"==typeof e){oe("string"==typeof e.name&&"number"==typeof e.chainId,"invalid network object name or chainId","network",e);const t=new mp(e.name,e.chainId);return(e.ensAddress||null!=e.ensNetwork)&&t.attachPlugin(new pp(e.ensAddress,e.ensNetwork)),t}oe(!1,"invalid network","network",e)}static register(e,t){"number"==typeof e&&(e=BigInt(e));const n=yp.get(e);n&&oe(!1,`conflicting network for ${JSON.stringify(n.name)}`,"nameOrChainId",e),yp.set(e,t)}}function wp(e,t){const n=String(e);if(!n.match(/^[0-9.]+$/))throw new Error(`invalid gwei value: ${e}`);const r=n.split(".");if(1===r.length&&r.push(""),2!==r.length)throw new Error(`invalid gwei value: ${e}`);for(;r[1].length<t;)r[1]+="0";if(r[1].length>9){let e=BigInt(r[1].substring(0,9));r[1].substring(9).match(/^0+$/)||e++,r[1]=e.toString()}return BigInt(r[0]+r[1])}function bp(e){return new gp(e,async(e,t,n)=>{let r;n.setHeader("User-Agent","ethers");try{const[t,o]=await Promise.all([n.send(),e()]);r=t;const i=r.bodyJson.standard;return{gasPrice:o.gasPrice,maxFeePerGas:wp(i.maxFee,9),maxPriorityFeePerGas:wp(i.maxPriorityFee,9)}}catch(e){re(!1,`error encountered with polygon gas station (${JSON.stringify(n.url)})`,"SERVER_ERROR",{request:n,response:r,error:e})}})}let vp=!1;function Ep(e){return JSON.parse(JSON.stringify(e))}class Ap{#Te;#Ne;#Pe;#Be;constructor(e){this.#Te=e,this.#Ne=null,this.#Pe=4e3,this.#Be=-2}get pollingInterval(){return this.#Pe}set pollingInterval(e){this.#Pe=e}async#Re(){try{const e=await this.#Te.getBlockNumber();if(-2===this.#Be)return void(this.#Be=e);if(e!==this.#Be){for(let t=this.#Be+1;t<=e;t++){if(null==this.#Ne)return;await this.#Te.emit("block",t)}this.#Be=e}}catch(e){}null!=this.#Ne&&(this.#Ne=this.#Te._setTimeout(this.#Re.bind(this),this.#Pe))}start(){this.#Ne||(this.#Ne=this.#Te._setTimeout(this.#Re.bind(this),this.#Pe),this.#Re())}stop(){this.#Ne&&(this.#Te._clearTimeout(this.#Ne),this.#Ne=null)}pause(e){this.stop(),e&&(this.#Be=-2)}resume(){this.start()}}class xp{#Te;#Re;#Ue;constructor(e){this.#Te=e,this.#Ue=!1,this.#Re=e=>{this._poll(e,this.#Te)}}async _poll(e,t){throw new Error("sub-classes must override this")}start(){this.#Ue||(this.#Ue=!0,this.#Re(-2),this.#Te.on("block",this.#Re))}stop(){this.#Ue&&(this.#Ue=!1,this.#Te.off("block",this.#Re))}pause(e){this.stop()}resume(){this.start()}}class kp extends xp{#De;#Le;constructor(e,t){super(e),this.#De=t,this.#Le=-2}pause(e){e&&(this.#Le=-2),super.pause(e)}async _poll(e,t){const n=await t.getBlock(this.#De);null!=n&&(-2===this.#Le?this.#Le=n.number:n.number>this.#Le&&(t.emit(this.#De,n.number),this.#Le=n.number))}}class Sp extends xp{#ne;constructor(e,t){super(e),this.#ne=Ep(t)}async _poll(e,t){throw new Error("@TODO")}}class Ip extends xp{#Fe;constructor(e,t){super(e),this.#Fe=t}async _poll(e,t){const n=await t.getTransactionReceipt(this.#Fe);n&&t.emit(this.#Fe,n)}}class Cp{#Te;#ne;#Ne;#Ue;#Be;constructor(e,t){this.#Te=e,this.#ne=Ep(t),this.#Ne=this.#Re.bind(this),this.#Ue=!1,this.#Be=-2}async#Re(e){if(-2===this.#Be)return;const t=Ep(this.#ne);t.fromBlock=this.#Be+1,t.toBlock=e;const n=await this.#Te.getLogs(t);if(0!==n.length)for(const e of n)this.#Te.emit(this.#ne,e),this.#Be=e.blockNumber;else this.#Be<e-60&&(this.#Be=e-60)}start(){this.#Ue||(this.#Ue=!0,-2===this.#Be&&this.#Te.getBlockNumber().then(e=>{this.#Be=e}),this.#Te.on("block",this.#Ne))}stop(){this.#Ue&&(this.#Ue=!1,this.#Te.off("block",this.#Ne))}pause(e){this.stop(),e&&(this.#Be=-2)}resume(){this.start()}}const Op=BigInt(2);function Tp(e){return e&&"function"==typeof e.then}function Np(e,t){return e+":"+JSON.stringify(t,(e,t)=>{if(null==t)return"null";if("bigint"==typeof t)return`bigint:${t.toString()}`;if("string"==typeof t)return t.toLowerCase();if("object"==typeof t&&!Array.isArray(t)){const e=Object.keys(t);return e.sort(),e.reduce((e,n)=>(e[n]=t[n],e),{})}return t})}class Pp{name;constructor(e){Y(this,{name:e})}start(){}stop(){}pause(e){}resume(){}}function Bp(e){return(e=Array.from(new Set(e).values())).sort(),e}async function Rp(e,t){if(null==e)throw new Error("invalid event");if(Array.isArray(e)&&(e={topics:e}),"string"==typeof e)switch(e){case"block":case"debug":case"error":case"finalized":case"network":case"pending":case"safe":return{type:e,tag:e}}if(he(e,32)){const t=e.toLowerCase();return{type:"transaction",tag:Np("tx",{hash:t}),hash:t}}if(e.orphan){const t=e;return{type:"orphan",tag:Np("orphan",t),filter:(n=t,JSON.parse(JSON.stringify(n)))}}var n;if(e.address||e.topics){const n=e,r={topics:(n.topics||[]).map(e=>null==e?null:Array.isArray(e)?Bp(e.map(e=>e.toLowerCase())):e.toLowerCase())};if(n.address){const e=[],o=[],i=n=>{he(n)?e.push(n):o.push((async()=>{e.push(await Eu(n,t))})())};Array.isArray(n.address)?n.address.forEach(i):i(n.address),o.length&&await Promise.all(o),r.address=Bp(e.map(e=>e.toLowerCase()))}return{filter:r,tag:Np("event",r),type:"event"}}oe(!1,"unknown ProviderEvent","event",e)}function Up(){return(new Date).getTime()}const Dp={cacheTimeout:250,pollingInterval:4e3};class Lp{#_e;#Oe;#Me;#Ge;#je;#He;#ze;#Ve;#Ke;#We;#$e;#l;constructor(e,t){if(this.#l=Object.assign({},Dp,t||{}),"any"===e)this.#He=!0,this.#je=null;else if(e){const t=mp.from(e);this.#He=!1,this.#je=Promise.resolve(t),setTimeout(()=>{this.emit("network",t,null)},0)}else this.#He=!1,this.#je=null;this.#Ve=-1,this.#ze=new Map,this.#_e=new Map,this.#Oe=new Map,this.#Me=null,this.#Ge=!1,this.#Ke=1,this.#We=new Map,this.#$e=!1}get pollingInterval(){return this.#l.pollingInterval}get provider(){return this}get plugins(){return Array.from(this.#Oe.values())}attachPlugin(e){if(this.#Oe.get(e.name))throw new Error(`cannot replace existing plugin: ${e.name} `);return this.#Oe.set(e.name,e.connect(this)),this}getPlugin(e){return this.#Oe.get(e)||null}get disableCcipRead(){return this.#$e}set disableCcipRead(e){this.#$e=!!e}async#qe(e){const t=this.#l.cacheTimeout;if(t<0)return await this._perform(e);const n=Np(e.method,e);let r=this.#ze.get(n);return r||(r=this._perform(e),this.#ze.set(n,r),setTimeout(()=>{this.#ze.get(n)===r&&this.#ze.delete(n)},t)),await r}async ccipReadFetch(e,t,n){if(this.disableCcipRead||0===n.length||null==e.to)return null;const r=e.to.toLowerCase(),o=t.toLowerCase(),i=[];for(let t=0;t<n.length;t++){const s=n[t],a=s.replace("{sender}",r).replace("{data}",o),c=new ll(a);-1===s.indexOf("{data}")&&(c.body={data:o,sender:r}),this.emit("debug",{action:"sendCcipReadFetchRequest",request:c,index:t,urls:n});let u,l="unknown error";try{u=await c.send()}catch(e){i.push(e.message),this.emit("debug",{action:"receiveCcipReadFetchError",request:c,result:{error:e}});continue}try{const e=u.bodyJson;if(e.data)return this.emit("debug",{action:"receiveCcipReadFetchResult",request:c,result:e}),e.data;e.message&&(l=e.message),this.emit("debug",{action:"receiveCcipReadFetchError",request:c,result:e})}catch(e){}re(u.statusCode<400||u.statusCode>=500,`response not found during CCIP fetch: ${l}`,"OFFCHAIN_FAULT",{reason:"404_MISSING_RESOURCE",transaction:e,info:{url:s,errorMessage:l}}),i.push(l)}re(!1,`error encountered during CCIP fetch: ${i.map(e=>JSON.stringify(e)).join(", ")}`,"OFFCHAIN_FAULT",{reason:"500_SERVER_ERROR",transaction:e,info:{urls:n,errorMessages:i}})}_wrapBlock(e,t){return new Il(function(e){const t=cp(e);return t.transactions=e.transactions.map(e=>"string"==typeof e?e:fp(e)),t}(e),this)}_wrapLog(e,t){return new Cl(function(e){return ap(e)}(e),this)}_wrapTransactionReceipt(e,t){return new Ol(function(e){return lp(e)}(e),this)}_wrapTransactionResponse(e,t){return new Tl(fp(e),this)}_detectNetwork(){re(!1,"sub-classes must implement this","UNSUPPORTED_OPERATION",{operation:"_detectNetwork"})}async _perform(e){re(!1,`unsupported method: ${e.method}`,"UNSUPPORTED_OPERATION",{operation:e.method,info:e})}async getBlockNumber(){const e=Ta(await this.#qe({method:"getBlockNumber"}),"%response");return this.#Ve>=0&&(this.#Ve=e),e}_getAddress(e){return Eu(e,this)}_getBlockTag(e){if(null==e)return"latest";switch(e){case"earliest":return"0x0";case"finalized":case"latest":case"pending":case"safe":return e}return he(e)?he(e,32)?e:Ba(e):("bigint"==typeof e&&(e=Ta(e,"blockTag")),"number"==typeof e?e>=0?Ba(e):this.#Ve>=0?Ba(this.#Ve+e):this.getBlockNumber().then(t=>Ba(t+e)):void oe(!1,"invalid blockTag","blockTag",e))}_getFilter(e){const t=(e.topics||[]).map(e=>null==e?null:Array.isArray(e)?Bp(e.map(e=>e.toLowerCase())):e.toLowerCase()),n="blockHash"in e?e.blockHash:void 0,r=(e,r,o)=>{let i;switch(e.length){case 0:break;case 1:i=e[0];break;default:e.sort(),i=e}if(n&&(null!=r||null!=o))throw new Error("invalid filter");const s={};return i&&(s.address=i),t.length&&(s.topics=t),r&&(s.fromBlock=r),o&&(s.toBlock=o),n&&(s.blockHash=n),s};let o,i,s=[];if(e.address)if(Array.isArray(e.address))for(const t of e.address)s.push(this._getAddress(t));else s.push(this._getAddress(e.address));return"fromBlock"in e&&(o=this._getBlockTag(e.fromBlock)),"toBlock"in e&&(i=this._getBlockTag(e.toBlock)),s.filter(e=>"string"!=typeof e).length||null!=o&&"string"!=typeof o||null!=i&&"string"!=typeof i?Promise.all([Promise.all(s),o,i]).then(e=>r(e[0],e[1],e[2])):r(s,o,i)}_getTransactionRequest(e){const t=Sl(e),n=[];if(["to","from"].forEach(e=>{if(null==t[e])return;const r=Eu(t[e],this);Tp(r)?n.push(async function(){t[e]=await r}()):t[e]=r}),null!=t.blockTag){const e=this._getBlockTag(t.blockTag);Tp(e)?n.push(async function(){t.blockTag=await e}()):t.blockTag=e}return n.length?async function(){return await Promise.all(n),t}():t}async getNetwork(){if(null==this.#je){const e=(async()=>{try{const e=await this._detectNetwork();return this.emit("network",e,null),e}catch(t){throw this.#je===e&&(this.#je=null),t}})();return this.#je=e,(await e).clone()}const e=this.#je,[t,n]=await Promise.all([e,this._detectNetwork()]);return t.chainId!==n.chainId&&(this.#He?(this.emit("network",n,t),this.#je===e&&(this.#je=Promise.resolve(n))):re(!1,`network changed: ${t.chainId} => ${n.chainId} `,"NETWORK_ERROR",{event:"changed"})),t.clone()}async getFeeData(){const e=await this.getNetwork(),t=async()=>{const{_block:t,gasPrice:n,priorityFee:r}=await Z({_block:this.#Je("latest",!1),gasPrice:(async()=>{try{return Sa(await this.#qe({method:"getGasPrice"}),"%response")}catch(e){}return null})(),priorityFee:(async()=>{try{return Sa(await this.#qe({method:"getPriorityFee"}),"%response")}catch(e){}return null})()});let o=null,i=null;const s=this._wrapBlock(t,e);return s&&s.baseFeePerGas&&(i=null!=r?r:BigInt("1000000000"),o=s.baseFeePerGas*Op+i),new kl(n,o,i)},n=e.getPlugin("org.ethers.plugins.network.FetchUrlFeeDataPlugin");if(n){const e=new ll(n.url),r=await n.processFunc(t,this,e);return new kl(r.gasPrice,r.maxFeePerGas,r.maxPriorityFeePerGas)}return await t()}async estimateGas(e){let t=this._getTransactionRequest(e);return Tp(t)&&(t=await t),Sa(await this.#qe({method:"estimateGas",transaction:t}),"%response")}async#Qe(e,t,n){re(n<10,"CCIP read exceeded maximum redirections","OFFCHAIN_FAULT",{reason:"TOO_MANY_REDIRECTS",transaction:Object.assign({},e,{blockTag:t,enableCcipRead:!0})});const r=Sl(e);try{return ge(await this._perform({method:"call",transaction:r,blockTag:t}))}catch(e){if(!this.disableCcipRead&&te(e)&&e.data&&n>=0&&"latest"===t&&null!=r.to&&"0x556f1830"===we(e.data,0,4)){const o=e.data,i=await Eu(r.to,this);let s;try{s=function(e){const t={sender:"",urls:[],calldata:"",selector:"",extraData:"",errorArgs:[]};re(me(e)>=160,"insufficient OffchainLookup data","OFFCHAIN_FAULT",{reason:"insufficient OffchainLookup data"});const n=we(e,0,32);re(we(n,0,12)===we(zp,0,12),"corrupt OffchainLookup sender","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup sender"}),t.sender=we(n,12);try{const n=[],r=Ta(we(e,32,64)),o=Ta(we(e,r,r+32)),i=we(e,r+32);for(let e=0;e<o;e++){const t=Fp(i,32*e);if(null==t)throw new Error("abort");n.push(t)}t.urls=n}catch(e){re(!1,"corrupt OffchainLookup urls","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup urls"})}try{const n=_p(e,64);if(null==n)throw new Error("abort");t.calldata=n}catch(e){re(!1,"corrupt OffchainLookup calldata","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup calldata"})}re(we(e,100,128)===we(zp,0,28),"corrupt OffchainLookup callbaackSelector","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup callbaackSelector"}),t.selector=we(e,96,100);try{const n=_p(e,128);if(null==n)throw new Error("abort");t.extraData=n}catch(e){re(!1,"corrupt OffchainLookup extraData","OFFCHAIN_FAULT",{reason:"corrupt OffchainLookup extraData"})}return t.errorArgs="sender,urls,calldata,selector,extraData".split(/,/).map(e=>t[e]),t}(we(e.data,4))}catch(e){re(!1,e.message,"OFFCHAIN_FAULT",{reason:"BAD_DATA",transaction:r,info:{data:o}})}re(s.sender.toLowerCase()===i.toLowerCase(),"CCIP Read sender mismatch","CALL_EXCEPTION",{action:"call",data:o,reason:"OffchainLookup",transaction:r,invocation:null,revert:{signature:"OffchainLookup(address,string[],bytes,bytes4,bytes)",name:"OffchainLookup",args:s.errorArgs}});const a=await this.ccipReadFetch(r,s.calldata,s.urls);re(null!=a,"CCIP Read failed to fetch data","OFFCHAIN_FAULT",{reason:"FETCH_FAILED",transaction:r,info:{data:e.data,errorArgs:s.errorArgs}});const c={to:i,data:ye([s.selector,Hp([a,s.extraData])])};this.emit("debug",{action:"sendCcipReadCall",transaction:c});try{const e=await this.#Qe(c,t,n+1);return this.emit("debug",{action:"receiveCcipReadCallResult",transaction:Object.assign({},c),result:e}),e}catch(e){throw this.emit("debug",{action:"receiveCcipReadCallError",transaction:Object.assign({},c),error:e}),e}}throw e}}async#Ze(e){const{value:t}=await Z({network:this.getNetwork(),value:e});return t}async call(e){const{tx:t,blockTag:n}=await Z({tx:this._getTransactionRequest(e),blockTag:this._getBlockTag(e.blockTag)});return await this.#Ze(this.#Qe(t,n,e.enableCcipRead?0:-1))}async#Ye(e,t,n){let r=this._getAddress(t),o=this._getBlockTag(n);return"string"==typeof r&&"string"==typeof o||([r,o]=await Promise.all([r,o])),await this.#Ze(this.#qe(Object.assign(e,{address:r,blockTag:o})))}async getBalance(e,t){return Sa(await this.#Ye({method:"getBalance"},e,t),"%response")}async getTransactionCount(e,t){return Ta(await this.#Ye({method:"getTransactionCount"},e,t),"%response")}async getCode(e,t){return ge(await this.#Ye({method:"getCode"},e,t))}async getStorage(e,t,n){const r=Sa(t,"position");return ge(await this.#Ye({method:"getStorage",position:r},e,n))}async broadcastTransaction(e){const{blockNumber:t,hash:n,network:r}=await Z({blockNumber:this.getBlockNumber(),hash:this._perform({method:"broadcastTransaction",signedTransaction:e}),network:this.getNetwork()}),o=zd.from(e);if(o.hash!==n)throw new Error("@TODO: the returned hash did not match");return this._wrapTransactionResponse(o,r).replaceableTransaction(t)}async#Je(e,t){if(he(e,32))return await this.#qe({method:"getBlock",blockHash:e,includeTransactions:t});let n=this._getBlockTag(e);return"string"!=typeof n&&(n=await n),await this.#qe({method:"getBlock",blockTag:n,includeTransactions:t})}async getBlock(e,t){const{network:n,params:r}=await Z({network:this.getNetwork(),params:this.#Je(e,!!t)});return null==r?null:this._wrapBlock(r,n)}async getTransaction(e){const{network:t,params:n}=await Z({network:this.getNetwork(),params:this.#qe({method:"getTransaction",hash:e})});return null==n?null:this._wrapTransactionResponse(n,t)}async getTransactionReceipt(e){const{network:t,params:n}=await Z({network:this.getNetwork(),params:this.#qe({method:"getTransactionReceipt",hash:e})});if(null==n)return null;if(null==n.gasPrice&&null==n.effectiveGasPrice){const t=await this.#qe({method:"getTransaction",hash:e});if(null==t)throw new Error("report this; could not find tx or effectiveGasPrice");n.effectiveGasPrice=t.gasPrice}return this._wrapTransactionReceipt(n,t)}async getTransactionResult(e){const{result:t}=await Z({network:this.getNetwork(),result:this.#qe({method:"getTransactionResult",hash:e})});return null==t?null:ge(t)}async getLogs(e){let t=this._getFilter(e);Tp(t)&&(t=await t);const{network:n,params:r}=await Z({network:this.getNetwork(),params:this.#qe({method:"getLogs",filter:t})});return r.map(e=>this._wrapLog(e,n))}_getProvider(e){re(!1,"provider cannot connect to target network","UNSUPPORTED_OPERATION",{operation:"_getProvider()"})}async getResolver(e){return await ep.fromName(this,e)}async getAvatar(e){const t=await this.getResolver(e);return t?await t.getAvatar():null}async resolveName(e){const t=await this.getResolver(e);return t?await t.getAddress():null}async lookupAddress(e){const t=hh((e=Ya(e)).substring(2).toLowerCase()+".addr.reverse");try{const n=await ep.getEnsAddress(this),r=new af(n,["function resolver(bytes32) view returns (address)"],this),o=await r.resolver(t);if(null==o||o===dl)return null;const i=new af(o,["function name(bytes32) view returns (string)"],this),s=await i.name(t);return await this.resolveName(s)!==e?null:s}catch(e){if(ee(e,"BAD_DATA")&&"0x"===e.value)return null;if(ee(e,"CALL_EXCEPTION"))return null;throw e}}async waitForTransaction(e,t,n){const r=null!=t?t:1;return 0===r?this.getTransactionReceipt(e):new Promise(async(t,o)=>{let i=null;const s=async n=>{try{const o=await this.getTransactionReceipt(e);if(null!=o&&n-o.blockNumber+1>=r)return t(o),void(i&&(clearTimeout(i),i=null))}catch(e){console.log("EEE",e)}this.once("block",s)};null!=n&&(i=setTimeout(()=>{null!=i&&(i=null,this.off("block",s),o(ne("timeout","TIMEOUT",{reason:"timeout"})))},n)),s(await this.getBlockNumber())})}async waitForBlock(e){re(!1,"not implemented yet","NOT_IMPLEMENTED",{operation:"waitForBlock"})}_clearTimeout(e){const t=this.#We.get(e);t&&(t.timer&&clearTimeout(t.timer),this.#We.delete(e))}_setTimeout(e,t){null==t&&(t=0);const n=this.#Ke++,r=()=>{this.#We.delete(n),e()};if(this.paused)this.#We.set(n,{timer:null,func:r,time:t});else{const e=setTimeout(r,t);this.#We.set(n,{timer:e,func:r,time:Up()})}return n}_forEachSubscriber(e){for(const t of this.#_e.values())e(t.subscriber)}_getSubscriber(e){switch(e.type){case"debug":case"error":case"network":return new Pp(e.type);case"block":{const e=new Ap(this);return e.pollingInterval=this.pollingInterval,e}case"safe":case"finalized":return new kp(this,e.type);case"event":return new Cp(this,e.filter);case"transaction":return new Ip(this,e.hash);case"orphan":return new Sp(this,e.filter)}throw new Error(`unsupported event: ${e.type}`)}_recoverSubscriber(e,t){for(const n of this.#_e.values())if(n.subscriber===e){n.started&&n.subscriber.stop(),n.subscriber=t,n.started&&t.start(),null!=this.#Me&&t.pause(this.#Me);break}}async#Xe(e,t){let n=await Rp(e,this);return"event"===n.type&&t&&t.length>0&&!0===t[0].removed&&(n=await Rp({orphan:"drop-log",log:t[0]},this)),this.#_e.get(n.tag)||null}async#et(e){const t=await Rp(e,this),n=t.tag;let r=this.#_e.get(n);return r||(r={subscriber:this._getSubscriber(t),tag:n,addressableMap:new WeakMap,nameMap:new Map,started:!1,listeners:[]},this.#_e.set(n,r)),r}async on(e,t){const n=await this.#et(e);return n.listeners.push({listener:t,once:!1}),n.started||(n.subscriber.start(),n.started=!0,null!=this.#Me&&n.subscriber.pause(this.#Me)),this}async once(e,t){const n=await this.#et(e);return n.listeners.push({listener:t,once:!0}),n.started||(n.subscriber.start(),n.started=!0,null!=this.#Me&&n.subscriber.pause(this.#Me)),this}async emit(e,...t){const n=await this.#Xe(e,t);if(!n||0===n.listeners.length)return!1;const r=n.listeners.length;return n.listeners=n.listeners.filter(({listener:n,once:r})=>{const o=new Bl(this,r?null:n,e);try{n.call(this,...t,o)}catch(e){}return!r}),0===n.listeners.length&&(n.started&&n.subscriber.stop(),this.#_e.delete(n.tag)),r>0}async listenerCount(e){if(e){const t=await this.#Xe(e);return t?t.listeners.length:0}let t=0;for(const{listeners:e}of this.#_e.values())t+=e.length;return t}async listeners(e){if(e){const t=await this.#Xe(e);return t?t.listeners.map(({listener:e})=>e):[]}let t=[];for(const{listeners:e}of this.#_e.values())t=t.concat(e.map(({listener:e})=>e));return t}async off(e,t){const n=await this.#Xe(e);if(!n)return this;if(t){const e=n.listeners.map(({listener:e})=>e).indexOf(t);e>=0&&n.listeners.splice(e,1)}return t&&0!==n.listeners.length||(n.started&&n.subscriber.stop(),this.#_e.delete(n.tag)),this}async removeAllListeners(e){if(e){const{tag:t,started:n,subscriber:r}=await this.#et(e);n&&r.stop(),this.#_e.delete(t)}else for(const[e,{started:t,subscriber:n}]of this.#_e)t&&n.stop(),this.#_e.delete(e);return this}async addListener(e,t){return await this.on(e,t)}async removeListener(e,t){return this.off(e,t)}get destroyed(){return this.#Ge}destroy(){this.removeAllListeners();for(const e of this.#We.keys())this._clearTimeout(e);this.#Ge=!0}get paused(){return null!=this.#Me}set paused(e){!!e!==this.paused&&(this.paused?this.resume():this.pause(!1))}pause(e){if(this.#Ve=-1,null!=this.#Me){if(this.#Me==!!e)return;re(!1,"cannot change pause type; resume first","UNSUPPORTED_OPERATION",{operation:"pause"})}this._forEachSubscriber(t=>t.pause(e)),this.#Me=!!e;for(const e of this.#We.values())e.timer&&clearTimeout(e.timer),e.time=Up()-e.time}resume(){if(null!=this.#Me){this._forEachSubscriber(e=>e.resume()),this.#Me=null;for(const e of this.#We.values()){let t=e.time;t<0&&(t=0),e.time=Up(),setTimeout(e.func,t)}}}}function Fp(e,t){try{const n=_p(e,t);if(n)return ke(n)}catch(e){}return null}function _p(e,t){if("0x"===e)return null;try{const n=Ta(we(e,t,t+32)),r=Ta(we(e,n,n+32));return we(e,n+32,n+32+r)}catch(e){}return null}function Mp(e){const t=Pa(e);if(t.length>32)throw new Error("internal; should not happen");const n=new Uint8Array(32);return n.set(t,32-t.length),n}function Gp(e){if(e.length%32==0)return e;const t=new Uint8Array(32*Math.ceil(e.length/32));return t.set(e),t}const jp=new Uint8Array([]);function Hp(e){const t=[];let n=0;for(let r=0;r<e.length;r++)t.push(jp),n+=32;for(let r=0;r<e.length;r++){const o=le(e[r]);t[r]=Mp(n),t.push(Mp(o.length)),t.push(Gp(o)),n+=32+32*Math.ceil(o.length/32)}return ye(t)}const zp="0x0000000000000000000000000000000000000000000000000000000000000000";function Vp(e,t){if(e.provider)return e.provider;re(!1,"missing provider","UNSUPPORTED_OPERATION",{operation:t})}async function Kp(e,t){let n=Sl(t);if(null!=n.to&&(n.to=Eu(n.to,e)),null!=n.from){const t=n.from;n.from=Promise.all([e.getAddress(),Eu(t,e)]).then(([e,t])=>(oe(e.toLowerCase()===t.toLowerCase(),"transaction from mismatch","tx.from",t),e))}else n.from=e.getAddress();return await Z(n)}class Wp{provider;constructor(e){Y(this,{provider:e||null})}async getNonce(e){return Vp(this,"getTransactionCount").getTransactionCount(await this.getAddress(),e)}async populateCall(e){return await Kp(this,e)}async populateTransaction(e){const t=Vp(this,"populateTransaction"),n=await Kp(this,e);null==n.nonce&&(n.nonce=await this.getNonce("pending")),null==n.gasLimit&&(n.gasLimit=await this.estimateGas(n));const r=await this.provider.getNetwork();null!=n.chainId?oe(Sa(n.chainId)===r.chainId,"transaction chainId mismatch","tx.chainId",e.chainId):n.chainId=r.chainId;const o=null!=n.maxFeePerGas||null!=n.maxPriorityFeePerGas;if(null==n.gasPrice||2!==n.type&&!o?0!==n.type&&1!==n.type||!o||oe(!1,"pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas","tx",e):oe(!1,"eip-1559 transaction do not support gasPrice","tx",e),2!==n.type&&null!=n.type||null==n.maxFeePerGas||null==n.maxPriorityFeePerGas)if(0===n.type||1===n.type){const e=await t.getFeeData();re(null!=e.gasPrice,"network does not support gasPrice","UNSUPPORTED_OPERATION",{operation:"getGasPrice"}),null==n.gasPrice&&(n.gasPrice=e.gasPrice)}else{const e=await t.getFeeData();if(null==n.type)if(null!=e.maxFeePerGas&&null!=e.maxPriorityFeePerGas)if(n.authorizationList&&n.authorizationList.length?n.type=4:n.type=2,null!=n.gasPrice){const e=n.gasPrice;delete n.gasPrice,n.maxFeePerGas=e,n.maxPriorityFeePerGas=e}else null==n.maxFeePerGas&&(n.maxFeePerGas=e.maxFeePerGas),null==n.maxPriorityFeePerGas&&(n.maxPriorityFeePerGas=e.maxPriorityFeePerGas);else null!=e.gasPrice?(re(!o,"network does not support EIP-1559","UNSUPPORTED_OPERATION",{operation:"populateTransaction"}),null==n.gasPrice&&(n.gasPrice=e.gasPrice),n.type=0):re(!1,"failed to get consistent fee data","UNSUPPORTED_OPERATION",{operation:"signer.getFeeData"});else 2!==n.type&&3!==n.type&&4!==n.type||(null==n.maxFeePerGas&&(n.maxFeePerGas=e.maxFeePerGas),null==n.maxPriorityFeePerGas&&(n.maxPriorityFeePerGas=e.maxPriorityFeePerGas))}else n.type=2;return await Z(n)}async populateAuthorization(e){const t=Object.assign({},e);return null==t.chainId&&(t.chainId=(await Vp(this,"getNetwork").getNetwork()).chainId),null==t.nonce&&(t.nonce=await this.getNonce()),t}async estimateGas(e){return Vp(this,"estimateGas").estimateGas(await this.populateCall(e))}async call(e){return Vp(this,"call").call(await this.populateCall(e))}async resolveName(e){const t=Vp(this,"resolveName");return await t.resolveName(e)}async sendTransaction(e){const t=Vp(this,"sendTransaction"),n=await this.populateTransaction(e);delete n.from;const r=zd.from(n);return await t.broadcastTransaction(await this.signTransaction(r))}authorize(e){re(!1,"authorization not implemented for this signer","UNSUPPORTED_OPERATION",{operation:"authorize"})}}class $p extends Wp{address;constructor(e,t){super(t),Y(this,{address:e})}async getAddress(){return this.address}connect(e){return new $p(this.address,e)}#tt(e,t){re(!1,`VoidSigner cannot sign ${e}`,"UNSUPPORTED_OPERATION",{operation:t})}async signTransaction(e){this.#tt("transactions","signTransaction")}async signMessage(e){this.#tt("messages","signMessage")}async signTypedData(e,t,n){this.#tt("typed-data","signTypedData")}}class qp{#Te;#nt;#Ne;#Ue;#rt;#ot;constructor(e){this.#Te=e,this.#nt=null,this.#Ne=this.#Re.bind(this),this.#Ue=!1,this.#rt=null,this.#ot=!1}_subscribe(e){throw new Error("subclasses must override this")}_emitResults(e,t){throw new Error("subclasses must override this")}_recover(e){throw new Error("subclasses must override this")}async#Re(e){try{null==this.#nt&&(this.#nt=this._subscribe(this.#Te));let e=null;try{e=await this.#nt}catch(e){if(!ee(e,"UNSUPPORTED_OPERATION")||"eth_newFilter"!==e.operation)throw e}if(null==e)return this.#nt=null,void this.#Te._recoverSubscriber(this,this._recover(this.#Te));const t=await this.#Te.getNetwork();if(this.#rt||(this.#rt=t),this.#rt.chainId!==t.chainId)throw new Error("chaid changed");if(this.#ot)return;const n=await this.#Te.send("eth_getFilterChanges",[e]);await this._emitResults(this.#Te,n)}catch(e){console.log("@TODO",e)}this.#Te.once("block",this.#Ne)}#it(){const e=this.#nt;e&&(this.#nt=null,e.then(e=>{this.#Te.destroyed||this.#Te.send("eth_uninstallFilter",[e])}))}start(){this.#Ue||(this.#Ue=!0,this.#Re(-2))}stop(){this.#Ue&&(this.#Ue=!1,this.#ot=!0,this.#it(),this.#Te.off("block",this.#Ne))}pause(e){e&&this.#it(),this.#Te.off("block",this.#Ne)}resume(){this.start()}}class Jp extends qp{#st;constructor(e,t){var n;super(e),this.#st=(n=t,JSON.parse(JSON.stringify(n)))}_recover(e){return new Cp(e,this.#st)}async _subscribe(e){return await e.send("eth_newFilter",[this.#st])}async _emitResults(e,t){for(const n of t)e.emit(this.#st,e._wrapLog(n,e._network))}}class Qp extends qp{async _subscribe(e){return await e.send("eth_newPendingTransactionFilter",[])}async _emitResults(e,t){for(const n of t)e.emit("pending",n)}}const Zp="bigint,boolean,function,number,string,symbol".split(/,/g);function Yp(e){if(null==e||Zp.indexOf(typeof e)>=0)return e;if("function"==typeof e.getAddress)return e;if(Array.isArray(e))return e.map(Yp);if("object"==typeof e)return Object.keys(e).reduce((t,n)=>(t[n]=e[n],t),{});throw new Error(`should not happen: ${e} (${typeof e})`)}function Xp(e){return new Promise(t=>{setTimeout(t,e)})}function eg(e){return e?e.toLowerCase():e}function tg(e){return e&&"number"==typeof e.pollingInterval}const ng={polling:!1,staticNetwork:null,batchStallTime:10,batchMaxSize:1<<20,batchMaxCount:100,cacheTimeout:250,pollingInterval:4e3};class rg extends Wp{address;constructor(e,t){super(e),Y(this,{address:t=Ya(t)})}connect(e){re(!1,"cannot reconnect JsonRpcSigner","UNSUPPORTED_OPERATION",{operation:"signer.connect"})}async getAddress(){return this.address}async populateTransaction(e){return await this.populateCall(e)}async sendUncheckedTransaction(e){const t=Yp(e),n=[];if(t.from){const r=t.from;n.push((async()=>{const n=await Eu(r,this.provider);oe(null!=n&&n.toLowerCase()===this.address.toLowerCase(),"from address mismatch","transaction",e),t.from=n})())}else t.from=this.address;if(null==t.gasLimit&&n.push((async()=>{t.gasLimit=await this.provider.estimateGas({...t,from:this.address})})()),null!=t.to){const e=t.to;n.push((async()=>{t.to=await Eu(e,this.provider)})())}n.length&&await Promise.all(n);const r=this.provider.getRpcTransaction(t);return this.provider.send("eth_sendTransaction",[r])}async sendTransaction(e){const t=await this.provider.getBlockNumber(),n=await this.sendUncheckedTransaction(e);return await new Promise((e,r)=>{const o=[1e3,100];let i=0;const s=async()=>{try{const r=await this.provider.getTransaction(n);if(null!=r)return void e(r.replaceableTransaction(t))}catch(e){if(ee(e,"CANCELLED")||ee(e,"BAD_DATA")||ee(e,"NETWORK_ERROR")||ee(e,"UNSUPPORTED_OPERATION"))return null==e.info&&(e.info={}),e.info.sendTransactionHash=n,void r(e);if(ee(e,"INVALID_ARGUMENT")&&(i++,null==e.info&&(e.info={}),e.info.sendTransactionHash=n,i>10))return void r(e);this.provider.emit("error",ne("failed to fetch transation after sending (will try again)","UNKNOWN_ERROR",{error:e}))}this.provider._setTimeout(()=>{s()},o.pop()||4e3)};s()})}async signTransaction(e){const t=Yp(e);if(t.from){const n=await Eu(t.from,this.provider);oe(null!=n&&n.toLowerCase()===this.address.toLowerCase(),"from address mismatch","transaction",e),t.from=n}else t.from=this.address;const n=this.provider.getRpcTransaction(t);return await this.provider.send("eth_signTransaction",[n])}async signMessage(e){const t="string"==typeof e?xe(e):e;return await this.provider.send("personal_sign",[ge(t),this.address.toLowerCase()])}async signTypedData(e,t,n){const r=Yp(n),o=await Lu.resolveNames(e,t,r,async e=>{const t=await Eu(e);return oe(null!=t,"TypedData does not support null address","value",e),t});return await this.provider.send("eth_signTypedData_v4",[this.address.toLowerCase(),JSON.stringify(Lu.getPayload(o.domain,t,o.value))])}async unlock(e){return this.provider.send("personal_unlockAccount",[this.address.toLowerCase(),e,null])}async _legacySignMessage(e){const t="string"==typeof e?xe(e):e;return await this.provider.send("eth_sign",[this.address.toLowerCase(),ge(t)])}}class og extends Lp{#l;#at;#ct;#ut;#lt;#rt;#ft;#ht(){if(this.#ut)return;const e=1===this._getOption("batchMaxCount")?0:this._getOption("batchStallTime");this.#ut=setTimeout(()=>{this.#ut=null;const e=this.#ct;for(this.#ct=[];e.length;){const t=[e.shift()];for(;e.length&&t.length!==this.#l.batchMaxCount;)if(t.push(e.shift()),JSON.stringify(t.map(e=>e.payload)).length>this.#l.batchMaxSize){e.unshift(t.pop());break}(async()=>{const e=1===t.length?t[0].payload:t.map(e=>e.payload);this.emit("debug",{action:"sendRpcPayload",payload:e});try{const n=await this._send(e);this.emit("debug",{action:"receiveRpcResult",result:n});for(const{resolve:e,reject:r,payload:o}of t){if(this.destroyed){r(ne("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:o.method}));continue}const t=n.filter(e=>e.id===o.id)[0];if(null==t){const e=ne("missing response for request","BAD_DATA",{value:n,info:{payload:o}});this.emit("error",e),r(e);continue}"error"in t?r(this.getRpcError(o,t)):e(t.result)}}catch(e){this.emit("debug",{action:"receiveRpcError",error:e});for(const{reject:n}of t)n(e)}})()}},e)}constructor(e,t){super(e,t),this.#at=1,this.#l=Object.assign({},ng,t||{}),this.#ct=[],this.#ut=null,this.#rt=null,this.#ft=null;{let e=null;const t=new Promise(t=>{e=t});this.#lt={promise:t,resolve:e}}const n=this._getOption("staticNetwork");"boolean"==typeof n?(oe(!n||"any"!==e,"staticNetwork cannot be used on special network 'any'","options",t),n&&null!=e&&(this.#rt=mp.from(e))):n&&(oe(null==e||n.matches(e),"staticNetwork MUST match network object","options",t),this.#rt=n)}_getOption(e){return this.#l[e]}get _network(){return re(this.#rt,"network is not available yet","NETWORK_ERROR"),this.#rt}async _perform(e){if("call"===e.method||"estimateGas"===e.method){let t=e.transaction;if(t&&null!=t.type&&Sa(t.type)&&null==t.maxFeePerGas&&null==t.maxPriorityFeePerGas){const n=await this.getFeeData();null==n.maxFeePerGas&&null==n.maxPriorityFeePerGas&&(e=Object.assign({},e,{transaction:Object.assign({},t,{type:void 0})}))}}const t=this.getRpcRequest(e);return null!=t?await this.send(t.method,t.args):super._perform(e)}async _detectNetwork(){const e=this._getOption("staticNetwork");if(e){if(!0!==e)return e;if(this.#rt)return this.#rt}return this.#ft?await this.#ft:this.ready?(this.#ft=(async()=>{try{const e=mp.from(Sa(await this.send("eth_chainId",[])));return this.#ft=null,e}catch(e){throw this.#ft=null,e}})(),await this.#ft):(this.#ft=(async()=>{const e={id:this.#at++,method:"eth_chainId",params:[],jsonrpc:"2.0"};let t;this.emit("debug",{action:"sendRpcPayload",payload:e});try{t=(await this._send(e))[0],this.#ft=null}catch(e){throw this.#ft=null,this.emit("debug",{action:"receiveRpcError",error:e}),e}if(this.emit("debug",{action:"receiveRpcResult",result:t}),"result"in t)return mp.from(Sa(t.result));throw this.getRpcError(e,t)})(),await this.#ft)}_start(){null!=this.#lt&&null!=this.#lt.resolve&&(this.#lt.resolve(),this.#lt=null,(async()=>{for(;null==this.#rt&&!this.destroyed;)try{this.#rt=await this._detectNetwork()}catch(e){if(this.destroyed)break;console.log("JsonRpcProvider failed to detect network and cannot start up; retry in 1s (perhaps the URL is wrong or the node is not started)"),this.emit("error",ne("failed to bootstrap network detection","NETWORK_ERROR",{event:"initial-network-discovery",info:{error:e}})),await Xp(1e3)}this.#ht()})())}async _waitUntilReady(){if(null!=this.#lt)return await this.#lt.promise}_getSubscriber(e){return"pending"===e.type?new Qp(this):"event"===e.type?this._getOption("polling")?new Cp(this,e.filter):new Jp(this,e.filter):"orphan"===e.type&&"drop-log"===e.filter.orphan?new Pp("orphan"):super._getSubscriber(e)}get ready(){return null==this.#lt}getRpcTransaction(e){const t={};return["chainId","gasLimit","gasPrice","type","maxFeePerGas","maxPriorityFeePerGas","nonce","value"].forEach(n=>{if(null==e[n])return;let r=n;"gasLimit"===n&&(r="gas"),t[r]=Ba(Sa(e[n],`tx.${n}`))}),["from","to","data"].forEach(n=>{null!=e[n]&&(t[n]=ge(e[n]))}),e.accessList&&(t.accessList=_u(e.accessList)),e.blobVersionedHashes&&(t.blobVersionedHashes=e.blobVersionedHashes.map(e=>e.toLowerCase())),e.authorizationList&&(t.authorizationList=e.authorizationList.map(e=>{const t=Yu(e);return{address:t.address,nonce:Ba(t.nonce),chainId:Ba(t.chainId),yParity:Ba(t.signature.yParity),r:Ba(t.signature.r),s:Ba(t.signature.s)}})),t}getRpcRequest(e){switch(e.method){case"chainId":return{method:"eth_chainId",args:[]};case"getBlockNumber":return{method:"eth_blockNumber",args:[]};case"getGasPrice":return{method:"eth_gasPrice",args:[]};case"getPriorityFee":return{method:"eth_maxPriorityFeePerGas",args:[]};case"getBalance":return{method:"eth_getBalance",args:[eg(e.address),e.blockTag]};case"getTransactionCount":return{method:"eth_getTransactionCount",args:[eg(e.address),e.blockTag]};case"getCode":return{method:"eth_getCode",args:[eg(e.address),e.blockTag]};case"getStorage":return{method:"eth_getStorageAt",args:[eg(e.address),"0x"+e.position.toString(16),e.blockTag]};case"broadcastTransaction":return{method:"eth_sendRawTransaction",args:[e.signedTransaction]};case"getBlock":if("blockTag"in e)return{method:"eth_getBlockByNumber",args:[e.blockTag,!!e.includeTransactions]};if("blockHash"in e)return{method:"eth_getBlockByHash",args:[e.blockHash,!!e.includeTransactions]};break;case"getTransaction":return{method:"eth_getTransactionByHash",args:[e.hash]};case"getTransactionReceipt":return{method:"eth_getTransactionReceipt",args:[e.hash]};case"call":return{method:"eth_call",args:[this.getRpcTransaction(e.transaction),e.blockTag]};case"estimateGas":return{method:"eth_estimateGas",args:[this.getRpcTransaction(e.transaction)]};case"getLogs":return e.filter&&null!=e.filter.address&&(Array.isArray(e.filter.address)?e.filter.address=e.filter.address.map(eg):e.filter.address=eg(e.filter.address)),{method:"eth_getLogs",args:[e.filter]}}return null}getRpcError(e,t){const{method:n}=e,{error:r}=t;if("eth_estimateGas"===n&&r.message){const t=r.message;if(!t.match(/revert/i)&&t.match(/insufficient funds/i))return ne("insufficient funds","INSUFFICIENT_FUNDS",{transaction:e.params[0],info:{payload:e,error:r}});if(t.match(/nonce/i)&&t.match(/too low/i))return ne("nonce has already been used","NONCE_EXPIRED",{transaction:e.params[0],info:{payload:e,error:r}})}if("eth_call"===n||"eth_estimateGas"===n){const t=ag(r),o=wu.getBuiltinCallException("eth_call"===n?"call":"estimateGas",e.params[0],t?t.data:null);return o.info={error:r,payload:e},o}const o=JSON.stringify(function(e){const t=[];return cg(e,t),t}(r));if("string"==typeof r.message&&r.message.match(/user denied|ethers-user-denied/i))return ne("user rejected action","ACTION_REJECTED",{action:{eth_sign:"signMessage",personal_sign:"signMessage",eth_signTypedData_v4:"signTypedData",eth_signTransaction:"signTransaction",eth_sendTransaction:"sendTransaction",eth_requestAccounts:"requestAccess",wallet_requestAccounts:"requestAccess"}[n]||"unknown",reason:"rejected",info:{payload:e,error:r}});if("eth_sendRawTransaction"===n||"eth_sendTransaction"===n){const t=e.params[0];if(o.match(/insufficient funds|base fee exceeds gas limit/i))return ne("insufficient funds for intrinsic transaction cost","INSUFFICIENT_FUNDS",{transaction:t,info:{error:r}});if(o.match(/nonce/i)&&o.match(/too low/i))return ne("nonce has already been used","NONCE_EXPIRED",{transaction:t,info:{error:r}});if(o.match(/replacement transaction/i)&&o.match(/underpriced/i))return ne("replacement fee too low","REPLACEMENT_UNDERPRICED",{transaction:t,info:{error:r}});if(o.match(/only replay-protected/i))return ne("legacy pre-eip-155 transactions not supported","UNSUPPORTED_OPERATION",{operation:n,info:{transaction:t,info:{error:r}}})}let i=!!o.match(/the method .* does not exist/i);return i||r&&r.details&&r.details.startsWith("Unauthorized method:")&&(i=!0),i?ne("unsupported operation","UNSUPPORTED_OPERATION",{operation:e.method,info:{error:r,payload:e}}):ne("could not coalesce error","UNKNOWN_ERROR",{error:r,payload:e})}send(e,t){if(this.destroyed)return Promise.reject(ne("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:e}));const n=this.#at++,r=new Promise((r,o)=>{this.#ct.push({resolve:r,reject:o,payload:{method:e,params:t,id:n,jsonrpc:"2.0"}})});return this.#ht(),r}async getSigner(e){null==e&&(e=0);const t=this.send("eth_accounts",[]);if("number"==typeof e){const n=await t;if(e>=n.length)throw new Error("no such account");return new rg(this,n[e])}const{accounts:n}=await Z({network:this.getNetwork(),accounts:t});e=Ya(e);for(const t of n)if(Ya(t)===e)return new rg(this,e);throw new Error("invalid account")}async listAccounts(){return(await this.send("eth_accounts",[])).map(e=>new rg(this,e))}destroy(){this.#ut&&(clearTimeout(this.#ut),this.#ut=null);for(const{payload:e,reject:t}of this.#ct)t(ne("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:e.method}));this.#ct=[],super.destroy()}}class ig extends og{#dt;constructor(e,t){super(e,t);let n=this._getOption("pollingInterval");null==n&&(n=ng.pollingInterval),this.#dt=n}_getSubscriber(e){const t=super._getSubscriber(e);return tg(t)&&(t.pollingInterval=this.#dt),t}get pollingInterval(){return this.#dt}set pollingInterval(e){if(!Number.isInteger(e)||e<0)throw new Error("invalid interval");this.#dt=e,this._forEachSubscriber(e=>{tg(e)&&(e.pollingInterval=this.#dt)})}}class sg extends ig{#pt;constructor(e,t,n){null==e&&(e="http://localhost:8545"),super(t,n),this.#pt="string"==typeof e?new ll(e):e.clone()}_getConnection(){return this.#pt.clone()}async send(e,t){return await this._start(),await super.send(e,t)}async _send(e){const t=this._getConnection();t.body=JSON.stringify(e),t.setHeader("content-type","application/json");const n=await t.send();n.assertOk();let r=n.bodyJson;return Array.isArray(r)||(r=[r]),r}}function ag(e){if(null==e)return null;if("string"==typeof e.message&&e.message.match(/revert/i)&&he(e.data))return{message:e.message,data:e.data};if("object"==typeof e){for(const t in e){const n=ag(e[t]);if(n)return n}return null}if("string"==typeof e)try{return ag(JSON.parse(e))}catch(e){}return null}function cg(e,t){if(null!=e){if("string"==typeof e.message&&t.push(e.message),"object"==typeof e)for(const n in e)cg(e[n],t);if("string"==typeof e)try{return cg(JSON.parse(e),t)}catch(e){}}}class ug extends ig{#z;#gt;constructor(e,t,n){const r=Object.assign({},null!=n?n:{},{batchMaxCount:1});oe(e&&e.request,"invalid EIP-1193 provider","ethereum",e),super(t,r),this.#gt=null,n&&n.providerInfo&&(this.#gt=n.providerInfo),this.#z=async(t,n)=>{const r={method:t,params:n};this.emit("debug",{action:"sendEip1193Request",payload:r});try{const t=await e.request(r);return this.emit("debug",{action:"receiveEip1193Result",result:t}),t}catch(e){const t=new Error(e.message);throw t.code=e.code,t.data=e.data,t.payload=r,this.emit("debug",{action:"receiveEip1193Error",error:t}),t}}}get providerInfo(){return this.#gt}async send(e,t){return await this._start(),await super.send(e,t)}async _send(e){oe(!Array.isArray(e),"EIP-1193 does not support batch request","payload",e);try{const t=await this.#z(e.method,e.params||[]);return[{id:e.id,result:t}]}catch(t){return[{id:e.id,error:{code:t.code,data:t.data,message:t.message}}]}}getRpcError(e,t){switch((t=JSON.parse(JSON.stringify(t))).error.code||-1){case 4001:t.error.message=`ethers-user-denied: ${t.error.message}`;break;case 4200:t.error.message=`ethers-unsupported: ${t.error.message}`}return super.getRpcError(e,t)}async hasSigner(e){null==e&&(e=0);const t=await this.send("eth_accounts",[]);return"number"==typeof e?t.length>e:(e=e.toLowerCase(),0!==t.filter(t=>t.toLowerCase()===e).length)}async getSigner(e){if(null==e&&(e=0),!await this.hasSigner(e))try{await this.#z("eth_requestAccounts",[])}catch(e){const t=e.payload;throw this.getRpcError(t,{id:t.id,error:e})}return await super.getSigner(e)}static async discover(e){if(null==e&&(e={}),e.provider)return new ug(e.provider);const t=e.window?e.window:"undefined"!=typeof window?window:null;if(null==t)return null;const n=e.anyProvider;if(n&&t.ethereum)return new ug(t.ethereum);if(!("addEventListener"in t&&"dispatchEvent"in t&&"removeEventListener"in t))return null;const r=e.timeout?e.timeout:300;return 0===r?null:await new Promise((o,i)=>{let s=[];const a=e=>{s.push(e.detail),n&&c()},c=()=>{if(clearTimeout(u),s.length)if(e&&e.filter){const t=e.filter(s.map(e=>Object.assign({},e.info)));if(null==t)o(null);else if(t instanceof ug)o(t);else{let e=null;if(t.uuid){const n=s.filter(e=>t.uuid===e.info.uuid);e=n[0]}if(e){const{provider:t,info:n}=e;o(new ug(t,void 0,{providerInfo:n}))}else i(ne("filter returned unknown info","UNSUPPORTED_OPERATION",{value:t}))}}else{const{provider:e,info:t}=s[0];o(new ug(e,void 0,{providerInfo:t}))}else o(null);t.removeEventListener("eip6963:announceProvider",a)},u=setTimeout(()=>{c()},r);t.addEventListener("eip6963:announceProvider",a),t.dispatchEvent(new Event("eip6963:requestProvider"))})}}function lg(e){return"string"==typeof e&&(e=xe(e)),Vt(ye([xe("Ethereum Signed Message:\n"),xe(String(e.length)),e]))}function fg(e,t){return xd(lg(e),t)}class hg extends Wp{address;#yt;constructor(e,t){super(t),oe(e&&"function"==typeof e.sign,"invalid private key","privateKey","[ REDACTED ]"),this.#yt=e,Y(this,{address:Ad(this.signingKey.publicKey)})}get signingKey(){return this.#yt}get privateKey(){return this.signingKey.privateKey}async getAddress(){return this.address}connect(e){return new hg(this.#yt,e)}async signTransaction(e){e=Sl(e);const{to:t,from:n}=await Z({to:e.to?Eu(e.to,this):void 0,from:e.from?Eu(e.from,this):void 0});null!=t&&(e.to=t),null!=n&&(e.from=n),null!=e.from&&(oe(Ya(e.from)===this.address,"transaction from address mismatch","tx.from",e.from),delete e.from);const r=zd.from(e);return r.signature=this.signingKey.sign(r.unsignedHash),r.serialized}async signMessage(e){return this.signMessageSync(e)}signMessageSync(e){return this.signingKey.sign(lg(e)).serialized}authorizeSync(e){oe("string"==typeof e.address,"invalid address for authorizeSync","auth.address",e);const t=this.signingKey.sign(function(e){return oe("string"==typeof e.address,"invalid address for hashAuthorization","auth.address",e),Vt(ye(["0x05",Ed([null!=e.chainId?Pa(e.chainId):"0x",Ya(e.address),null!=e.nonce?Pa(e.nonce):"0x"])]))}(e));return Object.assign({},{address:Ya(e.address),nonce:Sa(e.nonce||0),chainId:Sa(e.chainId||0)},{signature:t})}async authorize(e){return e=Object.assign({},e,{address:await Eu(e.address,this)}),this.authorizeSync(await this.populateAuthorization(e))}async signTypedData(e,t,n){const r=await Lu.resolveNames(e,t,n,async e=>{re(null!=this.provider,"cannot resolve ENS names without a provider","UNSUPPORTED_OPERATION",{operation:"resolveName",info:{name:e}});const t=await this.provider.resolveName(e);return re(null!=t,"unconfigured ENS name","UNCONFIGURED_NAME",{value:e}),t});return this.signingKey.sign(Lu.hash(r.domain,t,r.value)).serialized}}let dg=!1;const pg=function(e,t,n){return function(e,t){const n={sha256:Xe,sha512:pt}[e];return oe(null!=n,"invalid hmac algorithm","algorithm",e),Ve.create(n,t)}(e,t).update(n).digest()};let gg=pg;function yg(e,t,n){const r=le(t,"key"),o=le(n,"data");return ge(gg(e,r,o))}yg._=pg,yg.lock=function(){dg=!0},yg.register=function(e){if(dg)throw new Error("computeHmac is locked");gg=e},Object.freeze(yg);const mg=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),wg=Uint8Array.from({length:16},(e,t)=>t),bg=wg.map(e=>(9*e+5)%16);let vg=[wg],Eg=[bg];for(let e=0;e<4;e++)for(let t of[vg,Eg])t.push(t[e].map(e=>mg[e]));const Ag=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>new Uint8Array(e)),xg=vg.map((e,t)=>e.map(e=>Ag[t][e])),kg=Eg.map((e,t)=>e.map(e=>Ag[t][e])),Sg=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Ig=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),Cg=(e,t)=>e<<t|e>>>32-t;function Og(e,t,n,r){return 0===e?t^n^r:1===e?t&n|~t&r:2===e?(t|~n)^r:3===e?t&r|n&~r:t^(n|~r)}const Tg=new Uint32Array(16);class Ng extends We{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:n,h3:r,h4:o}=this;return[e,t,n,r,o]}set(e,t,n,r,o){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|o}process(e,t){for(let n=0;n<16;n++,t+=4)Tg[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,o=0|this.h1,i=o,s=0|this.h2,a=s,c=0|this.h3,u=c,l=0|this.h4,f=l;for(let e=0;e<5;e++){const t=4-e,h=Sg[e],d=Ig[e],p=vg[e],g=Eg[e],y=xg[e],m=kg[e];for(let t=0;t<16;t++){const r=Cg(n+Og(e,o,s,c)+Tg[p[t]]+h,y[t])+l|0;n=l,l=c,c=0|Cg(s,10),s=o,o=r}for(let e=0;e<16;e++){const n=Cg(r+Og(t,i,a,u)+Tg[g[e]]+d,m[e])+f|0;r=f,f=u,u=0|Cg(a,10),a=i,i=n}}this.set(this.h1+s+u|0,this.h2+c+f|0,this.h3+l+r|0,this.h4+n+i|0,this.h0+o+a|0)}roundClean(){Tg.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const Pg=je(()=>new Ng);let Bg=!1;const Rg=function(e){return Pg(e)};let Ug=Rg;function Dg(e){const t=le(e,"data");return ge(Ug(t))}Dg._=Rg,Dg.lock=function(){Bg=!0},Dg.register=function(e){if(Bg)throw new TypeError("ripemd160 is locked");Ug=e},Object.freeze(Dg);let Lg=!1;const Fg=function(e){return new Uint8Array(function(e){re(null!=yt,"platform does not support secure random numbers","UNSUPPORTED_OPERATION",{operation:"randomBytes"}),oe(Number.isInteger(e)&&e>0&&e<=1024,"invalid length","length",e);const t=new Uint8Array(e);return yt.getRandomValues(t),t}(e))};let _g=Fg;function Mg(e){return _g(e)}Mg._=Fg,Mg.lock=function(){Lg=!0},Mg.register=function(e){if(Lg)throw new Error("randomBytes is locked");_g=e},Object.freeze(Mg);const Gg=/^[a-z]*$/i;function jg(e,t){let n=97;return e.reduce((e,r)=>(r===t?n++:r.match(Gg)?e.push(String.fromCharCode(n)+r):(n=97,e.push(r)),e),[])}class Hg{locale;constructor(e){Y(this,{locale:e})}split(e){return e.toLowerCase().split(/\s+/g)}join(e){return e.join(" ")}}class zg extends Hg{#t;#mt;constructor(e,t,n){super(e),this.#t=t,this.#mt=n,this.#wt=null}get _data(){return this.#t}_decodeWords(){return oe("0"===(e=this.#t)[0],"unsupported auwl data","data",e),function(e,t){for(let n=28;n>=0;n--)e=e.split(" !#$%&'()*+,-./<=>?@[]^_`{|}~"[n]).join(t.substring(2*n,2*n+2));const n=[],r=e.replace(/(:|([0-9])|([A-Z][a-z]*))/g,(e,t,r,o)=>{if(r)for(let e=parseInt(r);e>=0;e--)n.push(";");else n.push(t.toLowerCase());return""});if(r)throw new Error(`leftovers: ${JSON.stringify(r)}`);return jg(jg(n,";"),":")}(e.substring(59),e.substring(1,59));var e}#wt;#bt(){if(null==this.#wt){const e=this._decodeWords();if(Ec(e.join("\n")+"\n")!==this.#mt)throw new Error(`BIP39 Wordlist for ${this.locale} FAILED`);this.#wt=e}return this.#wt}getWord(e){const t=this.#bt();return oe(e>=0&&e<t.length,`invalid word index: ${e}`,"index",e),t[e]}getWordIndex(e){return this.#bt().indexOf(e)}}let Vg=null;class Kg extends zg{constructor(){super("en","0erleonalorenseinceregesticitStanvetearctssi#ch2Athck&tneLl0And#Il.yLeOutO=S|S%b/ra@SurdU'0Ce[Cid|CountCu'Hie=IdOu,-Qui*Ro[TT]T%T*[Tu$0AptDD-tD*[Ju,M.UltV<)Vi)0Rob-0FairF%dRaid0A(EEntRee0Ead0MRRp%tS!_rmBumCoholErtI&LLeyLowMo,O}PhaReadySoT Ways0A>urAz(gOngOuntU'd0Aly,Ch%Ci|G G!GryIm$K!Noun)Nu$O` Sw T&naTiqueXietyY1ArtOlogyPe?P!Pro=Ril1ChCt-EaEnaGueMMedM%MyOundR<+Re,Ri=RowTTefa@Ti,Tw%k0KPe@SaultSetSi,SumeThma0H!>OmTa{T&dT.udeTra@0Ct]D.Gu,NtTh%ToTumn0Era+OcadoOid0AkeA*AyEsomeFulKw?d0Is:ByChel%C#D+GL<)Lc#y~MbooN<aNn RRelyRga(R*lSeS-SketTt!3A^AnAutyCau'ComeEfF%eG(Ha=H(dLie=LowLtN^Nef./TrayTt Twe&Y#d3Cyc!DKeNdOlogyRdR`Tt _{AdeAmeAnketA,EakE[IndOodO[omOu'UeUrUsh_rdAtDyIlMbNeNusOkO,Rd R(gRrowSsTtomUn)XY_{etA(AndA[A=EadEezeI{Id+IefIghtIngIskOccoliOk&OnzeOomO` OwnUsh2Bb!DdyD+tFf$oIldLbLkL!tNd!Nk Rd&Rg R,SS(e[SyTt Y Zz:Bba+B(B!CtusGeKe~LmM aMpNN$N)lNdyNn#NoeNvasNy#Pab!P.$Pta(RRb#RdRgoRpetRryRtSeShS(o/!Su$TT$ogT^Teg%yTt!UghtU'Ut]Ve3Il(gL yM|NsusNturyRe$Rta(_irAlkAmp]An+AosApt Ar+A'AtEapE{Ee'EfErryE,I{&IefIldIm}yOi)Oo'R#-U{!UnkUrn0G?Nnam#Rc!Tiz&TyVil_imApArifyAwAyE<ErkEv I{I|IffImbIn-IpO{OgO'O`OudOwnUbUmpU, Ut^_^A,C#utDeFfeeIlInL!@L%LumnMb(eMeMf%tM-Mm#Mp<yNc tNdu@NfirmNg*[N}@Nsid NtrolNv()OkOlPp PyR$ReRnR*@/Tt#U^UntryUp!Ur'Us(V Yo>_{Ad!AftAmA}AshAt AwlAzyEamEd.EekEwI{etImeIspIt-OpO[Ou^OwdUci$UelUi'Umb!Un^UshYY,$2BeLtu*PPbo?dRiousRr|Rta(R=Sh]/omTe3C!:DMa+MpN)Ng R(gShUght WnY3AlBa>BrisCadeCemb CideCl(eC%a>C*a'ErF&'F(eFyG*eLayLiv M<dMi'Ni$Nti,NyP?tP&dPos.P`PutyRi=ScribeS tSignSkSpair/royTailTe@VelopVi)Vo>3AgramAlAm#dAryCeE'lEtFf G.$Gn.yLemmaNn NosaurRe@RtSag*eScov Sea'ShSmi[S%d Splay/<)V tVideV%)Zzy5Ct%Cum|G~Lph(Ma(Na>NkeyN%OrSeUb!Ve_ftAg#AmaA,-AwEamE[IftIllInkIpI=OpUmY2CkMbNeR(g/T^Ty1Arf1Nam-:G G!RlyRnR`Sily/Sy1HoOlogyOnomy0GeItUca>1F%t0G1GhtTh 2BowD E@r-Eg<tEm|Eph<tEvat%I>Se0B?kBodyBra)Er+Ot]PloyPow Pty0Ab!A@DD![D%'EmyErgyF%)Ga+G(eH<)JoyLi,OughR-hRollSu*T Ti*TryVelope1Isode0U$Uip0AA'OdeOs]R%Upt0CapeSayS&)Ta>0Ern$H-s1Id&)IlOkeOl=1A@Amp!Ce[Ch<+C.eCludeCu'Ecu>Erci'Hau,Hib.I!I,ItOt-P<dPe@Pi*Pla(Po'P*[T&dTra0EEbrow:Br-CeCultyDeIntI`~L'MeMilyMousNNcyNtasyRmSh]TT$Th TigueUltV%.e3Atu*Bru?yD $EEdElMa!N)/iv$T^V W3B Ct]EldGu*LeLmLt N$NdNeNg NishReRmR,Sc$ShTT}[X_gAmeAshAtAv%EeIghtIpOatO{O%Ow UidUshY_mCusGIlLd~owOdOtR)Re,R+tRkRtu}RumRw?dSsil/ UndX_gi!AmeEqu|EshI&dIn+OgOntO,OwnOz&U.2ElNNnyRna)RyTu*:D+tInLaxy~ yMePRa+Rba+Rd&Rl-Rm|SSpTeTh U+Ze3N $NiusN*Nt!Nu(e/u*2O,0AntFtGg!Ng RaffeRlVe_dAn)A*A[IdeImp'ObeOomOryO=OwUe_tDde[LdOdO'RillaSpelSsipV nWn_bA)A(AntApeA[Av.yEatE&IdIefItOc yOupOwUnt_rdE[IdeIltIt?N3M:B.IrLfMm M, NdPpyRb%RdRshR=,TVeWkZ?d3AdAl`ArtAvyD+hogIght~oLmetLpNRo3Dd&Gh~NtPRe/%y5BbyCkeyLdLeLiday~owMeNeyOdPeRnRr%R'Sp.$/TelUrV 5BGeM<Mb!M%Nd*dNgryNtRd!RryRtSb<d3Brid:1EOn0EaEntifyLe2N%e4LLeg$L}[0A+Ita>M&'Mu}Pa@Po'Pro=Pul'0ChCludeComeC*a'DexD-a>Do%Du,ryF<tFl-tF%mHa!H .Iti$Je@JuryMa>N Noc|PutQuiryS<eSe@SideSpi*/$lTa@T e,ToVe,V.eVol=3On0L<dOla>Sue0Em1Ory:CketGu?RZz3AlousAns~yWel9BInKeUr}yY5D+I)MpNg!Ni%Nk/:Ng?oo3EnEpT^upY3CkDD}yNdNgdomSsTT^&TeTt&Wi4EeIfeO{Ow:BBelB%Dd DyKeMpNgua+PtopR+T T(UghUndryVaWWnWsu.Y Zy3Ad AfArnA=Ctu*FtGG$G&dIsu*M#NdNg`NsOp?dSs#Tt Vel3ArB tyBr?yC&'FeFtGhtKeMbM.NkOnQuid/Tt!VeZ?d5AdAnB, C$CkG-NelyNgOpTt yUdUn+VeY$5CkyGga+Mb N?N^Xury3R-s:Ch(eDG-G}tIdIlInJ%KeMm$NNa+Nda>NgoNs]Nu$P!Rb!R^Rg(R(eRketRria+SkSs/ T^T i$ThTrixTt XimumZe3AdowAnAsu*AtCh<-D$DiaLodyLtMb M%yNt]NuRcyR+R.RryShSsa+T$Thod3Dd!DnightLk~]M-NdNimumN%Nu>Rac!Rr%S ySs/akeXXedXtu*5Bi!DelDifyMM|N.%NkeyN, N`OnR$ReRn(gSqu.oTh T]T%Unta(U'VeVie5ChFf(LeLtiplySc!SeumShroomS-/Tu$3Self/ yTh:I=MePk(Rrow/yT]Tu*3ArCkEdGati=G!@I` PhewR=/TTw%kUtr$V WsXt3CeGht5B!I'M(eeOd!Rm$R`SeTab!TeTh(gTi)VelW5C!?Mb R'T:K0EyJe@Li+Scu*S =Ta(Vious0CurE<Tob 0Or1FF Fi)T&2L1Ay0DI=Ymp-0It0CeEI#L(eLy1EnEraIn]Po'T]1An+B.Ch?dD D(?yG<I|Ig($Ph<0Tr-h0H 0Tdo%T TputTside0AlEnEr0NN 0Yg&0/ 0O}:CtDd!GeIrLa)LmNdaNelN-N` P RadeR|RkRrotRtySsT^ThTi|TrolTt nU'VeYm|3A)AnutArAs<tL-<NN$tyNcilOp!Pp Rfe@Rm.Rs#T2O}OtoRa'Ys-$0AnoCn-Ctu*E)GGe#~LotNkO} Pe/olT^Zza_)A}tA,-A>AyEa'Ed+U{UgUn+2EmEtIntL?LeLi)NdNyOlPul?Rt]S.]Ssib!/TatoTt yV tyWd W _@i)Ai'Ed-tEf Epa*Es|EttyEv|I)IdeIm?yIntI%.yIs#Iva>IzeOb!mO)[Odu)Of.OgramOje@Omo>OofOp tyOsp O>@OudOvide2Bl-Dd(g~LpL'Mpk(N^PilPpyR^a'R.yRpo'R'ShTZz!3Ramid:99Al.yAntumArt E,]I{ItIzO>:Bb.Cco#CeCkD?DioIlInI'~yMpN^NdomN+PidReTeTh V&WZ%3AdyAlAs#BelBuildC$lCei=CipeC%dCyc!Du)F!@F%mFu'G]G*tGul?Je@LaxLea'LiefLyMa(Memb M(dMo=Nd NewNtOp&PairPeatPla)P%tQui*ScueSemb!Si,Sour)Sp#'SultTi*T*atTurnUn]Ve$ViewW?d2Y`m0BBb#CeChDeD+F!GhtGidNgOtPp!SkTu$V$V 5AdA,BotBu,CketM<)OfOkieOmSeTa>UghUndU>Y$5Bb DeGLeNNwayR$:DDd!D}[FeIlLadLm#L#LtLu>MeMp!NdTisfyToshiU)Usa+VeY1A!AnA*Att E}HemeHoolI&)I[%sOrp]OutRapRe&RiptRub1AAr^As#AtC#dC*tCt]Cur.yEdEkGm|Le@~M(?Ni%N'Nt&)RiesRvi)Ss]Tt!TupV&_dowAftAllowA*EdEllEriffIeldIftI}IpIv O{OeOotOpOrtOuld O=RimpRugUff!Y0Bl(gCkDeE+GhtGnL|Lk~yLv Mil?Mp!N)NgR&/ Tua>XZe1A>Et^IIllInIrtUll0AbAmEepEnd I)IdeIghtImOg<OtOwUsh0AllArtI!OkeOo`0A{AkeApIffOw0ApCc Ci$CkDaFtL?Ldi LidLut]L=Me#eNgOnRryRtUlUndUpUr)U`0A)A*Ati$AwnEakEci$EedEllEndH eI)Id IkeInIr.L.OilOns%O#OrtOtRayReadR(gY0Ua*UeezeUir*l_b!AdiumAffA+AirsAmpAndArtA>AyEakEelEmEpE*oI{IllIngO{Oma^O}OolOryO=Ra>gyReetRikeR#gRugg!Ud|UffUmb!Y!0Bje@Bm.BwayC)[ChDd&Ff G?G+,ItMm NNnyN'tP PplyP*meReRfa)R+Rpri'RroundR=ySpe@/a(1AllowAmpApArmE?EetIftImIngIt^Ord1MbolMptomRup/em:B!Ck!GIlL|LkNkPeR+tSk/eTtooXi3A^Am~NN<tNnisNtRm/Xt_nkAtEmeEnE%yE*EyIngIsOughtReeRi=RowUmbUnd 0CketDeG LtMb MeNyPRedSsueT!5A,BaccoDayDdl EGe` I!tK&MatoM%rowNeNgueNightOlO`PP-Pp!R^RnadoRtoi'SsT$Uri,W?dW WnY_{AdeAff-Ag-A(Ansf ApAshA=lAyEatEeEndI$IbeI{Igg ImIpOphyOub!U{UeUlyUmpetU,U`Y2BeIt]Mb!NaN}lRkeyRnRt!1El=EntyI)InI,O1PeP-$:5Ly5B*lla0Ab!Awa*C!Cov D DoFairFoldHappyIf%mIqueItIv 'KnownLo{TilUsu$Veil1Da>GradeHoldOnP Set1B<Ge0A+EEdEfulE![U$0Il.y:C<tCuumGueLidL!yL=NNishP%Rious/Ult3H-!L=tNd%Ntu*NueRbRifyRs]RyS'lT <3Ab!Br<tCiousCt%yDeoEw~a+Nta+Ol(Rtu$RusSaS.Su$T$Vid5C$I)IdLc<oLumeTeYa+:GeG#ItLk~LnutNtRfa*RmRri%ShSp/eT VeY3Al`Ap#ArA'lA` BDd(gEk&dIrdLcome/T_!AtEatEelEnE*IpIsp 0DeD`FeLd~NNdowNeNgNkNn Nt ReSdomSeShT}[5LfM<Nd OdOlRdRkRldRryR`_pE{E,!I,I>Ong::Rd3Ar~ow9UUngU`:3BraRo9NeO","0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60")}static wordlist(){return null==Vg&&(Vg=new Kg),Vg}}let Wg=!1;const $g=function(e,t,n,r,o){return function(e,t,n,r,o){const i={sha256:Xe,sha512:pt}[o];return oe(null!=i,"invalid pbkdf2 algorithm","algorithm",o),Ke(i,e,t,{c:n,dkLen:r})}(e,t,n,r,o)};let qg=$g;function Jg(e,t,n,r,o){const i=le(e,"password"),s=le(t,"salt");return ge(qg(i,s,n,r,o))}function Qg(e){return(1<<e)-1<<8-e&255}function Zg(e){return(1<<e)-1&255}function Yg(e,t){ae("NFKD"),null==t&&(t=Kg.wordlist());const n=t.split(e);oe(n.length%3==0&&n.length>=12&&n.length<=24,"invalid mnemonic length","mnemonic","[ REDACTED ]");const r=new Uint8Array(Math.ceil(11*n.length/8));let o=0;for(let e=0;e<n.length;e++){let i=t.getWordIndex(n[e].normalize("NFKD"));oe(i>=0,`invalid mnemonic word at index ${e}`,"mnemonic","[ REDACTED ]");for(let e=0;e<11;e++)i&1<<10-e&&(r[o>>3]|=1<<7-o%8),o++}const i=32*n.length/3,s=Qg(n.length/3);return oe((le(kt(r.slice(0,i/8)))[0]&s)===(r[r.length-1]&s),"invalid mnemonic checksum","mnemonic","[ REDACTED ]"),ge(r.slice(0,i/8))}function Xg(e,t){oe(e.length%4==0&&e.length>=16&&e.length<=32,"invalid entropy size","entropy","[ REDACTED ]"),null==t&&(t=Kg.wordlist());const n=[0];let r=11;for(let t=0;t<e.length;t++)r>8?(n[n.length-1]<<=8,n[n.length-1]|=e[t],r-=8):(n[n.length-1]<<=r,n[n.length-1]|=e[t]>>8-r,n.push(e[t]&Zg(8-r)),r+=3);const o=e.length/4,i=parseInt(kt(e).substring(2,4),16)&Qg(o);return n[n.length-1]<<=o,n[n.length-1]|=i>>8-o,t.join(n.map(e=>t.getWord(e)))}Jg._=$g,Jg.lock=function(){Wg=!0},Jg.register=function(e){if(Wg)throw new Error("pbkdf2 is locked");qg=e},Object.freeze(Jg);const ey={};class ty{phrase;password;wordlist;entropy;constructor(e,t,n,r,o){null==r&&(r=""),null==o&&(o=Kg.wordlist()),ce(e,ey,"Mnemonic"),Y(this,{phrase:n,password:r,wordlist:o,entropy:t})}computeSeed(){const e=xe("mnemonic"+this.password,"NFKD");return Jg(xe(this.phrase,"NFKD"),e,2048,64,"sha512")}static fromPhrase(e,t,n){const r=Yg(e,n);return e=Xg(le(r),n),new ty(ey,r,e,t,n)}static fromEntropy(e,t,n){const r=le(e,"entropy"),o=Xg(r,n);return new ty(ey,ge(r),o,t,n)}static entropyToPhrase(e,t){return Xg(le(e,"entropy"),t)}static phraseToEntropy(e,t){return Yg(e,t)}static isValidMnemonic(e,t){try{return Yg(e,t),!0}catch(e){}return!1}}var ny,ry,oy,iy=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)},sy=function(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n};const ay={16:10,24:12,32:14},cy=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],uy=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],ly=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],fy=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],hy=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],dy=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],py=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],gy=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],yy=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],my=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239e3,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],wy=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998e3,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],by=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],vy=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],Ey=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239e3,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],Ay=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998e3,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function xy(e){const t=[];for(let n=0;n<e.length;n+=4)t.push(e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3]);return t}class ky{get key(){return iy(this,ny,"f").slice()}constructor(e){if(ny.set(this,void 0),ry.set(this,void 0),oy.set(this,void 0),!(this instanceof ky))throw Error("AES must be instanitated with `new`");sy(this,ny,new Uint8Array(e),"f");const t=ay[this.key.length];if(null==t)throw new TypeError("invalid key size (must be 16, 24 or 32 bytes)");sy(this,oy,[],"f"),sy(this,ry,[],"f");for(let e=0;e<=t;e++)iy(this,oy,"f").push([0,0,0,0]),iy(this,ry,"f").push([0,0,0,0]);const n=4*(t+1),r=this.key.length/4,o=xy(this.key);let i;for(let e=0;e<r;e++)i=e>>2,iy(this,oy,"f")[i][e%4]=o[e],iy(this,ry,"f")[t-i][e%4]=o[e];let s,a=0,c=r;for(;c<n;){if(s=o[r-1],o[0]^=uy[s>>16&255]<<24^uy[s>>8&255]<<16^uy[255&s]<<8^uy[s>>24&255]^cy[a]<<24,a+=1,8!=r)for(let e=1;e<r;e++)o[e]^=o[e-1];else{for(let e=1;e<r/2;e++)o[e]^=o[e-1];s=o[r/2-1],o[r/2]^=uy[255&s]^uy[s>>8&255]<<8^uy[s>>16&255]<<16^uy[s>>24&255]<<24;for(let e=r/2+1;e<r;e++)o[e]^=o[e-1]}let e,i,u=0;for(;u<r&&c<n;)e=c>>2,i=c%4,iy(this,oy,"f")[e][i]=o[u],iy(this,ry,"f")[t-e][i]=o[u++],c++}for(let e=1;e<t;e++)for(let t=0;t<4;t++)s=iy(this,ry,"f")[e][t],iy(this,ry,"f")[e][t]=by[s>>24&255]^vy[s>>16&255]^Ey[s>>8&255]^Ay[255&s]}encrypt(e){if(16!=e.length)throw new TypeError("invalid plaintext size (must be 16 bytes)");const t=iy(this,oy,"f").length-1,n=[0,0,0,0];let r=xy(e);for(let e=0;e<4;e++)r[e]^=iy(this,oy,"f")[0][e];for(let e=1;e<t;e++){for(let t=0;t<4;t++)n[t]=fy[r[t]>>24&255]^hy[r[(t+1)%4]>>16&255]^dy[r[(t+2)%4]>>8&255]^py[255&r[(t+3)%4]]^iy(this,oy,"f")[e][t];r=n.slice()}const o=new Uint8Array(16);let i=0;for(let e=0;e<4;e++)i=iy(this,oy,"f")[t][e],o[4*e]=255&(uy[r[e]>>24&255]^i>>24),o[4*e+1]=255&(uy[r[(e+1)%4]>>16&255]^i>>16),o[4*e+2]=255&(uy[r[(e+2)%4]>>8&255]^i>>8),o[4*e+3]=255&(uy[255&r[(e+3)%4]]^i);return o}decrypt(e){if(16!=e.length)throw new TypeError("invalid ciphertext size (must be 16 bytes)");const t=iy(this,ry,"f").length-1,n=[0,0,0,0];let r=xy(e);for(let e=0;e<4;e++)r[e]^=iy(this,ry,"f")[0][e];for(let e=1;e<t;e++){for(let t=0;t<4;t++)n[t]=gy[r[t]>>24&255]^yy[r[(t+3)%4]>>16&255]^my[r[(t+2)%4]>>8&255]^wy[255&r[(t+1)%4]]^iy(this,ry,"f")[e][t];r=n.slice()}const o=new Uint8Array(16);let i=0;for(let e=0;e<4;e++)i=iy(this,ry,"f")[t][e],o[4*e]=255&(ly[r[e]>>24&255]^i>>24),o[4*e+1]=255&(ly[r[(e+3)%4]>>16&255]^i>>16),o[4*e+2]=255&(ly[r[(e+2)%4]>>8&255]^i>>8),o[4*e+3]=255&(ly[255&r[(e+1)%4]]^i);return o}}ny=new WeakMap,ry=new WeakMap,oy=new WeakMap;class Sy{constructor(e,t,n){if(n&&!(this instanceof n))throw new Error(`${e} must be instantiated with "new"`);Object.defineProperties(this,{aes:{enumerable:!0,value:new ky(t)},name:{enumerable:!0,value:e}})}}var Iy,Cy,Oy=function(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n},Ty=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class Ny extends Sy{constructor(e,t){if(super("ECC",e,Ny),Iy.set(this,void 0),Cy.set(this,void 0),t){if(t.length%16)throw new TypeError("invalid iv size (must be 16 bytes)");Oy(this,Iy,new Uint8Array(t),"f")}else Oy(this,Iy,new Uint8Array(16),"f");Oy(this,Cy,this.iv,"f")}get iv(){return new Uint8Array(Ty(this,Iy,"f"))}encrypt(e){if(e.length%16)throw new TypeError("invalid plaintext size (must be multiple of 16 bytes)");const t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){for(let t=0;t<16;t++)Ty(this,Cy,"f")[t]^=e[n+t];Oy(this,Cy,this.aes.encrypt(Ty(this,Cy,"f")),"f"),t.set(Ty(this,Cy,"f"),n)}return t}decrypt(e){if(e.length%16)throw new TypeError("invalid ciphertext size (must be multiple of 16 bytes)");const t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){const r=this.aes.decrypt(e.subarray(n,n+16));for(let o=0;o<16;o++)t[n+o]=r[o]^Ty(this,Cy,"f")[o],Ty(this,Cy,"f")[o]=e[n+o]}return t}}Iy=new WeakMap,Cy=new WeakMap,new WeakMap,new WeakMap,new WeakSet;var Py,By,Ry,Uy=function(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n},Dy=function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};class Ly extends Sy{constructor(e,t){super("CTR",e,Ly),Py.set(this,void 0),By.set(this,void 0),Ry.set(this,void 0),Uy(this,Ry,new Uint8Array(16),"f"),Dy(this,Ry,"f").fill(0),Uy(this,Py,Dy(this,Ry,"f"),"f"),Uy(this,By,16,"f"),null==t&&(t=1),"number"==typeof t?this.setCounterValue(t):this.setCounterBytes(t)}get counter(){return new Uint8Array(Dy(this,Ry,"f"))}setCounterValue(e){if(!Number.isInteger(e)||e<0||e>Number.MAX_SAFE_INTEGER)throw new TypeError("invalid counter initial integer value");for(let t=15;t>=0;--t)Dy(this,Ry,"f")[t]=e%256,e=Math.floor(e/256)}setCounterBytes(e){if(16!==e.length)throw new TypeError("invalid counter initial Uint8Array value length");Dy(this,Ry,"f").set(e)}increment(){for(let e=15;e>=0;e--){if(255!==Dy(this,Ry,"f")[e]){Dy(this,Ry,"f")[e]++;break}Dy(this,Ry,"f")[e]=0}}encrypt(e){var t,n;const r=new Uint8Array(e);for(let e=0;e<r.length;e++)16===Dy(this,By,"f")&&(Uy(this,Py,this.aes.encrypt(Dy(this,Ry,"f")),"f"),Uy(this,By,0,"f"),this.increment()),r[e]^=Dy(this,Py,"f")[(Uy(this,By,(n=Dy(this,By,"f"),t=n++,n),"f"),t)];return r}decrypt(e){return this.encrypt(e)}}Py=new WeakMap,By=new WeakMap,Ry=new WeakMap,new WeakMap,new WeakMap,new WeakMap;const Fy=(e,t)=>e<<t|e>>>32-t;function _y(e,t,n,r,o,i){let s=e[t++]^n[r++],a=e[t++]^n[r++],c=e[t++]^n[r++],u=e[t++]^n[r++],l=e[t++]^n[r++],f=e[t++]^n[r++],h=e[t++]^n[r++],d=e[t++]^n[r++],p=e[t++]^n[r++],g=e[t++]^n[r++],y=e[t++]^n[r++],m=e[t++]^n[r++],w=e[t++]^n[r++],b=e[t++]^n[r++],v=e[t++]^n[r++],E=e[t++]^n[r++],A=s,x=a,k=c,S=u,I=l,C=f,O=h,T=d,N=p,P=g,B=y,R=m,U=w,D=b,L=v,F=E;for(let e=0;e<8;e+=2)I^=Fy(A+U|0,7),N^=Fy(I+A|0,9),U^=Fy(N+I|0,13),A^=Fy(U+N|0,18),P^=Fy(C+x|0,7),D^=Fy(P+C|0,9),x^=Fy(D+P|0,13),C^=Fy(x+D|0,18),L^=Fy(B+O|0,7),k^=Fy(L+B|0,9),O^=Fy(k+L|0,13),B^=Fy(O+k|0,18),S^=Fy(F+R|0,7),T^=Fy(S+F|0,9),R^=Fy(T+S|0,13),F^=Fy(R+T|0,18),x^=Fy(A+S|0,7),k^=Fy(x+A|0,9),S^=Fy(k+x|0,13),A^=Fy(S+k|0,18),O^=Fy(C+I|0,7),T^=Fy(O+C|0,9),I^=Fy(T+O|0,13),C^=Fy(I+T|0,18),R^=Fy(B+P|0,7),N^=Fy(R+B|0,9),P^=Fy(N+R|0,13),B^=Fy(P+N|0,18),U^=Fy(F+L|0,7),D^=Fy(U+F|0,9),L^=Fy(D+U|0,13),F^=Fy(L+D|0,18);o[i++]=s+A|0,o[i++]=a+x|0,o[i++]=c+k|0,o[i++]=u+S|0,o[i++]=l+I|0,o[i++]=f+C|0,o[i++]=h+O|0,o[i++]=d+T|0,o[i++]=p+N|0,o[i++]=g+P|0,o[i++]=y+B|0,o[i++]=m+R|0,o[i++]=w+U|0,o[i++]=b+D|0,o[i++]=v+L|0,o[i++]=E+F|0}function My(e,t,n,r,o){let i=r+0,s=r+16*o;for(let r=0;r<16;r++)n[s+r]=e[t+16*(2*o-1)+r];for(let r=0;r<o;r++,i+=16,t+=16)_y(n,s,e,t,n,i),r>0&&(s+=16),_y(n,i,e,t+=16,n,s)}function Gy(e,t,n){const r=Ge({dkLen:32,asyncTick:10,maxmem:1073742848},n),{N:o,r:i,p:s,dkLen:a,asyncTick:c,maxmem:u,onProgress:l}=r;if(Se(o),Se(i),Se(s),Se(a),Se(c),Se(u),void 0!==l&&"function"!=typeof l)throw new Error("progressCb should be function");const f=128*i,h=f/4;if(o<=1||o&o-1||o>=2**(f/8)||o>2**32)throw new Error("Scrypt: N must be larger than 1, a power of 2, less than 2^(128 * r / 8) and less than 2^32");if(s<0||s>137438953440/f)throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(a<0||a>137438953440)throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");const d=f*(o+s);if(d>u)throw new Error(`Scrypt: parameters too large, ${d} (128 * r * (N + p)) > ${u} (maxmem)`);const p=Ke(Xe,e,t,{c:1,dkLen:f*s}),g=Be(p),y=Be(new Uint8Array(f*o)),m=Be(new Uint8Array(f));let w=()=>{};if(l){const e=2*o*s,t=Math.max(Math.floor(e/1e4),1);let n=0;w=()=>{n++,!l||n%t&&n!==e||l(n/e)}}return{N:o,r:i,p:s,dkLen:a,blockSize32:h,V:y,B32:g,B:p,tmp:m,blockMixCb:w,asyncTick:c}}function jy(e,t,n,r,o){const i=Ke(Xe,e,n,{c:1,dkLen:t});return n.fill(0),r.fill(0),o.fill(0),i}let Hy=!1,zy=!1;const Vy=async function(e,t,n,r,o,i,s){return await async function(e,t,n){const{N:r,r:o,p:i,dkLen:s,blockSize32:a,V:c,B32:u,B:l,tmp:f,blockMixCb:h,asyncTick:d}=Gy(e,t,n);for(let e=0;e<i;e++){const t=a*e;for(let e=0;e<a;e++)c[e]=u[t+e];let n=0;await Le(r-1,d,()=>{My(c,n,c,n+=a,o),h()}),My(c,(r-1)*a,u,t,o),h(),await Le(r,d,()=>{const e=u[t+a-16]%r;for(let n=0;n<a;n++)f[n]=u[t+n]^c[e*a+n];My(f,0,u,t,o),h()})}return jy(e,s,l,c,f)}(e,t,{N:n,r,p:o,dkLen:i,onProgress:s})},Ky=function(e,t,n,r,o,i){return function(e,t,n){const{N:r,r:o,p:i,dkLen:s,blockSize32:a,V:c,B32:u,B:l,tmp:f,blockMixCb:h}=Gy(e,t,n);for(let e=0;e<i;e++){const t=a*e;for(let e=0;e<a;e++)c[e]=u[t+e];for(let e=0,t=0;e<r-1;e++)My(c,t,c,t+=a,o),h();My(c,(r-1)*a,u,t,o),h();for(let e=0;e<r;e++){const e=u[t+a-16]%r;for(let n=0;n<a;n++)f[n]=u[t+n]^c[e*a+n];My(f,0,u,t,o),h()}}return jy(e,s,l,c,f)}(e,t,{N:n,r,p:o,dkLen:i})};let Wy=Vy,$y=Ky;async function qy(e,t,n,r,o,i,s){const a=le(e,"passwd"),c=le(t,"salt");return ge(await Wy(a,c,n,r,o,i,s))}function Jy(e,t,n,r,o,i){const s=le(e,"passwd"),a=le(t,"salt");return ge($y(s,a,n,r,o,i))}function Qy(e){const t=le(e,"randomBytes");t[6]=15&t[6]|64,t[8]=63&t[8]|128;const n=ge(t);return[n.substring(2,10),n.substring(10,14),n.substring(14,18),n.substring(18,22),n.substring(22,34)].join("-")}function Zy(e){return"string"!=typeof e||e.startsWith("0x")||(e="0x"+e),fe(e)}function Yy(e,t){for(e=String(e);e.length<t;)e="0"+e;return e}function Xy(e){return"string"==typeof e?xe(e,"NFKC"):fe(e)}function em(e,t){const n=t.match(/^([a-z0-9$_.-]*)(:([a-z]+))?(!)?$/i);oe(null!=n,"invalid path","path",t);const r=n[1],o=n[3],i="!"===n[4];let s=e;for(const e of r.toLowerCase().split(".")){if(Array.isArray(s)){if(!e.match(/^[0-9]+$/))break;s=s[parseInt(e)]}else if("object"==typeof s){let t=null;for(const n in s)if(n.toLowerCase()===e){t=s[n];break}s=t}else s=null;if(null==s)break}if(oe(!i||null!=s,"missing required value","path",r),o&&null!=s){if("int"===o){if("string"==typeof s&&s.match(/^-?[0-9]+$/))return parseInt(s);if(Number.isSafeInteger(s))return s}if("number"===o&&"string"==typeof s&&s.match(/^-?[0-9.]*$/))return parseFloat(s);if("data"===o&&"string"==typeof s)return Zy(s);if("array"===o&&Array.isArray(s))return s;if(o===typeof s)return s;oe(!1,`wrong type found for ${o} `,"path",r)}return s}qy._=Vy,qy.lock=function(){zy=!0},qy.register=function(e){if(zy)throw new Error("scrypt is locked");Wy=e},Object.freeze(qy),Jy._=Ky,Jy.lock=function(){Hy=!0},Jy.register=function(e){if(Hy)throw new Error("scryptSync is locked");$y=e},Object.freeze(Jy);const tm="m/44'/60'/0'/0/0";function nm(e){try{const t=JSON.parse(e);if(3===(null!=t.version?parseInt(t.version):0))return!0}catch(e){}return!1}function rm(e,t){const n=le(t),r=em(e,"crypto.ciphertext:data!");oe(ge(Vt(ye([n.slice(16,32),r]))).substring(2)===em(e,"crypto.mac:string!").toLowerCase(),"incorrect password","password","[ REDACTED ]");const o=function(e,t,n){if("aes-128-ctr"===em(e,"crypto.cipher:string")){const r=em(e,"crypto.cipherparams.iv:data!");return ge(new Ly(t,r).decrypt(n))}re(!1,"unsupported cipher","UNSUPPORTED_OPERATION",{operation:"decrypt"})}(e,n.slice(0,16),r),i=Ad(o);if(e.address){let t=e.address.toLowerCase();t.startsWith("0x")||(t="0x"+t),oe(Ya(t)===i,"keystore address/privateKey mismatch","address",e.address)}const s={address:i,privateKey:o};if("0.1"===em(e,"x-ethers.version:string")){const t=n.slice(32,64),r=em(e,"x-ethers.mnemonicCiphertext:data!"),o=em(e,"x-ethers.mnemonicCounter:data!"),i=new Ly(t,o);s.mnemonic={path:em(e,"x-ethers.path:string")||tm,locale:em(e,"x-ethers.locale:string")||"en",entropy:ge(le(i.decrypt(r)))}}return s}function om(e){const t=em(e,"crypto.kdf:string");if(t&&"string"==typeof t){if("scrypt"===t.toLowerCase()){const n=em(e,"crypto.kdfparams.salt:data!"),r=em(e,"crypto.kdfparams.n:int!"),o=em(e,"crypto.kdfparams.r:int!"),i=em(e,"crypto.kdfparams.p:int!");oe(r>0&&!(r&r-1),"invalid kdf.N","kdf.N",r),oe(o>0&&i>0,"invalid kdf","kdf",t);const s=em(e,"crypto.kdfparams.dklen:int!");return oe(32===s,"invalid kdf.dklen","kdf.dflen",s),{name:"scrypt",salt:n,N:r,r:o,p:i,dkLen:64}}if("pbkdf2"===t.toLowerCase()){const t=em(e,"crypto.kdfparams.salt:data!"),n=em(e,"crypto.kdfparams.prf:string!"),r=n.split("-").pop();oe("sha256"===r||"sha512"===r,"invalid kdf.pdf","kdf.pdf",n);const o=em(e,"crypto.kdfparams.c:int!"),i=em(e,"crypto.kdfparams.dklen:int!");return oe(32===i,"invalid kdf.dklen","kdf.dklen",i),{name:"pbkdf2",salt:t,count:o,dkLen:i,algorithm:r}}}oe(!1,"unsupported key-derivation function","kdf",t)}function im(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}function sm(e){const t=null!=e.salt?le(e.salt,"options.salt"):Mg(32);let n=1<<17,r=8,o=1;return e.scrypt&&(e.scrypt.N&&(n=e.scrypt.N),e.scrypt.r&&(r=e.scrypt.r),e.scrypt.p&&(o=e.scrypt.p)),oe("number"==typeof n&&n>0&&Number.isSafeInteger(n)&&(BigInt(n)&BigInt(n-1))===BigInt(0),"invalid scrypt N parameter","options.N",n),oe("number"==typeof r&&r>0&&Number.isSafeInteger(r),"invalid scrypt r parameter","options.r",r),oe("number"==typeof o&&o>0&&Number.isSafeInteger(o),"invalid scrypt p parameter","options.p",o),{name:"scrypt",dkLen:32,salt:t,N:n,r,p:o}}function am(e,t,n,r){const o=le(n.privateKey,"privateKey"),i=null!=r.iv?le(r.iv,"options.iv"):Mg(16);oe(16===i.length,"invalid options.iv length","options.iv",r.iv);const s=null!=r.uuid?le(r.uuid,"options.uuid"):Mg(16);oe(16===s.length,"invalid options.uuid length","options.uuid",r.iv);const a=e.slice(0,16),c=e.slice(16,32),u=le(new Ly(a,i).encrypt(o)),l=Vt(ye([c,u])),f={address:n.address.substring(2).toLowerCase(),id:Qy(s),version:3,Crypto:{cipher:"aes-128-ctr",cipherparams:{iv:ge(i).substring(2)},ciphertext:ge(u).substring(2),kdf:"scrypt",kdfparams:{salt:ge(t.salt).substring(2),n:t.N,dklen:32,p:t.p,r:t.r},mac:l.substring(2)}};if(n.mnemonic){const t=null!=r.client?r.client:`ethers/${J}`,o=n.mnemonic.path||tm,i=n.mnemonic.locale||"en",s=e.slice(32,64),a=le(n.mnemonic.entropy,"account.mnemonic.entropy"),c=Mg(16),u=le(new Ly(s,c).encrypt(a)),l=new Date,h="UTC--"+l.getUTCFullYear()+"-"+Yy(l.getUTCMonth()+1,2)+"-"+Yy(l.getUTCDate(),2)+"T"+Yy(l.getUTCHours(),2)+"-"+Yy(l.getUTCMinutes(),2)+"-"+Yy(l.getUTCSeconds(),2)+".0Z--"+f.address;f["x-ethers"]={client:t,gethFilename:h,path:o,locale:i,mnemonicCounter:ge(c).substring(2),mnemonicCiphertext:ge(u).substring(2),version:"0.1"}}return JSON.stringify(f)}function cm(e,t,n){null==n&&(n={});const r=Xy(t),o=sm(n);return am(le(Jy(r,o.salt,o.N,o.r,o.p,64)),o,e,n)}async function um(e,t,n){null==n&&(n={});const r=Xy(t),o=sm(n);return am(le(await qy(r,o.salt,o.N,o.r,o.p,64,n.progressCallback)),o,e,n)}const lm="m/44'/60'/0'/0/0",fm=new Uint8Array([66,105,116,99,111,105,110,32,115,101,101,100]),hm=2147483648,dm=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");function pm(e,t){let n="";for(;e;)n="0123456789abcdef"[e%16]+n,e=Math.trunc(e/16);for(;n.length<2*t;)n="0"+n;return"0x"+n}function gm(e){const t=le(e);return Jd(ye([t,we(kt(kt(t)),0,4)]))}const ym={};function mm(e,t,n,r){const o=new Uint8Array(37);e&hm?(re(null!=r,"cannot derive child of neutered node","UNSUPPORTED_OPERATION",{operation:"deriveChild"}),o.set(le(r),1)):o.set(le(n));for(let t=24;t>=0;t-=8)o[33+(t>>3)]=e>>24-t&255;const i=le(yg("sha512",t,o));return{IL:i.slice(0,32),IR:i.slice(32)}}function wm(e,t){const n=t.split("/");oe(n.length>0,"invalid path","path",t),"m"===n[0]&&(oe(0===e.depth,`cannot derive root path (i.e. path starting with "m/") for a node at non-zero depth ${e.depth}`,"path",t),n.shift());let r=e;for(let e=0;e<n.length;e++){const t=n[e];if(t.match(/^[0-9]+'$/)){const n=parseInt(t.substring(0,t.length-1));oe(n<hm,"invalid path index",`path[${e}]`,t),r=r.deriveChild(hm+n)}else if(t.match(/^[0-9]+$/)){const n=parseInt(t);oe(n<hm,"invalid path index",`path[${e}]`,t),r=r.deriveChild(n)}else oe(!1,"invalid path component",`path[${e}]`,t)}return r}class bm extends hg{publicKey;fingerprint;parentFingerprint;mnemonic;chainCode;path;index;depth;constructor(e,t,n,r,o,i,s,a,c){super(t,c),ce(e,ym,"HDNodeWallet"),Y(this,{publicKey:t.compressedPublicKey}),Y(this,{parentFingerprint:n,fingerprint:we(Dg(kt(this.publicKey)),0,4),chainCode:r,path:o,index:i,depth:s}),Y(this,{mnemonic:a})}connect(e){return new bm(ym,this.signingKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.mnemonic,e)}#vt(){const e={address:this.address,privateKey:this.privateKey},t=this.mnemonic;return this.path&&t&&"en"===t.wordlist.locale&&""===t.password&&(e.mnemonic={path:this.path,locale:"en",entropy:t.entropy}),e}async encrypt(e,t){return await um(this.#vt(),e,{progressCallback:t})}encryptSync(e){return cm(this.#vt(),e)}get extendedKey(){return re(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),gm(ye(["0x0488ADE4",pm(this.depth,1),this.parentFingerprint,pm(this.index,4),this.chainCode,ye(["0x00",this.privateKey])]))}hasPath(){return null!=this.path}neuter(){return new vm(ym,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,this.provider)}deriveChild(e){const t=Ta(e,"index");oe(t<=4294967295,"invalid index","index",t);let n=this.path;n&&(n+="/"+(2147483647&t),t&hm&&(n+="'"));const{IR:r,IL:o}=mm(t,this.chainCode,this.publicKey,this.privateKey),i=new hd(Na((Oa(o)+BigInt(this.privateKey))%dm,32));return new bm(ym,i,this.fingerprint,ge(r),n,t,this.depth+1,this.mnemonic,this.provider)}derivePath(e){return wm(this,e)}static#Et(e,t){oe(de(e),"invalid seed","seed","[REDACTED]");const n=le(e,"seed");oe(n.length>=16&&n.length<=64,"invalid seed","seed","[REDACTED]");const r=le(yg("sha512",fm,n)),o=new hd(ge(r.slice(0,32)));return new bm(ym,o,"0x00000000",ge(r.slice(32)),"m",0,0,t,null)}static fromExtendedKey(e){const t=Pa(function(e){let t=$d;for(let n=0;n<e.length;n++)t*=qd,t+=Wd(e[n]);return t}(e));oe(82===t.length||gm(t.slice(0,78))===e,"invalid extended key","extendedKey","[ REDACTED ]");const n=t[4],r=ge(t.slice(5,9)),o=parseInt(ge(t.slice(9,13)).substring(2),16),i=ge(t.slice(13,45)),s=t.slice(45,78);switch(ge(t.slice(0,4))){case"0x0488b21e":case"0x043587cf":{const e=ge(s);return new vm(ym,Ad(e),e,r,i,null,o,n,null)}case"0x0488ade4":case"0x04358394 ":if(0!==s[0])break;return new bm(ym,new hd(s.slice(1)),r,i,null,o,n,null,null)}oe(!1,"invalid extended key prefix","extendedKey","[ REDACTED ]")}static createRandom(e,t,n){null==e&&(e=""),null==t&&(t=lm),null==n&&(n=Kg.wordlist());const r=ty.fromEntropy(Mg(16),e,n);return bm.#Et(r.computeSeed(),r).derivePath(t)}static fromMnemonic(e,t){return t||(t=lm),bm.#Et(e.computeSeed(),e).derivePath(t)}static fromPhrase(e,t,n,r){null==t&&(t=""),null==n&&(n=lm),null==r&&(r=Kg.wordlist());const o=ty.fromPhrase(e,t,r);return bm.#Et(o.computeSeed(),o).derivePath(n)}static fromSeed(e){return bm.#Et(e,null)}}class vm extends $p{publicKey;fingerprint;parentFingerprint;chainCode;path;index;depth;constructor(e,t,n,r,o,i,s,a,c){super(t,c),ce(e,ym,"HDNodeVoidWallet"),Y(this,{publicKey:n}),Y(this,{publicKey:n,fingerprint:we(Dg(kt(n)),0,4),parentFingerprint:r,chainCode:o,path:i,index:s,depth:a})}connect(e){return new vm(ym,this.address,this.publicKey,this.parentFingerprint,this.chainCode,this.path,this.index,this.depth,e)}get extendedKey(){return re(this.depth<256,"Depth too deep","UNSUPPORTED_OPERATION",{operation:"extendedKey"}),gm(ye(["0x0488B21E",pm(this.depth,1),this.parentFingerprint,pm(this.index,4),this.chainCode,this.publicKey]))}hasPath(){return null!=this.path}deriveChild(e){const t=Ta(e,"index");oe(t<=4294967295,"invalid index","index",t);let n=this.path;n&&(n+="/"+(2147483647&t),t&hm&&(n+="'"));const{IR:r,IL:o}=mm(t,this.chainCode,this.publicKey,null),i=hd.addPoints(o,this.publicKey,!0),s=Ad(i);return new vm(ym,s,i,this.fingerprint,ge(r),n,t,this.depth+1,this.provider)}derivePath(e){return wm(this,e)}}function Em(e){try{if(JSON.parse(e).encseed)return!0}catch(e){}return!1}function Am(e,t){const n=JSON.parse(e),r=Xy(t),o=Ya(em(n,"ethaddr:string!")),i=Zy(em(n,"encseed:string!"));oe(i&&i.length%16==0,"invalid encseed","json",e);const s=le(Jg(r,r,2e3,32,"sha256")).slice(0,16),a=i.slice(0,16),c=i.slice(16),u=function(e){if(e.length<16)throw new TypeError("PKCS#7 invalid length");const t=e[e.length-1];if(t>16)throw new TypeError("PKCS#7 padding byte out of range");const n=e.length-t;for(let r=0;r<t;r++)if(e[n+r]!==t)throw new TypeError("PKCS#7 invalid padding byte");return new Uint8Array(e.subarray(0,n))}(le(new Ny(s,a).decrypt(c)));let l="";for(let e=0;e<u.length;e++)l+=String.fromCharCode(u[e]);return{address:o,privateKey:Ec(l)}}function xm(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}class km extends hg{constructor(e,t){"string"!=typeof e||e.startsWith("0x")||(e="0x"+e),super("string"==typeof e?new hd(e):e,t)}connect(e){return new km(this.signingKey,e)}async encrypt(e,t){const n={address:this.address,privateKey:this.privateKey};return await um(n,e,{progressCallback:t})}encryptSync(e){return cm({address:this.address,privateKey:this.privateKey},e)}static#At(e){if(oe(e,"invalid JSON wallet","json","[ REDACTED ]"),"mnemonic"in e&&e.mnemonic&&"en"===e.mnemonic.locale){const t=ty.fromEntropy(e.mnemonic.entropy),n=bm.fromMnemonic(t,e.mnemonic.path);if(n.address===e.address&&n.privateKey===e.privateKey)return n;console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key")}const t=new km(e.privateKey);return oe(t.address===e.address,"address/privateKey mismatch","json","[ REDACTED ]"),t}static async fromEncryptedJson(e,t,n){let r=null;return nm(e)?r=await async function(e,t,n){const r=JSON.parse(e),o=Xy(t),i=om(r);if("pbkdf2"===i.name){n&&(n(0),await im(0));const{salt:e,count:t,dkLen:s,algorithm:a}=i,c=Jg(o,e,t,s,a);return n&&(n(1),await im(0)),rm(r,c)}re("scrypt"===i.name,"cannot be reached","UNKNOWN_ERROR",{params:i});const{salt:s,N:a,r:c,p:u,dkLen:l}=i;return rm(r,await qy(o,s,a,c,u,l,n))}(e,t,n):Em(e)&&(n&&(n(0),await xm(0)),r=Am(e,t),n&&(n(1),await xm(0))),km.#At(r)}static fromEncryptedJsonSync(e,t){let n=null;return nm(e)?n=function(e,t){const n=JSON.parse(e),r=Xy(t),o=om(n);if("pbkdf2"===o.name){const{salt:e,count:t,dkLen:i,algorithm:s}=o;return rm(n,Jg(r,e,t,i,s))}re("scrypt"===o.name,"cannot be reached","UNKNOWN_ERROR",{params:o});const{salt:i,N:s,r:a,p:c,dkLen:u}=o;return rm(n,Jy(r,i,s,a,c,u))}(e,t):Em(e)?n=Am(e,t):oe(!1,"invalid JSON wallet","json","[ REDACTED ]"),km.#At(n)}static createRandom(e){const t=bm.createRandom();return e?t.connect(e):t}static fromPhrase(e,t){const n=bm.fromPhrase(e);return t?n.connect(t):n}}var Sm=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Im=function(){return Im=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Im.apply(this,arguments)},Cm=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},Om=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Tm=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return n.MESSAGE_TO_SIGN="I Love Shogun!",n.DEFAULT_CONFIG={cacheDuration:18e5,maxRetries:3,retryDelay:1e3,timeout:6e4},n.signatureCache=new Map,n.provider=null,n.customProvider=null,n.customWallet=null,n.config=Im(Im({},n.DEFAULT_CONFIG),t),n.initProvider(),n.setupEventListeners(),n}return Sm(t,e),t.prototype.initProvider=function(){if("undefined"!=typeof window)try{var e=t.getAvailableEthereumProvider();e?this.provider=new ug(e):console.warn("No compatible Ethereum provider found")}catch(e){console.error("Failed to initialize BrowserProvider",e)}else console.warn("Window object not available (non-browser environment)")},t.getAvailableEthereumProvider=function(){var e,n;if("undefined"!=typeof window){if(void 0!==t.cachedEthereumProvider)return t.cachedEthereumProvider||void 0;var r=[{source:function(){return window._ethereumProviders&&window._ethereumProviders[0]},name:"Registry Primary"},{source:function(){return window.ethereum},name:"Standard ethereum"},{source:function(){var e;return null===(e=window.web3)||void 0===e?void 0:e.currentProvider},name:"Legacy web3"},{source:function(){return window.metamask},name:"MetaMask specific"},{source:function(){var e,t;return null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.providers)||void 0===t?void 0:t.find(function(e){return e.isMetaMask})},name:"MetaMask from providers array"},{source:function(){var e,t;return null===(t=null===(e=window.ethereum)||void 0===e?void 0:e.providers)||void 0===t?void 0:t[0]},name:"First provider in array"},{source:function(){var e,t;return null===(t=null===(e=window.enkrypt)||void 0===e?void 0:e.providers)||void 0===t?void 0:t.ethereum},name:"Enkrypt"},{source:function(){return window.coinbaseWalletExtension},name:"Coinbase"},{source:function(){return window.trustWallet},name:"Trust Wallet"},{source:function(){return Array.isArray(window._ethereumProviders)?window._ethereumProviders.find(function(e){return!e._isProxy}):void 0},name:"Registry non-proxy"}];try{for(var o=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(r),i=o.next();!i.done;i=o.next()){var s=i.value,a=s.source,c=s.name;try{var u=a();if(u&&"function"==typeof u.request)return t.cachedEthereumProvider=u,u}catch(e){console.warn("Error checking provider ".concat(c,":"),e);continue}}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}console.warn("No compatible Ethereum provider found"),t.cachedEthereumProvider=null}},t.prototype.setupProvider=function(){return Cm(this,void 0,void 0,function(){var e;return Om(this,function(n){try{"undefined"!=typeof window?(e=t.getAvailableEthereumProvider())?this.provider=new ug(e):console.warn("No compatible Ethereum provider found"):console.warn("Window object not available (non-browser environment)")}catch(e){console.error("Failed to initialize BrowserProvider",e)}return[2]})})},t.prototype.setupEventListeners=function(){var e=this;if(this.provider){this.provider.on("network",function(t,n){e.emit("chainChanged",t)});try{var n=t.getAvailableEthereumProvider();(null==n?void 0:n.on)&&(n.on("accountsChanged",function(t){e.emit("accountsChanged",t)}),n.on("chainChanged",function(t){e.emit("chainChanged",{chainId:t})}))}catch(e){console.warn("Failed to setup account change listeners",e)}}},t.prototype.cleanup=function(){this.provider&&this.provider.removeAllListeners(),this.removeAllListeners()},t.prototype.getCachedSignature=function(e){var t=this.signatureCache.get(e);return t?Date.now()-t.timestamp>this.config.cacheDuration?(this.signatureCache.delete(e),null):!t.signature||"string"!=typeof t.signature||t.signature.length<16?(console.warn("Invalid cached signature for address ".concat(e," (length: ").concat(t.signature?t.signature.length:0,"), deleting from cache.")),this.signatureCache.delete(e),null):t.signature:null},t.prototype.cacheSignature=function(e,t){this.signatureCache.set(e,{signature:t,timestamp:Date.now(),address:e})},t.prototype.validateAddress=function(e){if(!e)throw new Error("Address not provided");try{var t=String(e).trim().toLowerCase();if(!function(e){try{return Ya(e),!0}catch(e){}return!1}(t))throw new Error("Invalid address format");return Ya(t)}catch(e){throw K.handle(j.VALIDATION,"INVALID_ADDRESS","Invalid Ethereum address provided",e),e}},t.prototype.connectMetaMask=function(){return Cm(this,void 0,void 0,function(){var e,n,r,o,i,s,a,c,u,l=this;return Om(this,function(f){switch(f.label){case 0:if(f.trys.push([0,19,,20]),!this.provider&&(this.initProvider(),!this.provider))throw new Error("MetaMask is not available. Please install MetaMask extension.");if(!(e=t.getAvailableEthereumProvider()))throw new Error("No compatible Ethereum provider found");n=[],f.label=1;case 1:return f.trys.push([1,3,,10]),[4,e.request({method:"eth_requestAccounts"})];case 2:return n=f.sent(),[3,10];case 3:if(r=f.sent(),console.warn("First account request failed, trying window.ethereum:",r),!window.ethereum||window.ethereum===e)return[3,8];f.label=4;case 4:return f.trys.push([4,6,,7]),[4,window.ethereum.request({method:"eth_requestAccounts"})];case 5:return n=f.sent(),[3,7];case 6:throw o=f.sent(),console.error("All account request methods failed",o),new Error("User denied account access");case 7:return[3,9];case 8:throw new Error("User denied account access");case 9:return[3,10];case 10:!n||n.length,i=1,f.label=11;case 11:if(!(i<=this.config.maxRetries))return[3,18];f.label=12;case 12:return f.trys.push([12,15,,17]),[4,this.provider.getSigner()];case 13:return[4,f.sent().getAddress()];case 14:if(!(s=f.sent()))throw console.error("No address returned from signer"),new Error("No address returned from signer");return this.emit("connected",{address:s}),[2,{success:!0,address:s}];case 15:if(a=f.sent(),console.error("Attempt ".concat(i," failed:"),a),i===this.config.maxRetries)throw a;return[4,new Promise(function(e){return setTimeout(e,l.config.retryDelay)})];case 16:return f.sent(),[3,17];case 17:return i++,[3,11];case 18:throw new Error("Failed to get signer after all attempts");case 19:return c=f.sent(),console.error("Failed to connect to MetaMask:",c),K.handle(j.WEBAUTHN,"METAMASK_CONNECTION_ERROR",null!==(u=c.message)&&void 0!==u?u:"Unknown error while connecting to MetaMask",c),[2,{success:!1,error:c.message}];case 20:return[2]}})})},t.prototype.generateCredentials=function(e){return Cm(this,void 0,void 0,function(){var t,n,r,o,i,s;return Om(this,function(a){switch(a.label){case 0:if(a.trys.push([0,5,,6]),t=this.validateAddress(e),n=this.getCachedSignature(t))return[2,this.generateCredentialsFromSignature(t,n)];r=void 0,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.requestSignatureWithTimeout(t,this.MESSAGE_TO_SIGN,this.config.timeout)];case 2:return r=a.sent(),[3,4];case 3:throw o=a.sent(),console.warn("Failed to get signature: ".concat(o,". Using fallback method.")),o;case 4:return this.cacheSignature(t,r),[2,this.generateCredentialsFromSignature(t,r)];case 5:throw i=a.sent(),K.handle(j.WEBAUTHN,"CREDENTIALS_GENERATION_ERROR",null!==(s=i.message)&&void 0!==s?s:"Error generating MetaMask credentials",i),i;case 6:return[2]}})})},t.prototype.generateCredentialsFromSignature=function(e,t){return Cm(this,void 0,void 0,function(){var n,r;return Om(this,function(o){switch(o.label){case 0:return n=Vt(xe(e)),r="".concat(e,"_").concat(t),[4,di(n,r,{includeP256:!0})];case 1:return[2,o.sent()]}})})},t.prototype.generateFallbackCredentials=function(e){console.warn("Using fallback credentials generation for address:",e);var t=Vt(xe(e+"fallback"));return{username:e.toLowerCase(),password:t,message:this.MESSAGE_TO_SIGN,signature:t}},t.isMetaMaskAvailable=function(){return!!t.getAvailableEthereumProvider()},t.prototype.requestSignatureWithTimeout=function(e,t,n){var r=this;return void 0===n&&(n=3e4),new Promise(function(o,i){var s=setTimeout(function(){i(new Error("Signature request timed out"))},n),a=function(){clearTimeout(s)};Cm(r,void 0,void 0,function(){var n,r,s,c;return Om(this,function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),[4,this.provider.getSigner()];case 1:return[4,(n=u.sent()).getAddress()];case 2:if((r=u.sent()).toLowerCase()!==e.toLowerCase())throw new Error("Signer address (".concat(r,") does not match expected address (").concat(e,")"));return[4,n.signMessage(t)];case 3:return s=u.sent(),a(),o(s),[3,5];case 4:return c=u.sent(),console.error("Failed to request signature:",c),l=c,a(),i(l),[3,5];case 5:return[2]}var l})})})},t.prototype.isAvailable=function(){return t.isMetaMaskAvailable()},t.prototype.setCustomProvider=function(e,t){var n;try{this.customProvider=new sg(e),this.customWallet=new km(t,this.customProvider)}catch(e){throw new Error("Error configuring provider: ".concat(null!==(n=e.message)&&void 0!==n?n:"Unknown error"))}},t.prototype.getSigner=function(){return Cm(this,void 0,void 0,function(){var e;return Om(this,function(t){switch(t.label){case 0:if(t.trys.push([0,2,,3]),this.customWallet)return[2,this.customWallet];if(this.provider||this.initProvider(),!this.provider)throw new Error("Provider not initialized");return[4,this.provider.getSigner()];case 1:return[2,t.sent()];case 2:throw e=t.sent(),new Error("Unable to get Ethereum signer: ".concat(e.message||"Unknown error"));case 3:return[2]}})})},t.prototype.getProvider=function(){return Cm(this,void 0,void 0,function(){return Om(this,function(e){return this.customProvider?[2,this.customProvider]:(this.provider||this.initProvider(),[2,this.provider])})})},t.prototype.generatePassword=function(e){return Cm(this,void 0,void 0,function(){return Om(this,function(t){if(!e)throw new Error("Invalid signature");return[2,Vt(xe(e)).slice(2,66)]})})},t.prototype.verifySignature=function(e,t){return Cm(this,void 0,void 0,function(){return Om(this,function(n){if(!e||!t)throw new Error("Invalid message or signature");try{return[2,fg(e,t)]}catch(e){throw new Error("Invalid message or signature")}})})},t.prototype.getEthereumSigner=function(){return Cm(this,void 0,void 0,function(){var e,n,r;return Om(this,function(o){switch(o.label){case 0:if(!t.isMetaMaskAvailable())throw new Error("MetaMask not found. Please install MetaMask to continue.");o.label=1;case 1:return o.trys.push([1,3,,4]),[4,(e=window.ethereum).request({method:"eth_requestAccounts"})];case 2:return o.sent(),[2,new ug(e).getSigner()];case 3:throw n=o.sent(),new Error("Error accessing MetaMask: ".concat(null!==(r=n.message)&&void 0!==r?r:"Unknown error"));case 4:return[2]}})})},t.cachedEthereumProvider=void 0,t}(W);"undefined"!=typeof window?window.Web3Connector=Tm:void 0!==r.g&&(r.g.Web3Connector=Tm);var Nm=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},Pm=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Bm=function(){function e(e){this.credentials=new Map,this.MESSAGE_TO_SIGN="I Love Shogun!",this.web3Connector=e||new Tm}return e.prototype.createSigningCredential=function(e){return Nm(this,void 0,void 0,function(){var t,n,r,o,i,s;return Pm(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),t=Ya(e.toLowerCase()),[4,this.requestSignature(t)];case 1:return n=a.sent(),r="".concat(t.toLowerCase()),o=Vt(xe("".concat(t.toLowerCase(),":shogun-web3"))),i={address:t,signature:n,message:this.MESSAGE_TO_SIGN,username:r,password:o},this.credentials.set(t.toLowerCase(),i),[2,i];case 2:throw s=a.sent(),K.handle(j.WALLET,"WEB3_CREDENTIAL_ERROR","Error creating Web3 signing credential",s),new Error("Failed to create Web3 signing credential: ".concat(s.message));case 3:return[2]}})})},e.prototype.requestSignature=function(e){return Nm(this,void 0,void 0,function(){var t,n,r;return Pm(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,this.web3Connector.getSigner()];case 1:return[4,(t=o.sent()).getAddress()];case 2:if((n=o.sent()).toLowerCase()!==e.toLowerCase())throw new Error("Signer address (".concat(n,") does not match expected address (").concat(e,")"));return[4,t.signMessage(this.MESSAGE_TO_SIGN)];case 3:return[2,o.sent()];case 4:throw r=o.sent(),K.handle(j.WALLET,"WEB3_SIGNATURE_ERROR","Failed to request signature",r),r;case 5:return[2]}})})},e.prototype.createAuthenticator=function(e){var t=this;if(!this.credentials.get(e.toLowerCase()))throw new Error("Credential for address ".concat(e," not found"));return function(n){return Nm(t,void 0,void 0,function(){var t,r,o;return Pm(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),[4,this.web3Connector.getSigner()];case 1:return[4,(t=i.sent()).getAddress()];case 2:if(i.sent().toLowerCase()!==e.toLowerCase())throw new Error("Address mismatch during authentication");return r=JSON.stringify(n),[4,t.signMessage(r)];case 3:return[2,i.sent()];case 4:throw o=i.sent(),K.handle(j.AUTHENTICATION,"WEB3_AUTH_ERROR","Web3 authentication error",o),o;case 5:return[2]}})})}},e.prototype.createDerivedKeyPair=function(e,t){return Nm(this,void 0,void 0,function(){return Pm(this,function(n){return[2,this.createDerivedKeyPairFromAddress(e,t)]})})},e.prototype.authenticateWithExistingPair=function(e,t){return Nm(this,void 0,void 0,function(){var n,r;return Pm(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.createDerivedKeyPairFromAddress(e)];case 1:return n=o.sent(),[2,new Promise(function(e){t.user().auth(n,function(t){if(t.err)K.handle(j.AUTHENTICATION,"WEB3_GUN_AUTH_FAILED","Web3Signer - GunDB auth failed",t.err),e({success:!1,error:t.err});else{var n=t.pub;e({success:!0,userPub:n})}})})];case 2:return r=o.sent(),K.handle(j.AUTHENTICATION,"WEB3_AUTH_EXISTING_FAILED","Error authenticating with deterministic pair",r),[2,{success:!1,error:r.message}];case 3:return[2]}})})},e.prototype.createDerivedKeyPairFromAddress=function(e,t){return Nm(this,void 0,void 0,function(){var n,r,o;return Pm(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),n=Ya(e.toLowerCase()),[4,di(Vt(xe("".concat(n.toLowerCase(),":shogun-web3"))),t,{includeP256:!0})];case 1:return[2,{pub:(r=i.sent()).pub,priv:r.priv,epub:r.epub,epriv:r.epriv}];case 2:throw o=i.sent(),K.handle(j.ENCRYPTION,"WEB3_KEY_DERIVATION_ERROR","Error creating derived key pair from address",o),o;case 3:return[2]}})})},e.prototype.createGunUser=function(e,t){return Nm(this,void 0,void 0,function(){var n,r;return Pm(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.createDerivedKeyPairFromAddress(e)];case 1:return n=o.sent(),[2,new Promise(function(e){t.user().create(n,function(r){r.err?(K.handle(j.DATABASE,"WEB3_USER_CREATION_FAILED","Web3Signer - user creation failed, trying auth",r.err),t.user().auth(n,function(t){if(t.err)K.handle(j.AUTHENTICATION,"WEB3_USER_AUTH_FAILED","Web3Signer - auth also failed",t.err),e({success:!1,error:t.err});else{var n=t.pub;e({success:!0,userPub:n})}})):t.user().auth(n,function(t){if(t.err)K.handle(j.AUTHENTICATION,"WEB3_LOGIN_AFTER_CREATION_FAILED","Web3Signer - login after creation failed",t.err),e({success:!1,error:t.err});else{var n=t.pub;e({success:!0,userPub:n})}})})})];case 2:return r=o.sent(),K.handle(j.DATABASE,"WEB3_CREATE_USER_ERROR","Error creating Gun user",r),[2,{success:!1,error:r.message}];case 3:return[2]}})})},e.prototype.signWithDerivedKeys=function(e,t,n){return Nm(this,void 0,void 0,function(){var r,o,i,s,a;return Pm(this,function(c){switch(c.label){case 0:return c.trys.push([0,4,,5]),[4,this.createAuthenticator(t)(e)];case 1:return c.sent(),[4,this.createDerivedKeyPair(t,n)];case 2:return r=c.sent(),Vt(xe(o=JSON.stringify(e))),[4,new km(r.priv).signMessage(o)];case 3:return i=c.sent(),s={m:o,s:i},[2,"SEA"+JSON.stringify(s)];case 4:throw a=c.sent(),K.handle(j.SIGNATURE,"WEB3_DERIVED_SIGN_ERROR","Error signing with derived keys",a),a;case 5:return[2]}})})},e.prototype.getGunUserPub=function(e){return Nm(this,void 0,void 0,function(){var t;return Pm(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.createDerivedKeyPairFromAddress(e)];case 1:return[2,n.sent().pub];case 2:return t=n.sent(),K.handle(j.ENCRYPTION,"WEB3_GET_PUB_ERROR","Error getting Gun user pub",t),[2,void 0];case 3:return[2]}})})},e.prototype.getPassword=function(e){try{var t=Ya(e.toLowerCase());return Vt(xe("".concat(t.toLowerCase(),":shogun-web3")))}catch(e){return void K.handle(j.ENCRYPTION,"WEB3_GET_PASSWORD_ERROR","Error getting password",e)}},e.prototype.verifyConsistency=function(e,t){return Nm(this,void 0,void 0,function(){var n,r;return Pm(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.createDerivedKeyPairFromAddress(e)];case 1:return n=o.sent(),[2,{consistent:!t||n.pub===t,actualUserPub:n.pub,expectedUserPub:t}];case 2:return r=o.sent(),K.handle(j.ENCRYPTION,"WEB3_CONSISTENCY_ERROR","Error verifying consistency",r),[2,{consistent:!1}];case 3:return[2]}})})},e.prototype.getCredential=function(e){return this.credentials.get(e.toLowerCase())},e.prototype.listCredentials=function(){return Array.from(this.credentials.values())},e.prototype.removeCredential=function(e){return this.credentials.delete(e.toLowerCase())},e}(),Rm=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Um=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},Dm=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Lm=function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.name="web3",t.version="1.0.0",t.description="Provides Ethereum wallet connection and authentication for ShogunCore",t.Web3=null,t.signer=null,t}return Rm(t,e),t.prototype.initialize=function(t){e.prototype.initialize.call(this,t),this.Web3=new Tm,this.signer=new Bm(this.Web3)},t.prototype.destroy=function(){this.Web3&&this.Web3.cleanup(),this.Web3=null,this.signer=null,e.prototype.destroy.call(this)},t.prototype.assertMetaMask=function(){if(this.assertInitialized(),!this.Web3)throw new Error("Web3 module not initialized");return this.Web3},t.prototype.assertSigner=function(){if(this.assertInitialized(),!this.signer)throw new Error("Web3 signer not initialized");return this.signer},t.prototype.isAvailable=function(){return this.assertMetaMask().isAvailable()},t.prototype.connectMetaMask=function(){return Um(this,void 0,void 0,function(){return Dm(this,function(e){return[2,this.assertMetaMask().connectMetaMask()]})})},t.prototype.generateCredentials=function(e){return Um(this,void 0,void 0,function(){return Dm(this,function(t){return[2,this.assertMetaMask().generateCredentials(e)]})})},t.prototype.cleanup=function(){this.assertMetaMask().cleanup()},t.prototype.setCustomProvider=function(e,t){this.assertMetaMask().setCustomProvider(e,t)},t.prototype.getSigner=function(){return Um(this,void 0,void 0,function(){return Dm(this,function(e){return[2,this.assertMetaMask().getSigner()]})})},t.prototype.getProvider=function(){return Um(this,void 0,void 0,function(){return Dm(this,function(e){return[2,this.assertMetaMask().getProvider()]})})},t.prototype.generatePassword=function(e){return Um(this,void 0,void 0,function(){return Dm(this,function(t){return[2,this.assertMetaMask().generatePassword(e)]})})},t.prototype.verifySignature=function(e,t){return Um(this,void 0,void 0,function(){return Dm(this,function(n){return[2,this.assertMetaMask().verifySignature(e,t)]})})},t.prototype.createSigningCredential=function(e){return Um(this,void 0,void 0,function(){var t,n;return Dm(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),"function"!=typeof(t=this.assertMetaMask()).createSigningCredential?[3,2]:[4,t.createSigningCredential(e)];case 1:case 3:return[2,r.sent()];case 2:return[4,this.assertSigner().createSigningCredential(e)];case 4:throw n=r.sent(),console.error("Error creating Web3 signing credential: ".concat(n.message)),n;case 5:return[2]}})})},t.prototype.createAuthenticator=function(e){try{var t=this.assertMetaMask();return"function"==typeof t.createAuthenticator?t.createAuthenticator(e):this.assertSigner().createAuthenticator(e)}catch(e){throw console.error("Error creating Web3 authenticator: ".concat(e.message)),e}},t.prototype.createDerivedKeyPair=function(e,t){return Um(this,void 0,void 0,function(){var n,r;return Dm(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(n=this.assertMetaMask()).createDerivedKeyPair?[3,2]:[4,n.createDerivedKeyPair(e,t)];case 1:case 3:return[2,o.sent()];case 2:return[4,this.assertSigner().createDerivedKeyPair(e,t)];case 4:throw r=o.sent(),console.error("Error creating derived key pair: ".concat(r.message)),r;case 5:return[2]}})})},t.prototype.signWithDerivedKeys=function(e,t,n){return Um(this,void 0,void 0,function(){var r,o;return Dm(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(r=this.assertMetaMask()).signWithDerivedKeys?[3,2]:[4,r.signWithDerivedKeys(e,t,n)];case 1:case 3:return[2,i.sent()];case 2:return[4,this.assertSigner().signWithDerivedKeys(e,t,n)];case 4:throw o=i.sent(),console.error("Error signing with derived keys: ".concat(o.message)),o;case 5:return[2]}})})},t.prototype.getSigningCredential=function(e){var t=this.assertMetaMask();return"function"==typeof t.getSigningCredential?t.getSigningCredential(e):this.assertSigner().getCredential(e)},t.prototype.listSigningCredentials=function(){var e=this.assertMetaMask();return"function"==typeof e.listSigningCredentials?e.listSigningCredentials():this.assertSigner().listCredentials()},t.prototype.removeSigningCredential=function(e){var t=this.assertMetaMask();return"function"==typeof t.removeSigningCredential?t.removeSigningCredential(e):this.assertSigner().removeCredential(e)},t.prototype.createGunUserFromSigningCredential=function(e){return Um(this,void 0,void 0,function(){var t,n,r,o,i,s;return Dm(this,function(a){switch(a.label){case 0:return a.trys.push([0,5,,6]),console.log("🔧 createGunUserFromSigningCredential called with address:",e),"function"!=typeof(t=this.assertMetaMask()).createGunUserFromSigningCredential?[3,2]:(console.log("🔧 Using connector's createGunUserFromSigningCredential"),[4,t.createGunUserFromSigningCredential(e)]);case 1:return n=a.sent(),console.log("🔧 Connector result:",n),[2,n];case 2:return console.log("🔧 Using fallback createGunUser"),r=this.assertInitialized(),console.log("🔧 Attempting authentication with deterministic pair"),[4,this.assertSigner().authenticateWithExistingPair(e,r.gun)];case 3:return(o=a.sent()).success?(console.log("🔧 Authentication successful with existing user"),[2,o]):(console.log("🔧 Authentication failed, creating new user"),[4,this.assertSigner().createGunUser(e,r.gun)]);case 4:return i=a.sent(),console.log("🔧 User creation result:",i),[2,i];case 5:throw s=a.sent(),console.error("Error creating Gun user from Web3 signing credential: ".concat(s.message)),s;case 6:return[2]}})})},t.prototype.getGunUserPubFromSigningCredential=function(e){return Um(this,void 0,void 0,function(){var t;return Dm(this,function(n){switch(n.label){case 0:return"function"!=typeof(t=this.assertMetaMask()).getGunUserPubFromSigningCredential?[3,2]:[4,t.getGunUserPubFromSigningCredential(e)];case 1:case 3:return[2,n.sent()];case 2:return[4,this.assertSigner().getGunUserPub(e)]}})})},t.prototype.getPassword=function(e){var t=this.assertMetaMask();return"function"==typeof t.getPassword?t.getPassword(e):this.assertSigner().getPassword(e)},t.prototype.verifyConsistency=function(e,t){return Um(this,void 0,void 0,function(){var n,r;return Dm(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(n=this.assertMetaMask()).verifyConsistency?[3,2]:[4,n.verifyConsistency(e,t)];case 1:case 3:return[2,o.sent()];case 2:return[4,this.assertSigner().verifyConsistency(e,t)];case 4:return r=o.sent(),console.error("Error verifying Web3 consistency: ".concat(r.message)),[2,{consistent:!1}];case 5:return[2]}})})},t.prototype.setupConsistentOneshotSigning=function(e){return Um(this,void 0,void 0,function(){var t,n,r,o,i;return Dm(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),"function"!=typeof(t=this.assertMetaMask()).setupConsistentOneshotSigning?[3,2]:[4,t.setupConsistentOneshotSigning(e)];case 1:return[2,s.sent()];case 2:return[4,this.createSigningCredential(e)];case 3:return n=s.sent(),r=this.createAuthenticator(e),[4,this.createGunUserFromSigningCredential(e)];case 4:return o=s.sent(),[2,{credential:n,authenticator:r,gunUser:o,username:e,password:"web3-generated-password"}];case 5:throw i=s.sent(),console.error("Error setting up consistent Web3 oneshot signing: ".concat(i.message)),i;case 6:return[2]}})})},t.prototype.login=function(e){return Um(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c,u,l,f;return Dm(this,function(h){switch(h.label){case 0:if(h.trys.push([0,4,,5]),t=this.assertInitialized(),!e)throw z(j.VALIDATION,"ADDRESS_REQUIRED","Ethereum address required for Web3 login");if(!this.isAvailable())throw z(j.ENVIRONMENT,"WEB3_UNAVAILABLE","Web3 is not available in the browser");return console.log("🔧 Web3 login - starting login for address:",e),this.getSigningCredential(e)?(console.log("🔧 Web3 login - found existing credential, using it"),[4,this.createGunUserFromSigningCredential(e)]):[3,2];case 1:if(n=h.sent(),console.log("🔧 Web3 login - existing credential result:",n),n.success&&n.userPub)return t.setAuthMethod("web3"),r={success:!0,user:{userPub:n.userPub,username:e},userPub:n.userPub},console.log("🔧 Web3 login - returning result:",{success:r.success,userPub:r.userPub?r.userPub.slice(0,8)+"...":"null",username:null===(l=r.user)||void 0===l?void 0:l.username}),t.emit("auth:login",{userPub:n.userPub||"",username:e,method:"web3"}),[2,r];h.label=2;case 2:return console.log("🔧 Web3 login - no existing credential, creating new one"),[4,this.setupConsistentOneshotSigning(e)];case 3:if(o=h.sent().gunUser,console.log("🔧 Web3 login - setupConsistentOneshotSigning result:",{gunUser:o,address:e}),!o.success)throw z(j.AUTHENTICATION,"WEB3_LOGIN_FAILED",o.error||"Failed to log in with Web3 credentials");return console.log("🔧 Web3 login - gunUser success, userPub:",o.userPub?o.userPub.slice(0,8)+"...":"null"),t.setAuthMethod("web3"),i={success:!0,user:{userPub:o.userPub,username:e},userPub:o.userPub},console.log("🔧 Web3 login - returning result:",{success:i.success,userPub:i.userPub?i.userPub.slice(0,8)+"...":"null",username:null===(f=i.user)||void 0===f?void 0:f.username}),t.emit("auth:login",{userPub:o.userPub||"",username:e,method:"web3"}),[2,i];case 4:return s=h.sent(),a=(null==s?void 0:s.type)||j.AUTHENTICATION,c=(null==s?void 0:s.code)||"WEB3_LOGIN_ERROR",u=(null==s?void 0:s.message)||"Unknown error during Web3 login",K.handle(a,c,u,s),[2,{success:!1,error:u}];case 5:return[2]}})})},t.prototype.signUp=function(e){return Um(this,void 0,void 0,function(){var t,n,r,o,i,s;return Dm(this,function(a){switch(a.label){case 0:if(a.trys.push([0,2,,3]),t=this.assertInitialized(),!e)throw z(j.VALIDATION,"ADDRESS_REQUIRED","Ethereum address required for Web3 registration");if(!this.isAvailable())throw z(j.ENVIRONMENT,"WEB3_UNAVAILABLE","Web3 is not available in the browser");return[4,this.setupConsistentOneshotSigning(e)];case 1:if(!(n=a.sent().gunUser).success)throw z(j.AUTHENTICATION,"WEB3_SIGNUP_FAILED",n.error||"Failed to sign up with Web3 credentials");return t.setAuthMethod("web3"),[2,{success:!0,user:{userPub:n.userPub,username:e},userPub:n.userPub}];case 2:return r=a.sent(),o=(null==r?void 0:r.type)||j.AUTHENTICATION,i=(null==r?void 0:r.code)||"WEB3_SIGNUP_ERROR",s=(null==r?void 0:r.message)||"Unknown error during Web3 registration",K.handle(o,i,s,r),[2,{success:!1,error:s}];case 3:return[2]}})})},t}(q);function Fm(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function _m(e,t=""){if(!Number.isSafeInteger(e)||e<0)throw new Error(`${t&&`"${t}" `}expected integer >= 0, got ${e}`)}function Mm(e,t,n=""){const r=Fm(e),o=e?.length,i=void 0!==t;if(!r||i&&o!==t)throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(i?` of length ${t}`:"")+", got "+(r?`length=${o}`:"type="+typeof e));return e}function Gm(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash must wrapped by utils.createHasher");_m(e.outputLen),_m(e.blockLen)}function jm(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Hm(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function zm(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Vm(e,t){return e<<32-t|e>>>t}const Km=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),Wm=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $m(e){if(Mm(e),Km)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=Wm[e[n]];return t}function qm(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Jm(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(Km)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,o=0;t<n;t++,o+=2){const n=qm(e.charCodeAt(o)),i=qm(e.charCodeAt(o+1));if(void 0===n||void 0===i){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}r[t]=16*n+i}return r}function Qm(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];Mm(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const o=e[t];n.set(o,r),r+=o.length}return n}function Zm(e,t={}){const n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function Ym(e=32){const t="object"==typeof globalThis?globalThis.crypto:null;if("function"!=typeof t?.getRandomValues)throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}const Xm=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ew(e,t,n){return e&t^~e&n}function tw(e,t,n){return e&t^e&n^t&n}class nw{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=zm(this.buffer)}update(e){jm(this),Mm(e);const{view:t,buffer:n,blockLen:r}=this,o=e.length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=zm(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){jm(this),function(e,t){Mm(e,void 0,"digestInto() output");const n=t.outputLen;if(e.length<n)throw new Error('"digestInto() output" expected to be of length >='+n)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,Hm(this.buffer.subarray(i)),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;n.setBigUint64(r-8,BigInt(8*this.length),o),this.process(n,0);const s=zm(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const rw=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ow=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),iw=new Uint32Array(64);class sw extends nw{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)iw[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=iw[e-15],n=iw[e-2],r=Vm(t,7)^Vm(t,18)^t>>>3,o=Vm(n,17)^Vm(n,19)^n>>>10;iw[e]=o+iw[e-7]+r+iw[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(Vm(s,6)^Vm(s,11)^Vm(s,25))+ew(s,a,c)+ow[e]+iw[e]|0,l=(Vm(n,2)^Vm(n,13)^Vm(n,22))+tw(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){Hm(iw)}destroy(){this.set(0,0,0,0,0,0,0,0),Hm(this.buffer)}}class aw extends sw{A=0|rw[0];B=0|rw[1];C=0|rw[2];D=0|rw[3];E=0|rw[4];F=0|rw[5];G=0|rw[6];H=0|rw[7];constructor(){super(32)}}const cw=Zm(()=>new aw,Xm(1)),uw=BigInt(0),lw=BigInt(1);function fw(e,t=""){if("boolean"!=typeof e)throw new Error((t&&`"${t}" `)+"expected boolean, got type="+typeof e);return e}function hw(e){if("bigint"==typeof e){if(!bw(e))throw new Error("positive bigint expected, got "+e)}else _m(e);return e}function dw(e){const t=hw(e).toString(16);return 1&t.length?"0"+t:t}function pw(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?uw:BigInt("0x"+e)}function gw(e){return pw($m(e))}function yw(e){return pw($m(function(e){return Uint8Array.from(e)}(Mm(e)).reverse()))}function mw(e,t){_m(t);const n=Jm((e=hw(e)).toString(16).padStart(2*t,"0"));if(n.length!==t)throw new Error("number too large");return n}function ww(e,t){return mw(e,t).reverse()}const bw=e=>"bigint"==typeof e&&uw<=e;const vw=e=>(lw<<BigInt(e))-lw;function Ew(e,t={},n={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");const r=(t,n)=>Object.entries(t).forEach(([t,r])=>function(t,n,r){const o=e[t];if(r&&void 0===o)return;const i=typeof o;if(i!==n||null===o)throw new Error(`param "${t}" is invalid: expected ${n}, got ${i}`)}(t,r,n));r(t,!1),r(n,!0)}function Aw(e){const t=new WeakMap;return(n,...r)=>{const o=t.get(n);if(void 0!==o)return o;const i=e(n,...r);return t.set(n,i),i}}const xw=BigInt(0),kw=BigInt(1),Sw=BigInt(2),Iw=BigInt(3),Cw=BigInt(4),Ow=BigInt(5),Tw=BigInt(7),Nw=BigInt(8),Pw=BigInt(9),Bw=BigInt(16);function Rw(e,t){const n=e%t;return n>=xw?n:t+n}function Uw(e,t,n){let r=e;for(;t-- >xw;)r*=r,r%=n;return r}function Dw(e,t){if(e===xw)throw new Error("invert: expected non-zero number");if(t<=xw)throw new Error("invert: expected positive modulus, got "+t);let n=Rw(e,t),r=t,o=xw,i=kw,s=kw,a=xw;for(;n!==xw;){const e=r/n,t=r%n,c=o-s*e,u=i-a*e;r=n,n=t,o=s,i=a,s=c,a=u}if(r!==kw)throw new Error("invert: does not exist");return Rw(o,t)}function Lw(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function Fw(e,t){const n=(e.ORDER+kw)/Cw,r=e.pow(t,n);return Lw(e,r,t),r}function _w(e,t){const n=(e.ORDER-Ow)/Nw,r=e.mul(t,Sw),o=e.pow(r,n),i=e.mul(t,o),s=e.mul(e.mul(i,Sw),o),a=e.mul(i,e.sub(s,e.ONE));return Lw(e,a,t),a}function Mw(e){if(e<Iw)throw new Error("sqrt is not defined for small field");let t=e-kw,n=0;for(;t%Sw===xw;)t/=Sw,n++;let r=Sw;const o=Vw(e);for(;1===Hw(o,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return Fw;let i=o.pow(r,t);const s=(t+kw)/Sw;return function(e,r){if(e.is0(r))return r;if(1!==Hw(e,r))throw new Error("Cannot find square root");let o=n,a=e.mul(e.ONE,i),c=e.pow(r,t),u=e.pow(r,s);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===o)throw new Error("Cannot find square root");const r=kw<<BigInt(o-t-1),i=e.pow(a,r);o=t,a=e.sqr(i),c=e.mul(c,a),u=e.mul(u,i)}return u}}const Gw=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function jw(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),o=t.reduce((t,n,o)=>e.is0(n)?t:(r[o]=t,e.mul(t,n)),e.ONE),i=e.inv(o);return t.reduceRight((t,n,o)=>e.is0(n)?t:(r[o]=e.mul(t,r[o]),e.mul(t,n)),i),r}function Hw(e,t){const n=(e.ORDER-kw)/Sw,r=e.pow(t,n),o=e.eql(r,e.ONE),i=e.eql(r,e.ZERO),s=e.eql(r,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}class zw{ORDER;BITS;BYTES;isLE;ZERO=xw;ONE=kw;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=xw)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,null!=t&&"object"==typeof t&&("number"==typeof t.BITS&&(n=t.BITS),"function"==typeof t.sqrt&&(this.sqrt=t.sqrt),"boolean"==typeof t.isLE&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),"boolean"==typeof t.modFromBytes&&(this._mod=t.modFromBytes));const{nBitLength:r,nByteLength:o}=function(e,t){void 0!==t&&_m(t);const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=r,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return Rw(e,this.ORDER)}isValid(e){if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return xw<=e&&e<this.ORDER}is0(e){return e===xw}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&kw)===kw}neg(e){return Rw(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return Rw(e*e,this.ORDER)}add(e,t){return Rw(e+t,this.ORDER)}sub(e,t){return Rw(e-t,this.ORDER)}mul(e,t){return Rw(e*t,this.ORDER)}pow(e,t){return function(e,t,n){if(n<xw)throw new Error("invalid exponent, negatives unsupported");if(n===xw)return e.ONE;if(n===kw)return t;let r=e.ONE,o=t;for(;n>xw;)n&kw&&(r=e.mul(r,o)),o=e.sqr(o),n>>=kw;return r}(this,e,t)}div(e,t){return Rw(e*Dw(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Dw(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=(t=this.ORDER)%Cw===Iw?Fw:t%Nw===Ow?_w:t%Bw===Pw?function(e){const t=Vw(e),n=Mw(e),r=n(t,t.neg(t.ONE)),o=n(t,r),i=n(t,t.neg(r)),s=(e+Tw)/Bw;return(e,t)=>{let n=e.pow(t,s),a=e.mul(n,r);const c=e.mul(n,o),u=e.mul(n,i),l=e.eql(e.sqr(a),t),f=e.eql(e.sqr(c),t);n=e.cmov(n,a,l),a=e.cmov(u,c,f);const h=e.eql(e.sqr(a),t),d=e.cmov(n,a,h);return Lw(e,d,t),d}}(t):Mw(t)),this._sqrt(this,e);var t}toBytes(e){return this.isLE?ww(e,this.BYTES):mw(e,this.BYTES)}fromBytes(e,t=!1){Mm(e);const{_lengths:n,BYTES:r,isLE:o,ORDER:i,_mod:s}=this;if(n){if(!n.includes(e.length)||e.length>r)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);const t=new Uint8Array(r);t.set(e,o?0:t.length-e.length),e=t}if(e.length!==r)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+e.length);let a=o?yw(e):gw(e);if(s&&(a=Rw(a,i)),!t&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return jw(this,e)}cmov(e,t,n){return n?t:e}}function Vw(e,t={}){return new zw(e,t)}function Kw(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Ww(e){const t=Kw(e);return t+Math.ceil(t/2)}function $w(e,t,n=!1){Mm(e);const r=e.length,o=Kw(t),i=Ww(t);if(r<16||r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);const s=Rw(n?yw(e):gw(e),t-kw)+kw;return n?ww(s,o):mw(s,o)}const qw=BigInt(0),Jw=BigInt(1);function Qw(e,t){const n=t.negate();return e?n:t}function Zw(e,t){const n=jw(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Yw(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Xw(e,t){Yw(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:vw(e),maxNumber:n,shiftBy:BigInt(e)}}function eb(e,t,n){const{windowSize:r,mask:o,maxNumber:i,shiftBy:s}=n;let a=Number(e&o),c=e>>s;a>r&&(a-=i,c+=Jw);const u=t*r;return{nextN:c,offset:u+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:u}}const tb=new WeakMap,nb=new WeakMap;function rb(e){return nb.get(e)||1}function ob(e){if(e!==qw)throw new Error("invalid wNAF")}class ib{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>qw;)t&Jw&&(n=n.add(r)),r=r.double(),t>>=Jw;return n}precomputeWindow(e,t){const{windows:n,windowSize:r}=Xw(t,this.bits),o=[];let i=e,s=i;for(let e=0;e<n;e++){s=i,o.push(s);for(let e=1;e<r;e++)s=s.add(i),o.push(s);i=s.double()}return o}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,o=this.BASE;const i=Xw(e,this.bits);for(let e=0;e<i.windows;e++){const{nextN:s,offset:a,isZero:c,isNeg:u,isNegF:l,offsetF:f}=eb(n,e,i);n=s,c?o=o.add(Qw(l,t[f])):r=r.add(Qw(u,t[a]))}return ob(n),{p:r,f:o}}wNAFUnsafe(e,t,n,r=this.ZERO){const o=Xw(e,this.bits);for(let e=0;e<o.windows&&n!==qw;e++){const{nextN:i,offset:s,isZero:a,isNeg:c}=eb(n,e,o);if(n=i,!a){const e=t[s];r=r.add(c?e.negate():e)}}return ob(n),r}getPrecomputes(e,t,n){let r=tb.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),tb.set(t,r))),r}cached(e,t,n){const r=rb(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){const o=rb(e);return 1===o?this._unsafeLadder(e,t,r):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),t,r)}createCache(e,t){Yw(t,this.bits),nb.set(e,t),tb.delete(e)}hasCache(e){return 1!==rb(e)}}function sb(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){Ew(e,Gw.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return Vw(e,{isLE:n})}function ab(e,t){return function(n){const r=e(n);return{secretKey:r,publicKey:t(r)}}}class cb{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(Gm(e),Mm(t,void 0,"key"),this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),Hm(r)}update(e){return jm(this),this.iHash.update(e),this}digestInto(e){jm(this),Mm(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const ub=(e,t,n)=>new cb(e,t).update(n).digest();ub.create=(e,t)=>new cb(e,t);const lb=(e,t)=>(e+(e>=0?t:-t)/mb)/t;function fb(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function hb(e,t){const n={};for(let r of Object.keys(t))n[r]=void 0===e[r]?t[r]:e[r];return fw(n.lowS,"lowS"),fw(n.prehash,"prehash"),void 0!==n.format&&fb(n.format),n}class db extends Error{constructor(e=""){super(e)}}const pb={Err:db,_tlv:{encode:(e,t)=>{const{Err:n}=pb;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");const r=t.length/2,o=dw(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");const i=r>127?dw(o.length/2|128):"";return dw(e)+i+o+t},decode(e,t){const{Err:n}=pb;let r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");const o=t[r++];let i=0;if(128&o){const e=127&o;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)i=i<<8|e;if(r+=e,i<128)throw new n("tlv.decode(long): not minimal encoding")}else i=o;const s=t.subarray(r,r+i);if(s.length!==i)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+i)}}},_int:{encode(e){const{Err:t}=pb;if(e<gb)throw new t("integer: negative integers are not allowed");let n=dw(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){const{Err:t}=pb;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return gw(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=pb,o=Mm(e,void 0,"signature"),{v:i,l:s}=r.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,i),{v:u,l}=r.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(e){const{_tlv:t,_int:n}=pb,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},gb=BigInt(0),yb=BigInt(1),mb=BigInt(2),wb=BigInt(3),bb=BigInt(4);function vb(e,t={}){const n=function(e,t,n={},r){if(void 0===r&&(r="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const n=t[e];if(!("bigint"==typeof n&&n>qw))throw new Error(`CURVE.${e} must be positive bigint`)}const o=sb(t.p,n.Fp,r),i=sb(t.n,n.Fn,r),s=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const e of s)if(!o.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:i}}("weierstrass",e,t),{Fp:r,Fn:o}=n;let i=n.CURVE;const{h:s,n:a}=i;Ew(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:c}=t;if(c&&(!r.is0(i.a)||"bigint"!=typeof c.beta||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Ab(r,o);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const f=t.toBytes||function(e,t,n){const{x:o,y:i}=t.toAffine(),s=r.toBytes(o);return fw(n,"isCompressed"),n?(l(),Qm(Eb(!r.isOdd(i)),s)):Qm(Uint8Array.of(4),s,r.toBytes(i))},h=t.fromBytes||function(e){Mm(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:n}=u,o=e.length,i=e[0],s=e.subarray(1);if(o!==t||2!==i&&3!==i){if(o===n&&4===i){const e=r.BYTES,t=r.fromBytes(s.subarray(0,e)),n=r.fromBytes(s.subarray(e,2*e));if(!p(t,n))throw new Error("bad point: is not on curve");return{x:t,y:n}}throw new Error(`bad point: got length ${o}, expected compressed=${t} or uncompressed=${n}`)}{const e=r.fromBytes(s);if(!r.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=d(e);let n;try{n=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}return l(),!(1&~i)!==r.isOdd(n)&&(n=r.neg(n)),{x:e,y:n}}};function d(e){const t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,i.a)),i.b)}function p(e,t){const n=r.sqr(t),o=d(e);return r.eql(n,o)}if(!p(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const g=r.mul(r.pow(i.a,wb),bb),y=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(g,y)))throw new Error("bad curve params: a or b");function m(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function w(e){if(!(e instanceof x))throw new Error("Weierstrass Point expected")}function b(e){if(!c||!c.basises)throw new Error("no endo");return function(e,t,n){const[[r,o],[i,s]]=t,a=lb(s*e,n),c=lb(-o*e,n);let u=e-a*r-c*i,l=-a*o-c*s;const f=u<gb,h=l<gb;f&&(u=-u),h&&(l=-l);const d=vw(Math.ceil(function(e){let t;for(t=0;e>uw;e>>=lw,t+=1);return t}(n)/2))+yb;if(u<gb||u>=d||l<gb||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:u,k2neg:h,k2:l}}(e,c.basises,o.ORDER)}const v=Aw((e,t)=>{const{X:n,Y:o,Z:i}=e;if(r.eql(i,r.ONE))return{x:n,y:o};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(i));const a=r.mul(n,t),c=r.mul(o,t),u=r.mul(i,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw new Error("invZ was invalid");return{x:a,y:c}}),E=Aw(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:n,y:o}=e.toAffine();if(!r.isValid(n)||!r.isValid(o))throw new Error("bad point: x or y not field elements");if(!p(n,o))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function A(e,t,n,o,i){return n=new x(r.mul(n.X,e),n.Y,n.Z),t=Qw(o,t),n=Qw(i,n),t.add(n)}class x{static BASE=new x(i.Gx,i.Gy,r.ONE);static ZERO=new x(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=o;X;Y;Z;constructor(e,t,n){this.X=m("x",e),this.Y=m("y",t,!0),this.Z=m("z",n),Object.freeze(this)}static CURVE(){return i}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof x)throw new Error("projective point not allowed");return r.is0(t)&&r.is0(n)?x.ZERO:new x(t,n,r.ONE)}static fromBytes(e){const t=x.fromAffine(h(Mm(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return x.fromBytes(Jm(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return S.createCache(this,e),t||this.multiply(wb),this}assertValidity(){E(this)}hasEvenY(){const{y:e}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(e)}equals(e){w(e);const{X:t,Y:n,Z:o}=this,{X:i,Y:s,Z:a}=e,c=r.eql(r.mul(t,a),r.mul(i,o)),u=r.eql(r.mul(n,a),r.mul(s,o));return c&&u}negate(){return new x(this.X,r.neg(this.Y),this.Z)}double(){const{a:e,b:t}=i,n=r.mul(t,wb),{X:o,Y:s,Z:a}=this;let c=r.ZERO,u=r.ZERO,l=r.ZERO,f=r.mul(o,o),h=r.mul(s,s),d=r.mul(a,a),p=r.mul(o,s);return p=r.add(p,p),l=r.mul(o,a),l=r.add(l,l),c=r.mul(e,l),u=r.mul(n,d),u=r.add(c,u),c=r.sub(h,u),u=r.add(h,u),u=r.mul(c,u),c=r.mul(p,c),l=r.mul(n,l),d=r.mul(e,d),p=r.sub(f,d),p=r.mul(e,p),p=r.add(p,l),l=r.add(f,f),f=r.add(l,f),f=r.add(f,d),f=r.mul(f,p),u=r.add(u,f),d=r.mul(s,a),d=r.add(d,d),f=r.mul(d,p),c=r.sub(c,f),l=r.mul(d,h),l=r.add(l,l),l=r.add(l,l),new x(c,u,l)}add(e){w(e);const{X:t,Y:n,Z:o}=this,{X:s,Y:a,Z:c}=e;let u=r.ZERO,l=r.ZERO,f=r.ZERO;const h=i.a,d=r.mul(i.b,wb);let p=r.mul(t,s),g=r.mul(n,a),y=r.mul(o,c),m=r.add(t,n),b=r.add(s,a);m=r.mul(m,b),b=r.add(p,g),m=r.sub(m,b),b=r.add(t,o);let v=r.add(s,c);return b=r.mul(b,v),v=r.add(p,y),b=r.sub(b,v),v=r.add(n,o),u=r.add(a,c),v=r.mul(v,u),u=r.add(g,y),v=r.sub(v,u),f=r.mul(h,b),u=r.mul(d,y),f=r.add(u,f),u=r.sub(g,f),f=r.add(g,f),l=r.mul(u,f),g=r.add(p,p),g=r.add(g,p),y=r.mul(h,y),b=r.mul(d,b),g=r.add(g,y),y=r.sub(p,y),y=r.mul(h,y),b=r.add(b,y),p=r.mul(g,b),l=r.add(l,p),p=r.mul(v,b),u=r.mul(m,u),u=r.sub(u,p),p=r.mul(m,g),f=r.mul(v,f),f=r.add(f,p),new x(u,l,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(x.ZERO)}multiply(e){const{endo:n}=t;if(!o.isValidNot0(e))throw new Error("invalid scalar: out of range");let r,i;const s=e=>S.cached(this,e,e=>Zw(x,e));if(n){const{k1neg:t,k1:o,k2neg:a,k2:c}=b(e),{p:u,f:l}=s(o),{p:f,f:h}=s(c);i=l.add(h),r=A(n.beta,u,f,t,a)}else{const{p:t,f:n}=s(e);r=t,i=n}return Zw(x,[r,i])[0]}multiplyUnsafe(e){const{endo:n}=t,r=this;if(!o.isValid(e))throw new Error("invalid scalar: out of range");if(e===gb||r.is0())return x.ZERO;if(e===yb)return r;if(S.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:o,k2neg:i,k2:s}=b(e),{p1:a,p2:c}=function(e,t,n,r){let o=t,i=e.ZERO,s=e.ZERO;for(;n>qw||r>qw;)n&Jw&&(i=i.add(o)),r&Jw&&(s=s.add(o)),o=o.double(),n>>=Jw,r>>=Jw;return{p1:i,p2:s}}(x,r,o,s);return A(n.beta,a,c,t,i)}return S.unsafe(r,e)}toAffine(e){return v(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===yb||(e?e(x,this):S.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===yb?this:e?e(x,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return fw(e,"isCompressed"),this.assertValidity(),f(x,this,e)}toHex(e=!0){return $m(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const k=o.BITS,S=new ib(x,t.endo?Math.ceil(k/2):k);return x.BASE.precompute(8),x}function Eb(e){return Uint8Array.of(e?2:3)}function Ab(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function xb(e,t,n={}){Gm(t),Ew(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=(n=Object.assign({},n)).randomBytes||Ym,o=n.hmac||((e,n)=>ub(t,e,n)),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d}=function(e,t={}){const{Fn:n}=e,r=t.randomBytes||Ym,o=Object.assign(Ab(e.Fp,n),{seed:Ww(n.ORDER)});function i(e=r(o.seed)){return $w(Mm(e,o.seed,"seed"),n.ORDER)}function s(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function a(e){const{secretKey:t,publicKey:r,publicKeyUncompressed:i}=o;if(!Fm(e))return;if("_lengths"in n&&n._lengths||t===r)return;const s=Mm(e,void 0,"key").length;return s===r||s===i}const c={isValidSecretKey:function(e){try{const t=n.fromBytes(e);return n.isValidNot0(t)}catch(e){return!1}},isValidPublicKey:function(t,n){const{publicKey:r,publicKeyUncompressed:i}=o;try{const o=t.length;return!(!0===n&&o!==r||!1===n&&o!==i||!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:i},u=ab(i,s);return Object.freeze({getPublicKey:s,getSharedSecret:function(t,r,o=!0){if(!0===a(t))throw new Error("first arg must be private key");if(!1===a(r))throw new Error("second arg must be public key");const i=n.fromBytes(t);return e.fromBytes(r).multiply(i).toBytes(o)},keygen:u,Point:e,utils:c,lengths:o})}(e,n),p={prehash:!0,lowS:"boolean"!=typeof n.lowS||n.lowS,format:"compact",extraEntropy:!1},g=a*mb<i.ORDER;function y(e){return e>a>>yb}function m(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function w(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function b(e,t){fb(t);const n=d.signature;return Mm(e,"compact"===t?n:"recovered"===t?n+1:void 0)}class v{r;s;recovery;constructor(e,t,n){if(this.r=m("r",e),this.s=m("s",t),null!=n){if(w(),![0,1,2,3].includes(n))throw new Error("invalid recovery id");this.recovery=n}Object.freeze(this)}static fromBytes(e,t=p.format){let n;if(b(e,t),"der"===t){const{r:t,s:n}=pb.toSig(Mm(e));return new v(t,n)}"recovered"===t&&(n=e[0],t="compact",e=e.subarray(1));const r=d.signature/2,o=e.subarray(0,r),i=e.subarray(r,2*r);return new v(s.fromBytes(o),s.fromBytes(i),n)}static fromHex(e,t){return this.fromBytes(Jm(e),t)}assertRecovery(){const{recovery:e}=this;if(null==e)throw new Error("invalid recovery id: must be present");return e}addRecoveryBit(e){return new v(this.r,this.s,e)}recoverPublicKey(t){const{r:n,s:r}=this,o=this.assertRecovery(),c=2===o||3===o?n+a:n;if(!i.isValid(c))throw new Error("invalid recovery id: sig.r+curve.n != R.x");const u=i.toBytes(c),l=e.fromBytes(Qm(Eb(!(1&o)),u)),f=s.inv(c),h=A(Mm(t,void 0,"msgHash")),d=s.create(-h*f),p=s.create(r*f),g=e.BASE.multiplyUnsafe(d).add(l.multiplyUnsafe(p));if(g.is0())throw new Error("invalid recovery: point at infinify");return g.assertValidity(),g}hasHighS(){return y(this.s)}toBytes(e=p.format){if(fb(e),"der"===e)return Jm(pb.hexFromSig(this));const{r:t,s:n}=this,r=s.toBytes(t),o=s.toBytes(n);return"recovered"===e?(w(),Qm(Uint8Array.of(this.assertRecovery()),r,o)):Qm(r,o)}toHex(e){return $m(this.toBytes(e))}}const E=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=gw(e),n=8*e.length-c;return n>0?t>>BigInt(n):t},A=n.bits2int_modN||function(e){return s.create(E(e))},x=vw(c);function k(e){return function(e,t,n,r){if(!function(e,t,n){return bw(e)&&bw(t)&&bw(n)&&t<=e&&e<n}(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}("num < 2^"+c,e,gb,x),s.toBytes(e)}function S(e,n){return Mm(e,void 0,"message"),n?Mm(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:h,lengths:d,Point:e,sign:function(n,i,a={}){const{seed:c,k2sig:u}=function(t,n,o){const{lowS:i,prehash:a,extraEntropy:c}=hb(o,p);t=S(t,a);const u=A(t),l=s.fromBytes(n);if(!s.isValidNot0(l))throw new Error("invalid private key");const f=[k(l),k(u)];if(null!=c&&!1!==c){const e=!0===c?r(d.secretKey):c;f.push(Mm(e,void 0,"extraEntropy"))}const h=Qm(...f),m=u;return{seed:h,k2sig:function(t){const n=E(t);if(!s.isValidNot0(n))return;const r=s.inv(n),o=e.BASE.multiply(n).toAffine(),a=s.create(o.x);if(a===gb)return;const c=s.create(r*s.create(m+a*l));if(c===gb)return;let u=(o.x===a?0:2)|Number(o.y&yb),f=c;return i&&y(c)&&(f=s.neg(c),u^=1),new v(a,f,g?void 0:u)}}}(n,i,a),l=function(e,t,n){if(_m(e,"hashLen"),_m(t,"qByteLen"),"function"!=typeof n)throw new Error("hmacFn must be a function");const r=e=>new Uint8Array(e),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1);let a=r(e),c=r(e),u=0;const l=()=>{a.fill(1),c.fill(0),u=0},f=(...e)=>n(c,Qm(a,...e)),h=(e=o)=>{c=f(i,e),a=f(),0!==e.length&&(c=f(s,e),a=f())},d=()=>{if(u++>=1e3)throw new Error("drbg: tried max amount of iterations");let e=0;const n=[];for(;e<t;){a=f();const t=a.slice();n.push(t),e+=a.length}return Qm(...n)};return(e,t)=>{let n;for(l(),h(e);!(n=t(d()));)h();return l(),n}}(t.outputLen,s.BYTES,o);return l(c,u).toBytes(a.format)},verify:function(t,n,r,o={}){const{lowS:i,prehash:a,format:c}=hb(o,p);if(r=Mm(r,void 0,"publicKey"),n=S(n,a),!Fm(t))throw new Error("verify expects Uint8Array signature"+(t instanceof v?", use sig.toBytes()":""));b(t,c);try{const o=v.fromBytes(t,c),a=e.fromBytes(r);if(i&&o.hasHighS())return!1;const{r:u,s:l}=o,f=A(n),h=s.inv(l),d=s.create(f*h),p=s.create(u*h),g=e.BASE.multiplyUnsafe(d).add(a.multiplyUnsafe(p));return!g.is0()&&s.create(g.x)===u}catch(e){return!1}},recoverPublicKey:function(e,t,n={}){const{prehash:r}=hb(n,p);return t=S(t,r),v.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:v,hash:t})}const kb={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Sb={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Ib=BigInt(0),Cb=BigInt(2),Ob=Vw(kb.p,{sqrt:function(e){const t=kb.p,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=Uw(l,n,t)*l%t,h=Uw(f,n,t)*l%t,d=Uw(h,Cb,t)*u%t,p=Uw(d,o,t)*d%t,g=Uw(p,i,t)*p%t,y=Uw(g,a,t)*g%t,m=Uw(y,c,t)*y%t,w=Uw(m,a,t)*g%t,b=Uw(w,n,t)*l%t,v=Uw(b,s,t)*p%t,E=Uw(v,r,t)*u%t,A=Uw(E,Cb,t);if(!Ob.eql(Ob.sqr(A),e))throw new Error("Cannot find square root");return A}}),Tb=vb(kb,{Fp:Ob,endo:Sb}),Nb=xb(Tb,cw),Pb={};function Bb(e,...t){let n=Pb[e];if(void 0===n){const t=cw((r=e,Uint8Array.from(r,(e,t)=>{const n=e.charCodeAt(0);if(1!==e.length||n>127)throw new Error(`string contains non-ASCII character "${r[t]}" with code ${n} at position ${t}`);return n})));n=Qm(t,t),Pb[e]=n}var r;return cw(Qm(n,...t))}const Rb=e=>e.toBytes(!0).slice(1),Ub=e=>e%Cb===Ib;function Db(e){const{Fn:t,BASE:n}=Tb,r=t.fromBytes(e),o=n.multiply(r);return{scalar:Ub(o.y)?r:t.neg(r),bytes:Rb(o)}}function Lb(e){const t=Ob;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x ≥ p");const n=t.create(e*e),r=t.create(n*e+BigInt(7));let o=t.sqrt(r);Ub(o)||(o=t.neg(o));const i=Tb.fromAffine({x:e,y:o});return i.assertValidity(),i}const Fb=gw;function _b(...e){return Tb.Fn.create(Fb(Bb("BIP0340/challenge",...e)))}function Mb(e){return Db(e).bytes}function Gb(e,t,n=Ym(32)){const{Fn:r}=Tb,o=Mm(e,void 0,"message"),{bytes:i,scalar:s}=Db(t),a=Mm(n,32,"auxRand"),c=r.toBytes(s^Fb(Bb("BIP0340/aux",a))),u=Bb("BIP0340/nonce",c,i,o),{bytes:l,scalar:f}=Db(u),h=_b(l,i,o),d=new Uint8Array(64);if(d.set(l,0),d.set(r.toBytes(r.create(f+h*s)),32),!jb(d,o,i))throw new Error("sign: Invalid signature produced");return d}function jb(e,t,n){const{Fp:r,Fn:o,BASE:i}=Tb,s=Mm(e,64,"signature"),a=Mm(t,void 0,"message"),c=Mm(n,32,"publicKey");try{const e=Lb(Fb(c)),t=Fb(s.subarray(0,32));if(!r.isValidNot0(t))return!1;const n=Fb(s.subarray(32,64));if(!o.isValidNot0(n))return!1;const u=_b(o.toBytes(t),Rb(e),a),l=i.multiplyUnsafe(n).add(e.multiplyUnsafe(o.neg(u))),{x:f,y:h}=l.toAffine();return!(l.is0()||!Ub(h)||f!==t)}catch(e){return!1}}const Hb=(()=>{const e=(e=Ym(48))=>$w(e,kb.n);return{keygen:ab(e,Mb),getPublicKey:Mb,sign:Gb,verify:jb,Point:Tb,utils:{randomSecretKey:e,taggedHash:Bb,lift_x:Lb,pointToBytes:Rb},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();function zb(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Vb(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function Kb(e){if("function"!=typeof e)throw new Error("function expected");return!0}function Wb(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function $b(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function qb(e){if(!Array.isArray(e))throw new Error("array expected")}function Jb(e,t){if(!Vb(!0,t))throw new Error(`${e}: array of strings expected`)}function Qb(e,t){if(!Vb(!1,t))throw new Error(`${e}: array of numbers expected`)}function Zb(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function Yb(e){const t="string"==typeof e?e.split(""):e,n=t.length;Jb("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(qb(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(qb(t),t.map(t=>{Wb("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function Xb(e=""){return Wb("join",e),{encode:t=>(Jb("join.decode",t),t.join(e)),decode:t=>(Wb("join.decode",t),t.split(e))}}function ev(e,t="="){return $b(e),Wb("padding",t),{encode(n){for(Jb("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){Jb("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding");return n.slice(0,r)}}}function tv(e){return Kb(e),{encode:e=>e,decode:t=>e(t)}}function nv(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(qb(e),!e.length)return[];let r=0;const o=[],i=Array.from(e,e=>{if($b(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=i.length;for(;;){let e=0,a=!0;for(let o=r;o<s;o++){const s=i[o],c=t*e,u=c+s;if(!Number.isSafeInteger(u)||c/t!==e||u-s!==c)throw new Error("convertRadix: carry overflow");const l=u/n;e=u%n;const f=Math.floor(l);if(i[o]=f,!Number.isSafeInteger(f)||f*n+e!==u)throw new Error("convertRadix: carry overflow");a&&(f?a=!1:r=o)}if(o.push(e),a)break}for(let t=0;t<e.length-1&&0===e[t];t++)o.push(0);return o.reverse()}const rv=(e,t)=>0===t?e:rv(t,e%t),ov=(e,t)=>e+(t-rv(e,t)),iv=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function sv(e,t,n,r){if(qb(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(ov(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${ov(t,n)}`);let o=0,i=0;const s=iv[t],a=iv[n]-1,c=[];for(const r of e){if($b(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<<t|r,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=iv[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<<n-i&a,!r&&i>=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}function av(e,t=!1){if($b(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(ov(8,e)>32||ov(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!zb(n))throw new Error("radix2.encode input should be Uint8Array");return sv(Array.from(n),8,e,!t)},decode:n=>(Qb("radix2.decode",n),Uint8Array.from(sv(n,e,8,t)))}}function cv(e){return Kb(e),function(...t){try{return e.apply(null,t)}catch(e){}}}Zb(av(4),Yb("0123456789ABCDEF"),Xb("")),Zb(av(5),Yb("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),ev(5),Xb(""));const uv=(Zb(av(5),Yb("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Xb("")),Zb(av(5),Yb("0123456789ABCDEFGHIJKLMNOPQRSTUV"),ev(5),Xb("")),Zb(av(5),Yb("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Xb("")),Zb(av(5),Yb("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),Xb(""),tv(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()),lv=uv?{encode:e=>(function(e){if(!zb(e))throw new Error("Uint8Array expected")}(e),e.toBase64()),decode:e=>((e,t)=>{Wb("base64",e);const n=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,r=t?"base64url":"base64";if(e.length>0&&!n.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:r,lastChunkHandling:"strict"})})(e,!1)}:Zb(av(6),Yb("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ev(6),Xb("")),fv=(Zb(av(6),Yb("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Xb("")),uv||Zb(av(6),Yb("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),ev(6),Xb("")),Zb(av(6),Yb("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Xb("")),e=>{return Zb(($b(t=58),{encode:e=>{if(!zb(e))throw new Error("radix.encode input should be Uint8Array");return nv(Array.from(e),256,t)},decode:e=>(Qb("radix.decode",e),Uint8Array.from(nv(e,t,256)))}),Yb(e),Xb(""));var t}),hv=(fv("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),fv("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),fv("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),Zb(Yb("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Xb(""))),dv=[996825010,642813549,513874426,1027748829,705979059];function pv(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<dv.length;e++)1==(t>>e&1)&&(n^=dv[e]);return n}function gv(e,t,n=1){const r=e.length;let o=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);o=pv(o)^n>>5}o=pv(o);for(let t=0;t<r;t++)o=pv(o)^31&e.charCodeAt(t);for(let e of t)o=pv(o)^e;for(let e=0;e<6;e++)o=pv(o);return o^=n,hv.encode(sv([o%iv[30]],30,5,!1))}function yv(e){const t="bech32"===e?1:734539939,n=av(5),r=n.decode,o=n.encode,i=cv(r);function s(e,n,r=90){Wb("bech32.encode prefix",e),zb(n)&&(n=Array.from(n)),Qb("bech32.encode",n);const o=e.length;if(0===o)throw new TypeError(`Invalid prefix length ${o}`);const i=o+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);const s=e.toLowerCase(),a=gv(s,n,t);return`${s}1${hv.encode(n)}${a}`}function a(e,n=90){Wb("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);const o=e.toLowerCase();if(e!==o&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=o.lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const s=o.slice(0,i),a=o.slice(i+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const c=hv.decode(a).slice(0,-6),u=gv(s,c,t);if(!a.endsWith(u))throw new Error(`Invalid checksum in ${e}: expected "${u}"`);return{prefix:s,words:c}}return{encode:s,decode:a,encodeFromBytes:function(e,t){return s(e,o(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:cv(a),fromWords:r,fromWordsUnsafe:i,toWords:o}}const mv=yv("bech32");function wv(e){if("boolean"!=typeof e)throw new Error(`boolean expected, not ${e}`)}function bv(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function vv(e,t,n=""){const r=(o=e)instanceof Uint8Array||ArrayBuffer.isView(o)&&"Uint8Array"===o.constructor.name;var o;const i=e?.length,s=void 0!==t;if(!r||s&&i!==t)throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(s?` of length ${t}`:"")+", got "+(r?`length=${i}`:"type="+typeof e));return e}function Ev(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Av(e,t){vv(e,void 0,"output");const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function xv(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function kv(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Sv(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}yv("bech32m"),(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)()||Zb(av(4),Yb("0123456789abcdef"),Xb(""),tv(e=>{if("string"!=typeof e||e.length%2!=0)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const Iv=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])();function Cv(e,t){if(function(e,t){return e.buffer===t.buffer&&e.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<e.byteOffset+e.byteLength}(e,t)&&e.byteOffset<t.byteOffset)throw new Error("complex overlap of input and output is not supported")}function Ov(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n}const Tv=(e,t)=>{function n(n,...r){if(vv(n,void 0,"key"),!Iv)throw new Error("Non little-endian hardware is not yet supported");void 0!==e.nonceLength&&vv(r[0],e.varSizeNonce?void 0:e.nonceLength,"nonce");const o=e.tagLength;o&&void 0!==r[1]&&vv(r[1],void 0,"AAD");const i=t(n,...r),s=(e,t)=>{if(void 0!==t){if(2!==e)throw new Error("cipher output not supported");vv(t,void 0,"output")}};let a=!1;const c={encrypt(e,t){if(a)throw new Error("cannot encrypt() twice with same key + nonce");return a=!0,vv(e),s(i.encrypt.length,t),i.encrypt(e,t)},decrypt(e,t){if(vv(e),o&&e.length<o)throw new Error('"ciphertext" expected length bigger than tagLength='+o);return s(i.decrypt.length,t),i.decrypt(e,t)}};return c}return Object.assign(n,e),n};function Nv(e,t,n=!0){if(void 0===t)return new Uint8Array(e);if(t.length!==e)throw new Error('"output" expected Uint8Array of length '+e+", got: "+t.length);if(n&&!Pv(t))throw new Error("invalid output, must be aligned");return t}function Pv(e){return e.byteOffset%4==0}function Bv(e){return Uint8Array.from(e)}const Rv=16,Uv=new Uint8Array(16),Dv=xv(Uv),Lv=(e,t,n,r)=>({s3:n<<31|r>>>1,s2:t<<31|n>>>1,s1:e<<31|t>>>1,s0:e>>>1^225<<24&-(1&r)}),Fv=e=>(e>>>0&255)<<24|(e>>>8&255)<<16|(e>>>16&255)<<8|e>>>24&255;class _v{blockLen=Rv;outputLen=Rv;s0=0;s1=0;s2=0;s3=0;finished=!1;t;W;windowSize;constructor(e,t){vv(e,16,"key");const n=Sv(e=Bv(e));let r=n.getUint32(0,!1),o=n.getUint32(4,!1),i=n.getUint32(8,!1),s=n.getUint32(12,!1);const a=[];for(let e=0;e<128;e++)a.push({s0:Fv(r),s1:Fv(o),s2:Fv(i),s3:Fv(s)}),({s0:r,s1:o,s2:i,s3:s}=Lv(r,o,i,s));const c=(e=>e>65536?8:e>1024?4:2)(t||1024);if(![1,2,4,8].includes(c))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=c;const u=128/c,l=this.windowSize=2**c,f=[];for(let e=0;e<u;e++)for(let t=0;t<l;t++){let n=0,r=0,o=0,i=0;for(let s=0;s<c;s++){if(!(t>>>c-s-1&1))continue;const{s0:u,s1:l,s2:f,s3:h}=a[c*e+s];n^=u,r^=l,o^=f,i^=h}f.push({s0:n,s1:r,s2:o,s3:i})}this.t=f}_updateBlock(e,t,n,r){e^=this.s0,t^=this.s1,n^=this.s2,r^=this.s3;const{W:o,t:i,windowSize:s}=this;let a=0,c=0,u=0,l=0;const f=(1<<o)-1;let h=0;for(const d of[e,t,n,r])for(let e=0;e<4;e++){const t=d>>>8*e&255;for(let e=8/o-1;e>=0;e--){const n=t>>>o*e&f,{s0:r,s1:d,s2:p,s3:g}=i[h*s+n];a^=r,c^=d,u^=p,l^=g,h+=1}}this.s0=a,this.s1=c,this.s2=u,this.s3=l}update(e){Ev(this),vv(e);const t=xv(e=Bv(e)),n=Math.floor(e.length/Rv),r=e.length%Rv;for(let e=0;e<n;e++)this._updateBlock(t[4*e+0],t[4*e+1],t[4*e+2],t[4*e+3]);return r&&(Uv.set(e.subarray(n*Rv)),this._updateBlock(Dv[0],Dv[1],Dv[2],Dv[3]),kv(Dv)),this}destroy(){const{t:e}=this;for(const t of e)t.s0=0,t.s1=0,t.s2=0,t.s3=0}digestInto(e){Ev(this),Av(e,this),this.finished=!0;const{s0:t,s1:n,s2:r,s3:o}=this,i=xv(e);return i[0]=t,i[1]=n,i[2]=r,i[3]=o,e}digest(){const e=new Uint8Array(Rv);return this.digestInto(e),this.destroy(),e}}class Mv extends _v{constructor(e,t){vv(e);const n=function(e){e.reverse();const t=1&e[15];let n=0;for(let t=0;t<e.length;t++){const r=e[t];e[t]=r>>>1|n,n=(1&r)<<7}return e[0]^=225&-t,e}(Bv(e));super(n,t),kv(n)}update(e){Ev(this),vv(e);const t=xv(e=Bv(e)),n=e.length%Rv,r=Math.floor(e.length/Rv);for(let e=0;e<r;e++)this._updateBlock(Fv(t[4*e+3]),Fv(t[4*e+2]),Fv(t[4*e+1]),Fv(t[4*e+0]));return n&&(Uv.set(e.subarray(r*Rv)),this._updateBlock(Fv(Dv[3]),Fv(Dv[2]),Fv(Dv[1]),Fv(Dv[0])),kv(Dv)),this}digestInto(e){Ev(this),Av(e,this),this.finished=!0;const{s0:t,s1:n,s2:r,s3:o}=this,i=xv(e);return i[0]=t,i[1]=n,i[2]=r,i[3]=o,e.reverse()}}function Gv(e){const t=(t,n)=>e(n,t.length).update(t).digest(),n=e(new Uint8Array(16),0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=(t,n)=>e(t,n),t}Gv((e,t)=>new _v(e,t)),Gv((e,t)=>new Mv(e,t));const jv=16;function Hv(e){if(![16,24,32].includes(e.length))throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length='+e.length)}function zv(e){return e<<1^283&-(e>>7)}function Vv(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(1&t),e=zv(e);return n}const Kv=(()=>{const e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=zv(n))e[t]=n;const t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=255&(r^r>>4^r>>5^r>>6^r>>7^99)}return kv(e),t})(),Wv=Kv.map((e,t)=>Kv.indexOf(t)),$v=e=>e<<24|e>>>8,qv=e=>e<<8|e>>>24;function Jv(e,t){if(256!==e.length)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((n,r)=>t(e[r])),r=n.map(qv),o=r.map(qv),i=o.map(qv),s=new Uint32Array(65536),a=new Uint32Array(65536),c=new Uint16Array(65536);for(let t=0;t<256;t++)for(let u=0;u<256;u++){const l=256*t+u;s[l]=n[t]^r[u],a[l]=o[t]^i[u],c[l]=e[t]<<8|e[u]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:o,T3:i,T01:s,T23:a}}const Qv=Jv(Kv,e=>Vv(e,3)<<24|e<<16|e<<8|Vv(e,2)),Zv=Jv(Wv,e=>Vv(e,11)<<24|Vv(e,13)<<16|Vv(e,9)<<8|Vv(e,14)),Yv=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=zv(n))e[t]=n;return e})();function Xv(e){vv(e);const t=e.length;Hv(e);const{sbox2:n}=Qv,r=[];Pv(e)||r.push(e=Bv(e));const o=xv(e),i=o.length,s=e=>tE(n,e,e,e,e),a=new Uint32Array(t+28);a.set(o);for(let e=i;e<a.length;e++){let t=a[e-1];e%i===0?t=s($v(t))^Yv[e/i-1]:i>6&&e%i===4&&(t=s(t)),a[e]=a[e-i]^t}return kv(...r),a}function eE(e,t,n,r,o,i){return e[n<<8&65280|r>>>8&255]^t[o>>>8&65280|i>>>24&255]}function tE(e,t,n,r,o){return e[255&t|65280&n]|e[r>>>16&255|o>>>16&65280]<<16}function nE(e,t,n,r,o){const{sbox2:i,T01:s,T23:a}=Qv;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];const u=e.length/4-2;for(let i=0;i<u;i++){const i=e[c++]^eE(s,a,t,n,r,o),u=e[c++]^eE(s,a,n,r,o,t),l=e[c++]^eE(s,a,r,o,t,n),f=e[c++]^eE(s,a,o,t,n,r);t=i,n=u,r=l,o=f}return{s0:e[c++]^tE(i,t,n,r,o),s1:e[c++]^tE(i,n,r,o,t),s2:e[c++]^tE(i,r,o,t,n),s3:e[c++]^tE(i,o,t,n,r)}}function rE(e,t,n,r,o){const{sbox2:i,T01:s,T23:a}=Zv;let c=0;t^=e[c++],n^=e[c++],r^=e[c++],o^=e[c++];const u=e.length/4-2;for(let i=0;i<u;i++){const i=e[c++]^eE(s,a,t,o,r,n),u=e[c++]^eE(s,a,n,t,o,r),l=e[c++]^eE(s,a,r,n,t,o),f=e[c++]^eE(s,a,o,r,n,t);t=i,n=u,r=l,o=f}return{s0:e[c++]^tE(i,t,o,r,n),s1:e[c++]^tE(i,n,t,o,r),s2:e[c++]^tE(i,r,n,t,o),s3:e[c++]^tE(i,o,r,n,t)}}const oE=Tv({blockSize:16,nonceLength:16},function(e,t,n={}){const r=!n.disablePadding;return{encrypt(n,o){const i=Xv(e),{b:s,o:a,out:c}=function(e,t,n){vv(e);let r=e.length;const o=r%jv;if(!t&&0!==o)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");Pv(e)||(e=Bv(e));const i=xv(e);if(t){let e=jv-o;e||(e=jv),r+=e}return Cv(e,n=Nv(r,n)),{b:i,o:xv(n),out:n}}(n,r,o);let u=t;const l=[i];Pv(u)||l.push(u=Bv(u));const f=xv(u);let h=f[0],d=f[1],p=f[2],g=f[3],y=0;for(;y+4<=s.length;)h^=s[y+0],d^=s[y+1],p^=s[y+2],g^=s[y+3],({s0:h,s1:d,s2:p,s3:g}=nE(i,h,d,p,g)),a[y++]=h,a[y++]=d,a[y++]=p,a[y++]=g;if(r){const e=function(e){const t=new Uint8Array(16),n=xv(t);t.set(e);const r=jv-e.length;for(let e=jv-r;e<jv;e++)t[e]=r;return n}(n.subarray(4*y));h^=e[0],d^=e[1],p^=e[2],g^=e[3],({s0:h,s1:d,s2:p,s3:g}=nE(i,h,d,p,g)),a[y++]=h,a[y++]=d,a[y++]=p,a[y++]=g}return kv(...l),c},decrypt(n,o){!function(e){if(vv(e),e.length%jv!==0)throw new Error("aes-(cbc/ecb).decrypt ciphertext should consist of blocks with size 16")}(n);const i=function(e){const t=Xv(e),n=t.slice(),r=t.length,{sbox2:o}=Qv,{T0:i,T1:s,T2:a,T3:c}=Zv;for(let e=0;e<r;e+=4)for(let o=0;o<4;o++)n[e+o]=t[r-e-4+o];kv(t);for(let e=4;e<r-4;e++){const t=n[e],r=tE(o,t,t,t,t);n[e]=i[255&r]^s[r>>>8&255]^a[r>>>16&255]^c[r>>>24]}return n}(e);let s=t;const a=[i];Pv(s)||a.push(s=Bv(s));const c=xv(s);o=Nv(n.length,o),Pv(n)||a.push(n=Bv(n)),Cv(n,o);const u=xv(n),l=xv(o);let f=c[0],h=c[1],d=c[2],p=c[3];for(let e=0;e+4<=u.length;){const t=f,n=h,r=d,o=p;f=u[e+0],h=u[e+1],d=u[e+2],p=u[e+3];const{s0:s,s1:a,s2:c,s3:g}=rE(i,f,h,d,p);l[e++]=s^t,l[e++]=a^n,l[e++]=c^r,l[e++]=g^o}return kv(...a),function(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error("aes/pcks5: wrong padding");const o=e.subarray(0,-r);for(let t=0;t<r;t++)if(e[n-t-1]!==r)throw new Error("aes/pcks5: wrong padding");return o}(o,r)}}});const iE=e=>Uint8Array.from(e.split(""),e=>e.charCodeAt(0)),sE=iE("expand 16-byte k"),aE=iE("expand 32-byte k"),cE=xv(sE),uE=xv(aE);function lE(e,t){return e<<t|e>>>32-t}function fE(e){return e.byteOffset%4==0}const hE=2**32-1,dE=Uint32Array.of();function pE(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:i,rounds:s}=function(e,t){if(null==t||"object"!=typeof t)throw new Error("options must be defined");return Object.assign({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t)}(0,t);if("function"!=typeof e)throw new Error("core must be a function");return bv(o),bv(s),wv(i),wv(n),(t,a,c,u,l=0)=>{vv(t,void 0,"key"),vv(a,void 0,"nonce"),vv(c,void 0,"data");const f=c.length;if(void 0===u&&(u=new Uint8Array(f)),vv(u,void 0,"output"),bv(l),l<0||l>=hE)throw new Error("arx: counter overflow");if(u.length<f)throw new Error(`arx: output (${u.length}) is shorter than data (${f})`);const h=[];let d,p,g=t.length;if(32===g)h.push(d=Bv(t)),p=uE;else{if(16!==g||!n)throw vv(t,32,"arx key"),new Error("invalid key size");d=new Uint8Array(32),d.set(t),d.set(t,16),p=cE,h.push(d)}fE(a)||h.push(a=Bv(a));const y=xv(d);if(r){if(24!==a.length)throw new Error("arx: extended nonce must be 24 bytes");r(p,y,xv(a.subarray(0,16)),y),a=a.subarray(16)}const m=16-o;if(m!==a.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(12!==m){const e=new Uint8Array(12);e.set(a,i?0:12-a.length),a=e,h.push(a)}const w=xv(a);return function(e,t,n,r,o,i,s,a){const c=o.length,u=new Uint8Array(64),l=xv(u),f=fE(o)&&fE(i),h=f?xv(o):dE,d=f?xv(i):dE;for(let p=0;p<c;s++){if(e(t,n,r,l,s,a),s>=hE)throw new Error("arx: counter overflow");const g=Math.min(64,c-p);if(f&&64===g){const e=p/4;if(p%4!=0)throw new Error("arx: invalid block position");for(let t,n=0;n<16;n++)t=e+n,d[t]=h[t]^l[n];p+=64;continue}for(let e,t=0;t<g;t++)e=p+t,i[e]=o[e]^u[t];p+=g}}(e,p,y,w,c,u,l,s),kv(...h),u}}function gE(e,t){return 255&e[t++]|(255&e[t++])<<8}class yE{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;constructor(e){const t=gE(e=Bv(vv(e,32,"key")),0),n=gE(e,2),r=gE(e,4),o=gE(e,6),i=gE(e,8),s=gE(e,10),a=gE(e,12),c=gE(e,14);this.r[0]=8191&t,this.r[1]=8191&(t>>>13|n<<3),this.r[2]=7939&(n>>>10|r<<6),this.r[3]=8191&(r>>>7|o<<9),this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,this.r[6]=8191&(i>>>14|s<<2),this.r[7]=8065&(s>>>11|a<<5),this.r[8]=8191&(a>>>8|c<<8),this.r[9]=c>>>5&127;for(let t=0;t<8;t++)this.pad[t]=gE(e,16+2*t)}process(e,t,n=!1){const r=n?0:2048,{h:o,r:i}=this,s=i[0],a=i[1],c=i[2],u=i[3],l=i[4],f=i[5],h=i[6],d=i[7],p=i[8],g=i[9],y=gE(e,t+0),m=gE(e,t+2),w=gE(e,t+4),b=gE(e,t+6),v=gE(e,t+8),E=gE(e,t+10),A=gE(e,t+12),x=gE(e,t+14);let k=o[0]+(8191&y),S=o[1]+(8191&(y>>>13|m<<3)),I=o[2]+(8191&(m>>>10|w<<6)),C=o[3]+(8191&(w>>>7|b<<9)),O=o[4]+(8191&(b>>>4|v<<12)),T=o[5]+(v>>>1&8191),N=o[6]+(8191&(v>>>14|E<<2)),P=o[7]+(8191&(E>>>11|A<<5)),B=o[8]+(8191&(A>>>8|x<<8)),R=o[9]+(x>>>5|r),U=0,D=U+k*s+S*(5*g)+I*(5*p)+C*(5*d)+O*(5*h);U=D>>>13,D&=8191,D+=T*(5*f)+N*(5*l)+P*(5*u)+B*(5*c)+R*(5*a),U+=D>>>13,D&=8191;let L=U+k*a+S*s+I*(5*g)+C*(5*p)+O*(5*d);U=L>>>13,L&=8191,L+=T*(5*h)+N*(5*f)+P*(5*l)+B*(5*u)+R*(5*c),U+=L>>>13,L&=8191;let F=U+k*c+S*a+I*s+C*(5*g)+O*(5*p);U=F>>>13,F&=8191,F+=T*(5*d)+N*(5*h)+P*(5*f)+B*(5*l)+R*(5*u),U+=F>>>13,F&=8191;let _=U+k*u+S*c+I*a+C*s+O*(5*g);U=_>>>13,_&=8191,_+=T*(5*p)+N*(5*d)+P*(5*h)+B*(5*f)+R*(5*l),U+=_>>>13,_&=8191;let M=U+k*l+S*u+I*c+C*a+O*s;U=M>>>13,M&=8191,M+=T*(5*g)+N*(5*p)+P*(5*d)+B*(5*h)+R*(5*f),U+=M>>>13,M&=8191;let G=U+k*f+S*l+I*u+C*c+O*a;U=G>>>13,G&=8191,G+=T*s+N*(5*g)+P*(5*p)+B*(5*d)+R*(5*h),U+=G>>>13,G&=8191;let j=U+k*h+S*f+I*l+C*u+O*c;U=j>>>13,j&=8191,j+=T*a+N*s+P*(5*g)+B*(5*p)+R*(5*d),U+=j>>>13,j&=8191;let H=U+k*d+S*h+I*f+C*l+O*u;U=H>>>13,H&=8191,H+=T*c+N*a+P*s+B*(5*g)+R*(5*p),U+=H>>>13,H&=8191;let z=U+k*p+S*d+I*h+C*f+O*l;U=z>>>13,z&=8191,z+=T*u+N*c+P*a+B*s+R*(5*g),U+=z>>>13,z&=8191;let V=U+k*g+S*p+I*d+C*h+O*f;U=V>>>13,V&=8191,V+=T*l+N*u+P*c+B*a+R*s,U+=V>>>13,V&=8191,U=(U<<2)+U|0,U=U+D|0,D=8191&U,U>>>=13,L+=U,o[0]=D,o[1]=L,o[2]=F,o[3]=_,o[4]=M,o[5]=G,o[6]=j,o[7]=H,o[8]=z,o[9]=V}finalize(){const{h:e,pad:t}=this,n=new Uint16Array(10);let r=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=r,r=e[t]>>>13,e[t]&=8191;e[0]+=5*r,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(let t=1;t<10;t++)n[t]=e[t]+r,r=n[t]>>>13,n[t]&=8191;n[9]-=8192;let o=(1^r)-1;for(let e=0;e<10;e++)n[e]&=o;o=~o;for(let t=0;t<10;t++)e[t]=e[t]&o|n[t];e[0]=65535&(e[0]|e[1]<<13),e[1]=65535&(e[1]>>>3|e[2]<<10),e[2]=65535&(e[2]>>>6|e[3]<<7),e[3]=65535&(e[3]>>>9|e[4]<<4),e[4]=65535&(e[4]>>>12|e[5]<<1|e[6]<<14),e[5]=65535&(e[6]>>>2|e[7]<<11),e[6]=65535&(e[7]>>>5|e[8]<<8),e[7]=65535&(e[8]>>>8|e[9]<<5);let i=e[0]+t[0];e[0]=65535&i;for(let n=1;n<8;n++)i=(e[n]+t[n]|0)+(i>>>16)|0,e[n]=65535&i;kv(n)}update(e){Ev(this),vv(e),e=Bv(e);const{buffer:t,blockLen:n}=this,r=e.length;for(let o=0;o<r;){const i=Math.min(n-this.pos,r-o);if(i!==n)t.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(t,0,!1),this.pos=0);else for(;n<=r-o;o+=n)this.process(e,o)}return this}destroy(){kv(this.h,this.r,this.buffer,this.pad)}digestInto(e){Ev(this),Av(e,this),this.finished=!0;const{buffer:t,h:n}=this;let{pos:r}=this;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();let o=0;for(let t=0;t<8;t++)e[o++]=n[t]>>>0,e[o++]=n[t]>>>8;return e}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}}const mE=(()=>function(e){const t=(t,n)=>e(n).update(t).digest(),n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t}(e=>new yE(e)))();function wE(e,t,n,r,o,i=20){let s=e[0],a=e[1],c=e[2],u=e[3],l=t[0],f=t[1],h=t[2],d=t[3],p=t[4],g=t[5],y=t[6],m=t[7],w=o,b=n[0],v=n[1],E=n[2],A=s,x=a,k=c,S=u,I=l,C=f,O=h,T=d,N=p,P=g,B=y,R=m,U=w,D=b,L=v,F=E;for(let e=0;e<i;e+=2)A=A+I|0,U=lE(U^A,16),N=N+U|0,I=lE(I^N,12),A=A+I|0,U=lE(U^A,8),N=N+U|0,I=lE(I^N,7),x=x+C|0,D=lE(D^x,16),P=P+D|0,C=lE(C^P,12),x=x+C|0,D=lE(D^x,8),P=P+D|0,C=lE(C^P,7),k=k+O|0,L=lE(L^k,16),B=B+L|0,O=lE(O^B,12),k=k+O|0,L=lE(L^k,8),B=B+L|0,O=lE(O^B,7),S=S+T|0,F=lE(F^S,16),R=R+F|0,T=lE(T^R,12),S=S+T|0,F=lE(F^S,8),R=R+F|0,T=lE(T^R,7),A=A+C|0,F=lE(F^A,16),B=B+F|0,C=lE(C^B,12),A=A+C|0,F=lE(F^A,8),B=B+F|0,C=lE(C^B,7),x=x+O|0,U=lE(U^x,16),R=R+U|0,O=lE(O^R,12),x=x+O|0,U=lE(U^x,8),R=R+U|0,O=lE(O^R,7),k=k+T|0,D=lE(D^k,16),N=N+D|0,T=lE(T^N,12),k=k+T|0,D=lE(D^k,8),N=N+D|0,T=lE(T^N,7),S=S+I|0,L=lE(L^S,16),P=P+L|0,I=lE(I^P,12),S=S+I|0,L=lE(L^S,8),P=P+L|0,I=lE(I^P,7);let _=0;r[_++]=s+A|0,r[_++]=a+x|0,r[_++]=c+k|0,r[_++]=u+S|0,r[_++]=l+I|0,r[_++]=f+C|0,r[_++]=h+O|0,r[_++]=d+T|0,r[_++]=p+N|0,r[_++]=g+P|0,r[_++]=y+B|0,r[_++]=m+R|0,r[_++]=w+U|0,r[_++]=b+D|0,r[_++]=v+L|0,r[_++]=E+F|0}const bE=pE(wE,{counterRight:!1,counterLength:4,allowShortKeys:!1}),vE=pE(wE,{counterRight:!1,counterLength:8,extendNonceFn:function(e,t,n,r){let o=e[0],i=e[1],s=e[2],a=e[3],c=t[0],u=t[1],l=t[2],f=t[3],h=t[4],d=t[5],p=t[6],g=t[7],y=n[0],m=n[1],w=n[2],b=n[3];for(let e=0;e<20;e+=2)o=o+c|0,y=lE(y^o,16),h=h+y|0,c=lE(c^h,12),o=o+c|0,y=lE(y^o,8),h=h+y|0,c=lE(c^h,7),i=i+u|0,m=lE(m^i,16),d=d+m|0,u=lE(u^d,12),i=i+u|0,m=lE(m^i,8),d=d+m|0,u=lE(u^d,7),s=s+l|0,w=lE(w^s,16),p=p+w|0,l=lE(l^p,12),s=s+l|0,w=lE(w^s,8),p=p+w|0,l=lE(l^p,7),a=a+f|0,b=lE(b^a,16),g=g+b|0,f=lE(f^g,12),a=a+f|0,b=lE(b^a,8),g=g+b|0,f=lE(f^g,7),o=o+u|0,b=lE(b^o,16),p=p+b|0,u=lE(u^p,12),o=o+u|0,b=lE(b^o,8),p=p+b|0,u=lE(u^p,7),i=i+l|0,y=lE(y^i,16),g=g+y|0,l=lE(l^g,12),i=i+l|0,y=lE(y^i,8),g=g+y|0,l=lE(l^g,7),s=s+f|0,m=lE(m^s,16),h=h+m|0,f=lE(f^h,12),s=s+f|0,m=lE(m^s,8),h=h+m|0,f=lE(f^h,7),a=a+c|0,w=lE(w^a,16),d=d+w|0,c=lE(c^d,12),a=a+c|0,w=lE(w^a,8),d=d+w|0,c=lE(c^d,7);let v=0;r[v++]=o,r[v++]=i,r[v++]=s,r[v++]=a,r[v++]=y,r[v++]=m,r[v++]=w,r[v++]=b},allowShortKeys:!1}),EE=new Uint8Array(16),AE=(e,t)=>{e.update(t);const n=t.length%16;n&&e.update(EE.subarray(n))},xE=new Uint8Array(32);function kE(e,t,n,r,o){void 0!==o&&vv(o,void 0,"AAD");const i=e(t,n,xE),s=function(e,t,n){wv(n);const r=new Uint8Array(16),o=Sv(r);return o.setBigUint64(0,BigInt(t),n),o.setBigUint64(8,BigInt(e),n),r}(r.length,o?o.length:0,!0),a=mE.create(i);o&&AE(a,o),AE(a,r),a.update(s);const c=a.digest();return kv(i,s),c}const SE=e=>(t,n,r)=>({encrypt(o,i){const s=o.length;(i=Nv(s+16,i,!1)).set(o);const a=i.subarray(0,-16);e(t,n,a,a,1);const c=kE(e,t,n,a,r);return i.set(c,s),kv(c),i},decrypt(o,i){i=Nv(o.length-16,i,!1);const s=o.subarray(0,-16),a=o.subarray(-16),c=kE(e,t,n,s,r);if(!Ov(a,c))throw new Error("invalid tag");return i.set(o.subarray(0,-16)),e(t,n,i,i,1),kv(c),i}});SE(bE),SE(vE);const IE=Uint8Array.of(0),CE=Uint8Array.of();var OE=Object.defineProperty,TE=(e,t)=>{for(var n in t)OE(e,n,{get:t[n],enumerable:!0})},NE=Symbol("verified");function PE(e){if(!(e instanceof Object))return!1;if("number"!=typeof e.kind)return!1;if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if("string"!=typeof e.pubkey)return!1;if(!e.pubkey.match(/^[a-f0-9]{64}$/))return!1;if(!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let e=0;e<n.length;e++)if("string"!=typeof n[e])return!1}return!0}var BE={};TE(BE,{binarySearch:()=>_E,bytesToHex:()=>$m,hexToBytes:()=>Jm,insertEventIntoAscendingList:()=>FE,insertEventIntoDescendingList:()=>LE,mergeReverseSortedLists:()=>ME,normalizeURL:()=>DE,utf8Decoder:()=>RE,utf8Encoder:()=>UE});var RE=new TextDecoder("utf-8"),UE=new TextEncoder;function DE(e){try{-1===e.indexOf("://")&&(e="wss://"+e);let t=new URL(e);return"http:"===t.protocol?t.protocol="ws:":"https:"===t.protocol&&(t.protocol="wss:"),t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),("80"===t.port&&"ws:"===t.protocol||"443"===t.port&&"wss:"===t.protocol)&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch(t){throw new Error(`Invalid URL: ${e}`)}}function LE(e,t){const[n,r]=_E(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:e.created_at-t.created_at);return r||e.splice(n,0,t),e}function FE(e,t){const[n,r]=_E(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:t.created_at-e.created_at);return r||e.splice(n,0,t),e}function _E(e,t){let n=0,r=e.length-1;for(;n<=r;){const o=Math.floor((n+r)/2),i=t(e[o]);if(0===i)return[o,!0];i<0?r=o-1:n=o+1}return[n,!1]}function ME(e,t){const n=new Array(e.length+t.length);n.length=0;let r=0,o=0,i=[];for(;r<e.length&&o<t.length;){let s;if(e[r]?.created_at>t[o]?.created_at?(s=e[r],r++):(s=t[o],o++),n.length>0&&n[n.length-1].created_at===s.created_at){if(i.includes(s.id))continue}else i.length=0;n.push(s),i.push(s.id)}for(;r<e.length;){const t=e[r];if(r++,n.length>0&&n[n.length-1].created_at===t.created_at){if(i.includes(t.id))continue}else i.length=0;n.push(t),i.push(t.id)}for(;o<t.length;){const e=t[o];if(o++,n.length>0&&n[n.length-1].created_at===e.created_at){if(i.includes(e.id))continue}else i.length=0;n.push(e),i.push(e.id)}return n}function GE(e){return $m(cw(UE.encode(function(e){if(!PE(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}(e))))}var jE=new class{generateSecretKey(){return Hb.utils.randomSecretKey()}getPublicKey(e){return $m(Hb.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=$m(Hb.getPublicKey(t)),n.id=GE(n),n.sig=$m(Hb.sign(Jm(GE(n)),t)),n[NE]=!0,n}verifyEvent(e){if("boolean"==typeof e[NE])return e[NE];try{const t=GE(e);if(t!==e.id)return e[NE]=!1,!1;const n=Hb.verify(Jm(e.sig),Jm(t),Jm(e.pubkey));return e[NE]=n,n}catch(t){return e[NE]=!1,!1}}},HE=jE.generateSecretKey,zE=jE.getPublicKey,VE=jE.finalizeEvent,KE=jE.verifyEvent;function WE(e){return e<1e4&&0!==e&&3!==e}function $E(e){return 0===e||3===e||1e4<=e&&e<2e4}function qE(e){return 2e4<=e&&e<3e4}function JE(e){return 3e4<=e&&e<4e4}function QE(e){return WE(e)?"regular":$E(e)?"replaceable":qE(e)?"ephemeral":JE(e)?"parameterized":"unknown"}function ZE(e,t){const n=t instanceof Array?t:[t];return PE(e)&&n.includes(e.kind)||!1}TE({},{Application:()=>Ax,BadgeAward:()=>sA,BadgeDefinition:()=>gx,BlockedRelaysList:()=>qA,BlossomServerList:()=>tx,BookmarkList:()=>KA,Bookmarksets:()=>hx,Calendar:()=>Tx,CalendarEventRSVP:()=>Nx,ChannelCreation:()=>yA,ChannelHideMessage:()=>bA,ChannelMessage:()=>wA,ChannelMetadata:()=>mA,ChannelMuteUser:()=>vA,ChatMessage:()=>aA,ClassifiedListing:()=>Sx,ClientAuth:()=>ox,Comment:()=>SA,CommunitiesList:()=>WA,CommunityDefinition:()=>Ux,CommunityPostApproval:()=>RA,Contacts:()=>tA,CreateOrUpdateProduct:()=>wx,CreateOrUpdateStall:()=>mx,Curationsets:()=>dx,Date:()=>Cx,DirectMessageRelaysList:()=>XA,DraftClassifiedListing:()=>Ix,DraftLong:()=>vx,Emojisets:()=>Ex,EncryptedDirectMessage:()=>nA,EventDeletion:()=>rA,FavoriteRelays:()=>QA,FileMessage:()=>fA,FileMetadata:()=>kA,FileServerPreference:()=>ex,Followsets:()=>ux,ForumThread:()=>cA,GenericRepost:()=>hA,Genericlists:()=>lx,GiftWrap:()=>AA,GroupMetadata:()=>Dx,HTTPAuth:()=>cx,Handlerinformation:()=>Rx,Handlerrecommendation:()=>Bx,Highlights:()=>GA,InterestsList:()=>ZA,Interestsets:()=>yx,JobFeedback:()=>LA,JobRequest:()=>UA,JobResult:()=>DA,Label:()=>BA,LightningPubRPC:()=>rx,LiveChatMessage:()=>IA,LiveEvent:()=>xx,LongFormArticle:()=>bx,Metadata:()=>YE,Mutelist:()=>HA,NWCWalletInfo:()=>nx,NWCWalletRequest:()=>ix,NWCWalletResponse:()=>sx,NormalVideo:()=>pA,NostrConnect:()=>ax,OpenTimestamps:()=>EA,Photo:()=>dA,Pinlist:()=>zA,Poll:()=>xA,PollResponse:()=>jA,PrivateDirectMessage:()=>lA,ProblemTracker:()=>TA,ProfileBadges:()=>px,PublicChatsList:()=>$A,Reaction:()=>iA,RecommendRelay:()=>eA,RelayList:()=>VA,RelayReview:()=>Px,Relaysets:()=>fx,Report:()=>NA,Reporting:()=>PA,Repost:()=>oA,Seal:()=>uA,SearchRelaysList:()=>JA,ShortTextNote:()=>XE,ShortVideo:()=>gA,Time:()=>Ox,UserEmojiList:()=>YA,UserStatuses:()=>kx,Voice:()=>CA,VoiceComment:()=>OA,Zap:()=>MA,ZapGoal:()=>FA,ZapRequest:()=>_A,classifyKind:()=>QE,isAddressableKind:()=>JE,isEphemeralKind:()=>qE,isKind:()=>ZE,isRegularKind:()=>WE,isReplaceableKind:()=>$E});var YE=0,XE=1,eA=2,tA=3,nA=4,rA=5,oA=6,iA=7,sA=8,aA=9,cA=11,uA=13,lA=14,fA=15,hA=16,dA=20,pA=21,gA=22,yA=40,mA=41,wA=42,bA=43,vA=44,EA=1040,AA=1059,xA=1068,kA=1063,SA=1111,IA=1311,CA=1222,OA=1244,TA=1971,NA=1984,PA=1984,BA=1985,RA=4550,UA=5999,DA=6999,LA=7e3,FA=9041,_A=9734,MA=9735,GA=9802,jA=1018,HA=1e4,zA=10001,VA=10002,KA=10003,WA=10004,$A=10005,qA=10006,JA=10007,QA=10012,ZA=10015,YA=10030,XA=10050,ex=10096,tx=10063,nx=13194,rx=21e3,ox=22242,ix=23194,sx=23195,ax=24133,cx=27235,ux=3e4,lx=30001,fx=30002,hx=30003,dx=30004,px=30008,gx=30009,yx=30015,mx=30017,wx=30018,bx=30023,vx=30024,Ex=30030,Ax=30078,xx=30311,kx=30315,Sx=30402,Ix=30403,Cx=31922,Ox=31923,Tx=31924,Nx=31925,Px=31987,Bx=31989,Rx=31990,Ux=34550,Dx=39e3;function Lx(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,o=e.slice(r).indexOf('"')+r+1;return e.slice(o,o+64)}function Fx(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,o=e.slice(r),i=Math.min(o.indexOf(","),o.indexOf("}"));return parseInt(o.slice(0,i),10)}function _x(e){let t=e.slice(0,22).indexOf('"EVENT"');if(-1===t)return null;let n=e.slice(t+7+1).indexOf('"');if(-1===n)return null;let r=t+7+1+n,o=e.slice(r+1,80).indexOf('"');if(-1===o)return null;let i=r+1+o;return e.slice(r+1,i)}function Mx(e,t){return t===Lx(e,"id")}function Gx(e,t){return t===Lx(e,"pubkey")}function jx(e,t){return t===Fx(e,"kind")}function Hx(e,t){return{kind:ox,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}TE({},{getHex64:()=>Lx,getInt:()=>Fx,getSubscriptionId:()=>_x,matchEventId:()=>Mx,matchEventKind:()=>jx,matchEventPubkey:()=>Gx}),TE({},{makeAuthEvent:()=>Hx}),Error;try{WebSocket}catch{}try{WebSocket}catch{}TE({},{BECH32_REGEX:()=>Kx,Bech32MaxSize:()=>Vx,NostrTypeGuard:()=>zx,decode:()=>$x,decodeNostrURI:()=>Wx,encodeBytes:()=>Xx,naddrEncode:()=>nk,neventEncode:()=>tk,noteEncode:()=>Zx,nprofileEncode:()=>ek,npubEncode:()=>Qx,nsecEncode:()=>Jx});var zx={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Vx=5e3,Kx=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function Wx(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),$x(e)}catch(e){return{type:"invalid",data:null}}}function $x(e){let{prefix:t,words:n}=mv.decode(e,Vx),r=new Uint8Array(mv.fromWords(n));switch(t){case"nprofile":{let e=qx(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nprofile");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:$m(e[0][0]),relays:e[1]?e[1].map(e=>RE.decode(e)):[]}}}case"nevent":{let e=qx(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nevent");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");if(e[2]&&32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(e[3]&&4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:$m(e[0][0]),relays:e[1]?e[1].map(e=>RE.decode(e)):[],author:e[2]?.[0]?$m(e[2][0]):void 0,kind:e[3]?.[0]?parseInt($m(e[3][0]),16):void 0}}}case"naddr":{let e=qx(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for naddr");if(!e[2]?.[0])throw new Error("missing TLV 2 for naddr");if(32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(!e[3]?.[0])throw new Error("missing TLV 3 for naddr");if(4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:RE.decode(e[0][0]),pubkey:$m(e[2][0]),kind:parseInt($m(e[3][0]),16),relays:e[1]?e[1].map(e=>RE.decode(e)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:$m(r)};default:throw new Error(`unknown prefix ${t}`)}}function qx(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],o=n.slice(2,2+r);if(n=n.slice(2+r),o.length<r)throw new Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(o)}return t}function Jx(e){return Xx("nsec",e)}function Qx(e){return Xx("npub",Jm(e))}function Zx(e){return Xx("note",Jm(e))}function Yx(e,t){let n=mv.toWords(t);return mv.encode(e,n,Vx)}function Xx(e,t){return Yx(e,t)}function ek(e){return Yx("nprofile",rk({0:[Jm(e.pubkey)],1:(e.relays||[]).map(e=>UE.encode(e))}))}function tk(e){let t;return void 0!==e.kind&&(t=function(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=255&e,t}(e.kind)),Yx("nevent",rk({0:[Jm(e.id)],1:(e.relays||[]).map(e=>UE.encode(e)),2:e.author?[Jm(e.author)]:[],3:t?[new Uint8Array(t)]:[]}))}function nk(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),Yx("naddr",rk({0:[UE.encode(e.identifier)],1:(e.relays||[]).map(e=>UE.encode(e)),2:[Jm(e.pubkey)],3:[new Uint8Array(t)]}))}function rk(e){let t=[];return Object.entries(e).reverse().forEach(([e,n])=>{n.forEach(n=>{let r=new Uint8Array(n.length+2);r.set([parseInt(e)],0),r.set([n.length],1),r.set(n,2),t.push(r)})}),Qm(...t)}function ok(e,t,n){const r=e instanceof Uint8Array?e:Jm(e),o=sk(Nb.getSharedSecret(r,Jm("02"+t)));let i=Uint8Array.from(Ym(16)),s=UE.encode(n),a=oE(o,i).encrypt(s);return`${lv.encode(new Uint8Array(a))}?iv=${lv.encode(new Uint8Array(i.buffer))}`}function ik(e,t,n){const r=e instanceof Uint8Array?e:Jm(e);let[o,i]=n.split("?iv="),s=sk(Nb.getSharedSecret(r,Jm("02"+t))),a=lv.decode(i),c=lv.decode(o),u=oE(s,a).decrypt(c);return RE.decode(u)}function sk(e){return e.slice(1,33)}TE({},{decrypt:()=>ik,encrypt:()=>ok}),TE({},{NIP05_REGEX:()=>ck,isNip05:()=>uk,isValid:()=>dk,queryProfile:()=>hk,searchDomain:()=>fk,useFetchImplementation:()=>lk});var ak,ck=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,uk=e=>ck.test(e||"");try{ak=fetch}catch(e){}function lk(e){ak=e}async function fk(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await ak(n,{redirect:"manual"});if(200!==r.status)throw Error("Wrong response code");return(await r.json()).names}catch(e){return{}}}async function hk(e){const t=e.match(ck);if(!t)return null;const[,n="_",r]=t;try{const e=`https://${r}/.well-known/nostr.json?name=${n}`,t=await ak(e,{redirect:"manual"});if(200!==t.status)throw Error("Wrong response code");const o=await t.json(),i=o.names[n];return i?{pubkey:i,relays:o.relays?.[i]}:null}catch(e){return null}}async function dk(e,t){const n=await hk(t);return!!n&&n.pubkey===e}function pk(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let o=e.tags.length-1;o>=0;o--){const i=e.tags[o];if("e"===i[0]&&i[1]){const[e,o,s,a,c]=i,u={id:o,relays:s?[s]:[],author:c};if("root"===a){t.root=u;continue}if("reply"===a){t.reply=u;continue}if("mention"===a){t.mentions.push(u);continue}n?r=u:n=u,t.mentions.push(u);continue}if("q"===i[0]&&i[1]){const[e,n,r]=i;t.quotes.push({id:n,relays:r?[r]:[]})}"p"===i[0]&&i[1]&&t.profiles.push({pubkey:i[1],relays:i[2]?[i[2]]:[]})}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(e=>{if(!e)return;let n=t.mentions.indexOf(e);if(-1!==n&&t.mentions.splice(n,1),e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays?.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t.mentions.forEach(e=>{if(e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t}TE({},{parse:()=>pk}),TE({},{fetchRelayInformation:()=>yk,useFetchImplementation:()=>gk});try{fetch}catch{}function gk(e){}async function yk(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}function mk(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(0!==r){t+=Math.clz32(r);break}t+=32}return t}function wk(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(0!==r){t+=Math.clz32(r)-24;break}t+=8}return t}function bk(e,t){let n=0;const r=e,o=["nonce",n.toString(),t.toString()];for(r.tags.push(o);;){const e=Math.floor((new Date).getTime()/1e3);e!==r.created_at&&(n=0,r.created_at=e),o[1]=(++n).toString();const i=cw(UE.encode(JSON.stringify([0,r.pubkey,r.created_at,r.kind,r.tags,r.content])));if(wk(i)>=t){r.id=$m(i);break}}return r}TE({},{getPow:()=>mk,minePow:()=>bk}),TE({},{unwrapEvent:()=>zk,unwrapManyEvents:()=>Vk,wrapEvent:()=>jk,wrapManyEvents:()=>Hk}),TE({},{createRumor:()=>Uk,createSeal:()=>Dk,createWrap:()=>Lk,unwrapEvent:()=>Mk,unwrapManyEvents:()=>Gk,wrapEvent:()=>Fk,wrapManyEvents:()=>_k}),TE({},{decrypt:()=>Ck,encrypt:()=>Ik,getConversationKey:()=>Ak,v2:()=>Ok});var vk=1,Ek=65535;function Ak(e,t){const n=Nb.getSharedSecret(e,Jm("02"+t)).subarray(1,33);return r=cw,o=n,i=UE.encode("nip44-v2"),Gm(r),void 0===i&&(i=new Uint8Array(r.outputLen)),ub(r,i,o);var r,o,i}function xk(e,t){const n=function(e,t,n,r=32){Gm(e),_m(r,"length");const o=e.outputLen;if(r>255*o)throw new Error("Length must be <= 255*HashLen");const i=Math.ceil(r/o);void 0===n?n=CE:Mm(n,void 0,"info");const s=new Uint8Array(i*o),a=ub.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let e=0;e<i;e++)IE[0]=e+1,c.update(0===e?CE:u).update(n).update(IE).digestInto(u),s.set(u,o*e),a._cloneInto(c);return a.destroy(),c.destroy(),Hm(u,IE),s.slice(0,r)}(cw,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function kk(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function Sk(e,t,n){if(32!==n.length)throw new Error("AAD associated data must be 32 bytes");const r=Qm(n,t);return ub(cw,e,r)}function Ik(e,t,n=Ym(32)){const{chacha_key:r,chacha_nonce:o,hmac_key:i}=xk(t,n),s=function(e){const t=UE.encode(e),n=t.length;return Qm(function(e){if(!Number.isSafeInteger(e)||e<vk||e>Ek)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}(n),t,new Uint8Array(kk(n)-n))}(e),a=bE(r,o,s),c=Sk(i,a,n);return lv.encode(Qm(new Uint8Array([2]),n,a,c))}function Ck(e,t){const{nonce:n,ciphertext:r,mac:o}=function(e){if("string"!=typeof e)throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if("#"===e[0])throw new Error("unknown encryption version");let n;try{n=lv.decode(e)}catch(e){throw new Error("invalid base64: "+e.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const o=n[0];if(2!==o)throw new Error("unknown encryption version "+o);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}(e),{chacha_key:i,chacha_nonce:s,hmac_key:a}=xk(t,n);if(!Ov(Sk(a,r,n),o))throw new Error("invalid MAC");return function(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<vk||t>Ek||n.length!==t||e.length!==2+kk(t))throw new Error("invalid padding");return RE.decode(n)}(bE(i,s,r))}var Ok={utils:{getConversationKey:Ak,calcPaddedLen:kk},encrypt:Ik,decrypt:Ck},Tk=()=>Math.round(Date.now()/1e3),Nk=()=>Math.round(Tk()-172800*Math.random()),Pk=(e,t)=>Ak(e,t),Bk=(e,t,n)=>Ik(JSON.stringify(e),Pk(t,n)),Rk=(e,t)=>JSON.parse(Ck(e.content,Pk(t,e.pubkey)));function Uk(e,t){const n={created_at:Tk(),content:"",tags:[],...e,pubkey:zE(t)};return n.id=GE(n),n}function Dk(e,t,n){return VE({kind:uA,content:Bk(e,t,n),created_at:Nk(),tags:[]},t)}function Lk(e,t){const n=HE();return VE({kind:AA,content:Bk(e,n,t),created_at:Nk(),tags:[["p",t]]},n)}function Fk(e,t,n){return Lk(Dk(Uk(e,t),t,n),n)}function _k(e,t,n){if(!n||0===n.length)throw new Error("At least one recipient is required.");const r=zE(t),o=[Fk(e,t,r)];return n.forEach(n=>{o.push(Fk(e,t,n))}),o}function Mk(e,t){const n=Rk(e,t);return Rk(n,t)}function Gk(e,t){let n=[];return e.forEach(e=>{n.push(Mk(e,t))}),n.sort((e,t)=>e.created_at-t.created_at),n}function jk(e,t,n,r,o){const i=function(e,t,n,r){const o={created_at:Math.ceil(Date.now()/1e3),kind:lA,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:e,relayUrl:t})=>{o.tags.push(t?["p",e,t]:["p",e])}),r&&o.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&o.tags.push(["subject",n]),o}(t,n,r,o);return Fk(i,e,t.publicKey)}function Hk(e,t,n,r,o){if(!t||0===t.length)throw new Error("At least one recipient is required.");return[{publicKey:zE(e)},...t].map(t=>jk(e,t,n,r,o))}var zk=Mk,Vk=Gk;function Kk(e,t,n,r){let o;const i=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===XE?o=oA:(o=hA,i.push(["k",String(t.kind)])),VE({kind:o,tags:i,content:""===e.content||t.tags?.find(e=>"-"===e[0])?"":JSON.stringify(t),created_at:e.created_at},r)}function Wk(e){if(![oA,hA].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const o=e.tags[r];o.length>=2&&("e"===o[0]&&void 0===t?t=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==t?{id:t[1],relays:[t[2],n?.[2]].filter(e=>"string"==typeof e),author:n?.[1]}:void 0}function $k(e,{skipVerification:t}={}){const n=Wk(e);if(void 0===n||""===e.content)return;let r;try{r=JSON.parse(e.content)}catch(e){return}return r.id===n.id&&(t||KE(r))?r:void 0}TE({},{finishRepostEvent:()=>Kk,getRepostedEvent:()=>$k,getRepostedEventPointer:()=>Wk}),TE({},{NOSTR_URI_REGEX:()=>qk,parse:()=>Qk,test:()=>Jk});var qk=new RegExp(`nostr:(${Kx.source})`);function Jk(e){return"string"==typeof e&&new RegExp(`^${qk.source}$`).test(e)}function Qk(e){const t=e.match(new RegExp(`^${qk.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:$x(t[1])}}function Zk(e,t,n){const r=t.tags.filter(e=>e.length>=2&&("e"===e[0]||"p"===e[0]));return VE({...e,kind:iA,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function Yk(e){if(e.kind!==iA)return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const o=e.tags[r];o.length>=2&&("e"===o[0]&&void 0===t?t=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==t&&void 0!==n?{id:t[1],relays:[t[2],n[2]].filter(e=>void 0!==e),author:n[1]}:void 0}TE({},{finishReactionEvent:()=>Zk,getReactedEventPointer:()=>Yk}),TE({},{parse:()=>nS});var Xk=/\W/m,eS=/[^\w\/] |[^\w\/]$|$|,| /m,tS=42;function*nS(e){let t=[];if("string"!=typeof e){for(let n=0;n<e.tags.length;n++){const r=e.tags[n];"emoji"===r[0]&&r.length>=3&&t.push({type:"emoji",shortcode:r[1],url:r[2]})}e=e.content}const n=e.length;let r=0,o=0;e:for(;o<n;){const i=e.indexOf(":",o),s=e.indexOf("#",o);if(-1===i&&-1===s)break e;if(-1===i||s>=0&&s<i){if(0===s||e[s-1].match(Xk)){const t=e.slice(s+1,s+tS).match(Xk),i=t?s+1+t.index:n;yield{type:"text",text:e.slice(r,s)},yield{type:"hashtag",value:e.slice(s+1,i)},o=i,r=o;continue e}o=s+1}else if("nostr"===e.slice(i-5,i)){const t=e.slice(i+60).match(Xk),s=t?i+60+t.index:n;try{let t,{data:n,type:a}=$x(e.slice(i+1,s));switch(a){case"npub":t={pubkey:n};break;case"note":t={id:n};break;case"nsec":o=s+1;continue;default:t=n}r!==i-5&&(yield{type:"text",text:e.slice(r,i-5)}),yield{type:"reference",pointer:t},o=s,r=o;continue e}catch(e){o=i+1;continue e}}else if("https"===e.slice(i-5,i)||"http"===e.slice(i-4,i)){const t=e.slice(i+4).match(eS),s=t?i+4+t.index:n,a="s"===e[i-1]?5:4;try{let t=new URL(e.slice(i-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid url");if(r!==i-a&&(yield{type:"text",text:e.slice(r,i-a)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(t.pathname)){yield{type:"image",url:t.toString()},o=s,r=o;continue e}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(t.pathname)){yield{type:"video",url:t.toString()},o=s,r=o;continue e}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(t.pathname)){yield{type:"audio",url:t.toString()},o=s,r=o;continue e}yield{type:"url",url:t.toString()},o=s,r=o;continue e}catch(e){o=s+1;continue e}}else{if("wss"!==e.slice(i-3,i)&&"ws"!==e.slice(i-2,i)){for(let n=0;n<t.length;n++){const s=t[n];if(":"===e[i+s.shortcode.length+1]&&e.slice(i+1,i+s.shortcode.length+1)===s.shortcode){r!==i&&(yield{type:"text",text:e.slice(r,i)}),yield s,o=i+s.shortcode.length+2,r=o;continue e}}o=i+1;continue e}{const t=e.slice(i+4).match(eS),s=t?i+4+t.index:n,a="s"===e[i-1]?3:2;try{let t=new URL(e.slice(i-a,s));if(-1===t.hostname.indexOf("."))throw new Error("invalid ws url");r!==i-a&&(yield{type:"text",text:e.slice(r,i-a)}),yield{type:"relay",url:t.toString()},o=s,r=o;continue e}catch(e){o=s+1;continue e}}}}r!==n&&(yield{type:"text",text:e.slice(r)})}TE({},{channelCreateEvent:()=>rS,channelHideMessageEvent:()=>sS,channelMessageEvent:()=>iS,channelMetadataEvent:()=>oS,channelMuteUserEvent:()=>aS});var rS=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return VE({kind:yA,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},oS=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return VE({kind:mA,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},iS=(e,t)=>{const n=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&n.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),VE({kind:wA,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},sS=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return VE({kind:bA,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},aS=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return VE({kind:vA,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)};TE({},{EMOJI_SHORTCODE_REGEX:()=>lS,matchAll:()=>hS,regex:()=>fS,replaceAll:()=>dS});var cS,uS,lS=/:(\w+):/,fS=()=>new RegExp(`\\B${lS.source}\\B`,"g");function*hS(e){const t=e.matchAll(fS());for(const e of t)try{const[t,n]=e;yield{shortcode:t,name:n,start:e.index,end:e.index+t.length}}catch(e){}}function dS(e,t){return e.replaceAll(fS(),(e,n)=>t({shortcode:e,name:n}))}TE({},{useFetchImplementation:()=>pS,validateGithub:()=>gS});try{cS=fetch}catch{}function pS(e){cS=e}async function gS(e,t,n){try{return await(await cS(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch(e){return!1}}function yS(e){const{host:t,pathname:n,searchParams:r}=new URL(e),o=n||t,i=r.get("relay"),s=r.get("secret");if(!o||!i||!s)throw new Error("invalid connection string");return{pubkey:o,relay:i,secret:s}}async function mS(e,t,n){const r={method:"pay_invoice",params:{invoice:n}},o=ok(t,e,JSON.stringify(r)),i={kind:ix,created_at:Math.round(Date.now()/1e3),content:o,tags:[["p",e]]};return VE(i,t)}function wS(e){return e=(e=e.trim().toLowerCase()).normalize("NFKC"),Array.from(e).map(e=>/\p{Letter}/u.test(e)||/\p{Number}/u.test(e)?e:"-").join("")}TE({},{makeNwcRequestEvent:()=>mS,parseConnectionString:()=>yS}),TE({},{normalizeIdentifier:()=>wS}),TE({},{getSatoshisAmountFromBolt11:()=>kS,getZapEndpoint:()=>vS,makeZapReceipt:()=>xS,makeZapRequest:()=>ES,useFetchImplementation:()=>bS,validateZapRequest:()=>AS});try{uS=fetch}catch{}function bS(e){uS=e}async function vS(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(r){let[e,n]=r.split("@");t=new URL(`/.well-known/lnurlp/${e}`,`https://${n}`).toString()}else{if(!n)return null;{let{words:e}=mv.decode(n,1e3),r=mv.fromWords(e);t=RE.decode(r)}}let o=await uS(t),i=await o.json();if(i.allowsNostr&&i.nostrPubkey)return i.callback}catch(e){}return null}function ES(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),$E(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(JE(e.event.kind)){let n=e.event.tags.find(([e,t])=>"d"===e&&t);if(!n)throw new Error("d tag not found or is empty");const r=["a",`${e.event.kind}:${e.event.pubkey}:${n[1]}`];t.tags.push(r)}t.tags.push(["k",e.event.kind.toString()])}return t}function AS(e){let t;try{t=JSON.parse(e)}catch(e){return"Invalid zap request JSON."}if(!PE(t))return"Zap request is not a valid Nostr event.";if(!KE(t))return"Invalid signature on zap request.";let n=t.tags.find(([e,t])=>"p"===e&&t);if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=t.tags.find(([e,t])=>"e"===e&&t);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([e,t])=>"relays"===e&&t)?null:"Zap request doesn't have a 'relays' tag."}function xS({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let o=JSON.parse(e),i=o.tags.filter(([e])=>"e"===e||"p"===e||"a"===e),s={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...i,["P",o.pubkey],["bolt11",n],["description",e]]};return t&&s.tags.push(["preimage",t]),s}function kS(e){if(e.length<50)return 0;const t=(e=e.substring(0,50)).lastIndexOf("1");if(-1===t)return 0;const n=e.substring(0,t);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const o=r[r.length-1],i=o.charCodeAt(0)-"0".charCodeAt(0),s=i>=0&&i<=9;let a=r.length-1;if(s&&a++,a<1)return 0;const c=parseInt(r.substring(0,a));switch(o){case"m":return 1e5*c;case"u":return 100*c;case"n":return c/10;case"p":return c/1e4;default:return 1e8*c}}TE({},{Negentropy:()=>BS,NegentropyStorageVector:()=>PS,NegentropySync:()=>DS});var SS=32,IS=class{_raw;length;constructor(e){"number"==typeof e?(this._raw=new Uint8Array(e),this.length=0):e instanceof Uint8Array?(this._raw=new Uint8Array(e),this.length=e.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(e){if(e instanceof IS&&(e=e.unwrap()),"number"!=typeof e.length)throw Error("bad length");const t=e.length+this.length;if(this.capacity<t){const e=this._raw,n=Math.max(2*this.capacity,t);this._raw=new Uint8Array(n),this._raw.set(e)}this._raw.set(e,this.length),this.length+=e.length}shift(){const e=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,e}shiftN(e=1){const t=this._raw.subarray(0,e);return this._raw=this._raw.subarray(e),this.length-=e,t}};function CS(e){let t=0;for(;;){if(0===e.length)throw Error("parse ends prematurely");let n=e.shift();if(t=t<<7|127&n,!(128&n))break}return t}function OS(e){if(0===e)return new IS(new Uint8Array([0]));let t=[];for(;0!==e;)t.push(127&e),e>>>=7;t.reverse();for(let e=0;e<t.length-1;e++)t[e]|=128;return new IS(new Uint8Array(t))}function TS(e,t){if(e.length<t)throw Error("parse ends prematurely");return e.shiftN(t)}var NS=class{buf;constructor(){this.setToZero()}setToZero(){this.buf=new Uint8Array(SS)}add(e){let t=0,n=0,r=new DataView(this.buf.buffer),o=new DataView(e.buffer);for(let e=0;e<8;e++){let i=4*e,s=r.getUint32(i,!0);s+=t,s+=o.getUint32(i,!0),s>4294967295&&(n=1),r.setUint32(i,4294967295&s,!0),t=n,n=0}}negate(){let e=new DataView(this.buf.buffer);for(let t=0;t<8;t++){let n=4*t;e.setUint32(n,~e.getUint32(n,!0))}let t=new Uint8Array(SS);t[0]=1,this.add(t)}getFingerprint(e){let t=new IS;return t.extend(this.buf),t.extend(OS(e)),cw(t.unwrap()).subarray(0,16)}},PS=class{items;sealed;constructor(){this.items=[],this.sealed=!1}insert(e,t){if(this.sealed)throw Error("already sealed");const n=Jm(t);if(n.byteLength!==SS)throw Error("bad id size for added item");this.items.push({timestamp:e,id:n})}seal(){if(this.sealed)throw Error("already sealed");this.sealed=!0,this.items.sort(US);for(let e=1;e<this.items.length;e++)if(0===US(this.items[e-1],this.items[e]))throw Error("duplicate item inserted")}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(e){if(this._checkSealed(),e>=this.items.length)throw Error("out of range");return this.items[e]}iterate(e,t,n){this._checkSealed(),this._checkBounds(e,t);for(let r=e;r<t&&n(this.items[r],r);++r);}findLowerBound(e,t,n){return this._checkSealed(),this._checkBounds(e,t),this._binarySearch(this.items,e,t,e=>US(e,n)<0)}fingerprint(e,t){let n=new NS;return n.setToZero(),this.iterate(e,t,e=>(n.add(e.id),!0)),n.getFingerprint(t-e)}_checkSealed(){if(!this.sealed)throw Error("not sealed")}_checkBounds(e,t){if(e>t||t>this.items.length)throw Error("bad range")}_binarySearch(e,t,n,r){let o=n-t;for(;o>0;){let n=t,i=Math.floor(o/2);n+=i,r(e[n])?(t=++n,o-=i+1):o=i}return t}},BS=class{storage;frameSizeLimit;lastTimestampIn;lastTimestampOut;constructor(e,t=6e4){if(t<4096)throw Error("frameSizeLimit too small");this.storage=e,this.frameSizeLimit=t,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(e,t){return{timestamp:e,id:t||new Uint8Array(0)}}initiate(){let e=new IS;return e.extend(new Uint8Array([97])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),e),$m(e.unwrap())}reconcile(e,t,n){const r=new IS(Jm(e));this.lastTimestampIn=this.lastTimestampOut=0;let o=new IS;o.extend(new Uint8Array([97]));let i=TS(r,1)[0];if(i<96||i>111)throw Error("invalid negentropy protocol version byte");if(97!==i)throw Error("unsupported negentropy protocol version requested: "+(i-96));let s=this.storage.size(),a=this._bound(0),c=0,u=!1;for(;0!==r.length;){let e=new IS,i=()=>{u&&(u=!1,e.extend(this.encodeBound(a)),e.extend(OS(0)))},l=this.decodeBound(r),f=CS(r),h=c,d=this.storage.findLowerBound(c,s,l);if(0===f)u=!0;else if(1===f)0!==RS(TS(r,16),this.storage.fingerprint(h,d))?(i(),this.splitRange(h,d,l,e)):u=!0;else{if(2!==f)throw Error("unexpected mode");{let e=CS(r),o={};for(let t=0;t<e;t++){let e=TS(r,SS);o[$m(e)]=e}if(u=!0,this.storage.iterate(h,d,e=>{let n=e.id;const r=$m(n);return o[r]?delete o[$m(n)]:t?.(r),!0}),n)for(let e of Object.values(o))n($m(e))}}if(this.exceededFrameSizeLimit(o.length+e.length)){let e=this.storage.fingerprint(d,s);o.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),o.extend(OS(1)),o.extend(e);break}o.extend(e),c=d,a=l}return 1===o.length?null:$m(o.unwrap())}splitRange(e,t,n,r){let o=t-e;if(o<32)r.extend(this.encodeBound(n)),r.extend(OS(2)),r.extend(OS(o)),this.storage.iterate(e,t,e=>(r.extend(e.id),!0));else{let i=Math.floor(o/16),s=o%16,a=e;for(let e=0;e<16;e++){let o,c=i+(e<s?1:0),u=this.storage.fingerprint(a,a+c);if(a+=c,a===t)o=n;else{let e,t;this.storage.iterate(a-1,a+1,(n,r)=>(r===a-1?e=n:t=n,!0)),o=this.getMinimalBound(e,t)}r.extend(this.encodeBound(o)),r.extend(OS(1)),r.extend(u)}}}exceededFrameSizeLimit(e){return e>this.frameSizeLimit-200}decodeTimestampIn(e){let t=CS(e);return t=0===t?Number.MAX_VALUE:t-1,this.lastTimestampIn===Number.MAX_VALUE||t===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(t+=this.lastTimestampIn,this.lastTimestampIn=t,t)}decodeBound(e){let t=this.decodeTimestampIn(e),n=CS(e);if(n>SS)throw Error("bound key too long");return{timestamp:t,id:TS(e,n)}}encodeTimestampOut(e){if(e===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,OS(0);let t=e;return e-=this.lastTimestampOut,this.lastTimestampOut=t,OS(e+1)}encodeBound(e){let t=new IS;return t.extend(this.encodeTimestampOut(e.timestamp)),t.extend(OS(e.id.length)),t.extend(e.id),t}getMinimalBound(e,t){if(t.timestamp!==e.timestamp)return this._bound(t.timestamp);{let n=0,r=t.id,o=e.id;for(let e=0;e<SS&&r[e]===o[e];e++)n++;return this._bound(t.timestamp,t.id.subarray(0,n+1))}}};function RS(e,t){for(let n=0;n<e.byteLength;n++){if(e[n]<t[n])return-1;if(e[n]>t[n])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function US(e,t){return e.timestamp===t.timestamp?RS(e.id,t.id):e.timestamp-t.timestamp}var DS=class{relay;storage;neg;filter;subscription;onhave;onneed;constructor(e,t,n,r={}){this.relay=e,this.storage=t,this.neg=new BS(t),this.onhave=r.onhave,this.onneed=r.onneed,this.filter=n,this.subscription=this.relay.prepareSubscription([{}],{label:r.label||"negentropy"}),this.subscription.oncustom=e=>{switch(e[0]){case"NEG-MSG":e.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${e}`);try{const t=this.neg.reconcile(e[2],this.onhave,this.onneed);t?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${t}"]`):(this.close(),r.onclose?.())}catch(e){console.error("negentropy reconcile error:",e),r?.onclose?.(`reconcile error: ${e}`)}break;case"NEG-CLOSE":{const t=e[2];console.warn("negentropy error:",t),r.onclose?.(t);break}case"NEG-ERR":r.onclose?.()}}}async start(){const e=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${e}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}};TE({},{getToken:()=>FS,hashPayload:()=>VS,unpackEventFromToken:()=>MS,validateEvent:()=>WS,validateEventKind:()=>jS,validateEventMethodTag:()=>zS,validateEventPayloadTag:()=>KS,validateEventTimestamp:()=>GS,validateEventUrlTag:()=>HS,validateToken:()=>_S});var LS="Nostr ";async function FS(e,t,n,r=!1,o){const i={kind:cx,tags:[["u",e],["method",t]],created_at:Math.round((new Date).getTime()/1e3),content:""};o&&i.tags.push(["payload",VS(o)]);const s=await n(i);return(r?LS:"")+lv.encode(UE.encode(JSON.stringify(s)))}async function _S(e,t,n){const r=await MS(e).catch(e=>{throw e});return await WS(r,t,n).catch(e=>{throw e})}async function MS(e){if(!e)throw new Error("Missing token");e=e.replace(LS,"");const t=RE.decode(lv.decode(e));if(!t||0===t.length||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function GS(e){return!!e.created_at&&Math.round((new Date).getTime()/1e3)-e.created_at<60}function jS(e){return e.kind===cx}function HS(e,t){const n=e.tags.find(e=>"u"===e[0]);return!!n&&n.length>0&&n[1]===t}function zS(e,t){const n=e.tags.find(e=>"method"===e[0]);return!!n&&n.length>0&&n[1].toLowerCase()===t.toLowerCase()}function VS(e){return $m(cw(UE.encode(JSON.stringify(e))))}function KS(e,t){const n=e.tags.find(e=>"payload"===e[0]);if(!n)return!1;const r=VS(t);return n.length>0&&n[1]===r}async function WS(e,t,n,r){if(!KE(e))throw new Error("Invalid nostr event, signature invalid");if(!jS(e))throw new Error("Invalid nostr event, kind invalid");if(!GS(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!HS(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!zS(e,n))throw new Error("Invalid nostr event, method tag invalid");if(Boolean(r)&&"object"==typeof r&&Object.keys(r).length>0&&!KS(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}r(287).hp;var $S=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),qS=function(){return qS=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},qS.apply(this,arguments)},JS=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},QS=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},ZS="I Love Shogun!",YS=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return n.DEFAULT_CONFIG={cacheDuration:864e5,maxRetries:3,retryDelay:1e3,timeout:6e4,network:"mainnet",useApi:!1},n.signatureCache=new Map,n.connectedAddress=null,n.connectedType=null,n.manualKeyPair=null,n.config=qS(qS({},n.DEFAULT_CONFIG),t),n.setupEventListeners(),n}return $S(t,e),t.prototype.setupEventListeners=function(){},t.prototype.clearSignatureCache=function(e){if(e){this.signatureCache.delete(e);try{var t="shogun_bitcoin_sig_".concat(e);localStorage.removeItem(t),console.log("Cleared signature cache for address: ".concat(e.substring(0,10),"..."))}catch(e){console.error("Error clearing signature cache from localStorage:",e)}}else{this.signatureCache.clear();try{for(var n=[],r=0;r<localStorage.length;r++){var o=localStorage.key(r);o&&o.startsWith("shogun_bitcoin_sig_")&&n.push(o)}n.forEach(function(e){return localStorage.removeItem(e)}),console.log("Cleared all signature caches (".concat(n.length," entries)"))}catch(e){console.error("Error clearing all signature caches from localStorage:",e)}}},t.prototype.isNostrExtensionAvailable=function(){return"undefined"!=typeof window&&!!window.nostr},t.prototype.isAvailable=function(){return this.isNostrExtensionAvailable()||null!==this.manualKeyPair},t.prototype.connectWallet=function(){return JS(this,arguments,void 0,function(e){var t,n;return void 0===e&&(e="nostr"),QS(this,function(r){switch(r.label){case 0:console.log("Connecting to Bitcoin wallet via ".concat(e,"...")),r.label=1;case 1:switch(r.trys.push([1,10,,11]),t=void 0,e){case"alby":return[3,2];case"nostr":return[3,4];case"manual":return[3,6]}return[3,8];case 2:return console.log("[nostrConnector] Alby is deprecated, redirecting to Nostr"),[4,this.connectNostr()];case 3:return t=r.sent(),[3,9];case 4:return[4,this.connectNostr()];case 5:return t=r.sent(),[3,9];case 6:return[4,this.connectManual()];case 7:return t=r.sent(),[3,9];case 8:throw new Error("Unsupported wallet type: ".concat(e));case 9:return t.success&&t.address&&(this.connectedAddress=t.address,this.connectedType=e,console.log("Successfully connected to ".concat(e," wallet: ").concat(t.address)),this.emit("wallet_connected",{address:t.address,type:this.connectedType})),[2,t];case 10:return n=r.sent(),console.error("Error connecting to ".concat(e," wallet:"),n),[2,{success:!1,error:n.message||"Failed to connect to wallet"}];case 11:return[2]}})})},t.prototype.connectNostr=function(){return JS(this,void 0,void 0,function(){var e,t,n;return QS(this,function(r){switch(r.label){case 0:if(!this.isNostrExtensionAvailable())return[2,{success:!1,error:"Nostr extension is not available. Please install a Nostr compatible extension like nos2x, Alby, or Coracle."}];r.label=1;case 1:return r.trys.push([1,3,,4]),console.log("[nostrConnector] Attempting to connect to Nostr extension..."),[4,window.nostr.getPublicKey()];case 2:if(!(e=r.sent()))throw new Error("Could not get public key from Nostr extension");return console.log("[nostrConnector] Successfully connected to Nostr extension: ".concat(e.substring(0,10),"...")),this.connectedAddress=e,this.connectedType="nostr",this.emit("connected",{address:e,type:"nostr"}),t="nostr_".concat(e.substring(0,10)),[2,{success:!0,address:e,username:t,extensionType:"nostr"}];case 3:throw n=r.sent(),console.error("[nostrConnector] Nostr connection error:",n),n.message&&n.message.includes("User rejected")?new Error("Nostr connection was rejected by the user"):n.message&&n.message.includes("not available")?new Error("Nostr extension is not available or not properly installed"):new Error("Nostr connection error: ".concat(n.message));case 4:return[2]}})})},t.prototype.connectManual=function(){return JS(this,void 0,void 0,function(){var e;return QS(this,function(t){return this.manualKeyPair?(this.connectedAddress=this.manualKeyPair.address,this.connectedType="manual",this.emit("connected",{address:this.manualKeyPair.address,type:"manual"}),e="btc_".concat(this.manualKeyPair.address.substring(0,10)),[2,{success:!0,address:this.manualKeyPair.address,username:e,extensionType:"manual"}]):[2,{success:!1,error:"No manual key pair configured. Use setKeyPair() first."}]})})},t.prototype.setKeyPair=function(e){this.manualKeyPair=e,e.address&&(this.connectedAddress=e.address,this.connectedType="manual")},t.prototype.generateCredentials=function(e,t,n){return JS(this,void 0,void 0,function(){var r,o,i,s;return QS(this,function(a){switch(a.label){case 0:return u={id:e},r="web3"==(c="nostr")&&u.id?"web3_".concat(u.id.toLowerCase()):u.id?"nostr_".concat(u.id):u.email&&(l=u.email)&&"string"==typeof l&&/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(l)?"".concat(c,"_").concat(u.email.split("@")[0]):u.name?"".concat(c,"_").concat(u.name.replace(/\s+/g,"_")):u.id?"".concat(c,"_").concat(u.id):"".concat(c,"_user"),o=Vt(xe(e)),i="".concat(r,"_").concat(e,"_").concat(n,"_").concat(t),[4,di(o,i,{includeP256:!0})];case 1:return s=a.sent(),[2,{username:r,key:s,message:n,signature:t}]}var c,u,l})})},t.prototype.generatePassword=function(e){return JS(this,void 0,void 0,function(){return QS(this,function(t){if(!e)throw new Error("Invalid signature");try{return[2,kt(xe(e.toLowerCase().replace(/[^a-f0-9]/g,"")))]}catch(e){throw console.error("Error generating password:",e),new Error("Failed to generate password from signature")}})})},t.prototype.verifySignature=function(e,t,n){return JS(this,void 0,void 0,function(){var r,o,i,s;return QS(this,function(a){try{if(r="object"==typeof n?n.address||JSON.stringify(n):String(n),console.log("Verifying signature for address: ".concat(r)),!t||!e||!r)return console.error("Invalid message, signature, or address for verification"),[2,!1];if("nostr"===this.connectedType||"alby"===this.connectedType)try{return o=qS(qS({},i={kind:1,created_at:0,tags:[],content:e,pubkey:r}),{id:GE(i),sig:t}),[2,KE(o)]}catch(e){return console.error("Error in Nostr signature verification:",e),[2,!1]}else if("manual"===this.connectedType&&this.manualKeyPair){if(console.log("[nostrConnector] Manual verification for keypair"),!this.manualKeyPair.privateKey)return console.error("Manual verification failed: private key is missing."),[2,!1];try{return s=qS(qS({},i={kind:1,created_at:0,tags:[],content:e,pubkey:r}),{id:GE(i),sig:t}),[2,KE(s)]}catch(e){return console.error("Error in manual signature verification:",e),[2,!1]}}return console.warn("No specific verification method available, signature cannot be fully verified"),[2,!1]}catch(e){return console.error("Error verifying signature:",e),[2,!1]}})})},t.prototype.getConnectedAddress=function(){return this.connectedAddress},t.prototype.getConnectedType=function(){return this.connectedType},t.prototype.requestSignature=function(e,t){return JS(this,void 0,void 0,function(){var n,r,o,i,s,a,c,u;return QS(this,function(l){switch(l.label){case 0:if(!this.connectedType)throw new Error("No wallet connected");l.label=1;case 1:switch(l.trys.push([1,8,,9]),this.connectedType){case"alby":case"nostr":return[3,2];case"manual":return[3,4]}return[3,6];case 2:if("alby"===this.connectedType&&console.warn("Alby is deprecated, using Nostr functionality for signature request"),console.log("[nostrConnector] Requesting Nostr signature for message:",t),!window.nostr)throw new Error("Nostr extension not available");return r=qS(qS({},n={kind:1,created_at:0,tags:[],content:t,pubkey:e}),{id:GE(n),sig:""}),[4,window.nostr.signEvent(r)];case 3:return o=l.sent(),console.log("Received Nostr signature:",o.sig.substring(0,20)+"..."),[2,o.sig];case 4:if(console.log("[nostrConnector] Using manual key pair for signature"),!this.manualKeyPair||!this.manualKeyPair.privateKey)throw new Error("No manual key pair available or private key missing");return i={kind:1,created_at:0,tags:[],content:t,pubkey:this.manualKeyPair.address},s=qS(qS({},i),{id:GE(i),sig:""}),a=BE.hexToBytes(this.manualKeyPair.privateKey),[4,VE(s,a)];case 5:return c=l.sent(),console.log("Generated manual signature:",c.sig.substring(0,20)+"..."),[2,c.sig];case 6:throw new Error("Unsupported wallet type: ".concat(this.connectedType));case 7:return[3,9];case 8:throw u=l.sent(),console.error("Error requesting signature:",u),new Error("Failed to get signature: ".concat(u.message));case 9:return[2]}})})},t.prototype.cleanup=function(){this.removeAllListeners(),this.connectedAddress=null,this.connectedType=null,this.manualKeyPair=null},t}(W);function XS(e,t,n){return JS(this,void 0,void 0,function(){var t;return QS(this,function(r){switch(r.label){case 0:return t="".concat(e,"_").concat(n),[4,di(e,t,{includeP256:!0})];case 1:return[2,r.sent()]}})})}"undefined"!=typeof window?window.NostrConnector=YS:void 0!==r.g&&(r.g.NostrConnector=YS);var eI,tI,nI=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},rI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},oI=function(){function e(e){this.credentials=new Map,this.MESSAGE_TO_SIGN="I Love Shogun!",this.nostrConnector=e||new YS}return e.prototype.createSigningCredential=function(e){return nI(this,void 0,void 0,function(){var t,n,r,o,i,s;return rI(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),t=this.validateAddress(e),[4,this.generateDeterministicSignature(t)];case 1:return n=a.sent(),r="".concat(t.toLowerCase()),[4,this.generatePassword(n)];case 2:return o=a.sent(),i={address:t,signature:n,message:this.MESSAGE_TO_SIGN,username:r,password:o},this.credentials.set(t.toLowerCase(),i),[2,i];case 3:throw s=a.sent(),K.handle(j.BITCOIN,"NOSTR_CREDENTIAL_ERROR","Error creating Nostr signing credential",s),new Error("Failed to create Nostr signing credential: ".concat(s.message));case 4:return[2]}})})},e.prototype.validateAddress=function(e){if(!e)throw new Error("Address not provided");try{var t=String(e).trim();if(!/^(npub1|[0-9a-f]{64}|bc1|[13])[a-zA-HJ-NP-Z0-9]{25,59}$/.test(t)&&t.length<10)throw new Error("Invalid Nostr/Bitcoin address format");return t}catch(e){throw new Error("Invalid Nostr/Bitcoin address provided")}},e.prototype.generateDeterministicSignature=function(e){return nI(this,void 0,void 0,function(){var t,n,r,o,i,s;return rI(this,function(a){for(t="".concat(e,"_").concat(this.MESSAGE_TO_SIGN,"_shogun_deterministic"),n="",r=0,o=0;o<t.length;o++)i=t.charCodeAt(o),r=31*r+i&4294967295,o%4==3&&(n+=r.toString(16).padStart(8,"0"));for(;n.length<128;)r=31*r+n.length&4294967295,n+=r.toString(16).padStart(8,"0");return(s=(s=n.substring(0,128)).toLowerCase().replace(/[^0-9a-f]/g,"0")).length<128?s=s.padEnd(128,"0"):s.length>128&&(s=s.substring(0,128)),[2,s]})})},e.prototype.generatePassword=function(e){return nI(this,void 0,void 0,function(){return rI(this,function(t){if(!e)throw new Error("Invalid signature");try{return[2,kt(xe(e.toLowerCase().replace(/[^a-f0-9]/g,"")))]}catch(e){throw K.handle(j.ENCRYPTION,"NOSTR_PASSWORD_ERROR","Error generating password",e),new Error("Failed to generate password from signature")}})})},e.prototype.createAuthenticator=function(e){var t=this,n=this.credentials.get(e.toLowerCase());if(!n)throw new Error("Credential for address ".concat(e," not found"));return function(e){return nI(t,void 0,void 0,function(){var t,r;return rI(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),t=JSON.stringify(e),[4,this.signData(t,n)];case 1:return[2,o.sent()];case 2:throw r=o.sent(),K.handle(j.AUTHENTICATION,"NOSTR_AUTH_ERROR","Nostr authentication error",r),r;case 3:return[2]}})})}},e.prototype.signData=function(e,t){return nI(this,void 0,void 0,function(){var n;return rI(this,function(r){return n="".concat(t.signature,"_").concat(e),[2,this.generateDeterministicSignature(n)]})})},e.prototype.createDerivedKeyPair=function(e,t){return nI(this,void 0,void 0,function(){var n,r,o;return rI(this,function(i){switch(i.label){case 0:if(!(n=this.credentials.get(e.toLowerCase())))throw new Error("Credential for address ".concat(e," not found"));i.label=1;case 1:return i.trys.push([1,3,,4]),[4,di(n.password,t,{includeP256:!0})];case 2:return[2,{pub:(r=i.sent()).pub,priv:r.priv,epub:r.epub,epriv:r.epriv}];case 3:throw o=i.sent(),K.handle(j.ENCRYPTION,"NOSTR_KEY_DERIVATION_ERROR","Error deriving keys from Nostr credential",o),o;case 4:return[2]}})})},e.prototype.createGunUser=function(e,t){return nI(this,void 0,void 0,function(){var n,r,o,i=this;return rI(this,function(s){switch(s.label){case 0:if(!(n=this.credentials.get(e.toLowerCase())))throw new Error("Credential for address ".concat(e," not found"));s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.createDerivedKeyPair(e)];case 2:return r=s.sent(),[2,new Promise(function(o){var s=function(t){if(t.err)K.handle(j.AUTHENTICATION,"NOSTR_GUN_AUTH_FAILED","NostrSigner - GunDB auth failed",t.err),o({success:!1,error:t.err});else{var r=t.pub;n.gunUserPub=r,i.credentials.set(e.toLowerCase(),n),o({success:!0,userPub:r})}};t.user().create(r,function(e){e.err,t.user().auth(r,s)})})];case 3:return o=s.sent(),K.handle(j.DATABASE,"NOSTR_CREATE_USER_ERROR","Error creating Gun user",o),[2,{success:!1,error:o.message}];case 4:return[2]}})})},e.prototype.signWithDerivedKeys=function(e,t,n){return nI(this,void 0,void 0,function(){var r,o,i,s,a;return rI(this,function(c){switch(c.label){case 0:return c.trys.push([0,4,,5]),[4,this.createAuthenticator(t)(e)];case 1:return c.sent(),[4,this.createDerivedKeyPair(t,n)];case 2:return r=c.sent(),o=JSON.stringify(e),[4,this.generateDeterministicSignature("".concat(r.priv,"_").concat(o))];case 3:return i=c.sent(),s={m:o,s:i},[2,"SEA"+JSON.stringify(s)];case 4:throw a=c.sent(),K.handle(j.SIGNATURE,"NOSTR_DERIVED_SIGN_ERROR","Error signing with derived keys",a),a;case 5:return[2]}})})},e.prototype.getGunUserPub=function(e){var t=this.credentials.get(e.toLowerCase());return null==t?void 0:t.gunUserPub},e.prototype.getPassword=function(e){var t=this.credentials.get(e.toLowerCase());return null==t?void 0:t.password},e.prototype.verifyConsistency=function(e,t){return nI(this,void 0,void 0,function(){var n;return rI(this,function(r){switch(r.label){case 0:return this.credentials.get(e.toLowerCase())?[4,this.createDerivedKeyPair(e)]:[2,{consistent:!1}];case 1:return n=r.sent(),[2,{consistent:!t||n.pub===t,actualUserPub:n.pub,expectedUserPub:t}]}})})},e.prototype.getCredential=function(e){return this.credentials.get(e.toLowerCase())},e.prototype.listCredentials=function(){return Array.from(this.credentials.values())},e.prototype.removeCredential=function(e){return this.credentials.delete(e.toLowerCase())},e}(),iI=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),sI=function(){return sI=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},sI.apply(this,arguments)},aI=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},cI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},uI=function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.name="nostr",t.version="1.0.0",t.description="Provides Bitcoin wallet connection and authentication for ShogunCore",t.bitcoinConnector=null,t.signer=null,t}return iI(t,e),t.prototype.initialize=function(t){e.prototype.initialize.call(this,t),this.bitcoinConnector=new YS,this.signer=new oI(this.bitcoinConnector)},t.prototype.destroy=function(){this.bitcoinConnector&&this.bitcoinConnector.cleanup(),this.bitcoinConnector=null,this.signer=null,e.prototype.destroy.call(this)},t.prototype.assertBitcoinConnector=function(){if(this.assertInitialized(),!this.bitcoinConnector)throw new Error("Bitcoin wallet module not initialized");return this.bitcoinConnector},t.prototype.assertSigner=function(){if(this.assertInitialized(),!this.signer)throw new Error("Nostr signer not initialized");return this.signer},t.prototype.isAvailable=function(){return this.assertBitcoinConnector().isAvailable()},t.prototype.isNostrExtensionAvailable=function(){return this.assertBitcoinConnector().isNostrExtensionAvailable()},t.prototype.connectNostrWallet=function(){return aI(this,void 0,void 0,function(){var e,t;return cI(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.isNostrExtensionAvailable()?[4,this.connectBitcoinWallet("nostr")]:[2,{success:!1,error:"Nostr extension not available. Please install a Nostr extension like nos2x, Alby, or Coracle."}];case 1:return(e=n.sent()).success,[2,e];case 2:return t=n.sent(),console.error("[nostrConnectorPlugin] Error connecting to Nostr wallet:",t),[2,{success:!1,error:t.message||"Unknown error connecting to Nostr wallet"}];case 3:return[2]}})})},t.prototype.connectBitcoinWallet=function(){return aI(this,arguments,void 0,function(e){return void 0===e&&(e="nostr"),cI(this,function(t){return"alby"===e&&(e="nostr"),[2,this.assertBitcoinConnector().connectWallet(e)]})})},t.prototype.generateCredentials=function(e,t,n){return aI(this,void 0,void 0,function(){return cI(this,function(r){return[2,this.assertBitcoinConnector().generateCredentials(e,t,n)]})})},t.prototype.cleanup=function(){this.assertBitcoinConnector().cleanup()},t.prototype.verifySignature=function(e,t,n){return aI(this,void 0,void 0,function(){return cI(this,function(r){return[2,this.assertBitcoinConnector().verifySignature(e,t,n)]})})},t.prototype.generatePassword=function(e){return aI(this,void 0,void 0,function(){return cI(this,function(t){return[2,this.assertBitcoinConnector().generatePassword(e)]})})},t.prototype.createSigningCredential=function(e){return aI(this,void 0,void 0,function(){var t,n;return cI(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),"function"!=typeof(t=this.assertBitcoinConnector()).createSigningCredential?[3,2]:[4,t.createSigningCredential(e)];case 1:case 3:return[2,r.sent()];case 2:return[4,this.assertSigner().createSigningCredential(e)];case 4:throw n=r.sent(),console.error("Error creating Nostr signing credential: ".concat(n.message)),n;case 5:return[2]}})})},t.prototype.createAuthenticator=function(e){try{var t=this.assertBitcoinConnector();return"function"==typeof t.createAuthenticator?t.createAuthenticator(e):this.assertSigner().createAuthenticator(e)}catch(e){throw console.error("Error creating Nostr authenticator: ".concat(e.message)),e}},t.prototype.createDerivedKeyPair=function(e,t){return aI(this,void 0,void 0,function(){var n,r;return cI(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(n=this.assertBitcoinConnector()).createDerivedKeyPair?[3,2]:[4,n.createDerivedKeyPair(e,t)];case 1:case 3:return[2,o.sent()];case 2:return[4,this.assertSigner().createDerivedKeyPair(e,t)];case 4:throw r=o.sent(),console.error("Error creating derived key pair: ".concat(r.message)),r;case 5:return[2]}})})},t.prototype.signWithDerivedKeys=function(e,t,n){return aI(this,void 0,void 0,function(){var r,o;return cI(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),"function"!=typeof(r=this.assertBitcoinConnector()).signWithDerivedKeys?[3,2]:[4,r.signWithDerivedKeys(e,t,n)];case 1:case 3:return[2,i.sent()];case 2:return[4,this.assertSigner().signWithDerivedKeys(e,t,n)];case 4:throw o=i.sent(),console.error("Error signing with derived keys: ".concat(o.message)),o;case 5:return[2]}})})},t.prototype.getSigningCredential=function(e){var t=this.assertBitcoinConnector();return"function"==typeof t.getSigningCredential?t.getSigningCredential(e):this.assertSigner().getCredential(e)},t.prototype.listSigningCredentials=function(){var e=this.assertBitcoinConnector();return"function"==typeof e.listSigningCredentials?e.listSigningCredentials():this.assertSigner().listCredentials()},t.prototype.removeSigningCredential=function(e){var t=this.assertBitcoinConnector();return"function"==typeof t.removeSigningCredential?t.removeSigningCredential(e):this.assertSigner().removeCredential(e)},t.prototype.createGunUserFromSigningCredential=function(e){return aI(this,void 0,void 0,function(){var t,n,r;return cI(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(t=this.assertBitcoinConnector()).createGunUserFromSigningCredential?[3,2]:[4,t.createGunUserFromSigningCredential(e)];case 1:case 3:return[2,o.sent()];case 2:return n=this.assertInitialized(),[4,this.assertSigner().createGunUser(e,n.gun)];case 4:throw r=o.sent(),console.error("Error creating Gun user from Nostr signing credential: ".concat(r.message)),r;case 5:return[2]}})})},t.prototype.getGunUserPubFromSigningCredential=function(e){var t=this.assertBitcoinConnector();return"function"==typeof t.getGunUserPubFromSigningCredential?t.getGunUserPubFromSigningCredential(e):this.assertSigner().getGunUserPub(e)},t.prototype.getPassword=function(e){var t=this.assertBitcoinConnector();return"function"==typeof t.getPassword?t.getPassword(e):this.assertSigner().getPassword(e)},t.prototype.verifyConsistency=function(e,t){return aI(this,void 0,void 0,function(){var n,r;return cI(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),"function"!=typeof(n=this.assertBitcoinConnector()).verifyConsistency?[3,2]:[4,n.verifyConsistency(e,t)];case 1:case 3:return[2,o.sent()];case 2:return[4,this.assertSigner().verifyConsistency(e,t)];case 4:return r=o.sent(),console.error("Error verifying Nostr consistency: ".concat(r.message)),[2,{consistent:!1}];case 5:return[2]}})})},t.prototype.setupConsistentOneshotSigning=function(e){return aI(this,void 0,void 0,function(){var t,n,r,o,i;return cI(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),"function"!=typeof(t=this.assertBitcoinConnector()).setupConsistentOneshotSigning?[3,2]:[4,t.setupConsistentOneshotSigning(e)];case 1:return[2,s.sent()];case 2:return[4,this.createSigningCredential(e)];case 3:return n=s.sent(),r=this.createAuthenticator(e),[4,this.createGunUserFromSigningCredential(e)];case 4:return o=s.sent(),[2,{credential:n,authenticator:r,gunUser:o,username:n.username,password:n.password}];case 5:throw i=s.sent(),console.error("Error setting up consistent Nostr oneshot signing: ".concat(i.message)),i;case 6:return[2]}})})},t.prototype.login=function(e){return aI(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c,u,l;return cI(this,function(f){switch(f.label){case 0:if(f.trys.push([0,6,,7]),t=this.assertInitialized(),!e)throw z(j.VALIDATION,"ADDRESS_REQUIRED","Bitcoin address required for login");if(!this.isAvailable())throw z(j.ENVIRONMENT,"BITCOIN_WALLET_UNAVAILABLE","No Bitcoin wallet available in the browser");return n=ZS,[4,this.assertBitcoinConnector().requestSignature(e,n)];case 1:return r=f.sent(),[4,this.generateCredentials(e,r,n)];case 2:if(!((null==(o=f.sent())?void 0:o.username)&&(null==o?void 0:o.key)&&o.message&&o.signature))throw z(j.AUTHENTICATION,"CREDENTIAL_GENERATION_FAILED","Bitcoin wallet credentials not generated correctly or signature missing");return[4,this.verifySignature(o.message,o.signature,e)];case 3:if(!f.sent())throw console.error("Signature verification failed for address: ".concat(e)),z(j.SECURITY,"SIGNATURE_VERIFICATION_FAILED","Bitcoin wallet signature verification failed");return[4,XS(e,0,n)];case 4:return i=f.sent(),t.setAuthMethod("nostr"),[4,t.login(o.username,"",i)];case 5:if(!(s=f.sent()).success)throw z(j.AUTHENTICATION,"BITCOIN_LOGIN_FAILED",s.error||"Failed to log in with Bitcoin credentials");return t.emit("auth:login",{userPub:s.userPub||"",username:o.username,method:"nostr"}),[2,s];case 6:return a=f.sent(),c=(null==a?void 0:a.type)||j.AUTHENTICATION,u=(null==a?void 0:a.code)||"BITCOIN_LOGIN_ERROR",l=(null==a?void 0:a.message)||"Unknown error during Bitcoin wallet login",K.handle(c,u,l,a),[2,{success:!1,error:l}];case 7:return[2]}})})},t.prototype.signUp=function(e){return aI(this,void 0,void 0,function(){var t,n,r,o,i,s,a,c,u,l,f;return cI(this,function(h){switch(h.label){case 0:if(h.trys.push([0,11,,12]),t=this.assertInitialized(),!e)throw z(j.VALIDATION,"ADDRESS_REQUIRED","Bitcoin address required for signup");if(!this.isAvailable())throw z(j.ENVIRONMENT,"BITCOIN_WALLET_UNAVAILABLE","No Bitcoin wallet available in the browser");return n=ZS,[4,this.assertBitcoinConnector().requestSignature(e,n)];case 1:return r=h.sent(),[4,this.generateCredentials(e,r,n)];case 2:if(!((null==(o=h.sent())?void 0:o.username)&&(null==o?void 0:o.key)&&o.message&&o.signature))throw z(j.AUTHENTICATION,"CREDENTIAL_GENERATION_FAILED","Bitcoin wallet credentials not generated correctly or signature missing");return[4,this.verifySignature(o.message,o.signature,e)];case 3:if(!h.sent())throw console.error("Signature verification failed for address: ".concat(e)),z(j.SECURITY,"SIGNATURE_VERIFICATION_FAILED","Bitcoin wallet signature verification failed");return[4,XS(e,0,n)];case 4:return i=h.sent(),t.setAuthMethod("nostr"),[4,t.signUp(o.username,void 0,i)];case 5:return(s=h.sent()).success?[4,t.login(o.username,"",i)]:[3,7];case 6:return(a=h.sent()).success?(console.log("Bitcoin wallet registration and login completed for user: ".concat(o.username)),t.emit("auth:signup",{userPub:a.userPub||"",username:o.username,method:"nostr"}),[2,sI({},a)]):[2,sI(sI({},s),{error:"User created but login failed"})];case 7:return s.error&&s.error.toLowerCase().includes("exist")?[4,t.login(o.username,"",i)]:[3,9];case 8:return a=h.sent(),[2,sI({},a)];case 9:return[2,s];case 10:return[3,12];case 11:return c=h.sent(),u=(null==c?void 0:c.type)||j.AUTHENTICATION,l=(null==c?void 0:c.code)||"BITCOIN_SIGNUP_ERROR",f=(null==c?void 0:c.message)||"Unknown error during Bitcoin wallet signup",K.handle(u,l,f,c),[2,{success:!1,error:f}];case 12:return[2]}})})},t.prototype.loginWithBitcoinWallet=function(e){return aI(this,void 0,void 0,function(){return cI(this,function(t){return[2,this.login(e)]})})},t.prototype.signUpWithBitcoinWallet=function(e){return aI(this,void 0,void 0,function(){return cI(this,function(t){return[2,this.signUp(e)]})})},t}(q);!function(e){e.Authentication="authentication",e.Wallet="wallet",e.Privacy="privacy",e.Identity="identity",e.Utility="utility",e.Messages="messages",e.Other="other"}(eI||(eI={})),function(e){e.WebAuthn="webauthn",e.Web3="web3",e.Nostr="nostr",e.Challenge="challenge"}(tI||(tI={}));var lI,fI=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),hI=function(){return hI=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},hI.apply(this,arguments)},dI=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},pI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},gI=(function(e){function t(){var t=e.apply(this,function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(arguments),!1))||this;return t.name="challenge",t.version="1.0.0",t.description="Challenge-response authentication using Gun SEA signatures",t._category=eI.Authentication,t.config={serverUrl:"",challengeEndpoint:"/login-challenge",verifyEndpoint:"/login-verify",timeout:1e4},t}fI(t,e),t.prototype.configure=function(e){this.config=hI(hI({},this.config),e)},t.prototype.getSEA=function(){var e,t,n=this.core;if(n){var r=null===(e=n.db)||void 0===e?void 0:e.sea;if(r)return r}return(null===(t=globalThis.Gun)||void 0===t?void 0:t.SEA)?globalThis.Gun.SEA:globalThis.SEA?globalThis.SEA:null},t.prototype.requestChallenge=function(e,t,n){return dI(this,void 0,void 0,function(){var r,o,i,s,a,c,u,l;return pI(this,function(f){switch(f.label){case 0:r=this.config.challengeEndpoint||"/login-challenge",o="".concat(e).concat(r),i=new AbortController,s=setTimeout(function(){return i.abort()},this.config.timeout||1e4),f.label=1;case 1:return f.trys.push([1,6,,7]),[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:t,password:n}),signal:i.signal})];case 2:return a=f.sent(),clearTimeout(s),a.ok?[3,4]:[4,a.json().catch(function(){return{error:"Request failed"}})];case 3:throw c=f.sent(),new Error(c.error||"Challenge request failed: ".concat(a.status));case 4:return[4,a.json()];case 5:if(!(u=f.sent()).success)throw new Error(u.error||"Challenge request rejected by server");return[2,{challengeId:u.challengeId,challenge:u.challenge,pub:u.pub,expiresAt:u.expiresAt}];case 6:if(l=f.sent(),clearTimeout(s),"AbortError"===l.name)throw new Error("Challenge request timed out");throw l;case 7:return[2]}})})},t.prototype.signChallenge=function(e,t){return dI(this,void 0,void 0,function(){var n,r;return pI(this,function(o){switch(o.label){case 0:if(!(n=this.getSEA())||!n.sign)throw new Error("SEA not available for challenge signing");return[4,n.sign(e,t)];case 1:if(!(r=o.sent()))throw new Error("Failed to sign challenge");return[2,r]}})})},t.prototype.verifyChallenge=function(e,t,n){return dI(this,void 0,void 0,function(){var r;return pI(this,function(o){switch(o.label){case 0:if(!(r=this.getSEA())||!r.verify)throw new Error("SEA not available for challenge verification");return[4,r.verify(e,t)];case 1:return[2,o.sent()===n]}})})},t.prototype.login=function(e,t,n,r){return dI(this,void 0,void 0,function(){var o,i,s,a,c,u,l,f,h;return pI(this,function(d){switch(d.label){case 0:return d.trys.push([0,5,,6]),[4,this.requestChallenge(e,t,n)];case 1:return o=d.sent(),[4,this.signChallenge(o.challenge,r)];case 2:return i=d.sent(),s=this.config.verifyEndpoint||"/login-verify",a="".concat(e).concat(s),c=new AbortController,u=setTimeout(function(){return c.abort()},this.config.timeout||1e4),[4,fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({challengeId:o.challengeId,signedChallenge:i}),signal:c.signal})];case 3:return l=d.sent(),clearTimeout(u),[4,l.json()];case 4:return(f=d.sent()).success?(h={success:!0,userPub:f.pub,username:f.username||t,sessionToken:f.token,authMethod:"challenge"},this.core&&this.core.emit("auth:login",{userPub:f.pub,method:"password",username:f.username||t}),[2,h]):[2,{success:!1,error:f.error||"Challenge verification failed"}];case 5:return[2,{success:!1,error:d.sent().message||"Challenge-response login failed"}];case 6:return[2]}})})}}(q),r(229),r(30),r(410),r(719),r(617),r(924),r(402),r(140),r(809)),yI=function(){return yI=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},yI.apply(this,arguments)},mI=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},wI=function(){function e(e){this.plugins=new Map,this.core=e}return e.prototype.register=function(e){try{if(!e.name)return void("undefined"!=typeof console&&console.error&&console.error("Plugin registration failed: Plugin must have a name"));if(this.plugins.has(e.name))return void("undefined"!=typeof console&&console.warn&&console.warn('Plugin "'.concat(e.name,'" is already registered. Skipping.')));e.initialize(this.core),this.plugins.set(e.name,e),this.core.emit("plugin:registered",{name:e.name,version:e.version||"unknown",category:e._category||"unknown"})}catch(t){"undefined"!=typeof console&&console.error&&console.error('Error registering plugin "'.concat(e.name,'":'),t)}},e.prototype.unregister=function(e){try{var t=this.plugins.get(e);if(!t)return"undefined"!=typeof console&&console.warn&&console.warn('Plugin "'.concat(e,'" not found for unregistration')),!1;if("function"==typeof t.destroy)try{t.destroy()}catch(t){"undefined"!=typeof console&&console.error&&console.error('Error destroying plugin "'.concat(e,'":'),t)}return this.plugins.delete(e),this.core.emit("plugin:unregistered",{name:t.name}),!0}catch(t){return"undefined"!=typeof console&&console.error&&console.error('Error unregistering plugin "'.concat(e,'":'),t),!1}},e.prototype.getPlugin=function(e){if(e&&"string"==typeof e){var t=this.plugins.get(e);if(t)return t;"undefined"!=typeof console&&console.warn&&console.warn('Plugin "'.concat(e,'" not found'))}else"undefined"!=typeof console&&console.warn&&console.warn("Invalid plugin name provided to getPlugin")},e.prototype.getPluginsInfo=function(){var e=[];return this.plugins.forEach(function(t){e.push({name:t.name,version:t.version||"unknown",category:t._category,description:t.description})}),e},e.prototype.getPluginCount=function(){return this.plugins.size},e.prototype.getPluginsInitializationStatus=function(){var e={};return this.plugins.forEach(function(t,n){try{"function"==typeof t.assertInitialized?(t.assertInitialized(),e[n]={initialized:!0}):e[n]={initialized:!!t.core,error:t.core?void 0:"No core reference found"}}catch(t){e[n]={initialized:!1,error:t instanceof Error?t.message:String(t)}}}),e},e.prototype.validatePluginSystem=function(){var e=this.getPluginsInitializationStatus(),t=Object.keys(e).length,n=Object.values(e).filter(function(e){return e.initialized}).length,r=Object.entries(e).filter(function(e){var t=mI(e,2);return t[0],!t[1].initialized}).map(function(e){var t=mI(e,2),n=t[0];return t[1],n}),o=[];return 0===t&&o.push("No plugins registered"),r.length>0&&o.push("Failed plugins: ".concat(r.join(", "))),{totalPlugins:t,initializedPlugins:n,failedPlugins:r,warnings:o}},e.prototype.reinitializeFailedPlugins=function(){var e=this,t=this.getPluginsInitializationStatus(),n=Object.entries(t).filter(function(e){var t=mI(e,2);return t[0],!t[1].initialized}).map(function(e){var t=mI(e,2),n=t[0];return t[1],n}),r=[],o=[];return n.forEach(function(t){try{var n=e.plugins.get(t);if(!n)return void o.push({name:t,error:"Plugin not found"});n.initialize(e.core),r.push(t)}catch(e){var i=e instanceof Error?e.message:String(e);o.push({name:t,error:i}),"undefined"!=typeof console&&console.error&&console.error("[PluginManager] Failed to reinitialize plugin ".concat(t,":"),e)}}),{success:r,failed:o}},e.prototype.checkPluginCompatibility=function(){var e=[],t=[],n=[];return this.plugins.forEach(function(r){var o={name:r.name,version:r.version||"unknown"};if("function"==typeof r.getCompatibilityInfo)try{var i=r.getCompatibilityInfo();i&&i.compatible?e.push(o):t.push(yI(yI({},o),{reason:(null==i?void 0:i.reason)||"Unknown compatibility issue"}))}catch(e){n.push(o)}else n.push(o)}),{compatible:e,incompatible:t,unknown:n}},e.prototype.getPluginSystemDebugInfo=function(){var e=this.getPluginsInfo(),t=this.getPluginsInitializationStatus(),n=e.map(function(e){var n,r;return yI(yI({},e),{initialized:(null===(n=t[e.name])||void 0===n?void 0:n.initialized)||!1,error:null===(r=t[e.name])||void 0===r?void 0:r.error})});return{shogunCoreVersion:"^1.6.6",totalPlugins:this.getPluginCount(),plugins:n,initializationStatus:t,validation:this.validatePluginSystem(),compatibility:this.checkPluginCompatibility()}},e.prototype.hasPlugin=function(e){return this.plugins.has(e)},e.prototype.getPluginsByCategory=function(e){var t=[];return this.plugins.forEach(function(n){n._category===e&&t.push(n)}),t},e}(),bI=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},vI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},EI=function(){function e(e){this.core=e}return e.prototype.isLoggedIn=function(){return this.core.db.isLoggedIn()},e.prototype.logout=function(){try{if(!this.isLoggedIn())return;this.core.db.logout(),this.core.emit("auth:logout")}catch(e){K.handle(j.AUTHENTICATION,"LOGOUT_FAILED",e instanceof Error?e.message:"Error during logout",e)}},e.prototype.login=function(e,t,n){return bI(this,void 0,void 0,function(){var r,o,i,s,a,c,u,l;return vI(this,function(f){switch(f.label){case 0:return f.trys.push([0,2,,3]),this.currentAuthMethod||(this.currentAuthMethod="password"),[4,this.core.db.login(e,t,n)];case 1:return(r=f.sent()).success?((o=null===(a=null===(s=this.core.user)||void 0===s?void 0:s._)||void 0===a?void 0:a.sea)&&(r.sea=o),this.core.emit("auth:login",{userPub:null!==(c=r.userPub)&&void 0!==c?c:"",method:"pair"===this.currentAuthMethod?"password":this.currentAuthMethod||"password"})):r.error=r.error||"Wrong user or password",[2,r];case 2:return i=f.sent(),K.handle(j.AUTHENTICATION,"LOGIN_FAILED",null!==(u=i.message)&&void 0!==u?u:"Unknown error during login",i),[2,{success:!1,error:null!==(l=i.message)&&void 0!==l?l:"Unknown error during login"}];case 3:return[2]}})})},e.prototype.loginWithPair=function(e,t){return bI(this,void 0,void 0,function(){var n,r,o,i,s,a,c,u;return vI(this,function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),t&&t.pub&&t.priv&&t.epub&&t.epriv?[4,this.core.db.loginWithPair(e,t)]:[2,{success:!1,error:"Invalid pair structure - missing required keys"}];case 1:return(n=l.sent()).success?((r=null===(s=null===(i=this.core.user)||void 0===i?void 0:i._)||void 0===s?void 0:s.sea)&&(n.sea=r),this.currentAuthMethod="pair",this.core.emit("auth:login",{userPub:null!==(a=n.userPub)&&void 0!==a?a:"",method:"pair",username:e})):n.error=n.error||"Authentication failed with provided pair",[2,n];case 2:return o=l.sent(),K.handle(j.AUTHENTICATION,"PAIR_LOGIN_FAILED",null!==(c=o.message)&&void 0!==c?c:"Unknown error during pair login",o),[2,{success:!1,error:null!==(u=o.message)&&void 0!==u?u:"Unknown error during pair login"}];case 3:return[2]}})})},e.prototype.loginWithSeed=function(e,t){return bI(this,void 0,void 0,function(){var n,r,o;return vI(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),ta(t)?[4,(0,gI.generatePairFromMnemonic)(t,e)]:[2,{success:!1,error:"Invalid seed phrase"}];case 1:return n=i.sent(),[4,this.loginWithPair(e,n)];case 2:return(r=i.sent()).success&&this.core,[2,r];case 3:return[2,{success:!1,error:(o=i.sent())instanceof Error?o.message:String(o)}];case 4:return[2]}})})},e.prototype.signUp=function(e,t,n){return bI(this,void 0,void 0,function(){var r,o;return vI(this,function(i){switch(i.label){case 0:if(i.trys.push([0,2,,3]),!this.core.db)throw new Error("Database not initialized");if(!(n||t&&""!==t.trim()))throw new Error("Password is required for password-based signup");return[4,this.core.db.signUp(e,t||"",n)];case 1:return(r=i.sent()).success?(this.currentAuthMethod=n?"web3":"password",this.core.emit("auth:signup",{userPub:r.userPub,username:e,method:this.currentAuthMethod}),this.core.emit("debug",{action:"signup_success",userPub:r.userPub,method:this.currentAuthMethod})):this.core.emit("debug",{action:"signup_failed",error:r.error,username:e}),[2,r];case 2:return o=i.sent(),K.handle(j.AUTHENTICATION,"SIGNUP_FAILED","Error during registration for user ".concat(e,": ").concat(o instanceof Error?o.message:String(o)),o),this.core.emit("debug",{action:"signup_error",error:o instanceof Error?o.message:String(o),username:e}),[2,{success:!1,error:"Registration failed: ".concat(o instanceof Error?o.message:String(o))}];case 3:return[2]}})})},e.prototype.setAuthMethod=function(e){this.currentAuthMethod=e},e.prototype.getAuthMethod=function(){return this.currentAuthMethod},e.prototype.getAuthenticationMethod=function(e){var t=this;switch(e){case"webauthn":return this.core.getPlugin("webauthn");case"web3":return this.core.getPlugin("web3");case"nostr":return this.core.getPlugin("nostr");default:return{name:"password",version:"1.0.0",initialize:function(){},login:function(e,n){return bI(t,void 0,void 0,function(){return vI(this,function(t){switch(t.label){case 0:return[4,this.login(e,n||"")];case 1:return[2,t.sent()]}})})},signUp:function(e,n){return bI(t,void 0,void 0,function(){var t,r,o;return vI(this,function(i){switch(i.label){case 0:if(r=(t=n||{}).password,(o=t.confirm)&&r!==o)throw new Error("Password and confirm password do not match");return[4,this.signUp(e,r||"")];case 1:return[2,i.sent()]}})})}}}},e}(),AI=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),xI=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return AI(t,e),t.prototype.emit=function(t,n){return e.prototype.emit.call(this,t,n)},t.prototype.on=function(t,n){e.prototype.on.call(this,t,n)},t.prototype.off=function(t,n){e.prototype.off.call(this,t,n)},t}(W),kI=function(){function e(){this.eventEmitter=new xI}return e.prototype.emit=function(e,t){return this.eventEmitter.emit(e,t)},e.prototype.on=function(e,t){return this.eventEmitter.on(e,t),this},e.prototype.once=function(e,t){return this.eventEmitter.once(e,t),this},e.prototype.off=function(e,t){return this.eventEmitter.off(e,t),this},e.prototype.removeAllListeners=function(e){return this.eventEmitter.removeAllListeners(e),this},e.prototype.getEventEmitter=function(){return this.eventEmitter},e}(),SI=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},II=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},CI=function(){function e(e){if(void 0===e&&(e=!1),this.store=new Map,this.silent=e,this.isTestMode=!1,this.useLocalStorage=!1,this.isTestMode)this.useLocalStorage=!1;else if("undefined"!=typeof localStorage)try{var t="_shogun_test";localStorage.setItem(t,t),localStorage.removeItem(t),this.useLocalStorage=!0,this.silent||console.log("ShogunStorage: localStorage enabled");var n=localStorage.getItem("shogun_keypair");n&&this.store.set("keypair",JSON.parse(n))}catch(e){this.useLocalStorage=!1,this.silent||console.log("ShogunStorage: localStorage error:",e.message)}}return e.prototype.getPair=function(){return SI(this,void 0,void 0,function(){return II(this,function(e){return[2,this.getPairSync()]})})},e.prototype.getPairSync=function(){return this.store.get("keypair")||null},e.prototype.setPair=function(e){return SI(this,void 0,void 0,function(){return II(this,function(t){if(this.store.set("keypair",e),this.useLocalStorage)try{localStorage.setItem("shogun_keypair",JSON.stringify(e))}catch(e){this.isTestMode||console.error("Error saving data to localStorage:",e)}return[2]})})},e.prototype.clearAll=function(){if(this.store.clear(),this.useLocalStorage)try{localStorage.removeItem("shogun_keypair")}catch(e){this.isTestMode||console.error("Error removing data from localStorage:",e)}},e.prototype.getItem=function(e){var t=this.store.get(e);return void 0===t?null:t},e.prototype.setItem=function(e,t){if(this.store.set(e,t),this.useLocalStorage)try{localStorage.setItem(e,"string"==typeof t?t:JSON.stringify(t))}catch(t){this.isTestMode||console.error("Error saving ".concat(e," to localStorage:"),t)}},e.prototype.removeItem=function(e){if(this.store.delete(e),this.useLocalStorage)try{localStorage.removeItem(e)}catch(t){this.isTestMode||console.error("Error removing ".concat(e," from localStorage:"),t)}},e}(),OI=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),TI=function(e){function t(t){var n=e.call(this,t)||this;return n.name="GunError",n}return OI(t,e),t}(Error),NI=function(e){function t(t){var n=e.call(this,t)||this;return n.name="AuthError",n}return OI(t,e),t}(TI),PI=(OI(function(e){void 0===e&&(e="Credenziali non valide");var t=lI.call(this,e)||this;return t.name="InvalidCredentials",t},lI=NI),function(e){OI(function(t){void 0===t&&(t="Utente già esistente");var n=e.call(this,t)||this;return n.name="UserExists",n},e)}(NI),function(e){OI(function(t){void 0===t&&(t="Timeout durante l'operazione");var n=e.call(this,t)||this;return n.name="TimeoutError",n},e)}(TI),function(e){OI(function(t){void 0===t&&(t="Autenticazione multipla in corso");var n=e.call(this,t)||this;return n.name="MultipleAuthError",n},e)}(NI),function(e){OI(function(){return null!==e&&e.apply(this,arguments)||this},e)}(TI),function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})}),BI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},RI=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},UI=8,DI=1024,LI=64,FI=function(){function e(e,t,n){var r;if(this.user=null,this.onAuthCallbacks=[],this._isDestroyed=!1,this.prefix="",this.ev={},this.eventEmitter=new W,this.core=t,!e)throw new Error("Gun instance is required but was not provided");if("function"!=typeof e.user)throw new Error("Gun instance is invalid: gun.user is not a function");this.gun=e,this.user=this.gun.user().recall({sessionStorage:!0}),this.subscribeToAuthEvents(),this.crypto=gI,this.sea=n||null,this.sea||(this.gun.SEA?this.sea=this.gun.SEA:(null===(r=globalThis.Gun)||void 0===r?void 0:r.SEA)?this.sea=globalThis.Gun.SEA:globalThis.SEA&&(this.sea=globalThis.SEA)),this.usernamesNode=this.gun.get("usernames"),console.log("[DB] DataBase initialization completed")}return e.prototype.initialize=function(){},e.prototype.subscribeToAuthEvents=function(){var e=this;this.gun.on("auth",function(t){var n;t.err?console.error("[DB] Auth event error:",t.err):e.notifyAuthListeners((null===(n=t.sea)||void 0===n?void 0:n.pub)||"")})},e.prototype.notifyAuthListeners=function(e){var t=this.gun.user();this.onAuthCallbacks.forEach(function(e){return e(t)})},e.prototype.onAuth=function(e){var t=this;this.onAuthCallbacks.push(e);var n=this.gun.user();return n&&n.is&&e(n),function(){var n=t.onAuthCallbacks.indexOf(e);-1!==n&&t.onAuthCallbacks.splice(n,1)}},e.prototype.isLoggedIn=function(){try{var e=this.gun.user();return!!(e&&e.is&&e.is.pub)}catch(e){return!1}},e.prototype.restoreSession=function(){return PI(this,void 0,void 0,function(){var e,t,n,r,o,i;return BI(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),"undefined"==typeof sessionStorage?[2,{success:!1,error:"sessionStorage not available"}]:(e=sessionStorage.getItem("gunSessionData"))?!(t=JSON.parse(e)).version||t.version<2?(sessionStorage.removeItem("gunSessionData"),[2,{success:!1,error:"Legacy session expired"}]):t.encrypted&&t.integrity&&t.salt&&t.pub?[4,this.sea.work(t.encrypted,null,null,{name:"SHA-256"})]:[2,{success:!1,error:"Invalid encrypted session format"}]:[2,{success:!1,error:"No saved session"}];case 1:return s.sent()!==t.integrity?(sessionStorage.removeItem("gunSessionData"),[2,{success:!1,error:"Session integrity check failed"}]):[4,this.deriveSessionKey(t.username,t.salt,t.pub)];case 2:return n=s.sent(),[4,this.sea.decrypt(t.encrypted,n)];case 3:return(r=s.sent())?r.pub!==t.pub?[2,{success:!1,error:"Session public key mismatch"}]:r.expiresAt&&Date.now()>r.expiresAt?(sessionStorage.removeItem("gunSessionData"),[2,{success:!1,error:"Session expired"}]):(o=this.gun.user()).is&&o.is.pub===t.pub?(this.user=o,[2,{success:!0,userPub:t.pub}]):[2,{success:!1,error:"Session verification failed"}]:(sessionStorage.removeItem("gunSessionData"),[2,{success:!1,error:"Session decryption failed"}]);case 4:return i=s.sent(),console.error("[DB] Restore session error:",i),[2,{success:!1,error:String(i)}];case 5:return[2]}})})},e.prototype.logout=function(){try{var e=!!this.user,t=this.gun.user();t&&t.is&&t.leave(),this.user=null,"undefined"!=typeof sessionStorage&&sessionStorage.removeItem("gunSessionData"),e&&this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:logout",void 0)}catch(e){console.error("[DB] Error during logout:",e)}},e.prototype.validatePasswordStrength=function(e){return e.length<UI?{valid:!1,error:"Password must be at least ".concat(UI," characters long")}:e.length>DI?{valid:!1,error:"Password must be ".concat(DI," characters or fewer")}:/[A-Z]/.test(e)?/[a-z]/.test(e)?/[0-9]/.test(e)?/[!@#$%^&*()_+\-=[\]{}|;':",./<>?]/.test(e)?{valid:!0}:{valid:!1,error:"Password must contain at least one special character"}:{valid:!1,error:"Password must contain at least one number"}:{valid:!1,error:"Password must contain at least one lowercase letter"}:{valid:!1,error:"Password must contain at least one uppercase letter"}},e.prototype.validateSignupCredentials=function(e,t,n){return!e||e.length<1?{valid:!1,error:"Username must be more than 0 characters long"}:e.length>LI?{valid:!1,error:"Username must be ".concat(LI," characters or fewer")}:/^[a-zA-Z0-9._-]+$/.test(e)?n?n.pub&&n.priv&&n.epub&&n.epriv?{valid:!0}:{valid:!1,error:"Invalid pair provided"}:this.validatePasswordStrength(t):{valid:!1,error:"Username can only contain letters, numbers, dots, underscores, and hyphens"}},e.prototype.ensureAliasAvailable=function(e){return PI(this,arguments,void 0,function(e,t){return void 0===t&&(t=5e3),BI(this,function(n){switch(n.label){case 0:return[4,this.isAliasAvailable(e,t)];case 1:if(!n.sent())throw new Error('Alias "'.concat(e,'" is already registered in Gun'));return[2]}})})},e.prototype.isAliasAvailable=function(e){return PI(this,arguments,void 0,function(e,t){var n,r=this;return void 0===t&&(t=5e3),BI(this,function(o){if("string"!=typeof e||!e.trim())throw new Error("Alias must be a non-empty string");return n=e.trim().toLowerCase(),[2,new Promise(function(e,o){var i=!1,s=setTimeout(function(){i||(i=!0,o(new Error("Timeout while checking alias availability")))},t);r.usernamesNode.get(n).once(function(t){i||(i=!0,clearTimeout(s),e(!t))})})]})})},e.prototype.isAliasTaken=function(e){return PI(this,void 0,void 0,function(){var t=this;return BI(this,function(n){return[2,new Promise(function(n,r){t.gun.get("~@".concat(e)).once(function(e){n(!!e)})})]})})},e.prototype.registerAlias=function(e,t){return PI(this,arguments,void 0,function(e,t,n){var r,o,i=this;return void 0===n&&(n=5e3),BI(this,function(s){switch(s.label){case 0:if(!e||!e.trim())throw new Error("Alias must be provided for registration");if(!t)throw new Error("userPub must be provided for alias registration");return r=e.trim().toLowerCase(),[4,this.isAliasAvailable(r,n).catch(function(e){throw console.error("[DB] Alias availability check failed:",e),e})];case 1:return o=s.sent(),[4,this.isAliasTaken(r)];case 2:if(s.sent())throw new Error('Alias "'.concat(r,'" is already taken'));if(!o)throw new Error('Alias "'.concat(r,'" is no longer available for registration'));return[4,new Promise(function(e,o){var s=!1,a=setTimeout(function(){s||(s=!0,o(new Error("Timeout while registering alias")))},n);i.usernamesNode.get(r).put(t,function(t){s||(s=!0,clearTimeout(a),t&&t.err?o(new Error(String(t.err))):e())})}).catch(function(e){throw console.error("[DB] Failed to register alias:",e),e})];case 3:return s.sent(),[2]}})})},e.prototype.resetAuthState=function(){try{var e=this.gun.user();if(e&&e._){var t=e._;t.ing=!1,t.auth=null,t.act=null,t.auth&&(t.auth=null)}try{e.leave()}catch(e){}this.user=null}catch(e){}},e.prototype.buildLoginResult=function(e,t){var n,r,o=null===(r=null===(n=this.gun.user())||void 0===n?void 0:n._)||void 0===r?void 0:r.sea;return{success:!0,userPub:t,username:e,sea:o?{pub:o.pub,priv:o.priv,epub:o.epub,epriv:o.epriv}:void 0}},e.prototype.getDeviceSecret=function(){try{if("undefined"==typeof localStorage)return"";var e="shogun_device_secret",t=localStorage.getItem(e);if(!t){t=this.crypto.randomUUID();try{localStorage.setItem(e,t)}catch(e){console.warn("[DB] Failed to save device secret to localStorage",e)}}return t}catch(e){return""}},e.prototype.deriveSessionKey=function(e,t,n){return PI(this,void 0,void 0,function(){var r,o;return BI(this,function(i){switch(i.label){case 0:if(!this.sea)throw new Error("SEA not available");return r=this.getDeviceSecret(),o="".concat(e,":").concat(t,":").concat(n,":").concat(r),[4,this.sea.work(o,null,null,{name:"SHA-256"})];case 1:return[2,i.sent()]}})})},e.prototype.saveCredentials=function(e){return PI(this,void 0,void 0,function(){var t,n,r,o,i,s,a;return BI(this,function(c){switch(c.label){case 0:return c.trys.push([0,6,,7]),"undefined"==typeof sessionStorage?[3,5]:this.sea?[4,this.sea.work(this.crypto.randomUUID(),null,null,{name:"SHA-256"})]:[2];case 1:return t=c.sent(),[4,this.deriveSessionKey(e.alias,t,e.userPub)];case 2:return n=c.sent(),r={username:e.alias,pair:e.pair,pub:e.userPub,expiresAt:Date.now()+6048e5},[4,this.sea.encrypt(r,n)];case 3:return o=c.sent(),[4,this.sea.work(o,null,null,{name:"SHA-256"})];case 4:i=c.sent(),s={version:2,username:e.alias,pub:e.userPub,salt:t,encrypted:o,integrity:i},sessionStorage.setItem("gunSessionData",JSON.stringify(s)),c.label=5;case 5:return[3,7];case 6:return a=c.sent(),console.error("[DB] Error saving credentials:",a),[3,7];case 7:return[2]}})})},e.prototype.signUp=function(e,t,n){return PI(this,void 0,void 0,function(){var r,o,i,s,a,c=this;return BI(this,function(u){switch(u.label){case 0:if(!(r=this.validateSignupCredentials(e,t,n)).valid)return[2,{success:!1,error:r.error}];if(this.resetAuthState(),o=e.trim().toLowerCase(),i=this.gun.user(),!n)return[3,4];u.label=1;case 1:return u.trys.push([1,3,,4]),[4,new Promise(function(e){var t=!1;i.auth(n,function(r){return PI(c,void 0,void 0,function(){var s,a,c,u,l,f;return BI(this,function(h){switch(h.label){case 0:return t?[2]:(t=!0,r.err?(e({success:!1,error:r.err}),[2]):(s=null===(u=null==i?void 0:i.is)||void 0===u?void 0:u.pub)?(this.user=i,a=null===(l=null==i?void 0:i.is)||void 0===l?void 0:l.alias,c=null===(f=null==i?void 0:i._)||void 0===f?void 0:f.sea,[4,this.saveCredentials({alias:a||o,pair:null!=n?n:c,userPub:s})]):(this.resetAuthState(),e({success:!1,error:"No userPub available"}),[2]));case 1:return h.sent(),this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:signup",{userPub:s,username:o,method:"pair"}),e(this.buildLoginResult(a||o,s)),[2]}})})})})];case 2:return(s=u.sent())&&s.success?[2,s]:[3,4];case 3:return u.sent(),[3,4];case 4:return u.trys.push([4,6,,7]),[4,this.ensureAliasAvailable(o)];case 5:return u.sent(),[3,7];case 6:return[2,{success:!1,error:(a=u.sent())instanceof Error?a.message:String(a)}];case 7:return[4,new Promise(function(e){var r=!1;i.create(o,t,function(s){if(!r){if(s.err||void 0!==s.ok&&0!==s.ok)return r=!0,c.resetAuthState(),void e({success:!1,error:s.err||"Signup failed"});if(!s.pub)return r=!0,c.resetAuthState(),void e({success:!1,error:"No userPub available from signup"});i.auth(o,t,function(t){return PI(c,void 0,void 0,function(){var s,a,c,u,l,f,h,d,p;return BI(this,function(g){switch(g.label){case 0:if(r)return[2];if(r=!0,t.err)return this.resetAuthState(),e({success:!1,error:t.err||"Authentication after signup failed"}),[2];if(!(s=null===(f=null==i?void 0:i.is)||void 0===f?void 0:f.pub))return this.resetAuthState(),e({success:!1,error:"User not authenticated after signup"}),[2];this.user=i,a=null===(h=null==i?void 0:i.is)||void 0===h?void 0:h.alias,c=null===(d=null==i?void 0:i._)||void 0===d?void 0:d.sea,g.label=1;case 1:return g.trys.push([1,3,,4]),[4,this.saveCredentials({alias:a||o,pair:null!=n?n:c,userPub:s})];case 2:case 3:return g.sent(),[3,4];case 4:return g.trys.push([4,6,,7]),[4,this.registerAlias(a||o,s)];case 5:return g.sent(),[3,7];case 6:return u=g.sent(),console.error("[DB] Alias registration failed:",u),[3,7];case 7:return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:signup",{userPub:s,username:o,method:n?"pair":"password"}),l=null===(p=null==i?void 0:i._)||void 0===p?void 0:p.sea,e({success:!0,userPub:s,username:o,isNewUser:!0,sea:l?{pub:l.pub,priv:l.priv,epub:l.epub,epriv:l.epriv}:void 0}),[2]}})})})}})})];case 8:return[2,u.sent()]}})})},e.prototype.login=function(e,t,n){return PI(this,void 0,void 0,function(){var r,o,i=this;return BI(this,function(s){return this.resetAuthState(),r=e.trim().toLowerCase(),o=this.gun.user(),[2,new Promise(function(e){n?o.auth(n,function(t){return PI(i,void 0,void 0,function(){var i,s,a,c,u,l;return BI(this,function(f){switch(f.label){case 0:if(t.err)return this.resetAuthState(),e({success:!1,error:t.err}),[2];if(!(i=null===(c=null==o?void 0:o.is)||void 0===c?void 0:c.pub))return this.resetAuthState(),e({success:!1,error:"No userPub available"}),[2];this.user=o,s=null===(u=null==o?void 0:o.is)||void 0===u?void 0:u.alias,a=null===(l=null==o?void 0:o._)||void 0===l?void 0:l.sea,f.label=1;case 1:return f.trys.push([1,3,,4]),[4,this.saveCredentials({alias:s||r,pair:null!=n?n:a,userPub:i})];case 2:case 3:return f.sent(),[3,4];case 4:return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:login",{userPub:i,username:s||r,method:"pair"}),e(this.buildLoginResult(s||r,i)),[2]}})})}):o.auth(r,t,function(t){return PI(i,void 0,void 0,function(){var i,s,a,c,u,l;return BI(this,function(f){switch(f.label){case 0:if(t.err)return this.resetAuthState(),e({success:!1,error:t.err}),[2];if(!(i=null===(c=null==o?void 0:o.is)||void 0===c?void 0:c.pub))return this.resetAuthState(),e({success:!1,error:"No userPub available"}),[2];this.user=o,s=null===(u=null==o?void 0:o.is)||void 0===u?void 0:u.alias,a=null===(l=null==o?void 0:o._)||void 0===l?void 0:l.sea,f.label=1;case 1:return f.trys.push([1,3,,4]),[4,this.saveCredentials({alias:s||r,pair:null!=n?n:a,userPub:i})];case 2:case 3:return f.sent(),[3,4];case 4:return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:login",{userPub:i,username:s||r,method:"password"}),e(this.buildLoginResult(s||r,i)),[2]}})})})})]})})},e.prototype.getCurrentUser=function(){try{var e=this.gun.user();return e&&e.is&&e.is.pub?{pub:e.is.pub,user:e}:null}catch(e){return null}},e.prototype.getUserPub=function(){var e;try{var t=this.gun.user();return(null===(e=null==t?void 0:t.is)||void 0===e?void 0:e.pub)||null}catch(e){return null}},e.prototype.loginWithPair=function(e,t){return PI(this,void 0,void 0,function(){var n,r,o=this;return BI(this,function(i){return t&&t.pub&&t.priv&&t.epub&&t.epriv?e.length>LI?[2,{success:!1,error:"Username must be ".concat(LI," characters or fewer")}]:(this.resetAuthState(),n=e.trim().toLowerCase(),r=this.gun.user(),console.log("[DB] Login with pair for username:",n),[2,new Promise(function(e){r.auth(t,function(i){return PI(o,void 0,void 0,function(){var o,s,a,c,u,l;return BI(this,function(f){switch(f.label){case 0:if(i.err)return this.resetAuthState(),e({success:!1,error:i.err}),[2];if(!(o=null===(c=null==r?void 0:r.is)||void 0===c?void 0:c.pub))return this.resetAuthState(),e({success:!1,error:"No userPub available"}),[2];this.user=r,s=null===(u=null==r?void 0:r.is)||void 0===u?void 0:u.alias,a=null===(l=null==r?void 0:r._)||void 0===l?void 0:l.sea,f.label=1;case 1:return f.trys.push([1,3,,4]),[4,this.saveCredentials({alias:s||n,pair:null!=t?t:a,userPub:o})];case 2:case 3:return f.sent(),[3,4];case 4:return this.core&&"function"==typeof this.core.emit&&this.core.emit("auth:login",{userPub:o,username:s||n,method:"pair"}),e(this.buildLoginResult(s||n,o)),[2]}})})})})]):[2,{success:!1,error:"Invalid pair structure - missing required keys"}]})})},e.prototype.loginWithPairLegacy=function(e,t){return PI(this,void 0,void 0,function(){return BI(this,function(n){return[2,this.login(e,"",t)]})})},e.prototype._timeout=function(e){return PI(this,void 0,void 0,function(){return BI(this,function(t){return[2,new Promise(function(t){return setTimeout(t,e)})]})})},e.prototype.Off=function(e){void 0===e&&(e="default"),this.ev[e]&&this.ev[e].handler?this.ev[e].handler.off():this.ev[e]={handler:null}},e.prototype.Listen=function(e,t,n){void 0===n&&(n=this.prefix);var r=(e="".concat(n).concat(e)).split("/"),o=this.gun;r.forEach(function(e){o=o.get(e)}),o.map().once(function(e){t(e)})},e.prototype.On=function(e,t,n,r,o){var i=this;void 0===n&&(n="default"),void 0===r&&(r=!0),void 0===o&&(o=this.prefix);var s=(e="".concat(o).concat(e)).split("/"),a=this.gun;s.forEach(function(e){a=a.get(e)}),a.on(function(e,r,o,s){i.ev[n]={handler:s},e&&t(JSON.parse(JSON.stringify(e)))},{change:r})},e.prototype.addContentAdressing=function(e,t){var n=this;return"object"==typeof t&&(t=JSON.stringify(t)),new Promise(function(r,o){n.sea.work(t,null,void 0,{name:"SHA-256"}).then(function(i){i?n.gun.get("".concat(e)).get(i).put(t,function(e){r(e)}):o(new Error("Hash generation failed"))}).catch(o)})},e.prototype.userGet=function(e,t,n){void 0===t&&(t=1),void 0===n&&(n=this.prefix);var r=this.getUserPub();return r?(e="~".concat(r,"/").concat(e),this.Get(e,t,n)):Promise.resolve(void 0)},e.prototype.userLoad=function(e,t,n,r){void 0===t&&(t=!1),void 0===n&&(n=1),void 0===r&&(r=this.prefix);var o=this.getUserPub();return o?(e="~".concat(o,"/").concat(e),this.Load(e,t,n,r)):Promise.resolve({data:{},err:[{path:e,err:"User not logged in"}]})},e.prototype.Get=function(e,t,n){var r=this;void 0===t&&(t=1),void 0===n&&(n=this.prefix);var o=e,i=(e="".concat(n).concat(e)).split("/"),s=this.gun;return i.forEach(function(e){s=s.get(e)}),new Promise(function(i,a){setTimeout(function(){a({err:"timeout",ket:"TIMEOUT, Possibly Data : ".concat(e," is corrupt"),data:{},"#":e})},5e3),s.once(function(s){return PI(r,void 0,void 0,function(){var r,c;return BI(this,function(u){switch(u.label){case 0:return s?(s=JSON.parse(JSON.stringify(s)),i(s),[3,8]):[3,1];case 1:return t?[4,this._timeout(1e3)]:[3,7];case 2:u.sent(),u.label=3;case 3:return u.trys.push([3,5,,6]),[4,this.Get(o,t-1,n)];case 4:return r=u.sent(),i(r),[3,6];case 5:return c=u.sent(),a(c),[3,6];case 6:return[3,8];case 7:a({err:"notfound",ket:"Data Not Found, Data : ".concat(e," is undefined"),data:{},"#":e}),u.label=8;case 8:return[2]}})})})})},e.prototype.userPut=function(e,t,n,r){var o=this;return void 0===n&&(n=!1),void 0===r&&(r=this.prefix),new Promise(function(i,s){var a=o.getUserPub();a?(e="~".concat(a,"/").concat(e),o.Put(e,t,n,r).then(i).catch(s)):s({err:new Error("User Belum Login"),ok:void 0})})},e.prototype._randomAlphaNumeric=function(e){var t=new Uint8Array(e),n=null===globalThis||void 0===globalThis?void 0:globalThis.crypto;if(!(null==n?void 0:n.getRandomValues))throw new TI("Cryptographically secure randomness is not available.");try{n.getRandomValues(t)}catch(e){throw new TI("Failed to generate secure random values: ".concat(e instanceof Error?e.message:String(e)))}for(var r="",o=0;o<e;o++)r+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(t[o]%62);return r},e.prototype.Set=function(e,t,n,r,o){var i=this;return void 0===n&&(n=!1),void 0===r&&(r=this.prefix),void 0===o&&(o=void 0),new Promise(function(s,a){var c=i._randomAlphaNumeric(30);t.id=c,i.Put("".concat(e,"/").concat(c),t,n,r,o).then(function(e){s(e)}).catch(function(e){a(e)})})},e.prototype.Put=function(e,t,n,r,o){var i,s;void 0===n&&(n=!1),void 0===r&&(r=this.prefix),void 0===o&&(o=void 0);var a=(e="".concat(r).concat(e)).split("/"),c=this.gun;a.forEach(function(e){c=c.get(e)}),void 0===t&&(t={t:"_"});var u=[],l={data:[],error:[]};if("object"==typeof t&&null!==t)try{for(var f=RI(Object.keys(t)),h=f.next();!h.done;h=f.next()){var d=h.value;if(Object.hasOwnProperty.call(t,d)){var p=t[d];"object"==typeof p&&(delete t[d],u.push(this.Put("".concat(e,"/").concat(d),p,n).then(function(e){return l.data=l.data.concat(e.data),l.error=l.error.concat(e.error),e.data[0]})))}}}catch(e){i={error:e}}finally{try{h&&!h.done&&(s=f.return)&&s.call(f)}finally{if(i)throw i.error}}return new Promise(function(n,r){Promise.allSettled(u).then(function(){t&&0===Object.keys(t).length?n(l):(setTimeout(function(){l.error.push({err:Error("TIMEOUT, Failed to put Data"),ok:e}),n(l)},2e3),c.put(t,function(t){void 0===t.err?l.data.push(t):l.error.push({err:Error(JSON.stringify(t)),ok:e}),n(l)},o))}).catch(function(t){l.error.push({err:Error(JSON.stringify(t)),ok:e}),n(l)})})},e.prototype.purge=function(e){var t=this;return new Promise(function(n,r){t.Get(e).then(function(o){var i,s,a=JSON.parse(JSON.stringify(o));if("object"==typeof a&&null!==a)try{for(var c=RI(Object.keys(a)),u=c.next();!u.done;u=c.next()){var l=u.value;"_"!=l&&">"!=l&&"#"!=l&&":"!=l&&(a[l]=null)}}catch(e){i={error:e}}finally{try{u&&!u.done&&(s=c.return)&&s.call(c)}finally{if(i)throw i.error}}t.Put(e,a).then(function(){n("OK")}).catch(function(e){console.log(e),r(JSON.stringify(e))})}).catch(r)})},e.prototype.userDel=function(e,t){var n=this;return void 0===t&&(t=!0),new Promise(function(r,o){var i=n.getUserPub();if(!i)return o(new Error("User not logged in"));e="~".concat(i,"/").concat(e),n.Del(e,t).then(function(e){r(e)}).catch(function(e){o(e)})})},e.prototype.Del=function(e,t,n){var r=this;return void 0===t&&(t=!0),void 0===n&&(n=""),new Promise(function(o,i){try{var s,a=e.split("/"),c=r.gun;s=t?null:a[0].indexOf("~")>=0?r.gun.user().get("newNode").set({t:"_"}):r.gun.get("newNode").set({t:"_"}),a.forEach(function(e){c=c.get(e)}),n?c.put(s,function(e){void 0===e.err?o({data:[{ok:"ok",err:void 0}],error:[]}):i({data:[{ok:"",err:e.err}],error:[]})},{opt:{cert:n}}):c.put(s,function(e){void 0===e.err?o({data:[{ok:"ok",err:void 0}],error:[]}):i({data:[{ok:"",err:e.err}],error:[]})})}catch(e){i(e)}})},e.prototype.Load=function(e,t,n,r){var o=this;return void 0===t&&(t=!1),void 0===n&&(n=1),void 0===r&&(r=this.prefix),new Promise(function(i,s){var a=[],c={data:{},err:[]};o.Get(e,n,r).then(function(n){var r,s;if("object"==typeof n&&null!==n){var u,l=function(r){"_"!=r&&"#"!=r&&">"!=r&&("object"==typeof(u="object"==typeof n?n[r]:n)?a.push(o.Load("".concat(e,"/").concat(r),t).then(function(e){c.data[r]=e}).catch(function(e){c.err.push(e)})):c.data[r]=u)};try{for(var f=RI(Object.keys(n)),h=f.next();!h.done;h=f.next())l(h.value)}catch(e){r={error:e}}finally{try{h&&!h.done&&(s=f.return)&&s.call(f)}finally{if(r)throw r.error}}}Promise.allSettled(a).then(function(){i(c)}).catch(function(e){c.err.push(e),i(c)})}).catch(function(e){c.err.push(e),i(c)})})},e.prototype.generatePublicCert=function(){var e=this;return new Promise(function(t,n){var r,o,i=e.getUserPub(),s=null===(o=null===(r=e.gun.user())||void 0===r?void 0:r._)||void 0===o?void 0:o.sea;i&&s?e.sea.certify("*",[{"*":"chat-with","+":"*"}],s,null,{}).then(function(t){return e.userPut("chat-cert",t)}).then(function(e){return t(e)}).catch(n):n("User belum Login")})},e.prototype.destroy=function(){if(!this._isDestroyed){if(console.log("[DB] Destroying DataBase instance..."),this._isDestroyed=!0,this.onAuthCallbacks.length=0,this.eventEmitter.removeAllListeners(),this.user){try{this.user.leave()}catch(e){}this.user=null}console.log("[DB] DataBase instance destroyed")}},e.prototype.aggressiveAuthCleanup=function(){console.log("🧹 Performing aggressive auth cleanup..."),this.resetAuthState(),this.logout(),console.log("✓ Aggressive auth cleanup completed")},e.prototype.on=function(e,t){this.eventEmitter.on(e,t)},e.prototype.off=function(e,t){this.eventEmitter.off(e,t)},e.prototype.once=function(e,t){this.eventEmitter.once(e,t)},e.prototype.emit=function(e,t){return this.eventEmitter.emit(e,t)},e}(),_I=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},MI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},GI=function(){function e(e){this.core=e}return e.prototype.initialize=function(e){return _I(this,void 0,void 0,function(){var t=this;return MI(this,function(n){return"undefined"==typeof console&&(r.g.console={log:function(){},warn:function(){},error:function(){},info:function(){},debug:function(){}}),this.core.storage=new CI(e.silent),K.addListener(function(e){t.core.emit("error",{action:e.code,message:e.message,type:e.type})}),this.initializeGun(e),this.initializeGunUser(),this.setupGunEventForwarding(),this.setupWalletDerivation(),this.registerBuiltinPlugins(e),this.initializeDb(),[2]})})},e.prototype.initializeGun=function(e){try{if(!e.gunInstance)throw new Error("gunInstance is required but was not provided");if("object"!=typeof e.gunInstance)throw new Error("Gun instance must be an object, received: ".concat(typeof e.gunInstance));if("function"!=typeof e.gunInstance.user)throw new Error("Gun instance is invalid: gun.user is not a function. Received gun.user type: ".concat(typeof e.gunInstance.user));if("function"!=typeof e.gunInstance.get)throw new Error("Gun instance is invalid: gun.get is not a function. Received gun.get type: ".concat(typeof e.gunInstance.get));if("function"!=typeof e.gunInstance.on)throw new Error("Gun instance is invalid: gun.on is not a function. Received gun.on type: ".concat(typeof e.gunInstance.on));this.core._gun=e.gunInstance}catch(e){throw"undefined"!=typeof console&&console.error&&console.error("Error validating Gun instance:",e),new Error("Failed to validate Gun instance: ".concat(e))}try{var t=this.resolveSEA(this.core._gun);return this.core.db=new FI(this.core._gun,this.core,t),!0}catch(e){throw"undefined"!=typeof console&&console.error&&console.error("Error initializing DataBase:",e),new Error("Failed to initialize DataBase: ".concat(e))}},e.prototype.resolveSEA=function(e){var t=e.SEA||null;if(t)return t;var n="Gun",o=globalThis,i="undefined"!=typeof window?window:{},s=void 0!==r.g?r.g:{};return i[n]&&i[n].SEA?t=i[n].SEA:o[n]&&o[n].SEA?t=o[n].SEA:s[n]&&s[n].SEA?t=s[n].SEA:o.SEA?t=o.SEA:i.SEA&&(t=i.SEA),t},e.prototype.initializeGunUser=function(){var e=this;try{var t=this.core.gun.user();"function"==typeof t.recall?t.recall.length>0?this.core._user=t.recall({sessionStorage:!0}):(t.recall(),this.core._user=t.is?t:null):this.core._user=t}catch(e){throw"undefined"!=typeof console&&console.error&&console.error("Error initializing user:",e),new Error("Failed to initialize user: ".concat(e))}if("function"==typeof this.core.gun.on)try{this.core.gun.on("auth",function(t){var n,r=e.core.gun.user();"function"==typeof r.recall?r.recall.length>0?e.core._user=r.recall({sessionStorage:!0}):(r.recall(),e.core._user=r.is?r:null):e.core._user=r,e.core.emit("auth:login",{userPub:t.pub||(null===(n=t.is)||void 0===n?void 0:n.pub),method:"password"})})}catch(e){"undefined"!=typeof console&&console.warn&&console.warn("[CoreInitializer] Failed to register auth event listener:",e)}},e.prototype.setupGunEventForwarding=function(){var e=this;["gun:put","gun:get","gun:set","gun:remove"].forEach(function(t){e.core.db.on(t,function(n){e.core.emit(t,n)})}),["gun:peer:add","gun:peer:remove","gun:peer:connect","gun:peer:disconnect"].forEach(function(t){e.core.db.on(t,function(n){e.core.emit(t,n)})})},e.prototype.setupWalletDerivation=function(){var e=this;if("function"==typeof this.core.gun.on)try{this.core.gun.on("auth",function(t){return _I(e,void 0,void 0,function(){var e,n,r,o,i,s,a,c,u;return MI(this,function(l){switch(l.label){case 0:return t.is?(e=(null===(i=null===(o=t._)||void 0===o?void 0:o.sea)||void 0===i?void 0:i.epriv)||(null===(s=t.is)||void 0===s?void 0:s.epriv),n=(null===(c=null===(a=t._)||void 0===a?void 0:a.sea)||void 0===c?void 0:c.epub)||(null===(u=t.is)||void 0===u?void 0:u.epub),e&&n?(r=this.core,[4,di(e,n,{includeSecp256k1Bitcoin:!0,includeSecp256k1Ethereum:!0})]):[3,2]):[2];case 1:r.wallets=l.sent(),l.label=2;case 2:return[2]}})})})}catch(e){"undefined"!=typeof console&&console.warn&&console.warn("[CoreInitializer] Failed to register wallet derivation listener:",e)}},e.prototype.registerBuiltinPlugins=function(e){try{if(e.webauthn){"undefined"!=typeof console&&console.warn&&console.warn("WebAuthn plugin will be registered with provided configuration");var t=new ba;"function"==typeof t.configure&&t.configure(e.webauthn),this.core.pluginManager.register(t)}if(e.web3){"undefined"!=typeof console&&console.warn&&console.warn("Web3 plugin will be registered with provided configuration");var n=new Lm;"function"==typeof n.configure&&n.configure(e.web3),this.core.pluginManager.register(n)}if(e.nostr){"undefined"!=typeof console&&console.warn&&console.warn("Nostr plugin will be registered with provided configuration");var r=new uI;"function"==typeof r.configure&&r.configure(e.nostr),this.core.pluginManager.register(r)}}catch(e){"undefined"!=typeof console&&console.error&&console.error("Error registering builtin plugins:",e)}},e.prototype.initializeDb=function(){try{return this.core.db.initialize(),this.core.emit("debug",{action:"core_initialized",timestamp:Date.now()}),!0}catch(e){return"undefined"!=typeof console&&console.error&&console.error("Error during Shogun Core initialization:",e),!1}},e}(),jI=function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},HI=function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},zI=function(){function e(e){this._user=null,this.config=e,this.eventManager=new kI,this.pluginManager=new wI(this),this.authManager=new EI(this),this.coreInitializer=new GI(this),this.coreInitializer.initialize(e).catch(function(e){"undefined"!=typeof console&&console.warn&&console.warn("Error during async initialization:",e)})}return Object.defineProperty(e.prototype,"gun",{get:function(){return this._gun},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"user",{get:function(){return this._user},enumerable:!1,configurable:!0}),e.prototype.getCurrentUser=function(){return this.db?this.db.getCurrentUser():null},e.prototype.register=function(e){this.pluginManager.register(e)},e.prototype.unregister=function(e){this.pluginManager.unregister(e)},e.prototype.getPlugin=function(e){return this.pluginManager.getPlugin(e)},e.prototype.getPluginsInfo=function(){return this.pluginManager.getPluginsInfo()},e.prototype.getPluginCount=function(){return this.pluginManager.getPluginCount()},e.prototype.getPluginsInitializationStatus=function(){return this.pluginManager.getPluginsInitializationStatus()},e.prototype.validatePluginSystem=function(){return this.pluginManager.validatePluginSystem()},e.prototype.reinitializeFailedPlugins=function(){return this.pluginManager.reinitializeFailedPlugins()},e.prototype.checkPluginCompatibility=function(){return this.pluginManager.checkPluginCompatibility()},e.prototype.getPluginSystemDebugInfo=function(){return this.pluginManager.getPluginSystemDebugInfo()},e.prototype.hasPlugin=function(e){return this.pluginManager.hasPlugin(e)},e.prototype.getPluginsByCategory=function(e){return this.pluginManager.getPluginsByCategory(e)},e.prototype.getAuthenticationMethod=function(e){return this.authManager.getAuthenticationMethod(e)},e.prototype.getRecentErrors=function(e){return void 0===e&&(e=10),K.getRecentErrors(e)},e.prototype.isLoggedIn=function(){return this.authManager.isLoggedIn()},e.prototype.logout=function(){this.authManager.logout()},e.prototype.login=function(e,t,n){return jI(this,void 0,void 0,function(){return HI(this,function(r){return[2,this.authManager.login(e,t,n)]})})},e.prototype.loginWithPair=function(e,t){return jI(this,void 0,void 0,function(){return HI(this,function(n){return[2,this.authManager.loginWithPair(e,t)]})})},e.prototype.loginWithSeed=function(e,t){return jI(this,void 0,void 0,function(){return HI(this,function(n){return[2,this.authManager.loginWithSeed(e,t)]})})},e.prototype.signUp=function(e,t,n){return jI(this,void 0,void 0,function(){return HI(this,function(r){return[2,this.authManager.signUp(e,t,n)]})})},e.prototype.emit=function(e,t){return this.eventManager.emit(e,t)},e.prototype.on=function(e,t){return this.eventManager.on(e,t),this},e.prototype.once=function(e,t){return this.eventManager.once(e,t),this},e.prototype.off=function(e,t){return this.eventManager.off(e,t),this},e.prototype.removeAllListeners=function(e){return this.eventManager.removeAllListeners(e),this},e.prototype.setAuthMethod=function(e){this.authManager.setAuthMethod(e)},e.prototype.getAuthMethod=function(){return this.authManager.getAuthMethod()},e.prototype.saveCredentials=function(e){return jI(this,void 0,void 0,function(){return HI(this,function(t){try{this.storage.setItem("userCredentials",JSON.stringify(e))}catch(e){"undefined"!=typeof console&&console.warn&&console.warn("Failed to save credentials to storage"),"undefined"!=typeof console&&console.error&&console.error("Error saving credentials:",e)}return[2]})})},e.prototype.getIsLoggedIn=function(){return!(!this.user||!this.user.is)},e.API_VERSION="^6.2.1",e}();async function VI(e){const{gunInstance:t,appName:n,timeouts:r,webauthn:o,nostr:i,web3:s,challenge:a,showWebauthn:c,showNostr:u,showMetamask:l,showChallenge:f,darkMode:h,enableGunDebug:d=!0,enableConnectionMonitoring:p=!0,defaultPageSize:g=20,connectionTimeout:y=1e4,debounceInterval:m=100,crypto:w,...b}=e;let v=null,E=null;return E=t,v=new zI({gunInstance:E,webauthn:(null==o?void 0:o.enabled)?{enabled:!0,rpName:n||"Shogun App",rpId:"undefined"!=typeof window?window.location.hostname:"localhost"}:void 0,web3:(null==s?void 0:s.enabled)?{enabled:!0}:void 0,nostr:(null==i?void 0:i.enabled)?{enabled:!0}:void 0,challenge:(null==a?void 0:a.enabled)?{enabled:!0}:void 0,timeouts:r,silent:!1}),console.log("[DEBUG] ShogunConnector: ShogunCore initialized with gunInstance"),{core:v,options:e,setProvider:e=>{var t;if(!v)return!1;try{let n=null;if(e&&e.connection&&e.connection.url?n=e.connection.url:"string"==typeof e&&(n=e),n){const e=(null===(t=null==v?void 0:v.db)||void 0===t?void 0:t.gun)||(null==v?void 0:v.gun);if(e&&"function"==typeof e.opt)try{return e.opt({peers:[n]}),!0}catch(e){return console.error("Error adding peer via gun.opt:",e),!1}}return!1}catch(e){return console.error("Error setting provider:",e),!1}},getCurrentProviderUrl:()=>{var e;const t=(null===(e=null==v?void 0:v.db)||void 0===e?void 0:e.gun)||(null==v?void 0:v.gun);try{const e=t&&t.back?t.back("opt.peers"):void 0,n=e&&"object"==typeof e?Object.keys(e):[];return n.length>0?n[0]:null}catch{return null}},registerPlugin:e=>{if(v&&"function"==typeof v.register)try{return v.register(e),!0}catch(t){return console.error(`Error registering plugin: ${e.name}`,t),!1}return!1},hasPlugin:e=>!!v&&v.hasPlugin(e),gunPlugin:null}}return"undefined"!=typeof window&&(window.Shogun=function(e){return new zI(e)}),o})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ShogunButtonReact=e(require("react")):this.ShogunButtonReact=e(this.React);