nostr-web-components
Version:
collection of web components that provide quick access to basic nostr things
7 lines (5 loc) • 87.4 kB
JavaScript
var nostr_user_search=(function(){"use strict";var Sr=Object.defineProperty;var Rr=(le,F,H)=>F in le?Sr(le,F,{enumerable:!0,configurable:!0,writable:!0,value:H}):le[F]=H;var h=(le,F,H)=>Rr(le,typeof F!="symbol"?F+"":F,H);/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function le(i){return i instanceof Uint8Array||ArrayBuffer.isView(i)&&i.constructor.name==="Uint8Array"}function F(i,e=""){if(!Number.isSafeInteger(i)||i<0){const n=e&&`"${e}" `;throw new Error(`${n}expected integer >= 0, got ${i}`)}}function H(i,e,n=""){const t=le(i),r=i==null?void 0:i.length,s=e!==void 0;if(!t||s&&r!==e){const a=n&&`"${n}" `,o=s?` of length ${e}`:"",c=t?`length=${r}`:`type=${typeof i}`;throw new Error(a+"expected Uint8Array"+o+", got "+c)}return i}function vt(i,e=!0){if(i.destroyed)throw new Error("Hash instance has been destroyed");if(e&&i.finished)throw new Error("Hash#digest() has already been called")}function On(i,e){H(i,void 0,"digestInto() output");const n=e.outputLen;if(i.length<n)throw new Error('"digestInto() output" expected to be of length >='+n)}function Ze(...i){for(let e=0;e<i.length;e++)i[e].fill(0)}function Ke(i){return new DataView(i.buffer,i.byteOffset,i.byteLength)}function Y(i,e){return i<<32-e|i>>>e}const xt=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",kn=Array.from({length:256},(i,e)=>e.toString(16).padStart(2,"0"));function C(i){if(H(i),xt)return i.toHex();let e="";for(let n=0;n<i.length;n++)e+=kn[i[n]];return e}const ne={_0:48,_9:57,A:65,F:70,a:97,f:102};function St(i){if(i>=ne._0&&i<=ne._9)return i-ne._0;if(i>=ne.A&&i<=ne.F)return i-(ne.A-10);if(i>=ne.a&&i<=ne.f)return i-(ne.a-10)}function Z(i){if(typeof i!="string")throw new Error("hex string expected, got "+typeof i);if(xt)return Uint8Array.fromHex(i);const e=i.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const t=new Uint8Array(n);for(let r=0,s=0;r<n;r++,s+=2){const a=St(i.charCodeAt(s)),o=St(i.charCodeAt(s+1));if(a===void 0||o===void 0){const c=i[s]+i[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}t[r]=a*16+o}return t}function Pe(...i){let e=0;for(let t=0;t<i.length;t++){const r=i[t];H(r),e+=r.length}const n=new Uint8Array(e);for(let t=0,r=0;t<i.length;t++){const s=i[t];n.set(s,r),r+=s.length}return n}function Pn(i,e={}){const n=(r,s)=>i(s).update(r).digest(),t=i(void 0);return n.outputLen=t.outputLen,n.blockLen=t.blockLen,n.create=r=>i(r),Object.assign(n,e),Object.freeze(n)}function Rt(i=32){const e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof(e==null?void 0:e.getRandomValues)!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(i))}const _n=i=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,i])}),_e=new TextDecoder("utf-8"),Cn=new TextEncoder;function ue(i){try{i.indexOf("://")===-1&&(i="wss://"+i);let e=new URL(i);return e.protocol==="http:"?e.protocol="ws:":e.protocol==="https:"&&(e.protocol="wss:"),e.pathname=e.pathname.replace(/\/+/g,"/"),e.pathname.endsWith("/")&&(e.pathname=e.pathname.slice(0,-1)),(e.port==="80"&&e.protocol==="ws:"||e.port==="443"&&e.protocol==="wss:")&&(e.port=""),e.searchParams.sort(),e.hash="",e.toString()}catch{throw new Error(`Invalid URL: ${i}`)}}/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Tt(i){return i instanceof Uint8Array||ArrayBuffer.isView(i)&&i.constructor.name==="Uint8Array"}function At(i,e){return Array.isArray(e)?e.length===0?!0:i?e.every(n=>typeof n=="string"):e.every(n=>Number.isSafeInteger(n)):!1}function Bn(i){if(typeof i!="function")throw new Error("function expected");return!0}function ve(i,e){if(typeof e!="string")throw new Error(`${i}: string expected`);return!0}function Ot(i){if(!Number.isSafeInteger(i))throw new Error(`invalid integer: ${i}`)}function ze(i){if(!Array.isArray(i))throw new Error("array expected")}function kt(i,e){if(!At(!0,e))throw new Error(`${i}: array of strings expected`)}function Pt(i,e){if(!At(!1,e))throw new Error(`${i}: array of numbers expected`)}function In(...i){const e=s=>s,n=(s,a)=>o=>s(a(o)),t=i.map(s=>s.encode).reduceRight(n,e),r=i.map(s=>s.decode).reduce(n,e);return{encode:t,decode:r}}function $n(i){const e=typeof i=="string"?i.split(""):i,n=e.length;kt("alphabet",e);const t=new Map(e.map((r,s)=>[r,s]));return{encode:r=>(ze(r),r.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${i}`);return e[s]})),decode:r=>(ze(r),r.map(s=>{ve("alphabet.decode",s);const a=t.get(s);if(a===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${i}`);return a}))}}function Hn(i=""){return ve("join",i),{encode:e=>(kt("join.decode",e),e.join(i)),decode:e=>(ve("join.decode",e),e.split(i))}}const _t=(i,e)=>e===0?i:_t(e,i%e),Ce=(i,e)=>i+(e-_t(i,e)),Be=(()=>{let i=[];for(let e=0;e<40;e++)i.push(2**e);return i})();function je(i,e,n,t){if(ze(i),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Ce(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Ce(e,n)}`);let r=0,s=0;const a=Be[e],o=Be[n]-1,c=[];for(const u of i){if(Ot(u),u>=a)throw new Error(`convertRadix2: invalid data word=${u} from=${e}`);if(r=r<<e|u,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=n;s-=n)c.push((r>>s-n&o)>>>0);const f=Be[s];if(f===void 0)throw new Error("invalid carry");r&=f-1}if(r=r<<n-s&o,!t&&s>=e)throw new Error("Excess padding");if(!t&&r>0)throw new Error(`Non-zero padding: ${r}`);return t&&s>0&&c.push(r>>>0),c}function Ln(i,e=!1){if(Ot(i),i<=0||i>32)throw new Error("radix2: bits should be in (0..32]");if(Ce(8,i)>32||Ce(i,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Tt(n))throw new Error("radix2.encode input should be Uint8Array");return je(Array.from(n),8,i,!e)},decode:n=>(Pt("radix2.decode",n),Uint8Array.from(je(n,i,8,e)))}}function Ct(i){return Bn(i),function(...e){try{return i.apply(null,e)}catch{}}}const Ye=In($n("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Hn("")),Bt=[996825010,642813549,513874426,1027748829,705979059];function xe(i){const e=i>>25;let n=(i&33554431)<<5;for(let t=0;t<Bt.length;t++)(e>>t&1)===1&&(n^=Bt[t]);return n}function It(i,e,n=1){const t=i.length;let r=1;for(let s=0;s<t;s++){const a=i.charCodeAt(s);if(a<33||a>126)throw new Error(`Invalid prefix (${i})`);r=xe(r)^a>>5}r=xe(r);for(let s=0;s<t;s++)r=xe(r)^i.charCodeAt(s)&31;for(let s of e)r=xe(r)^s;for(let s=0;s<6;s++)r=xe(r);return r^=n,Ye.encode(je([r%Be[30]],30,5,!1))}function Nn(i){const e=i==="bech32"?1:734539939,n=Ln(5),t=n.decode,r=n.encode,s=Ct(t);function a(l,y,d=90){ve("bech32.encode prefix",l),Tt(y)&&(y=Array.from(y)),Pt("bech32.encode",y);const b=l.length;if(b===0)throw new TypeError(`Invalid prefix length ${b}`);const w=b+7+y.length;if(d!==!1&&w>d)throw new TypeError(`Length ${w} exceeds limit ${d}`);const p=l.toLowerCase(),T=It(p,y,e);return`${p}1${Ye.encode(y)}${T}`}function o(l,y=90){ve("bech32.decode input",l);const d=l.length;if(d<8||y!==!1&&d>y)throw new TypeError(`invalid string length: ${d} (${l}). Expected (8..${y})`);const b=l.toLowerCase();if(l!==b&&l!==l.toUpperCase())throw new Error("String must be lowercase or uppercase");const w=b.lastIndexOf("1");if(w===0||w===-1)throw new Error('Letter "1" must be present between prefix and data only');const p=b.slice(0,w),T=b.slice(w+1);if(T.length<6)throw new Error("Data must be at least 6 characters long");const I=Ye.decode(T).slice(0,-6),U=It(p,I,e);if(!T.endsWith(U))throw new Error(`Invalid checksum in ${l}: expected "${U}"`);return{prefix:p,words:I}}const c=Ct(o);function u(l){const{prefix:y,words:d}=o(l,!1);return{prefix:y,words:d,bytes:t(d)}}function f(l,y){return a(l,r(y))}return{encode:a,decode:o,encodeFromBytes:f,decodeToBytes:u,decodeUnsafe:c,fromWords:t,fromWordsUnsafe:s,toWords:r}}const we=Nn("bech32"),qn=5e3;function $t(i){var r,s,a,o,c,u,f;let{prefix:e,words:n}=we.decode(i,qn),t=new Uint8Array(we.fromWords(n));switch(e){case"nprofile":{let l=Je(t);if(!((r=l[0])!=null&&r[0]))throw new Error("missing TLV 0 for nprofile");if(l[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:C(l[0][0]),relays:l[1]?l[1].map(y=>_e.decode(y)):[]}}}case"nevent":{let l=Je(t);if(!((s=l[0])!=null&&s[0]))throw new Error("missing TLV 0 for nevent");if(l[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(l[2]&&l[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(l[3]&&l[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:C(l[0][0]),relays:l[1]?l[1].map(y=>_e.decode(y)):[],author:(a=l[2])!=null&&a[0]?C(l[2][0]):void 0,kind:(o=l[3])!=null&&o[0]?parseInt(C(l[3][0]),16):void 0}}}case"naddr":{let l=Je(t);if(!((c=l[0])!=null&&c[0]))throw new Error("missing TLV 0 for naddr");if(!((u=l[2])!=null&&u[0]))throw new Error("missing TLV 2 for naddr");if(l[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((f=l[3])!=null&&f[0]))throw new Error("missing TLV 3 for naddr");if(l[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:_e.decode(l[0][0]),pubkey:C(l[2][0]),kind:parseInt(C(l[3][0]),16),relays:l[1]?l[1].map(y=>_e.decode(y)):[]}}}case"nsec":return{type:e,data:t};case"npub":case"note":return{type:e,data:C(t)};default:throw new Error(`unknown prefix ${e}`)}}function Je(i){let e={},n=i;for(;n.length>0;){let t=n[0],r=n[1],s=n.slice(2,2+r);if(n=n.slice(2+r),s.length<r)throw new Error(`not enough data to read on TLV ${t}`);e[t]=e[t]||[],e[t].push(s)}return e}var Mn=Math.pow(2,8)-1,Un=Math.pow(2,16)-1,Wn=Math.pow(2,32)-1;const Vn=function(i){var e=i-1;if(e<=Mn)return Uint8Array;if(e<=Un)return Uint16Array;if(e<=Wn)return Uint32Array;throw new Error("mnemonist: Pointer Array of size > 4294967295 is not supported.")};function re(i){if(this.capacity=i,typeof this.capacity!="number"||this.capacity<=0)throw new Error("mnemonist/lru-cache: capacity should be positive number.");if(!isFinite(this.capacity)||Math.floor(this.capacity)!==this.capacity)throw new Error("mnemonist/lru-cache: capacity should be a finite positive integer.");var e=Vn(i);this.forward=new e(i),this.backward=new e(i),this.K=new Array(i),this.V=new Array(i),this.size=0,this.head=0,this.tail=0,this.items={}}re.prototype.clear=function(){this.size=0,this.head=0,this.tail=0,this.items={}},re.prototype.splayOnTop=function(i){var e=this.head;if(this.head===i)return this;var n=this.backward[i],t=this.forward[i];return this.tail===i?this.tail=n:this.backward[t]=n,this.forward[n]=t,this.backward[e]=i,this.head=i,this.forward[i]=e,this},re.prototype.set=function(i,e){var n=this.items[i];if(typeof n<"u"){this.splayOnTop(n),this.V[n]=e;return}this.size<this.capacity?n=this.size++:(n=this.tail,this.tail=this.backward[n],delete this.items[this.K[n]]),this.items[i]=n,this.K[n]=i,this.V[n]=e,this.forward[n]=this.head,this.backward[this.head]=n,this.head=n},re.prototype.setpop=function(i,e){var n=null,t=null,r=this.items[i];return typeof r<"u"?(this.splayOnTop(r),n=this.V[r],this.V[r]=e,{evicted:!1,key:i,value:n}):(this.size<this.capacity?r=this.size++:(r=this.tail,this.tail=this.backward[r],n=this.V[r],t=this.K[r],delete this.items[t]),this.items[i]=r,this.K[r]=i,this.V[r]=e,this.forward[r]=this.head,this.backward[this.head]=r,this.head=r,t?{evicted:!0,key:t,value:n}:null)},re.prototype.has=function(i){return i in this.items},re.prototype.get=function(i){var e=this.items[i];if(!(typeof e>"u"))return this.splayOnTop(e),this.V[e]},re.prototype.peek=function(i){var e=this.items[i];if(!(typeof e>"u"))return this.V[e]};class Ht{constructor(e,n){h(this,"_batchLoadFn");h(this,"_maxBatchSize");h(this,"_cacheKeyFn");h(this,"_cacheMap");h(this,"_batch");if(typeof e!="function")throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but got: ${e}.`);this._batchLoadFn=e,this._maxBatchSize=(n==null?void 0:n.maxBatchSize)||1/0,this._cacheKeyFn=n==null?void 0:n.cacheKeyFn;const t=new re(2e3);this._cacheMap={get:n.transformCacheHit?r=>{var s;return(s=t.get(r))==null?void 0:s.then(n.transformCacheHit)}:r=>t.get(r),set(r,s){return t.set(r,s)},delete(r){t.set(r,void 0)},clear(){t.clear()}},this._batch=null}load(e){if(e==null)throw new TypeError(`The loader.load() function must be called with a value, but got: ${String(e)}.`);const n=Dn(this),t=this._cacheKeyFn(e),r=this._cacheMap.get(t);if(r){const a=n.cacheHits||(n.cacheHits=[]);return new Promise(o=>{a.push(()=>{o(r)})})}n.keys.push(e);const s=new Promise((a,o)=>{n.callbacks.push({resolve:a,reject:o})});return this._cacheMap.set(t,s),s}clear(e){const n=this._cacheMap;if(n){const t=this._cacheKeyFn(e);n.delete(t)}return this}}function Dn(i){const e=i._batch;if(e!==null&&!e.hasDispatched&&e.keys.length<i._maxBatchSize)return e;const n={hasDispatched:!1,keys:[],callbacks:[]};return i._batch=n,setTimeout(()=>{Fn(i,n)}),n}function Fn(i,e){if(e.hasDispatched=!0,e.keys.length===0){Xe(e);return}let n;try{n=i._batchLoadFn(e.keys)}catch(t){return Ge(i,e,new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function errored synchronously: ${String(t)}.`))}if(!n||typeof n.then!="function")return Ge(i,e,new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise: ${String(n)}.`));n.then(t=>{if(t.length!==e.keys.length)throw new TypeError(`DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array of the same length as the Array of keys.
Keys:
${String(e.keys)}
Values:
${String(t)}`);Xe(e);for(let r=0;r<e.callbacks.length;r++){const s=t[r];s instanceof Error?e.callbacks[r].reject(s):e.callbacks[r].resolve(s)}}).catch(t=>{Ge(i,e,t)})}function Ge(i,e,n){Xe(e);for(let t=0;t<e.keys.length;t++)i.clear(e.keys[t]),e.callbacks[t].reject(n)}function Xe(i){if(i.cacheHits)for(let e=0;e<i.cacheHits.length;e++)i.cacheHits[e]()}const Ie=new TextDecoder("utf-8"),Zn=new TextEncoder;function J(i){try{i.indexOf("://")===-1&&(i="wss://"+i);let e=new URL(i);return e.protocol==="http:"?e.protocol="ws:":e.protocol==="https:"&&(e.protocol="wss:"),e.pathname=e.pathname.replace(/\/+/g,"/"),e.pathname.endsWith("/")&&(e.pathname=e.pathname.slice(0,-1)),(e.port==="80"&&e.protocol==="ws:"||e.port==="443"&&e.protocol==="wss:")&&(e.port=""),e.searchParams.sort(),e.hash="",e.toString()}catch{throw new Error(`Invalid URL: ${i}`)}}const Lt=5e3;function Nt(i){var r,s,a,o,c,u,f;let{prefix:e,words:n}=we.decode(i,Lt),t=new Uint8Array(we.fromWords(n));switch(e){case"nprofile":{let l=Qe(t);if(!((r=l[0])!=null&&r[0]))throw new Error("missing TLV 0 for nprofile");if(l[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:C(l[0][0]),relays:l[1]?l[1].map(y=>Ie.decode(y)):[]}}}case"nevent":{let l=Qe(t);if(!((s=l[0])!=null&&s[0]))throw new Error("missing TLV 0 for nevent");if(l[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(l[2]&&l[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(l[3]&&l[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:C(l[0][0]),relays:l[1]?l[1].map(y=>Ie.decode(y)):[],author:(a=l[2])!=null&&a[0]?C(l[2][0]):void 0,kind:(o=l[3])!=null&&o[0]?parseInt(C(l[3][0]),16):void 0}}}case"naddr":{let l=Qe(t);if(!((c=l[0])!=null&&c[0]))throw new Error("missing TLV 0 for naddr");if(!((u=l[2])!=null&&u[0]))throw new Error("missing TLV 2 for naddr");if(l[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((f=l[3])!=null&&f[0]))throw new Error("missing TLV 3 for naddr");if(l[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:Ie.decode(l[0][0]),pubkey:C(l[2][0]),kind:parseInt(C(l[3][0]),16),relays:l[1]?l[1].map(y=>Ie.decode(y)):[]}}}case"nsec":return{type:e,data:t};case"npub":case"note":return{type:e,data:C(t)};default:throw new Error(`unknown prefix ${e}`)}}function Qe(i){let e={},n=i;for(;n.length>0;){let t=n[0],r=n[1],s=n.slice(2,2+r);if(n=n.slice(2+r),s.length<r)throw new Error(`not enough data to read on TLV ${t}`);e[t]=e[t]||[],e[t].push(s)}return e}function qt(i){return zn("npub",Z(i))}function Kn(i,e){let n=we.toWords(e);return we.encode(i,n,Lt)}function zn(i,e){return Kn(i,e)}function jn(i,e,n){return i&e^~i&n}function Yn(i,e,n){return i&e^i&n^e&n}class Jn{constructor(e,n,t,r){h(this,"blockLen");h(this,"outputLen");h(this,"padOffset");h(this,"isLE");h(this,"buffer");h(this,"view");h(this,"finished",!1);h(this,"length",0);h(this,"pos",0);h(this,"destroyed",!1);this.blockLen=e,this.outputLen=n,this.padOffset=t,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Ke(this.buffer)}update(e){vt(this),H(e);const{view:n,buffer:t,blockLen:r}=this,s=e.length;for(let a=0;a<s;){const o=Math.min(r-this.pos,s-a);if(o===r){const c=Ke(e);for(;r<=s-a;a+=r)this.process(c,a);continue}t.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){vt(this),On(e,this),this.finished=!0;const{buffer:n,view:t,blockLen:r,isLE:s}=this;let{pos:a}=this;n[a++]=128,Ze(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(t,0),a=0);for(let l=a;l<r;l++)n[l]=0;t.setBigUint64(r-8,BigInt(this.length*8),s),this.process(t,0);const o=Ke(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)o.setUint32(4*l,f[l],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const t=e.slice(0,n);return this.destroy(),t}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:t,length:r,finished:s,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=s,e.length=r,e.pos=o,r%n&&e.buffer.set(t),e}clone(){return this._cloneInto()}}const se=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Gn=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),oe=new Uint32Array(64);class Xn extends Jn{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:n,C:t,D:r,E:s,F:a,G:o,H:c}=this;return[e,n,t,r,s,a,o,c]}set(e,n,t,r,s,a,o,c){this.A=e|0,this.B=n|0,this.C=t|0,this.D=r|0,this.E=s|0,this.F=a|0,this.G=o|0,this.H=c|0}process(e,n){for(let l=0;l<16;l++,n+=4)oe[l]=e.getUint32(n,!1);for(let l=16;l<64;l++){const y=oe[l-15],d=oe[l-2],b=Y(y,7)^Y(y,18)^y>>>3,w=Y(d,17)^Y(d,19)^d>>>10;oe[l]=w+oe[l-7]+b+oe[l-16]|0}let{A:t,B:r,C:s,D:a,E:o,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){const y=Y(o,6)^Y(o,11)^Y(o,25),d=f+y+jn(o,c,u)+Gn[l]+oe[l]|0,w=(Y(t,2)^Y(t,13)^Y(t,22))+Yn(t,r,s)|0;f=u,u=c,c=o,o=a+d|0,a=s,s=r,r=t,t=d+w|0}t=t+this.A|0,r=r+this.B|0,s=s+this.C|0,a=a+this.D|0,o=o+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(t,r,s,a,o,c,u,f)}roundClean(){Ze(oe)}destroy(){this.set(0,0,0,0,0,0,0,0),Ze(this.buffer)}}class Qn extends Xn{constructor(){super(32);h(this,"A",se[0]|0);h(this,"B",se[1]|0);h(this,"C",se[2]|0);h(this,"D",se[3]|0);h(this,"E",se[4]|0);h(this,"F",se[5]|0);h(this,"G",se[6]|0);h(this,"H",se[7]|0)}}const $e=Pn(()=>new Qn,_n(1));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const et=BigInt(0),tt=BigInt(1);function Mt(i,e=""){if(typeof i!="boolean"){const n=e&&`"${e}" `;throw new Error(n+"expected boolean, got type="+typeof i)}return i}function ei(i){if(typeof i=="bigint"){if(!ii(i))throw new Error("positive bigint expected, got "+i)}else F(i);return i}function Ut(i){if(typeof i!="string")throw new Error("hex string expected, got "+typeof i);return i===""?et:BigInt("0x"+i)}function nt(i){return Ut(C(i))}function Wt(i){return Ut(C(ti(H(i)).reverse()))}function it(i,e){F(e),i=ei(i);const n=Z(i.toString(16).padStart(e*2,"0"));if(n.length!==e)throw new Error("number too large");return n}function Vt(i,e){return it(i,e).reverse()}function ti(i){return Uint8Array.from(i)}function ni(i){return Uint8Array.from(i,(e,n)=>{const t=e.charCodeAt(0);if(e.length!==1||t>127)throw new Error(`string contains non-ASCII character "${i[n]}" with code ${t} at position ${n}`);return t})}const ii=i=>typeof i=="bigint"&&et<=i;function ri(i){let e;for(e=0;i>et;i>>=tt,e+=1);return e}const Dt=i=>(tt<<BigInt(i))-tt;function Ft(i,e={},n={}){if(!i||typeof i!="object")throw new Error("expected valid options object");function t(s,a,o){const c=i[s];if(o&&c===void 0)return;const u=typeof c;if(u!==a||c===null)throw new Error(`param "${s}" is invalid: expected ${a}, got ${u}`)}const r=(s,a)=>Object.entries(s).forEach(([o,c])=>t(o,c,a));r(e,!1),r(n,!0)}function Zt(i){const e=new WeakMap;return(n,...t)=>{const r=e.get(n);if(r!==void 0)return r;const s=i(n,...t);return e.set(n,s),s}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const M=BigInt(0),N=BigInt(1),he=BigInt(2),Kt=BigInt(3),zt=BigInt(4),jt=BigInt(5),si=BigInt(7),Yt=BigInt(8),oi=BigInt(9),Jt=BigInt(16);function K(i,e){const n=i%e;return n>=M?n:e+n}function W(i,e,n){let t=i;for(;e-- >M;)t*=t,t%=n;return t}function Gt(i,e){if(i===M)throw new Error("invert: expected non-zero number");if(e<=M)throw new Error("invert: expected positive modulus, got "+e);let n=K(i,e),t=e,r=M,s=N;for(;n!==M;){const o=t/n,c=t%n,u=r-s*o;t=n,n=c,r=s,s=u}if(t!==N)throw new Error("invert: does not exist");return K(r,e)}function rt(i,e,n){if(!i.eql(i.sqr(e),n))throw new Error("Cannot find square root")}function Xt(i,e){const n=(i.ORDER+N)/zt,t=i.pow(e,n);return rt(i,t,e),t}function ai(i,e){const n=(i.ORDER-jt)/Yt,t=i.mul(e,he),r=i.pow(t,n),s=i.mul(e,r),a=i.mul(i.mul(s,he),r),o=i.mul(s,i.sub(a,i.ONE));return rt(i,o,e),o}function ci(i){const e=He(i),n=Qt(i),t=n(e,e.neg(e.ONE)),r=n(e,t),s=n(e,e.neg(t)),a=(i+si)/Jt;return(o,c)=>{let u=o.pow(c,a),f=o.mul(u,t);const l=o.mul(u,r),y=o.mul(u,s),d=o.eql(o.sqr(f),c),b=o.eql(o.sqr(l),c);u=o.cmov(u,f,d),f=o.cmov(y,l,b);const w=o.eql(o.sqr(f),c),p=o.cmov(u,f,w);return rt(o,p,c),p}}function Qt(i){if(i<Kt)throw new Error("sqrt is not defined for small field");let e=i-N,n=0;for(;e%he===M;)e/=he,n++;let t=he;const r=He(i);for(;tn(r,t)===1;)if(t++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return Xt;let s=r.pow(t,e);const a=(e+N)/he;return function(c,u){if(c.is0(u))return u;if(tn(c,u)!==1)throw new Error("Cannot find square root");let f=n,l=c.mul(c.ONE,s),y=c.pow(u,e),d=c.pow(u,a);for(;!c.eql(y,c.ONE);){if(c.is0(y))return c.ZERO;let b=1,w=c.sqr(y);for(;!c.eql(w,c.ONE);)if(b++,w=c.sqr(w),b===f)throw new Error("Cannot find square root");const p=N<<BigInt(f-b-1),T=c.pow(l,p);f=b,l=c.sqr(T),y=c.mul(y,l),d=c.mul(d,T)}return d}}function li(i){return i%zt===Kt?Xt:i%Yt===jt?ai:i%Jt===oi?ci(i):Qt(i)}const ui=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function hi(i){const e={ORDER:"bigint",BYTES:"number",BITS:"number"},n=ui.reduce((t,r)=>(t[r]="function",t),e);return Ft(i,n),i}function fi(i,e,n){if(n<M)throw new Error("invalid exponent, negatives unsupported");if(n===M)return i.ONE;if(n===N)return e;let t=i.ONE,r=e;for(;n>M;)n&N&&(t=i.mul(t,r)),r=i.sqr(r),n>>=N;return t}function en(i,e,n=!1){const t=new Array(e.length).fill(n?i.ZERO:void 0),r=e.reduce((a,o,c)=>i.is0(o)?a:(t[c]=a,i.mul(a,o)),i.ONE),s=i.inv(r);return e.reduceRight((a,o,c)=>i.is0(o)?a:(t[c]=i.mul(a,t[c]),i.mul(a,o)),s),t}function tn(i,e){const n=(i.ORDER-N)/he,t=i.pow(e,n),r=i.eql(t,i.ONE),s=i.eql(t,i.ZERO),a=i.eql(t,i.neg(i.ONE));if(!r&&!s&&!a)throw new Error("invalid Legendre symbol result");return r?1:s?0:-1}function di(i,e){e!==void 0&&F(e);const n=e!==void 0?e:i.toString(2).length,t=Math.ceil(n/8);return{nBitLength:n,nByteLength:t}}class yi{constructor(e,n={}){h(this,"ORDER");h(this,"BITS");h(this,"BYTES");h(this,"isLE");h(this,"ZERO",M);h(this,"ONE",N);h(this,"_lengths");h(this,"_sqrt");h(this,"_mod");var a;if(e<=M)throw new Error("invalid field: expected ORDER > 0, got "+e);let t;this.isLE=!1,n!=null&&typeof n=="object"&&(typeof n.BITS=="number"&&(t=n.BITS),typeof n.sqrt=="function"&&(this.sqrt=n.sqrt),typeof n.isLE=="boolean"&&(this.isLE=n.isLE),n.allowedLengths&&(this._lengths=(a=n.allowedLengths)==null?void 0:a.slice()),typeof n.modFromBytes=="boolean"&&(this._mod=n.modFromBytes));const{nBitLength:r,nByteLength:s}=di(e,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=r,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return K(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return M<=e&&e<this.ORDER}is0(e){return e===M}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&N)===N}neg(e){return K(-e,this.ORDER)}eql(e,n){return e===n}sqr(e){return K(e*e,this.ORDER)}add(e,n){return K(e+n,this.ORDER)}sub(e,n){return K(e-n,this.ORDER)}mul(e,n){return K(e*n,this.ORDER)}pow(e,n){return fi(this,e,n)}div(e,n){return K(e*Gt(n,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,n){return e+n}subN(e,n){return e-n}mulN(e,n){return e*n}inv(e){return Gt(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=li(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?Vt(e,this.BYTES):it(e,this.BYTES)}fromBytes(e,n=!1){H(e);const{_lengths:t,BYTES:r,isLE:s,ORDER:a,_mod:o}=this;if(t){if(!t.includes(e.length)||e.length>r)throw new Error("Field.fromBytes: expected "+t+" bytes, got "+e.length);const u=new Uint8Array(r);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==r)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+e.length);let c=s?Wt(e):nt(e);if(o&&(c=K(c,a)),!n&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return en(this,e)}cmov(e,n,t){return t?n:e}}function He(i,e={}){return new yi(i,e)}function nn(i){if(typeof i!="bigint")throw new Error("field order must be bigint");const e=i.toString(2).length;return Math.ceil(e/8)}function bi(i){const e=nn(i);return e+Math.ceil(e/2)}function wi(i,e,n=!1){H(i);const t=i.length,r=nn(e),s=bi(e);if(t<16||t<s||t>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+t);const a=n?Wt(i):nt(i),o=K(a,e-N)+N;return n?Vt(o,r):it(o,r)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ge=BigInt(0),fe=BigInt(1);function Le(i,e){const n=e.negate();return i?n:e}function rn(i,e){const n=en(i.Fp,e.map(t=>t.Z));return e.map((t,r)=>i.fromAffine(t.toAffine(n[r])))}function sn(i,e){if(!Number.isSafeInteger(i)||i<=0||i>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+i)}function st(i,e){sn(i,e);const n=Math.ceil(e/i)+1,t=2**(i-1),r=2**i,s=Dt(i),a=BigInt(i);return{windows:n,windowSize:t,mask:s,maxNumber:r,shiftBy:a}}function on(i,e,n){const{windowSize:t,mask:r,maxNumber:s,shiftBy:a}=n;let o=Number(i&r),c=i>>a;o>t&&(o-=s,c+=fe);const u=e*t,f=u+Math.abs(o)-1,l=o===0,y=o<0,d=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:y,isNegF:d,offsetF:u}}const ot=new WeakMap,an=new WeakMap;function at(i){return an.get(i)||1}function cn(i){if(i!==ge)throw new Error("invalid wNAF")}class gi{constructor(e,n){h(this,"BASE");h(this,"ZERO");h(this,"Fn");h(this,"bits");this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=n}_unsafeLadder(e,n,t=this.ZERO){let r=e;for(;n>ge;)n&fe&&(t=t.add(r)),r=r.double(),n>>=fe;return t}precomputeWindow(e,n){const{windows:t,windowSize:r}=st(n,this.bits),s=[];let a=e,o=a;for(let c=0;c<t;c++){o=a,s.push(o);for(let u=1;u<r;u++)o=o.add(a),s.push(o);a=o.double()}return s}wNAF(e,n,t){if(!this.Fn.isValid(t))throw new Error("invalid scalar");let r=this.ZERO,s=this.BASE;const a=st(e,this.bits);for(let o=0;o<a.windows;o++){const{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:y,offsetF:d}=on(t,o,a);t=c,f?s=s.add(Le(y,n[d])):r=r.add(Le(l,n[u]))}return cn(t),{p:r,f:s}}wNAFUnsafe(e,n,t,r=this.ZERO){const s=st(e,this.bits);for(let a=0;a<s.windows&&t!==ge;a++){const{nextN:o,offset:c,isZero:u,isNeg:f}=on(t,a,s);if(t=o,!u){const l=n[c];r=r.add(f?l.negate():l)}}return cn(t),r}getPrecomputes(e,n,t){let r=ot.get(n);return r||(r=this.precomputeWindow(n,e),e!==1&&(typeof t=="function"&&(r=t(r)),ot.set(n,r))),r}cached(e,n,t){const r=at(e);return this.wNAF(r,this.getPrecomputes(r,e,t),n)}unsafe(e,n,t,r){const s=at(e);return s===1?this._unsafeLadder(e,n,r):this.wNAFUnsafe(s,this.getPrecomputes(s,e,t),n,r)}createCache(e,n){sn(n,this.bits),an.set(e,n),ot.delete(e)}hasCache(e){return at(e)!==1}}function pi(i,e,n,t){let r=e,s=i.ZERO,a=i.ZERO;for(;n>ge||t>ge;)n&fe&&(s=s.add(r)),t&fe&&(a=a.add(r)),r=r.double(),n>>=fe,t>>=fe;return{p1:s,p2:a}}function ln(i,e,n){if(e){if(e.ORDER!==i)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return hi(e),e}else return He(i,{isLE:n})}function mi(i,e,n={},t){if(t===void 0&&(t=i==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${i} CURVE object`);for(const c of["p","n","h"]){const u=e[c];if(!(typeof u=="bigint"&&u>ge))throw new Error(`CURVE.${c} must be positive bigint`)}const r=ln(e.p,n.Fp,t),s=ln(e.n,n.Fn,t),o=["Gx","Gy","a","b"];for(const c of o)if(!r.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:r,Fn:s}}function Ei(i,e){return function(t){const r=i(t);return{secretKey:r,publicKey:e(r)}}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const un=(i,e)=>(i+(i>=0?e:-e)/xi)/e;function vi(i,e,n){const[[t,r],[s,a]]=e,o=un(a*i,n),c=un(-r*i,n);let u=i-o*t-c*s,f=-o*r-c*a;const l=u<Se,y=f<Se;l&&(u=-u),y&&(f=-f);const d=Dt(Math.ceil(ri(n)/2))+Ne;if(u<Se||u>=d||f<Se||f>=d)throw new Error("splitScalar (endomorphism): failed, k="+i);return{k1neg:l,k1:u,k2neg:y,k2:f}}const Se=BigInt(0),Ne=BigInt(1),xi=BigInt(2),qe=BigInt(3),Si=BigInt(4);function Ri(i,e={}){const n=mi("weierstrass",i,e),{Fp:t,Fn:r}=n;let s=n.CURVE;const{h:a,n:o}=s;Ft(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:c}=e;if(c&&(!t.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Ai(t,r);function f(){if(!t.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(k,g,m){const{x:v,y:x}=g.toAffine(),P=t.toBytes(v);if(Mt(m,"isCompressed"),m){f();const A=!t.isOdd(x);return Pe(Ti(A),P)}else return Pe(Uint8Array.of(4),P,t.toBytes(x))}function y(k){H(k,void 0,"Point");const{publicKey:g,publicKeyUncompressed:m}=u,v=k.length,x=k[0],P=k.subarray(1);if(v===g&&(x===2||x===3)){const A=t.fromBytes(P);if(!t.isValid(A))throw new Error("bad point: is not on curve, wrong x");const S=w(A);let E;try{E=t.sqrt(S)}catch(D){const L=D instanceof Error?": "+D.message:"";throw new Error("bad point: is not on curve, sqrt error"+L)}f();const R=t.isOdd(E);return(x&1)===1!==R&&(E=t.neg(E)),{x:A,y:E}}else if(v===m&&x===4){const A=t.BYTES,S=t.fromBytes(P.subarray(0,A)),E=t.fromBytes(P.subarray(A,A*2));if(!p(S,E))throw new Error("bad point: is not on curve");return{x:S,y:E}}else throw new Error(`bad point: got length ${v}, expected compressed=${g} or uncompressed=${m}`)}const d=e.toBytes||l,b=e.fromBytes||y;function w(k){const g=t.sqr(k),m=t.mul(g,k);return t.add(t.add(m,t.mul(k,s.a)),s.b)}function p(k,g){const m=t.sqr(g),v=w(k);return t.eql(m,v)}if(!p(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const T=t.mul(t.pow(s.a,qe),Si),I=t.mul(t.sqr(s.b),BigInt(27));if(t.is0(t.add(T,I)))throw new Error("bad curve params: a or b");function U(k,g,m=!1){if(!t.isValid(g)||m&&t.is0(g))throw new Error(`bad point coordinate ${k}`);return g}function ee(k){if(!(k instanceof be))throw new Error("Weierstrass Point expected")}function $(k){if(!c||!c.basises)throw new Error("no endo");return vi(k,c.basises,r.ORDER)}const V=Zt((k,g)=>{const{X:m,Y:v,Z:x}=k;if(t.eql(x,t.ONE))return{x:m,y:v};const P=k.is0();g==null&&(g=P?t.ONE:t.inv(x));const A=t.mul(m,g),S=t.mul(v,g),E=t.mul(x,g);if(P)return{x:t.ZERO,y:t.ZERO};if(!t.eql(E,t.ONE))throw new Error("invZ was invalid");return{x:A,y:S}}),xr=Zt(k=>{if(k.is0()){if(e.allowInfinityPoint&&!t.is0(k.Y))return;throw new Error("bad point: ZERO")}const{x:g,y:m}=k.toAffine();if(!t.isValid(g)||!t.isValid(m))throw new Error("bad point: x or y not field elements");if(!p(g,m))throw new Error("bad point: equation left != right");if(!k.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function Rn(k,g,m,v,x){return m=new be(t.mul(m.X,k),m.Y,m.Z),g=Le(v,g),m=Le(x,m),g.add(m)}const B=class B{constructor(g,m,v){h(this,"X");h(this,"Y");h(this,"Z");this.X=U("x",g),this.Y=U("y",m,!0),this.Z=U("z",v),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){const{x:m,y:v}=g||{};if(!g||!t.isValid(m)||!t.isValid(v))throw new Error("invalid affine point");if(g instanceof B)throw new Error("projective point not allowed");return t.is0(m)&&t.is0(v)?B.ZERO:new B(m,v,t.ONE)}static fromBytes(g){const m=B.fromAffine(b(H(g,void 0,"point")));return m.assertValidity(),m}static fromHex(g){return B.fromBytes(Z(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,m=!0){return ke.createCache(this,g),m||this.multiply(qe),this}assertValidity(){xr(this)}hasEvenY(){const{y:g}=this.toAffine();if(!t.isOdd)throw new Error("Field doesn't support isOdd");return!t.isOdd(g)}equals(g){ee(g);const{X:m,Y:v,Z:x}=this,{X:P,Y:A,Z:S}=g,E=t.eql(t.mul(m,S),t.mul(P,x)),R=t.eql(t.mul(v,S),t.mul(A,x));return E&&R}negate(){return new B(this.X,t.neg(this.Y),this.Z)}double(){const{a:g,b:m}=s,v=t.mul(m,qe),{X:x,Y:P,Z:A}=this;let S=t.ZERO,E=t.ZERO,R=t.ZERO,O=t.mul(x,x),D=t.mul(P,P),L=t.mul(A,A),_=t.mul(x,P);return _=t.add(_,_),R=t.mul(x,A),R=t.add(R,R),S=t.mul(g,R),E=t.mul(v,L),E=t.add(S,E),S=t.sub(D,E),E=t.add(D,E),E=t.mul(S,E),S=t.mul(_,S),R=t.mul(v,R),L=t.mul(g,L),_=t.sub(O,L),_=t.mul(g,_),_=t.add(_,R),R=t.add(O,O),O=t.add(R,O),O=t.add(O,L),O=t.mul(O,_),E=t.add(E,O),L=t.mul(P,A),L=t.add(L,L),O=t.mul(L,_),S=t.sub(S,O),R=t.mul(L,D),R=t.add(R,R),R=t.add(R,R),new B(S,E,R)}add(g){ee(g);const{X:m,Y:v,Z:x}=this,{X:P,Y:A,Z:S}=g;let E=t.ZERO,R=t.ZERO,O=t.ZERO;const D=s.a,L=t.mul(s.b,qe);let _=t.mul(m,P),z=t.mul(v,A),j=t.mul(x,S),Ee=t.add(m,v),q=t.add(P,A);Ee=t.mul(Ee,q),q=t.add(_,z),Ee=t.sub(Ee,q),q=t.add(m,x);let te=t.add(P,S);return q=t.mul(q,te),te=t.add(_,j),q=t.sub(q,te),te=t.add(v,x),E=t.add(A,S),te=t.mul(te,E),E=t.add(z,j),te=t.sub(te,E),O=t.mul(D,q),E=t.mul(L,j),O=t.add(E,O),E=t.sub(z,O),O=t.add(z,O),R=t.mul(E,O),z=t.add(_,_),z=t.add(z,_),j=t.mul(D,j),q=t.mul(L,q),z=t.add(z,j),j=t.sub(_,j),j=t.mul(D,j),q=t.add(q,j),_=t.mul(z,q),R=t.add(R,_),_=t.mul(te,q),E=t.mul(Ee,E),E=t.sub(E,_),_=t.mul(Ee,z),O=t.mul(te,O),O=t.add(O,_),new B(E,R,O)}subtract(g){return this.add(g.negate())}is0(){return this.equals(B.ZERO)}multiply(g){const{endo:m}=e;if(!r.isValidNot0(g))throw new Error("invalid scalar: out of range");let v,x;const P=A=>ke.cached(this,A,S=>rn(B,S));if(m){const{k1neg:A,k1:S,k2neg:E,k2:R}=$(g),{p:O,f:D}=P(S),{p:L,f:_}=P(R);x=D.add(_),v=Rn(m.beta,O,L,A,E)}else{const{p:A,f:S}=P(g);v=A,x=S}return rn(B,[v,x])[0]}multiplyUnsafe(g){const{endo:m}=e,v=this;if(!r.isValid(g))throw new Error("invalid scalar: out of range");if(g===Se||v.is0())return B.ZERO;if(g===Ne)return v;if(ke.hasCache(this))return this.multiply(g);if(m){const{k1neg:x,k1:P,k2neg:A,k2:S}=$(g),{p1:E,p2:R}=pi(B,v,P,S);return Rn(m.beta,E,R,x,A)}else return ke.unsafe(v,g)}toAffine(g){return V(this,g)}isTorsionFree(){const{isTorsionFree:g}=e;return a===Ne?!0:g?g(B,this):ke.unsafe(this,o).is0()}clearCofactor(){const{clearCofactor:g}=e;return a===Ne?this:g?g(B,this):this.multiplyUnsafe(a)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}toBytes(g=!0){return Mt(g,"isCompressed"),this.assertValidity(),d(B,this,g)}toHex(g=!0){return C(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};h(B,"BASE",new B(s.Gx,s.Gy,t.ONE)),h(B,"ZERO",new B(t.ZERO,t.ONE,t.ZERO)),h(B,"Fp",t),h(B,"Fn",r);let be=B;const Tn=r.BITS,ke=new gi(be,e.endo?Math.ceil(Tn/2):Tn);return be.BASE.precompute(8),be}function Ti(i){return Uint8Array.of(i?2:3)}function Ai(i,e){return{secretKey:e.BYTES,publicKey:1+i.BYTES,publicKeyUncompressed:1+2*i.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Me={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Oi={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},ki=BigInt(0),ct=BigInt(2);function Pi(i){const e=Me.p,n=BigInt(3),t=BigInt(6),r=BigInt(11),s=BigInt(22),a=BigInt(23),o=BigInt(44),c=BigInt(88),u=i*i*i%e,f=u*u*i%e,l=W(f,n,e)*f%e,y=W(l,n,e)*f%e,d=W(y,ct,e)*u%e,b=W(d,r,e)*d%e,w=W(b,s,e)*b%e,p=W(w,o,e)*w%e,T=W(p,c,e)*p%e,I=W(T,o,e)*w%e,U=W(I,n,e)*f%e,ee=W(U,a,e)*b%e,$=W(ee,t,e)*u%e,V=W($,ct,e);if(!Ue.eql(Ue.sqr(V),i))throw new Error("Cannot find square root");return V}const Ue=He(Me.p,{sqrt:Pi}),pe=Ri(Me,{Fp:Ue,endo:Oi}),hn={};function We(i,...e){let n=hn[i];if(n===void 0){const t=$e(ni(i));n=Pe(t,t),hn[i]=n}return $e(Pe(n,...e))}const lt=i=>i.toBytes(!0).slice(1),ut=i=>i%ct===ki;function ht(i){const{Fn:e,BASE:n}=pe,t=e.fromBytes(i),r=n.multiply(t);return{scalar:ut(r.y)?t:e.neg(t),bytes:lt(r)}}function fn(i){const e=Ue;if(!e.isValidNot0(i))throw new Error("invalid x: Fail if x ≥ p");const n=e.create(i*i),t=e.create(n*i+BigInt(7));let r=e.sqrt(t);ut(r)||(r=e.neg(r));const s=pe.fromAffine({x:i,y:r});return s.assertValidity(),s}const Re=nt;function dn(...i){return pe.Fn.create(Re(We("BIP0340/challenge",...i)))}function yn(i){return ht(i).bytes}function _i(i,e,n=Rt(32)){const{Fn:t}=pe,r=H(i,void 0,"message"),{bytes:s,scalar:a}=ht(e),o=H(n,32,"auxRand"),c=t.toBytes(a^Re(We("BIP0340/aux",o))),u=We("BIP0340/nonce",c,s,r),{bytes:f,scalar:l}=ht(u),y=dn(f,s,r),d=new Uint8Array(64);if(d.set(f,0),d.set(t.toBytes(t.create(l+y*a)),32),!bn(d,r,s))throw new Error("sign: Invalid signature produced");return d}function bn(i,e,n){const{Fp:t,Fn:r,BASE:s}=pe,a=H(i,64,"signature"),o=H(e,void 0,"message"),c=H(n,32,"publicKey");try{const u=fn(Re(c)),f=Re(a.subarray(0,32));if(!t.isValidNot0(f))return!1;const l=Re(a.subarray(32,64));if(!r.isValidNot0(l))return!1;const y=dn(r.toBytes(f),lt(u),o),d=s.multiplyUnsafe(l).add(u.multiplyUnsafe(r.neg(y))),{x:b,y:w}=d.toAffine();return!(d.is0()||!ut(w)||b!==f)}catch{return!1}}const G=(()=>{const n=(t=Rt(48))=>wi(t,Me.n);return{keygen:Ei(n,yn),getPublicKey:yn,sign:_i,verify:bn,Point:pe,utils:{randomSecretKey:n,taggedHash:We,lift_x:fn,pointToBytes:lt},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),de=Symbol("verified"),Ci=i=>i instanceof Object;function Bi(i){if(!Ci(i)||typeof i.kind!="number"||typeof i.content!="string"||typeof i.created_at!="number"||typeof i.pubkey!="string"||!i.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(i.tags))return!1;for(let e=0;e<i.tags.length;e++){let n=i.tags[e];if(!Array.isArray(n))return!1;for(let t=0;t<n.length;t++)if(typeof n[t]!="string")return!1}return!0}let Ii=class{generateSecretKey(){return G.utils.randomSecretKey()}getPublicKey(e){return C(G.getPublicKey(e))}finalizeEvent(e,n){const t=e;return t.pubkey=C(G.getPublicKey(n)),t.id=ft(t),t.sig=C(G.sign(Z(ft(t)),n)),t[de]=!0,t}verifyEvent(e){if(typeof e[de]=="boolean")return e[de];const n=ft(e);if(n!==e.id)return e[de]=!1,!1;try{const t=G.verify(Z(e.sig),Z(n),Z(e.pubkey));return e[de]=t,t}catch{return e[de]=!1,!1}}};function $i(i){if(!Bi(i))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,i.pubkey,i.created_at,i.kind,i.tags,i.content])}function ft(i){let e=$e(Zn.encode($i(i)));return C(e)}const Ve=new Ii;Ve.generateSecretKey,Ve.getPublicKey,Ve.finalizeEvent;const Hi=Ve.verifyEvent,Li=22242;function Ni(i,e){if(i.ids&&i.ids.indexOf(e.id)===-1||i.kinds&&i.kinds.indexOf(e.kind)===-1||i.authors&&i.authors.indexOf(e.pubkey)===-1)return!1;for(let n in i)if(n[0]==="#"){let t=n.slice(1),r=i[`#${t}`];if(r&&!e.tags.find(([s,a])=>s===n.slice(1)&&r.indexOf(a)!==-1))return!1}return!(i.since&&e.created_at<i.since||i.until&&e.created_at>i.until)}function qi(i,e){for(let n=0;n<i.length;n++)if(Ni(i[n],e))return!0;return!1}function Mi(i,e){let n=e.length+3,t=i.indexOf(`"${e}":`)+n,r=i.slice(t).indexOf('"')+t+1;return i.slice(r,r+64)}function Ui(i){let e=i.slice(0,22).indexOf('"EVENT"');if(e===-1)return null;let n=i.slice(e+7+1).indexOf('"');if(n===-1)return null;let t=e+7+1+n,r=i.slice(t+1,80).indexOf('"');if(r===-1)return null;let s=t+1+r;return i.slice(t+1,s)}function Wi(i,e){return{kind:Li,created_at:Math.floor(Date.now()/1e3),tags:[["relay",i],["challenge",e]],content:""}}let wn=class extends Error{constructor(e,n){super(`Tried to send message '${e} on a closed connection to ${n}.`),this.name="SendingOnClosedConnection"}},Vi=class An{constructor(e,n){h(this,"url");h(this,"_connected",!1);h(this,"onclose",null);h(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));h(this,"onauth");h(this,"baseEoseTimeout",4400);h(this,"publishTimeout",4400);h(this,"pingFrequency",29e3);h(this,"pingTimeout",2e4);h(this,"resubscribeBackoff",[1e4,1e4,1e4,2e4,2e4,3e4,6e4]);h(this,"openSubs",new Map);h(this,"enablePing");h(this,"enableReconnect");h(this,"idleSince",Date.now());h(this,"ongoingOperations",0);h(this,"reconnectTimeoutHandle");h(this,"pingIntervalHandle");h(this,"reconnectAttempts",0);h(this,"skipReconnection",!1);h(this,"connectionPromise");h(this,"openCountRequests",new Map);h(this,"openEventPublishes",new Map);h(this,"ws");h(this,"challenge");h(this,"authPromise");h(this,"serial",0);h(this,"verifyEvent");h(this,"_WebSocket");this.url=J(e),this.verifyEvent=n.verifyEvent,this._WebSocket=n.websocketImplementation||WebSocket,this.enablePing=n.enablePing,this.enableReconnect=n.enableReconnect||!1}static async connect(e,n){const t=new An(e,n);return await t.connect(n),t}closeAllSubscriptions(e){for(let[n,t]of this.openSubs)t.close(e);this.openSubs.clear();for(let[n,t]of this.openEventPublishes)t.reject(new Error(e));this.openEventPublishes.clear();for(let[n,t]of this.openCountRequests)t.reject(new Error(e));this.openCountRequests.clear()}get connected(){return this._connected}async reconnect(){const e=this.resubscribeBackoff[Math.min(this.reconnectAttempts,this.resubscribeBackoff.length-1)];this.reconnectAttempts++,this.reconnectTimeoutHandle=setTimeout(async()=>{try{await this.connect()}catch{}},e)}handleHardClose(e){var n;this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0,this.idleSince=void 0,this.enableReconnect&&!this.skipReconnection?this.reconnect():((n=this.onclose)==null||n.call(this),this.closeAllSubscriptions(e))}async connect(e){let n;return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.authPromise=void 0,this.skipReconnection=!1,this.connectionPromise=new Promise((t,r)=>{e!=null&&e.timeout&&(n=setTimeout(()=>{var s;r("connection timed out"),this.connectionPromise=void 0,this.skipReconnection=!0,(s=this.onclose)==null||s.call(this),this.handleHardClose("relay connection timed out")},e.timeout)),e!=null&&e.abort&&(e.abort.onabort=r);try{this.ws=new this._WebSocket(this.url)}catch(s){clearTimeout(n),r(s);return}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(n),this._connected=!0;const s=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const a of this.openSubs.values()){if(a.eosed=!1,s)for(let o=0;o<a.filters.length;o++)a.lastEmitted&&(a.filters[o].since=a.lastEmitted+1);a.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),t()},this.ws.onerror=()=>{var s;clearTimeout(n),r("connection failed"),this.connectionPromise=void 0,this.skipReconnection=!0,(s=this.onclose)==null||s.call(this),this.handleHardClose("relay connection failed")},this.ws.onclose=s=>{clearTimeout(n),r(s.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}waitForPingPong(){return new Promise(e=>{this.ws.once("pong",()=>e(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((e,n)=>{if(!this.connectionPromise)return n(new Error(`no connection to ${this.url}, can't ping`));try{const t=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"<forced-ping>",oneose:()=>{e(!0),t.close()},onclose(){e(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(t){n(t)}})}async pingpong(){var e,n,t;((e=this.ws)==null?void 0:e.readyState)===1&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.once?this.waitForPingPong():this.waitForDummyReq(),new Promise(s=>setTimeout(()=>s(!1),this.pingTimeout))])||((n=this.ws)==null?void 0:n.readyState)===this._WebSocket.OPEN&&((t=this.ws)==null||t.close()))}async send(e){if(!this.connectionPromise)throw new wn(e,this.url);this.connectionPromise.then(()=>{var n;(n=this.ws)==null||n.send(e)})}async auth(e){const n=this.challenge;if(!n)throw new Error("can't perform auth, no challenge was received");return this.authPromise?this.authPromise:(this.authPromise=new Promise(async(t,r)=>{try{let s=await e(Wi(this.url,n)),a=setTimeout(()=>{let o=this.openEventPublishes.get(s.id);o&&(o.reject(new Error("auth timed out")),this.openEventPublishes.delete(s.id))},this.publishTimeout);this.openEventPublishes.set(s.id,{resolve:t,reject:r,timeout:a}),this.send('["AUTH",'+JSON.stringify(s)+"]")}catch(s){console.warn("subscribe auth function failed:",s)}}),this.authPromise)}async publish(e){this.idleSince=void 0,this.ongoingOperations++;const n=new Promise((t,r)=>{const s=setTimeout(()=>{const a=this.openEventPublishes.get(e.id);a&&(a.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:t,reject:r,timeout:s})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),this.ongoingOperations--,this.ongoingOperations===0&&(this.idleSince=Date.now()),n}async count(e,n){this.serial++;const t=(n==null?void 0:n.id)||"count:"+this.serial,r=new Promise((s,a)=>{this.openCountRequests.set(t,{resolve:s,reject:a})});return this.send('["COUNT","'+t+'",'+JSON.stringify(e).substring(1)),r}subscribe(e,n){n.label!=="<forced-ping>"&&(this.idleSince=void 0,this.ongoingOperations++);const t=this.prepareSubscription(e,n);return t.fire(),n.abort&&(n.abort.onabort=()=>t.close(String(n.abort.reason||"<aborted>"))),t}prepareSubscription(e,n){this.serial++;const t=n.id||(n.label?n.label+":":"sub:")+this.serial,r=new Di(this,t,e,n);return this.openSubs.set(t,r),r}close(){var e,n,t;this.skipReconnection=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,this.idleSince=void 0,(e=this.onclose)==null||e.call(this),((n=this.ws)==null?void 0:n.readyState)===this._WebSocket.OPEN&&((t=this.ws)==null||t.close())}_onmessage(e){var r,s,a;const n=e.data;if(!n)return;const t=Ui(n);if(t){const o=this.openSubs.get(t);if(!o)return;const c=Mi(n,"id"),u=(r=o.alreadyHaveEvent)==null?void 0:r.call(o,c);if((s=o.receivedEvent)==null||s.call(o,this,c),u)return}try{let o=JSON.parse(n);switch(o[0]){case"EVENT":{const c=this.openSubs.get(o[1]),u=o[2];this.verifyEvent(u)&&qi(c.filters,u)&&c.onevent(u),(!c.lastEmitted||c.lastEmitted<u.created_at)&&(c.lastEmitted=u.created_at);return}case"COUNT":{const c=o[1],u=o[2],f=this.openCountRequests.get(c);f&&(f.resolve(u.count),this.openCountRequests.delete(c));return}case"EOSE":{const c=this.openSubs.get(o[1]);if(!c)return;c.receivedEose();return}case"OK":{const c=o[1],u=o[2],f=o[3],l=this.openEventPublishes.get(c);l&&(clearTimeout(l.timeout),u?l.resolve(f):l.reject(new Error(f)),this.openEventPublishes.delete(c));return}case"CLOSED":{const c=o[1],u=this.openSubs.get(c);if(!u)return;u.closed=!0,u.close(o[2]);return}case"NOTICE":{this.onnotice(o[1]);return}case"AUTH":{this.challenge=o[1],this.onauth&&this.auth(this.onauth);return}default:{const c=this.openSubs.get(o[1]);(a=c==null?void 0:c.oncustom)==null||a.call(c,o);return}}}catch(o){const[c,u,f]=JSON.parse(n);window.printer.maybe(f.pubkey,":: caught err",f,this.url,o);return}}},Di=class{constructor(e,n,t,r){h(this,"relay");h(this,"id");h(