nostr-crypto-utils 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/main.nostr-crypto-utils.min.js +2 -2
- package/dist/browser/main.nostr-crypto-utils.min.js.map +3 -3
- package/dist/browser/nip-46.nostr-crypto-utils.min.js +1 -1
- package/dist/browser/nip-46.nostr-crypto-utils.min.js.map +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/nips/nip-46.js +191 -1
- package/dist/cjs/nips/nip-46.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/nips/nip-46.js +187 -1
- package/dist/esm/nips/nip-46.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/nips/nip-46.d.ts +43 -1
- package/dist/types/nips/nip-46.d.ts.map +1 -1
- package/dist/types/types/nip46.d.ts +50 -0
- package/dist/types/types/nip46.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/nips/nip-46.test.ts +320 -1
- package/src/index.ts +4 -0
- package/src/nips/nip-46.ts +233 -1
- package/src/types/nip46.ts +56 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var NostrCryptoUtils=(()=>{var
|
|
2
|
-
`);for(let r=1;r<e.length;r++){let n=e[r].trim();if(/(^at\s+)?(createWrap|LOG|set\s*\(|asObject|Object\.apply|Function\.apply)/.test(n)||n.indexOf("browser.js")!==-1||n.indexOf("node:internal")!==-1||n.indexOf("node_modules")!==-1)continue;let o=n.match(/\((.*?):(\d+):(\d+)\)/);if(o||(o=n.match(/at\s+(.*?):(\d+):(\d+)/)),o){let i=o[1],s=o[2],c=o[3];return i+":"+s+":"+c}}return null}});var qr={};ve(qr,{default:()=>nc});var nc,$r=ps(()=>{nc={}});var ii=Ze(ot=>{"use strict";Object.defineProperty(ot,"__esModule",{value:!0});ot.bech32m=ot.bech32=void 0;var Yt="qpzry9x8gf2tvdw0s3jn54khce6mua7l",ni={};for(let t=0;t<Yt.length;t++){let e=Yt.charAt(t);ni[e]=t}function nt(t){let e=t>>25;return(t&33554431)<<5^-(e>>0&1)&996825010^-(e>>1&1)&642813549^-(e>>2&1)&513874426^-(e>>3&1)&1027748829^-(e>>4&1)&705979059}function ri(t){let e=1;for(let r=0;r<t.length;++r){let n=t.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+t+")";e=nt(e)^n>>5}e=nt(e);for(let r=0;r<t.length;++r){let n=t.charCodeAt(r);e=nt(e)^n&31}return e}function on(t,e,r,n){let o=0,i=0,s=(1<<r)-1,c=[];for(let a=0;a<t.length;++a)for(o=o<<e|t[a],i+=e;i>=r;)i-=r,c.push(o>>i&s);if(n)i>0&&c.push(o<<r-i&s);else{if(i>=e)return"Excess padding";if(o<<r-i&s)return"Non-zero padding"}return c}function lc(t){return on(t,8,5,!0)}function dc(t){let e=on(t,5,8,!1);if(Array.isArray(e))return e}function hc(t){let e=on(t,5,8,!1);if(Array.isArray(e))return e;throw new Error(e)}function oi(t){let e;t==="bech32"?e=1:e=734539939;function r(s,c,a){if(a=a||90,s.length+7+c.length>a)throw new TypeError("Exceeds length limit");s=s.toLowerCase();let f=ri(s);if(typeof f=="string")throw new Error(f);let l=s+"1";for(let u=0;u<c.length;++u){let p=c[u];if(p>>5!==0)throw new Error("Non 5-bit word");f=nt(f)^p,l+=Yt.charAt(p)}for(let u=0;u<6;++u)f=nt(f);f^=e;for(let u=0;u<6;++u){let p=f>>(5-u)*5&31;l+=Yt.charAt(p)}return l}function n(s,c){if(c=c||90,s.length<8)return s+" too short";if(s.length>c)return"Exceeds length limit";let a=s.toLowerCase(),f=s.toUpperCase();if(s!==a&&s!==f)return"Mixed-case string "+s;s=a;let l=s.lastIndexOf("1");if(l===-1)return"No separator character for "+s;if(l===0)return"Missing prefix for "+s;let u=s.slice(0,l),p=s.slice(l+1);if(p.length<6)return"Data too short";let h=ri(u);if(typeof h=="string")return h;let b=[];for(let x=0;x<p.length;++x){let w=p.charAt(x),A=ni[w];if(A===void 0)return"Unknown character "+w;h=nt(h)^A,!(x+6>=p.length)&&b.push(A)}return h!==e?"Invalid checksum for "+s:{prefix:u,words:b}}function o(s,c){let a=n(s,c);if(typeof a=="object")return a}function i(s,c){let a=n(s,c);if(typeof a=="object")return a;throw new Error(a)}return{decodeUnsafe:o,decode:i,encode:r,toWords:lc,fromWordsUnsafe:dc,fromWords:hc}}ot.bech32=oi("bech32");ot.bech32m=oi("bech32m")});var ai=Ze(Kt=>{"use strict";Kt.byteLength=yc;Kt.toByteArray=xc;Kt.fromByteArray=wc;var Ee=[],ge=[],pc=typeof Uint8Array<"u"?Uint8Array:Array,sn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(ze=0,si=sn.length;ze<si;++ze)Ee[ze]=sn[ze],ge[sn.charCodeAt(ze)]=ze;var ze,si;ge[45]=62;ge[95]=63;function ci(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 yc(t){var e=ci(t),r=e[0],n=e[1];return(r+n)*3/4-n}function gc(t,e,r){return(e+r)*3/4-r}function xc(t){var e,r=ci(t),n=r[0],o=r[1],i=new pc(gc(t,n,o)),s=0,c=o>0?n-4:n,a;for(a=0;a<c;a+=4)e=ge[t.charCodeAt(a)]<<18|ge[t.charCodeAt(a+1)]<<12|ge[t.charCodeAt(a+2)]<<6|ge[t.charCodeAt(a+3)],i[s++]=e>>16&255,i[s++]=e>>8&255,i[s++]=e&255;return o===2&&(e=ge[t.charCodeAt(a)]<<2|ge[t.charCodeAt(a+1)]>>4,i[s++]=e&255),o===1&&(e=ge[t.charCodeAt(a)]<<10|ge[t.charCodeAt(a+1)]<<4|ge[t.charCodeAt(a+2)]>>2,i[s++]=e>>8&255,i[s++]=e&255),i}function bc(t){return Ee[t>>18&63]+Ee[t>>12&63]+Ee[t>>6&63]+Ee[t&63]}function mc(t,e,r){for(var n,o=[],i=e;i<r;i+=3)n=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(t[i+2]&255),o.push(bc(n));return o.join("")}function wc(t){for(var e,r=t.length,n=r%3,o=[],i=16383,s=0,c=r-n;s<c;s+=i)o.push(mc(t,s,s+i>c?c:s+i));return n===1?(e=t[r-1],o.push(Ee[e>>2]+Ee[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(Ee[e>>10]+Ee[e>>4&63]+Ee[e<<2&63]+"=")),o.join("")}});var fi=Ze(cn=>{cn.read=function(t,e,r,n,o){var i,s,c=o*8-n-1,a=(1<<c)-1,f=a>>1,l=-7,u=r?o-1:0,p=r?-1:1,h=t[e+u];for(u+=p,i=h&(1<<-l)-1,h>>=-l,l+=c;l>0;i=i*256+t[e+u],u+=p,l-=8);for(s=i&(1<<-l)-1,i>>=-l,l+=n;l>0;s=s*256+t[e+u],u+=p,l-=8);if(i===0)i=1-f;else{if(i===a)return s?NaN:(h?-1:1)*(1/0);s=s+Math.pow(2,n),i=i-f}return(h?-1:1)*s*Math.pow(2,i-n)};cn.write=function(t,e,r,n,o,i){var s,c,a,f=i*8-o-1,l=(1<<f)-1,u=l>>1,p=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:i-1,b=n?1:-1,x=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(c=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-s))<1&&(s--,a*=2),s+u>=1?e+=p/a:e+=p*Math.pow(2,1-u),e*a>=2&&(s++,a/=2),s+u>=l?(c=0,s=l):s+u>=1?(c=(e*a-1)*Math.pow(2,o),s=s+u):(c=e*Math.pow(2,u-1)*Math.pow(2,o),s=0));o>=8;t[r+h]=c&255,h+=b,c/=256,o-=8);for(s=s<<o|c,f+=o;f>0;t[r+h]=s&255,h+=b,s/=256,f-=8);t[r+h-b]|=x*128}});var vi=Ze(at=>{"use strict";var an=ai(),st=fi(),ui=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;at.Buffer=g;at.SlowBuffer=vc;at.INSPECT_MAX_BYTES=50;var Xt=2147483647;at.kMaxLength=Xt;g.TYPED_ARRAY_SUPPORT=Ec();!g.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 Ec(){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(g.prototype,"parent",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.buffer}});Object.defineProperty(g.prototype,"offset",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.byteOffset}});function Le(t){if(t>Xt)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,g.prototype),e}function g(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 dn(t)}return pi(t,e,r)}g.poolSize=8192;function pi(t,e,r){if(typeof t=="string")return Ac(t,e);if(ArrayBuffer.isView(t))return Ic(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(Be(t,ArrayBuffer)||t&&Be(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Be(t,SharedArrayBuffer)||t&&Be(t.buffer,SharedArrayBuffer)))return un(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 g.from(n,e,r);let o=Sc(t);if(o)return o;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return g.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)}g.from=function(t,e,r){return pi(t,e,r)};Object.setPrototypeOf(g.prototype,Uint8Array.prototype);Object.setPrototypeOf(g,Uint8Array);function yi(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 Bc(t,e,r){return yi(t),t<=0?Le(t):e!==void 0?typeof r=="string"?Le(t).fill(e,r):Le(t).fill(e):Le(t)}g.alloc=function(t,e,r){return Bc(t,e,r)};function dn(t){return yi(t),Le(t<0?0:hn(t)|0)}g.allocUnsafe=function(t){return dn(t)};g.allocUnsafeSlow=function(t){return dn(t)};function Ac(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!g.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=gi(t,e)|0,n=Le(r),o=n.write(t,e);return o!==r&&(n=n.slice(0,o)),n}function fn(t){let e=t.length<0?0:hn(t.length)|0,r=Le(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Ic(t){if(Be(t,Uint8Array)){let e=new Uint8Array(t);return un(e.buffer,e.byteOffset,e.byteLength)}return fn(t)}function un(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,g.prototype),n}function Sc(t){if(g.isBuffer(t)){let e=hn(t.length)|0,r=Le(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||yn(t.length)?Le(0):fn(t);if(t.type==="Buffer"&&Array.isArray(t.data))return fn(t.data)}function hn(t){if(t>=Xt)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Xt.toString(16)+" bytes");return t|0}function vc(t){return+t!=t&&(t=0),g.alloc(+t)}g.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==g.prototype};g.compare=function(e,r){if(Be(e,Uint8Array)&&(e=g.from(e,e.offset,e.byteLength)),Be(r,Uint8Array)&&(r=g.from(r,r.offset,r.byteLength)),!g.isBuffer(e)||!g.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,o=r.length;for(let i=0,s=Math.min(n,o);i<s;++i)if(e[i]!==r[i]){n=e[i],o=r[i];break}return n<o?-1:o<n?1:0};g.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}};g.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return g.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let o=g.allocUnsafe(r),i=0;for(n=0;n<e.length;++n){let s=e[n];if(Be(s,Uint8Array))i+s.length>o.length?(g.isBuffer(s)||(s=g.from(s)),s.copy(o,i)):Uint8Array.prototype.set.call(o,s,i);else if(g.isBuffer(s))s.copy(o,i);else throw new TypeError('"list" argument must be an Array of Buffers');i+=s.length}return o};function gi(t,e){if(g.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Be(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 o=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return ln(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Si(t).length;default:if(o)return n?-1:ln(t).length;e=(""+e).toLowerCase(),o=!0}}g.byteLength=gi;function Rc(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 Dc(this,e,r);case"utf8":case"utf-8":return bi(this,e,r);case"ascii":return Oc(this,e,r);case"latin1":case"binary":return Pc(this,e,r);case"base64":return Lc(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Hc(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}g.prototype._isBuffer=!0;function Ge(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}g.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)Ge(this,r,r+1);return this};g.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)Ge(this,r,r+3),Ge(this,r+1,r+2);return this};g.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)Ge(this,r,r+7),Ge(this,r+1,r+6),Ge(this,r+2,r+5),Ge(this,r+3,r+4);return this};g.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?bi(this,0,e):Rc.apply(this,arguments)};g.prototype.toLocaleString=g.prototype.toString;g.prototype.equals=function(e){if(!g.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:g.compare(this,e)===0};g.prototype.inspect=function(){let e="",r=at.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};ui&&(g.prototype[ui]=g.prototype.inspect);g.prototype.compare=function(e,r,n,o,i){if(Be(e,Uint8Array)&&(e=g.from(e,e.offset,e.byteLength)),!g.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),o===void 0&&(o=0),i===void 0&&(i=this.length),r<0||n>e.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&r>=n)return 0;if(o>=i)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,o>>>=0,i>>>=0,this===e)return 0;let s=i-o,c=n-r,a=Math.min(s,c),f=this.slice(o,i),l=e.slice(r,n);for(let u=0;u<a;++u)if(f[u]!==l[u]){s=f[u],c=l[u];break}return s<c?-1:c<s?1:0};function xi(t,e,r,n,o){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,yn(r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0)if(o)r=0;else return-1;if(typeof e=="string"&&(e=g.from(e,n)),g.isBuffer(e))return e.length===0?-1:li(t,e,r,n,o);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):li(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function li(t,e,r,n,o){let i=1,s=t.length,c=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,s/=2,c/=2,r/=2}function a(l,u){return i===1?l[u]:l.readUInt16BE(u*i)}let f;if(o){let l=-1;for(f=r;f<s;f++)if(a(t,f)===a(e,l===-1?0:f-l)){if(l===-1&&(l=f),f-l+1===c)return l*i}else l!==-1&&(f-=f-l),l=-1}else for(r+c>s&&(r=s-c),f=r;f>=0;f--){let l=!0;for(let u=0;u<c;u++)if(a(t,f+u)!==a(e,u)){l=!1;break}if(l)return f}return-1}g.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};g.prototype.indexOf=function(e,r,n){return xi(this,e,r,n,!0)};g.prototype.lastIndexOf=function(e,r,n){return xi(this,e,r,n,!1)};function Uc(t,e,r,n){r=Number(r)||0;let o=t.length-r;n?(n=Number(n),n>o&&(n=o)):n=o;let i=e.length;n>i/2&&(n=i/2);let s;for(s=0;s<n;++s){let c=parseInt(e.substr(s*2,2),16);if(yn(c))return s;t[r+s]=c}return s}function kc(t,e,r,n){return Jt(ln(e,t.length-r),t,r,n)}function Tc(t,e,r,n){return Jt(qc(e),t,r,n)}function Nc(t,e,r,n){return Jt(Si(e),t,r,n)}function _c(t,e,r,n){return Jt($c(e,t.length-r),t,r,n)}g.prototype.write=function(e,r,n,o){if(r===void 0)o="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")o=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,o===void 0&&(o="utf8")):(o=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");o||(o="utf8");let s=!1;for(;;)switch(o){case"hex":return Uc(this,e,r,n);case"utf8":case"utf-8":return kc(this,e,r,n);case"ascii":case"latin1":case"binary":return Tc(this,e,r,n);case"base64":return Nc(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _c(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),s=!0}};g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Lc(t,e,r){return e===0&&r===t.length?an.fromByteArray(t):an.fromByteArray(t.slice(e,r))}function bi(t,e,r){r=Math.min(t.length,r);let n=[],o=e;for(;o<r;){let i=t[o],s=null,c=i>239?4:i>223?3:i>191?2:1;if(o+c<=r){let a,f,l,u;switch(c){case 1:i<128&&(s=i);break;case 2:a=t[o+1],(a&192)===128&&(u=(i&31)<<6|a&63,u>127&&(s=u));break;case 3:a=t[o+1],f=t[o+2],(a&192)===128&&(f&192)===128&&(u=(i&15)<<12|(a&63)<<6|f&63,u>2047&&(u<55296||u>57343)&&(s=u));break;case 4:a=t[o+1],f=t[o+2],l=t[o+3],(a&192)===128&&(f&192)===128&&(l&192)===128&&(u=(i&15)<<18|(a&63)<<12|(f&63)<<6|l&63,u>65535&&u<1114112&&(s=u))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),o+=c}return Cc(n)}var di=4096;function Cc(t){let e=t.length;if(e<=di)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=di));return r}function Oc(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(t[o]&127);return n}function Pc(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function Dc(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let o="";for(let i=e;i<r;++i)o+=jc[t[i]];return o}function Hc(t,e,r){let n=t.slice(e,r),o="";for(let i=0;i<n.length-1;i+=2)o+=String.fromCharCode(n[i]+n[i+1]*256);return o}g.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 o=this.subarray(e,r);return Object.setPrototypeOf(o,g.prototype),o};function se(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")}g.prototype.readUintLE=g.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||se(e,r,this.length);let o=this[e],i=1,s=0;for(;++s<r&&(i*=256);)o+=this[e+s]*i;return o};g.prototype.readUintBE=g.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||se(e,r,this.length);let o=this[e+--r],i=1;for(;r>0&&(i*=256);)o+=this[e+--r]*i;return o};g.prototype.readUint8=g.prototype.readUInt8=function(e,r){return e=e>>>0,r||se(e,1,this.length),this[e]};g.prototype.readUint16LE=g.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||se(e,2,this.length),this[e]|this[e+1]<<8};g.prototype.readUint16BE=g.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||se(e,2,this.length),this[e]<<8|this[e+1]};g.prototype.readUint32LE=g.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||se(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};g.prototype.readUint32BE=g.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||se(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};g.prototype.readBigUInt64LE=Fe(function(e){e=e>>>0,ct(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&At(e,this.length-8);let o=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(o)+(BigInt(i)<<BigInt(32))});g.prototype.readBigUInt64BE=Fe(function(e){e=e>>>0,ct(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&At(e,this.length-8);let o=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(o)<<BigInt(32))+BigInt(i)});g.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||se(e,r,this.length);let o=this[e],i=1,s=0;for(;++s<r&&(i*=256);)o+=this[e+s]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*r)),o};g.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||se(e,r,this.length);let o=r,i=1,s=this[e+--o];for(;o>0&&(i*=256);)s+=this[e+--o]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*r)),s};g.prototype.readInt8=function(e,r){return e=e>>>0,r||se(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};g.prototype.readInt16LE=function(e,r){e=e>>>0,r||se(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};g.prototype.readInt16BE=function(e,r){e=e>>>0,r||se(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};g.prototype.readInt32LE=function(e,r){return e=e>>>0,r||se(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};g.prototype.readInt32BE=function(e,r){return e=e>>>0,r||se(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};g.prototype.readBigInt64LE=Fe(function(e){e=e>>>0,ct(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&At(e,this.length-8);let o=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(o)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});g.prototype.readBigInt64BE=Fe(function(e){e=e>>>0,ct(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&At(e,this.length-8);let o=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(o)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});g.prototype.readFloatLE=function(e,r){return e=e>>>0,r||se(e,4,this.length),st.read(this,e,!0,23,4)};g.prototype.readFloatBE=function(e,r){return e=e>>>0,r||se(e,4,this.length),st.read(this,e,!1,23,4)};g.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||se(e,8,this.length),st.read(this,e,!0,52,8)};g.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||se(e,8,this.length),st.read(this,e,!1,52,8)};function he(t,e,r,n,o,i){if(!g.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}g.prototype.writeUintLE=g.prototype.writeUIntLE=function(e,r,n,o){if(e=+e,r=r>>>0,n=n>>>0,!o){let c=Math.pow(2,8*n)-1;he(this,e,r,n,c,0)}let i=1,s=0;for(this[r]=e&255;++s<n&&(i*=256);)this[r+s]=e/i&255;return r+n};g.prototype.writeUintBE=g.prototype.writeUIntBE=function(e,r,n,o){if(e=+e,r=r>>>0,n=n>>>0,!o){let c=Math.pow(2,8*n)-1;he(this,e,r,n,c,0)}let i=n-1,s=1;for(this[r+i]=e&255;--i>=0&&(s*=256);)this[r+i]=e/s&255;return r+n};g.prototype.writeUint8=g.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||he(this,e,r,1,255,0),this[r]=e&255,r+1};g.prototype.writeUint16LE=g.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||he(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};g.prototype.writeUint16BE=g.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||he(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};g.prototype.writeUint32LE=g.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||he(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};g.prototype.writeUint32BE=g.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||he(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 mi(t,e,r,n,o){Ii(e,n,o,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 s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,r}function wi(t,e,r,n,o){Ii(e,n,o,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 s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s=s>>8,t[r+2]=s,s=s>>8,t[r+1]=s,s=s>>8,t[r]=s,r+8}g.prototype.writeBigUInt64LE=Fe(function(e,r=0){return mi(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeBigUInt64BE=Fe(function(e,r=0){return wi(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeIntLE=function(e,r,n,o){if(e=+e,r=r>>>0,!o){let a=Math.pow(2,8*n-1);he(this,e,r,n,a-1,-a)}let i=0,s=1,c=0;for(this[r]=e&255;++i<n&&(s*=256);)e<0&&c===0&&this[r+i-1]!==0&&(c=1),this[r+i]=(e/s>>0)-c&255;return r+n};g.prototype.writeIntBE=function(e,r,n,o){if(e=+e,r=r>>>0,!o){let a=Math.pow(2,8*n-1);he(this,e,r,n,a-1,-a)}let i=n-1,s=1,c=0;for(this[r+i]=e&255;--i>=0&&(s*=256);)e<0&&c===0&&this[r+i+1]!==0&&(c=1),this[r+i]=(e/s>>0)-c&255;return r+n};g.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||he(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};g.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||he(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};g.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||he(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};g.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||he(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};g.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||he(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};g.prototype.writeBigInt64LE=Fe(function(e,r=0){return mi(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});g.prototype.writeBigInt64BE=Fe(function(e,r=0){return wi(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ei(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Bi(t,e,r,n,o){return e=+e,r=r>>>0,o||Ei(t,e,r,4,34028234663852886e22,-34028234663852886e22),st.write(t,e,r,n,23,4),r+4}g.prototype.writeFloatLE=function(e,r,n){return Bi(this,e,r,!0,n)};g.prototype.writeFloatBE=function(e,r,n){return Bi(this,e,r,!1,n)};function Ai(t,e,r,n,o){return e=+e,r=r>>>0,o||Ei(t,e,r,8,17976931348623157e292,-17976931348623157e292),st.write(t,e,r,n,52,8),r+8}g.prototype.writeDoubleLE=function(e,r,n){return Ai(this,e,r,!0,n)};g.prototype.writeDoubleBE=function(e,r,n){return Ai(this,e,r,!1,n)};g.prototype.copy=function(e,r,n,o){if(!g.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!o&&o!==0&&(o=this.length),r>=e.length&&(r=e.length),r||(r=0),o>0&&o<n&&(o=n),o===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(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),e.length-r<o-n&&(o=e.length-r+n);let i=o-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,o):Uint8Array.prototype.set.call(e,this.subarray(n,o),r),i};g.prototype.fill=function(e,r,n,o){if(typeof e=="string"){if(typeof r=="string"?(o=r,r=0,n=this.length):typeof n=="string"&&(o=n,n=this.length),o!==void 0&&typeof o!="string")throw new TypeError("encoding must be a string");if(typeof o=="string"&&!g.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(e.length===1){let s=e.charCodeAt(0);(o==="utf8"&&s<128||o==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let i;if(typeof e=="number")for(i=r;i<n;++i)this[i]=e;else{let s=g.isBuffer(e)?e:g.from(e,o),c=s.length;if(c===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<n-r;++i)this[i+r]=s[i%c]}return this};var it={};function pn(t,e,r){it[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(o){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:o,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}pn("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);pn("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);pn("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,o=r;return Number.isInteger(r)&&Math.abs(r)>2**32?o=hi(String(r)):typeof r=="bigint"&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=hi(o)),o+="n"),n+=` It must be ${e}. Received ${o}`,n},RangeError);function hi(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 Vc(t,e,r){ct(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&At(e,t.length-(r+1))}function Ii(t,e,r,n,o,i){if(t>r||t<e){let s=typeof e=="bigint"?"n":"",c;throw i>3?e===0||e===BigInt(0)?c=`>= 0${s} and < 2${s} ** ${(i+1)*8}${s}`:c=`>= -(2${s} ** ${(i+1)*8-1}${s}) and < 2 ** ${(i+1)*8-1}${s}`:c=`>= ${e}${s} and <= ${r}${s}`,new it.ERR_OUT_OF_RANGE("value",c,t)}Vc(n,o,i)}function ct(t,e){if(typeof t!="number")throw new it.ERR_INVALID_ARG_TYPE(e,"number",t)}function At(t,e,r){throw Math.floor(t)!==t?(ct(t,r),new it.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new it.ERR_BUFFER_OUT_OF_BOUNDS:new it.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var Fc=/[^+/0-9A-Za-z-_]/g;function Mc(t){if(t=t.split("=")[0],t=t.trim().replace(Fc,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function ln(t,e){e=e||1/0;let r,n=t.length,o=null,i=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=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 qc(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function $c(t,e){let r,n,o,i=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}function Si(t){return an.toByteArray(Mc(t))}function Jt(t,e,r,n){let o;for(o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function Be(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function yn(t){return t!==t}var jc=(function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let o=0;o<16;++o)e[n+o]=t[r]+t[o]}return e})();function Fe(t){return typeof BigInt>"u"?zc:t}function zc(){throw new Error("BigInt not supported")}});var ff={};ve(ff,{Nip46Method:()=>Rt,NostrEventKind:()=>lr,NostrMessageType:()=>dt,bytesToHex:()=>is,bytesToUtf8:()=>cs,calculateEventId:()=>Kr,computeSharedSecret:()=>en,createEvent:()=>jo,decrypt:()=>Zo,decryptMessage:()=>Qr,encrypt:()=>Wo,encryptMessage:()=>Jr,finalizeEvent:()=>zo,generateKeyPair:()=>qo,getPublicKey:()=>zt,getPublicKeySync:()=>Gr,hexToBytes:()=>os,nip01:()=>nn,nip04:()=>tn,nip19:()=>xn,nip26:()=>mn,nip44:()=>Cn,nip46:()=>On,nip49:()=>Vn,signEvent:()=>zr,utf8ToBytes:()=>ss,validateEvent:()=>Ko,validateEventBase:()=>Wt,validateEventId:()=>Wr,validateEventSignature:()=>Zr,validateFilter:()=>Zt,validateKeyPair:()=>$o,validateResponse:()=>Jo,validateSignedEvent:()=>Gt,validateSubscription:()=>Xo,verifySignature:()=>Go});var dt=(c=>(c.EVENT="EVENT",c.NOTICE="NOTICE",c.OK="OK",c.EOSE="EOSE",c.REQ="REQ",c.CLOSE="CLOSE",c.AUTH="AUTH",c))(dt||{});var Rt=(f=>(f.CONNECT="connect",f.PING="ping",f.GET_PUBLIC_KEY="get_public_key",f.SIGN_EVENT="sign_event",f.NIP04_ENCRYPT="nip04_encrypt",f.NIP04_DECRYPT="nip04_decrypt",f.NIP44_ENCRYPT="nip44_encrypt",f.NIP44_DECRYPT="nip44_decrypt",f.GET_RELAYS="get_relays",f))(Rt||{});var lr=(d=>(d[d.SET_METADATA=0]="SET_METADATA",d[d.TEXT_NOTE=1]="TEXT_NOTE",d[d.RECOMMEND_SERVER=2]="RECOMMEND_SERVER",d[d.CONTACT_LIST=3]="CONTACT_LIST",d[d.ENCRYPTED_DIRECT_MESSAGE=4]="ENCRYPTED_DIRECT_MESSAGE",d[d.DELETE=5]="DELETE",d[d.REPOST=6]="REPOST",d[d.REACTION=7]="REACTION",d[d.BADGE_AWARD=8]="BADGE_AWARD",d[d.CHANNEL_CREATE=40]="CHANNEL_CREATE",d[d.CHANNEL_METADATA=41]="CHANNEL_METADATA",d[d.CHANNEL_MESSAGE=42]="CHANNEL_MESSAGE",d[d.CHANNEL_HIDE_MESSAGE=43]="CHANNEL_HIDE_MESSAGE",d[d.CHANNEL_MUTE_USER=44]="CHANNEL_MUTE_USER",d[d.CHANNEL_RESERVE=45]="CHANNEL_RESERVE",d[d.REPORTING=1984]="REPORTING",d[d.ZAP_REQUEST=9734]="ZAP_REQUEST",d[d.ZAP=9735]="ZAP",d[d.MUTE_LIST=1e4]="MUTE_LIST",d[d.PIN_LIST=10001]="PIN_LIST",d[d.RELAY_LIST_METADATA=10002]="RELAY_LIST_METADATA",d[d.CLIENT_AUTH=22242]="CLIENT_AUTH",d[d.AUTH_RESPONSE=22243]="AUTH_RESPONSE",d[d.NOSTR_CONNECT=24133]="NOSTR_CONNECT",d[d.CATEGORIZED_PEOPLE=3e4]="CATEGORIZED_PEOPLE",d[d.CATEGORIZED_BOOKMARKS=30001]="CATEGORIZED_BOOKMARKS",d[d.PROFILE_BADGES=30008]="PROFILE_BADGES",d[d.BADGE_DEFINITION=30009]="BADGE_DEFINITION",d[d.LONG_FORM=30023]="LONG_FORM",d[d.APPLICATION_SPECIFIC=30078]="APPLICATION_SPECIFIC",d))(lr||{});function ht(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Q(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function q(t,e,r=""){let n=ht(t),o=t?.length,i=e!==void 0;if(!n||i&&o!==e){let s=r&&`"${r}" `,c=i?` of length ${e}`:"",a=n?`length=${o}`:`type=${typeof t}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return t}function Ue(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Q(t.outputLen),Q(t.blockLen)}function Ye(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 jn(t,e){q(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Ut(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function pe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Ke(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function be(t,e){return t<<32-e|t>>>e}function j(t,e){return t<<e|t>>>32-e>>>0}var gs=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function xs(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function bs(t){for(let e=0;e<t.length;e++)t[e]=xs(t[e]);return t}var dr=gs?t=>t:bs,zn=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ms=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function z(t){if(q(t),zn)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=ms[t[r]];return e}var Re={_0:48,_9:57,A:65,F:70,a:97,f:102};function $n(t){if(t>=Re._0&&t<=Re._9)return t-Re._0;if(t>=Re.A&&t<=Re.F)return t-(Re.A-10);if(t>=Re.a&&t<=Re.f)return t-(Re.a-10)}function V(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(zn)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 o=0,i=0;o<r;o++,i+=2){let s=$n(t.charCodeAt(i)),c=$n(t.charCodeAt(i+1));if(s===void 0||c===void 0){let a=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function ws(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function hr(t,e=""){return typeof t=="string"?ws(t):q(t,void 0,e)}function re(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];q(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}function kt(t,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("options must be object or undefined");return Object.assign(t,e)}function Gn(t,e={}){let r=(o,i)=>t(i).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function oe(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var Wn=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Zn(t,e,r){return t&e^~t&r}function Yn(t,e,r){return t&e^t&r^e&r}var Tt=class{constructor(e,r,n,o){R(this,"blockLen");R(this,"outputLen");R(this,"padOffset");R(this,"isLE");R(this,"buffer");R(this,"view");R(this,"finished",!1);R(this,"length",0);R(this,"pos",0);R(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Ke(this.buffer)}update(e){Ye(this),q(e);let{view:r,buffer:n,blockLen:o}=this,i=e.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=Ke(e);for(;o<=i-s;s+=o)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ye(this),jn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,pe(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let u=s;u<o;u++)r[u]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let c=Ke(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=a/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)c.setUint32(4*u,l[u],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:o,finished:i,destroyed:s,pos:c}=this;return e.destroyed=s,e.finished=i,e.length=o,e.pos=c,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},ke=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Es=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]),Pe=new Uint32Array(64),pr=class extends Tt{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[e,r,n,o,i,s,c,a]}set(e,r,n,o,i,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let u=0;u<16;u++,r+=4)Pe[u]=e.getUint32(r,!1);for(let u=16;u<64;u++){let p=Pe[u-15],h=Pe[u-2],b=be(p,7)^be(p,18)^p>>>3,x=be(h,17)^be(h,19)^h>>>10;Pe[u]=x+Pe[u-7]+b+Pe[u-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:f,H:l}=this;for(let u=0;u<64;u++){let p=be(c,6)^be(c,11)^be(c,25),h=l+p+Zn(c,a,f)+Es[u]+Pe[u]|0,x=(be(n,2)^be(n,13)^be(n,22))+Yn(n,o,i)|0;l=f,f=a,a=c,c=s+h|0,s=i,i=o,o=n,n=h+x|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(n,o,i,s,c,a,f,l)}roundClean(){pe(Pe)}destroy(){this.set(0,0,0,0,0,0,0,0),pe(this.buffer)}},yr=class extends pr{constructor(){super(32);R(this,"A",ke[0]|0);R(this,"B",ke[1]|0);R(this,"C",ke[2]|0);R(this,"D",ke[3]|0);R(this,"E",ke[4]|0);R(this,"F",ke[5]|0);R(this,"G",ke[6]|0);R(this,"H",ke[7]|0)}};var Z=Gn(()=>new yr,Wn(1));var xr=BigInt(0),gr=BigInt(1);function pt(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Kn(t){if(typeof t=="bigint"){if(!Nt(t))throw new Error("positive bigint expected, got "+t)}else Q(t);return t}function yt(t){let e=Kn(t).toString(16);return e.length&1?"0"+e:e}function Xn(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?xr:BigInt("0x"+t)}function De(t){return Xn(z(t))}function br(t){return Xn(z(Bs(q(t)).reverse()))}function _t(t,e){Q(e),t=Kn(t);let r=V(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function mr(t,e){return _t(t,e).reverse()}function Bs(t){return Uint8Array.from(t)}function Jn(t){return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Nt=t=>typeof t=="bigint"&&xr<=t;function As(t,e,r){return Nt(t)&&Nt(e)&&Nt(r)&&e<=t&&t<r}function Qn(t,e,r,n){if(!As(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function wr(t){let e;for(e=0;t>xr;t>>=gr,e+=1);return e}var gt=t=>(gr<<BigInt(t))-gr;function eo(t,e,r){if(Q(t,"hashLen"),Q(e,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=w=>new Uint8Array(w),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),c=1e3,a=n(t),f=n(t),l=0,u=()=>{a.fill(1),f.fill(0),l=0},p=(...w)=>r(f,re(a,...w)),h=(w=o)=>{f=p(i,w),a=p(),w.length!==0&&(f=p(s,w),a=p())},b=()=>{if(l++>=c)throw new Error("drbg: tried max amount of iterations");let w=0,A=[];for(;w<e;){a=p();let _=a.slice();A.push(_),w+=a.length}return re(...A)};return(w,A)=>{u(),h(w);let _;for(;!(_=A(b()));)h();return u(),_}}function xt(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(i,s,c){let a=t[i];if(c&&a===void 0)return;let f=typeof a;if(f!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`)}let o=(i,s)=>Object.entries(i).forEach(([c,a])=>n(c,a,s));o(e,!1),o(r,!0)}function Er(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let i=t(r,...n);return e.set(r,i),i}}var le=BigInt(0),fe=BigInt(1),Me=BigInt(2),no=BigInt(3),oo=BigInt(4),io=BigInt(5),Is=BigInt(7),so=BigInt(8),Ss=BigInt(9),co=BigInt(16);function me(t,e){let r=t%e;return r>=le?r:e+r}function ye(t,e,r){let n=t;for(;e-- >le;)n*=n,n%=r;return n}function to(t,e){if(t===le)throw new Error("invert: expected non-zero number");if(e<=le)throw new Error("invert: expected positive modulus, got "+e);let r=me(t,e),n=e,o=le,i=fe,s=fe,c=le;for(;r!==le;){let f=n/r,l=n%r,u=o-s*f,p=i-c*f;n=r,r=l,o=s,i=c,s=u,c=p}if(n!==fe)throw new Error("invert: does not exist");return me(o,e)}function Ar(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function ao(t,e){let r=(t.ORDER+fe)/oo,n=t.pow(e,r);return Ar(t,n,e),n}function vs(t,e){let r=(t.ORDER-io)/so,n=t.mul(e,Me),o=t.pow(n,r),i=t.mul(e,o),s=t.mul(t.mul(i,Me),o),c=t.mul(i,t.sub(s,t.ONE));return Ar(t,c,e),c}function Rs(t){let e=Xe(t),r=fo(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+Is)/co;return(c,a)=>{let f=c.pow(a,s),l=c.mul(f,n),u=c.mul(f,o),p=c.mul(f,i),h=c.eql(c.sqr(l),a),b=c.eql(c.sqr(u),a);f=c.cmov(f,l,h),l=c.cmov(p,u,b);let x=c.eql(c.sqr(l),a),w=c.cmov(f,l,x);return Ar(c,w,a),w}}function fo(t){if(t<no)throw new Error("sqrt is not defined for small field");let e=t-fe,r=0;for(;e%Me===le;)e/=Me,r++;let n=Me,o=Xe(t);for(;ro(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ao;let i=o.pow(n,e),s=(e+fe)/Me;return function(a,f){if(a.is0(f))return f;if(ro(a,f)!==1)throw new Error("Cannot find square root");let l=r,u=a.mul(a.ONE,i),p=a.pow(f,e),h=a.pow(f,s);for(;!a.eql(p,a.ONE);){if(a.is0(p))return a.ZERO;let b=1,x=a.sqr(p);for(;!a.eql(x,a.ONE);)if(b++,x=a.sqr(x),b===l)throw new Error("Cannot find square root");let w=fe<<BigInt(l-b-1),A=a.pow(u,w);l=b,u=a.sqr(A),p=a.mul(p,u),h=a.mul(h,A)}return h}}function Us(t){return t%oo===no?ao:t%so===io?vs:t%co===Ss?Rs(t):fo(t)}var ks=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ir(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=ks.reduce((n,o)=>(n[o]="function",n),e);return xt(t,r),t}function Ts(t,e,r){if(r<le)throw new Error("invalid exponent, negatives unsupported");if(r===le)return t.ONE;if(r===fe)return e;let n=t.ONE,o=e;for(;r>le;)r&fe&&(n=t.mul(n,o)),o=t.sqr(o),r>>=fe;return n}function Lt(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),o=e.reduce((s,c,a)=>t.is0(c)?s:(n[a]=s,t.mul(s,c)),t.ONE),i=t.inv(o);return e.reduceRight((s,c,a)=>t.is0(c)?s:(n[a]=t.mul(s,n[a]),t.mul(s,c)),i),n}function ro(t,e){let r=(t.ORDER-fe)/Me,n=t.pow(e,r),o=t.eql(n,t.ONE),i=t.eql(n,t.ZERO),s=t.eql(n,t.neg(t.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Ns(t,e){e!==void 0&&Q(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Br=class{constructor(e,r={}){R(this,"ORDER");R(this,"BITS");R(this,"BYTES");R(this,"isLE");R(this,"ZERO",le);R(this,"ONE",fe);R(this,"_lengths");R(this,"_sqrt");R(this,"_mod");if(e<=le)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=Ns(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return me(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return le<=e&&e<this.ORDER}is0(e){return e===le}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&fe)===fe}neg(e){return me(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return me(e*e,this.ORDER)}add(e,r){return me(e+r,this.ORDER)}sub(e,r){return me(e-r,this.ORDER)}mul(e,r){return me(e*r,this.ORDER)}pow(e,r){return Ts(this,e,r)}div(e,r){return me(e*to(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return to(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=Us(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?mr(e,this.BYTES):_t(e,this.BYTES)}fromBytes(e,r=!1){q(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:c}=this;if(n){if(!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(o);f.set(e,i?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let a=i?br(e):De(e);if(c&&(a=me(a,s)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return Lt(this,e)}cmov(e,r,n){return n?r:e}};function Xe(t,e={}){return new Br(t,e)}function uo(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 Sr(t){let e=uo(t);return e+Math.ceil(e/2)}function Ct(t,e,r=!1){q(t);let n=t.length,o=uo(e),i=Sr(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?br(t):De(t),c=me(s,e-fe)+fe;return r?mr(c,o):_t(c,o)}var Je=BigInt(0),qe=BigInt(1);function bt(t,e){let r=e.negate();return t?r:e}function kr(t,e){let r=Lt(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function yo(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function vr(t,e){yo(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,i=gt(t),s=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function lo(t,e,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,c=Number(t&o),a=t>>s;c>n&&(c-=i,a+=qe);let f=e*n,l=f+Math.abs(c)-1,u=c===0,p=c<0,h=e%2!==0;return{nextN:a,offset:l,isZero:u,isNeg:p,isNegF:h,offsetF:f}}var Rr=new WeakMap,go=new WeakMap;function Ur(t){return go.get(t)||1}function ho(t){if(t!==Je)throw new Error("invalid wNAF")}var Ot=class{constructor(e,r){R(this,"BASE");R(this,"ZERO");R(this,"Fn");R(this,"bits");this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>Je;)r&qe&&(n=n.add(o)),o=o.double(),r>>=qe;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=vr(r,this.bits),i=[],s=e,c=s;for(let a=0;a<n;a++){c=s,i.push(c);for(let f=1;f<o;f++)c=c.add(s),i.push(c);s=c.double()}return i}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=vr(e,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:f,isZero:l,isNeg:u,isNegF:p,offsetF:h}=lo(n,c,s);n=a,l?i=i.add(bt(p,r[h])):o=o.add(bt(u,r[f]))}return ho(n),{p:o,f:i}}wNAFUnsafe(e,r,n,o=this.ZERO){let i=vr(e,this.bits);for(let s=0;s<i.windows&&n!==Je;s++){let{nextN:c,offset:a,isZero:f,isNeg:l}=lo(n,s,i);if(n=c,!f){let u=r[a];o=o.add(l?u.negate():u)}}return ho(n),o}getPrecomputes(e,r,n){let o=Rr.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Rr.set(r,o))),o}cached(e,r,n){let o=Ur(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let i=Ur(e);return i===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),r,o)}createCache(e,r){yo(r,this.bits),go.set(e,r),Rr.delete(e)}hasCache(e){return Ur(e)!==1}};function xo(t,e,r,n){let o=e,i=t.ZERO,s=t.ZERO;for(;r>Je||n>Je;)r&qe&&(i=i.add(o)),n&qe&&(s=s.add(o)),o=o.double(),r>>=qe,n>>=qe;return{p1:i,p2:s}}function po(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ir(e),e}else return Xe(t,{isLE:r})}function bo(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 a of["p","n","h"]){let f=e[a];if(!(typeof f=="bigint"&&f>Je))throw new Error(`CURVE.${a} must be positive bigint`)}let o=po(e.p,r.Fp,n),i=po(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function Pt(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Dt=class{constructor(e,r){R(this,"oHash");R(this,"iHash");R(this,"blockLen");R(this,"outputLen");R(this,"finished",!1);R(this,"destroyed",!1);if(Ue(e),q(r,void 0,"key"),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 n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),pe(o)}update(e){return Ye(this),this.iHash.update(e),this}digestInto(e){Ye(this),q(e,this.outputLen,"output"),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:o,destroyed:i,blockLen:s,outputLen:c}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=c,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()}},we=(t,e,r)=>new Dt(t,e).update(r).digest();we.create=(t,e)=>new Dt(t,e);var mo=(t,e)=>(t+(t>=0?e:-e)/wo)/e;function _s(t,e,r){let[[n,o],[i,s]]=e,c=mo(s*t,r),a=mo(-o*t,r),f=t-c*n-a*i,l=-c*o-a*s,u=f<Te,p=l<Te;u&&(f=-f),p&&(l=-l);let h=gt(Math.ceil(wr(r)/2))+Qe;if(f<Te||f>=h||l<Te||l>=h)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:u,k1:f,k2neg:p,k2:l}}function Nr(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Tr(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return pt(r.lowS,"lowS"),pt(r.prehash,"prehash"),r.format!==void 0&&Nr(r.format),r}var _r=class extends Error{constructor(e=""){super(e)}},He={Err:_r,_tlv:{encode:(t,e)=>{let{Err:r}=He;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,o=yt(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?yt(o.length/2|128):"";return yt(t)+i+o+e},decode(t,e){let{Err:r}=He,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 o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of f)s=s<<8|l;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=e.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=He;if(t<Te)throw new e("integer: negative integers are not allowed");let r=yt(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}=He;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 De(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=He,o=q(t,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,i),{v:f,l}=n.decode(2,a);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=He,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}},Te=BigInt(0),Qe=BigInt(1),wo=BigInt(2),Ht=BigInt(3),Ls=BigInt(4);function Eo(t,e={}){let r=bo("weierstrass",t,e),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:c}=i;xt(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=e;if(a&&(!n.is0(i.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Ao(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(T,d,y){let{x:E,y:B}=d.toAffine(),S=n.toBytes(E);if(pt(y,"isCompressed"),y){l();let m=!n.isOdd(B);return re(Bo(m),S)}else return re(Uint8Array.of(4),S,n.toBytes(B))}function p(T){q(T,void 0,"Point");let{publicKey:d,publicKeyUncompressed:y}=f,E=T.length,B=T[0],S=T.subarray(1);if(E===d&&(B===2||B===3)){let m=n.fromBytes(S);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let v=x(m),I;try{I=n.sqrt(v)}catch(X){let G=X instanceof Error?": "+X.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}l();let U=n.isOdd(I);return(B&1)===1!==U&&(I=n.neg(I)),{x:m,y:I}}else if(E===y&&B===4){let m=n.BYTES,v=n.fromBytes(S.subarray(0,m)),I=n.fromBytes(S.subarray(m,m*2));if(!w(v,I))throw new Error("bad point: is not on curve");return{x:v,y:I}}else throw new Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${y}`)}let h=e.toBytes||u,b=e.fromBytes||p;function x(T){let d=n.sqr(T),y=n.mul(d,T);return n.add(n.add(y,n.mul(T,i.a)),i.b)}function w(T,d){let y=n.sqr(d),E=x(T);return n.eql(y,E)}if(!w(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let A=n.mul(n.pow(i.a,Ht),Ls),_=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(A,_)))throw new Error("bad curve params: a or b");function C(T,d,y=!1){if(!n.isValid(d)||y&&n.is0(d))throw new Error(`bad point coordinate ${T}`);return d}function H(T){if(!(T instanceof P))throw new Error("Weierstrass Point expected")}function K(T){if(!a||!a.basises)throw new Error("no endo");return _s(T,a.basises,o.ORDER)}let O=Er((T,d)=>{let{X:y,Y:E,Z:B}=T;if(n.eql(B,n.ONE))return{x:y,y:E};let S=T.is0();d==null&&(d=S?n.ONE:n.inv(B));let m=n.mul(y,d),v=n.mul(E,d),I=n.mul(B,d);if(S)return{x:n.ZERO,y:n.ZERO};if(!n.eql(I,n.ONE))throw new Error("invZ was invalid");return{x:m,y:v}}),$=Er(T=>{if(T.is0()){if(e.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:d,y}=T.toAffine();if(!n.isValid(d)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!w(d,y))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function W(T,d,y,E,B){return y=new P(n.mul(y.X,T),y.Y,y.Z),d=bt(E,d),y=bt(B,y),d.add(y)}let N=class N{constructor(d,y,E){R(this,"X");R(this,"Y");R(this,"Z");this.X=C("x",d),this.Y=C("y",y,!0),this.Z=C("z",E),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){let{x:y,y:E}=d||{};if(!d||!n.isValid(y)||!n.isValid(E))throw new Error("invalid affine point");if(d instanceof N)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(E)?N.ZERO:new N(y,E,n.ONE)}static fromBytes(d){let y=N.fromAffine(b(q(d,void 0,"point")));return y.assertValidity(),y}static fromHex(d){return N.fromBytes(V(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,y=!0){return F.createCache(this,d),y||this.multiply(Ht),this}assertValidity(){$(this)}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){H(d);let{X:y,Y:E,Z:B}=this,{X:S,Y:m,Z:v}=d,I=n.eql(n.mul(y,v),n.mul(S,B)),U=n.eql(n.mul(E,v),n.mul(m,B));return I&&U}negate(){return new N(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:y}=i,E=n.mul(y,Ht),{X:B,Y:S,Z:m}=this,v=n.ZERO,I=n.ZERO,U=n.ZERO,L=n.mul(B,B),X=n.mul(S,S),G=n.mul(m,m),D=n.mul(B,S);return D=n.add(D,D),U=n.mul(B,m),U=n.add(U,U),v=n.mul(d,U),I=n.mul(E,G),I=n.add(v,I),v=n.sub(X,I),I=n.add(X,I),I=n.mul(v,I),v=n.mul(D,v),U=n.mul(E,U),G=n.mul(d,G),D=n.sub(L,G),D=n.mul(d,D),D=n.add(D,U),U=n.add(L,L),L=n.add(U,L),L=n.add(L,G),L=n.mul(L,D),I=n.add(I,L),G=n.mul(S,m),G=n.add(G,G),L=n.mul(G,D),v=n.sub(v,L),U=n.mul(G,X),U=n.add(U,U),U=n.add(U,U),new N(v,I,U)}add(d){H(d);let{X:y,Y:E,Z:B}=this,{X:S,Y:m,Z:v}=d,I=n.ZERO,U=n.ZERO,L=n.ZERO,X=i.a,G=n.mul(i.b,Ht),D=n.mul(y,S),J=n.mul(E,m),ee=n.mul(B,v),ne=n.add(y,E),te=n.add(S,m);ne=n.mul(ne,te),te=n.add(D,J),ne=n.sub(ne,te),te=n.add(y,B);let ue=n.add(S,v);return te=n.mul(te,ue),ue=n.add(D,ee),te=n.sub(te,ue),ue=n.add(E,B),I=n.add(m,v),ue=n.mul(ue,I),I=n.add(J,ee),ue=n.sub(ue,I),L=n.mul(X,te),I=n.mul(G,ee),L=n.add(I,L),I=n.sub(J,L),L=n.add(J,L),U=n.mul(I,L),J=n.add(D,D),J=n.add(J,D),ee=n.mul(X,ee),te=n.mul(G,te),J=n.add(J,ee),ee=n.sub(D,ee),ee=n.mul(X,ee),te=n.add(te,ee),D=n.mul(J,te),U=n.add(U,D),D=n.mul(ue,te),I=n.mul(ne,I),I=n.sub(I,D),D=n.mul(ne,J),L=n.mul(ue,L),L=n.add(L,D),new N(I,U,L)}subtract(d){return this.add(d.negate())}is0(){return this.equals(N.ZERO)}multiply(d){let{endo:y}=e;if(!o.isValidNot0(d))throw new Error("invalid scalar: out of range");let E,B,S=m=>F.cached(this,m,v=>kr(N,v));if(y){let{k1neg:m,k1:v,k2neg:I,k2:U}=K(d),{p:L,f:X}=S(v),{p:G,f:D}=S(U);B=X.add(D),E=W(y.beta,L,G,m,I)}else{let{p:m,f:v}=S(d);E=m,B=v}return kr(N,[E,B])[0]}multiplyUnsafe(d){let{endo:y}=e,E=this;if(!o.isValid(d))throw new Error("invalid scalar: out of range");if(d===Te||E.is0())return N.ZERO;if(d===Qe)return E;if(F.hasCache(this))return this.multiply(d);if(y){let{k1neg:B,k1:S,k2neg:m,k2:v}=K(d),{p1:I,p2:U}=xo(N,E,S,v);return W(y.beta,I,U,B,m)}else return F.unsafe(E,d)}toAffine(d){return O(this,d)}isTorsionFree(){let{isTorsionFree:d}=e;return s===Qe?!0:d?d(N,this):F.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:d}=e;return s===Qe?this:d?d(N,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(d=!0){return pt(d,"isCompressed"),this.assertValidity(),h(N,this,d)}toHex(d=!0){return z(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};R(N,"BASE",new N(i.Gx,i.Gy,n.ONE)),R(N,"ZERO",new N(n.ZERO,n.ONE,n.ZERO)),R(N,"Fp",n),R(N,"Fn",o);let P=N,M=o.BITS,F=new Ot(P,e.endo?Math.ceil(M/2):M);return P.BASE.precompute(8),P}function Bo(t){return Uint8Array.of(t?2:3)}function Ao(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Cs(t,e={}){let{Fn:r}=t,n=e.randomBytes||oe,o=Object.assign(Ao(t.Fp,r),{seed:Sr(r.ORDER)});function i(h){try{let b=r.fromBytes(h);return r.isValidNot0(b)}catch{return!1}}function s(h,b){let{publicKey:x,publicKeyUncompressed:w}=o;try{let A=h.length;return b===!0&&A!==x||b===!1&&A!==w?!1:!!t.fromBytes(h)}catch{return!1}}function c(h=n(o.seed)){return Ct(q(h,o.seed,"seed"),r.ORDER)}function a(h,b=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(b)}function f(h){let{secretKey:b,publicKey:x,publicKeyUncompressed:w}=o;if(!ht(h)||"_lengths"in r&&r._lengths||b===x)return;let A=q(h,void 0,"key").length;return A===x||A===w}function l(h,b,x=!0){if(f(h)===!0)throw new Error("first arg must be private key");if(f(b)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(h);return t.fromBytes(b).multiply(w).toBytes(x)}let u={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:c},p=Pt(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:p,Point:t,utils:u,lengths:o})}function Io(t,e,r={}){Ue(e),xt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||oe,o=r.hmac||((d,y)=>we(e,d,y)),{Fp:i,Fn:s}=t,{ORDER:c,BITS:a}=s,{keygen:f,getPublicKey:l,getSharedSecret:u,utils:p,lengths:h}=Cs(t,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},x=c*wo<i.ORDER;function w(d){let y=c>>Qe;return d>y}function A(d,y){if(!s.isValidNot0(y))throw new Error(`invalid signature ${d}: out of range 1..Point.Fn.ORDER`);return y}function _(){if(x)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(d,y){Nr(y);let E=h.signature,B=y==="compact"?E:y==="recovered"?E+1:void 0;return q(d,B)}class H{constructor(y,E,B){R(this,"r");R(this,"s");R(this,"recovery");if(this.r=A("r",y),this.s=A("s",E),B!=null){if(_(),![0,1,2,3].includes(B))throw new Error("invalid recovery id");this.recovery=B}Object.freeze(this)}static fromBytes(y,E=b.format){C(y,E);let B;if(E==="der"){let{r:I,s:U}=He.toSig(q(y));return new H(I,U)}E==="recovered"&&(B=y[0],E="compact",y=y.subarray(1));let S=h.signature/2,m=y.subarray(0,S),v=y.subarray(S,S*2);return new H(s.fromBytes(m),s.fromBytes(v),B)}static fromHex(y,E){return this.fromBytes(V(y),E)}assertRecovery(){let{recovery:y}=this;if(y==null)throw new Error("invalid recovery id: must be present");return y}addRecoveryBit(y){return new H(this.r,this.s,y)}recoverPublicKey(y){let{r:E,s:B}=this,S=this.assertRecovery(),m=S===2||S===3?E+c:E;if(!i.isValid(m))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let v=i.toBytes(m),I=t.fromBytes(re(Bo((S&1)===0),v)),U=s.inv(m),L=O(q(y,void 0,"msgHash")),X=s.create(-L*U),G=s.create(B*U),D=t.BASE.multiplyUnsafe(X).add(I.multiplyUnsafe(G));if(D.is0())throw new Error("invalid recovery: point at infinify");return D.assertValidity(),D}hasHighS(){return w(this.s)}toBytes(y=b.format){if(Nr(y),y==="der")return V(He.hexFromSig(this));let{r:E,s:B}=this,S=s.toBytes(E),m=s.toBytes(B);return y==="recovered"?(_(),re(Uint8Array.of(this.assertRecovery()),S,m)):re(S,m)}toHex(y){return z(this.toBytes(y))}}let K=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let E=De(y),B=y.length*8-a;return B>0?E>>BigInt(B):E},O=r.bits2int_modN||function(y){return s.create(K(y))},$=gt(a);function W(d){return Qn("num < 2^"+a,d,Te,$),s.toBytes(d)}function P(d,y){return q(d,void 0,"message"),y?q(e(d),void 0,"prehashed message"):d}function M(d,y,E){let{lowS:B,prehash:S,extraEntropy:m}=Tr(E,b);d=P(d,S);let v=O(d),I=s.fromBytes(y);if(!s.isValidNot0(I))throw new Error("invalid private key");let U=[W(I),W(v)];if(m!=null&&m!==!1){let D=m===!0?n(h.secretKey):m;U.push(q(D,void 0,"extraEntropy"))}let L=re(...U),X=v;function G(D){let J=K(D);if(!s.isValidNot0(J))return;let ee=s.inv(J),ne=t.BASE.multiply(J).toAffine(),te=s.create(ne.x);if(te===Te)return;let ue=s.create(ee*s.create(X+te*I));if(ue===Te)return;let Fn=(ne.x===te?0:2)|Number(ne.y&Qe),Mn=ue;return B&&w(ue)&&(Mn=s.neg(ue),Fn^=1),new H(te,Mn,x?void 0:Fn)}return{seed:L,k2sig:G}}function F(d,y,E={}){let{seed:B,k2sig:S}=M(d,y,E);return eo(e.outputLen,s.BYTES,o)(B,S).toBytes(E.format)}function N(d,y,E,B={}){let{lowS:S,prehash:m,format:v}=Tr(B,b);if(E=q(E,void 0,"publicKey"),y=P(y,m),!ht(d)){let I=d instanceof H?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+I)}C(d,v);try{let I=H.fromBytes(d,v),U=t.fromBytes(E);if(S&&I.hasHighS())return!1;let{r:L,s:X}=I,G=O(y),D=s.inv(X),J=s.create(G*D),ee=s.create(L*D),ne=t.BASE.multiplyUnsafe(J).add(U.multiplyUnsafe(ee));return ne.is0()?!1:s.create(ne.x)===L}catch{return!1}}function T(d,y,E={}){let{prehash:B}=Tr(E,b);return y=P(y,B),H.fromBytes(d,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:u,utils:p,lengths:h,Point:t,sign:F,verify:N,recoverPublicKey:T,Signature:H,hash:e})}var Mt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Os={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Ps=BigInt(0),Lr=BigInt(2);function Ds(t){let e=Mt.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),f=t*t*t%e,l=f*f*t%e,u=ye(l,r,e)*l%e,p=ye(u,r,e)*l%e,h=ye(p,Lr,e)*f%e,b=ye(h,o,e)*h%e,x=ye(b,i,e)*b%e,w=ye(x,c,e)*x%e,A=ye(w,a,e)*w%e,_=ye(A,c,e)*x%e,C=ye(_,r,e)*l%e,H=ye(C,s,e)*b%e,K=ye(H,n,e)*f%e,O=ye(K,Lr,e);if(!Vt.eql(Vt.sqr(O),t))throw new Error("Cannot find square root");return O}var Vt=Xe(Mt.p,{sqrt:Ds}),$e=Eo(Mt,{Fp:Vt,endo:Os}),Ne=Io($e,Z),So={};function Ft(t,...e){let r=So[t];if(r===void 0){let n=Z(Jn(t));r=re(n,n),So[t]=r}return Z(re(r,...e))}var Or=t=>t.toBytes(!0).slice(1),Pr=t=>t%Lr===Ps;function Cr(t){let{Fn:e,BASE:r}=$e,n=e.fromBytes(t),o=r.multiply(n);return{scalar:Pr(o.y)?n:e.neg(n),bytes:Or(o)}}function Ro(t){let e=Vt;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let r=e.create(t*t),n=e.create(r*t+BigInt(7)),o=e.sqrt(n);Pr(o)||(o=e.neg(o));let i=$e.fromAffine({x:t,y:o});return i.assertValidity(),i}var mt=De;function Uo(...t){return $e.Fn.create(mt(Ft("BIP0340/challenge",...t)))}function vo(t){return Cr(t).bytes}function Hs(t,e,r=oe(32)){let{Fn:n}=$e,o=q(t,void 0,"message"),{bytes:i,scalar:s}=Cr(e),c=q(r,32,"auxRand"),a=n.toBytes(s^mt(Ft("BIP0340/aux",c))),f=Ft("BIP0340/nonce",a,i,o),{bytes:l,scalar:u}=Cr(f),p=Uo(l,i,o),h=new Uint8Array(64);if(h.set(l,0),h.set(n.toBytes(n.create(u+p*s)),32),!ko(h,o,i))throw new Error("sign: Invalid signature produced");return h}function ko(t,e,r){let{Fp:n,Fn:o,BASE:i}=$e,s=q(t,64,"signature"),c=q(e,void 0,"message"),a=q(r,32,"publicKey");try{let f=Ro(mt(a)),l=mt(s.subarray(0,32));if(!n.isValidNot0(l))return!1;let u=mt(s.subarray(32,64));if(!o.isValidNot0(u))return!1;let p=Uo(o.toBytes(l),Or(f),c),h=i.multiplyUnsafe(u).add(f.multiplyUnsafe(o.neg(p))),{x:b,y:x}=h.toAffine();return!(h.is0()||!Pr(x)||b!==l)}catch{return!1}}var ie=(()=>{let r=(n=oe(48))=>Ct(n,Mt.n);return{keygen:Pt(r,vo),getPublicKey:vo,sign:Hs,verify:ko,Point:$e,utils:{randomSecretKey:r,taggedHash:Ft,lift_x:Ro,pointToBytes:Or},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Vo=ur(Ho());var Y=(0,Vo.default)({name:"nostr-crypto-utils",level:process.env.LOG_LEVEL||"info",transport:void 0,formatters:{level:t=>({level:t.toUpperCase()}),log:t=>{if(t&&typeof t=="object"&&"err"in t){let e={...t};if(e.err instanceof Error){let r=e.err;e.err={message:r.message,stack:r.stack,name:r.name}}return e}return t}}});function rc(t){try{return!!t.match(/^[A-Za-z0-9+/]*={0,2}$/)}catch{return!1}}function tt(t){let e="";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return btoa(e)}function rt(t){if(!rc(t))throw new Error("Invalid base64 string");let e=atob(t),r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}var oc=async()=>{if(typeof window<"u"&&window.crypto)return window.crypto;if(typeof global<"u"&&global.crypto)return global.crypto;try{let t=await Promise.resolve().then(()=>($r(),qr));if(t.webcrypto)return t.webcrypto}catch{Y.debug("Node crypto not available")}throw new Error("No WebCrypto implementation available")},jr=class{constructor(){R(this,"cryptoInstance",null);R(this,"initPromise");this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await oc()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(e){return(await this.ensureInitialized()).getRandomValues(e)}},jt=new jr,Fo=ie.sign,Mo=ie.verify;async function qo(){let t=oe(32),e=z(t);t.fill(0);let r=await zt(e);return{privateKey:e,publicKey:r}}async function zt(t){try{let e=V(t),r=ie.getPublicKey(e);return{hex:z(r),bytes:r}}catch(e){throw Y.error({error:e},"Failed to get public key"),e}}async function $o(t){try{return(await zt(t.privateKey)).hex===t.publicKey.hex}catch(e){return Y.error({error:e},"Failed to validate key pair"),!1}}function jo(t){let e=Math.floor(Date.now()/1e3);return{...t,created_at:t.created_at||e,tags:t.tags||[],content:t.content||"",kind:t.kind||1}}function ic(t){return t instanceof Uint8Array?z(t):t}async function zr(t,e){try{let r=ic(e),n=JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content]),o=Z(new TextEncoder().encode(n)),i=V(r),s=ie.sign(o,i);return{...t,id:z(o),sig:z(s)}}catch(r){throw Y.error({error:r},"Failed to sign event"),r}}function Gr(t){let e=t instanceof Uint8Array?t:V(t),r=ie.getPublicKey(e);return z(r)}async function zo(t,e){let r=t.pubkey||Gr(e),n=t.created_at||Math.floor(Date.now()/1e3),o={kind:t.kind||1,created_at:n,tags:t.tags||[],content:t.content||"",pubkey:r};return zr(o,e)}async function Go(t){try{let e=JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content]),r=Z(new TextEncoder().encode(e));if(z(r)!==t.id)return Y.error("Event ID mismatch"),!1;let o=V(t.sig),i=V(t.pubkey);return ie.verify(o,r,i)}catch(e){return Y.error({error:e},"Failed to verify signature"),!1}}async function Wo(t,e,r){try{let n=typeof e=="string"?e:e.hex,o=Ne.getSharedSecret(V(r),V(n)),i=o.slice(1,33),s=oe(16),c=await jt.getSubtle().then(p=>p.importKey("raw",i.buffer,{name:"AES-CBC",length:256},!1,["encrypt"]));i.fill(0),o.fill(0);let a=new TextEncoder().encode(t),f=await jt.getSubtle().then(p=>p.encrypt({name:"AES-CBC",iv:s},c,a.buffer)),l=tt(new Uint8Array(f)),u=tt(s);return l+"?iv="+u}catch(n){throw Y.error({error:n},"Failed to encrypt message"),n}}async function Zo(t,e,r){try{let n=typeof e=="string"?e:e.hex,o=Ne.getSharedSecret(V(r),V(n)),i=o.slice(1,33),s,c;if(t.includes("?iv=")){let[l,u]=t.split("?iv=");c=rt(l),s=rt(u)}else{let l=V(t);s=l.slice(0,16),c=l.slice(16)}let a=await jt.getSubtle().then(l=>l.importKey("raw",i.buffer,{name:"AES-CBC",length:256},!1,["decrypt"]));i.fill(0),o.fill(0);let f=await jt.getSubtle().then(l=>l.decrypt({name:"AES-CBC",iv:s},a,c.buffer));return new TextDecoder().decode(f)}catch(n){throw Y.error({error:n},"Failed to decrypt message"),n}}function Et(t){return typeof t=="string"?t:t.hex}function Yo(t){return new Uint8Array(t.match(/.{1,2}/g).map(e=>parseInt(e,16)))}function Wr(t){try{let e=JSON.stringify([0,Et(t.pubkey),t.created_at,t.kind,t.tags,t.content]),r=z(Z(new TextEncoder().encode(e)));return{isValid:r===t.id,error:r===t.id?void 0:"Invalid event ID"}}catch(e){return Y.error({error:e},"Failed to validate event ID"),{isValid:!1,error:"Failed to validate event ID"}}}function Zr(t){try{let e=JSON.stringify([0,Et(t.pubkey),t.created_at,t.kind,t.tags,t.content]),r=Z(new TextEncoder().encode(e)),n=Et(t.pubkey),o=Yo(n),i=ie.verify(Yo(t.sig),r,o);return{isValid:i,error:i?void 0:"Invalid signature"}}catch(e){return Y.error({error:e},"Failed to validate event signature"),{isValid:!1,error:"Failed to validate event signature"}}}function Ko(t){let e=Wt(t);if(!e.isValid)return e;let r=Wr(t);return r.isValid?Zr(t):r}function Gt(t){try{let e=Wt(t);if(!e.isValid)return e;let r=Et(t.pubkey);return!r||typeof r!="string"||r.length!==64?{isValid:!1,error:"Invalid public key format"}:!t.sig||typeof t.sig!="string"||t.sig.length!==128?{isValid:!1,error:"Invalid signature format"}:!t.id||typeof t.id!="string"||t.id.length!==64?{isValid:!1,error:"Invalid event ID format"}:{isValid:!0}}catch(e){return Y.error({error:e},"Failed to validate signed event"),{isValid:!1,error:"Failed to validate signed event"}}}function Wt(t){if(!t||typeof t!="object")return{isValid:!1,error:"Invalid event structure"};if(typeof t.kind!="number"||t.kind<0)return{isValid:!1,error:"Event kind must be a non-negative integer"};let e=Math.floor(Date.now()/1e3);if(typeof t.created_at!="number"||t.created_at>e+60)return{isValid:!1,error:"Event timestamp cannot be in the future"};if(typeof t.content!="string")return{isValid:!1,error:"Event content must be a string"};if(!t.pubkey)return{isValid:!1,error:"Missing public key"};let r=Et(t.pubkey);if(typeof r!="string"||!/^[0-9a-f]{64}$/.test(r))return{isValid:!1,error:"Invalid public key format"};if(!Array.isArray(t.tags))return{isValid:!1,error:"Event tags must be an array"};for(let n of t.tags){if(!Array.isArray(n))return{isValid:!1,error:"Each tag must be an array"};if(n.length===0)return{isValid:!1,error:"Empty tags are not allowed"};if(typeof n[0]!="string")return{isValid:!1,error:"Tag identifier must be a string"}}return{isValid:!0}}function Zt(t){try{if(!t||typeof t!="object")return{isValid:!1,error:"Invalid filter structure"};if(t.ids&&(!Array.isArray(t.ids)||!t.ids.every(e=>typeof e=="string")))return{isValid:!1,error:"Filter ids must be an array of strings"};if(t.authors&&(!Array.isArray(t.authors)||!t.authors.every(e=>typeof e=="string")))return{isValid:!1,error:"Filter authors must be an array of strings"};if(t.kinds){if(!Array.isArray(t.kinds))return{isValid:!1,error:"Filter kinds must be an array of numbers"};if(!t.kinds.every(e=>typeof e=="number"&&Number.isInteger(e)&&e>=0))return{isValid:!1,error:"Filter kinds must be non-negative integers"}}return t.since&&typeof t.since!="number"?{isValid:!1,error:"Filter since must be a number"}:t.until&&typeof t.until!="number"?{isValid:!1,error:"Filter until must be a number"}:t.limit&&typeof t.limit!="number"?{isValid:!1,error:"Filter limit must be a number"}:t.search&&typeof t.search!="string"?{isValid:!1,error:"Filter search must be a string"}:{isValid:!0}}catch(e){return Y.error({error:e},"Failed to validate filter"),{isValid:!1,error:"Failed to validate filter"}}}function Xo(t){try{if(!t||typeof t!="object")return{isValid:!1,error:"Invalid subscription structure"};if(!t.id||typeof t.id!="string")return{isValid:!1,error:"Subscription must have a string ID"};if(!Array.isArray(t.filters))return{isValid:!1,error:"Subscription filters must be an array"};for(let e of t.filters){let r=Zt(e);if(!r.isValid)return r}return{isValid:!0}}catch(e){return Y.error({error:e},"Failed to validate subscription"),{isValid:!1,error:"Failed to validate subscription"}}}function Jo(t){if(!Array.isArray(t))return{isValid:!1,error:"Invalid message format: must be an array"};if(t.length===0)return{isValid:!1,error:"Invalid message format: array is empty"};let e=t[0];if(!Object.values(dt).includes(e))return{isValid:!1,error:`Invalid message type: ${e}`};switch(e){case"EVENT":return t.length!==2?{isValid:!1,error:"EVENT message must have exactly 2 elements"}:Gt(t[1]);case"NOTICE":return t.length!==2||typeof t[1]!="string"?{isValid:!1,error:"NOTICE message must have exactly 2 elements with a string message"}:{isValid:!0};case"OK":return t.length!==4||typeof t[1]!="string"||typeof t[2]!="boolean"||typeof t[3]!="string"?{isValid:!1,error:"OK message must have exactly 4 elements: [type, eventId, success, message]"}:{isValid:!0};case"EOSE":return t.length!==2||typeof t[1]!="string"?{isValid:!1,error:"EOSE message must have exactly 2 elements with a subscription ID"}:{isValid:!0};case"REQ":if(t.length<2)return{isValid:!1,error:"REQ message must have at least 2 elements"};if(typeof t[1]!="string")return{isValid:!1,error:"REQ message must have a string subscription ID"};for(let r=2;r<t.length;r++){let n=Zt(t[r]);if(!n.isValid)return n}return{isValid:!0};case"CLOSE":return t.length!==2||typeof t[1]!="string"?{isValid:!1,error:"CLOSE message must have exactly 2 elements with a subscription ID"}:{isValid:!0};case"AUTH":return t.length!==2?{isValid:!1,error:"AUTH message must have exactly 2 elements"}:Gt(t[1]);default:return{isValid:!1,error:`Unsupported message type: ${e}`}}}function Qo(t){return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}async function Yr(t){try{let e=Qo(t),r=await Z(new TextEncoder().encode(e));return z(r)}catch(e){throw Y.error({error:e},"Failed to get event hash"),e}}function Kr(t){return Yr(t)}var tn={};ve(tn,{computeSharedSecret:()=>en,decryptMessage:()=>Qr,encryptMessage:()=>Jr,generateSharedSecret:()=>en});var sc=async()=>{if(typeof window<"u"&&window.crypto)return window.crypto;if(typeof global<"u"&&global.crypto)return global.crypto;try{let t=await Promise.resolve().then(()=>($r(),qr));if(t.webcrypto)return t.webcrypto}catch{Y.debug("Node crypto not available")}throw new Error("No WebCrypto implementation available")},Xr=class{constructor(){R(this,"cryptoInstance",null);R(this,"initPromise");this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await sc()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(e){return(await this.ensureInitialized()).getRandomValues(e)}},Bt=new Xr;async function Jr(t,e,r){try{if(!t||!e||!r)throw new Error("Invalid input parameters");if(!/^[0-9a-f]{64}$/i.test(e))throw new Error("Invalid private key format");let n=r.startsWith("02")||r.startsWith("03")?r:"02"+r,o=Ne.getSharedSecret(V(e),V(n)),i=o.slice(1,33),s=await(await Bt.getSubtle()).importKey("raw",i.buffer,{name:"AES-CBC",length:256},!1,["encrypt"]);i.fill(0),o.fill(0);let c=new Uint8Array(16);await Bt.getRandomValues(c);let a=new TextEncoder().encode(t),f=await(await Bt.getSubtle()).encrypt({name:"AES-CBC",iv:c},s,a.buffer),l=tt(new Uint8Array(f)),u=tt(c);return l+"?iv="+u}catch(n){throw Y.error({error:n},"Failed to encrypt message"),n}}async function Qr(t,e,r){try{if(!t||!e||!r)throw new Error("Invalid input parameters");if(!/^[0-9a-f]{64}$/i.test(e))throw new Error("Invalid private key format");let n=r.startsWith("02")||r.startsWith("03")?r:"02"+r,o=Ne.getSharedSecret(V(e),V(n)),i=o.slice(1,33),s=await(await Bt.getSubtle()).importKey("raw",i.buffer,{name:"AES-CBC",length:256},!1,["decrypt"]);i.fill(0),o.fill(0);let c,a;if(t.includes("?iv=")){let[l,u]=t.split("?iv=");a=rt(l),c=rt(u)}else{let l=V(t);c=l.slice(0,16),a=l.slice(16)}let f=await(await Bt.getSubtle()).decrypt({name:"AES-CBC",iv:c},s,a.buffer);return new TextDecoder().decode(f)}catch(n){throw Y.error({error:n},"Failed to decrypt message"),n}}function en(t,e){try{if(!t||!e)throw new Error("Invalid input parameters");if(!/^[0-9a-f]{64}$/i.test(t))throw new Error("Invalid private key format");let r=e.startsWith("02")||e.startsWith("03")?e:"02"+e;return{sharedSecret:Ne.getSharedSecret(V(t),V(r)).slice(1,33)}}catch(r){throw Y.error({error:r},"Failed to generate shared secret"),r}}var nn={};ve(nn,{calculateEventId:()=>ti,createEvent:()=>cc,getEventHash:()=>ei,serializeEvent:()=>rn,signEvent:()=>ac,validateEvent:()=>uc,verifySignature:()=>fc});function cc(t){let{kind:e,content:r,tags:n=[],created_at:o=Math.floor(Date.now()/1e3),pubkey:i=""}=t;return{kind:e,content:r,tags:n,created_at:o,pubkey:i}}function rn(t){return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}async function ei(t){try{let e=rn(t),r=Z(new TextEncoder().encode(e));return z(r)}catch(e){throw Y.error({error:e},"Failed to get event hash"),e}}async function ac(t,e){try{let r=await ei(t),n=ie.sign(V(r),V(e));return{...t,id:r,sig:z(n)}}catch(r){throw Y.error({error:r},"Failed to sign event"),r}}function fc(t){try{let e=ti(t);return t.id!==e?!1:ie.verify(V(t.sig),V(t.id),V(t.pubkey))}catch(e){return Y.error({error:e},"Failed to verify signature"),!1}}function ti(t){let e=rn(t),r=Z(new TextEncoder().encode(e));return z(r)}function uc(t){try{if(typeof t.content!="string"||typeof t.created_at!="number"||typeof t.kind!="number"||!Array.isArray(t.tags)||typeof t.pubkey!="string")return!1;for(let e of t.tags)if(!Array.isArray(e)||e.length===0||typeof e[0]!="string")return!1;return!0}catch(e){return Y.error({error:e},"Failed to validate event"),!1}}var xn={};ve(xn,{decode:()=>ea,naddrEncode:()=>Jc,neventEncode:()=>Xc,noteEncode:()=>Yc,nprofileEncode:()=>Kc,npubEncode:()=>Wc,nrelayEncode:()=>Qc,nsecEncode:()=>Zc});var de=ur(ii()),xe=ur(vi()),Gc=["npub","nsec","note","nprofile","nevent","naddr","nrelay"],Ae={SPECIAL:0,RELAY:1,AUTHOR:2,KIND:3,IDENTIFIER:4};function Wc(t){Ie(t,64);let e=xe.Buffer.from(t,"hex"),r=de.bech32.toWords(e);return de.bech32.encode("npub",r,1e3)}function Zc(t){Ie(t,64);let e=xe.Buffer.from(t,"hex"),r=de.bech32.toWords(e);return de.bech32.encode("nsec",r,1e3)}function Yc(t){Ie(t,64);let e=xe.Buffer.from(t,"hex"),r=de.bech32.toWords(e);return de.bech32.encode("note",r,1e3)}function Kc(t,e){Ie(t,64),e&&e.forEach(ft);let r=gn({type:"nprofile",data:t,relays:e});return de.bech32.encode("nprofile",r,1e3)}function Xc(t,e,r,n){if(Ie(t,64),e&&e.forEach(ft),r&&Ie(r,64),n!==void 0&&!Number.isInteger(n))throw new Error("Invalid event kind");let o=gn({type:"nevent",data:t,relays:e,author:r,kind:n});return de.bech32.encode("nevent",o,1e3)}function Jc(t,e,r,n){if(Ie(t,64),!Number.isInteger(e))throw new Error("Invalid event kind");if(!r)throw new Error("Identifier is required");n&&n.forEach(ft);let o=gn({type:"naddr",data:t,kind:e,identifier:r,relays:n});return de.bech32.encode("naddr",o,1e3)}function Qc(t){ft(t);let e=xe.Buffer.from(t,"utf8"),r=de.bech32.toWords(e);return de.bech32.encode("nrelay",r,1e3)}function ea(t){if(!t.includes("1"))throw new Error("Invalid bech32 string");let e=t.split("1")[0].toLowerCase();if(!Gc.includes(e))throw new Error("Unknown prefix");try{let r=de.bech32.decode(t,1e3),n=xe.Buffer.from(de.bech32.fromWords(r.words)),o,i;switch(r.prefix){case"npub":case"nsec":case"note":return Ie(n.toString("hex"),64),{type:r.prefix,data:n.toString("hex")};case"nrelay":return o=n.toString("utf8"),ft(o),{type:"nrelay",data:o};case"nprofile":case"nevent":case"naddr":return i=ta(r.prefix,n),i;default:throw new Error("Unknown prefix")}}catch(r){throw r instanceof Error?r:new Error("Invalid bech32 string")}}function Ie(t,e){if(!/^[0-9a-fA-F]+$/.test(t))throw new Error("Invalid hex string");if(e&&t.length!==e)throw new Error(`Invalid hex string length (expected ${e})`)}function ft(t){try{let e=new URL(t);if(!["ws:","wss:"].includes(e.protocol))throw new Error("Invalid relay URL protocol")}catch{throw new Error("Invalid relay URL")}}function gn(t){let e=[],r=xe.Buffer.from(t.data,"hex");if(e.push(Ae.SPECIAL,r.length),e.push(...r),t.relays?.length)for(let n of t.relays){let o=xe.Buffer.from(n,"utf8");e.push(Ae.RELAY,o.length),e.push(...o)}if(t.author){let n=xe.Buffer.from(t.author,"hex");e.push(Ae.AUTHOR,n.length),e.push(...n)}if(t.kind!==void 0){let n=xe.Buffer.alloc(4);n.writeUInt32BE(t.kind),e.push(Ae.KIND,n.length),e.push(...n)}if(t.identifier){let n=xe.Buffer.from(t.identifier,"utf8");e.push(Ae.IDENTIFIER,n.length),e.push(...n)}return de.bech32.toWords(xe.Buffer.from(e))}function ta(t,e){let r={type:t,data:"",relays:[]},n=0,o;for(;n<e.length;){let i=e[n],s=e[n+1];if(n+2+s>e.length)throw new Error("Invalid TLV data");let c=e.slice(n+2,n+2+s);switch(i){case Ae.SPECIAL:r.data=c.toString("hex"),Ie(r.data,64);break;case Ae.RELAY:o=c.toString("utf8"),ft(o),r.relays=r.relays||[],r.relays.push(o);break;case Ae.AUTHOR:r.author=c.toString("hex"),Ie(r.author,64);break;case Ae.KIND:r.kind=c.readUInt32BE();break;case Ae.IDENTIFIER:r.identifier=c.toString("utf8");break;default:break}n+=2+s}return r}var mn={};ve(mn,{addDelegationTag:()=>ia,checkDelegationConditions:()=>oa,createDelegation:()=>ra,extractDelegation:()=>sa,verifyDelegation:()=>na});function ra(t,e,r){let n=bn(r),o=aa(t,e,n);return{delegator:z(ie.getPublicKey(V(t))),delegatee:e,conditions:r,token:o}}async function na(t){let e=bn(t.conditions);return await fa(t.delegator,t.delegatee,e,t.token)}function oa(t,e){return!(e.kind!==void 0&&t.kind!==e.kind||e.since!==void 0&&t.created_at<e.since||e.until!==void 0&&t.created_at>e.until)}function ia(t,e){let r=["delegation",e.delegator,bn(e.conditions),e.token];return{...t,tags:[...t.tags,r]}}function sa(t){let e=t.tags.find(r=>r[0]==="delegation");return!e||e.length!==4?null:{delegator:e[1],delegatee:t.pubkey,conditions:ca(e[2]),token:e[3]}}function bn(t){let e=[];return t.kind!==void 0&&e.push(`kind=${t.kind}`),t.since!==void 0&&e.push(`created_at>${t.since}`),t.until!==void 0&&e.push(`created_at<${t.until}`),e.join("&")}function ca(t){let e={},r=t.split("&");for(let n of r)n.startsWith("kind=")?e.kind=parseInt(n.slice(5)):n.startsWith("created_at>")?e.since=parseInt(n.slice(11)):n.startsWith("created_at<")&&(e.until=parseInt(n.slice(11)));return e}function aa(t,e,r){let n=`nostr:delegation:${e}:${r}`,o=Z(new TextEncoder().encode(n)),i=Fo(o,V(t));return z(i)}async function fa(t,e,r,n){let o=Z(new TextEncoder().encode(`nostr:delegation:${e}:${r}`));return Mo(V(n),o,V(t))}var Cn={};ve(Cn,{calcPaddedLen:()=>cr,decrypt:()=>fr,encrypt:()=>ar,getConversationKey:()=>vt,v2:()=>Ca});function ua(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Qt(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function er(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function ce(t,e,r=""){let n=ua(t),o=t?.length,i=e!==void 0;if(!n||i&&o!==e){let s=r&&`"${r}" `,c=i?` of length ${e}`:"",a=n?`length=${o}`:`type=${typeof t}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return t}function wn(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 Ri(t,e){ce(t,void 0,"output");let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ce(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Oe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function la(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var da=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ui(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function tr(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 En=(t,e)=>{function r(n,...o){if(ce(n,void 0,"key"),!da)throw new Error("Non little-endian hardware is not yet supported");if(t.nonceLength!==void 0){let l=o[0];ce(l,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let i=t.tagLength;i&&o[1]!==void 0&&ce(o[1],void 0,"AAD");let s=e(n,...o),c=(l,u)=>{if(u!==void 0){if(l!==2)throw new Error("cipher output not supported");ce(u,void 0,"output")}},a=!1;return{encrypt(l,u){if(a)throw new Error("cannot encrypt() twice with same key + nonce");return a=!0,ce(l),c(s.encrypt.length,u),s.encrypt(l,u)},decrypt(l,u){if(ce(l),i&&l.length<i)throw new Error('"ciphertext" expected length bigger than tagLength='+i);return c(s.decrypt.length,u),s.decrypt(l,u)}}}return Object.assign(r,t),r};function Bn(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(e.length!==t)throw new Error('"output" expected Uint8Array of length '+t+", got: "+e.length);if(r&&!ha(e))throw new Error("invalid output, must be aligned");return e}function ki(t,e,r){Qt(r);let n=new Uint8Array(16),o=la(n);return o.setBigUint64(0,BigInt(e),r),o.setBigUint64(8,BigInt(t),r),n}function ha(t){return t.byteOffset%4===0}function ut(t){return Uint8Array.from(t)}var Ni=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),pa=Ni("expand 16-byte k"),ya=Ni("expand 32-byte k"),ga=Ce(pa),xa=Ce(ya);function k(t,e){return t<<e|t>>>32-e}function An(t){return t.byteOffset%4===0}var rr=64,ba=16,_i=2**32-1,Ti=Uint32Array.of();function ma(t,e,r,n,o,i,s,c){let a=o.length,f=new Uint8Array(rr),l=Ce(f),u=An(o)&&An(i),p=u?Ce(o):Ti,h=u?Ce(i):Ti;for(let b=0;b<a;s++){if(t(e,r,n,l,s,c),s>=_i)throw new Error("arx: counter overflow");let x=Math.min(rr,a-b);if(u&&x===rr){let w=b/4;if(b%4!==0)throw new Error("arx: invalid block position");for(let A=0,_;A<ba;A++)_=w+A,h[_]=p[_]^l[A];b+=rr;continue}for(let w=0,A;w<x;w++)A=b+w,i[A]=o[A]^f[w];b+=x}}function In(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=Ui({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return er(o),er(s),Qt(i),Qt(r),(c,a,f,l,u=0)=>{ce(c,void 0,"key"),ce(a,void 0,"nonce"),ce(f,void 0,"data");let p=f.length;if(l===void 0&&(l=new Uint8Array(p)),ce(l,void 0,"output"),er(u),u<0||u>=_i)throw new Error("arx: counter overflow");if(l.length<p)throw new Error(`arx: output (${l.length}) is shorter than data (${p})`);let h=[],b=c.length,x,w;if(b===32)h.push(x=ut(c)),w=xa;else if(b===16&&r)x=new Uint8Array(32),x.set(c),x.set(c,16),w=ga,h.push(x);else throw ce(c,32,"arx key"),new Error("invalid key size");An(a)||h.push(a=ut(a));let A=Ce(x);if(n){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(w,A,Ce(a.subarray(0,16)),A),a=a.subarray(16)}let _=16-o;if(_!==a.length)throw new Error(`arx: nonce must be ${_} or 16 bytes`);if(_!==12){let H=new Uint8Array(12);H.set(a,i?0:12-a.length),a=H,h.push(a)}let C=Ce(a);return ma(t,w,A,C,f,l,u,s),Oe(...h),l}}function ae(t,e){return t[e++]&255|(t[e++]&255)<<8}var Sn=class{constructor(e){R(this,"blockLen",16);R(this,"outputLen",16);R(this,"buffer",new Uint8Array(16));R(this,"r",new Uint16Array(10));R(this,"h",new Uint16Array(10));R(this,"pad",new Uint16Array(8));R(this,"pos",0);R(this,"finished",!1);e=ut(ce(e,32,"key"));let r=ae(e,0),n=ae(e,2),o=ae(e,4),i=ae(e,6),s=ae(e,8),c=ae(e,10),a=ae(e,12),f=ae(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|c<<2)&8191,this.r[7]=(c>>>11|a<<5)&8065,this.r[8]=(a>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let l=0;l<8;l++)this.pad[l]=ae(e,16+2*l)}process(e,r,n=!1){let o=n?0:2048,{h:i,r:s}=this,c=s[0],a=s[1],f=s[2],l=s[3],u=s[4],p=s[5],h=s[6],b=s[7],x=s[8],w=s[9],A=ae(e,r+0),_=ae(e,r+2),C=ae(e,r+4),H=ae(e,r+6),K=ae(e,r+8),O=ae(e,r+10),$=ae(e,r+12),W=ae(e,r+14),P=i[0]+(A&8191),M=i[1]+((A>>>13|_<<3)&8191),F=i[2]+((_>>>10|C<<6)&8191),N=i[3]+((C>>>7|H<<9)&8191),T=i[4]+((H>>>4|K<<12)&8191),d=i[5]+(K>>>1&8191),y=i[6]+((K>>>14|O<<2)&8191),E=i[7]+((O>>>11|$<<5)&8191),B=i[8]+(($>>>8|W<<8)&8191),S=i[9]+(W>>>5|o),m=0,v=m+P*c+M*(5*w)+F*(5*x)+N*(5*b)+T*(5*h);m=v>>>13,v&=8191,v+=d*(5*p)+y*(5*u)+E*(5*l)+B*(5*f)+S*(5*a),m+=v>>>13,v&=8191;let I=m+P*a+M*c+F*(5*w)+N*(5*x)+T*(5*b);m=I>>>13,I&=8191,I+=d*(5*h)+y*(5*p)+E*(5*u)+B*(5*l)+S*(5*f),m+=I>>>13,I&=8191;let U=m+P*f+M*a+F*c+N*(5*w)+T*(5*x);m=U>>>13,U&=8191,U+=d*(5*b)+y*(5*h)+E*(5*p)+B*(5*u)+S*(5*l),m+=U>>>13,U&=8191;let L=m+P*l+M*f+F*a+N*c+T*(5*w);m=L>>>13,L&=8191,L+=d*(5*x)+y*(5*b)+E*(5*h)+B*(5*p)+S*(5*u),m+=L>>>13,L&=8191;let X=m+P*u+M*l+F*f+N*a+T*c;m=X>>>13,X&=8191,X+=d*(5*w)+y*(5*x)+E*(5*b)+B*(5*h)+S*(5*p),m+=X>>>13,X&=8191;let G=m+P*p+M*u+F*l+N*f+T*a;m=G>>>13,G&=8191,G+=d*c+y*(5*w)+E*(5*x)+B*(5*b)+S*(5*h),m+=G>>>13,G&=8191;let D=m+P*h+M*p+F*u+N*l+T*f;m=D>>>13,D&=8191,D+=d*a+y*c+E*(5*w)+B*(5*x)+S*(5*b),m+=D>>>13,D&=8191;let J=m+P*b+M*h+F*p+N*u+T*l;m=J>>>13,J&=8191,J+=d*f+y*a+E*c+B*(5*w)+S*(5*x),m+=J>>>13,J&=8191;let ee=m+P*x+M*b+F*h+N*p+T*u;m=ee>>>13,ee&=8191,ee+=d*l+y*f+E*a+B*c+S*(5*w),m+=ee>>>13,ee&=8191;let ne=m+P*w+M*x+F*b+N*h+T*p;m=ne>>>13,ne&=8191,ne+=d*u+y*l+E*f+B*a+S*c,m+=ne>>>13,ne&=8191,m=(m<<2)+m|0,m=m+v|0,v=m&8191,m=m>>>13,I+=m,i[0]=v,i[1]=I,i[2]=U,i[3]=L,i[4]=X,i[5]=G,i[6]=D,i[7]=J,i[8]=ee,i[9]=ne}finalize(){let{h:e,pad:r}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let c=2;c<10;c++)e[c]+=o,o=e[c]>>>13,e[c]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=e[c]+o,o=n[c]>>>13,n[c]&=8191;n[9]-=8192;let i=(o^1)-1;for(let c=0;c<10;c++)n[c]&=i;i=~i;for(let c=0;c<10;c++)e[c]=e[c]&i|n[c];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 s=e[0]+r[0];e[0]=s&65535;for(let c=1;c<8;c++)s=(e[c]+r[c]|0)+(s>>>16)|0,e[c]=s&65535;Oe(n)}update(e){wn(this),ce(e),e=ut(e);let{buffer:r,blockLen:n}=this,o=e.length;for(let i=0;i<o;){let s=Math.min(n-this.pos,o-i);if(s===n){for(;n<=o-i;i+=n)this.process(e,i);continue}r.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){Oe(this.h,this.r,this.buffer,this.pad)}digestInto(e){wn(this),Ri(e,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:o}=this;if(o){for(r[o++]=1;o<16;o++)r[o]=0;this.process(r,0,!0)}this.finalize();let i=0;for(let s=0;s<8;s++)e[i++]=n[s]>>>0,e[i++]=n[s]>>>8;return e}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}};function wa(t){let e=(n,o)=>t(o).update(n).digest(),r=t(new Uint8Array(32));return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}var Li=wa(t=>new Sn(t));function Pi(t,e,r,n,o,i=20){let s=t[0],c=t[1],a=t[2],f=t[3],l=e[0],u=e[1],p=e[2],h=e[3],b=e[4],x=e[5],w=e[6],A=e[7],_=o,C=r[0],H=r[1],K=r[2],O=s,$=c,W=a,P=f,M=l,F=u,N=p,T=h,d=b,y=x,E=w,B=A,S=_,m=C,v=H,I=K;for(let L=0;L<i;L+=2)O=O+M|0,S=k(S^O,16),d=d+S|0,M=k(M^d,12),O=O+M|0,S=k(S^O,8),d=d+S|0,M=k(M^d,7),$=$+F|0,m=k(m^$,16),y=y+m|0,F=k(F^y,12),$=$+F|0,m=k(m^$,8),y=y+m|0,F=k(F^y,7),W=W+N|0,v=k(v^W,16),E=E+v|0,N=k(N^E,12),W=W+N|0,v=k(v^W,8),E=E+v|0,N=k(N^E,7),P=P+T|0,I=k(I^P,16),B=B+I|0,T=k(T^B,12),P=P+T|0,I=k(I^P,8),B=B+I|0,T=k(T^B,7),O=O+F|0,I=k(I^O,16),E=E+I|0,F=k(F^E,12),O=O+F|0,I=k(I^O,8),E=E+I|0,F=k(F^E,7),$=$+N|0,S=k(S^$,16),B=B+S|0,N=k(N^B,12),$=$+N|0,S=k(S^$,8),B=B+S|0,N=k(N^B,7),W=W+T|0,m=k(m^W,16),d=d+m|0,T=k(T^d,12),W=W+T|0,m=k(m^W,8),d=d+m|0,T=k(T^d,7),P=P+M|0,v=k(v^P,16),y=y+v|0,M=k(M^y,12),P=P+M|0,v=k(v^P,8),y=y+v|0,M=k(M^y,7);let U=0;n[U++]=s+O|0,n[U++]=c+$|0,n[U++]=a+W|0,n[U++]=f+P|0,n[U++]=l+M|0,n[U++]=u+F|0,n[U++]=p+N|0,n[U++]=h+T|0,n[U++]=b+d|0,n[U++]=x+y|0,n[U++]=w+E|0,n[U++]=A+B|0,n[U++]=_+S|0,n[U++]=C+m|0,n[U++]=H+v|0,n[U++]=K+I|0}function Ea(t,e,r,n){let o=t[0],i=t[1],s=t[2],c=t[3],a=e[0],f=e[1],l=e[2],u=e[3],p=e[4],h=e[5],b=e[6],x=e[7],w=r[0],A=r[1],_=r[2],C=r[3];for(let K=0;K<20;K+=2)o=o+a|0,w=k(w^o,16),p=p+w|0,a=k(a^p,12),o=o+a|0,w=k(w^o,8),p=p+w|0,a=k(a^p,7),i=i+f|0,A=k(A^i,16),h=h+A|0,f=k(f^h,12),i=i+f|0,A=k(A^i,8),h=h+A|0,f=k(f^h,7),s=s+l|0,_=k(_^s,16),b=b+_|0,l=k(l^b,12),s=s+l|0,_=k(_^s,8),b=b+_|0,l=k(l^b,7),c=c+u|0,C=k(C^c,16),x=x+C|0,u=k(u^x,12),c=c+u|0,C=k(C^c,8),x=x+C|0,u=k(u^x,7),o=o+f|0,C=k(C^o,16),b=b+C|0,f=k(f^b,12),o=o+f|0,C=k(C^o,8),b=b+C|0,f=k(f^b,7),i=i+l|0,w=k(w^i,16),x=x+w|0,l=k(l^x,12),i=i+l|0,w=k(w^i,8),x=x+w|0,l=k(l^x,7),s=s+u|0,A=k(A^s,16),p=p+A|0,u=k(u^p,12),s=s+u|0,A=k(A^s,8),p=p+A|0,u=k(u^p,7),c=c+a|0,_=k(_^c,16),h=h+_|0,a=k(a^h,12),c=c+a|0,_=k(_^c,8),h=h+_|0,a=k(a^h,7);let H=0;n[H++]=o,n[H++]=i,n[H++]=s,n[H++]=c,n[H++]=w,n[H++]=A,n[H++]=_,n[H++]=C}var nr=In(Pi,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Ba=In(Pi,{counterRight:!1,counterLength:8,extendNonceFn:Ea,allowShortKeys:!1});var Aa=new Uint8Array(16),Ci=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(Aa.subarray(r))},Ia=new Uint8Array(32);function Oi(t,e,r,n,o){o!==void 0&&ce(o,void 0,"AAD");let i=t(e,r,Ia),s=ki(n.length,o?o.length:0,!0),c=Li.create(i);o&&Ci(c,o),Ci(c,n),c.update(s);let a=c.digest();return Oe(i,s),a}var Di=t=>(e,r,n)=>({encrypt(i,s){let c=i.length;s=Bn(c+16,s,!1),s.set(i);let a=s.subarray(0,-16);t(e,r,a,a,1);let f=Oi(t,e,r,a,n);return s.set(f,c),Oe(f),s},decrypt(i,s){s=Bn(i.length-16,s,!1);let c=i.subarray(0,-16),a=i.subarray(-16),f=Oi(t,e,r,c,n);if(!tr(a,f))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),t(e,r,s,s,1),Oe(f),s}}),El=En({blockSize:64,nonceLength:12,tagLength:16},Di(nr)),vn=En({blockSize:64,nonceLength:24,tagLength:16},Di(Ba));function Vi(t,e,r){return Ue(t),r===void 0&&(r=new Uint8Array(t.outputLen)),we(t,r,e)}var Rn=Uint8Array.of(0),Hi=Uint8Array.of();function Fi(t,e,r,n=32){Ue(t),Q(n,"length");let o=t.outputLen;if(n>255*o)throw new Error("Length must be <= 255*HashLen");let i=Math.ceil(n/o);r===void 0?r=Hi:q(r,void 0,"info");let s=new Uint8Array(i*o),c=we.create(t,e),a=c._cloneInto(),f=new Uint8Array(c.outputLen);for(let l=0;l<i;l++)Rn[0]=l+1,a.update(l===0?Hi:f).update(r).update(Rn).digestInto(f),s.set(f,o*l),c._cloneInto(a);return c.destroy(),a.destroy(),pe(f,Rn),s.slice(0,n)}function Nn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Sa(t){if(!Nn(t))throw new Error("Uint8Array expected")}function ji(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 va(t){if(typeof t!="function")throw new Error("function expected");return!0}function We(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function _n(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Un(t){if(!Array.isArray(t))throw new Error("array expected")}function ir(t,e){if(!ji(!0,e))throw new Error(`${t}: array of strings expected`)}function zi(t,e){if(!ji(!1,e))throw new Error(`${t}: array of numbers expected`)}function Gi(...t){let e=i=>i,r=(i,s)=>c=>i(s(c)),n=t.map(i=>i.encode).reduceRight(r,e),o=t.map(i=>i.decode).reduce(r,e);return{encode:n,decode:o}}function Wi(t){let e=typeof t=="string"?t.split(""):t,r=e.length;ir("alphabet",e);let n=new Map(e.map((o,i)=>[o,i]));return{encode:o=>(Un(o),o.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:o=>(Un(o),o.map(i=>{We("alphabet.decode",i);let s=n.get(i);if(s===void 0)throw new Error(`Unknown letter: "${i}". Allowed: ${t}`);return s}))}}function Zi(t=""){return We("join",t),{encode:e=>(ir("join.decode",e),e.join(t)),decode:e=>(We("join.decode",e),e.split(t))}}function Ra(t,e="="){return _n(t),We("padding",e),{encode(r){for(ir("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){ir("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)}}}var Yi=(t,e)=>e===0?t:Yi(e,t%e),sr=(t,e)=>t+(e-Yi(t,e)),or=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function kn(t,e,r,n){if(Un(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(sr(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${sr(e,r)}`);let o=0,i=0,s=or[e],c=or[r]-1,a=[];for(let f of t){if(_n(f),f>=s)throw new Error(`convertRadix2: invalid data word=${f} from=${e}`);if(o=o<<e|f,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=r;i-=r)a.push((o>>i-r&c)>>>0);let l=or[i];if(l===void 0)throw new Error("invalid carry");o&=l-1}if(o=o<<r-i&c,!n&&i>=e)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&i>0&&a.push(o>>>0),a}function Ki(t,e=!1){if(_n(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(sr(8,t)>32||sr(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Nn(r))throw new Error("radix2.encode input should be Uint8Array");return kn(Array.from(r),8,t,!e)},decode:r=>(zi("radix2.decode",r),Uint8Array.from(kn(r,t,8,e)))}}function Mi(t){return va(t),function(...e){try{return t.apply(null,e)}catch{}}}var Ua=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",ka=(t,e)=>{We("base64",t);let r=e?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,n=e?"base64url":"base64";if(t.length>0&&!r.test(t))throw new Error("invalid base64");return Uint8Array.fromBase64(t,{alphabet:n,lastChunkHandling:"strict"})},Ln=Ua?{encode(t){return Sa(t),t.toBase64()},decode(t){return ka(t,!1)}}:Gi(Ki(6),Wi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Ra(6),Zi(""));var Tn=Gi(Wi("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Zi("")),qi=[996825010,642813549,513874426,1027748829,705979059];function It(t){let e=t>>25,r=(t&33554431)<<5;for(let n=0;n<qi.length;n++)(e>>n&1)===1&&(r^=qi[n]);return r}function $i(t,e,r=1){let n=t.length,o=1;for(let i=0;i<n;i++){let s=t.charCodeAt(i);if(s<33||s>126)throw new Error(`Invalid prefix (${t})`);o=It(o)^s>>5}o=It(o);for(let i=0;i<n;i++)o=It(o)^t.charCodeAt(i)&31;for(let i of e)o=It(o)^i;for(let i=0;i<6;i++)o=It(o);return o^=r,Tn.encode(kn([o%or[30]],30,5,!1))}function Ta(t){let e=t==="bech32"?1:734539939,r=Ki(5),n=r.decode,o=r.encode,i=Mi(n);function s(u,p,h=90){We("bech32.encode prefix",u),Nn(p)&&(p=Array.from(p)),zi("bech32.encode",p);let b=u.length;if(b===0)throw new TypeError(`Invalid prefix length ${b}`);let x=b+7+p.length;if(h!==!1&&x>h)throw new TypeError(`Length ${x} exceeds limit ${h}`);let w=u.toLowerCase(),A=$i(w,p,e);return`${w}1${Tn.encode(p)}${A}`}function c(u,p=90){We("bech32.decode input",u);let h=u.length;if(h<8||p!==!1&&h>p)throw new TypeError(`invalid string length: ${h} (${u}). Expected (8..${p})`);let b=u.toLowerCase();if(u!==b&&u!==u.toUpperCase())throw new Error("String must be lowercase or uppercase");let x=b.lastIndexOf("1");if(x===0||x===-1)throw new Error('Letter "1" must be present between prefix and data only');let w=b.slice(0,x),A=b.slice(x+1);if(A.length<6)throw new Error("Data must be at least 6 characters long");let _=Tn.decode(A).slice(0,-6),C=$i(w,_,e);if(!A.endsWith(C))throw new Error(`Invalid checksum in ${u}: expected "${C}"`);return{prefix:w,words:_}}let a=Mi(c);function f(u){let{prefix:p,words:h}=c(u,!1);return{prefix:p,words:h,bytes:n(h)}}function l(u,p){return s(u,o(p))}return{encode:s,decode:c,encodeFromBytes:l,decodeToBytes:f,decodeUnsafe:a,fromWords:n,fromWordsUnsafe:i,toWords:o}}var St=Ta("bech32");var Xi=new TextEncoder,Na=new TextDecoder,Ji=1,Qi=65535;function cr(t){if(!Number.isSafeInteger(t)||t<1)throw new Error("expected positive integer");if(t<=32)return 32;let e=1<<Math.floor(Math.log2(t-1))+1,r=e<=256?32:e/8;return r*(Math.floor((t-1)/r)+1)}function _a(t){let e=Xi.encode(t),r=e.length;if(r<Ji||r>Qi)throw new Error("invalid plaintext length: must be between 1 and 65535 bytes");let n=new Uint8Array(2);new DataView(n.buffer).setUint16(0,r,!1);let o=new Uint8Array(cr(r)-r);return re(n,e,o)}function La(t){let e=new DataView(t.buffer,t.byteOffset).getUint16(0,!1),r=t.subarray(2,2+e);if(e<Ji||e>Qi||r.length!==e||t.length!==2+cr(e))throw new Error("invalid padding");return Na.decode(r)}function vt(t,e){let n=Ne.getSharedSecret(t,V("02"+e)).subarray(1,33);return Vi(Z,n,Xi.encode("nip44-v2"))}function es(t,e){let r=Fi(Z,t,e,76);return{chacha_key:r.subarray(0,32),chacha_nonce:r.subarray(32,44),hmac_key:r.subarray(44,76)}}function ar(t,e,r=oe(32)){let{chacha_key:n,chacha_nonce:o,hmac_key:i}=es(e,r),s=_a(t),c=nr(n,o,s),a=we(Z,i,re(r,c));return Ln.encode(re(new Uint8Array([2]),r,c,a))}function fr(t,e){let r=Ln.decode(t),n=r[0];if(n!==2)throw new Error(`unknown encryption version: ${n}`);if(r.length<99||r.length>65603)throw new Error("invalid payload size");let o=r.subarray(1,33),i=r.subarray(33,r.length-32),s=r.subarray(r.length-32),{chacha_key:c,chacha_nonce:a,hmac_key:f}=es(e,o),l=we(Z,f,re(o,i));if(!tr(s,l))throw new Error("invalid MAC");let u=nr(c,a,i);return La(u)}var Ca={utils:{getConversationKey:vt,calcPaddedLen:cr},encrypt:ar,decrypt:fr};var On={};ve(On,{connectRequest:()=>za,createBunkerURI:()=>Oa,createRequest:()=>Se,createResponse:()=>Fa,createResponseFilter:()=>ef,createSession:()=>Da,getPublicKeyRequest:()=>Wa,getRelaysRequest:()=>Qa,getSessionInfo:()=>Va,isRequest:()=>Ma,isResponse:()=>qa,nip04DecryptRequest:()=>Ka,nip04EncryptRequest:()=>Ya,nip44DecryptRequest:()=>Ja,nip44EncryptRequest:()=>Xa,parseBunkerURI:()=>ts,parsePayload:()=>rs,pingRequest:()=>Ga,restoreSession:()=>Ha,signEventRequest:()=>Za,unwrapEvent:()=>ja,validateBunkerURI:()=>Pa,wrapEvent:()=>$a});function ts(t){if(!t.startsWith("bunker://"))throw new Error("invalid bunker URI: must start with bunker://");let e=new URL(t.replace("bunker://","https://")),r=e.hostname;if(!/^[0-9a-f]{64}$/.test(r))throw new Error("invalid bunker URI: remote pubkey must be 64 hex characters");let n=e.searchParams.getAll("relay");if(n.length===0)throw new Error("invalid bunker URI: at least one relay is required");let o=e.searchParams.get("secret")||void 0;return{remotePubkey:r,relays:n,secret:o}}function Oa(t,e,r){if(!/^[0-9a-f]{64}$/.test(t))throw new Error("remotePubkey must be 64 hex characters");if(e.length===0)throw new Error("at least one relay is required");let n=e.map(o=>`relay=${encodeURIComponent(o)}`);return r&&n.push(`secret=${encodeURIComponent(r)}`),`bunker://${t}?${n.join("&")}`}function Pa(t){try{return{isValid:!0,uri:ts(t)}}catch(e){return{isValid:!1,error:e.message}}}function Da(t){if(!/^[0-9a-f]{64}$/.test(t))throw new Error("remotePubkey must be 64 hex characters");let e=oe(32),r=z(e),n=ie.getPublicKey(e),o=z(n),i=vt(e,t);return{clientSecretKey:r,clientPubkey:o,remotePubkey:t,conversationKey:i}}function Ha(t,e){let r=V(t),n=ie.getPublicKey(r),o=z(n),i=vt(r,e);return{clientSecretKey:t,clientPubkey:o,remotePubkey:e,conversationKey:i}}function Va(t){return{clientPubkey:t.clientPubkey,remotePubkey:t.remotePubkey}}function Se(t,e,r){return{id:r||z(oe(16)),method:t,params:e}}function Fa(t,e,r){let n={id:t};return e!==void 0&&(n.result=e),r!==void 0&&(n.error=r),n}function rs(t){let e=JSON.parse(t);if(typeof e.id!="string")throw new Error("invalid NIP-46 payload: missing id");return e}function Ma(t){return"method"in t&&"params"in t}function qa(t){return"result"in t||"error"in t}async function $a(t,e,r){let n=JSON.stringify(t),o=ar(n,e.conversationKey),s={kind:24133,created_at:Math.floor(Date.now()/1e3),tags:[["p",r]],content:o,pubkey:e.clientPubkey},c=JSON.stringify([0,s.pubkey,s.created_at,s.kind,s.tags,s.content]),a=Z(new TextEncoder().encode(c)),f=V(e.clientSecretKey),l=ie.sign(a,f);return{...s,id:z(a),sig:z(l)}}function ja(t,e){if(t.kind!==24133)throw new Error(`expected kind 24133, got ${t.kind}`);let r=fr(t.content,e.conversationKey);return rs(r)}function za(t,e,r){let n=[t];return e?n.push(e):r&&n.push(""),r&&n.push(r),Se("connect",n)}function Ga(){return Se("ping",[])}function Wa(){return Se("get_public_key",[])}function Za(t){return Se("sign_event",[t])}function Ya(t,e){return Se("nip04_encrypt",[t,e])}function Ka(t,e){return Se("nip04_decrypt",[t,e])}function Xa(t,e){return Se("nip44_encrypt",[t,e])}function Ja(t,e){return Se("nip44_decrypt",[t,e])}function Qa(){return Se("get_relays",[])}function ef(t,e){let r={kinds:[24133],"#p":[t]};return e!==void 0&&(r.since=e),r}var Vn={};ve(Vn,{decrypt:()=>af,encrypt:()=>cf});function rf(t,e,r,n){Ue(t);let o=kt({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:c}=o;if(Q(i,"c"),Q(s,"dkLen"),Q(c,"asyncTick"),i<1)throw new Error("iterations (c) must be >= 1");let a=hr(e,"password"),f=hr(r,"salt"),l=new Uint8Array(s),u=we.create(t,a),p=u._cloneInto().update(f);return{c:i,dkLen:s,asyncTick:c,DK:l,PRF:u,PRFSalt:p}}function nf(t,e,r,n,o){return t.destroy(),e.destroy(),n&&n.destroy(),pe(o),r}function Pn(t,e,r,n){let{c:o,dkLen:i,DK:s,PRF:c,PRFSalt:a}=rf(t,e,r,n),f,l=new Uint8Array(4),u=Ke(l),p=new Uint8Array(c.outputLen);for(let h=1,b=0;b<i;h++,b+=c.outputLen){let x=s.subarray(b,b+c.outputLen);u.setInt32(0,h,!1),(f=a._cloneInto(f)).update(l).digestInto(p),x.set(p.subarray(0,x.length));for(let w=1;w<o;w++){c._cloneInto(f).update(p).digestInto(p);for(let A=0;A<x.length;A++)x[A]^=p[A]}}return nf(c,a,s,f,p)}function ns(t,e,r,n,o,i){let s=t[e++]^r[n++],c=t[e++]^r[n++],a=t[e++]^r[n++],f=t[e++]^r[n++],l=t[e++]^r[n++],u=t[e++]^r[n++],p=t[e++]^r[n++],h=t[e++]^r[n++],b=t[e++]^r[n++],x=t[e++]^r[n++],w=t[e++]^r[n++],A=t[e++]^r[n++],_=t[e++]^r[n++],C=t[e++]^r[n++],H=t[e++]^r[n++],K=t[e++]^r[n++],O=s,$=c,W=a,P=f,M=l,F=u,N=p,T=h,d=b,y=x,E=w,B=A,S=_,m=C,v=H,I=K;for(let U=0;U<8;U+=2)M^=j(O+S|0,7),d^=j(M+O|0,9),S^=j(d+M|0,13),O^=j(S+d|0,18),y^=j(F+$|0,7),m^=j(y+F|0,9),$^=j(m+y|0,13),F^=j($+m|0,18),v^=j(E+N|0,7),W^=j(v+E|0,9),N^=j(W+v|0,13),E^=j(N+W|0,18),P^=j(I+B|0,7),T^=j(P+I|0,9),B^=j(T+P|0,13),I^=j(B+T|0,18),$^=j(O+P|0,7),W^=j($+O|0,9),P^=j(W+$|0,13),O^=j(P+W|0,18),N^=j(F+M|0,7),T^=j(N+F|0,9),M^=j(T+N|0,13),F^=j(M+T|0,18),B^=j(E+y|0,7),d^=j(B+E|0,9),y^=j(d+B|0,13),E^=j(y+d|0,18),S^=j(I+v|0,7),m^=j(S+I|0,9),v^=j(m+S|0,13),I^=j(v+m|0,18);o[i++]=s+O|0,o[i++]=c+$|0,o[i++]=a+W|0,o[i++]=f+P|0,o[i++]=l+M|0,o[i++]=u+F|0,o[i++]=p+N|0,o[i++]=h+T|0,o[i++]=b+d|0,o[i++]=x+y|0,o[i++]=w+E|0,o[i++]=A+B|0,o[i++]=_+S|0,o[i++]=C+m|0,o[i++]=H+v|0,o[i++]=K+I|0}function Dn(t,e,r,n,o){let i=n+0,s=n+16*o;for(let c=0;c<16;c++)r[s+c]=t[e+(2*o-1)*16+c];for(let c=0;c<o;c++,i+=16,e+=16)ns(r,s,t,e,r,i),c>0&&(s+=16),ns(r,i,t,e+=16,r,s)}function of(t,e,r){let n=kt({dkLen:32,asyncTick:10,maxmem:1073742848},r),{N:o,r:i,p:s,dkLen:c,asyncTick:a,maxmem:f,onProgress:l}=n;if(Q(o,"N"),Q(i,"r"),Q(s,"p"),Q(c,"dkLen"),Q(a,"asyncTick"),Q(f,"maxmem"),l!==void 0&&typeof l!="function")throw new Error("progressCb must be a function");let u=128*i,p=u/4,h=Math.pow(2,32);if(o<=1||(o&o-1)!==0||o>h)throw new Error('"N" expected a power of 2, and 2^1 <= N <= 2^32');if(s<1||s>(h-1)*32/u)throw new Error('"p" expected integer 1..((2^32 - 1) * 32) / (128 * r)');if(c<1||c>(h-1)*32)throw new Error('"dkLen" expected integer 1..(2^32 - 1) * 32');if(u*(o+s)>f)throw new Error('"maxmem" limit was hit, expected 128*r*(N+p) <= "maxmem"='+f);let x=Pn(Z,t,e,{c:1,dkLen:u*s}),w=Ut(x),A=Ut(new Uint8Array(u*o)),_=Ut(new Uint8Array(u)),C=()=>{};if(l){let H=2*o*s,K=Math.max(Math.floor(H/1e4),1),O=0;C=()=>{O++,l&&(!(O%K)||O===H)&&l(O/H)}}return{N:o,r:i,p:s,dkLen:c,blockSize32:p,V:A,B32:w,B:x,tmp:_,blockMixCb:C,asyncTick:a}}function sf(t,e,r,n,o){let i=Pn(Z,t,r,{c:1,dkLen:e});return pe(r,n,o),i}function Hn(t,e,r){let{N:n,r:o,p:i,dkLen:s,blockSize32:c,V:a,B32:f,B:l,tmp:u,blockMixCb:p}=of(t,e,r);dr(f);for(let h=0;h<i;h++){let b=c*h;for(let x=0;x<c;x++)a[x]=f[b+x];for(let x=0,w=0;x<n-1;x++)Dn(a,w,a,w+=c,o),p();Dn(a,(n-1)*c,f,b,o),p();for(let x=0;x<n;x++){let w=(f[b+c-16]&n-1)>>>0;for(let A=0;A<c;A++)u[A]=f[b+A]^a[w*c+A];Dn(u,0,f,b,o),p()}}return dr(f),sf(t,s,l,a,u)}function cf(t,e,r=16,n=2){let o=oe(16),i=2**r,s=e.normalize("NFKC"),c=Hn(s,o,{N:i,r:8,p:1,dkLen:32}),a=oe(24),f=Uint8Array.from([n]),u=vn(c,a,f).encrypt(t),p=re(Uint8Array.from([2]),Uint8Array.from([r]),o,a,f,u),h=St.toWords(p);return St.encode("ncryptsec",h,200)}function af(t,e){let{prefix:r,words:n}=St.decode(t,200);if(r!=="ncryptsec")throw new Error("invalid ncryptsec prefix");let o=new Uint8Array(St.fromWords(n)),i=o[0];if(i!==2)throw new Error(`unknown ncryptsec version: ${i}`);let s=o[1],c=o.subarray(2,18),a=o.subarray(18,42),f=o[42],l=o.subarray(43),u=2**s,p=e.normalize("NFKC"),h=Hn(p,c,{N:u,r:8,p:1,dkLen:32}),b=Uint8Array.from([f]);return vn(h,a,b).decrypt(l)}function os(t){let e=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)e[r/2]=parseInt(t.slice(r,r+2),16);return e}function is(t){return Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function ss(t){return new TextEncoder().encode(t)}function cs(t){return new TextDecoder().decode(t)}return ys(ff);})();
|
|
1
|
+
"use strict";var NostrCryptoUtils=(()=>{var us=Object.create;var ht=Object.defineProperty;var ls=Object.getOwnPropertyDescriptor;var ds=Object.getOwnPropertyNames;var hs=Object.getPrototypeOf,ps=Object.prototype.hasOwnProperty;var ys=(t,e,r)=>e in t?ht(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var gs=(t,e)=>()=>(t&&(e=t(t=0)),e);var Ze=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Re=(t,e)=>{for(var r in e)ht(t,r,{get:e[r],enumerable:!0})},jn=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ds(e))!ps.call(t,i)&&i!==r&&ht(t,i,{get:()=>e[i],enumerable:!(n=ls(e,i))||n.enumerable});return t};var lr=(t,e,r)=>(r=t!=null?us(hs(t)):{},jn(e||!t||!t.__esModule?ht(r,"default",{value:t,enumerable:!0}):r,t)),xs=t=>jn(ht({},"__esModule",{value:!0}),t);var R=(t,e,r)=>ys(t,typeof e!="symbol"?e+"":e,r);var _i=Ze((fu,Ni)=>{"use strict";function qs(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}Ni.exports=Ms;function Ms(t,e,r){var n=r&&r.stringify||qs,i=1;if(typeof t=="object"&&t!==null){var o=e.length+i;if(o===1)return t;var s=new Array(o);s[0]=n(t);for(var c=1;c<o;c++)s[c]=n(e[c]);return s.join(" ")}if(typeof t!="string")return t;var a=e.length;if(a===0)return t;for(var f="",l=1-i,u=-1,p=t&&t.length||0,h=0;h<p;){if(t.charCodeAt(h)===37&&h+1<p){switch(u=u>-1?u:0,t.charCodeAt(h+1)){case 100:case 102:if(l>=a||e[l]==null)break;u<h&&(f+=t.slice(u,h)),f+=Number(e[l]),u=h+2,h++;break;case 105:if(l>=a||e[l]==null)break;u<h&&(f+=t.slice(u,h)),f+=Math.floor(Number(e[l])),u=h+2,h++;break;case 79:case 111:case 106:if(l>=a||e[l]===void 0)break;u<h&&(f+=t.slice(u,h));var b=typeof e[l];if(b==="string"){f+="'"+e[l]+"'",u=h+2,h++;break}if(b==="function"){f+=e[l].name||"<anonymous>",u=h+2,h++;break}f+=n(e[l]),u=h+2,h++;break;case 115:if(l>=a)break;u<h&&(f+=t.slice(u,h)),f+=String(e[l]),u=h+2,h++;break;case 37:u<h&&(f+=t.slice(u,h)),f+="%",u=h+2,h++,l--;break}++l}++h}return u===-1?t:(u<p&&(f+=t.slice(u)),f)}});var Vi=Ze((uu,Gt)=>{"use strict";var Li=_i();Gt.exports=Le;var Bt=nc().console||{},$s={mapHttpRequest:zt,mapHttpResponse:zt,wrapRequestSerializer:Hr,wrapResponseSerializer:Hr,wrapErrorSerializer:Hr,req:zt,res:zt,err:Oi,errWithCause:Oi};function Fe(t,e){return t==="silent"?1/0:e.levels.values[t]}var qr=Symbol("pino.logFuncs"),Vr=Symbol("pino.hierarchy"),js={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function Ci(t,e){let r={logger:e,parent:t[Vr]};e[Vr]=r}function zs(t,e,r){let n={};e.forEach(i=>{n[i]=r[i]?r[i]:Bt[i]||Bt[js[i]||"log"]||rt}),t[qr]=n}function Gs(t,e){return Array.isArray(t)?t.filter(function(n){return n!=="!stdSerializers.err"}):t===!0?Object.keys(e):!1}function Le(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||Bt;t.browser.write&&(t.browser.asObject=!0);let n=t.serializers||{},i=Gs(t.browser.serialize,n),o=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(o=!1);let s=Object.keys(t.customLevels||{}),c=["error","fatal","warn","info","debug","trace"].concat(s);typeof r=="function"&&c.forEach(function(x){r[x]=r}),(t.enabled===!1||t.browser.disabled)&&(t.level="silent");let a=t.level||"info",f=Object.create(r);f.log||(f.log=rt),zs(f,c,r),Ci({},f),Object.defineProperty(f,"levelVal",{get:u}),Object.defineProperty(f,"level",{get:p,set:h});let l={transmit:e,serialize:i,asObject:t.browser.asObject,asObjectBindingsOnly:t.browser.asObjectBindingsOnly,formatters:t.browser.formatters,reportCaller:t.browser.reportCaller,levels:c,timestamp:ec(t),messageKey:t.messageKey||"msg",onChild:t.onChild||rt};f.levels=Ys(t),f.level=a,f.isLevelEnabled=function(x){return this.levels.values[x]?this.levels.values[x]>=this.levels.values[this.level]:!1},f.setMaxListeners=f.getMaxListeners=f.emit=f.addListener=f.on=f.prependListener=f.once=f.prependOnceListener=f.removeListener=f.removeAllListeners=f.listeners=f.listenerCount=f.eventNames=f.write=f.flush=rt,f.serializers=n,f._serialize=i,f._stdErrSerialize=o,f.child=function(...x){return b.call(this,l,...x)},e&&(f._logEvent=Fr());function u(){return Fe(this.level,this)}function p(){return this._level}function h(x){if(x!=="silent"&&!this.levels.values[x])throw Error("unknown level "+x);this._level=x,ze(this,l,f,"error"),ze(this,l,f,"fatal"),ze(this,l,f,"warn"),ze(this,l,f,"info"),ze(this,l,f,"debug"),ze(this,l,f,"trace"),s.forEach(w=>{ze(this,l,f,w)})}function b(x,w,A){if(!w)throw new Error("missing bindings for child Pino");A=A||{},i&&w.serializers&&(A.serializers=w.serializers);let _=A.serializers;if(i&&_){var C=Object.assign({},n,_),V=t.browser.serialize===!0?Object.keys(C):i;delete w.serializers,Mr([w],V,C,this._stdErrSerialize)}function Z(j){this._childLevel=(j._childLevel|0)+1,this.bindings=w,C&&(this.serializers=C,this._serialize=V),e&&(this._logEvent=Fr([].concat(j._logEvent.bindings,w)))}Z.prototype=this;let O=new Z(this);return Ci(this,O),O.child=function(...j){return b.call(this,x,...j)},O.level=A.level||this.level,x.onChild(O),O}return f}function Ys(t){let e=t.customLevels||{},r=Object.assign({},Le.levels.values,e),n=Object.assign({},Le.levels.labels,Ks(e));return{values:r,labels:n}}function Ks(t){let e={};return Object.keys(t).forEach(function(r){e[t[r]]=r}),e}Le.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"}};Le.stdSerializers=$s;Le.stdTimeFunctions=Object.assign({},{nullTime:Di,epochTime:Hi,unixTime:tc,isoTime:rc});function Ws(t){let e=[];t.bindings&&e.push(t.bindings);let r=t[Vr];for(;r.parent;)r=r.parent,r.logger.bindings&&e.push(r.logger.bindings);return e.reverse()}function ze(t,e,r,n){if(Object.defineProperty(t,n,{value:Fe(t.level,r)>Fe(n,r)?rt:r[qr][n],writable:!0,enumerable:!0,configurable:!0}),t[n]===rt){if(!e.transmit)return;let o=e.transmit.level||t.level,s=Fe(o,r);if(Fe(n,r)<s)return}t[n]=Xs(t,e,r,n);let i=Ws(t);i.length!==0&&(t[n]=Zs(i,t[n]))}function Zs(t,e){return function(){return e.apply(this,[...t,...arguments])}}function Xs(t,e,r,n){return(function(i){return function(){let s=e.timestamp(),c=new Array(arguments.length),a=Object.getPrototypeOf&&Object.getPrototypeOf(this)===Bt?Bt:this;for(var f=0;f<c.length;f++)c[f]=arguments[f];var l=!1;if(e.serialize&&(Mr(c,this._serialize,this.serializers,this._stdErrSerialize),l=!0),e.asObject||e.formatters){let u=Js(this,n,c,s,e);if(e.reportCaller&&u&&u.length>0&&u[0]&&typeof u[0]=="object")try{let p=Pi();p&&(u[0].caller=p)}catch{}i.call(a,...u)}else{if(e.reportCaller)try{let u=Pi();u&&c.push(u)}catch{}i.apply(a,c)}if(e.transmit){let u=e.transmit.level||t._level,p=Fe(u,r),h=Fe(n,r);if(h<p)return;Qs(this,{ts:s,methodLevel:n,methodValue:h,transmitLevel:u,transmitValue:r.levels.values[e.transmit.level||t._level],send:e.transmit.send,val:Fe(t._level,r)},c,l)}}})(t[qr][n])}function Js(t,e,r,n,i){let{level:o,log:s=u=>u}=i.formatters||{},c=r.slice(),a=c[0],f={},l=(t._childLevel|0)+1;if(l<1&&(l=1),n&&(f.time=n),o){let u=o(e,t.levels.values[e]);Object.assign(f,u)}else f.level=t.levels.values[e];if(i.asObjectBindingsOnly){if(a!==null&&typeof a=="object")for(;l--&&typeof c[0]=="object";)Object.assign(f,c.shift());return[s(f),...c]}else{if(a!==null&&typeof a=="object"){for(;l--&&typeof c[0]=="object";)Object.assign(f,c.shift());a=c.length?Li(c.shift(),c):void 0}else typeof a=="string"&&(a=Li(c.shift(),c));return a!==void 0&&(f[i.messageKey]=a),[s(f)]}}function Mr(t,e,r,n){for(let i in t)if(n&&t[i]instanceof Error)t[i]=Le.stdSerializers.err(t[i]);else if(typeof t[i]=="object"&&!Array.isArray(t[i])&&e)for(let o in t[i])e.indexOf(o)>-1&&o in r&&(t[i][o]=r[o](t[i][o]))}function Qs(t,e,r,n=!1){let i=e.send,o=e.ts,s=e.methodLevel,c=e.methodValue,a=e.val,f=t._logEvent.bindings;n||Mr(r,t._serialize||Object.keys(t.serializers),t.serializers,t._stdErrSerialize===void 0?!0:t._stdErrSerialize),t._logEvent.ts=o,t._logEvent.messages=r.filter(function(l){return f.indexOf(l)===-1}),t._logEvent.level.label=s,t._logEvent.level.value=c,i(s,t._logEvent,a),t._logEvent=Fr(f)}function Fr(t){return{ts:0,messages:[],bindings:t||[],level:{label:"",value:0}}}function Oi(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 ec(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?Di:Hi}function zt(){return{}}function Hr(t){return t}function rt(){}function Di(){return!1}function Hi(){return Date.now()}function tc(){return Math.round(Date.now()/1e3)}function rc(){return new Date(Date.now()).toISOString()}function nc(){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)||{}}}Gt.exports.default=Le;Gt.exports.pino=Le;function Pi(){let t=new Error().stack;if(!t)return null;let e=t.split(`
|
|
2
|
+
`);for(let r=1;r<e.length;r++){let n=e[r].trim();if(/(^at\s+)?(createWrap|LOG|set\s*\(|asObject|Object\.apply|Function\.apply)/.test(n)||n.indexOf("browser.js")!==-1||n.indexOf("node:internal")!==-1||n.indexOf("node_modules")!==-1)continue;let i=n.match(/\((.*?):(\d+):(\d+)\)/);if(i||(i=n.match(/at\s+(.*?):(\d+):(\d+)/)),i){let o=i[1],s=i[2],c=i[3];return o+":"+s+":"+c}}return null}});var $r={};Re($r,{default:()=>oc});var oc,jr=gs(()=>{oc={}});var so=Ze(st=>{"use strict";Object.defineProperty(st,"__esModule",{value:!0});st.bech32m=st.bech32=void 0;var Jt="qpzry9x8gf2tvdw0s3jn54khce6mua7l",io={};for(let t=0;t<Jt.length;t++){let e=Jt.charAt(t);io[e]=t}function ot(t){let e=t>>25;return(t&33554431)<<5^-(e>>0&1)&996825010^-(e>>1&1)&642813549^-(e>>2&1)&513874426^-(e>>3&1)&1027748829^-(e>>4&1)&705979059}function no(t){let e=1;for(let r=0;r<t.length;++r){let n=t.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+t+")";e=ot(e)^n>>5}e=ot(e);for(let r=0;r<t.length;++r){let n=t.charCodeAt(r);e=ot(e)^n&31}return e}function sn(t,e,r,n){let i=0,o=0,s=(1<<r)-1,c=[];for(let a=0;a<t.length;++a)for(i=i<<e|t[a],o+=e;o>=r;)o-=r,c.push(i>>o&s);if(n)o>0&&c.push(i<<r-o&s);else{if(o>=e)return"Excess padding";if(i<<r-o&s)return"Non-zero padding"}return c}function hc(t){return sn(t,8,5,!0)}function pc(t){let e=sn(t,5,8,!1);if(Array.isArray(e))return e}function yc(t){let e=sn(t,5,8,!1);if(Array.isArray(e))return e;throw new Error(e)}function oo(t){let e;t==="bech32"?e=1:e=734539939;function r(s,c,a){if(a=a||90,s.length+7+c.length>a)throw new TypeError("Exceeds length limit");s=s.toLowerCase();let f=no(s);if(typeof f=="string")throw new Error(f);let l=s+"1";for(let u=0;u<c.length;++u){let p=c[u];if(p>>5!==0)throw new Error("Non 5-bit word");f=ot(f)^p,l+=Jt.charAt(p)}for(let u=0;u<6;++u)f=ot(f);f^=e;for(let u=0;u<6;++u){let p=f>>(5-u)*5&31;l+=Jt.charAt(p)}return l}function n(s,c){if(c=c||90,s.length<8)return s+" too short";if(s.length>c)return"Exceeds length limit";let a=s.toLowerCase(),f=s.toUpperCase();if(s!==a&&s!==f)return"Mixed-case string "+s;s=a;let l=s.lastIndexOf("1");if(l===-1)return"No separator character for "+s;if(l===0)return"Missing prefix for "+s;let u=s.slice(0,l),p=s.slice(l+1);if(p.length<6)return"Data too short";let h=no(u);if(typeof h=="string")return h;let b=[];for(let x=0;x<p.length;++x){let w=p.charAt(x),A=io[w];if(A===void 0)return"Unknown character "+w;h=ot(h)^A,!(x+6>=p.length)&&b.push(A)}return h!==e?"Invalid checksum for "+s:{prefix:u,words:b}}function i(s,c){let a=n(s,c);if(typeof a=="object")return a}function o(s,c){let a=n(s,c);if(typeof a=="object")return a;throw new Error(a)}return{decodeUnsafe:i,decode:o,encode:r,toWords:hc,fromWordsUnsafe:pc,fromWords:yc}}st.bech32=oo("bech32");st.bech32m=oo("bech32m")});var fo=Ze(Qt=>{"use strict";Qt.byteLength=xc;Qt.toByteArray=mc;Qt.fromByteArray=Bc;var Be=[],xe=[],gc=typeof Uint8Array<"u"?Uint8Array:Array,cn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Ge=0,co=cn.length;Ge<co;++Ge)Be[Ge]=cn[Ge],xe[cn.charCodeAt(Ge)]=Ge;var Ge,co;xe[45]=62;xe[95]=63;function ao(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 xc(t){var e=ao(t),r=e[0],n=e[1];return(r+n)*3/4-n}function bc(t,e,r){return(e+r)*3/4-r}function mc(t){var e,r=ao(t),n=r[0],i=r[1],o=new gc(bc(t,n,i)),s=0,c=i>0?n-4:n,a;for(a=0;a<c;a+=4)e=xe[t.charCodeAt(a)]<<18|xe[t.charCodeAt(a+1)]<<12|xe[t.charCodeAt(a+2)]<<6|xe[t.charCodeAt(a+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=xe[t.charCodeAt(a)]<<2|xe[t.charCodeAt(a+1)]>>4,o[s++]=e&255),i===1&&(e=xe[t.charCodeAt(a)]<<10|xe[t.charCodeAt(a+1)]<<4|xe[t.charCodeAt(a+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function wc(t){return Be[t>>18&63]+Be[t>>12&63]+Be[t>>6&63]+Be[t&63]}function Ec(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(wc(n));return i.join("")}function Bc(t){for(var e,r=t.length,n=r%3,i=[],o=16383,s=0,c=r-n;s<c;s+=o)i.push(Ec(t,s,s+o>c?c:s+o));return n===1?(e=t[r-1],i.push(Be[e>>2]+Be[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(Be[e>>10]+Be[e>>4&63]+Be[e<<2&63]+"=")),i.join("")}});var uo=Ze(an=>{an.read=function(t,e,r,n,i){var o,s,c=i*8-n-1,a=(1<<c)-1,f=a>>1,l=-7,u=r?i-1:0,p=r?-1:1,h=t[e+u];for(u+=p,o=h&(1<<-l)-1,h>>=-l,l+=c;l>0;o=o*256+t[e+u],u+=p,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=n;l>0;s=s*256+t[e+u],u+=p,l-=8);if(o===0)o=1-f;else{if(o===a)return s?NaN:(h?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-f}return(h?-1:1)*s*Math.pow(2,o-n)};an.write=function(t,e,r,n,i,o){var s,c,a,f=o*8-i-1,l=(1<<f)-1,u=l>>1,p=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:o-1,b=n?1:-1,x=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(c=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-s))<1&&(s--,a*=2),s+u>=1?e+=p/a:e+=p*Math.pow(2,1-u),e*a>=2&&(s++,a/=2),s+u>=l?(c=0,s=l):s+u>=1?(c=(e*a-1)*Math.pow(2,i),s=s+u):(c=e*Math.pow(2,u-1)*Math.pow(2,i),s=0));i>=8;t[r+h]=c&255,h+=b,c/=256,i-=8);for(s=s<<i|c,f+=i;f>0;t[r+h]=s&255,h+=b,s/=256,f-=8);t[r+h-b]|=x*128}});var ko=Ze(ut=>{"use strict";var fn=fo(),at=uo(),lo=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;ut.Buffer=g;ut.SlowBuffer=kc;ut.INSPECT_MAX_BYTES=50;var er=2147483647;ut.kMaxLength=er;g.TYPED_ARRAY_SUPPORT=Ac();!g.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 Ac(){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(g.prototype,"parent",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.buffer}});Object.defineProperty(g.prototype,"offset",{enumerable:!0,get:function(){if(g.isBuffer(this))return this.byteOffset}});function Ce(t){if(t>er)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,g.prototype),e}function g(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 hn(t)}return go(t,e,r)}g.poolSize=8192;function go(t,e,r){if(typeof t=="string")return Sc(t,e);if(ArrayBuffer.isView(t))return vc(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(Ae(t,ArrayBuffer)||t&&Ae(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Ae(t,SharedArrayBuffer)||t&&Ae(t.buffer,SharedArrayBuffer)))return ln(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 g.from(n,e,r);let i=Rc(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return g.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)}g.from=function(t,e,r){return go(t,e,r)};Object.setPrototypeOf(g.prototype,Uint8Array.prototype);Object.setPrototypeOf(g,Uint8Array);function xo(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 Ic(t,e,r){return xo(t),t<=0?Ce(t):e!==void 0?typeof r=="string"?Ce(t).fill(e,r):Ce(t).fill(e):Ce(t)}g.alloc=function(t,e,r){return Ic(t,e,r)};function hn(t){return xo(t),Ce(t<0?0:pn(t)|0)}g.allocUnsafe=function(t){return hn(t)};g.allocUnsafeSlow=function(t){return hn(t)};function Sc(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!g.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let r=bo(t,e)|0,n=Ce(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function un(t){let e=t.length<0?0:pn(t.length)|0,r=Ce(e);for(let n=0;n<e;n+=1)r[n]=t[n]&255;return r}function vc(t){if(Ae(t,Uint8Array)){let e=new Uint8Array(t);return ln(e.buffer,e.byteOffset,e.byteLength)}return un(t)}function ln(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,g.prototype),n}function Rc(t){if(g.isBuffer(t)){let e=pn(t.length)|0,r=Ce(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||gn(t.length)?Ce(0):un(t);if(t.type==="Buffer"&&Array.isArray(t.data))return un(t.data)}function pn(t){if(t>=er)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+er.toString(16)+" bytes");return t|0}function kc(t){return+t!=t&&(t=0),g.alloc(+t)}g.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==g.prototype};g.compare=function(e,r){if(Ae(e,Uint8Array)&&(e=g.from(e,e.offset,e.byteLength)),Ae(r,Uint8Array)&&(r=g.from(r,r.offset,r.byteLength)),!g.isBuffer(e)||!g.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;let n=e.length,i=r.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};g.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}};g.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return g.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;let i=g.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){let s=e[n];if(Ae(s,Uint8Array))o+s.length>i.length?(g.isBuffer(s)||(s=g.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(g.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function bo(t,e){if(g.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Ae(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return dn(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Ro(t).length;default:if(i)return n?-1:dn(t).length;e=(""+e).toLowerCase(),i=!0}}g.byteLength=bo;function Uc(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 Vc(this,e,r);case"utf8":case"utf-8":return wo(this,e,r);case"ascii":return Dc(this,e,r);case"latin1":case"binary":return Hc(this,e,r);case"base64":return Oc(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Fc(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}g.prototype._isBuffer=!0;function Ye(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}g.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)Ye(this,r,r+1);return this};g.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)Ye(this,r,r+3),Ye(this,r+1,r+2);return this};g.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)Ye(this,r,r+7),Ye(this,r+1,r+6),Ye(this,r+2,r+5),Ye(this,r+3,r+4);return this};g.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?wo(this,0,e):Uc.apply(this,arguments)};g.prototype.toLocaleString=g.prototype.toString;g.prototype.equals=function(e){if(!g.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:g.compare(this,e)===0};g.prototype.inspect=function(){let e="",r=ut.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};lo&&(g.prototype[lo]=g.prototype.inspect);g.prototype.compare=function(e,r,n,i,o){if(Ae(e,Uint8Array)&&(e=g.from(e,e.offset,e.byteLength)),!g.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,c=n-r,a=Math.min(s,c),f=this.slice(i,o),l=e.slice(r,n);for(let u=0;u<a;++u)if(f[u]!==l[u]){s=f[u],c=l[u];break}return s<c?-1:c<s?1:0};function mo(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,gn(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=g.from(e,n)),g.isBuffer(e))return e.length===0?-1:ho(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):ho(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function ho(t,e,r,n,i){let o=1,s=t.length,c=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,c/=2,r/=2}function a(l,u){return o===1?l[u]:l.readUInt16BE(u*o)}let f;if(i){let l=-1;for(f=r;f<s;f++)if(a(t,f)===a(e,l===-1?0:f-l)){if(l===-1&&(l=f),f-l+1===c)return l*o}else l!==-1&&(f-=f-l),l=-1}else for(r+c>s&&(r=s-c),f=r;f>=0;f--){let l=!0;for(let u=0;u<c;u++)if(a(t,f+u)!==a(e,u)){l=!1;break}if(l)return f}return-1}g.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};g.prototype.indexOf=function(e,r,n){return mo(this,e,r,n,!0)};g.prototype.lastIndexOf=function(e,r,n){return mo(this,e,r,n,!1)};function Tc(t,e,r,n){r=Number(r)||0;let i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let c=parseInt(e.substr(s*2,2),16);if(gn(c))return s;t[r+s]=c}return s}function Nc(t,e,r,n){return tr(dn(e,t.length-r),t,r,n)}function _c(t,e,r,n){return tr(jc(e),t,r,n)}function Lc(t,e,r,n){return tr(Ro(e),t,r,n)}function Cc(t,e,r,n){return tr(zc(e,t.length-r),t,r,n)}g.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return Tc(this,e,r,n);case"utf8":case"utf-8":return Nc(this,e,r,n);case"ascii":case"latin1":case"binary":return _c(this,e,r,n);case"base64":return Lc(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Cc(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Oc(t,e,r){return e===0&&r===t.length?fn.fromByteArray(t):fn.fromByteArray(t.slice(e,r))}function wo(t,e,r){r=Math.min(t.length,r);let n=[],i=e;for(;i<r;){let o=t[i],s=null,c=o>239?4:o>223?3:o>191?2:1;if(i+c<=r){let a,f,l,u;switch(c){case 1:o<128&&(s=o);break;case 2:a=t[i+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(s=u));break;case 3:a=t[i+1],f=t[i+2],(a&192)===128&&(f&192)===128&&(u=(o&15)<<12|(a&63)<<6|f&63,u>2047&&(u<55296||u>57343)&&(s=u));break;case 4:a=t[i+1],f=t[i+2],l=t[i+3],(a&192)===128&&(f&192)===128&&(l&192)===128&&(u=(o&15)<<18|(a&63)<<12|(f&63)<<6|l&63,u>65535&&u<1114112&&(s=u))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=c}return Pc(n)}var po=4096;function Pc(t){let e=t.length;if(e<=po)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=po));return r}function Dc(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function Hc(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function Vc(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=e;o<r;++o)i+=Gc[t[o]];return i}function Fc(t,e,r){let n=t.slice(e,r),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}g.prototype.slice=function(e,r){let n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);let i=this.subarray(e,r);return Object.setPrototypeOf(i,g.prototype),i};function ce(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")}g.prototype.readUintLE=g.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||ce(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return i};g.prototype.readUintBE=g.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||ce(e,r,this.length);let i=this[e+--r],o=1;for(;r>0&&(o*=256);)i+=this[e+--r]*o;return i};g.prototype.readUint8=g.prototype.readUInt8=function(e,r){return e=e>>>0,r||ce(e,1,this.length),this[e]};g.prototype.readUint16LE=g.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||ce(e,2,this.length),this[e]|this[e+1]<<8};g.prototype.readUint16BE=g.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||ce(e,2,this.length),this[e]<<8|this[e+1]};g.prototype.readUint32LE=g.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||ce(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};g.prototype.readUint32BE=g.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||ce(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};g.prototype.readBigUInt64LE=qe(function(e){e=e>>>0,ft(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&St(e,this.length-8);let i=r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});g.prototype.readBigUInt64BE=qe(function(e){e=e>>>0,ft(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&St(e,this.length-8);let i=r*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});g.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||ce(e,r,this.length);let i=this[e],o=1,s=0;for(;++s<r&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};g.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||ce(e,r,this.length);let i=r,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*r)),s};g.prototype.readInt8=function(e,r){return e=e>>>0,r||ce(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};g.prototype.readInt16LE=function(e,r){e=e>>>0,r||ce(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};g.prototype.readInt16BE=function(e,r){e=e>>>0,r||ce(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};g.prototype.readInt32LE=function(e,r){return e=e>>>0,r||ce(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};g.prototype.readInt32BE=function(e,r){return e=e>>>0,r||ce(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};g.prototype.readBigInt64LE=qe(function(e){e=e>>>0,ft(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&St(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(r+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});g.prototype.readBigInt64BE=qe(function(e){e=e>>>0,ft(e,"offset");let r=this[e],n=this[e+7];(r===void 0||n===void 0)&&St(e,this.length-8);let i=(r<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});g.prototype.readFloatLE=function(e,r){return e=e>>>0,r||ce(e,4,this.length),at.read(this,e,!0,23,4)};g.prototype.readFloatBE=function(e,r){return e=e>>>0,r||ce(e,4,this.length),at.read(this,e,!1,23,4)};g.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||ce(e,8,this.length),at.read(this,e,!0,52,8)};g.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||ce(e,8,this.length),at.read(this,e,!1,52,8)};function pe(t,e,r,n,i,o){if(!g.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}g.prototype.writeUintLE=g.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;pe(this,e,r,n,c,0)}let o=1,s=0;for(this[r]=e&255;++s<n&&(o*=256);)this[r+s]=e/o&255;return r+n};g.prototype.writeUintBE=g.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){let c=Math.pow(2,8*n)-1;pe(this,e,r,n,c,0)}let o=n-1,s=1;for(this[r+o]=e&255;--o>=0&&(s*=256);)this[r+o]=e/s&255;return r+n};g.prototype.writeUint8=g.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||pe(this,e,r,1,255,0),this[r]=e&255,r+1};g.prototype.writeUint16LE=g.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||pe(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};g.prototype.writeUint16BE=g.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||pe(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};g.prototype.writeUint32LE=g.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||pe(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};g.prototype.writeUint32BE=g.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||pe(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 Eo(t,e,r,n,i){vo(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o,o=o>>8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,s=s>>8,t[r++]=s,r}function Bo(t,e,r,n,i){vo(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o=o>>8,t[r+6]=o,o=o>>8,t[r+5]=o,o=o>>8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s=s>>8,t[r+2]=s,s=s>>8,t[r+1]=s,s=s>>8,t[r]=s,r+8}g.prototype.writeBigUInt64LE=qe(function(e,r=0){return Eo(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeBigUInt64BE=qe(function(e,r=0){return Bo(this,e,r,BigInt(0),BigInt("0xffffffffffffffff"))});g.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let a=Math.pow(2,8*n-1);pe(this,e,r,n,a-1,-a)}let o=0,s=1,c=0;for(this[r]=e&255;++o<n&&(s*=256);)e<0&&c===0&&this[r+o-1]!==0&&(c=1),this[r+o]=(e/s>>0)-c&255;return r+n};g.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){let a=Math.pow(2,8*n-1);pe(this,e,r,n,a-1,-a)}let o=n-1,s=1,c=0;for(this[r+o]=e&255;--o>=0&&(s*=256);)e<0&&c===0&&this[r+o+1]!==0&&(c=1),this[r+o]=(e/s>>0)-c&255;return r+n};g.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||pe(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};g.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||pe(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};g.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||pe(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};g.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||pe(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};g.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||pe(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};g.prototype.writeBigInt64LE=qe(function(e,r=0){return Eo(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});g.prototype.writeBigInt64BE=qe(function(e,r=0){return Bo(this,e,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ao(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Io(t,e,r,n,i){return e=+e,r=r>>>0,i||Ao(t,e,r,4,34028234663852886e22,-34028234663852886e22),at.write(t,e,r,n,23,4),r+4}g.prototype.writeFloatLE=function(e,r,n){return Io(this,e,r,!0,n)};g.prototype.writeFloatBE=function(e,r,n){return Io(this,e,r,!1,n)};function So(t,e,r,n,i){return e=+e,r=r>>>0,i||Ao(t,e,r,8,17976931348623157e292,-17976931348623157e292),at.write(t,e,r,n,52,8),r+8}g.prototype.writeDoubleLE=function(e,r,n){return So(this,e,r,!0,n)};g.prototype.writeDoubleBE=function(e,r,n){return So(this,e,r,!1,n)};g.prototype.copy=function(e,r,n,i){if(!g.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};g.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!g.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=r;o<n;++o)this[o]=e;else{let s=g.isBuffer(e)?e:g.from(e,i),c=s.length;if(c===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-r;++o)this[o+r]=s[o%c]}return this};var ct={};function yn(t,e,r){ct[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}yn("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);yn("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);yn("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=yo(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=yo(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function yo(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 qc(t,e,r){ft(e,"offset"),(t[e]===void 0||t[e+r]===void 0)&&St(e,t.length-(r+1))}function vo(t,e,r,n,i,o){if(t>r||t<e){let s=typeof e=="bigint"?"n":"",c;throw o>3?e===0||e===BigInt(0)?c=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:c=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:c=`>= ${e}${s} and <= ${r}${s}`,new ct.ERR_OUT_OF_RANGE("value",c,t)}qc(n,i,o)}function ft(t,e){if(typeof t!="number")throw new ct.ERR_INVALID_ARG_TYPE(e,"number",t)}function St(t,e,r){throw Math.floor(t)!==t?(ft(t,r),new ct.ERR_OUT_OF_RANGE(r||"offset","an integer",t)):e<0?new ct.ERR_BUFFER_OUT_OF_BOUNDS:new ct.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}var Mc=/[^+/0-9A-Za-z-_]/g;function $c(t){if(t=t.split("=")[0],t=t.trim().replace(Mc,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function dn(t,e){e=e||1/0;let r,n=t.length,i=null,o=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function jc(t){let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function zc(t,e){let r,n,i,o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Ro(t){return fn.toByteArray($c(t))}function tr(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function Ae(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function gn(t){return t!==t}var Gc=(function(){let t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e})();function qe(t){return typeof BigInt>"u"?Yc:t}function Yc(){throw new Error("BigInt not supported")}});var hf={};Re(hf,{Nip46Method:()=>Tt,NostrEventKind:()=>dr,NostrMessageType:()=>pt,bytesToHex:()=>cs,bytesToUtf8:()=>fs,calculateEventId:()=>Xr,computeSharedSecret:()=>tn,createEvent:()=>zi,decrypt:()=>Wi,decryptMessage:()=>en,encrypt:()=>Ki,encryptMessage:()=>Qr,finalizeEvent:()=>Gi,generateKeyPair:()=>$i,getPublicKey:()=>Kt,getPublicKeySync:()=>Yr,hexToBytes:()=>ss,nip01:()=>on,nip04:()=>rn,nip19:()=>bn,nip26:()=>wn,nip44:()=>On,nip46:()=>Dn,nip49:()=>qn,signEvent:()=>Gr,utf8ToBytes:()=>as,validateEvent:()=>Xi,validateEventBase:()=>Zt,validateEventId:()=>Kr,validateEventSignature:()=>Wr,validateFilter:()=>Xt,validateKeyPair:()=>ji,validateResponse:()=>Qi,validateSignedEvent:()=>Wt,validateSubscription:()=>Ji,verifySignature:()=>Yi});var pt=(c=>(c.EVENT="EVENT",c.NOTICE="NOTICE",c.OK="OK",c.EOSE="EOSE",c.REQ="REQ",c.CLOSE="CLOSE",c.AUTH="AUTH",c))(pt||{});var Tt=(f=>(f.CONNECT="connect",f.PING="ping",f.GET_PUBLIC_KEY="get_public_key",f.SIGN_EVENT="sign_event",f.NIP04_ENCRYPT="nip04_encrypt",f.NIP04_DECRYPT="nip04_decrypt",f.NIP44_ENCRYPT="nip44_encrypt",f.NIP44_DECRYPT="nip44_decrypt",f.GET_RELAYS="get_relays",f))(Tt||{});var dr=(d=>(d[d.SET_METADATA=0]="SET_METADATA",d[d.TEXT_NOTE=1]="TEXT_NOTE",d[d.RECOMMEND_SERVER=2]="RECOMMEND_SERVER",d[d.CONTACT_LIST=3]="CONTACT_LIST",d[d.ENCRYPTED_DIRECT_MESSAGE=4]="ENCRYPTED_DIRECT_MESSAGE",d[d.DELETE=5]="DELETE",d[d.REPOST=6]="REPOST",d[d.REACTION=7]="REACTION",d[d.BADGE_AWARD=8]="BADGE_AWARD",d[d.CHANNEL_CREATE=40]="CHANNEL_CREATE",d[d.CHANNEL_METADATA=41]="CHANNEL_METADATA",d[d.CHANNEL_MESSAGE=42]="CHANNEL_MESSAGE",d[d.CHANNEL_HIDE_MESSAGE=43]="CHANNEL_HIDE_MESSAGE",d[d.CHANNEL_MUTE_USER=44]="CHANNEL_MUTE_USER",d[d.CHANNEL_RESERVE=45]="CHANNEL_RESERVE",d[d.REPORTING=1984]="REPORTING",d[d.ZAP_REQUEST=9734]="ZAP_REQUEST",d[d.ZAP=9735]="ZAP",d[d.MUTE_LIST=1e4]="MUTE_LIST",d[d.PIN_LIST=10001]="PIN_LIST",d[d.RELAY_LIST_METADATA=10002]="RELAY_LIST_METADATA",d[d.CLIENT_AUTH=22242]="CLIENT_AUTH",d[d.AUTH_RESPONSE=22243]="AUTH_RESPONSE",d[d.NOSTR_CONNECT=24133]="NOSTR_CONNECT",d[d.CATEGORIZED_PEOPLE=3e4]="CATEGORIZED_PEOPLE",d[d.CATEGORIZED_BOOKMARKS=30001]="CATEGORIZED_BOOKMARKS",d[d.PROFILE_BADGES=30008]="PROFILE_BADGES",d[d.BADGE_DEFINITION=30009]="BADGE_DEFINITION",d[d.LONG_FORM=30023]="LONG_FORM",d[d.APPLICATION_SPECIFIC=30078]="APPLICATION_SPECIFIC",d))(dr||{});function yt(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Q(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function M(t,e,r=""){let n=yt(t),i=t?.length,o=e!==void 0;if(!n||o&&i!==e){let s=r&&`"${r}" `,c=o?` of length ${e}`:"",a=n?`length=${i}`:`type=${typeof t}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return t}function Ue(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Q(t.outputLen),Q(t.blockLen)}function Xe(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 Gn(t,e){M(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Nt(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function ye(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Je(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function me(t,e){return t<<32-e|t>>>e}function z(t,e){return t<<e|t>>>32-e>>>0}var bs=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ms(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function ws(t){for(let e=0;e<t.length;e++)t[e]=ms(t[e]);return t}var hr=bs?t=>t:ws,Yn=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Es=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function $(t){if(M(t),Yn)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Es[t[r]];return e}var ke={_0:48,_9:57,A:65,F:70,a:97,f:102};function zn(t){if(t>=ke._0&&t<=ke._9)return t-ke._0;if(t>=ke.A&&t<=ke.F)return t-(ke.A-10);if(t>=ke.a&&t<=ke.f)return t-(ke.a-10)}function H(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Yn)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 i=0,o=0;i<r;i++,o+=2){let s=zn(t.charCodeAt(o)),c=zn(t.charCodeAt(o+1));if(s===void 0||c===void 0){let a=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[i]=s*16+c}return n}function Bs(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function pr(t,e=""){return typeof t=="string"?Bs(t):M(t,void 0,e)}function re(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];M(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}function _t(t,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("options must be object or undefined");return Object.assign(t,e)}function Kn(t,e={}){let r=(i,o)=>t(o).update(i).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=i=>t(i),Object.assign(r,e),Object.freeze(r)}function se(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var Wn=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Zn(t,e,r){return t&e^~t&r}function Xn(t,e,r){return t&e^t&r^e&r}var Lt=class{constructor(e,r,n,i){R(this,"blockLen");R(this,"outputLen");R(this,"padOffset");R(this,"isLE");R(this,"buffer");R(this,"view");R(this,"finished",!1);R(this,"length",0);R(this,"pos",0);R(this,"destroyed",!1);this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=Je(this.buffer)}update(e){Xe(this),M(e);let{view:r,buffer:n,blockLen:i}=this,o=e.length;for(let s=0;s<o;){let c=Math.min(i-this.pos,o-s);if(c===i){let a=Je(e);for(;i<=o-s;s+=i)this.process(a,s);continue}n.set(e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Xe(this),Gn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,ye(this.buffer.subarray(s)),this.padOffset>i-s&&(this.process(n,0),s=0);for(let u=s;u<i;u++)r[u]=0;n.setBigUint64(i-8,BigInt(this.length*8),o),this.process(n,0);let c=Je(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=a/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)c.setUint32(4*u,l[u],o)}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:i,finished:o,destroyed:s,pos:c}=this;return e.destroyed=s,e.finished=o,e.length=i,e.pos=c,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Te=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var As=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]),De=new Uint32Array(64),yr=class extends Lt{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:c,H:a}=this;return[e,r,n,i,o,s,c,a]}set(e,r,n,i,o,s,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=c|0,this.H=a|0}process(e,r){for(let u=0;u<16;u++,r+=4)De[u]=e.getUint32(r,!1);for(let u=16;u<64;u++){let p=De[u-15],h=De[u-2],b=me(p,7)^me(p,18)^p>>>3,x=me(h,17)^me(h,19)^h>>>10;De[u]=x+De[u-7]+b+De[u-16]|0}let{A:n,B:i,C:o,D:s,E:c,F:a,G:f,H:l}=this;for(let u=0;u<64;u++){let p=me(c,6)^me(c,11)^me(c,25),h=l+p+Zn(c,a,f)+As[u]+De[u]|0,x=(me(n,2)^me(n,13)^me(n,22))+Xn(n,i,o)|0;l=f,f=a,a=c,c=s+h|0,s=o,o=i,i=n,n=h+x|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(n,i,o,s,c,a,f,l)}roundClean(){ye(De)}destroy(){this.set(0,0,0,0,0,0,0,0),ye(this.buffer)}},gr=class extends yr{constructor(){super(32);R(this,"A",Te[0]|0);R(this,"B",Te[1]|0);R(this,"C",Te[2]|0);R(this,"D",Te[3]|0);R(this,"E",Te[4]|0);R(this,"F",Te[5]|0);R(this,"G",Te[6]|0);R(this,"H",Te[7]|0)}};var K=Kn(()=>new gr,Wn(1));var br=BigInt(0),xr=BigInt(1);function gt(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Jn(t){if(typeof t=="bigint"){if(!Ct(t))throw new Error("positive bigint expected, got "+t)}else Q(t);return t}function xt(t){let e=Jn(t).toString(16);return e.length&1?"0"+e:e}function Qn(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?br:BigInt("0x"+t)}function He(t){return Qn($(t))}function mr(t){return Qn($(Is(M(t)).reverse()))}function Ot(t,e){Q(e),t=Jn(t);let r=H(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function wr(t,e){return Ot(t,e).reverse()}function Is(t){return Uint8Array.from(t)}function ei(t){return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new Error(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Ct=t=>typeof t=="bigint"&&br<=t;function Ss(t,e,r){return Ct(t)&&Ct(e)&&Ct(r)&&e<=t&&t<r}function ti(t,e,r,n){if(!Ss(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Er(t){let e;for(e=0;t>br;t>>=xr,e+=1);return e}var bt=t=>(xr<<BigInt(t))-xr;function ri(t,e,r){if(Q(t,"hashLen"),Q(e,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=w=>new Uint8Array(w),i=Uint8Array.of(),o=Uint8Array.of(0),s=Uint8Array.of(1),c=1e3,a=n(t),f=n(t),l=0,u=()=>{a.fill(1),f.fill(0),l=0},p=(...w)=>r(f,re(a,...w)),h=(w=i)=>{f=p(o,w),a=p(),w.length!==0&&(f=p(s,w),a=p())},b=()=>{if(l++>=c)throw new Error("drbg: tried max amount of iterations");let w=0,A=[];for(;w<e;){a=p();let _=a.slice();A.push(_),w+=a.length}return re(...A)};return(w,A)=>{u(),h(w);let _;for(;!(_=A(b()));)h();return u(),_}}function mt(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(o,s,c){let a=t[o];if(c&&a===void 0)return;let f=typeof a;if(f!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${f}`)}let i=(o,s)=>Object.entries(o).forEach(([c,a])=>n(c,a,s));i(e,!1),i(r,!0)}function Br(t){let e=new WeakMap;return(r,...n)=>{let i=e.get(r);if(i!==void 0)return i;let o=t(r,...n);return e.set(r,o),o}}var de=BigInt(0),ue=BigInt(1),Me=BigInt(2),oi=BigInt(3),si=BigInt(4),ci=BigInt(5),vs=BigInt(7),ai=BigInt(8),Rs=BigInt(9),fi=BigInt(16);function we(t,e){let r=t%e;return r>=de?r:e+r}function ge(t,e,r){let n=t;for(;e-- >de;)n*=n,n%=r;return n}function ni(t,e){if(t===de)throw new Error("invert: expected non-zero number");if(e<=de)throw new Error("invert: expected positive modulus, got "+e);let r=we(t,e),n=e,i=de,o=ue,s=ue,c=de;for(;r!==de;){let f=n/r,l=n%r,u=i-s*f,p=o-c*f;n=r,r=l,i=s,o=c,s=u,c=p}if(n!==ue)throw new Error("invert: does not exist");return we(i,e)}function Ir(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function ui(t,e){let r=(t.ORDER+ue)/si,n=t.pow(e,r);return Ir(t,n,e),n}function ks(t,e){let r=(t.ORDER-ci)/ai,n=t.mul(e,Me),i=t.pow(n,r),o=t.mul(e,i),s=t.mul(t.mul(o,Me),i),c=t.mul(o,t.sub(s,t.ONE));return Ir(t,c,e),c}function Us(t){let e=Qe(t),r=li(t),n=r(e,e.neg(e.ONE)),i=r(e,n),o=r(e,e.neg(n)),s=(t+vs)/fi;return(c,a)=>{let f=c.pow(a,s),l=c.mul(f,n),u=c.mul(f,i),p=c.mul(f,o),h=c.eql(c.sqr(l),a),b=c.eql(c.sqr(u),a);f=c.cmov(f,l,h),l=c.cmov(p,u,b);let x=c.eql(c.sqr(l),a),w=c.cmov(f,l,x);return Ir(c,w,a),w}}function li(t){if(t<oi)throw new Error("sqrt is not defined for small field");let e=t-ue,r=0;for(;e%Me===de;)e/=Me,r++;let n=Me,i=Qe(t);for(;ii(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ui;let o=i.pow(n,e),s=(e+ue)/Me;return function(a,f){if(a.is0(f))return f;if(ii(a,f)!==1)throw new Error("Cannot find square root");let l=r,u=a.mul(a.ONE,o),p=a.pow(f,e),h=a.pow(f,s);for(;!a.eql(p,a.ONE);){if(a.is0(p))return a.ZERO;let b=1,x=a.sqr(p);for(;!a.eql(x,a.ONE);)if(b++,x=a.sqr(x),b===l)throw new Error("Cannot find square root");let w=ue<<BigInt(l-b-1),A=a.pow(u,w);l=b,u=a.sqr(A),p=a.mul(p,u),h=a.mul(h,A)}return h}}function Ts(t){return t%si===oi?ui:t%ai===ci?ks:t%fi===Rs?Us(t):li(t)}var Ns=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Sr(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Ns.reduce((n,i)=>(n[i]="function",n),e);return mt(t,r),t}function _s(t,e,r){if(r<de)throw new Error("invalid exponent, negatives unsupported");if(r===de)return t.ONE;if(r===ue)return e;let n=t.ONE,i=e;for(;r>de;)r&ue&&(n=t.mul(n,i)),i=t.sqr(i),r>>=ue;return n}function Pt(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),i=e.reduce((s,c,a)=>t.is0(c)?s:(n[a]=s,t.mul(s,c)),t.ONE),o=t.inv(i);return e.reduceRight((s,c,a)=>t.is0(c)?s:(n[a]=t.mul(s,n[a]),t.mul(s,c)),o),n}function ii(t,e){let r=(t.ORDER-ue)/Me,n=t.pow(e,r),i=t.eql(n,t.ONE),o=t.eql(n,t.ZERO),s=t.eql(n,t.neg(t.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function Ls(t,e){e!==void 0&&Q(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Ar=class{constructor(e,r={}){R(this,"ORDER");R(this,"BITS");R(this,"BYTES");R(this,"isLE");R(this,"ZERO",de);R(this,"ONE",ue);R(this,"_lengths");R(this,"_sqrt");R(this,"_mod");if(e<=de)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:i,nByteLength:o}=Ls(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=i,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return we(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return de<=e&&e<this.ORDER}is0(e){return e===de}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ue)===ue}neg(e){return we(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return we(e*e,this.ORDER)}add(e,r){return we(e+r,this.ORDER)}sub(e,r){return we(e-r,this.ORDER)}mul(e,r){return we(e*r,this.ORDER)}pow(e,r){return _s(this,e,r)}div(e,r){return we(e*ni(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return ni(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=Ts(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?wr(e,this.BYTES):Ot(e,this.BYTES)}fromBytes(e,r=!1){M(e);let{_lengths:n,BYTES:i,isLE:o,ORDER:s,_mod:c}=this;if(n){if(!n.includes(e.length)||e.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let f=new Uint8Array(i);f.set(e,o?0:f.length-e.length),e=f}if(e.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);let a=o?mr(e):He(e);if(c&&(a=we(a,s)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return Pt(this,e)}cmov(e,r,n){return n?r:e}};function Qe(t,e={}){return new Ar(t,e)}function di(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 vr(t){let e=di(t);return e+Math.ceil(e/2)}function Dt(t,e,r=!1){M(t);let n=t.length,i=di(e),o=vr(e);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let s=r?mr(t):He(t),c=we(s,e-ue)+ue;return r?wr(c,i):Ot(c,i)}var et=BigInt(0),$e=BigInt(1);function wt(t,e){let r=e.negate();return t?r:e}function Tr(t,e){let r=Pt(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function gi(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Rr(t,e){gi(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,o=bt(t),s=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:i,shiftBy:s}}function hi(t,e,r){let{windowSize:n,mask:i,maxNumber:o,shiftBy:s}=r,c=Number(t&i),a=t>>s;c>n&&(c-=o,a+=$e);let f=e*n,l=f+Math.abs(c)-1,u=c===0,p=c<0,h=e%2!==0;return{nextN:a,offset:l,isZero:u,isNeg:p,isNegF:h,offsetF:f}}var kr=new WeakMap,xi=new WeakMap;function Ur(t){return xi.get(t)||1}function pi(t){if(t!==et)throw new Error("invalid wNAF")}var Ht=class{constructor(e,r){R(this,"BASE");R(this,"ZERO");R(this,"Fn");R(this,"bits");this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let i=e;for(;r>et;)r&$e&&(n=n.add(i)),i=i.double(),r>>=$e;return n}precomputeWindow(e,r){let{windows:n,windowSize:i}=Rr(r,this.bits),o=[],s=e,c=s;for(let a=0;a<n;a++){c=s,o.push(c);for(let f=1;f<i;f++)c=c.add(s),o.push(c);s=c.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,o=this.BASE,s=Rr(e,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:f,isZero:l,isNeg:u,isNegF:p,offsetF:h}=hi(n,c,s);n=a,l?o=o.add(wt(p,r[h])):i=i.add(wt(u,r[f]))}return pi(n),{p:i,f:o}}wNAFUnsafe(e,r,n,i=this.ZERO){let o=Rr(e,this.bits);for(let s=0;s<o.windows&&n!==et;s++){let{nextN:c,offset:a,isZero:f,isNeg:l}=hi(n,s,o);if(n=c,!f){let u=r[a];i=i.add(l?u.negate():u)}}return pi(n),i}getPrecomputes(e,r,n){let i=kr.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),kr.set(r,i))),i}cached(e,r,n){let i=Ur(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){let o=Ur(e);return o===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,i)}createCache(e,r){gi(r,this.bits),xi.set(e,r),kr.delete(e)}hasCache(e){return Ur(e)!==1}};function bi(t,e,r,n){let i=e,o=t.ZERO,s=t.ZERO;for(;r>et||n>et;)r&$e&&(o=o.add(i)),n&$e&&(s=s.add(i)),i=i.double(),r>>=$e,n>>=$e;return{p1:o,p2:s}}function yi(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Sr(e),e}else return Qe(t,{isLE:r})}function mi(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 a of["p","n","h"]){let f=e[a];if(!(typeof f=="bigint"&&f>et))throw new Error(`CURVE.${a} must be positive bigint`)}let i=yi(e.p,r.Fp,n),o=yi(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of c)if(!i.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:o}}function Vt(t,e){return function(n){let i=t(n);return{secretKey:i,publicKey:e(i)}}}var Ft=class{constructor(e,r){R(this,"oHash");R(this,"iHash");R(this,"blockLen");R(this,"outputLen");R(this,"finished",!1);R(this,"destroyed",!1);if(Ue(e),M(r,void 0,"key"),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 n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);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),ye(i)}update(e){return Xe(this),this.iHash.update(e),this}digestInto(e){Xe(this),M(e,this.outputLen,"output"),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:i,destroyed:o,blockLen:s,outputLen:c}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=c,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()}},Ee=(t,e,r)=>new Ft(t,e).update(r).digest();Ee.create=(t,e)=>new Ft(t,e);var wi=(t,e)=>(t+(t>=0?e:-e)/Ei)/e;function Cs(t,e,r){let[[n,i],[o,s]]=e,c=wi(s*t,r),a=wi(-i*t,r),f=t-c*n-a*o,l=-c*i-a*s,u=f<Ne,p=l<Ne;u&&(f=-f),p&&(l=-l);let h=bt(Math.ceil(Er(r)/2))+tt;if(f<Ne||f>=h||l<Ne||l>=h)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:u,k1:f,k2neg:p,k2:l}}function _r(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Nr(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return gt(r.lowS,"lowS"),gt(r.prehash,"prehash"),r.format!==void 0&&_r(r.format),r}var Lr=class extends Error{constructor(e=""){super(e)}},Ve={Err:Lr,_tlv:{encode:(t,e)=>{let{Err:r}=Ve;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,i=xt(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?xt(i.length/2|128):"";return xt(t)+o+i+e},decode(t,e){let{Err:r}=Ve,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 i=e[n++],o=!!(i&128),s=0;if(!o)s=i;else{let a=i&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of f)s=s<<8|l;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=e.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=Ve;if(t<Ne)throw new e("integer: negative integers are not allowed");let r=xt(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}=Ve;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 He(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ve,i=M(t,void 0,"signature"),{v:o,l:s}=n.decode(48,i);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,o),{v:f,l}=n.decode(2,a);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=Ve,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),o=n+i;return e.encode(48,o)}},Ne=BigInt(0),tt=BigInt(1),Ei=BigInt(2),qt=BigInt(3),Os=BigInt(4);function Bi(t,e={}){let r=mi("weierstrass",t,e),{Fp:n,Fn:i}=r,o=r.CURVE,{h:s,n:c}=o;mt(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=e;if(a&&(!n.is0(o.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Ii(n,i);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(T,d,y){let{x:E,y:B}=d.toAffine(),S=n.toBytes(E);if(gt(y,"isCompressed"),y){l();let m=!n.isOdd(B);return re(Ai(m),S)}else return re(Uint8Array.of(4),S,n.toBytes(B))}function p(T){M(T,void 0,"Point");let{publicKey:d,publicKeyUncompressed:y}=f,E=T.length,B=T[0],S=T.subarray(1);if(E===d&&(B===2||B===3)){let m=n.fromBytes(S);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let v=x(m),I;try{I=n.sqrt(v)}catch(X){let G=X instanceof Error?": "+X.message:"";throw new Error("bad point: is not on curve, sqrt error"+G)}l();let k=n.isOdd(I);return(B&1)===1!==k&&(I=n.neg(I)),{x:m,y:I}}else if(E===y&&B===4){let m=n.BYTES,v=n.fromBytes(S.subarray(0,m)),I=n.fromBytes(S.subarray(m,m*2));if(!w(v,I))throw new Error("bad point: is not on curve");return{x:v,y:I}}else throw new Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${y}`)}let h=e.toBytes||u,b=e.fromBytes||p;function x(T){let d=n.sqr(T),y=n.mul(d,T);return n.add(n.add(y,n.mul(T,o.a)),o.b)}function w(T,d){let y=n.sqr(d),E=x(T);return n.eql(y,E)}if(!w(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let A=n.mul(n.pow(o.a,qt),Os),_=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(A,_)))throw new Error("bad curve params: a or b");function C(T,d,y=!1){if(!n.isValid(d)||y&&n.is0(d))throw new Error(`bad point coordinate ${T}`);return d}function V(T){if(!(T instanceof P))throw new Error("Weierstrass Point expected")}function Z(T){if(!a||!a.basises)throw new Error("no endo");return Cs(T,a.basises,i.ORDER)}let O=Br((T,d)=>{let{X:y,Y:E,Z:B}=T;if(n.eql(B,n.ONE))return{x:y,y:E};let S=T.is0();d==null&&(d=S?n.ONE:n.inv(B));let m=n.mul(y,d),v=n.mul(E,d),I=n.mul(B,d);if(S)return{x:n.ZERO,y:n.ZERO};if(!n.eql(I,n.ONE))throw new Error("invZ was invalid");return{x:m,y:v}}),j=Br(T=>{if(T.is0()){if(e.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:d,y}=T.toAffine();if(!n.isValid(d)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!w(d,y))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function Y(T,d,y,E,B){return y=new P(n.mul(y.X,T),y.Y,y.Z),d=wt(E,d),y=wt(B,y),d.add(y)}let N=class N{constructor(d,y,E){R(this,"X");R(this,"Y");R(this,"Z");this.X=C("x",d),this.Y=C("y",y,!0),this.Z=C("z",E),Object.freeze(this)}static CURVE(){return o}static fromAffine(d){let{x:y,y:E}=d||{};if(!d||!n.isValid(y)||!n.isValid(E))throw new Error("invalid affine point");if(d instanceof N)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(E)?N.ZERO:new N(y,E,n.ONE)}static fromBytes(d){let y=N.fromAffine(b(M(d,void 0,"point")));return y.assertValidity(),y}static fromHex(d){return N.fromBytes(H(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,y=!0){return F.createCache(this,d),y||this.multiply(qt),this}assertValidity(){j(this)}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){V(d);let{X:y,Y:E,Z:B}=this,{X:S,Y:m,Z:v}=d,I=n.eql(n.mul(y,v),n.mul(S,B)),k=n.eql(n.mul(E,v),n.mul(m,B));return I&&k}negate(){return new N(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:y}=o,E=n.mul(y,qt),{X:B,Y:S,Z:m}=this,v=n.ZERO,I=n.ZERO,k=n.ZERO,L=n.mul(B,B),X=n.mul(S,S),G=n.mul(m,m),D=n.mul(B,S);return D=n.add(D,D),k=n.mul(B,m),k=n.add(k,k),v=n.mul(d,k),I=n.mul(E,G),I=n.add(v,I),v=n.sub(X,I),I=n.add(X,I),I=n.mul(v,I),v=n.mul(D,v),k=n.mul(E,k),G=n.mul(d,G),D=n.sub(L,G),D=n.mul(d,D),D=n.add(D,k),k=n.add(L,L),L=n.add(k,L),L=n.add(L,G),L=n.mul(L,D),I=n.add(I,L),G=n.mul(S,m),G=n.add(G,G),L=n.mul(G,D),v=n.sub(v,L),k=n.mul(G,X),k=n.add(k,k),k=n.add(k,k),new N(v,I,k)}add(d){V(d);let{X:y,Y:E,Z:B}=this,{X:S,Y:m,Z:v}=d,I=n.ZERO,k=n.ZERO,L=n.ZERO,X=o.a,G=n.mul(o.b,qt),D=n.mul(y,S),J=n.mul(E,m),ee=n.mul(B,v),ne=n.add(y,E),te=n.add(S,m);ne=n.mul(ne,te),te=n.add(D,J),ne=n.sub(ne,te),te=n.add(y,B);let le=n.add(S,v);return te=n.mul(te,le),le=n.add(D,ee),te=n.sub(te,le),le=n.add(E,B),I=n.add(m,v),le=n.mul(le,I),I=n.add(J,ee),le=n.sub(le,I),L=n.mul(X,te),I=n.mul(G,ee),L=n.add(I,L),I=n.sub(J,L),L=n.add(J,L),k=n.mul(I,L),J=n.add(D,D),J=n.add(J,D),ee=n.mul(X,ee),te=n.mul(G,te),J=n.add(J,ee),ee=n.sub(D,ee),ee=n.mul(X,ee),te=n.add(te,ee),D=n.mul(J,te),k=n.add(k,D),D=n.mul(le,te),I=n.mul(ne,I),I=n.sub(I,D),D=n.mul(ne,J),L=n.mul(le,L),L=n.add(L,D),new N(I,k,L)}subtract(d){return this.add(d.negate())}is0(){return this.equals(N.ZERO)}multiply(d){let{endo:y}=e;if(!i.isValidNot0(d))throw new Error("invalid scalar: out of range");let E,B,S=m=>F.cached(this,m,v=>Tr(N,v));if(y){let{k1neg:m,k1:v,k2neg:I,k2:k}=Z(d),{p:L,f:X}=S(v),{p:G,f:D}=S(k);B=X.add(D),E=Y(y.beta,L,G,m,I)}else{let{p:m,f:v}=S(d);E=m,B=v}return Tr(N,[E,B])[0]}multiplyUnsafe(d){let{endo:y}=e,E=this;if(!i.isValid(d))throw new Error("invalid scalar: out of range");if(d===Ne||E.is0())return N.ZERO;if(d===tt)return E;if(F.hasCache(this))return this.multiply(d);if(y){let{k1neg:B,k1:S,k2neg:m,k2:v}=Z(d),{p1:I,p2:k}=bi(N,E,S,v);return Y(y.beta,I,k,B,m)}else return F.unsafe(E,d)}toAffine(d){return O(this,d)}isTorsionFree(){let{isTorsionFree:d}=e;return s===tt?!0:d?d(N,this):F.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:d}=e;return s===tt?this:d?d(N,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(d=!0){return gt(d,"isCompressed"),this.assertValidity(),h(N,this,d)}toHex(d=!0){return $(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};R(N,"BASE",new N(o.Gx,o.Gy,n.ONE)),R(N,"ZERO",new N(n.ZERO,n.ONE,n.ZERO)),R(N,"Fp",n),R(N,"Fn",i);let P=N,q=i.BITS,F=new Ht(P,e.endo?Math.ceil(q/2):q);return P.BASE.precompute(8),P}function Ai(t){return Uint8Array.of(t?2:3)}function Ii(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Ps(t,e={}){let{Fn:r}=t,n=e.randomBytes||se,i=Object.assign(Ii(t.Fp,r),{seed:vr(r.ORDER)});function o(h){try{let b=r.fromBytes(h);return r.isValidNot0(b)}catch{return!1}}function s(h,b){let{publicKey:x,publicKeyUncompressed:w}=i;try{let A=h.length;return b===!0&&A!==x||b===!1&&A!==w?!1:!!t.fromBytes(h)}catch{return!1}}function c(h=n(i.seed)){return Dt(M(h,i.seed,"seed"),r.ORDER)}function a(h,b=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(b)}function f(h){let{secretKey:b,publicKey:x,publicKeyUncompressed:w}=i;if(!yt(h)||"_lengths"in r&&r._lengths||b===x)return;let A=M(h,void 0,"key").length;return A===x||A===w}function l(h,b,x=!0){if(f(h)===!0)throw new Error("first arg must be private key");if(f(b)===!1)throw new Error("second arg must be public key");let w=r.fromBytes(h);return t.fromBytes(b).multiply(w).toBytes(x)}let u={isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:c},p=Vt(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:p,Point:t,utils:u,lengths:i})}function Si(t,e,r={}){Ue(e),mt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||se,i=r.hmac||((d,y)=>Ee(e,d,y)),{Fp:o,Fn:s}=t,{ORDER:c,BITS:a}=s,{keygen:f,getPublicKey:l,getSharedSecret:u,utils:p,lengths:h}=Ps(t,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},x=c*Ei<o.ORDER;function w(d){let y=c>>tt;return d>y}function A(d,y){if(!s.isValidNot0(y))throw new Error(`invalid signature ${d}: out of range 1..Point.Fn.ORDER`);return y}function _(){if(x)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(d,y){_r(y);let E=h.signature,B=y==="compact"?E:y==="recovered"?E+1:void 0;return M(d,B)}class V{constructor(y,E,B){R(this,"r");R(this,"s");R(this,"recovery");if(this.r=A("r",y),this.s=A("s",E),B!=null){if(_(),![0,1,2,3].includes(B))throw new Error("invalid recovery id");this.recovery=B}Object.freeze(this)}static fromBytes(y,E=b.format){C(y,E);let B;if(E==="der"){let{r:I,s:k}=Ve.toSig(M(y));return new V(I,k)}E==="recovered"&&(B=y[0],E="compact",y=y.subarray(1));let S=h.signature/2,m=y.subarray(0,S),v=y.subarray(S,S*2);return new V(s.fromBytes(m),s.fromBytes(v),B)}static fromHex(y,E){return this.fromBytes(H(y),E)}assertRecovery(){let{recovery:y}=this;if(y==null)throw new Error("invalid recovery id: must be present");return y}addRecoveryBit(y){return new V(this.r,this.s,y)}recoverPublicKey(y){let{r:E,s:B}=this,S=this.assertRecovery(),m=S===2||S===3?E+c:E;if(!o.isValid(m))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let v=o.toBytes(m),I=t.fromBytes(re(Ai((S&1)===0),v)),k=s.inv(m),L=O(M(y,void 0,"msgHash")),X=s.create(-L*k),G=s.create(B*k),D=t.BASE.multiplyUnsafe(X).add(I.multiplyUnsafe(G));if(D.is0())throw new Error("invalid recovery: point at infinify");return D.assertValidity(),D}hasHighS(){return w(this.s)}toBytes(y=b.format){if(_r(y),y==="der")return H(Ve.hexFromSig(this));let{r:E,s:B}=this,S=s.toBytes(E),m=s.toBytes(B);return y==="recovered"?(_(),re(Uint8Array.of(this.assertRecovery()),S,m)):re(S,m)}toHex(y){return $(this.toBytes(y))}}let Z=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let E=He(y),B=y.length*8-a;return B>0?E>>BigInt(B):E},O=r.bits2int_modN||function(y){return s.create(Z(y))},j=bt(a);function Y(d){return ti("num < 2^"+a,d,Ne,j),s.toBytes(d)}function P(d,y){return M(d,void 0,"message"),y?M(e(d),void 0,"prehashed message"):d}function q(d,y,E){let{lowS:B,prehash:S,extraEntropy:m}=Nr(E,b);d=P(d,S);let v=O(d),I=s.fromBytes(y);if(!s.isValidNot0(I))throw new Error("invalid private key");let k=[Y(I),Y(v)];if(m!=null&&m!==!1){let D=m===!0?n(h.secretKey):m;k.push(M(D,void 0,"extraEntropy"))}let L=re(...k),X=v;function G(D){let J=Z(D);if(!s.isValidNot0(J))return;let ee=s.inv(J),ne=t.BASE.multiply(J).toAffine(),te=s.create(ne.x);if(te===Ne)return;let le=s.create(ee*s.create(X+te*I));if(le===Ne)return;let Mn=(ne.x===te?0:2)|Number(ne.y&tt),$n=le;return B&&w(le)&&($n=s.neg(le),Mn^=1),new V(te,$n,x?void 0:Mn)}return{seed:L,k2sig:G}}function F(d,y,E={}){let{seed:B,k2sig:S}=q(d,y,E);return ri(e.outputLen,s.BYTES,i)(B,S).toBytes(E.format)}function N(d,y,E,B={}){let{lowS:S,prehash:m,format:v}=Nr(B,b);if(E=M(E,void 0,"publicKey"),y=P(y,m),!yt(d)){let I=d instanceof V?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+I)}C(d,v);try{let I=V.fromBytes(d,v),k=t.fromBytes(E);if(S&&I.hasHighS())return!1;let{r:L,s:X}=I,G=O(y),D=s.inv(X),J=s.create(G*D),ee=s.create(L*D),ne=t.BASE.multiplyUnsafe(J).add(k.multiplyUnsafe(ee));return ne.is0()?!1:s.create(ne.x)===L}catch{return!1}}function T(d,y,E={}){let{prehash:B}=Nr(E,b);return y=P(y,B),V.fromBytes(d,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:u,utils:p,lengths:h,Point:t,sign:F,verify:N,recoverPublicKey:T,Signature:V,hash:e})}var jt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ds={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Hs=BigInt(0),Cr=BigInt(2);function Vs(t){let e=jt.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),f=t*t*t%e,l=f*f*t%e,u=ge(l,r,e)*l%e,p=ge(u,r,e)*l%e,h=ge(p,Cr,e)*f%e,b=ge(h,i,e)*h%e,x=ge(b,o,e)*b%e,w=ge(x,c,e)*x%e,A=ge(w,a,e)*w%e,_=ge(A,c,e)*x%e,C=ge(_,r,e)*l%e,V=ge(C,s,e)*b%e,Z=ge(V,n,e)*f%e,O=ge(Z,Cr,e);if(!Mt.eql(Mt.sqr(O),t))throw new Error("Cannot find square root");return O}var Mt=Qe(jt.p,{sqrt:Vs}),je=Bi(jt,{Fp:Mt,endo:Ds}),_e=Si(je,K),vi={};function $t(t,...e){let r=vi[t];if(r===void 0){let n=K(ei(t));r=re(n,n),vi[t]=r}return K(re(r,...e))}var Pr=t=>t.toBytes(!0).slice(1),Dr=t=>t%Cr===Hs;function Or(t){let{Fn:e,BASE:r}=je,n=e.fromBytes(t),i=r.multiply(n);return{scalar:Dr(i.y)?n:e.neg(n),bytes:Pr(i)}}function ki(t){let e=Mt;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let r=e.create(t*t),n=e.create(r*t+BigInt(7)),i=e.sqrt(n);Dr(i)||(i=e.neg(i));let o=je.fromAffine({x:t,y:i});return o.assertValidity(),o}var Et=He;function Ui(...t){return je.Fn.create(Et($t("BIP0340/challenge",...t)))}function Ri(t){return Or(t).bytes}function Fs(t,e,r=se(32)){let{Fn:n}=je,i=M(t,void 0,"message"),{bytes:o,scalar:s}=Or(e),c=M(r,32,"auxRand"),a=n.toBytes(s^Et($t("BIP0340/aux",c))),f=$t("BIP0340/nonce",a,o,i),{bytes:l,scalar:u}=Or(f),p=Ui(l,o,i),h=new Uint8Array(64);if(h.set(l,0),h.set(n.toBytes(n.create(u+p*s)),32),!Ti(h,i,o))throw new Error("sign: Invalid signature produced");return h}function Ti(t,e,r){let{Fp:n,Fn:i,BASE:o}=je,s=M(t,64,"signature"),c=M(e,void 0,"message"),a=M(r,32,"publicKey");try{let f=ki(Et(a)),l=Et(s.subarray(0,32));if(!n.isValidNot0(l))return!1;let u=Et(s.subarray(32,64));if(!i.isValidNot0(u))return!1;let p=Ui(i.toBytes(l),Pr(f),c),h=o.multiplyUnsafe(u).add(f.multiplyUnsafe(i.neg(p))),{x:b,y:x}=h.toAffine();return!(h.is0()||!Dr(x)||b!==l)}catch{return!1}}var ie=(()=>{let r=(n=se(48))=>Dt(n,jt.n);return{keygen:Vt(r,Ri),getPublicKey:Ri,sign:Fs,verify:Ti,Point:je,utils:{randomSecretKey:r,taggedHash:$t,lift_x:ki,pointToBytes:Pr},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Fi=lr(Vi());var W=(0,Fi.default)({name:"nostr-crypto-utils",level:process.env.LOG_LEVEL||"info",transport:void 0,formatters:{level:t=>({level:t.toUpperCase()}),log:t=>{if(t&&typeof t=="object"&&"err"in t){let e={...t};if(e.err instanceof Error){let r=e.err;e.err={message:r.message,stack:r.stack,name:r.name}}return e}return t}}});function ic(t){try{return!!t.match(/^[A-Za-z0-9+/]*={0,2}$/)}catch{return!1}}function nt(t){let e="";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return btoa(e)}function it(t){if(!ic(t))throw new Error("Invalid base64 string");let e=atob(t),r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}var sc=async()=>{if(typeof window<"u"&&window.crypto)return window.crypto;if(typeof global<"u"&&global.crypto)return global.crypto;try{let t=await Promise.resolve().then(()=>(jr(),$r));if(t.webcrypto)return t.webcrypto}catch{W.debug("Node crypto not available")}throw new Error("No WebCrypto implementation available")},zr=class{constructor(){R(this,"cryptoInstance",null);R(this,"initPromise");this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await sc()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(e){return(await this.ensureInitialized()).getRandomValues(e)}},Yt=new zr,qi=ie.sign,Mi=ie.verify;async function $i(){let t=se(32),e=$(t);t.fill(0);let r=await Kt(e);return{privateKey:e,publicKey:r}}async function Kt(t){try{let e=H(t),r=ie.getPublicKey(e);return{hex:$(r),bytes:r}}catch(e){throw W.error({error:e},"Failed to get public key"),e}}async function ji(t){try{return(await Kt(t.privateKey)).hex===t.publicKey.hex}catch(e){return W.error({error:e},"Failed to validate key pair"),!1}}function zi(t){let e=Math.floor(Date.now()/1e3);return{...t,created_at:t.created_at||e,tags:t.tags||[],content:t.content||"",kind:t.kind||1}}function cc(t){return t instanceof Uint8Array?$(t):t}async function Gr(t,e){try{let r=cc(e),n=JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content]),i=K(new TextEncoder().encode(n)),o=H(r),s=ie.sign(i,o);return{...t,id:$(i),sig:$(s)}}catch(r){throw W.error({error:r},"Failed to sign event"),r}}function Yr(t){let e=t instanceof Uint8Array?t:H(t),r=ie.getPublicKey(e);return $(r)}async function Gi(t,e){let r=t.pubkey||Yr(e),n=t.created_at||Math.floor(Date.now()/1e3),i={kind:t.kind||1,created_at:n,tags:t.tags||[],content:t.content||"",pubkey:r};return Gr(i,e)}async function Yi(t){try{let e=JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content]),r=K(new TextEncoder().encode(e));if($(r)!==t.id)return W.error("Event ID mismatch"),!1;let i=H(t.sig),o=H(t.pubkey);return ie.verify(i,r,o)}catch(e){return W.error({error:e},"Failed to verify signature"),!1}}async function Ki(t,e,r){try{let n=typeof e=="string"?e:e.hex,i=_e.getSharedSecret(H(r),H(n)),o=i.slice(1,33),s=se(16),c=await Yt.getSubtle().then(p=>p.importKey("raw",o.buffer,{name:"AES-CBC",length:256},!1,["encrypt"]));o.fill(0),i.fill(0);let a=new TextEncoder().encode(t),f=await Yt.getSubtle().then(p=>p.encrypt({name:"AES-CBC",iv:s},c,a.buffer)),l=nt(new Uint8Array(f)),u=nt(s);return l+"?iv="+u}catch(n){throw W.error({error:n},"Failed to encrypt message"),n}}async function Wi(t,e,r){try{let n=typeof e=="string"?e:e.hex,i=_e.getSharedSecret(H(r),H(n)),o=i.slice(1,33),s,c;if(t.includes("?iv=")){let[l,u]=t.split("?iv=");c=it(l),s=it(u)}else{let l=H(t);s=l.slice(0,16),c=l.slice(16)}let a=await Yt.getSubtle().then(l=>l.importKey("raw",o.buffer,{name:"AES-CBC",length:256},!1,["decrypt"]));o.fill(0),i.fill(0);let f=await Yt.getSubtle().then(l=>l.decrypt({name:"AES-CBC",iv:s},a,c.buffer));return new TextDecoder().decode(f)}catch(n){throw W.error({error:n},"Failed to decrypt message"),n}}function At(t){return typeof t=="string"?t:t.hex}function Zi(t){return new Uint8Array(t.match(/.{1,2}/g).map(e=>parseInt(e,16)))}function Kr(t){try{let e=JSON.stringify([0,At(t.pubkey),t.created_at,t.kind,t.tags,t.content]),r=$(K(new TextEncoder().encode(e)));return{isValid:r===t.id,error:r===t.id?void 0:"Invalid event ID"}}catch(e){return W.error({error:e},"Failed to validate event ID"),{isValid:!1,error:"Failed to validate event ID"}}}function Wr(t){try{let e=JSON.stringify([0,At(t.pubkey),t.created_at,t.kind,t.tags,t.content]),r=K(new TextEncoder().encode(e)),n=At(t.pubkey),i=Zi(n),o=ie.verify(Zi(t.sig),r,i);return{isValid:o,error:o?void 0:"Invalid signature"}}catch(e){return W.error({error:e},"Failed to validate event signature"),{isValid:!1,error:"Failed to validate event signature"}}}function Xi(t){let e=Zt(t);if(!e.isValid)return e;let r=Kr(t);return r.isValid?Wr(t):r}function Wt(t){try{let e=Zt(t);if(!e.isValid)return e;let r=At(t.pubkey);return!r||typeof r!="string"||r.length!==64?{isValid:!1,error:"Invalid public key format"}:!t.sig||typeof t.sig!="string"||t.sig.length!==128?{isValid:!1,error:"Invalid signature format"}:!t.id||typeof t.id!="string"||t.id.length!==64?{isValid:!1,error:"Invalid event ID format"}:{isValid:!0}}catch(e){return W.error({error:e},"Failed to validate signed event"),{isValid:!1,error:"Failed to validate signed event"}}}function Zt(t){if(!t||typeof t!="object")return{isValid:!1,error:"Invalid event structure"};if(typeof t.kind!="number"||t.kind<0)return{isValid:!1,error:"Event kind must be a non-negative integer"};let e=Math.floor(Date.now()/1e3);if(typeof t.created_at!="number"||t.created_at>e+60)return{isValid:!1,error:"Event timestamp cannot be in the future"};if(typeof t.content!="string")return{isValid:!1,error:"Event content must be a string"};if(!t.pubkey)return{isValid:!1,error:"Missing public key"};let r=At(t.pubkey);if(typeof r!="string"||!/^[0-9a-f]{64}$/.test(r))return{isValid:!1,error:"Invalid public key format"};if(!Array.isArray(t.tags))return{isValid:!1,error:"Event tags must be an array"};for(let n of t.tags){if(!Array.isArray(n))return{isValid:!1,error:"Each tag must be an array"};if(n.length===0)return{isValid:!1,error:"Empty tags are not allowed"};if(typeof n[0]!="string")return{isValid:!1,error:"Tag identifier must be a string"}}return{isValid:!0}}function Xt(t){try{if(!t||typeof t!="object")return{isValid:!1,error:"Invalid filter structure"};if(t.ids&&(!Array.isArray(t.ids)||!t.ids.every(e=>typeof e=="string")))return{isValid:!1,error:"Filter ids must be an array of strings"};if(t.authors&&(!Array.isArray(t.authors)||!t.authors.every(e=>typeof e=="string")))return{isValid:!1,error:"Filter authors must be an array of strings"};if(t.kinds){if(!Array.isArray(t.kinds))return{isValid:!1,error:"Filter kinds must be an array of numbers"};if(!t.kinds.every(e=>typeof e=="number"&&Number.isInteger(e)&&e>=0))return{isValid:!1,error:"Filter kinds must be non-negative integers"}}return t.since&&typeof t.since!="number"?{isValid:!1,error:"Filter since must be a number"}:t.until&&typeof t.until!="number"?{isValid:!1,error:"Filter until must be a number"}:t.limit&&typeof t.limit!="number"?{isValid:!1,error:"Filter limit must be a number"}:t.search&&typeof t.search!="string"?{isValid:!1,error:"Filter search must be a string"}:{isValid:!0}}catch(e){return W.error({error:e},"Failed to validate filter"),{isValid:!1,error:"Failed to validate filter"}}}function Ji(t){try{if(!t||typeof t!="object")return{isValid:!1,error:"Invalid subscription structure"};if(!t.id||typeof t.id!="string")return{isValid:!1,error:"Subscription must have a string ID"};if(!Array.isArray(t.filters))return{isValid:!1,error:"Subscription filters must be an array"};for(let e of t.filters){let r=Xt(e);if(!r.isValid)return r}return{isValid:!0}}catch(e){return W.error({error:e},"Failed to validate subscription"),{isValid:!1,error:"Failed to validate subscription"}}}function Qi(t){if(!Array.isArray(t))return{isValid:!1,error:"Invalid message format: must be an array"};if(t.length===0)return{isValid:!1,error:"Invalid message format: array is empty"};let e=t[0];if(!Object.values(pt).includes(e))return{isValid:!1,error:`Invalid message type: ${e}`};switch(e){case"EVENT":return t.length!==2?{isValid:!1,error:"EVENT message must have exactly 2 elements"}:Wt(t[1]);case"NOTICE":return t.length!==2||typeof t[1]!="string"?{isValid:!1,error:"NOTICE message must have exactly 2 elements with a string message"}:{isValid:!0};case"OK":return t.length!==4||typeof t[1]!="string"||typeof t[2]!="boolean"||typeof t[3]!="string"?{isValid:!1,error:"OK message must have exactly 4 elements: [type, eventId, success, message]"}:{isValid:!0};case"EOSE":return t.length!==2||typeof t[1]!="string"?{isValid:!1,error:"EOSE message must have exactly 2 elements with a subscription ID"}:{isValid:!0};case"REQ":if(t.length<2)return{isValid:!1,error:"REQ message must have at least 2 elements"};if(typeof t[1]!="string")return{isValid:!1,error:"REQ message must have a string subscription ID"};for(let r=2;r<t.length;r++){let n=Xt(t[r]);if(!n.isValid)return n}return{isValid:!0};case"CLOSE":return t.length!==2||typeof t[1]!="string"?{isValid:!1,error:"CLOSE message must have exactly 2 elements with a subscription ID"}:{isValid:!0};case"AUTH":return t.length!==2?{isValid:!1,error:"AUTH message must have exactly 2 elements"}:Wt(t[1]);default:return{isValid:!1,error:`Unsupported message type: ${e}`}}}function eo(t){return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}async function Zr(t){try{let e=eo(t),r=await K(new TextEncoder().encode(e));return $(r)}catch(e){throw W.error({error:e},"Failed to get event hash"),e}}function Xr(t){return Zr(t)}var rn={};Re(rn,{computeSharedSecret:()=>tn,decryptMessage:()=>en,encryptMessage:()=>Qr,generateSharedSecret:()=>tn});var ac=async()=>{if(typeof window<"u"&&window.crypto)return window.crypto;if(typeof global<"u"&&global.crypto)return global.crypto;try{let t=await Promise.resolve().then(()=>(jr(),$r));if(t.webcrypto)return t.webcrypto}catch{W.debug("Node crypto not available")}throw new Error("No WebCrypto implementation available")},Jr=class{constructor(){R(this,"cryptoInstance",null);R(this,"initPromise");this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await ac()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(e){return(await this.ensureInitialized()).getRandomValues(e)}},It=new Jr;async function Qr(t,e,r){try{if(!t||!e||!r)throw new Error("Invalid input parameters");if(!/^[0-9a-f]{64}$/i.test(e))throw new Error("Invalid private key format");let n=r.startsWith("02")||r.startsWith("03")?r:"02"+r,i=_e.getSharedSecret(H(e),H(n)),o=i.slice(1,33),s=await(await It.getSubtle()).importKey("raw",o.buffer,{name:"AES-CBC",length:256},!1,["encrypt"]);o.fill(0),i.fill(0);let c=new Uint8Array(16);await It.getRandomValues(c);let a=new TextEncoder().encode(t),f=await(await It.getSubtle()).encrypt({name:"AES-CBC",iv:c},s,a.buffer),l=nt(new Uint8Array(f)),u=nt(c);return l+"?iv="+u}catch(n){throw W.error({error:n},"Failed to encrypt message"),n}}async function en(t,e,r){try{if(!t||!e||!r)throw new Error("Invalid input parameters");if(!/^[0-9a-f]{64}$/i.test(e))throw new Error("Invalid private key format");let n=r.startsWith("02")||r.startsWith("03")?r:"02"+r,i=_e.getSharedSecret(H(e),H(n)),o=i.slice(1,33),s=await(await It.getSubtle()).importKey("raw",o.buffer,{name:"AES-CBC",length:256},!1,["decrypt"]);o.fill(0),i.fill(0);let c,a;if(t.includes("?iv=")){let[l,u]=t.split("?iv=");a=it(l),c=it(u)}else{let l=H(t);c=l.slice(0,16),a=l.slice(16)}let f=await(await It.getSubtle()).decrypt({name:"AES-CBC",iv:c},s,a.buffer);return new TextDecoder().decode(f)}catch(n){throw W.error({error:n},"Failed to decrypt message"),n}}function tn(t,e){try{if(!t||!e)throw new Error("Invalid input parameters");if(!/^[0-9a-f]{64}$/i.test(t))throw new Error("Invalid private key format");let r=e.startsWith("02")||e.startsWith("03")?e:"02"+e;return{sharedSecret:_e.getSharedSecret(H(t),H(r)).slice(1,33)}}catch(r){throw W.error({error:r},"Failed to generate shared secret"),r}}var on={};Re(on,{calculateEventId:()=>ro,createEvent:()=>fc,getEventHash:()=>to,serializeEvent:()=>nn,signEvent:()=>uc,validateEvent:()=>dc,verifySignature:()=>lc});function fc(t){let{kind:e,content:r,tags:n=[],created_at:i=Math.floor(Date.now()/1e3),pubkey:o=""}=t;return{kind:e,content:r,tags:n,created_at:i,pubkey:o}}function nn(t){return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}async function to(t){try{let e=nn(t),r=K(new TextEncoder().encode(e));return $(r)}catch(e){throw W.error({error:e},"Failed to get event hash"),e}}async function uc(t,e){try{let r=await to(t),n=ie.sign(H(r),H(e));return{...t,id:r,sig:$(n)}}catch(r){throw W.error({error:r},"Failed to sign event"),r}}function lc(t){try{let e=ro(t);return t.id!==e?!1:ie.verify(H(t.sig),H(t.id),H(t.pubkey))}catch(e){return W.error({error:e},"Failed to verify signature"),!1}}function ro(t){let e=nn(t),r=K(new TextEncoder().encode(e));return $(r)}function dc(t){try{if(typeof t.content!="string"||typeof t.created_at!="number"||typeof t.kind!="number"||!Array.isArray(t.tags)||typeof t.pubkey!="string")return!1;for(let e of t.tags)if(!Array.isArray(e)||e.length===0||typeof e[0]!="string")return!1;return!0}catch(e){return W.error({error:e},"Failed to validate event"),!1}}var bn={};Re(bn,{decode:()=>ra,naddrEncode:()=>ea,neventEncode:()=>Qc,noteEncode:()=>Xc,nprofileEncode:()=>Jc,npubEncode:()=>Wc,nrelayEncode:()=>ta,nsecEncode:()=>Zc});var he=lr(so()),be=lr(ko()),Kc=["npub","nsec","note","nprofile","nevent","naddr","nrelay"],Ie={SPECIAL:0,RELAY:1,AUTHOR:2,KIND:3,IDENTIFIER:4};function Wc(t){Se(t,64);let e=be.Buffer.from(t,"hex"),r=he.bech32.toWords(e);return he.bech32.encode("npub",r,1e3)}function Zc(t){Se(t,64);let e=be.Buffer.from(t,"hex"),r=he.bech32.toWords(e);return he.bech32.encode("nsec",r,1e3)}function Xc(t){Se(t,64);let e=be.Buffer.from(t,"hex"),r=he.bech32.toWords(e);return he.bech32.encode("note",r,1e3)}function Jc(t,e){Se(t,64),e&&e.forEach(lt);let r=xn({type:"nprofile",data:t,relays:e});return he.bech32.encode("nprofile",r,1e3)}function Qc(t,e,r,n){if(Se(t,64),e&&e.forEach(lt),r&&Se(r,64),n!==void 0&&!Number.isInteger(n))throw new Error("Invalid event kind");let i=xn({type:"nevent",data:t,relays:e,author:r,kind:n});return he.bech32.encode("nevent",i,1e3)}function ea(t,e,r,n){if(Se(t,64),!Number.isInteger(e))throw new Error("Invalid event kind");if(!r)throw new Error("Identifier is required");n&&n.forEach(lt);let i=xn({type:"naddr",data:t,kind:e,identifier:r,relays:n});return he.bech32.encode("naddr",i,1e3)}function ta(t){lt(t);let e=be.Buffer.from(t,"utf8"),r=he.bech32.toWords(e);return he.bech32.encode("nrelay",r,1e3)}function ra(t){if(!t.includes("1"))throw new Error("Invalid bech32 string");let e=t.split("1")[0].toLowerCase();if(!Kc.includes(e))throw new Error("Unknown prefix");try{let r=he.bech32.decode(t,1e3),n=be.Buffer.from(he.bech32.fromWords(r.words)),i,o;switch(r.prefix){case"npub":case"nsec":case"note":return Se(n.toString("hex"),64),{type:r.prefix,data:n.toString("hex")};case"nrelay":return i=n.toString("utf8"),lt(i),{type:"nrelay",data:i};case"nprofile":case"nevent":case"naddr":return o=na(r.prefix,n),o;default:throw new Error("Unknown prefix")}}catch(r){throw r instanceof Error?r:new Error("Invalid bech32 string")}}function Se(t,e){if(!/^[0-9a-fA-F]+$/.test(t))throw new Error("Invalid hex string");if(e&&t.length!==e)throw new Error(`Invalid hex string length (expected ${e})`)}function lt(t){try{let e=new URL(t);if(!["ws:","wss:"].includes(e.protocol))throw new Error("Invalid relay URL protocol")}catch{throw new Error("Invalid relay URL")}}function xn(t){let e=[],r=be.Buffer.from(t.data,"hex");if(e.push(Ie.SPECIAL,r.length),e.push(...r),t.relays?.length)for(let n of t.relays){let i=be.Buffer.from(n,"utf8");e.push(Ie.RELAY,i.length),e.push(...i)}if(t.author){let n=be.Buffer.from(t.author,"hex");e.push(Ie.AUTHOR,n.length),e.push(...n)}if(t.kind!==void 0){let n=be.Buffer.alloc(4);n.writeUInt32BE(t.kind),e.push(Ie.KIND,n.length),e.push(...n)}if(t.identifier){let n=be.Buffer.from(t.identifier,"utf8");e.push(Ie.IDENTIFIER,n.length),e.push(...n)}return he.bech32.toWords(be.Buffer.from(e))}function na(t,e){let r={type:t,data:"",relays:[]},n=0,i;for(;n<e.length;){let o=e[n],s=e[n+1];if(n+2+s>e.length)throw new Error("Invalid TLV data");let c=e.slice(n+2,n+2+s);switch(o){case Ie.SPECIAL:r.data=c.toString("hex"),Se(r.data,64);break;case Ie.RELAY:i=c.toString("utf8"),lt(i),r.relays=r.relays||[],r.relays.push(i);break;case Ie.AUTHOR:r.author=c.toString("hex"),Se(r.author,64);break;case Ie.KIND:r.kind=c.readUInt32BE();break;case Ie.IDENTIFIER:r.identifier=c.toString("utf8");break;default:break}n+=2+s}return r}var wn={};Re(wn,{addDelegationTag:()=>ca,checkDelegationConditions:()=>sa,createDelegation:()=>ia,extractDelegation:()=>aa,verifyDelegation:()=>oa});function ia(t,e,r){let n=mn(r),i=ua(t,e,n);return{delegator:$(ie.getPublicKey(H(t))),delegatee:e,conditions:r,token:i}}async function oa(t){let e=mn(t.conditions);return await la(t.delegator,t.delegatee,e,t.token)}function sa(t,e){return!(e.kind!==void 0&&t.kind!==e.kind||e.since!==void 0&&t.created_at<e.since||e.until!==void 0&&t.created_at>e.until)}function ca(t,e){let r=["delegation",e.delegator,mn(e.conditions),e.token];return{...t,tags:[...t.tags,r]}}function aa(t){let e=t.tags.find(r=>r[0]==="delegation");return!e||e.length!==4?null:{delegator:e[1],delegatee:t.pubkey,conditions:fa(e[2]),token:e[3]}}function mn(t){let e=[];return t.kind!==void 0&&e.push(`kind=${t.kind}`),t.since!==void 0&&e.push(`created_at>${t.since}`),t.until!==void 0&&e.push(`created_at<${t.until}`),e.join("&")}function fa(t){let e={},r=t.split("&");for(let n of r)n.startsWith("kind=")?e.kind=parseInt(n.slice(5)):n.startsWith("created_at>")?e.since=parseInt(n.slice(11)):n.startsWith("created_at<")&&(e.until=parseInt(n.slice(11)));return e}function ua(t,e,r){let n=`nostr:delegation:${e}:${r}`,i=K(new TextEncoder().encode(n)),o=qi(i,H(t));return $(o)}async function la(t,e,r,n){let i=K(new TextEncoder().encode(`nostr:delegation:${e}:${r}`));return Mi(H(n),i,H(t))}var On={};Re(On,{calcPaddedLen:()=>ur,decrypt:()=>Ut,encrypt:()=>kt,getConversationKey:()=>We,v2:()=>Pa});function da(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function rr(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function nr(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function ae(t,e,r=""){let n=da(t),i=t?.length,o=e!==void 0;if(!n||o&&i!==e){let s=r&&`"${r}" `,c=o?` of length ${e}`:"",a=n?`length=${i}`:`type=${typeof t}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return t}function En(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 Uo(t,e){ae(t,void 0,"output");let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Oe(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Pe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function ha(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var pa=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function To(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function ir(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 Bn=(t,e)=>{function r(n,...i){if(ae(n,void 0,"key"),!pa)throw new Error("Non little-endian hardware is not yet supported");if(t.nonceLength!==void 0){let l=i[0];ae(l,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let o=t.tagLength;o&&i[1]!==void 0&&ae(i[1],void 0,"AAD");let s=e(n,...i),c=(l,u)=>{if(u!==void 0){if(l!==2)throw new Error("cipher output not supported");ae(u,void 0,"output")}},a=!1;return{encrypt(l,u){if(a)throw new Error("cannot encrypt() twice with same key + nonce");return a=!0,ae(l),c(s.encrypt.length,u),s.encrypt(l,u)},decrypt(l,u){if(ae(l),o&&l.length<o)throw new Error('"ciphertext" expected length bigger than tagLength='+o);return c(s.decrypt.length,u),s.decrypt(l,u)}}}return Object.assign(r,t),r};function An(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(e.length!==t)throw new Error('"output" expected Uint8Array of length '+t+", got: "+e.length);if(r&&!ya(e))throw new Error("invalid output, must be aligned");return e}function No(t,e,r){rr(r);let n=new Uint8Array(16),i=ha(n);return i.setBigUint64(0,BigInt(e),r),i.setBigUint64(8,BigInt(t),r),n}function ya(t){return t.byteOffset%4===0}function dt(t){return Uint8Array.from(t)}var Lo=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),ga=Lo("expand 16-byte k"),xa=Lo("expand 32-byte k"),ba=Oe(ga),ma=Oe(xa);function U(t,e){return t<<e|t>>>32-e}function In(t){return t.byteOffset%4===0}var or=64,wa=16,Co=2**32-1,_o=Uint32Array.of();function Ea(t,e,r,n,i,o,s,c){let a=i.length,f=new Uint8Array(or),l=Oe(f),u=In(i)&&In(o),p=u?Oe(i):_o,h=u?Oe(o):_o;for(let b=0;b<a;s++){if(t(e,r,n,l,s,c),s>=Co)throw new Error("arx: counter overflow");let x=Math.min(or,a-b);if(u&&x===or){let w=b/4;if(b%4!==0)throw new Error("arx: invalid block position");for(let A=0,_;A<wa;A++)_=w+A,h[_]=p[_]^l[A];b+=or;continue}for(let w=0,A;w<x;w++)A=b+w,o[A]=i[A]^f[w];b+=x}}function Sn(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:i,counterRight:o,rounds:s}=To({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return nr(i),nr(s),rr(o),rr(r),(c,a,f,l,u=0)=>{ae(c,void 0,"key"),ae(a,void 0,"nonce"),ae(f,void 0,"data");let p=f.length;if(l===void 0&&(l=new Uint8Array(p)),ae(l,void 0,"output"),nr(u),u<0||u>=Co)throw new Error("arx: counter overflow");if(l.length<p)throw new Error(`arx: output (${l.length}) is shorter than data (${p})`);let h=[],b=c.length,x,w;if(b===32)h.push(x=dt(c)),w=ma;else if(b===16&&r)x=new Uint8Array(32),x.set(c),x.set(c,16),w=ba,h.push(x);else throw ae(c,32,"arx key"),new Error("invalid key size");In(a)||h.push(a=dt(a));let A=Oe(x);if(n){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(w,A,Oe(a.subarray(0,16)),A),a=a.subarray(16)}let _=16-i;if(_!==a.length)throw new Error(`arx: nonce must be ${_} or 16 bytes`);if(_!==12){let V=new Uint8Array(12);V.set(a,o?0:12-a.length),a=V,h.push(a)}let C=Oe(a);return Ea(t,w,A,C,f,l,u,s),Pe(...h),l}}function fe(t,e){return t[e++]&255|(t[e++]&255)<<8}var vn=class{constructor(e){R(this,"blockLen",16);R(this,"outputLen",16);R(this,"buffer",new Uint8Array(16));R(this,"r",new Uint16Array(10));R(this,"h",new Uint16Array(10));R(this,"pad",new Uint16Array(8));R(this,"pos",0);R(this,"finished",!1);e=dt(ae(e,32,"key"));let r=fe(e,0),n=fe(e,2),i=fe(e,4),o=fe(e,6),s=fe(e,8),c=fe(e,10),a=fe(e,12),f=fe(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|i<<6)&7939,this.r[3]=(i>>>7|o<<9)&8191,this.r[4]=(o>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|c<<2)&8191,this.r[7]=(c>>>11|a<<5)&8065,this.r[8]=(a>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let l=0;l<8;l++)this.pad[l]=fe(e,16+2*l)}process(e,r,n=!1){let i=n?0:2048,{h:o,r:s}=this,c=s[0],a=s[1],f=s[2],l=s[3],u=s[4],p=s[5],h=s[6],b=s[7],x=s[8],w=s[9],A=fe(e,r+0),_=fe(e,r+2),C=fe(e,r+4),V=fe(e,r+6),Z=fe(e,r+8),O=fe(e,r+10),j=fe(e,r+12),Y=fe(e,r+14),P=o[0]+(A&8191),q=o[1]+((A>>>13|_<<3)&8191),F=o[2]+((_>>>10|C<<6)&8191),N=o[3]+((C>>>7|V<<9)&8191),T=o[4]+((V>>>4|Z<<12)&8191),d=o[5]+(Z>>>1&8191),y=o[6]+((Z>>>14|O<<2)&8191),E=o[7]+((O>>>11|j<<5)&8191),B=o[8]+((j>>>8|Y<<8)&8191),S=o[9]+(Y>>>5|i),m=0,v=m+P*c+q*(5*w)+F*(5*x)+N*(5*b)+T*(5*h);m=v>>>13,v&=8191,v+=d*(5*p)+y*(5*u)+E*(5*l)+B*(5*f)+S*(5*a),m+=v>>>13,v&=8191;let I=m+P*a+q*c+F*(5*w)+N*(5*x)+T*(5*b);m=I>>>13,I&=8191,I+=d*(5*h)+y*(5*p)+E*(5*u)+B*(5*l)+S*(5*f),m+=I>>>13,I&=8191;let k=m+P*f+q*a+F*c+N*(5*w)+T*(5*x);m=k>>>13,k&=8191,k+=d*(5*b)+y*(5*h)+E*(5*p)+B*(5*u)+S*(5*l),m+=k>>>13,k&=8191;let L=m+P*l+q*f+F*a+N*c+T*(5*w);m=L>>>13,L&=8191,L+=d*(5*x)+y*(5*b)+E*(5*h)+B*(5*p)+S*(5*u),m+=L>>>13,L&=8191;let X=m+P*u+q*l+F*f+N*a+T*c;m=X>>>13,X&=8191,X+=d*(5*w)+y*(5*x)+E*(5*b)+B*(5*h)+S*(5*p),m+=X>>>13,X&=8191;let G=m+P*p+q*u+F*l+N*f+T*a;m=G>>>13,G&=8191,G+=d*c+y*(5*w)+E*(5*x)+B*(5*b)+S*(5*h),m+=G>>>13,G&=8191;let D=m+P*h+q*p+F*u+N*l+T*f;m=D>>>13,D&=8191,D+=d*a+y*c+E*(5*w)+B*(5*x)+S*(5*b),m+=D>>>13,D&=8191;let J=m+P*b+q*h+F*p+N*u+T*l;m=J>>>13,J&=8191,J+=d*f+y*a+E*c+B*(5*w)+S*(5*x),m+=J>>>13,J&=8191;let ee=m+P*x+q*b+F*h+N*p+T*u;m=ee>>>13,ee&=8191,ee+=d*l+y*f+E*a+B*c+S*(5*w),m+=ee>>>13,ee&=8191;let ne=m+P*w+q*x+F*b+N*h+T*p;m=ne>>>13,ne&=8191,ne+=d*u+y*l+E*f+B*a+S*c,m+=ne>>>13,ne&=8191,m=(m<<2)+m|0,m=m+v|0,v=m&8191,m=m>>>13,I+=m,o[0]=v,o[1]=I,o[2]=k,o[3]=L,o[4]=X,o[5]=G,o[6]=D,o[7]=J,o[8]=ee,o[9]=ne}finalize(){let{h:e,pad:r}=this,n=new Uint16Array(10),i=e[1]>>>13;e[1]&=8191;for(let c=2;c<10;c++)e[c]+=i,i=e[c]>>>13,e[c]&=8191;e[0]+=i*5,i=e[0]>>>13,e[0]&=8191,e[1]+=i,i=e[1]>>>13,e[1]&=8191,e[2]+=i,n[0]=e[0]+5,i=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=e[c]+i,i=n[c]>>>13,n[c]&=8191;n[9]-=8192;let o=(i^1)-1;for(let c=0;c<10;c++)n[c]&=o;o=~o;for(let c=0;c<10;c++)e[c]=e[c]&o|n[c];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 s=e[0]+r[0];e[0]=s&65535;for(let c=1;c<8;c++)s=(e[c]+r[c]|0)+(s>>>16)|0,e[c]=s&65535;Pe(n)}update(e){En(this),ae(e),e=dt(e);let{buffer:r,blockLen:n}=this,i=e.length;for(let o=0;o<i;){let s=Math.min(n-this.pos,i-o);if(s===n){for(;n<=i-o;o+=n)this.process(e,o);continue}r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){Pe(this.h,this.r,this.buffer,this.pad)}digestInto(e){En(this),Uo(e,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:i}=this;if(i){for(r[i++]=1;i<16;i++)r[i]=0;this.process(r,0,!0)}this.finalize();let o=0;for(let s=0;s<8;s++)e[o++]=n[s]>>>0,e[o++]=n[s]>>>8;return e}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}};function Ba(t){let e=(n,i)=>t(i).update(n).digest(),r=t(new Uint8Array(32));return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}var Oo=Ba(t=>new vn(t));function Ho(t,e,r,n,i,o=20){let s=t[0],c=t[1],a=t[2],f=t[3],l=e[0],u=e[1],p=e[2],h=e[3],b=e[4],x=e[5],w=e[6],A=e[7],_=i,C=r[0],V=r[1],Z=r[2],O=s,j=c,Y=a,P=f,q=l,F=u,N=p,T=h,d=b,y=x,E=w,B=A,S=_,m=C,v=V,I=Z;for(let L=0;L<o;L+=2)O=O+q|0,S=U(S^O,16),d=d+S|0,q=U(q^d,12),O=O+q|0,S=U(S^O,8),d=d+S|0,q=U(q^d,7),j=j+F|0,m=U(m^j,16),y=y+m|0,F=U(F^y,12),j=j+F|0,m=U(m^j,8),y=y+m|0,F=U(F^y,7),Y=Y+N|0,v=U(v^Y,16),E=E+v|0,N=U(N^E,12),Y=Y+N|0,v=U(v^Y,8),E=E+v|0,N=U(N^E,7),P=P+T|0,I=U(I^P,16),B=B+I|0,T=U(T^B,12),P=P+T|0,I=U(I^P,8),B=B+I|0,T=U(T^B,7),O=O+F|0,I=U(I^O,16),E=E+I|0,F=U(F^E,12),O=O+F|0,I=U(I^O,8),E=E+I|0,F=U(F^E,7),j=j+N|0,S=U(S^j,16),B=B+S|0,N=U(N^B,12),j=j+N|0,S=U(S^j,8),B=B+S|0,N=U(N^B,7),Y=Y+T|0,m=U(m^Y,16),d=d+m|0,T=U(T^d,12),Y=Y+T|0,m=U(m^Y,8),d=d+m|0,T=U(T^d,7),P=P+q|0,v=U(v^P,16),y=y+v|0,q=U(q^y,12),P=P+q|0,v=U(v^P,8),y=y+v|0,q=U(q^y,7);let k=0;n[k++]=s+O|0,n[k++]=c+j|0,n[k++]=a+Y|0,n[k++]=f+P|0,n[k++]=l+q|0,n[k++]=u+F|0,n[k++]=p+N|0,n[k++]=h+T|0,n[k++]=b+d|0,n[k++]=x+y|0,n[k++]=w+E|0,n[k++]=A+B|0,n[k++]=_+S|0,n[k++]=C+m|0,n[k++]=V+v|0,n[k++]=Z+I|0}function Aa(t,e,r,n){let i=t[0],o=t[1],s=t[2],c=t[3],a=e[0],f=e[1],l=e[2],u=e[3],p=e[4],h=e[5],b=e[6],x=e[7],w=r[0],A=r[1],_=r[2],C=r[3];for(let Z=0;Z<20;Z+=2)i=i+a|0,w=U(w^i,16),p=p+w|0,a=U(a^p,12),i=i+a|0,w=U(w^i,8),p=p+w|0,a=U(a^p,7),o=o+f|0,A=U(A^o,16),h=h+A|0,f=U(f^h,12),o=o+f|0,A=U(A^o,8),h=h+A|0,f=U(f^h,7),s=s+l|0,_=U(_^s,16),b=b+_|0,l=U(l^b,12),s=s+l|0,_=U(_^s,8),b=b+_|0,l=U(l^b,7),c=c+u|0,C=U(C^c,16),x=x+C|0,u=U(u^x,12),c=c+u|0,C=U(C^c,8),x=x+C|0,u=U(u^x,7),i=i+f|0,C=U(C^i,16),b=b+C|0,f=U(f^b,12),i=i+f|0,C=U(C^i,8),b=b+C|0,f=U(f^b,7),o=o+l|0,w=U(w^o,16),x=x+w|0,l=U(l^x,12),o=o+l|0,w=U(w^o,8),x=x+w|0,l=U(l^x,7),s=s+u|0,A=U(A^s,16),p=p+A|0,u=U(u^p,12),s=s+u|0,A=U(A^s,8),p=p+A|0,u=U(u^p,7),c=c+a|0,_=U(_^c,16),h=h+_|0,a=U(a^h,12),c=c+a|0,_=U(_^c,8),h=h+_|0,a=U(a^h,7);let V=0;n[V++]=i,n[V++]=o,n[V++]=s,n[V++]=c,n[V++]=w,n[V++]=A,n[V++]=_,n[V++]=C}var sr=Sn(Ho,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Ia=Sn(Ho,{counterRight:!1,counterLength:8,extendNonceFn:Aa,allowShortKeys:!1});var Sa=new Uint8Array(16),Po=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(Sa.subarray(r))},va=new Uint8Array(32);function Do(t,e,r,n,i){i!==void 0&&ae(i,void 0,"AAD");let o=t(e,r,va),s=No(n.length,i?i.length:0,!0),c=Oo.create(o);i&&Po(c,i),Po(c,n),c.update(s);let a=c.digest();return Pe(o,s),a}var Vo=t=>(e,r,n)=>({encrypt(o,s){let c=o.length;s=An(c+16,s,!1),s.set(o);let a=s.subarray(0,-16);t(e,r,a,a,1);let f=Do(t,e,r,a,n);return s.set(f,c),Pe(f),s},decrypt(o,s){s=An(o.length-16,s,!1);let c=o.subarray(0,-16),a=o.subarray(-16),f=Do(t,e,r,c,n);if(!ir(a,f))throw new Error("invalid tag");return s.set(o.subarray(0,-16)),t(e,r,s,s,1),Pe(f),s}}),Sl=Bn({blockSize:64,nonceLength:12,tagLength:16},Vo(sr)),Rn=Bn({blockSize:64,nonceLength:24,tagLength:16},Vo(Ia));function qo(t,e,r){return Ue(t),r===void 0&&(r=new Uint8Array(t.outputLen)),Ee(t,r,e)}var kn=Uint8Array.of(0),Fo=Uint8Array.of();function Mo(t,e,r,n=32){Ue(t),Q(n,"length");let i=t.outputLen;if(n>255*i)throw new Error("Length must be <= 255*HashLen");let o=Math.ceil(n/i);r===void 0?r=Fo:M(r,void 0,"info");let s=new Uint8Array(o*i),c=Ee.create(t,e),a=c._cloneInto(),f=new Uint8Array(c.outputLen);for(let l=0;l<o;l++)kn[0]=l+1,a.update(l===0?Fo:f).update(r).update(kn).digestInto(f),s.set(f,i*l),c._cloneInto(a);return c.destroy(),a.destroy(),ye(f,kn),s.slice(0,n)}function _n(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Ra(t){if(!_n(t))throw new Error("Uint8Array expected")}function Go(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 ka(t){if(typeof t!="function")throw new Error("function expected");return!0}function Ke(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function Ln(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Un(t){if(!Array.isArray(t))throw new Error("array expected")}function ar(t,e){if(!Go(!0,e))throw new Error(`${t}: array of strings expected`)}function Yo(t,e){if(!Go(!1,e))throw new Error(`${t}: array of numbers expected`)}function Ko(...t){let e=o=>o,r=(o,s)=>c=>o(s(c)),n=t.map(o=>o.encode).reduceRight(r,e),i=t.map(o=>o.decode).reduce(r,e);return{encode:n,decode:i}}function Wo(t){let e=typeof t=="string"?t.split(""):t,r=e.length;ar("alphabet",e);let n=new Map(e.map((i,o)=>[i,o]));return{encode:i=>(Un(i),i.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${t}`);return e[o]})),decode:i=>(Un(i),i.map(o=>{Ke("alphabet.decode",o);let s=n.get(o);if(s===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${t}`);return s}))}}function Zo(t=""){return Ke("join",t),{encode:e=>(ar("join.decode",e),e.join(t)),decode:e=>(Ke("join.decode",e),e.split(t))}}function Ua(t,e="="){return Ln(t),Ke("padding",e),{encode(r){for(ar("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){ar("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)}}}var Xo=(t,e)=>e===0?t:Xo(e,t%e),fr=(t,e)=>t+(e-Xo(t,e)),cr=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Tn(t,e,r,n){if(Un(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(fr(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${fr(e,r)}`);let i=0,o=0,s=cr[e],c=cr[r]-1,a=[];for(let f of t){if(Ln(f),f>=s)throw new Error(`convertRadix2: invalid data word=${f} from=${e}`);if(i=i<<e|f,o+e>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${e}`);for(o+=e;o>=r;o-=r)a.push((i>>o-r&c)>>>0);let l=cr[o];if(l===void 0)throw new Error("invalid carry");i&=l-1}if(i=i<<r-o&c,!n&&o>=e)throw new Error("Excess padding");if(!n&&i>0)throw new Error(`Non-zero padding: ${i}`);return n&&o>0&&a.push(i>>>0),a}function Jo(t,e=!1){if(Ln(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(fr(8,t)>32||fr(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!_n(r))throw new Error("radix2.encode input should be Uint8Array");return Tn(Array.from(r),8,t,!e)},decode:r=>(Yo("radix2.decode",r),Uint8Array.from(Tn(r,t,8,e)))}}function $o(t){return ka(t),function(...e){try{return t.apply(null,e)}catch{}}}var Ta=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",Na=(t,e)=>{Ke("base64",t);let r=e?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,n=e?"base64url":"base64";if(t.length>0&&!r.test(t))throw new Error("invalid base64");return Uint8Array.fromBase64(t,{alphabet:n,lastChunkHandling:"strict"})},Cn=Ta?{encode(t){return Ra(t),t.toBase64()},decode(t){return Na(t,!1)}}:Ko(Jo(6),Wo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Ua(6),Zo(""));var Nn=Ko(Wo("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Zo("")),jo=[996825010,642813549,513874426,1027748829,705979059];function vt(t){let e=t>>25,r=(t&33554431)<<5;for(let n=0;n<jo.length;n++)(e>>n&1)===1&&(r^=jo[n]);return r}function zo(t,e,r=1){let n=t.length,i=1;for(let o=0;o<n;o++){let s=t.charCodeAt(o);if(s<33||s>126)throw new Error(`Invalid prefix (${t})`);i=vt(i)^s>>5}i=vt(i);for(let o=0;o<n;o++)i=vt(i)^t.charCodeAt(o)&31;for(let o of e)i=vt(i)^o;for(let o=0;o<6;o++)i=vt(i);return i^=r,Nn.encode(Tn([i%cr[30]],30,5,!1))}function _a(t){let e=t==="bech32"?1:734539939,r=Jo(5),n=r.decode,i=r.encode,o=$o(n);function s(u,p,h=90){Ke("bech32.encode prefix",u),_n(p)&&(p=Array.from(p)),Yo("bech32.encode",p);let b=u.length;if(b===0)throw new TypeError(`Invalid prefix length ${b}`);let x=b+7+p.length;if(h!==!1&&x>h)throw new TypeError(`Length ${x} exceeds limit ${h}`);let w=u.toLowerCase(),A=zo(w,p,e);return`${w}1${Nn.encode(p)}${A}`}function c(u,p=90){Ke("bech32.decode input",u);let h=u.length;if(h<8||p!==!1&&h>p)throw new TypeError(`invalid string length: ${h} (${u}). Expected (8..${p})`);let b=u.toLowerCase();if(u!==b&&u!==u.toUpperCase())throw new Error("String must be lowercase or uppercase");let x=b.lastIndexOf("1");if(x===0||x===-1)throw new Error('Letter "1" must be present between prefix and data only');let w=b.slice(0,x),A=b.slice(x+1);if(A.length<6)throw new Error("Data must be at least 6 characters long");let _=Nn.decode(A).slice(0,-6),C=zo(w,_,e);if(!A.endsWith(C))throw new Error(`Invalid checksum in ${u}: expected "${C}"`);return{prefix:w,words:_}}let a=$o(c);function f(u){let{prefix:p,words:h}=c(u,!1);return{prefix:p,words:h,bytes:n(h)}}function l(u,p){return s(u,i(p))}return{encode:s,decode:c,encodeFromBytes:l,decodeToBytes:f,decodeUnsafe:a,fromWords:n,fromWordsUnsafe:o,toWords:i}}var Rt=_a("bech32");var Qo=new TextEncoder,La=new TextDecoder,es=1,ts=65535;function ur(t){if(!Number.isSafeInteger(t)||t<1)throw new Error("expected positive integer");if(t<=32)return 32;let e=1<<Math.floor(Math.log2(t-1))+1,r=e<=256?32:e/8;return r*(Math.floor((t-1)/r)+1)}function Ca(t){let e=Qo.encode(t),r=e.length;if(r<es||r>ts)throw new Error("invalid plaintext length: must be between 1 and 65535 bytes");let n=new Uint8Array(2);new DataView(n.buffer).setUint16(0,r,!1);let i=new Uint8Array(ur(r)-r);return re(n,e,i)}function Oa(t){let e=new DataView(t.buffer,t.byteOffset).getUint16(0,!1),r=t.subarray(2,2+e);if(e<es||e>ts||r.length!==e||t.length!==2+ur(e))throw new Error("invalid padding");return La.decode(r)}function We(t,e){let n=_e.getSharedSecret(t,H("02"+e)).subarray(1,33);return qo(K,n,Qo.encode("nip44-v2"))}function rs(t,e){let r=Mo(K,t,e,76);return{chacha_key:r.subarray(0,32),chacha_nonce:r.subarray(32,44),hmac_key:r.subarray(44,76)}}function kt(t,e,r=se(32)){let{chacha_key:n,chacha_nonce:i,hmac_key:o}=rs(e,r),s=Ca(t),c=sr(n,i,s),a=Ee(K,o,re(r,c));return Cn.encode(re(new Uint8Array([2]),r,c,a))}function Ut(t,e){let r=Cn.decode(t),n=r[0];if(n!==2)throw new Error(`unknown encryption version: ${n}`);if(r.length<99||r.length>65603)throw new Error("invalid payload size");let i=r.subarray(1,33),o=r.subarray(33,r.length-32),s=r.subarray(r.length-32),{chacha_key:c,chacha_nonce:a,hmac_key:f}=rs(e,i),l=Ee(K,f,re(i,o));if(!ir(s,l))throw new Error("invalid MAC");let u=sr(c,a,o);return Oa(u)}var Pa={utils:{getConversationKey:We,calcPaddedLen:ur},encrypt:kt,decrypt:Ut};var Dn={};Re(Dn,{connectRequest:()=>za,createBunkerURI:()=>Da,createRequest:()=>ve,createRequestFilter:()=>tf,createResponse:()=>oe,createResponseFilter:()=>ef,createSession:()=>Va,getPublicKeyRequest:()=>Ya,getRelaysRequest:()=>Qa,getSessionInfo:()=>qa,handleSignerRequest:()=>of,isRequest:()=>is,isResponse:()=>Ma,nip04DecryptRequest:()=>Za,nip04EncryptRequest:()=>Wa,nip44DecryptRequest:()=>Ja,nip44EncryptRequest:()=>Xa,parseBunkerURI:()=>ns,parsePayload:()=>Pn,pingRequest:()=>Ga,restoreSession:()=>Fa,signEventRequest:()=>Ka,unwrapEvent:()=>ja,unwrapRequest:()=>rf,validateBunkerURI:()=>Ha,wrapEvent:()=>$a,wrapResponse:()=>nf});function ns(t){if(!t.startsWith("bunker://"))throw new Error("invalid bunker URI: must start with bunker://");let e=new URL(t.replace("bunker://","https://")),r=e.hostname;if(!/^[0-9a-f]{64}$/.test(r))throw new Error("invalid bunker URI: remote pubkey must be 64 hex characters");let n=e.searchParams.getAll("relay");if(n.length===0)throw new Error("invalid bunker URI: at least one relay is required");let i=e.searchParams.get("secret")||void 0;return{remotePubkey:r,relays:n,secret:i}}function Da(t,e,r){if(!/^[0-9a-f]{64}$/.test(t))throw new Error("remotePubkey must be 64 hex characters");if(e.length===0)throw new Error("at least one relay is required");let n=e.map(i=>`relay=${encodeURIComponent(i)}`);return r&&n.push(`secret=${encodeURIComponent(r)}`),`bunker://${t}?${n.join("&")}`}function Ha(t){try{return{isValid:!0,uri:ns(t)}}catch(e){return{isValid:!1,error:e.message}}}function Va(t){if(!/^[0-9a-f]{64}$/.test(t))throw new Error("remotePubkey must be 64 hex characters");let e=se(32),r=$(e),n=ie.getPublicKey(e),i=$(n),o=We(e,t);return{clientSecretKey:r,clientPubkey:i,remotePubkey:t,conversationKey:o}}function Fa(t,e){let r=H(t),n=ie.getPublicKey(r),i=$(n),o=We(r,e);return{clientSecretKey:t,clientPubkey:i,remotePubkey:e,conversationKey:o}}function qa(t){return{clientPubkey:t.clientPubkey,remotePubkey:t.remotePubkey}}function ve(t,e,r){return{id:r||$(se(16)),method:t,params:e}}function oe(t,e,r){let n={id:t};return e!==void 0&&(n.result=e),r!==void 0&&(n.error=r),n}function Pn(t){let e=JSON.parse(t);if(typeof e.id!="string")throw new Error("invalid NIP-46 payload: missing id");return e}function is(t){return"method"in t&&"params"in t}function Ma(t){return"result"in t||"error"in t}async function $a(t,e,r){let n=JSON.stringify(t),i=kt(n,e.conversationKey),s={kind:24133,created_at:Math.floor(Date.now()/1e3),tags:[["p",r]],content:i,pubkey:e.clientPubkey},c=JSON.stringify([0,s.pubkey,s.created_at,s.kind,s.tags,s.content]),a=K(new TextEncoder().encode(c)),f=H(e.clientSecretKey),l=ie.sign(a,f);return{...s,id:$(a),sig:$(l)}}function ja(t,e){if(t.kind!==24133)throw new Error(`expected kind 24133, got ${t.kind}`);let r=Ut(t.content,e.conversationKey);return Pn(r)}function za(t,e,r){let n=[t];return e?n.push(e):r&&n.push(""),r&&n.push(r),ve("connect",n)}function Ga(){return ve("ping",[])}function Ya(){return ve("get_public_key",[])}function Ka(t){return ve("sign_event",[t])}function Wa(t,e){return ve("nip04_encrypt",[t,e])}function Za(t,e){return ve("nip04_decrypt",[t,e])}function Xa(t,e){return ve("nip44_encrypt",[t,e])}function Ja(t,e){return ve("nip44_decrypt",[t,e])}function Qa(){return ve("get_relays",[])}function ef(t,e){let r={kinds:[24133],"#p":[t]};return e!==void 0&&(r.since=e),r}function tf(t,e){let r={kinds:[24133],"#p":[t]};return e!==void 0&&(r.since=e),r}function rf(t,e){if(t.kind!==24133)throw new Error(`expected kind 24133, got ${t.kind}`);let r=t.pubkey,n=H(e),i=We(n,r),o=Ut(t.content,i),s=Pn(o);if(!is(s))throw new Error("expected a NIP-46 request, got a response");return{request:s,clientPubkey:r,conversationKey:i}}async function nf(t,e,r,n,i){let o=H(e),s=i||We(o,n),c=JSON.stringify(t),a=kt(c,s),l={kind:24133,created_at:Math.floor(Date.now()/1e3),tags:[["p",n]],content:a,pubkey:r},u=JSON.stringify([0,l.pubkey,l.created_at,l.kind,l.tags,l.content]),p=K(new TextEncoder().encode(u)),h=ie.sign(p,o);return{...l,id:$(p),sig:$(h)}}async function of(t,e,r,n){let{method:i,params:o,id:s}=t,c=n?.authenticatedClients;if(i==="connect"||i==="connect"){let a=o[1]||void 0;return n?.secret&&a!==n.secret?{response:oe(s,void 0,"invalid secret")}:{response:oe(s,"ack"),newlyAuthenticated:e}}if(i==="ping"||i==="ping")return{response:oe(s,"pong")};if(c&&!c.has(e))return{response:oe(s,void 0,"unauthorized: call connect first")};try{switch(i){case"get_public_key":case"get_public_key":{let a=await r.getPublicKey();return{response:oe(s,a)}}case"sign_event":case"sign_event":{let a=await r.signEvent(o[0]);return{response:oe(s,a)}}case"nip04_encrypt":case"nip04_encrypt":{if(!r.nip04Encrypt)return{response:oe(s,void 0,"nip04_encrypt not supported")};let a=await r.nip04Encrypt(o[0],o[1]);return{response:oe(s,a)}}case"nip04_decrypt":case"nip04_decrypt":{if(!r.nip04Decrypt)return{response:oe(s,void 0,"nip04_decrypt not supported")};let a=await r.nip04Decrypt(o[0],o[1]);return{response:oe(s,a)}}case"nip44_encrypt":case"nip44_encrypt":{if(!r.nip44Encrypt)return{response:oe(s,void 0,"nip44_encrypt not supported")};let a=await r.nip44Encrypt(o[0],o[1]);return{response:oe(s,a)}}case"nip44_decrypt":case"nip44_decrypt":{if(!r.nip44Decrypt)return{response:oe(s,void 0,"nip44_decrypt not supported")};let a=await r.nip44Decrypt(o[0],o[1]);return{response:oe(s,a)}}case"get_relays":case"get_relays":{if(!r.getRelays)return{response:oe(s,void 0,"get_relays not supported")};let a=await r.getRelays();return{response:oe(s,a)}}default:return{response:oe(s,void 0,`unsupported method: ${i}`)}}}catch(a){let f=a instanceof Error?a.message:String(a);return{response:oe(s,void 0,f)}}}var qn={};Re(qn,{decrypt:()=>df,encrypt:()=>lf});function cf(t,e,r,n){Ue(t);let i=_t({dkLen:32,asyncTick:10},n),{c:o,dkLen:s,asyncTick:c}=i;if(Q(o,"c"),Q(s,"dkLen"),Q(c,"asyncTick"),o<1)throw new Error("iterations (c) must be >= 1");let a=pr(e,"password"),f=pr(r,"salt"),l=new Uint8Array(s),u=Ee.create(t,a),p=u._cloneInto().update(f);return{c:o,dkLen:s,asyncTick:c,DK:l,PRF:u,PRFSalt:p}}function af(t,e,r,n,i){return t.destroy(),e.destroy(),n&&n.destroy(),ye(i),r}function Hn(t,e,r,n){let{c:i,dkLen:o,DK:s,PRF:c,PRFSalt:a}=cf(t,e,r,n),f,l=new Uint8Array(4),u=Je(l),p=new Uint8Array(c.outputLen);for(let h=1,b=0;b<o;h++,b+=c.outputLen){let x=s.subarray(b,b+c.outputLen);u.setInt32(0,h,!1),(f=a._cloneInto(f)).update(l).digestInto(p),x.set(p.subarray(0,x.length));for(let w=1;w<i;w++){c._cloneInto(f).update(p).digestInto(p);for(let A=0;A<x.length;A++)x[A]^=p[A]}}return af(c,a,s,f,p)}function os(t,e,r,n,i,o){let s=t[e++]^r[n++],c=t[e++]^r[n++],a=t[e++]^r[n++],f=t[e++]^r[n++],l=t[e++]^r[n++],u=t[e++]^r[n++],p=t[e++]^r[n++],h=t[e++]^r[n++],b=t[e++]^r[n++],x=t[e++]^r[n++],w=t[e++]^r[n++],A=t[e++]^r[n++],_=t[e++]^r[n++],C=t[e++]^r[n++],V=t[e++]^r[n++],Z=t[e++]^r[n++],O=s,j=c,Y=a,P=f,q=l,F=u,N=p,T=h,d=b,y=x,E=w,B=A,S=_,m=C,v=V,I=Z;for(let k=0;k<8;k+=2)q^=z(O+S|0,7),d^=z(q+O|0,9),S^=z(d+q|0,13),O^=z(S+d|0,18),y^=z(F+j|0,7),m^=z(y+F|0,9),j^=z(m+y|0,13),F^=z(j+m|0,18),v^=z(E+N|0,7),Y^=z(v+E|0,9),N^=z(Y+v|0,13),E^=z(N+Y|0,18),P^=z(I+B|0,7),T^=z(P+I|0,9),B^=z(T+P|0,13),I^=z(B+T|0,18),j^=z(O+P|0,7),Y^=z(j+O|0,9),P^=z(Y+j|0,13),O^=z(P+Y|0,18),N^=z(F+q|0,7),T^=z(N+F|0,9),q^=z(T+N|0,13),F^=z(q+T|0,18),B^=z(E+y|0,7),d^=z(B+E|0,9),y^=z(d+B|0,13),E^=z(y+d|0,18),S^=z(I+v|0,7),m^=z(S+I|0,9),v^=z(m+S|0,13),I^=z(v+m|0,18);i[o++]=s+O|0,i[o++]=c+j|0,i[o++]=a+Y|0,i[o++]=f+P|0,i[o++]=l+q|0,i[o++]=u+F|0,i[o++]=p+N|0,i[o++]=h+T|0,i[o++]=b+d|0,i[o++]=x+y|0,i[o++]=w+E|0,i[o++]=A+B|0,i[o++]=_+S|0,i[o++]=C+m|0,i[o++]=V+v|0,i[o++]=Z+I|0}function Vn(t,e,r,n,i){let o=n+0,s=n+16*i;for(let c=0;c<16;c++)r[s+c]=t[e+(2*i-1)*16+c];for(let c=0;c<i;c++,o+=16,e+=16)os(r,s,t,e,r,o),c>0&&(s+=16),os(r,o,t,e+=16,r,s)}function ff(t,e,r){let n=_t({dkLen:32,asyncTick:10,maxmem:1073742848},r),{N:i,r:o,p:s,dkLen:c,asyncTick:a,maxmem:f,onProgress:l}=n;if(Q(i,"N"),Q(o,"r"),Q(s,"p"),Q(c,"dkLen"),Q(a,"asyncTick"),Q(f,"maxmem"),l!==void 0&&typeof l!="function")throw new Error("progressCb must be a function");let u=128*o,p=u/4,h=Math.pow(2,32);if(i<=1||(i&i-1)!==0||i>h)throw new Error('"N" expected a power of 2, and 2^1 <= N <= 2^32');if(s<1||s>(h-1)*32/u)throw new Error('"p" expected integer 1..((2^32 - 1) * 32) / (128 * r)');if(c<1||c>(h-1)*32)throw new Error('"dkLen" expected integer 1..(2^32 - 1) * 32');if(u*(i+s)>f)throw new Error('"maxmem" limit was hit, expected 128*r*(N+p) <= "maxmem"='+f);let x=Hn(K,t,e,{c:1,dkLen:u*s}),w=Nt(x),A=Nt(new Uint8Array(u*i)),_=Nt(new Uint8Array(u)),C=()=>{};if(l){let V=2*i*s,Z=Math.max(Math.floor(V/1e4),1),O=0;C=()=>{O++,l&&(!(O%Z)||O===V)&&l(O/V)}}return{N:i,r:o,p:s,dkLen:c,blockSize32:p,V:A,B32:w,B:x,tmp:_,blockMixCb:C,asyncTick:a}}function uf(t,e,r,n,i){let o=Hn(K,t,r,{c:1,dkLen:e});return ye(r,n,i),o}function Fn(t,e,r){let{N:n,r:i,p:o,dkLen:s,blockSize32:c,V:a,B32:f,B:l,tmp:u,blockMixCb:p}=ff(t,e,r);hr(f);for(let h=0;h<o;h++){let b=c*h;for(let x=0;x<c;x++)a[x]=f[b+x];for(let x=0,w=0;x<n-1;x++)Vn(a,w,a,w+=c,i),p();Vn(a,(n-1)*c,f,b,i),p();for(let x=0;x<n;x++){let w=(f[b+c-16]&n-1)>>>0;for(let A=0;A<c;A++)u[A]=f[b+A]^a[w*c+A];Vn(u,0,f,b,i),p()}}return hr(f),uf(t,s,l,a,u)}function lf(t,e,r=16,n=2){let i=se(16),o=2**r,s=e.normalize("NFKC"),c=Fn(s,i,{N:o,r:8,p:1,dkLen:32}),a=se(24),f=Uint8Array.from([n]),u=Rn(c,a,f).encrypt(t),p=re(Uint8Array.from([2]),Uint8Array.from([r]),i,a,f,u),h=Rt.toWords(p);return Rt.encode("ncryptsec",h,200)}function df(t,e){let{prefix:r,words:n}=Rt.decode(t,200);if(r!=="ncryptsec")throw new Error("invalid ncryptsec prefix");let i=new Uint8Array(Rt.fromWords(n)),o=i[0];if(o!==2)throw new Error(`unknown ncryptsec version: ${o}`);let s=i[1],c=i.subarray(2,18),a=i.subarray(18,42),f=i[42],l=i.subarray(43),u=2**s,p=e.normalize("NFKC"),h=Fn(p,c,{N:u,r:8,p:1,dkLen:32}),b=Uint8Array.from([f]);return Rn(h,a,b).decrypt(l)}function ss(t){let e=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)e[r/2]=parseInt(t.slice(r,r+2),16);return e}function cs(t){return Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function as(t){return new TextEncoder().encode(t)}function fs(t){return new TextDecoder().decode(t)}return xs(hf);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
ieee754/index.js:
|