nostr-blog-widget 0.2.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see nostr-blog.js.LICENSE.txt */
2
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.NostrBlog=t():e.NostrBlog=t()}(this,()=>(()=>{"use strict";var e,t,n={35(e,t,n){n.d(t,{Bq:()=>c,XX:()=>i,Yr:()=>h,pP:()=>u,ph:()=>s,vs:()=>a,z_:()=>l});var r=n(701);Object.create(null),Object.create(null);const s=e=>(0,r.To)(()=>e()),o="_$DX_DELEGATE";function i(e,t,n,s={}){let o;return(0,r.Hr)(r=>{o=r,t===document?e():h(t,e(),t.firstChild?null:void 0,n)},s.owner),()=>{o(),t.textContent=""}}function a(e,t,n,s){let o;const i=()=>{const t=s?document.createElementNS("http://www.w3.org/1998/Math/MathML","template"):document.createElement("template");return t.innerHTML=e,n?t.content.firstChild.firstChild:s?t.firstChild:t.content.firstChild},a=t?()=>(0,r.vz)(()=>document.importNode(o||(o=i()),!0)):()=>(o||(o=i())).cloneNode(!0);return a.cloneNode=a,a}function l(e,t=window.document){const n=t[o]||(t[o]=new Set);for(let r=0,s=e.length;r<s;r++){const s=e[r];n.has(s)||(n.add(s),t.addEventListener(s,p))}}function c(e,t,n){d(e)||(null==n?e.removeAttribute(t):e.setAttribute(t,n))}function u(e,t,n={}){const r=Object.keys(t||{}),s=Object.keys(n);let o,i;for(o=0,i=s.length;o<i;o++){const r=s[o];r&&"undefined"!==r&&!t[r]&&(f(e,r,!1),delete n[r])}for(o=0,i=r.length;o<i;o++){const s=r[o],i=!!t[s];s&&"undefined"!==s&&n[s]!==i&&i&&(f(e,s,!0),n[s]=i)}return n}function h(e,t,n,s){if(void 0===n||s||(s=[]),"function"!=typeof t)return g(e,t,s,n);(0,r.gb)(r=>g(e,t(),r,n),s)}function d(e){return!!r.sE.context&&!r.sE.done&&(!e||e.isConnected)}function f(e,t,n){const r=t.trim().split(/\s+/);for(let t=0,s=r.length;t<s;t++)e.classList.toggle(r[t],n)}function p(e){if(r.sE.registry&&r.sE.events&&r.sE.events.find(([t,n])=>n===e))return;let t=e.target;const n=`$$${e.type}`,s=e.target,o=e.currentTarget,i=t=>Object.defineProperty(e,"target",{configurable:!0,value:t}),a=()=>{const r=t[n];if(r&&!t.disabled){const s=t[`${n}Data`];if(void 0!==s?r.call(t,s,e):r.call(t,e),e.cancelBubble)return}return t.host&&"string"!=typeof t.host&&!t.host._$host&&t.contains(e.target)&&i(t.host),!0},l=()=>{for(;a()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get:()=>t||document}),r.sE.registry&&!r.sE.done&&(r.sE.done=_$HY.done=!0),e.composedPath){const n=e.composedPath();i(n[0]);for(let e=0;e<n.length-2&&(t=n[e],a());e++){if(t._$host){t=t._$host,l();break}if(t.parentNode===o)break}}else l();i(s)}function g(e,t,n,s,o){const i=d(e);if(i){!n&&(n=[...e.childNodes]);let t=[];for(let e=0;e<n.length;e++){const r=n[e];8===r.nodeType&&"!$"===r.data.slice(0,2)?r.remove():t.push(r)}n=t}for(;"function"==typeof n;)n=n();if(t===n)return n;const a=typeof t,l=void 0!==s;if(e=l&&n[0]&&n[0].parentNode||e,"string"===a||"number"===a){if(i)return n;if("number"===a&&(t=t.toString())===n)return n;if(l){let r=n[0];r&&3===r.nodeType?r.data!==t&&(r.data=t):r=document.createTextNode(t),n=y(e,n,s,r)}else n=""!==n&&"string"==typeof n?e.firstChild.data=t:e.textContent=t}else if(null==t||"boolean"===a){if(i)return n;n=y(e,n,s)}else{if("function"===a)return(0,r.gb)(()=>{let r=t();for(;"function"==typeof r;)r=r();n=g(e,r,n,s)}),()=>n;if(Array.isArray(t)){const a=[],c=n&&Array.isArray(n);if(w(a,t,n,o))return(0,r.gb)(()=>n=g(e,a,n,s,!0)),()=>n;if(i){if(!a.length)return n;if(void 0===s)return n=[...e.childNodes];let t=a[0];if(t.parentNode!==e)return n;const r=[t];for(;(t=t.nextSibling)!==s;)r.push(t);return n=r}if(0===a.length){if(n=y(e,n,s),l)return n}else c?0===n.length?b(e,a,s):function(e,t,n){let r=n.length,s=t.length,o=r,i=0,a=0,l=t[s-1].nextSibling,c=null;for(;i<s||a<o;)if(t[i]!==n[a]){for(;t[s-1]===n[o-1];)s--,o--;if(s===i){const t=o<r?a?n[a-1].nextSibling:n[o-a]:l;for(;a<o;)e.insertBefore(n[a++],t)}else if(o===a)for(;i<s;)c&&c.has(t[i])||t[i].remove(),i++;else if(t[i]===n[o-1]&&n[a]===t[s-1]){const r=t[--s].nextSibling;e.insertBefore(n[a++],t[i++].nextSibling),e.insertBefore(n[--o],r),t[s]=n[o]}else{if(!c){c=new Map;let e=a;for(;e<o;)c.set(n[e],e++)}const r=c.get(t[i]);if(null!=r)if(a<r&&r<o){let l,u=i,h=1;for(;++u<s&&u<o&&null!=(l=c.get(t[u]))&&l===r+h;)h++;if(h>r-a){const s=t[i];for(;a<r;)e.insertBefore(n[a++],s)}else e.replaceChild(n[a++],t[i++])}else i++;else t[i++].remove()}}else i++,a++}(e,n,a):(n&&y(e),b(e,a));n=a}else if(t.nodeType){if(i&&t.parentNode)return n=l?[t]:t;if(Array.isArray(n)){if(l)return n=y(e,n,s,t);y(e,n,null,t)}else null!=n&&""!==n&&e.firstChild?e.replaceChild(t,e.firstChild):e.appendChild(t);n=t}}return n}function w(e,t,n,r){let s=!1;for(let o=0,i=t.length;o<i;o++){let i,a=t[o],l=n&&n[e.length];if(null==a||!0===a||!1===a);else if("object"==(i=typeof a)&&a.nodeType)e.push(a);else if(Array.isArray(a))s=w(e,a,l)||s;else if("function"===i)if(r){for(;"function"==typeof a;)a=a();s=w(e,Array.isArray(a)?a:[a],Array.isArray(l)?l:[l])||s}else e.push(a),s=!0;else{const t=String(a);l&&3===l.nodeType&&l.data===t?e.push(l):e.push(document.createTextNode(t))}}return s}function b(e,t,n=null){for(let r=0,s=t.length;r<s;r++)e.insertBefore(t[r],n)}function y(e,t,n,r){if(void 0===n)return e.textContent="";const s=r||document.createTextNode("");if(t.length){let r=!1;for(let o=t.length-1;o>=0;o--){const i=t[o];if(s!==i){const t=i.parentNode===e;r||o?t&&i.remove():t?e.replaceChild(s,i):e.insertBefore(s,n)}else r=!0}}else e.insertBefore(s,n);return[s]}Symbol()},168(e,t,n){n.d(t,{createRouter:()=>s});var r=n(701);function s(){const[e,t]=(0,r.n5)(n());function n(){const e=window.location.hash.slice(1);if(!e||"/"===e)return{view:"list"};const t=e.match(/^\/post\/(.+)$/);return t?{view:"detail",postId:t[1]}:{view:"list"}}function s(){t(n())}return window.addEventListener("hashchange",s),(0,r.Ki)(()=>window.removeEventListener("hashchange",s)),{route:e,navigateToPost:function(e){window.location.hash=`/post/${e}`},navigateToList:function(){window.location.hash="/"}}}},261(e,t,n){n.d(t,{NostrService:()=>Ba});var r={};function s(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function o(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function i(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}n.r(r),n.d(r,{OG:()=>N,My:()=>$,Ph:()=>B,lX:()=>L,Id:()=>U,fg:()=>q,qj:()=>C,aT:()=>I,lq:()=>_,z:()=>P,Q5:()=>H});const a="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,l=e=>e instanceof Uint8Array,c=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),u=(e,t)=>e<<32-t|e>>>t;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");function h(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!l(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class d{clone(){return this._cloneInto()}}function f(e){const t=t=>e().update(h(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function p(e=32){if(a&&"function"==typeof a.getRandomValues)return a.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}class g extends d{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=c(this.buffer)}update(e){i(this);const{view:t,buffer:n,blockLen:r}=this,s=(e=h(e)).length;for(let o=0;o<s;){const i=Math.min(r-this.pos,s-o);if(i===r){const t=c(e);for(;r<=s-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){i(this),function(e,t){o(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:s}=this;let{pos:a}=this;t[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),l=r?4:0,c=r?0:4;e.setUint32(t+l,i,r),e.setUint32(t+c,a,r)}(n,r-8,BigInt(8*this.length),s),this.process(n,0);const l=c(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const h=u/4,d=this.get();if(h>d.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<h;e++)l.setUint32(4*e,d[e],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:s,destroyed:o,pos:i}=this;return e.length=r,e.pos=i,e.finished=s,e.destroyed=o,r%t&&e.buffer.set(n),e}}const w=(e,t,n)=>e&t^~e&n,b=(e,t,n)=>e&t^e&n^t&n,y=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]),m=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),v=new Uint32Array(64);class k extends g{constructor(){super(64,32,8,!1),this.A=0|m[0],this.B=0|m[1],this.C=0|m[2],this.D=0|m[3],this.E=0|m[4],this.F=0|m[5],this.G=0|m[6],this.H=0|m[7]}get(){const{A:e,B:t,C:n,D:r,E:s,F:o,G:i,H:a}=this;return[e,t,n,r,s,o,i,a]}set(e,t,n,r,s,o,i,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|s,this.F=0|o,this.G=0|i,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)v[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=v[e-15],n=v[e-2],r=u(t,7)^u(t,18)^t>>>3,s=u(n,17)^u(n,19)^n>>>10;v[e]=s+v[e-7]+r+v[e-16]|0}let{A:n,B:r,C:s,D:o,E:i,F:a,G:l,H:c}=this;for(let e=0;e<64;e++){const t=c+(u(i,6)^u(i,11)^u(i,25))+w(i,a,l)+y[e]+v[e]|0,h=(u(n,2)^u(n,13)^u(n,22))+b(n,r,s)|0;c=l,l=a,a=i,i=o+t|0,o=s,s=r,r=n,n=t+h|0}n=n+this.A|0,r=r+this.B|0,s=s+this.C|0,o=o+this.D|0,i=i+this.E|0,a=a+this.F|0,l=l+this.G|0,c=c+this.H|0,this.set(n,r,s,o,i,a,l,c)}roundClean(){v.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const x=f(()=>new k),E=(BigInt(0),BigInt(1)),S=BigInt(2),A=e=>e instanceof Uint8Array,T=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $(e){if(!A(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=T[e[n]];return t}function R(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function I(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let t=0;t<n.length;t++){const r=2*t,s=e.slice(r,r+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[t]=o}return n}function B(e){return R($(e))}function L(e){if(!A(e))throw new Error("Uint8Array expected");return R($(Uint8Array.from(e).reverse()))}function _(e,t){return I(e.toString(16).padStart(2*t,"0"))}function P(e,t){return _(e,t).reverse()}function C(e,t,n){let r;if("string"==typeof t)try{r=I(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!A(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const s=r.length;if("number"==typeof n&&s!==n)throw new Error(`${e} expected ${n} bytes, got ${s}`);return r}function U(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!A(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const N=e=>(S<<BigInt(e-1))-E,O=e=>new Uint8Array(e),z=e=>Uint8Array.from(e);function q(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=O(e),s=O(e),o=0;const i=()=>{r.fill(1),s.fill(0),o=0},a=(...e)=>n(s,r,...e),l=(e=O())=>{s=a(z([0]),e),r=a(),0!==e.length&&(s=a(z([1]),e),r=a())},c=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=a();const t=r.slice();n.push(t),e+=r.length}return U(...n)};return(e,t)=>{let n;for(i(),l(e);!(n=t(c()));)l();return i(),n}}const M={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function H(e,t,n={}){const r=(t,n,r)=>{const s=M[n];if("function"!=typeof s)throw new Error(`Invalid validator "${n}", expected function`);const o=e[t];if(!(r&&void 0===o||s(o,e)))throw new Error(`Invalid param ${String(t)}=${o} (${typeof o}), expected ${n}`)};for(const[e,n]of Object.entries(t))r(e,n,!1);for(const[e,t]of Object.entries(n))r(e,t,!0);return e}const j=BigInt(0),D=BigInt(1),F=BigInt(2),V=BigInt(3),W=BigInt(4),Z=BigInt(5),K=BigInt(8);function Y(e,t){const n=e%t;return n>=j?n:t+n}function G(e,t,n){if(n<=j||t<j)throw new Error("Expected power/modulo > 0");if(n===D)return j;let r=D;for(;t>j;)t&D&&(r=r*e%n),e=e*e%n,t>>=D;return r}function J(e,t,n){let r=e;for(;t-- >j;)r*=r,r%=n;return r}function Q(e,t){if(e===j||t<=j)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Y(e,t),r=t,s=j,o=D,i=D,a=j;for(;n!==j;){const e=r/n,t=r%n,l=s-i*e,c=o-a*e;r=n,n=t,s=i,o=a,i=l,a=c}if(r!==D)throw new Error("invert: does not exist");return Y(s,t)}BigInt(9),BigInt(16);const X=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ee(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function te(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function ne(e){const t=te(e);return t+Math.ceil(t/2)}class re extends d{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");s(e.outputLen),s(e.blockLen)}(e);const n=h(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),o.fill(0)}update(e){return i(this),this.iHash.update(e),this}digestInto(e){i(this),o(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:s,blockLen:o,outputLen:i}=this;return e.finished=r,e.destroyed=s,e.blockLen=o,e.outputLen=i,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const se=(e,t,n)=>new re(e,t).update(n).digest();se.create=(e,t)=>new re(e,t);const oe=BigInt(0),ie=BigInt(1);function ae(e){return H(e.Fp,X.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),H(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ee(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}const{Ph:le,aT:ce}=r,ue={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=ue;if(e.length<2||2!==e[0])throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:le(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=ue,n="string"==typeof e?ce(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:s,l:o}=ue._parseInt(n.subarray(2)),{d:i,l:a}=ue._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(e){const t=e=>8&Number.parseInt(e[0],16)?"00"+e:e,n=e=>{const t=e.toString(16);return 1&t.length?`0${t}`:t},r=t(n(e.s)),s=t(n(e.r)),o=r.length/2,i=s.length/2,a=n(o),l=n(i);return`30${n(i+o+4)}02${l}${s}02${a}${r}`}},he=BigInt(0),de=BigInt(1),fe=(BigInt(2),BigInt(3));function pe(e){const t=function(e){const t=ae(e);return H(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:n,n:r}=t,s=n.BYTES+1,o=2*n.BYTES+1;function i(e){return Y(e,r)}function a(e){return Q(e,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:u,isWithinCurveOrder:h}=function(e){const t=function(e){const t=ae(e);H(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:s}=t;if(n){if(!r.eql(s,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:n}=t,r=t.toBytes||((e,t,r)=>{const s=t.toAffine();return U(Uint8Array.from([4]),n.toBytes(s.x),n.toBytes(s.y))}),s=t.fromBytes||(e=>{const t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function o(e){const{a:r,b:s}=t,o=n.sqr(e),i=n.mul(o,e);return n.add(n.add(i,n.mul(e,r)),s)}if(!n.eql(n.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(e){return"bigint"==typeof e&&he<e&&e<t.n}function a(e){if(!i(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function l(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:s,n:o}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=$(e)),"string"!=typeof e||!n.includes(e.length))throw new Error("Invalid key");e=e.padStart(2*r,"0")}let i;try{i="bigint"==typeof e?e:B(C("private key",e,r))}catch(t){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return s&&(i=Y(i,o)),a(i),i}const c=new Map;function u(e){if(!(e instanceof h))throw new Error("ProjectivePoint expected")}class h{constructor(e,t,r){if(this.px=e,this.py=t,this.pz=r,null==e||!n.isValid(e))throw new Error("x required");if(null==t||!n.isValid(t))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof h)throw new Error("projective point not allowed");const s=e=>n.eql(e,n.ZERO);return s(t)&&s(r)?h.ZERO:new h(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(h.fromAffine)}static fromHex(e){const t=h.fromAffine(s(C("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return h.BASE.multiply(l(e))}_setWindowSize(e){this._WINDOW_SIZE=e,c.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:e,y:r}=this.toAffine();if(!n.isValid(e)||!n.isValid(r))throw new Error("bad point: x or y not FE");const s=n.sqr(r),i=o(e);if(!n.eql(s,i))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){u(e);const{px:t,py:r,pz:s}=this,{px:o,py:i,pz:a}=e,l=n.eql(n.mul(t,a),n.mul(o,s)),c=n.eql(n.mul(r,a),n.mul(i,s));return l&&c}negate(){return new h(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,s=n.mul(r,fe),{px:o,py:i,pz:a}=this;let l=n.ZERO,c=n.ZERO,u=n.ZERO,d=n.mul(o,o),f=n.mul(i,i),p=n.mul(a,a),g=n.mul(o,i);return g=n.add(g,g),u=n.mul(o,a),u=n.add(u,u),l=n.mul(e,u),c=n.mul(s,p),c=n.add(l,c),l=n.sub(f,c),c=n.add(f,c),c=n.mul(l,c),l=n.mul(g,l),u=n.mul(s,u),p=n.mul(e,p),g=n.sub(d,p),g=n.mul(e,g),g=n.add(g,u),u=n.add(d,d),d=n.add(u,d),d=n.add(d,p),d=n.mul(d,g),c=n.add(c,d),p=n.mul(i,a),p=n.add(p,p),d=n.mul(p,g),l=n.sub(l,d),u=n.mul(p,f),u=n.add(u,u),u=n.add(u,u),new h(l,c,u)}add(e){u(e);const{px:r,py:s,pz:o}=this,{px:i,py:a,pz:l}=e;let c=n.ZERO,d=n.ZERO,f=n.ZERO;const p=t.a,g=n.mul(t.b,fe);let w=n.mul(r,i),b=n.mul(s,a),y=n.mul(o,l),m=n.add(r,s),v=n.add(i,a);m=n.mul(m,v),v=n.add(w,b),m=n.sub(m,v),v=n.add(r,o);let k=n.add(i,l);return v=n.mul(v,k),k=n.add(w,y),v=n.sub(v,k),k=n.add(s,o),c=n.add(a,l),k=n.mul(k,c),c=n.add(b,y),k=n.sub(k,c),f=n.mul(p,v),c=n.mul(g,y),f=n.add(c,f),c=n.sub(b,f),f=n.add(b,f),d=n.mul(c,f),b=n.add(w,w),b=n.add(b,w),y=n.mul(p,y),v=n.mul(g,v),b=n.add(b,y),y=n.sub(w,y),y=n.mul(p,y),v=n.add(v,y),w=n.mul(b,v),d=n.add(d,w),w=n.mul(k,v),c=n.mul(m,c),c=n.sub(c,w),w=n.mul(m,b),f=n.mul(k,f),f=n.add(f,w),new h(c,d,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(h.ZERO)}wNAF(e){return f.wNAFCached(this,c,e,e=>{const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(h.fromAffine)})}multiplyUnsafe(e){const r=h.ZERO;if(e===he)return r;if(a(e),e===de)return this;const{endo:s}=t;if(!s)return f.unsafeLadder(this,e);let{k1neg:o,k1:i,k2neg:l,k2:c}=s.splitScalar(e),u=r,d=r,p=this;for(;i>he||c>he;)i&de&&(u=u.add(p)),c&de&&(d=d.add(p)),p=p.double(),i>>=de,c>>=de;return o&&(u=u.negate()),l&&(d=d.negate()),d=new h(n.mul(d.px,s.beta),d.py,d.pz),u.add(d)}multiply(e){a(e);let r,s,o=e;const{endo:i}=t;if(i){const{k1neg:e,k1:t,k2neg:a,k2:l}=i.splitScalar(o);let{p:c,f:u}=this.wNAF(t),{p:d,f:p}=this.wNAF(l);c=f.constTimeNegate(e,c),d=f.constTimeNegate(a,d),d=new h(n.mul(d.px,i.beta),d.py,d.pz),r=c.add(d),s=u.add(p)}else{const{p:e,f:t}=this.wNAF(o);r=e,s=t}return h.normalizeZ([r,s])[0]}multiplyAndAddUnsafe(e,t,n){const r=h.BASE,s=(e,t)=>t!==he&&t!==de&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),o=s(this,t).add(s(e,n));return o.is0()?void 0:o}toAffine(e){const{px:t,py:r,pz:s}=this,o=this.is0();null==e&&(e=o?n.ONE:n.inv(s));const i=n.mul(t,e),a=n.mul(r,e),l=n.mul(s,e);if(o)return{x:n.ZERO,y:n.ZERO};if(!n.eql(l,n.ONE))throw new Error("invZ was invalid");return{x:i,y:a}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===de)return!0;if(n)return n(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:n}=t;return e===de?this:n?n(h,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(h,this,e)}toHex(e=!0){return $(this.toRawBytes(e))}}h.BASE=new h(t.Gx,t.Gy,n.ONE),h.ZERO=new h(n.ZERO,n.ONE,n.ZERO);const d=t.nBitLength,f=function(e,t){const n=(e,t)=>{const n=t.negate();return e?n:t},r=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:n,unsafeLadder(t,n){let r=e.ZERO,s=t;for(;n>oe;)n&ie&&(r=r.add(s)),s=s.double(),n>>=ie;return r},precomputeWindow(e,t){const{windows:n,windowSize:s}=r(t),o=[];let i=e,a=i;for(let e=0;e<n;e++){a=i,o.push(a);for(let e=1;e<s;e++)a=a.add(i),o.push(a);i=a.double()}return o},wNAF(t,s,o){const{windows:i,windowSize:a}=r(t);let l=e.ZERO,c=e.BASE;const u=BigInt(2**t-1),h=2**t,d=BigInt(t);for(let e=0;e<i;e++){const t=e*a;let r=Number(o&u);o>>=d,r>a&&(r-=h,o+=ie);const i=t,f=t+Math.abs(r)-1,p=e%2!=0,g=r<0;0===r?c=c.add(n(p,s[i])):l=l.add(n(g,s[f]))}return{p:l,f:c}},wNAFCached(e,t,n,r){const s=e._WINDOW_SIZE||1;let o=t.get(e);return o||(o=this.precomputeWindow(e,s),1!==s&&t.set(e,r(o))),this.wNAF(s,o,n)}}}(h,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:l,weierstrassEquation:o,isWithinCurveOrder:i}}({...t,toBytes(e,t,r){const s=t.toAffine(),o=n.toBytes(s.x),i=U;return r?i(Uint8Array.from([t.hasEvenY()?2:3]),o):i(Uint8Array.from([4]),o,n.toBytes(s.y))},fromBytes(e){const t=e.length,r=e[0],i=e.subarray(1);if(t!==s||2!==r&&3!==r){if(t===o&&4===r)return{x:n.fromBytes(i.subarray(0,n.BYTES)),y:n.fromBytes(i.subarray(n.BYTES,2*n.BYTES))};throw new Error(`Point of length ${t} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}{const e=B(i);if(!(he<(a=e)&&a<n.ORDER))throw new Error("Point is not on curve");const t=u(e);let s=n.sqrt(t);return!(1&~r)!=((s&de)===de)&&(s=n.neg(s)),{x:e,y:s}}var a}}),d=e=>$(_(e,t.nByteLength));function f(e){return e>r>>de}const p=(e,t,n)=>B(e.slice(t,n));class g{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=C("compactSignature",e,2*n),new g(p(e,0,n),p(e,n,2*n))}static fromDER(e){const{r:t,s:n}=ue.toSig(C("DER",e));return new g(t,n)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(e){return new g(this.r,this.s,e)}recoverPublicKey(e){const{r,s,recovery:o}=this,c=m(C("msgHash",e));if(null==o||![0,1,2,3].includes(o))throw new Error("recovery id invalid");const u=2===o||3===o?r+t.n:r;if(u>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const h=1&o?"03":"02",f=l.fromHex(h+d(u)),p=a(u),g=i(-c*p),w=i(s*p),b=l.BASE.multiplyAndAddUnsafe(f,g,w);if(!b)throw new Error("point at infinify");return b.assertValidity(),b}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return I(this.toDERHex())}toDERHex(){return ue.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return I(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}const w={isValidPrivateKey(e){try{return c(e),!0}catch(e){return!1}},normPrivateKeyToScalar:c,randomPrivateKey:()=>{const e=ne(t.n);return function(e,t,n=!1){const r=e.length,s=te(t),o=ne(t);if(r<16||r<o||r>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${r}`);const i=Y(n?B(e):L(e),t-D)+D;return n?P(i,s):_(i,s)}(t.randomBytes(e),t.n)},precompute:(e=8,t=l.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function b(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===s||r===o:n?r===2*s||r===2*o:e instanceof l}const y=t.bits2int||function(e){const n=B(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},m=t.bits2int_modN||function(e){return i(y(e))},v=N(t.nBitLength);function k(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(he<=e&&e<v))throw new Error(`bigint expected < 2^${t.nBitLength}`);return _(e,t.nByteLength)}const x={lowS:t.lowS,prehash:!1},E={lowS:t.lowS,prehash:!1};return l.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return l.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(b(e))throw new Error("first arg must be private key");if(!b(t))throw new Error("second arg must be public key");return l.fromHex(t).multiply(c(e)).toRawBytes(n)},sign:function(e,r,s=x){const{seed:o,k2sig:u}=function(e,r,s=x){if(["recovered","canonical"].some(e=>e in s))throw new Error("sign() legacy options not supported");const{hash:o,randomBytes:u}=t;let{lowS:d,prehash:p,extraEntropy:w}=s;null==d&&(d=!0),e=C("msgHash",e),p&&(e=C("prehashed msgHash",o(e)));const b=m(e),v=c(r),E=[k(v),k(b)];if(null!=w){const e=!0===w?u(n.BYTES):w;E.push(C("extraEntropy",e))}const S=U(...E),A=b;return{seed:S,k2sig:function(e){const t=y(e);if(!h(t))return;const n=a(t),r=l.BASE.multiply(t).toAffine(),s=i(r.x);if(s===he)return;const o=i(n*i(A+s*v));if(o===he)return;let c=(r.x===s?0:2)|Number(r.y&de),u=o;return d&&f(o)&&(u=function(e){return f(e)?i(-e):e}(o),c^=1),new g(s,u,c)}}}(e,r,s),d=t;return q(d.hash.outputLen,d.nByteLength,d.hmac)(o,u)},verify:function(e,n,r,s=E){const o=e;if(n=C("msgHash",n),r=C("publicKey",r),"strict"in s)throw new Error("options.strict was renamed to lowS");const{lowS:c,prehash:u}=s;let h,d;try{if("string"==typeof o||o instanceof Uint8Array)try{h=g.fromDER(o)}catch(e){if(!(e instanceof ue.Err))throw e;h=g.fromCompact(o)}else{if("object"!=typeof o||"bigint"!=typeof o.r||"bigint"!=typeof o.s)throw new Error("PARSE");{const{r:e,s:t}=o;h=new g(e,t)}}d=l.fromHex(r)}catch(e){if("PARSE"===e.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(c&&h.hasHighS())return!1;u&&(n=t.hash(n));const{r:f,s:p}=h,w=m(n),b=a(p),y=i(w*b),v=i(f*b),k=l.BASE.multiplyAndAddUnsafe(d,y,v)?.toAffine();return!!k&&i(k.x)===f},ProjectivePoint:l,Signature:g,utils:w}}function ge(e){return{hash:e,hmac:(t,...n)=>se(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!l(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:p}}BigInt(4);const we=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),be=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ye=BigInt(1),me=BigInt(2),ve=(e,t)=>(e+t/me)/t;function ke(e){const t=we,n=BigInt(3),r=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),l=BigInt(88),c=e*e*e%t,u=c*c*e%t,h=J(u,n,t)*u%t,d=J(h,n,t)*u%t,f=J(d,me,t)*c%t,p=J(f,s,t)*f%t,g=J(p,o,t)*p%t,w=J(g,a,t)*g%t,b=J(w,l,t)*w%t,y=J(b,a,t)*g%t,m=J(y,n,t)*u%t,v=J(m,i,t)*p%t,k=J(v,r,t)*c%t,x=J(k,me,t);if(!xe.eql(xe.sqr(x),e))throw new Error("Cannot find square root");return x}const xe=function(e,t,n=!1,r={}){if(e<=j)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:o}=ee(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=function(e){if(e%W===V){const t=(e+D)/W;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%K===Z){const t=(e-Z)/K;return function(e,n){const r=e.mul(n,F),s=e.pow(r,t),o=e.mul(n,s),i=e.mul(e.mul(o,F),s),a=e.mul(o,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-D)/F;let n,r,s;for(n=e-D,r=0;n%F===j;n/=F,r++);for(s=F;s<e&&G(s,t,e)!==e-D;s++);if(1===r){const t=(e+D)/W;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const o=(n+D)/F;return function(e,i){if(e.pow(i,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,l=e.pow(e.mul(e.ONE,s),n),c=e.pow(i,o),u=e.pow(i,n);for(;!e.eql(u,e.ONE);){if(e.eql(u,e.ZERO))return e.ZERO;let t=1;for(let n=e.sqr(u);t<a&&!e.eql(n,e.ONE);t++)n=e.sqr(n);const n=e.pow(l,D<<BigInt(a-t-1));l=e.sqr(n),c=e.mul(c,n),u=e.mul(u,l),a=t}return c}}(e)}(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:o,MASK:N(s),ZERO:j,ONE:D,create:t=>Y(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return j<=t&&t<e},is0:e=>e===j,isOdd:e=>(e&D)===D,neg:t=>Y(-t,e),eql:(e,t)=>e===t,sqr:t=>Y(t*t,e),add:(t,n)=>Y(t+n,e),sub:(t,n)=>Y(t-n,e),mul:(t,n)=>Y(t*n,e),pow:(e,t)=>function(e,t,n){if(n<j)throw new Error("Expected power > 0");if(n===j)return e.ONE;if(n===D)return t;let r=e.ONE,s=t;for(;n>j;)n&D&&(r=e.mul(r,s)),s=e.sqr(s),n>>=D;return r}(a,e,t),div:(t,n)=>Y(t*Q(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Q(t,e),sqrt:r.sqrt||(e=>i(a,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce((t,r,s)=>e.is0(r)?t:(n[s]=t,e.mul(t,r)),e.ONE),s=e.inv(r);return t.reduceRight((t,r,s)=>e.is0(r)?t:(n[s]=e.mul(t,n[s]),e.mul(t,r)),s),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?P(e,o):_(e,o),fromBytes:e=>{if(e.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${e.length}`);return n?L(e):B(e)}});return Object.freeze(a)}(we,void 0,void 0,{sqrt:ke}),Ee=function(e,t){const n=t=>pe({...e,...ge(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:xe,n:be,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=be,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-ye*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,i=BigInt("0x100000000000000000000000000000000"),a=ve(o*e,t),l=ve(-r*e,t);let c=Y(e-a*n-l*s,t),u=Y(-a*r-l*o,t);const h=c>i,d=u>i;if(h&&(c=t-c),d&&(u=t-u),c>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:h,k1:c,k2neg:d,k2:u}}}},x),Se=BigInt(0),Ae=e=>"bigint"==typeof e&&Se<e&&e<we,Te={};function $e(e,...t){let n=Te[e];if(void 0===n){const t=x(Uint8Array.from(e,e=>e.charCodeAt(0)));n=U(t,t),Te[e]=n}return x(U(n,...t))}const Re=e=>e.toRawBytes(!0).slice(1),Ie=e=>_(e,32),Be=e=>Y(e,we),Le=e=>Y(e,be),_e=Ee.ProjectivePoint;function Pe(e){let t=Ee.utils.normPrivateKeyToScalar(e),n=_e.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Le(-t),bytes:Re(n)}}function Ce(e){if(!Ae(e))throw new Error("bad x: need 0 < x < p");const t=Be(e*e);let n=ke(Be(t*e+BigInt(7)));n%me!==Se&&(n=Be(-n));const r=new _e(e,n,ye);return r.assertValidity(),r}function Ue(...e){return Le(B($e("BIP0340/challenge",...e)))}function Ne(e){return Pe(e).bytes}function Oe(e,t,n=p(32)){const r=C("message",e),{bytes:s,scalar:o}=Pe(t),i=C("auxRand",n,32),a=Ie(o^B($e("BIP0340/aux",i))),l=$e("BIP0340/nonce",a,s,r),c=Le(B(l));if(c===Se)throw new Error("sign failed: k is zero");const{bytes:u,scalar:h}=Pe(c),d=Ue(u,s,r),f=new Uint8Array(64);if(f.set(u,0),f.set(Ie(Le(h+d*o)),32),!ze(f,r,s))throw new Error("sign: Invalid signature produced");return f}function ze(e,t,n){const r=C("signature",e,64),s=C("message",t),o=C("publicKey",n,32);try{const e=Ce(B(o)),t=B(r.subarray(0,32));if(!Ae(t))return!1;const n=B(r.subarray(32,64));if(!(e=>"bigint"==typeof e&&Se<e&&e<be)(n))return!1;const i=Ue(Ie(t),Re(e),s),a=((e,t,n)=>_e.BASE.multiplyAndAddUnsafe(e,t,n))(e,n,Le(-i));return!(!a||!a.hasEvenY()||a.toAffine().x!==t)}catch(e){return!1}}const qe=(()=>({getPublicKey:Ne,sign:Oe,verify:ze,utils:{randomPrivateKey:Ee.utils.randomPrivateKey,lift_x:Ce,pointToBytes:Re,numberToBytesBE:_,bytesToNumberBE:B,taggedHash:$e,mod:Y}}))(),Me="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,He=e=>e instanceof Uint8Array,je=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),De=(e,t)=>e<<32-t|e>>>t;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const Fe=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ve(e){if(!He(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Fe[e[n]];return t}function We(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let t=0;t<n.length;t++){const r=2*t,s=e.slice(r,r+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[t]=o}return n}function Ze(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!He(e))throw new Error("expected Uint8Array, got "+typeof e);return e}function Ke(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!He(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}class Ye{clone(){return this._cloneInto()}}function Ge(e){const t=t=>e().update(Ze(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Je(e=32){if(Me&&"function"==typeof Me.getRandomValues)return Me.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Qe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Xe(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}const et={number:Qe,bool:function(e){if("boolean"!=typeof e)throw new Error(`Expected boolean, not ${e}`)},bytes:Xe,hash:function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Qe(e.outputLen),Qe(e.blockLen)},exists:function(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")},output:function(e,t){Xe(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}},tt=et;class nt extends Ye{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=je(this.buffer)}update(e){tt.exists(this);const{view:t,buffer:n,blockLen:r}=this,s=(e=Ze(e)).length;for(let o=0;o<s;){const i=Math.min(r-this.pos,s-o);if(i===r){const t=je(e);for(;r<=s-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){tt.exists(this),tt.output(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:s}=this;let{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>r-o&&(this.process(n,0),o=0);for(let e=o;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),l=r?4:0,c=r?0:4;e.setUint32(t+l,i,r),e.setUint32(t+c,a,r)}(n,r-8,BigInt(8*this.length),s),this.process(n,0);const i=je(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,c=this.get();if(l>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)i.setUint32(4*e,c[e],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:s,destroyed:o,pos:i}=this;return e.length=r,e.pos=i,e.finished=s,e.destroyed=o,r%t&&e.buffer.set(n),e}}const rt=(e,t,n)=>e&t^~e&n,st=(e,t,n)=>e&t^e&n^t&n,ot=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]),it=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),at=new Uint32Array(64);class lt extends nt{constructor(){super(64,32,8,!1),this.A=0|it[0],this.B=0|it[1],this.C=0|it[2],this.D=0|it[3],this.E=0|it[4],this.F=0|it[5],this.G=0|it[6],this.H=0|it[7]}get(){const{A:e,B:t,C:n,D:r,E:s,F:o,G:i,H:a}=this;return[e,t,n,r,s,o,i,a]}set(e,t,n,r,s,o,i,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|s,this.F=0|o,this.G=0|i,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)at[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=at[e-15],n=at[e-2],r=De(t,7)^De(t,18)^t>>>3,s=De(n,17)^De(n,19)^n>>>10;at[e]=s+at[e-7]+r+at[e-16]|0}let{A:n,B:r,C:s,D:o,E:i,F:a,G:l,H:c}=this;for(let e=0;e<64;e++){const t=c+(De(i,6)^De(i,11)^De(i,25))+rt(i,a,l)+ot[e]+at[e]|0,u=(De(n,2)^De(n,13)^De(n,22))+st(n,r,s)|0;c=l,l=a,a=i,i=o+t|0,o=s,s=r,r=n,n=t+u|0}n=n+this.A|0,r=r+this.B|0,s=s+this.C|0,o=o+this.D|0,i=i+this.E|0,a=a+this.F|0,l=l+this.G|0,c=c+this.H|0,this.set(n,r,s,o,i,a,l,c)}roundClean(){at.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class ct extends lt{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 ut=Ge(()=>new lt);function ht(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function dt(...e){const t=(e,t)=>n=>e(t(n)),n=Array.from(e).reverse().reduce((e,n)=>e?t(e,n.encode):n.encode,void 0),r=e.reduce((e,n)=>e?t(e,n.decode):n.decode,void 0);return{encode:n,decode:r}}function ft(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("alphabet.encode input should be an array of numbers");return t.map(t=>{if(ht(t),t<0||t>=e.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${e.length})`);return e[t]})},decode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("alphabet.decode input should be array of strings");return t.map(t=>{if("string"!=typeof t)throw new Error(`alphabet.decode: not string element=${t}`);const n=e.indexOf(t);if(-1===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n})}}}function pt(e=""){if("string"!=typeof e)throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("join.encode input should be array of strings");for(let e of t)if("string"!=typeof e)throw new Error(`join.encode: non-string input=${e}`);return t.join(e)},decode:t=>{if("string"!=typeof t)throw new Error("join.decode input should be string");return t.split(e)}}}function gt(e,t="="){if(ht(e),"string"!=typeof t)throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let e of n)if("string"!=typeof e)throw new Error(`padding.encode: non-string input=${e}`);for(;n.length*e%8;)n.push(t);return n},decode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let e of n)if("string"!=typeof e)throw new Error(`padding.decode: non-string input=${e}`);let r=n.length;if(r*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if(!((r-1)*e%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function wt(e){if("function"!=typeof e)throw new Error("normalize fn should be function");return{encode:e=>e,decode:t=>e(t)}}function bt(e,t,n){if(t<2)throw new Error(`convertRadix: wrong from=${t}, 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(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let r=0;const s=[],o=Array.from(e);for(o.forEach(e=>{if(ht(e),e<0||e>=t)throw new Error(`Wrong integer: ${e}`)});;){let e=0,i=!0;for(let s=r;s<o.length;s++){const a=o[s],l=t*e+a;if(!Number.isSafeInteger(l)||t*e/t!==e||l-a!==t*e)throw new Error("convertRadix: carry overflow");if(e=l%n,o[s]=Math.floor(l/n),!Number.isSafeInteger(o[s])||o[s]*n+e!==l)throw new Error("convertRadix: carry overflow");i&&(o[s]?i=!1:r=s)}if(s.push(e),i)break}for(let t=0;t<e.length-1&&0===e[t];t++)s.push(0);return s.reverse()}Ge(()=>new ct);const yt=(e,t)=>t?yt(t,e%t):e,mt=(e,t)=>e+(t-yt(e,t));function vt(e,t,n,r){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(mt(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${mt(t,n)}`);let s=0,o=0;const i=2**n-1,a=[];for(const r of e){if(ht(r),r>=2**t)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(s=s<<t|r,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)a.push((s>>o-n&i)>>>0);s&=2**o-1}if(s=s<<n-o&i,!r&&o>=t)throw new Error("Excess padding");if(!r&&s)throw new Error(`Non-zero padding: ${s}`);return r&&o>0&&a.push(s>>>0),a}function kt(e,t=!1){if(ht(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(mt(8,e)>32||mt(e,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 vt(Array.from(n),8,e,!t)},decode:n=>{if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(vt(n,e,8,t))}}}function xt(e){if("function"!=typeof e)throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch(e){}}}dt(kt(4),ft("0123456789ABCDEF"),pt("")),dt(kt(5),ft("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),gt(5),pt(""));const Et=(dt(kt(5),ft("0123456789ABCDEFGHIJKLMNOPQRSTUV"),gt(5),pt("")),dt(kt(5),ft("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),pt(""),wt(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),dt(kt(6),ft("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),gt(6),pt(""))),St=(dt(kt(6),ft("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),gt(6),pt("")),e=>{return dt((ht(t=58),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return bt(Array.from(e),256,t)},decode:e=>{if(!Array.isArray(e)||e.length&&"number"!=typeof e[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(bt(e,t,256))}}),ft(e),pt(""));var t}),At=(St("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),St("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),St("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),dt(ft("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),pt(""))),Tt=[996825010,642813549,513874426,1027748829,705979059];function $t(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Tt.length;e++)1==(t>>e&1)&&(n^=Tt[e]);return n}function Rt(e,t,n=1){const r=e.length;let s=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);s=$t(s)^n>>5}s=$t(s);for(let t=0;t<r;t++)s=$t(s)^31&e.charCodeAt(t);for(let e of t)s=$t(s)^e;for(let e=0;e<6;e++)s=$t(s);return s^=n,At.encode(vt([s%2**30],30,5,!1))}function It(e){const t="bech32"===e?1:734539939,n=kt(5),r=n.decode,s=n.encode,o=xt(r);function i(e,n=90){if("string"!=typeof e)throw new Error("bech32.decode input should be string, not "+typeof e);if(e.length<8||!1!==n&&e.length>n)throw new TypeError(`Wrong string length: ${e.length} (${e}). Expected (8..${n})`);const r=e.toLowerCase();if(e!==r&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const s=(e=r).lastIndexOf("1");if(0===s||-1===s)throw new Error('Letter "1" must be present between prefix and data only');const o=e.slice(0,s),i=e.slice(s+1);if(i.length<6)throw new Error("Data must be at least 6 characters long");const a=At.decode(i).slice(0,-6),l=Rt(o,a,t);if(!i.endsWith(l))throw new Error(`Invalid checksum in ${e}: expected "${l}"`);return{prefix:o,words:a}}return{encode:function(e,n,r=90){if("string"!=typeof e)throw new Error("bech32.encode prefix should be string, not "+typeof e);if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof n);const s=e.length+7+n.length;if(!1!==r&&s>r)throw new TypeError(`Length ${s} exceeds limit ${r}`);return`${e=e.toLowerCase()}1${At.encode(n)}${Rt(e,n,t)}`},decode:i,decodeToBytes:function(e){const{prefix:t,words:n}=i(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:xt(i),fromWords:r,fromWordsUnsafe:o,toWords:s}}const Bt=It("bech32");It("bech32m");function Lt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function _t(e){if("boolean"!=typeof e)throw new Error(`boolean expected, not ${e}`)}function Pt(e){return e instanceof Uint8Array||null!=e&&"object"==typeof e&&"Uint8Array"===e.constructor.name}function Ct(e,...t){if(!Pt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function Ut(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Nt(e,t){Ct(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}dt(kt(4),ft("0123456789abcdef"),pt(""),wt(e=>{if("string"!=typeof e||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const Ot=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),zt=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),qt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const Mt=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ht(e){Ct(e);let t="";for(let n=0;n<e.length;n++)t+=Mt[e[n]];return t}function jt(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Dt(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length,n=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,s=0;t<n;t++,s+=2){const n=jt(e.charCodeAt(s)),o=jt(e.charCodeAt(s+1));if(void 0===n||void 0===o){const t=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+s)}r[t]=16*n+o}return r}function Ft(e){if("string"==typeof e)e=function(e){if("string"!=typeof e)throw new Error("string expected, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e);else{if(!Pt(e))throw new Error("Uint8Array expected, got "+typeof e);e=e.slice()}return e}function Vt(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n}const Wt=(e,t)=>(Object.assign(t,e),t);function Zt(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),l=r?4:0,c=r?0:4;e.setUint32(t+l,i,r),e.setUint32(t+c,a,r)}const Kt=16,Yt=new Uint8Array(16),Gt=zt(Yt),Jt=(e,t,n,r)=>({s3:n<<31|r>>>1,s2:t<<31|n>>>1,s1:e<<31|t>>>1,s0:e>>>1^225<<24&-(1&r)}),Qt=e=>(e>>>0&255)<<24|(e>>>8&255)<<16|(e>>>16&255)<<8|e>>>24&255;class Xt{constructor(e,t){this.blockLen=Kt,this.outputLen=Kt,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,Ct(e=Ft(e),16);const n=qt(e);let r=n.getUint32(0,!1),s=n.getUint32(4,!1),o=n.getUint32(8,!1),i=n.getUint32(12,!1);const a=[];for(let e=0;e<128;e++)a.push({s0:Qt(r),s1:Qt(s),s2:Qt(o),s3:Qt(i)}),({s0:r,s1:s,s2:o,s3:i}=Jt(r,s,o,i));const l=(e=>e>65536?8:e>1024?4:2)(t||1024);if(![1,2,4,8].includes(l))throw new Error(`ghash: wrong window size=${l}, should be 2, 4 or 8`);this.W=l;const c=128/l,u=this.windowSize=2**l,h=[];for(let e=0;e<c;e++)for(let t=0;t<u;t++){let n=0,r=0,s=0,o=0;for(let i=0;i<l;i++){if(!(t>>>l-i-1&1))continue;const{s0:c,s1:u,s2:h,s3:d}=a[l*e+i];n^=c,r^=u,s^=h,o^=d}h.push({s0:n,s1:r,s2:s,s3:o})}this.t=h}_updateBlock(e,t,n,r){e^=this.s0,t^=this.s1,n^=this.s2,r^=this.s3;const{W:s,t:o,windowSize:i}=this;let a=0,l=0,c=0,u=0;const h=(1<<s)-1;let d=0;for(const f of[e,t,n,r])for(let e=0;e<4;e++){const t=f>>>8*e&255;for(let e=8/s-1;e>=0;e--){const n=t>>>s*e&h,{s0:r,s1:f,s2:p,s3:g}=o[d*i+n];a^=r,l^=f,c^=p,u^=g,d+=1}}this.s0=a,this.s1=l,this.s2=c,this.s3=u}update(e){e=Ft(e),Ut(this);const t=zt(e),n=Math.floor(e.length/Kt),r=e.length%Kt;for(let e=0;e<n;e++)this._updateBlock(t[4*e+0],t[4*e+1],t[4*e+2],t[4*e+3]);return r&&(Yt.set(e.subarray(n*Kt)),this._updateBlock(Gt[0],Gt[1],Gt[2],Gt[3]),Gt.fill(0)),this}destroy(){const{t:e}=this;for(const t of e)t.s0=0,t.s1=0,t.s2=0,t.s3=0}digestInto(e){Ut(this),Nt(e,this),this.finished=!0;const{s0:t,s1:n,s2:r,s3:s}=this,o=zt(e);return o[0]=t,o[1]=n,o[2]=r,o[3]=s,e}digest(){const e=new Uint8Array(Kt);return this.digestInto(e),this.destroy(),e}}class en extends Xt{constructor(e,t){const n=function(e){e.reverse();const t=1&e[15];let n=0;for(let t=0;t<e.length;t++){const r=e[t];e[t]=r>>>1|n,n=(1&r)<<7}return e[0]^=225&-t,e}((e=Ft(e)).slice());super(n,t),n.fill(0)}update(e){e=Ft(e),Ut(this);const t=zt(e),n=e.length%Kt,r=Math.floor(e.length/Kt);for(let e=0;e<r;e++)this._updateBlock(Qt(t[4*e+3]),Qt(t[4*e+2]),Qt(t[4*e+1]),Qt(t[4*e+0]));return n&&(Yt.set(e.subarray(r*Kt)),this._updateBlock(Qt(Gt[3]),Qt(Gt[2]),Qt(Gt[1]),Qt(Gt[0])),Gt.fill(0)),this}digestInto(e){Ut(this),Nt(e,this),this.finished=!0;const{s0:t,s1:n,s2:r,s3:s}=this,o=zt(e);return o[0]=t,o[1]=n,o[2]=r,o[3]=s,e.reverse()}}function tn(e){const t=(t,n)=>e(n,t.length).update(Ft(t)).digest(),n=e(new Uint8Array(16),0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=(t,n)=>e(t,n),t}const nn=tn((e,t)=>new Xt(e,t)),rn=tn((e,t)=>new en(e,t)),sn=16,on=new Uint8Array(sn);function an(e){return e<<1^283&-(e>>7)}function ln(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(1&t),e=an(e);return n}const cn=(()=>{let e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=an(n))e[t]=n;const t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=255&(r^r>>4^r>>5^r>>6^r>>7^99)}return t})(),un=cn.map((e,t)=>cn.indexOf(t)),hn=e=>e<<24|e>>>8,dn=e=>e<<8|e>>>24;function fn(e,t){if(256!==e.length)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((n,r)=>t(e[r])),r=n.map(dn),s=r.map(dn),o=s.map(dn),i=new Uint32Array(65536),a=new Uint32Array(65536),l=new Uint16Array(65536);for(let t=0;t<256;t++)for(let c=0;c<256;c++){const u=256*t+c;i[u]=n[t]^r[c],a[u]=s[t]^o[c],l[u]=e[t]<<8|e[c]}return{sbox:e,sbox2:l,T0:n,T1:r,T2:s,T3:o,T01:i,T23:a}}const pn=fn(cn,e=>ln(e,3)<<24|e<<16|e<<8|ln(e,2)),gn=fn(un,e=>ln(e,11)<<24|ln(e,13)<<16|ln(e,9)<<8|ln(e,14)),wn=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=an(n))e[t]=n;return e})();function bn(e){Ct(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:n}=pn,r=zt(e),s=r.length,o=e=>vn(n,e,e,e,e),i=new Uint32Array(t+28);i.set(r);for(let e=s;e<i.length;e++){let t=i[e-1];e%s===0?t=o(hn(t))^wn[e/s-1]:s>6&&e%s===4&&(t=o(t)),i[e]=i[e-s]^t}return i}function yn(e){const t=bn(e),n=t.slice(),r=t.length,{sbox2:s}=pn,{T0:o,T1:i,T2:a,T3:l}=gn;for(let e=0;e<r;e+=4)for(let s=0;s<4;s++)n[e+s]=t[r-e-4+s];t.fill(0);for(let e=4;e<r-4;e++){const t=n[e],r=vn(s,t,t,t,t);n[e]=o[255&r]^i[r>>>8&255]^a[r>>>16&255]^l[r>>>24]}return n}function mn(e,t,n,r,s,o){return e[n<<8&65280|r>>>8&255]^t[s>>>8&65280|o>>>24&255]}function vn(e,t,n,r,s){return e[255&t|65280&n]|e[r>>>16&255|s>>>16&65280]<<16}function kn(e,t,n,r,s){const{sbox2:o,T01:i,T23:a}=pn;let l=0;t^=e[l++],n^=e[l++],r^=e[l++],s^=e[l++];const c=e.length/4-2;for(let o=0;o<c;o++){const o=e[l++]^mn(i,a,t,n,r,s),c=e[l++]^mn(i,a,n,r,s,t),u=e[l++]^mn(i,a,r,s,t,n),h=e[l++]^mn(i,a,s,t,n,r);t=o,n=c,r=u,s=h}return{s0:e[l++]^vn(o,t,n,r,s),s1:e[l++]^vn(o,n,r,s,t),s2:e[l++]^vn(o,r,s,t,n),s3:e[l++]^vn(o,s,t,n,r)}}function xn(e,t,n,r,s){const{sbox2:o,T01:i,T23:a}=gn;let l=0;t^=e[l++],n^=e[l++],r^=e[l++],s^=e[l++];const c=e.length/4-2;for(let o=0;o<c;o++){const o=e[l++]^mn(i,a,t,s,r,n),c=e[l++]^mn(i,a,n,t,s,r),u=e[l++]^mn(i,a,r,n,t,s),h=e[l++]^mn(i,a,s,r,n,t);t=o,n=c,r=u,s=h}return{s0:e[l++]^vn(o,t,s,r,n),s1:e[l++]^vn(o,n,t,s,r),s2:e[l++]^vn(o,r,n,t,s),s3:e[l++]^vn(o,s,r,n,t)}}function En(e,t){if(!t)return new Uint8Array(e);if(Ct(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function Sn(e,t,n,r,s){Ct(n,sn),Ct(r),s=En(r.length,s);const o=n,i=zt(o),a=qt(o),l=zt(r),c=zt(s),u=t?0:12,h=r.length;let d=a.getUint32(u,t),{s0:f,s1:p,s2:g,s3:w}=kn(e,i[0],i[1],i[2],i[3]);for(let n=0;n+4<=l.length;n+=4)c[n+0]=l[n+0]^f,c[n+1]=l[n+1]^p,c[n+2]=l[n+2]^g,c[n+3]=l[n+3]^w,d=d+1>>>0,a.setUint32(u,d,t),({s0:f,s1:p,s2:g,s3:w}=kn(e,i[0],i[1],i[2],i[3]));const b=sn*Math.floor(l.length/4);if(b<h){const e=new Uint32Array([f,p,g,w]),t=Ot(e);for(let e=b,n=0;e<h;e++,n++)s[e]=r[e]^t[n]}return s}function An(e){if(Ct(e),e.length%sn!==0)throw new Error("aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size 16")}function Tn(e,t,n){let r=e.length;const s=r%sn;if(!t&&0!==s)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const o=zt(e);if(t){let e=sn-s;e||(e=sn),r+=e}const i=En(r,n);return{b:o,o:zt(i),out:i}}function $n(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const s=e.subarray(0,-r);for(let t=0;t<r;t++)if(e[n-t-1]!==r)throw new Error("aes/pcks5: wrong padding");return s}function Rn(e){const t=new Uint8Array(16),n=zt(t);t.set(e);const r=sn-e.length;for(let e=sn-r;e<sn;e++)t[e]=r;return n}Wt({blockSize:16,nonceLength:16},function(e,t){function n(n,r){const s=bn(e),o=t.slice(),i=function(e,t,n,r){Ct(t,sn),Ct(n);const s=n.length;r=En(s,r);const o=t,i=zt(o);let{s0:a,s1:l,s2:c,s3:u}=kn(e,i[0],i[1],i[2],i[3]);const h=zt(n),d=zt(r);for(let t=0;t+4<=h.length;t+=4){d[t+0]=h[t+0]^a,d[t+1]=h[t+1]^l,d[t+2]=h[t+2]^c,d[t+3]=h[t+3]^u;let n=1;for(let e=o.length-1;e>=0;e--)n=n+(255&o[e])|0,o[e]=255&n,n>>>=8;({s0:a,s1:l,s2:c,s3:u}=kn(e,i[0],i[1],i[2],i[3]))}const f=sn*Math.floor(h.length/4);if(f<s){const e=new Uint32Array([a,l,c,u]),t=Ot(e);for(let e=f,o=0;e<s;e++,o++)r[e]=n[e]^t[o]}return r}(s,o,n,r);return s.fill(0),o.fill(0),i}return Ct(e),Ct(t,sn),{encrypt:(e,t)=>n(e,t),decrypt:(e,t)=>n(e,t)}}),Wt({blockSize:16},function(e,t={}){Ct(e);const n=!t.disablePadding;return{encrypt:(t,r)=>{Ct(t);const{b:s,o,out:i}=Tn(t,n,r),a=bn(e);let l=0;for(;l+4<=s.length;){const{s0:e,s1:t,s2:n,s3:r}=kn(a,s[l+0],s[l+1],s[l+2],s[l+3]);o[l++]=e,o[l++]=t,o[l++]=n,o[l++]=r}if(n){const e=Rn(t.subarray(4*l)),{s0:n,s1:r,s2:s,s3:i}=kn(a,e[0],e[1],e[2],e[3]);o[l++]=n,o[l++]=r,o[l++]=s,o[l++]=i}return a.fill(0),i},decrypt:(t,r)=>{An(t);const s=yn(e),o=En(t.length,r),i=zt(t),a=zt(o);for(let e=0;e+4<=i.length;){const{s0:t,s1:n,s2:r,s3:o}=xn(s,i[e+0],i[e+1],i[e+2],i[e+3]);a[e++]=t,a[e++]=n,a[e++]=r,a[e++]=o}return s.fill(0),$n(o,n)}}});const In=Wt({blockSize:16,nonceLength:16},function(e,t,n={}){Ct(e),Ct(t,16);const r=!n.disablePadding;return{encrypt:(n,s)=>{const o=bn(e),{b:i,o:a,out:l}=Tn(n,r,s),c=zt(t);let u=c[0],h=c[1],d=c[2],f=c[3],p=0;for(;p+4<=i.length;)u^=i[p+0],h^=i[p+1],d^=i[p+2],f^=i[p+3],({s0:u,s1:h,s2:d,s3:f}=kn(o,u,h,d,f)),a[p++]=u,a[p++]=h,a[p++]=d,a[p++]=f;if(r){const e=Rn(n.subarray(4*p));u^=e[0],h^=e[1],d^=e[2],f^=e[3],({s0:u,s1:h,s2:d,s3:f}=kn(o,u,h,d,f)),a[p++]=u,a[p++]=h,a[p++]=d,a[p++]=f}return o.fill(0),l},decrypt:(n,s)=>{An(n);const o=yn(e),i=zt(t),a=En(n.length,s),l=zt(n),c=zt(a);let u=i[0],h=i[1],d=i[2],f=i[3];for(let e=0;e+4<=l.length;){const t=u,n=h,r=d,s=f;u=l[e+0],h=l[e+1],d=l[e+2],f=l[e+3];const{s0:i,s1:a,s2:p,s3:g}=xn(o,u,h,d,f);c[e++]=i^t,c[e++]=a^n,c[e++]=p^r,c[e++]=g^s}return o.fill(0),$n(a,r)}}});function Bn(e,t,n,r,s){const o=e.create(n,r.length+(s?.length||0));s&&o.update(s),o.update(r);const i=new Uint8Array(16),a=qt(i);return s&&Zt(a,0,BigInt(8*s.length),t),Zt(a,8,BigInt(8*r.length),t),o.update(i),o.digest()}Wt({blockSize:16,nonceLength:16},function(e,t){function n(n,r,s){const o=bn(e),i=n.length;s=En(i,s);const a=zt(n),l=zt(s),c=r?l:a,u=zt(t);let h=u[0],d=u[1],f=u[2],p=u[3];for(let e=0;e+4<=a.length;){const{s0:t,s1:n,s2:r,s3:s}=kn(o,h,d,f,p);l[e+0]=a[e+0]^t,l[e+1]=a[e+1]^n,l[e+2]=a[e+2]^r,l[e+3]=a[e+3]^s,h=c[e++],d=c[e++],f=c[e++],p=c[e++]}const g=sn*Math.floor(a.length/4);if(g<i){({s0:h,s1:d,s2:f,s3:p}=kn(o,h,d,f,p));const e=Ot(new Uint32Array([h,d,f,p]));for(let t=g,r=0;t<i;t++,r++)s[t]=n[t]^e[r];e.fill(0)}return o.fill(0),s}return Ct(e),Ct(t,16),{encrypt:(e,t)=>n(e,!0,t),decrypt:(e,t)=>n(e,!1,t)}}),Wt({blockSize:16,nonceLength:12,tagLength:16},function(e,t,n){if(Ct(t),0===t.length)throw new Error("aes/gcm: empty nonce");function r(e,t,r){const s=Bn(nn,!1,e,r,n);for(let e=0;e<t.length;e++)s[e]^=t[e];return s}function s(){const n=bn(e),r=on.slice(),s=on.slice();if(Sn(n,!1,s,s,r),12===t.length)s.set(t);else{const e=on.slice();Zt(qt(e),8,BigInt(8*t.length),!1),nn.create(r).update(t).update(e).digestInto(s)}return{xk:n,authKey:r,counter:s,tagMask:Sn(n,!1,s,on)}}return{encrypt:e=>{Ct(e);const{xk:t,authKey:n,counter:o,tagMask:i}=s(),a=new Uint8Array(e.length+16);Sn(t,!1,o,e,a);const l=r(n,i,a.subarray(0,a.length-16));return a.set(l,e.length),t.fill(0),a},decrypt:e=>{if(Ct(e),e.length<16)throw new Error("aes/gcm: ciphertext less than tagLen (16)");const{xk:t,authKey:n,counter:o,tagMask:i}=s(),a=e.subarray(0,-16),l=e.subarray(-16);if(!Vt(r(n,i,a),l))throw new Error("aes/gcm: invalid ghash tag");const c=Sn(t,!1,o,a);return n.fill(0),i.fill(0),t.fill(0),c}}});const Ln=(e,t,n)=>r=>{if(!Number.isSafeInteger(r)||t>r||r>n)throw new Error(`${e}: invalid value=${r}, must be [${t}..${n}]`)};Wt({blockSize:16,nonceLength:12,tagLength:16},function(e,t,n){const r=Ln("AAD",0,2**36),s=Ln("plaintext",0,2**36),o=Ln("nonce",12,12),i=Ln("ciphertext",16,2**36+16);function a(){const n=e.length;if(16!==n&&24!==n&&32!==n)throw new Error(`key length must be 16, 24 or 32 bytes, got: ${n} bytes`);const r=bn(e),s=new Uint8Array(n),o=new Uint8Array(16),i=zt(t);let a=0,l=i[0],c=i[1],u=i[2],h=0;for(const e of[o,s].map(zt)){const t=zt(e);for(let e=0;e<t.length;e+=2){const{s0:n,s1:s}=kn(r,a,l,c,u);t[e+0]=n,t[e+1]=s,a=++h}}return r.fill(0),{authKey:o,encKey:bn(s)}}function l(e,r,s){const o=Bn(rn,!0,r,s,n);for(let e=0;e<12;e++)o[e]^=t[e];o[15]&=127;const i=zt(o);let a=i[0],l=i[1],c=i[2],u=i[3];return({s0:a,s1:l,s2:c,s3:u}=kn(e,a,l,c,u)),i[0]=a,i[1]=l,i[2]=c,i[3]=u,o}function c(e,t,n){let r=t.slice();return r[15]|=128,Sn(e,!0,r,n)}return Ct(t),o(t.length),n&&(Ct(n),r(n.length)),{encrypt:e=>{Ct(e),s(e.length);const{encKey:t,authKey:n}=a(),r=l(t,n,e),o=new Uint8Array(e.length+16);return o.set(r,e.length),o.set(c(t,r,e)),t.fill(0),n.fill(0),o},decrypt:e=>{Ct(e),i(e.length);const t=e.subarray(-16),{encKey:n,authKey:r}=a(),s=c(n,t,e.subarray(0,-16)),o=l(n,r,s);if(n.fill(0),r.fill(0),!Vt(t,o))throw new Error("invalid polyval tag");return s}}});const _n=(e,t)=>255&e[t++]|(255&e[t++])<<8;class Pn{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,Ct(e=Ft(e),32);const t=_n(e,0),n=_n(e,2),r=_n(e,4),s=_n(e,6),o=_n(e,8),i=_n(e,10),a=_n(e,12),l=_n(e,14);this.r[0]=8191&t,this.r[1]=8191&(t>>>13|n<<3),this.r[2]=7939&(n>>>10|r<<6),this.r[3]=8191&(r>>>7|s<<9),this.r[4]=255&(s>>>4|o<<12),this.r[5]=o>>>1&8190,this.r[6]=8191&(o>>>14|i<<2),this.r[7]=8065&(i>>>11|a<<5),this.r[8]=8191&(a>>>8|l<<8),this.r[9]=l>>>5&127;for(let t=0;t<8;t++)this.pad[t]=_n(e,16+2*t)}process(e,t,n=!1){const r=n?0:2048,{h:s,r:o}=this,i=o[0],a=o[1],l=o[2],c=o[3],u=o[4],h=o[5],d=o[6],f=o[7],p=o[8],g=o[9],w=_n(e,t+0),b=_n(e,t+2),y=_n(e,t+4),m=_n(e,t+6),v=_n(e,t+8),k=_n(e,t+10),x=_n(e,t+12),E=_n(e,t+14);let S=s[0]+(8191&w),A=s[1]+(8191&(w>>>13|b<<3)),T=s[2]+(8191&(b>>>10|y<<6)),$=s[3]+(8191&(y>>>7|m<<9)),R=s[4]+(8191&(m>>>4|v<<12)),I=s[5]+(v>>>1&8191),B=s[6]+(8191&(v>>>14|k<<2)),L=s[7]+(8191&(k>>>11|x<<5)),_=s[8]+(8191&(x>>>8|E<<8)),P=s[9]+(E>>>5|r),C=0,U=C+S*i+A*(5*g)+T*(5*p)+$*(5*f)+R*(5*d);C=U>>>13,U&=8191,U+=I*(5*h)+B*(5*u)+L*(5*c)+_*(5*l)+P*(5*a),C+=U>>>13,U&=8191;let N=C+S*a+A*i+T*(5*g)+$*(5*p)+R*(5*f);C=N>>>13,N&=8191,N+=I*(5*d)+B*(5*h)+L*(5*u)+_*(5*c)+P*(5*l),C+=N>>>13,N&=8191;let O=C+S*l+A*a+T*i+$*(5*g)+R*(5*p);C=O>>>13,O&=8191,O+=I*(5*f)+B*(5*d)+L*(5*h)+_*(5*u)+P*(5*c),C+=O>>>13,O&=8191;let z=C+S*c+A*l+T*a+$*i+R*(5*g);C=z>>>13,z&=8191,z+=I*(5*p)+B*(5*f)+L*(5*d)+_*(5*h)+P*(5*u),C+=z>>>13,z&=8191;let q=C+S*u+A*c+T*l+$*a+R*i;C=q>>>13,q&=8191,q+=I*(5*g)+B*(5*p)+L*(5*f)+_*(5*d)+P*(5*h),C+=q>>>13,q&=8191;let M=C+S*h+A*u+T*c+$*l+R*a;C=M>>>13,M&=8191,M+=I*i+B*(5*g)+L*(5*p)+_*(5*f)+P*(5*d),C+=M>>>13,M&=8191;let H=C+S*d+A*h+T*u+$*c+R*l;C=H>>>13,H&=8191,H+=I*a+B*i+L*(5*g)+_*(5*p)+P*(5*f),C+=H>>>13,H&=8191;let j=C+S*f+A*d+T*h+$*u+R*c;C=j>>>13,j&=8191,j+=I*l+B*a+L*i+_*(5*g)+P*(5*p),C+=j>>>13,j&=8191;let D=C+S*p+A*f+T*d+$*h+R*u;C=D>>>13,D&=8191,D+=I*c+B*l+L*a+_*i+P*(5*g),C+=D>>>13,D&=8191;let F=C+S*g+A*p+T*f+$*d+R*h;C=F>>>13,F&=8191,F+=I*u+B*c+L*l+_*a+P*i,C+=F>>>13,F&=8191,C=(C<<2)+C|0,C=C+U|0,U=8191&C,C>>>=13,N+=C,s[0]=U,s[1]=N,s[2]=O,s[3]=z,s[4]=q,s[5]=M,s[6]=H,s[7]=j,s[8]=D,s[9]=F}finalize(){const{h:e,pad:t}=this,n=new Uint16Array(10);let r=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=r,r=e[t]>>>13,e[t]&=8191;e[0]+=5*r,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(let t=1;t<10;t++)n[t]=e[t]+r,r=n[t]>>>13,n[t]&=8191;n[9]-=8192;let s=(1^r)-1;for(let e=0;e<10;e++)n[e]&=s;s=~s;for(let t=0;t<10;t++)e[t]=e[t]&s|n[t];e[0]=65535&(e[0]|e[1]<<13),e[1]=65535&(e[1]>>>3|e[2]<<10),e[2]=65535&(e[2]>>>6|e[3]<<7),e[3]=65535&(e[3]>>>9|e[4]<<4),e[4]=65535&(e[4]>>>12|e[5]<<1|e[6]<<14),e[5]=65535&(e[6]>>>2|e[7]<<11),e[6]=65535&(e[7]>>>5|e[8]<<8),e[7]=65535&(e[8]>>>8|e[9]<<5);let o=e[0]+t[0];e[0]=65535&o;for(let n=1;n<8;n++)o=(e[n]+t[n]|0)+(o>>>16)|0,e[n]=65535&o}update(e){Ut(this);const{buffer:t,blockLen:n}=this,r=(e=Ft(e)).length;for(let s=0;s<r;){const o=Math.min(n-this.pos,r-s);if(o!==n)t.set(e.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===n&&(this.process(t,0,!1),this.pos=0);else for(;n<=r-s;s+=n)this.process(e,s)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){Ut(this),Nt(e,this),this.finished=!0;const{buffer:t,h:n}=this;let{pos:r}=this;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();let s=0;for(let t=0;t<8;t++)e[s++]=n[t]>>>0,e[s++]=n[t]>>>8;return e}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}}const Cn=function(e){const t=(t,n)=>e(n).update(Ft(t)).digest(),n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t}(e=>new Pn(e)),Un=e=>Uint8Array.from(e.split("").map(e=>e.charCodeAt(0))),Nn=Un("expand 16-byte k"),On=Un("expand 32-byte k"),zn=zt(Nn),qn=zt(On);function Mn(e,t){return e<<t|e>>>32-t}function Hn(e){return e.byteOffset%4==0}qn.slice();const jn=2**32-1,Dn=new Uint32Array;function Fn(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:s,counterRight:o,rounds:i}=function(e,t){if(null==t||"object"!=typeof t)throw new Error("options must be defined");return Object.assign({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t)}(0,t);if("function"!=typeof e)throw new Error("core must be a function");return Lt(s),Lt(i),_t(o),_t(n),(t,a,l,c,u=0)=>{Ct(t),Ct(a),Ct(l);const h=l.length;if(c||(c=new Uint8Array(h)),Ct(c),Lt(u),u<0||u>=jn)throw new Error("arx: counter overflow");if(c.length<h)throw new Error(`arx: output (${c.length}) is shorter than data (${h})`);const d=[];let f,p,g=t.length;if(32===g)f=t.slice(),d.push(f),p=qn;else{if(16!==g||!n)throw new Error(`arx: invalid 32-byte key, got length=${g}`);f=new Uint8Array(32),f.set(t),f.set(t,16),p=zn,d.push(f)}Hn(a)||(a=a.slice(),d.push(a));const w=zt(f);if(r){if(24!==a.length)throw new Error("arx: extended nonce must be 24 bytes");r(p,w,zt(a.subarray(0,16)),w),a=a.subarray(16)}const b=16-s;if(b!==a.length)throw new Error(`arx: nonce must be ${b} or 16 bytes`);if(12!==b){const e=new Uint8Array(12);e.set(a,o?0:12-a.length),a=e,d.push(a)}const y=zt(a);for(function(e,t,n,r,s,o,i,a){const l=s.length,c=new Uint8Array(64),u=zt(c),h=Hn(s)&&Hn(o),d=h?zt(s):Dn,f=h?zt(o):Dn;for(let p=0;p<l;i++){if(e(t,n,r,u,i,a),i>=jn)throw new Error("arx: counter overflow");const g=Math.min(64,l-p);if(h&&64===g){const e=p/4;if(p%4!=0)throw new Error("arx: invalid block position");for(let t,n=0;n<16;n++)t=e+n,f[t]=d[t]^u[n];p+=64;continue}for(let e,t=0;t<g;t++)e=p+t,o[e]=s[e]^c[t];p+=g}}(e,p,w,y,l,c,u,i);d.length>0;)d.pop().fill(0);return c}}function Vn(e,t,n,r,s,o=20){let i=e[0],a=e[1],l=e[2],c=e[3],u=t[0],h=t[1],d=t[2],f=t[3],p=t[4],g=t[5],w=t[6],b=t[7],y=s,m=n[0],v=n[1],k=n[2],x=i,E=a,S=l,A=c,T=u,$=h,R=d,I=f,B=p,L=g,_=w,P=b,C=y,U=m,N=v,O=k;for(let e=0;e<o;e+=2)x=x+T|0,C=Mn(C^x,16),B=B+C|0,T=Mn(T^B,12),x=x+T|0,C=Mn(C^x,8),B=B+C|0,T=Mn(T^B,7),E=E+$|0,U=Mn(U^E,16),L=L+U|0,$=Mn($^L,12),E=E+$|0,U=Mn(U^E,8),L=L+U|0,$=Mn($^L,7),S=S+R|0,N=Mn(N^S,16),_=_+N|0,R=Mn(R^_,12),S=S+R|0,N=Mn(N^S,8),_=_+N|0,R=Mn(R^_,7),A=A+I|0,O=Mn(O^A,16),P=P+O|0,I=Mn(I^P,12),A=A+I|0,O=Mn(O^A,8),P=P+O|0,I=Mn(I^P,7),x=x+$|0,O=Mn(O^x,16),_=_+O|0,$=Mn($^_,12),x=x+$|0,O=Mn(O^x,8),_=_+O|0,$=Mn($^_,7),E=E+R|0,C=Mn(C^E,16),P=P+C|0,R=Mn(R^P,12),E=E+R|0,C=Mn(C^E,8),P=P+C|0,R=Mn(R^P,7),S=S+I|0,U=Mn(U^S,16),B=B+U|0,I=Mn(I^B,12),S=S+I|0,U=Mn(U^S,8),B=B+U|0,I=Mn(I^B,7),A=A+T|0,N=Mn(N^A,16),L=L+N|0,T=Mn(T^L,12),A=A+T|0,N=Mn(N^A,8),L=L+N|0,T=Mn(T^L,7);let z=0;r[z++]=i+x|0,r[z++]=a+E|0,r[z++]=l+S|0,r[z++]=c+A|0,r[z++]=u+T|0,r[z++]=h+$|0,r[z++]=d+R|0,r[z++]=f+I|0,r[z++]=p+B|0,r[z++]=g+L|0,r[z++]=w+_|0,r[z++]=b+P|0,r[z++]=y+C|0,r[z++]=m+U|0,r[z++]=v+N|0,r[z++]=k+O|0}const Wn=Fn(Vn,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Zn=Fn(Vn,{counterRight:!1,counterLength:8,extendNonceFn:function(e,t,n,r){let s=e[0],o=e[1],i=e[2],a=e[3],l=t[0],c=t[1],u=t[2],h=t[3],d=t[4],f=t[5],p=t[6],g=t[7],w=n[0],b=n[1],y=n[2],m=n[3];for(let e=0;e<20;e+=2)s=s+l|0,w=Mn(w^s,16),d=d+w|0,l=Mn(l^d,12),s=s+l|0,w=Mn(w^s,8),d=d+w|0,l=Mn(l^d,7),o=o+c|0,b=Mn(b^o,16),f=f+b|0,c=Mn(c^f,12),o=o+c|0,b=Mn(b^o,8),f=f+b|0,c=Mn(c^f,7),i=i+u|0,y=Mn(y^i,16),p=p+y|0,u=Mn(u^p,12),i=i+u|0,y=Mn(y^i,8),p=p+y|0,u=Mn(u^p,7),a=a+h|0,m=Mn(m^a,16),g=g+m|0,h=Mn(h^g,12),a=a+h|0,m=Mn(m^a,8),g=g+m|0,h=Mn(h^g,7),s=s+c|0,m=Mn(m^s,16),p=p+m|0,c=Mn(c^p,12),s=s+c|0,m=Mn(m^s,8),p=p+m|0,c=Mn(c^p,7),o=o+u|0,w=Mn(w^o,16),g=g+w|0,u=Mn(u^g,12),o=o+u|0,w=Mn(w^o,8),g=g+w|0,u=Mn(u^g,7),i=i+h|0,b=Mn(b^i,16),d=d+b|0,h=Mn(h^d,12),i=i+h|0,b=Mn(b^i,8),d=d+b|0,h=Mn(h^d,7),a=a+l|0,y=Mn(y^a,16),f=f+y|0,l=Mn(l^f,12),a=a+l|0,y=Mn(y^a,8),f=f+y|0,l=Mn(l^f,7);let v=0;r[v++]=s,r[v++]=o,r[v++]=i,r[v++]=a,r[v++]=w,r[v++]=b,r[v++]=y,r[v++]=m},allowShortKeys:!1}),Kn=new Uint8Array(16),Yn=(e,t)=>{e.update(t);const n=t.length%16;n&&e.update(Kn.subarray(n))},Gn=new Uint8Array(32);function Jn(e,t,n,r,s){const o=e(t,n,Gn),i=Cn.create(o);s&&Yn(i,s),Yn(i,r);const a=new Uint8Array(16),l=qt(a);Zt(l,0,BigInt(s?s.length:0),!0),Zt(l,8,BigInt(r.length),!0),i.update(a);const c=i.digest();return o.fill(0),c}const Qn=e=>(t,n,r)=>(Ct(t,32),Ct(n),{encrypt:(s,o)=>{const i=s.length,a=i+16;o?Ct(o,a):o=new Uint8Array(a),e(t,n,s,o,1);const l=Jn(e,t,n,o.subarray(0,-16),r);return o.set(l,i),o},decrypt:(s,o)=>{const i=s.length,a=i-16;if(i<16)throw new Error("encrypted data must be at least 16 bytes");o?Ct(o,a):o=new Uint8Array(a);const l=s.subarray(0,-16);if(!Vt(s.subarray(-16),Jn(e,t,n,l,r)))throw new Error("invalid tag");return e(t,n,l,o,1),o}});Qn(Wn),Qn(Zn);class Xn extends Ye{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,tt.hash(e);const n=Ze(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,s=new Uint8Array(r);s.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<s.length;e++)s[e]^=54;this.iHash.update(s),this.oHash=e.create();for(let e=0;e<s.length;e++)s[e]^=106;this.oHash.update(s),s.fill(0)}update(e){return tt.exists(this),this.iHash.update(e),this}digestInto(e){tt.exists(this),tt.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:t,iHash:n,finished:r,destroyed:s,blockLen:o,outputLen:i}=this;return e.finished=r,e.destroyed=s,e.blockLen=o,e.outputLen=i,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const er=(e,t,n)=>new Xn(e,t).update(n).digest();er.create=(e,t)=>new Xn(e,t);const tr=new Uint8Array([0]),nr=new Uint8Array;var rr=Object.defineProperty,sr=(e,t)=>{for(var n in t)rr(e,n,{get:t[n],enumerable:!0})},or=Symbol("verified");function ir(e){if(!(e instanceof Object))return!1;if("number"!=typeof e.kind)return!1;if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if("string"!=typeof e.pubkey)return!1;if(!e.pubkey.match(/^[a-f0-9]{64}$/))return!1;if(!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let e=0;e<n.length;e++)if("string"!=typeof n[e])return!1}return!0}sr({},{Queue:()=>pr,QueueNode:()=>fr,binarySearch:()=>dr,bytesToHex:()=>Ve,hexToBytes:()=>We,insertEventIntoAscendingList:()=>hr,insertEventIntoDescendingList:()=>ur,normalizeURL:()=>cr,utf8Decoder:()=>ar,utf8Encoder:()=>lr});var ar=new TextDecoder("utf-8"),lr=new TextEncoder;function cr(e){try{-1===e.indexOf("://")&&(e="wss://"+e);let t=new URL(e);return"http:"===t.protocol?t.protocol="ws:":"https:"===t.protocol&&(t.protocol="wss:"),t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),("80"===t.port&&"ws:"===t.protocol||"443"===t.port&&"wss:"===t.protocol)&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch(t){throw new Error(`Invalid URL: ${e}`)}}function ur(e,t){const[n,r]=dr(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:e.created_at-t.created_at);return r||e.splice(n,0,t),e}function hr(e,t){const[n,r]=dr(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:t.created_at-e.created_at);return r||e.splice(n,0,t),e}function dr(e,t){let n=0,r=e.length-1;for(;n<=r;){const s=Math.floor((n+r)/2),o=t(e[s]);if(0===o)return[s,!0];o<0?r=s-1:n=s+1}return[n,!1]}var fr=class{value;next=null;prev=null;constructor(e){this.value=e}},pr=class{first;last;constructor(){this.first=null,this.last=null}enqueue(e){const t=new fr(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const e=this.first;return this.first=null,this.last=null,e.value}const e=this.first;return this.first=e.next,this.first&&(this.first.prev=null),e.value}};function gr(e){return Ve(ut(lr.encode(function(e){if(!ir(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}(e))))}var wr=new class{generateSecretKey(){return qe.utils.randomPrivateKey()}getPublicKey(e){return Ve(qe.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=Ve(qe.getPublicKey(t)),n.id=gr(n),n.sig=Ve(qe.sign(gr(n),t)),n[or]=!0,n}verifyEvent(e){if("boolean"==typeof e[or])return e[or];const t=gr(e);if(t!==e.id)return e[or]=!1,!1;try{const n=qe.verify(e.sig,t,e.pubkey);return e[or]=n,n}catch(t){return e[or]=!1,!1}}},br=wr.generateSecretKey,yr=wr.getPublicKey,mr=wr.finalizeEvent,vr=wr.verifyEvent;function kr(e){return e<1e4&&0!==e&&3!==e}function xr(e){return 0===e||3===e||1e4<=e&&e<2e4}function Er(e){return 2e4<=e&&e<3e4}function Sr(e){return 3e4<=e&&e<4e4}function Ar(e){return kr(e)?"regular":xr(e)?"replaceable":Er(e)?"ephemeral":Sr(e)?"parameterized":"unknown"}function Tr(e,t){const n=t instanceof Array?t:[t];return ir(e)&&n.includes(e.kind)||!1}sr({},{Application:()=>Js,BadgeAward:()=>Ur,BadgeDefinition:()=>Fs,BlockedRelaysList:()=>Es,BlossomServerList:()=>Bs,BookmarkList:()=>vs,Bookmarksets:()=>Hs,Calendar:()=>so,CalendarEventRSVP:()=>oo,ChannelCreation:()=>Vr,ChannelHideMessage:()=>Kr,ChannelMessage:()=>Zr,ChannelMetadata:()=>Wr,ChannelMuteUser:()=>Yr,ChatMessage:()=>Nr,ClassifiedListing:()=>eo,ClientAuth:()=>Ps,Comment:()=>es,CommunitiesList:()=>ks,CommunityDefinition:()=>co,CommunityPostApproval:()=>ls,Contacts:()=>Br,CreateOrUpdateProduct:()=>Zs,CreateOrUpdateStall:()=>Ws,Curationsets:()=>js,Date:()=>no,DirectMessageRelaysList:()=>Rs,DraftClassifiedListing:()=>to,DraftLong:()=>Ys,Emojisets:()=>Gs,EncryptedDirectMessage:()=>Lr,EventDeletion:()=>_r,FavoriteRelays:()=>As,FileMessage:()=>Mr,FileMetadata:()=>Xr,FileServerPreference:()=>Is,Followsets:()=>zs,ForumThread:()=>Or,GenericRepost:()=>Hr,Genericlists:()=>qs,GiftWrap:()=>Jr,GroupMetadata:()=>uo,HTTPAuth:()=>Os,Handlerinformation:()=>lo,Handlerrecommendation:()=>ao,Highlights:()=>gs,InterestsList:()=>Ts,Interestsets:()=>Vs,JobFeedback:()=>hs,JobRequest:()=>cs,JobResult:()=>us,Label:()=>as,LightningPubRPC:()=>_s,LiveChatMessage:()=>ts,LiveEvent:()=>Qs,LongFormArticle:()=>Ks,Metadata:()=>$r,Mutelist:()=>bs,NWCWalletInfo:()=>Ls,NWCWalletRequest:()=>Cs,NWCWalletResponse:()=>Us,NormalVideo:()=>Dr,NostrConnect:()=>Ns,OpenTimestamps:()=>Gr,Photo:()=>jr,Pinlist:()=>ys,Poll:()=>Qr,PollResponse:()=>ws,PrivateDirectMessage:()=>qr,ProblemTracker:()=>ss,ProfileBadges:()=>Ds,PublicChatsList:()=>xs,Reaction:()=>Cr,RecommendRelay:()=>Ir,RelayList:()=>ms,RelayReview:()=>io,Relaysets:()=>Ms,Report:()=>os,Reporting:()=>is,Repost:()=>Pr,Seal:()=>zr,SearchRelaysList:()=>Ss,ShortTextNote:()=>Rr,ShortVideo:()=>Fr,Time:()=>ro,UserEmojiList:()=>$s,UserStatuses:()=>Xs,Voice:()=>ns,VoiceComment:()=>rs,Zap:()=>ps,ZapGoal:()=>ds,ZapRequest:()=>fs,classifyKind:()=>Ar,isAddressableKind:()=>Sr,isEphemeralKind:()=>Er,isKind:()=>Tr,isRegularKind:()=>kr,isReplaceableKind:()=>xr});var $r=0,Rr=1,Ir=2,Br=3,Lr=4,_r=5,Pr=6,Cr=7,Ur=8,Nr=9,Or=11,zr=13,qr=14,Mr=15,Hr=16,jr=20,Dr=21,Fr=22,Vr=40,Wr=41,Zr=42,Kr=43,Yr=44,Gr=1040,Jr=1059,Qr=1068,Xr=1063,es=1111,ts=1311,ns=1222,rs=1244,ss=1971,os=1984,is=1984,as=1985,ls=4550,cs=5999,us=6999,hs=7e3,ds=9041,fs=9734,ps=9735,gs=9802,ws=1018,bs=1e4,ys=10001,ms=10002,vs=10003,ks=10004,xs=10005,Es=10006,Ss=10007,As=10012,Ts=10015,$s=10030,Rs=10050,Is=10096,Bs=10063,Ls=13194,_s=21e3,Ps=22242,Cs=23194,Us=23195,Ns=24133,Os=27235,zs=3e4,qs=30001,Ms=30002,Hs=30003,js=30004,Ds=30008,Fs=30009,Vs=30015,Ws=30017,Zs=30018,Ks=30023,Ys=30024,Gs=30030,Js=30078,Qs=30311,Xs=30315,eo=30402,to=30403,no=31922,ro=31923,so=31924,oo=31925,io=31987,ao=31989,lo=31990,co=34550,uo=39e3;function ho(e,t){if(e.ids&&-1===e.ids.indexOf(t.id))return!1;if(e.kinds&&-1===e.kinds.indexOf(t.kind))return!1;if(e.authors&&-1===e.authors.indexOf(t.pubkey))return!1;for(let n in e)if("#"===n[0]){let r=e[`#${n.slice(1)}`];if(r&&!t.tags.find(([e,t])=>e===n.slice(1)&&-1!==r.indexOf(t)))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function fo(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,s=e.slice(r).indexOf('"')+r+1;return e.slice(s,s+64)}function po(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,s=e.slice(r),o=Math.min(s.indexOf(","),s.indexOf("}"));return parseInt(s.slice(0,o),10)}function go(e){let t=e.slice(0,22).indexOf('"EVENT"');if(-1===t)return null;let n=e.slice(t+7+1).indexOf('"');if(-1===n)return null;let r=t+7+1+n,s=e.slice(r+1,80).indexOf('"');if(-1===s)return null;let o=r+1+s;return e.slice(r+1,o)}function wo(e,t){return t===fo(e,"id")}function bo(e,t){return t===fo(e,"pubkey")}function yo(e,t){return t===po(e,"kind")}function mo(e,t){return{kind:Ps,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function vo(){return new Promise((e,t)=>{try{if("undefined"!=typeof MessageChannel){const t=new MessageChannel,n=()=>{t.port1.removeEventListener("message",n),e()};t.port1.addEventListener("message",n),t.port2.postMessage(0),t.port1.start()}else"undefined"!=typeof setImmediate?setImmediate(e):"undefined"!=typeof setTimeout?setTimeout(e,0):e()}catch(e){console.error("during yield: ",e),t(e)}})}sr({},{getHex64:()=>fo,getInt:()=>po,getSubscriptionId:()=>go,matchEventId:()=>wo,matchEventKind:()=>yo,matchEventPubkey:()=>bo}),sr({},{makeAuthEvent:()=>mo});var ko=e=>(e[or]=!0,!0),xo=class extends Error{constructor(e,t){super(`Tried to send message '${e} on a closed connection to ${t}.`),this.name="SendingOnClosedConnection"}},Eo=class{url;_connected=!1;onclose=null;onnotice=e=>console.debug(`NOTICE from ${this.url}: ${e}`);onauth;baseEoseTimeout=4400;connectionTimeout=4400;publishTimeout=4400;pingFrequency=29e3;pingTimeout=2e4;resubscribeBackoff=[1e4,1e4,1e4,2e4,2e4,3e4,6e4];openSubs=new Map;enablePing;enableReconnect;connectionTimeoutHandle;reconnectTimeoutHandle;pingIntervalHandle;reconnectAttempts=0;closedIntentionally=!1;connectionPromise;openCountRequests=new Map;openEventPublishes=new Map;ws;incomingMessageQueue=new pr;queueRunning=!1;challenge;authPromise;serial=0;verifyEvent;_WebSocket;constructor(e,t){this.url=cr(e),this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation||WebSocket,this.enablePing=t.enablePing,this.enableReconnect=t.enableReconnect||!1}static async connect(e,t){const n=new Eo(e,t);return await n.connect(),n}closeAllSubscriptions(e){for(let[t,n]of this.openSubs)n.close(e);this.openSubs.clear();for(let[t,n]of this.openEventPublishes)n.reject(new Error(e));this.openEventPublishes.clear();for(let[t,n]of this.openCountRequests)n.reject(new Error(e));this.openCountRequests.clear()}get connected(){return this._connected}async reconnect(){const e=this.resubscribeBackoff[Math.min(this.reconnectAttempts,this.resubscribeBackoff.length-1)];this.reconnectAttempts++,this.reconnectTimeoutHandle=setTimeout(async()=>{try{await this.connect()}catch(e){}},e)}handleHardClose(e){this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0;const t=this.closedIntentionally;this.closedIntentionally=!1,this.onclose?.(),this.enableReconnect&&!t?this.reconnect():this.closeAllSubscriptions(e)}async connect(){return this.connectionPromise||(this.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise((e,t)=>{this.connectionTimeoutHandle=setTimeout(()=>{t("connection timed out"),this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(e){return clearTimeout(this.connectionTimeoutHandle),void t(e)}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(this.connectionTimeoutHandle),this._connected=!0;const t=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const e of this.openSubs.values()){if(e.eosed=!1,t)for(let t=0;t<e.filters.length;t++)e.lastEmitted&&(e.filters[t].since=e.lastEmitted+1);e.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),e()},this.ws.onerror=e=>{clearTimeout(this.connectionTimeoutHandle),t(e.message||"websocket error"),this.handleHardClose("relay connection errored")},this.ws.onclose=e=>{clearTimeout(this.connectionTimeoutHandle),t(e.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)})),this.connectionPromise}waitForPingPong(){return new Promise(e=>{this.ws.once("pong",()=>e(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((e,t)=>{if(!this.connectionPromise)return t(new Error(`no connection to ${this.url}, can't ping`));try{const t=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"forced-ping",oneose:()=>{e(!0),t.close()},onclose(){e(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(e){t(e)}})}async pingpong(){1===this.ws?.readyState&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.once?this.waitForPingPong():this.waitForDummyReq(),new Promise(e=>setTimeout(()=>e(!1),this.pingTimeout))])||this.ws?.readyState===this._WebSocket.OPEN&&this.ws?.close())}async runQueue(){for(this.queueRunning=!0;!1!==this.handleNext();)await vo();this.queueRunning=!1}handleNext(){const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const t=go(e);if(t){const n=this.openSubs.get(t);if(!n)return;const r=fo(e,"id"),s=n.alreadyHaveEvent?.(r);if(n.receivedEvent?.(this,r),s)return}try{let t=JSON.parse(e);switch(t[0]){case"EVENT":{const e=this.openSubs.get(t[1]),n=t[2];return this.verifyEvent(n)&&function(e,t){for(let n=0;n<e.length;n++)if(ho(e[n],t))return!0;return!1}(e.filters,n)&&e.onevent(n),void((!e.lastEmitted||e.lastEmitted<n.created_at)&&(e.lastEmitted=n.created_at))}case"COUNT":{const e=t[1],n=t[2],r=this.openCountRequests.get(e);return void(r&&(r.resolve(n.count),this.openCountRequests.delete(e)))}case"EOSE":{const e=this.openSubs.get(t[1]);if(!e)return;return void e.receivedEose()}case"OK":{const e=t[1],n=t[2],r=t[3],s=this.openEventPublishes.get(e);return void(s&&(clearTimeout(s.timeout),n?s.resolve(r):s.reject(new Error(r)),this.openEventPublishes.delete(e)))}case"CLOSED":{const e=t[1],n=this.openSubs.get(e);if(!n)return;return n.closed=!0,void n.close(t[2])}case"NOTICE":return void this.onnotice(t[1]);case"AUTH":return this.challenge=t[1],void(this.onauth&&this.auth(this.onauth));default:{const e=this.openSubs.get(t[1]);return void e?.oncustom?.(t)}}}catch(e){return}}async send(e){if(!this.connectionPromise)throw new xo(e,this.url);this.connectionPromise.then(()=>{this.ws?.send(e)})}async auth(e){const t=this.challenge;if(!t)throw new Error("can't perform auth, no challenge was received");return this.authPromise||(this.authPromise=new Promise(async(n,r)=>{try{let s=await e(mo(this.url,t)),o=setTimeout(()=>{let e=this.openEventPublishes.get(s.id);e&&(e.reject(new Error("auth timed out")),this.openEventPublishes.delete(s.id))},this.publishTimeout);this.openEventPublishes.set(s.id,{resolve:n,reject:r,timeout:o}),this.send('["AUTH",'+JSON.stringify(s)+"]")}catch(e){console.warn("subscribe auth function failed:",e)}})),this.authPromise}async publish(e){const t=new Promise((t,n)=>{const r=setTimeout(()=>{const t=this.openEventPublishes.get(e.id);t&&(t.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:t,reject:n,timeout:r})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),t}async count(e,t){this.serial++;const n=t?.id||"count:"+this.serial,r=new Promise((e,t)=>{this.openCountRequests.set(n,{resolve:e,reject:t})});return this.send('["COUNT","'+n+'",'+JSON.stringify(e).substring(1)),r}subscribe(e,t){const n=this.prepareSubscription(e,t);return n.fire(),n}prepareSubscription(e,t){this.serial++;const n=t.id||(t.label?t.label+":":"sub:")+this.serial,r=new So(this,n,e,t);return this.openSubs.set(n,r),r}close(){this.closedIntentionally=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,this.onclose?.(),this.ws?.readyState===this._WebSocket.OPEN&&this.ws?.close()}_onmessage(e){this.incomingMessageQueue.enqueue(e.data),this.queueRunning||this.runQueue()}},So=class{relay;id;lastEmitted;closed=!1;eosed=!1;filters;alreadyHaveEvent;receivedEvent;onevent;oneose;onclose;oncustom;eoseTimeout;eoseTimeoutHandle;constructor(e,t,n,r){if(0===n.length)throw new Error("subscription can't be created with zero filters");this.relay=e,this.filters=n,this.id=t,this.alreadyHaveEvent=r.alreadyHaveEvent,this.receivedEvent=r.receivedEvent,this.eoseTimeout=r.eoseTimeout||e.baseEoseTimeout,this.oneose=r.oneose,this.onclose=r.onclose,this.onevent=r.onevent||(e=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,e)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,this.oneose?.())}close(e="closed by caller"){if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(e){if(!(e instanceof xo))throw e}this.closed=!0}this.relay.openSubs.delete(this.id),this.onclose?.(e)}};try{WebSocket}catch{}var Ao,To=class{relays=new Map;seenOn=new Map;trackRelays=!1;verifyEvent;enablePing;enableReconnect;automaticallyAuth;trustedRelayURLs=new Set;_WebSocket;constructor(e){this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation,this.enablePing=e.enablePing,this.enableReconnect=e.enableReconnect||!1,this.automaticallyAuth=e.automaticallyAuth}async ensureRelay(e,t){e=cr(e);let n=this.relays.get(e);if(n||(n=new Eo(e,{verifyEvent:this.trustedRelayURLs.has(e)?ko:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),n.onclose=()=>{n&&!n.enableReconnect&&this.relays.delete(e)},t?.connectionTimeout&&(n.connectionTimeout=t.connectionTimeout),this.relays.set(e,n)),this.automaticallyAuth){const t=this.automaticallyAuth(e);t&&(n.onauth=t)}return await n.connect(),n}close(e){e.map(cr).forEach(e=>{this.relays.get(e)?.close(),this.relays.delete(e)})}subscribe(e,t,n){const r=[];for(let n=0;n<e.length;n++){const s=cr(e[n]);r.find(e=>e.url===s)||r.push({url:s,filter:t})}return this.subscribeMap(r,n)}subscribeMany(e,t,n){const r=[],s=[];for(let n=0;n<e.length;n++){const o=cr(e[n]);-1===s.indexOf(o)&&(s.push(o),r.push({url:o,filter:t}))}return this.subscribeMap(r,n)}subscribeMap(e,t){const n=new Map;for(const t of e){const{url:e,filter:r}=t;n.has(e)||n.set(e,[]),n.get(e).push(r)}const r=Array.from(n.entries()).map(([e,t])=>({url:e,filters:t}));this.trackRelays&&(t.receivedEvent=(e,t)=>{let n=this.seenOn.get(t);n||(n=new Set,this.seenOn.set(t,n)),n.add(e)});const s=new Set,o=[],i=[];let a=e=>{i[e]||(i[e]=!0,i.filter(e=>e).length===r.length&&(t.oneose?.(),a=()=>{}))};const l=[];let c=(e,n)=>{l[e]||(a(e),l[e]=n,l.filter(e=>e).length===r.length&&(t.onclose?.(l),c=()=>{}))};const u=e=>{if(t.alreadyHaveEvent?.(e))return!0;const n=s.has(e);return s.add(e),n},h=Promise.all(r.map(async({url:e,filters:n},r)=>{let s;try{s=await this.ensureRelay(e,{connectionTimeout:t.maxWait?Math.max(.8*t.maxWait,t.maxWait-1e3):void 0})}catch(e){return void c(r,e?.message||String(e))}let i=s.subscribe(n,{...t,oneose:()=>a(r),onclose:e=>{e.startsWith("auth-required: ")&&t.onauth?s.auth(t.onauth).then(()=>{s.subscribe(n,{...t,oneose:()=>a(r),onclose:e=>{c(r,e)},alreadyHaveEvent:u,eoseTimeout:t.maxWait})}).catch(e=>{c(r,`auth was required and attempted, but failed with: ${e}`)}):c(r,e)},alreadyHaveEvent:u,eoseTimeout:t.maxWait});o.push(i)}));return{async close(e){await h,o.forEach(t=>{t.close(e)})}}}subscribeEose(e,t,n){const r=this.subscribe(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}subscribeManyEose(e,t,n){const r=this.subscribeMany(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}async querySync(e,t,n){return new Promise(async r=>{const s=[];this.subscribeEose(e,t,{...n,onevent(e){s.push(e)},onclose(e){r(s)}})})}async get(e,t,n){t.limit=1;const r=await this.querySync(e,t,n);return r.sort((e,t)=>t.created_at-e.created_at),r[0]||null}publish(e,t,n){return e.map(cr).map(async(e,r,s)=>{if(s.indexOf(e)!==r)return Promise.reject("duplicate url");let o=await this.ensureRelay(e);return o.publish(t).catch(async e=>{if(e instanceof Error&&e.message.startsWith("auth-required: ")&&n?.onauth)return await o.auth(n.onauth),o.publish(t);throw e}).then(e=>{if(this.trackRelays){let e=this.seenOn.get(t.id);e||(e=new Set,this.seenOn.set(t.id,e)),e.add(o)}return e})})}listConnectionStatus(){const e=new Map;return this.relays.forEach((t,n)=>e.set(n,t.connected)),e}destroy(){this.relays.forEach(e=>e.close()),this.relays=new Map}};try{Ao=WebSocket}catch{}var $o=class extends To{constructor(e){super({verifyEvent:vr,websocketImplementation:Ao,...e})}},Ro={};sr(Ro,{BECH32_REGEX:()=>Lo,Bech32MaxSize:()=>Bo,NostrTypeGuard:()=>Io,decode:()=>Po,decodeNostrURI:()=>_o,encodeBytes:()=>qo,naddrEncode:()=>jo,neventEncode:()=>Ho,noteEncode:()=>Oo,nprofileEncode:()=>Mo,npubEncode:()=>No,nsecEncode:()=>Uo});var Io={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Bo=5e3,Lo=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function _o(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),Po(e)}catch(e){return{type:"invalid",data:null}}}function Po(e){let{prefix:t,words:n}=Bt.decode(e,Bo),r=new Uint8Array(Bt.fromWords(n));switch(t){case"nprofile":{let e=Co(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nprofile");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:Ve(e[0][0]),relays:e[1]?e[1].map(e=>ar.decode(e)):[]}}}case"nevent":{let e=Co(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nevent");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");if(e[2]&&32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(e[3]&&4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:Ve(e[0][0]),relays:e[1]?e[1].map(e=>ar.decode(e)):[],author:e[2]?.[0]?Ve(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(Ve(e[3][0]),16):void 0}}}case"naddr":{let e=Co(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for naddr");if(!e[2]?.[0])throw new Error("missing TLV 2 for naddr");if(32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(!e[3]?.[0])throw new Error("missing TLV 3 for naddr");if(4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:ar.decode(e[0][0]),pubkey:Ve(e[2][0]),kind:parseInt(Ve(e[3][0]),16),relays:e[1]?e[1].map(e=>ar.decode(e)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:Ve(r)};default:throw new Error(`unknown prefix ${t}`)}}function Co(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],s=n.slice(2,2+r);if(n=n.slice(2+r),s.length<r)throw new Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(s)}return t}function Uo(e){return qo("nsec",e)}function No(e){return qo("npub",We(e))}function Oo(e){return qo("note",We(e))}function zo(e,t){let n=Bt.toWords(t);return Bt.encode(e,n,Bo)}function qo(e,t){return zo(e,t)}function Mo(e){return zo("nprofile",Do({0:[We(e.pubkey)],1:(e.relays||[]).map(e=>lr.encode(e))}))}function Ho(e){let t;return void 0!==e.kind&&(t=function(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=255&e,t}(e.kind)),zo("nevent",Do({0:[We(e.id)],1:(e.relays||[]).map(e=>lr.encode(e)),2:e.author?[We(e.author)]:[],3:t?[new Uint8Array(t)]:[]}))}function jo(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),zo("naddr",Do({0:[lr.encode(e.identifier)],1:(e.relays||[]).map(e=>lr.encode(e)),2:[We(e.pubkey)],3:[new Uint8Array(t)]}))}function Do(e){let t=[];return Object.entries(e).reverse().forEach(([e,n])=>{n.forEach(n=>{let r=new Uint8Array(n.length+2);r.set([parseInt(e)],0),r.set([n.length],1),r.set(n,2),t.push(r)})}),Ke(...t)}function Fo(e,t,n){const r=e instanceof Uint8Array?Ve(e):e,s=Wo(Ee.getSharedSecret(r,"02"+t));let o=Uint8Array.from(Je(16)),i=lr.encode(n),a=In(s,o).encrypt(i);return`${Et.encode(new Uint8Array(a))}?iv=${Et.encode(new Uint8Array(o.buffer))}`}function Vo(e,t,n){const r=e instanceof Uint8Array?Ve(e):e;let[s,o]=n.split("?iv="),i=Wo(Ee.getSharedSecret(r,"02"+t)),a=Et.decode(o),l=Et.decode(s),c=In(i,a).decrypt(l);return ar.decode(c)}function Wo(e){return e.slice(1,33)}sr({},{decrypt:()=>Vo,encrypt:()=>Fo}),sr({},{NIP05_REGEX:()=>Ko,isNip05:()=>Yo,isValid:()=>Xo,queryProfile:()=>Qo,searchDomain:()=>Jo,useFetchImplementation:()=>Go});var Zo,Ko=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Yo=e=>Ko.test(e||"");try{Zo=fetch}catch(e){}function Go(e){Zo=e}async function Jo(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await Zo(n,{redirect:"manual"});if(200!==r.status)throw Error("Wrong response code");return(await r.json()).names}catch(e){return{}}}async function Qo(e){const t=e.match(Ko);if(!t)return null;const[,n="_",r]=t;try{const e=`https://${r}/.well-known/nostr.json?name=${n}`,t=await Zo(e,{redirect:"manual"});if(200!==t.status)throw Error("Wrong response code");const s=await t.json(),o=s.names[n];return o?{pubkey:o,relays:s.relays?.[o]}:null}catch(e){return null}}async function Xo(e,t){const n=await Qo(t);return!!n&&n.pubkey===e}function ei(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let s=e.tags.length-1;s>=0;s--){const o=e.tags[s];if("e"===o[0]&&o[1]){const[e,s,i,a,l]=o,c={id:s,relays:i?[i]:[],author:l};if("root"===a){t.root=c;continue}if("reply"===a){t.reply=c;continue}if("mention"===a){t.mentions.push(c);continue}n?r=c:n=c,t.mentions.push(c);continue}if("q"===o[0]&&o[1]){const[e,n,r]=o;t.quotes.push({id:n,relays:r?[r]:[]})}"p"===o[0]&&o[1]&&t.profiles.push({pubkey:o[1],relays:o[2]?[o[2]]:[]})}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(e=>{if(!e)return;let n=t.mentions.indexOf(e);if(-1!==n&&t.mentions.splice(n,1),e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays?.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t.mentions.forEach(e=>{if(e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t}sr({},{parse:()=>ei}),sr({},{fetchRelayInformation:()=>ni,useFetchImplementation:()=>ti});try{fetch}catch{}function ti(e){}async function ni(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}function ri(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(0!==r){t+=Math.clz32(r);break}t+=32}return t}function si(e,t){let n=0;const r=e,s=["nonce",n.toString(),t.toString()];for(r.tags.push(s);;){const e=Math.floor((new Date).getTime()/1e3);if(e!==r.created_at&&(n=0,r.created_at=e),s[1]=(++n).toString(),r.id=oi(r),ri(r.id)>=t)break}return r}function oi(e){return Ve(ut(lr.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}function ii(e,t){const n=Ee.getSharedSecret(e,"02"+t).subarray(1,33);return r=ut,s=n,o="nip44-v2",tt.hash(r),void 0===o&&(o=new Uint8Array(r.outputLen)),er(r,Ze(o),Ze(s));var r,s,o}function ai(e,t){const n=function(e,t,n,r=32){if(tt.hash(e),tt.number(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const s=Math.ceil(r/e.outputLen);void 0===n&&(n=nr);const o=new Uint8Array(s*e.outputLen),i=er.create(e,t),a=i._cloneInto(),l=new Uint8Array(i.outputLen);for(let t=0;t<s;t++)tr[0]=t+1,a.update(0===t?nr:l).update(n).update(tr).digestInto(l),o.set(l,e.outputLen*t),i._cloneInto(a);return i.destroy(),a.destroy(),l.fill(0),tr.fill(0),o.slice(0,r)}(ut,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function li(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function ci(e,t,n){if(32!==n.length)throw new Error("AAD associated data must be 32 bytes");const r=Ke(n,t);return er(ut,e,r)}function ui(e,t,n=Je(32)){const{chacha_key:r,chacha_nonce:s,hmac_key:o}=ai(t,n),i=function(e){const t=lr.encode(e),n=t.length;return Ke(function(e){if(!Number.isSafeInteger(e)||e<1||e>65535)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}(n),t,new Uint8Array(li(n)-n))}(e),a=Wn(r,s,i),l=ci(o,a,n);return Et.encode(Ke(new Uint8Array([2]),n,a,l))}function hi(e,t){const{nonce:n,ciphertext:r,mac:s}=function(e){if("string"!=typeof e)throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if("#"===e[0])throw new Error("unknown encryption version");let n;try{n=Et.decode(e)}catch(e){throw new Error("invalid base64: "+e.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const s=n[0];if(2!==s)throw new Error("unknown encryption version "+s);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}(e),{chacha_key:o,chacha_nonce:i,hmac_key:a}=ai(t,n);if(!Vt(ci(a,r,n),s))throw new Error("invalid MAC");return function(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<1||t>65535||n.length!==t||e.length!==2+li(t))throw new Error("invalid padding");return ar.decode(n)}(Wn(o,i,r))}sr({},{fastEventHash:()=>oi,getPow:()=>ri,minePow:()=>si}),sr({},{unwrapEvent:()=>$i,unwrapManyEvents:()=>Ri,wrapEvent:()=>Ai,wrapManyEvents:()=>Ti}),sr({},{createRumor:()=>yi,createSeal:()=>mi,createWrap:()=>vi,unwrapEvent:()=>Ei,unwrapManyEvents:()=>Si,wrapEvent:()=>ki,wrapManyEvents:()=>xi}),sr({},{decrypt:()=>hi,encrypt:()=>ui,getConversationKey:()=>ii,v2:()=>di});var di={utils:{getConversationKey:ii,calcPaddedLen:li},encrypt:ui,decrypt:hi},fi=()=>Math.round(Date.now()/1e3),pi=()=>Math.round(fi()-172800*Math.random()),gi=(e,t)=>ii(e,t),wi=(e,t,n)=>ui(JSON.stringify(e),gi(t,n)),bi=(e,t)=>JSON.parse(hi(e.content,gi(t,e.pubkey)));function yi(e,t){const n={created_at:fi(),content:"",tags:[],...e,pubkey:yr(t)};return n.id=gr(n),n}function mi(e,t,n){return mr({kind:zr,content:wi(e,t,n),created_at:pi(),tags:[]},t)}function vi(e,t){const n=br();return mr({kind:Jr,content:wi(e,n,t),created_at:pi(),tags:[["p",t]]},n)}function ki(e,t,n){return vi(mi(yi(e,t),t,n),n)}function xi(e,t,n){if(!n||0===n.length)throw new Error("At least one recipient is required.");const r=yr(t),s=[ki(e,t,r)];return n.forEach(n=>{s.push(ki(e,t,n))}),s}function Ei(e,t){const n=bi(e,t);return bi(n,t)}function Si(e,t){let n=[];return e.forEach(e=>{n.push(Ei(e,t))}),n.sort((e,t)=>e.created_at-t.created_at),n}function Ai(e,t,n,r,s){const o=function(e,t,n,r){const s={created_at:Math.ceil(Date.now()/1e3),kind:qr,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:e,relayUrl:t})=>{s.tags.push(t?["p",e,t]:["p",e])}),r&&s.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&s.tags.push(["subject",n]),s}(t,n,r,s);return ki(o,e,t.publicKey)}function Ti(e,t,n,r,s){if(!t||0===t.length)throw new Error("At least one recipient is required.");return[{publicKey:yr(e)},...t].map(t=>Ai(e,t,n,r,s))}var $i=Ei,Ri=Si;function Ii(e,t,n,r){let s;const o=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===Rr?s=Pr:(s=Hr,o.push(["k",String(t.kind)])),mr({kind:s,tags:o,content:""===e.content||t.tags?.find(e=>"-"===e[0])?"":JSON.stringify(t),created_at:e.created_at},r)}function Bi(e){if(![Pr,Hr].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const s=e.tags[r];s.length>=2&&("e"===s[0]&&void 0===t?t=s:"p"===s[0]&&void 0===n&&(n=s))}return void 0!==t?{id:t[1],relays:[t[2],n?.[2]].filter(e=>"string"==typeof e),author:n?.[1]}:void 0}function Li(e,{skipVerification:t}={}){const n=Bi(e);if(void 0===n||""===e.content)return;let r;try{r=JSON.parse(e.content)}catch(e){return}return r.id===n.id&&(t||vr(r))?r:void 0}sr({},{finishRepostEvent:()=>Ii,getRepostedEvent:()=>Li,getRepostedEventPointer:()=>Bi}),sr({},{NOSTR_URI_REGEX:()=>_i,parse:()=>Ci,test:()=>Pi});var _i=new RegExp(`nostr:(${Lo.source})`);function Pi(e){return"string"==typeof e&&new RegExp(`^${_i.source}$`).test(e)}function Ci(e){const t=e.match(new RegExp(`^${_i.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:Po(t[1])}}function Ui(e,t,n){const r=t.tags.filter(e=>e.length>=2&&("e"===e[0]||"p"===e[0]));return mr({...e,kind:Cr,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function Ni(e){if(e.kind!==Cr)return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const s=e.tags[r];s.length>=2&&("e"===s[0]&&void 0===t?t=s:"p"===s[0]&&void 0===n&&(n=s))}return void 0!==t&&void 0!==n?{id:t[1],relays:[t[2],n[2]].filter(e=>void 0!==e),author:n[1]}:void 0}sr({},{finishReactionEvent:()=>Ui,getReactedEventPointer:()=>Ni}),sr({},{parse:()=>qi});var Oi=/\W/m,zi=/[^\w\/] |[^\w\/]$|$|,| /m;function*qi(e){let t=[];if("string"!=typeof e){for(let n=0;n<e.tags.length;n++){const r=e.tags[n];"emoji"===r[0]&&r.length>=3&&t.push({type:"emoji",shortcode:r[1],url:r[2]})}e=e.content}const n=e.length;let r=0,s=0;e:for(;s<n;){const o=e.indexOf(":",s),i=e.indexOf("#",s);if(-1===o&&-1===i)break e;if(-1===o||i>=0&&i<o){if(0===i||" "===e[i-1]){const t=e.slice(i+1,i+42).match(Oi),o=t?i+1+t.index:n;yield{type:"text",text:e.slice(r,i)},yield{type:"hashtag",value:e.slice(i+1,o)},s=o,r=s;continue e}s=i+1}else if("nostr"===e.slice(o-5,o)){const t=e.slice(o+60).match(Oi),i=t?o+60+t.index:n;try{let t,{data:n,type:a}=Po(e.slice(o+1,i));switch(a){case"npub":t={pubkey:n};break;case"note":t={id:n};break;case"nsec":s=i+1;continue;default:t=n}r!==o-5&&(yield{type:"text",text:e.slice(r,o-5)}),yield{type:"reference",pointer:t},s=i,r=s;continue e}catch(e){s=o+1;continue e}}else if("https"===e.slice(o-5,o)||"http"===e.slice(o-4,o)){const t=e.slice(o+4).match(zi),i=t?o+4+t.index:n,a="s"===e[o-1]?5:4;try{let t=new URL(e.slice(o-a,i));if(-1===t.hostname.indexOf("."))throw new Error("invalid url");if(r!==o-a&&(yield{type:"text",text:e.slice(r,o-a)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(t.pathname)){yield{type:"image",url:t.toString()},s=i,r=s;continue e}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(t.pathname)){yield{type:"video",url:t.toString()},s=i,r=s;continue e}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(t.pathname)){yield{type:"audio",url:t.toString()},s=i,r=s;continue e}yield{type:"url",url:t.toString()},s=i,r=s;continue e}catch(e){s=i+1;continue e}}else{if("wss"!==e.slice(o-3,o)&&"ws"!==e.slice(o-2,o)){for(let n=0;n<t.length;n++){const i=t[n];if(":"===e[o+i.shortcode.length+1]&&e.slice(o+1,o+i.shortcode.length+1)===i.shortcode){r!==o&&(yield{type:"text",text:e.slice(r,o)}),yield i,s=o+i.shortcode.length+2,r=s;continue e}}s=o+1;continue e}{const t=e.slice(o+4).match(zi),i=t?o+4+t.index:n,a="s"===e[o-1]?3:2;try{let t=new URL(e.slice(o-a,i));if(-1===t.hostname.indexOf("."))throw new Error("invalid ws url");r!==o-a&&(yield{type:"text",text:e.slice(r,o-a)}),yield{type:"relay",url:t.toString()},s=i,r=s;continue e}catch(e){s=i+1;continue e}}}}r!==n&&(yield{type:"text",text:e.slice(r)})}sr({},{channelCreateEvent:()=>Mi,channelHideMessageEvent:()=>Di,channelMessageEvent:()=>ji,channelMetadataEvent:()=>Hi,channelMuteUserEvent:()=>Fi});var Mi=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return mr({kind:Vr,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},Hi=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return mr({kind:Wr,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},ji=(e,t)=>{const n=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&n.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),mr({kind:Zr,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},Di=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return mr({kind:Kr,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},Fi=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return mr({kind:Yr,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)};sr({},{EMOJI_SHORTCODE_REGEX:()=>Zi,matchAll:()=>Yi,regex:()=>Ki,replaceAll:()=>Gi});var Vi,Wi,Zi=/:(\w+):/,Ki=()=>new RegExp(`\\B${Zi.source}\\B`,"g");function*Yi(e){const t=e.matchAll(Ki());for(const e of t)try{const[t,n]=e;yield{shortcode:t,name:n,start:e.index,end:e.index+t.length}}catch(e){}}function Gi(e,t){return e.replaceAll(Ki(),(e,n)=>t({shortcode:e,name:n}))}sr({},{useFetchImplementation:()=>Ji,validateGithub:()=>Qi});try{Vi=fetch}catch{}function Ji(e){Vi=e}async function Qi(e,t,n){try{return await(await Vi(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch(e){return!1}}function Xi(e){const{host:t,pathname:n,searchParams:r}=new URL(e),s=n||t,o=r.get("relay"),i=r.get("secret");if(!s||!o||!i)throw new Error("invalid connection string");return{pubkey:s,relay:o,secret:i}}async function ea(e,t,n){const r={method:"pay_invoice",params:{invoice:n}},s=Fo(t,e,JSON.stringify(r)),o={kind:Cs,created_at:Math.round(Date.now()/1e3),content:s,tags:[["p",e]]};return mr(o,t)}function ta(e){return e=(e=e.trim().toLowerCase()).normalize("NFKC"),Array.from(e).map(e=>/\p{Letter}/u.test(e)||/\p{Number}/u.test(e)?e:"-").join("")}sr({},{makeNwcRequestEvent:()=>ea,parseConnectionString:()=>Xi}),sr({},{normalizeIdentifier:()=>ta}),sr({},{getSatoshisAmountFromBolt11:()=>aa,getZapEndpoint:()=>ra,makeZapReceipt:()=>ia,makeZapRequest:()=>sa,useFetchImplementation:()=>na,validateZapRequest:()=>oa});try{Wi=fetch}catch{}function na(e){Wi=e}async function ra(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(r){let[e,n]=r.split("@");t=new URL(`/.well-known/lnurlp/${e}`,`https://${n}`).toString()}else{if(!n)return null;{let{words:e}=Bt.decode(n,1e3),r=Bt.fromWords(e);t=ar.decode(r)}}let s=await Wi(t),o=await s.json();if(o.allowsNostr&&o.nostrPubkey)return o.callback}catch(e){}return null}function sa(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),xr(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(Sr(e.event.kind)){let n=e.event.tags.find(([e,t])=>"d"===e&&t);if(!n)throw new Error("d tag not found or is empty");const r=["a",`${e.event.kind}:${e.event.pubkey}:${n[1]}`];t.tags.push(r)}t.tags.push(["k",e.event.kind.toString()])}return t}function oa(e){let t;try{t=JSON.parse(e)}catch(e){return"Invalid zap request JSON."}if(!ir(t))return"Zap request is not a valid Nostr event.";if(!vr(t))return"Invalid signature on zap request.";let n=t.tags.find(([e,t])=>"p"===e&&t);if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=t.tags.find(([e,t])=>"e"===e&&t);if(r&&!r[1].match(/^[a-f0-9]{64}$/))return"Zap request 'e' tag is not valid hex.";let s=t.tags.find(([e,t])=>"relays"===e&&t);return s?null:"Zap request doesn't have a 'relays' tag."}function ia({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let s=JSON.parse(e),o=s.tags.filter(([e])=>"e"===e||"p"===e||"a"===e),i={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...o,["P",s.pubkey],["bolt11",n],["description",e]]};return t&&i.tags.push(["preimage",t]),i}function aa(e){if(e.length<50)return 0;const t=(e=e.substring(0,50)).lastIndexOf("1");if(-1===t)return 0;const n=e.substring(0,t);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const s=r[r.length-1],o=s.charCodeAt(0)-"0".charCodeAt(0),i=o>=0&&o<=9;let a=r.length-1;if(i&&a++,a<1)return 0;const l=parseInt(r.substring(0,a));switch(s){case"m":return 1e5*l;case"u":return 100*l;case"n":return l/10;case"p":return l/1e4;default:return 1e8*l}}sr({},{Negentropy:()=>ga,NegentropyStorageVector:()=>pa,NegentropySync:()=>ya});var la=32,ca=class{_raw;length;constructor(e){"number"==typeof e?(this._raw=new Uint8Array(e),this.length=0):e instanceof Uint8Array?(this._raw=new Uint8Array(e),this.length=e.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(e){if(e instanceof ca&&(e=e.unwrap()),"number"!=typeof e.length)throw Error("bad length");const t=e.length+this.length;if(this.capacity<t){const e=this._raw,n=Math.max(2*this.capacity,t);this._raw=new Uint8Array(n),this._raw.set(e)}this._raw.set(e,this.length),this.length+=e.length}shift(){const e=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,e}shiftN(e=1){const t=this._raw.subarray(0,e);return this._raw=this._raw.subarray(e),this.length-=e,t}};function ua(e){let t=0;for(;;){if(0===e.length)throw Error("parse ends prematurely");let n=e.shift();if(t=t<<7|127&n,!(128&n))break}return t}function ha(e){if(0===e)return new ca(new Uint8Array([0]));let t=[];for(;0!==e;)t.push(127&e),e>>>=7;t.reverse();for(let e=0;e<t.length-1;e++)t[e]|=128;return new ca(new Uint8Array(t))}function da(e,t){if(e.length<t)throw Error("parse ends prematurely");return e.shiftN(t)}var fa=class{buf;constructor(){this.setToZero()}setToZero(){this.buf=new Uint8Array(la)}add(e){let t=0,n=0,r=new DataView(this.buf.buffer),s=new DataView(e.buffer);for(let e=0;e<8;e++){let o=4*e,i=r.getUint32(o,!0);i+=t,i+=s.getUint32(o,!0),i>4294967295&&(n=1),r.setUint32(o,4294967295&i,!0),t=n,n=0}}negate(){let e=new DataView(this.buf.buffer);for(let t=0;t<8;t++){let n=4*t;e.setUint32(n,~e.getUint32(n,!0))}let t=new Uint8Array(la);t[0]=1,this.add(t)}getFingerprint(e){let t=new ca;return t.extend(this.buf),t.extend(ha(e)),ut(t.unwrap()).subarray(0,16)}},pa=class{items;sealed;constructor(){this.items=[],this.sealed=!1}insert(e,t){if(this.sealed)throw Error("already sealed");const n=Dt(t);if(n.byteLength!==la)throw Error("bad id size for added item");this.items.push({timestamp:e,id:n})}seal(){if(this.sealed)throw Error("already sealed");this.sealed=!0,this.items.sort(ba);for(let e=1;e<this.items.length;e++)if(0===ba(this.items[e-1],this.items[e]))throw Error("duplicate item inserted")}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(e){if(this._checkSealed(),e>=this.items.length)throw Error("out of range");return this.items[e]}iterate(e,t,n){this._checkSealed(),this._checkBounds(e,t);for(let r=e;r<t&&n(this.items[r],r);++r);}findLowerBound(e,t,n){return this._checkSealed(),this._checkBounds(e,t),this._binarySearch(this.items,e,t,e=>ba(e,n)<0)}fingerprint(e,t){let n=new fa;return n.setToZero(),this.iterate(e,t,e=>(n.add(e.id),!0)),n.getFingerprint(t-e)}_checkSealed(){if(!this.sealed)throw Error("not sealed")}_checkBounds(e,t){if(e>t||t>this.items.length)throw Error("bad range")}_binarySearch(e,t,n,r){let s=n-t;for(;s>0;){let n=t,o=Math.floor(s/2);n+=o,r(e[n])?(t=++n,s-=o+1):s=o}return t}},ga=class{storage;frameSizeLimit;lastTimestampIn;lastTimestampOut;constructor(e,t=6e4){if(t<4096)throw Error("frameSizeLimit too small");this.storage=e,this.frameSizeLimit=t,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(e,t){return{timestamp:e,id:t||new Uint8Array(0)}}initiate(){let e=new ca;return e.extend(new Uint8Array([97])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),e),Ht(e.unwrap())}reconcile(e,t,n){const r=new ca(Dt(e));this.lastTimestampIn=this.lastTimestampOut=0;let s=new ca;s.extend(new Uint8Array([97]));let o=da(r,1)[0];if(o<96||o>111)throw Error("invalid negentropy protocol version byte");if(97!==o)throw Error("unsupported negentropy protocol version requested: "+(o-96));let i=this.storage.size(),a=this._bound(0),l=0,c=!1;for(;0!==r.length;){let e=new ca,o=()=>{c&&(c=!1,e.extend(this.encodeBound(a)),e.extend(ha(0)))},u=this.decodeBound(r),h=ua(r),d=l,f=this.storage.findLowerBound(l,i,u);if(0===h)c=!0;else if(1===h)0!==wa(da(r,16),this.storage.fingerprint(d,f))?(o(),this.splitRange(d,f,u,e)):c=!0;else{if(2!==h)throw Error("unexpected mode");{let e=ua(r),s={};for(let t=0;t<e;t++){let e=da(r,la);s[Ht(e)]=e}if(c=!0,this.storage.iterate(d,f,e=>{let n=e.id;const r=Ht(n);return s[r]?delete s[Ht(n)]:t?.(r),!0}),n)for(let e of Object.values(s))n(Ht(e))}}if(this.exceededFrameSizeLimit(s.length+e.length)){let e=this.storage.fingerprint(f,i);s.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),s.extend(ha(1)),s.extend(e);break}s.extend(e),l=f,a=u}return 1===s.length?null:Ht(s.unwrap())}splitRange(e,t,n,r){let s=t-e;if(s<32)r.extend(this.encodeBound(n)),r.extend(ha(2)),r.extend(ha(s)),this.storage.iterate(e,t,e=>(r.extend(e.id),!0));else{let o=Math.floor(s/16),i=s%16,a=e;for(let e=0;e<16;e++){let s,l=o+(e<i?1:0),c=this.storage.fingerprint(a,a+l);if(a+=l,a===t)s=n;else{let e,t;this.storage.iterate(a-1,a+1,(n,r)=>(r===a-1?e=n:t=n,!0)),s=this.getMinimalBound(e,t)}r.extend(this.encodeBound(s)),r.extend(ha(1)),r.extend(c)}}}exceededFrameSizeLimit(e){return e>this.frameSizeLimit-200}decodeTimestampIn(e){let t=ua(e);return t=0===t?Number.MAX_VALUE:t-1,this.lastTimestampIn===Number.MAX_VALUE||t===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(t+=this.lastTimestampIn,this.lastTimestampIn=t,t)}decodeBound(e){let t=this.decodeTimestampIn(e),n=ua(e);if(n>la)throw Error("bound key too long");return{timestamp:t,id:da(e,n)}}encodeTimestampOut(e){if(e===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,ha(0);let t=e;return e-=this.lastTimestampOut,this.lastTimestampOut=t,ha(e+1)}encodeBound(e){let t=new ca;return t.extend(this.encodeTimestampOut(e.timestamp)),t.extend(ha(e.id.length)),t.extend(e.id),t}getMinimalBound(e,t){if(t.timestamp!==e.timestamp)return this._bound(t.timestamp);{let n=0,r=t.id,s=e.id;for(let e=0;e<la&&r[e]===s[e];e++)n++;return this._bound(t.timestamp,t.id.subarray(0,n+1))}}};function wa(e,t){for(let n=0;n<e.byteLength;n++){if(e[n]<t[n])return-1;if(e[n]>t[n])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function ba(e,t){return e.timestamp===t.timestamp?wa(e.id,t.id):e.timestamp-t.timestamp}var ya=class{relay;storage;neg;filter;subscription;onhave;onneed;constructor(e,t,n,r={}){this.relay=e,this.storage=t,this.neg=new ga(t),this.onhave=r.onhave,this.onneed=r.onneed,this.filter=n,this.subscription=this.relay.prepareSubscription([{}],{label:r.label||"negentropy"}),this.subscription.oncustom=e=>{switch(e[0]){case"NEG-MSG":e.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${e}`);try{const t=this.neg.reconcile(e[2],this.onhave,this.onneed);t?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${t}"]`):(this.close(),r.onclose?.())}catch(e){console.error("negentropy reconcile error:",e),r?.onclose?.(`reconcile error: ${e}`)}break;case"NEG-CLOSE":{const t=e[2];console.warn("negentropy error:",t),r.onclose?.(t);break}case"NEG-ERR":r.onclose?.()}}}async start(){const e=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${e}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}};sr({},{getToken:()=>va,hashPayload:()=>$a,unpackEventFromToken:()=>xa,validateEvent:()=>Ia,validateEventKind:()=>Sa,validateEventMethodTag:()=>Ta,validateEventPayloadTag:()=>Ra,validateEventTimestamp:()=>Ea,validateEventUrlTag:()=>Aa,validateToken:()=>ka});var ma="Nostr ";async function va(e,t,n,r=!1,s){const o={kind:Os,tags:[["u",e],["method",t]],created_at:Math.round((new Date).getTime()/1e3),content:""};s&&o.tags.push(["payload",$a(s)]);const i=await n(o);return(r?ma:"")+Et.encode(lr.encode(JSON.stringify(i)))}async function ka(e,t,n){const r=await xa(e).catch(e=>{throw e});return await Ia(r,t,n).catch(e=>{throw e})}async function xa(e){if(!e)throw new Error("Missing token");e=e.replace(ma,"");const t=ar.decode(Et.decode(e));if(!t||0===t.length||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function Ea(e){return!!e.created_at&&Math.round((new Date).getTime()/1e3)-e.created_at<60}function Sa(e){return e.kind===Os}function Aa(e,t){const n=e.tags.find(e=>"u"===e[0]);return!!n&&n.length>0&&n[1]===t}function Ta(e,t){const n=e.tags.find(e=>"method"===e[0]);return!!n&&n.length>0&&n[1].toLowerCase()===t.toLowerCase()}function $a(e){return Ve(ut(lr.encode(JSON.stringify(e))))}function Ra(e,t){const n=e.tags.find(e=>"payload"===e[0]);if(!n)return!1;const r=$a(t);return n.length>0&&n[1]===r}async function Ia(e,t,n,r){if(!vr(e))throw new Error("Invalid nostr event, signature invalid");if(!Sa(e))throw new Error("Invalid nostr event, kind invalid");if(!Ea(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!Aa(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!Ta(e,n))throw new Error("Invalid nostr event, method tag invalid");if(Boolean(r)&&"object"==typeof r&&Object.keys(r).length>0&&!Ra(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}class Ba{constructor(e){this.profileCache=new Map,this.pool=new $o,this.relays=e}normalizePublicKey(e){if(e.startsWith("npub"))try{return Ro.decode(e).data}catch(t){return console.error("Invalid npub format:",t),e}return e}async fetchPosts(e,t=50,n="all",r){const s=(Array.isArray(e)?e:[e]).map(e=>this.normalizePublicKey(e));let o;switch(n){case"long-form":o=[30023];break;case"short-form":o=[1];break;default:o=[30023,1]}let i=[];if(s.length>1){const e=Math.ceil(t/s.length);for(const t of s){const n={authors:[t],kinds:o,limit:e};r?.since&&(n.since=r.since),r?.until&&(n.until=r.until);const s=await this.pool.querySync(this.relays,n);i=i.concat(s)}}else{const e={authors:s,kinds:o,limit:t};r?.since&&(e.since=r.since),r?.until&&(e.until=r.until),i=await this.pool.querySync(this.relays,e)}return await this.fetchAuthorProfiles(s),this.parsePosts(i)}async fetchAuthorProfiles(e){const t=e.filter(e=>!this.profileCache.has(e));if(0===t.length)return;const n={authors:t,kinds:[0],limit:t.length};try{(await this.pool.querySync(this.relays,n)).forEach(e=>{try{const t=JSON.parse(e.content);this.profileCache.set(e.pubkey,t)}catch(t){console.error("Failed to parse profile for",e.pubkey,t)}})}catch(e){console.error("Failed to fetch author profiles:",e)}}async fetchPostById(e){if(e.startsWith("naddr"))return this.fetchPostByNaddr(e);if(e.startsWith("nevent"))return this.fetchPostByNevent(e);if(e.startsWith("note1"))try{const t=Ro.decode(e);"note"===t.type&&(e=t.data)}catch(e){console.error("Failed to decode note1:",e)}const t={ids:[e]},n=await this.pool.querySync(this.relays,t);return 0===n.length?null:(n[0]?.pubkey&&await this.fetchAuthorProfiles([n[0].pubkey]),this.parsePosts(n)[0]||null)}async fetchPostByNevent(e){try{const t=Ro.decode(e);if("nevent"!==t.type)return console.error("Not a valid nevent"),null;const n=t.data,r=n.relays&&n.relays.length>0?n.relays:this.relays,s={ids:[n.id]};n.author&&(s.authors=[n.author]);const o=await this.pool.querySync(r,s);return 0===o.length?null:(o[0]?.pubkey&&await this.fetchAuthorProfiles([o[0].pubkey]),this.parsePosts(o)[0]||null)}catch(e){return console.error("Failed to decode nevent:",e),null}}async fetchPostByNaddr(e){try{const t=Ro.decode(e);if("naddr"!==t.type)return console.error("Not a valid naddr"),null;const n=t.data,r=n.relays&&n.relays.length>0?n.relays:this.relays,s={authors:[n.pubkey],kinds:[n.kind],"#d":[n.identifier],limit:1},o=await this.pool.querySync(r,s);if(0===o.length)return null;const i=o.reduce((e,t)=>t.created_at>e.created_at?t:e);return i?.pubkey&&await this.fetchAuthorProfiles([i.pubkey]),this.parsePost(i)}catch(e){return console.error("Failed to decode naddr:",e),null}}parsePosts(e){return e.map(e=>this.parsePost(e)).sort((e,t)=>(t.published_at||t.created_at)-(e.published_at||e.created_at))}parsePost(e){const t={...e};if(e.tags.forEach(([e,n])=>{switch(e){case"title":t.title=n;break;case"summary":t.summary=n;break;case"image":t.image=n;break;case"published_at":t.published_at=parseInt(n,10)}}),t.content=e.content,!t.summary&&e.content){let n=e.content.replace(/https?:\/\/\S+/gi,"").replace(/nostr:(naddr1|note1|npub1|nevent1|nprofile1|nrelay1)\S+/gi,"").replace(/(naddr1|note1|npub1|nevent1|nprofile1|nrelay1)\S+/gi,"").replace(/\s+/g," ").trim();t.summary=n.substring(0,200)+(n.length>200?"...":"")}if(!t.title)if(30023===e.kind){const n=e.content.match(/^#\s+(.+)$/m);t.title=n?n[1]:"Untitled Post"}else{const n=e.content.split("\n")[0];t.title=n.substring(0,50)+(n.length>50?"...":"")}const n=this.profileCache.get(e.pubkey);if(n?(t.authorName=n.display_name||n.name||"Anonymous",t.authorAvatar=n.picture,t.authorNip05=n.nip05):t.authorName=e.pubkey.substring(0,8)+"...",30023===e.kind){const n=e.tags.find(([e])=>"d"===e);if(n&&n[1])try{const r=Ro.naddrEncode({kind:e.kind,pubkey:e.pubkey,identifier:n[1],relays:this.relays.slice(0,2)});t.naddr=r}catch(e){console.error("Failed to encode naddr:",e)}}return t}close(){this.pool.close(this.relays)}}},701(e,t,n){n.d(t,{EH:()=>m,Hr:()=>w,Ki:()=>E,Rc:()=>x,To:()=>v,a:()=>D,a0:()=>j,gb:()=>y,n5:()=>b,sE:()=>r,vz:()=>k,wv:()=>F});const r={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return s(this.context.count)},getNextContextId(){return s(this.context.count++)}};function s(e){const t=String(e),n=t.length-1;return r.context.id+(n?String.fromCharCode(96+n):"")+t}function o(e){r.context=e}const i=(Symbol("solid-proxy"),Symbol("solid-track")),a=(Symbol("solid-dev-component"),{equals:(e,t)=>e===t});let l=P;const c={owned:null,cleanups:null,context:null,owner:null};var u=null;let h=null,d=null,f=null,p=null,g=0;function w(e,t){const n=d,r=u,s=0===e.length,o=void 0===t?r:t,i=s?c:{owned:null,cleanups:null,context:o?o.context:null,owner:o},a=s?e:()=>e(()=>k(()=>O(i)));u=i,d=null;try{return _(a,!0)}finally{d=n,u=r}}function b(e,t){const n={value:e,observers:null,observerSlots:null,comparator:(t=t?Object.assign({},a,t):a).equals||void 0};return[T.bind(n),e=>("function"==typeof e&&(e=h&&h.running&&h.sources.has(n)?e(n.tValue):e(n.value)),$(n,e))]}function y(e,t,n){const r=B(e,t,!1,1);R(r)}function m(e,t,n){l=C;const r=B(e,t,!1,1);n&&n.render||(r.user=!0),p?p.push(r):R(r)}function v(e,t,n){n=n?Object.assign({},a,n):a;const r=B(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,R(r),T.bind(r)}function k(e){if(null===d)return e();const t=d;d=null;try{return e()}finally{d=t}}function x(e){m(()=>k(e))}function E(e){return null===u||(null===u.cleanups?u.cleanups=[e]:u.cleanups.push(e)),e}const[S,A]=b(!1);function T(){const e=h&&h.running;if(this.sources&&(e?this.tState:this.state))if(1===(e?this.tState:this.state))R(this);else{const e=f;f=null,_(()=>U(this),!1),f=e}if(d){const e=this.observers?this.observers.length:0;d.sources?(d.sources.push(this),d.sourceSlots.push(e)):(d.sources=[this],d.sourceSlots=[e]),this.observers?(this.observers.push(d),this.observerSlots.push(d.sources.length-1)):(this.observers=[d],this.observerSlots=[d.sources.length-1])}return e&&h.sources.has(this)?this.tValue:this.value}function $(e,t,n){let r=h&&h.running&&h.sources.has(e)?e.tValue:e.value;if(!e.comparator||!e.comparator(r,t)){if(h){const r=h.running;(r||!n&&h.sources.has(e))&&(h.sources.add(e),e.tValue=t),r||(e.value=t)}else e.value=t;e.observers&&e.observers.length&&_(()=>{for(let t=0;t<e.observers.length;t+=1){const n=e.observers[t],r=h&&h.running;r&&h.disposed.has(n)||((r?n.tState:n.state)||(n.pure?f.push(n):p.push(n),n.observers&&N(n)),r?n.tState=1:n.state=1)}if(f.length>1e6)throw f=[],new Error},!1)}return t}function R(e){if(!e.fn)return;O(e);const t=g;I(e,h&&h.running&&h.sources.has(e)?e.tValue:e.value,t),h&&!h.running&&h.sources.has(e)&&queueMicrotask(()=>{_(()=>{h&&(h.running=!0),d=u=e,I(e,e.tValue,t),d=u=null},!1)})}function I(e,t,n){let r;const s=u,o=d;d=u=e;try{r=e.fn(t)}catch(t){return e.pure&&(h&&h.running?(e.tState=1,e.tOwned&&e.tOwned.forEach(O),e.tOwned=void 0):(e.state=1,e.owned&&e.owned.forEach(O),e.owned=null)),e.updatedAt=n+1,q(t)}finally{d=o,u=s}(!e.updatedAt||e.updatedAt<=n)&&(null!=e.updatedAt&&"observers"in e?$(e,r,!0):h&&h.running&&e.pure?(h.sources.add(e),e.tValue=r):e.value=r,e.updatedAt=n)}function B(e,t,n,r=1,s){const o={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:u,context:u?u.context:null,pure:n};return h&&h.running&&(o.state=0,o.tState=r),null===u||u!==c&&(h&&h.running&&u.pure?u.tOwned?u.tOwned.push(o):u.tOwned=[o]:u.owned?u.owned.push(o):u.owned=[o]),o}function L(e){const t=h&&h.running;if(0===(t?e.tState:e.state))return;if(2===(t?e.tState:e.state))return U(e);if(e.suspense&&k(e.suspense.inFallback))return e.suspense.effects.push(e);const n=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<g);){if(t&&h.disposed.has(e))return;(t?e.tState:e.state)&&n.push(e)}for(let r=n.length-1;r>=0;r--){if(e=n[r],t){let t=e,s=n[r+1];for(;(t=t.owner)&&t!==s;)if(h.disposed.has(t))return}if(1===(t?e.tState:e.state))R(e);else if(2===(t?e.tState:e.state)){const t=f;f=null,_(()=>U(e,n[0]),!1),f=t}}}function _(e,t){if(f)return e();let n=!1;t||(f=[]),p?n=!0:p=[],g++;try{const t=e();return function(e){if(f&&(P(f),f=null),e)return;let t;if(h)if(h.promises.size||h.queue.size){if(h.running)return h.running=!1,h.effects.push.apply(h.effects,p),p=null,void A(!0)}else{const e=h.sources,n=h.disposed;p.push.apply(p,h.effects),t=h.resolve;for(const e of p)"tState"in e&&(e.state=e.tState),delete e.tState;h=null,_(()=>{for(const e of n)O(e);for(const t of e){if(t.value=t.tValue,t.owned)for(let e=0,n=t.owned.length;e<n;e++)O(t.owned[e]);t.tOwned&&(t.owned=t.tOwned),delete t.tValue,delete t.tOwned,t.tState=0}A(!1)},!1)}const n=p;p=null,n.length&&_(()=>l(n),!1),t&&t()}(n),t}catch(e){n||(p=null),f=null,q(e)}}function P(e){for(let t=0;t<e.length;t++)L(e[t])}function C(e){let t,n=0;for(t=0;t<e.length;t++){const r=e[t];r.user?e[n++]=r:L(r)}if(r.context){if(r.count)return r.effects||(r.effects=[]),void r.effects.push(...e.slice(0,n));o()}for(!r.effects||!r.done&&r.count||(e=[...r.effects,...e],n+=r.effects.length,delete r.effects),t=0;t<n;t++)L(e[t])}function U(e,t){const n=h&&h.running;n?e.tState=0:e.state=0;for(let r=0;r<e.sources.length;r+=1){const s=e.sources[r];if(s.sources){const e=n?s.tState:s.state;1===e?s!==t&&(!s.updatedAt||s.updatedAt<g)&&L(s):2===e&&U(s,t)}}}function N(e){const t=h&&h.running;for(let n=0;n<e.observers.length;n+=1){const r=e.observers[n];(t?r.tState:r.state)||(t?r.tState=2:r.state=2,r.pure?f.push(r):p.push(r),r.observers&&N(r))}}function O(e){let t;if(e.sources)for(;e.sources.length;){const t=e.sources.pop(),n=e.sourceSlots.pop(),r=t.observers;if(r&&r.length){const e=r.pop(),s=t.observerSlots.pop();n<r.length&&(e.sourceSlots[s]=n,r[n]=e,t.observerSlots[n]=s)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)O(e.tOwned[t]);delete e.tOwned}if(h&&h.running&&e.pure)z(e,!0);else if(e.owned){for(t=e.owned.length-1;t>=0;t--)O(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}h&&h.running?e.tState=0:e.state=0}function z(e,t){if(t||(e.tState=0,h.disposed.add(e)),e.owned)for(let t=0;t<e.owned.length;t++)z(e.owned[t])}function q(e,t=u){const n=function(e){return e instanceof Error?e:new Error("string"==typeof e?e:"Unknown error",{cause:e})}(e);throw n}const M=Symbol("fallback");function H(e){for(let t=0;t<e.length;t++)e[t]()}function j(e,t){return k(()=>e(t||{}))}function D(e){const t="fallback"in e&&{fallback:()=>e.fallback};return v(function(e,t,n={}){let r=[],s=[],o=[],a=0,l=t.length>1?[]:null;return E(()=>H(o)),()=>{let c,u,h=e()||[],d=h.length;return h[i],k(()=>{let e,t,i,p,g,b,y,m,v;if(0===d)0!==a&&(H(o),o=[],r=[],s=[],a=0,l&&(l=[])),n.fallback&&(r=[M],s[0]=w(e=>(o[0]=e,n.fallback())),a=1);else if(0===a){for(s=new Array(d),u=0;u<d;u++)r[u]=h[u],s[u]=w(f);a=d}else{for(i=new Array(d),p=new Array(d),l&&(g=new Array(d)),b=0,y=Math.min(a,d);b<y&&r[b]===h[b];b++);for(y=a-1,m=d-1;y>=b&&m>=b&&r[y]===h[m];y--,m--)i[m]=s[y],p[m]=o[y],l&&(g[m]=l[y]);for(e=new Map,t=new Array(m+1),u=m;u>=b;u--)v=h[u],c=e.get(v),t[u]=void 0===c?-1:c,e.set(v,u);for(c=b;c<=y;c++)v=r[c],u=e.get(v),void 0!==u&&-1!==u?(i[u]=s[c],p[u]=o[c],l&&(g[u]=l[c]),u=t[u],e.set(v,u)):o[c]();for(u=b;u<d;u++)u in i?(s[u]=i[u],o[u]=p[u],l&&(l[u]=g[u],l[u](u))):s[u]=w(f);s=s.slice(0,a=d),r=h.slice(0)}return s});function f(e){if(o[u]=e,l){const[e,n]=b(u);return l[u]=n,t(h[u],e)}return t(h[u])}}}(()=>e.each,e.children,t||void 0))}function F(e){const t=e.keyed,n=v(()=>e.when,void 0,void 0),r=t?n:v(n,void 0,{equals:(e,t)=>!e==!t});return v(()=>{const s=r();if(s){const o=e.children;return"function"==typeof o&&o.length>0?k(()=>o(t?s:()=>{if(!k(r))throw`Stale read from <${"Show"}>.`;return n()})):o}return e.fallback},void 0,void 0)}}},r={};function s(e){var t=r[e];if(void 0!==t)return t.exports;var o=r[e]={exports:{}};return n[e](o,o.exports,s),o.exports}s.m=n,s.d=(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.f={},s.e=e=>Promise.all(Object.keys(s.f).reduce((t,n)=>(s.f[n](e,t),t),[])),s.u=e=>e+".nostr-blog.js",s.miniCssF=e=>{},s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e={},t="NostrBlog:",s.l=(n,r,o,i)=>{if(e[n])e[n].push(r);else{var a,l;if(void 0!==o)for(var c=document.getElementsByTagName("script"),u=0;u<c.length;u++){var h=c[u];if(h.getAttribute("src")==n||h.getAttribute("data-webpack")==t+o){a=h;break}}a||(l=!0,(a=document.createElement("script")).charset="utf-8",s.nc&&a.setAttribute("nonce",s.nc),a.setAttribute("data-webpack",t+o),a.src=n),e[n]=[r];var d=(t,r)=>{a.onerror=a.onload=null,clearTimeout(f);var s=e[n];if(delete e[n],a.parentNode&&a.parentNode.removeChild(a),s&&s.forEach(e=>e(r)),t)return t(r)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=d.bind(null,a.onerror),a.onload=d.bind(null,a.onload),l&&document.head.appendChild(a)}},s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;s.g.importScripts&&(e=s.g.location+"");var t=s.g.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");if(n.length)for(var r=n.length-1;r>-1&&(!e||!/^http(s?):/.test(e));)e=n[r--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=e})(),(()=>{var e={792:0};s.f.j=(t,n)=>{var r=s.o(e,t)?e[t]:void 0;if(0!==r)if(r)n.push(r[2]);else{var o=new Promise((n,s)=>r=e[t]=[n,s]);n.push(r[2]=o);var i=s.p+s.u(t),a=new Error;s.l(i,n=>{if(s.o(e,t)&&(0!==(r=e[t])&&(e[t]=void 0),r)){var o=n&&("load"===n.type?"missing":n.type),i=n&&n.target&&n.target.src;a.message="Loading chunk "+t+" failed.\n("+o+": "+i+")",a.name="ChunkLoadError",a.type=o,a.request=i,r[1](a)}},"chunk-"+t,t)}};var t=(t,n)=>{var r,o,[i,a,l]=n,c=0;if(i.some(t=>0!==e[t])){for(r in a)s.o(a,r)&&(s.m[r]=a[r]);l&&l(s)}for(t&&t(n);c<i.length;c++)o=i[c],s.o(e,o)&&e[o]&&e[o][0](),e[o]=0},n=this.webpackChunkNostrBlog=this.webpackChunkNostrBlog||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))})();var o={};s.d(o,{default:()=>ot});var i=s(701),a=s(35),l=s(261),c=s(168);var u={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function h(e){u=e}var d={exec:()=>null};function f(e,t=""){let n="string"==typeof e?e:e.source,r={replace:(e,t)=>{let s="string"==typeof t?t:t.source;return s=s.replace(g.caret,"$1"),n=n.replace(e,s),r},getRegex:()=>new RegExp(n,t)};return r}var p=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),g={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},w=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,b=/(?:[*+-]|\d{1,9}[.)])/,y=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,m=f(y).replace(/bull/g,b).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),v=f(y).replace(/bull/g,b).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),k=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,x=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,E=f(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",x).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),S=f(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,b).getRegex(),A="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",T=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,$=f("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",T).replace("tag",A).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),R=f(k).replace("hr",w).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),I={blockquote:f(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",R).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:E,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:w,html:$,lheading:m,list:S,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:R,table:d,text:/^[^\n]+/},B=f("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",w).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),L={...I,lheading:v,table:B,paragraph:f(k).replace("hr",w).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",B).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex()},_={...I,html:f("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",T).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:d,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:f(k).replace("hr",w).replace("heading"," *#{1,6} *[^\n]").replace("lheading",m).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},P=/^( {2,}|\\)\n(?!\s*$)/,C=/[\p{P}\p{S}]/u,U=/[\s\p{P}\p{S}]/u,N=/[^\s\p{P}\p{S}]/u,O=f(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,U).getRegex(),z=/(?!~)[\p{P}\p{S}]/u,q=f(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",p?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),M=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,H=f(M,"u").replace(/punct/g,C).getRegex(),j=f(M,"u").replace(/punct/g,z).getRegex(),D="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",F=f(D,"gu").replace(/notPunctSpace/g,N).replace(/punctSpace/g,U).replace(/punct/g,C).getRegex(),V=f(D,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,z).getRegex(),W=f("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,N).replace(/punctSpace/g,U).replace(/punct/g,C).getRegex(),Z=f(/\\(punct)/,"gu").replace(/punct/g,C).getRegex(),K=f(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Y=f(T).replace("(?:--\x3e|$)","--\x3e").getRegex(),G=f("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Y).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),J=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,Q=f(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",J).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),X=f(/^!?\[(label)\]\[(ref)\]/).replace("label",J).replace("ref",x).getRegex(),ee=f(/^!?\[(ref)\](?:\[\])?/).replace("ref",x).getRegex(),te=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,ne={_backpedal:d,anyPunctuation:Z,autolink:K,blockSkip:q,br:P,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:d,emStrongLDelim:H,emStrongRDelimAst:F,emStrongRDelimUnd:W,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:Q,nolink:ee,punctuation:O,reflink:X,reflinkSearch:f("reflink|nolink(?!\\()","g").replace("reflink",X).replace("nolink",ee).getRegex(),tag:G,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:d},re={...ne,link:f(/^!?\[(label)\]\((.*?)\)/).replace("label",J).getRegex(),reflink:f(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",J).getRegex()},se={...ne,emStrongRDelimAst:V,emStrongLDelim:j,url:f(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",te).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:f(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",te).getRegex()},oe={...se,br:f(P).replace("{2,}","*").getRegex(),text:f(se.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},ie={normal:I,gfm:L,pedantic:_},ae={normal:ne,gfm:se,breaks:oe,pedantic:re},le={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ce=e=>le[e];function ue(e,t){if(t){if(g.escapeTest.test(e))return e.replace(g.escapeReplace,ce)}else if(g.escapeTestNoEncode.test(e))return e.replace(g.escapeReplaceNoEncode,ce);return e}function he(e){try{e=encodeURI(e).replace(g.percentDecode,"%")}catch{return null}return e}function de(e,t){let n=e.replace(g.findPipe,(e,t,n)=>{let r=!1,s=t;for(;--s>=0&&"\\"===n[s];)r=!r;return r?"|":" |"}).split(g.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;r<n.length;r++)n[r]=n[r].trim().replace(g.slashPipe,"|");return n}function fe(e,t,n){let r=e.length;if(0===r)return"";let s=0;for(;s<r;){let o=e.charAt(r-s-1);if(o!==t||n){if(o===t||!n)break;s++}else s++}return e.slice(0,r-s)}function pe(e,t,n,r,s){let o=t.href,i=t.title||null,a=e[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;let l={type:"!"===e[0].charAt(0)?"image":"link",raw:n,href:o,title:i,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}var ge=class{options;rules;lexer;constructor(e){this.options=e||u}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:fe(e,"\n")}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=function(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(null===r)return t;let s=r[1];return t.split("\n").map(e=>{let t=e.match(n.other.beginningSpace);if(null===t)return e;let[r]=t;return r.length>=s.length?e.slice(s.length):e}).join("\n")}(e,t[3]||"",this.rules);return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=fe(e,"#");(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:fe(t[0],"\n")}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=fe(t[0],"\n").split("\n"),n="",r="",s=[];for(;e.length>0;){let t,o=!1,i=[];for(t=0;t<e.length;t++)if(this.rules.other.blockquoteStart.test(e[t]))i.push(e[t]),o=!0;else{if(o)break;i.push(e[t])}e=e.slice(t);let a=i.join("\n"),l=a.replace(this.rules.other.blockquoteSetextReplace,"\n $1").replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}\n${a}`:a,r=r?`${r}\n${l}`:l;let c=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,s,!0),this.lexer.state.top=c,0===e.length)break;let u=s.at(-1);if("code"===u?.type)break;if("blockquote"===u?.type){let t=u,o=t.raw+"\n"+e.join("\n"),i=this.blockquote(o);s[s.length-1]=i,n=n.substring(0,n.length-t.raw.length)+i.raw,r=r.substring(0,r.length-t.text.length)+i.text;break}if("list"===u?.type){let t=u,o=t.raw+"\n"+e.join("\n"),i=this.list(o);s[s.length-1]=i,n=n.substring(0,n.length-u.raw.length)+i.raw,r=r.substring(0,r.length-t.raw.length)+i.raw,e=o.substring(s.at(-1).raw.length).split("\n");continue}}return{type:"blockquote",raw:n,tokens:s,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let o=this.rules.other.listItemRegex(n),i=!1;for(;e;){let n=!1,r="",a="";if(!(t=o.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let l=t[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,e=>" ".repeat(3*e.length)),c=e.split("\n",1)[0],u=!l.trim(),h=0;if(this.options.pedantic?(h=2,a=l.trimStart()):u?h=t[1].length+1:(h=t[2].search(this.rules.other.nonSpaceChar),h=h>4?1:h,a=l.slice(h),h+=t[1].length),u&&this.rules.other.blankLine.test(c)&&(r+=c+"\n",e=e.substring(c.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(h),n=this.rules.other.hrRegex(h),s=this.rules.other.fencesBeginRegex(h),o=this.rules.other.headingBeginRegex(h),i=this.rules.other.htmlBeginRegex(h);for(;e;){let d,f=e.split("\n",1)[0];if(c=f,this.options.pedantic?(c=c.replace(this.rules.other.listReplaceNesting," "),d=c):d=c.replace(this.rules.other.tabCharGlobal," "),s.test(c)||o.test(c)||i.test(c)||t.test(c)||n.test(c))break;if(d.search(this.rules.other.nonSpaceChar)>=h||!c.trim())a+="\n"+d.slice(h);else{if(u||l.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||s.test(l)||o.test(l)||n.test(l))break;a+="\n"+c}!u&&!c.trim()&&(u=!0),r+=f+"\n",e=e.substring(f.length+1),l=d.slice(h)}}s.loose||(i?s.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(i=!0)),s.items.push({type:"list_item",raw:r,task:!!this.options.gfm&&this.rules.other.listIsTask.test(a),loose:!1,text:a,tokens:[]}),s.raw+=r}let a=s.items.at(-1);if(!a)return;a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd(),s.raw=s.raw.trimEnd();for(let e of s.items){if(this.lexer.state.top=!1,e.tokens=this.lexer.blockTokens(e.text,[]),e.task){if(e.text=e.text.replace(this.rules.other.listReplaceTask,""),"text"===e.tokens[0]?.type||"paragraph"===e.tokens[0]?.type){e.tokens[0].raw=e.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),e.tokens[0].text=e.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let e=this.lexer.inlineQueue.length-1;e>=0;e--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[e].src)){this.lexer.inlineQueue[e].src=this.lexer.inlineQueue[e].src.replace(this.rules.other.listReplaceTask,"");break}}let t=this.rules.other.listTaskCheckbox.exec(e.raw);if(t){let n={type:"checkbox",raw:t[0]+" ",checked:"[ ]"!==t[0]};e.checked=n.checked,s.loose?e.tokens[0]&&["paragraph","text"].includes(e.tokens[0].type)&&"tokens"in e.tokens[0]&&e.tokens[0].tokens?(e.tokens[0].raw=n.raw+e.tokens[0].raw,e.tokens[0].text=n.raw+e.tokens[0].text,e.tokens[0].tokens.unshift(n)):e.tokens.unshift({type:"paragraph",raw:n.raw,text:n.raw,tokens:[n]}):e.tokens.unshift(n)}}if(!s.loose){let t=e.tokens.filter(e=>"space"===e.type),n=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw));s.loose=n}}if(s.loose)for(let e of s.items){e.loose=!0;for(let t of e.tokens)"text"===t.type&&(t.type="paragraph")}return s}}html(e){let t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}def(e){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:r}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=de(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split("\n"):[],o={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(let e of r)this.rules.other.tableAlignRight.test(e)?o.align.push("right"):this.rules.other.tableAlignCenter.test(e)?o.align.push("center"):this.rules.other.tableAlignLeft.test(e)?o.align.push("left"):o.align.push(null);for(let e=0;e<n.length;e++)o.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:o.align[e]});for(let e of s)o.rows.push(de(e,o.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:o.align[t]})));return o}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=fe(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{let e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let r=0;r<e.length;r++)if("\\"===e[r])r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}(t[2],"()");if(-2===e)return;if(e>-1){let n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],r="";if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),pe(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return pe(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!r[1]&&!r[2]||!n||this.rules.inline.punctuation.exec(n))){let n,s,o=[...r[0]].length-1,i=o,a=0,l="*"===r[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+o);null!=(r=l.exec(t));){if(n=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!n)continue;if(s=[...n].length,r[3]||r[4]){i+=s;continue}if((r[5]||r[6])&&o%3&&!((o+s)%3)){a+=s;continue}if(i-=s,i>0)continue;s=Math.min(s,s+i+a);let t=[...r[0]][0].length,l=e.slice(0,o+r.index+t+s);if(Math.min(o,s)%2){let e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}let c=l.slice(2,-2);return{type:"strong",raw:l,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal," "),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:"codespan",raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=t[1],n="mailto:"+e):(e=t[1],n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=t[0],n="mailto:"+e;else{let r;do{r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(r!==t[0]);e=t[0],n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:e}}}},we=class e{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||u,this.options.tokenizer=this.options.tokenizer||new ge,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:g,block:ie.normal,inline:ae.normal};this.options.pedantic?(t.block=ie.pedantic,t.inline=ae.pedantic):this.options.gfm&&(t.block=ie.gfm,this.options.breaks?t.inline=ae.breaks:t.inline=ae.gfm),this.tokenizer.rules=t}static get rules(){return{block:ie,inline:ae}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(g.carriageReturn,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(g.tabCharGlobal," ").replace(g.spaceLine,""));e;){let r;if(this.options.extensions?.block?.some(n=>!!(r=n.call({lexer:this},e,t))&&(e=e.substring(r.raw.length),t.push(r),!0)))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);1===r.raw.length&&void 0!==n?n.raw+="\n":t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+r.raw,n.text+="\n"+r.text,this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if(r=this.tokenizer.fences(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.heading(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.hr(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.blockquote(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.list(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.html(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+r.raw,n.text+="\n"+r.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},t.push(r));continue}if(r=this.tokenizer.table(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.lheading(e)){e=e.substring(r.raw.length),t.push(r);continue}let s=e;if(this.options.extensions?.startBlock){let t,n=1/0,r=e.slice(1);this.options.extensions.startBlock.forEach(e=>{t=e.call({lexer:this},r),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(s=e.substring(0,n+1))}if(this.state.top&&(r=this.tokenizer.paragraph(s))){let o=t.at(-1);n&&"paragraph"===o?.type?(o.raw+=(o.raw.endsWith("\n")?"":"\n")+r.raw,o.text+="\n"+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):t.push(r),n=s.length!==e.length,e=e.substring(r.raw.length);continue}if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let n=t.at(-1);"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+r.raw,n.text+="\n"+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n,r=e,s=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(s=this.tokenizer.rules.inline.reflinkSearch.exec(r));)e.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(s=this.tokenizer.rules.inline.anyPunctuation.exec(r));)r=r.slice(0,s.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(s=this.tokenizer.rules.inline.blockSkip.exec(r));)n=s[2]?s[2].length:0,r=r.slice(0,s.index+n)+"["+"a".repeat(s[0].length-n-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let o=!1,i="";for(;e;){let n;if(o||(i=""),o=!1,this.options.extensions?.inline?.some(r=>!!(n=r.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))continue;if(n=this.tokenizer.escape(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.tag(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.link(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(n.raw.length);let r=t.at(-1);"text"===n.type&&"text"===r?.type?(r.raw+=n.raw,r.text+=n.text):t.push(n);continue}if(n=this.tokenizer.emStrong(e,r,i)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.codespan(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.br(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.del(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.autolink(e)){e=e.substring(n.raw.length),t.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(e))){e=e.substring(n.raw.length),t.push(n);continue}let s=e;if(this.options.extensions?.startInline){let t,n=1/0,r=e.slice(1);this.options.extensions.startInline.forEach(e=>{t=e.call({lexer:this},r),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(s=e.substring(0,n+1))}if(n=this.tokenizer.inlineText(s)){e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(i=n.raw.slice(-1)),o=!0;let r=t.at(-1);"text"===r?.type?(r.raw+=n.raw,r.text+=n.text):t.push(n);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return t}},be=class{options;parser;constructor(e){this.options=e||u}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(g.notSpaceStart)?.[0],s=e.replace(g.endingNewline,"")+"\n";return r?'<pre><code class="language-'+ue(r)+'">'+(n?s:ue(s,!0))+"</code></pre>\n":"<pre><code>"+(n?s:ue(s,!0))+"</code></pre>\n"}blockquote({tokens:e}){return`<blockquote>\n${this.parser.parse(e)}</blockquote>\n`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>\n`}hr(e){return"<hr>\n"}list(e){let t=e.ordered,n=e.start,r="";for(let t=0;t<e.items.length;t++){let n=e.items[t];r+=this.listitem(n)}let s=t?"ol":"ul";return"<"+s+(t&&1!==n?' start="'+n+'"':"")+">\n"+r+"</"+s+">\n"}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>\n`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>\n`}table(e){let t="",n="";for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r="";for(let t=0;t<e.rows.length;t++){let s=e.rows[t];n="";for(let e=0;e<s.length;e++)n+=this.tablecell(s[e]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),"<table>\n<thead>\n"+t+"</thead>\n"+r+"</table>\n"}tablerow({text:e}){return`<tr>\n${e}</tr>\n`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>\n`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${ue(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),s=he(e);if(null===s)return r;let o='<a href="'+(e=s)+'"';return t&&(o+=' title="'+ue(t)+'"'),o+=">"+r+"</a>",o}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let s=he(e);if(null===s)return ue(n);let o=`<img src="${e=s}" alt="${n}"`;return t&&(o+=` title="${ue(t)}"`),o+=">",o}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:ue(e.text)}},ye=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},me=class e{options;renderer;textRenderer;constructor(e){this.options=e||u,this.options.renderer=this.options.renderer||new be,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ye}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){let t="";for(let n=0;n<e.length;n++){let r=e[n];if(this.options.extensions?.renderers?.[r.type]){let e=r,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==n||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(e.type)){t+=n||"";continue}}let s=r;switch(s.type){case"space":t+=this.renderer.space(s);break;case"hr":t+=this.renderer.hr(s);break;case"heading":t+=this.renderer.heading(s);break;case"code":t+=this.renderer.code(s);break;case"table":t+=this.renderer.table(s);break;case"blockquote":t+=this.renderer.blockquote(s);break;case"list":t+=this.renderer.list(s);break;case"checkbox":t+=this.renderer.checkbox(s);break;case"html":t+=this.renderer.html(s);break;case"def":t+=this.renderer.def(s);break;case"paragraph":t+=this.renderer.paragraph(s);break;case"text":t+=this.renderer.text(s);break;default:{let e='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return t}parseInline(e,t=this.renderer){let n="";for(let r=0;r<e.length;r++){let s=e[r];if(this.options.extensions?.renderers?.[s.type]){let e=this.options.extensions.renderers[s.type].call({parser:this},s);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type)){n+=e||"";continue}}let o=s;switch(o.type){case"escape":case"text":n+=t.text(o);break;case"html":n+=t.html(o);break;case"link":n+=t.link(o);break;case"image":n+=t.image(o);break;case"checkbox":n+=t.checkbox(o);break;case"strong":n+=t.strong(o);break;case"em":n+=t.em(o);break;case"codespan":n+=t.codespan(o);break;case"br":n+=t.br(o);break;case"del":n+=t.del(o);break;default:{let e='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}},ve=class{options;block;constructor(e){this.options=e||u}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(){return this.block?we.lex:we.lexInline}provideParser(){return this.block?me.parse:me.parseInline}},ke=new class{defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=me;Renderer=be;TextRenderer=ye;Lexer=we;Tokenizer=ge;Hooks=ve;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let s=e[r].flat(1/0);n=n.concat(this.walkTokens(s,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){let n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let r=e.renderer.apply(this,t);return!1===r&&(r=n.apply(this,t)),r}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new be(this.defaults);for(let n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if(["options","parser"].includes(n))continue;let r=n,s=e.renderer[r],o=t[r];t[r]=(...e)=>{let n=s.apply(t,e);return!1===n&&(n=o.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new ge(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;let r=n,s=e.tokenizer[r],o=t[r];t[r]=(...e)=>{let n=s.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new ve;for(let n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if(["options","block"].includes(n))continue;let r=n,s=e.hooks[r],o=t[r];ve.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async&&ve.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await s.call(t,e);return o.call(t,n)})();let r=s.call(t,e);return o.call(t,r)}:t[r]=(...e)=>{if(this.defaults.async)return(async()=>{let n=await s.apply(t,e);return!1===n&&(n=await o.apply(t,e)),n})();let n=s.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return we.lex(e,t??this.defaults)}parser(e,t){return me.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},s={...this.defaults,...r},o=this.onError(!!s.silent,!!s.async);if(!0===this.defaults.async&&!1===r.async)return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||null===t)return o(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof t)return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=e),s.async)return(async()=>{let n=s.hooks?await s.hooks.preprocess(t):t,r=await(s.hooks?await s.hooks.provideLexer():e?we.lex:we.lexInline)(n,s),o=s.hooks?await s.hooks.processAllTokens(r):r;s.walkTokens&&await Promise.all(this.walkTokens(o,s.walkTokens));let i=await(s.hooks?await s.hooks.provideParser():e?me.parse:me.parseInline)(o,s);return s.hooks?await s.hooks.postprocess(i):i})().catch(o);try{s.hooks&&(t=s.hooks.preprocess(t));let n=(s.hooks?s.hooks.provideLexer():e?we.lex:we.lexInline)(t,s);s.hooks&&(n=s.hooks.processAllTokens(n)),s.walkTokens&&this.walkTokens(n,s.walkTokens);let r=(s.hooks?s.hooks.provideParser():e?me.parse:me.parseInline)(n,s);return s.hooks&&(r=s.hooks.postprocess(r)),r}catch(e){return o(e)}}}onError(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){let e="<p>An error occurred:</p><pre>"+ue(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function xe(e,t){return ke.parse(e,t)}xe.options=xe.setOptions=function(e){return ke.setOptions(e),xe.defaults=ke.defaults,h(xe.defaults),xe},xe.getDefaults=function(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}},xe.defaults=u,xe.use=function(...e){return ke.use(...e),xe.defaults=ke.defaults,h(xe.defaults),xe},xe.walkTokens=function(e,t){return ke.walkTokens(e,t)},xe.parseInline=ke.parseInline,xe.Parser=me,xe.parser=me.parse,xe.Renderer=be,xe.TextRenderer=ye,xe.Lexer=we,xe.lexer=we.lex,xe.Tokenizer=ge,xe.Hooks=ve,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,me.parse,we.lex;var Ee=(0,a.vs)('<div class="nbw-p-4 nbw-text-gray-500 nbw-text-sm">Loading post...'),Se=(0,a.vs)('<div class="nbw-p-4 nbw-text-red-500 nbw-text-sm">Failed to load embedded post'),Ae=(0,a.vs)('<img class="nbw-w-full nbw-h-32 nbw-object-cover nbw-rounded nbw-mb-3">'),Te=(0,a.vs)('<p class="nbw-text-sm nbw-text-gray-600 nbw-mb-3 nbw-line-clamp-2">'),$e=(0,a.vs)('<img class="nbw-w-5 nbw-h-5 nbw-rounded-full">'),Re=(0,a.vs)('<a class="nbw-block nbw-no-underline hover:nbw-no-underline"><div class="nbw-embedded-post-content nbw-p-4"><h4 class="nbw-text-lg nbw-font-semibold nbw-text-gray-900 nbw-mb-2 nbw-line-clamp-2"></h4><div class="nbw-flex nbw-items-center nbw-gap-2 nbw-text-xs nbw-text-gray-500"><span class="nbw-font-medium nbw-text-gray-700"></span><span>•</span><span>'),Ie=(0,a.vs)('<div class="nbw-embedded-post nbw-my-4 nbw-border nbw-border-gray-300 nbw-rounded-lg nbw-overflow-hidden nbw-bg-gray-50 hover:nbw-bg-gray-100 nbw-transition-colors">');const Be=e=>{const[t,n]=(0,i.n5)(null),[r,s]=(0,i.n5)(!0),[o,l]=(0,i.n5)(!1);return(0,i.Rc)(async()=>{try{s(!0);const t=await e.onFetch(e.eventId);n(t),l(!t)}catch(e){console.error("Failed to fetch embedded post:",e),l(!0)}finally{s(!1)}}),c=Ie(),(0,a.Yr)(c,(0,i.a0)(i.wv,{get when(){return r()},get children(){return Ee()}}),null),(0,a.Yr)(c,(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!o())()&&!r()},get children(){return Se()}}),null),(0,a.Yr)(c,(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!t())()&&!r()},get children(){var n=Re(),r=n.firstChild,s=r.firstChild,o=s.nextSibling,l=o.firstChild,c=l.nextSibling.nextSibling;return(0,a.Yr)(r,(0,i.a0)(i.wv,{get when(){return t().image},get children(){var e=Ae();return(0,i.gb)(n=>{var r=t().image,s=t().title;return r!==n.e&&(0,a.Bq)(e,"src",n.e=r),s!==n.t&&(0,a.Bq)(e,"alt",n.t=s),n},{e:void 0,t:void 0}),e}}),s),(0,a.Yr)(s,()=>t().title||"Untitled Post"),(0,a.Yr)(r,(0,i.a0)(i.wv,{get when(){return t().summary},get children(){var e=Te();return(0,a.Yr)(e,()=>t().summary),e}}),o),(0,a.Yr)(o,(0,i.a0)(i.wv,{get when(){return t().authorAvatar},get children(){var e=$e();return(0,i.gb)(n=>{var r=t().authorAvatar,s=t().authorName;return r!==n.e&&(0,a.Bq)(e,"src",n.e=r),s!==n.t&&(0,a.Bq)(e,"alt",n.t=s),n},{e:void 0,t:void 0}),e}}),l),(0,a.Yr)(l,()=>t().authorName),(0,a.Yr)(c,()=>{return e=t().published_at||t().created_at,new Date(1e3*e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});var e}),(0,i.gb)(()=>(0,a.Bq)(n,"href",`#/post/${e.eventId}`)),n}}),null),c;var c};var Le=(0,a.vs)("<div class=nbw-content-renderer>"),_e=(0,a.vs)("<div>");const Pe=e=>{const[t,n]=(0,i.n5)([]),[r,s]=(0,i.n5)([]);return(0,i.EH)(()=>{(e=>{const t=/(?:nostr\s*:?\s*)?(naddr1\S+|note1\S+|nevent1\S+|nprofile1\S+|npub1\S+|nrelay1\S+)/gi,r=[],o=[];let i,a=0,l=0;for(;null!==(i=t.exec(e));){const t=i[1].trim().replace(/[)\]\}\.,!?:;"'>]+$/,""),n=t.substring(0,t.indexOf("1")+1).toLowerCase();let s="other";if(n.startsWith("naddr")?s="naddr":n.startsWith("nevent")?s="nevent":n.startsWith("note")&&(s="note"),"other"!==s){o.push(e.substring(a,i.index));const n="nostr-ref-"+l++;o.push(`[[${n}]]`),r.push({id:n,fullId:t,type:s}),a=i.index+i[0].length}}o.push(e.substring(a));const c=o.map(e=>{if(e.startsWith("[[")&&e.endsWith("]]"))return e;let t=(e=>e.replace(/(https?:\/\/[^\s]+\.(?:jpg|jpeg|png|gif|webp|svg|mp4|webm|mov|avi))/gi,e=>{const t=e.toLowerCase();return t.endsWith(".mp4")||t.endsWith(".webm")||t.endsWith(".mov")||t.endsWith(".avi")?`\n\n<video controls class="nbw-content-video nbw-max-w-full nbw-h-auto nbw-rounded-lg nbw-my-4"><source src="${e}"></video>\n\n`:`\n\n<img src="${e}" alt="Image" class="nbw-content-image nbw-max-w-full nbw-h-auto nbw-rounded-lg nbw-my-4" />\n\n`}))(e);return t=t.replace(/(?:nostr:\s*)?(npub1\S+|nprofile1\S+|nrelay1\S+)/gi,(e,t)=>`<a href="https://njump.me/${t}" target="_blank" rel="noopener noreferrer" class="nbw-nostr-link nbw-text-blue-600 hover:nbw-underline">${t}</a>`),t});n(r),s(c)})(e.content)}),o=Le(),(0,a.Yr)(o,(0,i.a0)(i.a,{get each(){return r()},children:n=>{if(n.startsWith("[[")&&n.endsWith("]]")){const r=n.slice(2,-2),s=t().find(e=>e.id===r);return s?(0,i.a0)(Be,{get eventId(){return s.fullId},get onFetch(){return e.onFetchPost}}):null}if(e.useMarkdown)return s=_e(),(0,i.gb)(()=>s.innerHTML=xe(n)),s;{const e=n.replace(/\n/g,"<br />");return(r=_e()).innerHTML=e,r}var r,s}})),o;var o};var Ce=(0,a.vs)('<div class="nbw-grid nbw-gap-6">'),Ue=(0,a.vs)('<div class="nbw-py-2 nbw-border-b nbw-border-gray-200"><div class="nbw-text-gray-500 nbw-text-xs nbw-mb-1"></div><a class="nbw-text-blue-600 hover:nbw-underline nbw-font-medium nbw-no-underline hover:nbw-text-blue-800">'),Ne=(0,a.vs)('<article class="nbw-bg-white nbw-rounded-lg nbw-shadow-md nbw-overflow-hidden nbw-transition-transform hover:nbw-scale-105 nbw-cursor-pointer"><div class=nbw-p-6><h2 class="nbw-text-2xl nbw-font-bold nbw-mb-2 nbw-text-gray-900"></h2><div class="nbw-flex nbw-items-center nbw-gap-3 nbw-mb-3"><div class=nbw-flex-1><p class="nbw-text-gray-900 nbw-text-sm nbw-font-medium"></p><p class="nbw-text-gray-600 nbw-text-xs">'),Oe=(0,a.vs)('<img class="nbw-w-full nbw-h-48 nbw-object-cover">'),ze=(0,a.vs)('<img class="nbw-w-8 nbw-h-8 nbw-rounded-full nbw-object-cover">'),qe=(0,a.vs)('<a class="nbw-text-blue-600 hover:nbw-text-blue-800 nbw-font-semibold nbw-no-underline">Read more →'),Me=(0,a.vs)('<p class="nbw-text-gray-700 nbw-mb-4">');const He=e=>{const t=t=>{const n=new Date(1e3*t);switch(e.config.dateFormat){case"short":default:return n.toLocaleDateString();case"long":return n.toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"});case"relative":const e=Date.now()-n.getTime(),t=Math.floor(e/864e5);return 0===t?"Today":1===t?"Yesterday":t<7?`${t} days ago`:t<30?`${Math.floor(t/7)} weeks ago`:t<365?`${Math.floor(t/30)} months ago`:`${Math.floor(t/365)} years ago`}};return n=Ce(),(0,a.Yr)(n,(0,i.a0)(i.a,{get each(){return e.posts},children:n=>{return"compact"===e.config.layout?(w=(g=Ue()).firstChild,b=w.nextSibling,(0,a.Yr)(w,()=>t(n.published_at||n.created_at)),b.$$click=t=>{t.preventDefault(),e.onNavigate(n.id)},(0,a.Yr)(b,()=>n.title),(0,i.gb)(()=>(0,a.Bq)(b,"href",`#/post/${n.id}`)),g):(p=(f=(d=(h=(u=(c=(l=Ne()).firstChild).firstChild).nextSibling).firstChild).firstChild).nextSibling,l.$$click=()=>e.onNavigate(n.id),(0,a.Yr)(l,(r=(0,a.ph)(()=>!(!e.config.showImages||!n.image)),()=>{return r()&&(e=Oe(),(0,i.gb)(t=>{var r=n.image,s=n.title;return r!==t.e&&(0,a.Bq)(e,"src",t.e=r),s!==t.t&&(0,a.Bq)(e,"alt",t.t=s),t},{e:void 0,t:void 0}),e);var e}),c),(0,a.Yr)(u,()=>n.title),(0,a.Yr)(h,(s=(0,a.ph)(()=>!!n.authorAvatar),()=>{return s()&&(e=ze(),(0,i.gb)(t=>{var r=n.authorAvatar,s=n.authorName;return r!==t.e&&(0,a.Bq)(e,"src",t.e=r),s!==t.t&&(0,a.Bq)(e,"alt",t.t=s),t},{e:void 0,t:void 0}),e);var e}),d),(0,a.Yr)(f,()=>n.authorName),(0,a.Yr)(p,()=>t(n.published_at||n.created_at)),(0,a.Yr)(c,(o=(0,a.ph)(()=>!(1!==n.kind&&"1"!==n.kind)),()=>{return o()?(0,i.a0)(Pe,{get content(){return n.content||""},get onFetchPost(){return e.onFetchPost},useMarkdown:!1}):[(0,a.ph)(()=>{return(0,a.ph)(()=>!(!e.config.showSummary||!n.summary))()&&(t=Me(),(0,a.Yr)(t,()=>n.summary),t);var t}),(t=qe(),t.$$click=t=>{t.stopPropagation(),t.preventDefault(),e.onNavigate(n.id)},(0,i.gb)(()=>(0,a.Bq)(t,"href",`#/post/${n.id}`)),t)];var t}),null),l);var r,s,o,l,c,u,h,d,f,p,g,w,b}})),(0,i.gb)(t=>(0,a.pP)(n,{"nbw-grid-cols-1":"list"===e.config.layout||"compact"===e.config.layout,"nbw-grid-cols-1 md:nbw-grid-cols-2 lg:nbw-grid-cols-3":"grid"===e.config.layout},t)),n;var n};(0,a.z_)(["click"]);var je=(0,a.vs)('<img class="nbw-w-full nbw-h-64 nbw-object-cover">'),De=(0,a.vs)('<img class="nbw-w-12 nbw-h-12 nbw-rounded-full nbw-object-cover">'),Fe=(0,a.vs)('<article class="nbw-bg-white nbw-rounded-lg nbw-shadow-lg nbw-overflow-hidden"><div class=nbw-p-8><button class="nbw-mb-4 nbw-text-blue-600 hover:nbw-text-blue-800 nbw-font-semibold nbw-bg-transparent nbw-border-none nbw-cursor-pointer nbw-p-0">← Back to posts</button><h1 class="nbw-text-4xl nbw-font-bold nbw-mb-4 nbw-text-gray-900"></h1><div class="nbw-flex nbw-items-center nbw-gap-4 nbw-mb-6 nbw-pb-6 nbw-border-b nbw-border-gray-200"><div class=nbw-flex-1><p class="nbw-text-gray-900 nbw-font-semibold"></p><p class="nbw-text-gray-600 nbw-text-sm"></p></div></div><div class="nbw-prose nbw-max-w-none nbw-text-gray-800">');const Ve=e=>{return u=(c=(l=(o=(s=(r=(n=(t=Fe()).firstChild).firstChild).nextSibling).nextSibling).firstChild).firstChild).nextSibling,h=o.nextSibling,(0,a.Yr)(t,(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!e.config.showImages)()&&e.post.image},get children(){var t=je();return(0,i.gb)(n=>{var r=e.post.image,s=e.post.title;return r!==n.e&&(0,a.Bq)(t,"src",n.e=r),s!==n.t&&(0,a.Bq)(t,"alt",n.t=s),n},{e:void 0,t:void 0}),t}}),n),r.$$click=()=>e.onBack(),(0,a.Yr)(s,()=>e.post.title),(0,a.Yr)(o,(0,i.a0)(i.wv,{get when(){return e.post.authorAvatar},get children(){var t=De();return(0,i.gb)(n=>{var r=e.post.authorAvatar,s=e.post.authorName;return r!==n.e&&(0,a.Bq)(t,"src",n.e=r),s!==n.t&&(0,a.Bq)(t,"alt",n.t=s),n},{e:void 0,t:void 0}),t}}),l),(0,a.Yr)(c,()=>e.post.authorName),(0,a.Yr)(u,()=>{return t=e.post.published_at||e.post.created_at,new Date(1e3*t).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"});var t}),(0,a.Yr)(h,(0,i.a0)(Pe,{get content(){return e.post.content||""},get onFetchPost(){return e.onFetchPost},get useMarkdown(){return 30023===e.post.kind||"30023"===e.post.kind}})),t;var t,n,r,s,o,l,c,u,h};(0,a.z_)(["click"]);var We=(0,a.vs)('<div class="nbw-flex nbw-items-center nbw-justify-center nbw-p-8"><div class="nbw-animate-spin nbw-rounded-full nbw-h-12 nbw-w-12 nbw-border-b-2 nbw-border-gray-900">');const Ze=()=>We();var Ke=(0,a.vs)('<div class="nbw-divider nbw-hidden md:nbw-block nbw-h-8 nbw-w-px nbw-bg-gray-300">'),Ye=(0,a.vs)('<div class="nbw-control-group nbw-author-control nbw-flex nbw-flex-col nbw-gap-1"><select class="nbw-author-select nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-gray-300 nbw-rounded-md nbw-bg-white nbw-text-gray-700 hover:nbw-bg-gray-50 nbw-transition-all nbw-cursor-pointer focus:nbw-outline-none focus:nbw-ring-2 focus:nbw-ring-blue-500"><option class=nbw-author-option value>All Authors</option></select><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center">Author'),Ge=(0,a.vs)('<div class="nbw-control-panel nbw-bg-white nbw-border nbw-border-gray-200 nbw-rounded-lg nbw-shadow-sm nbw-mb-6 nbw-p-4"><div class="nbw-control-panel-inner nbw-flex nbw-flex-wrap nbw-items-center nbw-gap-3 md:nbw-gap-4"><div class="nbw-control-group nbw-layout-control nbw-flex nbw-flex-col nbw-gap-1"><div class="nbw-button-group nbw-flex nbw-rounded-md nbw-shadow-sm"><button class="nbw-layout-btn nbw-layout-btn-list nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-rounded-l-md nbw-transition-all"title="List View"><svg class="nbw-icon nbw-w-4 nbw-h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 6h16M4 12h16M4 18h16"></path></svg></button><button class="nbw-layout-btn nbw-layout-btn-grid nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-l-0 nbw-transition-all"title="Grid View"><svg class="nbw-icon nbw-w-4 nbw-h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 5a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM14 5a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 15a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1H5a1 1 0 01-1-1v-4zM14 15a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1v-4z"></path></svg></button><button class="nbw-layout-btn nbw-layout-btn-compact nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-l-0 nbw-rounded-r-md nbw-transition-all"title="Compact View"><svg class="nbw-icon nbw-w-4 nbw-h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 8h16M4 16h16"></path></svg></button></div><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center">View</span></div><div class="nbw-divider nbw-hidden md:nbw-block nbw-h-8 nbw-w-px nbw-bg-gray-300"></div><div class="nbw-control-group nbw-content-type-control nbw-flex nbw-flex-col nbw-gap-1"><div class="nbw-button-group nbw-flex nbw-rounded-md nbw-shadow-sm"><button class="nbw-content-btn nbw-content-btn-all nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-rounded-l-md nbw-transition-all"title="All Content">All</button><button class="nbw-content-btn nbw-content-btn-articles nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-l-0 nbw-transition-all"title="Articles Only">Articles</button><button class="nbw-content-btn nbw-content-btn-notes nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-l-0 nbw-rounded-r-md nbw-transition-all"title="Notes Only">Notes</button></div><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center">Type</span></div><div class="nbw-divider nbw-hidden md:nbw-block nbw-h-8 nbw-w-px nbw-bg-gray-300"></div><div class="nbw-control-group nbw-date-control nbw-flex nbw-flex-col nbw-gap-1"><select class="nbw-date-select nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-gray-300 nbw-rounded-md nbw-bg-white nbw-text-gray-700 hover:nbw-bg-gray-50 nbw-transition-all nbw-cursor-pointer focus:nbw-outline-none focus:nbw-ring-2 focus:nbw-ring-blue-500"><option class=nbw-date-option value=all>All Time</option><option class=nbw-date-option value=week>Last Week</option><option class=nbw-date-option value=month>Last Month</option><option class=nbw-date-option value=year>Last Year</option></select><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center">Period</span></div><div class="nbw-spacer nbw-flex-1 nbw-hidden lg:nbw-block"></div><div class="nbw-control-group nbw-refresh-control nbw-flex nbw-flex-col nbw-gap-1"><button class="nbw-refresh-btn nbw-px-4 nbw-py-1.5 nbw-bg-blue-600 nbw-text-white nbw-text-sm nbw-font-medium nbw-rounded-md hover:nbw-bg-blue-700 nbw-transition-all nbw-shadow-sm hover:nbw-shadow focus:nbw-outline-none focus:nbw-ring-2 focus:nbw-ring-blue-500"title="Refresh Posts"><svg class="nbw-icon nbw-w-4 nbw-h-4 nbw-inline nbw-mr-1.5"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path></svg><span class="nbw-hidden sm:nbw-inline">Refresh</span></button><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center nbw-invisible">Action'),Je=(0,a.vs)("<option class=nbw-author-option>");const Qe=e=>{const t=(0,i.To)(()=>{const t=new Map;return e.posts.forEach(e=>{t.has(e.pubkey)||t.set(e.pubkey,{pubkey:e.pubkey,name:e.authorName||e.pubkey.substring(0,8)+"...",avatar:e.authorAvatar})}),Array.from(t.values())}),n=(0,i.To)(()=>t().length>1),r=(0,i.To)(()=>e.config.selectedAuthor??"");return l=(o=(s=Ge()).firstChild).firstChild,c=l.firstChild.firstChild,u=c.nextSibling,h=u.nextSibling,d=l.nextSibling.nextSibling,f=d.firstChild.firstChild,p=f.nextSibling,g=p.nextSibling,b=(w=d.nextSibling.nextSibling).firstChild,m=(y=w.nextSibling).nextSibling.firstChild,c.$$click=()=>e.onLayoutChange("list"),u.$$click=()=>e.onLayoutChange("grid"),h.$$click=()=>e.onLayoutChange("compact"),f.$$click=()=>e.onContentTypeChange("all"),p.$$click=()=>e.onContentTypeChange("long-form"),g.$$click=()=>e.onContentTypeChange("short-form"),b.addEventListener("change",t=>e.onDateRangeChange(t.currentTarget.value)),(0,a.Yr)(o,(0,i.a0)(i.wv,{get when(){return n()},get children(){return[Ke(),(n=Ye(),s=n.firstChild,o=s.firstChild,s.addEventListener("change",t=>e.onAuthorChange(t.currentTarget.value||void 0)),(0,a.Yr)(s,(0,i.a0)(i.a,{get each(){return t()},children:e=>{return t=Je(),(0,a.Yr)(t,()=>e.name),(0,i.gb)(()=>t.selected=r()===e.pubkey),(0,i.gb)(()=>t.value=e.pubkey),t;var t}}),null),(0,i.gb)(()=>o.selected=""===r()),(0,i.gb)(()=>s.value=r()),n)];var n,s,o}}),y),m.$$click=()=>e.onRefresh(),(0,i.gb)(t=>{var n={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"list"===e.config.layout,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"list"!==e.config.layout},r={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"grid"===e.config.layout,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"grid"!==e.config.layout},s={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"compact"===e.config.layout,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"compact"!==e.config.layout},o={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"all"===e.config.contentType,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"all"!==e.config.contentType},i={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"long-form"===e.config.contentType,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"long-form"!==e.config.contentType},l={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"short-form"===e.config.contentType,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"short-form"!==e.config.contentType};return t.e=(0,a.pP)(c,n,t.e),t.t=(0,a.pP)(u,r,t.t),t.a=(0,a.pP)(h,s,t.a),t.o=(0,a.pP)(f,o,t.o),t.i=(0,a.pP)(p,i,t.i),t.n=(0,a.pP)(g,l,t.n),t},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),s;var s,o,l,c,u,h,d,f,p,g,w,b,y,m};(0,a.z_)(["click"]);var Xe=(0,a.vs)('<div class="nbw-bg-red-100 nbw-border nbw-border-red-400 nbw-text-red-700 nbw-px-4 nbw-py-3 nbw-rounded nbw-mb-4">'),et=(0,a.vs)('<div class="nbw-font-sans nbw-antialiased">'),tt=(0,a.vs)('<svg class="nbw-animate-spin nbw-h-5 nbw-w-5 nbw-inline nbw-mr-2"fill=none viewBox="0 0 24 24"><circle class=nbw-opacity-25 cx=12 cy=12 r=10 stroke=currentColor stroke-width=4></circle><path class=nbw-opacity-75 fill=currentColor d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">'),nt=(0,a.vs)('<div class="nbw-load-more-container nbw-flex nbw-justify-center nbw-mt-8"><button class="nbw-load-more-btn nbw-px-6 nbw-py-3 nbw-bg-blue-600 nbw-text-white nbw-font-medium nbw-rounded-lg hover:nbw-bg-blue-700 nbw-transition-all nbw-shadow-md hover:nbw-shadow-lg disabled:nbw-opacity-50 disabled:nbw-cursor-not-allowed">');const rt=e=>{const[t,n]=(0,i.n5)([]),[r,s]=(0,i.n5)([]),[o,u]=(0,i.n5)(0),[h,d]=(0,i.n5)(null),[f,p]=(0,i.n5)(!0),[g,w]=(0,i.n5)(!1),[b,y]=(0,i.n5)(null),[m,v]=(0,i.n5)(e.config),k=(0,c.createRouter)(),x=new l.NostrService(m().relays),E=async(e=!1)=>{try{e?w(!0):p(!0),y(null);const t=m(),r=3*t.postsPerPage,i=await x.fetchPosts(t.pubkey,r,t.contentType,t.dateRange);s(i);const a=t.selectedAuthor?i.filter(e=>e.pubkey===t.selectedAuthor):i;u(e?Math.min(o()+t.postsPerPage,a.length):Math.min(t.postsPerPage,a.length));const l=a.slice(0,o());n(l),p(!1),w(!1)}catch(e){y("Failed to load posts. Please try again later."),p(!1),w(!1),console.error("Error fetching posts:",e)}},S=()=>{const e=o(),t=r(),s=m(),i=s.selectedAuthor?t.filter(e=>e.pubkey===s.selectedAuthor):t,a=Math.min(e+s.postsPerPage,i.length);u(a),n(i.slice(0,a))};(0,i.EH)(()=>{m(),E()}),(0,i.EH)(async()=>{const e=k.route();if("detail"===e.view&&e.postId){const n=t().find(t=>t.id===e.postId);if(n)d(n);else try{p(!0);const t=await x.fetchPostById(e.postId);d(t),p(!1)}catch(e){y("Failed to load post."),p(!1),console.error("Error fetching post:",e)}}else d(null)}),(0,i.Ki)(()=>{x.close()});const A=e=>{v({...m(),layout:e})},T=e=>{v({...m(),contentType:e})},$=e=>{const t=Math.floor(Date.now()/1e3);let n;switch(e){case"week":n={since:t-604800};break;case"month":n={since:t-2592e3};break;case"year":n={since:t-31536e3};break;default:n=void 0}v({...m(),dateRange:n})},R=e=>{v({...m(),selectedAuthor:e})};return I=et(),(0,a.Yr)(I,(0,i.a0)(i.wv,{get when(){return b()},get children(){var e=Xe();return(0,a.Yr)(e,b),e}}),null),(0,a.Yr)(I,(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!m().showControls)()&&"list"===k.route().view},get children(){return(0,i.a0)(Qe,{get config(){return m()},get posts(){return r()},onLayoutChange:A,onContentTypeChange:T,onDateRangeChange:$,onAuthorChange:R,onRefresh:E})}}),null),(0,a.Yr)(I,(0,i.a0)(i.wv,{get when(){return f()},get children(){return(0,i.a0)(Ze,{})}}),null),(0,a.Yr)(I,(0,i.a0)(i.wv,{get when(){return!f()},get children(){return(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>"detail"===k.route().view)()&&h()},get fallback(){return[(0,i.a0)(He,{get posts(){return t()},get config(){return m()},get onNavigate(){return k.navigateToPost},onFetchPost:e=>x.fetchPostById(e)}),(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!(()=>{const e=m(),t=r(),n=e.selectedAuthor?t.filter(t=>t.pubkey===e.selectedAuthor):t;return o()<n.length})())()&&"load-more"===m().pagination},get children(){var e=nt(),t=e.firstChild;return t.$$click=S,(0,a.Yr)(t,(0,i.a0)(i.wv,{get when(){return g()},fallback:"Load More Posts",get children(){return[tt(),"Loading..."]}})),(0,i.gb)(()=>t.disabled=g()),e}})]},children:e=>(0,i.a0)(Ve,{get post(){return e()},get config(){return m()},get onBack(){return k.navigateToList},onFetchPost:e=>x.fetchPostById(e)})})}}),null),I;var I};function st(){const e=document.querySelector("script[data-pubkey]");if(!e)return void console.error("NostrBlog: Could not find script tag with data-pubkey attribute");const t=e.dataset.pubkey||"";let n,r;try{n=JSON.parse(t)}catch{n=t}(e.dataset.dateSince||e.dataset.dateUntil)&&(r={},e.dataset.dateSince&&(r.since=parseInt(e.dataset.dateSince,10)),e.dataset.dateUntil&&(r.until=parseInt(e.dataset.dateUntil,10)));const o={pubkey:n,relays:JSON.parse(e.dataset.relays||'["wss://relay.damus.io", "wss://nos.lol"]'),navSelector:e.dataset.navSelector||"",contentSelector:e.dataset.contentSelector||"",layout:e.dataset.layout||"list",theme:e.dataset.theme||"light",postsPerPage:parseInt(e.dataset.postsPerPage||"10",10),showImages:"false"!==e.dataset.showImages,dateFormat:e.dataset.dateFormat||"short",contentType:e.dataset.contentType||"all",dateRange:r,showControls:"true"===e.dataset.showControls,pagination:e.dataset.pagination||"load-more",showSummary:"false"!==e.dataset.showSummary};if(!o.pubkey||Array.isArray(o.pubkey)&&0===o.pubkey.length)return void console.error("NostrBlog: pubkey is required");if(!o.contentSelector)return void console.error("NostrBlog: contentSelector is required");const l=document.querySelector(o.contentSelector);if(!l)return void console.error(`NostrBlog: Could not find element with selector "${o.contentSelector}"`);const c=o.navSelector?document.querySelector(o.navSelector):null;(0,a.XX)(()=>(0,i.a0)(rt,{config:o}),l),c&&s.e(485).then(s.bind(s,485)).then(({Navigation:e})=>{Promise.resolve().then(s.bind(s,261)).then(({NostrService:t})=>{Promise.resolve().then(s.bind(s,168)).then(({createRouter:n})=>{const r=new t(o.relays),s=n();r.fetchPosts(o.pubkey).then(t=>{(0,a.XX)(()=>(0,i.a0)(e,{posts:t,get currentPostId(){return s.route().postId},get onNavigate(){return s.navigateToPost},get onHome(){return s.navigateToList}}),c)})})})}),console.log("NostrBlog initialized with config:",o)}(0,a.z_)(["click"]),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",st):st();const ot={init:st};return o.default})());
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.NostrBlog=t():e.NostrBlog=t()}(this,()=>(()=>{"use strict";var e,t,n={35(e,t,n){n.d(t,{Bq:()=>c,XX:()=>i,Yr:()=>h,pP:()=>u,ph:()=>s,vs:()=>a,z_:()=>l});var r=n(701);Object.create(null),Object.create(null);const s=e=>(0,r.To)(()=>e()),o="_$DX_DELEGATE";function i(e,t,n,s={}){let o;return(0,r.Hr)(r=>{o=r,t===document?e():h(t,e(),t.firstChild?null:void 0,n)},s.owner),()=>{o(),t.textContent=""}}function a(e,t,n,s){let o;const i=()=>{const t=s?document.createElementNS("http://www.w3.org/1998/Math/MathML","template"):document.createElement("template");return t.innerHTML=e,n?t.content.firstChild.firstChild:s?t.firstChild:t.content.firstChild},a=t?()=>(0,r.vz)(()=>document.importNode(o||(o=i()),!0)):()=>(o||(o=i())).cloneNode(!0);return a.cloneNode=a,a}function l(e,t=window.document){const n=t[o]||(t[o]=new Set);for(let r=0,s=e.length;r<s;r++){const s=e[r];n.has(s)||(n.add(s),t.addEventListener(s,p))}}function c(e,t,n){d(e)||(null==n?e.removeAttribute(t):e.setAttribute(t,n))}function u(e,t,n={}){const r=Object.keys(t||{}),s=Object.keys(n);let o,i;for(o=0,i=s.length;o<i;o++){const r=s[o];r&&"undefined"!==r&&!t[r]&&(f(e,r,!1),delete n[r])}for(o=0,i=r.length;o<i;o++){const s=r[o],i=!!t[s];s&&"undefined"!==s&&n[s]!==i&&i&&(f(e,s,!0),n[s]=i)}return n}function h(e,t,n,s){if(void 0===n||s||(s=[]),"function"!=typeof t)return g(e,t,s,n);(0,r.gb)(r=>g(e,t(),r,n),s)}function d(e){return!!r.sE.context&&!r.sE.done&&(!e||e.isConnected)}function f(e,t,n){const r=t.trim().split(/\s+/);for(let t=0,s=r.length;t<s;t++)e.classList.toggle(r[t],n)}function p(e){if(r.sE.registry&&r.sE.events&&r.sE.events.find(([t,n])=>n===e))return;let t=e.target;const n=`$$${e.type}`,s=e.target,o=e.currentTarget,i=t=>Object.defineProperty(e,"target",{configurable:!0,value:t}),a=()=>{const r=t[n];if(r&&!t.disabled){const s=t[`${n}Data`];if(void 0!==s?r.call(t,s,e):r.call(t,e),e.cancelBubble)return}return t.host&&"string"!=typeof t.host&&!t.host._$host&&t.contains(e.target)&&i(t.host),!0},l=()=>{for(;a()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get:()=>t||document}),r.sE.registry&&!r.sE.done&&(r.sE.done=_$HY.done=!0),e.composedPath){const n=e.composedPath();i(n[0]);for(let e=0;e<n.length-2&&(t=n[e],a());e++){if(t._$host){t=t._$host,l();break}if(t.parentNode===o)break}}else l();i(s)}function g(e,t,n,s,o){const i=d(e);if(i){!n&&(n=[...e.childNodes]);let t=[];for(let e=0;e<n.length;e++){const r=n[e];8===r.nodeType&&"!$"===r.data.slice(0,2)?r.remove():t.push(r)}n=t}for(;"function"==typeof n;)n=n();if(t===n)return n;const a=typeof t,l=void 0!==s;if(e=l&&n[0]&&n[0].parentNode||e,"string"===a||"number"===a){if(i)return n;if("number"===a&&(t=t.toString())===n)return n;if(l){let r=n[0];r&&3===r.nodeType?r.data!==t&&(r.data=t):r=document.createTextNode(t),n=y(e,n,s,r)}else n=""!==n&&"string"==typeof n?e.firstChild.data=t:e.textContent=t}else if(null==t||"boolean"===a){if(i)return n;n=y(e,n,s)}else{if("function"===a)return(0,r.gb)(()=>{let r=t();for(;"function"==typeof r;)r=r();n=g(e,r,n,s)}),()=>n;if(Array.isArray(t)){const a=[],c=n&&Array.isArray(n);if(w(a,t,n,o))return(0,r.gb)(()=>n=g(e,a,n,s,!0)),()=>n;if(i){if(!a.length)return n;if(void 0===s)return n=[...e.childNodes];let t=a[0];if(t.parentNode!==e)return n;const r=[t];for(;(t=t.nextSibling)!==s;)r.push(t);return n=r}if(0===a.length){if(n=y(e,n,s),l)return n}else c?0===n.length?b(e,a,s):function(e,t,n){let r=n.length,s=t.length,o=r,i=0,a=0,l=t[s-1].nextSibling,c=null;for(;i<s||a<o;)if(t[i]!==n[a]){for(;t[s-1]===n[o-1];)s--,o--;if(s===i){const t=o<r?a?n[a-1].nextSibling:n[o-a]:l;for(;a<o;)e.insertBefore(n[a++],t)}else if(o===a)for(;i<s;)c&&c.has(t[i])||t[i].remove(),i++;else if(t[i]===n[o-1]&&n[a]===t[s-1]){const r=t[--s].nextSibling;e.insertBefore(n[a++],t[i++].nextSibling),e.insertBefore(n[--o],r),t[s]=n[o]}else{if(!c){c=new Map;let e=a;for(;e<o;)c.set(n[e],e++)}const r=c.get(t[i]);if(null!=r)if(a<r&&r<o){let l,u=i,h=1;for(;++u<s&&u<o&&null!=(l=c.get(t[u]))&&l===r+h;)h++;if(h>r-a){const s=t[i];for(;a<r;)e.insertBefore(n[a++],s)}else e.replaceChild(n[a++],t[i++])}else i++;else t[i++].remove()}}else i++,a++}(e,n,a):(n&&y(e),b(e,a));n=a}else if(t.nodeType){if(i&&t.parentNode)return n=l?[t]:t;if(Array.isArray(n)){if(l)return n=y(e,n,s,t);y(e,n,null,t)}else null!=n&&""!==n&&e.firstChild?e.replaceChild(t,e.firstChild):e.appendChild(t);n=t}}return n}function w(e,t,n,r){let s=!1;for(let o=0,i=t.length;o<i;o++){let i,a=t[o],l=n&&n[e.length];if(null==a||!0===a||!1===a);else if("object"==(i=typeof a)&&a.nodeType)e.push(a);else if(Array.isArray(a))s=w(e,a,l)||s;else if("function"===i)if(r){for(;"function"==typeof a;)a=a();s=w(e,Array.isArray(a)?a:[a],Array.isArray(l)?l:[l])||s}else e.push(a),s=!0;else{const t=String(a);l&&3===l.nodeType&&l.data===t?e.push(l):e.push(document.createTextNode(t))}}return s}function b(e,t,n=null){for(let r=0,s=t.length;r<s;r++)e.insertBefore(t[r],n)}function y(e,t,n,r){if(void 0===n)return e.textContent="";const s=r||document.createTextNode("");if(t.length){let r=!1;for(let o=t.length-1;o>=0;o--){const i=t[o];if(s!==i){const t=i.parentNode===e;r||o?t&&i.remove():t?e.replaceChild(s,i):e.insertBefore(s,n)}else r=!0}}else e.insertBefore(s,n);return[s]}Symbol()},168(e,t,n){n.d(t,{createRouter:()=>s});var r=n(701);function s(){const[e,t]=(0,r.n5)(n());function n(){const e=window.location.hash.slice(1);if(!e||"/"===e)return{view:"list"};const t=e.match(/^\/post\/(.+)$/);return t?{view:"detail",postId:t[1]}:{view:"list"}}function s(){t(n())}return window.addEventListener("hashchange",s),(0,r.Ki)(()=>window.removeEventListener("hashchange",s)),{route:e,navigateToPost:function(e){window.location.hash=`/post/${e}`},navigateToList:function(){window.location.hash="/"}}}},261(e,t,n){n.d(t,{NostrService:()=>Ba});var r={};function s(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function o(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function i(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}n.r(r),n.d(r,{OG:()=>N,My:()=>$,Ph:()=>B,lX:()=>L,Id:()=>U,fg:()=>q,qj:()=>C,aT:()=>I,lq:()=>_,z:()=>P,Q5:()=>H});const a="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,l=e=>e instanceof Uint8Array,c=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),u=(e,t)=>e<<32-t|e>>>t;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");function h(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!l(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class d{clone(){return this._cloneInto()}}function f(e){const t=t=>e().update(h(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function p(e=32){if(a&&"function"==typeof a.getRandomValues)return a.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}class g extends d{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=c(this.buffer)}update(e){i(this);const{view:t,buffer:n,blockLen:r}=this,s=(e=h(e)).length;for(let o=0;o<s;){const i=Math.min(r-this.pos,s-o);if(i===r){const t=c(e);for(;r<=s-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){i(this),function(e,t){o(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:s}=this;let{pos:a}=this;t[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),l=r?4:0,c=r?0:4;e.setUint32(t+l,i,r),e.setUint32(t+c,a,r)}(n,r-8,BigInt(8*this.length),s),this.process(n,0);const l=c(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const h=u/4,d=this.get();if(h>d.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<h;e++)l.setUint32(4*e,d[e],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:s,destroyed:o,pos:i}=this;return e.length=r,e.pos=i,e.finished=s,e.destroyed=o,r%t&&e.buffer.set(n),e}}const w=(e,t,n)=>e&t^~e&n,b=(e,t,n)=>e&t^e&n^t&n,y=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]),m=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),v=new Uint32Array(64);class k extends g{constructor(){super(64,32,8,!1),this.A=0|m[0],this.B=0|m[1],this.C=0|m[2],this.D=0|m[3],this.E=0|m[4],this.F=0|m[5],this.G=0|m[6],this.H=0|m[7]}get(){const{A:e,B:t,C:n,D:r,E:s,F:o,G:i,H:a}=this;return[e,t,n,r,s,o,i,a]}set(e,t,n,r,s,o,i,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|s,this.F=0|o,this.G=0|i,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)v[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=v[e-15],n=v[e-2],r=u(t,7)^u(t,18)^t>>>3,s=u(n,17)^u(n,19)^n>>>10;v[e]=s+v[e-7]+r+v[e-16]|0}let{A:n,B:r,C:s,D:o,E:i,F:a,G:l,H:c}=this;for(let e=0;e<64;e++){const t=c+(u(i,6)^u(i,11)^u(i,25))+w(i,a,l)+y[e]+v[e]|0,h=(u(n,2)^u(n,13)^u(n,22))+b(n,r,s)|0;c=l,l=a,a=i,i=o+t|0,o=s,s=r,r=n,n=t+h|0}n=n+this.A|0,r=r+this.B|0,s=s+this.C|0,o=o+this.D|0,i=i+this.E|0,a=a+this.F|0,l=l+this.G|0,c=c+this.H|0,this.set(n,r,s,o,i,a,l,c)}roundClean(){v.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const x=f(()=>new k),E=(BigInt(0),BigInt(1)),S=BigInt(2),A=e=>e instanceof Uint8Array,T=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $(e){if(!A(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=T[e[n]];return t}function R(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function I(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let t=0;t<n.length;t++){const r=2*t,s=e.slice(r,r+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[t]=o}return n}function B(e){return R($(e))}function L(e){if(!A(e))throw new Error("Uint8Array expected");return R($(Uint8Array.from(e).reverse()))}function _(e,t){return I(e.toString(16).padStart(2*t,"0"))}function P(e,t){return _(e,t).reverse()}function C(e,t,n){let r;if("string"==typeof t)try{r=I(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!A(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const s=r.length;if("number"==typeof n&&s!==n)throw new Error(`${e} expected ${n} bytes, got ${s}`);return r}function U(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!A(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const N=e=>(S<<BigInt(e-1))-E,O=e=>new Uint8Array(e),z=e=>Uint8Array.from(e);function q(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=O(e),s=O(e),o=0;const i=()=>{r.fill(1),s.fill(0),o=0},a=(...e)=>n(s,r,...e),l=(e=O())=>{s=a(z([0]),e),r=a(),0!==e.length&&(s=a(z([1]),e),r=a())},c=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=a();const t=r.slice();n.push(t),e+=r.length}return U(...n)};return(e,t)=>{let n;for(i(),l(e);!(n=t(c()));)l();return i(),n}}const M={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function H(e,t,n={}){const r=(t,n,r)=>{const s=M[n];if("function"!=typeof s)throw new Error(`Invalid validator "${n}", expected function`);const o=e[t];if(!(r&&void 0===o||s(o,e)))throw new Error(`Invalid param ${String(t)}=${o} (${typeof o}), expected ${n}`)};for(const[e,n]of Object.entries(t))r(e,n,!1);for(const[e,t]of Object.entries(n))r(e,t,!0);return e}const j=BigInt(0),D=BigInt(1),F=BigInt(2),V=BigInt(3),W=BigInt(4),Z=BigInt(5),K=BigInt(8);function Y(e,t){const n=e%t;return n>=j?n:t+n}function G(e,t,n){if(n<=j||t<j)throw new Error("Expected power/modulo > 0");if(n===D)return j;let r=D;for(;t>j;)t&D&&(r=r*e%n),e=e*e%n,t>>=D;return r}function J(e,t,n){let r=e;for(;t-- >j;)r*=r,r%=n;return r}function Q(e,t){if(e===j||t<=j)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Y(e,t),r=t,s=j,o=D,i=D,a=j;for(;n!==j;){const e=r/n,t=r%n,l=s-i*e,c=o-a*e;r=n,n=t,s=i,o=a,i=l,a=c}if(r!==D)throw new Error("invert: does not exist");return Y(s,t)}BigInt(9),BigInt(16);const X=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ee(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function te(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function ne(e){const t=te(e);return t+Math.ceil(t/2)}class re extends d{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");s(e.outputLen),s(e.blockLen)}(e);const n=h(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),o.fill(0)}update(e){return i(this),this.iHash.update(e),this}digestInto(e){i(this),o(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:s,blockLen:o,outputLen:i}=this;return e.finished=r,e.destroyed=s,e.blockLen=o,e.outputLen=i,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const se=(e,t,n)=>new re(e,t).update(n).digest();se.create=(e,t)=>new re(e,t);const oe=BigInt(0),ie=BigInt(1);function ae(e){return H(e.Fp,X.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),H(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ee(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}const{Ph:le,aT:ce}=r,ue={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=ue;if(e.length<2||2!==e[0])throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:le(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=ue,n="string"==typeof e?ce(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:s,l:o}=ue._parseInt(n.subarray(2)),{d:i,l:a}=ue._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(e){const t=e=>8&Number.parseInt(e[0],16)?"00"+e:e,n=e=>{const t=e.toString(16);return 1&t.length?`0${t}`:t},r=t(n(e.s)),s=t(n(e.r)),o=r.length/2,i=s.length/2,a=n(o),l=n(i);return`30${n(i+o+4)}02${l}${s}02${a}${r}`}},he=BigInt(0),de=BigInt(1),fe=(BigInt(2),BigInt(3));function pe(e){const t=function(e){const t=ae(e);return H(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:n,n:r}=t,s=n.BYTES+1,o=2*n.BYTES+1;function i(e){return Y(e,r)}function a(e){return Q(e,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:u,isWithinCurveOrder:h}=function(e){const t=function(e){const t=ae(e);H(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:s}=t;if(n){if(!r.eql(s,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:n}=t,r=t.toBytes||((e,t,r)=>{const s=t.toAffine();return U(Uint8Array.from([4]),n.toBytes(s.x),n.toBytes(s.y))}),s=t.fromBytes||(e=>{const t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function o(e){const{a:r,b:s}=t,o=n.sqr(e),i=n.mul(o,e);return n.add(n.add(i,n.mul(e,r)),s)}if(!n.eql(n.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(e){return"bigint"==typeof e&&he<e&&e<t.n}function a(e){if(!i(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function l(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:s,n:o}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=$(e)),"string"!=typeof e||!n.includes(e.length))throw new Error("Invalid key");e=e.padStart(2*r,"0")}let i;try{i="bigint"==typeof e?e:B(C("private key",e,r))}catch(t){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return s&&(i=Y(i,o)),a(i),i}const c=new Map;function u(e){if(!(e instanceof h))throw new Error("ProjectivePoint expected")}class h{constructor(e,t,r){if(this.px=e,this.py=t,this.pz=r,null==e||!n.isValid(e))throw new Error("x required");if(null==t||!n.isValid(t))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof h)throw new Error("projective point not allowed");const s=e=>n.eql(e,n.ZERO);return s(t)&&s(r)?h.ZERO:new h(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(h.fromAffine)}static fromHex(e){const t=h.fromAffine(s(C("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return h.BASE.multiply(l(e))}_setWindowSize(e){this._WINDOW_SIZE=e,c.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:e,y:r}=this.toAffine();if(!n.isValid(e)||!n.isValid(r))throw new Error("bad point: x or y not FE");const s=n.sqr(r),i=o(e);if(!n.eql(s,i))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){u(e);const{px:t,py:r,pz:s}=this,{px:o,py:i,pz:a}=e,l=n.eql(n.mul(t,a),n.mul(o,s)),c=n.eql(n.mul(r,a),n.mul(i,s));return l&&c}negate(){return new h(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,s=n.mul(r,fe),{px:o,py:i,pz:a}=this;let l=n.ZERO,c=n.ZERO,u=n.ZERO,d=n.mul(o,o),f=n.mul(i,i),p=n.mul(a,a),g=n.mul(o,i);return g=n.add(g,g),u=n.mul(o,a),u=n.add(u,u),l=n.mul(e,u),c=n.mul(s,p),c=n.add(l,c),l=n.sub(f,c),c=n.add(f,c),c=n.mul(l,c),l=n.mul(g,l),u=n.mul(s,u),p=n.mul(e,p),g=n.sub(d,p),g=n.mul(e,g),g=n.add(g,u),u=n.add(d,d),d=n.add(u,d),d=n.add(d,p),d=n.mul(d,g),c=n.add(c,d),p=n.mul(i,a),p=n.add(p,p),d=n.mul(p,g),l=n.sub(l,d),u=n.mul(p,f),u=n.add(u,u),u=n.add(u,u),new h(l,c,u)}add(e){u(e);const{px:r,py:s,pz:o}=this,{px:i,py:a,pz:l}=e;let c=n.ZERO,d=n.ZERO,f=n.ZERO;const p=t.a,g=n.mul(t.b,fe);let w=n.mul(r,i),b=n.mul(s,a),y=n.mul(o,l),m=n.add(r,s),v=n.add(i,a);m=n.mul(m,v),v=n.add(w,b),m=n.sub(m,v),v=n.add(r,o);let k=n.add(i,l);return v=n.mul(v,k),k=n.add(w,y),v=n.sub(v,k),k=n.add(s,o),c=n.add(a,l),k=n.mul(k,c),c=n.add(b,y),k=n.sub(k,c),f=n.mul(p,v),c=n.mul(g,y),f=n.add(c,f),c=n.sub(b,f),f=n.add(b,f),d=n.mul(c,f),b=n.add(w,w),b=n.add(b,w),y=n.mul(p,y),v=n.mul(g,v),b=n.add(b,y),y=n.sub(w,y),y=n.mul(p,y),v=n.add(v,y),w=n.mul(b,v),d=n.add(d,w),w=n.mul(k,v),c=n.mul(m,c),c=n.sub(c,w),w=n.mul(m,b),f=n.mul(k,f),f=n.add(f,w),new h(c,d,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(h.ZERO)}wNAF(e){return f.wNAFCached(this,c,e,e=>{const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(h.fromAffine)})}multiplyUnsafe(e){const r=h.ZERO;if(e===he)return r;if(a(e),e===de)return this;const{endo:s}=t;if(!s)return f.unsafeLadder(this,e);let{k1neg:o,k1:i,k2neg:l,k2:c}=s.splitScalar(e),u=r,d=r,p=this;for(;i>he||c>he;)i&de&&(u=u.add(p)),c&de&&(d=d.add(p)),p=p.double(),i>>=de,c>>=de;return o&&(u=u.negate()),l&&(d=d.negate()),d=new h(n.mul(d.px,s.beta),d.py,d.pz),u.add(d)}multiply(e){a(e);let r,s,o=e;const{endo:i}=t;if(i){const{k1neg:e,k1:t,k2neg:a,k2:l}=i.splitScalar(o);let{p:c,f:u}=this.wNAF(t),{p:d,f:p}=this.wNAF(l);c=f.constTimeNegate(e,c),d=f.constTimeNegate(a,d),d=new h(n.mul(d.px,i.beta),d.py,d.pz),r=c.add(d),s=u.add(p)}else{const{p:e,f:t}=this.wNAF(o);r=e,s=t}return h.normalizeZ([r,s])[0]}multiplyAndAddUnsafe(e,t,n){const r=h.BASE,s=(e,t)=>t!==he&&t!==de&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),o=s(this,t).add(s(e,n));return o.is0()?void 0:o}toAffine(e){const{px:t,py:r,pz:s}=this,o=this.is0();null==e&&(e=o?n.ONE:n.inv(s));const i=n.mul(t,e),a=n.mul(r,e),l=n.mul(s,e);if(o)return{x:n.ZERO,y:n.ZERO};if(!n.eql(l,n.ONE))throw new Error("invZ was invalid");return{x:i,y:a}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===de)return!0;if(n)return n(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:n}=t;return e===de?this:n?n(h,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(h,this,e)}toHex(e=!0){return $(this.toRawBytes(e))}}h.BASE=new h(t.Gx,t.Gy,n.ONE),h.ZERO=new h(n.ZERO,n.ONE,n.ZERO);const d=t.nBitLength,f=function(e,t){const n=(e,t)=>{const n=t.negate();return e?n:t},r=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:n,unsafeLadder(t,n){let r=e.ZERO,s=t;for(;n>oe;)n&ie&&(r=r.add(s)),s=s.double(),n>>=ie;return r},precomputeWindow(e,t){const{windows:n,windowSize:s}=r(t),o=[];let i=e,a=i;for(let e=0;e<n;e++){a=i,o.push(a);for(let e=1;e<s;e++)a=a.add(i),o.push(a);i=a.double()}return o},wNAF(t,s,o){const{windows:i,windowSize:a}=r(t);let l=e.ZERO,c=e.BASE;const u=BigInt(2**t-1),h=2**t,d=BigInt(t);for(let e=0;e<i;e++){const t=e*a;let r=Number(o&u);o>>=d,r>a&&(r-=h,o+=ie);const i=t,f=t+Math.abs(r)-1,p=e%2!=0,g=r<0;0===r?c=c.add(n(p,s[i])):l=l.add(n(g,s[f]))}return{p:l,f:c}},wNAFCached(e,t,n,r){const s=e._WINDOW_SIZE||1;let o=t.get(e);return o||(o=this.precomputeWindow(e,s),1!==s&&t.set(e,r(o))),this.wNAF(s,o,n)}}}(h,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:l,weierstrassEquation:o,isWithinCurveOrder:i}}({...t,toBytes(e,t,r){const s=t.toAffine(),o=n.toBytes(s.x),i=U;return r?i(Uint8Array.from([t.hasEvenY()?2:3]),o):i(Uint8Array.from([4]),o,n.toBytes(s.y))},fromBytes(e){const t=e.length,r=e[0],i=e.subarray(1);if(t!==s||2!==r&&3!==r){if(t===o&&4===r)return{x:n.fromBytes(i.subarray(0,n.BYTES)),y:n.fromBytes(i.subarray(n.BYTES,2*n.BYTES))};throw new Error(`Point of length ${t} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}{const e=B(i);if(!(he<(a=e)&&a<n.ORDER))throw new Error("Point is not on curve");const t=u(e);let s=n.sqrt(t);return!(1&~r)!=((s&de)===de)&&(s=n.neg(s)),{x:e,y:s}}var a}}),d=e=>$(_(e,t.nByteLength));function f(e){return e>r>>de}const p=(e,t,n)=>B(e.slice(t,n));class g{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=C("compactSignature",e,2*n),new g(p(e,0,n),p(e,n,2*n))}static fromDER(e){const{r:t,s:n}=ue.toSig(C("DER",e));return new g(t,n)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(e){return new g(this.r,this.s,e)}recoverPublicKey(e){const{r,s,recovery:o}=this,c=m(C("msgHash",e));if(null==o||![0,1,2,3].includes(o))throw new Error("recovery id invalid");const u=2===o||3===o?r+t.n:r;if(u>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const h=1&o?"03":"02",f=l.fromHex(h+d(u)),p=a(u),g=i(-c*p),w=i(s*p),b=l.BASE.multiplyAndAddUnsafe(f,g,w);if(!b)throw new Error("point at infinify");return b.assertValidity(),b}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return I(this.toDERHex())}toDERHex(){return ue.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return I(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}const w={isValidPrivateKey(e){try{return c(e),!0}catch(e){return!1}},normPrivateKeyToScalar:c,randomPrivateKey:()=>{const e=ne(t.n);return function(e,t,n=!1){const r=e.length,s=te(t),o=ne(t);if(r<16||r<o||r>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${r}`);const i=Y(n?B(e):L(e),t-D)+D;return n?P(i,s):_(i,s)}(t.randomBytes(e),t.n)},precompute:(e=8,t=l.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function b(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===s||r===o:n?r===2*s||r===2*o:e instanceof l}const y=t.bits2int||function(e){const n=B(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},m=t.bits2int_modN||function(e){return i(y(e))},v=N(t.nBitLength);function k(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(he<=e&&e<v))throw new Error(`bigint expected < 2^${t.nBitLength}`);return _(e,t.nByteLength)}const x={lowS:t.lowS,prehash:!1},E={lowS:t.lowS,prehash:!1};return l.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return l.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(b(e))throw new Error("first arg must be private key");if(!b(t))throw new Error("second arg must be public key");return l.fromHex(t).multiply(c(e)).toRawBytes(n)},sign:function(e,r,s=x){const{seed:o,k2sig:u}=function(e,r,s=x){if(["recovered","canonical"].some(e=>e in s))throw new Error("sign() legacy options not supported");const{hash:o,randomBytes:u}=t;let{lowS:d,prehash:p,extraEntropy:w}=s;null==d&&(d=!0),e=C("msgHash",e),p&&(e=C("prehashed msgHash",o(e)));const b=m(e),v=c(r),E=[k(v),k(b)];if(null!=w){const e=!0===w?u(n.BYTES):w;E.push(C("extraEntropy",e))}const S=U(...E),A=b;return{seed:S,k2sig:function(e){const t=y(e);if(!h(t))return;const n=a(t),r=l.BASE.multiply(t).toAffine(),s=i(r.x);if(s===he)return;const o=i(n*i(A+s*v));if(o===he)return;let c=(r.x===s?0:2)|Number(r.y&de),u=o;return d&&f(o)&&(u=function(e){return f(e)?i(-e):e}(o),c^=1),new g(s,u,c)}}}(e,r,s),d=t;return q(d.hash.outputLen,d.nByteLength,d.hmac)(o,u)},verify:function(e,n,r,s=E){const o=e;if(n=C("msgHash",n),r=C("publicKey",r),"strict"in s)throw new Error("options.strict was renamed to lowS");const{lowS:c,prehash:u}=s;let h,d;try{if("string"==typeof o||o instanceof Uint8Array)try{h=g.fromDER(o)}catch(e){if(!(e instanceof ue.Err))throw e;h=g.fromCompact(o)}else{if("object"!=typeof o||"bigint"!=typeof o.r||"bigint"!=typeof o.s)throw new Error("PARSE");{const{r:e,s:t}=o;h=new g(e,t)}}d=l.fromHex(r)}catch(e){if("PARSE"===e.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(c&&h.hasHighS())return!1;u&&(n=t.hash(n));const{r:f,s:p}=h,w=m(n),b=a(p),y=i(w*b),v=i(f*b),k=l.BASE.multiplyAndAddUnsafe(d,y,v)?.toAffine();return!!k&&i(k.x)===f},ProjectivePoint:l,Signature:g,utils:w}}function ge(e){return{hash:e,hmac:(t,...n)=>se(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!l(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:p}}BigInt(4);const we=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),be=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ye=BigInt(1),me=BigInt(2),ve=(e,t)=>(e+t/me)/t;function ke(e){const t=we,n=BigInt(3),r=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),l=BigInt(88),c=e*e*e%t,u=c*c*e%t,h=J(u,n,t)*u%t,d=J(h,n,t)*u%t,f=J(d,me,t)*c%t,p=J(f,s,t)*f%t,g=J(p,o,t)*p%t,w=J(g,a,t)*g%t,b=J(w,l,t)*w%t,y=J(b,a,t)*g%t,m=J(y,n,t)*u%t,v=J(m,i,t)*p%t,k=J(v,r,t)*c%t,x=J(k,me,t);if(!xe.eql(xe.sqr(x),e))throw new Error("Cannot find square root");return x}const xe=function(e,t,n=!1,r={}){if(e<=j)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:o}=ee(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=function(e){if(e%W===V){const t=(e+D)/W;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%K===Z){const t=(e-Z)/K;return function(e,n){const r=e.mul(n,F),s=e.pow(r,t),o=e.mul(n,s),i=e.mul(e.mul(o,F),s),a=e.mul(o,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-D)/F;let n,r,s;for(n=e-D,r=0;n%F===j;n/=F,r++);for(s=F;s<e&&G(s,t,e)!==e-D;s++);if(1===r){const t=(e+D)/W;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const o=(n+D)/F;return function(e,i){if(e.pow(i,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,l=e.pow(e.mul(e.ONE,s),n),c=e.pow(i,o),u=e.pow(i,n);for(;!e.eql(u,e.ONE);){if(e.eql(u,e.ZERO))return e.ZERO;let t=1;for(let n=e.sqr(u);t<a&&!e.eql(n,e.ONE);t++)n=e.sqr(n);const n=e.pow(l,D<<BigInt(a-t-1));l=e.sqr(n),c=e.mul(c,n),u=e.mul(u,l),a=t}return c}}(e)}(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:o,MASK:N(s),ZERO:j,ONE:D,create:t=>Y(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return j<=t&&t<e},is0:e=>e===j,isOdd:e=>(e&D)===D,neg:t=>Y(-t,e),eql:(e,t)=>e===t,sqr:t=>Y(t*t,e),add:(t,n)=>Y(t+n,e),sub:(t,n)=>Y(t-n,e),mul:(t,n)=>Y(t*n,e),pow:(e,t)=>function(e,t,n){if(n<j)throw new Error("Expected power > 0");if(n===j)return e.ONE;if(n===D)return t;let r=e.ONE,s=t;for(;n>j;)n&D&&(r=e.mul(r,s)),s=e.sqr(s),n>>=D;return r}(a,e,t),div:(t,n)=>Y(t*Q(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Q(t,e),sqrt:r.sqrt||(e=>i(a,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce((t,r,s)=>e.is0(r)?t:(n[s]=t,e.mul(t,r)),e.ONE),s=e.inv(r);return t.reduceRight((t,r,s)=>e.is0(r)?t:(n[s]=e.mul(t,n[s]),e.mul(t,r)),s),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?P(e,o):_(e,o),fromBytes:e=>{if(e.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${e.length}`);return n?L(e):B(e)}});return Object.freeze(a)}(we,void 0,void 0,{sqrt:ke}),Ee=function(e,t){const n=t=>pe({...e,...ge(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:xe,n:be,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=be,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-ye*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,i=BigInt("0x100000000000000000000000000000000"),a=ve(o*e,t),l=ve(-r*e,t);let c=Y(e-a*n-l*s,t),u=Y(-a*r-l*o,t);const h=c>i,d=u>i;if(h&&(c=t-c),d&&(u=t-u),c>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:h,k1:c,k2neg:d,k2:u}}}},x),Se=BigInt(0),Ae=e=>"bigint"==typeof e&&Se<e&&e<we,Te={};function $e(e,...t){let n=Te[e];if(void 0===n){const t=x(Uint8Array.from(e,e=>e.charCodeAt(0)));n=U(t,t),Te[e]=n}return x(U(n,...t))}const Re=e=>e.toRawBytes(!0).slice(1),Ie=e=>_(e,32),Be=e=>Y(e,we),Le=e=>Y(e,be),_e=Ee.ProjectivePoint;function Pe(e){let t=Ee.utils.normPrivateKeyToScalar(e),n=_e.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Le(-t),bytes:Re(n)}}function Ce(e){if(!Ae(e))throw new Error("bad x: need 0 < x < p");const t=Be(e*e);let n=ke(Be(t*e+BigInt(7)));n%me!==Se&&(n=Be(-n));const r=new _e(e,n,ye);return r.assertValidity(),r}function Ue(...e){return Le(B($e("BIP0340/challenge",...e)))}function Ne(e){return Pe(e).bytes}function Oe(e,t,n=p(32)){const r=C("message",e),{bytes:s,scalar:o}=Pe(t),i=C("auxRand",n,32),a=Ie(o^B($e("BIP0340/aux",i))),l=$e("BIP0340/nonce",a,s,r),c=Le(B(l));if(c===Se)throw new Error("sign failed: k is zero");const{bytes:u,scalar:h}=Pe(c),d=Ue(u,s,r),f=new Uint8Array(64);if(f.set(u,0),f.set(Ie(Le(h+d*o)),32),!ze(f,r,s))throw new Error("sign: Invalid signature produced");return f}function ze(e,t,n){const r=C("signature",e,64),s=C("message",t),o=C("publicKey",n,32);try{const e=Ce(B(o)),t=B(r.subarray(0,32));if(!Ae(t))return!1;const n=B(r.subarray(32,64));if(!(e=>"bigint"==typeof e&&Se<e&&e<be)(n))return!1;const i=Ue(Ie(t),Re(e),s),a=((e,t,n)=>_e.BASE.multiplyAndAddUnsafe(e,t,n))(e,n,Le(-i));return!(!a||!a.hasEvenY()||a.toAffine().x!==t)}catch(e){return!1}}const qe=(()=>({getPublicKey:Ne,sign:Oe,verify:ze,utils:{randomPrivateKey:Ee.utils.randomPrivateKey,lift_x:Ce,pointToBytes:Re,numberToBytesBE:_,bytesToNumberBE:B,taggedHash:$e,mod:Y}}))(),Me="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,He=e=>e instanceof Uint8Array,je=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),De=(e,t)=>e<<32-t|e>>>t;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const Fe=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ve(e){if(!He(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Fe[e[n]];return t}function We(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let t=0;t<n.length;t++){const r=2*t,s=e.slice(r,r+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[t]=o}return n}function Ze(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!He(e))throw new Error("expected Uint8Array, got "+typeof e);return e}function Ke(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!He(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}class Ye{clone(){return this._cloneInto()}}function Ge(e){const t=t=>e().update(Ze(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Je(e=32){if(Me&&"function"==typeof Me.getRandomValues)return Me.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Qe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Xe(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}const et={number:Qe,bool:function(e){if("boolean"!=typeof e)throw new Error(`Expected boolean, not ${e}`)},bytes:Xe,hash:function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Qe(e.outputLen),Qe(e.blockLen)},exists:function(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")},output:function(e,t){Xe(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}},tt=et;class nt extends Ye{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=je(this.buffer)}update(e){tt.exists(this);const{view:t,buffer:n,blockLen:r}=this,s=(e=Ze(e)).length;for(let o=0;o<s;){const i=Math.min(r-this.pos,s-o);if(i===r){const t=je(e);for(;r<=s-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){tt.exists(this),tt.output(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:s}=this;let{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>r-o&&(this.process(n,0),o=0);for(let e=o;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),l=r?4:0,c=r?0:4;e.setUint32(t+l,i,r),e.setUint32(t+c,a,r)}(n,r-8,BigInt(8*this.length),s),this.process(n,0);const i=je(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,c=this.get();if(l>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)i.setUint32(4*e,c[e],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:s,destroyed:o,pos:i}=this;return e.length=r,e.pos=i,e.finished=s,e.destroyed=o,r%t&&e.buffer.set(n),e}}const rt=(e,t,n)=>e&t^~e&n,st=(e,t,n)=>e&t^e&n^t&n,ot=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]),it=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),at=new Uint32Array(64);class lt extends nt{constructor(){super(64,32,8,!1),this.A=0|it[0],this.B=0|it[1],this.C=0|it[2],this.D=0|it[3],this.E=0|it[4],this.F=0|it[5],this.G=0|it[6],this.H=0|it[7]}get(){const{A:e,B:t,C:n,D:r,E:s,F:o,G:i,H:a}=this;return[e,t,n,r,s,o,i,a]}set(e,t,n,r,s,o,i,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|s,this.F=0|o,this.G=0|i,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)at[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=at[e-15],n=at[e-2],r=De(t,7)^De(t,18)^t>>>3,s=De(n,17)^De(n,19)^n>>>10;at[e]=s+at[e-7]+r+at[e-16]|0}let{A:n,B:r,C:s,D:o,E:i,F:a,G:l,H:c}=this;for(let e=0;e<64;e++){const t=c+(De(i,6)^De(i,11)^De(i,25))+rt(i,a,l)+ot[e]+at[e]|0,u=(De(n,2)^De(n,13)^De(n,22))+st(n,r,s)|0;c=l,l=a,a=i,i=o+t|0,o=s,s=r,r=n,n=t+u|0}n=n+this.A|0,r=r+this.B|0,s=s+this.C|0,o=o+this.D|0,i=i+this.E|0,a=a+this.F|0,l=l+this.G|0,c=c+this.H|0,this.set(n,r,s,o,i,a,l,c)}roundClean(){at.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class ct extends lt{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 ut=Ge(()=>new lt);function ht(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function dt(...e){const t=(e,t)=>n=>e(t(n)),n=Array.from(e).reverse().reduce((e,n)=>e?t(e,n.encode):n.encode,void 0),r=e.reduce((e,n)=>e?t(e,n.decode):n.decode,void 0);return{encode:n,decode:r}}function ft(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("alphabet.encode input should be an array of numbers");return t.map(t=>{if(ht(t),t<0||t>=e.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${e.length})`);return e[t]})},decode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("alphabet.decode input should be array of strings");return t.map(t=>{if("string"!=typeof t)throw new Error(`alphabet.decode: not string element=${t}`);const n=e.indexOf(t);if(-1===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n})}}}function pt(e=""){if("string"!=typeof e)throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("join.encode input should be array of strings");for(let e of t)if("string"!=typeof e)throw new Error(`join.encode: non-string input=${e}`);return t.join(e)},decode:t=>{if("string"!=typeof t)throw new Error("join.decode input should be string");return t.split(e)}}}function gt(e,t="="){if(ht(e),"string"!=typeof t)throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let e of n)if("string"!=typeof e)throw new Error(`padding.encode: non-string input=${e}`);for(;n.length*e%8;)n.push(t);return n},decode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let e of n)if("string"!=typeof e)throw new Error(`padding.decode: non-string input=${e}`);let r=n.length;if(r*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--)if(!((r-1)*e%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function wt(e){if("function"!=typeof e)throw new Error("normalize fn should be function");return{encode:e=>e,decode:t=>e(t)}}function bt(e,t,n){if(t<2)throw new Error(`convertRadix: wrong from=${t}, 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(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let r=0;const s=[],o=Array.from(e);for(o.forEach(e=>{if(ht(e),e<0||e>=t)throw new Error(`Wrong integer: ${e}`)});;){let e=0,i=!0;for(let s=r;s<o.length;s++){const a=o[s],l=t*e+a;if(!Number.isSafeInteger(l)||t*e/t!==e||l-a!==t*e)throw new Error("convertRadix: carry overflow");if(e=l%n,o[s]=Math.floor(l/n),!Number.isSafeInteger(o[s])||o[s]*n+e!==l)throw new Error("convertRadix: carry overflow");i&&(o[s]?i=!1:r=s)}if(s.push(e),i)break}for(let t=0;t<e.length-1&&0===e[t];t++)s.push(0);return s.reverse()}Ge(()=>new ct);const yt=(e,t)=>t?yt(t,e%t):e,mt=(e,t)=>e+(t-yt(e,t));function vt(e,t,n,r){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(mt(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${mt(t,n)}`);let s=0,o=0;const i=2**n-1,a=[];for(const r of e){if(ht(r),r>=2**t)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(s=s<<t|r,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)a.push((s>>o-n&i)>>>0);s&=2**o-1}if(s=s<<n-o&i,!r&&o>=t)throw new Error("Excess padding");if(!r&&s)throw new Error(`Non-zero padding: ${s}`);return r&&o>0&&a.push(s>>>0),a}function kt(e,t=!1){if(ht(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(mt(8,e)>32||mt(e,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 vt(Array.from(n),8,e,!t)},decode:n=>{if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(vt(n,e,8,t))}}}function xt(e){if("function"!=typeof e)throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch(e){}}}dt(kt(4),ft("0123456789ABCDEF"),pt("")),dt(kt(5),ft("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),gt(5),pt(""));const Et=(dt(kt(5),ft("0123456789ABCDEFGHIJKLMNOPQRSTUV"),gt(5),pt("")),dt(kt(5),ft("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),pt(""),wt(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),dt(kt(6),ft("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),gt(6),pt(""))),St=(dt(kt(6),ft("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),gt(6),pt("")),e=>{return dt((ht(t=58),{encode:e=>{if(!(e instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return bt(Array.from(e),256,t)},decode:e=>{if(!Array.isArray(e)||e.length&&"number"!=typeof e[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(bt(e,t,256))}}),ft(e),pt(""));var t}),At=(St("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),St("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),St("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),dt(ft("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),pt(""))),Tt=[996825010,642813549,513874426,1027748829,705979059];function $t(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Tt.length;e++)1==(t>>e&1)&&(n^=Tt[e]);return n}function Rt(e,t,n=1){const r=e.length;let s=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);s=$t(s)^n>>5}s=$t(s);for(let t=0;t<r;t++)s=$t(s)^31&e.charCodeAt(t);for(let e of t)s=$t(s)^e;for(let e=0;e<6;e++)s=$t(s);return s^=n,At.encode(vt([s%2**30],30,5,!1))}function It(e){const t="bech32"===e?1:734539939,n=kt(5),r=n.decode,s=n.encode,o=xt(r);function i(e,n=90){if("string"!=typeof e)throw new Error("bech32.decode input should be string, not "+typeof e);if(e.length<8||!1!==n&&e.length>n)throw new TypeError(`Wrong string length: ${e.length} (${e}). Expected (8..${n})`);const r=e.toLowerCase();if(e!==r&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const s=(e=r).lastIndexOf("1");if(0===s||-1===s)throw new Error('Letter "1" must be present between prefix and data only');const o=e.slice(0,s),i=e.slice(s+1);if(i.length<6)throw new Error("Data must be at least 6 characters long");const a=At.decode(i).slice(0,-6),l=Rt(o,a,t);if(!i.endsWith(l))throw new Error(`Invalid checksum in ${e}: expected "${l}"`);return{prefix:o,words:a}}return{encode:function(e,n,r=90){if("string"!=typeof e)throw new Error("bech32.encode prefix should be string, not "+typeof e);if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof n);const s=e.length+7+n.length;if(!1!==r&&s>r)throw new TypeError(`Length ${s} exceeds limit ${r}`);return`${e=e.toLowerCase()}1${At.encode(n)}${Rt(e,n,t)}`},decode:i,decodeToBytes:function(e){const{prefix:t,words:n}=i(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:xt(i),fromWords:r,fromWordsUnsafe:o,toWords:s}}const Bt=It("bech32");It("bech32m");function Lt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function _t(e){if("boolean"!=typeof e)throw new Error(`boolean expected, not ${e}`)}function Pt(e){return e instanceof Uint8Array||null!=e&&"object"==typeof e&&"Uint8Array"===e.constructor.name}function Ct(e,...t){if(!Pt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function Ut(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Nt(e,t){Ct(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}dt(kt(4),ft("0123456789abcdef"),pt(""),wt(e=>{if("string"!=typeof e||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const Ot=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),zt=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),qt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const Mt=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ht(e){Ct(e);let t="";for(let n=0;n<e.length;n++)t+=Mt[e[n]];return t}function jt(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Dt(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length,n=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,s=0;t<n;t++,s+=2){const n=jt(e.charCodeAt(s)),o=jt(e.charCodeAt(s+1));if(void 0===n||void 0===o){const t=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+s)}r[t]=16*n+o}return r}function Ft(e){if("string"==typeof e)e=function(e){if("string"!=typeof e)throw new Error("string expected, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e);else{if(!Pt(e))throw new Error("Uint8Array expected, got "+typeof e);e=e.slice()}return e}function Vt(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n}const Wt=(e,t)=>(Object.assign(t,e),t);function Zt(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),l=r?4:0,c=r?0:4;e.setUint32(t+l,i,r),e.setUint32(t+c,a,r)}const Kt=16,Yt=new Uint8Array(16),Gt=zt(Yt),Jt=(e,t,n,r)=>({s3:n<<31|r>>>1,s2:t<<31|n>>>1,s1:e<<31|t>>>1,s0:e>>>1^225<<24&-(1&r)}),Qt=e=>(e>>>0&255)<<24|(e>>>8&255)<<16|(e>>>16&255)<<8|e>>>24&255;class Xt{constructor(e,t){this.blockLen=Kt,this.outputLen=Kt,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,Ct(e=Ft(e),16);const n=qt(e);let r=n.getUint32(0,!1),s=n.getUint32(4,!1),o=n.getUint32(8,!1),i=n.getUint32(12,!1);const a=[];for(let e=0;e<128;e++)a.push({s0:Qt(r),s1:Qt(s),s2:Qt(o),s3:Qt(i)}),({s0:r,s1:s,s2:o,s3:i}=Jt(r,s,o,i));const l=(e=>e>65536?8:e>1024?4:2)(t||1024);if(![1,2,4,8].includes(l))throw new Error(`ghash: wrong window size=${l}, should be 2, 4 or 8`);this.W=l;const c=128/l,u=this.windowSize=2**l,h=[];for(let e=0;e<c;e++)for(let t=0;t<u;t++){let n=0,r=0,s=0,o=0;for(let i=0;i<l;i++){if(!(t>>>l-i-1&1))continue;const{s0:c,s1:u,s2:h,s3:d}=a[l*e+i];n^=c,r^=u,s^=h,o^=d}h.push({s0:n,s1:r,s2:s,s3:o})}this.t=h}_updateBlock(e,t,n,r){e^=this.s0,t^=this.s1,n^=this.s2,r^=this.s3;const{W:s,t:o,windowSize:i}=this;let a=0,l=0,c=0,u=0;const h=(1<<s)-1;let d=0;for(const f of[e,t,n,r])for(let e=0;e<4;e++){const t=f>>>8*e&255;for(let e=8/s-1;e>=0;e--){const n=t>>>s*e&h,{s0:r,s1:f,s2:p,s3:g}=o[d*i+n];a^=r,l^=f,c^=p,u^=g,d+=1}}this.s0=a,this.s1=l,this.s2=c,this.s3=u}update(e){e=Ft(e),Ut(this);const t=zt(e),n=Math.floor(e.length/Kt),r=e.length%Kt;for(let e=0;e<n;e++)this._updateBlock(t[4*e+0],t[4*e+1],t[4*e+2],t[4*e+3]);return r&&(Yt.set(e.subarray(n*Kt)),this._updateBlock(Gt[0],Gt[1],Gt[2],Gt[3]),Gt.fill(0)),this}destroy(){const{t:e}=this;for(const t of e)t.s0=0,t.s1=0,t.s2=0,t.s3=0}digestInto(e){Ut(this),Nt(e,this),this.finished=!0;const{s0:t,s1:n,s2:r,s3:s}=this,o=zt(e);return o[0]=t,o[1]=n,o[2]=r,o[3]=s,e}digest(){const e=new Uint8Array(Kt);return this.digestInto(e),this.destroy(),e}}class en extends Xt{constructor(e,t){const n=function(e){e.reverse();const t=1&e[15];let n=0;for(let t=0;t<e.length;t++){const r=e[t];e[t]=r>>>1|n,n=(1&r)<<7}return e[0]^=225&-t,e}((e=Ft(e)).slice());super(n,t),n.fill(0)}update(e){e=Ft(e),Ut(this);const t=zt(e),n=e.length%Kt,r=Math.floor(e.length/Kt);for(let e=0;e<r;e++)this._updateBlock(Qt(t[4*e+3]),Qt(t[4*e+2]),Qt(t[4*e+1]),Qt(t[4*e+0]));return n&&(Yt.set(e.subarray(r*Kt)),this._updateBlock(Qt(Gt[3]),Qt(Gt[2]),Qt(Gt[1]),Qt(Gt[0])),Gt.fill(0)),this}digestInto(e){Ut(this),Nt(e,this),this.finished=!0;const{s0:t,s1:n,s2:r,s3:s}=this,o=zt(e);return o[0]=t,o[1]=n,o[2]=r,o[3]=s,e.reverse()}}function tn(e){const t=(t,n)=>e(n,t.length).update(Ft(t)).digest(),n=e(new Uint8Array(16),0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=(t,n)=>e(t,n),t}const nn=tn((e,t)=>new Xt(e,t)),rn=tn((e,t)=>new en(e,t)),sn=16,on=new Uint8Array(sn);function an(e){return e<<1^283&-(e>>7)}function ln(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(1&t),e=an(e);return n}const cn=(()=>{let e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=an(n))e[t]=n;const t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=255&(r^r>>4^r>>5^r>>6^r>>7^99)}return t})(),un=cn.map((e,t)=>cn.indexOf(t)),hn=e=>e<<24|e>>>8,dn=e=>e<<8|e>>>24;function fn(e,t){if(256!==e.length)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map((n,r)=>t(e[r])),r=n.map(dn),s=r.map(dn),o=s.map(dn),i=new Uint32Array(65536),a=new Uint32Array(65536),l=new Uint16Array(65536);for(let t=0;t<256;t++)for(let c=0;c<256;c++){const u=256*t+c;i[u]=n[t]^r[c],a[u]=s[t]^o[c],l[u]=e[t]<<8|e[c]}return{sbox:e,sbox2:l,T0:n,T1:r,T2:s,T3:o,T01:i,T23:a}}const pn=fn(cn,e=>ln(e,3)<<24|e<<16|e<<8|ln(e,2)),gn=fn(un,e=>ln(e,11)<<24|ln(e,13)<<16|ln(e,9)<<8|ln(e,14)),wn=(()=>{const e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=an(n))e[t]=n;return e})();function bn(e){Ct(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:n}=pn,r=zt(e),s=r.length,o=e=>vn(n,e,e,e,e),i=new Uint32Array(t+28);i.set(r);for(let e=s;e<i.length;e++){let t=i[e-1];e%s===0?t=o(hn(t))^wn[e/s-1]:s>6&&e%s===4&&(t=o(t)),i[e]=i[e-s]^t}return i}function yn(e){const t=bn(e),n=t.slice(),r=t.length,{sbox2:s}=pn,{T0:o,T1:i,T2:a,T3:l}=gn;for(let e=0;e<r;e+=4)for(let s=0;s<4;s++)n[e+s]=t[r-e-4+s];t.fill(0);for(let e=4;e<r-4;e++){const t=n[e],r=vn(s,t,t,t,t);n[e]=o[255&r]^i[r>>>8&255]^a[r>>>16&255]^l[r>>>24]}return n}function mn(e,t,n,r,s,o){return e[n<<8&65280|r>>>8&255]^t[s>>>8&65280|o>>>24&255]}function vn(e,t,n,r,s){return e[255&t|65280&n]|e[r>>>16&255|s>>>16&65280]<<16}function kn(e,t,n,r,s){const{sbox2:o,T01:i,T23:a}=pn;let l=0;t^=e[l++],n^=e[l++],r^=e[l++],s^=e[l++];const c=e.length/4-2;for(let o=0;o<c;o++){const o=e[l++]^mn(i,a,t,n,r,s),c=e[l++]^mn(i,a,n,r,s,t),u=e[l++]^mn(i,a,r,s,t,n),h=e[l++]^mn(i,a,s,t,n,r);t=o,n=c,r=u,s=h}return{s0:e[l++]^vn(o,t,n,r,s),s1:e[l++]^vn(o,n,r,s,t),s2:e[l++]^vn(o,r,s,t,n),s3:e[l++]^vn(o,s,t,n,r)}}function xn(e,t,n,r,s){const{sbox2:o,T01:i,T23:a}=gn;let l=0;t^=e[l++],n^=e[l++],r^=e[l++],s^=e[l++];const c=e.length/4-2;for(let o=0;o<c;o++){const o=e[l++]^mn(i,a,t,s,r,n),c=e[l++]^mn(i,a,n,t,s,r),u=e[l++]^mn(i,a,r,n,t,s),h=e[l++]^mn(i,a,s,r,n,t);t=o,n=c,r=u,s=h}return{s0:e[l++]^vn(o,t,s,r,n),s1:e[l++]^vn(o,n,t,s,r),s2:e[l++]^vn(o,r,n,t,s),s3:e[l++]^vn(o,s,r,n,t)}}function En(e,t){if(!t)return new Uint8Array(e);if(Ct(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function Sn(e,t,n,r,s){Ct(n,sn),Ct(r),s=En(r.length,s);const o=n,i=zt(o),a=qt(o),l=zt(r),c=zt(s),u=t?0:12,h=r.length;let d=a.getUint32(u,t),{s0:f,s1:p,s2:g,s3:w}=kn(e,i[0],i[1],i[2],i[3]);for(let n=0;n+4<=l.length;n+=4)c[n+0]=l[n+0]^f,c[n+1]=l[n+1]^p,c[n+2]=l[n+2]^g,c[n+3]=l[n+3]^w,d=d+1>>>0,a.setUint32(u,d,t),({s0:f,s1:p,s2:g,s3:w}=kn(e,i[0],i[1],i[2],i[3]));const b=sn*Math.floor(l.length/4);if(b<h){const e=new Uint32Array([f,p,g,w]),t=Ot(e);for(let e=b,n=0;e<h;e++,n++)s[e]=r[e]^t[n]}return s}function An(e){if(Ct(e),e.length%sn!==0)throw new Error("aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size 16")}function Tn(e,t,n){let r=e.length;const s=r%sn;if(!t&&0!==s)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const o=zt(e);if(t){let e=sn-s;e||(e=sn),r+=e}const i=En(r,n);return{b:o,o:zt(i),out:i}}function $n(e,t){if(!t)return e;const n=e.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=e[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const s=e.subarray(0,-r);for(let t=0;t<r;t++)if(e[n-t-1]!==r)throw new Error("aes/pcks5: wrong padding");return s}function Rn(e){const t=new Uint8Array(16),n=zt(t);t.set(e);const r=sn-e.length;for(let e=sn-r;e<sn;e++)t[e]=r;return n}Wt({blockSize:16,nonceLength:16},function(e,t){function n(n,r){const s=bn(e),o=t.slice(),i=function(e,t,n,r){Ct(t,sn),Ct(n);const s=n.length;r=En(s,r);const o=t,i=zt(o);let{s0:a,s1:l,s2:c,s3:u}=kn(e,i[0],i[1],i[2],i[3]);const h=zt(n),d=zt(r);for(let t=0;t+4<=h.length;t+=4){d[t+0]=h[t+0]^a,d[t+1]=h[t+1]^l,d[t+2]=h[t+2]^c,d[t+3]=h[t+3]^u;let n=1;for(let e=o.length-1;e>=0;e--)n=n+(255&o[e])|0,o[e]=255&n,n>>>=8;({s0:a,s1:l,s2:c,s3:u}=kn(e,i[0],i[1],i[2],i[3]))}const f=sn*Math.floor(h.length/4);if(f<s){const e=new Uint32Array([a,l,c,u]),t=Ot(e);for(let e=f,o=0;e<s;e++,o++)r[e]=n[e]^t[o]}return r}(s,o,n,r);return s.fill(0),o.fill(0),i}return Ct(e),Ct(t,sn),{encrypt:(e,t)=>n(e,t),decrypt:(e,t)=>n(e,t)}}),Wt({blockSize:16},function(e,t={}){Ct(e);const n=!t.disablePadding;return{encrypt:(t,r)=>{Ct(t);const{b:s,o,out:i}=Tn(t,n,r),a=bn(e);let l=0;for(;l+4<=s.length;){const{s0:e,s1:t,s2:n,s3:r}=kn(a,s[l+0],s[l+1],s[l+2],s[l+3]);o[l++]=e,o[l++]=t,o[l++]=n,o[l++]=r}if(n){const e=Rn(t.subarray(4*l)),{s0:n,s1:r,s2:s,s3:i}=kn(a,e[0],e[1],e[2],e[3]);o[l++]=n,o[l++]=r,o[l++]=s,o[l++]=i}return a.fill(0),i},decrypt:(t,r)=>{An(t);const s=yn(e),o=En(t.length,r),i=zt(t),a=zt(o);for(let e=0;e+4<=i.length;){const{s0:t,s1:n,s2:r,s3:o}=xn(s,i[e+0],i[e+1],i[e+2],i[e+3]);a[e++]=t,a[e++]=n,a[e++]=r,a[e++]=o}return s.fill(0),$n(o,n)}}});const In=Wt({blockSize:16,nonceLength:16},function(e,t,n={}){Ct(e),Ct(t,16);const r=!n.disablePadding;return{encrypt:(n,s)=>{const o=bn(e),{b:i,o:a,out:l}=Tn(n,r,s),c=zt(t);let u=c[0],h=c[1],d=c[2],f=c[3],p=0;for(;p+4<=i.length;)u^=i[p+0],h^=i[p+1],d^=i[p+2],f^=i[p+3],({s0:u,s1:h,s2:d,s3:f}=kn(o,u,h,d,f)),a[p++]=u,a[p++]=h,a[p++]=d,a[p++]=f;if(r){const e=Rn(n.subarray(4*p));u^=e[0],h^=e[1],d^=e[2],f^=e[3],({s0:u,s1:h,s2:d,s3:f}=kn(o,u,h,d,f)),a[p++]=u,a[p++]=h,a[p++]=d,a[p++]=f}return o.fill(0),l},decrypt:(n,s)=>{An(n);const o=yn(e),i=zt(t),a=En(n.length,s),l=zt(n),c=zt(a);let u=i[0],h=i[1],d=i[2],f=i[3];for(let e=0;e+4<=l.length;){const t=u,n=h,r=d,s=f;u=l[e+0],h=l[e+1],d=l[e+2],f=l[e+3];const{s0:i,s1:a,s2:p,s3:g}=xn(o,u,h,d,f);c[e++]=i^t,c[e++]=a^n,c[e++]=p^r,c[e++]=g^s}return o.fill(0),$n(a,r)}}});function Bn(e,t,n,r,s){const o=e.create(n,r.length+(s?.length||0));s&&o.update(s),o.update(r);const i=new Uint8Array(16),a=qt(i);return s&&Zt(a,0,BigInt(8*s.length),t),Zt(a,8,BigInt(8*r.length),t),o.update(i),o.digest()}Wt({blockSize:16,nonceLength:16},function(e,t){function n(n,r,s){const o=bn(e),i=n.length;s=En(i,s);const a=zt(n),l=zt(s),c=r?l:a,u=zt(t);let h=u[0],d=u[1],f=u[2],p=u[3];for(let e=0;e+4<=a.length;){const{s0:t,s1:n,s2:r,s3:s}=kn(o,h,d,f,p);l[e+0]=a[e+0]^t,l[e+1]=a[e+1]^n,l[e+2]=a[e+2]^r,l[e+3]=a[e+3]^s,h=c[e++],d=c[e++],f=c[e++],p=c[e++]}const g=sn*Math.floor(a.length/4);if(g<i){({s0:h,s1:d,s2:f,s3:p}=kn(o,h,d,f,p));const e=Ot(new Uint32Array([h,d,f,p]));for(let t=g,r=0;t<i;t++,r++)s[t]=n[t]^e[r];e.fill(0)}return o.fill(0),s}return Ct(e),Ct(t,16),{encrypt:(e,t)=>n(e,!0,t),decrypt:(e,t)=>n(e,!1,t)}}),Wt({blockSize:16,nonceLength:12,tagLength:16},function(e,t,n){if(Ct(t),0===t.length)throw new Error("aes/gcm: empty nonce");function r(e,t,r){const s=Bn(nn,!1,e,r,n);for(let e=0;e<t.length;e++)s[e]^=t[e];return s}function s(){const n=bn(e),r=on.slice(),s=on.slice();if(Sn(n,!1,s,s,r),12===t.length)s.set(t);else{const e=on.slice();Zt(qt(e),8,BigInt(8*t.length),!1),nn.create(r).update(t).update(e).digestInto(s)}return{xk:n,authKey:r,counter:s,tagMask:Sn(n,!1,s,on)}}return{encrypt:e=>{Ct(e);const{xk:t,authKey:n,counter:o,tagMask:i}=s(),a=new Uint8Array(e.length+16);Sn(t,!1,o,e,a);const l=r(n,i,a.subarray(0,a.length-16));return a.set(l,e.length),t.fill(0),a},decrypt:e=>{if(Ct(e),e.length<16)throw new Error("aes/gcm: ciphertext less than tagLen (16)");const{xk:t,authKey:n,counter:o,tagMask:i}=s(),a=e.subarray(0,-16),l=e.subarray(-16);if(!Vt(r(n,i,a),l))throw new Error("aes/gcm: invalid ghash tag");const c=Sn(t,!1,o,a);return n.fill(0),i.fill(0),t.fill(0),c}}});const Ln=(e,t,n)=>r=>{if(!Number.isSafeInteger(r)||t>r||r>n)throw new Error(`${e}: invalid value=${r}, must be [${t}..${n}]`)};Wt({blockSize:16,nonceLength:12,tagLength:16},function(e,t,n){const r=Ln("AAD",0,2**36),s=Ln("plaintext",0,2**36),o=Ln("nonce",12,12),i=Ln("ciphertext",16,2**36+16);function a(){const n=e.length;if(16!==n&&24!==n&&32!==n)throw new Error(`key length must be 16, 24 or 32 bytes, got: ${n} bytes`);const r=bn(e),s=new Uint8Array(n),o=new Uint8Array(16),i=zt(t);let a=0,l=i[0],c=i[1],u=i[2],h=0;for(const e of[o,s].map(zt)){const t=zt(e);for(let e=0;e<t.length;e+=2){const{s0:n,s1:s}=kn(r,a,l,c,u);t[e+0]=n,t[e+1]=s,a=++h}}return r.fill(0),{authKey:o,encKey:bn(s)}}function l(e,r,s){const o=Bn(rn,!0,r,s,n);for(let e=0;e<12;e++)o[e]^=t[e];o[15]&=127;const i=zt(o);let a=i[0],l=i[1],c=i[2],u=i[3];return({s0:a,s1:l,s2:c,s3:u}=kn(e,a,l,c,u)),i[0]=a,i[1]=l,i[2]=c,i[3]=u,o}function c(e,t,n){let r=t.slice();return r[15]|=128,Sn(e,!0,r,n)}return Ct(t),o(t.length),n&&(Ct(n),r(n.length)),{encrypt:e=>{Ct(e),s(e.length);const{encKey:t,authKey:n}=a(),r=l(t,n,e),o=new Uint8Array(e.length+16);return o.set(r,e.length),o.set(c(t,r,e)),t.fill(0),n.fill(0),o},decrypt:e=>{Ct(e),i(e.length);const t=e.subarray(-16),{encKey:n,authKey:r}=a(),s=c(n,t,e.subarray(0,-16)),o=l(n,r,s);if(n.fill(0),r.fill(0),!Vt(t,o))throw new Error("invalid polyval tag");return s}}});const _n=(e,t)=>255&e[t++]|(255&e[t++])<<8;class Pn{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,Ct(e=Ft(e),32);const t=_n(e,0),n=_n(e,2),r=_n(e,4),s=_n(e,6),o=_n(e,8),i=_n(e,10),a=_n(e,12),l=_n(e,14);this.r[0]=8191&t,this.r[1]=8191&(t>>>13|n<<3),this.r[2]=7939&(n>>>10|r<<6),this.r[3]=8191&(r>>>7|s<<9),this.r[4]=255&(s>>>4|o<<12),this.r[5]=o>>>1&8190,this.r[6]=8191&(o>>>14|i<<2),this.r[7]=8065&(i>>>11|a<<5),this.r[8]=8191&(a>>>8|l<<8),this.r[9]=l>>>5&127;for(let t=0;t<8;t++)this.pad[t]=_n(e,16+2*t)}process(e,t,n=!1){const r=n?0:2048,{h:s,r:o}=this,i=o[0],a=o[1],l=o[2],c=o[3],u=o[4],h=o[5],d=o[6],f=o[7],p=o[8],g=o[9],w=_n(e,t+0),b=_n(e,t+2),y=_n(e,t+4),m=_n(e,t+6),v=_n(e,t+8),k=_n(e,t+10),x=_n(e,t+12),E=_n(e,t+14);let S=s[0]+(8191&w),A=s[1]+(8191&(w>>>13|b<<3)),T=s[2]+(8191&(b>>>10|y<<6)),$=s[3]+(8191&(y>>>7|m<<9)),R=s[4]+(8191&(m>>>4|v<<12)),I=s[5]+(v>>>1&8191),B=s[6]+(8191&(v>>>14|k<<2)),L=s[7]+(8191&(k>>>11|x<<5)),_=s[8]+(8191&(x>>>8|E<<8)),P=s[9]+(E>>>5|r),C=0,U=C+S*i+A*(5*g)+T*(5*p)+$*(5*f)+R*(5*d);C=U>>>13,U&=8191,U+=I*(5*h)+B*(5*u)+L*(5*c)+_*(5*l)+P*(5*a),C+=U>>>13,U&=8191;let N=C+S*a+A*i+T*(5*g)+$*(5*p)+R*(5*f);C=N>>>13,N&=8191,N+=I*(5*d)+B*(5*h)+L*(5*u)+_*(5*c)+P*(5*l),C+=N>>>13,N&=8191;let O=C+S*l+A*a+T*i+$*(5*g)+R*(5*p);C=O>>>13,O&=8191,O+=I*(5*f)+B*(5*d)+L*(5*h)+_*(5*u)+P*(5*c),C+=O>>>13,O&=8191;let z=C+S*c+A*l+T*a+$*i+R*(5*g);C=z>>>13,z&=8191,z+=I*(5*p)+B*(5*f)+L*(5*d)+_*(5*h)+P*(5*u),C+=z>>>13,z&=8191;let q=C+S*u+A*c+T*l+$*a+R*i;C=q>>>13,q&=8191,q+=I*(5*g)+B*(5*p)+L*(5*f)+_*(5*d)+P*(5*h),C+=q>>>13,q&=8191;let M=C+S*h+A*u+T*c+$*l+R*a;C=M>>>13,M&=8191,M+=I*i+B*(5*g)+L*(5*p)+_*(5*f)+P*(5*d),C+=M>>>13,M&=8191;let H=C+S*d+A*h+T*u+$*c+R*l;C=H>>>13,H&=8191,H+=I*a+B*i+L*(5*g)+_*(5*p)+P*(5*f),C+=H>>>13,H&=8191;let j=C+S*f+A*d+T*h+$*u+R*c;C=j>>>13,j&=8191,j+=I*l+B*a+L*i+_*(5*g)+P*(5*p),C+=j>>>13,j&=8191;let D=C+S*p+A*f+T*d+$*h+R*u;C=D>>>13,D&=8191,D+=I*c+B*l+L*a+_*i+P*(5*g),C+=D>>>13,D&=8191;let F=C+S*g+A*p+T*f+$*d+R*h;C=F>>>13,F&=8191,F+=I*u+B*c+L*l+_*a+P*i,C+=F>>>13,F&=8191,C=(C<<2)+C|0,C=C+U|0,U=8191&C,C>>>=13,N+=C,s[0]=U,s[1]=N,s[2]=O,s[3]=z,s[4]=q,s[5]=M,s[6]=H,s[7]=j,s[8]=D,s[9]=F}finalize(){const{h:e,pad:t}=this,n=new Uint16Array(10);let r=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=r,r=e[t]>>>13,e[t]&=8191;e[0]+=5*r,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(let t=1;t<10;t++)n[t]=e[t]+r,r=n[t]>>>13,n[t]&=8191;n[9]-=8192;let s=(1^r)-1;for(let e=0;e<10;e++)n[e]&=s;s=~s;for(let t=0;t<10;t++)e[t]=e[t]&s|n[t];e[0]=65535&(e[0]|e[1]<<13),e[1]=65535&(e[1]>>>3|e[2]<<10),e[2]=65535&(e[2]>>>6|e[3]<<7),e[3]=65535&(e[3]>>>9|e[4]<<4),e[4]=65535&(e[4]>>>12|e[5]<<1|e[6]<<14),e[5]=65535&(e[6]>>>2|e[7]<<11),e[6]=65535&(e[7]>>>5|e[8]<<8),e[7]=65535&(e[8]>>>8|e[9]<<5);let o=e[0]+t[0];e[0]=65535&o;for(let n=1;n<8;n++)o=(e[n]+t[n]|0)+(o>>>16)|0,e[n]=65535&o}update(e){Ut(this);const{buffer:t,blockLen:n}=this,r=(e=Ft(e)).length;for(let s=0;s<r;){const o=Math.min(n-this.pos,r-s);if(o!==n)t.set(e.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===n&&(this.process(t,0,!1),this.pos=0);else for(;n<=r-s;s+=n)this.process(e,s)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){Ut(this),Nt(e,this),this.finished=!0;const{buffer:t,h:n}=this;let{pos:r}=this;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();let s=0;for(let t=0;t<8;t++)e[s++]=n[t]>>>0,e[s++]=n[t]>>>8;return e}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}}const Cn=function(e){const t=(t,n)=>e(n).update(Ft(t)).digest(),n=e(new Uint8Array(32));return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t}(e=>new Pn(e)),Un=e=>Uint8Array.from(e.split("").map(e=>e.charCodeAt(0))),Nn=Un("expand 16-byte k"),On=Un("expand 32-byte k"),zn=zt(Nn),qn=zt(On);function Mn(e,t){return e<<t|e>>>32-t}function Hn(e){return e.byteOffset%4==0}qn.slice();const jn=2**32-1,Dn=new Uint32Array;function Fn(e,t){const{allowShortKeys:n,extendNonceFn:r,counterLength:s,counterRight:o,rounds:i}=function(e,t){if(null==t||"object"!=typeof t)throw new Error("options must be defined");return Object.assign({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t)}(0,t);if("function"!=typeof e)throw new Error("core must be a function");return Lt(s),Lt(i),_t(o),_t(n),(t,a,l,c,u=0)=>{Ct(t),Ct(a),Ct(l);const h=l.length;if(c||(c=new Uint8Array(h)),Ct(c),Lt(u),u<0||u>=jn)throw new Error("arx: counter overflow");if(c.length<h)throw new Error(`arx: output (${c.length}) is shorter than data (${h})`);const d=[];let f,p,g=t.length;if(32===g)f=t.slice(),d.push(f),p=qn;else{if(16!==g||!n)throw new Error(`arx: invalid 32-byte key, got length=${g}`);f=new Uint8Array(32),f.set(t),f.set(t,16),p=zn,d.push(f)}Hn(a)||(a=a.slice(),d.push(a));const w=zt(f);if(r){if(24!==a.length)throw new Error("arx: extended nonce must be 24 bytes");r(p,w,zt(a.subarray(0,16)),w),a=a.subarray(16)}const b=16-s;if(b!==a.length)throw new Error(`arx: nonce must be ${b} or 16 bytes`);if(12!==b){const e=new Uint8Array(12);e.set(a,o?0:12-a.length),a=e,d.push(a)}const y=zt(a);for(function(e,t,n,r,s,o,i,a){const l=s.length,c=new Uint8Array(64),u=zt(c),h=Hn(s)&&Hn(o),d=h?zt(s):Dn,f=h?zt(o):Dn;for(let p=0;p<l;i++){if(e(t,n,r,u,i,a),i>=jn)throw new Error("arx: counter overflow");const g=Math.min(64,l-p);if(h&&64===g){const e=p/4;if(p%4!=0)throw new Error("arx: invalid block position");for(let t,n=0;n<16;n++)t=e+n,f[t]=d[t]^u[n];p+=64;continue}for(let e,t=0;t<g;t++)e=p+t,o[e]=s[e]^c[t];p+=g}}(e,p,w,y,l,c,u,i);d.length>0;)d.pop().fill(0);return c}}function Vn(e,t,n,r,s,o=20){let i=e[0],a=e[1],l=e[2],c=e[3],u=t[0],h=t[1],d=t[2],f=t[3],p=t[4],g=t[5],w=t[6],b=t[7],y=s,m=n[0],v=n[1],k=n[2],x=i,E=a,S=l,A=c,T=u,$=h,R=d,I=f,B=p,L=g,_=w,P=b,C=y,U=m,N=v,O=k;for(let e=0;e<o;e+=2)x=x+T|0,C=Mn(C^x,16),B=B+C|0,T=Mn(T^B,12),x=x+T|0,C=Mn(C^x,8),B=B+C|0,T=Mn(T^B,7),E=E+$|0,U=Mn(U^E,16),L=L+U|0,$=Mn($^L,12),E=E+$|0,U=Mn(U^E,8),L=L+U|0,$=Mn($^L,7),S=S+R|0,N=Mn(N^S,16),_=_+N|0,R=Mn(R^_,12),S=S+R|0,N=Mn(N^S,8),_=_+N|0,R=Mn(R^_,7),A=A+I|0,O=Mn(O^A,16),P=P+O|0,I=Mn(I^P,12),A=A+I|0,O=Mn(O^A,8),P=P+O|0,I=Mn(I^P,7),x=x+$|0,O=Mn(O^x,16),_=_+O|0,$=Mn($^_,12),x=x+$|0,O=Mn(O^x,8),_=_+O|0,$=Mn($^_,7),E=E+R|0,C=Mn(C^E,16),P=P+C|0,R=Mn(R^P,12),E=E+R|0,C=Mn(C^E,8),P=P+C|0,R=Mn(R^P,7),S=S+I|0,U=Mn(U^S,16),B=B+U|0,I=Mn(I^B,12),S=S+I|0,U=Mn(U^S,8),B=B+U|0,I=Mn(I^B,7),A=A+T|0,N=Mn(N^A,16),L=L+N|0,T=Mn(T^L,12),A=A+T|0,N=Mn(N^A,8),L=L+N|0,T=Mn(T^L,7);let z=0;r[z++]=i+x|0,r[z++]=a+E|0,r[z++]=l+S|0,r[z++]=c+A|0,r[z++]=u+T|0,r[z++]=h+$|0,r[z++]=d+R|0,r[z++]=f+I|0,r[z++]=p+B|0,r[z++]=g+L|0,r[z++]=w+_|0,r[z++]=b+P|0,r[z++]=y+C|0,r[z++]=m+U|0,r[z++]=v+N|0,r[z++]=k+O|0}const Wn=Fn(Vn,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Zn=Fn(Vn,{counterRight:!1,counterLength:8,extendNonceFn:function(e,t,n,r){let s=e[0],o=e[1],i=e[2],a=e[3],l=t[0],c=t[1],u=t[2],h=t[3],d=t[4],f=t[5],p=t[6],g=t[7],w=n[0],b=n[1],y=n[2],m=n[3];for(let e=0;e<20;e+=2)s=s+l|0,w=Mn(w^s,16),d=d+w|0,l=Mn(l^d,12),s=s+l|0,w=Mn(w^s,8),d=d+w|0,l=Mn(l^d,7),o=o+c|0,b=Mn(b^o,16),f=f+b|0,c=Mn(c^f,12),o=o+c|0,b=Mn(b^o,8),f=f+b|0,c=Mn(c^f,7),i=i+u|0,y=Mn(y^i,16),p=p+y|0,u=Mn(u^p,12),i=i+u|0,y=Mn(y^i,8),p=p+y|0,u=Mn(u^p,7),a=a+h|0,m=Mn(m^a,16),g=g+m|0,h=Mn(h^g,12),a=a+h|0,m=Mn(m^a,8),g=g+m|0,h=Mn(h^g,7),s=s+c|0,m=Mn(m^s,16),p=p+m|0,c=Mn(c^p,12),s=s+c|0,m=Mn(m^s,8),p=p+m|0,c=Mn(c^p,7),o=o+u|0,w=Mn(w^o,16),g=g+w|0,u=Mn(u^g,12),o=o+u|0,w=Mn(w^o,8),g=g+w|0,u=Mn(u^g,7),i=i+h|0,b=Mn(b^i,16),d=d+b|0,h=Mn(h^d,12),i=i+h|0,b=Mn(b^i,8),d=d+b|0,h=Mn(h^d,7),a=a+l|0,y=Mn(y^a,16),f=f+y|0,l=Mn(l^f,12),a=a+l|0,y=Mn(y^a,8),f=f+y|0,l=Mn(l^f,7);let v=0;r[v++]=s,r[v++]=o,r[v++]=i,r[v++]=a,r[v++]=w,r[v++]=b,r[v++]=y,r[v++]=m},allowShortKeys:!1}),Kn=new Uint8Array(16),Yn=(e,t)=>{e.update(t);const n=t.length%16;n&&e.update(Kn.subarray(n))},Gn=new Uint8Array(32);function Jn(e,t,n,r,s){const o=e(t,n,Gn),i=Cn.create(o);s&&Yn(i,s),Yn(i,r);const a=new Uint8Array(16),l=qt(a);Zt(l,0,BigInt(s?s.length:0),!0),Zt(l,8,BigInt(r.length),!0),i.update(a);const c=i.digest();return o.fill(0),c}const Qn=e=>(t,n,r)=>(Ct(t,32),Ct(n),{encrypt:(s,o)=>{const i=s.length,a=i+16;o?Ct(o,a):o=new Uint8Array(a),e(t,n,s,o,1);const l=Jn(e,t,n,o.subarray(0,-16),r);return o.set(l,i),o},decrypt:(s,o)=>{const i=s.length,a=i-16;if(i<16)throw new Error("encrypted data must be at least 16 bytes");o?Ct(o,a):o=new Uint8Array(a);const l=s.subarray(0,-16);if(!Vt(s.subarray(-16),Jn(e,t,n,l,r)))throw new Error("invalid tag");return e(t,n,l,o,1),o}});Qn(Wn),Qn(Zn);class Xn extends Ye{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,tt.hash(e);const n=Ze(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,s=new Uint8Array(r);s.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<s.length;e++)s[e]^=54;this.iHash.update(s),this.oHash=e.create();for(let e=0;e<s.length;e++)s[e]^=106;this.oHash.update(s),s.fill(0)}update(e){return tt.exists(this),this.iHash.update(e),this}digestInto(e){tt.exists(this),tt.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:t,iHash:n,finished:r,destroyed:s,blockLen:o,outputLen:i}=this;return e.finished=r,e.destroyed=s,e.blockLen=o,e.outputLen=i,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const er=(e,t,n)=>new Xn(e,t).update(n).digest();er.create=(e,t)=>new Xn(e,t);const tr=new Uint8Array([0]),nr=new Uint8Array;var rr=Object.defineProperty,sr=(e,t)=>{for(var n in t)rr(e,n,{get:t[n],enumerable:!0})},or=Symbol("verified");function ir(e){if(!(e instanceof Object))return!1;if("number"!=typeof e.kind)return!1;if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if("string"!=typeof e.pubkey)return!1;if(!e.pubkey.match(/^[a-f0-9]{64}$/))return!1;if(!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let e=0;e<n.length;e++)if("string"!=typeof n[e])return!1}return!0}sr({},{Queue:()=>pr,QueueNode:()=>fr,binarySearch:()=>dr,bytesToHex:()=>Ve,hexToBytes:()=>We,insertEventIntoAscendingList:()=>hr,insertEventIntoDescendingList:()=>ur,normalizeURL:()=>cr,utf8Decoder:()=>ar,utf8Encoder:()=>lr});var ar=new TextDecoder("utf-8"),lr=new TextEncoder;function cr(e){try{-1===e.indexOf("://")&&(e="wss://"+e);let t=new URL(e);return"http:"===t.protocol?t.protocol="ws:":"https:"===t.protocol&&(t.protocol="wss:"),t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),("80"===t.port&&"ws:"===t.protocol||"443"===t.port&&"wss:"===t.protocol)&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch(t){throw new Error(`Invalid URL: ${e}`)}}function ur(e,t){const[n,r]=dr(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:e.created_at-t.created_at);return r||e.splice(n,0,t),e}function hr(e,t){const[n,r]=dr(e,e=>t.id===e.id?0:t.created_at===e.created_at?-1:t.created_at-e.created_at);return r||e.splice(n,0,t),e}function dr(e,t){let n=0,r=e.length-1;for(;n<=r;){const s=Math.floor((n+r)/2),o=t(e[s]);if(0===o)return[s,!0];o<0?r=s-1:n=s+1}return[n,!1]}var fr=class{value;next=null;prev=null;constructor(e){this.value=e}},pr=class{first;last;constructor(){this.first=null,this.last=null}enqueue(e){const t=new fr(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const e=this.first;return this.first=null,this.last=null,e.value}const e=this.first;return this.first=e.next,this.first&&(this.first.prev=null),e.value}};function gr(e){return Ve(ut(lr.encode(function(e){if(!ir(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}(e))))}var wr=new class{generateSecretKey(){return qe.utils.randomPrivateKey()}getPublicKey(e){return Ve(qe.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=Ve(qe.getPublicKey(t)),n.id=gr(n),n.sig=Ve(qe.sign(gr(n),t)),n[or]=!0,n}verifyEvent(e){if("boolean"==typeof e[or])return e[or];const t=gr(e);if(t!==e.id)return e[or]=!1,!1;try{const n=qe.verify(e.sig,t,e.pubkey);return e[or]=n,n}catch(t){return e[or]=!1,!1}}},br=wr.generateSecretKey,yr=wr.getPublicKey,mr=wr.finalizeEvent,vr=wr.verifyEvent;function kr(e){return e<1e4&&0!==e&&3!==e}function xr(e){return 0===e||3===e||1e4<=e&&e<2e4}function Er(e){return 2e4<=e&&e<3e4}function Sr(e){return 3e4<=e&&e<4e4}function Ar(e){return kr(e)?"regular":xr(e)?"replaceable":Er(e)?"ephemeral":Sr(e)?"parameterized":"unknown"}function Tr(e,t){const n=t instanceof Array?t:[t];return ir(e)&&n.includes(e.kind)||!1}sr({},{Application:()=>Js,BadgeAward:()=>Ur,BadgeDefinition:()=>Fs,BlockedRelaysList:()=>Es,BlossomServerList:()=>Bs,BookmarkList:()=>vs,Bookmarksets:()=>Hs,Calendar:()=>so,CalendarEventRSVP:()=>oo,ChannelCreation:()=>Vr,ChannelHideMessage:()=>Kr,ChannelMessage:()=>Zr,ChannelMetadata:()=>Wr,ChannelMuteUser:()=>Yr,ChatMessage:()=>Nr,ClassifiedListing:()=>eo,ClientAuth:()=>Ps,Comment:()=>es,CommunitiesList:()=>ks,CommunityDefinition:()=>co,CommunityPostApproval:()=>ls,Contacts:()=>Br,CreateOrUpdateProduct:()=>Zs,CreateOrUpdateStall:()=>Ws,Curationsets:()=>js,Date:()=>no,DirectMessageRelaysList:()=>Rs,DraftClassifiedListing:()=>to,DraftLong:()=>Ys,Emojisets:()=>Gs,EncryptedDirectMessage:()=>Lr,EventDeletion:()=>_r,FavoriteRelays:()=>As,FileMessage:()=>Mr,FileMetadata:()=>Xr,FileServerPreference:()=>Is,Followsets:()=>zs,ForumThread:()=>Or,GenericRepost:()=>Hr,Genericlists:()=>qs,GiftWrap:()=>Jr,GroupMetadata:()=>uo,HTTPAuth:()=>Os,Handlerinformation:()=>lo,Handlerrecommendation:()=>ao,Highlights:()=>gs,InterestsList:()=>Ts,Interestsets:()=>Vs,JobFeedback:()=>hs,JobRequest:()=>cs,JobResult:()=>us,Label:()=>as,LightningPubRPC:()=>_s,LiveChatMessage:()=>ts,LiveEvent:()=>Qs,LongFormArticle:()=>Ks,Metadata:()=>$r,Mutelist:()=>bs,NWCWalletInfo:()=>Ls,NWCWalletRequest:()=>Cs,NWCWalletResponse:()=>Us,NormalVideo:()=>Dr,NostrConnect:()=>Ns,OpenTimestamps:()=>Gr,Photo:()=>jr,Pinlist:()=>ys,Poll:()=>Qr,PollResponse:()=>ws,PrivateDirectMessage:()=>qr,ProblemTracker:()=>ss,ProfileBadges:()=>Ds,PublicChatsList:()=>xs,Reaction:()=>Cr,RecommendRelay:()=>Ir,RelayList:()=>ms,RelayReview:()=>io,Relaysets:()=>Ms,Report:()=>os,Reporting:()=>is,Repost:()=>Pr,Seal:()=>zr,SearchRelaysList:()=>Ss,ShortTextNote:()=>Rr,ShortVideo:()=>Fr,Time:()=>ro,UserEmojiList:()=>$s,UserStatuses:()=>Xs,Voice:()=>ns,VoiceComment:()=>rs,Zap:()=>ps,ZapGoal:()=>ds,ZapRequest:()=>fs,classifyKind:()=>Ar,isAddressableKind:()=>Sr,isEphemeralKind:()=>Er,isKind:()=>Tr,isRegularKind:()=>kr,isReplaceableKind:()=>xr});var $r=0,Rr=1,Ir=2,Br=3,Lr=4,_r=5,Pr=6,Cr=7,Ur=8,Nr=9,Or=11,zr=13,qr=14,Mr=15,Hr=16,jr=20,Dr=21,Fr=22,Vr=40,Wr=41,Zr=42,Kr=43,Yr=44,Gr=1040,Jr=1059,Qr=1068,Xr=1063,es=1111,ts=1311,ns=1222,rs=1244,ss=1971,os=1984,is=1984,as=1985,ls=4550,cs=5999,us=6999,hs=7e3,ds=9041,fs=9734,ps=9735,gs=9802,ws=1018,bs=1e4,ys=10001,ms=10002,vs=10003,ks=10004,xs=10005,Es=10006,Ss=10007,As=10012,Ts=10015,$s=10030,Rs=10050,Is=10096,Bs=10063,Ls=13194,_s=21e3,Ps=22242,Cs=23194,Us=23195,Ns=24133,Os=27235,zs=3e4,qs=30001,Ms=30002,Hs=30003,js=30004,Ds=30008,Fs=30009,Vs=30015,Ws=30017,Zs=30018,Ks=30023,Ys=30024,Gs=30030,Js=30078,Qs=30311,Xs=30315,eo=30402,to=30403,no=31922,ro=31923,so=31924,oo=31925,io=31987,ao=31989,lo=31990,co=34550,uo=39e3;function ho(e,t){if(e.ids&&-1===e.ids.indexOf(t.id))return!1;if(e.kinds&&-1===e.kinds.indexOf(t.kind))return!1;if(e.authors&&-1===e.authors.indexOf(t.pubkey))return!1;for(let n in e)if("#"===n[0]){let r=e[`#${n.slice(1)}`];if(r&&!t.tags.find(([e,t])=>e===n.slice(1)&&-1!==r.indexOf(t)))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function fo(e,t){let n=t.length+3,r=e.indexOf(`"${t}":`)+n,s=e.slice(r).indexOf('"')+r+1;return e.slice(s,s+64)}function po(e,t){let n=t.length,r=e.indexOf(`"${t}":`)+n+3,s=e.slice(r),o=Math.min(s.indexOf(","),s.indexOf("}"));return parseInt(s.slice(0,o),10)}function go(e){let t=e.slice(0,22).indexOf('"EVENT"');if(-1===t)return null;let n=e.slice(t+7+1).indexOf('"');if(-1===n)return null;let r=t+7+1+n,s=e.slice(r+1,80).indexOf('"');if(-1===s)return null;let o=r+1+s;return e.slice(r+1,o)}function wo(e,t){return t===fo(e,"id")}function bo(e,t){return t===fo(e,"pubkey")}function yo(e,t){return t===po(e,"kind")}function mo(e,t){return{kind:Ps,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function vo(){return new Promise((e,t)=>{try{if("undefined"!=typeof MessageChannel){const t=new MessageChannel,n=()=>{t.port1.removeEventListener("message",n),e()};t.port1.addEventListener("message",n),t.port2.postMessage(0),t.port1.start()}else"undefined"!=typeof setImmediate?setImmediate(e):"undefined"!=typeof setTimeout?setTimeout(e,0):e()}catch(e){console.error("during yield: ",e),t(e)}})}sr({},{getHex64:()=>fo,getInt:()=>po,getSubscriptionId:()=>go,matchEventId:()=>wo,matchEventKind:()=>yo,matchEventPubkey:()=>bo}),sr({},{makeAuthEvent:()=>mo});var ko=e=>(e[or]=!0,!0),xo=class extends Error{constructor(e,t){super(`Tried to send message '${e} on a closed connection to ${t}.`),this.name="SendingOnClosedConnection"}},Eo=class{url;_connected=!1;onclose=null;onnotice=e=>console.debug(`NOTICE from ${this.url}: ${e}`);onauth;baseEoseTimeout=4400;connectionTimeout=4400;publishTimeout=4400;pingFrequency=29e3;pingTimeout=2e4;resubscribeBackoff=[1e4,1e4,1e4,2e4,2e4,3e4,6e4];openSubs=new Map;enablePing;enableReconnect;connectionTimeoutHandle;reconnectTimeoutHandle;pingIntervalHandle;reconnectAttempts=0;closedIntentionally=!1;connectionPromise;openCountRequests=new Map;openEventPublishes=new Map;ws;incomingMessageQueue=new pr;queueRunning=!1;challenge;authPromise;serial=0;verifyEvent;_WebSocket;constructor(e,t){this.url=cr(e),this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation||WebSocket,this.enablePing=t.enablePing,this.enableReconnect=t.enableReconnect||!1}static async connect(e,t){const n=new Eo(e,t);return await n.connect(),n}closeAllSubscriptions(e){for(let[t,n]of this.openSubs)n.close(e);this.openSubs.clear();for(let[t,n]of this.openEventPublishes)n.reject(new Error(e));this.openEventPublishes.clear();for(let[t,n]of this.openCountRequests)n.reject(new Error(e));this.openCountRequests.clear()}get connected(){return this._connected}async reconnect(){const e=this.resubscribeBackoff[Math.min(this.reconnectAttempts,this.resubscribeBackoff.length-1)];this.reconnectAttempts++,this.reconnectTimeoutHandle=setTimeout(async()=>{try{await this.connect()}catch(e){}},e)}handleHardClose(e){this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0;const t=this.closedIntentionally;this.closedIntentionally=!1,this.onclose?.(),this.enableReconnect&&!t?this.reconnect():this.closeAllSubscriptions(e)}async connect(){return this.connectionPromise||(this.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise((e,t)=>{this.connectionTimeoutHandle=setTimeout(()=>{t("connection timed out"),this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(e){return clearTimeout(this.connectionTimeoutHandle),void t(e)}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(this.connectionTimeoutHandle),this._connected=!0;const t=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const e of this.openSubs.values()){if(e.eosed=!1,t)for(let t=0;t<e.filters.length;t++)e.lastEmitted&&(e.filters[t].since=e.lastEmitted+1);e.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),e()},this.ws.onerror=e=>{clearTimeout(this.connectionTimeoutHandle),t(e.message||"websocket error"),this.handleHardClose("relay connection errored")},this.ws.onclose=e=>{clearTimeout(this.connectionTimeoutHandle),t(e.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)})),this.connectionPromise}waitForPingPong(){return new Promise(e=>{this.ws.once("pong",()=>e(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((e,t)=>{if(!this.connectionPromise)return t(new Error(`no connection to ${this.url}, can't ping`));try{const t=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"forced-ping",oneose:()=>{e(!0),t.close()},onclose(){e(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(e){t(e)}})}async pingpong(){1===this.ws?.readyState&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.once?this.waitForPingPong():this.waitForDummyReq(),new Promise(e=>setTimeout(()=>e(!1),this.pingTimeout))])||this.ws?.readyState===this._WebSocket.OPEN&&this.ws?.close())}async runQueue(){for(this.queueRunning=!0;!1!==this.handleNext();)await vo();this.queueRunning=!1}handleNext(){const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const t=go(e);if(t){const n=this.openSubs.get(t);if(!n)return;const r=fo(e,"id"),s=n.alreadyHaveEvent?.(r);if(n.receivedEvent?.(this,r),s)return}try{let t=JSON.parse(e);switch(t[0]){case"EVENT":{const e=this.openSubs.get(t[1]),n=t[2];return this.verifyEvent(n)&&function(e,t){for(let n=0;n<e.length;n++)if(ho(e[n],t))return!0;return!1}(e.filters,n)&&e.onevent(n),void((!e.lastEmitted||e.lastEmitted<n.created_at)&&(e.lastEmitted=n.created_at))}case"COUNT":{const e=t[1],n=t[2],r=this.openCountRequests.get(e);return void(r&&(r.resolve(n.count),this.openCountRequests.delete(e)))}case"EOSE":{const e=this.openSubs.get(t[1]);if(!e)return;return void e.receivedEose()}case"OK":{const e=t[1],n=t[2],r=t[3],s=this.openEventPublishes.get(e);return void(s&&(clearTimeout(s.timeout),n?s.resolve(r):s.reject(new Error(r)),this.openEventPublishes.delete(e)))}case"CLOSED":{const e=t[1],n=this.openSubs.get(e);if(!n)return;return n.closed=!0,void n.close(t[2])}case"NOTICE":return void this.onnotice(t[1]);case"AUTH":return this.challenge=t[1],void(this.onauth&&this.auth(this.onauth));default:{const e=this.openSubs.get(t[1]);return void e?.oncustom?.(t)}}}catch(e){return}}async send(e){if(!this.connectionPromise)throw new xo(e,this.url);this.connectionPromise.then(()=>{this.ws?.send(e)})}async auth(e){const t=this.challenge;if(!t)throw new Error("can't perform auth, no challenge was received");return this.authPromise||(this.authPromise=new Promise(async(n,r)=>{try{let s=await e(mo(this.url,t)),o=setTimeout(()=>{let e=this.openEventPublishes.get(s.id);e&&(e.reject(new Error("auth timed out")),this.openEventPublishes.delete(s.id))},this.publishTimeout);this.openEventPublishes.set(s.id,{resolve:n,reject:r,timeout:o}),this.send('["AUTH",'+JSON.stringify(s)+"]")}catch(e){console.warn("subscribe auth function failed:",e)}})),this.authPromise}async publish(e){const t=new Promise((t,n)=>{const r=setTimeout(()=>{const t=this.openEventPublishes.get(e.id);t&&(t.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:t,reject:n,timeout:r})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),t}async count(e,t){this.serial++;const n=t?.id||"count:"+this.serial,r=new Promise((e,t)=>{this.openCountRequests.set(n,{resolve:e,reject:t})});return this.send('["COUNT","'+n+'",'+JSON.stringify(e).substring(1)),r}subscribe(e,t){const n=this.prepareSubscription(e,t);return n.fire(),n}prepareSubscription(e,t){this.serial++;const n=t.id||(t.label?t.label+":":"sub:")+this.serial,r=new So(this,n,e,t);return this.openSubs.set(n,r),r}close(){this.closedIntentionally=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,this.onclose?.(),this.ws?.readyState===this._WebSocket.OPEN&&this.ws?.close()}_onmessage(e){this.incomingMessageQueue.enqueue(e.data),this.queueRunning||this.runQueue()}},So=class{relay;id;lastEmitted;closed=!1;eosed=!1;filters;alreadyHaveEvent;receivedEvent;onevent;oneose;onclose;oncustom;eoseTimeout;eoseTimeoutHandle;constructor(e,t,n,r){if(0===n.length)throw new Error("subscription can't be created with zero filters");this.relay=e,this.filters=n,this.id=t,this.alreadyHaveEvent=r.alreadyHaveEvent,this.receivedEvent=r.receivedEvent,this.eoseTimeout=r.eoseTimeout||e.baseEoseTimeout,this.oneose=r.oneose,this.onclose=r.onclose,this.onevent=r.onevent||(e=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,e)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,this.oneose?.())}close(e="closed by caller"){if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(e){if(!(e instanceof xo))throw e}this.closed=!0}this.relay.openSubs.delete(this.id),this.onclose?.(e)}};try{WebSocket}catch{}var Ao,To=class{relays=new Map;seenOn=new Map;trackRelays=!1;verifyEvent;enablePing;enableReconnect;automaticallyAuth;trustedRelayURLs=new Set;_WebSocket;constructor(e){this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation,this.enablePing=e.enablePing,this.enableReconnect=e.enableReconnect||!1,this.automaticallyAuth=e.automaticallyAuth}async ensureRelay(e,t){e=cr(e);let n=this.relays.get(e);if(n||(n=new Eo(e,{verifyEvent:this.trustedRelayURLs.has(e)?ko:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),n.onclose=()=>{n&&!n.enableReconnect&&this.relays.delete(e)},t?.connectionTimeout&&(n.connectionTimeout=t.connectionTimeout),this.relays.set(e,n)),this.automaticallyAuth){const t=this.automaticallyAuth(e);t&&(n.onauth=t)}return await n.connect(),n}close(e){e.map(cr).forEach(e=>{this.relays.get(e)?.close(),this.relays.delete(e)})}subscribe(e,t,n){const r=[];for(let n=0;n<e.length;n++){const s=cr(e[n]);r.find(e=>e.url===s)||r.push({url:s,filter:t})}return this.subscribeMap(r,n)}subscribeMany(e,t,n){const r=[],s=[];for(let n=0;n<e.length;n++){const o=cr(e[n]);-1===s.indexOf(o)&&(s.push(o),r.push({url:o,filter:t}))}return this.subscribeMap(r,n)}subscribeMap(e,t){const n=new Map;for(const t of e){const{url:e,filter:r}=t;n.has(e)||n.set(e,[]),n.get(e).push(r)}const r=Array.from(n.entries()).map(([e,t])=>({url:e,filters:t}));this.trackRelays&&(t.receivedEvent=(e,t)=>{let n=this.seenOn.get(t);n||(n=new Set,this.seenOn.set(t,n)),n.add(e)});const s=new Set,o=[],i=[];let a=e=>{i[e]||(i[e]=!0,i.filter(e=>e).length===r.length&&(t.oneose?.(),a=()=>{}))};const l=[];let c=(e,n)=>{l[e]||(a(e),l[e]=n,l.filter(e=>e).length===r.length&&(t.onclose?.(l),c=()=>{}))};const u=e=>{if(t.alreadyHaveEvent?.(e))return!0;const n=s.has(e);return s.add(e),n},h=Promise.all(r.map(async({url:e,filters:n},r)=>{let s;try{s=await this.ensureRelay(e,{connectionTimeout:t.maxWait?Math.max(.8*t.maxWait,t.maxWait-1e3):void 0})}catch(e){return void c(r,e?.message||String(e))}let i=s.subscribe(n,{...t,oneose:()=>a(r),onclose:e=>{e.startsWith("auth-required: ")&&t.onauth?s.auth(t.onauth).then(()=>{s.subscribe(n,{...t,oneose:()=>a(r),onclose:e=>{c(r,e)},alreadyHaveEvent:u,eoseTimeout:t.maxWait})}).catch(e=>{c(r,`auth was required and attempted, but failed with: ${e}`)}):c(r,e)},alreadyHaveEvent:u,eoseTimeout:t.maxWait});o.push(i)}));return{async close(e){await h,o.forEach(t=>{t.close(e)})}}}subscribeEose(e,t,n){const r=this.subscribe(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}subscribeManyEose(e,t,n){const r=this.subscribeMany(e,t,{...n,oneose(){r.close("closed automatically on eose")}});return r}async querySync(e,t,n){return new Promise(async r=>{const s=[];this.subscribeEose(e,t,{...n,onevent(e){s.push(e)},onclose(e){r(s)}})})}async get(e,t,n){t.limit=1;const r=await this.querySync(e,t,n);return r.sort((e,t)=>t.created_at-e.created_at),r[0]||null}publish(e,t,n){return e.map(cr).map(async(e,r,s)=>{if(s.indexOf(e)!==r)return Promise.reject("duplicate url");let o=await this.ensureRelay(e);return o.publish(t).catch(async e=>{if(e instanceof Error&&e.message.startsWith("auth-required: ")&&n?.onauth)return await o.auth(n.onauth),o.publish(t);throw e}).then(e=>{if(this.trackRelays){let e=this.seenOn.get(t.id);e||(e=new Set,this.seenOn.set(t.id,e)),e.add(o)}return e})})}listConnectionStatus(){const e=new Map;return this.relays.forEach((t,n)=>e.set(n,t.connected)),e}destroy(){this.relays.forEach(e=>e.close()),this.relays=new Map}};try{Ao=WebSocket}catch{}var $o=class extends To{constructor(e){super({verifyEvent:vr,websocketImplementation:Ao,...e})}},Ro={};sr(Ro,{BECH32_REGEX:()=>Lo,Bech32MaxSize:()=>Bo,NostrTypeGuard:()=>Io,decode:()=>Po,decodeNostrURI:()=>_o,encodeBytes:()=>qo,naddrEncode:()=>jo,neventEncode:()=>Ho,noteEncode:()=>Oo,nprofileEncode:()=>Mo,npubEncode:()=>No,nsecEncode:()=>Uo});var Io={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Bo=5e3,Lo=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function _o(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),Po(e)}catch(e){return{type:"invalid",data:null}}}function Po(e){let{prefix:t,words:n}=Bt.decode(e,Bo),r=new Uint8Array(Bt.fromWords(n));switch(t){case"nprofile":{let e=Co(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nprofile");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:Ve(e[0][0]),relays:e[1]?e[1].map(e=>ar.decode(e)):[]}}}case"nevent":{let e=Co(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for nevent");if(32!==e[0][0].length)throw new Error("TLV 0 should be 32 bytes");if(e[2]&&32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(e[3]&&4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:Ve(e[0][0]),relays:e[1]?e[1].map(e=>ar.decode(e)):[],author:e[2]?.[0]?Ve(e[2][0]):void 0,kind:e[3]?.[0]?parseInt(Ve(e[3][0]),16):void 0}}}case"naddr":{let e=Co(r);if(!e[0]?.[0])throw new Error("missing TLV 0 for naddr");if(!e[2]?.[0])throw new Error("missing TLV 2 for naddr");if(32!==e[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(!e[3]?.[0])throw new Error("missing TLV 3 for naddr");if(4!==e[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:ar.decode(e[0][0]),pubkey:Ve(e[2][0]),kind:parseInt(Ve(e[3][0]),16),relays:e[1]?e[1].map(e=>ar.decode(e)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:Ve(r)};default:throw new Error(`unknown prefix ${t}`)}}function Co(e){let t={},n=e;for(;n.length>0;){let e=n[0],r=n[1],s=n.slice(2,2+r);if(n=n.slice(2+r),s.length<r)throw new Error(`not enough data to read on TLV ${e}`);t[e]=t[e]||[],t[e].push(s)}return t}function Uo(e){return qo("nsec",e)}function No(e){return qo("npub",We(e))}function Oo(e){return qo("note",We(e))}function zo(e,t){let n=Bt.toWords(t);return Bt.encode(e,n,Bo)}function qo(e,t){return zo(e,t)}function Mo(e){return zo("nprofile",Do({0:[We(e.pubkey)],1:(e.relays||[]).map(e=>lr.encode(e))}))}function Ho(e){let t;return void 0!==e.kind&&(t=function(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=255&e,t}(e.kind)),zo("nevent",Do({0:[We(e.id)],1:(e.relays||[]).map(e=>lr.encode(e)),2:e.author?[We(e.author)]:[],3:t?[new Uint8Array(t)]:[]}))}function jo(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,e.kind,!1),zo("naddr",Do({0:[lr.encode(e.identifier)],1:(e.relays||[]).map(e=>lr.encode(e)),2:[We(e.pubkey)],3:[new Uint8Array(t)]}))}function Do(e){let t=[];return Object.entries(e).reverse().forEach(([e,n])=>{n.forEach(n=>{let r=new Uint8Array(n.length+2);r.set([parseInt(e)],0),r.set([n.length],1),r.set(n,2),t.push(r)})}),Ke(...t)}function Fo(e,t,n){const r=e instanceof Uint8Array?Ve(e):e,s=Wo(Ee.getSharedSecret(r,"02"+t));let o=Uint8Array.from(Je(16)),i=lr.encode(n),a=In(s,o).encrypt(i);return`${Et.encode(new Uint8Array(a))}?iv=${Et.encode(new Uint8Array(o.buffer))}`}function Vo(e,t,n){const r=e instanceof Uint8Array?Ve(e):e;let[s,o]=n.split("?iv="),i=Wo(Ee.getSharedSecret(r,"02"+t)),a=Et.decode(o),l=Et.decode(s),c=In(i,a).decrypt(l);return ar.decode(c)}function Wo(e){return e.slice(1,33)}sr({},{decrypt:()=>Vo,encrypt:()=>Fo}),sr({},{NIP05_REGEX:()=>Ko,isNip05:()=>Yo,isValid:()=>Xo,queryProfile:()=>Qo,searchDomain:()=>Jo,useFetchImplementation:()=>Go});var Zo,Ko=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,Yo=e=>Ko.test(e||"");try{Zo=fetch}catch(e){}function Go(e){Zo=e}async function Jo(e,t=""){try{const n=`https://${e}/.well-known/nostr.json?name=${t}`,r=await Zo(n,{redirect:"manual"});if(200!==r.status)throw Error("Wrong response code");return(await r.json()).names}catch(e){return{}}}async function Qo(e){const t=e.match(Ko);if(!t)return null;const[,n="_",r]=t;try{const e=`https://${r}/.well-known/nostr.json?name=${n}`,t=await Zo(e,{redirect:"manual"});if(200!==t.status)throw Error("Wrong response code");const s=await t.json(),o=s.names[n];return o?{pubkey:o,relays:s.relays?.[o]}:null}catch(e){return null}}async function Xo(e,t){const n=await Qo(t);return!!n&&n.pubkey===e}function ei(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let s=e.tags.length-1;s>=0;s--){const o=e.tags[s];if("e"===o[0]&&o[1]){const[e,s,i,a,l]=o,c={id:s,relays:i?[i]:[],author:l};if("root"===a){t.root=c;continue}if("reply"===a){t.reply=c;continue}if("mention"===a){t.mentions.push(c);continue}n?r=c:n=c,t.mentions.push(c);continue}if("q"===o[0]&&o[1]){const[e,n,r]=o;t.quotes.push({id:n,relays:r?[r]:[]})}"p"===o[0]&&o[1]&&t.profiles.push({pubkey:o[1],relays:o[2]?[o[2]]:[]})}return t.root||(t.root=r||n||t.reply),t.reply||(t.reply=n||t.root),[t.reply,t.root].forEach(e=>{if(!e)return;let n=t.mentions.indexOf(e);if(-1!==n&&t.mentions.splice(n,1),e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays?.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t.mentions.forEach(e=>{if(e.author){let n=t.profiles.find(t=>t.pubkey===e.author);n&&n.relays&&(e.relays||(e.relays=[]),n.relays.forEach(t=>{-1===e.relays.indexOf(t)&&e.relays.push(t)}),n.relays=e.relays)}}),t}sr({},{parse:()=>ei}),sr({},{fetchRelayInformation:()=>ni,useFetchImplementation:()=>ti});try{fetch}catch{}function ti(e){}async function ni(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}function ri(e){let t=0;for(let n=0;n<64;n+=8){const r=parseInt(e.substring(n,n+8),16);if(0!==r){t+=Math.clz32(r);break}t+=32}return t}function si(e,t){let n=0;const r=e,s=["nonce",n.toString(),t.toString()];for(r.tags.push(s);;){const e=Math.floor((new Date).getTime()/1e3);if(e!==r.created_at&&(n=0,r.created_at=e),s[1]=(++n).toString(),r.id=oi(r),ri(r.id)>=t)break}return r}function oi(e){return Ve(ut(lr.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}function ii(e,t){const n=Ee.getSharedSecret(e,"02"+t).subarray(1,33);return r=ut,s=n,o="nip44-v2",tt.hash(r),void 0===o&&(o=new Uint8Array(r.outputLen)),er(r,Ze(o),Ze(s));var r,s,o}function ai(e,t){const n=function(e,t,n,r=32){if(tt.hash(e),tt.number(r),r>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const s=Math.ceil(r/e.outputLen);void 0===n&&(n=nr);const o=new Uint8Array(s*e.outputLen),i=er.create(e,t),a=i._cloneInto(),l=new Uint8Array(i.outputLen);for(let t=0;t<s;t++)tr[0]=t+1,a.update(0===t?nr:l).update(n).update(tr).digestInto(l),o.set(l,e.outputLen*t),i._cloneInto(a);return i.destroy(),a.destroy(),l.fill(0),tr.fill(0),o.slice(0,r)}(ut,e,t,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function li(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,n=t<=256?32:t/8;return n*(Math.floor((e-1)/n)+1)}function ci(e,t,n){if(32!==n.length)throw new Error("AAD associated data must be 32 bytes");const r=Ke(n,t);return er(ut,e,r)}function ui(e,t,n=Je(32)){const{chacha_key:r,chacha_nonce:s,hmac_key:o}=ai(t,n),i=function(e){const t=lr.encode(e),n=t.length;return Ke(function(e){if(!Number.isSafeInteger(e)||e<1||e>65535)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}(n),t,new Uint8Array(li(n)-n))}(e),a=Wn(r,s,i),l=ci(o,a,n);return Et.encode(Ke(new Uint8Array([2]),n,a,l))}function hi(e,t){const{nonce:n,ciphertext:r,mac:s}=function(e){if("string"!=typeof e)throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if("#"===e[0])throw new Error("unknown encryption version");let n;try{n=Et.decode(e)}catch(e){throw new Error("invalid base64: "+e.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const s=n[0];if(2!==s)throw new Error("unknown encryption version "+s);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}(e),{chacha_key:o,chacha_nonce:i,hmac_key:a}=ai(t,n);if(!Vt(ci(a,r,n),s))throw new Error("invalid MAC");return function(e){const t=new DataView(e.buffer).getUint16(0),n=e.subarray(2,2+t);if(t<1||t>65535||n.length!==t||e.length!==2+li(t))throw new Error("invalid padding");return ar.decode(n)}(Wn(o,i,r))}sr({},{fastEventHash:()=>oi,getPow:()=>ri,minePow:()=>si}),sr({},{unwrapEvent:()=>$i,unwrapManyEvents:()=>Ri,wrapEvent:()=>Ai,wrapManyEvents:()=>Ti}),sr({},{createRumor:()=>yi,createSeal:()=>mi,createWrap:()=>vi,unwrapEvent:()=>Ei,unwrapManyEvents:()=>Si,wrapEvent:()=>ki,wrapManyEvents:()=>xi}),sr({},{decrypt:()=>hi,encrypt:()=>ui,getConversationKey:()=>ii,v2:()=>di});var di={utils:{getConversationKey:ii,calcPaddedLen:li},encrypt:ui,decrypt:hi},fi=()=>Math.round(Date.now()/1e3),pi=()=>Math.round(fi()-172800*Math.random()),gi=(e,t)=>ii(e,t),wi=(e,t,n)=>ui(JSON.stringify(e),gi(t,n)),bi=(e,t)=>JSON.parse(hi(e.content,gi(t,e.pubkey)));function yi(e,t){const n={created_at:fi(),content:"",tags:[],...e,pubkey:yr(t)};return n.id=gr(n),n}function mi(e,t,n){return mr({kind:zr,content:wi(e,t,n),created_at:pi(),tags:[]},t)}function vi(e,t){const n=br();return mr({kind:Jr,content:wi(e,n,t),created_at:pi(),tags:[["p",t]]},n)}function ki(e,t,n){return vi(mi(yi(e,t),t,n),n)}function xi(e,t,n){if(!n||0===n.length)throw new Error("At least one recipient is required.");const r=yr(t),s=[ki(e,t,r)];return n.forEach(n=>{s.push(ki(e,t,n))}),s}function Ei(e,t){const n=bi(e,t);return bi(n,t)}function Si(e,t){let n=[];return e.forEach(e=>{n.push(Ei(e,t))}),n.sort((e,t)=>e.created_at-t.created_at),n}function Ai(e,t,n,r,s){const o=function(e,t,n,r){const s={created_at:Math.ceil(Date.now()/1e3),kind:qr,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:e,relayUrl:t})=>{s.tags.push(t?["p",e,t]:["p",e])}),r&&s.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&s.tags.push(["subject",n]),s}(t,n,r,s);return ki(o,e,t.publicKey)}function Ti(e,t,n,r,s){if(!t||0===t.length)throw new Error("At least one recipient is required.");return[{publicKey:yr(e)},...t].map(t=>Ai(e,t,n,r,s))}var $i=Ei,Ri=Si;function Ii(e,t,n,r){let s;const o=[...e.tags??[],["e",t.id,n],["p",t.pubkey]];return t.kind===Rr?s=Pr:(s=Hr,o.push(["k",String(t.kind)])),mr({kind:s,tags:o,content:""===e.content||t.tags?.find(e=>"-"===e[0])?"":JSON.stringify(t),created_at:e.created_at},r)}function Bi(e){if(![Pr,Hr].includes(e.kind))return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const s=e.tags[r];s.length>=2&&("e"===s[0]&&void 0===t?t=s:"p"===s[0]&&void 0===n&&(n=s))}return void 0!==t?{id:t[1],relays:[t[2],n?.[2]].filter(e=>"string"==typeof e),author:n?.[1]}:void 0}function Li(e,{skipVerification:t}={}){const n=Bi(e);if(void 0===n||""===e.content)return;let r;try{r=JSON.parse(e.content)}catch(e){return}return r.id===n.id&&(t||vr(r))?r:void 0}sr({},{finishRepostEvent:()=>Ii,getRepostedEvent:()=>Li,getRepostedEventPointer:()=>Bi}),sr({},{NOSTR_URI_REGEX:()=>_i,parse:()=>Ci,test:()=>Pi});var _i=new RegExp(`nostr:(${Lo.source})`);function Pi(e){return"string"==typeof e&&new RegExp(`^${_i.source}$`).test(e)}function Ci(e){const t=e.match(new RegExp(`^${_i.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:Po(t[1])}}function Ui(e,t,n){const r=t.tags.filter(e=>e.length>=2&&("e"===e[0]||"p"===e[0]));return mr({...e,kind:Cr,tags:[...e.tags??[],...r,["e",t.id],["p",t.pubkey]],content:e.content??"+"},n)}function Ni(e){if(e.kind!==Cr)return;let t,n;for(let r=e.tags.length-1;r>=0&&(void 0===t||void 0===n);r--){const s=e.tags[r];s.length>=2&&("e"===s[0]&&void 0===t?t=s:"p"===s[0]&&void 0===n&&(n=s))}return void 0!==t&&void 0!==n?{id:t[1],relays:[t[2],n[2]].filter(e=>void 0!==e),author:n[1]}:void 0}sr({},{finishReactionEvent:()=>Ui,getReactedEventPointer:()=>Ni}),sr({},{parse:()=>qi});var Oi=/\W/m,zi=/[^\w\/] |[^\w\/]$|$|,| /m;function*qi(e){let t=[];if("string"!=typeof e){for(let n=0;n<e.tags.length;n++){const r=e.tags[n];"emoji"===r[0]&&r.length>=3&&t.push({type:"emoji",shortcode:r[1],url:r[2]})}e=e.content}const n=e.length;let r=0,s=0;e:for(;s<n;){const o=e.indexOf(":",s),i=e.indexOf("#",s);if(-1===o&&-1===i)break e;if(-1===o||i>=0&&i<o){if(0===i||" "===e[i-1]){const t=e.slice(i+1,i+42).match(Oi),o=t?i+1+t.index:n;yield{type:"text",text:e.slice(r,i)},yield{type:"hashtag",value:e.slice(i+1,o)},s=o,r=s;continue e}s=i+1}else if("nostr"===e.slice(o-5,o)){const t=e.slice(o+60).match(Oi),i=t?o+60+t.index:n;try{let t,{data:n,type:a}=Po(e.slice(o+1,i));switch(a){case"npub":t={pubkey:n};break;case"note":t={id:n};break;case"nsec":s=i+1;continue;default:t=n}r!==o-5&&(yield{type:"text",text:e.slice(r,o-5)}),yield{type:"reference",pointer:t},s=i,r=s;continue e}catch(e){s=o+1;continue e}}else if("https"===e.slice(o-5,o)||"http"===e.slice(o-4,o)){const t=e.slice(o+4).match(zi),i=t?o+4+t.index:n,a="s"===e[o-1]?5:4;try{let t=new URL(e.slice(o-a,i));if(-1===t.hostname.indexOf("."))throw new Error("invalid url");if(r!==o-a&&(yield{type:"text",text:e.slice(r,o-a)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(t.pathname)){yield{type:"image",url:t.toString()},s=i,r=s;continue e}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(t.pathname)){yield{type:"video",url:t.toString()},s=i,r=s;continue e}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(t.pathname)){yield{type:"audio",url:t.toString()},s=i,r=s;continue e}yield{type:"url",url:t.toString()},s=i,r=s;continue e}catch(e){s=i+1;continue e}}else{if("wss"!==e.slice(o-3,o)&&"ws"!==e.slice(o-2,o)){for(let n=0;n<t.length;n++){const i=t[n];if(":"===e[o+i.shortcode.length+1]&&e.slice(o+1,o+i.shortcode.length+1)===i.shortcode){r!==o&&(yield{type:"text",text:e.slice(r,o)}),yield i,s=o+i.shortcode.length+2,r=s;continue e}}s=o+1;continue e}{const t=e.slice(o+4).match(zi),i=t?o+4+t.index:n,a="s"===e[o-1]?3:2;try{let t=new URL(e.slice(o-a,i));if(-1===t.hostname.indexOf("."))throw new Error("invalid ws url");r!==o-a&&(yield{type:"text",text:e.slice(r,o-a)}),yield{type:"relay",url:t.toString()},s=i,r=s;continue e}catch(e){s=i+1;continue e}}}}r!==n&&(yield{type:"text",text:e.slice(r)})}sr({},{channelCreateEvent:()=>Mi,channelHideMessageEvent:()=>Di,channelMessageEvent:()=>ji,channelMetadataEvent:()=>Hi,channelMuteUserEvent:()=>Fi});var Mi=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return mr({kind:Vr,tags:[...e.tags??[]],content:n,created_at:e.created_at},t)},Hi=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return mr({kind:Wr,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},ji=(e,t)=>{const n=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&n.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),mr({kind:Zr,tags:[...n,...e.tags??[]],content:e.content,created_at:e.created_at},t)},Di=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return mr({kind:Kr,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:n,created_at:e.created_at},t)},Fi=(e,t)=>{let n;if("object"==typeof e.content)n=JSON.stringify(e.content);else{if("string"!=typeof e.content)return;n=e.content}return mr({kind:Yr,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:n,created_at:e.created_at},t)};sr({},{EMOJI_SHORTCODE_REGEX:()=>Zi,matchAll:()=>Yi,regex:()=>Ki,replaceAll:()=>Gi});var Vi,Wi,Zi=/:(\w+):/,Ki=()=>new RegExp(`\\B${Zi.source}\\B`,"g");function*Yi(e){const t=e.matchAll(Ki());for(const e of t)try{const[t,n]=e;yield{shortcode:t,name:n,start:e.index,end:e.index+t.length}}catch(e){}}function Gi(e,t){return e.replaceAll(Ki(),(e,n)=>t({shortcode:e,name:n}))}sr({},{useFetchImplementation:()=>Ji,validateGithub:()=>Qi});try{Vi=fetch}catch{}function Ji(e){Vi=e}async function Qi(e,t,n){try{return await(await Vi(`https://gist.github.com/${t}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch(e){return!1}}function Xi(e){const{host:t,pathname:n,searchParams:r}=new URL(e),s=n||t,o=r.get("relay"),i=r.get("secret");if(!s||!o||!i)throw new Error("invalid connection string");return{pubkey:s,relay:o,secret:i}}async function ea(e,t,n){const r={method:"pay_invoice",params:{invoice:n}},s=Fo(t,e,JSON.stringify(r)),o={kind:Cs,created_at:Math.round(Date.now()/1e3),content:s,tags:[["p",e]]};return mr(o,t)}function ta(e){return e=(e=e.trim().toLowerCase()).normalize("NFKC"),Array.from(e).map(e=>/\p{Letter}/u.test(e)||/\p{Number}/u.test(e)?e:"-").join("")}sr({},{makeNwcRequestEvent:()=>ea,parseConnectionString:()=>Xi}),sr({},{normalizeIdentifier:()=>ta}),sr({},{getSatoshisAmountFromBolt11:()=>aa,getZapEndpoint:()=>ra,makeZapReceipt:()=>ia,makeZapRequest:()=>sa,useFetchImplementation:()=>na,validateZapRequest:()=>oa});try{Wi=fetch}catch{}function na(e){Wi=e}async function ra(e){try{let t="",{lud06:n,lud16:r}=JSON.parse(e.content);if(r){let[e,n]=r.split("@");t=new URL(`/.well-known/lnurlp/${e}`,`https://${n}`).toString()}else{if(!n)return null;{let{words:e}=Bt.decode(n,1e3),r=Bt.fromWords(e);t=ar.decode(r)}}let s=await Wi(t),o=await s.json();if(o.allowsNostr&&o.nostrPubkey)return o.callback}catch(e){}return null}function sa(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),xr(e.event.kind)){const n=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(n)}else if(Sr(e.event.kind)){let n=e.event.tags.find(([e,t])=>"d"===e&&t);if(!n)throw new Error("d tag not found or is empty");const r=["a",`${e.event.kind}:${e.event.pubkey}:${n[1]}`];t.tags.push(r)}t.tags.push(["k",e.event.kind.toString()])}return t}function oa(e){let t;try{t=JSON.parse(e)}catch(e){return"Invalid zap request JSON."}if(!ir(t))return"Zap request is not a valid Nostr event.";if(!vr(t))return"Invalid signature on zap request.";let n=t.tags.find(([e,t])=>"p"===e&&t);if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=t.tags.find(([e,t])=>"e"===e&&t);if(r&&!r[1].match(/^[a-f0-9]{64}$/))return"Zap request 'e' tag is not valid hex.";let s=t.tags.find(([e,t])=>"relays"===e&&t);return s?null:"Zap request doesn't have a 'relays' tag."}function ia({zapRequest:e,preimage:t,bolt11:n,paidAt:r}){let s=JSON.parse(e),o=s.tags.filter(([e])=>"e"===e||"p"===e||"a"===e),i={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...o,["P",s.pubkey],["bolt11",n],["description",e]]};return t&&i.tags.push(["preimage",t]),i}function aa(e){if(e.length<50)return 0;const t=(e=e.substring(0,50)).lastIndexOf("1");if(-1===t)return 0;const n=e.substring(0,t);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const s=r[r.length-1],o=s.charCodeAt(0)-"0".charCodeAt(0),i=o>=0&&o<=9;let a=r.length-1;if(i&&a++,a<1)return 0;const l=parseInt(r.substring(0,a));switch(s){case"m":return 1e5*l;case"u":return 100*l;case"n":return l/10;case"p":return l/1e4;default:return 1e8*l}}sr({},{Negentropy:()=>ga,NegentropyStorageVector:()=>pa,NegentropySync:()=>ya});var la=32,ca=class{_raw;length;constructor(e){"number"==typeof e?(this._raw=new Uint8Array(e),this.length=0):e instanceof Uint8Array?(this._raw=new Uint8Array(e),this.length=e.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(e){if(e instanceof ca&&(e=e.unwrap()),"number"!=typeof e.length)throw Error("bad length");const t=e.length+this.length;if(this.capacity<t){const e=this._raw,n=Math.max(2*this.capacity,t);this._raw=new Uint8Array(n),this._raw.set(e)}this._raw.set(e,this.length),this.length+=e.length}shift(){const e=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,e}shiftN(e=1){const t=this._raw.subarray(0,e);return this._raw=this._raw.subarray(e),this.length-=e,t}};function ua(e){let t=0;for(;;){if(0===e.length)throw Error("parse ends prematurely");let n=e.shift();if(t=t<<7|127&n,!(128&n))break}return t}function ha(e){if(0===e)return new ca(new Uint8Array([0]));let t=[];for(;0!==e;)t.push(127&e),e>>>=7;t.reverse();for(let e=0;e<t.length-1;e++)t[e]|=128;return new ca(new Uint8Array(t))}function da(e,t){if(e.length<t)throw Error("parse ends prematurely");return e.shiftN(t)}var fa=class{buf;constructor(){this.setToZero()}setToZero(){this.buf=new Uint8Array(la)}add(e){let t=0,n=0,r=new DataView(this.buf.buffer),s=new DataView(e.buffer);for(let e=0;e<8;e++){let o=4*e,i=r.getUint32(o,!0);i+=t,i+=s.getUint32(o,!0),i>4294967295&&(n=1),r.setUint32(o,4294967295&i,!0),t=n,n=0}}negate(){let e=new DataView(this.buf.buffer);for(let t=0;t<8;t++){let n=4*t;e.setUint32(n,~e.getUint32(n,!0))}let t=new Uint8Array(la);t[0]=1,this.add(t)}getFingerprint(e){let t=new ca;return t.extend(this.buf),t.extend(ha(e)),ut(t.unwrap()).subarray(0,16)}},pa=class{items;sealed;constructor(){this.items=[],this.sealed=!1}insert(e,t){if(this.sealed)throw Error("already sealed");const n=Dt(t);if(n.byteLength!==la)throw Error("bad id size for added item");this.items.push({timestamp:e,id:n})}seal(){if(this.sealed)throw Error("already sealed");this.sealed=!0,this.items.sort(ba);for(let e=1;e<this.items.length;e++)if(0===ba(this.items[e-1],this.items[e]))throw Error("duplicate item inserted")}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(e){if(this._checkSealed(),e>=this.items.length)throw Error("out of range");return this.items[e]}iterate(e,t,n){this._checkSealed(),this._checkBounds(e,t);for(let r=e;r<t&&n(this.items[r],r);++r);}findLowerBound(e,t,n){return this._checkSealed(),this._checkBounds(e,t),this._binarySearch(this.items,e,t,e=>ba(e,n)<0)}fingerprint(e,t){let n=new fa;return n.setToZero(),this.iterate(e,t,e=>(n.add(e.id),!0)),n.getFingerprint(t-e)}_checkSealed(){if(!this.sealed)throw Error("not sealed")}_checkBounds(e,t){if(e>t||t>this.items.length)throw Error("bad range")}_binarySearch(e,t,n,r){let s=n-t;for(;s>0;){let n=t,o=Math.floor(s/2);n+=o,r(e[n])?(t=++n,s-=o+1):s=o}return t}},ga=class{storage;frameSizeLimit;lastTimestampIn;lastTimestampOut;constructor(e,t=6e4){if(t<4096)throw Error("frameSizeLimit too small");this.storage=e,this.frameSizeLimit=t,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(e,t){return{timestamp:e,id:t||new Uint8Array(0)}}initiate(){let e=new ca;return e.extend(new Uint8Array([97])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),e),Ht(e.unwrap())}reconcile(e,t,n){const r=new ca(Dt(e));this.lastTimestampIn=this.lastTimestampOut=0;let s=new ca;s.extend(new Uint8Array([97]));let o=da(r,1)[0];if(o<96||o>111)throw Error("invalid negentropy protocol version byte");if(97!==o)throw Error("unsupported negentropy protocol version requested: "+(o-96));let i=this.storage.size(),a=this._bound(0),l=0,c=!1;for(;0!==r.length;){let e=new ca,o=()=>{c&&(c=!1,e.extend(this.encodeBound(a)),e.extend(ha(0)))},u=this.decodeBound(r),h=ua(r),d=l,f=this.storage.findLowerBound(l,i,u);if(0===h)c=!0;else if(1===h)0!==wa(da(r,16),this.storage.fingerprint(d,f))?(o(),this.splitRange(d,f,u,e)):c=!0;else{if(2!==h)throw Error("unexpected mode");{let e=ua(r),s={};for(let t=0;t<e;t++){let e=da(r,la);s[Ht(e)]=e}if(c=!0,this.storage.iterate(d,f,e=>{let n=e.id;const r=Ht(n);return s[r]?delete s[Ht(n)]:t?.(r),!0}),n)for(let e of Object.values(s))n(Ht(e))}}if(this.exceededFrameSizeLimit(s.length+e.length)){let e=this.storage.fingerprint(f,i);s.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),s.extend(ha(1)),s.extend(e);break}s.extend(e),l=f,a=u}return 1===s.length?null:Ht(s.unwrap())}splitRange(e,t,n,r){let s=t-e;if(s<32)r.extend(this.encodeBound(n)),r.extend(ha(2)),r.extend(ha(s)),this.storage.iterate(e,t,e=>(r.extend(e.id),!0));else{let o=Math.floor(s/16),i=s%16,a=e;for(let e=0;e<16;e++){let s,l=o+(e<i?1:0),c=this.storage.fingerprint(a,a+l);if(a+=l,a===t)s=n;else{let e,t;this.storage.iterate(a-1,a+1,(n,r)=>(r===a-1?e=n:t=n,!0)),s=this.getMinimalBound(e,t)}r.extend(this.encodeBound(s)),r.extend(ha(1)),r.extend(c)}}}exceededFrameSizeLimit(e){return e>this.frameSizeLimit-200}decodeTimestampIn(e){let t=ua(e);return t=0===t?Number.MAX_VALUE:t-1,this.lastTimestampIn===Number.MAX_VALUE||t===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(t+=this.lastTimestampIn,this.lastTimestampIn=t,t)}decodeBound(e){let t=this.decodeTimestampIn(e),n=ua(e);if(n>la)throw Error("bound key too long");return{timestamp:t,id:da(e,n)}}encodeTimestampOut(e){if(e===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,ha(0);let t=e;return e-=this.lastTimestampOut,this.lastTimestampOut=t,ha(e+1)}encodeBound(e){let t=new ca;return t.extend(this.encodeTimestampOut(e.timestamp)),t.extend(ha(e.id.length)),t.extend(e.id),t}getMinimalBound(e,t){if(t.timestamp!==e.timestamp)return this._bound(t.timestamp);{let n=0,r=t.id,s=e.id;for(let e=0;e<la&&r[e]===s[e];e++)n++;return this._bound(t.timestamp,t.id.subarray(0,n+1))}}};function wa(e,t){for(let n=0;n<e.byteLength;n++){if(e[n]<t[n])return-1;if(e[n]>t[n])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function ba(e,t){return e.timestamp===t.timestamp?wa(e.id,t.id):e.timestamp-t.timestamp}var ya=class{relay;storage;neg;filter;subscription;onhave;onneed;constructor(e,t,n,r={}){this.relay=e,this.storage=t,this.neg=new ga(t),this.onhave=r.onhave,this.onneed=r.onneed,this.filter=n,this.subscription=this.relay.prepareSubscription([{}],{label:r.label||"negentropy"}),this.subscription.oncustom=e=>{switch(e[0]){case"NEG-MSG":e.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${e}`);try{const t=this.neg.reconcile(e[2],this.onhave,this.onneed);t?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${t}"]`):(this.close(),r.onclose?.())}catch(e){console.error("negentropy reconcile error:",e),r?.onclose?.(`reconcile error: ${e}`)}break;case"NEG-CLOSE":{const t=e[2];console.warn("negentropy error:",t),r.onclose?.(t);break}case"NEG-ERR":r.onclose?.()}}}async start(){const e=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${e}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}};sr({},{getToken:()=>va,hashPayload:()=>$a,unpackEventFromToken:()=>xa,validateEvent:()=>Ia,validateEventKind:()=>Sa,validateEventMethodTag:()=>Ta,validateEventPayloadTag:()=>Ra,validateEventTimestamp:()=>Ea,validateEventUrlTag:()=>Aa,validateToken:()=>ka});var ma="Nostr ";async function va(e,t,n,r=!1,s){const o={kind:Os,tags:[["u",e],["method",t]],created_at:Math.round((new Date).getTime()/1e3),content:""};s&&o.tags.push(["payload",$a(s)]);const i=await n(o);return(r?ma:"")+Et.encode(lr.encode(JSON.stringify(i)))}async function ka(e,t,n){const r=await xa(e).catch(e=>{throw e});return await Ia(r,t,n).catch(e=>{throw e})}async function xa(e){if(!e)throw new Error("Missing token");e=e.replace(ma,"");const t=ar.decode(Et.decode(e));if(!t||0===t.length||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function Ea(e){return!!e.created_at&&Math.round((new Date).getTime()/1e3)-e.created_at<60}function Sa(e){return e.kind===Os}function Aa(e,t){const n=e.tags.find(e=>"u"===e[0]);return!!n&&n.length>0&&n[1]===t}function Ta(e,t){const n=e.tags.find(e=>"method"===e[0]);return!!n&&n.length>0&&n[1].toLowerCase()===t.toLowerCase()}function $a(e){return Ve(ut(lr.encode(JSON.stringify(e))))}function Ra(e,t){const n=e.tags.find(e=>"payload"===e[0]);if(!n)return!1;const r=$a(t);return n.length>0&&n[1]===r}async function Ia(e,t,n,r){if(!vr(e))throw new Error("Invalid nostr event, signature invalid");if(!Sa(e))throw new Error("Invalid nostr event, kind invalid");if(!Ea(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!Aa(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!Ta(e,n))throw new Error("Invalid nostr event, method tag invalid");if(Boolean(r)&&"object"==typeof r&&Object.keys(r).length>0&&!Ra(e,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}class Ba{constructor(e){this.profileCache=new Map,this.pool=new $o,this.relays=e}normalizePublicKey(e){if(e.startsWith("npub"))try{return Ro.decode(e).data}catch(t){return console.error("Invalid npub format:",t),e}return e}async fetchPosts(e,t=50,n="all",r){const s=(Array.isArray(e)?e:[e]).map(e=>this.normalizePublicKey(e));let o;switch(n){case"long-form":o=[30023];break;case"short-form":o=[1];break;default:o=[30023,1]}let i=[];if(s.length>1){const e=Math.ceil(t/s.length);for(const t of s){const n={authors:[t],kinds:o,limit:e};r?.since&&(n.since=r.since),r?.until&&(n.until=r.until);const s=await this.pool.querySync(this.relays,n);i=i.concat(s)}}else{const e={authors:s,kinds:o,limit:t};r?.since&&(e.since=r.since),r?.until&&(e.until=r.until),i=await this.pool.querySync(this.relays,e)}return await this.fetchAuthorProfiles(s),this.parsePosts(i)}async fetchAuthorProfiles(e){const t=e.filter(e=>!this.profileCache.has(e));if(0===t.length)return;const n={authors:t,kinds:[0],limit:t.length};try{(await this.pool.querySync(this.relays,n)).forEach(e=>{try{const t=JSON.parse(e.content);this.profileCache.set(e.pubkey,t)}catch(t){console.error("Failed to parse profile for",e.pubkey,t)}})}catch(e){console.error("Failed to fetch author profiles:",e)}}async fetchPostById(e){if(e.startsWith("naddr"))return this.fetchPostByNaddr(e);if(e.startsWith("nevent"))return this.fetchPostByNevent(e);if(e.startsWith("note1"))try{const t=Ro.decode(e);"note"===t.type&&(e=t.data)}catch(e){console.error("Failed to decode note1:",e)}const t={ids:[e]},n=await this.pool.querySync(this.relays,t);return 0===n.length?null:(n[0]?.pubkey&&await this.fetchAuthorProfiles([n[0].pubkey]),this.parsePosts(n)[0]||null)}async fetchPostByNevent(e){try{const t=Ro.decode(e);if("nevent"!==t.type)return console.error("Not a valid nevent"),null;const n=t.data,r=n.relays&&n.relays.length>0?n.relays:this.relays,s={ids:[n.id]};n.author&&(s.authors=[n.author]);const o=await this.pool.querySync(r,s);return 0===o.length?null:(o[0]?.pubkey&&await this.fetchAuthorProfiles([o[0].pubkey]),this.parsePosts(o)[0]||null)}catch(e){return console.error("Failed to decode nevent:",e),null}}async fetchPostByNaddr(e){try{const t=Ro.decode(e);if("naddr"!==t.type)return console.error("Not a valid naddr"),null;const n=t.data,r=n.relays&&n.relays.length>0?n.relays:this.relays,s={authors:[n.pubkey],kinds:[n.kind],"#d":[n.identifier],limit:1},o=await this.pool.querySync(r,s);if(0===o.length)return null;const i=o.reduce((e,t)=>t.created_at>e.created_at?t:e);return i?.pubkey&&await this.fetchAuthorProfiles([i.pubkey]),this.parsePost(i)}catch(e){return console.error("Failed to decode naddr:",e),null}}parsePosts(e){const t=[],n=new Map;for(const r of e)if(30023===r.kind){const e=r.tags.find(([e])=>"d"===e)?.[1];if(e){const t=`${r.pubkey}:${e}`,s=n.get(t);(!s||r.created_at>s.created_at)&&n.set(t,r)}}else t.push(r);return t.push(...n.values()),t.map(e=>this.parsePost(e)).sort((e,t)=>(t.published_at||t.created_at)-(e.published_at||e.created_at))}parsePost(e){const t={...e};let n;if(e.tags.forEach(([e,r])=>{switch(e){case"title":t.title=r;break;case"summary":t.summary=r;break;case"image":t.image=r;break;case"published_at":t.published_at=parseInt(r,10);break;case"d":n=r}}),30023===e.kind&&n?t.naddr=Ro.naddrEncode({kind:e.kind,pubkey:e.pubkey,identifier:n,relays:this.relays.slice(0,2)}):1===e.kind&&(t.naddr=Ro.neventEncode({id:e.id,relays:this.relays.slice(0,2),author:e.pubkey})),t.content=e.content,!t.summary&&e.content){let n=e.content.replace(/https?:\/\/\S+/gi,"").replace(/nostr:(naddr1|note1|npub1|nevent1|nprofile1|nrelay1)\S+/gi,"").replace(/(naddr1|note1|npub1|nevent1|nprofile1|nrelay1)\S+/gi,"").replace(/\s+/g," ").trim();t.summary=n.substring(0,200)+(n.length>200?"...":"")}if(!t.title)if(30023===e.kind){const n=e.content.match(/^#\s+(.+)$/m);t.title=n?n[1]:"Untitled Post"}else{const n=e.content.split("\n")[0];t.title=n.substring(0,50)+(n.length>50?"...":"")}const r=this.profileCache.get(e.pubkey);if(r?(t.authorName=r.display_name||r.name||"Anonymous",t.authorAvatar=r.picture,t.authorNip05=r.nip05):t.authorName=e.pubkey.substring(0,8)+"...",30023===e.kind){const n=e.tags.find(([e])=>"d"===e);if(n&&n[1])try{const r=Ro.naddrEncode({kind:e.kind,pubkey:e.pubkey,identifier:n[1],relays:this.relays.slice(0,2)});t.naddr=r}catch(e){console.error("Failed to encode naddr:",e)}}return t}close(){this.pool.close(this.relays)}}},701(e,t,n){n.d(t,{EH:()=>m,Hr:()=>w,Ki:()=>E,Rc:()=>x,To:()=>v,a:()=>D,a0:()=>j,gb:()=>y,n5:()=>b,sE:()=>r,vz:()=>k,wv:()=>F});const r={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return s(this.context.count)},getNextContextId(){return s(this.context.count++)}};function s(e){const t=String(e),n=t.length-1;return r.context.id+(n?String.fromCharCode(96+n):"")+t}function o(e){r.context=e}const i=(Symbol("solid-proxy"),Symbol("solid-track")),a=(Symbol("solid-dev-component"),{equals:(e,t)=>e===t});let l=P;const c={owned:null,cleanups:null,context:null,owner:null};var u=null;let h=null,d=null,f=null,p=null,g=0;function w(e,t){const n=d,r=u,s=0===e.length,o=void 0===t?r:t,i=s?c:{owned:null,cleanups:null,context:o?o.context:null,owner:o},a=s?e:()=>e(()=>k(()=>O(i)));u=i,d=null;try{return _(a,!0)}finally{d=n,u=r}}function b(e,t){const n={value:e,observers:null,observerSlots:null,comparator:(t=t?Object.assign({},a,t):a).equals||void 0};return[T.bind(n),e=>("function"==typeof e&&(e=h&&h.running&&h.sources.has(n)?e(n.tValue):e(n.value)),$(n,e))]}function y(e,t,n){const r=B(e,t,!1,1);R(r)}function m(e,t,n){l=C;const r=B(e,t,!1,1);n&&n.render||(r.user=!0),p?p.push(r):R(r)}function v(e,t,n){n=n?Object.assign({},a,n):a;const r=B(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,R(r),T.bind(r)}function k(e){if(null===d)return e();const t=d;d=null;try{return e()}finally{d=t}}function x(e){m(()=>k(e))}function E(e){return null===u||(null===u.cleanups?u.cleanups=[e]:u.cleanups.push(e)),e}const[S,A]=b(!1);function T(){const e=h&&h.running;if(this.sources&&(e?this.tState:this.state))if(1===(e?this.tState:this.state))R(this);else{const e=f;f=null,_(()=>U(this),!1),f=e}if(d){const e=this.observers?this.observers.length:0;d.sources?(d.sources.push(this),d.sourceSlots.push(e)):(d.sources=[this],d.sourceSlots=[e]),this.observers?(this.observers.push(d),this.observerSlots.push(d.sources.length-1)):(this.observers=[d],this.observerSlots=[d.sources.length-1])}return e&&h.sources.has(this)?this.tValue:this.value}function $(e,t,n){let r=h&&h.running&&h.sources.has(e)?e.tValue:e.value;if(!e.comparator||!e.comparator(r,t)){if(h){const r=h.running;(r||!n&&h.sources.has(e))&&(h.sources.add(e),e.tValue=t),r||(e.value=t)}else e.value=t;e.observers&&e.observers.length&&_(()=>{for(let t=0;t<e.observers.length;t+=1){const n=e.observers[t],r=h&&h.running;r&&h.disposed.has(n)||((r?n.tState:n.state)||(n.pure?f.push(n):p.push(n),n.observers&&N(n)),r?n.tState=1:n.state=1)}if(f.length>1e6)throw f=[],new Error},!1)}return t}function R(e){if(!e.fn)return;O(e);const t=g;I(e,h&&h.running&&h.sources.has(e)?e.tValue:e.value,t),h&&!h.running&&h.sources.has(e)&&queueMicrotask(()=>{_(()=>{h&&(h.running=!0),d=u=e,I(e,e.tValue,t),d=u=null},!1)})}function I(e,t,n){let r;const s=u,o=d;d=u=e;try{r=e.fn(t)}catch(t){return e.pure&&(h&&h.running?(e.tState=1,e.tOwned&&e.tOwned.forEach(O),e.tOwned=void 0):(e.state=1,e.owned&&e.owned.forEach(O),e.owned=null)),e.updatedAt=n+1,q(t)}finally{d=o,u=s}(!e.updatedAt||e.updatedAt<=n)&&(null!=e.updatedAt&&"observers"in e?$(e,r,!0):h&&h.running&&e.pure?(h.sources.add(e),e.tValue=r):e.value=r,e.updatedAt=n)}function B(e,t,n,r=1,s){const o={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:u,context:u?u.context:null,pure:n};return h&&h.running&&(o.state=0,o.tState=r),null===u||u!==c&&(h&&h.running&&u.pure?u.tOwned?u.tOwned.push(o):u.tOwned=[o]:u.owned?u.owned.push(o):u.owned=[o]),o}function L(e){const t=h&&h.running;if(0===(t?e.tState:e.state))return;if(2===(t?e.tState:e.state))return U(e);if(e.suspense&&k(e.suspense.inFallback))return e.suspense.effects.push(e);const n=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<g);){if(t&&h.disposed.has(e))return;(t?e.tState:e.state)&&n.push(e)}for(let r=n.length-1;r>=0;r--){if(e=n[r],t){let t=e,s=n[r+1];for(;(t=t.owner)&&t!==s;)if(h.disposed.has(t))return}if(1===(t?e.tState:e.state))R(e);else if(2===(t?e.tState:e.state)){const t=f;f=null,_(()=>U(e,n[0]),!1),f=t}}}function _(e,t){if(f)return e();let n=!1;t||(f=[]),p?n=!0:p=[],g++;try{const t=e();return function(e){if(f&&(P(f),f=null),e)return;let t;if(h)if(h.promises.size||h.queue.size){if(h.running)return h.running=!1,h.effects.push.apply(h.effects,p),p=null,void A(!0)}else{const e=h.sources,n=h.disposed;p.push.apply(p,h.effects),t=h.resolve;for(const e of p)"tState"in e&&(e.state=e.tState),delete e.tState;h=null,_(()=>{for(const e of n)O(e);for(const t of e){if(t.value=t.tValue,t.owned)for(let e=0,n=t.owned.length;e<n;e++)O(t.owned[e]);t.tOwned&&(t.owned=t.tOwned),delete t.tValue,delete t.tOwned,t.tState=0}A(!1)},!1)}const n=p;p=null,n.length&&_(()=>l(n),!1),t&&t()}(n),t}catch(e){n||(p=null),f=null,q(e)}}function P(e){for(let t=0;t<e.length;t++)L(e[t])}function C(e){let t,n=0;for(t=0;t<e.length;t++){const r=e[t];r.user?e[n++]=r:L(r)}if(r.context){if(r.count)return r.effects||(r.effects=[]),void r.effects.push(...e.slice(0,n));o()}for(!r.effects||!r.done&&r.count||(e=[...r.effects,...e],n+=r.effects.length,delete r.effects),t=0;t<n;t++)L(e[t])}function U(e,t){const n=h&&h.running;n?e.tState=0:e.state=0;for(let r=0;r<e.sources.length;r+=1){const s=e.sources[r];if(s.sources){const e=n?s.tState:s.state;1===e?s!==t&&(!s.updatedAt||s.updatedAt<g)&&L(s):2===e&&U(s,t)}}}function N(e){const t=h&&h.running;for(let n=0;n<e.observers.length;n+=1){const r=e.observers[n];(t?r.tState:r.state)||(t?r.tState=2:r.state=2,r.pure?f.push(r):p.push(r),r.observers&&N(r))}}function O(e){let t;if(e.sources)for(;e.sources.length;){const t=e.sources.pop(),n=e.sourceSlots.pop(),r=t.observers;if(r&&r.length){const e=r.pop(),s=t.observerSlots.pop();n<r.length&&(e.sourceSlots[s]=n,r[n]=e,t.observerSlots[n]=s)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)O(e.tOwned[t]);delete e.tOwned}if(h&&h.running&&e.pure)z(e,!0);else if(e.owned){for(t=e.owned.length-1;t>=0;t--)O(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}h&&h.running?e.tState=0:e.state=0}function z(e,t){if(t||(e.tState=0,h.disposed.add(e)),e.owned)for(let t=0;t<e.owned.length;t++)z(e.owned[t])}function q(e,t=u){const n=function(e){return e instanceof Error?e:new Error("string"==typeof e?e:"Unknown error",{cause:e})}(e);throw n}const M=Symbol("fallback");function H(e){for(let t=0;t<e.length;t++)e[t]()}function j(e,t){return k(()=>e(t||{}))}function D(e){const t="fallback"in e&&{fallback:()=>e.fallback};return v(function(e,t,n={}){let r=[],s=[],o=[],a=0,l=t.length>1?[]:null;return E(()=>H(o)),()=>{let c,u,h=e()||[],d=h.length;return h[i],k(()=>{let e,t,i,p,g,b,y,m,v;if(0===d)0!==a&&(H(o),o=[],r=[],s=[],a=0,l&&(l=[])),n.fallback&&(r=[M],s[0]=w(e=>(o[0]=e,n.fallback())),a=1);else if(0===a){for(s=new Array(d),u=0;u<d;u++)r[u]=h[u],s[u]=w(f);a=d}else{for(i=new Array(d),p=new Array(d),l&&(g=new Array(d)),b=0,y=Math.min(a,d);b<y&&r[b]===h[b];b++);for(y=a-1,m=d-1;y>=b&&m>=b&&r[y]===h[m];y--,m--)i[m]=s[y],p[m]=o[y],l&&(g[m]=l[y]);for(e=new Map,t=new Array(m+1),u=m;u>=b;u--)v=h[u],c=e.get(v),t[u]=void 0===c?-1:c,e.set(v,u);for(c=b;c<=y;c++)v=r[c],u=e.get(v),void 0!==u&&-1!==u?(i[u]=s[c],p[u]=o[c],l&&(g[u]=l[c]),u=t[u],e.set(v,u)):o[c]();for(u=b;u<d;u++)u in i?(s[u]=i[u],o[u]=p[u],l&&(l[u]=g[u],l[u](u))):s[u]=w(f);s=s.slice(0,a=d),r=h.slice(0)}return s});function f(e){if(o[u]=e,l){const[e,n]=b(u);return l[u]=n,t(h[u],e)}return t(h[u])}}}(()=>e.each,e.children,t||void 0))}function F(e){const t=e.keyed,n=v(()=>e.when,void 0,void 0),r=t?n:v(n,void 0,{equals:(e,t)=>!e==!t});return v(()=>{const s=r();if(s){const o=e.children;return"function"==typeof o&&o.length>0?k(()=>o(t?s:()=>{if(!k(r))throw`Stale read from <${"Show"}>.`;return n()})):o}return e.fallback},void 0,void 0)}}},r={};function s(e){var t=r[e];if(void 0!==t)return t.exports;var o=r[e]={exports:{}};return n[e](o,o.exports,s),o.exports}s.m=n,s.d=(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.f={},s.e=e=>Promise.all(Object.keys(s.f).reduce((t,n)=>(s.f[n](e,t),t),[])),s.u=e=>e+".nostr-blog.js",s.miniCssF=e=>{},s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e={},t="NostrBlog:",s.l=(n,r,o,i)=>{if(e[n])e[n].push(r);else{var a,l;if(void 0!==o)for(var c=document.getElementsByTagName("script"),u=0;u<c.length;u++){var h=c[u];if(h.getAttribute("src")==n||h.getAttribute("data-webpack")==t+o){a=h;break}}a||(l=!0,(a=document.createElement("script")).charset="utf-8",s.nc&&a.setAttribute("nonce",s.nc),a.setAttribute("data-webpack",t+o),a.src=n),e[n]=[r];var d=(t,r)=>{a.onerror=a.onload=null,clearTimeout(f);var s=e[n];if(delete e[n],a.parentNode&&a.parentNode.removeChild(a),s&&s.forEach(e=>e(r)),t)return t(r)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=d.bind(null,a.onerror),a.onload=d.bind(null,a.onload),l&&document.head.appendChild(a)}},s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;s.g.importScripts&&(e=s.g.location+"");var t=s.g.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");if(n.length)for(var r=n.length-1;r>-1&&(!e||!/^http(s?):/.test(e));)e=n[r--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=e})(),(()=>{var e={792:0};s.f.j=(t,n)=>{var r=s.o(e,t)?e[t]:void 0;if(0!==r)if(r)n.push(r[2]);else{var o=new Promise((n,s)=>r=e[t]=[n,s]);n.push(r[2]=o);var i=s.p+s.u(t),a=new Error;s.l(i,n=>{if(s.o(e,t)&&(0!==(r=e[t])&&(e[t]=void 0),r)){var o=n&&("load"===n.type?"missing":n.type),i=n&&n.target&&n.target.src;a.message="Loading chunk "+t+" failed.\n("+o+": "+i+")",a.name="ChunkLoadError",a.type=o,a.request=i,r[1](a)}},"chunk-"+t,t)}};var t=(t,n)=>{var r,o,[i,a,l]=n,c=0;if(i.some(t=>0!==e[t])){for(r in a)s.o(a,r)&&(s.m[r]=a[r]);l&&l(s)}for(t&&t(n);c<i.length;c++)o=i[c],s.o(e,o)&&e[o]&&e[o][0](),e[o]=0},n=this.webpackChunkNostrBlog=this.webpackChunkNostrBlog||[];n.forEach(t.bind(null,0)),n.push=t.bind(null,n.push.bind(n))})();var o={};s.d(o,{default:()=>ot});var i=s(701),a=s(35),l=s(261),c=s(168);var u={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function h(e){u=e}var d={exec:()=>null};function f(e,t=""){let n="string"==typeof e?e:e.source,r={replace:(e,t)=>{let s="string"==typeof t?t:t.source;return s=s.replace(g.caret,"$1"),n=n.replace(e,s),r},getRegex:()=>new RegExp(n,t)};return r}var p=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),g={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},w=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,b=/(?:[*+-]|\d{1,9}[.)])/,y=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,m=f(y).replace(/bull/g,b).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),v=f(y).replace(/bull/g,b).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),k=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,x=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,E=f(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",x).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),S=f(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,b).getRegex(),A="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",T=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,$=f("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",T).replace("tag",A).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),R=f(k).replace("hr",w).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),I={blockquote:f(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",R).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:E,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:w,html:$,lheading:m,list:S,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:R,table:d,text:/^[^\n]+/},B=f("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",w).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),L={...I,lheading:v,table:B,paragraph:f(k).replace("hr",w).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",B).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex()},_={...I,html:f("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",T).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:d,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:f(k).replace("hr",w).replace("heading"," *#{1,6} *[^\n]").replace("lheading",m).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},P=/^( {2,}|\\)\n(?!\s*$)/,C=/[\p{P}\p{S}]/u,U=/[\s\p{P}\p{S}]/u,N=/[^\s\p{P}\p{S}]/u,O=f(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,U).getRegex(),z=/(?!~)[\p{P}\p{S}]/u,q=f(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",p?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),M=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,H=f(M,"u").replace(/punct/g,C).getRegex(),j=f(M,"u").replace(/punct/g,z).getRegex(),D="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",F=f(D,"gu").replace(/notPunctSpace/g,N).replace(/punctSpace/g,U).replace(/punct/g,C).getRegex(),V=f(D,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,z).getRegex(),W=f("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,N).replace(/punctSpace/g,U).replace(/punct/g,C).getRegex(),Z=f(/\\(punct)/,"gu").replace(/punct/g,C).getRegex(),K=f(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Y=f(T).replace("(?:--\x3e|$)","--\x3e").getRegex(),G=f("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Y).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),J=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,Q=f(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",J).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),X=f(/^!?\[(label)\]\[(ref)\]/).replace("label",J).replace("ref",x).getRegex(),ee=f(/^!?\[(ref)\](?:\[\])?/).replace("ref",x).getRegex(),te=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,ne={_backpedal:d,anyPunctuation:Z,autolink:K,blockSkip:q,br:P,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:d,emStrongLDelim:H,emStrongRDelimAst:F,emStrongRDelimUnd:W,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:Q,nolink:ee,punctuation:O,reflink:X,reflinkSearch:f("reflink|nolink(?!\\()","g").replace("reflink",X).replace("nolink",ee).getRegex(),tag:G,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:d},re={...ne,link:f(/^!?\[(label)\]\((.*?)\)/).replace("label",J).getRegex(),reflink:f(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",J).getRegex()},se={...ne,emStrongRDelimAst:V,emStrongLDelim:j,url:f(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",te).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:f(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",te).getRegex()},oe={...se,br:f(P).replace("{2,}","*").getRegex(),text:f(se.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},ie={normal:I,gfm:L,pedantic:_},ae={normal:ne,gfm:se,breaks:oe,pedantic:re},le={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ce=e=>le[e];function ue(e,t){if(t){if(g.escapeTest.test(e))return e.replace(g.escapeReplace,ce)}else if(g.escapeTestNoEncode.test(e))return e.replace(g.escapeReplaceNoEncode,ce);return e}function he(e){try{e=encodeURI(e).replace(g.percentDecode,"%")}catch{return null}return e}function de(e,t){let n=e.replace(g.findPipe,(e,t,n)=>{let r=!1,s=t;for(;--s>=0&&"\\"===n[s];)r=!r;return r?"|":" |"}).split(g.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;r<n.length;r++)n[r]=n[r].trim().replace(g.slashPipe,"|");return n}function fe(e,t,n){let r=e.length;if(0===r)return"";let s=0;for(;s<r;){let o=e.charAt(r-s-1);if(o!==t||n){if(o===t||!n)break;s++}else s++}return e.slice(0,r-s)}function pe(e,t,n,r,s){let o=t.href,i=t.title||null,a=e[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;let l={type:"!"===e[0].charAt(0)?"image":"link",raw:n,href:o,title:i,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}var ge=class{options;rules;lexer;constructor(e){this.options=e||u}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:fe(e,"\n")}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=function(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(null===r)return t;let s=r[1];return t.split("\n").map(e=>{let t=e.match(n.other.beginningSpace);if(null===t)return e;let[r]=t;return r.length>=s.length?e.slice(s.length):e}).join("\n")}(e,t[3]||"",this.rules);return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=fe(e,"#");(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:fe(t[0],"\n")}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=fe(t[0],"\n").split("\n"),n="",r="",s=[];for(;e.length>0;){let t,o=!1,i=[];for(t=0;t<e.length;t++)if(this.rules.other.blockquoteStart.test(e[t]))i.push(e[t]),o=!0;else{if(o)break;i.push(e[t])}e=e.slice(t);let a=i.join("\n"),l=a.replace(this.rules.other.blockquoteSetextReplace,"\n $1").replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}\n${a}`:a,r=r?`${r}\n${l}`:l;let c=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,s,!0),this.lexer.state.top=c,0===e.length)break;let u=s.at(-1);if("code"===u?.type)break;if("blockquote"===u?.type){let t=u,o=t.raw+"\n"+e.join("\n"),i=this.blockquote(o);s[s.length-1]=i,n=n.substring(0,n.length-t.raw.length)+i.raw,r=r.substring(0,r.length-t.text.length)+i.text;break}if("list"===u?.type){let t=u,o=t.raw+"\n"+e.join("\n"),i=this.list(o);s[s.length-1]=i,n=n.substring(0,n.length-u.raw.length)+i.raw,r=r.substring(0,r.length-t.raw.length)+i.raw,e=o.substring(s.at(-1).raw.length).split("\n");continue}}return{type:"blockquote",raw:n,tokens:s,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let o=this.rules.other.listItemRegex(n),i=!1;for(;e;){let n=!1,r="",a="";if(!(t=o.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let l=t[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,e=>" ".repeat(3*e.length)),c=e.split("\n",1)[0],u=!l.trim(),h=0;if(this.options.pedantic?(h=2,a=l.trimStart()):u?h=t[1].length+1:(h=t[2].search(this.rules.other.nonSpaceChar),h=h>4?1:h,a=l.slice(h),h+=t[1].length),u&&this.rules.other.blankLine.test(c)&&(r+=c+"\n",e=e.substring(c.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(h),n=this.rules.other.hrRegex(h),s=this.rules.other.fencesBeginRegex(h),o=this.rules.other.headingBeginRegex(h),i=this.rules.other.htmlBeginRegex(h);for(;e;){let d,f=e.split("\n",1)[0];if(c=f,this.options.pedantic?(c=c.replace(this.rules.other.listReplaceNesting," "),d=c):d=c.replace(this.rules.other.tabCharGlobal," "),s.test(c)||o.test(c)||i.test(c)||t.test(c)||n.test(c))break;if(d.search(this.rules.other.nonSpaceChar)>=h||!c.trim())a+="\n"+d.slice(h);else{if(u||l.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||s.test(l)||o.test(l)||n.test(l))break;a+="\n"+c}!u&&!c.trim()&&(u=!0),r+=f+"\n",e=e.substring(f.length+1),l=d.slice(h)}}s.loose||(i?s.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(i=!0)),s.items.push({type:"list_item",raw:r,task:!!this.options.gfm&&this.rules.other.listIsTask.test(a),loose:!1,text:a,tokens:[]}),s.raw+=r}let a=s.items.at(-1);if(!a)return;a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd(),s.raw=s.raw.trimEnd();for(let e of s.items){if(this.lexer.state.top=!1,e.tokens=this.lexer.blockTokens(e.text,[]),e.task){if(e.text=e.text.replace(this.rules.other.listReplaceTask,""),"text"===e.tokens[0]?.type||"paragraph"===e.tokens[0]?.type){e.tokens[0].raw=e.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),e.tokens[0].text=e.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let e=this.lexer.inlineQueue.length-1;e>=0;e--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[e].src)){this.lexer.inlineQueue[e].src=this.lexer.inlineQueue[e].src.replace(this.rules.other.listReplaceTask,"");break}}let t=this.rules.other.listTaskCheckbox.exec(e.raw);if(t){let n={type:"checkbox",raw:t[0]+" ",checked:"[ ]"!==t[0]};e.checked=n.checked,s.loose?e.tokens[0]&&["paragraph","text"].includes(e.tokens[0].type)&&"tokens"in e.tokens[0]&&e.tokens[0].tokens?(e.tokens[0].raw=n.raw+e.tokens[0].raw,e.tokens[0].text=n.raw+e.tokens[0].text,e.tokens[0].tokens.unshift(n)):e.tokens.unshift({type:"paragraph",raw:n.raw,text:n.raw,tokens:[n]}):e.tokens.unshift(n)}}if(!s.loose){let t=e.tokens.filter(e=>"space"===e.type),n=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw));s.loose=n}}if(s.loose)for(let e of s.items){e.loose=!0;for(let t of e.tokens)"text"===t.type&&(t.type="paragraph")}return s}}html(e){let t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}def(e){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:r}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=de(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split("\n"):[],o={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(let e of r)this.rules.other.tableAlignRight.test(e)?o.align.push("right"):this.rules.other.tableAlignCenter.test(e)?o.align.push("center"):this.rules.other.tableAlignLeft.test(e)?o.align.push("left"):o.align.push(null);for(let e=0;e<n.length;e++)o.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:o.align[e]});for(let e of s)o.rows.push(de(e,o.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:o.align[t]})));return o}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=fe(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{let e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let r=0;r<e.length;r++)if("\\"===e[r])r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}(t[2],"()");if(-2===e)return;if(e>-1){let n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],r="";if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),pe(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return pe(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!r[1]&&!r[2]||!n||this.rules.inline.punctuation.exec(n))){let n,s,o=[...r[0]].length-1,i=o,a=0,l="*"===r[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+o);null!=(r=l.exec(t));){if(n=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!n)continue;if(s=[...n].length,r[3]||r[4]){i+=s;continue}if((r[5]||r[6])&&o%3&&!((o+s)%3)){a+=s;continue}if(i-=s,i>0)continue;s=Math.min(s,s+i+a);let t=[...r[0]][0].length,l=e.slice(0,o+r.index+t+s);if(Math.min(o,s)%2){let e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}let c=l.slice(2,-2);return{type:"strong",raw:l,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal," "),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:"codespan",raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=t[1],n="mailto:"+e):(e=t[1],n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=t[0],n="mailto:"+e;else{let r;do{r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(r!==t[0]);e=t[0],n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:e}}}},we=class e{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||u,this.options.tokenizer=this.options.tokenizer||new ge,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:g,block:ie.normal,inline:ae.normal};this.options.pedantic?(t.block=ie.pedantic,t.inline=ae.pedantic):this.options.gfm&&(t.block=ie.gfm,this.options.breaks?t.inline=ae.breaks:t.inline=ae.gfm),this.tokenizer.rules=t}static get rules(){return{block:ie,inline:ae}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(g.carriageReturn,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(g.tabCharGlobal," ").replace(g.spaceLine,""));e;){let r;if(this.options.extensions?.block?.some(n=>!!(r=n.call({lexer:this},e,t))&&(e=e.substring(r.raw.length),t.push(r),!0)))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);1===r.raw.length&&void 0!==n?n.raw+="\n":t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+r.raw,n.text+="\n"+r.text,this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if(r=this.tokenizer.fences(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.heading(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.hr(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.blockquote(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.list(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.html(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+r.raw,n.text+="\n"+r.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},t.push(r));continue}if(r=this.tokenizer.table(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.lheading(e)){e=e.substring(r.raw.length),t.push(r);continue}let s=e;if(this.options.extensions?.startBlock){let t,n=1/0,r=e.slice(1);this.options.extensions.startBlock.forEach(e=>{t=e.call({lexer:this},r),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(s=e.substring(0,n+1))}if(this.state.top&&(r=this.tokenizer.paragraph(s))){let o=t.at(-1);n&&"paragraph"===o?.type?(o.raw+=(o.raw.endsWith("\n")?"":"\n")+r.raw,o.text+="\n"+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):t.push(r),n=s.length!==e.length,e=e.substring(r.raw.length);continue}if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let n=t.at(-1);"text"===n?.type?(n.raw+=(n.raw.endsWith("\n")?"":"\n")+r.raw,n.text+="\n"+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n,r=e,s=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(s=this.tokenizer.rules.inline.reflinkSearch.exec(r));)e.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(s=this.tokenizer.rules.inline.anyPunctuation.exec(r));)r=r.slice(0,s.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(s=this.tokenizer.rules.inline.blockSkip.exec(r));)n=s[2]?s[2].length:0,r=r.slice(0,s.index+n)+"["+"a".repeat(s[0].length-n-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let o=!1,i="";for(;e;){let n;if(o||(i=""),o=!1,this.options.extensions?.inline?.some(r=>!!(n=r.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))continue;if(n=this.tokenizer.escape(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.tag(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.link(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(n.raw.length);let r=t.at(-1);"text"===n.type&&"text"===r?.type?(r.raw+=n.raw,r.text+=n.text):t.push(n);continue}if(n=this.tokenizer.emStrong(e,r,i)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.codespan(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.br(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.del(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.autolink(e)){e=e.substring(n.raw.length),t.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(e))){e=e.substring(n.raw.length),t.push(n);continue}let s=e;if(this.options.extensions?.startInline){let t,n=1/0,r=e.slice(1);this.options.extensions.startInline.forEach(e=>{t=e.call({lexer:this},r),"number"==typeof t&&t>=0&&(n=Math.min(n,t))}),n<1/0&&n>=0&&(s=e.substring(0,n+1))}if(n=this.tokenizer.inlineText(s)){e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(i=n.raw.slice(-1)),o=!0;let r=t.at(-1);"text"===r?.type?(r.raw+=n.raw,r.text+=n.text):t.push(n);continue}if(e){let t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return t}},be=class{options;parser;constructor(e){this.options=e||u}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(g.notSpaceStart)?.[0],s=e.replace(g.endingNewline,"")+"\n";return r?'<pre><code class="language-'+ue(r)+'">'+(n?s:ue(s,!0))+"</code></pre>\n":"<pre><code>"+(n?s:ue(s,!0))+"</code></pre>\n"}blockquote({tokens:e}){return`<blockquote>\n${this.parser.parse(e)}</blockquote>\n`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>\n`}hr(e){return"<hr>\n"}list(e){let t=e.ordered,n=e.start,r="";for(let t=0;t<e.items.length;t++){let n=e.items[t];r+=this.listitem(n)}let s=t?"ol":"ul";return"<"+s+(t&&1!==n?' start="'+n+'"':"")+">\n"+r+"</"+s+">\n"}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>\n`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>\n`}table(e){let t="",n="";for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r="";for(let t=0;t<e.rows.length;t++){let s=e.rows[t];n="";for(let e=0;e<s.length;e++)n+=this.tablecell(s[e]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),"<table>\n<thead>\n"+t+"</thead>\n"+r+"</table>\n"}tablerow({text:e}){return`<tr>\n${e}</tr>\n`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>\n`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${ue(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),s=he(e);if(null===s)return r;let o='<a href="'+(e=s)+'"';return t&&(o+=' title="'+ue(t)+'"'),o+=">"+r+"</a>",o}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let s=he(e);if(null===s)return ue(n);let o=`<img src="${e=s}" alt="${n}"`;return t&&(o+=` title="${ue(t)}"`),o+=">",o}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:ue(e.text)}},ye=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},me=class e{options;renderer;textRenderer;constructor(e){this.options=e||u,this.options.renderer=this.options.renderer||new be,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ye}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){let t="";for(let n=0;n<e.length;n++){let r=e[n];if(this.options.extensions?.renderers?.[r.type]){let e=r,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==n||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(e.type)){t+=n||"";continue}}let s=r;switch(s.type){case"space":t+=this.renderer.space(s);break;case"hr":t+=this.renderer.hr(s);break;case"heading":t+=this.renderer.heading(s);break;case"code":t+=this.renderer.code(s);break;case"table":t+=this.renderer.table(s);break;case"blockquote":t+=this.renderer.blockquote(s);break;case"list":t+=this.renderer.list(s);break;case"checkbox":t+=this.renderer.checkbox(s);break;case"html":t+=this.renderer.html(s);break;case"def":t+=this.renderer.def(s);break;case"paragraph":t+=this.renderer.paragraph(s);break;case"text":t+=this.renderer.text(s);break;default:{let e='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return t}parseInline(e,t=this.renderer){let n="";for(let r=0;r<e.length;r++){let s=e[r];if(this.options.extensions?.renderers?.[s.type]){let e=this.options.extensions.renderers[s.type].call({parser:this},s);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type)){n+=e||"";continue}}let o=s;switch(o.type){case"escape":case"text":n+=t.text(o);break;case"html":n+=t.html(o);break;case"link":n+=t.link(o);break;case"image":n+=t.image(o);break;case"checkbox":n+=t.checkbox(o);break;case"strong":n+=t.strong(o);break;case"em":n+=t.em(o);break;case"codespan":n+=t.codespan(o);break;case"br":n+=t.br(o);break;case"del":n+=t.del(o);break;default:{let e='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}},ve=class{options;block;constructor(e){this.options=e||u}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(){return this.block?we.lex:we.lexInline}provideParser(){return this.block?me.parse:me.parseInline}},ke=new class{defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=me;Renderer=be;TextRenderer=ye;Lexer=we;Tokenizer=ge;Hooks=ve;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let s=e[r].flat(1/0);n=n.concat(this.walkTokens(s,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){let n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let r=e.renderer.apply(this,t);return!1===r&&(r=n.apply(this,t)),r}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new be(this.defaults);for(let n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if(["options","parser"].includes(n))continue;let r=n,s=e.renderer[r],o=t[r];t[r]=(...e)=>{let n=s.apply(t,e);return!1===n&&(n=o.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new ge(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;let r=n,s=e.tokenizer[r],o=t[r];t[r]=(...e)=>{let n=s.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new ve;for(let n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if(["options","block"].includes(n))continue;let r=n,s=e.hooks[r],o=t[r];ve.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async&&ve.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await s.call(t,e);return o.call(t,n)})();let r=s.call(t,e);return o.call(t,r)}:t[r]=(...e)=>{if(this.defaults.async)return(async()=>{let n=await s.apply(t,e);return!1===n&&(n=await o.apply(t,e)),n})();let n=s.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return we.lex(e,t??this.defaults)}parser(e,t){return me.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},s={...this.defaults,...r},o=this.onError(!!s.silent,!!s.async);if(!0===this.defaults.async&&!1===r.async)return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||null===t)return o(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof t)return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=e),s.async)return(async()=>{let n=s.hooks?await s.hooks.preprocess(t):t,r=await(s.hooks?await s.hooks.provideLexer():e?we.lex:we.lexInline)(n,s),o=s.hooks?await s.hooks.processAllTokens(r):r;s.walkTokens&&await Promise.all(this.walkTokens(o,s.walkTokens));let i=await(s.hooks?await s.hooks.provideParser():e?me.parse:me.parseInline)(o,s);return s.hooks?await s.hooks.postprocess(i):i})().catch(o);try{s.hooks&&(t=s.hooks.preprocess(t));let n=(s.hooks?s.hooks.provideLexer():e?we.lex:we.lexInline)(t,s);s.hooks&&(n=s.hooks.processAllTokens(n)),s.walkTokens&&this.walkTokens(n,s.walkTokens);let r=(s.hooks?s.hooks.provideParser():e?me.parse:me.parseInline)(n,s);return s.hooks&&(r=s.hooks.postprocess(r)),r}catch(e){return o(e)}}}onError(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){let e="<p>An error occurred:</p><pre>"+ue(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function xe(e,t){return ke.parse(e,t)}xe.options=xe.setOptions=function(e){return ke.setOptions(e),xe.defaults=ke.defaults,h(xe.defaults),xe},xe.getDefaults=function(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}},xe.defaults=u,xe.use=function(...e){return ke.use(...e),xe.defaults=ke.defaults,h(xe.defaults),xe},xe.walkTokens=function(e,t){return ke.walkTokens(e,t)},xe.parseInline=ke.parseInline,xe.Parser=me,xe.parser=me.parse,xe.Renderer=be,xe.TextRenderer=ye,xe.Lexer=we,xe.lexer=we.lex,xe.Tokenizer=ge,xe.Hooks=ve,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,me.parse,we.lex;var Ee=(0,a.vs)('<div class="nbw-p-4 nbw-text-gray-500 nbw-text-sm">Loading post...'),Se=(0,a.vs)('<div class="nbw-p-4 nbw-text-red-500 nbw-text-sm">Failed to load embedded post'),Ae=(0,a.vs)('<img class="nbw-w-full nbw-h-32 nbw-object-cover nbw-rounded nbw-mb-3">'),Te=(0,a.vs)('<p class="nbw-text-sm nbw-text-gray-600 nbw-mb-3 nbw-line-clamp-2">'),$e=(0,a.vs)('<img class="nbw-w-5 nbw-h-5 nbw-rounded-full">'),Re=(0,a.vs)('<a class="nbw-block nbw-no-underline hover:nbw-no-underline"><div class="nbw-embedded-post-content nbw-p-4"><h4 class="nbw-text-lg nbw-font-semibold nbw-text-gray-900 nbw-mb-2 nbw-line-clamp-2"></h4><div class="nbw-flex nbw-items-center nbw-gap-2 nbw-text-xs nbw-text-gray-500"><span class="nbw-font-medium nbw-text-gray-700"></span><span>•</span><span>'),Ie=(0,a.vs)('<div class="nbw-embedded-post nbw-my-4 nbw-border nbw-border-gray-300 nbw-rounded-lg nbw-overflow-hidden nbw-bg-gray-50 hover:nbw-bg-gray-100 nbw-transition-colors">');const Be=e=>{const[t,n]=(0,i.n5)(null),[r,s]=(0,i.n5)(!0),[o,l]=(0,i.n5)(!1);return(0,i.Rc)(async()=>{try{s(!0);const t=await e.onFetch(e.eventId);n(t),l(!t)}catch(e){console.error("Failed to fetch embedded post:",e),l(!0)}finally{s(!1)}}),c=Ie(),(0,a.Yr)(c,(0,i.a0)(i.wv,{get when(){return r()},get children(){return Ee()}}),null),(0,a.Yr)(c,(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!o())()&&!r()},get children(){return Se()}}),null),(0,a.Yr)(c,(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!t())()&&!r()},get children(){var n=Re(),r=n.firstChild,s=r.firstChild,o=s.nextSibling,l=o.firstChild,c=l.nextSibling.nextSibling;return(0,a.Yr)(r,(0,i.a0)(i.wv,{get when(){return t().image},get children(){var e=Ae();return(0,i.gb)(n=>{var r=t().image,s=t().title;return r!==n.e&&(0,a.Bq)(e,"src",n.e=r),s!==n.t&&(0,a.Bq)(e,"alt",n.t=s),n},{e:void 0,t:void 0}),e}}),s),(0,a.Yr)(s,()=>t().title||"Untitled Post"),(0,a.Yr)(r,(0,i.a0)(i.wv,{get when(){return t().summary},get children(){var e=Te();return(0,a.Yr)(e,()=>t().summary),e}}),o),(0,a.Yr)(o,(0,i.a0)(i.wv,{get when(){return t().authorAvatar},get children(){var e=$e();return(0,i.gb)(n=>{var r=t().authorAvatar,s=t().authorName;return r!==n.e&&(0,a.Bq)(e,"src",n.e=r),s!==n.t&&(0,a.Bq)(e,"alt",n.t=s),n},{e:void 0,t:void 0}),e}}),l),(0,a.Yr)(l,()=>t().authorName),(0,a.Yr)(c,()=>{return e=t().published_at||t().created_at,new Date(1e3*e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});var e}),(0,i.gb)(()=>(0,a.Bq)(n,"href",`#/post/${e.eventId}`)),n}}),null),c;var c};var Le=(0,a.vs)("<div class=nbw-content-renderer>"),_e=(0,a.vs)("<div>");const Pe=e=>{const[t,n]=(0,i.n5)([]),[r,s]=(0,i.n5)([]);return(0,i.EH)(()=>{(e=>{const t=/(?:nostr\s*:?\s*)?(naddr1\S+|note1\S+|nevent1\S+|nprofile1\S+|npub1\S+|nrelay1\S+)/gi,r=[],o=[];let i,a=0,l=0;for(;null!==(i=t.exec(e));){const t=i[1].trim().replace(/[)\]\}\.,!?:;"'>]+$/,""),n=t.substring(0,t.indexOf("1")+1).toLowerCase();let s="other";if(n.startsWith("naddr")?s="naddr":n.startsWith("nevent")?s="nevent":n.startsWith("note")&&(s="note"),"other"!==s){o.push(e.substring(a,i.index));const n="nostr-ref-"+l++;o.push(`[[${n}]]`),r.push({id:n,fullId:t,type:s}),a=i.index+i[0].length}}o.push(e.substring(a));const c=o.map(e=>{if(e.startsWith("[[")&&e.endsWith("]]"))return e;let t=(e=>e.replace(/(https?:\/\/[^\s]+\.(?:jpg|jpeg|png|gif|webp|svg|mp4|webm|mov|avi))/gi,e=>{const t=e.toLowerCase();return t.endsWith(".mp4")||t.endsWith(".webm")||t.endsWith(".mov")||t.endsWith(".avi")?`\n\n<video controls class="nbw-content-video nbw-max-w-full nbw-h-auto nbw-rounded-lg nbw-my-4"><source src="${e}"></video>\n\n`:`\n\n<img src="${e}" alt="Image" class="nbw-content-image nbw-max-w-full nbw-h-auto nbw-rounded-lg nbw-my-4" />\n\n`}))(e);return t=t.replace(/(?:nostr:\s*)?(npub1\S+|nprofile1\S+|nrelay1\S+)/gi,(e,t)=>`<a href="https://njump.me/${t}" target="_blank" rel="noopener noreferrer" class="nbw-nostr-link nbw-text-blue-600 hover:nbw-underline">${t}</a>`),t});n(r),s(c)})(e.content)}),o=Le(),(0,a.Yr)(o,(0,i.a0)(i.a,{get each(){return r()},children:n=>{if(n.startsWith("[[")&&n.endsWith("]]")){const r=n.slice(2,-2),s=t().find(e=>e.id===r);return s?(0,i.a0)(Be,{get eventId(){return s.fullId},get onFetch(){return e.onFetchPost}}):null}if(e.useMarkdown)return s=_e(),(0,i.gb)(()=>s.innerHTML=xe(n)),s;{const e=n.replace(/\n/g,"<br />");return(r=_e()).innerHTML=e,r}var r,s}})),o;var o};var Ce=(0,a.vs)('<div class="nbw-grid nbw-gap-6">'),Ue=(0,a.vs)('<div class="nbw-py-2 nbw-border-b nbw-border-gray-200"><div class="nbw-text-gray-500 nbw-text-xs nbw-mb-1"></div><a class="nbw-text-blue-600 hover:nbw-underline nbw-font-medium nbw-no-underline hover:nbw-text-blue-800">'),Ne=(0,a.vs)('<article class="nbw-bg-white nbw-rounded-lg nbw-shadow-md nbw-overflow-hidden nbw-cursor-pointer"><div class=nbw-p-6><h2 class="nbw-text-2xl nbw-font-bold nbw-mb-2 nbw-text-gray-900 hover:nbw-underline"></h2><div class="nbw-flex nbw-items-center nbw-gap-3 nbw-mb-3"><div class=nbw-flex-1><p class="nbw-text-gray-900 nbw-text-sm nbw-font-medium"></p><p class="nbw-text-gray-600 nbw-text-xs">'),Oe=(0,a.vs)('<img class="nbw-w-full nbw-h-48 nbw-object-cover">'),ze=(0,a.vs)('<img class="nbw-w-8 nbw-h-8 nbw-rounded-full nbw-object-cover">'),qe=(0,a.vs)('<div class="nbw-flex nbw-justify-end"><a class="nbw-read-more nbw-text-black nbw-font-medium nbw-no-underline hover:nbw-underline">Read more →'),Me=(0,a.vs)('<p class="nbw-text-gray-700 nbw-mb-4">');const He=e=>{const t=t=>{const n=new Date(1e3*t);switch(e.config.dateFormat){case"short":default:return n.toLocaleDateString();case"long":return n.toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"});case"relative":const e=Date.now()-n.getTime(),t=Math.floor(e/864e5);return 0===t?"Today":1===t?"Yesterday":t<7?`${t} days ago`:t<30?`${Math.floor(t/7)} weeks ago`:t<365?`${Math.floor(t/30)} months ago`:`${Math.floor(t/365)} years ago`}};return n=Ce(),(0,a.Yr)(n,(0,i.a0)(i.a,{get each(){return e.posts},children:n=>{return"compact"===e.config.layout?(w=(g=Ue()).firstChild,b=w.nextSibling,(0,a.Yr)(w,()=>t(n.published_at||n.created_at)),b.$$click=t=>{t.preventDefault(),e.onNavigate(n.naddr||n.id)},(0,a.Yr)(b,()=>n.title),(0,i.gb)(()=>(0,a.Bq)(b,"href",`#/post/${n.naddr||n.id}`)),g):(p=(f=(d=(h=(u=(c=(l=Ne()).firstChild).firstChild).nextSibling).firstChild).firstChild).nextSibling,l.$$click=()=>e.onNavigate(n.naddr||n.id),(0,a.Yr)(l,(r=(0,a.ph)(()=>!(!e.config.showImages||!n.image)),()=>{return r()&&(e=Oe(),(0,i.gb)(t=>{var r=n.image,s=n.title;return r!==t.e&&(0,a.Bq)(e,"src",t.e=r),s!==t.t&&(0,a.Bq)(e,"alt",t.t=s),t},{e:void 0,t:void 0}),e);var e}),c),(0,a.Yr)(u,()=>n.title),(0,a.Yr)(h,(s=(0,a.ph)(()=>!!n.authorAvatar),()=>{return s()&&(e=ze(),(0,i.gb)(t=>{var r=n.authorAvatar,s=n.authorName;return r!==t.e&&(0,a.Bq)(e,"src",t.e=r),s!==t.t&&(0,a.Bq)(e,"alt",t.t=s),t},{e:void 0,t:void 0}),e);var e}),d),(0,a.Yr)(f,()=>n.authorName),(0,a.Yr)(p,()=>t(n.published_at||n.created_at)),(0,a.Yr)(c,(o=(0,a.ph)(()=>!(1!==n.kind&&"1"!==n.kind)),()=>{return o()?(0,i.a0)(Pe,{get content(){return n.content||""},get onFetchPost(){return e.onFetchPost},useMarkdown:!1}):[(0,a.ph)(()=>{return(0,a.ph)(()=>!(!e.config.showSummary||!n.summary))()&&(t=Me(),(0,a.Yr)(t,()=>n.summary),t);var t}),(t=qe(),r=t.firstChild,r.$$click=t=>{t.stopPropagation(),t.preventDefault(),e.onNavigate(n.naddr||n.id)},(0,i.gb)(()=>(0,a.Bq)(r,"href",`#/post/${n.naddr||n.id}`)),t)];var t,r}),null),l);var r,s,o,l,c,u,h,d,f,p,g,w,b}})),(0,i.gb)(t=>(0,a.pP)(n,{"nbw-grid-cols-1":"list"===e.config.layout||"compact"===e.config.layout,"nbw-grid-cols-1 md:nbw-grid-cols-2 lg:nbw-grid-cols-3":"grid"===e.config.layout},t)),n;var n};(0,a.z_)(["click"]);var je=(0,a.vs)('<img class="nbw-w-full nbw-h-64 nbw-object-cover">'),De=(0,a.vs)('<img class="nbw-w-12 nbw-h-12 nbw-rounded-full nbw-object-cover">'),Fe=(0,a.vs)('<article class="nbw-bg-white nbw-rounded-lg nbw-shadow-lg nbw-overflow-hidden"><div class=nbw-p-8><button class="nbw-mb-4 nbw-text-blue-600 hover:nbw-text-blue-800 nbw-font-semibold nbw-bg-transparent nbw-border-none nbw-cursor-pointer nbw-p-0">← Back to posts</button><h1 class="nbw-text-4xl nbw-font-bold nbw-mb-4 nbw-text-gray-900"></h1><div class="nbw-flex nbw-items-center nbw-gap-4 nbw-mb-6 nbw-pb-6 nbw-border-b nbw-border-gray-200"><div class=nbw-flex-1><p class="nbw-text-gray-900 nbw-font-semibold"></p><p class="nbw-text-gray-600 nbw-text-sm"></p></div></div><div class="nbw-prose nbw-max-w-none nbw-text-gray-800">');const Ve=e=>{return u=(c=(l=(o=(s=(r=(n=(t=Fe()).firstChild).firstChild).nextSibling).nextSibling).firstChild).firstChild).nextSibling,h=o.nextSibling,(0,a.Yr)(t,(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!e.config.showImages)()&&e.post.image},get children(){var t=je();return(0,i.gb)(n=>{var r=e.post.image,s=e.post.title;return r!==n.e&&(0,a.Bq)(t,"src",n.e=r),s!==n.t&&(0,a.Bq)(t,"alt",n.t=s),n},{e:void 0,t:void 0}),t}}),n),r.$$click=()=>e.onBack(),(0,a.Yr)(s,()=>e.post.title),(0,a.Yr)(o,(0,i.a0)(i.wv,{get when(){return e.post.authorAvatar},get children(){var t=De();return(0,i.gb)(n=>{var r=e.post.authorAvatar,s=e.post.authorName;return r!==n.e&&(0,a.Bq)(t,"src",n.e=r),s!==n.t&&(0,a.Bq)(t,"alt",n.t=s),n},{e:void 0,t:void 0}),t}}),l),(0,a.Yr)(c,()=>e.post.authorName),(0,a.Yr)(u,()=>{return t=e.post.published_at||e.post.created_at,new Date(1e3*t).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"});var t}),(0,a.Yr)(h,(0,i.a0)(Pe,{get content(){return e.post.content||""},get onFetchPost(){return e.onFetchPost},get useMarkdown(){return 30023===e.post.kind||"30023"===e.post.kind}})),t;var t,n,r,s,o,l,c,u,h};(0,a.z_)(["click"]);var We=(0,a.vs)('<div class="nbw-flex nbw-items-center nbw-justify-center nbw-p-8"><div class="nbw-animate-spin nbw-rounded-full nbw-h-12 nbw-w-12 nbw-border-b-2 nbw-border-gray-900">');const Ze=()=>We();var Ke=(0,a.vs)('<div class="nbw-divider nbw-hidden md:nbw-block nbw-h-8 nbw-w-px nbw-bg-gray-300">'),Ye=(0,a.vs)('<div class="nbw-control-group nbw-author-control nbw-flex nbw-flex-col nbw-gap-1"><select class="nbw-author-select nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-gray-300 nbw-rounded-md nbw-bg-white nbw-text-gray-700 hover:nbw-bg-gray-50 nbw-transition-all nbw-cursor-pointer focus:nbw-outline-none focus:nbw-ring-2 focus:nbw-ring-blue-500"><option class=nbw-author-option value>All Authors</option></select><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center">Author'),Ge=(0,a.vs)('<div class="nbw-control-panel nbw-bg-white nbw-border nbw-border-gray-200 nbw-rounded-lg nbw-shadow-sm nbw-mb-6 nbw-p-4"><div class="nbw-control-panel-inner nbw-flex nbw-flex-wrap nbw-items-center nbw-gap-3 md:nbw-gap-4"><div class="nbw-control-group nbw-layout-control nbw-flex nbw-flex-col nbw-gap-1"><div class="nbw-button-group nbw-flex nbw-rounded-md nbw-shadow-sm"><button class="nbw-layout-btn nbw-layout-btn-list nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-rounded-l-md nbw-transition-all"title="List View"><svg class="nbw-icon nbw-w-4 nbw-h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 6h16M4 12h16M4 18h16"></path></svg></button><button class="nbw-layout-btn nbw-layout-btn-grid nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-l-0 nbw-transition-all"title="Grid View"><svg class="nbw-icon nbw-w-4 nbw-h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 5a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM14 5a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 15a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1H5a1 1 0 01-1-1v-4zM14 15a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1v-4z"></path></svg></button><button class="nbw-layout-btn nbw-layout-btn-compact nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-l-0 nbw-rounded-r-md nbw-transition-all"title="Compact View"><svg class="nbw-icon nbw-w-4 nbw-h-4"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 8h16M4 16h16"></path></svg></button></div><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center">View</span></div><div class="nbw-divider nbw-hidden md:nbw-block nbw-h-8 nbw-w-px nbw-bg-gray-300"></div><div class="nbw-control-group nbw-content-type-control nbw-flex nbw-flex-col nbw-gap-1"><div class="nbw-button-group nbw-flex nbw-rounded-md nbw-shadow-sm"><button class="nbw-content-btn nbw-content-btn-all nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-rounded-l-md nbw-transition-all"title="All Content">All</button><button class="nbw-content-btn nbw-content-btn-articles nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-l-0 nbw-transition-all"title="Articles Only">Articles</button><button class="nbw-content-btn nbw-content-btn-notes nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-l-0 nbw-rounded-r-md nbw-transition-all"title="Notes Only">Notes</button></div><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center">Type</span></div><div class="nbw-divider nbw-hidden md:nbw-block nbw-h-8 nbw-w-px nbw-bg-gray-300"></div><div class="nbw-control-group nbw-date-control nbw-flex nbw-flex-col nbw-gap-1"><select class="nbw-date-select nbw-px-3 nbw-py-1.5 nbw-text-sm nbw-font-medium nbw-border nbw-border-gray-300 nbw-rounded-md nbw-bg-white nbw-text-gray-700 hover:nbw-bg-gray-50 nbw-transition-all nbw-cursor-pointer focus:nbw-outline-none focus:nbw-ring-2 focus:nbw-ring-blue-500"><option class=nbw-date-option value=all>All Time</option><option class=nbw-date-option value=week>Last Week</option><option class=nbw-date-option value=month>Last Month</option><option class=nbw-date-option value=year>Last Year</option></select><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center">Period</span></div><div class="nbw-spacer nbw-flex-1 nbw-hidden lg:nbw-block"></div><div class="nbw-control-group nbw-refresh-control nbw-flex nbw-flex-col nbw-gap-1"><button class="nbw-refresh-btn nbw-px-4 nbw-py-1.5 nbw-bg-blue-600 nbw-text-white nbw-text-sm nbw-font-medium nbw-rounded-md hover:nbw-bg-blue-700 nbw-transition-all nbw-shadow-sm hover:nbw-shadow focus:nbw-outline-none focus:nbw-ring-2 focus:nbw-ring-blue-500"title="Refresh Posts"><svg class="nbw-icon nbw-w-4 nbw-h-4 nbw-inline nbw-mr-1.5"fill=none stroke=currentColor viewBox="0 0 24 24"><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path></svg><span class="nbw-hidden sm:nbw-inline">Refresh</span></button><span class="nbw-control-label nbw-text-xs nbw-text-gray-500 nbw-text-center nbw-invisible">Action'),Je=(0,a.vs)("<option class=nbw-author-option>");const Qe=e=>{const t=(0,i.To)(()=>{const t=new Map;return e.posts.forEach(e=>{t.has(e.pubkey)||t.set(e.pubkey,{pubkey:e.pubkey,name:e.authorName||e.pubkey.substring(0,8)+"...",avatar:e.authorAvatar})}),Array.from(t.values())}),n=(0,i.To)(()=>t().length>1),r=(0,i.To)(()=>e.config.selectedAuthor??"");return l=(o=(s=Ge()).firstChild).firstChild,c=l.firstChild.firstChild,u=c.nextSibling,h=u.nextSibling,d=l.nextSibling.nextSibling,f=d.firstChild.firstChild,p=f.nextSibling,g=p.nextSibling,b=(w=d.nextSibling.nextSibling).firstChild,m=(y=w.nextSibling).nextSibling.firstChild,c.$$click=()=>e.onLayoutChange("list"),u.$$click=()=>e.onLayoutChange("grid"),h.$$click=()=>e.onLayoutChange("compact"),f.$$click=()=>e.onContentTypeChange("all"),p.$$click=()=>e.onContentTypeChange("long-form"),g.$$click=()=>e.onContentTypeChange("short-form"),b.addEventListener("change",t=>e.onDateRangeChange(t.currentTarget.value)),(0,a.Yr)(o,(0,i.a0)(i.wv,{get when(){return n()},get children(){return[Ke(),(n=Ye(),s=n.firstChild,o=s.firstChild,s.addEventListener("change",t=>e.onAuthorChange(t.currentTarget.value||void 0)),(0,a.Yr)(s,(0,i.a0)(i.a,{get each(){return t()},children:e=>{return t=Je(),(0,a.Yr)(t,()=>e.name),(0,i.gb)(()=>t.selected=r()===e.pubkey),(0,i.gb)(()=>t.value=e.pubkey),t;var t}}),null),(0,i.gb)(()=>o.selected=""===r()),(0,i.gb)(()=>s.value=r()),n)];var n,s,o}}),y),m.$$click=()=>e.onRefresh(),(0,i.gb)(t=>{var n={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"list"===e.config.layout,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"list"!==e.config.layout},r={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"grid"===e.config.layout,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"grid"!==e.config.layout},s={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"compact"===e.config.layout,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"compact"!==e.config.layout},o={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"all"===e.config.contentType,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"all"!==e.config.contentType},i={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"long-form"===e.config.contentType,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"long-form"!==e.config.contentType},l={"nbw-active nbw-bg-blue-600 nbw-text-white nbw-border-blue-600":"short-form"===e.config.contentType,"nbw-bg-white nbw-text-gray-700 nbw-border-gray-300 hover:nbw-bg-gray-50":"short-form"!==e.config.contentType};return t.e=(0,a.pP)(c,n,t.e),t.t=(0,a.pP)(u,r,t.t),t.a=(0,a.pP)(h,s,t.a),t.o=(0,a.pP)(f,o,t.o),t.i=(0,a.pP)(p,i,t.i),t.n=(0,a.pP)(g,l,t.n),t},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),s;var s,o,l,c,u,h,d,f,p,g,w,b,y,m};(0,a.z_)(["click"]);var Xe=(0,a.vs)('<div class="nbw-bg-red-100 nbw-border nbw-border-red-400 nbw-text-red-700 nbw-px-4 nbw-py-3 nbw-rounded nbw-mb-4">'),et=(0,a.vs)('<div class="nbw-font-sans nbw-antialiased">'),tt=(0,a.vs)('<svg class="nbw-animate-spin nbw-h-5 nbw-w-5 nbw-inline nbw-mr-2"fill=none viewBox="0 0 24 24"><circle class=nbw-opacity-25 cx=12 cy=12 r=10 stroke=currentColor stroke-width=4></circle><path class=nbw-opacity-75 fill=currentColor d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">'),nt=(0,a.vs)('<div class="nbw-load-more-container nbw-flex nbw-justify-center nbw-mt-8"><button class="nbw-load-more-btn nbw-px-6 nbw-py-3 nbw-bg-blue-600 nbw-text-white nbw-font-medium nbw-rounded-lg hover:nbw-bg-blue-700 nbw-transition-all nbw-shadow-md hover:nbw-shadow-lg disabled:nbw-opacity-50 disabled:nbw-cursor-not-allowed">');const rt=e=>{const[t,n]=(0,i.n5)([]),[r,s]=(0,i.n5)([]),[o,u]=(0,i.n5)(0),[h,d]=(0,i.n5)(null),[f,p]=(0,i.n5)(!0),[g,w]=(0,i.n5)(!1),[b,y]=(0,i.n5)(null),[m,v]=(0,i.n5)(e.config),k=(0,c.createRouter)(),x=new l.NostrService(m().relays),E=async(e=!1)=>{try{e?w(!0):p(!0),y(null);const t=m(),r=3*t.postsPerPage,i=await x.fetchPosts(t.pubkey,r,t.contentType,t.dateRange);s(i);const a=t.selectedAuthor?i.filter(e=>e.pubkey===t.selectedAuthor):i;u(e?Math.min(o()+t.postsPerPage,a.length):Math.min(t.postsPerPage,a.length));const l=a.slice(0,o());n(l),p(!1),w(!1)}catch(e){y("Failed to load posts. Please try again later."),p(!1),w(!1),console.error("Error fetching posts:",e)}},S=()=>{const e=o(),t=r(),s=m(),i=s.selectedAuthor?t.filter(e=>e.pubkey===s.selectedAuthor):t,a=Math.min(e+s.postsPerPage,i.length);u(a),n(i.slice(0,a))};(0,i.EH)(()=>{m(),E()}),(0,i.EH)(async()=>{const e=k.route();if("detail"===e.view&&e.postId){const n=t().find(t=>t.id===e.postId);if(n)d(n);else try{p(!0);const t=await x.fetchPostById(e.postId);d(t),p(!1)}catch(e){y("Failed to load post."),p(!1),console.error("Error fetching post:",e)}}else d(null)}),(0,i.Ki)(()=>{x.close()});const A=e=>{v({...m(),layout:e})},T=e=>{v({...m(),contentType:e})},$=e=>{const t=Math.floor(Date.now()/1e3);let n;switch(e){case"week":n={since:t-604800};break;case"month":n={since:t-2592e3};break;case"year":n={since:t-31536e3};break;default:n=void 0}v({...m(),dateRange:n})},R=e=>{v({...m(),selectedAuthor:e})};return I=et(),(0,a.Yr)(I,(0,i.a0)(i.wv,{get when(){return b()},get children(){var e=Xe();return(0,a.Yr)(e,b),e}}),null),(0,a.Yr)(I,(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!m().showControls)()&&"list"===k.route().view},get children(){return(0,i.a0)(Qe,{get config(){return m()},get posts(){return r()},onLayoutChange:A,onContentTypeChange:T,onDateRangeChange:$,onAuthorChange:R,onRefresh:E})}}),null),(0,a.Yr)(I,(0,i.a0)(i.wv,{get when(){return f()},get children(){return(0,i.a0)(Ze,{})}}),null),(0,a.Yr)(I,(0,i.a0)(i.wv,{get when(){return!f()},get children(){return(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>"detail"===k.route().view)()&&h()},get fallback(){return[(0,i.a0)(He,{get posts(){return t()},get config(){return m()},get onNavigate(){return k.navigateToPost},onFetchPost:e=>x.fetchPostById(e)}),(0,i.a0)(i.wv,{get when(){return(0,a.ph)(()=>!!(()=>{const e=m(),t=r(),n=e.selectedAuthor?t.filter(t=>t.pubkey===e.selectedAuthor):t;return o()<n.length})())()&&"load-more"===m().pagination},get children(){var e=nt(),t=e.firstChild;return t.$$click=S,(0,a.Yr)(t,(0,i.a0)(i.wv,{get when(){return g()},fallback:"Load More Posts",get children(){return[tt(),"Loading..."]}})),(0,i.gb)(()=>t.disabled=g()),e}})]},children:e=>(0,i.a0)(Ve,{get post(){return e()},get config(){return m()},get onBack(){return k.navigateToList},onFetchPost:e=>x.fetchPostById(e)})})}}),null),(0,i.gb)(()=>(0,a.Bq)(I,"data-theme",m().theme)),I;var I};function st(){const e=document.querySelector("script[data-pubkey]");if(!e)return void console.error("NostrBlog: Could not find script tag with data-pubkey attribute");const t=e.dataset.pubkey||"";let n,r;try{n=JSON.parse(t)}catch{n=t}(e.dataset.dateSince||e.dataset.dateUntil)&&(r={},e.dataset.dateSince&&(r.since=parseInt(e.dataset.dateSince,10)),e.dataset.dateUntil&&(r.until=parseInt(e.dataset.dateUntil,10)));const o={pubkey:n,relays:JSON.parse(e.dataset.relays||'["wss://relay.damus.io", "wss://nos.lol"]'),navSelector:e.dataset.navSelector||"",contentSelector:e.dataset.contentSelector||"",layout:e.dataset.layout||"list",theme:e.dataset.theme||"light",postsPerPage:parseInt(e.dataset.postsPerPage||"10",10),showImages:"false"!==e.dataset.showImages,dateFormat:e.dataset.dateFormat||"short",contentType:e.dataset.contentType||"all",dateRange:r,showControls:"true"===e.dataset.showControls,pagination:e.dataset.pagination||"load-more",showSummary:"false"!==e.dataset.showSummary};if(!o.pubkey||Array.isArray(o.pubkey)&&0===o.pubkey.length)return void console.error("NostrBlog: pubkey is required");if(!o.contentSelector)return void console.error("NostrBlog: contentSelector is required");const l=document.querySelector(o.contentSelector);if(!l)return void console.error(`NostrBlog: Could not find element with selector "${o.contentSelector}"`);const c=o.navSelector?document.querySelector(o.navSelector):null;(0,a.XX)(()=>(0,i.a0)(rt,{config:o}),l),c&&s.e(485).then(s.bind(s,485)).then(({Navigation:e})=>{Promise.resolve().then(s.bind(s,261)).then(({NostrService:t})=>{Promise.resolve().then(s.bind(s,168)).then(({createRouter:n})=>{const r=new t(o.relays),s=n();r.fetchPosts(o.pubkey).then(t=>{(0,a.XX)(()=>(0,i.a0)(e,{posts:t,get currentPostId(){return s.route().postId},get onNavigate(){return s.navigateToPost},get onHome(){return s.navigateToList}}),c)})})})}),console.log("NostrBlog initialized with config:",o)}(0,a.z_)(["click"]),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",st):st();const ot={init:st};return o.default})());
3
3
  //# sourceMappingURL=nostr-blog.js.map