Back to Composer
SOURCE / PINNED RELEASE

Made of little things.

Composer

Release
5bb4d85eb6f6…
Author-recorded commit
Not provided
License
Check the original source

The hash-verified playable HTML, which may contain bundled or minified code. This view does not execute it.

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" /><title>Composer</title><meta name="description" content="Write a Nostr note: a new one, a reply, or a quote."><meta name="napplet-id" content="composer"><meta name="napplet-archetype" content="composer"><meta name="napplet-intent" content="napplet:composer/open"><meta name="napplet-requires" content="identity outbox relay"><meta name="napplet-optional" content="inc intent link resource storage theme"><link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAMAAADDpiTIAAAAllBMVEX////1sIz3waT739HrYxz99O/1sY3qWAz5zrfudzr74NL99fD0rIb51cPvgknsbSvzoXf1tpXxl2j4y7T86uD86uH4xq3tdjf51cL3wKPxk2Ltbi3ufULwjFjrYBjvhU3zonf0qoPxk2H4yrPzoXbsZyL3v6LvgUjymm33v6H2t5fxlmfvhEz2uJj0q4Xwi1f0qYLwjFfNssJoAAAACXBIWXMAAAsSAAALEgHS3X78AAAJi0lEQVR42u3d2XbbRhaG0TLFBKRFkSJF2bLjeYgz9vD+L9fpYa3OIGsAUcApnP3d5k7/DswBLJROqSv+BAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEAAD+BAAIAAEgAASAABAAAkAACAA9rt2njzfHUs5uXvxzCUC6Pp2V3/VxC0Cqfj6WP3WzBSBNy5tyS38DIEnrY7m1F0sAUuz/TflKZ0sAMu8fXgAAlfePLgCA2vsHFwBA9f1jCwCg/v6hBQAwwv6RBQAwxv6BBQAwyv5xBQAwzv5hBQAw0v5RBQDQv+WxlOYFANC/s1LaFwBA7w6lzEAAAGP9AxBUAAB925QyBwEA9O1YZiEAgL5vAUuZhQAAenZZ5iEAgJ5dlHkIAGCsDwGCCgCg7x+uzEMAAFMACCQAgEkAxBEAwDQAwggAYPx3AaEEANCzqzIPAQCM/kFQLAEA9GxX5iEAgL49nYcAALrx7geJKACA3l3PQgAAvXtd5iAAgP4t5iAAgIlfB04tAIATWp63LwCAU1q3LwCA5AIAuPc6/+XLl+V8BQBwd7sX9xz3N5QAAGL//vebdWUBLwCI/fvv6gIuAYj9+//qAnYAxD7/obaABQDBz/+oLWAHQPDzXyoL2AMQ/fyfugKOAIQ//6mugB0A4c//qirgEoD457/VFLABoIHz/yoKWADQwvmP9QRcANDE+Z/VBADQyPmvtQTsAWjk/N9KArwIbOb85zoCDgA0c/53FQE+CGro/PcKAp52ADR0/v/wAjYAtPT8h8EFnC8BaGn/wQVs3BDS1v4DC5jmAgDACfsPK+B1B0Br+w8pYNMB0N7+wwlYdAC0uP9QAhZ+G9jo/sMIWPh1cLP7DyFg4XyAhvc/XcDCCSFN73+qgIUzghrf/zQBC6eENb//KQIWzgmcwf79BSycFDqL/fsKWDgreCb73yngOu7+qQEMuv9dApYXsT7/B6DG/ncJ6Pa3ff976ACY0/53Ctj+5SKw8cygue1/p4Buu/jdi8Hr/a7z1LDZ7X+3gN8MbPYXv7W53HWeHDrL/e8TELBi/9wCiv1zCyj2zy2g2D+3gGL/3AKK/XMLKPbPLaDYP7eAYv/cAor9cwso9s8toNg/t4Bi/9wCiv1zCyj2zy2g2L9qxyUAmfePcedvegAT7j/Ng4AACLN/KQDk3h+A5PsDkHz/KwBS71+2AKTef9EBYH8A7A+A/QGwPwD2B8D+ANgfAPsDYH8A7A+A/QGwPwD2B8D+ANgfAPsDYH8A7A+A/QGwPwD2B8D+ANgfAPsDYH8A7A+A/QGwPwD2B8D+ANg/PQD75wZg/9wA7J8bgP1zA7B/bgD2zw3A/rkB2D83APvnBmD/3ADsnxuA/XMDsH9uAPbPDcD+uQHYPzcA++cGYP/cAOyfG4D9cwOwf24A9s8NwP65Adg/NwD7JwdwZv/UAF7bPzeAjf1zA7iyf24Ae/vnBnBp/9wAdvZP/jZwb//knwRe2D83gOVT++f+MmgKAQn2b+jr4PEFZNg/JICfb443n6YXkGL/iABe/OfPf7acWECO/QMCOPxvgIkFJNk/IICbEkFAlv3jAVj+f4QJBaTZPx6AbQkgIM/+8QD84av/iQQk2j8egD9+5juJgEz7xwPwpzEmEJBq/3AA1mVqAbn2Dwfgr7d+jCwg2f7hANxy99+oArLtHw7AsUwqIN3+0QDcfu/XaALy7R8NwKFMKSDh/tEAfO3ev1EEZNw/GoCv/gZwBAEp9w8GYPn1eaoLyLl/MADbMpmApPsHA3Dnj0CrCsi6fzAAd9/9X1FA2v2DAbhnpmoC8u4fC8C6TCMg8f6xANz/I+AqAjLvHwvAA86BqCAg9f6xABzLBAJy7x8KwMNOARhYQPL9QwE4lPEFZN8/FICHngIxoID0+4cC8ODTIAcTYP9IAJYPH24gAfYPBWBbRhZg/1gAHnUc6AAC7B8MwOPOgTpZgP2jAXjkBfxEAfaPBmBdxhRg/3AAHn8c7AkC7B8PQI8TwXsLsH9AAMcymgD7BwTQ7zzoXgLsHxHAoYwlwP4hAfQ9D/zRAuwfE0Dv54I9UoD9YwJYljKKAPsHBbAtowiwf1QAJz0Y7sEC7B8WwGlPBHmgAPvHBXDirf0PEmD/uADWpb4A+wcGcPqDAe8VYP/IAAZ4Nuw9AuwfGsCx1BFwZf8mAAzzZNBbBHSb83//l/NLS4cGcCjVBHTbw2Fr5+AAhnoy7K0CFB/AWSEgM4BlKQRkBrAtBKQGsCkEpAYw7LPhCWgOwMCHPhPQGIB1ISA1gMtCQGoAV4WA1ACOhYDMAHalEJAZwKEKgPLRuI0A2NcBUHwH2AiAs0oANtZtAsCy0v5lb90mAGxrAThYtwkAm0r7X3sb0AaAizr7n6+N2waAKvNfXPr/vxEAg38TdH116X/+hgAM+k3Q0/1hZ9O2AAz2TdDFZuuy3yCAo6t+agA7V/3cAA6u+rkB7F31cwM4c9VPDWDpqp8bwNZVPzeAjat+bgAXrvq5Abjq5wawdtXPDWDrqu8K4KrvRaCrfloA63NX/dwfBa+vXPUdECEABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAAC4L+9+vDh3ZMG+vDhl88ADN3nfzxbNdRPvwAwZG/erVrrx1cADNZ3P60a7O8ADLX/s1WTvQNgmOt/o/uvVm8BGKInq2Z7DsDpvW13/9UTAE7vx4YBrF4BcGrPW95/9R6AU/uhaQDPADi1b5sGMOLLwLkCeAZAbgBt7796CQAAAPgnAAAvAgHI+DZw5W3gqb3yQVDyj4K/bxnAWwC6zF8G/erLoAH61UvA3AA+N/tO8HUHQOeWMACSCnjZATBUb9r7OOh7t4UP2vP3bc3/8k0HwMBXgbcvf/i2hd6/fP1d56dhAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABAAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAANDI/QtkPXV5WeH2lgAAAABJRU5ErkJggg==" type="image/png">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover, interactive-widget=resizes-content" />
    
    
    <script type="module" crossorigin>var js=Object.defineProperty;var Ds=(e,t,n)=>t in e?js(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var k=(e,t,n)=>Ds(e,typeof t!="symbol"?t+"":t,n);var Dn=function(e,t){return Dn=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[i]=r[i])},Dn(e,t)};function he(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Dn(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function zs(e,t,n,r){function i(o){return o instanceof n?o:new n(function(s){s(o)})}return new(n||(n=Promise))(function(o,s){function a(l){try{u(r.next(l))}catch(f){s(f)}}function c(l){try{u(r.throw(l))}catch(f){s(f)}}function u(l){l.done?o(l.value):i(l.value).then(a,c)}u((r=r.apply(e,t||[])).next())})}function Zi(e,t){var n={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},r,i,o,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(u){return function(l){return c([u,l])}}function c(u){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,u[0]&&(n=0)),n;)try{if(r=1,i&&(o=u[0]&2?i.return:u[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,u[1])).done)return o;switch(i=0,o&&(u=[u[0]&2,o.value]),u[0]){case 0:case 1:o=u;break;case 4:return n.label++,{value:u[1],done:!1};case 5:n.label++,i=u[1],u=[0];continue;case 7:u=n.ops.pop(),n.trys.pop();continue;default:if(o=n.trys,!(o=o.length>0&&o[o.length-1])&&(u[0]===6||u[0]===2)){n=0;continue}if(u[0]===3&&(!o||u[1]>o[0]&&u[1]<o[3])){n.label=u[1];break}if(u[0]===6&&n.label<o[1]){n.label=o[1],o=u;break}if(o&&n.label<o[2]){n.label=o[2],n.ops.push(u);break}o[2]&&n.ops.pop(),n.trys.pop();continue}u=t.call(e,n)}catch(l){u=[6,l],i=0}finally{r=o=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function ct(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ve(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,o=[],s;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)o.push(i.value)}catch(a){s={error:a}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(s)throw s.error}}return o}function Ke(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,o;r<i;r++)(o||!(r in t))&&(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}function ot(e){return this instanceof ot?(this.v=e,this):new ot(e)}function Fs(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(p){return function(y){return Promise.resolve(y).then(p,f)}}function a(p,y){r[p]&&(i[p]=function(d){return new Promise(function(g,b){o.push([p,d,g,b])>1||c(p,d)})},y&&(i[p]=y(i[p])))}function c(p,y){try{u(r[p](y))}catch(d){h(o[0][3],d)}}function u(p){p.value instanceof ot?Promise.resolve(p.value.v).then(l,f):h(o[0][2],p)}function l(p){c("next",p)}function f(p){c("throw",p)}function h(p,y){p(y),o.shift(),o.length&&c(o[0][0],o[0][1])}}function Vs(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof ct=="function"?ct(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(o){n[o]=e[o]&&function(s){return new Promise(function(a,c){s=e[o](s),i(a,c,s.done,s.value)})}}function i(o,s,a,c){Promise.resolve(c).then(function(u){o({value:u,done:a})},s)}}function M(e){return typeof e=="function"}function pr(e){var t=function(r){Error.call(r),r.stack=new Error().stack},n=e(t);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var An=pr(function(e){return function(n){e(this),this.message=n?n.length+` errors occurred during unsubscription:
`+n.map(function(r,i){return i+1+") "+r.toString()}).join(`
  `):"",this.name="UnsubscriptionError",this.errors=n}});function Yt(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var we=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,n,r,i,o;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=ct(s),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(d){t={error:d}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(t)throw t.error}}else s.remove(this);var l=this.initialTeardown;if(M(l))try{l()}catch(d){o=d instanceof An?d.errors:[d]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var h=ct(f),p=h.next();!p.done;p=h.next()){var y=p.value;try{Qr(y)}catch(d){o=o??[],d instanceof An?o=Ke(Ke([],Ve(o)),Ve(d.errors)):o.push(d)}}}catch(d){r={error:d}}finally{try{p&&!p.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}}if(o)throw new An(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)Qr(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(t)}},e.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},e.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},e.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&Yt(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&Yt(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})(),Xi=we.EMPTY;function Qi(e){return e instanceof we||e&&"closed"in e&&M(e.remove)&&M(e.add)&&M(e.unsubscribe)}function Qr(e){M(e)?e():e.unsubscribe()}var Ks={Promise:void 0},Ws={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,Ke([e,t],Ve(n)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function Ji(e){Ws.setTimeout(function(){throw e})}function zn(){}function Vt(e){e()}var yr=(function(e){he(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,Qi(n)&&n.add(r)):r.destination=Zs,r}return t.create=function(n,r,i){return new _t(n,r,i)},t.prototype.next=function(n){this.isStopped||this._next(n)},t.prototype.error=function(n){this.isStopped||(this.isStopped=!0,this._error(n))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(n){this.destination.next(n)},t.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(we),Gs=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(r){Dt(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){Dt(r)}else Dt(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){Dt(n)}},e})(),_t=(function(e){he(t,e);function t(n,r,i){var o=e.call(this)||this,s;return M(n)||!n?s={next:n??void 0,error:r??void 0,complete:i??void 0}:s=n,o.destination=new Gs(s),o}return t})(yr);function Dt(e){Ji(e)}function Ys(e){throw e}var Zs={closed:!0,next:zn,error:Ys,complete:zn},gr=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Ze(e){return e}function Xs(e){return e.length===0?Ze:e.length===1?e[0]:function(n){return e.reduce(function(r,i){return i(r)},n)}}var D=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(t,n,r){var i=this,o=Js(t)?t:new _t(t,n,r);return Vt(function(){var s=i,a=s.operator,c=s.source;o.add(a?a.call(o,c):c?i._subscribe(o):i._trySubscribe(o))}),o},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(n){t.error(n)}},e.prototype.forEach=function(t,n){var r=this;return n=Jr(n),new n(function(i,o){var s=new _t({next:function(a){try{t(a)}catch(c){o(c),s.unsubscribe()}},error:o,complete:i});r.subscribe(s)})},e.prototype._subscribe=function(t){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(t)},e.prototype[gr]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return Xs(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=Jr(t),new t(function(r,i){var o;n.subscribe(function(s){return o=s},function(s){return i(s)},function(){return r(o)})})},e.create=function(t){return new e(t)},e})();function Jr(e){var t;return(t=e??Ks.Promise)!==null&&t!==void 0?t:Promise}function Qs(e){return e&&M(e.next)&&M(e.error)&&M(e.complete)}function Js(e){return e&&e instanceof yr||Qs(e)&&Qi(e)}function ea(e){return M(e==null?void 0:e.lift)}function q(e){return function(t){if(ea(t))return t.lift(function(n){try{return e(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function K(e,t,n,r,i){return new ta(e,t,n,r,i)}var ta=(function(e){he(t,e);function t(n,r,i,o,s,a){var c=e.call(this,n)||this;return c.onFinalize=s,c.shouldUnsubscribe=a,c._next=r?function(u){try{r(u)}catch(l){n.error(l)}}:e.prototype._next,c._error=o?function(u){try{o(u)}catch(l){n.error(l)}finally{this.unsubscribe()}}:e.prototype._error,c._complete=i?function(){try{i()}catch(u){n.error(u)}finally{this.unsubscribe()}}:e.prototype._complete,c}return t.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;e.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},t})(yr),na=pr(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ye=(function(e){he(t,e);function t(){var n=e.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return t.prototype.lift=function(n){var r=new ei(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new na},t.prototype.next=function(n){var r=this;Vt(function(){var i,o;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var s=ct(r.currentObservers),a=s.next();!a.done;a=s.next()){var c=a.value;c.next(n)}}catch(u){i={error:u}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}}})},t.prototype.error=function(n){var r=this;Vt(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var i=r.observers;i.length;)i.shift().error(n)}})},t.prototype.complete=function(){var n=this;Vt(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(n){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,n)},t.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},t.prototype._innerSubscribe=function(n){var r=this,i=this,o=i.hasError,s=i.isStopped,a=i.observers;return o||s?Xi:(this.currentObservers=null,a.push(n),new we(function(){r.currentObservers=null,Yt(a,n)}))},t.prototype._checkFinalizedStatuses=function(n){var r=this,i=r.hasError,o=r.thrownError,s=r.isStopped;i?n.error(o):s&&n.complete()},t.prototype.asObservable=function(){var n=new D;return n.source=this,n},t.create=function(n,r){return new ei(n,r)},t})(D),ei=(function(e){he(t,e);function t(n,r){var i=e.call(this)||this;return i.destination=n,i.source=r,i}return t.prototype.next=function(n){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.next)===null||i===void 0||i.call(r,n)},t.prototype.error=function(n){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.error)===null||i===void 0||i.call(r,n)},t.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},t.prototype._subscribe=function(n){var r,i;return(i=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&i!==void 0?i:Xi},t})(ye),eo=(function(e){he(t,e);function t(n){var r=e.call(this)||this;return r._value=n,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(n){var r=e.prototype._subscribe.call(this,n);return!r.closed&&n.next(this._value),r},t.prototype.getValue=function(){var n=this,r=n.hasError,i=n.thrownError,o=n._value;if(r)throw i;return this._throwIfClosed(),o},t.prototype.next=function(n){e.prototype.next.call(this,this._value=n)},t})(ye),br={now:function(){return(br.delegate||Date).now()},delegate:void 0},ti=(function(e){he(t,e);function t(n,r,i){n===void 0&&(n=1/0),r===void 0&&(r=1/0),i===void 0&&(i=br);var o=e.call(this)||this;return o._bufferSize=n,o._windowTime=r,o._timestampProvider=i,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=r===1/0,o._bufferSize=Math.max(1,n),o._windowTime=Math.max(1,r),o}return t.prototype.next=function(n){var r=this,i=r.isStopped,o=r._buffer,s=r._infiniteTimeWindow,a=r._timestampProvider,c=r._windowTime;i||(o.push(n),!s&&o.push(a.now()+c)),this._trimBuffer(),e.prototype.next.call(this,n)},t.prototype._subscribe=function(n){this._throwIfClosed(),this._trimBuffer();for(var r=this._innerSubscribe(n),i=this,o=i._infiniteTimeWindow,s=i._buffer,a=s.slice(),c=0;c<a.length&&!n.closed;c+=o?1:2)n.next(a[c]);return this._checkFinalizedStatuses(n),r},t.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,i=n._timestampProvider,o=n._buffer,s=n._infiniteTimeWindow,a=(s?1:2)*r;if(r<1/0&&a<o.length&&o.splice(0,o.length-a),!s){for(var c=i.now(),u=0,l=1;l<o.length&&o[l]<=c;l+=2)u=l;u&&o.splice(0,u+1)}},t})(ye),ra=(function(e){he(t,e);function t(n,r){return e.call(this)||this}return t.prototype.schedule=function(n,r){return this},t})(we),ni={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setInterval.apply(void 0,Ke([e,t],Ve(n)))},clearInterval:function(e){return clearInterval(e)},delegate:void 0},ia=(function(e){he(t,e);function t(n,r){var i=e.call(this,n,r)||this;return i.scheduler=n,i.work=r,i.pending=!1,i}return t.prototype.schedule=function(n,r){var i;if(r===void 0&&(r=0),this.closed)return this;this.state=n;var o=this.id,s=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(s,o,r)),this.pending=!0,this.delay=r,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(s,this.id,r),this},t.prototype.requestAsyncId=function(n,r,i){return i===void 0&&(i=0),ni.setInterval(n.flush.bind(n,this),i)},t.prototype.recycleAsyncId=function(n,r,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return r;r!=null&&ni.clearInterval(r)},t.prototype.execute=function(n,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(n,r);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(n,r){var i=!1,o;try{this.work(n)}catch(s){i=!0,o=s||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),o},t.prototype.unsubscribe=function(){if(!this.closed){var n=this,r=n.id,i=n.scheduler,o=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,Yt(o,this),r!=null&&(this.id=this.recycleAsyncId(i,r,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t})(ra),ri=(function(){function e(t,n){n===void 0&&(n=e.now),this.schedulerActionCtor=t,this.now=n}return e.prototype.schedule=function(t,n,r){return n===void 0&&(n=0),new this.schedulerActionCtor(this,t).schedule(r,n)},e.now=br.now,e})(),oa=(function(e){he(t,e);function t(n,r){r===void 0&&(r=ri.now);var i=e.call(this,n,r)||this;return i.actions=[],i._active=!1,i}return t.prototype.flush=function(n){var r=this.actions;if(this._active){r.push(n);return}var i;this._active=!0;do if(i=n.execute(n.state,n.delay))break;while(n=r.shift());if(this._active=!1,i){for(;n=r.shift();)n.unsubscribe();throw i}},t})(ri),sa=new oa(ia),aa=sa,un=new D(function(e){return e.complete()});function ca(e){return e&&M(e.schedule)}function to(e){return e[e.length-1]}function Mt(e){return ca(to(e))?e.pop():void 0}function no(e,t){return typeof to(e)=="number"?e.pop():t}var ro=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function io(e){return M(e==null?void 0:e.then)}function oo(e){return M(e[gr])}function so(e){return Symbol.asyncIterator&&M(e==null?void 0:e[Symbol.asyncIterator])}function ao(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function ua(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var co=ua();function uo(e){return M(e==null?void 0:e[co])}function fo(e){return Fs(this,arguments,function(){var n,r,i,o;return Zi(this,function(s){switch(s.label){case 0:n=e.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,ot(n.read())];case 3:return r=s.sent(),i=r.value,o=r.done,o?[4,ot(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,ot(i)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function lo(e){return M(e==null?void 0:e.getReader)}function re(e){if(e instanceof D)return e;if(e!=null){if(oo(e))return fa(e);if(ro(e))return la(e);if(io(e))return da(e);if(so(e))return ho(e);if(uo(e))return ha(e);if(lo(e))return pa(e)}throw ao(e)}function fa(e){return new D(function(t){var n=e[gr]();if(M(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function la(e){return new D(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()})}function da(e){return new D(function(t){e.then(function(n){t.closed||(t.next(n),t.complete())},function(n){return t.error(n)}).then(null,Ji)})}function ha(e){return new D(function(t){var n,r;try{for(var i=ct(e),o=i.next();!o.done;o=i.next()){var s=o.value;if(t.next(s),t.closed)return}}catch(a){n={error:a}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}t.complete()})}function ho(e){return new D(function(t){ya(e,t).catch(function(n){return t.error(n)})})}function pa(e){return ho(fo(e))}function ya(e,t){var n,r,i,o;return zs(this,void 0,void 0,function(){var s,a;return Zi(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=Vs(e),c.label=1;case 1:return[4,n.next()];case 2:if(r=c.sent(),!!r.done)return[3,4];if(s=r.value,t.next(s),t.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),i={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),r&&!r.done&&(o=n.return)?[4,o.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function ze(e,t,n,r,i){r===void 0&&(r=0),i===void 0&&(i=!1);var o=t.schedule(function(){n(),i?e.add(this.schedule(null,r)):this.unsubscribe()},r);if(e.add(o),!i)return o}function po(e,t){return t===void 0&&(t=0),q(function(n,r){n.subscribe(K(r,function(i){return ze(r,e,function(){return r.next(i)},t)},function(){return ze(r,e,function(){return r.complete()},t)},function(i){return ze(r,e,function(){return r.error(i)},t)}))})}function yo(e,t){return t===void 0&&(t=0),q(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function ga(e,t){return re(e).pipe(yo(t),po(t))}function ba(e,t){return re(e).pipe(yo(t),po(t))}function wa(e,t){return new D(function(n){var r=0;return t.schedule(function(){r===e.length?n.complete():(n.next(e[r++]),n.closed||this.schedule())})})}function ma(e,t){return new D(function(n){var r;return ze(n,t,function(){r=e[co](),ze(n,t,function(){var i,o,s;try{i=r.next(),o=i.value,s=i.done}catch(a){n.error(a);return}s?n.complete():n.next(o)},0,!0)}),function(){return M(r==null?void 0:r.return)&&r.return()}})}function go(e,t){if(!e)throw new Error("Iterable cannot be null");return new D(function(n){ze(n,t,function(){var r=e[Symbol.asyncIterator]();ze(n,t,function(){r.next().then(function(i){i.done?n.complete():n.next(i.value)})},0,!0)})})}function va(e,t){return go(fo(e),t)}function xa(e,t){if(e!=null){if(oo(e))return ga(e,t);if(ro(e))return wa(e,t);if(io(e))return ba(e,t);if(so(e))return go(e,t);if(uo(e))return ma(e,t);if(lo(e))return va(e,t)}throw ao(e)}function ae(e,t){return t?xa(e,t):re(e)}function Bt(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Mt(e);return ae(e,n)}var Ea=pr(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function ka(e,t){var n=typeof t=="object";return new Promise(function(r,i){var o=!1,s;e.subscribe({next:function(a){s=a,o=!0},error:i,complete:function(){o?r(s):n?r(t.defaultValue):i(new Ea)}})})}function Sa(e){return e instanceof Date&&!isNaN(e)}function Me(e,t){return q(function(n,r){var i=0;n.subscribe(K(r,function(o){r.next(e.call(t,o,i++))}))})}function Aa(e,t,n,r,i,o,s,a){var c=[],u=0,l=0,f=!1,h=function(){f&&!c.length&&!u&&t.complete()},p=function(d){return u<r?y(d):c.push(d)},y=function(d){u++;var g=!1;re(n(d,l++)).subscribe(K(t,function(b){t.next(b)},function(){g=!0},void 0,function(){if(g)try{u--;for(var b=function(){var x=c.shift();s||y(x)};c.length&&u<r;)b();h()}catch(x){t.error(x)}}))};return e.subscribe(K(t,p,function(){f=!0,h()})),function(){}}function fn(e,t,n){return n===void 0&&(n=1/0),M(t)?fn(function(r,i){return Me(function(o,s){return t(r,o,i,s)})(re(e(r,i)))},n):(typeof t=="number"&&(n=t),q(function(r,i){return Aa(r,i,e,n)}))}function wr(e){return e===void 0&&(e=1/0),fn(Ze,e)}function Ia(){return wr(1)}function ii(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ia()(ae(e,Mt(e)))}function gt(e){return new D(function(t){re(e()).subscribe(t)})}function Zt(e,t,n){return e===void 0&&(e=0),n===void 0&&(n=aa),new D(function(r){var i=Sa(e)?+e-n.now():e;i<0&&(i=0);var o=0;return n.schedule(function(){r.closed||(r.next(o++),r.complete())},i)})}function ut(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Mt(e),r=no(e,1/0),i=e;return i.length?i.length===1?re(i[0]):wr(r)(ae(i,n)):un}function ge(e,t){return q(function(n,r){var i=0;n.subscribe(K(r,function(o){return e.call(t,o,i++)&&r.next(o)}))})}function bo(e,t,n,r,i){return function(o,s){var a=n,c=t,u=0;o.subscribe(K(s,function(l){var f=u++;c=a?e(c,l,f):(a=!0,l),r&&s.next(c)},i&&(function(){a&&s.next(c),s.complete()})))}}function $a(e,t){return q(bo(e,t,arguments.length>=2,!1,!0))}var _a=function(e,t){return e.push(t),e};function Ba(){return q(function(e,t){$a(_a,[])(e).subscribe(t)})}function Ta(e){return e<=0?function(){return un}:q(function(t,n){var r=0;t.subscribe(K(n,function(i){++r<=e&&(n.next(i),e<=r&&n.complete())}))})}function mr(e,t){return t===void 0&&(t=Ze),e=e??Ca,q(function(n,r){var i,o=!0;n.subscribe(K(r,function(s){var a=t(s);(o||!e(i,a))&&(o=!1,i=a,r.next(s))}))})}function Ca(e,t){return e===t}function ln(e){return q(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function La(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Mt(e),r=no(e,1/0);return q(function(i,o){wr(r)(ae(Ke([i],Ve(e)),n)).subscribe(o)})}function Fn(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return La.apply(void 0,Ke([],Ve(e)))}function Oa(e){e===void 0&&(e=1/0);var t;e&&typeof e=="object"?t=e:t={count:e};var n=t.count,r=n===void 0?1/0:n,i=t.delay,o=t.resetOnSuccess,s=o===void 0?!1:o;return r<=0?Ze:q(function(a,c){var u=0,l,f=function(){var h=!1;l=a.subscribe(K(c,function(p){s&&(u=0),c.next(p)},void 0,function(p){if(u++<r){var y=function(){l?(l.unsubscribe(),l=null,f()):h=!0};if(i!=null){var d=typeof i=="number"?Zt(i):re(i(p,u)),g=K(c,function(){g.unsubscribe(),y()},function(){c.complete()});d.subscribe(g)}else y()}else c.error(p)})),h&&(l.unsubscribe(),l=null,f())};f()})}function Ra(e,t){return q(bo(e,t,arguments.length>=2,!0))}function Na(e){e===void 0&&(e={});var t=e.connector,n=t===void 0?function(){return new ye}:t,r=e.resetOnError,i=r===void 0?!0:r,o=e.resetOnComplete,s=o===void 0?!0:o,a=e.resetOnRefCountZero,c=a===void 0?!0:a;return function(u){var l,f,h,p=0,y=!1,d=!1,g=function(){f==null||f.unsubscribe(),f=void 0},b=function(){g(),l=h=void 0,y=d=!1},x=function(){var E=l;b(),E==null||E.unsubscribe()};return q(function(E,B){p++,!d&&!y&&g();var A=h=h??n();B.add(function(){p--,p===0&&!d&&!y&&(f=In(x,c))}),A.subscribe(B),!l&&p>0&&(l=new _t({next:function(v){return A.next(v)},error:function(v){d=!0,g(),f=In(b,i,v),A.error(v)},complete:function(){y=!0,g(),f=In(b,s),A.complete()}}),re(E).subscribe(l))})(u)}}function In(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(t===!0){e();return}if(t!==!1){var i=new _t({next:function(){i.unsubscribe(),e()}});return re(t.apply(void 0,Ke([],Ve(n)))).subscribe(i)}}function Ma(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Mt(e);return q(function(r,i){(n?ii(e,r,n):ii(e,r)).subscribe(i)})}function Ua(e,t){return q(function(n,r){var i=null,o=0,s=!1,a=function(){return s&&!i&&r.complete()};n.subscribe(K(r,function(c){i==null||i.unsubscribe();var u=0,l=o++;re(e(c,l)).subscribe(i=K(r,function(f){return r.next(t?t(c,f,l,u++):f)},function(){i=null,a()}))},function(){s=!0,a()}))})}function Pa(e){return q(function(t,n){re(e).subscribe(K(n,function(){return n.complete()},zn)),!n.closed&&t.subscribe(n)})}function dn(e,t,n){var r=M(e)||t||n?{next:e,error:t,complete:n}:e;return r?q(function(i,o){var s;(s=r.subscribe)===null||s===void 0||s.call(r);var a=!0;i.subscribe(K(o,function(c){var u;(u=r.next)===null||u===void 0||u.call(r,c),o.next(c)},function(){var c;a=!1,(c=r.complete)===null||c===void 0||c.call(r),o.complete()},function(c){var u;a=!1,(u=r.error)===null||u===void 0||u.call(r,c),o.error(c)},function(){var c,u;a&&((c=r.unsubscribe)===null||c===void 0||c.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):Ze}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const vr=e=>e instanceof Uint8Array,$n=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),ue=(e,t)=>e<<32-t|e>>>t,Ha=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ha)throw new Error("Non little-endian hardware is not supported");const qa=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function se(e){if(!vr(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=qa[e[n]];return t}function Xt(e){if(typeof e!="string")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 r=0;r<n.length;r++){const i=r*2,o=e.slice(i,i+2),s=Number.parseInt(o,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function ja(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function wo(e){if(typeof e=="string"&&(e=ja(e)),!vr(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function Da(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!vr(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}let za=class{clone(){return this._cloneInto()}};function mo(e){const t=r=>e().update(wo(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function bt(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function me(...e){const t=(i,o)=>s=>i(o(s)),n=Array.from(e).reverse().reduce((i,o)=>i?t(i,o.encode):o.encode,void 0),r=e.reduce((i,o)=>i?t(i,o.decode):o.decode,void 0);return{encode:n,decode:r}}function ve(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(n=>{if(bt(n),n<0||n>=e.length)throw new Error(`Digit index outside alphabet: ${n} (alphabet: ${e.length})`);return e[n]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(n=>{if(typeof n!="string")throw new Error(`alphabet.decode: not string element=${n}`);const r=e.indexOf(n);if(r===-1)throw new Error(`Unknown letter: "${n}". Allowed: ${e}`);return r})}}}function xe(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let n of t)if(typeof n!="string")throw new Error(`join.encode: non-string input=${n}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function hn(e,t="="){if(bt(e),typeof t!="string")throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let r of n)if(typeof r!="string")throw new Error(`padding.encode: non-string input=${r}`);for(;n.length*e%8;)n.push(t);return n},decode(n){if(!Array.isArray(n)||n.length&&typeof n[0]!="string")throw new Error("padding.encode input should be array of strings");for(let i of n)if(typeof i!="string")throw new Error(`padding.decode: non-string input=${i}`);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 vo(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function oi(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 i=[],o=Array.from(e);for(o.forEach(s=>{if(bt(s),s<0||s>=t)throw new Error(`Wrong integer: ${s}`)});;){let s=0,a=!0;for(let c=r;c<o.length;c++){const u=o[c],l=t*s+u;if(!Number.isSafeInteger(l)||t*s/t!==s||l-u!==t*s)throw new Error("convertRadix: carry overflow");if(s=l%n,o[c]=Math.floor(l/n),!Number.isSafeInteger(o[c])||o[c]*n+s!==l)throw new Error("convertRadix: carry overflow");if(a)o[c]?a=!1:r=c;else continue}if(i.push(s),a)break}for(let s=0;s<e.length-1&&e[s]===0;s++)i.push(0);return i.reverse()}const xo=(e,t)=>t?xo(t,e%t):e,Qt=(e,t)=>e+(t-xo(e,t));function Vn(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(Qt(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Qt(t,n)}`);let i=0,o=0;const s=2**n-1,a=[];for(const c of e){if(bt(c),c>=2**t)throw new Error(`convertRadix2: invalid data word=${c} from=${t}`);if(i=i<<t|c,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)a.push((i>>o-n&s)>>>0);i&=2**o-1}if(i=i<<n-o&s,!r&&o>=t)throw new Error("Excess padding");if(!r&&i)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&a.push(i>>>0),a}function Fa(e){return bt(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return oi(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(oi(t,e,2**8))}}}function Ue(e,t=!1){if(bt(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Qt(8,e)>32||Qt(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 Vn(Array.from(n),8,e,!t)},decode:n=>{if(!Array.isArray(n)||n.length&&typeof n[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(Vn(n,e,8,t))}}}function si(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const Va=me(Ue(4),ve("0123456789ABCDEF"),xe("")),Ka=me(Ue(5),ve("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),hn(5),xe(""));me(Ue(5),ve("0123456789ABCDEFGHIJKLMNOPQRSTUV"),hn(5),xe(""));me(Ue(5),ve("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),xe(""),vo(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const Wa=me(Ue(6),ve("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),hn(6),xe("")),Ga=me(Ue(6),ve("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),hn(6),xe("")),xr=e=>me(Fa(58),ve(e),xe("")),Kn=xr("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");xr("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");xr("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const ai=[0,2,3,5,6,7,9,10,11],Ya={encode(e){let t="";for(let n=0;n<e.length;n+=8){const r=e.subarray(n,n+8);t+=Kn.encode(r).padStart(ai[r.length],"1")}return t},decode(e){let t=[];for(let n=0;n<e.length;n+=11){const r=e.slice(n,n+11),i=ai.indexOf(r.length),o=Kn.decode(r);for(let s=0;s<o.length-i;s++)if(o[s]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(o.slice(o.length-i)))}return Uint8Array.from(t)}},Wn=me(ve("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),xe("")),ci=[996825010,642813549,513874426,1027748829,705979059];function xt(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r<ci.length;r++)(t>>r&1)===1&&(n^=ci[r]);return n}function ui(e,t,n=1){const r=e.length;let i=1;for(let o=0;o<r;o++){const s=e.charCodeAt(o);if(s<33||s>126)throw new Error(`Invalid prefix (${e})`);i=xt(i)^s>>5}i=xt(i);for(let o=0;o<r;o++)i=xt(i)^e.charCodeAt(o)&31;for(let o of t)i=xt(i)^o;for(let o=0;o<6;o++)i=xt(i);return i^=n,Wn.encode(Vn([i%2**30],30,5,!1))}function Eo(e){const t=e==="bech32"?1:734539939,n=Ue(5),r=n.decode,i=n.encode,o=si(r);function s(l,f,h=90){if(typeof l!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof l}`);if(!Array.isArray(f)||f.length&&typeof f[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof f}`);const p=l.length+7+f.length;if(h!==!1&&p>h)throw new TypeError(`Length ${p} exceeds limit ${h}`);return l=l.toLowerCase(),`${l}1${Wn.encode(f)}${ui(l,f,t)}`}function a(l,f=90){if(typeof l!="string")throw new Error(`bech32.decode input should be string, not ${typeof l}`);if(l.length<8||f!==!1&&l.length>f)throw new TypeError(`Wrong string length: ${l.length} (${l}). Expected (8..${f})`);const h=l.toLowerCase();if(l!==h&&l!==l.toUpperCase())throw new Error("String must be lowercase or uppercase");l=h;const p=l.lastIndexOf("1");if(p===0||p===-1)throw new Error('Letter "1" must be present between prefix and data only');const y=l.slice(0,p),d=l.slice(p+1);if(d.length<6)throw new Error("Data must be at least 6 characters long");const g=Wn.decode(d).slice(0,-6),b=ui(y,g,t);if(!d.endsWith(b))throw new Error(`Invalid checksum in ${l}: expected "${b}"`);return{prefix:y,words:g}}const c=si(a);function u(l){const{prefix:f,words:h}=a(l,!1);return{prefix:f,words:h,bytes:r(h)}}return{encode:s,decode:a,decodeToBytes:u,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:o,toWords:i}}const Jt=Eo("bech32");Eo("bech32m");const Za={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},Xa=me(Ue(4),ve("0123456789abcdef"),xe(""),vo(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})),Qa={utf8:Za,hex:Xa,base16:Va,base32:Ka,base64:Wa,base64url:Ga,base58:Kn,base58xmr:Ya};`${Object.keys(Qa).join(", ")}`;var zt=new TextDecoder("utf-8"),ko=new TextEncoder,So=5e3;function Ja(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=e&255,t}function wt(e){var i,o,s,a,c,u,l;let{prefix:t,words:n}=Jt.decode(e,So),r=new Uint8Array(Jt.fromWords(n));switch(t){case"nprofile":{let f=_n(r);if(!((i=f[0])!=null&&i[0]))throw new Error("missing TLV 0 for nprofile");if(f[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:se(f[0][0]),relays:f[1]?f[1].map(h=>zt.decode(h)):[]}}}case"nevent":{let f=_n(r);if(!((o=f[0])!=null&&o[0]))throw new Error("missing TLV 0 for nevent");if(f[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(f[2]&&f[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(f[3]&&f[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:se(f[0][0]),relays:f[1]?f[1].map(h=>zt.decode(h)):[],author:(s=f[2])!=null&&s[0]?se(f[2][0]):void 0,kind:(a=f[3])!=null&&a[0]?parseInt(se(f[3][0]),16):void 0}}}case"naddr":{let f=_n(r);if(!((c=f[0])!=null&&c[0]))throw new Error("missing TLV 0 for naddr");if(!((u=f[2])!=null&&u[0]))throw new Error("missing TLV 2 for naddr");if(f[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((l=f[3])!=null&&l[0]))throw new Error("missing TLV 3 for naddr");if(f[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:zt.decode(f[0][0]),pubkey:se(f[2][0]),kind:parseInt(se(f[3][0]),16),relays:f[1]?f[1].map(h=>zt.decode(h)):[]}}}case"nsec":return{type:t,data:r};case"npub":case"note":return{type:t,data:se(r)};default:throw new Error(`unknown prefix ${t}`)}}function _n(e){let t={},n=e;for(;n.length>0;){let r=n[0],i=n[1],o=n.slice(2,2+i);if(n=n.slice(2+i),o.length<i)throw new Error(`not enough data to read on TLV ${r}`);t[r]=t[r]||[],t[r].push(o)}return t}function ft(e){return ec("npub",Xt(e))}function Er(e,t){let n=Jt.toWords(t);return Jt.encode(e,n,So)}function ec(e,t){return Er(e,t)}function tc(e){let t=Io({0:[Xt(e.pubkey)],1:(e.relays||[]).map(n=>ko.encode(n))});return Er("nprofile",t)}function Ao(e){let t;e.kind!==void 0&&(t=Ja(e.kind));let n=Io({0:[Xt(e.id)],1:(e.relays||[]).map(r=>ko.encode(r)),2:e.author?[Xt(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return Er("nevent",n)}function Io(e){let t=[];return Object.entries(e).reverse().forEach(([n,r])=>{r.forEach(i=>{let o=new Uint8Array(i.length+2);o.set([parseInt(n)],0),o.set([i.length],1),o.set(i,2),t.push(o)})}),Da(...t)}const nc=1,Tt=/^[0-9a-f]{64}$/,rc=/nostr:((?:npub1|nprofile1|note1|nevent1)[023456789acdefghjklmnpqrstuvwxyz]+)/gi,ic=/(?:^|[^\p{L}\p{N}_/&#])#([\p{L}\p{N}_]{1,64})/gu;function oc(e){const t=e.tags.filter(i=>i[0]==="e"&&Tt.test(i[1]??"")),n=t.find(i=>i[3]==="root");if(n)return{id:n[1],relay:n[2]??"",pubkey:Tt.test(n[4]??"")?n[4]:""};const r=t.filter(i=>!i[3]);return r.length?{id:r[0][1],relay:r[0][2]??"",pubkey:""}:null}function sc(e,t,n=""){const r=oc(e),i=[];!r||r.id===e.id?i.push(["e",e.id,n,"root",e.pubkey]):(i.push(["e",r.id,r.relay,"root",...r.pubkey?[r.pubkey]:[]]),i.push(["e",e.id,n,"reply",e.pubkey]));const o=new Set;o.add(e.pubkey);for(const s of e.tags)s[0]==="p"&&Tt.test(s[1]??"")&&o.add(s[1]);o.delete(t);for(const s of o)i.push(["p",s]);return i}function ac(e,t=""){return`nostr:${Ao({id:e.id,author:e.pubkey,kind:e.kind,relays:t?[t]:[]})}`}function cc(e,t,n=""){for(const i of kr(e))if(i.type==="event"&&i.id===t.id)return e;const r=e.replace(/\s+$/,"");return`${r}${r?`

`:""}${ac(t,n)}`}function kr(e){var n;const t=[];for(const r of e.matchAll(rc))try{const i=wt(r[1].toLowerCase());i.type==="npub"?t.push({type:"person",pubkey:i.data}):i.type==="nprofile"?t.push({type:"person",pubkey:i.data.pubkey}):i.type==="note"?t.push({type:"event",id:i.data}):i.type==="nevent"&&t.push({type:"event",id:i.data.id,...i.data.author?{author:i.data.author}:{},...(n=i.data.relays)!=null&&n[0]?{relay:i.data.relays[0]}:{}})}catch{}return t}function uc(e){const t=new Set;for(const n of e.matchAll(ic)){const r=n[1].toLowerCase();/^\d+$/.test(r)||t.add(r)}return[...t]}function fc(e){return e.content.trim().length>0||!!e.quote}function $o(e,t,n=Math.floor(Date.now()/1e3)){var c;let r=e.content.replace(/\s+$/,"");e.quote&&(r=cc(r,e.quote,e.quoteRelay));const i=[],o=new Set,s=new Set,a=u=>{u===t||o.has(u)||!Tt.test(u)||(o.add(u),i.push(["p",u]))};if(e.replyTo)for(const u of sc(e.replyTo,t,e.replyRelay))u[0]==="p"?a(u[1]):i.push(u);e.quote&&(s.add(e.quote.id),i.push(["q",e.quote.id,e.quoteRelay??"",e.quote.pubkey]),a(e.quote.pubkey));for(const u of kr(r))u.type==="person"?a(u.pubkey):!s.has(u.id)&&u.id!==((c=e.replyTo)==null?void 0:c.id)&&(s.add(u.id),i.push(["q",u.id,u.relay??"",...u.author?[u.author]:[]]),u.author&&a(u.author));for(const u of uc(r))i.push(["t",u]);return{kind:nc,content:r,tags:i,created_at:n}}function lc(e,t,n){var o,s;const r=new Set,i=a=>{a&&a!==n&&Tt.test(a)&&r.add(a)};i((o=e.replyTo)==null?void 0:o.pubkey),i((s=e.quote)==null?void 0:s.pubkey);for(const a of kr(t.content))a.type==="person"&&i(a.pubkey);for(const a of t.tags)a[0]==="p"&&i(a[1]);return[...r]}const Sr=/^[0-9a-f]{64}$/i,_o=/^([0-9a-f]{64})(?:\.([a-z0-9]{1,8}))?$/i;function Ut(e){try{const t=new URL(e);return t.protocol==="https:"||t.protocol==="http:"?t:null}catch{return null}}function dc(e,t,n){var u,l;if(/^blossom:/i.test(e))return yc(e,t,n);const r=Ut(e);if(r&&To(r.hostname))return null;const i=r?decodeURIComponent(r.pathname.split("/").pop()??""):"",o=_o.exec(i);let s;if(o&&(s=o[1].toLowerCase()),!s)return null;let a=(u=o==null?void 0:o[2])==null?void 0:u.toLowerCase();if(!a){const f=/\.([a-z0-9]{1,8})$/i.exec(i);a=(l=f==null?void 0:f[1])==null?void 0:l.toLowerCase()}const c=[];return r&&c.push(`xs=${r.origin}`),n&&Sr.test(n)&&c.push(`as=${n.toLowerCase()}`),`blossom:${s}${a?`.${a}`:""}${c.length?`?${c.join("&")}`:""}`}const hc=/^blossom:(?:sha256:)?([0-9a-f]{64})(?:\.([a-z0-9]{1,8}))?(?:\?(.*))?$/i;function pc(e){const t=e.trim();if(!t)return null;const n=Ut(/^https?:\/\//i.test(t)?t:`https://${t}`);return!n||!(n.hostname.includes(".")||n.hostname==="localhost")?null:n.origin}function pn(e){const t=hc.exec(e.trim());if(!t)return null;const n={sha:t[1].toLowerCase(),xs:[],as:[]};t[2]&&(n.ext=t[2].toLowerCase());for(const r of(t[3]??"").split("&")){const i=r.indexOf("=");if(i<=0)continue;const o=r.slice(0,i).toLowerCase();let s=r.slice(i+1);try{s=decodeURIComponent(s)}catch{}if(o==="xs"){const a=pc(s);a&&!n.xs.includes(a)&&n.xs.length<3&&n.xs.push(a)}else if(o==="as"){const a=s.toLowerCase();Sr.test(a)&&!n.as.includes(a)&&n.as.length<3&&n.as.push(a)}else o==="sz"&&/^\d+$/.test(s)&&s!=="0"&&(n.sz??(n.sz=s))}return n}function yc(e,t,n){const r=pn(e);if(!r)return null;const i=r.as.length?r.as:n&&Sr.test(n)?[n.toLowerCase()]:[],o=r.sz??void 0,s=[...r.xs.map(a=>`xs=${a}`),...i.map(a=>`as=${a}`),...o?[`sz=${o}`]:[]];return`blossom:${r.sha}${r.ext?`.${r.ext}`:""}${s.length?`?${s.join("&")}`:""}`}const fi=/^(?:jpe?g|png|gif|webp|avif)$/i;function Bo(e){const t=pn(e);if(t)return!t.ext||fi.test(t.ext);const n=Ut(e);if(!n||To(n.hostname))return!1;let r="";try{r=decodeURIComponent(n.pathname.split("/").pop()??"")}catch{return!1}const i=_o.exec(r);return!!i&&(!i[2]||fi.test(i[2]))}function To(e){const t=e.toLowerCase();return t==="nostr.build"||t.endsWith(".nostr.build")}function gc(e){const t=/^blossom:(?:sha256:)?([0-9a-f]{64})/i.exec(e);return t?t[1].toLowerCase():null}function bc(e){return e.replace(/^blossom:(?:sha256:)?([0-9a-f]{64})\.[a-z0-9]{1,8}/i,"blossom:$1")}function Co(e){const t=e==null?void 0:e.trim().toLowerCase();if(t){if(t.startsWith("image/")||/^(?:jpe?g|png|gif|webp|avif|heic|heif|bmp)$/.test(t))return!0;if(/^(?:video|audio|text|application)\//.test(t))return!1}}function wc(e){const t=e==null?void 0:e.trim().toLowerCase();if(t){if(t.startsWith("video/")||/^(?:mp4|webm|mov|quicktime|m4v)$/.test(t))return!0;if(Co(t)||/^(?:audio|text|application)\//.test(t))return!1}}const li=/\.(?:mp4|webm|mov|m4v)$/i;function Lo(e){const t=pn(e);if(t)return!!t.ext&&li.test(`.${t.ext}`);const n=Ut(e);return!!n&&li.test(n.pathname)}function mc(e){const t=Ut(e);return!!t&&/\.(?:jpe?g|png|gif|webp|avif)$/i.test(t.pathname)}const rt=/^[0-9a-f]{64}$/i,vc=/^wss?:\/\/\S+$/;function Gn(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&vc.test(t)).slice(0,5):[]}function di(e){const t=e.trim().replace(/^nostr:/i,"");if(rt.test(t))return{id:t.toLowerCase(),relays:[]};if(!/^(note|nevent|naddr)1[023456789acdefghjklmnpqrstuvwxyz]+$/i.test(t))return null;try{const n=wt(t.toLowerCase());if(n.type==="note")return{id:n.data,relays:[]};if(n.type==="nevent")return{id:n.data.id,relays:Gn(n.data.relays),...n.data.author?{author:n.data.author}:{},...n.data.kind!==void 0?{kind:n.data.kind}:{}};if(n.type==="naddr")return{relays:Gn(n.data.relays),author:n.data.pubkey,kind:n.data.kind,address:{kind:n.data.kind,pubkey:n.data.pubkey,identifier:n.data.identifier}}}catch{}return null}function Ar(e,t=0){if(typeof e=="string")return di(e);if(typeof e!="object"||e===null||t>2)return null;const n=e;if(n.target!==void 0){const s=Ar(n.target,t+1);if(s)return s}let r=null;for(const s of["id","eventId","event_id","note","nevent","naddr","uri","url","value"])if(typeof n[s]=="string"&&(r=di(n[s]),r))break;if(!r&&typeof n.event=="object"&&n.event!==null){const s=n.event;typeof s.id=="string"&&rt.test(s.id)&&(r={id:s.id.toLowerCase(),relays:[],...typeof s.pubkey=="string"&&rt.test(s.pubkey)?{author:s.pubkey.toLowerCase()}:{}})}if(!r&&typeof n.kind=="number"&&typeof n.pubkey=="string"&&rt.test(n.pubkey)&&typeof n.identifier=="string"&&(r={relays:[],author:n.pubkey.toLowerCase(),kind:n.kind,address:{kind:n.kind,pubkey:n.pubkey.toLowerCase(),identifier:n.identifier}}),!r)return null;const i=[...new Set([...r.relays,...Gn(n.relays)])].slice(0,5),o=r.author??(typeof n.author=="string"&&rt.test(n.author)?n.author.toLowerCase():typeof n.pubkey=="string"&&rt.test(n.pubkey)?n.pubkey.toLowerCase():void 0);return{...r,relays:i,...o?{author:o}:{}}}const St=50,xc=/^[a-z0-9-]{1,13}$/,Ec=/^[0-9a-z]+$/,kc=(BigInt(1)<<BigInt(256))-BigInt(1);function Sc(e){if(e.length!==St||!Ec.test(e))return null;let t=BigInt(0);const n=BigInt(36);for(const r of e)t=t*n+BigInt(parseInt(r,36));return t>kc?null:t.toString(16).padStart(64,"0")}function Ac(e){return xc.test(e)&&!e.endsWith("-")}function Ic(e){const t=e.toLowerCase();if(t.startsWith("npub1"))try{const i=wt(t);if(i.type==="npub")return{pubkey:i.data}}catch{}if(t.length<=St||t.length>St+13)return null;const n=t.slice(St);if(!Ac(n))return null;const r=Sc(t.slice(0,St));return r?{pubkey:r,identifier:n}:null}function $c(e){const t=e.toLowerCase().replace(/\.$/,""),n=t.indexOf(".");if(n<=0)return null;const r=t.slice(0,n),i=t.slice(n+1),o=i.split(".");return i==="nsite"||o.length>=2&&o.some(a=>a.includes("nsite"))?{label:r,gateway:i}:null}function _c(e){const t=$c(e);return!!t&&Ic(t.label)!==null}const Bc=new RegExp("(https?:\\/\\/[^\\s<>\"'`]+)|nostr:((?:npub1|nprofile1|note1|nevent1|naddr1)[023456789acdefghjklmnpqrstuvwxyz]+)|(blossom:(?:sha256:)?[0-9a-f]{64}(?:\\.[a-z0-9]{1,8})?(?:\\?[^\\s<>\"'`]*)?)|((?<![\\w@.\\/:%+-])(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z]{2,24}(?::\\d{1,5})?(?:\\/[^\\s<>\"'`]*)?)","gi"),Tc=/[.,;:!?)\]}'"]+$/;function Cc(e){try{const t=wt(e);if(t.type==="npub")return{pubkey:t.data,relays:[]};if(t.type==="nprofile")return{pubkey:t.data.pubkey,relays:t.data.relays??[]}}catch{}return null}function Oo(e,t){const n=t?{imeta:t}:{},r=wc(t==null?void 0:t.m),i=Co(t==null?void 0:t.m);return r||r===void 0&&i===void 0&&Lo(e)?{type:"video",url:e,...n}:i??(mc(e)||Bo(e))?{type:"image",url:e,...n}:null}function Lc(e,t){return Oo(e,t.get(e))??{type:"link",url:e}}function Oc(e){return pn(e)?Lo(e)?{type:"video",url:e}:Bo(e)?{type:"image",url:e}:null:null}function Rc(e,t){const n=`https://${e}`;let r;try{r=new URL(n)}catch{return null}if(r.pathname.length>1){const i=Oo(n,t.get(n)??t.get(e));if(i)return i}return _c(r.hostname)?{type:"link",url:n}:null}function Nc(e,t=new Map){var o;const n=[],r=s=>{if(!s)return;const a=n[n.length-1];(a==null?void 0:a.type)==="text"?a.text+=s:n.push({type:"text",text:s})};let i=0;for(const s of e.matchAll(Bc)){const a=s.index??0;if(r(e.slice(i,a)),i=a+s[0].length,s[1]||s[3]||s[4]){let c=s[0];const u=((o=Tc.exec(c))==null?void 0:o[0])??"";u&&(c=c.slice(0,-u.length));const l=s[1]?Lc(c,t):s[3]?Oc(c):Rc(c,t);l?n.push(l):r(c),r(u)}else if(/^n(?:pub|profile)1/i.test(s[2])){const c=Cc(s[2]);c?n.push({type:"profile",...c,text:s[0]}):r(s[0])}else{const c=Ar(s[2]);c?n.push({type:"note",pointer:c,text:s[0]}):r(s[0])}}return r(e.slice(i)),n}const yn=0,Yn=3,Zn=/^[0-9a-f]{64}$/,Mc=/^[0-9a-f]{128}$/;function Ir(e){return typeof e=="string"&&Zn.test(e)}function Uc(e){if(typeof e!="object"||e===null)return!1;const t=e;return typeof t.id=="string"&&Zn.test(t.id)&&typeof t.pubkey=="string"&&Zn.test(t.pubkey)&&typeof t.sig=="string"&&Mc.test(t.sig)&&typeof t.kind=="number"&&Number.isInteger(t.kind)&&typeof t.created_at=="number"&&typeof t.content=="string"&&Array.isArray(t.tags)&&t.tags.every(n=>Array.isArray(n)&&n.every(r=>typeof r=="string"))}function Pc(e){var n;if(!e||e.kind!==Yn)return[];const t=new Set;for(const r of e.tags){const i=(n=r[1])==null?void 0:n.toLowerCase();r[0]==="p"&&Ir(i)&&t.add(i)}return[...t]}function Et(e,t=500){return typeof e=="string"&&e.trim()?e.trim().slice(0,t):void 0}function Hc(e){if(e.kind!==yn)return null;let t;try{const n=JSON.parse(e.content);if(typeof n!="object"||n===null)return null;t=n}catch{return null}return{pubkey:e.pubkey,name:Et(t.name,80),displayName:Et(t.display_name,80)??Et(t.displayName,80),picture:Et(t.picture,2e3),nip05:Et(t.nip05,200),createdAt:e.created_at}}function qc(){const e=new Map;function t(i,o){if(e.has(i))throw new Error(`NAP domain "${i}" is already registered`);e.set(i,o)}function n(i){const o=i.type.indexOf(".");if(o<=0)return!1;const s=i.type.slice(0,o),a=e.get(s);return a?(a(i),!0):!1}function r(){return Array.from(e.keys())}return{registerNap:t,dispatch:n,getRegisteredDomains:r}}var jc=qc(),Ee=jc.registerNap,Dc="relay";function $r(){var t;const e=window;if(!((t=e.napplet)!=null&&t.relay))throw new Error("window.napplet.relay is unavailable -- runtime did not inject the relay domain");return e.napplet.relay}function zc(e,t,n,r){return $r().subscribe(e,t,n,r)}function Fc(e,t){return $r().publish(e,t)}function Vc(e){return $r().query(e)}Ee(Dc,e=>{});var Kc="identity";function Ro(){var t;const e=window;if(!((t=e.napplet)!=null&&t.identity))throw new Error("window.napplet.identity is unavailable -- runtime did not inject this domain");return e.napplet.identity}function Wc(){return Ro().getPublicKey()}function Gc(e){return Ro().onChanged(e)}Ee(Kc,e=>{});var Yc="storage";function No(){var t;const e=window;if(!((t=e.napplet)!=null&&t.storage))throw new Error("window.napplet.storage is unavailable -- runtime did not inject this domain");return e.napplet.storage}function Zc(e){return No().getItem(e)}function Xc(e,t){return No().setItem(e,t)}Ee(Yc,e=>{});var Qc="inc";function Jc(){var t;const e=window;if(!((t=e.napplet)!=null&&t.inc))throw new Error("window.napplet.inc is unavailable -- runtime did not inject this domain");return e.napplet.inc}function eu(e,t){return Jc().on(e,t)}Ee(Qc,e=>{});var tu="theme";function Mo(){var t;const e=window;if(!((t=e.napplet)!=null&&t.theme))throw new Error("window.napplet.theme is unavailable -- runtime did not inject this domain");return e.napplet.theme}function nu(){return Mo().get()}function ru(e){return Mo().onChanged(e)}Ee(tu,e=>{});var iu="resource";function Uo(){var t;const e=window;if(!((t=e.napplet)!=null&&t.resource))throw new Error("window.napplet.resource is unavailable -- runtime did not inject this domain");return e.napplet.resource}function ou(){return Uo().info()}function su(e,t){return Uo().bytes(e,t)}Ee(iu,e=>{});var au="outbox";function gn(){var t;const e=window;if(!((t=e.napplet)!=null&&t.outbox))throw new Error("window.napplet.outbox is unavailable -- runtime did not inject this domain");return e.napplet.outbox}function cu(e,t){return gn().getEvent(e,t)}function uu(e,t){return gn().subscribe(e,t)}function hi(e,t){return gn().publish(e,t)}function fu(e){return gn().resolveRelays(e)}Ee(au,e=>{});var lu="intent";function du(){var t;const e=window;if(!((t=e.napplet)!=null&&t.intent))throw new Error("window.napplet.intent is unavailable -- runtime did not inject this domain");return e.napplet.intent}function Po(e,t,n){return du().open(e,t,n)}Ee(lu,e=>{});var hu="link";function pu(){var t;const e=window;if(!((t=e.napplet)!=null&&t.link))throw new Error("window.napplet.link is unavailable -- runtime did not inject this domain");return e.napplet.link}function Ho(e,t){return pu().open(e,t)}Ee(hu,e=>{});function en(){return window.napplet}function U(e,t){var r;const n=(r=en())==null?void 0:r[e];return typeof(n==null?void 0:n[t])=="function"}function yu(e){var n,r;const t=(n=en())==null?void 0:n.shell;if(typeof(t==null?void 0:t.supports)=="function")try{return t.supports(e)===!0}catch{}return!!((r=en())!=null&&r[e])}function gu(){return typeof en()=="object"}async function bu(){if(!U("identity","getPublicKey"))return"";try{return await Wc()||""}catch{return""}}function wu(e){if(!U("identity","onChanged"))return()=>{};try{const t=Gc(e);return()=>t.close()}catch{return()=>{}}}const mu="relay list unavailable";async function vu(e){const t=[...new Set(e)];if(!t.length||!U("outbox","resolveRelays"))return[];try{const n=await fu({authors:t,direction:"write"}),r=new Set((n==null?void 0:n.missingAuthors)??[]);return t.filter(i=>!r.has(i))}catch{return[]}}async function xu(e,t={}){var n;try{if(U("outbox","publish")){const r=(n=t.toInboxes)!=null&&n.length?t.toInboxes:void 0;let i=await hi(e,r?{toInboxes:r}:void 0);return!i.ok&&r&&i.error===mu&&(i=await hi(e)),i.ok?i.event?{ok:!0,event:i.event}:{ok:!0}:{ok:!1,error:i.error||"publish refused"}}return U("relay","publish")?(await Fc(e),{ok:!0}):{ok:!1,error:"This shell cannot publish."}}catch(r){return{ok:!1,error:r instanceof Error?r.message:String(r)}}}function qo(){return U("outbox","publish")||U("relay","publish")}let pi;function Eu(){return pi??(pi=(async()=>{if(U("resource","info"))try{return await ou()}catch{return}})()),pi}function ku(){return Eu().then(e=>!!(e!=null&&e.schemes.some(t=>t.scheme==="https"&&t.enabled!==!1)))}const Su="napplet:composer/open";function Au(e,t){if(!U("inc","on"))return()=>{};try{const n=eu(e,r=>t(r.payload,r.sender));return()=>n.close()}catch{return()=>{}}}function jo(){return yu("intent")&&U("intent","open")}async function Iu(e,t=[]){if(jo())try{const n=await Po("profile",{pubkey:e,npub:ft(e)},{convention:"napplet:profile/open"});if(n!=null&&n.ok&&n.handled)return"intent"}catch{}if(U("link","open"))try{const n=t.length?`nostr:${tc({pubkey:e,relays:t.slice(0,3)})}`:`nostr:${ft(e)}`;if((await Ho(n)).status==="opened")return"link"}catch{}return"none"}async function _r(e){const t=Ao({id:e.id,relays:(e.relays??[]).slice(0,3),...e.author?{author:e.author}:{},...e.kind!==void 0?{kind:e.kind}:{}});if(jo())try{const n=await Po("note",{id:e.id,nevent:t,relays:e.relays??[],...e.author?{author:e.author}:{}},{convention:"napplet:note/open"});if(n!=null&&n.ok&&n.handled)return"intent"}catch{}if(U("link","open"))try{if((await Ho(`nostr:${t}`)).status==="opened")return"link"}catch{}return"none"}async function $u(e){if(!U("storage","getItem"))return null;try{return await Zc(e)}catch{return null}}async function Do(e,t){if(U("storage","setItem"))try{await Xc(e,t)}catch{}}const _u=5e3,zo=10;function Bu(e){var t,n;return{...(t=e.authors)!=null&&t.length?{authors:e.authors}:{},...(n=e.relays)!=null&&n.length?{relays:[...new Set(e.relays)].slice(0,zo)}:{}}}class Tu extends Error{}function Fo(e,t={}){if(U("outbox","subscribe")){const n=new D(r=>{const i=Bu(t),o=uu(e,Object.keys(i).length?i:void 0);let s=!0;return o.on("event",a=>{a!=null&&a.event&&r.next(a.event)}),o.on("closed",a=>{s&&r.error(new Tu(a??""))}),()=>{s=!1,o.close()}});return gt(()=>n).pipe(Oa({delay:r=>{var o;const i=r instanceof Error?r.message:"";return(o=t.onNotice)==null||o.call(t,`A read was closed by the shell${i?`: ${i}`:""}. Reopening…`),Zt(_u)}}))}return U("relay","subscribe")?new D(n=>{const r=zc(e,i=>(i==null?void 0:i.event)&&n.next(i.event),()=>{});return()=>r.close()}):new D(()=>{var n;(n=t.onNotice)==null||n.call(t,"This shell offers no way to read relays (no outbox or relay domain).")})}function Cu(e,t={}){return gt(async()=>{var r,i;const n=[...new Set(t.relays??[])].slice(0,zo);if(U("outbox","getEvent"))try{const o=await cu(e,{...t.author?{author:t.author}:{},...n.length?{relays:n}:{},timeoutMs:6e3});if((r=o.result)!=null&&r.event)return o.result.event}catch{}if(U("relay","query"))try{return(i=(await Vc([{ids:[e],limit:1}]))[0])==null?void 0:i.event}catch{return}}).pipe(fn(n=>n&&n.id===e?[n]:un))}function Lu(e){return e<1e4&&e!==0&&e!==3}function Vo(e){return e===0||e===3||1e4<=e&&e<2e4}function Ko(e){return 3e4<=e&&e<4e4}var Wo=0,Ou=3,Ru=4,Go=5,Nu=13,Mu=1059,Uu=1e4,Pu=10002,Hu=10003,qu=10004,ju=10005,Du=10007,zu=10015,Fu=3e4,Vu=30002,Ku=30003,Wu=30004,Gu=30015,Yu=30024,Zu=31990;function yi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Yo(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 Xu(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");yi(e.outputLen),yi(e.blockLen)}function tn(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 Qu(e,t){Yo(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Bn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Zo=e=>e instanceof Uint8Array,Tn=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),fe=(e,t)=>e<<32-t|e>>>t,Ju=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ju)throw new Error("Non little-endian hardware is not supported");function ef(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Br(e){if(typeof e=="string"&&(e=ef(e)),!Zo(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function tf(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!Zo(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}class Xo{clone(){return this._cloneInto()}}function nf(e){const t=r=>e().update(Br(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Qo(e=32){if(Bn&&typeof Bn.getRandomValues=="function")return Bn.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function rf(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}let of=class extends Xo{constructor(t,n,r,i){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Tn(this.buffer)}update(t){tn(this);const{view:n,buffer:r,blockLen:i}=this;t=Br(t);const o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const c=Tn(t);for(;i<=o-s;s+=i)this.process(c,s);continue}r.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){tn(this),Qu(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:o}=this;let{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(r,0),s=0);for(let f=s;f<i;f++)n[f]=0;rf(r,i-8,BigInt(this.length*8),o),this.process(r,0);const a=Tn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],o)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:o,destroyed:s,pos:a}=this;return t.length=i,t.pos=a,t.finished=o,t.destroyed=s,i%n&&t.buffer.set(r),t}};const sf=(e,t,n)=>e&t^~e&n,af=(e,t,n)=>e&t^e&n^t&n,cf=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]),$e=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),_e=new Uint32Array(64);let uf=class extends of{constructor(){super(64,32,8,!1),this.A=$e[0]|0,this.B=$e[1]|0,this.C=$e[2]|0,this.D=$e[3]|0,this.E=$e[4]|0,this.F=$e[5]|0,this.G=$e[6]|0,this.H=$e[7]|0}get(){const{A:t,B:n,C:r,D:i,E:o,F:s,G:a,H:c}=this;return[t,n,r,i,o,s,a,c]}set(t,n,r,i,o,s,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,n){for(let f=0;f<16;f++,n+=4)_e[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const h=_e[f-15],p=_e[f-2],y=fe(h,7)^fe(h,18)^h>>>3,d=fe(p,17)^fe(p,19)^p>>>10;_e[f]=d+_e[f-7]+y+_e[f-16]|0}let{A:r,B:i,C:o,D:s,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const h=fe(a,6)^fe(a,11)^fe(a,25),p=l+h+sf(a,c,u)+cf[f]+_e[f]|0,d=(fe(r,2)^fe(r,13)^fe(r,22))+af(r,i,o)|0;l=u,u=c,c=a,a=s+p|0,s=o,o=i,i=r,r=p+d|0}r=r+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,i,o,s,a,c,u,l)}roundClean(){_e.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Xn=nf(()=>new uf);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */BigInt(0);const ff=BigInt(1),lf=BigInt(2),bn=e=>e instanceof Uint8Array,df=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function lt(e){if(!bn(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=df[e[n]];return t}function Tr(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function Ct(e){if(typeof e!="string")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 r=0;r<n.length;r++){const i=r*2,o=e.slice(i,i+2),s=Number.parseInt(o,16);if(Number.isNaN(s)||s<0)throw new Error("Invalid byte sequence");n[r]=s}return n}function F(e){return Tr(lt(e))}function Cr(e){if(!bn(e))throw new Error("Uint8Array expected");return Tr(lt(Uint8Array.from(e).reverse()))}function Ne(e,t){return Ct(e.toString(16).padStart(t*2,"0"))}function Lr(e,t){return Ne(e,t).reverse()}function z(e,t,n){let r;if(typeof t=="string")try{r=Ct(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(bn(t))r=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(`${e} expected ${n} bytes, got ${i}`);return r}function We(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!bn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}const Or=e=>(lf<<BigInt(e-1))-ff,Cn=e=>new Uint8Array(e),gi=e=>Uint8Array.from(e);function Jo(e,t,n){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=Cn(e),i=Cn(e),o=0;const s=()=>{r.fill(1),i.fill(0),o=0},a=(...f)=>n(i,r,...f),c=(f=Cn())=>{i=a(gi([0]),f),r=a(),f.length!==0&&(i=a(gi([1]),f),r=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0;const h=[];for(;f<t;){r=a();const p=r.slice();h.push(p),f+=r.length}return We(...h)};return(f,h)=>{s(),c(f);let p;for(;!(p=h(u()));)c();return s(),p}}const hf={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Pt(e,t,n={}){const r=(i,o,s)=>{const a=hf[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);const c=e[i];if(!(s&&c===void 0)&&!a(c,e))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(const[i,o]of Object.entries(t))r(i,o,!1);for(const[i,o]of Object.entries(n))r(i,o,!0);return e}const pf=Object.freeze(Object.defineProperty({__proto__:null,bitMask:Or,bytesToHex:lt,bytesToNumberBE:F,bytesToNumberLE:Cr,concatBytes:We,createHmacDrbg:Jo,ensureBytes:z,hexToBytes:Ct,hexToNumber:Tr,numberToBytesBE:Ne,numberToBytesLE:Lr,validateObject:Pt},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const H=BigInt(0),N=BigInt(1),qe=BigInt(2),yf=BigInt(3),Qn=BigInt(4),bi=BigInt(5),wi=BigInt(8);BigInt(9);BigInt(16);function j(e,t){const n=e%t;return n>=H?n:t+n}function gf(e,t,n){if(n<=H||t<H)throw new Error("Expected power/modulo > 0");if(n===N)return H;let r=N;for(;t>H;)t&N&&(r=r*e%n),e=e*e%n,t>>=N;return r}function ee(e,t,n){let r=e;for(;t-- >H;)r*=r,r%=n;return r}function Jn(e,t){if(e===H||t<=H)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=j(e,t),r=t,i=H,o=N;for(;n!==H;){const a=r/n,c=r%n,u=i-o*a;r=n,n=c,i=o,o=u}if(r!==N)throw new Error("invert: does not exist");return j(i,t)}function bf(e){const t=(e-N)/qe;let n,r,i;for(n=e-N,r=0;n%qe===H;n/=qe,r++);for(i=qe;i<e&&gf(i,t,e)!==e-N;i++);if(r===1){const s=(e+N)/Qn;return function(c,u){const l=c.pow(u,s);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}const o=(n+N)/qe;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=r,l=a.pow(a.mul(a.ONE,i),n),f=a.pow(c,o),h=a.pow(c,n);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let p=1;for(let d=a.sqr(h);p<u&&!a.eql(d,a.ONE);p++)d=a.sqr(d);const y=a.pow(l,N<<BigInt(u-p-1));l=a.sqr(y),f=a.mul(f,y),h=a.mul(h,l),u=p}return f}}function wf(e){if(e%Qn===yf){const t=(e+N)/Qn;return function(r,i){const o=r.pow(i,t);if(!r.eql(r.sqr(o),i))throw new Error("Cannot find square root");return o}}if(e%wi===bi){const t=(e-bi)/wi;return function(r,i){const o=r.mul(i,qe),s=r.pow(o,t),a=r.mul(i,s),c=r.mul(r.mul(a,qe),s),u=r.mul(a,r.sub(c,r.ONE));if(!r.eql(r.sqr(u),i))throw new Error("Cannot find square root");return u}}return bf(e)}const mf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vf(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=mf.reduce((r,i)=>(r[i]="function",r),t);return Pt(e,n)}function xf(e,t,n){if(n<H)throw new Error("Expected power > 0");if(n===H)return e.ONE;if(n===N)return t;let r=e.ONE,i=t;for(;n>H;)n&N&&(r=e.mul(r,i)),i=e.sqr(i),n>>=N;return r}function Ef(e,t){const n=new Array(t.length),r=t.reduce((o,s,a)=>e.is0(s)?o:(n[a]=o,e.mul(o,s)),e.ONE),i=e.inv(r);return t.reduceRight((o,s,a)=>e.is0(s)?o:(n[a]=e.mul(o,n[a]),e.mul(o,s)),i),n}function es(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function kf(e,t,n=!1,r={}){if(e<=H)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:o}=es(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=wf(e),a=Object.freeze({ORDER:e,BITS:i,BYTES:o,MASK:Or(i),ZERO:H,ONE:N,create:c=>j(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return H<=c&&c<e},is0:c=>c===H,isOdd:c=>(c&N)===N,neg:c=>j(-c,e),eql:(c,u)=>c===u,sqr:c=>j(c*c,e),add:(c,u)=>j(c+u,e),sub:(c,u)=>j(c-u,e),mul:(c,u)=>j(c*u,e),pow:(c,u)=>xf(a,c,u),div:(c,u)=>j(c*Jn(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Jn(c,e),sqrt:r.sqrt||(c=>s(a,c)),invertBatch:c=>Ef(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>n?Lr(c,o):Ne(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return n?Cr(c):F(c)}});return Object.freeze(a)}function ts(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function ns(e){const t=ts(e);return t+Math.ceil(t/2)}function Sf(e,t,n=!1){const r=e.length,i=ts(t),o=ns(t);if(r<16||r<o||r>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${r}`);const s=n?F(e):Cr(e),a=j(s,t-N)+N;return n?Lr(a,i):Ne(a,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Af=BigInt(0),Ln=BigInt(1);function If(e,t){const n=(i,o)=>{const s=o.negate();return i?s:o},r=i=>{const o=Math.ceil(t/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:n,unsafeLadder(i,o){let s=e.ZERO,a=i;for(;o>Af;)o&Ln&&(s=s.add(a)),a=a.double(),o>>=Ln;return s},precomputeWindow(i,o){const{windows:s,windowSize:a}=r(o),c=[];let u=i,l=u;for(let f=0;f<s;f++){l=u,c.push(l);for(let h=1;h<a;h++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(i,o,s){const{windows:a,windowSize:c}=r(i);let u=e.ZERO,l=e.BASE;const f=BigInt(2**i-1),h=2**i,p=BigInt(i);for(let y=0;y<a;y++){const d=y*c;let g=Number(s&f);s>>=p,g>c&&(g-=h,s+=Ln);const b=d,x=d+Math.abs(g)-1,E=y%2!==0,B=g<0;g===0?l=l.add(n(E,o[b])):u=u.add(n(B,o[x]))}return{p:u,f:l}},wNAFCached(i,o,s,a){const c=i._WINDOW_SIZE||1;let u=o.get(i);return u||(u=this.precomputeWindow(i,c),c!==1&&o.set(i,a(u))),this.wNAF(c,u,s)}}}function rs(e){return vf(e.Fp),Pt(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...es(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function $f(e){const t=rs(e);Pt(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:i}=t;if(n){if(!r.eql(i,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:_f,hexToBytes:Bf}=pf,je={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=je;if(e.length<2||e[0]!==2)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(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:_f(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=je,n=typeof e=="string"?Bf(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:i,l:o}=je._parseInt(n.subarray(2)),{d:s,l:a}=je._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(e){const t=u=>Number.parseInt(u[0],16)&8?"00"+u:u,n=u=>{const l=u.toString(16);return l.length&1?`0${l}`:l},r=t(n(e.s)),i=t(n(e.r)),o=r.length/2,s=i.length/2,a=n(o),c=n(s);return`30${n(s+o+4)}02${c}${i}02${a}${r}`}},pe=BigInt(0),ne=BigInt(1);BigInt(2);const mi=BigInt(3);BigInt(4);function Tf(e){const t=$f(e),{Fp:n}=t,r=t.toBytes||((y,d,g)=>{const b=d.toAffine();return We(Uint8Array.from([4]),n.toBytes(b.x),n.toBytes(b.y))}),i=t.fromBytes||(y=>{const d=y.subarray(1),g=n.fromBytes(d.subarray(0,n.BYTES)),b=n.fromBytes(d.subarray(n.BYTES,2*n.BYTES));return{x:g,y:b}});function o(y){const{a:d,b:g}=t,b=n.sqr(y),x=n.mul(b,y);return n.add(n.add(x,n.mul(y,d)),g)}if(!n.eql(n.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function s(y){return typeof y=="bigint"&&pe<y&&y<t.n}function a(y){if(!s(y))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(y){const{allowedPrivateKeyLengths:d,nByteLength:g,wrapPrivateKey:b,n:x}=t;if(d&&typeof y!="bigint"){if(y instanceof Uint8Array&&(y=lt(y)),typeof y!="string"||!d.includes(y.length))throw new Error("Invalid key");y=y.padStart(g*2,"0")}let E;try{E=typeof y=="bigint"?y:F(z("private key",y,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof y}`)}return b&&(E=j(E,x)),a(E),E}const u=new Map;function l(y){if(!(y instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(d,g,b){if(this.px=d,this.py=g,this.pz=b,d==null||!n.isValid(d))throw new Error("x required");if(g==null||!n.isValid(g))throw new Error("y required");if(b==null||!n.isValid(b))throw new Error("z required")}static fromAffine(d){const{x:g,y:b}=d||{};if(!d||!n.isValid(g)||!n.isValid(b))throw new Error("invalid affine point");if(d instanceof f)throw new Error("projective point not allowed");const x=E=>n.eql(E,n.ZERO);return x(g)&&x(b)?f.ZERO:new f(g,b,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){const g=n.invertBatch(d.map(b=>b.pz));return d.map((b,x)=>b.toAffine(g[x])).map(f.fromAffine)}static fromHex(d){const g=f.fromAffine(i(z("pointHex",d)));return g.assertValidity(),g}static fromPrivateKey(d){return f.BASE.multiply(c(d))}_setWindowSize(d){this._WINDOW_SIZE=d,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:d,y:g}=this.toAffine();if(!n.isValid(d)||!n.isValid(g))throw new Error("bad point: x or y not FE");const b=n.sqr(g),x=o(d);if(!n.eql(b,x))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:d}=this.toAffine();if(n.isOdd)return!n.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){l(d);const{px:g,py:b,pz:x}=this,{px:E,py:B,pz:A}=d,v=n.eql(n.mul(g,A),n.mul(E,x)),S=n.eql(n.mul(b,A),n.mul(B,x));return v&&S}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:d,b:g}=t,b=n.mul(g,mi),{px:x,py:E,pz:B}=this;let A=n.ZERO,v=n.ZERO,S=n.ZERO,$=n.mul(x,x),J=n.mul(E,E),R=n.mul(B,B),C=n.mul(x,E);return C=n.add(C,C),S=n.mul(x,B),S=n.add(S,S),A=n.mul(d,S),v=n.mul(b,R),v=n.add(A,v),A=n.sub(J,v),v=n.add(J,v),v=n.mul(A,v),A=n.mul(C,A),S=n.mul(b,S),R=n.mul(d,R),C=n.sub($,R),C=n.mul(d,C),C=n.add(C,S),S=n.add($,$),$=n.add(S,$),$=n.add($,R),$=n.mul($,C),v=n.add(v,$),R=n.mul(E,B),R=n.add(R,R),$=n.mul(R,C),A=n.sub(A,$),S=n.mul(R,J),S=n.add(S,S),S=n.add(S,S),new f(A,v,S)}add(d){l(d);const{px:g,py:b,pz:x}=this,{px:E,py:B,pz:A}=d;let v=n.ZERO,S=n.ZERO,$=n.ZERO;const J=t.a,R=n.mul(t.b,mi);let C=n.mul(g,E),W=n.mul(b,B),G=n.mul(x,A),ke=n.add(g,b),w=n.add(E,B);ke=n.mul(ke,w),w=n.add(C,W),ke=n.sub(ke,w),w=n.add(g,x);let m=n.add(E,A);return w=n.mul(w,m),m=n.add(C,G),w=n.sub(w,m),m=n.add(b,x),v=n.add(B,A),m=n.mul(m,v),v=n.add(W,G),m=n.sub(m,v),$=n.mul(J,w),v=n.mul(R,G),$=n.add(v,$),v=n.sub(W,$),$=n.add(W,$),S=n.mul(v,$),W=n.add(C,C),W=n.add(W,C),G=n.mul(J,G),w=n.mul(R,w),W=n.add(W,G),G=n.sub(C,G),G=n.mul(J,G),w=n.add(w,G),C=n.mul(W,w),S=n.add(S,C),C=n.mul(m,w),v=n.mul(ke,v),v=n.sub(v,C),C=n.mul(ke,W),$=n.mul(m,$),$=n.add($,C),new f(v,S,$)}subtract(d){return this.add(d.negate())}is0(){return this.equals(f.ZERO)}wNAF(d){return p.wNAFCached(this,u,d,g=>{const b=n.invertBatch(g.map(x=>x.pz));return g.map((x,E)=>x.toAffine(b[E])).map(f.fromAffine)})}multiplyUnsafe(d){const g=f.ZERO;if(d===pe)return g;if(a(d),d===ne)return this;const{endo:b}=t;if(!b)return p.unsafeLadder(this,d);let{k1neg:x,k1:E,k2neg:B,k2:A}=b.splitScalar(d),v=g,S=g,$=this;for(;E>pe||A>pe;)E&ne&&(v=v.add($)),A&ne&&(S=S.add($)),$=$.double(),E>>=ne,A>>=ne;return x&&(v=v.negate()),B&&(S=S.negate()),S=new f(n.mul(S.px,b.beta),S.py,S.pz),v.add(S)}multiply(d){a(d);let g=d,b,x;const{endo:E}=t;if(E){const{k1neg:B,k1:A,k2neg:v,k2:S}=E.splitScalar(g);let{p:$,f:J}=this.wNAF(A),{p:R,f:C}=this.wNAF(S);$=p.constTimeNegate(B,$),R=p.constTimeNegate(v,R),R=new f(n.mul(R.px,E.beta),R.py,R.pz),b=$.add(R),x=J.add(C)}else{const{p:B,f:A}=this.wNAF(g);b=B,x=A}return f.normalizeZ([b,x])[0]}multiplyAndAddUnsafe(d,g,b){const x=f.BASE,E=(A,v)=>v===pe||v===ne||!A.equals(x)?A.multiplyUnsafe(v):A.multiply(v),B=E(this,g).add(E(d,b));return B.is0()?void 0:B}toAffine(d){const{px:g,py:b,pz:x}=this,E=this.is0();d==null&&(d=E?n.ONE:n.inv(x));const B=n.mul(g,d),A=n.mul(b,d),v=n.mul(x,d);if(E)return{x:n.ZERO,y:n.ZERO};if(!n.eql(v,n.ONE))throw new Error("invZ was invalid");return{x:B,y:A}}isTorsionFree(){const{h:d,isTorsionFree:g}=t;if(d===ne)return!0;if(g)return g(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:d,clearCofactor:g}=t;return d===ne?this:g?g(f,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return this.assertValidity(),r(f,this,d)}toHex(d=!0){return lt(this.toRawBytes(d))}}f.BASE=new f(t.Gx,t.Gy,n.ONE),f.ZERO=new f(n.ZERO,n.ONE,n.ZERO);const h=t.nBitLength,p=If(f,t.endo?Math.ceil(h/2):h);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:s}}function Cf(e){const t=rs(e);return Pt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Lf(e){const t=Cf(e),{Fp:n,n:r}=t,i=n.BYTES+1,o=2*n.BYTES+1;function s(w){return pe<w&&w<n.ORDER}function a(w){return j(w,r)}function c(w){return Jn(w,r)}const{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:f,isWithinCurveOrder:h}=Tf({...t,toBytes(w,m,I){const O=m.toAffine(),L=n.toBytes(O.x),P=We;return I?P(Uint8Array.from([m.hasEvenY()?2:3]),L):P(Uint8Array.from([4]),L,n.toBytes(O.y))},fromBytes(w){const m=w.length,I=w[0],O=w.subarray(1);if(m===i&&(I===2||I===3)){const L=F(O);if(!s(L))throw new Error("Point is not on curve");const P=f(L);let Y=n.sqrt(P);const Z=(Y&ne)===ne;return(I&1)===1!==Z&&(Y=n.neg(Y)),{x:L,y:Y}}else if(m===o&&I===4){const L=n.fromBytes(O.subarray(0,n.BYTES)),P=n.fromBytes(O.subarray(n.BYTES,2*n.BYTES));return{x:L,y:P}}else throw new Error(`Point of length ${m} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),p=w=>lt(Ne(w,t.nByteLength));function y(w){const m=r>>ne;return w>m}function d(w){return y(w)?a(-w):w}const g=(w,m,I)=>F(w.slice(m,I));class b{constructor(m,I,O){this.r=m,this.s=I,this.recovery=O,this.assertValidity()}static fromCompact(m){const I=t.nByteLength;return m=z("compactSignature",m,I*2),new b(g(m,0,I),g(m,I,2*I))}static fromDER(m){const{r:I,s:O}=je.toSig(z("DER",m));return new b(I,O)}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(m){return new b(this.r,this.s,m)}recoverPublicKey(m){const{r:I,s:O,recovery:L}=this,P=S(z("msgHash",m));if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");const Y=L===2||L===3?I+t.n:I;if(Y>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const Z=(L&1)===0?"02":"03",Se=u.fromHex(Z+p(Y)),Ae=c(Y),Qe=a(-P*Ae),vt=a(O*Ae),Ie=u.BASE.multiplyAndAddUnsafe(Se,Qe,vt);if(!Ie)throw new Error("point at infinify");return Ie.assertValidity(),Ie}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Ct(this.toDERHex())}toDERHex(){return je.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ct(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}const x={isValidPrivateKey(w){try{return l(w),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{const w=ns(t.n);return Sf(t.randomBytes(w),t.n)},precompute(w=8,m=u.BASE){return m._setWindowSize(w),m.multiply(BigInt(3)),m}};function E(w,m=!0){return u.fromPrivateKey(w).toRawBytes(m)}function B(w){const m=w instanceof Uint8Array,I=typeof w=="string",O=(m||I)&&w.length;return m?O===i||O===o:I?O===2*i||O===2*o:w instanceof u}function A(w,m,I=!0){if(B(w))throw new Error("first arg must be private key");if(!B(m))throw new Error("second arg must be public key");return u.fromHex(m).multiply(l(w)).toRawBytes(I)}const v=t.bits2int||function(w){const m=F(w),I=w.length*8-t.nBitLength;return I>0?m>>BigInt(I):m},S=t.bits2int_modN||function(w){return a(v(w))},$=Or(t.nBitLength);function J(w){if(typeof w!="bigint")throw new Error("bigint expected");if(!(pe<=w&&w<$))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Ne(w,t.nByteLength)}function R(w,m,I=C){if(["recovered","canonical"].some(Pe=>Pe in I))throw new Error("sign() legacy options not supported");const{hash:O,randomBytes:L}=t;let{lowS:P,prehash:Y,extraEntropy:Z}=I;P==null&&(P=!0),w=z("msgHash",w),Y&&(w=z("prehashed msgHash",O(w)));const Se=S(w),Ae=l(m),Qe=[J(Ae),J(Se)];if(Z!=null){const Pe=Z===!0?L(n.BYTES):Z;Qe.push(z("extraEntropy",Pe))}const vt=We(...Qe),Ie=Se;function Sn(Pe){const Je=v(Pe);if(!h(Je))return;const Yr=c(Je),et=u.BASE.multiply(Je).toAffine(),oe=a(et.x);if(oe===pe)return;const tt=a(Yr*a(Ie+oe*Ae));if(tt===pe)return;let Zr=(et.x===oe?0:2)|Number(et.y&ne),Xr=tt;return P&&y(tt)&&(Xr=d(tt),Zr^=1),new b(oe,Xr,Zr)}return{seed:vt,k2sig:Sn}}const C={lowS:t.lowS,prehash:!1},W={lowS:t.lowS,prehash:!1};function G(w,m,I=C){const{seed:O,k2sig:L}=R(w,m,I),P=t;return Jo(P.hash.outputLen,P.nByteLength,P.hmac)(O,L)}u.BASE._setWindowSize(8);function ke(w,m,I,O=W){var et;const L=w;if(m=z("msgHash",m),I=z("publicKey",I),"strict"in O)throw new Error("options.strict was renamed to lowS");const{lowS:P,prehash:Y}=O;let Z,Se;try{if(typeof L=="string"||L instanceof Uint8Array)try{Z=b.fromDER(L)}catch(oe){if(!(oe instanceof je.Err))throw oe;Z=b.fromCompact(L)}else if(typeof L=="object"&&typeof L.r=="bigint"&&typeof L.s=="bigint"){const{r:oe,s:tt}=L;Z=new b(oe,tt)}else throw new Error("PARSE");Se=u.fromHex(I)}catch(oe){if(oe.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(P&&Z.hasHighS())return!1;Y&&(m=t.hash(m));const{r:Ae,s:Qe}=Z,vt=S(m),Ie=c(Qe),Sn=a(vt*Ie),Pe=a(Ae*Ie),Je=(et=u.BASE.multiplyAndAddUnsafe(Se,Sn,Pe))==null?void 0:et.toAffine();return Je?a(Je.x)===Ae:!1}return{CURVE:t,getPublicKey:E,getSharedSecret:A,sign:G,verify:ke,ProjectivePoint:u,Signature:b,utils:x}}class is extends Xo{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Xu(t);const r=Br(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,o=new Uint8Array(i);o.set(r.length>i?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(t){return tn(this),this.iHash.update(t),this}digestInto(t){tn(this),Yo(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:o,blockLen:s,outputLen:a}=this;return t=t,t.finished=i,t.destroyed=o,t.blockLen=s,t.outputLen=a,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const os=(e,t,n)=>new is(e,t).update(n).digest();os.create=(e,t)=>new is(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Of(e){return{hash:e,hmac:(t,...n)=>os(e,t,tf(...n)),randomBytes:Qo}}function Rf(e,t){const n=r=>Lf({...e,...Of(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const wn=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),nn=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ss=BigInt(1),rn=BigInt(2),vi=(e,t)=>(e+t/rn)/t;function as(e){const t=wn,n=BigInt(3),r=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=ee(l,n,t)*l%t,h=ee(f,n,t)*l%t,p=ee(h,rn,t)*u%t,y=ee(p,i,t)*p%t,d=ee(y,o,t)*y%t,g=ee(d,a,t)*d%t,b=ee(g,c,t)*g%t,x=ee(b,a,t)*d%t,E=ee(x,n,t)*l%t,B=ee(E,s,t)*y%t,A=ee(B,r,t)*u%t,v=ee(A,rn,t);if(!er.eql(er.sqr(v),e))throw new Error("Cannot find square root");return v}const er=kf(wn,void 0,void 0,{sqrt:as}),Rr=Rf({a:BigInt(0),b:BigInt(7),Fp:er,n:nn,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=nn,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-ss*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,s=BigInt("0x100000000000000000000000000000000"),a=vi(o*e,t),c=vi(-r*e,t);let u=j(e-a*n-c*i,t),l=j(-a*r-c*o,t);const f=u>s,h=l>s;if(f&&(u=t-u),h&&(l=t-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},Xn),mn=BigInt(0),cs=e=>typeof e=="bigint"&&mn<e&&e<wn,Nf=e=>typeof e=="bigint"&&mn<e&&e<nn,xi={};function on(e,...t){let n=xi[e];if(n===void 0){const r=Xn(Uint8Array.from(e,i=>i.charCodeAt(0)));n=We(r,r),xi[e]=n}return Xn(We(n,...t))}const Nr=e=>e.toRawBytes(!0).slice(1),tr=e=>Ne(e,32),On=e=>j(e,wn),Lt=e=>j(e,nn),Mr=Rr.ProjectivePoint,Mf=(e,t,n)=>Mr.BASE.multiplyAndAddUnsafe(e,t,n);function nr(e){let t=Rr.utils.normPrivateKeyToScalar(e),n=Mr.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Lt(-t),bytes:Nr(n)}}function us(e){if(!cs(e))throw new Error("bad x: need 0 < x < p");const t=On(e*e),n=On(t*e+BigInt(7));let r=as(n);r%rn!==mn&&(r=On(-r));const i=new Mr(e,r,ss);return i.assertValidity(),i}function fs(...e){return Lt(F(on("BIP0340/challenge",...e)))}function Uf(e){return nr(e).bytes}function Pf(e,t,n=Qo(32)){const r=z("message",e),{bytes:i,scalar:o}=nr(t),s=z("auxRand",n,32),a=tr(o^F(on("BIP0340/aux",s))),c=on("BIP0340/nonce",a,i,r),u=Lt(F(c));if(u===mn)throw new Error("sign failed: k is zero");const{bytes:l,scalar:f}=nr(u),h=fs(l,i,r),p=new Uint8Array(64);if(p.set(l,0),p.set(tr(Lt(f+h*o)),32),!ls(p,r,i))throw new Error("sign: Invalid signature produced");return p}function ls(e,t,n){const r=z("signature",e,64),i=z("message",t),o=z("publicKey",n,32);try{const s=us(F(o)),a=F(r.subarray(0,32));if(!cs(a))return!1;const c=F(r.subarray(32,64));if(!Nf(c))return!1;const u=fs(tr(a),Nr(s),i),l=Mf(s,c,Lt(-u));return!(!l||!l.hasEvenY()||l.toAffine().x!==a)}catch{return!1}}const kt={getPublicKey:Uf,sign:Pf,verify:ls,utils:{randomPrivateKey:Rr.utils.randomPrivateKey,lift_x:us,pointToBytes:Nr,numberToBytesBE:Ne,bytesToNumberBE:F,taggedHash:on,mod:j}};function rr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Hf(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function ds(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 qf(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");rr(e.outputLen),rr(e.blockLen)}function jf(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 Df(e,t){ds(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Rn={number:rr,bool:Hf,bytes:ds,hash:qf,exists:jf,output:Df};function zf(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}class Ff extends za{constructor(t,n,r,i){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=$n(this.buffer)}update(t){Rn.exists(this);const{view:n,buffer:r,blockLen:i}=this;t=wo(t);const o=t.length;for(let s=0;s<o;){const a=Math.min(i-this.pos,o-s);if(a===i){const c=$n(t);for(;i<=o-s;s+=i)this.process(c,s);continue}r.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Rn.exists(this),Rn.output(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:o}=this;let{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(r,0),s=0);for(let f=s;f<i;f++)n[f]=0;zf(r,i-8,BigInt(this.length*8),o),this.process(r,0);const a=$n(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],o)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:o,destroyed:s,pos:a}=this;return t.length=i,t.pos=a,t.finished=o,t.destroyed=s,i%n&&t.buffer.set(r),t}}const Vf=(e,t,n)=>e&t^~e&n,Kf=(e,t,n)=>e&t^e&n^t&n,Wf=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]),Be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Te=new Uint32Array(64);class hs extends Ff{constructor(){super(64,32,8,!1),this.A=Be[0]|0,this.B=Be[1]|0,this.C=Be[2]|0,this.D=Be[3]|0,this.E=Be[4]|0,this.F=Be[5]|0,this.G=Be[6]|0,this.H=Be[7]|0}get(){const{A:t,B:n,C:r,D:i,E:o,F:s,G:a,H:c}=this;return[t,n,r,i,o,s,a,c]}set(t,n,r,i,o,s,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,n){for(let f=0;f<16;f++,n+=4)Te[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const h=Te[f-15],p=Te[f-2],y=ue(h,7)^ue(h,18)^h>>>3,d=ue(p,17)^ue(p,19)^p>>>10;Te[f]=d+Te[f-7]+y+Te[f-16]|0}let{A:r,B:i,C:o,D:s,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const h=ue(a,6)^ue(a,11)^ue(a,25),p=l+h+Vf(a,c,u)+Wf[f]+Te[f]|0,d=(ue(r,2)^ue(r,13)^ue(r,22))+Kf(r,i,o)|0;l=u,u=c,c=a,a=s+p|0,s=o,o=i,i=r,r=p+d|0}r=r+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,i,o,s,a,c,u,l)}roundClean(){Te.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Gf extends hs{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 Yf=mo(()=>new hs);mo(()=>new Gf);var He=Symbol("verified"),Zf=e=>e instanceof Object;function Xf(e){if(!Zf(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!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 r=0;r<n.length;r++)if(typeof n[r]!="string")return!1}return!0}new TextDecoder("utf-8");var Qf=new TextEncoder,Jf=class{generateSecretKey(){return kt.utils.randomPrivateKey()}getPublicKey(e){return se(kt.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=se(kt.getPublicKey(t)),n.id=Nn(n),n.sig=se(kt.sign(Nn(n),t)),n[He]=!0,n}verifyEvent(e){if(typeof e[He]=="boolean")return e[He];const t=Nn(e);if(t!==e.id)return e[He]=!1,!1;try{const n=kt.verify(e.sig,t,e.pubkey);return e[He]=n,n}catch{return e[He]=!1,!1}}};function el(e){if(!Xf(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])}function Nn(e){let t=Yf(Qf.encode(el(e)));return se(t)}var vn=new Jf;vn.generateSecretKey;vn.getPublicKey;vn.finalizeEvent;var tl=vn.verifyEvent;function Xe(e,t,n){if(Reflect.has(e,t))return Reflect.get(e,t);{const r=n();return Reflect.set(e,t,r),r}}new TextDecoder("utf-8");new TextEncoder;function Kt(e,t){const[n,r]=Wt(e,i=>t.id===i.id?0:t.created_at===i.created_at?-1:i.created_at-t.created_at);return r||e.splice(n,0,t),e}function Wt(e,t){let n=0,r=e.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),o=t(e[i]);if(o===0)return[i,!0];o<0?r=i-1:n=i+1}return[n,!1]}const Ei=Symbol.for("event-store"),ki=Symbol.for("event-uid"),nl=Symbol.for("replaceable-address"),rl=Symbol.for("from-cache"),il=Symbol.for("replaceable-identifier");function de(e){return Vo(e)||Ko(e)}function ol(e){let t=Reflect.get(e,ki);return t||(de(e.kind)?t=sl(e)??e.id:t=e.id,Reflect.set(e,ki,t)),t}function sl(e){return de(e.kind)?Xe(e,nl,()=>it(e.kind,e.pubkey,Fe(e))):null}function it(e,t,n){return e+":"+t+":"+(n??"")}function Fe(e){return Xe(e,il,()=>{var t;return((t=e.tags.find(n=>n[0]==="d"))==null?void 0:t[1])??""})}const Ur=Symbol.for("encrypted-content"),ps={[Ru]:"nip04",[Nu]:"nip44",[Mu]:"nip44"};function ys(e,t){return ps[e]=t,e}function al(e){return ps[e]!==void 0}function cl(e){return Reflect.get(e,Ur)}function Gt(){return Math.round(Date.now()/1e3)}function xn(e,t){return e[0]!==void 0&&e[1]!==void 0&&(t?e[0]===t:!0)}function ul(e){return xn(e,"e")}function gs(e){return xn(e,"p")}function bs(e){return xn(e,"r")}function fl(e){return xn(e,"a")}const ws=(e,...t)=>t.reduce((n,r)=>{const i=[];for(const o of n)try{const s=r(o);if(s===void 0)continue;i.push(s)}catch{}return i},e);function Ht(e){let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),(t.port==="80"&&(t.protocol==="ws:"||t.protocol==="http:")||t.port==="443"&&(t.protocol==="wss:"||t.protocol==="https:"))&&(t.port=""),typeof e=="string"?t.toString():t}const ir=Symbol.for("seen-relays");function Si(e,t){let n=Reflect.get(e,ir);return n?(n.add(t),n):(n=new Set([t]),Reflect.set(e,ir,n),n)}function ll(e){return Reflect.get(e,ir)}const dl=/^wss?:\/\/([-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}|localhost)\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)$/;function qt(e){return e.length>=8&&dl.test(e)}function Pr(e){return!e||e.length!==64?!1:!!e.toLowerCase().match(/^[0-9a-f]{64}$/)}function hl(e,t=!1){const n=e.split(":"),r=n[0]?parseInt(n[0]):void 0,i=n[1];if(r===void 0||i===void 0||i===""||!Pr(i))return null;const o=n.slice(2).join(":");return t&&o===""?null:{kind:r,pubkey:i,identifier:o}}function pl(e){const t=e[1];if(!t||!Pr(t))return null;const n={id:t};return e[2]&&qt(e[2])&&(n.relays=[Ht(e[2])]),n}function yl(e){if(!e[1])return null;const t=hl(e[1]);return t?(e[2]&&qt(e[2])&&(t.relays=[Ht(e[2])]),t):null}function ms(e){const t=e[1];if(!t||!Pr(t))return null;const n={pubkey:t};return e[2]&&qt(e[2])&&(n.relays=[Ht(e[2])]),n}function gl(e){return typeof e=="object"&&e!==null&&"identifier"in e&&"pubkey"in e&&"kind"in e&&typeof e.identifier=="string"&&typeof e.pubkey=="string"&&typeof e.kind=="number"}function At(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function Ai(e,t){return At(t)?e.id===t.id&&(t.author?e.pubkey===t.author:!0):e.kind===t.kind&&e.pubkey===t.pubkey&&Fe(e)===(t.identifier??"")}const Ii=Ur,vs=new Set([ys(Yu,"nip04")]);function te(e,t){return vs.add(ys(e,t)),e}function xs(e){return al(e)&&vs.has(e)}function bl(e){if(xs(e.kind))return Ii in e?Reflect.get(e,Ii):cl(e)}const wl=10009,Mn=Symbol.for("hidden-tags"),ml=new Set([te(Hu,"nip04"),te(zu,"nip04"),te(Uu,"nip04"),te(qu,"nip04"),te(ju,"nip04"),te(Du,"nip04"),te(wl,"nip04"),te(Ku,"nip04"),te(Vu,"nip04"),te(Fu,"nip04"),te(Wu,"nip04"),te(Gu,"nip04")]);function vl(e){return xs(e)&&ml.has(e)}function xl(e){if(!vl(e.kind))return;if(Mn in e)return e[Mn];const t=bl(e);if(t===void 0)return;const n=JSON.parse(t);if(!Array.isArray(n))throw new Error("Content is not an array of tags");const r=n.filter(i=>Array.isArray(i)).map(i=>i.map(o=>String(o)));return Reflect.set(e,Mn,r),r}const El=Symbol.for("public-contacts"),Un=Symbol.for("hidden-contacts");function kl(...e){const t=new Map;for(const n of e)if(Array.isArray(n))for(const r of n)r&&t.set(r.pubkey,r);else n&&t.set(n.pubkey,n);return Array.from(t.values())}function Sl(e){return kl(Al(e),Il(e))}function Al(e){return Xe(e,El,()=>ws(e.tags,t=>gs(t)?t:void 0,t=>ms(t)??void 0))}function Il(e){if(Un in e)return e[Un];const t=xl(e);if(!t)return;const n=ws(t,r=>gs(r)?r:void 0,r=>ms(r)??void 0);return Reflect.set(e,Un,n),n}function $l(e){return e.tags.filter(ul).map(pl).filter(t=>t!==null).map(t=>(t.author=e.pubkey,t))}function _l(e){return e.tags.filter(fl).map(yl).filter(t=>t!==null).filter(t=>t.pubkey===e.pubkey)}function jt(e){const t=(()=>{});return t.enabled=!1,t.namespace=e,t.log=()=>{},t.extend=(n,r=":")=>jt(`${e}${r}${n}`),t.destroy=()=>!0,t}jt.enable=e=>{};jt.disable=()=>"";jt.enabled=e=>!1;const Es=jt("applesauce");Es.extend("event-cache");const Bl=Symbol("expiration-timestamp");function or(e){return Xe(e,Bl,()=>{var n;const t=(n=e.tags.find(r=>r[0]==="expiration"))==null?void 0:n[1];return t?parseInt(t):void 0})}function Tl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}const $i="abcdefghijklmnopqrstuvwxyz",sr=new Set(($i+$i.toUpperCase()).split("")),_i=Symbol.for("indexable-tags");function It(e){let t=Reflect.get(e,_i);if(!t){const n=new Set;for(const r of e.tags)r.length>=2&&r[0].length===1&&sr.has(r[0])&&n.add(r[0]+":"+r[1]);t=n,Reflect.set(e,_i,n)}return t}function Cl(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1||e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)return!1;for(let n in e)if(n[0]==="&"){let r=n.slice(1),i=e[n];if(i&&i.length>0){const o=It(t);for(const s of i)if(!o.has(r+":"+s))return!1}}for(let n in e)if(n[0]==="#"){let r=n.slice(1),i=e[n];if(i){const o=`&${r}`,s=e[o],a=s?i.filter(u=>!s.includes(u)):i;if(a.length===0)continue;const c=It(t);if(a.some(u=>c.has(r+":"+u))===!1)return!1}}return!0}function ar(e,t){for(let n=0;n<e.length;n++)if(Cl(e[n],t))return!0;return!1}function Ll(e){try{return JSON.parse(e)}catch{return}}class Bi{constructor(t=0,n=0,r=!1){k(this,"first",null);k(this,"items",Object.create(null));k(this,"last",null);k(this,"max");k(this,"resetTtl");k(this,"size");k(this,"ttl");this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=r,this.size=0,this.ttl=n}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const n=this.items[t];delete this.items[t],this.size--,n.prev!==null&&(n.prev.next=n.next),n.next!==null&&(n.next.prev=n.prev),this.first===n&&(this.first=n.next),this.last===n&&(this.last=n.prev)}return this}entries(t=this.keys()){return t.map(n=>[n,this.get(n)])}evict(t=!1){if(t||this.size>0){const n=this.first;delete this.items[n.key],--this.size===0?(this.first=null,this.last=null):(this.first=n.next,this.first.prev=null)}return this}expiresAt(t){let n;return this.has(t)&&(n=this.items[t].expiry),n}get(t){let n;if(this.has(t)){const r=this.items[t];this.ttl>0&&r.expiry<=Date.now()?this.delete(t):(n=r.value,this.set(t,n,!0))}return n}has(t){return t in this.items}keys(){const t=[];let n=this.first;for(;n!==null;)t.push(n.key),n=n.next;return t}set(t,n,r=!1,i=this.resetTtl){let o;if(r||this.has(t)){if(o=this.items[t],o.value=n,r===!1&&i&&(o.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==o){const s=this.last,a=o.next,c=o.prev;this.first===o&&(this.first=o.next),o.next=null,o.prev=this.last,s.next=o,c!==null&&(c.next=a),a!==null&&(a.prev=c)}}else this.max>0&&this.size===this.max&&this.evict(!0),o=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:n},++this.size===1?this.first=o:this.last.next=o;return this.last=o,this}values(t=this.keys()){return t.map(n=>this.get(n))}}const Ol=Symbol.for("mailboxes-inboxes"),Rl=Symbol.for("mailboxes-outboxes");function Nl(e){return Xe(e,Ol,()=>{const t=[];for(const n of e.tags)if(bs(n))try{const[,r,i]=n;r&&qt(r)&&!t.includes(r)&&(i==="read"||i===void 0)&&t.push(Ht(r))}catch{}return t})}function Ml(e){return Xe(e,Rl,()=>{const t=[];for(const n of e.tags)if(bs(n))try{const[r,i,o]=n;r==="r"&&qt(i)&&!t.includes(i)&&(o==="write"||o===void 0)&&t.push(Ht(i))}catch{}return t})}const Ul=Symbol.for("profile-content");function ks(e){return Xe(e,Ul,()=>{var n,r;const t=Ll(e.content);if(t)return t.nip05&&typeof t.nip05!="string"&&(t.nip05=String(t.nip05)),t.website&&((n=t.website)==null?void 0:n.length)>0&&((r=t.website)==null?void 0:r.startsWith("http"))===!1&&(t.website="https://"+t.website),t})}function Pl(e){return!(!e||e.kind!==Wo&&e.kind!==Zu||!ks(e))}var Pn,Ti;function Hl(){if(Ti)return Pn;Ti=1;function e(s,a){for(;s.length<a;)s="0"+s;return s}function t(s,a){var c,u,l;if(a.length===0)return s;for(c=0,l=a.length;c<l;c++)u=a.charCodeAt(c),s=(s<<5)-s+u,s|=0;return s<0?s*-2:s}function n(s,a,c){return Object.keys(a).sort().reduce(u,s);function u(l,f){return r(l,a[f],f,c)}}function r(s,a,c,u){var l=t(t(t(s,c),i(a)),typeof a);if(a===null)return t(l,"null");if(a===void 0)return t(l,"undefined");if(typeof a=="object"||typeof a=="function"){if(u.indexOf(a)!==-1)return t(l,"[Circular]"+c);u.push(a);var f=n(l,a,u);if(!("valueOf"in a)||typeof a.valueOf!="function")return f;try{return t(f,String(a.valueOf()))}catch(h){return t(f,"[valueOf exception]"+(h.stack||h.message))}}return t(l,a.toString())}function i(s){return Object.prototype.toString.call(s)}function o(s){return e(r(0,s,"",[]).toString(16),8)}return Pn=o,Pn}var ql=Hl();const jl=Tl(ql);class Dl{constructor(){k(this,"deleted$");k(this,"deletedSubject",new ye);k(this,"deletedIds",new Map);k(this,"deletedIdentifiers",new Map);this.deleted$=this.deletedSubject.asObservable()}add(t){if(t.kind!==Go)return[];const n=t.pubkey,r=[],i=$l(t);if(i.length>0){let s=this.deletedIds.get(n);s||(s=new Set,this.deletedIds.set(n,s));for(const a of i){s.add(a.id);const c={pointer:a,until:t.created_at};r.push(c),this.deletedSubject.next(c)}}const o=_l(t);if(o.length>0){let s=this.deletedIdentifiers.get(n);s||(s=new Map,this.deletedIdentifiers.set(n,s));for(const a of o){const c=a.kind+"|"+a.identifier;s.set(c,t.created_at);const u={pointer:a,until:t.created_at};r.push(u),this.deletedSubject.next(u)}}return r}check(t){const n=t.pubkey;if(Vo(t.kind)||Ko(t.kind)){const r=this.deletedIdentifiers.get(n);if(!r)return!1;const i=Fe(t),o=t.kind+"|"+i,s=r.get(o);return s===void 0?!1:s>=t.created_at}else{const r=this.deletedIds.get(n);return r?r.has(t.id):!1}}filter(t){return t.filter(n=>this.check(n)===!1)}}class Ci{constructor(){k(this,"log",Es.extend("EventMemory"));k(this,"kinds",new Map);k(this,"authors",new Map);k(this,"tags",new Bi);k(this,"created_at",[]);k(this,"kindAuthor",new Map);k(this,"events",new Bi);k(this,"replaceable",new Map);k(this,"claims",new WeakMap)}get size(){return this.events.size}hasEvent(t){return this.events.has(t)}getEvent(t){return this.events.get(t)}hasReplaceable(t,n,r){const i=this.replaceable.get(it(t,n,r));return!!i&&i.length>0}getReplaceable(t,n,r){const i=it(t,n,r),o=this.replaceable.get(i);return o==null?void 0:o[0]}getReplaceableHistory(t,n,r){const i=it(t,n,r);return this.replaceable.get(i)}getByFilters(t){return Array.from(this.getEventsForFilters(Array.isArray(t)?t:[t]))}getTimeline(t){const n=[],r=this.getByFilters(t);for(const i of r)Kt(n,i);return n}add(t){var i;const n=t.id,r=this.events.get(n);if(r)return r;this.events.set(n,t),this.getKindIndex(t.kind).add(t),this.getAuthorsIndex(t.pubkey).add(t),this.getKindAuthorIndex(t.kind,t.pubkey).add(t);for(const o of It(t))this.tags.has(o)&&this.getTagIndex(o).add(t);if(Kt(this.created_at,t),de(t.kind)){const o=(i=t.tags.find(c=>c[0]==="d"))==null?void 0:i[1],s=it(t.kind,t.pubkey,o);let a=this.replaceable.get(s);this.replaceable.has(s)||(a=[],this.replaceable.set(s,a)),Kt(a,t)}return t}remove(t){var c;let n=typeof t=="string"?this.events.get(t):t;if(!n)return!1;const r=n.id;if(!this.events.has(r))return!1;const i=this.authors.get(n.pubkey);i&&(i.delete(n),i.size===0&&this.authors.delete(n.pubkey));const o=this.kinds.get(n.kind);o&&(o.delete(n),o.size===0&&this.kinds.delete(n.kind));const s=`${n.kind}:${n.pubkey}`,a=this.kindAuthor.get(s);a&&(a.delete(n),a.size===0&&this.kindAuthor.delete(s));for(const u of It(n))if(this.tags.has(u)){const l=this.getTagIndex(u);l.delete(n),l.size===0&&this.tags.delete(u)}if(this.removeFromSortedArray(this.created_at,n),this.events.delete(r),de(n.kind)){const u=(c=n.tags.find(h=>h[0]==="d"))==null?void 0:c[1],l=it(n.kind,n.pubkey,u),f=this.replaceable.get(l);f&&(this.removeFromSortedArray(f,n),f.length===0&&this.replaceable.delete(l))}return this.claims.delete(n),!0}removeByFilters(t){const n=this.getByFilters(t);let r=0;for(const i of n)this.remove(i)&&r++;return r}update(t){}touch(t){this.events.has(t.id)&&this.events.set(t.id,t)}claim(t){const n=this.claims.get(t)||0;this.claims.set(t,n+1),this.touch(t)}isClaimed(t){const n=this.claims.get(t);return n!==void 0&&n>0}removeClaim(t){const n=this.claims.get(t);if(n!==void 0&&n>0){const r=n-1;r===0?this.claims.delete(t):this.claims.set(t,r)}}clearClaim(t){this.claims.delete(t)}*unclaimed(){let t=0,n=this.events.first;for(;n;){const r=n.value;this.isClaimed(r)||(yield r),n=n.next}return t}prune(t){let n=0;const r=this.unclaimed();for(const i of r)if(this.remove(i),n++,t&&n>=t)break;return n}getKindIndex(t){return this.kinds.has(t)||this.kinds.set(t,new Set),this.kinds.get(t)}getAuthorsIndex(t){return this.authors.has(t)||this.authors.set(t,new Set),this.authors.get(t)}getKindAuthorIndex(t,n){const r=`${t}:${n}`;return this.kindAuthor.has(r)||this.kindAuthor.set(r,new Set),this.kindAuthor.get(r)}getTagIndex(t){if(!this.tags.has(t)){const n=new Set,r=Date.now();for(const o of this.events.values())It(o).has(t)&&n.add(o);const i=Date.now()-r;i>100&&this.log(`Built index ${t} took ${i}ms`),this.tags.set(t,n)}return this.tags.get(t)}removeFromSortedArray(t,n){if(t.length===0)return;const r=Wt(t,o=>o.created_at-n.created_at);if(r){let o=r[0],s=!1;if(t[o]===n){t.splice(o,1);return}for(let a=o-1;a>=0&&t[a].created_at===n.created_at;a--)if(t[a]===n){t.splice(a,1),s=!0;break}if(s)return;for(let a=o+1;a<t.length&&t[a].created_at===n.created_at;a++)if(t[a]===n){t.splice(a,1);return}}const i=t.indexOf(n);i!==-1&&t.splice(i,1)}*iterateAuthors(t){for(const n of t){const r=this.authors.get(n);if(r)for(const i of r)yield i}}*iterateTag(t,n){for(const r of n){const i=this.getTagIndex(t+":"+r);if(i)for(const o of i)yield o}}*iterateKinds(t){for(const n of t){const r=this.kinds.get(n);if(r)for(const i of r)yield i}}*iterateTime(t,n){if(this.created_at.length===0)return;let r=0,i=this.created_at.length-1,o=n?Wt(this.created_at,a=>a.created_at-n):void 0;o&&(r=Math.max(0,Math.min(o[0],this.created_at.length-1)));const s=t?Wt(this.created_at,a=>a.created_at-t):void 0;if(s&&(i=Math.max(0,Math.min(s[0],this.created_at.length-1))),!(r>i))for(let a=r;a<=i;a++){const c=this.created_at[a];if(!(n!==void 0&&c.created_at>n)){if(t!==void 0&&c.created_at<t)break;yield c}}}*iterateIds(t){for(const n of t)this.events.has(n)&&(yield this.events.get(n))}getEventsForFilter(t){if(t.search)return new Set;let n=!0,r=new Set;const i=s=>{const a=s instanceof Set?s:new Set(s);if(n)r=a,n=!1;else for(const c of r)a.has(c)||r.delete(c);return r};t.ids&&i(this.iterateIds(t.ids));let o=null;t.since!==void 0&&(o=Array.from(this.iterateTime(t.since,t.until)),i(o));for(const s of sr){const a=`&${s}`,c=t[a];if(c!=null&&c.length)for(const u of c)i(this.iterateTag(s,[u]))}for(const s of sr){const a=`#${s}`,c=t[a];if(c!=null&&c.length){const u=`&${s}`,l=t[u],f=l?c.filter(h=>!l.includes(h)):c;f.length>0&&i(this.iterateTag(s,f))}}if(t.authors&&t.kinds&&t.authors.length*t.kinds.length<=20){const s=new Set;for(const a of t.kinds)for(const c of t.authors){const u=`${a}:${c}`,l=this.kindAuthor.get(u);if(l)for(const f of l)s.add(f)}i(s)}else t.authors&&i(this.iterateAuthors(t.authors)),t.kinds&&i(this.iterateKinds(t.kinds));if(t.since===void 0&&t.until!==void 0&&(o=Array.from(this.iterateTime(t.since,t.until)),i(o)),n)return new Set(this.events.values());if(t.limit&&o){const s=new Set;for(const a of o){if(s.size>=t.limit)break;r.has(a)&&s.add(a)}return s}return r}getEventsForFilters(t){if(t.length===0)return new Set;let n=new Set;for(const r of t){const i=this.getEventsForFilter(r);for(const o of i)n.add(o)}return n}reset(){this.events.clear(),this.kinds.clear(),this.authors.clear(),this.kindAuthor.clear(),this.tags.clear(),this.created_at=[],this.replaceable.clear(),this.claims=new WeakMap}}function Li(e){return t=>{const n=new Set;return t.pipe(dn(r=>{if(r!==void 0)if(Array.isArray(r))for(const i of r)n.has(i)||(n.add(i),e.claim(i));else n.has(r)||(n.add(r),e.claim(r))}),ln(()=>{for(const r of n)e.removeClaim(r)}))}}function Ss(e){return t=>{let n;return t.pipe(dn(r=>{n!==r&&(n&&e.removeClaim(n),r&&e.claim(r),n=r)}),ln(()=>{n&&e.removeClaim(n)}))}}function zl(e,t){const n=e.getEvent(t.id);return n instanceof Promise?ae(n):Bt(n)}function Fl(e,t){const n=e.getReplaceable(t.kind,t.pubkey,t.identifier);return n instanceof Promise?ae(n):Bt(n)}function Vl(e,t){const n=e.getByFilters(t);return n instanceof Promise?ae(n).pipe(fn(r=>ae(r))):ae(n)}function As(e,t){return Ua(n=>n||!e.eventLoader?Bt(n):ae(e.eventLoader(t)).pipe(Ma(void 0)))}function Kl(e){return typeof e=="string"&&(e={id:e}),t=>ut(gt(()=>zl(t,e)).pipe(t.eventLoader?As(t,e):Ze),t.insert$.pipe(ge(n=>n.id===e.id)),t.remove$.pipe(ge(n=>n.id===e.id),Ta(1),Me(()=>{}))).pipe(mr((n,r)=>(n==null?void 0:n.id)===(r==null?void 0:r.id)),Ss(t))}function Wl(e){return t=>{let n;return ut(gt(()=>Fl(t,e)).pipe(t.eventLoader?As(t,e):Ze),t.insert$.pipe(ge(r=>r.pubkey==e.pubkey&&r.kind===e.kind&&(e.identifier!==void 0?Fe(r)===e.identifier:!0)))).pipe(dn(r=>n=r),Fn(t.remove$.pipe(ge(r=>r.id===(n==null?void 0:n.id)),Me(()=>{}))),mr((r,i)=>r===void 0||i===void 0?r===i:i.created_at<r.created_at),Ss(t))}}function Gl(e,t){return e=Array.isArray(e)?e:[e],n=>{const r=new Map,i=o=>t?o.id:ol(o);return gt(()=>{const o=n.getTimeline(e);return o instanceof Promise?ae(o):Bt(o)}).pipe(Li(n),Fn(n.insert$.pipe(ge(o=>ar(e,o)),Li(n))),Fn(n.remove$.pipe(ge(o=>ar(e,o)),Me(o=>o.id))),Ra((o,s)=>{var l;if(typeof s=="string"){const f=o.find(h=>h.id===s);if(f){const h=i(f);((l=r.get(h))==null?void 0:l.id)===s&&r.delete(h)}return o.filter(h=>h.id!==s)}if(Array.isArray(s)){r.clear();for(const f of s)r.set(i(f),f);return[...s]}let a=[...o];const c=i(s),u=r.get(c);if(u&&(!de(s.kind)||!t&&s.created_at<u.created_at))return[...o];if(!t&&de(s.kind)){if(r.set(c,s),u){const f=a.indexOf(u);f!==-1&&a.splice(f,1)}}else r.set(c,s);return Kt(a,s),a},[]),mr(),ln(()=>r.clear()))}}function Yl(e,t=!1){return e=Array.isArray(e)?e:[e],n=>{const r=t?un:gt(()=>Vl(n,e)),i=n.insert$.pipe(ge(o=>ar(e,o)));return ut(r,i)}}function Zl(e){return t=>{let n;return ut(t.pipe(dn(r=>n=r)),e.update$.pipe(ge(r=>r.id===(n==null?void 0:n.id))))}}function Xl(e){return typeof e=="string"&&(e={pubkey:e}),t=>t.replaceable({kind:Ou,pubkey:e.pubkey,relays:e.relays}).pipe(Zl(t),Me(n=>n?Sl(n):[]))}function Ql(e){return typeof e=="string"&&(e={pubkey:e}),t=>t.replaceable({kind:Pu,pubkey:e.pubkey,relays:e.relays}).pipe(Me(n=>n&&{inboxes:Nl(n),outboxes:Ml(n)}))}function Jl(e){return typeof e=="string"&&(e={pubkey:e}),t=>t.replaceable({kind:Wo,pubkey:e.pubkey,relays:e.relays}).pipe(ge(Pl),Me(n=>n&&ks(n)))}class ed{constructor(){k(this,"models",new Map);k(this,"modelKeepWarm",6e4);k(this,"destroy$",new ti(1))}model(t,...n){let r=this.models.get(t);r||(r=new Map,this.models.set(t,r));const i=t.getKey?t.getKey(...n):jl(n);let o=r.get(i);if(!o){const s=()=>{r.get(i)===o&&r.delete(i)};o=t(...n)(this).pipe(ln(s),Na({connector:()=>new ti(1),resetOnComplete:()=>ut(Zt(this.modelKeepWarm),this.destroy$),resetOnRefCountZero:()=>ut(Zt(this.modelKeepWarm),this.destroy$)}),Pa(this.destroy$)),r.set(i,o)}return o}filters(t,n=!1){return Array.isArray(t)||(t=[t]),this.model(Yl,t,n)}event(t){return typeof t=="string"||At(t)?this.model(Kl,t):this.replaceable(t)}replaceable(...t){let n;if(t.length===1)n=t[0];else if(t.length===3||t.length===2){let[r,i,o]=t;n={kind:r,pubkey:i,identifier:o}}if(!n)throw new Error("Invalid arguments, expected address pointer or kind, pubkey, identifier");return this.model(Wl,n)}addressable(t){return this.replaceable(t)}timeline(t,n=!1){return this.model(Gl,t,n)}profile(t){return this.model(Jl,t)}contacts(t){return typeof t=="string"&&(t={pubkey:t}),this.model(Xl,t)}mailboxes(t){return typeof t=="string"&&(t={pubkey:t}),this.model(Ql,t)}dispose(){this.destroy$.next(),this.destroy$.complete()}}class td{constructor(){k(this,"expired$");k(this,"expiredSubject");k(this,"expirations",new Map);k(this,"timer",null);k(this,"nextCheck",null);this.expiredSubject=new ye,this.expired$=this.expiredSubject.asObservable()}track(t){const n=or(t);if(!n||!Number.isFinite(n))return;const r=Gt();if(n<=r||(this.expirations.set(t.id,n),this.timer&&this.nextCheck&&this.nextCheck<=n))return;this.timer&&clearTimeout(this.timer);const i=n-r;i>0&&(this.timer=setTimeout(this.emitNotifications.bind(this),i*1e3+10),this.nextCheck=n)}forget(t){this.expirations.delete(t)}check(t){const n=or(t);return n?n<=Gt():!1}dispose(){this.timer&&clearTimeout(this.timer),this.timer=null,this.nextCheck=null,this.expirations.clear(),this.expiredSubject.complete()}[Symbol.dispose](){this.dispose()}emitNotifications(){const t=Gt();let n=1/0;for(const[r,i]of this.expirations)i<=t?(this.expirations.delete(r),this.expiredSubject.next(r)):i<n&&(n=i);if(n!==1/0){this.timer&&clearTimeout(this.timer),this.nextCheck=null,this.timer=null;const r=n-t;r>0&&(this.timer=setTimeout(this.emitNotifications.bind(this),r*1e3+10),this.nextCheck=n)}}}class $t extends ed{constructor(n){super();k(this,"database");k(this,"memory");k(this,"deletes");k(this,"expiration");k(this,"keepOldVersions",!1);k(this,"keepExpired",!1);k(this,"keepDeleted",!1);k(this,"_verifyEventMethod",tl);k(this,"insert$",new ye);k(this,"update$",new ye);k(this,"remove$",new ye);k(this,"eventLoader");k(this,"internalSubscriptions",new we);n!=null&&n.database?(this.database=n.database,this.memory=new Ci):this.database=this.memory=new Ci,(n==null?void 0:n.keepDeleted)!==void 0&&(this.keepDeleted=n.keepDeleted),(n==null?void 0:n.keepExpired)!==void 0&&(this.keepExpired=n.keepExpired),(n==null?void 0:n.keepOldVersions)!==void 0&&(this.keepOldVersions=n.keepOldVersions),n!=null&&n.verifyEvent&&(this.verifyEvent=n.verifyEvent),this.deletes=(n==null?void 0:n.deleteManager)??new Dl,this.internalSubscriptions.add(this.deletes.deleted$.subscribe(this.handleDeleteNotification.bind(this))),this.expiration=(n==null?void 0:n.expirationManager)??new td,this.internalSubscriptions.add(this.expiration.expired$.subscribe(this.handleExpiredNotification.bind(this)))}get verifyEvent(){return this._verifyEventMethod}set verifyEvent(n){this._verifyEventMethod=n,n===void 0&&console.warn("[applesauce-core] EventStore.verifyEvent is undefined; signature checks are disabled.")}mapToMemory(n){if(n!==void 0)return this.memory?this.memory.add(n):n}handleDeleteNotification({pointer:n,until:r}){if(!this.keepDeleted){if(At(n)){const i=this.getEvent(n.id);i&&r>=i.created_at&&Ai(i,n)&&this.remove(i)}else if(gl(n)){const i=this.getReplaceableHistory(n.kind,n.pubkey,n.identifier);if(i)for(const o of i)r>=o.created_at&&Ai(o,n)&&this.remove(o)}}}handleExpiredNotification(n){this.keepExpired||this.remove(n)}static copySymbolsToDuplicateEvent(n,r){if(n.kind!==r.kind)throw new Error("Source and destination events must have the same kind");if(Lu(n.kind)&&n.id!==r.id)throw new Error("Source and destination events must have the same ID");if(de(n.kind)&&n.pubkey!==r.pubkey&&Fe(n)!==Fe(r))throw new Error("Source and destination events must have the same pubkey and replaceable identifier");let i=!1;const o=ll(n);if(o){for(const a of o)Si(r,a);i=!0}const s=[rl,He,Ur];for(const a of s)a in n&&!(a in r)&&(Reflect.set(r,a,Reflect.get(n,a)),i=!0);return i}add(n,r){if(n.kind===Go)return this.deletes.add(n),n;if(this.deletes.check(n))return n;const i=or(n);if(this.keepExpired===!1&&i&&i<=Gt())return null;r&&Si(n,r);const o=de(n.kind)?Fe(n):void 0;if(this.keepOldVersions===!1&&de(n.kind)){const c=this.database.getReplaceableHistory(n.kind,n.pubkey,o);if(c&&c.length>0){let u=c[0];for(const f of c)(f.created_at>u.created_at||f.created_at===u.created_at&&f.id<u.id)&&(u=f);if(!(n.created_at>u.created_at||n.created_at===u.created_at&&n.id<u.id))return $t.copySymbolsToDuplicateEvent(n,u)&&this.update(u),u}}if(this.verifyEvent&&this.verifyEvent(n)===!1)return null;const s=this.memory.add(n);if(s&&s!==n)return $t.copySymbolsToDuplicateEvent(n,s)&&this.update(s),s;const a=this.mapToMemory(this.database.add(n));if(a===n?(Reflect.set(a,Ei,this),this.insert$.next(a)):$t.copySymbolsToDuplicateEvent(n,a)&&this.update(a),this.keepOldVersions===!1&&de(n.kind)){const c=this.database.getReplaceableHistory(n.kind,n.pubkey,o);if(c&&c.length>0){let u=c[0];for(const f of c)(f.created_at>u.created_at||f.created_at===u.created_at&&f.id<u.id)&&(u=f);const l=c.filter(f=>f!==u);for(const f of l)this.remove(f);if(l.length>0)return u}}return this.keepExpired===!1&&i!==void 0&&this.expiration.track(a),a}remove(n){const r=typeof n=="string"?n:n.id;let i=this.memory.getEvent(r);this.expiration.forget(r),i&&Reflect.deleteProperty(i,Ei),this.memory!==this.database&&this.memory.remove(n);const o=this.database.remove(n);return o&&i&&this.remove$.next(i),o}removeByFilters(n){const r=this.getByFilters(n);for(const o of r)this.expiration.forget(o.id);this.memory!==this.database&&this.memory.removeByFilters(n);const i=this.database.removeByFilters(n);for(const o of r)this.remove$.next(o);return i}update(n){var i,o;return this.database.add(n)?((o=(i=this.database).update)==null||o.call(i,n),this.update$.next(n),!0):!1}hasEvent(n){return typeof n=="string"?this.memory.hasEvent(n)||this.database.hasEvent(n):At(n)?this.memory.hasEvent(n.id)||this.database.hasEvent(n.id):this.hasReplaceable(n.kind,n.pubkey,n.identifier)}getEvent(n){return typeof n=="string"?this.memory.getEvent(n)??this.mapToMemory(this.database.getEvent(n)):At(n)?this.memory.getEvent(n.id)??this.mapToMemory(this.database.getEvent(n.id)):this.getReplaceable(n.kind,n.pubkey,n.identifier)}hasReplaceable(n,r,i){return this.memory.hasReplaceable(n,r,i)||this.database.hasReplaceable(n,r,i)}getReplaceable(n,r,i){return this.memory.getReplaceable(n,r,i)??this.mapToMemory(this.database.getReplaceable(n,r,i))}getReplaceableHistory(n,r,i){var o;return this.memory.getReplaceableHistory(n,r,i)??((o=this.database.getReplaceableHistory(n,r,i))==null?void 0:o.map(s=>this.mapToMemory(s)??s))}getByFilters(n){const r=this.database.getByFilters(n);return this.memory?r.map(i=>this.mapToMemory(i)):r}getTimeline(n){const r=this.database.getTimeline(n);return this.memory?r.map(i=>this.mapToMemory(i)):r}touch(n){return this.memory.touch(n)}claim(n){return this.memory.claim(n)}isClaimed(n){return this.memory.isClaimed(n)??!1}removeClaim(n){return this.memory.removeClaim(n)}clearClaim(n){return this.memory.clearClaim(n)}unclaimed(){return this.memory.unclaimed()||(function*(){})()}prune(n){return this.memory.prune(n)??0}dispose(){var r,i;const n=this.eventLoader;n&&typeof n[Symbol.dispose]=="function"&&n[Symbol.dispose](),this.eventLoader=void 0,super.dispose(),this.internalSubscriptions.unsubscribe(),(i=(r=this.expiration).dispose)==null||i.call(r),this.insert$.complete(),this.update$.complete(),this.remove$.complete()}[Symbol.dispose](){this.dispose()}}function nd(){return new $t({verifyEvent:e=>Uc(e)})}function rd(e,t){const n=[];for(const r of t){const i=Hc(r);if(!i)continue;const o=e.get(i.pubkey);o&&o.createdAt>=i.createdAt||(e.set(i.pubkey,i),(!o||o.name!==i.name||o.displayName!==i.displayName||o.picture!==i.picture)&&n.push(i.pubkey))}return n}const Ot=nd();function En(e){if(!(!e||!Ir(e.pubkey)))return Ot.add(e)??void 0}const dt=new Map,id=Ot.timeline({kinds:[yn]}).pipe(Me(e=>rd(dt,e))),Hn=new Set;let Ft,Oi;const Ri=250;function od(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function Hr(e){!Ir(e)||Hn.has(e)||(Hn.add(e),Oi??(Oi=setTimeout(()=>{Oi=void 0;const t=[...Hn].slice(-1e3),n=Fo(od(t,Ri).map(r=>({kinds:[yn],authors:r})),{authors:t.slice(0,Ri)}).subscribe(r=>En(r));Ft==null||Ft.unsubscribe(),Ft=n},16)))}const sn=new eo(!1);function sd(){ku().then(e=>{e&&!sn.value&&sn.next(!0)})}function Is(e,t){const n=dc(e,null,t);return n?bc(n):sn.value&&e.startsWith("https://")?e:null}function ad(e,t){const n=new we;n.add(Fo([{kinds:[Yn,yn],authors:[e]}],{authors:[e],...t?{onNotice:t}:{}}).subscribe(i=>En(i)));const r=new eo([]);return n.add(Ot.replaceable(Yn,e).subscribe(i=>r.next((i==null?void 0:i.pubkey)===e?Pc(i):[]))),{me:e,follows$:r,close:()=>n.unsubscribe()}}async function cd(e){if(!e.id)return;const t=Ot.getEvent(e.id);if(t)return t;const n=await ka(Cu(e.id,{...e.author?{author:e.author}:{},relays:e.relays}).pipe(Ba()),{defaultValue:[]}).catch(()=>[]);for(const r of n)En(r);return Ot.getEvent(e.id)}const ud=20;async function fd(e,t=[]){const n=await vu(t.slice(0,ud)),r=await xu(e,{toInboxes:n});return r.ok&&En(r.event),r}function T(e,t=null,...n){const r=document.createElement(e);if(t)for(const[i,o]of Object.entries(t))r.setAttribute(i,o);for(const i of n)i!=null&&i!==!1&&r.append(i);return r}const ie=e=>document.getElementById(e),ld={back:'<path d="M15 5l-7 7 7 7"/>',globe:'<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.6 3.8 5.6 3.8 9s-1.3 6.4-3.8 9c-2.5-2.6-3.8-5.6-3.8-9S9.5 5.6 12 3z"/>',copy:'<rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V6a2 2 0 0 1 2-2h9"/>',check:'<path d="M5 12.5l4.5 4.5L19 7.5"/>',bolt:'<path d="M13 3 5 13.5h6L10 21l8-10.5h-6z"/>',close:'<path d="M6 6l12 12M18 6L6 18"/>',reply:'<path d="M10 8L4 13l6 5"/><path d="M4 13h10a6 6 0 0 1 6 6"/>',quote:'<path d="M7 7h4v4c0 3-1.5 5-4 6M14 7h4v4c0 3-1.5 5-4 6"/>',verified:'<path fill="currentColor" stroke="none" d="M12 2.5l2.4 1.8 3-.1.9 2.9 2.4 1.8-1 2.9 1 2.9-2.4 1.8-.9 2.9-3-.1L12 21.5l-2.4-1.8-3 .1-.9-2.9-2.4-1.8 1-2.9-1-2.9 2.4-1.8.9-2.9 3 .1z"/><path d="M8.3 12.2l2.5 2.5 4.9-5" style="stroke: var(--bg)" stroke-width="2" fill="none"/>'};function $s(e){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("aria-hidden","true"),t.classList.add("icon"),t.innerHTML=ld[e],t}class dd{constructor(t,n=4){k(this,"done",new Map);k(this,"failed",new Map);k(this,"jobs",new Map);k(this,"running",0);this.load=t,this.max=n}loaded(t){return this.done.get(t)}hasFailed(t){return this.failed.has(t)}get stats(){return{running:this.running,queued:this.jobs.size-this.running}}want(t,n){const r=this.done.get(t);if(r!==void 0)return n.ready(r),()=>{};if(this.failed.has(t))return n.fail(this.failed.get(t)),()=>{};let i=this.jobs.get(t);i||this.jobs.set(t,i={key:t,waiters:new Set,running:!1}),i.waiters.add(n),this.pump();const o=i;return()=>this.release(o,n)}release(t,n){var r;!t.waiters.delete(n)||t.waiters.size>0||(t.running?(r=t.controller)==null||r.abort():this.jobs.get(t.key)===t&&this.jobs.delete(t.key))}next(){let t;for(const n of this.jobs.values())if(!n.running){for(const r of n.waiters)if(r.isVisible())return n;t??(t=n)}return t}pump(){for(;this.running<this.max;){const t=this.next();if(!t)return;this.start(t)}}start(t){const n=new AbortController;t.running=!0,t.controller=n,this.running++,this.load(t.key,n.signal).then(r=>{this.done.set(t.key,r),this.finish(t);for(const i of t.waiters)i.ready(r)},r=>{if(n.signal.aborted){this.running--,t.running=!1,t.controller=void 0,t.waiters.size===0&&this.jobs.delete(t.key),this.pump();return}this.failed.set(t.key,r),this.finish(t);for(const i of t.waiters)i.fail(r)})}finish(t){this.running--,this.jobs.delete(t.key),this.pump()}}const hd=300,pd=4;async function yd(e){const t=e.type.toLowerCase();if(t.includes("svg")||t&&!t.startsWith("image/")&&t!=="application/octet-stream")return!1;const n=new TextDecoder().decode(await e.slice(0,1024).arrayBuffer()).toLowerCase();return!n.includes("<svg")&&!n.trimStart().startsWith("<?xml")&&!n.trimStart().startsWith("<")}function gd(e){return gc(e)??e}const cr=new Map,ur=new dd(async(e,t)=>{if(!U("resource","bytes"))throw new Error("no resource domain");const n=await su(cr.get(e)??e,{signal:t});if(n.size===0||!await yd(n))throw new Error("not a raster image");return URL.createObjectURL(n)},pd);function _s(e){const t=gd(e);return cr.has(t)||cr.set(t,e),t}const Bs=new WeakMap,Le=new WeakMap,Ni=new Set;function bd(e){if(!e.isConnected)return!1;const t=e.getBoundingClientRect();return t.bottom>0&&t.top<(window.innerHeight||0)&&t.width+t.height>0}function kn(e,t){const n=e.parentElement;!n||n.classList.contains("avatar")||n.classList.toggle("is-loading",t)}function wd(e,t){Le.delete(e),Re==null||Re.unobserve(e);const n=()=>{e.src=t,e.classList.add("loaded"),kn(e,!1)};if(Ni.has(t)||typeof Image!="function"){n();return}const r=new Image;r.decoding="async",r.src=t,(typeof r.decode=="function"?r.decode():Promise.resolve()).catch(()=>{}).then(()=>{Ni.add(t),n()})}function md(e){var t;Le.delete(e),Re==null||Re.unobserve(e),kn(e,!1),(t=Bs.get(e))==null||t(e)}function Ts(e){const t=e.dataset.res;if(!t||Le.has(e)||e.classList.contains("loaded"))return;Le.set(e,()=>{}),kn(e,!0);const n=ur.want(_s(t),{isVisible:()=>bd(e),ready:r=>wd(e,r),fail:()=>md(e)});Le.has(e)&&Le.set(e,n)}function vd(e){const t=Le.get(e);t&&(Le.delete(e),kn(e,!1),t())}const Re=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{for(const t of e){const n=t.target;t.isIntersecting?Ts(n):vd(n)}},{rootMargin:`${hd}px 0px`}):void 0;function Cs(e,t,n){e.dataset.res=t,e.decoding="async",n&&Bs.set(e,n);const r=_s(t),i=ur.loaded(r);if(i!==void 0){e.src=i,e.classList.add("loaded");return}if(ur.hasFailed(r)){queueMicrotask(()=>n==null?void 0:n(e));return}Re?Re.observe(e):Ts(e)}function xd(e,t){const n=e.slice(0,t),r=/(^|[\s(])@([\p{L}\p{N}_.-]{0,32})$/u.exec(n);return r?{start:n.length-r[2].length-1,query:r[2].toLowerCase()}:null}function Ed(e,t){const n=[e.displayName,e.name,e.nip05].filter(i=>!!i).map(i=>i.toLowerCase());if(!t)return n.length?1:0;let r=0;for(const i of n)i===t?r=Math.max(r,4):i.startsWith(t)?r=Math.max(r,3):i.split(/[\s._@-]+/).some(o=>o.startsWith(t))?r=Math.max(r,2):i.includes(t)&&(r=Math.max(r,1));return r}function kd(e,t,n=6){return e.map((r,i)=>({p:r,i,s:Ed(r,t)})).filter(r=>r.s>0).sort((r,i)=>i.s-r.s||r.i-i.i).slice(0,n).map(r=>r.p)}function Ls(e){return`@${e.replace(/[\s\u200b-\u200d\ufeff]+/g," ").trim().slice(0,48)||"someone"}`}function qr(e,t,n){const r=Ls(e),i=n.find(o=>o.label===r);return!i||i.pubkey===t?r:`${r} (${ft(t).slice(0,12)})`}function Sd(e,t,n,r){const i=`${r} `;return{text:e.slice(0,t)+i+e.slice(n),caret:t+i.length}}function Ad(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function jr(e){return new RegExp(`(^|[^\\p{L}\\p{N}_@])${Ad(e)}(?![\\p{L}\\p{N}_])`,"gu")}function Id(e,t){let n=e;for(const r of[...t].sort((i,o)=>o.label.length-i.label.length)){const i=`nostr:${ft(r.pubkey)}`;n=n.replace(jr(r.label),(o,s)=>`${s}${i}`)}return n}const $d=/nostr:((?:npub1|nprofile1)[023456789acdefghjklmnpqrstuvwxyz]+)/gi;function _d(e,t,n=[]){const r=[...n];return{text:e.replace($d,(o,s)=>{let a;try{const l=wt(s.toLowerCase());if(l.type==="npub")a=l.data;else if(l.type==="nprofile")a=l.data.pubkey;else return o}catch{return o}const c=r.find(l=>l.pubkey===a);if(c)return c.label;const u=qr(t(a),a,r);return r.push({label:u,pubkey:a}),u}),mentions:r}}function Bd(e,t){return t.filter(n=>jr(n.label).test(e))}function Td(e,t,n,r,i){const o=n.find(c=>c.pubkey===r);if(!o||o.label===i||n.some(c=>c.label===i))return{text:e,caret:t,mentions:[...n]};let s=0;return{text:e.replace(jr(o.label),(c,u,l)=>(l+c.length<=t&&(s+=i.length-o.label.length),`${u}${i}`)),caret:t+s,mentions:n.map(c=>c.pubkey===r?{label:i,pubkey:r}:c)}}const Cd=/^[0-9a-f]{64}$/i,Mi=1e4,Ld=20;function Ui(e){const t=Ar(e);return t&&t.id?t:void 0}function Od(e){if(typeof e!="string")return;const t=e.trim().replace(/^nostr:/i,"");if(Cd.test(t))return t.toLowerCase();try{const n=wt(t.toLowerCase());if(n.type==="npub")return n.data;if(n.type==="nprofile")return n.data.pubkey}catch{}}function Rd(e){if(typeof e=="string")return e.trim()?{content:e.slice(0,Mi),mentions:[]}:null;if(typeof e!="object"||e===null||Array.isArray(e))return null;const t=e,n=Ui(t.replyTo??t.reply??t.inReplyTo),r=Ui(t.quote),i=typeof t.content=="string"?t.content:typeof t.text=="string"?t.text:void 0,o=Array.isArray(t.mentions)?[...new Set(t.mentions.map(Od).filter(s=>!!s))].slice(0,Ld):[];return Object.keys(t).length&&!n&&!r&&!(i!=null&&i.trim())&&!o.length?null:{...n?{replyTo:n}:{},...r?{quote:r}:{},...i!=null&&i.trim()?{content:i.slice(0,Mi)}:{},mentions:o}}function Nd(e){const t=e.mentions.map(n=>`nostr:${ft(n)}`).join(" ");return[t,e.content??""].filter(Boolean).join(t&&e.content?" ":"")}function fr(e){const t=ft(e);return`${t.slice(0,10)}…${t.slice(-4)}`}function mt(e){const t=dt.get(e);return(t==null?void 0:t.displayName)||(t==null?void 0:t.name)||fr(e)}function Dr(e,t="span"){return Hr(e),T(t,{class:"name","data-pk":e,"data-role":"name"},mt(e))}let lr=new Set;function zr(e,t){Hr(e);const n=T("span",{class:`avatar avatar-${t}`,"data-pk":e,"data-role":"avatar","aria-hidden":"true"});return n.classList.toggle("avatar-followed",lr.has(e)),Fr(n,e),n}function Pi(e){lr=new Set(e);for(const t of document.querySelectorAll('[data-role="avatar"][data-pk]'))t.classList.toggle("avatar-followed",lr.has(t.dataset.pk))}const Md="🥀";function Fr(e,t){var c;const n=(mt(t).replace(/^npub1/,"")[0]??"?").toUpperCase(),r=T("span",{class:"avatar-initial"},n);e.replaceChildren(r),e.classList.remove("avatar-wilted"),e.style.setProperty("--hue",String(parseInt(t.slice(0,4),16)%360));const i=(c=dt.get(t))==null?void 0:c.picture;if(!i)return;const o=()=>{r.textContent=Md,e.classList.add("avatar-wilted")},s=Is(i,t);if(!s){o();return}const a=T("img",{alt:"",decoding:"async"});e.append(a),Cs(a,s,u=>{u.remove(),o()})}function Ud(e){for(const t of document.querySelectorAll(`[data-pk="${e}"]`)){const n=t.dataset.role;n==="name"?t.textContent=mt(e):n==="avatar"&&Fr(t,e)}}sn.subscribe(e=>{if(e)for(const t of document.querySelectorAll('[data-role="avatar"][data-pk]'))t.querySelector("img")||Fr(t,t.dataset.pk)});const Pd={background:"#ffffff",text:"#0f172a",primary:"#059669"},Hd={background:"#000000",text:"#ffffff",primary:"#34d399"},qd=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;function an(e){let t=e.slice(1);return t.length===3&&(t=[...t].map(n=>n+n).join("")),[0,2,4].map(n=>parseInt(t.slice(n,n+2),16))}function Hi(e){const[t,n,r]=an(e).map(i=>{const o=i/255;return o<=.03928?o/12.92:((o+.055)/1.055)**2.4});return .2126*t+.7152*n+.0722*r}function qi(e,t,n){const[r,i]=[an(e),an(n)],o=s=>Math.round((r[s]*t+i[s]*(100-t))/100);return`rgb(${o(0)}, ${o(1)}, ${o(2)})`}function qn(e,t){const[n,r,i]=an(e);return`rgba(${n}, ${r}, ${i}, ${t/100})`}function nt(e){var l,f,h,p;const n=((l=window.matchMedia)==null?void 0:l.call(window,"(prefers-color-scheme: dark)").matches)??!1?Hd:Pd,r=(y,d)=>y&&qd.test(y)?y:d,i=r((f=e==null?void 0:e.colors)==null?void 0:f.background,n.background),o=r((h=e==null?void 0:e.colors)==null?void 0:h.text,n.text),s=r((p=e==null?void 0:e.colors)==null?void 0:p.primary,n.primary),a=Hi(i)<.35,c=document.documentElement,u=(y,d)=>c.style.setProperty(y,d);u("--bg",i),u("--text",o),u("--primary",s),u("--on-primary",Hi(s)>.45?"#000000":"#ffffff"),u("--surface",qi(o,a?8:4,i)),u("--border",qn(o,a?18:12)),u("--muted",qi(o,60,i)),u("--primary-soft",qn(s,16)),u("--scrim",qn("#000000",a?70:45)),c.style.colorScheme=a?"dark":"light"}function ji(){var e;if(nt(void 0),!U("theme","get")){(e=window.matchMedia)==null||e.call(window,"(prefers-color-scheme: dark)").addEventListener("change",()=>nt(void 0));return}try{nu().then(nt,()=>nt(void 0)),ru(nt)}catch{nt(void 0)}}let X="",le,Di=0,V,ce,ht=0,cn=!1,Ce=!1,Q=[];const Os=ie("title"),zi=ie("status"),Ge=ie("context"),Rs=ie("compose"),_=ie("text"),Fi=ie("rendered"),Ye=ie("quote"),dr=ie("done"),pt=ie("post"),Rt=ie("preview"),Oe=ie("suggest"),jd=ie("me");function De(e){zi.textContent=e??"",zi.hidden=!e}const Vr="composer-draft";let Vi;function Dd(){V||ce||ht||(window.clearTimeout(Vi),Vi=window.setTimeout(()=>void Do(Vr,Ns()),500))}function Ns(){return Id(_.value,Q)}function Ms(e){const t=_d(e,mt);_.value=t.text,Q=t.mentions}function Kr(){return{content:Ns(),...V?{replyTo:V.event,replyRelay:V.relay}:{},...ce?{quote:ce.event,quoteRelay:ce.relay}:{}}}function Nt(){const e=!!X&&qo()&&!ht&&!cn&&fc(Kr());pt.disabled=!e,pt.textContent=cn?"Posting…":V?"Reply":"Post"}function yt(){Os.textContent=V||st==="reply"?"Reply":ce||st==="quote"?"Quote":"New note",_.placeholder=V||st==="reply"?"Write your reply":ce?"Add a comment":"What's on your mind?"}let st=null;function zd(){const e=window.scrollY;_.style.height="auto",_.style.height=`${_.scrollHeight}px`,window.scrollTo(0,e)}let at=null,hr=!1;function Fd(){const e=(le==null?void 0:le.follows$.value)??[];!hr&&e.length&&(hr=!0,e.forEach(Hr));const t=new Set,n=[];for(const r of[...e,...dt.keys()]){if(t.has(r)||r===X)continue;t.add(r);const i=dt.get(r);n.push({pubkey:r,...i!=null&&i.name?{name:i.name}:{},...i!=null&&i.displayName?{displayName:i.displayName}:{},...i!=null&&i.nip05?{nip05:i.nip05}:{}})}return n}function Wr(){if(at=xd(_.value,_.selectionStart??_.value.length),!at){Oe.hidden=!0;return}const e=kd(Fd(),at.query);if(!e.length){Oe.hidden=!0;return}Oe.replaceChildren(...e.map(t=>{var i;const n=(i=dt.get(t.pubkey))==null?void 0:i.nip05,r=T("button",{type:"button",class:"suggest-item",role:"option"},zr(t.pubkey,"sm"),T("span",{class:"suggest-text"},Dr(t.pubkey),n?T("span",{class:"suggest-nip05"},n):""));return r.addEventListener("mousedown",o=>o.preventDefault()),r.addEventListener("click",()=>Vd(t.pubkey)),r})),Oe.hidden=!1}function Vd(e){if(!at)return;const t=_.selectionStart??_.value.length,n=Q.find(o=>o.pubkey===e),r=(n==null?void 0:n.label)??qr(mt(e),e,Q);n||Q.push({label:r,pubkey:e});const i=Sd(_.value,at.start,t,r);_.value=i.text,_.setSelectionRange(i.caret,i.caret),Oe.hidden=!0,at=null,_.focus(),be()}function Gr(e){const t=T("div",{class:"content"});for(const n of Nc(e))if(n.type==="text")t.append(n.text);else if(n.type==="link")t.append(T("span",{class:"link-text"},n.url));else if(n.type==="profile")t.append(T("span",{class:"mention"},"@",Dr(n.pubkey)));else if(n.type==="note")t.append(T("span",{class:"link-text"},n.text.replace(/^nostr:/,"").slice(0,16)+"…"));else if(n.type==="image"){const r=Is(n.url);if(r){const i=T("img",{alt:"",decoding:"async"}),o=T("span",{class:"pic"},i);Cs(i,r,()=>o.replaceWith(T("span",{class:"link-text"},n.url))),t.append(o)}else t.append(T("span",{class:"link-text"},n.url))}else t.append(T("span",{class:"link-text"},n.url));return t}function Us(){Rt.setAttribute("aria-pressed",String(Ce)),Rt.textContent=Ce?"Edit":"Preview",_.hidden=Ce,Fi.hidden=!Ce,Ce&&Fi.replaceChildren(Gr($o(Kr(),X).content))}function Ki(e,t){const n=e.content.length>400?`${e.content.slice(0,400)}…`:e.content,r=T("button",{type:"button",class:"card-who"},zr(e.pubkey,"sm"),Dr(e.pubkey));r.addEventListener("click",()=>void Iu(e.pubkey));const i=T("article",{class:"card"},T("div",{class:"card-label"},t),r,T("div",{class:"card-text"},Gr(n)));return i.addEventListener("click",o=>{o.target.closest("button")||_r({id:e.id,author:e.pubkey,kind:e.kind})}),i}function Kd(e){return T("div",{class:"card card-missing"},`The ${e} couldn't be found. You can still write; it will be posted as a new note.`)}function Wi(e){const t=T("button",{type:"button",class:"card-clear","aria-label":`Remove the ${e}`},$s("close"));return t.addEventListener("click",()=>{e==="reply"?(V=void 0,Ge.replaceChildren(),Ge.hidden=!0):(ce=void 0,Ye.replaceChildren(),Ye.hidden=!0),yt(),be()}),t}async function Gi(e,t,n){const r=e==="reply"?Ge:Ye;ht++,st=e,r.hidden=!1,r.replaceChildren(T("div",{class:"card card-loading is-loading"},e==="reply"?"Finding the note you are replying to…":"Finding the note you are quoting…")),yt(),Nt();const i=await cd(t);if(n!==Ps)return;ht--,st=null;const o=t.relays[0]??"";i?e==="reply"?(V={event:i,relay:o},r.replaceChildren(T("div",{class:"card-row"},Ki(i,"Replying to"),Wi("reply")))):(ce={event:i,relay:o},r.replaceChildren(T("div",{class:"card-row"},Ki(i,"Quoting"),Wi("quote")))):r.replaceChildren(Kd(e==="reply"?"note you are replying to":"quoted note")),yt(),be()}let Ps=0;function Wd(e){const t=Rd(e);t&&Gd(t)}function Gd(e){const t=++Ps;ht=0,st=null,V=void 0,ce=void 0,Ge.replaceChildren(),Ge.hidden=!0,Ye.replaceChildren(),Ye.hidden=!0,qs();const n=Nd(e);Ms(n&&e.mentions.length&&!e.content?`${n} `:n),e.replyTo&&Gi("reply",e.replyTo,t),e.quote&&Gi("quote",e.quote,t),yt(),be(),_.focus();const r=_.value.length;_.setSelectionRange(r,r)}async function Hs(){if(pt.disabled)return;const e=Kr();cn=!0,Nt(),De(null);const t=$o(e,X),n=await fd(t,lc(e,t,X));if(cn=!1,!n.ok){De(n.error?`Not posted: ${n.error}`:"Not posted."),Nt();return}Do(Vr,""),_.value="",Q=[],Yd(n.event,t.content),n.event&&_r({id:n.event.id,author:n.event.pubkey,kind:n.event.kind})}function Yd(e,t){Rs.hidden=!0,Ge.hidden=!0,Ye.hidden=!0,pt.hidden=!0,Rt.hidden=!0,Os.textContent=V?"Replied":"Posted";const n=T("button",{type:"button",class:"btn"},"Write another");n.addEventListener("click",()=>{_.value="",Q=[],V=void 0,ce=void 0,Ge.replaceChildren(),Ye.replaceChildren(),qs(),yt(),be(),_.focus()});const r=T("div",{class:"done-actions"},n);if(e){const i=T("button",{type:"button",class:"btn"},"Open it");i.addEventListener("click",()=>void _r({id:e.id,author:e.pubkey,kind:e.kind})),r.prepend(i)}dr.replaceChildren(T("div",{class:"done-mark"},$s("check"),V?"Your reply is out.":"Your note is out."),T("div",{class:"done-note"},Gr(t)),r),dr.hidden=!1}function qs(){dr.hidden=!0,Rs.hidden=!1,pt.hidden=!1,Rt.hidden=!1,Ce=!1,Us()}function be(){Q=Bd(_.value,Q),zd(),Nt(),Wr(),Dd()}_.addEventListener("input",be);_.addEventListener("click",Wr);_.addEventListener("keyup",e=>{e.key.startsWith("Arrow")&&Wr()});_.addEventListener("keydown",e=>{e.key==="Enter"&&(e.metaKey||e.ctrlKey)?(e.preventDefault(),Hs()):e.key==="Escape"&&!Oe.hidden&&(e.preventDefault(),e.stopPropagation(),Oe.hidden=!0)});pt.addEventListener("click",()=>void Hs());Rt.addEventListener("click",()=>{Ce=!Ce,Oe.hidden=!0,Us()});function Zd(){const e=window.visualViewport;if(!e)return;const t=()=>{const n=Math.max(0,window.innerHeight-e.height-e.offsetTop);document.documentElement.style.setProperty("--keyboard",`${Math.round(n)}px`)};e.addEventListener("resize",t),e.addEventListener("scroll",t),t()}let jn=new we;function Xd(e){const t=Q.find(o=>o.pubkey===e);if(!t||t.label!==Ls(fr(e)))return;const n=mt(e);if(n===fr(e))return;const r=_.selectionStart??_.value.length,i=Td(_.value,r,Q,e,qr(n,e,Q));_.value=i.text,Q=i.mentions,document.activeElement===_&&_.setSelectionRange(i.caret,i.caret),be()}async function Yi(){const e=++Di,t=await bu();e===Di&&(t===X&&le||(le==null||le.close(),jn.unsubscribe(),jn=new we,X=t,le=X?ad(X,n=>De(n)):void 0,hr=!1,Pi([]),le&&jn.add(le.follows$.subscribe(n=>Pi(n))),jd.replaceChildren(X?zr(X,"md"):""),X?qo()?De(null):De("This shell cannot publish."):De("You're not logged in. Log in to this app's shell to post."),Nt()))}gu()?(Au(Su,e=>queueMicrotask(()=>Wd(e))),ji(),Zd(),sd(),id.subscribe(e=>{e.forEach(Ud),e.forEach(Xd)}),wu(e=>{e!==X&&Yi()}),Yi(),$u(Vr).then(e=>{e&&!_.value&&!V&&!ce&&!ht&&(Ms(e),be())}),yt(),be(),_.focus()):(ji(),De("Composer runs inside a napplet shell such as Myco. Open it from there."),_.disabled=!0);
</script>
    <style>:root{--bg: #ffffff;--text: #0f172a;--primary: #059669;--on-primary: #ffffff;--surface: #f5f6f8;--border: rgba(15, 23, 42, .12);--muted: #64748b;--primary-soft: rgba(5, 150, 105, .16);--gold: #d4a017;--font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;--keyboard: 0px}@media(prefers-color-scheme:dark){:root{--bg: #000000;--text: #ffffff;--primary: #34d399;--on-primary: #000000;--surface: #141414;--border: rgba(255, 255, 255, .18);--muted: #999999;--primary-soft: rgba(52, 211, 153, .16);--gold: #f5c542}}*{box-sizing:border-box}html,body{margin:0;background:var(--bg);color:var(--text);font:16px/1.45 var(--font);-webkit-text-size-adjust:100%}button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}[hidden]{display:none!important}.icon{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;flex:none}.app{max-width:640px;margin:0 auto;min-height:100vh;padding-bottom:calc(env(safe-area-inset-bottom) + var(--keyboard) + 24px)}.bar{position:sticky;top:0;z-index:5;display:flex;align-items:center;gap:8px;padding:calc(env(safe-area-inset-top) + 8px) 16px 8px;background:var(--bg);border-bottom:1px solid var(--border)}.bar-title{flex:1;margin:0;font-size:17px;font-weight:600}.bar-btn{min-height:36px;padding:0 12px;border-radius:999px;color:var(--muted);font-size:14px;font-weight:500}.bar-btn[aria-pressed=true]{color:var(--primary)}.post-btn{min-height:36px;padding:0 18px;border-radius:999px;background:var(--primary);color:var(--on-primary);font-weight:600}.post-btn:disabled{opacity:.4;cursor:default}.status{margin:12px 16px 0;padding:10px 12px;border-radius:10px;background:var(--surface);color:var(--muted);font-size:14px}.compose{padding:12px 16px 0}.writer{display:flex;gap:12px;align-items:flex-start}.writer-avatar{flex:none;padding-top:4px}.text{flex:1;min-width:0;min-height:120px;padding:6px 0;border:0;outline:none;resize:none;background:transparent;color:var(--text);font:18px/1.5 var(--font)}.text::placeholder{color:var(--muted)}.rendered{padding:6px 0 6px 48px;font-size:18px;line-height:1.5}.content{white-space:pre-wrap;overflow-wrap:anywhere}.mention{color:var(--primary);font-weight:500}.link-text{color:var(--primary);overflow-wrap:anywhere}.pic{display:block;position:relative;margin:8px 0;min-height:120px;border-radius:12px;overflow:hidden;background:var(--surface)}.pic:has(img.loaded){min-height:0}.pic img{display:block;width:100%;height:auto;opacity:0}.pic img.loaded{opacity:1}.context{padding:12px 16px 0}.quote-slot{padding:12px 0 0 48px}.card-row{display:flex;gap:6px;align-items:flex-start}.card{flex:1;min-width:0;padding:10px 12px;border:1px solid var(--border);border-radius:14px;cursor:pointer}.card-label{color:var(--muted);font-size:12px;font-weight:600;letter-spacing:.03em;text-transform:uppercase;margin-bottom:6px}.card-who{display:inline-flex;align-items:center;gap:8px;font-size:14px;font-weight:600}.card-text{position:relative;margin-top:6px;max-height:174px;overflow:hidden;font-size:15px;color:var(--text);-webkit-mask-image:linear-gradient(to bottom,#000 calc(100% - 2.5em),transparent);mask-image:linear-gradient(to bottom,#000 calc(100% - 2.5em),transparent)}.card-text .pic{max-height:160px}.card-missing,.card-loading{color:var(--muted);font-size:14px;cursor:default}.card-loading{min-height:56px}.card-clear{flex:none;width:36px;height:36px;display:inline-flex;align-items:center;justify-content:center;border-radius:50%;color:var(--muted)}.suggest{position:fixed;left:0;right:0;bottom:calc(var(--keyboard) + env(safe-area-inset-bottom));z-index:20;max-height:40vh;overflow-y:auto;max-width:640px;margin:0 auto;background:var(--bg);border-top:1px solid var(--border);box-shadow:0 -6px 20px #00000014}.suggest-item{display:flex;align-items:center;gap:10px;width:100%;min-height:48px;padding:8px 16px;text-align:left}.suggest-item+.suggest-item{border-top:1px solid var(--border)}.suggest-text{display:flex;flex-direction:column;min-width:0;font-weight:500}.suggest-nip05{color:var(--muted);font-size:13px;font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.done{padding:24px 16px}.done-mark{display:flex;align-items:center;gap:8px;font-size:18px;font-weight:600;color:var(--primary)}.done-mark .icon{width:22px;height:22px}.done-note{margin:16px 0;padding:12px 14px;border:1px solid var(--border);border-radius:14px}.done-actions{display:flex;gap:8px}.btn{min-height:44px;padding:0 18px;border-radius:999px;border:1px solid var(--border);font-weight:500}.avatar{position:relative;display:inline-flex;align-items:center;justify-content:center;flex:none;border-radius:50%;overflow:hidden;background:hsl(var(--hue, 200),35%,55%);color:#fff;font-weight:600}.avatar img{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%;object-fit:cover;opacity:0}.avatar img.loaded{opacity:1}.avatar-followed{box-shadow:0 0 0 2px var(--bg),0 0 0 4px var(--gold)}.avatar-wilted{background:var(--surface)}.avatar-sm{width:24px;height:24px;font-size:11px}.avatar-md{width:36px;height:36px;font-size:15px}.is-loading{position:relative}.is-loading:after{content:"";position:absolute;right:14px;top:50%;width:16px;height:16px;margin-top:-8px;border:2px solid var(--muted);border-top-color:transparent;border-radius:50%;opacity:.5;animation:spin .9s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}
</style>
  </head>
  <body>
    <main id="app" class="app">
      <header class="bar">
        <h1 id="title" class="bar-title">New note</h1>
        <button id="preview" type="button" class="bar-btn" aria-pressed="false">Preview</button>
        <button id="post" type="button" class="post-btn" disabled>Post</button>
      </header>
      <div id="status" class="status" role="status" aria-live="polite" hidden></div>
      <section id="context" class="context" hidden></section>
      <section id="compose" class="compose">
        <div class="writer">
          <span id="me" class="writer-avatar" aria-hidden="true"></span>
          <textarea id="text" class="text" rows="5" placeholder="What's on your mind?" aria-label="Your note" autocomplete="off"></textarea>
        </div>
        <div id="rendered" class="rendered" hidden></div>
        <section id="quote" class="quote-slot" hidden></section>
      </section>
      <section id="done" class="done" hidden></section>
    </main>
    <!-- People matching what is typed after `@`; above the keyboard. -->
    <div id="suggest" class="suggest" role="listbox" aria-label="People" hidden></div>
  </body>
</html>