mirror of
https://github.com/pezkuwichain/pezkuwi-wallet-utils.git
synced 2026-11-05 16:51:07 +00:00
* Sign the root over WalletConnect Wallet 1.3.0's DApp browser never delivers injected-provider requests, so the page could not get a signature from any installed wallet. WalletConnect is the route installed wallets answer: on the phone the page opens the wallet by its pezkuwiwallet://wc link, elsewhere it shows a code for the wallet to scan, then asks for polkadot_signMessage on <Bytes>payload</Bytes>. Measured over a real session on the 1.3.0 signing code: the signature verifies under the "substrate" context, which is what the thresholds count. The injected provider stays as a second button for wallets where it works. The WalletConnect bundle is built from scripts/root/wc (pinned versions, node build.mjs). * Open the wallet by a fixed link, not the peer's redirect The redirect in a WalletConnect session's peer metadata is supplied by whichever wallet connects, so following it let a connecting peer navigate the signing page anywhere, javascript: included.
96 lines
495 KiB
JavaScript
96 lines
495 KiB
JavaScript
var RootSigningWC=(()=>{var tv=Object.create;var Ui=Object.defineProperty;var rv=Object.getOwnPropertyDescriptor;var nv=Object.getOwnPropertyNames;var sv=Object.getPrototypeOf,iv=Object.prototype.hasOwnProperty;var ov=(t,e,r)=>e in t?Ui(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var av=(t,e,r)=>()=>{if(r)throw r[0];try{return t&&(e=t(t=0)),e}catch(n){throw r=[n],n}};var X=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Ce=(t,e)=>{for(var r in e)Ui(t,r,{get:e[r],enumerable:!0})},ea=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of nv(e))!iv.call(t,s)&&s!==r&&Ui(t,s,{get:()=>e[s],enumerable:!(n=rv(e,s))||n.enumerable});return t},wt=(t,e,r)=>(ea(t,e,"default"),r&&ea(r,e,"default")),Ie=(t,e,r)=>(r=t!=null?tv(sv(t)):{},ea(e||!t||!t.__esModule?Ui(r,"default",{value:t,enumerable:!0}):r,t)),Cs=t=>ea(Ui({},"__esModule",{value:!0}),t);var Z=(t,e,r)=>ov(t,typeof e!="symbol"?e+"":e,r);var i0=X(ta=>{"use strict";ta.byteLength=uv;ta.toByteArray=fv;ta.fromByteArray=pv;var Qt=[],Dt=[],cv=typeof Uint8Array<"u"?Uint8Array:Array,Yu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Hn=0,n0=Yu.length;Hn<n0;++Hn)Qt[Hn]=Yu[Hn],Dt[Yu.charCodeAt(Hn)]=Hn;var Hn,n0;Dt[45]=62;Dt[95]=63;function s0(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function uv(t){var e=s0(t),r=e[0],n=e[1];return(r+n)*3/4-n}function lv(t,e,r){return(e+r)*3/4-r}function fv(t){var e,r=s0(t),n=r[0],s=r[1],i=new cv(lv(t,n,s)),o=0,a=s>0?n-4:n,c;for(c=0;c<a;c+=4)e=Dt[t.charCodeAt(c)]<<18|Dt[t.charCodeAt(c+1)]<<12|Dt[t.charCodeAt(c+2)]<<6|Dt[t.charCodeAt(c+3)],i[o++]=e>>16&255,i[o++]=e>>8&255,i[o++]=e&255;return s===2&&(e=Dt[t.charCodeAt(c)]<<2|Dt[t.charCodeAt(c+1)]>>4,i[o++]=e&255),s===1&&(e=Dt[t.charCodeAt(c)]<<10|Dt[t.charCodeAt(c+1)]<<4|Dt[t.charCodeAt(c+2)]>>2,i[o++]=e>>8&255,i[o++]=e&255),i}function hv(t){return Qt[t>>18&63]+Qt[t>>12&63]+Qt[t>>6&63]+Qt[t&63]}function dv(t,e,r){for(var n,s=[],i=e;i<r;i+=3)n=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(t[i+2]&255),s.push(hv(n));return s.join("")}function pv(t){for(var e,r=t.length,n=r%3,s=[],i=16383,o=0,a=r-n;o<a;o+=i)s.push(dv(t,o,o+i>a?a:o+i));return n===1?(e=t[r-1],s.push(Qt[e>>2]+Qt[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],s.push(Qt[e>>10]+Qt[e>>4&63]+Qt[e<<2&63]+"=")),s.join("")}});var o0=X(Ju=>{Ju.read=function(t,e,r,n,s){var i,o,a=s*8-n-1,c=(1<<a)-1,u=c>>1,f=-7,l=r?s-1:0,h=r?-1:1,d=t[e+l];for(l+=h,i=d&(1<<-f)-1,d>>=-f,f+=a;f>0;i=i*256+t[e+l],l+=h,f-=8);for(o=i&(1<<-f)-1,i>>=-f,f+=n;f>0;o=o*256+t[e+l],l+=h,f-=8);if(i===0)i=1-u;else{if(i===c)return o?NaN:(d?-1:1)*(1/0);o=o+Math.pow(2,n),i=i-u}return(d?-1:1)*o*Math.pow(2,i-n)};Ju.write=function(t,e,r,n,s,i){var o,a,c,u=i*8-s-1,f=(1<<u)-1,l=f>>1,h=s===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:i-1,p=n?1:-1,g=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=f):(o=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+l>=1?e+=h/c:e+=h*Math.pow(2,1-l),e*c>=2&&(o++,c/=2),o+l>=f?(a=0,o=f):o+l>=1?(a=(e*c-1)*Math.pow(2,s),o=o+l):(a=e*Math.pow(2,l-1)*Math.pow(2,s),o=0));s>=8;t[r+d]=a&255,d+=p,a/=256,s-=8);for(o=o<<s|a,u+=s;u>0;t[r+d]=o&255,d+=p,o/=256,u-=8);t[r+d-p]|=g*128}});var _0=X(Ls=>{"use strict";var Xu=i0(),Ps=o0(),a0=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Ls.Buffer=M;Ls.SlowBuffer=bv;Ls.INSPECT_MAX_BYTES=50;var ra=2147483647;Ls.kMaxLength=ra;M.TYPED_ARRAY_SUPPORT=gv();!M.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function gv(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(M.prototype,"parent",{enumerable:!0,get:function(){if(M.isBuffer(this))return this.buffer}});Object.defineProperty(M.prototype,"offset",{enumerable:!0,get:function(){if(M.isBuffer(this))return this.byteOffset}});function Er(t){if(t>ra)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,M.prototype),e}function M(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return tl(t)}return f0(t,e,r)}M.poolSize=8192;function f0(t,e,r){if(typeof t=="string")return yv(t,e);if(ArrayBuffer.isView(t))return wv(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(er(t,ArrayBuffer)||t&&er(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(er(t,SharedArrayBuffer)||t&&er(t.buffer,SharedArrayBuffer)))return Qu(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return M.from(n,e,r);let s=xv(t);if(s)return s;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return M.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}M.from=function(t,e,r){return f0(t,e,r)};Object.setPrototypeOf(M.prototype,Uint8Array.prototype);Object.setPrototypeOf(M,Uint8Array);function h0(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function mv(t,e,r){return h0(t),t<=0?Er(t):e!==void 0?typeof r=="string"?Er(t).fill(e,r):Er(t).fill(e):Er(t)}M.alloc=function(t,e,r){return mv(t,e,r)};function tl(t){return h0(t),Er(t<0?0:rl(t)|0)}M.allocUnsafe=function(t){return tl(t)};M.allocUnsafeSlow=function(t){return tl(t)};function yv(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!M.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=d0(t,e)|0,n=Er(r),s=n.write(t,e);return s!==r&&(n=n.slice(0,s)),n}function Zu(t){let e=t.length<0?0:rl(t.length)|0,r=Er(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function wv(t){if(er(t,Uint8Array)){let e=new Uint8Array(t);return Qu(e.buffer,e.byteOffset,e.byteLength)}return Zu(t)}function Qu(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,M.prototype),n}function xv(t){if(M.isBuffer(t)){let e=rl(t.length)|0,r=Er(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||sl(t.length)?Er(0):Zu(t);if(t.type==="Buffer"&&Array.isArray(t.data))return Zu(t.data)}function rl(t){if(t>=ra)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+ra.toString(16)+" bytes");return t|0}function bv(t){return+t!=t&&(t=0),M.alloc(+t)}M.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==M.prototype};M.compare=function(e,r){if(er(e,Uint8Array)&&(e=M.from(e,e.offset,e.byteLength)),er(r,Uint8Array)&&(r=M.from(r,r.offset,r.byteLength)),!M.isBuffer(e)||!M.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,s=r.length;for(let i=0,o=Math.min(n,s);i<o;++i)if(e[i]!==r[i]){n=e[i],s=r[i];break}return n<s?-1:s<n?1:0};M.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}};M.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return M.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let s=M.allocUnsafe(r),i=0;for(n=0;n<e.length;++n){let o=e[n];if(er(o,Uint8Array))i+o.length>s.length?(M.isBuffer(o)||(o=M.from(o)),o.copy(s,i)):Uint8Array.prototype.set.call(s,o,i);else if(M.isBuffer(o))o.copy(s,i);else throw new TypeError('"list" argument must be an Array of Buffers');i+=o.length}return s};function d0(t,e){if(M.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||er(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let s=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return el(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return v0(t).length;default:if(s)return n?-1:el(t).length;e=(""+e).toLowerCase(),s=!0}}M.byteLength=d0;function Ev(t,e,r){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return Ov(this,e,r);case"utf8":case"utf-8":return g0(this,e,r);case"ascii":return Rv(this,e,r);case"latin1":case"binary":return Dv(this,e,r);case"base64":return Av(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Cv(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}M.prototype._isBuffer=!0;function zn(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}M.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<e;r+=2)zn(this,r,r+1);return this};M.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<e;r+=4)zn(this,r,r+3),zn(this,r+1,r+2);return this};M.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<e;r+=8)zn(this,r,r+7),zn(this,r+1,r+6),zn(this,r+2,r+5),zn(this,r+3,r+4);return this};M.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?g0(this,0,e):Ev.apply(this,arguments)};M.prototype.toLocaleString=M.prototype.toString;M.prototype.equals=function(e){if(!M.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:M.compare(this,e)===0};M.prototype.inspect=function(){let e="",r=Ls.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};a0&&(M.prototype[a0]=M.prototype.inspect);M.prototype.compare=function(e,r,n,s,i){if(er(e,Uint8Array)&&(e=M.from(e,e.offset,e.byteLength)),!M.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),s===void 0&&(s=0),i===void 0&&(i=this.length),r<0||n>e.length||s<0||i>this.length)throw new RangeError("out of range index");if(s>=i&&r>=n)return 0;if(s>=i)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,s>>>=0,i>>>=0,this===e)return 0;let o=i-s,a=n-r,c=Math.min(o,a),u=this.slice(s,i),f=e.slice(r,n);for(let l=0;l<c;++l)if(u[l]!==f[l]){o=u[l],a=f[l];break}return o<a?-1:a<o?1:0};function p0(t,e,r,n,s){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,sl(r)&&(r=s?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(s)return-1;r=t.length-1}else if(r<0)if(s)r=0;else return-1;if(typeof e=="string"&&(e=M.from(e,n)),M.isBuffer(e))return e.length===0?-1:c0(t,e,r,n,s);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?s?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):c0(t,[e],r,n,s);throw new TypeError("val must be string, number or Buffer")}function c0(t,e,r,n,s){let i=1,o=t.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;i=2,o/=2,a/=2,r/=2}function c(f,l){return i===1?f[l]:f.readUInt16BE(l*i)}let u;if(s){let f=-1;for(u=r;u<o;u++)if(c(t,u)===c(e,f===-1?0:u-f)){if(f===-1&&(f=u),u-f+1===a)return f*i}else f!==-1&&(u-=u-f),f=-1}else for(r+a>o&&(r=o-a),u=r;u>=0;u--){let f=!0;for(let l=0;l<a;l++)if(c(t,u+l)!==c(e,l)){f=!1;break}if(f)return u}return-1}M.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};M.prototype.indexOf=function(e,r,n){return p0(this,e,r,n,!0)};M.prototype.lastIndexOf=function(e,r,n){return p0(this,e,r,n,!1)};function vv(t,e,r,n){r=Number(r)||0;let s=t.length-r;n?(n=Number(n),n>s&&(n=s)):n=s;let i=e.length;n>i/2&&(n=i/2);let o;for(o=0;o<n;++o){let a=parseInt(e.substr(o*2,2),16);if(sl(a))return o;t[r+o]=a}return o}function _v(t,e,r,n){return na(el(e,t.length-r),t,r,n)}function Sv(t,e,r,n){return na(Lv(e),t,r,n)}function Iv(t,e,r,n){return na(v0(e),t,r,n)}function Bv(t,e,r,n){return na(kv(e,t.length-r),t,r,n)}M.prototype.write=function(e,r,n,s){if(r===void 0)s="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")s=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,s===void 0&&(s="utf8")):(s=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let i=this.length-r;if((n===void 0||n>i)&&(n=i),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");s||(s="utf8");let o=!1;for(;;)switch(s){case"hex":return vv(this,e,r,n);case"utf8":case"utf-8":return _v(this,e,r,n);case"ascii":case"latin1":case"binary":return Sv(this,e,r,n);case"base64":return Iv(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Bv(this,e,r,n);default:if(o)throw new TypeError("Unknown encoding: "+s);s=(""+s).toLowerCase(),o=!0}};M.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Av(t,e,r){return e===0&&r===t.length?Xu.fromByteArray(t):Xu.fromByteArray(t.slice(e,r))}function g0(t,e,r){r=Math.min(t.length,r);let n=[],s=e;for(;s<r;){let i=t[s],o=null,a=i>239?4:i>223?3:i>191?2:1;if(s+a<=r){let c,u,f,l;switch(a){case 1:i<128&&(o=i);break;case 2:c=t[s+1],(c&192)===128&&(l=(i&31)<<6|c&63,l>127&&(o=l));break;case 3:c=t[s+1],u=t[s+2],(c&192)===128&&(u&192)===128&&(l=(i&15)<<12|(c&63)<<6|u&63,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:c=t[s+1],u=t[s+2],f=t[s+3],(c&192)===128&&(u&192)===128&&(f&192)===128&&(l=(i&15)<<18|(c&63)<<12|(u&63)<<6|f&63,l>65535&&l<1114112&&(o=l))}}o===null?(o=65533,a=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),s+=a}return Tv(n)}var u0=4096;function Tv(t){let e=t.length;if(e<=u0)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=u0));return r}function Rv(t,e,r){let n="";r=Math.min(t.length,r);for(let s=e;s<r;++s)n+=String.fromCharCode(t[s]&127);return n}function Dv(t,e,r){let n="";r=Math.min(t.length,r);for(let s=e;s<r;++s)n+=String.fromCharCode(t[s]);return n}function Ov(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let s="";for(let i=e;i<r;++i)s+=Mv[t[i]];return s}function Cv(t,e,r){let n=t.slice(e,r),s="";for(let i=0;i<n.length-1;i+=2)s+=String.fromCharCode(n[i]+n[i+1]*256);return s}M.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let s=this.subarray(e,r);return Object.setPrototypeOf(s,M.prototype),s};function Ne(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}M.prototype.readUintLE=M.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ne(e,r,this.length);let s=this[e],i=1,o=0;for(;++o<r&&(i*=256);)s+=this[e+o]*i;return s};M.prototype.readUintBE=M.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ne(e,r,this.length);let s=this[e+--r],i=1;for(;r>0&&(i*=256);)s+=this[e+--r]*i;return s};M.prototype.readUint8=M.prototype.readUInt8=function(e,r){return e=e>>>0,r||Ne(e,1,this.length),this[e]};M.prototype.readUint16LE=M.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||Ne(e,2,this.length),this[e]|this[e+1]<<8};M.prototype.readUint16BE=M.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||Ne(e,2,this.length),this[e]<<8|this[e+1]};M.prototype.readUint32LE=M.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||Ne(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};M.prototype.readUint32BE=M.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||Ne(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};M.prototype.readBigUInt64LE=rn(function(e){e=e>>>0,Us(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Li(e,this.length-8);let s=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,i=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(s)+(BigInt(i)<<BigInt(32))});M.prototype.readBigUInt64BE=rn(function(e){e=e>>>0,Us(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Li(e,this.length-8);let s=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],i=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(s)<<BigInt(32))+BigInt(i)});M.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ne(e,r,this.length);let s=this[e],i=1,o=0;for(;++o<r&&(i*=256);)s+=this[e+o]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*r)),s};M.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||Ne(e,r,this.length);let s=r,i=1,o=this[e+--s];for(;s>0&&(i*=256);)o+=this[e+--s]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*r)),o};M.prototype.readInt8=function(e,r){return e=e>>>0,r||Ne(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};M.prototype.readInt16LE=function(e,r){e=e>>>0,r||Ne(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};M.prototype.readInt16BE=function(e,r){e=e>>>0,r||Ne(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};M.prototype.readInt32LE=function(e,r){return e=e>>>0,r||Ne(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};M.prototype.readInt32BE=function(e,r){return e=e>>>0,r||Ne(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};M.prototype.readBigInt64LE=rn(function(e){e=e>>>0,Us(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Li(e,this.length-8);let s=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(s)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});M.prototype.readBigInt64BE=rn(function(e){e=e>>>0,Us(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&Li(e,this.length-8);let s=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(s)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});M.prototype.readFloatLE=function(e,r){return e=e>>>0,r||Ne(e,4,this.length),Ps.read(this,e,!0,23,4)};M.prototype.readFloatBE=function(e,r){return e=e>>>0,r||Ne(e,4,this.length),Ps.read(this,e,!1,23,4)};M.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||Ne(e,8,this.length),Ps.read(this,e,!0,52,8)};M.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||Ne(e,8,this.length),Ps.read(this,e,!1,52,8)};function lt(t,e,r,n,s,i){if(!M.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>s||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}M.prototype.writeUintLE=M.prototype.writeUIntLE=function(e,r,n,s){if(e=+e,r=r>>>0,n=n>>>0,!s){let a=Math.pow(2,8*n)-1;lt(this,e,r,n,a,0)}let i=1,o=0;for(this[r]=e&255;++o<n&&(i*=256);)this[r+o]=e/i&255;return r+n};M.prototype.writeUintBE=M.prototype.writeUIntBE=function(e,r,n,s){if(e=+e,r=r>>>0,n=n>>>0,!s){let a=Math.pow(2,8*n)-1;lt(this,e,r,n,a,0)}let i=n-1,o=1;for(this[r+i]=e&255;--i>=0&&(o*=256);)this[r+i]=e/o&255;return r+n};M.prototype.writeUint8=M.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,1,255,0),this[r]=e&255,r+1};M.prototype.writeUint16LE=M.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};M.prototype.writeUint16BE=M.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};M.prototype.writeUint32LE=M.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};M.prototype.writeUint32BE=M.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function m0(t,e,r,n,s){E0(e,n,s,t,r,7);let i=Number(e&BigInt(4294967295));t[r++]=i,i=i>>8,t[r++]=i,i=i>>8,t[r++]=i,i=i>>8,t[r++]=i;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,r}function y0(t,e,r,n,s){E0(e,n,s,t,r,7);let i=Number(e&BigInt(4294967295));t[r+7]=i,i=i>>8,t[r+6]=i,i=i>>8,t[r+5]=i,i=i>>8,t[r+4]=i;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=o,o=o>>8,t[r+2]=o,o=o>>8,t[r+1]=o,o=o>>8,t[r]=o,r+8}M.prototype.writeBigUInt64LE=rn(function(e,r=0){return m0(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});M.prototype.writeBigUInt64BE=rn(function(e,r=0){return y0(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});M.prototype.writeIntLE=function(e,r,n,s){if(e=+e,r=r>>>0,!s){let c=Math.pow(2,8*n-1);lt(this,e,r,n,c-1,-c)}let i=0,o=1,a=0;for(this[r]=e&255;++i<n&&(o*=256);)e<0&&a===0&&this[r+i-1]!==0&&(a=1),this[r+i]=(e/o>>0)-a&255;return r+n};M.prototype.writeIntBE=function(e,r,n,s){if(e=+e,r=r>>>0,!s){let c=Math.pow(2,8*n-1);lt(this,e,r,n,c-1,-c)}let i=n-1,o=1,a=0;for(this[r+i]=e&255;--i>=0&&(o*=256);)e<0&&a===0&&this[r+i+1]!==0&&(a=1),this[r+i]=(e/o>>0)-a&255;return r+n};M.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};M.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};M.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};M.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};M.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||lt(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};M.prototype.writeBigInt64LE=rn(function(e,r=0){return m0(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});M.prototype.writeBigInt64BE=rn(function(e,r=0){return y0(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function w0(t,e,r,n,s,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function x0(t,e,r,n,s){return e=+e,r=r>>>0,s||w0(t,e,r,4,34028234663852886e22,-34028234663852886e22),Ps.write(t,e,r,n,23,4),r+4}M.prototype.writeFloatLE=function(e,r,n){return x0(this,e,r,!0,n)};M.prototype.writeFloatBE=function(e,r,n){return x0(this,e,r,!1,n)};function b0(t,e,r,n,s){return e=+e,r=r>>>0,s||w0(t,e,r,8,17976931348623157e292,-17976931348623157e292),Ps.write(t,e,r,n,52,8),r+8}M.prototype.writeDoubleLE=function(e,r,n){return b0(this,e,r,!0,n)};M.prototype.writeDoubleBE=function(e,r,n){return b0(this,e,r,!1,n)};M.prototype.copy=function(e,r,n,s){if(!M.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!s&&s!==0&&(s=this.length),r>=e.length&&(r=e.length),r||(r=0),s>0&&s<n&&(s=n),s===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(s<0)throw new RangeError("sourceEnd out of bounds");s>this.length&&(s=this.length),e.length-r<s-n&&(s=e.length-r+n);let i=s-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,s):Uint8Array.prototype.set.call(e,this.subarray(n,s),r),i};M.prototype.fill=function(e,r,n,s){if(typeof e=="string"){if(typeof r=="string"?(s=r,r=0,n=this.length):typeof n=="string"&&(s=n,n=this.length),s!==void 0&&typeof s!="string")throw new TypeError("encoding must be a string");if(typeof s=="string"&&!M.isEncoding(s))throw new TypeError("Unknown encoding: "+s);if(e.length===1){let o=e.charCodeAt(0);(s==="utf8"&&o<128||s==="latin1")&&(e=o)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let i;if(typeof e=="number")for(i=r;i<n;++i)this[i]=e;else{let o=M.isBuffer(e)?e:M.from(e,s),a=o.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<n-r;++i)this[i+r]=o[i%a]}return this};var Ns={};function nl(t,e,r){Ns[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(s){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:s,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}nl("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);nl("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);nl("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,s=r;return Number.isInteger(r)&&Math.abs(r)>2**32?s=l0(String(r)):typeof r=="bigint"&&(s=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(s=l0(s)),s+="n"),n+=` It must be ${e}. Received ${s}`,n},RangeError);function l0(t){let e="",r=t.length,n=t[0]==="-"?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function Nv(t,e,r){Us(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&Li(e,t.length-(r+1))}function E0(t,e,r,n,s,i){if(t>r||t<e){let o=typeof e=="bigint"?"n":"",a;throw i>3?e===0||e===BigInt(0)?a=`>= 0${o} and < 2${o} ** ${(i+1)*8}${o}`:a=`>= -(2${o} ** ${(i+1)*8-1}${o}) and < 2 ** ${(i+1)*8-1}${o}`:a=`>= ${e}${o} and <= ${r}${o}`,new Ns.ERR_OUT_OF_RANGE("value",a,t)}Nv(n,s,i)}function Us(t,e){if(typeof t!="number")throw new Ns.ERR_INVALID_ARG_TYPE(e,"number",t)}function Li(t,e,r){throw Math.floor(t)!==t?(Us(t,r),new Ns.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new Ns.ERR_BUFFER_OUT_OF_BOUNDS:new Ns.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var Pv=/[^+/0-9A-Za-z-_]/g;function Uv(t){if(t=t.split("=")[0],t=t.trim().replace(Pv,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function el(t,e){e=e||1/0;let r,n=t.length,s=null,i=[];for(let o=0;o<n;++o){if(r=t.charCodeAt(o),r>55295&&r<57344){if(!s){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}else if(o+1===n){(e-=3)>-1&&i.push(239,191,189);continue}s=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),s=r;continue}r=(s-55296<<10|r-56320)+65536}else s&&(e-=3)>-1&&i.push(239,191,189);if(s=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function Lv(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function kv(t,e){let r,n,s,i=[];for(let o=0;o<t.length&&!((e-=2)<0);++o)r=t.charCodeAt(o),n=r>>8,s=r%256,i.push(s),i.push(n);return i}function v0(t){return Xu.toByteArray(Uv(t))}function na(t,e,r,n){let s;for(s=0;s<n&&!(s+r>=e.length||s>=t.length);++s)e[s+r]=t[s];return s}function er(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function sl(t){return t!==t}var Mv=(function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let s=0;s<16;++s)e[n+s]=t[r]+t[s]}return e})();function rn(t){return typeof BigInt>"u"?qv:t}function qv(){throw new Error("BigInt not supported")}});var T0=X((fD,A0)=>{var we=A0.exports={},tr,rr;function il(){throw new Error("setTimeout has not been defined")}function ol(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?tr=setTimeout:tr=il}catch{tr=il}try{typeof clearTimeout=="function"?rr=clearTimeout:rr=ol}catch{rr=ol}})();function S0(t){if(tr===setTimeout)return setTimeout(t,0);if((tr===il||!tr)&&setTimeout)return tr=setTimeout,setTimeout(t,0);try{return tr(t,0)}catch{try{return tr.call(null,t,0)}catch{return tr.call(this,t,0)}}}function Fv(t){if(rr===clearTimeout)return clearTimeout(t);if((rr===ol||!rr)&&clearTimeout)return rr=clearTimeout,clearTimeout(t);try{return rr(t)}catch{try{return rr.call(null,t)}catch{return rr.call(this,t)}}}var vr=[],ks=!1,Vn,sa=-1;function Hv(){!ks||!Vn||(ks=!1,Vn.length?vr=Vn.concat(vr):sa=-1,vr.length&&I0())}function I0(){if(!ks){var t=S0(Hv);ks=!0;for(var e=vr.length;e;){for(Vn=vr,vr=[];++sa<e;)Vn&&Vn[sa].run();sa=-1,e=vr.length}Vn=null,ks=!1,Fv(t)}}we.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];vr.push(new B0(t,e)),vr.length===1&&!ks&&S0(I0)};function B0(t,e){this.fun=t,this.array=e}B0.prototype.run=function(){this.fun.apply(null,this.array)};we.title="browser";we.browser=!0;we.env={};we.argv=[];we.version="";we.versions={};function _r(){}we.on=_r;we.addListener=_r;we.once=_r;we.off=_r;we.removeListener=_r;we.removeAllListeners=_r;we.emit=_r;we.prependListener=_r;we.prependOnceListener=_r;we.listeners=function(t){return[]};we.binding=function(t){throw new Error("process.binding is not supported")};we.cwd=function(){return"/"};we.chdir=function(t){throw new Error("process.chdir is not supported")};we.umask=function(){return 0}});var $n=X((hD,al)=>{"use strict";var Ms=typeof Reflect=="object"?Reflect:null,R0=Ms&&typeof Ms.apply=="function"?Ms.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},ia;Ms&&typeof Ms.ownKeys=="function"?ia=Ms.ownKeys:Object.getOwnPropertySymbols?ia=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ia=function(e){return Object.getOwnPropertyNames(e)};function zv(t){console&&console.warn&&console.warn(t)}var O0=Number.isNaN||function(e){return e!==e};function ue(){ue.init.call(this)}al.exports=ue;al.exports.once=Kv;ue.EventEmitter=ue;ue.prototype._events=void 0;ue.prototype._eventsCount=0;ue.prototype._maxListeners=void 0;var D0=10;function oa(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(ue,"defaultMaxListeners",{enumerable:!0,get:function(){return D0},set:function(t){if(typeof t!="number"||t<0||O0(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");D0=t}});ue.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};ue.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||O0(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function C0(t){return t._maxListeners===void 0?ue.defaultMaxListeners:t._maxListeners}ue.prototype.getMaxListeners=function(){return C0(this)};ue.prototype.emit=function(e){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var s=e==="error",i=this._events;if(i!==void 0)s=s&&i.error===void 0;else if(!s)return!1;if(s){var o;if(r.length>0&&(o=r[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=i[e];if(c===void 0)return!1;if(typeof c=="function")R0(c,this,r);else for(var u=c.length,f=k0(c,u),n=0;n<u;++n)R0(f[n],this,r);return!0};function N0(t,e,r,n){var s,i,o;if(oa(r),i=t._events,i===void 0?(i=t._events=Object.create(null),t._eventsCount=0):(i.newListener!==void 0&&(t.emit("newListener",e,r.listener?r.listener:r),i=t._events),o=i[e]),o===void 0)o=i[e]=r,++t._eventsCount;else if(typeof o=="function"?o=i[e]=n?[r,o]:[o,r]:n?o.unshift(r):o.push(r),s=C0(t),s>0&&o.length>s&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=o.length,zv(a)}return t}ue.prototype.addListener=function(e,r){return N0(this,e,r,!1)};ue.prototype.on=ue.prototype.addListener;ue.prototype.prependListener=function(e,r){return N0(this,e,r,!0)};function Vv(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function P0(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},s=Vv.bind(n);return s.listener=r,n.wrapFn=s,s}ue.prototype.once=function(e,r){return oa(r),this.on(e,P0(this,e,r)),this};ue.prototype.prependOnceListener=function(e,r){return oa(r),this.prependListener(e,P0(this,e,r)),this};ue.prototype.removeListener=function(e,r){var n,s,i,o,a;if(oa(r),s=this._events,s===void 0)return this;if(n=s[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete s[e],s.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===r||n[o].listener===r){a=n[o].listener,i=o;break}if(i<0)return this;i===0?n.shift():$v(n,i),n.length===1&&(s[e]=n[0]),s.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};ue.prototype.off=ue.prototype.removeListener;ue.prototype.removeAllListeners=function(e){var r,n,s;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),o;for(s=0;s<i.length;++s)o=i[s],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[e],typeof r=="function")this.removeListener(e,r);else if(r!==void 0)for(s=r.length-1;s>=0;s--)this.removeListener(e,r[s]);return this};function U0(t,e,r){var n=t._events;if(n===void 0)return[];var s=n[e];return s===void 0?[]:typeof s=="function"?r?[s.listener||s]:[s]:r?jv(s):k0(s,s.length)}ue.prototype.listeners=function(e){return U0(this,e,!0)};ue.prototype.rawListeners=function(e){return U0(this,e,!1)};ue.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):L0.call(t,e)};ue.prototype.listenerCount=L0;function L0(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}ue.prototype.eventNames=function(){return this._eventsCount>0?ia(this._events):[]};function k0(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function $v(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function jv(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function Kv(t,e){return new Promise(function(r,n){function s(o){t.removeListener(e,i),n(o)}function i(){typeof t.removeListener=="function"&&t.removeListener("error",s),r([].slice.call(arguments))}M0(t,e,i,{once:!0}),e!=="error"&&Wv(t,s,{once:!0})})}function Wv(t,e,r){typeof t.on=="function"&&M0(t,"error",e,r)}function M0(t,e,r,n){if(typeof t.on=="function")n.once?t.once(e,r):t.on(e,r);else if(typeof t.addEventListener=="function")t.addEventListener(e,function s(i){n.once&&t.removeEventListener(e,s),r(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}});var qs={};Ce(qs,{__assign:()=>ul,__asyncDelegator:()=>o8,__asyncGenerator:()=>i8,__asyncValues:()=>a8,__await:()=>ki,__awaiter:()=>Qv,__classPrivateFieldGet:()=>f8,__classPrivateFieldSet:()=>h8,__createBinding:()=>t8,__decorate:()=>Jv,__exportStar:()=>r8,__extends:()=>Gv,__generator:()=>e8,__importDefault:()=>l8,__importStar:()=>u8,__makeTemplateObject:()=>c8,__metadata:()=>Zv,__param:()=>Xv,__read:()=>q0,__rest:()=>Yv,__spread:()=>n8,__spreadArrays:()=>s8,__values:()=>ll});function Gv(t,e){cl(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}function Yv(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(r[n[s]]=t[n[s]]);return r}function Jv(t,e,r,n){var s=arguments.length,i=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(i=(s<3?o(i):s>3?o(e,r,i):o(e,r))||i);return s>3&&i&&Object.defineProperty(e,r,i),i}function Xv(t,e){return function(r,n){e(r,n,t)}}function Zv(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function Qv(t,e,r,n){function s(i){return i instanceof r?i:new r(function(o){o(i)})}return new(r||(r=Promise))(function(i,o){function a(f){try{u(n.next(f))}catch(l){o(l)}}function c(f){try{u(n.throw(f))}catch(l){o(l)}}function u(f){f.done?i(f.value):s(f.value).then(a,c)}u((n=n.apply(t,e||[])).next())})}function e8(t,e){var r={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,s,i,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(u){return function(f){return c([u,f])}}function c(u){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,s&&(i=u[0]&2?s.return:u[0]?s.throw||((i=s.return)&&i.call(s),0):s.next)&&!(i=i.call(s,u[1])).done)return i;switch(s=0,i&&(u=[u[0]&2,i.value]),u[0]){case 0:case 1:i=u;break;case 4:return r.label++,{value:u[1],done:!1};case 5:r.label++,s=u[1],u=[0];continue;case 7:u=r.ops.pop(),r.trys.pop();continue;default:if(i=r.trys,!(i=i.length>0&&i[i.length-1])&&(u[0]===6||u[0]===2)){r=0;continue}if(u[0]===3&&(!i||u[1]>i[0]&&u[1]<i[3])){r.label=u[1];break}if(u[0]===6&&r.label<i[1]){r.label=i[1],i=u;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(u);break}i[2]&&r.ops.pop(),r.trys.pop();continue}u=e.call(t,r)}catch(f){u=[6,f],s=0}finally{n=i=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function t8(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}function r8(t,e){for(var r in t)r!=="default"&&!e.hasOwnProperty(r)&&(e[r]=t[r])}function ll(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function q0(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),s,i=[],o;try{for(;(e===void 0||e-- >0)&&!(s=n.next()).done;)i.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return i}function n8(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(q0(arguments[e]));return t}function s8(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),s=0,e=0;e<r;e++)for(var i=arguments[e],o=0,a=i.length;o<a;o++,s++)n[s]=i[o];return n}function ki(t){return this instanceof ki?(this.v=t,this):new ki(t)}function i8(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),s,i=[];return s={},o("next"),o("throw"),o("return"),s[Symbol.asyncIterator]=function(){return this},s;function o(h){n[h]&&(s[h]=function(d){return new Promise(function(p,g){i.push([h,d,p,g])>1||a(h,d)})})}function a(h,d){try{c(n[h](d))}catch(p){l(i[0][3],p)}}function c(h){h.value instanceof ki?Promise.resolve(h.value.v).then(u,f):l(i[0][2],h)}function u(h){a("next",h)}function f(h){a("throw",h)}function l(h,d){h(d),i.shift(),i.length&&a(i[0][0],i[0][1])}}function o8(t){var e,r;return e={},n("next"),n("throw",function(s){throw s}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(s,i){e[s]=t[s]?function(o){return(r=!r)?{value:ki(t[s](o)),done:s==="return"}:i?i(o):o}:i}}function a8(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof ll=="function"?ll(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=t[i]&&function(o){return new Promise(function(a,c){o=t[i](o),s(a,c,o.done,o.value)})}}function s(i,o,a,c){Promise.resolve(c).then(function(u){i({value:u,done:a})},o)}}function c8(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function u8(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function l8(t){return t&&t.__esModule?t:{default:t}}function f8(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function h8(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}var cl,ul,Fs=av(()=>{cl=function(t,e){return cl=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var s in n)n.hasOwnProperty(s)&&(r[s]=n[s])},cl(t,e)};ul=function(){return ul=Object.assign||function(e){for(var r,n=1,s=arguments.length;n<s;n++){r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},ul.apply(this,arguments)}});var F0=X(aa=>{"use strict";Object.defineProperty(aa,"__esModule",{value:!0});aa.delay=void 0;function d8(t){return new Promise(e=>{setTimeout(()=>{e(!0)},t)})}aa.delay=d8});var H0=X(Hs=>{"use strict";Object.defineProperty(Hs,"__esModule",{value:!0});Hs.ONE_THOUSAND=Hs.ONE_HUNDRED=void 0;Hs.ONE_HUNDRED=100;Hs.ONE_THOUSAND=1e3});var z0=X(j=>{"use strict";Object.defineProperty(j,"__esModule",{value:!0});j.ONE_YEAR=j.FOUR_WEEKS=j.THREE_WEEKS=j.TWO_WEEKS=j.ONE_WEEK=j.THIRTY_DAYS=j.SEVEN_DAYS=j.FIVE_DAYS=j.THREE_DAYS=j.ONE_DAY=j.TWENTY_FOUR_HOURS=j.TWELVE_HOURS=j.SIX_HOURS=j.THREE_HOURS=j.ONE_HOUR=j.SIXTY_MINUTES=j.THIRTY_MINUTES=j.TEN_MINUTES=j.FIVE_MINUTES=j.ONE_MINUTE=j.SIXTY_SECONDS=j.THIRTY_SECONDS=j.TEN_SECONDS=j.FIVE_SECONDS=j.ONE_SECOND=void 0;j.ONE_SECOND=1;j.FIVE_SECONDS=5;j.TEN_SECONDS=10;j.THIRTY_SECONDS=30;j.SIXTY_SECONDS=60;j.ONE_MINUTE=j.SIXTY_SECONDS;j.FIVE_MINUTES=j.ONE_MINUTE*5;j.TEN_MINUTES=j.ONE_MINUTE*10;j.THIRTY_MINUTES=j.ONE_MINUTE*30;j.SIXTY_MINUTES=j.ONE_MINUTE*60;j.ONE_HOUR=j.SIXTY_MINUTES;j.THREE_HOURS=j.ONE_HOUR*3;j.SIX_HOURS=j.ONE_HOUR*6;j.TWELVE_HOURS=j.ONE_HOUR*12;j.TWENTY_FOUR_HOURS=j.ONE_HOUR*24;j.ONE_DAY=j.TWENTY_FOUR_HOURS;j.THREE_DAYS=j.ONE_DAY*3;j.FIVE_DAYS=j.ONE_DAY*5;j.SEVEN_DAYS=j.ONE_DAY*7;j.THIRTY_DAYS=j.ONE_DAY*30;j.ONE_WEEK=j.SEVEN_DAYS;j.TWO_WEEKS=j.ONE_WEEK*2;j.THREE_WEEKS=j.ONE_WEEK*3;j.FOUR_WEEKS=j.ONE_WEEK*4;j.ONE_YEAR=j.ONE_DAY*365});var fl=X(ca=>{"use strict";Object.defineProperty(ca,"__esModule",{value:!0});var V0=(Fs(),Cs(qs));V0.__exportStar(H0(),ca);V0.__exportStar(z0(),ca)});var j0=X(zs=>{"use strict";Object.defineProperty(zs,"__esModule",{value:!0});zs.fromMiliseconds=zs.toMiliseconds=void 0;var $0=fl();function p8(t){return t*$0.ONE_THOUSAND}zs.toMiliseconds=p8;function g8(t){return Math.floor(t/$0.ONE_THOUSAND)}zs.fromMiliseconds=g8});var W0=X(ua=>{"use strict";Object.defineProperty(ua,"__esModule",{value:!0});var K0=(Fs(),Cs(qs));K0.__exportStar(F0(),ua);K0.__exportStar(j0(),ua)});var G0=X(Mi=>{"use strict";Object.defineProperty(Mi,"__esModule",{value:!0});Mi.Watch=void 0;var la=class{constructor(){this.timestamps=new Map}start(e){if(this.timestamps.has(e))throw new Error(`Watch already started for label: ${e}`);this.timestamps.set(e,{started:Date.now()})}stop(e){let r=this.get(e);if(typeof r.elapsed<"u")throw new Error(`Watch already stopped for label: ${e}`);let n=Date.now()-r.started;this.timestamps.set(e,{started:r.started,elapsed:n})}get(e){let r=this.timestamps.get(e);if(typeof r>"u")throw new Error(`No timestamp found for label: ${e}`);return r}elapsed(e){let r=this.get(e);return r.elapsed||Date.now()-r.started}};Mi.Watch=la;Mi.default=la});var Y0=X(fa=>{"use strict";Object.defineProperty(fa,"__esModule",{value:!0});fa.IWatch=void 0;var hl=class{};fa.IWatch=hl});var J0=X(dl=>{"use strict";Object.defineProperty(dl,"__esModule",{value:!0});var m8=(Fs(),Cs(qs));m8.__exportStar(Y0(),dl)});var $s=X(Vs=>{"use strict";Object.defineProperty(Vs,"__esModule",{value:!0});var ha=(Fs(),Cs(qs));ha.__exportStar(W0(),Vs);ha.__exportStar(G0(),Vs);ha.__exportStar(J0(),Vs);ha.__exportStar(fl(),Vs)});var Ja=X(le=>{"use strict";Object.defineProperty(le,"__esModule",{value:!0});le.getLocalStorage=le.getLocalStorageOrThrow=le.getCrypto=le.getCryptoOrThrow=le.getLocation=le.getLocationOrThrow=le.getNavigator=le.getNavigatorOrThrow=le.getDocument=le.getDocumentOrThrow=le.getFromWindowOrThrow=le.getFromWindow=void 0;function Jn(t){let e;return typeof window<"u"&&typeof window[t]<"u"&&(e=window[t]),e}le.getFromWindow=Jn;function Qs(t){let e=Jn(t);if(!e)throw new Error(`${t} is not defined in Window`);return e}le.getFromWindowOrThrow=Qs;function R6(){return Qs("document")}le.getDocumentOrThrow=R6;function D6(){return Jn("document")}le.getDocument=D6;function O6(){return Qs("navigator")}le.getNavigatorOrThrow=O6;function C6(){return Jn("navigator")}le.getNavigator=C6;function N6(){return Qs("location")}le.getLocationOrThrow=N6;function P6(){return Jn("location")}le.getLocation=P6;function U6(){return Qs("crypto")}le.getCryptoOrThrow=U6;function L6(){return Jn("crypto")}le.getCrypto=L6;function k6(){return Qs("localStorage")}le.getLocalStorageOrThrow=k6;function M6(){return Jn("localStorage")}le.getLocalStorage=M6});var zm=X(Xa=>{"use strict";Object.defineProperty(Xa,"__esModule",{value:!0});Xa.getWindowMetadata=void 0;var Hm=Ja();function q6(){let t,e;try{t=Hm.getDocumentOrThrow(),e=Hm.getLocationOrThrow()}catch{return null}function r(){let l=t.getElementsByTagName("link"),h=[];for(let d=0;d<l.length;d++){let p=l[d],g=p.getAttribute("rel");if(g&&g.toLowerCase().indexOf("icon")>-1){let m=p.getAttribute("href");if(m)if(m.toLowerCase().indexOf("https:")===-1&&m.toLowerCase().indexOf("http:")===-1&&m.indexOf("//")!==0){let b=e.protocol+"//"+e.host;if(m.indexOf("/")===0)b+=m;else{let T=e.pathname.split("/");T.pop();let w=T.join("/");b+=w+"/"+m}h.push(b)}else if(m.indexOf("//")===0){let b=e.protocol+m;h.push(b)}else h.push(m)}}return h}function n(...l){let h=t.getElementsByTagName("meta");for(let d=0;d<h.length;d++){let p=h[d],g=["itemprop","property","name"].map(m=>p.getAttribute(m)).filter(m=>m?l.includes(m):!1);if(g.length&&g){let m=p.getAttribute("content");if(m)return m}}return""}function s(){let l=n("name","og:site_name","og:title","twitter:title");return l||(l=t.title),l}function i(){return n("description","og:description","twitter:description","keywords")}let o=s(),a=i(),c=e.origin,u=r();return{description:a,url:c,icons:u,name:o}}Xa.getWindowMetadata=q6});var pd=X((o9,ax)=>{var VA="Input must be an string, Buffer or Uint8Array";function $A(t){let e;if(t instanceof Uint8Array)e=t;else if(typeof t=="string")e=new TextEncoder().encode(t);else throw new Error(VA);return e}function jA(t){return Array.prototype.map.call(t,function(e){return(e<16?"0":"")+e.toString(16)}).join("")}function su(t){return(4294967296+t).toString(16).substring(1)}function KA(t,e,r){let n=`
|
|
`+t+" = ";for(let s=0;s<e.length;s+=2){if(r===32)n+=su(e[s]).toUpperCase(),n+=" ",n+=su(e[s+1]).toUpperCase();else if(r===64)n+=su(e[s+1]).toUpperCase(),n+=su(e[s]).toUpperCase();else throw new Error("Invalid size "+r);s%6===4?n+=`
|
|
`+new Array(t.length+4).join(" "):s<e.length-2&&(n+=" ")}console.log(n)}function WA(t,e,r){let n=new Date().getTime(),s=new Uint8Array(e);for(let o=0;o<e;o++)s[o]=o%256;let i=new Date().getTime();console.log("Generated random input in "+(i-n)+"ms"),n=i;for(let o=0;o<r;o++){let a=t(s),c=new Date().getTime(),u=c-n;n=c,console.log("Hashed in "+u+"ms: "+a.substring(0,20)+"..."),console.log(Math.round(e/(1<<20)/(u/1e3)*100)/100+" MB PER SECOND")}}ax.exports={normalizeInput:$A,toHex:jA,debugPrint:KA,testSpeed:WA}});var mx=X((a9,gx)=>{var ou=pd();function iu(t,e,r){let n=t[e]+t[r],s=t[e+1]+t[r+1];n>=4294967296&&s++,t[e]=n,t[e+1]=s}function cx(t,e,r,n){let s=t[e]+r;r<0&&(s+=4294967296);let i=t[e+1]+n;s>=4294967296&&i++,t[e]=s,t[e+1]=i}function ux(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function Sn(t,e,r,n,s,i){let o=So[s],a=So[s+1],c=So[i],u=So[i+1];iu(Q,t,e),cx(Q,t,o,a);let f=Q[n]^Q[t],l=Q[n+1]^Q[t+1];Q[n]=l,Q[n+1]=f,iu(Q,r,n),f=Q[e]^Q[r],l=Q[e+1]^Q[r+1],Q[e]=f>>>24^l<<8,Q[e+1]=l>>>24^f<<8,iu(Q,t,e),cx(Q,t,c,u),f=Q[n]^Q[t],l=Q[n+1]^Q[t+1],Q[n]=f>>>16^l<<16,Q[n+1]=l>>>16^f<<16,iu(Q,r,n),f=Q[e]^Q[r],l=Q[e+1]^Q[r+1],Q[e]=l>>>31^f<<1,Q[e+1]=f>>>31^l<<1}var lx=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),GA=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3],Qe=new Uint8Array(GA.map(function(t){return t*2})),Q=new Uint32Array(32),So=new Uint32Array(32);function fx(t,e){let r=0;for(r=0;r<16;r++)Q[r]=t.h[r],Q[r+16]=lx[r];for(Q[24]=Q[24]^t.t,Q[25]=Q[25]^t.t/4294967296,e&&(Q[28]=~Q[28],Q[29]=~Q[29]),r=0;r<32;r++)So[r]=ux(t.b,4*r);for(r=0;r<12;r++)Sn(0,8,16,24,Qe[r*16+0],Qe[r*16+1]),Sn(2,10,18,26,Qe[r*16+2],Qe[r*16+3]),Sn(4,12,20,28,Qe[r*16+4],Qe[r*16+5]),Sn(6,14,22,30,Qe[r*16+6],Qe[r*16+7]),Sn(0,10,20,30,Qe[r*16+8],Qe[r*16+9]),Sn(2,12,22,24,Qe[r*16+10],Qe[r*16+11]),Sn(4,14,16,26,Qe[r*16+12],Qe[r*16+13]),Sn(6,8,18,28,Qe[r*16+14],Qe[r*16+15]);for(r=0;r<16;r++)t.h[r]=t.h[r]^Q[r]^Q[r+16]}var In=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);function hx(t,e,r,n){if(t===0||t>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(e&&e.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");if(r&&r.length!==16)throw new Error("Illegal salt, expected Uint8Array with length is 16");if(n&&n.length!==16)throw new Error("Illegal personal, expected Uint8Array with length is 16");let s={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:t};In.fill(0),In[0]=t,e&&(In[1]=e.length),In[2]=1,In[3]=1,r&&In.set(r,32),n&&In.set(n,48);for(let i=0;i<16;i++)s.h[i]=lx[i]^ux(In,i*4);return e&&(gd(s,e),s.c=128),s}function gd(t,e){for(let r=0;r<e.length;r++)t.c===128&&(t.t+=t.c,fx(t,!1),t.c=0),t.b[t.c++]=e[r]}function dx(t){for(t.t+=t.c;t.c<128;)t.b[t.c++]=0;fx(t,!0);let e=new Uint8Array(t.outlen);for(let r=0;r<t.outlen;r++)e[r]=t.h[r>>2]>>8*(r&3);return e}function px(t,e,r,n,s){r=r||64,t=ou.normalizeInput(t),n&&(n=ou.normalizeInput(n)),s&&(s=ou.normalizeInput(s));let i=hx(r,e,n,s);return gd(i,t),dx(i)}function YA(t,e,r,n,s){let i=px(t,e,r,n,s);return ou.toHex(i)}gx.exports={blake2b:px,blake2bHex:YA,blake2bInit:hx,blake2bUpdate:gd,blake2bFinal:dx}});var Sx=X((c9,_x)=>{var yx=pd();function JA(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function Bn(t,e,r,n,s,i){se[t]=se[t]+se[e]+s,se[n]=au(se[n]^se[t],16),se[r]=se[r]+se[n],se[e]=au(se[e]^se[r],12),se[t]=se[t]+se[e]+i,se[n]=au(se[n]^se[t],8),se[r]=se[r]+se[n],se[e]=au(se[e]^se[r],7)}function au(t,e){return t>>>e^t<<32-e}var wx=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),et=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]),se=new Uint32Array(16),Ve=new Uint32Array(16);function xx(t,e){let r=0;for(r=0;r<8;r++)se[r]=t.h[r],se[r+8]=wx[r];for(se[12]^=t.t,se[13]^=t.t/4294967296,e&&(se[14]=~se[14]),r=0;r<16;r++)Ve[r]=JA(t.b,4*r);for(r=0;r<10;r++)Bn(0,4,8,12,Ve[et[r*16+0]],Ve[et[r*16+1]]),Bn(1,5,9,13,Ve[et[r*16+2]],Ve[et[r*16+3]]),Bn(2,6,10,14,Ve[et[r*16+4]],Ve[et[r*16+5]]),Bn(3,7,11,15,Ve[et[r*16+6]],Ve[et[r*16+7]]),Bn(0,5,10,15,Ve[et[r*16+8]],Ve[et[r*16+9]]),Bn(1,6,11,12,Ve[et[r*16+10]],Ve[et[r*16+11]]),Bn(2,7,8,13,Ve[et[r*16+12]],Ve[et[r*16+13]]),Bn(3,4,9,14,Ve[et[r*16+14]],Ve[et[r*16+15]]);for(r=0;r<8;r++)t.h[r]^=se[r]^se[r+8]}function bx(t,e){if(!(t>0&&t<=32))throw new Error("Incorrect output length, should be in [1, 32]");let r=e?e.length:0;if(e&&!(r>0&&r<=32))throw new Error("Incorrect key length, should be in [1, 32]");let n={h:new Uint32Array(wx),b:new Uint8Array(64),c:0,t:0,outlen:t};return n.h[0]^=16842752^r<<8^t,r>0&&(md(n,e),n.c=64),n}function md(t,e){for(let r=0;r<e.length;r++)t.c===64&&(t.t+=t.c,xx(t,!1),t.c=0),t.b[t.c++]=e[r]}function Ex(t){for(t.t+=t.c;t.c<64;)t.b[t.c++]=0;xx(t,!0);let e=new Uint8Array(t.outlen);for(let r=0;r<t.outlen;r++)e[r]=t.h[r>>2]>>8*(r&3)&255;return e}function vx(t,e,r){r=r||32,t=yx.normalizeInput(t);let n=bx(r,e);return md(n,t),Ex(n)}function XA(t,e,r){let n=vx(t,e,r);return yx.toHex(n)}_x.exports={blake2s:vx,blake2sHex:XA,blake2sInit:bx,blake2sUpdate:md,blake2sFinal:Ex}});var Bx=X((u9,Ix)=>{var Io=mx(),Bo=Sx();Ix.exports={blake2b:Io.blake2b,blake2bHex:Io.blake2bHex,blake2bInit:Io.blake2bInit,blake2bUpdate:Io.blake2bUpdate,blake2bFinal:Io.blake2bFinal,blake2s:Bo.blake2s,blake2sHex:Bo.blake2sHex,blake2sInit:Bo.blake2sInit,blake2sUpdate:Bo.blake2sUpdate,blake2sFinal:Bo.blake2sFinal}});var zb=X(Dn=>{"use strict";Object.defineProperty(Dn,"__esModule",{value:!0});Dn.isBrowserCryptoAvailable=Dn.getSubtleCrypto=Dn.getBrowerCrypto=void 0;function jd(){return globalThis?.crypto||globalThis?.msCrypto||{}}Dn.getBrowerCrypto=jd;function Hb(){let t=jd();return t.subtle||t.webkitSubtle}Dn.getSubtleCrypto=Hb;function o5(){return!!jd()&&!!Hb()}Dn.isBrowserCryptoAvailable=o5});var jb=X(On=>{"use strict";Object.defineProperty(On,"__esModule",{value:!0});On.isBrowser=On.isNode=On.isReactNative=void 0;function Vb(){return typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"}On.isReactNative=Vb;function $b(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}On.isNode=$b;function a5(){return!Vb()&&!$b()}On.isBrowser=a5});var Kd=X(Iu=>{"use strict";Object.defineProperty(Iu,"__esModule",{value:!0});var Kb=(Fs(),Cs(qs));Kb.__exportStar(zb(),Iu);Kb.__exportStar(jb(),Iu)});var Qb=X((ek,Zb)=>{"use strict";Zb.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}});var W2=X((zk,K2)=>{K2.exports=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}});var kn=X(Ts=>{var Ap,hR=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];Ts.getSymbolSize=function(e){if(!e)throw new Error('"version" cannot be null or undefined');if(e<1||e>40)throw new Error('"version" should be in range from 1 to 40');return e*4+17};Ts.getSymbolTotalCodewords=function(e){return hR[e]};Ts.getBCHDigit=function(t){let e=0;for(;t!==0;)e++,t>>>=1;return e};Ts.setToSJISFunction=function(e){if(typeof e!="function")throw new Error('"toSJISFunc" is not a valid function.');Ap=e};Ts.isKanjiModeEnabled=function(){return typeof Ap<"u"};Ts.toSJIS=function(e){return Ap(e)}});var ku=X(Ht=>{Ht.L={bit:1};Ht.M={bit:0};Ht.Q={bit:3};Ht.H={bit:2};function dR(t){if(typeof t!="string")throw new Error("Param is not a string");switch(t.toLowerCase()){case"l":case"low":return Ht.L;case"m":case"medium":return Ht.M;case"q":case"quartile":return Ht.Q;case"h":case"high":return Ht.H;default:throw new Error("Unknown EC Level: "+t)}}Ht.isValid=function(e){return e&&typeof e.bit<"u"&&e.bit>=0&&e.bit<4};Ht.from=function(e,r){if(Ht.isValid(e))return e;try{return dR(e)}catch{return r}}});var J2=X((jk,Y2)=>{function G2(){this.buffer=[],this.length=0}G2.prototype={get:function(t){let e=Math.floor(t/8);return(this.buffer[e]>>>7-t%8&1)===1},put:function(t,e){for(let r=0;r<e;r++)this.putBit((t>>>e-r-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){let e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}};Y2.exports=G2});var Z2=X((Kk,X2)=>{function jo(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}jo.prototype.set=function(t,e,r,n){let s=t*this.size+e;this.data[s]=r,n&&(this.reservedBit[s]=!0)};jo.prototype.get=function(t,e){return this.data[t*this.size+e]};jo.prototype.xor=function(t,e,r){this.data[t*this.size+e]^=r};jo.prototype.isReserved=function(t,e){return this.reservedBit[t*this.size+e]};X2.exports=jo});var Q2=X(Mu=>{var pR=kn().getSymbolSize;Mu.getRowColCoords=function(e){if(e===1)return[];let r=Math.floor(e/7)+2,n=pR(e),s=n===145?26:Math.ceil((n-13)/(2*r-2))*2,i=[n-7];for(let o=1;o<r-1;o++)i[o]=i[o-1]-s;return i.push(6),i.reverse()};Mu.getPositions=function(e){let r=[],n=Mu.getRowColCoords(e),s=n.length;for(let i=0;i<s;i++)for(let o=0;o<s;o++)i===0&&o===0||i===0&&o===s-1||i===s-1&&o===0||r.push([n[i],n[o]]);return r}});var rE=X(tE=>{var gR=kn().getSymbolSize,eE=7;tE.getPositions=function(e){let r=gR(e);return[[0,0],[r-eE,0],[0,r-eE]]}});var nE=X(he=>{he.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var Rs={N1:3,N2:3,N3:40,N4:10};he.isValid=function(e){return e!=null&&e!==""&&!isNaN(e)&&e>=0&&e<=7};he.from=function(e){return he.isValid(e)?parseInt(e,10):void 0};he.getPenaltyN1=function(e){let r=e.size,n=0,s=0,i=0,o=null,a=null;for(let c=0;c<r;c++){s=i=0,o=a=null;for(let u=0;u<r;u++){let f=e.get(c,u);f===o?s++:(s>=5&&(n+=Rs.N1+(s-5)),o=f,s=1),f=e.get(u,c),f===a?i++:(i>=5&&(n+=Rs.N1+(i-5)),a=f,i=1)}s>=5&&(n+=Rs.N1+(s-5)),i>=5&&(n+=Rs.N1+(i-5))}return n};he.getPenaltyN2=function(e){let r=e.size,n=0;for(let s=0;s<r-1;s++)for(let i=0;i<r-1;i++){let o=e.get(s,i)+e.get(s,i+1)+e.get(s+1,i)+e.get(s+1,i+1);(o===4||o===0)&&n++}return n*Rs.N2};he.getPenaltyN3=function(e){let r=e.size,n=0,s=0,i=0;for(let o=0;o<r;o++){s=i=0;for(let a=0;a<r;a++)s=s<<1&2047|e.get(o,a),a>=10&&(s===1488||s===93)&&n++,i=i<<1&2047|e.get(a,o),a>=10&&(i===1488||i===93)&&n++}return n*Rs.N3};he.getPenaltyN4=function(e){let r=0,n=e.data.length;for(let i=0;i<n;i++)r+=e.data[i];return Math.abs(Math.ceil(r*100/n/5)-10)*Rs.N4};function mR(t,e,r){switch(t){case he.Patterns.PATTERN000:return(e+r)%2===0;case he.Patterns.PATTERN001:return e%2===0;case he.Patterns.PATTERN010:return r%3===0;case he.Patterns.PATTERN011:return(e+r)%3===0;case he.Patterns.PATTERN100:return(Math.floor(e/2)+Math.floor(r/3))%2===0;case he.Patterns.PATTERN101:return e*r%2+e*r%3===0;case he.Patterns.PATTERN110:return(e*r%2+e*r%3)%2===0;case he.Patterns.PATTERN111:return(e*r%3+(e+r)%2)%2===0;default:throw new Error("bad maskPattern:"+t)}}he.applyMask=function(e,r){let n=r.size;for(let s=0;s<n;s++)for(let i=0;i<n;i++)r.isReserved(i,s)||r.xor(i,s,mR(e,i,s))};he.getBestMask=function(e,r){let n=Object.keys(he.Patterns).length,s=0,i=1/0;for(let o=0;o<n;o++){r(o),he.applyMask(o,e);let a=he.getPenaltyN1(e)+he.getPenaltyN2(e)+he.getPenaltyN3(e)+he.getPenaltyN4(e);he.applyMask(o,e),a<i&&(i=a,s=o)}return s}});var Rp=X(Tp=>{var Mn=ku(),qu=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],Fu=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];Tp.getBlocksCount=function(e,r){switch(r){case Mn.L:return qu[(e-1)*4+0];case Mn.M:return qu[(e-1)*4+1];case Mn.Q:return qu[(e-1)*4+2];case Mn.H:return qu[(e-1)*4+3];default:return}};Tp.getTotalCodewordsCount=function(e,r){switch(r){case Mn.L:return Fu[(e-1)*4+0];case Mn.M:return Fu[(e-1)*4+1];case Mn.Q:return Fu[(e-1)*4+2];case Mn.H:return Fu[(e-1)*4+3];default:return}}});var sE=X(zu=>{var Ko=new Uint8Array(512),Hu=new Uint8Array(256);(function(){let e=1;for(let r=0;r<255;r++)Ko[r]=e,Hu[e]=r,e<<=1,e&256&&(e^=285);for(let r=255;r<512;r++)Ko[r]=Ko[r-255]})();zu.log=function(e){if(e<1)throw new Error("log("+e+")");return Hu[e]};zu.exp=function(e){return Ko[e]};zu.mul=function(e,r){return e===0||r===0?0:Ko[Hu[e]+Hu[r]]}});var iE=X(Wo=>{var Dp=sE();Wo.mul=function(e,r){let n=new Uint8Array(e.length+r.length-1);for(let s=0;s<e.length;s++)for(let i=0;i<r.length;i++)n[s+i]^=Dp.mul(e[s],r[i]);return n};Wo.mod=function(e,r){let n=new Uint8Array(e);for(;n.length-r.length>=0;){let s=n[0];for(let o=0;o<r.length;o++)n[o]^=Dp.mul(r[o],s);let i=0;for(;i<n.length&&n[i]===0;)i++;n=n.slice(i)}return n};Wo.generateECPolynomial=function(e){let r=new Uint8Array([1]);for(let n=0;n<e;n++)r=Wo.mul(r,new Uint8Array([1,Dp.exp(n)]));return r}});var cE=X((Qk,aE)=>{var oE=iE();function Op(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}Op.prototype.initialize=function(e){this.degree=e,this.genPoly=oE.generateECPolynomial(this.degree)};Op.prototype.encode=function(e){if(!this.genPoly)throw new Error("Encoder not initialized");let r=new Uint8Array(e.length+this.degree);r.set(e);let n=oE.mod(r,this.genPoly),s=this.degree-n.length;if(s>0){let i=new Uint8Array(this.degree);return i.set(n,s),i}return n};aE.exports=Op});var Cp=X(uE=>{uE.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}});var Np=X(tn=>{var lE="[0-9]+",yR="[A-Z $%*+\\-./:]+",Go="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Go=Go.replace(/u/g,"\\u");var wR="(?:(?![A-Z0-9 $%*+\\-./:]|"+Go+`)(?:.|[\r
|
|
]))+`;tn.KANJI=new RegExp(Go,"g");tn.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");tn.BYTE=new RegExp(wR,"g");tn.NUMERIC=new RegExp(lE,"g");tn.ALPHANUMERIC=new RegExp(yR,"g");var xR=new RegExp("^"+Go+"$"),bR=new RegExp("^"+lE+"$"),ER=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");tn.testKanji=function(e){return xR.test(e)};tn.testNumeric=function(e){return bR.test(e)};tn.testAlphanumeric=function(e){return ER.test(e)}});var qn=X(Be=>{var vR=Cp(),Pp=Np();Be.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]};Be.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]};Be.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]};Be.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]};Be.MIXED={bit:-1};Be.getCharCountIndicator=function(e,r){if(!e.ccBits)throw new Error("Invalid mode: "+e);if(!vR.isValid(r))throw new Error("Invalid version: "+r);return r>=1&&r<10?e.ccBits[0]:r<27?e.ccBits[1]:e.ccBits[2]};Be.getBestModeForData=function(e){return Pp.testNumeric(e)?Be.NUMERIC:Pp.testAlphanumeric(e)?Be.ALPHANUMERIC:Pp.testKanji(e)?Be.KANJI:Be.BYTE};Be.toString=function(e){if(e&&e.id)return e.id;throw new Error("Invalid mode")};Be.isValid=function(e){return e&&e.bit&&e.ccBits};function _R(t){if(typeof t!="string")throw new Error("Param is not a string");switch(t.toLowerCase()){case"numeric":return Be.NUMERIC;case"alphanumeric":return Be.ALPHANUMERIC;case"kanji":return Be.KANJI;case"byte":return Be.BYTE;default:throw new Error("Unknown mode: "+t)}}Be.from=function(e,r){if(Be.isValid(e))return e;try{return _R(e)}catch{return r}}});var gE=X(Ds=>{var Vu=kn(),SR=Rp(),fE=ku(),Fn=qn(),Up=Cp(),dE=7973,hE=Vu.getBCHDigit(dE);function IR(t,e,r){for(let n=1;n<=40;n++)if(e<=Ds.getCapacity(n,r,t))return n}function pE(t,e){return Fn.getCharCountIndicator(t,e)+4}function BR(t,e){let r=0;return t.forEach(function(n){let s=pE(n.mode,e);r+=s+n.getBitsLength()}),r}function AR(t,e){for(let r=1;r<=40;r++)if(BR(t,r)<=Ds.getCapacity(r,e,Fn.MIXED))return r}Ds.from=function(e,r){return Up.isValid(e)?parseInt(e,10):r};Ds.getCapacity=function(e,r,n){if(!Up.isValid(e))throw new Error("Invalid QR Code version");typeof n>"u"&&(n=Fn.BYTE);let s=Vu.getSymbolTotalCodewords(e),i=SR.getTotalCodewordsCount(e,r),o=(s-i)*8;if(n===Fn.MIXED)return o;let a=o-pE(n,e);switch(n){case Fn.NUMERIC:return Math.floor(a/10*3);case Fn.ALPHANUMERIC:return Math.floor(a/11*2);case Fn.KANJI:return Math.floor(a/13);case Fn.BYTE:default:return Math.floor(a/8)}};Ds.getBestVersionForData=function(e,r){let n,s=fE.from(r,fE.M);if(Array.isArray(e)){if(e.length>1)return AR(e,s);if(e.length===0)return 1;n=e[0]}else n=e;return IR(n.mode,n.getLength(),s)};Ds.getEncodedBits=function(e){if(!Up.isValid(e)||e<7)throw new Error("Invalid QR Code version");let r=e<<12;for(;Vu.getBCHDigit(r)-hE>=0;)r^=dE<<Vu.getBCHDigit(r)-hE;return e<<12|r}});var xE=X(wE=>{var Lp=kn(),yE=1335,TR=21522,mE=Lp.getBCHDigit(yE);wE.getEncodedBits=function(e,r){let n=e.bit<<3|r,s=n<<10;for(;Lp.getBCHDigit(s)-mE>=0;)s^=yE<<Lp.getBCHDigit(s)-mE;return(n<<10|s)^TR}});var EE=X((iM,bE)=>{var RR=qn();function Di(t){this.mode=RR.NUMERIC,this.data=t.toString()}Di.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)};Di.prototype.getLength=function(){return this.data.length};Di.prototype.getBitsLength=function(){return Di.getBitsLength(this.data.length)};Di.prototype.write=function(e){let r,n,s;for(r=0;r+3<=this.data.length;r+=3)n=this.data.substr(r,3),s=parseInt(n,10),e.put(s,10);let i=this.data.length-r;i>0&&(n=this.data.substr(r),s=parseInt(n,10),e.put(s,i*3+1))};bE.exports=Di});var _E=X((oM,vE)=>{var DR=qn(),kp=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function Oi(t){this.mode=DR.ALPHANUMERIC,this.data=t}Oi.getBitsLength=function(e){return 11*Math.floor(e/2)+6*(e%2)};Oi.prototype.getLength=function(){return this.data.length};Oi.prototype.getBitsLength=function(){return Oi.getBitsLength(this.data.length)};Oi.prototype.write=function(e){let r;for(r=0;r+2<=this.data.length;r+=2){let n=kp.indexOf(this.data[r])*45;n+=kp.indexOf(this.data[r+1]),e.put(n,11)}this.data.length%2&&e.put(kp.indexOf(this.data[r]),6)};vE.exports=Oi});var IE=X((aM,SE)=>{var OR=qn();function Ci(t){this.mode=OR.BYTE,typeof t=="string"?this.data=new TextEncoder().encode(t):this.data=new Uint8Array(t)}Ci.getBitsLength=function(e){return e*8};Ci.prototype.getLength=function(){return this.data.length};Ci.prototype.getBitsLength=function(){return Ci.getBitsLength(this.data.length)};Ci.prototype.write=function(t){for(let e=0,r=this.data.length;e<r;e++)t.put(this.data[e],8)};SE.exports=Ci});var AE=X((cM,BE)=>{var CR=qn(),NR=kn();function Ni(t){this.mode=CR.KANJI,this.data=t}Ni.getBitsLength=function(e){return e*13};Ni.prototype.getLength=function(){return this.data.length};Ni.prototype.getBitsLength=function(){return Ni.getBitsLength(this.data.length)};Ni.prototype.write=function(t){let e;for(e=0;e<this.data.length;e++){let r=NR.toSJIS(this.data[e]);if(r>=33088&&r<=40956)r-=33088;else if(r>=57408&&r<=60351)r-=49472;else throw new Error("Invalid SJIS character: "+this.data[e]+`
|
|
Make sure your charset is UTF-8`);r=(r>>>8&255)*192+(r&255),t.put(r,13)}};BE.exports=Ni});var TE=X((uM,Mp)=>{"use strict";var Yo={single_source_shortest_paths:function(t,e,r){var n={},s={};s[e]=0;var i=Yo.PriorityQueue.make();i.push(e,0);for(var o,a,c,u,f,l,h,d,p;!i.empty();){o=i.pop(),a=o.value,u=o.cost,f=t[a]||{};for(c in f)f.hasOwnProperty(c)&&(l=f[c],h=u+l,d=s[c],p=typeof s[c]>"u",(p||d>h)&&(s[c]=h,i.push(c,h),n[c]=a))}if(typeof r<"u"&&typeof s[r]>"u"){var g=["Could not find a path from ",e," to ",r,"."].join("");throw new Error(g)}return n},extract_shortest_path_from_predecessor_list:function(t,e){for(var r=[],n=e,s;n;)r.push(n),s=t[n],n=t[n];return r.reverse(),r},find_path:function(t,e,r){var n=Yo.single_source_shortest_paths(t,e,r);return Yo.extract_shortest_path_from_predecessor_list(n,r)},PriorityQueue:{make:function(t){var e=Yo.PriorityQueue,r={},n;t=t||{};for(n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return r.queue=[],r.sorter=t.sorter||e.default_sorter,r},default_sorter:function(t,e){return t.cost-e.cost},push:function(t,e){var r={value:t,cost:e};this.queue.push(r),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};typeof Mp<"u"&&(Mp.exports=Yo)});var LE=X(Pi=>{var ce=qn(),OE=EE(),CE=_E(),NE=IE(),PE=AE(),Jo=Np(),$u=kn(),PR=TE();function RE(t){return unescape(encodeURIComponent(t)).length}function Xo(t,e,r){let n=[],s;for(;(s=t.exec(r))!==null;)n.push({data:s[0],index:s.index,mode:e,length:s[0].length});return n}function UE(t){let e=Xo(Jo.NUMERIC,ce.NUMERIC,t),r=Xo(Jo.ALPHANUMERIC,ce.ALPHANUMERIC,t),n,s;return $u.isKanjiModeEnabled()?(n=Xo(Jo.BYTE,ce.BYTE,t),s=Xo(Jo.KANJI,ce.KANJI,t)):(n=Xo(Jo.BYTE_KANJI,ce.BYTE,t),s=[]),e.concat(r,n,s).sort(function(o,a){return o.index-a.index}).map(function(o){return{data:o.data,mode:o.mode,length:o.length}})}function qp(t,e){switch(e){case ce.NUMERIC:return OE.getBitsLength(t);case ce.ALPHANUMERIC:return CE.getBitsLength(t);case ce.KANJI:return PE.getBitsLength(t);case ce.BYTE:return NE.getBitsLength(t)}}function UR(t){return t.reduce(function(e,r){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===r.mode?(e[e.length-1].data+=r.data,e):(e.push(r),e)},[])}function LR(t){let e=[];for(let r=0;r<t.length;r++){let n=t[r];switch(n.mode){case ce.NUMERIC:e.push([n,{data:n.data,mode:ce.ALPHANUMERIC,length:n.length},{data:n.data,mode:ce.BYTE,length:n.length}]);break;case ce.ALPHANUMERIC:e.push([n,{data:n.data,mode:ce.BYTE,length:n.length}]);break;case ce.KANJI:e.push([n,{data:n.data,mode:ce.BYTE,length:RE(n.data)}]);break;case ce.BYTE:e.push([{data:n.data,mode:ce.BYTE,length:RE(n.data)}])}}return e}function kR(t,e){let r={},n={start:{}},s=["start"];for(let i=0;i<t.length;i++){let o=t[i],a=[];for(let c=0;c<o.length;c++){let u=o[c],f=""+i+c;a.push(f),r[f]={node:u,lastCount:0},n[f]={};for(let l=0;l<s.length;l++){let h=s[l];r[h]&&r[h].node.mode===u.mode?(n[h][f]=qp(r[h].lastCount+u.length,u.mode)-qp(r[h].lastCount,u.mode),r[h].lastCount+=u.length):(r[h]&&(r[h].lastCount=u.length),n[h][f]=qp(u.length,u.mode)+4+ce.getCharCountIndicator(u.mode,e))}}s=a}for(let i=0;i<s.length;i++)n[s[i]].end=0;return{map:n,table:r}}function DE(t,e){let r,n=ce.getBestModeForData(t);if(r=ce.from(e,n),r!==ce.BYTE&&r.bit<n.bit)throw new Error('"'+t+'" cannot be encoded with mode '+ce.toString(r)+`.
|
|
Suggested mode is: `+ce.toString(n));switch(r===ce.KANJI&&!$u.isKanjiModeEnabled()&&(r=ce.BYTE),r){case ce.NUMERIC:return new OE(t);case ce.ALPHANUMERIC:return new CE(t);case ce.KANJI:return new PE(t);case ce.BYTE:return new NE(t)}}Pi.fromArray=function(e){return e.reduce(function(r,n){return typeof n=="string"?r.push(DE(n,null)):n.data&&r.push(DE(n.data,n.mode)),r},[])};Pi.fromString=function(e,r){let n=UE(e,$u.isKanjiModeEnabled()),s=LR(n),i=kR(s,r),o=PR.find_path(i.map,"start","end"),a=[];for(let c=1;c<o.length-1;c++)a.push(i.table[o[c]].node);return Pi.fromArray(UR(a))};Pi.rawSplit=function(e){return Pi.fromArray(UE(e,$u.isKanjiModeEnabled()))}});var ME=X(kE=>{var Ku=kn(),Fp=ku(),MR=J2(),qR=Z2(),FR=Q2(),HR=rE(),Vp=nE(),$p=Rp(),zR=cE(),ju=gE(),VR=xE(),$R=qn(),Hp=LE();function jR(t,e){let r=t.size,n=HR.getPositions(e);for(let s=0;s<n.length;s++){let i=n[s][0],o=n[s][1];for(let a=-1;a<=7;a++)if(!(i+a<=-1||r<=i+a))for(let c=-1;c<=7;c++)o+c<=-1||r<=o+c||(a>=0&&a<=6&&(c===0||c===6)||c>=0&&c<=6&&(a===0||a===6)||a>=2&&a<=4&&c>=2&&c<=4?t.set(i+a,o+c,!0,!0):t.set(i+a,o+c,!1,!0))}}function KR(t){let e=t.size;for(let r=8;r<e-8;r++){let n=r%2===0;t.set(r,6,n,!0),t.set(6,r,n,!0)}}function WR(t,e){let r=FR.getPositions(e);for(let n=0;n<r.length;n++){let s=r[n][0],i=r[n][1];for(let o=-2;o<=2;o++)for(let a=-2;a<=2;a++)o===-2||o===2||a===-2||a===2||o===0&&a===0?t.set(s+o,i+a,!0,!0):t.set(s+o,i+a,!1,!0)}}function GR(t,e){let r=t.size,n=ju.getEncodedBits(e),s,i,o;for(let a=0;a<18;a++)s=Math.floor(a/3),i=a%3+r-8-3,o=(n>>a&1)===1,t.set(s,i,o,!0),t.set(i,s,o,!0)}function zp(t,e,r){let n=t.size,s=VR.getEncodedBits(e,r),i,o;for(i=0;i<15;i++)o=(s>>i&1)===1,i<6?t.set(i,8,o,!0):i<8?t.set(i+1,8,o,!0):t.set(n-15+i,8,o,!0),i<8?t.set(8,n-i-1,o,!0):i<9?t.set(8,15-i-1+1,o,!0):t.set(8,15-i-1,o,!0);t.set(n-8,8,1,!0)}function YR(t,e){let r=t.size,n=-1,s=r-1,i=7,o=0;for(let a=r-1;a>0;a-=2)for(a===6&&a--;;){for(let c=0;c<2;c++)if(!t.isReserved(s,a-c)){let u=!1;o<e.length&&(u=(e[o]>>>i&1)===1),t.set(s,a-c,u),i--,i===-1&&(o++,i=7)}if(s+=n,s<0||r<=s){s-=n,n=-n;break}}}function JR(t,e,r){let n=new MR;r.forEach(function(c){n.put(c.mode.bit,4),n.put(c.getLength(),$R.getCharCountIndicator(c.mode,t)),c.write(n)});let s=Ku.getSymbolTotalCodewords(t),i=$p.getTotalCodewordsCount(t,e),o=(s-i)*8;for(n.getLengthInBits()+4<=o&&n.put(0,4);n.getLengthInBits()%8!==0;)n.putBit(0);let a=(o-n.getLengthInBits())/8;for(let c=0;c<a;c++)n.put(c%2?17:236,8);return XR(n,t,e)}function XR(t,e,r){let n=Ku.getSymbolTotalCodewords(e),s=$p.getTotalCodewordsCount(e,r),i=n-s,o=$p.getBlocksCount(e,r),a=n%o,c=o-a,u=Math.floor(n/o),f=Math.floor(i/o),l=f+1,h=u-f,d=new zR(h),p=0,g=new Array(o),m=new Array(o),b=0,T=new Uint8Array(t.buffer);for(let O=0;O<o;O++){let N=O<c?f:l;g[O]=T.slice(p,p+N),m[O]=d.encode(g[O]),p+=N,b=Math.max(b,N)}let w=new Uint8Array(n),v=0,R,C;for(R=0;R<b;R++)for(C=0;C<o;C++)R<g[C].length&&(w[v++]=g[C][R]);for(R=0;R<h;R++)for(C=0;C<o;C++)w[v++]=m[C][R];return w}function ZR(t,e,r,n){let s;if(Array.isArray(t))s=Hp.fromArray(t);else if(typeof t=="string"){let u=e;if(!u){let f=Hp.rawSplit(t);u=ju.getBestVersionForData(f,r)}s=Hp.fromString(t,u||40)}else throw new Error("Invalid data");let i=ju.getBestVersionForData(s,r);if(!i)throw new Error("The amount of data is too big to be stored in a QR Code");if(!e)e=i;else if(e<i)throw new Error(`
|
|
The chosen QR Code version cannot contain this amount of data.
|
|
Minimum version required to store current data is: `+i+`.
|
|
`);let o=JR(e,r,s),a=Ku.getSymbolSize(e),c=new qR(a);return jR(c,e),KR(c),WR(c,e),zp(c,r,0),e>=7&&GR(c,e),YR(c,o),isNaN(n)&&(n=Vp.getBestMask(c,zp.bind(null,c,r))),Vp.applyMask(n,c),zp(c,r,n),{modules:c,version:e,errorCorrectionLevel:r,maskPattern:n,segments:s}}kE.create=function(e,r){if(typeof e>"u"||e==="")throw new Error("No input text");let n=Fp.M,s,i;return typeof r<"u"&&(n=Fp.from(r.errorCorrectionLevel,Fp.M),s=ju.from(r.version),i=Vp.from(r.maskPattern),r.toSJISFunc&&Ku.setToSJISFunction(r.toSJISFunc)),ZR(e,s,n,i)}});var jp=X(Os=>{function qE(t){if(typeof t=="number"&&(t=t.toString()),typeof t!="string")throw new Error("Color should be defined as hex string");let e=t.slice().replace("#","").split("");if(e.length<3||e.length===5||e.length>8)throw new Error("Invalid hex color: "+t);(e.length===3||e.length===4)&&(e=Array.prototype.concat.apply([],e.map(function(n){return[n,n]}))),e.length===6&&e.push("F","F");let r=parseInt(e.join(""),16);return{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:r&255,hex:"#"+e.slice(0,6).join("")}}Os.getOptions=function(e){e||(e={}),e.color||(e.color={});let r=typeof e.margin>"u"||e.margin===null||e.margin<0?4:e.margin,n=e.width&&e.width>=21?e.width:void 0,s=e.scale||4;return{width:n,scale:n?4:s,margin:r,color:{dark:qE(e.color.dark||"#000000ff"),light:qE(e.color.light||"#ffffffff")},type:e.type,rendererOpts:e.rendererOpts||{}}};Os.getScale=function(e,r){return r.width&&r.width>=e+r.margin*2?r.width/(e+r.margin*2):r.scale};Os.getImageWidth=function(e,r){let n=Os.getScale(e,r);return Math.floor((e+r.margin*2)*n)};Os.qrToImageData=function(e,r,n){let s=r.modules.size,i=r.modules.data,o=Os.getScale(s,n),a=Math.floor((s+n.margin*2)*o),c=n.margin*o,u=[n.color.light,n.color.dark];for(let f=0;f<a;f++)for(let l=0;l<a;l++){let h=(f*a+l)*4,d=n.color.light;if(f>=c&&l>=c&&f<a-c&&l<a-c){let p=Math.floor((f-c)/o),g=Math.floor((l-c)/o);d=u[i[p*s+g]?1:0]}e[h++]=d.r,e[h++]=d.g,e[h++]=d.b,e[h]=d.a}}});var FE=X(Wu=>{var Kp=jp();function QR(t,e,r){t.clearRect(0,0,e.width,e.height),e.style||(e.style={}),e.height=r,e.width=r,e.style.height=r+"px",e.style.width=r+"px"}function eD(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}Wu.render=function(e,r,n){let s=n,i=r;typeof s>"u"&&(!r||!r.getContext)&&(s=r,r=void 0),r||(i=eD()),s=Kp.getOptions(s);let o=Kp.getImageWidth(e.modules.size,s),a=i.getContext("2d"),c=a.createImageData(o,o);return Kp.qrToImageData(c.data,e,s),QR(a,i,o),a.putImageData(c,0,0),i};Wu.renderToDataURL=function(e,r,n){let s=n;typeof s>"u"&&(!r||!r.getContext)&&(s=r,r=void 0),s||(s={});let i=Wu.render(e,r,s),o=s.type||"image/png",a=s.rendererOpts||{};return i.toDataURL(o,a.quality)}});var VE=X(zE=>{var tD=jp();function HE(t,e){let r=t.a/255,n=e+'="'+t.hex+'"';return r<1?n+" "+e+'-opacity="'+r.toFixed(2).slice(1)+'"':n}function Wp(t,e,r){let n=t+e;return typeof r<"u"&&(n+=" "+r),n}function rD(t,e,r){let n="",s=0,i=!1,o=0;for(let a=0;a<t.length;a++){let c=Math.floor(a%e),u=Math.floor(a/e);!c&&!i&&(i=!0),t[a]?(o++,a>0&&c>0&&t[a-1]||(n+=i?Wp("M",c+r,.5+u+r):Wp("m",s,0),s=0,i=!1),c+1<e&&t[a+1]||(n+=Wp("h",o),o=0)):s++}return n}zE.render=function(e,r,n){let s=tD.getOptions(r),i=e.modules.size,o=e.modules.data,a=i+s.margin*2,c=s.color.light.a?"<path "+HE(s.color.light,"fill")+' d="M0 0h'+a+"v"+a+'H0z"/>':"",u="<path "+HE(s.color.dark,"stroke")+' d="'+rD(o,i,s.margin)+'"/>',f='viewBox="0 0 '+a+" "+a+'"',h='<svg xmlns="http://www.w3.org/2000/svg" '+(s.width?'width="'+s.width+'" height="'+s.width+'" ':"")+f+' shape-rendering="crispEdges">'+c+u+`</svg>
|
|
`;return typeof n=="function"&&n(null,h),h}});var jE=X(Zo=>{var nD=W2(),Gp=ME(),$E=FE(),sD=VE();function Yp(t,e,r,n,s){let i=[].slice.call(arguments,1),o=i.length,a=typeof i[o-1]=="function";if(!a&&!nD())throw new Error("Callback required as last argument");if(a){if(o<2)throw new Error("Too few arguments provided");o===2?(s=r,r=e,e=n=void 0):o===3&&(e.getContext&&typeof s>"u"?(s=n,n=void 0):(s=n,n=r,r=e,e=void 0))}else{if(o<1)throw new Error("Too few arguments provided");return o===1?(r=e,e=n=void 0):o===2&&!e.getContext&&(n=r,r=e,e=void 0),new Promise(function(c,u){try{let f=Gp.create(r,n);c(t(f,e,n))}catch(f){u(f)}})}try{let c=Gp.create(r,n);s(null,t(c,e,n))}catch(c){s(c)}}Zo.create=Gp.create;Zo.toCanvas=Yp.bind(null,$E.render);Zo.toDataURL=Yp.bind(null,$E.renderToDataURL);Zo.toString=Yp.bind(null,function(t,e,r){return sD.render(t,r)})});var iD={};Ce(iD,{SignClient:()=>j2,qrDataUrl:()=>GE.toDataURL});var KE=Ie(_0(),1),WE=Ie(T0(),1);var Uu=Ie($n(),1);var en=Ie($n(),1);var Z0=Ie($n()),pa=Ie($s());var $t=class{};var pl=class extends $t{constructor(e){super()}},X0=pa.FIVE_SECONDS,nn={pulse:"heartbeat_pulse"},da=class t extends pl{constructor(e){super(e),this.events=new Z0.EventEmitter,this.interval=X0,this.interval=e?.interval||X0}static async init(e){let r=new t(e);return await r.init(),r}async init(){await this.initialize()}stop(){clearInterval(this.intervalRef)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async initialize(){this.intervalRef=setInterval(()=>this.pulse(),(0,pa.toMiliseconds)(this.interval))}pulse(){this.events.emit(nn.pulse)}};var y8=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,w8=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,x8=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function b8(t,e){if(t==="__proto__"||t==="constructor"&&e&&typeof e=="object"&&"prototype"in e){E8(t);return}return e}function E8(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}function qi(t,e={}){if(typeof t!="string")return t;if(t[0]==='"'&&t[t.length-1]==='"'&&t.indexOf("\\")===-1)return t.slice(1,-1);let r=t.trim();if(r.length<=9)switch(r.toLowerCase()){case"true":return!0;case"false":return!1;case"undefined":return;case"null":return null;case"nan":return Number.NaN;case"infinity":return Number.POSITIVE_INFINITY;case"-infinity":return Number.NEGATIVE_INFINITY}if(!x8.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(y8.test(t)||w8.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,b8)}return JSON.parse(t)}catch(n){if(e.strict)throw n;return t}}function v8(t){return!t||typeof t.then!="function"?Promise.resolve(t):t}function Ae(t,...e){try{return v8(t(...e))}catch(r){return Promise.reject(r)}}function _8(t){let e=typeof t;return t===null||e!=="object"&&e!=="function"}function S8(t){let e=Object.getPrototypeOf(t);return!e||e.isPrototypeOf(Object)}function Fi(t){if(_8(t))return String(t);if(S8(t)||Array.isArray(t))return JSON.stringify(t);if(typeof t.toJSON=="function")return Fi(t.toJSON());throw new Error("[unstorage] Cannot stringify value!")}var gl="base64:";function Q0(t){return typeof t=="string"?t:gl+B8(t)}function eg(t){return typeof t!="string"||!t.startsWith(gl)?t:I8(t.slice(gl.length))}function I8(t){return globalThis.Buffer?Buffer.from(t,"base64"):Uint8Array.from(globalThis.atob(t),e=>e.codePointAt(0))}function B8(t){return globalThis.Buffer?Buffer.from(t).toString("base64"):globalThis.btoa(String.fromCodePoint(...t))}function sn(t){return t&&t.split("?")[0]?.replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,"")||""}function ml(t){return t.split(":").some(e=>e==="."||e==="..")}function tg(...t){return sn(t.join(":"))}function yl(t){return t=sn(t),t?t+":":""}function rg(t,e){if(e===void 0)return!0;let r=0,n=t.indexOf(":");for(;n>-1;)r++,n=t.indexOf(":",n+1);return r<=e}function ng(t,e){return e?t.startsWith(e)&&t[t.length-1]!=="$":t[t.length-1]!=="$"}var A8="memory",T8=()=>{let t=new Map;return{name:A8,getInstance:()=>t,hasItem(e){return t.has(e)},getItem(e){return t.get(e)??null},getItemRaw(e){return t.get(e)??null},setItem(e,r){t.set(e,r)},setItemRaw(e,r){t.set(e,r)},removeItem(e){t.delete(e)},getKeys(){return[...t.keys()]},clear(){t.clear()},dispose(){t.clear()}}};function og(t={}){let e={mounts:{"":t.driver||T8()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},r=l=>{let h=sn(l);if(!h||ml(h))throw new Error(`[unstorage] Invalid key: ${JSON.stringify(l)}`);return h},n=l=>{let h=yl(l);if(ml(h))throw new Error(`[unstorage] Invalid base: ${JSON.stringify(l)}`);return h},s=l=>{for(let h of e.mountpoints)if(l.startsWith(h))return{base:h,relativeKey:l.slice(h.length),driver:e.mounts[h]};return{base:"",relativeKey:l,driver:e.mounts[""]}},i=(l,h)=>e.mountpoints.filter(d=>d.startsWith(l)||h&&l.startsWith(d)).map(d=>({relativeBase:l.length>d.length?l.slice(d.length):void 0,mountpoint:d,driver:e.mounts[d]})),o=(l,h)=>{if(e.watching){h=sn(h);for(let d of e.watchListeners)d(l,h)}},a=async()=>{if(!e.watching){e.watching=!0;for(let l in e.mounts)e.unwatch[l]=await sg(e.mounts[l],o,l)}},c=async()=>{if(e.watching){for(let l in e.unwatch)await e.unwatch[l]();e.unwatch={},e.watching=!1}},u=(l,h,d)=>{let p=new Map,g=m=>{let b=p.get(m.base);return b||(b={driver:m.driver,base:m.base,items:[]},p.set(m.base,b)),b};for(let m of l){let b=typeof m=="string",T=r(b?m:m.key),w=b?void 0:m.value,v=b||!m.options?h:{...h,...m.options},R=s(T);g(R).items.push({key:T,value:w,relativeKey:R.relativeKey,options:v})}return Promise.all([...p.values()].map(m=>d(m))).then(m=>m.flat())},f={async hasItem(l,h={}){l=r(l);let{relativeKey:d,driver:p}=s(l);return Ae(p.hasItem,d,h)},async getItem(l,h={}){l=r(l);let{relativeKey:d,driver:p}=s(l);return Ae(p.getItem,d,h).then(g=>qi(g))},async getItems(l,h={}){return u(l,h,d=>d.driver.getItems?Ae(d.driver.getItems,d.items.map(p=>({key:p.relativeKey,options:p.options})),h).then(p=>p.map(g=>({key:tg(d.base,g.key),value:qi(g.value)}))):Promise.all(d.items.map(p=>Ae(d.driver.getItem,p.relativeKey,p.options).then(g=>({key:p.key,value:qi(g)})))))},async getItemRaw(l,h={}){l=r(l);let{relativeKey:d,driver:p}=s(l);return p.getItemRaw?Ae(p.getItemRaw,d,h):Ae(p.getItem,d,h).then(g=>eg(g))},async setItem(l,h,d={}){if(h===void 0)return f.removeItem(l);l=r(l);let{relativeKey:p,driver:g}=s(l);g.setItem&&(await Ae(g.setItem,p,Fi(h),d),g.watch||o("update",l))},async setItems(l,h){await u(l,h,async d=>{if(d.driver.setItems)return Ae(d.driver.setItems,d.items.map(p=>({key:p.relativeKey,value:Fi(p.value),options:p.options})),h);d.driver.setItem&&await Promise.all(d.items.map(p=>Ae(d.driver.setItem,p.relativeKey,Fi(p.value),p.options)))})},async setItemRaw(l,h,d={}){if(h===void 0)return f.removeItem(l,d);l=r(l);let{relativeKey:p,driver:g}=s(l);if(g.setItemRaw)await Ae(g.setItemRaw,p,h,d);else if(g.setItem)await Ae(g.setItem,p,Q0(h),d);else return;g.watch||o("update",l)},async removeItem(l,h={}){typeof h=="boolean"&&(h={removeMeta:h}),l=r(l);let{relativeKey:d,driver:p}=s(l);p.removeItem&&(await Ae(p.removeItem,d,h),(h.removeMeta||h.removeMata)&&await Ae(p.removeItem,d+"$",h),p.watch||o("remove",l))},async getMeta(l,h={}){typeof h=="boolean"&&(h={nativeOnly:h}),l=r(l);let{relativeKey:d,driver:p}=s(l),g=Object.create(null);if(p.getMeta&&Object.assign(g,await Ae(p.getMeta,d,h)),!h.nativeOnly){let m=await Ae(p.getItem,d+"$",h).then(b=>qi(b));m&&typeof m=="object"&&(typeof m.atime=="string"&&(m.atime=new Date(m.atime)),typeof m.mtime=="string"&&(m.mtime=new Date(m.mtime)),Object.assign(g,m))}return g},async setMeta(l,h,d={}){return this.setItem(r(l)+"$",h,d)},async removeMeta(l,h={}){return this.removeItem(r(l)+"$",h)},async getKeys(l,h={}){l=n(l);let d=i(l,!0),p=[],g=[],m=!0;for(let T of d){T.driver.flags?.maxDepth||(m=!1);let w=await Ae(T.driver.getKeys,T.relativeBase,h);for(let v of w){let R=T.mountpoint+sn(v);p.some(C=>R.startsWith(C))||g.push(R)}p=[T.mountpoint,...p.filter(v=>!v.startsWith(T.mountpoint))]}let b=h.maxDepth!==void 0&&!m;return g.filter(T=>(!b||rg(T,h.maxDepth))&&ng(T,l))},async clear(l,h={}){l=n(l),await Promise.all(i(l,!1).map(async d=>{if(d.driver.clear)return Ae(d.driver.clear,d.relativeBase,h);if(d.driver.removeItem){let p=await d.driver.getKeys(d.relativeBase||"",h);return Promise.all(p.map(g=>d.driver.removeItem(g,h)))}}))},async dispose(){await Promise.all(Object.values(e.mounts).map(l=>ig(l)))},async watch(l){return await a(),e.watchListeners.push(l),async()=>{e.watchListeners=e.watchListeners.filter(h=>h!==l),e.watchListeners.length===0&&await c()}},async unwatch(){e.watchListeners=[],await c()},mount(l,h){if(l=n(l),l&&e.mounts[l])throw new Error(`already mounted at ${l}`);return l&&(e.mountpoints.push(l),e.mountpoints.sort((d,p)=>p.length-d.length)),e.mounts[l]=h,e.watching&&Promise.resolve(sg(h,o,l)).then(d=>{e.unwatch[l]=d}).catch(console.error),f},async unmount(l,h=!0){l=yl(l),!(!l||!e.mounts[l])&&(e.watching&&l in e.unwatch&&(e.unwatch[l]?.(),delete e.unwatch[l]),h&&await ig(e.mounts[l]),e.mountpoints=e.mountpoints.filter(d=>d!==l),delete e.mounts[l])},getMount(l=""){l=sn(l)+":";let h=s(l);return{driver:h.driver,base:h.base}},getMounts(l="",h={}){return l=sn(l),i(l,h.parents).map(p=>({driver:p.driver,base:p.mountpoint}))},keys:(l,h={})=>f.getKeys(l,h),get:(l,h={})=>f.getItem(l,h),set:(l,h,d={})=>f.setItem(l,h,d),has:(l,h={})=>f.hasItem(l,h),del:(l,h={})=>f.removeItem(l,h),remove:(l,h={})=>f.removeItem(l,h)};return f}function sg(t,e,r){return t.watch?t.watch((n,s)=>e(n,r+s)):()=>{}}async function ig(t){typeof t.dispose=="function"&&await Ae(t.dispose)}function jn(t){return new Promise((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)})}function xl(t,e){let r,n=()=>{if(r)return r;let s=indexedDB.open(t);return s.onupgradeneeded=()=>s.result.createObjectStore(e),r=jn(s),r.then(i=>{i.onclose=()=>r=void 0},()=>{r=void 0}),r};return(s,i)=>n().then(o=>i(o.transaction(e,s).objectStore(e)))}var wl;function Hi(){return wl||(wl=xl("keyval-store","keyval")),wl}function bl(t,e=Hi()){return e("readonly",r=>jn(r.get(t)))}function ag(t,e,r=Hi()){return r("readwrite",n=>(n.put(e,t),jn(n.transaction)))}function cg(t,e=Hi()){return e("readwrite",r=>(r.delete(t),jn(r.transaction)))}function ug(t=Hi()){return t("readwrite",e=>(e.clear(),jn(e.transaction)))}function R8(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},jn(t.transaction)}function lg(t=Hi()){return t("readonly",e=>{if(e.getAllKeys)return jn(e.getAllKeys());let r=[];return R8(e,n=>r.push(n.key)).then(()=>r)})}var D8=t=>JSON.stringify(t,(e,r)=>typeof r=="bigint"?r.toString()+"n":r),O8=t=>{let e=/([\[:])?(\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))([,\}\]])/g,r=t.replace(e,'$1"$2n"$3');return JSON.parse(r,(n,s)=>typeof s=="string"&&s.match(/^\d+n$/)?BigInt(s.substring(0,s.length-1)):s)};function nr(t){if(typeof t!="string")throw new Error(`Cannot safe json parse value of type ${typeof t}`);try{return O8(t)}catch{return t}}function Sr(t){return typeof t=="string"?t:D8(t)||""}var C8="idb-keyval",N8=(t={})=>{let e=t.base&&t.base.length>0?`${t.base}:`:"",r=s=>e+s,n;return t.dbName&&t.storeName&&(n=xl(t.dbName,t.storeName)),{name:C8,options:t,async hasItem(s){return!(typeof await bl(r(s),n)>"u")},async getItem(s){return await bl(r(s),n)??null},setItem(s,i){return ag(r(s),i,n)},removeItem(s){return cg(r(s),n)},getKeys(){return lg(n)},clear(){return ug(n)}}},P8="WALLET_CONNECT_V2_INDEXED_DB",U8="keyvaluestorage",vl=class{constructor(){this.indexedDb=og({driver:N8({dbName:P8,storeName:U8})})}async getKeys(){return this.indexedDb.getKeys()}async getEntries(){return(await this.indexedDb.getItems(await this.indexedDb.getKeys())).map(e=>[e.key,e.value])}async getItem(e){let r=await this.indexedDb.getItem(e);if(r!==null)return r}async setItem(e,r){await this.indexedDb.setItem(e,Sr(r))}async removeItem(e){await this.indexedDb.removeItem(e)}},El=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},ga={exports:{}};(function(){let t;function e(){}t=e,t.prototype.getItem=function(r){return this.hasOwnProperty(r)?String(this[r]):null},t.prototype.setItem=function(r,n){this[r]=String(n)},t.prototype.removeItem=function(r){delete this[r]},t.prototype.clear=function(){let r=this;Object.keys(r).forEach(function(n){r[n]=void 0,delete r[n]})},t.prototype.key=function(r){return r=r||0,Object.keys(this)[r]},t.prototype.__defineGetter__("length",function(){return Object.keys(this).length}),typeof El<"u"&&El.localStorage?ga.exports=El.localStorage:typeof window<"u"&&window.localStorage?ga.exports=window.localStorage:ga.exports=new e})();function L8(t){var e;return[t[0],nr((e=t[1])!=null?e:"")]}var _l=class{constructor(){this.localStorage=ga.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(L8)}async getItem(e){let r=this.localStorage.getItem(e);if(r!==null)return nr(r)}async setItem(e,r){this.localStorage.setItem(e,Sr(r))}async removeItem(e){this.localStorage.removeItem(e)}},k8="wc_storage_version",fg=1,M8=async(t,e,r)=>{let n=k8,s=await e.getItem(n);if(s&&s>=fg){r(e);return}let i=await t.getKeys();if(!i.length){r(e);return}let o=[];for(;i.length;){let a=i.shift();if(!a)continue;let c=a.toLowerCase();if(c.includes("wc@")||c.includes("walletconnect")||c.includes("wc_")||c.includes("wallet_connect")){let u=await t.getItem(a);await e.setItem(a,u),o.push(a)}}await e.setItem(n,fg),r(e),q8(t,o)},q8=async(t,e)=>{e.length&&e.forEach(async r=>{await t.removeItem(r)})},ma=class{constructor(){this.initialized=!1,this.setInitialized=r=>{this.storage=r,this.initialized=!0};let e=new _l;this.storage=e;try{let r=new vl;M8(e,r,this.setInitialized)}catch{this.initialized=!0}}async getKeys(){return await this.initialize(),this.storage.getKeys()}async getEntries(){return await this.initialize(),this.storage.getEntries()}async getItem(e){return await this.initialize(),this.storage.getItem(e)}async setItem(e,r){return await this.initialize(),this.storage.setItem(e,r)}async removeItem(e){return await this.initialize(),this.storage.removeItem(e)}async initialize(){this.initialized||await new Promise(e=>{let r=setInterval(()=>{this.initialized&&(clearInterval(r),e())},20)})}};var sr={exports:{}};function F8(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}var H8=z8;function z8(t,e,r){var n=r&&r.stringify||F8,s=1;if(typeof t=="object"&&t!==null){var i=e.length+s;if(i===1)return t;var o=new Array(i);o[0]=n(t);for(var a=1;a<i;a++)o[a]=n(e[a]);return o.join(" ")}if(typeof t!="string")return t;var c=e.length;if(c===0)return t;for(var u="",f=1-s,l=-1,h=t&&t.length||0,d=0;d<h;){if(t.charCodeAt(d)===37&&d+1<h){switch(l=l>-1?l:0,t.charCodeAt(d+1)){case 100:case 102:if(f>=c||e[f]==null)break;l<d&&(u+=t.slice(l,d)),u+=Number(e[f]),l=d+2,d++;break;case 105:if(f>=c||e[f]==null)break;l<d&&(u+=t.slice(l,d)),u+=Math.floor(Number(e[f])),l=d+2,d++;break;case 79:case 111:case 106:if(f>=c||e[f]===void 0)break;l<d&&(u+=t.slice(l,d));var p=typeof e[f];if(p==="string"){u+="'"+e[f]+"'",l=d+2,d++;break}if(p==="function"){u+=e[f].name||"<anonymous>",l=d+2,d++;break}u+=n(e[f]),l=d+2,d++;break;case 115:if(f>=c)break;l<d&&(u+=t.slice(l,d)),u+=String(e[f]),l=d+2,d++;break;case 37:l<d&&(u+=t.slice(l,d)),u+="%",l=d+2,d++,f--;break}++f}++d}return l===-1?t:(l<h&&(u+=t.slice(l)),u)}var hg=H8;sr.exports=Ir;var zi=n3().console||{},V8={mapHttpRequest:ya,mapHttpResponse:ya,wrapRequestSerializer:Sl,wrapResponseSerializer:Sl,wrapErrorSerializer:Sl,req:ya,res:ya,err:pg,errWithCause:pg};function an(t,e){return t==="silent"?1/0:e.levels.values[t]}var Dl=Symbol("pino.logFuncs"),Il=Symbol("pino.hierarchy"),$8={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function dg(t,e){let r={logger:e,parent:t[Il]};e[Il]=r}function j8(t,e,r){let n={};e.forEach(s=>{n[s]=r[s]?r[s]:zi[s]||zi[$8[s]||"log"]||js}),t[Dl]=n}function K8(t,e){return Array.isArray(t)?t.filter(function(r){return r!=="!stdSerializers.err"}):t===!0?Object.keys(e):!1}function Ir(t){t=t||{},t.browser=t.browser||{};let e=t.browser.transmit;if(e&&typeof e.send!="function")throw Error("pino: transmit option must have a send function");let r=t.browser.write||zi;t.browser.write&&(t.browser.asObject=!0);let n=t.serializers||{},s=K8(t.browser.serialize,n),i=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(i=!1);let o=Object.keys(t.customLevels||{}),a=["error","fatal","warn","info","debug","trace"].concat(o);typeof r=="function"&&a.forEach(function(g){r[g]=r}),(t.enabled===!1||t.browser.disabled)&&(t.level="silent");let c=t.level||"info",u=Object.create(r);u.log||(u.log=js),j8(u,a,r),dg({},u),Object.defineProperty(u,"levelVal",{get:l}),Object.defineProperty(u,"level",{get:h,set:d});let f={transmit:e,serialize:s,asObject:t.browser.asObject,asObjectBindingsOnly:t.browser.asObjectBindingsOnly,formatters:t.browser.formatters,levels:a,timestamp:e3(t),messageKey:t.messageKey||"msg",onChild:t.onChild||js};u.levels=W8(t),u.level=c,u.isLevelEnabled=function(g){return this.levels.values[g]?this.levels.values[g]>=this.levels.values[this.level]:!1},u.setMaxListeners=u.getMaxListeners=u.emit=u.addListener=u.on=u.prependListener=u.once=u.prependOnceListener=u.removeListener=u.removeAllListeners=u.listeners=u.listenerCount=u.eventNames=u.write=u.flush=js,u.serializers=n,u._serialize=s,u._stdErrSerialize=i,u.child=function(...g){return p.call(this,f,...g)},e&&(u._logEvent=Bl());function l(){return an(this.level,this)}function h(){return this._level}function d(g){if(g!=="silent"&&!this.levels.values[g])throw Error("unknown level "+g);this._level=g,Kn(this,f,u,"error"),Kn(this,f,u,"fatal"),Kn(this,f,u,"warn"),Kn(this,f,u,"info"),Kn(this,f,u,"debug"),Kn(this,f,u,"trace"),o.forEach(m=>{Kn(this,f,u,m)})}function p(g,m,b){if(!m)throw new Error("missing bindings for child Pino");b=b||{},s&&m.serializers&&(b.serializers=m.serializers);let T=b.serializers;if(s&&T){var w=Object.assign({},n,T),v=t.browser.serialize===!0?Object.keys(w):s;delete m.serializers,Ol([m],v,w,this._stdErrSerialize)}function R(O){this._childLevel=(O._childLevel|0)+1,this.bindings=m,w&&(this.serializers=w,this._serialize=v),e&&(this._logEvent=Bl([].concat(O._logEvent.bindings,m)))}R.prototype=this;let C=new R(this);return dg(this,C),C.child=function(...O){return p.call(this,g,...O)},C.level=b.level||this.level,g.onChild(C),C}return u}function W8(t){let e=t.customLevels||{},r=Object.assign({},Ir.levels.values,e),n=Object.assign({},Ir.levels.labels,G8(e));return{values:r,labels:n}}function G8(t){let e={};return Object.keys(t).forEach(function(r){e[t[r]]=r}),e}Ir.levels={values:{fatal:60,error:50,warn:40,info:30,debug:20,trace:10},labels:{10:"trace",20:"debug",30:"info",40:"warn",50:"error",60:"fatal"}},Ir.stdSerializers=V8,Ir.stdTimeFunctions=Object.assign({},{nullTime:wg,epochTime:xg,unixTime:t3,isoTime:r3});function Y8(t){let e=[];t.bindings&&e.push(t.bindings);let r=t[Il];for(;r.parent;)r=r.parent,r.logger.bindings&&e.push(r.logger.bindings);return e.reverse()}function Kn(t,e,r,n){if(Object.defineProperty(t,n,{value:an(t.level,r)>an(n,r)?js:r[Dl][n],writable:!0,enumerable:!0,configurable:!0}),t[n]===js){if(!e.transmit)return;let i=e.transmit.level||t.level,o=an(i,r);if(an(n,r)<o)return}t[n]=X8(t,e,r,n);let s=Y8(t);s.length!==0&&(t[n]=J8(s,t[n]))}function J8(t,e){return function(){return e.apply(this,[...t,...arguments])}}function X8(t,e,r,n){return(function(s){return function(){let i=e.timestamp(),o=new Array(arguments.length),a=Object.getPrototypeOf&&Object.getPrototypeOf(this)===zi?zi:this;for(var c=0;c<o.length;c++)o[c]=arguments[c];var u=!1;if(e.serialize&&(Ol(o,this._serialize,this.serializers,this._stdErrSerialize),u=!0),e.asObject||e.formatters?s.call(a,...Z8(this,n,o,i,e)):s.apply(a,o),e.transmit){let f=e.transmit.level||t._level,l=an(f,r),h=an(n,r);if(h<l)return;Q8(this,{ts:i,methodLevel:n,methodValue:h,transmitLevel:f,transmitValue:r.levels.values[e.transmit.level||t._level],send:e.transmit.send,val:an(t._level,r)},o,u)}}})(t[Dl][n])}function Z8(t,e,r,n,s){let{level:i,log:o=l=>l}=s.formatters||{},a=r.slice(),c=a[0],u={},f=(t._childLevel|0)+1;if(f<1&&(f=1),n&&(u.time=n),i){let l=i(e,t.levels.values[e]);Object.assign(u,l)}else u.level=t.levels.values[e];if(s.asObjectBindingsOnly){if(c!==null&&typeof c=="object")for(;f--&&typeof a[0]=="object";)Object.assign(u,a.shift());return[o(u),...a]}else{if(c!==null&&typeof c=="object"){for(;f--&&typeof a[0]=="object";)Object.assign(u,a.shift());c=a.length?hg(a.shift(),a):void 0}else typeof c=="string"&&(c=hg(a.shift(),a));return c!==void 0&&(u[s.messageKey]=c),[o(u)]}}function Ol(t,e,r,n){for(let s in t)if(n&&t[s]instanceof Error)t[s]=Ir.stdSerializers.err(t[s]);else if(typeof t[s]=="object"&&!Array.isArray(t[s])&&e)for(let i in t[s])e.indexOf(i)>-1&&i in r&&(t[s][i]=r[i](t[s][i]))}function Q8(t,e,r,n=!1){let s=e.send,i=e.ts,o=e.methodLevel,a=e.methodValue,c=e.val,u=t._logEvent.bindings;n||Ol(r,t._serialize||Object.keys(t.serializers),t.serializers,t._stdErrSerialize===void 0?!0:t._stdErrSerialize),t._logEvent.ts=i,t._logEvent.messages=r.filter(function(f){return u.indexOf(f)===-1}),t._logEvent.level.label=o,t._logEvent.level.value=a,s(o,t._logEvent,c),t._logEvent=Bl(u)}function Bl(t){return{ts:0,messages:[],bindings:t||[],level:{label:"",value:0}}}function pg(t){let e={type:t.constructor.name,msg:t.message,stack:t.stack};for(let r in t)e[r]===void 0&&(e[r]=t[r]);return e}function e3(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?wg:xg}function ya(){return{}}function Sl(t){return t}function js(){}function wg(){return!1}function xg(){return Date.now()}function t3(){return Math.round(Date.now()/1e3)}function r3(){return new Date(Date.now()).toISOString()}function n3(){function t(e){return typeof e<"u"&&e}try{return typeof globalThis<"u"||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch{return t(self)||t(window)||t(this)||{}}}sr.exports.default=Ir;var qD=sr.exports.pino=Ir,s3={level:"info"},Ea="custom_context",Cl=1e3*1024,i3=Object.defineProperty,o3=(t,e,r)=>e in t?i3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,on=(t,e,r)=>o3(t,typeof e!="symbol"?e+"":e,r),Al=class{constructor(e){on(this,"nodeValue"),on(this,"sizeInBytes"),on(this,"next"),this.nodeValue=e,this.sizeInBytes=new TextEncoder().encode(this.nodeValue).length,this.next=null}get value(){return this.nodeValue}get size(){return this.sizeInBytes}},xa=class{constructor(e){on(this,"lengthInNodes"),on(this,"sizeInBytes"),on(this,"head"),on(this,"tail"),on(this,"maxSizeInBytes"),this.head=null,this.tail=null,this.lengthInNodes=0,this.maxSizeInBytes=e,this.sizeInBytes=0}append(e){let r=new Al(e);if(r.size>this.maxSizeInBytes)throw new Error(`[LinkedList] Value too big to insert into list: ${e} with size ${r.size}`);for(;this.size+r.size>this.maxSizeInBytes;)this.shift();this.head?(this.tail&&(this.tail.next=r),this.tail=r):(this.head=r,this.tail=r),this.lengthInNodes++,this.sizeInBytes+=r.size}shift(){if(!this.head)return;let e=this.head;this.head=this.head.next,this.head||(this.tail=null),this.lengthInNodes--,this.sizeInBytes-=e.size}toArray(){let e=[],r=this.head;for(;r!==null;)e.push(r.value),r=r.next;return e}get length(){return this.lengthInNodes}get size(){return this.sizeInBytes}toOrderedArray(){return Array.from(this)}[Symbol.iterator](){let e=this.head;return{next:()=>{if(!e)return{done:!0,value:null};let r=e.value;return e=e.next,{done:!1,value:r}}}}},a3=t=>JSON.stringify(t,(e,r)=>typeof r=="bigint"?r.toString()+"n":r);function gg(t){return typeof t=="string"?t:a3(t)||""}var c3=Object.defineProperty,u3=(t,e,r)=>e in t?c3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wa=(t,e,r)=>u3(t,typeof e!="symbol"?e+"":e,r),ba=class{constructor(e,r=Cl){wa(this,"logs"),wa(this,"level"),wa(this,"levelValue"),wa(this,"MAX_LOG_SIZE_IN_BYTES"),this.level=e??"error",this.levelValue=sr.exports.levels.values[this.level],this.MAX_LOG_SIZE_IN_BYTES=r,this.logs=new xa(this.MAX_LOG_SIZE_IN_BYTES)}forwardToConsole(e,r){r===sr.exports.levels.values.error?console.error(e):r===sr.exports.levels.values.warn?console.warn(e):r===sr.exports.levels.values.debug?console.debug(e):r===sr.exports.levels.values.trace?console.trace(e):console.log(e)}appendToLogs(e){this.logs.append(gg({timestamp:new Date().toISOString(),log:e}));let r=typeof e=="string"?JSON.parse(e).level:e.level;r>=this.levelValue&&this.forwardToConsole(e,r)}getLogs(){return this.logs}clearLogs(){this.logs=new xa(this.MAX_LOG_SIZE_IN_BYTES)}getLogArray(){return Array.from(this.logs)}logsToBlob(e){let r=this.getLogArray();return r.push(gg({extraMetadata:e})),new Blob(r,{type:"application/json"})}},l3=Object.defineProperty,f3=(t,e,r)=>e in t?l3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,h3=(t,e,r)=>f3(t,typeof e!="symbol"?e+"":e,r),Tl=class{constructor(e,r=Cl){h3(this,"baseChunkLogger"),this.baseChunkLogger=new ba(e,r)}write(e){this.baseChunkLogger.appendToLogs(e)}getLogs(){return this.baseChunkLogger.getLogs()}clearLogs(){this.baseChunkLogger.clearLogs()}getLogArray(){return this.baseChunkLogger.getLogArray()}logsToBlob(e){return this.baseChunkLogger.logsToBlob(e)}downloadLogsBlobInBrowser(e){let r=URL.createObjectURL(this.logsToBlob(e)),n=document.createElement("a");n.href=r,n.download=`walletconnect-logs-${new Date().toISOString()}.txt`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(r)}},d3=Object.defineProperty,p3=(t,e,r)=>e in t?d3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,g3=(t,e,r)=>p3(t,typeof e!="symbol"?e+"":e,r),Rl=class{constructor(e,r=Cl){g3(this,"baseChunkLogger"),this.baseChunkLogger=new ba(e,r)}write(e){this.baseChunkLogger.appendToLogs(e)}getLogs(){return this.baseChunkLogger.getLogs()}clearLogs(){this.baseChunkLogger.clearLogs()}getLogArray(){return this.baseChunkLogger.getLogArray()}logsToBlob(e){return this.baseChunkLogger.logsToBlob(e)}},m3=Object.defineProperty,y3=Object.defineProperties,w3=Object.getOwnPropertyDescriptors,mg=Object.getOwnPropertySymbols,x3=Object.prototype.hasOwnProperty,b3=Object.prototype.propertyIsEnumerable,yg=(t,e,r)=>e in t?m3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cn=(t,e)=>{for(var r in e||(e={}))x3.call(e,r)&&yg(t,r,e[r]);if(mg)for(var r of mg(e))b3.call(e,r)&&yg(t,r,e[r]);return t},un=(t,e)=>y3(t,w3(e));function bg(t){return un(cn({},t),{level:t?.level||s3.level})}function E3(t,e,r=Ea){return t[r]=e,t}function We(t,e=Ea){return t[e]||""}function v3(t,e,r=Ea){let n=We(t,r);return n.trim()?`${n}/${e}`:e}function ft(t,e,r=Ea){let n=v3(t,e,r),s=t.child({context:n});return E3(s,n,r)}function _3(t){var e,r;let n=new Tl((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:sr.exports(un(cn({},t.opts),{level:"trace",browser:un(cn({},(r=t.opts)==null?void 0:r.browser),{write:s=>n.write(s)})})),chunkLoggerController:n}}function S3(t){var e,r;let n=new Rl((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:sr.exports(un(cn({},t.opts),{level:"trace",browser:un(cn({},(r=t.opts)==null?void 0:r.browser),{write:s=>n.write(s)})}),n),chunkLoggerController:n}}function va(t){var e;if(typeof t.loggerOverride<"u"&&typeof t.loggerOverride!="string")return{logger:t.loggerOverride,chunkLoggerController:null};let r=un(cn({},t.opts),{level:typeof t.loggerOverride=="string"?t.loggerOverride:(e=t.opts)==null?void 0:e.level});return typeof window<"u"?_3(un(cn({},t),{opts:r})):S3(un(cn({},t),{opts:r}))}var Eg=Ie($n()),_a=class extends $t{constructor(e){super(),this.opts=e,this.protocol="wc",this.version=2}};var Sa=class extends $t{constructor(e,r){super(),this.core=e,this.logger=r,this.records=new Map}},Ia=class{constructor(e,r){this.logger=e,this.core=r}},Ba=class extends $t{constructor(e,r){super(),this.relayer=e,this.logger=r}},Aa=class extends $t{constructor(e){super()}},Ta=class{constructor(e,r,n,s){this.core=e,this.logger=r,this.name=n}};var Ra=class extends $t{constructor(e,r){super(),this.relayer=e,this.logger=r}};var Da=class extends $t{constructor(e,r){super(),this.core=e,this.logger=r}};var Oa=class{constructor(e,r,n){this.core=e,this.logger=r,this.store=n}},Ca=class{constructor(e,r){this.projectId=e,this.logger=r}},Na=class{constructor(e,r,n){this.core=e,this.logger=r,this.telemetryEnabled=n}};var Pa=class{constructor(e){this.opts=e,this.protocol="wc",this.version=2}};var Ua=class{constructor(e){this.client=e}};var G=Ie($s(),1);var Fg=Ie($s());function I3(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Hg(t,...e){if(!I3(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function vg(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function B3(t,e){Hg(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var Ks=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Nl=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function A3(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function zg(t){return typeof t=="string"&&(t=A3(t)),Hg(t),t}var Hl=class{clone(){return this._cloneInto()}};function T3(t){let e=n=>t().update(zg(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Vg(t=32){if(Ks&&typeof Ks.getRandomValues=="function")return Ks.getRandomValues(new Uint8Array(t));if(Ks&&typeof Ks.randomBytes=="function")return Ks.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function R3(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(r>>s&i),a=Number(r&i),c=n?4:0,u=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+u,a,n)}var zl=class extends Hl{constructor(e,r,n,s){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Nl(this.buffer)}update(e){vg(this);let{view:r,buffer:n,blockLen:s}=this;e=zg(e);let i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=Nl(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){vg(this),B3(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let l=o;l<s;l++)r[l]=0;R3(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=Nl(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%r&&e.buffer.set(n),e}},La=BigInt(2**32-1),Vl=BigInt(32);function $g(t,e=!1){return e?{h:Number(t&La),l:Number(t>>Vl&La)}:{h:Number(t>>Vl&La)|0,l:Number(t&La)|0}}function D3(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let s=0;s<t.length;s++){let{h:i,l:o}=$g(t[s],e);[r[s],n[s]]=[i,o]}return[r,n]}var O3=(t,e)=>BigInt(t>>>0)<<Vl|BigInt(e>>>0),C3=(t,e,r)=>t>>>r,N3=(t,e,r)=>t<<32-r|e>>>r,P3=(t,e,r)=>t>>>r|e<<32-r,U3=(t,e,r)=>t<<32-r|e>>>r,L3=(t,e,r)=>t<<64-r|e>>>r-32,k3=(t,e,r)=>t>>>r-32|e<<64-r,M3=(t,e)=>e,q3=(t,e)=>t,F3=(t,e,r)=>t<<r|e>>>32-r,H3=(t,e,r)=>e<<r|t>>>32-r,z3=(t,e,r)=>e<<r-32|t>>>64-r,V3=(t,e,r)=>t<<r-32|e>>>64-r;function $3(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var j3=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),K3=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,W3=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),G3=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,Y3=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),J3=(t,e,r,n,s,i)=>e+r+n+s+i+(t/2**32|0)|0,te={fromBig:$g,split:D3,toBig:O3,shrSH:C3,shrSL:N3,rotrSH:P3,rotrSL:U3,rotrBH:L3,rotrBL:k3,rotr32H:M3,rotr32L:q3,rotlSH:F3,rotlSL:H3,rotlBH:z3,rotlBL:V3,add:$3,add3L:j3,add3H:K3,add4L:W3,add4H:G3,add5H:J3,add5L:Y3},[X3,Z3]=te.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),ln=new Uint32Array(80),fn=new Uint32Array(80),$l=class extends zl{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:d,Gl:p,Hh:g,Hl:m}=this;return[e,r,n,s,i,o,a,c,u,f,l,h,d,p,g,m]}set(e,r,n,s,i,o,a,c,u,f,l,h,d,p,g,m){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=p|0,this.Hh=g|0,this.Hl=m|0}process(e,r){for(let w=0;w<16;w++,r+=4)ln[w]=e.getUint32(r),fn[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let v=ln[w-15]|0,R=fn[w-15]|0,C=te.rotrSH(v,R,1)^te.rotrSH(v,R,8)^te.shrSH(v,R,7),O=te.rotrSL(v,R,1)^te.rotrSL(v,R,8)^te.shrSL(v,R,7),N=ln[w-2]|0,I=fn[w-2]|0,k=te.rotrSH(N,I,19)^te.rotrBH(N,I,61)^te.shrSH(N,I,6),L=te.rotrSL(N,I,19)^te.rotrBL(N,I,61)^te.shrSL(N,I,6),P=te.add4L(O,L,fn[w-7],fn[w-16]),E=te.add4H(P,C,k,ln[w-7],ln[w-16]);ln[w]=E|0,fn[w]=P|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:p,Gh:g,Gl:m,Hh:b,Hl:T}=this;for(let w=0;w<80;w++){let v=te.rotrSH(l,h,14)^te.rotrSH(l,h,18)^te.rotrBH(l,h,41),R=te.rotrSL(l,h,14)^te.rotrSL(l,h,18)^te.rotrBL(l,h,41),C=l&d^~l&g,O=h&p^~h&m,N=te.add5L(T,R,O,Z3[w],fn[w]),I=te.add5H(N,b,v,C,X3[w],ln[w]),k=N|0,L=te.rotrSH(n,s,28)^te.rotrBH(n,s,34)^te.rotrBH(n,s,39),P=te.rotrSL(n,s,28)^te.rotrBL(n,s,34)^te.rotrBL(n,s,39),E=n&i^n&a^i&a,B=s&o^s&c^o&c;b=g|0,T=m|0,g=d|0,m=p|0,d=l|0,p=h|0,{h:l,l:h}=te.add(u|0,f|0,I|0,k|0),u=a|0,f=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let y=te.add3L(k,P,B);n=te.add3H(y,I,L,E),s=y|0}({h:n,l:s}=te.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=te.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=te.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=te.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=te.add(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:p}=te.add(this.Fh|0,this.Fl|0,d|0,p|0),{h:g,l:m}=te.add(this.Gh|0,this.Gl|0,g|0,m|0),{h:b,l:T}=te.add(this.Hh|0,this.Hl|0,b|0,T|0),this.set(n,s,i,o,a,c,u,f,l,h,d,p,g,m,b,T)}roundClean(){ln.fill(0),fn.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)}},Q3=T3(()=>new $l);var tf=BigInt(0),jg=BigInt(1),e_=BigInt(2);function rf(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function nf(t){if(!rf(t))throw new Error("Uint8Array expected")}function Pl(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}var t_=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function sf(t){nf(t);let e="";for(let r=0;r<t.length;r++)e+=t_[t[r]];return e}function Kg(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?tf:BigInt("0x"+t)}var Br={_0:48,_9:57,A:65,F:70,a:97,f:102};function _g(t){if(t>=Br._0&&t<=Br._9)return t-Br._0;if(t>=Br.A&&t<=Br.F)return t-(Br.A-10);if(t>=Br.a&&t<=Br.f)return t-(Br.a-10)}function Wg(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){let o=_g(t.charCodeAt(i)),a=_g(t.charCodeAt(i+1));if(o===void 0||a===void 0){let c=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function r_(t){return Kg(sf(t))}function qa(t){return nf(t),Kg(sf(Uint8Array.from(t).reverse()))}function Gg(t,e){return Wg(t.toString(16).padStart(e*2,"0"))}function jl(t,e){return Gg(t,e).reverse()}function Ar(t,e,r){let n;if(typeof e=="string")try{n=Wg(e)}catch(i){throw new Error(t+" must be hex string or Uint8Array, cause: "+i)}else if(rf(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let s=n.length;if(typeof r=="number"&&s!==r)throw new Error(t+" of length "+r+" expected, got "+s);return n}function Sg(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];nf(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let i=t[n];r.set(i,s),s+=i.length}return r}var Ul=t=>typeof t=="bigint"&&tf<=t;function n_(t,e,r){return Ul(t)&&Ul(e)&&Ul(r)&&e<=t&&t<r}function Vi(t,e,r,n){if(!n_(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function s_(t){let e;for(e=0;t>tf;t>>=jg,e+=1);return e}var i_=t=>(e_<<BigInt(t-1))-jg,o_={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||rf(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function of(t,e,r={}){let n=(s,i,o)=>{let a=o_[i];if(typeof a!="function")throw new Error("invalid validator function");let c=t[s];if(!(o&&c===void 0)&&!a(c,t))throw new Error("param "+String(s)+" is invalid. Expected "+i+", got "+c)};for(let[s,i]of Object.entries(e))n(s,i,!1);for(let[s,i]of Object.entries(r))n(s,i,!0);return t}function Ig(t){let e=new WeakMap;return(r,...n)=>{let s=e.get(r);if(s!==void 0)return s;let i=t(r,...n);return e.set(r,i),i}}var Pe=BigInt(0),xe=BigInt(1),Wn=BigInt(2),a_=BigInt(3),Kl=BigInt(4),Bg=BigInt(5),Ag=BigInt(8);function Te(t,e){let r=t%e;return r>=Pe?r:e+r}function c_(t,e,r){if(e<Pe)throw new Error("invalid exponent, negatives unsupported");if(r<=Pe)throw new Error("invalid modulus");if(r===xe)return Pe;let n=xe;for(;e>Pe;)e&xe&&(n=n*t%r),t=t*t%r,e>>=xe;return n}function ir(t,e,r){let n=t;for(;e-- >Pe;)n*=n,n%=r;return n}function Tg(t,e){if(t===Pe)throw new Error("invert: expected non-zero number");if(e<=Pe)throw new Error("invert: expected positive modulus, got "+e);let r=Te(t,e),n=e,s=Pe,i=xe;for(;r!==Pe;){let o=n/r,a=n%r,c=s-i*o;n=r,r=a,s=i,i=c}if(n!==xe)throw new Error("invert: does not exist");return Te(s,e)}function u_(t){let e=(t-xe)/Wn,r,n,s;for(r=t-xe,n=0;r%Wn===Pe;r/=Wn,n++);for(s=Wn;s<t&&c_(s,e,t)!==t-xe;s++)if(s>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let o=(t+xe)/Kl;return function(a,c){let u=a.pow(c,o);if(!a.eql(a.sqr(u),c))throw new Error("Cannot find square root");return u}}let i=(r+xe)/Wn;return function(o,a){if(o.pow(a,e)===o.neg(o.ONE))throw new Error("Cannot find square root");let c=n,u=o.pow(o.mul(o.ONE,s),r),f=o.pow(a,i),l=o.pow(a,r);for(;!o.eql(l,o.ONE);){if(o.eql(l,o.ZERO))return o.ZERO;let h=1;for(let p=o.sqr(l);h<c&&!o.eql(p,o.ONE);h++)p=o.sqr(p);let d=o.pow(u,xe<<BigInt(c-h-1));u=o.sqr(d),f=o.mul(f,d),l=o.mul(l,u),c=h}return f}}function l_(t){if(t%Kl===a_){let e=(t+xe)/Kl;return function(r,n){let s=r.pow(n,e);if(!r.eql(r.sqr(s),n))throw new Error("Cannot find square root");return s}}if(t%Ag===Bg){let e=(t-Bg)/Ag;return function(r,n){let s=r.mul(n,Wn),i=r.pow(s,e),o=r.mul(n,i),a=r.mul(r.mul(o,Wn),i),c=r.mul(o,r.sub(a,r.ONE));if(!r.eql(r.sqr(c),n))throw new Error("Cannot find square root");return c}}return u_(t)}var f_=(t,e)=>(Te(t,e)&xe)===xe,h_=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function d_(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=h_.reduce((n,s)=>(n[s]="function",n),e);return of(t,r)}function p_(t,e,r){if(r<Pe)throw new Error("invalid exponent, negatives unsupported");if(r===Pe)return t.ONE;if(r===xe)return e;let n=t.ONE,s=e;for(;r>Pe;)r&xe&&(n=t.mul(n,s)),s=t.sqr(s),r>>=xe;return n}function g_(t,e){let r=new Array(e.length),n=e.reduce((i,o,a)=>t.is0(o)?i:(r[a]=i,t.mul(i,o)),t.ONE),s=t.inv(n);return e.reduceRight((i,o,a)=>t.is0(o)?i:(r[a]=t.mul(i,r[a]),t.mul(i,o)),s),r}function Yg(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Jg(t,e,r=!1,n={}){if(t<=Pe)throw new Error("invalid field: expected ORDER > 0, got "+t);let{nBitLength:s,nByteLength:i}=Yg(t,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o,a=Object.freeze({ORDER:t,isLE:r,BITS:s,BYTES:i,MASK:i_(s),ZERO:Pe,ONE:xe,create:c=>Te(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Pe<=c&&c<t},is0:c=>c===Pe,isOdd:c=>(c&xe)===xe,neg:c=>Te(-c,t),eql:(c,u)=>c===u,sqr:c=>Te(c*c,t),add:(c,u)=>Te(c+u,t),sub:(c,u)=>Te(c-u,t),mul:(c,u)=>Te(c*u,t),pow:(c,u)=>p_(a,c,u),div:(c,u)=>Te(c*Tg(u,t),t),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Tg(c,t),sqrt:n.sqrt||(c=>(o||(o=l_(t)),o(a,c))),invertBatch:c=>g_(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>r?jl(c,i):Gg(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return r?qa(c):r_(c)}});return Object.freeze(a)}var Rg=BigInt(0),ka=BigInt(1);function Ll(t,e){let r=e.negate();return t?r:e}function Xg(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function kl(t,e){Xg(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1);return{windows:r,windowSize:n}}function m_(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function y_(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var Ml=new WeakMap,Zg=new WeakMap;function ql(t){return Zg.get(t)||1}function w_(t,e){return{constTimeNegate:Ll,hasPrecomputes(r){return ql(r)!==1},unsafeLadder(r,n,s=t.ZERO){let i=r;for(;n>Rg;)n&ka&&(s=s.add(i)),i=i.double(),n>>=ka;return s},precomputeWindow(r,n){let{windows:s,windowSize:i}=kl(n,e),o=[],a=r,c=a;for(let u=0;u<s;u++){c=a,o.push(c);for(let f=1;f<i;f++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(r,n,s){let{windows:i,windowSize:o}=kl(r,e),a=t.ZERO,c=t.BASE,u=BigInt(2**r-1),f=2**r,l=BigInt(r);for(let h=0;h<i;h++){let d=h*o,p=Number(s&u);s>>=l,p>o&&(p-=f,s+=ka);let g=d,m=d+Math.abs(p)-1,b=h%2!==0,T=p<0;p===0?c=c.add(Ll(b,n[g])):a=a.add(Ll(T,n[m]))}return{p:a,f:c}},wNAFUnsafe(r,n,s,i=t.ZERO){let{windows:o,windowSize:a}=kl(r,e),c=BigInt(2**r-1),u=2**r,f=BigInt(r);for(let l=0;l<o;l++){let h=l*a;if(s===Rg)break;let d=Number(s&c);if(s>>=f,d>a&&(d-=u,s+=ka),d===0)continue;let p=n[h+Math.abs(d)-1];d<0&&(p=p.negate()),i=i.add(p)}return i},getPrecomputes(r,n,s){let i=Ml.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&Ml.set(n,s(i))),i},wNAFCached(r,n,s){let i=ql(r);return this.wNAF(i,this.getPrecomputes(i,r,s),n)},wNAFCachedUnsafe(r,n,s,i){let o=ql(r);return o===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(o,this.getPrecomputes(o,r,s),n,i)},setWindowSize(r,n){Xg(n,e),Zg.set(r,n),Ml.delete(r)}}}function x_(t,e,r,n){if(m_(r,t),y_(n,e),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let s=t.ZERO,i=s_(BigInt(r.length)),o=i>12?i-3:i>4?i-2:i?2:1,a=(1<<o)-1,c=new Array(a+1).fill(s),u=Math.floor((e.BITS-1)/o)*o,f=s;for(let l=u;l>=0;l-=o){c.fill(s);for(let d=0;d<n.length;d++){let p=n[d],g=Number(p>>BigInt(l)&BigInt(a));c[g]=c[g].add(r[d])}let h=s;for(let d=c.length-1,p=s;d>0;d--)p=p.add(c[d]),h=h.add(p);if(f=f.add(h),l!==0)for(let d=0;d<o;d++)f=f.double()}return f}function b_(t){return d_(t.Fp),of(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Yg(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var jt=BigInt(0),ht=BigInt(1),Ma=BigInt(2),E_=BigInt(8),v_={zip215:!0};function __(t){let e=b_(t);return of(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function S_(t){let e=__(t),{Fp:r,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=e,u=Ma<<BigInt(a*8)-ht,f=r.create,l=Jg(e.n,e.nBitLength),h=e.uvRatio||((y,x)=>{try{return{isValid:!0,value:r.sqrt(y*r.inv(x))}}catch{return{isValid:!1,value:jt}}}),d=e.adjustScalarBytes||(y=>y),p=e.domain||((y,x,S)=>{if(Pl("phflag",S),x.length||S)throw new Error("Contexts/pre-hash are not supported");return y});function g(y,x){Vi("coordinate "+y,x,jt,u)}function m(y){if(!(y instanceof w))throw new Error("ExtendedPoint expected")}let b=Ig((y,x)=>{let{ex:S,ey:A,ez:_}=y,D=y.is0();x==null&&(x=D?E_:r.inv(_));let U=f(S*x),q=f(A*x),z=f(_*x);if(D)return{x:jt,y:ht};if(z!==ht)throw new Error("invZ was invalid");return{x:U,y:q}}),T=Ig(y=>{let{a:x,d:S}=e;if(y.is0())throw new Error("bad point: ZERO");let{ex:A,ey:_,ez:D,et:U}=y,q=f(A*A),z=f(_*_),V=f(D*D),H=f(V*V),W=f(q*x),J=f(V*f(W+z)),ee=f(H+f(S*f(q*z)));if(J!==ee)throw new Error("bad point: equation left != right (1)");let Y=f(A*_),ne=f(D*U);if(Y!==ne)throw new Error("bad point: equation left != right (2)");return!0});class w{constructor(x,S,A,_){this.ex=x,this.ey=S,this.ez=A,this.et=_,g("x",x),g("y",S),g("z",A),g("t",_),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(x){if(x instanceof w)throw new Error("extended point not allowed");let{x:S,y:A}=x||{};return g("x",S),g("y",A),new w(S,A,ht,f(S*A))}static normalizeZ(x){let S=r.invertBatch(x.map(A=>A.ez));return x.map((A,_)=>A.toAffine(S[_])).map(w.fromAffine)}static msm(x,S){return x_(w,l,x,S)}_setWindowSize(x){C.setWindowSize(this,x)}assertValidity(){T(this)}equals(x){m(x);let{ex:S,ey:A,ez:_}=this,{ex:D,ey:U,ez:q}=x,z=f(S*q),V=f(D*_),H=f(A*q),W=f(U*_);return z===V&&H===W}is0(){return this.equals(w.ZERO)}negate(){return new w(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:x}=e,{ex:S,ey:A,ez:_}=this,D=f(S*S),U=f(A*A),q=f(Ma*f(_*_)),z=f(x*D),V=S+A,H=f(f(V*V)-D-U),W=z+U,J=W-q,ee=z-U,Y=f(H*J),ne=f(W*ee),Se=f(H*ee),je=f(J*W);return new w(Y,ne,je,Se)}add(x){m(x);let{a:S,d:A}=e,{ex:_,ey:D,ez:U,et:q}=this,{ex:z,ey:V,ez:H,et:W}=x;if(S===BigInt(-1)){let Jp=f((D-_)*(V+z)),Xp=f((D+_)*(V-z)),Gu=f(Xp-Jp);if(Gu===jt)return this.double();let Zp=f(U*Ma*W),Qp=f(q*Ma*H),e0=Qp+Zp,t0=Xp+Jp,r0=Qp-Zp,XE=f(e0*Gu),ZE=f(t0*r0),QE=f(e0*r0),ev=f(Gu*t0);return new w(XE,ZE,ev,QE)}let J=f(_*z),ee=f(D*V),Y=f(q*A*W),ne=f(U*H),Se=f((_+D)*(z+V)-J-ee),je=ne-Y,Ke=ne+Y,zt=f(ee-S*J),Vt=f(Se*je),Qo=f(Ke*zt),YE=f(Se*zt),JE=f(je*Ke);return new w(Vt,Qo,JE,YE)}subtract(x){return this.add(x.negate())}wNAF(x){return C.wNAFCached(this,x,w.normalizeZ)}multiply(x){let S=x;Vi("scalar",S,ht,n);let{p:A,f:_}=this.wNAF(S);return w.normalizeZ([A,_])[0]}multiplyUnsafe(x,S=w.ZERO){let A=x;return Vi("scalar",A,jt,n),A===jt?R:this.is0()||A===ht?this:C.wNAFCachedUnsafe(this,A,w.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return C.unsafeLadder(this,n).is0()}toAffine(x){return b(this,x)}clearCofactor(){let{h:x}=e;return x===ht?this:this.multiplyUnsafe(x)}static fromHex(x,S=!1){let{d:A,a:_}=e,D=r.BYTES;x=Ar("pointHex",x,D),Pl("zip215",S);let U=x.slice(),q=x[D-1];U[D-1]=q&-129;let z=qa(U),V=S?u:r.ORDER;Vi("pointHex.y",z,jt,V);let H=f(z*z),W=f(H-ht),J=f(A*H-_),{isValid:ee,value:Y}=h(W,J);if(!ee)throw new Error("Point.fromHex: invalid y coordinate");let ne=(Y&ht)===ht,Se=(q&128)!==0;if(!S&&Y===jt&&Se)throw new Error("Point.fromHex: x=0 and x_0=1");return Se!==ne&&(Y=f(-Y)),w.fromAffine({x:Y,y:z})}static fromPrivateKey(x){return I(x).point}toRawBytes(){let{x,y:S}=this.toAffine(),A=jl(S,r.BYTES);return A[A.length-1]|=x&ht?128:0,A}toHex(){return sf(this.toRawBytes())}}w.BASE=new w(e.Gx,e.Gy,ht,f(e.Gx*e.Gy)),w.ZERO=new w(jt,ht,ht,jt);let{BASE:v,ZERO:R}=w,C=w_(w,a*8);function O(y){return Te(y,n)}function N(y){return O(qa(y))}function I(y){let x=r.BYTES;y=Ar("private key",y,x);let S=Ar("hashed private key",i(y),2*x),A=d(S.slice(0,x)),_=S.slice(x,2*x),D=N(A),U=v.multiply(D),q=U.toRawBytes();return{head:A,prefix:_,scalar:D,point:U,pointBytes:q}}function k(y){return I(y).pointBytes}function L(y=new Uint8Array,...x){let S=Sg(...x);return N(i(p(S,Ar("context",y),!!s)))}function P(y,x,S={}){y=Ar("message",y),s&&(y=s(y));let{prefix:A,scalar:_,pointBytes:D}=I(x),U=L(S.context,A,y),q=v.multiply(U).toRawBytes(),z=L(S.context,q,D,y),V=O(U+z*_);Vi("signature.s",V,jt,n);let H=Sg(q,jl(V,r.BYTES));return Ar("result",H,r.BYTES*2)}let E=v_;function B(y,x,S,A=E){let{context:_,zip215:D}=A,U=r.BYTES;y=Ar("signature",y,2*U),x=Ar("message",x),S=Ar("publicKey",S,U),D!==void 0&&Pl("zip215",D),s&&(x=s(x));let q=qa(y.slice(U,2*U)),z,V,H;try{z=w.fromHex(S,D),V=w.fromHex(y.slice(0,U),D),H=v.multiplyUnsafe(q)}catch{return!1}if(!D&&z.isSmallOrder())return!1;let W=L(_,V.toRawBytes(),z.toRawBytes(),x);return V.add(z.multiplyUnsafe(W)).subtract(H).clearCofactor().equals(w.ZERO)}return v._setWindowSize(8),{CURVE:e,getPublicKey:k,sign:P,verify:B,ExtendedPoint:w,utils:{getExtendedPublicKey:I,randomPrivateKey:()=>o(r.BYTES),precompute(y=8,x=w.BASE){return x._setWindowSize(y),x.multiply(BigInt(3)),x}}}}BigInt(0),BigInt(1);var af=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Dg=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);var I_=BigInt(1),Og=BigInt(2);BigInt(3);var B_=BigInt(5),A_=BigInt(8);function T_(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),i=af,o=t*t%i*t%i,a=ir(o,Og,i)*o%i,c=ir(a,I_,i)*t%i,u=ir(c,B_,i)*c%i,f=ir(u,e,i)*u%i,l=ir(f,r,i)*f%i,h=ir(l,n,i)*l%i,d=ir(h,s,i)*h%i,p=ir(d,s,i)*h%i,g=ir(p,e,i)*u%i;return{pow_p_5_8:ir(g,Og,i)*t%i,b2:o}}function R_(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function D_(t,e){let r=af,n=Te(e*e*e,r),s=Te(n*n*e,r),i=T_(t*s).pow_p_5_8,o=Te(t*n*i,r),a=Te(e*o*o,r),c=o,u=Te(o*Dg,r),f=a===t,l=a===Te(-t,r),h=a===Te(-t*Dg,r);return f&&(o=c),(l||h)&&(o=u),f_(o,r)&&(o=Te(-o,r)),{isValid:f||l,value:o}}var O_=Jg(af,void 0,!0),C_={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:O_,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:A_,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Q3,randomBytes:Vg,adjustScalarBytes:R_,uvRatio:D_},Qg=S_(C_),N_="EdDSA",P_="JWT",Fa=".",za="base64url",em="utf8",tm="utf8",U_=":",L_="did",k_="key",Cg="base58btc",M_="z",q_="K36";var F_=32;function cf(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function rm(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?cf(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function nm(t,e){e||(e=t.reduce((s,i)=>s+i.length,0));let r=rm(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return cf(r)}function H_(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<t.length;s++){var i=t.charAt(s),o=i.charCodeAt(0);if(r[o]!==255)throw new TypeError(i+" is ambiguous");r[o]=s}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,m=0,b=0,T=p.length;b!==T&&p[b]===0;)b++,g++;for(var w=(T-b)*f+1>>>0,v=new Uint8Array(w);b!==T;){for(var R=p[b],C=0,O=w-1;(R!==0||C<m)&&O!==-1;O--,C++)R+=256*v[O]>>>0,v[O]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");m=C,b++}for(var N=w-m;N!==w&&v[N]===0;)N++;for(var I=c.repeat(g);N<w;++N)I+=t.charAt(v[N]);return I}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var m=0,b=0;p[g]===c;)m++,g++;for(var T=(p.length-g)*u+1>>>0,w=new Uint8Array(T);p[g];){var v=r[p.charCodeAt(g)];if(v===255)return;for(var R=0,C=T-1;(v!==0||R<b)&&C!==-1;C--,R++)v+=a*w[C]>>>0,w[C]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");b=R,g++}if(p[g]!==" "){for(var O=T-b;O!==T&&w[O]===0;)O++;for(var N=new Uint8Array(m+(T-O)),I=m;O!==T;)N[I++]=w[O++];return N}}}function d(p){var g=h(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:d}}var z_=H_,V_=z_,sm=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},$_=t=>new TextEncoder().encode(t),j_=t=>new TextDecoder().decode(t),Wl=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Gl=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return im(this,e)}},Yl=class{constructor(e){this.decoders=e}or(e){return im(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},im=(t,e)=>new Yl({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),Jl=class{constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new Wl(e,r,n),this.decoder=new Gl(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Va=({name:t,prefix:e,encode:r,decode:n})=>new Jl(t,e,r,n),$i=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:s}=V_(r,e);return Va({prefix:t,name:e,encode:n,decode:i=>sm(s(i))})},K_=(t,e,r,n)=>{let s={};for(let f=0;f<e.length;++f)s[e[f]]=f;let i=t.length;for(;t[i-1]==="=";)--i;let o=new Uint8Array(i*r/8|0),a=0,c=0,u=0;for(let f=0;f<i;++f){let l=s[t[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|l,a+=r,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},W_=(t,e,r)=>{let n=e[e.length-1]==="=",s=(1<<r)-1,i="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,i+=e[s&a>>o];if(o&&(i+=e[s&a<<r-o]),n)for(;i.length*r&7;)i+="=";return i},qe=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>Va({prefix:e,name:t,encode(s){return W_(s,n,r)},decode(s){return K_(s,n,r,t)}}),G_=Va({prefix:"\0",name:"identity",encode:t=>j_(t),decode:t=>$_(t)}),Y_=Object.freeze({__proto__:null,identity:G_}),J_=qe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1}),X_=Object.freeze({__proto__:null,base2:J_}),Z_=qe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3}),Q_=Object.freeze({__proto__:null,base8:Z_}),eS=$i({prefix:"9",name:"base10",alphabet:"0123456789"}),tS=Object.freeze({__proto__:null,base10:eS}),rS=qe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),nS=qe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4}),sS=Object.freeze({__proto__:null,base16:rS,base16upper:nS}),iS=qe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),oS=qe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),aS=qe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),cS=qe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),uS=qe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),lS=qe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),fS=qe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),hS=qe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),dS=qe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),pS=Object.freeze({__proto__:null,base32:iS,base32upper:oS,base32pad:aS,base32padupper:cS,base32hex:uS,base32hexupper:lS,base32hexpad:fS,base32hexpadupper:hS,base32z:dS}),gS=$i({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),mS=$i({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}),yS=Object.freeze({__proto__:null,base36:gS,base36upper:mS}),wS=$i({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xS=$i({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),bS=Object.freeze({__proto__:null,base58btc:wS,base58flickr:xS}),ES=qe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),vS=qe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_S=qe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),SS=qe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6}),IS=Object.freeze({__proto__:null,base64:ES,base64pad:vS,base64url:_S,base64urlpad:SS}),om=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),BS=om.reduce((t,e,r)=>(t[r]=e,t),[]),AS=om.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function TS(t){return t.reduce((e,r)=>(e+=BS[r],e),"")}function RS(t){let e=[];for(let r of t){let n=AS[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}var DS=Va({prefix:"\u{1F680}",name:"base256emoji",encode:TS,decode:RS}),OS=Object.freeze({__proto__:null,base256emoji:DS}),CS=am,Ng=128,NS=127,PS=~NS,US=Math.pow(2,31);function am(t,e,r){e=e||[],r=r||0;for(var n=r;t>=US;)e[r++]=t&255|Ng,t/=128;for(;t&PS;)e[r++]=t&255|Ng,t>>>=7;return e[r]=t|0,am.bytes=r-n+1,e}var LS=Xl,kS=128,Pg=127;function Xl(t,n){var r=0,n=n||0,s=0,i=n,o,a=t.length;do{if(i>=a)throw Xl.bytes=0,new RangeError("Could not decode varint");o=t[i++],r+=s<28?(o&Pg)<<s:(o&Pg)*Math.pow(2,s),s+=7}while(o>=kS);return Xl.bytes=i-n,r}var MS=Math.pow(2,7),qS=Math.pow(2,14),FS=Math.pow(2,21),HS=Math.pow(2,28),zS=Math.pow(2,35),VS=Math.pow(2,42),$S=Math.pow(2,49),jS=Math.pow(2,56),KS=Math.pow(2,63),WS=function(t){return t<MS?1:t<qS?2:t<FS?3:t<HS?4:t<zS?5:t<VS?6:t<$S?7:t<jS?8:t<KS?9:10},GS={encode:CS,decode:LS,encodingLength:WS},cm=GS,Ug=(t,e,r=0)=>(cm.encode(t,e,r),e),Lg=t=>cm.encodingLength(t),Zl=(t,e)=>{let r=e.byteLength,n=Lg(t),s=n+Lg(r),i=new Uint8Array(s+r);return Ug(t,i,0),Ug(r,i,n),i.set(e,s),new Ql(t,r,e,i)},Ql=class{constructor(e,r,n,s){this.code=e,this.size=r,this.digest=n,this.bytes=s}},um=({name:t,code:e,encode:r})=>new ef(t,e,r),ef=class{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?Zl(this.code,r):r.then(n=>Zl(this.code,n))}else throw Error("Unknown type, must be binary type")}},lm=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),YS=um({name:"sha2-256",code:18,encode:lm("SHA-256")}),JS=um({name:"sha2-512",code:19,encode:lm("SHA-512")}),XS=Object.freeze({__proto__:null,sha256:YS,sha512:JS}),fm=0,ZS="identity",hm=sm,QS=t=>Zl(fm,hm(t)),eI={code:fm,name:ZS,encode:hm,digest:QS},tI=Object.freeze({__proto__:null,identity:eI});new TextEncoder,new TextDecoder;var kg={...Y_,...X_,...Q_,...tS,...sS,...pS,...yS,...bS,...IS,...OS};({...XS,...tI});function dm(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Mg=dm("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Fl=dm("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=rm(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),pm={utf8:Mg,"utf-8":Mg,hex:kg.base16,latin1:Fl,ascii:Fl,binary:Fl,...kg};function $a(t,e="utf8"){let r=pm[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}function Ws(t,e="utf8"){let r=pm[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?cf(globalThis.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}function qg(t){return nr($a(Ws(t,za),em))}function Ha(t){return $a(Ws(Sr(t),em),za)}function uf(t){let e=Ws(q_,Cg),r=M_+$a(nm([e,t]),Cg);return[L_,k_,r].join(U_)}function rI(t){return $a(t,za)}function nI(t){return Ws(t,za)}function sI(t){return Ws([Ha(t.header),Ha(t.payload)].join(Fa),tm)}function iI(t){return[Ha(t.header),Ha(t.payload),rI(t.signature)].join(Fa)}function ji(t){let e=t.split(Fa),r=qg(e[0]),n=qg(e[1]),s=nI(e[2]),i=Ws(e.slice(0,2).join(Fa),tm);return{header:r,payload:n,signature:s,data:i}}function lf(t=Vg(F_)){let e=Qg.getPublicKey(t);return{secretKey:nm([t,e]),publicKey:e}}async function gm(t,e,r,n,s=(0,Fg.fromMiliseconds)(Date.now())){let i={alg:N_,typ:P_},o=uf(n.publicKey),a=s+r,c={iss:o,sub:t,aud:e,iat:s,exp:a},u=sI({header:i,payload:c}),f=Qg.sign(u,n.secretKey.slice(0,32));return iI({header:i,payload:c,signature:f})}var gf={};Ce(gf,{identity:()=>hI});function aI(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<t.length;s++){var i=t.charAt(s),o=i.charCodeAt(0);if(r[o]!==255)throw new TypeError(i+" is ambiguous");r[o]=s}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,m=0,b=0,T=p.length;b!==T&&p[b]===0;)b++,g++;for(var w=(T-b)*f+1>>>0,v=new Uint8Array(w);b!==T;){for(var R=p[b],C=0,O=w-1;(R!==0||C<m)&&O!==-1;O--,C++)R+=256*v[O]>>>0,v[O]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");m=C,b++}for(var N=w-m;N!==w&&v[N]===0;)N++;for(var I=c.repeat(g);N<w;++N)I+=t.charAt(v[N]);return I}function h(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var m=0,b=0;p[g]===c;)m++,g++;for(var T=(p.length-g)*u+1>>>0,w=new Uint8Array(T);p[g];){var v=r[p.charCodeAt(g)];if(v===255)return;for(var R=0,C=T-1;(v!==0||R<b)&&C!==-1;C--,R++)v+=a*w[C]>>>0,w[C]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");b=R,g++}if(p[g]!==" "){for(var O=T-b;O!==T&&w[O]===0;)O++;for(var N=new Uint8Array(m+(T-O)),I=m;O!==T;)N[I++]=w[O++];return N}}}function d(p){var g=h(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:d}}var cI=aI,uI=cI,mm=uI;var jD=new Uint8Array(0);var ym=(t,e)=>{if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},Tr=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};var wm=t=>new TextEncoder().encode(t),xm=t=>new TextDecoder().decode(t);var ff=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},hf=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Em(this,e)}},df=class{constructor(e){this.decoders=e}or(e){return Em(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Em=(t,e)=>new df({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),pf=class{constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new ff(e,r,n),this.decoder=new hf(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},Gs=({name:t,prefix:e,encode:r,decode:n})=>new pf(t,e,r,n),hn=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:s}=mm(r,e);return Gs({prefix:t,name:e,encode:n,decode:i=>Tr(s(i))})},lI=(t,e,r,n)=>{let s={};for(let f=0;f<e.length;++f)s[e[f]]=f;let i=t.length;for(;t[i-1]==="=";)--i;let o=new Uint8Array(i*r/8|0),a=0,c=0,u=0;for(let f=0;f<i;++f){let l=s[t[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|l,a+=r,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},fI=(t,e,r)=>{let n=e[e.length-1]==="=",s=(1<<r)-1,i="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,i+=e[s&a>>o];if(o&&(i+=e[s&a<<r-o]),n)for(;i.length*r&7;)i+="=";return i},ge=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>Gs({prefix:e,name:t,encode(s){return fI(s,n,r)},decode(s){return lI(s,n,r,t)}});var hI=Gs({prefix:"\0",name:"identity",encode:t=>xm(t),decode:t=>wm(t)});var mf={};Ce(mf,{base2:()=>dI});var dI=ge({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yf={};Ce(yf,{base8:()=>pI});var pI=ge({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wf={};Ce(wf,{base10:()=>gI});var gI=hn({prefix:"9",name:"base10",alphabet:"0123456789"});var xf={};Ce(xf,{base16:()=>mI,base16upper:()=>yI});var mI=ge({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yI=ge({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var bf={};Ce(bf,{base32:()=>Ys,base32hex:()=>EI,base32hexpad:()=>_I,base32hexpadupper:()=>SI,base32hexupper:()=>vI,base32pad:()=>xI,base32padupper:()=>bI,base32upper:()=>wI,base32z:()=>II});var Ys=ge({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),wI=ge({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),xI=ge({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),bI=ge({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),EI=ge({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vI=ge({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_I=ge({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),SI=ge({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),II=ge({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ef={};Ce(Ef,{base36:()=>BI,base36upper:()=>AI});var BI=hn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),AI=hn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var vf={};Ce(vf,{base58btc:()=>or,base58flickr:()=>TI});var or=hn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),TI=hn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _f={};Ce(_f,{base64:()=>RI,base64pad:()=>DI,base64url:()=>OI,base64urlpad:()=>CI});var RI=ge({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),DI=ge({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),OI=ge({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),CI=ge({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Sf={};Ce(Sf,{base256emoji:()=>kI});var vm=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),NI=vm.reduce((t,e,r)=>(t[r]=e,t),[]),PI=vm.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function UI(t){return t.reduce((e,r)=>(e+=NI[r],e),"")}function LI(t){let e=[];for(let r of t){let n=PI[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}var kI=Gs({prefix:"\u{1F680}",name:"base256emoji",encode:UI,decode:LI});var Tf={};Ce(Tf,{sha256:()=>r6,sha512:()=>n6});var MI=Im,_m=128,qI=127,FI=~qI,HI=Math.pow(2,31);function Im(t,e,r){e=e||[],r=r||0;for(var n=r;t>=HI;)e[r++]=t&255|_m,t/=128;for(;t&FI;)e[r++]=t&255|_m,t>>>=7;return e[r]=t|0,Im.bytes=r-n+1,e}var zI=If,VI=128,Sm=127;function If(t,n){var r=0,n=n||0,s=0,i=n,o,a=t.length;do{if(i>=a)throw If.bytes=0,new RangeError("Could not decode varint");o=t[i++],r+=s<28?(o&Sm)<<s:(o&Sm)*Math.pow(2,s),s+=7}while(o>=VI);return If.bytes=i-n,r}var $I=Math.pow(2,7),jI=Math.pow(2,14),KI=Math.pow(2,21),WI=Math.pow(2,28),GI=Math.pow(2,35),YI=Math.pow(2,42),JI=Math.pow(2,49),XI=Math.pow(2,56),ZI=Math.pow(2,63),QI=function(t){return t<$I?1:t<jI?2:t<KI?3:t<WI?4:t<GI?5:t<YI?6:t<JI?7:t<XI?8:t<ZI?9:10},e6={encode:MI,decode:zI,encodingLength:QI},t6=e6,Ki=t6;var Wi=(t,e=0)=>[Ki.decode(t,e),Ki.decode.bytes],Js=(t,e,r=0)=>(Ki.encode(t,e,r),e),Xs=t=>Ki.encodingLength(t);var Gn=(t,e)=>{let r=e.byteLength,n=Xs(t),s=n+Xs(r),i=new Uint8Array(s+r);return Js(t,i,0),Js(r,i,n),i.set(e,s),new Zs(t,r,e,i)},Bm=t=>{let e=Tr(t),[r,n]=Wi(e),[s,i]=Wi(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new Zs(r,s,o,e)},Am=(t,e)=>t===e?!0:t.code===e.code&&t.size===e.size&&ym(t.bytes,e.bytes),Zs=class{constructor(e,r,n,s){this.code=e,this.size=r,this.digest=n,this.bytes=s}};var Af=({name:t,code:e,encode:r})=>new Bf(t,e,r),Bf=class{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?Gn(this.code,r):r.then(n=>Gn(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Rm=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),r6=Af({name:"sha2-256",code:18,encode:Rm("SHA-256")}),n6=Af({name:"sha2-512",code:19,encode:Rm("SHA-512")});var Rf={};Ce(Rf,{identity:()=>o6});var Dm=0,s6="identity",Om=Tr,i6=t=>Gn(Dm,Om(t)),o6={code:Dm,name:s6,encode:Om,digest:i6};var hO=new TextEncoder,dO=new TextDecoder;var Ga=class t{constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=s,this.byteOffset=s.byteOffset,this.byteLength=s.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:Wa,byteLength:Wa,code:Ka,version:Ka,multihash:Ka,bytes:Ka,_baseCache:Wa,asCID:Wa})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:r}=this;if(e!==Yi)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==h6)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Gn(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&Am(this.multihash,e.multihash)}toString(e){let{bytes:r,version:n,_baseCache:s}=this;return n===0?l6(r,s,e||or.encoder):f6(r,s,e||Ys.encoder)}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return p6(/^0\.0/,g6),!!(e&&(e[Nm]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof t)return e;if(e!=null&&e.asCID===e){let{version:r,code:n,multihash:s,bytes:i}=e;return new t(r,n,s,i||Cm(r,n,s.bytes))}else if(e!=null&&e[Nm]===!0){let{version:r,multihash:n,code:s}=e,i=Bm(n);return t.create(r,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(r!==Yi)throw new Error(`Version 0 CID must use dag-pb (code: ${Yi}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=Cm(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Yi,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Tr(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=s.subarray(r.multihashSize-r.digestSize),o=new Zs(r.multihashCode,r.digestSize,i,s);return[r.version===0?t.createV0(o):t.createV1(r.codec,o),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Wi(e.subarray(r));return r+=h,l},s=n(),i=Yi;if(s===18?(s=0,r=0):s===1&&(i=n()),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=r,a=n(),c=n(),u=r+c,f=u-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,s]=u6(e,r),i=t.decode(s);return i._baseCache.set(n,e),i}},u6=(t,e)=>{switch(t[0]){case"Q":{let r=e||or;return[or.prefix,r.decode(`${or.prefix}${t}`)]}case or.prefix:{let r=e||or;return[or.prefix,r.decode(t)]}case Ys.prefix:{let r=e||Ys;return[Ys.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}},l6=(t,e,r)=>{let{prefix:n}=r;if(n!==or.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return s},f6=(t,e,r)=>{let{prefix:n}=r,s=e.get(n);if(s==null){let i=r.encode(t);return e.set(n,i),i}else return s},Yi=112,h6=18,Cm=(t,e,r)=>{let n=Xs(t),s=n+Xs(e),i=new Uint8Array(s+r.byteLength);return Js(t,i,0),Js(e,i,n),i.set(r,s),i},Nm=Symbol.for("@ipld/js-cid/CID"),Ka={writable:!1,configurable:!1,enumerable:!0},Wa={writable:!1,enumerable:!1,configurable:!1},d6="0.0.0-dev",p6=(t,e)=>{if(t.test(d6))console.warn(e);else throw new Error(e)},g6=`CID.isCID(v) is deprecated and will be removed in the next major release.
|
|
Following code pattern:
|
|
|
|
if (CID.isCID(value)) {
|
|
doSomethingWithCID(value)
|
|
}
|
|
|
|
Is replaced with:
|
|
|
|
const cid = CID.asCID(value)
|
|
if (cid) {
|
|
// Make sure to use cid instead of value
|
|
doSomethingWithCID(cid)
|
|
}
|
|
`;var Df={...gf,...mf,...yf,...wf,...xf,...bf,...Ef,...vf,..._f,...Sf},EO={...Tf,...Rf};function Yn(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function Ji(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Yn(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function Um(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Pm=Um("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Of=Um("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ji(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),m6={utf8:Pm,"utf-8":Pm,hex:Df.base16,latin1:Of,ascii:Of,binary:Of,...Df},Ya=m6;function Re(t,e="utf8"){let r=Ya[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Yn(globalThis.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}var Lm=function(t,e,r){if(r||arguments.length===2)for(var n=0,s=e.length,i;n<s;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))},y6=(function(){function t(e,r,n){this.name=e,this.version=r,this.os=n,this.type="browser"}return t})();var w6=(function(){function t(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return t})();var x6=(function(){function t(e,r,n,s){this.name=e,this.version=r,this.os=n,this.bot=s,this.type="bot-device"}return t})();var b6=(function(){function t(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return t})();var E6=(function(){function t(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return t})();var v6=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,_6=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,km=3,S6=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",v6]],Mm=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function Fm(t){return t?qm(t):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new E6:typeof navigator<"u"?qm(navigator.userAgent):A6()}function I6(t){return t!==""&&S6.reduce(function(e,r){var n=r[0],s=r[1];if(e)return e;var i=s.exec(t);return!!i&&[n,i]},!1)}function qm(t){var e=I6(t);if(!e)return null;var r=e[0],n=e[1];if(r==="searchbot")return new b6;var s=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);s?s.length<km&&(s=Lm(Lm([],s,!0),T6(km-s.length),!0)):s=[];var i=s.join("."),o=B6(t),a=_6.exec(t);return a&&a[1]?new x6(r,i,o,a[1]):new y6(r,i,o)}function B6(t){for(var e=0,r=Mm.length;e<r;e++){var n=Mm[e],s=n[0],i=n[1],o=i.exec(t);if(o)return s}return null}function A6(){var t=typeof process<"u"&&process.version;return t?new w6(process.version.slice(1)):null}function T6(t){for(var e=[],r=0;r<t;r++)e.push("0");return e}var Jr=Ie($s(),1),Yt=Ie(Ja(),1),Ox=Ie(zm(),1);var Za=BigInt(4294967295),Vm=BigInt(32);function Cf(t,e=!1){return e?{h:Number(t&Za),l:Number(t>>Vm&Za)}:{h:Number(t>>Vm&Za)|0,l:Number(t&Za)|0}}function Qa(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let i=0;i<r;i++){let{h:o,l:a}=Cf(t[i],e);[n[i],s[i]]=[o,a]}return[n,s]}var Nf=(t,e,r)=>t>>>r,Pf=(t,e,r)=>t<<32-r|e>>>r,ar=(t,e,r)=>t>>>r|e<<32-r,cr=(t,e,r)=>t<<32-r|e>>>r,Xn=(t,e,r)=>t<<64-r|e>>>r-32,Zn=(t,e,r)=>t>>>r-32|e<<64-r,$m=(t,e)=>e,jm=(t,e)=>t,Km=(t,e,r)=>t<<r|e>>>32-r,Wm=(t,e,r)=>e<<r|t>>>32-r,Gm=(t,e,r)=>e<<r-32|t>>>64-r,Ym=(t,e,r)=>t<<r-32|e>>>64-r;function xt(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Xi=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Zi=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Jm=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Xm=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,Zm=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),Qm=(t,e,r,n,s,i)=>e+r+n+s+i+(t/2**32|0)|0;var Qn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Dr(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function dt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function be(t,...e){if(!Dr(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function es(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");dt(t.outputLen),dt(t.blockLen)}function Ot(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function ei(t,e){be(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ts(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Ue(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function ec(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Kt(t,e){return t<<32-e|t>>>e}var ry=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ny(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}var lr=ry?t=>t:t=>ny(t);function F6(t){for(let e=0;e<t.length;e++)t[e]=ny(t[e]);return t}var fr=ry?t=>t:F6,sy=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",H6=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ct(t){if(be(t),sy)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=H6[t[r]];return e}var Rr={_0:48,_9:57,A:65,F:70,a:97,f:102};function ty(t){if(t>=Rr._0&&t<=Rr._9)return t-Rr._0;if(t>=Rr.A&&t<=Rr.F)return t-(Rr.A-10);if(t>=Rr.a&&t<=Rr.f)return t-(Rr.a-10)}function rs(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(sy)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){let o=ty(t.charCodeAt(i)),a=ty(t.charCodeAt(i+1));if(o===void 0||a===void 0){let c=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function Uf(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Ge(t){return typeof t=="string"&&(t=Uf(t)),be(t),t}function it(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];be(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let i=t[n];r.set(i,s),s+=i.length}return r}var ur=class{};function ns(t){let e=n=>t().update(Ge(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function iy(t){let e=(n,s)=>t(s).update(Ge(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}function bt(t=32){if(Qn&&typeof Qn.getRandomValues=="function")return Qn.getRandomValues(new Uint8Array(t));if(Qn&&typeof Qn.randomBytes=="function")return Uint8Array.from(Qn.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}var z6=BigInt(0),Qi=BigInt(1),V6=BigInt(2),$6=BigInt(7),j6=BigInt(256),K6=BigInt(113),cy=[],uy=[],ly=[];for(let t=0,e=Qi,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],cy.push(2*(5*n+r)),uy.push((t+1)*(t+2)/2%64);let s=z6;for(let i=0;i<7;i++)e=(e<<Qi^(e>>$6)*K6)%j6,e&V6&&(s^=Qi<<(Qi<<BigInt(i))-Qi);ly.push(s)}var fy=Qa(ly,!0),W6=fy[0],G6=fy[1],oy=(t,e,r)=>r>32?Gm(t,e,r):Km(t,e,r),ay=(t,e,r)=>r>32?Ym(t,e,r):Wm(t,e,r);function Y6(t,e=24){let r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let o=0;o<10;o++)r[o]=t[o]^t[o+10]^t[o+20]^t[o+30]^t[o+40];for(let o=0;o<10;o+=2){let a=(o+8)%10,c=(o+2)%10,u=r[c],f=r[c+1],l=oy(u,f,1)^r[a],h=ay(u,f,1)^r[a+1];for(let d=0;d<50;d+=10)t[o+d]^=l,t[o+d+1]^=h}let s=t[2],i=t[3];for(let o=0;o<24;o++){let a=uy[o],c=oy(s,i,a),u=ay(s,i,a),f=cy[o];s=t[f],i=t[f+1],t[f]=c,t[f+1]=u}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}t[0]^=W6[n],t[1]^=G6[n]}Ue(r)}var Lf=class t extends ur{constructor(e,r,n,s=!1,i=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=s,this.rounds=i,dt(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=ts(this.state)}clone(){return this._cloneInto()}keccak(){fr(this.state32),Y6(this.state32,this.rounds),fr(this.state32),this.posOut=0,this.pos=0}update(e){Ot(this),e=Ge(e),be(e);let{blockLen:r,state:n}=this,s=e.length;for(let i=0;i<s;){let o=Math.min(r-this.pos,s-i);for(let a=0;a<o;a++)n[this.pos++]^=e[i++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:r,pos:n,blockLen:s}=this;e[n]^=r,(r&128)!==0&&n===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){Ot(this,!1),be(e),this.finish();let r=this.state,{blockLen:n}=this;for(let s=0,i=e.length;s<i;){this.posOut>=n&&this.keccak();let o=Math.min(n-this.posOut,i-s);e.set(r.subarray(this.posOut,this.posOut+o),s),this.posOut+=o,s+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return dt(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(ei(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,Ue(this.state)}_cloneInto(e){let{blockLen:r,suffix:n,outputLen:s,rounds:i,enableXOF:o}=this;return e||(e=new t(r,n,s,o,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=n,e.outputLen=s,e.enableXOF=o,e.destroyed=this.destroyed,e}},J6=(t,e,r)=>ns(()=>new Lf(e,t,r));var hy=J6(1,136,256/8);var dy="0.1.1";function py(){return dy}var ie=class t extends Error{constructor(e,r={}){let n=(()=>{if(r.cause instanceof t){if(r.cause.details)return r.cause.details;if(r.cause.shortMessage)return r.cause.shortMessage}return r.cause&&"details"in r.cause&&typeof r.cause.details=="string"?r.cause.details:r.cause?.message?r.cause.message:r.details})(),s=r.cause instanceof t&&r.cause.docsPath||r.docsPath,o=`https://oxlib.sh${s??""}`,a=[e||"An error occurred.",...r.metaMessages?["",...r.metaMessages]:[],...n||s?["",n?`Details: ${n}`:void 0,s?`See: ${o}`:void 0]:[]].filter(c=>typeof c=="string").join(`
|
|
`);super(a,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:`ox@${py()}`}),this.cause=r.cause,this.details=n,this.docs=o,this.docsPath=s,this.shortMessage=e}walk(e){return gy(this,e)}};function gy(t,e){return e?.(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause?gy(t.cause,e):e?null:t}var ss=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function X6(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function is(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function hr(t,...e){if(!X6(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function my(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");is(t.outputLen),is(t.blockLen)}function Or(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function tc(t,e){hr(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function yy(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function dr(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function rc(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Wt(t,e){return t<<32-e|t>>>e}var Z6=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Q6(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function e4(t){for(let e=0;e<t.length;e++)t[e]=Q6(t[e]);return t}var kf=Z6?t=>t:e4;function t4(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function os(t){return typeof t=="string"&&(t=t4(t)),hr(t),t}function wy(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];hr(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let i=t[n];r.set(i,s),s+=i.length}return r}var dn=class{};function nc(t){let e=n=>t().update(os(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function xy(t=32){if(ss&&typeof ss.getRandomValues=="function")return ss.getRandomValues(new Uint8Array(t));if(ss&&typeof ss.randomBytes=="function")return Uint8Array.from(ss.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function r4(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(r>>s&i),a=Number(r&i),c=n?4:0,u=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+u,a,n)}function by(t,e,r){return t&e^~t&r}function Ey(t,e,r){return t&e^t&r^e&r}var sc=class extends dn{constructor(e,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=rc(this.buffer)}update(e){Or(this),e=os(e),hr(e);let{view:r,buffer:n,blockLen:s}=this,i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=rc(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Or(this),tc(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;r[o++]=128,dr(this.buffer.subarray(o)),this.padOffset>s-o&&(this.process(n,0),o=0);for(let l=o;l<s;l++)r[l]=0;r4(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=rc(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=i,e.length=s,e.pos=a,s%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Cr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ic=BigInt(4294967295),vy=BigInt(32);function n4(t,e=!1){return e?{h:Number(t&ic),l:Number(t>>vy&ic)}:{h:Number(t>>vy&ic)|0,l:Number(t&ic)|0}}function _y(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let i=0;i<r;i++){let{h:o,l:a}=n4(t[i],e);[n[i],s[i]]=[o,a]}return[n,s]}var Sy=(t,e,r)=>t<<r|e>>>32-r,Iy=(t,e,r)=>e<<r|t>>>32-r,By=(t,e,r)=>e<<r-32|t>>>64-r,Ay=(t,e,r)=>t<<r-32|e>>>64-r;var s4=BigInt(0),eo=BigInt(1),i4=BigInt(2),o4=BigInt(7),a4=BigInt(256),c4=BigInt(113),Dy=[],Oy=[],Cy=[];for(let t=0,e=eo,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],Dy.push(2*(5*n+r)),Oy.push((t+1)*(t+2)/2%64);let s=s4;for(let i=0;i<7;i++)e=(e<<eo^(e>>o4)*c4)%a4,e&i4&&(s^=eo<<(eo<<BigInt(i))-eo);Cy.push(s)}var Ny=_y(Cy,!0),u4=Ny[0],l4=Ny[1],Ty=(t,e,r)=>r>32?By(t,e,r):Sy(t,e,r),Ry=(t,e,r)=>r>32?Ay(t,e,r):Iy(t,e,r);function f4(t,e=24){let r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let o=0;o<10;o++)r[o]=t[o]^t[o+10]^t[o+20]^t[o+30]^t[o+40];for(let o=0;o<10;o+=2){let a=(o+8)%10,c=(o+2)%10,u=r[c],f=r[c+1],l=Ty(u,f,1)^r[a],h=Ry(u,f,1)^r[a+1];for(let d=0;d<50;d+=10)t[o+d]^=l,t[o+d+1]^=h}let s=t[2],i=t[3];for(let o=0;o<24;o++){let a=Oy[o],c=Ty(s,i,a),u=Ry(s,i,a),f=Dy[o];s=t[f],i=t[f+1],t[f]=c,t[f+1]=u}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}t[0]^=u4[n],t[1]^=l4[n]}dr(r)}var Mf=class t extends dn{constructor(e,r,n,s=!1,i=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=s,this.rounds=i,is(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=yy(this.state)}clone(){return this._cloneInto()}keccak(){kf(this.state32),f4(this.state32,this.rounds),kf(this.state32),this.posOut=0,this.pos=0}update(e){Or(this),e=os(e),hr(e);let{blockLen:r,state:n}=this,s=e.length;for(let i=0;i<s;){let o=Math.min(r-this.pos,s-i);for(let a=0;a<o;a++)n[this.pos++]^=e[i++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:r,pos:n,blockLen:s}=this;e[n]^=r,(r&128)!==0&&n===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){Or(this,!1),hr(e),this.finish();let r=this.state,{blockLen:n}=this;for(let s=0,i=e.length;s<i;){this.posOut>=n&&this.keccak();let o=Math.min(n-this.posOut,i-s);e.set(r.subarray(this.posOut,this.posOut+o),s),this.posOut+=o,s+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return is(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(tc(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,dr(this.state)}_cloneInto(e){let{blockLen:r,suffix:n,outputLen:s,rounds:i,enableXOF:o}=this;return e||(e=new t(r,n,s,o,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=n,e.outputLen=s,e.enableXOF=o,e.destroyed=this.destroyed,e}},h4=(t,e,r)=>nc(()=>new Mf(e,t,r));var Py=h4(1,136,256/8);var d4=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]),pn=new Uint32Array(64),qf=class extends sc{constructor(e=32){super(64,e,8,!1),this.A=Cr[0]|0,this.B=Cr[1]|0,this.C=Cr[2]|0,this.D=Cr[3]|0,this.E=Cr[4]|0,this.F=Cr[5]|0,this.G=Cr[6]|0,this.H=Cr[7]|0}get(){let{A:e,B:r,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[e,r,n,s,i,o,a,c]}set(e,r,n,s,i,o,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)pn[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=pn[l-15],d=pn[l-2],p=Wt(h,7)^Wt(h,18)^h>>>3,g=Wt(d,17)^Wt(d,19)^d>>>10;pn[l]=g+pn[l-7]+p+pn[l-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=Wt(a,6)^Wt(a,11)^Wt(a,25),d=f+h+by(a,c,u)+d4[l]+pn[l]|0,g=(Wt(n,2)^Wt(n,13)^Wt(n,22))+Ey(n,s,i)|0;f=u,u=c,c=a,a=o+d|0,o=i,i=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,i,o,a,c,u,f)}roundClean(){dr(pn)}destroy(){this.set(0,0,0,0,0,0,0,0),dr(this.buffer)}};var Uy=nc(()=>new qf);var Vf=BigInt(0),zf=BigInt(1);function ri(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function $f(t){if(!ri(t))throw new Error("Uint8Array expected")}function ni(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}function to(t){let e=t.toString(16);return e.length&1?"0"+e:e}function My(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Vf:BigInt("0x"+t)}var qy=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",p4=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function si(t){if($f(t),qy)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=p4[t[r]];return e}var Nr={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ly(t){if(t>=Nr._0&&t<=Nr._9)return t-Nr._0;if(t>=Nr.A&&t<=Nr.F)return t-(Nr.A-10);if(t>=Nr.a&&t<=Nr.f)return t-(Nr.a-10)}function ro(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(qy)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){let o=Ly(t.charCodeAt(i)),a=Ly(t.charCodeAt(i+1));if(o===void 0||a===void 0){let c=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function Pr(t){return My(si(t))}function jf(t){return $f(t),My(si(Uint8Array.from(t).reverse()))}function as(t,e){return ro(t.toString(16).padStart(e*2,"0"))}function Kf(t,e){return as(t,e).reverse()}function pt(t,e,r){let n;if(typeof e=="string")try{n=ro(e)}catch(i){throw new Error(t+" must be hex string or Uint8Array, cause: "+i)}else if(ri(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let s=n.length;if(typeof r=="number"&&s!==r)throw new Error(t+" of length "+r+" expected, got "+s);return n}function no(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];$f(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let i=t[n];r.set(i,s),s+=i.length}return r}var Ff=t=>typeof t=="bigint"&&Vf<=t;function oc(t,e,r){return Ff(t)&&Ff(e)&&Ff(r)&&e<=t&&t<r}function cs(t,e,r,n){if(!oc(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Fy(t){let e;for(e=0;t>Vf;t>>=zf,e+=1);return e}var us=t=>(zf<<BigInt(t))-zf,Hf=t=>new Uint8Array(t),ky=t=>Uint8Array.from(t);function Hy(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=Hf(t),s=Hf(t),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...l)=>r(s,n,...l),c=(l=Hf(0))=>{s=a(ky([0]),l),n=a(),l.length!==0&&(s=a(ky([1]),l),n=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,h=[];for(;l<e;){n=a();let d=n.slice();h.push(d),l+=n.length}return no(...h)};return(l,h)=>{o(),c(l);let d;for(;!(d=h(u()));)c();return o(),d}}var g4={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||ri(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function ls(t,e,r={}){let n=(s,i,o)=>{let a=g4[i];if(typeof a!="function")throw new Error("invalid validator function");let c=t[s];if(!(o&&c===void 0)&&!a(c,t))throw new Error("param "+String(s)+" is invalid. Expected "+i+", got "+c)};for(let[s,i]of Object.entries(e))n(s,i,!1);for(let[s,i]of Object.entries(r))n(s,i,!0);return t}function Wf(t){let e=new WeakMap;return(r,...n)=>{let s=e.get(r);if(s!==void 0)return s;let i=t(r,...n);return e.set(r,i),i}}function zy(t,e){if(Gf(t)>e)throw new ac({givenSize:Gf(t),maxSize:e})}var Ur={zero:48,nine:57,A:65,F:70,a:97,f:102};function Yf(t){if(t>=Ur.zero&&t<=Ur.nine)return t-Ur.zero;if(t>=Ur.A&&t<=Ur.F)return t-(Ur.A-10);if(t>=Ur.a&&t<=Ur.f)return t-(Ur.a-10)}function Vy(t,e={}){let{dir:r,size:n=32}=e;if(n===0)return t;if(t.length>n)throw new cc({size:t.length,targetSize:n,type:"Bytes"});let s=new Uint8Array(n);for(let i=0;i<n;i++){let o=r==="right";s[o?i:n-i-1]=t[o?i:t.length-i-1]}return s}function uc(t,e){if(Nt(t)>e)throw new lc({givenSize:Nt(t),maxSize:e})}function $y(t,e){if(typeof e=="number"&&e>0&&e>Nt(t)-1)throw new so({offset:e,position:"start",size:Nt(t)})}function jy(t,e,r){if(typeof e=="number"&&typeof r=="number"&&Nt(t)!==r-e)throw new so({offset:r,position:"end",size:Nt(t)})}function Jf(t,e={}){let{dir:r,size:n=32}=e;if(n===0)return t;let s=t.replace("0x","");if(s.length>n*2)throw new fc({size:Math.ceil(s.length/2),targetSize:n,type:"Hex"});return`0x${s[r==="right"?"padEnd":"padStart"](n*2,"0")}`}function Ky(t,e={}){let{dir:r="left"}=e,n=t.replace("0x",""),s=0;for(let i=0;i<n.length-1&&n[r==="left"?i:n.length-i-1].toString()==="0";i++)s++;return n=r==="left"?n.slice(s):n.slice(0,n.length-s),n==="0"?"0x":r==="right"&&n.length%2===1?`0x${n}0`:`0x${n}`}var y4="#__bigint";function gn(t,e,r){return JSON.stringify(t,(n,s)=>typeof e=="function"?e(n,s):typeof s=="bigint"?s.toString()+y4:s,r)}var w4=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function x4(t,e={}){let{strict:r=!1}=e;if(!t)throw new hc(t);if(typeof t!="string")throw new hc(t);if(r&&!/^0x[0-9a-fA-F]*$/.test(t))throw new dc(t);if(!t.startsWith("0x"))throw new dc(t)}function pc(...t){return`0x${t.reduce((e,r)=>e+r.replace("0x",""),"")}`}function pr(t){return t instanceof Uint8Array?Et(t):Array.isArray(t)?Et(new Uint8Array(t)):t}function Et(t,e={}){let r="";for(let s=0;s<t.length;s++)r+=w4[t[s]];let n=`0x${r}`;return typeof e.size=="number"?(uc(n,e.size),Zf(n,e.size)):n}function vt(t,e={}){let{signed:r,size:n}=e,s=BigInt(t),i;n?r?i=(1n<<BigInt(n)*8n-1n)-1n:i=2n**(BigInt(n)*8n)-1n:typeof t=="number"&&(i=BigInt(Number.MAX_SAFE_INTEGER));let o=typeof i=="bigint"&&r?-i-1n:0;if(i&&s>i||s<o){let u=typeof t=="bigint"?"n":"";throw new Xf({max:i?`${i}${u}`:void 0,min:`${o}${u}`,signed:r,size:n,value:`${t}${u}`})}let c=`0x${(r&&s<0?(1n<<BigInt(n*8))+BigInt(s):s).toString(16)}`;return n?b4(c,n):c}function b4(t,e){return Jf(t,{dir:"left",size:e})}function Zf(t,e){return Jf(t,{dir:"right",size:e})}function Gt(t,e,r,n={}){let{strict:s}=n;$y(t,e);let i=`0x${t.replace("0x","").slice((e??0)*2,(r??t.length)*2)}`;return s&&jy(i,e,r),i}function Nt(t){return Math.ceil((t.length-2)/2)}function Qf(t){return Ky(t,{dir:"left"})}function eh(t,e={}){let{strict:r=!1}=e;try{return x4(t,{strict:r}),!0}catch{return!1}}var Xf=class extends ie{constructor({max:e,min:r,signed:n,size:s,value:i}){super(`Number \`${i}\` is not in safe${s?` ${s*8}-bit`:""}${n?" signed":" unsigned"} integer range ${e?`(\`${r}\` to \`${e}\`)`:`(above \`${r}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}};var hc=class extends ie{constructor(e){super(`Value \`${typeof e=="object"?gn(e):e}\` of type \`${typeof e}\` is an invalid hex type.`,{metaMessages:['Hex types must be represented as `"0x${string}"`.']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexTypeError"})}},dc=class extends ie{constructor(e){super(`Value \`${e}\` is an invalid hex value.`,{metaMessages:['Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexValueError"})}};var lc=class extends ie{constructor({givenSize:e,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}},so=class extends ie{constructor({offset:e,position:r,size:n}){super(`Slice ${r==="start"?"starting":"ending"} at offset \`${e}\` is out-of-bounds (size: \`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SliceOffsetOutOfBoundsError"})}},fc=class extends ie{constructor({size:e,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}};var E4=new TextEncoder;function v4(t){if(!(t instanceof Uint8Array)){if(!t)throw new ii(t);if(typeof t!="object")throw new ii(t);if(!("BYTES_PER_ELEMENT"in t))throw new ii(t);if(t.BYTES_PER_ELEMENT!==1||t.constructor.name!=="Uint8Array")throw new ii(t)}}function oi(t){return t instanceof Uint8Array?t:typeof t=="string"?oo(t):_4(t)}function _4(t){return t instanceof Uint8Array?t:new Uint8Array(t)}function oo(t,e={}){let{size:r}=e,n=t;r&&(uc(t,r),n=Zf(t,r));let s=n.slice(2);s.length%2&&(s=`0${s}`);let i=s.length/2,o=new Uint8Array(i);for(let a=0,c=0;a<i;a++){let u=Yf(s.charCodeAt(c++)),f=Yf(s.charCodeAt(c++));if(u===void 0||f===void 0)throw new ie(`Invalid byte sequence ("${s[c-2]}${s[c-1]}" in "${s}").`);o[a]=u*16+f}return o}function Gy(t,e={}){let{size:r}=e,n=E4.encode(t);return typeof r=="number"?(zy(n,r),S4(n,r)):n}function S4(t,e){return Vy(t,{dir:"right",size:e})}function Gf(t){return t.length}function Yy(t){try{return v4(t),!0}catch{return!1}}var ii=class extends ie{constructor(e){super(`Value \`${typeof e=="object"?gn(e):e}\` of type \`${typeof e}\` is an invalid Bytes value.`,{metaMessages:["Bytes values must be of type `Bytes`."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.InvalidBytesTypeError"})}},ac=class extends ie{constructor({givenSize:e,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}};var cc=class extends ie{constructor({size:e,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}};function th(t,e={}){let{as:r=typeof t=="string"?"Hex":"Bytes"}=e,n=Py(oi(t));return r==="Bytes"?n:Et(n)}var gc=class extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){let r=super.get(e);return super.has(e)&&r!==void 0&&(this.delete(e),super.set(e,r)),r}set(e,r){if(super.set(e,r),this.maxSize&&this.size>this.maxSize){let n=this.keys().next().value;n&&this.delete(n)}return this}};var I4={checksum:new gc(8192)},mc=I4.checksum;function Zy(t,e={}){let{compressed:r}=e,{prefix:n,x:s,y:i}=t;if(r===!1||typeof s=="bigint"&&typeof i=="bigint"){if(n!==4)throw new yc({prefix:n,cause:new sh});return}if(r===!0||typeof s=="bigint"&&typeof i>"u"){if(n!==3&&n!==2)throw new yc({prefix:n,cause:new nh});return}throw new rh({publicKey:t})}function oh(t){let e=(()=>{if(eh(t))return Qy(t);if(Yy(t))return B4(t);let{prefix:r,x:n,y:s}=t;return typeof n=="bigint"&&typeof s=="bigint"?{prefix:r??4,x:n,y:s}:{prefix:r,x:n}})();return Zy(e),e}function B4(t){return Qy(Et(t))}function Qy(t){if(t.length!==132&&t.length!==130&&t.length!==68)throw new ih({publicKey:t});if(t.length===130){let n=BigInt(Gt(t,0,32)),s=BigInt(Gt(t,32,64));return{prefix:4,x:n,y:s}}if(t.length===132){let n=Number(Gt(t,0,1)),s=BigInt(Gt(t,1,33)),i=BigInt(Gt(t,33,65));return{prefix:n,x:s,y:i}}let e=Number(Gt(t,0,1)),r=BigInt(Gt(t,1,33));return{prefix:e,x:r}}function ew(t,e={}){return oo(ao(t,e))}function ao(t,e={}){Zy(t);let{prefix:r,x:n,y:s}=t,{includePrefix:i=!0}=e;return pc(i?vt(r,{size:1}):"0x",vt(n,{size:32}),typeof s=="bigint"?vt(s,{size:32}):"0x")}var rh=class extends ie{constructor({publicKey:e}){super(`Value \`${gn(e)}\` is not a valid public key.`,{metaMessages:["Public key must contain:","- an `x` and `prefix` value (compressed)","- an `x`, `y`, and `prefix` value (uncompressed)"]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidError"})}},yc=class extends ie{constructor({prefix:e,cause:r}){super(`Prefix "${e}" is invalid.`,{cause:r}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidPrefixError"})}},nh=class extends ie{constructor(){super("Prefix must be 2 or 3 for compressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidCompressedPrefixError"})}},sh=class extends ie{constructor(){super("Prefix must be 4 for uncompressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidUncompressedPrefixError"})}},ih=class extends ie{constructor({publicKey:e}){super(`Value \`${e}\` is an invalid public key size.`,{metaMessages:["Expected: 33 bytes (compressed + prefix), 64 bytes (uncompressed) or 65 bytes (uncompressed + prefix).",`Received ${Nt(pr(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidSerializedSizeError"})}};var A4=/^0x[a-fA-F0-9]{40}$/;function wc(t,e={}){let{strict:r=!0}=e;if(!A4.test(t))throw new xc({address:t,cause:new ch});if(r){if(t.toLowerCase()===t)return;if(tw(t)!==t)throw new xc({address:t,cause:new uh})}}function tw(t){if(mc.has(t))return mc.get(t);wc(t,{strict:!1});let e=t.substring(2).toLowerCase(),r=th(Gy(e),{as:"Bytes"}),n=e.split("");for(let i=0;i<40;i+=2)r[i>>1]>>4>=8&&n[i]&&(n[i]=n[i].toUpperCase()),(r[i>>1]&15)>=8&&n[i+1]&&(n[i+1]=n[i+1].toUpperCase());let s=`0x${n.join("")}`;return mc.set(t,s),s}function T4(t,e={}){let{checksum:r=!1}=e;return wc(t),r?tw(t):t}function rw(t,e={}){let r=th(`0x${ao(t).slice(4)}`).substring(26);return T4(`0x${r}`,e)}function nw(t,e){return wc(t,{strict:!1}),wc(e,{strict:!1}),t.toLowerCase()===e.toLowerCase()}var xc=class extends ie{constructor({address:e,cause:r}){super(`Address "${e}" is invalid.`,{cause:r}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}},ch=class extends ie{constructor(){super("Address is not a 20 byte (40 hexadecimal character) value."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidInputError"})}},uh=class extends ie{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}};var wC=2n**(8n-1n)-1n,xC=2n**(16n-1n)-1n,bC=2n**(24n-1n)-1n,EC=2n**(32n-1n)-1n,vC=2n**(40n-1n)-1n,_C=2n**(48n-1n)-1n,SC=2n**(56n-1n)-1n,IC=2n**(64n-1n)-1n,BC=2n**(72n-1n)-1n,AC=2n**(80n-1n)-1n,TC=2n**(88n-1n)-1n,RC=2n**(96n-1n)-1n,DC=2n**(104n-1n)-1n,OC=2n**(112n-1n)-1n,CC=2n**(120n-1n)-1n,NC=2n**(128n-1n)-1n,PC=2n**(136n-1n)-1n,UC=2n**(144n-1n)-1n,LC=2n**(152n-1n)-1n,kC=2n**(160n-1n)-1n,MC=2n**(168n-1n)-1n,qC=2n**(176n-1n)-1n,FC=2n**(184n-1n)-1n,HC=2n**(192n-1n)-1n,zC=2n**(200n-1n)-1n,VC=2n**(208n-1n)-1n,$C=2n**(216n-1n)-1n,jC=2n**(224n-1n)-1n,KC=2n**(232n-1n)-1n,WC=2n**(240n-1n)-1n,GC=2n**(248n-1n)-1n,YC=2n**(256n-1n)-1n,JC=-(2n**(8n-1n)),XC=-(2n**(16n-1n)),ZC=-(2n**(24n-1n)),QC=-(2n**(32n-1n)),eN=-(2n**(40n-1n)),tN=-(2n**(48n-1n)),rN=-(2n**(56n-1n)),nN=-(2n**(64n-1n)),sN=-(2n**(72n-1n)),iN=-(2n**(80n-1n)),oN=-(2n**(88n-1n)),aN=-(2n**(96n-1n)),cN=-(2n**(104n-1n)),uN=-(2n**(112n-1n)),lN=-(2n**(120n-1n)),fN=-(2n**(128n-1n)),hN=-(2n**(136n-1n)),dN=-(2n**(144n-1n)),pN=-(2n**(152n-1n)),gN=-(2n**(160n-1n)),mN=-(2n**(168n-1n)),yN=-(2n**(176n-1n)),wN=-(2n**(184n-1n)),xN=-(2n**(192n-1n)),bN=-(2n**(200n-1n)),EN=-(2n**(208n-1n)),vN=-(2n**(216n-1n)),_N=-(2n**(224n-1n)),SN=-(2n**(232n-1n)),IN=-(2n**(240n-1n)),BN=-(2n**(248n-1n)),AN=-(2n**(256n-1n)),TN=2n**8n-1n,RN=2n**16n-1n,DN=2n**24n-1n,ON=2n**32n-1n,CN=2n**40n-1n,NN=2n**48n-1n,PN=2n**56n-1n,UN=2n**64n-1n,LN=2n**72n-1n,kN=2n**80n-1n,MN=2n**88n-1n,qN=2n**96n-1n,FN=2n**104n-1n,HN=2n**112n-1n,zN=2n**120n-1n,VN=2n**128n-1n,$N=2n**136n-1n,jN=2n**144n-1n,KN=2n**152n-1n,WN=2n**160n-1n,GN=2n**168n-1n,YN=2n**176n-1n,JN=2n**184n-1n,XN=2n**192n-1n,ZN=2n**200n-1n,QN=2n**208n-1n,eP=2n**216n-1n,tP=2n**224n-1n,rP=2n**232n-1n,nP=2n**240n-1n,sP=2n**248n-1n,lh=2n**256n-1n;var Tc={};Ce(Tc,{InvalidRError:()=>_c,InvalidSError:()=>Sc,InvalidSerializedSizeError:()=>vc,InvalidVError:()=>Ic,InvalidYParityError:()=>ps,MissingPropertiesError:()=>ai,assert:()=>Bc,extract:()=>j4,from:()=>Th,fromBytes:()=>Iw,fromDerBytes:()=>K4,fromDerHex:()=>Bw,fromHex:()=>Ah,fromLegacy:()=>Aw,fromRpc:()=>Tw,fromTuple:()=>W4,toBytes:()=>G4,toDerBytes:()=>Y4,toDerHex:()=>J4,toHex:()=>Rw,toLegacy:()=>X4,toRpc:()=>Z4,toTuple:()=>Q4,vToYParity:()=>Ac,validate:()=>eB,yParityToV:()=>Rh});var bc=class extends dn{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,my(e);let n=os(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?e.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),dr(i)}update(e){return Or(this),this.iHash.update(e),this}digestInto(e){Or(this),hr(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},fh=(t,e,r)=>new bc(t,e).update(r).digest();fh.create=(t,e)=>new bc(t,e);var ot=BigInt(0),Je=BigInt(1),ds=BigInt(2),R4=BigInt(3),aw=BigInt(4),cw=BigInt(5),uw=BigInt(8);function Ye(t,e){let r=t%e;return r>=ot?r:e+r}function _t(t,e,r){let n=t;for(;e-- >ot;)n*=n,n%=r;return n}function Ec(t,e){if(t===ot)throw new Error("invert: expected non-zero number");if(e<=ot)throw new Error("invert: expected positive modulus, got "+e);let r=Ye(t,e),n=e,s=ot,i=Je,o=Je,a=ot;for(;r!==ot;){let u=n/r,f=n%r,l=s-o*u,h=i-a*u;n=r,r=f,s=o,i=a,o=l,a=h}if(n!==Je)throw new Error("invert: does not exist");return Ye(s,e)}function lw(t,e){let r=(t.ORDER+Je)/aw,n=t.pow(e,r);if(!t.eql(t.sqr(n),e))throw new Error("Cannot find square root");return n}function D4(t,e){let r=(t.ORDER-cw)/uw,n=t.mul(e,ds),s=t.pow(n,r),i=t.mul(e,s),o=t.mul(t.mul(i,ds),s),a=t.mul(i,t.sub(o,t.ONE));if(!t.eql(t.sqr(a),e))throw new Error("Cannot find square root");return a}function O4(t){if(t<BigInt(3))throw new Error("sqrt is not defined for small field");let e=t-Je,r=0;for(;e%ds===ot;)e/=ds,r++;let n=ds,s=co(t);for(;ow(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return lw;let i=s.pow(n,e),o=(e+Je)/ds;return function(c,u){if(c.is0(u))return u;if(ow(c,u)!==1)throw new Error("Cannot find square root");let f=r,l=c.mul(c.ONE,i),h=c.pow(u,e),d=c.pow(u,o);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let p=1,g=c.sqr(h);for(;!c.eql(g,c.ONE);)if(p++,g=c.sqr(g),p===f)throw new Error("Cannot find square root");let m=Je<<BigInt(f-p-1),b=c.pow(l,m);f=p,l=c.sqr(b),h=c.mul(h,l),d=c.mul(d,b)}return d}}function C4(t){return t%aw===R4?lw:t%uw===cw?D4:O4(t)}var N4=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function hh(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=N4.reduce((n,s)=>(n[s]="function",n),e);return ls(t,r)}function P4(t,e,r){if(r<ot)throw new Error("invalid exponent, negatives unsupported");if(r===ot)return t.ONE;if(r===Je)return e;let n=t.ONE,s=e;for(;r>ot;)r&Je&&(n=t.mul(n,s)),s=t.sqr(s),r>>=Je;return n}function dh(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),s=e.reduce((o,a,c)=>t.is0(a)?o:(n[c]=o,t.mul(o,a)),t.ONE),i=t.inv(s);return e.reduceRight((o,a,c)=>t.is0(a)?o:(n[c]=t.mul(o,n[c]),t.mul(o,a)),i),n}function ow(t,e){let r=(t.ORDER-Je)/ds,n=t.pow(e,r),s=t.eql(n,t.ONE),i=t.eql(n,t.ZERO),o=t.eql(n,t.neg(t.ONE));if(!s&&!i&&!o)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ph(t,e){e!==void 0&&is(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function co(t,e,r=!1,n={}){if(t<=ot)throw new Error("invalid field: expected ORDER > 0, got "+t);let{nBitLength:s,nByteLength:i}=ph(t,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o,a=Object.freeze({ORDER:t,isLE:r,BITS:s,BYTES:i,MASK:us(s),ZERO:ot,ONE:Je,create:c=>Ye(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return ot<=c&&c<t},is0:c=>c===ot,isOdd:c=>(c&Je)===Je,neg:c=>Ye(-c,t),eql:(c,u)=>c===u,sqr:c=>Ye(c*c,t),add:(c,u)=>Ye(c+u,t),sub:(c,u)=>Ye(c-u,t),mul:(c,u)=>Ye(c*u,t),pow:(c,u)=>P4(a,c,u),div:(c,u)=>Ye(c*Ec(u,t),t),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Ec(c,t),sqrt:n.sqrt||(c=>(o||(o=C4(t)),o(a,c))),toBytes:c=>r?Kf(c,i):as(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return r?jf(c):Pr(c)},invertBatch:c=>dh(a,c),cmov:(c,u,f)=>f?u:c});return Object.freeze(a)}function fw(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function gh(t){let e=fw(t);return e+Math.ceil(e/2)}function hw(t,e,r=!1){let n=t.length,s=fw(e),i=gh(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=r?jf(t):Pr(t),a=Ye(o,e-Je)+Je;return r?Kf(a,s):as(a,s)}var dw=BigInt(0),bh=BigInt(1);function mh(t,e){let r=e.negate();return t?r:e}function gw(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function yh(t,e){gw(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),s=2**t,i=us(t),o=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:s,shiftBy:o}}function pw(t,e,r){let{windowSize:n,mask:s,maxNumber:i,shiftBy:o}=r,a=Number(t&s),c=t>>o;a>n&&(a-=i,c+=bh);let u=e*n,f=u+Math.abs(a)-1,l=a===0,h=a<0,d=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}}function U4(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function L4(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var wh=new WeakMap,mw=new WeakMap;function xh(t){return mw.get(t)||1}function yw(t,e){return{constTimeNegate:mh,hasPrecomputes(r){return xh(r)!==1},unsafeLadder(r,n,s=t.ZERO){let i=r;for(;n>dw;)n&bh&&(s=s.add(i)),i=i.double(),n>>=bh;return s},precomputeWindow(r,n){let{windows:s,windowSize:i}=yh(n,e),o=[],a=r,c=a;for(let u=0;u<s;u++){c=a,o.push(c);for(let f=1;f<i;f++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(r,n,s){let i=t.ZERO,o=t.BASE,a=yh(r,e);for(let c=0;c<a.windows;c++){let{nextN:u,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:p}=pw(s,c,a);s=u,l?o=o.add(mh(d,n[p])):i=i.add(mh(h,n[f]))}return{p:i,f:o}},wNAFUnsafe(r,n,s,i=t.ZERO){let o=yh(r,e);for(let a=0;a<o.windows&&s!==dw;a++){let{nextN:c,offset:u,isZero:f,isNeg:l}=pw(s,a,o);if(s=c,!f){let h=n[u];i=i.add(l?h.negate():h)}}return i},getPrecomputes(r,n,s){let i=wh.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&wh.set(n,s(i))),i},wNAFCached(r,n,s){let i=xh(r);return this.wNAF(i,this.getPrecomputes(i,r,s),n)},wNAFCachedUnsafe(r,n,s,i){let o=xh(r);return o===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(o,this.getPrecomputes(o,r,s),n,i)},setWindowSize(r,n){gw(n,e),mw.set(r,n),wh.delete(r)}}}function ww(t,e,r,n){U4(r,t),L4(n,e);let s=r.length,i=n.length;if(s!==i)throw new Error("arrays of points and scalars must have equal length");let o=t.ZERO,a=Fy(BigInt(s)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=us(c),f=new Array(Number(u)+1).fill(o),l=Math.floor((e.BITS-1)/c)*c,h=o;for(let d=l;d>=0;d-=c){f.fill(o);for(let g=0;g<i;g++){let m=n[g],b=Number(m>>BigInt(d)&u);f[b]=f[b].add(r[g])}let p=o;for(let g=f.length-1,m=o;g>0;g--)m=m.add(f[g]),p=p.add(m);if(h=h.add(p),d!==0)for(let g=0;g<c;g++)h=h.double()}return h}function Eh(t){return hh(t.Fp),ls(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ph(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function xw(t){t.lowS!==void 0&&ni("lowS",t.lowS),t.prehash!==void 0&&ni("prehash",t.prehash)}function k4(t){let e=Eh(t);ls(e,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:r,Fp:n,a:s}=e;if(r){if(!n.eql(s,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...e})}var Sh=class extends Error{constructor(e=""){super(e)}},Lr={Err:Sh,_tlv:{encode:(t,e)=>{let{Err:r}=Lr;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=to(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?to(s.length/2|128):"";return to(t)+i+s+e},decode(t,e){let{Err:r}=Lr,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)o=o<<8|f;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(t){let{Err:e}=Lr;if(t<kr)throw new e("integer: negative integers are not allowed");let r=to(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Lr;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Pr(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Lr,s=pt("signature",t),{v:i,l:o}=n.decode(48,s);if(o.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Lr,n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),i=n+s;return e.encode(48,i)}};function vh(t,e){return si(as(t,e))}var kr=BigInt(0),Le=BigInt(1),mP=BigInt(2),_h=BigInt(3),M4=BigInt(4);function q4(t){let e=k4(t),{Fp:r}=e,n=co(e.n,e.nBitLength),s=e.toBytes||((w,v,R)=>{let C=v.toAffine();return no(Uint8Array.from([4]),r.toBytes(C.x),r.toBytes(C.y))}),i=e.fromBytes||(w=>{let v=w.subarray(1),R=r.fromBytes(v.subarray(0,r.BYTES)),C=r.fromBytes(v.subarray(r.BYTES,2*r.BYTES));return{x:R,y:C}});function o(w){let{a:v,b:R}=e,C=r.sqr(w),O=r.mul(C,w);return r.add(r.add(O,r.mul(w,v)),R)}function a(w,v){let R=r.sqr(v),C=o(w);return r.eql(R,C)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let c=r.mul(r.pow(e.a,_h),M4),u=r.mul(r.sqr(e.b),BigInt(27));if(r.is0(r.add(c,u)))throw new Error("bad curve params: a or b");function f(w){return oc(w,Le,e.n)}function l(w){let{allowedPrivateKeyLengths:v,nByteLength:R,wrapPrivateKey:C,n:O}=e;if(v&&typeof w!="bigint"){if(ri(w)&&(w=si(w)),typeof w!="string"||!v.includes(w.length))throw new Error("invalid private key");w=w.padStart(R*2,"0")}let N;try{N=typeof w=="bigint"?w:Pr(pt("private key",w,R))}catch{throw new Error("invalid private key, expected hex or "+R+" bytes, got "+typeof w)}return C&&(N=Ye(N,O)),cs("private key",N,Le,O),N}function h(w){if(!(w instanceof g))throw new Error("ProjectivePoint expected")}let d=Wf((w,v)=>{let{px:R,py:C,pz:O}=w;if(r.eql(O,r.ONE))return{x:R,y:C};let N=w.is0();v==null&&(v=N?r.ONE:r.inv(O));let I=r.mul(R,v),k=r.mul(C,v),L=r.mul(O,v);if(N)return{x:r.ZERO,y:r.ZERO};if(!r.eql(L,r.ONE))throw new Error("invZ was invalid");return{x:I,y:k}}),p=Wf(w=>{if(w.is0()){if(e.allowInfinityPoint&&!r.is0(w.py))return;throw new Error("bad point: ZERO")}let{x:v,y:R}=w.toAffine();if(!r.isValid(v)||!r.isValid(R))throw new Error("bad point: x or y not FE");if(!a(v,R))throw new Error("bad point: equation left != right");if(!w.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class g{constructor(v,R,C){if(v==null||!r.isValid(v))throw new Error("x required");if(R==null||!r.isValid(R)||r.is0(R))throw new Error("y required");if(C==null||!r.isValid(C))throw new Error("z required");this.px=v,this.py=R,this.pz=C,Object.freeze(this)}static fromAffine(v){let{x:R,y:C}=v||{};if(!v||!r.isValid(R)||!r.isValid(C))throw new Error("invalid affine point");if(v instanceof g)throw new Error("projective point not allowed");let O=N=>r.eql(N,r.ZERO);return O(R)&&O(C)?g.ZERO:new g(R,C,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(v){let R=dh(r,v.map(C=>C.pz));return v.map((C,O)=>C.toAffine(R[O])).map(g.fromAffine)}static fromHex(v){let R=g.fromAffine(i(pt("pointHex",v)));return R.assertValidity(),R}static fromPrivateKey(v){return g.BASE.multiply(l(v))}static msm(v,R){return ww(g,n,v,R)}_setWindowSize(v){T.setWindowSize(this,v)}assertValidity(){p(this)}hasEvenY(){let{y:v}=this.toAffine();if(r.isOdd)return!r.isOdd(v);throw new Error("Field doesn't support isOdd")}equals(v){h(v);let{px:R,py:C,pz:O}=this,{px:N,py:I,pz:k}=v,L=r.eql(r.mul(R,k),r.mul(N,O)),P=r.eql(r.mul(C,k),r.mul(I,O));return L&&P}negate(){return new g(this.px,r.neg(this.py),this.pz)}double(){let{a:v,b:R}=e,C=r.mul(R,_h),{px:O,py:N,pz:I}=this,k=r.ZERO,L=r.ZERO,P=r.ZERO,E=r.mul(O,O),B=r.mul(N,N),y=r.mul(I,I),x=r.mul(O,N);return x=r.add(x,x),P=r.mul(O,I),P=r.add(P,P),k=r.mul(v,P),L=r.mul(C,y),L=r.add(k,L),k=r.sub(B,L),L=r.add(B,L),L=r.mul(k,L),k=r.mul(x,k),P=r.mul(C,P),y=r.mul(v,y),x=r.sub(E,y),x=r.mul(v,x),x=r.add(x,P),P=r.add(E,E),E=r.add(P,E),E=r.add(E,y),E=r.mul(E,x),L=r.add(L,E),y=r.mul(N,I),y=r.add(y,y),E=r.mul(y,x),k=r.sub(k,E),P=r.mul(y,B),P=r.add(P,P),P=r.add(P,P),new g(k,L,P)}add(v){h(v);let{px:R,py:C,pz:O}=this,{px:N,py:I,pz:k}=v,L=r.ZERO,P=r.ZERO,E=r.ZERO,B=e.a,y=r.mul(e.b,_h),x=r.mul(R,N),S=r.mul(C,I),A=r.mul(O,k),_=r.add(R,C),D=r.add(N,I);_=r.mul(_,D),D=r.add(x,S),_=r.sub(_,D),D=r.add(R,O);let U=r.add(N,k);return D=r.mul(D,U),U=r.add(x,A),D=r.sub(D,U),U=r.add(C,O),L=r.add(I,k),U=r.mul(U,L),L=r.add(S,A),U=r.sub(U,L),E=r.mul(B,D),L=r.mul(y,A),E=r.add(L,E),L=r.sub(S,E),E=r.add(S,E),P=r.mul(L,E),S=r.add(x,x),S=r.add(S,x),A=r.mul(B,A),D=r.mul(y,D),S=r.add(S,A),A=r.sub(x,A),A=r.mul(B,A),D=r.add(D,A),x=r.mul(S,D),P=r.add(P,x),x=r.mul(U,D),L=r.mul(_,L),L=r.sub(L,x),x=r.mul(_,S),E=r.mul(U,E),E=r.add(E,x),new g(L,P,E)}subtract(v){return this.add(v.negate())}is0(){return this.equals(g.ZERO)}wNAF(v){return T.wNAFCached(this,v,g.normalizeZ)}multiplyUnsafe(v){let{endo:R,n:C}=e;cs("scalar",v,kr,C);let O=g.ZERO;if(v===kr)return O;if(this.is0()||v===Le)return this;if(!R||T.hasPrecomputes(this))return T.wNAFCachedUnsafe(this,v,g.normalizeZ);let{k1neg:N,k1:I,k2neg:k,k2:L}=R.splitScalar(v),P=O,E=O,B=this;for(;I>kr||L>kr;)I&Le&&(P=P.add(B)),L&Le&&(E=E.add(B)),B=B.double(),I>>=Le,L>>=Le;return N&&(P=P.negate()),k&&(E=E.negate()),E=new g(r.mul(E.px,R.beta),E.py,E.pz),P.add(E)}multiply(v){let{endo:R,n:C}=e;cs("scalar",v,Le,C);let O,N;if(R){let{k1neg:I,k1:k,k2neg:L,k2:P}=R.splitScalar(v),{p:E,f:B}=this.wNAF(k),{p:y,f:x}=this.wNAF(P);E=T.constTimeNegate(I,E),y=T.constTimeNegate(L,y),y=new g(r.mul(y.px,R.beta),y.py,y.pz),O=E.add(y),N=B.add(x)}else{let{p:I,f:k}=this.wNAF(v);O=I,N=k}return g.normalizeZ([O,N])[0]}multiplyAndAddUnsafe(v,R,C){let O=g.BASE,N=(k,L)=>L===kr||L===Le||!k.equals(O)?k.multiplyUnsafe(L):k.multiply(L),I=N(this,R).add(N(v,C));return I.is0()?void 0:I}toAffine(v){return d(this,v)}isTorsionFree(){let{h:v,isTorsionFree:R}=e;if(v===Le)return!0;if(R)return R(g,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:v,clearCofactor:R}=e;return v===Le?this:R?R(g,this):this.multiplyUnsafe(e.h)}toRawBytes(v=!0){return ni("isCompressed",v),this.assertValidity(),s(g,this,v)}toHex(v=!0){return ni("isCompressed",v),si(this.toRawBytes(v))}}g.BASE=new g(e.Gx,e.Gy,r.ONE),g.ZERO=new g(r.ZERO,r.ONE,r.ZERO);let{endo:m,nBitLength:b}=e,T=yw(g,m?Math.ceil(b/2):b);return{CURVE:e,ProjectivePoint:g,normPrivateKeyToScalar:l,weierstrassEquation:o,isWithinCurveOrder:f}}function F4(t){let e=Eh(t);return ls(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function bw(t){let e=F4(t),{Fp:r,n,nByteLength:s,nBitLength:i}=e,o=r.BYTES+1,a=2*r.BYTES+1;function c(y){return Ye(y,n)}function u(y){return Ec(y,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:l,weierstrassEquation:h,isWithinCurveOrder:d}=q4({...e,toBytes(y,x,S){let A=x.toAffine(),_=r.toBytes(A.x),D=no;return ni("isCompressed",S),S?D(Uint8Array.from([x.hasEvenY()?2:3]),_):D(Uint8Array.from([4]),_,r.toBytes(A.y))},fromBytes(y){let x=y.length,S=y[0],A=y.subarray(1);if(x===o&&(S===2||S===3)){let _=Pr(A);if(!oc(_,Le,r.ORDER))throw new Error("Point is not on curve");let D=h(_),U;try{U=r.sqrt(D)}catch(V){let H=V instanceof Error?": "+V.message:"";throw new Error("Point is not on curve"+H)}let q=(U&Le)===Le;return(S&1)===1!==q&&(U=r.neg(U)),{x:_,y:U}}else if(x===a&&S===4){let _=r.fromBytes(A.subarray(0,r.BYTES)),D=r.fromBytes(A.subarray(r.BYTES,2*r.BYTES));return{x:_,y:D}}else{let _=o,D=a;throw new Error("invalid Point, expected length of "+_+", or uncompressed "+D+", got "+x)}}});function p(y){let x=n>>Le;return y>x}function g(y){return p(y)?c(-y):y}let m=(y,x,S)=>Pr(y.slice(x,S));class b{constructor(x,S,A){cs("r",x,Le,n),cs("s",S,Le,n),this.r=x,this.s=S,A!=null&&(this.recovery=A),Object.freeze(this)}static fromCompact(x){let S=s;return x=pt("compactSignature",x,S*2),new b(m(x,0,S),m(x,S,2*S))}static fromDER(x){let{r:S,s:A}=Lr.toSig(pt("DER",x));return new b(S,A)}assertValidity(){}addRecoveryBit(x){return new b(this.r,this.s,x)}recoverPublicKey(x){let{r:S,s:A,recovery:_}=this,D=O(pt("msgHash",x));if(_==null||![0,1,2,3].includes(_))throw new Error("recovery id invalid");let U=_===2||_===3?S+e.n:S;if(U>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let q=(_&1)===0?"02":"03",z=f.fromHex(q+vh(U,r.BYTES)),V=u(U),H=c(-D*V),W=c(A*V),J=f.BASE.multiplyAndAddUnsafe(z,H,W);if(!J)throw new Error("point at infinify");return J.assertValidity(),J}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return ro(this.toDERHex())}toDERHex(){return Lr.hexFromSig(this)}toCompactRawBytes(){return ro(this.toCompactHex())}toCompactHex(){let x=s;return vh(this.r,x)+vh(this.s,x)}}let T={isValidPrivateKey(y){try{return l(y),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let y=gh(e.n);return hw(e.randomBytes(y),e.n)},precompute(y=8,x=f.BASE){return x._setWindowSize(y),x.multiply(BigInt(3)),x}};function w(y,x=!0){return f.fromPrivateKey(y).toRawBytes(x)}function v(y){if(typeof y=="bigint")return!1;if(y instanceof f)return!0;let S=pt("key",y).length,A=r.BYTES,_=A+1,D=2*A+1;if(!(e.allowedPrivateKeyLengths||s===_))return S===_||S===D}function R(y,x,S=!0){if(v(y)===!0)throw new Error("first arg must be private key");if(v(x)===!1)throw new Error("second arg must be public key");return f.fromHex(x).multiply(l(y)).toRawBytes(S)}let C=e.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let x=Pr(y),S=y.length*8-i;return S>0?x>>BigInt(S):x},O=e.bits2int_modN||function(y){return c(C(y))},N=us(i);function I(y){return cs("num < 2^"+i,y,kr,N),as(y,s)}function k(y,x,S=L){if(["recovered","canonical"].some(Y=>Y in S))throw new Error("sign() legacy options not supported");let{hash:A,randomBytes:_}=e,{lowS:D,prehash:U,extraEntropy:q}=S;D==null&&(D=!0),y=pt("msgHash",y),xw(S),U&&(y=pt("prehashed msgHash",A(y)));let z=O(y),V=l(x),H=[I(V),I(z)];if(q!=null&&q!==!1){let Y=q===!0?_(r.BYTES):q;H.push(pt("extraEntropy",Y))}let W=no(...H),J=z;function ee(Y){let ne=C(Y);if(!d(ne))return;let Se=u(ne),je=f.BASE.multiply(ne).toAffine(),Ke=c(je.x);if(Ke===kr)return;let zt=c(Se*c(J+Ke*V));if(zt===kr)return;let Vt=(je.x===Ke?0:2)|Number(je.y&Le),Qo=zt;return D&&p(zt)&&(Qo=g(zt),Vt^=1),new b(Ke,Qo,Vt)}return{seed:W,k2sig:ee}}let L={lowS:e.lowS,prehash:!1},P={lowS:e.lowS,prehash:!1};function E(y,x,S=L){let{seed:A,k2sig:_}=k(y,x,S),D=e;return Hy(D.hash.outputLen,D.nByteLength,D.hmac)(A,_)}f.BASE._setWindowSize(8);function B(y,x,S,A=P){let _=y;x=pt("msgHash",x),S=pt("publicKey",S);let{lowS:D,prehash:U,format:q}=A;if(xw(A),"strict"in A)throw new Error("options.strict was renamed to lowS");if(q!==void 0&&q!=="compact"&&q!=="der")throw new Error("format must be compact or der");let z=typeof _=="string"||ri(_),V=!z&&!q&&typeof _=="object"&&_!==null&&typeof _.r=="bigint"&&typeof _.s=="bigint";if(!z&&!V)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let H,W;try{if(V&&(H=new b(_.r,_.s)),z){try{q!=="compact"&&(H=b.fromDER(_))}catch(Vt){if(!(Vt instanceof Lr.Err))throw Vt}!H&&q!=="der"&&(H=b.fromCompact(_))}W=f.fromHex(S)}catch{return!1}if(!H||D&&H.hasHighS())return!1;U&&(x=e.hash(x));let{r:J,s:ee}=H,Y=O(x),ne=u(ee),Se=c(Y*ne),je=c(J*ne),Ke=f.BASE.multiplyAndAddUnsafe(W,Se,je)?.toAffine();return Ke?c(Ke.x)===J:!1}return{CURVE:e,getPublicKey:w,getSharedSecret:R,sign:E,verify:B,ProjectivePoint:f,Signature:b,utils:T}}function H4(t){return{hash:t,hmac:(e,...r)=>fh(t,e,wy(...r)),randomBytes:xy}}function Ew(t,e){let r=n=>bw({...t,...H4(n)});return{...r(e),create:r}}var Sw=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),vw=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),z4=BigInt(0),V4=BigInt(1),Ih=BigInt(2),_w=(t,e)=>(t+e/Ih)/e;function $4(t){let e=Sw,r=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=_t(f,r,e)*f%e,h=_t(l,r,e)*f%e,d=_t(h,Ih,e)*u%e,p=_t(d,s,e)*d%e,g=_t(p,i,e)*p%e,m=_t(g,a,e)*g%e,b=_t(m,c,e)*m%e,T=_t(b,a,e)*g%e,w=_t(T,r,e)*f%e,v=_t(w,o,e)*p%e,R=_t(v,n,e)*u%e,C=_t(R,Ih,e);if(!Bh.eql(Bh.sqr(C),t))throw new Error("Cannot find square root");return C}var Bh=co(Sw,void 0,void 0,{sqrt:$4}),St=Ew({a:z4,b:BigInt(7),Fp:Bh,n:vw,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=vw,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-V4*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,o=BigInt("0x100000000000000000000000000000000"),a=_w(i*t,e),c=_w(-n*t,e),u=Ye(t-a*r-c*s,e),f=Ye(-a*n-c*i,e),l=u>o,h=f>o;if(l&&(u=e-u),h&&(f=e-f),u>o||f>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:l,k1:u,k2neg:h,k2:f}}}},Uy);function Bc(t,e={}){let{recovered:r}=e;if(typeof t.r>"u")throw new ai({signature:t});if(typeof t.s>"u")throw new ai({signature:t});if(r&&typeof t.yParity>"u")throw new ai({signature:t});if(t.r<0n||t.r>lh)throw new _c({value:t.r});if(t.s<0n||t.s>lh)throw new Sc({value:t.s});if(typeof t.yParity=="number"&&t.yParity!==0&&t.yParity!==1)throw new ps({value:t.yParity})}function Iw(t){return Ah(Et(t))}function Ah(t){if(t.length!==130&&t.length!==132)throw new vc({signature:t});let e=BigInt(Gt(t,0,32)),r=BigInt(Gt(t,32,64)),n=(()=>{let s=+`0x${t.slice(130)}`;if(!Number.isNaN(s))try{return Ac(s)}catch{throw new ps({value:s})}})();return typeof n>"u"?{r:e,s:r}:{r:e,s:r,yParity:n}}function j4(t){if(!(typeof t.r>"u")&&!(typeof t.s>"u"))return Th(t)}function Th(t){let e=typeof t=="string"?Ah(t):t instanceof Uint8Array?Iw(t):typeof t.r=="string"?Tw(t):t.v?Aw(t):{r:t.r,s:t.s,...typeof t.yParity<"u"?{yParity:t.yParity}:{}};return Bc(e),e}function K4(t){return Bw(Et(t))}function Bw(t){let{r:e,s:r}=St.Signature.fromDER(pr(t).slice(2));return{r:e,s:r}}function Aw(t){return{r:t.r,s:t.s,yParity:Ac(t.v)}}function Tw(t){let e=(()=>{let r=t.v?Number(t.v):void 0,n=t.yParity?Number(t.yParity):void 0;if(typeof r=="number"&&typeof n!="number"&&(n=Ac(r)),typeof n!="number")throw new ps({value:t.yParity});return n})();return{r:BigInt(t.r),s:BigInt(t.s),yParity:e}}function W4(t){let[e,r,n]=t;return Th({r:r==="0x"?0n:BigInt(r),s:n==="0x"?0n:BigInt(n),yParity:e==="0x"?0:Number(e)})}function G4(t){return oo(Rw(t))}function Rw(t){Bc(t);let e=t.r,r=t.s;return pc(vt(e,{size:32}),vt(r,{size:32}),typeof t.yParity=="number"?vt(Rh(t.yParity),{size:1}):"0x")}function Y4(t){return new St.Signature(t.r,t.s).toDERRawBytes()}function J4(t){return`0x${new St.Signature(t.r,t.s).toDERHex()}`}function X4(t){return{r:t.r,s:t.s,v:Rh(t.yParity)}}function Z4(t){let{r:e,s:r,yParity:n}=t;return{r:vt(e,{size:32}),s:vt(r,{size:32}),yParity:n===0?"0x0":"0x1"}}function Q4(t){let{r:e,s:r,yParity:n}=t;return[n?"0x01":"0x",e===0n?"0x":Qf(vt(e)),r===0n?"0x":Qf(vt(r))]}function eB(t,e={}){try{return Bc(t,e),!0}catch{return!1}}function Ac(t){if(t===0||t===27)return 0;if(t===1||t===28)return 1;if(t>=35)return t%2===0?1:0;throw new Ic({value:t})}function Rh(t){if(t===0)return 27;if(t===1)return 28;throw new ps({value:t})}var vc=class extends ie{constructor({signature:e}){super(`Value \`${e}\` is an invalid signature size.`,{metaMessages:["Expected: 64 bytes or 65 bytes.",`Received ${Nt(pr(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSerializedSizeError"})}},ai=class extends ie{constructor({signature:e}){super(`Signature \`${gn(e)}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.MissingPropertiesError"})}},_c=class extends ie{constructor({value:e}){super(`Value \`${e}\` is an invalid r value. r must be a positive integer less than 2^256.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidRError"})}},Sc=class extends ie{constructor({value:e}){super(`Value \`${e}\` is an invalid s value. s must be a positive integer less than 2^256.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSError"})}},ps=class extends ie{constructor({value:e}){super(`Value \`${e}\` is an invalid y-parity value. Y-parity must be 0 or 1.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidYParityError"})}},Ic=class extends ie{constructor({value:e}){super(`Value \`${e}\` is an invalid v value. v must be 27, 28 or >=35.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidVError"})}};function Cw(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Nw(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function Rc(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function uo(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Dc(t){if(!Array.isArray(t))throw new Error("array expected")}function Oc(t,e){if(!Nw(!0,e))throw new Error(`${t}: array of strings expected`)}function Pw(t,e){if(!Nw(!1,e))throw new Error(`${t}: array of numbers expected`)}function Uw(...t){let e=i=>i,r=(i,o)=>a=>i(o(a)),n=t.map(i=>i.encode).reduceRight(r,e),s=t.map(i=>i.decode).reduce(r,e);return{encode:n,decode:s}}function Lw(t){let e=typeof t=="string"?t.split(""):t,r=e.length;Oc("alphabet",e);let n=new Map(e.map((s,i)=>[s,i]));return{encode:s=>(Dc(s),s.map(i=>{if(!Number.isSafeInteger(i)||i<0||i>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${t}`);return e[i]})),decode:s=>(Dc(s),s.map(i=>{Rc("alphabet.decode",i);let o=n.get(i);if(o===void 0)throw new Error(`Unknown letter: "${i}". Allowed: ${t}`);return o}))}}function kw(t=""){return Rc("join",t),{encode:e=>(Oc("join.decode",e),e.join(t)),decode:e=>(Rc("join.decode",e),e.split(t))}}function tB(t,e="="){return uo(t),Rc("padding",e),{encode(r){for(Oc("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){Oc("padding.decode",r);let n=r.length;if(n*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===e;n--)if((n-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}function Dw(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(Dc(t),!t.length)return[];let n=0,s=[],i=Array.from(t,a=>{if(uo(a),a<0||a>=e)throw new Error(`invalid integer: ${a}`);return a}),o=i.length;for(;;){let a=0,c=!0;for(let u=n;u<o;u++){let f=i[u],l=e*a,h=l+f;if(!Number.isSafeInteger(h)||l/e!==a||h-f!==l)throw new Error("convertRadix: carry overflow");let d=h/r;a=h%r;let p=Math.floor(d);if(i[u]=p,!Number.isSafeInteger(p)||p*r+a!==h)throw new Error("convertRadix: carry overflow");if(c)p?c=!1:n=u;else continue}if(s.push(a),c)break}for(let a=0;a<t.length-1&&t[a]===0;a++)s.push(0);return s.reverse()}var Mw=(t,e)=>e===0?t:Mw(e,t%e),Cc=(t,e)=>t+(e-Mw(t,e)),Dh=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Ow(t,e,r,n){if(Dc(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Cc(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Cc(e,r)}`);let s=0,i=0,o=Dh[e],a=Dh[r]-1,c=[];for(let u of t){if(uo(u),u>=o)throw new Error(`convertRadix2: invalid data word=${u} from=${e}`);if(s=s<<e|u,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=r;i-=r)c.push((s>>i-r&a)>>>0);let f=Dh[i];if(f===void 0)throw new Error("invalid carry");s&=f-1}if(s=s<<r-i&a,!n&&i>=e)throw new Error("Excess padding");if(!n&&s>0)throw new Error(`Non-zero padding: ${s}`);return n&&i>0&&c.push(s>>>0),c}function rB(t){uo(t);let e=2**8;return{encode:r=>{if(!Cw(r))throw new Error("radix.encode input should be Uint8Array");return Dw(Array.from(r),e,t)},decode:r=>(Pw("radix.decode",r),Uint8Array.from(Dw(r,t,e)))}}function nB(t,e=!1){if(uo(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Cc(8,t)>32||Cc(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Cw(r))throw new Error("radix2.encode input should be Uint8Array");return Ow(Array.from(r),8,t,!e)},decode:r=>(Pw("radix2.decode",r),Uint8Array.from(Ow(r,t,8,e)))}}var qw=Uw(nB(5),Lw("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),tB(5),kw(""));var sB=t=>Uw(rB(58),Lw(t),kw("")),ci=sB("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var Nc={};Ce(Nc,{createKeyPair:()=>aB,getPublicKey:()=>Hw,getSharedSecret:()=>cB,noble:()=>oB,randomPrivateKey:()=>zw,recoverAddress:()=>Vw,recoverPublicKey:()=>$w,sign:()=>uB,verify:()=>lB});var Fw=!1;var oB=St;function aB(t={}){let{as:e="Hex"}=t,r=zw({as:e}),n=Hw({privateKey:r});return{privateKey:r,publicKey:n}}function Hw(t){let{privateKey:e}=t,r=St.ProjectivePoint.fromPrivateKey(pr(e).slice(2));return oh(r)}function cB(t){let{as:e="Hex",privateKey:r,publicKey:n}=t,o=St.ProjectivePoint.fromHex(ao(n).slice(2)).multiply(St.utils.normPrivateKeyToScalar(pr(r).slice(2))).toRawBytes(!0);return e==="Hex"?Et(o):o}function zw(t={}){let{as:e="Hex"}=t,r=St.utils.randomPrivateKey();return e==="Hex"?Et(r):r}function Vw(t){return rw($w(t))}function $w(t){let{payload:e,signature:r}=t,{r:n,s,yParity:i}=r,a=new St.Signature(BigInt(n),BigInt(s)).addRecoveryBit(i).recoverPublicKey(pr(e).substring(2));return oh(a)}function uB(t){let{extraEntropy:e=Fw,hash:r,payload:n,privateKey:s}=t,{r:i,s:o,recovery:a}=St.sign(oi(n),oi(s),{extraEntropy:typeof e=="boolean"?e:pr(e).slice(2),lowS:!0,...r?{prehash:!0}:{}});return{r:i,s:o,yParity:a}}function lB(t){let{address:e,hash:r,payload:n,publicKey:s,signature:i}=t;return e?nw(e,Vw({payload:n,signature:i})):St.verify(i,oi(n),ew(s),...r?[{prehash:!0,lowS:!0}]:[])}function Kw(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Pc(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function Uc(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Xe(t,...e){if(!Kw(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Oh(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Ww(t,e){Xe(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Mr(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function qr(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function fB(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var hB=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function dB(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Lc(t){if(typeof t=="string")t=dB(t);else if(Kw(t))t=kc(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function Gw(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function Yw(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}var Ch=(t,e)=>{function r(n,...s){if(Xe(n),!hB)throw new Error("Non little-endian hardware is not yet supported");if(t.nonceLength!==void 0){let f=s[0];if(!f)throw new Error("nonce / iv required");t.varSizeNonce?Xe(f):Xe(f,t.nonceLength)}let i=t.tagLength;i&&s[1]!==void 0&&Xe(s[1]);let o=e(n,...s),a=(f,l)=>{if(l!==void 0){if(f!==2)throw new Error("cipher output not supported");Xe(l)}},c=!1;return{encrypt(f,l){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Xe(f),a(o.encrypt.length,l),o.encrypt(f,l)},decrypt(f,l){if(Xe(f),i&&f.length<i)throw new Error("invalid ciphertext length: smaller than tagLength="+i);return a(o.decrypt.length,l),o.decrypt(f,l)}}}return Object.assign(r,t),r};function Nh(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(e.length!==t)throw new Error("invalid output length, expected "+t+", got: "+e.length);if(r&&!pB(e))throw new Error("invalid output, must be aligned");return e}function jw(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(r>>s&i),a=Number(r&i),c=n?4:0,u=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+u,a,n)}function Jw(t,e,r){Pc(r);let n=new Uint8Array(16),s=fB(n);return jw(s,0,BigInt(e),r),jw(s,8,BigInt(t),r),n}function pB(t){return t.byteOffset%4===0}function kc(t){return Uint8Array.from(t)}function gB(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(r>>s&i),a=Number(r&i),c=n?4:0,u=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+u,a,n)}function Xw(t,e,r){return t&e^~t&r}function Zw(t,e,r){return t&e^t&r^e&r}var lo=class extends ur{constructor(e,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=ec(this.buffer)}update(e){Ot(this),e=Ge(e),be(e);let{view:r,buffer:n,blockLen:s}=this,i=e.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=ec(e);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ot(this),ei(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;r[o++]=128,Ue(this.buffer.subarray(o)),this.padOffset>s-o&&(this.process(n,0),o=0);for(let l=o;l<s;l++)r[l]=0;gB(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=ec(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:i,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=i,e.length=s,e.pos=a,s%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Fr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Fe=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),He=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var mB=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]),mn=new Uint32Array(64),Mc=class extends lo{constructor(e=32){super(64,e,8,!1),this.A=Fr[0]|0,this.B=Fr[1]|0,this.C=Fr[2]|0,this.D=Fr[3]|0,this.E=Fr[4]|0,this.F=Fr[5]|0,this.G=Fr[6]|0,this.H=Fr[7]|0}get(){let{A:e,B:r,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[e,r,n,s,i,o,a,c]}set(e,r,n,s,i,o,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)mn[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=mn[l-15],d=mn[l-2],p=Kt(h,7)^Kt(h,18)^h>>>3,g=Kt(d,17)^Kt(d,19)^d>>>10;mn[l]=g+mn[l-7]+p+mn[l-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=Kt(a,6)^Kt(a,11)^Kt(a,25),d=f+h+Xw(a,c,u)+mB[l]+mn[l]|0,g=(Kt(n,2)^Kt(n,13)^Kt(n,22))+Zw(n,s,i)|0;f=u,u=c,c=a,a=o+d|0,o=i,i=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,i,o,a,c,u,f)}roundClean(){Ue(mn)}destroy(){this.set(0,0,0,0,0,0,0,0),Ue(this.buffer)}};var Qw=Qa(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),yB=Qw[0],wB=Qw[1],yn=new Uint32Array(80),wn=new Uint32Array(80),fo=class extends lo{constructor(e=64){super(128,e,16,!1),this.Ah=He[0]|0,this.Al=He[1]|0,this.Bh=He[2]|0,this.Bl=He[3]|0,this.Ch=He[4]|0,this.Cl=He[5]|0,this.Dh=He[6]|0,this.Dl=He[7]|0,this.Eh=He[8]|0,this.El=He[9]|0,this.Fh=He[10]|0,this.Fl=He[11]|0,this.Gh=He[12]|0,this.Gl=He[13]|0,this.Hh=He[14]|0,this.Hl=He[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:d,Gl:p,Hh:g,Hl:m}=this;return[e,r,n,s,i,o,a,c,u,f,l,h,d,p,g,m]}set(e,r,n,s,i,o,a,c,u,f,l,h,d,p,g,m){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=p|0,this.Hh=g|0,this.Hl=m|0}process(e,r){for(let w=0;w<16;w++,r+=4)yn[w]=e.getUint32(r),wn[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let v=yn[w-15]|0,R=wn[w-15]|0,C=ar(v,R,1)^ar(v,R,8)^Nf(v,R,7),O=cr(v,R,1)^cr(v,R,8)^Pf(v,R,7),N=yn[w-2]|0,I=wn[w-2]|0,k=ar(N,I,19)^Xn(N,I,61)^Nf(N,I,6),L=cr(N,I,19)^Zn(N,I,61)^Pf(N,I,6),P=Jm(O,L,wn[w-7],wn[w-16]),E=Xm(P,C,k,yn[w-7],yn[w-16]);yn[w]=E|0,wn[w]=P|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:p,Gh:g,Gl:m,Hh:b,Hl:T}=this;for(let w=0;w<80;w++){let v=ar(l,h,14)^ar(l,h,18)^Xn(l,h,41),R=cr(l,h,14)^cr(l,h,18)^Zn(l,h,41),C=l&d^~l&g,O=h&p^~h&m,N=Zm(T,R,O,wB[w],wn[w]),I=Qm(N,b,v,C,yB[w],yn[w]),k=N|0,L=ar(n,s,28)^Xn(n,s,34)^Xn(n,s,39),P=cr(n,s,28)^Zn(n,s,34)^Zn(n,s,39),E=n&i^n&a^i&a,B=s&o^s&c^o&c;b=g|0,T=m|0,g=d|0,m=p|0,d=l|0,p=h|0,{h:l,l:h}=xt(u|0,f|0,I|0,k|0),u=a|0,f=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let y=Xi(k,P,B);n=Zi(y,I,L,E),s=y|0}({h:n,l:s}=xt(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=xt(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=xt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=xt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=xt(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:p}=xt(this.Fh|0,this.Fl|0,d|0,p|0),{h:g,l:m}=xt(this.Gh|0,this.Gl|0,g|0,m|0),{h:b,l:T}=xt(this.Hh|0,this.Hl|0,b|0,T|0),this.set(n,s,i,o,a,c,u,f,l,h,d,p,g,m,b,T)}roundClean(){Ue(yn,wn)}destroy(){Ue(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ph=class extends fo{constructor(){super(48),this.Ah=Fe[0]|0,this.Al=Fe[1]|0,this.Bh=Fe[2]|0,this.Bl=Fe[3]|0,this.Ch=Fe[4]|0,this.Cl=Fe[5]|0,this.Dh=Fe[6]|0,this.Dl=Fe[7]|0,this.Eh=Fe[8]|0,this.El=Fe[9]|0,this.Fh=Fe[10]|0,this.Fl=Fe[11]|0,this.Gh=Fe[12]|0,this.Gl=Fe[13]|0,this.Hh=Fe[14]|0,this.Hl=Fe[15]|0}};var Ze=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);var Uh=class extends fo{constructor(){super(32),this.Ah=Ze[0]|0,this.Al=Ze[1]|0,this.Bh=Ze[2]|0,this.Bl=Ze[3]|0,this.Ch=Ze[4]|0,this.Cl=Ze[5]|0,this.Dh=Ze[6]|0,this.Dl=Ze[7]|0,this.Eh=Ze[8]|0,this.El=Ze[9]|0,this.Fh=Ze[10]|0,this.Fl=Ze[11]|0,this.Gh=Ze[12]|0,this.Gl=Ze[13]|0,this.Hh=Ze[14]|0,this.Hl=Ze[15]|0}},gs=ns(()=>new Mc);var qc=ns(()=>new fo),e1=ns(()=>new Ph),t1=ns(()=>new Uh);var r1=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]);var De=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),$=new Uint32Array(32);function xn(t,e,r,n,s,i){let o=s[i],a=s[i+1],c=$[2*t],u=$[2*t+1],f=$[2*e],l=$[2*e+1],h=$[2*r],d=$[2*r+1],p=$[2*n],g=$[2*n+1],m=Xi(c,f,o);u=Zi(m,u,l,a),c=m|0,{Dh:g,Dl:p}={Dh:g^u,Dl:p^c},{Dh:g,Dl:p}={Dh:$m(g,p),Dl:jm(g,p)},{h:d,l:h}=xt(d,h,g,p),{Bh:l,Bl:f}={Bh:l^d,Bl:f^h},{Bh:l,Bl:f}={Bh:ar(l,f,24),Bl:cr(l,f,24)},$[2*t]=c,$[2*t+1]=u,$[2*e]=f,$[2*e+1]=l,$[2*r]=h,$[2*r+1]=d,$[2*n]=p,$[2*n+1]=g}function bn(t,e,r,n,s,i){let o=s[i],a=s[i+1],c=$[2*t],u=$[2*t+1],f=$[2*e],l=$[2*e+1],h=$[2*r],d=$[2*r+1],p=$[2*n],g=$[2*n+1],m=Xi(c,f,o);u=Zi(m,u,l,a),c=m|0,{Dh:g,Dl:p}={Dh:g^u,Dl:p^c},{Dh:g,Dl:p}={Dh:ar(g,p,16),Dl:cr(g,p,16)},{h:d,l:h}=xt(d,h,g,p),{Bh:l,Bl:f}={Bh:l^d,Bl:f^h},{Bh:l,Bl:f}={Bh:Xn(l,f,63),Bl:Zn(l,f,63)},$[2*t]=c,$[2*t+1]=u,$[2*e]=f,$[2*e+1]=l,$[2*r]=h,$[2*r+1]=d,$[2*n]=p,$[2*n+1]=g}function xB(t,e={},r,n,s){if(dt(r),t<0||t>r)throw new Error("outputLen bigger than keyLen");let{key:i,salt:o,personalization:a}=e;if(i!==void 0&&(i.length<1||i.length>r))throw new Error("key length must be undefined or 1.."+r);if(o!==void 0&&o.length!==n)throw new Error("salt must be undefined or "+n);if(a!==void 0&&a.length!==s)throw new Error("personalization must be undefined or "+s)}var Lh=class extends ur{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,dt(e),dt(r),this.blockLen=e,this.outputLen=r,this.buffer=new Uint8Array(e),this.buffer32=ts(this.buffer)}update(e){Ot(this),e=Ge(e),be(e);let{blockLen:r,buffer:n,buffer32:s}=this,i=e.length,o=e.byteOffset,a=e.buffer;for(let c=0;c<i;){this.pos===r&&(fr(s),this.compress(s,0,!1),fr(s),this.pos=0);let u=Math.min(r-this.pos,i-c),f=o+c;if(u===r&&!(f%4)&&c+u<i){let l=new Uint32Array(a,f,Math.floor((i-c)/4));fr(l);for(let h=0;c+r<i;h+=s.length,c+=r)this.length+=r,this.compress(l,h,!1);fr(l);continue}n.set(e.subarray(c,c+u),this.pos),this.pos+=u,this.length+=u,c+=u}return this}digestInto(e){Ot(this),ei(e,this);let{pos:r,buffer32:n}=this;this.finished=!0,Ue(this.buffer.subarray(r)),fr(n),this.compress(n,0,!0),fr(n);let s=ts(e);this.get().forEach((i,o)=>s[o]=lr(i))}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){let{buffer:r,length:n,finished:s,destroyed:i,outputLen:o,pos:a}=this;return e||(e=new this.constructor({dkLen:o})),e.set(...this.get()),e.buffer.set(r),e.destroyed=i,e.finished=s,e.length=n,e.pos=a,e.outputLen=o,e}clone(){return this._cloneInto()}},kh=class extends Lh{constructor(e={}){let r=e.dkLen===void 0?64:e.dkLen;super(128,r),this.v0l=De[0]|0,this.v0h=De[1]|0,this.v1l=De[2]|0,this.v1h=De[3]|0,this.v2l=De[4]|0,this.v2h=De[5]|0,this.v3l=De[6]|0,this.v3h=De[7]|0,this.v4l=De[8]|0,this.v4h=De[9]|0,this.v5l=De[10]|0,this.v5h=De[11]|0,this.v6l=De[12]|0,this.v6h=De[13]|0,this.v7l=De[14]|0,this.v7h=De[15]|0,xB(r,e,64,16,16);let{key:n,personalization:s,salt:i}=e,o=0;if(n!==void 0&&(n=Ge(n),o=n.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,i!==void 0){i=Ge(i);let a=ts(i);this.v4l^=lr(a[0]),this.v4h^=lr(a[1]),this.v5l^=lr(a[2]),this.v5h^=lr(a[3])}if(s!==void 0){s=Ge(s);let a=ts(s);this.v6l^=lr(a[0]),this.v6h^=lr(a[1]),this.v7l^=lr(a[2]),this.v7h^=lr(a[3])}if(n!==void 0){let a=new Uint8Array(this.blockLen);a.set(n),this.update(a)}}get(){let{v0l:e,v0h:r,v1l:n,v1h:s,v2l:i,v2h:o,v3l:a,v3h:c,v4l:u,v4h:f,v5l:l,v5h:h,v6l:d,v6h:p,v7l:g,v7h:m}=this;return[e,r,n,s,i,o,a,c,u,f,l,h,d,p,g,m]}set(e,r,n,s,i,o,a,c,u,f,l,h,d,p,g,m){this.v0l=e|0,this.v0h=r|0,this.v1l=n|0,this.v1h=s|0,this.v2l=i|0,this.v2h=o|0,this.v3l=a|0,this.v3h=c|0,this.v4l=u|0,this.v4h=f|0,this.v5l=l|0,this.v5h=h|0,this.v6l=d|0,this.v6h=p|0,this.v7l=g|0,this.v7h=m|0}compress(e,r,n){this.get().forEach((c,u)=>$[u]=c),$.set(De,16);let{h:s,l:i}=Cf(BigInt(this.length));$[24]=De[8]^i,$[25]=De[9]^s,n&&($[28]=~$[28],$[29]=~$[29]);let o=0,a=r1;for(let c=0;c<12;c++)xn(0,4,8,12,e,r+2*a[o++]),bn(0,4,8,12,e,r+2*a[o++]),xn(1,5,9,13,e,r+2*a[o++]),bn(1,5,9,13,e,r+2*a[o++]),xn(2,6,10,14,e,r+2*a[o++]),bn(2,6,10,14,e,r+2*a[o++]),xn(3,7,11,15,e,r+2*a[o++]),bn(3,7,11,15,e,r+2*a[o++]),xn(0,5,10,15,e,r+2*a[o++]),bn(0,5,10,15,e,r+2*a[o++]),xn(1,6,11,12,e,r+2*a[o++]),bn(1,6,11,12,e,r+2*a[o++]),xn(2,7,8,13,e,r+2*a[o++]),bn(2,7,8,13,e,r+2*a[o++]),xn(3,4,9,14,e,r+2*a[o++]),bn(3,4,9,14,e,r+2*a[o++]);this.v0l^=$[0]^$[16],this.v0h^=$[1]^$[17],this.v1l^=$[2]^$[18],this.v1h^=$[3]^$[19],this.v2l^=$[4]^$[20],this.v2h^=$[5]^$[21],this.v3l^=$[6]^$[22],this.v3h^=$[7]^$[23],this.v4l^=$[8]^$[24],this.v4h^=$[9]^$[25],this.v5l^=$[10]^$[26],this.v5h^=$[11]^$[27],this.v6l^=$[12]^$[28],this.v6h^=$[13]^$[29],this.v7l^=$[14]^$[30],this.v7h^=$[15]^$[31],Ue($)}destroy(){this.destroyed=!0,Ue(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},n1=iy(t=>new kh(t));function s1(t){let e=t.length,r=0,n=0;for(;n<e;){let s=t.charCodeAt(n++);if((s&4294967168)===0){r++;continue}else if((s&4294965248)===0)r+=2;else{if(s>=55296&&s<=56319&&n<e){let i=t.charCodeAt(n);(i&64512)===56320&&(++n,s=((s&1023)<<10)+(i&1023)+65536)}(s&4294901760)===0?r+=3:r+=4}}return r}function bB(t,e,r){let n=t.length,s=r,i=0;for(;i<n;){let o=t.charCodeAt(i++);if((o&4294967168)===0){e[s++]=o;continue}else if((o&4294965248)===0)e[s++]=o>>6&31|192;else{if(o>=55296&&o<=56319&&i<n){let a=t.charCodeAt(i);(a&64512)===56320&&(++i,o=((o&1023)<<10)+(a&1023)+65536)}(o&4294901760)===0?(e[s++]=o>>12&15|224,e[s++]=o>>6&63|128):(e[s++]=o>>18&7|240,e[s++]=o>>12&63|128,e[s++]=o>>6&63|128)}e[s++]=o&63|128}}var EB=new TextEncoder,vB=50;function _B(t,e,r){EB.encodeInto(t,e.subarray(r))}function i1(t,e,r){t.length>vB?_B(t,e,r):bB(t,e,r)}var SB=4096;function Mh(t,e,r){let n=e,s=n+r,i=[],o="";for(;n<s;){let a=t[n++];if((a&128)===0)i.push(a);else if((a&224)===192){let c=t[n++]&63;i.push((a&31)<<6|c)}else if((a&240)===224){let c=t[n++]&63,u=t[n++]&63;i.push((a&31)<<12|c<<6|u)}else if((a&248)===240){let c=t[n++]&63,u=t[n++]&63,f=t[n++]&63,l=(a&7)<<18|c<<12|u<<6|f;l>65535&&(l-=65536,i.push(l>>>10&1023|55296),l=56320|l&1023),i.push(l)}else i.push(a);i.length>=SB&&(o+=String.fromCharCode(...i),i.length=0)}return i.length>0&&(o+=String.fromCharCode(...i)),o}var IB=new TextDecoder,BB=200;function AB(t,e,r){let n=t.subarray(e,e+r);return IB.decode(n)}function o1(t,e,r){return r>BB?AB(t,e,r):Mh(t,e,r)}var ms=class{constructor(e,r){Z(this,"type");Z(this,"data");this.type=e,this.data=r}};var gt=class t extends Error{constructor(e){super(e);let r=Object.create(t.prototype);Object.setPrototypeOf(this,r),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:t.name})}};function a1(t,e,r){let n=r/4294967296,s=r;t.setUint32(e,n),t.setUint32(e+4,s)}function Fc(t,e,r){let n=Math.floor(r/4294967296),s=r;t.setUint32(e,n),t.setUint32(e+4,s)}function Hc(t,e){let r=t.getInt32(e),n=t.getUint32(e+4);return r*4294967296+n}function c1(t,e){let r=t.getUint32(e),n=t.getUint32(e+4);return r*4294967296+n}var TB=-1,RB=4294967296-1,DB=17179869184-1;function OB({sec:t,nsec:e}){if(t>=0&&e>=0&&t<=DB)if(e===0&&t<=RB){let r=new Uint8Array(4);return new DataView(r.buffer).setUint32(0,t),r}else{let r=t/4294967296,n=t&4294967295,s=new Uint8Array(8),i=new DataView(s.buffer);return i.setUint32(0,e<<2|r&3),i.setUint32(4,n),s}else{let r=new Uint8Array(12),n=new DataView(r.buffer);return n.setUint32(0,e),Fc(n,4,t),r}}function CB(t){let e=t.getTime(),r=Math.floor(e/1e3),n=(e-r*1e3)*1e6,s=Math.floor(n/1e9);return{sec:r+s,nsec:n-s*1e9}}function NB(t){if(t instanceof Date){let e=CB(t);return OB(e)}else return null}function PB(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength);switch(t.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{let r=e.getUint32(0),n=e.getUint32(4),s=(r&3)*4294967296+n,i=r>>>2;return{sec:s,nsec:i}}case 12:{let r=Hc(e,4),n=e.getUint32(0);return{sec:r,nsec:n}}default:throw new gt(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${t.length}`)}}function UB(t){let e=PB(t);return new Date(e.sec*1e3+e.nsec/1e6)}var u1={type:TB,encode:NB,decode:UB};var zc=class zc{constructor(){Z(this,"__brand");Z(this,"builtInEncoders",[]);Z(this,"builtInDecoders",[]);Z(this,"encoders",[]);Z(this,"decoders",[]);this.register(u1)}register({type:e,encode:r,decode:n}){if(e>=0)this.encoders[e]=r,this.decoders[e]=n;else{let s=-1-e;this.builtInEncoders[s]=r,this.builtInDecoders[s]=n}}tryToEncode(e,r){for(let n=0;n<this.builtInEncoders.length;n++){let s=this.builtInEncoders[n];if(s!=null){let i=s(e,r);if(i!=null){let o=-1-n;return new ms(o,i)}}}for(let n=0;n<this.encoders.length;n++){let s=this.encoders[n];if(s!=null){let i=s(e,r);if(i!=null){let o=n;return new ms(o,i)}}}return e instanceof ms?e:null}decode(e,r,n){let s=r<0?this.builtInDecoders[-1-r]:this.decoders[r];return s?s(e,r,n):new ms(r,e)}};Z(zc,"defaultCodec",new zc);var ui=zc;function LB(t){return t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer}function ho(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):LB(t)?new Uint8Array(t):Uint8Array.from(t)}var kB=100,MB=2048,Vc=class t{constructor(e){Z(this,"extensionCodec");Z(this,"context");Z(this,"useBigInt64");Z(this,"maxDepth");Z(this,"initialBufferSize");Z(this,"sortKeys");Z(this,"forceFloat32");Z(this,"ignoreUndefined");Z(this,"forceIntegerToFloat");Z(this,"pos");Z(this,"view");Z(this,"bytes");Z(this,"entered",!1);this.extensionCodec=e?.extensionCodec??ui.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??kB,this.initialBufferSize=e?.initialBufferSize??MB,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new t({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,r){if(r>this.maxDepth)throw new Error(`Too deep objects in depth ${r}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.useBigInt64&&typeof e=="bigint"?this.encodeBigInt64(e):this.encodeObject(e,r)}ensureBufferSizeToWrite(e){let r=this.pos+e;this.view.byteLength<r&&this.resizeBuffer(r*2)}resizeBuffer(e){let r=new ArrayBuffer(e),n=new Uint8Array(r),s=new DataView(r);n.set(this.bytes),this.view=s,this.bytes=n}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){let n=s1(e);this.ensureBufferSizeToWrite(5+n),this.writeStringHeader(n),i1(e,this.bytes,this.pos),this.pos+=n}encodeObject(e,r){let n=this.extensionCodec.tryToEncode(e,this.context);if(n!=null)this.encodeExtension(n);else if(Array.isArray(e))this.encodeArray(e,r);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,r);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){let r=e.byteLength;if(r<256)this.writeU8(196),this.writeU8(r);else if(r<65536)this.writeU8(197),this.writeU16(r);else if(r<4294967296)this.writeU8(198),this.writeU32(r);else throw new Error(`Too large binary: ${r}`);let n=ho(e);this.writeU8a(n)}encodeArray(e,r){let n=e.length;if(n<16)this.writeU8(144+n);else if(n<65536)this.writeU8(220),this.writeU16(n);else if(n<4294967296)this.writeU8(221),this.writeU32(n);else throw new Error(`Too large array: ${n}`);for(let s of e)this.doEncode(s,r+1)}countWithoutUndefined(e,r){let n=0;for(let s of r)e[s]!==void 0&&n++;return n}encodeMap(e,r){let n=Object.keys(e);this.sortKeys&&n.sort();let s=this.ignoreUndefined?this.countWithoutUndefined(e,n):n.length;if(s<16)this.writeU8(128+s);else if(s<65536)this.writeU8(222),this.writeU16(s);else if(s<4294967296)this.writeU8(223),this.writeU32(s);else throw new Error(`Too large map object: ${s}`);for(let i of n){let o=e[i];this.ignoreUndefined&&o===void 0||(this.encodeString(i),this.doEncode(o,r+1))}}encodeExtension(e){if(typeof e.data=="function"){let n=e.data(this.pos+6),s=n.length;if(s>=4294967296)throw new Error(`Too large extension object: ${s}`);this.writeU8(201),this.writeU32(s),this.writeI8(e.type),this.writeU8a(n);return}let r=e.data.length;if(r===1)this.writeU8(212);else if(r===2)this.writeU8(213);else if(r===4)this.writeU8(214);else if(r===8)this.writeU8(215);else if(r===16)this.writeU8(216);else if(r<256)this.writeU8(199),this.writeU8(r);else if(r<65536)this.writeU8(200),this.writeU16(r);else if(r<4294967296)this.writeU8(201),this.writeU32(r);else throw new Error(`Too large extension object: ${r}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){let r=e.length;this.ensureBufferSizeToWrite(r),this.bytes.set(e,this.pos),this.pos+=r}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),a1(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),Fc(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}};function qh(t,e){return new Vc(e).encodeSharedRef(t)}function $c(t){return`${t<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`}var qB=16,FB=16,jc=class{constructor(e=qB,r=FB){Z(this,"hit",0);Z(this,"miss",0);Z(this,"caches");Z(this,"maxKeyLength");Z(this,"maxLengthPerKey");this.maxKeyLength=e,this.maxLengthPerKey=r,this.caches=[];for(let n=0;n<this.maxKeyLength;n++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,r,n){let s=this.caches[n-1];e:for(let i of s){let o=i.bytes;for(let a=0;a<n;a++)if(o[a]!==e[r+a])continue e;return i.str}return null}store(e,r){let n=this.caches[e.length-1],s={bytes:e,str:r};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=s:n.push(s)}decode(e,r,n){let s=this.find(e,r,n);if(s!=null)return this.hit++,s;this.miss++;let i=Mh(e,r,n),o=Uint8Array.prototype.slice.call(e,r,r+n);return this.store(o,i),i}};var Fh="array",mo="map_key",f1="map_value",HB=t=>{if(typeof t=="string"||typeof t=="number")return t;throw new gt("The type of key must be string or number but "+typeof t)},Hh=class{constructor(){Z(this,"stack",[]);Z(this,"stackHeadPosition",-1)}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let r=this.getUninitializedStateFromPool();r.type=Fh,r.position=0,r.size=e,r.array=new Array(e)}pushMapState(e){let r=this.getUninitializedStateFromPool();r.type=mo,r.readCount=0,r.size=e,r.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===Fh){let n=e;n.size=0,n.array=void 0,n.position=0,n.type=void 0}if(e.type===mo||e.type===f1){let n=e;n.size=0,n.map=void 0,n.readCount=0,n.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},go=-1,zh=new DataView(new ArrayBuffer(0)),zB=new Uint8Array(zh.buffer);try{zh.getInt8(0)}catch(t){if(!(t instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var l1=new RangeError("Insufficient data"),VB=new jc,Kc=class t{constructor(e){Z(this,"extensionCodec");Z(this,"context");Z(this,"useBigInt64");Z(this,"rawStrings");Z(this,"maxStrLength");Z(this,"maxBinLength");Z(this,"maxArrayLength");Z(this,"maxMapLength");Z(this,"maxExtLength");Z(this,"keyDecoder");Z(this,"mapKeyConverter");Z(this,"totalPos",0);Z(this,"pos",0);Z(this,"view",zh);Z(this,"bytes",zB);Z(this,"headByte",go);Z(this,"stack",new Hh);Z(this,"entered",!1);this.extensionCodec=e?.extensionCodec??ui.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??4294967295,this.maxBinLength=e?.maxBinLength??4294967295,this.maxArrayLength=e?.maxArrayLength??4294967295,this.maxMapLength=e?.maxMapLength??4294967295,this.maxExtLength=e?.maxExtLength??4294967295,this.keyDecoder=e?.keyDecoder!==void 0?e.keyDecoder:VB,this.mapKeyConverter=e?.mapKeyConverter??HB}clone(){return new t({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=go,this.stack.reset()}setBuffer(e){let r=ho(e);this.bytes=r,this.view=new DataView(r.buffer,r.byteOffset,r.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===go&&!this.hasRemaining(1))this.setBuffer(e);else{let r=this.bytes.subarray(this.pos),n=ho(e),s=new Uint8Array(r.length+n.length);s.set(r),s.set(n,r.length),this.setBuffer(s)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:r,pos:n}=this;return new RangeError(`Extra ${r.byteLength-n} of ${r.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let r=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return r}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let r=!1,n;for await(let a of e){if(r)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(a);try{n=this.doDecodeSync(),r=!0}catch(c){if(!(c instanceof RangeError))throw c}this.totalPos+=this.pos}if(r){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:s,pos:i,totalPos:o}=this;throw new RangeError(`Insufficient data in parsing ${$c(s)} at ${o} (${i} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,r){if(this.entered){yield*this.clone().decodeMultiAsync(e,r);return}try{this.entered=!0;let n=r,s=-1;for await(let i of e){if(r&&s===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(i),n&&(s=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--s!==0;);}catch(o){if(!(o instanceof RangeError))throw o}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){let e=this.readHeadByte(),r;if(e>=224)r=e-256;else if(e<192)if(e<128)r=e;else if(e<144){let s=e-128;if(s!==0){this.pushMapState(s),this.complete();continue e}else r={}}else if(e<160){let s=e-144;if(s!==0){this.pushArrayState(s),this.complete();continue e}else r=[]}else{let s=e-160;r=this.decodeString(s,0)}else if(e===192)r=null;else if(e===194)r=!1;else if(e===195)r=!0;else if(e===202)r=this.readF32();else if(e===203)r=this.readF64();else if(e===204)r=this.readU8();else if(e===205)r=this.readU16();else if(e===206)r=this.readU32();else if(e===207)this.useBigInt64?r=this.readU64AsBigInt():r=this.readU64();else if(e===208)r=this.readI8();else if(e===209)r=this.readI16();else if(e===210)r=this.readI32();else if(e===211)this.useBigInt64?r=this.readI64AsBigInt():r=this.readI64();else if(e===217){let s=this.lookU8();r=this.decodeString(s,1)}else if(e===218){let s=this.lookU16();r=this.decodeString(s,2)}else if(e===219){let s=this.lookU32();r=this.decodeString(s,4)}else if(e===220){let s=this.readU16();if(s!==0){this.pushArrayState(s),this.complete();continue e}else r=[]}else if(e===221){let s=this.readU32();if(s!==0){this.pushArrayState(s),this.complete();continue e}else r=[]}else if(e===222){let s=this.readU16();if(s!==0){this.pushMapState(s),this.complete();continue e}else r={}}else if(e===223){let s=this.readU32();if(s!==0){this.pushMapState(s),this.complete();continue e}else r={}}else if(e===196){let s=this.lookU8();r=this.decodeBinary(s,1)}else if(e===197){let s=this.lookU16();r=this.decodeBinary(s,2)}else if(e===198){let s=this.lookU32();r=this.decodeBinary(s,4)}else if(e===212)r=this.decodeExtension(1,0);else if(e===213)r=this.decodeExtension(2,0);else if(e===214)r=this.decodeExtension(4,0);else if(e===215)r=this.decodeExtension(8,0);else if(e===216)r=this.decodeExtension(16,0);else if(e===199){let s=this.lookU8();r=this.decodeExtension(s,1)}else if(e===200){let s=this.lookU16();r=this.decodeExtension(s,2)}else if(e===201){let s=this.lookU32();r=this.decodeExtension(s,4)}else throw new gt(`Unrecognized type byte: ${$c(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let s=n.top();if(s.type===Fh)if(s.array[s.position]=r,s.position++,s.position===s.size)r=s.array,n.release(s);else continue e;else if(s.type===mo){if(r==="__proto__")throw new gt("The key __proto__ is not allowed");s.key=this.mapKeyConverter(r),s.type=f1;continue e}else if(s.map[s.key]=r,s.readCount++,s.readCount===s.size)r=s.map,n.release(s);else{s.key=null,s.type=mo;continue e}}return r}}readHeadByte(){return this.headByte===go&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=go}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new gt(`Unrecognized array type byte: ${$c(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new gt(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new gt(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,r){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,r):this.decodeBinary(e,r)}decodeUtf8String(e,r){if(e>this.maxStrLength)throw new gt(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+r+e)throw l1;let n=this.pos+r,s;return this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?s=this.keyDecoder.decode(this.bytes,n,e):s=o1(this.bytes,n,e),this.pos+=r+e,s}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===mo:!1}decodeBinary(e,r){if(e>this.maxBinLength)throw new gt(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+r))throw l1;let n=this.pos+r,s=this.bytes.subarray(n,n+e);return this.pos+=r+e,s}decodeExtension(e,r){if(e>this.maxExtLength)throw new gt(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+r),s=this.decodeBinary(e,r+1);return this.extensionCodec.decode(s,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=c1(this.view,this.pos);return this.pos+=8,e}readI64(){let e=Hc(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}};function Vh(t,e){return new Kc(e).decode(t)}function Hr(t,e){e||(e=t.reduce((s,i)=>s+i.length,0));let r=Ji(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return Yn(r)}function Ee(t,e="utf8"){let r=Ya[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var d1=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),$B=d1("expand 16-byte k"),jB=d1("expand 32-byte k"),KB=Mr($B),WB=Mr(jB);function K(t,e){return t<<e|t>>>32-e}function $h(t){return t.byteOffset%4===0}var Wc=64,GB=16,p1=2**32-1,h1=new Uint32Array;function YB(t,e,r,n,s,i,o,a){let c=s.length,u=new Uint8Array(Wc),f=Mr(u),l=$h(s)&&$h(i),h=l?Mr(s):h1,d=l?Mr(i):h1;for(let p=0;p<c;o++){if(t(e,r,n,f,o,a),o>=p1)throw new Error("arx: counter overflow");let g=Math.min(Wc,c-p);if(l&&g===Wc){let m=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let b=0,T;b<GB;b++)T=m+b,d[T]=h[T]^f[b];p+=Wc;continue}for(let m=0,b;m<g;m++)b=p+m,i[b]=s[b]^u[m];p+=g}}function jh(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:s,counterRight:i,rounds:o}=Gw({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Uc(s),Uc(o),Pc(i),Pc(r),(a,c,u,f,l=0)=>{Xe(a),Xe(c),Xe(u);let h=u.length;if(f===void 0&&(f=new Uint8Array(h)),Xe(f),Uc(l),l<0||l>=p1)throw new Error("arx: counter overflow");if(f.length<h)throw new Error(`arx: output (${f.length}) is shorter than data (${h})`);let d=[],p=a.length,g,m;if(p===32)d.push(g=kc(a)),m=WB;else if(p===16&&r)g=new Uint8Array(32),g.set(a),g.set(a,16),m=KB,d.push(g);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);$h(c)||d.push(c=kc(c));let b=Mr(g);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(m,b,Mr(c.subarray(0,16)),b),c=c.subarray(16)}let T=16-s;if(T!==c.length)throw new Error(`arx: nonce must be ${T} or 16 bytes`);if(T!==12){let v=new Uint8Array(12);v.set(c,i?0:12-c.length),c=v,d.push(c)}let w=Mr(c);return YB(t,m,b,w,u,f,l,o),qr(...d),f}}var ze=(t,e)=>t[e++]&255|(t[e++]&255)<<8,Kh=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=Lc(e),Xe(e,32);let r=ze(e,0),n=ze(e,2),s=ze(e,4),i=ze(e,6),o=ze(e,8),a=ze(e,10),c=ze(e,12),u=ze(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|i<<9)&8191,this.r[4]=(i>>>4|o<<12)&255,this.r[5]=o>>>1&8190,this.r[6]=(o>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=ze(e,16+2*f)}process(e,r,n=!1){let s=n?0:2048,{h:i,r:o}=this,a=o[0],c=o[1],u=o[2],f=o[3],l=o[4],h=o[5],d=o[6],p=o[7],g=o[8],m=o[9],b=ze(e,r+0),T=ze(e,r+2),w=ze(e,r+4),v=ze(e,r+6),R=ze(e,r+8),C=ze(e,r+10),O=ze(e,r+12),N=ze(e,r+14),I=i[0]+(b&8191),k=i[1]+((b>>>13|T<<3)&8191),L=i[2]+((T>>>10|w<<6)&8191),P=i[3]+((w>>>7|v<<9)&8191),E=i[4]+((v>>>4|R<<12)&8191),B=i[5]+(R>>>1&8191),y=i[6]+((R>>>14|C<<2)&8191),x=i[7]+((C>>>11|O<<5)&8191),S=i[8]+((O>>>8|N<<8)&8191),A=i[9]+(N>>>5|s),_=0,D=_+I*a+k*(5*m)+L*(5*g)+P*(5*p)+E*(5*d);_=D>>>13,D&=8191,D+=B*(5*h)+y*(5*l)+x*(5*f)+S*(5*u)+A*(5*c),_+=D>>>13,D&=8191;let U=_+I*c+k*a+L*(5*m)+P*(5*g)+E*(5*p);_=U>>>13,U&=8191,U+=B*(5*d)+y*(5*h)+x*(5*l)+S*(5*f)+A*(5*u),_+=U>>>13,U&=8191;let q=_+I*u+k*c+L*a+P*(5*m)+E*(5*g);_=q>>>13,q&=8191,q+=B*(5*p)+y*(5*d)+x*(5*h)+S*(5*l)+A*(5*f),_+=q>>>13,q&=8191;let z=_+I*f+k*u+L*c+P*a+E*(5*m);_=z>>>13,z&=8191,z+=B*(5*g)+y*(5*p)+x*(5*d)+S*(5*h)+A*(5*l),_+=z>>>13,z&=8191;let V=_+I*l+k*f+L*u+P*c+E*a;_=V>>>13,V&=8191,V+=B*(5*m)+y*(5*g)+x*(5*p)+S*(5*d)+A*(5*h),_+=V>>>13,V&=8191;let H=_+I*h+k*l+L*f+P*u+E*c;_=H>>>13,H&=8191,H+=B*a+y*(5*m)+x*(5*g)+S*(5*p)+A*(5*d),_+=H>>>13,H&=8191;let W=_+I*d+k*h+L*l+P*f+E*u;_=W>>>13,W&=8191,W+=B*c+y*a+x*(5*m)+S*(5*g)+A*(5*p),_+=W>>>13,W&=8191;let J=_+I*p+k*d+L*h+P*l+E*f;_=J>>>13,J&=8191,J+=B*u+y*c+x*a+S*(5*m)+A*(5*g),_+=J>>>13,J&=8191;let ee=_+I*g+k*p+L*d+P*h+E*l;_=ee>>>13,ee&=8191,ee+=B*f+y*u+x*c+S*a+A*(5*m),_+=ee>>>13,ee&=8191;let Y=_+I*m+k*g+L*p+P*d+E*h;_=Y>>>13,Y&=8191,Y+=B*l+y*f+x*u+S*c+A*a,_+=Y>>>13,Y&=8191,_=(_<<2)+_|0,_=_+D|0,D=_&8191,_=_>>>13,U+=_,i[0]=D,i[1]=U,i[2]=q,i[3]=z,i[4]=V,i[5]=H,i[6]=W,i[7]=J,i[8]=ee,i[9]=Y}finalize(){let{h:e,pad:r}=this,n=new Uint16Array(10),s=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=s,s=e[a]>>>13,e[a]&=8191;e[0]+=s*5,s=e[0]>>>13,e[0]&=8191,e[1]+=s,s=e[1]>>>13,e[1]&=8191,e[2]+=s,n[0]=e[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let i=(s^1)-1;for(let a=0;a<10;a++)n[a]&=i;i=~i;for(let a=0;a<10;a++)e[a]=e[a]&i|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let o=e[0]+r[0];e[0]=o&65535;for(let a=1;a<8;a++)o=(e[a]+r[a]|0)+(o>>>16)|0,e[a]=o&65535;qr(n)}update(e){Oh(this),e=Lc(e),Xe(e);let{buffer:r,blockLen:n}=this,s=e.length;for(let i=0;i<s;){let o=Math.min(n-this.pos,s-i);if(o===n){for(;n<=s-i;i+=n)this.process(e,i);continue}r.set(e.subarray(i,i+o),this.pos),this.pos+=o,i+=o,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){qr(this.h,this.r,this.buffer,this.pad)}digestInto(e){Oh(this),Ww(e,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:s}=this;if(s){for(r[s++]=1;s<16;s++)r[s]=0;this.process(r,0,!0)}this.finalize();let i=0;for(let o=0;o<8;o++)e[i++]=n[o]>>>0,e[i++]=n[o]>>>8;return e}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}};function JB(t){let e=(n,s)=>t(s).update(Lc(n)).digest(),r=t(new Uint8Array(32));return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}var g1=JB(t=>new Kh(t));function w1(t,e,r,n,s,i=20){let o=t[0],a=t[1],c=t[2],u=t[3],f=e[0],l=e[1],h=e[2],d=e[3],p=e[4],g=e[5],m=e[6],b=e[7],T=s,w=r[0],v=r[1],R=r[2],C=o,O=a,N=c,I=u,k=f,L=l,P=h,E=d,B=p,y=g,x=m,S=b,A=T,_=w,D=v,U=R;for(let z=0;z<i;z+=2)C=C+k|0,A=K(A^C,16),B=B+A|0,k=K(k^B,12),C=C+k|0,A=K(A^C,8),B=B+A|0,k=K(k^B,7),O=O+L|0,_=K(_^O,16),y=y+_|0,L=K(L^y,12),O=O+L|0,_=K(_^O,8),y=y+_|0,L=K(L^y,7),N=N+P|0,D=K(D^N,16),x=x+D|0,P=K(P^x,12),N=N+P|0,D=K(D^N,8),x=x+D|0,P=K(P^x,7),I=I+E|0,U=K(U^I,16),S=S+U|0,E=K(E^S,12),I=I+E|0,U=K(U^I,8),S=S+U|0,E=K(E^S,7),C=C+L|0,U=K(U^C,16),x=x+U|0,L=K(L^x,12),C=C+L|0,U=K(U^C,8),x=x+U|0,L=K(L^x,7),O=O+P|0,A=K(A^O,16),S=S+A|0,P=K(P^S,12),O=O+P|0,A=K(A^O,8),S=S+A|0,P=K(P^S,7),N=N+E|0,_=K(_^N,16),B=B+_|0,E=K(E^B,12),N=N+E|0,_=K(_^N,8),B=B+_|0,E=K(E^B,7),I=I+k|0,D=K(D^I,16),y=y+D|0,k=K(k^y,12),I=I+k|0,D=K(D^I,8),y=y+D|0,k=K(k^y,7);let q=0;n[q++]=o+C|0,n[q++]=a+O|0,n[q++]=c+N|0,n[q++]=u+I|0,n[q++]=f+k|0,n[q++]=l+L|0,n[q++]=h+P|0,n[q++]=d+E|0,n[q++]=p+B|0,n[q++]=g+y|0,n[q++]=m+x|0,n[q++]=b+S|0,n[q++]=T+A|0,n[q++]=w+_|0,n[q++]=v+D|0,n[q++]=R+U|0}function XB(t,e,r,n){let s=t[0],i=t[1],o=t[2],a=t[3],c=e[0],u=e[1],f=e[2],l=e[3],h=e[4],d=e[5],p=e[6],g=e[7],m=r[0],b=r[1],T=r[2],w=r[3];for(let R=0;R<20;R+=2)s=s+c|0,m=K(m^s,16),h=h+m|0,c=K(c^h,12),s=s+c|0,m=K(m^s,8),h=h+m|0,c=K(c^h,7),i=i+u|0,b=K(b^i,16),d=d+b|0,u=K(u^d,12),i=i+u|0,b=K(b^i,8),d=d+b|0,u=K(u^d,7),o=o+f|0,T=K(T^o,16),p=p+T|0,f=K(f^p,12),o=o+f|0,T=K(T^o,8),p=p+T|0,f=K(f^p,7),a=a+l|0,w=K(w^a,16),g=g+w|0,l=K(l^g,12),a=a+l|0,w=K(w^a,8),g=g+w|0,l=K(l^g,7),s=s+u|0,w=K(w^s,16),p=p+w|0,u=K(u^p,12),s=s+u|0,w=K(w^s,8),p=p+w|0,u=K(u^p,7),i=i+f|0,m=K(m^i,16),g=g+m|0,f=K(f^g,12),i=i+f|0,m=K(m^i,8),g=g+m|0,f=K(f^g,7),o=o+l|0,b=K(b^o,16),h=h+b|0,l=K(l^h,12),o=o+l|0,b=K(b^o,8),h=h+b|0,l=K(l^h,7),a=a+c|0,T=K(T^a,16),d=d+T|0,c=K(c^d,12),a=a+c|0,T=K(T^a,8),d=d+T|0,c=K(c^d,7);let v=0;n[v++]=s,n[v++]=i,n[v++]=o,n[v++]=a,n[v++]=m,n[v++]=b,n[v++]=T,n[v++]=w}var ZB=jh(w1,{counterRight:!1,counterLength:4,allowShortKeys:!1}),QB=jh(w1,{counterRight:!1,counterLength:8,extendNonceFn:XB,allowShortKeys:!1});var eA=new Uint8Array(16),m1=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(eA.subarray(r))},tA=new Uint8Array(32);function y1(t,e,r,n,s){let i=t(e,r,tA),o=g1.create(i);s&&m1(o,s),m1(o,n);let a=Jw(n.length,s?s.length:0,!0);o.update(a);let c=o.digest();return qr(i,a),c}var x1=t=>(e,r,n)=>({encrypt(i,o){let a=i.length;o=Nh(a+16,o,!1),o.set(i);let c=o.subarray(0,-16);t(e,r,c,c,1);let u=y1(t,e,r,c,n);return o.set(u,a),qr(u),o},decrypt(i,o){o=Nh(i.length-16,o,!1);let a=i.subarray(0,-16),c=i.subarray(-16),u=y1(t,e,r,a,n);if(!Yw(c,u))throw new Error("invalid tag");return o.set(i.subarray(0,-16)),t(e,r,o,o,1),qr(u),o}}),Wh=Ch({blockSize:64,nonceLength:12,tagLength:16},x1(ZB)),i7=Ch({blockSize:64,nonceLength:24,tagLength:16},x1(QB));var Gc=class extends ur{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,es(e);let n=Ge(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?e.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=e.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),Ue(i)}update(e){return Ot(this),this.iHash.update(e),this}digestInto(e){Ot(this),be(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},li=(t,e,r)=>new Gc(t,e).update(r).digest();li.create=(t,e)=>new Gc(t,e);function rA(t,e,r){return es(t),r===void 0&&(r=new Uint8Array(t.outputLen)),li(t,Ge(r),Ge(e))}var Gh=Uint8Array.from([0]),b1=Uint8Array.of();function nA(t,e,r,n=32){es(t),dt(n);let s=t.outputLen;if(n>255*s)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/s);r===void 0&&(r=b1);let o=new Uint8Array(i*s),a=li.create(t,e),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let f=0;f<i;f++)Gh[0]=f+1,c.update(f===0?b1:u).update(r).update(Gh).digestInto(u),o.set(u,s*f),a._cloneInto(c);return a.destroy(),c.destroy(),Ue(u,Gh),o.slice(0,n)}var E1=(t,e,r,n,s)=>nA(t,rA(t,e,r),n,s);var yo=gs;var Xh=BigInt(0),Jh=BigInt(1);function zr(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}"`;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function It(t,e,r=""){let n=Dr(t),s=t?.length,i=e!==void 0;if(!n||i&&s!==e){let o=r&&`"${r}" `,a=i?` of length ${e}`:"",c=n?`length=${s}`:`type=${typeof t}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return t}function wo(t){let e=t.toString(16);return e.length&1?"0"+e:e}function v1(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Xh:BigInt("0x"+t)}function fi(t){return v1(Ct(t))}function Pt(t){return be(t),v1(Ct(Uint8Array.from(t).reverse()))}function Yc(t,e){return rs(t.toString(16).padStart(e*2,"0"))}function xo(t,e){return Yc(t,e).reverse()}function oe(t,e,r){let n;if(typeof e=="string")try{n=rs(e)}catch(i){throw new Error(t+" must be hex string or Uint8Array, cause: "+i)}else if(Dr(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let s=n.length;if(typeof r=="number"&&s!==r)throw new Error(t+" of length "+r+" expected, got "+s);return n}function _1(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Zh(t){return Uint8Array.from(t)}var Yh=t=>typeof t=="bigint"&&Xh<=t;function S1(t,e,r){return Yh(t)&&Yh(e)&&Yh(r)&&e<=t&&t<r}function En(t,e,r,n){if(!S1(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Jc(t){let e;for(e=0;t>Xh;t>>=Jh,e+=1);return e}var vn=t=>(Jh<<BigInt(t))-Jh;function I1(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=d=>new Uint8Array(d),s=d=>Uint8Array.of(d),i=n(t),o=n(t),a=0,c=()=>{i.fill(1),o.fill(0),a=0},u=(...d)=>r(o,i,...d),f=(d=n(0))=>{o=u(s(0),d),i=u(),d.length!==0&&(o=u(s(1),d),i=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,p=[];for(;d<e;){i=u();let g=i.slice();p.push(g),d+=i.length}return it(...p)};return(d,p)=>{c(),f(d);let g;for(;!(g=p(l()));)f();return c(),g}}function gr(t,e,r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(s,i,o){let a=t[s];if(o&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([s,i])=>n(s,i,!1)),Object.entries(r).forEach(([s,i])=>n(s,i,!0))}var Qh=()=>{throw new Error("not implemented")};function hi(t){let e=new WeakMap;return(r,...n)=>{let s=e.get(r);if(s!==void 0)return s;let i=t(r,...n);return e.set(r,i),i}}var at=BigInt(0),ke=BigInt(1),ys=BigInt(2),T1=BigInt(3),R1=BigInt(4),D1=BigInt(5),sA=BigInt(7),O1=BigInt(8),iA=BigInt(9),C1=BigInt(16);function de(t,e){let r=t%e;return r>=at?r:e+r}function Ut(t,e,r){let n=t;for(;e-- >at;)n*=n,n%=r;return n}function B1(t,e){if(t===at)throw new Error("invert: expected non-zero number");if(e<=at)throw new Error("invert: expected positive modulus, got "+e);let r=de(t,e),n=e,s=at,i=ke,o=ke,a=at;for(;r!==at;){let u=n/r,f=n%r,l=s-o*u,h=i-a*u;n=r,r=f,s=o,i=a,o=l,a=h}if(n!==ke)throw new Error("invert: does not exist");return de(s,e)}function ed(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function N1(t,e){let r=(t.ORDER+ke)/R1,n=t.pow(e,r);return ed(t,n,e),n}function oA(t,e){let r=(t.ORDER-D1)/O1,n=t.mul(e,ys),s=t.pow(n,r),i=t.mul(e,s),o=t.mul(t.mul(i,ys),s),a=t.mul(i,t.sub(o,t.ONE));return ed(t,a,e),a}function aA(t){let e=ct(t),r=P1(t),n=r(e,e.neg(e.ONE)),s=r(e,n),i=r(e,e.neg(n)),o=(t+sA)/C1;return(a,c)=>{let u=a.pow(c,o),f=a.mul(u,n),l=a.mul(u,s),h=a.mul(u,i),d=a.eql(a.sqr(f),c),p=a.eql(a.sqr(l),c);u=a.cmov(u,f,d),f=a.cmov(h,l,p);let g=a.eql(a.sqr(f),c),m=a.cmov(u,f,g);return ed(a,m,c),m}}function P1(t){if(t<T1)throw new Error("sqrt is not defined for small field");let e=t-ke,r=0;for(;e%ys===at;)e/=ys,r++;let n=ys,s=ct(t);for(;A1(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return N1;let i=s.pow(n,e),o=(e+ke)/ys;return function(c,u){if(c.is0(u))return u;if(A1(c,u)!==1)throw new Error("Cannot find square root");let f=r,l=c.mul(c.ONE,i),h=c.pow(u,e),d=c.pow(u,o);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let p=1,g=c.sqr(h);for(;!c.eql(g,c.ONE);)if(p++,g=c.sqr(g),p===f)throw new Error("Cannot find square root");let m=ke<<BigInt(f-p-1),b=c.pow(l,m);f=p,l=c.sqr(b),h=c.mul(h,l),d=c.mul(d,b)}return d}}function cA(t){return t%R1===T1?N1:t%O1===D1?oA:t%C1===iA?aA(t):P1(t)}var Vr=(t,e)=>(de(t,e)&ke)===ke,uA=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function td(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=uA.reduce((n,s)=>(n[s]="function",n),e);return gr(t,r),t}function lA(t,e,r){if(r<at)throw new Error("invalid exponent, negatives unsupported");if(r===at)return t.ONE;if(r===ke)return e;let n=t.ONE,s=e;for(;r>at;)r&ke&&(n=t.mul(n,s)),s=t.sqr(s),r>>=ke;return n}function bo(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),s=e.reduce((o,a,c)=>t.is0(a)?o:(n[c]=o,t.mul(o,a)),t.ONE),i=t.inv(s);return e.reduceRight((o,a,c)=>t.is0(a)?o:(n[c]=t.mul(o,n[c]),t.mul(o,a)),i),n}function A1(t,e){let r=(t.ORDER-ke)/ys,n=t.pow(e,r),s=t.eql(n,t.ONE),i=t.eql(n,t.ZERO),o=t.eql(n,t.neg(t.ONE));if(!s&&!i&&!o)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Xc(t,e){e!==void 0&&dt(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ct(t,e,r=!1,n={}){if(t<=at)throw new Error("invalid field: expected ORDER > 0, got "+t);let s,i,o=!1,a;if(typeof e=="object"&&e!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let h=e;h.BITS&&(s=h.BITS),h.sqrt&&(i=h.sqrt),typeof h.isLE=="boolean"&&(r=h.isLE),typeof h.modFromBytes=="boolean"&&(o=h.modFromBytes),a=h.allowedLengths}else typeof e=="number"&&(s=e),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:u}=Xc(t,s);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f,l=Object.freeze({ORDER:t,isLE:r,BITS:c,BYTES:u,MASK:vn(c),ZERO:at,ONE:ke,allowedLengths:a,create:h=>de(h,t),isValid:h=>{if(typeof h!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof h);return at<=h&&h<t},is0:h=>h===at,isValidNot0:h=>!l.is0(h)&&l.isValid(h),isOdd:h=>(h&ke)===ke,neg:h=>de(-h,t),eql:(h,d)=>h===d,sqr:h=>de(h*h,t),add:(h,d)=>de(h+d,t),sub:(h,d)=>de(h-d,t),mul:(h,d)=>de(h*d,t),pow:(h,d)=>lA(l,h,d),div:(h,d)=>de(h*B1(d,t),t),sqrN:h=>h*h,addN:(h,d)=>h+d,subN:(h,d)=>h-d,mulN:(h,d)=>h*d,inv:h=>B1(h,t),sqrt:i||(h=>(f||(f=cA(t)),f(l,h))),toBytes:h=>r?xo(h,u):Yc(h,u),fromBytes:(h,d=!0)=>{if(a){if(!a.includes(h.length)||h.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+h.length);let g=new Uint8Array(u);g.set(h,r?0:g.length-h.length),h=g}if(h.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+h.length);let p=r?Pt(h):fi(h);if(o&&(p=de(p,t)),!d&&!l.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:h=>bo(l,h),cmov:(h,d,p)=>p?d:h});return Object.freeze(l)}function U1(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function rd(t){let e=U1(t);return e+Math.ceil(e/2)}function L1(t,e,r=!1){let n=t.length,s=U1(e),i=rd(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=r?Pt(t):fi(t),a=de(o,e-ke)+ke;return r?xo(a,s):Yc(a,s)}var di=BigInt(0),ws=BigInt(1);function Eo(t,e){let r=e.negate();return t?r:e}function $r(t,e){let r=bo(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function F1(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function nd(t,e){F1(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),s=2**t,i=vn(t),o=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:s,shiftBy:o}}function k1(t,e,r){let{windowSize:n,mask:s,maxNumber:i,shiftBy:o}=r,a=Number(t&s),c=t>>o;a>n&&(a-=i,c+=ws);let u=e*n,f=u+Math.abs(a)-1,l=a===0,h=a<0,d=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}}function fA(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function hA(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var sd=new WeakMap,H1=new WeakMap;function id(t){return H1.get(t)||1}function M1(t){if(t!==di)throw new Error("invalid wNAF")}var pi=class{constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let s=e;for(;r>di;)r&ws&&(n=n.add(s)),s=s.double(),r>>=ws;return n}precomputeWindow(e,r){let{windows:n,windowSize:s}=nd(r,this.bits),i=[],o=e,a=o;for(let c=0;c<n;c++){a=o,i.push(a);for(let u=1;u<s;u++)a=a.add(o),i.push(a);o=a.double()}return i}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,i=this.BASE,o=nd(e,this.bits);for(let a=0;a<o.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:h,offsetF:d}=k1(n,a,o);n=c,f?i=i.add(Eo(h,r[d])):s=s.add(Eo(l,r[u]))}return M1(n),{p:s,f:i}}wNAFUnsafe(e,r,n,s=this.ZERO){let i=nd(e,this.bits);for(let o=0;o<i.windows&&n!==di;o++){let{nextN:a,offset:c,isZero:u,isNeg:f}=k1(n,o,i);if(n=a,!u){let l=r[c];s=s.add(f?l.negate():l)}}return M1(n),s}getPrecomputes(e,r,n){let s=sd.get(r);return s||(s=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(s=n(s)),sd.set(r,s))),s}cached(e,r,n){let s=id(e);return this.wNAF(s,this.getPrecomputes(s,e,n),r)}unsafe(e,r,n,s){let i=id(e);return i===1?this._unsafeLadder(e,r,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),r,s)}createCache(e,r){F1(r,this.bits),H1.set(e,r),sd.delete(e)}hasCache(e){return id(e)!==1}};function z1(t,e,r,n){let s=e,i=t.ZERO,o=t.ZERO;for(;r>di||n>di;)r&ws&&(i=i.add(s)),n&ws&&(o=o.add(s)),s=s.double(),r>>=ws,n>>=ws;return{p1:i,p2:o}}function gi(t,e,r,n){fA(r,t),hA(n,e);let s=r.length,i=n.length;if(s!==i)throw new Error("arrays of points and scalars must have equal length");let o=t.ZERO,a=Jc(BigInt(s)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=vn(c),f=new Array(Number(u)+1).fill(o),l=Math.floor((e.BITS-1)/c)*c,h=o;for(let d=l;d>=0;d-=c){f.fill(o);for(let g=0;g<i;g++){let m=n[g],b=Number(m>>BigInt(d)&u);f[b]=f[b].add(r[g])}let p=o;for(let g=f.length-1,m=o;g>0;g--)m=m.add(f[g]),p=p.add(m);if(h=h.add(p),d!==0)for(let g=0;g<c;g++)h=h.double()}return h}function q1(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return td(e),e}else return ct(t,{isLE:r})}function Zc(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>di))throw new Error(`CURVE.${c} must be positive bigint`)}let s=q1(e.p,r.Fp,n),i=q1(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:i}}var _n=BigInt(0),Me=BigInt(1),od=BigInt(2),dA=BigInt(8);function pA(t,e,r,n){let s=t.sqr(r),i=t.sqr(n),o=t.add(t.mul(e.a,s),i),a=t.add(t.ONE,t.mul(e.d,t.mul(s,i)));return t.eql(o,a)}function gA(t,e={}){let r=Zc("edwards",t,e,e.FpFnLE),{Fp:n,Fn:s}=r,i=r.CURVE,{h:o}=i;gr(e,{},{uvRatio:"function"});let a=od<<BigInt(s.BYTES*8)-Me,c=m=>n.create(m),u=e.uvRatio||((m,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(m,b))}}catch{return{isValid:!1,value:_n}}});if(!pA(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function f(m,b,T=!1){let w=T?Me:_n;return En("coordinate "+m,b,w,a),b}function l(m){if(!(m instanceof p))throw new Error("ExtendedPoint expected")}let h=hi((m,b)=>{let{X:T,Y:w,Z:v}=m,R=m.is0();b==null&&(b=R?dA:n.inv(v));let C=c(T*b),O=c(w*b),N=n.mul(v,b);if(R)return{x:_n,y:Me};if(N!==Me)throw new Error("invZ was invalid");return{x:C,y:O}}),d=hi(m=>{let{a:b,d:T}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:w,Y:v,Z:R,T:C}=m,O=c(w*w),N=c(v*v),I=c(R*R),k=c(I*I),L=c(O*b),P=c(I*c(L+N)),E=c(k+c(T*c(O*N)));if(P!==E)throw new Error("bad point: equation left != right (1)");let B=c(w*v),y=c(R*C);if(B!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(b,T,w,v){this.X=f("x",b),this.Y=f("y",T),this.Z=f("z",w,!0),this.T=f("t",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:T,y:w}=b||{};return f("x",T),f("y",w),new p(T,w,Me,c(T*w))}static fromBytes(b,T=!1){let w=n.BYTES,{a:v,d:R}=i;b=Zh(It(b,w,"point")),zr(T,"zip215");let C=Zh(b),O=b[w-1];C[w-1]=O&-129;let N=Pt(C),I=T?a:n.ORDER;En("point.y",N,_n,I);let k=c(N*N),L=c(k-Me),P=c(R*k-v),{isValid:E,value:B}=u(L,P);if(!E)throw new Error("bad point: invalid y coordinate");let y=(B&Me)===Me,x=(O&128)!==0;if(!T&&B===_n&&x)throw new Error("bad point: x=0 and x_0=1");return x!==y&&(B=c(-B)),p.fromAffine({x:B,y:N})}static fromHex(b,T=!1){return p.fromBytes(oe("point",b),T)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,T=!0){return g.createCache(this,b),T||this.multiply(od),this}assertValidity(){d(this)}equals(b){l(b);let{X:T,Y:w,Z:v}=this,{X:R,Y:C,Z:O}=b,N=c(T*O),I=c(R*v),k=c(w*O),L=c(C*v);return N===I&&k===L}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=i,{X:T,Y:w,Z:v}=this,R=c(T*T),C=c(w*w),O=c(od*c(v*v)),N=c(b*R),I=T+w,k=c(c(I*I)-R-C),L=N+C,P=L-O,E=N-C,B=c(k*P),y=c(L*E),x=c(k*E),S=c(P*L);return new p(B,y,S,x)}add(b){l(b);let{a:T,d:w}=i,{X:v,Y:R,Z:C,T:O}=this,{X:N,Y:I,Z:k,T:L}=b,P=c(v*N),E=c(R*I),B=c(O*w*L),y=c(C*k),x=c((v+R)*(N+I)-P-E),S=y-B,A=y+B,_=c(E-T*P),D=c(x*S),U=c(A*_),q=c(x*_),z=c(S*A);return new p(D,U,z,q)}subtract(b){return this.add(b.negate())}multiply(b){if(!s.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:T,f:w}=g.cached(this,b,v=>$r(p,v));return $r(p,[T,w])[0]}multiplyUnsafe(b,T=p.ZERO){if(!s.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===_n?p.ZERO:this.is0()||b===Me?this:g.unsafe(this,b,w=>$r(p,w),T)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return g.unsafe(this,i.n).is0()}toAffine(b){return h(this,b)}clearCofactor(){return o===Me?this:this.multiplyUnsafe(o)}toBytes(){let{x:b,y:T}=this.toAffine(),w=n.toBytes(T);return w[w.length-1]|=b&Me?128:0,w}toHex(){return Ct(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return $r(p,b)}static msm(b,T){return gi(p,s,b,T)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}p.BASE=new p(i.Gx,i.Gy,Me,c(i.Gx*i.Gy)),p.ZERO=new p(_n,Me,Me,_n),p.Fp=n,p.Fn=s;let g=new pi(p,s.BITS);return p.BASE.precompute(8),p}var Qc=class{constructor(e){this.ep=e}static fromBytes(e){Qh()}static fromHex(e){Qh()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Ct(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.init(this.ep.precompute(e,r))}toRawBytes(){return this.toBytes()}};function mA(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');gr(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:s,Fp:i,Fn:o}=t,a=r.randomBytes||bt,c=r.adjustScalarBytes||(I=>I),u=r.domain||((I,k,L)=>{if(zr(L,"phflag"),k.length||L)throw new Error("Contexts/pre-hash are not supported");return I});function f(I){return o.create(Pt(I))}function l(I){let k=w.secretKey;I=oe("private key",I,k);let L=oe("hashed private key",e(I),2*k),P=c(L.slice(0,k)),E=L.slice(k,2*k),B=f(P);return{head:P,prefix:E,scalar:B}}function h(I){let{head:k,prefix:L,scalar:P}=l(I),E=s.multiply(P),B=E.toBytes();return{head:k,prefix:L,scalar:P,point:E,pointBytes:B}}function d(I){return h(I).pointBytes}function p(I=Uint8Array.of(),...k){let L=it(...k);return f(e(u(L,oe("context",I),!!n)))}function g(I,k,L={}){I=oe("message",I),n&&(I=n(I));let{prefix:P,scalar:E,pointBytes:B}=h(k),y=p(L.context,P,I),x=s.multiply(y).toBytes(),S=p(L.context,x,B,I),A=o.create(y+S*E);if(!o.isValid(A))throw new Error("sign failed: invalid s");let _=it(x,o.toBytes(A));return It(_,w.signature,"result")}let m={zip215:!0};function b(I,k,L,P=m){let{context:E,zip215:B}=P,y=w.signature;I=oe("signature",I,y),k=oe("message",k),L=oe("publicKey",L,w.publicKey),B!==void 0&&zr(B,"zip215"),n&&(k=n(k));let x=y/2,S=I.subarray(0,x),A=Pt(I.subarray(x,y)),_,D,U;try{_=t.fromBytes(L,B),D=t.fromBytes(S,B),U=s.multiplyUnsafe(A)}catch{return!1}if(!B&&_.isSmallOrder())return!1;let q=p(E,D.toBytes(),_.toBytes(),k);return D.add(_.multiplyUnsafe(q)).subtract(U).clearCofactor().is0()}let T=i.BYTES,w={secretKey:T,publicKey:T,signature:2*T,seed:T};function v(I=a(w.seed)){return It(I,w.seed,"seed")}function R(I){let k=N.randomSecretKey(I);return{secretKey:k,publicKey:d(k)}}function C(I){return Dr(I)&&I.length===o.BYTES}function O(I,k){try{return!!t.fromBytes(I,k)}catch{return!1}}let N={getExtendedPublicKey:h,randomSecretKey:v,isValidSecretKey:C,isValidPublicKey:O,toMontgomery(I){let{y:k}=t.fromBytes(I),L=w.publicKey,P=L===32;if(!P&&L!==57)throw new Error("only defined for 25519 and 448");let E=P?i.div(Me+k,Me-k):i.div(k-Me,k+Me);return i.toBytes(E)},toMontgomerySecret(I){let k=w.secretKey;It(I,k);let L=e(I.subarray(0,k));return c(L).subarray(0,k)},randomPrivateKey:v,precompute(I=8,k=t.BASE){return k.precompute(I,!1)}};return Object.freeze({keygen:R,getPublicKey:d,sign:g,verify:b,utils:N,Point:t,lengths:w})}function yA(t){let e={a:t.a,d:t.d,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=ct(e.n,t.nBitLength,!0),s={Fp:r,Fn:n,uvRatio:t.uvRatio},i={randomBytes:t.randomBytes,adjustScalarBytes:t.adjustScalarBytes,domain:t.domain,prehash:t.prehash,mapToCurve:t.mapToCurve};return{CURVE:e,curveOpts:s,hash:t.hash,eddsaOpts:i}}function wA(t,e){let r=e.Point;return Object.assign({},e,{ExtendedPoint:r,CURVE:t,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function V1(t){let{CURVE:e,curveOpts:r,hash:n,eddsaOpts:s}=yA(t),i=gA(e,r),o=mA(i,n,s);return wA(t,o)}var vo=BigInt(0),mi=BigInt(1),eu=BigInt(2);function xA(t){return gr(t,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...t})}function $1(t){let e=xA(t),{P:r,type:n,adjustScalarBytes:s,powPminus2:i,randomBytes:o}=e,a=n==="x25519";if(!a&&n!=="x448")throw new Error("invalid type");let c=o||bt,u=a?255:448,f=a?32:56,l=BigInt(a?9:5),h=BigInt(a?121665:39081),d=a?eu**BigInt(254):eu**BigInt(447),p=a?BigInt(8)*eu**BigInt(251)-mi:BigInt(4)*eu**BigInt(445)-mi,g=d+p+mi,m=E=>de(E,r),b=T(l);function T(E){return xo(m(E),f)}function w(E){let B=oe("u coordinate",E,f);return a&&(B[31]&=127),m(Pt(B))}function v(E){return Pt(s(oe("scalar",E,f)))}function R(E,B){let y=N(w(B),v(E));if(y===vo)throw new Error("invalid private or public key received");return T(y)}function C(E){return R(E,b)}function O(E,B,y){let x=m(E*(B-y));return B=m(B-x),y=m(y+x),{x_2:B,x_3:y}}function N(E,B){En("u",E,vo,r),En("scalar",B,d,g);let y=B,x=E,S=mi,A=vo,_=E,D=mi,U=vo;for(let z=BigInt(u-1);z>=vo;z--){let V=y>>z&mi;U^=V,{x_2:S,x_3:_}=O(U,S,_),{x_2:A,x_3:D}=O(U,A,D),U=V;let H=S+A,W=m(H*H),J=S-A,ee=m(J*J),Y=W-ee,ne=_+D,Se=_-D,je=m(Se*H),Ke=m(ne*J),zt=je+Ke,Vt=je-Ke;_=m(zt*zt),D=m(x*m(Vt*Vt)),S=m(W*ee),A=m(Y*(W+m(h*Y)))}({x_2:S,x_3:_}=O(U,S,_)),{x_2:A,x_3:D}=O(U,A,D);let q=i(A);return m(S*q)}let I={secretKey:f,publicKey:f,seed:f},k=(E=c(f))=>(be(E,I.seed),E);function L(E){let B=k(E);return{secretKey:B,publicKey:C(B)}}return{keygen:L,getSharedSecret:(E,B)=>R(E,B),getPublicKey:E=>C(E),scalarMult:R,scalarMultBase:C,utils:{randomSecretKey:k,randomPrivateKey:k},GuBytes:b.slice(),lengths:I}}var bA=BigInt(0),Kr=BigInt(1),j1=BigInt(2),EA=BigInt(3),vA=BigInt(5),_A=BigInt(8),yi=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),_o={p:yi,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:_A,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function G1(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),i=yi,a=t*t%i*t%i,c=Ut(a,j1,i)*a%i,u=Ut(c,Kr,i)*t%i,f=Ut(u,vA,i)*u%i,l=Ut(f,e,i)*f%i,h=Ut(l,r,i)*l%i,d=Ut(h,n,i)*h%i,p=Ut(d,s,i)*d%i,g=Ut(p,s,i)*d%i,m=Ut(g,e,i)*f%i;return{pow_p_5_8:Ut(m,j1,i)*t%i,b2:a}}function Y1(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var ad=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ld(t,e){let r=yi,n=de(e*e*e,r),s=de(n*n*e,r),i=G1(t*s).pow_p_5_8,o=de(t*n*i,r),a=de(e*o*o,r),c=o,u=de(o*ad,r),f=a===t,l=a===de(-t,r),h=a===de(-t*ad,r);return f&&(o=c),(l||h)&&(o=u),Vr(o,r)&&(o=de(-o,r)),{isValid:f||l,value:o}}var jr=ct(_o.p,{isLE:!0}),SA=ct(_o.n,{isLE:!0}),IA={..._o,Fp:jr,hash:qc,adjustScalarBytes:Y1,uvRatio:ld},xs=V1(IA);var tu=(()=>{let t=jr.ORDER;return $1({P:t,type:"x25519",powPminus2:e=>{let{pow_p_5_8:r,b2:n}=G1(e);return de(Ut(r,EA,t)*n,t)},adjustScalarBytes:Y1})})();var cd=ad,BA=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),AA=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),TA=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),RA=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),K1=t=>ld(Kr,t),DA=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ud=t=>xs.Point.Fp.create(Pt(t)&DA);function W1(t){let{d:e}=_o,r=yi,n=b=>jr.create(b),s=n(cd*t*t),i=n((s+Kr)*TA),o=BigInt(-1),a=n((o-e*s)*n(s+e)),{isValid:c,value:u}=ld(i,a),f=n(u*t);Vr(f,r)||(f=n(-f)),c||(u=f),c||(o=s);let l=n(o*(s-Kr)*RA-a),h=u*u,d=n((u+u)*a),p=n(l*BA),g=n(Kr-h),m=n(Kr+h);return new xs.Point(n(d*m),n(g*p),n(p*m),n(d*g))}function OA(t){be(t,64);let e=ud(t.subarray(0,32)),r=W1(e),n=ud(t.subarray(32,64)),s=W1(n);return new Wr(r.add(s))}var Wr=class t extends Qc{constructor(e){super(e)}static fromAffine(e){return new t(xs.Point.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static hashToCurve(e){return OA(oe("ristrettoHash",e,64))}static fromBytes(e){be(e,32);let{a:r,d:n}=_o,s=yi,i=v=>jr.create(v),o=ud(e);if(!_1(jr.toBytes(o),e)||Vr(o,s))throw new Error("invalid ristretto255 encoding 1");let a=i(o*o),c=i(Kr+r*a),u=i(Kr-r*a),f=i(c*c),l=i(u*u),h=i(r*n*f-l),{isValid:d,value:p}=K1(i(h*l)),g=i(p*u),m=i(p*g*h),b=i((o+o)*g);Vr(b,s)&&(b=i(-b));let T=i(c*m),w=i(b*T);if(!d||Vr(w,s)||T===bA)throw new Error("invalid ristretto255 encoding 2");return new t(new xs.Point(b,T,Kr,w))}static fromHex(e){return t.fromBytes(oe("ristrettoHex",e,32))}static msm(e,r){return gi(t,xs.Point.Fn,e,r)}toBytes(){let{X:e,Y:r,Z:n,T:s}=this.ep,i=yi,o=m=>jr.create(m),a=o(o(n+r)*o(n-r)),c=o(e*r),u=o(c*c),{value:f}=K1(o(a*u)),l=o(f*a),h=o(f*c),d=o(l*h*s),p;if(Vr(s*d,i)){let m=o(r*cd),b=o(e*cd);e=m,r=b,p=o(l*AA)}else p=h;Vr(e*d,i)&&(r=o(-r));let g=o((n-r)*p);return Vr(g,i)&&(g=o(-g)),jr.toBytes(g)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:s,Y:i}=e.ep,o=u=>jr.create(u),a=o(r*i)===o(n*s),c=o(n*i)===o(r*s);return a||c}is0(){return this.equals(t.ZERO)}};Wr.BASE=new Wr(xs.Point.BASE);Wr.ZERO=new Wr(xs.Point.ZERO);Wr.Fp=jr;Wr.Fn=SA;var J1=(t,e)=>(t+(t>=0?e:-e)/X1)/e;function CA(t,e,r){let[[n,s],[i,o]]=e,a=J1(o*t,r),c=J1(-s*t,r),u=t-a*n-c*i,f=-a*s-c*o,l=u<Yr,h=f<Yr;l&&(u=-u),h&&(f=-f);let d=vn(Math.ceil(Jc(r)/2))+xi;if(u<Yr||u>=d||f<Yr||f>=d)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:l,k1:u,k2neg:h,k2:f}}function hd(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function fd(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return zr(r.lowS,"lowS"),zr(r.prehash,"prehash"),r.format!==void 0&&hd(r.format),r}var dd=class extends Error{constructor(e=""){super(e)}},Gr={Err:dd,_tlv:{encode:(t,e)=>{let{Err:r}=Gr;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=wo(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?wo(s.length/2|128):"";return wo(t)+i+s+e},decode(t,e){let{Err:r}=Gr,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)o=o<<8|f;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(t){let{Err:e}=Gr;if(t<Yr)throw new e("integer: negative integers are not allowed");let r=wo(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Gr;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return fi(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Gr,s=oe("signature",t),{v:i,l:o}=n.decode(48,s);if(o.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Gr,n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),i=n+s;return e.encode(48,i)}},Yr=BigInt(0),xi=BigInt(1),X1=BigInt(2),ru=BigInt(3),NA=BigInt(4);function wi(t,e){let{BYTES:r}=t,n;if(typeof e=="bigint")n=e;else{let s=oe("private key",e);try{n=t.fromBytes(s)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`)}}if(!t.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function PA(t,e={}){let r=Zc("weierstrass",t,e),{Fp:n,Fn:s}=r,i=r.CURVE,{h:o,n:a}=i;gr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=e;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Q1(n,s);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(P,E,B){let{x:y,y:x}=E.toAffine(),S=n.toBytes(y);if(zr(B,"isCompressed"),B){f();let A=!n.isOdd(x);return it(Z1(A),S)}else return it(Uint8Array.of(4),S,n.toBytes(x))}function h(P){It(P,void 0,"Point");let{publicKey:E,publicKeyUncompressed:B}=u,y=P.length,x=P[0],S=P.subarray(1);if(y===E&&(x===2||x===3)){let A=n.fromBytes(S);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let _=g(A),D;try{D=n.sqrt(_)}catch(z){let V=z instanceof Error?": "+z.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}f();let U=n.isOdd(D);return(x&1)===1!==U&&(D=n.neg(D)),{x:A,y:D}}else if(y===B&&x===4){let A=n.BYTES,_=n.fromBytes(S.subarray(0,A)),D=n.fromBytes(S.subarray(A,A*2));if(!m(_,D))throw new Error("bad point: is not on curve");return{x:_,y:D}}else throw new Error(`bad point: got length ${y}, expected compressed=${E} or uncompressed=${B}`)}let d=e.toBytes||l,p=e.fromBytes||h;function g(P){let E=n.sqr(P),B=n.mul(E,P);return n.add(n.add(B,n.mul(P,i.a)),i.b)}function m(P,E){let B=n.sqr(E),y=g(P);return n.eql(B,y)}if(!m(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(i.a,ru),NA),T=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(b,T)))throw new Error("bad curve params: a or b");function w(P,E,B=!1){if(!n.isValid(E)||B&&n.is0(E))throw new Error(`bad point coordinate ${P}`);return E}function v(P){if(!(P instanceof I))throw new Error("ProjectivePoint expected")}function R(P){if(!c||!c.basises)throw new Error("no endo");return CA(P,c.basises,s.ORDER)}let C=hi((P,E)=>{let{X:B,Y:y,Z:x}=P;if(n.eql(x,n.ONE))return{x:B,y};let S=P.is0();E==null&&(E=S?n.ONE:n.inv(x));let A=n.mul(B,E),_=n.mul(y,E),D=n.mul(x,E);if(S)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:A,y:_}}),O=hi(P=>{if(P.is0()){if(e.allowInfinityPoint&&!n.is0(P.Y))return;throw new Error("bad point: ZERO")}let{x:E,y:B}=P.toAffine();if(!n.isValid(E)||!n.isValid(B))throw new Error("bad point: x or y not field elements");if(!m(E,B))throw new Error("bad point: equation left != right");if(!P.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function N(P,E,B,y,x){return B=new I(n.mul(B.X,P),B.Y,B.Z),E=Eo(y,E),B=Eo(x,B),E.add(B)}class I{constructor(E,B,y){this.X=w("x",E),this.Y=w("y",B,!0),this.Z=w("z",y),Object.freeze(this)}static CURVE(){return i}static fromAffine(E){let{x:B,y}=E||{};if(!E||!n.isValid(B)||!n.isValid(y))throw new Error("invalid affine point");if(E instanceof I)throw new Error("projective point not allowed");return n.is0(B)&&n.is0(y)?I.ZERO:new I(B,y,n.ONE)}static fromBytes(E){let B=I.fromAffine(p(It(E,void 0,"point")));return B.assertValidity(),B}static fromHex(E){return I.fromBytes(oe("pointHex",E))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(E=8,B=!0){return L.createCache(this,E),B||this.multiply(ru),this}assertValidity(){O(this)}hasEvenY(){let{y:E}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(E)}equals(E){v(E);let{X:B,Y:y,Z:x}=this,{X:S,Y:A,Z:_}=E,D=n.eql(n.mul(B,_),n.mul(S,x)),U=n.eql(n.mul(y,_),n.mul(A,x));return D&&U}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:E,b:B}=i,y=n.mul(B,ru),{X:x,Y:S,Z:A}=this,_=n.ZERO,D=n.ZERO,U=n.ZERO,q=n.mul(x,x),z=n.mul(S,S),V=n.mul(A,A),H=n.mul(x,S);return H=n.add(H,H),U=n.mul(x,A),U=n.add(U,U),_=n.mul(E,U),D=n.mul(y,V),D=n.add(_,D),_=n.sub(z,D),D=n.add(z,D),D=n.mul(_,D),_=n.mul(H,_),U=n.mul(y,U),V=n.mul(E,V),H=n.sub(q,V),H=n.mul(E,H),H=n.add(H,U),U=n.add(q,q),q=n.add(U,q),q=n.add(q,V),q=n.mul(q,H),D=n.add(D,q),V=n.mul(S,A),V=n.add(V,V),q=n.mul(V,H),_=n.sub(_,q),U=n.mul(V,z),U=n.add(U,U),U=n.add(U,U),new I(_,D,U)}add(E){v(E);let{X:B,Y:y,Z:x}=this,{X:S,Y:A,Z:_}=E,D=n.ZERO,U=n.ZERO,q=n.ZERO,z=i.a,V=n.mul(i.b,ru),H=n.mul(B,S),W=n.mul(y,A),J=n.mul(x,_),ee=n.add(B,y),Y=n.add(S,A);ee=n.mul(ee,Y),Y=n.add(H,W),ee=n.sub(ee,Y),Y=n.add(B,x);let ne=n.add(S,_);return Y=n.mul(Y,ne),ne=n.add(H,J),Y=n.sub(Y,ne),ne=n.add(y,x),D=n.add(A,_),ne=n.mul(ne,D),D=n.add(W,J),ne=n.sub(ne,D),q=n.mul(z,Y),D=n.mul(V,J),q=n.add(D,q),D=n.sub(W,q),q=n.add(W,q),U=n.mul(D,q),W=n.add(H,H),W=n.add(W,H),J=n.mul(z,J),Y=n.mul(V,Y),W=n.add(W,J),J=n.sub(H,J),J=n.mul(z,J),Y=n.add(Y,J),H=n.mul(W,Y),U=n.add(U,H),H=n.mul(ne,Y),D=n.mul(ee,D),D=n.sub(D,H),H=n.mul(ee,W),q=n.mul(ne,q),q=n.add(q,H),new I(D,U,q)}subtract(E){return this.add(E.negate())}is0(){return this.equals(I.ZERO)}multiply(E){let{endo:B}=e;if(!s.isValidNot0(E))throw new Error("invalid scalar: out of range");let y,x,S=A=>L.cached(this,A,_=>$r(I,_));if(B){let{k1neg:A,k1:_,k2neg:D,k2:U}=R(E),{p:q,f:z}=S(_),{p:V,f:H}=S(U);x=z.add(H),y=N(B.beta,q,V,A,D)}else{let{p:A,f:_}=S(E);y=A,x=_}return $r(I,[y,x])[0]}multiplyUnsafe(E){let{endo:B}=e,y=this;if(!s.isValid(E))throw new Error("invalid scalar: out of range");if(E===Yr||y.is0())return I.ZERO;if(E===xi)return y;if(L.hasCache(this))return this.multiply(E);if(B){let{k1neg:x,k1:S,k2neg:A,k2:_}=R(E),{p1:D,p2:U}=z1(I,y,S,_);return N(B.beta,D,U,x,A)}else return L.unsafe(y,E)}multiplyAndAddUnsafe(E,B,y){let x=this.multiplyUnsafe(B).add(E.multiplyUnsafe(y));return x.is0()?void 0:x}toAffine(E){return C(this,E)}isTorsionFree(){let{isTorsionFree:E}=e;return o===xi?!0:E?E(I,this):L.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:E}=e;return o===xi?this:E?E(I,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(E=!0){return zr(E,"isCompressed"),this.assertValidity(),d(I,this,E)}toHex(E=!0){return Ct(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 $r(I,E)}static msm(E,B){return gi(I,s,E,B)}static fromPrivateKey(E){return I.BASE.multiply(wi(s,E))}}I.BASE=new I(i.Gx,i.Gy,n.ONE),I.ZERO=new I(n.ZERO,n.ONE,n.ZERO),I.Fp=n,I.Fn=s;let k=s.BITS,L=new pi(I,e.endo?Math.ceil(k/2):k);return I.BASE.precompute(8),I}function Z1(t){return Uint8Array.of(t?2:3)}function Q1(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function UA(t,e={}){let{Fn:r}=t,n=e.randomBytes||bt,s=Object.assign(Q1(t.Fp,r),{seed:rd(r.ORDER)});function i(d){try{return!!wi(r,d)}catch{return!1}}function o(d,p){let{publicKey:g,publicKeyUncompressed:m}=s;try{let b=d.length;return p===!0&&b!==g||p===!1&&b!==m?!1:!!t.fromBytes(d)}catch{return!1}}function a(d=n(s.seed)){return L1(It(d,s.seed,"seed"),r.ORDER)}function c(d,p=!0){return t.BASE.multiply(wi(r,d)).toBytes(p)}function u(d){let p=a(d);return{secretKey:p,publicKey:c(p)}}function f(d){if(typeof d=="bigint")return!1;if(d instanceof t)return!0;let{secretKey:p,publicKey:g,publicKeyUncompressed:m}=s;if(r.allowedLengths||p===g)return;let b=oe("key",d).length;return b===g||b===m}function l(d,p,g=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");let m=wi(r,d);return t.fromHex(p).multiply(m).toBytes(g)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:u,Point:t,utils:{isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a,isValidPrivateKey:i,randomPrivateKey:a,normPrivateKeyToScalar:d=>wi(r,d),precompute(d=8,p=t.BASE){return p.precompute(d,!1)}},lengths:s})}function LA(t,e,r={}){es(e),gr(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||bt,s=r.hmac||((B,...y)=>li(e,B,it(...y))),{Fp:i,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:u,getPublicKey:f,getSharedSecret:l,utils:h,lengths:d}=UA(t,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function m(B){let y=a>>xi;return B>y}function b(B,y){if(!o.isValidNot0(y))throw new Error(`invalid signature ${B}: out of range 1..Point.Fn.ORDER`);return y}function T(B,y){hd(y);let x=d.signature,S=y==="compact"?x:y==="recovered"?x+1:void 0;return It(B,S,`${y} signature`)}class w{constructor(y,x,S){this.r=b("r",y),this.s=b("s",x),S!=null&&(this.recovery=S),Object.freeze(this)}static fromBytes(y,x=g){T(y,x);let S;if(x==="der"){let{r:U,s:q}=Gr.toSig(It(y));return new w(U,q)}x==="recovered"&&(S=y[0],x="compact",y=y.subarray(1));let A=o.BYTES,_=y.subarray(0,A),D=y.subarray(A,A*2);return new w(o.fromBytes(_),o.fromBytes(D),S)}static fromHex(y,x){return this.fromBytes(rs(y),x)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let x=i.ORDER,{r:S,s:A,recovery:_}=this;if(_==null||![0,1,2,3].includes(_))throw new Error("recovery id invalid");if(a*X1<x&&_>1)throw new Error("recovery id is ambiguous for h>1 curve");let U=_===2||_===3?S+a:S;if(!i.isValid(U))throw new Error("recovery id 2 or 3 invalid");let q=i.toBytes(U),z=t.fromBytes(it(Z1((_&1)===0),q)),V=o.inv(U),H=R(oe("msgHash",y)),W=o.create(-H*V),J=o.create(A*V),ee=t.BASE.multiplyUnsafe(W).add(z.multiplyUnsafe(J));if(ee.is0())throw new Error("point at infinify");return ee.assertValidity(),ee}hasHighS(){return m(this.s)}toBytes(y=g){if(hd(y),y==="der")return rs(Gr.hexFromSig(this));let x=o.toBytes(this.r),S=o.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return it(Uint8Array.of(this.recovery),x,S)}return it(x,S)}toHex(y){return Ct(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(oe("sig",y),"compact")}static fromDER(y){return w.fromBytes(oe("sig",y),"der")}normalizeS(){return this.hasHighS()?new w(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Ct(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Ct(this.toBytes("compact"))}}let v=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let x=fi(y),S=y.length*8-c;return S>0?x>>BigInt(S):x},R=r.bits2int_modN||function(y){return o.create(v(y))},C=vn(c);function O(B){return En("num < 2^"+c,B,Yr,C),o.toBytes(B)}function N(B,y){return It(B,void 0,"message"),y?It(e(B),void 0,"prehashed message"):B}function I(B,y,x){if(["recovered","canonical"].some(W=>W in x))throw new Error("sign() legacy options not supported");let{lowS:S,prehash:A,extraEntropy:_}=fd(x,p);B=N(B,A);let D=R(B),U=wi(o,y),q=[O(U),O(D)];if(_!=null&&_!==!1){let W=_===!0?n(d.secretKey):_;q.push(oe("extraEntropy",W))}let z=it(...q),V=D;function H(W){let J=v(W);if(!o.isValidNot0(J))return;let ee=o.inv(J),Y=t.BASE.multiply(J).toAffine(),ne=o.create(Y.x);if(ne===Yr)return;let Se=o.create(ee*o.create(V+ne*U));if(Se===Yr)return;let je=(Y.x===ne?0:2)|Number(Y.y&xi),Ke=Se;return S&&m(Se)&&(Ke=o.neg(Se),je^=1),new w(ne,Ke,je)}return{seed:z,k2sig:H}}function k(B,y,x={}){B=oe("message",B);let{seed:S,k2sig:A}=I(B,y,x);return I1(e.outputLen,o.BYTES,s)(S,A)}function L(B){let y,x=typeof B=="string"||Dr(B),S=!x&&B!==null&&typeof B=="object"&&typeof B.r=="bigint"&&typeof B.s=="bigint";if(!x&&!S)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(S)y=new w(B.r,B.s);else if(x){try{y=w.fromBytes(oe("sig",B),"der")}catch(A){if(!(A instanceof Gr.Err))throw A}if(!y)try{y=w.fromBytes(oe("sig",B),"compact")}catch{return!1}}return y||!1}function P(B,y,x,S={}){let{lowS:A,prehash:_,format:D}=fd(S,p);if(x=oe("publicKey",x),y=N(oe("message",y),_),"strict"in S)throw new Error("options.strict was renamed to lowS");let U=D===void 0?L(B):w.fromBytes(oe("sig",B),D);if(U===!1)return!1;try{let q=t.fromBytes(x);if(A&&U.hasHighS())return!1;let{r:z,s:V}=U,H=R(y),W=o.inv(V),J=o.create(H*W),ee=o.create(z*W),Y=t.BASE.multiplyUnsafe(J).add(q.multiplyUnsafe(ee));return Y.is0()?!1:o.create(Y.x)===z}catch{return!1}}function E(B,y,x={}){let{prehash:S}=fd(x,p);return y=N(y,S),w.fromBytes(B,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:l,utils:h,lengths:d,Point:t,sign:k,verify:P,recoverPublicKey:E,Signature:w,hash:e})}function kA(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0,s=ct(e.n,{BITS:t.nBitLength,allowedLengths:n,modFromBytes:t.wrapPrivateKey}),i={Fp:r,Fn:s,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:i}}function MA(t){let{CURVE:e,curveOpts:r}=kA(t),n={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:r,hash:t.hash,ecdsaOpts:n}}function qA(t,e){let r=e.Point;return Object.assign({},e,{ProjectivePoint:r,CURVE:Object.assign({},t,Xc(r.Fn.ORDER,r.Fn.BITS))})}function ex(t){let{CURVE:e,curveOpts:r,hash:n,ecdsaOpts:s}=MA(t),i=PA(e,r),o=LA(i,n,s);return qA(t,o)}function nu(t,e){let r=n=>ex({...t,hash:n});return{...r(e),create:r}}var tx={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},rx={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},nx={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},FA=ct(tx.p),HA=ct(rx.p),zA=ct(nx.p);var sx=nu({...tx,Fp:FA,lowS:!1},gs);var Q7=nu({...rx,Fp:HA,lowS:!1},e1);var e9=nu({...nx,Fp:zA,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},qc);var ix=sx;var ox={waku:{publish:"waku_publish",batchPublish:"waku_batchPublish",subscribe:"waku_subscribe",batchSubscribe:"waku_batchSubscribe",subscription:"waku_subscription",unsubscribe:"waku_unsubscribe",batchUnsubscribe:"waku_batchUnsubscribe",batchFetchMessages:"waku_batchFetchMessages"},irn:{publish:"irn_publish",batchPublish:"irn_batchPublish",subscribe:"irn_subscribe",batchSubscribe:"irn_batchSubscribe",subscription:"irn_subscription",unsubscribe:"irn_unsubscribe",batchUnsubscribe:"irn_batchUnsubscribe",batchFetchMessages:"irn_batchFetchMessages"},iridium:{publish:"iridium_publish",batchPublish:"iridium_batchPublish",subscribe:"iridium_subscribe",batchSubscribe:"iridium_batchSubscribe",subscription:"iridium_subscription",unsubscribe:"iridium_unsubscribe",batchUnsubscribe:"iridium_batchUnsubscribe",batchFetchMessages:"iridium_batchFetchMessages"}};var Cx=Ie(Bx(),1);var ZA=":";function Ro(t){let[e,r]=t.split(ZA);return{namespace:e,reference:r}}function Nx(t,e){return t.includes(":")?[t]:e.chains||[]}var QA={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}},eT={NOT_INITIALIZED:{message:"Not initialized.",code:1},NO_MATCHING_KEY:{message:"No matching key.",code:2},RESTORE_WILL_OVERRIDE:{message:"Restore will override.",code:3},RESUBSCRIBED:{message:"Resubscribed.",code:4},MISSING_OR_INVALID:{message:"Missing or invalid.",code:5},EXPIRED:{message:"Expired.",code:6},UNKNOWN_TYPE:{message:"Unknown type.",code:7},MISMATCHED_TOPIC:{message:"Mismatched topic.",code:8},NON_CONFORMING_NAMESPACES:{message:"Non conforming namespaces.",code:9}};function F(t,e){let{message:r,code:n}=eT[t];return{message:e?`${r} ${e}`:r,code:n}}function pe(t,e){let{message:r,code:n}=QA[t];return{message:e?`${r} ${e}`:r,code:n}}var tT="ReactNative",mt={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"};var rT="js";function Do(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function Xr(){return!(0,Yt.getDocument)()&&!!(0,Yt.getNavigator)()&&navigator.product===tT}function Px(){return Xr()&&typeof globalThis<"u"&&typeof globalThis?.Platform<"u"&&globalThis?.Platform.OS==="android"}function Ux(){return Xr()&&typeof globalThis<"u"&&typeof globalThis?.Platform<"u"&&globalThis?.Platform.OS==="ios"}function _s(){return!Do()&&!!(0,Yt.getNavigator)()&&!!(0,Yt.getDocument)()}function Oo(){return Xr()?mt.reactNative:Do()?mt.node:_s()?mt.browser:mt.unknown}function xd(){try{return Xr()&&typeof globalThis<"u"&&typeof globalThis?.Application<"u"?globalThis.Application?.applicationId:void 0}catch{return}}function nT(t,e){let r=new URLSearchParams(t);return Object.entries(e).sort(([n],[s])=>n.localeCompare(s)).forEach(([n,s])=>{s!=null&&r.set(n,String(s))}),r.toString()}function Lx(t){let e=bd();try{return t?.url&&e.url&&new URL(t.url).host!==new URL(e.url).host&&(console.warn(`The configured WalletConnect 'metadata.url':${t.url} differs from the actual page url:${e.url}. This is probably unintended and can lead to issues.`),t.url=e.url),t?.icons?.length&&t.icons.length>0&&(t.icons=t.icons.filter(r=>r!=="")),{...e,...t,url:t?.url||e.url,name:t?.name||e.name,description:t?.description||e.description,icons:t?.icons?.length&&t.icons.length>0?t.icons:e.icons}}catch(r){return console.warn("Error populating app metadata",r),t||e}}function bd(){return(0,Ox.getWindowMetadata)()||{name:"",description:"",url:"",icons:[""]}}function sT(){if(Oo()===mt.reactNative&&typeof globalThis<"u"&&typeof globalThis?.Platform<"u"){let{OS:r,Version:n}=globalThis.Platform;return[r,n].join("-")}let t=Fm();if(t===null)return"unknown";let e=t.os?t.os.replace(" ","").toLowerCase():"unknown";return t.type==="browser"?[e,t.name,t.version].join("-"):[e,t.version].join("-")}function iT(){let t=Oo();return t===mt.browser?[t,(0,Yt.getLocation)()?.host||"unknown"].join(":"):t}function Ed(t,e,r){let n=sT(),s=iT();return[[t,e].join("-"),[rT,r].join("-"),n,s].join("/")}function kx({protocol:t,version:e,relayUrl:r,sdkVersion:n,auth:s,projectId:i,useOnCloseEvent:o,bundleId:a,packageName:c}){let u=r.split("?"),f=Ed(t,e,n),l={auth:s,ua:f,projectId:i,useOnCloseEvent:o||void 0,packageName:c||void 0,bundleId:a||void 0},h=nT(u[1]||"",l);return u[0]+"?"+h}function bs(t,e){return t.filter(r=>e.includes(r)).length===t.length}function hu(t){return Object.fromEntries(t.entries())}function du(t){return new Map(Object.entries(t))}function Zr(t=Jr.FIVE_MINUTES,e){let r=(0,Jr.toMiliseconds)(t||Jr.FIVE_MINUTES),n,s,i,o;return{resolve:a=>{i&&n&&(clearTimeout(i),n(a),o=Promise.resolve(a))},reject:a=>{i&&s&&(clearTimeout(i),s(a))},done:()=>new Promise((a,c)=>{if(o)return a(o);i=setTimeout(()=>{let u=F("EXPIRED"),f=new Error(e||u.message);f.code=u.code,c(f)},r),n=a,s=c})}}function Lt(t,e,r){return new Promise(async(n,s)=>{let i=setTimeout(()=>s(new Error(r)),e);try{let o=await t;n(o)}catch(o){s(o)}clearTimeout(i)})}function Mx(t,e){if(typeof e=="string"&&e.startsWith(`${t}:`))return e;if(t.toLowerCase()==="topic"){if(typeof e!="string")throw new Error('Value must be "string" for expirer target type: topic');return`topic:${e}`}else if(t.toLowerCase()==="id"){if(typeof e!="number")throw new Error('Value must be "number" for expirer target type: id');return`id:${e}`}throw new Error(`Unknown expirer target type: ${t}`)}function qx(t){return Mx("topic",t)}function Fx(t){return Mx("id",t)}function pu(t){let[e,r]=t.split(":"),n={id:void 0,topic:void 0};if(e==="topic"&&typeof r=="string")n.topic=r;else if(e==="id"&&Number.isInteger(Number(r)))n.id=Number(r);else throw new Error(`Invalid target, expected id:number or topic:string, got ${e}:${r}`);return n}function _e(t,e){return(0,Jr.fromMiliseconds)((e||Date.now())+(0,Jr.toMiliseconds)(t))}function mr(t){return Date.now()>=(0,Jr.toMiliseconds)(t)}function ae(t,e){return`${t}${e?`:${e}`:""}`}function Es(t=[],e=[]){return[...new Set([...t,...e])]}async function Hx({id:t,topic:e,wcDeepLink:r}){try{if(!r)return;let n=(typeof r=="string"?JSON.parse(r):r)?.href;if(typeof n!="string")return;let s=oT(n,t,e),i=Oo();if(i===mt.browser){if(!(0,Yt.getDocument)()?.hasFocus()){console.warn("Document does not have focus, skipping deeplink.");return}aT(s)}else i===mt.reactNative&&typeof globalThis?.Linking<"u"&&await globalThis.Linking.openURL(s)}catch(n){console.error(n)}}function oT(t,e,r){let n=`requestId=${e}&sessionTopic=${r}`;t.endsWith("/")&&(t=t.slice(0,-1));let s=`${t}`;if(t.startsWith("https://t.me")){let i=t.includes("?")?"&startapp=":"?startapp=";s=`${s}${i}${lT(n,!0)}`}else s=`${s}/wc?${n}`;return s}function aT(t){let e="_self";uT()?e="_top":(cT()||t.startsWith("https://")||t.startsWith("http://"))&&(e="_blank"),window.open(t,e,"noreferrer noopener")}async function zx(t,e){let r="";try{if(_s()&&(r=localStorage.getItem(e),r))return r;r=await t.getItem(e)}catch(n){console.error(n)}return r}function vd(t,e){if(!t.includes(e))return null;let r=t.split(/([&,?,=])/),n=r.indexOf(e);return r[n+2]}function _d(){return typeof crypto<"u"&&crypto?.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/gu,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function Co(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function cT(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function uT(){try{return window.self!==window.top}catch{return!1}}function lT(t,e=!1){let r=new TextEncoder().encode(t),n=new Array(r.length);for(let i=0;i<r.length;i++)n[i]=String.fromCharCode(r[i]);let s=btoa(n.join(""));return e?s.replace(/[=]/g,""):s}function Vx(t){let e=t+"=".repeat((4-t.length%4)%4),r=atob(e),n=new Uint8Array(r.length);for(let s=0;s<r.length;s++)n[s]=r.charCodeAt(s);return new TextDecoder().decode(n)}function $x(t){return new Promise(e=>setTimeout(e,t))}var cu=class{constructor({limit:e}){this.limit=e,this.set=new Set}add(e){if(!this.set.has(e)){if(this.set.size>=this.limit){let r=this.set.values().next().value;r&&this.set.delete(r)}this.set.add(e)}}has(e){return this.set.has(e)}},fT="https://rpc.walletconnect.org/v1";function bi(t){let e=t+"=".repeat((4-t.length%4)%4),r=atob(e),n=new Uint8Array(r.length);for(let s=0;s<r.length;s++)n[s]=r.charCodeAt(s);return n}function jx(t){let e=`Ethereum Signed Message:
|
|
${t.length}`,r=new TextEncoder().encode(e+t);return"0x"+Ee(hy(r),"base16")}async function hT(t,e,r,n,s,i){switch(r.t){case"eip191":return await dT(t,e,r.s);case"eip1271":return await pT(t,e,r.s,n,s,i);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${r.t}`)}}function dT(t,e,r){let n=Tc.fromHex(r);return Nc.recoverAddress({payload:jx(e),signature:n}).toLowerCase()===t.toLowerCase()}async function pT(t,e,r,n,s,i){let o=Ro(n);if(!o.namespace||!o.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${n}`);try{let a="0x1626ba7e",c="0000000000000000000000000000000000000000000000000000000000000040",u=r.substring(2),f=(u.length/2).toString(16).padStart(64,"0"),l=(e.startsWith("0x")?e:jx(e)).substring(2),h=a+l+c+f+u,d=await fetch(`${i||fT}/?chainId=${n}&projectId=${s}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify({id:gT(),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:h},"latest"]})}),{result:p}=await d.json();return p?p.slice(0,a.length).toLowerCase()===a.toLowerCase():!1}catch(a){return console.error("isValidEip1271Signature: ",a),!1}}function gT(){return Date.now()+Math.floor(Math.random()*1e3)}function Kx(t){let e=bi(t),r=e[0];if(r===0)throw new Error("No signatures found");let n=1+r*64;if(e.length<n)throw new Error("Transaction data too short for claimed signature count");if(e.length<100)throw new Error("Transaction too short");let s=e.slice(1,65);return ci.encode(s)}function Wx(t){let e=bi(t),r=new TextEncoder().encode("TransactionData::"),n=new Uint8Array(r.length+e.length);n.set(r),n.set(e,r.length);let s=n1(n,{dkLen:32});return ci.encode(s)}function Sd(t){let e=new Uint8Array(gs(mT(t)));return ci.encode(e)}function mT(t){if(t instanceof Uint8Array)return t;if(Array.isArray(t))return new Uint8Array(t);if(typeof t=="object"&&t?.data)return new Uint8Array(Object.values(t.data));if(typeof t=="object"&&t)return new Uint8Array(Object.values(t));throw new Error("getNearUint8ArrayFromBytes: Unexpected result type from bytes array")}function Id(t){let e=bi(t),r=Vh(e).txn;if(!r)throw new Error("Invalid signed transaction: missing 'txn' field");let n=qh(r),s=new TextEncoder().encode("TX"),i=Hr([s,new Uint8Array(n)]),o=t1(i);return qw.encode(o).replace(/=+$/,"")}function yd(t){let e=[],r=BigInt(t);for(;r>=0x80n;)e.push(Number(r&0x7fn|0x80n)),r>>=7n;return e.push(Number(r)),new Uint8Array(e)}function Gx(t){let e=bi(t.signed.bodyBytes),r=bi(t.signed.authInfoBytes),n=bi(t.signature.signature),s=[];s.push(new Uint8Array([10])),s.push(yd(e.length)),s.push(e),s.push(new Uint8Array([18])),s.push(yd(r.length)),s.push(r),s.push(new Uint8Array([26])),s.push(yd(n.length)),s.push(n);let i=Hr(s),o=gs(i);return Ee(o,"base16").toUpperCase()}function Yx(t){let e=[];try{if(typeof t=="string")return e.push(t),e;if(typeof t!="object")return e;t?.id&&e.push(t.id);let r=t?.capabilities?.caip345?.transactionHashes;r&&e.push(...r)}catch(r){console.warn("getWalletSendCallsHashes failed: ",r)}return e}var Jx="did:pkh:",yT={eip155:"Ethereum",solana:"Solana",bip122:"Bitcoin"},wT=t=>t?yT[t]||t:"",gu=t=>t?.split(":"),xT=t=>{let e=t&&gu(t);if(e)return t.includes(Jx)?e[3]:e[1]},bT=t=>{let e=t&&gu(t);if(e)return t.includes(Jx)?e[2]:e[0]},mu=t=>{let e=t&&gu(t);if(e)return e[2]+":"+e[3]},No=t=>{let e=t&&gu(t);if(e)return e.pop()};async function Bd(t){let{cacao:e,projectId:r}=t,{s:n,p:s}=e,i=Ad(s,s.iss),o=No(s.iss);return await hT(o,i,n,mu(s.iss),r)}var Ad=(t,e)=>{let r=bT(e);if(!r)throw new Error("Invalid issuer: "+e);let n=`${t.domain} wants you to sign in with your ${wT(r)} account:`,s=No(e);if(!t.aud&&!t.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let i=t.statement||void 0,o=`URI: ${t.aud||t.uri}`,a=`Version: ${t.version}`,c=`Chain ID: ${xT(e)}`,u=`Nonce: ${t.nonce}`,f=`Issued At: ${t.iat}`,l=t.exp?`Expiration Time: ${t.exp}`:void 0,h=t.nbf?`Not Before: ${t.nbf}`:void 0,d=t.requestId?`Request ID: ${t.requestId}`:void 0,p=t.resources?`Resources:${t.resources.map(m=>`
|
|
- ${m}`).join("")}`:void 0,g=Po(t.resources);if(g){let m=To(g);i=AT(i,m)}return[n,s,"",i,"",o,a,c,u,f,l,h,d,p].filter(m=>m!=null).join(`
|
|
`)};function ET(t){let e=JSON.stringify(t),r=new TextEncoder().encode(e),n=new Array(r.length);for(let s=0;s<r.length;s++)n[s]=String.fromCharCode(r[s]);return btoa(n.join(""))}function vT(t){let e=t+"=".repeat((4-t.length%4)%4),r=atob(e),n=new Uint8Array(r.length);for(let s=0;s<r.length;s++)n[s]=r.charCodeAt(s);return JSON.parse(new TextDecoder().decode(n))}function vs(t){if(!t)throw new Error("No recap provided, value is undefined");if(!t.att)throw new Error("No `att` property found");let e=Object.keys(t.att);if(!e?.length)throw new Error("No resources found in `att` property");e.forEach(r=>{let n=t.att[r];if(Array.isArray(n))throw new Error(`Resource must be an object: ${r}`);if(typeof n!="object")throw new Error(`Resource must be an object: ${r}`);if(!Object.keys(n).length)throw new Error(`Resource object is empty: ${r}`);Object.keys(n).forEach(s=>{let i=n[s];if(!Array.isArray(i))throw new Error(`Ability limits ${s} must be an array of objects, found: ${i}`);if(!i.length)throw new Error(`Value of ${s} is empty array, must be an array with objects`);i.forEach(o=>{if(typeof o!="object")throw new Error(`Ability limits (${s}) must be an array of objects, found: ${o}`)})})})}function _T(t,e,r,n={}){return r?.sort((s,i)=>s.localeCompare(i)),{att:{[t]:ST(e,r,n)}}}function ST(t,e,r={}){e=e?.sort((s,i)=>s.localeCompare(i));let n=e.map(s=>({[`${t}/${s}`]:[r]}));return Object.assign({},...n)}function Xx(t){return vs(t),`urn:recap:${ET(t).replace(/=/g,"")}`}function To(t){let e=vT(t.replace("urn:recap:",""));return vs(e),e}function Zx(t,e,r){let n=_T(t,e,r);return Xx(n)}function IT(t){return t&&t.includes("urn:recap:")}function Qx(t,e){let r=To(t),n=To(e),s=BT(r,n);return Xx(s)}function BT(t,e){vs(t),vs(e);let r=Object.keys(t.att).concat(Object.keys(e.att)).sort((s,i)=>s.localeCompare(i)),n={att:{}};return r.forEach(s=>{Object.keys(t.att?.[s]||{}).concat(Object.keys(e.att?.[s]||{})).sort((i,o)=>i.localeCompare(o)).forEach(i=>{n.att[s]={...n.att[s],[i]:t.att[s]?.[i]||e.att[s]?.[i]}})}),n}function AT(t="",e){vs(e);let r="I further authorize the stated URI to perform the following actions on my behalf: ";if(t.includes(r))return t;let n=[],s=0;Object.keys(e.att).forEach(a=>{let c=Object.keys(e.att[a]).map(l=>({ability:l.split("/")[0],action:l.split("/")[1]}));c.sort((l,h)=>l.action.localeCompare(h.action));let u={};c.forEach(l=>{u[l.ability]||(u[l.ability]=[]),u[l.ability].push(l.action)});let f=Object.keys(u).map(l=>(s++,`(${s}) '${l}': '${u[l].join("', '")}' for '${a}'.`));n.push(f.join(", ").replace(".,","."))});let i=n.join(" "),o=`${r}${i}`;return`${t?t+" ":""}${o}`}function Td(t){let e=To(t);vs(e);let r=e.att?.eip155;return r?Object.keys(r).map(n=>n.split("/")[1]):[]}function Rd(t){let e=To(t);vs(e);let r=[];return Object.values(e.att).forEach(n=>{Object.values(n).forEach(s=>{s?.[0]?.chains&&r.push(s[0].chains)})}),[...new Set(r.flat())]}function Po(t){if(!t)return;let e=t?.[t.length-1];return IT(e)?e:void 0}var eb="base10",tt="base16",Oe="base64pad",Qr="base64url",Uo="utf8",tb=0,Jt=1,Ei=2,TT=0,Ax=1,Ao=12,Dd=32;function rb(){let t=tu.utils.randomPrivateKey(),e=tu.getPublicKey(t);return{privateKey:Ee(t,tt),publicKey:Ee(e,tt)}}function yu(){let t=bt(Dd);return Ee(t,tt)}function nb(t,e){let r=tu.getSharedSecret(Re(t,tt),Re(e,tt)),n=E1(yo,r,void 0,void 0,Dd);return Ee(n,tt)}function vi(t){let e=yo(Re(t,tt));return Ee(e,tt)}function yt(t){let e=yo(Re(t,Uo));return Ee(e,tt)}function sb(t){return Re(`${t}`,eb)}function An(t){return Number(Ee(t,eb))}function ib(t){return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function uu(t){let e=t.replace(/-/g,"+").replace(/_/g,"/"),r=(4-e.length%4)%4;return e+"=".repeat(r)}function ob(t){let e=sb(typeof t.type<"u"?t.type:tb);if(An(e)===Jt&&typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");let r=typeof t.senderPublicKey<"u"?Re(t.senderPublicKey,tt):void 0,n=typeof t.iv<"u"?Re(t.iv,tt):bt(Ao),s=Re(t.symKey,tt),i=Wh(s,n).encrypt(Re(t.message,Uo)),o=lb({type:e,sealed:i,iv:n,senderPublicKey:r});return t.encoding===Qr?ib(o):o}function ab(t){let e=Re(t.symKey,tt),{sealed:r,iv:n}=_i({encoded:t.encoded,encoding:t.encoding}),s=Wh(e,n).decrypt(r);if(s===null)throw new Error("Failed to decrypt");return Ee(s,Uo)}function cb(t,e){let r=sb(Ei),n=bt(Ao),s=Re(t,Uo),i=lb({type:r,sealed:s,iv:n});return e===Qr?ib(i):i}function ub(t,e){let{sealed:r}=_i({encoded:t,encoding:e});return Ee(r,Uo)}function lb(t){if(An(t.type)===Ei)return Ee(Hr([t.type,t.sealed]),Oe);if(An(t.type)===Jt){if(typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return Ee(Hr([t.type,t.senderPublicKey,t.iv,t.sealed]),Oe)}return Ee(Hr([t.type,t.iv,t.sealed]),Oe)}function _i(t){let e=(t.encoding||Oe)===Qr?uu(t.encoded):t.encoded,r=Re(e,Oe),n=r.slice(TT,Ax),s=Ax;if(An(n)===Jt){let c=s+Dd,u=c+Ao,f=r.slice(s,c),l=r.slice(c,u),h=r.slice(u);return{type:n,sealed:h,iv:l,senderPublicKey:f}}if(An(n)===Ei){let c=r.slice(s),u=bt(Ao);return{type:n,sealed:c,iv:u}}let i=s+Ao,o=r.slice(s,i),a=r.slice(i);return{type:n,sealed:a,iv:o}}function fb(t,e){let r=_i({encoded:t,encoding:e?.encoding});return Od({type:An(r.type),senderPublicKey:typeof r.senderPublicKey<"u"?Ee(r.senderPublicKey,tt):void 0,receiverPublicKey:e?.receiverPublicKey})}function Od(t){let e=t?.type||tb;if(e===Jt){if(typeof t?.senderPublicKey>"u")throw new Error("missing sender public key");if(typeof t?.receiverPublicKey>"u")throw new Error("missing receiver public key")}return{type:e,senderPublicKey:t?.senderPublicKey,receiverPublicKey:t?.receiverPublicKey}}function Cd(t){return t.type===Jt&&typeof t.senderPublicKey=="string"&&typeof t.receiverPublicKey=="string"}function Nd(t){return t.type===Ei}function RT(t){let e=Re(uu(t.x),Oe),r=Re(uu(t.y),Oe);return Hr([new Uint8Array([4]),e,r])}function hb(t,e){let[r,n,s]=t.split("."),i=Re(uu(s),Oe);if(i.length!==64)throw new Error("Invalid signature length");let o=i.slice(0,32),a=i.slice(32,64),c=`${r}.${n}`,u=yo(c),f=RT(e);if(!ix.verify(Hr([o,a]),u,f))throw new Error("Invalid signature");return ji(t).payload}var DT="irn";function Lo(t){return t?.relay||{protocol:DT}}function Ss(t){let e=ox[t];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${t}`);return e}function OT(t,e="-"){let r={},n="relay"+e;return Object.keys(t).forEach(s=>{if(s.startsWith(n)){let i=s.replace(n,""),o=t[s];r[i]=o}}),r}function Pd(t){if(!t.includes("wc:")){let u=Vx(t);u?.includes("wc:")&&(t=u)}t=t.includes("wc://")?t.replace("wc://",""):t,t=t.includes("wc:")?t.replace("wc:",""):t;let e=t.indexOf(":"),r=t.indexOf("?")!==-1?t.indexOf("?"):void 0,n=t.substring(0,e),s=t.substring(e+1,r).split("@"),i=typeof r<"u"?t.substring(r):"",o=new URLSearchParams(i),a=Object.fromEntries(o.entries()),c=typeof a.methods=="string"?a.methods.split(","):void 0;return{protocol:n,topic:CT(s[0]),version:parseInt(s[1],10),symKey:a.symKey,relay:OT(a),methods:c,expiryTimestamp:a.expiryTimestamp?parseInt(a.expiryTimestamp,10):void 0}}function CT(t){return t.startsWith("//")?t.substring(2):t}function NT(t,e="-"){let r="relay",n={};return Object.keys(t).forEach(s=>{let i=s,o=r+e+i;t[i]&&(n[o]=t[i])}),n}function Ud(t){let e=new URLSearchParams,r={...NT(t.relay),symKey:t.symKey,...t.expiryTimestamp&&{expiryTimestamp:t.expiryTimestamp.toString()},...t.methods&&{methods:t.methods.join(",")}};return Object.entries(r).sort(([n],[s])=>n.localeCompare(s)).forEach(([n,s])=>{s!==void 0&&e.append(n,String(s))}),`${t.protocol}:${t.topic}@${t.version}?${e}`}function ko(t,e,r){return`${t}?wc_ev=${r}&topic=${e}`}function Si(t){let e=[];return t.forEach(r=>{let[n,s]=r.split(":");e.push(`${n}:${s}`)}),e}function Ld(t){let e=[];return Object.values(t).forEach(r=>{e.push(...Si(r.accounts))}),[...new Set(e)]}function db(t){let e=[];return Object.values(t).forEach(r=>{e.push(...r.methods)}),[...new Set(e)]}function pb(t){let e=[];return Object.values(t).forEach(r=>{e.push(...r.events)}),[...new Set(e)]}function PT(t,e){let r=[];return Object.values(t).forEach(n=>{Si(n.accounts).includes(e)&&r.push(...n.methods)}),r}function UT(t,e){let r=[];return Object.values(t).forEach(n=>{Si(n.accounts).includes(e)&&r.push(...n.events)}),r}function gb(t){return t.includes(":")}function LT(t){return gb(t)?t.split(":")[0]:t}function Tx(t){let e={};if(!Ii(t))return e;for(let[r,n]of Object.entries(t)){let s=gb(r)?[r]:n.chains,i=n.methods||[],o=n.events||[],a=LT(r);e[a]={...e[a],chains:Es(s,e[a]?.chains),methods:Es(i,e[a]?.methods),events:Es(o,e[a]?.events)}}return e}function kT(t){let e={};return t?.forEach(r=>{let[n,s]=r.split(":");e[n]||(e[n]={accounts:[],chains:[],events:[],methods:[]}),e[n].accounts.push(r),e[n].chains?.push(`${n}:${s}`)}),e}function kd(t,e){e=e.map(n=>n.replace("did:pkh:",""));let r=kT(e);for(let[n,s]of Object.entries(r))s.methods?s.methods=Es(s.methods,t):s.methods=t,s.events=["chainChanged","accountsChanged"];return r}function mb(t,e){let r=Tx(t),n=Tx(e),s={},i=Object.keys(r).concat(Object.keys(n));for(let o of i)s[o]={chains:Es(r[o]?.chains,n[o]?.chains),methods:Es(r[o]?.methods,n[o]?.methods),events:Es(r[o]?.events,n[o]?.events)};return s}function Is(t,e){return Array.isArray(t)?typeof e<"u"&&t.length?t.every(e):!0:!1}function Ii(t){return Object.getPrototypeOf(t)===Object.prototype&&Object.keys(t).length}function ve(t){return typeof t>"u"}function me(t,e){return e&&ve(t)?!0:typeof t=="string"&&!!t.trim().length}function Md(t,e){return e&&ve(t)?!0:typeof t=="number"&&!isNaN(t)}function yb(t,e){let{requiredNamespaces:r}=e,n=Object.keys(t.namespaces),s=Object.keys(r),i=!0;return bs(s,n)?(n.forEach(o=>{let{accounts:a,methods:c,events:u}=t.namespaces[o],f=Si(a),l=r[o];(!bs(Nx(o,l),f)||!bs(l.methods,c)||!bs(l.events,u))&&(i=!1)}),i):!1}function lu(t){return me(t,!1)&&t.includes(":")?t.split(":").length===2:!1}function MT(t){if(me(t,!1)&&t.includes(":")){let e=t.split(":");if(e.length===3){let r=e[0]+":"+e[1];return!!e[2]&&lu(r)}}return!1}function wb(t){function e(r){try{return typeof new URL(r)<"u"}catch{return!1}}try{if(me(t,!1)){if(e(t))return!0;let r=Vx(t);return e(r)}}catch{}return!1}function xb(t){return t?.proposer?.publicKey}function bb(t){return t?.topic}function Eb(t,e){let r=null;return me(t?.publicKey,!1)||(r=F("MISSING_OR_INVALID",`${e} controller public key should be a string`)),r}function Rx(t){let e=!0;return Is(t)?t.length&&(e=t.every(r=>me(r,!1))):e=!1,e}function qT(t,e,r){let n=null;return Is(e)&&e.length?e.forEach(s=>{n||lu(s)||(n=pe("UNSUPPORTED_CHAINS",`${r}, chain ${s} should be a string and conform to "namespace:chainId" format`))}):lu(t)||(n=pe("UNSUPPORTED_CHAINS",`${r}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),n}function FT(t,e,r){let n=null;return Object.entries(t).forEach(([s,i])=>{if(n)return;let o=qT(s,Nx(s,i),`${e} ${r}`);o&&(n=o)}),n}function HT(t,e){let r=null;return Is(t)?t.forEach(n=>{r||MT(n)||(r=pe("UNSUPPORTED_ACCOUNTS",`${e}, account ${n} should be a string and conform to "namespace:chainId:address" format`))}):r=pe("UNSUPPORTED_ACCOUNTS",`${e}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),r}function zT(t,e){let r=null;return Object.values(t).forEach(n=>{if(r)return;let s=HT(n?.accounts,`${e} namespace`);s&&(r=s)}),r}function VT(t,e){let r=null;return Rx(t?.methods)?Rx(t?.events)||(r=pe("UNSUPPORTED_EVENTS",`${e}, events should be an array of strings or empty array for no events`)):r=pe("UNSUPPORTED_METHODS",`${e}, methods should be an array of strings or empty array for no methods`),r}function vb(t,e){let r=null;return Object.values(t).forEach(n=>{if(r)return;let s=VT(n,`${e}, namespace`);s&&(r=s)}),r}function _b(t,e,r){let n=null;if(t&&Ii(t)){let s=vb(t,e);s&&(n=s);let i=FT(t,e,r);i&&(n=i)}else n=F("MISSING_OR_INVALID",`${e}, ${r} should be an object with data`);return n}function wu(t,e){let r=null;if(t&&Ii(t)){let n=vb(t,e);n&&(r=n);let s=zT(t,e);s&&(r=s)}else r=F("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return r}function qd(t){return me(t.protocol,!0)}function Sb(t,e){let r=!1;return e&&!t?r=!0:t&&Is(t)&&t.length&&t.forEach(n=>{r=qd(n)}),r}function Ib(t){return typeof t=="number"}function rt(t){return typeof t<"u"&&typeof t!==null}function Bb(t){return!(!t||typeof t!="object"||!t.code||!Md(t.code,!1)||!t.message||!me(t.message,!1))}function Ab(t){return!(ve(t)||!me(t.method,!1))}function Tb(t){return!(ve(t)||ve(t.result)&&ve(t.error)||!Md(t.id,!1)||!me(t.jsonrpc,!1))}function Rb(t){return!(ve(t)||!me(t.name,!1))}function Fd(t,e){return!(!lu(e)||!Ld(t).includes(e))}function Db(t,e,r){return me(r,!1)?PT(t,e).includes(r):!1}function Ob(t,e,r){return me(r,!1)?UT(t,e).includes(r):!1}function Hd(t,e,r){let n=null,s=$T(t),i=jT(e),o=Object.keys(s),a=Object.keys(i),c=Dx(Object.keys(t)),u=Dx(Object.keys(e)),f=c.filter(l=>!u.includes(l));return f.length&&(n=F("NON_CONFORMING_NAMESPACES",`${r} namespaces keys don't satisfy requiredNamespaces.
|
|
Required: ${f.toString()}
|
|
Received: ${Object.keys(e).toString()}`)),bs(o,a)||(n=F("NON_CONFORMING_NAMESPACES",`${r} namespaces chains don't satisfy required namespaces.
|
|
Required: ${o.toString()}
|
|
Approved: ${a.toString()}`)),Object.keys(e).forEach(l=>{if(!l.includes(":")||n)return;let h=Si(e[l].accounts);h.includes(l)||(n=F("NON_CONFORMING_NAMESPACES",`${r} namespaces accounts don't satisfy namespace accounts for ${l}
|
|
Required: ${l}
|
|
Approved: ${h.toString()}`))}),o.forEach(l=>{n||(bs(s[l].methods,i[l].methods)?bs(s[l].events,i[l].events)||(n=F("NON_CONFORMING_NAMESPACES",`${r} namespaces events don't satisfy namespace events for ${l}`)):n=F("NON_CONFORMING_NAMESPACES",`${r} namespaces methods don't satisfy namespace methods for ${l}`))}),n}function $T(t){let e={};return Object.keys(t).forEach(r=>{r.includes(":")?e[r]=t[r]:t[r].chains?.forEach(n=>{e[n]={methods:t[r].methods,events:t[r].events}})}),e}function Dx(t){return[...new Set(t.map(e=>e.includes(":")?e.split(":")[0]:e))]}function jT(t){let e={};return Object.keys(t).forEach(r=>{r.includes(":")?e[r]=t[r]:Si(t[r].accounts)?.forEach(n=>{e[n]={accounts:t[r].accounts.filter(s=>s.includes(`${n}:`)),methods:t[r].methods,events:t[r].events}})}),e}function Cb(t,e){return Md(t,!1)&&t<=e.max&&t>=e.min}function zd(){let t=Oo();return new Promise(e=>{switch(t){case mt.browser:e(KT());break;case mt.reactNative:e(WT());break;case mt.node:e(GT());break;default:e(!0)}})}function KT(){return _s()&&navigator?.onLine}async function WT(){return Xr()&&typeof globalThis<"u"&&globalThis?.NetInfo?(await globalThis?.NetInfo.fetch())?.isConnected:!0}function GT(){return!0}function Nb(t){switch(Oo()){case mt.browser:YT(t);break;case mt.reactNative:JT(t);break;case mt.node:break}}function YT(t){!Xr()&&_s()&&(window.addEventListener("online",()=>t(!0)),window.addEventListener("offline",()=>t(!1)))}function JT(t){Xr()&&typeof globalThis<"u"&&globalThis?.NetInfo&&globalThis?.NetInfo.addEventListener(e=>t(e?.isConnected))}function Pb(){return _s()&&(0,Yt.getDocument)()?(0,Yt.getDocument)()?.visibilityState==="visible":!0}var wd={},Tn=class{static get(e){return wd[e]}static set(e,r){wd[e]=r}static delete(e){delete wd[e]}};function XT(t){let e=ci.decode(t);if(e.length<33)throw new Error("Too short to contain a public key");return e.slice(1,33)}function ZT({publicKey:t,signature:e,payload:r}){let n=fu(r.method),s=128|parseInt(r.version?.toString()||"4"),i=t5(r.address),o=r.era==="00"?new Uint8Array([0]):fu(r.era);if(o.length!==1&&o.length!==2)throw new Error("Invalid era length");let a=parseInt(r.nonce,16),c=new Uint8Array([a&255,a>>8&255]),u=BigInt(`0x${e5(r.tip)}`),f=n5(u),l=new Uint8Array([0,...t,i,...e,...o,...c,...f,...n]),h=r5(l.length+1);return new Uint8Array([...h,s,...l])}function QT(t){let e=fu(t),r=(0,Cx.blake2b)(e,void 0,32);return"0x"+Ee(r,"base16")}function fu(t){return new Uint8Array(t.replace(/^0x/,"").match(/.{1,2}/g).map(e=>parseInt(e,16)))}function e5(t){return t.startsWith("0x")?t.slice(2):t}function t5(t){let e=ci.decode(t)[0];return e===42?0:e===60?2:1}function r5(t){if(t<64)return new Uint8Array([t<<2]);if(t<16384){let e=t<<2|1;return new Uint8Array([e&255,e>>8&255])}else if(t<1<<30){let e=t<<2|2;return new Uint8Array([e&255,e>>8&255,e>>16&255,e>>24&255])}else throw new Error("Compact encoding > 2^30 not supported")}function n5(t){if(t<1n<<6n)return new Uint8Array([Number(t<<2n)]);if(t<1n<<14n){let e=t<<2n|0x01n;return new Uint8Array([Number(e&0xffn),Number(e>>8n&0xffn)])}else if(t<1n<<30n){let e=t<<2n|0x02n;return new Uint8Array([Number(e&0xffn),Number(e>>8n&0xffn),Number(e>>16n&0xffn),Number(e>>24n&0xffn)])}else throw new Error("BigInt compact encoding not supported > 2^30")}function Ub(t){let e=fu(t.signature),r=XT(t.transaction.address),n=ZT({publicKey:r,signature:e,payload:t.transaction}),s=Ee(n,"base16");return QT(s)}function xu({logger:t,name:e}){let r=typeof t=="string"?va({opts:{level:t,name:e}}).logger:t;return r.level=typeof t=="string"?t:t.level,r}var Xb=Ie($n());var st={};Ce(st,{DEFAULT_ERROR:()=>qo,IBaseJsonRpcProvider:()=>Tu,IEvents:()=>Fo,IJsonRpcConnection:()=>Wd,IJsonRpcProvider:()=>Ho,INTERNAL_ERROR:()=>bu,INVALID_PARAMS:()=>qb,INVALID_REQUEST:()=>kb,METHOD_NOT_FOUND:()=>Mb,PARSE_ERROR:()=>Lb,RESERVED_ERROR_CODES:()=>Vd,SERVER_ERROR:()=>Mo,SERVER_ERROR_CODE_RANGE:()=>Eu,STANDARD_ERROR_MAP:()=>Rn,formatErrorMessage:()=>Yb,formatJsonRpcError:()=>As,formatJsonRpcRequest:()=>Bt,formatJsonRpcResult:()=>Bs,getBigIntRpcId:()=>Mt,getError:()=>_u,getErrorByCode:()=>Su,isHttpUrl:()=>p5,isJsonRpcError:()=>nt,isJsonRpcPayload:()=>Yd,isJsonRpcRequest:()=>Bi,isJsonRpcResponse:()=>Cn,isJsonRpcResult:()=>At,isJsonRpcValidationInvalid:()=>g5,isLocalhostUrl:()=>Gd,isNodeJs:()=>Gb,isReservedErrorCode:()=>vu,isServerErrorCode:()=>s5,isValidDefaultRoute:()=>Bu,isValidErrorCode:()=>Fb,isValidLeadingWildcardRoute:()=>u5,isValidRoute:()=>c5,isValidTrailingWildcardRoute:()=>l5,isValidWildcardRoute:()=>Au,isWsUrl:()=>Ru,parseConnectionError:()=>$d,payloadId:()=>kt,validateJsonRpcError:()=>i5});var Lb="PARSE_ERROR",kb="INVALID_REQUEST",Mb="METHOD_NOT_FOUND",qb="INVALID_PARAMS",bu="INTERNAL_ERROR",Mo="SERVER_ERROR",Vd=[-32700,-32600,-32601,-32602,-32603],Eu=[-32e3,-32099],Rn={[Lb]:{code:-32700,message:"Parse error"},[kb]:{code:-32600,message:"Invalid Request"},[Mb]:{code:-32601,message:"Method not found"},[qb]:{code:-32602,message:"Invalid params"},[bu]:{code:-32603,message:"Internal error"},[Mo]:{code:-32e3,message:"Server error"}},qo=Mo;function s5(t){return t<=Eu[0]&&t>=Eu[1]}function vu(t){return Vd.includes(t)}function Fb(t){return typeof t=="number"}function _u(t){return Object.keys(Rn).includes(t)?Rn[t]:Rn[qo]}function Su(t){let e=Object.values(Rn).find(r=>r.code===t);return e||Rn[qo]}function i5(t){if(typeof t.error.code>"u")return{valid:!1,error:"Missing code for JSON-RPC error"};if(typeof t.error.message>"u")return{valid:!1,error:"Missing message for JSON-RPC error"};if(!Fb(t.error.code))return{valid:!1,error:`Invalid error code type for JSON-RPC: ${t.error.code}`};if(vu(t.error.code)){let e=Su(t.error.code);if(e.message!==Rn[qo].message&&t.error.message===e.message)return{valid:!1,error:`Invalid error code message for JSON-RPC: ${t.error.code}`}}return{valid:!0}}function $d(t,e,r){return t.message.includes("getaddrinfo ENOTFOUND")||t.message.includes("connect ECONNREFUSED")?new Error(`Unavailable ${r} RPC url at ${e}`):t}var ut={};Ce(ut,{isNodeJs:()=>Gb});var Wb=Ie(Kd());wt(ut,Ie(Kd()));var Gb=Wb.isNode;wt(st,ut);function kt(t=3){let e=Date.now()*Math.pow(10,t),r=Math.floor(Math.random()*Math.pow(10,t));return e+r}function Mt(t=6){return BigInt(kt(t))}function Bt(t,e,r){return{id:r||kt(),jsonrpc:"2.0",method:t,params:e}}function Bs(t,e){return{id:t,jsonrpc:"2.0",result:e}}function As(t,e,r){return{id:t,jsonrpc:"2.0",error:Yb(e,r)}}function Yb(t,e){return typeof t>"u"?_u(bu):(typeof t=="string"&&(t=Object.assign(Object.assign({},_u(Mo)),{message:t})),typeof e<"u"&&(t.data=e),vu(t.code)&&(t=Su(t.code)),t)}function c5(t){return t.includes("*")?Au(t):!/\W/g.test(t)}function Bu(t){return t==="*"}function Au(t){return Bu(t)?!0:!(!t.includes("*")||t.split("*").length!==2||t.split("*").filter(e=>e.trim()==="").length!==1)}function u5(t){return!Bu(t)&&Au(t)&&!t.split("*")[0].trim()}function l5(t){return!Bu(t)&&Au(t)&&!t.split("*")[1].trim()}var Fo=class{},Wd=class extends Fo{constructor(e){super()}},Tu=class extends Fo{constructor(){super()}},Ho=class extends Tu{constructor(e){super()}};var f5="^https?:",h5="^wss?:";function d5(t){let e=t.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function Jb(t,e){let r=d5(t);return typeof r>"u"?!1:new RegExp(e).test(r)}function p5(t){return Jb(t,f5)}function Ru(t){return Jb(t,h5)}function Gd(t){return new RegExp("wss?://localhost(:d{2,5})?").test(t)}function Yd(t){return typeof t=="object"&&"id"in t&&"jsonrpc"in t&&t.jsonrpc==="2.0"}function Bi(t){return Yd(t)&&"method"in t}function Cn(t){return Yd(t)&&(At(t)||nt(t))}function At(t){return"result"in t}function nt(t){return"error"in t}function g5(t){return"error"in t&&t.valid===!1}var Du=class extends Ho{constructor(e){super(e),this.events=new Xb.EventEmitter,this.hasRegisteredEventListeners=!1,this.connection=this.setConnection(e),this.connection.connected&&this.registerEventListeners()}async connect(e=this.connection){await this.open(e)}async disconnect(){await this.close()}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async request(e,r){return this.requestStrict(Bt(e.method,e.params||[],e.id||Mt().toString()),r)}async requestStrict(e,r){return new Promise(async(n,s)=>{if(!this.connection.connected)try{await this.open()}catch(i){s(i)}this.events.on(`${e.id}`,i=>{nt(i)?s(i.error):n(i.result)});try{await this.connection.send(e,r)}catch(i){s(i)}})}setConnection(e=this.connection){return e}onPayload(e){this.events.emit("payload",e),Cn(e)?this.events.emit(`${e.id}`,e):this.events.emit("message",{type:e.method,data:e.params})}onClose(e){e&&e.code===3e3&&this.events.emit("error",new Error(`WebSocket connection closed abnormally with code: ${e.code} ${e.reason?`(${e.reason})`:""}`)),this.events.emit("disconnect")}async open(e=this.connection){this.connection===e&&this.connection.connected||(this.connection.connected&&this.close(),typeof e=="string"&&(await this.connection.open(e),e=this.connection),this.connection=this.setConnection(e),await this.connection.open(),this.registerEventListeners(),this.events.emit("connect"))}async close(){await this.connection.close()}registerEventListeners(){this.hasRegisteredEventListeners||(this.connection.on("payload",e=>this.onPayload(e)),this.connection.on("close",e=>this.onClose(e)),this.connection.on("error",e=>this.events.emit("error",e)),this.connection.on("register_error",e=>this.onClose()),this.hasRegisteredEventListeners=!0)}};var r2=Ie($n());var m5=()=>typeof WebSocket<"u"?WebSocket:typeof globalThis<"u"&&typeof globalThis.WebSocket<"u"?globalThis.WebSocket:typeof window<"u"&&typeof window.WebSocket<"u"?window.WebSocket:typeof self<"u"&&typeof self.WebSocket<"u"?self.WebSocket:Qb(),y5=()=>typeof WebSocket<"u"||typeof globalThis<"u"&&typeof globalThis.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u",e2=t=>t.split("?")[0],t2=10,w5=m5(),Ou=class{constructor(e){if(this.url=e,this.events=new r2.EventEmitter,this.registering=!1,!Ru(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);this.url=e}get connected(){return typeof this.socket<"u"}get connecting(){return this.registering}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async open(e=this.url){await this.register(e)}async close(){return new Promise((e,r)=>{if(typeof this.socket>"u"){r(new Error("Connection already closed"));return}this.socket.onclose=n=>{this.onClose(n),e()},this.socket.close()})}async send(e){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(Sr(e))}catch(r){this.onError(e.id,r)}}register(e=this.url){if(!Ru(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);if(this.registering){let r=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=r||this.events.listenerCount("open")>=r)&&this.events.setMaxListeners(r+1),new Promise((n,s)=>{this.events.once("register_error",i=>{this.resetMaxListeners(),s(i)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.socket>"u")return s(new Error("WebSocket connection is missing or invalid"));n(this.socket)})})}return this.url=e,this.registering=!0,new Promise((r,n)=>{let s=(0,st.isReactNative)()?void 0:{rejectUnauthorized:!Gd(e)},i=new w5(e,[],s);y5()?i.onerror=o=>{let a=o;n(this.emitError(a.error))}:i.on("error",o=>{n(this.emitError(o))}),i.onopen=()=>{this.onOpen(i),r(i)}})}onOpen(e){e.onmessage=r=>this.onPayload(r),e.onclose=r=>this.onClose(r),this.socket=e,this.registering=!1,this.events.emit("open")}onClose(e){this.socket=void 0,this.registering=!1,this.events.emit("close",e)}onPayload(e){if(typeof e.data>"u")return;let r=typeof e.data=="string"?nr(e.data):e.data;this.events.emit("payload",r)}onError(e,r){let n=this.parseError(r),s=n.message||n.toString(),i=As(e,s);this.events.emit("payload",i)}parseError(e,r=this.url){return $d(e,e2(r),"WS")}resetMaxListeners(){this.events.getMaxListeners()>t2&&this.events.setMaxListeners(t2)}emitError(e){let r=this.parseError(new Error(e?.message||`WebSocket connection failed for host: ${e2(this.url)}`));return this.events.emit("register_error",r),r}};function n2(t,e){return t===e||Number.isNaN(t)&&Number.isNaN(e)}function Jd(t){return Object.getOwnPropertySymbols(t).filter(e=>Object.prototype.propertyIsEnumerable.call(t,e))}function Xd(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}var s2="[object RegExp]",i2="[object String]",o2="[object Number]",a2="[object Boolean]",Zd="[object Arguments]",c2="[object Symbol]",u2="[object Date]",l2="[object Map]",f2="[object Set]",h2="[object Array]",d2="[object Function]",p2="[object ArrayBuffer]",Cu="[object Object]",g2="[object Error]",m2="[object DataView]",y2="[object Uint8Array]",w2="[object Uint8ClampedArray]",x2="[object Uint16Array]",b2="[object Uint32Array]",E2="[object BigUint64Array]",v2="[object Int8Array]",_2="[object Int16Array]",S2="[object Int32Array]",I2="[object BigInt64Array]",B2="[object Float32Array]",A2="[object Float64Array]";function Qd(t){if(!t||typeof t!="object")return!1;let e=Object.getPrototypeOf(t);return e===null||e===Object.prototype||Object.getPrototypeOf(e)===null?Object.prototype.toString.call(t)==="[object Object]":!1}function T2(t,e,r){return zo(t,e,void 0,void 0,void 0,void 0,r)}function zo(t,e,r,n,s,i,o){let a=o(t,e,r,n,s,i);if(a!==void 0)return a;if(typeof t==typeof e)switch(typeof t){case"bigint":case"string":case"boolean":case"symbol":case"undefined":return t===e;case"number":return t===e||Object.is(t,e);case"function":return t===e;case"object":return Vo(t,e,i,o)}return Vo(t,e,i,o)}function Vo(t,e,r,n){if(Object.is(t,e))return!0;let s=Xd(t),i=Xd(e);if(s===Zd&&(s=Cu),i===Zd&&(i=Cu),s!==i)return!1;switch(s){case i2:return t.toString()===e.toString();case o2:{let c=t.valueOf(),u=e.valueOf();return n2(c,u)}case a2:case u2:case c2:return Object.is(t.valueOf(),e.valueOf());case s2:return t.source===e.source&&t.flags===e.flags;case d2:return t===e}r=r??new Map;let o=r.get(t),a=r.get(e);if(o!=null&&a!=null)return o===e;r.set(t,e),r.set(e,t);try{switch(s){case l2:{if(t.size!==e.size)return!1;for(let[c,u]of t.entries())if(!e.has(c)||!zo(u,e.get(c),c,t,e,r,n))return!1;return!0}case f2:{if(t.size!==e.size)return!1;let c=Array.from(t.values()),u=Array.from(e.values());for(let f=0;f<c.length;f++){let l=c[f],h=u.findIndex(d=>zo(l,d,void 0,t,e,r,n));if(h===-1)return!1;u.splice(h,1)}return!0}case h2:case y2:case w2:case x2:case b2:case E2:case v2:case _2:case S2:case I2:case B2:case A2:{if(typeof Buffer<"u"&&Buffer.isBuffer(t)!==Buffer.isBuffer(e)||t.length!==e.length)return!1;for(let c=0;c<t.length;c++)if(!zo(t[c],e[c],c,t,e,r,n))return!1;return!0}case p2:return t.byteLength!==e.byteLength?!1:Vo(new Uint8Array(t),new Uint8Array(e),r,n);case m2:return t.byteLength!==e.byteLength||t.byteOffset!==e.byteOffset?!1:Vo(new Uint8Array(t),new Uint8Array(e),r,n);case g2:return t.name===e.name&&t.message===e.message;case Cu:{if(!(Vo(t.constructor,e.constructor,r,n)||Qd(t)&&Qd(e)))return!1;let u=[...Object.keys(t),...Jd(t)],f=[...Object.keys(e),...Jd(e)];if(u.length!==f.length)return!1;for(let l=0;l<u.length;l++){let h=u[l],d=t[h];if(!Object.hasOwn(e,h))return!1;let p=e[h];if(!zo(d,p,h,t,e,r,n))return!1}return!0}default:return!1}}finally{r.delete(t),r.delete(e)}}function R2(){}function ep(t,e){return T2(t,e,R2)}var C2=Ie(Ja(),1),N2="wc",P2=2,Pu="core",wr=`${N2}@2:${Pu}:`,x5={name:Pu,logger:"error"},b5={database:":memory:"},E5="crypto",D2="client_ed25519_seed",v5=G.ONE_DAY,_5="keychain",S5="0.3",I5="messages",B5="0.3",A5=G.SIX_HOURS,T5="publisher",gp="irn",R5="error",U2="wss://relay.walletconnect.org",D5="relayer",ye={message:"relayer_message",message_ack:"relayer_message_ack",connect:"relayer_connect",disconnect:"relayer_disconnect",error:"relayer_error",connection_stalled:"relayer_connection_stalled",transport_closed:"relayer_transport_closed",publish:"relayer_publish"},O5="_subscription",qt={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},C5=.1;var tp="2.23.9";var fe={link_mode:"link_mode",relay:"relay"},Nu={inbound:"inbound",outbound:"outbound"},N5="0.3",P5="WALLETCONNECT_CLIENT_ID",O2="WALLETCONNECT_LINK_MODE_APPS",Tt={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"};var U5="subscription",L5="0.3",Pk=G.FIVE_SECONDS*1e3,k5="pairing",M5="0.3";var $o={wc_pairingDelete:{req:{ttl:G.ONE_DAY,prompt:!1,tag:1e3},res:{ttl:G.ONE_DAY,prompt:!1,tag:1001}},wc_pairingPing:{req:{ttl:G.THIRTY_SECONDS,prompt:!1,tag:1002},res:{ttl:G.THIRTY_SECONDS,prompt:!1,tag:1003}},unregistered_method:{req:{ttl:G.ONE_DAY,prompt:!1,tag:0},res:{ttl:G.ONE_DAY,prompt:!1,tag:0}}},Nn={create:"pairing_create",expire:"pairing_expire",delete:"pairing_delete",ping:"pairing_ping"},Xt={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},q5="history",F5="0.3",H5="expirer",Rt={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},z5="0.3";var V5="verify-api",$5="https://verify.walletconnect.com",L2="https://verify.walletconnect.org",Ai=L2,j5=`${Ai}/v3`,K5=[$5,L2],W5="echo",G5="https://echo.walletconnect.com";var Zt={pairing_started:"pairing_started",pairing_uri_validation_success:"pairing_uri_validation_success",pairing_uri_not_expired:"pairing_uri_not_expired",store_new_pairing:"store_new_pairing",subscribing_pairing_topic:"subscribing_pairing_topic",subscribe_pairing_topic_success:"subscribe_pairing_topic_success",existing_pairing:"existing_pairing",pairing_not_expired:"pairing_not_expired",emit_inactive_pairing:"emit_inactive_pairing",emit_session_proposal:"emit_session_proposal",subscribing_to_pairing_topic:"subscribing_to_pairing_topic"},yr={no_wss_connection:"no_wss_connection",no_internet_connection:"no_internet_connection",malformed_pairing_uri:"malformed_pairing_uri",active_pairing_already_exists:"active_pairing_already_exists",subscribe_pairing_topic_failure:"subscribe_pairing_topic_failure",pairing_expired:"pairing_expired",proposal_expired:"proposal_expired",proposal_listener_not_found:"proposal_listener_not_found"},Ft={session_approve_started:"session_approve_started",proposal_not_expired:"proposal_not_expired",session_namespaces_validation_success:"session_namespaces_validation_success",create_session_topic:"create_session_topic",subscribing_session_topic:"subscribing_session_topic",subscribe_session_topic_success:"subscribe_session_topic_success",publishing_session_approve:"publishing_session_approve",session_approve_publish_success:"session_approve_publish_success",store_session:"store_session",publishing_session_settle:"publishing_session_settle",session_settle_publish_success:"session_settle_publish_success",session_request_response_started:"session_request_response_started",session_request_response_validation_success:"session_request_response_validation_success",session_request_response_publish_started:"session_request_response_publish_started"},Pn={no_internet_connection:"no_internet_connection",no_wss_connection:"no_wss_connection",proposal_expired:"proposal_expired",subscribe_session_topic_failure:"subscribe_session_topic_failure",session_approve_publish_failure:"session_approve_publish_failure",session_settle_publish_failure:"session_settle_publish_failure",session_approve_namespace_validation_failure:"session_approve_namespace_validation_failure",proposal_not_found:"proposal_not_found",session_request_response_validation_failure:"session_request_response_validation_failure",session_request_response_publish_failure:"session_request_response_publish_failure"},Un={authenticated_session_approve_started:"authenticated_session_approve_started",authenticated_session_not_expired:"authenticated_session_not_expired",chains_caip2_compliant:"chains_caip2_compliant",chains_evm_compliant:"chains_evm_compliant",create_authenticated_session_topic:"create_authenticated_session_topic",cacaos_verified:"cacaos_verified",store_authenticated_session:"store_authenticated_session",subscribing_authenticated_session_topic:"subscribing_authenticated_session_topic",subscribe_authenticated_session_topic_success:"subscribe_authenticated_session_topic_success",publishing_authenticated_session_approve:"publishing_authenticated_session_approve",authenticated_session_approve_publish_success:"authenticated_session_approve_publish_success"},Ti={no_internet_connection:"no_internet_connection",no_wss_connection:"no_wss_connection",missing_session_authenticate_request:"missing_session_authenticate_request",session_authenticate_request_expired:"session_authenticate_request_expired",chains_caip2_compliant_failure:"chains_caip2_compliant_failure",chains_evm_compliant_failure:"chains_evm_compliant_failure",invalid_cacao:"invalid_cacao",subscribe_authenticated_session_topic_failure:"subscribe_authenticated_session_topic_failure",authenticated_session_approve_publish_failure:"authenticated_session_approve_publish_failure",authenticated_session_pending_request_not_found:"authenticated_session_pending_request_not_found"},Y5=.1,J5="event-client",X5=86400,Z5="https://pulse.walletconnect.org/batch",rp=class{constructor(e,r){this.core=e,this.logger=r,this.keychain=new Map,this.name=_5,this.version=S5,this.initialized=!1,this.storagePrefix=wr,this.init=async()=>{if(!this.initialized){let n=await this.getKeyChain();typeof n<"u"&&(this.keychain=n),this.initialized=!0}},this.has=n=>(this.isInitialized(),this.keychain.has(n)),this.set=async(n,s)=>{this.isInitialized(),this.keychain.set(n,s),await this.persist()},this.get=n=>{this.isInitialized();let s=this.keychain.get(n);if(typeof s>"u"){let{message:i}=F("NO_MATCHING_KEY",`${this.name}: ${n}`);throw new Error(i)}return s},this.del=async n=>{this.isInitialized(),this.keychain.delete(n),await this.persist()},this.core=e,this.logger=ft(r,this.name)}get context(){return We(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(e){await this.core.storage.setItem(this.storageKey,hu(e))}async getKeyChain(){let e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?du(e):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}},np=class{constructor(e,r,n){this.core=e,this.logger=r,this.name=E5,this.randomSessionIdentifier=yu(),this.initialized=!1,this.init=async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)},this.hasKeys=s=>(this.isInitialized(),this.keychain.has(s)),this.getClientId=async()=>{if(this.isInitialized(),this.clientId)return this.clientId;let s=await this.getClientSeed(),i=lf(s),o=uf(i.publicKey);return this.clientId=o,o},this.generateKeyPair=()=>{this.isInitialized();let s=rb();return this.setPrivateKey(s.publicKey,s.privateKey)},this.signJWT=async s=>{this.isInitialized();let i=await this.getClientSeed(),o=lf(i),a=this.randomSessionIdentifier;return await gm(a,s,v5,o)},this.generateSharedKey=(s,i,o)=>{this.isInitialized();let a=this.getPrivateKey(s),c=nb(a,i);return this.setSymKey(c,o)},this.setSymKey=async(s,i)=>{this.isInitialized();let o=i||vi(s);return await this.keychain.set(o,s),o},this.deleteKeyPair=async s=>{this.isInitialized(),await this.keychain.del(s)},this.deleteSymKey=async s=>{this.isInitialized(),await this.keychain.del(s)},this.encode=async(s,i,o)=>{this.isInitialized();let a=Od(o),c=Sr(i);if(Nd(a))return cb(c,o?.encoding);if(Cd(a)){let h=a.senderPublicKey,d=a.receiverPublicKey;s=await this.generateSharedKey(h,d)}let u=this.getSymKey(s),{type:f,senderPublicKey:l}=a;return ob({type:f,symKey:u,message:c,senderPublicKey:l,encoding:o?.encoding})},this.decode=async(s,i,o)=>{this.isInitialized();let a=fb(i,o);if(Nd(a)){let c=ub(i,o?.encoding);return nr(c)}if(Cd(a)){let c=a.receiverPublicKey,u=a.senderPublicKey;s=await this.generateSharedKey(c,u)}try{let c=this.getSymKey(s),u=ab({symKey:c,encoded:i,encoding:o?.encoding});return nr(u)}catch(c){this.logger.error(`Failed to decode message from topic: '${s}', clientId: '${await this.getClientId()}'`),this.logger.error(c)}},this.getPayloadType=(s,i=Oe)=>{let o=_i({encoded:s,encoding:i});return An(o.type)},this.getPayloadSenderPublicKey=(s,i=Oe)=>{let o=_i({encoded:s,encoding:i});return o.senderPublicKey?Ee(o.senderPublicKey,tt):void 0},this.core=e,this.logger=ft(r,this.name),this.keychain=n||new rp(this.core,this.logger)}get context(){return We(this.logger)}async setPrivateKey(e,r){return await this.keychain.set(e,r),e}getPrivateKey(e){return this.keychain.get(e)}async getClientSeed(){let e="";try{e=this.keychain.get(D2)}catch{e=yu(),await this.keychain.set(D2,e)}return Re(e,"base16")}getSymKey(e){return this.keychain.get(e)}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}},sp=class extends Ia{constructor(e,r){super(e,r),this.logger=e,this.core=r,this.messages=new Map,this.messagesWithoutClientAck=new Map,this.name=I5,this.version=B5,this.initialized=!1,this.storagePrefix=wr,this.init=async()=>{if(!this.initialized){this.logger.trace("Initialized");try{let n=await this.getRelayerMessages();typeof n<"u"&&(this.messages=n);let s=await this.getRelayerMessagesWithoutClientAck();typeof s<"u"&&(this.messagesWithoutClientAck=s),this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",size:this.messages.size})}catch(n){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(n)}finally{this.initialized=!0}}},this.set=async(n,s,i)=>{this.isInitialized();let o=yt(s),a=this.messages.get(n);if(typeof a>"u"&&(a={}),typeof a[o]<"u")return o;if(a[o]=s,this.messages.set(n,a),i===Nu.inbound){let c=this.messagesWithoutClientAck.get(n)||{};this.messagesWithoutClientAck.set(n,{...c,[o]:s})}return await this.persist(),o},this.get=n=>{this.isInitialized();let s=this.messages.get(n);return typeof s>"u"&&(s={}),s},this.getWithoutAck=n=>{this.isInitialized();let s={};for(let i of n){let o=this.messagesWithoutClientAck.get(i)||{};s[i]=Object.values(o)}return s},this.has=(n,s)=>{this.isInitialized();let i=this.get(n),o=yt(s);return typeof i[o]<"u"},this.ack=async(n,s)=>{this.isInitialized();let i=this.messagesWithoutClientAck.get(n);if(typeof i>"u")return;let o=yt(s);delete i[o],Object.keys(i).length===0?this.messagesWithoutClientAck.delete(n):this.messagesWithoutClientAck.set(n,i),await this.persist()},this.del=async n=>{this.isInitialized(),this.messages.delete(n),this.messagesWithoutClientAck.delete(n),await this.persist()},this.logger=ft(e,this.name),this.core=r}get context(){return We(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get storageKeyWithoutClientAck(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name+"_withoutClientAck"}async setRelayerMessages(e){await this.core.storage.setItem(this.storageKey,hu(e))}async setRelayerMessagesWithoutClientAck(e){await this.core.storage.setItem(this.storageKeyWithoutClientAck,hu(e))}async getRelayerMessages(){let e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?du(e):void 0}async getRelayerMessagesWithoutClientAck(){let e=await this.core.storage.getItem(this.storageKeyWithoutClientAck);return typeof e<"u"?du(e):void 0}async persist(){await this.setRelayerMessages(this.messages),await this.setRelayerMessagesWithoutClientAck(this.messagesWithoutClientAck)}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}},ip=class extends Ba{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,this.events=new en.EventEmitter,this.name=T5,this.queue=new Map,this.publishTimeout=(0,G.toMiliseconds)(G.ONE_MINUTE),this.initialPublishTimeout=(0,G.toMiliseconds)(G.ONE_SECOND*15),this.needsTransportRestart=!1,this.publish=async(n,s,i)=>{this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:n,message:s,opts:i}});let o=i?.ttl||A5,a=i?.prompt||!1,c=i?.tag||0,u=i?.id||Mt().toString(),f=Ss(Lo().protocol),l={id:u,method:i?.publishMethod||f.publish,params:{topic:n,message:s,ttl:o,prompt:a,tag:c,attestation:i?.attestation,...i?.tvf}},h=`Failed to publish payload, please try again. id:${u} tag:${c}`;try{ve(l.params?.prompt)&&delete l.params?.prompt,ve(l.params?.tag)&&delete l.params?.tag;let d=new Promise(async p=>{let g=({id:b})=>{l.id?.toString()===b.toString()&&(this.removeRequestFromQueue(b),this.relayer.events.removeListener(ye.publish,g),p())};this.relayer.events.on(ye.publish,g);let m=Lt(new Promise((b,T)=>{this.rpcPublish(l,i).then(b).catch(w=>{this.logger.warn(w,w?.message),T(w)})}),this.initialPublishTimeout,`Failed initial publish, retrying.... id:${u} tag:${c}`);try{await m,this.events.removeListener(ye.publish,g)}catch(b){this.queue.set(u,{request:l,opts:i,attempt:1}),this.logger.warn(b,b?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:u,topic:n,message:s,opts:i}}),await Lt(d,this.publishTimeout,h)}catch(d){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(d),i?.internal?.throwOnFailedPublish)throw d}finally{this.queue.delete(u)}},this.publishCustom=async n=>{this.logger.debug("Publishing custom payload"),this.logger.trace({type:"method",method:"publishCustom",params:n});let{payload:s,opts:i={}}=n,{attestation:o,tvf:a,publishMethod:c,prompt:u,tag:f,ttl:l=G.FIVE_MINUTES}=i,h=i.id||Mt().toString(),d=Ss(Lo().protocol),p=c||d.publish,g={id:h,method:p,params:{...s,ttl:l,prompt:u,tag:f,attestation:o,...a}},m=`Failed to publish custom payload, please try again. id:${h} tag:${f}`;try{ve(g.params?.prompt)&&delete g.params?.prompt,ve(g.params?.tag)&&delete g.params?.tag;let b=new Promise(async T=>{let w=({id:R})=>{g.id?.toString()===R.toString()&&(this.removeRequestFromQueue(R),this.relayer.events.removeListener(ye.publish,w),T())};this.relayer.events.on(ye.publish,w);let v=Lt(new Promise((R,C)=>{this.rpcPublish(g,i).then(R).catch(O=>{this.logger.warn(O,O?.message),C(O)})}),this.initialPublishTimeout,`Failed initial custom payload publish, retrying.... method:${p} id:${h} tag:${f}`);try{await v,this.events.removeListener(ye.publish,w)}catch(R){this.queue.set(h,{request:g,opts:i,attempt:1}),this.logger.warn(R,R?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:h,payload:s,opts:i}}),await Lt(b,this.publishTimeout,m)}catch(b){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(b),i?.internal?.throwOnFailedPublish)throw b}finally{this.queue.delete(h)}},this.on=(n,s)=>{this.events.on(n,s)},this.once=(n,s)=>{this.events.once(n,s)},this.off=(n,s)=>{this.events.off(n,s)},this.removeListener=(n,s)=>{this.events.removeListener(n,s)},this.relayer=e,this.logger=ft(r,this.name),this.registerEventListeners()}get context(){return We(this.logger)}async rpcPublish(e,r){this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:e});let n=await this.relayer.request(e);return this.relayer.events.emit(ye.publish,{...e,...r}),this.logger.debug("Successfully Published Payload"),n}removeRequestFromQueue(e){this.queue.delete(e)}checkQueue(){this.queue.forEach(async(e,r)=>{let n=e.attempt+1;this.queue.set(r,{...e,attempt:n}),this.logger.warn({},`Publisher: queue->publishing: ${e.request.id}, tag: ${e.request.params?.tag}, attempt: ${n}`),await this.rpcPublish(e.request,e.opts),this.logger.warn({},`Publisher: queue->published: ${e.request.id}`)})}registerEventListeners(){this.relayer.core.heartbeat.on(nn.pulse,()=>{if(this.needsTransportRestart){this.needsTransportRestart=!1,this.relayer.events.emit(ye.connection_stalled);return}this.checkQueue()}),this.relayer.on(ye.message_ack,e=>{this.removeRequestFromQueue(e.id.toString())})}},op=class{constructor(){this.map=new Map,this.set=(e,r)=>{let n=this.get(e);this.exists(e,r)||this.map.set(e,[...n,r])},this.get=e=>this.map.get(e)||[],this.exists=(e,r)=>this.get(e).includes(r),this.delete=(e,r)=>{if(typeof r>"u"){this.map.delete(e);return}if(!this.map.has(e))return;let n=this.get(e);if(!this.exists(e,r))return;let s=n.filter(i=>i!==r);if(!s.length){this.map.delete(e);return}this.map.set(e,s)},this.clear=()=>{this.map.clear()}}get topics(){return Array.from(this.map.keys())}},ap=class extends Ra{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,this.subscriptions=new Map,this.topicMap=new op,this.events=new en.EventEmitter,this.name=U5,this.version=L5,this.pending=new Map,this.cached=[],this.initialized=!1,this.storagePrefix=wr,this.subscribeTimeout=(0,G.toMiliseconds)(G.ONE_MINUTE),this.initialSubscribeTimeout=(0,G.toMiliseconds)(G.ONE_SECOND*15),this.batchSubscribeTopicsLimit=500,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),await this.restore()),this.initialized=!0},this.subscribe=async(n,s)=>{this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:n,opts:s}});try{let i=Lo(s),o={topic:n,relay:i,transportType:s?.transportType};s?.internal?.skipSubscribe||this.pending.set(n,o);let a=await this.rpcSubscribe(n,i,s);return typeof a=="string"&&(this.onSubscribe(a,o),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:n,opts:s}})),a}catch(i){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(i),i}},this.unsubscribe=async(n,s)=>{this.isInitialized(),typeof s?.id<"u"?await this.unsubscribeById(n,s.id,s):await this.unsubscribeByTopic(n,s)},this.isSubscribed=n=>new Promise(s=>{s(this.topicMap.topics.includes(n))}),this.isKnownTopic=n=>new Promise(s=>{s(this.topicMap.topics.includes(n)||this.pending.has(n)||this.cached.some(i=>i.topic===n))}),this.on=(n,s)=>{this.events.on(n,s)},this.once=(n,s)=>{this.events.once(n,s)},this.off=(n,s)=>{this.events.off(n,s)},this.removeListener=(n,s)=>{this.events.removeListener(n,s)},this.start=async()=>{await this.onConnect()},this.stop=async()=>{await this.onDisconnect()},this.restart=async()=>{await this.restore(),await this.onRestart()},this.checkPending=async()=>{if(this.pending.size===0&&(!this.initialized||!this.relayer.connected))return;let n=[];this.pending.forEach(s=>{n.push(s)}),await this.batchSubscribe(n)},this.registerEventListeners=()=>{this.relayer.core.heartbeat.on(nn.pulse,async()=>{await this.checkPending()}),this.events.on(Tt.created,async n=>{let s=Tt.created;this.logger.info(`Emitting ${s}`),this.logger.debug({type:"event",event:s,data:n}),await this.persist()}),this.events.on(Tt.deleted,async n=>{let s=Tt.deleted;this.logger.info(`Emitting ${s}`),this.logger.debug({type:"event",event:s,data:n}),await this.persist()})},this.relayer=e,this.logger=ft(r,this.name),this.clientId=""}get context(){return We(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.relayer.core.customStoragePrefix+"//"+this.name}get length(){return this.subscriptions.size}get ids(){return Array.from(this.subscriptions.keys())}get values(){return Array.from(this.subscriptions.values())}get topics(){return this.topicMap.topics}get hasAnyTopics(){return this.topicMap.topics.length>0||this.pending.size>0||this.cached.length>0||this.subscriptions.size>0}hasSubscription(e,r){let n=!1;try{n=this.getSubscription(e).topic===r}catch{}return n}reset(){this.cached=[],this.initialized=!0}onDisable(){this.values.length>0&&(this.cached=this.values),this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(e,r){let n=this.topicMap.get(e);await Promise.all(n.map(async s=>await this.unsubscribeById(e,s,r)))}async unsubscribeById(e,r,n){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:n}});try{let s=pe("USER_DISCONNECTED",`${this.name}, ${e}`);await this.onUnsubscribe(e,r,s);let i=Lo(n);await this.restartToComplete({topic:e,id:r,relay:i}),await this.rpcUnsubscribe(e,r,i),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:n}})}catch(s){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(s),s}}async rpcSubscribe(e,r,n){let s=await this.getSubscriptionId(e);if(n?.internal?.skipSubscribe)return s;(!n||n?.transportType===fe.relay)&&await this.restartToComplete({topic:e,id:e,relay:r});let i={method:Ss(r.protocol).subscribe,params:{topic:e}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i});let o=n?.internal?.throwOnFailedPublish;try{if(n?.transportType===fe.link_mode)return setTimeout(()=>{(this.relayer.connected||this.relayer.connecting)&&this.relayer.request(i).catch(u=>this.logger.warn(u))},(0,G.toMiliseconds)(G.ONE_SECOND)),s;let a=new Promise(async u=>{let f=l=>{l.topic===e&&(this.events.removeListener(Tt.created,f),u(l.id))};this.events.on(Tt.created,f);try{let l=await Lt(new Promise((h,d)=>{this.relayer.request(i).catch(p=>{this.logger.warn(p,p?.message),d(p)}).then(h)}),this.initialSubscribeTimeout,`Subscribing to ${e} failed, please try again`);this.events.removeListener(Tt.created,f),u(l)}catch{}}),c=await Lt(a,this.subscribeTimeout,`Subscribing to ${e} failed, please try again`);if(!c&&o)throw new Error(`Subscribing to ${e} failed, please try again`);return c?s:null}catch(a){if(this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(ye.connection_stalled),o)throw a}return null}async rpcBatchSubscribe(e){if(!e.length)return!0;let r=e[0].relay,n={method:Ss(r.protocol).batchSubscribe,params:{topics:e.map(s=>s.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n});try{return await Lt(new Promise((s,i)=>{this.relayer.request(n).then(s).catch(o=>{this.logger.warn(o),i(o)})}),this.subscribeTimeout,"rpcBatchSubscribe failed, please try again"),!0}catch{return this.relayer.events.emit(ye.connection_stalled),!1}}async rpcBatchFetchMessages(e){if(!e.length)return;let r=e[0].relay,n={method:Ss(r.protocol).batchFetchMessages,params:{topics:e.map(i=>i.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n});let s;try{s=await await Lt(new Promise((i,o)=>{this.relayer.request(n).catch(a=>{this.logger.warn(a),o(a)}).then(i)}),this.subscribeTimeout,"rpcBatchFetchMessages failed, please try again")}catch{this.relayer.events.emit(ye.connection_stalled)}return s}rpcUnsubscribe(e,r,n){let s={method:Ss(n.protocol).unsubscribe,params:{topic:e,id:r}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:s}),this.relayer.request(s)}onSubscribe(e,r){this.setSubscription(e,{...r,id:e}),this.pending.delete(r.topic)}onBatchSubscribe(e){e.length&&e.forEach(r=>{this.setSubscription(r.id,{...r}),this.pending.delete(r.topic)})}async onUnsubscribe(e,r,n){this.events.removeAllListeners(r),this.hasSubscription(r,e)&&this.deleteSubscription(r,n),await this.relayer.messages.del(e)}async setRelayerSubscriptions(e){await this.relayer.core.storage.setItem(this.storageKey,e)}async getRelayerSubscriptions(){return await this.relayer.core.storage.getItem(this.storageKey)}setSubscription(e,r){this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:r}),this.addSubscription(e,r)}addSubscription(e,r){this.subscriptions.set(e,{...r}),this.topicMap.set(r.topic,e),this.events.emit(Tt.created,r)}getSubscription(e){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});let r=this.subscriptions.get(e);if(!r){let{message:n}=F("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(n)}return r}deleteSubscription(e,r){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:r});let n=this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(n.topic,e),this.events.emit(Tt.deleted,{...n,reason:r})}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit(Tt.sync)}async onRestart(){if(this.cached.length){let e=[...this.cached],r=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let n=0;n<r;n++){let s=e.splice(0,this.batchSubscribeTopicsLimit);await this.batchSubscribe(s)}}this.events.emit(Tt.resubscribed)}async restore(){try{let e=await this.getRelayerSubscriptions();if(typeof e>"u"||!e.length)return;if(this.subscriptions.size&&!e.every(r=>r.topic===this.subscriptions.get(r.id)?.topic)){let{message:r}=F("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored subscriptions for ${this.name}`),this.logger.trace({type:"method",method:"restore",subscriptions:this.values})}catch(e){this.logger.debug(`Failed to Restore subscriptions for ${this.name}`),this.logger.error(e)}}async batchSubscribe(e){if(e.length){if(!await this.rpcBatchSubscribe(e)){this.logger.warn(`Batch subscribe failed for ${e.length} topics, adding to pending for retry`),e.forEach(r=>{this.pending.set(r.topic,r)});return}this.onBatchSubscribe(await Promise.all(e.map(async r=>({...r,id:await this.getSubscriptionId(r.topic)}))))}}async batchFetchMessages(e){if(!e.length)return;this.logger.trace(`Fetching batch messages for ${e.length} subscriptions`);let r=await this.rpcBatchFetchMessages(e);r&&r.messages&&(await $x((0,G.toMiliseconds)(G.ONE_SECOND)),await this.relayer.handleBatchMessageEvents(r.messages))}async onConnect(){await this.restart(),this.reset()}onDisconnect(){this.onDisable()}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}async restartToComplete(e){!this.relayer.connected&&!this.relayer.connecting&&(this.cached.push(e),await this.relayer.transportOpen())}async getClientId(){return this.clientId||(this.clientId=await this.relayer.core.crypto.getClientId()),this.clientId}async getSubscriptionId(e){return yt(e+await this.getClientId())}},cp=class extends Aa{constructor(e){super(e),this.protocol="wc",this.version=2,this.events=new en.EventEmitter,this.name=D5,this.transportExplicitlyClosed=!1,this.initialized=!1,this.connectionAttemptInProgress=!1,this.hasExperiencedNetworkDisruption=!1,this.heartBeatTimeout=(0,G.toMiliseconds)(G.THIRTY_SECONDS+G.FIVE_SECONDS),this.reconnectInProgress=!1,this.requestsInFlight=[],this.connectTimeout=(0,G.toMiliseconds)(G.ONE_SECOND*15),this.stalledRestartInProgress=!1,this.stalledRestartBackoff=0,this.stalledRestartBaseInterval=(0,G.toMiliseconds)(G.ONE_SECOND*2),this.stalledRestartMaxInterval=(0,G.toMiliseconds)(G.THIRTY_SECONDS),this.request=async r=>{this.logger.debug("Publishing Request Payload");let n=r.id||Mt().toString();await this.toEstablishConnection();try{this.logger.trace({id:n,method:r.method,topic:r.params?.topic},"relayer.request - publishing...");let s=`${n}:${r.params?.tag||""}`;this.requestsInFlight.push(s);let i=await this.provider.request(r);return this.requestsInFlight=this.requestsInFlight.filter(o=>o!==s),i}catch(s){throw this.logger.debug(`Failed to Publish Request: ${n}`),s}},this.resetPingTimeout=()=>{Do()&&(clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(()=>{try{this.logger.debug({},"pingTimeout: Connection stalled, terminating..."),this.provider?.connection?.socket?.terminate?.()}catch(r){this.logger.warn(r,r?.message)}},this.heartBeatTimeout))},this.onPayloadHandler=r=>{this.onProviderPayload(r),this.resetPingTimeout()},this.onConnectHandler=()=>{this.logger.warn({},"Relayer connected \u{1F6DC}"),this.startPingTimeout(),this.stalledRestartBackoff=0,this.events.emit(ye.connect)},this.onDisconnectHandler=()=>{this.logger.warn({},"Relayer disconnected \u{1F6D1}"),this.requestsInFlight=[],this.onProviderDisconnect()},this.onProviderErrorHandler=r=>{this.logger.fatal(`Fatal socket error: ${r.message}`),this.events.emit(ye.error,r),this.logger.fatal("Fatal socket error received, closing transport"),this.transportExplicitlyClosed=!0,clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0,this.reconnectInProgress=!1,this.transportClose().catch(n=>this.logger.warn(n))},this.registerProviderListeners=()=>{this.provider.on(qt.payload,this.onPayloadHandler),this.provider.on(qt.connect,this.onConnectHandler),this.provider.on(qt.disconnect,this.onDisconnectHandler),this.provider.on(qt.error,this.onProviderErrorHandler)},this.core=e.core,this.logger=xu({logger:e.logger??R5,name:this.name}),this.messages=new sp(this.logger,e.core),this.subscriber=new ap(this,this.logger),this.publisher=new ip(this,this.logger),this.projectId=e.projectId,this.relayUrl=e.relayUrl||U2,Px()?this.packageName=xd():Ux()&&(this.bundleId=xd()),this.provider={}}async init(){this.logger.trace("Initialized"),this.registerEventListeners(),await Promise.all([this.messages.init(),this.subscriber.init()]),this.initialized=!0,this.transportOpen().catch(e=>this.logger.warn(e,e?.message))}get context(){return We(this.logger)}get connected(){return this.provider?.connection?.socket?.readyState===1}get connecting(){return this.provider?.connection?.socket?.readyState===0||this.connectPromise!==void 0}async publish(e,r,n){this.isInitialized(),await this.publisher.publish(e,r,n),await this.recordMessageEvent({topic:e,message:r,publishedAt:Date.now(),transportType:fe.relay},Nu.outbound)}async publishCustom(e){this.isInitialized(),await this.publisher.publishCustom(e)}async subscribe(e,r){this.isInitialized(),(!r?.transportType||r?.transportType==="relay")&&await this.toEstablishConnection();let n=r?.internal?.throwOnFailedPublish??!0,s=this.subscriber.topicMap.get(e)?.[0]||"",i,o=a=>{a.topic===e&&(this.subscriber.off(Tt.created,o),i())};return await Promise.all([new Promise(a=>{i=a,this.subscriber.on(Tt.created,o)}),new Promise((a,c)=>{this.subscriber.subscribe(e,{internal:{throwOnFailedPublish:n},...r}).then(u=>{s=u||s,a()}).catch(u=>{n?c(u):a()})})]),s}async unsubscribe(e,r){this.isInitialized(),await this.subscriber.unsubscribe(e,r)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async transportDisconnect(){this.provider.disconnect&&(this.hasExperiencedNetworkDisruption||this.connected)?await Lt(this.provider.disconnect(),2e3,"provider.disconnect()").catch(()=>this.onProviderDisconnect()):this.onProviderDisconnect()}async transportClose(){this.transportExplicitlyClosed=!0,clearTimeout(this.stalledRestartTimeout),this.stalledRestartInProgress=!1,this.stalledRestartBackoff=0,await this.resetTransport()}async transportOpen(e){if(!this.subscriber.hasAnyTopics){this.logger.info("Starting WS connection skipped because the client has no topics to work with.");return}if(this.connectPromise?(this.logger.debug({},"Waiting for existing connection attempt to resolve..."),await this.connectPromise,this.logger.debug({},"Existing connection attempt resolved")):(this.connectPromise=this.connect(e).finally(()=>{this.connectPromise=void 0}),await this.connectPromise),!this.connected)throw new Error(`Couldn't establish socket connection to the relay server: ${this.relayUrl}`)}async restartTransport(e){this.logger.debug({},"Restarting transport..."),!this.connectionAttemptInProgress&&(this.relayUrl=e||this.relayUrl,await this.confirmOnlineStateOrThrow(),await this.resetTransport(),await this.transportOpen())}async resetTransport(){this.reconnectInProgress=!0,clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0,await this.transportDisconnect(),await this.subscriber.stop(),this.reconnectInProgress=!1}async confirmOnlineStateOrThrow(){if(!await zd())throw new Error("No internet connection detected. Please restart your network and try again.")}async handleBatchMessageEvents(e){if(e?.length===0){this.logger.trace("Batch message events is empty. Ignoring...");return}let r=e.sort((n,s)=>n.publishedAt-s.publishedAt);this.logger.debug(`Batch of ${r.length} message events sorted`);for(let n of r)try{await this.onMessageEvent(n)}catch(s){this.logger.warn(s,"Error while processing batch message event: "+s?.message)}this.logger.trace(`Batch of ${r.length} message events processed`)}async onLinkMessageEvent(e,r){let{topic:n}=e;if(!r.sessionExists){let s=_e(G.FIVE_MINUTES),i={topic:n,expiry:s,relay:{protocol:"irn"},active:!1};await this.core.pairing.pairings.set(n,i)}this.events.emit(ye.message,e),await this.recordMessageEvent(e,Nu.inbound)}async connect(e){await this.confirmOnlineStateOrThrow(),e&&e!==this.relayUrl&&(this.relayUrl=e,await this.transportDisconnect()),this.transportExplicitlyClosed=!1;let r=1;try{for(;r<6;){this.connectionAttemptInProgress=!0;try{if(this.transportExplicitlyClosed)break;this.logger.debug({},`Connecting to ${this.relayUrl}, attempt: ${r}...`),await this.createProvider(),await new Promise((n,s)=>{let i=()=>{s(new Error("Connection interrupted while trying to connect"))};this.provider.once(qt.disconnect,i),Lt(this.provider.connect(),this.connectTimeout,`Socket stalled when trying to connect to ${this.relayUrl}`).then(()=>n()).catch(s).finally(()=>{this.provider.off(qt.disconnect,i),clearTimeout(this.reconnectTimeout)})}),await new Promise((n,s)=>{let i=()=>{s(new Error("Connection interrupted while trying to subscribe"))};this.provider.once(qt.disconnect,i),this.subscriber.start().then(n).catch(s).finally(()=>{this.provider.off(qt.disconnect,i)})}),this.hasExperiencedNetworkDisruption=!1}catch(n){await this.subscriber.stop();let s=n;this.logger.warn({},s.message),this.hasExperiencedNetworkDisruption=!0}if(this.connected){this.logger.debug({},`Connected to ${this.relayUrl} successfully on attempt: ${r}`);break}await new Promise(n=>setTimeout(n,(0,G.toMiliseconds)(r*1))),r++}}finally{this.connectionAttemptInProgress=!1,clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0,this.reconnectInProgress=!1}}startPingTimeout(){if(Do())try{this.provider?.connection?.socket?.on("ping",()=>{this.resetPingTimeout()}),this.resetPingTimeout()}catch(e){this.logger.warn(e,e?.message)}}async createProvider(){if(this.provider.connection&&(this.unregisterProviderListeners(),this.connected))try{await Lt(this.provider.disconnect(),1e3,"Closing previous provider")}catch{}let e=await this.core.crypto.signJWT(this.relayUrl);this.provider=new Du(new Ou(kx({sdkVersion:tp,protocol:this.protocol,version:this.version,relayUrl:this.relayUrl,projectId:this.projectId,auth:e,useOnCloseEvent:!0,bundleId:this.bundleId,packageName:this.packageName}))),this.registerProviderListeners()}async recordMessageEvent(e,r){let{topic:n,message:s}=e;await this.messages.set(n,s,r)}async shouldIgnoreMessageEvent(e){let{topic:r,message:n}=e;if(!n||n.length===0)return this.logger.warn(`Ignoring invalid/empty message: ${n}`),!0;if(!await this.subscriber.isKnownTopic(r))return this.logger.warn(`Ignoring message for unknown topic ${r}`),!0;let s=this.messages.has(r,n);return s&&this.logger.warn(`Ignoring duplicate message: ${n}`),s}async onProviderPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),Bi(e)){if(!e.method.endsWith(O5))return;let r=e.params,{topic:n,message:s,publishedAt:i,attestation:o}=r.data,a={topic:n,message:s,publishedAt:i,transportType:fe.relay,attestation:o};this.logger.debug("Emitting Relayer Payload"),this.logger.trace({type:"event",event:r.id,...a}),this.events.emit(r.id,a),await this.acknowledgePayload(e),await this.onMessageEvent(a)}else Cn(e)&&this.events.emit(ye.message_ack,e)}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(await this.recordMessageEvent(e,Nu.inbound),this.events.emit(ye.message,e))}async acknowledgePayload(e){let r=Bs(e.id,!0);await this.provider.connection.send(r)}unregisterProviderListeners(){this.provider.off(qt.payload,this.onPayloadHandler),this.provider.off(qt.connect,this.onConnectHandler),this.provider.off(qt.disconnect,this.onDisconnectHandler),this.provider.off(qt.error,this.onProviderErrorHandler),clearTimeout(this.pingTimeout)}async registerEventListeners(){let e=await zd();Nb(async r=>{e!==r&&(e=r,r?await this.transportOpen().catch(n=>this.logger.error(n,n?.message)):(this.hasExperiencedNetworkDisruption=!0,await this.transportDisconnect(),this.transportExplicitlyClosed=!1))}),this.core.heartbeat.on(nn.pulse,async()=>{if(!this.transportExplicitlyClosed&&!this.connected&&Pb())try{await this.confirmOnlineStateOrThrow(),await this.transportOpen()}catch(r){this.logger.warn(r,r?.message)}}),this.events.on(ye.connection_stalled,()=>{if(this.transportExplicitlyClosed||this.stalledRestartInProgress)return;this.stalledRestartInProgress=!0;let r=this.stalledRestartBackoff===0?0:Math.min(Math.pow(2,this.stalledRestartBackoff-1)*this.stalledRestartBaseInterval,this.stalledRestartMaxInterval);this.stalledRestartBackoff++,this.logger.warn(`Connection stalled, restarting transport${r?` in ${r}ms`:""}...`),this.stalledRestartTimeout=setTimeout(async()=>{try{if(this.transportExplicitlyClosed)return;await this.restartTransport()}catch(n){this.logger.error(n,n?.message)}finally{this.stalledRestartInProgress=!1}},r)})}async onProviderDisconnect(){if(clearTimeout(this.pingTimeout),this.events.emit(ye.disconnect),!this.reconnectInProgress){this.reconnectInProgress=!0;try{await this.subscriber.stop()}catch(e){this.logger.warn(e,"subscriber.stop() failed during disconnect")}if(!this.subscriber.hasAnyTopics||this.transportExplicitlyClosed){this.reconnectInProgress=!1;return}this.reconnectTimeout=setTimeout(async()=>{await this.transportOpen().catch(e=>this.logger.error(e,e?.message)),this.reconnectTimeout=void 0,this.reconnectInProgress=!1},(0,G.toMiliseconds)(C5))}}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}async toEstablishConnection(){if(await this.confirmOnlineStateOrThrow(),!this.connected){if(this.connectPromise){await this.connectPromise;return}this.connectPromise=this.connect().finally(()=>{this.connectPromise=void 0}),await this.connectPromise}}},xr=class extends Ta{constructor(e,r,n,s=wr,i=void 0){super(e,r,n,s),this.core=e,this.logger=r,this.name=n,this.map=new Map,this.version=N5,this.cached=[],this.initialized=!1,this.storagePrefix=wr,this.recentlyDeleted=[],this.recentlyDeletedLimit=200,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(o=>{this.getKey&&o!==null&&!ve(o)?this.map.set(this.getKey(o),o):xb(o)?this.map.set(o.id,o):bb(o)&&this.map.set(o.topic,o)}),this.cached=[],this.initialized=!0)},this.set=async(o,a)=>{this.isInitialized(),this.map.has(o)?await this.update(o,a):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:o,value:a}),this.map.set(o,a),await this.persist())},this.get=o=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:o}),this.getData(o)),this.getAll=o=>(this.isInitialized(),o?this.values.filter(a=>Object.keys(o).every(c=>ep(a[c],o[c]))):this.values),this.update=async(o,a)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:o,update:a});let c={...this.getData(o),...a};this.map.set(o,c),await this.persist()},this.delete=async(o,a)=>{this.isInitialized(),this.map.has(o)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:o,reason:a}),this.map.delete(o),this.addToRecentlyDeleted(o),await this.persist())},this.logger=ft(r,this.name),this.storagePrefix=s,this.getKey=i}get context(){return We(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get length(){return this.map.size}get keys(){return Array.from(this.map.keys())}get values(){return Array.from(this.map.values())}addToRecentlyDeleted(e){this.recentlyDeleted.push(e),this.recentlyDeleted.length>=this.recentlyDeletedLimit&&this.recentlyDeleted.splice(0,this.recentlyDeletedLimit/2)}async setDataStore(e){await this.core.storage.setItem(this.storageKey,e)}async getDataStore(){return await this.core.storage.getItem(this.storageKey)}getData(e){let r=this.map.get(e);if(!r){if(this.recentlyDeleted.includes(e)){let{message:s}=F("MISSING_OR_INVALID",`Record was recently deleted - ${this.name}: ${e}`);throw this.logger.error(s),new Error(s)}let{message:n}=F("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(n),new Error(n)}return r}async persist(){await this.setDataStore(this.values)}async restore(){try{let e=await this.getDataStore();if(typeof e>"u"||!e.length)return;if(this.map.size){let{message:r}=F("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored value for ${this.name}`),this.logger.trace({type:"method",method:"restore",value:this.values})}catch(e){this.logger.debug(`Failed to Restore value for ${this.name}`),this.logger.error(e)}}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}},up=class{constructor(e,r){this.core=e,this.logger=r,this.name=k5,this.version=M5,this.events=new en.default,this.initialized=!1,this.storagePrefix=wr,this.ignoredPayloadTypes=[Jt],this.registeredMethods=[],this.init=async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))},this.register=({methods:n})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...n])]},this.create=async n=>{this.isInitialized();let s=yu(),i=await this.core.crypto.setSymKey(s),o=_e(G.FIVE_MINUTES),a={protocol:gp},c={topic:i,expiry:o,relay:a,active:!1,methods:n?.methods},u=Ud({protocol:this.core.protocol,version:this.core.version,topic:i,symKey:s,relay:a,expiryTimestamp:o,methods:n?.methods});return this.events.emit(Nn.create,c),this.core.expirer.set(i,o),await this.pairings.set(i,c),await this.core.relayer.subscribe(i,{transportType:n?.transportType,internal:n?.internal}),{topic:i,uri:u}},this.pair=async n=>{this.isInitialized();let s=this.core.eventClient.createEvent({properties:{topic:n?.uri,trace:[Zt.pairing_started]}});this.isValidPair(n,s);let{topic:i,symKey:o,relay:a,expiryTimestamp:c,methods:u}=Pd(n.uri);s.props.properties.topic=i,s.addTrace(Zt.pairing_uri_validation_success),s.addTrace(Zt.pairing_uri_not_expired);let f;if(this.pairings.keys.includes(i)){if(f=this.pairings.get(i),s.addTrace(Zt.existing_pairing),f.active)throw s.setError(yr.active_pairing_already_exists),new Error(`Pairing already exists: ${i}. Please try again with a new connection URI.`);s.addTrace(Zt.pairing_not_expired)}let l=c||_e(G.FIVE_MINUTES),h={topic:i,relay:a,expiry:l,active:!1,methods:u};this.core.expirer.set(i,l),await this.pairings.set(i,h),s.addTrace(Zt.store_new_pairing),n.activatePairing&&await this.activate({topic:i}),this.events.emit(Nn.create,h),s.addTrace(Zt.emit_inactive_pairing),this.core.crypto.keychain.has(i)||await this.core.crypto.setSymKey(o,i),s.addTrace(Zt.subscribing_pairing_topic);try{await this.core.relayer.confirmOnlineStateOrThrow()}catch{s.setError(yr.no_internet_connection)}try{await this.core.relayer.subscribe(i,{relay:a})}catch(d){throw s.setError(yr.subscribe_pairing_topic_failure),d}return s.addTrace(Zt.subscribe_pairing_topic_success),h},this.activate=async({topic:n})=>{this.isInitialized();let s=_e(G.FIVE_MINUTES);this.core.expirer.set(n,s),await this.pairings.update(n,{active:!0,expiry:s})},this.ping=async n=>{this.isInitialized(),await this.isValidPing(n),this.logger.warn("ping() is deprecated and will be removed in the next major release.");let{topic:s}=n;if(this.pairings.keys.includes(s)){let i=await this.sendRequest(s,"wc_pairingPing",{}),{done:o,resolve:a,reject:c}=Zr();this.events.once(ae("pairing_ping",i),({error:u})=>{u?c(u):a()}),await o()}},this.updateExpiry=async({topic:n,expiry:s})=>{this.isInitialized(),await this.pairings.update(n,{expiry:s})},this.updateMetadata=async({topic:n,metadata:s})=>{this.isInitialized(),await this.pairings.update(n,{peerMetadata:s})},this.getPairings=()=>(this.isInitialized(),this.pairings.values),this.disconnect=async n=>{this.isInitialized(),await this.isValidDisconnect(n);let{topic:s}=n;this.pairings.keys.includes(s)&&(await this.sendRequest(s,"wc_pairingDelete",pe("USER_DISCONNECTED")),await this.deletePairing(s))},this.formatUriFromPairing=n=>{this.isInitialized();let{topic:s,relay:i,expiry:o,methods:a}=n,c=this.core.crypto.keychain.get(s);return Ud({protocol:this.core.protocol,version:this.core.version,topic:s,symKey:c,relay:i,expiryTimestamp:o,methods:a})},this.sendRequest=async(n,s,i)=>{let o=Bt(s,i),a=await this.core.crypto.encode(n,o),c=$o[s].req;return this.core.history.set(n,o),this.core.relayer.publish(n,a,c),o.id},this.sendResult=async(n,s,i)=>{let o=Bs(n,i),a=await this.core.crypto.encode(s,o),c=(await this.core.history.get(s,n)).request.method,u=$o[c].res;await this.core.relayer.publish(s,a,u),await this.core.history.resolve(o)},this.sendError=async(n,s,i)=>{let o=As(n,i),a=await this.core.crypto.encode(s,o),c=(await this.core.history.get(s,n)).request.method,u=$o[c]?$o[c].res:$o.unregistered_method.res;await this.core.relayer.publish(s,a,u),await this.core.history.resolve(o)},this.deletePairing=async(n,s)=>{await this.core.relayer.unsubscribe(n),await Promise.all([this.pairings.delete(n,pe("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(n),s?Promise.resolve():this.core.expirer.del(n)])},this.cleanup=async()=>{let n=this.pairings.getAll().filter(s=>mr(s.expiry));await Promise.all(n.map(s=>this.deletePairing(s.topic)))},this.onRelayEventRequest=async n=>{let{topic:s,payload:i}=n;switch(i.method){case"wc_pairingPing":return await this.onPairingPingRequest(s,i);case"wc_pairingDelete":return await this.onPairingDeleteRequest(s,i);default:return await this.onUnknownRpcMethodRequest(s,i)}},this.onRelayEventResponse=async n=>{let{topic:s,payload:i}=n,o=(await this.core.history.get(s,i.id)).request.method;return o==="wc_pairingPing"?this.onPairingPingResponse(s,i):this.onUnknownRpcMethodResponse(o)},this.onPairingPingRequest=async(n,s)=>{let{id:i}=s;try{this.isValidPing({topic:n}),await this.sendResult(i,n,!0),this.events.emit(Nn.ping,{id:i,topic:n})}catch(o){await this.sendError(i,n,o),this.logger.error(o)}},this.onPairingPingResponse=(n,s)=>{let{id:i}=s;setTimeout(()=>{At(s)?this.events.emit(ae("pairing_ping",i),{}):nt(s)&&this.events.emit(ae("pairing_ping",i),{error:s.error})},500)},this.onPairingDeleteRequest=async(n,s)=>{let{id:i}=s;try{this.isValidDisconnect({topic:n}),await this.deletePairing(n),this.events.emit(Nn.delete,{id:i,topic:n})}catch(o){await this.sendError(i,n,o),this.logger.error(o)}},this.onUnknownRpcMethodRequest=async(n,s)=>{let{id:i,method:o}=s;try{if(this.registeredMethods.includes(o))return;let a=pe("WC_METHOD_UNSUPPORTED",o);await this.sendError(i,n,a),this.logger.error(a)}catch(a){await this.sendError(i,n,a),this.logger.error(a)}},this.onUnknownRpcMethodResponse=n=>{this.registeredMethods.includes(n)||this.logger.error(pe("WC_METHOD_UNSUPPORTED",n))},this.isValidPair=(n,s)=>{if(!rt(n)){let{message:o}=F("MISSING_OR_INVALID",`pair() params: ${n}`);throw s.setError(yr.malformed_pairing_uri),new Error(o)}if(!wb(n.uri)){let{message:o}=F("MISSING_OR_INVALID",`pair() uri: ${n.uri}`);throw s.setError(yr.malformed_pairing_uri),new Error(o)}let i=Pd(n?.uri);if(!i?.relay?.protocol){let{message:o}=F("MISSING_OR_INVALID","pair() uri#relay-protocol");throw s.setError(yr.malformed_pairing_uri),new Error(o)}if(!i?.symKey){let{message:o}=F("MISSING_OR_INVALID","pair() uri#symKey");throw s.setError(yr.malformed_pairing_uri),new Error(o)}if(i?.expiryTimestamp&&(0,G.toMiliseconds)(i?.expiryTimestamp)<Date.now()){s.setError(yr.pairing_expired);let{message:o}=F("EXPIRED","pair() URI has expired. Please try again with a new connection URI.");throw new Error(o)}},this.isValidPing=async n=>{if(!rt(n)){let{message:i}=F("MISSING_OR_INVALID",`ping() params: ${n}`);throw new Error(i)}let{topic:s}=n;await this.isValidPairingTopic(s)},this.isValidDisconnect=async n=>{if(!rt(n)){let{message:i}=F("MISSING_OR_INVALID",`disconnect() params: ${n}`);throw new Error(i)}let{topic:s}=n;await this.isValidPairingTopic(s)},this.isValidPairingTopic=async n=>{if(!me(n,!1)){let{message:s}=F("MISSING_OR_INVALID",`pairing topic should be a string: ${n}`);throw new Error(s)}if(!this.pairings.keys.includes(n)){let{message:s}=F("NO_MATCHING_KEY",`pairing topic doesn't exist: ${n}`);throw new Error(s)}if(mr(this.pairings.get(n).expiry)){await this.deletePairing(n);let{message:s}=F("EXPIRED",`pairing topic: ${n}`);throw new Error(s)}},this.core=e,this.logger=ft(r,this.name),this.pairings=new xr(this.core,this.logger,this.name,this.storagePrefix)}get context(){return We(this.logger)}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.core.relayer.on(ye.message,async e=>{let{topic:r,message:n,transportType:s}=e;if(this.pairings.keys.includes(r)&&s!==fe.link_mode&&!this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(n)))try{let i=await this.core.crypto.decode(r,n);Bi(i)?(this.core.history.set(r,i),await this.onRelayEventRequest({topic:r,payload:i})):Cn(i)&&(await this.core.history.resolve(i),await this.onRelayEventResponse({topic:r,payload:i}),this.core.history.delete(r,i.id)),await this.core.relayer.messages.ack(r,n)}catch(i){this.logger.error(i)}})}registerExpirerEvents(){this.core.expirer.on(Rt.expired,async e=>{let{topic:r}=pu(e.target);r&&this.pairings.keys.includes(r)&&(await this.deletePairing(r,!0),this.events.emit(Nn.expire,{topic:r}))})}},lp=class extends Sa{constructor(e,r){super(e,r),this.core=e,this.logger=r,this.records=new Map,this.events=new en.EventEmitter,this.name=q5,this.version=F5,this.cached=[],this.initialized=!1,this.storagePrefix=wr,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(n=>this.records.set(n.id,n)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.set=(n,s,i)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:n,request:s,chainId:i}),this.records.has(s.id))return;let o={id:s.id,topic:n,request:{method:s.method,params:s.params||null},chainId:i,expiry:_e(G.THIRTY_DAYS)};this.records.set(o.id,o),this.persist(),this.events.emit(Xt.created,o)},this.resolve=async n=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:n}),!this.records.has(n.id))return;let s=await this.getRecord(n.id);typeof s.response<"u"||(s.response=nt(n)?{error:n.error}:{result:n.result},this.records.set(s.id,s),this.persist(),this.events.emit(Xt.updated,s))},this.get=async(n,s)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:n,id:s}),await this.getRecord(s)),this.delete=(n,s)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:s}),this.values.forEach(i=>{if(i.topic===n){if(typeof s<"u"&&i.id!==s)return;this.records.delete(i.id),this.events.emit(Xt.deleted,i)}}),this.persist()},this.exists=async(n,s)=>(this.isInitialized(),this.records.has(s)?(await this.getRecord(s)).topic===n:!1),this.on=(n,s)=>{this.events.on(n,s)},this.once=(n,s)=>{this.events.once(n,s)},this.off=(n,s)=>{this.events.off(n,s)},this.removeListener=(n,s)=>{this.events.removeListener(n,s)},this.logger=ft(r,this.name)}get context(){return We(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get size(){return this.records.size}get keys(){return Array.from(this.records.keys())}get values(){return Array.from(this.records.values())}get pending(){let e=[];return this.values.forEach(r=>{if(typeof r.response<"u")return;let n={topic:r.topic,request:Bt(r.request.method,r.request.params,r.id),chainId:r.chainId};return e.push(n)}),e}async setJsonRpcRecords(e){await this.core.storage.setItem(this.storageKey,e)}async getJsonRpcRecords(){return await this.core.storage.getItem(this.storageKey)}getRecord(e){this.isInitialized();let r=this.records.get(e);if(!r){let{message:n}=F("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(n)}return r}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit(Xt.sync)}async restore(){try{let e=await this.getJsonRpcRecords();if(typeof e>"u"||!e.length)return;if(this.records.size){let{message:r}=F("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",records:this.values})}catch(e){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(e)}}registerEventListeners(){this.events.on(Xt.created,e=>{let r=Xt.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e})}),this.events.on(Xt.updated,e=>{let r=Xt.updated;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e})}),this.events.on(Xt.deleted,e=>{let r=Xt.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e})}),this.core.heartbeat.on(nn.pulse,()=>{this.cleanup()})}cleanup(){try{this.isInitialized();let e=!1;this.records.forEach(r=>{(0,G.toMiliseconds)(r.expiry||0)-Date.now()<=0&&(this.logger.info(`Deleting expired history log: ${r.id}`),this.records.delete(r.id),this.events.emit(Xt.deleted,r,!1),e=!0)}),e&&this.persist()}catch(e){this.logger.warn(e)}}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}},fp=class extends Da{constructor(e,r){super(e,r),this.core=e,this.logger=r,this.expirations=new Map,this.events=new en.EventEmitter,this.name=H5,this.version=z5,this.cached=[],this.initialized=!1,this.storagePrefix=wr,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(n=>this.expirations.set(n.target,n)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.has=n=>{try{let s=this.formatTarget(n);return typeof this.getExpiration(s)<"u"}catch{return!1}},this.set=(n,s)=>{this.isInitialized();let i=this.formatTarget(n),o={target:i,expiry:s};this.expirations.set(i,o),this.checkExpiry(i,o),this.events.emit(Rt.created,{target:i,expiration:o})},this.get=n=>{this.isInitialized();let s=this.formatTarget(n);return this.getExpiration(s)},this.del=n=>{if(this.isInitialized(),this.has(n)){let s=this.formatTarget(n),i=this.getExpiration(s);this.expirations.delete(s),this.events.emit(Rt.deleted,{target:s,expiration:i})}},this.on=(n,s)=>{this.events.on(n,s)},this.once=(n,s)=>{this.events.once(n,s)},this.off=(n,s)=>{this.events.off(n,s)},this.removeListener=(n,s)=>{this.events.removeListener(n,s)},this.logger=ft(r,this.name)}get context(){return We(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get length(){return this.expirations.size}get keys(){return Array.from(this.expirations.keys())}get values(){return Array.from(this.expirations.values())}formatTarget(e){if(typeof e=="string")return qx(e);if(typeof e=="number")return Fx(e);let{message:r}=F("UNKNOWN_TYPE",`Target type: ${typeof e}`);throw new Error(r)}async setExpirations(e){await this.core.storage.setItem(this.storageKey,e)}async getExpirations(){return await this.core.storage.getItem(this.storageKey)}async persist(){await this.setExpirations(this.values),this.events.emit(Rt.sync)}async restore(){try{let e=await this.getExpirations();if(typeof e>"u"||!e.length)return;if(this.expirations.size){let{message:r}=F("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=e,this.logger.debug(`Successfully Restored expirations for ${this.name}`),this.logger.trace({type:"method",method:"restore",expirations:this.values})}catch(e){this.logger.debug(`Failed to Restore expirations for ${this.name}`),this.logger.error(e)}}getExpiration(e){let r=this.expirations.get(e);if(!r){let{message:n}=F("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.warn(n),new Error(n)}return r}checkExpiry(e,r){let{expiry:n}=r;(0,G.toMiliseconds)(n)-Date.now()<=0&&this.expire(e,r)}expire(e,r){this.expirations.delete(e),this.events.emit(Rt.expired,{target:e,expiration:r})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((e,r)=>this.checkExpiry(r,e))}registerEventListeners(){this.core.heartbeat.on(nn.pulse,()=>this.checkExpirations()),this.events.on(Rt.created,e=>{let r=Rt.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(Rt.expired,e=>{let r=Rt.expired;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(Rt.deleted,e=>{let r=Rt.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()})}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}},hp=class extends Oa{constructor(e,r,n){super(e,r,n),this.core=e,this.logger=r,this.store=n,this.name=V5,this.verifyUrlV3=j5,this.storagePrefix=wr,this.version=P2,this.init=async()=>{this.isDevEnv||(this.publicKey=await this.store.getItem(this.storeKey),this.publicKey&&(0,G.toMiliseconds)(this.publicKey?.expiresAt)<Date.now()&&(this.logger.debug("verify v2 public key expired"),await this.removePublicKey()))},this.register=async s=>{if(!_s()||this.isDevEnv)return;let i=window.location.origin,{id:o,decryptedId:a}=s,c=`${this.verifyUrlV3}/attestation?projectId=${this.core.projectId}&origin=${i}&id=${o}&decryptedId=${a}`;try{let u=(0,C2.getDocument)(),f=this.startAbortTimer(G.ONE_SECOND*5),l=await new Promise((h,d)=>{let p=()=>{window.removeEventListener("message",m),u.body.removeChild(g),d("attestation aborted")};this.abortController.signal.addEventListener("abort",p);let g=u.createElement("iframe");g.src=c,g.style.display="none",g.addEventListener("error",p,{signal:this.abortController.signal});let m=b=>{if(b.data&&typeof b.data=="string")try{let T=JSON.parse(b.data);if(T.type==="verify_attestation"){if(ji(T.attestation).payload.id!==o)return;clearInterval(f),u.body.removeChild(g),this.abortController.signal.removeEventListener("abort",p),window.removeEventListener("message",m),h(T.attestation===null?"":T.attestation)}}catch(T){this.logger.warn(T)}};u.body.appendChild(g),window.addEventListener("message",m,{signal:this.abortController.signal})});return this.logger.debug(l,"jwt attestation"),l}catch(u){this.logger.warn(u)}return""},this.resolve=async s=>{if(this.isDevEnv)return"";let{attestationId:i,hash:o,encryptedId:a}=s;if(i===""){this.logger.debug("resolve: attestationId is empty, skipping");return}if(i){if(ji(i).payload.id!==a)return;let u=await this.isValidJwtAttestation(i);if(u){if(!u.isVerified){this.logger.warn("resolve: jwt attestation: origin url not verified");return}return u}}if(!o)return;let c=this.getVerifyUrl(s?.verifyUrl);return this.fetchAttestation(o,c)},this.fetchAttestation=async(s,i)=>{this.logger.debug(`resolving attestation: ${s} from url: ${i}`);let o=this.startAbortTimer(G.ONE_SECOND*5),a=await fetch(`${i}/attestation/${s}?v2Supported=true`,{signal:this.abortController.signal});return clearTimeout(o),a.status===200?await a.json():void 0},this.getVerifyUrl=s=>{let i=s||Ai;return K5.includes(i)||(this.logger.info(`verify url: ${i}, not included in trusted list, assigning default: ${Ai}`),i=Ai),i},this.fetchPublicKey=async()=>{try{this.logger.debug(`fetching public key from: ${this.verifyUrlV3}`);let s=this.startAbortTimer(G.FIVE_SECONDS),i=await fetch(`${this.verifyUrlV3}/public-key`,{signal:this.abortController.signal});return clearTimeout(s),await i.json()}catch(s){this.logger.warn(s)}},this.persistPublicKey=async s=>{this.logger.debug(s,"persisting public key to local storage"),await this.store.setItem(this.storeKey,s),this.publicKey=s},this.removePublicKey=async()=>{this.logger.debug("removing verify v2 public key from storage"),await this.store.removeItem(this.storeKey),this.publicKey=void 0},this.isValidJwtAttestation=async s=>{let i=await this.getPublicKey();try{if(i)return this.validateAttestation(s,i)}catch(a){this.logger.error(a),this.logger.warn("error validating attestation")}let o=await this.fetchAndPersistPublicKey();try{if(o)return this.validateAttestation(s,o)}catch(a){this.logger.error(a),this.logger.warn("error validating attestation")}},this.getPublicKey=async()=>this.publicKey?this.publicKey:await this.fetchAndPersistPublicKey(),this.fetchAndPersistPublicKey=async()=>{if(this.fetchPromise)return await this.fetchPromise,this.publicKey;this.fetchPromise=new Promise(async i=>{let o=await this.fetchPublicKey();o&&(await this.persistPublicKey(o),i(o))});let s=await this.fetchPromise;return this.fetchPromise=void 0,s},this.validateAttestation=(s,i)=>{let o=hb(s,i.publicKey),a={hasExpired:(0,G.toMiliseconds)(o.exp)<Date.now(),payload:o};if(a.hasExpired)throw this.logger.warn("resolve: jwt attestation expired"),new Error("JWT attestation expired");return{origin:a.payload.origin,isScam:a.payload.isScam,isVerified:a.payload.isVerified}},this.logger=ft(r,this.name),this.abortController=new AbortController,this.isDevEnv=Co(),this.init()}get storeKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//verify:public:key"}get context(){return We(this.logger)}startAbortTimer(e){return this.abortController=new AbortController,setTimeout(()=>this.abortController.abort(),(0,G.toMiliseconds)(e))}},dp=class extends Ca{constructor(e,r){super(e,r),this.projectId=e,this.logger=r,this.context=W5,this.registerDeviceToken=async n=>{let{clientId:s,token:i,notificationType:o,enableEncrypted:a=!1}=n,c=`${G5}/${this.projectId}/clients`;await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:s,type:o,token:i,always_raw:a})})},this.logger=ft(r,this.context)}},pp=class extends Na{constructor(e,r,n=!0){super(e,r,n),this.core=e,this.logger=r,this.context=J5,this.storagePrefix=wr,this.storageVersion=Y5,this.events=new Map,this.shouldPersist=!1,this.init=async()=>{if(!Co())try{let s={eventId:_d(),timestamp:Date.now(),domain:this.getAppDomain(),props:{event:"INIT",type:"",properties:{client_id:await this.core.crypto.getClientId(),user_agent:Ed(this.core.relayer.protocol,this.core.relayer.version,tp)}}};await this.sendEvent([s])}catch(s){this.logger.warn(s)}},this.createEvent=s=>{let{event:i="ERROR",type:o="",properties:{topic:a,trace:c}}=s,u=_d(),f=this.core.projectId||"",l=Date.now(),h={eventId:u,timestamp:l,props:{event:i,type:o,properties:{topic:a,trace:c}},bundleId:f,domain:this.getAppDomain(),...this.setMethods(u)};return this.telemetryEnabled&&(this.events.set(u,h),this.shouldPersist=!0),h},this.getEvent=s=>{let{eventId:i,topic:o}=s;if(i)return this.events.get(i);let a=Array.from(this.events.values()).find(c=>c.props.properties.topic===o);if(a)return{...a,...this.setMethods(a.eventId)}},this.deleteEvent=s=>{let{eventId:i}=s;this.events.delete(i),this.shouldPersist=!0},this.setEventListeners=()=>{this.core.heartbeat.on(nn.pulse,async()=>{this.shouldPersist&&await this.persist(),this.events.forEach(s=>{(0,G.fromMiliseconds)(Date.now())-(0,G.fromMiliseconds)(s.timestamp)>X5&&(this.events.delete(s.eventId),this.shouldPersist=!0)})})},this.setMethods=s=>({addTrace:i=>this.addTrace(s,i),setError:i=>this.setError(s,i)}),this.addTrace=(s,i)=>{let o=this.events.get(s);o&&(o.props.properties.trace.push(i),this.events.set(s,o),this.shouldPersist=!0)},this.setError=(s,i)=>{let o=this.events.get(s);o&&(o.props.type=i,o.timestamp=Date.now(),this.events.set(s,o),this.shouldPersist=!0)},this.persist=async()=>{await this.core.storage.setItem(this.storageKey,Array.from(this.events.values())),this.shouldPersist=!1},this.restore=async()=>{try{let s=await this.core.storage.getItem(this.storageKey)||[];if(!s.length)return;s.forEach(i=>{this.events.set(i.eventId,{...i,...this.setMethods(i.eventId)})})}catch(s){this.logger.warn(s)}},this.submit=async()=>{if(!this.telemetryEnabled||this.events.size===0)return;let s=[];for(let[i,o]of this.events)o.props.type&&s.push(o);if(s.length!==0)try{if((await this.sendEvent(s)).ok)for(let i of s)this.events.delete(i.eventId),this.shouldPersist=!0}catch(i){this.logger.warn(i)}},this.sendEvent=async s=>{let i=this.getAppDomain()?"":"&sp=desktop";return await fetch(`${Z5}?projectId=${this.core.projectId}&st=events_sdk&sv=js-${tp}${i}`,{method:"POST",body:JSON.stringify(s)})},this.getAppDomain=()=>bd().url,this.logger=ft(r,this.context),this.telemetryEnabled=n,n?this.restore().then(async()=>{await this.submit(),this.setEventListeners()}):this.persist()}get storageKey(){return this.storagePrefix+this.storageVersion+this.core.customStoragePrefix+"//"+this.context}},Q5=class k2 extends _a{constructor(e){super(e),this.protocol=N2,this.version=P2,this.name=Pu,this.events=new en.EventEmitter,this.initialized=!1,this.on=(o,a)=>this.events.on(o,a),this.once=(o,a)=>this.events.once(o,a),this.off=(o,a)=>this.events.off(o,a),this.removeListener=(o,a)=>this.events.removeListener(o,a),this.dispatchEnvelope=({topic:o,message:a,sessionExists:c})=>{if(!o||!a)return;let u={topic:o,message:a,publishedAt:Date.now(),transportType:fe.link_mode};this.relayer.onLinkMessageEvent(u,{sessionExists:c})};let r=this.getGlobalCore(e?.customStoragePrefix);if(r)try{return this.customStoragePrefix=r.customStoragePrefix,this.logger=r.logger,this.heartbeat=r.heartbeat,this.crypto=r.crypto,this.history=r.history,this.expirer=r.expirer,this.storage=r.storage,this.relayer=r.relayer,this.pairing=r.pairing,this.verify=r.verify,this.echoClient=r.echoClient,this.linkModeSupportedApps=r.linkModeSupportedApps,this.eventClient=r.eventClient,this.initialized=r.initialized,this.logChunkController=r.logChunkController,r}catch(o){console.warn("Failed to copy global core",o)}this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||U2,this.customStoragePrefix=e?.customStoragePrefix?`:${e.customStoragePrefix}`:"";let n=bg({level:typeof e?.logger=="string"&&e.logger?e.logger:x5.logger,name:Pu}),{logger:s,chunkLoggerController:i}=va({opts:n,maxSizeInBytes:e?.maxLogBlobSizeInBytes,loggerOverride:e?.logger});this.logChunkController=i,this.logChunkController?.downloadLogsBlobInBrowser&&(window.downloadLogsBlobInBrowser=async()=>{this.logChunkController?.downloadLogsBlobInBrowser&&this.logChunkController?.downloadLogsBlobInBrowser({clientId:await this.crypto.getClientId()})}),this.logger=ft(s,this.name),this.heartbeat=new da,this.crypto=new np(this,this.logger,e?.keychain),this.history=new lp(this,this.logger),this.expirer=new fp(this,this.logger),this.storage=e?.storage?e.storage:new ma({...b5,...e?.storageOptions}),this.relayer=new cp({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new up(this,this.logger),this.verify=new hp(this,this.logger,this.storage),this.echoClient=new dp(this.projectId||"",this.logger),this.linkModeSupportedApps=[],this.eventClient=new pp(this,this.logger,e?.telemetryEnabled),this.setGlobalCore(this)}static async init(e){let r=new k2(e);await r.initialize();let n=await r.crypto.getClientId();return await r.storage.setItem(P5,n),r}get context(){return We(this.logger)}async start(){this.initialized||await this.initialize()}async getLogsBlob(){return this.logChunkController?.logsToBlob({clientId:await this.crypto.getClientId()})}async addLinkModeSupportedApp(e){this.linkModeSupportedApps.includes(e)||(this.linkModeSupportedApps.push(e),await this.storage.setItem(O2,this.linkModeSupportedApps))}async initialize(){this.logger.trace("Initialized");try{await this.crypto.init(),await this.history.init(),await this.expirer.init(),await this.relayer.init(),await this.heartbeat.init(),await this.pairing.init(),this.linkModeSupportedApps=await this.storage.getItem(O2)||[],this.initialized=!0,this.logger.info("Core Initialization Success")}catch(e){throw this.logger.warn(e,`Core Initialization Failure at epoch ${Date.now()}`),this.logger.error(e.message),e}}getGlobalCore(e=""){try{if(this.isGlobalCoreDisabled())return;let r=`_walletConnectCore_${e}`,n=`${r}_count`;return globalThis[n]=(globalThis[n]||0)+1,globalThis[n]>1&&console.warn(`WalletConnect Core is already initialized. This is probably a mistake and can lead to unexpected behavior. Init() was called ${globalThis[n]} times.`),globalThis[r]}catch(r){console.warn("Failed to get global WalletConnect core",r);return}}setGlobalCore(e){try{if(this.isGlobalCoreDisabled())return;let r=`_walletConnectCore_${e.opts?.customStoragePrefix||""}`;globalThis[r]=e}catch(r){console.warn("Failed to set global WalletConnect core",r)}}isGlobalCoreDisabled(){try{return typeof process<"u"&&process.env.DISABLE_GLOBAL_CORE==="true"}catch{return!0}}},M2=Q5;var re=Ie($s(),1);var H2="wc",z2=2,V2="client",Bp=`${H2}@${z2}:${V2}:`,mp={name:V2,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.org"};var q2="WALLETCONNECT_DEEPLINK_CHOICE";var eR="proposal";var F2="Proposal expired",tR="session",Ri=re.SEVEN_DAYS,rR="engine",$e={wc_sessionPropose:{req:{ttl:re.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:re.FIVE_MINUTES,prompt:!1,tag:1101},reject:{ttl:re.FIVE_MINUTES,prompt:!1,tag:1120},autoReject:{ttl:re.FIVE_MINUTES,prompt:!1,tag:1121}},wc_sessionSettle:{req:{ttl:re.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:re.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:re.ONE_DAY,prompt:!1,tag:1104},res:{ttl:re.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:re.ONE_DAY,prompt:!1,tag:1106},res:{ttl:re.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:re.FIVE_MINUTES*3,prompt:!0,tag:1108},res:{ttl:re.FIVE_MINUTES*3,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:re.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:re.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:re.ONE_DAY,prompt:!1,tag:1112},res:{ttl:re.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:re.ONE_DAY,prompt:!1,tag:1114},res:{ttl:re.ONE_DAY,prompt:!1,tag:1115}},wc_sessionAuthenticate:{req:{ttl:re.ONE_HOUR,prompt:!0,tag:1116},res:{ttl:re.ONE_HOUR,prompt:!1,tag:1117},reject:{ttl:re.FIVE_MINUTES,prompt:!1,tag:1118},autoReject:{ttl:re.FIVE_MINUTES,prompt:!1,tag:1119}}},yp={min:re.FIVE_MINUTES,max:re.SEVEN_DAYS},br={idle:"IDLE",active:"ACTIVE"},nR={eth_sendTransaction:{key:""},eth_sendRawTransaction:{key:""},wallet_sendCalls:{key:""},solana_signTransaction:{key:"signature"},solana_signAllTransactions:{key:"transactions"},solana_signAndSendTransaction:{key:"signature"},sui_signAndExecuteTransaction:{key:"digest"},sui_signTransaction:{key:""},hedera_signAndExecuteTransaction:{key:"transactionId"},hedera_executeTransaction:{key:"transactionId"},near_signTransaction:{key:""},near_signTransactions:{key:""},tron_signTransaction:{key:"txID"},xrpl_signTransaction:{key:""},xrpl_signTransactionFor:{key:""},algo_signTxn:{key:""},sendTransfer:{key:"txid"},stacks_stxTransfer:{key:"txId"},polkadot_signTransaction:{key:""},cosmos_signDirect:{key:""}},sR="request",iR=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],oR="wc";var aR="auth",cR="authKeys",uR="pairingTopics",lR="requests",Lu=`${oR}@${1.5}:${aR}:`,Ln=`${Lu}:PUB_KEY`,wp=class extends Ua{constructor(e){super(e),this.name=rR,this.events=new Uu.default,this.initialized=!1,this.requestQueue={state:br.idle,queue:[]},this.sessionRequestQueue={state:br.idle,queue:[]},this.emittedSessionRequests=new cu({limit:500}),this.requestQueueDelay=re.ONE_SECOND,this.expectedPairingMethodMap=new Map,this.recentlyDeletedMap=new Map,this.recentlyDeletedLimit=200,this.relayMessageCache=[],this.pendingSessions=new Map,this.init=async()=>{this.initialized||(await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.registerPairingEvents(),this.registerSubscriptionCleanup(),await this.registerLinkModeListeners(),this.client.core.pairing.register({methods:Object.keys($e)}),this.initialized=!0,setTimeout(async()=>{await this.processPendingMessageEvents(),this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()},(0,re.toMiliseconds)(this.requestQueueDelay)))},this.connect=async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();let n={...r,requiredNamespaces:r.requiredNamespaces||{},optionalNamespaces:r.optionalNamespaces||{}};await this.isValidConnect(n),n.optionalNamespaces=mb(n.requiredNamespaces,n.optionalNamespaces),n.requiredNamespaces={};let{pairingTopic:s,requiredNamespaces:i,optionalNamespaces:o,sessionProperties:a,scopedProperties:c,relays:u,authentication:f,walletPay:l}=n,h=f?.[0]?.ttl||$e.wc_sessionPropose.req.ttl||re.FIVE_MINUTES;this.validateRequestExpiry(h);let d=s,p,g=!1;try{if(d){let N=this.client.core.pairing.pairings.get(d);this.client.logger.warn("connect() with existing pairing topic is deprecated and will be removed in the next major release."),g=N.active}}catch(N){throw this.client.logger.error(`connect() -> pairing.get(${d}) failed`),N}if(!d||!g){let{topic:N,uri:I}=await this.client.core.pairing.create({internal:{skipSubscribe:!0}});d=N,p=I}if(!d){let{message:N}=F("NO_MATCHING_KEY",`connect() pairing topic: ${d}`);throw new Error(N)}let m=await this.client.core.crypto.generateKeyPair(),b=_e(h),T={requiredNamespaces:i,optionalNamespaces:o,relays:u??[{protocol:gp}],proposer:{publicKey:m,metadata:this.client.metadata},expiryTimestamp:b,pairingTopic:d,...a&&{sessionProperties:a},...c&&{scopedProperties:c},id:kt(),...(f||l)&&{requests:{authentication:f?.map(N=>{let{domain:I,chains:k,nonce:L,uri:P,exp:E,nbf:B,type:y,statement:x,requestId:S,resources:A,signatureTypes:_}=N;return{domain:I,chains:k,nonce:L,type:y??"caip122",aud:P,version:"1",iat:new Date().toISOString(),exp:E,nbf:B,statement:x,requestId:S,resources:A,signatureTypes:_}}),walletPay:l}}},w=ae("session_connect",T.id),{reject:v,resolve:R,done:C}=Zr(h,F2),O=({id:N})=>{if(N===T.id){this.client.events.off("proposal_expire",O);let I=this.pendingSessions.get(T.id);if(I){let{sessionTopic:k,publicKey:L}=I;Promise.all([this.client.core.relayer.unsubscribe(k),this.client.core.crypto.keychain.has(k)?this.client.core.crypto.deleteSymKey(k):Promise.resolve(),this.client.core.crypto.keychain.has(L)?this.client.core.crypto.deleteKeyPair(L):Promise.resolve()]).catch(P=>this.client.logger.warn(P))}this.pendingSessions.delete(T.id),this.events.emit(w,{error:{message:F2,code:0}})}};return this.client.events.on("proposal_expire",O),this.events.once(w,({error:N,session:I})=>{this.client.events.off("proposal_expire",O),N?v(N):I&&R(I)}),await this.setProposal(T.id,T),await this.sendProposeSession({proposal:T,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:{correlationId:T.id}}}).catch(N=>{throw this.deleteProposal(T.id),N}),{uri:p,approval:C}},this.pair=async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{return await this.client.core.pairing.pair(r)}catch(n){throw this.client.logger.error("pair() failed"),n}},this.approve=async r=>{let n=this.client.core.eventClient.createEvent({properties:{topic:r?.id?.toString(),trace:[Ft.session_approve_started]}});try{this.isInitialized(),await this.confirmOnlineStateOrThrow()}catch(O){throw n.setError(Pn.no_internet_connection),O}try{await this.isValidProposalId(r?.id)}catch(O){throw this.client.logger.error(`approve() -> proposal.get(${r?.id}) failed`),n.setError(Pn.proposal_not_found),O}try{await this.isValidApprove(r)}catch(O){throw this.client.logger.error("approve() -> isValidApprove() failed"),n.setError(Pn.session_approve_namespace_validation_failure),O}let{id:s,relayProtocol:i,namespaces:o,sessionProperties:a,scopedProperties:c,sessionConfig:u,proposalRequestsResponses:f}=r,l=this.client.proposal.get(s);this.client.core.eventClient.deleteEvent({eventId:n.eventId});let{pairingTopic:h,proposer:d,requiredNamespaces:p,optionalNamespaces:g}=l,m=this.client.core.eventClient?.getEvent({topic:h});m||(m=this.client.core.eventClient?.createEvent({type:Ft.session_approve_started,properties:{topic:h,trace:[Ft.session_approve_started,Ft.session_namespaces_validation_success]}}));let b=await this.client.core.crypto.generateKeyPair(),T=d.publicKey,w=await this.client.core.crypto.generateSharedKey(b,T),v={relay:{protocol:i??"irn"},namespaces:o,controller:{publicKey:b,metadata:this.client.metadata},expiry:_e(Ri),...a&&{sessionProperties:a},...c&&{scopedProperties:c},...u&&{sessionConfig:u},proposalRequestsResponses:f},R=fe.relay;m.addTrace(Ft.subscribing_session_topic);try{await this.client.core.relayer.subscribe(w,{transportType:R,internal:{skipSubscribe:!0}})}catch(O){throw m.setError(Pn.subscribe_session_topic_failure),O}m.addTrace(Ft.subscribe_session_topic_success);let C={...v,topic:w,requiredNamespaces:p,optionalNamespaces:g,pairingTopic:h,acknowledged:!1,self:v.controller,peer:{publicKey:d.publicKey,metadata:d.metadata},controller:b,transportType:fe.relay,authentication:f?.authentication,walletPayResult:f?.walletPay};await this.client.session.set(w,C),m.addTrace(Ft.store_session);try{await this.sendApproveSession({sessionTopic:w,proposal:l,pairingProposalResponse:{relay:{protocol:i??"irn"},responderPublicKey:b},sessionSettleRequest:v,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:{correlationId:s,...this.getTVFApproveParams(C)}}}),m.addTrace(Ft.session_approve_publish_success)}catch(O){throw this.client.logger.error(O),this.client.session.delete(w,pe("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe(w),O}return this.client.core.eventClient.deleteEvent({eventId:m.eventId}),await this.client.core.pairing.updateMetadata({topic:h,metadata:d.metadata}),await this.deleteProposal(s),await this.client.core.pairing.activate({topic:h}),await this.setExpiry(w,_e(Ri)),{topic:w,acknowledged:()=>Promise.resolve(this.client.session.get(w))}},this.reject=async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidReject(r)}catch(o){throw this.client.logger.error("reject() -> isValidReject() failed"),o}let{id:n,reason:s}=r,i;try{i=this.client.proposal.get(n).pairingTopic}catch(o){throw this.client.logger.error(`reject() -> proposal.get(${n}) failed`),o}i&&await this.sendError({id:n,topic:i,error:s,rpcOpts:$e.wc_sessionPropose.reject}),await this.deleteProposal(n)},this.update=async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidUpdate(r)}catch(l){throw this.client.logger.error("update() -> isValidUpdate() failed"),l}let{topic:n,namespaces:s}=r,{done:i,resolve:o,reject:a}=Zr(re.FIVE_MINUTES,"Session update request expired without receiving any acknowledgement"),c=kt(),u=Mt().toString(),f=this.client.session.get(n).namespaces;return this.events.once(ae("session_update",c),({error:l})=>{l?a(l):o()}),await this.client.session.update(n,{namespaces:s}),await this.sendRequest({topic:n,method:"wc_sessionUpdate",params:{namespaces:s},throwOnFailedPublish:!0,clientRpcId:c,relayRpcId:u}).catch(l=>{this.client.logger.error(l),this.client.session.update(n,{namespaces:f}),a(l)}),{acknowledged:i}},this.extend=async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidExtend(r)}catch(c){throw this.client.logger.error("extend() -> isValidExtend() failed"),c}let{topic:n}=r,s=kt(),{done:i,resolve:o,reject:a}=Zr(re.FIVE_MINUTES,"Session extend request expired without receiving any acknowledgement");return this.events.once(ae("session_extend",s),({error:c})=>{c?a(c):o()}),await this.setExpiry(n,_e(Ri)),this.sendRequest({topic:n,method:"wc_sessionExtend",params:{},clientRpcId:s,throwOnFailedPublish:!0}).catch(c=>{a(c)}),{acknowledged:i}},this.request=async r=>{this.isInitialized();try{await this.isValidRequest(r)}catch(m){throw this.client.logger.error("request() -> isValidRequest() failed"),m}let{chainId:n,request:s,topic:i,expiry:o=$e.wc_sessionRequest.req.ttl}=r,a=this.client.session.get(i);a?.transportType===fe.relay&&await this.confirmOnlineStateOrThrow();let c=kt(),u=Mt().toString(),{done:f,resolve:l,reject:h}=Zr(o,"Request expired. Please try again.");this.events.once(ae("session_request",c),({error:m,result:b})=>{m?h(m):l(b)});let d="wc_sessionRequest",p=this.getAppLinkIfEnabled(a.peer.metadata,a.transportType);if(p)return await this.sendRequest({clientRpcId:c,relayRpcId:u,topic:i,method:d,params:{request:{...s,expiryTimestamp:_e(o)},chainId:n},expiry:o,throwOnFailedPublish:!0,appLink:p}).catch(m=>h(m)),this.client.events.emit("session_request_sent",{topic:i,request:s,chainId:n,id:c}),await f();let g={request:{...s,expiryTimestamp:_e(o)},chainId:n};return await Promise.all([new Promise(async m=>{await this.sendRequest({clientRpcId:c,relayRpcId:u,topic:i,method:d,params:g,expiry:o,throwOnFailedPublish:!0,tvf:this.getTVFParams(c,g)}).catch(b=>h(b)),this.client.events.emit("session_request_sent",{topic:i,request:s,chainId:n,id:c}),m()}),new Promise(async m=>{if(!a.sessionConfig?.disableDeepLink){let b=await zx(this.client.core.storage,q2);await Hx({id:c,topic:i,wcDeepLink:b})}m()}),f()]).then(m=>m[2])},this.respond=async r=>{this.isInitialized();let n=this.client.core.eventClient.createEvent({properties:{topic:r?.topic||r?.response?.id?.toString(),trace:[Ft.session_request_response_started]}});try{await this.isValidRespond(r)}catch(u){throw n.addTrace(u?.message),n.setError(Pn.session_request_response_validation_failure),u}n.addTrace(Ft.session_request_response_validation_success);let{topic:s,response:i}=r,{id:o}=i,a=this.client.session.get(s);a.transportType===fe.relay&&await this.confirmOnlineStateOrThrow();let c=this.getAppLinkIfEnabled(a.peer.metadata,a.transportType);try{n.addTrace(Ft.session_request_response_publish_started),At(i)?await this.sendResult({id:o,topic:s,result:i.result,throwOnFailedPublish:!0,appLink:c}):nt(i)&&await this.sendError({id:o,topic:s,error:i.error,appLink:c}),this.cleanupAfterResponse(r)}catch(u){throw n.addTrace(u?.message),n.setError(Pn.session_request_response_publish_failure),u}},this.ping=async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidPing(r)}catch(s){throw this.client.logger.error("ping() -> isValidPing() failed"),s}let{topic:n}=r;if(this.client.session.keys.includes(n)){let s=kt(),i=Mt().toString(),{done:o,resolve:a,reject:c}=Zr(re.FIVE_MINUTES,"Ping request expired without receiving any acknowledgement");this.events.once(ae("session_ping",s),({error:u})=>{u?c(u):a()}),await Promise.all([this.sendRequest({topic:n,method:"wc_sessionPing",params:{},throwOnFailedPublish:!0,clientRpcId:s,relayRpcId:i}),o()])}else this.client.core.pairing.pairings.keys.includes(n)&&(this.client.logger.warn("ping() on pairing topic is deprecated and will be removed in the next major release."),await this.client.core.pairing.ping({topic:n}))},this.emit=async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidEmit(r);let{topic:n,event:s,chainId:i}=r,o=Mt().toString(),a=kt();await this.sendRequest({topic:n,method:"wc_sessionEvent",params:{event:s,chainId:i},throwOnFailedPublish:!0,relayRpcId:o,clientRpcId:a})},this.disconnect=async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidDisconnect(r);let{topic:n}=r;if(this.client.session.keys.includes(n))await this.sendRequest({topic:n,method:"wc_sessionDelete",params:pe("USER_DISCONNECTED"),throwOnFailedPublish:!0}),await this.deleteSession({topic:n,emitEvent:!1});else if(this.client.core.pairing.pairings.keys.includes(n))await this.client.core.pairing.disconnect({topic:n});else{let{message:s}=F("MISMATCHED_TOPIC",`Session or pairing topic not found: ${n}`);throw new Error(s)}},this.find=r=>(this.isInitialized(),this.client.session.getAll().filter(n=>yb(n,r))),this.getPendingSessionRequests=()=>this.client.pendingRequest.getAll(),this.authenticate=async(r,n)=>{this.isInitialized(),this.isValidAuthenticate(r);let s=n&&this.client.core.linkModeSupportedApps.includes(n)&&this.client.metadata.redirect?.linkMode,i=s?fe.link_mode:fe.relay;i===fe.relay&&await this.confirmOnlineStateOrThrow();let{chains:o,statement:a="",uri:c,domain:u,nonce:f,type:l,exp:h,nbf:d,methods:p=[],expiry:g}=r,m=[...r.resources||[]],{topic:b,uri:T}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"],transportType:i});if(this.client.logger.info({message:"Generated new pairing",pairing:{topic:b,uri:T}}),this.client.auth.authKeys.keys.includes(Ln)){let{responseTopic:A,publicKey:_}=this.client.auth.authKeys.get(Ln);A&&(await this.client.core.relayer.unsubscribe(A).catch(D=>this.client.logger.warn(D)),await this.client.auth.pairingTopics.delete(A,{message:"replaced",code:0}).catch(D=>this.client.logger.warn(D))),_&&this.client.core.crypto.keychain.has(_)&&await this.client.core.crypto.deleteKeyPair(_)}let w=await this.client.core.crypto.generateKeyPair(),v=vi(w);if(await Promise.all([this.client.auth.authKeys.set(Ln,{responseTopic:v,publicKey:w}),this.client.auth.pairingTopics.set(v,{topic:v,pairingTopic:b})]),await this.client.core.relayer.subscribe(v,{transportType:i}),this.client.logger.info(`sending request to new pairing topic: ${b}`),p.length>0){let{namespace:A}=Ro(o[0]),_=Zx(A,"request",p);Po(m)&&(_=Qx(_,m.pop())),m.push(_)}let R=g&&g>$e.wc_sessionAuthenticate.req.ttl?g:$e.wc_sessionAuthenticate.req.ttl,C={authPayload:{type:l??"caip122",chains:o,statement:a,aud:c,domain:u,version:"1",nonce:f,iat:new Date().toISOString(),exp:h,nbf:d,resources:m},requester:{publicKey:w,metadata:this.client.metadata},expiryTimestamp:_e(R)},O={eip155:{chains:o,methods:[...new Set(["personal_sign",...p])],events:["chainChanged","accountsChanged"]}},N={requiredNamespaces:{},optionalNamespaces:O,relays:[{protocol:"irn"}],pairingTopic:b,proposer:{publicKey:w,metadata:this.client.metadata},expiryTimestamp:_e($e.wc_sessionPropose.req.ttl),id:kt()},{done:I,resolve:k,reject:L}=Zr(R,"Request expired"),P=kt(),E=ae("session_connect",N.id),B=ae("session_request",P),y=async({error:A,session:_})=>{this.events.off(B,x),A?L(A):_&&k({session:_})},x=async A=>{if(await this.deletePendingAuthRequest(P,{message:"fulfilled",code:0}),A.error){let H=pe("WC_METHOD_UNSUPPORTED","wc_sessionAuthenticate");return A.error.code===H.code?void 0:(this.events.off(E,y),L(A.error.message))}await this.deleteProposal(N.id),this.events.off(E,y);let{cacaos:_,responder:D}=A.result,U=[],q=[];for(let H of _){await Bd({cacao:H,projectId:this.client.core.projectId})||(this.client.logger.error(H,"Signature verification failed"),L(pe("SESSION_SETTLEMENT_FAILED","Signature verification failed")));let{p:W}=H,J=Po(W.resources),ee=[mu(W.iss)],Y=No(W.iss);if(J){let ne=Td(J),Se=Rd(J);U.push(...ne),ee.push(...Se)}for(let ne of ee)q.push(`${ne}:${Y}`)}let z=await this.client.core.crypto.generateSharedKey(w,D.publicKey),V;U.length>0&&(V={topic:z,acknowledged:!0,self:{publicKey:w,metadata:this.client.metadata},peer:D,controller:D.publicKey,expiry:_e(Ri),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:b,namespaces:kd([...new Set(U)],[...new Set(q)]),transportType:i},await this.client.core.relayer.subscribe(z,{transportType:i}),await this.client.session.set(z,V),b&&await this.client.core.pairing.updateMetadata({topic:b,metadata:D.metadata}),V=this.client.session.get(z)),this.client.metadata.redirect?.linkMode&&D.metadata.redirect?.linkMode&&D.metadata.redirect?.universal&&n&&(this.client.core.addLinkModeSupportedApp(D.metadata.redirect.universal),this.client.session.update(z,{transportType:fe.link_mode})),k({auths:_,session:V})};this.events.once(E,y),this.events.once(B,x);let S;try{if(s){let A=Bt("wc_sessionAuthenticate",C,P);this.client.core.history.set(b,A);let _=await this.client.core.crypto.encode("",A,{type:Ei,encoding:Qr});S=ko(n,b,_)}else await Promise.all([this.sendRequest({topic:b,method:"wc_sessionAuthenticate",params:C,expiry:r.expiry,throwOnFailedPublish:!0,clientRpcId:P}),this.sendRequest({topic:b,method:"wc_sessionPropose",params:N,expiry:$e.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:N.id})])}catch(A){throw this.events.off(E,y),this.events.off(B,x),A}return await this.setProposal(N.id,N),await this.setAuthRequest(P,{request:{...C,verifyContext:{}},pairingTopic:b,transportType:i}),{uri:S??T,response:I}},this.approveSessionAuthenticate=async r=>{let{id:n,auths:s}=r,i=this.client.core.eventClient.createEvent({properties:{topic:n.toString(),trace:[Un.authenticated_session_approve_started]}});try{this.isInitialized()}catch(m){throw i.setError(Ti.no_internet_connection),m}let o=this.getPendingAuthRequest(n);if(!o)throw i.setError(Ti.authenticated_session_pending_request_not_found),new Error(`Could not find pending auth request with id ${n}`);let a=o.transportType||fe.relay;a===fe.relay&&await this.confirmOnlineStateOrThrow();let c=o.requester.publicKey,u=await this.client.core.crypto.generateKeyPair(),f=vi(c),l={type:Jt,receiverPublicKey:c,senderPublicKey:u},h=[],d=[];for(let m of s){if(!await Bd({cacao:m,projectId:this.client.core.projectId})){i.setError(Ti.invalid_cacao);let R=pe("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:n,topic:f,error:R,encodeOpts:l}),new Error(R.message)}i.addTrace(Un.cacaos_verified);let{p:b}=m,T=Po(b.resources),w=[mu(b.iss)],v=No(b.iss);if(T){let R=Td(T),C=Rd(T);h.push(...R),w.push(...C)}for(let R of w)d.push(`${R}:${v}`)}let p=await this.client.core.crypto.generateSharedKey(u,c);i.addTrace(Un.create_authenticated_session_topic);let g;if(h?.length>0){g={topic:p,acknowledged:!0,self:{publicKey:u,metadata:this.client.metadata},peer:{publicKey:c,metadata:o.requester.metadata},controller:c,expiry:_e(Ri),authentication:s,requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:o.pairingTopic,namespaces:kd([...new Set(h)],[...new Set(d)]),transportType:a},i.addTrace(Un.subscribing_authenticated_session_topic);try{await this.client.core.relayer.subscribe(p,{transportType:a})}catch(m){throw i.setError(Ti.subscribe_authenticated_session_topic_failure),m}i.addTrace(Un.subscribe_authenticated_session_topic_success),await this.client.session.set(p,g),i.addTrace(Un.store_authenticated_session),await this.client.core.pairing.updateMetadata({topic:o.pairingTopic,metadata:o.requester.metadata})}i.addTrace(Un.publishing_authenticated_session_approve);try{await this.sendResult({topic:f,id:n,result:{cacaos:s,responder:{publicKey:u,metadata:this.client.metadata}},encodeOpts:l,throwOnFailedPublish:!0,appLink:this.getAppLinkIfEnabled(o.requester.metadata,a)})}catch(m){throw i.setError(Ti.authenticated_session_approve_publish_failure),m}return await this.client.auth.requests.delete(n,{message:"fulfilled",code:0}),await this.client.core.pairing.activate({topic:o.pairingTopic}),this.client.core.eventClient.deleteEvent({eventId:i.eventId}),{session:g}},this.rejectSessionAuthenticate=async r=>{this.isInitialized();let{id:n,reason:s}=r,i=this.getPendingAuthRequest(n);if(!i)throw new Error(`Could not find pending auth request with id ${n}`);i.transportType===fe.relay&&await this.confirmOnlineStateOrThrow();let o=i.requester.publicKey,a=await this.client.core.crypto.generateKeyPair(),c=vi(o),u={type:Jt,receiverPublicKey:o,senderPublicKey:a};await this.sendError({id:n,topic:c,error:s,encodeOpts:u,rpcOpts:$e.wc_sessionAuthenticate.reject,appLink:this.getAppLinkIfEnabled(i.requester.metadata,i.transportType)}),await this.client.auth.requests.delete(n,{message:"rejected",code:0}),await this.deleteProposal(n)},this.formatAuthMessage=r=>{this.isInitialized();let{request:n,iss:s}=r;return Ad(n,s)},this.processRelayMessageCache=()=>{setTimeout(async()=>{if(this.relayMessageCache.length!==0)for(;this.relayMessageCache.length>0;)try{let r=this.relayMessageCache.shift();r&&await this.onRelayMessage(r)}catch(r){this.client.logger.error(r)}},50)},this.cleanupDuplicatePairings=async r=>{if(r.pairingTopic)try{let n=this.client.core.pairing.pairings.get(r.pairingTopic),s=this.client.core.pairing.pairings.getAll().filter(i=>i.peerMetadata?.url&&i.peerMetadata?.url===r.peer.metadata.url&&i.topic&&i.topic!==n.topic);if(s.length===0)return;this.client.logger.info(`Cleaning up ${s.length} duplicate pairing(s)`),await Promise.all(s.map(i=>this.client.core.pairing.disconnect({topic:i.topic}))),this.client.logger.info("Duplicate pairings clean up finished")}catch(n){this.client.logger.error(n)}},this.deleteSession=async r=>{let{topic:n,expirerHasDeleted:s=!1,emitEvent:i=!0,id:o=0}=r,{self:a}=this.client.session.get(n);await this.client.core.relayer.unsubscribe(n),await this.client.session.delete(n,pe("USER_DISCONNECTED")),this.addToRecentlyDeleted(n,"session"),this.client.core.crypto.keychain.has(a.publicKey)&&await this.client.core.crypto.deleteKeyPair(a.publicKey),this.client.core.crypto.keychain.has(n)&&await this.client.core.crypto.deleteSymKey(n),s||this.client.core.expirer.del(n),this.client.core.storage.removeItem(q2).catch(c=>this.client.logger.warn(c)),n===this.sessionRequestQueue.queue[0]?.topic&&(this.sessionRequestQueue.state=br.idle),await Promise.all(this.getPendingSessionRequests().filter(c=>c.topic===n).map(c=>this.deletePendingSessionRequest(c.id,pe("USER_DISCONNECTED")))),i&&this.client.events.emit("session_delete",{id:o,topic:n})},this.deleteProposal=async(r,n)=>{if(n)try{let s=this.client.proposal.get(r);this.client.core.eventClient.getEvent({topic:s.pairingTopic})?.setError(Pn.proposal_expired)}catch{}await Promise.all([this.client.proposal.delete(r,pe("USER_DISCONNECTED")),n?Promise.resolve():this.client.core.expirer.del(r)]),this.addToRecentlyDeleted(r,"proposal")},this.deletePendingSessionRequest=async(r,n,s=!1)=>{await Promise.all([this.client.pendingRequest.delete(r,n),s?Promise.resolve():this.client.core.expirer.del(r)]),this.addToRecentlyDeleted(r,"request"),this.sessionRequestQueue.queue=this.sessionRequestQueue.queue.filter(i=>i.id!==r),s&&(this.sessionRequestQueue.state=br.idle,this.client.events.emit("session_request_expire",{id:r}))},this.deletePendingAuthRequest=async(r,n,s=!1)=>{await Promise.all([this.client.auth.requests.delete(r,n),s?Promise.resolve():this.client.core.expirer.del(r)])},this.setExpiry=async(r,n)=>{this.client.session.keys.includes(r)&&(this.client.core.expirer.set(r,n),await this.client.session.update(r,{expiry:n}))},this.setProposal=async(r,n)=>{this.client.core.expirer.set(r,_e($e.wc_sessionPropose.req.ttl)),await this.client.proposal.set(r,n)},this.setAuthRequest=async(r,n)=>{let{request:s,pairingTopic:i,transportType:o=fe.relay}=n;this.client.core.expirer.set(r,s.expiryTimestamp),await this.client.auth.requests.set(r,{authPayload:s.authPayload,requester:s.requester,expiryTimestamp:s.expiryTimestamp,id:r,pairingTopic:i,verifyContext:s.verifyContext,transportType:o})},this.setPendingSessionRequest=async r=>{let{id:n,topic:s,params:i,verifyContext:o}=r,a=i.request.expiryTimestamp||_e($e.wc_sessionRequest.req.ttl);this.client.core.expirer.set(n,a),await this.client.pendingRequest.set(n,{id:n,topic:s,params:i,verifyContext:o})},this.sendRequest=async r=>{let{topic:n,method:s,params:i,expiry:o,relayRpcId:a,clientRpcId:c,throwOnFailedPublish:u,appLink:f,tvf:l,publishOpts:h={}}=r,d=Bt(s,i,c),p,g=!!f;try{let T=g?Qr:Oe;p=await this.client.core.crypto.encode(n,d,{encoding:T})}catch(T){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${n} failed`),T}let m;if(iR.includes(s)){let T=yt(JSON.stringify(d)),w=yt(p);m=await this.client.core.verify.register({id:w,decryptedId:T})}let b={...$e[s].req,...h};if(b.attestation=m,o&&(b.ttl=o),a&&(b.id=a),this.client.core.history.set(n,d),g){let T=ko(f,n,p);await globalThis.Linking.openURL(T,this.client.name)}else b.tvf={...l,correlationId:d.id},u?(b.internal={...b.internal,throwOnFailedPublish:!0},await this.client.core.relayer.publish(n,p,b)):this.client.core.relayer.publish(n,p,b).catch(T=>this.client.logger.error(T));return d.id},this.sendProposeSession=async r=>{let{proposal:n,publishOpts:s}=r,i=Bt("wc_sessionPropose",n,n.id);this.client.core.history.set(n.pairingTopic,i);let o=await this.client.core.crypto.encode(n.pairingTopic,i,{encoding:Oe}),a=yt(JSON.stringify(i)),c=yt(o),u=await this.client.core.verify.register({id:c,decryptedId:a});await this.client.core.relayer.publishCustom({payload:{pairingTopic:n.pairingTopic,sessionProposal:o},opts:{...s,publishMethod:"wc_proposeSession",attestation:u}})},this.sendApproveSession=async r=>{let{sessionTopic:n,pairingProposalResponse:s,proposal:i,sessionSettleRequest:o,publishOpts:a}=r,c=Bs(i.id,s),u=await this.client.core.crypto.encode(i.pairingTopic,c,{encoding:Oe}),f=Bt("wc_sessionSettle",o,a?.id),l=await this.client.core.crypto.encode(n,f,{encoding:Oe});this.client.core.history.set(n,f),await this.client.core.relayer.publishCustom({payload:{sessionTopic:n,pairingTopic:i.pairingTopic,sessionProposalResponse:u,sessionSettlementRequest:l},opts:{...a,publishMethod:"wc_approveSession"}})},this.sendResult=async r=>{let{id:n,topic:s,result:i,throwOnFailedPublish:o,encodeOpts:a,appLink:c}=r,u=Bs(n,i),f,l=c&&typeof globalThis?.Linking<"u";try{let p=l?Qr:Oe;f=await this.client.core.crypto.encode(s,u,{...a||{},encoding:p})}catch(p){throw await this.cleanup(),this.client.logger.error(`sendResult() -> core.crypto.encode() for topic ${s} failed`),p}let h,d;try{h=await this.client.core.history.get(s,n);let p=h.request;try{d=this.getTVFParams(n,p.params,i)}catch(g){this.client.logger.warn(`sendResult() -> getTVFParams() failed: ${g?.message}`)}}catch(p){throw this.client.logger.error(`sendResult() -> history.get(${s}, ${n}) failed`),p}if(l){let p=ko(c,s,f);await globalThis.Linking.openURL(p,this.client.name)}else{let p=h.request.method,g=$e[p].res;g.tvf={...d,correlationId:n},o?(g.internal={...g.internal,throwOnFailedPublish:!0},await this.client.core.relayer.publish(s,f,g)):this.client.core.relayer.publish(s,f,g).catch(m=>this.client.logger.error(m))}await this.client.core.history.resolve(u)},this.sendError=async r=>{let{id:n,topic:s,error:i,encodeOpts:o,rpcOpts:a,appLink:c}=r,u=As(n,i),f,l=c&&typeof globalThis?.Linking<"u";try{let d=l?Qr:Oe;f=await this.client.core.crypto.encode(s,u,{...o||{},encoding:d})}catch(d){throw await this.cleanup(),this.client.logger.error(`sendError() -> core.crypto.encode() for topic ${s} failed`),d}let h;try{h=await this.client.core.history.get(s,n)}catch(d){throw this.client.logger.error(`sendError() -> history.get(${s}, ${n}) failed`),d}if(l){let d=ko(c,s,f);await globalThis.Linking.openURL(d,this.client.name)}else{let d=h.request.method,p=a||$e[d].res;this.client.core.relayer.publish(s,f,p)}await this.client.core.history.resolve(u)},this.cleanup=async()=>{let r=[],n=[];this.client.session.getAll().forEach(s=>{let i=!1;mr(s.expiry)&&(i=!0),this.client.core.crypto.keychain.has(s.topic)||(i=!0),i&&r.push(s.topic)}),this.client.proposal.getAll().forEach(s=>{mr(s.expiryTimestamp)&&n.push(s.id)}),await Promise.all([...r.map(s=>this.deleteSession({topic:s})),...n.map(s=>this.deleteProposal(s))])},this.onProviderMessageEvent=async r=>{!this.initialized||this.relayMessageCache.length>0?this.relayMessageCache.push(r):await this.onRelayMessage(r)},this.onRelayEventRequest=async r=>{this.requestQueue.queue.push(r),await this.processRequestsQueue()},this.processRequestsQueue=async()=>{if(this.requestQueue.state===br.active){this.client.logger.info("Request queue already active, skipping...");return}for(this.client.logger.info(`Request queue starting with ${this.requestQueue.queue.length} requests`);this.requestQueue.queue.length>0;){this.requestQueue.state=br.active;let r=this.requestQueue.queue.shift();if(r)try{await this.processRequest(r)}catch(n){this.client.logger.warn(n)}}this.requestQueue.state=br.idle},this.processRequest=async r=>{let{topic:n,payload:s,attestation:i,transportType:o,encryptedId:a}=r,c=s.method;if(!this.shouldIgnorePairingRequest({topic:n,requestMethod:c}))switch(c){case"wc_sessionPropose":return await this.onSessionProposeRequest({topic:n,payload:s,attestation:i,encryptedId:a});case"wc_sessionSettle":return await this.onSessionSettleRequest(n,s);case"wc_sessionUpdate":return await this.onSessionUpdateRequest(n,s);case"wc_sessionExtend":return await this.onSessionExtendRequest(n,s);case"wc_sessionPing":return await this.onSessionPingRequest(n,s);case"wc_sessionDelete":return await this.onSessionDeleteRequest(n,s);case"wc_sessionRequest":return await this.onSessionRequest({topic:n,payload:s,attestation:i,encryptedId:a,transportType:o});case"wc_sessionEvent":return await this.onSessionEventRequest(n,s);case"wc_sessionAuthenticate":return await this.onSessionAuthenticateRequest({topic:n,payload:s,attestation:i,encryptedId:a,transportType:o});default:return this.client.logger.info(`Unsupported request method ${c}`)}},this.onRelayEventResponse=async r=>{let{topic:n,payload:s,transportType:i}=r,o=(await this.client.core.history.get(n,s.id)).request.method;switch(o){case"wc_sessionPropose":return this.onSessionProposeResponse(n,s,i);case"wc_sessionSettle":return this.onSessionSettleResponse(n,s);case"wc_sessionUpdate":return this.onSessionUpdateResponse(n,s);case"wc_sessionExtend":return this.onSessionExtendResponse(n,s);case"wc_sessionPing":return this.onSessionPingResponse(n,s);case"wc_sessionRequest":return this.onSessionRequestResponse(n,s);case"wc_sessionAuthenticate":return this.onSessionAuthenticateResponse(n,s);default:return this.client.logger.info(`Unsupported response method ${o}`)}},this.onRelayEventUnknownPayload=r=>{let{topic:n}=r,{message:s}=F("MISSING_OR_INVALID",`Decoded payload on topic ${n} is not identifiable as a JSON-RPC request or a response.`);throw new Error(s)},this.shouldIgnorePairingRequest=r=>{let{topic:n,requestMethod:s}=r,i=this.expectedPairingMethodMap.get(n);return!i||i.includes(s)?!1:!!(i.includes("wc_sessionAuthenticate")&&this.client.events.listenerCount("session_authenticate")>0)},this.onSessionProposeRequest=async r=>{let{topic:n,payload:s,attestation:i,encryptedId:o}=r,{params:a,id:c}=s;try{let u=this.client.core.eventClient.getEvent({topic:n});this.client.events.listenerCount("session_proposal")===0&&(console.warn("No listener for session_proposal event"),u?.setError(yr.proposal_listener_not_found)),this.isValidConnect({...s.params});let f=a.expiryTimestamp||_e($e.wc_sessionPropose.req.ttl),l={id:c,pairingTopic:n,expiryTimestamp:f,attestation:i,encryptedId:o,...a};await this.setProposal(c,l);let h=await this.getVerifyContext({attestationId:i,hash:yt(JSON.stringify(s)),encryptedId:o,metadata:l.proposer.metadata});u?.addTrace(Zt.emit_session_proposal),this.client.events.emit("session_proposal",{id:c,params:l,verifyContext:h})}catch(u){await this.sendError({id:c,topic:n,error:u,rpcOpts:$e.wc_sessionPropose.autoReject}),this.client.logger.error(u)}},this.onSessionProposeResponse=async(r,n,s)=>{let{id:i}=n;if(At(n)){let{result:o}=n;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",result:o});let a=this.client.proposal.get(i);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",proposal:a});let c=a.proposer.publicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",selfPublicKey:c});let u=o.responderPublicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",peerPublicKey:u});let f=await this.client.core.crypto.generateSharedKey(c,u);this.pendingSessions.set(i,{sessionTopic:f,pairingTopic:r,proposalId:i,publicKey:c});let l=await this.client.core.relayer.subscribe(f,{transportType:s});this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:l}),await this.client.core.pairing.activate({topic:r})}else if(nt(n)){await this.deleteProposal(i);let o=ae("session_connect",i);if(this.events.listenerCount(o)===0)throw new Error(`emitting ${o} without any listeners, 954`);this.events.emit(o,{error:n.error})}},this.onSessionSettleRequest=async(r,n)=>{let{id:s,params:i}=n;try{this.isValidSessionSettleRequest(i);let{relay:o,controller:a,expiry:c,namespaces:u,sessionProperties:f,scopedProperties:l,sessionConfig:h,proposalRequestsResponses:d}=n.params,p=[...this.pendingSessions.values()].find(b=>b.sessionTopic===r);if(!p)return this.client.logger.error(`Pending session not found for topic ${r}`);let g=this.client.proposal.get(p.proposalId),m={topic:r,relay:o,expiry:c,namespaces:u,acknowledged:!0,pairingTopic:p.pairingTopic,requiredNamespaces:g.requiredNamespaces,optionalNamespaces:g.optionalNamespaces,controller:a.publicKey,self:{publicKey:p.publicKey,metadata:this.client.metadata},peer:{publicKey:a.publicKey,metadata:a.metadata},...f&&{sessionProperties:f},...l&&{scopedProperties:l},...h&&{sessionConfig:h},transportType:fe.relay,authentication:d?.authentication,walletPayResult:d?.walletPay};await this.client.session.set(m.topic,m),await this.setExpiry(m.topic,m.expiry),await this.client.core.pairing.updateMetadata({topic:p.pairingTopic,metadata:m.peer.metadata}),this.pendingSessions.delete(p.proposalId),this.deleteProposal(p.proposalId,!1),this.cleanupDuplicatePairings(m),await this.sendResult({id:n.id,topic:r,throwOnFailedPublish:!0,result:!0}),this.client.events.emit("session_connect",{session:m}),this.events.emit(ae("session_connect",p.proposalId),{session:m})}catch(o){await this.sendError({id:s,topic:r,error:o}),this.client.logger.error(o)}},this.onSessionSettleResponse=async(r,n)=>{let{id:s}=n;At(n)?(await this.client.session.update(r,{acknowledged:!0}),this.events.emit(ae("session_approve",s),{})):nt(n)&&(await this.deleteSession({topic:r,emitEvent:!1}),this.events.emit(ae("session_approve",s),{error:n.error}))},this.onSessionUpdateRequest=async(r,n)=>{let{params:s,id:i}=n;try{let o=`${r}_session_update`,a=Tn.get(o);if(a&&this.isRequestOutOfSync(a,i)){this.client.logger.warn(`Discarding out of sync request - ${i}`),this.sendError({id:i,topic:r,error:pe("INVALID_UPDATE_REQUEST")});return}this.isValidUpdate({topic:r,...s});try{Tn.set(o,i),await this.client.session.update(r,{namespaces:s.namespaces}),await this.sendResult({id:i,topic:r,result:!0})}catch(c){throw Tn.delete(o),c}this.client.events.emit("session_update",{id:i,topic:r,params:s})}catch(o){await this.sendError({id:i,topic:r,error:o}),this.client.logger.error(o)}},this.isRequestOutOfSync=(r,n)=>n.toString().slice(0,-3)<r.toString().slice(0,-3),this.onSessionUpdateResponse=(r,n)=>{let{id:s}=n,i=ae("session_update",s);if(this.events.listenerCount(i)===0)throw new Error(`emitting ${i} without any listeners`);At(n)?this.events.emit(ae("session_update",s),{}):nt(n)&&this.events.emit(ae("session_update",s),{error:n.error})},this.onSessionExtendRequest=async(r,n)=>{let{id:s}=n;try{this.isValidExtend({topic:r}),await this.setExpiry(r,_e(Ri)),await this.sendResult({id:s,topic:r,result:!0}),this.client.events.emit("session_extend",{id:s,topic:r})}catch(i){await this.sendError({id:s,topic:r,error:i}),this.client.logger.error(i)}},this.onSessionExtendResponse=(r,n)=>{let{id:s}=n,i=ae("session_extend",s);if(this.events.listenerCount(i)===0)throw new Error(`emitting ${i} without any listeners`);At(n)?this.events.emit(ae("session_extend",s),{}):nt(n)&&this.events.emit(ae("session_extend",s),{error:n.error})},this.onSessionPingRequest=async(r,n)=>{let{id:s}=n;try{this.isValidPing({topic:r}),await this.sendResult({id:s,topic:r,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_ping",{id:s,topic:r})}catch(i){await this.sendError({id:s,topic:r,error:i}),this.client.logger.error(i)}},this.onSessionPingResponse=(r,n)=>{let{id:s}=n,i=ae("session_ping",s);setTimeout(()=>{if(this.events.listenerCount(i)===0)throw new Error(`emitting ${i} without any listeners 2176`);At(n)?this.events.emit(ae("session_ping",s),{}):nt(n)&&this.events.emit(ae("session_ping",s),{error:n.error})},500)},this.onSessionDeleteRequest=async(r,n)=>{let{id:s}=n;try{await this.isValidDisconnect({topic:r,reason:n.params}),this.cleanupPendingSentRequestsForTopic({topic:r,error:pe("USER_DISCONNECTED")}),await this.deleteSession({topic:r,id:s})}catch(i){this.client.logger.error(i)}},this.onSessionRequest=async r=>{let{topic:n,payload:s,attestation:i,encryptedId:o,transportType:a}=r,{id:c,params:u}=s;try{await this.isValidRequest({topic:n,...u});let f=this.client.session.get(n),l=await this.getVerifyContext({attestationId:i,hash:yt(JSON.stringify(Bt("wc_sessionRequest",u,c))),encryptedId:o,metadata:f.peer.metadata,transportType:a}),h={id:c,topic:n,params:u,verifyContext:l};await this.setPendingSessionRequest(h),a===fe.link_mode&&f.peer.metadata.redirect?.universal&&this.client.core.addLinkModeSupportedApp(f.peer.metadata.redirect?.universal),this.client.signConfig?.disableRequestQueue?this.emitSessionRequest(h):(this.addSessionRequestToSessionRequestQueue(h),this.processSessionRequestQueue())}catch(f){await this.sendError({id:c,topic:n,error:f}),this.client.logger.error(f)}},this.onSessionRequestResponse=(r,n)=>{let{id:s}=n,i=ae("session_request",s);if(this.events.listenerCount(i)===0)throw new Error(`emitting ${i} without any listeners`);At(n)?this.events.emit(ae("session_request",s),{result:n.result}):nt(n)&&this.events.emit(ae("session_request",s),{error:n.error})},this.onSessionEventRequest=async(r,n)=>{let{id:s,params:i}=n;try{let o=`${r}_session_event_${i.event.name}`,a=Tn.get(o);if(a&&this.isRequestOutOfSync(a,s)){this.client.logger.info(`Discarding out of sync request - ${s}`);return}this.isValidEmit({topic:r,...i}),this.client.events.emit("session_event",{id:s,topic:r,params:i}),Tn.set(o,s)}catch(o){await this.sendError({id:s,topic:r,error:o}),this.client.logger.error(o)}},this.onSessionAuthenticateResponse=(r,n)=>{let{id:s}=n;this.client.logger.trace({type:"method",method:"onSessionAuthenticateResponse",topic:r,payload:n}),At(n)?this.events.emit(ae("session_request",s),{result:n.result}):nt(n)&&this.events.emit(ae("session_request",s),{error:n.error})},this.onSessionAuthenticateRequest=async r=>{let{topic:n,payload:s,attestation:i,encryptedId:o,transportType:a}=r;try{let{requester:c,authPayload:u,expiryTimestamp:f}=s.params,l=await this.getVerifyContext({attestationId:i,hash:yt(JSON.stringify(s)),encryptedId:o,metadata:c.metadata,transportType:a}),h={requester:c,pairingTopic:n,id:s.id,authPayload:u,verifyContext:l,expiryTimestamp:f};await this.setAuthRequest(s.id,{request:h,pairingTopic:n,transportType:a}),a===fe.link_mode&&c.metadata.redirect?.universal&&this.client.core.addLinkModeSupportedApp(c.metadata.redirect.universal),this.client.events.emit("session_authenticate",{topic:n,params:s.params,id:s.id,verifyContext:l})}catch(c){this.client.logger.error(c);let u=s.params.requester.publicKey,f=await this.client.core.crypto.generateKeyPair(),l=this.getAppLinkIfEnabled(s.params.requester.metadata,a),h={type:Jt,receiverPublicKey:u,senderPublicKey:f};await this.sendError({id:s.id,topic:n,error:c,encodeOpts:h,rpcOpts:$e.wc_sessionAuthenticate.autoReject,appLink:l})}},this.addSessionRequestToSessionRequestQueue=r=>{this.sessionRequestQueue.queue.push(r)},this.cleanupAfterResponse=r=>{this.deletePendingSessionRequest(r.response.id,{message:"fulfilled",code:0}),setTimeout(()=>{this.sessionRequestQueue.state=br.idle,this.processSessionRequestQueue()},(0,re.toMiliseconds)(this.requestQueueDelay))},this.cleanupPendingSentRequestsForTopic=({topic:r,error:n})=>{let s=this.client.core.history.pending;s.length>0&&s.filter(i=>i.topic===r&&i.request.method==="wc_sessionRequest").forEach(i=>{this.events.emit(ae("session_request",i.request.id),{error:n})})},this.processSessionRequestQueue=()=>{if(this.sessionRequestQueue.state===br.active){this.client.logger.info("session request queue is already active.");return}let r=this.sessionRequestQueue.queue[0];if(!r){this.client.logger.info("session request queue is empty.");return}try{this.emitSessionRequest(r)}catch(n){this.client.logger.error(n)}},this.emitSessionRequest=r=>{if(this.emittedSessionRequests.has(r.id)){this.client.logger.warn({id:r.id},`Skipping emitting \`session_request\` event for duplicate request. id: ${r.id}`);return}this.sessionRequestQueue.state=br.active,this.emittedSessionRequests.add(r.id),this.client.events.emit("session_request",r)},this.cleanupInProgress=!1,this.cleanupOrphanedSubscriptions=async()=>{let r=this.client.core.relayer.subscriber.topics;if(r.length===0)return;let n=new Set(this.client.session.keys),s=new Set(this.client.core.pairing.pairings.keys),i=new Set([...this.pendingSessions.values()].map(a=>a.sessionTopic)),o;if(this.client.auth.authKeys.keys.includes(Ln)){let{responseTopic:a}=this.client.auth.authKeys.get(Ln);o=a}for(let a of r)if(!n.has(a)&&!s.has(a)&&!i.has(a)&&a!==o){this.client.logger.info(`Cleaning up orphaned subscriber topic: ${a}`);try{await this.client.core.relayer.subscriber.unsubscribe(a)}catch(c){this.client.logger.warn(c,`Failed to clean up orphaned subscription: ${a}`)}}},this.onPairingCreated=r=>{if(r.methods&&this.expectedPairingMethodMap.set(r.topic,r.methods),r.active)return;let n=this.client.proposal.getAll().find(s=>s.pairingTopic===r.topic);n&&this.onSessionProposeRequest({topic:r.topic,payload:Bt("wc_sessionPropose",{...n,requiredNamespaces:n.requiredNamespaces,optionalNamespaces:n.optionalNamespaces,relays:n.relays,proposer:n.proposer,sessionProperties:n.sessionProperties,scopedProperties:n.scopedProperties},n.id),attestation:n.attestation,encryptedId:n.encryptedId})},this.isValidConnect=async r=>{if(!rt(r)){let{message:u}=F("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(r)}`);throw new Error(u)}let{pairingTopic:n,requiredNamespaces:s,optionalNamespaces:i,sessionProperties:o,scopedProperties:a,relays:c}=r;if(ve(n)||await this.isValidPairingTopic(n),!Sb(c,!0)){let{message:u}=F("MISSING_OR_INVALID",`connect() relays: ${c}`);throw new Error(u)}if(s&&!ve(s)&&Ii(s)!==0){let u="requiredNamespaces are deprecated and are automatically assigned to optionalNamespaces";["fatal","error","silent"].includes(this.client.logger.level)?console.warn(u):this.client.logger.warn(u),this.validateNamespaces(s,"requiredNamespaces")}if(i&&!ve(i)&&Ii(i)!==0&&this.validateNamespaces(i,"optionalNamespaces"),o&&!ve(o)&&this.validateSessionProps(o,"sessionProperties"),a&&!ve(a)){this.validateSessionProps(a,"scopedProperties");let u=Object.keys(s||{}).concat(Object.keys(i||{}));if(!Object.keys(a).every(f=>u.includes(f.split(":")[0])))throw new Error(`Scoped properties must be a subset of required/optional namespaces, received: ${JSON.stringify(a)}, required/optional namespaces: ${JSON.stringify(u)}`)}},this.validateNamespaces=(r,n)=>{let s=_b(r,"connect()",n);if(s)throw new Error(s.message)},this.isValidApprove=async r=>{if(!rt(r))throw new Error(F("MISSING_OR_INVALID",`approve() params: ${r}`).message);let{id:n,namespaces:s,relayProtocol:i,sessionProperties:o,scopedProperties:a}=r;this.checkRecentlyDeleted(n),await this.isValidProposalId(n);let c=this.client.proposal.get(n),u=wu(s,"approve()");if(u)throw new Error(u.message);let f=Hd(c.requiredNamespaces,s,"approve()");if(f)throw new Error(f.message);if(!me(i,!0)){let{message:l}=F("MISSING_OR_INVALID",`approve() relayProtocol: ${i}`);throw new Error(l)}if(o&&!ve(o)&&this.validateSessionProps(o,"sessionProperties"),a&&!ve(a)){this.validateSessionProps(a,"scopedProperties");let l=new Set(Object.keys(s));if(!Object.keys(a).every(h=>l.has(h.split(":")[0])))throw new Error(`Scoped properties must be a subset of approved namespaces, received: ${JSON.stringify(a)}, approved namespaces: ${Array.from(l).join(", ")}`)}},this.isValidReject=async r=>{if(!rt(r)){let{message:i}=F("MISSING_OR_INVALID",`reject() params: ${r}`);throw new Error(i)}let{id:n,reason:s}=r;if(this.checkRecentlyDeleted(n),await this.isValidProposalId(n),!Bb(s)){let{message:i}=F("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(s)}`);throw new Error(i)}},this.isValidSessionSettleRequest=r=>{if(!rt(r)){let{message:u}=F("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${r}`);throw new Error(u)}let{relay:n,controller:s,namespaces:i,expiry:o}=r;if(!qd(n)){let{message:u}=F("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(u)}let a=Eb(s,"onSessionSettleRequest()");if(a)throw new Error(a.message);let c=wu(i,"onSessionSettleRequest()");if(c)throw new Error(c.message);if(mr(o)){let{message:u}=F("EXPIRED","onSessionSettleRequest()");throw new Error(u)}},this.isValidUpdate=async r=>{if(!rt(r)){let{message:c}=F("MISSING_OR_INVALID",`update() params: ${r}`);throw new Error(c)}let{topic:n,namespaces:s}=r;this.checkRecentlyDeleted(n),await this.isValidSessionTopic(n);let i=this.client.session.get(n),o=wu(s,"update()");if(o)throw new Error(o.message);let a=Hd(i.requiredNamespaces,s,"update()");if(a)throw new Error(a.message)},this.isValidExtend=async r=>{if(!rt(r)){let{message:s}=F("MISSING_OR_INVALID",`extend() params: ${r}`);throw new Error(s)}let{topic:n}=r;this.checkRecentlyDeleted(n),await this.isValidSessionTopic(n)},this.isValidRequest=async r=>{if(!rt(r)){let{message:c}=F("MISSING_OR_INVALID",`request() params: ${r}`);throw new Error(c)}let{topic:n,request:s,chainId:i,expiry:o}=r;this.checkRecentlyDeleted(n),await this.isValidSessionTopic(n);let{namespaces:a}=this.client.session.get(n);if(!Fd(a,i)){let{message:c}=F("MISSING_OR_INVALID",`request() chainId: ${i}`);throw new Error(c)}if(!Ab(s)){let{message:c}=F("MISSING_OR_INVALID",`request() ${JSON.stringify(s)}`);throw new Error(c)}if(!Db(a,i,s.method)){let{message:c}=F("MISSING_OR_INVALID",`request() method: ${s.method}`);throw new Error(c)}this.validateRequestExpiry(o)},this.isValidRespond=async r=>{if(!rt(r)){let{message:o}=F("MISSING_OR_INVALID",`respond() params: ${r}`);throw new Error(o)}let{topic:n,response:s}=r;try{await this.isValidSessionTopic(n)}catch(o){throw r?.response?.id&&this.cleanupAfterResponse(r),o}if(!Tb(s)){let{message:o}=F("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(s)}`);throw new Error(o)}let i=this.client.pendingRequest.get(s.id);if(i.topic!==n){let{message:o}=F("MISMATCHED_TOPIC",`Request response topic mismatch. reqId: ${s.id}, expected topic: ${i.topic}, received topic: ${n}`);throw new Error(o)}},this.isValidPing=async r=>{if(!rt(r)){let{message:s}=F("MISSING_OR_INVALID",`ping() params: ${r}`);throw new Error(s)}let{topic:n}=r;await this.isValidSessionOrPairingTopic(n)},this.isValidEmit=async r=>{if(!rt(r)){let{message:a}=F("MISSING_OR_INVALID",`emit() params: ${r}`);throw new Error(a)}let{topic:n,event:s,chainId:i}=r;await this.isValidSessionTopic(n);let{namespaces:o}=this.client.session.get(n);if(!Fd(o,i)){let{message:a}=F("MISSING_OR_INVALID",`emit() chainId: ${i}`);throw new Error(a)}if(!Rb(s)){let{message:a}=F("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(s)}`);throw new Error(a)}if(!Ob(o,i,s.name)){let{message:a}=F("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(s)}`);throw new Error(a)}},this.isValidDisconnect=async r=>{if(!rt(r)){let{message:s}=F("MISSING_OR_INVALID",`disconnect() params: ${r}`);throw new Error(s)}let{topic:n}=r;await this.isValidSessionOrPairingTopic(n)},this.isValidAuthenticate=r=>{let{chains:n,uri:s,domain:i,nonce:o}=r;if(!Array.isArray(n)||n.length===0)throw new Error("chains is required and must be a non-empty array");if(!me(s,!1))throw new Error("uri is required parameter");if(!me(i,!1))throw new Error("domain is required parameter");if(!me(o,!1))throw new Error("nonce is required parameter");if([...new Set(n.map(c=>Ro(c).namespace))].length>1)throw new Error("Multi-namespace requests are not supported. Please request single namespace only.");let{namespace:a}=Ro(n[0]);if(a!=="eip155")throw new Error("Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.")},this.getVerifyContext=async r=>{let{attestationId:n,hash:s,encryptedId:i,metadata:o,transportType:a}=r,c={verified:{verifyUrl:o.verifyUrl||Ai,validation:"UNKNOWN",origin:o.url||""}};try{if(a===fe.link_mode){let f=this.getAppLinkIfEnabled(o,a);return c.verified.validation=f&&new URL(f).origin===new URL(o.url).origin?"VALID":"INVALID",c}let u=await this.client.core.verify.resolve({attestationId:n,hash:s,encryptedId:i,verifyUrl:o.verifyUrl});u&&(c.verified.origin=u.origin,c.verified.isScam=u.isScam,c.verified.validation=u.origin===new URL(o.url).origin?"VALID":"INVALID")}catch(u){this.client.logger.warn(u)}return this.client.logger.debug(`Verify context: ${JSON.stringify(c)}`),c},this.validateSessionProps=(r,n)=>{Object.values(r).forEach((s,i)=>{if(s==null){let{message:o}=F("MISSING_OR_INVALID",`${n} must contain an existing value for each key. Received: ${s} for key ${Object.keys(r)[i]}`);throw new Error(o)}})},this.getPendingAuthRequest=r=>{let n=this.client.auth.requests.get(r);return typeof n=="object"?n:void 0},this.addToRecentlyDeleted=(r,n)=>{if(this.recentlyDeletedMap.set(r,n),this.recentlyDeletedMap.size>=this.recentlyDeletedLimit){let s=0,i=this.recentlyDeletedLimit/2;for(let o of this.recentlyDeletedMap.keys()){if(s++>=i)break;this.recentlyDeletedMap.delete(o)}}},this.checkRecentlyDeleted=r=>{let n=this.recentlyDeletedMap.get(r);if(n){let{message:s}=F("MISSING_OR_INVALID",`Record was recently deleted - ${n}: ${r}`);throw new Error(s)}},this.isLinkModeEnabled=(r,n)=>!r||n!==fe.link_mode?!1:this.client.metadata?.redirect?.linkMode===!0&&this.client.metadata?.redirect?.universal!==void 0&&this.client.metadata?.redirect?.universal!==""&&r?.redirect?.universal!==void 0&&r?.redirect?.universal!==""&&r?.redirect?.linkMode===!0&&this.client.core.linkModeSupportedApps.includes(r.redirect.universal)&&typeof globalThis?.Linking<"u",this.getAppLinkIfEnabled=(r,n)=>this.isLinkModeEnabled(r,n)?r?.redirect?.universal:void 0,this.handleLinkModeMessage=({url:r})=>{if(!r||!r.includes("wc_ev")||!r.includes("topic"))return;let n=vd(r,"topic")||"",s=decodeURIComponent(vd(r,"wc_ev")||""),i=this.client.session.keys.includes(n);i&&this.client.session.update(n,{transportType:fe.link_mode}),this.client.core.dispatchEnvelope({topic:n,message:s,sessionExists:i})},this.registerLinkModeListeners=async()=>{if(Co()||Xr()&&this.client.metadata.redirect?.linkMode){let r=globalThis?.Linking;if(typeof r<"u"){r.addEventListener("url",this.handleLinkModeMessage,this.client.name);let n=await r.getInitialURL();n&&setTimeout(()=>{this.handleLinkModeMessage({url:n})},50)}}},this.getTVFApproveParams=r=>{try{let n=Ld(r.namespaces),s=db(r.namespaces),i=pb(r.namespaces),o=r.sessionProperties,a=r.scopedProperties;return{approvedChains:n,approvedMethods:s,approvedEvents:i,sessionProperties:o,scopedProperties:a}}catch(n){return this.client.logger.warn(n,"Error getting TVF approve params"),{}}},this.getTVFParams=(r,n,s)=>{if(!n.request?.method)return{};let i={correlationId:r,rpcMethods:[n.request.method],chainId:n.chainId};try{let o=this.extractTxHashesFromResult(n.request,s);i.txHashes=o,i.contractAddresses=this.isValidContractData(n.request.params)?[n.request.params?.[0]?.to]:[]}catch(o){this.client.logger.warn(o,"Error getting TVF params")}return i},this.isValidContractData=r=>{if(!r)return!1;try{let n=r?.data||r?.[0]?.data;if(!n.startsWith("0x"))return!1;let s=n.slice(2);return/^[0-9a-fA-F]*$/.test(s)?s.length%2===0:!1}catch{}return!1},this.extractTxHashesFromResult=(r,n)=>{try{if(!n)return[];let s=r.method,i=nR[s];if(s==="sui_signTransaction")return[Wx(n.transactionBytes)];if(s==="near_signTransaction")return[Sd(n)];if(s==="near_signTransactions")return n.map(a=>Sd(a));if(s==="xrpl_signTransactionFor"||s==="xrpl_signTransaction")return[n.tx_json?.hash];if(s==="polkadot_signTransaction")return[Ub({transaction:r.params.transactionPayload,signature:n.signature})];if(s==="algo_signTxn")return Is(n)?n.map(a=>Id(a)):[Id(n)];if(s==="cosmos_signDirect")return[Gx(n)];if(s==="wallet_sendCalls")return Yx(n);if(typeof n=="string")return[n];let o=n[i.key];if(Is(o))return s==="solana_signAllTransactions"?o.map(a=>Kx(a)):o;if(typeof o=="string")return[o]}catch(s){this.client.logger.warn(s,"Error extracting tx hashes from result")}return[]}}async processPendingMessageEvents(){try{let e=this.client.session.keys,r=this.client.core.relayer.messages.getWithoutAck(e);for(let[n,s]of Object.entries(r))for(let i of s)try{await this.onProviderMessageEvent({topic:n,message:i,publishedAt:Date.now()})}catch{this.client.logger.warn(`Error processing pending message event for topic: ${n}, message: ${i}`)}}catch(e){this.client.logger.warn(e,"processPendingMessageEvents failed")}}isInitialized(){if(!this.initialized){let{message:e}=F("NOT_INITIALIZED",this.name);throw new Error(e)}}async confirmOnlineStateOrThrow(){await this.client.core.relayer.confirmOnlineStateOrThrow()}registerRelayerEvents(){this.client.core.relayer.on(ye.message,e=>{this.onProviderMessageEvent(e)})}async onRelayMessage(e){let{topic:r,message:n,attestation:s,transportType:i}=e,{publicKey:o}=this.client.auth.authKeys.keys.includes(Ln)?this.client.auth.authKeys.get(Ln):{publicKey:void 0};try{let a=await this.client.core.crypto.decode(r,n,{receiverPublicKey:o,encoding:i===fe.link_mode?Qr:Oe});Bi(a)?(this.client.core.history.set(r,a),await this.onRelayEventRequest({topic:r,payload:a,attestation:s,transportType:i,encryptedId:yt(n)})):Cn(a)?(await this.client.core.history.resolve(a),await this.onRelayEventResponse({topic:r,payload:a,transportType:i}),this.client.core.history.delete(r,a.id)):(this.client.logger.error(`onRelayMessage() -> unknown payload: ${JSON.stringify(a)}`),await this.onRelayEventUnknownPayload({topic:r,payload:a,transportType:i})),await this.client.core.relayer.messages.ack(r,n)}catch(a){this.client.logger.error(`onRelayMessage() -> failed to process an inbound message: ${n}`),this.client.logger.error(a)}}registerExpirerEvents(){this.client.core.expirer.on(Rt.expired,async e=>{let{topic:r,id:n}=pu(e.target);if(n&&this.client.pendingRequest.keys.includes(n))return await this.deletePendingSessionRequest(n,F("EXPIRED"),!0);if(n&&this.client.auth.requests.keys.includes(n))return await this.deletePendingAuthRequest(n,F("EXPIRED"),!0);r?this.client.session.keys.includes(r)&&(await this.deleteSession({topic:r,expirerHasDeleted:!0}),this.client.events.emit("session_expire",{topic:r})):n&&(await this.deleteProposal(n,!0),this.client.events.emit("proposal_expire",{id:n}))})}registerSubscriptionCleanup(){this.client.core.heartbeat.on("heartbeat_pulse",async()=>{if(!this.cleanupInProgress){this.cleanupInProgress=!0;try{await this.cleanupOrphanedSubscriptions()}catch(e){this.client.logger.warn(e)}finally{this.cleanupInProgress=!1}}})}registerPairingEvents(){this.client.core.pairing.events.on(Nn.create,e=>this.onPairingCreated(e)),this.client.core.pairing.events.on(Nn.delete,e=>{this.addToRecentlyDeleted(e.topic,"pairing")})}isValidPairingTopic(e){if(!me(e,!1)){let{message:r}=F("MISSING_OR_INVALID",`pairing topic should be a string: ${e}`);throw new Error(r)}if(!this.client.core.pairing.pairings.keys.includes(e)){let{message:r}=F("NO_MATCHING_KEY",`pairing topic doesn't exist: ${e}`);throw new Error(r)}if(mr(this.client.core.pairing.pairings.get(e).expiry)){let{message:r}=F("EXPIRED",`pairing topic: ${e}`);throw new Error(r)}}async isValidSessionTopic(e){if(!me(e,!1)){let{message:r}=F("MISSING_OR_INVALID",`session topic should be a string: ${e}`);throw new Error(r)}if(this.checkRecentlyDeleted(e),!this.client.session.keys.includes(e)){let{message:r}=F("NO_MATCHING_KEY",`session topic doesn't exist: ${e}`);throw new Error(r)}if(mr(this.client.session.get(e).expiry)){await this.deleteSession({topic:e});let{message:r}=F("EXPIRED",`session topic: ${e}`);throw new Error(r)}if(!this.client.core.crypto.keychain.has(e)){let{message:r}=F("MISSING_OR_INVALID",`session topic does not exist in keychain: ${e}`);throw await this.deleteSession({topic:e}),new Error(r)}}async isValidSessionOrPairingTopic(e){if(this.checkRecentlyDeleted(e),this.client.session.keys.includes(e))await this.isValidSessionTopic(e);else if(this.client.core.pairing.pairings.keys.includes(e))this.isValidPairingTopic(e);else if(me(e,!1)){let{message:r}=F("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${e}`);throw new Error(r)}else{let{message:r}=F("MISSING_OR_INVALID",`session or pairing topic should be a string: ${e}`);throw new Error(r)}}async isValidProposalId(e){if(!Ib(e)){let{message:r}=F("MISSING_OR_INVALID",`proposal id should be a number: ${e}`);throw new Error(r)}if(!this.client.proposal.keys.includes(e)){let{message:r}=F("NO_MATCHING_KEY",`proposal id doesn't exist: ${e}`);throw new Error(r)}if(mr(this.client.proposal.get(e).expiryTimestamp)){await this.deleteProposal(e);let{message:r}=F("EXPIRED",`proposal id: ${e}`);throw new Error(r)}}validateRequestExpiry(e){if(e&&!Cb(e,yp)){let{message:r}=F("MISSING_OR_INVALID",`request() expiry: ${e}. Expiry must be a number (in seconds) between ${yp.min} and ${yp.max}`);throw new Error(r)}}},xp=class extends xr{constructor(e,r){super(e,r,eR,Bp),this.core=e,this.logger=r}},bp=class extends xr{constructor(e,r){super(e,r,tR,Bp),this.core=e,this.logger=r}},Ep=class extends xr{constructor(e,r){super(e,r,sR,Bp,n=>n.id),this.core=e,this.logger=r}},vp=class extends xr{constructor(e,r){super(e,r,cR,Lu,()=>Ln),this.core=e,this.logger=r}},_p=class extends xr{constructor(e,r){super(e,r,uR,Lu),this.core=e,this.logger=r}},Sp=class extends xr{constructor(e,r){super(e,r,lR,Lu,n=>n.id),this.core=e,this.logger=r}},Ip=class{constructor(e,r){this.core=e,this.logger=r,this.authKeys=new vp(this.core,this.logger),this.pairingTopics=new _p(this.core,this.logger),this.requests=new Sp(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}},fR=class $2 extends Pa{constructor(e){super(e),this.protocol=H2,this.version=z2,this.name=mp.name,this.events=new Uu.EventEmitter,this.on=(n,s)=>this.events.on(n,s),this.once=(n,s)=>this.events.once(n,s),this.off=(n,s)=>this.events.off(n,s),this.removeListener=(n,s)=>this.events.removeListener(n,s),this.removeAllListeners=n=>this.events.removeAllListeners(n),this.connect=async n=>{try{return await this.engine.connect(n)}catch(s){throw this.logger.error(s.message),s}},this.pair=async n=>{try{return await this.engine.pair(n)}catch(s){throw this.logger.error(s.message),s}},this.approve=async n=>{try{return await this.engine.approve(n)}catch(s){throw this.logger.error(s.message),s}},this.reject=async n=>{try{return await this.engine.reject(n)}catch(s){throw this.logger.error(s.message),s}},this.update=async n=>{try{return await this.engine.update(n)}catch(s){throw this.logger.error(s.message),s}},this.extend=async n=>{try{return await this.engine.extend(n)}catch(s){throw this.logger.error(s.message),s}},this.request=async n=>{try{return await this.engine.request(n)}catch(s){throw this.logger.error(s.message),s}},this.respond=async n=>{try{return await this.engine.respond(n)}catch(s){throw this.logger.error(s.message),s}},this.ping=async n=>{try{return await this.engine.ping(n)}catch(s){throw this.logger.error(s.message),s}},this.emit=async n=>{try{return await this.engine.emit(n)}catch(s){throw this.logger.error(s.message),s}},this.disconnect=async n=>{try{return await this.engine.disconnect(n)}catch(s){throw this.logger.error(s.message),s}},this.find=n=>{try{return this.engine.find(n)}catch(s){throw this.logger.error(s.message),s}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(n){throw this.logger.error(n.message),n}},this.authenticate=async(n,s)=>{try{return await this.engine.authenticate(n,s)}catch(i){throw this.logger.error(i.message),i}},this.formatAuthMessage=n=>{try{return this.engine.formatAuthMessage(n)}catch(s){throw this.logger.error(s.message),s}},this.approveSessionAuthenticate=async n=>{try{return await this.engine.approveSessionAuthenticate(n)}catch(s){throw this.logger.error(s.message),s}},this.rejectSessionAuthenticate=async n=>{try{return await this.engine.rejectSessionAuthenticate(n)}catch(s){throw this.logger.error(s.message),s}},this.name=e?.name||mp.name,this.metadata=Lx(e?.metadata),this.signConfig=e?.signConfig;let r=xu({logger:e?.logger||mp.logger,name:this.name});this.logger=r,this.core=e?.core||new M2(e),this.session=new bp(this.core,this.logger),this.proposal=new xp(this.core,this.logger),this.pendingRequest=new Ep(this.core,this.logger),this.engine=new wp(this),this.auth=new Ip(this.core,this.logger)}static async init(e){let r=new $2(e);return await r.initialize(),r}get context(){return We(this.logger)}get pairing(){return this.core.pairing.pairings}async initialize(){this.logger.trace("Initialized");try{await this.core.start(),await this.session.init(),await this.proposal.init(),await this.pendingRequest.init(),await this.auth.init(),await this.engine.init(),this.logger.info("SignClient Initialization Success")}catch(e){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(e.message),e}}};var j2=fR;var GE=Ie(jE(),1);typeof globalThis.Buffer>"u"&&(globalThis.Buffer=KE.Buffer);typeof globalThis.process>"u"&&(globalThis.process=WE.default);globalThis.process.version||(globalThis.process.version="v18.0.0");return Cs(iD);})();
|
|
/*! Bundled license information:
|
|
|
|
ieee754/index.js:
|
|
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
|
|
buffer/index.js:
|
|
(*!
|
|
* The buffer module from node.js, for the browser.
|
|
*
|
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
* @license MIT
|
|
*)
|
|
|
|
tslib/tslib.es6.js:
|
|
(*! *****************************************************************************
|
|
Copyright (c) Microsoft Corporation.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
PERFORMANCE OF THIS SOFTWARE.
|
|
***************************************************************************** *)
|
|
|
|
@walletconnect/relay-auth/dist/index.es.js:
|
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
|
|
@noble/hashes/esm/utils.js:
|
|
@noble/hashes/esm/utils.js:
|
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
|
|
@noble/curves/esm/abstract/utils.js:
|
|
@noble/curves/esm/abstract/modular.js:
|
|
@noble/curves/esm/abstract/curve.js:
|
|
@noble/curves/esm/abstract/weierstrass.js:
|
|
@noble/curves/esm/_shortw_utils.js:
|
|
@noble/curves/esm/secp256k1.js:
|
|
@noble/curves/esm/utils.js:
|
|
@noble/curves/esm/abstract/modular.js:
|
|
@noble/curves/esm/abstract/curve.js:
|
|
@noble/curves/esm/abstract/edwards.js:
|
|
@noble/curves/esm/abstract/montgomery.js:
|
|
@noble/curves/esm/ed25519.js:
|
|
@noble/curves/esm/abstract/weierstrass.js:
|
|
@noble/curves/esm/_shortw_utils.js:
|
|
@noble/curves/esm/nist.js:
|
|
@noble/curves/esm/p256.js:
|
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
|
|
@scure/base/lib/esm/index.js:
|
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
|
|
@noble/ciphers/esm/utils.js:
|
|
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
*/
|