mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
8 lines
108 KiB
JavaScript
8 lines
108 KiB
JavaScript
/**
|
|
* Minified by jsDelivr using Terser v5.39.0.
|
|
* Original file: /npm/[email protected]/lib/nostr.bundle.js
|
|
*
|
|
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
*/
|
|
"use strict";var NostrTools=(()=>{var t=Object.defineProperty,e=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,o=(e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})},i={};function s(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function a(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function c(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}o(i,{Relay:()=>Cr,SimplePool:()=>Mr,finalizeEvent:()=>qe,fj:()=>xr,generateSecretKey:()=>He,getEventHash:()=>_e,getFilterLimit:()=>vr,getPublicKey:()=>Ce,kinds:()=>je,matchFilter:()=>br,matchFilters:()=>mr,mergeFilters:()=>Er,nip04:()=>$o,nip05:()=>Ri,nip10:()=>Mi,nip11:()=>zi,nip13:()=>Ki,nip17:()=>Gi,nip18:()=>Zs,nip19:()=>jr,nip21:()=>Qs,nip25:()=>na,nip27:()=>ia,nip28:()=>ua,nip30:()=>ga,nip39:()=>va,nip42:()=>Lr,nip44:()=>Yi,nip47:()=>ka,nip54:()=>Ua,nip57:()=>Ta,nip59:()=>Ji,nip98:()=>Ha,parseReferences:()=>Ro,serializeEvent:()=>Ne,sortEvents:()=>de,utils:()=>Se,validateEvent:()=>fe,verifiedSymbol:()=>le,verifyEvent:()=>Me});var u="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,l=t=>t instanceof Uint8Array,h=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),f=(t,e)=>t<<32-e|t>>>e;if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");function d(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}(t)),!l(t))throw new Error("expected Uint8Array, got "+typeof t);return t}var p=class{clone(){return this._cloneInto()}};function g(t){const e=e=>t().update(d(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function y(t=32){if(u&&"function"==typeof u.getRandomValues)return u.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}var w=class extends p{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=h(this.buffer)}update(t){c(this);const{view:e,buffer:n,blockLen:r}=this,o=(t=d(t)).length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s!==r)n.set(t.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(e,0),this.pos=0);else{const e=h(t);for(;r<=o-i;i+=r)this.process(e,i)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){c(this),function(t,e){a(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let t=i;t<r;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=h(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=u/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<l;t++)s.setUint32(4*t,f[t],o)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return t.length=r,t.pos=s,t.finished=o,t.destroyed=i,r%e&&t.buffer.set(n),t}},b=(t,e,n)=>t&e^t&n^e&n,m=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]),v=new Uint32Array(64),x=class extends w{constructor(){super(64,32,8,!1),this.A=0|E[0],this.B=0|E[1],this.C=0|E[2],this.D=0|E[3],this.E=0|E[4],this.F=0|E[5],this.G=0|E[6],this.H=0|E[7]}get(){const{A:t,B:e,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[t,e,n,r,o,i,s,a]}set(t,e,n,r,o,i,s,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)v[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=v[t-15],n=v[t-2],r=f(e,7)^f(e,18)^e>>>3,o=f(n,17)^f(n,19)^n>>>10;v[t]=o+v[t-7]+r+v[t-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let t=0;t<64;t++){const e=u+(f(s,6)^f(s,11)^f(s,25))+((l=s)&a^~l&c)+m[t]+v[t]|0,h=(f(n,2)^f(n,13)^f(n,22))+b(n,r,o)|0;u=c,c=a,a=s,s=i+e|0,i=o,o=r,r=n,n=e+h|0}var l;n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){v.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},A=g((()=>new x)),k={};o(k,{bitGet:()=>F,bitLen:()=>D,bitMask:()=>W,bitSet:()=>K,bytesToHex:()=>T,bytesToNumberBE:()=>N,bytesToNumberLE:()=>_,concatBytes:()=>M,createHmacDrbg:()=>G,ensureBytes:()=>q,equalBytes:()=>j,hexToBytes:()=>$,hexToNumber:()=>R,numberToBytesBE:()=>P,numberToBytesLE:()=>H,numberToHexUnpadded:()=>O,numberToVarBytesBE:()=>C,utf8ToBytes:()=>z,validateObject:()=>Y});var S=BigInt(0),B=BigInt(1),U=BigInt(2),I=t=>t instanceof Uint8Array,L=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function T(t){if(!I(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=L[t[n]];return e}function O(t){const e=t.toString(16);return 1&e.length?`0${e}`:e}function R(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);return BigInt(""===t?"0":`0x${t}`)}function $(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let e=0;e<n.length;e++){const r=2*e,o=t.slice(r,r+2),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[e]=i}return n}function N(t){return R(T(t))}function _(t){if(!I(t))throw new Error("Uint8Array expected");return R(T(Uint8Array.from(t).reverse()))}function P(t,e){return $(t.toString(16).padStart(2*e,"0"))}function H(t,e){return P(t,e).reverse()}function C(t){return $(O(t))}function q(t,e,n){let r;if("string"==typeof e)try{r=$(e)}catch(n){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${n}`)}else{if(!I(e))throw new Error(`${t} must be hex string or Uint8Array`);r=Uint8Array.from(e)}const o=r.length;if("number"==typeof n&&o!==n)throw new Error(`${t} expected ${n} bytes, got ${o}`);return r}function M(...t){const e=new Uint8Array(t.reduce(((t,e)=>t+e.length),0));let n=0;return t.forEach((t=>{if(!I(t))throw new Error("Uint8Array expected");e.set(t,n),n+=t.length})),e}function j(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function z(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}function D(t){let e;for(e=0;t>S;t>>=B,e+=1);return e}function F(t,e){return t>>BigInt(e)&B}var K=(t,e,n)=>t|(n?B:S)<<BigInt(e),W=t=>(U<<BigInt(t-1))-B,V=t=>new Uint8Array(t),Z=t=>Uint8Array.from(t);function G(t,e,n){if("number"!=typeof t||t<2)throw new Error("hashLen must be a number");if("number"!=typeof e||e<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=V(t),o=V(t),i=0;const s=()=>{r.fill(1),o.fill(0),i=0},a=(...t)=>n(o,r,...t),c=(t=V())=>{o=a(Z([0]),t),r=a(),0!==t.length&&(o=a(Z([1]),t),r=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let t=0;const n=[];for(;t<e;){r=a();const e=r.slice();n.push(e),t+=r.length}return M(...n)};return(t,e)=>{let n;for(s(),c(t);!(n=e(u()));)c();return s(),n}}var J={bigint:t=>"bigint"==typeof t,function:t=>"function"==typeof t,boolean:t=>"boolean"==typeof t,string:t=>"string"==typeof t,stringOrUint8Array:t=>"string"==typeof t||t instanceof Uint8Array,isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>"function"==typeof t&&Number.isSafeInteger(t.outputLen)};function Y(t,e,n={}){const r=(e,n,r)=>{const o=J[n];if("function"!=typeof o)throw new Error(`Invalid validator "${n}", expected function`);const i=t[e];if(!(r&&void 0===i||o(i,t)))throw new Error(`Invalid param ${String(e)}=${i} (${typeof i}), expected ${n}`)};for(const[t,n]of Object.entries(e))r(t,n,!1);for(const[t,e]of Object.entries(n))r(t,e,!0);return t}var Q=BigInt(0),X=BigInt(1),tt=BigInt(2),et=BigInt(3),nt=BigInt(4),rt=BigInt(5),ot=BigInt(8);BigInt(9),BigInt(16);function it(t,e){const n=t%e;return n>=Q?n:e+n}function st(t,e,n){if(n<=Q||e<Q)throw new Error("Expected power/modulo > 0");if(n===X)return Q;let r=X;for(;e>Q;)e&X&&(r=r*t%n),t=t*t%n,e>>=X;return r}function at(t,e,n){let r=t;for(;e-- >Q;)r*=r,r%=n;return r}function ct(t,e){if(t===Q||e<=Q)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=it(t,e),r=e,o=Q,i=X,s=X,a=Q;for(;n!==Q;){const t=r/n,e=r%n,c=o-s*t,u=i-a*t;r=n,n=e,o=s,i=a,s=c,a=u}if(r!==X)throw new Error("invert: does not exist");return it(o,e)}function ut(t){if(t%nt===et){const e=(t+X)/nt;return function(t,n){const r=t.pow(n,e);if(!t.eql(t.sqr(r),n))throw new Error("Cannot find square root");return r}}if(t%ot===rt){const e=(t-rt)/ot;return function(t,n){const r=t.mul(n,tt),o=t.pow(r,e),i=t.mul(n,o),s=t.mul(t.mul(i,tt),o),a=t.mul(i,t.sub(s,t.ONE));if(!t.eql(t.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(t){const e=(t-X)/tt;let n,r,o;for(n=t-X,r=0;n%tt===Q;n/=tt,r++);for(o=tt;o<t&&st(o,e,t)!==t-X;o++);if(1===r){const e=(t+X)/nt;return function(t,n){const r=t.pow(n,e);if(!t.eql(t.sqr(r),n))throw new Error("Cannot find square root");return r}}const i=(n+X)/tt;return function(t,s){if(t.pow(s,e)===t.neg(t.ONE))throw new Error("Cannot find square root");let a=r,c=t.pow(t.mul(t.ONE,o),n),u=t.pow(s,i),l=t.pow(s,n);for(;!t.eql(l,t.ONE);){if(t.eql(l,t.ZERO))return t.ZERO;let e=1;for(let n=t.sqr(l);e<a&&!t.eql(n,t.ONE);e++)n=t.sqr(n);const n=t.pow(c,X<<BigInt(a-e-1));c=t.sqr(n),u=t.mul(u,n),l=t.mul(l,c),a=e}return u}}(t)}var lt=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ht(t,e){const n=void 0!==e?e:t.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function ft(t){if("bigint"!=typeof t)throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function dt(t){const e=ft(t);return e+Math.ceil(e/2)}var pt=BigInt(0),gt=BigInt(1);function yt(t){return Y(t.Fp,lt.reduce(((t,e)=>(t[e]="function",t)),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),Y(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ht(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var{bytesToNumberBE:wt,hexToBytes:bt}=k,mt={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(t){const{Err:e}=mt;if(t.length<2||2!==t[0])throw new e("Invalid signature integer tag");const n=t[1],r=t.subarray(2,n+2);if(!n||r.length!==n)throw new e("Invalid signature integer: wrong length");if(128&r[0])throw new e("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new e("Invalid signature integer: unnecessary leading zero");return{d:wt(r),l:t.subarray(n+2)}},toSig(t){const{Err:e}=mt,n="string"==typeof t?bt(t):t;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new e("Invalid signature tag");if(n[1]!==r-2)throw new e("Invalid signature: incorrect length");const{d:o,l:i}=mt._parseInt(n.subarray(2)),{d:s,l:a}=mt._parseInt(i);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:o,s:s}},hexFromSig(t){const e=t=>8&Number.parseInt(t[0],16)?"00"+t:t,n=t=>{const e=t.toString(16);return 1&e.length?`0${e}`:e},r=e(n(t.s)),o=e(n(t.r)),i=r.length/2,s=o.length/2,a=n(i),c=n(s);return`30${n(s+i+4)}02${c}${o}02${a}${r}`}},Et=BigInt(0),vt=BigInt(1),xt=(BigInt(2),BigInt(3));BigInt(4);function At(t){const e=function(t){const e=yt(t);Y(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:o}=e;if(n){if(!r.eql(o,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}(t),{Fp:n}=e,r=e.toBytes||((t,e,r)=>{const o=e.toAffine();return M(Uint8Array.from([4]),n.toBytes(o.x),n.toBytes(o.y))}),o=e.fromBytes||(t=>{const e=t.subarray(1);return{x:n.fromBytes(e.subarray(0,n.BYTES)),y:n.fromBytes(e.subarray(n.BYTES,2*n.BYTES))}});function i(t){const{a:r,b:o}=e,i=n.sqr(t),s=n.mul(i,t);return n.add(n.add(s,n.mul(t,r)),o)}if(!n.eql(n.sqr(e.Gy),i(e.Gx)))throw new Error("bad generator point: equation left != right");function s(t){return"bigint"==typeof t&&Et<t&&t<e.n}function a(t){if(!s(t))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(t){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:o,n:i}=e;if(n&&"bigint"!=typeof t){if(t instanceof Uint8Array&&(t=T(t)),"string"!=typeof t||!n.includes(t.length))throw new Error("Invalid key");t=t.padStart(2*r,"0")}let s;try{s="bigint"==typeof t?t:N(q("private key",t,r))}catch(e){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof t}`)}return o&&(s=it(s,i)),a(s),s}const u=new Map;function l(t){if(!(t instanceof h))throw new Error("ProjectivePoint expected")}class h{constructor(t,e,r){if(this.px=t,this.py=e,this.pz=r,null==t||!n.isValid(t))throw new Error("x required");if(null==e||!n.isValid(e))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(t){const{x:e,y:r}=t||{};if(!t||!n.isValid(e)||!n.isValid(r))throw new Error("invalid affine point");if(t instanceof h)throw new Error("projective point not allowed");const o=t=>n.eql(t,n.ZERO);return o(e)&&o(r)?h.ZERO:new h(e,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(t){const e=n.invertBatch(t.map((t=>t.pz)));return t.map(((t,n)=>t.toAffine(e[n]))).map(h.fromAffine)}static fromHex(t){const e=h.fromAffine(o(q("pointHex",t)));return e.assertValidity(),e}static fromPrivateKey(t){return h.BASE.multiply(c(t))}_setWindowSize(t){this._WINDOW_SIZE=t,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:t,y:r}=this.toAffine();if(!n.isValid(t)||!n.isValid(r))throw new Error("bad point: x or y not FE");const o=n.sqr(r),s=i(t);if(!n.eql(o,s))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:t}=this.toAffine();if(n.isOdd)return!n.isOdd(t);throw new Error("Field doesn't support isOdd")}equals(t){l(t);const{px:e,py:r,pz:o}=this,{px:i,py:s,pz:a}=t,c=n.eql(n.mul(e,a),n.mul(i,o)),u=n.eql(n.mul(r,a),n.mul(s,o));return c&&u}negate(){return new h(this.px,n.neg(this.py),this.pz)}double(){const{a:t,b:r}=e,o=n.mul(r,xt),{px:i,py:s,pz:a}=this;let c=n.ZERO,u=n.ZERO,l=n.ZERO,f=n.mul(i,i),d=n.mul(s,s),p=n.mul(a,a),g=n.mul(i,s);return g=n.add(g,g),l=n.mul(i,a),l=n.add(l,l),c=n.mul(t,l),u=n.mul(o,p),u=n.add(c,u),c=n.sub(d,u),u=n.add(d,u),u=n.mul(c,u),c=n.mul(g,c),l=n.mul(o,l),p=n.mul(t,p),g=n.sub(f,p),g=n.mul(t,g),g=n.add(g,l),l=n.add(f,f),f=n.add(l,f),f=n.add(f,p),f=n.mul(f,g),u=n.add(u,f),p=n.mul(s,a),p=n.add(p,p),f=n.mul(p,g),c=n.sub(c,f),l=n.mul(p,d),l=n.add(l,l),l=n.add(l,l),new h(c,u,l)}add(t){l(t);const{px:r,py:o,pz:i}=this,{px:s,py:a,pz:c}=t;let u=n.ZERO,f=n.ZERO,d=n.ZERO;const p=e.a,g=n.mul(e.b,xt);let y=n.mul(r,s),w=n.mul(o,a),b=n.mul(i,c),m=n.add(r,o),E=n.add(s,a);m=n.mul(m,E),E=n.add(y,w),m=n.sub(m,E),E=n.add(r,i);let v=n.add(s,c);return E=n.mul(E,v),v=n.add(y,b),E=n.sub(E,v),v=n.add(o,i),u=n.add(a,c),v=n.mul(v,u),u=n.add(w,b),v=n.sub(v,u),d=n.mul(p,E),u=n.mul(g,b),d=n.add(u,d),u=n.sub(w,d),d=n.add(w,d),f=n.mul(u,d),w=n.add(y,y),w=n.add(w,y),b=n.mul(p,b),E=n.mul(g,E),w=n.add(w,b),b=n.sub(y,b),b=n.mul(p,b),E=n.add(E,b),y=n.mul(w,E),f=n.add(f,y),y=n.mul(v,E),u=n.mul(m,u),u=n.sub(u,y),y=n.mul(m,w),d=n.mul(v,d),d=n.add(d,y),new h(u,f,d)}subtract(t){return this.add(t.negate())}is0(){return this.equals(h.ZERO)}wNAF(t){return d.wNAFCached(this,u,t,(t=>{const e=n.invertBatch(t.map((t=>t.pz)));return t.map(((t,n)=>t.toAffine(e[n]))).map(h.fromAffine)}))}multiplyUnsafe(t){const r=h.ZERO;if(t===Et)return r;if(a(t),t===vt)return this;const{endo:o}=e;if(!o)return d.unsafeLadder(this,t);let{k1neg:i,k1:s,k2neg:c,k2:u}=o.splitScalar(t),l=r,f=r,p=this;for(;s>Et||u>Et;)s&vt&&(l=l.add(p)),u&vt&&(f=f.add(p)),p=p.double(),s>>=vt,u>>=vt;return i&&(l=l.negate()),c&&(f=f.negate()),f=new h(n.mul(f.px,o.beta),f.py,f.pz),l.add(f)}multiply(t){a(t);let r,o,i=t;const{endo:s}=e;if(s){const{k1neg:t,k1:e,k2neg:a,k2:c}=s.splitScalar(i);let{p:u,f:l}=this.wNAF(e),{p:f,f:p}=this.wNAF(c);u=d.constTimeNegate(t,u),f=d.constTimeNegate(a,f),f=new h(n.mul(f.px,s.beta),f.py,f.pz),r=u.add(f),o=l.add(p)}else{const{p:t,f:e}=this.wNAF(i);r=t,o=e}return h.normalizeZ([r,o])[0]}multiplyAndAddUnsafe(t,e,n){const r=h.BASE,o=(t,e)=>e!==Et&&e!==vt&&t.equals(r)?t.multiply(e):t.multiplyUnsafe(e),i=o(this,e).add(o(t,n));return i.is0()?void 0:i}toAffine(t){const{px:e,py:r,pz:o}=this,i=this.is0();null==t&&(t=i?n.ONE:n.inv(o));const s=n.mul(e,t),a=n.mul(r,t),c=n.mul(o,t);if(i)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:s,y:a}}isTorsionFree(){const{h:t,isTorsionFree:n}=e;if(t===vt)return!0;if(n)return n(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:t,clearCofactor:n}=e;return t===vt?this:n?n(h,this):this.multiplyUnsafe(e.h)}toRawBytes(t=!0){return this.assertValidity(),r(h,this,t)}toHex(t=!0){return T(this.toRawBytes(t))}}h.BASE=new h(e.Gx,e.Gy,n.ONE),h.ZERO=new h(n.ZERO,n.ONE,n.ZERO);const f=e.nBitLength,d=function(t,e){const n=(t,e)=>{const n=e.negate();return t?n:e},r=t=>({windows:Math.ceil(e/t)+1,windowSize:2**(t-1)});return{constTimeNegate:n,unsafeLadder(e,n){let r=t.ZERO,o=e;for(;n>pt;)n>&&(r=r.add(o)),o=o.double(),n>>=gt;return r},precomputeWindow(t,e){const{windows:n,windowSize:o}=r(e),i=[];let s=t,a=s;for(let t=0;t<n;t++){a=s,i.push(a);for(let t=1;t<o;t++)a=a.add(s),i.push(a);s=a.double()}return i},wNAF(e,o,i){const{windows:s,windowSize:a}=r(e);let c=t.ZERO,u=t.BASE;const l=BigInt(2**e-1),h=2**e,f=BigInt(e);for(let t=0;t<s;t++){const e=t*a;let r=Number(i&l);i>>=f,r>a&&(r-=h,i+=gt);const s=e,d=e+Math.abs(r)-1,p=t%2!=0,g=r<0;0===r?u=u.add(n(p,o[s])):c=c.add(n(g,o[d]))}return{p:c,f:u}},wNAFCached(t,e,n,r){const o=t._WINDOW_SIZE||1;let i=e.get(t);return i||(i=this.precomputeWindow(t,o),1!==o&&e.set(t,r(i))),this.wNAF(o,i,n)}}}(h,e.endo?Math.ceil(f/2):f);return{CURVE:e,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function kt(t){const e=function(t){const e=yt(t);return Y(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}(t),{Fp:n,n:r}=e,o=n.BYTES+1,i=2*n.BYTES+1;function s(t){return it(t,r)}function a(t){return ct(t,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:h}=At({...e,toBytes(t,e,r){const o=e.toAffine(),i=n.toBytes(o.x),s=M;return r?s(Uint8Array.from([e.hasEvenY()?2:3]),i):s(Uint8Array.from([4]),i,n.toBytes(o.y))},fromBytes(t){const e=t.length,r=t[0],s=t.subarray(1);if(e!==o||2!==r&&3!==r){if(e===i&&4===r){return{x:n.fromBytes(s.subarray(0,n.BYTES)),y:n.fromBytes(s.subarray(n.BYTES,2*n.BYTES))}}throw new Error(`Point of length ${e} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}{const t=N(s);if(!(Et<(a=t)&&a<n.ORDER))throw new Error("Point is not on curve");const e=l(t);let o=n.sqrt(e);return!(1&~r)!==((o&vt)===vt)&&(o=n.neg(o)),{x:t,y:o}}var a}}),f=t=>T(P(t,e.nByteLength));function d(t){return t>r>>vt}const p=(t,e,n)=>N(t.slice(e,n));class g{constructor(t,e,n){this.r=t,this.s=e,this.recovery=n,this.assertValidity()}static fromCompact(t){const n=e.nByteLength;return t=q("compactSignature",t,2*n),new g(p(t,0,n),p(t,n,2*n))}static fromDER(t){const{r:e,s:n}=mt.toSig(q("DER",t));return new g(e,n)}assertValidity(){if(!h(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!h(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(t){return new g(this.r,this.s,t)}recoverPublicKey(t){const{r:r,s:o,recovery:i}=this,u=m(q("msgHash",t));if(null==i||![0,1,2,3].includes(i))throw new Error("recovery id invalid");const l=2===i||3===i?r+e.n:r;if(l>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const h=1&i?"03":"02",d=c.fromHex(h+f(l)),p=a(l),g=s(-u*p),y=s(o*p),w=c.BASE.multiplyAndAddUnsafe(d,g,y);if(!w)throw new Error("point at infinify");return w.assertValidity(),w}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return $(this.toDERHex())}toDERHex(){return mt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return $(this.toCompactHex())}toCompactHex(){return f(this.r)+f(this.s)}}const y={isValidPrivateKey(t){try{return u(t),!0}catch(t){return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const t=dt(e.n);return function(t,e,n=!1){const r=t.length,o=ft(e),i=dt(e);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const s=it(n?N(t):_(t),e-X)+X;return n?H(s,o):P(s,o)}(e.randomBytes(t),e.n)},precompute:(t=8,e=c.BASE)=>(e._setWindowSize(t),e.multiply(BigInt(3)),e)};function w(t){const e=t instanceof Uint8Array,n="string"==typeof t,r=(e||n)&&t.length;return e?r===o||r===i:n?r===2*o||r===2*i:t instanceof c}const b=e.bits2int||function(t){const n=N(t),r=8*t.length-e.nBitLength;return r>0?n>>BigInt(r):n},m=e.bits2int_modN||function(t){return s(b(t))},E=W(e.nBitLength);function v(t){if("bigint"!=typeof t)throw new Error("bigint expected");if(!(Et<=t&&t<E))throw new Error(`bigint expected < 2^${e.nBitLength}`);return P(t,e.nByteLength)}function x(t,r,o=A){if(["recovered","canonical"].some((t=>t in o)))throw new Error("sign() legacy options not supported");const{hash:i,randomBytes:l}=e;let{lowS:f,prehash:p,extraEntropy:y}=o;null==f&&(f=!0),t=q("msgHash",t),p&&(t=q("prehashed msgHash",i(t)));const w=m(t),E=u(r),x=[v(E),v(w)];if(null!=y){const t=!0===y?l(n.BYTES):y;x.push(q("extraEntropy",t))}const k=M(...x),S=w;return{seed:k,k2sig:function(t){const e=b(t);if(!h(e))return;const n=a(e),r=c.BASE.multiply(e).toAffine(),o=s(r.x);if(o===Et)return;const i=s(n*s(S+o*E));if(i===Et)return;let u=(r.x===o?0:2)|Number(r.y&vt),l=i;return f&&d(i)&&(l=function(t){return d(t)?s(-t):t}(i),u^=1),new g(o,l,u)}}}const A={lowS:e.lowS,prehash:!1},k={lowS:e.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:e,getPublicKey:function(t,e=!0){return c.fromPrivateKey(t).toRawBytes(e)},getSharedSecret:function(t,e,n=!0){if(w(t))throw new Error("first arg must be private key");if(!w(e))throw new Error("second arg must be public key");return c.fromHex(e).multiply(u(t)).toRawBytes(n)},sign:function(t,n,r=A){const{seed:o,k2sig:i}=x(t,n,r),s=e;return G(s.hash.outputLen,s.nByteLength,s.hmac)(o,i)},verify:function(t,n,r,o=k){const i=t;if(n=q("msgHash",n),r=q("publicKey",r),"strict"in o)throw new Error("options.strict was renamed to lowS");const{lowS:u,prehash:l}=o;let h,f;try{if("string"==typeof i||i instanceof Uint8Array)try{h=g.fromDER(i)}catch(t){if(!(t instanceof mt.Err))throw t;h=g.fromCompact(i)}else{if("object"!=typeof i||"bigint"!=typeof i.r||"bigint"!=typeof i.s)throw new Error("PARSE");{const{r:t,s:e}=i;h=new g(t,e)}}f=c.fromHex(r)}catch(t){if("PARSE"===t.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(u&&h.hasHighS())return!1;l&&(n=e.hash(n));const{r:d,s:p}=h,y=m(n),w=a(p),b=s(y*w),E=s(d*w),v=c.BASE.multiplyAndAddUnsafe(f,b,E)?.toAffine();return!!v&&s(v.x)===d},ProjectivePoint:c,Signature:g,utils:y}}var St=class extends p{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,function(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");s(t.outputLen),s(t.blockLen)}(t);const n=d(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?t.create().update(n).digest():n);for(let t=0;t<o.length;t++)o[t]^=54;this.iHash.update(o),this.oHash=t.create();for(let t=0;t<o.length;t++)o[t]^=106;this.oHash.update(o),o.fill(0)}update(t){return c(this),this.iHash.update(t),this}digestInto(t){c(this),a(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:e,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return t.finished=r,t.destroyed=o,t.blockLen=i,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Bt=(t,e,n)=>new St(t,e).update(n).digest();function Ut(t){return{hash:t,hmac:(e,...n)=>Bt(t,e,function(...t){const e=new Uint8Array(t.reduce(((t,e)=>t+e.length),0));let n=0;return t.forEach((t=>{if(!l(t))throw new Error("Uint8Array expected");e.set(t,n),n+=t.length})),e}(...n)),randomBytes:y}}Bt.create=(t,e)=>new St(t,e);var It=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Lt=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Tt=BigInt(1),Ot=BigInt(2),Rt=(t,e)=>(t+e/Ot)/e;function $t(t){const e=It,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,l=u*u*t%e,h=at(l,n,e)*l%e,f=at(h,n,e)*l%e,d=at(f,Ot,e)*u%e,p=at(d,o,e)*d%e,g=at(p,i,e)*p%e,y=at(g,a,e)*g%e,w=at(y,c,e)*y%e,b=at(w,a,e)*g%e,m=at(b,n,e)*l%e,E=at(m,s,e)*p%e,v=at(E,r,e)*u%e,x=at(v,Ot,e);if(!Nt.eql(Nt.sqr(x),t))throw new Error("Cannot find square root");return x}var Nt=function(t,e,n=!1,r={}){if(t<=Q)throw new Error(`Expected Field ORDER > 0, got ${t}`);const{nBitLength:o,nByteLength:i}=ht(t,e);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=ut(t),a=Object.freeze({ORDER:t,BITS:o,BYTES:i,MASK:W(o),ZERO:Q,ONE:X,create:e=>it(e,t),isValid:e=>{if("bigint"!=typeof e)throw new Error("Invalid field element: expected bigint, got "+typeof e);return Q<=e&&e<t},is0:t=>t===Q,isOdd:t=>(t&X)===X,neg:e=>it(-e,t),eql:(t,e)=>t===e,sqr:e=>it(e*e,t),add:(e,n)=>it(e+n,t),sub:(e,n)=>it(e-n,t),mul:(e,n)=>it(e*n,t),pow:(t,e)=>function(t,e,n){if(n<Q)throw new Error("Expected power > 0");if(n===Q)return t.ONE;if(n===X)return e;let r=t.ONE,o=e;for(;n>Q;)n&X&&(r=t.mul(r,o)),o=t.sqr(o),n>>=X;return r}(a,t,e),div:(e,n)=>it(e*ct(n,t),t),sqrN:t=>t*t,addN:(t,e)=>t+e,subN:(t,e)=>t-e,mulN:(t,e)=>t*e,inv:e=>ct(e,t),sqrt:r.sqrt||(t=>s(a,t)),invertBatch:t=>function(t,e){const n=new Array(e.length),r=e.reduce(((e,r,o)=>t.is0(r)?e:(n[o]=e,t.mul(e,r))),t.ONE),o=t.inv(r);return e.reduceRight(((e,r,o)=>t.is0(r)?e:(n[o]=t.mul(e,n[o]),t.mul(e,r))),o),n}(a,t),cmov:(t,e,n)=>n?e:t,toBytes:t=>n?H(t,i):P(t,i),fromBytes:t=>{if(t.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${t.length}`);return n?_(t):N(t)}});return Object.freeze(a)}(It,void 0,void 0,{sqrt:$t}),_t=function(t,e){const n=e=>kt({...t,...Ut(e)});return Object.freeze({...n(e),create:n})}({a:BigInt(0),b:BigInt(7),Fp:Nt,n:Lt,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=Lt,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Tt*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),a=Rt(i*t,e),c=Rt(-r*t,e);let u=it(t-a*n-c*o,e),l=it(-a*r-c*i,e);const h=u>s,f=l>s;if(h&&(u=e-u),f&&(l=e-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:h,k1:u,k2neg:f,k2:l}}}},A),Pt=BigInt(0),Ht=t=>"bigint"==typeof t&&Pt<t&&t<It,Ct={};function qt(t,...e){let n=Ct[t];if(void 0===n){const e=A(Uint8Array.from(t,(t=>t.charCodeAt(0))));n=M(e,e),Ct[t]=n}return A(M(n,...e))}var Mt=t=>t.toRawBytes(!0).slice(1),jt=t=>P(t,32),zt=t=>it(t,It),Dt=t=>it(t,Lt),Ft=_t.ProjectivePoint;function Kt(t){let e=_t.utils.normPrivateKeyToScalar(t),n=Ft.fromPrivateKey(e);return{scalar:n.hasEvenY()?e:Dt(-e),bytes:Mt(n)}}function Wt(t){if(!Ht(t))throw new Error("bad x: need 0 < x < p");const e=zt(t*t);let n=$t(zt(e*t+BigInt(7)));n%Ot!==Pt&&(n=zt(-n));const r=new Ft(t,n,Tt);return r.assertValidity(),r}function Vt(...t){return Dt(N(qt("BIP0340/challenge",...t)))}function Zt(t){return Kt(t).bytes}function Gt(t,e,n=y(32)){const r=q("message",t),{bytes:o,scalar:i}=Kt(e),s=q("auxRand",n,32),a=jt(i^N(qt("BIP0340/aux",s))),c=qt("BIP0340/nonce",a,o,r),u=Dt(N(c));if(u===Pt)throw new Error("sign failed: k is zero");const{bytes:l,scalar:h}=Kt(u),f=Vt(l,o,r),d=new Uint8Array(64);if(d.set(l,0),d.set(jt(Dt(h+f*i)),32),!Jt(d,r,o))throw new Error("sign: Invalid signature produced");return d}function Jt(t,e,n){const r=q("signature",t,64),o=q("message",e),i=q("publicKey",n,32);try{const t=Wt(N(i)),e=N(r.subarray(0,32));if(!Ht(e))return!1;const n=N(r.subarray(32,64));if(!("bigint"==typeof(u=n)&&Pt<u&&u<Lt))return!1;const l=Vt(jt(e),Mt(t),o),h=(s=t,a=n,c=Dt(-l),Ft.BASE.multiplyAndAddUnsafe(s,a,c));return!(!h||!h.hasEvenY()||h.toAffine().x!==e)}catch(t){return!1}var s,a,c,u}var Yt=(()=>({getPublicKey:Zt,sign:Gt,verify:Jt,utils:{randomPrivateKey:_t.utils.randomPrivateKey,lift_x:Wt,pointToBytes:Mt,numberToBytesBE:P,bytesToNumberBE:N,taggedHash:qt,mod:it}}))(),Qt="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,Xt=t=>t instanceof Uint8Array,te=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),ee=(t,e)=>t<<32-e|t>>>e;if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");var ne=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function re(t){if(!Xt(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=ne[t[n]];return e}function oe(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(e/2);for(let e=0;e<n.length;e++){const r=2*e,o=t.slice(r,r+2),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[e]=i}return n}function ie(t){if("string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}(t)),!Xt(t))throw new Error("expected Uint8Array, got "+typeof t);return t}function se(...t){const e=new Uint8Array(t.reduce(((t,e)=>t+e.length),0));let n=0;return t.forEach((t=>{if(!Xt(t))throw new Error("Uint8Array expected");e.set(t,n),n+=t.length})),e}var ae=class{clone(){return this._cloneInto()}};function ce(t){const e=e=>t().update(ie(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function ue(t=32){if(Qt&&"function"==typeof Qt.getRandomValues)return Qt.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}var le=Symbol("verified"),he=t=>t instanceof Object;function fe(t){if(!he(t))return!1;if("number"!=typeof t.kind)return!1;if("string"!=typeof t.content)return!1;if("number"!=typeof t.created_at)return!1;if("string"!=typeof t.pubkey)return!1;if(!t.pubkey.match(/^[a-f0-9]{64}$/))return!1;if(!Array.isArray(t.tags))return!1;for(let e=0;e<t.tags.length;e++){let n=t.tags[e];if(!Array.isArray(n))return!1;for(let t=0;t<n.length;t++)if("string"!=typeof n[t])return!1}return!0}function de(t){return t.sort(((t,e)=>t.created_at!==e.created_at?e.created_at-t.created_at:t.id.localeCompare(e.id)))}function pe(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function ge(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}var ye={number:pe,bool:function(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)},bytes:ge,hash:function(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");pe(t.outputLen),pe(t.blockLen)},exists:function(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")},output:function(t,e){ge(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}};var we=class extends ae{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=te(this.buffer)}update(t){ye.exists(this);const{view:e,buffer:n,blockLen:r}=this,o=(t=ie(t)).length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s!==r)n.set(t.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(e,0),this.pos=0);else{const e=te(t);for(;r<=o-i;i+=r)this.process(e,i)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){ye.exists(this),ye.output(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let t=i;t<r;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=te(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<c;t++)s.setUint32(4*t,u[t],o)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return t.length=r,t.pos=s,t.finished=o,t.destroyed=i,r%e&&t.buffer.set(n),t}},be=(t,e,n)=>t&e^t&n^e&n,me=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]),Ee=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ve=new Uint32Array(64),xe=class extends we{constructor(){super(64,32,8,!1),this.A=0|Ee[0],this.B=0|Ee[1],this.C=0|Ee[2],this.D=0|Ee[3],this.E=0|Ee[4],this.F=0|Ee[5],this.G=0|Ee[6],this.H=0|Ee[7]}get(){const{A:t,B:e,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[t,e,n,r,o,i,s,a]}set(t,e,n,r,o,i,s,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)ve[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=ve[t-15],n=ve[t-2],r=ee(e,7)^ee(e,18)^e>>>3,o=ee(n,17)^ee(n,19)^n>>>10;ve[t]=o+ve[t-7]+r+ve[t-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let t=0;t<64;t++){const e=u+(ee(s,6)^ee(s,11)^ee(s,25))+((l=s)&a^~l&c)+me[t]+ve[t]|0,h=(ee(n,2)^ee(n,13)^ee(n,22))+be(n,r,o)|0;u=c,c=a,a=s,s=i+e|0,i=o,o=r,r=n,n=e+h|0}var l;n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){ve.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Ae=class extends xe{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}},ke=ce((()=>new xe)),Se=(ce((()=>new Ae)),{});o(Se,{Queue:()=>$e,QueueNode:()=>Re,binarySearch:()=>Oe,bytesToHex:()=>re,hexToBytes:()=>oe,insertEventIntoAscendingList:()=>Te,insertEventIntoDescendingList:()=>Le,normalizeURL:()=>Ie,utf8Decoder:()=>Be,utf8Encoder:()=>Ue});var Be=new TextDecoder("utf-8"),Ue=new TextEncoder;function Ie(t){try{-1===t.indexOf("://")&&(t="wss://"+t);let e=new URL(t);return e.pathname=e.pathname.replace(/\/+/g,"/"),e.pathname.endsWith("/")&&(e.pathname=e.pathname.slice(0,-1)),("80"===e.port&&"ws:"===e.protocol||"443"===e.port&&"wss:"===e.protocol)&&(e.port=""),e.searchParams.sort(),e.hash="",e.toString()}catch(e){throw new Error(`Invalid URL: ${t}`)}}function Le(t,e){const[n,r]=Oe(t,(t=>e.id===t.id?0:e.created_at===t.created_at?-1:t.created_at-e.created_at));return r||t.splice(n,0,e),t}function Te(t,e){const[n,r]=Oe(t,(t=>e.id===t.id?0:e.created_at===t.created_at?-1:e.created_at-t.created_at));return r||t.splice(n,0,e),t}function Oe(t,e){let n=0,r=t.length-1;for(;n<=r;){const o=Math.floor((n+r)/2),i=e(t[o]);if(0===i)return[o,!0];i<0?r=o-1:n=o+1}return[n,!1]}var Re=class{value;next=null;prev=null;constructor(t){this.value=t}},$e=class{first;last;constructor(){this.first=null,this.last=null}enqueue(t){const e=new Re(t);return this.last?this.last===this.first?(this.last=e,this.last.prev=this.first,this.first.next=e):(e.prev=this.last,this.last.next=e,this.last=e):(this.first=e,this.last=e),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const t=this.first;return this.first=t.next,this.first&&(this.first.prev=null),t.value}};function Ne(t){if(!fe(t))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}function _e(t){return re(ke(Ue.encode(Ne(t))))}var Pe=new class{generateSecretKey(){return Yt.utils.randomPrivateKey()}getPublicKey(t){return re(Yt.getPublicKey(t))}finalizeEvent(t,e){const n=t;return n.pubkey=re(Yt.getPublicKey(e)),n.id=_e(n),n.sig=re(Yt.sign(_e(n),e)),n[le]=!0,n}verifyEvent(t){if("boolean"==typeof t[le])return t[le];const e=_e(t);if(e!==t.id)return t[le]=!1,!1;try{const n=Yt.verify(t.sig,e,t.pubkey);return t[le]=n,n}catch(e){return t[le]=!1,!1}}},He=Pe.generateSecretKey,Ce=Pe.getPublicKey,qe=Pe.finalizeEvent,Me=Pe.verifyEvent,je={};function ze(t){return 1e3<=t&&t<1e4||[1,2,4,5,6,7,8,16,40,41,42,43,44].includes(t)}function De(t){return[0,3].includes(t)||1e4<=t&&t<2e4}function Fe(t){return 2e4<=t&&t<3e4}function Ke(t){return 3e4<=t&&t<4e4}function We(t){return ze(t)?"regular":De(t)?"replaceable":Fe(t)?"ephemeral":Ke(t)?"parameterized":"unknown"}function Ve(t,e){const n=e instanceof Array?e:[e];return fe(t)&&n.includes(t.kind)||!1}o(je,{Application:()=>sr,BadgeAward:()=>nn,BadgeDefinition:()=>Xn,BlockedRelaysList:()=>Nn,BookmarkList:()=>On,Bookmarksets:()=>Jn,Calendar:()=>dr,CalendarEventRSVP:()=>pr,ChannelCreation:()=>an,ChannelHideMessage:()=>ln,ChannelMessage:()=>un,ChannelMetadata:()=>cn,ChannelMuteUser:()=>hn,ClassifiedListing:()=>ur,ClientAuth:()=>zn,CommunitiesList:()=>Rn,CommunityDefinition:()=>wr,CommunityPostApproval:()=>En,Contacts:()=>Ye,CreateOrUpdateProduct:()=>nr,CreateOrUpdateStall:()=>er,Curationsets:()=>Yn,Date:()=>hr,DirectMessageRelaysList:()=>Cn,DraftClassifiedListing:()=>lr,DraftLong:()=>or,Emojisets:()=>ir,EncryptedDirectMessage:()=>Qe,EventDeletion:()=>Xe,FileMetadata:()=>pn,FileServerPreference:()=>qn,Followsets:()=>Vn,GenericRepost:()=>sn,Genericlists:()=>Zn,GiftWrap:()=>dn,HTTPAuth:()=>Wn,Handlerinformation:()=>yr,Handlerrecommendation:()=>gr,Highlights:()=>Un,InterestsList:()=>Pn,Interestsets:()=>tr,JobFeedback:()=>An,JobRequest:()=>vn,JobResult:()=>xn,Label:()=>mn,LightningPubRPC:()=>jn,LiveChatMessage:()=>gn,LiveEvent:()=>ar,LongFormArticle:()=>rr,Metadata:()=>Ze,Mutelist:()=>In,NWCWalletInfo:()=>Mn,NWCWalletRequest:()=>Dn,NWCWalletResponse:()=>Fn,NostrConnect:()=>Kn,OpenTimestamps:()=>fn,Pinlist:()=>Ln,PrivateDirectMessage:()=>on,ProblemTracker:()=>yn,ProfileBadges:()=>Qn,PublicChatsList:()=>$n,Reaction:()=>en,RecommendRelay:()=>Je,RelayList:()=>Tn,Relaysets:()=>Gn,Report:()=>wn,Reporting:()=>bn,Repost:()=>tn,Seal:()=>rn,SearchRelaysList:()=>_n,ShortTextNote:()=>Ge,Time:()=>fr,UserEmojiList:()=>Hn,UserStatuses:()=>cr,Zap:()=>Bn,ZapGoal:()=>kn,ZapRequest:()=>Sn,classifyKind:()=>We,isAddressableKind:()=>Ke,isEphemeralKind:()=>Fe,isKind:()=>Ve,isRegularKind:()=>ze,isReplaceableKind:()=>De});var Ze=0,Ge=1,Je=2,Ye=3,Qe=4,Xe=5,tn=6,en=7,nn=8,rn=13,on=14,sn=16,an=40,cn=41,un=42,ln=43,hn=44,fn=1040,dn=1059,pn=1063,gn=1311,yn=1971,wn=1984,bn=1984,mn=1985,En=4550,vn=5999,xn=6999,An=7e3,kn=9041,Sn=9734,Bn=9735,Un=9802,In=1e4,Ln=10001,Tn=10002,On=10003,Rn=10004,$n=10005,Nn=10006,_n=10007,Pn=10015,Hn=10030,Cn=10050,qn=10096,Mn=13194,jn=21e3,zn=22242,Dn=23194,Fn=23195,Kn=24133,Wn=27235,Vn=3e4,Zn=30001,Gn=30002,Jn=30003,Yn=30004,Qn=30008,Xn=30009,tr=30015,er=30017,nr=30018,rr=30023,or=30024,ir=30030,sr=30078,ar=30311,cr=30315,ur=30402,lr=30403,hr=31922,fr=31923,dr=31924,pr=31925,gr=31989,yr=31990,wr=34550;function br(t,e){if(t.ids&&-1===t.ids.indexOf(e.id))return!1;if(t.kinds&&-1===t.kinds.indexOf(e.kind))return!1;if(t.authors&&-1===t.authors.indexOf(e.pubkey))return!1;for(let n in t)if("#"===n[0]){let r=t[`#${n.slice(1)}`];if(r&&!e.tags.find((([t,e])=>t===n.slice(1)&&-1!==r.indexOf(e))))return!1}return!(t.since&&e.created_at<t.since)&&!(t.until&&e.created_at>t.until)}function mr(t,e){for(let n=0;n<t.length;n++)if(br(t[n],e))return!0;return!1}function Er(...t){let e={};for(let n=0;n<t.length;n++){let r=t[n];Object.entries(r).forEach((([t,n])=>{if("kinds"===t||"ids"===t||"authors"===t||"#"===t[0]){e[t]=e[t]||[];for(let r=0;r<n.length;r++){let o=n[r];e[t].includes(o)||e[t].push(o)}}})),r.limit&&(!e.limit||r.limit>e.limit)&&(e.limit=r.limit),r.until&&(!e.until||r.until>e.until)&&(e.until=r.until),r.since&&(!e.since||r.since<e.since)&&(e.since=r.since)}return e}function vr(t){if(t.ids&&!t.ids.length)return 0;if(t.kinds&&!t.kinds.length)return 0;if(t.authors&&!t.authors.length)return 0;for(const[e,n]of Object.entries(t))if("#"===e[0]&&Array.isArray(n)&&!n.length)return 0;return Math.min(Math.max(0,t.limit??1/0),t.ids?.length??1/0,t.authors?.length&&t.kinds?.every((t=>De(t)))?t.authors.length*t.kinds.length:1/0,t.authors?.length&&t.kinds?.every((t=>Ke(t)))&&t["#d"]?.length?t.authors.length*t.kinds.length*t["#d"].length:1/0)}var xr={};function Ar(t,e){let n=e.length+3,r=t.indexOf(`"${e}":`)+n,o=t.slice(r).indexOf('"')+r+1;return t.slice(o,o+64)}function kr(t,e){let n=e.length,r=t.indexOf(`"${e}":`)+n+3,o=t.slice(r),i=Math.min(o.indexOf(","),o.indexOf("}"));return parseInt(o.slice(0,i),10)}function Sr(t){let e=t.slice(0,22).indexOf('"EVENT"');if(-1===e)return null;let n=t.slice(e+7+1).indexOf('"');if(-1===n)return null;let r=e+7+1+n,o=t.slice(r+1,80).indexOf('"');if(-1===o)return null;let i=r+1+o;return t.slice(r+1,i)}function Br(t,e){return e===Ar(t,"id")}function Ur(t,e){return e===Ar(t,"pubkey")}function Ir(t,e){return e===kr(t,"kind")}o(xr,{getHex64:()=>Ar,getInt:()=>kr,getSubscriptionId:()=>Sr,matchEventId:()=>Br,matchEventKind:()=>Ir,matchEventPubkey:()=>Ur});var Lr={};function Tr(t,e){return{kind:zn,created_at:Math.floor(Date.now()/1e3),tags:[["relay",t],["challenge",e]],content:""}}async function Or(){return new Promise((t=>{const e=new MessageChannel,n=()=>{e.port1.removeEventListener("message",n),t()};e.port1.addEventListener("message",n),e.port2.postMessage(0),e.port1.start()}))}o(Lr,{makeAuthEvent:()=>Tr});var Rr,$r=t=>(t[le]=!0,!0),Nr=class extends Error{constructor(t,e){super(`Tried to send message '${t} on a closed connection to ${e}.`),this.name="SendingOnClosedConnection"}},_r=class{url;_connected=!1;onclose=null;onnotice=t=>console.debug(`NOTICE from ${this.url}: ${t}`);baseEoseTimeout=4400;connectionTimeout=4400;publishTimeout=4400;pingFrequency=2e4;pingTimeout=2e4;openSubs=new Map;enablePing;connectionTimeoutHandle;connectionPromise;openCountRequests=new Map;openEventPublishes=new Map;ws;incomingMessageQueue=new $e;queueRunning=!1;challenge;authPromise;serial=0;verifyEvent;_WebSocket;constructor(t,e){this.url=Ie(t),this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation||WebSocket,this.enablePing=e.enablePing}static async connect(t,e){const n=new _r(t,e);return await n.connect(),n}closeAllSubscriptions(t){for(let[e,n]of this.openSubs)n.close(t);this.openSubs.clear();for(let[e,n]of this.openEventPublishes)n.reject(new Error(t));this.openEventPublishes.clear();for(let[e,n]of this.openCountRequests)n.reject(new Error(t));this.openCountRequests.clear()}get connected(){return this._connected}async connect(){return this.connectionPromise||(this.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise(((t,e)=>{this.connectionTimeoutHandle=setTimeout((()=>{e("connection timed out"),this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection timed out")}),this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(t){return clearTimeout(this.connectionTimeoutHandle),void e(t)}this.ws.onopen=()=>{clearTimeout(this.connectionTimeoutHandle),this._connected=!0,this.enablePing&&this.pingpong(),t()},this.ws.onerror=t=>{clearTimeout(this.connectionTimeoutHandle),e(t.message||"websocket error"),this._connected=!1,this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection errored")},this.ws.onclose=t=>{clearTimeout(this.connectionTimeoutHandle),e(t.message||"websocket closed"),this._connected=!1,this.connectionPromise=void 0,this.onclose?.(),this.closeAllSubscriptions("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}))),this.connectionPromise}async waitForPingPong(){return new Promise(((t,e)=>{this.ws&&this.ws.on&&this.ws.on("pong",(()=>t(!0)))||e("ws can't listen for pong"),this.ws&&this.ws.ping&&this.ws.ping()}))}async waitForDummyReq(){return new Promise(((t,e)=>{const n=this.subscribe([{ids:["a".repeat(64)]}],{oneose:()=>{n.close(),t(!0)},eoseTimeout:this.pingTimeout+1e3})}))}async pingpong(){if(1===this.ws?.readyState){await Promise.any([this.ws&&this.ws.ping&&this.ws.on?this.waitForPingPong():this.waitForDummyReq(),new Promise((t=>setTimeout((()=>t(!1)),this.pingTimeout)))])?setTimeout((()=>this.pingpong()),this.pingFrequency):(this.closeAllSubscriptions("pingpong timed out"),this._connected=!1,this.onclose?.(),this.ws?.close())}}async runQueue(){for(this.queueRunning=!0;!1!==this.handleNext();)await Or();this.queueRunning=!1}handleNext(){const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const e=Sr(t);if(e){const n=this.openSubs.get(e);if(!n)return;const r=Ar(t,"id"),o=n.alreadyHaveEvent?.(r);if(n.receivedEvent?.(this,r),o)return}try{let e=JSON.parse(t);switch(e[0]){case"EVENT":{const t=this.openSubs.get(e[1]),n=e[2];return void(this.verifyEvent(n)&&mr(t.filters,n)&&t.onevent(n))}case"COUNT":{const t=e[1],n=e[2],r=this.openCountRequests.get(t);return void(r&&(r.resolve(n.count),this.openCountRequests.delete(t)))}case"EOSE":{const t=this.openSubs.get(e[1]);if(!t)return;return void t.receivedEose()}case"OK":{const t=e[1],n=e[2],r=e[3],o=this.openEventPublishes.get(t);return void(o&&(clearTimeout(o.timeout),n?o.resolve(r):o.reject(new Error(r)),this.openEventPublishes.delete(t)))}case"CLOSED":{const t=e[1],n=this.openSubs.get(t);if(!n)return;return n.closed=!0,void n.close(e[2])}case"NOTICE":return void this.onnotice(e[1]);case"AUTH":return void(this.challenge=e[1])}}catch(t){return}}async send(t){if(!this.connectionPromise)throw new Nr(t,this.url);this.connectionPromise.then((()=>{this.ws?.send(t)}))}async auth(t){const e=this.challenge;if(!e)throw new Error("can't perform auth, no challenge was received");return this.authPromise||(this.authPromise=new Promise((async(n,r)=>{try{let o=await t(Tr(this.url,e)),i=setTimeout((()=>{let t=this.openEventPublishes.get(o.id);t&&(t.reject(new Error("auth timed out")),this.openEventPublishes.delete(o.id))}),this.publishTimeout);this.openEventPublishes.set(o.id,{resolve:n,reject:r,timeout:i}),this.send('["AUTH",'+JSON.stringify(o)+"]")}catch(t){console.warn("subscribe auth function failed:",t)}}))),this.authPromise}async publish(t){const e=new Promise(((e,n)=>{const r=setTimeout((()=>{const e=this.openEventPublishes.get(t.id);e&&(e.reject(new Error("publish timed out")),this.openEventPublishes.delete(t.id))}),this.publishTimeout);this.openEventPublishes.set(t.id,{resolve:e,reject:n,timeout:r})}));return this.send('["EVENT",'+JSON.stringify(t)+"]"),e}async count(t,e){this.serial++;const n=e?.id||"count:"+this.serial,r=new Promise(((t,e)=>{this.openCountRequests.set(n,{resolve:t,reject:e})}));return this.send('["COUNT","'+n+'",'+JSON.stringify(t).substring(1)),r}subscribe(t,e){const n=this.prepareSubscription(t,e);return n.fire(),n}prepareSubscription(t,e){this.serial++;const n=e.id||(e.label?e.label+":":"sub:")+this.serial,r=new Pr(this,n,t,e);return this.openSubs.set(n,r),r}close(){this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,this.onclose?.(),this.ws?.close()}_onmessage(t){this.incomingMessageQueue.enqueue(t.data),this.queueRunning||this.runQueue()}},Pr=class{relay;id;closed=!1;eosed=!1;filters;alreadyHaveEvent;receivedEvent;onevent;oneose;onclose;eoseTimeout;eoseTimeoutHandle;constructor(t,e,n,r){this.relay=t,this.filters=n,this.id=e,this.alreadyHaveEvent=r.alreadyHaveEvent,this.receivedEvent=r.receivedEvent,this.eoseTimeout=r.eoseTimeout||t.baseEoseTimeout,this.oneose=r.oneose,this.onclose=r.onclose,this.onevent=r.onevent||(t=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,t)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,this.oneose?.())}close(t="closed by caller"){if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(t){if(!(t instanceof Nr))throw t}this.closed=!0}this.relay.openSubs.delete(this.id),this.onclose?.(t)}};try{Rr=WebSocket}catch{}var Hr,Cr=class extends _r{constructor(t){super(t,{verifyEvent:Me,websocketImplementation:Rr})}static async connect(t){const e=new Cr(t);return await e.connect(),e}},qr=class{relays=new Map;seenOn=new Map;trackRelays=!1;verifyEvent;enablePing;trustedRelayURLs=new Set;_WebSocket;constructor(t){this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation,this.enablePing=t.enablePing}async ensureRelay(t,e){t=Ie(t);let n=this.relays.get(t);return n||(n=new _r(t,{verifyEvent:this.trustedRelayURLs.has(t)?$r:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing}),n.onclose=()=>{this.relays.delete(t)},e?.connectionTimeout&&(n.connectionTimeout=e.connectionTimeout),this.relays.set(t,n)),await n.connect(),n}close(t){t.map(Ie).forEach((t=>{this.relays.get(t)?.close(),this.relays.delete(t)}))}subscribe(t,e,n){n.onauth=n.onauth||n.doauth;const r=[];for(let n=0;n<t.length;n++){const o=Ie(t[n]);r.find((t=>t.url===o))||r.push({url:o,filter:e})}return this.subscribeMap(r,n)}subscribeMany(t,e,n){n.onauth=n.onauth||n.doauth;const r=[],o=[];for(let n=0;n<t.length;n++){const i=Ie(t[n]);-1===o.indexOf(i)&&(o.push(i),r.push({url:i,filter:e}))}return this.subscribeMap(r,n)}subscribeMap(t,e){e.onauth=e.onauth||e.doauth;const n=new Map;for(const e of t){const{url:t,filter:r}=e;n.has(t)||n.set(t,[]),n.get(t).push(r)}const r=Array.from(n.entries()).map((([t,e])=>({url:t,filters:e})));this.trackRelays&&(e.receivedEvent=(t,e)=>{let n=this.seenOn.get(e);n||(n=new Set,this.seenOn.set(e,n)),n.add(t)});const o=new Set,i=[],s=[];let a=n=>{s[n]||(s[n]=!0,s.filter((t=>t)).length===t.length&&(e.oneose?.(),a=()=>{}))};const c=[];let u=(n,r)=>{c[n]||(a(n),c[n]=r,c.filter((t=>t)).length===t.length&&(e.onclose?.(c),u=()=>{}))};const l=t=>{if(e.alreadyHaveEvent?.(t))return!0;const n=o.has(t);return o.add(t),n},h=Promise.all(r.map((async({url:t,filters:n},r)=>{let o;try{o=await this.ensureRelay(t,{connectionTimeout:e.maxWait?Math.max(.8*e.maxWait,e.maxWait-1e3):void 0})}catch(t){return void u(r,t?.message||String(t))}let s=o.subscribe(n,{...e,oneose:()=>a(r),onclose:t=>{t.startsWith("auth-required: ")&&e.onauth?o.auth(e.onauth).then((()=>{o.subscribe(n,{...e,oneose:()=>a(r),onclose:t=>{u(r,t)},alreadyHaveEvent:l,eoseTimeout:e.maxWait})})).catch((t=>{u(r,`auth was required and attempted, but failed with: ${t}`)})):u(r,t)},alreadyHaveEvent:l,eoseTimeout:e.maxWait});i.push(s)})));return{async close(t){await h,i.forEach((e=>{e.close(t)}))}}}subscribeEose(t,e,n){n.onauth=n.onauth||n.doauth;const r=this.subscribe(t,e,{...n,oneose(){r.close("closed automatically on eose")}});return r}subscribeManyEose(t,e,n){n.onauth=n.onauth||n.doauth;const r=this.subscribeMany(t,e,{...n,oneose(){r.close("closed automatically on eose")}});return r}async querySync(t,e,n){return new Promise((async r=>{const o=[];this.subscribeEose(t,e,{...n,onevent(t){o.push(t)},onclose(t){r(o)}})}))}async get(t,e,n){e.limit=1;const r=await this.querySync(t,e,n);return r.sort(((t,e)=>e.created_at-t.created_at)),r[0]||null}publish(t,e,n){return t.map(Ie).map((async(t,r,o)=>{if(o.indexOf(t)!==r)return Promise.reject("duplicate url");let i=await this.ensureRelay(t);return i.publish(e).catch((async t=>{if(t instanceof Error&&t.message.startsWith("auth-required: ")&&n?.onauth)return await i.auth(n.onauth),i.publish(e);throw t})).then((t=>{if(this.trackRelays){let t=this.seenOn.get(e.id);t||(t=new Set,this.seenOn.set(e.id,t)),t.add(i)}return t}))}))}listConnectionStatus(){const t=new Map;return this.relays.forEach(((e,n)=>t.set(n,e.connected))),t}destroy(){this.relays.forEach((t=>t.close())),this.relays=new Map}};try{Hr=WebSocket}catch{}var Mr=class extends qr{constructor(t){super({verifyEvent:Me,websocketImplementation:Hr,...t})}},jr={};function zr(t){if(!Number.isSafeInteger(t))throw new Error(`Wrong integer: ${t}`)}function Dr(...t){const e=(t,e)=>n=>t(e(n));return{encode:Array.from(t).reverse().reduce(((t,n)=>t?e(t,n.encode):n.encode),void 0),decode:t.reduce(((t,n)=>t?e(t,n.decode):n.decode),void 0)}}function Fr(t){return{encode:e=>{if(!Array.isArray(e)||e.length&&"number"!=typeof e[0])throw new Error("alphabet.encode input should be an array of numbers");return e.map((e=>{if(zr(e),e<0||e>=t.length)throw new Error(`Digit index outside alphabet: ${e} (alphabet: ${t.length})`);return t[e]}))},decode:e=>{if(!Array.isArray(e)||e.length&&"string"!=typeof e[0])throw new Error("alphabet.decode input should be array of strings");return e.map((e=>{if("string"!=typeof e)throw new Error(`alphabet.decode: not string element=${e}`);const n=t.indexOf(e);if(-1===n)throw new Error(`Unknown letter: "${e}". Allowed: ${t}`);return n}))}}}function Kr(t=""){if("string"!=typeof t)throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&"string"!=typeof e[0])throw new Error("join.encode input should be array of strings");for(let t of e)if("string"!=typeof t)throw new Error(`join.encode: non-string input=${t}`);return e.join(t)},decode:e=>{if("string"!=typeof e)throw new Error("join.decode input should be string");return e.split(t)}}}function Wr(t,e="="){if(zr(t),"string"!=typeof e)throw new Error("padding chr should be string");return{encode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let t of n)if("string"!=typeof t)throw new Error(`padding.encode: non-string input=${t}`);for(;n.length*t%8;)n.push(e);return n},decode(n){if(!Array.isArray(n)||n.length&&"string"!=typeof n[0])throw new Error("padding.encode input should be array of strings");for(let t of n)if("string"!=typeof t)throw new Error(`padding.decode: non-string input=${t}`);let r=n.length;if(r*t%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if(!((r-1)*t%8))throw new Error("Invalid padding: string has too much padding");return n.slice(0,r)}}}function Vr(t){if("function"!=typeof t)throw new Error("normalize fn should be function");return{encode:t=>t,decode:e=>t(e)}}function Zr(t,e,n){if(e<2)throw new Error(`convertRadix: wrong from=${e}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(t))throw new Error("convertRadix: data should be array");if(!t.length)return[];let r=0;const o=[],i=Array.from(t);for(i.forEach((t=>{if(zr(t),t<0||t>=e)throw new Error(`Wrong integer: ${t}`)}));;){let t=0,s=!0;for(let o=r;o<i.length;o++){const a=i[o],c=e*t+a;if(!Number.isSafeInteger(c)||e*t/e!==t||c-a!=e*t)throw new Error("convertRadix: carry overflow");if(t=c%n,i[o]=Math.floor(c/n),!Number.isSafeInteger(i[o])||i[o]*n+t!==c)throw new Error("convertRadix: carry overflow");s&&(i[o]?s=!1:r=o)}if(o.push(t),s)break}for(let e=0;e<t.length-1&&0===t[e];e++)o.push(0);return o.reverse()}o(jr,{BECH32_REGEX:()=>bo,Bech32MaxSize:()=>wo,NostrTypeGuard:()=>yo,decode:()=>Eo,decodeNostrURI:()=>mo,encodeBytes:()=>Bo,naddrEncode:()=>Lo,neventEncode:()=>Io,noteEncode:()=>ko,nprofileEncode:()=>Uo,npubEncode:()=>Ao,nsecEncode:()=>xo});var Gr=(t,e)=>e?Gr(e,t%e):t,Jr=(t,e)=>t+(e-Gr(t,e));function Yr(t,e,n,r){if(!Array.isArray(t))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Jr(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Jr(e,n)}`);let o=0,i=0;const s=2**n-1,a=[];for(const r of t){if(zr(r),r>=2**e)throw new Error(`convertRadix2: invalid data word=${r} from=${e}`);if(o=o<<e|r,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=n;i-=n)a.push((o>>i-n&s)>>>0);o&=2**i-1}if(o=o<<n-i&s,!r&&i>=e)throw new Error("Excess padding");if(!r&&o)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&a.push(o>>>0),a}function Qr(t,e=!1){if(zr(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Jr(8,t)>32||Jr(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!(n instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return Yr(Array.from(n),8,t,!e)},decode:n=>{if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(Yr(n,t,8,e))}}}function Xr(t){if("function"!=typeof t)throw new Error("unsafeWrapper fn should be function");return function(...e){try{return t.apply(null,e)}catch(t){}}}var to=Dr(Qr(4),Fr("0123456789ABCDEF"),Kr("")),eo=Dr(Qr(5),Fr("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Wr(5),Kr("")),no=(Dr(Qr(5),Fr("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Wr(5),Kr("")),Dr(Qr(5),Fr("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),Kr(""),Vr((t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")))),Dr(Qr(6),Fr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Wr(6),Kr(""))),ro=Dr(Qr(6),Fr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Wr(6),Kr("")),oo=t=>{return Dr((zr(e=58),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return Zr(Array.from(t),256,e)},decode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(Zr(t,e,256))}}),Fr(t),Kr(""));var e},io=oo("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),so=(oo("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),oo("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),[0,2,3,5,6,7,9,10,11]),ao={encode(t){let e="";for(let n=0;n<t.length;n+=8){const r=t.subarray(n,n+8);e+=io.encode(r).padStart(so[r.length],"1")}return e},decode(t){let e=[];for(let n=0;n<t.length;n+=11){const r=t.slice(n,n+11),o=so.indexOf(r.length),i=io.decode(r);for(let t=0;t<i.length-o;t++)if(0!==i[t])throw new Error("base58xmr: wrong padding");e=e.concat(Array.from(i.slice(i.length-o)))}return Uint8Array.from(e)}},co=Dr(Fr("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Kr("")),uo=[996825010,642813549,513874426,1027748829,705979059];function lo(t){const e=t>>25;let n=(33554431&t)<<5;for(let t=0;t<uo.length;t++)1==(e>>t&1)&&(n^=uo[t]);return n}function ho(t,e,n=1){const r=t.length;let o=1;for(let e=0;e<r;e++){const n=t.charCodeAt(e);if(n<33||n>126)throw new Error(`Invalid prefix (${t})`);o=lo(o)^n>>5}o=lo(o);for(let e=0;e<r;e++)o=lo(o)^31&t.charCodeAt(e);for(let t of e)o=lo(o)^t;for(let t=0;t<6;t++)o=lo(o);return o^=n,co.encode(Yr([o%2**30],30,5,!1))}function fo(t){const e="bech32"===t?1:734539939,n=Qr(5),r=n.decode,o=n.encode,i=Xr(r);function s(t,n=90){if("string"!=typeof t)throw new Error("bech32.decode input should be string, not "+typeof t);if(t.length<8||!1!==n&&t.length>n)throw new TypeError(`Wrong string length: ${t.length} (${t}). Expected (8..${n})`);const r=t.toLowerCase();if(t!==r&&t!==t.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=(t=r).lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const i=t.slice(0,o),s=t.slice(o+1);if(s.length<6)throw new Error("Data must be at least 6 characters long");const a=co.decode(s).slice(0,-6),c=ho(i,a,e);if(!s.endsWith(c))throw new Error(`Invalid checksum in ${t}: expected "${c}"`);return{prefix:i,words:a}}return{encode:function(t,n,r=90){if("string"!=typeof t)throw new Error("bech32.encode prefix should be string, not "+typeof t);if(!Array.isArray(n)||n.length&&"number"!=typeof n[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof n);const o=t.length+7+n.length;if(!1!==r&&o>r)throw new TypeError(`Length ${o} exceeds limit ${r}`);return`${t=t.toLowerCase()}1${co.encode(n)}${ho(t,n,e)}`},decode:s,decodeToBytes:function(t){const{prefix:e,words:n}=s(t,!1);return{prefix:e,words:n,bytes:r(n)}},decodeUnsafe:Xr(s),fromWords:r,fromWordsUnsafe:i,toWords:o}}var po=fo("bech32"),go=(fo("bech32m"),{utf8:{encode:t=>(new TextDecoder).decode(t),decode:t=>(new TextEncoder).encode(t)},hex:Dr(Qr(4),Fr("0123456789abcdef"),Kr(""),Vr((t=>{if("string"!=typeof t||t.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}))),base16:to,base32:eo,base64:no,base64url:ro,base58:io,base58xmr:ao}),yo=(Object.keys(go).join(", "),{isNProfile:t=>/^nprofile1[a-z\d]+$/.test(t||""),isNEvent:t=>/^nevent1[a-z\d]+$/.test(t||""),isNAddr:t=>/^naddr1[a-z\d]+$/.test(t||""),isNSec:t=>/^nsec1[a-z\d]{58}$/.test(t||""),isNPub:t=>/^npub1[a-z\d]{58}$/.test(t||""),isNote:t=>/^note1[a-z\d]+$/.test(t||""),isNcryptsec:t=>/^ncryptsec1[a-z\d]+$/.test(t||"")}),wo=5e3,bo=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function mo(t){try{return t.startsWith("nostr:")&&(t=t.substring(6)),Eo(t)}catch(t){return{type:"invalid",data:null}}}function Eo(t){let{prefix:e,words:n}=po.decode(t,wo),r=new Uint8Array(po.fromWords(n));switch(e){case"nprofile":{let t=vo(r);if(!t[0]?.[0])throw new Error("missing TLV 0 for nprofile");if(32!==t[0][0].length)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:re(t[0][0]),relays:t[1]?t[1].map((t=>Be.decode(t))):[]}}}case"nevent":{let t=vo(r);if(!t[0]?.[0])throw new Error("missing TLV 0 for nevent");if(32!==t[0][0].length)throw new Error("TLV 0 should be 32 bytes");if(t[2]&&32!==t[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(t[3]&&4!==t[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:re(t[0][0]),relays:t[1]?t[1].map((t=>Be.decode(t))):[],author:t[2]?.[0]?re(t[2][0]):void 0,kind:t[3]?.[0]?parseInt(re(t[3][0]),16):void 0}}}case"naddr":{let t=vo(r);if(!t[0]?.[0])throw new Error("missing TLV 0 for naddr");if(!t[2]?.[0])throw new Error("missing TLV 2 for naddr");if(32!==t[2][0].length)throw new Error("TLV 2 should be 32 bytes");if(!t[3]?.[0])throw new Error("missing TLV 3 for naddr");if(4!==t[3][0].length)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:Be.decode(t[0][0]),pubkey:re(t[2][0]),kind:parseInt(re(t[3][0]),16),relays:t[1]?t[1].map((t=>Be.decode(t))):[]}}}case"nsec":return{type:e,data:r};case"npub":case"note":return{type:e,data:re(r)};default:throw new Error(`unknown prefix ${e}`)}}function vo(t){let e={},n=t;for(;n.length>0;){let t=n[0],r=n[1],o=n.slice(2,2+r);if(n=n.slice(2+r),o.length<r)throw new Error(`not enough data to read on TLV ${t}`);e[t]=e[t]||[],e[t].push(o)}return e}function xo(t){return Bo("nsec",t)}function Ao(t){return Bo("npub",oe(t))}function ko(t){return Bo("note",oe(t))}function So(t,e){let n=po.toWords(e);return po.encode(t,n,wo)}function Bo(t,e){return So(t,e)}function Uo(t){return So("nprofile",To({0:[oe(t.pubkey)],1:(t.relays||[]).map((t=>Ue.encode(t)))}))}function Io(t){let e;return void 0!==t.kind&&(e=function(t){const e=new Uint8Array(4);return e[0]=t>>24&255,e[1]=t>>16&255,e[2]=t>>8&255,e[3]=255&t,e}(t.kind)),So("nevent",To({0:[oe(t.id)],1:(t.relays||[]).map((t=>Ue.encode(t))),2:t.author?[oe(t.author)]:[],3:e?[new Uint8Array(e)]:[]}))}function Lo(t){let e=new ArrayBuffer(4);return new DataView(e).setUint32(0,t.kind,!1),So("naddr",To({0:[Ue.encode(t.identifier)],1:(t.relays||[]).map((t=>Ue.encode(t))),2:[oe(t.pubkey)],3:[new Uint8Array(e)]}))}function To(t){let e=[];return Object.entries(t).reverse().forEach((([t,n])=>{n.forEach((n=>{let r=new Uint8Array(n.length+2);r.set([parseInt(t)],0),r.set([n.length],1),r.set(n,2),e.push(r)}))})),se(...e)}var Oo=/\bnostr:((note|npub|naddr|nevent|nprofile)1\w+)\b|#\[(\d+)\]/g;function Ro(t){let e=[];for(let n of t.content.matchAll(Oo))if(n[2])try{let{type:t,data:r}=Eo(n[1]);switch(t){case"npub":e.push({text:n[0],profile:{pubkey:r,relays:[]}});break;case"nprofile":e.push({text:n[0],profile:r});break;case"note":e.push({text:n[0],event:{id:r,relays:[]}});break;case"nevent":e.push({text:n[0],event:r});break;case"naddr":e.push({text:n[0],address:r})}}catch(t){}else if(n[3]){let r=parseInt(n[3],10),o=t.tags[r];if(!o)continue;switch(o[0]){case"p":e.push({text:n[0],profile:{pubkey:o[1],relays:o[2]?[o[2]]:[]}});break;case"e":e.push({text:n[0],event:{id:o[1],relays:o[2]?[o[2]]:[]}});break;case"a":try{let[t,r,i]=o[1].split(":");e.push({text:n[0],address:{identifier:i,pubkey:r,kind:parseInt(t,10),relays:o[2]?[o[2]]:[]}})}catch(t){}}}return e}var $o={};function No(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function _o(t){if("boolean"!=typeof t)throw new Error(`boolean expected, not ${t}`)}function Po(t){return t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name}function Ho(t,...e){if(!Po(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function Co(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function qo(t,e){Ho(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}o($o,{decrypt:()=>Ti,encrypt:()=>Li});var Mo=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength),jo=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),zo=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");function Do(t){if("string"!=typeof t)throw new Error("string expected, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}function Fo(t){if("string"==typeof t)t=Do(t);else{if(!Po(t))throw new Error("Uint8Array expected, got "+typeof t);t=t.slice()}return t}function Ko(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return 0===n}var Wo=(t,e)=>(Object.assign(e,t),e);function Vo(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+u,a,r)}var Zo=16,Go=new Uint8Array(16),Jo=jo(Go),Yo=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255;var Qo=class{constructor(t,e){this.blockLen=Zo,this.outputLen=Zo,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,Ho(t=Fo(t),16);const n=zo(t);let r=n.getUint32(0,!1),o=n.getUint32(4,!1),i=n.getUint32(8,!1),s=n.getUint32(12,!1);const a=[];for(let t=0;t<128;t++)a.push({s0:Yo(r),s1:Yo(o),s2:Yo(i),s3:Yo(s)}),({s0:r,s1:o,s2:i,s3:s}={s3:(l=i)<<31|(h=s)>>>1,s2:(u=o)<<31|l>>>1,s1:(c=r)<<31|u>>>1,s0:c>>>1^225<<24&-(1&h)});var c,u,l,h;const f=(d=e||1024)>65536?8:d>1024?4:2;var d;if(![1,2,4,8].includes(f))throw new Error(`ghash: wrong window size=${f}, should be 2, 4 or 8`);this.W=f;const p=128/f,g=this.windowSize=2**f,y=[];for(let t=0;t<p;t++)for(let e=0;e<g;e++){let n=0,r=0,o=0,i=0;for(let s=0;s<f;s++){if(!(e>>>f-s-1&1))continue;const{s0:c,s1:u,s2:l,s3:h}=a[f*t+s];n^=c,r^=u,o^=l,i^=h}y.push({s0:n,s1:r,s2:o,s3:i})}this.t=y}_updateBlock(t,e,n,r){t^=this.s0,e^=this.s1,n^=this.s2,r^=this.s3;const{W:o,t:i,windowSize:s}=this;let a=0,c=0,u=0,l=0;const h=(1<<o)-1;let f=0;for(const d of[t,e,n,r])for(let t=0;t<4;t++){const e=d>>>8*t&255;for(let t=8/o-1;t>=0;t--){const n=e>>>o*t&h,{s0:r,s1:d,s2:p,s3:g}=i[f*s+n];a^=r,c^=d,u^=p,l^=g,f+=1}}this.s0=a,this.s1=c,this.s2=u,this.s3=l}update(t){t=Fo(t),Co(this);const e=jo(t),n=Math.floor(t.length/Zo),r=t.length%Zo;for(let t=0;t<n;t++)this._updateBlock(e[4*t+0],e[4*t+1],e[4*t+2],e[4*t+3]);return r&&(Go.set(t.subarray(n*Zo)),this._updateBlock(Jo[0],Jo[1],Jo[2],Jo[3]),Jo.fill(0)),this}destroy(){const{t:t}=this;for(const e of t)e.s0=0,e.s1=0,e.s2=0,e.s3=0}digestInto(t){Co(this),qo(t,this),this.finished=!0;const{s0:e,s1:n,s2:r,s3:o}=this,i=jo(t);return i[0]=e,i[1]=n,i[2]=r,i[3]=o,t}digest(){const t=new Uint8Array(Zo);return this.digestInto(t),this.destroy(),t}},Xo=class extends Qo{constructor(t,e){const n=function(t){t.reverse();const e=1&t[15];let n=0;for(let e=0;e<t.length;e++){const r=t[e];t[e]=r>>>1|n,n=(1&r)<<7}return t[0]^=225&-e,t}((t=Fo(t)).slice());super(n,e),n.fill(0)}update(t){t=Fo(t),Co(this);const e=jo(t),n=t.length%Zo,r=Math.floor(t.length/Zo);for(let t=0;t<r;t++)this._updateBlock(Yo(e[4*t+3]),Yo(e[4*t+2]),Yo(e[4*t+1]),Yo(e[4*t+0]));return n&&(Go.set(t.subarray(r*Zo)),this._updateBlock(Yo(Jo[3]),Yo(Jo[2]),Yo(Jo[1]),Yo(Jo[0])),Jo.fill(0)),this}digestInto(t){Co(this),qo(t,this),this.finished=!0;const{s0:e,s1:n,s2:r,s3:o}=this,i=jo(t);return i[0]=e,i[1]=n,i[2]=r,i[3]=o,t.reverse()}};function ti(t){const e=(e,n)=>t(n,e.length).update(Fo(e)).digest(),n=t(new Uint8Array(16),0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=(e,n)=>t(e,n),e}var ei=ti(((t,e)=>new Qo(t,e))),ni=ti(((t,e)=>new Xo(t,e))),ri=16,oi=new Uint8Array(ri);function ii(t){return t<<1^283&-(t>>7)}function si(t,e){let n=0;for(;e>0;e>>=1)n^=t&-(1&e),t=ii(t);return n}var ai=(()=>{let t=new Uint8Array(256);for(let e=0,n=1;e<256;e++,n^=ii(n))t[e]=n;const e=new Uint8Array(256);e[0]=99;for(let n=0;n<255;n++){let r=t[255-n];r|=r<<8,e[t[n]]=255&(r^r>>4^r>>5^r>>6^r>>7^99)}return e})(),ci=ai.map(((t,e)=>ai.indexOf(e))),ui=t=>t<<8|t>>>24;function li(t,e){if(256!==t.length)throw new Error("Wrong sbox length");const n=new Uint32Array(256).map(((n,r)=>e(t[r]))),r=n.map(ui),o=r.map(ui),i=o.map(ui),s=new Uint32Array(65536),a=new Uint32Array(65536),c=new Uint16Array(65536);for(let e=0;e<256;e++)for(let u=0;u<256;u++){const l=256*e+u;s[l]=n[e]^r[u],a[l]=o[e]^i[u],c[l]=t[e]<<8|t[u]}return{sbox:t,sbox2:c,T0:n,T1:r,T2:o,T3:i,T01:s,T23:a}}var hi=li(ai,(t=>si(t,3)<<24|t<<16|t<<8|si(t,2))),fi=li(ci,(t=>si(t,11)<<24|si(t,13)<<16|si(t,9)<<8|si(t,14))),di=(()=>{const t=new Uint8Array(16);for(let e=0,n=1;e<16;e++,n=ii(n))t[e]=n;return t})();function pi(t){Ho(t);const e=t.length;if(![16,24,32].includes(e))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${e}`);const{sbox2:n}=hi,r=jo(t),o=r.length,i=t=>wi(n,t,t,t,t),s=new Uint32Array(e+28);s.set(r);for(let t=o;t<s.length;t++){let e=s[t-1];t%o==0?e=i((a=e)<<24|a>>>8)^di[t/o-1]:o>6&&t%o==4&&(e=i(e)),s[t]=s[t-o]^e}var a;return s}function gi(t){const e=pi(t),n=e.slice(),r=e.length,{sbox2:o}=hi,{T0:i,T1:s,T2:a,T3:c}=fi;for(let t=0;t<r;t+=4)for(let o=0;o<4;o++)n[t+o]=e[r-t-4+o];e.fill(0);for(let t=4;t<r-4;t++){const e=n[t],r=wi(o,e,e,e,e);n[t]=i[255&r]^s[r>>>8&255]^a[r>>>16&255]^c[r>>>24]}return n}function yi(t,e,n,r,o,i){return t[n<<8&65280|r>>>8&255]^e[o>>>8&65280|i>>>24&255]}function wi(t,e,n,r,o){return t[255&e|65280&n]|t[r>>>16&255|o>>>16&65280]<<16}function bi(t,e,n,r,o){const{sbox2:i,T01:s,T23:a}=hi;let c=0;e^=t[c++],n^=t[c++],r^=t[c++],o^=t[c++];const u=t.length/4-2;for(let i=0;i<u;i++){const i=t[c++]^yi(s,a,e,n,r,o),u=t[c++]^yi(s,a,n,r,o,e),l=t[c++]^yi(s,a,r,o,e,n),h=t[c++]^yi(s,a,o,e,n,r);e=i,n=u,r=l,o=h}return{s0:t[c++]^wi(i,e,n,r,o),s1:t[c++]^wi(i,n,r,o,e),s2:t[c++]^wi(i,r,o,e,n),s3:t[c++]^wi(i,o,e,n,r)}}function mi(t,e,n,r,o){const{sbox2:i,T01:s,T23:a}=fi;let c=0;e^=t[c++],n^=t[c++],r^=t[c++],o^=t[c++];const u=t.length/4-2;for(let i=0;i<u;i++){const i=t[c++]^yi(s,a,e,o,r,n),u=t[c++]^yi(s,a,n,e,o,r),l=t[c++]^yi(s,a,r,n,e,o),h=t[c++]^yi(s,a,o,r,n,e);e=i,n=u,r=l,o=h}return{s0:t[c++]^wi(i,e,o,r,n),s1:t[c++]^wi(i,n,e,o,r),s2:t[c++]^wi(i,r,n,e,o),s3:t[c++]^wi(i,o,r,n,e)}}function Ei(t,e){if(!e)return new Uint8Array(t);if(Ho(e),e.length<t)throw new Error(`aes: wrong destination length, expected at least ${t}, got: ${e.length}`);return e}function vi(t,e,n,r,o){Ho(n,ri),Ho(r),o=Ei(r.length,o);const i=n,s=jo(i),a=zo(i),c=jo(r),u=jo(o),l=e?0:12,h=r.length;let f=a.getUint32(l,e),{s0:d,s1:p,s2:g,s3:y}=bi(t,s[0],s[1],s[2],s[3]);for(let n=0;n+4<=c.length;n+=4)u[n+0]=c[n+0]^d,u[n+1]=c[n+1]^p,u[n+2]=c[n+2]^g,u[n+3]=c[n+3]^y,f=f+1>>>0,a.setUint32(l,f,e),({s0:d,s1:p,s2:g,s3:y}=bi(t,s[0],s[1],s[2],s[3]));const w=ri*Math.floor(c.length/4);if(w<h){const t=new Uint32Array([d,p,g,y]),e=Mo(t);for(let t=w,n=0;t<h;t++,n++)o[t]=r[t]^e[n]}return o}Wo({blockSize:16,nonceLength:16},(function(t,e){function n(n,r){const o=pi(t),i=e.slice(),s=function(t,e,n,r){Ho(e,ri),Ho(n);const o=n.length;r=Ei(o,r);const i=e,s=jo(i);let{s0:a,s1:c,s2:u,s3:l}=bi(t,s[0],s[1],s[2],s[3]);const h=jo(n),f=jo(r);for(let e=0;e+4<=h.length;e+=4){f[e+0]=h[e+0]^a,f[e+1]=h[e+1]^c,f[e+2]=h[e+2]^u,f[e+3]=h[e+3]^l;let n=1;for(let t=i.length-1;t>=0;t--)n=n+(255&i[t])|0,i[t]=255&n,n>>>=8;({s0:a,s1:c,s2:u,s3:l}=bi(t,s[0],s[1],s[2],s[3]))}const d=ri*Math.floor(h.length/4);if(d<o){const t=new Uint32Array([a,c,u,l]),e=Mo(t);for(let t=d,i=0;t<o;t++,i++)r[t]=n[t]^e[i]}return r}(o,i,n,r);return o.fill(0),i.fill(0),s}return Ho(t),Ho(e,ri),{encrypt:(t,e)=>n(t,e),decrypt:(t,e)=>n(t,e)}}));function xi(t){if(Ho(t),t.length%ri!=0)throw new Error("aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size 16")}function Ai(t,e,n){let r=t.length;const o=r%ri;if(!e&&0!==o)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const i=jo(t);if(e){let t=ri-o;t||(t=ri),r+=t}const s=Ei(r,n);return{b:i,o:jo(s),out:s}}function ki(t,e){if(!e)return t;const n=t.length;if(!n)throw new Error("aes/pcks5: empty ciphertext not allowed");const r=t[n-1];if(r<=0||r>16)throw new Error(`aes/pcks5: wrong padding byte: ${r}`);const o=t.subarray(0,-r);for(let e=0;e<r;e++)if(t[n-e-1]!==r)throw new Error("aes/pcks5: wrong padding");return o}function Si(t){const e=new Uint8Array(16),n=jo(e);e.set(t);const r=ri-t.length;for(let t=ri-r;t<ri;t++)e[t]=r;return n}Wo({blockSize:16},(function(t,e={}){Ho(t);const n=!e.disablePadding;return{encrypt:(e,r)=>{Ho(e);const{b:o,o:i,out:s}=Ai(e,n,r),a=pi(t);let c=0;for(;c+4<=o.length;){const{s0:t,s1:e,s2:n,s3:r}=bi(a,o[c+0],o[c+1],o[c+2],o[c+3]);i[c++]=t,i[c++]=e,i[c++]=n,i[c++]=r}if(n){const t=Si(e.subarray(4*c)),{s0:n,s1:r,s2:o,s3:s}=bi(a,t[0],t[1],t[2],t[3]);i[c++]=n,i[c++]=r,i[c++]=o,i[c++]=s}return a.fill(0),s},decrypt:(e,r)=>{xi(e);const o=gi(t),i=Ei(e.length,r),s=jo(e),a=jo(i);for(let t=0;t+4<=s.length;){const{s0:e,s1:n,s2:r,s3:i}=mi(o,s[t+0],s[t+1],s[t+2],s[t+3]);a[t++]=e,a[t++]=n,a[t++]=r,a[t++]=i}return o.fill(0),ki(i,n)}}}));var Bi=Wo({blockSize:16,nonceLength:16},(function(t,e,n={}){Ho(t),Ho(e,16);const r=!n.disablePadding;return{encrypt:(n,o)=>{const i=pi(t),{b:s,o:a,out:c}=Ai(n,r,o),u=jo(e);let l=u[0],h=u[1],f=u[2],d=u[3],p=0;for(;p+4<=s.length;)l^=s[p+0],h^=s[p+1],f^=s[p+2],d^=s[p+3],({s0:l,s1:h,s2:f,s3:d}=bi(i,l,h,f,d)),a[p++]=l,a[p++]=h,a[p++]=f,a[p++]=d;if(r){const t=Si(n.subarray(4*p));l^=t[0],h^=t[1],f^=t[2],d^=t[3],({s0:l,s1:h,s2:f,s3:d}=bi(i,l,h,f,d)),a[p++]=l,a[p++]=h,a[p++]=f,a[p++]=d}return i.fill(0),c},decrypt:(n,o)=>{xi(n);const i=gi(t),s=jo(e),a=Ei(n.length,o),c=jo(n),u=jo(a);let l=s[0],h=s[1],f=s[2],d=s[3];for(let t=0;t+4<=c.length;){const e=l,n=h,r=f,o=d;l=c[t+0],h=c[t+1],f=c[t+2],d=c[t+3];const{s0:s,s1:a,s2:p,s3:g}=mi(i,l,h,f,d);u[t++]=s^e,u[t++]=a^n,u[t++]=p^r,u[t++]=g^o}return i.fill(0),ki(a,r)}}}));function Ui(t,e,n,r,o){const i=t.create(n,r.length+(o?.length||0));o&&i.update(o),i.update(r);const s=new Uint8Array(16),a=zo(s);return o&&Vo(a,0,BigInt(8*o.length),e),Vo(a,8,BigInt(8*r.length),e),i.update(s),i.digest()}Wo({blockSize:16,nonceLength:12,tagLength:16},(function(t,e,n){if(Ho(e),0===e.length)throw new Error("aes/gcm: empty nonce");const r=16;function o(t,e,r){const o=Ui(ei,!1,t,r,n);for(let t=0;t<e.length;t++)o[t]^=e[t];return o}function i(){const n=pi(t),r=oi.slice(),o=oi.slice();if(vi(n,!1,o,o,r),12===e.length)o.set(e);else{const t=oi.slice();Vo(zo(t),8,BigInt(8*e.length),!1),ei.create(r).update(e).update(t).digestInto(o)}return{xk:n,authKey:r,counter:o,tagMask:vi(n,!1,o,oi)}}return{encrypt:t=>{Ho(t);const{xk:e,authKey:n,counter:s,tagMask:a}=i(),c=new Uint8Array(t.length+r);vi(e,!1,s,t,c);const u=o(n,a,c.subarray(0,c.length-r));return c.set(u,t.length),e.fill(0),c},decrypt:t=>{if(Ho(t),t.length<r)throw new Error("aes/gcm: ciphertext less than tagLen (16)");const{xk:e,authKey:n,counter:s,tagMask:a}=i(),c=t.subarray(0,-16),u=t.subarray(-16);if(!Ko(o(n,a,c),u))throw new Error("aes/gcm: invalid ghash tag");const l=vi(e,!1,s,c);return n.fill(0),a.fill(0),e.fill(0),l}}}));var Ii=(t,e,n)=>r=>{if(!Number.isSafeInteger(r)||e>r||r>n)throw new Error(`${t}: invalid value=${r}, must be [${e}..${n}]`)};Wo({blockSize:16,nonceLength:12,tagLength:16},(function(t,e,n){const r=Ii("AAD",0,2**36),o=Ii("plaintext",0,2**36),i=Ii("nonce",12,12),s=Ii("ciphertext",16,2**36+16);function a(){const n=t.length;if(16!==n&&24!==n&&32!==n)throw new Error(`key length must be 16, 24 or 32 bytes, got: ${n} bytes`);const r=pi(t),o=new Uint8Array(n),i=new Uint8Array(16),s=jo(e);let a=0,c=s[0],u=s[1],l=s[2],h=0;for(const t of[i,o].map(jo)){const e=jo(t);for(let t=0;t<e.length;t+=2){const{s0:n,s1:o}=bi(r,a,c,u,l);e[t+0]=n,e[t+1]=o,a=++h}}return r.fill(0),{authKey:i,encKey:pi(o)}}function c(t,r,o){const i=Ui(ni,!0,r,o,n);for(let t=0;t<12;t++)i[t]^=e[t];i[15]&=127;const s=jo(i);let a=s[0],c=s[1],u=s[2],l=s[3];return({s0:a,s1:c,s2:u,s3:l}=bi(t,a,c,u,l)),s[0]=a,s[1]=c,s[2]=u,s[3]=l,i}function u(t,e,n){let r=e.slice();return r[15]|=128,vi(t,!0,r,n)}return Ho(e),i(e.length),n&&(Ho(n),r(n.length)),{encrypt:t=>{Ho(t),o(t.length);const{encKey:e,authKey:n}=a(),r=c(e,n,t),i=new Uint8Array(t.length+16);return i.set(r,t.length),i.set(u(e,r,t)),e.fill(0),n.fill(0),i},decrypt:t=>{Ho(t),s(t.length);const e=t.subarray(-16),{encKey:n,authKey:r}=a(),o=u(n,e,t.subarray(0,-16)),i=c(n,r,o);if(n.fill(0),r.fill(0),!Ko(e,i))throw new Error("invalid polyval tag");return o}}}));function Li(t,e,n){const r=t instanceof Uint8Array?re(t):t,o=Oi(_t.getSharedSecret(r,"02"+e));let i=Uint8Array.from(ue(16)),s=Ue.encode(n),a=Bi(o,i).encrypt(s);return`${no.encode(new Uint8Array(a))}?iv=${no.encode(new Uint8Array(i.buffer))}`}function Ti(t,e,n){const r=t instanceof Uint8Array?re(t):t;let[o,i]=n.split("?iv="),s=Oi(_t.getSharedSecret(r,"02"+e)),a=no.decode(i),c=no.decode(o),u=Bi(s,a).decrypt(c);return Be.decode(u)}function Oi(t){return t.slice(1,33)}var Ri={};o(Ri,{NIP05_REGEX:()=>Ni,isNip05:()=>_i,isValid:()=>qi,queryProfile:()=>Ci,searchDomain:()=>Hi,useFetchImplementation:()=>Pi});var $i,Ni=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,_i=t=>Ni.test(t||"");try{$i=fetch}catch(t){}function Pi(t){$i=t}async function Hi(t,e=""){try{const n=`https://${t}/.well-known/nostr.json?name=${e}`,r=await $i(n,{redirect:"manual"});if(200!==r.status)throw Error("Wrong response code");return(await r.json()).names}catch(t){return{}}}async function Ci(t){const e=t.match(Ni);if(!e)return null;const[,n="_",r]=e;try{const t=`https://${r}/.well-known/nostr.json?name=${n}`,e=await $i(t,{redirect:"manual"});if(200!==e.status)throw Error("Wrong response code");const o=await e.json(),i=o.names[n];return i?{pubkey:i,relays:o.relays?.[i]}:null}catch(t){return null}}async function qi(t,e){const n=await Ci(e);return!!n&&n.pubkey===t}var Mi={};function ji(t){const e={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let n,r;for(let o=t.tags.length-1;o>=0;o--){const i=t.tags[o];if("e"===i[0]&&i[1]){const[t,o,s,a,c]=i,u={id:o,relays:s?[s]:[],author:c};if("root"===a){e.root=u;continue}if("reply"===a){e.reply=u;continue}if("mention"===a){e.mentions.push(u);continue}n?r=u:n=u,e.mentions.push(u)}else{if("q"===i[0]&&i[1]){const[t,n,r]=i;e.quotes.push({id:n,relays:r?[r]:[]})}"p"===i[0]&&i[1]&&e.profiles.push({pubkey:i[1],relays:i[2]?[i[2]]:[]})}}return e.root||(e.root=r||n||e.reply),e.reply||(e.reply=n||e.root),[e.reply,e.root].forEach((t=>{if(!t)return;let n=e.mentions.indexOf(t);if(-1!==n&&e.mentions.splice(n,1),t.author){let n=e.profiles.find((e=>e.pubkey===t.author));n&&n.relays&&(t.relays||(t.relays=[]),n.relays.forEach((e=>{-1===t.relays?.indexOf(e)&&t.relays.push(e)})),n.relays=t.relays)}})),e.mentions.forEach((t=>{if(t.author){let n=e.profiles.find((e=>e.pubkey===t.author));n&&n.relays&&(t.relays||(t.relays=[]),n.relays.forEach((e=>{-1===t.relays.indexOf(e)&&t.relays.push(e)})),n.relays=t.relays)}})),e}o(Mi,{parse:()=>ji});var zi={};o(zi,{fetchRelayInformation:()=>Fi,useFetchImplementation:()=>Di});try{fetch}catch{}function Di(t){0}async function Fi(t){return await(await fetch(t.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var Ki={};function Wi(t){let e=0;for(let n=0;n<64;n+=8){const r=parseInt(t.substring(n,n+8),16);if(0!==r){e+=Math.clz32(r);break}e+=32}return e}function Vi(t,e){let n=0;const r=t,o=["nonce",n.toString(),e.toString()];for(r.tags.push(o);;){const t=Math.floor((new Date).getTime()/1e3);if(t!==r.created_at&&(n=0,r.created_at=t),o[1]=(++n).toString(),r.id=Zi(r),Wi(r.id)>=e)break}return r}function Zi(t){return re(ke(Ue.encode(JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content]))))}o(Ki,{fastEventHash:()=>Zi,getPow:()=>Wi,minePow:()=>Vi});var Gi={};o(Gi,{unwrapEvent:()=>Ws,unwrapManyEvents:()=>Vs,wrapEvent:()=>Fs,wrapManyEvents:()=>Ks});var Ji={};o(Ji,{createRumor:()=>Hs,createSeal:()=>Cs,createWrap:()=>qs,unwrapEvent:()=>zs,unwrapManyEvents:()=>Ds,wrapEvent:()=>Ms,wrapManyEvents:()=>js});var Yi={};o(Yi,{decrypt:()=>Ts,encrypt:()=>Ls,getConversationKey:()=>ks,v2:()=>Os});var Qi=(t,e)=>255&t[e++]|(255&t[e++])<<8,Xi=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,Ho(t=Fo(t),32);const e=Qi(t,0),n=Qi(t,2),r=Qi(t,4),o=Qi(t,6),i=Qi(t,8),s=Qi(t,10),a=Qi(t,12),c=Qi(t,14);this.r[0]=8191&e,this.r[1]=8191&(e>>>13|n<<3),this.r[2]=7939&(n>>>10|r<<6),this.r[3]=8191&(r>>>7|o<<9),this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,this.r[6]=8191&(i>>>14|s<<2),this.r[7]=8065&(s>>>11|a<<5),this.r[8]=8191&(a>>>8|c<<8),this.r[9]=c>>>5&127;for(let e=0;e<8;e++)this.pad[e]=Qi(t,16+2*e)}process(t,e,n=!1){const r=n?0:2048,{h:o,r:i}=this,s=i[0],a=i[1],c=i[2],u=i[3],l=i[4],h=i[5],f=i[6],d=i[7],p=i[8],g=i[9],y=Qi(t,e+0),w=Qi(t,e+2),b=Qi(t,e+4),m=Qi(t,e+6),E=Qi(t,e+8),v=Qi(t,e+10),x=Qi(t,e+12),A=Qi(t,e+14);let k=o[0]+(8191&y),S=o[1]+(8191&(y>>>13|w<<3)),B=o[2]+(8191&(w>>>10|b<<6)),U=o[3]+(8191&(b>>>7|m<<9)),I=o[4]+(8191&(m>>>4|E<<12)),L=o[5]+(E>>>1&8191),T=o[6]+(8191&(E>>>14|v<<2)),O=o[7]+(8191&(v>>>11|x<<5)),R=o[8]+(8191&(x>>>8|A<<8)),$=o[9]+(A>>>5|r),N=0,_=N+k*s+S*(5*g)+B*(5*p)+U*(5*d)+I*(5*f);N=_>>>13,_&=8191,_+=L*(5*h)+T*(5*l)+O*(5*u)+R*(5*c)+$*(5*a),N+=_>>>13,_&=8191;let P=N+k*a+S*s+B*(5*g)+U*(5*p)+I*(5*d);N=P>>>13,P&=8191,P+=L*(5*f)+T*(5*h)+O*(5*l)+R*(5*u)+$*(5*c),N+=P>>>13,P&=8191;let H=N+k*c+S*a+B*s+U*(5*g)+I*(5*p);N=H>>>13,H&=8191,H+=L*(5*d)+T*(5*f)+O*(5*h)+R*(5*l)+$*(5*u),N+=H>>>13,H&=8191;let C=N+k*u+S*c+B*a+U*s+I*(5*g);N=C>>>13,C&=8191,C+=L*(5*p)+T*(5*d)+O*(5*f)+R*(5*h)+$*(5*l),N+=C>>>13,C&=8191;let q=N+k*l+S*u+B*c+U*a+I*s;N=q>>>13,q&=8191,q+=L*(5*g)+T*(5*p)+O*(5*d)+R*(5*f)+$*(5*h),N+=q>>>13,q&=8191;let M=N+k*h+S*l+B*u+U*c+I*a;N=M>>>13,M&=8191,M+=L*s+T*(5*g)+O*(5*p)+R*(5*d)+$*(5*f),N+=M>>>13,M&=8191;let j=N+k*f+S*h+B*l+U*u+I*c;N=j>>>13,j&=8191,j+=L*a+T*s+O*(5*g)+R*(5*p)+$*(5*d),N+=j>>>13,j&=8191;let z=N+k*d+S*f+B*h+U*l+I*u;N=z>>>13,z&=8191,z+=L*c+T*a+O*s+R*(5*g)+$*(5*p),N+=z>>>13,z&=8191;let D=N+k*p+S*d+B*f+U*h+I*l;N=D>>>13,D&=8191,D+=L*u+T*c+O*a+R*s+$*(5*g),N+=D>>>13,D&=8191;let F=N+k*g+S*p+B*d+U*f+I*h;N=F>>>13,F&=8191,F+=L*l+T*u+O*c+R*a+$*s,N+=F>>>13,F&=8191,N=(N<<2)+N|0,N=N+_|0,_=8191&N,N>>>=13,P+=N,o[0]=_,o[1]=P,o[2]=H,o[3]=C,o[4]=q,o[5]=M,o[6]=j,o[7]=z,o[8]=D,o[9]=F}finalize(){const{h:t,pad:e}=this,n=new Uint16Array(10);let r=t[1]>>>13;t[1]&=8191;for(let e=2;e<10;e++)t[e]+=r,r=t[e]>>>13,t[e]&=8191;t[0]+=5*r,r=t[0]>>>13,t[0]&=8191,t[1]+=r,r=t[1]>>>13,t[1]&=8191,t[2]+=r,n[0]=t[0]+5,r=n[0]>>>13,n[0]&=8191;for(let e=1;e<10;e++)n[e]=t[e]+r,r=n[e]>>>13,n[e]&=8191;n[9]-=8192;let o=(1^r)-1;for(let t=0;t<10;t++)n[t]&=o;o=~o;for(let e=0;e<10;e++)t[e]=t[e]&o|n[e];t[0]=65535&(t[0]|t[1]<<13),t[1]=65535&(t[1]>>>3|t[2]<<10),t[2]=65535&(t[2]>>>6|t[3]<<7),t[3]=65535&(t[3]>>>9|t[4]<<4),t[4]=65535&(t[4]>>>12|t[5]<<1|t[6]<<14),t[5]=65535&(t[6]>>>2|t[7]<<11),t[6]=65535&(t[7]>>>5|t[8]<<8),t[7]=65535&(t[8]>>>8|t[9]<<5);let i=t[0]+e[0];t[0]=65535&i;for(let n=1;n<8;n++)i=(t[n]+e[n]|0)+(i>>>16)|0,t[n]=65535&i}update(t){Co(this);const{buffer:e,blockLen:n}=this,r=(t=Fo(t)).length;for(let o=0;o<r;){const i=Math.min(n-this.pos,r-o);if(i!==n)e.set(t.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(e,0,!1),this.pos=0);else for(;n<=r-o;o+=n)this.process(t,o)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(t){Co(this),qo(t,this),this.finished=!0;const{buffer:e,h:n}=this;let{pos:r}=this;if(r){for(e[r++]=1;r<16;r++)e[r]=0;this.process(e,0,!0)}this.finalize();let o=0;for(let e=0;e<8;e++)t[o++]=n[e]>>>0,t[o++]=n[e]>>>8;return t}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}};var ts=function(t){const e=(e,n)=>t(n).update(Fo(e)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=e=>t(e),e}((t=>new Xi(t))),es=Do("expand 16-byte k"),ns=Do("expand 32-byte k"),rs=jo(es),os=jo(ns);function is(t,e){return t<<e|t>>>32-e}function ss(t){return t.byteOffset%4==0}var as=2**32-1,cs=new Uint32Array;function us(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:i,rounds:s}=function(t,e){if(null==e||"object"!=typeof e)throw new Error("options must be defined");return Object.assign(t,e)}({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if("function"!=typeof t)throw new Error("core must be a function");return No(o),No(s),_o(i),_o(n),(e,a,c,u,l=0)=>{Ho(e),Ho(a),Ho(c);const h=c.length;if(u||(u=new Uint8Array(h)),Ho(u),No(l),l<0||l>=as)throw new Error("arx: counter overflow");if(u.length<h)throw new Error(`arx: output (${u.length}) is shorter than data (${h})`);const f=[];let d,p,g=e.length;if(32===g)d=e.slice(),f.push(d),p=os;else{if(16!==g||!n)throw new Error(`arx: invalid 32-byte key, got length=${g}`);d=new Uint8Array(32),d.set(e),d.set(e,16),p=rs,f.push(d)}ss(a)||(a=a.slice(),f.push(a));const y=jo(d);if(r){if(24!==a.length)throw new Error("arx: extended nonce must be 24 bytes");r(p,y,jo(a.subarray(0,16)),y),a=a.subarray(16)}const w=16-o;if(w!==a.length)throw new Error(`arx: nonce must be ${w} or 16 bytes`);if(12!==w){const t=new Uint8Array(12);t.set(a,i?0:12-a.length),a=t,f.push(a)}const b=jo(a);for(!function(t,e,n,r,o,i,s,a){const c=o.length,u=new Uint8Array(64),l=jo(u),h=ss(o)&&ss(i),f=h?jo(o):cs,d=h?jo(i):cs;for(let p=0;p<c;s++){if(t(e,n,r,l,s,a),s>=as)throw new Error("arx: counter overflow");const g=Math.min(64,c-p);if(h&&64===g){const t=p/4;if(p%4!=0)throw new Error("arx: invalid block position");for(let e,n=0;n<16;n++)e=t+n,d[e]=f[e]^l[n];p+=64}else{for(let t,e=0;e<g;e++)t=p+e,i[t]=o[t]^u[e];p+=g}}}(t,p,y,b,c,u,l,s);f.length>0;)f.pop().fill(0);return u}}function ls(t,e,n,r,o,i=20){let s=t[0],a=t[1],c=t[2],u=t[3],l=e[0],h=e[1],f=e[2],d=e[3],p=e[4],g=e[5],y=e[6],w=e[7],b=o,m=n[0],E=n[1],v=n[2],x=s,A=a,k=c,S=u,B=l,U=h,I=f,L=d,T=p,O=g,R=y,$=w,N=b,_=m,P=E,H=v;for(let t=0;t<i;t+=2)x=x+B|0,N=is(N^x,16),T=T+N|0,B=is(B^T,12),x=x+B|0,N=is(N^x,8),T=T+N|0,B=is(B^T,7),A=A+U|0,_=is(_^A,16),O=O+_|0,U=is(U^O,12),A=A+U|0,_=is(_^A,8),O=O+_|0,U=is(U^O,7),k=k+I|0,P=is(P^k,16),R=R+P|0,I=is(I^R,12),k=k+I|0,P=is(P^k,8),R=R+P|0,I=is(I^R,7),S=S+L|0,H=is(H^S,16),$=$+H|0,L=is(L^$,12),S=S+L|0,H=is(H^S,8),$=$+H|0,L=is(L^$,7),x=x+U|0,H=is(H^x,16),R=R+H|0,U=is(U^R,12),x=x+U|0,H=is(H^x,8),R=R+H|0,U=is(U^R,7),A=A+I|0,N=is(N^A,16),$=$+N|0,I=is(I^$,12),A=A+I|0,N=is(N^A,8),$=$+N|0,I=is(I^$,7),k=k+L|0,_=is(_^k,16),T=T+_|0,L=is(L^T,12),k=k+L|0,_=is(_^k,8),T=T+_|0,L=is(L^T,7),S=S+B|0,P=is(P^S,16),O=O+P|0,B=is(B^O,12),S=S+B|0,P=is(P^S,8),O=O+P|0,B=is(B^O,7);let C=0;r[C++]=s+x|0,r[C++]=a+A|0,r[C++]=c+k|0,r[C++]=u+S|0,r[C++]=l+B|0,r[C++]=h+U|0,r[C++]=f+I|0,r[C++]=d+L|0,r[C++]=p+T|0,r[C++]=g+O|0,r[C++]=y+R|0,r[C++]=w+$|0,r[C++]=b+N|0,r[C++]=m+_|0,r[C++]=E+P|0,r[C++]=v+H|0}var hs=us(ls,{counterRight:!1,counterLength:4,allowShortKeys:!1}),fs=us(ls,{counterRight:!1,counterLength:8,extendNonceFn:function(t,e,n,r){let o=t[0],i=t[1],s=t[2],a=t[3],c=e[0],u=e[1],l=e[2],h=e[3],f=e[4],d=e[5],p=e[6],g=e[7],y=n[0],w=n[1],b=n[2],m=n[3];for(let t=0;t<20;t+=2)o=o+c|0,y=is(y^o,16),f=f+y|0,c=is(c^f,12),o=o+c|0,y=is(y^o,8),f=f+y|0,c=is(c^f,7),i=i+u|0,w=is(w^i,16),d=d+w|0,u=is(u^d,12),i=i+u|0,w=is(w^i,8),d=d+w|0,u=is(u^d,7),s=s+l|0,b=is(b^s,16),p=p+b|0,l=is(l^p,12),s=s+l|0,b=is(b^s,8),p=p+b|0,l=is(l^p,7),a=a+h|0,m=is(m^a,16),g=g+m|0,h=is(h^g,12),a=a+h|0,m=is(m^a,8),g=g+m|0,h=is(h^g,7),o=o+u|0,m=is(m^o,16),p=p+m|0,u=is(u^p,12),o=o+u|0,m=is(m^o,8),p=p+m|0,u=is(u^p,7),i=i+l|0,y=is(y^i,16),g=g+y|0,l=is(l^g,12),i=i+l|0,y=is(y^i,8),g=g+y|0,l=is(l^g,7),s=s+h|0,w=is(w^s,16),f=f+w|0,h=is(h^f,12),s=s+h|0,w=is(w^s,8),f=f+w|0,h=is(h^f,7),a=a+c|0,b=is(b^a,16),d=d+b|0,c=is(c^d,12),a=a+c|0,b=is(b^a,8),d=d+b|0,c=is(c^d,7);let E=0;r[E++]=o,r[E++]=i,r[E++]=s,r[E++]=a,r[E++]=y,r[E++]=w,r[E++]=b,r[E++]=m},allowShortKeys:!1}),ds=new Uint8Array(16),ps=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update(ds.subarray(n))},gs=new Uint8Array(32);function ys(t,e,n,r,o){const i=t(e,n,gs),s=ts.create(i);o&&ps(s,o),ps(s,r);const a=new Uint8Array(16),c=zo(a);Vo(c,0,BigInt(o?o.length:0),!0),Vo(c,8,BigInt(r.length),!0),s.update(a);const u=s.digest();return i.fill(0),u}var ws=t=>(e,n,r)=>{const o=16;return Ho(e,32),Ho(n),{encrypt:(i,s)=>{const a=i.length,c=a+o;s?Ho(s,c):s=new Uint8Array(c),t(e,n,i,s,1);const u=ys(t,e,n,s.subarray(0,-16),r);return s.set(u,a),s},decrypt:(i,s)=>{const a=i.length,c=a-o;if(a<o)throw new Error("encrypted data must be at least 16 bytes");s?Ho(s,c):s=new Uint8Array(c);const u=i.subarray(0,-16);if(!Ko(i.subarray(-16),ys(t,e,n,u,r)))throw new Error("invalid tag");return t(e,n,u,s,1),s}}},bs=(ws(hs),ws(fs),class extends ae{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,ye.hash(t);const n=ie(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?t.create().update(n).digest():n);for(let t=0;t<o.length;t++)o[t]^=54;this.iHash.update(o),this.oHash=t.create();for(let t=0;t<o.length;t++)o[t]^=106;this.oHash.update(o),o.fill(0)}update(t){return ye.exists(this),this.iHash.update(t),this}digestInto(t){ye.exists(this),ye.bytes(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:e,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return t.finished=r,t.destroyed=o,t.blockLen=i,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}),ms=(t,e,n)=>new bs(t,e).update(n).digest();ms.create=(t,e)=>new bs(t,e);var Es=new Uint8Array([0]),vs=new Uint8Array;var xs=1,As=65535;function ks(t,e){const n=_t.getSharedSecret(t,"02"+e).subarray(1,33);return r=ke,o=n,i="nip44-v2",ye.hash(r),void 0===i&&(i=new Uint8Array(r.outputLen)),ms(r,ie(i),ie(o));var r,o,i}function Ss(t,e){const n=function(t,e,n,r=32){if(ye.hash(t),ye.number(r),r>255*t.outputLen)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/t.outputLen);void 0===n&&(n=vs);const i=new Uint8Array(o*t.outputLen),s=ms.create(t,e),a=s._cloneInto(),c=new Uint8Array(s.outputLen);for(let e=0;e<o;e++)Es[0]=e+1,a.update(0===e?vs:c).update(n).update(Es).digestInto(c),i.set(c,t.outputLen*e),s._cloneInto(a);return s.destroy(),a.destroy(),c.fill(0),Es.fill(0),i.slice(0,r)}(ke,t,e,76);return{chacha_key:n.subarray(0,32),chacha_nonce:n.subarray(32,44),hmac_key:n.subarray(44,76)}}function Bs(t){if(!Number.isSafeInteger(t)||t<1)throw new Error("expected positive integer");if(t<=32)return 32;const e=1<<Math.floor(Math.log2(t-1))+1,n=e<=256?32:e/8;return n*(Math.floor((t-1)/n)+1)}function Us(t){const e=Ue.encode(t),n=e.length;return se(function(t){if(!Number.isSafeInteger(t)||t<xs||t>As)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const e=new Uint8Array(2);return new DataView(e.buffer).setUint16(0,t,!1),e}(n),e,new Uint8Array(Bs(n)-n))}function Is(t,e,n){if(32!==n.length)throw new Error("AAD associated data must be 32 bytes");const r=se(n,e);return ms(ke,t,r)}function Ls(t,e,n=ue(32)){const{chacha_key:r,chacha_nonce:o,hmac_key:i}=Ss(e,n),s=Us(t),a=hs(r,o,s),c=Is(i,a,n);return no.encode(se(new Uint8Array([2]),n,a,c))}function Ts(t,e){const{nonce:n,ciphertext:r,mac:o}=function(t){if("string"!=typeof t)throw new Error("payload must be a valid string");const e=t.length;if(e<132||e>87472)throw new Error("invalid payload length: "+e);if("#"===t[0])throw new Error("unknown encryption version");let n;try{n=no.decode(t)}catch(t){throw new Error("invalid base64: "+t.message)}const r=n.length;if(r<99||r>65603)throw new Error("invalid data length: "+r);const o=n[0];if(2!==o)throw new Error("unknown encryption version "+o);return{nonce:n.subarray(1,33),ciphertext:n.subarray(33,-32),mac:n.subarray(-32)}}(t),{chacha_key:i,chacha_nonce:s,hmac_key:a}=Ss(e,n);if(!Ko(Is(a,r,n),o))throw new Error("invalid MAC");return function(t){const e=new DataView(t.buffer).getUint16(0),n=t.subarray(2,2+e);if(e<xs||e>As||n.length!==e||t.length!==2+Bs(e))throw new Error("invalid padding");return Be.decode(n)}(hs(i,s,r))}var Os={utils:{getConversationKey:ks,calcPaddedLen:Bs},encrypt:Ls,decrypt:Ts},Rs=()=>Math.round(Date.now()/1e3),$s=()=>Math.round(Rs()-172800*Math.random()),Ns=(t,e)=>ks(t,e),_s=(t,e,n)=>Ls(JSON.stringify(t),Ns(e,n)),Ps=(t,e)=>JSON.parse(Ts(t.content,Ns(e,t.pubkey)));function Hs(t,e){const n={created_at:Rs(),content:"",tags:[],...t,pubkey:Ce(e)};return n.id=_e(n),n}function Cs(t,e,n){return qe({kind:rn,content:_s(t,e,n),created_at:$s(),tags:[]},e)}function qs(t,e){const n=He();return qe({kind:dn,content:_s(t,n,e),created_at:$s(),tags:[["p",e]]},n)}function Ms(t,e,n){return qs(Cs(Hs(t,e),e,n),n)}function js(t,e,n){if(!n||0===n.length)throw new Error("At least one recipient is required.");const r=Ce(e),o=[Ms(t,e,r)];return n.forEach((n=>{o.push(Ms(t,e,n))})),o}function zs(t,e){const n=Ps(t,e);return Ps(n,e)}function Ds(t,e){let n=[];return t.forEach((t=>{n.push(zs(t,e))})),n.sort(((t,e)=>t.created_at-e.created_at)),n}function Fs(t,e,n,r,o){const i=function(t,e,n,r){const o={created_at:Math.ceil(Date.now()/1e3),kind:on,tags:[],content:e};return(Array.isArray(t)?t:[t]).forEach((({publicKey:t,relayUrl:e})=>{o.tags.push(e?["p",t,e]:["p",t])})),r&&o.tags.push(["e",r.eventId,r.relayUrl||"","reply"]),n&&o.tags.push(["subject",n]),o}(e,n,r,o);return Ms(i,t,e.publicKey)}function Ks(t,e,n,r,o){if(!e||0===e.length)throw new Error("At least one recipient is required.");return[{publicKey:Ce(t)},...e].map((e=>Fs(t,e,n,r,o)))}var Ws=zs,Vs=Ds,Zs={};function Gs(t,e,n,r){let o;const i=[...t.tags??[],["e",e.id,n],["p",e.pubkey]];return e.kind===Ge?o=tn:(o=sn,i.push(["k",String(e.kind)])),qe({kind:o,tags:i,content:""===t.content||e.tags?.find((t=>"-"===t[0]))?"":JSON.stringify(e),created_at:t.created_at},r)}function Js(t){if(![tn,sn].includes(t.kind))return;let e,n;for(let r=t.tags.length-1;r>=0&&(void 0===e||void 0===n);r--){const o=t.tags[r];o.length>=2&&("e"===o[0]&&void 0===e?e=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==e?{id:e[1],relays:[e[2],n?.[2]].filter((t=>"string"==typeof t)),author:n?.[1]}:void 0}function Ys(t,{skipVerification:e}={}){const n=Js(t);if(void 0===n||""===t.content)return;let r;try{r=JSON.parse(t.content)}catch(t){return}return r.id===n.id&&(e||Me(r))?r:void 0}o(Zs,{finishRepostEvent:()=>Gs,getRepostedEvent:()=>Ys,getRepostedEventPointer:()=>Js});var Qs={};o(Qs,{NOSTR_URI_REGEX:()=>Xs,parse:()=>ea,test:()=>ta});var Xs=new RegExp(`nostr:(${bo.source})`);function ta(t){return"string"==typeof t&&new RegExp(`^${Xs.source}$`).test(t)}function ea(t){const e=t.match(new RegExp(`^${Xs.source}$`));if(!e)throw new Error(`Invalid Nostr URI: ${t}`);return{uri:e[0],value:e[1],decoded:Eo(e[1])}}var na={};function ra(t,e,n){const r=e.tags.filter((t=>t.length>=2&&("e"===t[0]||"p"===t[0])));return qe({...t,kind:en,tags:[...t.tags??[],...r,["e",e.id],["p",e.pubkey]],content:t.content??"+"},n)}function oa(t){if(t.kind!==en)return;let e,n;for(let r=t.tags.length-1;r>=0&&(void 0===e||void 0===n);r--){const o=t.tags[r];o.length>=2&&("e"===o[0]&&void 0===e?e=o:"p"===o[0]&&void 0===n&&(n=o))}return void 0!==e&&void 0!==n?{id:e[1],relays:[e[2],n[2]].filter((t=>void 0!==t)),author:n[1]}:void 0}o(na,{finishReactionEvent:()=>ra,getReactedEventPointer:()=>oa});var ia={};o(ia,{parse:()=>ca});var sa=/\W/m,aa=/\W |\W$|$|,| /m;function*ca(t){const e=t.length;let n=0,r=0;for(;r<e;){let o=t.indexOf(":",r);if(-1===o)break;if("nostr"===t.substring(o-5,o)){const i=t.substring(o+60).match(sa),s=i?o+60+i.index:e;try{let e,{data:i,type:a}=Eo(t.substring(o+1,s));switch(a){case"npub":e={pubkey:i};break;case"nsec":case"note":r=s+1;continue;default:e=i}n!==o-5&&(yield{type:"text",text:t.substring(n,o-5)}),yield{type:"reference",pointer:e},r=s,n=r;continue}catch(t){r=o+1;continue}}else if("https"===t.substring(o-5,o)||"http"===t.substring(o-4,o)){const i=t.substring(o+4).match(aa),s=i?o+4+i.index:e,a="s"===t[o-1]?5:4;try{let e=new URL(t.substring(o-a,s));if(-1===e.hostname.indexOf("."))throw new Error("invalid url");if(n!==o-a&&(yield{type:"text",text:t.substring(n,o-a)}),/\.(png|jpe?g|gif|webp)$/i.test(e.pathname)){yield{type:"image",url:e.toString()},r=s,n=r;continue}if(/\.(mp4|avi|webm|mkv)$/i.test(e.pathname)){yield{type:"video",url:e.toString()},r=s,n=r;continue}if(/\.(mp3|aac|ogg|opus)$/i.test(e.pathname)){yield{type:"audio",url:e.toString()},r=s,n=r;continue}yield{type:"url",url:e.toString()},r=s,n=r;continue}catch(t){r=s+1;continue}}else{if("wss"!==t.substring(o-3,o)&&"ws"!==t.substring(o-2,o)){r=o+1;continue}{const i=t.substring(o+4).match(aa),s=i?o+4+i.index:e,a="s"===t[o-1]?3:2;try{let e=new URL(t.substring(o-a,s));if(-1===e.hostname.indexOf("."))throw new Error("invalid ws url");n!==o-a&&(yield{type:"text",text:t.substring(n,o-a)}),yield{type:"relay",url:e.toString()},r=s,n=r;continue}catch(t){r=s+1;continue}}}}n!==e&&(yield{type:"text",text:t.substring(n)})}var ua={};o(ua,{channelCreateEvent:()=>la,channelHideMessageEvent:()=>da,channelMessageEvent:()=>fa,channelMetadataEvent:()=>ha,channelMuteUserEvent:()=>pa});var la=(t,e)=>{let n;if("object"==typeof t.content)n=JSON.stringify(t.content);else{if("string"!=typeof t.content)return;n=t.content}return qe({kind:an,tags:[...t.tags??[]],content:n,created_at:t.created_at},e)},ha=(t,e)=>{let n;if("object"==typeof t.content)n=JSON.stringify(t.content);else{if("string"!=typeof t.content)return;n=t.content}return qe({kind:cn,tags:[["e",t.channel_create_event_id],...t.tags??[]],content:n,created_at:t.created_at},e)},fa=(t,e)=>{const n=[["e",t.channel_create_event_id,t.relay_url,"root"]];return t.reply_to_channel_message_event_id&&n.push(["e",t.reply_to_channel_message_event_id,t.relay_url,"reply"]),qe({kind:un,tags:[...n,...t.tags??[]],content:t.content,created_at:t.created_at},e)},da=(t,e)=>{let n;if("object"==typeof t.content)n=JSON.stringify(t.content);else{if("string"!=typeof t.content)return;n=t.content}return qe({kind:ln,tags:[["e",t.channel_message_event_id],...t.tags??[]],content:n,created_at:t.created_at},e)},pa=(t,e)=>{let n;if("object"==typeof t.content)n=JSON.stringify(t.content);else{if("string"!=typeof t.content)return;n=t.content}return qe({kind:hn,tags:[["p",t.pubkey_to_mute],...t.tags??[]],content:n,created_at:t.created_at},e)},ga={};o(ga,{EMOJI_SHORTCODE_REGEX:()=>ya,matchAll:()=>ba,regex:()=>wa,replaceAll:()=>ma});var ya=/:(\w+):/,wa=()=>new RegExp(`\\B${ya.source}\\B`,"g");function*ba(t){const e=t.matchAll(wa());for(const t of e)try{const[e,n]=t;yield{shortcode:e,name:n,start:t.index,end:t.index+e.length}}catch(t){}}function ma(t,e){return t.replaceAll(wa(),((t,n)=>e({shortcode:t,name:n})))}var Ea,va={};o(va,{useFetchImplementation:()=>xa,validateGithub:()=>Aa});try{Ea=fetch}catch{}function xa(t){Ea=t}async function Aa(t,e,n){try{return await(await Ea(`https://gist.github.com/${e}/${n}/raw`)).text()===`Verifying that I control the following Nostr public key: ${t}`}catch(t){return!1}}var ka={};function Sa(t){const{host:e,pathname:n,searchParams:r}=new URL(t),o=n||e,i=r.get("relay"),s=r.get("secret");if(!o||!i||!s)throw new Error("invalid connection string");return{pubkey:o,relay:i,secret:s}}async function Ba(t,e,n){const r={method:"pay_invoice",params:{invoice:n}},o=Li(e,t,JSON.stringify(r)),i={kind:Dn,created_at:Math.round(Date.now()/1e3),content:o,tags:[["p",t]]};return qe(i,e)}o(ka,{makeNwcRequestEvent:()=>Ba,parseConnectionString:()=>Sa});var Ua={};function Ia(t){return t=(t=t.trim().toLowerCase()).normalize("NFKC"),Array.from(t).map((t=>/\p{Letter}/u.test(t)||/\p{Number}/u.test(t)?t:"-")).join("")}o(Ua,{normalizeIdentifier:()=>Ia});var La,Ta={};o(Ta,{getSatoshisAmountFromBolt11:()=>Pa,getZapEndpoint:()=>Ra,makeZapReceipt:()=>_a,makeZapRequest:()=>$a,useFetchImplementation:()=>Oa,validateZapRequest:()=>Na});try{La=fetch}catch{}function Oa(t){La=t}async function Ra(t){try{let e="",{lud06:n,lud16:r}=JSON.parse(t.content);if(n){let{words:t}=po.decode(n,1e3),r=po.fromWords(t);e=Be.decode(r)}else{if(!r)return null;{let[t,n]=r.split("@");e=new URL(`/.well-known/lnurlp/${t}`,`https://${n}`).toString()}}let o=await La(e),i=await o.json();if(i.allowsNostr&&i.nostrPubkey)return i.callback}catch(t){}return null}function $a(t){let e={kind:9734,created_at:Math.round(Date.now()/1e3),content:t.comment||"",tags:[["p","pubkey"in t?t.pubkey:t.event.pubkey],["amount",t.amount.toString()],["relays",...t.relays]]};if("event"in t){if(e.tags.push(["e",t.event.id]),De(t.event.kind)){const n=["a",`${t.event.kind}:${t.event.pubkey}:`];e.tags.push(n)}else if(Ke(t.event.kind)){let n=t.event.tags.find((([t,e])=>"d"===t&&e));if(!n)throw new Error("d tag not found or is empty");const r=["a",`${t.event.kind}:${t.event.pubkey}:${n[1]}`];e.tags.push(r)}e.tags.push(["k",t.event.kind.toString()])}return e}function Na(t){let e;try{e=JSON.parse(t)}catch(t){return"Invalid zap request JSON."}if(!fe(e))return"Zap request is not a valid Nostr event.";if(!Me(e))return"Invalid signature on zap request.";let n=e.tags.find((([t,e])=>"p"===t&&e));if(!n)return"Zap request doesn't have a 'p' tag.";if(!n[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let r=e.tags.find((([t,e])=>"e"===t&&e));return r&&!r[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":e.tags.find((([t,e])=>"relays"===t&&e))?null:"Zap request doesn't have a 'relays' tag."}function _a({zapRequest:t,preimage:e,bolt11:n,paidAt:r}){let o=JSON.parse(t),i=o.tags.filter((([t])=>"e"===t||"p"===t||"a"===t)),s={kind:9735,created_at:Math.round(r.getTime()/1e3),content:"",tags:[...i,["P",o.pubkey],["bolt11",n],["description",t]]};return e&&s.tags.push(["preimage",e]),s}function Pa(t){if(t.length<50)return 0;const e=(t=t.substring(0,50)).lastIndexOf("1");if(-1===e)return 0;const n=t.substring(0,e);if(!n.startsWith("lnbc"))return 0;const r=n.substring(4);if(r.length<1)return 0;const o=r[r.length-1],i=o.charCodeAt(0)-"0".charCodeAt(0),s=i>=0&&i<=9;let a=r.length-1;if(s&&a++,a<1)return 0;const c=parseInt(r.substring(0,a));switch(o){case"m":return 1e5*c;case"u":return 100*c;case"n":return c/10;case"p":return c/1e4;default:return 1e8*c}}var Ha={};o(Ha,{getToken:()=>Ma,hashPayload:()=>Va,unpackEventFromToken:()=>za,validateEvent:()=>Ga,validateEventKind:()=>Fa,validateEventMethodTag:()=>Wa,validateEventPayloadTag:()=>Za,validateEventTimestamp:()=>Da,validateEventUrlTag:()=>Ka,validateToken:()=>ja});var Ca,qa="Nostr ";async function Ma(t,e,n,r=!1,o){const i={kind:Wn,tags:[["u",t],["method",e]],created_at:Math.round((new Date).getTime()/1e3),content:""};o&&i.tags.push(["payload",Va(o)]);const s=await n(i);return(r?qa:"")+no.encode(Ue.encode(JSON.stringify(s)))}async function ja(t,e,n){const r=await za(t).catch((t=>{throw t}));return await Ga(r,e,n).catch((t=>{throw t}))}async function za(t){if(!t)throw new Error("Missing token");t=t.replace(qa,"");const e=Be.decode(no.decode(t));if(!e||0===e.length||!e.startsWith("{"))throw new Error("Invalid token");return JSON.parse(e)}function Da(t){return!!t.created_at&&Math.round((new Date).getTime()/1e3)-t.created_at<60}function Fa(t){return t.kind===Wn}function Ka(t,e){const n=t.tags.find((t=>"u"===t[0]));return!!n&&(n.length>0&&n[1]===e)}function Wa(t,e){const n=t.tags.find((t=>"method"===t[0]));return!!n&&(n.length>0&&n[1].toLowerCase()===e.toLowerCase())}function Va(t){return re(ke(Ue.encode(JSON.stringify(t))))}function Za(t,e){const n=t.tags.find((t=>"payload"===t[0]));if(!n)return!1;const r=Va(e);return n.length>0&&n[1]===r}async function Ga(t,e,n,r){if(!Me(t))throw new Error("Invalid nostr event, signature invalid");if(!Fa(t))throw new Error("Invalid nostr event, kind invalid");if(!Da(t))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!Ka(t,e))throw new Error("Invalid nostr event, url tag invalid");if(!Wa(t,n))throw new Error("Invalid nostr event, method tag invalid");if(Boolean(r)&&"object"==typeof r&&Object.keys(r).length>0&&!Za(t,r))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}return Ca=i,((o,i,s,a)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of n(i))r.call(o,c)||c===s||t(o,c,{get:()=>i[c],enumerable:!(a=e(i,c))||a.enumerable});return o})(t({},"__esModule",{value:!0}),Ca)})();
|
|
//# sourceMappingURL=/sm/8a637fc3be698500d2b32d47068de522c987ef5def0a7be9de886b2e0952c2a5.map
|