2024-04-26 15:34:43 -03:00

2137 lines
328 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var ue=Object.defineProperty;var he=(t,e,n)=>e in t?ue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var N=(t,e,n)=>(he(t,typeof e!="symbol"?e+"":e,n),n);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const i of s)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(s){if(s.ep)return;s.ep=!0;const i=n(s);fetch(s.href,i)}})();function noop(){}function run(t){return t()}function blank_object(){return Object.create(null)}function run_all(t){t.forEach(run)}function is_function(t){return typeof t=="function"}function safe_not_equal(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}let src_url_equal_anchor;function src_url_equal(t,e){return t===e?!0:(src_url_equal_anchor||(src_url_equal_anchor=document.createElement("a")),src_url_equal_anchor.href=e,t===src_url_equal_anchor.href)}function is_empty(t){return Object.keys(t).length===0}function append(t,e){t.appendChild(e)}function insert(t,e,n){t.insertBefore(e,n||null)}function detach(t){t.parentNode&&t.parentNode.removeChild(t)}function destroy_each(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function element(t){return document.createElement(t)}function svg_element(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function text(t){return document.createTextNode(t)}function space(){return text(" ")}function empty(){return text("")}function listen(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function attr(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function children(t){return Array.from(t.childNodes)}function set_data(t,e){e=""+e,t.data!==e&&(t.data=e)}function set_input_value(t,e){t.value=e??""}function set_style(t,e,n,r){n==null?t.style.removeProperty(e):t.style.setProperty(e,n,r?"important":"")}class HtmlTag{constructor(e=!1){N(this,"is_svg",!1);N(this,"e");N(this,"n");N(this,"t");N(this,"a");this.is_svg=e,this.e=this.n=null}c(e){this.h(e)}m(e,n,r=null){this.e||(this.is_svg?this.e=svg_element(n.nodeName):this.e=element(n.nodeType===11?"TEMPLATE":n.nodeName),this.t=n.tagName!=="TEMPLATE"?n:n.content,this.c(e)),this.i(r)}h(e){this.e.innerHTML=e,this.n=Array.from(this.e.nodeName==="TEMPLATE"?this.e.content.childNodes:this.e.childNodes)}i(e){for(let n=0;n<this.n.length;n+=1)insert(this.t,this.n[n],e)}p(e){this.d(),this.h(e),this.i(this.a)}d(){this.n.forEach(detach)}}let current_component;function set_current_component(t){current_component=t}const dirty_components=[],binding_callbacks=[];let render_callbacks=[];const flush_callbacks=[],resolved_promise=Promise.resolve();let update_scheduled=!1;function schedule_update(){update_scheduled||(update_scheduled=!0,resolved_promise.then(flush))}function add_render_callback(t){render_callbacks.push(t)}const seen_callbacks=new Set;let flushidx=0;function flush(){if(flushidx!==0)return;const t=current_component;do{try{for(;flushidx<dirty_components.length;){const e=dirty_components[flushidx];flushidx++,set_current_component(e),update(e.$$)}}catch(e){throw dirty_components.length=0,flushidx=0,e}for(set_current_component(null),dirty_components.length=0,flushidx=0;binding_callbacks.length;)binding_callbacks.pop()();for(let e=0;e<render_callbacks.length;e+=1){const n=render_callbacks[e];seen_callbacks.has(n)||(seen_callbacks.add(n),n())}render_callbacks.length=0}while(dirty_components.length);for(;flush_callbacks.length;)flush_callbacks.pop()();update_scheduled=!1,seen_callbacks.clear(),set_current_component(t)}function update(t){if(t.fragment!==null){t.update(),run_all(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(add_render_callback)}}function flush_render_callbacks(t){const e=[],n=[];render_callbacks.forEach(r=>t.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),render_callbacks=e}const outroing=new Set;function transition_in(t,e){t&&t.i&&(outroing.delete(t),t.i(e))}function ensure_array_like(t){return(t==null?void 0:t.length)!==void 0?t:Array.from(t)}function mount_component(t,e,n){const{fragment:r,after_update:s}=t.$$;r&&r.m(e,n),add_render_callback(()=>{const i=t.$$.on_mount.map(run).filter(is_function);t.$$.on_destroy?t.$$.on_destroy.push(...i):run_all(i),t.$$.on_mount=[]}),s.forEach(add_render_callback)}function destroy_component(t,e){const n=t.$$;n.fragment!==null&&(flush_render_callbacks(n.after_update),run_all(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function make_dirty(t,e){t.$$.dirty[0]===-1&&(dirty_components.push(t),schedule_update(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function init(t,e,n,r,s,i,o=null,a=[-1]){const c=current_component;set_current_component(t);const l=t.$$={fragment:null,ctx:[],props:i,update:noop,not_equal:s,bound:blank_object(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(c?c.$$.context:[])),callbacks:blank_object(),dirty:a,skip_bound:!1,root:e.target||c.$$.root};o&&o(l.root);let h=!1;if(l.ctx=n?n(t,e.props||{},(u,p,...g)=>{const m=g.length?g[0]:p;return l.ctx&&s(l.ctx[u],l.ctx[u]=m)&&(!l.skip_bound&&l.bound[u]&&l.bound[u](m),h&&make_dirty(t,u)),p}):[],l.update(),h=!0,run_all(l.before_update),l.fragment=r?r(l.ctx):!1,e.target){if(e.hydrate){const u=children(e.target);l.fragment&&l.fragment.l(u),u.forEach(detach)}else l.fragment&&l.fragment.c();e.intro&&transition_in(t.$$.fragment),mount_component(t,e.target,e.anchor),flush()}set_current_component(c)}class SvelteComponent{constructor(){N(this,"$$");N(this,"$$set")}$destroy(){destroy_component(this,1),this.$destroy=noop}$on(e,n){if(!is_function(n))return noop;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(n),()=>{const s=r.indexOf(n);s!==-1&&r.splice(s,1)}}$set(e){this.$$set&&!is_empty(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const PUBLIC_VERSION="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(PUBLIC_VERSION);function number$5(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function bool$3(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function bytes$5(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function hash$5(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number$5(t.outputLen),number$5(t.blockLen)}function exists$5(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 output$5(t,e){bytes$5(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const assert$3={number:number$5,bool:bool$3,bytes:bytes$5,hash:hash$5,exists:exists$5,output:output$5},crypto$4=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const u8a$4=t=>t instanceof Uint8Array,createView$4=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),rotr$4=(t,e)=>t<<32-e|t>>>e,isLE$4=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$4)throw new Error("Non little-endian hardware is not supported");const hexes$5=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function bytesToHex$5(t){if(!u8a$4(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=hexes$5[t[n]];return e}function hexToBytes$4(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const s=r*2,i=t.slice(s,s+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function utf8ToBytes$8(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function toBytes$5(t){if(typeof t=="string"&&(t=utf8ToBytes$8(t)),!u8a$4(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function concatBytes$6(...t){const e=new Uint8Array(t.reduce((r,s)=>r+s.length,0));let n=0;return t.forEach(r=>{if(!u8a$4(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}let Hash$4=class{clone(){return this._cloneInto()}};function wrapConstructor$4(t){const e=r=>t().update(toBytes$5(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function randomBytes$3(t=32){if(crypto$4&&typeof crypto$4.getRandomValues=="function")return crypto$4.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function setBigUint64$4(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const s=BigInt(32),i=BigInt(4294967295),o=Number(n>>s&i),a=Number(n&i),c=r?4:0,l=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+l,a,r)}let SHA2$3=class extends Hash$4{constructor(e,n,r,s){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=createView$4(this.buffer)}update(e){assert$3.exists(this);const{view:n,buffer:r,blockLen:s}=this;e=toBytes$5(e);const i=e.length;for(let o=0;o<i;){const a=Math.min(s-this.pos,i-o);if(a===s){const c=createView$4(e);for(;s<=i-o;o+=s)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){assert$3.exists(this),assert$3.output(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:s,isLE:i}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(r,0),o=0);for(let u=o;u<s;u++)n[u]=0;setBigUint64$4(r,s-8,BigInt(this.length*8),i),this.process(r,0);const a=createView$4(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,h[u],i)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%n&&e.buffer.set(r),e}};const Chi$4=(t,e,n)=>t&e^~t&n,Maj$4=(t,e,n)=>t&e^t&n^e&n,SHA256_K$4=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV$3=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W$4=new Uint32Array(64);let SHA256$4=class extends SHA2$3{constructor(){super(64,32,8,!1),this.A=IV$3[0]|0,this.B=IV$3[1]|0,this.C=IV$3[2]|0,this.D=IV$3[3]|0,this.E=IV$3[4]|0,this.F=IV$3[5]|0,this.G=IV$3[6]|0,this.H=IV$3[7]|0}get(){const{A:e,B:n,C:r,D:s,E:i,F:o,G:a,H:c}=this;return[e,n,r,s,i,o,a,c]}set(e,n,r,s,i,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let u=0;u<16;u++,n+=4)SHA256_W$4[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const p=SHA256_W$4[u-15],g=SHA256_W$4[u-2],m=rotr$4(p,7)^rotr$4(p,18)^p>>>3,d=rotr$4(g,17)^rotr$4(g,19)^g>>>10;SHA256_W$4[u]=d+SHA256_W$4[u-7]+m+SHA256_W$4[u-16]|0}let{A:r,B:s,C:i,D:o,E:a,F:c,G:l,H:h}=this;for(let u=0;u<64;u++){const p=rotr$4(a,6)^rotr$4(a,11)^rotr$4(a,25),g=h+p+Chi$4(a,c,l)+SHA256_K$4[u]+SHA256_W$4[u]|0,d=(rotr$4(r,2)^rotr$4(r,13)^rotr$4(r,22))+Maj$4(r,s,i)|0;h=l,l=c,c=a,a=o+g|0,o=i,i=s,s=r,r=g+d|0}r=r+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(r,s,i,o,a,c,l,h)}roundClean(){SHA256_W$4.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},SHA224$1=class extends SHA256$4{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const sha256$4=wrapConstructor$4(()=>new SHA256$4);wrapConstructor$4(()=>new SHA224$1);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$d=BigInt(0),_1n$e=BigInt(1),_2n$8=BigInt(2),u8a$3=t=>t instanceof Uint8Array,hexes$4=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function bytesToHex$4(t){if(!u8a$3(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=hexes$4[t[n]];return e}function numberToHexUnpadded$2(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function hexToNumber$2(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function hexToBytes$3(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const s=r*2,i=t.slice(s,s+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function bytesToNumberBE$2(t){return hexToNumber$2(bytesToHex$4(t))}function bytesToNumberLE$2(t){if(!u8a$3(t))throw new Error("Uint8Array expected");return hexToNumber$2(bytesToHex$4(Uint8Array.from(t).reverse()))}function numberToBytesBE$2(t,e){return hexToBytes$3(t.toString(16).padStart(e*2,"0"))}function numberToBytesLE$2(t,e){return numberToBytesBE$2(t,e).reverse()}function numberToVarBytesBE$2(t){return hexToBytes$3(numberToHexUnpadded$2(t))}function ensureBytes$3(t,e,n){let r;if(typeof e=="string")try{r=hexToBytes$3(e)}catch(i){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${i}`)}else if(u8a$3(e))r=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);const s=r.length;if(typeof n=="number"&&s!==n)throw new Error(`${t} expected ${n} bytes, got ${s}`);return r}function concatBytes$5(...t){const e=new Uint8Array(t.reduce((r,s)=>r+s.length,0));let n=0;return t.forEach(r=>{if(!u8a$3(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}function equalBytes$3(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function utf8ToBytes$7(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function bitLen$2(t){let e;for(e=0;t>_0n$d;t>>=_1n$e,e+=1);return e}function bitGet$2(t,e){return t>>BigInt(e)&_1n$e}const bitSet$2=(t,e,n)=>t|(n?_1n$e:_0n$d)<<BigInt(e),bitMask$2=t=>(_2n$8<<BigInt(t-1))-_1n$e,u8n$2=t=>new Uint8Array(t),u8fr$2=t=>Uint8Array.from(t);function createHmacDrbg$2(t,e,n){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=u8n$2(t),s=u8n$2(t),i=0;const o=()=>{r.fill(1),s.fill(0),i=0},a=(...u)=>n(s,r,...u),c=(u=u8n$2())=>{s=a(u8fr$2([0]),u),r=a(),u.length!==0&&(s=a(u8fr$2([1]),u),r=a())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const p=[];for(;u<e;){r=a();const g=r.slice();p.push(g),u+=r.length}return concatBytes$5(...p)};return(u,p)=>{o(),c(u);let g;for(;!(g=p(l()));)c();return o(),g}}const validatorFns$2={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function validateObject$2(t,e,n={}){const r=(s,i,o)=>{const a=validatorFns$2[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);const c=t[s];if(!(o&&c===void 0)&&!a(c,t))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${i}`)};for(const[s,i]of Object.entries(e))r(s,i,!1);for(const[s,i]of Object.entries(n))r(s,i,!0);return t}const ut$2=Object.freeze(Object.defineProperty({__proto__:null,bitGet:bitGet$2,bitLen:bitLen$2,bitMask:bitMask$2,bitSet:bitSet$2,bytesToHex:bytesToHex$4,bytesToNumberBE:bytesToNumberBE$2,bytesToNumberLE:bytesToNumberLE$2,concatBytes:concatBytes$5,createHmacDrbg:createHmacDrbg$2,ensureBytes:ensureBytes$3,equalBytes:equalBytes$3,hexToBytes:hexToBytes$3,hexToNumber:hexToNumber$2,numberToBytesBE:numberToBytesBE$2,numberToBytesLE:numberToBytesLE$2,numberToHexUnpadded:numberToHexUnpadded$2,numberToVarBytesBE:numberToVarBytesBE$2,utf8ToBytes:utf8ToBytes$7,validateObject:validateObject$2},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$c=BigInt(0),_1n$d=BigInt(1),_2n$7=BigInt(2),_3n$5=BigInt(3),_4n$2=BigInt(4),_5n$2=BigInt(5),_8n$2=BigInt(8);BigInt(9);BigInt(16);function mod$2(t,e){const n=t%e;return n>=_0n$c?n:e+n}function pow$2(t,e,n){if(n<=_0n$c||e<_0n$c)throw new Error("Expected power/modulo > 0");if(n===_1n$d)return _0n$c;let r=_1n$d;for(;e>_0n$c;)e&_1n$d&&(r=r*t%n),t=t*t%n,e>>=_1n$d;return r}function pow2$2(t,e,n){let r=t;for(;e-- >_0n$c;)r*=r,r%=n;return r}function invert$2(t,e){if(t===_0n$c||e<=_0n$c)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=mod$2(t,e),r=e,s=_0n$c,i=_1n$d;for(;n!==_0n$c;){const a=r/n,c=r%n,l=s-i*a;r=n,n=c,s=i,i=l}if(r!==_1n$d)throw new Error("invert: does not exist");return mod$2(s,e)}function tonelliShanks$2(t){const e=(t-_1n$d)/_2n$7;let n,r,s;for(n=t-_1n$d,r=0;n%_2n$7===_0n$c;n/=_2n$7,r++);for(s=_2n$7;s<t&&pow$2(s,e,t)!==t-_1n$d;s++);if(r===1){const o=(t+_1n$d)/_4n$2;return function(c,l){const h=c.pow(l,o);if(!c.eql(c.sqr(h),l))throw new Error("Cannot find square root");return h}}const i=(n+_1n$d)/_2n$7;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=r,h=a.pow(a.mul(a.ONE,s),n),u=a.pow(c,i),p=a.pow(c,n);for(;!a.eql(p,a.ONE);){if(a.eql(p,a.ZERO))return a.ZERO;let g=1;for(let d=a.sqr(p);g<l&&!a.eql(d,a.ONE);g++)d=a.sqr(d);const m=a.pow(h,_1n$d<<BigInt(l-g-1));h=a.sqr(m),u=a.mul(u,m),p=a.mul(p,h),l=g}return u}}function FpSqrt$2(t){if(t%_4n$2===_3n$5){const e=(t+_1n$d)/_4n$2;return function(r,s){const i=r.pow(s,e);if(!r.eql(r.sqr(i),s))throw new Error("Cannot find square root");return i}}if(t%_8n$2===_5n$2){const e=(t-_5n$2)/_8n$2;return function(r,s){const i=r.mul(s,_2n$7),o=r.pow(i,e),a=r.mul(s,o),c=r.mul(r.mul(a,_2n$7),o),l=r.mul(a,r.sub(c,r.ONE));if(!r.eql(r.sqr(l),s))throw new Error("Cannot find square root");return l}}return tonelliShanks$2(t)}const FIELD_FIELDS$2=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function validateField$2(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=FIELD_FIELDS$2.reduce((r,s)=>(r[s]="function",r),e);return validateObject$2(t,n)}function FpPow$2(t,e,n){if(n<_0n$c)throw new Error("Expected power > 0");if(n===_0n$c)return t.ONE;if(n===_1n$d)return e;let r=t.ONE,s=e;for(;n>_0n$c;)n&_1n$d&&(r=t.mul(r,s)),s=t.sqr(s),n>>=_1n$d;return r}function FpInvertBatch$2(t,e){const n=new Array(e.length),r=e.reduce((i,o,a)=>t.is0(o)?i:(n[a]=i,t.mul(i,o)),t.ONE),s=t.inv(r);return e.reduceRight((i,o,a)=>t.is0(o)?i:(n[a]=t.mul(i,n[a]),t.mul(i,o)),s),n}function nLength$2(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Field$2(t,e,n=!1,r={}){if(t<=_0n$c)throw new Error(`Expected Fp ORDER > 0, got ${t}`);const{nBitLength:s,nByteLength:i}=nLength$2(t,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=FpSqrt$2(t),a=Object.freeze({ORDER:t,BITS:s,BYTES:i,MASK:bitMask$2(s),ZERO:_0n$c,ONE:_1n$d,create:c=>mod$2(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return _0n$c<=c&&c<t},is0:c=>c===_0n$c,isOdd:c=>(c&_1n$d)===_1n$d,neg:c=>mod$2(-c,t),eql:(c,l)=>c===l,sqr:c=>mod$2(c*c,t),add:(c,l)=>mod$2(c+l,t),sub:(c,l)=>mod$2(c-l,t),mul:(c,l)=>mod$2(c*l,t),pow:(c,l)=>FpPow$2(a,c,l),div:(c,l)=>mod$2(c*invert$2(l,t),t),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>invert$2(c,t),sqrt:r.sqrt||(c=>o(a,c)),invertBatch:c=>FpInvertBatch$2(a,c),cmov:(c,l,h)=>h?l:c,toBytes:c=>n?numberToBytesLE$2(c,i):numberToBytesBE$2(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return n?bytesToNumberLE$2(c):bytesToNumberBE$2(c)}});return Object.freeze(a)}function hashToPrivateScalar$1(t,e,n=!1){t=ensureBytes$3("privateHash",t);const r=t.length,s=nLength$2(e).nByteLength+8;if(s<24||r<s||r>1024)throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${r}`);const i=n?bytesToNumberLE$2(t):bytesToNumberBE$2(t);return mod$2(i,e-_1n$d)+_1n$d}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$b=BigInt(0),_1n$c=BigInt(1);function wNAF$2(t,e){const n=(s,i)=>{const o=i.negate();return s?o:i},r=s=>{const i=Math.ceil(e/s)+1,o=2**(s-1);return{windows:i,windowSize:o}};return{constTimeNegate:n,unsafeLadder(s,i){let o=t.ZERO,a=s;for(;i>_0n$b;)i&_1n$c&&(o=o.add(a)),a=a.double(),i>>=_1n$c;return o},precomputeWindow(s,i){const{windows:o,windowSize:a}=r(i),c=[];let l=s,h=l;for(let u=0;u<o;u++){h=l,c.push(h);for(let p=1;p<a;p++)h=h.add(l),c.push(h);l=h.double()}return c},wNAF(s,i,o){const{windows:a,windowSize:c}=r(s);let l=t.ZERO,h=t.BASE;const u=BigInt(2**s-1),p=2**s,g=BigInt(s);for(let m=0;m<a;m++){const d=m*c;let w=Number(o&u);o>>=g,w>c&&(w-=p,o+=_1n$c);const $=d,_=d+Math.abs(w)-1,x=m%2!==0,I=w<0;w===0?h=h.add(n(x,i[$])):l=l.add(n(I,i[_]))}return{p:l,f:h}},wNAFCached(s,i,o,a){const c=s._WINDOW_SIZE||1;let l=i.get(s);return l||(l=this.precomputeWindow(s,c),c!==1&&i.set(s,a(l))),this.wNAF(c,l,o)}}}function validateBasic$2(t){return validateField$2(t.Fp),validateObject$2(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...nLength$2(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function validatePointOpts$2(t){const e=validateBasic$2(t);validateObject$2(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:s}=e;if(n){if(!r.eql(s,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}const{bytesToNumberBE:b2n$2,hexToBytes:h2b$2}=ut$2,DER$2={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=DER$2;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");const n=t[1],r=t.subarray(2,n+2);if(!n||r.length!==n)throw new e("Invalid signature integer: wrong length");if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:b2n$2(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=DER$2,n=typeof t=="string"?h2b$2(t):t;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new e("Invalid signature tag");if(n[1]!==r-2)throw new e("Invalid signature: incorrect length");const{d:s,l:i}=DER$2._parseInt(n.subarray(2)),{d:o,l:a}=DER$2._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:s,s:o}},hexFromSig(t){const e=l=>Number.parseInt(l[0],16)&8?"00"+l:l,n=l=>{const h=l.toString(16);return h.length&1?`0${h}`:h},r=e(n(t.s)),s=e(n(t.r)),i=r.length/2,o=s.length/2,a=n(i),c=n(o);return`30${n(o+i+4)}02${c}${s}02${a}${r}`}},_0n$a=BigInt(0),_1n$b=BigInt(1);BigInt(2);const _3n$4=BigInt(3);BigInt(4);function weierstrassPoints$2(t){const e=validatePointOpts$2(t),{Fp:n}=e,r=e.toBytes||((m,d,w)=>{const $=d.toAffine();return concatBytes$5(Uint8Array.from([4]),n.toBytes($.x),n.toBytes($.y))}),s=e.fromBytes||(m=>{const d=m.subarray(1),w=n.fromBytes(d.subarray(0,n.BYTES)),$=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:w,y:$}});function i(m){const{a:d,b:w}=e,$=n.sqr(m),_=n.mul($,m);return n.add(n.add(_,n.mul(m,d)),w)}if(!n.eql(n.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function o(m){return typeof m=="bigint"&&_0n$a<m&&m<e.n}function a(m){if(!o(m))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(m){const{allowedPrivateKeyLengths:d,nByteLength:w,wrapPrivateKey:$,n:_}=e;if(d&&typeof m!="bigint"){if(m instanceof Uint8Array&&(m=bytesToHex$4(m)),typeof m!="string"||!d.includes(m.length))throw new Error("Invalid key");m=m.padStart(w*2,"0")}let x;try{x=typeof m=="bigint"?m:bytesToNumberBE$2(ensureBytes$3("private key",m,w))}catch{throw new Error(`private key must be ${w} bytes, hex or bigint, not ${typeof m}`)}return $&&(x=mod$2(x,_)),a(x),x}const l=new Map;function h(m){if(!(m instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,w,$){if(this.px=d,this.py=w,this.pz=$,d==null||!n.isValid(d))throw new Error("x required");if(w==null||!n.isValid(w))throw new Error("y required");if($==null||!n.isValid($))throw new Error("z required")}static fromAffine(d){const{x:w,y:$}=d||{};if(!d||!n.isValid(w)||!n.isValid($))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");const _=x=>n.eql(x,n.ZERO);return _(w)&&_($)?u.ZERO:new u(w,$,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const w=n.invertBatch(d.map($=>$.pz));return d.map(($,_)=>$.toAffine(w[_])).map(u.fromAffine)}static fromHex(d){const w=u.fromAffine(s(ensureBytes$3("pointHex",d)));return w.assertValidity(),w}static fromPrivateKey(d){return u.BASE.multiply(c(d))}_setWindowSize(d){this._WINDOW_SIZE=d,l.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:d,y:w}=this.toAffine();if(!n.isValid(d)||!n.isValid(w))throw new Error("bad point: x or y not FE");const $=n.sqr(w),_=i(d);if(!n.eql($,_))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:d}=this.toAffine();if(n.isOdd)return!n.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){h(d);const{px:w,py:$,pz:_}=this,{px:x,py:I,pz:R}=d,v=n.eql(n.mul(w,R),n.mul(x,_)),B=n.eql(n.mul($,R),n.mul(I,_));return v&&B}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:w}=e,$=n.mul(w,_3n$4),{px:_,py:x,pz:I}=this;let R=n.ZERO,v=n.ZERO,B=n.ZERO,S=n.mul(_,_),H=n.mul(x,x),L=n.mul(I,I),E=n.mul(_,x);return E=n.add(E,E),B=n.mul(_,I),B=n.add(B,B),R=n.mul(d,B),v=n.mul($,L),v=n.add(R,v),R=n.sub(H,v),v=n.add(H,v),v=n.mul(R,v),R=n.mul(E,R),B=n.mul($,B),L=n.mul(d,L),E=n.sub(S,L),E=n.mul(d,E),E=n.add(E,B),B=n.add(S,S),S=n.add(B,S),S=n.add(S,L),S=n.mul(S,E),v=n.add(v,S),L=n.mul(x,I),L=n.add(L,L),S=n.mul(L,E),R=n.sub(R,S),B=n.mul(L,H),B=n.add(B,B),B=n.add(B,B),new u(R,v,B)}add(d){h(d);const{px:w,py:$,pz:_}=this,{px:x,py:I,pz:R}=d;let v=n.ZERO,B=n.ZERO,S=n.ZERO;const H=e.a,L=n.mul(e.b,_3n$4);let E=n.mul(w,x),k=n.mul($,I),T=n.mul(_,R),P=n.add(w,$),y=n.add(x,I);P=n.mul(P,y),y=n.add(E,k),P=n.sub(P,y),y=n.add(w,_);let b=n.add(x,R);return y=n.mul(y,b),b=n.add(E,T),y=n.sub(y,b),b=n.add($,_),v=n.add(I,R),b=n.mul(b,v),v=n.add(k,T),b=n.sub(b,v),S=n.mul(H,y),v=n.mul(L,T),S=n.add(v,S),v=n.sub(k,S),S=n.add(k,S),B=n.mul(v,S),k=n.add(E,E),k=n.add(k,E),T=n.mul(H,T),y=n.mul(L,y),k=n.add(k,T),T=n.sub(E,T),T=n.mul(H,T),y=n.add(y,T),E=n.mul(k,y),B=n.add(B,E),E=n.mul(b,y),v=n.mul(P,v),v=n.sub(v,E),E=n.mul(P,k),S=n.mul(b,S),S=n.add(S,E),new u(v,B,S)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return g.wNAFCached(this,l,d,w=>{const $=n.invertBatch(w.map(_=>_.pz));return w.map((_,x)=>_.toAffine($[x])).map(u.fromAffine)})}multiplyUnsafe(d){const w=u.ZERO;if(d===_0n$a)return w;if(a(d),d===_1n$b)return this;const{endo:$}=e;if(!$)return g.unsafeLadder(this,d);let{k1neg:_,k1:x,k2neg:I,k2:R}=$.splitScalar(d),v=w,B=w,S=this;for(;x>_0n$a||R>_0n$a;)x&_1n$b&&(v=v.add(S)),R&_1n$b&&(B=B.add(S)),S=S.double(),x>>=_1n$b,R>>=_1n$b;return _&&(v=v.negate()),I&&(B=B.negate()),B=new u(n.mul(B.px,$.beta),B.py,B.pz),v.add(B)}multiply(d){a(d);let w=d,$,_;const{endo:x}=e;if(x){const{k1neg:I,k1:R,k2neg:v,k2:B}=x.splitScalar(w);let{p:S,f:H}=this.wNAF(R),{p:L,f:E}=this.wNAF(B);S=g.constTimeNegate(I,S),L=g.constTimeNegate(v,L),L=new u(n.mul(L.px,x.beta),L.py,L.pz),$=S.add(L),_=H.add(E)}else{const{p:I,f:R}=this.wNAF(w);$=I,_=R}return u.normalizeZ([$,_])[0]}multiplyAndAddUnsafe(d,w,$){const _=u.BASE,x=(R,v)=>v===_0n$a||v===_1n$b||!R.equals(_)?R.multiplyUnsafe(v):R.multiply(v),I=x(this,w).add(x(d,$));return I.is0()?void 0:I}toAffine(d){const{px:w,py:$,pz:_}=this,x=this.is0();d==null&&(d=x?n.ONE:n.inv(_));const I=n.mul(w,d),R=n.mul($,d),v=n.mul(_,d);if(x)return{x:n.ZERO,y:n.ZERO};if(!n.eql(v,n.ONE))throw new Error("invZ was invalid");return{x:I,y:R}}isTorsionFree(){const{h:d,isTorsionFree:w}=e;if(d===_1n$b)return!0;if(w)return w(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:w}=e;return d===_1n$b?this:w?w(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return bytesToHex$4(this.toRawBytes(d))}}u.BASE=new u(e.Gx,e.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const p=e.nBitLength,g=wNAF$2(u,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:o}}function validateOpts$2(t){const e=validateBasic$2(t);return validateObject$2(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function weierstrass$2(t){const e=validateOpts$2(t),{Fp:n,n:r}=e,s=n.BYTES+1,i=2*n.BYTES+1;function o(y){return _0n$a<y&&y<n.ORDER}function a(y){return mod$2(y,r)}function c(y){return invert$2(y,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:h,weierstrassEquation:u,isWithinCurveOrder:p}=weierstrassPoints$2({...e,toBytes(y,b,A){const U=b.toAffine(),C=n.toBytes(U.x),D=concatBytes$5;return A?D(Uint8Array.from([b.hasEvenY()?2:3]),C):D(Uint8Array.from([4]),C,n.toBytes(U.y))},fromBytes(y){const b=y.length,A=y[0],U=y.subarray(1);if(b===s&&(A===2||A===3)){const C=bytesToNumberBE$2(U);if(!o(C))throw new Error("Point is not on curve");const D=u(C);let F=n.sqrt(D);const O=(F&_1n$b)===_1n$b;return(A&1)===1!==O&&(F=n.neg(F)),{x:C,y:F}}else if(b===i&&A===4){const C=n.fromBytes(U.subarray(0,n.BYTES)),D=n.fromBytes(U.subarray(n.BYTES,2*n.BYTES));return{x:C,y:D}}else throw new Error(`Point of length ${b} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),g=y=>bytesToHex$4(numberToBytesBE$2(y,e.nByteLength));function m(y){const b=r>>_1n$b;return y>b}function d(y){return m(y)?a(-y):y}const w=(y,b,A)=>bytesToNumberBE$2(y.slice(b,A));class ${constructor(b,A,U){this.r=b,this.s=A,this.recovery=U,this.assertValidity()}static fromCompact(b){const A=e.nByteLength;return b=ensureBytes$3("compactSignature",b,A*2),new $(w(b,0,A),w(b,A,2*A))}static fromDER(b){const{r:A,s:U}=DER$2.toSig(ensureBytes$3("DER",b));return new $(A,U)}assertValidity(){if(!p(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!p(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(b){return new $(this.r,this.s,b)}recoverPublicKey(b){const{r:A,s:U,recovery:C}=this,D=B(ensureBytes$3("msgHash",b));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");const F=C===2||C===3?A+e.n:A;if(F>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const O=C&1?"03":"02",K=l.fromHex(O+g(F)),M=c(F),z=a(-D*M),V=a(U*M),q=l.BASE.multiplyAndAddUnsafe(K,z,V);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new $(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return hexToBytes$3(this.toDERHex())}toDERHex(){return DER$2.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hexToBytes$3(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}const _={isValidPrivateKey(y){try{return h(y),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const y=e.randomBytes(n.BYTES+8),b=hashToPrivateScalar$1(y,r);return numberToBytesBE$2(b,e.nByteLength)},precompute(y=8,b=l.BASE){return b._setWindowSize(y),b.multiply(BigInt(3)),b}};function x(y,b=!0){return l.fromPrivateKey(y).toRawBytes(b)}function I(y){const b=y instanceof Uint8Array,A=typeof y=="string",U=(b||A)&&y.length;return b?U===s||U===i:A?U===2*s||U===2*i:y instanceof l}function R(y,b,A=!0){if(I(y))throw new Error("first arg must be private key");if(!I(b))throw new Error("second arg must be public key");return l.fromHex(b).multiply(h(y)).toRawBytes(A)}const v=e.bits2int||function(y){const b=bytesToNumberBE$2(y),A=y.length*8-e.nBitLength;return A>0?b>>BigInt(A):b},B=e.bits2int_modN||function(y){return a(v(y))},S=bitMask$2(e.nBitLength);function H(y){if(typeof y!="bigint")throw new Error("bigint expected");if(!(_0n$a<=y&&y<S))throw new Error(`bigint expected < 2^${e.nBitLength}`);return numberToBytesBE$2(y,e.nByteLength)}function L(y,b,A=E){if(["recovered","canonical"].some(W=>W in A))throw new Error("sign() legacy options not supported");const{hash:U,randomBytes:C}=e;let{lowS:D,prehash:F,extraEntropy:O}=A;D==null&&(D=!0),y=ensureBytes$3("msgHash",y),F&&(y=ensureBytes$3("prehashed msgHash",U(y)));const K=B(y),M=h(b),z=[H(M),H(K)];if(O!=null){const W=O===!0?C(n.BYTES):O;z.push(ensureBytes$3("extraEntropy",W,n.BYTES))}const V=concatBytes$5(...z),q=K;function G(W){const Z=v(W);if(!p(Z))return;const J=c(Z),Y=l.BASE.multiply(Z).toAffine(),j=a(Y.x);if(j===_0n$a)return;const X=a(J*a(q+j*M));if(X===_0n$a)return;let Q=(Y.x===j?0:2)|Number(Y.y&_1n$b),te=X;return D&&m(X)&&(te=d(X),Q^=1),new $(j,te,Q)}return{seed:V,k2sig:G}}const E={lowS:e.lowS,prehash:!1},k={lowS:e.lowS,prehash:!1};function T(y,b,A=E){const{seed:U,k2sig:C}=L(y,b,A),D=e;return createHmacDrbg$2(D.hash.outputLen,D.nByteLength,D.hmac)(U,C)}l.BASE._setWindowSize(8);function P(y,b,A,U=k){var Y;const C=y;if(b=ensureBytes$3("msgHash",b),A=ensureBytes$3("publicKey",A),"strict"in U)throw new Error("options.strict was renamed to lowS");const{lowS:D,prehash:F}=U;let O,K;try{if(typeof C=="string"||C instanceof Uint8Array)try{O=$.fromDER(C)}catch(j){if(!(j instanceof DER$2.Err))throw j;O=$.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){const{r:j,s:X}=C;O=new $(j,X)}else throw new Error("PARSE");K=l.fromHex(A)}catch(j){if(j.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(D&&O.hasHighS())return!1;F&&(b=e.hash(b));const{r:M,s:z}=O,V=B(b),q=c(z),G=a(V*q),W=a(M*q),Z=(Y=l.BASE.multiplyAndAddUnsafe(K,G,W))==null?void 0:Y.toAffine();return Z?a(Z.x)===M:!1}return{CURVE:e,getPublicKey:x,getSharedSecret:R,sign:T,verify:P,ProjectivePoint:l,Signature:$,utils:_}}let HMAC$4=class extends Hash$4{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,assert$3.hash(e);const r=toBytes$5(n);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,i=new Uint8Array(s);i.set(r.length>s?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),i.fill(0)}update(e){return assert$3.exists(this),this.iHash.update(e),this}digestInto(e){assert$3.exists(this),assert$3.bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const hmac$4=(t,e,n)=>new HMAC$4(t,e).update(n).digest();hmac$4.create=(t,e)=>new HMAC$4(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function getHash$2(t){return{hash:t,hmac:(e,...n)=>hmac$4(t,e,concatBytes$6(...n)),randomBytes:randomBytes$3}}function createCurve$2(t,e){const n=r=>weierstrass$2({...t,...getHash$2(r)});return Object.freeze({...n(e),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const secp256k1P$2=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),secp256k1N$2=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),_1n$a=BigInt(1),_2n$6=BigInt(2),divNearest$2=(t,e)=>(t+e/_2n$6)/e;function sqrtMod$2(t){const e=secp256k1P$2,n=BigInt(3),r=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),l=t*t*t%e,h=l*l*t%e,u=pow2$2(h,n,e)*h%e,p=pow2$2(u,n,e)*h%e,g=pow2$2(p,_2n$6,e)*l%e,m=pow2$2(g,s,e)*g%e,d=pow2$2(m,i,e)*m%e,w=pow2$2(d,a,e)*d%e,$=pow2$2(w,c,e)*w%e,_=pow2$2($,a,e)*d%e,x=pow2$2(_,n,e)*h%e,I=pow2$2(x,o,e)*m%e,R=pow2$2(I,r,e)*l%e,v=pow2$2(R,_2n$6,e);if(!Fp$2.eql(Fp$2.sqr(v),t))throw new Error("Cannot find square root");return v}const Fp$2=Field$2(secp256k1P$2,void 0,void 0,{sqrt:sqrtMod$2}),secp256k1$2=createCurve$2({a:BigInt(0),b:BigInt(7),Fp:Fp$2,n:secp256k1N$2,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=secp256k1N$2,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-_1n$a*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,o=BigInt("0x100000000000000000000000000000000"),a=divNearest$2(i*t,e),c=divNearest$2(-r*t,e);let l=mod$2(t-a*n-c*s,e),h=mod$2(-a*r-c*i,e);const u=l>o,p=h>o;if(u&&(l=e-l),p&&(h=e-h),l>o||h>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:l,k2neg:p,k2:h}}}},sha256$4),_0n$9=BigInt(0),fe$1=t=>typeof t=="bigint"&&_0n$9<t&&t<secp256k1P$2,ge$1=t=>typeof t=="bigint"&&_0n$9<t&&t<secp256k1N$2,TAGGED_HASH_PREFIXES$1={};function taggedHash$1(t,...e){let n=TAGGED_HASH_PREFIXES$1[t];if(n===void 0){const r=sha256$4(Uint8Array.from(t,s=>s.charCodeAt(0)));n=concatBytes$5(r,r),TAGGED_HASH_PREFIXES$1[t]=n}return sha256$4(concatBytes$5(n,...e))}const pointToBytes$1=t=>t.toRawBytes(!0).slice(1),numTo32b$1=t=>numberToBytesBE$2(t,32),modP$1=t=>mod$2(t,secp256k1P$2),modN$1=t=>mod$2(t,secp256k1N$2),Point$2=secp256k1$2.ProjectivePoint,GmulAdd$1=(t,e,n)=>Point$2.BASE.multiplyAndAddUnsafe(t,e,n);function schnorrGetExtPubKey$1(t){let e=secp256k1$2.utils.normPrivateKeyToScalar(t),n=Point$2.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:modN$1(-e),bytes:pointToBytes$1(n)}}function lift_x$1(t){if(!fe$1(t))throw new Error("bad x: need 0 < x < p");const e=modP$1(t*t),n=modP$1(e*t+BigInt(7));let r=sqrtMod$2(n);r%_2n$6!==_0n$9&&(r=modP$1(-r));const s=new Point$2(t,r,_1n$a);return s.assertValidity(),s}function challenge$1(...t){return modN$1(bytesToNumberBE$2(taggedHash$1("BIP0340/challenge",...t)))}function schnorrGetPublicKey$1(t){return schnorrGetExtPubKey$1(t).bytes}function schnorrSign$1(t,e,n=randomBytes$3(32)){const r=ensureBytes$3("message",t),{bytes:s,scalar:i}=schnorrGetExtPubKey$1(e),o=ensureBytes$3("auxRand",n,32),a=numTo32b$1(i^bytesToNumberBE$2(taggedHash$1("BIP0340/aux",o))),c=taggedHash$1("BIP0340/nonce",a,s,r),l=modN$1(bytesToNumberBE$2(c));if(l===_0n$9)throw new Error("sign failed: k is zero");const{bytes:h,scalar:u}=schnorrGetExtPubKey$1(l),p=challenge$1(h,s,r),g=new Uint8Array(64);if(g.set(h,0),g.set(numTo32b$1(modN$1(u+p*i)),32),!schnorrVerify$1(g,r,s))throw new Error("sign: Invalid signature produced");return g}function schnorrVerify$1(t,e,n){const r=ensureBytes$3("signature",t,64),s=ensureBytes$3("message",e),i=ensureBytes$3("publicKey",n,32);try{const o=lift_x$1(bytesToNumberBE$2(i)),a=bytesToNumberBE$2(r.subarray(0,32));if(!fe$1(a))return!1;const c=bytesToNumberBE$2(r.subarray(32,64));if(!ge$1(c))return!1;const l=challenge$1(numTo32b$1(a),pointToBytes$1(o),s),h=GmulAdd$1(o,c,modN$1(-l));return!(!h||!h.hasEvenY()||h.toAffine().x!==a)}catch{return!1}}const schnorr$1={getPublicKey:schnorrGetPublicKey$1,sign:schnorrSign$1,verify:schnorrVerify$1,utils:{randomPrivateKey:secp256k1$2.utils.randomPrivateKey,lift_x:lift_x$1,pointToBytes:pointToBytes$1,numberToBytesBE:numberToBytesBE$2,bytesToNumberBE:bytesToNumberBE$2,taggedHash:taggedHash$1,mod:mod$2}};/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function assertNumber(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function chain$1(...t){const e=(s,i)=>o=>s(i(o)),n=Array.from(t).reverse().reduce((s,i)=>s?e(s,i.encode):i.encode,void 0),r=t.reduce((s,i)=>s?e(s,i.decode):i.decode,void 0);return{encode:n,decode:r}}function alphabet$1(t){return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return e.map(n=>{if(assertNumber(n),n<0||n>=t.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${t.length})`);return t[n]})},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("alphabet.decode input should be array of strings");return e.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=t.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${t}`);return r})}}}function join$1(t=""){if(typeof t!="string")throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of e)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return e.join(t)},decode:e=>{if(typeof e!="string")throw new Error("join.decode input should be string");return e.split(t)}}}function padding$1(t,e="="){if(assertNumber(t),typeof e!="string")throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let r of n)if(typeof r!="string")throw new Error(`padding.encode: non-string input=${r}`);for(;n.length*t%8;)n.push(e);return n},decode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let s of n)if(typeof s!="string")throw new Error(`padding.decode: non-string input=${s}`);let r=n.length;if(r*t%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if(!((r-1)*t%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function normalize$2(t){if(typeof t!="function")throw new Error("normalize fn should be function");return{encode:e=>e,decode:e=>t(e)}}function convertRadix$1(t,e,n){if(e<2)throw new Error(`convertRadix: wrong from=${e}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(t))throw new Error("convertRadix: data should be array");if(!t.length)return[];let r=0;const s=[],i=Array.from(t);for(i.forEach(o=>{if(assertNumber(o),o<0||o>=e)throw new Error(`Wrong integer: ${o}`)});;){let o=0,a=!0;for(let c=r;c<i.length;c++){const l=i[c],h=e*o+l;if(!Number.isSafeInteger(h)||e*o/e!==o||h-l!==e*o)throw new Error("convertRadix: carry overflow");if(o=h%n,i[c]=Math.floor(h/n),!Number.isSafeInteger(i[c])||i[c]*n+o!==h)throw new Error("convertRadix: carry overflow");if(a)i[c]?a=!1:r=c;else continue}if(s.push(o),a)break}for(let o=0;o<t.length-1&&t[o]===0;o++)s.push(0);return s.reverse()}const gcd$1=(t,e)=>e?gcd$1(e,t%e):t,radix2carry$1=(t,e)=>t+(e-gcd$1(t,e));function convertRadix2$1(t,e,n,r){if(!Array.isArray(t))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(radix2carry$1(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${radix2carry$1(e,n)}`);let s=0,i=0;const o=2**n-1,a=[];for(const c of t){if(assertNumber(c),c>=2**e)throw new Error(`convertRadix2: invalid data word=${c} from=${e}`);if(s=s<<e|c,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=n;i-=n)a.push((s>>i-n&o)>>>0);s&=2**i-1}if(s=s<<n-i&o,!r&&i>=e)throw new Error("Excess padding");if(!r&&s)throw new Error(`Non-zero padding: ${s}`);return r&&i>0&&a.push(s>>>0),a}function radix$1(t){return assertNumber(t),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return convertRadix$1(Array.from(e),2**8,t)},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(convertRadix$1(e,t,2**8))}}}function radix2$1(t,e=!1){if(assertNumber(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(radix2carry$1(8,t)>32||radix2carry$1(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return convertRadix2$1(Array.from(n),8,t,!e)},decode:n=>{if(!Array.isArray(n)||n.length&&typeof n[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(convertRadix2$1(n,t,8,e))}}}function unsafeWrapper$1(t){if(typeof t!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch{}}}const base16=chain$1(radix2$1(4),alphabet$1("0123456789ABCDEF"),join$1("")),base32=chain$1(radix2$1(5),alphabet$1("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),padding$1(5),join$1(""));chain$1(radix2$1(5),alphabet$1("0123456789ABCDEFGHIJKLMNOPQRSTUV"),padding$1(5),join$1(""));chain$1(radix2$1(5),alphabet$1("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),join$1(""),normalize$2(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const base64=chain$1(radix2$1(6),alphabet$1("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),padding$1(6),join$1("")),base64url=chain$1(radix2$1(6),alphabet$1("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),padding$1(6),join$1("")),genBase58$1=t=>chain$1(radix$1(58),alphabet$1(t),join$1("")),base58$1=genBase58$1("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");genBase58$1("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");genBase58$1("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const XMR_BLOCK_LEN=[0,2,3,5,6,7,9,10,11],base58xmr={encode(t){let e="";for(let n=0;n<t.length;n+=8){const r=t.subarray(n,n+8);e+=base58$1.encode(r).padStart(XMR_BLOCK_LEN[r.length],"1")}return e},decode(t){let e=[];for(let n=0;n<t.length;n+=11){const r=t.slice(n,n+11),s=XMR_BLOCK_LEN.indexOf(r.length),i=base58$1.decode(r);for(let o=0;o<i.length-s;o++)if(i[o]!==0)throw new Error("base58xmr: wrong padding");e=e.concat(Array.from(i.slice(i.length-s)))}return Uint8Array.from(e)}},BECH_ALPHABET$1=chain$1(alphabet$1("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),join$1("")),POLYMOD_GENERATORS$1=[996825010,642813549,513874426,1027748829,705979059];function bech32Polymod$1(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<POLYMOD_GENERATORS$1.length;r++)(e>>r&1)===1&&(n^=POLYMOD_GENERATORS$1[r]);return n}function bechChecksum$1(t,e,n=1){const r=t.length;let s=1;for(let i=0;i<r;i++){const o=t.charCodeAt(i);if(o<33||o>126)throw new Error(`Invalid prefix (${t})`);s=bech32Polymod$1(s)^o>>5}s=bech32Polymod$1(s);for(let i=0;i<r;i++)s=bech32Polymod$1(s)^t.charCodeAt(i)&31;for(let i of e)s=bech32Polymod$1(s)^i;for(let i=0;i<6;i++)s=bech32Polymod$1(s);return s^=n,BECH_ALPHABET$1.encode(convertRadix2$1([s%2**30],30,5,!1))}function genBech32$1(t){const e=t==="bech32"?1:734539939,n=radix2$1(5),r=n.decode,s=n.encode,i=unsafeWrapper$1(r);function o(h,u,p=90){if(typeof h!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof h}`);if(!Array.isArray(u)||u.length&&typeof u[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);const g=h.length+7+u.length;if(p!==!1&&g>p)throw new TypeError(`Length ${g} exceeds limit ${p}`);return h=h.toLowerCase(),`${h}1${BECH_ALPHABET$1.encode(u)}${bechChecksum$1(h,u,e)}`}function a(h,u=90){if(typeof h!="string")throw new Error(`bech32.decode input should be string, not ${typeof h}`);if(h.length<8||u!==!1&&h.length>u)throw new TypeError(`Wrong string length: ${h.length} (${h}). Expected (8..${u})`);const p=h.toLowerCase();if(h!==p&&h!==h.toUpperCase())throw new Error("String must be lowercase or uppercase");h=p;const g=h.lastIndexOf("1");if(g===0||g===-1)throw new Error('Letter "1" must be present between prefix and data only');const m=h.slice(0,g),d=h.slice(g+1);if(d.length<6)throw new Error("Data must be at least 6 characters long");const w=BECH_ALPHABET$1.decode(d).slice(0,-6),$=bechChecksum$1(m,w,e);if(!d.endsWith($))throw new Error(`Invalid checksum in ${h}: expected "${$}"`);return{prefix:m,words:w}}const c=unsafeWrapper$1(a);function l(h){const{prefix:u,words:p}=a(h,!1);return{prefix:u,words:p,bytes:r(p)}}return{encode:o,decode:a,decodeToBytes:l,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:i,toWords:s}}const bech32$1=genBech32$1("bech32");genBech32$1("bech32m");const utf8={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},hex=chain$1(radix2$1(4),alphabet$1("0123456789abcdef"),join$1(""),normalize$2(t=>{if(typeof t!="string"||t.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()})),CODERS={utf8,hex,base16,base32,base64,base64url,base58:base58$1,base58xmr};`${Object.keys(CODERS).join(", ")}`;const wordlist=`abandon
ability
able
about
above
absent
absorb
abstract
absurd
abuse
access
accident
account
accuse
achieve
acid
acoustic
acquire
across
act
action
actor
actress
actual
adapt
add
addict
address
adjust
admit
adult
advance
advice
aerobic
affair
afford
afraid
again
age
agent
agree
ahead
aim
air
airport
aisle
alarm
album
alcohol
alert
alien
all
alley
allow
almost
alone
alpha
already
also
alter
always
amateur
amazing
among
amount
amused
analyst
anchor
ancient
anger
angle
angry
animal
ankle
announce
annual
another
answer
antenna
antique
anxiety
any
apart
apology
appear
apple
approve
april
arch
arctic
area
arena
argue
arm
armed
armor
army
around
arrange
arrest
arrive
arrow
art
artefact
artist
artwork
ask
aspect
assault
asset
assist
assume
asthma
athlete
atom
attack
attend
attitude
attract
auction
audit
august
aunt
author
auto
autumn
average
avocado
avoid
awake
aware
away
awesome
awful
awkward
axis
baby
bachelor
bacon
badge
bag
balance
balcony
ball
bamboo
banana
banner
bar
barely
bargain
barrel
base
basic
basket
battle
beach
bean
beauty
because
become
beef
before
begin
behave
behind
believe
below
belt
bench
benefit
best
betray
better
between
beyond
bicycle
bid
bike
bind
biology
bird
birth
bitter
black
blade
blame
blanket
blast
bleak
bless
blind
blood
blossom
blouse
blue
blur
blush
board
boat
body
boil
bomb
bone
bonus
book
boost
border
boring
borrow
boss
bottom
bounce
box
boy
bracket
brain
brand
brass
brave
bread
breeze
brick
bridge
brief
bright
bring
brisk
broccoli
broken
bronze
broom
brother
brown
brush
bubble
buddy
budget
buffalo
build
bulb
bulk
bullet
bundle
bunker
burden
burger
burst
bus
business
busy
butter
buyer
buzz
cabbage
cabin
cable
cactus
cage
cake
call
calm
camera
camp
can
canal
cancel
candy
cannon
canoe
canvas
canyon
capable
capital
captain
car
carbon
card
cargo
carpet
carry
cart
case
cash
casino
castle
casual
cat
catalog
catch
category
cattle
caught
cause
caution
cave
ceiling
celery
cement
census
century
cereal
certain
chair
chalk
champion
change
chaos
chapter
charge
chase
chat
cheap
check
cheese
chef
cherry
chest
chicken
chief
child
chimney
choice
choose
chronic
chuckle
chunk
churn
cigar
cinnamon
circle
citizen
city
civil
claim
clap
clarify
claw
clay
clean
clerk
clever
click
client
cliff
climb
clinic
clip
clock
clog
close
cloth
cloud
clown
club
clump
cluster
clutch
coach
coast
coconut
code
coffee
coil
coin
collect
color
column
combine
come
comfort
comic
common
company
concert
conduct
confirm
congress
connect
consider
control
convince
cook
cool
copper
copy
coral
core
corn
correct
cost
cotton
couch
country
couple
course
cousin
cover
coyote
crack
cradle
craft
cram
crane
crash
crater
crawl
crazy
cream
credit
creek
crew
cricket
crime
crisp
critic
crop
cross
crouch
crowd
crucial
cruel
cruise
crumble
crunch
crush
cry
crystal
cube
culture
cup
cupboard
curious
current
curtain
curve
cushion
custom
cute
cycle
dad
damage
damp
dance
danger
daring
dash
daughter
dawn
day
deal
debate
debris
decade
december
decide
decline
decorate
decrease
deer
defense
define
defy
degree
delay
deliver
demand
demise
denial
dentist
deny
depart
depend
deposit
depth
deputy
derive
describe
desert
design
desk
despair
destroy
detail
detect
develop
device
devote
diagram
dial
diamond
diary
dice
diesel
diet
differ
digital
dignity
dilemma
dinner
dinosaur
direct
dirt
disagree
discover
disease
dish
dismiss
disorder
display
distance
divert
divide
divorce
dizzy
doctor
document
dog
doll
dolphin
domain
donate
donkey
donor
door
dose
double
dove
draft
dragon
drama
drastic
draw
dream
dress
drift
drill
drink
drip
drive
drop
drum
dry
duck
dumb
dune
during
dust
dutch
duty
dwarf
dynamic
eager
eagle
early
earn
earth
easily
east
easy
echo
ecology
economy
edge
edit
educate
effort
egg
eight
either
elbow
elder
electric
elegant
element
elephant
elevator
elite
else
embark
embody
embrace
emerge
emotion
employ
empower
empty
enable
enact
end
endless
endorse
enemy
energy
enforce
engage
engine
enhance
enjoy
enlist
enough
enrich
enroll
ensure
enter
entire
entry
envelope
episode
equal
equip
era
erase
erode
erosion
error
erupt
escape
essay
essence
estate
eternal
ethics
evidence
evil
evoke
evolve
exact
example
excess
exchange
excite
exclude
excuse
execute
exercise
exhaust
exhibit
exile
exist
exit
exotic
expand
expect
expire
explain
expose
express
extend
extra
eye
eyebrow
fabric
face
faculty
fade
faint
faith
fall
false
fame
family
famous
fan
fancy
fantasy
farm
fashion
fat
fatal
father
fatigue
fault
favorite
feature
february
federal
fee
feed
feel
female
fence
festival
fetch
fever
few
fiber
fiction
field
figure
file
film
filter
final
find
fine
finger
finish
fire
firm
first
fiscal
fish
fit
fitness
fix
flag
flame
flash
flat
flavor
flee
flight
flip
float
flock
floor
flower
fluid
flush
fly
foam
focus
fog
foil
fold
follow
food
foot
force
forest
forget
fork
fortune
forum
forward
fossil
foster
found
fox
fragile
frame
frequent
fresh
friend
fringe
frog
front
frost
frown
frozen
fruit
fuel
fun
funny
furnace
fury
future
gadget
gain
galaxy
gallery
game
gap
garage
garbage
garden
garlic
garment
gas
gasp
gate
gather
gauge
gaze
general
genius
genre
gentle
genuine
gesture
ghost
giant
gift
giggle
ginger
giraffe
girl
give
glad
glance
glare
glass
glide
glimpse
globe
gloom
glory
glove
glow
glue
goat
goddess
gold
good
goose
gorilla
gospel
gossip
govern
gown
grab
grace
grain
grant
grape
grass
gravity
great
green
grid
grief
grit
grocery
group
grow
grunt
guard
guess
guide
guilt
guitar
gun
gym
habit
hair
half
hammer
hamster
hand
happy
harbor
hard
harsh
harvest
hat
have
hawk
hazard
head
health
heart
heavy
hedgehog
height
hello
helmet
help
hen
hero
hidden
high
hill
hint
hip
hire
history
hobby
hockey
hold
hole
holiday
hollow
home
honey
hood
hope
horn
horror
horse
hospital
host
hotel
hour
hover
hub
huge
human
humble
humor
hundred
hungry
hunt
hurdle
hurry
hurt
husband
hybrid
ice
icon
idea
identify
idle
ignore
ill
illegal
illness
image
imitate
immense
immune
impact
impose
improve
impulse
inch
include
income
increase
index
indicate
indoor
industry
infant
inflict
inform
inhale
inherit
initial
inject
injury
inmate
inner
innocent
input
inquiry
insane
insect
inside
inspire
install
intact
interest
into
invest
invite
involve
iron
island
isolate
issue
item
ivory
jacket
jaguar
jar
jazz
jealous
jeans
jelly
jewel
job
join
joke
journey
joy
judge
juice
jump
jungle
junior
junk
just
kangaroo
keen
keep
ketchup
key
kick
kid
kidney
kind
kingdom
kiss
kit
kitchen
kite
kitten
kiwi
knee
knife
knock
know
lab
label
labor
ladder
lady
lake
lamp
language
laptop
large
later
latin
laugh
laundry
lava
law
lawn
lawsuit
layer
lazy
leader
leaf
learn
leave
lecture
left
leg
legal
legend
leisure
lemon
lend
length
lens
leopard
lesson
letter
level
liar
liberty
library
license
life
lift
light
like
limb
limit
link
lion
liquid
list
little
live
lizard
load
loan
lobster
local
lock
logic
lonely
long
loop
lottery
loud
lounge
love
loyal
lucky
luggage
lumber
lunar
lunch
luxury
lyrics
machine
mad
magic
magnet
maid
mail
main
major
make
mammal
man
manage
mandate
mango
mansion
manual
maple
marble
march
margin
marine
market
marriage
mask
mass
master
match
material
math
matrix
matter
maximum
maze
meadow
mean
measure
meat
mechanic
medal
media
melody
melt
member
memory
mention
menu
mercy
merge
merit
merry
mesh
message
metal
method
middle
midnight
milk
million
mimic
mind
minimum
minor
minute
miracle
mirror
misery
miss
mistake
mix
mixed
mixture
mobile
model
modify
mom
moment
monitor
monkey
monster
month
moon
moral
more
morning
mosquito
mother
motion
motor
mountain
mouse
move
movie
much
muffin
mule
multiply
muscle
museum
mushroom
music
must
mutual
myself
mystery
myth
naive
name
napkin
narrow
nasty
nation
nature
near
neck
need
negative
neglect
neither
nephew
nerve
nest
net
network
neutral
never
news
next
nice
night
noble
noise
nominee
noodle
normal
north
nose
notable
note
nothing
notice
novel
now
nuclear
number
nurse
nut
oak
obey
object
oblige
obscure
observe
obtain
obvious
occur
ocean
october
odor
off
offer
office
often
oil
okay
old
olive
olympic
omit
once
one
onion
online
only
open
opera
opinion
oppose
option
orange
orbit
orchard
order
ordinary
organ
orient
original
orphan
ostrich
other
outdoor
outer
output
outside
oval
oven
over
own
owner
oxygen
oyster
ozone
pact
paddle
page
pair
palace
palm
panda
panel
panic
panther
paper
parade
parent
park
parrot
party
pass
patch
path
patient
patrol
pattern
pause
pave
payment
peace
peanut
pear
peasant
pelican
pen
penalty
pencil
people
pepper
perfect
permit
person
pet
phone
photo
phrase
physical
piano
picnic
picture
piece
pig
pigeon
pill
pilot
pink
pioneer
pipe
pistol
pitch
pizza
place
planet
plastic
plate
play
please
pledge
pluck
plug
plunge
poem
poet
point
polar
pole
police
pond
pony
pool
popular
portion
position
possible
post
potato
pottery
poverty
powder
power
practice
praise
predict
prefer
prepare
present
pretty
prevent
price
pride
primary
print
priority
prison
private
prize
problem
process
produce
profit
program
project
promote
proof
property
prosper
protect
proud
provide
public
pudding
pull
pulp
pulse
pumpkin
punch
pupil
puppy
purchase
purity
purpose
purse
push
put
puzzle
pyramid
quality
quantum
quarter
question
quick
quit
quiz
quote
rabbit
raccoon
race
rack
radar
radio
rail
rain
raise
rally
ramp
ranch
random
range
rapid
rare
rate
rather
raven
raw
razor
ready
real
reason
rebel
rebuild
recall
receive
recipe
record
recycle
reduce
reflect
reform
refuse
region
regret
regular
reject
relax
release
relief
rely
remain
remember
remind
remove
render
renew
rent
reopen
repair
repeat
replace
report
require
rescue
resemble
resist
resource
response
result
retire
retreat
return
reunion
reveal
review
reward
rhythm
rib
ribbon
rice
rich
ride
ridge
rifle
right
rigid
ring
riot
ripple
risk
ritual
rival
river
road
roast
robot
robust
rocket
romance
roof
rookie
room
rose
rotate
rough
round
route
royal
rubber
rude
rug
rule
run
runway
rural
sad
saddle
sadness
safe
sail
salad
salmon
salon
salt
salute
same
sample
sand
satisfy
satoshi
sauce
sausage
save
say
scale
scan
scare
scatter
scene
scheme
school
science
scissors
scorpion
scout
scrap
screen
script
scrub
sea
search
season
seat
second
secret
section
security
seed
seek
segment
select
sell
seminar
senior
sense
sentence
series
service
session
settle
setup
seven
shadow
shaft
shallow
share
shed
shell
sheriff
shield
shift
shine
ship
shiver
shock
shoe
shoot
shop
short
shoulder
shove
shrimp
shrug
shuffle
shy
sibling
sick
side
siege
sight
sign
silent
silk
silly
silver
similar
simple
since
sing
siren
sister
situate
six
size
skate
sketch
ski
skill
skin
skirt
skull
slab
slam
sleep
slender
slice
slide
slight
slim
slogan
slot
slow
slush
small
smart
smile
smoke
smooth
snack
snake
snap
sniff
snow
soap
soccer
social
sock
soda
soft
solar
soldier
solid
solution
solve
someone
song
soon
sorry
sort
soul
sound
soup
source
south
space
spare
spatial
spawn
speak
special
speed
spell
spend
sphere
spice
spider
spike
spin
spirit
split
spoil
sponsor
spoon
sport
spot
spray
spread
spring
spy
square
squeeze
squirrel
stable
stadium
staff
stage
stairs
stamp
stand
start
state
stay
steak
steel
stem
step
stereo
stick
still
sting
stock
stomach
stone
stool
story
stove
strategy
street
strike
strong
struggle
student
stuff
stumble
style
subject
submit
subway
success
such
sudden
suffer
sugar
suggest
suit
summer
sun
sunny
sunset
super
supply
supreme
sure
surface
surge
surprise
surround
survey
suspect
sustain
swallow
swamp
swap
swarm
swear
sweet
swift
swim
swing
switch
sword
symbol
symptom
syrup
system
table
tackle
tag
tail
talent
talk
tank
tape
target
task
taste
tattoo
taxi
teach
team
tell
ten
tenant
tennis
tent
term
test
text
thank
that
theme
then
theory
there
they
thing
this
thought
three
thrive
throw
thumb
thunder
ticket
tide
tiger
tilt
timber
time
tiny
tip
tired
tissue
title
toast
tobacco
today
toddler
toe
together
toilet
token
tomato
tomorrow
tone
tongue
tonight
tool
tooth
top
topic
topple
torch
tornado
tortoise
toss
total
tourist
toward
tower
town
toy
track
trade
traffic
tragic
train
transfer
trap
trash
travel
tray
treat
tree
trend
trial
tribe
trick
trigger
trim
trip
trophy
trouble
truck
true
truly
trumpet
trust
truth
try
tube
tuition
tumble
tuna
tunnel
turkey
turn
turtle
twelve
twenty
twice
twin
twist
two
type
typical
ugly
umbrella
unable
unaware
uncle
uncover
under
undo
unfair
unfold
unhappy
uniform
unique
unit
universe
unknown
unlock
until
unusual
unveil
update
upgrade
uphold
upon
upper
upset
urban
urge
usage
use
used
useful
useless
usual
utility
vacant
vacuum
vague
valid
valley
valve
van
vanish
vapor
various
vast
vault
vehicle
velvet
vendor
venture
venue
verb
verify
version
very
vessel
veteran
viable
vibrant
vicious
victory
video
view
village
vintage
violin
virtual
virus
visa
visit
visual
vital
vivid
vocal
voice
void
volcano
volume
vote
voyage
wage
wagon
wait
walk
wall
walnut
want
warfare
warm
warrior
wash
wasp
waste
water
wave
way
wealth
weapon
wear
weasel
weather
web
wedding
weekend
weird
welcome
west
wet
whale
what
wheat
wheel
when
where
whip
whisper
wide
width
wife
wild
will
win
window
wine
wing
wink
winner
winter
wire
wisdom
wise
wish
witness
wolf
woman
wonder
wood
wool
word
work
world
worry
worth
wrap
wreck
wrestle
wrist
write
wrong
yard
year
yellow
you
young
youth
zebra
zero
zone
zoo`.split(`
`);function number$4(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function bool$2(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function isBytes$6(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function bytes$4(t,...e){if(!isBytes$6(t))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function hash$4(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number$4(t.outputLen),number$4(t.blockLen)}function exists$4(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 output$4(t,e){bytes$4(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const assert$2={number:number$4,bool:bool$2,bytes:bytes$4,hash:hash$4,exists:exists$4,output:output$4},crypto$3=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function isBytes$5(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}const createView$3=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),rotr$3=(t,e)=>t<<32-e|t>>>e,isLE$3=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$3)throw new Error("Non little-endian hardware is not supported");function utf8ToBytes$6(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function toBytes$4(t){if(typeof t=="string"&&(t=utf8ToBytes$6(t)),!isBytes$5(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}let Hash$3=class{clone(){return this._cloneInto()}};const toStr={}.toString;function checkOpts$1(t,e){if(e!==void 0&&toStr.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(t,e)}function wrapConstructor$3(t){const e=r=>t().update(toBytes$4(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function randomBytes$2(t=32){if(crypto$3&&typeof crypto$3.getRandomValues=="function")return crypto$3.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}let HMAC$3=class extends Hash$3{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,hash$4(e);const r=toBytes$4(n);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,i=new Uint8Array(s);i.set(r.length>s?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),i.fill(0)}update(e){return exists$4(this),this.iHash.update(e),this}digestInto(e){exists$4(this),bytes$4(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const hmac$3=(t,e,n)=>new HMAC$3(t,e).update(n).digest();hmac$3.create=(t,e)=>new HMAC$3(t,e);function pbkdf2Init(t,e,n,r){hash$4(t);const s=checkOpts$1({dkLen:32,asyncTick:10},r),{c:i,dkLen:o,asyncTick:a}=s;if(number$4(i),number$4(o),number$4(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");const c=toBytes$4(e),l=toBytes$4(n),h=new Uint8Array(o),u=hmac$3.create(t,c),p=u._cloneInto().update(l);return{c:i,dkLen:o,asyncTick:a,DK:h,PRF:u,PRFSalt:p}}function pbkdf2Output(t,e,n,r,s){return t.destroy(),e.destroy(),r&&r.destroy(),s.fill(0),n}function pbkdf2(t,e,n,r){const{c:s,dkLen:i,DK:o,PRF:a,PRFSalt:c}=pbkdf2Init(t,e,n,r);let l;const h=new Uint8Array(4),u=createView$3(h),p=new Uint8Array(a.outputLen);for(let g=1,m=0;m<i;g++,m+=a.outputLen){const d=o.subarray(m,m+a.outputLen);u.setInt32(0,g,!1),(l=c._cloneInto(l)).update(h).digestInto(p),d.set(p.subarray(0,d.length));for(let w=1;w<s;w++){a._cloneInto(l).update(p).digestInto(p);for(let $=0;$<d.length;$++)d[$]^=p[$]}}return pbkdf2Output(a,c,o,l,p)}function setBigUint64$3(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const s=BigInt(32),i=BigInt(4294967295),o=Number(n>>s&i),a=Number(n&i),c=r?4:0,l=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+l,a,r)}let SHA2$2=class extends Hash$3{constructor(e,n,r,s){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=createView$3(this.buffer)}update(e){exists$4(this);const{view:n,buffer:r,blockLen:s}=this;e=toBytes$4(e);const i=e.length;for(let o=0;o<i;){const a=Math.min(s-this.pos,i-o);if(a===s){const c=createView$3(e);for(;s<=i-o;o+=s)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){exists$4(this),output$4(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:s,isLE:i}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(r,0),o=0);for(let u=o;u<s;u++)n[u]=0;setBigUint64$3(r,s-8,BigInt(this.length*8),i),this.process(r,0);const a=createView$3(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,h[u],i)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%n&&e.buffer.set(r),e}};const Chi$3=(t,e,n)=>t&e^~t&n,Maj$3=(t,e,n)=>t&e^t&n^e&n,SHA256_K$3=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV$2=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W$3=new Uint32Array(64);let SHA256$3=class extends SHA2$2{constructor(){super(64,32,8,!1),this.A=IV$2[0]|0,this.B=IV$2[1]|0,this.C=IV$2[2]|0,this.D=IV$2[3]|0,this.E=IV$2[4]|0,this.F=IV$2[5]|0,this.G=IV$2[6]|0,this.H=IV$2[7]|0}get(){const{A:e,B:n,C:r,D:s,E:i,F:o,G:a,H:c}=this;return[e,n,r,s,i,o,a,c]}set(e,n,r,s,i,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let u=0;u<16;u++,n+=4)SHA256_W$3[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const p=SHA256_W$3[u-15],g=SHA256_W$3[u-2],m=rotr$3(p,7)^rotr$3(p,18)^p>>>3,d=rotr$3(g,17)^rotr$3(g,19)^g>>>10;SHA256_W$3[u]=d+SHA256_W$3[u-7]+m+SHA256_W$3[u-16]|0}let{A:r,B:s,C:i,D:o,E:a,F:c,G:l,H:h}=this;for(let u=0;u<64;u++){const p=rotr$3(a,6)^rotr$3(a,11)^rotr$3(a,25),g=h+p+Chi$3(a,c,l)+SHA256_K$3[u]+SHA256_W$3[u]|0,d=(rotr$3(r,2)^rotr$3(r,13)^rotr$3(r,22))+Maj$3(r,s,i)|0;h=l,l=c,c=a,a=o+g|0,o=i,i=s,s=r,r=g+d|0}r=r+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(r,s,i,o,a,c,l,h)}roundClean(){SHA256_W$3.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const sha256$3=wrapConstructor$3(()=>new SHA256$3),U32_MASK64$1=BigInt(2**32-1),_32n$1=BigInt(32);function fromBig$1(t,e=!1){return e?{h:Number(t&U32_MASK64$1),l:Number(t>>_32n$1&U32_MASK64$1)}:{h:Number(t>>_32n$1&U32_MASK64$1)|0,l:Number(t&U32_MASK64$1)|0}}function split$1(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let s=0;s<t.length;s++){const{h:i,l:o}=fromBig$1(t[s],e);[n[s],r[s]]=[i,o]}return[n,r]}const toBig$1=(t,e)=>BigInt(t>>>0)<<_32n$1|BigInt(e>>>0),shrSH$1=(t,e,n)=>t>>>n,shrSL$1=(t,e,n)=>t<<32-n|e>>>n,rotrSH$1=(t,e,n)=>t>>>n|e<<32-n,rotrSL$1=(t,e,n)=>t<<32-n|e>>>n,rotrBH$1=(t,e,n)=>t<<64-n|e>>>n-32,rotrBL$1=(t,e,n)=>t>>>n-32|e<<64-n,rotr32H$1=(t,e)=>e,rotr32L$1=(t,e)=>t,rotlSH$1=(t,e,n)=>t<<n|e>>>32-n,rotlSL$1=(t,e,n)=>e<<n|t>>>32-n,rotlBH$1=(t,e,n)=>e<<n-32|t>>>64-n,rotlBL$1=(t,e,n)=>t<<n-32|e>>>64-n;function add$1(t,e,n,r){const s=(e>>>0)+(r>>>0);return{h:t+n+(s/2**32|0)|0,l:s|0}}const add3L$1=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),add3H$1=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,add4L$1=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),add4H$1=(t,e,n,r,s)=>e+n+r+s+(t/2**32|0)|0,add5L$1=(t,e,n,r,s)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(s>>>0),add5H$1=(t,e,n,r,s,i)=>e+n+r+s+i+(t/2**32|0)|0,u64$1={fromBig:fromBig$1,split:split$1,toBig:toBig$1,shrSH:shrSH$1,shrSL:shrSL$1,rotrSH:rotrSH$1,rotrSL:rotrSL$1,rotrBH:rotrBH$1,rotrBL:rotrBL$1,rotr32H:rotr32H$1,rotr32L:rotr32L$1,rotlSH:rotlSH$1,rotlSL:rotlSL$1,rotlBH:rotlBH$1,rotlBL:rotlBL$1,add:add$1,add3L:add3L$1,add3H:add3H$1,add4L:add4L$1,add4H:add4H$1,add5H:add5H$1,add5L:add5L$1},[SHA512_Kh$1,SHA512_Kl$1]=u64$1.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),SHA512_W_H$1=new Uint32Array(80),SHA512_W_L$1=new Uint32Array(80);let SHA512$1=class extends SHA2$2{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:n,Bh:r,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:l,El:h,Fh:u,Fl:p,Gh:g,Gl:m,Hh:d,Hl:w}=this;return[e,n,r,s,i,o,a,c,l,h,u,p,g,m,d,w]}set(e,n,r,s,i,o,a,c,l,h,u,p,g,m,d,w){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=h|0,this.Fh=u|0,this.Fl=p|0,this.Gh=g|0,this.Gl=m|0,this.Hh=d|0,this.Hl=w|0}process(e,n){for(let x=0;x<16;x++,n+=4)SHA512_W_H$1[x]=e.getUint32(n),SHA512_W_L$1[x]=e.getUint32(n+=4);for(let x=16;x<80;x++){const I=SHA512_W_H$1[x-15]|0,R=SHA512_W_L$1[x-15]|0,v=u64$1.rotrSH(I,R,1)^u64$1.rotrSH(I,R,8)^u64$1.shrSH(I,R,7),B=u64$1.rotrSL(I,R,1)^u64$1.rotrSL(I,R,8)^u64$1.shrSL(I,R,7),S=SHA512_W_H$1[x-2]|0,H=SHA512_W_L$1[x-2]|0,L=u64$1.rotrSH(S,H,19)^u64$1.rotrBH(S,H,61)^u64$1.shrSH(S,H,6),E=u64$1.rotrSL(S,H,19)^u64$1.rotrBL(S,H,61)^u64$1.shrSL(S,H,6),k=u64$1.add4L(B,E,SHA512_W_L$1[x-7],SHA512_W_L$1[x-16]),T=u64$1.add4H(k,v,L,SHA512_W_H$1[x-7],SHA512_W_H$1[x-16]);SHA512_W_H$1[x]=T|0,SHA512_W_L$1[x]=k|0}let{Ah:r,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:l,Dl:h,Eh:u,El:p,Fh:g,Fl:m,Gh:d,Gl:w,Hh:$,Hl:_}=this;for(let x=0;x<80;x++){const I=u64$1.rotrSH(u,p,14)^u64$1.rotrSH(u,p,18)^u64$1.rotrBH(u,p,41),R=u64$1.rotrSL(u,p,14)^u64$1.rotrSL(u,p,18)^u64$1.rotrBL(u,p,41),v=u&g^~u&d,B=p&m^~p&w,S=u64$1.add5L(_,R,B,SHA512_Kl$1[x],SHA512_W_L$1[x]),H=u64$1.add5H(S,$,I,v,SHA512_Kh$1[x],SHA512_W_H$1[x]),L=S|0,E=u64$1.rotrSH(r,s,28)^u64$1.rotrBH(r,s,34)^u64$1.rotrBH(r,s,39),k=u64$1.rotrSL(r,s,28)^u64$1.rotrBL(r,s,34)^u64$1.rotrBL(r,s,39),T=r&i^r&a^i&a,P=s&o^s&c^o&c;$=d|0,_=w|0,d=g|0,w=m|0,g=u|0,m=p|0,{h:u,l:p}=u64$1.add(l|0,h|0,H|0,L|0),l=a|0,h=c|0,a=i|0,c=o|0,i=r|0,o=s|0;const y=u64$1.add3L(L,k,P);r=u64$1.add3H(y,H,E,T),s=y|0}({h:r,l:s}=u64$1.add(this.Ah|0,this.Al|0,r|0,s|0)),{h:i,l:o}=u64$1.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=u64$1.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=u64$1.add(this.Dh|0,this.Dl|0,l|0,h|0),{h:u,l:p}=u64$1.add(this.Eh|0,this.El|0,u|0,p|0),{h:g,l:m}=u64$1.add(this.Fh|0,this.Fl|0,g|0,m|0),{h:d,l:w}=u64$1.add(this.Gh|0,this.Gl|0,d|0,w|0),{h:$,l:_}=u64$1.add(this.Hh|0,this.Hl|0,$|0,_|0),this.set(r,s,i,o,a,c,l,h,u,p,g,m,d,w,$,_)}roundClean(){SHA512_W_H$1.fill(0),SHA512_W_L$1.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};const sha512$1=wrapConstructor$3(()=>new SHA512$1);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function isBytes$4(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function chain(...t){const e=i=>i,n=(i,o)=>a=>i(o(a)),r=t.map(i=>i.encode).reduceRight(n,e),s=t.map(i=>i.decode).reduce(n,e);return{encode:r,decode:s}}function alphabet(t){return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return e.map(n=>{if(n<0||n>=t.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${t.length})`);return t[n]})},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("alphabet.decode input should be array of strings");return e.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=t.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${t}`);return r})}}}function join(t=""){if(typeof t!="string")throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of e)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return e.join(t)},decode:e=>{if(typeof e!="string")throw new Error("join.decode input should be string");return e.split(t)}}}function padding(t,e="="){if(typeof e!="string")throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let r of n)if(typeof r!="string")throw new Error(`padding.encode: non-string input=${r}`);for(;n.length*t%8;)n.push(e);return n},decode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let s of n)if(typeof s!="string")throw new Error(`padding.decode: non-string input=${s}`);let r=n.length;if(r*t%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if(!((r-1)*t%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function convertRadix(t,e,n){if(e<2)throw new Error(`convertRadix: wrong from=${e}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(t))throw new Error("convertRadix: data should be array");if(!t.length)return[];let r=0;const s=[],i=Array.from(t);for(i.forEach(o=>{if(o<0||o>=e)throw new Error(`Wrong integer: ${o}`)});;){let o=0,a=!0;for(let c=r;c<i.length;c++){const l=i[c],h=e*o+l;if(!Number.isSafeInteger(h)||e*o/e!==o||h-l!==e*o)throw new Error("convertRadix: carry overflow");o=h%n;const u=Math.floor(h/n);if(i[c]=u,!Number.isSafeInteger(u)||u*n+o!==h)throw new Error("convertRadix: carry overflow");if(a)u?a=!1:r=c;else continue}if(s.push(o),a)break}for(let o=0;o<t.length-1&&t[o]===0;o++)s.push(0);return s.reverse()}const gcd=(t,e)=>e?gcd(e,t%e):t,radix2carry=(t,e)=>t+(e-gcd(t,e));function convertRadix2(t,e,n,r){if(!Array.isArray(t))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(radix2carry(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${radix2carry(e,n)}`);let s=0,i=0;const o=2**n-1,a=[];for(const c of t){if(c>=2**e)throw new Error(`convertRadix2: invalid data word=${c} from=${e}`);if(s=s<<e|c,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=n;i-=n)a.push((s>>i-n&o)>>>0);s&=2**i-1}if(s=s<<n-i&o,!r&&i>=e)throw new Error("Excess padding");if(!r&&s)throw new Error(`Non-zero padding: ${s}`);return r&&i>0&&a.push(s>>>0),a}function radix(t){return{encode:e=>{if(!isBytes$4(e))throw new Error("radix.encode input should be Uint8Array");return convertRadix(Array.from(e),2**8,t)},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("radix.decode input should be array of numbers");return Uint8Array.from(convertRadix(e,t,2**8))}}}function radix2(t,e=!1){if(t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(radix2carry(8,t)>32||radix2carry(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!isBytes$4(n))throw new Error("radix2.encode input should be Uint8Array");return convertRadix2(Array.from(n),8,t,!e)},decode:n=>{if(!Array.isArray(n)||n.length&&typeof n[0]!="number")throw new Error("radix2.decode input should be array of numbers");return Uint8Array.from(convertRadix2(n,t,8,e))}}}function unsafeWrapper(t){if(typeof t!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch{}}}function checksum(t,e){if(typeof e!="function")throw new Error("checksum fn should be function");return{encode(n){if(!isBytes$4(n))throw new Error("checksum.encode: input should be Uint8Array");const r=e(n).slice(0,t),s=new Uint8Array(n.length+t);return s.set(n),s.set(r,n.length),s},decode(n){if(!isBytes$4(n))throw new Error("checksum.decode: input should be Uint8Array");const r=n.slice(0,-t),s=e(r).slice(0,t),i=n.slice(-t);for(let o=0;o<t;o++)if(s[o]!==i[o])throw new Error("Invalid checksum");return r}}}const utils$2={alphabet,chain,checksum,convertRadix,convertRadix2,radix,radix2,join,padding},genBase58=t=>chain(radix(58),alphabet(t),join("")),base58=genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),createBase58check=t=>chain(checksum(4,e=>t(t(e))),base58),base58check$1=createBase58check,BECH_ALPHABET=chain(alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),join("")),POLYMOD_GENERATORS=[996825010,642813549,513874426,1027748829,705979059];function bech32Polymod(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<POLYMOD_GENERATORS.length;r++)(e>>r&1)===1&&(n^=POLYMOD_GENERATORS[r]);return n}function bechChecksum(t,e,n=1){const r=t.length;let s=1;for(let i=0;i<r;i++){const o=t.charCodeAt(i);if(o<33||o>126)throw new Error(`Invalid prefix (${t})`);s=bech32Polymod(s)^o>>5}s=bech32Polymod(s);for(let i=0;i<r;i++)s=bech32Polymod(s)^t.charCodeAt(i)&31;for(let i of e)s=bech32Polymod(s)^i;for(let i=0;i<6;i++)s=bech32Polymod(s);return s^=n,BECH_ALPHABET.encode(convertRadix2([s%2**30],30,5,!1))}function genBech32(t){const e=t==="bech32"?1:734539939,n=radix2(5),r=n.decode,s=n.encode,i=unsafeWrapper(r);function o(h,u,p=90){if(typeof h!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof h}`);if(!Array.isArray(u)||u.length&&typeof u[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof u}`);if(h.length===0)throw new TypeError(`Invalid prefix length ${h.length}`);const g=h.length+7+u.length;if(p!==!1&&g>p)throw new TypeError(`Length ${g} exceeds limit ${p}`);const m=h.toLowerCase(),d=bechChecksum(m,u,e);return`${m}1${BECH_ALPHABET.encode(u)}${d}`}function a(h,u=90){if(typeof h!="string")throw new Error(`bech32.decode input should be string, not ${typeof h}`);if(h.length<8||u!==!1&&h.length>u)throw new TypeError(`Wrong string length: ${h.length} (${h}). Expected (8..${u})`);const p=h.toLowerCase();if(h!==p&&h!==h.toUpperCase())throw new Error("String must be lowercase or uppercase");const g=p.lastIndexOf("1");if(g===0||g===-1)throw new Error('Letter "1" must be present between prefix and data only');const m=p.slice(0,g),d=p.slice(g+1);if(d.length<6)throw new Error("Data must be at least 6 characters long");const w=BECH_ALPHABET.decode(d).slice(0,-6),$=bechChecksum(m,w,e);if(!d.endsWith($))throw new Error(`Invalid checksum in ${h}: expected "${$}"`);return{prefix:m,words:w}}const c=unsafeWrapper(a);function l(h){const{prefix:u,words:p}=a(h,!1);return{prefix:u,words:p,bytes:r(p)}}return{encode:o,decode:a,decodeToBytes:l,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:i,toWords:s}}const bech32=genBech32("bech32"),isJapanese=t=>t[0]==="あいこくしん";function nfkd(t){if(typeof t!="string")throw new TypeError(`Invalid mnemonic type: ${typeof t}`);return t.normalize("NFKD")}function normalize$1(t){const e=nfkd(t),n=e.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:e,words:n}}function assertEntropy(t){assert$2.bytes(t,16,20,24,28,32)}function generateMnemonic(t,e=128){if(assert$2.number(e),e%32!==0||e>256)throw new TypeError("Invalid entropy");return entropyToMnemonic(randomBytes$2(e/8),t)}const calcChecksum=t=>{const e=8-t.length/4;return new Uint8Array([sha256$3(t)[0]>>e<<e])};function getCoder(t){if(!Array.isArray(t)||t.length!==2048||typeof t[0]!="string")throw new Error("Worlist: expected array of 2048 strings");return t.forEach(e=>{if(typeof e!="string")throw new Error(`Wordlist: non-string element: ${e}`)}),utils$2.chain(utils$2.checksum(1,calcChecksum),utils$2.radix2(11,!0),utils$2.alphabet(t))}function mnemonicToEntropy(t,e){const{words:n}=normalize$1(t),r=getCoder(e).decode(n);return assertEntropy(r),r}function entropyToMnemonic(t,e){return assertEntropy(t),getCoder(e).encode(t).join(isJapanese(e)?" ":" ")}function validateMnemonic(t,e){try{mnemonicToEntropy(t,e)}catch{return!1}return!0}const salt=t=>nfkd(`mnemonic${t}`);function mnemonicToSeedSync(t,e=""){return pbkdf2(sha512$1,normalize$1(t).nfkd,salt(e),{c:2048,dkLen:64})}function number$3(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function isBytes$3(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function bytes$3(t,...e){if(!isBytes$3(t))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function hash$3(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number$3(t.outputLen),number$3(t.blockLen)}function exists$3(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 output$3(t,e){bytes$3(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function isBytes$2(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}const createView$2=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),rotr$2=(t,e)=>t<<32-e|t>>>e,isLE$2=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$2)throw new Error("Non little-endian hardware is not supported");const hexes$3=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function bytesToHex$3(t){if(!isBytes$2(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=hexes$3[t[n]];return e}const asciis$1={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function asciiToBase16$1(t){if(t>=asciis$1._0&&t<=asciis$1._9)return t-asciis$1._0;if(t>=asciis$1._A&&t<=asciis$1._F)return t-(asciis$1._A-10);if(t>=asciis$1._a&&t<=asciis$1._f)return t-(asciis$1._a-10)}function hexToBytes$2(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,n=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let s=0,i=0;s<n;s++,i+=2){const o=asciiToBase16$1(t.charCodeAt(i)),a=asciiToBase16$1(t.charCodeAt(i+1));if(o===void 0||a===void 0){const c=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}r[s]=o*16+a}return r}function utf8ToBytes$5(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function toBytes$3(t){if(typeof t=="string"&&(t=utf8ToBytes$5(t)),!isBytes$2(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function concatBytes$4(...t){let e=0;for(let r=0;r<t.length;r++){const s=t[r];if(!isBytes$2(s))throw new Error("Uint8Array expected");e+=s.length}const n=new Uint8Array(e);for(let r=0,s=0;r<t.length;r++){const i=t[r];n.set(i,s),s+=i.length}return n}let Hash$2=class{clone(){return this._cloneInto()}};function wrapConstructor$2(t){const e=r=>t().update(toBytes$3(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}let HMAC$2=class extends Hash$2{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,hash$3(e);const r=toBytes$3(n);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,i=new Uint8Array(s);i.set(r.length>s?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),i.fill(0)}update(e){return exists$3(this),this.iHash.update(e),this}digestInto(e){exists$3(this),bytes$3(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const hmac$2=(t,e,n)=>new HMAC$2(t,e).update(n).digest();hmac$2.create=(t,e)=>new HMAC$2(t,e);function setBigUint64$2(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const s=BigInt(32),i=BigInt(4294967295),o=Number(n>>s&i),a=Number(n&i),c=r?4:0,l=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+l,a,r)}let SHA2$1=class extends Hash$2{constructor(e,n,r,s){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=createView$2(this.buffer)}update(e){exists$3(this);const{view:n,buffer:r,blockLen:s}=this;e=toBytes$3(e);const i=e.length;for(let o=0;o<i;){const a=Math.min(s-this.pos,i-o);if(a===s){const c=createView$2(e);for(;s<=i-o;o+=s)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){exists$3(this),output$3(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:s,isLE:i}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(r,0),o=0);for(let u=o;u<s;u++)n[u]=0;setBigUint64$2(r,s-8,BigInt(this.length*8),i),this.process(r,0);const a=createView$2(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,h[u],i)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%n&&e.buffer.set(r),e}};const Rho=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Id=Uint8Array.from({length:16},(t,e)=>e),Pi=Id.map(t=>(9*t+5)%16);let idxL=[Id],idxR=[Pi];for(let t=0;t<4;t++)for(let e of[idxL,idxR])e.push(e[t].map(n=>Rho[n]));const shifts=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(t=>new Uint8Array(t)),shiftsL=idxL.map((t,e)=>t.map(n=>shifts[e][n])),shiftsR=idxR.map((t,e)=>t.map(n=>shifts[e][n])),Kl=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Kr=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),rotl$1=(t,e)=>t<<e|t>>>32-e;function f(t,e,n,r){return t===0?e^n^r:t===1?e&n|~e&r:t===2?(e|~n)^r:t===3?e&r|n&~r:e^(n|~r)}const BUF=new Uint32Array(16);class RIPEMD160 extends SHA2$1{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:n,h2:r,h3:s,h4:i}=this;return[e,n,r,s,i]}set(e,n,r,s,i){this.h0=e|0,this.h1=n|0,this.h2=r|0,this.h3=s|0,this.h4=i|0}process(e,n){for(let g=0;g<16;g++,n+=4)BUF[g]=e.getUint32(n,!0);let r=this.h0|0,s=r,i=this.h1|0,o=i,a=this.h2|0,c=a,l=this.h3|0,h=l,u=this.h4|0,p=u;for(let g=0;g<5;g++){const m=4-g,d=Kl[g],w=Kr[g],$=idxL[g],_=idxR[g],x=shiftsL[g],I=shiftsR[g];for(let R=0;R<16;R++){const v=rotl$1(r+f(g,i,a,l)+BUF[$[R]]+d,x[R])+u|0;r=u,u=l,l=rotl$1(a,10)|0,a=i,i=v}for(let R=0;R<16;R++){const v=rotl$1(s+f(m,o,c,h)+BUF[_[R]]+w,I[R])+p|0;s=p,p=h,h=rotl$1(c,10)|0,c=o,o=v}}this.set(this.h1+a+h|0,this.h2+l+p|0,this.h3+u+s|0,this.h4+r+o|0,this.h0+i+c|0)}roundClean(){BUF.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const ripemd160=wrapConstructor$2(()=>new RIPEMD160),Chi$2=(t,e,n)=>t&e^~t&n,Maj$2=(t,e,n)=>t&e^t&n^e&n,SHA256_K$2=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV$1=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W$2=new Uint32Array(64);let SHA256$2=class extends SHA2$1{constructor(){super(64,32,8,!1),this.A=IV$1[0]|0,this.B=IV$1[1]|0,this.C=IV$1[2]|0,this.D=IV$1[3]|0,this.E=IV$1[4]|0,this.F=IV$1[5]|0,this.G=IV$1[6]|0,this.H=IV$1[7]|0}get(){const{A:e,B:n,C:r,D:s,E:i,F:o,G:a,H:c}=this;return[e,n,r,s,i,o,a,c]}set(e,n,r,s,i,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let u=0;u<16;u++,n+=4)SHA256_W$2[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const p=SHA256_W$2[u-15],g=SHA256_W$2[u-2],m=rotr$2(p,7)^rotr$2(p,18)^p>>>3,d=rotr$2(g,17)^rotr$2(g,19)^g>>>10;SHA256_W$2[u]=d+SHA256_W$2[u-7]+m+SHA256_W$2[u-16]|0}let{A:r,B:s,C:i,D:o,E:a,F:c,G:l,H:h}=this;for(let u=0;u<64;u++){const p=rotr$2(a,6)^rotr$2(a,11)^rotr$2(a,25),g=h+p+Chi$2(a,c,l)+SHA256_K$2[u]+SHA256_W$2[u]|0,d=(rotr$2(r,2)^rotr$2(r,13)^rotr$2(r,22))+Maj$2(r,s,i)|0;h=l,l=c,c=a,a=o+g|0,o=i,i=s,s=r,r=g+d|0}r=r+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(r,s,i,o,a,c,l,h)}roundClean(){SHA256_W$2.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const sha256$2=wrapConstructor$2(()=>new SHA256$2),U32_MASK64=BigInt(2**32-1),_32n=BigInt(32);function fromBig(t,e=!1){return e?{h:Number(t&U32_MASK64),l:Number(t>>_32n&U32_MASK64)}:{h:Number(t>>_32n&U32_MASK64)|0,l:Number(t&U32_MASK64)|0}}function split(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let s=0;s<t.length;s++){const{h:i,l:o}=fromBig(t[s],e);[n[s],r[s]]=[i,o]}return[n,r]}const toBig=(t,e)=>BigInt(t>>>0)<<_32n|BigInt(e>>>0),shrSH=(t,e,n)=>t>>>n,shrSL=(t,e,n)=>t<<32-n|e>>>n,rotrSH=(t,e,n)=>t>>>n|e<<32-n,rotrSL=(t,e,n)=>t<<32-n|e>>>n,rotrBH=(t,e,n)=>t<<64-n|e>>>n-32,rotrBL=(t,e,n)=>t>>>n-32|e<<64-n,rotr32H=(t,e)=>e,rotr32L=(t,e)=>t,rotlSH=(t,e,n)=>t<<n|e>>>32-n,rotlSL=(t,e,n)=>e<<n|t>>>32-n,rotlBH=(t,e,n)=>e<<n-32|t>>>64-n,rotlBL=(t,e,n)=>t<<n-32|e>>>64-n;function add(t,e,n,r){const s=(e>>>0)+(r>>>0);return{h:t+n+(s/2**32|0)|0,l:s|0}}const add3L=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),add3H=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,add4L=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),add4H=(t,e,n,r,s)=>e+n+r+s+(t/2**32|0)|0,add5L=(t,e,n,r,s)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(s>>>0),add5H=(t,e,n,r,s,i)=>e+n+r+s+i+(t/2**32|0)|0,u64={fromBig,split,toBig,shrSH,shrSL,rotrSH,rotrSL,rotrBH,rotrBL,rotr32H,rotr32L,rotlSH,rotlSL,rotlBH,rotlBL,add,add3L,add3H,add4L,add4H,add5H,add5L},[SHA512_Kh,SHA512_Kl]=u64.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),SHA512_W_H=new Uint32Array(80),SHA512_W_L=new Uint32Array(80);class SHA512 extends SHA2$1{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:n,Bh:r,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:l,El:h,Fh:u,Fl:p,Gh:g,Gl:m,Hh:d,Hl:w}=this;return[e,n,r,s,i,o,a,c,l,h,u,p,g,m,d,w]}set(e,n,r,s,i,o,a,c,l,h,u,p,g,m,d,w){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=h|0,this.Fh=u|0,this.Fl=p|0,this.Gh=g|0,this.Gl=m|0,this.Hh=d|0,this.Hl=w|0}process(e,n){for(let x=0;x<16;x++,n+=4)SHA512_W_H[x]=e.getUint32(n),SHA512_W_L[x]=e.getUint32(n+=4);for(let x=16;x<80;x++){const I=SHA512_W_H[x-15]|0,R=SHA512_W_L[x-15]|0,v=u64.rotrSH(I,R,1)^u64.rotrSH(I,R,8)^u64.shrSH(I,R,7),B=u64.rotrSL(I,R,1)^u64.rotrSL(I,R,8)^u64.shrSL(I,R,7),S=SHA512_W_H[x-2]|0,H=SHA512_W_L[x-2]|0,L=u64.rotrSH(S,H,19)^u64.rotrBH(S,H,61)^u64.shrSH(S,H,6),E=u64.rotrSL(S,H,19)^u64.rotrBL(S,H,61)^u64.shrSL(S,H,6),k=u64.add4L(B,E,SHA512_W_L[x-7],SHA512_W_L[x-16]),T=u64.add4H(k,v,L,SHA512_W_H[x-7],SHA512_W_H[x-16]);SHA512_W_H[x]=T|0,SHA512_W_L[x]=k|0}let{Ah:r,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:l,Dl:h,Eh:u,El:p,Fh:g,Fl:m,Gh:d,Gl:w,Hh:$,Hl:_}=this;for(let x=0;x<80;x++){const I=u64.rotrSH(u,p,14)^u64.rotrSH(u,p,18)^u64.rotrBH(u,p,41),R=u64.rotrSL(u,p,14)^u64.rotrSL(u,p,18)^u64.rotrBL(u,p,41),v=u&g^~u&d,B=p&m^~p&w,S=u64.add5L(_,R,B,SHA512_Kl[x],SHA512_W_L[x]),H=u64.add5H(S,$,I,v,SHA512_Kh[x],SHA512_W_H[x]),L=S|0,E=u64.rotrSH(r,s,28)^u64.rotrBH(r,s,34)^u64.rotrBH(r,s,39),k=u64.rotrSL(r,s,28)^u64.rotrBL(r,s,34)^u64.rotrBL(r,s,39),T=r&i^r&a^i&a,P=s&o^s&c^o&c;$=d|0,_=w|0,d=g|0,w=m|0,g=u|0,m=p|0,{h:u,l:p}=u64.add(l|0,h|0,H|0,L|0),l=a|0,h=c|0,a=i|0,c=o|0,i=r|0,o=s|0;const y=u64.add3L(L,k,P);r=u64.add3H(y,H,E,T),s=y|0}({h:r,l:s}=u64.add(this.Ah|0,this.Al|0,r|0,s|0)),{h:i,l:o}=u64.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=u64.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:h}=u64.add(this.Dh|0,this.Dl|0,l|0,h|0),{h:u,l:p}=u64.add(this.Eh|0,this.El|0,u|0,p|0),{h:g,l:m}=u64.add(this.Fh|0,this.Fl|0,g|0,m|0),{h:d,l:w}=u64.add(this.Gh|0,this.Gl|0,d|0,w|0),{h:$,l:_}=u64.add(this.Hh|0,this.Hl|0,$|0,_|0),this.set(r,s,i,o,a,c,l,h,u,p,g,m,d,w,$,_)}roundClean(){SHA512_W_H.fill(0),SHA512_W_L.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const sha512=wrapConstructor$2(()=>new SHA512);function number$2(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function bool$1(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function bytes$2(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function hash$2(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number$2(t.outputLen),number$2(t.blockLen)}function exists$2(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 output$2(t,e){bytes$2(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const assert$1={number:number$2,bool:bool$1,bytes:bytes$2,hash:hash$2,exists:exists$2,output:output$2},crypto$2=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const u8a$2=t=>t instanceof Uint8Array,createView$1=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),rotr$1=(t,e)=>t<<32-e|t>>>e,isLE$1=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$1)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function utf8ToBytes$4(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function toBytes$2(t){if(typeof t=="string"&&(t=utf8ToBytes$4(t)),!u8a$2(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function concatBytes$3(...t){const e=new Uint8Array(t.reduce((r,s)=>r+s.length,0));let n=0;return t.forEach(r=>{if(!u8a$2(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}let Hash$1=class{clone(){return this._cloneInto()}};function wrapConstructor$1(t){const e=r=>t().update(toBytes$2(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function randomBytes$1(t=32){if(crypto$2&&typeof crypto$2.getRandomValues=="function")return crypto$2.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function setBigUint64$1(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const s=BigInt(32),i=BigInt(4294967295),o=Number(n>>s&i),a=Number(n&i),c=r?4:0,l=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+l,a,r)}class SHA2 extends Hash$1{constructor(e,n,r,s){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=createView$1(this.buffer)}update(e){assert$1.exists(this);const{view:n,buffer:r,blockLen:s}=this;e=toBytes$2(e);const i=e.length;for(let o=0;o<i;){const a=Math.min(s-this.pos,i-o);if(a===s){const c=createView$1(e);for(;s<=i-o;o+=s)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){assert$1.exists(this),assert$1.output(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:s,isLE:i}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(r,0),o=0);for(let u=o;u<s;u++)n[u]=0;setBigUint64$1(r,s-8,BigInt(this.length*8),i),this.process(r,0);const a=createView$1(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,h[u],i)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%n&&e.buffer.set(r),e}}const Chi$1=(t,e,n)=>t&e^~t&n,Maj$1=(t,e,n)=>t&e^t&n^e&n,SHA256_K$1=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W$1=new Uint32Array(64);let SHA256$1=class extends SHA2{constructor(){super(64,32,8,!1),this.A=IV[0]|0,this.B=IV[1]|0,this.C=IV[2]|0,this.D=IV[3]|0,this.E=IV[4]|0,this.F=IV[5]|0,this.G=IV[6]|0,this.H=IV[7]|0}get(){const{A:e,B:n,C:r,D:s,E:i,F:o,G:a,H:c}=this;return[e,n,r,s,i,o,a,c]}set(e,n,r,s,i,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let u=0;u<16;u++,n+=4)SHA256_W$1[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const p=SHA256_W$1[u-15],g=SHA256_W$1[u-2],m=rotr$1(p,7)^rotr$1(p,18)^p>>>3,d=rotr$1(g,17)^rotr$1(g,19)^g>>>10;SHA256_W$1[u]=d+SHA256_W$1[u-7]+m+SHA256_W$1[u-16]|0}let{A:r,B:s,C:i,D:o,E:a,F:c,G:l,H:h}=this;for(let u=0;u<64;u++){const p=rotr$1(a,6)^rotr$1(a,11)^rotr$1(a,25),g=h+p+Chi$1(a,c,l)+SHA256_K$1[u]+SHA256_W$1[u]|0,d=(rotr$1(r,2)^rotr$1(r,13)^rotr$1(r,22))+Maj$1(r,s,i)|0;h=l,l=c,c=a,a=o+g|0,o=i,i=s,s=r,r=g+d|0}r=r+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(r,s,i,o,a,c,l,h)}roundClean(){SHA256_W$1.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};class SHA224 extends SHA256$1{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const sha256$1=wrapConstructor$1(()=>new SHA256$1);wrapConstructor$1(()=>new SHA224);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$8=BigInt(0),_1n$9=BigInt(1),_2n$5=BigInt(2),u8a$1=t=>t instanceof Uint8Array,hexes$2=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function bytesToHex$2(t){if(!u8a$1(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=hexes$2[t[n]];return e}function numberToHexUnpadded$1(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function hexToNumber$1(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function hexToBytes$1(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){const s=r*2,i=t.slice(s,s+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function bytesToNumberBE$1(t){return hexToNumber$1(bytesToHex$2(t))}function bytesToNumberLE$1(t){if(!u8a$1(t))throw new Error("Uint8Array expected");return hexToNumber$1(bytesToHex$2(Uint8Array.from(t).reverse()))}function numberToBytesBE$1(t,e){return hexToBytes$1(t.toString(16).padStart(e*2,"0"))}function numberToBytesLE$1(t,e){return numberToBytesBE$1(t,e).reverse()}function numberToVarBytesBE$1(t){return hexToBytes$1(numberToHexUnpadded$1(t))}function ensureBytes$2(t,e,n){let r;if(typeof e=="string")try{r=hexToBytes$1(e)}catch(i){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${i}`)}else if(u8a$1(e))r=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);const s=r.length;if(typeof n=="number"&&s!==n)throw new Error(`${t} expected ${n} bytes, got ${s}`);return r}function concatBytes$2(...t){const e=new Uint8Array(t.reduce((r,s)=>r+s.length,0));let n=0;return t.forEach(r=>{if(!u8a$1(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}function equalBytes$2(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function utf8ToBytes$3(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function bitLen$1(t){let e;for(e=0;t>_0n$8;t>>=_1n$9,e+=1);return e}function bitGet$1(t,e){return t>>BigInt(e)&_1n$9}const bitSet$1=(t,e,n)=>t|(n?_1n$9:_0n$8)<<BigInt(e),bitMask$1=t=>(_2n$5<<BigInt(t-1))-_1n$9,u8n$1=t=>new Uint8Array(t),u8fr$1=t=>Uint8Array.from(t);function createHmacDrbg$1(t,e,n){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=u8n$1(t),s=u8n$1(t),i=0;const o=()=>{r.fill(1),s.fill(0),i=0},a=(...u)=>n(s,r,...u),c=(u=u8n$1())=>{s=a(u8fr$1([0]),u),r=a(),u.length!==0&&(s=a(u8fr$1([1]),u),r=a())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const p=[];for(;u<e;){r=a();const g=r.slice();p.push(g),u+=r.length}return concatBytes$2(...p)};return(u,p)=>{o(),c(u);let g;for(;!(g=p(l()));)c();return o(),g}}const validatorFns$1={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function validateObject$1(t,e,n={}){const r=(s,i,o)=>{const a=validatorFns$1[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);const c=t[s];if(!(o&&c===void 0)&&!a(c,t))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${i}`)};for(const[s,i]of Object.entries(e))r(s,i,!1);for(const[s,i]of Object.entries(n))r(s,i,!0);return t}const ut$1=Object.freeze(Object.defineProperty({__proto__:null,bitGet:bitGet$1,bitLen:bitLen$1,bitMask:bitMask$1,bitSet:bitSet$1,bytesToHex:bytesToHex$2,bytesToNumberBE:bytesToNumberBE$1,bytesToNumberLE:bytesToNumberLE$1,concatBytes:concatBytes$2,createHmacDrbg:createHmacDrbg$1,ensureBytes:ensureBytes$2,equalBytes:equalBytes$2,hexToBytes:hexToBytes$1,hexToNumber:hexToNumber$1,numberToBytesBE:numberToBytesBE$1,numberToBytesLE:numberToBytesLE$1,numberToHexUnpadded:numberToHexUnpadded$1,numberToVarBytesBE:numberToVarBytesBE$1,utf8ToBytes:utf8ToBytes$3,validateObject:validateObject$1},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$7=BigInt(0),_1n$8=BigInt(1),_2n$4=BigInt(2),_3n$3=BigInt(3),_4n$1=BigInt(4),_5n$1=BigInt(5),_8n$1=BigInt(8);BigInt(9);BigInt(16);function mod$1(t,e){const n=t%e;return n>=_0n$7?n:e+n}function pow$1(t,e,n){if(n<=_0n$7||e<_0n$7)throw new Error("Expected power/modulo > 0");if(n===_1n$8)return _0n$7;let r=_1n$8;for(;e>_0n$7;)e&_1n$8&&(r=r*t%n),t=t*t%n,e>>=_1n$8;return r}function pow2$1(t,e,n){let r=t;for(;e-- >_0n$7;)r*=r,r%=n;return r}function invert$1(t,e){if(t===_0n$7||e<=_0n$7)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=mod$1(t,e),r=e,s=_0n$7,i=_1n$8;for(;n!==_0n$7;){const a=r/n,c=r%n,l=s-i*a;r=n,n=c,s=i,i=l}if(r!==_1n$8)throw new Error("invert: does not exist");return mod$1(s,e)}function tonelliShanks$1(t){const e=(t-_1n$8)/_2n$4;let n,r,s;for(n=t-_1n$8,r=0;n%_2n$4===_0n$7;n/=_2n$4,r++);for(s=_2n$4;s<t&&pow$1(s,e,t)!==t-_1n$8;s++);if(r===1){const o=(t+_1n$8)/_4n$1;return function(c,l){const h=c.pow(l,o);if(!c.eql(c.sqr(h),l))throw new Error("Cannot find square root");return h}}const i=(n+_1n$8)/_2n$4;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=r,h=a.pow(a.mul(a.ONE,s),n),u=a.pow(c,i),p=a.pow(c,n);for(;!a.eql(p,a.ONE);){if(a.eql(p,a.ZERO))return a.ZERO;let g=1;for(let d=a.sqr(p);g<l&&!a.eql(d,a.ONE);g++)d=a.sqr(d);const m=a.pow(h,_1n$8<<BigInt(l-g-1));h=a.sqr(m),u=a.mul(u,m),p=a.mul(p,h),l=g}return u}}function FpSqrt$1(t){if(t%_4n$1===_3n$3){const e=(t+_1n$8)/_4n$1;return function(r,s){const i=r.pow(s,e);if(!r.eql(r.sqr(i),s))throw new Error("Cannot find square root");return i}}if(t%_8n$1===_5n$1){const e=(t-_5n$1)/_8n$1;return function(r,s){const i=r.mul(s,_2n$4),o=r.pow(i,e),a=r.mul(s,o),c=r.mul(r.mul(a,_2n$4),o),l=r.mul(a,r.sub(c,r.ONE));if(!r.eql(r.sqr(l),s))throw new Error("Cannot find square root");return l}}return tonelliShanks$1(t)}const FIELD_FIELDS$1=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function validateField$1(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=FIELD_FIELDS$1.reduce((r,s)=>(r[s]="function",r),e);return validateObject$1(t,n)}function FpPow$1(t,e,n){if(n<_0n$7)throw new Error("Expected power > 0");if(n===_0n$7)return t.ONE;if(n===_1n$8)return e;let r=t.ONE,s=e;for(;n>_0n$7;)n&_1n$8&&(r=t.mul(r,s)),s=t.sqr(s),n>>=_1n$8;return r}function FpInvertBatch$1(t,e){const n=new Array(e.length),r=e.reduce((i,o,a)=>t.is0(o)?i:(n[a]=i,t.mul(i,o)),t.ONE),s=t.inv(r);return e.reduceRight((i,o,a)=>t.is0(o)?i:(n[a]=t.mul(i,n[a]),t.mul(i,o)),s),n}function nLength$1(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Field$1(t,e,n=!1,r={}){if(t<=_0n$7)throw new Error(`Expected Fp ORDER > 0, got ${t}`);const{nBitLength:s,nByteLength:i}=nLength$1(t,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=FpSqrt$1(t),a=Object.freeze({ORDER:t,BITS:s,BYTES:i,MASK:bitMask$1(s),ZERO:_0n$7,ONE:_1n$8,create:c=>mod$1(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return _0n$7<=c&&c<t},is0:c=>c===_0n$7,isOdd:c=>(c&_1n$8)===_1n$8,neg:c=>mod$1(-c,t),eql:(c,l)=>c===l,sqr:c=>mod$1(c*c,t),add:(c,l)=>mod$1(c+l,t),sub:(c,l)=>mod$1(c-l,t),mul:(c,l)=>mod$1(c*l,t),pow:(c,l)=>FpPow$1(a,c,l),div:(c,l)=>mod$1(c*invert$1(l,t),t),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>invert$1(c,t),sqrt:r.sqrt||(c=>o(a,c)),invertBatch:c=>FpInvertBatch$1(a,c),cmov:(c,l,h)=>h?l:c,toBytes:c=>n?numberToBytesLE$1(c,i):numberToBytesBE$1(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return n?bytesToNumberLE$1(c):bytesToNumberBE$1(c)}});return Object.freeze(a)}function hashToPrivateScalar(t,e,n=!1){t=ensureBytes$2("privateHash",t);const r=t.length,s=nLength$1(e).nByteLength+8;if(s<24||r<s||r>1024)throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${r}`);const i=n?bytesToNumberLE$1(t):bytesToNumberBE$1(t);return mod$1(i,e-_1n$8)+_1n$8}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$6=BigInt(0),_1n$7=BigInt(1);function wNAF$1(t,e){const n=(s,i)=>{const o=i.negate();return s?o:i},r=s=>{const i=Math.ceil(e/s)+1,o=2**(s-1);return{windows:i,windowSize:o}};return{constTimeNegate:n,unsafeLadder(s,i){let o=t.ZERO,a=s;for(;i>_0n$6;)i&_1n$7&&(o=o.add(a)),a=a.double(),i>>=_1n$7;return o},precomputeWindow(s,i){const{windows:o,windowSize:a}=r(i),c=[];let l=s,h=l;for(let u=0;u<o;u++){h=l,c.push(h);for(let p=1;p<a;p++)h=h.add(l),c.push(h);l=h.double()}return c},wNAF(s,i,o){const{windows:a,windowSize:c}=r(s);let l=t.ZERO,h=t.BASE;const u=BigInt(2**s-1),p=2**s,g=BigInt(s);for(let m=0;m<a;m++){const d=m*c;let w=Number(o&u);o>>=g,w>c&&(w-=p,o+=_1n$7);const $=d,_=d+Math.abs(w)-1,x=m%2!==0,I=w<0;w===0?h=h.add(n(x,i[$])):l=l.add(n(I,i[_]))}return{p:l,f:h}},wNAFCached(s,i,o,a){const c=s._WINDOW_SIZE||1;let l=i.get(s);return l||(l=this.precomputeWindow(s,c),c!==1&&i.set(s,a(l))),this.wNAF(c,l,o)}}}function validateBasic$1(t){return validateField$1(t.Fp),validateObject$1(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...nLength$1(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function validatePointOpts$1(t){const e=validateBasic$1(t);validateObject$1(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:s}=e;if(n){if(!r.eql(s,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}const{bytesToNumberBE:b2n$1,hexToBytes:h2b$1}=ut$1,DER$1={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=DER$1;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");const n=t[1],r=t.subarray(2,n+2);if(!n||r.length!==n)throw new e("Invalid signature integer: wrong length");if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:b2n$1(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=DER$1,n=typeof t=="string"?h2b$1(t):t;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new e("Invalid signature tag");if(n[1]!==r-2)throw new e("Invalid signature: incorrect length");const{d:s,l:i}=DER$1._parseInt(n.subarray(2)),{d:o,l:a}=DER$1._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:s,s:o}},hexFromSig(t){const e=l=>Number.parseInt(l[0],16)&8?"00"+l:l,n=l=>{const h=l.toString(16);return h.length&1?`0${h}`:h},r=e(n(t.s)),s=e(n(t.r)),i=r.length/2,o=s.length/2,a=n(i),c=n(o);return`30${n(o+i+4)}02${c}${s}02${a}${r}`}},_0n$5=BigInt(0),_1n$6=BigInt(1);BigInt(2);const _3n$2=BigInt(3);BigInt(4);function weierstrassPoints$1(t){const e=validatePointOpts$1(t),{Fp:n}=e,r=e.toBytes||((m,d,w)=>{const $=d.toAffine();return concatBytes$2(Uint8Array.from([4]),n.toBytes($.x),n.toBytes($.y))}),s=e.fromBytes||(m=>{const d=m.subarray(1),w=n.fromBytes(d.subarray(0,n.BYTES)),$=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:w,y:$}});function i(m){const{a:d,b:w}=e,$=n.sqr(m),_=n.mul($,m);return n.add(n.add(_,n.mul(m,d)),w)}if(!n.eql(n.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function o(m){return typeof m=="bigint"&&_0n$5<m&&m<e.n}function a(m){if(!o(m))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(m){const{allowedPrivateKeyLengths:d,nByteLength:w,wrapPrivateKey:$,n:_}=e;if(d&&typeof m!="bigint"){if(m instanceof Uint8Array&&(m=bytesToHex$2(m)),typeof m!="string"||!d.includes(m.length))throw new Error("Invalid key");m=m.padStart(w*2,"0")}let x;try{x=typeof m=="bigint"?m:bytesToNumberBE$1(ensureBytes$2("private key",m,w))}catch{throw new Error(`private key must be ${w} bytes, hex or bigint, not ${typeof m}`)}return $&&(x=mod$1(x,_)),a(x),x}const l=new Map;function h(m){if(!(m instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,w,$){if(this.px=d,this.py=w,this.pz=$,d==null||!n.isValid(d))throw new Error("x required");if(w==null||!n.isValid(w))throw new Error("y required");if($==null||!n.isValid($))throw new Error("z required")}static fromAffine(d){const{x:w,y:$}=d||{};if(!d||!n.isValid(w)||!n.isValid($))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");const _=x=>n.eql(x,n.ZERO);return _(w)&&_($)?u.ZERO:new u(w,$,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const w=n.invertBatch(d.map($=>$.pz));return d.map(($,_)=>$.toAffine(w[_])).map(u.fromAffine)}static fromHex(d){const w=u.fromAffine(s(ensureBytes$2("pointHex",d)));return w.assertValidity(),w}static fromPrivateKey(d){return u.BASE.multiply(c(d))}_setWindowSize(d){this._WINDOW_SIZE=d,l.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:d,y:w}=this.toAffine();if(!n.isValid(d)||!n.isValid(w))throw new Error("bad point: x or y not FE");const $=n.sqr(w),_=i(d);if(!n.eql($,_))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:d}=this.toAffine();if(n.isOdd)return!n.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){h(d);const{px:w,py:$,pz:_}=this,{px:x,py:I,pz:R}=d,v=n.eql(n.mul(w,R),n.mul(x,_)),B=n.eql(n.mul($,R),n.mul(I,_));return v&&B}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:w}=e,$=n.mul(w,_3n$2),{px:_,py:x,pz:I}=this;let R=n.ZERO,v=n.ZERO,B=n.ZERO,S=n.mul(_,_),H=n.mul(x,x),L=n.mul(I,I),E=n.mul(_,x);return E=n.add(E,E),B=n.mul(_,I),B=n.add(B,B),R=n.mul(d,B),v=n.mul($,L),v=n.add(R,v),R=n.sub(H,v),v=n.add(H,v),v=n.mul(R,v),R=n.mul(E,R),B=n.mul($,B),L=n.mul(d,L),E=n.sub(S,L),E=n.mul(d,E),E=n.add(E,B),B=n.add(S,S),S=n.add(B,S),S=n.add(S,L),S=n.mul(S,E),v=n.add(v,S),L=n.mul(x,I),L=n.add(L,L),S=n.mul(L,E),R=n.sub(R,S),B=n.mul(L,H),B=n.add(B,B),B=n.add(B,B),new u(R,v,B)}add(d){h(d);const{px:w,py:$,pz:_}=this,{px:x,py:I,pz:R}=d;let v=n.ZERO,B=n.ZERO,S=n.ZERO;const H=e.a,L=n.mul(e.b,_3n$2);let E=n.mul(w,x),k=n.mul($,I),T=n.mul(_,R),P=n.add(w,$),y=n.add(x,I);P=n.mul(P,y),y=n.add(E,k),P=n.sub(P,y),y=n.add(w,_);let b=n.add(x,R);return y=n.mul(y,b),b=n.add(E,T),y=n.sub(y,b),b=n.add($,_),v=n.add(I,R),b=n.mul(b,v),v=n.add(k,T),b=n.sub(b,v),S=n.mul(H,y),v=n.mul(L,T),S=n.add(v,S),v=n.sub(k,S),S=n.add(k,S),B=n.mul(v,S),k=n.add(E,E),k=n.add(k,E),T=n.mul(H,T),y=n.mul(L,y),k=n.add(k,T),T=n.sub(E,T),T=n.mul(H,T),y=n.add(y,T),E=n.mul(k,y),B=n.add(B,E),E=n.mul(b,y),v=n.mul(P,v),v=n.sub(v,E),E=n.mul(P,k),S=n.mul(b,S),S=n.add(S,E),new u(v,B,S)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return g.wNAFCached(this,l,d,w=>{const $=n.invertBatch(w.map(_=>_.pz));return w.map((_,x)=>_.toAffine($[x])).map(u.fromAffine)})}multiplyUnsafe(d){const w=u.ZERO;if(d===_0n$5)return w;if(a(d),d===_1n$6)return this;const{endo:$}=e;if(!$)return g.unsafeLadder(this,d);let{k1neg:_,k1:x,k2neg:I,k2:R}=$.splitScalar(d),v=w,B=w,S=this;for(;x>_0n$5||R>_0n$5;)x&_1n$6&&(v=v.add(S)),R&_1n$6&&(B=B.add(S)),S=S.double(),x>>=_1n$6,R>>=_1n$6;return _&&(v=v.negate()),I&&(B=B.negate()),B=new u(n.mul(B.px,$.beta),B.py,B.pz),v.add(B)}multiply(d){a(d);let w=d,$,_;const{endo:x}=e;if(x){const{k1neg:I,k1:R,k2neg:v,k2:B}=x.splitScalar(w);let{p:S,f:H}=this.wNAF(R),{p:L,f:E}=this.wNAF(B);S=g.constTimeNegate(I,S),L=g.constTimeNegate(v,L),L=new u(n.mul(L.px,x.beta),L.py,L.pz),$=S.add(L),_=H.add(E)}else{const{p:I,f:R}=this.wNAF(w);$=I,_=R}return u.normalizeZ([$,_])[0]}multiplyAndAddUnsafe(d,w,$){const _=u.BASE,x=(R,v)=>v===_0n$5||v===_1n$6||!R.equals(_)?R.multiplyUnsafe(v):R.multiply(v),I=x(this,w).add(x(d,$));return I.is0()?void 0:I}toAffine(d){const{px:w,py:$,pz:_}=this,x=this.is0();d==null&&(d=x?n.ONE:n.inv(_));const I=n.mul(w,d),R=n.mul($,d),v=n.mul(_,d);if(x)return{x:n.ZERO,y:n.ZERO};if(!n.eql(v,n.ONE))throw new Error("invZ was invalid");return{x:I,y:R}}isTorsionFree(){const{h:d,isTorsionFree:w}=e;if(d===_1n$6)return!0;if(w)return w(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:w}=e;return d===_1n$6?this:w?w(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return bytesToHex$2(this.toRawBytes(d))}}u.BASE=new u(e.Gx,e.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const p=e.nBitLength,g=wNAF$1(u,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:o}}function validateOpts$1(t){const e=validateBasic$1(t);return validateObject$1(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function weierstrass$1(t){const e=validateOpts$1(t),{Fp:n,n:r}=e,s=n.BYTES+1,i=2*n.BYTES+1;function o(y){return _0n$5<y&&y<n.ORDER}function a(y){return mod$1(y,r)}function c(y){return invert$1(y,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:h,weierstrassEquation:u,isWithinCurveOrder:p}=weierstrassPoints$1({...e,toBytes(y,b,A){const U=b.toAffine(),C=n.toBytes(U.x),D=concatBytes$2;return A?D(Uint8Array.from([b.hasEvenY()?2:3]),C):D(Uint8Array.from([4]),C,n.toBytes(U.y))},fromBytes(y){const b=y.length,A=y[0],U=y.subarray(1);if(b===s&&(A===2||A===3)){const C=bytesToNumberBE$1(U);if(!o(C))throw new Error("Point is not on curve");const D=u(C);let F=n.sqrt(D);const O=(F&_1n$6)===_1n$6;return(A&1)===1!==O&&(F=n.neg(F)),{x:C,y:F}}else if(b===i&&A===4){const C=n.fromBytes(U.subarray(0,n.BYTES)),D=n.fromBytes(U.subarray(n.BYTES,2*n.BYTES));return{x:C,y:D}}else throw new Error(`Point of length ${b} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),g=y=>bytesToHex$2(numberToBytesBE$1(y,e.nByteLength));function m(y){const b=r>>_1n$6;return y>b}function d(y){return m(y)?a(-y):y}const w=(y,b,A)=>bytesToNumberBE$1(y.slice(b,A));class ${constructor(b,A,U){this.r=b,this.s=A,this.recovery=U,this.assertValidity()}static fromCompact(b){const A=e.nByteLength;return b=ensureBytes$2("compactSignature",b,A*2),new $(w(b,0,A),w(b,A,2*A))}static fromDER(b){const{r:A,s:U}=DER$1.toSig(ensureBytes$2("DER",b));return new $(A,U)}assertValidity(){if(!p(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!p(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(b){return new $(this.r,this.s,b)}recoverPublicKey(b){const{r:A,s:U,recovery:C}=this,D=B(ensureBytes$2("msgHash",b));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");const F=C===2||C===3?A+e.n:A;if(F>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const O=C&1?"03":"02",K=l.fromHex(O+g(F)),M=c(F),z=a(-D*M),V=a(U*M),q=l.BASE.multiplyAndAddUnsafe(K,z,V);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new $(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return hexToBytes$1(this.toDERHex())}toDERHex(){return DER$1.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hexToBytes$1(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}const _={isValidPrivateKey(y){try{return h(y),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const y=e.randomBytes(n.BYTES+8),b=hashToPrivateScalar(y,r);return numberToBytesBE$1(b,e.nByteLength)},precompute(y=8,b=l.BASE){return b._setWindowSize(y),b.multiply(BigInt(3)),b}};function x(y,b=!0){return l.fromPrivateKey(y).toRawBytes(b)}function I(y){const b=y instanceof Uint8Array,A=typeof y=="string",U=(b||A)&&y.length;return b?U===s||U===i:A?U===2*s||U===2*i:y instanceof l}function R(y,b,A=!0){if(I(y))throw new Error("first arg must be private key");if(!I(b))throw new Error("second arg must be public key");return l.fromHex(b).multiply(h(y)).toRawBytes(A)}const v=e.bits2int||function(y){const b=bytesToNumberBE$1(y),A=y.length*8-e.nBitLength;return A>0?b>>BigInt(A):b},B=e.bits2int_modN||function(y){return a(v(y))},S=bitMask$1(e.nBitLength);function H(y){if(typeof y!="bigint")throw new Error("bigint expected");if(!(_0n$5<=y&&y<S))throw new Error(`bigint expected < 2^${e.nBitLength}`);return numberToBytesBE$1(y,e.nByteLength)}function L(y,b,A=E){if(["recovered","canonical"].some(W=>W in A))throw new Error("sign() legacy options not supported");const{hash:U,randomBytes:C}=e;let{lowS:D,prehash:F,extraEntropy:O}=A;D==null&&(D=!0),y=ensureBytes$2("msgHash",y),F&&(y=ensureBytes$2("prehashed msgHash",U(y)));const K=B(y),M=h(b),z=[H(M),H(K)];if(O!=null){const W=O===!0?C(n.BYTES):O;z.push(ensureBytes$2("extraEntropy",W,n.BYTES))}const V=concatBytes$2(...z),q=K;function G(W){const Z=v(W);if(!p(Z))return;const J=c(Z),Y=l.BASE.multiply(Z).toAffine(),j=a(Y.x);if(j===_0n$5)return;const X=a(J*a(q+j*M));if(X===_0n$5)return;let Q=(Y.x===j?0:2)|Number(Y.y&_1n$6),te=X;return D&&m(X)&&(te=d(X),Q^=1),new $(j,te,Q)}return{seed:V,k2sig:G}}const E={lowS:e.lowS,prehash:!1},k={lowS:e.lowS,prehash:!1};function T(y,b,A=E){const{seed:U,k2sig:C}=L(y,b,A),D=e;return createHmacDrbg$1(D.hash.outputLen,D.nByteLength,D.hmac)(U,C)}l.BASE._setWindowSize(8);function P(y,b,A,U=k){var Y;const C=y;if(b=ensureBytes$2("msgHash",b),A=ensureBytes$2("publicKey",A),"strict"in U)throw new Error("options.strict was renamed to lowS");const{lowS:D,prehash:F}=U;let O,K;try{if(typeof C=="string"||C instanceof Uint8Array)try{O=$.fromDER(C)}catch(j){if(!(j instanceof DER$1.Err))throw j;O=$.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){const{r:j,s:X}=C;O=new $(j,X)}else throw new Error("PARSE");K=l.fromHex(A)}catch(j){if(j.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(D&&O.hasHighS())return!1;F&&(b=e.hash(b));const{r:M,s:z}=O,V=B(b),q=c(z),G=a(V*q),W=a(M*q),Z=(Y=l.BASE.multiplyAndAddUnsafe(K,G,W))==null?void 0:Y.toAffine();return Z?a(Z.x)===M:!1}return{CURVE:e,getPublicKey:x,getSharedSecret:R,sign:T,verify:P,ProjectivePoint:l,Signature:$,utils:_}}let HMAC$1=class extends Hash$1{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,assert$1.hash(e);const r=toBytes$2(n);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,i=new Uint8Array(s);i.set(r.length>s?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),i.fill(0)}update(e){return assert$1.exists(this),this.iHash.update(e),this}digestInto(e){assert$1.exists(this),assert$1.bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const hmac$1=(t,e,n)=>new HMAC$1(t,e).update(n).digest();hmac$1.create=(t,e)=>new HMAC$1(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function getHash$1(t){return{hash:t,hmac:(e,...n)=>hmac$1(t,e,concatBytes$3(...n)),randomBytes:randomBytes$1}}function createCurve$1(t,e){const n=r=>weierstrass$1({...t,...getHash$1(r)});return Object.freeze({...n(e),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const secp256k1P$1=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),secp256k1N$1=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),_1n$5=BigInt(1),_2n$3=BigInt(2),divNearest$1=(t,e)=>(t+e/_2n$3)/e;function sqrtMod$1(t){const e=secp256k1P$1,n=BigInt(3),r=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),l=t*t*t%e,h=l*l*t%e,u=pow2$1(h,n,e)*h%e,p=pow2$1(u,n,e)*h%e,g=pow2$1(p,_2n$3,e)*l%e,m=pow2$1(g,s,e)*g%e,d=pow2$1(m,i,e)*m%e,w=pow2$1(d,a,e)*d%e,$=pow2$1(w,c,e)*w%e,_=pow2$1($,a,e)*d%e,x=pow2$1(_,n,e)*h%e,I=pow2$1(x,o,e)*m%e,R=pow2$1(I,r,e)*l%e,v=pow2$1(R,_2n$3,e);if(!Fp$1.eql(Fp$1.sqr(v),t))throw new Error("Cannot find square root");return v}const Fp$1=Field$1(secp256k1P$1,void 0,void 0,{sqrt:sqrtMod$1}),secp256k1$1=createCurve$1({a:BigInt(0),b:BigInt(7),Fp:Fp$1,n:secp256k1N$1,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=secp256k1N$1,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-_1n$5*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,o=BigInt("0x100000000000000000000000000000000"),a=divNearest$1(i*t,e),c=divNearest$1(-r*t,e);let l=mod$1(t-a*n-c*s,e),h=mod$1(-a*r-c*i,e);const u=l>o,p=h>o;if(u&&(l=e-l),p&&(h=e-h),l>o||h>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:l,k2neg:p,k2:h}}}},sha256$1);BigInt(0);secp256k1$1.ProjectivePoint;const Point$1=secp256k1$1.ProjectivePoint,base58check=base58check$1(sha256$2);function bytesToNumber(t){return BigInt(`0x${bytesToHex$3(t)}`)}function numberToBytes(t){return hexToBytes$2(t.toString(16).padStart(64,"0"))}const MASTER_SECRET=utf8ToBytes$5("Bitcoin seed"),BITCOIN_VERSIONS={private:76066276,public:76067358},HARDENED_OFFSET=2147483648,hash160=t=>ripemd160(sha256$2(t)),fromU32=t=>createView$2(t).getUint32(0,!1),toU32=t=>{if(!Number.isSafeInteger(t)||t<0||t>2**32-1)throw new Error(`Invalid number=${t}. Should be from 0 to 2 ** 32 - 1`);const e=new Uint8Array(4);return createView$2(e).setUint32(0,t,!1),e};class HDKey{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return fromU32(this.pubHash)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this.privKeyBytes||null}get publicKey(){return this.pubKey||null}get privateExtendedKey(){const e=this.privateKey;if(!e)throw new Error("No private key");return base58check.encode(this.serialize(this.versions.private,concatBytes$4(new Uint8Array([0]),e)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return base58check.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(e,n=BITCOIN_VERSIONS){if(bytes$3(e),8*e.length<128||8*e.length>512)throw new Error(`HDKey: wrong seed length=${e.length}. Should be between 128 and 512 bits; 256 bits is advised)`);const r=hmac$2(sha512,MASTER_SECRET,e);return new HDKey({versions:n,chainCode:r.slice(32),privateKey:r.slice(0,32)})}static fromExtendedKey(e,n=BITCOIN_VERSIONS){const r=base58check.decode(e),s=createView$2(r),i=s.getUint32(0,!1),o={versions:n,depth:r[4],parentFingerprint:s.getUint32(5,!1),index:s.getUint32(9,!1),chainCode:r.slice(13,45)},a=r.slice(45),c=a[0]===0;if(i!==n[c?"private":"public"])throw new Error("Version mismatch");return c?new HDKey({...o,privateKey:a.slice(1)}):new HDKey({...o,publicKey:a})}static fromJSON(e){return HDKey.fromExtendedKey(e.xpriv)}constructor(e){if(this.depth=0,this.index=0,this.chainCode=null,this.parentFingerprint=0,!e||typeof e!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=e.versions||BITCOIN_VERSIONS,this.depth=e.depth||0,this.chainCode=e.chainCode,this.index=e.index||0,this.parentFingerprint=e.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(e.publicKey&&e.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(e.privateKey){if(!secp256k1$1.utils.isValidPrivateKey(e.privateKey))throw new Error("Invalid private key");this.privKey=typeof e.privateKey=="bigint"?e.privateKey:bytesToNumber(e.privateKey),this.privKeyBytes=numberToBytes(this.privKey),this.pubKey=secp256k1$1.getPublicKey(e.privateKey,!0)}else if(e.publicKey)this.pubKey=Point$1.fromHex(e.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=hash160(this.pubKey)}derive(e){if(!/^[mM]'?/.test(e))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(e))return this;const n=e.replace(/^[mM]'?\//,"").split("/");let r=this;for(const s of n){const i=/^(\d+)('?)$/.exec(s);if(!i||i.length!==3)throw new Error(`Invalid child index: ${s}`);let o=+i[1];if(!Number.isSafeInteger(o)||o>=HARDENED_OFFSET)throw new Error("Invalid index");i[2]==="'"&&(o+=HARDENED_OFFSET),r=r.deriveChild(o)}return r}deriveChild(e){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=toU32(e);if(e>=HARDENED_OFFSET){const a=this.privateKey;if(!a)throw new Error("Could not derive hardened child key");n=concatBytes$4(new Uint8Array([0]),a,n)}else n=concatBytes$4(this.pubKey,n);const r=hmac$2(sha512,this.chainCode,n),s=bytesToNumber(r.slice(0,32)),i=r.slice(32);if(!secp256k1$1.utils.isValidPrivateKey(s))throw new Error("Tweak bigger than curve order");const o={versions:this.versions,chainCode:i,depth:this.depth+1,parentFingerprint:this.fingerprint,index:e};try{if(this.privateKey){const a=mod$1(this.privKey+s,secp256k1$1.CURVE.n);if(!secp256k1$1.utils.isValidPrivateKey(a))throw new Error("The tweak was out of range or the resulted private key is invalid");o.privateKey=a}else{const a=Point$1.fromHex(this.pubKey).add(Point$1.fromPrivateKey(s));if(a.equals(Point$1.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");o.publicKey=a.toRawBytes(!0)}return new HDKey(o)}catch{return this.deriveChild(e+1)}}sign(e){if(!this.privateKey)throw new Error("No privateKey set!");return bytes$3(e,32),secp256k1$1.sign(e,this.privKey).toCompactRawBytes()}verify(e,n){if(bytes$3(e,32),bytes$3(n,64),!this.publicKey)throw new Error("No publicKey set!");let r;try{r=secp256k1$1.Signature.fromCompact(n)}catch{return!1}return secp256k1$1.verify(r,e,this.publicKey)}wipePrivateData(){return this.privKey=void 0,this.privKeyBytes&&(this.privKeyBytes.fill(0),this.privKeyBytes=void 0),this}toJSON(){return{xpriv:this.privateExtendedKey,xpub:this.publicExtendedKey}}serialize(e,n){if(!this.chainCode)throw new Error("No chainCode set");return bytes$3(n,33),concatBytes$4(toU32(e),new Uint8Array([this.depth]),toU32(this.parentFingerprint),toU32(this.index),this.chainCode,n)}}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */const u8a=t=>t instanceof Uint8Array,u32=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE)throw new Error("Non little-endian hardware is not supported");function utf8ToBytes$2(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function toBytes$1(t){if(typeof t=="string"&&(t=utf8ToBytes$2(t)),!u8a(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}const isPlainObject=t=>Object.prototype.toString.call(t)==="[object Object]"&&t.constructor===Object;function checkOpts(t,e){if(e!==void 0&&(typeof e!="object"||!isPlainObject(e)))throw new Error("options must be object or undefined");return Object.assign(t,e)}function ensureBytes$1(t,e){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");if(typeof e=="number"&&t.length!==e)throw new Error(`Uint8Array length ${e} expected`)}function equalBytes$1(t,e){if(t.length!==e.length)throw new Error("equalBytes: Different size of Uint8Arrays");let n=!0;for(let r=0;r<t.length;r++)n&&(n=t[r]===e[r]);return n}function number$1(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function bool(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function bytes$1(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function hash$1(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("hash must be wrapped by utils.wrapConstructor");number$1(t.outputLen),number$1(t.blockLen)}function exists$1(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 output$1(t,e){bytes$1(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const assert={number:number$1,bool,bytes:bytes$1,hash:hash$1,exists:exists$1,output:output$1},u8to16=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class Poly1305{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=toBytes$1(e),ensureBytes$1(e,32);const n=u8to16(e,0),r=u8to16(e,2),s=u8to16(e,4),i=u8to16(e,6),o=u8to16(e,8),a=u8to16(e,10),c=u8to16(e,12),l=u8to16(e,14);this.r[0]=n&8191,this.r[1]=(n>>>13|r<<3)&8191,this.r[2]=(r>>>10|s<<6)&7939,this.r[3]=(s>>>7|i<<9)&8191,this.r[4]=(i>>>4|o<<12)&255,this.r[5]=o>>>1&8190,this.r[6]=(o>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let h=0;h<8;h++)this.pad[h]=u8to16(e,16+2*h)}process(e,n,r=!1){const s=r?0:2048,{h:i,r:o}=this,a=o[0],c=o[1],l=o[2],h=o[3],u=o[4],p=o[5],g=o[6],m=o[7],d=o[8],w=o[9],$=u8to16(e,n+0),_=u8to16(e,n+2),x=u8to16(e,n+4),I=u8to16(e,n+6),R=u8to16(e,n+8),v=u8to16(e,n+10),B=u8to16(e,n+12),S=u8to16(e,n+14);let H=i[0]+($&8191),L=i[1]+(($>>>13|_<<3)&8191),E=i[2]+((_>>>10|x<<6)&8191),k=i[3]+((x>>>7|I<<9)&8191),T=i[4]+((I>>>4|R<<12)&8191),P=i[5]+(R>>>1&8191),y=i[6]+((R>>>14|v<<2)&8191),b=i[7]+((v>>>11|B<<5)&8191),A=i[8]+((B>>>8|S<<8)&8191),U=i[9]+(S>>>5|s),C=0,D=C+H*a+L*(5*w)+E*(5*d)+k*(5*m)+T*(5*g);C=D>>>13,D&=8191,D+=P*(5*p)+y*(5*u)+b*(5*h)+A*(5*l)+U*(5*c),C+=D>>>13,D&=8191;let F=C+H*c+L*a+E*(5*w)+k*(5*d)+T*(5*m);C=F>>>13,F&=8191,F+=P*(5*g)+y*(5*p)+b*(5*u)+A*(5*h)+U*(5*l),C+=F>>>13,F&=8191;let O=C+H*l+L*c+E*a+k*(5*w)+T*(5*d);C=O>>>13,O&=8191,O+=P*(5*m)+y*(5*g)+b*(5*p)+A*(5*u)+U*(5*h),C+=O>>>13,O&=8191;let K=C+H*h+L*l+E*c+k*a+T*(5*w);C=K>>>13,K&=8191,K+=P*(5*d)+y*(5*m)+b*(5*g)+A*(5*p)+U*(5*u),C+=K>>>13,K&=8191;let M=C+H*u+L*h+E*l+k*c+T*a;C=M>>>13,M&=8191,M+=P*(5*w)+y*(5*d)+b*(5*m)+A*(5*g)+U*(5*p),C+=M>>>13,M&=8191;let z=C+H*p+L*u+E*h+k*l+T*c;C=z>>>13,z&=8191,z+=P*a+y*(5*w)+b*(5*d)+A*(5*m)+U*(5*g),C+=z>>>13,z&=8191;let V=C+H*g+L*p+E*u+k*h+T*l;C=V>>>13,V&=8191,V+=P*c+y*a+b*(5*w)+A*(5*d)+U*(5*m),C+=V>>>13,V&=8191;let q=C+H*m+L*g+E*p+k*u+T*h;C=q>>>13,q&=8191,q+=P*l+y*c+b*a+A*(5*w)+U*(5*d),C+=q>>>13,q&=8191;let G=C+H*d+L*m+E*g+k*p+T*u;C=G>>>13,G&=8191,G+=P*h+y*l+b*c+A*a+U*(5*w),C+=G>>>13,G&=8191;let W=C+H*w+L*d+E*m+k*g+T*p;C=W>>>13,W&=8191,W+=P*u+y*h+b*l+A*c+U*a,C+=W>>>13,W&=8191,C=(C<<2)+C|0,C=C+D|0,D=C&8191,C=C>>>13,F+=C,i[0]=D,i[1]=F,i[2]=O,i[3]=K,i[4]=M,i[5]=z,i[6]=V,i[7]=q,i[8]=G,i[9]=W}finalize(){const{h:e,pad:n}=this,r=new Uint16Array(10);let s=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=s,s=e[a]>>>13,e[a]&=8191;e[0]+=s*5,s=e[0]>>>13,e[0]&=8191,e[1]+=s,s=e[1]>>>13,e[1]&=8191,e[2]+=s,r[0]=e[0]+5,s=r[0]>>>13,r[0]&=8191;for(let a=1;a<10;a++)r[a]=e[a]+s,s=r[a]>>>13,r[a]&=8191;r[9]-=8192;let i=(s^1)-1;for(let a=0;a<10;a++)r[a]&=i;i=~i;for(let a=0;a<10;a++)e[a]=e[a]&i|r[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let o=e[0]+n[0];e[0]=o&65535;for(let a=1;a<8;a++)o=(e[a]+n[a]|0)+(o>>>16)|0,e[a]=o&65535}update(e){assert.exists(this);const{buffer:n,blockLen:r}=this;e=toBytes$1(e);const s=e.length;for(let i=0;i<s;){const o=Math.min(r-this.pos,s-i);if(o===r){for(;r<=s-i;i+=r)this.process(e,i);continue}n.set(e.subarray(i,i+o),this.pos),this.pos+=o,i+=o,this.pos===r&&(this.process(n,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){assert.exists(this),assert.output(e,this),this.finished=!0;const{buffer:n,h:r}=this;let{pos:s}=this;if(s){for(n[s++]=1;s<16;s++)n[s]=0;this.process(n,0,!0)}this.finalize();let i=0;for(let o=0;o<8;o++)e[i++]=r[o]>>>0,e[i++]=r[o]>>>8;return e}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}}function wrapConstructorWithKey(t){const e=(r,s)=>t(s).update(toBytes$1(r)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}wrapConstructorWithKey(t=>new Poly1305(t));const sigma16=utf8ToBytes$2("expand 16-byte k"),sigma32=utf8ToBytes$2("expand 32-byte k"),sigma16_32=u32(sigma16),sigma32_32=u32(sigma32),isAligned32=t=>!(t.byteOffset%4),salsaBasic=t=>{const{core:e,rounds:n,counterRight:r,counterLen:s,allow128bitKeys:i,extendNonceFn:o,blockLen:a}=checkOpts({rounds:20,counterRight:!1,counterLen:8,allow128bitKeys:!0,blockLen:64},t);assert.number(s),assert.number(n),assert.number(a),assert.bool(r),assert.bool(i);const c=a/4;if(a%4!==0)throw new Error("Salsa/ChaCha: blockLen must be aligned to 4 bytes");return(l,h,u,p,g=0)=>{if(assert.bytes(l),assert.bytes(h),assert.bytes(u),p||(p=new Uint8Array(u.length)),assert.bytes(p),assert.number(g),g<0||g>=2**32-1)throw new Error("Salsa/ChaCha: counter overflow");if(p.length<u.length)throw new Error(`Salsa/ChaCha: output (${p.length}) is shorter than data (${u.length})`);const m=[];let d,w;if(l.length===32)d=l,w=sigma32_32;else if(l.length===16&&i)d=new Uint8Array(32),d.set(l),d.set(l,16),w=sigma16_32,m.push(d);else throw new Error(`Salsa/ChaCha: invalid 32-byte key, got length=${l.length}`);if(o){if(h.length<=16)throw new Error("Salsa/ChaCha: extended nonce must be bigger than 16 bytes");d=o(w,d,h.subarray(0,16),new Uint8Array(32)),m.push(d),h=h.subarray(16)}const $=16-s;if(h.length!==$)throw new Error(`Salsa/ChaCha: nonce must be ${$} or 16 bytes`);if($!==12){const H=new Uint8Array(12);H.set(h,r?0:12-h.length),m.push(h=H)}const _=new Uint8Array(a),x=u32(_),I=u32(d),R=u32(h),v=isAligned32(u)&&u32(u),B=isAligned32(p)&&u32(p);m.push(x);const S=u.length;for(let H=0,L=g;H<S;L++){if(e(w,I,R,x,L,n),L>=2**32-1)throw new Error("Salsa/ChaCha: counter overflow");const E=Math.min(a,S-H);if(E===a&&B&&v){const k=H/4;if(H%4!==0)throw new Error("Salsa/ChaCha: invalid block position");for(let T=0;T<c;T++)B[k+T]=v[k+T]^x[T];H+=a;continue}for(let k=0;k<E;k++)p[H+k]=u[H+k]^_[k];H+=E}for(let H=0;H<m.length;H++)m[H].fill(0);return p}},rotl=(t,e)=>t<<e|t>>>32-e;function chachaCore(t,e,n,r,s,i=20){let o=t[0],a=t[1],c=t[2],l=t[3],h=e[0],u=e[1],p=e[2],g=e[3],m=e[4],d=e[5],w=e[6],$=e[7],_=s,x=n[0],I=n[1],R=n[2],v=o,B=a,S=c,H=l,L=h,E=u,k=p,T=g,P=m,y=d,b=w,A=$,U=_,C=x,D=I,F=R;for(let K=0;K<i;K+=2)v=v+L|0,U=rotl(U^v,16),P=P+U|0,L=rotl(L^P,12),v=v+L|0,U=rotl(U^v,8),P=P+U|0,L=rotl(L^P,7),B=B+E|0,C=rotl(C^B,16),y=y+C|0,E=rotl(E^y,12),B=B+E|0,C=rotl(C^B,8),y=y+C|0,E=rotl(E^y,7),S=S+k|0,D=rotl(D^S,16),b=b+D|0,k=rotl(k^b,12),S=S+k|0,D=rotl(D^S,8),b=b+D|0,k=rotl(k^b,7),H=H+T|0,F=rotl(F^H,16),A=A+F|0,T=rotl(T^A,12),H=H+T|0,F=rotl(F^H,8),A=A+F|0,T=rotl(T^A,7),v=v+E|0,F=rotl(F^v,16),b=b+F|0,E=rotl(E^b,12),v=v+E|0,F=rotl(F^v,8),b=b+F|0,E=rotl(E^b,7),B=B+k|0,U=rotl(U^B,16),A=A+U|0,k=rotl(k^A,12),B=B+k|0,U=rotl(U^B,8),A=A+U|0,k=rotl(k^A,7),S=S+T|0,C=rotl(C^S,16),P=P+C|0,T=rotl(T^P,12),S=S+T|0,C=rotl(C^S,8),P=P+C|0,T=rotl(T^P,7),H=H+L|0,D=rotl(D^H,16),y=y+D|0,L=rotl(L^y,12),H=H+L|0,D=rotl(D^H,8),y=y+D|0,L=rotl(L^y,7);let O=0;r[O++]=o+v|0,r[O++]=a+B|0,r[O++]=c+S|0,r[O++]=l+H|0,r[O++]=h+L|0,r[O++]=u+E|0,r[O++]=p+k|0,r[O++]=g+T|0,r[O++]=m+P|0,r[O++]=d+y|0,r[O++]=w+b|0,r[O++]=$+A|0,r[O++]=_+U|0,r[O++]=x+C|0,r[O++]=I+D|0,r[O++]=R+F|0}const chacha20=salsaBasic({core:chachaCore,counterRight:!1,counterLen:4,allow128bitKeys:!1});function extract(t,e,n){return assert$3.hash(t),n===void 0&&(n=new Uint8Array(t.outputLen)),hmac$4(t,toBytes$5(n),toBytes$5(e))}const HKDF_COUNTER=new Uint8Array([0]),EMPTY_BUFFER=new Uint8Array;function expand(t,e,n,r=32){if(assert$3.hash(t),assert$3.number(r),r>255*t.outputLen)throw new Error("Length should be <= 255*HashLen");const s=Math.ceil(r/t.outputLen);n===void 0&&(n=EMPTY_BUFFER);const i=new Uint8Array(s*t.outputLen),o=hmac$4.create(t,e),a=o._cloneInto(),c=new Uint8Array(o.outputLen);for(let l=0;l<s;l++)HKDF_COUNTER[0]=l+1,a.update(l===0?EMPTY_BUFFER:c).update(n).update(HKDF_COUNTER).digestInto(c),i.set(c,t.outputLen*l),o._cloneInto(a);return o.destroy(),a.destroy(),c.fill(0),HKDF_COUNTER.fill(0),i.slice(0,r)}const hkdf=(t,e,n,r,s)=>expand(t,extract(t,e,n),r,s);var __defProp=Object.defineProperty,__export=(t,e)=>{for(var n in e)__defProp(t,n,{get:e[n],enumerable:!0})};function generatePrivateKey(){return bytesToHex$5(schnorr$1.utils.randomPrivateKey())}function getPublicKey(t){return bytesToHex$5(schnorr$1.getPublicKey(t))}var utils_exports={};__export(utils_exports,{MessageNode:()=>MessageNode,MessageQueue:()=>MessageQueue,insertEventIntoAscendingList:()=>insertEventIntoAscendingList,insertEventIntoDescendingList:()=>insertEventIntoDescendingList,normalizeURL:()=>normalizeURL,utf8Decoder:()=>utf8Decoder,utf8Encoder:()=>utf8Encoder});var utf8Decoder=new TextDecoder("utf-8"),utf8Encoder=new TextEncoder;function normalizeURL(t){let e=new URL(t);return e.pathname=e.pathname.replace(/\/+/g,"/"),e.pathname.endsWith("/")&&(e.pathname=e.pathname.slice(0,-1)),(e.port==="80"&&e.protocol==="ws:"||e.port==="443"&&e.protocol==="wss:")&&(e.port=""),e.searchParams.sort(),e.hash="",e.toString()}function insertEventIntoDescendingList(t,e){var o;let n=0,r=t.length-1,s,i=n;if(r<0)i=0;else if(e.created_at<t[r].created_at)i=r+1;else if(e.created_at>=t[n].created_at)i=n;else for(;;){if(r<=n+1){i=r;break}if(s=Math.floor(n+(r-n)/2),t[s].created_at>e.created_at)n=s;else if(t[s].created_at<e.created_at)r=s;else{i=s;break}}return((o=t[i])==null?void 0:o.id)!==e.id?[...t.slice(0,i),e,...t.slice(i)]:t}function insertEventIntoAscendingList(t,e){var o;let n=0,r=t.length-1,s,i=n;if(r<0)i=0;else if(e.created_at>t[r].created_at)i=r+1;else if(e.created_at<=t[n].created_at)i=n;else for(;;){if(r<=n+1){i=r;break}if(s=Math.floor(n+(r-n)/2),t[s].created_at<e.created_at)n=s;else if(t[s].created_at>e.created_at)r=s;else{i=s;break}}return((o=t[i])==null?void 0:o.id)!==e.id?[...t.slice(0,i),e,...t.slice(i)]:t}var MessageNode=class{constructor(t){N(this,"_value");N(this,"_next");this._value=t,this._next=null}get value(){return this._value}set value(t){this._value=t}get next(){return this._next}set next(t){this._next=t}},MessageQueue=class{constructor(){N(this,"_first");N(this,"_last");N(this,"_size");this._first=null,this._last=null,this._size=0}get first(){return this._first}set first(t){this._first=t}get last(){return this._last}set last(t){this._last=t}get size(){return this._size}set size(t){this._size=t}enqueue(t){const e=new MessageNode(t);return this._size===0||!this._last?(this._first=e,this._last=e):(this._last.next=e,this._last=e),this._size++,!0}dequeue(){if(this._size===0||!this._first)return null;let t=this._first;return this._first=t.next,t.next=null,this._size--,t.value}},verifiedSymbol=Symbol("verified");function getBlankEvent(t=255){return{kind:t,content:"",tags:[],created_at:0}}function finishEvent(t,e){const n=t;return n.pubkey=getPublicKey(e),n.id=getEventHash$1(n),n.sig=getSignature(n,e),n[verifiedSymbol]=!0,n}function serializeEvent(t){if(!validateEvent(t))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}function getEventHash$1(t){let e=sha256$4(utf8Encoder.encode(serializeEvent(t)));return bytesToHex$5(e)}var isRecord=t=>t instanceof Object;function validateEvent(t){if(!isRecord(t)||typeof t.kind!="number"||typeof t.content!="string"||typeof t.created_at!="number"||typeof t.pubkey!="string"||!t.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(t.tags))return!1;for(let e=0;e<t.tags.length;e++){let n=t.tags[e];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]=="object")return!1}return!0}function verifySignature$1(t){if(typeof t[verifiedSymbol]=="boolean")return t[verifiedSymbol];const e=getEventHash$1(t);if(e!==t.id)return t[verifiedSymbol]=!1;try{return t[verifiedSymbol]=schnorr$1.verify(t.sig,e,t.pubkey)}catch{return t[verifiedSymbol]=!1}}function getSignature(t,e){return bytesToHex$5(schnorr$1.sign(getEventHash$1(t),e))}function matchFilter(t,e){if(t.ids&&t.ids.indexOf(e.id)===-1&&!t.ids.some(n=>e.id.startsWith(n))||t.kinds&&t.kinds.indexOf(e.kind)===-1||t.authors&&t.authors.indexOf(e.pubkey)===-1&&!t.authors.some(n=>e.pubkey.startsWith(n)))return!1;for(let n in t)if(n[0]==="#"){let r=n.slice(1),s=t[`#${r}`];if(s&&!e.tags.find(([i,o])=>i===n.slice(1)&&s.indexOf(o)!==-1))return!1}return!(t.since&&e.created_at<t.since||t.until&&e.created_at>t.until)}function matchFilters(t,e){for(let n=0;n<t.length;n++)if(matchFilter(t[n],e))return!0;return!1}var fakejson_exports={};__export(fakejson_exports,{getHex64:()=>getHex64,getInt:()=>getInt,getSubscriptionId:()=>getSubscriptionId,matchEventId:()=>matchEventId,matchEventKind:()=>matchEventKind,matchEventPubkey:()=>matchEventPubkey});function getHex64(t,e){let n=e.length+3,r=t.indexOf(`"${e}":`)+n,s=t.slice(r).indexOf('"')+r+1;return t.slice(s,s+64)}function getInt(t,e){let n=e.length,r=t.indexOf(`"${e}":`)+n+3,s=t.slice(r),i=Math.min(s.indexOf(","),s.indexOf("}"));return parseInt(s.slice(0,i),10)}function getSubscriptionId(t){let e=t.slice(0,22).indexOf('"EVENT"');if(e===-1)return null;let n=t.slice(e+7+1).indexOf('"');if(n===-1)return null;let r=e+7+1+n,s=t.slice(r+1,80).indexOf('"');if(s===-1)return null;let i=r+1+s;return t.slice(r+1,i)}function matchEventId(t,e){return e===getHex64(t,"id")}function matchEventPubkey(t,e){return e===getHex64(t,"pubkey")}function matchEventKind(t,e){return e===getInt(t,"kind")}var newListeners=()=>({connect:[],disconnect:[],error:[],notice:[],auth:[]});function relayInit(t,e={}){let{listTimeout:n=3e3,getTimeout:r=3e3,countTimeout:s=3e3}=e;var i,o={},a=newListeners(),c={},l={},h;async function u(){return h||(h=new Promise(($,_)=>{try{i=new WebSocket(t)}catch(v){_(v)}i.onopen=()=>{a.connect.forEach(v=>v()),$()},i.onerror=()=>{h=void 0,a.error.forEach(v=>v()),_()},i.onclose=async()=>{h=void 0,a.disconnect.forEach(v=>v())};let x=new MessageQueue,I;i.onmessage=v=>{x.enqueue(v.data),I||(I=setInterval(R,0))};function R(){var S,H,L;if(x.size===0){clearInterval(I),I=null;return}var v=x.dequeue();if(!v)return;let B=getSubscriptionId(v);if(B){let E=o[B];if(E&&E.alreadyHaveEvent&&E.alreadyHaveEvent(getHex64(v,"id"),t))return}try{let E=JSON.parse(v);switch(E[0]){case"EVENT":{let y=E[1],b=E[2];validateEvent(b)&&o[y]&&(o[y].skipVerification||verifySignature$1(b))&&matchFilters(o[y].filters,b)&&(o[y],(((S=c[y])==null?void 0:S.event)||[]).forEach(A=>A(b)));return}case"COUNT":let k=E[1],T=E[2];o[k]&&(((H=c[k])==null?void 0:H.count)||[]).forEach(y=>y(T));return;case"EOSE":{let y=E[1];y in c&&(c[y].eose.forEach(b=>b()),c[y].eose=[]);return}case"OK":{let y=E[1],b=E[2],A=E[3]||"";if(y in l){let{resolve:U,reject:C}=l[y];b?U(null):C(new Error(A))}return}case"NOTICE":let P=E[1];a.notice.forEach(y=>y(P));return;case"AUTH":{let y=E[1];(L=a.auth)==null||L.forEach(b=>b(y));return}}}catch{return}}}),h)}function p(){return(i==null?void 0:i.readyState)===1}async function g(){p()||await u()}async function m($){let _=JSON.stringify($);if(!(!p()&&(await new Promise(x=>setTimeout(x,1e3)),!p())))try{i.send(_)}catch(x){console.log(x)}}const d=($,{verb:_="REQ",skipVerification:x=!1,alreadyHaveEvent:I=null,id:R=Math.random().toString().slice(2)}={})=>{let v=R;o[v]={id:v,filters:$,skipVerification:x,alreadyHaveEvent:I},m([_,v,...$]);let B={sub:(S,H={})=>d(S||$,{skipVerification:H.skipVerification||x,alreadyHaveEvent:H.alreadyHaveEvent||I,id:v}),unsub:()=>{delete o[v],delete c[v],m(["CLOSE",v])},on:(S,H)=>{c[v]=c[v]||{event:[],count:[],eose:[]},c[v][S].push(H)},off:(S,H)=>{let L=c[v],E=L[S].indexOf(H);E>=0&&L[S].splice(E,1)},get events(){return eventsGenerator(B)}};return B};function w($,_){return new Promise((x,I)=>{if(!$.id){I(new Error(`event ${$} has no id`));return}let R=$.id;m([_,$]),l[R]={resolve:x,reject:I}})}return{url:t,sub:d,on:($,_)=>{a[$].push(_),$==="connect"&&(i==null?void 0:i.readyState)===1&&_()},off:($,_)=>{let x=a[$].indexOf(_);x!==-1&&a[$].splice(x,1)},list:($,_)=>new Promise(x=>{let I=d($,_),R=[],v=setTimeout(()=>{I.unsub(),x(R)},n);I.on("eose",()=>{I.unsub(),clearTimeout(v),x(R)}),I.on("event",B=>{R.push(B)})}),get:($,_)=>new Promise(x=>{let I=d([$],_),R=setTimeout(()=>{I.unsub(),x(null)},r);I.on("event",v=>{I.unsub(),clearTimeout(R),x(v)})}),count:$=>new Promise(_=>{let x=d($,{...d,verb:"COUNT"}),I=setTimeout(()=>{x.unsub(),_(null)},s);x.on("count",R=>{x.unsub(),clearTimeout(I),_(R)})}),async publish($){await w($,"EVENT")},async auth($){await w($,"AUTH")},connect:g,close(){a=newListeners(),c={},l={},(i==null?void 0:i.readyState)===WebSocket.OPEN&&i.close()},get status(){return(i==null?void 0:i.readyState)??3}}}async function*eventsGenerator(t){let e;const n=[],r=s=>{e?(e(s),e=void 0):n.push(s)};t.on("event",r);try{for(;;)n.length>0?yield n.shift():yield await new Promise(i=>{e=i})}finally{t.off("event",r)}}var nip19_exports={};__export(nip19_exports,{BECH32_REGEX:()=>BECH32_REGEX$1,decode:()=>decode,naddrEncode:()=>naddrEncode,neventEncode:()=>neventEncode,noteEncode:()=>noteEncode,nprofileEncode:()=>nprofileEncode,npubEncode:()=>npubEncode,nrelayEncode:()=>nrelayEncode,nsecEncode:()=>nsecEncode});var Bech32MaxSize=5e3,BECH32_REGEX$1=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function integerToUint8Array(t){const e=new Uint8Array(4);return e[0]=t>>24&255,e[1]=t>>16&255,e[2]=t>>8&255,e[3]=t&255,e}function decode(t){var s,i,o,a,c,l,h,u;let{prefix:e,words:n}=bech32$1.decode(t,Bech32MaxSize),r=new Uint8Array(bech32$1.fromWords(n));switch(e){case"nprofile":{let p=parseTLV(r);if(!((s=p[0])!=null&&s[0]))throw new Error("missing TLV 0 for nprofile");if(p[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:bytesToHex$5(p[0][0]),relays:p[1]?p[1].map(g=>utf8Decoder.decode(g)):[]}}}case"nevent":{let p=parseTLV(r);if(!((i=p[0])!=null&&i[0]))throw new Error("missing TLV 0 for nevent");if(p[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(p[2]&&p[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(p[3]&&p[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:bytesToHex$5(p[0][0]),relays:p[1]?p[1].map(g=>utf8Decoder.decode(g)):[],author:(o=p[2])!=null&&o[0]?bytesToHex$5(p[2][0]):void 0,kind:(a=p[3])!=null&&a[0]?parseInt(bytesToHex$5(p[3][0]),16):void 0}}}case"naddr":{let p=parseTLV(r);if(!((c=p[0])!=null&&c[0]))throw new Error("missing TLV 0 for naddr");if(!((l=p[2])!=null&&l[0]))throw new Error("missing TLV 2 for naddr");if(p[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((h=p[3])!=null&&h[0]))throw new Error("missing TLV 3 for naddr");if(p[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:utf8Decoder.decode(p[0][0]),pubkey:bytesToHex$5(p[2][0]),kind:parseInt(bytesToHex$5(p[3][0]),16),relays:p[1]?p[1].map(g=>utf8Decoder.decode(g)):[]}}}case"nrelay":{let p=parseTLV(r);if(!((u=p[0])!=null&&u[0]))throw new Error("missing TLV 0 for nrelay");return{type:"nrelay",data:utf8Decoder.decode(p[0][0])}}case"nsec":case"npub":case"note":return{type:e,data:bytesToHex$5(r)};default:throw new Error(`unknown prefix ${e}`)}}function parseTLV(t){let e={},n=t;for(;n.length>0;){let r=n[0],s=n[1];if(!s)throw new Error(`malformed TLV ${r}`);let i=n.slice(2,2+s);if(n=n.slice(2+s),i.length<s)throw new Error(`not enough data to read on TLV ${r}`);e[r]=e[r]||[],e[r].push(i)}return e}function nsecEncode(t){return encodeBytes("nsec",t)}function npubEncode(t){return encodeBytes("npub",t)}function noteEncode(t){return encodeBytes("note",t)}function encodeBech32(t,e){let n=bech32$1.toWords(e);return bech32$1.encode(t,n,Bech32MaxSize)}function encodeBytes(t,e){let n=hexToBytes$4(e);return encodeBech32(t,n)}function nprofileEncode(t){let e=encodeTLV({0:[hexToBytes$4(t.pubkey)],1:(t.relays||[]).map(n=>utf8Encoder.encode(n))});return encodeBech32("nprofile",e)}function neventEncode(t){let e;t.kind!=null&&(e=integerToUint8Array(t.kind));let n=encodeTLV({0:[hexToBytes$4(t.id)],1:(t.relays||[]).map(r=>utf8Encoder.encode(r)),2:t.author?[hexToBytes$4(t.author)]:[],3:e?[new Uint8Array(e)]:[]});return encodeBech32("nevent",n)}function naddrEncode(t){let e=new ArrayBuffer(4);new DataView(e).setUint32(0,t.kind,!1);let n=encodeTLV({0:[utf8Encoder.encode(t.identifier)],1:(t.relays||[]).map(r=>utf8Encoder.encode(r)),2:[hexToBytes$4(t.pubkey)],3:[new Uint8Array(e)]});return encodeBech32("naddr",n)}function nrelayEncode(t){let e=encodeTLV({0:[utf8Encoder.encode(t)]});return encodeBech32("nrelay",e)}function encodeTLV(t){let e=[];return Object.entries(t).forEach(([n,r])=>{r.forEach(s=>{let i=new Uint8Array(s.length+2);i.set([parseInt(n)],0),i.set([s.length],1),i.set(s,2),e.push(i)})}),concatBytes$6(...e)}var nip04_exports={};__export(nip04_exports,{decrypt:()=>decrypt$1,encrypt:()=>encrypt$1});typeof crypto<"u"&&!crypto.subtle&&crypto.webcrypto&&(crypto.subtle=crypto.webcrypto.subtle);async function encrypt$1(t,e,n){const r=secp256k1$2.getSharedSecret(t,"02"+e),s=getNormalizedX(r);let i=Uint8Array.from(randomBytes$3(16)),o=utf8Encoder.encode(n),a=await crypto.subtle.importKey("raw",s,{name:"AES-CBC"},!1,["encrypt"]),c=await crypto.subtle.encrypt({name:"AES-CBC",iv:i},a,o),l=base64.encode(new Uint8Array(c)),h=base64.encode(new Uint8Array(i.buffer));return`${l}?iv=${h}`}async function decrypt$1(t,e,n){let[r,s]=n.split("?iv="),i=secp256k1$2.getSharedSecret(t,"02"+e),o=getNormalizedX(i),a=await crypto.subtle.importKey("raw",o,{name:"AES-CBC"},!1,["decrypt"]),c=base64.decode(r),l=base64.decode(s),h=await crypto.subtle.decrypt({name:"AES-CBC",iv:l},a,c);return utf8Decoder.decode(h)}function getNormalizedX(t){return t.slice(1,33)}var nip05_exports={};__export(nip05_exports,{NIP05_REGEX:()=>NIP05_REGEX$1,queryProfile:()=>queryProfile,searchDomain:()=>searchDomain,useFetchImplementation:()=>useFetchImplementation});var NIP05_REGEX$1=/^(?:([\w.+-]+)@)?([\w.-]+)$/,_fetch;try{_fetch=fetch}catch{}function useFetchImplementation(t){_fetch=t}async function searchDomain(t,e=""){try{return(await(await _fetch(`https://${t}/.well-known/nostr.json?name=${e}`)).json()).names}catch{return{}}}async function queryProfile(t){const e=t.match(NIP05_REGEX$1);if(!e)return null;const[n,r="_",s]=e;try{const i=await _fetch(`https://${s}/.well-known/nostr.json?name=${r}`),{names:o,relays:a}=parseNIP05Result$1(await i.json()),c=o[r];return c?{pubkey:c,relays:a==null?void 0:a[c]}:null}catch{return null}}function parseNIP05Result$1(t){const e={names:{}};for(const[n,r]of Object.entries(t.names))typeof n=="string"&&typeof r=="string"&&(e.names[n]=r);if(t.relays){e.relays={};for(const[n,r]of Object.entries(t.relays))typeof n=="string"&&Array.isArray(r)&&(e.relays[n]=r.filter(s=>typeof s=="string"))}return e}var nip06_exports={};__export(nip06_exports,{generateSeedWords:()=>generateSeedWords,privateKeyFromSeedWords:()=>privateKeyFromSeedWords,validateWords:()=>validateWords});function privateKeyFromSeedWords(t,e){let r=HDKey.fromMasterSeed(mnemonicToSeedSync(t,e)).derive("m/44'/1237'/0'/0/0").privateKey;if(!r)throw new Error("could not derive private key");return bytesToHex$5(r)}function generateSeedWords(){return generateMnemonic(wordlist)}function validateWords(t){return validateMnemonic(t,wordlist)}var nip10_exports={};__export(nip10_exports,{parse:()=>parse});function parse(t){const e={reply:void 0,root:void 0,mentions:[],profiles:[]},n=[];for(const r of t.tags)r[0]==="e"&&r[1]&&n.push(r),r[0]==="p"&&r[1]&&e.profiles.push({pubkey:r[1],relays:r[2]?[r[2]]:[]});for(let r=0;r<n.length;r++){const s=n[r],[i,o,a,c]=s,l={id:o,relays:a?[a]:[]},h=r===0,u=r===n.length-1;if(c==="root"){e.root=l;continue}if(c==="reply"){e.reply=l;continue}if(c==="mention"){e.mentions.push(l);continue}if(h){e.root=l;continue}if(u){e.reply=l;continue}e.mentions.push(l)}return e}var nip13_exports={};__export(nip13_exports,{getPow:()=>getPow,minePow:()=>minePow});function getPow(t){let e=0;for(let n=0;n<t.length;n++){const r=parseInt(t[n],16);if(r===0)e+=4;else{e+=Math.clz32(r)-28;break}}return e}function minePow(t,e){let n=0;const r=t,s=["nonce",n.toString(),e.toString()];for(r.tags.push(s);;){const i=Math.floor(new Date().getTime()/1e3);if(i!==r.created_at&&(n=0,r.created_at=i),s[1]=(++n).toString(),r.id=getEventHash$1(r),getPow(r.id)>=e)break}return r}var nip18_exports={};__export(nip18_exports,{finishRepostEvent:()=>finishRepostEvent,getRepostedEvent:()=>getRepostedEvent,getRepostedEventPointer:()=>getRepostedEventPointer});function finishRepostEvent(t,e,n,r){return finishEvent({kind:6,tags:[...t.tags??[],["e",e.id,n],["p",e.pubkey]],content:t.content===""?"":JSON.stringify(e),created_at:t.created_at},r)}function getRepostedEventPointer(t){if(t.kind!==6)return;let e,n;for(let r=t.tags.length-1;r>=0&&(e===void 0||n===void 0);r--){const s=t.tags[r];s.length>=2&&(s[0]==="e"&&e===void 0?e=s:s[0]==="p"&&n===void 0&&(n=s))}if(e!==void 0)return{id:e[1],relays:[e[2],n==null?void 0:n[2]].filter(r=>typeof r=="string"),author:n==null?void 0:n[1]}}function getRepostedEvent(t,{skipVerification:e}={}){const n=getRepostedEventPointer(t);if(n===void 0||t.content==="")return;let r;try{r=JSON.parse(t.content)}catch{return}if(r.id===n.id&&!(!e&&!verifySignature$1(r)))return r}var nip21_exports={};__export(nip21_exports,{NOSTR_URI_REGEX:()=>NOSTR_URI_REGEX,parse:()=>parse2,test:()=>test});var NOSTR_URI_REGEX=new RegExp(`nostr:(${BECH32_REGEX$1.source})`);function test(t){return typeof t=="string"&&new RegExp(`^${NOSTR_URI_REGEX.source}$`).test(t)}function parse2(t){const e=t.match(new RegExp(`^${NOSTR_URI_REGEX.source}$`));if(!e)throw new Error(`Invalid Nostr URI: ${t}`);return{uri:e[0],value:e[1],decoded:decode(e[1])}}var nip25_exports={};__export(nip25_exports,{finishReactionEvent:()=>finishReactionEvent,getReactedEventPointer:()=>getReactedEventPointer});function finishReactionEvent(t,e,n){const r=e.tags.filter(s=>s.length>=2&&(s[0]==="e"||s[0]==="p"));return finishEvent({...t,kind:7,tags:[...t.tags??[],...r,["e",e.id],["p",e.pubkey]],content:t.content??"+"},n)}function getReactedEventPointer(t){if(t.kind!==7)return;let e,n;for(let r=t.tags.length-1;r>=0&&(e===void 0||n===void 0);r--){const s=t.tags[r];s.length>=2&&(s[0]==="e"&&e===void 0?e=s:s[0]==="p"&&n===void 0&&(n=s))}if(!(e===void 0||n===void 0))return{id:e[1],relays:[e[2],n[2]].filter(r=>r!==void 0),author:n[1]}}var nip26_exports={};__export(nip26_exports,{createDelegation:()=>createDelegation,getDelegator:()=>getDelegator});function createDelegation(t,e){let n=[];(e.kind||-1)>=0&&n.push(`kind=${e.kind}`),e.until&&n.push(`created_at<${e.until}`),e.since&&n.push(`created_at>${e.since}`);let r=n.join("&");if(r==="")throw new Error("refusing to create a delegation without any conditions");let s=sha256$4(utf8Encoder.encode(`nostr:delegation:${e.pubkey}:${r}`)),i=bytesToHex$5(schnorr$1.sign(s,t));return{from:getPublicKey(t),to:e.pubkey,cond:r,sig:i}}function getDelegator(t){let e=t.tags.find(a=>a[0]==="delegation"&&a.length>=4);if(!e)return null;let n=e[1],r=e[2],s=e[3],i=r.split("&");for(let a=0;a<i.length;a++){let[c,l,h]=i[a].split(/\b/);if(!(c==="kind"&&l==="="&&t.kind===parseInt(h))){if(c==="created_at"&&l==="<"&&t.created_at<parseInt(h))continue;if(c==="created_at"&&l===">"&&t.created_at>parseInt(h))continue;return null}}let o=sha256$4(utf8Encoder.encode(`nostr:delegation:${t.pubkey}:${r}`));return schnorr$1.verify(s,o,n)?n:null}var nip27_exports={};__export(nip27_exports,{matchAll:()=>matchAll,regex:()=>regex,replaceAll:()=>replaceAll});var regex=()=>new RegExp(`\\b${NOSTR_URI_REGEX.source}\\b`,"g");function*matchAll(t){const e=t.matchAll(regex());for(const n of e)try{const[r,s]=n;yield{uri:r,value:s,decoded:decode(s),start:n.index,end:n.index+r.length}}catch{}}function replaceAll(t,e){return t.replaceAll(regex(),(n,r)=>e({uri:n,value:r,decoded:decode(r)}))}var nip28_exports={};__export(nip28_exports,{channelCreateEvent:()=>channelCreateEvent,channelHideMessageEvent:()=>channelHideMessageEvent,channelMessageEvent:()=>channelMessageEvent,channelMetadataEvent:()=>channelMetadataEvent,channelMuteUserEvent:()=>channelMuteUserEvent});var channelCreateEvent=(t,e)=>{let n;if(typeof t.content=="object")n=JSON.stringify(t.content);else if(typeof t.content=="string")n=t.content;else return;return finishEvent({kind:40,tags:[...t.tags??[]],content:n,created_at:t.created_at},e)},channelMetadataEvent=(t,e)=>{let n;if(typeof t.content=="object")n=JSON.stringify(t.content);else if(typeof t.content=="string")n=t.content;else return;return finishEvent({kind:41,tags:[["e",t.channel_create_event_id],...t.tags??[]],content:n,created_at:t.created_at},e)},channelMessageEvent=(t,e)=>{const n=[["e",t.channel_create_event_id,t.relay_url,"root"]];return t.reply_to_channel_message_event_id&&n.push(["e",t.reply_to_channel_message_event_id,t.relay_url,"reply"]),finishEvent({kind:42,tags:[...n,...t.tags??[]],content:t.content,created_at:t.created_at},e)},channelHideMessageEvent=(t,e)=>{let n;if(typeof t.content=="object")n=JSON.stringify(t.content);else if(typeof t.content=="string")n=t.content;else return;return finishEvent({kind:43,tags:[["e",t.channel_message_event_id],...t.tags??[]],content:n,created_at:t.created_at},e)},channelMuteUserEvent=(t,e)=>{let n;if(typeof t.content=="object")n=JSON.stringify(t.content);else if(typeof t.content=="string")n=t.content;else return;return finishEvent({kind:44,tags:[["p",t.pubkey_to_mute],...t.tags??[]],content:n,created_at:t.created_at},e)},nip39_exports={};__export(nip39_exports,{useFetchImplementation:()=>useFetchImplementation2,validateGithub:()=>validateGithub});var _fetch2;try{_fetch2=fetch}catch{}function useFetchImplementation2(t){_fetch2=t}async function validateGithub(t,e,n){try{return await(await _fetch2(`https://gist.github.com/${e}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${t}`}catch{return!1}}var nip42_exports={};__export(nip42_exports,{authenticate:()=>authenticate});var authenticate=async({challenge:t,relay:e,sign:n})=>{const r={kind:22242,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e.url],["challenge",t]],content:""};return e.auth(await n(r))},nip44_exports={};__export(nip44_exports,{decrypt:()=>decrypt2,encrypt:()=>encrypt2,utils:()=>utils$1});var utils$1={v2:{maxPlaintextSize:65408,minCiphertextSize:100,maxCiphertextSize:102400,getConversationKey(t,e){return secp256k1$2.getSharedSecret(t,"02"+e).subarray(1,33)},getMessageKeys(t,e){const n=hkdf(sha256$4,t,e,"nip44-v2",76);return{encryption:n.subarray(0,32),nonce:n.subarray(32,44),auth:n.subarray(44,76)}},calcPadding(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("expected positive integer");if(t<=32)return 32;const e=1<<Math.floor(Math.log2(t-1))+1,n=e<=256?32:e/8;return n*(Math.floor((t-1)/n)+1)},pad(t){const e=utf8Encoder.encode(t),n=e.length;if(n<1||n>=utils$1.v2.maxPlaintextSize)throw new Error("invalid plaintext length: must be between 1b and 64KB");const r=utils$1.v2.calcPadding(n),s=new Uint8Array(r-n),i=new Uint8Array(2);return new DataView(i.buffer).setUint16(0,n),concatBytes$6(i,e,s)},unpad(t){const e=new DataView(t.buffer).getUint16(0),n=t.subarray(2,2+e);if(e===0||n.length!==e||t.length!==2+utils$1.v2.calcPadding(e))throw new Error("invalid padding");return utf8Decoder.decode(n)}}};function encrypt2(t,e,n={}){const r=n.version??2;if(r!==2)throw new Error("unknown encryption version "+r);const s=n.salt??randomBytes$3(32);ensureBytes$1(s,32);const i=utils$1.v2.getMessageKeys(t,s),o=utils$1.v2.pad(e),a=chacha20(i.encryption,i.nonce,o),c=hmac$4(sha256$4,i.auth,a);return base64.encode(concatBytes$6(new Uint8Array([r]),s,a,c))}function decrypt2(t,e){const n=utils$1.v2;ensureBytes$1(t,32);const r=e.length;if(r<n.minCiphertextSize||r>=n.maxCiphertextSize)throw new Error("invalid ciphertext length: "+r);if(e[0]==="#")throw new Error("unknown encryption version");let s;try{s=base64.decode(e)}catch(p){throw new Error("invalid base64: "+p.message)}const i=s.subarray(0,1)[0];if(i!==2)throw new Error("unknown encryption version "+i);const o=s.subarray(1,33),a=s.subarray(33,-32),c=s.subarray(-32),l=n.getMessageKeys(t,o),h=hmac$4(sha256$4,l.auth,a);if(!equalBytes$1(h,c))throw new Error("invalid MAC");const u=chacha20(l.encryption,l.nonce,a);return n.unpad(u)}var nip47_exports={};__export(nip47_exports,{makeNwcRequestEvent:()=>makeNwcRequestEvent,parseConnectionString:()=>parseConnectionString});function parseConnectionString(t){const{pathname:e,searchParams:n}=new URL(t),r=e,s=n.get("relay"),i=n.get("secret");if(!r||!s||!i)throw new Error("invalid connection string");return{pubkey:r,relay:s,secret:i}}async function makeNwcRequestEvent({pubkey:t,secret:e,invoice:n}){const s=await encrypt$1(e,t,JSON.stringify({method:"pay_invoice",params:{invoice:n}})),i={kind:23194,created_at:Math.round(Date.now()/1e3),content:s,tags:[["p",t]]};return finishEvent(i,e)}var nip57_exports={};__export(nip57_exports,{getZapEndpoint:()=>getZapEndpoint,makeZapReceipt:()=>makeZapReceipt,makeZapRequest:()=>makeZapRequest,useFetchImplementation:()=>useFetchImplementation3,validateZapRequest:()=>validateZapRequest});var _fetch3;try{_fetch3=fetch}catch{}function useFetchImplementation3(t){_fetch3=t}async function getZapEndpoint(t){try{let e="",{lud06:n,lud16:r}=JSON.parse(t.content);if(n){let{words:o}=bech32$1.decode(n,1e3),a=bech32$1.fromWords(o);e=utf8Decoder.decode(a)}else if(r){let[o,a]=r.split("@");e=`https://${a}/.well-known/lnurlp/${o}`}else return null;let i=await(await _fetch3(e)).json();if(i.allowsNostr&&i.nostrPubkey)return i.callback}catch{}return null}function makeZapRequest({profile:t,event:e,amount:n,relays:r,comment:s=""}){if(!n)throw new Error("amount not given");if(!t)throw new Error("profile not given");let i={kind:9734,created_at:Math.round(Date.now()/1e3),content:s,tags:[["p",t],["amount",n.toString()],["relays",...r]]};return e&&i.tags.push(["e",e]),i}function validateZapRequest(t){let e;try{e=JSON.parse(t)}catch{return"Invalid zap request JSON."}if(!validateEvent(e))return"Zap request is not a valid Nostr event.";if(!verifySignature$1(e))return"Invalid signature on zap request.";let n=e.tags.find(([i,o])=>i==="p"&&o);if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=e.tags.find(([i,o])=>i==="e"&&o);return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":e.tags.find(([i,o])=>i==="relays"&&o)?null:"Zap request doesn't have a 'relays' tag."}function makeZapReceipt({zapRequest:t,preimage:e,bolt11:n,paidAt:r}){let i=JSON.parse(t).tags.filter(([a])=>a==="e"||a==="p"||a==="a"),o={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...i,["bolt11",n],["description",t]]};return e&&o.tags.push(["preimage",e]),o}var nip98_exports={};__export(nip98_exports,{getToken:()=>getToken,unpackEventFromToken:()=>unpackEventFromToken,validateEvent:()=>validateEvent2,validateToken:()=>validateToken});var _authorizationScheme="Nostr ";async function getToken(t,e,n,r=!1){if(!t||!e)throw new Error("Missing loginUrl or httpMethod");const s=getBlankEvent(27235);s.tags=[["u",t],["method",e]],s.created_at=Math.round(new Date().getTime()/1e3);const i=await n(s);return(r?_authorizationScheme:"")+base64.encode(utf8Encoder.encode(JSON.stringify(i)))}async function validateToken(t,e,n){const r=await unpackEventFromToken(t).catch(i=>{throw i});return await validateEvent2(r,e,n).catch(i=>{throw i})}async function unpackEventFromToken(t){if(!t)throw new Error("Missing token");t=t.replace(_authorizationScheme,"");const e=utf8Decoder.decode(base64.decode(t));if(!e||e.length===0||!e.startsWith("{"))throw new Error("Invalid token");return JSON.parse(e)}async function validateEvent2(t,e,n){if(!t)throw new Error("Invalid nostr event");if(!verifySignature$1(t))throw new Error("Invalid nostr event, signature invalid");if(t.kind!==27235)throw new Error("Invalid nostr event, kind invalid");if(!t.created_at)throw new Error("Invalid nostr event, created_at invalid");if(Math.round(new Date().getTime()/1e3)-t.created_at>60)throw new Error("Invalid nostr event, expired");const r=t.tags.find(i=>i[0]==="u");if((r==null?void 0:r.length)!==1&&(r==null?void 0:r[1])!==e)throw new Error("Invalid nostr event, url tag invalid");const s=t.tags.find(i=>i[0]==="method");if((s==null?void 0:s.length)!==1&&(s==null?void 0:s[1].toLowerCase())!==n.toLowerCase())throw new Error("Invalid nostr event, method tag invalid");return!0}var commonjsGlobal=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function getDefaultExportFromCjs(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var lib$1={},types={};Object.defineProperty(types,"__esModule",{value:!0});var ee={},taskCollection$1={},taskCollection={},bakeCollection={};(function(exports){Object.defineProperty(exports,"__esModule",{value:!0}),exports.bakeCollectionVariadic=exports.bakeCollectionAwait=exports.bakeCollection=exports.BAKED_EMPTY_FUNC=void 0,exports.BAKED_EMPTY_FUNC=function(){};var FORLOOP_FALLBACK=1500;function generateArgsDefCode(t){var e="";if(t===0)return e;for(var n=0;n<t-1;++n)e+="arg"+String(n)+", ";return e+="arg"+String(t-1),e}function generateBodyPartsCode(t,e){for(var n="",r="",s=0;s<e;++s)n+="var f".concat(s," = collection[").concat(s,`];
`),r+="f".concat(s,"(").concat(t,`)
`);return{funcDefCode:n,funcCallCode:r}}function generateBodyPartsVariadicCode(t){for(var e="",n="",r=0;r<t;++r)e+="var f".concat(r," = collection[").concat(r,`];
`),n+="f".concat(r,`.apply(undefined, arguments)
`);return{funcDefCode:e,funcCallCode:n}}function bakeCollection(collection,fixedArgsNum){if(collection.length===0)return exports.BAKED_EMPTY_FUNC;if(collection.length===1)return collection[0];var funcFactoryCode;if(collection.length<FORLOOP_FALLBACK){var argsDefCode=generateArgsDefCode(fixedArgsNum),_a=generateBodyPartsCode(argsDefCode,collection.length),funcDefCode=_a.funcDefCode,funcCallCode=_a.funcCallCode;funcFactoryCode=`(function(collection) {
`.concat(funcDefCode,`
collection = undefined;
return (function(`).concat(argsDefCode,`) {
`).concat(funcCallCode,`
});
})`)}else{var argsDefCode=generateArgsDefCode(fixedArgsNum);collection.length%10===0?funcFactoryCode=`(function(collection) {
return (function(`.concat(argsDefCode,`) {
for (var i = 0; i < collection.length; i += 10) {
collection[i](`).concat(argsDefCode,`);
collection[i+1](`).concat(argsDefCode,`);
collection[i+2](`).concat(argsDefCode,`);
collection[i+3](`).concat(argsDefCode,`);
collection[i+4](`).concat(argsDefCode,`);
collection[i+5](`).concat(argsDefCode,`);
collection[i+6](`).concat(argsDefCode,`);
collection[i+7](`).concat(argsDefCode,`);
collection[i+8](`).concat(argsDefCode,`);
collection[i+9](`).concat(argsDefCode,`);
}
});
})`):collection.length%4===0?funcFactoryCode=`(function(collection) {
return (function(`.concat(argsDefCode,`) {
for (var i = 0; i < collection.length; i += 4) {
collection[i](`).concat(argsDefCode,`);
collection[i+1](`).concat(argsDefCode,`);
collection[i+2](`).concat(argsDefCode,`);
collection[i+3](`).concat(argsDefCode,`);
}
});
})`):collection.length%3===0?funcFactoryCode=`(function(collection) {
return (function(`.concat(argsDefCode,`) {
for (var i = 0; i < collection.length; i += 3) {
collection[i](`).concat(argsDefCode,`);
collection[i+1](`).concat(argsDefCode,`);
collection[i+2](`).concat(argsDefCode,`);
}
});
})`):funcFactoryCode=`(function(collection) {
return (function(`.concat(argsDefCode,`) {
for (var i = 0; i < collection.length; ++i) {
collection[i](`).concat(argsDefCode,`);
}
});
})`)}{var funcFactory=eval(funcFactoryCode);return funcFactory(collection)}}exports.bakeCollection=bakeCollection;function bakeCollectionAwait(collection,fixedArgsNum){if(collection.length===0)return exports.BAKED_EMPTY_FUNC;if(collection.length===1)return collection[0];var funcFactoryCode;if(collection.length<FORLOOP_FALLBACK){var argsDefCode=generateArgsDefCode(fixedArgsNum),_a=generateBodyPartsCode(argsDefCode,collection.length),funcDefCode=_a.funcDefCode,funcCallCode=_a.funcCallCode;funcFactoryCode=`(function(collection) {
`.concat(funcDefCode,`
collection = undefined;
return (function(`).concat(argsDefCode,`) {
return Promise.all([ `).concat(funcCallCode,` ]);
});
})`)}else{var argsDefCode=generateArgsDefCode(fixedArgsNum);funcFactoryCode=`(function(collection) {
return (function(`.concat(argsDefCode,`) {
var promises = Array(collection.length);
for (var i = 0; i < collection.length; ++i) {
promises[i] = collection[i](`).concat(argsDefCode,`);
}
return Promise.all(promises);
});
})`)}{var funcFactory=eval(funcFactoryCode);return funcFactory(collection)}}exports.bakeCollectionAwait=bakeCollectionAwait;function bakeCollectionVariadic(collection){if(collection.length===0)return exports.BAKED_EMPTY_FUNC;if(collection.length===1)return collection[0];var funcFactoryCode;if(collection.length<FORLOOP_FALLBACK){var _a=generateBodyPartsVariadicCode(collection.length),funcDefCode=_a.funcDefCode,funcCallCode=_a.funcCallCode;funcFactoryCode=`(function(collection) {
`.concat(funcDefCode,`
collection = undefined;
return (function() {
`).concat(funcCallCode,`
});
})`)}else funcFactoryCode=`(function(collection) {
return (function() {
for (var i = 0; i < collection.length; ++i) {
collection[i].apply(undefined, arguments);
}
});
})`;{var funcFactory=eval(funcFactoryCode);return funcFactory(collection)}}exports.bakeCollectionVariadic=bakeCollectionVariadic})(bakeCollection);var __spreadArray$1=commonjsGlobal&&commonjsGlobal.__spreadArray||function(t,e,n){if(n||arguments.length===2)for(var r=0,s=e.length,i;r<s;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))};Object.defineProperty(taskCollection,"__esModule",{value:!0});taskCollection.TaskCollection=taskCollection._fast_remove_single=void 0;var bake_collection_1=bakeCollection;function push_norebuild(t,e){var n=this.length;if(n>1)if(e){var r;(r=this._tasks).push.apply(r,arguments),this.length+=arguments.length}else this._tasks.push(t),this.length++;else if(e){if(n===1){var s=Array(1+arguments.length);s.push(s),s.push.apply(s,arguments),this._tasks=s}else{var s=Array(arguments.length);s.push.apply(s,arguments),this._tasks=s}this.length+=arguments.length}else n===1?this._tasks=[this._tasks,t]:this._tasks=t,this.length++}function push_rebuild(t,e){var n=this.length;if(n>1)if(e){var r;(r=this._tasks).push.apply(r,arguments),this.length+=arguments.length}else this._tasks.push(t),this.length++;else if(e){if(n===1){var s=Array(1+arguments.length);s.push(s),s.push.apply(s,arguments),this._tasks=s}else{var s=Array(arguments.length);s.push.apply(s,arguments),this._tasks=s}this.length+=arguments.length}else n===1?this._tasks=[this._tasks,t]:this._tasks=t,this.length++;this.firstEmitBuildStrategy?this.call=rebuild_on_first_call:this.rebuild()}function _fast_remove_single(t,e){e!==-1&&(e===0?t.shift():e===t.length-1?t.length=t.length-1:t.splice(e,1))}taskCollection._fast_remove_single=_fast_remove_single;function removeLast_norebuild(t){this.length!==0&&(this.length===1?this._tasks===t&&(this.length=0):(_fast_remove_single(this._tasks,this._tasks.lastIndexOf(t)),this._tasks.length===1?(this._tasks=this._tasks[0],this.length=1):this.length=this._tasks.length))}function removeLast_rebuild(t){if(this.length!==0){if(this.length===1)if(this._tasks===t&&(this.length=0),this.firstEmitBuildStrategy){this.call=bake_collection_1.BAKED_EMPTY_FUNC;return}else{this.rebuild();return}else _fast_remove_single(this._tasks,this._tasks.lastIndexOf(t)),this._tasks.length===1?(this._tasks=this._tasks[0],this.length=1):this.length=this._tasks.length;this.firstEmitBuildStrategy?this.call=rebuild_on_first_call:this.rebuild()}}function insert_norebuild(t){for(var e,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];this.length===0?(this._tasks=n,this.length=1):this.length===1?(n.unshift(this._tasks),this._tasks=n,this.length=this._tasks.length):((e=this._tasks).splice.apply(e,__spreadArray$1([t,0],n,!1)),this.length=this._tasks.length)}function insert_rebuild(t){for(var e,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];this.length===0?(this._tasks=n,this.length=1):this.length===1?(n.unshift(this._tasks),this._tasks=n,this.length=this._tasks.length):((e=this._tasks).splice.apply(e,__spreadArray$1([t,0],n,!1)),this.length=this._tasks.length),this.firstEmitBuildStrategy?this.call=rebuild_on_first_call:this.rebuild()}function rebuild_noawait(){this.length===0?this.call=bake_collection_1.BAKED_EMPTY_FUNC:this.length===1?this.call=this._tasks:this.call=(0,bake_collection_1.bakeCollection)(this._tasks,this.argsNum)}function rebuild_await(){this.length===0?this.call=bake_collection_1.BAKED_EMPTY_FUNC:this.length===1?this.call=this._tasks:this.call=(0,bake_collection_1.bakeCollectionAwait)(this._tasks,this.argsNum)}function rebuild_on_first_call(){this.rebuild(),this.call.apply(void 0,arguments)}var TaskCollection=function(){function t(e,n,r,s){n===void 0&&(n=!0),r===void 0&&(r=null),s===void 0&&(s=!1),this.awaitTasks=s,this.call=bake_collection_1.BAKED_EMPTY_FUNC,this.argsNum=e,this.firstEmitBuildStrategy=!0,s?this.rebuild=rebuild_await.bind(this):this.rebuild=rebuild_noawait.bind(this),this.setAutoRebuild(n),r?typeof r=="function"?(this._tasks=r,this.length=1):(this._tasks=r,this.length=r.length):(this._tasks=null,this.length=0),n&&this.rebuild()}return t}();taskCollection.TaskCollection=TaskCollection;function fastClear(){this._tasks=null,this.length=0,this.call=bake_collection_1.BAKED_EMPTY_FUNC}function clear(){this._tasks=null,this.length=0,this.call=bake_collection_1.BAKED_EMPTY_FUNC}function growArgsNum(t){this.argsNum<t&&(this.argsNum=t,this.firstEmitBuildStrategy?this.call=rebuild_on_first_call:this.rebuild())}function setAutoRebuild(t){t?(this.push=push_rebuild.bind(this),this.insert=insert_rebuild.bind(this),this.removeLast=removeLast_rebuild.bind(this)):(this.push=push_norebuild.bind(this),this.insert=insert_norebuild.bind(this),this.removeLast=removeLast_norebuild.bind(this))}function tasksAsArray(){return this.length===0?[]:this.length===1?[this._tasks]:this._tasks}function setTasks(t){t.length===0?(this.length=0,this.call=bake_collection_1.BAKED_EMPTY_FUNC):t.length===1?(this.length=1,this.call=t[0],this._tasks=t[0]):(this.length=t.length,this._tasks=t,this.firstEmitBuildStrategy?this.call=rebuild_on_first_call:this.rebuild())}TaskCollection.prototype.fastClear=fastClear;TaskCollection.prototype.clear=clear;TaskCollection.prototype.growArgsNum=growArgsNum;TaskCollection.prototype.setAutoRebuild=setAutoRebuild;TaskCollection.prototype.tasksAsArray=tasksAsArray;TaskCollection.prototype.setTasks=setTasks;(function(t){var e=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(r,s,i,o){o===void 0&&(o=i);var a=Object.getOwnPropertyDescriptor(s,i);(!a||("get"in a?!s.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return s[i]}}),Object.defineProperty(r,o,a)}:function(r,s,i,o){o===void 0&&(o=i),r[o]=s[i]}),n=commonjsGlobal&&commonjsGlobal.__exportStar||function(r,s){for(var i in r)i!=="default"&&!Object.prototype.hasOwnProperty.call(s,i)&&e(s,r,i)};Object.defineProperty(t,"__esModule",{value:!0}),n(taskCollection,t)})(taskCollection$1);var utils={};Object.defineProperty(utils,"__esModule",{value:!0});utils.nullObj=void 0;function nullObj(){var t={};return t.__proto__=null,t.prototype=null,t}utils.nullObj=nullObj;var __spreadArray=commonjsGlobal&&commonjsGlobal.__spreadArray||function(t,e,n){if(n||arguments.length===2)for(var r=0,s=e.length,i;r<s;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))};Object.defineProperty(ee,"__esModule",{value:!0});ee.EventEmitter=void 0;var task_collection_1=taskCollection$1,utils_1=utils;function emit(t,e,n,r,s,i){var o=this.events[t];return o?o.length===0?!1:(o.argsNum<6?o.call(e,n,r,s,i):o.call.apply(void 0,arguments),!0):!1}function emitHasOnce(t,e,n,r,s,i){var o=this.events[t];if(o){if(o.length===0)return!1;o.argsNum<6?o.call(e,n,r,s,i):o.call.apply(void 0,arguments)}var a=this.onceEvents[t];if(a){if(typeof a=="function")this.onceEvents[t]=void 0,arguments.length<6?a(e,n,r,s,i):a.apply(void 0,arguments);else{var c=a;if(this.onceEvents[t]=void 0,arguments.length<6)for(var l=0;l<c.length;++l)c[l](e,n,r,s,i);else for(var l=0;l<c.length;++l)c[l].apply(void 0,arguments)}return!0}return!!o}var EventEmitter=function(){function t(){this.events=(0,utils_1.nullObj)(),this.onceEvents=(0,utils_1.nullObj)(),this._symbolKeys=new Set,this.maxListeners=1/0}return Object.defineProperty(t.prototype,"_eventsCount",{get:function(){return this.eventNames().length},enumerable:!1,configurable:!0}),t}();ee.EventEmitter=EventEmitter;function once(t,e){switch(this.emit===emit&&(this.emit=emitHasOnce),typeof this.onceEvents[t]){case"undefined":this.onceEvents[t]=e,typeof t=="symbol"&&this._symbolKeys.add(t);break;case"function":this.onceEvents[t]=[this.onceEvents[t],e];break;case"object":this.onceEvents[t].push(e)}return this}function addListener(t,e,n){if(n===void 0&&(n=e.length),typeof e!="function")throw new TypeError("The listener must be a function");var r=this.events[t];return r?(r.push(e),r.growArgsNum(n),this.maxListeners!==1/0&&this.maxListeners<=r.length&&console.warn('Maximum event listeners for "'.concat(String(t),'" event!'))):(this.events[t]=new task_collection_1.TaskCollection(n,!0,e,!1),typeof t=="symbol"&&this._symbolKeys.add(t)),this}function removeListener(t,e){var n=this.events[t];n&&n.removeLast(e);var r=this.onceEvents[t];return r&&(typeof r=="function"?this.onceEvents[t]=void 0:typeof r=="object"&&(r.length===1&&r[0]===e?this.onceEvents[t]=void 0:(0,task_collection_1._fast_remove_single)(r,r.lastIndexOf(e)))),this}function addListenerBound(t,e,n,r){n===void 0&&(n=this),r===void 0&&(r=e.length),this.boundFuncs||(this.boundFuncs=new Map);var s=e.bind(n);return this.boundFuncs.set(e,s),this.addListener(t,s,r)}function removeListenerBound(t,e){var n,r,s=(n=this.boundFuncs)===null||n===void 0?void 0:n.get(e);return(r=this.boundFuncs)===null||r===void 0||r.delete(e),this.removeListener(t,s)}function hasListeners(t){return this.events[t]&&!!this.events[t].length}function prependListener(t,e,n){if(n===void 0&&(n=e.length),typeof e!="function")throw new TypeError("The listener must be a function");var r=this.events[t];return!r||!(r instanceof task_collection_1.TaskCollection)?(r=this.events[t]=new task_collection_1.TaskCollection(n,!0,e,!1),typeof t=="symbol"&&this._symbolKeys.add(t)):(r.insert(0,e),r.growArgsNum(n),this.maxListeners!==1/0&&this.maxListeners<=r.length&&console.warn('Maximum event listeners for "'.concat(String(t),'" event!'))),this}function prependOnceListener(t,e){this.emit===emit&&(this.emit=emitHasOnce);var n=this.onceEvents[t];return n?typeof n!="object"?(this.onceEvents[t]=[e,n],typeof t=="symbol"&&this._symbolKeys.add(t)):(n.unshift(e),this.maxListeners!==1/0&&this.maxListeners<=n.length&&console.warn('Maximum event listeners for "'.concat(String(t),'" once event!'))):(this.onceEvents[t]=[e],typeof t=="symbol"&&this._symbolKeys.add(t)),this}function removeAllListeners(t){return t===void 0?(this.events=(0,utils_1.nullObj)(),this.onceEvents=(0,utils_1.nullObj)(),this._symbolKeys=new Set):(this.events[t]=void 0,this.onceEvents[t]=void 0,typeof t=="symbol"&&this._symbolKeys.delete(t)),this}function setMaxListeners(t){return this.maxListeners=t,this}function getMaxListeners(){return this.maxListeners}function listeners(t){return this.emit===emit?this.events[t]?this.events[t].tasksAsArray().slice():[]:this.events[t]&&this.onceEvents[t]?__spreadArray(__spreadArray([],this.events[t].tasksAsArray(),!0),typeof this.onceEvents[t]=="function"?[this.onceEvents[t]]:this.onceEvents[t],!0):this.events[t]?this.events[t].tasksAsArray():this.onceEvents[t]?typeof this.onceEvents[t]=="function"?[this.onceEvents[t]]:this.onceEvents[t]:[]}function eventNames(){var t=this;if(this.emit===emit){var e=Object.keys(this.events);return __spreadArray(__spreadArray([],e,!0),Array.from(this._symbolKeys),!0).filter(function(r){return r in t.events&&t.events[r]&&t.events[r].length})}else{var e=Object.keys(this.events).filter(function(s){return t.events[s]&&t.events[s].length}),n=Object.keys(this.onceEvents).filter(function(s){return t.onceEvents[s]&&t.onceEvents[s].length});return __spreadArray(__spreadArray(__spreadArray([],e,!0),n,!0),Array.from(this._symbolKeys).filter(function(s){return s in t.events&&t.events[s]&&t.events[s].length||s in t.onceEvents&&t.onceEvents[s]&&t.onceEvents[s].length}),!0)}}function listenerCount(t){return this.emit===emit?this.events[t]&&this.events[t].length||0:(this.events[t]&&this.events[t].length||0)+(this.onceEvents[t]&&this.onceEvents[t].length||0)}EventEmitter.prototype.emit=emit;EventEmitter.prototype.on=addListener;EventEmitter.prototype.once=once;EventEmitter.prototype.addListener=addListener;EventEmitter.prototype.removeListener=removeListener;EventEmitter.prototype.addListenerBound=addListenerBound;EventEmitter.prototype.removeListenerBound=removeListenerBound;EventEmitter.prototype.hasListeners=hasListeners;EventEmitter.prototype.prependListener=prependListener;EventEmitter.prototype.prependOnceListener=prependOnceListener;EventEmitter.prototype.off=removeListener;EventEmitter.prototype.removeAllListeners=removeAllListeners;EventEmitter.prototype.setMaxListeners=setMaxListeners;EventEmitter.prototype.getMaxListeners=getMaxListeners;EventEmitter.prototype.listeners=listeners;EventEmitter.prototype.eventNames=eventNames;EventEmitter.prototype.listenerCount=listenerCount;(function(t){var e=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(r,s,i,o){o===void 0&&(o=i);var a=Object.getOwnPropertyDescriptor(s,i);(!a||("get"in a?!s.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return s[i]}}),Object.defineProperty(r,o,a)}:function(r,s,i,o){o===void 0&&(o=i),r[o]=s[i]}),n=commonjsGlobal&&commonjsGlobal.__exportStar||function(r,s){for(var i in r)i!=="default"&&!Object.prototype.hasOwnProperty.call(s,i)&&e(s,r,i)};Object.defineProperty(t,"__esModule",{value:!0}),n(types,t),n(ee,t)})(lib$1);var browser={exports:{}},ms,hasRequiredMs;function requireMs(){if(hasRequiredMs)return ms;hasRequiredMs=1;var t=1e3,e=t*60,n=e*60,r=n*24,s=r*7,i=r*365.25;ms=function(h,u){u=u||{};var p=typeof h;if(p==="string"&&h.length>0)return o(h);if(p==="number"&&isFinite(h))return u.long?c(h):a(h);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(h))};function o(h){if(h=String(h),!(h.length>100)){var u=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(h);if(u){var p=parseFloat(u[1]),g=(u[2]||"ms").toLowerCase();switch(g){case"years":case"year":case"yrs":case"yr":case"y":return p*i;case"weeks":case"week":case"w":return p*s;case"days":case"day":case"d":return p*r;case"hours":case"hour":case"hrs":case"hr":case"h":return p*n;case"minutes":case"minute":case"mins":case"min":case"m":return p*e;case"seconds":case"second":case"secs":case"sec":case"s":return p*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return p;default:return}}}}function a(h){var u=Math.abs(h);return u>=r?Math.round(h/r)+"d":u>=n?Math.round(h/n)+"h":u>=e?Math.round(h/e)+"m":u>=t?Math.round(h/t)+"s":h+"ms"}function c(h){var u=Math.abs(h);return u>=r?l(h,u,r,"day"):u>=n?l(h,u,n,"hour"):u>=e?l(h,u,e,"minute"):u>=t?l(h,u,t,"second"):h+" ms"}function l(h,u,p,g){var m=u>=p*1.5;return Math.round(h/p)+" "+g+(m?"s":"")}return ms}function setup(t){n.debug=n,n.default=n,n.coerce=c,n.disable=i,n.enable=s,n.enabled=o,n.humanize=requireMs(),n.destroy=l,Object.keys(t).forEach(h=>{n[h]=t[h]}),n.names=[],n.skips=[],n.formatters={};function e(h){let u=0;for(let p=0;p<h.length;p++)u=(u<<5)-u+h.charCodeAt(p),u|=0;return n.colors[Math.abs(u)%n.colors.length]}n.selectColor=e;function n(h){let u,p=null,g,m;function d(...w){if(!d.enabled)return;const $=d,_=Number(new Date),x=_-(u||_);$.diff=x,$.prev=u,$.curr=_,u=_,w[0]=n.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let I=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(v,B)=>{if(v==="%%")return"%";I++;const S=n.formatters[B];if(typeof S=="function"){const H=w[I];v=S.call($,H),w.splice(I,1),I--}return v}),n.formatArgs.call($,w),($.log||n.log).apply($,w)}return d.namespace=h,d.useColors=n.useColors(),d.color=n.selectColor(h),d.extend=r,d.destroy=n.destroy,Object.defineProperty(d,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:(g!==n.namespaces&&(g=n.namespaces,m=n.enabled(h)),m),set:w=>{p=w}}),typeof n.init=="function"&&n.init(d),d}function r(h,u){const p=n(this.namespace+(typeof u>"u"?":":u)+h);return p.log=this.log,p}function s(h){n.save(h),n.namespaces=h,n.names=[],n.skips=[];let u;const p=(typeof h=="string"?h:"").split(/[\s,]+/),g=p.length;for(u=0;u<g;u++)p[u]&&(h=p[u].replace(/\*/g,".*?"),h[0]==="-"?n.skips.push(new RegExp("^"+h.slice(1)+"$")):n.names.push(new RegExp("^"+h+"$")))}function i(){const h=[...n.names.map(a),...n.skips.map(a).map(u=>"-"+u)].join(",");return n.enable(""),h}function o(h){if(h[h.length-1]==="*")return!0;let u,p;for(u=0,p=n.skips.length;u<p;u++)if(n.skips[u].test(h))return!1;for(u=0,p=n.names.length;u<p;u++)if(n.names[u].test(h))return!0;return!1}function a(h){return h.toString().substring(2,h.toString().length-2).replace(/\.\*\?$/,"*")}function c(h){return h instanceof Error?h.stack||h.message:h}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}var common=setup;(function(t,e){var n={};e.formatArgs=s,e.save=i,e.load=o,e.useColors=r,e.storage=a(),e.destroy=(()=>{let l=!1;return()=>{l||(l=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function r(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function s(l){if(l[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+l[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),!this.useColors)return;const h="color: "+this.color;l.splice(1,0,h,"color: inherit");let u=0,p=0;l[0].replace(/%[a-zA-Z%]/g,g=>{g!=="%%"&&(u++,g==="%c"&&(p=u))}),l.splice(p,0,h)}e.log=console.debug||console.log||(()=>{});function i(l){try{l?e.storage.setItem("debug",l):e.storage.removeItem("debug")}catch{}}function o(){let l;try{l=e.storage.getItem("debug")}catch{}return!l&&typeof process<"u"&&"env"in process&&(l=n.DEBUG),l}function a(){try{return localStorage}catch{}}t.exports=common(e);const{formatters:c}=t.exports;c.j=function(l){try{return JSON.stringify(l)}catch(h){return"[UnexpectedJSONParseError]: "+h.message}}})(browser,browser.exports);var browserExports=browser.exports;const debug6=getDefaultExportFromCjs(browserExports);function number(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function isBytes$1(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function bytes(t,...e){if(!isBytes$1(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function hash(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number(t.outputLen),number(t.blockLen)}function exists(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 output(t,e){bytes(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const crypto$1=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const createView=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),rotr=(t,e)=>t<<32-e|t>>>e;new Uint8Array(new Uint32Array([287454020]).buffer)[0];const hexes$1=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function bytesToHex$1(t){bytes(t);let e="";for(let n=0;n<t.length;n++)e+=hexes$1[t[n]];return e}function utf8ToBytes$1(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function toBytes(t){return typeof t=="string"&&(t=utf8ToBytes$1(t)),bytes(t),t}function concatBytes$1(...t){let e=0;for(let r=0;r<t.length;r++){const s=t[r];bytes(s),e+=s.length}const n=new Uint8Array(e);for(let r=0,s=0;r<t.length;r++){const i=t[r];n.set(i,s),s+=i.length}return n}class Hash{clone(){return this._cloneInto()}}function wrapConstructor(t){const e=r=>t().update(toBytes(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function randomBytes(t=32){if(crypto$1&&typeof crypto$1.getRandomValues=="function")return crypto$1.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function setBigUint64(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const s=BigInt(32),i=BigInt(4294967295),o=Number(n>>s&i),a=Number(n&i),c=r?4:0,l=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+l,a,r)}const Chi=(t,e,n)=>t&e^~t&n,Maj=(t,e,n)=>t&e^t&n^e&n;class HashMD extends Hash{constructor(e,n,r,s){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=createView(this.buffer)}update(e){exists(this);const{view:n,buffer:r,blockLen:s}=this;e=toBytes(e);const i=e.length;for(let o=0;o<i;){const a=Math.min(s-this.pos,i-o);if(a===s){const c=createView(e);for(;s<=i-o;o+=s)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){exists(this),output(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:s,isLE:i}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(r,0),o=0);for(let u=o;u<s;u++)n[u]=0;setBigUint64(r,s-8,BigInt(this.length*8),i),this.process(r,0);const a=createView(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,h=this.get();if(l>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,h[u],i)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:s,finished:i,destroyed:o,pos:a}=this;return e.length=s,e.pos=a,e.finished=i,e.destroyed=o,s%n&&e.buffer.set(r),e}}const SHA256_K=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),SHA256_IV=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W=new Uint32Array(64);class SHA256 extends HashMD{constructor(){super(64,32,8,!1),this.A=SHA256_IV[0]|0,this.B=SHA256_IV[1]|0,this.C=SHA256_IV[2]|0,this.D=SHA256_IV[3]|0,this.E=SHA256_IV[4]|0,this.F=SHA256_IV[5]|0,this.G=SHA256_IV[6]|0,this.H=SHA256_IV[7]|0}get(){const{A:e,B:n,C:r,D:s,E:i,F:o,G:a,H:c}=this;return[e,n,r,s,i,o,a,c]}set(e,n,r,s,i,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let u=0;u<16;u++,n+=4)SHA256_W[u]=e.getUint32(n,!1);for(let u=16;u<64;u++){const p=SHA256_W[u-15],g=SHA256_W[u-2],m=rotr(p,7)^rotr(p,18)^p>>>3,d=rotr(g,17)^rotr(g,19)^g>>>10;SHA256_W[u]=d+SHA256_W[u-7]+m+SHA256_W[u-16]|0}let{A:r,B:s,C:i,D:o,E:a,F:c,G:l,H:h}=this;for(let u=0;u<64;u++){const p=rotr(a,6)^rotr(a,11)^rotr(a,25),g=h+p+Chi(a,c,l)+SHA256_K[u]+SHA256_W[u]|0,d=(rotr(r,2)^rotr(r,13)^rotr(r,22))+Maj(r,s,i)|0;h=l,l=c,c=a,a=o+g|0,o=i,i=s,s=r,r=g+d|0}r=r+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,h=h+this.H|0,this.set(r,s,i,o,a,c,l,h)}roundClean(){SHA256_W.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const sha256=wrapConstructor(()=>new SHA256);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$4=BigInt(0),_1n$4=BigInt(1),_2n$2=BigInt(2);function isBytes(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function abytes(t){if(!isBytes(t))throw new Error("Uint8Array expected")}const hexes=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function bytesToHex(t){abytes(t);let e="";for(let n=0;n<t.length;n++)e+=hexes[t[n]];return e}function numberToHexUnpadded(t){const e=t.toString(16);return e.length&1?`0${e}`:e}function hexToNumber(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}const asciis={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function asciiToBase16(t){if(t>=asciis._0&&t<=asciis._9)return t-asciis._0;if(t>=asciis._A&&t<=asciis._F)return t-(asciis._A-10);if(t>=asciis._a&&t<=asciis._f)return t-(asciis._a-10)}function hexToBytes(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,n=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let s=0,i=0;s<n;s++,i+=2){const o=asciiToBase16(t.charCodeAt(i)),a=asciiToBase16(t.charCodeAt(i+1));if(o===void 0||a===void 0){const c=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}r[s]=o*16+a}return r}function bytesToNumberBE(t){return hexToNumber(bytesToHex(t))}function bytesToNumberLE(t){return abytes(t),hexToNumber(bytesToHex(Uint8Array.from(t).reverse()))}function numberToBytesBE(t,e){return hexToBytes(t.toString(16).padStart(e*2,"0"))}function numberToBytesLE(t,e){return numberToBytesBE(t,e).reverse()}function numberToVarBytesBE(t){return hexToBytes(numberToHexUnpadded(t))}function ensureBytes(t,e,n){let r;if(typeof e=="string")try{r=hexToBytes(e)}catch(i){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${i}`)}else if(isBytes(e))r=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);const s=r.length;if(typeof n=="number"&&s!==n)throw new Error(`${t} expected ${n} bytes, got ${s}`);return r}function concatBytes(...t){let e=0;for(let r=0;r<t.length;r++){const s=t[r];abytes(s),e+=s.length}const n=new Uint8Array(e);for(let r=0,s=0;r<t.length;r++){const i=t[r];n.set(i,s),s+=i.length}return n}function equalBytes(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}function utf8ToBytes(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function bitLen(t){let e;for(e=0;t>_0n$4;t>>=_1n$4,e+=1);return e}function bitGet(t,e){return t>>BigInt(e)&_1n$4}function bitSet(t,e,n){return t|(n?_1n$4:_0n$4)<<BigInt(e)}const bitMask=t=>(_2n$2<<BigInt(t-1))-_1n$4,u8n=t=>new Uint8Array(t),u8fr=t=>Uint8Array.from(t);function createHmacDrbg(t,e,n){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=u8n(t),s=u8n(t),i=0;const o=()=>{r.fill(1),s.fill(0),i=0},a=(...u)=>n(s,r,...u),c=(u=u8n())=>{s=a(u8fr([0]),u),r=a(),u.length!==0&&(s=a(u8fr([1]),u),r=a())},l=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const p=[];for(;u<e;){r=a();const g=r.slice();p.push(g),u+=r.length}return concatBytes(...p)};return(u,p)=>{o(),c(u);let g;for(;!(g=p(l()));)c();return o(),g}}const validatorFns={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||isBytes(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function validateObject(t,e,n={}){const r=(s,i,o)=>{const a=validatorFns[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);const c=t[s];if(!(o&&c===void 0)&&!a(c,t))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${i}`)};for(const[s,i]of Object.entries(e))r(s,i,!1);for(const[s,i]of Object.entries(n))r(s,i,!0);return t}const ut=Object.freeze(Object.defineProperty({__proto__:null,abytes,bitGet,bitLen,bitMask,bitSet,bytesToHex,bytesToNumberBE,bytesToNumberLE,concatBytes,createHmacDrbg,ensureBytes,equalBytes,hexToBytes,hexToNumber,isBytes,numberToBytesBE,numberToBytesLE,numberToHexUnpadded,numberToVarBytesBE,utf8ToBytes,validateObject},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$3=BigInt(0),_1n$3=BigInt(1),_2n$1=BigInt(2),_3n$1=BigInt(3),_4n=BigInt(4),_5n=BigInt(5),_8n=BigInt(8);BigInt(9);BigInt(16);function mod(t,e){const n=t%e;return n>=_0n$3?n:e+n}function pow(t,e,n){if(n<=_0n$3||e<_0n$3)throw new Error("Expected power/modulo > 0");if(n===_1n$3)return _0n$3;let r=_1n$3;for(;e>_0n$3;)e&_1n$3&&(r=r*t%n),t=t*t%n,e>>=_1n$3;return r}function pow2(t,e,n){let r=t;for(;e-- >_0n$3;)r*=r,r%=n;return r}function invert(t,e){if(t===_0n$3||e<=_0n$3)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=mod(t,e),r=e,s=_0n$3,i=_1n$3;for(;n!==_0n$3;){const a=r/n,c=r%n,l=s-i*a;r=n,n=c,s=i,i=l}if(r!==_1n$3)throw new Error("invert: does not exist");return mod(s,e)}function tonelliShanks(t){const e=(t-_1n$3)/_2n$1;let n,r,s;for(n=t-_1n$3,r=0;n%_2n$1===_0n$3;n/=_2n$1,r++);for(s=_2n$1;s<t&&pow(s,e,t)!==t-_1n$3;s++);if(r===1){const o=(t+_1n$3)/_4n;return function(c,l){const h=c.pow(l,o);if(!c.eql(c.sqr(h),l))throw new Error("Cannot find square root");return h}}const i=(n+_1n$3)/_2n$1;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=r,h=a.pow(a.mul(a.ONE,s),n),u=a.pow(c,i),p=a.pow(c,n);for(;!a.eql(p,a.ONE);){if(a.eql(p,a.ZERO))return a.ZERO;let g=1;for(let d=a.sqr(p);g<l&&!a.eql(d,a.ONE);g++)d=a.sqr(d);const m=a.pow(h,_1n$3<<BigInt(l-g-1));h=a.sqr(m),u=a.mul(u,m),p=a.mul(p,h),l=g}return u}}function FpSqrt(t){if(t%_4n===_3n$1){const e=(t+_1n$3)/_4n;return function(r,s){const i=r.pow(s,e);if(!r.eql(r.sqr(i),s))throw new Error("Cannot find square root");return i}}if(t%_8n===_5n){const e=(t-_5n)/_8n;return function(r,s){const i=r.mul(s,_2n$1),o=r.pow(i,e),a=r.mul(s,o),c=r.mul(r.mul(a,_2n$1),o),l=r.mul(a,r.sub(c,r.ONE));if(!r.eql(r.sqr(l),s))throw new Error("Cannot find square root");return l}}return tonelliShanks(t)}const FIELD_FIELDS=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function validateField(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=FIELD_FIELDS.reduce((r,s)=>(r[s]="function",r),e);return validateObject(t,n)}function FpPow(t,e,n){if(n<_0n$3)throw new Error("Expected power > 0");if(n===_0n$3)return t.ONE;if(n===_1n$3)return e;let r=t.ONE,s=e;for(;n>_0n$3;)n&_1n$3&&(r=t.mul(r,s)),s=t.sqr(s),n>>=_1n$3;return r}function FpInvertBatch(t,e){const n=new Array(e.length),r=e.reduce((i,o,a)=>t.is0(o)?i:(n[a]=i,t.mul(i,o)),t.ONE),s=t.inv(r);return e.reduceRight((i,o,a)=>t.is0(o)?i:(n[a]=t.mul(i,n[a]),t.mul(i,o)),s),n}function nLength(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Field(t,e,n=!1,r={}){if(t<=_0n$3)throw new Error(`Expected Field ORDER > 0, got ${t}`);const{nBitLength:s,nByteLength:i}=nLength(t,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=FpSqrt(t),a=Object.freeze({ORDER:t,BITS:s,BYTES:i,MASK:bitMask(s),ZERO:_0n$3,ONE:_1n$3,create:c=>mod(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return _0n$3<=c&&c<t},is0:c=>c===_0n$3,isOdd:c=>(c&_1n$3)===_1n$3,neg:c=>mod(-c,t),eql:(c,l)=>c===l,sqr:c=>mod(c*c,t),add:(c,l)=>mod(c+l,t),sub:(c,l)=>mod(c-l,t),mul:(c,l)=>mod(c*l,t),pow:(c,l)=>FpPow(a,c,l),div:(c,l)=>mod(c*invert(l,t),t),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>invert(c,t),sqrt:r.sqrt||(c=>o(a,c)),invertBatch:c=>FpInvertBatch(a,c),cmov:(c,l,h)=>h?l:c,toBytes:c=>n?numberToBytesLE(c,i):numberToBytesBE(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return n?bytesToNumberLE(c):bytesToNumberBE(c)}});return Object.freeze(a)}function getFieldBytesLength(t){if(typeof t!="bigint")throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function getMinHashLength(t){const e=getFieldBytesLength(t);return e+Math.ceil(e/2)}function mapHashToField(t,e,n=!1){const r=t.length,s=getFieldBytesLength(e),i=getMinHashLength(e);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const o=n?bytesToNumberBE(t):bytesToNumberLE(t),a=mod(o,e-_1n$3)+_1n$3;return n?numberToBytesLE(a,s):numberToBytesBE(a,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$2=BigInt(0),_1n$2=BigInt(1);function wNAF(t,e){const n=(s,i)=>{const o=i.negate();return s?o:i},r=s=>{const i=Math.ceil(e/s)+1,o=2**(s-1);return{windows:i,windowSize:o}};return{constTimeNegate:n,unsafeLadder(s,i){let o=t.ZERO,a=s;for(;i>_0n$2;)i&_1n$2&&(o=o.add(a)),a=a.double(),i>>=_1n$2;return o},precomputeWindow(s,i){const{windows:o,windowSize:a}=r(i),c=[];let l=s,h=l;for(let u=0;u<o;u++){h=l,c.push(h);for(let p=1;p<a;p++)h=h.add(l),c.push(h);l=h.double()}return c},wNAF(s,i,o){const{windows:a,windowSize:c}=r(s);let l=t.ZERO,h=t.BASE;const u=BigInt(2**s-1),p=2**s,g=BigInt(s);for(let m=0;m<a;m++){const d=m*c;let w=Number(o&u);o>>=g,w>c&&(w-=p,o+=_1n$2);const $=d,_=d+Math.abs(w)-1,x=m%2!==0,I=w<0;w===0?h=h.add(n(x,i[$])):l=l.add(n(I,i[_]))}return{p:l,f:h}},wNAFCached(s,i,o,a){const c=s._WINDOW_SIZE||1;let l=i.get(s);return l||(l=this.precomputeWindow(s,c),c!==1&&i.set(s,a(l))),this.wNAF(c,l,o)}}}function validateBasic(t){return validateField(t.Fp),validateObject(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...nLength(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function validatePointOpts(t){const e=validateBasic(t);validateObject(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:s}=e;if(n){if(!r.eql(s,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}const{bytesToNumberBE:b2n,hexToBytes:h2b}=ut,DER={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){const{Err:e}=DER;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");const n=t[1],r=t.subarray(2,n+2);if(!n||r.length!==n)throw new e("Invalid signature integer: wrong length");if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:b2n(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=DER,n=typeof t=="string"?h2b(t):t;abytes(n);let r=n.length;if(r<2||n[0]!=48)throw new e("Invalid signature tag");if(n[1]!==r-2)throw new e("Invalid signature: incorrect length");const{d:s,l:i}=DER._parseInt(n.subarray(2)),{d:o,l:a}=DER._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:s,s:o}},hexFromSig(t){const e=l=>Number.parseInt(l[0],16)&8?"00"+l:l,n=l=>{const h=l.toString(16);return h.length&1?`0${h}`:h},r=e(n(t.s)),s=e(n(t.r)),i=r.length/2,o=s.length/2,a=n(i),c=n(o);return`30${n(o+i+4)}02${c}${s}02${a}${r}`}},_0n$1=BigInt(0),_1n$1=BigInt(1);BigInt(2);const _3n=BigInt(3);BigInt(4);function weierstrassPoints(t){const e=validatePointOpts(t),{Fp:n}=e,r=e.toBytes||((m,d,w)=>{const $=d.toAffine();return concatBytes(Uint8Array.from([4]),n.toBytes($.x),n.toBytes($.y))}),s=e.fromBytes||(m=>{const d=m.subarray(1),w=n.fromBytes(d.subarray(0,n.BYTES)),$=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:w,y:$}});function i(m){const{a:d,b:w}=e,$=n.sqr(m),_=n.mul($,m);return n.add(n.add(_,n.mul(m,d)),w)}if(!n.eql(n.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function o(m){return typeof m=="bigint"&&_0n$1<m&&m<e.n}function a(m){if(!o(m))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(m){const{allowedPrivateKeyLengths:d,nByteLength:w,wrapPrivateKey:$,n:_}=e;if(d&&typeof m!="bigint"){if(isBytes(m)&&(m=bytesToHex(m)),typeof m!="string"||!d.includes(m.length))throw new Error("Invalid key");m=m.padStart(w*2,"0")}let x;try{x=typeof m=="bigint"?m:bytesToNumberBE(ensureBytes("private key",m,w))}catch{throw new Error(`private key must be ${w} bytes, hex or bigint, not ${typeof m}`)}return $&&(x=mod(x,_)),a(x),x}const l=new Map;function h(m){if(!(m instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(d,w,$){if(this.px=d,this.py=w,this.pz=$,d==null||!n.isValid(d))throw new Error("x required");if(w==null||!n.isValid(w))throw new Error("y required");if($==null||!n.isValid($))throw new Error("z required")}static fromAffine(d){const{x:w,y:$}=d||{};if(!d||!n.isValid(w)||!n.isValid($))throw new Error("invalid affine point");if(d instanceof u)throw new Error("projective point not allowed");const _=x=>n.eql(x,n.ZERO);return _(w)&&_($)?u.ZERO:new u(w,$,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const w=n.invertBatch(d.map($=>$.pz));return d.map(($,_)=>$.toAffine(w[_])).map(u.fromAffine)}static fromHex(d){const w=u.fromAffine(s(ensureBytes("pointHex",d)));return w.assertValidity(),w}static fromPrivateKey(d){return u.BASE.multiply(c(d))}_setWindowSize(d){this._WINDOW_SIZE=d,l.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:d,y:w}=this.toAffine();if(!n.isValid(d)||!n.isValid(w))throw new Error("bad point: x or y not FE");const $=n.sqr(w),_=i(d);if(!n.eql($,_))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:d}=this.toAffine();if(n.isOdd)return!n.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){h(d);const{px:w,py:$,pz:_}=this,{px:x,py:I,pz:R}=d,v=n.eql(n.mul(w,R),n.mul(x,_)),B=n.eql(n.mul($,R),n.mul(I,_));return v&&B}negate(){return new u(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:w}=e,$=n.mul(w,_3n),{px:_,py:x,pz:I}=this;let R=n.ZERO,v=n.ZERO,B=n.ZERO,S=n.mul(_,_),H=n.mul(x,x),L=n.mul(I,I),E=n.mul(_,x);return E=n.add(E,E),B=n.mul(_,I),B=n.add(B,B),R=n.mul(d,B),v=n.mul($,L),v=n.add(R,v),R=n.sub(H,v),v=n.add(H,v),v=n.mul(R,v),R=n.mul(E,R),B=n.mul($,B),L=n.mul(d,L),E=n.sub(S,L),E=n.mul(d,E),E=n.add(E,B),B=n.add(S,S),S=n.add(B,S),S=n.add(S,L),S=n.mul(S,E),v=n.add(v,S),L=n.mul(x,I),L=n.add(L,L),S=n.mul(L,E),R=n.sub(R,S),B=n.mul(L,H),B=n.add(B,B),B=n.add(B,B),new u(R,v,B)}add(d){h(d);const{px:w,py:$,pz:_}=this,{px:x,py:I,pz:R}=d;let v=n.ZERO,B=n.ZERO,S=n.ZERO;const H=e.a,L=n.mul(e.b,_3n);let E=n.mul(w,x),k=n.mul($,I),T=n.mul(_,R),P=n.add(w,$),y=n.add(x,I);P=n.mul(P,y),y=n.add(E,k),P=n.sub(P,y),y=n.add(w,_);let b=n.add(x,R);return y=n.mul(y,b),b=n.add(E,T),y=n.sub(y,b),b=n.add($,_),v=n.add(I,R),b=n.mul(b,v),v=n.add(k,T),b=n.sub(b,v),S=n.mul(H,y),v=n.mul(L,T),S=n.add(v,S),v=n.sub(k,S),S=n.add(k,S),B=n.mul(v,S),k=n.add(E,E),k=n.add(k,E),T=n.mul(H,T),y=n.mul(L,y),k=n.add(k,T),T=n.sub(E,T),T=n.mul(H,T),y=n.add(y,T),E=n.mul(k,y),B=n.add(B,E),E=n.mul(b,y),v=n.mul(P,v),v=n.sub(v,E),E=n.mul(P,k),S=n.mul(b,S),S=n.add(S,E),new u(v,B,S)}subtract(d){return this.add(d.negate())}is0(){return this.equals(u.ZERO)}wNAF(d){return g.wNAFCached(this,l,d,w=>{const $=n.invertBatch(w.map(_=>_.pz));return w.map((_,x)=>_.toAffine($[x])).map(u.fromAffine)})}multiplyUnsafe(d){const w=u.ZERO;if(d===_0n$1)return w;if(a(d),d===_1n$1)return this;const{endo:$}=e;if(!$)return g.unsafeLadder(this,d);let{k1neg:_,k1:x,k2neg:I,k2:R}=$.splitScalar(d),v=w,B=w,S=this;for(;x>_0n$1||R>_0n$1;)x&_1n$1&&(v=v.add(S)),R&_1n$1&&(B=B.add(S)),S=S.double(),x>>=_1n$1,R>>=_1n$1;return _&&(v=v.negate()),I&&(B=B.negate()),B=new u(n.mul(B.px,$.beta),B.py,B.pz),v.add(B)}multiply(d){a(d);let w=d,$,_;const{endo:x}=e;if(x){const{k1neg:I,k1:R,k2neg:v,k2:B}=x.splitScalar(w);let{p:S,f:H}=this.wNAF(R),{p:L,f:E}=this.wNAF(B);S=g.constTimeNegate(I,S),L=g.constTimeNegate(v,L),L=new u(n.mul(L.px,x.beta),L.py,L.pz),$=S.add(L),_=H.add(E)}else{const{p:I,f:R}=this.wNAF(w);$=I,_=R}return u.normalizeZ([$,_])[0]}multiplyAndAddUnsafe(d,w,$){const _=u.BASE,x=(R,v)=>v===_0n$1||v===_1n$1||!R.equals(_)?R.multiplyUnsafe(v):R.multiply(v),I=x(this,w).add(x(d,$));return I.is0()?void 0:I}toAffine(d){const{px:w,py:$,pz:_}=this,x=this.is0();d==null&&(d=x?n.ONE:n.inv(_));const I=n.mul(w,d),R=n.mul($,d),v=n.mul(_,d);if(x)return{x:n.ZERO,y:n.ZERO};if(!n.eql(v,n.ONE))throw new Error("invZ was invalid");return{x:I,y:R}}isTorsionFree(){const{h:d,isTorsionFree:w}=e;if(d===_1n$1)return!0;if(w)return w(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:w}=e;return d===_1n$1?this:w?w(u,this):this.multiplyUnsafe(e.h)}toRawBytes(d=!0){return this.assertValidity(),r(u,this,d)}toHex(d=!0){return bytesToHex(this.toRawBytes(d))}}u.BASE=new u(e.Gx,e.Gy,n.ONE),u.ZERO=new u(n.ZERO,n.ONE,n.ZERO);const p=e.nBitLength,g=wNAF(u,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:o}}function validateOpts(t){const e=validateBasic(t);return validateObject(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function weierstrass(t){const e=validateOpts(t),{Fp:n,n:r}=e,s=n.BYTES+1,i=2*n.BYTES+1;function o(y){return _0n$1<y&&y<n.ORDER}function a(y){return mod(y,r)}function c(y){return invert(y,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:h,weierstrassEquation:u,isWithinCurveOrder:p}=weierstrassPoints({...e,toBytes(y,b,A){const U=b.toAffine(),C=n.toBytes(U.x),D=concatBytes;return A?D(Uint8Array.from([b.hasEvenY()?2:3]),C):D(Uint8Array.from([4]),C,n.toBytes(U.y))},fromBytes(y){const b=y.length,A=y[0],U=y.subarray(1);if(b===s&&(A===2||A===3)){const C=bytesToNumberBE(U);if(!o(C))throw new Error("Point is not on curve");const D=u(C);let F;try{F=n.sqrt(D)}catch(M){const z=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+z)}const O=(F&_1n$1)===_1n$1;return(A&1)===1!==O&&(F=n.neg(F)),{x:C,y:F}}else if(b===i&&A===4){const C=n.fromBytes(U.subarray(0,n.BYTES)),D=n.fromBytes(U.subarray(n.BYTES,2*n.BYTES));return{x:C,y:D}}else throw new Error(`Point of length ${b} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),g=y=>bytesToHex(numberToBytesBE(y,e.nByteLength));function m(y){const b=r>>_1n$1;return y>b}function d(y){return m(y)?a(-y):y}const w=(y,b,A)=>bytesToNumberBE(y.slice(b,A));class ${constructor(b,A,U){this.r=b,this.s=A,this.recovery=U,this.assertValidity()}static fromCompact(b){const A=e.nByteLength;return b=ensureBytes("compactSignature",b,A*2),new $(w(b,0,A),w(b,A,2*A))}static fromDER(b){const{r:A,s:U}=DER.toSig(ensureBytes("DER",b));return new $(A,U)}assertValidity(){if(!p(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!p(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(b){return new $(this.r,this.s,b)}recoverPublicKey(b){const{r:A,s:U,recovery:C}=this,D=B(ensureBytes("msgHash",b));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");const F=C===2||C===3?A+e.n:A;if(F>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const O=C&1?"03":"02",K=l.fromHex(O+g(F)),M=c(F),z=a(-D*M),V=a(U*M),q=l.BASE.multiplyAndAddUnsafe(K,z,V);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new $(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return hexToBytes(this.toDERHex())}toDERHex(){return DER.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hexToBytes(this.toCompactHex())}toCompactHex(){return g(this.r)+g(this.s)}}const _={isValidPrivateKey(y){try{return h(y),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const y=getMinHashLength(e.n);return mapHashToField(e.randomBytes(y),e.n)},precompute(y=8,b=l.BASE){return b._setWindowSize(y),b.multiply(BigInt(3)),b}};function x(y,b=!0){return l.fromPrivateKey(y).toRawBytes(b)}function I(y){const b=isBytes(y),A=typeof y=="string",U=(b||A)&&y.length;return b?U===s||U===i:A?U===2*s||U===2*i:y instanceof l}function R(y,b,A=!0){if(I(y))throw new Error("first arg must be private key");if(!I(b))throw new Error("second arg must be public key");return l.fromHex(b).multiply(h(y)).toRawBytes(A)}const v=e.bits2int||function(y){const b=bytesToNumberBE(y),A=y.length*8-e.nBitLength;return A>0?b>>BigInt(A):b},B=e.bits2int_modN||function(y){return a(v(y))},S=bitMask(e.nBitLength);function H(y){if(typeof y!="bigint")throw new Error("bigint expected");if(!(_0n$1<=y&&y<S))throw new Error(`bigint expected < 2^${e.nBitLength}`);return numberToBytesBE(y,e.nByteLength)}function L(y,b,A=E){if(["recovered","canonical"].some(W=>W in A))throw new Error("sign() legacy options not supported");const{hash:U,randomBytes:C}=e;let{lowS:D,prehash:F,extraEntropy:O}=A;D==null&&(D=!0),y=ensureBytes("msgHash",y),F&&(y=ensureBytes("prehashed msgHash",U(y)));const K=B(y),M=h(b),z=[H(M),H(K)];if(O!=null&&O!==!1){const W=O===!0?C(n.BYTES):O;z.push(ensureBytes("extraEntropy",W))}const V=concatBytes(...z),q=K;function G(W){const Z=v(W);if(!p(Z))return;const J=c(Z),Y=l.BASE.multiply(Z).toAffine(),j=a(Y.x);if(j===_0n$1)return;const X=a(J*a(q+j*M));if(X===_0n$1)return;let Q=(Y.x===j?0:2)|Number(Y.y&_1n$1),te=X;return D&&m(X)&&(te=d(X),Q^=1),new $(j,te,Q)}return{seed:V,k2sig:G}}const E={lowS:e.lowS,prehash:!1},k={lowS:e.lowS,prehash:!1};function T(y,b,A=E){const{seed:U,k2sig:C}=L(y,b,A),D=e;return createHmacDrbg(D.hash.outputLen,D.nByteLength,D.hmac)(U,C)}l.BASE._setWindowSize(8);function P(y,b,A,U=k){var Y;const C=y;if(b=ensureBytes("msgHash",b),A=ensureBytes("publicKey",A),"strict"in U)throw new Error("options.strict was renamed to lowS");const{lowS:D,prehash:F}=U;let O,K;try{if(typeof C=="string"||isBytes(C))try{O=$.fromDER(C)}catch(j){if(!(j instanceof DER.Err))throw j;O=$.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){const{r:j,s:X}=C;O=new $(j,X)}else throw new Error("PARSE");K=l.fromHex(A)}catch(j){if(j.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(D&&O.hasHighS())return!1;F&&(b=e.hash(b));const{r:M,s:z}=O,V=B(b),q=c(z),G=a(V*q),W=a(M*q),Z=(Y=l.BASE.multiplyAndAddUnsafe(K,G,W))==null?void 0:Y.toAffine();return Z?a(Z.x)===M:!1}return{CURVE:e,getPublicKey:x,getSharedSecret:R,sign:T,verify:P,ProjectivePoint:l,Signature:$,utils:_}}class HMAC extends Hash{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,hash(e);const r=toBytes(n);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,i=new Uint8Array(s);i.set(r.length>s?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),i.fill(0)}update(e){return exists(this),this.iHash.update(e),this}digestInto(e){exists(this),bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=i,e.blockLen=o,e.outputLen=a,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const hmac=(t,e,n)=>new HMAC(t,e).update(n).digest();hmac.create=(t,e)=>new HMAC(t,e);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function getHash(t){return{hash:t,hmac:(e,...n)=>hmac(t,e,concatBytes$1(...n)),randomBytes}}function createCurve(t,e){const n=r=>weierstrass({...t,...getHash(r)});return Object.freeze({...n(e),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const secp256k1P=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),secp256k1N=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),_1n=BigInt(1),_2n=BigInt(2),divNearest=(t,e)=>(t+e/_2n)/e;function sqrtMod(t){const e=secp256k1P,n=BigInt(3),r=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),l=t*t*t%e,h=l*l*t%e,u=pow2(h,n,e)*h%e,p=pow2(u,n,e)*h%e,g=pow2(p,_2n,e)*l%e,m=pow2(g,s,e)*g%e,d=pow2(m,i,e)*m%e,w=pow2(d,a,e)*d%e,$=pow2(w,c,e)*w%e,_=pow2($,a,e)*d%e,x=pow2(_,n,e)*h%e,I=pow2(x,o,e)*m%e,R=pow2(I,r,e)*l%e,v=pow2(R,_2n,e);if(!Fp.eql(Fp.sqr(v),t))throw new Error("Cannot find square root");return v}const Fp=Field(secp256k1P,void 0,void 0,{sqrt:sqrtMod}),secp256k1=createCurve({a:BigInt(0),b:BigInt(7),Fp,n:secp256k1N,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=secp256k1N,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-_1n*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,o=BigInt("0x100000000000000000000000000000000"),a=divNearest(i*t,e),c=divNearest(-r*t,e);let l=mod(t-a*n-c*s,e),h=mod(-a*r-c*i,e);const u=l>o,p=h>o;if(u&&(l=e-l),p&&(h=e-h),l>o||h>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:l,k2neg:p,k2:h}}}},sha256),_0n=BigInt(0),fe=t=>typeof t=="bigint"&&_0n<t&&t<secp256k1P,ge=t=>typeof t=="bigint"&&_0n<t&&t<secp256k1N,TAGGED_HASH_PREFIXES={};function taggedHash(t,...e){let n=TAGGED_HASH_PREFIXES[t];if(n===void 0){const r=sha256(Uint8Array.from(t,s=>s.charCodeAt(0)));n=concatBytes(r,r),TAGGED_HASH_PREFIXES[t]=n}return sha256(concatBytes(n,...e))}const pointToBytes=t=>t.toRawBytes(!0).slice(1),numTo32b=t=>numberToBytesBE(t,32),modP=t=>mod(t,secp256k1P),modN=t=>mod(t,secp256k1N),Point=secp256k1.ProjectivePoint,GmulAdd=(t,e,n)=>Point.BASE.multiplyAndAddUnsafe(t,e,n);function schnorrGetExtPubKey(t){let e=secp256k1.utils.normPrivateKeyToScalar(t),n=Point.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:modN(-e),bytes:pointToBytes(n)}}function lift_x(t){if(!fe(t))throw new Error("bad x: need 0 < x < p");const e=modP(t*t),n=modP(e*t+BigInt(7));let r=sqrtMod(n);r%_2n!==_0n&&(r=modP(-r));const s=new Point(t,r,_1n);return s.assertValidity(),s}function challenge(...t){return modN(bytesToNumberBE(taggedHash("BIP0340/challenge",...t)))}function schnorrGetPublicKey(t){return schnorrGetExtPubKey(t).bytes}function schnorrSign(t,e,n=randomBytes(32)){const r=ensureBytes("message",t),{bytes:s,scalar:i}=schnorrGetExtPubKey(e),o=ensureBytes("auxRand",n,32),a=numTo32b(i^bytesToNumberBE(taggedHash("BIP0340/aux",o))),c=taggedHash("BIP0340/nonce",a,s,r),l=modN(bytesToNumberBE(c));if(l===_0n)throw new Error("sign failed: k is zero");const{bytes:h,scalar:u}=schnorrGetExtPubKey(l),p=challenge(h,s,r),g=new Uint8Array(64);if(g.set(h,0),g.set(numTo32b(modN(u+p*i)),32),!schnorrVerify(g,r,s))throw new Error("sign: Invalid signature produced");return g}function schnorrVerify(t,e,n){const r=ensureBytes("signature",t,64),s=ensureBytes("message",e),i=ensureBytes("publicKey",n,32);try{const o=lift_x(bytesToNumberBE(i)),a=bytesToNumberBE(r.subarray(0,32));if(!fe(a))return!1;const c=bytesToNumberBE(r.subarray(32,64));if(!ge(c))return!1;const l=challenge(numTo32b(a),pointToBytes(o),s),h=GmulAdd(o,c,modN(-l));return!(!h||!h.hasEvenY()||h.toAffine().x!==a)}catch{return!1}}const schnorr={getPublicKey:schnorrGetPublicKey,sign:schnorrSign,verify:schnorrVerify,utils:{randomPrivateKey:secp256k1.utils.randomPrivateKey,lift_x,pointToBytes,numberToBytesBE,bytesToNumberBE,taggedHash,mod}};var dist={},LRUCache$1={},LRUCacheNode$1={};Object.defineProperty(LRUCacheNode$1,"__esModule",{value:!0});LRUCacheNode$1.LRUCacheNode=void 0;class LRUCacheNode{constructor(e,n,r){const{entryExpirationTimeInMS:s=null,next:i=null,prev:o=null,onEntryEvicted:a,onEntryMarkedAsMostRecentlyUsed:c,clone:l,cloneFn:h}=r??{};if(typeof s=="number"&&(s<=0||Number.isNaN(s)))throw new Error("entryExpirationTimeInMS must either be null (no expiry) or greater than 0");this.clone=l??!1,this.cloneFn=h??this.defaultClone,this.key=e,this.internalValue=this.clone?this.cloneFn(n):n,this.created=Date.now(),this.entryExpirationTimeInMS=s,this.next=i,this.prev=o,this.onEntryEvicted=a,this.onEntryMarkedAsMostRecentlyUsed=c}get value(){return this.clone?this.cloneFn(this.internalValue):this.internalValue}get isExpired(){return typeof this.entryExpirationTimeInMS=="number"&&Date.now()-this.created>this.entryExpirationTimeInMS}invokeOnEvicted(){if(this.onEntryEvicted){const{key:e,value:n,isExpired:r}=this;this.onEntryEvicted({key:e,value:n,isExpired:r})}}invokeOnEntryMarkedAsMostRecentlyUsed(){if(this.onEntryMarkedAsMostRecentlyUsed){const{key:e,value:n}=this;this.onEntryMarkedAsMostRecentlyUsed({key:e,value:n})}}defaultClone(e){return typeof e=="boolean"||typeof e=="string"||typeof e=="number"?e:JSON.parse(JSON.stringify(e))}}LRUCacheNode$1.LRUCacheNode=LRUCacheNode;Object.defineProperty(LRUCache$1,"__esModule",{value:!0});LRUCache$1.LRUCache=void 0;const LRUCacheNode_1=LRUCacheNode$1;class LRUCache{constructor(e){this.lookupTable=new Map,this.head=null,this.tail=null;const{maxSize:n=25,entryExpirationTimeInMS:r=null,onEntryEvicted:s,onEntryMarkedAsMostRecentlyUsed:i,cloneFn:o,clone:a}=e??{};if(Number.isNaN(n)||n<=0)throw new Error("maxSize must be greater than 0.");if(typeof r=="number"&&(r<=0||Number.isNaN(r)))throw new Error("entryExpirationTimeInMS must either be null (no expiry) or greater than 0");this.maxSizeInternal=n,this.entryExpirationTimeInMS=r,this.onEntryEvicted=s,this.onEntryMarkedAsMostRecentlyUsed=i,this.clone=a,this.cloneFn=o}get size(){return this.cleanCache(),this.lookupTable.size}get remainingSize(){return this.maxSizeInternal-this.size}get newest(){return this.head?this.head.isExpired?(this.removeNodeFromListAndLookupTable(this.head),this.newest):this.mapNodeToEntry(this.head):null}get oldest(){return this.tail?this.tail.isExpired?(this.removeNodeFromListAndLookupTable(this.tail),this.oldest):this.mapNodeToEntry(this.tail):null}get maxSize(){return this.maxSizeInternal}set maxSize(e){if(Number.isNaN(e)||e<=0)throw new Error("maxSize must be greater than 0.");this.maxSizeInternal=e,this.enforceSizeLimit()}set(e,n,r){const s=this.lookupTable.get(e);s&&this.removeNodeFromListAndLookupTable(s);const i=new LRUCacheNode_1.LRUCacheNode(e,n,{entryExpirationTimeInMS:this.entryExpirationTimeInMS,onEntryEvicted:this.onEntryEvicted,onEntryMarkedAsMostRecentlyUsed:this.onEntryMarkedAsMostRecentlyUsed,clone:this.clone,cloneFn:this.cloneFn,...r});return this.setNodeAsHead(i),this.lookupTable.set(e,i),this.enforceSizeLimit(),this}get(e){const n=this.lookupTable.get(e);return n?n.isExpired?(this.removeNodeFromListAndLookupTable(n),null):(this.setNodeAsHead(n),n.value):null}peek(e){const n=this.lookupTable.get(e);return n?n.isExpired?(this.removeNodeFromListAndLookupTable(n),null):n.value:null}delete(e){const n=this.lookupTable.get(e);return n?this.removeNodeFromListAndLookupTable(n):!1}has(e){const n=this.lookupTable.get(e);return n?n.isExpired?(this.removeNodeFromListAndLookupTable(n),!1):!0:!1}clear(){this.head=null,this.tail=null,this.lookupTable.clear()}find(e){let n=this.head;for(;n;){if(n.isExpired){const s=n.next;this.removeNodeFromListAndLookupTable(n),n=s;continue}const r=this.mapNodeToEntry(n);if(e(r))return this.setNodeAsHead(n),r;n=n.next}return null}forEach(e){let n=this.head,r=0;for(;n;){if(n.isExpired){const s=n.next;this.removeNodeFromListAndLookupTable(n),n=s;continue}e(n.value,n.key,r),n=n.next,r++}}*values(){let e=this.head;for(;e;){if(e.isExpired){const n=e.next;this.removeNodeFromListAndLookupTable(e),e=n;continue}yield e.value,e=e.next}}*keys(){let e=this.head;for(;e;){if(e.isExpired){const n=e.next;this.removeNodeFromListAndLookupTable(e),e=n;continue}yield e.key,e=e.next}}*entries(){let e=this.head;for(;e;){if(e.isExpired){const n=e.next;this.removeNodeFromListAndLookupTable(e),e=n;continue}yield this.mapNodeToEntry(e),e=e.next}}*[Symbol.iterator](){let e=this.head;for(;e;){if(e.isExpired){const n=e.next;this.removeNodeFromListAndLookupTable(e),e=n;continue}yield this.mapNodeToEntry(e),e=e.next}}enforceSizeLimit(){let e=this.tail;for(;e!==null&&this.size>this.maxSizeInternal;){const n=e.prev;this.removeNodeFromListAndLookupTable(e),e=n}}mapNodeToEntry({key:e,value:n}){return{key:e,value:n}}setNodeAsHead(e){this.removeNodeFromList(e),this.head?(e.next=this.head,this.head.prev=e,this.head=e):(this.head=e,this.tail=e),e.invokeOnEntryMarkedAsMostRecentlyUsed()}removeNodeFromList(e){e.prev!==null&&(e.prev.next=e.next),e.next!==null&&(e.next.prev=e.prev),this.head===e&&(this.head=e.next),this.tail===e&&(this.tail=e.prev),e.next=null,e.prev=null}removeNodeFromListAndLookupTable(e){return e.invokeOnEvicted(),this.removeNodeFromList(e),this.lookupTable.delete(e.key)}cleanCache(){if(!this.entryExpirationTimeInMS)return;const e=[];for(const n of this.lookupTable.values())n.isExpired&&e.push(n);e.forEach(n=>this.removeNodeFromListAndLookupTable(n))}}LRUCache$1.LRUCache=LRUCache;(function(t){var e=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(r,s,i,o){o===void 0&&(o=i);var a=Object.getOwnPropertyDescriptor(s,i);(!a||("get"in a?!s.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return s[i]}}),Object.defineProperty(r,o,a)}:function(r,s,i,o){o===void 0&&(o=i),r[o]=s[i]}),n=commonjsGlobal&&commonjsGlobal.__exportStar||function(r,s){for(var i in r)i!=="default"&&!Object.prototype.hasOwnProperty.call(s,i)&&e(s,r,i)};Object.defineProperty(t,"__esModule",{value:!0}),n(LRUCache$1,t)})(dist);var lib={};(function(t){/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(t,"__esModule",{value:!0}),t.bytes=t.stringToBytes=t.str=t.bytesToString=t.hex=t.utf8=t.bech32m=t.bech32=t.base58check=t.base58xmr=t.base58xrp=t.base58flickr=t.base58=t.base64url=t.base64=t.base32crockford=t.base32hex=t.base32=t.base16=t.utils=t.assertNumber=void 0;function e(E){if(!Number.isSafeInteger(E))throw new Error(`Wrong integer: ${E}`)}t.assertNumber=e;function n(...E){const k=(y,b)=>A=>y(b(A)),T=Array.from(E).reverse().reduce((y,b)=>y?k(y,b.encode):b.encode,void 0),P=E.reduce((y,b)=>y?k(y,b.decode):b.decode,void 0);return{encode:T,decode:P}}function r(E){return{encode:k=>{if(!Array.isArray(k)||k.length&&typeof k[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return k.map(T=>{if(e(T),T<0||T>=E.length)throw new Error(`Digit index outside alphabet: ${T} (alphabet: ${E.length})`);return E[T]})},decode:k=>{if(!Array.isArray(k)||k.length&&typeof k[0]!="string")throw new Error("alphabet.decode input should be array of strings");return k.map(T=>{if(typeof T!="string")throw new Error(`alphabet.decode: not string element=${T}`);const P=E.indexOf(T);if(P===-1)throw new Error(`Unknown letter: "${T}". Allowed: ${E}`);return P})}}}function s(E=""){if(typeof E!="string")throw new Error("join separator should be string");return{encode:k=>{if(!Array.isArray(k)||k.length&&typeof k[0]!="string")throw new Error("join.encode input should be array of strings");for(let T of k)if(typeof T!="string")throw new Error(`join.encode: non-string input=${T}`);return k.join(E)},decode:k=>{if(typeof k!="string")throw new Error("join.decode input should be string");return k.split(E)}}}function i(E,k="="){if(e(E),typeof k!="string")throw new Error("padding chr should be string");return{encode(T){if(!Array.isArray(T)||T.length&&typeof T[0]!="string")throw new Error("padding.encode input should be array of strings");for(let P of T)if(typeof P!="string")throw new Error(`padding.encode: non-string input=${P}`);for(;T.length*E%8;)T.push(k);return T},decode(T){if(!Array.isArray(T)||T.length&&typeof T[0]!="string")throw new Error("padding.encode input should be array of strings");for(let y of T)if(typeof y!="string")throw new Error(`padding.decode: non-string input=${y}`);let P=T.length;if(P*E%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;P>0&&T[P-1]===k;P--)if(!((P-1)*E%8))throw new Error("Invalid padding: string has too much padding");return T.slice(0,P)}}}function o(E){if(typeof E!="function")throw new Error("normalize fn should be function");return{encode:k=>k,decode:k=>E(k)}}function a(E,k,T){if(k<2)throw new Error(`convertRadix: wrong from=${k}, base cannot be less than 2`);if(T<2)throw new Error(`convertRadix: wrong to=${T}, base cannot be less than 2`);if(!Array.isArray(E))throw new Error("convertRadix: data should be array");if(!E.length)return[];let P=0;const y=[],b=Array.from(E);for(b.forEach(A=>{if(e(A),A<0||A>=k)throw new Error(`Wrong integer: ${A}`)});;){let A=0,U=!0;for(let C=P;C<b.length;C++){const D=b[C],F=k*A+D;if(!Number.isSafeInteger(F)||k*A/k!==A||F-D!==k*A)throw new Error("convertRadix: carry overflow");if(A=F%T,b[C]=Math.floor(F/T),!Number.isSafeInteger(b[C])||b[C]*T+A!==F)throw new Error("convertRadix: carry overflow");if(U)b[C]?U=!1:P=C;else continue}if(y.push(A),U)break}for(let A=0;A<E.length-1&&E[A]===0;A++)y.push(0);return y.reverse()}const c=(E,k)=>k?c(k,E%k):E,l=(E,k)=>E+(k-c(E,k));function h(E,k,T,P){if(!Array.isArray(E))throw new Error("convertRadix2: data should be array");if(k<=0||k>32)throw new Error(`convertRadix2: wrong from=${k}`);if(T<=0||T>32)throw new Error(`convertRadix2: wrong to=${T}`);if(l(k,T)>32)throw new Error(`convertRadix2: carry overflow from=${k} to=${T} carryBits=${l(k,T)}`);let y=0,b=0;const A=2**T-1,U=[];for(const C of E){if(e(C),C>=2**k)throw new Error(`convertRadix2: invalid data word=${C} from=${k}`);if(y=y<<k|C,b+k>32)throw new Error(`convertRadix2: carry overflow pos=${b} from=${k}`);for(b+=k;b>=T;b-=T)U.push((y>>b-T&A)>>>0);y&=2**b-1}if(y=y<<T-b&A,!P&&b>=k)throw new Error("Excess padding");if(!P&&y)throw new Error(`Non-zero padding: ${y}`);return P&&b>0&&U.push(y>>>0),U}function u(E){return e(E),{encode:k=>{if(!(k instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return a(Array.from(k),2**8,E)},decode:k=>{if(!Array.isArray(k)||k.length&&typeof k[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(a(k,E,2**8))}}}function p(E,k=!1){if(e(E),E<=0||E>32)throw new Error("radix2: bits should be in (0..32]");if(l(8,E)>32||l(E,8)>32)throw new Error("radix2: carry overflow");return{encode:T=>{if(!(T instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return h(Array.from(T),8,E,!k)},decode:T=>{if(!Array.isArray(T)||T.length&&typeof T[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(h(T,E,8,k))}}}function g(E){if(typeof E!="function")throw new Error("unsafeWrapper fn should be function");return function(...k){try{return E.apply(null,k)}catch{}}}function m(E,k){if(e(E),typeof k!="function")throw new Error("checksum fn should be function");return{encode(T){if(!(T instanceof Uint8Array))throw new Error("checksum.encode: input should be Uint8Array");const P=k(T).slice(0,E),y=new Uint8Array(T.length+E);return y.set(T),y.set(P,T.length),y},decode(T){if(!(T instanceof Uint8Array))throw new Error("checksum.decode: input should be Uint8Array");const P=T.slice(0,-E),y=k(P).slice(0,E),b=T.slice(-E);for(let A=0;A<E;A++)if(y[A]!==b[A])throw new Error("Invalid checksum");return P}}}t.utils={alphabet:r,chain:n,checksum:m,radix:u,radix2:p,join:s,padding:i},t.base16=n(p(4),r("0123456789ABCDEF"),s("")),t.base32=n(p(5),r("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),i(5),s("")),t.base32hex=n(p(5),r("0123456789ABCDEFGHIJKLMNOPQRSTUV"),i(5),s("")),t.base32crockford=n(p(5),r("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),s(""),o(E=>E.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),t.base64=n(p(6),r("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),i(6),s("")),t.base64url=n(p(6),r("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),i(6),s(""));const d=E=>n(u(58),r(E),s(""));t.base58=d("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),t.base58flickr=d("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),t.base58xrp=d("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const w=[0,2,3,5,6,7,9,10,11];t.base58xmr={encode(E){let k="";for(let T=0;T<E.length;T+=8){const P=E.subarray(T,T+8);k+=t.base58.encode(P).padStart(w[P.length],"1")}return k},decode(E){let k=[];for(let T=0;T<E.length;T+=11){const P=E.slice(T,T+11),y=w.indexOf(P.length),b=t.base58.decode(P);for(let A=0;A<b.length-y;A++)if(b[A]!==0)throw new Error("base58xmr: wrong padding");k=k.concat(Array.from(b.slice(b.length-y)))}return Uint8Array.from(k)}};const $=E=>n(m(4,k=>E(E(k))),t.base58);t.base58check=$;const _=n(r("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),s("")),x=[996825010,642813549,513874426,1027748829,705979059];function I(E){const k=E>>25;let T=(E&33554431)<<5;for(let P=0;P<x.length;P++)(k>>P&1)===1&&(T^=x[P]);return T}function R(E,k,T=1){const P=E.length;let y=1;for(let b=0;b<P;b++){const A=E.charCodeAt(b);if(A<33||A>126)throw new Error(`Invalid prefix (${E})`);y=I(y)^A>>5}y=I(y);for(let b=0;b<P;b++)y=I(y)^E.charCodeAt(b)&31;for(let b of k)y=I(y)^b;for(let b=0;b<6;b++)y=I(y);return y^=T,_.encode(h([y%2**30],30,5,!1))}function v(E){const k=E==="bech32"?1:734539939,T=p(5),P=T.decode,y=T.encode,b=g(P);function A(F,O,K=90){if(typeof F!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof F}`);if(!Array.isArray(O)||O.length&&typeof O[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof O}`);const M=F.length+7+O.length;if(K!==!1&&M>K)throw new TypeError(`Length ${M} exceeds limit ${K}`);return F=F.toLowerCase(),`${F}1${_.encode(O)}${R(F,O,k)}`}function U(F,O=90){if(typeof F!="string")throw new Error(`bech32.decode input should be string, not ${typeof F}`);if(F.length<8||O!==!1&&F.length>O)throw new TypeError(`Wrong string length: ${F.length} (${F}). Expected (8..${O})`);const K=F.toLowerCase();if(F!==K&&F!==F.toUpperCase())throw new Error("String must be lowercase or uppercase");F=K;const M=F.lastIndexOf("1");if(M===0||M===-1)throw new Error('Letter "1" must be present between prefix and data only');const z=F.slice(0,M),V=F.slice(M+1);if(V.length<6)throw new Error("Data must be at least 6 characters long");const q=_.decode(V).slice(0,-6),G=R(z,q,k);if(!V.endsWith(G))throw new Error(`Invalid checksum in ${F}: expected "${G}"`);return{prefix:z,words:q}}const C=g(U);function D(F){const{prefix:O,words:K}=U(F,!1);return{prefix:O,words:K,bytes:P(K)}}return{encode:A,decode:U,decodeToBytes:D,decodeUnsafe:C,fromWords:P,fromWordsUnsafe:b,toWords:y}}t.bech32=v("bech32"),t.bech32m=v("bech32m"),t.utf8={encode:E=>new TextDecoder().decode(E),decode:E=>new TextEncoder().encode(E)},t.hex=n(p(4),r("0123456789abcdef"),s(""),o(E=>{if(typeof E!="string"||E.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof E} with length ${E.length}`);return E.toLowerCase()}));const B={utf8:t.utf8,hex:t.hex,base16:t.base16,base32:t.base32,base64:t.base64,base64url:t.base64url,base58:t.base58,base58xmr:t.base58xmr},S=`Invalid encoding type. Available types: ${Object.keys(B).join(", ")}`,H=(E,k)=>{if(typeof E!="string"||!B.hasOwnProperty(E))throw new TypeError(S);if(!(k instanceof Uint8Array))throw new TypeError("bytesToString() expects Uint8Array");return B[E].encode(k)};t.bytesToString=H,t.str=t.bytesToString;const L=(E,k)=>{if(!B.hasOwnProperty(E))throw new TypeError(S);if(typeof k!="string")throw new TypeError("stringToBytes() expects string");return B[E].decode(k)};t.stringToBytes=L,t.bytes=t.stringToBytes})(lib);BigInt(1e3),BigInt(1e6),BigInt(1e9),BigInt(1e12);BigInt("2100000000000000000");BigInt(1e11);const TAGCODES={payment_hash:1,payment_secret:16,description:13,payee:19,description_hash:23,expiry:6,min_final_cltv_expiry:24,fallback_address:9,route_hint:3,feature_bits:5,metadata:27};for(let t=0,e=Object.keys(TAGCODES);t<e.length;t++)e[t],TAGCODES[e[t]].toString();function getTopRelaysForAuthors(t,e){const n=new Map;return e.forEach(s=>{const i=getWriteRelaysFor(t,s);i&&i.forEach(o=>{const a=n.get(o)||0;n.set(o,a+1)})}),Array.from(n.entries()).sort((s,i)=>i[1]-s[1]).map(s=>s[0])}function getWriteRelaysFor(t,e){var n;if(t.outboxTracker)return(n=t.outboxTracker.data.get(e))==null?void 0:n.writeRelays}function getAllRelaysForAllPubkeys(t,e){const n=new Map,r=new Set;return e.forEach(s=>{const i=getWriteRelaysFor(t,s);i&&i.size>0?(i.forEach(o=>{const a=n.get(o)||new Set;a.add(s),n.set(o,a)}),n.set(s,i)):r.add(s)}),{pubkeysToRelays:n,authorsMissingRelays:r}}function getRelaysForFilterWithAuthors(t,e,n,r=2){const s=new Map,{pubkeysToRelays:i,authorsMissingRelays:o}=getAllRelaysForAllPubkeys(t,e),a=getTopRelaysForAuthors(t,e),c=(l,h)=>{const u=s.get(h)||[];u.push(l),s.set(h,u)};for(const[l,h]of i.entries()){let u=r;const p=n.connectedRelays();for(const g of p)h.has(g.url)&&(c(l,g.url),u--);for(const g of h)s.has(g)&&(c(l,g),u--);if(!(u<=0))for(const g of a){if(u<=0)break;h.has(g)&&(c(l,g),u--)}}for(const l of o)n.permanentAndConnectedRelays().forEach(h=>{const u=s.get(h.url)||[];u.push(l),s.set(h.url,u)});return s}async function runWithTimeout(t,e,n){return e?new Promise((r,s)=>{const i=setTimeout(()=>{s(new Error(n||`Timed out after ${e}ms`))},e);t().then(r,s).finally(()=>clearTimeout(i))}):t()}var NDKRelayConnectivity=class{constructor(t){N(this,"ndkRelay");N(this,"_status");N(this,"relay");N(this,"timeoutMs");N(this,"connectedAt");N(this,"_connectionStats",{attempts:0,success:0,durations:[]});N(this,"debug");N(this,"reconnectTimeout");N(this,"updateConnectionStats",{connected:()=>{this._connectionStats.success++,this._connectionStats.connectedAt=Date.now()},disconnected:()=>{this._connectionStats.connectedAt&&(this._connectionStats.durations.push(Date.now()-this._connectionStats.connectedAt),this._connectionStats.durations.length>100&&this._connectionStats.durations.shift()),this._connectionStats.connectedAt=void 0},attempt:()=>{this._connectionStats.attempts++}});this.ndkRelay=t,this._status=3,this.relay=relayInit(this.ndkRelay.url),this.debug=this.ndkRelay.debug.extend("connectivity"),this.relay.on("notice",e=>this.handleNotice(e))}async connect(t){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0),t??(t=this.timeoutMs),!this.timeoutMs&&t&&(this.timeoutMs=t);const e=()=>{this.updateConnectionStats.connected(),this._status=1,this.ndkRelay.emit("connect"),this.ndkRelay.emit("ready")},n=()=>{this.updateConnectionStats.disconnected(),this._status===1&&(this._status=3,this.handleReconnection()),this.ndkRelay.emit("disconnect")},r=async s=>{this.debug("Relay requested authentication",{havePolicy:!!this.ndkRelay.authPolicy}),this.ndkRelay.authPolicy?this._status!==7&&(this._status=7,await this.ndkRelay.authPolicy(this.ndkRelay,s),this._status===7&&(this.debug("Authentication policy finished"),this._status=1,this.ndkRelay.emit("authed"))):await this.ndkRelay.emit("auth",s)};try{this.updateConnectionStats.attempt(),this._status===3?this._status=0:this._status=4,this.relay.off("connect",e),this.relay.off("disconnect",n),this.relay.on("connect",e),this.relay.on("disconnect",n),this.relay.on("auth",r),await runWithTimeout(this.relay.connect,t,"Timed out while connecting")}catch(s){throw this._status=3,this.handleReconnection(),s}}disconnect(){this._status=2,this.relay.close()}get status(){return this._status}isAvailable(){return this._status===1}isFlapping(){const t=this._connectionStats.durations;if(t.length%3!==0)return!1;const n=t.reduce((o,a)=>o+a,0)/t.length,r=t.map(o=>Math.pow(o-n,2)).reduce((o,a)=>o+a,0)/t.length;return Math.sqrt(r)<1e3}async handleNotice(t){(t.includes("oo many")||t.includes("aximum"))&&(this.disconnect(),setTimeout(()=>this.connect(),2e3),this.debug(this.relay.url,"Relay complaining?",t)),this.ndkRelay.emit("notice",this.relay,t)}handleReconnection(t=0){if(this.reconnectTimeout)return;if(this.debug("Attempting to reconnect",{attempt:t}),this.isFlapping()){this.ndkRelay.emit("flapping",this,this._connectionStats),this._status=5;return}const e=this.connectedAt?Math.max(0,6e4-(Date.now()-this.connectedAt)):5e3*(this._connectionStats.attempts+1);this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=void 0,this._status=4,this.connect().then(()=>{this.debug("Reconnected")}).catch(n=>{t<5?setTimeout(()=>{this.handleReconnection(t+1)},1e3*(t+1)^2.5):this.debug("Reconnect failed after 5 attempts")})},e),this.debug("Reconnecting in",e),this._connectionStats.nextReconnectAt=Date.now()+e}get connectionStats(){return this._connectionStats}},NDKRelayPublisher=class{constructor(t){N(this,"ndkRelay");this.ndkRelay=t}async publish(t,e=2500){const n=()=>new Promise((a,c)=>{try{this.publishEvent(t,e).then(l=>a(l)).catch(l=>c(l))}catch(l){c(l)}}),r=new Promise((a,c)=>{setTimeout(()=>c(new Error("Timeout")),e)}),s=()=>{n().then(a=>i(a)).catch(a=>o(a))};let i,o;return this.ndkRelay.status===1?Promise.race([n(),r]):Promise.race([new Promise((a,c)=>{i=a,o=c,this.ndkRelay.once("connect",s)}),r]).finally(()=>{this.ndkRelay.removeListener("connect",s)})}async publishEvent(t,e){const n=await t.toNostrEvent(),r=this.ndkRelay.connectivity.relay.publish(n);let s;const i=new Promise((a,c)=>{r.then(()=>{clearTimeout(s),this.ndkRelay.emit("published",t),a(!0)}).catch(l=>{clearTimeout(s),this.ndkRelay.debug("Publish failed",l,t.id),this.ndkRelay.emit("publish:failed",t,l),c(l)})});if(!e||t.isEphemeral())return i;const o=new Promise((a,c)=>{s=setTimeout(()=>{this.ndkRelay.debug("Publish timed out",t.rawEvent()),this.ndkRelay.emit("publish:failed",t,"Timeout"),c(new Error("Publish operation timed out"))},e)});return Promise.race([i,o])}async auth(t){return this.ndkRelay.connectivity.relay.auth(t.rawEvent())}};function calculateGroupableId(t,e){const n=[];for(const s of t){if(s.since||s.until)return null;const o=Object.keys(s||{}).sort().join("-");n.push(o)}let r=e?"+":"";return r+=n.join("|"),r}function mergeFilters(t){const e={};return t.forEach(n=>{Object.entries(n).forEach(([r,s])=>{Array.isArray(s)?e[r]===void 0?e[r]=[...s]:e[r]=Array.from(new Set([...e[r],...s])):e[r]=s})}),e}var MAX_SUBID_LENGTH=20;function queryFullyFilled(t){return!!(filterIncludesIds(t.filter)&&resultHasAllRequestedIds(t))}function compareFilter(t,e){if(Object.keys(t).length!==Object.keys(e).length)return!1;for(const[n,r]of Object.entries(t)){const s=e[n];if(!s)return!1;if(Array.isArray(r)&&Array.isArray(s)){const i=r;for(const o of s){const a=o;if(!i.includes(a))return!1}}else if(s!==r)return!1}return!0}function filterIncludesIds(t){return!!t.ids}function resultHasAllRequestedIds(t){const e=t.filter.ids;return!!e&&e.length===t.eventFirstSeen.size}function generateSubId(t,e){var a;const n=t.map(c=>c.subId).filter(Boolean),r=[],s=new Set,i=new Set;if(n.length>0)r.push(Array.from(new Set(n)).join(","));else{for(const c of e)for(const l of Object.keys(c))l==="kinds"?(a=c.kinds)==null||a.forEach(h=>i.add(h)):s.add(l);i.size>0&&r.push("kinds:"+Array.from(i).join(",")),s.size>0&&r.push(Array.from(s).join(","))}let o=r.join("-");return o.length>MAX_SUBID_LENGTH&&(o=o.substring(0,MAX_SUBID_LENGTH)),o+="-"+Math.floor(Math.random()*999).toString(),o}function filterFromId(t){let e;if(t.match(NIP33_A_REGEX)){const[n,r,s]=t.split(":"),i={authors:[r],kinds:[parseInt(n)]};return s&&(i["#d"]=[s]),i}if(t.match(BECH32_REGEX))try{switch(e=nip19_exports.decode(t),e.type){case"nevent":return{ids:[e.data.id]};case"note":return{ids:[e.data]};case"naddr":return{authors:[e.data.pubkey],"#d":[e.data.identifier],kinds:[e.data.kind]}}}catch(n){console.error("Error decoding",t,n)}return{ids:[t]}}function isNip33AValue(t){return t.match(NIP33_A_REGEX)!==null}var NIP33_A_REGEX=/^(\d+):([0-9A-Fa-f]+)(?::(.*))?$/,BECH32_REGEX=/^n(event|ote|profile|pub|addr)1[\d\w]+$/;function relaysFromBech32(t){try{const e=nip19_exports.decode(t);if(["naddr","nevent"].includes(e==null?void 0:e.type)){const n=e.data;if(n!=null&&n.relays)return n.relays.map(r=>new NDKRelay(r))}}catch{}return[]}var NDKGroupedSubscriptions=class extends lib$1.EventEmitter{constructor(e,n){super();N(this,"subscriptions");N(this,"req");N(this,"debug");this.subscriptions=e,this.debug=n||this.subscriptions[0].subscription.debug.extend("grouped");for(const r of e)this.handleSubscriptionClosure(r)}addSubscription(e){this.subscriptions.push(e),this.handleSubscriptionClosure(e)}eventReceived(e){for(const n of this.subscriptions)n.eventReceived(e)}eoseReceived(e){Array.from(this.subscriptions).forEach(async r=>{r.subscription.eoseReceived(e)})}handleSubscriptionClosure(e){e.subscription.on("close",()=>{const n=this.subscriptions.findIndex(r=>r.subscription===e.subscription);this.subscriptions.splice(n,1),this.subscriptions.length<=0&&this.emit("close")})}map(e){return this.subscriptions.map(e)}[Symbol.iterator](){let e=0;const n=this.subscriptions;return{next(){return e<n.length?{value:n[e++],done:!1}:{value:null,done:!0}}}}},NDKSubscriptionFilters=class{constructor(t,e,n){N(this,"subscription");N(this,"filters",[]);N(this,"ndkRelay");this.subscription=t,this.filters=e,this.ndkRelay=n}eventReceived(t){if(!this.eventMatchesLocalFilter(t))return;const e=new NDKEvent(void 0,t);e.relay=this.ndkRelay,this.subscription.eventReceived(e,this.ndkRelay,!1)}eventMatchesLocalFilter(t){return this.filters.some(e=>matchFilter(e,t))}};function findMatchingActiveSubscriptions(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length&&compareFilter(t[n],e[n]);n++)return t[n]}var NDKRelaySubscriptions=class{constructor(t){N(this,"ndkRelay");N(this,"delayedItems",new Map);N(this,"delayedTimers",new Map);N(this,"activeSubscriptions",new Map);N(this,"activeSubscriptionsByGroupId",new Map);N(this,"executionTimeoutsByGroupId",new Map);N(this,"debug");N(this,"groupingDebug");N(this,"conn");this.ndkRelay=t,this.conn=t.connectivity,this.debug=t.debug.extend("subscriptions"),this.groupingDebug=t.debug.extend("grouping")}subscribe(t,e){const n=calculateGroupableId(e,t.closeOnEose),r=new NDKSubscriptionFilters(t,e,this.ndkRelay);if(!n||!t.isGroupable()){this.executeSubscriptions(n,new NDKGroupedSubscriptions([r]),e);return}const i=this.activeSubscriptionsByGroupId.get(n);if(i&&findMatchingActiveSubscriptions(i.filters,e)){const l=this.activeSubscriptions.get(i.sub);l==null||l.addSubscription(new NDKSubscriptionFilters(t,e,this.ndkRelay));return}let o=this.delayedItems.get(n);o?o.addSubscription(r):(o=new NDKGroupedSubscriptions([r]),this.delayedItems.set(n,o),o.once("close",()=>{this.delayedItems.get(n)&&this.delayedItems.delete(n)}));let a=this.executionTimeoutsByGroupId.get(n);(!a||t.opts.groupableDelayType==="at-most")&&(a=setTimeout(()=>{this.executeGroup(n,t)},t.opts.groupableDelay),this.executionTimeoutsByGroupId.set(n,a)),this.delayedTimers.has(n)?this.delayedTimers.get(n).push(a):this.delayedTimers.set(n,[a])}executeGroup(t,e){const n=this.delayedItems.get(t);this.delayedItems.delete(t);const r=this.delayedTimers.get(t);if(this.delayedTimers.delete(t),r)for(const s of r)clearTimeout(s);if(n){const s=n.subscriptions[0].filters.length,i=[];for(let o=0;o<s;o++){const a=n.map(c=>c.filters[o]);i.push(mergeFilters(a))}this.executeSubscriptions(t,n,i)}}executeSubscriptionsWhenConnected(t,e,n){const r=()=>{this.executeSubscriptionsConnected(t,e,n)};this.ndkRelay.once("ready",r),e.once("close",()=>{this.ndkRelay.removeListener("ready",r)})}executeSubscriptions(t,e,n){this.conn.isAvailable()?this.executeSubscriptionsConnected(t,e,n):this.executeSubscriptionsWhenConnected(t,e,n)}executeSubscriptionsConnected(t,e,n){const r=[];for(const{subscription:a}of e)r.push(a);const s=generateSubId(r,n);e.req=n;const i={id:s};i.skipVerification=!0;const o=this.conn.relay.sub(n,i);return this.activeSubscriptions.set(o,e),t&&this.activeSubscriptionsByGroupId.set(t,{filters:n,sub:o}),o.on("event",a=>{const c=this.activeSubscriptions.get(o);c==null||c.eventReceived(a)}),o.on("eose",()=>{const a=this.activeSubscriptions.get(o);a==null||a.eoseReceived(this.ndkRelay)}),e.once("close",()=>{o.unsub(),this.activeSubscriptions.delete(o),t&&this.activeSubscriptionsByGroupId.delete(t)}),this.executeSubscriptionsWhenConnected(t,e,n),o}executedFilters(){const t=new Map;for(const[,e]of this.activeSubscriptions)t.set(e.req,e.map(n=>n.subscription));return t}},NDKRelay=class extends lib$1.EventEmitter{constructor(e,n){super();N(this,"url");N(this,"scores");N(this,"connectivity");N(this,"subs");N(this,"publisher");N(this,"authPolicy");N(this,"validationRatio");N(this,"validatedEventCount",0);N(this,"skippedEventCount",0);N(this,"trusted",!1);N(this,"complaining",!1);N(this,"debug");this.url=e,this.scores=new Map,this.debug=debug6(`ndk:relay:${e}`),this.connectivity=new NDKRelayConnectivity(this),this.subs=new NDKRelaySubscriptions(this),this.publisher=new NDKRelayPublisher(this),this.authPolicy=n,this.validationRatio=void 0}get status(){return this.connectivity.status}get connectionStats(){return this.connectivity.connectionStats}async connect(e){return this.connectivity.connect(e)}disconnect(){this.status!==3&&this.connectivity.disconnect()}subscribe(e,n){this.subs.subscribe(e,n)}async publish(e,n=2500){return this.publisher.publish(e,n)}async auth(e){return this.publisher.auth(e)}scoreSlowerEvent(e){}tagReference(e){const n=["r",this.url];return e&&n.push(e),n}referenceTags(){return[["r",this.url]]}activeSubscriptions(){return this.subs.executedFilters()}addValidatedEvent(){this.validatedEventCount++}addSkippedEvent(){this.skippedEventCount++}getValidationRatio(){return this.skippedEventCount===0?1:this.validatedEventCount/(this.validatedEventCount+this.skippedEventCount)}shouldValidateEvent(){return this.trusted?!1:this.validationRatio===void 0?!0:this.getValidationRatio()<this.validationRatio}},PublishError=class extends Error{constructor(e,n){super(e);N(this,"errors");this.errors=n}get relayErrors(){const e=[];for(const[n,r]of this.errors)e.push(`${n.url}: ${r}`);return e.join(`
`)}},NDKRelaySet=class se{constructor(e,n){N(this,"relays");N(this,"debug");N(this,"ndk");this.relays=e,this.ndk=n,this.debug=n.debug.extend("relayset")}addRelay(e){this.relays.add(e)}static fromRelayUrls(e,n){const r=new Set;for(const s of e){const i=n.pool.relays.get(s);if(i)r.add(i);else{const o=new NDKRelay(s);n.pool.useTemporaryRelay(o),r.add(o)}}return new se(new Set(r),n)}async publish(e,n){const r=new Set,s=new Map,i=e.isEphemeral(),o=Array.from(this.relays).map(a=>new Promise(c=>{a.publish(e,n).then(l=>{r.add(a),c()}).catch(l=>{i||(s.set(a,l),this.debug("error publishing to relay",{relay:a.url,err:l})),c()})}));if(await Promise.all(o),r.size===0&&!i)throw new PublishError("No relay was able to receive the event",s);return r}get size(){return this.relays.size}};function calculateRelaySetFromEvent(t,e){var r;const n=new Set;return(r=t.pool)==null||r.permanentAndConnectedRelays().forEach(s=>n.add(s)),new NDKRelaySet(n,t)}function calculateRelaySetsFromFilter(t,e,n){const r=new Map,s=new Set;if(e.forEach(i=>{i.authors&&i.authors.forEach(o=>s.add(o))}),s.size>0){const i=getRelaysForFilterWithAuthors(t,Array.from(s),n);for(const o of i.keys())r.set(o,[]);for(const o of e)if(o.authors)for(const[a,c]of i.entries()){const l=o.authors.filter(h=>c.includes(h));r.set(a,[...r.get(a),{...o,authors:l}])}else for(const a of i.keys())r.set(a,[...r.get(a),o])}else n.permanentAndConnectedRelays().forEach(i=>{r.set(i.url,e)});return r}function calculateRelaySetsFromFilters(t,e,n){return calculateRelaySetsFromFilter(t,e,n)}function mergeTags(t,e){const n=new Map,r=o=>o.join(","),s=(o,a)=>o.every((c,l)=>c===a[l]),i=o=>{for(let[a,c]of n)if(s(c,o)||s(o,c)){o.length>=c.length&&n.set(a,o);return}n.set(r(o),o)};return t.concat(e).forEach(i),Array.from(n.values())}async function generateContentTags(t,e=[]){const n=/(@|nostr:)(npub|nprofile|note|nevent|naddr)[a-zA-Z0-9]+/g,r=new RegExp(`(?<=\\s|^)(#[^\\s!@#$%^&*()=+.\\/,\\[{\\]};:'"?><]+)`,"g");let s=[];const i=o=>{e.find(a=>["q",o[0]].includes(a[0])&&a[1]===o[1])||e.push(o)};return t=t.replace(n,o=>{try{const a=o.split(/(@|nostr:)/)[2],{type:c,data:l}=nip19_exports.decode(a);let h;switch(c){case"npub":h=["p",l];break;case"nprofile":h=["p",l.pubkey];break;case"note":s.push(new Promise(async u=>{i(["e",l,await maybeGetEventRelayUrl(a),"mention"]),u()}));break;case"nevent":s.push(new Promise(async u=>{let{id:p,relays:g,author:m}=l;(!g||g.length===0)&&(g=[await maybeGetEventRelayUrl(a)]),i(["e",p,g[0],"mention"]),m&&i(["p",m]),u()}));break;case"naddr":s.push(new Promise(async u=>{const p=[l.kind,l.pubkey,l.identifier].join(":");let g=l.relays??[];g.length===0&&(g=[await maybeGetEventRelayUrl(a)]),i(["a",p,g[0],"mention"]),i(["p",l.pubkey]),u()}));break;default:return o}return h&&i(h),`nostr:${a}`}catch{return o}}),await Promise.all(s),t=t.replace(r,(o,a)=>{const c=["t",a];return e.find(l=>l[0]===c[0]&&l[1]===c[1])||e.push(c),o}),{content:t,tags:e}}async function maybeGetEventRelayUrl(t){return""}function isReplaceable(){if(this.kind===void 0)throw new Error("Kind not set");return[0,3].includes(this.kind)||this.kind>=1e4&&this.kind<2e4||this.kind>=3e4&&this.kind<4e4}function isEphemeral(){if(this.kind===void 0)throw new Error("Kind not set");return this.kind>=2e4&&this.kind<3e4}function isParamReplaceable(){if(this.kind===void 0)throw new Error("Kind not set");return this.kind>=3e4&&this.kind<4e4}async function encrypt(t,e){if(!this.ndk)throw new Error("No NDK instance found!");if(e||(await this.ndk.assertSigner(),e=this.ndk.signer),!t){const n=this.getMatchingTags("p");if(n.length!==1)throw new Error("No recipient could be determined and no explicit recipient was provided");t=this.ndk.getUser({pubkey:n[0][1]})}this.content=await(e==null?void 0:e.encrypt(t,this.content))}async function decrypt(t,e){if(!this.ndk)throw new Error("No NDK instance found!");e||(await this.ndk.assertSigner(),e=this.ndk.signer),t||(t=this.author),this.content=await(e==null?void 0:e.decrypt(t,this.content))}function encode(){let t=[];return this.onRelays.length>0?t=this.onRelays.map(e=>e.url):this.relay&&(t=[this.relay.url]),this.isParamReplaceable()?nip19_exports.naddrEncode({kind:this.kind,pubkey:this.pubkey,identifier:this.replaceableDTag(),relays:t}):t.length>0?nip19_exports.neventEncode({id:this.tagId(),relays:t,author:this.pubkey}):nip19_exports.noteEncode(this.tagId())}async function repost(t=!0,e){if(!e&&t){if(!this.ndk)throw new Error("No NDK instance found");this.ndk.assertSigner(),e=this.ndk.signer}const n=new NDKEvent(this.ndk,{kind:getKind(this),content:""});return n.tag(this),n.kind===16?n.tags.push(["k",`${this.kind}`]):n.content=JSON.stringify(this.rawEvent()),e&&await n.sign(e),t&&await n.publish(),n}function getKind(t){return t.kind===1?6:16}function eventHasETagMarkers(t){return t.getMatchingTags("e").some(e=>e[3])}function getRootTag(t,e){e??(e=t.tagType());let n=t.tags.find(r=>r[3]==="root");if(!n){if(eventHasETagMarkers(t))return;const r=t.getMatchingTags(e);if(r.length<3)return r[0]}return n}function getReplyTag(t,e){e??(e=t.tagType());let n=t.tags.find(r=>r[3]==="reply");if(n||(n=t.tags.find(r=>r[3]==="root")),!n){if(eventHasETagMarkers(t))return;const r=t.getMatchingTags(e);if(r.length===1)return r[0];if(r.length===2)return r[1]}}async function fetchTaggedEvent(t,e){if(!this.ndk)throw new Error("NDK instance not found");const n=this.getMatchingTags(t,e);if(n.length===0)return;const[r,s,i]=n[0];return await this.ndk.fetchEvent(s,{},void 0)}async function fetchRootEvent(){if(!this.ndk)throw new Error("NDK instance not found");const t=getRootTag(this);if(t)return this.ndk.fetchEventFromTag(t)}async function fetchReplyEvent(){if(!this.ndk)throw new Error("NDK instance not found");const t=getReplyTag(this);if(t)return this.ndk.fetchEventFromTag(t)}function serialize(t=!1,e=!1){const n=[0,this.pubkey,this.created_at,this.kind,this.tags,this.content];return t&&n.push(this.sig),e&&n.push(this.id),JSON.stringify(n)}function deserialize(t){const e=JSON.parse(t),n={pubkey:e[1],created_at:e[2],kind:e[3],tags:e[4],content:e[5]};return e.length===7&&(n.sig=e[6]),e.length===8&&(n.id=e[7]),n}var worker,processingQueue={};function signatureVerificationInit(t){worker=t,worker.onmessage=e=>{const[n,r]=e.data,s=processingQueue[n];if(!s){console.error("No record found for event",n);return}delete processingQueue[n];for(const i of s.resolves)i(r)}}async function verifySignatureAsync(t,e){return new Promise(r=>{const s=t.serialize();let i=!1;processingQueue[t.id]||(processingQueue[t.id]={event:t,resolves:[]},i=!0),processingQueue[t.id].resolves.push(r),i&&worker.postMessage({serialized:s,id:t.id,sig:t.sig,pubkey:t.pubkey})})}var PUBKEY_REGEX=/^[a-f0-9]{64}$/;function validate(){if(typeof this.kind!="number"||typeof this.content!="string"||typeof this.created_at!="number"||typeof this.pubkey!="string"||!this.pubkey.match(PUBKEY_REGEX)||!Array.isArray(this.tags))return!1;for(let t=0;t<this.tags.length;t++){const e=this.tags[t];if(!Array.isArray(e))return!1;for(let n=0;n<e.length;n++)if(typeof e[n]=="object")return!1}return!0}var verifiedEvents=new dist.LRUCache({maxSize:1e3,entryExpirationTimeInMS:6e4});function verifySignature(t){var n;if(typeof this.signatureVerified=="boolean")return this.signatureVerified;const e=verifiedEvents.get(this.id);if(e!==null)return this.signatureVerified=e;try{if((n=this.ndk)!=null&&n.asyncSigVerification)verifySignatureAsync(this,t).then(r=>{t&&(this.signatureVerified=r,verifiedEvents.set(this.id,r)),r||this.ndk.emit("event:invalid-sig",this)});else{const r=sha256(new TextEncoder().encode(this.serialize())),s=schnorr.verify(this.sig,r,this.pubkey);return verifiedEvents.set(this.id,s),this.signatureVerified=s}}catch(r){return console.error("Error verifying signature",this.rawEvent(),r),this.signatureVerified=!1}}function getEventHash(){const t=sha256(new TextEncoder().encode(this.serialize()));return bytesToHex$1(t)}var debug2=debug6("ndk:zap"),DEFAULT_RELAYS=["wss://nos.lol","wss://relay.nostr.band","wss://relay.f7z.io","wss://relay.damus.io","wss://nostr.mom","wss://no.str.cr"],NDKZap=class ie extends lib$1.EventEmitter{constructor(n){var r;super();N(this,"ndk");N(this,"zappedEvent");N(this,"zappedUser");N(this,"fetch",fetch);this.ndk=n.ndk,this.zappedEvent=n.zappedEvent,this.fetch=n._fetch||fetch,this.zappedUser=n.zappedUser||this.ndk.getUser({pubkey:(r=this.zappedEvent)==null?void 0:r.pubkey})}static async getZapperPubkey(n,r){const s=n.getUser({pubkey:r}),o=await new ie({ndk:n,zappedUser:s}).getZapSpec();return o==null?void 0:o.nostrPubkey}async getZapSpec(){if(!this.zappedUser)throw new Error("No user to zap was provided");return this.zappedUser.getZapConfiguration(this.ndk)}async getZapSpecWithoutCache(){let n,r,s,i;if(this.zappedUser&&(this.zappedUser.profile||await this.zappedUser.fetchProfile({groupable:!1}),i=this.zappedUser.profile,n=(this.zappedUser.profile||{}).lud06,r=(this.zappedUser.profile||{}).lud16),r&&!r.startsWith("LNURL")){const[o,a]=r.split("@");s=`https://${a}/.well-known/lnurlp/${o}`}else if(n){const{words:o}=bech32.decode(n,1e3),a=bech32.fromWords(o);s=new TextDecoder("utf-8").decode(a)}if(!s)throw debug2("No zap endpoint found",i,{lud06:n,lud16:r}),new Error("No zap endpoint found");try{const a=await(this.fetch||this.ndk.httpFetch)(s);if(a.status!==200){const c=await a.text();throw new Error(`Unable to fetch zap endpoint ${s}: ${c}`)}return await a.json()}catch(o){throw new Error(`Unable to fetch zap endpoint ${s}: ${o}`)}}async getZapEndpoint(){const n=await this.getZapSpec();if(!n)return;let r;return n!=null&&n.allowsNostr&&(n!=null&&n.nostrPubkey||n!=null&&n.nostrPubkey)&&(r=n.callback),r}async createZapRequest(n,r,s,i,o){const a=await this.generateZapRequest(n,r,s,i);if(!a)return null;const{event:c,zapEndpoint:l}=a;if(!c)throw new Error("No zap request event found");await c.sign(o);let h;try{debug2(`Getting invoice for zap request: ${l}`),h=await this.getInvoice(c,n,l)}catch(u){throw new Error("Failed to get invoice: "+u)}return h}async getInvoice(n,r,s){debug2(`Fetching invoice from ${s}?`+new URLSearchParams({amount:r.toString(),nostr:encodeURIComponent(JSON.stringify(n.rawEvent()))}));const i=new URL(s);i.searchParams.append("amount",r.toString()),i.searchParams.append("nostr",JSON.stringify(n.rawEvent())),debug2(`Fetching invoice from ${i.toString()}`);const o=await fetch(i.toString());if(debug2(`Got response from zap endpoint: ${s}`,{status:o.status}),o.status!==200){debug2(`Received non-200 status from zap endpoint: ${s}`,{status:o.status,amount:r,nostr:JSON.stringify(n.rawEvent())});const c=await o.text();throw new Error(`Unable to fetch zap endpoint ${s}: ${c}`)}return(await o.json()).pr}async generateZapRequest(n,r,s,i,o){const a=await this.getZapEndpoint();if(!a)throw new Error("No zap endpoint found");if(!this.zappedEvent&&!this.zappedUser)throw new Error("No zapped event or user found");const c=nip57_exports.makeZapRequest({profile:this.zappedUser.pubkey,event:null,amount:n,comment:r||"",relays:i??this.relays()});if(this.zappedEvent){const u=this.zappedEvent.referenceTags().filter(p=>p[0]!=="p");c.tags.push(...u)}c.tags.push(["lnurl",a]);const l=new NDKEvent(this.ndk,c);return s&&(l.tags=l.tags.concat(s)),{event:l,zapEndpoint:a}}relays(){var r,s;let n=[];return(s=(r=this.ndk)==null?void 0:r.pool)!=null&&s.relays&&(n=this.ndk.pool.urls()),n.length||(n=DEFAULT_RELAYS),n}},NDKEvent=class ne extends lib$1.EventEmitter{constructor(n,r){super();N(this,"ndk");N(this,"created_at");N(this,"content","");N(this,"tags",[]);N(this,"kind");N(this,"id","");N(this,"sig");N(this,"pubkey","");N(this,"signatureVerified");N(this,"_author");N(this,"relay");N(this,"onRelays",[]);N(this,"serialize",serialize.bind(this));N(this,"getEventHash",getEventHash.bind(this));N(this,"validate",validate.bind(this));N(this,"verifySignature",verifySignature.bind(this));N(this,"isReplaceable",isReplaceable.bind(this));N(this,"isEphemeral",isEphemeral.bind(this));N(this,"isParamReplaceable",isParamReplaceable.bind(this));N(this,"encode",encode.bind(this));N(this,"encrypt",encrypt.bind(this));N(this,"decrypt",decrypt.bind(this));N(this,"fetchTaggedEvent",fetchTaggedEvent.bind(this));N(this,"fetchRootEvent",fetchRootEvent.bind(this));N(this,"fetchReplyEvent",fetchReplyEvent.bind(this));N(this,"repost",repost.bind(this));this.ndk=n,this.created_at=r==null?void 0:r.created_at,this.content=(r==null?void 0:r.content)||"",this.tags=(r==null?void 0:r.tags)||[],this.id=(r==null?void 0:r.id)||"",this.sig=r==null?void 0:r.sig,this.pubkey=(r==null?void 0:r.pubkey)||"",this.kind=r==null?void 0:r.kind}static deserialize(n,r){return new ne(n,deserialize(r))}rawEvent(){return{created_at:this.created_at,content:this.content,tags:this.tags,kind:this.kind,pubkey:this.pubkey,id:this.id,sig:this.sig}}set author(n){this.pubkey=n.pubkey,this._author=void 0}get author(){if(this._author)return this._author;if(!this.ndk)throw new Error("No NDK instance found");const n=this.ndk.getUser({pubkey:this.pubkey});return this._author=n,n}tag(n,r,s,i){let o=[];if(n.fetchProfile!==void 0){i??(i="p");const c=[i,n.pubkey];r&&c.push("",r),o.push(c)}else if(n instanceof ne){const c=n;s??(s=(c==null?void 0:c.pubkey)===this.pubkey),o=c.referenceTags(r,s,i);for(const l of c.getMatchingTags("p"))l[1]!==this.pubkey&&(this.tags.find(h=>h[0]==="p"&&h[1]===l[1])||this.tags.push(["p",l[1]]))}else if(Array.isArray(n))o=[n];else throw new Error("Invalid argument",n);this.tags=mergeTags(this.tags,o)}async toNostrEvent(n){var o,a;if(!n&&this.pubkey===""){const c=await((a=(o=this.ndk)==null?void 0:o.signer)==null?void 0:a.user());this.pubkey=(c==null?void 0:c.pubkey)||""}(!this.created_at||this.isReplaceable())&&(this.created_at=Math.floor(Date.now()/1e3));const r=this.rawEvent(),{content:s,tags:i}=await this.generateTags();r.content=s||"",r.tags=i;try{this.id=this.getEventHash()}catch{}return this.id&&(r.id=this.id),this.sig&&(r.sig=this.sig),r}getMatchingTags(n,r){return this.tags.filter(s=>s[0]===n).filter(s=>!r||s[3]===r)}tagValue(n){const r=this.getMatchingTags(n);if(r.length!==0)return r[0][1]}get alt(){return this.tagValue("alt")}set alt(n){this.removeTag("alt"),n&&this.tags.push(["alt",n])}get dTag(){return this.tagValue("d")}set dTag(n){this.removeTag("d"),n&&this.tags.push(["d",n])}removeTag(n){this.tags=this.tags.filter(r=>r[0]!==n)}async sign(n){var s;n?this.author=await n.user():((s=this.ndk)==null||s.assertSigner(),n=this.ndk.signer);const r=await this.toNostrEvent();return this.sig=await n.sign(r),this.sig}async publish(n,r){var i;if(this.sig||await this.sign(),!this.ndk)throw new Error("NDKEvent must be associated with an NDK instance to publish");n||(n=this.ndk.devWriteRelaySet||calculateRelaySetFromEvent(this.ndk)),this.ndk.debug(`publish to ${n.size} relays`,this.rawEvent()),this.kind===5&&((i=this.ndk.cacheAdapter)!=null&&i.deleteEvent)&&this.ndk.cacheAdapter.deleteEvent(this);const s=await n.publish(this,r);return this.onRelays=Array.from(s),s}async generateTags(){var i,o;let n=[];const r=await generateContentTags(this.content,this.tags),s=r.content;if(n=r.tags,this.kind&&this.isParamReplaceable()&&!this.getMatchingTags("d")[0]){const c=this.tagValue("title");let h=[...Array(c?6:16)].map(()=>Math.random().toString(36)[2]).join("");c&&c.length>0&&(h=c.replace(/[^a-z0-9]+/gi,"-").replace(/^-|-$/g,"")+"-"+h),n.push(["d",h])}if(((i=this.ndk)!=null&&i.clientName||(o=this.ndk)!=null&&o.clientNip89)&&!this.tagValue("client")){const a=["client",this.ndk.clientName??""];this.ndk.clientNip89&&a.push(this.ndk.clientNip89),n.push(a)}return{content:s||"",tags:n}}muted(){var i,o;const n=(i=this.ndk)==null?void 0:i.mutedIds.get(this.pubkey);if(n&&n==="p")return"author";const r=this.tagReference(),s=(o=this.ndk)==null?void 0:o.mutedIds.get(r[1]);return s&&s===r[0]?"event":null}replaceableDTag(){if(this.kind&&this.kind>=3e4&&this.kind<=4e4){const n=this.getMatchingTags("d")[0];return n?n[1]:""}throw new Error("Event is not a parameterized replaceable event")}deduplicationKey(){return this.kind===0||this.kind===3||this.kind&&this.kind>=1e4&&this.kind<2e4?`${this.kind}:${this.pubkey}`:this.tagId()}tagId(){return this.isParamReplaceable()?this.tagAddress():this.id}tagAddress(){if(!this.isParamReplaceable())throw new Error("This must only be called on replaceable events");const n=this.replaceableDTag();return`${this.kind}:${this.pubkey}:${n}`}tagType(){return this.isParamReplaceable()?"a":"e"}tagReference(n){let r;return this.isParamReplaceable()?r=["a",this.tagAddress()]:r=["e",this.tagId()],this.relay?r.push(this.relay.url):r.push(""),n&&r.push(n),r}referenceTags(n,r,s){var o;let i=[];return this.isParamReplaceable()?i=[[s??"a",this.tagAddress()],[s??"e",this.id]]:i=[[s??"e",this.id]],(o=this.relay)!=null&&o.url?i=i.map(a=>{var c;return a.push((c=this.relay)==null?void 0:c.url),a}):n&&(i=i.map(a=>(a.push(""),a))),n&&i.forEach(a=>a.push(n)),r||i.push(...this.author.referenceTags()),i}filter(){return this.isParamReplaceable()?{"#a":[this.tagId()]}:{"#e":[this.tagId()]}}async zap(n,r,s,i,o){if(!this.ndk)throw new Error("No NDK instance found");o||this.ndk.assertSigner();const a=new NDKZap({ndk:this.ndk,zappedEvent:this,zappedUser:i}),c=Array.from(this.ndk.pool.relays.keys());return await a.createZapRequest(n,r,s,c,o)}async delete(n,r=!0){if(!this.ndk)throw new Error("No NDK instance found");this.ndk.assertSigner();const s=new ne(this.ndk,{kind:5,content:n||""});return s.tag(this),r&&await s.publish(),s}async react(n,r=!0){if(!this.ndk)throw new Error("No NDK instance found");this.ndk.assertSigner();const s=new ne(this.ndk,{kind:7,content:n});return s.tag(this),r?await s.publish():await s.sign(),s}get isValid(){return this.validate()}},defaultOpts={closeOnEose:!1,cacheUsage:"CACHE_FIRST",groupable:!0,groupableDelay:100,groupableDelayType:"at-most"},NDKSubscription=class extends lib$1.EventEmitter{constructor(e,n,r,s,i){super();N(this,"subId");N(this,"filters");N(this,"opts");N(this,"pool");N(this,"skipVerification",!1);N(this,"skipValidation",!1);N(this,"relayFilters");N(this,"relaySet");N(this,"ndk");N(this,"debug");N(this,"eoseDebug");N(this,"eventFirstSeen",new Map);N(this,"eosesSeen",new Set);N(this,"eventsPerRelay",new Map);N(this,"lastEventReceivedAt");N(this,"internalId");N(this,"closeOnEose");N(this,"eoseTimeout");if(this.ndk=e,this.pool=(r==null?void 0:r.pool)||e.pool,this.opts={...defaultOpts,...r||{}},this.filters=n instanceof Array?n:[n],this.subId=i||(r==null?void 0:r.subId),this.internalId=Math.random().toString(36).substring(7),this.relaySet=s,this.debug=e.debug.extend(`subscription[${(r==null?void 0:r.subId)??this.internalId}]`),this.eoseDebug=this.debug.extend("eose"),this.skipVerification=(r==null?void 0:r.skipVerification)||!1,this.skipValidation=(r==null?void 0:r.skipValidation)||!1,this.closeOnEose=(r==null?void 0:r.closeOnEose)||!1,this.opts.cacheUsage==="ONLY_CACHE"&&!this.opts.closeOnEose)throw new Error("Cannot use cache-only options with a persistent subscription")}get filter(){return this.filters[0]}isGroupable(){var e;return((e=this.opts)==null?void 0:e.groupable)||!1}shouldQueryCache(){var e;return((e=this.opts)==null?void 0:e.cacheUsage)!=="ONLY_RELAY"}shouldQueryRelays(){var e;return((e=this.opts)==null?void 0:e.cacheUsage)!=="ONLY_CACHE"}shouldWaitForCache(){var e;return this.opts.closeOnEose&&!!((e=this.ndk.cacheAdapter)!=null&&e.locking)&&this.opts.cacheUsage!=="PARALLEL"}async start(){let e;if(this.shouldQueryCache()&&(e=this.startWithCache(),this.shouldWaitForCache()&&(await e,queryFullyFilled(this)))){this.emit("eose",this);return}this.shouldQueryRelays()?this.startWithRelays():this.emit("eose",this)}stop(){this.emit("close",this),this.removeAllListeners()}hasAuthorsFilter(){return this.filters.some(e=>{var n;return(n=e.authors)==null?void 0:n.length})}async startWithCache(){var e;if((e=this.ndk.cacheAdapter)!=null&&e.query){const n=this.ndk.cacheAdapter.query(this);this.ndk.cacheAdapter.locking&&await n}}startWithRelays(){if(!this.relaySet)this.relayFilters=calculateRelaySetsFromFilters(this.ndk,this.filters,this.pool);else{this.relayFilters=new Map;for(const e of this.relaySet.relays)this.relayFilters.set(e.url,this.filters)}if(!this.relayFilters||this.relayFilters.size===0){this.debug("No relays to subscribe to",this.pool.relays.size);return}for(const[e,n]of this.relayFilters)this.pool.getRelay(e,!0,!0,n).subscribe(this,n)}eventReceived(e,n,r=!1){if(n&&(e.relay??(e.relay=n),e.onRelays.push(n)),n||(n=e.relay),e.ndk??(e.ndk=this.ndk),this.eventFirstSeen.has(e.id)){const i=Date.now()-(this.eventFirstSeen.get(e.id)||0);n&&n.scoreSlowerEvent(i),this.emit("event:dup",e,n,i,this);return}if(!r){if(!this.skipValidation&&!e.isValid){this.debug("Event failed validation",e.rawEvent());return}if(!this.skipVerification&&!e.verifySignature(!0)&&!this.ndk.asyncSigVerification){this.debug("Event failed signature validation",e);return}}if(!r&&n){let i=this.eventsPerRelay.get(n);i||(i=new Set,this.eventsPerRelay.set(n,i)),i.add(e.id),this.ndk.cacheAdapter&&this.ndk.cacheAdapter.setEvent(e,this.filters,n),this.eventFirstSeen.set(e.id,Date.now())}else this.eventFirstSeen.set(e.id,0);this.emit("event",e,n,this),this.lastEventReceivedAt=Date.now()}eoseReceived(e){var i,o,a;this.eosesSeen.add(e);let n=this.lastEventReceivedAt?Date.now()-this.lastEventReceivedAt:void 0;const r=this.eosesSeen.size===((i=this.relayFilters)==null?void 0:i.size);if(queryFullyFilled(this))this.emit("eose"),(o=this.opts)!=null&&o.closeOnEose&&this.stop();else if(r)this.emit("eose"),this.eoseDebug("All EOSEs seen"),(a=this.opts)!=null&&a.closeOnEose&&this.stop();else{let c=1e3;const l=this.eosesSeen.size/this.relayFilters.size;if(this.eosesSeen.size>=2&&l>=.5){c=c*(1-l),this.eoseTimeout&&clearTimeout(this.eoseTimeout);const h=()=>{var u;n=this.lastEventReceivedAt?Date.now()-this.lastEventReceivedAt:void 0,n!==void 0&&n<20?this.eoseTimeout=setTimeout(h,c):(this.emit("eose"),(u=this.opts)!=null&&u.closeOnEose&&this.stop())};this.eoseTimeout=setTimeout(h,c)}}}};async function follows(t,e,n=3){var s,i;if(!this.ndk)throw new Error("NDK not set");const r=await this.ndk.fetchEvent({kinds:[n],authors:[this.pubkey]},t||{groupable:!1});if(r){const o=new Set;return r.tags.forEach(a=>{a[0]==="p"&&o.add(a[1])}),e&&((i=(s=this.ndk)==null?void 0:s.outboxTracker)==null||i.trackUsers(Array.from(o))),[...o].reduce((a,c)=>{const l=new NDKUser({pubkey:c});return l.ndk=this.ndk,a.add(l),a},new Set)}return new Set}function profileFromEvent(t){const e={};let n;try{n=JSON.parse(t.content)}catch(r){throw new Error(`Failed to parse profile event: ${r}`)}return Object.keys(n).forEach(r=>{switch(r){case"name":e.name=n.name;break;case"display_name":e.displayName=n.display_name;break;case"image":case"picture":e.image=n.picture||n.image;break;case"banner":e.banner=n.banner;break;case"bio":e.bio=n.bio;break;case"nip05":e.nip05=n.nip05;break;case"lud06":e.lud06=n.lud06;break;case"lud16":e.lud16=n.lud16;break;case"about":e.about=n.about;break;case"zapService":e.zapService=n.zapService;break;case"website":e.website=n.website;break;default:e[r]=n[r];break}}),e}function serializeProfile(t){const e={};for(const[n,r]of Object.entries(t))switch(n){case"username":case"name":e.name=r;break;case"displayName":e.display_name=r;break;case"image":case"picture":e.picture=r;break;case"bio":case"about":e.about=r;break;default:e[n]=r;break}return JSON.stringify(e)}var NIP05_REGEX=/^(?:([\w.+-]+)@)?([\w.-]+)$/;async function getNip05For(t,e,n=fetch,r={}){return await t.queuesNip05.add({id:e,func:async()=>{if(t.cacheAdapter&&t.cacheAdapter.loadNip05){const c=await t.cacheAdapter.loadNip05(e);if(c!=="missing"){if(c){const l=new NDKUser({pubkey:c.pubkey,relayUrls:c.relays,nip46Urls:c.nip46});return l.ndk=t,l}else if(r.cache!=="no-cache")return null}}const s=e.match(NIP05_REGEX);if(!s)return null;const[i,o="_",a]=s;try{const c=await n(`https://${a}/.well-known/nostr.json?name=${o}`,r),{names:l,relays:h,nip46:u}=parseNIP05Result(await c.json()),p=l[o.toLowerCase()];let g=null;return p&&(g={pubkey:p,relays:h==null?void 0:h[p],nip46:u==null?void 0:u[p]}),t!=null&&t.cacheAdapter&&t.cacheAdapter.saveNip05&&t.cacheAdapter.saveNip05(e,g),g}catch(c){return t!=null&&t.cacheAdapter&&t.cacheAdapter.saveNip05&&(t==null||t.cacheAdapter.saveNip05(e,null)),console.error("Failed to fetch NIP05 for",e,c),null}}})}function parseNIP05Result(t){const e={names:{}};for(const[n,r]of Object.entries(t.names))typeof n=="string"&&typeof r=="string"&&(e.names[n.toLowerCase()]=r);if(t.relays){e.relays={};for(const[n,r]of Object.entries(t.relays))typeof n=="string"&&Array.isArray(r)&&(e.relays[n]=r.filter(s=>typeof s=="string"))}if(t.nip46){e.nip46={};for(const[n,r]of Object.entries(t.nip46))typeof n=="string"&&Array.isArray(r)&&(e.nip46[n]=r.filter(s=>typeof s=="string"))}return e}var NDKUser=class oe{constructor(e){N(this,"ndk");N(this,"profile");N(this,"_npub");N(this,"_pubkey");N(this,"relayUrls",[]);N(this,"nip46Urls",[]);N(this,"follows",follows.bind(this));e.npub&&(this._npub=e.npub),e.hexpubkey&&(this._pubkey=e.hexpubkey),e.pubkey&&(this._pubkey=e.pubkey),e.relayUrls&&(this.relayUrls=e.relayUrls),e.nip46Urls&&(this.nip46Urls=e.nip46Urls)}get npub(){if(!this._npub){if(!this._pubkey)throw new Error("pubkey not set");this._npub=nip19_exports.npubEncode(this.pubkey)}return this._npub}set npub(e){this._npub=e}get hexpubkey(){return this.pubkey}set hexpubkey(e){this._pubkey=e}get pubkey(){if(!this._pubkey){if(!this._npub)throw new Error("npub not set");this._pubkey=nip19_exports.decode(this.npub).data}return this._pubkey}set pubkey(e){this._pubkey=e}async getZapConfiguration(e){if(e??(e=this.ndk),!e)throw new Error("No NDK instance found");const n=async()=>{var i,o,a,c;if((o=(i=this.ndk)==null?void 0:i.cacheAdapter)!=null&&o.loadUsersLNURLDoc){const l=await this.ndk.cacheAdapter.loadUsersLNURLDoc(this.pubkey);if(l!=="missing"){if(l===null)return;if(l)return l}}const r=new NDKZap({ndk:e,zappedUser:this});let s;try{s=await r.getZapSpecWithoutCache()}catch{}if((c=(a=this.ndk)==null?void 0:a.cacheAdapter)!=null&&c.saveUsersLNURLDoc&&this.ndk.cacheAdapter.saveUsersLNURLDoc(this.pubkey,s||null),!!s)return s};return await e.queuesZapConfig.add({id:this.pubkey,func:n})}async getZapperPubkey(){const e=await this.getZapConfiguration();return e==null?void 0:e.nostrPubkey}static async fromNip05(e,n,r=!1){if(!n)throw new Error("No NDK instance found");let s={};r&&(s.cache="no-cache");const i=await getNip05For(n,e,n==null?void 0:n.httpFetch,s);if(i){const o=new oe({pubkey:i.pubkey,relayUrls:i.relays,nip46Urls:i.nip46});return o.ndk=n,o}}async fetchProfile(e){if(!this.ndk)throw new Error("NDK not set");this.profile||(this.profile={});let n=null;if(this.ndk.cacheAdapter&&this.ndk.cacheAdapter.fetchProfile&&(e==null?void 0:e.cacheUsage)!=="ONLY_RELAY"){const s=await this.ndk.cacheAdapter.fetchProfile(this.pubkey);if(s)return this.profile=s,s}!e&&this.ndk.cacheAdapter&&this.ndk.cacheAdapter.locking&&(n=await this.ndk.fetchEvents({kinds:[0],authors:[this.pubkey]},{cacheUsage:"ONLY_CACHE",closeOnEose:!0,groupable:!1}),e={cacheUsage:"ONLY_RELAY",closeOnEose:!0,groupable:!0,groupableDelay:250}),(!n||n.size===0)&&(n=await this.ndk.fetchEvents({kinds:[0],authors:[this.pubkey]},e));const r=Array.from(n).sort((s,i)=>s.created_at-i.created_at);return r.length===0?null:(this.profile=profileFromEvent(r[0]),this.profile&&this.ndk.cacheAdapter&&this.ndk.cacheAdapter.saveProfile&&this.ndk.cacheAdapter.saveProfile(this.pubkey,this.profile),this.profile)}tagReference(){return["p",this.pubkey]}referenceTags(e){const n=[["p",this.pubkey]];return e&&n[0].push("",e),n}async publish(){if(!this.ndk)throw new Error("No NDK instance found");if(!this.profile)throw new Error("No profile available");this.ndk.assertSigner(),await new NDKEvent(this.ndk,{kind:0,content:serializeProfile(this.profile)}).publish()}async follow(e,n,r=3){if(!this.ndk)throw new Error("No NDK instance found");if(this.ndk.assertSigner(),n||(n=await this.follows(void 0,void 0,r)),n.has(e))return!1;n.add(e);const s=new NDKEvent(this.ndk,{kind:r});for(const i of n)s.tag(i);return await s.publish(),!0}async unfollow(e,n,r=3){if(!this.ndk)throw new Error("No NDK instance found");this.ndk.assertSigner(),n||(n=await this.follows(void 0,void 0,r));const s=new Set;let i=!1;for(const a of n)a.pubkey!==e.pubkey&&(s.add(a),i=!0);if(!i)return!1;const o=new NDKEvent(this.ndk,{kind:r});for(const a of n)o.tag(a);return await o.publish()}async validateNip05(e){if(!this.ndk)throw new Error("No NDK instance found");const n=await getNip05For(this.ndk,e);return n===null?null:n.pubkey===this.pubkey}async zap(e,n,r,s){if(!this.ndk)throw new Error("No NDK instance found");s||this.ndk.assertSigner();const i=new NDKZap({ndk:this.ndk,zappedUser:this}),o=Array.from(this.ndk.pool.relays.keys());return await i.createZapRequest(e,n,r,o,s)}},NDKList=class ae extends NDKEvent{constructor(n,r){super(n,r);N(this,"_encryptedTags");N(this,"encryptedTagsLength");this.kind??(this.kind=30001)}static from(n){return new ae(n.ndk,n.rawEvent())}get title(){const n=this.tagValue("title")||this.tagValue("name");return this.kind===3&&!n?"Contacts":this.kind===1e4&&!n?"Mute":this.kind===10001&&!n?"Pinned Notes":this.kind===10002&&!n?"Relay Metadata":this.kind===10003&&!n?"Bookmarks":this.kind===10004&&!n?"Communities":this.kind===10005&&!n?"Public Chats":this.kind===10006&&!n?"Blocked Relays":this.kind===10007&&!n?"Search Relays":this.kind===10015&&!n?"Interests":this.kind===10030&&!n?"Emojis":n??this.tagValue("d")}set title(n){if(this.removeTag("title"),this.removeTag("name"),n)this.tags.push(["title",n]);else throw new Error("Title cannot be empty")}get name(){const n=this.tagValue("name");return this.kind===3&&!n?"Contacts":this.kind===1e4&&!n?"Mute":this.kind===10001&&!n?"Pinned Notes":this.kind===10002&&!n?"Relay Metadata":this.kind===10003&&!n?"Bookmarks":this.kind===10004&&!n?"Communities":this.kind===10005&&!n?"Public Chats":this.kind===10006&&!n?"Blocked Relays":this.kind===10007&&!n?"Search Relays":this.kind===10015&&!n?"Interests":this.kind===10030&&!n?"Emojis":n??this.tagValue("d")}set name(n){if(this.removeTag("name"),n)this.tags.push(["title",n]);else throw new Error("Name cannot be empty")}get description(){return this.tagValue("description")}set description(n){n?this.tags.push(["description",n]):this.removeTag("description")}isEncryptedTagsCacheValid(){return!!(this._encryptedTags&&this.encryptedTagsLength===this.content.length)}async encryptedTags(n=!0){if(n&&this.isEncryptedTagsCacheValid())return this._encryptedTags;if(!this.ndk)throw new Error("NDK instance not set");if(!this.ndk.signer)throw new Error("NDK signer not set");const r=await this.ndk.signer.user();try{if(this.content.length>0)try{const s=await this.ndk.signer.decrypt(r,this.content),i=JSON.parse(s);return i&&i[0]?(this.encryptedTagsLength=this.content.length,this._encryptedTags=i):(this.encryptedTagsLength=this.content.length,this._encryptedTags=[])}catch{console.log(`error decrypting ${this.content}`)}}catch{}return[]}validateTag(n){return!0}get items(){return this.tags.filter(n=>!["d","L","l","title","name","description","summary","image","thumb","alt","expiration","subject","client"].includes(n[0]))}async addItem(n,r=void 0,s=!1){if(!this.ndk)throw new Error("NDK instance not set");if(!this.ndk.signer)throw new Error("NDK signer not set");let i;if(n instanceof NDKEvent)i=n.referenceTags();else if(n instanceof NDKUser)i=n.referenceTags();else if(n instanceof NDKRelay)i=n.referenceTags();else if(Array.isArray(n))i=[n];else throw new Error("Invalid object type");if(r&&i[0].push(r),s){const o=await this.ndk.signer.user(),a=await this.encryptedTags();a.push(...i),this._encryptedTags=a,this.encryptedTagsLength=this.content.length,this.content=JSON.stringify(a),await this.encrypt(o)}else this.tags.push(...i);this.created_at=Math.floor(Date.now()/1e3),this.emit("change")}async removeItem(n,r){if(!this.ndk)throw new Error("NDK instance not set");if(!this.ndk.signer)throw new Error("NDK signer not set");if(r){const s=await this.ndk.signer.user(),i=await this.encryptedTags();i.splice(n,1),this._encryptedTags=i,this.encryptedTagsLength=this.content.length,this.content=JSON.stringify(i),await this.encrypt(s)}else this.tags.splice(n,1);return this.created_at=Math.floor(Date.now()/1e3),this.emit("change"),this}filterForItems(){const n=new Set,r=new Map,s=[];for(const i of this.items)if(i[0]==="e"&&i[1])n.add(i[1]);else if(i[0]==="a"&&i[1]){const[o,a,c]=i[1].split(":");if(!o||!a)continue;const l=`${o}:${a}`,h=r.get(l)||[];h.push(c||""),r.set(l,h)}if(n.size>0&&s.push({ids:Array.from(n)}),r.size>0)for(const[i,o]of r.entries()){const[a,c]=i.split(":");s.push({kinds:[parseInt(a)],authors:[c],"#d":o})}return s}},lists_default=NDKList,DATA_URL_DEFAULT_MIME_TYPE="text/plain",DATA_URL_DEFAULT_CHARSET="us-ascii",testParameter=(t,e)=>e.some(n=>n instanceof RegExp?n.test(t):n===t),supportedProtocols=new Set(["https:","http:","file:"]),hasCustomProtocol=t=>{try{const{protocol:e}=new URL(t);return e.endsWith(":")&&!e.includes(".")&&!supportedProtocols.has(e)}catch{return!1}},normalizeDataURL=(t,{stripHash:e})=>{var u;const n=/^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(t);if(!n)throw new Error(`Invalid URL: ${t}`);let{type:r,data:s,hash:i}=n.groups;const o=r.split(";");i=e?"":i;let a=!1;o[o.length-1]==="base64"&&(o.pop(),a=!0);const c=((u=o.shift())==null?void 0:u.toLowerCase())??"",h=[...o.map(p=>{let[g,m=""]=p.split("=").map(d=>d.trim());return g==="charset"&&(m=m.toLowerCase(),m===DATA_URL_DEFAULT_CHARSET)?"":`${g}${m?`=${m}`:""}`}).filter(Boolean)];return a&&h.push("base64"),(h.length>0||c&&c!==DATA_URL_DEFAULT_MIME_TYPE)&&h.unshift(c),`data:${h.join(";")},${a?s.trim():s}${i?`#${i}`:""}`};function normalizeUrl(t,e){if(e={defaultProtocol:"http",normalizeProtocol:!0,forceHttp:!1,forceHttps:!1,stripAuthentication:!0,stripHash:!1,stripTextFragment:!0,stripWWW:!0,removeQueryParameters:[/^utm_\w+/i],removeTrailingSlash:!0,removeSingleSlash:!0,removeDirectoryIndex:!1,removeExplicitPort:!1,sortQueryParameters:!0,...e},typeof e.defaultProtocol=="string"&&!e.defaultProtocol.endsWith(":")&&(e.defaultProtocol=`${e.defaultProtocol}:`),t=t.trim(),/^data:/i.test(t))return normalizeDataURL(t,e);if(hasCustomProtocol(t))return t;const n=t.startsWith("//");!n&&/^\.*\//.test(t)||(t=t.replace(/^(?!(?:\w+:)?\/\/)|^\/\//,e.defaultProtocol));const s=new URL(t);if(e.forceHttp&&e.forceHttps)throw new Error("The `forceHttp` and `forceHttps` options cannot be used together");if(e.forceHttp&&s.protocol==="https:"&&(s.protocol="http:"),e.forceHttps&&s.protocol==="http:"&&(s.protocol="https:"),e.stripAuthentication&&(s.username="",s.password=""),e.stripHash?s.hash="":e.stripTextFragment&&(s.hash=s.hash.replace(/#?:~:text.*?$/i,"")),s.pathname){const o=/\b[a-z][a-z\d+\-.]{1,50}:\/\//g;let a=0,c="";for(;;){const h=o.exec(s.pathname);if(!h)break;const u=h[0],p=h.index,g=s.pathname.slice(a,p);c+=g.replace(/\/{2,}/g,"/"),c+=u,a=p+u.length}const l=s.pathname.slice(a,s.pathname.length);c+=l.replace(/\/{2,}/g,"/"),s.pathname=c}if(s.pathname)try{s.pathname=decodeURI(s.pathname)}catch{}if(e.removeDirectoryIndex===!0&&(e.removeDirectoryIndex=[/^index\.[a-z]+$/]),Array.isArray(e.removeDirectoryIndex)&&e.removeDirectoryIndex.length>0){let o=s.pathname.split("/");const a=o[o.length-1];testParameter(a,e.removeDirectoryIndex)&&(o=o.slice(0,-1),s.pathname=o.slice(1).join("/")+"/")}if(s.hostname&&(s.hostname=s.hostname.replace(/\.$/,""),e.stripWWW&&/^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(s.hostname)&&(s.hostname=s.hostname.replace(/^www\./,""))),Array.isArray(e.removeQueryParameters))for(const o of[...s.searchParams.keys()])testParameter(o,e.removeQueryParameters)&&s.searchParams.delete(o);if(!Array.isArray(e.keepQueryParameters)&&e.removeQueryParameters===!0&&(s.search=""),Array.isArray(e.keepQueryParameters)&&e.keepQueryParameters.length>0)for(const o of[...s.searchParams.keys()])testParameter(o,e.keepQueryParameters)||s.searchParams.delete(o);if(e.sortQueryParameters){s.searchParams.sort();try{s.search=decodeURIComponent(s.search)}catch{}}e.removeTrailingSlash&&(s.pathname=s.pathname.replace(/\/$/,"")),e.removeExplicitPort&&s.port&&(s.port="");const i=t;return t=s.toString(),!e.removeSingleSlash&&s.pathname==="/"&&!i.endsWith("/")&&s.hash===""&&(t=t.replace(/\/$/,"")),(e.removeTrailingSlash||s.pathname==="/")&&s.hash===""&&e.removeSingleSlash&&(t=t.replace(/\/$/,"")),n&&!e.normalizeProtocol&&(t=t.replace(/^http:\/\//,"//")),e.stripProtocol&&(t=t.replace(/^(?:https?:)?\/\//,"")),t}function normalizeRelayUrl(t){let e=normalizeUrl(t,{stripAuthentication:!1,stripWWW:!1,stripHash:!0});return e.endsWith("/")||(e+="/"),e}function normalize(t){const e=new Set;for(const n of t)try{e.add(normalizeRelayUrl(n))}catch{}return Array.from(e)}var READ_MARKER="read",WRITE_MARKER="write",NDKRelayList=class re extends NDKEvent{constructor(e,n){super(e,n),this.kind??(this.kind=10002)}static from(e){return new re(e.ndk,e.rawEvent())}static async forUser(e,n){return(await this.forUsers([e],n)).get(e)}static async forUsers(e,n){var l;const r=n.outboxPool||n.pool,s=new Set;for(const h of r.relays.values())s.add(h);const i=new Map,o=new Map,a=new NDKRelaySet(s,n);if((l=n.cacheAdapter)!=null&&l.locking){const h=await n.fetchEvents({kinds:[3,10002],authors:e},{cacheUsage:"ONLY_CACHE"});for(const u of h)u.kind===10002&&i.set(u.pubkey,re.from(u));for(const u of h)if(u.kind===3){const p=relayListFromKind3(n,u);p&&o.set(u.pubkey,p)}e=e.filter(u=>!i.has(u)&&!o.has(u))}if(e.length===0)return i;await Promise.all([new Promise(async h=>{const u=await n.fetchEvents({kinds:[10002],authors:e},{closeOnEose:!0,pool:r,groupable:!1},a);for(const p of u)i.set(p.pubkey,re.from(p));h()}),new Promise(async h=>{const u=await n.fetchEvents({kinds:[3],authors:e},{closeOnEose:!0,pool:r,groupable:!1},a);for(const p of u){const g=relayListFromKind3(n,p);g&&o.set(p.pubkey,g)}h()})]);const c=new Map;for(const h of e){const u=i.get(h)??o.get(h);u&&c.set(h,u)}return c}get readRelayUrls(){return this.tags.filter(e=>e[0]==="r"||e[0]==="relay").filter(e=>!e[2]||e[2]&&e[2]===READ_MARKER).map(e=>e[1])}set readRelayUrls(e){for(const n of e)this.tags.push(["r",n,READ_MARKER])}get writeRelayUrls(){return this.tags.filter(e=>e[0]==="r"||e[0]==="relay").filter(e=>!e[2]||e[2]&&e[2]===WRITE_MARKER).map(e=>e[1])}set writeRelayUrls(e){for(const n of e)this.tags.push(["r",n,WRITE_MARKER])}get bothRelayUrls(){return this.tags.filter(e=>e[0]==="r"||e[0]==="relay").filter(e=>!e[2]).map(e=>e[1])}set bothRelayUrls(e){for(const n of e)this.tags.push(["r",n])}get relays(){return this.tags.filter(e=>e[0]==="r"||e[0]==="relay").map(e=>e[1])}};function relayListFromKind3(t,e){try{const n=JSON.parse(e.content),r=new NDKRelayList(t),s=new Set,i=new Set;for(let[o,a]of Object.entries(n)){try{o=normalizeRelayUrl(o)}catch{continue}if(!a)s.add(o),i.add(o);else{const c=a;c.write&&i.add(o),c.read&&s.add(o)}}return r.readRelayUrls=Array.from(s),r.writeRelayUrls=Array.from(i),r}catch{}}async function payInvoice(t){return await this.sendReq("pay_invoice",{invoice:t})}var NDKPrivateKeySigner=class ce{constructor(e){N(this,"_user");N(this,"privateKey");e&&(this.privateKey=e,this._user=new NDKUser({pubkey:getPublicKey(this.privateKey)}))}static generate(){const e=generatePrivateKey();return new ce(e)}async blockUntilReady(){if(!this._user)throw new Error("NDKUser not initialized");return this._user}async user(){return await this.blockUntilReady(),this._user}async sign(e){if(!this.privateKey)throw Error("Attempted to sign without a private key");return getSignature(e,this.privateKey)}async encrypt(e,n){if(!this.privateKey)throw Error("Attempted to encrypt without a private key");const r=e.pubkey;return await nip04_exports.encrypt(this.privateKey,r,n)}async decrypt(e,n){if(!this.privateKey)throw Error("Attempted to decrypt without a private key");const r=e.pubkey;return await nip04_exports.decrypt(this.privateKey,r,n)}};async function sendReq(t,e){const n=new NDKEvent(this.ndk,{kind:23194,tags:[["p",this.walletService.pubkey]],content:JSON.stringify({method:t,params:e})});return this.debug("Sending request",n.content),await n.encrypt(this.walletService,this.signer),await n.sign(this.signer),this.debug("Request encrypted and signed"),new Promise(async(r,s)=>{try{const i=n.tagId();if(!i)throw new Error("Failed to get e-tag");const o=c=>{this.off(i,o),this.off("event",o),this.debug("Received response",c);try{const l=JSON.parse(c);l.error&&s(l),r(l)}catch(l){this.debug("Failed to parse response",l),s({result_type:"error",error:{code:"failed_to_parse_response",message:l.message}})}},a=this.ndk.subscribe({kinds:[23195],"#e":[i],limit:1},{groupable:!1,subId:`nwc-${t}`},this.relaySet);a.on("event",async c=>{await c.decrypt(c.author,this.signer),o(c.content),a.stop()}),this.once(i,o),this.once("event",o),this.debug("Sending request to relay",n.rawEvent()),await n.publish(this.relaySet)}catch(i){this.debug("Failed to send request",i,i.relayErrors),s({result_type:"error",error:{code:"failed_to_send_request",message:i.message}})}})}async function getBalance(){return await this.sendReq("get_balance",{})}async function getInfo(){return await this.sendReq("get_info",{})}var NDKNwc=class le extends lib$1.EventEmitter{constructor({ndk:n,pubkey:r,relayUrls:s,secret:i}){super();N(this,"ndk");N(this,"debug");N(this,"walletService");N(this,"relaySet");N(this,"signer");N(this,"active",!1);N(this,"getBalance",getBalance.bind(this));this.ndk=n,this.walletService=n.getUser({pubkey:r}),this.relaySet=new NDKRelaySet(new Set(s.map(o=>n.pool.getRelay(o))),n),this.signer=new NDKPrivateKeySigner(i),this.debug=n.debug.extend("nwc"),this.debug(`Starting with wallet service ${this.walletService.npub}`)}static async fromURI(n,r){const s=new URL(r);if(s.protocol!=="nostr+walletconnect:")throw new Error("Invalid protocol");return new le({ndk:n,pubkey:s.host??s.pathname,relayUrls:s.searchParams.getAll("relay")??[""],secret:s.searchParams.get("secret")??""})}async blockUntilReady(n){const r=await this.signer.user(),s=new Promise((a,c)=>{setTimeout(()=>{c(new Error("Timeout"))},n)}),o=[new Promise(a=>{const c=this.ndk.subscribe({kinds:[23195],"#p":[r.pubkey],limit:1},{groupable:!1,subId:"nwc"},this.relaySet);c.on("event",async l=>{this.debug("received response",l.rawEvent());const h=l.tagValue("e");if(!h){this.debug("Received an event without an e-tag");return}this.debug("received an event",h);try{await l.decrypt(l.author,this.signer),this.emit(h,l.content)}catch(u){this.debug("Failed to decrypt event",u);return}}),c.on("eose",()=>{this.debug("Subscription ready"),this.active=!0,a()}),c.on("close",()=>{this.debug("Subscription closed"),this.active=!1})})];return n&&o.push(s),await Promise.race(o)}async sendReq(n,r){return await sendReq.call(this,n,r)}async payInvoice(n){return await payInvoice.call(this,n)}async getInfo(){return await getInfo.call(this)}};function dedup(t,e){return t.created_at>e.created_at?t:e}var OutboxItem=class{constructor(t){N(this,"type");N(this,"relayUrlScores");N(this,"readRelays");N(this,"writeRelays");this.type=t,this.relayUrlScores=new Map,this.readRelays=new Set,this.writeRelays=new Set}},OutboxTracker=class extends lib$1.EventEmitter{constructor(e){super();N(this,"data");N(this,"ndk");N(this,"debug");this.ndk=e,this.debug=e.debug.extend("outbox-tracker"),this.data=new dist.LRUCache({maxSize:1e5,entryExpirationTimeInMS:2*60*1e3})}trackUsers(e){for(let n=0;n<e.length;n+=400){let s=e.slice(n,n+400).map(i=>getKeyFromItem(i)).filter(i=>!this.data.has(i));if(s.length!==0){for(const i of s)this.data.set(i,new OutboxItem("user"));NDKRelayList.forUsers(s,this.ndk).then(i=>{for(const[o,a]of i){const c=this.data.get(o);if(a){c.readRelays=new Set(normalize(a.readRelayUrls)),c.writeRelays=new Set(normalize(a.writeRelayUrls));for(const l of c.readRelays)this.ndk.pool.blacklistRelayUrls.has(l)&&c.readRelays.delete(l);for(const l of c.writeRelays)this.ndk.pool.blacklistRelayUrls.has(l)&&c.writeRelays.delete(l);this.data.set(o,c)}}})}}}track(e,n){const r=getKeyFromItem(e);n??(n=getTypeFromItem(e));let s=this.data.get(r);return s||(s=new OutboxItem(n),e instanceof NDKUser&&this.trackUsers([e])),s}};function getKeyFromItem(t){return t instanceof NDKUser?t.pubkey:t}function getTypeFromItem(t){return t instanceof NDKUser?"user":"kind"}var NDKPool=class extends lib$1.EventEmitter{constructor(e=[],n=[],r,s){super();N(this,"relays",new Map);N(this,"blacklistRelayUrls");N(this,"debug");N(this,"temporaryRelayTimers",new Map);N(this,"flappingRelays",new Set);N(this,"backoffTimes",new Map);this.debug=s??r.debug.extend("pool");for(const i of e){const o=new NDKRelay(i);this.addRelay(o,!1)}this.blacklistRelayUrls=new Set(n)}useTemporaryRelay(e,n=3e4){const r=this.relays.has(e.url);r||this.addRelay(e);const s=this.temporaryRelayTimers.get(e.url);if(s&&clearTimeout(s),!r||s){const i=setTimeout(()=>{this.removeRelay(e.url)},n);this.temporaryRelayTimers.set(e.url,i)}}addRelay(e,n=!0){var s;const r=e.url;if((s=this.blacklistRelayUrls)!=null&&s.has(r)){this.debug(`Relay ${r} is blacklisted`);return}if(r.includes("/npub1")){this.debug(`Relay ${r} is a filter relay`);return}e.on("notice",async(i,o)=>this.emit("notice",i,o)),e.on("connect",()=>this.handleRelayConnect(r)),e.on("ready",()=>this.handleRelayReady(e)),e.on("disconnect",async()=>this.emit("relay:disconnect",e)),e.on("flapping",()=>this.handleFlapping(e)),e.on("auth",async i=>this.emit("relay:auth",e,i)),e.on("authed",async()=>this.emit("relay:authed",e)),this.relays.set(r,e),n&&(this.emit("relay:connecting",e),e.connect().catch(i=>{this.debug(`Failed to connect to relay ${r}`,i)}))}removeRelay(e){const n=this.relays.get(e);if(n)return n.disconnect(),this.relays.delete(e),this.emit("relay:disconnect",n),!0;const r=this.temporaryRelayTimers.get(e);return r&&(clearTimeout(r),this.temporaryRelayTimers.delete(e)),!1}getRelay(e,n=!0,r=!1,s){let i=this.relays.get(e);return i||(i=new NDKRelay(e),r?this.useTemporaryRelay(i):this.addRelay(i,n)),i}handleRelayConnect(e){this.emit("relay:connect",this.relays.get(e)),this.stats().connected===this.relays.size&&this.emit("connect")}handleRelayReady(e){this.debug(`Relay ${e.url} ready`),this.emit("relay:ready",e)}async connect(e){const n=[];this.debug(`Connecting to ${this.relays.size} relays${e?`, timeout ${e}...`:""}`);for(const r of this.relays.values()){const s=new Promise((i,o)=>(this.emit("relay:connecting",r),r.connect(e).then(i).catch(o)));if(e){const i=new Promise((o,a)=>{setTimeout(()=>a(`Timed out after ${e}ms`),e)});n.push(Promise.race([s,i]).catch(o=>{this.debug(`Failed to connect to relay ${r.url}: ${o??"No reason specified"}`)}))}else n.push(s)}e&&setTimeout(()=>{const r=this.stats().connected===this.relays.size,s=this.stats().connected>0;!r&&s&&this.emit("connect")},e),await Promise.all(n)}checkOnFlappingRelays(){const e=this.flappingRelays.size,n=this.relays.size;if(e/n>=.8)for(const r of this.flappingRelays)this.backoffTimes.set(r,0)}handleFlapping(e){this.debug(`Relay ${e.url} is flapping`);let n=this.backoffTimes.get(e.url)||5e3;n=n*2,this.backoffTimes.set(e.url,n),this.debug(`Backoff time for ${e.url} is ${n}ms`),setTimeout(()=>{this.debug(`Attempting to reconnect to ${e.url}`),this.emit("relay:connecting",e),e.connect(),this.checkOnFlappingRelays()},n),e.disconnect(),this.emit("flapping",e)}size(){return this.relays.size}stats(){const e={total:0,connected:0,disconnected:0,connecting:0};for(const n of this.relays.values())e.total++,n.status===1?e.connected++:n.status===3?e.disconnected++:n.status===0&&e.connecting++;return e}connectedRelays(){return Array.from(this.relays.values()).filter(e=>e.status===1)}permanentAndConnectedRelays(){return Array.from(this.relays.values()).filter(e=>e.status===1||!this.temporaryRelayTimers.has(e.url))}urls(){return Array.from(this.relays.keys())}};function correctRelaySet(t,e){const n=e.connectedRelays();if(!Array.from(t.relays).some(s=>n.map(i=>i.url).includes(s.url)))for(const s of n)t.addRelay(s);if(n.length===0)for(const s of e.relays.values())t.addRelay(s);return t}async function fetchEventFromTag(t,e,n={type:"timeout"}){const r=this.debug.extend("fetch-event-from-tag"),[s,i,o]=t;let a,c=o&&o!==""?this.pool.getRelay(o,!0,!0,[{ids:[i]}]):void 0;const l=new Promise(u=>{this.fetchEvent(i,e,c).then(u)});if(o===""||!o||n.type==="none")return l;let h=new Promise(async u=>{let p=n.relaySet,g=n.timeout??1500,m=new Promise(d=>setTimeout(d,g));if(n.type==="timeout"&&await m,a)u(a);else{r("fallback fetch triggered");let d=await this.fetchEvent(i,e,p);u(d)}});switch(n.type){case"timeout":return Promise.race([l,h]);case"eose":return a=await l,a||h}}var SPEC_PATH="/.well-known/nostr/nip96.json",Nip96=class{constructor(t,e){N(this,"ndk");N(this,"spec");N(this,"url");N(this,"nip98Required",!1);this.url=`https://${t}${SPEC_PATH}`,this.ndk=e}async prepareUpload(t,e="POST"){if(this.validateHttpFetch(),this.spec||await this.fetchSpec(),!this.spec)throw new Error("Failed to fetch NIP96 spec");let n={};return this.nip98Required&&(n={Authorization:await this.generateNip98Header(this.spec.api_url,e,t)}),{url:this.spec.api_url,headers:n}}async xhrUpload(t,e){const n="POST",{url:r,headers:s}=await this.prepareUpload(e,n);t.open(n,r,!0),s.Authorization&&t.setRequestHeader("Authorization",s.Authorization);const i=new FormData;return i.append("file",e),new Promise((o,a)=>{t.onload=function(){t.status>=200&&t.status<300?o(JSON.parse(t.responseText)):a(new Error(t.statusText))},t.onerror=function(){a(new Error("Network Error"))},t.send(i)})}async upload(t){const e="POST",{url:n,headers:r}=await this.prepareUpload(t,e),s=new FormData;s.append("file",t);const i=await this.ndk.httpFetch(this.spec.api_url,{method:e,headers:r,body:s});if(i.status!==200)throw new Error(`Failed to upload file to ${n}`);const o=await i.json();if(o.status!=="success")throw new Error(o.message);return o}validateHttpFetch(){if(!this.ndk)throw new Error("NDK is required to fetch NIP96 spec");if(!this.ndk.httpFetch)throw new Error("NDK must have an httpFetch method to fetch NIP96 spec")}async fetchSpec(){this.validateHttpFetch();const t=await this.ndk.httpFetch(this.url);if(t.status!==200)throw new Error(`Failed to fetch NIP96 spec from ${this.url}`);const e=await t.json();if(!e)throw new Error(`Failed to parse NIP96 spec from ${this.url}`);this.spec=e,this.nip98Required=this.spec.plans.free.is_nip98_required}async generateNip98Header(t,e,n){const r=new NDKEvent(this.ndk,{kind:27235,tags:[["u",t],["method",e]]});if(["POST","PUT","PATCH"].includes(e)){const i=await this.calculateSha256(n);r.tags.push(["payload",i])}return await r.sign(),`Nostr ${btoa(JSON.stringify(r.rawEvent()))}`}async calculateSha256(t){const e=await t.arrayBuffer(),n=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(n)).map(i=>i.toString(16).padStart(2,"0")).join("")}},Queue=class{constructor(t,e){N(this,"queue",[]);N(this,"maxConcurrency");N(this,"processing",new Set);N(this,"promises",new Map);this.maxConcurrency=e}add(t){if(this.promises.has(t.id))return this.promises.get(t.id);const e=new Promise((n,r)=>{this.queue.push({...t,func:()=>t.func().then(s=>(n(s),s),s=>{throw r(s),s})}),this.process()});return this.promises.set(t.id,e),e.finally(()=>{this.promises.delete(t.id),this.processing.delete(t.id)}),e}process(){if(this.processing.size>=this.maxConcurrency||this.queue.length===0)return;const t=this.queue.shift();!t||this.processing.has(t.id)||(this.processing.add(t.id),t.func())}clear(){this.queue=[]}clearProcessing(){this.processing.clear()}clearAll(){this.clear(),this.clearProcessing()}length(){return this.queue.length}},DEFAULT_OUTBOX_RELAYS=["wss://purplepag.es/","wss://profiles.nos.social/"],DEFAULT_BLACKLISTED_RELAYS=["wss://brb.io/","wss://nostr.mutinywallet.com/"],NDK=class extends lib$1.EventEmitter{constructor(e={}){super();N(this,"explicitRelayUrls");N(this,"pool");N(this,"outboxPool");N(this,"_signer");N(this,"_activeUser");N(this,"cacheAdapter");N(this,"debug");N(this,"devWriteRelaySet");N(this,"outboxTracker");N(this,"mutedIds");N(this,"clientName");N(this,"clientNip89");N(this,"queuesZapConfig");N(this,"queuesNip05");N(this,"asyncSigVerification",!1);N(this,"validationRatio",1);N(this,"relayAuthDefaultPolicy");N(this,"httpFetch");N(this,"autoConnectUserRelays",!0);N(this,"autoFetchUserMutelist",!0);N(this,"fetchEventFromTag",fetchEventFromTag.bind(this));this.debug=e.debug||debug6("ndk"),this.explicitRelayUrls=e.explicitRelayUrls||[],this.pool=new NDKPool(e.explicitRelayUrls||[],e.blacklistRelayUrls||DEFAULT_BLACKLISTED_RELAYS,this),this.debug(`Starting with explicit relays: ${JSON.stringify(this.explicitRelayUrls)}`),this.pool.on("relay:auth",async(n,r)=>{this.relayAuthDefaultPolicy&&await this.relayAuthDefaultPolicy(n,r)}),this.autoConnectUserRelays=e.autoConnectUserRelays??!0,this.autoFetchUserMutelist=e.autoFetchUserMutelist??!0,this.clientName=e.clientName,this.clientNip89=e.clientNip89,this.relayAuthDefaultPolicy=e.relayAuthDefaultPolicy,e.enableOutboxModel&&(this.outboxPool=new NDKPool(e.outboxRelayUrls||DEFAULT_OUTBOX_RELAYS,e.blacklistRelayUrls||DEFAULT_BLACKLISTED_RELAYS,this,this.debug.extend("outbox-pool")),this.outboxTracker=new OutboxTracker(this)),this.signer=e.signer,this.cacheAdapter=e.cacheAdapter,this.mutedIds=e.mutedIds||new Map,e.devWriteRelayUrls&&(this.devWriteRelaySet=NDKRelaySet.fromRelayUrls(e.devWriteRelayUrls,this)),this.queuesZapConfig=new Queue("zaps",3),this.queuesNip05=new Queue("nip05",10),this.signatureVerificationWorker=e.signatureVerificationWorker,this.validationRatio=e.validationRatio||1;try{this.httpFetch=fetch}catch{}}set signatureVerificationWorker(e){this.asyncSigVerification=!!e,e&&signatureVerificationInit(e)}addExplicitRelay(e,n,r=!0){let s;return typeof e=="string"?s=new NDKRelay(e,n):s=e,this.pool.addRelay(s,r),this.explicitRelayUrls.push(s.url),s}toJSON(){return{relayCount:this.pool.relays.size}.toString()}get activeUser(){return this._activeUser}set activeUser(e){var r;const n=((r=this._activeUser)==null?void 0:r.pubkey)!==(e==null?void 0:e.pubkey);if(this._activeUser=e,e&&n){const s=async h=>{const u=await NDKRelayList.forUser(h.pubkey,this);if(!u){this.debug("No relay list found for user",{npub:h.npub});return}this.debug("Connecting to user relays",{npub:h.npub,relays:u.relays});for(const p of u.relays){let g=this.pool.relays.get(p);g||(g=new NDKRelay(p),this.pool.addRelay(g))}},i=async h=>{const u=await this.fetchEvent({kinds:[10006],authors:[h.pubkey]});if(u){const p=lists_default.from(u);for(const g of p.items)this.pool.blacklistRelayUrls.add(g[0])}this.debug("Blocked relays",{blockedRelays:u})},o=async h=>{const u=await this.fetchEvent({kinds:[1e4],authors:[h.pubkey]});if(u){const p=lists_default.from(u);for(const g of p.items)this.mutedIds.set(g[1],g[0])}},a=[i];this.autoConnectUserRelays&&a.push(s),this.autoFetchUserMutelist&&a.push(o);const c=async h=>{for(const u of a)await u(h)},l=this.outboxPool||this.pool;l.connectedRelays.length>0?c(e):(this.debug("Waiting for connection to main relays"),l.once("connect",()=>{c(e)}))}else e||(this.mutedIds=new Map)}get signer(){return this._signer}set signer(e){this._signer=e,e&&this.emit("signer:ready",e),e==null||e.user().then(n=>{n.ndk=this,this.activeUser=n})}async connect(e){this._signer&&this.autoConnectUserRelays&&(this.debug("Attempting to connect to user relays specified by signer"),this._signer.relays&&(await this._signer.relays()).forEach(s=>this.pool.addRelay(s)));const n=[this.pool.connect(e)];return this.outboxPool&&n.push(this.outboxPool.connect(e)),this.debug("Connecting to relays",{timeoutMs:e}),Promise.allSettled(n).then(()=>{})}getUser(e){const n=new NDKUser(e);return n.ndk=this,n}async getUserFromNip05(e,n=!1){return NDKUser.fromNip05(e,this,n)}subscribe(e,n,r,s=!0){var o;const i=new NDKSubscription(this,e,n,r);if(r)for(const a of r.relays)this.pool.useTemporaryRelay(a);if(this.outboxPool&&i.hasAuthorsFilter()){const a=i.filters.filter(c=>{var l;return c.authors&&((l=c.authors)==null?void 0:l.length)>0}).map(c=>c.authors).flat();(o=this.outboxTracker)==null||o.trackUsers(a)}return s&&setTimeout(()=>i.start(),0),i}async publish(e,n,r){return this.debug("Deprecated: Use `event.publish()` instead"),e.publish(n,r)}async fetchEvent(e,n,r){let s,i;if(r instanceof NDKRelay?i=new NDKRelaySet(new Set([r]),this):r instanceof NDKRelaySet&&(i=r),!r&&typeof e=="string"&&!isNip33AValue(e)){const o=relaysFromBech32(e);o.length>0&&(i=new NDKRelaySet(new Set(o),this),i=correctRelaySet(i,this.pool))}if(typeof e=="string"?s=filterFromId(e):s=e,!s)throw new Error(`Invalid filter: ${JSON.stringify(e)}`);return new Promise(o=>{let a=null;const c=this.subscribe(s,{...n||{},closeOnEose:!0},i,!1);c.on("event",l=>{l.ndk=this,l.isReplaceable()?(!a||a.created_at<l.created_at)&&(a=l):o(l)}),c.on("eose",()=>{o(a)}),c.start()})}async fetchEvents(e,n,r){return new Promise(s=>{const i=new Map,o=this.subscribe(e,{...n||{},closeOnEose:!0},r,!1),a=c=>{const l=c.deduplicationKey(),h=i.get(l);h&&(c=dedup(h,c)),c.ndk=this,i.set(l,c)};o.on("event",a),o.on("event:dup",a),o.on("eose",()=>{s(new Set(i.values()))}),o.start()})}assertSigner(){if(!this.signer)throw this.emit("signer:required"),new Error("Signer required")}getNip96(e){return new Nip96(e,this)}async nwc(e,n=2e3){const r=await NDKNwc.fromURI(this,e);return n!==!1&&await r.blockUntilReady(n),r}};async function fetchUserProfile(t,e){const n=e.getUser({npub:t});return await n.fetchProfile(),n}const relays=["wss://cache2.primal.net/v1","wss://relay.hodl.ar","wss://relay.current.fyi","wss://nostr.wine","wss://nostr.plebchain.org","wss://purplepag.es","wss://nos.lol","wss://nostr.mom","wss://nostrelay.yeghro.site","wss://relay.damus.io","wss://relay.nostr.bg","wss://relay.snort.social","wss://relay.primal.net","wss://nostr.bitcoiner.social","wss://nostr.mutinywallet.com","wss://relay.current.fyi","wss://brb.io"];function get_each_context(t,e,n){const r=t.slice();return r[15]=e[n],r[17]=n,r}function create_else_block_1(t){let e;return{c(){e=element("div"),e.textContent="Loading data...",attr(e,"class","loader")},m(n,r){insert(n,e,r)},p:noop,d(n){n&&detach(e)}}}function create_if_block_2(t){return{c:noop,m:noop,p:noop,d:noop}}function create_if_block(t){let e,n,r,s,i,o,a,c,l,h,u,p,g,m,d,w,$,_,x,I=t[10].length+"",R,v,B,S,H,L,E,k,T,P=t[9].length+"",y,b,A;function U(K,M){return K[11]<100?create_if_block_1:create_else_block}let C=U(t),D=C(t),F=ensure_array_like(t[9]),O=[];for(let K=0;K<F.length;K+=1)O[K]=create_each_block(get_each_context(t,F,K));return{c(){e=element("div"),n=element("img"),s=text(`
User:
`),i=element("a"),o=text(t[4]),c=text(`
|  Follows: `),l=text(t[0]),h=space(),u=element("br"),p=text(`
Unknown: `),g=text(t[8]),m=text(" | Follow_Back: "),d=text(t[6]),w=text(` |
`),$=element("strong"),$.textContent="👉 Not_Follow_Back",_=text(`
:
`),x=element("span"),R=text(I),v=space(),B=element("br"),S=space(),D.c(),H=space(),L=element("hr"),E=space(),k=element("br"),T=text(`
Results (`),y=text(P),b=text(`)
`),A=element("ul");for(let K=0;K<O.length;K+=1)O[K].c();src_url_equal(n.src,r=t[5])||attr(n,"src",r),attr(n,"width","50"),set_style(n,"border-radius","100%"),attr(n,"alt","user-thumb"),attr(i,"href",a="https://primal.net/p/"+t[2]),attr(x,"title","Actualy counted"),attr(e,"class","user-box")},m(K,M){insert(K,e,M),append(e,n),append(e,s),append(e,i),append(i,o),append(e,c),append(e,l),append(e,h),append(e,u),append(e,p),append(e,g),append(e,m),append(e,d),append(e,w),append(e,$),append(e,_),append(e,x),append(x,R),append(e,v),append(e,B),append(e,S),D.m(e,null),append(e,H),append(e,L),append(e,E),append(e,k),append(e,T),append(e,y),append(e,b),append(e,A);for(let z=0;z<O.length;z+=1)O[z]&&O[z].m(A,null)},p(K,M){if(M&32&&!src_url_equal(n.src,r=K[5])&&attr(n,"src",r),M&16&&set_data(o,K[4]),M&4&&a!==(a="https://primal.net/p/"+K[2])&&attr(i,"href",a),M&1&&set_data(l,K[0]),M&256&&set_data(g,K[8]),M&64&&set_data(d,K[6]),M&1024&&I!==(I=K[10].length+"")&&set_data(R,I),C===(C=U(K))&&D?D.p(K,M):(D.d(1),D=C(K),D&&(D.c(),D.m(e,H))),M&512&&P!==(P=K[9].length+"")&&set_data(y,P),M&512){F=ensure_array_like(K[9]);let z;for(z=0;z<F.length;z+=1){const V=get_each_context(K,F,z);O[z]?O[z].p(V,M):(O[z]=create_each_block(V),O[z].c(),O[z].m(A,null))}for(;z<O.length;z+=1)O[z].d(1);O.length=F.length}},d(K){K&&detach(e),D.d(),destroy_each(O,K)}}}function create_else_block(t){let e;return{c(){e=element("p"),e.innerHTML="<strong>Completed!</strong>"},m(n,r){insert(n,e,r)},p:noop,d(n){n&&detach(e)}}}function create_if_block_1(t){let e,n,r,s,i,o,a,c,l;return{c(){e=element("p"),n=text(`Progress =
`),r=element("strong"),s=text(t[11]),i=text("%"),o=text(`
- `),a=text(t[1]),c=text(" of "),l=text(t[0])},m(h,u){insert(h,e,u),append(e,n),append(e,r),append(r,s),append(r,i),append(e,o),append(e,a),append(e,c),append(e,l)},p(h,u){u&2048&&set_data(s,h[11]),u&2&&set_data(a,h[1]),u&1&&set_data(l,h[0])},d(h){h&&detach(e)}}}function create_each_block(t){let e,n,r=t[17]+1+"",s,i,o,a=t[15].followBack=="0"?"<span>🔴</span>":"<span>🟢</span>",c,l,h=t[15].npub+"",u,p,g;return{c(){e=element("li"),n=text("#"),s=text(r),i=text(" - "),o=new HtmlTag(!1),c=space(),l=element("a"),u=text(h),g=space(),o.a=c,attr(l,"target","_blank noreferrer noopener"),attr(l,"href",p="https://primal.net/p/"+t[15].npub)},m(m,d){insert(m,e,d),append(e,n),append(e,s),append(e,i),o.m(a,e),append(e,c),append(e,l),append(l,u),append(e,g)},p(m,d){d&512&&a!==(a=m[15].followBack=="0"?"<span>🔴</span>":"<span>🟢</span>")&&o.p(a),d&512&&h!==(h=m[15].npub+"")&&set_data(u,h),d&512&&p!==(p="https://primal.net/p/"+m[15].npub)&&attr(l,"href",p)},d(m){m&&detach(e)}}}function create_fragment(t){let e,n,r,s,i,o,a,c,l,h;function u(m,d){return m[5]?create_if_block:m[3]?create_else_block_1:create_if_block_2}let p=u(t),g=p(t);return{c(){e=element("form"),n=element("input"),s=space(),i=element("input"),a=space(),g.c(),c=empty(),n.disabled=r=t[3]&&t[11]<100,attr(n,"type","text"),attr(n,"placeholder","An npub to check"),attr(n,"class","svelte-163zan3"),attr(i,"type","button"),i.disabled=o=!t[2]&&t[11]<100,i.value="Analyze",attr(e,"class","npub-form svelte-163zan3")},m(m,d){insert(m,e,d),append(e,n),set_input_value(n,t[2]),append(e,s),append(e,i),insert(m,a,d),g.m(m,d),insert(m,c,d),l||(h=[listen(n,"input",t[13]),listen(i,"click",t[14])],l=!0)},p(m,[d]){d&2056&&r!==(r=m[3]&&m[11]<100)&&(n.disabled=r),d&4&&n.value!==m[2]&&set_input_value(n,m[2]),d&2052&&o!==(o=!m[2]&&m[11]<100)&&(i.disabled=o),p===(p=u(m))&&g?g.p(m,d):(g.d(1),g=p(m),g&&(g.c(),g.m(c.parentNode,c)))},i:noop,o:noop,d(m){m&&(detach(e),detach(a),detach(c)),g.d(m),l=!1,run_all(h)}}}function instance(t,e,n){let r,s="",i=!1,o="",a="",c=0,l=0,h=0,u=0,p=0,g=[],m=[];async function d(){try{const _=new NDK({explicitRelayUrls:relays});await _.connect();const x=await fetchUserProfile(s,_);if(n(4,o=x.profile.name),n(5,a=x.profile.image),o){const I=await x.follows();n(0,c=I.size);let R,v=0;I.forEach(async B=>{const S=await B.follows();if(g.push({npub:B.npub,followsBack:"-"}),n(9,g),S.size){let H=!1;for(let L of S)if(R=L.npub,L.npub==s){H=!0;break}n(9,g[v].followBack=H?"1":"0",g),H?(n(6,l++,l),n(1,p++,p)):(n(7,h++,h),m.push(B.npub),n(10,m),n(1,p++,p))}else n(8,u++,u),n(1,p++,p);v++})}}catch(_){console.error("Error fetching data:",_)}}function w(){s=this.value,n(2,s)}const $=async()=>{n(3,i=!0),n(4,o=""),n(5,a=""),n(9,g=[]),n(10,m=[]),n(6,l=0),n(7,h=0),n(8,u=0),n(1,p=0),await d()};return t.$$.update=()=>{t.$$.dirty&3&&n(11,r=(p/c*100).toFixed()|0)},[c,p,s,i,o,a,l,h,u,g,m,r,d,w,$]}class App extends SvelteComponent{constructor(e){super(),init(this,e,instance,create_fragment,safe_not_equal,{})}}new App({target:document.getElementById("app")});