ncc-client-poc 0.2.0 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var Et=Object.defineProperty;var St=(e,t,a)=>t in e?Et(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a;var _e=(e,t,a)=>St(e,typeof t!="symbol"?t+"":t,a);import{g as getDefaultExportFromCjs$1,c as commonjsGlobal}from"./vendor-react-KfUPlHYY.js";function _mergeNamespaces(e,t){for(var a=0;a<t.length;a++){const u=t[a];if(typeof u!="string"&&!Array.isArray(u)){for(const d in u)if(d!=="default"&&!(d in e)){const h=Object.getOwnPropertyDescriptor(u,d);h&&Object.defineProperty(e,d,h.get?h:{enumerable:!0,get:()=>u[d]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function number$3(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function bytes$3(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function hash$6(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number$3(e.outputLen),number$3(e.blockLen)}function exists$2(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output$2(e,t){bytes$3(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}const crypto$4=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const u8a$3=e=>e instanceof Uint8Array,createView$2=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),rotr$2=(e,t)=>e<<32-t|e>>>t,isLE$3=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$3)throw new Error("Non little-endian hardware is not supported");function utf8ToBytes$3(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes$2(e){if(typeof e=="string"&&(e=utf8ToBytes$3(e)),!u8a$3(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function concatBytes$3(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a$3(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}let Hash$a=class{clone(){return this._cloneInto()}};function wrapConstructor$2(e){const t=u=>e().update(toBytes$2(u)).digest(),a=e();return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=()=>e(),t}function randomBytes$5(e=32){if(crypto$4&&typeof crypto$4.getRandomValues=="function")return crypto$4.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function setBigUint64$2(e,t,a,u){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,a,u);const d=BigInt(32),h=BigInt(4294967295),w=Number(a>>d&h),x=Number(a&h),M=u?4:0,B=u?0:4;e.setUint32(t+M,w,u),e.setUint32(t+B,x,u)}let SHA2$2=class extends Hash$a{constructor(t,a,u,d){super(),this.blockLen=t,this.outputLen=a,this.padOffset=u,this.isLE=d,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=createView$2(this.buffer)}update(t){exists$2(this);const{view:a,buffer:u,blockLen:d}=this;t=toBytes$2(t);const h=t.length;for(let w=0;w<h;){const x=Math.min(d-this.pos,h-w);if(x===d){const M=createView$2(t);for(;d<=h-w;w+=d)this.process(M,w);continue}u.set(t.subarray(w,w+x),this.pos),this.pos+=x,w+=x,this.pos===d&&(this.process(a,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){exists$2(this),output$2(t,this),this.finished=!0;const{buffer:a,view:u,blockLen:d,isLE:h}=this;let{pos:w}=this;a[w++]=128,this.buffer.subarray(w).fill(0),this.padOffset>d-w&&(this.process(u,0),w=0);for(let S=w;S<d;S++)a[S]=0;setBigUint64$2(u,d-8,BigInt(this.length*8),h),this.process(u,0);const x=createView$2(t),M=this.outputLen;if(M%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const B=M/4,E=this.get();if(B>E.length)throw new Error("_sha2: outputLen bigger than state");for(let S=0;S<B;S++)x.setUint32(4*S,E[S],h)}digest(){const{buffer:t,outputLen:a}=this;this.digestInto(t);const u=t.slice(0,a);return this.destroy(),u}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:a,buffer:u,length:d,finished:h,destroyed:w,pos:x}=this;return t.length=d,t.pos=x,t.finished=h,t.destroyed=w,d%a&&t.buffer.set(u),t}};const Chi$2=(e,t,a)=>e&t^~e&a,Maj$2=(e,t,a)=>e&t^e&a^t&a,SHA256_K$2=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV$2=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W$2=new Uint32Array(64);let SHA256$4=class extends SHA2$2{constructor(){super(64,32,8,!1),this.A=IV$2[0]|0,this.B=IV$2[1]|0,this.C=IV$2[2]|0,this.D=IV$2[3]|0,this.E=IV$2[4]|0,this.F=IV$2[5]|0,this.G=IV$2[6]|0,this.H=IV$2[7]|0}get(){const{A:t,B:a,C:u,D:d,E:h,F:w,G:x,H:M}=this;return[t,a,u,d,h,w,x,M]}set(t,a,u,d,h,w,x,M){this.A=t|0,this.B=a|0,this.C=u|0,this.D=d|0,this.E=h|0,this.F=w|0,this.G=x|0,this.H=M|0}process(t,a){for(let S=0;S<16;S++,a+=4)SHA256_W$2[S]=t.getUint32(a,!1);for(let S=16;S<64;S++){const k=SHA256_W$2[S-15],C=SHA256_W$2[S-2],D=rotr$2(k,7)^rotr$2(k,18)^k>>>3,O=rotr$2(C,17)^rotr$2(C,19)^C>>>10;SHA256_W$2[S]=O+SHA256_W$2[S-7]+D+SHA256_W$2[S-16]|0}let{A:u,B:d,C:h,D:w,E:x,F:M,G:B,H:E}=this;for(let S=0;S<64;S++){const k=rotr$2(x,6)^rotr$2(x,11)^rotr$2(x,25),C=E+k+Chi$2(x,M,B)+SHA256_K$2[S]+SHA256_W$2[S]|0,O=(rotr$2(u,2)^rotr$2(u,13)^rotr$2(u,22))+Maj$2(u,d,h)|0;E=B,B=M,M=x,x=w+C|0,w=h,h=d,d=u,u=C+O|0}u=u+this.A|0,d=d+this.B|0,h=h+this.C|0,w=w+this.D|0,x=x+this.E|0,M=M+this.F|0,B=B+this.G|0,E=E+this.H|0,this.set(u,d,h,w,x,M,B,E)}roundClean(){SHA256_W$2.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const sha256$4=wrapConstructor$2(()=>new SHA256$4);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$5=BigInt(0),_1n$5=BigInt(1),_2n$3=BigInt(2),u8a$2=e=>e instanceof Uint8Array,hexes$3=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex$3(e){if(!u8a$2(e))throw new Error("Uint8Array expected");let t="";for(let a=0;a<e.length;a++)t+=hexes$3[e[a]];return t}function numberToHexUnpadded$1(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function hexToNumber$1(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function hexToBytes$3(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const a=new Uint8Array(t/2);for(let u=0;u<a.length;u++){const d=u*2,h=e.slice(d,d+2),w=Number.parseInt(h,16);if(Number.isNaN(w)||w<0)throw new Error("Invalid byte sequence");a[u]=w}return a}function bytesToNumberBE$1(e){return hexToNumber$1(bytesToHex$3(e))}function bytesToNumberLE$1(e){if(!u8a$2(e))throw new Error("Uint8Array expected");return hexToNumber$1(bytesToHex$3(Uint8Array.from(e).reverse()))}function numberToBytesBE$1(e,t){return hexToBytes$3(e.toString(16).padStart(t*2,"0"))}function numberToBytesLE$1(e,t){return numberToBytesBE$1(e,t).reverse()}function numberToVarBytesBE$1(e){return hexToBytes$3(numberToHexUnpadded$1(e))}function ensureBytes$1(e,t,a){let u;if(typeof t=="string")try{u=hexToBytes$3(t)}catch(h){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${h}`)}else if(u8a$2(t))u=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const d=u.length;if(typeof a=="number"&&d!==a)throw new Error(`${e} expected ${a} bytes, got ${d}`);return u}function concatBytes$2(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a$2(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}function equalBytes$2(e,t){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}function utf8ToBytes$2(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function bitLen$1(e){let t;for(t=0;e>_0n$5;e>>=_1n$5,t+=1);return t}function bitGet$1(e,t){return e>>BigInt(t)&_1n$5}const bitSet$1=(e,t,a)=>e|(a?_1n$5:_0n$5)<<BigInt(t),bitMask$1=e=>(_2n$3<<BigInt(e-1))-_1n$5,u8n$1=e=>new Uint8Array(e),u8fr$1=e=>Uint8Array.from(e);function createHmacDrbg$1(e,t,a){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof a!="function")throw new Error("hmacFn must be a function");let u=u8n$1(e),d=u8n$1(e),h=0;const w=()=>{u.fill(1),d.fill(0),h=0},x=(...S)=>a(d,u,...S),M=(S=u8n$1())=>{d=x(u8fr$1([0]),S),u=x(),S.length!==0&&(d=x(u8fr$1([1]),S),u=x())},B=()=>{if(h++>=1e3)throw new Error("drbg: tried 1000 values");let S=0;const k=[];for(;S<t;){u=x();const C=u.slice();k.push(C),S+=u.length}return concatBytes$2(...k)};return(S,k)=>{w(),M(S);let C;for(;!(C=k(B()));)M();return w(),C}}const validatorFns$1={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function validateObject$1(e,t,a={}){const u=(d,h,w)=>{const x=validatorFns$1[h];if(typeof x!="function")throw new Error(`Invalid validator "${h}", expected function`);const M=e[d];if(!(w&&M===void 0)&&!x(M,e))throw new Error(`Invalid param ${String(d)}=${M} (${typeof M}), expected ${h}`)};for(const[d,h]of Object.entries(t))u(d,h,!1);for(const[d,h]of Object.entries(a))u(d,h,!0);return e}const ut=Object.freeze(Object.defineProperty({__proto__:null,bitGet:bitGet$1,bitLen:bitLen$1,bitMask:bitMask$1,bitSet:bitSet$1,bytesToHex:bytesToHex$3,bytesToNumberBE:bytesToNumberBE$1,bytesToNumberLE:bytesToNumberLE$1,concatBytes:concatBytes$2,createHmacDrbg:createHmacDrbg$1,ensureBytes:ensureBytes$1,equalBytes:equalBytes$2,hexToBytes:hexToBytes$3,hexToNumber:hexToNumber$1,numberToBytesBE:numberToBytesBE$1,numberToBytesLE:numberToBytesLE$1,numberToHexUnpadded:numberToHexUnpadded$1,numberToVarBytesBE:numberToVarBytesBE$1,utf8ToBytes:utf8ToBytes$2,validateObject:validateObject$1},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$4=BigInt(0),_1n$4=BigInt(1),_2n$2=BigInt(2),_3n$2=BigInt(3),_4n$1=BigInt(4),_5n$1=BigInt(5),_8n$1=BigInt(8);BigInt(9);BigInt(16);function mod$1(e,t){const a=e%t;return a>=_0n$4?a:t+a}function pow$3(e,t,a){if(a<=_0n$4||t<_0n$4)throw new Error("Expected power/modulo > 0");if(a===_1n$4)return _0n$4;let u=_1n$4;for(;t>_0n$4;)t&_1n$4&&(u=u*e%a),e=e*e%a,t>>=_1n$4;return u}function pow2$1(e,t,a){let u=e;for(;t-- >_0n$4;)u*=u,u%=a;return u}function invert$1(e,t){if(e===_0n$4||t<=_0n$4)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let a=mod$1(e,t),u=t,d=_0n$4,h=_1n$4;for(;a!==_0n$4;){const x=u/a,M=u%a,B=d-h*x;u=a,a=M,d=h,h=B}if(u!==_1n$4)throw new Error("invert: does not exist");return mod$1(d,t)}function tonelliShanks$1(e){const t=(e-_1n$4)/_2n$2;let a,u,d;for(a=e-_1n$4,u=0;a%_2n$2===_0n$4;a/=_2n$2,u++);for(d=_2n$2;d<e&&pow$3(d,t,e)!==e-_1n$4;d++);if(u===1){const w=(e+_1n$4)/_4n$1;return function(M,B){const E=M.pow(B,w);if(!M.eql(M.sqr(E),B))throw new Error("Cannot find square root");return E}}const h=(a+_1n$4)/_2n$2;return function(x,M){if(x.pow(M,t)===x.neg(x.ONE))throw new Error("Cannot find square root");let B=u,E=x.pow(x.mul(x.ONE,d),a),S=x.pow(M,h),k=x.pow(M,a);for(;!x.eql(k,x.ONE);){if(x.eql(k,x.ZERO))return x.ZERO;let C=1;for(let O=x.sqr(k);C<B&&!x.eql(O,x.ONE);C++)O=x.sqr(O);const D=x.pow(E,_1n$4<<BigInt(B-C-1));E=x.sqr(D),S=x.mul(S,D),k=x.mul(k,E),B=C}return S}}function FpSqrt$1(e){if(e%_4n$1===_3n$2){const t=(e+_1n$4)/_4n$1;return function(u,d){const h=u.pow(d,t);if(!u.eql(u.sqr(h),d))throw new Error("Cannot find square root");return h}}if(e%_8n$1===_5n$1){const t=(e-_5n$1)/_8n$1;return function(u,d){const h=u.mul(d,_2n$2),w=u.pow(h,t),x=u.mul(d,w),M=u.mul(u.mul(x,_2n$2),w),B=u.mul(x,u.sub(M,u.ONE));if(!u.eql(u.sqr(B),d))throw new Error("Cannot find square root");return B}}return tonelliShanks$1(e)}const FIELD_FIELDS$1=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function validateField$1(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},a=FIELD_FIELDS$1.reduce((u,d)=>(u[d]="function",u),t);return validateObject$1(e,a)}function FpPow$1(e,t,a){if(a<_0n$4)throw new Error("Expected power > 0");if(a===_0n$4)return e.ONE;if(a===_1n$4)return t;let u=e.ONE,d=t;for(;a>_0n$4;)a&_1n$4&&(u=e.mul(u,d)),d=e.sqr(d),a>>=_1n$4;return u}function FpInvertBatch$1(e,t){const a=new Array(t.length),u=t.reduce((h,w,x)=>e.is0(w)?h:(a[x]=h,e.mul(h,w)),e.ONE),d=e.inv(u);return t.reduceRight((h,w,x)=>e.is0(w)?h:(a[x]=e.mul(h,a[x]),e.mul(h,w)),d),a}function nLength$1(e,t){const a=t!==void 0?t:e.toString(2).length,u=Math.ceil(a/8);return{nBitLength:a,nByteLength:u}}function Field$1(e,t,a=!1,u={}){if(e<=_0n$4)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:d,nByteLength:h}=nLength$1(e,t);if(h>2048)throw new Error("Field lengths over 2048 bytes are not supported");const w=FpSqrt$1(e),x=Object.freeze({ORDER:e,BITS:d,BYTES:h,MASK:bitMask$1(d),ZERO:_0n$4,ONE:_1n$4,create:M=>mod$1(M,e),isValid:M=>{if(typeof M!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof M}`);return _0n$4<=M&&M<e},is0:M=>M===_0n$4,isOdd:M=>(M&_1n$4)===_1n$4,neg:M=>mod$1(-M,e),eql:(M,B)=>M===B,sqr:M=>mod$1(M*M,e),add:(M,B)=>mod$1(M+B,e),sub:(M,B)=>mod$1(M-B,e),mul:(M,B)=>mod$1(M*B,e),pow:(M,B)=>FpPow$1(x,M,B),div:(M,B)=>mod$1(M*invert$1(B,e),e),sqrN:M=>M*M,addN:(M,B)=>M+B,subN:(M,B)=>M-B,mulN:(M,B)=>M*B,inv:M=>invert$1(M,e),sqrt:u.sqrt||(M=>w(x,M)),invertBatch:M=>FpInvertBatch$1(x,M),cmov:(M,B,E)=>E?B:M,toBytes:M=>a?numberToBytesLE$1(M,h):numberToBytesBE$1(M,h),fromBytes:M=>{if(M.length!==h)throw new Error(`Fp.fromBytes: expected ${h}, got ${M.length}`);return a?bytesToNumberLE$1(M):bytesToNumberBE$1(M)}});return Object.freeze(x)}function getFieldBytesLength$1(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function getMinHashLength$1(e){const t=getFieldBytesLength$1(e);return t+Math.ceil(t/2)}function mapHashToField$1(e,t,a=!1){const u=e.length,d=getFieldBytesLength$1(t),h=getMinHashLength$1(t);if(u<16||u<h||u>1024)throw new Error(`expected ${h}-1024 bytes of input, got ${u}`);const w=a?bytesToNumberBE$1(e):bytesToNumberLE$1(e),x=mod$1(w,t-_1n$4)+_1n$4;return a?numberToBytesLE$1(x,d):numberToBytesBE$1(x,d)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$3=BigInt(0),_1n$3=BigInt(1);function wNAF$1(e,t){const a=(d,h)=>{const w=h.negate();return d?w:h},u=d=>{const h=Math.ceil(t/d)+1,w=2**(d-1);return{windows:h,windowSize:w}};return{constTimeNegate:a,unsafeLadder(d,h){let w=e.ZERO,x=d;for(;h>_0n$3;)h&_1n$3&&(w=w.add(x)),x=x.double(),h>>=_1n$3;return w},precomputeWindow(d,h){const{windows:w,windowSize:x}=u(h),M=[];let B=d,E=B;for(let S=0;S<w;S++){E=B,M.push(E);for(let k=1;k<x;k++)E=E.add(B),M.push(E);B=E.double()}return M},wNAF(d,h,w){const{windows:x,windowSize:M}=u(d);let B=e.ZERO,E=e.BASE;const S=BigInt(2**d-1),k=2**d,C=BigInt(d);for(let D=0;D<x;D++){const O=D*M;let F=Number(w&S);w>>=C,F>M&&(F-=k,w+=_1n$3);const P=O,L=O+Math.abs(F)-1,J=D%2!==0,Y=F<0;F===0?E=E.add(a(J,h[P])):B=B.add(a(Y,h[L]))}return{p:B,f:E}},wNAFCached(d,h,w,x){const M=d._WINDOW_SIZE||1;let B=h.get(d);return B||(B=this.precomputeWindow(d,M),M!==1&&h.set(d,x(B))),this.wNAF(M,B,w)}}}function validateBasic$1(e){return validateField$1(e.Fp),validateObject$1(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...nLength$1(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function validatePointOpts$1(e){const t=validateBasic$1(e);validateObject$1(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:a,Fp:u,a:d}=t;if(a){if(!u.eql(d,u.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof a!="object"||typeof a.beta!="bigint"||typeof a.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:b2n$1,hexToBytes:h2b$1}=ut,DER$1={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=DER$1;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const a=e[1],u=e.subarray(2,a+2);if(!a||u.length!==a)throw new t("Invalid signature integer: wrong length");if(u[0]&128)throw new t("Invalid signature integer: negative");if(u[0]===0&&!(u[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:b2n$1(u),l:e.subarray(a+2)}},toSig(e){const{Err:t}=DER$1,a=typeof e=="string"?h2b$1(e):e;if(!(a instanceof Uint8Array))throw new Error("ui8a expected");let u=a.length;if(u<2||a[0]!=48)throw new t("Invalid signature tag");if(a[1]!==u-2)throw new t("Invalid signature: incorrect length");const{d,l:h}=DER$1._parseInt(a.subarray(2)),{d:w,l:x}=DER$1._parseInt(h);if(x.length)throw new t("Invalid signature: left bytes after parsing");return{r:d,s:w}},hexFromSig(e){const t=B=>Number.parseInt(B[0],16)&8?"00"+B:B,a=B=>{const E=B.toString(16);return E.length&1?`0${E}`:E},u=t(a(e.s)),d=t(a(e.r)),h=u.length/2,w=d.length/2,x=a(h),M=a(w);return`30${a(w+h+4)}02${M}${d}02${x}${u}`}},_0n$2=BigInt(0),_1n$2=BigInt(1);BigInt(2);const _3n$1=BigInt(3);BigInt(4);function weierstrassPoints$1(e){const t=validatePointOpts$1(e),{Fp:a}=t,u=t.toBytes||((D,O,F)=>{const P=O.toAffine();return concatBytes$2(Uint8Array.from([4]),a.toBytes(P.x),a.toBytes(P.y))}),d=t.fromBytes||(D=>{const O=D.subarray(1),F=a.fromBytes(O.subarray(0,a.BYTES)),P=a.fromBytes(O.subarray(a.BYTES,2*a.BYTES));return{x:F,y:P}});function h(D){const{a:O,b:F}=t,P=a.sqr(D),L=a.mul(P,D);return a.add(a.add(L,a.mul(D,O)),F)}if(!a.eql(a.sqr(t.Gy),h(t.Gx)))throw new Error("bad generator point: equation left != right");function w(D){return typeof D=="bigint"&&_0n$2<D&&D<t.n}function x(D){if(!w(D))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function M(D){const{allowedPrivateKeyLengths:O,nByteLength:F,wrapPrivateKey:P,n:L}=t;if(O&&typeof D!="bigint"){if(D instanceof Uint8Array&&(D=bytesToHex$3(D)),typeof D!="string"||!O.includes(D.length))throw new Error("Invalid key");D=D.padStart(F*2,"0")}let J;try{J=typeof D=="bigint"?D:bytesToNumberBE$1(ensureBytes$1("private key",D,F))}catch{throw new Error(`private key must be ${F} bytes, hex or bigint, not ${typeof D}`)}return P&&(J=mod$1(J,L)),x(J),J}const B=new Map;function E(D){if(!(D instanceof S))throw new Error("ProjectivePoint expected")}class S{constructor(O,F,P){if(this.px=O,this.py=F,this.pz=P,O==null||!a.isValid(O))throw new Error("x required");if(F==null||!a.isValid(F))throw new Error("y required");if(P==null||!a.isValid(P))throw new Error("z required")}static fromAffine(O){const{x:F,y:P}=O||{};if(!O||!a.isValid(F)||!a.isValid(P))throw new Error("invalid affine point");if(O instanceof S)throw new Error("projective point not allowed");const L=J=>a.eql(J,a.ZERO);return L(F)&&L(P)?S.ZERO:new S(F,P,a.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(O){const F=a.invertBatch(O.map(P=>P.pz));return O.map((P,L)=>P.toAffine(F[L])).map(S.fromAffine)}static fromHex(O){const F=S.fromAffine(d(ensureBytes$1("pointHex",O)));return F.assertValidity(),F}static fromPrivateKey(O){return S.BASE.multiply(M(O))}_setWindowSize(O){this._WINDOW_SIZE=O,B.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!a.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:O,y:F}=this.toAffine();if(!a.isValid(O)||!a.isValid(F))throw new Error("bad point: x or y not FE");const P=a.sqr(F),L=h(O);if(!a.eql(P,L))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:O}=this.toAffine();if(a.isOdd)return!a.isOdd(O);throw new Error("Field doesn't support isOdd")}equals(O){E(O);const{px:F,py:P,pz:L}=this,{px:J,py:Y,pz:ae}=O,oe=a.eql(a.mul(F,ae),a.mul(J,L)),ue=a.eql(a.mul(P,ae),a.mul(Y,L));return oe&&ue}negate(){return new S(this.px,a.neg(this.py),this.pz)}double(){const{a:O,b:F}=t,P=a.mul(F,_3n$1),{px:L,py:J,pz:Y}=this;let ae=a.ZERO,oe=a.ZERO,ue=a.ZERO,se=a.mul(L,L),ie=a.mul(J,J),ce=a.mul(Y,Y),$=a.mul(L,J);return $=a.add($,$),ue=a.mul(L,Y),ue=a.add(ue,ue),ae=a.mul(O,ue),oe=a.mul(P,ce),oe=a.add(ae,oe),ae=a.sub(ie,oe),oe=a.add(ie,oe),oe=a.mul(ae,oe),ae=a.mul($,ae),ue=a.mul(P,ue),ce=a.mul(O,ce),$=a.sub(se,ce),$=a.mul(O,$),$=a.add($,ue),ue=a.add(se,se),se=a.add(ue,se),se=a.add(se,ce),se=a.mul(se,$),oe=a.add(oe,se),ce=a.mul(J,Y),ce=a.add(ce,ce),se=a.mul(ce,$),ae=a.sub(ae,se),ue=a.mul(ce,ie),ue=a.add(ue,ue),ue=a.add(ue,ue),new S(ae,oe,ue)}add(O){E(O);const{px:F,py:P,pz:L}=this,{px:J,py:Y,pz:ae}=O;let oe=a.ZERO,ue=a.ZERO,se=a.ZERO;const ie=t.a,ce=a.mul(t.b,_3n$1);let $=a.mul(F,J),n=a.mul(P,Y),l=a.mul(L,ae),c=a.add(F,P),p=a.add(J,Y);c=a.mul(c,p),p=a.add($,n),c=a.sub(c,p),p=a.add(F,L);let y=a.add(J,ae);return p=a.mul(p,y),y=a.add($,l),p=a.sub(p,y),y=a.add(P,L),oe=a.add(Y,ae),y=a.mul(y,oe),oe=a.add(n,l),y=a.sub(y,oe),se=a.mul(ie,p),oe=a.mul(ce,l),se=a.add(oe,se),oe=a.sub(n,se),se=a.add(n,se),ue=a.mul(oe,se),n=a.add($,$),n=a.add(n,$),l=a.mul(ie,l),p=a.mul(ce,p),n=a.add(n,l),l=a.sub($,l),l=a.mul(ie,l),p=a.add(p,l),$=a.mul(n,p),ue=a.add(ue,$),$=a.mul(y,p),oe=a.mul(c,oe),oe=a.sub(oe,$),$=a.mul(c,n),se=a.mul(y,se),se=a.add(se,$),new S(oe,ue,se)}subtract(O){return this.add(O.negate())}is0(){return this.equals(S.ZERO)}wNAF(O){return C.wNAFCached(this,B,O,F=>{const P=a.invertBatch(F.map(L=>L.pz));return F.map((L,J)=>L.toAffine(P[J])).map(S.fromAffine)})}multiplyUnsafe(O){const F=S.ZERO;if(O===_0n$2)return F;if(x(O),O===_1n$2)return this;const{endo:P}=t;if(!P)return C.unsafeLadder(this,O);let{k1neg:L,k1:J,k2neg:Y,k2:ae}=P.splitScalar(O),oe=F,ue=F,se=this;for(;J>_0n$2||ae>_0n$2;)J&_1n$2&&(oe=oe.add(se)),ae&_1n$2&&(ue=ue.add(se)),se=se.double(),J>>=_1n$2,ae>>=_1n$2;return L&&(oe=oe.negate()),Y&&(ue=ue.negate()),ue=new S(a.mul(ue.px,P.beta),ue.py,ue.pz),oe.add(ue)}multiply(O){x(O);let F=O,P,L;const{endo:J}=t;if(J){const{k1neg:Y,k1:ae,k2neg:oe,k2:ue}=J.splitScalar(F);let{p:se,f:ie}=this.wNAF(ae),{p:ce,f:$}=this.wNAF(ue);se=C.constTimeNegate(Y,se),ce=C.constTimeNegate(oe,ce),ce=new S(a.mul(ce.px,J.beta),ce.py,ce.pz),P=se.add(ce),L=ie.add($)}else{const{p:Y,f:ae}=this.wNAF(F);P=Y,L=ae}return S.normalizeZ([P,L])[0]}multiplyAndAddUnsafe(O,F,P){const L=S.BASE,J=(ae,oe)=>oe===_0n$2||oe===_1n$2||!ae.equals(L)?ae.multiplyUnsafe(oe):ae.multiply(oe),Y=J(this,F).add(J(O,P));return Y.is0()?void 0:Y}toAffine(O){const{px:F,py:P,pz:L}=this,J=this.is0();O==null&&(O=J?a.ONE:a.inv(L));const Y=a.mul(F,O),ae=a.mul(P,O),oe=a.mul(L,O);if(J)return{x:a.ZERO,y:a.ZERO};if(!a.eql(oe,a.ONE))throw new Error("invZ was invalid");return{x:Y,y:ae}}isTorsionFree(){const{h:O,isTorsionFree:F}=t;if(O===_1n$2)return!0;if(F)return F(S,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:O,clearCofactor:F}=t;return O===_1n$2?this:F?F(S,this):this.multiplyUnsafe(t.h)}toRawBytes(O=!0){return this.assertValidity(),u(S,this,O)}toHex(O=!0){return bytesToHex$3(this.toRawBytes(O))}}S.BASE=new S(t.Gx,t.Gy,a.ONE),S.ZERO=new S(a.ZERO,a.ONE,a.ZERO);const k=t.nBitLength,C=wNAF$1(S,t.endo?Math.ceil(k/2):k);return{CURVE:t,ProjectivePoint:S,normPrivateKeyToScalar:M,weierstrassEquation:h,isWithinCurveOrder:w}}function validateOpts$1(e){const t=validateBasic$1(e);return validateObject$1(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function weierstrass$1(e){const t=validateOpts$1(e),{Fp:a,n:u}=t,d=a.BYTES+1,h=2*a.BYTES+1;function w(p){return _0n$2<p&&p<a.ORDER}function x(p){return mod$1(p,u)}function M(p){return invert$1(p,u)}const{ProjectivePoint:B,normPrivateKeyToScalar:E,weierstrassEquation:S,isWithinCurveOrder:k}=weierstrassPoints$1({...t,toBytes(p,y,b){const _=y.toAffine(),v=a.toBytes(_.x),o=concatBytes$2;return b?o(Uint8Array.from([y.hasEvenY()?2:3]),v):o(Uint8Array.from([4]),v,a.toBytes(_.y))},fromBytes(p){const y=p.length,b=p[0],_=p.subarray(1);if(y===d&&(b===2||b===3)){const v=bytesToNumberBE$1(_);if(!w(v))throw new Error("Point is not on curve");const o=S(v);let m=a.sqrt(o);const A=(m&_1n$2)===_1n$2;return(b&1)===1!==A&&(m=a.neg(m)),{x:v,y:m}}else if(y===h&&b===4){const v=a.fromBytes(_.subarray(0,a.BYTES)),o=a.fromBytes(_.subarray(a.BYTES,2*a.BYTES));return{x:v,y:o}}else throw new Error(`Point of length ${y} was invalid. Expected ${d} compressed bytes or ${h} uncompressed bytes`)}}),C=p=>bytesToHex$3(numberToBytesBE$1(p,t.nByteLength));function D(p){const y=u>>_1n$2;return p>y}function O(p){return D(p)?x(-p):p}const F=(p,y,b)=>bytesToNumberBE$1(p.slice(y,b));class P{constructor(y,b,_){this.r=y,this.s=b,this.recovery=_,this.assertValidity()}static fromCompact(y){const b=t.nByteLength;return y=ensureBytes$1("compactSignature",y,b*2),new P(F(y,0,b),F(y,b,2*b))}static fromDER(y){const{r:b,s:_}=DER$1.toSig(ensureBytes$1("DER",y));return new P(b,_)}assertValidity(){if(!k(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!k(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(y){return new P(this.r,this.s,y)}recoverPublicKey(y){const{r:b,s:_,recovery:v}=this,o=ue(ensureBytes$1("msgHash",y));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");const m=v===2||v===3?b+t.n:b;if(m>=a.ORDER)throw new Error("recovery id 2 or 3 invalid");const A=v&1?"03":"02",I=B.fromHex(A+C(m)),U=M(m),X=x(-o*U),V=x(_*U),T=B.BASE.multiplyAndAddUnsafe(I,X,V);if(!T)throw new Error("point at infinify");return T.assertValidity(),T}hasHighS(){return D(this.s)}normalizeS(){return this.hasHighS()?new P(this.r,x(-this.s),this.recovery):this}toDERRawBytes(){return hexToBytes$3(this.toDERHex())}toDERHex(){return DER$1.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hexToBytes$3(this.toCompactHex())}toCompactHex(){return C(this.r)+C(this.s)}}const L={isValidPrivateKey(p){try{return E(p),!0}catch{return!1}},normPrivateKeyToScalar:E,randomPrivateKey:()=>{const p=getMinHashLength$1(t.n);return mapHashToField$1(t.randomBytes(p),t.n)},precompute(p=8,y=B.BASE){return y._setWindowSize(p),y.multiply(BigInt(3)),y}};function J(p,y=!0){return B.fromPrivateKey(p).toRawBytes(y)}function Y(p){const y=p instanceof Uint8Array,b=typeof p=="string",_=(y||b)&&p.length;return y?_===d||_===h:b?_===2*d||_===2*h:p instanceof B}function ae(p,y,b=!0){if(Y(p))throw new Error("first arg must be private key");if(!Y(y))throw new Error("second arg must be public key");return B.fromHex(y).multiply(E(p)).toRawBytes(b)}const oe=t.bits2int||function(p){const y=bytesToNumberBE$1(p),b=p.length*8-t.nBitLength;return b>0?y>>BigInt(b):y},ue=t.bits2int_modN||function(p){return x(oe(p))},se=bitMask$1(t.nBitLength);function ie(p){if(typeof p!="bigint")throw new Error("bigint expected");if(!(_0n$2<=p&&p<se))throw new Error(`bigint expected < 2^${t.nBitLength}`);return numberToBytesBE$1(p,t.nByteLength)}function ce(p,y,b=$){if(["recovered","canonical"].some(Z=>Z in b))throw new Error("sign() legacy options not supported");const{hash:_,randomBytes:v}=t;let{lowS:o,prehash:m,extraEntropy:A}=b;o==null&&(o=!0),p=ensureBytes$1("msgHash",p),m&&(p=ensureBytes$1("prehashed msgHash",_(p)));const I=ue(p),U=E(y),X=[ie(U),ie(I)];if(A!=null){const Z=A===!0?v(a.BYTES):A;X.push(ensureBytes$1("extraEntropy",Z))}const V=concatBytes$2(...X),T=I;function q(Z){const te=oe(Z);if(!k(te))return;const ee=M(te),j=B.BASE.multiply(te).toAffine(),re=x(j.x);if(re===_0n$2)return;const qe=x(ee*x(T+re*U));if(qe===_0n$2)return;let de=(j.x===re?0:2)|Number(j.y&_1n$2),pe=qe;return o&&D(qe)&&(pe=O(qe),de^=1),new P(re,pe,de)}return{seed:V,k2sig:q}}const $={lowS:t.lowS,prehash:!1},n={lowS:t.lowS,prehash:!1};function l(p,y,b=$){const{seed:_,k2sig:v}=ce(p,y,b),o=t;return createHmacDrbg$1(o.hash.outputLen,o.nByteLength,o.hmac)(_,v)}B.BASE._setWindowSize(8);function c(p,y,b,_=n){var j;const v=p;if(y=ensureBytes$1("msgHash",y),b=ensureBytes$1("publicKey",b),"strict"in _)throw new Error("options.strict was renamed to lowS");const{lowS:o,prehash:m}=_;let A,I;try{if(typeof v=="string"||v instanceof Uint8Array)try{A=P.fromDER(v)}catch(re){if(!(re instanceof DER$1.Err))throw re;A=P.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){const{r:re,s:qe}=v;A=new P(re,qe)}else throw new Error("PARSE");I=B.fromHex(b)}catch(re){if(re.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(o&&A.hasHighS())return!1;m&&(y=t.hash(y));const{r:U,s:X}=A,V=ue(y),T=M(X),q=x(V*T),Z=x(U*T),te=(j=B.BASE.multiplyAndAddUnsafe(I,q,Z))==null?void 0:j.toAffine();return te?x(te.x)===U:!1}return{CURVE:t,getPublicKey:J,getSharedSecret:ae,sign:l,verify:c,ProjectivePoint:B,Signature:P,utils:L}}let HMAC$2=class extends Hash$a{constructor(t,a){super(),this.finished=!1,this.destroyed=!1,hash$6(t);const u=toBytes$2(a);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const d=this.blockLen,h=new Uint8Array(d);h.set(u.length>d?t.create().update(u).digest():u);for(let w=0;w<h.length;w++)h[w]^=54;this.iHash.update(h),this.oHash=t.create();for(let w=0;w<h.length;w++)h[w]^=106;this.oHash.update(h),h.fill(0)}update(t){return exists$2(this),this.iHash.update(t),this}digestInto(t){exists$2(this),bytes$3(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:a,iHash:u,finished:d,destroyed:h,blockLen:w,outputLen:x}=this;return t=t,t.finished=d,t.destroyed=h,t.blockLen=w,t.outputLen=x,t.oHash=a._cloneInto(t.oHash),t.iHash=u._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const hmac$3=(e,t,a)=>new HMAC$2(e,t).update(a).digest();hmac$3.create=(e,t)=>new HMAC$2(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function getHash$1(e){return{hash:e,hmac:(t,...a)=>hmac$3(e,t,concatBytes$3(...a)),randomBytes:randomBytes$5}}function createCurve$1(e,t){const a=u=>weierstrass$1({...e,...getHash$1(u)});return Object.freeze({...a(t),create:a})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const secp256k1P$1=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),secp256k1N$1=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),_1n$1=BigInt(1),_2n$1=BigInt(2),divNearest$1=(e,t)=>(e+t/_2n$1)/t;function sqrtMod$1(e){const t=secp256k1P$1,a=BigInt(3),u=BigInt(6),d=BigInt(11),h=BigInt(22),w=BigInt(23),x=BigInt(44),M=BigInt(88),B=e*e*e%t,E=B*B*e%t,S=pow2$1(E,a,t)*E%t,k=pow2$1(S,a,t)*E%t,C=pow2$1(k,_2n$1,t)*B%t,D=pow2$1(C,d,t)*C%t,O=pow2$1(D,h,t)*D%t,F=pow2$1(O,x,t)*O%t,P=pow2$1(F,M,t)*F%t,L=pow2$1(P,x,t)*O%t,J=pow2$1(L,a,t)*E%t,Y=pow2$1(J,w,t)*D%t,ae=pow2$1(Y,u,t)*B%t,oe=pow2$1(ae,_2n$1,t);if(!Fp$1.eql(Fp$1.sqr(oe),e))throw new Error("Cannot find square root");return oe}const Fp$1=Field$1(secp256k1P$1,void 0,void 0,{sqrt:sqrtMod$1}),secp256k1$2=createCurve$1({a:BigInt(0),b:BigInt(7),Fp:Fp$1,n:secp256k1N$1,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=secp256k1N$1,a=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),u=-_1n$1*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),d=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),h=a,w=BigInt("0x100000000000000000000000000000000"),x=divNearest$1(h*e,t),M=divNearest$1(-u*e,t);let B=mod$1(e-x*a-M*d,t),E=mod$1(-x*u-M*h,t);const S=B>w,k=E>w;if(S&&(B=t-B),k&&(E=t-E),B>w||E>w)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:S,k1:B,k2neg:k,k2:E}}}},sha256$4),_0n$1=BigInt(0),fe$1=e=>typeof e=="bigint"&&_0n$1<e&&e<secp256k1P$1,ge$1=e=>typeof e=="bigint"&&_0n$1<e&&e<secp256k1N$1,TAGGED_HASH_PREFIXES$1={};function taggedHash$1(e,...t){let a=TAGGED_HASH_PREFIXES$1[e];if(a===void 0){const u=sha256$4(Uint8Array.from(e,d=>d.charCodeAt(0)));a=concatBytes$2(u,u),TAGGED_HASH_PREFIXES$1[e]=a}return sha256$4(concatBytes$2(a,...t))}const pointToBytes$1=e=>e.toRawBytes(!0).slice(1),numTo32b$1=e=>numberToBytesBE$1(e,32),modP$1=e=>mod$1(e,secp256k1P$1),modN$1=e=>mod$1(e,secp256k1N$1),Point$4=secp256k1$2.ProjectivePoint,GmulAdd$1=(e,t,a)=>Point$4.BASE.multiplyAndAddUnsafe(e,t,a);function schnorrGetExtPubKey$1(e){let t=secp256k1$2.utils.normPrivateKeyToScalar(e),a=Point$4.fromPrivateKey(t);return{scalar:a.hasEvenY()?t:modN$1(-t),bytes:pointToBytes$1(a)}}function lift_x$1(e){if(!fe$1(e))throw new Error("bad x: need 0 < x < p");const t=modP$1(e*e),a=modP$1(t*e+BigInt(7));let u=sqrtMod$1(a);u%_2n$1!==_0n$1&&(u=modP$1(-u));const d=new Point$4(e,u,_1n$1);return d.assertValidity(),d}function challenge$1(...e){return modN$1(bytesToNumberBE$1(taggedHash$1("BIP0340/challenge",...e)))}function schnorrGetPublicKey$1(e){return schnorrGetExtPubKey$1(e).bytes}function schnorrSign$1(e,t,a=randomBytes$5(32)){const u=ensureBytes$1("message",e),{bytes:d,scalar:h}=schnorrGetExtPubKey$1(t),w=ensureBytes$1("auxRand",a,32),x=numTo32b$1(h^bytesToNumberBE$1(taggedHash$1("BIP0340/aux",w))),M=taggedHash$1("BIP0340/nonce",x,d,u),B=modN$1(bytesToNumberBE$1(M));if(B===_0n$1)throw new Error("sign failed: k is zero");const{bytes:E,scalar:S}=schnorrGetExtPubKey$1(B),k=challenge$1(E,d,u),C=new Uint8Array(64);if(C.set(E,0),C.set(numTo32b$1(modN$1(S+k*h)),32),!schnorrVerify$1(C,u,d))throw new Error("sign: Invalid signature produced");return C}function schnorrVerify$1(e,t,a){const u=ensureBytes$1("signature",e,64),d=ensureBytes$1("message",t),h=ensureBytes$1("publicKey",a,32);try{const w=lift_x$1(bytesToNumberBE$1(h)),x=bytesToNumberBE$1(u.subarray(0,32));if(!fe$1(x))return!1;const M=bytesToNumberBE$1(u.subarray(32,64));if(!ge$1(M))return!1;const B=challenge$1(numTo32b$1(x),pointToBytes$1(w),d),E=GmulAdd$1(w,M,modN$1(-B));return!(!E||!E.hasEvenY()||E.toAffine().x!==x)}catch{return!1}}const schnorr$1={getPublicKey:schnorrGetPublicKey$1,sign:schnorrSign$1,verify:schnorrVerify$1,utils:{randomPrivateKey:secp256k1$2.utils.randomPrivateKey,lift_x:lift_x$1,pointToBytes:pointToBytes$1,numberToBytesBE:numberToBytesBE$1,bytesToNumberBE:bytesToNumberBE$1,taggedHash:taggedHash$1,mod:mod$1}},crypto$3=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const u8a$1=e=>e instanceof Uint8Array,createView$1=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),rotr$1=(e,t)=>e<<32-t|e>>>t,isLE$2=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$2)throw new Error("Non little-endian hardware is not supported");const hexes$2=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex$2(e){if(!u8a$1(e))throw new Error("Uint8Array expected");let t="";for(let a=0;a<e.length;a++)t+=hexes$2[e[a]];return t}function hexToBytes$2(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const a=new Uint8Array(t/2);for(let u=0;u<a.length;u++){const d=u*2,h=e.slice(d,d+2),w=Number.parseInt(h,16);if(Number.isNaN(w)||w<0)throw new Error("Invalid byte sequence");a[u]=w}return a}function utf8ToBytes$1(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes$1(e){if(typeof e=="string"&&(e=utf8ToBytes$1(e)),!u8a$1(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function concatBytes$1(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a$1(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}let Hash$9=class{clone(){return this._cloneInto()}};function wrapConstructor$1(e){const t=u=>e().update(toBytes$1(u)).digest(),a=e();return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=()=>e(),t}function randomBytes$4(e=32){if(crypto$3&&typeof crypto$3.getRandomValues=="function")return crypto$3.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function number$2(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function bool$2(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function bytes$2(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function hash$5(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number$2(e.outputLen),number$2(e.blockLen)}function exists$1(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output$1(e,t){bytes$2(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}const assert$k={number:number$2,bool:bool$2,bytes:bytes$2,hash:hash$5,exists:exists$1,output:output$1};function setBigUint64$1(e,t,a,u){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,a,u);const d=BigInt(32),h=BigInt(4294967295),w=Number(a>>d&h),x=Number(a&h),M=u?4:0,B=u?0:4;e.setUint32(t+M,w,u),e.setUint32(t+B,x,u)}let SHA2$1=class extends Hash$9{constructor(t,a,u,d){super(),this.blockLen=t,this.outputLen=a,this.padOffset=u,this.isLE=d,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=createView$1(this.buffer)}update(t){assert$k.exists(this);const{view:a,buffer:u,blockLen:d}=this;t=toBytes$1(t);const h=t.length;for(let w=0;w<h;){const x=Math.min(d-this.pos,h-w);if(x===d){const M=createView$1(t);for(;d<=h-w;w+=d)this.process(M,w);continue}u.set(t.subarray(w,w+x),this.pos),this.pos+=x,w+=x,this.pos===d&&(this.process(a,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){assert$k.exists(this),assert$k.output(t,this),this.finished=!0;const{buffer:a,view:u,blockLen:d,isLE:h}=this;let{pos:w}=this;a[w++]=128,this.buffer.subarray(w).fill(0),this.padOffset>d-w&&(this.process(u,0),w=0);for(let S=w;S<d;S++)a[S]=0;setBigUint64$1(u,d-8,BigInt(this.length*8),h),this.process(u,0);const x=createView$1(t),M=this.outputLen;if(M%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const B=M/4,E=this.get();if(B>E.length)throw new Error("_sha2: outputLen bigger than state");for(let S=0;S<B;S++)x.setUint32(4*S,E[S],h)}digest(){const{buffer:t,outputLen:a}=this;this.digestInto(t);const u=t.slice(0,a);return this.destroy(),u}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:a,buffer:u,length:d,finished:h,destroyed:w,pos:x}=this;return t.length=d,t.pos=x,t.finished=h,t.destroyed=w,d%a&&t.buffer.set(u),t}};const Chi$1=(e,t,a)=>e&t^~e&a,Maj$1=(e,t,a)=>e&t^e&a^t&a,SHA256_K$1=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV$1=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W$1=new Uint32Array(64);let SHA256$3=class extends SHA2$1{constructor(){super(64,32,8,!1),this.A=IV$1[0]|0,this.B=IV$1[1]|0,this.C=IV$1[2]|0,this.D=IV$1[3]|0,this.E=IV$1[4]|0,this.F=IV$1[5]|0,this.G=IV$1[6]|0,this.H=IV$1[7]|0}get(){const{A:t,B:a,C:u,D:d,E:h,F:w,G:x,H:M}=this;return[t,a,u,d,h,w,x,M]}set(t,a,u,d,h,w,x,M){this.A=t|0,this.B=a|0,this.C=u|0,this.D=d|0,this.E=h|0,this.F=w|0,this.G=x|0,this.H=M|0}process(t,a){for(let S=0;S<16;S++,a+=4)SHA256_W$1[S]=t.getUint32(a,!1);for(let S=16;S<64;S++){const k=SHA256_W$1[S-15],C=SHA256_W$1[S-2],D=rotr$1(k,7)^rotr$1(k,18)^k>>>3,O=rotr$1(C,17)^rotr$1(C,19)^C>>>10;SHA256_W$1[S]=O+SHA256_W$1[S-7]+D+SHA256_W$1[S-16]|0}let{A:u,B:d,C:h,D:w,E:x,F:M,G:B,H:E}=this;for(let S=0;S<64;S++){const k=rotr$1(x,6)^rotr$1(x,11)^rotr$1(x,25),C=E+k+Chi$1(x,M,B)+SHA256_K$1[S]+SHA256_W$1[S]|0,O=(rotr$1(u,2)^rotr$1(u,13)^rotr$1(u,22))+Maj$1(u,d,h)|0;E=B,B=M,M=x,x=w+C|0,w=h,h=d,d=u,u=C+O|0}u=u+this.A|0,d=d+this.B|0,h=h+this.C|0,w=w+this.D|0,x=x+this.E|0,M=M+this.F|0,B=B+this.G|0,E=E+this.H|0,this.set(u,d,h,w,x,M,B,E)}roundClean(){SHA256_W$1.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},SHA224$2=class extends SHA256$3{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const sha256$3=wrapConstructor$1(()=>new SHA256$3);wrapConstructor$1(()=>new SHA224$2);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function assertNumber$1(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function chain$1(...e){const t=(d,h)=>w=>d(h(w)),a=Array.from(e).reverse().reduce((d,h)=>d?t(d,h.encode):h.encode,void 0),u=e.reduce((d,h)=>d?t(d,h.decode):h.decode,void 0);return{encode:a,decode:u}}function alphabet$1(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(a=>{if(assertNumber$1(a),a<0||a>=e.length)throw new Error(`Digit index outside alphabet: ${a} (alphabet: ${e.length})`);return e[a]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(a=>{if(typeof a!="string")throw new Error(`alphabet.decode: not string element=${a}`);const u=e.indexOf(a);if(u===-1)throw new Error(`Unknown letter: "${a}". Allowed: ${e}`);return u})}}}function join$1(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let a of t)if(typeof a!="string")throw new Error(`join.encode: non-string input=${a}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function padding$1(e,t="="){if(assertNumber$1(e),typeof t!="string")throw new Error("padding chr should be string");return{encode(a){if(!Array.isArray(a)||a.length&&typeof a[0]!="string")throw new Error("padding.encode input should be array of strings");for(let u of a)if(typeof u!="string")throw new Error(`padding.encode: non-string input=${u}`);for(;a.length*e%8;)a.push(t);return a},decode(a){if(!Array.isArray(a)||a.length&&typeof a[0]!="string")throw new Error("padding.encode input should be array of strings");for(let d of a)if(typeof d!="string")throw new Error(`padding.decode: non-string input=${d}`);let u=a.length;if(u*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;u>0&&a[u-1]===t;u--)if(!((u-1)*e%8))throw new Error("Invalid padding: string has too much padding");return a.slice(0,u)}}}function normalize$1(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function convertRadix$1(e,t,a){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(a<2)throw new Error(`convertRadix: wrong to=${a}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let u=0;const d=[],h=Array.from(e);for(h.forEach(w=>{if(assertNumber$1(w),w<0||w>=t)throw new Error(`Wrong integer: ${w}`)});;){let w=0,x=!0;for(let M=u;M<h.length;M++){const B=h[M],E=t*w+B;if(!Number.isSafeInteger(E)||t*w/t!==w||E-B!==t*w)throw new Error("convertRadix: carry overflow");if(w=E%a,h[M]=Math.floor(E/a),!Number.isSafeInteger(h[M])||h[M]*a+w!==E)throw new Error("convertRadix: carry overflow");if(x)h[M]?x=!1:u=M;else continue}if(d.push(w),x)break}for(let w=0;w<e.length-1&&e[w]===0;w++)d.push(0);return d.reverse()}const gcd$1=(e,t)=>t?gcd$1(t,e%t):e,radix2carry$1=(e,t)=>e+(t-gcd$1(e,t));function convertRadix2$1(e,t,a,u){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(a<=0||a>32)throw new Error(`convertRadix2: wrong to=${a}`);if(radix2carry$1(t,a)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${a} carryBits=${radix2carry$1(t,a)}`);let d=0,h=0;const w=2**a-1,x=[];for(const M of e){if(assertNumber$1(M),M>=2**t)throw new Error(`convertRadix2: invalid data word=${M} from=${t}`);if(d=d<<t|M,h+t>32)throw new Error(`convertRadix2: carry overflow pos=${h} from=${t}`);for(h+=t;h>=a;h-=a)x.push((d>>h-a&w)>>>0);d&=2**h-1}if(d=d<<a-h&w,!u&&h>=t)throw new Error("Excess padding");if(!u&&d)throw new Error(`Non-zero padding: ${d}`);return u&&h>0&&x.push(d>>>0),x}function radix$1(e){return assertNumber$1(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return convertRadix$1(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(convertRadix$1(t,e,2**8))}}}function radix2$1(e,t=!1){if(assertNumber$1(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(radix2carry$1(8,e)>32||radix2carry$1(e,8)>32)throw new Error("radix2: carry overflow");return{encode:a=>{if(!(a instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return convertRadix2$1(Array.from(a),8,e,!t)},decode:a=>{if(!Array.isArray(a)||a.length&&typeof a[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(convertRadix2$1(a,e,8,t))}}}function unsafeWrapper$1(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const base16$1=chain$1(radix2$1(4),alphabet$1("0123456789ABCDEF"),join$1("")),base32$1=chain$1(radix2$1(5),alphabet$1("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),padding$1(5),join$1(""));chain$1(radix2$1(5),alphabet$1("0123456789ABCDEFGHIJKLMNOPQRSTUV"),padding$1(5),join$1(""));chain$1(radix2$1(5),alphabet$1("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),join$1(""),normalize$1(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const base64$1=chain$1(radix2$1(6),alphabet$1("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),padding$1(6),join$1("")),base64url$1=chain$1(radix2$1(6),alphabet$1("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),padding$1(6),join$1("")),genBase58$1=e=>chain$1(radix$1(58),alphabet$1(e),join$1("")),base58$1=genBase58$1("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");genBase58$1("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");genBase58$1("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const XMR_BLOCK_LEN$1=[0,2,3,5,6,7,9,10,11],base58xmr$1={encode(e){let t="";for(let a=0;a<e.length;a+=8){const u=e.subarray(a,a+8);t+=base58$1.encode(u).padStart(XMR_BLOCK_LEN$1[u.length],"1")}return t},decode(e){let t=[];for(let a=0;a<e.length;a+=11){const u=e.slice(a,a+11),d=XMR_BLOCK_LEN$1.indexOf(u.length),h=base58$1.decode(u);for(let w=0;w<h.length-d;w++)if(h[w]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(h.slice(h.length-d)))}return Uint8Array.from(t)}},BECH_ALPHABET$1=chain$1(alphabet$1("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),join$1("")),POLYMOD_GENERATORS$1=[996825010,642813549,513874426,1027748829,705979059];function bech32Polymod$1(e){const t=e>>25;let a=(e&33554431)<<5;for(let u=0;u<POLYMOD_GENERATORS$1.length;u++)(t>>u&1)===1&&(a^=POLYMOD_GENERATORS$1[u]);return a}function bechChecksum$1(e,t,a=1){const u=e.length;let d=1;for(let h=0;h<u;h++){const w=e.charCodeAt(h);if(w<33||w>126)throw new Error(`Invalid prefix (${e})`);d=bech32Polymod$1(d)^w>>5}d=bech32Polymod$1(d);for(let h=0;h<u;h++)d=bech32Polymod$1(d)^e.charCodeAt(h)&31;for(let h of t)d=bech32Polymod$1(d)^h;for(let h=0;h<6;h++)d=bech32Polymod$1(d);return d^=a,BECH_ALPHABET$1.encode(convertRadix2$1([d%2**30],30,5,!1))}function genBech32$1(e){const t=e==="bech32"?1:734539939,a=radix2$1(5),u=a.decode,d=a.encode,h=unsafeWrapper$1(u);function w(E,S,k=90){if(typeof E!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof E}`);if(!Array.isArray(S)||S.length&&typeof S[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof S}`);const C=E.length+7+S.length;if(k!==!1&&C>k)throw new TypeError(`Length ${C} exceeds limit ${k}`);return E=E.toLowerCase(),`${E}1${BECH_ALPHABET$1.encode(S)}${bechChecksum$1(E,S,t)}`}function x(E,S=90){if(typeof E!="string")throw new Error(`bech32.decode input should be string, not ${typeof E}`);if(E.length<8||S!==!1&&E.length>S)throw new TypeError(`Wrong string length: ${E.length} (${E}). Expected (8..${S})`);const k=E.toLowerCase();if(E!==k&&E!==E.toUpperCase())throw new Error("String must be lowercase or uppercase");E=k;const C=E.lastIndexOf("1");if(C===0||C===-1)throw new Error('Letter "1" must be present between prefix and data only');const D=E.slice(0,C),O=E.slice(C+1);if(O.length<6)throw new Error("Data must be at least 6 characters long");const F=BECH_ALPHABET$1.decode(O).slice(0,-6),P=bechChecksum$1(D,F,t);if(!O.endsWith(P))throw new Error(`Invalid checksum in ${E}: expected "${P}"`);return{prefix:D,words:F}}const M=unsafeWrapper$1(x);function B(E){const{prefix:S,words:k}=x(E,!1);return{prefix:S,words:k,bytes:u(k)}}return{encode:w,decode:x,decodeToBytes:B,decodeUnsafe:M,fromWords:u,fromWordsUnsafe:h,toWords:d}}const bech32$1=genBech32$1("bech32");genBech32$1("bech32m");const utf8$1={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},hex$1=chain$1(radix2$1(4),alphabet$1("0123456789abcdef"),join$1(""),normalize$1(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})),CODERS$1={utf8:utf8$1,hex:hex$1,base16:base16$1,base32:base32$1,base64:base64$1,base64url:base64url$1,base58:base58$1,base58xmr:base58xmr$1};`${Object.keys(CODERS$1).join(", ")}`;function number$1(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function bool$1(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function isBytes$1(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function bytes$1(e,...t){if(!isBytes$1(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */const u32$1=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),isLE$1=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$1)throw new Error("Non little-endian hardware is not supported");const hexes$1=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex$1(e){bytes$1(e);let t="";for(let a=0;a<e.length;a++)t+=hexes$1[e[a]];return t}const asciis$1={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function asciiToBase16$1(e){if(e>=asciis$1._0&&e<=asciis$1._9)return e-asciis$1._0;if(e>=asciis$1._A&&e<=asciis$1._F)return e-(asciis$1._A-10);if(e>=asciis$1._a&&e<=asciis$1._f)return e-(asciis$1._a-10)}function hexToBytes$1(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length,a=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const u=new Uint8Array(a);for(let d=0,h=0;d<a;d++,h+=2){const w=asciiToBase16$1(e.charCodeAt(h)),x=asciiToBase16$1(e.charCodeAt(h+1));if(w===void 0||x===void 0){const M=e[h]+e[h+1];throw new Error('hex string expected, got non-hex character "'+M+'" at index '+h)}u[d]=w*16+x}return u}function checkOpts$1(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function equalBytes$1(e,t){if(e.length!==t.length)return!1;let a=0;for(let u=0;u<e.length;u++)a|=e[u]^t[u];return a===0}const wrapCipher$1=(e,t)=>(Object.assign(t,e),t),BLOCK_SIZE$1=16,POLY$1=283;function mul2$1(e){return e<<1^POLY$1&-(e>>7)}function mul$1(e,t){let a=0;for(;t>0;t>>=1)a^=e&-(t&1),e=mul2$1(e);return a}const sbox$1=(()=>{let e=new Uint8Array(256);for(let a=0,u=1;a<256;a++,u^=mul2$1(u))e[a]=u;const t=new Uint8Array(256);t[0]=99;for(let a=0;a<255;a++){let u=e[255-a];u|=u<<8,t[e[a]]=(u^u>>4^u>>5^u>>6^u>>7^99)&255}return t})(),invSbox$1=sbox$1.map((e,t)=>sbox$1.indexOf(t)),rotr32_8$1=e=>e<<24|e>>>8,rotl32_8$1=e=>e<<8|e>>>24;function genTtable$1(e,t){if(e.length!==256)throw new Error("Wrong sbox length");const a=new Uint32Array(256).map((B,E)=>t(e[E])),u=a.map(rotl32_8$1),d=u.map(rotl32_8$1),h=d.map(rotl32_8$1),w=new Uint32Array(256*256),x=new Uint32Array(256*256),M=new Uint16Array(256*256);for(let B=0;B<256;B++)for(let E=0;E<256;E++){const S=B*256+E;w[S]=a[B]^u[E],x[S]=d[B]^h[E],M[S]=e[B]<<8|e[E]}return{sbox:e,sbox2:M,T0:a,T1:u,T2:d,T3:h,T01:w,T23:x}}const tableEncoding$1=genTtable$1(sbox$1,e=>mul$1(e,3)<<24|e<<16|e<<8|mul$1(e,2)),tableDecoding$1=genTtable$1(invSbox$1,e=>mul$1(e,11)<<24|mul$1(e,13)<<16|mul$1(e,9)<<8|mul$1(e,14)),xPowers$1=(()=>{const e=new Uint8Array(16);for(let t=0,a=1;t<16;t++,a=mul2$1(a))e[t]=a;return e})();function expandKeyLE$1(e){bytes$1(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:a}=tableEncoding$1,u=u32$1(e),d=u.length,h=x=>applySbox$1(a,x,x,x,x),w=new Uint32Array(t+28);w.set(u);for(let x=d;x<w.length;x++){let M=w[x-1];x%d===0?M=h(rotr32_8$1(M))^xPowers$1[x/d-1]:d>6&&x%d===4&&(M=h(M)),w[x]=w[x-d]^M}return w}function expandKeyDecLE$1(e){const t=expandKeyLE$1(e),a=t.slice(),u=t.length,{sbox2:d}=tableEncoding$1,{T0:h,T1:w,T2:x,T3:M}=tableDecoding$1;for(let B=0;B<u;B+=4)for(let E=0;E<4;E++)a[B+E]=t[u-B-4+E];t.fill(0);for(let B=4;B<u-4;B++){const E=a[B],S=applySbox$1(d,E,E,E,E);a[B]=h[S&255]^w[S>>>8&255]^x[S>>>16&255]^M[S>>>24]}return a}function apply0123$1(e,t,a,u,d,h){return e[a<<8&65280|u>>>8&255]^t[d>>>8&65280|h>>>24&255]}function applySbox$1(e,t,a,u,d){return e[t&255|a&65280]|e[u>>>16&255|d>>>16&65280]<<16}function encrypt$2(e,t,a,u,d){const{sbox2:h,T01:w,T23:x}=tableEncoding$1;let M=0;t^=e[M++],a^=e[M++],u^=e[M++],d^=e[M++];const B=e.length/4-2;for(let D=0;D<B;D++){const O=e[M++]^apply0123$1(w,x,t,a,u,d),F=e[M++]^apply0123$1(w,x,a,u,d,t),P=e[M++]^apply0123$1(w,x,u,d,t,a),L=e[M++]^apply0123$1(w,x,d,t,a,u);t=O,a=F,u=P,d=L}const E=e[M++]^applySbox$1(h,t,a,u,d),S=e[M++]^applySbox$1(h,a,u,d,t),k=e[M++]^applySbox$1(h,u,d,t,a),C=e[M++]^applySbox$1(h,d,t,a,u);return{s0:E,s1:S,s2:k,s3:C}}function decrypt$3(e,t,a,u,d){const{sbox2:h,T01:w,T23:x}=tableDecoding$1;let M=0;t^=e[M++],a^=e[M++],u^=e[M++],d^=e[M++];const B=e.length/4-2;for(let D=0;D<B;D++){const O=e[M++]^apply0123$1(w,x,t,d,u,a),F=e[M++]^apply0123$1(w,x,a,t,d,u),P=e[M++]^apply0123$1(w,x,u,a,t,d),L=e[M++]^apply0123$1(w,x,d,u,a,t);t=O,a=F,u=P,d=L}const E=e[M++]^applySbox$1(h,t,d,u,a),S=e[M++]^applySbox$1(h,a,t,d,u),k=e[M++]^applySbox$1(h,u,a,t,d),C=e[M++]^applySbox$1(h,d,u,a,t);return{s0:E,s1:S,s2:k,s3:C}}function getDst$1(e,t){if(!t)return new Uint8Array(e);if(bytes$1(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function validateBlockDecrypt$1(e){if(bytes$1(e),e.length%BLOCK_SIZE$1!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${BLOCK_SIZE$1}`)}function validateBlockEncrypt$1(e,t,a){let u=e.length;const d=u%BLOCK_SIZE$1;if(!t&&d!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const h=u32$1(e);if(t){let M=BLOCK_SIZE$1-d;M||(M=BLOCK_SIZE$1),u=u+M}const w=getDst$1(u,a),x=u32$1(w);return{b:h,o:x,out:w}}function validatePCKS$1(e,t){if(!t)return e;const a=e.length;if(!a)throw new Error("aes/pcks5: empty ciphertext not allowed");const u=e[a-1];if(u<=0||u>16)throw new Error(`aes/pcks5: wrong padding byte: ${u}`);const d=e.subarray(0,-u);for(let h=0;h<u;h++)if(e[a-h-1]!==u)throw new Error("aes/pcks5: wrong padding");return d}function padPCKS$1(e){const t=new Uint8Array(16),a=u32$1(t);t.set(e);const u=BLOCK_SIZE$1-e.length;for(let d=BLOCK_SIZE$1-u;d<BLOCK_SIZE$1;d++)t[d]=u;return a}const cbc$3=wrapCipher$1({blockSize:16,nonceLength:16},function(t,a,u={}){bytes$1(t),bytes$1(a,16);const d=!u.disablePadding;return{encrypt:(h,w)=>{const x=expandKeyLE$1(t),{b:M,o:B,out:E}=validateBlockEncrypt$1(h,d,w),S=u32$1(a);let k=S[0],C=S[1],D=S[2],O=S[3],F=0;for(;F+4<=M.length;)k^=M[F+0],C^=M[F+1],D^=M[F+2],O^=M[F+3],{s0:k,s1:C,s2:D,s3:O}=encrypt$2(x,k,C,D,O),B[F++]=k,B[F++]=C,B[F++]=D,B[F++]=O;if(d){const P=padPCKS$1(h.subarray(F*4));k^=P[0],C^=P[1],D^=P[2],O^=P[3],{s0:k,s1:C,s2:D,s3:O}=encrypt$2(x,k,C,D,O),B[F++]=k,B[F++]=C,B[F++]=D,B[F++]=O}return x.fill(0),E},decrypt:(h,w)=>{validateBlockDecrypt$1(h);const x=expandKeyDecLE$1(t),M=u32$1(a),B=getDst$1(h.length,w),E=u32$1(h),S=u32$1(B);let k=M[0],C=M[1],D=M[2],O=M[3];for(let F=0;F+4<=E.length;){const P=k,L=C,J=D,Y=O;k=E[F+0],C=E[F+1],D=E[F+2],O=E[F+3];const{s0:ae,s1:oe,s2:ue,s3:se}=decrypt$3(x,k,C,D,O);S[F++]=ae^P,S[F++]=oe^L,S[F++]=ue^J,S[F++]=se^Y}return x.fill(0),validatePCKS$1(B,d)}}}),_utf8ToBytes$1=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),sigma16$1=_utf8ToBytes$1("expand 16-byte k"),sigma32$1=_utf8ToBytes$1("expand 32-byte k"),sigma16_32$1=u32$1(sigma16$1),sigma32_32$1=u32$1(sigma32$1);sigma32_32$1.slice();function rotl$3(e,t){return e<<t|e>>>32-t}function isAligned32$1(e){return e.byteOffset%4===0}const BLOCK_LEN$1=64,BLOCK_LEN32$1=16,MAX_COUNTER$1=2**32-1,U32_EMPTY$1=new Uint32Array;function runCipher$1(e,t,a,u,d,h,w,x){const M=d.length,B=new Uint8Array(BLOCK_LEN$1),E=u32$1(B),S=isAligned32$1(d)&&isAligned32$1(h),k=S?u32$1(d):U32_EMPTY$1,C=S?u32$1(h):U32_EMPTY$1;for(let D=0;D<M;w++){if(e(t,a,u,E,w,x),w>=MAX_COUNTER$1)throw new Error("arx: counter overflow");const O=Math.min(BLOCK_LEN$1,M-D);if(S&&O===BLOCK_LEN$1){const F=D/4;if(D%4!==0)throw new Error("arx: invalid block position");for(let P=0,L;P<BLOCK_LEN32$1;P++)L=F+P,C[L]=k[L]^E[P];D+=BLOCK_LEN$1;continue}for(let F=0,P;F<O;F++)P=D+F,h[P]=d[P]^B[F];D+=O}}function createCipher$3(e,t){const{allowShortKeys:a,extendNonceFn:u,counterLength:d,counterRight:h,rounds:w}=checkOpts$1({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return number$1(d),number$1(w),bool$1(h),bool$1(a),(x,M,B,E,S=0)=>{bytes$1(x),bytes$1(M),bytes$1(B);const k=B.length;if(E||(E=new Uint8Array(k)),bytes$1(E),number$1(S),S<0||S>=MAX_COUNTER$1)throw new Error("arx: counter overflow");if(E.length<k)throw new Error(`arx: output (${E.length}) is shorter than data (${k})`);const C=[];let D=x.length,O,F;if(D===32)O=x.slice(),C.push(O),F=sigma32_32$1;else if(D===16&&a)O=new Uint8Array(32),O.set(x),O.set(x,16),F=sigma16_32$1,C.push(O);else throw new Error(`arx: invalid 32-byte key, got length=${D}`);isAligned32$1(M)||(M=M.slice(),C.push(M));const P=u32$1(O);if(u){if(M.length!==24)throw new Error("arx: extended nonce must be 24 bytes");u(F,P,u32$1(M.subarray(0,16)),P),M=M.subarray(16)}const L=16-d;if(L!==M.length)throw new Error(`arx: nonce must be ${L} or 16 bytes`);if(L!==12){const Y=new Uint8Array(12);Y.set(M,h?0:12-M.length),M=Y,C.push(M)}const J=u32$1(M);for(runCipher$1(e,F,P,J,B,E,S,w);C.length>0;)C.pop().fill(0);return E}}function chachaCore$1(e,t,a,u,d,h=20){let w=e[0],x=e[1],M=e[2],B=e[3],E=t[0],S=t[1],k=t[2],C=t[3],D=t[4],O=t[5],F=t[6],P=t[7],L=d,J=a[0],Y=a[1],ae=a[2],oe=w,ue=x,se=M,ie=B,ce=E,$=S,n=k,l=C,c=D,p=O,y=F,b=P,_=L,v=J,o=Y,m=ae;for(let I=0;I<h;I+=2)oe=oe+ce|0,_=rotl$3(_^oe,16),c=c+_|0,ce=rotl$3(ce^c,12),oe=oe+ce|0,_=rotl$3(_^oe,8),c=c+_|0,ce=rotl$3(ce^c,7),ue=ue+$|0,v=rotl$3(v^ue,16),p=p+v|0,$=rotl$3($^p,12),ue=ue+$|0,v=rotl$3(v^ue,8),p=p+v|0,$=rotl$3($^p,7),se=se+n|0,o=rotl$3(o^se,16),y=y+o|0,n=rotl$3(n^y,12),se=se+n|0,o=rotl$3(o^se,8),y=y+o|0,n=rotl$3(n^y,7),ie=ie+l|0,m=rotl$3(m^ie,16),b=b+m|0,l=rotl$3(l^b,12),ie=ie+l|0,m=rotl$3(m^ie,8),b=b+m|0,l=rotl$3(l^b,7),oe=oe+$|0,m=rotl$3(m^oe,16),y=y+m|0,$=rotl$3($^y,12),oe=oe+$|0,m=rotl$3(m^oe,8),y=y+m|0,$=rotl$3($^y,7),ue=ue+n|0,_=rotl$3(_^ue,16),b=b+_|0,n=rotl$3(n^b,12),ue=ue+n|0,_=rotl$3(_^ue,8),b=b+_|0,n=rotl$3(n^b,7),se=se+l|0,v=rotl$3(v^se,16),c=c+v|0,l=rotl$3(l^c,12),se=se+l|0,v=rotl$3(v^se,8),c=c+v|0,l=rotl$3(l^c,7),ie=ie+ce|0,o=rotl$3(o^ie,16),p=p+o|0,ce=rotl$3(ce^p,12),ie=ie+ce|0,o=rotl$3(o^ie,8),p=p+o|0,ce=rotl$3(ce^p,7);let A=0;u[A++]=w+oe|0,u[A++]=x+ue|0,u[A++]=M+se|0,u[A++]=B+ie|0,u[A++]=E+ce|0,u[A++]=S+$|0,u[A++]=k+n|0,u[A++]=C+l|0,u[A++]=D+c|0,u[A++]=O+p|0,u[A++]=F+y|0,u[A++]=P+b|0,u[A++]=L+_|0,u[A++]=J+v|0,u[A++]=Y+o|0,u[A++]=ae+m|0}const chacha20$1=createCipher$3(chachaCore$1,{counterRight:!1,counterLength:4,allowShortKeys:!1});let HMAC$1=class extends Hash$9{constructor(t,a){super(),this.finished=!1,this.destroyed=!1,assert$k.hash(t);const u=toBytes$1(a);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const d=this.blockLen,h=new Uint8Array(d);h.set(u.length>d?t.create().update(u).digest():u);for(let w=0;w<h.length;w++)h[w]^=54;this.iHash.update(h),this.oHash=t.create();for(let w=0;w<h.length;w++)h[w]^=106;this.oHash.update(h),h.fill(0)}update(t){return assert$k.exists(this),this.iHash.update(t),this}digestInto(t){assert$k.exists(this),assert$k.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:a,iHash:u,finished:d,destroyed:h,blockLen:w,outputLen:x}=this;return t=t,t.finished=d,t.destroyed=h,t.blockLen=w,t.outputLen=x,t.oHash=a._cloneInto(t.oHash),t.iHash=u._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const hmac$2=(e,t,a)=>new HMAC$1(e,t).update(a).digest();hmac$2.create=(e,t)=>new HMAC$1(e,t);function extract$1(e,t,a){return assert$k.hash(e),hmac$2(e,toBytes$1(a),toBytes$1(t))}const HKDF_COUNTER$1=new Uint8Array([0]),EMPTY_BUFFER$1=new Uint8Array;function expand$1(e,t,a,u=32){if(assert$k.hash(e),assert$k.number(u),u>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const d=Math.ceil(u/e.outputLen);a===void 0&&(a=EMPTY_BUFFER$1);const h=new Uint8Array(d*e.outputLen),w=hmac$2.create(e,t),x=w._cloneInto(),M=new Uint8Array(w.outputLen);for(let B=0;B<d;B++)HKDF_COUNTER$1[0]=B+1,x.update(B===0?EMPTY_BUFFER$1:M).update(a).update(HKDF_COUNTER$1).digestInto(M),h.set(M,e.outputLen*B),w._cloneInto(x);return w.destroy(),x.destroy(),M.fill(0),HKDF_COUNTER$1.fill(0),h.slice(0,u)}var __defProp$1=Object.defineProperty,__export$1=(e,t)=>{for(var a in t)__defProp$1(e,a,{get:t[a],enumerable:!0})},verifiedSymbol$1=Symbol("verified"),isRecord$1=e=>e instanceof Object;function validateEvent$1(e){if(!isRecord$1(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let a=e.tags[t];if(!Array.isArray(a))return!1;for(let u=0;u<a.length;u++)if(typeof a[u]!="string")return!1}return!0}var utils_exports$1={};__export$1(utils_exports$1,{Queue:()=>Queue$1,QueueNode:()=>QueueNode$1,binarySearch:()=>binarySearch$1,bytesToHex:()=>bytesToHex$2,hexToBytes:()=>hexToBytes$2,insertEventIntoAscendingList:()=>insertEventIntoAscendingList$1,insertEventIntoDescendingList:()=>insertEventIntoDescendingList$1,normalizeURL:()=>normalizeURL$1,utf8Decoder:()=>utf8Decoder,utf8Encoder:()=>utf8Encoder$1});var utf8Decoder=new TextDecoder("utf-8"),utf8Encoder$1=new TextEncoder;function normalizeURL$1(e){try{e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.protocol==="http:"?t.protocol="ws:":t.protocol==="https:"&&(t.protocol="wss:"),t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch{throw new Error(`Invalid URL: ${e}`)}}function insertEventIntoDescendingList$1(e,t){const[a,u]=binarySearch$1(e,d=>t.id===d.id?0:t.created_at===d.created_at?-1:d.created_at-t.created_at);return u||e.splice(a,0,t),e}function insertEventIntoAscendingList$1(e,t){const[a,u]=binarySearch$1(e,d=>t.id===d.id?0:t.created_at===d.created_at?-1:t.created_at-d.created_at);return u||e.splice(a,0,t),e}function binarySearch$1(e,t){let a=0,u=e.length-1;for(;a<=u;){const d=Math.floor((a+u)/2),h=t(e[d]);if(h===0)return[d,!0];h<0?u=d-1:a=d+1}return[a,!1]}var QueueNode$1=class{constructor(t){_e(this,"value");_e(this,"next",null);_e(this,"prev",null);this.value=t}},Queue$1=class{constructor(){_e(this,"first");_e(this,"last");this.first=null,this.last=null}enqueue(t){const a=new QueueNode$1(t);return this.last?this.last===this.first?(this.last=a,this.last.prev=this.first,this.first.next=a):(a.prev=this.last,this.last.next=a,this.last=a):(this.first=a,this.last=a),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const a=this.first;return this.first=null,this.last=null,a.value}const t=this.first;return this.first=t.next,this.first&&(this.first.prev=null),t.value}},JS$1=class{generateSecretKey(){return schnorr$1.utils.randomPrivateKey()}getPublicKey(t){return bytesToHex$2(schnorr$1.getPublicKey(t))}finalizeEvent(t,a){const u=t;return u.pubkey=bytesToHex$2(schnorr$1.getPublicKey(a)),u.id=getEventHash$1(u),u.sig=bytesToHex$2(schnorr$1.sign(getEventHash$1(u),a)),u[verifiedSymbol$1]=!0,u}verifyEvent(t){if(typeof t[verifiedSymbol$1]=="boolean")return t[verifiedSymbol$1];const a=getEventHash$1(t);if(a!==t.id)return t[verifiedSymbol$1]=!1,!1;try{const u=schnorr$1.verify(t.sig,a,t.pubkey);return t[verifiedSymbol$1]=u,u}catch{return t[verifiedSymbol$1]=!1,!1}}};function serializeEvent$1(e){if(!validateEvent$1(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function getEventHash$1(e){let t=sha256$3(utf8Encoder$1.encode(serializeEvent$1(e)));return bytesToHex$2(t)}var i$1=new JS$1,generateSecretKey=i$1.generateSecretKey,getPublicKey=i$1.getPublicKey,finalizeEvent=i$1.finalizeEvent,verifyEvent=i$1.verifyEvent,kinds_exports$1={};__export$1(kinds_exports$1,{Application:()=>Application$1,BadgeAward:()=>BadgeAward$1,BadgeDefinition:()=>BadgeDefinition$1,BlockedRelaysList:()=>BlockedRelaysList$1,BlossomServerList:()=>BlossomServerList$1,BookmarkList:()=>BookmarkList$1,Bookmarksets:()=>Bookmarksets$1,Calendar:()=>Calendar$1,CalendarEventRSVP:()=>CalendarEventRSVP$1,ChannelCreation:()=>ChannelCreation$1,ChannelHideMessage:()=>ChannelHideMessage$1,ChannelMessage:()=>ChannelMessage$1,ChannelMetadata:()=>ChannelMetadata$1,ChannelMuteUser:()=>ChannelMuteUser$1,ChatMessage:()=>ChatMessage$1,ClassifiedListing:()=>ClassifiedListing$1,ClientAuth:()=>ClientAuth$1,Comment:()=>Comment$1,CommunitiesList:()=>CommunitiesList$1,CommunityDefinition:()=>CommunityDefinition$1,CommunityPostApproval:()=>CommunityPostApproval$1,Contacts:()=>Contacts$1,CreateOrUpdateProduct:()=>CreateOrUpdateProduct$1,CreateOrUpdateStall:()=>CreateOrUpdateStall$1,Curationsets:()=>Curationsets$1,Date:()=>Date2$1,DirectMessageRelaysList:()=>DirectMessageRelaysList$1,DraftClassifiedListing:()=>DraftClassifiedListing$1,DraftLong:()=>DraftLong$1,Emojisets:()=>Emojisets$1,EncryptedDirectMessage:()=>EncryptedDirectMessage$1,EventDeletion:()=>EventDeletion$1,FavoriteRelays:()=>FavoriteRelays$1,FileMessage:()=>FileMessage$1,FileMetadata:()=>FileMetadata$1,FileServerPreference:()=>FileServerPreference$1,Followsets:()=>Followsets$1,ForumThread:()=>ForumThread$1,GenericRepost:()=>GenericRepost$1,Genericlists:()=>Genericlists$1,GiftWrap:()=>GiftWrap$1,GroupMetadata:()=>GroupMetadata$1,HTTPAuth:()=>HTTPAuth$1,Handlerinformation:()=>Handlerinformation$1,Handlerrecommendation:()=>Handlerrecommendation$1,Highlights:()=>Highlights$1,InterestsList:()=>InterestsList$1,Interestsets:()=>Interestsets$1,JobFeedback:()=>JobFeedback$1,JobRequest:()=>JobRequest$1,JobResult:()=>JobResult$1,Label:()=>Label$1,LightningPubRPC:()=>LightningPubRPC$1,LiveChatMessage:()=>LiveChatMessage$1,LiveEvent:()=>LiveEvent$1,LongFormArticle:()=>LongFormArticle$1,Metadata:()=>Metadata$1,Mutelist:()=>Mutelist$1,NWCWalletInfo:()=>NWCWalletInfo$1,NWCWalletRequest:()=>NWCWalletRequest$1,NWCWalletResponse:()=>NWCWalletResponse$1,NormalVideo:()=>NormalVideo$1,NostrConnect:()=>NostrConnect$1,OpenTimestamps:()=>OpenTimestamps$1,Photo:()=>Photo$1,Pinlist:()=>Pinlist$1,Poll:()=>Poll$1,PollResponse:()=>PollResponse$1,PrivateDirectMessage:()=>PrivateDirectMessage$1,ProblemTracker:()=>ProblemTracker$1,ProfileBadges:()=>ProfileBadges$1,PublicChatsList:()=>PublicChatsList$1,Reaction:()=>Reaction$1,RecommendRelay:()=>RecommendRelay$1,RelayList:()=>RelayList$1,RelayReview:()=>RelayReview$1,Relaysets:()=>Relaysets$1,Report:()=>Report$1,Reporting:()=>Reporting$1,Repost:()=>Repost$1,Seal:()=>Seal$1,SearchRelaysList:()=>SearchRelaysList$1,ShortTextNote:()=>ShortTextNote$1,ShortVideo:()=>ShortVideo$1,Time:()=>Time$2,UserEmojiList:()=>UserEmojiList$1,UserStatuses:()=>UserStatuses$1,Voice:()=>Voice$1,VoiceComment:()=>VoiceComment$1,Zap:()=>Zap$1,ZapGoal:()=>ZapGoal$1,ZapRequest:()=>ZapRequest$1,classifyKind:()=>classifyKind$1,isAddressableKind:()=>isAddressableKind$1,isEphemeralKind:()=>isEphemeralKind$1,isKind:()=>isKind$1,isRegularKind:()=>isRegularKind$1,isReplaceableKind:()=>isReplaceableKind$1});function isRegularKind$1(e){return e<1e4&&e!==0&&e!==3}function isReplaceableKind$1(e){return e===0||e===3||1e4<=e&&e<2e4}function isEphemeralKind$1(e){return 2e4<=e&&e<3e4}function isAddressableKind$1(e){return 3e4<=e&&e<4e4}function classifyKind$1(e){return isRegularKind$1(e)?"regular":isReplaceableKind$1(e)?"replaceable":isEphemeralKind$1(e)?"ephemeral":isAddressableKind$1(e)?"parameterized":"unknown"}function isKind$1(e,t){const a=t instanceof Array?t:[t];return validateEvent$1(e)&&a.includes(e.kind)||!1}var Metadata$1=0,ShortTextNote$1=1,RecommendRelay$1=2,Contacts$1=3,EncryptedDirectMessage$1=4,EventDeletion$1=5,Repost$1=6,Reaction$1=7,BadgeAward$1=8,ChatMessage$1=9,ForumThread$1=11,Seal$1=13,PrivateDirectMessage$1=14,FileMessage$1=15,GenericRepost$1=16,Photo$1=20,NormalVideo$1=21,ShortVideo$1=22,ChannelCreation$1=40,ChannelMetadata$1=41,ChannelMessage$1=42,ChannelHideMessage$1=43,ChannelMuteUser$1=44,OpenTimestamps$1=1040,GiftWrap$1=1059,Poll$1=1068,FileMetadata$1=1063,Comment$1=1111,LiveChatMessage$1=1311,Voice$1=1222,VoiceComment$1=1244,ProblemTracker$1=1971,Report$1=1984,Reporting$1=1984,Label$1=1985,CommunityPostApproval$1=4550,JobRequest$1=5999,JobResult$1=6999,JobFeedback$1=7e3,ZapGoal$1=9041,ZapRequest$1=9734,Zap$1=9735,Highlights$1=9802,PollResponse$1=1018,Mutelist$1=1e4,Pinlist$1=10001,RelayList$1=10002,BookmarkList$1=10003,CommunitiesList$1=10004,PublicChatsList$1=10005,BlockedRelaysList$1=10006,SearchRelaysList$1=10007,FavoriteRelays$1=10012,InterestsList$1=10015,UserEmojiList$1=10030,DirectMessageRelaysList$1=10050,FileServerPreference$1=10096,BlossomServerList$1=10063,NWCWalletInfo$1=13194,LightningPubRPC$1=21e3,ClientAuth$1=22242,NWCWalletRequest$1=23194,NWCWalletResponse$1=23195,NostrConnect$1=24133,HTTPAuth$1=27235,Followsets$1=3e4,Genericlists$1=30001,Relaysets$1=30002,Bookmarksets$1=30003,Curationsets$1=30004,ProfileBadges$1=30008,BadgeDefinition$1=30009,Interestsets$1=30015,CreateOrUpdateStall$1=30017,CreateOrUpdateProduct$1=30018,LongFormArticle$1=30023,DraftLong$1=30024,Emojisets$1=30030,Application$1=30078,LiveEvent$1=30311,UserStatuses$1=30315,ClassifiedListing$1=30402,DraftClassifiedListing$1=30403,Date2$1=31922,Time$2=31923,Calendar$1=31924,CalendarEventRSVP$1=31925,RelayReview$1=31987,Handlerrecommendation$1=31989,Handlerinformation$1=31990,CommunityDefinition$1=34550,GroupMetadata$1=39e3;function matchFilter$1(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1)return!1;for(let a in e)if(a[0]==="#"){let u=a.slice(1),d=e[`#${u}`];if(d&&!t.tags.find(([h,w])=>h===a.slice(1)&&d.indexOf(w)!==-1))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function matchFilters$1(e,t){for(let a=0;a<e.length;a++)if(matchFilter$1(e[a],t))return!0;return!1}var fakejson_exports$1={};__export$1(fakejson_exports$1,{getHex64:()=>getHex64$1,getInt:()=>getInt$1,getSubscriptionId:()=>getSubscriptionId$1,matchEventId:()=>matchEventId$1,matchEventKind:()=>matchEventKind$1,matchEventPubkey:()=>matchEventPubkey$1});function getHex64$1(e,t){let a=t.length+3,u=e.indexOf(`"${t}":`)+a,d=e.slice(u).indexOf('"')+u+1;return e.slice(d,d+64)}function getInt$1(e,t){let a=t.length,u=e.indexOf(`"${t}":`)+a+3,d=e.slice(u),h=Math.min(d.indexOf(","),d.indexOf("}"));return parseInt(d.slice(0,h),10)}function getSubscriptionId$1(e){let t=e.slice(0,22).indexOf('"EVENT"');if(t===-1)return null;let a=e.slice(t+7+1).indexOf('"');if(a===-1)return null;let u=t+7+1+a,d=e.slice(u+1,80).indexOf('"');if(d===-1)return null;let h=u+1+d;return e.slice(u+1,h)}function matchEventId$1(e,t){return t===getHex64$1(e,"id")}function matchEventPubkey$1(e,t){return t===getHex64$1(e,"pubkey")}function matchEventKind$1(e,t){return t===getInt$1(e,"kind")}var nip42_exports$1={};__export$1(nip42_exports$1,{makeAuthEvent:()=>makeAuthEvent$1});function makeAuthEvent$1(e,t){return{kind:ClientAuth$1,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function yieldThread$1(){return new Promise((e,t)=>{try{if(typeof MessageChannel<"u"){const a=new MessageChannel,u=()=>{a.port1.removeEventListener("message",u),e()};a.port1.addEventListener("message",u),a.port2.postMessage(0),a.port1.start()}else typeof setImmediate<"u"?setImmediate(e):typeof setTimeout<"u"?setTimeout(e,0):e()}catch(a){console.error("during yield: ",a),t(a)}})}var alwaysTrue$1=e=>(e[verifiedSymbol$1]=!0,!0),SendingOnClosedConnection$1=class extends Error{constructor(t,a){super(`Tried to send message '${t} on a closed connection to ${a}.`),this.name="SendingOnClosedConnection"}},AbstractRelay$1=class{constructor(t,a){_e(this,"url");_e(this,"_connected",!1);_e(this,"onclose",null);_e(this,"onnotice",t=>console.debug(`NOTICE from ${this.url}: ${t}`));_e(this,"onauth");_e(this,"baseEoseTimeout",4400);_e(this,"connectionTimeout",4400);_e(this,"publishTimeout",4400);_e(this,"pingFrequency",29e3);_e(this,"pingTimeout",2e4);_e(this,"resubscribeBackoff",[1e4,1e4,1e4,2e4,2e4,3e4,6e4]);_e(this,"openSubs",new Map);_e(this,"enablePing");_e(this,"enableReconnect");_e(this,"connectionTimeoutHandle");_e(this,"reconnectTimeoutHandle");_e(this,"pingIntervalHandle");_e(this,"reconnectAttempts",0);_e(this,"closedIntentionally",!1);_e(this,"connectionPromise");_e(this,"openCountRequests",new Map);_e(this,"openEventPublishes",new Map);_e(this,"ws");_e(this,"incomingMessageQueue",new Queue$1);_e(this,"queueRunning",!1);_e(this,"challenge");_e(this,"authPromise");_e(this,"serial",0);_e(this,"verifyEvent");_e(this,"_WebSocket");this.url=normalizeURL$1(t),this.verifyEvent=a.verifyEvent,this._WebSocket=a.websocketImplementation||WebSocket,this.enablePing=a.enablePing,this.enableReconnect=a.enableReconnect||!1}static async connect(t,a){const u=new AbstractRelay$1(t,a);return await u.connect(),u}closeAllSubscriptions(t){for(let[a,u]of this.openSubs)u.close(t);this.openSubs.clear();for(let[a,u]of this.openEventPublishes)u.reject(new Error(t));this.openEventPublishes.clear();for(let[a,u]of this.openCountRequests)u.reject(new Error(t));this.openCountRequests.clear()}get connected(){return this._connected}async reconnect(){const t=this.resubscribeBackoff[Math.min(this.reconnectAttempts,this.resubscribeBackoff.length-1)];this.reconnectAttempts++,this.reconnectTimeoutHandle=setTimeout(async()=>{try{await this.connect()}catch{}},t)}handleHardClose(t){var u;this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0;const a=this.closedIntentionally;this.closedIntentionally=!1,(u=this.onclose)==null||u.call(this),this.enableReconnect&&!a?this.reconnect():this.closeAllSubscriptions(t)}async connect(){return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise((t,a)=>{this.connectionTimeoutHandle=setTimeout(()=>{var u;a("connection timed out"),this.connectionPromise=void 0,(u=this.onclose)==null||u.call(this),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(u){clearTimeout(this.connectionTimeoutHandle),a(u);return}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(this.connectionTimeoutHandle),this._connected=!0;const u=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const d of this.openSubs.values()){if(d.eosed=!1,u)for(let h=0;h<d.filters.length;h++)d.lastEmitted&&(d.filters[h].since=d.lastEmitted+1);d.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),t()},this.ws.onerror=u=>{clearTimeout(this.connectionTimeoutHandle),a(u.message||"websocket error"),this.handleHardClose("relay connection errored")},this.ws.onclose=u=>{clearTimeout(this.connectionTimeoutHandle),a(u.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}waitForPingPong(){return new Promise(t=>{this.ws.once("pong",()=>t(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((t,a)=>{if(!this.connectionPromise)return a(new Error(`no connection to ${this.url}, can't ping`));try{const u=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"forced-ping",oneose:()=>{t(!0),u.close()},onclose(){t(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(u){a(u)}})}async pingpong(){var t,a,u;((t=this.ws)==null?void 0:t.readyState)===1&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.once?this.waitForPingPong():this.waitForDummyReq(),new Promise(h=>setTimeout(()=>h(!1),this.pingTimeout))])||((a=this.ws)==null?void 0:a.readyState)===this._WebSocket.OPEN&&((u=this.ws)==null||u.close()))}async runQueue(){for(this.queueRunning=!0;this.handleNext()!==!1;)await yieldThread$1();this.queueRunning=!1}handleNext(){var u,d,h;const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const a=getSubscriptionId$1(t);if(a){const w=this.openSubs.get(a);if(!w)return;const x=getHex64$1(t,"id"),M=(u=w.alreadyHaveEvent)==null?void 0:u.call(w,x);if((d=w.receivedEvent)==null||d.call(w,this,x),M)return}try{let w=JSON.parse(t);switch(w[0]){case"EVENT":{const x=this.openSubs.get(w[1]),M=w[2];this.verifyEvent(M)&&matchFilters$1(x.filters,M)&&x.onevent(M),(!x.lastEmitted||x.lastEmitted<M.created_at)&&(x.lastEmitted=M.created_at);return}case"COUNT":{const x=w[1],M=w[2],B=this.openCountRequests.get(x);B&&(B.resolve(M.count),this.openCountRequests.delete(x));return}case"EOSE":{const x=this.openSubs.get(w[1]);if(!x)return;x.receivedEose();return}case"OK":{const x=w[1],M=w[2],B=w[3],E=this.openEventPublishes.get(x);E&&(clearTimeout(E.timeout),M?E.resolve(B):E.reject(new Error(B)),this.openEventPublishes.delete(x));return}case"CLOSED":{const x=w[1],M=this.openSubs.get(x);if(!M)return;M.closed=!0,M.close(w[2]);return}case"NOTICE":{this.onnotice(w[1]);return}case"AUTH":{this.challenge=w[1],this.onauth&&this.auth(this.onauth);return}default:{const x=this.openSubs.get(w[1]);(h=x==null?void 0:x.oncustom)==null||h.call(x,w);return}}}catch{return}}async send(t){if(!this.connectionPromise)throw new SendingOnClosedConnection$1(t,this.url);this.connectionPromise.then(()=>{var a;(a=this.ws)==null||a.send(t)})}async auth(t){const a=this.challenge;if(!a)throw new Error("can't perform auth, no challenge was received");return this.authPromise?this.authPromise:(this.authPromise=new Promise(async(u,d)=>{try{let h=await t(makeAuthEvent$1(this.url,a)),w=setTimeout(()=>{let x=this.openEventPublishes.get(h.id);x&&(x.reject(new Error("auth timed out")),this.openEventPublishes.delete(h.id))},this.publishTimeout);this.openEventPublishes.set(h.id,{resolve:u,reject:d,timeout:w}),this.send('["AUTH",'+JSON.stringify(h)+"]")}catch(h){console.warn("subscribe auth function failed:",h)}}),this.authPromise)}async publish(t){const a=new Promise((u,d)=>{const h=setTimeout(()=>{const w=this.openEventPublishes.get(t.id);w&&(w.reject(new Error("publish timed out")),this.openEventPublishes.delete(t.id))},this.publishTimeout);this.openEventPublishes.set(t.id,{resolve:u,reject:d,timeout:h})});return this.send('["EVENT",'+JSON.stringify(t)+"]"),a}async count(t,a){this.serial++;const u=(a==null?void 0:a.id)||"count:"+this.serial,d=new Promise((h,w)=>{this.openCountRequests.set(u,{resolve:h,reject:w})});return this.send('["COUNT","'+u+'",'+JSON.stringify(t).substring(1)),d}subscribe(t,a){const u=this.prepareSubscription(t,a);return u.fire(),u}prepareSubscription(t,a){this.serial++;const u=a.id||(a.label?a.label+":":"sub:")+this.serial,d=new Subscription$1(this,u,t,a);return this.openSubs.set(u,d),d}close(){var t,a,u;this.closedIntentionally=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,(t=this.onclose)==null||t.call(this),((a=this.ws)==null?void 0:a.readyState)===this._WebSocket.OPEN&&((u=this.ws)==null||u.close())}_onmessage(t){this.incomingMessageQueue.enqueue(t.data),this.queueRunning||this.runQueue()}},Subscription$1=class{constructor(t,a,u,d){_e(this,"relay");_e(this,"id");_e(this,"lastEmitted");_e(this,"closed",!1);_e(this,"eosed",!1);_e(this,"filters");_e(this,"alreadyHaveEvent");_e(this,"receivedEvent");_e(this,"onevent");_e(this,"oneose");_e(this,"onclose");_e(this,"oncustom");_e(this,"eoseTimeout");_e(this,"eoseTimeoutHandle");if(u.length===0)throw new Error("subscription can't be created with zero filters");this.relay=t,this.filters=u,this.id=a,this.alreadyHaveEvent=d.alreadyHaveEvent,this.receivedEvent=d.receivedEvent,this.eoseTimeout=d.eoseTimeout||t.baseEoseTimeout,this.oneose=d.oneose,this.onclose=d.onclose,this.onevent=d.onevent||(h=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,h)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){var t;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(t=this.oneose)==null||t.call(this))}close(t="closed by caller"){var a;if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(u){if(!(u instanceof SendingOnClosedConnection$1))throw u}this.closed=!0}this.relay.openSubs.delete(this.id),(a=this.onclose)==null||a.call(this,t)}},_WebSocket$1;try{_WebSocket$1=WebSocket}catch{}var AbstractSimplePool$1=class{constructor(t){_e(this,"relays",new Map);_e(this,"seenOn",new Map);_e(this,"trackRelays",!1);_e(this,"verifyEvent");_e(this,"enablePing");_e(this,"enableReconnect");_e(this,"automaticallyAuth");_e(this,"trustedRelayURLs",new Set);_e(this,"_WebSocket");this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation,this.enablePing=t.enablePing,this.enableReconnect=t.enableReconnect||!1,this.automaticallyAuth=t.automaticallyAuth}async ensureRelay(t,a){t=normalizeURL$1(t);let u=this.relays.get(t);if(u||(u=new AbstractRelay$1(t,{verifyEvent:this.trustedRelayURLs.has(t)?alwaysTrue$1:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),u.onclose=()=>{u&&!u.enableReconnect&&this.relays.delete(t)},a!=null&&a.connectionTimeout&&(u.connectionTimeout=a.connectionTimeout),this.relays.set(t,u)),this.automaticallyAuth){const d=this.automaticallyAuth(t);d&&(u.onauth=d)}return await u.connect(),u}close(t){t.map(normalizeURL$1).forEach(a=>{var u;(u=this.relays.get(a))==null||u.close(),this.relays.delete(a)})}subscribe(t,a,u){const d=[];for(let h=0;h<t.length;h++){const w=normalizeURL$1(t[h]);d.find(x=>x.url===w)||d.push({url:w,filter:a})}return this.subscribeMap(d,u)}subscribeMany(t,a,u){const d=[],h=[];for(let w=0;w<t.length;w++){const x=normalizeURL$1(t[w]);h.indexOf(x)===-1&&(h.push(x),d.push({url:x,filter:a}))}return this.subscribeMap(d,u)}subscribeMap(t,a){const u=new Map;for(const C of t){const{url:D,filter:O}=C;u.has(D)||u.set(D,[]),u.get(D).push(O)}const d=Array.from(u.entries()).map(([C,D])=>({url:C,filters:D}));this.trackRelays&&(a.receivedEvent=(C,D)=>{let O=this.seenOn.get(D);O||(O=new Set,this.seenOn.set(D,O)),O.add(C)});const h=new Set,w=[],x=[];let M=C=>{var D;x[C]||(x[C]=!0,x.filter(O=>O).length===d.length&&((D=a.oneose)==null||D.call(a),M=()=>{}))};const B=[];let E=(C,D)=>{var O;B[C]||(M(C),B[C]=D,B.filter(F=>F).length===d.length&&((O=a.onclose)==null||O.call(a,B),E=()=>{}))};const S=C=>{var O;if((O=a.alreadyHaveEvent)!=null&&O.call(a,C))return!0;const D=h.has(C);return h.add(C),D},k=Promise.all(d.map(async({url:C,filters:D},O)=>{let F;try{F=await this.ensureRelay(C,{connectionTimeout:a.maxWait?Math.max(a.maxWait*.8,a.maxWait-1e3):void 0})}catch(L){E(O,(L==null?void 0:L.message)||String(L));return}let P=F.subscribe(D,{...a,oneose:()=>M(O),onclose:L=>{L.startsWith("auth-required: ")&&a.onauth?F.auth(a.onauth).then(()=>{F.subscribe(D,{...a,oneose:()=>M(O),onclose:J=>{E(O,J)},alreadyHaveEvent:S,eoseTimeout:a.maxWait})}).catch(J=>{E(O,`auth was required and attempted, but failed with: ${J}`)}):E(O,L)},alreadyHaveEvent:S,eoseTimeout:a.maxWait});w.push(P)}));return{async close(C){await k,w.forEach(D=>{D.close(C)})}}}subscribeEose(t,a,u){const d=this.subscribe(t,a,{...u,oneose(){d.close("closed automatically on eose")}});return d}subscribeManyEose(t,a,u){const d=this.subscribeMany(t,a,{...u,oneose(){d.close("closed automatically on eose")}});return d}async querySync(t,a,u){return new Promise(async d=>{const h=[];this.subscribeEose(t,a,{...u,onevent(w){h.push(w)},onclose(w){d(h)}})})}async get(t,a,u){a.limit=1;const d=await this.querySync(t,a,u);return d.sort((h,w)=>w.created_at-h.created_at),d[0]||null}publish(t,a,u){return t.map(normalizeURL$1).map(async(d,h,w)=>{if(w.indexOf(d)!==h)return Promise.reject("duplicate url");let x=await this.ensureRelay(d);return x.publish(a).catch(async M=>{if(M instanceof Error&&M.message.startsWith("auth-required: ")&&(u!=null&&u.onauth))return await x.auth(u.onauth),x.publish(a);throw M}).then(M=>{if(this.trackRelays){let B=this.seenOn.get(a.id);B||(B=new Set,this.seenOn.set(a.id,B)),B.add(x)}return M})})}listConnectionStatus(){const t=new Map;return this.relays.forEach((a,u)=>t.set(u,a.connected)),t}destroy(){this.relays.forEach(t=>t.close()),this.relays=new Map}},_WebSocket2$1;try{_WebSocket2$1=WebSocket}catch{}var SimplePool$1=class extends AbstractSimplePool$1{constructor(t){super({verifyEvent,websocketImplementation:_WebSocket2$1,...t})}},nip19_exports$1={};__export$1(nip19_exports$1,{BECH32_REGEX:()=>BECH32_REGEX$1,Bech32MaxSize:()=>Bech32MaxSize$1,NostrTypeGuard:()=>NostrTypeGuard$1,decode:()=>decode$1,decodeNostrURI:()=>decodeNostrURI$1,encodeBytes:()=>encodeBytes$1,naddrEncode:()=>naddrEncode$1,neventEncode:()=>neventEncode$1,noteEncode:()=>noteEncode$1,nprofileEncode:()=>nprofileEncode$1,npubEncode:()=>npubEncode$1,nsecEncode:()=>nsecEncode$1});var NostrTypeGuard$1={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Bech32MaxSize$1=5e3,BECH32_REGEX$1=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function integerToUint8Array$1(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=e&255,t}function decodeNostrURI$1(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),decode$1(e)}catch{return{type:"invalid",data:null}}}function decode$1(e){var d,h,w,x,M,B,E;let{prefix:t,words:a}=bech32$1.decode(e,Bech32MaxSize$1),u=new Uint8Array(bech32$1.fromWords(a));switch(t){case"nprofile":{let S=parseTLV$1(u);if(!((d=S[0])!=null&&d[0]))throw new Error("missing TLV 0 for nprofile");if(S[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:bytesToHex$2(S[0][0]),relays:S[1]?S[1].map(k=>utf8Decoder.decode(k)):[]}}}case"nevent":{let S=parseTLV$1(u);if(!((h=S[0])!=null&&h[0]))throw new Error("missing TLV 0 for nevent");if(S[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(S[2]&&S[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(S[3]&&S[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:bytesToHex$2(S[0][0]),relays:S[1]?S[1].map(k=>utf8Decoder.decode(k)):[],author:(w=S[2])!=null&&w[0]?bytesToHex$2(S[2][0]):void 0,kind:(x=S[3])!=null&&x[0]?parseInt(bytesToHex$2(S[3][0]),16):void 0}}}case"naddr":{let S=parseTLV$1(u);if(!((M=S[0])!=null&&M[0]))throw new Error("missing TLV 0 for naddr");if(!((B=S[2])!=null&&B[0]))throw new Error("missing TLV 2 for naddr");if(S[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((E=S[3])!=null&&E[0]))throw new Error("missing TLV 3 for naddr");if(S[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:utf8Decoder.decode(S[0][0]),pubkey:bytesToHex$2(S[2][0]),kind:parseInt(bytesToHex$2(S[3][0]),16),relays:S[1]?S[1].map(k=>utf8Decoder.decode(k)):[]}}}case"nsec":return{type:t,data:u};case"npub":case"note":return{type:t,data:bytesToHex$2(u)};default:throw new Error(`unknown prefix ${t}`)}}function parseTLV$1(e){let t={},a=e;for(;a.length>0;){let u=a[0],d=a[1],h=a.slice(2,2+d);if(a=a.slice(2+d),h.length<d)throw new Error(`not enough data to read on TLV ${u}`);t[u]=t[u]||[],t[u].push(h)}return t}function nsecEncode$1(e){return encodeBytes$1("nsec",e)}function npubEncode$1(e){return encodeBytes$1("npub",hexToBytes$2(e))}function noteEncode$1(e){return encodeBytes$1("note",hexToBytes$2(e))}function encodeBech32$1(e,t){let a=bech32$1.toWords(t);return bech32$1.encode(e,a,Bech32MaxSize$1)}function encodeBytes$1(e,t){return encodeBech32$1(e,t)}function nprofileEncode$1(e){let t=encodeTLV$1({0:[hexToBytes$2(e.pubkey)],1:(e.relays||[]).map(a=>utf8Encoder$1.encode(a))});return encodeBech32$1("nprofile",t)}function neventEncode$1(e){let t;e.kind!==void 0&&(t=integerToUint8Array$1(e.kind));let a=encodeTLV$1({0:[hexToBytes$2(e.id)],1:(e.relays||[]).map(u=>utf8Encoder$1.encode(u)),2:e.author?[hexToBytes$2(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return encodeBech32$1("nevent",a)}function naddrEncode$1(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let a=encodeTLV$1({0:[utf8Encoder$1.encode(e.identifier)],1:(e.relays||[]).map(u=>utf8Encoder$1.encode(u)),2:[hexToBytes$2(e.pubkey)],3:[new Uint8Array(t)]});return encodeBech32$1("naddr",a)}function encodeTLV$1(e){let t=[];return Object.entries(e).reverse().forEach(([a,u])=>{u.forEach(d=>{let h=new Uint8Array(d.length+2);h.set([parseInt(a)],0),h.set([d.length],1),h.set(d,2),t.push(h)})}),concatBytes$1(...t)}var nip04_exports$1={};__export$1(nip04_exports$1,{decrypt:()=>decrypt$2,encrypt:()=>encrypt$1});function encrypt$1(e,t,a){const u=e instanceof Uint8Array?bytesToHex$2(e):e,d=secp256k1$2.getSharedSecret(u,"02"+t),h=getNormalizedX$1(d);let w=Uint8Array.from(randomBytes$4(16)),x=utf8Encoder$1.encode(a),M=cbc$3(h,w).encrypt(x),B=base64$1.encode(new Uint8Array(M)),E=base64$1.encode(new Uint8Array(w.buffer));return`${B}?iv=${E}`}function decrypt$2(e,t,a){const u=e instanceof Uint8Array?bytesToHex$2(e):e;let[d,h]=a.split("?iv="),w=secp256k1$2.getSharedSecret(u,"02"+t),x=getNormalizedX$1(w),M=base64$1.decode(h),B=base64$1.decode(d),E=cbc$3(x,M).decrypt(B);return utf8Decoder.decode(E)}function getNormalizedX$1(e){return e.slice(1,33)}var nip05_exports$1={};__export$1(nip05_exports$1,{NIP05_REGEX:()=>NIP05_REGEX$1,isNip05:()=>isNip05$1,isValid:()=>isValid$1,queryProfile:()=>queryProfile$1,searchDomain:()=>searchDomain$1,useFetchImplementation:()=>useFetchImplementation$1});var NIP05_REGEX$1=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,isNip05$1=e=>NIP05_REGEX$1.test(e||""),_fetch$1;try{_fetch$1=fetch}catch{}function useFetchImplementation$1(e){_fetch$1=e}async function searchDomain$1(e,t=""){try{const a=`https://${e}/.well-known/nostr.json?name=${t}`,u=await _fetch$1(a,{redirect:"manual"});if(u.status!==200)throw Error("Wrong response code");return(await u.json()).names}catch{return{}}}async function queryProfile$1(e){var d;const t=e.match(NIP05_REGEX$1);if(!t)return null;const[,a="_",u]=t;try{const h=`https://${u}/.well-known/nostr.json?name=${a}`,w=await _fetch$1(h,{redirect:"manual"});if(w.status!==200)throw Error("Wrong response code");const x=await w.json(),M=x.names[a];return M?{pubkey:M,relays:(d=x.relays)==null?void 0:d[M]}:null}catch{return null}}async function isValid$1(e,t){const a=await queryProfile$1(t);return a?a.pubkey===e:!1}var nip10_exports$1={};__export$1(nip10_exports$1,{parse:()=>parse$1});function parse$1(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let a,u;for(let d=e.tags.length-1;d>=0;d--){const h=e.tags[d];if(h[0]==="e"&&h[1]){const[w,x,M,B,E]=h,S={id:x,relays:M?[M]:[],author:E};if(B==="root"){t.root=S;continue}if(B==="reply"){t.reply=S;continue}if(B==="mention"){t.mentions.push(S);continue}a?u=S:a=S,t.mentions.push(S);continue}if(h[0]==="q"&&h[1]){const[w,x,M]=h;t.quotes.push({id:x,relays:M?[M]:[]})}if(h[0]==="p"&&h[1]){t.profiles.push({pubkey:h[1],relays:h[2]?[h[2]]:[]});continue}}return t.root||(t.root=u||a||t.reply),t.reply||(t.reply=a||t.root),[t.reply,t.root].forEach(d=>{if(!d)return;let h=t.mentions.indexOf(d);if(h!==-1&&t.mentions.splice(h,1),d.author){let w=t.profiles.find(x=>x.pubkey===d.author);w&&w.relays&&(d.relays||(d.relays=[]),w.relays.forEach(x=>{var M;((M=d.relays)==null?void 0:M.indexOf(x))===-1&&d.relays.push(x)}),w.relays=d.relays)}}),t.mentions.forEach(d=>{if(d.author){let h=t.profiles.find(w=>w.pubkey===d.author);h&&h.relays&&(d.relays||(d.relays=[]),h.relays.forEach(w=>{d.relays.indexOf(w)===-1&&d.relays.push(w)}),h.relays=d.relays)}}),t}var nip11_exports$1={};__export$1(nip11_exports$1,{fetchRelayInformation:()=>fetchRelayInformation$1,useFetchImplementation:()=>useFetchImplementation2$1});var _fetch2$1;try{_fetch2$1=fetch}catch{}function useFetchImplementation2$1(e){_fetch2$1=e}async function fetchRelayInformation$1(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var nip13_exports$1={};__export$1(nip13_exports$1,{fastEventHash:()=>fastEventHash$1,getPow:()=>getPow$1,minePow:()=>minePow$1});function getPow$1(e){let t=0;for(let a=0;a<64;a+=8){const u=parseInt(e.substring(a,a+8),16);if(u===0)t+=32;else{t+=Math.clz32(u);break}}return t}function minePow$1(e,t){let a=0;const u=e,d=["nonce",a.toString(),t.toString()];for(u.tags.push(d);;){const h=Math.floor(new Date().getTime()/1e3);if(h!==u.created_at&&(a=0,u.created_at=h),d[1]=(++a).toString(),u.id=fastEventHash$1(u),getPow$1(u.id)>=t)break}return u}function fastEventHash$1(e){return bytesToHex$2(sha256$3(utf8Encoder$1.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}var nip17_exports$1={};__export$1(nip17_exports$1,{unwrapEvent:()=>unwrapEvent2$1,unwrapManyEvents:()=>unwrapManyEvents2$1,wrapEvent:()=>wrapEvent2$1,wrapManyEvents:()=>wrapManyEvents2$1});var nip59_exports$1={};__export$1(nip59_exports$1,{createRumor:()=>createRumor$1,createSeal:()=>createSeal$1,createWrap:()=>createWrap$1,unwrapEvent:()=>unwrapEvent$1,unwrapManyEvents:()=>unwrapManyEvents$1,wrapEvent:()=>wrapEvent$1,wrapManyEvents:()=>wrapManyEvents$1});var nip44_exports$1={};__export$1(nip44_exports$1,{decrypt:()=>decrypt2$1,encrypt:()=>encrypt2$1,getConversationKey:()=>getConversationKey$1,v2:()=>v2$1});var minPlaintextSize$1=1,maxPlaintextSize$1=65535;function getConversationKey$1(e,t){const a=secp256k1$2.getSharedSecret(e,"02"+t).subarray(1,33);return extract$1(sha256$3,a,"nip44-v2")}function getMessageKeys$1(e,t){const a=expand$1(sha256$3,e,t,76);return{chacha_key:a.subarray(0,32),chacha_nonce:a.subarray(32,44),hmac_key:a.subarray(44,76)}}function calcPaddedLen$1(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,a=t<=256?32:t/8;return a*(Math.floor((e-1)/a)+1)}function writeU16BE$1(e){if(!Number.isSafeInteger(e)||e<minPlaintextSize$1||e>maxPlaintextSize$1)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}function pad$1(e){const t=utf8Encoder$1.encode(e),a=t.length,u=writeU16BE$1(a),d=new Uint8Array(calcPaddedLen$1(a)-a);return concatBytes$1(u,t,d)}function unpad$2(e){const t=new DataView(e.buffer).getUint16(0),a=e.subarray(2,2+t);if(t<minPlaintextSize$1||t>maxPlaintextSize$1||a.length!==t||e.length!==2+calcPaddedLen$1(t))throw new Error("invalid padding");return utf8Decoder.decode(a)}function hmacAad$1(e,t,a){if(a.length!==32)throw new Error("AAD associated data must be 32 bytes");const u=concatBytes$1(a,t);return hmac$2(sha256$3,e,u)}function decodePayload$1(e){if(typeof e!="string")throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if(e[0]==="#")throw new Error("unknown encryption version");let a;try{a=base64$1.decode(e)}catch(h){throw new Error("invalid base64: "+h.message)}const u=a.length;if(u<99||u>65603)throw new Error("invalid data length: "+u);const d=a[0];if(d!==2)throw new Error("unknown encryption version "+d);return{nonce:a.subarray(1,33),ciphertext:a.subarray(33,-32),mac:a.subarray(-32)}}function encrypt2$1(e,t,a=randomBytes$4(32)){const{chacha_key:u,chacha_nonce:d,hmac_key:h}=getMessageKeys$1(t,a),w=pad$1(e),x=chacha20$1(u,d,w),M=hmacAad$1(h,x,a);return base64$1.encode(concatBytes$1(new Uint8Array([2]),a,x,M))}function decrypt2$1(e,t){const{nonce:a,ciphertext:u,mac:d}=decodePayload$1(e),{chacha_key:h,chacha_nonce:w,hmac_key:x}=getMessageKeys$1(t,a),M=hmacAad$1(x,u,a);if(!equalBytes$1(M,d))throw new Error("invalid MAC");const B=chacha20$1(h,w,u);return unpad$2(B)}var v2$1={utils:{getConversationKey:getConversationKey$1,calcPaddedLen:calcPaddedLen$1},encrypt:encrypt2$1,decrypt:decrypt2$1},TWO_DAYS$1=2*24*60*60,now$1=()=>Math.round(Date.now()/1e3),randomNow$1=()=>Math.round(now$1()-Math.random()*TWO_DAYS$1),nip44ConversationKey$1=(e,t)=>getConversationKey$1(e,t),nip44Encrypt$1=(e,t,a)=>encrypt2$1(JSON.stringify(e),nip44ConversationKey$1(t,a)),nip44Decrypt$1=(e,t)=>JSON.parse(decrypt2$1(e.content,nip44ConversationKey$1(t,e.pubkey)));function createRumor$1(e,t){const a={created_at:now$1(),content:"",tags:[],...e,pubkey:getPublicKey(t)};return a.id=getEventHash$1(a),a}function createSeal$1(e,t,a){return finalizeEvent({kind:Seal$1,content:nip44Encrypt$1(e,t,a),created_at:randomNow$1(),tags:[]},t)}function createWrap$1(e,t){const a=generateSecretKey();return finalizeEvent({kind:GiftWrap$1,content:nip44Encrypt$1(e,a,t),created_at:randomNow$1(),tags:[["p",t]]},a)}function wrapEvent$1(e,t,a){const u=createRumor$1(e,t),d=createSeal$1(u,t,a);return createWrap$1(d,a)}function wrapManyEvents$1(e,t,a){if(!a||a.length===0)throw new Error("At least one recipient is required.");const u=getPublicKey(t),d=[wrapEvent$1(e,t,u)];return a.forEach(h=>{d.push(wrapEvent$1(e,t,h))}),d}function unwrapEvent$1(e,t){const a=nip44Decrypt$1(e,t);return nip44Decrypt$1(a,t)}function unwrapManyEvents$1(e,t){let a=[];return e.forEach(u=>{a.push(unwrapEvent$1(u,t))}),a.sort((u,d)=>u.created_at-d.created_at),a}function createEvent$1(e,t,a,u){const d={created_at:Math.ceil(Date.now()/1e3),kind:PrivateDirectMessage$1,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:w,relayUrl:x})=>{d.tags.push(x?["p",w,x]:["p",w])}),u&&d.tags.push(["e",u.eventId,u.relayUrl||"","reply"]),a&&d.tags.push(["subject",a]),d}function wrapEvent2$1(e,t,a,u,d){const h=createEvent$1(t,a,u,d);return wrapEvent$1(h,e,t.publicKey)}function wrapManyEvents2$1(e,t,a,u,d){if(!t||t.length===0)throw new Error("At least one recipient is required.");return[{publicKey:getPublicKey(e)},...t].map(w=>wrapEvent2$1(e,w,a,u,d))}var unwrapEvent2$1=unwrapEvent$1,unwrapManyEvents2$1=unwrapManyEvents$1,nip18_exports$1={};__export$1(nip18_exports$1,{finishRepostEvent:()=>finishRepostEvent$1,getRepostedEvent:()=>getRepostedEvent$1,getRepostedEventPointer:()=>getRepostedEventPointer$1});function finishRepostEvent$1(e,t,a,u){var w;let d;const h=[...e.tags??[],["e",t.id,a],["p",t.pubkey]];return t.kind===ShortTextNote$1?d=Repost$1:(d=GenericRepost$1,h.push(["k",String(t.kind)])),finalizeEvent({kind:d,tags:h,content:e.content===""||(w=t.tags)!=null&&w.find(x=>x[0]==="-")?"":JSON.stringify(t),created_at:e.created_at},u)}function getRepostedEventPointer$1(e){if(![Repost$1,GenericRepost$1].includes(e.kind))return;let t,a;for(let u=e.tags.length-1;u>=0&&(t===void 0||a===void 0);u--){const d=e.tags[u];d.length>=2&&(d[0]==="e"&&t===void 0?t=d:d[0]==="p"&&a===void 0&&(a=d))}if(t!==void 0)return{id:t[1],relays:[t[2],a==null?void 0:a[2]].filter(u=>typeof u=="string"),author:a==null?void 0:a[1]}}function getRepostedEvent$1(e,{skipVerification:t}={}){const a=getRepostedEventPointer$1(e);if(a===void 0||e.content==="")return;let u;try{u=JSON.parse(e.content)}catch{return}if(u.id===a.id&&!(!t&&!verifyEvent(u)))return u}var nip21_exports$1={};__export$1(nip21_exports$1,{NOSTR_URI_REGEX:()=>NOSTR_URI_REGEX$1,parse:()=>parse2$1,test:()=>test$1});var NOSTR_URI_REGEX$1=new RegExp(`nostr:(${BECH32_REGEX$1.source})`);function test$1(e){return typeof e=="string"&&new RegExp(`^${NOSTR_URI_REGEX$1.source}$`).test(e)}function parse2$1(e){const t=e.match(new RegExp(`^${NOSTR_URI_REGEX$1.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:decode$1(t[1])}}var nip25_exports$1={};__export$1(nip25_exports$1,{finishReactionEvent:()=>finishReactionEvent$1,getReactedEventPointer:()=>getReactedEventPointer$1});function finishReactionEvent$1(e,t,a){const u=t.tags.filter(d=>d.length>=2&&(d[0]==="e"||d[0]==="p"));return finalizeEvent({...e,kind:Reaction$1,tags:[...e.tags??[],...u,["e",t.id],["p",t.pubkey]],content:e.content??"+"},a)}function getReactedEventPointer$1(e){if(e.kind!==Reaction$1)return;let t,a;for(let u=e.tags.length-1;u>=0&&(t===void 0||a===void 0);u--){const d=e.tags[u];d.length>=2&&(d[0]==="e"&&t===void 0?t=d:d[0]==="p"&&a===void 0&&(a=d))}if(!(t===void 0||a===void 0))return{id:t[1],relays:[t[2],a[2]].filter(u=>u!==void 0),author:a[1]}}var nip27_exports$1={};__export$1(nip27_exports$1,{parse:()=>parse3$1});var noCharacter$1=/\W/m,noURLCharacter$1=/[^\w\/] |[^\w\/]$|$|,| /m,MAX_HASHTAG_LENGTH$1=42;function*parse3$1(e){let t=[];if(typeof e!="string"){for(let h=0;h<e.tags.length;h++){const w=e.tags[h];w[0]==="emoji"&&w.length>=3&&t.push({type:"emoji",shortcode:w[1],url:w[2]})}e=e.content}const a=e.length;let u=0,d=0;e:for(;d<a;){const h=e.indexOf(":",d),w=e.indexOf("#",d);if(h===-1&&w===-1)break e;if(h===-1||w>=0&&w<h){if(w===0||e[w-1]===" "){const x=e.slice(w+1,w+MAX_HASHTAG_LENGTH$1).match(noCharacter$1),M=x?w+1+x.index:a;yield{type:"text",text:e.slice(u,w)},yield{type:"hashtag",value:e.slice(w+1,M)},d=M,u=d;continue e}d=w+1;continue e}if(e.slice(h-5,h)==="nostr"){const x=e.slice(h+60).match(noCharacter$1),M=x?h+60+x.index:a;try{let B,{data:E,type:S}=decode$1(e.slice(h+1,M));switch(S){case"npub":B={pubkey:E};break;case"note":B={id:E};break;case"nsec":d=M+1;continue;default:B=E}u!==h-5&&(yield{type:"text",text:e.slice(u,h-5)}),yield{type:"reference",pointer:B},d=M,u=d;continue e}catch{d=h+1;continue e}}else if(e.slice(h-5,h)==="https"||e.slice(h-4,h)==="http"){const x=e.slice(h+4).match(noURLCharacter$1),M=x?h+4+x.index:a,B=e[h-1]==="s"?5:4;try{let E=new URL(e.slice(h-B,M));if(E.hostname.indexOf(".")===-1)throw new Error("invalid url");if(u!==h-B&&(yield{type:"text",text:e.slice(u,h-B)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(E.pathname)){yield{type:"image",url:E.toString()},d=M,u=d;continue e}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(E.pathname)){yield{type:"video",url:E.toString()},d=M,u=d;continue e}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(E.pathname)){yield{type:"audio",url:E.toString()},d=M,u=d;continue e}yield{type:"url",url:E.toString()},d=M,u=d;continue e}catch{d=M+1;continue e}}else if(e.slice(h-3,h)==="wss"||e.slice(h-2,h)==="ws"){const x=e.slice(h+4).match(noURLCharacter$1),M=x?h+4+x.index:a,B=e[h-1]==="s"?3:2;try{let E=new URL(e.slice(h-B,M));if(E.hostname.indexOf(".")===-1)throw new Error("invalid ws url");u!==h-B&&(yield{type:"text",text:e.slice(u,h-B)}),yield{type:"relay",url:E.toString()},d=M,u=d;continue e}catch{d=M+1;continue e}}else{for(let x=0;x<t.length;x++){const M=t[x];if(e[h+M.shortcode.length+1]===":"&&e.slice(h+1,h+M.shortcode.length+1)===M.shortcode){u!==h&&(yield{type:"text",text:e.slice(u,h)}),yield M,d=h+M.shortcode.length+2,u=d;continue e}}d=h+1;continue e}}u!==a&&(yield{type:"text",text:e.slice(u)})}var nip28_exports$1={};__export$1(nip28_exports$1,{channelCreateEvent:()=>channelCreateEvent$1,channelHideMessageEvent:()=>channelHideMessageEvent$1,channelMessageEvent:()=>channelMessageEvent$1,channelMetadataEvent:()=>channelMetadataEvent$1,channelMuteUserEvent:()=>channelMuteUserEvent$1});var channelCreateEvent$1=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent({kind:ChannelCreation$1,tags:[...e.tags??[]],content:a,created_at:e.created_at},t)},channelMetadataEvent$1=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent({kind:ChannelMetadata$1,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:a,created_at:e.created_at},t)},channelMessageEvent$1=(e,t)=>{const a=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&a.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),finalizeEvent({kind:ChannelMessage$1,tags:[...a,...e.tags??[]],content:e.content,created_at:e.created_at},t)},channelHideMessageEvent$1=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent({kind:ChannelHideMessage$1,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:a,created_at:e.created_at},t)},channelMuteUserEvent$1=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent({kind:ChannelMuteUser$1,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:a,created_at:e.created_at},t)},nip30_exports$1={};__export$1(nip30_exports$1,{EMOJI_SHORTCODE_REGEX:()=>EMOJI_SHORTCODE_REGEX$1,matchAll:()=>matchAll$1,regex:()=>regex$1,replaceAll:()=>replaceAll$1});var EMOJI_SHORTCODE_REGEX$1=/:(\w+):/,regex$1=()=>new RegExp(`\\B${EMOJI_SHORTCODE_REGEX$1.source}\\B`,"g");function*matchAll$1(e){const t=e.matchAll(regex$1());for(const a of t)try{const[u,d]=a;yield{shortcode:u,name:d,start:a.index,end:a.index+u.length}}catch{}}function replaceAll$1(e,t){return e.replaceAll(regex$1(),(a,u)=>t({shortcode:a,name:u}))}var nip39_exports$1={};__export$1(nip39_exports$1,{useFetchImplementation:()=>useFetchImplementation3$1,validateGithub:()=>validateGithub$1});var _fetch3$1;try{_fetch3$1=fetch}catch{}function useFetchImplementation3$1(e){_fetch3$1=e}async function validateGithub$1(e,t,a){try{return await(await _fetch3$1(`https://gist.github.com/${t}/${a}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var nip47_exports$1={};__export$1(nip47_exports$1,{makeNwcRequestEvent:()=>makeNwcRequestEvent$1,parseConnectionString:()=>parseConnectionString$1});function parseConnectionString$1(e){const{host:t,pathname:a,searchParams:u}=new URL(e),d=a||t,h=u.get("relay"),w=u.get("secret");if(!d||!h||!w)throw new Error("invalid connection string");return{pubkey:d,relay:h,secret:w}}async function makeNwcRequestEvent$1(e,t,a){const d=encrypt$1(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:a}})),h={kind:NWCWalletRequest$1,created_at:Math.round(Date.now()/1e3),content:d,tags:[["p",e]]};return finalizeEvent(h,t)}var nip54_exports$1={};__export$1(nip54_exports$1,{normalizeIdentifier:()=>normalizeIdentifier$1});function normalizeIdentifier$1(e){return e=e.trim().toLowerCase(),e=e.normalize("NFKC"),Array.from(e).map(t=>new RegExp("\\p{Letter}","u").test(t)||new RegExp("\\p{Number}","u").test(t)?t:"-").join("")}var nip57_exports$1={};__export$1(nip57_exports$1,{getSatoshisAmountFromBolt11:()=>getSatoshisAmountFromBolt11$1,getZapEndpoint:()=>getZapEndpoint$1,makeZapReceipt:()=>makeZapReceipt$1,makeZapRequest:()=>makeZapRequest$1,useFetchImplementation:()=>useFetchImplementation4$1,validateZapRequest:()=>validateZapRequest$1});var _fetch4$1;try{_fetch4$1=fetch}catch{}function useFetchImplementation4$1(e){_fetch4$1=e}async function getZapEndpoint$1(e){try{let t="",{lud06:a,lud16:u}=JSON.parse(e.content);if(u){let[w,x]=u.split("@");t=new URL(`/.well-known/lnurlp/${w}`,`https://${x}`).toString()}else if(a){let{words:w}=bech32$1.decode(a,1e3),x=bech32$1.fromWords(w);t=utf8Decoder.decode(x)}else return null;let h=await(await _fetch4$1(t)).json();if(h.allowsNostr&&h.nostrPubkey)return h.callback}catch{}return null}function makeZapRequest$1(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),isReplaceableKind$1(e.event.kind)){const a=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(a)}else if(isAddressableKind$1(e.event.kind)){let a=e.event.tags.find(([d,h])=>d==="d"&&h);if(!a)throw new Error("d tag not found or is empty");const u=["a",`${e.event.kind}:${e.event.pubkey}:${a[1]}`];t.tags.push(u)}t.tags.push(["k",e.event.kind.toString()])}return t}function validateZapRequest$1(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!validateEvent$1(t))return"Zap request is not a valid Nostr event.";if(!verifyEvent(t))return"Invalid signature on zap request.";let a=t.tags.find(([h,w])=>h==="p"&&w);if(!a)return"Zap request doesn't have a 'p' tag.";if(!a[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let u=t.tags.find(([h,w])=>h==="e"&&w);return u&&!u[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([h,w])=>h==="relays"&&w)?null:"Zap request doesn't have a 'relays' tag."}function makeZapReceipt$1({zapRequest:e,preimage:t,bolt11:a,paidAt:u}){let d=JSON.parse(e),h=d.tags.filter(([x])=>x==="e"||x==="p"||x==="a"),w={kind:9735,created_at:Math.round(u.getTime()/1e3),content:"",tags:[...h,["P",d.pubkey],["bolt11",a],["description",e]]};return t&&w.tags.push(["preimage",t]),w}function getSatoshisAmountFromBolt11$1(e){if(e.length<50)return 0;e=e.substring(0,50);const t=e.lastIndexOf("1");if(t===-1)return 0;const a=e.substring(0,t);if(!a.startsWith("lnbc"))return 0;const u=a.substring(4);if(u.length<1)return 0;const d=u[u.length-1],h=d.charCodeAt(0)-48,w=h>=0&&h<=9;let x=u.length-1;if(w&&x++,x<1)return 0;const M=parseInt(u.substring(0,x));switch(d){case"m":return M*1e5;case"u":return M*100;case"n":return M/10;case"p":return M/1e4;default:return M*1e8}}var nip77_exports$1={};__export$1(nip77_exports$1,{Negentropy:()=>Negentropy$1,NegentropyStorageVector:()=>NegentropyStorageVector$1,NegentropySync:()=>NegentropySync$1});var PROTOCOL_VERSION$1=97,ID_SIZE$1=32,FINGERPRINT_SIZE$1=16,Mode$1={Skip:0,Fingerprint:1,IdList:2},WrappedBuffer$1=class{constructor(t){_e(this,"_raw");_e(this,"length");typeof t=="number"?(this._raw=new Uint8Array(t),this.length=0):t instanceof Uint8Array?(this._raw=new Uint8Array(t),this.length=t.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(t){if(t instanceof WrappedBuffer$1&&(t=t.unwrap()),typeof t.length!="number")throw Error("bad length");const a=t.length+this.length;if(this.capacity<a){const u=this._raw,d=Math.max(this.capacity*2,a);this._raw=new Uint8Array(d),this._raw.set(u)}this._raw.set(t,this.length),this.length+=t.length}shift(){const t=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,t}shiftN(t=1){const a=this._raw.subarray(0,t);return this._raw=this._raw.subarray(t),this.length-=t,a}};function decodeVarInt$1(e){let t=0;for(;;){if(e.length===0)throw Error("parse ends prematurely");let a=e.shift();if(t=t<<7|a&127,!(a&128))break}return t}function encodeVarInt$1(e){if(e===0)return new WrappedBuffer$1(new Uint8Array([0]));let t=[];for(;e!==0;)t.push(e&127),e>>>=7;t.reverse();for(let a=0;a<t.length-1;a++)t[a]|=128;return new WrappedBuffer$1(new Uint8Array(t))}function getByte$1(e){return getBytes$1(e,1)[0]}function getBytes$1(e,t){if(e.length<t)throw Error("parse ends prematurely");return e.shiftN(t)}var Accumulator$1=class{constructor(){_e(this,"buf");this.setToZero()}setToZero(){this.buf=new Uint8Array(ID_SIZE$1)}add(t){let a=0,u=0,d=new DataView(this.buf.buffer),h=new DataView(t.buffer);for(let w=0;w<8;w++){let x=w*4,M=d.getUint32(x,!0),B=h.getUint32(x,!0),E=M;E+=a,E+=B,E>4294967295&&(u=1),d.setUint32(x,E&4294967295,!0),a=u,u=0}}negate(){let t=new DataView(this.buf.buffer);for(let u=0;u<8;u++){let d=u*4;t.setUint32(d,~t.getUint32(d,!0))}let a=new Uint8Array(ID_SIZE$1);a[0]=1,this.add(a)}getFingerprint(t){let a=new WrappedBuffer$1;return a.extend(this.buf),a.extend(encodeVarInt$1(t)),sha256$3(a.unwrap()).subarray(0,FINGERPRINT_SIZE$1)}},NegentropyStorageVector$1=class{constructor(){_e(this,"items");_e(this,"sealed");this.items=[],this.sealed=!1}insert(t,a){if(this.sealed)throw Error("already sealed");const u=hexToBytes$1(a);if(u.byteLength!==ID_SIZE$1)throw Error("bad id size for added item");this.items.push({timestamp:t,id:u})}seal(){if(this.sealed)throw Error("already sealed");this.sealed=!0,this.items.sort(itemCompare$1);for(let t=1;t<this.items.length;t++)if(itemCompare$1(this.items[t-1],this.items[t])===0)throw Error("duplicate item inserted")}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(t){if(this._checkSealed(),t>=this.items.length)throw Error("out of range");return this.items[t]}iterate(t,a,u){this._checkSealed(),this._checkBounds(t,a);for(let d=t;d<a&&u(this.items[d],d);++d);}findLowerBound(t,a,u){return this._checkSealed(),this._checkBounds(t,a),this._binarySearch(this.items,t,a,d=>itemCompare$1(d,u)<0)}fingerprint(t,a){let u=new Accumulator$1;return u.setToZero(),this.iterate(t,a,d=>(u.add(d.id),!0)),u.getFingerprint(a-t)}_checkSealed(){if(!this.sealed)throw Error("not sealed")}_checkBounds(t,a){if(t>a||a>this.items.length)throw Error("bad range")}_binarySearch(t,a,u,d){let h=u-a;for(;h>0;){let w=a,x=Math.floor(h/2);w+=x,d(t[w])?(a=++w,h-=x+1):h=x}return a}},Negentropy$1=class{constructor(t,a=6e4){_e(this,"storage");_e(this,"frameSizeLimit");_e(this,"lastTimestampIn");_e(this,"lastTimestampOut");if(a<4096)throw Error("frameSizeLimit too small");this.storage=t,this.frameSizeLimit=a,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(t,a){return{timestamp:t,id:a||new Uint8Array(0)}}initiate(){let t=new WrappedBuffer$1;return t.extend(new Uint8Array([PROTOCOL_VERSION$1])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),t),bytesToHex$1(t.unwrap())}reconcile(t,a,u){const d=new WrappedBuffer$1(hexToBytes$1(t));this.lastTimestampIn=this.lastTimestampOut=0;let h=new WrappedBuffer$1;h.extend(new Uint8Array([PROTOCOL_VERSION$1]));let w=getByte$1(d);if(w<96||w>111)throw Error("invalid negentropy protocol version byte");if(w!==PROTOCOL_VERSION$1)throw Error("unsupported negentropy protocol version requested: "+(w-96));let x=this.storage.size(),M=this._bound(0),B=0,E=!1;for(;d.length!==0;){let S=new WrappedBuffer$1,k=()=>{E&&(E=!1,S.extend(this.encodeBound(M)),S.extend(encodeVarInt$1(Mode$1.Skip)))},C=this.decodeBound(d),D=decodeVarInt$1(d),O=B,F=this.storage.findLowerBound(B,x,C);if(D===Mode$1.Skip)E=!0;else if(D===Mode$1.Fingerprint){let P=getBytes$1(d,FINGERPRINT_SIZE$1),L=this.storage.fingerprint(O,F);compareUint8Array$1(P,L)!==0?(k(),this.splitRange(O,F,C,S)):E=!0}else if(D===Mode$1.IdList){let P=decodeVarInt$1(d),L={};for(let J=0;J<P;J++){let Y=getBytes$1(d,ID_SIZE$1);L[bytesToHex$1(Y)]=Y}if(E=!0,this.storage.iterate(O,F,J=>{let Y=J.id;const ae=bytesToHex$1(Y);return L[ae]?delete L[bytesToHex$1(Y)]:a==null||a(ae),!0}),u)for(let J of Object.values(L))u(bytesToHex$1(J))}else throw Error("unexpected mode");if(this.exceededFrameSizeLimit(h.length+S.length)){let P=this.storage.fingerprint(F,x);h.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),h.extend(encodeVarInt$1(Mode$1.Fingerprint)),h.extend(P);break}else h.extend(S);B=F,M=C}return h.length===1?null:bytesToHex$1(h.unwrap())}splitRange(t,a,u,d){let h=a-t,w=16;if(h<w*2)d.extend(this.encodeBound(u)),d.extend(encodeVarInt$1(Mode$1.IdList)),d.extend(encodeVarInt$1(h)),this.storage.iterate(t,a,x=>(d.extend(x.id),!0));else{let x=Math.floor(h/w),M=h%w,B=t;for(let E=0;E<w;E++){let S=x+(E<M?1:0),k=this.storage.fingerprint(B,B+S);B+=S;let C;if(B===a)C=u;else{let D,O;this.storage.iterate(B-1,B+1,(F,P)=>(P===B-1?D=F:O=F,!0)),C=this.getMinimalBound(D,O)}d.extend(this.encodeBound(C)),d.extend(encodeVarInt$1(Mode$1.Fingerprint)),d.extend(k)}}}exceededFrameSizeLimit(t){return t>this.frameSizeLimit-200}decodeTimestampIn(t){let a=decodeVarInt$1(t);return a=a===0?Number.MAX_VALUE:a-1,this.lastTimestampIn===Number.MAX_VALUE||a===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(a+=this.lastTimestampIn,this.lastTimestampIn=a,a)}decodeBound(t){let a=this.decodeTimestampIn(t),u=decodeVarInt$1(t);if(u>ID_SIZE$1)throw Error("bound key too long");let d=getBytes$1(t,u);return{timestamp:a,id:d}}encodeTimestampOut(t){if(t===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,encodeVarInt$1(0);let a=t;return t-=this.lastTimestampOut,this.lastTimestampOut=a,encodeVarInt$1(t+1)}encodeBound(t){let a=new WrappedBuffer$1;return a.extend(this.encodeTimestampOut(t.timestamp)),a.extend(encodeVarInt$1(t.id.length)),a.extend(t.id),a}getMinimalBound(t,a){if(a.timestamp!==t.timestamp)return this._bound(a.timestamp);{let u=0,d=a.id,h=t.id;for(let w=0;w<ID_SIZE$1&&d[w]===h[w];w++)u++;return this._bound(a.timestamp,a.id.subarray(0,u+1))}}};function compareUint8Array$1(e,t){for(let a=0;a<e.byteLength;a++){if(e[a]<t[a])return-1;if(e[a]>t[a])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function itemCompare$1(e,t){return e.timestamp===t.timestamp?compareUint8Array$1(e.id,t.id):e.timestamp-t.timestamp}var NegentropySync$1=class{constructor(t,a,u,d={}){_e(this,"relay");_e(this,"storage");_e(this,"neg");_e(this,"filter");_e(this,"subscription");_e(this,"onhave");_e(this,"onneed");this.relay=t,this.storage=a,this.neg=new Negentropy$1(a),this.onhave=d.onhave,this.onneed=d.onneed,this.filter=u,this.subscription=this.relay.prepareSubscription([{}],{label:d.label||"negentropy"}),this.subscription.oncustom=h=>{var w,x,M,B;switch(h[0]){case"NEG-MSG":{h.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${h}`);try{const E=this.neg.reconcile(h[2],this.onhave,this.onneed);E?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${E}"]`):(this.close(),(w=d.onclose)==null||w.call(d))}catch(E){console.error("negentropy reconcile error:",E),(x=d==null?void 0:d.onclose)==null||x.call(d,`reconcile error: ${E}`)}break}case"NEG-CLOSE":{const E=h[2];console.warn("negentropy error:",E),(M=d.onclose)==null||M.call(d,E);break}case"NEG-ERR":(B=d.onclose)==null||B.call(d)}}}async start(){const t=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${t}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}},nip98_exports$1={};__export$1(nip98_exports$1,{getToken:()=>getToken$1,hashPayload:()=>hashPayload$1,unpackEventFromToken:()=>unpackEventFromToken$1,validateEvent:()=>validateEvent2$1,validateEventKind:()=>validateEventKind$1,validateEventMethodTag:()=>validateEventMethodTag$1,validateEventPayloadTag:()=>validateEventPayloadTag$1,validateEventTimestamp:()=>validateEventTimestamp$1,validateEventUrlTag:()=>validateEventUrlTag$1,validateToken:()=>validateToken$1});var _authorizationScheme$1="Nostr ";async function getToken$1(e,t,a,u=!1,d){const h={kind:HTTPAuth$1,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};d&&h.tags.push(["payload",hashPayload$1(d)]);const w=await a(h);return(u?_authorizationScheme$1:"")+base64$1.encode(utf8Encoder$1.encode(JSON.stringify(w)))}async function validateToken$1(e,t,a){const u=await unpackEventFromToken$1(e).catch(h=>{throw h});return await validateEvent2$1(u,t,a).catch(h=>{throw h})}async function unpackEventFromToken$1(e){if(!e)throw new Error("Missing token");e=e.replace(_authorizationScheme$1,"");const t=utf8Decoder.decode(base64$1.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function validateEventTimestamp$1(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function validateEventKind$1(e){return e.kind===HTTPAuth$1}function validateEventUrlTag$1(e,t){const a=e.tags.find(u=>u[0]==="u");return a?a.length>0&&a[1]===t:!1}function validateEventMethodTag$1(e,t){const a=e.tags.find(u=>u[0]==="method");return a?a.length>0&&a[1].toLowerCase()===t.toLowerCase():!1}function hashPayload$1(e){const t=sha256$3(utf8Encoder$1.encode(JSON.stringify(e)));return bytesToHex$2(t)}function validateEventPayloadTag$1(e,t){const a=e.tags.find(d=>d[0]==="payload");if(!a)return!1;const u=hashPayload$1(t);return a.length>0&&a[1]===u}async function validateEvent2$1(e,t,a,u){if(!verifyEvent(e))throw new Error("Invalid nostr event, signature invalid");if(!validateEventKind$1(e))throw new Error("Invalid nostr event, kind invalid");if(!validateEventTimestamp$1(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!validateEventUrlTag$1(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!validateEventMethodTag$1(e,a))throw new Error("Invalid nostr event, method tag invalid");if(u&&typeof u=="object"&&Object.keys(u).length>0&&!validateEventPayloadTag$1(e,u))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}const TAG_PRIVATE="private";class NCC05Error extends Error{constructor(t){super(t),this.name="NCC05Error"}}class NCC05RelayError extends NCC05Error{constructor(t){super(t),this.name="NCC05RelayError"}}class NCC05TimeoutError extends NCC05Error{constructor(t){super(t),this.name="NCC05TimeoutError"}}class NCC05DecryptionError extends NCC05Error{constructor(t){super(t),this.name="NCC05DecryptionError"}}class NCC05ArgumentError extends NCC05Error{constructor(t){super(t),this.name="NCC05ArgumentError"}}function ensureUint8Array(e){if(e instanceof Uint8Array)return e;if(typeof e=="string"){if(e.match(/^[0-9a-fA-F]+$/))return new Uint8Array(e.match(/.{1,2}/g).map(t=>parseInt(t,16)));throw new NCC05ArgumentError("Invalid hex key provided")}throw new NCC05ArgumentError("Key must be a hex string or Uint8Array")}class LocalSigner{constructor(t){_e(this,"secretKey");_e(this,"pubkey");this.secretKey=t,this.pubkey=getPublicKey(t)}async getPublicKey(){return this.pubkey}async signEvent(t){const a={...t,pubkey:this.pubkey};return finalizeEvent(a,this.secretKey)}async getConversationKey(t){return nip44_exports$1.getConversationKey(this.secretKey,t)}}function toSigner(e){if(e){if(typeof e=="string"||e instanceof Uint8Array){const t=ensureUint8Array(e);return new LocalSigner(t)}return e}}class NCC05Resolver{constructor(t={}){_e(this,"pool");_e(this,"_ownPool");_e(this,"bootstrapRelays");_e(this,"timeout");_e(this,"urlTransformer");_e(this,"cache",new Map);this._ownPool=!t.pool,this.pool=t.pool||new SimplePool$1,this.bootstrapRelays=t.bootstrapRelays||["wss://relay.damus.io","wss://npub1..."],this.timeout=t.timeout||1e4,this.urlTransformer=t.urlTransformer}applyUrlTransformer(t){return this.urlTransformer?{...t,endpoints:t.endpoints.map(a=>this.urlTransformer(a))}:t}async decryptEventContent(t,a,u){let d=t.content;if(d.includes('"wraps"')&&d.includes('"ciphertext"')&&d.startsWith("{")){if(!u)return null;try{const w=JSON.parse(d),x=await u.getPublicKey(),M=w.wraps[x];if(!M)return null;const B=await u.getConversationKey(a),E=nip44_exports$1.decrypt(M,B),S=new Uint8Array(E.match(/.{1,2}/g).map(C=>parseInt(C,16))),k=nip44_exports$1.getConversationKey(S,getPublicKey(S));d=nip44_exports$1.decrypt(w.ciphertext,k)}catch{throw new NCC05DecryptionError("Failed to decrypt wrapped content")}}else if(u&&!d.startsWith("{"))try{const w=await u.getConversationKey(a);d=nip44_exports$1.decrypt(d,w)}catch{throw new NCC05DecryptionError("Failed to decrypt content")}return d}async buildPayloadRecord(t,a,u){const d=await this.decryptEventContent(t,a,u);if(!d)return null;let h;try{h=JSON.parse(d)}catch{return null}if(!h||!Array.isArray(h.endpoints)||typeof h.updated_at!="number"||typeof h.ttl!="number")return null;const w=t.tags.find(k=>k[0]==="expiration"),x=w?parseInt(w[1],10):1/0,M=Number.isFinite(x)?x:1/0,B=h.updated_at+h.ttl,E=Math.min(M,B),S=h.updated_at||t.created_at;return{event:t,payload:h,expiry:E,freshness:S}}async discoverRelays(t,a){let u=[...this.bootstrapRelays];if(!a)return u;try{const d=await this.pool.get(this.bootstrapRelays,{authors:[t],kinds:[10002]});if(d&&verifyEvent(d)&&d.pubkey===t){const h=d.tags.filter(w=>w[0]==="r").map(w=>w[1]);h.length>0&&(u=[...new Set([...u,...h])])}}catch(d){console.warn(`[NCC-05] Gossip discovery failed: ${d.message}`)}return u}async fetchFreshestRecord(t,a,u){const d=await this.discoverRelays(t,u),h={authors:[t],kinds:[30058],limit:50};try{const w=this.pool.querySync(d,h),x=new Promise((E,S)=>setTimeout(()=>S(new NCC05TimeoutError("Resolution timed out")),this.timeout)),M=await Promise.race([w,x]);if(!M||Array.isArray(M)&&M.length===0)return null;const B=M.filter(E=>E.pubkey===t&&verifyEvent(E)).sort((E,S)=>S.created_at!==E.created_at?S.created_at-E.created_at:E.id.localeCompare(S.id));return B.length===0?null:this.buildPayloadRecord(B[0],t,a)}catch(w){throw w instanceof NCC05Error?w:new NCC05RelayError(`Relay query failed: ${w.message}`)}}async resolve(t,a,u="addr",d={}){var C;let h=t;t.startsWith("npub1")&&(h=nip19_exports$1.decode(t).data);const w=Math.floor(Date.now()/1e3),x=`${h}:${u}`,M=this.cache.get(x);if(M&&M.expires>w)return M.payload;M&&this.cache.delete(x);const B=a?toSigner(a):void 0,E=await this.fetchFreshestRecord(h,B,d.gossip);if(!E||((C=E.event.tags.find(D=>D[0]==="d"))==null?void 0:C[1])!==u)return null;const k=this.applyUrlTransformer(E.payload);return w>E.expiry?d.strict?null:(console.warn("NCC-05 record expired"),k):(this.cache.set(x,{payload:k,expires:E.expiry}),k)}async resolveLatest(t,a,u={}){let d=t;t.startsWith("npub1")&&(d=nip19_exports$1.decode(t).data);const h=Math.floor(Date.now()/1e3),w=`${d}:latest`,x=this.cache.get(w);if(x&&x.expires>h)return x.payload;x&&this.cache.delete(w);const M=a?toSigner(a):void 0,B=await this.fetchFreshestRecord(d,M,u.gossip);if(!B)return null;const E=this.applyUrlTransformer(B.payload);return h>B.expiry?u.strict?null:(console.warn("NCC-05 record expired"),E):(this.cache.set(w,{payload:E,expires:B.expiry}),E)}close(){this._ownPool&&this.pool.close(this.bootstrapRelays)}}class NCC05Publisher{constructor(t={}){_e(this,"pool");_e(this,"_ownPool");_e(this,"timeout");this._ownPool=!t.pool,this.pool=t.pool||new SimplePool$1,this.timeout=t.timeout||5e3}async _publishToRelays(t,a){const d=this.pool.publish(t,a).map(x=>new Promise((M,B)=>{const E=setTimeout(()=>B(new NCC05TimeoutError("Publish timed out")),this.timeout);x.then(()=>{clearTimeout(E),M()}).catch(S=>{clearTimeout(E),B(S)})})),h=await Promise.allSettled(d);if(h.filter(x=>x.status==="fulfilled").length===0){const x=h.filter(M=>M.status==="rejected").map(M=>M.reason.message).join(", ");throw new NCC05RelayError(`Failed to publish to any relay. Errors: ${x}`)}}async publishWrapped(t,a,u,d,h="addr"){let w="addr",x=!1;typeof h=="string"?w=h:(w=h.identifier||"addr",x=!!h.privateLocator);const M=toSigner(a);if(!M)throw new NCC05ArgumentError("Signer must be provided.");const B=await M.getPublicKey(),E=generateSecretKey(),S=Array.from(E).map(J=>J.toString(16).padStart(2,"0")).join(""),k=nip44_exports$1.getConversationKey(E,getPublicKey(E)),C=nip44_exports$1.encrypt(JSON.stringify(d),k),D={};for(const J of u){const Y=await M.getConversationKey(J);D[J]=nip44_exports$1.encrypt(S,Y)}const O={ciphertext:C,wraps:D},F=[["d",w]];x&&F.push([TAG_PRIVATE,"true"]);const P={kind:30058,created_at:Math.floor(Date.now()/1e3),pubkey:B,tags:F,content:JSON.stringify(O)},L=await M.signEvent(P);return await this._publishToRelays(t,L),L}async publish(t,a,u,d={}){const h=toSigner(a);if(!h)throw new NCC05ArgumentError("Signer must be provided.");const w=await h.getPublicKey(),x=d.identifier||"addr";let M=JSON.stringify(u);if(!d.public){const k=d.recipientPubkey||w,C=await h.getConversationKey(k);M=nip44_exports$1.encrypt(M,C)}const B=[["d",x]];d.privateLocator&&B.push([TAG_PRIVATE,"true"]);const E={kind:30058,created_at:Math.floor(Date.now()/1e3),pubkey:w,tags:B,content:M},S=await h.signEvent(E);return await this._publishToRelays(t,S),S}close(t){this._ownPool&&this.pool.close(t)}}var cryptoBrowserify={};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var browser$c={exports:{}},process=browser$c.exports={},cachedSetTimeout,cachedClearTimeout;function defaultSetTimout(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?cachedSetTimeout=setTimeout:cachedSetTimeout=defaultSetTimout}catch{cachedSetTimeout=defaultSetTimout}try{typeof clearTimeout=="function"?cachedClearTimeout=clearTimeout:cachedClearTimeout=defaultClearTimeout}catch{cachedClearTimeout=defaultClearTimeout}})();function runTimeout(e){if(cachedSetTimeout===setTimeout)return setTimeout(e,0);if((cachedSetTimeout===defaultSetTimout||!cachedSetTimeout)&&setTimeout)return cachedSetTimeout=setTimeout,setTimeout(e,0);try{return cachedSetTimeout(e,0)}catch{try{return cachedSetTimeout.call(null,e,0)}catch{return cachedSetTimeout.call(this,e,0)}}}function runClearTimeout(e){if(cachedClearTimeout===clearTimeout)return clearTimeout(e);if((cachedClearTimeout===defaultClearTimeout||!cachedClearTimeout)&&clearTimeout)return cachedClearTimeout=clearTimeout,clearTimeout(e);try{return cachedClearTimeout(e)}catch{try{return cachedClearTimeout.call(null,e)}catch{return cachedClearTimeout.call(this,e)}}}var queue=[],draining=!1,currentQueue,queueIndex=-1;function cleanUpNextTick(){!draining||!currentQueue||(draining=!1,currentQueue.length?queue=currentQueue.concat(queue):queueIndex=-1,queue.length&&drainQueue())}function drainQueue(){if(!draining){var e=runTimeout(cleanUpNextTick);draining=!0;for(var t=queue.length;t;){for(currentQueue=queue,queue=[];++queueIndex<t;)currentQueue&&currentQueue[queueIndex].run();queueIndex=-1,t=queue.length}currentQueue=null,draining=!1,runClearTimeout(e)}}process.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var a=1;a<arguments.length;a++)t[a-1]=arguments[a];queue.push(new Item(e,t)),queue.length===1&&!draining&&runTimeout(drainQueue)};function Item(e,t){this.fun=e,this.array=t}Item.prototype.run=function(){this.fun.apply(null,this.array)};process.title="browser";process.browser=!0;process.env={};process.argv=[];process.version="";process.versions={};function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.prependListener=noop;process.prependOnceListener=noop;process.listeners=function(e){return[]};process.binding=function(e){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(e){throw new Error("process.chdir is not supported")};process.umask=function(){return 0};var browserExports$1=browser$c.exports;const process$1=getDefaultExportFromCjs(browserExports$1);var browser$b={exports:{}},safeBuffer$5={exports:{}},dist={};(function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var t={},a={};a.byteLength=E,a.toByteArray=k,a.fromByteArray=O;for(var u=[],d=[],h=typeof Uint8Array<"u"?Uint8Array:Array,w="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",x=0,M=w.length;x<M;++x)u[x]=w[x],d[w.charCodeAt(x)]=x;d[45]=62,d[95]=63;function B(L){var J=L.length;if(J%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var Y=L.indexOf("=");Y===-1&&(Y=J);var ae=Y===J?0:4-Y%4;return[Y,ae]}function E(L){var J=B(L),Y=J[0],ae=J[1];return(Y+ae)*3/4-ae}function S(L,J,Y){return(J+Y)*3/4-Y}function k(L){var J,Y=B(L),ae=Y[0],oe=Y[1],ue=new h(S(L,ae,oe)),se=0,ie=oe>0?ae-4:ae,ce;for(ce=0;ce<ie;ce+=4)J=d[L.charCodeAt(ce)]<<18|d[L.charCodeAt(ce+1)]<<12|d[L.charCodeAt(ce+2)]<<6|d[L.charCodeAt(ce+3)],ue[se++]=J>>16&255,ue[se++]=J>>8&255,ue[se++]=J&255;return oe===2&&(J=d[L.charCodeAt(ce)]<<2|d[L.charCodeAt(ce+1)]>>4,ue[se++]=J&255),oe===1&&(J=d[L.charCodeAt(ce)]<<10|d[L.charCodeAt(ce+1)]<<4|d[L.charCodeAt(ce+2)]>>2,ue[se++]=J>>8&255,ue[se++]=J&255),ue}function C(L){return u[L>>18&63]+u[L>>12&63]+u[L>>6&63]+u[L&63]}function D(L,J,Y){for(var ae,oe=[],ue=J;ue<Y;ue+=3)ae=(L[ue]<<16&16711680)+(L[ue+1]<<8&65280)+(L[ue+2]&255),oe.push(C(ae));return oe.join("")}function O(L){for(var J,Y=L.length,ae=Y%3,oe=[],ue=16383,se=0,ie=Y-ae;se<ie;se+=ue)oe.push(D(L,se,se+ue>ie?ie:se+ue));return ae===1?(J=L[Y-1],oe.push(u[J>>2]+u[J<<4&63]+"==")):ae===2&&(J=(L[Y-2]<<8)+L[Y-1],oe.push(u[J>>10]+u[J>>4&63]+u[J<<2&63]+"=")),oe.join("")}var F={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */F.read=function(L,J,Y,ae,oe){var ue,se,ie=oe*8-ae-1,ce=(1<<ie)-1,$=ce>>1,n=-7,l=Y?oe-1:0,c=Y?-1:1,p=L[J+l];for(l+=c,ue=p&(1<<-n)-1,p>>=-n,n+=ie;n>0;ue=ue*256+L[J+l],l+=c,n-=8);for(se=ue&(1<<-n)-1,ue>>=-n,n+=ae;n>0;se=se*256+L[J+l],l+=c,n-=8);if(ue===0)ue=1-$;else{if(ue===ce)return se?NaN:(p?-1:1)*(1/0);se=se+Math.pow(2,ae),ue=ue-$}return(p?-1:1)*se*Math.pow(2,ue-ae)},F.write=function(L,J,Y,ae,oe,ue){var se,ie,ce,$=ue*8-oe-1,n=(1<<$)-1,l=n>>1,c=oe===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=ae?0:ue-1,y=ae?1:-1,b=J<0||J===0&&1/J<0?1:0;for(J=Math.abs(J),isNaN(J)||J===1/0?(ie=isNaN(J)?1:0,se=n):(se=Math.floor(Math.log(J)/Math.LN2),J*(ce=Math.pow(2,-se))<1&&(se--,ce*=2),se+l>=1?J+=c/ce:J+=c*Math.pow(2,1-l),J*ce>=2&&(se++,ce/=2),se+l>=n?(ie=0,se=n):se+l>=1?(ie=(J*ce-1)*Math.pow(2,oe),se=se+l):(ie=J*Math.pow(2,l-1)*Math.pow(2,oe),se=0));oe>=8;L[Y+p]=ie&255,p+=y,ie/=256,oe-=8);for(se=se<<oe|ie,$+=oe;$>0;L[Y+p]=se&255,p+=y,se/=256,$-=8);L[Y+p-y]|=b*128};/*!
1
+ var Et=Object.defineProperty;var St=(e,t,a)=>t in e?Et(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a;var _e=(e,t,a)=>St(e,typeof t!="symbol"?t+"":t,a);import{g as getDefaultExportFromCjs$1,c as commonjsGlobal}from"./vendor-react-KfUPlHYY.js";function _mergeNamespaces(e,t){for(var a=0;a<t.length;a++){const u=t[a];if(typeof u!="string"&&!Array.isArray(u)){for(const d in u)if(d!=="default"&&!(d in e)){const h=Object.getOwnPropertyDescriptor(u,d);h&&Object.defineProperty(e,d,h.get?h:{enumerable:!0,get:()=>u[d]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}function number$3(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function bytes$3(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function hash$6(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number$3(e.outputLen),number$3(e.blockLen)}function exists$2(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output$2(e,t){bytes$3(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}const crypto$4=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const u8a$3=e=>e instanceof Uint8Array,createView$2=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),rotr$2=(e,t)=>e<<32-t|e>>>t,isLE$3=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$3)throw new Error("Non little-endian hardware is not supported");function utf8ToBytes$3(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes$2(e){if(typeof e=="string"&&(e=utf8ToBytes$3(e)),!u8a$3(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function concatBytes$3(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a$3(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}let Hash$a=class{clone(){return this._cloneInto()}};function wrapConstructor$2(e){const t=u=>e().update(toBytes$2(u)).digest(),a=e();return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=()=>e(),t}function randomBytes$5(e=32){if(crypto$4&&typeof crypto$4.getRandomValues=="function")return crypto$4.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function setBigUint64$2(e,t,a,u){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,a,u);const d=BigInt(32),h=BigInt(4294967295),w=Number(a>>d&h),x=Number(a&h),M=u?4:0,B=u?0:4;e.setUint32(t+M,w,u),e.setUint32(t+B,x,u)}let SHA2$2=class extends Hash$a{constructor(t,a,u,d){super(),this.blockLen=t,this.outputLen=a,this.padOffset=u,this.isLE=d,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=createView$2(this.buffer)}update(t){exists$2(this);const{view:a,buffer:u,blockLen:d}=this;t=toBytes$2(t);const h=t.length;for(let w=0;w<h;){const x=Math.min(d-this.pos,h-w);if(x===d){const M=createView$2(t);for(;d<=h-w;w+=d)this.process(M,w);continue}u.set(t.subarray(w,w+x),this.pos),this.pos+=x,w+=x,this.pos===d&&(this.process(a,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){exists$2(this),output$2(t,this),this.finished=!0;const{buffer:a,view:u,blockLen:d,isLE:h}=this;let{pos:w}=this;a[w++]=128,this.buffer.subarray(w).fill(0),this.padOffset>d-w&&(this.process(u,0),w=0);for(let S=w;S<d;S++)a[S]=0;setBigUint64$2(u,d-8,BigInt(this.length*8),h),this.process(u,0);const x=createView$2(t),M=this.outputLen;if(M%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const B=M/4,E=this.get();if(B>E.length)throw new Error("_sha2: outputLen bigger than state");for(let S=0;S<B;S++)x.setUint32(4*S,E[S],h)}digest(){const{buffer:t,outputLen:a}=this;this.digestInto(t);const u=t.slice(0,a);return this.destroy(),u}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:a,buffer:u,length:d,finished:h,destroyed:w,pos:x}=this;return t.length=d,t.pos=x,t.finished=h,t.destroyed=w,d%a&&t.buffer.set(u),t}};const Chi$2=(e,t,a)=>e&t^~e&a,Maj$2=(e,t,a)=>e&t^e&a^t&a,SHA256_K$2=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV$2=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W$2=new Uint32Array(64);let SHA256$4=class extends SHA2$2{constructor(){super(64,32,8,!1),this.A=IV$2[0]|0,this.B=IV$2[1]|0,this.C=IV$2[2]|0,this.D=IV$2[3]|0,this.E=IV$2[4]|0,this.F=IV$2[5]|0,this.G=IV$2[6]|0,this.H=IV$2[7]|0}get(){const{A:t,B:a,C:u,D:d,E:h,F:w,G:x,H:M}=this;return[t,a,u,d,h,w,x,M]}set(t,a,u,d,h,w,x,M){this.A=t|0,this.B=a|0,this.C=u|0,this.D=d|0,this.E=h|0,this.F=w|0,this.G=x|0,this.H=M|0}process(t,a){for(let S=0;S<16;S++,a+=4)SHA256_W$2[S]=t.getUint32(a,!1);for(let S=16;S<64;S++){const k=SHA256_W$2[S-15],C=SHA256_W$2[S-2],D=rotr$2(k,7)^rotr$2(k,18)^k>>>3,O=rotr$2(C,17)^rotr$2(C,19)^C>>>10;SHA256_W$2[S]=O+SHA256_W$2[S-7]+D+SHA256_W$2[S-16]|0}let{A:u,B:d,C:h,D:w,E:x,F:M,G:B,H:E}=this;for(let S=0;S<64;S++){const k=rotr$2(x,6)^rotr$2(x,11)^rotr$2(x,25),C=E+k+Chi$2(x,M,B)+SHA256_K$2[S]+SHA256_W$2[S]|0,O=(rotr$2(u,2)^rotr$2(u,13)^rotr$2(u,22))+Maj$2(u,d,h)|0;E=B,B=M,M=x,x=w+C|0,w=h,h=d,d=u,u=C+O|0}u=u+this.A|0,d=d+this.B|0,h=h+this.C|0,w=w+this.D|0,x=x+this.E|0,M=M+this.F|0,B=B+this.G|0,E=E+this.H|0,this.set(u,d,h,w,x,M,B,E)}roundClean(){SHA256_W$2.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const sha256$4=wrapConstructor$2(()=>new SHA256$4);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$5=BigInt(0),_1n$5=BigInt(1),_2n$3=BigInt(2),u8a$2=e=>e instanceof Uint8Array,hexes$3=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex$3(e){if(!u8a$2(e))throw new Error("Uint8Array expected");let t="";for(let a=0;a<e.length;a++)t+=hexes$3[e[a]];return t}function numberToHexUnpadded$1(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function hexToNumber$1(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function hexToBytes$3(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const a=new Uint8Array(t/2);for(let u=0;u<a.length;u++){const d=u*2,h=e.slice(d,d+2),w=Number.parseInt(h,16);if(Number.isNaN(w)||w<0)throw new Error("Invalid byte sequence");a[u]=w}return a}function bytesToNumberBE$1(e){return hexToNumber$1(bytesToHex$3(e))}function bytesToNumberLE$1(e){if(!u8a$2(e))throw new Error("Uint8Array expected");return hexToNumber$1(bytesToHex$3(Uint8Array.from(e).reverse()))}function numberToBytesBE$1(e,t){return hexToBytes$3(e.toString(16).padStart(t*2,"0"))}function numberToBytesLE$1(e,t){return numberToBytesBE$1(e,t).reverse()}function numberToVarBytesBE$1(e){return hexToBytes$3(numberToHexUnpadded$1(e))}function ensureBytes$1(e,t,a){let u;if(typeof t=="string")try{u=hexToBytes$3(t)}catch(h){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${h}`)}else if(u8a$2(t))u=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const d=u.length;if(typeof a=="number"&&d!==a)throw new Error(`${e} expected ${a} bytes, got ${d}`);return u}function concatBytes$2(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a$2(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}function equalBytes$2(e,t){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}function utf8ToBytes$2(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function bitLen$1(e){let t;for(t=0;e>_0n$5;e>>=_1n$5,t+=1);return t}function bitGet$1(e,t){return e>>BigInt(t)&_1n$5}const bitSet$1=(e,t,a)=>e|(a?_1n$5:_0n$5)<<BigInt(t),bitMask$1=e=>(_2n$3<<BigInt(e-1))-_1n$5,u8n$1=e=>new Uint8Array(e),u8fr$1=e=>Uint8Array.from(e);function createHmacDrbg$1(e,t,a){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof a!="function")throw new Error("hmacFn must be a function");let u=u8n$1(e),d=u8n$1(e),h=0;const w=()=>{u.fill(1),d.fill(0),h=0},x=(...S)=>a(d,u,...S),M=(S=u8n$1())=>{d=x(u8fr$1([0]),S),u=x(),S.length!==0&&(d=x(u8fr$1([1]),S),u=x())},B=()=>{if(h++>=1e3)throw new Error("drbg: tried 1000 values");let S=0;const k=[];for(;S<t;){u=x();const C=u.slice();k.push(C),S+=u.length}return concatBytes$2(...k)};return(S,k)=>{w(),M(S);let C;for(;!(C=k(B()));)M();return w(),C}}const validatorFns$1={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function validateObject$1(e,t,a={}){const u=(d,h,w)=>{const x=validatorFns$1[h];if(typeof x!="function")throw new Error(`Invalid validator "${h}", expected function`);const M=e[d];if(!(w&&M===void 0)&&!x(M,e))throw new Error(`Invalid param ${String(d)}=${M} (${typeof M}), expected ${h}`)};for(const[d,h]of Object.entries(t))u(d,h,!1);for(const[d,h]of Object.entries(a))u(d,h,!0);return e}const ut=Object.freeze(Object.defineProperty({__proto__:null,bitGet:bitGet$1,bitLen:bitLen$1,bitMask:bitMask$1,bitSet:bitSet$1,bytesToHex:bytesToHex$3,bytesToNumberBE:bytesToNumberBE$1,bytesToNumberLE:bytesToNumberLE$1,concatBytes:concatBytes$2,createHmacDrbg:createHmacDrbg$1,ensureBytes:ensureBytes$1,equalBytes:equalBytes$2,hexToBytes:hexToBytes$3,hexToNumber:hexToNumber$1,numberToBytesBE:numberToBytesBE$1,numberToBytesLE:numberToBytesLE$1,numberToHexUnpadded:numberToHexUnpadded$1,numberToVarBytesBE:numberToVarBytesBE$1,utf8ToBytes:utf8ToBytes$2,validateObject:validateObject$1},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$4=BigInt(0),_1n$4=BigInt(1),_2n$2=BigInt(2),_3n$2=BigInt(3),_4n$1=BigInt(4),_5n$1=BigInt(5),_8n$1=BigInt(8);BigInt(9);BigInt(16);function mod$1(e,t){const a=e%t;return a>=_0n$4?a:t+a}function pow$3(e,t,a){if(a<=_0n$4||t<_0n$4)throw new Error("Expected power/modulo > 0");if(a===_1n$4)return _0n$4;let u=_1n$4;for(;t>_0n$4;)t&_1n$4&&(u=u*e%a),e=e*e%a,t>>=_1n$4;return u}function pow2$1(e,t,a){let u=e;for(;t-- >_0n$4;)u*=u,u%=a;return u}function invert$1(e,t){if(e===_0n$4||t<=_0n$4)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let a=mod$1(e,t),u=t,d=_0n$4,h=_1n$4;for(;a!==_0n$4;){const x=u/a,M=u%a,B=d-h*x;u=a,a=M,d=h,h=B}if(u!==_1n$4)throw new Error("invert: does not exist");return mod$1(d,t)}function tonelliShanks$1(e){const t=(e-_1n$4)/_2n$2;let a,u,d;for(a=e-_1n$4,u=0;a%_2n$2===_0n$4;a/=_2n$2,u++);for(d=_2n$2;d<e&&pow$3(d,t,e)!==e-_1n$4;d++);if(u===1){const w=(e+_1n$4)/_4n$1;return function(M,B){const E=M.pow(B,w);if(!M.eql(M.sqr(E),B))throw new Error("Cannot find square root");return E}}const h=(a+_1n$4)/_2n$2;return function(x,M){if(x.pow(M,t)===x.neg(x.ONE))throw new Error("Cannot find square root");let B=u,E=x.pow(x.mul(x.ONE,d),a),S=x.pow(M,h),k=x.pow(M,a);for(;!x.eql(k,x.ONE);){if(x.eql(k,x.ZERO))return x.ZERO;let C=1;for(let O=x.sqr(k);C<B&&!x.eql(O,x.ONE);C++)O=x.sqr(O);const D=x.pow(E,_1n$4<<BigInt(B-C-1));E=x.sqr(D),S=x.mul(S,D),k=x.mul(k,E),B=C}return S}}function FpSqrt$1(e){if(e%_4n$1===_3n$2){const t=(e+_1n$4)/_4n$1;return function(u,d){const h=u.pow(d,t);if(!u.eql(u.sqr(h),d))throw new Error("Cannot find square root");return h}}if(e%_8n$1===_5n$1){const t=(e-_5n$1)/_8n$1;return function(u,d){const h=u.mul(d,_2n$2),w=u.pow(h,t),x=u.mul(d,w),M=u.mul(u.mul(x,_2n$2),w),B=u.mul(x,u.sub(M,u.ONE));if(!u.eql(u.sqr(B),d))throw new Error("Cannot find square root");return B}}return tonelliShanks$1(e)}const FIELD_FIELDS$1=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function validateField$1(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},a=FIELD_FIELDS$1.reduce((u,d)=>(u[d]="function",u),t);return validateObject$1(e,a)}function FpPow$1(e,t,a){if(a<_0n$4)throw new Error("Expected power > 0");if(a===_0n$4)return e.ONE;if(a===_1n$4)return t;let u=e.ONE,d=t;for(;a>_0n$4;)a&_1n$4&&(u=e.mul(u,d)),d=e.sqr(d),a>>=_1n$4;return u}function FpInvertBatch$1(e,t){const a=new Array(t.length),u=t.reduce((h,w,x)=>e.is0(w)?h:(a[x]=h,e.mul(h,w)),e.ONE),d=e.inv(u);return t.reduceRight((h,w,x)=>e.is0(w)?h:(a[x]=e.mul(h,a[x]),e.mul(h,w)),d),a}function nLength$1(e,t){const a=t!==void 0?t:e.toString(2).length,u=Math.ceil(a/8);return{nBitLength:a,nByteLength:u}}function Field$1(e,t,a=!1,u={}){if(e<=_0n$4)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:d,nByteLength:h}=nLength$1(e,t);if(h>2048)throw new Error("Field lengths over 2048 bytes are not supported");const w=FpSqrt$1(e),x=Object.freeze({ORDER:e,BITS:d,BYTES:h,MASK:bitMask$1(d),ZERO:_0n$4,ONE:_1n$4,create:M=>mod$1(M,e),isValid:M=>{if(typeof M!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof M}`);return _0n$4<=M&&M<e},is0:M=>M===_0n$4,isOdd:M=>(M&_1n$4)===_1n$4,neg:M=>mod$1(-M,e),eql:(M,B)=>M===B,sqr:M=>mod$1(M*M,e),add:(M,B)=>mod$1(M+B,e),sub:(M,B)=>mod$1(M-B,e),mul:(M,B)=>mod$1(M*B,e),pow:(M,B)=>FpPow$1(x,M,B),div:(M,B)=>mod$1(M*invert$1(B,e),e),sqrN:M=>M*M,addN:(M,B)=>M+B,subN:(M,B)=>M-B,mulN:(M,B)=>M*B,inv:M=>invert$1(M,e),sqrt:u.sqrt||(M=>w(x,M)),invertBatch:M=>FpInvertBatch$1(x,M),cmov:(M,B,E)=>E?B:M,toBytes:M=>a?numberToBytesLE$1(M,h):numberToBytesBE$1(M,h),fromBytes:M=>{if(M.length!==h)throw new Error(`Fp.fromBytes: expected ${h}, got ${M.length}`);return a?bytesToNumberLE$1(M):bytesToNumberBE$1(M)}});return Object.freeze(x)}function getFieldBytesLength$1(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function getMinHashLength$1(e){const t=getFieldBytesLength$1(e);return t+Math.ceil(t/2)}function mapHashToField$1(e,t,a=!1){const u=e.length,d=getFieldBytesLength$1(t),h=getMinHashLength$1(t);if(u<16||u<h||u>1024)throw new Error(`expected ${h}-1024 bytes of input, got ${u}`);const w=a?bytesToNumberBE$1(e):bytesToNumberLE$1(e),x=mod$1(w,t-_1n$4)+_1n$4;return a?numberToBytesLE$1(x,d):numberToBytesBE$1(x,d)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _0n$3=BigInt(0),_1n$3=BigInt(1);function wNAF$1(e,t){const a=(d,h)=>{const w=h.negate();return d?w:h},u=d=>{const h=Math.ceil(t/d)+1,w=2**(d-1);return{windows:h,windowSize:w}};return{constTimeNegate:a,unsafeLadder(d,h){let w=e.ZERO,x=d;for(;h>_0n$3;)h&_1n$3&&(w=w.add(x)),x=x.double(),h>>=_1n$3;return w},precomputeWindow(d,h){const{windows:w,windowSize:x}=u(h),M=[];let B=d,E=B;for(let S=0;S<w;S++){E=B,M.push(E);for(let k=1;k<x;k++)E=E.add(B),M.push(E);B=E.double()}return M},wNAF(d,h,w){const{windows:x,windowSize:M}=u(d);let B=e.ZERO,E=e.BASE;const S=BigInt(2**d-1),k=2**d,C=BigInt(d);for(let D=0;D<x;D++){const O=D*M;let F=Number(w&S);w>>=C,F>M&&(F-=k,w+=_1n$3);const P=O,L=O+Math.abs(F)-1,J=D%2!==0,Y=F<0;F===0?E=E.add(a(J,h[P])):B=B.add(a(Y,h[L]))}return{p:B,f:E}},wNAFCached(d,h,w,x){const M=d._WINDOW_SIZE||1;let B=h.get(d);return B||(B=this.precomputeWindow(d,M),M!==1&&h.set(d,x(B))),this.wNAF(M,B,w)}}}function validateBasic$1(e){return validateField$1(e.Fp),validateObject$1(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...nLength$1(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function validatePointOpts$1(e){const t=validateBasic$1(e);validateObject$1(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:a,Fp:u,a:d}=t;if(a){if(!u.eql(d,u.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof a!="object"||typeof a.beta!="bigint"||typeof a.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:b2n$1,hexToBytes:h2b$1}=ut,DER$1={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=DER$1;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const a=e[1],u=e.subarray(2,a+2);if(!a||u.length!==a)throw new t("Invalid signature integer: wrong length");if(u[0]&128)throw new t("Invalid signature integer: negative");if(u[0]===0&&!(u[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:b2n$1(u),l:e.subarray(a+2)}},toSig(e){const{Err:t}=DER$1,a=typeof e=="string"?h2b$1(e):e;if(!(a instanceof Uint8Array))throw new Error("ui8a expected");let u=a.length;if(u<2||a[0]!=48)throw new t("Invalid signature tag");if(a[1]!==u-2)throw new t("Invalid signature: incorrect length");const{d,l:h}=DER$1._parseInt(a.subarray(2)),{d:w,l:x}=DER$1._parseInt(h);if(x.length)throw new t("Invalid signature: left bytes after parsing");return{r:d,s:w}},hexFromSig(e){const t=B=>Number.parseInt(B[0],16)&8?"00"+B:B,a=B=>{const E=B.toString(16);return E.length&1?`0${E}`:E},u=t(a(e.s)),d=t(a(e.r)),h=u.length/2,w=d.length/2,x=a(h),M=a(w);return`30${a(w+h+4)}02${M}${d}02${x}${u}`}},_0n$2=BigInt(0),_1n$2=BigInt(1);BigInt(2);const _3n$1=BigInt(3);BigInt(4);function weierstrassPoints$1(e){const t=validatePointOpts$1(e),{Fp:a}=t,u=t.toBytes||((D,O,F)=>{const P=O.toAffine();return concatBytes$2(Uint8Array.from([4]),a.toBytes(P.x),a.toBytes(P.y))}),d=t.fromBytes||(D=>{const O=D.subarray(1),F=a.fromBytes(O.subarray(0,a.BYTES)),P=a.fromBytes(O.subarray(a.BYTES,2*a.BYTES));return{x:F,y:P}});function h(D){const{a:O,b:F}=t,P=a.sqr(D),L=a.mul(P,D);return a.add(a.add(L,a.mul(D,O)),F)}if(!a.eql(a.sqr(t.Gy),h(t.Gx)))throw new Error("bad generator point: equation left != right");function w(D){return typeof D=="bigint"&&_0n$2<D&&D<t.n}function x(D){if(!w(D))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function M(D){const{allowedPrivateKeyLengths:O,nByteLength:F,wrapPrivateKey:P,n:L}=t;if(O&&typeof D!="bigint"){if(D instanceof Uint8Array&&(D=bytesToHex$3(D)),typeof D!="string"||!O.includes(D.length))throw new Error("Invalid key");D=D.padStart(F*2,"0")}let J;try{J=typeof D=="bigint"?D:bytesToNumberBE$1(ensureBytes$1("private key",D,F))}catch{throw new Error(`private key must be ${F} bytes, hex or bigint, not ${typeof D}`)}return P&&(J=mod$1(J,L)),x(J),J}const B=new Map;function E(D){if(!(D instanceof S))throw new Error("ProjectivePoint expected")}class S{constructor(O,F,P){if(this.px=O,this.py=F,this.pz=P,O==null||!a.isValid(O))throw new Error("x required");if(F==null||!a.isValid(F))throw new Error("y required");if(P==null||!a.isValid(P))throw new Error("z required")}static fromAffine(O){const{x:F,y:P}=O||{};if(!O||!a.isValid(F)||!a.isValid(P))throw new Error("invalid affine point");if(O instanceof S)throw new Error("projective point not allowed");const L=J=>a.eql(J,a.ZERO);return L(F)&&L(P)?S.ZERO:new S(F,P,a.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(O){const F=a.invertBatch(O.map(P=>P.pz));return O.map((P,L)=>P.toAffine(F[L])).map(S.fromAffine)}static fromHex(O){const F=S.fromAffine(d(ensureBytes$1("pointHex",O)));return F.assertValidity(),F}static fromPrivateKey(O){return S.BASE.multiply(M(O))}_setWindowSize(O){this._WINDOW_SIZE=O,B.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!a.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:O,y:F}=this.toAffine();if(!a.isValid(O)||!a.isValid(F))throw new Error("bad point: x or y not FE");const P=a.sqr(F),L=h(O);if(!a.eql(P,L))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:O}=this.toAffine();if(a.isOdd)return!a.isOdd(O);throw new Error("Field doesn't support isOdd")}equals(O){E(O);const{px:F,py:P,pz:L}=this,{px:J,py:Y,pz:ae}=O,oe=a.eql(a.mul(F,ae),a.mul(J,L)),ue=a.eql(a.mul(P,ae),a.mul(Y,L));return oe&&ue}negate(){return new S(this.px,a.neg(this.py),this.pz)}double(){const{a:O,b:F}=t,P=a.mul(F,_3n$1),{px:L,py:J,pz:Y}=this;let ae=a.ZERO,oe=a.ZERO,ue=a.ZERO,se=a.mul(L,L),ie=a.mul(J,J),ce=a.mul(Y,Y),$=a.mul(L,J);return $=a.add($,$),ue=a.mul(L,Y),ue=a.add(ue,ue),ae=a.mul(O,ue),oe=a.mul(P,ce),oe=a.add(ae,oe),ae=a.sub(ie,oe),oe=a.add(ie,oe),oe=a.mul(ae,oe),ae=a.mul($,ae),ue=a.mul(P,ue),ce=a.mul(O,ce),$=a.sub(se,ce),$=a.mul(O,$),$=a.add($,ue),ue=a.add(se,se),se=a.add(ue,se),se=a.add(se,ce),se=a.mul(se,$),oe=a.add(oe,se),ce=a.mul(J,Y),ce=a.add(ce,ce),se=a.mul(ce,$),ae=a.sub(ae,se),ue=a.mul(ce,ie),ue=a.add(ue,ue),ue=a.add(ue,ue),new S(ae,oe,ue)}add(O){E(O);const{px:F,py:P,pz:L}=this,{px:J,py:Y,pz:ae}=O;let oe=a.ZERO,ue=a.ZERO,se=a.ZERO;const ie=t.a,ce=a.mul(t.b,_3n$1);let $=a.mul(F,J),n=a.mul(P,Y),l=a.mul(L,ae),c=a.add(F,P),p=a.add(J,Y);c=a.mul(c,p),p=a.add($,n),c=a.sub(c,p),p=a.add(F,L);let y=a.add(J,ae);return p=a.mul(p,y),y=a.add($,l),p=a.sub(p,y),y=a.add(P,L),oe=a.add(Y,ae),y=a.mul(y,oe),oe=a.add(n,l),y=a.sub(y,oe),se=a.mul(ie,p),oe=a.mul(ce,l),se=a.add(oe,se),oe=a.sub(n,se),se=a.add(n,se),ue=a.mul(oe,se),n=a.add($,$),n=a.add(n,$),l=a.mul(ie,l),p=a.mul(ce,p),n=a.add(n,l),l=a.sub($,l),l=a.mul(ie,l),p=a.add(p,l),$=a.mul(n,p),ue=a.add(ue,$),$=a.mul(y,p),oe=a.mul(c,oe),oe=a.sub(oe,$),$=a.mul(c,n),se=a.mul(y,se),se=a.add(se,$),new S(oe,ue,se)}subtract(O){return this.add(O.negate())}is0(){return this.equals(S.ZERO)}wNAF(O){return C.wNAFCached(this,B,O,F=>{const P=a.invertBatch(F.map(L=>L.pz));return F.map((L,J)=>L.toAffine(P[J])).map(S.fromAffine)})}multiplyUnsafe(O){const F=S.ZERO;if(O===_0n$2)return F;if(x(O),O===_1n$2)return this;const{endo:P}=t;if(!P)return C.unsafeLadder(this,O);let{k1neg:L,k1:J,k2neg:Y,k2:ae}=P.splitScalar(O),oe=F,ue=F,se=this;for(;J>_0n$2||ae>_0n$2;)J&_1n$2&&(oe=oe.add(se)),ae&_1n$2&&(ue=ue.add(se)),se=se.double(),J>>=_1n$2,ae>>=_1n$2;return L&&(oe=oe.negate()),Y&&(ue=ue.negate()),ue=new S(a.mul(ue.px,P.beta),ue.py,ue.pz),oe.add(ue)}multiply(O){x(O);let F=O,P,L;const{endo:J}=t;if(J){const{k1neg:Y,k1:ae,k2neg:oe,k2:ue}=J.splitScalar(F);let{p:se,f:ie}=this.wNAF(ae),{p:ce,f:$}=this.wNAF(ue);se=C.constTimeNegate(Y,se),ce=C.constTimeNegate(oe,ce),ce=new S(a.mul(ce.px,J.beta),ce.py,ce.pz),P=se.add(ce),L=ie.add($)}else{const{p:Y,f:ae}=this.wNAF(F);P=Y,L=ae}return S.normalizeZ([P,L])[0]}multiplyAndAddUnsafe(O,F,P){const L=S.BASE,J=(ae,oe)=>oe===_0n$2||oe===_1n$2||!ae.equals(L)?ae.multiplyUnsafe(oe):ae.multiply(oe),Y=J(this,F).add(J(O,P));return Y.is0()?void 0:Y}toAffine(O){const{px:F,py:P,pz:L}=this,J=this.is0();O==null&&(O=J?a.ONE:a.inv(L));const Y=a.mul(F,O),ae=a.mul(P,O),oe=a.mul(L,O);if(J)return{x:a.ZERO,y:a.ZERO};if(!a.eql(oe,a.ONE))throw new Error("invZ was invalid");return{x:Y,y:ae}}isTorsionFree(){const{h:O,isTorsionFree:F}=t;if(O===_1n$2)return!0;if(F)return F(S,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:O,clearCofactor:F}=t;return O===_1n$2?this:F?F(S,this):this.multiplyUnsafe(t.h)}toRawBytes(O=!0){return this.assertValidity(),u(S,this,O)}toHex(O=!0){return bytesToHex$3(this.toRawBytes(O))}}S.BASE=new S(t.Gx,t.Gy,a.ONE),S.ZERO=new S(a.ZERO,a.ONE,a.ZERO);const k=t.nBitLength,C=wNAF$1(S,t.endo?Math.ceil(k/2):k);return{CURVE:t,ProjectivePoint:S,normPrivateKeyToScalar:M,weierstrassEquation:h,isWithinCurveOrder:w}}function validateOpts$1(e){const t=validateBasic$1(e);return validateObject$1(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function weierstrass$1(e){const t=validateOpts$1(e),{Fp:a,n:u}=t,d=a.BYTES+1,h=2*a.BYTES+1;function w(p){return _0n$2<p&&p<a.ORDER}function x(p){return mod$1(p,u)}function M(p){return invert$1(p,u)}const{ProjectivePoint:B,normPrivateKeyToScalar:E,weierstrassEquation:S,isWithinCurveOrder:k}=weierstrassPoints$1({...t,toBytes(p,y,b){const _=y.toAffine(),v=a.toBytes(_.x),o=concatBytes$2;return b?o(Uint8Array.from([y.hasEvenY()?2:3]),v):o(Uint8Array.from([4]),v,a.toBytes(_.y))},fromBytes(p){const y=p.length,b=p[0],_=p.subarray(1);if(y===d&&(b===2||b===3)){const v=bytesToNumberBE$1(_);if(!w(v))throw new Error("Point is not on curve");const o=S(v);let m=a.sqrt(o);const A=(m&_1n$2)===_1n$2;return(b&1)===1!==A&&(m=a.neg(m)),{x:v,y:m}}else if(y===h&&b===4){const v=a.fromBytes(_.subarray(0,a.BYTES)),o=a.fromBytes(_.subarray(a.BYTES,2*a.BYTES));return{x:v,y:o}}else throw new Error(`Point of length ${y} was invalid. Expected ${d} compressed bytes or ${h} uncompressed bytes`)}}),C=p=>bytesToHex$3(numberToBytesBE$1(p,t.nByteLength));function D(p){const y=u>>_1n$2;return p>y}function O(p){return D(p)?x(-p):p}const F=(p,y,b)=>bytesToNumberBE$1(p.slice(y,b));class P{constructor(y,b,_){this.r=y,this.s=b,this.recovery=_,this.assertValidity()}static fromCompact(y){const b=t.nByteLength;return y=ensureBytes$1("compactSignature",y,b*2),new P(F(y,0,b),F(y,b,2*b))}static fromDER(y){const{r:b,s:_}=DER$1.toSig(ensureBytes$1("DER",y));return new P(b,_)}assertValidity(){if(!k(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!k(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(y){return new P(this.r,this.s,y)}recoverPublicKey(y){const{r:b,s:_,recovery:v}=this,o=ue(ensureBytes$1("msgHash",y));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");const m=v===2||v===3?b+t.n:b;if(m>=a.ORDER)throw new Error("recovery id 2 or 3 invalid");const A=v&1?"03":"02",I=B.fromHex(A+C(m)),U=M(m),X=x(-o*U),V=x(_*U),T=B.BASE.multiplyAndAddUnsafe(I,X,V);if(!T)throw new Error("point at infinify");return T.assertValidity(),T}hasHighS(){return D(this.s)}normalizeS(){return this.hasHighS()?new P(this.r,x(-this.s),this.recovery):this}toDERRawBytes(){return hexToBytes$3(this.toDERHex())}toDERHex(){return DER$1.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hexToBytes$3(this.toCompactHex())}toCompactHex(){return C(this.r)+C(this.s)}}const L={isValidPrivateKey(p){try{return E(p),!0}catch{return!1}},normPrivateKeyToScalar:E,randomPrivateKey:()=>{const p=getMinHashLength$1(t.n);return mapHashToField$1(t.randomBytes(p),t.n)},precompute(p=8,y=B.BASE){return y._setWindowSize(p),y.multiply(BigInt(3)),y}};function J(p,y=!0){return B.fromPrivateKey(p).toRawBytes(y)}function Y(p){const y=p instanceof Uint8Array,b=typeof p=="string",_=(y||b)&&p.length;return y?_===d||_===h:b?_===2*d||_===2*h:p instanceof B}function ae(p,y,b=!0){if(Y(p))throw new Error("first arg must be private key");if(!Y(y))throw new Error("second arg must be public key");return B.fromHex(y).multiply(E(p)).toRawBytes(b)}const oe=t.bits2int||function(p){const y=bytesToNumberBE$1(p),b=p.length*8-t.nBitLength;return b>0?y>>BigInt(b):y},ue=t.bits2int_modN||function(p){return x(oe(p))},se=bitMask$1(t.nBitLength);function ie(p){if(typeof p!="bigint")throw new Error("bigint expected");if(!(_0n$2<=p&&p<se))throw new Error(`bigint expected < 2^${t.nBitLength}`);return numberToBytesBE$1(p,t.nByteLength)}function ce(p,y,b=$){if(["recovered","canonical"].some(Z=>Z in b))throw new Error("sign() legacy options not supported");const{hash:_,randomBytes:v}=t;let{lowS:o,prehash:m,extraEntropy:A}=b;o==null&&(o=!0),p=ensureBytes$1("msgHash",p),m&&(p=ensureBytes$1("prehashed msgHash",_(p)));const I=ue(p),U=E(y),X=[ie(U),ie(I)];if(A!=null){const Z=A===!0?v(a.BYTES):A;X.push(ensureBytes$1("extraEntropy",Z))}const V=concatBytes$2(...X),T=I;function q(Z){const te=oe(Z);if(!k(te))return;const ee=M(te),j=B.BASE.multiply(te).toAffine(),re=x(j.x);if(re===_0n$2)return;const qe=x(ee*x(T+re*U));if(qe===_0n$2)return;let de=(j.x===re?0:2)|Number(j.y&_1n$2),pe=qe;return o&&D(qe)&&(pe=O(qe),de^=1),new P(re,pe,de)}return{seed:V,k2sig:q}}const $={lowS:t.lowS,prehash:!1},n={lowS:t.lowS,prehash:!1};function l(p,y,b=$){const{seed:_,k2sig:v}=ce(p,y,b),o=t;return createHmacDrbg$1(o.hash.outputLen,o.nByteLength,o.hmac)(_,v)}B.BASE._setWindowSize(8);function c(p,y,b,_=n){var j;const v=p;if(y=ensureBytes$1("msgHash",y),b=ensureBytes$1("publicKey",b),"strict"in _)throw new Error("options.strict was renamed to lowS");const{lowS:o,prehash:m}=_;let A,I;try{if(typeof v=="string"||v instanceof Uint8Array)try{A=P.fromDER(v)}catch(re){if(!(re instanceof DER$1.Err))throw re;A=P.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){const{r:re,s:qe}=v;A=new P(re,qe)}else throw new Error("PARSE");I=B.fromHex(b)}catch(re){if(re.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(o&&A.hasHighS())return!1;m&&(y=t.hash(y));const{r:U,s:X}=A,V=ue(y),T=M(X),q=x(V*T),Z=x(U*T),te=(j=B.BASE.multiplyAndAddUnsafe(I,q,Z))==null?void 0:j.toAffine();return te?x(te.x)===U:!1}return{CURVE:t,getPublicKey:J,getSharedSecret:ae,sign:l,verify:c,ProjectivePoint:B,Signature:P,utils:L}}let HMAC$2=class extends Hash$a{constructor(t,a){super(),this.finished=!1,this.destroyed=!1,hash$6(t);const u=toBytes$2(a);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const d=this.blockLen,h=new Uint8Array(d);h.set(u.length>d?t.create().update(u).digest():u);for(let w=0;w<h.length;w++)h[w]^=54;this.iHash.update(h),this.oHash=t.create();for(let w=0;w<h.length;w++)h[w]^=106;this.oHash.update(h),h.fill(0)}update(t){return exists$2(this),this.iHash.update(t),this}digestInto(t){exists$2(this),bytes$3(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:a,iHash:u,finished:d,destroyed:h,blockLen:w,outputLen:x}=this;return t=t,t.finished=d,t.destroyed=h,t.blockLen=w,t.outputLen=x,t.oHash=a._cloneInto(t.oHash),t.iHash=u._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const hmac$3=(e,t,a)=>new HMAC$2(e,t).update(a).digest();hmac$3.create=(e,t)=>new HMAC$2(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function getHash$1(e){return{hash:e,hmac:(t,...a)=>hmac$3(e,t,concatBytes$3(...a)),randomBytes:randomBytes$5}}function createCurve$1(e,t){const a=u=>weierstrass$1({...e,...getHash$1(u)});return Object.freeze({...a(t),create:a})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const secp256k1P$1=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),secp256k1N$1=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),_1n$1=BigInt(1),_2n$1=BigInt(2),divNearest$1=(e,t)=>(e+t/_2n$1)/t;function sqrtMod$1(e){const t=secp256k1P$1,a=BigInt(3),u=BigInt(6),d=BigInt(11),h=BigInt(22),w=BigInt(23),x=BigInt(44),M=BigInt(88),B=e*e*e%t,E=B*B*e%t,S=pow2$1(E,a,t)*E%t,k=pow2$1(S,a,t)*E%t,C=pow2$1(k,_2n$1,t)*B%t,D=pow2$1(C,d,t)*C%t,O=pow2$1(D,h,t)*D%t,F=pow2$1(O,x,t)*O%t,P=pow2$1(F,M,t)*F%t,L=pow2$1(P,x,t)*O%t,J=pow2$1(L,a,t)*E%t,Y=pow2$1(J,w,t)*D%t,ae=pow2$1(Y,u,t)*B%t,oe=pow2$1(ae,_2n$1,t);if(!Fp$1.eql(Fp$1.sqr(oe),e))throw new Error("Cannot find square root");return oe}const Fp$1=Field$1(secp256k1P$1,void 0,void 0,{sqrt:sqrtMod$1}),secp256k1$2=createCurve$1({a:BigInt(0),b:BigInt(7),Fp:Fp$1,n:secp256k1N$1,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=secp256k1N$1,a=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),u=-_1n$1*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),d=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),h=a,w=BigInt("0x100000000000000000000000000000000"),x=divNearest$1(h*e,t),M=divNearest$1(-u*e,t);let B=mod$1(e-x*a-M*d,t),E=mod$1(-x*u-M*h,t);const S=B>w,k=E>w;if(S&&(B=t-B),k&&(E=t-E),B>w||E>w)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:S,k1:B,k2neg:k,k2:E}}}},sha256$4),_0n$1=BigInt(0),fe$1=e=>typeof e=="bigint"&&_0n$1<e&&e<secp256k1P$1,ge$1=e=>typeof e=="bigint"&&_0n$1<e&&e<secp256k1N$1,TAGGED_HASH_PREFIXES$1={};function taggedHash$1(e,...t){let a=TAGGED_HASH_PREFIXES$1[e];if(a===void 0){const u=sha256$4(Uint8Array.from(e,d=>d.charCodeAt(0)));a=concatBytes$2(u,u),TAGGED_HASH_PREFIXES$1[e]=a}return sha256$4(concatBytes$2(a,...t))}const pointToBytes$1=e=>e.toRawBytes(!0).slice(1),numTo32b$1=e=>numberToBytesBE$1(e,32),modP$1=e=>mod$1(e,secp256k1P$1),modN$1=e=>mod$1(e,secp256k1N$1),Point$4=secp256k1$2.ProjectivePoint,GmulAdd$1=(e,t,a)=>Point$4.BASE.multiplyAndAddUnsafe(e,t,a);function schnorrGetExtPubKey$1(e){let t=secp256k1$2.utils.normPrivateKeyToScalar(e),a=Point$4.fromPrivateKey(t);return{scalar:a.hasEvenY()?t:modN$1(-t),bytes:pointToBytes$1(a)}}function lift_x$1(e){if(!fe$1(e))throw new Error("bad x: need 0 < x < p");const t=modP$1(e*e),a=modP$1(t*e+BigInt(7));let u=sqrtMod$1(a);u%_2n$1!==_0n$1&&(u=modP$1(-u));const d=new Point$4(e,u,_1n$1);return d.assertValidity(),d}function challenge$1(...e){return modN$1(bytesToNumberBE$1(taggedHash$1("BIP0340/challenge",...e)))}function schnorrGetPublicKey$1(e){return schnorrGetExtPubKey$1(e).bytes}function schnorrSign$1(e,t,a=randomBytes$5(32)){const u=ensureBytes$1("message",e),{bytes:d,scalar:h}=schnorrGetExtPubKey$1(t),w=ensureBytes$1("auxRand",a,32),x=numTo32b$1(h^bytesToNumberBE$1(taggedHash$1("BIP0340/aux",w))),M=taggedHash$1("BIP0340/nonce",x,d,u),B=modN$1(bytesToNumberBE$1(M));if(B===_0n$1)throw new Error("sign failed: k is zero");const{bytes:E,scalar:S}=schnorrGetExtPubKey$1(B),k=challenge$1(E,d,u),C=new Uint8Array(64);if(C.set(E,0),C.set(numTo32b$1(modN$1(S+k*h)),32),!schnorrVerify$1(C,u,d))throw new Error("sign: Invalid signature produced");return C}function schnorrVerify$1(e,t,a){const u=ensureBytes$1("signature",e,64),d=ensureBytes$1("message",t),h=ensureBytes$1("publicKey",a,32);try{const w=lift_x$1(bytesToNumberBE$1(h)),x=bytesToNumberBE$1(u.subarray(0,32));if(!fe$1(x))return!1;const M=bytesToNumberBE$1(u.subarray(32,64));if(!ge$1(M))return!1;const B=challenge$1(numTo32b$1(x),pointToBytes$1(w),d),E=GmulAdd$1(w,M,modN$1(-B));return!(!E||!E.hasEvenY()||E.toAffine().x!==x)}catch{return!1}}const schnorr$1={getPublicKey:schnorrGetPublicKey$1,sign:schnorrSign$1,verify:schnorrVerify$1,utils:{randomPrivateKey:secp256k1$2.utils.randomPrivateKey,lift_x:lift_x$1,pointToBytes:pointToBytes$1,numberToBytesBE:numberToBytesBE$1,bytesToNumberBE:bytesToNumberBE$1,taggedHash:taggedHash$1,mod:mod$1}},crypto$3=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const u8a$1=e=>e instanceof Uint8Array,createView$1=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),rotr$1=(e,t)=>e<<32-t|e>>>t,isLE$2=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$2)throw new Error("Non little-endian hardware is not supported");const hexes$2=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex$2(e){if(!u8a$1(e))throw new Error("Uint8Array expected");let t="";for(let a=0;a<e.length;a++)t+=hexes$2[e[a]];return t}function hexToBytes$2(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const a=new Uint8Array(t/2);for(let u=0;u<a.length;u++){const d=u*2,h=e.slice(d,d+2),w=Number.parseInt(h,16);if(Number.isNaN(w)||w<0)throw new Error("Invalid byte sequence");a[u]=w}return a}function utf8ToBytes$1(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes$1(e){if(typeof e=="string"&&(e=utf8ToBytes$1(e)),!u8a$1(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function concatBytes$1(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a$1(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}let Hash$9=class{clone(){return this._cloneInto()}};function wrapConstructor$1(e){const t=u=>e().update(toBytes$1(u)).digest(),a=e();return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=()=>e(),t}function randomBytes$4(e=32){if(crypto$3&&typeof crypto$3.getRandomValues=="function")return crypto$3.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function number$2(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function bool$2(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function bytes$2(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function hash$5(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number$2(e.outputLen),number$2(e.blockLen)}function exists$1(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output$1(e,t){bytes$2(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}const assert$k={number:number$2,bool:bool$2,bytes:bytes$2,hash:hash$5,exists:exists$1,output:output$1};function setBigUint64$1(e,t,a,u){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,a,u);const d=BigInt(32),h=BigInt(4294967295),w=Number(a>>d&h),x=Number(a&h),M=u?4:0,B=u?0:4;e.setUint32(t+M,w,u),e.setUint32(t+B,x,u)}let SHA2$1=class extends Hash$9{constructor(t,a,u,d){super(),this.blockLen=t,this.outputLen=a,this.padOffset=u,this.isLE=d,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=createView$1(this.buffer)}update(t){assert$k.exists(this);const{view:a,buffer:u,blockLen:d}=this;t=toBytes$1(t);const h=t.length;for(let w=0;w<h;){const x=Math.min(d-this.pos,h-w);if(x===d){const M=createView$1(t);for(;d<=h-w;w+=d)this.process(M,w);continue}u.set(t.subarray(w,w+x),this.pos),this.pos+=x,w+=x,this.pos===d&&(this.process(a,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){assert$k.exists(this),assert$k.output(t,this),this.finished=!0;const{buffer:a,view:u,blockLen:d,isLE:h}=this;let{pos:w}=this;a[w++]=128,this.buffer.subarray(w).fill(0),this.padOffset>d-w&&(this.process(u,0),w=0);for(let S=w;S<d;S++)a[S]=0;setBigUint64$1(u,d-8,BigInt(this.length*8),h),this.process(u,0);const x=createView$1(t),M=this.outputLen;if(M%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const B=M/4,E=this.get();if(B>E.length)throw new Error("_sha2: outputLen bigger than state");for(let S=0;S<B;S++)x.setUint32(4*S,E[S],h)}digest(){const{buffer:t,outputLen:a}=this;this.digestInto(t);const u=t.slice(0,a);return this.destroy(),u}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:a,buffer:u,length:d,finished:h,destroyed:w,pos:x}=this;return t.length=d,t.pos=x,t.finished=h,t.destroyed=w,d%a&&t.buffer.set(u),t}};const Chi$1=(e,t,a)=>e&t^~e&a,Maj$1=(e,t,a)=>e&t^e&a^t&a,SHA256_K$1=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV$1=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W$1=new Uint32Array(64);let SHA256$3=class extends SHA2$1{constructor(){super(64,32,8,!1),this.A=IV$1[0]|0,this.B=IV$1[1]|0,this.C=IV$1[2]|0,this.D=IV$1[3]|0,this.E=IV$1[4]|0,this.F=IV$1[5]|0,this.G=IV$1[6]|0,this.H=IV$1[7]|0}get(){const{A:t,B:a,C:u,D:d,E:h,F:w,G:x,H:M}=this;return[t,a,u,d,h,w,x,M]}set(t,a,u,d,h,w,x,M){this.A=t|0,this.B=a|0,this.C=u|0,this.D=d|0,this.E=h|0,this.F=w|0,this.G=x|0,this.H=M|0}process(t,a){for(let S=0;S<16;S++,a+=4)SHA256_W$1[S]=t.getUint32(a,!1);for(let S=16;S<64;S++){const k=SHA256_W$1[S-15],C=SHA256_W$1[S-2],D=rotr$1(k,7)^rotr$1(k,18)^k>>>3,O=rotr$1(C,17)^rotr$1(C,19)^C>>>10;SHA256_W$1[S]=O+SHA256_W$1[S-7]+D+SHA256_W$1[S-16]|0}let{A:u,B:d,C:h,D:w,E:x,F:M,G:B,H:E}=this;for(let S=0;S<64;S++){const k=rotr$1(x,6)^rotr$1(x,11)^rotr$1(x,25),C=E+k+Chi$1(x,M,B)+SHA256_K$1[S]+SHA256_W$1[S]|0,O=(rotr$1(u,2)^rotr$1(u,13)^rotr$1(u,22))+Maj$1(u,d,h)|0;E=B,B=M,M=x,x=w+C|0,w=h,h=d,d=u,u=C+O|0}u=u+this.A|0,d=d+this.B|0,h=h+this.C|0,w=w+this.D|0,x=x+this.E|0,M=M+this.F|0,B=B+this.G|0,E=E+this.H|0,this.set(u,d,h,w,x,M,B,E)}roundClean(){SHA256_W$1.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},SHA224$2=class extends SHA256$3{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const sha256$3=wrapConstructor$1(()=>new SHA256$3);wrapConstructor$1(()=>new SHA224$2);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function assertNumber$1(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function chain$1(...e){const t=(d,h)=>w=>d(h(w)),a=Array.from(e).reverse().reduce((d,h)=>d?t(d,h.encode):h.encode,void 0),u=e.reduce((d,h)=>d?t(d,h.decode):h.decode,void 0);return{encode:a,decode:u}}function alphabet$1(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(a=>{if(assertNumber$1(a),a<0||a>=e.length)throw new Error(`Digit index outside alphabet: ${a} (alphabet: ${e.length})`);return e[a]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(a=>{if(typeof a!="string")throw new Error(`alphabet.decode: not string element=${a}`);const u=e.indexOf(a);if(u===-1)throw new Error(`Unknown letter: "${a}". Allowed: ${e}`);return u})}}}function join$1(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let a of t)if(typeof a!="string")throw new Error(`join.encode: non-string input=${a}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function padding$1(e,t="="){if(assertNumber$1(e),typeof t!="string")throw new Error("padding chr should be string");return{encode(a){if(!Array.isArray(a)||a.length&&typeof a[0]!="string")throw new Error("padding.encode input should be array of strings");for(let u of a)if(typeof u!="string")throw new Error(`padding.encode: non-string input=${u}`);for(;a.length*e%8;)a.push(t);return a},decode(a){if(!Array.isArray(a)||a.length&&typeof a[0]!="string")throw new Error("padding.encode input should be array of strings");for(let d of a)if(typeof d!="string")throw new Error(`padding.decode: non-string input=${d}`);let u=a.length;if(u*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;u>0&&a[u-1]===t;u--)if(!((u-1)*e%8))throw new Error("Invalid padding: string has too much padding");return a.slice(0,u)}}}function normalize$1(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function convertRadix$1(e,t,a){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(a<2)throw new Error(`convertRadix: wrong to=${a}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let u=0;const d=[],h=Array.from(e);for(h.forEach(w=>{if(assertNumber$1(w),w<0||w>=t)throw new Error(`Wrong integer: ${w}`)});;){let w=0,x=!0;for(let M=u;M<h.length;M++){const B=h[M],E=t*w+B;if(!Number.isSafeInteger(E)||t*w/t!==w||E-B!==t*w)throw new Error("convertRadix: carry overflow");if(w=E%a,h[M]=Math.floor(E/a),!Number.isSafeInteger(h[M])||h[M]*a+w!==E)throw new Error("convertRadix: carry overflow");if(x)h[M]?x=!1:u=M;else continue}if(d.push(w),x)break}for(let w=0;w<e.length-1&&e[w]===0;w++)d.push(0);return d.reverse()}const gcd$1=(e,t)=>t?gcd$1(t,e%t):e,radix2carry$1=(e,t)=>e+(t-gcd$1(e,t));function convertRadix2$1(e,t,a,u){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(a<=0||a>32)throw new Error(`convertRadix2: wrong to=${a}`);if(radix2carry$1(t,a)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${a} carryBits=${radix2carry$1(t,a)}`);let d=0,h=0;const w=2**a-1,x=[];for(const M of e){if(assertNumber$1(M),M>=2**t)throw new Error(`convertRadix2: invalid data word=${M} from=${t}`);if(d=d<<t|M,h+t>32)throw new Error(`convertRadix2: carry overflow pos=${h} from=${t}`);for(h+=t;h>=a;h-=a)x.push((d>>h-a&w)>>>0);d&=2**h-1}if(d=d<<a-h&w,!u&&h>=t)throw new Error("Excess padding");if(!u&&d)throw new Error(`Non-zero padding: ${d}`);return u&&h>0&&x.push(d>>>0),x}function radix$1(e){return assertNumber$1(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return convertRadix$1(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(convertRadix$1(t,e,2**8))}}}function radix2$1(e,t=!1){if(assertNumber$1(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(radix2carry$1(8,e)>32||radix2carry$1(e,8)>32)throw new Error("radix2: carry overflow");return{encode:a=>{if(!(a instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return convertRadix2$1(Array.from(a),8,e,!t)},decode:a=>{if(!Array.isArray(a)||a.length&&typeof a[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(convertRadix2$1(a,e,8,t))}}}function unsafeWrapper$1(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}const base16$1=chain$1(radix2$1(4),alphabet$1("0123456789ABCDEF"),join$1("")),base32$1=chain$1(radix2$1(5),alphabet$1("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),padding$1(5),join$1(""));chain$1(radix2$1(5),alphabet$1("0123456789ABCDEFGHIJKLMNOPQRSTUV"),padding$1(5),join$1(""));chain$1(radix2$1(5),alphabet$1("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),join$1(""),normalize$1(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const base64$1=chain$1(radix2$1(6),alphabet$1("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),padding$1(6),join$1("")),base64url$1=chain$1(radix2$1(6),alphabet$1("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),padding$1(6),join$1("")),genBase58$1=e=>chain$1(radix$1(58),alphabet$1(e),join$1("")),base58$1=genBase58$1("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");genBase58$1("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");genBase58$1("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const XMR_BLOCK_LEN$1=[0,2,3,5,6,7,9,10,11],base58xmr$1={encode(e){let t="";for(let a=0;a<e.length;a+=8){const u=e.subarray(a,a+8);t+=base58$1.encode(u).padStart(XMR_BLOCK_LEN$1[u.length],"1")}return t},decode(e){let t=[];for(let a=0;a<e.length;a+=11){const u=e.slice(a,a+11),d=XMR_BLOCK_LEN$1.indexOf(u.length),h=base58$1.decode(u);for(let w=0;w<h.length-d;w++)if(h[w]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(h.slice(h.length-d)))}return Uint8Array.from(t)}},BECH_ALPHABET$1=chain$1(alphabet$1("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),join$1("")),POLYMOD_GENERATORS$1=[996825010,642813549,513874426,1027748829,705979059];function bech32Polymod$1(e){const t=e>>25;let a=(e&33554431)<<5;for(let u=0;u<POLYMOD_GENERATORS$1.length;u++)(t>>u&1)===1&&(a^=POLYMOD_GENERATORS$1[u]);return a}function bechChecksum$1(e,t,a=1){const u=e.length;let d=1;for(let h=0;h<u;h++){const w=e.charCodeAt(h);if(w<33||w>126)throw new Error(`Invalid prefix (${e})`);d=bech32Polymod$1(d)^w>>5}d=bech32Polymod$1(d);for(let h=0;h<u;h++)d=bech32Polymod$1(d)^e.charCodeAt(h)&31;for(let h of t)d=bech32Polymod$1(d)^h;for(let h=0;h<6;h++)d=bech32Polymod$1(d);return d^=a,BECH_ALPHABET$1.encode(convertRadix2$1([d%2**30],30,5,!1))}function genBech32$1(e){const t=e==="bech32"?1:734539939,a=radix2$1(5),u=a.decode,d=a.encode,h=unsafeWrapper$1(u);function w(E,S,k=90){if(typeof E!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof E}`);if(!Array.isArray(S)||S.length&&typeof S[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof S}`);const C=E.length+7+S.length;if(k!==!1&&C>k)throw new TypeError(`Length ${C} exceeds limit ${k}`);return E=E.toLowerCase(),`${E}1${BECH_ALPHABET$1.encode(S)}${bechChecksum$1(E,S,t)}`}function x(E,S=90){if(typeof E!="string")throw new Error(`bech32.decode input should be string, not ${typeof E}`);if(E.length<8||S!==!1&&E.length>S)throw new TypeError(`Wrong string length: ${E.length} (${E}). Expected (8..${S})`);const k=E.toLowerCase();if(E!==k&&E!==E.toUpperCase())throw new Error("String must be lowercase or uppercase");E=k;const C=E.lastIndexOf("1");if(C===0||C===-1)throw new Error('Letter "1" must be present between prefix and data only');const D=E.slice(0,C),O=E.slice(C+1);if(O.length<6)throw new Error("Data must be at least 6 characters long");const F=BECH_ALPHABET$1.decode(O).slice(0,-6),P=bechChecksum$1(D,F,t);if(!O.endsWith(P))throw new Error(`Invalid checksum in ${E}: expected "${P}"`);return{prefix:D,words:F}}const M=unsafeWrapper$1(x);function B(E){const{prefix:S,words:k}=x(E,!1);return{prefix:S,words:k,bytes:u(k)}}return{encode:w,decode:x,decodeToBytes:B,decodeUnsafe:M,fromWords:u,fromWordsUnsafe:h,toWords:d}}const bech32$1=genBech32$1("bech32");genBech32$1("bech32m");const utf8$1={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},hex$1=chain$1(radix2$1(4),alphabet$1("0123456789abcdef"),join$1(""),normalize$1(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})),CODERS$1={utf8:utf8$1,hex:hex$1,base16:base16$1,base32:base32$1,base64:base64$1,base64url:base64url$1,base58:base58$1,base58xmr:base58xmr$1};`${Object.keys(CODERS$1).join(", ")}`;function number$1(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function bool$1(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function isBytes$1(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function bytes$1(e,...t){if(!isBytes$1(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */const u32$1=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),isLE$1=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE$1)throw new Error("Non little-endian hardware is not supported");const hexes$1=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex$1(e){bytes$1(e);let t="";for(let a=0;a<e.length;a++)t+=hexes$1[e[a]];return t}const asciis$1={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function asciiToBase16$1(e){if(e>=asciis$1._0&&e<=asciis$1._9)return e-asciis$1._0;if(e>=asciis$1._A&&e<=asciis$1._F)return e-(asciis$1._A-10);if(e>=asciis$1._a&&e<=asciis$1._f)return e-(asciis$1._a-10)}function hexToBytes$1(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length,a=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const u=new Uint8Array(a);for(let d=0,h=0;d<a;d++,h+=2){const w=asciiToBase16$1(e.charCodeAt(h)),x=asciiToBase16$1(e.charCodeAt(h+1));if(w===void 0||x===void 0){const M=e[h]+e[h+1];throw new Error('hex string expected, got non-hex character "'+M+'" at index '+h)}u[d]=w*16+x}return u}function checkOpts$1(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function equalBytes$1(e,t){if(e.length!==t.length)return!1;let a=0;for(let u=0;u<e.length;u++)a|=e[u]^t[u];return a===0}const wrapCipher$1=(e,t)=>(Object.assign(t,e),t),BLOCK_SIZE$1=16,POLY$1=283;function mul2$1(e){return e<<1^POLY$1&-(e>>7)}function mul$1(e,t){let a=0;for(;t>0;t>>=1)a^=e&-(t&1),e=mul2$1(e);return a}const sbox$1=(()=>{let e=new Uint8Array(256);for(let a=0,u=1;a<256;a++,u^=mul2$1(u))e[a]=u;const t=new Uint8Array(256);t[0]=99;for(let a=0;a<255;a++){let u=e[255-a];u|=u<<8,t[e[a]]=(u^u>>4^u>>5^u>>6^u>>7^99)&255}return t})(),invSbox$1=sbox$1.map((e,t)=>sbox$1.indexOf(t)),rotr32_8$1=e=>e<<24|e>>>8,rotl32_8$1=e=>e<<8|e>>>24;function genTtable$1(e,t){if(e.length!==256)throw new Error("Wrong sbox length");const a=new Uint32Array(256).map((B,E)=>t(e[E])),u=a.map(rotl32_8$1),d=u.map(rotl32_8$1),h=d.map(rotl32_8$1),w=new Uint32Array(256*256),x=new Uint32Array(256*256),M=new Uint16Array(256*256);for(let B=0;B<256;B++)for(let E=0;E<256;E++){const S=B*256+E;w[S]=a[B]^u[E],x[S]=d[B]^h[E],M[S]=e[B]<<8|e[E]}return{sbox:e,sbox2:M,T0:a,T1:u,T2:d,T3:h,T01:w,T23:x}}const tableEncoding$1=genTtable$1(sbox$1,e=>mul$1(e,3)<<24|e<<16|e<<8|mul$1(e,2)),tableDecoding$1=genTtable$1(invSbox$1,e=>mul$1(e,11)<<24|mul$1(e,13)<<16|mul$1(e,9)<<8|mul$1(e,14)),xPowers$1=(()=>{const e=new Uint8Array(16);for(let t=0,a=1;t<16;t++,a=mul2$1(a))e[t]=a;return e})();function expandKeyLE$1(e){bytes$1(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:a}=tableEncoding$1,u=u32$1(e),d=u.length,h=x=>applySbox$1(a,x,x,x,x),w=new Uint32Array(t+28);w.set(u);for(let x=d;x<w.length;x++){let M=w[x-1];x%d===0?M=h(rotr32_8$1(M))^xPowers$1[x/d-1]:d>6&&x%d===4&&(M=h(M)),w[x]=w[x-d]^M}return w}function expandKeyDecLE$1(e){const t=expandKeyLE$1(e),a=t.slice(),u=t.length,{sbox2:d}=tableEncoding$1,{T0:h,T1:w,T2:x,T3:M}=tableDecoding$1;for(let B=0;B<u;B+=4)for(let E=0;E<4;E++)a[B+E]=t[u-B-4+E];t.fill(0);for(let B=4;B<u-4;B++){const E=a[B],S=applySbox$1(d,E,E,E,E);a[B]=h[S&255]^w[S>>>8&255]^x[S>>>16&255]^M[S>>>24]}return a}function apply0123$1(e,t,a,u,d,h){return e[a<<8&65280|u>>>8&255]^t[d>>>8&65280|h>>>24&255]}function applySbox$1(e,t,a,u,d){return e[t&255|a&65280]|e[u>>>16&255|d>>>16&65280]<<16}function encrypt$2(e,t,a,u,d){const{sbox2:h,T01:w,T23:x}=tableEncoding$1;let M=0;t^=e[M++],a^=e[M++],u^=e[M++],d^=e[M++];const B=e.length/4-2;for(let D=0;D<B;D++){const O=e[M++]^apply0123$1(w,x,t,a,u,d),F=e[M++]^apply0123$1(w,x,a,u,d,t),P=e[M++]^apply0123$1(w,x,u,d,t,a),L=e[M++]^apply0123$1(w,x,d,t,a,u);t=O,a=F,u=P,d=L}const E=e[M++]^applySbox$1(h,t,a,u,d),S=e[M++]^applySbox$1(h,a,u,d,t),k=e[M++]^applySbox$1(h,u,d,t,a),C=e[M++]^applySbox$1(h,d,t,a,u);return{s0:E,s1:S,s2:k,s3:C}}function decrypt$3(e,t,a,u,d){const{sbox2:h,T01:w,T23:x}=tableDecoding$1;let M=0;t^=e[M++],a^=e[M++],u^=e[M++],d^=e[M++];const B=e.length/4-2;for(let D=0;D<B;D++){const O=e[M++]^apply0123$1(w,x,t,d,u,a),F=e[M++]^apply0123$1(w,x,a,t,d,u),P=e[M++]^apply0123$1(w,x,u,a,t,d),L=e[M++]^apply0123$1(w,x,d,u,a,t);t=O,a=F,u=P,d=L}const E=e[M++]^applySbox$1(h,t,d,u,a),S=e[M++]^applySbox$1(h,a,t,d,u),k=e[M++]^applySbox$1(h,u,a,t,d),C=e[M++]^applySbox$1(h,d,u,a,t);return{s0:E,s1:S,s2:k,s3:C}}function getDst$1(e,t){if(!t)return new Uint8Array(e);if(bytes$1(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function validateBlockDecrypt$1(e){if(bytes$1(e),e.length%BLOCK_SIZE$1!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${BLOCK_SIZE$1}`)}function validateBlockEncrypt$1(e,t,a){let u=e.length;const d=u%BLOCK_SIZE$1;if(!t&&d!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const h=u32$1(e);if(t){let M=BLOCK_SIZE$1-d;M||(M=BLOCK_SIZE$1),u=u+M}const w=getDst$1(u,a),x=u32$1(w);return{b:h,o:x,out:w}}function validatePCKS$1(e,t){if(!t)return e;const a=e.length;if(!a)throw new Error("aes/pcks5: empty ciphertext not allowed");const u=e[a-1];if(u<=0||u>16)throw new Error(`aes/pcks5: wrong padding byte: ${u}`);const d=e.subarray(0,-u);for(let h=0;h<u;h++)if(e[a-h-1]!==u)throw new Error("aes/pcks5: wrong padding");return d}function padPCKS$1(e){const t=new Uint8Array(16),a=u32$1(t);t.set(e);const u=BLOCK_SIZE$1-e.length;for(let d=BLOCK_SIZE$1-u;d<BLOCK_SIZE$1;d++)t[d]=u;return a}const cbc$3=wrapCipher$1({blockSize:16,nonceLength:16},function(t,a,u={}){bytes$1(t),bytes$1(a,16);const d=!u.disablePadding;return{encrypt:(h,w)=>{const x=expandKeyLE$1(t),{b:M,o:B,out:E}=validateBlockEncrypt$1(h,d,w),S=u32$1(a);let k=S[0],C=S[1],D=S[2],O=S[3],F=0;for(;F+4<=M.length;)k^=M[F+0],C^=M[F+1],D^=M[F+2],O^=M[F+3],{s0:k,s1:C,s2:D,s3:O}=encrypt$2(x,k,C,D,O),B[F++]=k,B[F++]=C,B[F++]=D,B[F++]=O;if(d){const P=padPCKS$1(h.subarray(F*4));k^=P[0],C^=P[1],D^=P[2],O^=P[3],{s0:k,s1:C,s2:D,s3:O}=encrypt$2(x,k,C,D,O),B[F++]=k,B[F++]=C,B[F++]=D,B[F++]=O}return x.fill(0),E},decrypt:(h,w)=>{validateBlockDecrypt$1(h);const x=expandKeyDecLE$1(t),M=u32$1(a),B=getDst$1(h.length,w),E=u32$1(h),S=u32$1(B);let k=M[0],C=M[1],D=M[2],O=M[3];for(let F=0;F+4<=E.length;){const P=k,L=C,J=D,Y=O;k=E[F+0],C=E[F+1],D=E[F+2],O=E[F+3];const{s0:ae,s1:oe,s2:ue,s3:se}=decrypt$3(x,k,C,D,O);S[F++]=ae^P,S[F++]=oe^L,S[F++]=ue^J,S[F++]=se^Y}return x.fill(0),validatePCKS$1(B,d)}}}),_utf8ToBytes$1=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),sigma16$1=_utf8ToBytes$1("expand 16-byte k"),sigma32$1=_utf8ToBytes$1("expand 32-byte k"),sigma16_32$1=u32$1(sigma16$1),sigma32_32$1=u32$1(sigma32$1);sigma32_32$1.slice();function rotl$3(e,t){return e<<t|e>>>32-t}function isAligned32$1(e){return e.byteOffset%4===0}const BLOCK_LEN$1=64,BLOCK_LEN32$1=16,MAX_COUNTER$1=2**32-1,U32_EMPTY$1=new Uint32Array;function runCipher$1(e,t,a,u,d,h,w,x){const M=d.length,B=new Uint8Array(BLOCK_LEN$1),E=u32$1(B),S=isAligned32$1(d)&&isAligned32$1(h),k=S?u32$1(d):U32_EMPTY$1,C=S?u32$1(h):U32_EMPTY$1;for(let D=0;D<M;w++){if(e(t,a,u,E,w,x),w>=MAX_COUNTER$1)throw new Error("arx: counter overflow");const O=Math.min(BLOCK_LEN$1,M-D);if(S&&O===BLOCK_LEN$1){const F=D/4;if(D%4!==0)throw new Error("arx: invalid block position");for(let P=0,L;P<BLOCK_LEN32$1;P++)L=F+P,C[L]=k[L]^E[P];D+=BLOCK_LEN$1;continue}for(let F=0,P;F<O;F++)P=D+F,h[P]=d[P]^B[F];D+=O}}function createCipher$3(e,t){const{allowShortKeys:a,extendNonceFn:u,counterLength:d,counterRight:h,rounds:w}=checkOpts$1({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return number$1(d),number$1(w),bool$1(h),bool$1(a),(x,M,B,E,S=0)=>{bytes$1(x),bytes$1(M),bytes$1(B);const k=B.length;if(E||(E=new Uint8Array(k)),bytes$1(E),number$1(S),S<0||S>=MAX_COUNTER$1)throw new Error("arx: counter overflow");if(E.length<k)throw new Error(`arx: output (${E.length}) is shorter than data (${k})`);const C=[];let D=x.length,O,F;if(D===32)O=x.slice(),C.push(O),F=sigma32_32$1;else if(D===16&&a)O=new Uint8Array(32),O.set(x),O.set(x,16),F=sigma16_32$1,C.push(O);else throw new Error(`arx: invalid 32-byte key, got length=${D}`);isAligned32$1(M)||(M=M.slice(),C.push(M));const P=u32$1(O);if(u){if(M.length!==24)throw new Error("arx: extended nonce must be 24 bytes");u(F,P,u32$1(M.subarray(0,16)),P),M=M.subarray(16)}const L=16-d;if(L!==M.length)throw new Error(`arx: nonce must be ${L} or 16 bytes`);if(L!==12){const Y=new Uint8Array(12);Y.set(M,h?0:12-M.length),M=Y,C.push(M)}const J=u32$1(M);for(runCipher$1(e,F,P,J,B,E,S,w);C.length>0;)C.pop().fill(0);return E}}function chachaCore$1(e,t,a,u,d,h=20){let w=e[0],x=e[1],M=e[2],B=e[3],E=t[0],S=t[1],k=t[2],C=t[3],D=t[4],O=t[5],F=t[6],P=t[7],L=d,J=a[0],Y=a[1],ae=a[2],oe=w,ue=x,se=M,ie=B,ce=E,$=S,n=k,l=C,c=D,p=O,y=F,b=P,_=L,v=J,o=Y,m=ae;for(let I=0;I<h;I+=2)oe=oe+ce|0,_=rotl$3(_^oe,16),c=c+_|0,ce=rotl$3(ce^c,12),oe=oe+ce|0,_=rotl$3(_^oe,8),c=c+_|0,ce=rotl$3(ce^c,7),ue=ue+$|0,v=rotl$3(v^ue,16),p=p+v|0,$=rotl$3($^p,12),ue=ue+$|0,v=rotl$3(v^ue,8),p=p+v|0,$=rotl$3($^p,7),se=se+n|0,o=rotl$3(o^se,16),y=y+o|0,n=rotl$3(n^y,12),se=se+n|0,o=rotl$3(o^se,8),y=y+o|0,n=rotl$3(n^y,7),ie=ie+l|0,m=rotl$3(m^ie,16),b=b+m|0,l=rotl$3(l^b,12),ie=ie+l|0,m=rotl$3(m^ie,8),b=b+m|0,l=rotl$3(l^b,7),oe=oe+$|0,m=rotl$3(m^oe,16),y=y+m|0,$=rotl$3($^y,12),oe=oe+$|0,m=rotl$3(m^oe,8),y=y+m|0,$=rotl$3($^y,7),ue=ue+n|0,_=rotl$3(_^ue,16),b=b+_|0,n=rotl$3(n^b,12),ue=ue+n|0,_=rotl$3(_^ue,8),b=b+_|0,n=rotl$3(n^b,7),se=se+l|0,v=rotl$3(v^se,16),c=c+v|0,l=rotl$3(l^c,12),se=se+l|0,v=rotl$3(v^se,8),c=c+v|0,l=rotl$3(l^c,7),ie=ie+ce|0,o=rotl$3(o^ie,16),p=p+o|0,ce=rotl$3(ce^p,12),ie=ie+ce|0,o=rotl$3(o^ie,8),p=p+o|0,ce=rotl$3(ce^p,7);let A=0;u[A++]=w+oe|0,u[A++]=x+ue|0,u[A++]=M+se|0,u[A++]=B+ie|0,u[A++]=E+ce|0,u[A++]=S+$|0,u[A++]=k+n|0,u[A++]=C+l|0,u[A++]=D+c|0,u[A++]=O+p|0,u[A++]=F+y|0,u[A++]=P+b|0,u[A++]=L+_|0,u[A++]=J+v|0,u[A++]=Y+o|0,u[A++]=ae+m|0}const chacha20$1=createCipher$3(chachaCore$1,{counterRight:!1,counterLength:4,allowShortKeys:!1});let HMAC$1=class extends Hash$9{constructor(t,a){super(),this.finished=!1,this.destroyed=!1,assert$k.hash(t);const u=toBytes$1(a);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const d=this.blockLen,h=new Uint8Array(d);h.set(u.length>d?t.create().update(u).digest():u);for(let w=0;w<h.length;w++)h[w]^=54;this.iHash.update(h),this.oHash=t.create();for(let w=0;w<h.length;w++)h[w]^=106;this.oHash.update(h),h.fill(0)}update(t){return assert$k.exists(this),this.iHash.update(t),this}digestInto(t){assert$k.exists(this),assert$k.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:a,iHash:u,finished:d,destroyed:h,blockLen:w,outputLen:x}=this;return t=t,t.finished=d,t.destroyed=h,t.blockLen=w,t.outputLen=x,t.oHash=a._cloneInto(t.oHash),t.iHash=u._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const hmac$2=(e,t,a)=>new HMAC$1(e,t).update(a).digest();hmac$2.create=(e,t)=>new HMAC$1(e,t);function extract$1(e,t,a){return assert$k.hash(e),hmac$2(e,toBytes$1(a),toBytes$1(t))}const HKDF_COUNTER$1=new Uint8Array([0]),EMPTY_BUFFER$1=new Uint8Array;function expand$1(e,t,a,u=32){if(assert$k.hash(e),assert$k.number(u),u>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const d=Math.ceil(u/e.outputLen);a===void 0&&(a=EMPTY_BUFFER$1);const h=new Uint8Array(d*e.outputLen),w=hmac$2.create(e,t),x=w._cloneInto(),M=new Uint8Array(w.outputLen);for(let B=0;B<d;B++)HKDF_COUNTER$1[0]=B+1,x.update(B===0?EMPTY_BUFFER$1:M).update(a).update(HKDF_COUNTER$1).digestInto(M),h.set(M,e.outputLen*B),w._cloneInto(x);return w.destroy(),x.destroy(),M.fill(0),HKDF_COUNTER$1.fill(0),h.slice(0,u)}var __defProp$1=Object.defineProperty,__export$1=(e,t)=>{for(var a in t)__defProp$1(e,a,{get:t[a],enumerable:!0})},verifiedSymbol$1=Symbol("verified"),isRecord$1=e=>e instanceof Object;function validateEvent$1(e){if(!isRecord$1(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let a=e.tags[t];if(!Array.isArray(a))return!1;for(let u=0;u<a.length;u++)if(typeof a[u]!="string")return!1}return!0}var utils_exports$1={};__export$1(utils_exports$1,{Queue:()=>Queue$1,QueueNode:()=>QueueNode$1,binarySearch:()=>binarySearch$1,bytesToHex:()=>bytesToHex$2,hexToBytes:()=>hexToBytes$2,insertEventIntoAscendingList:()=>insertEventIntoAscendingList$1,insertEventIntoDescendingList:()=>insertEventIntoDescendingList$1,normalizeURL:()=>normalizeURL$1,utf8Decoder:()=>utf8Decoder,utf8Encoder:()=>utf8Encoder$1});var utf8Decoder=new TextDecoder("utf-8"),utf8Encoder$1=new TextEncoder;function normalizeURL$1(e){try{e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.protocol==="http:"?t.protocol="ws:":t.protocol==="https:"&&(t.protocol="wss:"),t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch{throw new Error(`Invalid URL: ${e}`)}}function insertEventIntoDescendingList$1(e,t){const[a,u]=binarySearch$1(e,d=>t.id===d.id?0:t.created_at===d.created_at?-1:d.created_at-t.created_at);return u||e.splice(a,0,t),e}function insertEventIntoAscendingList$1(e,t){const[a,u]=binarySearch$1(e,d=>t.id===d.id?0:t.created_at===d.created_at?-1:t.created_at-d.created_at);return u||e.splice(a,0,t),e}function binarySearch$1(e,t){let a=0,u=e.length-1;for(;a<=u;){const d=Math.floor((a+u)/2),h=t(e[d]);if(h===0)return[d,!0];h<0?u=d-1:a=d+1}return[a,!1]}var QueueNode$1=class{constructor(t){_e(this,"value");_e(this,"next",null);_e(this,"prev",null);this.value=t}},Queue$1=class{constructor(){_e(this,"first");_e(this,"last");this.first=null,this.last=null}enqueue(t){const a=new QueueNode$1(t);return this.last?this.last===this.first?(this.last=a,this.last.prev=this.first,this.first.next=a):(a.prev=this.last,this.last.next=a,this.last=a):(this.first=a,this.last=a),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const a=this.first;return this.first=null,this.last=null,a.value}const t=this.first;return this.first=t.next,this.first&&(this.first.prev=null),t.value}},JS$1=class{generateSecretKey(){return schnorr$1.utils.randomPrivateKey()}getPublicKey(t){return bytesToHex$2(schnorr$1.getPublicKey(t))}finalizeEvent(t,a){const u=t;return u.pubkey=bytesToHex$2(schnorr$1.getPublicKey(a)),u.id=getEventHash$1(u),u.sig=bytesToHex$2(schnorr$1.sign(getEventHash$1(u),a)),u[verifiedSymbol$1]=!0,u}verifyEvent(t){if(typeof t[verifiedSymbol$1]=="boolean")return t[verifiedSymbol$1];const a=getEventHash$1(t);if(a!==t.id)return t[verifiedSymbol$1]=!1,!1;try{const u=schnorr$1.verify(t.sig,a,t.pubkey);return t[verifiedSymbol$1]=u,u}catch{return t[verifiedSymbol$1]=!1,!1}}};function serializeEvent$1(e){if(!validateEvent$1(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function getEventHash$1(e){let t=sha256$3(utf8Encoder$1.encode(serializeEvent$1(e)));return bytesToHex$2(t)}var i$1=new JS$1,generateSecretKey=i$1.generateSecretKey,getPublicKey$1=i$1.getPublicKey,finalizeEvent$1=i$1.finalizeEvent,verifyEvent=i$1.verifyEvent,kinds_exports$1={};__export$1(kinds_exports$1,{Application:()=>Application$1,BadgeAward:()=>BadgeAward$1,BadgeDefinition:()=>BadgeDefinition$1,BlockedRelaysList:()=>BlockedRelaysList$1,BlossomServerList:()=>BlossomServerList$1,BookmarkList:()=>BookmarkList$1,Bookmarksets:()=>Bookmarksets$1,Calendar:()=>Calendar$1,CalendarEventRSVP:()=>CalendarEventRSVP$1,ChannelCreation:()=>ChannelCreation$1,ChannelHideMessage:()=>ChannelHideMessage$1,ChannelMessage:()=>ChannelMessage$1,ChannelMetadata:()=>ChannelMetadata$1,ChannelMuteUser:()=>ChannelMuteUser$1,ChatMessage:()=>ChatMessage$1,ClassifiedListing:()=>ClassifiedListing$1,ClientAuth:()=>ClientAuth$1,Comment:()=>Comment$1,CommunitiesList:()=>CommunitiesList$1,CommunityDefinition:()=>CommunityDefinition$1,CommunityPostApproval:()=>CommunityPostApproval$1,Contacts:()=>Contacts$1,CreateOrUpdateProduct:()=>CreateOrUpdateProduct$1,CreateOrUpdateStall:()=>CreateOrUpdateStall$1,Curationsets:()=>Curationsets$1,Date:()=>Date2$1,DirectMessageRelaysList:()=>DirectMessageRelaysList$1,DraftClassifiedListing:()=>DraftClassifiedListing$1,DraftLong:()=>DraftLong$1,Emojisets:()=>Emojisets$1,EncryptedDirectMessage:()=>EncryptedDirectMessage$1,EventDeletion:()=>EventDeletion$1,FavoriteRelays:()=>FavoriteRelays$1,FileMessage:()=>FileMessage$1,FileMetadata:()=>FileMetadata$1,FileServerPreference:()=>FileServerPreference$1,Followsets:()=>Followsets$1,ForumThread:()=>ForumThread$1,GenericRepost:()=>GenericRepost$1,Genericlists:()=>Genericlists$1,GiftWrap:()=>GiftWrap$1,GroupMetadata:()=>GroupMetadata$1,HTTPAuth:()=>HTTPAuth$1,Handlerinformation:()=>Handlerinformation$1,Handlerrecommendation:()=>Handlerrecommendation$1,Highlights:()=>Highlights$1,InterestsList:()=>InterestsList$1,Interestsets:()=>Interestsets$1,JobFeedback:()=>JobFeedback$1,JobRequest:()=>JobRequest$1,JobResult:()=>JobResult$1,Label:()=>Label$1,LightningPubRPC:()=>LightningPubRPC$1,LiveChatMessage:()=>LiveChatMessage$1,LiveEvent:()=>LiveEvent$1,LongFormArticle:()=>LongFormArticle$1,Metadata:()=>Metadata$1,Mutelist:()=>Mutelist$1,NWCWalletInfo:()=>NWCWalletInfo$1,NWCWalletRequest:()=>NWCWalletRequest$1,NWCWalletResponse:()=>NWCWalletResponse$1,NormalVideo:()=>NormalVideo$1,NostrConnect:()=>NostrConnect$1,OpenTimestamps:()=>OpenTimestamps$1,Photo:()=>Photo$1,Pinlist:()=>Pinlist$1,Poll:()=>Poll$1,PollResponse:()=>PollResponse$1,PrivateDirectMessage:()=>PrivateDirectMessage$1,ProblemTracker:()=>ProblemTracker$1,ProfileBadges:()=>ProfileBadges$1,PublicChatsList:()=>PublicChatsList$1,Reaction:()=>Reaction$1,RecommendRelay:()=>RecommendRelay$1,RelayList:()=>RelayList$1,RelayReview:()=>RelayReview$1,Relaysets:()=>Relaysets$1,Report:()=>Report$1,Reporting:()=>Reporting$1,Repost:()=>Repost$1,Seal:()=>Seal$1,SearchRelaysList:()=>SearchRelaysList$1,ShortTextNote:()=>ShortTextNote$1,ShortVideo:()=>ShortVideo$1,Time:()=>Time$2,UserEmojiList:()=>UserEmojiList$1,UserStatuses:()=>UserStatuses$1,Voice:()=>Voice$1,VoiceComment:()=>VoiceComment$1,Zap:()=>Zap$1,ZapGoal:()=>ZapGoal$1,ZapRequest:()=>ZapRequest$1,classifyKind:()=>classifyKind$1,isAddressableKind:()=>isAddressableKind$1,isEphemeralKind:()=>isEphemeralKind$1,isKind:()=>isKind$1,isRegularKind:()=>isRegularKind$1,isReplaceableKind:()=>isReplaceableKind$1});function isRegularKind$1(e){return e<1e4&&e!==0&&e!==3}function isReplaceableKind$1(e){return e===0||e===3||1e4<=e&&e<2e4}function isEphemeralKind$1(e){return 2e4<=e&&e<3e4}function isAddressableKind$1(e){return 3e4<=e&&e<4e4}function classifyKind$1(e){return isRegularKind$1(e)?"regular":isReplaceableKind$1(e)?"replaceable":isEphemeralKind$1(e)?"ephemeral":isAddressableKind$1(e)?"parameterized":"unknown"}function isKind$1(e,t){const a=t instanceof Array?t:[t];return validateEvent$1(e)&&a.includes(e.kind)||!1}var Metadata$1=0,ShortTextNote$1=1,RecommendRelay$1=2,Contacts$1=3,EncryptedDirectMessage$1=4,EventDeletion$1=5,Repost$1=6,Reaction$1=7,BadgeAward$1=8,ChatMessage$1=9,ForumThread$1=11,Seal$1=13,PrivateDirectMessage$1=14,FileMessage$1=15,GenericRepost$1=16,Photo$1=20,NormalVideo$1=21,ShortVideo$1=22,ChannelCreation$1=40,ChannelMetadata$1=41,ChannelMessage$1=42,ChannelHideMessage$1=43,ChannelMuteUser$1=44,OpenTimestamps$1=1040,GiftWrap$1=1059,Poll$1=1068,FileMetadata$1=1063,Comment$1=1111,LiveChatMessage$1=1311,Voice$1=1222,VoiceComment$1=1244,ProblemTracker$1=1971,Report$1=1984,Reporting$1=1984,Label$1=1985,CommunityPostApproval$1=4550,JobRequest$1=5999,JobResult$1=6999,JobFeedback$1=7e3,ZapGoal$1=9041,ZapRequest$1=9734,Zap$1=9735,Highlights$1=9802,PollResponse$1=1018,Mutelist$1=1e4,Pinlist$1=10001,RelayList$1=10002,BookmarkList$1=10003,CommunitiesList$1=10004,PublicChatsList$1=10005,BlockedRelaysList$1=10006,SearchRelaysList$1=10007,FavoriteRelays$1=10012,InterestsList$1=10015,UserEmojiList$1=10030,DirectMessageRelaysList$1=10050,FileServerPreference$1=10096,BlossomServerList$1=10063,NWCWalletInfo$1=13194,LightningPubRPC$1=21e3,ClientAuth$1=22242,NWCWalletRequest$1=23194,NWCWalletResponse$1=23195,NostrConnect$1=24133,HTTPAuth$1=27235,Followsets$1=3e4,Genericlists$1=30001,Relaysets$1=30002,Bookmarksets$1=30003,Curationsets$1=30004,ProfileBadges$1=30008,BadgeDefinition$1=30009,Interestsets$1=30015,CreateOrUpdateStall$1=30017,CreateOrUpdateProduct$1=30018,LongFormArticle$1=30023,DraftLong$1=30024,Emojisets$1=30030,Application$1=30078,LiveEvent$1=30311,UserStatuses$1=30315,ClassifiedListing$1=30402,DraftClassifiedListing$1=30403,Date2$1=31922,Time$2=31923,Calendar$1=31924,CalendarEventRSVP$1=31925,RelayReview$1=31987,Handlerrecommendation$1=31989,Handlerinformation$1=31990,CommunityDefinition$1=34550,GroupMetadata$1=39e3;function matchFilter$1(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1)return!1;for(let a in e)if(a[0]==="#"){let u=a.slice(1),d=e[`#${u}`];if(d&&!t.tags.find(([h,w])=>h===a.slice(1)&&d.indexOf(w)!==-1))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function matchFilters$1(e,t){for(let a=0;a<e.length;a++)if(matchFilter$1(e[a],t))return!0;return!1}var fakejson_exports$1={};__export$1(fakejson_exports$1,{getHex64:()=>getHex64$1,getInt:()=>getInt$1,getSubscriptionId:()=>getSubscriptionId$1,matchEventId:()=>matchEventId$1,matchEventKind:()=>matchEventKind$1,matchEventPubkey:()=>matchEventPubkey$1});function getHex64$1(e,t){let a=t.length+3,u=e.indexOf(`"${t}":`)+a,d=e.slice(u).indexOf('"')+u+1;return e.slice(d,d+64)}function getInt$1(e,t){let a=t.length,u=e.indexOf(`"${t}":`)+a+3,d=e.slice(u),h=Math.min(d.indexOf(","),d.indexOf("}"));return parseInt(d.slice(0,h),10)}function getSubscriptionId$1(e){let t=e.slice(0,22).indexOf('"EVENT"');if(t===-1)return null;let a=e.slice(t+7+1).indexOf('"');if(a===-1)return null;let u=t+7+1+a,d=e.slice(u+1,80).indexOf('"');if(d===-1)return null;let h=u+1+d;return e.slice(u+1,h)}function matchEventId$1(e,t){return t===getHex64$1(e,"id")}function matchEventPubkey$1(e,t){return t===getHex64$1(e,"pubkey")}function matchEventKind$1(e,t){return t===getInt$1(e,"kind")}var nip42_exports$1={};__export$1(nip42_exports$1,{makeAuthEvent:()=>makeAuthEvent$1});function makeAuthEvent$1(e,t){return{kind:ClientAuth$1,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function yieldThread$1(){return new Promise((e,t)=>{try{if(typeof MessageChannel<"u"){const a=new MessageChannel,u=()=>{a.port1.removeEventListener("message",u),e()};a.port1.addEventListener("message",u),a.port2.postMessage(0),a.port1.start()}else typeof setImmediate<"u"?setImmediate(e):typeof setTimeout<"u"?setTimeout(e,0):e()}catch(a){console.error("during yield: ",a),t(a)}})}var alwaysTrue$1=e=>(e[verifiedSymbol$1]=!0,!0),SendingOnClosedConnection$1=class extends Error{constructor(t,a){super(`Tried to send message '${t} on a closed connection to ${a}.`),this.name="SendingOnClosedConnection"}},AbstractRelay$1=class{constructor(t,a){_e(this,"url");_e(this,"_connected",!1);_e(this,"onclose",null);_e(this,"onnotice",t=>console.debug(`NOTICE from ${this.url}: ${t}`));_e(this,"onauth");_e(this,"baseEoseTimeout",4400);_e(this,"connectionTimeout",4400);_e(this,"publishTimeout",4400);_e(this,"pingFrequency",29e3);_e(this,"pingTimeout",2e4);_e(this,"resubscribeBackoff",[1e4,1e4,1e4,2e4,2e4,3e4,6e4]);_e(this,"openSubs",new Map);_e(this,"enablePing");_e(this,"enableReconnect");_e(this,"connectionTimeoutHandle");_e(this,"reconnectTimeoutHandle");_e(this,"pingIntervalHandle");_e(this,"reconnectAttempts",0);_e(this,"closedIntentionally",!1);_e(this,"connectionPromise");_e(this,"openCountRequests",new Map);_e(this,"openEventPublishes",new Map);_e(this,"ws");_e(this,"incomingMessageQueue",new Queue$1);_e(this,"queueRunning",!1);_e(this,"challenge");_e(this,"authPromise");_e(this,"serial",0);_e(this,"verifyEvent");_e(this,"_WebSocket");this.url=normalizeURL$1(t),this.verifyEvent=a.verifyEvent,this._WebSocket=a.websocketImplementation||WebSocket,this.enablePing=a.enablePing,this.enableReconnect=a.enableReconnect||!1}static async connect(t,a){const u=new AbstractRelay$1(t,a);return await u.connect(),u}closeAllSubscriptions(t){for(let[a,u]of this.openSubs)u.close(t);this.openSubs.clear();for(let[a,u]of this.openEventPublishes)u.reject(new Error(t));this.openEventPublishes.clear();for(let[a,u]of this.openCountRequests)u.reject(new Error(t));this.openCountRequests.clear()}get connected(){return this._connected}async reconnect(){const t=this.resubscribeBackoff[Math.min(this.reconnectAttempts,this.resubscribeBackoff.length-1)];this.reconnectAttempts++,this.reconnectTimeoutHandle=setTimeout(async()=>{try{await this.connect()}catch{}},t)}handleHardClose(t){var u;this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0;const a=this.closedIntentionally;this.closedIntentionally=!1,(u=this.onclose)==null||u.call(this),this.enableReconnect&&!a?this.reconnect():this.closeAllSubscriptions(t)}async connect(){return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise((t,a)=>{this.connectionTimeoutHandle=setTimeout(()=>{var u;a("connection timed out"),this.connectionPromise=void 0,(u=this.onclose)==null||u.call(this),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(u){clearTimeout(this.connectionTimeoutHandle),a(u);return}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(this.connectionTimeoutHandle),this._connected=!0;const u=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const d of this.openSubs.values()){if(d.eosed=!1,u)for(let h=0;h<d.filters.length;h++)d.lastEmitted&&(d.filters[h].since=d.lastEmitted+1);d.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),t()},this.ws.onerror=u=>{clearTimeout(this.connectionTimeoutHandle),a(u.message||"websocket error"),this.handleHardClose("relay connection errored")},this.ws.onclose=u=>{clearTimeout(this.connectionTimeoutHandle),a(u.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}waitForPingPong(){return new Promise(t=>{this.ws.once("pong",()=>t(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((t,a)=>{if(!this.connectionPromise)return a(new Error(`no connection to ${this.url}, can't ping`));try{const u=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"forced-ping",oneose:()=>{t(!0),u.close()},onclose(){t(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(u){a(u)}})}async pingpong(){var t,a,u;((t=this.ws)==null?void 0:t.readyState)===1&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.once?this.waitForPingPong():this.waitForDummyReq(),new Promise(h=>setTimeout(()=>h(!1),this.pingTimeout))])||((a=this.ws)==null?void 0:a.readyState)===this._WebSocket.OPEN&&((u=this.ws)==null||u.close()))}async runQueue(){for(this.queueRunning=!0;this.handleNext()!==!1;)await yieldThread$1();this.queueRunning=!1}handleNext(){var u,d,h;const t=this.incomingMessageQueue.dequeue();if(!t)return!1;const a=getSubscriptionId$1(t);if(a){const w=this.openSubs.get(a);if(!w)return;const x=getHex64$1(t,"id"),M=(u=w.alreadyHaveEvent)==null?void 0:u.call(w,x);if((d=w.receivedEvent)==null||d.call(w,this,x),M)return}try{let w=JSON.parse(t);switch(w[0]){case"EVENT":{const x=this.openSubs.get(w[1]),M=w[2];this.verifyEvent(M)&&matchFilters$1(x.filters,M)&&x.onevent(M),(!x.lastEmitted||x.lastEmitted<M.created_at)&&(x.lastEmitted=M.created_at);return}case"COUNT":{const x=w[1],M=w[2],B=this.openCountRequests.get(x);B&&(B.resolve(M.count),this.openCountRequests.delete(x));return}case"EOSE":{const x=this.openSubs.get(w[1]);if(!x)return;x.receivedEose();return}case"OK":{const x=w[1],M=w[2],B=w[3],E=this.openEventPublishes.get(x);E&&(clearTimeout(E.timeout),M?E.resolve(B):E.reject(new Error(B)),this.openEventPublishes.delete(x));return}case"CLOSED":{const x=w[1],M=this.openSubs.get(x);if(!M)return;M.closed=!0,M.close(w[2]);return}case"NOTICE":{this.onnotice(w[1]);return}case"AUTH":{this.challenge=w[1],this.onauth&&this.auth(this.onauth);return}default:{const x=this.openSubs.get(w[1]);(h=x==null?void 0:x.oncustom)==null||h.call(x,w);return}}}catch{return}}async send(t){if(!this.connectionPromise)throw new SendingOnClosedConnection$1(t,this.url);this.connectionPromise.then(()=>{var a;(a=this.ws)==null||a.send(t)})}async auth(t){const a=this.challenge;if(!a)throw new Error("can't perform auth, no challenge was received");return this.authPromise?this.authPromise:(this.authPromise=new Promise(async(u,d)=>{try{let h=await t(makeAuthEvent$1(this.url,a)),w=setTimeout(()=>{let x=this.openEventPublishes.get(h.id);x&&(x.reject(new Error("auth timed out")),this.openEventPublishes.delete(h.id))},this.publishTimeout);this.openEventPublishes.set(h.id,{resolve:u,reject:d,timeout:w}),this.send('["AUTH",'+JSON.stringify(h)+"]")}catch(h){console.warn("subscribe auth function failed:",h)}}),this.authPromise)}async publish(t){const a=new Promise((u,d)=>{const h=setTimeout(()=>{const w=this.openEventPublishes.get(t.id);w&&(w.reject(new Error("publish timed out")),this.openEventPublishes.delete(t.id))},this.publishTimeout);this.openEventPublishes.set(t.id,{resolve:u,reject:d,timeout:h})});return this.send('["EVENT",'+JSON.stringify(t)+"]"),a}async count(t,a){this.serial++;const u=(a==null?void 0:a.id)||"count:"+this.serial,d=new Promise((h,w)=>{this.openCountRequests.set(u,{resolve:h,reject:w})});return this.send('["COUNT","'+u+'",'+JSON.stringify(t).substring(1)),d}subscribe(t,a){const u=this.prepareSubscription(t,a);return u.fire(),u}prepareSubscription(t,a){this.serial++;const u=a.id||(a.label?a.label+":":"sub:")+this.serial,d=new Subscription$1(this,u,t,a);return this.openSubs.set(u,d),d}close(){var t,a,u;this.closedIntentionally=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,(t=this.onclose)==null||t.call(this),((a=this.ws)==null?void 0:a.readyState)===this._WebSocket.OPEN&&((u=this.ws)==null||u.close())}_onmessage(t){this.incomingMessageQueue.enqueue(t.data),this.queueRunning||this.runQueue()}},Subscription$1=class{constructor(t,a,u,d){_e(this,"relay");_e(this,"id");_e(this,"lastEmitted");_e(this,"closed",!1);_e(this,"eosed",!1);_e(this,"filters");_e(this,"alreadyHaveEvent");_e(this,"receivedEvent");_e(this,"onevent");_e(this,"oneose");_e(this,"onclose");_e(this,"oncustom");_e(this,"eoseTimeout");_e(this,"eoseTimeoutHandle");if(u.length===0)throw new Error("subscription can't be created with zero filters");this.relay=t,this.filters=u,this.id=a,this.alreadyHaveEvent=d.alreadyHaveEvent,this.receivedEvent=d.receivedEvent,this.eoseTimeout=d.eoseTimeout||t.baseEoseTimeout,this.oneose=d.oneose,this.onclose=d.onclose,this.onevent=d.onevent||(h=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,h)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){var t;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(t=this.oneose)==null||t.call(this))}close(t="closed by caller"){var a;if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(u){if(!(u instanceof SendingOnClosedConnection$1))throw u}this.closed=!0}this.relay.openSubs.delete(this.id),(a=this.onclose)==null||a.call(this,t)}},_WebSocket$1;try{_WebSocket$1=WebSocket}catch{}var AbstractSimplePool$1=class{constructor(t){_e(this,"relays",new Map);_e(this,"seenOn",new Map);_e(this,"trackRelays",!1);_e(this,"verifyEvent");_e(this,"enablePing");_e(this,"enableReconnect");_e(this,"automaticallyAuth");_e(this,"trustedRelayURLs",new Set);_e(this,"_WebSocket");this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation,this.enablePing=t.enablePing,this.enableReconnect=t.enableReconnect||!1,this.automaticallyAuth=t.automaticallyAuth}async ensureRelay(t,a){t=normalizeURL$1(t);let u=this.relays.get(t);if(u||(u=new AbstractRelay$1(t,{verifyEvent:this.trustedRelayURLs.has(t)?alwaysTrue$1:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),u.onclose=()=>{u&&!u.enableReconnect&&this.relays.delete(t)},a!=null&&a.connectionTimeout&&(u.connectionTimeout=a.connectionTimeout),this.relays.set(t,u)),this.automaticallyAuth){const d=this.automaticallyAuth(t);d&&(u.onauth=d)}return await u.connect(),u}close(t){t.map(normalizeURL$1).forEach(a=>{var u;(u=this.relays.get(a))==null||u.close(),this.relays.delete(a)})}subscribe(t,a,u){const d=[];for(let h=0;h<t.length;h++){const w=normalizeURL$1(t[h]);d.find(x=>x.url===w)||d.push({url:w,filter:a})}return this.subscribeMap(d,u)}subscribeMany(t,a,u){const d=[],h=[];for(let w=0;w<t.length;w++){const x=normalizeURL$1(t[w]);h.indexOf(x)===-1&&(h.push(x),d.push({url:x,filter:a}))}return this.subscribeMap(d,u)}subscribeMap(t,a){const u=new Map;for(const C of t){const{url:D,filter:O}=C;u.has(D)||u.set(D,[]),u.get(D).push(O)}const d=Array.from(u.entries()).map(([C,D])=>({url:C,filters:D}));this.trackRelays&&(a.receivedEvent=(C,D)=>{let O=this.seenOn.get(D);O||(O=new Set,this.seenOn.set(D,O)),O.add(C)});const h=new Set,w=[],x=[];let M=C=>{var D;x[C]||(x[C]=!0,x.filter(O=>O).length===d.length&&((D=a.oneose)==null||D.call(a),M=()=>{}))};const B=[];let E=(C,D)=>{var O;B[C]||(M(C),B[C]=D,B.filter(F=>F).length===d.length&&((O=a.onclose)==null||O.call(a,B),E=()=>{}))};const S=C=>{var O;if((O=a.alreadyHaveEvent)!=null&&O.call(a,C))return!0;const D=h.has(C);return h.add(C),D},k=Promise.all(d.map(async({url:C,filters:D},O)=>{let F;try{F=await this.ensureRelay(C,{connectionTimeout:a.maxWait?Math.max(a.maxWait*.8,a.maxWait-1e3):void 0})}catch(L){E(O,(L==null?void 0:L.message)||String(L));return}let P=F.subscribe(D,{...a,oneose:()=>M(O),onclose:L=>{L.startsWith("auth-required: ")&&a.onauth?F.auth(a.onauth).then(()=>{F.subscribe(D,{...a,oneose:()=>M(O),onclose:J=>{E(O,J)},alreadyHaveEvent:S,eoseTimeout:a.maxWait})}).catch(J=>{E(O,`auth was required and attempted, but failed with: ${J}`)}):E(O,L)},alreadyHaveEvent:S,eoseTimeout:a.maxWait});w.push(P)}));return{async close(C){await k,w.forEach(D=>{D.close(C)})}}}subscribeEose(t,a,u){const d=this.subscribe(t,a,{...u,oneose(){d.close("closed automatically on eose")}});return d}subscribeManyEose(t,a,u){const d=this.subscribeMany(t,a,{...u,oneose(){d.close("closed automatically on eose")}});return d}async querySync(t,a,u){return new Promise(async d=>{const h=[];this.subscribeEose(t,a,{...u,onevent(w){h.push(w)},onclose(w){d(h)}})})}async get(t,a,u){a.limit=1;const d=await this.querySync(t,a,u);return d.sort((h,w)=>w.created_at-h.created_at),d[0]||null}publish(t,a,u){return t.map(normalizeURL$1).map(async(d,h,w)=>{if(w.indexOf(d)!==h)return Promise.reject("duplicate url");let x=await this.ensureRelay(d);return x.publish(a).catch(async M=>{if(M instanceof Error&&M.message.startsWith("auth-required: ")&&(u!=null&&u.onauth))return await x.auth(u.onauth),x.publish(a);throw M}).then(M=>{if(this.trackRelays){let B=this.seenOn.get(a.id);B||(B=new Set,this.seenOn.set(a.id,B)),B.add(x)}return M})})}listConnectionStatus(){const t=new Map;return this.relays.forEach((a,u)=>t.set(u,a.connected)),t}destroy(){this.relays.forEach(t=>t.close()),this.relays=new Map}},_WebSocket2$1;try{_WebSocket2$1=WebSocket}catch{}var SimplePool$1=class extends AbstractSimplePool$1{constructor(t){super({verifyEvent,websocketImplementation:_WebSocket2$1,...t})}},nip19_exports$1={};__export$1(nip19_exports$1,{BECH32_REGEX:()=>BECH32_REGEX$1,Bech32MaxSize:()=>Bech32MaxSize$1,NostrTypeGuard:()=>NostrTypeGuard$1,decode:()=>decode$1,decodeNostrURI:()=>decodeNostrURI$1,encodeBytes:()=>encodeBytes$1,naddrEncode:()=>naddrEncode$1,neventEncode:()=>neventEncode$1,noteEncode:()=>noteEncode$1,nprofileEncode:()=>nprofileEncode$1,npubEncode:()=>npubEncode$1,nsecEncode:()=>nsecEncode$1});var NostrTypeGuard$1={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Bech32MaxSize$1=5e3,BECH32_REGEX$1=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function integerToUint8Array$1(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=e&255,t}function decodeNostrURI$1(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),decode$1(e)}catch{return{type:"invalid",data:null}}}function decode$1(e){var d,h,w,x,M,B,E;let{prefix:t,words:a}=bech32$1.decode(e,Bech32MaxSize$1),u=new Uint8Array(bech32$1.fromWords(a));switch(t){case"nprofile":{let S=parseTLV$1(u);if(!((d=S[0])!=null&&d[0]))throw new Error("missing TLV 0 for nprofile");if(S[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:bytesToHex$2(S[0][0]),relays:S[1]?S[1].map(k=>utf8Decoder.decode(k)):[]}}}case"nevent":{let S=parseTLV$1(u);if(!((h=S[0])!=null&&h[0]))throw new Error("missing TLV 0 for nevent");if(S[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(S[2]&&S[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(S[3]&&S[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:bytesToHex$2(S[0][0]),relays:S[1]?S[1].map(k=>utf8Decoder.decode(k)):[],author:(w=S[2])!=null&&w[0]?bytesToHex$2(S[2][0]):void 0,kind:(x=S[3])!=null&&x[0]?parseInt(bytesToHex$2(S[3][0]),16):void 0}}}case"naddr":{let S=parseTLV$1(u);if(!((M=S[0])!=null&&M[0]))throw new Error("missing TLV 0 for naddr");if(!((B=S[2])!=null&&B[0]))throw new Error("missing TLV 2 for naddr");if(S[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((E=S[3])!=null&&E[0]))throw new Error("missing TLV 3 for naddr");if(S[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:utf8Decoder.decode(S[0][0]),pubkey:bytesToHex$2(S[2][0]),kind:parseInt(bytesToHex$2(S[3][0]),16),relays:S[1]?S[1].map(k=>utf8Decoder.decode(k)):[]}}}case"nsec":return{type:t,data:u};case"npub":case"note":return{type:t,data:bytesToHex$2(u)};default:throw new Error(`unknown prefix ${t}`)}}function parseTLV$1(e){let t={},a=e;for(;a.length>0;){let u=a[0],d=a[1],h=a.slice(2,2+d);if(a=a.slice(2+d),h.length<d)throw new Error(`not enough data to read on TLV ${u}`);t[u]=t[u]||[],t[u].push(h)}return t}function nsecEncode$1(e){return encodeBytes$1("nsec",e)}function npubEncode$1(e){return encodeBytes$1("npub",hexToBytes$2(e))}function noteEncode$1(e){return encodeBytes$1("note",hexToBytes$2(e))}function encodeBech32$1(e,t){let a=bech32$1.toWords(t);return bech32$1.encode(e,a,Bech32MaxSize$1)}function encodeBytes$1(e,t){return encodeBech32$1(e,t)}function nprofileEncode$1(e){let t=encodeTLV$1({0:[hexToBytes$2(e.pubkey)],1:(e.relays||[]).map(a=>utf8Encoder$1.encode(a))});return encodeBech32$1("nprofile",t)}function neventEncode$1(e){let t;e.kind!==void 0&&(t=integerToUint8Array$1(e.kind));let a=encodeTLV$1({0:[hexToBytes$2(e.id)],1:(e.relays||[]).map(u=>utf8Encoder$1.encode(u)),2:e.author?[hexToBytes$2(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return encodeBech32$1("nevent",a)}function naddrEncode$1(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let a=encodeTLV$1({0:[utf8Encoder$1.encode(e.identifier)],1:(e.relays||[]).map(u=>utf8Encoder$1.encode(u)),2:[hexToBytes$2(e.pubkey)],3:[new Uint8Array(t)]});return encodeBech32$1("naddr",a)}function encodeTLV$1(e){let t=[];return Object.entries(e).reverse().forEach(([a,u])=>{u.forEach(d=>{let h=new Uint8Array(d.length+2);h.set([parseInt(a)],0),h.set([d.length],1),h.set(d,2),t.push(h)})}),concatBytes$1(...t)}var nip04_exports$1={};__export$1(nip04_exports$1,{decrypt:()=>decrypt$2,encrypt:()=>encrypt$1});function encrypt$1(e,t,a){const u=e instanceof Uint8Array?bytesToHex$2(e):e,d=secp256k1$2.getSharedSecret(u,"02"+t),h=getNormalizedX$1(d);let w=Uint8Array.from(randomBytes$4(16)),x=utf8Encoder$1.encode(a),M=cbc$3(h,w).encrypt(x),B=base64$1.encode(new Uint8Array(M)),E=base64$1.encode(new Uint8Array(w.buffer));return`${B}?iv=${E}`}function decrypt$2(e,t,a){const u=e instanceof Uint8Array?bytesToHex$2(e):e;let[d,h]=a.split("?iv="),w=secp256k1$2.getSharedSecret(u,"02"+t),x=getNormalizedX$1(w),M=base64$1.decode(h),B=base64$1.decode(d),E=cbc$3(x,M).decrypt(B);return utf8Decoder.decode(E)}function getNormalizedX$1(e){return e.slice(1,33)}var nip05_exports$1={};__export$1(nip05_exports$1,{NIP05_REGEX:()=>NIP05_REGEX$1,isNip05:()=>isNip05$1,isValid:()=>isValid$1,queryProfile:()=>queryProfile$1,searchDomain:()=>searchDomain$1,useFetchImplementation:()=>useFetchImplementation$1});var NIP05_REGEX$1=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,isNip05$1=e=>NIP05_REGEX$1.test(e||""),_fetch$1;try{_fetch$1=fetch}catch{}function useFetchImplementation$1(e){_fetch$1=e}async function searchDomain$1(e,t=""){try{const a=`https://${e}/.well-known/nostr.json?name=${t}`,u=await _fetch$1(a,{redirect:"manual"});if(u.status!==200)throw Error("Wrong response code");return(await u.json()).names}catch{return{}}}async function queryProfile$1(e){var d;const t=e.match(NIP05_REGEX$1);if(!t)return null;const[,a="_",u]=t;try{const h=`https://${u}/.well-known/nostr.json?name=${a}`,w=await _fetch$1(h,{redirect:"manual"});if(w.status!==200)throw Error("Wrong response code");const x=await w.json(),M=x.names[a];return M?{pubkey:M,relays:(d=x.relays)==null?void 0:d[M]}:null}catch{return null}}async function isValid$1(e,t){const a=await queryProfile$1(t);return a?a.pubkey===e:!1}var nip10_exports$1={};__export$1(nip10_exports$1,{parse:()=>parse$1});function parse$1(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let a,u;for(let d=e.tags.length-1;d>=0;d--){const h=e.tags[d];if(h[0]==="e"&&h[1]){const[w,x,M,B,E]=h,S={id:x,relays:M?[M]:[],author:E};if(B==="root"){t.root=S;continue}if(B==="reply"){t.reply=S;continue}if(B==="mention"){t.mentions.push(S);continue}a?u=S:a=S,t.mentions.push(S);continue}if(h[0]==="q"&&h[1]){const[w,x,M]=h;t.quotes.push({id:x,relays:M?[M]:[]})}if(h[0]==="p"&&h[1]){t.profiles.push({pubkey:h[1],relays:h[2]?[h[2]]:[]});continue}}return t.root||(t.root=u||a||t.reply),t.reply||(t.reply=a||t.root),[t.reply,t.root].forEach(d=>{if(!d)return;let h=t.mentions.indexOf(d);if(h!==-1&&t.mentions.splice(h,1),d.author){let w=t.profiles.find(x=>x.pubkey===d.author);w&&w.relays&&(d.relays||(d.relays=[]),w.relays.forEach(x=>{var M;((M=d.relays)==null?void 0:M.indexOf(x))===-1&&d.relays.push(x)}),w.relays=d.relays)}}),t.mentions.forEach(d=>{if(d.author){let h=t.profiles.find(w=>w.pubkey===d.author);h&&h.relays&&(d.relays||(d.relays=[]),h.relays.forEach(w=>{d.relays.indexOf(w)===-1&&d.relays.push(w)}),h.relays=d.relays)}}),t}var nip11_exports$1={};__export$1(nip11_exports$1,{fetchRelayInformation:()=>fetchRelayInformation$1,useFetchImplementation:()=>useFetchImplementation2$1});var _fetch2$1;try{_fetch2$1=fetch}catch{}function useFetchImplementation2$1(e){_fetch2$1=e}async function fetchRelayInformation$1(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var nip13_exports$1={};__export$1(nip13_exports$1,{fastEventHash:()=>fastEventHash$1,getPow:()=>getPow$1,minePow:()=>minePow$1});function getPow$1(e){let t=0;for(let a=0;a<64;a+=8){const u=parseInt(e.substring(a,a+8),16);if(u===0)t+=32;else{t+=Math.clz32(u);break}}return t}function minePow$1(e,t){let a=0;const u=e,d=["nonce",a.toString(),t.toString()];for(u.tags.push(d);;){const h=Math.floor(new Date().getTime()/1e3);if(h!==u.created_at&&(a=0,u.created_at=h),d[1]=(++a).toString(),u.id=fastEventHash$1(u),getPow$1(u.id)>=t)break}return u}function fastEventHash$1(e){return bytesToHex$2(sha256$3(utf8Encoder$1.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}var nip17_exports$1={};__export$1(nip17_exports$1,{unwrapEvent:()=>unwrapEvent2$1,unwrapManyEvents:()=>unwrapManyEvents2$1,wrapEvent:()=>wrapEvent2$1,wrapManyEvents:()=>wrapManyEvents2$1});var nip59_exports$1={};__export$1(nip59_exports$1,{createRumor:()=>createRumor$1,createSeal:()=>createSeal$1,createWrap:()=>createWrap$1,unwrapEvent:()=>unwrapEvent$1,unwrapManyEvents:()=>unwrapManyEvents$1,wrapEvent:()=>wrapEvent$1,wrapManyEvents:()=>wrapManyEvents$1});var nip44_exports$1={};__export$1(nip44_exports$1,{decrypt:()=>decrypt2$1,encrypt:()=>encrypt2$1,getConversationKey:()=>getConversationKey$1,v2:()=>v2$1});var minPlaintextSize$1=1,maxPlaintextSize$1=65535;function getConversationKey$1(e,t){const a=secp256k1$2.getSharedSecret(e,"02"+t).subarray(1,33);return extract$1(sha256$3,a,"nip44-v2")}function getMessageKeys$1(e,t){const a=expand$1(sha256$3,e,t,76);return{chacha_key:a.subarray(0,32),chacha_nonce:a.subarray(32,44),hmac_key:a.subarray(44,76)}}function calcPaddedLen$1(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,a=t<=256?32:t/8;return a*(Math.floor((e-1)/a)+1)}function writeU16BE$1(e){if(!Number.isSafeInteger(e)||e<minPlaintextSize$1||e>maxPlaintextSize$1)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}function pad$1(e){const t=utf8Encoder$1.encode(e),a=t.length,u=writeU16BE$1(a),d=new Uint8Array(calcPaddedLen$1(a)-a);return concatBytes$1(u,t,d)}function unpad$2(e){const t=new DataView(e.buffer).getUint16(0),a=e.subarray(2,2+t);if(t<minPlaintextSize$1||t>maxPlaintextSize$1||a.length!==t||e.length!==2+calcPaddedLen$1(t))throw new Error("invalid padding");return utf8Decoder.decode(a)}function hmacAad$1(e,t,a){if(a.length!==32)throw new Error("AAD associated data must be 32 bytes");const u=concatBytes$1(a,t);return hmac$2(sha256$3,e,u)}function decodePayload$1(e){if(typeof e!="string")throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if(e[0]==="#")throw new Error("unknown encryption version");let a;try{a=base64$1.decode(e)}catch(h){throw new Error("invalid base64: "+h.message)}const u=a.length;if(u<99||u>65603)throw new Error("invalid data length: "+u);const d=a[0];if(d!==2)throw new Error("unknown encryption version "+d);return{nonce:a.subarray(1,33),ciphertext:a.subarray(33,-32),mac:a.subarray(-32)}}function encrypt2$1(e,t,a=randomBytes$4(32)){const{chacha_key:u,chacha_nonce:d,hmac_key:h}=getMessageKeys$1(t,a),w=pad$1(e),x=chacha20$1(u,d,w),M=hmacAad$1(h,x,a);return base64$1.encode(concatBytes$1(new Uint8Array([2]),a,x,M))}function decrypt2$1(e,t){const{nonce:a,ciphertext:u,mac:d}=decodePayload$1(e),{chacha_key:h,chacha_nonce:w,hmac_key:x}=getMessageKeys$1(t,a),M=hmacAad$1(x,u,a);if(!equalBytes$1(M,d))throw new Error("invalid MAC");const B=chacha20$1(h,w,u);return unpad$2(B)}var v2$1={utils:{getConversationKey:getConversationKey$1,calcPaddedLen:calcPaddedLen$1},encrypt:encrypt2$1,decrypt:decrypt2$1},TWO_DAYS$1=2*24*60*60,now$1=()=>Math.round(Date.now()/1e3),randomNow$1=()=>Math.round(now$1()-Math.random()*TWO_DAYS$1),nip44ConversationKey$1=(e,t)=>getConversationKey$1(e,t),nip44Encrypt$1=(e,t,a)=>encrypt2$1(JSON.stringify(e),nip44ConversationKey$1(t,a)),nip44Decrypt$1=(e,t)=>JSON.parse(decrypt2$1(e.content,nip44ConversationKey$1(t,e.pubkey)));function createRumor$1(e,t){const a={created_at:now$1(),content:"",tags:[],...e,pubkey:getPublicKey$1(t)};return a.id=getEventHash$1(a),a}function createSeal$1(e,t,a){return finalizeEvent$1({kind:Seal$1,content:nip44Encrypt$1(e,t,a),created_at:randomNow$1(),tags:[]},t)}function createWrap$1(e,t){const a=generateSecretKey();return finalizeEvent$1({kind:GiftWrap$1,content:nip44Encrypt$1(e,a,t),created_at:randomNow$1(),tags:[["p",t]]},a)}function wrapEvent$1(e,t,a){const u=createRumor$1(e,t),d=createSeal$1(u,t,a);return createWrap$1(d,a)}function wrapManyEvents$1(e,t,a){if(!a||a.length===0)throw new Error("At least one recipient is required.");const u=getPublicKey$1(t),d=[wrapEvent$1(e,t,u)];return a.forEach(h=>{d.push(wrapEvent$1(e,t,h))}),d}function unwrapEvent$1(e,t){const a=nip44Decrypt$1(e,t);return nip44Decrypt$1(a,t)}function unwrapManyEvents$1(e,t){let a=[];return e.forEach(u=>{a.push(unwrapEvent$1(u,t))}),a.sort((u,d)=>u.created_at-d.created_at),a}function createEvent$1(e,t,a,u){const d={created_at:Math.ceil(Date.now()/1e3),kind:PrivateDirectMessage$1,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:w,relayUrl:x})=>{d.tags.push(x?["p",w,x]:["p",w])}),u&&d.tags.push(["e",u.eventId,u.relayUrl||"","reply"]),a&&d.tags.push(["subject",a]),d}function wrapEvent2$1(e,t,a,u,d){const h=createEvent$1(t,a,u,d);return wrapEvent$1(h,e,t.publicKey)}function wrapManyEvents2$1(e,t,a,u,d){if(!t||t.length===0)throw new Error("At least one recipient is required.");return[{publicKey:getPublicKey$1(e)},...t].map(w=>wrapEvent2$1(e,w,a,u,d))}var unwrapEvent2$1=unwrapEvent$1,unwrapManyEvents2$1=unwrapManyEvents$1,nip18_exports$1={};__export$1(nip18_exports$1,{finishRepostEvent:()=>finishRepostEvent$1,getRepostedEvent:()=>getRepostedEvent$1,getRepostedEventPointer:()=>getRepostedEventPointer$1});function finishRepostEvent$1(e,t,a,u){var w;let d;const h=[...e.tags??[],["e",t.id,a],["p",t.pubkey]];return t.kind===ShortTextNote$1?d=Repost$1:(d=GenericRepost$1,h.push(["k",String(t.kind)])),finalizeEvent$1({kind:d,tags:h,content:e.content===""||(w=t.tags)!=null&&w.find(x=>x[0]==="-")?"":JSON.stringify(t),created_at:e.created_at},u)}function getRepostedEventPointer$1(e){if(![Repost$1,GenericRepost$1].includes(e.kind))return;let t,a;for(let u=e.tags.length-1;u>=0&&(t===void 0||a===void 0);u--){const d=e.tags[u];d.length>=2&&(d[0]==="e"&&t===void 0?t=d:d[0]==="p"&&a===void 0&&(a=d))}if(t!==void 0)return{id:t[1],relays:[t[2],a==null?void 0:a[2]].filter(u=>typeof u=="string"),author:a==null?void 0:a[1]}}function getRepostedEvent$1(e,{skipVerification:t}={}){const a=getRepostedEventPointer$1(e);if(a===void 0||e.content==="")return;let u;try{u=JSON.parse(e.content)}catch{return}if(u.id===a.id&&!(!t&&!verifyEvent(u)))return u}var nip21_exports$1={};__export$1(nip21_exports$1,{NOSTR_URI_REGEX:()=>NOSTR_URI_REGEX$1,parse:()=>parse2$1,test:()=>test$1});var NOSTR_URI_REGEX$1=new RegExp(`nostr:(${BECH32_REGEX$1.source})`);function test$1(e){return typeof e=="string"&&new RegExp(`^${NOSTR_URI_REGEX$1.source}$`).test(e)}function parse2$1(e){const t=e.match(new RegExp(`^${NOSTR_URI_REGEX$1.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:decode$1(t[1])}}var nip25_exports$1={};__export$1(nip25_exports$1,{finishReactionEvent:()=>finishReactionEvent$1,getReactedEventPointer:()=>getReactedEventPointer$1});function finishReactionEvent$1(e,t,a){const u=t.tags.filter(d=>d.length>=2&&(d[0]==="e"||d[0]==="p"));return finalizeEvent$1({...e,kind:Reaction$1,tags:[...e.tags??[],...u,["e",t.id],["p",t.pubkey]],content:e.content??"+"},a)}function getReactedEventPointer$1(e){if(e.kind!==Reaction$1)return;let t,a;for(let u=e.tags.length-1;u>=0&&(t===void 0||a===void 0);u--){const d=e.tags[u];d.length>=2&&(d[0]==="e"&&t===void 0?t=d:d[0]==="p"&&a===void 0&&(a=d))}if(!(t===void 0||a===void 0))return{id:t[1],relays:[t[2],a[2]].filter(u=>u!==void 0),author:a[1]}}var nip27_exports$1={};__export$1(nip27_exports$1,{parse:()=>parse3$1});var noCharacter$1=/\W/m,noURLCharacter$1=/[^\w\/] |[^\w\/]$|$|,| /m,MAX_HASHTAG_LENGTH$1=42;function*parse3$1(e){let t=[];if(typeof e!="string"){for(let h=0;h<e.tags.length;h++){const w=e.tags[h];w[0]==="emoji"&&w.length>=3&&t.push({type:"emoji",shortcode:w[1],url:w[2]})}e=e.content}const a=e.length;let u=0,d=0;e:for(;d<a;){const h=e.indexOf(":",d),w=e.indexOf("#",d);if(h===-1&&w===-1)break e;if(h===-1||w>=0&&w<h){if(w===0||e[w-1]===" "){const x=e.slice(w+1,w+MAX_HASHTAG_LENGTH$1).match(noCharacter$1),M=x?w+1+x.index:a;yield{type:"text",text:e.slice(u,w)},yield{type:"hashtag",value:e.slice(w+1,M)},d=M,u=d;continue e}d=w+1;continue e}if(e.slice(h-5,h)==="nostr"){const x=e.slice(h+60).match(noCharacter$1),M=x?h+60+x.index:a;try{let B,{data:E,type:S}=decode$1(e.slice(h+1,M));switch(S){case"npub":B={pubkey:E};break;case"note":B={id:E};break;case"nsec":d=M+1;continue;default:B=E}u!==h-5&&(yield{type:"text",text:e.slice(u,h-5)}),yield{type:"reference",pointer:B},d=M,u=d;continue e}catch{d=h+1;continue e}}else if(e.slice(h-5,h)==="https"||e.slice(h-4,h)==="http"){const x=e.slice(h+4).match(noURLCharacter$1),M=x?h+4+x.index:a,B=e[h-1]==="s"?5:4;try{let E=new URL(e.slice(h-B,M));if(E.hostname.indexOf(".")===-1)throw new Error("invalid url");if(u!==h-B&&(yield{type:"text",text:e.slice(u,h-B)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(E.pathname)){yield{type:"image",url:E.toString()},d=M,u=d;continue e}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(E.pathname)){yield{type:"video",url:E.toString()},d=M,u=d;continue e}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(E.pathname)){yield{type:"audio",url:E.toString()},d=M,u=d;continue e}yield{type:"url",url:E.toString()},d=M,u=d;continue e}catch{d=M+1;continue e}}else if(e.slice(h-3,h)==="wss"||e.slice(h-2,h)==="ws"){const x=e.slice(h+4).match(noURLCharacter$1),M=x?h+4+x.index:a,B=e[h-1]==="s"?3:2;try{let E=new URL(e.slice(h-B,M));if(E.hostname.indexOf(".")===-1)throw new Error("invalid ws url");u!==h-B&&(yield{type:"text",text:e.slice(u,h-B)}),yield{type:"relay",url:E.toString()},d=M,u=d;continue e}catch{d=M+1;continue e}}else{for(let x=0;x<t.length;x++){const M=t[x];if(e[h+M.shortcode.length+1]===":"&&e.slice(h+1,h+M.shortcode.length+1)===M.shortcode){u!==h&&(yield{type:"text",text:e.slice(u,h)}),yield M,d=h+M.shortcode.length+2,u=d;continue e}}d=h+1;continue e}}u!==a&&(yield{type:"text",text:e.slice(u)})}var nip28_exports$1={};__export$1(nip28_exports$1,{channelCreateEvent:()=>channelCreateEvent$1,channelHideMessageEvent:()=>channelHideMessageEvent$1,channelMessageEvent:()=>channelMessageEvent$1,channelMetadataEvent:()=>channelMetadataEvent$1,channelMuteUserEvent:()=>channelMuteUserEvent$1});var channelCreateEvent$1=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent$1({kind:ChannelCreation$1,tags:[...e.tags??[]],content:a,created_at:e.created_at},t)},channelMetadataEvent$1=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent$1({kind:ChannelMetadata$1,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:a,created_at:e.created_at},t)},channelMessageEvent$1=(e,t)=>{const a=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&a.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),finalizeEvent$1({kind:ChannelMessage$1,tags:[...a,...e.tags??[]],content:e.content,created_at:e.created_at},t)},channelHideMessageEvent$1=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent$1({kind:ChannelHideMessage$1,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:a,created_at:e.created_at},t)},channelMuteUserEvent$1=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent$1({kind:ChannelMuteUser$1,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:a,created_at:e.created_at},t)},nip30_exports$1={};__export$1(nip30_exports$1,{EMOJI_SHORTCODE_REGEX:()=>EMOJI_SHORTCODE_REGEX$1,matchAll:()=>matchAll$1,regex:()=>regex$1,replaceAll:()=>replaceAll$1});var EMOJI_SHORTCODE_REGEX$1=/:(\w+):/,regex$1=()=>new RegExp(`\\B${EMOJI_SHORTCODE_REGEX$1.source}\\B`,"g");function*matchAll$1(e){const t=e.matchAll(regex$1());for(const a of t)try{const[u,d]=a;yield{shortcode:u,name:d,start:a.index,end:a.index+u.length}}catch{}}function replaceAll$1(e,t){return e.replaceAll(regex$1(),(a,u)=>t({shortcode:a,name:u}))}var nip39_exports$1={};__export$1(nip39_exports$1,{useFetchImplementation:()=>useFetchImplementation3$1,validateGithub:()=>validateGithub$1});var _fetch3$1;try{_fetch3$1=fetch}catch{}function useFetchImplementation3$1(e){_fetch3$1=e}async function validateGithub$1(e,t,a){try{return await(await _fetch3$1(`https://gist.github.com/${t}/${a}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var nip47_exports$1={};__export$1(nip47_exports$1,{makeNwcRequestEvent:()=>makeNwcRequestEvent$1,parseConnectionString:()=>parseConnectionString$1});function parseConnectionString$1(e){const{host:t,pathname:a,searchParams:u}=new URL(e),d=a||t,h=u.get("relay"),w=u.get("secret");if(!d||!h||!w)throw new Error("invalid connection string");return{pubkey:d,relay:h,secret:w}}async function makeNwcRequestEvent$1(e,t,a){const d=encrypt$1(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:a}})),h={kind:NWCWalletRequest$1,created_at:Math.round(Date.now()/1e3),content:d,tags:[["p",e]]};return finalizeEvent$1(h,t)}var nip54_exports$1={};__export$1(nip54_exports$1,{normalizeIdentifier:()=>normalizeIdentifier$1});function normalizeIdentifier$1(e){return e=e.trim().toLowerCase(),e=e.normalize("NFKC"),Array.from(e).map(t=>new RegExp("\\p{Letter}","u").test(t)||new RegExp("\\p{Number}","u").test(t)?t:"-").join("")}var nip57_exports$1={};__export$1(nip57_exports$1,{getSatoshisAmountFromBolt11:()=>getSatoshisAmountFromBolt11$1,getZapEndpoint:()=>getZapEndpoint$1,makeZapReceipt:()=>makeZapReceipt$1,makeZapRequest:()=>makeZapRequest$1,useFetchImplementation:()=>useFetchImplementation4$1,validateZapRequest:()=>validateZapRequest$1});var _fetch4$1;try{_fetch4$1=fetch}catch{}function useFetchImplementation4$1(e){_fetch4$1=e}async function getZapEndpoint$1(e){try{let t="",{lud06:a,lud16:u}=JSON.parse(e.content);if(u){let[w,x]=u.split("@");t=new URL(`/.well-known/lnurlp/${w}`,`https://${x}`).toString()}else if(a){let{words:w}=bech32$1.decode(a,1e3),x=bech32$1.fromWords(w);t=utf8Decoder.decode(x)}else return null;let h=await(await _fetch4$1(t)).json();if(h.allowsNostr&&h.nostrPubkey)return h.callback}catch{}return null}function makeZapRequest$1(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),isReplaceableKind$1(e.event.kind)){const a=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(a)}else if(isAddressableKind$1(e.event.kind)){let a=e.event.tags.find(([d,h])=>d==="d"&&h);if(!a)throw new Error("d tag not found or is empty");const u=["a",`${e.event.kind}:${e.event.pubkey}:${a[1]}`];t.tags.push(u)}t.tags.push(["k",e.event.kind.toString()])}return t}function validateZapRequest$1(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!validateEvent$1(t))return"Zap request is not a valid Nostr event.";if(!verifyEvent(t))return"Invalid signature on zap request.";let a=t.tags.find(([h,w])=>h==="p"&&w);if(!a)return"Zap request doesn't have a 'p' tag.";if(!a[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let u=t.tags.find(([h,w])=>h==="e"&&w);return u&&!u[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([h,w])=>h==="relays"&&w)?null:"Zap request doesn't have a 'relays' tag."}function makeZapReceipt$1({zapRequest:e,preimage:t,bolt11:a,paidAt:u}){let d=JSON.parse(e),h=d.tags.filter(([x])=>x==="e"||x==="p"||x==="a"),w={kind:9735,created_at:Math.round(u.getTime()/1e3),content:"",tags:[...h,["P",d.pubkey],["bolt11",a],["description",e]]};return t&&w.tags.push(["preimage",t]),w}function getSatoshisAmountFromBolt11$1(e){if(e.length<50)return 0;e=e.substring(0,50);const t=e.lastIndexOf("1");if(t===-1)return 0;const a=e.substring(0,t);if(!a.startsWith("lnbc"))return 0;const u=a.substring(4);if(u.length<1)return 0;const d=u[u.length-1],h=d.charCodeAt(0)-48,w=h>=0&&h<=9;let x=u.length-1;if(w&&x++,x<1)return 0;const M=parseInt(u.substring(0,x));switch(d){case"m":return M*1e5;case"u":return M*100;case"n":return M/10;case"p":return M/1e4;default:return M*1e8}}var nip77_exports$1={};__export$1(nip77_exports$1,{Negentropy:()=>Negentropy$1,NegentropyStorageVector:()=>NegentropyStorageVector$1,NegentropySync:()=>NegentropySync$1});var PROTOCOL_VERSION$1=97,ID_SIZE$1=32,FINGERPRINT_SIZE$1=16,Mode$1={Skip:0,Fingerprint:1,IdList:2},WrappedBuffer$1=class{constructor(t){_e(this,"_raw");_e(this,"length");typeof t=="number"?(this._raw=new Uint8Array(t),this.length=0):t instanceof Uint8Array?(this._raw=new Uint8Array(t),this.length=t.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(t){if(t instanceof WrappedBuffer$1&&(t=t.unwrap()),typeof t.length!="number")throw Error("bad length");const a=t.length+this.length;if(this.capacity<a){const u=this._raw,d=Math.max(this.capacity*2,a);this._raw=new Uint8Array(d),this._raw.set(u)}this._raw.set(t,this.length),this.length+=t.length}shift(){const t=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,t}shiftN(t=1){const a=this._raw.subarray(0,t);return this._raw=this._raw.subarray(t),this.length-=t,a}};function decodeVarInt$1(e){let t=0;for(;;){if(e.length===0)throw Error("parse ends prematurely");let a=e.shift();if(t=t<<7|a&127,!(a&128))break}return t}function encodeVarInt$1(e){if(e===0)return new WrappedBuffer$1(new Uint8Array([0]));let t=[];for(;e!==0;)t.push(e&127),e>>>=7;t.reverse();for(let a=0;a<t.length-1;a++)t[a]|=128;return new WrappedBuffer$1(new Uint8Array(t))}function getByte$1(e){return getBytes$1(e,1)[0]}function getBytes$1(e,t){if(e.length<t)throw Error("parse ends prematurely");return e.shiftN(t)}var Accumulator$1=class{constructor(){_e(this,"buf");this.setToZero()}setToZero(){this.buf=new Uint8Array(ID_SIZE$1)}add(t){let a=0,u=0,d=new DataView(this.buf.buffer),h=new DataView(t.buffer);for(let w=0;w<8;w++){let x=w*4,M=d.getUint32(x,!0),B=h.getUint32(x,!0),E=M;E+=a,E+=B,E>4294967295&&(u=1),d.setUint32(x,E&4294967295,!0),a=u,u=0}}negate(){let t=new DataView(this.buf.buffer);for(let u=0;u<8;u++){let d=u*4;t.setUint32(d,~t.getUint32(d,!0))}let a=new Uint8Array(ID_SIZE$1);a[0]=1,this.add(a)}getFingerprint(t){let a=new WrappedBuffer$1;return a.extend(this.buf),a.extend(encodeVarInt$1(t)),sha256$3(a.unwrap()).subarray(0,FINGERPRINT_SIZE$1)}},NegentropyStorageVector$1=class{constructor(){_e(this,"items");_e(this,"sealed");this.items=[],this.sealed=!1}insert(t,a){if(this.sealed)throw Error("already sealed");const u=hexToBytes$1(a);if(u.byteLength!==ID_SIZE$1)throw Error("bad id size for added item");this.items.push({timestamp:t,id:u})}seal(){if(this.sealed)throw Error("already sealed");this.sealed=!0,this.items.sort(itemCompare$1);for(let t=1;t<this.items.length;t++)if(itemCompare$1(this.items[t-1],this.items[t])===0)throw Error("duplicate item inserted")}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(t){if(this._checkSealed(),t>=this.items.length)throw Error("out of range");return this.items[t]}iterate(t,a,u){this._checkSealed(),this._checkBounds(t,a);for(let d=t;d<a&&u(this.items[d],d);++d);}findLowerBound(t,a,u){return this._checkSealed(),this._checkBounds(t,a),this._binarySearch(this.items,t,a,d=>itemCompare$1(d,u)<0)}fingerprint(t,a){let u=new Accumulator$1;return u.setToZero(),this.iterate(t,a,d=>(u.add(d.id),!0)),u.getFingerprint(a-t)}_checkSealed(){if(!this.sealed)throw Error("not sealed")}_checkBounds(t,a){if(t>a||a>this.items.length)throw Error("bad range")}_binarySearch(t,a,u,d){let h=u-a;for(;h>0;){let w=a,x=Math.floor(h/2);w+=x,d(t[w])?(a=++w,h-=x+1):h=x}return a}},Negentropy$1=class{constructor(t,a=6e4){_e(this,"storage");_e(this,"frameSizeLimit");_e(this,"lastTimestampIn");_e(this,"lastTimestampOut");if(a<4096)throw Error("frameSizeLimit too small");this.storage=t,this.frameSizeLimit=a,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(t,a){return{timestamp:t,id:a||new Uint8Array(0)}}initiate(){let t=new WrappedBuffer$1;return t.extend(new Uint8Array([PROTOCOL_VERSION$1])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),t),bytesToHex$1(t.unwrap())}reconcile(t,a,u){const d=new WrappedBuffer$1(hexToBytes$1(t));this.lastTimestampIn=this.lastTimestampOut=0;let h=new WrappedBuffer$1;h.extend(new Uint8Array([PROTOCOL_VERSION$1]));let w=getByte$1(d);if(w<96||w>111)throw Error("invalid negentropy protocol version byte");if(w!==PROTOCOL_VERSION$1)throw Error("unsupported negentropy protocol version requested: "+(w-96));let x=this.storage.size(),M=this._bound(0),B=0,E=!1;for(;d.length!==0;){let S=new WrappedBuffer$1,k=()=>{E&&(E=!1,S.extend(this.encodeBound(M)),S.extend(encodeVarInt$1(Mode$1.Skip)))},C=this.decodeBound(d),D=decodeVarInt$1(d),O=B,F=this.storage.findLowerBound(B,x,C);if(D===Mode$1.Skip)E=!0;else if(D===Mode$1.Fingerprint){let P=getBytes$1(d,FINGERPRINT_SIZE$1),L=this.storage.fingerprint(O,F);compareUint8Array$1(P,L)!==0?(k(),this.splitRange(O,F,C,S)):E=!0}else if(D===Mode$1.IdList){let P=decodeVarInt$1(d),L={};for(let J=0;J<P;J++){let Y=getBytes$1(d,ID_SIZE$1);L[bytesToHex$1(Y)]=Y}if(E=!0,this.storage.iterate(O,F,J=>{let Y=J.id;const ae=bytesToHex$1(Y);return L[ae]?delete L[bytesToHex$1(Y)]:a==null||a(ae),!0}),u)for(let J of Object.values(L))u(bytesToHex$1(J))}else throw Error("unexpected mode");if(this.exceededFrameSizeLimit(h.length+S.length)){let P=this.storage.fingerprint(F,x);h.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),h.extend(encodeVarInt$1(Mode$1.Fingerprint)),h.extend(P);break}else h.extend(S);B=F,M=C}return h.length===1?null:bytesToHex$1(h.unwrap())}splitRange(t,a,u,d){let h=a-t,w=16;if(h<w*2)d.extend(this.encodeBound(u)),d.extend(encodeVarInt$1(Mode$1.IdList)),d.extend(encodeVarInt$1(h)),this.storage.iterate(t,a,x=>(d.extend(x.id),!0));else{let x=Math.floor(h/w),M=h%w,B=t;for(let E=0;E<w;E++){let S=x+(E<M?1:0),k=this.storage.fingerprint(B,B+S);B+=S;let C;if(B===a)C=u;else{let D,O;this.storage.iterate(B-1,B+1,(F,P)=>(P===B-1?D=F:O=F,!0)),C=this.getMinimalBound(D,O)}d.extend(this.encodeBound(C)),d.extend(encodeVarInt$1(Mode$1.Fingerprint)),d.extend(k)}}}exceededFrameSizeLimit(t){return t>this.frameSizeLimit-200}decodeTimestampIn(t){let a=decodeVarInt$1(t);return a=a===0?Number.MAX_VALUE:a-1,this.lastTimestampIn===Number.MAX_VALUE||a===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(a+=this.lastTimestampIn,this.lastTimestampIn=a,a)}decodeBound(t){let a=this.decodeTimestampIn(t),u=decodeVarInt$1(t);if(u>ID_SIZE$1)throw Error("bound key too long");let d=getBytes$1(t,u);return{timestamp:a,id:d}}encodeTimestampOut(t){if(t===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,encodeVarInt$1(0);let a=t;return t-=this.lastTimestampOut,this.lastTimestampOut=a,encodeVarInt$1(t+1)}encodeBound(t){let a=new WrappedBuffer$1;return a.extend(this.encodeTimestampOut(t.timestamp)),a.extend(encodeVarInt$1(t.id.length)),a.extend(t.id),a}getMinimalBound(t,a){if(a.timestamp!==t.timestamp)return this._bound(a.timestamp);{let u=0,d=a.id,h=t.id;for(let w=0;w<ID_SIZE$1&&d[w]===h[w];w++)u++;return this._bound(a.timestamp,a.id.subarray(0,u+1))}}};function compareUint8Array$1(e,t){for(let a=0;a<e.byteLength;a++){if(e[a]<t[a])return-1;if(e[a]>t[a])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function itemCompare$1(e,t){return e.timestamp===t.timestamp?compareUint8Array$1(e.id,t.id):e.timestamp-t.timestamp}var NegentropySync$1=class{constructor(t,a,u,d={}){_e(this,"relay");_e(this,"storage");_e(this,"neg");_e(this,"filter");_e(this,"subscription");_e(this,"onhave");_e(this,"onneed");this.relay=t,this.storage=a,this.neg=new Negentropy$1(a),this.onhave=d.onhave,this.onneed=d.onneed,this.filter=u,this.subscription=this.relay.prepareSubscription([{}],{label:d.label||"negentropy"}),this.subscription.oncustom=h=>{var w,x,M,B;switch(h[0]){case"NEG-MSG":{h.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${h}`);try{const E=this.neg.reconcile(h[2],this.onhave,this.onneed);E?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${E}"]`):(this.close(),(w=d.onclose)==null||w.call(d))}catch(E){console.error("negentropy reconcile error:",E),(x=d==null?void 0:d.onclose)==null||x.call(d,`reconcile error: ${E}`)}break}case"NEG-CLOSE":{const E=h[2];console.warn("negentropy error:",E),(M=d.onclose)==null||M.call(d,E);break}case"NEG-ERR":(B=d.onclose)==null||B.call(d)}}}async start(){const t=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${t}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}},nip98_exports$1={};__export$1(nip98_exports$1,{getToken:()=>getToken$1,hashPayload:()=>hashPayload$1,unpackEventFromToken:()=>unpackEventFromToken$1,validateEvent:()=>validateEvent2$1,validateEventKind:()=>validateEventKind$1,validateEventMethodTag:()=>validateEventMethodTag$1,validateEventPayloadTag:()=>validateEventPayloadTag$1,validateEventTimestamp:()=>validateEventTimestamp$1,validateEventUrlTag:()=>validateEventUrlTag$1,validateToken:()=>validateToken$1});var _authorizationScheme$1="Nostr ";async function getToken$1(e,t,a,u=!1,d){const h={kind:HTTPAuth$1,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};d&&h.tags.push(["payload",hashPayload$1(d)]);const w=await a(h);return(u?_authorizationScheme$1:"")+base64$1.encode(utf8Encoder$1.encode(JSON.stringify(w)))}async function validateToken$1(e,t,a){const u=await unpackEventFromToken$1(e).catch(h=>{throw h});return await validateEvent2$1(u,t,a).catch(h=>{throw h})}async function unpackEventFromToken$1(e){if(!e)throw new Error("Missing token");e=e.replace(_authorizationScheme$1,"");const t=utf8Decoder.decode(base64$1.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function validateEventTimestamp$1(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function validateEventKind$1(e){return e.kind===HTTPAuth$1}function validateEventUrlTag$1(e,t){const a=e.tags.find(u=>u[0]==="u");return a?a.length>0&&a[1]===t:!1}function validateEventMethodTag$1(e,t){const a=e.tags.find(u=>u[0]==="method");return a?a.length>0&&a[1].toLowerCase()===t.toLowerCase():!1}function hashPayload$1(e){const t=sha256$3(utf8Encoder$1.encode(JSON.stringify(e)));return bytesToHex$2(t)}function validateEventPayloadTag$1(e,t){const a=e.tags.find(d=>d[0]==="payload");if(!a)return!1;const u=hashPayload$1(t);return a.length>0&&a[1]===u}async function validateEvent2$1(e,t,a,u){if(!verifyEvent(e))throw new Error("Invalid nostr event, signature invalid");if(!validateEventKind$1(e))throw new Error("Invalid nostr event, kind invalid");if(!validateEventTimestamp$1(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!validateEventUrlTag$1(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!validateEventMethodTag$1(e,a))throw new Error("Invalid nostr event, method tag invalid");if(u&&typeof u=="object"&&Object.keys(u).length>0&&!validateEventPayloadTag$1(e,u))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}const TAG_PRIVATE="private";class NCC05Error extends Error{constructor(t){super(t),this.name="NCC05Error"}}class NCC05RelayError extends NCC05Error{constructor(t){super(t),this.name="NCC05RelayError"}}class NCC05TimeoutError extends NCC05Error{constructor(t){super(t),this.name="NCC05TimeoutError"}}class NCC05DecryptionError extends NCC05Error{constructor(t){super(t),this.name="NCC05DecryptionError"}}class NCC05ArgumentError extends NCC05Error{constructor(t){super(t),this.name="NCC05ArgumentError"}}function ensureUint8Array(e){if(e instanceof Uint8Array)return e;if(typeof e=="string"){if(e.match(/^[0-9a-fA-F]+$/))return new Uint8Array(e.match(/.{1,2}/g).map(t=>parseInt(t,16)));throw new NCC05ArgumentError("Invalid hex key provided")}throw new NCC05ArgumentError("Key must be a hex string or Uint8Array")}class LocalSigner{constructor(t){_e(this,"secretKey");_e(this,"pubkey");this.secretKey=t,this.pubkey=getPublicKey$1(t)}async getPublicKey(){return this.pubkey}async signEvent(t){const a={...t,pubkey:this.pubkey};return finalizeEvent$1(a,this.secretKey)}async getConversationKey(t){return nip44_exports$1.getConversationKey(this.secretKey,t)}}function toSigner(e){if(e){if(typeof e=="string"||e instanceof Uint8Array){const t=ensureUint8Array(e);return new LocalSigner(t)}return e}}class NCC05Resolver{constructor(t={}){_e(this,"pool");_e(this,"_ownPool");_e(this,"bootstrapRelays");_e(this,"timeout");_e(this,"urlTransformer");_e(this,"cache",new Map);this._ownPool=!t.pool,this.pool=t.pool||new SimplePool$1,this.bootstrapRelays=t.bootstrapRelays||["wss://relay.damus.io","wss://npub1..."],this.timeout=t.timeout||1e4,this.urlTransformer=t.urlTransformer}applyUrlTransformer(t){return this.urlTransformer?{...t,endpoints:t.endpoints.map(a=>this.urlTransformer(a))}:t}async decryptEventContent(t,a,u){let d=t.content;if(d.includes('"wraps"')&&d.includes('"ciphertext"')&&d.startsWith("{")){if(!u)return null;try{const w=JSON.parse(d),x=await u.getPublicKey(),M=w.wraps[x];if(!M)return null;const B=await u.getConversationKey(a),E=nip44_exports$1.decrypt(M,B),S=new Uint8Array(E.match(/.{1,2}/g).map(C=>parseInt(C,16))),k=nip44_exports$1.getConversationKey(S,getPublicKey$1(S));d=nip44_exports$1.decrypt(w.ciphertext,k)}catch{throw new NCC05DecryptionError("Failed to decrypt wrapped content")}}else if(u&&!d.startsWith("{"))try{const w=await u.getConversationKey(a);d=nip44_exports$1.decrypt(d,w)}catch{throw new NCC05DecryptionError("Failed to decrypt content")}return d}async buildPayloadRecord(t,a,u){const d=await this.decryptEventContent(t,a,u);if(!d)return null;let h;try{h=JSON.parse(d)}catch{return null}if(!h||!Array.isArray(h.endpoints)||typeof h.updated_at!="number"||typeof h.ttl!="number")return null;const w=t.tags.find(k=>k[0]==="expiration"),x=w?parseInt(w[1],10):1/0,M=Number.isFinite(x)?x:1/0,B=h.updated_at+h.ttl,E=Math.min(M,B),S=h.updated_at||t.created_at;return{event:t,payload:h,expiry:E,freshness:S}}async discoverRelays(t,a){let u=[...this.bootstrapRelays];if(!a)return u;try{const d=await this.pool.get(this.bootstrapRelays,{authors:[t],kinds:[10002]});if(d&&verifyEvent(d)&&d.pubkey===t){const h=d.tags.filter(w=>w[0]==="r").map(w=>w[1]);h.length>0&&(u=[...new Set([...u,...h])])}}catch(d){console.warn(`[NCC-05] Gossip discovery failed: ${d.message}`)}return u}async fetchFreshestRecord(t,a,u){const d=await this.discoverRelays(t,u),h={authors:[t],kinds:[30058],limit:50};try{const w=this.pool.querySync(d,h),x=new Promise((E,S)=>setTimeout(()=>S(new NCC05TimeoutError("Resolution timed out")),this.timeout)),M=await Promise.race([w,x]);if(!M||Array.isArray(M)&&M.length===0)return null;const B=M.filter(E=>E.pubkey===t&&verifyEvent(E)).sort((E,S)=>S.created_at!==E.created_at?S.created_at-E.created_at:E.id.localeCompare(S.id));return B.length===0?null:this.buildPayloadRecord(B[0],t,a)}catch(w){throw w instanceof NCC05Error?w:new NCC05RelayError(`Relay query failed: ${w.message}`)}}async resolve(t,a,u="addr",d={}){var C;let h=t;t.startsWith("npub1")&&(h=nip19_exports$1.decode(t).data);const w=Math.floor(Date.now()/1e3),x=`${h}:${u}`,M=this.cache.get(x);if(M&&M.expires>w)return M.payload;M&&this.cache.delete(x);const B=a?toSigner(a):void 0,E=await this.fetchFreshestRecord(h,B,d.gossip);if(!E||((C=E.event.tags.find(D=>D[0]==="d"))==null?void 0:C[1])!==u)return null;const k=this.applyUrlTransformer(E.payload);return w>E.expiry?d.strict?null:(console.warn("NCC-05 record expired"),k):(this.cache.set(x,{payload:k,expires:E.expiry}),k)}async resolveLatest(t,a,u={}){let d=t;t.startsWith("npub1")&&(d=nip19_exports$1.decode(t).data);const h=Math.floor(Date.now()/1e3),w=`${d}:latest`,x=this.cache.get(w);if(x&&x.expires>h)return x.payload;x&&this.cache.delete(w);const M=a?toSigner(a):void 0,B=await this.fetchFreshestRecord(d,M,u.gossip);if(!B)return null;const E=this.applyUrlTransformer(B.payload);return h>B.expiry?u.strict?null:(console.warn("NCC-05 record expired"),E):(this.cache.set(w,{payload:E,expires:B.expiry}),E)}close(){this._ownPool&&this.pool.close(this.bootstrapRelays)}}class NCC05Publisher{constructor(t={}){_e(this,"pool");_e(this,"_ownPool");_e(this,"timeout");this._ownPool=!t.pool,this.pool=t.pool||new SimplePool$1,this.timeout=t.timeout||5e3}async _publishToRelays(t,a){const d=this.pool.publish(t,a).map(x=>new Promise((M,B)=>{const E=setTimeout(()=>B(new NCC05TimeoutError("Publish timed out")),this.timeout);x.then(()=>{clearTimeout(E),M()}).catch(S=>{clearTimeout(E),B(S)})})),h=await Promise.allSettled(d);if(h.filter(x=>x.status==="fulfilled").length===0){const x=h.filter(M=>M.status==="rejected").map(M=>M.reason.message).join(", ");throw new NCC05RelayError(`Failed to publish to any relay. Errors: ${x}`)}}async publishWrapped(t,a,u,d,h="addr"){let w="addr",x=!1;typeof h=="string"?w=h:(w=h.identifier||"addr",x=!!h.privateLocator);const M=toSigner(a);if(!M)throw new NCC05ArgumentError("Signer must be provided.");const B=await M.getPublicKey(),E=generateSecretKey(),S=Array.from(E).map(J=>J.toString(16).padStart(2,"0")).join(""),k=nip44_exports$1.getConversationKey(E,getPublicKey$1(E)),C=nip44_exports$1.encrypt(JSON.stringify(d),k),D={};for(const J of u){const Y=await M.getConversationKey(J);D[J]=nip44_exports$1.encrypt(S,Y)}const O={ciphertext:C,wraps:D},F=[["d",w]];x&&F.push([TAG_PRIVATE,"true"]);const P={kind:30058,created_at:Math.floor(Date.now()/1e3),pubkey:B,tags:F,content:JSON.stringify(O)},L=await M.signEvent(P);return await this._publishToRelays(t,L),L}async publish(t,a,u,d={}){const h=toSigner(a);if(!h)throw new NCC05ArgumentError("Signer must be provided.");const w=await h.getPublicKey(),x=d.identifier||"addr";let M=JSON.stringify(u);if(!d.public){const k=d.recipientPubkey||w,C=await h.getConversationKey(k);M=nip44_exports$1.encrypt(M,C)}const B=[["d",x]];d.privateLocator&&B.push([TAG_PRIVATE,"true"]);const E={kind:30058,created_at:Math.floor(Date.now()/1e3),pubkey:w,tags:B,content:M},S=await h.signEvent(E);return await this._publishToRelays(t,S),S}close(t){this._ownPool&&this.pool.close(t)}}var cryptoBrowserify={};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var browser$c={exports:{}},process=browser$c.exports={},cachedSetTimeout,cachedClearTimeout;function defaultSetTimout(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?cachedSetTimeout=setTimeout:cachedSetTimeout=defaultSetTimout}catch{cachedSetTimeout=defaultSetTimout}try{typeof clearTimeout=="function"?cachedClearTimeout=clearTimeout:cachedClearTimeout=defaultClearTimeout}catch{cachedClearTimeout=defaultClearTimeout}})();function runTimeout(e){if(cachedSetTimeout===setTimeout)return setTimeout(e,0);if((cachedSetTimeout===defaultSetTimout||!cachedSetTimeout)&&setTimeout)return cachedSetTimeout=setTimeout,setTimeout(e,0);try{return cachedSetTimeout(e,0)}catch{try{return cachedSetTimeout.call(null,e,0)}catch{return cachedSetTimeout.call(this,e,0)}}}function runClearTimeout(e){if(cachedClearTimeout===clearTimeout)return clearTimeout(e);if((cachedClearTimeout===defaultClearTimeout||!cachedClearTimeout)&&clearTimeout)return cachedClearTimeout=clearTimeout,clearTimeout(e);try{return cachedClearTimeout(e)}catch{try{return cachedClearTimeout.call(null,e)}catch{return cachedClearTimeout.call(this,e)}}}var queue=[],draining=!1,currentQueue,queueIndex=-1;function cleanUpNextTick(){!draining||!currentQueue||(draining=!1,currentQueue.length?queue=currentQueue.concat(queue):queueIndex=-1,queue.length&&drainQueue())}function drainQueue(){if(!draining){var e=runTimeout(cleanUpNextTick);draining=!0;for(var t=queue.length;t;){for(currentQueue=queue,queue=[];++queueIndex<t;)currentQueue&&currentQueue[queueIndex].run();queueIndex=-1,t=queue.length}currentQueue=null,draining=!1,runClearTimeout(e)}}process.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var a=1;a<arguments.length;a++)t[a-1]=arguments[a];queue.push(new Item(e,t)),queue.length===1&&!draining&&runTimeout(drainQueue)};function Item(e,t){this.fun=e,this.array=t}Item.prototype.run=function(){this.fun.apply(null,this.array)};process.title="browser";process.browser=!0;process.env={};process.argv=[];process.version="";process.versions={};function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.prependListener=noop;process.prependOnceListener=noop;process.listeners=function(e){return[]};process.binding=function(e){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(e){throw new Error("process.chdir is not supported")};process.umask=function(){return 0};var browserExports$1=browser$c.exports;const process$1=getDefaultExportFromCjs(browserExports$1);var browser$b={exports:{}},safeBuffer$5={exports:{}},dist={};(function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var t={},a={};a.byteLength=E,a.toByteArray=k,a.fromByteArray=O;for(var u=[],d=[],h=typeof Uint8Array<"u"?Uint8Array:Array,w="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",x=0,M=w.length;x<M;++x)u[x]=w[x],d[w.charCodeAt(x)]=x;d[45]=62,d[95]=63;function B(L){var J=L.length;if(J%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var Y=L.indexOf("=");Y===-1&&(Y=J);var ae=Y===J?0:4-Y%4;return[Y,ae]}function E(L){var J=B(L),Y=J[0],ae=J[1];return(Y+ae)*3/4-ae}function S(L,J,Y){return(J+Y)*3/4-Y}function k(L){var J,Y=B(L),ae=Y[0],oe=Y[1],ue=new h(S(L,ae,oe)),se=0,ie=oe>0?ae-4:ae,ce;for(ce=0;ce<ie;ce+=4)J=d[L.charCodeAt(ce)]<<18|d[L.charCodeAt(ce+1)]<<12|d[L.charCodeAt(ce+2)]<<6|d[L.charCodeAt(ce+3)],ue[se++]=J>>16&255,ue[se++]=J>>8&255,ue[se++]=J&255;return oe===2&&(J=d[L.charCodeAt(ce)]<<2|d[L.charCodeAt(ce+1)]>>4,ue[se++]=J&255),oe===1&&(J=d[L.charCodeAt(ce)]<<10|d[L.charCodeAt(ce+1)]<<4|d[L.charCodeAt(ce+2)]>>2,ue[se++]=J>>8&255,ue[se++]=J&255),ue}function C(L){return u[L>>18&63]+u[L>>12&63]+u[L>>6&63]+u[L&63]}function D(L,J,Y){for(var ae,oe=[],ue=J;ue<Y;ue+=3)ae=(L[ue]<<16&16711680)+(L[ue+1]<<8&65280)+(L[ue+2]&255),oe.push(C(ae));return oe.join("")}function O(L){for(var J,Y=L.length,ae=Y%3,oe=[],ue=16383,se=0,ie=Y-ae;se<ie;se+=ue)oe.push(D(L,se,se+ue>ie?ie:se+ue));return ae===1?(J=L[Y-1],oe.push(u[J>>2]+u[J<<4&63]+"==")):ae===2&&(J=(L[Y-2]<<8)+L[Y-1],oe.push(u[J>>10]+u[J>>4&63]+u[J<<2&63]+"=")),oe.join("")}var F={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */F.read=function(L,J,Y,ae,oe){var ue,se,ie=oe*8-ae-1,ce=(1<<ie)-1,$=ce>>1,n=-7,l=Y?oe-1:0,c=Y?-1:1,p=L[J+l];for(l+=c,ue=p&(1<<-n)-1,p>>=-n,n+=ie;n>0;ue=ue*256+L[J+l],l+=c,n-=8);for(se=ue&(1<<-n)-1,ue>>=-n,n+=ae;n>0;se=se*256+L[J+l],l+=c,n-=8);if(ue===0)ue=1-$;else{if(ue===ce)return se?NaN:(p?-1:1)*(1/0);se=se+Math.pow(2,ae),ue=ue-$}return(p?-1:1)*se*Math.pow(2,ue-ae)},F.write=function(L,J,Y,ae,oe,ue){var se,ie,ce,$=ue*8-oe-1,n=(1<<$)-1,l=n>>1,c=oe===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=ae?0:ue-1,y=ae?1:-1,b=J<0||J===0&&1/J<0?1:0;for(J=Math.abs(J),isNaN(J)||J===1/0?(ie=isNaN(J)?1:0,se=n):(se=Math.floor(Math.log(J)/Math.LN2),J*(ce=Math.pow(2,-se))<1&&(se--,ce*=2),se+l>=1?J+=c/ce:J+=c*Math.pow(2,1-l),J*ce>=2&&(se++,ce/=2),se+l>=n?(ie=0,se=n):se+l>=1?(ie=(J*ce-1)*Math.pow(2,oe),se=se+l):(ie=J*Math.pow(2,l-1)*Math.pow(2,oe),se=0));oe>=8;L[Y+p]=ie&255,p+=y,ie/=256,oe-=8);for(se=se<<oe|ie,$+=oe;$>0;L[Y+p]=se&255,p+=y,se/=256,$-=8);L[Y+p-y]|=b*128};/*!
2
2
  * The buffer module from node.js, for the browser.
3
3
  *
4
4
  * @author Feross Aboukhadijeh <https://feross.org>
@@ -19,7 +19,7 @@ Use Chrome, Firefox or Internet Explorer 11`)}var Buffer$E=safeBufferExports$2.B
19
19
  `)},pem}var hasRequiredEncoders;function requireEncoders(){return hasRequiredEncoders||(hasRequiredEncoders=1,function(e){var t=e;t.der=requireDer(),t.pem=requirePem()}(encoders)),encoders}var hasRequiredAsn1;function requireAsn1(){return hasRequiredAsn1||(hasRequiredAsn1=1,function(e){var t=e;t.bignum=bnExports$2,t.define=requireApi().define,t.base=requireBase(),t.constants=requireConstants(),t.decoders=requireDecoders(),t.encoders=requireEncoders()}(asn1$2)),asn1$2}var asn=requireAsn1(),Time$1=asn.define("Time",function(){this.choice({utcTime:this.utctime(),generalTime:this.gentime()})}),AttributeTypeValue=asn.define("AttributeTypeValue",function(){this.seq().obj(this.key("type").objid(),this.key("value").any())}),AlgorithmIdentifier$1=asn.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional(),this.key("curve").objid().optional())}),SubjectPublicKeyInfo=asn.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(AlgorithmIdentifier$1),this.key("subjectPublicKey").bitstr())}),RelativeDistinguishedName=asn.define("RelativeDistinguishedName",function(){this.setof(AttributeTypeValue)}),RDNSequence=asn.define("RDNSequence",function(){this.seqof(RelativeDistinguishedName)}),Name=asn.define("Name",function(){this.choice({rdnSequence:this.use(RDNSequence)})}),Validity=asn.define("Validity",function(){this.seq().obj(this.key("notBefore").use(Time$1),this.key("notAfter").use(Time$1))}),Extension=asn.define("Extension",function(){this.seq().obj(this.key("extnID").objid(),this.key("critical").bool().def(!1),this.key("extnValue").octstr())}),TBSCertificate=asn.define("TBSCertificate",function(){this.seq().obj(this.key("version").explicit(0).int().optional(),this.key("serialNumber").int(),this.key("signature").use(AlgorithmIdentifier$1),this.key("issuer").use(Name),this.key("validity").use(Validity),this.key("subject").use(Name),this.key("subjectPublicKeyInfo").use(SubjectPublicKeyInfo),this.key("issuerUniqueID").implicit(1).bitstr().optional(),this.key("subjectUniqueID").implicit(2).bitstr().optional(),this.key("extensions").explicit(3).seqof(Extension).optional())}),X509Certificate=asn.define("X509Certificate",function(){this.seq().obj(this.key("tbsCertificate").use(TBSCertificate),this.key("signatureAlgorithm").use(AlgorithmIdentifier$1),this.key("signatureValue").bitstr())}),certificate=X509Certificate,asn1$1=requireAsn1();asn1$3.certificate=certificate;var RSAPrivateKey=asn1$1.define("RSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("modulus").int(),this.key("publicExponent").int(),this.key("privateExponent").int(),this.key("prime1").int(),this.key("prime2").int(),this.key("exponent1").int(),this.key("exponent2").int(),this.key("coefficient").int())});asn1$3.RSAPrivateKey=RSAPrivateKey;var RSAPublicKey=asn1$1.define("RSAPublicKey",function(){this.seq().obj(this.key("modulus").int(),this.key("publicExponent").int())});asn1$3.RSAPublicKey=RSAPublicKey;var AlgorithmIdentifier=asn1$1.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("none").null_().optional(),this.key("curve").objid().optional(),this.key("params").seq().obj(this.key("p").int(),this.key("q").int(),this.key("g").int()).optional())}),PublicKey=asn1$1.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(AlgorithmIdentifier),this.key("subjectPublicKey").bitstr())});asn1$3.PublicKey=PublicKey;var PrivateKeyInfo=asn1$1.define("PrivateKeyInfo",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").use(AlgorithmIdentifier),this.key("subjectPrivateKey").octstr())});asn1$3.PrivateKey=PrivateKeyInfo;var EncryptedPrivateKeyInfo=asn1$1.define("EncryptedPrivateKeyInfo",function(){this.seq().obj(this.key("algorithm").seq().obj(this.key("id").objid(),this.key("decrypt").seq().obj(this.key("kde").seq().obj(this.key("id").objid(),this.key("kdeparams").seq().obj(this.key("salt").octstr(),this.key("iters").int())),this.key("cipher").seq().obj(this.key("algo").objid(),this.key("iv").octstr()))),this.key("subjectPrivateKey").octstr())});asn1$3.EncryptedPrivateKey=EncryptedPrivateKeyInfo;var DSAPrivateKey=asn1$1.define("DSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("p").int(),this.key("q").int(),this.key("g").int(),this.key("pub_key").int(),this.key("priv_key").int())});asn1$3.DSAPrivateKey=DSAPrivateKey;asn1$3.DSAparam=asn1$1.define("DSAparam",function(){this.int()});var ECParameters=asn1$1.define("ECParameters",function(){this.choice({namedCurve:this.objid()})}),ECPrivateKey=asn1$1.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").optional().explicit(0).use(ECParameters),this.key("publicKey").optional().explicit(1).bitstr())});asn1$3.ECPrivateKey=ECPrivateKey;asn1$3.signature=asn1$1.define("signature",function(){this.seq().obj(this.key("r").int(),this.key("s").int())});const require$$1={"2.16.840.1.101.3.4.1.1":"aes-128-ecb","2.16.840.1.101.3.4.1.2":"aes-128-cbc","2.16.840.1.101.3.4.1.3":"aes-128-ofb","2.16.840.1.101.3.4.1.4":"aes-128-cfb","2.16.840.1.101.3.4.1.21":"aes-192-ecb","2.16.840.1.101.3.4.1.22":"aes-192-cbc","2.16.840.1.101.3.4.1.23":"aes-192-ofb","2.16.840.1.101.3.4.1.24":"aes-192-cfb","2.16.840.1.101.3.4.1.41":"aes-256-ecb","2.16.840.1.101.3.4.1.42":"aes-256-cbc","2.16.840.1.101.3.4.1.43":"aes-256-ofb","2.16.840.1.101.3.4.1.44":"aes-256-cfb"};var findProc=/Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m,startRegex=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m,fullRegex=/^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m,evp=evp_bytestokey,ciphers$1=browser$5,Buffer$6=safeBufferExports$2.Buffer,fixProc$1=function(e,t){var a=e.toString(),u=a.match(findProc),d;if(u){var w="aes"+u[1],x=Buffer$6.from(u[2],"hex"),M=Buffer$6.from(u[3].replace(/[\r\n]/g,""),"base64"),B=evp(t,x.slice(0,8),parseInt(u[1],10)).key,E=[],S=ciphers$1.createDecipheriv(w,B,x);E.push(S.update(M)),E.push(S.final()),d=Buffer$6.concat(E)}else{var h=a.match(fullRegex);d=Buffer$6.from(h[2].replace(/[\r\n]/g,""),"base64")}var k=a.match(startRegex)[1];return{tag:k,data:d}},asn1=asn1$3,aesid=require$$1,fixProc=fixProc$1,ciphers=browser$5,pbkdf2Sync=browser$7.pbkdf2Sync,Buffer$5=safeBufferExports$2.Buffer;function decrypt$1(e,t){var a=e.algorithm.decrypt.kde.kdeparams.salt,u=parseInt(e.algorithm.decrypt.kde.kdeparams.iters.toString(),10),d=aesid[e.algorithm.decrypt.cipher.algo.join(".")],h=e.algorithm.decrypt.cipher.iv,w=e.subjectPrivateKey,x=parseInt(d.split("-")[1],10)/8,M=pbkdf2Sync(t,a,u,x,"sha1"),B=ciphers.createDecipheriv(d,M,h),E=[];return E.push(B.update(w)),E.push(B.final()),Buffer$5.concat(E)}function parseKeys$2(e){var t;typeof e=="object"&&!Buffer$5.isBuffer(e)&&(t=e.passphrase,e=e.key),typeof e=="string"&&(e=Buffer$5.from(e));var a=fixProc(e,t),u=a.tag,d=a.data,h,w;switch(u){case"CERTIFICATE":w=asn1.certificate.decode(d,"der").tbsCertificate.subjectPublicKeyInfo;case"PUBLIC KEY":switch(w||(w=asn1.PublicKey.decode(d,"der")),h=w.algorithm.algorithm.join("."),h){case"1.2.840.113549.1.1.1":return asn1.RSAPublicKey.decode(w.subjectPublicKey.data,"der");case"1.2.840.10045.2.1":return w.subjectPrivateKey=w.subjectPublicKey,{type:"ec",data:w};case"1.2.840.10040.4.1":return w.algorithm.params.pub_key=asn1.DSAparam.decode(w.subjectPublicKey.data,"der"),{type:"dsa",data:w.algorithm.params};default:throw new Error("unknown key id "+h)}case"ENCRYPTED PRIVATE KEY":d=asn1.EncryptedPrivateKey.decode(d,"der"),d=decrypt$1(d,t);case"PRIVATE KEY":switch(w=asn1.PrivateKey.decode(d,"der"),h=w.algorithm.algorithm.join("."),h){case"1.2.840.113549.1.1.1":return asn1.RSAPrivateKey.decode(w.subjectPrivateKey,"der");case"1.2.840.10045.2.1":return{curve:w.algorithm.curve,privateKey:asn1.ECPrivateKey.decode(w.subjectPrivateKey,"der").privateKey};case"1.2.840.10040.4.1":return w.algorithm.params.priv_key=asn1.DSAparam.decode(w.subjectPrivateKey,"der"),{type:"dsa",params:w.algorithm.params};default:throw new Error("unknown key id "+h)}case"RSA PUBLIC KEY":return asn1.RSAPublicKey.decode(d,"der");case"RSA PRIVATE KEY":return asn1.RSAPrivateKey.decode(d,"der");case"DSA PRIVATE KEY":return{type:"dsa",params:asn1.DSAPrivateKey.decode(d,"der")};case"EC PRIVATE KEY":return d=asn1.ECPrivateKey.decode(d,"der"),{curve:d.parameters.value,privateKey:d.privateKey};default:throw new Error("unknown key type "+u)}}parseKeys$2.signature=asn1.signature;var parseAsn1=parseKeys$2;const require$$4={"1.3.132.0.10":"secp256k1","1.3.132.0.33":"p224","1.2.840.10045.3.1.1":"p192","1.2.840.10045.3.1.7":"p256","1.3.132.0.34":"p384","1.3.132.0.35":"p521"};var hasRequiredSign;function requireSign(){if(hasRequiredSign)return sign.exports;hasRequiredSign=1;var e=safeBufferExports$2.Buffer,t=browser$8,a=browserifyRsa,u=requireElliptic().ec,d=bnExports$4,h=parseAsn1,w=require$$4,x=1;function M(P,L,J,Y,ae){var oe=h(L);if(oe.curve){if(Y!=="ecdsa"&&Y!=="ecdsa/rsa")throw new Error("wrong private key type");return B(P,oe)}else if(oe.type==="dsa"){if(Y!=="dsa")throw new Error("wrong private key type");return E(P,oe,J)}if(Y!=="rsa"&&Y!=="ecdsa/rsa")throw new Error("wrong private key type");if(L.padding!==void 0&&L.padding!==x)throw new Error("illegal or unsupported padding mode");P=e.concat([ae,P]);for(var ue=oe.modulus.byteLength(),se=[0,1];P.length+se.length+1<ue;)se.push(255);se.push(0);for(var ie=-1;++ie<P.length;)se.push(P[ie]);var ce=a(se,oe);return ce}function B(P,L){var J=w[L.curve.join(".")];if(!J)throw new Error("unknown curve "+L.curve.join("."));var Y=new u(J),ae=Y.keyFromPrivate(L.privateKey),oe=ae.sign(P);return e.from(oe.toDER())}function E(P,L,J){for(var Y=L.params.priv_key,ae=L.params.p,oe=L.params.q,ue=L.params.g,se=new d(0),ie,ce=C(P,oe).mod(oe),$=!1,n=k(Y,oe,P,J);$===!1;)ie=O(oe,n,J),se=F(ue,ie,ae,oe),$=ie.invm(oe).imul(ce.add(Y.mul(se))).mod(oe),$.cmpn(0)===0&&($=!1,se=new d(0));return S(se,$)}function S(P,L){P=P.toArray(),L=L.toArray(),P[0]&128&&(P=[0].concat(P)),L[0]&128&&(L=[0].concat(L));var J=P.length+L.length+4,Y=[48,J,2,P.length];return Y=Y.concat(P,[2,L.length],L),e.from(Y)}function k(P,L,J,Y){if(P=e.from(P.toArray()),P.length<L.byteLength()){var ae=e.alloc(L.byteLength()-P.length);P=e.concat([ae,P])}var oe=J.length,ue=D(J,L),se=e.alloc(oe);se.fill(1);var ie=e.alloc(oe);return ie=t(Y,ie).update(se).update(e.from([0])).update(P).update(ue).digest(),se=t(Y,ie).update(se).digest(),ie=t(Y,ie).update(se).update(e.from([1])).update(P).update(ue).digest(),se=t(Y,ie).update(se).digest(),{k:ie,v:se}}function C(P,L){var J=new d(P),Y=(P.length<<3)-L.bitLength();return Y>0&&J.ishrn(Y),J}function D(P,L){P=C(P,L),P=P.mod(L);var J=e.from(P.toArray());if(J.length<L.byteLength()){var Y=e.alloc(L.byteLength()-J.length);J=e.concat([Y,J])}return J}function O(P,L,J){var Y,ae;do{for(Y=e.alloc(0);Y.length*8<P.bitLength();)L.v=t(J,L.k).update(L.v).digest(),Y=e.concat([Y,L.v]);ae=C(Y,P),L.k=t(J,L.k).update(L.v).update(e.from([0])).digest(),L.v=t(J,L.k).update(L.v).digest()}while(ae.cmp(P)!==-1);return ae}function F(P,L,J,Y){return P.toRed(d.mont(J)).redPow(L).fromRed().mod(Y)}return sign.exports=M,sign.exports.getKey=k,sign.exports.makeKey=O,sign.exports}var verify_1,hasRequiredVerify;function requireVerify(){if(hasRequiredVerify)return verify_1;hasRequiredVerify=1;var e=safeBufferExports$2.Buffer,t=bnExports$4,a=requireElliptic().ec,u=parseAsn1,d=require$$4;function h(B,E,S,k,C){var D=u(S);if(D.type==="ec"){if(k!=="ecdsa"&&k!=="ecdsa/rsa")throw new Error("wrong public key type");return w(B,E,D)}else if(D.type==="dsa"){if(k!=="dsa")throw new Error("wrong public key type");return x(B,E,D)}if(k!=="rsa"&&k!=="ecdsa/rsa")throw new Error("wrong public key type");E=e.concat([C,E]);for(var O=D.modulus.byteLength(),F=[1],P=0;E.length+F.length+2<O;)F.push(255),P+=1;F.push(0);for(var L=-1;++L<E.length;)F.push(E[L]);F=e.from(F);var J=t.mont(D.modulus);B=new t(B).toRed(J),B=B.redPow(new t(D.publicExponent)),B=e.from(B.fromRed().toArray());var Y=P<8?1:0;for(O=Math.min(B.length,F.length),B.length!==F.length&&(Y=1),L=-1;++L<O;)Y|=B[L]^F[L];return Y===0}function w(B,E,S){var k=d[S.data.algorithm.curve.join(".")];if(!k)throw new Error("unknown curve "+S.data.algorithm.curve.join("."));var C=new a(k),D=S.data.subjectPrivateKey.data;return C.verify(E,B,D)}function x(B,E,S){var k=S.data.p,C=S.data.q,D=S.data.g,O=S.data.pub_key,F=u.signature.decode(B,"der"),P=F.s,L=F.r;M(P,C),M(L,C);var J=t.mont(k),Y=P.invm(C),ae=D.toRed(J).redPow(new t(E).mul(Y).mod(C)).fromRed().mul(O.toRed(J).redPow(L.mul(Y).mod(C)).fromRed()).mod(k).mod(C);return ae.cmp(L)===0}function M(B,E){if(B.cmpn(0)<=0)throw new Error("invalid sig");if(B.cmp(E)>=0)throw new Error("invalid sig")}return verify_1=h,verify_1}var browser$3,hasRequiredBrowser$1;function requireBrowser$1(){if(hasRequiredBrowser$1)return browser$3;hasRequiredBrowser$1=1;var e=safeBufferExports$2.Buffer,t=browser$9,a=readableBrowserExports,u=inherits_browserExports,d=requireSign(),h=requireVerify(),w=require$$6;Object.keys(w).forEach(function(S){w[S].id=e.from(w[S].id,"hex"),w[S.toLowerCase()]=w[S]});function x(S){a.Writable.call(this);var k=w[S];if(!k)throw new Error("Unknown message digest");this._hashType=k.hash,this._hash=t(k.hash),this._tag=k.id,this._signType=k.sign}u(x,a.Writable),x.prototype._write=function(k,C,D){this._hash.update(k),D()},x.prototype.update=function(k,C){return this._hash.update(typeof k=="string"?e.from(k,C):k),this},x.prototype.sign=function(k,C){this.end();var D=this._hash.digest(),O=d(D,k,this._hashType,this._signType,this._tag);return C?O.toString(C):O};function M(S){a.Writable.call(this);var k=w[S];if(!k)throw new Error("Unknown message digest");this._hash=t(k.hash),this._tag=k.id,this._signType=k.sign}u(M,a.Writable),M.prototype._write=function(k,C,D){this._hash.update(k),D()},M.prototype.update=function(k,C){return this._hash.update(typeof k=="string"?e.from(k,C):k),this},M.prototype.verify=function(k,C,D){var O=typeof C=="string"?e.from(C,D):C;this.end();var F=this._hash.digest();return h(O,F,k,this._signType,this._tag)};function B(S){return new x(S)}function E(S){return new M(S)}return browser$3={Sign:B,Verify:E,createSign:B,createVerify:E},browser$3}var bn$1={exports:{}};bn$1.exports;(function(e){(function(t,a){function u($,n){if(!$)throw new Error(n||"Assertion failed")}function d($,n){$.super_=n;var l=function(){};l.prototype=n.prototype,$.prototype=new l,$.prototype.constructor=$}function h($,n,l){if(h.isBN($))return $;this.negative=0,this.words=null,this.length=0,this.red=null,$!==null&&((n==="le"||n==="be")&&(l=n,n=10),this._init($||0,n||10,l||"be"))}typeof t=="object"?t.exports=h:a.BN=h,h.BN=h,h.wordSize=26;var w;try{typeof window<"u"&&typeof window.Buffer<"u"?w=window.Buffer:w=dist.Buffer}catch{}h.isBN=function(n){return n instanceof h?!0:n!==null&&typeof n=="object"&&n.constructor.wordSize===h.wordSize&&Array.isArray(n.words)},h.max=function(n,l){return n.cmp(l)>0?n:l},h.min=function(n,l){return n.cmp(l)<0?n:l},h.prototype._init=function(n,l,c){if(typeof n=="number")return this._initNumber(n,l,c);if(typeof n=="object")return this._initArray(n,l,c);l==="hex"&&(l=16),u(l===(l|0)&&l>=2&&l<=36),n=n.toString().replace(/\s+/g,"");var p=0;n[0]==="-"&&(p++,this.negative=1),p<n.length&&(l===16?this._parseHex(n,p,c):(this._parseBase(n,l,p),c==="le"&&this._initArray(this.toArray(),l,c)))},h.prototype._initNumber=function(n,l,c){n<0&&(this.negative=1,n=-n),n<67108864?(this.words=[n&67108863],this.length=1):n<4503599627370496?(this.words=[n&67108863,n/67108864&67108863],this.length=2):(u(n<9007199254740992),this.words=[n&67108863,n/67108864&67108863,1],this.length=3),c==="le"&&this._initArray(this.toArray(),l,c)},h.prototype._initArray=function(n,l,c){if(u(typeof n.length=="number"),n.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(n.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var y,b,_=0;if(c==="be")for(p=n.length-1,y=0;p>=0;p-=3)b=n[p]|n[p-1]<<8|n[p-2]<<16,this.words[y]|=b<<_&67108863,this.words[y+1]=b>>>26-_&67108863,_+=24,_>=26&&(_-=26,y++);else if(c==="le")for(p=0,y=0;p<n.length;p+=3)b=n[p]|n[p+1]<<8|n[p+2]<<16,this.words[y]|=b<<_&67108863,this.words[y+1]=b>>>26-_&67108863,_+=24,_>=26&&(_-=26,y++);return this.strip()};function x($,n){var l=$.charCodeAt(n);return l>=65&&l<=70?l-55:l>=97&&l<=102?l-87:l-48&15}function M($,n,l){var c=x($,l);return l-1>=n&&(c|=x($,l-1)<<4),c}h.prototype._parseHex=function(n,l,c){this.length=Math.ceil((n.length-l)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var y=0,b=0,_;if(c==="be")for(p=n.length-1;p>=l;p-=2)_=M(n,l,p)<<y,this.words[b]|=_&67108863,y>=18?(y-=18,b+=1,this.words[b]|=_>>>26):y+=8;else{var v=n.length-l;for(p=v%2===0?l+1:l;p<n.length;p+=2)_=M(n,l,p)<<y,this.words[b]|=_&67108863,y>=18?(y-=18,b+=1,this.words[b]|=_>>>26):y+=8}this.strip()};function B($,n,l,c){for(var p=0,y=Math.min($.length,l),b=n;b<y;b++){var _=$.charCodeAt(b)-48;p*=c,_>=49?p+=_-49+10:_>=17?p+=_-17+10:p+=_}return p}h.prototype._parseBase=function(n,l,c){this.words=[0],this.length=1;for(var p=0,y=1;y<=67108863;y*=l)p++;p--,y=y/l|0;for(var b=n.length-c,_=b%p,v=Math.min(b,b-_)+c,o=0,m=c;m<v;m+=p)o=B(n,m,m+p,l),this.imuln(y),this.words[0]+o<67108864?this.words[0]+=o:this._iaddn(o);if(_!==0){var A=1;for(o=B(n,m,n.length,l),m=0;m<_;m++)A*=l;this.imuln(A),this.words[0]+o<67108864?this.words[0]+=o:this._iaddn(o)}this.strip()},h.prototype.copy=function(n){n.words=new Array(this.length);for(var l=0;l<this.length;l++)n.words[l]=this.words[l];n.length=this.length,n.negative=this.negative,n.red=this.red},h.prototype.clone=function(){var n=new h(null);return this.copy(n),n},h.prototype._expand=function(n){for(;this.length<n;)this.words[this.length++]=0;return this},h.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},h.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},h.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var E=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],S=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],k=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];h.prototype.toString=function(n,l){n=n||10,l=l|0||1;var c;if(n===16||n==="hex"){c="";for(var p=0,y=0,b=0;b<this.length;b++){var _=this.words[b],v=((_<<p|y)&16777215).toString(16);y=_>>>24-p&16777215,p+=2,p>=26&&(p-=26,b--),y!==0||b!==this.length-1?c=E[6-v.length]+v+c:c=v+c}for(y!==0&&(c=y.toString(16)+c);c.length%l!==0;)c="0"+c;return this.negative!==0&&(c="-"+c),c}if(n===(n|0)&&n>=2&&n<=36){var o=S[n],m=k[n];c="";var A=this.clone();for(A.negative=0;!A.isZero();){var I=A.modn(m).toString(n);A=A.idivn(m),A.isZero()?c=I+c:c=E[o-I.length]+I+c}for(this.isZero()&&(c="0"+c);c.length%l!==0;)c="0"+c;return this.negative!==0&&(c="-"+c),c}u(!1,"Base should be between 2 and 36")},h.prototype.toNumber=function(){var n=this.words[0];return this.length===2?n+=this.words[1]*67108864:this.length===3&&this.words[2]===1?n+=4503599627370496+this.words[1]*67108864:this.length>2&&u(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-n:n},h.prototype.toJSON=function(){return this.toString(16)},h.prototype.toBuffer=function(n,l){return u(typeof w<"u"),this.toArrayLike(w,n,l)},h.prototype.toArray=function(n,l){return this.toArrayLike(Array,n,l)},h.prototype.toArrayLike=function(n,l,c){var p=this.byteLength(),y=c||Math.max(1,p);u(p<=y,"byte array longer than desired length"),u(y>0,"Requested array length <= 0"),this.strip();var b=l==="le",_=new n(y),v,o,m=this.clone();if(b){for(o=0;!m.isZero();o++)v=m.andln(255),m.iushrn(8),_[o]=v;for(;o<y;o++)_[o]=0}else{for(o=0;o<y-p;o++)_[o]=0;for(o=0;!m.isZero();o++)v=m.andln(255),m.iushrn(8),_[y-o-1]=v}return _},Math.clz32?h.prototype._countBits=function(n){return 32-Math.clz32(n)}:h.prototype._countBits=function(n){var l=n,c=0;return l>=4096&&(c+=13,l>>>=13),l>=64&&(c+=7,l>>>=7),l>=8&&(c+=4,l>>>=4),l>=2&&(c+=2,l>>>=2),c+l},h.prototype._zeroBits=function(n){if(n===0)return 26;var l=n,c=0;return l&8191||(c+=13,l>>>=13),l&127||(c+=7,l>>>=7),l&15||(c+=4,l>>>=4),l&3||(c+=2,l>>>=2),l&1||c++,c},h.prototype.bitLength=function(){var n=this.words[this.length-1],l=this._countBits(n);return(this.length-1)*26+l};function C($){for(var n=new Array($.bitLength()),l=0;l<n.length;l++){var c=l/26|0,p=l%26;n[l]=($.words[c]&1<<p)>>>p}return n}h.prototype.zeroBits=function(){if(this.isZero())return 0;for(var n=0,l=0;l<this.length;l++){var c=this._zeroBits(this.words[l]);if(n+=c,c!==26)break}return n},h.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},h.prototype.toTwos=function(n){return this.negative!==0?this.abs().inotn(n).iaddn(1):this.clone()},h.prototype.fromTwos=function(n){return this.testn(n-1)?this.notn(n).iaddn(1).ineg():this.clone()},h.prototype.isNeg=function(){return this.negative!==0},h.prototype.neg=function(){return this.clone().ineg()},h.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},h.prototype.iuor=function(n){for(;this.length<n.length;)this.words[this.length++]=0;for(var l=0;l<n.length;l++)this.words[l]=this.words[l]|n.words[l];return this.strip()},h.prototype.ior=function(n){return u((this.negative|n.negative)===0),this.iuor(n)},h.prototype.or=function(n){return this.length>n.length?this.clone().ior(n):n.clone().ior(this)},h.prototype.uor=function(n){return this.length>n.length?this.clone().iuor(n):n.clone().iuor(this)},h.prototype.iuand=function(n){var l;this.length>n.length?l=n:l=this;for(var c=0;c<l.length;c++)this.words[c]=this.words[c]&n.words[c];return this.length=l.length,this.strip()},h.prototype.iand=function(n){return u((this.negative|n.negative)===0),this.iuand(n)},h.prototype.and=function(n){return this.length>n.length?this.clone().iand(n):n.clone().iand(this)},h.prototype.uand=function(n){return this.length>n.length?this.clone().iuand(n):n.clone().iuand(this)},h.prototype.iuxor=function(n){var l,c;this.length>n.length?(l=this,c=n):(l=n,c=this);for(var p=0;p<c.length;p++)this.words[p]=l.words[p]^c.words[p];if(this!==l)for(;p<l.length;p++)this.words[p]=l.words[p];return this.length=l.length,this.strip()},h.prototype.ixor=function(n){return u((this.negative|n.negative)===0),this.iuxor(n)},h.prototype.xor=function(n){return this.length>n.length?this.clone().ixor(n):n.clone().ixor(this)},h.prototype.uxor=function(n){return this.length>n.length?this.clone().iuxor(n):n.clone().iuxor(this)},h.prototype.inotn=function(n){u(typeof n=="number"&&n>=0);var l=Math.ceil(n/26)|0,c=n%26;this._expand(l),c>0&&l--;for(var p=0;p<l;p++)this.words[p]=~this.words[p]&67108863;return c>0&&(this.words[p]=~this.words[p]&67108863>>26-c),this.strip()},h.prototype.notn=function(n){return this.clone().inotn(n)},h.prototype.setn=function(n,l){u(typeof n=="number"&&n>=0);var c=n/26|0,p=n%26;return this._expand(c+1),l?this.words[c]=this.words[c]|1<<p:this.words[c]=this.words[c]&~(1<<p),this.strip()},h.prototype.iadd=function(n){var l;if(this.negative!==0&&n.negative===0)return this.negative=0,l=this.isub(n),this.negative^=1,this._normSign();if(this.negative===0&&n.negative!==0)return n.negative=0,l=this.isub(n),n.negative=1,l._normSign();var c,p;this.length>n.length?(c=this,p=n):(c=n,p=this);for(var y=0,b=0;b<p.length;b++)l=(c.words[b]|0)+(p.words[b]|0)+y,this.words[b]=l&67108863,y=l>>>26;for(;y!==0&&b<c.length;b++)l=(c.words[b]|0)+y,this.words[b]=l&67108863,y=l>>>26;if(this.length=c.length,y!==0)this.words[this.length]=y,this.length++;else if(c!==this)for(;b<c.length;b++)this.words[b]=c.words[b];return this},h.prototype.add=function(n){var l;return n.negative!==0&&this.negative===0?(n.negative=0,l=this.sub(n),n.negative^=1,l):n.negative===0&&this.negative!==0?(this.negative=0,l=n.sub(this),this.negative=1,l):this.length>n.length?this.clone().iadd(n):n.clone().iadd(this)},h.prototype.isub=function(n){if(n.negative!==0){n.negative=0;var l=this.iadd(n);return n.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(n),this.negative=1,this._normSign();var c=this.cmp(n);if(c===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,y;c>0?(p=this,y=n):(p=n,y=this);for(var b=0,_=0;_<y.length;_++)l=(p.words[_]|0)-(y.words[_]|0)+b,b=l>>26,this.words[_]=l&67108863;for(;b!==0&&_<p.length;_++)l=(p.words[_]|0)+b,b=l>>26,this.words[_]=l&67108863;if(b===0&&_<p.length&&p!==this)for(;_<p.length;_++)this.words[_]=p.words[_];return this.length=Math.max(this.length,_),p!==this&&(this.negative=1),this.strip()},h.prototype.sub=function(n){return this.clone().isub(n)};function D($,n,l){l.negative=n.negative^$.negative;var c=$.length+n.length|0;l.length=c,c=c-1|0;var p=$.words[0]|0,y=n.words[0]|0,b=p*y,_=b&67108863,v=b/67108864|0;l.words[0]=_;for(var o=1;o<c;o++){for(var m=v>>>26,A=v&67108863,I=Math.min(o,n.length-1),U=Math.max(0,o-$.length+1);U<=I;U++){var X=o-U|0;p=$.words[X]|0,y=n.words[U]|0,b=p*y+A,m+=b/67108864|0,A=b&67108863}l.words[o]=A|0,v=m|0}return v!==0?l.words[o]=v|0:l.length--,l.strip()}var O=function(n,l,c){var p=n.words,y=l.words,b=c.words,_=0,v,o,m,A=p[0]|0,I=A&8191,U=A>>>13,X=p[1]|0,V=X&8191,T=X>>>13,q=p[2]|0,Z=q&8191,te=q>>>13,ee=p[3]|0,j=ee&8191,re=ee>>>13,qe=p[4]|0,de=qe&8191,pe=qe>>>13,je=p[5]|0,we=je&8191,le=je>>>13,Ve=p[6]|0,xe=Ve&8191,$e=Ve>>>13,ze=p[7]|0,me=ze&8191,ke=ze>>>13,Ge=p[8]|0,Me=Ge&8191,Ne=Ge>>>13,Ze=p[9]|0,Be=Ze&8191,De=Ze>>>13,rt=y[0]|0,Ae=rt&8191,Oe=rt>>>13,Je=y[1]|0,Re=Je&8191,He=Je>>>13,Qe=y[2]|0,Te=Qe&8191,Ue=Qe>>>13,tt=y[3]|0,Ee=tt&8191,Pe=tt>>>13,et=y[4]|0,Ie=et&8191,Le=et>>>13,it=y[5]|0,z=it&8191,N=it>>>13,H=y[6]|0,Q=H&8191,ne=H>>>13,ve=y[7]|0,he=ve&8191,be=ve>>>13,We=y[8]|0,ye=We&8191,Se=We>>>13,Ke=y[9]|0,Ce=Ke&8191,Fe=Ke>>>13;c.negative=n.negative^l.negative,c.length=19,v=Math.imul(I,Ae),o=Math.imul(I,Oe),o=o+Math.imul(U,Ae)|0,m=Math.imul(U,Oe);var Xe=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(Xe>>>26)|0,Xe&=67108863,v=Math.imul(V,Ae),o=Math.imul(V,Oe),o=o+Math.imul(T,Ae)|0,m=Math.imul(T,Oe),v=v+Math.imul(I,Re)|0,o=o+Math.imul(I,He)|0,o=o+Math.imul(U,Re)|0,m=m+Math.imul(U,He)|0;var Ye=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,v=Math.imul(Z,Ae),o=Math.imul(Z,Oe),o=o+Math.imul(te,Ae)|0,m=Math.imul(te,Oe),v=v+Math.imul(V,Re)|0,o=o+Math.imul(V,He)|0,o=o+Math.imul(T,Re)|0,m=m+Math.imul(T,He)|0,v=v+Math.imul(I,Te)|0,o=o+Math.imul(I,Ue)|0,o=o+Math.imul(U,Te)|0,m=m+Math.imul(U,Ue)|0;var nt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(nt>>>26)|0,nt&=67108863,v=Math.imul(j,Ae),o=Math.imul(j,Oe),o=o+Math.imul(re,Ae)|0,m=Math.imul(re,Oe),v=v+Math.imul(Z,Re)|0,o=o+Math.imul(Z,He)|0,o=o+Math.imul(te,Re)|0,m=m+Math.imul(te,He)|0,v=v+Math.imul(V,Te)|0,o=o+Math.imul(V,Ue)|0,o=o+Math.imul(T,Te)|0,m=m+Math.imul(T,Ue)|0,v=v+Math.imul(I,Ee)|0,o=o+Math.imul(I,Pe)|0,o=o+Math.imul(U,Ee)|0,m=m+Math.imul(U,Pe)|0;var at=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(at>>>26)|0,at&=67108863,v=Math.imul(de,Ae),o=Math.imul(de,Oe),o=o+Math.imul(pe,Ae)|0,m=Math.imul(pe,Oe),v=v+Math.imul(j,Re)|0,o=o+Math.imul(j,He)|0,o=o+Math.imul(re,Re)|0,m=m+Math.imul(re,He)|0,v=v+Math.imul(Z,Te)|0,o=o+Math.imul(Z,Ue)|0,o=o+Math.imul(te,Te)|0,m=m+Math.imul(te,Ue)|0,v=v+Math.imul(V,Ee)|0,o=o+Math.imul(V,Pe)|0,o=o+Math.imul(T,Ee)|0,m=m+Math.imul(T,Pe)|0,v=v+Math.imul(I,Ie)|0,o=o+Math.imul(I,Le)|0,o=o+Math.imul(U,Ie)|0,m=m+Math.imul(U,Le)|0;var ot=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(ot>>>26)|0,ot&=67108863,v=Math.imul(we,Ae),o=Math.imul(we,Oe),o=o+Math.imul(le,Ae)|0,m=Math.imul(le,Oe),v=v+Math.imul(de,Re)|0,o=o+Math.imul(de,He)|0,o=o+Math.imul(pe,Re)|0,m=m+Math.imul(pe,He)|0,v=v+Math.imul(j,Te)|0,o=o+Math.imul(j,Ue)|0,o=o+Math.imul(re,Te)|0,m=m+Math.imul(re,Ue)|0,v=v+Math.imul(Z,Ee)|0,o=o+Math.imul(Z,Pe)|0,o=o+Math.imul(te,Ee)|0,m=m+Math.imul(te,Pe)|0,v=v+Math.imul(V,Ie)|0,o=o+Math.imul(V,Le)|0,o=o+Math.imul(T,Ie)|0,m=m+Math.imul(T,Le)|0,v=v+Math.imul(I,z)|0,o=o+Math.imul(I,N)|0,o=o+Math.imul(U,z)|0,m=m+Math.imul(U,N)|0;var st=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(st>>>26)|0,st&=67108863,v=Math.imul(xe,Ae),o=Math.imul(xe,Oe),o=o+Math.imul($e,Ae)|0,m=Math.imul($e,Oe),v=v+Math.imul(we,Re)|0,o=o+Math.imul(we,He)|0,o=o+Math.imul(le,Re)|0,m=m+Math.imul(le,He)|0,v=v+Math.imul(de,Te)|0,o=o+Math.imul(de,Ue)|0,o=o+Math.imul(pe,Te)|0,m=m+Math.imul(pe,Ue)|0,v=v+Math.imul(j,Ee)|0,o=o+Math.imul(j,Pe)|0,o=o+Math.imul(re,Ee)|0,m=m+Math.imul(re,Pe)|0,v=v+Math.imul(Z,Ie)|0,o=o+Math.imul(Z,Le)|0,o=o+Math.imul(te,Ie)|0,m=m+Math.imul(te,Le)|0,v=v+Math.imul(V,z)|0,o=o+Math.imul(V,N)|0,o=o+Math.imul(T,z)|0,m=m+Math.imul(T,N)|0,v=v+Math.imul(I,Q)|0,o=o+Math.imul(I,ne)|0,o=o+Math.imul(U,Q)|0,m=m+Math.imul(U,ne)|0;var ht=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(ht>>>26)|0,ht&=67108863,v=Math.imul(me,Ae),o=Math.imul(me,Oe),o=o+Math.imul(ke,Ae)|0,m=Math.imul(ke,Oe),v=v+Math.imul(xe,Re)|0,o=o+Math.imul(xe,He)|0,o=o+Math.imul($e,Re)|0,m=m+Math.imul($e,He)|0,v=v+Math.imul(we,Te)|0,o=o+Math.imul(we,Ue)|0,o=o+Math.imul(le,Te)|0,m=m+Math.imul(le,Ue)|0,v=v+Math.imul(de,Ee)|0,o=o+Math.imul(de,Pe)|0,o=o+Math.imul(pe,Ee)|0,m=m+Math.imul(pe,Pe)|0,v=v+Math.imul(j,Ie)|0,o=o+Math.imul(j,Le)|0,o=o+Math.imul(re,Ie)|0,m=m+Math.imul(re,Le)|0,v=v+Math.imul(Z,z)|0,o=o+Math.imul(Z,N)|0,o=o+Math.imul(te,z)|0,m=m+Math.imul(te,N)|0,v=v+Math.imul(V,Q)|0,o=o+Math.imul(V,ne)|0,o=o+Math.imul(T,Q)|0,m=m+Math.imul(T,ne)|0,v=v+Math.imul(I,he)|0,o=o+Math.imul(I,be)|0,o=o+Math.imul(U,he)|0,m=m+Math.imul(U,be)|0;var lt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(lt>>>26)|0,lt&=67108863,v=Math.imul(Me,Ae),o=Math.imul(Me,Oe),o=o+Math.imul(Ne,Ae)|0,m=Math.imul(Ne,Oe),v=v+Math.imul(me,Re)|0,o=o+Math.imul(me,He)|0,o=o+Math.imul(ke,Re)|0,m=m+Math.imul(ke,He)|0,v=v+Math.imul(xe,Te)|0,o=o+Math.imul(xe,Ue)|0,o=o+Math.imul($e,Te)|0,m=m+Math.imul($e,Ue)|0,v=v+Math.imul(we,Ee)|0,o=o+Math.imul(we,Pe)|0,o=o+Math.imul(le,Ee)|0,m=m+Math.imul(le,Pe)|0,v=v+Math.imul(de,Ie)|0,o=o+Math.imul(de,Le)|0,o=o+Math.imul(pe,Ie)|0,m=m+Math.imul(pe,Le)|0,v=v+Math.imul(j,z)|0,o=o+Math.imul(j,N)|0,o=o+Math.imul(re,z)|0,m=m+Math.imul(re,N)|0,v=v+Math.imul(Z,Q)|0,o=o+Math.imul(Z,ne)|0,o=o+Math.imul(te,Q)|0,m=m+Math.imul(te,ne)|0,v=v+Math.imul(V,he)|0,o=o+Math.imul(V,be)|0,o=o+Math.imul(T,he)|0,m=m+Math.imul(T,be)|0,v=v+Math.imul(I,ye)|0,o=o+Math.imul(I,Se)|0,o=o+Math.imul(U,ye)|0,m=m+Math.imul(U,Se)|0;var ct=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(ct>>>26)|0,ct&=67108863,v=Math.imul(Be,Ae),o=Math.imul(Be,Oe),o=o+Math.imul(De,Ae)|0,m=Math.imul(De,Oe),v=v+Math.imul(Me,Re)|0,o=o+Math.imul(Me,He)|0,o=o+Math.imul(Ne,Re)|0,m=m+Math.imul(Ne,He)|0,v=v+Math.imul(me,Te)|0,o=o+Math.imul(me,Ue)|0,o=o+Math.imul(ke,Te)|0,m=m+Math.imul(ke,Ue)|0,v=v+Math.imul(xe,Ee)|0,o=o+Math.imul(xe,Pe)|0,o=o+Math.imul($e,Ee)|0,m=m+Math.imul($e,Pe)|0,v=v+Math.imul(we,Ie)|0,o=o+Math.imul(we,Le)|0,o=o+Math.imul(le,Ie)|0,m=m+Math.imul(le,Le)|0,v=v+Math.imul(de,z)|0,o=o+Math.imul(de,N)|0,o=o+Math.imul(pe,z)|0,m=m+Math.imul(pe,N)|0,v=v+Math.imul(j,Q)|0,o=o+Math.imul(j,ne)|0,o=o+Math.imul(re,Q)|0,m=m+Math.imul(re,ne)|0,v=v+Math.imul(Z,he)|0,o=o+Math.imul(Z,be)|0,o=o+Math.imul(te,he)|0,m=m+Math.imul(te,be)|0,v=v+Math.imul(V,ye)|0,o=o+Math.imul(V,Se)|0,o=o+Math.imul(T,ye)|0,m=m+Math.imul(T,Se)|0,v=v+Math.imul(I,Ce)|0,o=o+Math.imul(I,Fe)|0,o=o+Math.imul(U,Ce)|0,m=m+Math.imul(U,Fe)|0;var dt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(dt>>>26)|0,dt&=67108863,v=Math.imul(Be,Re),o=Math.imul(Be,He),o=o+Math.imul(De,Re)|0,m=Math.imul(De,He),v=v+Math.imul(Me,Te)|0,o=o+Math.imul(Me,Ue)|0,o=o+Math.imul(Ne,Te)|0,m=m+Math.imul(Ne,Ue)|0,v=v+Math.imul(me,Ee)|0,o=o+Math.imul(me,Pe)|0,o=o+Math.imul(ke,Ee)|0,m=m+Math.imul(ke,Pe)|0,v=v+Math.imul(xe,Ie)|0,o=o+Math.imul(xe,Le)|0,o=o+Math.imul($e,Ie)|0,m=m+Math.imul($e,Le)|0,v=v+Math.imul(we,z)|0,o=o+Math.imul(we,N)|0,o=o+Math.imul(le,z)|0,m=m+Math.imul(le,N)|0,v=v+Math.imul(de,Q)|0,o=o+Math.imul(de,ne)|0,o=o+Math.imul(pe,Q)|0,m=m+Math.imul(pe,ne)|0,v=v+Math.imul(j,he)|0,o=o+Math.imul(j,be)|0,o=o+Math.imul(re,he)|0,m=m+Math.imul(re,be)|0,v=v+Math.imul(Z,ye)|0,o=o+Math.imul(Z,Se)|0,o=o+Math.imul(te,ye)|0,m=m+Math.imul(te,Se)|0,v=v+Math.imul(V,Ce)|0,o=o+Math.imul(V,Fe)|0,o=o+Math.imul(T,Ce)|0,m=m+Math.imul(T,Fe)|0;var pt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(pt>>>26)|0,pt&=67108863,v=Math.imul(Be,Te),o=Math.imul(Be,Ue),o=o+Math.imul(De,Te)|0,m=Math.imul(De,Ue),v=v+Math.imul(Me,Ee)|0,o=o+Math.imul(Me,Pe)|0,o=o+Math.imul(Ne,Ee)|0,m=m+Math.imul(Ne,Pe)|0,v=v+Math.imul(me,Ie)|0,o=o+Math.imul(me,Le)|0,o=o+Math.imul(ke,Ie)|0,m=m+Math.imul(ke,Le)|0,v=v+Math.imul(xe,z)|0,o=o+Math.imul(xe,N)|0,o=o+Math.imul($e,z)|0,m=m+Math.imul($e,N)|0,v=v+Math.imul(we,Q)|0,o=o+Math.imul(we,ne)|0,o=o+Math.imul(le,Q)|0,m=m+Math.imul(le,ne)|0,v=v+Math.imul(de,he)|0,o=o+Math.imul(de,be)|0,o=o+Math.imul(pe,he)|0,m=m+Math.imul(pe,be)|0,v=v+Math.imul(j,ye)|0,o=o+Math.imul(j,Se)|0,o=o+Math.imul(re,ye)|0,m=m+Math.imul(re,Se)|0,v=v+Math.imul(Z,Ce)|0,o=o+Math.imul(Z,Fe)|0,o=o+Math.imul(te,Ce)|0,m=m+Math.imul(te,Fe)|0;var vt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(vt>>>26)|0,vt&=67108863,v=Math.imul(Be,Ee),o=Math.imul(Be,Pe),o=o+Math.imul(De,Ee)|0,m=Math.imul(De,Pe),v=v+Math.imul(Me,Ie)|0,o=o+Math.imul(Me,Le)|0,o=o+Math.imul(Ne,Ie)|0,m=m+Math.imul(Ne,Le)|0,v=v+Math.imul(me,z)|0,o=o+Math.imul(me,N)|0,o=o+Math.imul(ke,z)|0,m=m+Math.imul(ke,N)|0,v=v+Math.imul(xe,Q)|0,o=o+Math.imul(xe,ne)|0,o=o+Math.imul($e,Q)|0,m=m+Math.imul($e,ne)|0,v=v+Math.imul(we,he)|0,o=o+Math.imul(we,be)|0,o=o+Math.imul(le,he)|0,m=m+Math.imul(le,be)|0,v=v+Math.imul(de,ye)|0,o=o+Math.imul(de,Se)|0,o=o+Math.imul(pe,ye)|0,m=m+Math.imul(pe,Se)|0,v=v+Math.imul(j,Ce)|0,o=o+Math.imul(j,Fe)|0,o=o+Math.imul(re,Ce)|0,m=m+Math.imul(re,Fe)|0;var yt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(yt>>>26)|0,yt&=67108863,v=Math.imul(Be,Ie),o=Math.imul(Be,Le),o=o+Math.imul(De,Ie)|0,m=Math.imul(De,Le),v=v+Math.imul(Me,z)|0,o=o+Math.imul(Me,N)|0,o=o+Math.imul(Ne,z)|0,m=m+Math.imul(Ne,N)|0,v=v+Math.imul(me,Q)|0,o=o+Math.imul(me,ne)|0,o=o+Math.imul(ke,Q)|0,m=m+Math.imul(ke,ne)|0,v=v+Math.imul(xe,he)|0,o=o+Math.imul(xe,be)|0,o=o+Math.imul($e,he)|0,m=m+Math.imul($e,be)|0,v=v+Math.imul(we,ye)|0,o=o+Math.imul(we,Se)|0,o=o+Math.imul(le,ye)|0,m=m+Math.imul(le,Se)|0,v=v+Math.imul(de,Ce)|0,o=o+Math.imul(de,Fe)|0,o=o+Math.imul(pe,Ce)|0,m=m+Math.imul(pe,Fe)|0;var mt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(mt>>>26)|0,mt&=67108863,v=Math.imul(Be,z),o=Math.imul(Be,N),o=o+Math.imul(De,z)|0,m=Math.imul(De,N),v=v+Math.imul(Me,Q)|0,o=o+Math.imul(Me,ne)|0,o=o+Math.imul(Ne,Q)|0,m=m+Math.imul(Ne,ne)|0,v=v+Math.imul(me,he)|0,o=o+Math.imul(me,be)|0,o=o+Math.imul(ke,he)|0,m=m+Math.imul(ke,be)|0,v=v+Math.imul(xe,ye)|0,o=o+Math.imul(xe,Se)|0,o=o+Math.imul($e,ye)|0,m=m+Math.imul($e,Se)|0,v=v+Math.imul(we,Ce)|0,o=o+Math.imul(we,Fe)|0,o=o+Math.imul(le,Ce)|0,m=m+Math.imul(le,Fe)|0;var gt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(gt>>>26)|0,gt&=67108863,v=Math.imul(Be,Q),o=Math.imul(Be,ne),o=o+Math.imul(De,Q)|0,m=Math.imul(De,ne),v=v+Math.imul(Me,he)|0,o=o+Math.imul(Me,be)|0,o=o+Math.imul(Ne,he)|0,m=m+Math.imul(Ne,be)|0,v=v+Math.imul(me,ye)|0,o=o+Math.imul(me,Se)|0,o=o+Math.imul(ke,ye)|0,m=m+Math.imul(ke,Se)|0,v=v+Math.imul(xe,Ce)|0,o=o+Math.imul(xe,Fe)|0,o=o+Math.imul($e,Ce)|0,m=m+Math.imul($e,Fe)|0;var bt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(bt>>>26)|0,bt&=67108863,v=Math.imul(Be,he),o=Math.imul(Be,be),o=o+Math.imul(De,he)|0,m=Math.imul(De,be),v=v+Math.imul(Me,ye)|0,o=o+Math.imul(Me,Se)|0,o=o+Math.imul(Ne,ye)|0,m=m+Math.imul(Ne,Se)|0,v=v+Math.imul(me,Ce)|0,o=o+Math.imul(me,Fe)|0,o=o+Math.imul(ke,Ce)|0,m=m+Math.imul(ke,Fe)|0;var wt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(wt>>>26)|0,wt&=67108863,v=Math.imul(Be,ye),o=Math.imul(Be,Se),o=o+Math.imul(De,ye)|0,m=Math.imul(De,Se),v=v+Math.imul(Me,Ce)|0,o=o+Math.imul(Me,Fe)|0,o=o+Math.imul(Ne,Ce)|0,m=m+Math.imul(Ne,Fe)|0;var _t=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(_t>>>26)|0,_t&=67108863,v=Math.imul(Be,Ce),o=Math.imul(Be,Fe),o=o+Math.imul(De,Ce)|0,m=Math.imul(De,Fe);var xt=(_+v|0)+((o&8191)<<13)|0;return _=(m+(o>>>13)|0)+(xt>>>26)|0,xt&=67108863,b[0]=Xe,b[1]=Ye,b[2]=nt,b[3]=at,b[4]=ot,b[5]=st,b[6]=ht,b[7]=lt,b[8]=ct,b[9]=dt,b[10]=pt,b[11]=vt,b[12]=yt,b[13]=mt,b[14]=gt,b[15]=bt,b[16]=wt,b[17]=_t,b[18]=xt,_!==0&&(b[19]=_,c.length++),c};Math.imul||(O=D);function F($,n,l){l.negative=n.negative^$.negative,l.length=$.length+n.length;for(var c=0,p=0,y=0;y<l.length-1;y++){var b=p;p=0;for(var _=c&67108863,v=Math.min(y,n.length-1),o=Math.max(0,y-$.length+1);o<=v;o++){var m=y-o,A=$.words[m]|0,I=n.words[o]|0,U=A*I,X=U&67108863;b=b+(U/67108864|0)|0,X=X+_|0,_=X&67108863,b=b+(X>>>26)|0,p+=b>>>26,b&=67108863}l.words[y]=_,c=b,b=p}return c!==0?l.words[y]=c:l.length--,l.strip()}function P($,n,l){var c=new L;return c.mulp($,n,l)}h.prototype.mulTo=function(n,l){var c,p=this.length+n.length;return this.length===10&&n.length===10?c=O(this,n,l):p<63?c=D(this,n,l):p<1024?c=F(this,n,l):c=P(this,n,l),c};function L($,n){this.x=$,this.y=n}L.prototype.makeRBT=function(n){for(var l=new Array(n),c=h.prototype._countBits(n)-1,p=0;p<n;p++)l[p]=this.revBin(p,c,n);return l},L.prototype.revBin=function(n,l,c){if(n===0||n===c-1)return n;for(var p=0,y=0;y<l;y++)p|=(n&1)<<l-y-1,n>>=1;return p},L.prototype.permute=function(n,l,c,p,y,b){for(var _=0;_<b;_++)p[_]=l[n[_]],y[_]=c[n[_]]},L.prototype.transform=function(n,l,c,p,y,b){this.permute(b,n,l,c,p,y);for(var _=1;_<y;_<<=1)for(var v=_<<1,o=Math.cos(2*Math.PI/v),m=Math.sin(2*Math.PI/v),A=0;A<y;A+=v)for(var I=o,U=m,X=0;X<_;X++){var V=c[A+X],T=p[A+X],q=c[A+X+_],Z=p[A+X+_],te=I*q-U*Z;Z=I*Z+U*q,q=te,c[A+X]=V+q,p[A+X]=T+Z,c[A+X+_]=V-q,p[A+X+_]=T-Z,X!==v&&(te=o*I-m*U,U=o*U+m*I,I=te)}},L.prototype.guessLen13b=function(n,l){var c=Math.max(l,n)|1,p=c&1,y=0;for(c=c/2|0;c;c=c>>>1)y++;return 1<<y+1+p},L.prototype.conjugate=function(n,l,c){if(!(c<=1))for(var p=0;p<c/2;p++){var y=n[p];n[p]=n[c-p-1],n[c-p-1]=y,y=l[p],l[p]=-l[c-p-1],l[c-p-1]=-y}},L.prototype.normalize13b=function(n,l){for(var c=0,p=0;p<l/2;p++){var y=Math.round(n[2*p+1]/l)*8192+Math.round(n[2*p]/l)+c;n[p]=y&67108863,y<67108864?c=0:c=y/67108864|0}return n},L.prototype.convert13b=function(n,l,c,p){for(var y=0,b=0;b<l;b++)y=y+(n[b]|0),c[2*b]=y&8191,y=y>>>13,c[2*b+1]=y&8191,y=y>>>13;for(b=2*l;b<p;++b)c[b]=0;u(y===0),u((y&-8192)===0)},L.prototype.stub=function(n){for(var l=new Array(n),c=0;c<n;c++)l[c]=0;return l},L.prototype.mulp=function(n,l,c){var p=2*this.guessLen13b(n.length,l.length),y=this.makeRBT(p),b=this.stub(p),_=new Array(p),v=new Array(p),o=new Array(p),m=new Array(p),A=new Array(p),I=new Array(p),U=c.words;U.length=p,this.convert13b(n.words,n.length,_,p),this.convert13b(l.words,l.length,m,p),this.transform(_,b,v,o,p,y),this.transform(m,b,A,I,p,y);for(var X=0;X<p;X++){var V=v[X]*A[X]-o[X]*I[X];o[X]=v[X]*I[X]+o[X]*A[X],v[X]=V}return this.conjugate(v,o,p),this.transform(v,o,U,b,p,y),this.conjugate(U,b,p),this.normalize13b(U,p),c.negative=n.negative^l.negative,c.length=n.length+l.length,c.strip()},h.prototype.mul=function(n){var l=new h(null);return l.words=new Array(this.length+n.length),this.mulTo(n,l)},h.prototype.mulf=function(n){var l=new h(null);return l.words=new Array(this.length+n.length),P(this,n,l)},h.prototype.imul=function(n){return this.clone().mulTo(n,this)},h.prototype.imuln=function(n){u(typeof n=="number"),u(n<67108864);for(var l=0,c=0;c<this.length;c++){var p=(this.words[c]|0)*n,y=(p&67108863)+(l&67108863);l>>=26,l+=p/67108864|0,l+=y>>>26,this.words[c]=y&67108863}return l!==0&&(this.words[c]=l,this.length++),this.length=n===0?1:this.length,this},h.prototype.muln=function(n){return this.clone().imuln(n)},h.prototype.sqr=function(){return this.mul(this)},h.prototype.isqr=function(){return this.imul(this.clone())},h.prototype.pow=function(n){var l=C(n);if(l.length===0)return new h(1);for(var c=this,p=0;p<l.length&&l[p]===0;p++,c=c.sqr());if(++p<l.length)for(var y=c.sqr();p<l.length;p++,y=y.sqr())l[p]!==0&&(c=c.mul(y));return c},h.prototype.iushln=function(n){u(typeof n=="number"&&n>=0);var l=n%26,c=(n-l)/26,p=67108863>>>26-l<<26-l,y;if(l!==0){var b=0;for(y=0;y<this.length;y++){var _=this.words[y]&p,v=(this.words[y]|0)-_<<l;this.words[y]=v|b,b=_>>>26-l}b&&(this.words[y]=b,this.length++)}if(c!==0){for(y=this.length-1;y>=0;y--)this.words[y+c]=this.words[y];for(y=0;y<c;y++)this.words[y]=0;this.length+=c}return this.strip()},h.prototype.ishln=function(n){return u(this.negative===0),this.iushln(n)},h.prototype.iushrn=function(n,l,c){u(typeof n=="number"&&n>=0);var p;l?p=(l-l%26)/26:p=0;var y=n%26,b=Math.min((n-y)/26,this.length),_=67108863^67108863>>>y<<y,v=c;if(p-=b,p=Math.max(0,p),v){for(var o=0;o<b;o++)v.words[o]=this.words[o];v.length=b}if(b!==0)if(this.length>b)for(this.length-=b,o=0;o<this.length;o++)this.words[o]=this.words[o+b];else this.words[0]=0,this.length=1;var m=0;for(o=this.length-1;o>=0&&(m!==0||o>=p);o--){var A=this.words[o]|0;this.words[o]=m<<26-y|A>>>y,m=A&_}return v&&m!==0&&(v.words[v.length++]=m),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},h.prototype.ishrn=function(n,l,c){return u(this.negative===0),this.iushrn(n,l,c)},h.prototype.shln=function(n){return this.clone().ishln(n)},h.prototype.ushln=function(n){return this.clone().iushln(n)},h.prototype.shrn=function(n){return this.clone().ishrn(n)},h.prototype.ushrn=function(n){return this.clone().iushrn(n)},h.prototype.testn=function(n){u(typeof n=="number"&&n>=0);var l=n%26,c=(n-l)/26,p=1<<l;if(this.length<=c)return!1;var y=this.words[c];return!!(y&p)},h.prototype.imaskn=function(n){u(typeof n=="number"&&n>=0);var l=n%26,c=(n-l)/26;if(u(this.negative===0,"imaskn works only with positive numbers"),this.length<=c)return this;if(l!==0&&c++,this.length=Math.min(c,this.length),l!==0){var p=67108863^67108863>>>l<<l;this.words[this.length-1]&=p}return this.strip()},h.prototype.maskn=function(n){return this.clone().imaskn(n)},h.prototype.iaddn=function(n){return u(typeof n=="number"),u(n<67108864),n<0?this.isubn(-n):this.negative!==0?this.length===1&&(this.words[0]|0)<n?(this.words[0]=n-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(n),this.negative=1,this):this._iaddn(n)},h.prototype._iaddn=function(n){this.words[0]+=n;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},h.prototype.isubn=function(n){if(u(typeof n=="number"),u(n<67108864),n<0)return this.iaddn(-n);if(this.negative!==0)return this.negative=0,this.iaddn(n),this.negative=1,this;if(this.words[0]-=n,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this.strip()},h.prototype.addn=function(n){return this.clone().iaddn(n)},h.prototype.subn=function(n){return this.clone().isubn(n)},h.prototype.iabs=function(){return this.negative=0,this},h.prototype.abs=function(){return this.clone().iabs()},h.prototype._ishlnsubmul=function(n,l,c){var p=n.length+c,y;this._expand(p);var b,_=0;for(y=0;y<n.length;y++){b=(this.words[y+c]|0)+_;var v=(n.words[y]|0)*l;b-=v&67108863,_=(b>>26)-(v/67108864|0),this.words[y+c]=b&67108863}for(;y<this.length-c;y++)b=(this.words[y+c]|0)+_,_=b>>26,this.words[y+c]=b&67108863;if(_===0)return this.strip();for(u(_===-1),_=0,y=0;y<this.length;y++)b=-(this.words[y]|0)+_,_=b>>26,this.words[y]=b&67108863;return this.negative=1,this.strip()},h.prototype._wordDiv=function(n,l){var c=this.length-n.length,p=this.clone(),y=n,b=y.words[y.length-1]|0,_=this._countBits(b);c=26-_,c!==0&&(y=y.ushln(c),p.iushln(c),b=y.words[y.length-1]|0);var v=p.length-y.length,o;if(l!=="mod"){o=new h(null),o.length=v+1,o.words=new Array(o.length);for(var m=0;m<o.length;m++)o.words[m]=0}var A=p.clone()._ishlnsubmul(y,1,v);A.negative===0&&(p=A,o&&(o.words[v]=1));for(var I=v-1;I>=0;I--){var U=(p.words[y.length+I]|0)*67108864+(p.words[y.length+I-1]|0);for(U=Math.min(U/b|0,67108863),p._ishlnsubmul(y,U,I);p.negative!==0;)U--,p.negative=0,p._ishlnsubmul(y,1,I),p.isZero()||(p.negative^=1);o&&(o.words[I]=U)}return o&&o.strip(),p.strip(),l!=="div"&&c!==0&&p.iushrn(c),{div:o||null,mod:p}},h.prototype.divmod=function(n,l,c){if(u(!n.isZero()),this.isZero())return{div:new h(0),mod:new h(0)};var p,y,b;return this.negative!==0&&n.negative===0?(b=this.neg().divmod(n,l),l!=="mod"&&(p=b.div.neg()),l!=="div"&&(y=b.mod.neg(),c&&y.negative!==0&&y.iadd(n)),{div:p,mod:y}):this.negative===0&&n.negative!==0?(b=this.divmod(n.neg(),l),l!=="mod"&&(p=b.div.neg()),{div:p,mod:b.mod}):this.negative&n.negative?(b=this.neg().divmod(n.neg(),l),l!=="div"&&(y=b.mod.neg(),c&&y.negative!==0&&y.isub(n)),{div:b.div,mod:y}):n.length>this.length||this.cmp(n)<0?{div:new h(0),mod:this}:n.length===1?l==="div"?{div:this.divn(n.words[0]),mod:null}:l==="mod"?{div:null,mod:new h(this.modn(n.words[0]))}:{div:this.divn(n.words[0]),mod:new h(this.modn(n.words[0]))}:this._wordDiv(n,l)},h.prototype.div=function(n){return this.divmod(n,"div",!1).div},h.prototype.mod=function(n){return this.divmod(n,"mod",!1).mod},h.prototype.umod=function(n){return this.divmod(n,"mod",!0).mod},h.prototype.divRound=function(n){var l=this.divmod(n);if(l.mod.isZero())return l.div;var c=l.div.negative!==0?l.mod.isub(n):l.mod,p=n.ushrn(1),y=n.andln(1),b=c.cmp(p);return b<0||y===1&&b===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},h.prototype.modn=function(n){u(n<=67108863);for(var l=(1<<26)%n,c=0,p=this.length-1;p>=0;p--)c=(l*c+(this.words[p]|0))%n;return c},h.prototype.idivn=function(n){u(n<=67108863);for(var l=0,c=this.length-1;c>=0;c--){var p=(this.words[c]|0)+l*67108864;this.words[c]=p/n|0,l=p%n}return this.strip()},h.prototype.divn=function(n){return this.clone().idivn(n)},h.prototype.egcd=function(n){u(n.negative===0),u(!n.isZero());var l=this,c=n.clone();l.negative!==0?l=l.umod(n):l=l.clone();for(var p=new h(1),y=new h(0),b=new h(0),_=new h(1),v=0;l.isEven()&&c.isEven();)l.iushrn(1),c.iushrn(1),++v;for(var o=c.clone(),m=l.clone();!l.isZero();){for(var A=0,I=1;!(l.words[0]&I)&&A<26;++A,I<<=1);if(A>0)for(l.iushrn(A);A-- >0;)(p.isOdd()||y.isOdd())&&(p.iadd(o),y.isub(m)),p.iushrn(1),y.iushrn(1);for(var U=0,X=1;!(c.words[0]&X)&&U<26;++U,X<<=1);if(U>0)for(c.iushrn(U);U-- >0;)(b.isOdd()||_.isOdd())&&(b.iadd(o),_.isub(m)),b.iushrn(1),_.iushrn(1);l.cmp(c)>=0?(l.isub(c),p.isub(b),y.isub(_)):(c.isub(l),b.isub(p),_.isub(y))}return{a:b,b:_,gcd:c.iushln(v)}},h.prototype._invmp=function(n){u(n.negative===0),u(!n.isZero());var l=this,c=n.clone();l.negative!==0?l=l.umod(n):l=l.clone();for(var p=new h(1),y=new h(0),b=c.clone();l.cmpn(1)>0&&c.cmpn(1)>0;){for(var _=0,v=1;!(l.words[0]&v)&&_<26;++_,v<<=1);if(_>0)for(l.iushrn(_);_-- >0;)p.isOdd()&&p.iadd(b),p.iushrn(1);for(var o=0,m=1;!(c.words[0]&m)&&o<26;++o,m<<=1);if(o>0)for(c.iushrn(o);o-- >0;)y.isOdd()&&y.iadd(b),y.iushrn(1);l.cmp(c)>=0?(l.isub(c),p.isub(y)):(c.isub(l),y.isub(p))}var A;return l.cmpn(1)===0?A=p:A=y,A.cmpn(0)<0&&A.iadd(n),A},h.prototype.gcd=function(n){if(this.isZero())return n.abs();if(n.isZero())return this.abs();var l=this.clone(),c=n.clone();l.negative=0,c.negative=0;for(var p=0;l.isEven()&&c.isEven();p++)l.iushrn(1),c.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;c.isEven();)c.iushrn(1);var y=l.cmp(c);if(y<0){var b=l;l=c,c=b}else if(y===0||c.cmpn(1)===0)break;l.isub(c)}while(!0);return c.iushln(p)},h.prototype.invm=function(n){return this.egcd(n).a.umod(n)},h.prototype.isEven=function(){return(this.words[0]&1)===0},h.prototype.isOdd=function(){return(this.words[0]&1)===1},h.prototype.andln=function(n){return this.words[0]&n},h.prototype.bincn=function(n){u(typeof n=="number");var l=n%26,c=(n-l)/26,p=1<<l;if(this.length<=c)return this._expand(c+1),this.words[c]|=p,this;for(var y=p,b=c;y!==0&&b<this.length;b++){var _=this.words[b]|0;_+=y,y=_>>>26,_&=67108863,this.words[b]=_}return y!==0&&(this.words[b]=y,this.length++),this},h.prototype.isZero=function(){return this.length===1&&this.words[0]===0},h.prototype.cmpn=function(n){var l=n<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this.strip();var c;if(this.length>1)c=1;else{l&&(n=-n),u(n<=67108863,"Number is too big");var p=this.words[0]|0;c=p===n?0:p<n?-1:1}return this.negative!==0?-c|0:c},h.prototype.cmp=function(n){if(this.negative!==0&&n.negative===0)return-1;if(this.negative===0&&n.negative!==0)return 1;var l=this.ucmp(n);return this.negative!==0?-l|0:l},h.prototype.ucmp=function(n){if(this.length>n.length)return 1;if(this.length<n.length)return-1;for(var l=0,c=this.length-1;c>=0;c--){var p=this.words[c]|0,y=n.words[c]|0;if(p!==y){p<y?l=-1:p>y&&(l=1);break}}return l},h.prototype.gtn=function(n){return this.cmpn(n)===1},h.prototype.gt=function(n){return this.cmp(n)===1},h.prototype.gten=function(n){return this.cmpn(n)>=0},h.prototype.gte=function(n){return this.cmp(n)>=0},h.prototype.ltn=function(n){return this.cmpn(n)===-1},h.prototype.lt=function(n){return this.cmp(n)===-1},h.prototype.lten=function(n){return this.cmpn(n)<=0},h.prototype.lte=function(n){return this.cmp(n)<=0},h.prototype.eqn=function(n){return this.cmpn(n)===0},h.prototype.eq=function(n){return this.cmp(n)===0},h.red=function(n){return new ie(n)},h.prototype.toRed=function(n){return u(!this.red,"Already a number in reduction context"),u(this.negative===0,"red works only with positives"),n.convertTo(this)._forceRed(n)},h.prototype.fromRed=function(){return u(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},h.prototype._forceRed=function(n){return this.red=n,this},h.prototype.forceRed=function(n){return u(!this.red,"Already a number in reduction context"),this._forceRed(n)},h.prototype.redAdd=function(n){return u(this.red,"redAdd works only with red numbers"),this.red.add(this,n)},h.prototype.redIAdd=function(n){return u(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,n)},h.prototype.redSub=function(n){return u(this.red,"redSub works only with red numbers"),this.red.sub(this,n)},h.prototype.redISub=function(n){return u(this.red,"redISub works only with red numbers"),this.red.isub(this,n)},h.prototype.redShl=function(n){return u(this.red,"redShl works only with red numbers"),this.red.shl(this,n)},h.prototype.redMul=function(n){return u(this.red,"redMul works only with red numbers"),this.red._verify2(this,n),this.red.mul(this,n)},h.prototype.redIMul=function(n){return u(this.red,"redMul works only with red numbers"),this.red._verify2(this,n),this.red.imul(this,n)},h.prototype.redSqr=function(){return u(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},h.prototype.redISqr=function(){return u(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},h.prototype.redSqrt=function(){return u(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},h.prototype.redInvm=function(){return u(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},h.prototype.redNeg=function(){return u(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},h.prototype.redPow=function(n){return u(this.red&&!n.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,n)};var J={k256:null,p224:null,p192:null,p25519:null};function Y($,n){this.name=$,this.p=new h(n,16),this.n=this.p.bitLength(),this.k=new h(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}Y.prototype._tmp=function(){var n=new h(null);return n.words=new Array(Math.ceil(this.n/13)),n},Y.prototype.ireduce=function(n){var l=n,c;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),c=l.bitLength();while(c>this.n);var p=c<this.n?-1:l.ucmp(this.p);return p===0?(l.words[0]=0,l.length=1):p>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},Y.prototype.split=function(n,l){n.iushrn(this.n,0,l)},Y.prototype.imulK=function(n){return n.imul(this.k)};function ae(){Y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}d(ae,Y),ae.prototype.split=function(n,l){for(var c=4194303,p=Math.min(n.length,9),y=0;y<p;y++)l.words[y]=n.words[y];if(l.length=p,n.length<=9){n.words[0]=0,n.length=1;return}var b=n.words[9];for(l.words[l.length++]=b&c,y=10;y<n.length;y++){var _=n.words[y]|0;n.words[y-10]=(_&c)<<4|b>>>22,b=_}b>>>=22,n.words[y-10]=b,b===0&&n.length>10?n.length-=10:n.length-=9},ae.prototype.imulK=function(n){n.words[n.length]=0,n.words[n.length+1]=0,n.length+=2;for(var l=0,c=0;c<n.length;c++){var p=n.words[c]|0;l+=p*977,n.words[c]=l&67108863,l=p*64+(l/67108864|0)}return n.words[n.length-1]===0&&(n.length--,n.words[n.length-1]===0&&n.length--),n};function oe(){Y.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}d(oe,Y);function ue(){Y.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}d(ue,Y);function se(){Y.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}d(se,Y),se.prototype.imulK=function(n){for(var l=0,c=0;c<n.length;c++){var p=(n.words[c]|0)*19+l,y=p&67108863;p>>>=26,n.words[c]=y,l=p}return l!==0&&(n.words[n.length++]=l),n},h._prime=function(n){if(J[n])return J[n];var l;if(n==="k256")l=new ae;else if(n==="p224")l=new oe;else if(n==="p192")l=new ue;else if(n==="p25519")l=new se;else throw new Error("Unknown prime "+n);return J[n]=l,l};function ie($){if(typeof $=="string"){var n=h._prime($);this.m=n.p,this.prime=n}else u($.gtn(1),"modulus must be greater than 1"),this.m=$,this.prime=null}ie.prototype._verify1=function(n){u(n.negative===0,"red works only with positives"),u(n.red,"red works only with red numbers")},ie.prototype._verify2=function(n,l){u((n.negative|l.negative)===0,"red works only with positives"),u(n.red&&n.red===l.red,"red works only with red numbers")},ie.prototype.imod=function(n){return this.prime?this.prime.ireduce(n)._forceRed(this):n.umod(this.m)._forceRed(this)},ie.prototype.neg=function(n){return n.isZero()?n.clone():this.m.sub(n)._forceRed(this)},ie.prototype.add=function(n,l){this._verify2(n,l);var c=n.add(l);return c.cmp(this.m)>=0&&c.isub(this.m),c._forceRed(this)},ie.prototype.iadd=function(n,l){this._verify2(n,l);var c=n.iadd(l);return c.cmp(this.m)>=0&&c.isub(this.m),c},ie.prototype.sub=function(n,l){this._verify2(n,l);var c=n.sub(l);return c.cmpn(0)<0&&c.iadd(this.m),c._forceRed(this)},ie.prototype.isub=function(n,l){this._verify2(n,l);var c=n.isub(l);return c.cmpn(0)<0&&c.iadd(this.m),c},ie.prototype.shl=function(n,l){return this._verify1(n),this.imod(n.ushln(l))},ie.prototype.imul=function(n,l){return this._verify2(n,l),this.imod(n.imul(l))},ie.prototype.mul=function(n,l){return this._verify2(n,l),this.imod(n.mul(l))},ie.prototype.isqr=function(n){return this.imul(n,n.clone())},ie.prototype.sqr=function(n){return this.mul(n,n)},ie.prototype.sqrt=function(n){if(n.isZero())return n.clone();var l=this.m.andln(3);if(u(l%2===1),l===3){var c=this.m.add(new h(1)).iushrn(2);return this.pow(n,c)}for(var p=this.m.subn(1),y=0;!p.isZero()&&p.andln(1)===0;)y++,p.iushrn(1);u(!p.isZero());var b=new h(1).toRed(this),_=b.redNeg(),v=this.m.subn(1).iushrn(1),o=this.m.bitLength();for(o=new h(2*o*o).toRed(this);this.pow(o,v).cmp(_)!==0;)o.redIAdd(_);for(var m=this.pow(o,p),A=this.pow(n,p.addn(1).iushrn(1)),I=this.pow(n,p),U=y;I.cmp(b)!==0;){for(var X=I,V=0;X.cmp(b)!==0;V++)X=X.redSqr();u(V<U);var T=this.pow(m,new h(1).iushln(U-V-1));A=A.redMul(T),m=T.redSqr(),I=I.redMul(m),U=V}return A},ie.prototype.invm=function(n){var l=n._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},ie.prototype.pow=function(n,l){if(l.isZero())return new h(1).toRed(this);if(l.cmpn(1)===0)return n.clone();var c=4,p=new Array(1<<c);p[0]=new h(1).toRed(this),p[1]=n;for(var y=2;y<p.length;y++)p[y]=this.mul(p[y-1],n);var b=p[0],_=0,v=0,o=l.bitLength()%26;for(o===0&&(o=26),y=l.length-1;y>=0;y--){for(var m=l.words[y],A=o-1;A>=0;A--){var I=m>>A&1;if(b!==p[0]&&(b=this.sqr(b)),I===0&&_===0){v=0;continue}_<<=1,_|=I,v++,!(v!==c&&(y!==0||A!==0))&&(b=this.mul(b,p[_]),v=0,_=0)}o=26}return b},ie.prototype.convertTo=function(n){var l=n.umod(this.m);return l===n?l.clone():l},ie.prototype.convertFrom=function(n){var l=n.clone();return l.red=null,l},h.mont=function(n){return new ce(n)};function ce($){ie.call(this,$),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new h(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}d(ce,ie),ce.prototype.convertTo=function(n){return this.imod(n.ushln(this.shift))},ce.prototype.convertFrom=function(n){var l=this.imod(n.mul(this.rinv));return l.red=null,l},ce.prototype.imul=function(n,l){if(n.isZero()||l.isZero())return n.words[0]=0,n.length=1,n;var c=n.imul(l),p=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=c.isub(p).iushrn(this.shift),b=y;return y.cmp(this.m)>=0?b=y.isub(this.m):y.cmpn(0)<0&&(b=y.iadd(this.m)),b._forceRed(this)},ce.prototype.mul=function(n,l){if(n.isZero()||l.isZero())return new h(0)._forceRed(this);var c=n.mul(l),p=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=c.isub(p).iushrn(this.shift),b=y;return y.cmp(this.m)>=0?b=y.isub(this.m):y.cmpn(0)<0&&(b=y.iadd(this.m)),b._forceRed(this)},ce.prototype.invm=function(n){var l=this.imod(n._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(e,commonjsGlobal)})(bn$1);var bnExports$1=bn$1.exports,browser$2,hasRequiredBrowser;function requireBrowser(){if(hasRequiredBrowser)return browser$2;hasRequiredBrowser=1;var e=requireElliptic(),t=bnExports$1;browser$2=function(w){return new u(w)};var a={secp256k1:{name:"secp256k1",byteLength:32},secp224r1:{name:"p224",byteLength:28},prime256v1:{name:"p256",byteLength:32},prime192v1:{name:"p192",byteLength:24},ed25519:{name:"ed25519",byteLength:32},secp384r1:{name:"p384",byteLength:48},secp521r1:{name:"p521",byteLength:66}};a.p224=a.secp224r1,a.p256=a.secp256r1=a.prime256v1,a.p192=a.secp192r1=a.prime192v1,a.p384=a.secp384r1,a.p521=a.secp521r1;function u(h){this.curveType=a[h],this.curveType||(this.curveType={name:h}),this.curve=new e.ec(this.curveType.name),this.keys=void 0}u.prototype.generateKeys=function(h,w){return this.keys=this.curve.genKeyPair(),this.getPublicKey(h,w)},u.prototype.computeSecret=function(h,w,x){w=w||"utf8",Buffer$F.isBuffer(h)||(h=new Buffer$F(h,w));var M=this.curve.keyFromPublic(h).getPublic(),B=M.mul(this.keys.getPrivate()).getX();return d(B,x,this.curveType.byteLength)},u.prototype.getPublicKey=function(h,w){var x=this.keys.getPublic(w==="compressed",!0);return w==="hybrid"&&(x[x.length-1]%2?x[0]=7:x[0]=6),d(x,h)},u.prototype.getPrivateKey=function(h){return d(this.keys.getPrivate(),h)},u.prototype.setPublicKey=function(h,w){return w=w||"utf8",Buffer$F.isBuffer(h)||(h=new Buffer$F(h,w)),this.keys._importPublic(h),this},u.prototype.setPrivateKey=function(h,w){w=w||"utf8",Buffer$F.isBuffer(h)||(h=new Buffer$F(h,w));var x=new t(h);return x=x.toString(16),this.keys=this.curve.genKeyPair(),this.keys._importPrivate(x),this};function d(h,w,x){Array.isArray(h)||(h=h.toArray());var M=new Buffer$F(h);if(x&&M.length<x){var B=new Buffer$F(x-M.length);B.fill(0),M=Buffer$F.concat([B,M])}return w?M.toString(w):M}return browser$2}var browser$1={},createHash$2=browser$9,Buffer$4=safeBufferExports$2.Buffer,mgf$2=function(e,t){for(var a=Buffer$4.alloc(0),u=0,d;a.length<t;)d=i2ops(u++),a=Buffer$4.concat([a,createHash$2("sha1").update(e).update(d).digest()]);return a.slice(0,t)};function i2ops(e){var t=Buffer$4.allocUnsafe(4);return t.writeUInt32BE(e,0),t}var xor$2=function e(t,a){for(var u=t.length,d=-1;++d<u;)t[d]^=a[d];return t},bn={exports:{}};bn.exports;(function(e){(function(t,a){function u($,n){if(!$)throw new Error(n||"Assertion failed")}function d($,n){$.super_=n;var l=function(){};l.prototype=n.prototype,$.prototype=new l,$.prototype.constructor=$}function h($,n,l){if(h.isBN($))return $;this.negative=0,this.words=null,this.length=0,this.red=null,$!==null&&((n==="le"||n==="be")&&(l=n,n=10),this._init($||0,n||10,l||"be"))}typeof t=="object"?t.exports=h:a.BN=h,h.BN=h,h.wordSize=26;var w;try{typeof window<"u"&&typeof window.Buffer<"u"?w=window.Buffer:w=dist.Buffer}catch{}h.isBN=function(n){return n instanceof h?!0:n!==null&&typeof n=="object"&&n.constructor.wordSize===h.wordSize&&Array.isArray(n.words)},h.max=function(n,l){return n.cmp(l)>0?n:l},h.min=function(n,l){return n.cmp(l)<0?n:l},h.prototype._init=function(n,l,c){if(typeof n=="number")return this._initNumber(n,l,c);if(typeof n=="object")return this._initArray(n,l,c);l==="hex"&&(l=16),u(l===(l|0)&&l>=2&&l<=36),n=n.toString().replace(/\s+/g,"");var p=0;n[0]==="-"&&(p++,this.negative=1),p<n.length&&(l===16?this._parseHex(n,p,c):(this._parseBase(n,l,p),c==="le"&&this._initArray(this.toArray(),l,c)))},h.prototype._initNumber=function(n,l,c){n<0&&(this.negative=1,n=-n),n<67108864?(this.words=[n&67108863],this.length=1):n<4503599627370496?(this.words=[n&67108863,n/67108864&67108863],this.length=2):(u(n<9007199254740992),this.words=[n&67108863,n/67108864&67108863,1],this.length=3),c==="le"&&this._initArray(this.toArray(),l,c)},h.prototype._initArray=function(n,l,c){if(u(typeof n.length=="number"),n.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(n.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var y,b,_=0;if(c==="be")for(p=n.length-1,y=0;p>=0;p-=3)b=n[p]|n[p-1]<<8|n[p-2]<<16,this.words[y]|=b<<_&67108863,this.words[y+1]=b>>>26-_&67108863,_+=24,_>=26&&(_-=26,y++);else if(c==="le")for(p=0,y=0;p<n.length;p+=3)b=n[p]|n[p+1]<<8|n[p+2]<<16,this.words[y]|=b<<_&67108863,this.words[y+1]=b>>>26-_&67108863,_+=24,_>=26&&(_-=26,y++);return this.strip()};function x($,n){var l=$.charCodeAt(n);return l>=65&&l<=70?l-55:l>=97&&l<=102?l-87:l-48&15}function M($,n,l){var c=x($,l);return l-1>=n&&(c|=x($,l-1)<<4),c}h.prototype._parseHex=function(n,l,c){this.length=Math.ceil((n.length-l)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var y=0,b=0,_;if(c==="be")for(p=n.length-1;p>=l;p-=2)_=M(n,l,p)<<y,this.words[b]|=_&67108863,y>=18?(y-=18,b+=1,this.words[b]|=_>>>26):y+=8;else{var v=n.length-l;for(p=v%2===0?l+1:l;p<n.length;p+=2)_=M(n,l,p)<<y,this.words[b]|=_&67108863,y>=18?(y-=18,b+=1,this.words[b]|=_>>>26):y+=8}this.strip()};function B($,n,l,c){for(var p=0,y=Math.min($.length,l),b=n;b<y;b++){var _=$.charCodeAt(b)-48;p*=c,_>=49?p+=_-49+10:_>=17?p+=_-17+10:p+=_}return p}h.prototype._parseBase=function(n,l,c){this.words=[0],this.length=1;for(var p=0,y=1;y<=67108863;y*=l)p++;p--,y=y/l|0;for(var b=n.length-c,_=b%p,v=Math.min(b,b-_)+c,o=0,m=c;m<v;m+=p)o=B(n,m,m+p,l),this.imuln(y),this.words[0]+o<67108864?this.words[0]+=o:this._iaddn(o);if(_!==0){var A=1;for(o=B(n,m,n.length,l),m=0;m<_;m++)A*=l;this.imuln(A),this.words[0]+o<67108864?this.words[0]+=o:this._iaddn(o)}this.strip()},h.prototype.copy=function(n){n.words=new Array(this.length);for(var l=0;l<this.length;l++)n.words[l]=this.words[l];n.length=this.length,n.negative=this.negative,n.red=this.red},h.prototype.clone=function(){var n=new h(null);return this.copy(n),n},h.prototype._expand=function(n){for(;this.length<n;)this.words[this.length++]=0;return this},h.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},h.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},h.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var E=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],S=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],k=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];h.prototype.toString=function(n,l){n=n||10,l=l|0||1;var c;if(n===16||n==="hex"){c="";for(var p=0,y=0,b=0;b<this.length;b++){var _=this.words[b],v=((_<<p|y)&16777215).toString(16);y=_>>>24-p&16777215,p+=2,p>=26&&(p-=26,b--),y!==0||b!==this.length-1?c=E[6-v.length]+v+c:c=v+c}for(y!==0&&(c=y.toString(16)+c);c.length%l!==0;)c="0"+c;return this.negative!==0&&(c="-"+c),c}if(n===(n|0)&&n>=2&&n<=36){var o=S[n],m=k[n];c="";var A=this.clone();for(A.negative=0;!A.isZero();){var I=A.modn(m).toString(n);A=A.idivn(m),A.isZero()?c=I+c:c=E[o-I.length]+I+c}for(this.isZero()&&(c="0"+c);c.length%l!==0;)c="0"+c;return this.negative!==0&&(c="-"+c),c}u(!1,"Base should be between 2 and 36")},h.prototype.toNumber=function(){var n=this.words[0];return this.length===2?n+=this.words[1]*67108864:this.length===3&&this.words[2]===1?n+=4503599627370496+this.words[1]*67108864:this.length>2&&u(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-n:n},h.prototype.toJSON=function(){return this.toString(16)},h.prototype.toBuffer=function(n,l){return u(typeof w<"u"),this.toArrayLike(w,n,l)},h.prototype.toArray=function(n,l){return this.toArrayLike(Array,n,l)},h.prototype.toArrayLike=function(n,l,c){var p=this.byteLength(),y=c||Math.max(1,p);u(p<=y,"byte array longer than desired length"),u(y>0,"Requested array length <= 0"),this.strip();var b=l==="le",_=new n(y),v,o,m=this.clone();if(b){for(o=0;!m.isZero();o++)v=m.andln(255),m.iushrn(8),_[o]=v;for(;o<y;o++)_[o]=0}else{for(o=0;o<y-p;o++)_[o]=0;for(o=0;!m.isZero();o++)v=m.andln(255),m.iushrn(8),_[y-o-1]=v}return _},Math.clz32?h.prototype._countBits=function(n){return 32-Math.clz32(n)}:h.prototype._countBits=function(n){var l=n,c=0;return l>=4096&&(c+=13,l>>>=13),l>=64&&(c+=7,l>>>=7),l>=8&&(c+=4,l>>>=4),l>=2&&(c+=2,l>>>=2),c+l},h.prototype._zeroBits=function(n){if(n===0)return 26;var l=n,c=0;return l&8191||(c+=13,l>>>=13),l&127||(c+=7,l>>>=7),l&15||(c+=4,l>>>=4),l&3||(c+=2,l>>>=2),l&1||c++,c},h.prototype.bitLength=function(){var n=this.words[this.length-1],l=this._countBits(n);return(this.length-1)*26+l};function C($){for(var n=new Array($.bitLength()),l=0;l<n.length;l++){var c=l/26|0,p=l%26;n[l]=($.words[c]&1<<p)>>>p}return n}h.prototype.zeroBits=function(){if(this.isZero())return 0;for(var n=0,l=0;l<this.length;l++){var c=this._zeroBits(this.words[l]);if(n+=c,c!==26)break}return n},h.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},h.prototype.toTwos=function(n){return this.negative!==0?this.abs().inotn(n).iaddn(1):this.clone()},h.prototype.fromTwos=function(n){return this.testn(n-1)?this.notn(n).iaddn(1).ineg():this.clone()},h.prototype.isNeg=function(){return this.negative!==0},h.prototype.neg=function(){return this.clone().ineg()},h.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},h.prototype.iuor=function(n){for(;this.length<n.length;)this.words[this.length++]=0;for(var l=0;l<n.length;l++)this.words[l]=this.words[l]|n.words[l];return this.strip()},h.prototype.ior=function(n){return u((this.negative|n.negative)===0),this.iuor(n)},h.prototype.or=function(n){return this.length>n.length?this.clone().ior(n):n.clone().ior(this)},h.prototype.uor=function(n){return this.length>n.length?this.clone().iuor(n):n.clone().iuor(this)},h.prototype.iuand=function(n){var l;this.length>n.length?l=n:l=this;for(var c=0;c<l.length;c++)this.words[c]=this.words[c]&n.words[c];return this.length=l.length,this.strip()},h.prototype.iand=function(n){return u((this.negative|n.negative)===0),this.iuand(n)},h.prototype.and=function(n){return this.length>n.length?this.clone().iand(n):n.clone().iand(this)},h.prototype.uand=function(n){return this.length>n.length?this.clone().iuand(n):n.clone().iuand(this)},h.prototype.iuxor=function(n){var l,c;this.length>n.length?(l=this,c=n):(l=n,c=this);for(var p=0;p<c.length;p++)this.words[p]=l.words[p]^c.words[p];if(this!==l)for(;p<l.length;p++)this.words[p]=l.words[p];return this.length=l.length,this.strip()},h.prototype.ixor=function(n){return u((this.negative|n.negative)===0),this.iuxor(n)},h.prototype.xor=function(n){return this.length>n.length?this.clone().ixor(n):n.clone().ixor(this)},h.prototype.uxor=function(n){return this.length>n.length?this.clone().iuxor(n):n.clone().iuxor(this)},h.prototype.inotn=function(n){u(typeof n=="number"&&n>=0);var l=Math.ceil(n/26)|0,c=n%26;this._expand(l),c>0&&l--;for(var p=0;p<l;p++)this.words[p]=~this.words[p]&67108863;return c>0&&(this.words[p]=~this.words[p]&67108863>>26-c),this.strip()},h.prototype.notn=function(n){return this.clone().inotn(n)},h.prototype.setn=function(n,l){u(typeof n=="number"&&n>=0);var c=n/26|0,p=n%26;return this._expand(c+1),l?this.words[c]=this.words[c]|1<<p:this.words[c]=this.words[c]&~(1<<p),this.strip()},h.prototype.iadd=function(n){var l;if(this.negative!==0&&n.negative===0)return this.negative=0,l=this.isub(n),this.negative^=1,this._normSign();if(this.negative===0&&n.negative!==0)return n.negative=0,l=this.isub(n),n.negative=1,l._normSign();var c,p;this.length>n.length?(c=this,p=n):(c=n,p=this);for(var y=0,b=0;b<p.length;b++)l=(c.words[b]|0)+(p.words[b]|0)+y,this.words[b]=l&67108863,y=l>>>26;for(;y!==0&&b<c.length;b++)l=(c.words[b]|0)+y,this.words[b]=l&67108863,y=l>>>26;if(this.length=c.length,y!==0)this.words[this.length]=y,this.length++;else if(c!==this)for(;b<c.length;b++)this.words[b]=c.words[b];return this},h.prototype.add=function(n){var l;return n.negative!==0&&this.negative===0?(n.negative=0,l=this.sub(n),n.negative^=1,l):n.negative===0&&this.negative!==0?(this.negative=0,l=n.sub(this),this.negative=1,l):this.length>n.length?this.clone().iadd(n):n.clone().iadd(this)},h.prototype.isub=function(n){if(n.negative!==0){n.negative=0;var l=this.iadd(n);return n.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(n),this.negative=1,this._normSign();var c=this.cmp(n);if(c===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,y;c>0?(p=this,y=n):(p=n,y=this);for(var b=0,_=0;_<y.length;_++)l=(p.words[_]|0)-(y.words[_]|0)+b,b=l>>26,this.words[_]=l&67108863;for(;b!==0&&_<p.length;_++)l=(p.words[_]|0)+b,b=l>>26,this.words[_]=l&67108863;if(b===0&&_<p.length&&p!==this)for(;_<p.length;_++)this.words[_]=p.words[_];return this.length=Math.max(this.length,_),p!==this&&(this.negative=1),this.strip()},h.prototype.sub=function(n){return this.clone().isub(n)};function D($,n,l){l.negative=n.negative^$.negative;var c=$.length+n.length|0;l.length=c,c=c-1|0;var p=$.words[0]|0,y=n.words[0]|0,b=p*y,_=b&67108863,v=b/67108864|0;l.words[0]=_;for(var o=1;o<c;o++){for(var m=v>>>26,A=v&67108863,I=Math.min(o,n.length-1),U=Math.max(0,o-$.length+1);U<=I;U++){var X=o-U|0;p=$.words[X]|0,y=n.words[U]|0,b=p*y+A,m+=b/67108864|0,A=b&67108863}l.words[o]=A|0,v=m|0}return v!==0?l.words[o]=v|0:l.length--,l.strip()}var O=function(n,l,c){var p=n.words,y=l.words,b=c.words,_=0,v,o,m,A=p[0]|0,I=A&8191,U=A>>>13,X=p[1]|0,V=X&8191,T=X>>>13,q=p[2]|0,Z=q&8191,te=q>>>13,ee=p[3]|0,j=ee&8191,re=ee>>>13,qe=p[4]|0,de=qe&8191,pe=qe>>>13,je=p[5]|0,we=je&8191,le=je>>>13,Ve=p[6]|0,xe=Ve&8191,$e=Ve>>>13,ze=p[7]|0,me=ze&8191,ke=ze>>>13,Ge=p[8]|0,Me=Ge&8191,Ne=Ge>>>13,Ze=p[9]|0,Be=Ze&8191,De=Ze>>>13,rt=y[0]|0,Ae=rt&8191,Oe=rt>>>13,Je=y[1]|0,Re=Je&8191,He=Je>>>13,Qe=y[2]|0,Te=Qe&8191,Ue=Qe>>>13,tt=y[3]|0,Ee=tt&8191,Pe=tt>>>13,et=y[4]|0,Ie=et&8191,Le=et>>>13,it=y[5]|0,z=it&8191,N=it>>>13,H=y[6]|0,Q=H&8191,ne=H>>>13,ve=y[7]|0,he=ve&8191,be=ve>>>13,We=y[8]|0,ye=We&8191,Se=We>>>13,Ke=y[9]|0,Ce=Ke&8191,Fe=Ke>>>13;c.negative=n.negative^l.negative,c.length=19,v=Math.imul(I,Ae),o=Math.imul(I,Oe),o=o+Math.imul(U,Ae)|0,m=Math.imul(U,Oe);var Xe=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(Xe>>>26)|0,Xe&=67108863,v=Math.imul(V,Ae),o=Math.imul(V,Oe),o=o+Math.imul(T,Ae)|0,m=Math.imul(T,Oe),v=v+Math.imul(I,Re)|0,o=o+Math.imul(I,He)|0,o=o+Math.imul(U,Re)|0,m=m+Math.imul(U,He)|0;var Ye=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,v=Math.imul(Z,Ae),o=Math.imul(Z,Oe),o=o+Math.imul(te,Ae)|0,m=Math.imul(te,Oe),v=v+Math.imul(V,Re)|0,o=o+Math.imul(V,He)|0,o=o+Math.imul(T,Re)|0,m=m+Math.imul(T,He)|0,v=v+Math.imul(I,Te)|0,o=o+Math.imul(I,Ue)|0,o=o+Math.imul(U,Te)|0,m=m+Math.imul(U,Ue)|0;var nt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(nt>>>26)|0,nt&=67108863,v=Math.imul(j,Ae),o=Math.imul(j,Oe),o=o+Math.imul(re,Ae)|0,m=Math.imul(re,Oe),v=v+Math.imul(Z,Re)|0,o=o+Math.imul(Z,He)|0,o=o+Math.imul(te,Re)|0,m=m+Math.imul(te,He)|0,v=v+Math.imul(V,Te)|0,o=o+Math.imul(V,Ue)|0,o=o+Math.imul(T,Te)|0,m=m+Math.imul(T,Ue)|0,v=v+Math.imul(I,Ee)|0,o=o+Math.imul(I,Pe)|0,o=o+Math.imul(U,Ee)|0,m=m+Math.imul(U,Pe)|0;var at=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(at>>>26)|0,at&=67108863,v=Math.imul(de,Ae),o=Math.imul(de,Oe),o=o+Math.imul(pe,Ae)|0,m=Math.imul(pe,Oe),v=v+Math.imul(j,Re)|0,o=o+Math.imul(j,He)|0,o=o+Math.imul(re,Re)|0,m=m+Math.imul(re,He)|0,v=v+Math.imul(Z,Te)|0,o=o+Math.imul(Z,Ue)|0,o=o+Math.imul(te,Te)|0,m=m+Math.imul(te,Ue)|0,v=v+Math.imul(V,Ee)|0,o=o+Math.imul(V,Pe)|0,o=o+Math.imul(T,Ee)|0,m=m+Math.imul(T,Pe)|0,v=v+Math.imul(I,Ie)|0,o=o+Math.imul(I,Le)|0,o=o+Math.imul(U,Ie)|0,m=m+Math.imul(U,Le)|0;var ot=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(ot>>>26)|0,ot&=67108863,v=Math.imul(we,Ae),o=Math.imul(we,Oe),o=o+Math.imul(le,Ae)|0,m=Math.imul(le,Oe),v=v+Math.imul(de,Re)|0,o=o+Math.imul(de,He)|0,o=o+Math.imul(pe,Re)|0,m=m+Math.imul(pe,He)|0,v=v+Math.imul(j,Te)|0,o=o+Math.imul(j,Ue)|0,o=o+Math.imul(re,Te)|0,m=m+Math.imul(re,Ue)|0,v=v+Math.imul(Z,Ee)|0,o=o+Math.imul(Z,Pe)|0,o=o+Math.imul(te,Ee)|0,m=m+Math.imul(te,Pe)|0,v=v+Math.imul(V,Ie)|0,o=o+Math.imul(V,Le)|0,o=o+Math.imul(T,Ie)|0,m=m+Math.imul(T,Le)|0,v=v+Math.imul(I,z)|0,o=o+Math.imul(I,N)|0,o=o+Math.imul(U,z)|0,m=m+Math.imul(U,N)|0;var st=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(st>>>26)|0,st&=67108863,v=Math.imul(xe,Ae),o=Math.imul(xe,Oe),o=o+Math.imul($e,Ae)|0,m=Math.imul($e,Oe),v=v+Math.imul(we,Re)|0,o=o+Math.imul(we,He)|0,o=o+Math.imul(le,Re)|0,m=m+Math.imul(le,He)|0,v=v+Math.imul(de,Te)|0,o=o+Math.imul(de,Ue)|0,o=o+Math.imul(pe,Te)|0,m=m+Math.imul(pe,Ue)|0,v=v+Math.imul(j,Ee)|0,o=o+Math.imul(j,Pe)|0,o=o+Math.imul(re,Ee)|0,m=m+Math.imul(re,Pe)|0,v=v+Math.imul(Z,Ie)|0,o=o+Math.imul(Z,Le)|0,o=o+Math.imul(te,Ie)|0,m=m+Math.imul(te,Le)|0,v=v+Math.imul(V,z)|0,o=o+Math.imul(V,N)|0,o=o+Math.imul(T,z)|0,m=m+Math.imul(T,N)|0,v=v+Math.imul(I,Q)|0,o=o+Math.imul(I,ne)|0,o=o+Math.imul(U,Q)|0,m=m+Math.imul(U,ne)|0;var ht=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(ht>>>26)|0,ht&=67108863,v=Math.imul(me,Ae),o=Math.imul(me,Oe),o=o+Math.imul(ke,Ae)|0,m=Math.imul(ke,Oe),v=v+Math.imul(xe,Re)|0,o=o+Math.imul(xe,He)|0,o=o+Math.imul($e,Re)|0,m=m+Math.imul($e,He)|0,v=v+Math.imul(we,Te)|0,o=o+Math.imul(we,Ue)|0,o=o+Math.imul(le,Te)|0,m=m+Math.imul(le,Ue)|0,v=v+Math.imul(de,Ee)|0,o=o+Math.imul(de,Pe)|0,o=o+Math.imul(pe,Ee)|0,m=m+Math.imul(pe,Pe)|0,v=v+Math.imul(j,Ie)|0,o=o+Math.imul(j,Le)|0,o=o+Math.imul(re,Ie)|0,m=m+Math.imul(re,Le)|0,v=v+Math.imul(Z,z)|0,o=o+Math.imul(Z,N)|0,o=o+Math.imul(te,z)|0,m=m+Math.imul(te,N)|0,v=v+Math.imul(V,Q)|0,o=o+Math.imul(V,ne)|0,o=o+Math.imul(T,Q)|0,m=m+Math.imul(T,ne)|0,v=v+Math.imul(I,he)|0,o=o+Math.imul(I,be)|0,o=o+Math.imul(U,he)|0,m=m+Math.imul(U,be)|0;var lt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(lt>>>26)|0,lt&=67108863,v=Math.imul(Me,Ae),o=Math.imul(Me,Oe),o=o+Math.imul(Ne,Ae)|0,m=Math.imul(Ne,Oe),v=v+Math.imul(me,Re)|0,o=o+Math.imul(me,He)|0,o=o+Math.imul(ke,Re)|0,m=m+Math.imul(ke,He)|0,v=v+Math.imul(xe,Te)|0,o=o+Math.imul(xe,Ue)|0,o=o+Math.imul($e,Te)|0,m=m+Math.imul($e,Ue)|0,v=v+Math.imul(we,Ee)|0,o=o+Math.imul(we,Pe)|0,o=o+Math.imul(le,Ee)|0,m=m+Math.imul(le,Pe)|0,v=v+Math.imul(de,Ie)|0,o=o+Math.imul(de,Le)|0,o=o+Math.imul(pe,Ie)|0,m=m+Math.imul(pe,Le)|0,v=v+Math.imul(j,z)|0,o=o+Math.imul(j,N)|0,o=o+Math.imul(re,z)|0,m=m+Math.imul(re,N)|0,v=v+Math.imul(Z,Q)|0,o=o+Math.imul(Z,ne)|0,o=o+Math.imul(te,Q)|0,m=m+Math.imul(te,ne)|0,v=v+Math.imul(V,he)|0,o=o+Math.imul(V,be)|0,o=o+Math.imul(T,he)|0,m=m+Math.imul(T,be)|0,v=v+Math.imul(I,ye)|0,o=o+Math.imul(I,Se)|0,o=o+Math.imul(U,ye)|0,m=m+Math.imul(U,Se)|0;var ct=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(ct>>>26)|0,ct&=67108863,v=Math.imul(Be,Ae),o=Math.imul(Be,Oe),o=o+Math.imul(De,Ae)|0,m=Math.imul(De,Oe),v=v+Math.imul(Me,Re)|0,o=o+Math.imul(Me,He)|0,o=o+Math.imul(Ne,Re)|0,m=m+Math.imul(Ne,He)|0,v=v+Math.imul(me,Te)|0,o=o+Math.imul(me,Ue)|0,o=o+Math.imul(ke,Te)|0,m=m+Math.imul(ke,Ue)|0,v=v+Math.imul(xe,Ee)|0,o=o+Math.imul(xe,Pe)|0,o=o+Math.imul($e,Ee)|0,m=m+Math.imul($e,Pe)|0,v=v+Math.imul(we,Ie)|0,o=o+Math.imul(we,Le)|0,o=o+Math.imul(le,Ie)|0,m=m+Math.imul(le,Le)|0,v=v+Math.imul(de,z)|0,o=o+Math.imul(de,N)|0,o=o+Math.imul(pe,z)|0,m=m+Math.imul(pe,N)|0,v=v+Math.imul(j,Q)|0,o=o+Math.imul(j,ne)|0,o=o+Math.imul(re,Q)|0,m=m+Math.imul(re,ne)|0,v=v+Math.imul(Z,he)|0,o=o+Math.imul(Z,be)|0,o=o+Math.imul(te,he)|0,m=m+Math.imul(te,be)|0,v=v+Math.imul(V,ye)|0,o=o+Math.imul(V,Se)|0,o=o+Math.imul(T,ye)|0,m=m+Math.imul(T,Se)|0,v=v+Math.imul(I,Ce)|0,o=o+Math.imul(I,Fe)|0,o=o+Math.imul(U,Ce)|0,m=m+Math.imul(U,Fe)|0;var dt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(dt>>>26)|0,dt&=67108863,v=Math.imul(Be,Re),o=Math.imul(Be,He),o=o+Math.imul(De,Re)|0,m=Math.imul(De,He),v=v+Math.imul(Me,Te)|0,o=o+Math.imul(Me,Ue)|0,o=o+Math.imul(Ne,Te)|0,m=m+Math.imul(Ne,Ue)|0,v=v+Math.imul(me,Ee)|0,o=o+Math.imul(me,Pe)|0,o=o+Math.imul(ke,Ee)|0,m=m+Math.imul(ke,Pe)|0,v=v+Math.imul(xe,Ie)|0,o=o+Math.imul(xe,Le)|0,o=o+Math.imul($e,Ie)|0,m=m+Math.imul($e,Le)|0,v=v+Math.imul(we,z)|0,o=o+Math.imul(we,N)|0,o=o+Math.imul(le,z)|0,m=m+Math.imul(le,N)|0,v=v+Math.imul(de,Q)|0,o=o+Math.imul(de,ne)|0,o=o+Math.imul(pe,Q)|0,m=m+Math.imul(pe,ne)|0,v=v+Math.imul(j,he)|0,o=o+Math.imul(j,be)|0,o=o+Math.imul(re,he)|0,m=m+Math.imul(re,be)|0,v=v+Math.imul(Z,ye)|0,o=o+Math.imul(Z,Se)|0,o=o+Math.imul(te,ye)|0,m=m+Math.imul(te,Se)|0,v=v+Math.imul(V,Ce)|0,o=o+Math.imul(V,Fe)|0,o=o+Math.imul(T,Ce)|0,m=m+Math.imul(T,Fe)|0;var pt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(pt>>>26)|0,pt&=67108863,v=Math.imul(Be,Te),o=Math.imul(Be,Ue),o=o+Math.imul(De,Te)|0,m=Math.imul(De,Ue),v=v+Math.imul(Me,Ee)|0,o=o+Math.imul(Me,Pe)|0,o=o+Math.imul(Ne,Ee)|0,m=m+Math.imul(Ne,Pe)|0,v=v+Math.imul(me,Ie)|0,o=o+Math.imul(me,Le)|0,o=o+Math.imul(ke,Ie)|0,m=m+Math.imul(ke,Le)|0,v=v+Math.imul(xe,z)|0,o=o+Math.imul(xe,N)|0,o=o+Math.imul($e,z)|0,m=m+Math.imul($e,N)|0,v=v+Math.imul(we,Q)|0,o=o+Math.imul(we,ne)|0,o=o+Math.imul(le,Q)|0,m=m+Math.imul(le,ne)|0,v=v+Math.imul(de,he)|0,o=o+Math.imul(de,be)|0,o=o+Math.imul(pe,he)|0,m=m+Math.imul(pe,be)|0,v=v+Math.imul(j,ye)|0,o=o+Math.imul(j,Se)|0,o=o+Math.imul(re,ye)|0,m=m+Math.imul(re,Se)|0,v=v+Math.imul(Z,Ce)|0,o=o+Math.imul(Z,Fe)|0,o=o+Math.imul(te,Ce)|0,m=m+Math.imul(te,Fe)|0;var vt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(vt>>>26)|0,vt&=67108863,v=Math.imul(Be,Ee),o=Math.imul(Be,Pe),o=o+Math.imul(De,Ee)|0,m=Math.imul(De,Pe),v=v+Math.imul(Me,Ie)|0,o=o+Math.imul(Me,Le)|0,o=o+Math.imul(Ne,Ie)|0,m=m+Math.imul(Ne,Le)|0,v=v+Math.imul(me,z)|0,o=o+Math.imul(me,N)|0,o=o+Math.imul(ke,z)|0,m=m+Math.imul(ke,N)|0,v=v+Math.imul(xe,Q)|0,o=o+Math.imul(xe,ne)|0,o=o+Math.imul($e,Q)|0,m=m+Math.imul($e,ne)|0,v=v+Math.imul(we,he)|0,o=o+Math.imul(we,be)|0,o=o+Math.imul(le,he)|0,m=m+Math.imul(le,be)|0,v=v+Math.imul(de,ye)|0,o=o+Math.imul(de,Se)|0,o=o+Math.imul(pe,ye)|0,m=m+Math.imul(pe,Se)|0,v=v+Math.imul(j,Ce)|0,o=o+Math.imul(j,Fe)|0,o=o+Math.imul(re,Ce)|0,m=m+Math.imul(re,Fe)|0;var yt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(yt>>>26)|0,yt&=67108863,v=Math.imul(Be,Ie),o=Math.imul(Be,Le),o=o+Math.imul(De,Ie)|0,m=Math.imul(De,Le),v=v+Math.imul(Me,z)|0,o=o+Math.imul(Me,N)|0,o=o+Math.imul(Ne,z)|0,m=m+Math.imul(Ne,N)|0,v=v+Math.imul(me,Q)|0,o=o+Math.imul(me,ne)|0,o=o+Math.imul(ke,Q)|0,m=m+Math.imul(ke,ne)|0,v=v+Math.imul(xe,he)|0,o=o+Math.imul(xe,be)|0,o=o+Math.imul($e,he)|0,m=m+Math.imul($e,be)|0,v=v+Math.imul(we,ye)|0,o=o+Math.imul(we,Se)|0,o=o+Math.imul(le,ye)|0,m=m+Math.imul(le,Se)|0,v=v+Math.imul(de,Ce)|0,o=o+Math.imul(de,Fe)|0,o=o+Math.imul(pe,Ce)|0,m=m+Math.imul(pe,Fe)|0;var mt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(mt>>>26)|0,mt&=67108863,v=Math.imul(Be,z),o=Math.imul(Be,N),o=o+Math.imul(De,z)|0,m=Math.imul(De,N),v=v+Math.imul(Me,Q)|0,o=o+Math.imul(Me,ne)|0,o=o+Math.imul(Ne,Q)|0,m=m+Math.imul(Ne,ne)|0,v=v+Math.imul(me,he)|0,o=o+Math.imul(me,be)|0,o=o+Math.imul(ke,he)|0,m=m+Math.imul(ke,be)|0,v=v+Math.imul(xe,ye)|0,o=o+Math.imul(xe,Se)|0,o=o+Math.imul($e,ye)|0,m=m+Math.imul($e,Se)|0,v=v+Math.imul(we,Ce)|0,o=o+Math.imul(we,Fe)|0,o=o+Math.imul(le,Ce)|0,m=m+Math.imul(le,Fe)|0;var gt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(gt>>>26)|0,gt&=67108863,v=Math.imul(Be,Q),o=Math.imul(Be,ne),o=o+Math.imul(De,Q)|0,m=Math.imul(De,ne),v=v+Math.imul(Me,he)|0,o=o+Math.imul(Me,be)|0,o=o+Math.imul(Ne,he)|0,m=m+Math.imul(Ne,be)|0,v=v+Math.imul(me,ye)|0,o=o+Math.imul(me,Se)|0,o=o+Math.imul(ke,ye)|0,m=m+Math.imul(ke,Se)|0,v=v+Math.imul(xe,Ce)|0,o=o+Math.imul(xe,Fe)|0,o=o+Math.imul($e,Ce)|0,m=m+Math.imul($e,Fe)|0;var bt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(bt>>>26)|0,bt&=67108863,v=Math.imul(Be,he),o=Math.imul(Be,be),o=o+Math.imul(De,he)|0,m=Math.imul(De,be),v=v+Math.imul(Me,ye)|0,o=o+Math.imul(Me,Se)|0,o=o+Math.imul(Ne,ye)|0,m=m+Math.imul(Ne,Se)|0,v=v+Math.imul(me,Ce)|0,o=o+Math.imul(me,Fe)|0,o=o+Math.imul(ke,Ce)|0,m=m+Math.imul(ke,Fe)|0;var wt=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(wt>>>26)|0,wt&=67108863,v=Math.imul(Be,ye),o=Math.imul(Be,Se),o=o+Math.imul(De,ye)|0,m=Math.imul(De,Se),v=v+Math.imul(Me,Ce)|0,o=o+Math.imul(Me,Fe)|0,o=o+Math.imul(Ne,Ce)|0,m=m+Math.imul(Ne,Fe)|0;var _t=(_+v|0)+((o&8191)<<13)|0;_=(m+(o>>>13)|0)+(_t>>>26)|0,_t&=67108863,v=Math.imul(Be,Ce),o=Math.imul(Be,Fe),o=o+Math.imul(De,Ce)|0,m=Math.imul(De,Fe);var xt=(_+v|0)+((o&8191)<<13)|0;return _=(m+(o>>>13)|0)+(xt>>>26)|0,xt&=67108863,b[0]=Xe,b[1]=Ye,b[2]=nt,b[3]=at,b[4]=ot,b[5]=st,b[6]=ht,b[7]=lt,b[8]=ct,b[9]=dt,b[10]=pt,b[11]=vt,b[12]=yt,b[13]=mt,b[14]=gt,b[15]=bt,b[16]=wt,b[17]=_t,b[18]=xt,_!==0&&(b[19]=_,c.length++),c};Math.imul||(O=D);function F($,n,l){l.negative=n.negative^$.negative,l.length=$.length+n.length;for(var c=0,p=0,y=0;y<l.length-1;y++){var b=p;p=0;for(var _=c&67108863,v=Math.min(y,n.length-1),o=Math.max(0,y-$.length+1);o<=v;o++){var m=y-o,A=$.words[m]|0,I=n.words[o]|0,U=A*I,X=U&67108863;b=b+(U/67108864|0)|0,X=X+_|0,_=X&67108863,b=b+(X>>>26)|0,p+=b>>>26,b&=67108863}l.words[y]=_,c=b,b=p}return c!==0?l.words[y]=c:l.length--,l.strip()}function P($,n,l){var c=new L;return c.mulp($,n,l)}h.prototype.mulTo=function(n,l){var c,p=this.length+n.length;return this.length===10&&n.length===10?c=O(this,n,l):p<63?c=D(this,n,l):p<1024?c=F(this,n,l):c=P(this,n,l),c};function L($,n){this.x=$,this.y=n}L.prototype.makeRBT=function(n){for(var l=new Array(n),c=h.prototype._countBits(n)-1,p=0;p<n;p++)l[p]=this.revBin(p,c,n);return l},L.prototype.revBin=function(n,l,c){if(n===0||n===c-1)return n;for(var p=0,y=0;y<l;y++)p|=(n&1)<<l-y-1,n>>=1;return p},L.prototype.permute=function(n,l,c,p,y,b){for(var _=0;_<b;_++)p[_]=l[n[_]],y[_]=c[n[_]]},L.prototype.transform=function(n,l,c,p,y,b){this.permute(b,n,l,c,p,y);for(var _=1;_<y;_<<=1)for(var v=_<<1,o=Math.cos(2*Math.PI/v),m=Math.sin(2*Math.PI/v),A=0;A<y;A+=v)for(var I=o,U=m,X=0;X<_;X++){var V=c[A+X],T=p[A+X],q=c[A+X+_],Z=p[A+X+_],te=I*q-U*Z;Z=I*Z+U*q,q=te,c[A+X]=V+q,p[A+X]=T+Z,c[A+X+_]=V-q,p[A+X+_]=T-Z,X!==v&&(te=o*I-m*U,U=o*U+m*I,I=te)}},L.prototype.guessLen13b=function(n,l){var c=Math.max(l,n)|1,p=c&1,y=0;for(c=c/2|0;c;c=c>>>1)y++;return 1<<y+1+p},L.prototype.conjugate=function(n,l,c){if(!(c<=1))for(var p=0;p<c/2;p++){var y=n[p];n[p]=n[c-p-1],n[c-p-1]=y,y=l[p],l[p]=-l[c-p-1],l[c-p-1]=-y}},L.prototype.normalize13b=function(n,l){for(var c=0,p=0;p<l/2;p++){var y=Math.round(n[2*p+1]/l)*8192+Math.round(n[2*p]/l)+c;n[p]=y&67108863,y<67108864?c=0:c=y/67108864|0}return n},L.prototype.convert13b=function(n,l,c,p){for(var y=0,b=0;b<l;b++)y=y+(n[b]|0),c[2*b]=y&8191,y=y>>>13,c[2*b+1]=y&8191,y=y>>>13;for(b=2*l;b<p;++b)c[b]=0;u(y===0),u((y&-8192)===0)},L.prototype.stub=function(n){for(var l=new Array(n),c=0;c<n;c++)l[c]=0;return l},L.prototype.mulp=function(n,l,c){var p=2*this.guessLen13b(n.length,l.length),y=this.makeRBT(p),b=this.stub(p),_=new Array(p),v=new Array(p),o=new Array(p),m=new Array(p),A=new Array(p),I=new Array(p),U=c.words;U.length=p,this.convert13b(n.words,n.length,_,p),this.convert13b(l.words,l.length,m,p),this.transform(_,b,v,o,p,y),this.transform(m,b,A,I,p,y);for(var X=0;X<p;X++){var V=v[X]*A[X]-o[X]*I[X];o[X]=v[X]*I[X]+o[X]*A[X],v[X]=V}return this.conjugate(v,o,p),this.transform(v,o,U,b,p,y),this.conjugate(U,b,p),this.normalize13b(U,p),c.negative=n.negative^l.negative,c.length=n.length+l.length,c.strip()},h.prototype.mul=function(n){var l=new h(null);return l.words=new Array(this.length+n.length),this.mulTo(n,l)},h.prototype.mulf=function(n){var l=new h(null);return l.words=new Array(this.length+n.length),P(this,n,l)},h.prototype.imul=function(n){return this.clone().mulTo(n,this)},h.prototype.imuln=function(n){u(typeof n=="number"),u(n<67108864);for(var l=0,c=0;c<this.length;c++){var p=(this.words[c]|0)*n,y=(p&67108863)+(l&67108863);l>>=26,l+=p/67108864|0,l+=y>>>26,this.words[c]=y&67108863}return l!==0&&(this.words[c]=l,this.length++),this.length=n===0?1:this.length,this},h.prototype.muln=function(n){return this.clone().imuln(n)},h.prototype.sqr=function(){return this.mul(this)},h.prototype.isqr=function(){return this.imul(this.clone())},h.prototype.pow=function(n){var l=C(n);if(l.length===0)return new h(1);for(var c=this,p=0;p<l.length&&l[p]===0;p++,c=c.sqr());if(++p<l.length)for(var y=c.sqr();p<l.length;p++,y=y.sqr())l[p]!==0&&(c=c.mul(y));return c},h.prototype.iushln=function(n){u(typeof n=="number"&&n>=0);var l=n%26,c=(n-l)/26,p=67108863>>>26-l<<26-l,y;if(l!==0){var b=0;for(y=0;y<this.length;y++){var _=this.words[y]&p,v=(this.words[y]|0)-_<<l;this.words[y]=v|b,b=_>>>26-l}b&&(this.words[y]=b,this.length++)}if(c!==0){for(y=this.length-1;y>=0;y--)this.words[y+c]=this.words[y];for(y=0;y<c;y++)this.words[y]=0;this.length+=c}return this.strip()},h.prototype.ishln=function(n){return u(this.negative===0),this.iushln(n)},h.prototype.iushrn=function(n,l,c){u(typeof n=="number"&&n>=0);var p;l?p=(l-l%26)/26:p=0;var y=n%26,b=Math.min((n-y)/26,this.length),_=67108863^67108863>>>y<<y,v=c;if(p-=b,p=Math.max(0,p),v){for(var o=0;o<b;o++)v.words[o]=this.words[o];v.length=b}if(b!==0)if(this.length>b)for(this.length-=b,o=0;o<this.length;o++)this.words[o]=this.words[o+b];else this.words[0]=0,this.length=1;var m=0;for(o=this.length-1;o>=0&&(m!==0||o>=p);o--){var A=this.words[o]|0;this.words[o]=m<<26-y|A>>>y,m=A&_}return v&&m!==0&&(v.words[v.length++]=m),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},h.prototype.ishrn=function(n,l,c){return u(this.negative===0),this.iushrn(n,l,c)},h.prototype.shln=function(n){return this.clone().ishln(n)},h.prototype.ushln=function(n){return this.clone().iushln(n)},h.prototype.shrn=function(n){return this.clone().ishrn(n)},h.prototype.ushrn=function(n){return this.clone().iushrn(n)},h.prototype.testn=function(n){u(typeof n=="number"&&n>=0);var l=n%26,c=(n-l)/26,p=1<<l;if(this.length<=c)return!1;var y=this.words[c];return!!(y&p)},h.prototype.imaskn=function(n){u(typeof n=="number"&&n>=0);var l=n%26,c=(n-l)/26;if(u(this.negative===0,"imaskn works only with positive numbers"),this.length<=c)return this;if(l!==0&&c++,this.length=Math.min(c,this.length),l!==0){var p=67108863^67108863>>>l<<l;this.words[this.length-1]&=p}return this.strip()},h.prototype.maskn=function(n){return this.clone().imaskn(n)},h.prototype.iaddn=function(n){return u(typeof n=="number"),u(n<67108864),n<0?this.isubn(-n):this.negative!==0?this.length===1&&(this.words[0]|0)<n?(this.words[0]=n-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(n),this.negative=1,this):this._iaddn(n)},h.prototype._iaddn=function(n){this.words[0]+=n;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},h.prototype.isubn=function(n){if(u(typeof n=="number"),u(n<67108864),n<0)return this.iaddn(-n);if(this.negative!==0)return this.negative=0,this.iaddn(n),this.negative=1,this;if(this.words[0]-=n,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this.strip()},h.prototype.addn=function(n){return this.clone().iaddn(n)},h.prototype.subn=function(n){return this.clone().isubn(n)},h.prototype.iabs=function(){return this.negative=0,this},h.prototype.abs=function(){return this.clone().iabs()},h.prototype._ishlnsubmul=function(n,l,c){var p=n.length+c,y;this._expand(p);var b,_=0;for(y=0;y<n.length;y++){b=(this.words[y+c]|0)+_;var v=(n.words[y]|0)*l;b-=v&67108863,_=(b>>26)-(v/67108864|0),this.words[y+c]=b&67108863}for(;y<this.length-c;y++)b=(this.words[y+c]|0)+_,_=b>>26,this.words[y+c]=b&67108863;if(_===0)return this.strip();for(u(_===-1),_=0,y=0;y<this.length;y++)b=-(this.words[y]|0)+_,_=b>>26,this.words[y]=b&67108863;return this.negative=1,this.strip()},h.prototype._wordDiv=function(n,l){var c=this.length-n.length,p=this.clone(),y=n,b=y.words[y.length-1]|0,_=this._countBits(b);c=26-_,c!==0&&(y=y.ushln(c),p.iushln(c),b=y.words[y.length-1]|0);var v=p.length-y.length,o;if(l!=="mod"){o=new h(null),o.length=v+1,o.words=new Array(o.length);for(var m=0;m<o.length;m++)o.words[m]=0}var A=p.clone()._ishlnsubmul(y,1,v);A.negative===0&&(p=A,o&&(o.words[v]=1));for(var I=v-1;I>=0;I--){var U=(p.words[y.length+I]|0)*67108864+(p.words[y.length+I-1]|0);for(U=Math.min(U/b|0,67108863),p._ishlnsubmul(y,U,I);p.negative!==0;)U--,p.negative=0,p._ishlnsubmul(y,1,I),p.isZero()||(p.negative^=1);o&&(o.words[I]=U)}return o&&o.strip(),p.strip(),l!=="div"&&c!==0&&p.iushrn(c),{div:o||null,mod:p}},h.prototype.divmod=function(n,l,c){if(u(!n.isZero()),this.isZero())return{div:new h(0),mod:new h(0)};var p,y,b;return this.negative!==0&&n.negative===0?(b=this.neg().divmod(n,l),l!=="mod"&&(p=b.div.neg()),l!=="div"&&(y=b.mod.neg(),c&&y.negative!==0&&y.iadd(n)),{div:p,mod:y}):this.negative===0&&n.negative!==0?(b=this.divmod(n.neg(),l),l!=="mod"&&(p=b.div.neg()),{div:p,mod:b.mod}):this.negative&n.negative?(b=this.neg().divmod(n.neg(),l),l!=="div"&&(y=b.mod.neg(),c&&y.negative!==0&&y.isub(n)),{div:b.div,mod:y}):n.length>this.length||this.cmp(n)<0?{div:new h(0),mod:this}:n.length===1?l==="div"?{div:this.divn(n.words[0]),mod:null}:l==="mod"?{div:null,mod:new h(this.modn(n.words[0]))}:{div:this.divn(n.words[0]),mod:new h(this.modn(n.words[0]))}:this._wordDiv(n,l)},h.prototype.div=function(n){return this.divmod(n,"div",!1).div},h.prototype.mod=function(n){return this.divmod(n,"mod",!1).mod},h.prototype.umod=function(n){return this.divmod(n,"mod",!0).mod},h.prototype.divRound=function(n){var l=this.divmod(n);if(l.mod.isZero())return l.div;var c=l.div.negative!==0?l.mod.isub(n):l.mod,p=n.ushrn(1),y=n.andln(1),b=c.cmp(p);return b<0||y===1&&b===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},h.prototype.modn=function(n){u(n<=67108863);for(var l=(1<<26)%n,c=0,p=this.length-1;p>=0;p--)c=(l*c+(this.words[p]|0))%n;return c},h.prototype.idivn=function(n){u(n<=67108863);for(var l=0,c=this.length-1;c>=0;c--){var p=(this.words[c]|0)+l*67108864;this.words[c]=p/n|0,l=p%n}return this.strip()},h.prototype.divn=function(n){return this.clone().idivn(n)},h.prototype.egcd=function(n){u(n.negative===0),u(!n.isZero());var l=this,c=n.clone();l.negative!==0?l=l.umod(n):l=l.clone();for(var p=new h(1),y=new h(0),b=new h(0),_=new h(1),v=0;l.isEven()&&c.isEven();)l.iushrn(1),c.iushrn(1),++v;for(var o=c.clone(),m=l.clone();!l.isZero();){for(var A=0,I=1;!(l.words[0]&I)&&A<26;++A,I<<=1);if(A>0)for(l.iushrn(A);A-- >0;)(p.isOdd()||y.isOdd())&&(p.iadd(o),y.isub(m)),p.iushrn(1),y.iushrn(1);for(var U=0,X=1;!(c.words[0]&X)&&U<26;++U,X<<=1);if(U>0)for(c.iushrn(U);U-- >0;)(b.isOdd()||_.isOdd())&&(b.iadd(o),_.isub(m)),b.iushrn(1),_.iushrn(1);l.cmp(c)>=0?(l.isub(c),p.isub(b),y.isub(_)):(c.isub(l),b.isub(p),_.isub(y))}return{a:b,b:_,gcd:c.iushln(v)}},h.prototype._invmp=function(n){u(n.negative===0),u(!n.isZero());var l=this,c=n.clone();l.negative!==0?l=l.umod(n):l=l.clone();for(var p=new h(1),y=new h(0),b=c.clone();l.cmpn(1)>0&&c.cmpn(1)>0;){for(var _=0,v=1;!(l.words[0]&v)&&_<26;++_,v<<=1);if(_>0)for(l.iushrn(_);_-- >0;)p.isOdd()&&p.iadd(b),p.iushrn(1);for(var o=0,m=1;!(c.words[0]&m)&&o<26;++o,m<<=1);if(o>0)for(c.iushrn(o);o-- >0;)y.isOdd()&&y.iadd(b),y.iushrn(1);l.cmp(c)>=0?(l.isub(c),p.isub(y)):(c.isub(l),y.isub(p))}var A;return l.cmpn(1)===0?A=p:A=y,A.cmpn(0)<0&&A.iadd(n),A},h.prototype.gcd=function(n){if(this.isZero())return n.abs();if(n.isZero())return this.abs();var l=this.clone(),c=n.clone();l.negative=0,c.negative=0;for(var p=0;l.isEven()&&c.isEven();p++)l.iushrn(1),c.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;c.isEven();)c.iushrn(1);var y=l.cmp(c);if(y<0){var b=l;l=c,c=b}else if(y===0||c.cmpn(1)===0)break;l.isub(c)}while(!0);return c.iushln(p)},h.prototype.invm=function(n){return this.egcd(n).a.umod(n)},h.prototype.isEven=function(){return(this.words[0]&1)===0},h.prototype.isOdd=function(){return(this.words[0]&1)===1},h.prototype.andln=function(n){return this.words[0]&n},h.prototype.bincn=function(n){u(typeof n=="number");var l=n%26,c=(n-l)/26,p=1<<l;if(this.length<=c)return this._expand(c+1),this.words[c]|=p,this;for(var y=p,b=c;y!==0&&b<this.length;b++){var _=this.words[b]|0;_+=y,y=_>>>26,_&=67108863,this.words[b]=_}return y!==0&&(this.words[b]=y,this.length++),this},h.prototype.isZero=function(){return this.length===1&&this.words[0]===0},h.prototype.cmpn=function(n){var l=n<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this.strip();var c;if(this.length>1)c=1;else{l&&(n=-n),u(n<=67108863,"Number is too big");var p=this.words[0]|0;c=p===n?0:p<n?-1:1}return this.negative!==0?-c|0:c},h.prototype.cmp=function(n){if(this.negative!==0&&n.negative===0)return-1;if(this.negative===0&&n.negative!==0)return 1;var l=this.ucmp(n);return this.negative!==0?-l|0:l},h.prototype.ucmp=function(n){if(this.length>n.length)return 1;if(this.length<n.length)return-1;for(var l=0,c=this.length-1;c>=0;c--){var p=this.words[c]|0,y=n.words[c]|0;if(p!==y){p<y?l=-1:p>y&&(l=1);break}}return l},h.prototype.gtn=function(n){return this.cmpn(n)===1},h.prototype.gt=function(n){return this.cmp(n)===1},h.prototype.gten=function(n){return this.cmpn(n)>=0},h.prototype.gte=function(n){return this.cmp(n)>=0},h.prototype.ltn=function(n){return this.cmpn(n)===-1},h.prototype.lt=function(n){return this.cmp(n)===-1},h.prototype.lten=function(n){return this.cmpn(n)<=0},h.prototype.lte=function(n){return this.cmp(n)<=0},h.prototype.eqn=function(n){return this.cmpn(n)===0},h.prototype.eq=function(n){return this.cmp(n)===0},h.red=function(n){return new ie(n)},h.prototype.toRed=function(n){return u(!this.red,"Already a number in reduction context"),u(this.negative===0,"red works only with positives"),n.convertTo(this)._forceRed(n)},h.prototype.fromRed=function(){return u(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},h.prototype._forceRed=function(n){return this.red=n,this},h.prototype.forceRed=function(n){return u(!this.red,"Already a number in reduction context"),this._forceRed(n)},h.prototype.redAdd=function(n){return u(this.red,"redAdd works only with red numbers"),this.red.add(this,n)},h.prototype.redIAdd=function(n){return u(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,n)},h.prototype.redSub=function(n){return u(this.red,"redSub works only with red numbers"),this.red.sub(this,n)},h.prototype.redISub=function(n){return u(this.red,"redISub works only with red numbers"),this.red.isub(this,n)},h.prototype.redShl=function(n){return u(this.red,"redShl works only with red numbers"),this.red.shl(this,n)},h.prototype.redMul=function(n){return u(this.red,"redMul works only with red numbers"),this.red._verify2(this,n),this.red.mul(this,n)},h.prototype.redIMul=function(n){return u(this.red,"redMul works only with red numbers"),this.red._verify2(this,n),this.red.imul(this,n)},h.prototype.redSqr=function(){return u(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},h.prototype.redISqr=function(){return u(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},h.prototype.redSqrt=function(){return u(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},h.prototype.redInvm=function(){return u(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},h.prototype.redNeg=function(){return u(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},h.prototype.redPow=function(n){return u(this.red&&!n.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,n)};var J={k256:null,p224:null,p192:null,p25519:null};function Y($,n){this.name=$,this.p=new h(n,16),this.n=this.p.bitLength(),this.k=new h(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}Y.prototype._tmp=function(){var n=new h(null);return n.words=new Array(Math.ceil(this.n/13)),n},Y.prototype.ireduce=function(n){var l=n,c;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),c=l.bitLength();while(c>this.n);var p=c<this.n?-1:l.ucmp(this.p);return p===0?(l.words[0]=0,l.length=1):p>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},Y.prototype.split=function(n,l){n.iushrn(this.n,0,l)},Y.prototype.imulK=function(n){return n.imul(this.k)};function ae(){Y.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}d(ae,Y),ae.prototype.split=function(n,l){for(var c=4194303,p=Math.min(n.length,9),y=0;y<p;y++)l.words[y]=n.words[y];if(l.length=p,n.length<=9){n.words[0]=0,n.length=1;return}var b=n.words[9];for(l.words[l.length++]=b&c,y=10;y<n.length;y++){var _=n.words[y]|0;n.words[y-10]=(_&c)<<4|b>>>22,b=_}b>>>=22,n.words[y-10]=b,b===0&&n.length>10?n.length-=10:n.length-=9},ae.prototype.imulK=function(n){n.words[n.length]=0,n.words[n.length+1]=0,n.length+=2;for(var l=0,c=0;c<n.length;c++){var p=n.words[c]|0;l+=p*977,n.words[c]=l&67108863,l=p*64+(l/67108864|0)}return n.words[n.length-1]===0&&(n.length--,n.words[n.length-1]===0&&n.length--),n};function oe(){Y.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}d(oe,Y);function ue(){Y.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}d(ue,Y);function se(){Y.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}d(se,Y),se.prototype.imulK=function(n){for(var l=0,c=0;c<n.length;c++){var p=(n.words[c]|0)*19+l,y=p&67108863;p>>>=26,n.words[c]=y,l=p}return l!==0&&(n.words[n.length++]=l),n},h._prime=function(n){if(J[n])return J[n];var l;if(n==="k256")l=new ae;else if(n==="p224")l=new oe;else if(n==="p192")l=new ue;else if(n==="p25519")l=new se;else throw new Error("Unknown prime "+n);return J[n]=l,l};function ie($){if(typeof $=="string"){var n=h._prime($);this.m=n.p,this.prime=n}else u($.gtn(1),"modulus must be greater than 1"),this.m=$,this.prime=null}ie.prototype._verify1=function(n){u(n.negative===0,"red works only with positives"),u(n.red,"red works only with red numbers")},ie.prototype._verify2=function(n,l){u((n.negative|l.negative)===0,"red works only with positives"),u(n.red&&n.red===l.red,"red works only with red numbers")},ie.prototype.imod=function(n){return this.prime?this.prime.ireduce(n)._forceRed(this):n.umod(this.m)._forceRed(this)},ie.prototype.neg=function(n){return n.isZero()?n.clone():this.m.sub(n)._forceRed(this)},ie.prototype.add=function(n,l){this._verify2(n,l);var c=n.add(l);return c.cmp(this.m)>=0&&c.isub(this.m),c._forceRed(this)},ie.prototype.iadd=function(n,l){this._verify2(n,l);var c=n.iadd(l);return c.cmp(this.m)>=0&&c.isub(this.m),c},ie.prototype.sub=function(n,l){this._verify2(n,l);var c=n.sub(l);return c.cmpn(0)<0&&c.iadd(this.m),c._forceRed(this)},ie.prototype.isub=function(n,l){this._verify2(n,l);var c=n.isub(l);return c.cmpn(0)<0&&c.iadd(this.m),c},ie.prototype.shl=function(n,l){return this._verify1(n),this.imod(n.ushln(l))},ie.prototype.imul=function(n,l){return this._verify2(n,l),this.imod(n.imul(l))},ie.prototype.mul=function(n,l){return this._verify2(n,l),this.imod(n.mul(l))},ie.prototype.isqr=function(n){return this.imul(n,n.clone())},ie.prototype.sqr=function(n){return this.mul(n,n)},ie.prototype.sqrt=function(n){if(n.isZero())return n.clone();var l=this.m.andln(3);if(u(l%2===1),l===3){var c=this.m.add(new h(1)).iushrn(2);return this.pow(n,c)}for(var p=this.m.subn(1),y=0;!p.isZero()&&p.andln(1)===0;)y++,p.iushrn(1);u(!p.isZero());var b=new h(1).toRed(this),_=b.redNeg(),v=this.m.subn(1).iushrn(1),o=this.m.bitLength();for(o=new h(2*o*o).toRed(this);this.pow(o,v).cmp(_)!==0;)o.redIAdd(_);for(var m=this.pow(o,p),A=this.pow(n,p.addn(1).iushrn(1)),I=this.pow(n,p),U=y;I.cmp(b)!==0;){for(var X=I,V=0;X.cmp(b)!==0;V++)X=X.redSqr();u(V<U);var T=this.pow(m,new h(1).iushln(U-V-1));A=A.redMul(T),m=T.redSqr(),I=I.redMul(m),U=V}return A},ie.prototype.invm=function(n){var l=n._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},ie.prototype.pow=function(n,l){if(l.isZero())return new h(1).toRed(this);if(l.cmpn(1)===0)return n.clone();var c=4,p=new Array(1<<c);p[0]=new h(1).toRed(this),p[1]=n;for(var y=2;y<p.length;y++)p[y]=this.mul(p[y-1],n);var b=p[0],_=0,v=0,o=l.bitLength()%26;for(o===0&&(o=26),y=l.length-1;y>=0;y--){for(var m=l.words[y],A=o-1;A>=0;A--){var I=m>>A&1;if(b!==p[0]&&(b=this.sqr(b)),I===0&&_===0){v=0;continue}_<<=1,_|=I,v++,!(v!==c&&(y!==0||A!==0))&&(b=this.mul(b,p[_]),v=0,_=0)}o=26}return b},ie.prototype.convertTo=function(n){var l=n.umod(this.m);return l===n?l.clone():l},ie.prototype.convertFrom=function(n){var l=n.clone();return l.red=null,l},h.mont=function(n){return new ce(n)};function ce($){ie.call(this,$),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new h(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}d(ce,ie),ce.prototype.convertTo=function(n){return this.imod(n.ushln(this.shift))},ce.prototype.convertFrom=function(n){var l=this.imod(n.mul(this.rinv));return l.red=null,l},ce.prototype.imul=function(n,l){if(n.isZero()||l.isZero())return n.words[0]=0,n.length=1,n;var c=n.imul(l),p=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=c.isub(p).iushrn(this.shift),b=y;return y.cmp(this.m)>=0?b=y.isub(this.m):y.cmpn(0)<0&&(b=y.iadd(this.m)),b._forceRed(this)},ce.prototype.mul=function(n,l){if(n.isZero()||l.isZero())return new h(0)._forceRed(this);var c=n.mul(l),p=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),y=c.isub(p).iushrn(this.shift),b=y;return y.cmp(this.m)>=0?b=y.isub(this.m):y.cmpn(0)<0&&(b=y.iadd(this.m)),b._forceRed(this)},ce.prototype.invm=function(n){var l=this.imod(n._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(e,commonjsGlobal)})(bn);var bnExports=bn.exports,BN$2=bnExports,Buffer$3=safeBufferExports$2.Buffer;function withPublic$2(e,t){return Buffer$3.from(e.toRed(BN$2.mont(t.modulus)).redPow(new BN$2(t.publicExponent)).fromRed().toArray())}var withPublic_1=withPublic$2,parseKeys$1=parseAsn1,randomBytes$1=browserExports,createHash$1=browser$9,mgf$1=mgf$2,xor$1=xor$2,BN$1=bnExports,withPublic$1=withPublic_1,crt$1=browserifyRsa,Buffer$2=safeBufferExports$2.Buffer,publicEncrypt=function e(t,a,u){var d;t.padding?d=t.padding:u?d=1:d=4;var h=parseKeys$1(t),w;if(d===4)w=oaep$1(h,a);else if(d===1)w=pkcs1$1(h,a,u);else if(d===3){if(w=new BN$1(a),w.cmp(h.modulus)>=0)throw new Error("data too long for modulus")}else throw new Error("unknown padding");return u?crt$1(w,h):withPublic$1(w,h)};function oaep$1(e,t){var a=e.modulus.byteLength(),u=t.length,d=createHash$1("sha1").update(Buffer$2.alloc(0)).digest(),h=d.length,w=2*h;if(u>a-w-2)throw new Error("message too long");var x=Buffer$2.alloc(a-u-w-2),M=a-h-1,B=randomBytes$1(h),E=xor$1(Buffer$2.concat([d,x,Buffer$2.alloc(1,1),t],M),mgf$1(B,M)),S=xor$1(B,mgf$1(E,h));return new BN$1(Buffer$2.concat([Buffer$2.alloc(1),S,E],a))}function pkcs1$1(e,t,a){var u=t.length,d=e.modulus.byteLength();if(u>d-11)throw new Error("message too long");var h;return a?h=Buffer$2.alloc(d-u-3,255):h=nonZero(d-u-3),new BN$1(Buffer$2.concat([Buffer$2.from([0,a?1:2]),h,Buffer$2.alloc(1),t],d))}function nonZero(e){for(var t=Buffer$2.allocUnsafe(e),a=0,u=randomBytes$1(e*2),d=0,h;a<e;)d===u.length&&(u=randomBytes$1(e*2),d=0),h=u[d++],h&&(t[a++]=h);return t}var parseKeys=parseAsn1,mgf=mgf$2,xor=xor$2,BN=bnExports,crt=browserifyRsa,createHash=browser$9,withPublic=withPublic_1,Buffer$1=safeBufferExports$2.Buffer,privateDecrypt=function e(t,a,u){var d;t.padding?d=t.padding:u?d=1:d=4;var h=parseKeys(t),w=h.modulus.byteLength();if(a.length>w||new BN(a).cmp(h.modulus)>=0)throw new Error("decryption error");var x;u?x=withPublic(new BN(a),h):x=crt(a,h);var M=Buffer$1.alloc(w-x.length);if(x=Buffer$1.concat([M,x],w),d===4)return oaep(h,x);if(d===1)return pkcs1(h,x,u);if(d===3)return x;throw new Error("unknown padding")};function oaep(e,t){var a=e.modulus.byteLength(),u=createHash("sha1").update(Buffer$1.alloc(0)).digest(),d=u.length;if(t[0]!==0)throw new Error("decryption error");var h=t.slice(1,d+1),w=t.slice(d+1),x=xor(h,mgf(w,d)),M=xor(w,mgf(x,a-d-1));if(compare(u,M.slice(0,d)))throw new Error("decryption error");for(var B=d;M[B]===0;)B++;if(M[B++]!==1)throw new Error("decryption error");return M.slice(B)}function pkcs1(e,t,a){for(var u=t.slice(0,2),d=2,h=0;t[d++]!==0;)if(d>=t.length){h++;break}var w=t.slice(2,d-1);if((u.toString("hex")!=="0002"&&!a||u.toString("hex")!=="0001"&&a)&&h++,w.length<8&&h++,h)throw new Error("decryption error");return t.slice(d)}function compare(e,t){e=Buffer$1.from(e),t=Buffer$1.from(t);var a=0,u=e.length;e.length!==t.length&&(a++,u=Math.min(e.length,t.length));for(var d=-1;++d<u;)a+=e[d]^t[d];return a}(function(e){e.publicEncrypt=publicEncrypt,e.privateDecrypt=privateDecrypt,e.privateEncrypt=function(a,u){return e.publicEncrypt(a,u,!0)},e.publicDecrypt=function(a,u){return e.privateDecrypt(a,u,!0)}})(browser$1);var browser={};function oldBrowser(){throw new Error(`secure random number generation not supported by this browser
20
20
  use chrome, FireFox or Internet Explorer 11`)}var safeBuffer=safeBufferExports$2,randombytes=browserExports,Buffer=safeBuffer.Buffer,kBufferMaxLength=safeBuffer.kMaxLength,crypto$1=commonjsGlobal.crypto||commonjsGlobal.msCrypto,kMaxUint32=Math.pow(2,32)-1;function assertOffset(e,t){if(typeof e!="number"||e!==e)throw new TypeError("offset must be a number");if(e>kMaxUint32||e<0)throw new TypeError("offset must be a uint32");if(e>kBufferMaxLength||e>t)throw new RangeError("offset out of range")}function assertSize(e,t,a){if(typeof e!="number"||e!==e)throw new TypeError("size must be a number");if(e>kMaxUint32||e<0)throw new TypeError("size must be a uint32");if(e+t>a||e>kBufferMaxLength)throw new RangeError("buffer too small")}crypto$1&&crypto$1.getRandomValues||!process$1.browser?(browser.randomFill=randomFill,browser.randomFillSync=randomFillSync):(browser.randomFill=oldBrowser,browser.randomFillSync=oldBrowser);function randomFill(e,t,a,u){if(!Buffer.isBuffer(e)&&!(e instanceof commonjsGlobal.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');if(typeof t=="function")u=t,t=0,a=e.length;else if(typeof a=="function")u=a,a=e.length-t;else if(typeof u!="function")throw new TypeError('"cb" argument must be a function');return assertOffset(t,e.length),assertSize(a,t,e.length),actualFill(e,t,a,u)}function actualFill(e,t,a,u){if(process$1.browser){var d=e.buffer,h=new Uint8Array(d,t,a);if(crypto$1.getRandomValues(h),u){process$1.nextTick(function(){u(null,e)});return}return e}if(u){randombytes(a,function(x,M){if(x)return u(x);M.copy(e,t),u(null,e)});return}var w=randombytes(a);return w.copy(e,t),e}function randomFillSync(e,t,a){if(typeof t>"u"&&(t=0),!Buffer.isBuffer(e)&&!(e instanceof commonjsGlobal.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');return assertOffset(t,e.length),a===void 0&&(a=e.length-t),assertSize(a,t,e.length),actualFill(e,t,a)}var hasRequiredCryptoBrowserify;function requireCryptoBrowserify(){if(hasRequiredCryptoBrowserify)return cryptoBrowserify;hasRequiredCryptoBrowserify=1,cryptoBrowserify.randomBytes=cryptoBrowserify.rng=cryptoBrowserify.pseudoRandomBytes=cryptoBrowserify.prng=browserExports,cryptoBrowserify.createHash=cryptoBrowserify.Hash=browser$9,cryptoBrowserify.createHmac=cryptoBrowserify.Hmac=browser$8;var e=algos,t=Object.keys(e),a=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(t);cryptoBrowserify.getHashes=function(){return a};var u=browser$7;cryptoBrowserify.pbkdf2=u.pbkdf2,cryptoBrowserify.pbkdf2Sync=u.pbkdf2Sync;var d=browser$6;cryptoBrowserify.Cipher=d.Cipher,cryptoBrowserify.createCipher=d.createCipher,cryptoBrowserify.Cipheriv=d.Cipheriv,cryptoBrowserify.createCipheriv=d.createCipheriv,cryptoBrowserify.Decipher=d.Decipher,cryptoBrowserify.createDecipher=d.createDecipher,cryptoBrowserify.Decipheriv=d.Decipheriv,cryptoBrowserify.createDecipheriv=d.createDecipheriv,cryptoBrowserify.getCiphers=d.getCiphers,cryptoBrowserify.listCiphers=d.listCiphers;var h=requireBrowser$2();cryptoBrowserify.DiffieHellmanGroup=h.DiffieHellmanGroup,cryptoBrowserify.createDiffieHellmanGroup=h.createDiffieHellmanGroup,cryptoBrowserify.getDiffieHellman=h.getDiffieHellman,cryptoBrowserify.createDiffieHellman=h.createDiffieHellman,cryptoBrowserify.DiffieHellman=h.DiffieHellman;var w=requireBrowser$1();cryptoBrowserify.createSign=w.createSign,cryptoBrowserify.Sign=w.Sign,cryptoBrowserify.createVerify=w.createVerify,cryptoBrowserify.Verify=w.Verify,cryptoBrowserify.createECDH=requireBrowser();var x=browser$1;cryptoBrowserify.publicEncrypt=x.publicEncrypt,cryptoBrowserify.privateEncrypt=x.privateEncrypt,cryptoBrowserify.publicDecrypt=x.publicDecrypt,cryptoBrowserify.privateDecrypt=x.privateDecrypt;var M=browser;return cryptoBrowserify.randomFill=M.randomFill,cryptoBrowserify.randomFillSync=M.randomFillSync,cryptoBrowserify.createCredentials=function(){throw new Error(`sorry, createCredentials is not implemented yet
21
21
  we accept pull requests
22
- https://github.com/browserify/crypto-browserify`)},cryptoBrowserify.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6},cryptoBrowserify}var cryptoBrowserifyExports=requireCryptoBrowserify();const index=getDefaultExportFromCjs$1(cryptoBrowserifyExports),nc2=_mergeNamespaces({__proto__:null,default:index},[cryptoBrowserifyExports]);var __defProp=Object.defineProperty,__export=(e,t)=>{for(var a in t)__defProp(e,a,{get:t[a],enumerable:!0})};function number(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function bytes(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function hash(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number(e.outputLen),number(e.blockLen)}function exists(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output(e,t){bytes(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}var crypto=nc2&&typeof nc2=="object"&&"webcrypto"in nc2?cryptoBrowserifyExports.webcrypto:void 0,u8a=e=>e instanceof Uint8Array,createView=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),rotr=(e,t)=>e<<32-t|e>>>t,isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE)throw new Error("Non little-endian hardware is not supported");function utf8ToBytes(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes(e){if(typeof e=="string"&&(e=utf8ToBytes(e)),!u8a(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function concatBytes(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}var Hash=class{clone(){return this._cloneInto()}};function wrapConstructor(e){const t=u=>e().update(toBytes(u)).digest(),a=e();return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=()=>e(),t}function randomBytes(e=32){if(crypto&&typeof crypto.getRandomValues=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function setBigUint64(e,t,a,u){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,a,u);const d=BigInt(32),h=BigInt(4294967295),w=Number(a>>d&h),x=Number(a&h),M=u?4:0,B=u?0:4;e.setUint32(t+M,w,u),e.setUint32(t+B,x,u)}var SHA2=class extends Hash{constructor(e,t,a,u){super(),this.blockLen=e,this.outputLen=t,this.padOffset=a,this.isLE=u,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=createView(this.buffer)}update(e){exists(this);const{view:t,buffer:a,blockLen:u}=this;e=toBytes(e);const d=e.length;for(let h=0;h<d;){const w=Math.min(u-this.pos,d-h);if(w===u){const x=createView(e);for(;u<=d-h;h+=u)this.process(x,h);continue}a.set(e.subarray(h,h+w),this.pos),this.pos+=w,h+=w,this.pos===u&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){exists(this),output(e,this),this.finished=!0;const{buffer:t,view:a,blockLen:u,isLE:d}=this;let{pos:h}=this;t[h++]=128,this.buffer.subarray(h).fill(0),this.padOffset>u-h&&(this.process(a,0),h=0);for(let E=h;E<u;E++)t[E]=0;setBigUint64(a,u-8,BigInt(this.length*8),d),this.process(a,0);const w=createView(e),x=this.outputLen;if(x%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const M=x/4,B=this.get();if(M>B.length)throw new Error("_sha2: outputLen bigger than state");for(let E=0;E<M;E++)w.setUint32(4*E,B[E],d)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const a=e.slice(0,t);return this.destroy(),a}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:a,length:u,finished:d,destroyed:h,pos:w}=this;return e.length=u,e.pos=w,e.finished=d,e.destroyed=h,u%t&&e.buffer.set(a),e}},Chi=(e,t,a)=>e&t^~e&a,Maj=(e,t,a)=>e&t^e&a^t&a,SHA256_K=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W=new Uint32Array(64),SHA256=class extends SHA2{constructor(){super(64,32,8,!1),this.A=IV[0]|0,this.B=IV[1]|0,this.C=IV[2]|0,this.D=IV[3]|0,this.E=IV[4]|0,this.F=IV[5]|0,this.G=IV[6]|0,this.H=IV[7]|0}get(){const{A:e,B:t,C:a,D:u,E:d,F:h,G:w,H:x}=this;return[e,t,a,u,d,h,w,x]}set(e,t,a,u,d,h,w,x){this.A=e|0,this.B=t|0,this.C=a|0,this.D=u|0,this.E=d|0,this.F=h|0,this.G=w|0,this.H=x|0}process(e,t){for(let E=0;E<16;E++,t+=4)SHA256_W[E]=e.getUint32(t,!1);for(let E=16;E<64;E++){const S=SHA256_W[E-15],k=SHA256_W[E-2],C=rotr(S,7)^rotr(S,18)^S>>>3,D=rotr(k,17)^rotr(k,19)^k>>>10;SHA256_W[E]=D+SHA256_W[E-7]+C+SHA256_W[E-16]|0}let{A:a,B:u,C:d,D:h,E:w,F:x,G:M,H:B}=this;for(let E=0;E<64;E++){const S=rotr(w,6)^rotr(w,11)^rotr(w,25),k=B+S+Chi(w,x,M)+SHA256_K[E]+SHA256_W[E]|0,D=(rotr(a,2)^rotr(a,13)^rotr(a,22))+Maj(a,u,d)|0;B=M,M=x,x=w,w=h+k|0,h=d,d=u,u=a,a=k+D|0}a=a+this.A|0,u=u+this.B|0,d=d+this.C|0,h=h+this.D|0,w=w+this.E|0,x=x+this.F|0,M=M+this.G|0,B=B+this.H|0,this.set(a,u,d,h,w,x,M,B)}roundClean(){SHA256_W.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},sha256=wrapConstructor(()=>new SHA256),utils_exports={};__export(utils_exports,{bitGet:()=>bitGet,bitLen:()=>bitLen,bitMask:()=>bitMask,bitSet:()=>bitSet,bytesToHex:()=>bytesToHex,bytesToNumberBE:()=>bytesToNumberBE,bytesToNumberLE:()=>bytesToNumberLE,concatBytes:()=>concatBytes2,createHmacDrbg:()=>createHmacDrbg,ensureBytes:()=>ensureBytes,equalBytes:()=>equalBytes,hexToBytes:()=>hexToBytes,hexToNumber:()=>hexToNumber,numberToBytesBE:()=>numberToBytesBE,numberToBytesLE:()=>numberToBytesLE,numberToHexUnpadded:()=>numberToHexUnpadded,numberToVarBytesBE:()=>numberToVarBytesBE,utf8ToBytes:()=>utf8ToBytes2,validateObject:()=>validateObject});var _0n=BigInt(0),_1n=BigInt(1),_2n=BigInt(2),u8a2=e=>e instanceof Uint8Array,hexes=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex(e){if(!u8a2(e))throw new Error("Uint8Array expected");let t="";for(let a=0;a<e.length;a++)t+=hexes[e[a]];return t}function numberToHexUnpadded(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function hexToNumber(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function hexToBytes(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const a=new Uint8Array(t/2);for(let u=0;u<a.length;u++){const d=u*2,h=e.slice(d,d+2),w=Number.parseInt(h,16);if(Number.isNaN(w)||w<0)throw new Error("Invalid byte sequence");a[u]=w}return a}function bytesToNumberBE(e){return hexToNumber(bytesToHex(e))}function bytesToNumberLE(e){if(!u8a2(e))throw new Error("Uint8Array expected");return hexToNumber(bytesToHex(Uint8Array.from(e).reverse()))}function numberToBytesBE(e,t){return hexToBytes(e.toString(16).padStart(t*2,"0"))}function numberToBytesLE(e,t){return numberToBytesBE(e,t).reverse()}function numberToVarBytesBE(e){return hexToBytes(numberToHexUnpadded(e))}function ensureBytes(e,t,a){let u;if(typeof t=="string")try{u=hexToBytes(t)}catch(h){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${h}`)}else if(u8a2(t))u=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const d=u.length;if(typeof a=="number"&&d!==a)throw new Error(`${e} expected ${a} bytes, got ${d}`);return u}function concatBytes2(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a2(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}function equalBytes(e,t){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}function utf8ToBytes2(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function bitLen(e){let t;for(t=0;e>_0n;e>>=_1n,t+=1);return t}function bitGet(e,t){return e>>BigInt(t)&_1n}var bitSet=(e,t,a)=>e|(a?_1n:_0n)<<BigInt(t),bitMask=e=>(_2n<<BigInt(e-1))-_1n,u8n=e=>new Uint8Array(e),u8fr=e=>Uint8Array.from(e);function createHmacDrbg(e,t,a){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof a!="function")throw new Error("hmacFn must be a function");let u=u8n(e),d=u8n(e),h=0;const w=()=>{u.fill(1),d.fill(0),h=0},x=(...S)=>a(d,u,...S),M=(S=u8n())=>{d=x(u8fr([0]),S),u=x(),S.length!==0&&(d=x(u8fr([1]),S),u=x())},B=()=>{if(h++>=1e3)throw new Error("drbg: tried 1000 values");let S=0;const k=[];for(;S<t;){u=x();const C=u.slice();k.push(C),S+=u.length}return concatBytes2(...k)};return(S,k)=>{w(),M(S);let C;for(;!(C=k(B()));)M();return w(),C}}var validatorFns={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function validateObject(e,t,a={}){const u=(d,h,w)=>{const x=validatorFns[h];if(typeof x!="function")throw new Error(`Invalid validator "${h}", expected function`);const M=e[d];if(!(w&&M===void 0)&&!x(M,e))throw new Error(`Invalid param ${String(d)}=${M} (${typeof M}), expected ${h}`)};for(const[d,h]of Object.entries(t))u(d,h,!1);for(const[d,h]of Object.entries(a))u(d,h,!0);return e}var _0n2=BigInt(0),_1n2=BigInt(1),_2n2=BigInt(2),_3n=BigInt(3),_4n=BigInt(4),_5n=BigInt(5),_8n=BigInt(8);BigInt(9);BigInt(16);function mod(e,t){const a=e%t;return a>=_0n2?a:t+a}function pow(e,t,a){if(a<=_0n2||t<_0n2)throw new Error("Expected power/modulo > 0");if(a===_1n2)return _0n2;let u=_1n2;for(;t>_0n2;)t&_1n2&&(u=u*e%a),e=e*e%a,t>>=_1n2;return u}function pow2(e,t,a){let u=e;for(;t-- >_0n2;)u*=u,u%=a;return u}function invert(e,t){if(e===_0n2||t<=_0n2)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let a=mod(e,t),u=t,d=_0n2,h=_1n2;for(;a!==_0n2;){const x=u/a,M=u%a,B=d-h*x;u=a,a=M,d=h,h=B}if(u!==_1n2)throw new Error("invert: does not exist");return mod(d,t)}function tonelliShanks(e){const t=(e-_1n2)/_2n2;let a,u,d;for(a=e-_1n2,u=0;a%_2n2===_0n2;a/=_2n2,u++);for(d=_2n2;d<e&&pow(d,t,e)!==e-_1n2;d++);if(u===1){const w=(e+_1n2)/_4n;return function(M,B){const E=M.pow(B,w);if(!M.eql(M.sqr(E),B))throw new Error("Cannot find square root");return E}}const h=(a+_1n2)/_2n2;return function(x,M){if(x.pow(M,t)===x.neg(x.ONE))throw new Error("Cannot find square root");let B=u,E=x.pow(x.mul(x.ONE,d),a),S=x.pow(M,h),k=x.pow(M,a);for(;!x.eql(k,x.ONE);){if(x.eql(k,x.ZERO))return x.ZERO;let C=1;for(let O=x.sqr(k);C<B&&!x.eql(O,x.ONE);C++)O=x.sqr(O);const D=x.pow(E,_1n2<<BigInt(B-C-1));E=x.sqr(D),S=x.mul(S,D),k=x.mul(k,E),B=C}return S}}function FpSqrt(e){if(e%_4n===_3n){const t=(e+_1n2)/_4n;return function(u,d){const h=u.pow(d,t);if(!u.eql(u.sqr(h),d))throw new Error("Cannot find square root");return h}}if(e%_8n===_5n){const t=(e-_5n)/_8n;return function(u,d){const h=u.mul(d,_2n2),w=u.pow(h,t),x=u.mul(d,w),M=u.mul(u.mul(x,_2n2),w),B=u.mul(x,u.sub(M,u.ONE));if(!u.eql(u.sqr(B),d))throw new Error("Cannot find square root");return B}}return tonelliShanks(e)}var FIELD_FIELDS=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function validateField(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},a=FIELD_FIELDS.reduce((u,d)=>(u[d]="function",u),t);return validateObject(e,a)}function FpPow(e,t,a){if(a<_0n2)throw new Error("Expected power > 0");if(a===_0n2)return e.ONE;if(a===_1n2)return t;let u=e.ONE,d=t;for(;a>_0n2;)a&_1n2&&(u=e.mul(u,d)),d=e.sqr(d),a>>=_1n2;return u}function FpInvertBatch(e,t){const a=new Array(t.length),u=t.reduce((h,w,x)=>e.is0(w)?h:(a[x]=h,e.mul(h,w)),e.ONE),d=e.inv(u);return t.reduceRight((h,w,x)=>e.is0(w)?h:(a[x]=e.mul(h,a[x]),e.mul(h,w)),d),a}function nLength(e,t){const a=t!==void 0?t:e.toString(2).length,u=Math.ceil(a/8);return{nBitLength:a,nByteLength:u}}function Field(e,t,a=!1,u={}){if(e<=_0n2)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:d,nByteLength:h}=nLength(e,t);if(h>2048)throw new Error("Field lengths over 2048 bytes are not supported");const w=FpSqrt(e),x=Object.freeze({ORDER:e,BITS:d,BYTES:h,MASK:bitMask(d),ZERO:_0n2,ONE:_1n2,create:M=>mod(M,e),isValid:M=>{if(typeof M!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof M}`);return _0n2<=M&&M<e},is0:M=>M===_0n2,isOdd:M=>(M&_1n2)===_1n2,neg:M=>mod(-M,e),eql:(M,B)=>M===B,sqr:M=>mod(M*M,e),add:(M,B)=>mod(M+B,e),sub:(M,B)=>mod(M-B,e),mul:(M,B)=>mod(M*B,e),pow:(M,B)=>FpPow(x,M,B),div:(M,B)=>mod(M*invert(B,e),e),sqrN:M=>M*M,addN:(M,B)=>M+B,subN:(M,B)=>M-B,mulN:(M,B)=>M*B,inv:M=>invert(M,e),sqrt:u.sqrt||(M=>w(x,M)),invertBatch:M=>FpInvertBatch(x,M),cmov:(M,B,E)=>E?B:M,toBytes:M=>a?numberToBytesLE(M,h):numberToBytesBE(M,h),fromBytes:M=>{if(M.length!==h)throw new Error(`Fp.fromBytes: expected ${h}, got ${M.length}`);return a?bytesToNumberLE(M):bytesToNumberBE(M)}});return Object.freeze(x)}function getFieldBytesLength(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function getMinHashLength(e){const t=getFieldBytesLength(e);return t+Math.ceil(t/2)}function mapHashToField(e,t,a=!1){const u=e.length,d=getFieldBytesLength(t),h=getMinHashLength(t);if(u<16||u<h||u>1024)throw new Error(`expected ${h}-1024 bytes of input, got ${u}`);const w=a?bytesToNumberBE(e):bytesToNumberLE(e),x=mod(w,t-_1n2)+_1n2;return a?numberToBytesLE(x,d):numberToBytesBE(x,d)}var _0n3=BigInt(0),_1n3=BigInt(1);function wNAF(e,t){const a=(d,h)=>{const w=h.negate();return d?w:h},u=d=>{const h=Math.ceil(t/d)+1,w=2**(d-1);return{windows:h,windowSize:w}};return{constTimeNegate:a,unsafeLadder(d,h){let w=e.ZERO,x=d;for(;h>_0n3;)h&_1n3&&(w=w.add(x)),x=x.double(),h>>=_1n3;return w},precomputeWindow(d,h){const{windows:w,windowSize:x}=u(h),M=[];let B=d,E=B;for(let S=0;S<w;S++){E=B,M.push(E);for(let k=1;k<x;k++)E=E.add(B),M.push(E);B=E.double()}return M},wNAF(d,h,w){const{windows:x,windowSize:M}=u(d);let B=e.ZERO,E=e.BASE;const S=BigInt(2**d-1),k=2**d,C=BigInt(d);for(let D=0;D<x;D++){const O=D*M;let F=Number(w&S);w>>=C,F>M&&(F-=k,w+=_1n3);const P=O,L=O+Math.abs(F)-1,J=D%2!==0,Y=F<0;F===0?E=E.add(a(J,h[P])):B=B.add(a(Y,h[L]))}return{p:B,f:E}},wNAFCached(d,h,w,x){const M=d._WINDOW_SIZE||1;let B=h.get(d);return B||(B=this.precomputeWindow(d,M),M!==1&&h.set(d,x(B))),this.wNAF(M,B,w)}}}function validateBasic(e){return validateField(e.Fp),validateObject(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...nLength(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}function validatePointOpts(e){const t=validateBasic(e);validateObject(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:a,Fp:u,a:d}=t;if(a){if(!u.eql(d,u.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof a!="object"||typeof a.beta!="bigint"||typeof a.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:b2n,hexToBytes:h2b}=utils_exports,DER={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=DER;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const a=e[1],u=e.subarray(2,a+2);if(!a||u.length!==a)throw new t("Invalid signature integer: wrong length");if(u[0]&128)throw new t("Invalid signature integer: negative");if(u[0]===0&&!(u[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:b2n(u),l:e.subarray(a+2)}},toSig(e){const{Err:t}=DER,a=typeof e=="string"?h2b(e):e;if(!(a instanceof Uint8Array))throw new Error("ui8a expected");let u=a.length;if(u<2||a[0]!=48)throw new t("Invalid signature tag");if(a[1]!==u-2)throw new t("Invalid signature: incorrect length");const{d,l:h}=DER._parseInt(a.subarray(2)),{d:w,l:x}=DER._parseInt(h);if(x.length)throw new t("Invalid signature: left bytes after parsing");return{r:d,s:w}},hexFromSig(e){const t=B=>Number.parseInt(B[0],16)&8?"00"+B:B,a=B=>{const E=B.toString(16);return E.length&1?`0${E}`:E},u=t(a(e.s)),d=t(a(e.r)),h=u.length/2,w=d.length/2,x=a(h),M=a(w);return`30${a(w+h+4)}02${M}${d}02${x}${u}`}},_0n4=BigInt(0),_1n4=BigInt(1);BigInt(2);var _3n2=BigInt(3);BigInt(4);function weierstrassPoints(e){const t=validatePointOpts(e),{Fp:a}=t,u=t.toBytes||((D,O,F)=>{const P=O.toAffine();return concatBytes2(Uint8Array.from([4]),a.toBytes(P.x),a.toBytes(P.y))}),d=t.fromBytes||(D=>{const O=D.subarray(1),F=a.fromBytes(O.subarray(0,a.BYTES)),P=a.fromBytes(O.subarray(a.BYTES,2*a.BYTES));return{x:F,y:P}});function h(D){const{a:O,b:F}=t,P=a.sqr(D),L=a.mul(P,D);return a.add(a.add(L,a.mul(D,O)),F)}if(!a.eql(a.sqr(t.Gy),h(t.Gx)))throw new Error("bad generator point: equation left != right");function w(D){return typeof D=="bigint"&&_0n4<D&&D<t.n}function x(D){if(!w(D))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function M(D){const{allowedPrivateKeyLengths:O,nByteLength:F,wrapPrivateKey:P,n:L}=t;if(O&&typeof D!="bigint"){if(D instanceof Uint8Array&&(D=bytesToHex(D)),typeof D!="string"||!O.includes(D.length))throw new Error("Invalid key");D=D.padStart(F*2,"0")}let J;try{J=typeof D=="bigint"?D:bytesToNumberBE(ensureBytes("private key",D,F))}catch{throw new Error(`private key must be ${F} bytes, hex or bigint, not ${typeof D}`)}return P&&(J=mod(J,L)),x(J),J}const B=new Map;function E(D){if(!(D instanceof S))throw new Error("ProjectivePoint expected")}class S{constructor(O,F,P){if(this.px=O,this.py=F,this.pz=P,O==null||!a.isValid(O))throw new Error("x required");if(F==null||!a.isValid(F))throw new Error("y required");if(P==null||!a.isValid(P))throw new Error("z required")}static fromAffine(O){const{x:F,y:P}=O||{};if(!O||!a.isValid(F)||!a.isValid(P))throw new Error("invalid affine point");if(O instanceof S)throw new Error("projective point not allowed");const L=J=>a.eql(J,a.ZERO);return L(F)&&L(P)?S.ZERO:new S(F,P,a.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(O){const F=a.invertBatch(O.map(P=>P.pz));return O.map((P,L)=>P.toAffine(F[L])).map(S.fromAffine)}static fromHex(O){const F=S.fromAffine(d(ensureBytes("pointHex",O)));return F.assertValidity(),F}static fromPrivateKey(O){return S.BASE.multiply(M(O))}_setWindowSize(O){this._WINDOW_SIZE=O,B.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!a.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:O,y:F}=this.toAffine();if(!a.isValid(O)||!a.isValid(F))throw new Error("bad point: x or y not FE");const P=a.sqr(F),L=h(O);if(!a.eql(P,L))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:O}=this.toAffine();if(a.isOdd)return!a.isOdd(O);throw new Error("Field doesn't support isOdd")}equals(O){E(O);const{px:F,py:P,pz:L}=this,{px:J,py:Y,pz:ae}=O,oe=a.eql(a.mul(F,ae),a.mul(J,L)),ue=a.eql(a.mul(P,ae),a.mul(Y,L));return oe&&ue}negate(){return new S(this.px,a.neg(this.py),this.pz)}double(){const{a:O,b:F}=t,P=a.mul(F,_3n2),{px:L,py:J,pz:Y}=this;let ae=a.ZERO,oe=a.ZERO,ue=a.ZERO,se=a.mul(L,L),ie=a.mul(J,J),ce=a.mul(Y,Y),$=a.mul(L,J);return $=a.add($,$),ue=a.mul(L,Y),ue=a.add(ue,ue),ae=a.mul(O,ue),oe=a.mul(P,ce),oe=a.add(ae,oe),ae=a.sub(ie,oe),oe=a.add(ie,oe),oe=a.mul(ae,oe),ae=a.mul($,ae),ue=a.mul(P,ue),ce=a.mul(O,ce),$=a.sub(se,ce),$=a.mul(O,$),$=a.add($,ue),ue=a.add(se,se),se=a.add(ue,se),se=a.add(se,ce),se=a.mul(se,$),oe=a.add(oe,se),ce=a.mul(J,Y),ce=a.add(ce,ce),se=a.mul(ce,$),ae=a.sub(ae,se),ue=a.mul(ce,ie),ue=a.add(ue,ue),ue=a.add(ue,ue),new S(ae,oe,ue)}add(O){E(O);const{px:F,py:P,pz:L}=this,{px:J,py:Y,pz:ae}=O;let oe=a.ZERO,ue=a.ZERO,se=a.ZERO;const ie=t.a,ce=a.mul(t.b,_3n2);let $=a.mul(F,J),n=a.mul(P,Y),l=a.mul(L,ae),c=a.add(F,P),p=a.add(J,Y);c=a.mul(c,p),p=a.add($,n),c=a.sub(c,p),p=a.add(F,L);let y=a.add(J,ae);return p=a.mul(p,y),y=a.add($,l),p=a.sub(p,y),y=a.add(P,L),oe=a.add(Y,ae),y=a.mul(y,oe),oe=a.add(n,l),y=a.sub(y,oe),se=a.mul(ie,p),oe=a.mul(ce,l),se=a.add(oe,se),oe=a.sub(n,se),se=a.add(n,se),ue=a.mul(oe,se),n=a.add($,$),n=a.add(n,$),l=a.mul(ie,l),p=a.mul(ce,p),n=a.add(n,l),l=a.sub($,l),l=a.mul(ie,l),p=a.add(p,l),$=a.mul(n,p),ue=a.add(ue,$),$=a.mul(y,p),oe=a.mul(c,oe),oe=a.sub(oe,$),$=a.mul(c,n),se=a.mul(y,se),se=a.add(se,$),new S(oe,ue,se)}subtract(O){return this.add(O.negate())}is0(){return this.equals(S.ZERO)}wNAF(O){return C.wNAFCached(this,B,O,F=>{const P=a.invertBatch(F.map(L=>L.pz));return F.map((L,J)=>L.toAffine(P[J])).map(S.fromAffine)})}multiplyUnsafe(O){const F=S.ZERO;if(O===_0n4)return F;if(x(O),O===_1n4)return this;const{endo:P}=t;if(!P)return C.unsafeLadder(this,O);let{k1neg:L,k1:J,k2neg:Y,k2:ae}=P.splitScalar(O),oe=F,ue=F,se=this;for(;J>_0n4||ae>_0n4;)J&_1n4&&(oe=oe.add(se)),ae&_1n4&&(ue=ue.add(se)),se=se.double(),J>>=_1n4,ae>>=_1n4;return L&&(oe=oe.negate()),Y&&(ue=ue.negate()),ue=new S(a.mul(ue.px,P.beta),ue.py,ue.pz),oe.add(ue)}multiply(O){x(O);let F=O,P,L;const{endo:J}=t;if(J){const{k1neg:Y,k1:ae,k2neg:oe,k2:ue}=J.splitScalar(F);let{p:se,f:ie}=this.wNAF(ae),{p:ce,f:$}=this.wNAF(ue);se=C.constTimeNegate(Y,se),ce=C.constTimeNegate(oe,ce),ce=new S(a.mul(ce.px,J.beta),ce.py,ce.pz),P=se.add(ce),L=ie.add($)}else{const{p:Y,f:ae}=this.wNAF(F);P=Y,L=ae}return S.normalizeZ([P,L])[0]}multiplyAndAddUnsafe(O,F,P){const L=S.BASE,J=(ae,oe)=>oe===_0n4||oe===_1n4||!ae.equals(L)?ae.multiplyUnsafe(oe):ae.multiply(oe),Y=J(this,F).add(J(O,P));return Y.is0()?void 0:Y}toAffine(O){const{px:F,py:P,pz:L}=this,J=this.is0();O==null&&(O=J?a.ONE:a.inv(L));const Y=a.mul(F,O),ae=a.mul(P,O),oe=a.mul(L,O);if(J)return{x:a.ZERO,y:a.ZERO};if(!a.eql(oe,a.ONE))throw new Error("invZ was invalid");return{x:Y,y:ae}}isTorsionFree(){const{h:O,isTorsionFree:F}=t;if(O===_1n4)return!0;if(F)return F(S,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:O,clearCofactor:F}=t;return O===_1n4?this:F?F(S,this):this.multiplyUnsafe(t.h)}toRawBytes(O=!0){return this.assertValidity(),u(S,this,O)}toHex(O=!0){return bytesToHex(this.toRawBytes(O))}}S.BASE=new S(t.Gx,t.Gy,a.ONE),S.ZERO=new S(a.ZERO,a.ONE,a.ZERO);const k=t.nBitLength,C=wNAF(S,t.endo?Math.ceil(k/2):k);return{CURVE:t,ProjectivePoint:S,normPrivateKeyToScalar:M,weierstrassEquation:h,isWithinCurveOrder:w}}function validateOpts(e){const t=validateBasic(e);return validateObject(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function weierstrass(e){const t=validateOpts(e),{Fp:a,n:u}=t,d=a.BYTES+1,h=2*a.BYTES+1;function w(p){return _0n4<p&&p<a.ORDER}function x(p){return mod(p,u)}function M(p){return invert(p,u)}const{ProjectivePoint:B,normPrivateKeyToScalar:E,weierstrassEquation:S,isWithinCurveOrder:k}=weierstrassPoints({...t,toBytes(p,y,b){const _=y.toAffine(),v=a.toBytes(_.x),o=concatBytes2;return b?o(Uint8Array.from([y.hasEvenY()?2:3]),v):o(Uint8Array.from([4]),v,a.toBytes(_.y))},fromBytes(p){const y=p.length,b=p[0],_=p.subarray(1);if(y===d&&(b===2||b===3)){const v=bytesToNumberBE(_);if(!w(v))throw new Error("Point is not on curve");const o=S(v);let m=a.sqrt(o);const A=(m&_1n4)===_1n4;return(b&1)===1!==A&&(m=a.neg(m)),{x:v,y:m}}else if(y===h&&b===4){const v=a.fromBytes(_.subarray(0,a.BYTES)),o=a.fromBytes(_.subarray(a.BYTES,2*a.BYTES));return{x:v,y:o}}else throw new Error(`Point of length ${y} was invalid. Expected ${d} compressed bytes or ${h} uncompressed bytes`)}}),C=p=>bytesToHex(numberToBytesBE(p,t.nByteLength));function D(p){const y=u>>_1n4;return p>y}function O(p){return D(p)?x(-p):p}const F=(p,y,b)=>bytesToNumberBE(p.slice(y,b));class P{constructor(y,b,_){this.r=y,this.s=b,this.recovery=_,this.assertValidity()}static fromCompact(y){const b=t.nByteLength;return y=ensureBytes("compactSignature",y,b*2),new P(F(y,0,b),F(y,b,2*b))}static fromDER(y){const{r:b,s:_}=DER.toSig(ensureBytes("DER",y));return new P(b,_)}assertValidity(){if(!k(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!k(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(y){return new P(this.r,this.s,y)}recoverPublicKey(y){const{r:b,s:_,recovery:v}=this,o=ue(ensureBytes("msgHash",y));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");const m=v===2||v===3?b+t.n:b;if(m>=a.ORDER)throw new Error("recovery id 2 or 3 invalid");const A=v&1?"03":"02",I=B.fromHex(A+C(m)),U=M(m),X=x(-o*U),V=x(_*U),T=B.BASE.multiplyAndAddUnsafe(I,X,V);if(!T)throw new Error("point at infinify");return T.assertValidity(),T}hasHighS(){return D(this.s)}normalizeS(){return this.hasHighS()?new P(this.r,x(-this.s),this.recovery):this}toDERRawBytes(){return hexToBytes(this.toDERHex())}toDERHex(){return DER.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hexToBytes(this.toCompactHex())}toCompactHex(){return C(this.r)+C(this.s)}}const L={isValidPrivateKey(p){try{return E(p),!0}catch{return!1}},normPrivateKeyToScalar:E,randomPrivateKey:()=>{const p=getMinHashLength(t.n);return mapHashToField(t.randomBytes(p),t.n)},precompute(p=8,y=B.BASE){return y._setWindowSize(p),y.multiply(BigInt(3)),y}};function J(p,y=!0){return B.fromPrivateKey(p).toRawBytes(y)}function Y(p){const y=p instanceof Uint8Array,b=typeof p=="string",_=(y||b)&&p.length;return y?_===d||_===h:b?_===2*d||_===2*h:p instanceof B}function ae(p,y,b=!0){if(Y(p))throw new Error("first arg must be private key");if(!Y(y))throw new Error("second arg must be public key");return B.fromHex(y).multiply(E(p)).toRawBytes(b)}const oe=t.bits2int||function(p){const y=bytesToNumberBE(p),b=p.length*8-t.nBitLength;return b>0?y>>BigInt(b):y},ue=t.bits2int_modN||function(p){return x(oe(p))},se=bitMask(t.nBitLength);function ie(p){if(typeof p!="bigint")throw new Error("bigint expected");if(!(_0n4<=p&&p<se))throw new Error(`bigint expected < 2^${t.nBitLength}`);return numberToBytesBE(p,t.nByteLength)}function ce(p,y,b=$){if(["recovered","canonical"].some(Z=>Z in b))throw new Error("sign() legacy options not supported");const{hash:_,randomBytes:v}=t;let{lowS:o,prehash:m,extraEntropy:A}=b;o==null&&(o=!0),p=ensureBytes("msgHash",p),m&&(p=ensureBytes("prehashed msgHash",_(p)));const I=ue(p),U=E(y),X=[ie(U),ie(I)];if(A!=null){const Z=A===!0?v(a.BYTES):A;X.push(ensureBytes("extraEntropy",Z))}const V=concatBytes2(...X),T=I;function q(Z){const te=oe(Z);if(!k(te))return;const ee=M(te),j=B.BASE.multiply(te).toAffine(),re=x(j.x);if(re===_0n4)return;const qe=x(ee*x(T+re*U));if(qe===_0n4)return;let de=(j.x===re?0:2)|Number(j.y&_1n4),pe=qe;return o&&D(qe)&&(pe=O(qe),de^=1),new P(re,pe,de)}return{seed:V,k2sig:q}}const $={lowS:t.lowS,prehash:!1},n={lowS:t.lowS,prehash:!1};function l(p,y,b=$){const{seed:_,k2sig:v}=ce(p,y,b),o=t;return createHmacDrbg(o.hash.outputLen,o.nByteLength,o.hmac)(_,v)}B.BASE._setWindowSize(8);function c(p,y,b,_=n){var j;const v=p;if(y=ensureBytes("msgHash",y),b=ensureBytes("publicKey",b),"strict"in _)throw new Error("options.strict was renamed to lowS");const{lowS:o,prehash:m}=_;let A,I;try{if(typeof v=="string"||v instanceof Uint8Array)try{A=P.fromDER(v)}catch(re){if(!(re instanceof DER.Err))throw re;A=P.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){const{r:re,s:qe}=v;A=new P(re,qe)}else throw new Error("PARSE");I=B.fromHex(b)}catch(re){if(re.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(o&&A.hasHighS())return!1;m&&(y=t.hash(y));const{r:U,s:X}=A,V=ue(y),T=M(X),q=x(V*T),Z=x(U*T),te=(j=B.BASE.multiplyAndAddUnsafe(I,q,Z))==null?void 0:j.toAffine();return te?x(te.x)===U:!1}return{CURVE:t,getPublicKey:J,getSharedSecret:ae,sign:l,verify:c,ProjectivePoint:B,Signature:P,utils:L}}var HMAC=class extends Hash{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,hash(e);const a=toBytes(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const u=this.blockLen,d=new Uint8Array(u);d.set(a.length>u?e.create().update(a).digest():a);for(let h=0;h<d.length;h++)d[h]^=54;this.iHash.update(d),this.oHash=e.create();for(let h=0;h<d.length;h++)d[h]^=106;this.oHash.update(d),d.fill(0)}update(e){return exists(this),this.iHash.update(e),this}digestInto(e){exists(this),bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:a,finished:u,destroyed:d,blockLen:h,outputLen:w}=this;return e=e,e.finished=u,e.destroyed=d,e.blockLen=h,e.outputLen=w,e.oHash=t._cloneInto(e.oHash),e.iHash=a._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},hmac=(e,t,a)=>new HMAC(e,t).update(a).digest();hmac.create=(e,t)=>new HMAC(e,t);function getHash(e){return{hash:e,hmac:(t,...a)=>hmac(e,t,concatBytes(...a)),randomBytes}}function createCurve(e,t){const a=u=>weierstrass({...e,...getHash(u)});return Object.freeze({...a(t),create:a})}var secp256k1P=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),secp256k1N=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),_1n5=BigInt(1),_2n4=BigInt(2),divNearest=(e,t)=>(e+t/_2n4)/t;function sqrtMod(e){const t=secp256k1P,a=BigInt(3),u=BigInt(6),d=BigInt(11),h=BigInt(22),w=BigInt(23),x=BigInt(44),M=BigInt(88),B=e*e*e%t,E=B*B*e%t,S=pow2(E,a,t)*E%t,k=pow2(S,a,t)*E%t,C=pow2(k,_2n4,t)*B%t,D=pow2(C,d,t)*C%t,O=pow2(D,h,t)*D%t,F=pow2(O,x,t)*O%t,P=pow2(F,M,t)*F%t,L=pow2(P,x,t)*O%t,J=pow2(L,a,t)*E%t,Y=pow2(J,w,t)*D%t,ae=pow2(Y,u,t)*B%t,oe=pow2(ae,_2n4,t);if(!Fp.eql(Fp.sqr(oe),e))throw new Error("Cannot find square root");return oe}var Fp=Field(secp256k1P,void 0,void 0,{sqrt:sqrtMod}),secp256k1=createCurve({a:BigInt(0),b:BigInt(7),Fp,n:secp256k1N,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=secp256k1N,a=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),u=-_1n5*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),d=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),h=a,w=BigInt("0x100000000000000000000000000000000"),x=divNearest(h*e,t),M=divNearest(-u*e,t);let B=mod(e-x*a-M*d,t),E=mod(-x*u-M*h,t);const S=B>w,k=E>w;if(S&&(B=t-B),k&&(E=t-E),B>w||E>w)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:S,k1:B,k2neg:k,k2:E}}}},sha256),_0n5=BigInt(0),fe=e=>typeof e=="bigint"&&_0n5<e&&e<secp256k1P,ge=e=>typeof e=="bigint"&&_0n5<e&&e<secp256k1N,TAGGED_HASH_PREFIXES={};function taggedHash(e,...t){let a=TAGGED_HASH_PREFIXES[e];if(a===void 0){const u=sha256(Uint8Array.from(e,d=>d.charCodeAt(0)));a=concatBytes2(u,u),TAGGED_HASH_PREFIXES[e]=a}return sha256(concatBytes2(a,...t))}var pointToBytes=e=>e.toRawBytes(!0).slice(1),numTo32b=e=>numberToBytesBE(e,32),modP=e=>mod(e,secp256k1P),modN=e=>mod(e,secp256k1N),Point=secp256k1.ProjectivePoint,GmulAdd=(e,t,a)=>Point.BASE.multiplyAndAddUnsafe(e,t,a);function schnorrGetExtPubKey(e){let t=secp256k1.utils.normPrivateKeyToScalar(e),a=Point.fromPrivateKey(t);return{scalar:a.hasEvenY()?t:modN(-t),bytes:pointToBytes(a)}}function lift_x(e){if(!fe(e))throw new Error("bad x: need 0 < x < p");const t=modP(e*e),a=modP(t*e+BigInt(7));let u=sqrtMod(a);u%_2n4!==_0n5&&(u=modP(-u));const d=new Point(e,u,_1n5);return d.assertValidity(),d}function challenge(...e){return modN(bytesToNumberBE(taggedHash("BIP0340/challenge",...e)))}function schnorrGetPublicKey(e){return schnorrGetExtPubKey(e).bytes}function schnorrSign(e,t,a=randomBytes(32)){const u=ensureBytes("message",e),{bytes:d,scalar:h}=schnorrGetExtPubKey(t),w=ensureBytes("auxRand",a,32),x=numTo32b(h^bytesToNumberBE(taggedHash("BIP0340/aux",w))),M=taggedHash("BIP0340/nonce",x,d,u),B=modN(bytesToNumberBE(M));if(B===_0n5)throw new Error("sign failed: k is zero");const{bytes:E,scalar:S}=schnorrGetExtPubKey(B),k=challenge(E,d,u),C=new Uint8Array(64);if(C.set(E,0),C.set(numTo32b(modN(S+k*h)),32),!schnorrVerify(C,u,d))throw new Error("sign: Invalid signature produced");return C}function schnorrVerify(e,t,a){const u=ensureBytes("signature",e,64),d=ensureBytes("message",t),h=ensureBytes("publicKey",a,32);try{const w=lift_x(bytesToNumberBE(h)),x=bytesToNumberBE(u.subarray(0,32));if(!fe(x))return!1;const M=bytesToNumberBE(u.subarray(32,64));if(!ge(M))return!1;const B=challenge(numTo32b(x),pointToBytes(w),d),E=GmulAdd(w,M,modN(-B));return!(!E||!E.hasEvenY()||E.toAffine().x!==x)}catch{return!1}}var schnorr={getPublicKey:schnorrGetPublicKey,sign:schnorrSign,verify:schnorrVerify,utils:{randomPrivateKey:secp256k1.utils.randomPrivateKey,lift_x,pointToBytes,numberToBytesBE,bytesToNumberBE,taggedHash,mod}},crypto2=nc2&&typeof nc2=="object"&&"webcrypto"in nc2?cryptoBrowserifyExports.webcrypto:void 0,u8a3=e=>e instanceof Uint8Array,createView2=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),rotr2=(e,t)=>e<<32-t|e>>>t,isLE2=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE2)throw new Error("Non little-endian hardware is not supported");var hexes2=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex2(e){if(!u8a3(e))throw new Error("Uint8Array expected");let t="";for(let a=0;a<e.length;a++)t+=hexes2[e[a]];return t}function hexToBytes2(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const a=new Uint8Array(t/2);for(let u=0;u<a.length;u++){const d=u*2,h=e.slice(d,d+2),w=Number.parseInt(h,16);if(Number.isNaN(w)||w<0)throw new Error("Invalid byte sequence");a[u]=w}return a}function utf8ToBytes3(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes2(e){if(typeof e=="string"&&(e=utf8ToBytes3(e)),!u8a3(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function concatBytes3(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a3(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}var Hash2=class{clone(){return this._cloneInto()}};function wrapConstructor2(e){const t=u=>e().update(toBytes2(u)).digest(),a=e();return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=()=>e(),t}function randomBytes2(e=32){if(crypto2&&typeof crypto2.getRandomValues=="function")return crypto2.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function number2(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function bool(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function bytes2(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function hash2(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number2(e.outputLen),number2(e.blockLen)}function exists2(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output2(e,t){bytes2(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}var assert={number:number2,bool,bytes:bytes2,hash:hash2,exists:exists2,output:output2},assert_default=assert;function setBigUint642(e,t,a,u){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,a,u);const d=BigInt(32),h=BigInt(4294967295),w=Number(a>>d&h),x=Number(a&h),M=u?4:0,B=u?0:4;e.setUint32(t+M,w,u),e.setUint32(t+B,x,u)}var SHA22=class extends Hash2{constructor(e,t,a,u){super(),this.blockLen=e,this.outputLen=t,this.padOffset=a,this.isLE=u,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=createView2(this.buffer)}update(e){assert_default.exists(this);const{view:t,buffer:a,blockLen:u}=this;e=toBytes2(e);const d=e.length;for(let h=0;h<d;){const w=Math.min(u-this.pos,d-h);if(w===u){const x=createView2(e);for(;u<=d-h;h+=u)this.process(x,h);continue}a.set(e.subarray(h,h+w),this.pos),this.pos+=w,h+=w,this.pos===u&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){assert_default.exists(this),assert_default.output(e,this),this.finished=!0;const{buffer:t,view:a,blockLen:u,isLE:d}=this;let{pos:h}=this;t[h++]=128,this.buffer.subarray(h).fill(0),this.padOffset>u-h&&(this.process(a,0),h=0);for(let E=h;E<u;E++)t[E]=0;setBigUint642(a,u-8,BigInt(this.length*8),d),this.process(a,0);const w=createView2(e),x=this.outputLen;if(x%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const M=x/4,B=this.get();if(M>B.length)throw new Error("_sha2: outputLen bigger than state");for(let E=0;E<M;E++)w.setUint32(4*E,B[E],d)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const a=e.slice(0,t);return this.destroy(),a}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:a,length:u,finished:d,destroyed:h,pos:w}=this;return e.length=u,e.pos=w,e.finished=d,e.destroyed=h,u%t&&e.buffer.set(a),e}},Chi2=(e,t,a)=>e&t^~e&a,Maj2=(e,t,a)=>e&t^e&a^t&a,SHA256_K2=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]),IV2=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W2=new Uint32Array(64),SHA2562=class extends SHA22{constructor(){super(64,32,8,!1),this.A=IV2[0]|0,this.B=IV2[1]|0,this.C=IV2[2]|0,this.D=IV2[3]|0,this.E=IV2[4]|0,this.F=IV2[5]|0,this.G=IV2[6]|0,this.H=IV2[7]|0}get(){const{A:e,B:t,C:a,D:u,E:d,F:h,G:w,H:x}=this;return[e,t,a,u,d,h,w,x]}set(e,t,a,u,d,h,w,x){this.A=e|0,this.B=t|0,this.C=a|0,this.D=u|0,this.E=d|0,this.F=h|0,this.G=w|0,this.H=x|0}process(e,t){for(let E=0;E<16;E++,t+=4)SHA256_W2[E]=e.getUint32(t,!1);for(let E=16;E<64;E++){const S=SHA256_W2[E-15],k=SHA256_W2[E-2],C=rotr2(S,7)^rotr2(S,18)^S>>>3,D=rotr2(k,17)^rotr2(k,19)^k>>>10;SHA256_W2[E]=D+SHA256_W2[E-7]+C+SHA256_W2[E-16]|0}let{A:a,B:u,C:d,D:h,E:w,F:x,G:M,H:B}=this;for(let E=0;E<64;E++){const S=rotr2(w,6)^rotr2(w,11)^rotr2(w,25),k=B+S+Chi2(w,x,M)+SHA256_K2[E]+SHA256_W2[E]|0,D=(rotr2(a,2)^rotr2(a,13)^rotr2(a,22))+Maj2(a,u,d)|0;B=M,M=x,x=w,w=h+k|0,h=d,d=u,u=a,a=k+D|0}a=a+this.A|0,u=u+this.B|0,d=d+this.C|0,h=h+this.D|0,w=w+this.E|0,x=x+this.F|0,M=M+this.G|0,B=B+this.H|0,this.set(a,u,d,h,w,x,M,B)}roundClean(){SHA256_W2.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},SHA224=class extends SHA2562{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}},sha2562=wrapConstructor2(()=>new SHA2562);wrapConstructor2(()=>new SHA224);var verifiedSymbol=Symbol("verified"),isRecord=e=>e instanceof Object;function validateEvent(e){if(!isRecord(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let a=e.tags[t];if(!Array.isArray(a))return!1;for(let u=0;u<a.length;u++)if(typeof a[u]!="string")return!1}return!0}new TextDecoder("utf-8");var utf8Encoder=new TextEncoder,JS=class{generateSecretKey(){return schnorr.utils.randomPrivateKey()}getPublicKey(e){return bytesToHex2(schnorr.getPublicKey(e))}finalizeEvent(e,t){const a=e;return a.pubkey=bytesToHex2(schnorr.getPublicKey(t)),a.id=getEventHash(a),a.sig=bytesToHex2(schnorr.sign(getEventHash(a),t)),a[verifiedSymbol]=!0,a}verifyEvent(e){if(typeof e[verifiedSymbol]=="boolean")return e[verifiedSymbol];const t=getEventHash(e);if(t!==e.id)return e[verifiedSymbol]=!1,!1;try{const a=schnorr.verify(e.sig,t,e.pubkey);return e[verifiedSymbol]=a,a}catch{return e[verifiedSymbol]=!1,!1}}};function serializeEvent(e){if(!validateEvent(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function getEventHash(e){let t=sha2562(utf8Encoder.encode(serializeEvent(e)));return bytesToHex2(t)}var i=new JS;i.generateSecretKey;i.getPublicKey;i.finalizeEvent;i.verifyEvent;new TextDecoder("utf-8");new TextEncoder;var KINDS={SERVICE_RECORD:30059,ATTESTATION:30060,REVOCATION:30061};function assertNumber(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function chain(...e){const t=(d,h)=>w=>d(h(w)),a=Array.from(e).reverse().reduce((d,h)=>d?t(d,h.encode):h.encode,void 0),u=e.reduce((d,h)=>d?t(d,h.decode):h.decode,void 0);return{encode:a,decode:u}}function alphabet(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(a=>{if(assertNumber(a),a<0||a>=e.length)throw new Error(`Digit index outside alphabet: ${a} (alphabet: ${e.length})`);return e[a]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(a=>{if(typeof a!="string")throw new Error(`alphabet.decode: not string element=${a}`);const u=e.indexOf(a);if(u===-1)throw new Error(`Unknown letter: "${a}". Allowed: ${e}`);return u})}}}function join(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let a of t)if(typeof a!="string")throw new Error(`join.encode: non-string input=${a}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function padding(e,t="="){if(assertNumber(e),typeof t!="string")throw new Error("padding chr should be string");return{encode(a){if(!Array.isArray(a)||a.length&&typeof a[0]!="string")throw new Error("padding.encode input should be array of strings");for(let u of a)if(typeof u!="string")throw new Error(`padding.encode: non-string input=${u}`);for(;a.length*e%8;)a.push(t);return a},decode(a){if(!Array.isArray(a)||a.length&&typeof a[0]!="string")throw new Error("padding.encode input should be array of strings");for(let d of a)if(typeof d!="string")throw new Error(`padding.decode: non-string input=${d}`);let u=a.length;if(u*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;u>0&&a[u-1]===t;u--)if(!((u-1)*e%8))throw new Error("Invalid padding: string has too much padding");return a.slice(0,u)}}}function normalize(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function convertRadix(e,t,a){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(a<2)throw new Error(`convertRadix: wrong to=${a}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let u=0;const d=[],h=Array.from(e);for(h.forEach(w=>{if(assertNumber(w),w<0||w>=t)throw new Error(`Wrong integer: ${w}`)});;){let w=0,x=!0;for(let M=u;M<h.length;M++){const B=h[M],E=t*w+B;if(!Number.isSafeInteger(E)||t*w/t!==w||E-B!==t*w)throw new Error("convertRadix: carry overflow");if(w=E%a,h[M]=Math.floor(E/a),!Number.isSafeInteger(h[M])||h[M]*a+w!==E)throw new Error("convertRadix: carry overflow");if(x)h[M]?x=!1:u=M;else continue}if(d.push(w),x)break}for(let w=0;w<e.length-1&&e[w]===0;w++)d.push(0);return d.reverse()}var gcd=(e,t)=>t?gcd(t,e%t):e,radix2carry=(e,t)=>e+(t-gcd(e,t));function convertRadix2(e,t,a,u){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(a<=0||a>32)throw new Error(`convertRadix2: wrong to=${a}`);if(radix2carry(t,a)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${a} carryBits=${radix2carry(t,a)}`);let d=0,h=0;const w=2**a-1,x=[];for(const M of e){if(assertNumber(M),M>=2**t)throw new Error(`convertRadix2: invalid data word=${M} from=${t}`);if(d=d<<t|M,h+t>32)throw new Error(`convertRadix2: carry overflow pos=${h} from=${t}`);for(h+=t;h>=a;h-=a)x.push((d>>h-a&w)>>>0);d&=2**h-1}if(d=d<<a-h&w,!u&&h>=t)throw new Error("Excess padding");if(!u&&d)throw new Error(`Non-zero padding: ${d}`);return u&&h>0&&x.push(d>>>0),x}function radix(e){return assertNumber(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return convertRadix(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(convertRadix(t,e,2**8))}}}function radix2(e,t=!1){if(assertNumber(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(radix2carry(8,e)>32||radix2carry(e,8)>32)throw new Error("radix2: carry overflow");return{encode:a=>{if(!(a instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return convertRadix2(Array.from(a),8,e,!t)},decode:a=>{if(!Array.isArray(a)||a.length&&typeof a[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(convertRadix2(a,e,8,t))}}}function unsafeWrapper(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}var base16=chain(radix2(4),alphabet("0123456789ABCDEF"),join("")),base32=chain(radix2(5),alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),padding(5),join(""));chain(radix2(5),alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"),padding(5),join(""));chain(radix2(5),alphabet("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),join(""),normalize(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));var base64=chain(radix2(6),alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),padding(6),join("")),base64url=chain(radix2(6),alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),padding(6),join("")),genBase58=e=>chain(radix(58),alphabet(e),join("")),base58=genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");genBase58("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");genBase58("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");var XMR_BLOCK_LEN=[0,2,3,5,6,7,9,10,11],base58xmr={encode(e){let t="";for(let a=0;a<e.length;a+=8){const u=e.subarray(a,a+8);t+=base58.encode(u).padStart(XMR_BLOCK_LEN[u.length],"1")}return t},decode(e){let t=[];for(let a=0;a<e.length;a+=11){const u=e.slice(a,a+11),d=XMR_BLOCK_LEN.indexOf(u.length),h=base58.decode(u);for(let w=0;w<h.length-d;w++)if(h[w]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(h.slice(h.length-d)))}return Uint8Array.from(t)}},BECH_ALPHABET=chain(alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),join("")),POLYMOD_GENERATORS=[996825010,642813549,513874426,1027748829,705979059];function bech32Polymod(e){const t=e>>25;let a=(e&33554431)<<5;for(let u=0;u<POLYMOD_GENERATORS.length;u++)(t>>u&1)===1&&(a^=POLYMOD_GENERATORS[u]);return a}function bechChecksum(e,t,a=1){const u=e.length;let d=1;for(let h=0;h<u;h++){const w=e.charCodeAt(h);if(w<33||w>126)throw new Error(`Invalid prefix (${e})`);d=bech32Polymod(d)^w>>5}d=bech32Polymod(d);for(let h=0;h<u;h++)d=bech32Polymod(d)^e.charCodeAt(h)&31;for(let h of t)d=bech32Polymod(d)^h;for(let h=0;h<6;h++)d=bech32Polymod(d);return d^=a,BECH_ALPHABET.encode(convertRadix2([d%2**30],30,5,!1))}function genBech32(e){const t=e==="bech32"?1:734539939,a=radix2(5),u=a.decode,d=a.encode,h=unsafeWrapper(u);function w(E,S,k=90){if(typeof E!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof E}`);if(!Array.isArray(S)||S.length&&typeof S[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof S}`);const C=E.length+7+S.length;if(k!==!1&&C>k)throw new TypeError(`Length ${C} exceeds limit ${k}`);return E=E.toLowerCase(),`${E}1${BECH_ALPHABET.encode(S)}${bechChecksum(E,S,t)}`}function x(E,S=90){if(typeof E!="string")throw new Error(`bech32.decode input should be string, not ${typeof E}`);if(E.length<8||S!==!1&&E.length>S)throw new TypeError(`Wrong string length: ${E.length} (${E}). Expected (8..${S})`);const k=E.toLowerCase();if(E!==k&&E!==E.toUpperCase())throw new Error("String must be lowercase or uppercase");E=k;const C=E.lastIndexOf("1");if(C===0||C===-1)throw new Error('Letter "1" must be present between prefix and data only');const D=E.slice(0,C),O=E.slice(C+1);if(O.length<6)throw new Error("Data must be at least 6 characters long");const F=BECH_ALPHABET.decode(O).slice(0,-6),P=bechChecksum(D,F,t);if(!O.endsWith(P))throw new Error(`Invalid checksum in ${E}: expected "${P}"`);return{prefix:D,words:F}}const M=unsafeWrapper(x);function B(E){const{prefix:S,words:k}=x(E,!1);return{prefix:S,words:k,bytes:u(k)}}return{encode:w,decode:x,decodeToBytes:B,decodeUnsafe:M,fromWords:u,fromWordsUnsafe:h,toWords:d}}var bech32=genBech32("bech32");genBech32("bech32m");var utf8={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},hex=chain(radix2(4),alphabet("0123456789abcdef"),join(""),normalize(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})),CODERS={utf8,hex,base16,base32,base64,base64url,base58,base58xmr};`${Object.keys(CODERS).join(", ")}`;function number3(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function bool2(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function isBytes(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function bytes3(e,...t){if(!isBytes(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function exists3(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output3(e,t){bytes3(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}var u32=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),createView3=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),isLE3=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE3)throw new Error("Non little-endian hardware is not supported");var hexes3=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex3(e){bytes3(e);let t="";for(let a=0;a<e.length;a++)t+=hexes3[e[a]];return t}var asciis={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function asciiToBase16(e){if(e>=asciis._0&&e<=asciis._9)return e-asciis._0;if(e>=asciis._A&&e<=asciis._F)return e-(asciis._A-10);if(e>=asciis._a&&e<=asciis._f)return e-(asciis._a-10)}function hexToBytes3(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length,a=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const u=new Uint8Array(a);for(let d=0,h=0;d<a;d++,h+=2){const w=asciiToBase16(e.charCodeAt(h)),x=asciiToBase16(e.charCodeAt(h+1));if(w===void 0||x===void 0){const M=e[h]+e[h+1];throw new Error('hex string expected, got non-hex character "'+M+'" at index '+h)}u[d]=w*16+x}return u}function utf8ToBytes4(e){if(typeof e!="string")throw new Error(`string expected, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes3(e){if(typeof e=="string")e=utf8ToBytes4(e);else if(isBytes(e))e=e.slice();else throw new Error(`Uint8Array expected, got ${typeof e}`);return e}function checkOpts(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function equalBytes2(e,t){if(e.length!==t.length)return!1;let a=0;for(let u=0;u<e.length;u++)a|=e[u]^t[u];return a===0}var wrapCipher=(e,t)=>(Object.assign(t,e),t),BLOCK_SIZE=16,ZEROS16=new Uint8Array(16),ZEROS32=u32(ZEROS16),POLY=225,mul2=(e,t,a,u)=>{const d=u&1;return{s3:a<<31|u>>>1,s2:t<<31|a>>>1,s1:e<<31|t>>>1,s0:e>>>1^POLY<<24&-(d&1)}},swapLE=e=>(e>>>0&255)<<24|(e>>>8&255)<<16|(e>>>16&255)<<8|e>>>24&255|0;function _toGHASHKey(e){e.reverse();const t=e[15]&1;let a=0;for(let u=0;u<e.length;u++){const d=e[u];e[u]=d>>>1|a,a=(d&1)<<7}return e[0]^=-t&225,e}var estimateWindow=e=>e>64*1024?8:e>1024?4:2,GHASH=class{constructor(e,t){this.blockLen=BLOCK_SIZE,this.outputLen=BLOCK_SIZE,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=toBytes3(e),bytes3(e,16);const a=createView3(e);let u=a.getUint32(0,!1),d=a.getUint32(4,!1),h=a.getUint32(8,!1),w=a.getUint32(12,!1);const x=[];for(let C=0;C<128;C++)x.push({s0:swapLE(u),s1:swapLE(d),s2:swapLE(h),s3:swapLE(w)}),{s0:u,s1:d,s2:h,s3:w}=mul2(u,d,h,w);const M=estimateWindow(t||1024);if(![1,2,4,8].includes(M))throw new Error(`ghash: wrong window size=${M}, should be 2, 4 or 8`);this.W=M;const E=128/M,S=this.windowSize=2**M,k=[];for(let C=0;C<E;C++)for(let D=0;D<S;D++){let O=0,F=0,P=0,L=0;for(let J=0;J<M;J++){if(!(D>>>M-J-1&1))continue;const{s0:ae,s1:oe,s2:ue,s3:se}=x[M*C+J];O^=ae,F^=oe,P^=ue,L^=se}k.push({s0:O,s1:F,s2:P,s3:L})}this.t=k}_updateBlock(e,t,a,u){e^=this.s0,t^=this.s1,a^=this.s2,u^=this.s3;const{W:d,t:h,windowSize:w}=this;let x=0,M=0,B=0,E=0;const S=(1<<d)-1;let k=0;for(const C of[e,t,a,u])for(let D=0;D<4;D++){const O=C>>>8*D&255;for(let F=8/d-1;F>=0;F--){const P=O>>>d*F&S,{s0:L,s1:J,s2:Y,s3:ae}=h[k*w+P];x^=L,M^=J,B^=Y,E^=ae,k+=1}}this.s0=x,this.s1=M,this.s2=B,this.s3=E}update(e){e=toBytes3(e),exists3(this);const t=u32(e),a=Math.floor(e.length/BLOCK_SIZE),u=e.length%BLOCK_SIZE;for(let d=0;d<a;d++)this._updateBlock(t[d*4+0],t[d*4+1],t[d*4+2],t[d*4+3]);return u&&(ZEROS16.set(e.subarray(a*BLOCK_SIZE)),this._updateBlock(ZEROS32[0],ZEROS32[1],ZEROS32[2],ZEROS32[3]),ZEROS32.fill(0)),this}destroy(){const{t:e}=this;for(const t of e)t.s0=0,t.s1=0,t.s2=0,t.s3=0}digestInto(e){exists3(this),output3(e,this),this.finished=!0;const{s0:t,s1:a,s2:u,s3:d}=this,h=u32(e);return h[0]=t,h[1]=a,h[2]=u,h[3]=d,e}digest(){const e=new Uint8Array(BLOCK_SIZE);return this.digestInto(e),this.destroy(),e}},Polyval=class extends GHASH{constructor(e,t){e=toBytes3(e);const a=_toGHASHKey(e.slice());super(a,t),a.fill(0)}update(e){e=toBytes3(e),exists3(this);const t=u32(e),a=e.length%BLOCK_SIZE,u=Math.floor(e.length/BLOCK_SIZE);for(let d=0;d<u;d++)this._updateBlock(swapLE(t[d*4+3]),swapLE(t[d*4+2]),swapLE(t[d*4+1]),swapLE(t[d*4+0]));return a&&(ZEROS16.set(e.subarray(u*BLOCK_SIZE)),this._updateBlock(swapLE(ZEROS32[3]),swapLE(ZEROS32[2]),swapLE(ZEROS32[1]),swapLE(ZEROS32[0])),ZEROS32.fill(0)),this}digestInto(e){exists3(this),output3(e,this),this.finished=!0;const{s0:t,s1:a,s2:u,s3:d}=this,h=u32(e);return h[0]=t,h[1]=a,h[2]=u,h[3]=d,e.reverse()}};function wrapConstructorWithKey(e){const t=(u,d)=>e(d,u.length).update(toBytes3(u)).digest(),a=e(new Uint8Array(16),0);return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=(u,d)=>e(u,d),t}wrapConstructorWithKey((e,t)=>new GHASH(e,t));wrapConstructorWithKey((e,t)=>new Polyval(e,t));var BLOCK_SIZE2=16,POLY2=283;function mul22(e){return e<<1^POLY2&-(e>>7)}function mul(e,t){let a=0;for(;t>0;t>>=1)a^=e&-(t&1),e=mul22(e);return a}var sbox=(()=>{let e=new Uint8Array(256);for(let a=0,u=1;a<256;a++,u^=mul22(u))e[a]=u;const t=new Uint8Array(256);t[0]=99;for(let a=0;a<255;a++){let u=e[255-a];u|=u<<8,t[e[a]]=(u^u>>4^u>>5^u>>6^u>>7^99)&255}return t})(),invSbox=sbox.map((e,t)=>sbox.indexOf(t)),rotr32_8=e=>e<<24|e>>>8,rotl32_8=e=>e<<8|e>>>24;function genTtable(e,t){if(e.length!==256)throw new Error("Wrong sbox length");const a=new Uint32Array(256).map((B,E)=>t(e[E])),u=a.map(rotl32_8),d=u.map(rotl32_8),h=d.map(rotl32_8),w=new Uint32Array(256*256),x=new Uint32Array(256*256),M=new Uint16Array(256*256);for(let B=0;B<256;B++)for(let E=0;E<256;E++){const S=B*256+E;w[S]=a[B]^u[E],x[S]=d[B]^h[E],M[S]=e[B]<<8|e[E]}return{sbox:e,sbox2:M,T0:a,T1:u,T2:d,T3:h,T01:w,T23:x}}var tableEncoding=genTtable(sbox,e=>mul(e,3)<<24|e<<16|e<<8|mul(e,2)),tableDecoding=genTtable(invSbox,e=>mul(e,11)<<24|mul(e,13)<<16|mul(e,9)<<8|mul(e,14)),xPowers=(()=>{const e=new Uint8Array(16);for(let t=0,a=1;t<16;t++,a=mul22(a))e[t]=a;return e})();function expandKeyLE(e){bytes3(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:a}=tableEncoding,u=u32(e),d=u.length,h=x=>applySbox(a,x,x,x,x),w=new Uint32Array(t+28);w.set(u);for(let x=d;x<w.length;x++){let M=w[x-1];x%d===0?M=h(rotr32_8(M))^xPowers[x/d-1]:d>6&&x%d===4&&(M=h(M)),w[x]=w[x-d]^M}return w}function expandKeyDecLE(e){const t=expandKeyLE(e),a=t.slice(),u=t.length,{sbox2:d}=tableEncoding,{T0:h,T1:w,T2:x,T3:M}=tableDecoding;for(let B=0;B<u;B+=4)for(let E=0;E<4;E++)a[B+E]=t[u-B-4+E];t.fill(0);for(let B=4;B<u-4;B++){const E=a[B],S=applySbox(d,E,E,E,E);a[B]=h[S&255]^w[S>>>8&255]^x[S>>>16&255]^M[S>>>24]}return a}function apply0123(e,t,a,u,d,h){return e[a<<8&65280|u>>>8&255]^t[d>>>8&65280|h>>>24&255]}function applySbox(e,t,a,u,d){return e[t&255|a&65280]|e[u>>>16&255|d>>>16&65280]<<16}function encrypt(e,t,a,u,d){const{sbox2:h,T01:w,T23:x}=tableEncoding;let M=0;t^=e[M++],a^=e[M++],u^=e[M++],d^=e[M++];const B=e.length/4-2;for(let D=0;D<B;D++){const O=e[M++]^apply0123(w,x,t,a,u,d),F=e[M++]^apply0123(w,x,a,u,d,t),P=e[M++]^apply0123(w,x,u,d,t,a),L=e[M++]^apply0123(w,x,d,t,a,u);t=O,a=F,u=P,d=L}const E=e[M++]^applySbox(h,t,a,u,d),S=e[M++]^applySbox(h,a,u,d,t),k=e[M++]^applySbox(h,u,d,t,a),C=e[M++]^applySbox(h,d,t,a,u);return{s0:E,s1:S,s2:k,s3:C}}function decrypt(e,t,a,u,d){const{sbox2:h,T01:w,T23:x}=tableDecoding;let M=0;t^=e[M++],a^=e[M++],u^=e[M++],d^=e[M++];const B=e.length/4-2;for(let D=0;D<B;D++){const O=e[M++]^apply0123(w,x,t,d,u,a),F=e[M++]^apply0123(w,x,a,t,d,u),P=e[M++]^apply0123(w,x,u,a,t,d),L=e[M++]^apply0123(w,x,d,u,a,t);t=O,a=F,u=P,d=L}const E=e[M++]^applySbox(h,t,d,u,a),S=e[M++]^applySbox(h,a,t,d,u),k=e[M++]^applySbox(h,u,a,t,d),C=e[M++]^applySbox(h,d,u,a,t);return{s0:E,s1:S,s2:k,s3:C}}function getDst(e,t){if(!t)return new Uint8Array(e);if(bytes3(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function validateBlockDecrypt(e){if(bytes3(e),e.length%BLOCK_SIZE2!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${BLOCK_SIZE2}`)}function validateBlockEncrypt(e,t,a){let u=e.length;const d=u%BLOCK_SIZE2;if(!t&&d!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const h=u32(e);if(t){let M=BLOCK_SIZE2-d;M||(M=BLOCK_SIZE2),u=u+M}const w=getDst(u,a),x=u32(w);return{b:h,o:x,out:w}}function validatePCKS(e,t){if(!t)return e;const a=e.length;if(!a)throw new Error("aes/pcks5: empty ciphertext not allowed");const u=e[a-1];if(u<=0||u>16)throw new Error(`aes/pcks5: wrong padding byte: ${u}`);const d=e.subarray(0,-u);for(let h=0;h<u;h++)if(e[a-h-1]!==u)throw new Error("aes/pcks5: wrong padding");return d}function padPCKS(e){const t=new Uint8Array(16),a=u32(t);t.set(e);const u=BLOCK_SIZE2-e.length;for(let d=BLOCK_SIZE2-u;d<BLOCK_SIZE2;d++)t[d]=u;return a}var cbc=wrapCipher({blockSize:16,nonceLength:16},function e(t,a,u={}){bytes3(t),bytes3(a,16);const d=!u.disablePadding;return{encrypt:(h,w)=>{const x=expandKeyLE(t),{b:M,o:B,out:E}=validateBlockEncrypt(h,d,w),S=u32(a);let k=S[0],C=S[1],D=S[2],O=S[3],F=0;for(;F+4<=M.length;)k^=M[F+0],C^=M[F+1],D^=M[F+2],O^=M[F+3],{s0:k,s1:C,s2:D,s3:O}=encrypt(x,k,C,D,O),B[F++]=k,B[F++]=C,B[F++]=D,B[F++]=O;if(d){const P=padPCKS(h.subarray(F*4));k^=P[0],C^=P[1],D^=P[2],O^=P[3],{s0:k,s1:C,s2:D,s3:O}=encrypt(x,k,C,D,O),B[F++]=k,B[F++]=C,B[F++]=D,B[F++]=O}return x.fill(0),E},decrypt:(h,w)=>{validateBlockDecrypt(h);const x=expandKeyDecLE(t),M=u32(a),B=getDst(h.length,w),E=u32(h),S=u32(B);let k=M[0],C=M[1],D=M[2],O=M[3];for(let F=0;F+4<=E.length;){const P=k,L=C,J=D,Y=O;k=E[F+0],C=E[F+1],D=E[F+2],O=E[F+3];const{s0:ae,s1:oe,s2:ue,s3:se}=decrypt(x,k,C,D,O);S[F++]=ae^P,S[F++]=oe^L,S[F++]=ue^J,S[F++]=se^Y}return x.fill(0),validatePCKS(B,d)}}}),u8to16=(e,t)=>e[t++]&255|(e[t++]&255)<<8,Poly1305=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=toBytes3(e),bytes3(e,32);const t=u8to16(e,0),a=u8to16(e,2),u=u8to16(e,4),d=u8to16(e,6),h=u8to16(e,8),w=u8to16(e,10),x=u8to16(e,12),M=u8to16(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|a<<3)&8191,this.r[2]=(a>>>10|u<<6)&7939,this.r[3]=(u>>>7|d<<9)&8191,this.r[4]=(d>>>4|h<<12)&255,this.r[5]=h>>>1&8190,this.r[6]=(h>>>14|w<<2)&8191,this.r[7]=(w>>>11|x<<5)&8065,this.r[8]=(x>>>8|M<<8)&8191,this.r[9]=M>>>5&127;for(let B=0;B<8;B++)this.pad[B]=u8to16(e,16+2*B)}process(e,t,a=!1){const u=a?0:2048,{h:d,r:h}=this,w=h[0],x=h[1],M=h[2],B=h[3],E=h[4],S=h[5],k=h[6],C=h[7],D=h[8],O=h[9],F=u8to16(e,t+0),P=u8to16(e,t+2),L=u8to16(e,t+4),J=u8to16(e,t+6),Y=u8to16(e,t+8),ae=u8to16(e,t+10),oe=u8to16(e,t+12),ue=u8to16(e,t+14);let se=d[0]+(F&8191),ie=d[1]+((F>>>13|P<<3)&8191),ce=d[2]+((P>>>10|L<<6)&8191),$=d[3]+((L>>>7|J<<9)&8191),n=d[4]+((J>>>4|Y<<12)&8191),l=d[5]+(Y>>>1&8191),c=d[6]+((Y>>>14|ae<<2)&8191),p=d[7]+((ae>>>11|oe<<5)&8191),y=d[8]+((oe>>>8|ue<<8)&8191),b=d[9]+(ue>>>5|u),_=0,v=_+se*w+ie*(5*O)+ce*(5*D)+$*(5*C)+n*(5*k);_=v>>>13,v&=8191,v+=l*(5*S)+c*(5*E)+p*(5*B)+y*(5*M)+b*(5*x),_+=v>>>13,v&=8191;let o=_+se*x+ie*w+ce*(5*O)+$*(5*D)+n*(5*C);_=o>>>13,o&=8191,o+=l*(5*k)+c*(5*S)+p*(5*E)+y*(5*B)+b*(5*M),_+=o>>>13,o&=8191;let m=_+se*M+ie*x+ce*w+$*(5*O)+n*(5*D);_=m>>>13,m&=8191,m+=l*(5*C)+c*(5*k)+p*(5*S)+y*(5*E)+b*(5*B),_+=m>>>13,m&=8191;let A=_+se*B+ie*M+ce*x+$*w+n*(5*O);_=A>>>13,A&=8191,A+=l*(5*D)+c*(5*C)+p*(5*k)+y*(5*S)+b*(5*E),_+=A>>>13,A&=8191;let I=_+se*E+ie*B+ce*M+$*x+n*w;_=I>>>13,I&=8191,I+=l*(5*O)+c*(5*D)+p*(5*C)+y*(5*k)+b*(5*S),_+=I>>>13,I&=8191;let U=_+se*S+ie*E+ce*B+$*M+n*x;_=U>>>13,U&=8191,U+=l*w+c*(5*O)+p*(5*D)+y*(5*C)+b*(5*k),_+=U>>>13,U&=8191;let X=_+se*k+ie*S+ce*E+$*B+n*M;_=X>>>13,X&=8191,X+=l*x+c*w+p*(5*O)+y*(5*D)+b*(5*C),_+=X>>>13,X&=8191;let V=_+se*C+ie*k+ce*S+$*E+n*B;_=V>>>13,V&=8191,V+=l*M+c*x+p*w+y*(5*O)+b*(5*D),_+=V>>>13,V&=8191;let T=_+se*D+ie*C+ce*k+$*S+n*E;_=T>>>13,T&=8191,T+=l*B+c*M+p*x+y*w+b*(5*O),_+=T>>>13,T&=8191;let q=_+se*O+ie*D+ce*C+$*k+n*S;_=q>>>13,q&=8191,q+=l*E+c*B+p*M+y*x+b*w,_+=q>>>13,q&=8191,_=(_<<2)+_|0,_=_+v|0,v=_&8191,_=_>>>13,o+=_,d[0]=v,d[1]=o,d[2]=m,d[3]=A,d[4]=I,d[5]=U,d[6]=X,d[7]=V,d[8]=T,d[9]=q}finalize(){const{h:e,pad:t}=this,a=new Uint16Array(10);let u=e[1]>>>13;e[1]&=8191;for(let w=2;w<10;w++)e[w]+=u,u=e[w]>>>13,e[w]&=8191;e[0]+=u*5,u=e[0]>>>13,e[0]&=8191,e[1]+=u,u=e[1]>>>13,e[1]&=8191,e[2]+=u,a[0]=e[0]+5,u=a[0]>>>13,a[0]&=8191;for(let w=1;w<10;w++)a[w]=e[w]+u,u=a[w]>>>13,a[w]&=8191;a[9]-=8192;let d=(u^1)-1;for(let w=0;w<10;w++)a[w]&=d;d=~d;for(let w=0;w<10;w++)e[w]=e[w]&d|a[w];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let h=e[0]+t[0];e[0]=h&65535;for(let w=1;w<8;w++)h=(e[w]+t[w]|0)+(h>>>16)|0,e[w]=h&65535}update(e){exists3(this);const{buffer:t,blockLen:a}=this;e=toBytes3(e);const u=e.length;for(let d=0;d<u;){const h=Math.min(a-this.pos,u-d);if(h===a){for(;a<=u-d;d+=a)this.process(e,d);continue}t.set(e.subarray(d,d+h),this.pos),this.pos+=h,d+=h,this.pos===a&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){exists3(this),output3(e,this),this.finished=!0;const{buffer:t,h:a}=this;let{pos:u}=this;if(u){for(t[u++]=1;u<16;u++)t[u]=0;this.process(t,0,!0)}this.finalize();let d=0;for(let h=0;h<8;h++)e[d++]=a[h]>>>0,e[d++]=a[h]>>>8;return e}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const a=e.slice(0,t);return this.destroy(),a}};function wrapConstructorWithKey2(e){const t=(u,d)=>e(d).update(toBytes3(u)).digest(),a=e(new Uint8Array(32));return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=u=>e(u),t}wrapConstructorWithKey2(e=>new Poly1305(e));var _utf8ToBytes=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),sigma16=_utf8ToBytes("expand 16-byte k"),sigma32=_utf8ToBytes("expand 32-byte k"),sigma16_32=u32(sigma16),sigma32_32=u32(sigma32);sigma32_32.slice();function rotl(e,t){return e<<t|e>>>32-t}function isAligned32(e){return e.byteOffset%4===0}var BLOCK_LEN=64,BLOCK_LEN32=16,MAX_COUNTER=2**32-1,U32_EMPTY=new Uint32Array;function runCipher(e,t,a,u,d,h,w,x){const M=d.length,B=new Uint8Array(BLOCK_LEN),E=u32(B),S=isAligned32(d)&&isAligned32(h),k=S?u32(d):U32_EMPTY,C=S?u32(h):U32_EMPTY;for(let D=0;D<M;w++){if(e(t,a,u,E,w,x),w>=MAX_COUNTER)throw new Error("arx: counter overflow");const O=Math.min(BLOCK_LEN,M-D);if(S&&O===BLOCK_LEN){const F=D/4;if(D%4!==0)throw new Error("arx: invalid block position");for(let P=0,L;P<BLOCK_LEN32;P++)L=F+P,C[L]=k[L]^E[P];D+=BLOCK_LEN;continue}for(let F=0,P;F<O;F++)P=D+F,h[P]=d[P]^B[F];D+=O}}function createCipher(e,t){const{allowShortKeys:a,extendNonceFn:u,counterLength:d,counterRight:h,rounds:w}=checkOpts({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return number3(d),number3(w),bool2(h),bool2(a),(x,M,B,E,S=0)=>{bytes3(x),bytes3(M),bytes3(B);const k=B.length;if(E||(E=new Uint8Array(k)),bytes3(E),number3(S),S<0||S>=MAX_COUNTER)throw new Error("arx: counter overflow");if(E.length<k)throw new Error(`arx: output (${E.length}) is shorter than data (${k})`);const C=[];let D=x.length,O,F;if(D===32)O=x.slice(),C.push(O),F=sigma32_32;else if(D===16&&a)O=new Uint8Array(32),O.set(x),O.set(x,16),F=sigma16_32,C.push(O);else throw new Error(`arx: invalid 32-byte key, got length=${D}`);isAligned32(M)||(M=M.slice(),C.push(M));const P=u32(O);if(u){if(M.length!==24)throw new Error("arx: extended nonce must be 24 bytes");u(F,P,u32(M.subarray(0,16)),P),M=M.subarray(16)}const L=16-d;if(L!==M.length)throw new Error(`arx: nonce must be ${L} or 16 bytes`);if(L!==12){const Y=new Uint8Array(12);Y.set(M,h?0:12-M.length),M=Y,C.push(M)}const J=u32(M);for(runCipher(e,F,P,J,B,E,S,w);C.length>0;)C.pop().fill(0);return E}}function chachaCore(e,t,a,u,d,h=20){let w=e[0],x=e[1],M=e[2],B=e[3],E=t[0],S=t[1],k=t[2],C=t[3],D=t[4],O=t[5],F=t[6],P=t[7],L=d,J=a[0],Y=a[1],ae=a[2],oe=w,ue=x,se=M,ie=B,ce=E,$=S,n=k,l=C,c=D,p=O,y=F,b=P,_=L,v=J,o=Y,m=ae;for(let I=0;I<h;I+=2)oe=oe+ce|0,_=rotl(_^oe,16),c=c+_|0,ce=rotl(ce^c,12),oe=oe+ce|0,_=rotl(_^oe,8),c=c+_|0,ce=rotl(ce^c,7),ue=ue+$|0,v=rotl(v^ue,16),p=p+v|0,$=rotl($^p,12),ue=ue+$|0,v=rotl(v^ue,8),p=p+v|0,$=rotl($^p,7),se=se+n|0,o=rotl(o^se,16),y=y+o|0,n=rotl(n^y,12),se=se+n|0,o=rotl(o^se,8),y=y+o|0,n=rotl(n^y,7),ie=ie+l|0,m=rotl(m^ie,16),b=b+m|0,l=rotl(l^b,12),ie=ie+l|0,m=rotl(m^ie,8),b=b+m|0,l=rotl(l^b,7),oe=oe+$|0,m=rotl(m^oe,16),y=y+m|0,$=rotl($^y,12),oe=oe+$|0,m=rotl(m^oe,8),y=y+m|0,$=rotl($^y,7),ue=ue+n|0,_=rotl(_^ue,16),b=b+_|0,n=rotl(n^b,12),ue=ue+n|0,_=rotl(_^ue,8),b=b+_|0,n=rotl(n^b,7),se=se+l|0,v=rotl(v^se,16),c=c+v|0,l=rotl(l^c,12),se=se+l|0,v=rotl(v^se,8),c=c+v|0,l=rotl(l^c,7),ie=ie+ce|0,o=rotl(o^ie,16),p=p+o|0,ce=rotl(ce^p,12),ie=ie+ce|0,o=rotl(o^ie,8),p=p+o|0,ce=rotl(ce^p,7);let A=0;u[A++]=w+oe|0,u[A++]=x+ue|0,u[A++]=M+se|0,u[A++]=B+ie|0,u[A++]=E+ce|0,u[A++]=S+$|0,u[A++]=k+n|0,u[A++]=C+l|0,u[A++]=D+c|0,u[A++]=O+p|0,u[A++]=F+y|0,u[A++]=P+b|0,u[A++]=L+_|0,u[A++]=J+v|0,u[A++]=Y+o|0,u[A++]=ae+m|0}var chacha20=createCipher(chachaCore,{counterRight:!1,counterLength:4,allowShortKeys:!1}),HMAC2=class extends Hash2{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,assert_default.hash(e);const a=toBytes2(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const u=this.blockLen,d=new Uint8Array(u);d.set(a.length>u?e.create().update(a).digest():a);for(let h=0;h<d.length;h++)d[h]^=54;this.iHash.update(d),this.oHash=e.create();for(let h=0;h<d.length;h++)d[h]^=106;this.oHash.update(d),d.fill(0)}update(e){return assert_default.exists(this),this.iHash.update(e),this}digestInto(e){assert_default.exists(this),assert_default.bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:a,finished:u,destroyed:d,blockLen:h,outputLen:w}=this;return e=e,e.finished=u,e.destroyed=d,e.blockLen=h,e.outputLen=w,e.oHash=t._cloneInto(e.oHash),e.iHash=a._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},hmac2=(e,t,a)=>new HMAC2(e,t).update(a).digest();hmac2.create=(e,t)=>new HMAC2(e,t);function extract(e,t,a){return assert_default.hash(e),hmac2(e,toBytes2(a),toBytes2(t))}var HKDF_COUNTER=new Uint8Array([0]),EMPTY_BUFFER=new Uint8Array;function expand(e,t,a,u=32){if(assert_default.hash(e),assert_default.number(u),u>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const d=Math.ceil(u/e.outputLen);a===void 0&&(a=EMPTY_BUFFER);const h=new Uint8Array(d*e.outputLen),w=hmac2.create(e,t),x=w._cloneInto(),M=new Uint8Array(w.outputLen);for(let B=0;B<d;B++)HKDF_COUNTER[0]=B+1,x.update(B===0?EMPTY_BUFFER:M).update(a).update(HKDF_COUNTER).digestInto(M),h.set(M,e.outputLen*B),w._cloneInto(x);return w.destroy(),x.destroy(),M.fill(0),HKDF_COUNTER.fill(0),h.slice(0,u)}var __defProp2=Object.defineProperty,__export2=(e,t)=>{for(var a in t)__defProp2(e,a,{get:t[a],enumerable:!0})},verifiedSymbol2=Symbol("verified"),isRecord2=e=>e instanceof Object;function validateEvent2(e){if(!isRecord2(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let a=e.tags[t];if(!Array.isArray(a))return!1;for(let u=0;u<a.length;u++)if(typeof a[u]!="string")return!1}return!0}var utils_exports2={};__export2(utils_exports2,{Queue:()=>Queue,QueueNode:()=>QueueNode,binarySearch:()=>binarySearch,bytesToHex:()=>bytesToHex2,hexToBytes:()=>hexToBytes2,insertEventIntoAscendingList:()=>insertEventIntoAscendingList,insertEventIntoDescendingList:()=>insertEventIntoDescendingList,normalizeURL:()=>normalizeURL,utf8Decoder:()=>utf8Decoder3,utf8Encoder:()=>utf8Encoder3});var utf8Decoder3=new TextDecoder("utf-8"),utf8Encoder3=new TextEncoder;function normalizeURL(e){try{e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.protocol==="http:"?t.protocol="ws:":t.protocol==="https:"&&(t.protocol="wss:"),t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch{throw new Error(`Invalid URL: ${e}`)}}function insertEventIntoDescendingList(e,t){const[a,u]=binarySearch(e,d=>t.id===d.id?0:t.created_at===d.created_at?-1:d.created_at-t.created_at);return u||e.splice(a,0,t),e}function insertEventIntoAscendingList(e,t){const[a,u]=binarySearch(e,d=>t.id===d.id?0:t.created_at===d.created_at?-1:t.created_at-d.created_at);return u||e.splice(a,0,t),e}function binarySearch(e,t){let a=0,u=e.length-1;for(;a<=u;){const d=Math.floor((a+u)/2),h=t(e[d]);if(h===0)return[d,!0];h<0?u=d-1:a=d+1}return[a,!1]}var QueueNode=class{constructor(e){_e(this,"value");_e(this,"next",null);_e(this,"prev",null);this.value=e}},Queue=class{constructor(){_e(this,"first");_e(this,"last");this.first=null,this.last=null}enqueue(e){const t=new QueueNode(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const e=this.first;return this.first=e.next,this.first&&(this.first.prev=null),e.value}},JS2=class{generateSecretKey(){return schnorr.utils.randomPrivateKey()}getPublicKey(e){return bytesToHex2(schnorr.getPublicKey(e))}finalizeEvent(e,t){const a=e;return a.pubkey=bytesToHex2(schnorr.getPublicKey(t)),a.id=getEventHash2(a),a.sig=bytesToHex2(schnorr.sign(getEventHash2(a),t)),a[verifiedSymbol2]=!0,a}verifyEvent(e){if(typeof e[verifiedSymbol2]=="boolean")return e[verifiedSymbol2];const t=getEventHash2(e);if(t!==e.id)return e[verifiedSymbol2]=!1,!1;try{const a=schnorr.verify(e.sig,t,e.pubkey);return e[verifiedSymbol2]=a,a}catch{return e[verifiedSymbol2]=!1,!1}}};function serializeEvent2(e){if(!validateEvent2(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function getEventHash2(e){let t=sha2562(utf8Encoder3.encode(serializeEvent2(e)));return bytesToHex2(t)}var i2=new JS2,generateSecretKey2=i2.generateSecretKey,getPublicKey2=i2.getPublicKey,finalizeEvent2=i2.finalizeEvent,verifyEvent2=i2.verifyEvent,kinds_exports={};__export2(kinds_exports,{Application:()=>Application,BadgeAward:()=>BadgeAward,BadgeDefinition:()=>BadgeDefinition,BlockedRelaysList:()=>BlockedRelaysList,BlossomServerList:()=>BlossomServerList,BookmarkList:()=>BookmarkList,Bookmarksets:()=>Bookmarksets,Calendar:()=>Calendar,CalendarEventRSVP:()=>CalendarEventRSVP,ChannelCreation:()=>ChannelCreation,ChannelHideMessage:()=>ChannelHideMessage,ChannelMessage:()=>ChannelMessage,ChannelMetadata:()=>ChannelMetadata,ChannelMuteUser:()=>ChannelMuteUser,ChatMessage:()=>ChatMessage,ClassifiedListing:()=>ClassifiedListing,ClientAuth:()=>ClientAuth,Comment:()=>Comment,CommunitiesList:()=>CommunitiesList,CommunityDefinition:()=>CommunityDefinition,CommunityPostApproval:()=>CommunityPostApproval,Contacts:()=>Contacts,CreateOrUpdateProduct:()=>CreateOrUpdateProduct,CreateOrUpdateStall:()=>CreateOrUpdateStall,Curationsets:()=>Curationsets,Date:()=>Date2,DirectMessageRelaysList:()=>DirectMessageRelaysList,DraftClassifiedListing:()=>DraftClassifiedListing,DraftLong:()=>DraftLong,Emojisets:()=>Emojisets,EncryptedDirectMessage:()=>EncryptedDirectMessage,EventDeletion:()=>EventDeletion,FavoriteRelays:()=>FavoriteRelays,FileMessage:()=>FileMessage,FileMetadata:()=>FileMetadata,FileServerPreference:()=>FileServerPreference,Followsets:()=>Followsets,ForumThread:()=>ForumThread,GenericRepost:()=>GenericRepost,Genericlists:()=>Genericlists,GiftWrap:()=>GiftWrap,GroupMetadata:()=>GroupMetadata,HTTPAuth:()=>HTTPAuth,Handlerinformation:()=>Handlerinformation,Handlerrecommendation:()=>Handlerrecommendation,Highlights:()=>Highlights,InterestsList:()=>InterestsList,Interestsets:()=>Interestsets,JobFeedback:()=>JobFeedback,JobRequest:()=>JobRequest,JobResult:()=>JobResult,Label:()=>Label,LightningPubRPC:()=>LightningPubRPC,LiveChatMessage:()=>LiveChatMessage,LiveEvent:()=>LiveEvent,LongFormArticle:()=>LongFormArticle,Metadata:()=>Metadata,Mutelist:()=>Mutelist,NWCWalletInfo:()=>NWCWalletInfo,NWCWalletRequest:()=>NWCWalletRequest,NWCWalletResponse:()=>NWCWalletResponse,NormalVideo:()=>NormalVideo,NostrConnect:()=>NostrConnect,OpenTimestamps:()=>OpenTimestamps,Photo:()=>Photo,Pinlist:()=>Pinlist,Poll:()=>Poll,PollResponse:()=>PollResponse,PrivateDirectMessage:()=>PrivateDirectMessage,ProblemTracker:()=>ProblemTracker,ProfileBadges:()=>ProfileBadges,PublicChatsList:()=>PublicChatsList,Reaction:()=>Reaction,RecommendRelay:()=>RecommendRelay,RelayList:()=>RelayList,RelayReview:()=>RelayReview,Relaysets:()=>Relaysets,Report:()=>Report,Reporting:()=>Reporting,Repost:()=>Repost,Seal:()=>Seal,SearchRelaysList:()=>SearchRelaysList,ShortTextNote:()=>ShortTextNote,ShortVideo:()=>ShortVideo,Time:()=>Time,UserEmojiList:()=>UserEmojiList,UserStatuses:()=>UserStatuses,Voice:()=>Voice,VoiceComment:()=>VoiceComment,Zap:()=>Zap,ZapGoal:()=>ZapGoal,ZapRequest:()=>ZapRequest,classifyKind:()=>classifyKind,isAddressableKind:()=>isAddressableKind,isEphemeralKind:()=>isEphemeralKind,isKind:()=>isKind,isRegularKind:()=>isRegularKind,isReplaceableKind:()=>isReplaceableKind});function isRegularKind(e){return e<1e4&&e!==0&&e!==3}function isReplaceableKind(e){return e===0||e===3||1e4<=e&&e<2e4}function isEphemeralKind(e){return 2e4<=e&&e<3e4}function isAddressableKind(e){return 3e4<=e&&e<4e4}function classifyKind(e){return isRegularKind(e)?"regular":isReplaceableKind(e)?"replaceable":isEphemeralKind(e)?"ephemeral":isAddressableKind(e)?"parameterized":"unknown"}function isKind(e,t){const a=t instanceof Array?t:[t];return validateEvent2(e)&&a.includes(e.kind)||!1}var Metadata=0,ShortTextNote=1,RecommendRelay=2,Contacts=3,EncryptedDirectMessage=4,EventDeletion=5,Repost=6,Reaction=7,BadgeAward=8,ChatMessage=9,ForumThread=11,Seal=13,PrivateDirectMessage=14,FileMessage=15,GenericRepost=16,Photo=20,NormalVideo=21,ShortVideo=22,ChannelCreation=40,ChannelMetadata=41,ChannelMessage=42,ChannelHideMessage=43,ChannelMuteUser=44,OpenTimestamps=1040,GiftWrap=1059,Poll=1068,FileMetadata=1063,Comment=1111,LiveChatMessage=1311,Voice=1222,VoiceComment=1244,ProblemTracker=1971,Report=1984,Reporting=1984,Label=1985,CommunityPostApproval=4550,JobRequest=5999,JobResult=6999,JobFeedback=7e3,ZapGoal=9041,ZapRequest=9734,Zap=9735,Highlights=9802,PollResponse=1018,Mutelist=1e4,Pinlist=10001,RelayList=10002,BookmarkList=10003,CommunitiesList=10004,PublicChatsList=10005,BlockedRelaysList=10006,SearchRelaysList=10007,FavoriteRelays=10012,InterestsList=10015,UserEmojiList=10030,DirectMessageRelaysList=10050,FileServerPreference=10096,BlossomServerList=10063,NWCWalletInfo=13194,LightningPubRPC=21e3,ClientAuth=22242,NWCWalletRequest=23194,NWCWalletResponse=23195,NostrConnect=24133,HTTPAuth=27235,Followsets=3e4,Genericlists=30001,Relaysets=30002,Bookmarksets=30003,Curationsets=30004,ProfileBadges=30008,BadgeDefinition=30009,Interestsets=30015,CreateOrUpdateStall=30017,CreateOrUpdateProduct=30018,LongFormArticle=30023,DraftLong=30024,Emojisets=30030,Application=30078,LiveEvent=30311,UserStatuses=30315,ClassifiedListing=30402,DraftClassifiedListing=30403,Date2=31922,Time=31923,Calendar=31924,CalendarEventRSVP=31925,RelayReview=31987,Handlerrecommendation=31989,Handlerinformation=31990,CommunityDefinition=34550,GroupMetadata=39e3;function matchFilter(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1)return!1;for(let a in e)if(a[0]==="#"){let u=a.slice(1),d=e[`#${u}`];if(d&&!t.tags.find(([h,w])=>h===a.slice(1)&&d.indexOf(w)!==-1))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function matchFilters(e,t){for(let a=0;a<e.length;a++)if(matchFilter(e[a],t))return!0;return!1}var fakejson_exports={};__export2(fakejson_exports,{getHex64:()=>getHex64,getInt:()=>getInt,getSubscriptionId:()=>getSubscriptionId,matchEventId:()=>matchEventId,matchEventKind:()=>matchEventKind,matchEventPubkey:()=>matchEventPubkey});function getHex64(e,t){let a=t.length+3,u=e.indexOf(`"${t}":`)+a,d=e.slice(u).indexOf('"')+u+1;return e.slice(d,d+64)}function getInt(e,t){let a=t.length,u=e.indexOf(`"${t}":`)+a+3,d=e.slice(u),h=Math.min(d.indexOf(","),d.indexOf("}"));return parseInt(d.slice(0,h),10)}function getSubscriptionId(e){let t=e.slice(0,22).indexOf('"EVENT"');if(t===-1)return null;let a=e.slice(t+7+1).indexOf('"');if(a===-1)return null;let u=t+7+1+a,d=e.slice(u+1,80).indexOf('"');if(d===-1)return null;let h=u+1+d;return e.slice(u+1,h)}function matchEventId(e,t){return t===getHex64(e,"id")}function matchEventPubkey(e,t){return t===getHex64(e,"pubkey")}function matchEventKind(e,t){return t===getInt(e,"kind")}var nip42_exports={};__export2(nip42_exports,{makeAuthEvent:()=>makeAuthEvent});function makeAuthEvent(e,t){return{kind:ClientAuth,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function yieldThread(){return new Promise((e,t)=>{try{if(typeof MessageChannel<"u"){const a=new MessageChannel,u=()=>{a.port1.removeEventListener("message",u),e()};a.port1.addEventListener("message",u),a.port2.postMessage(0),a.port1.start()}else typeof setImmediate<"u"?setImmediate(e):typeof setTimeout<"u"?setTimeout(e,0):e()}catch(a){console.error("during yield: ",a),t(a)}})}var alwaysTrue=e=>(e[verifiedSymbol2]=!0,!0),SendingOnClosedConnection=class extends Error{constructor(e,t){super(`Tried to send message '${e} on a closed connection to ${t}.`),this.name="SendingOnClosedConnection"}},AbstractRelay=class{constructor(e,t){_e(this,"url");_e(this,"_connected",!1);_e(this,"onclose",null);_e(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));_e(this,"onauth");_e(this,"baseEoseTimeout",4400);_e(this,"connectionTimeout",4400);_e(this,"publishTimeout",4400);_e(this,"pingFrequency",29e3);_e(this,"pingTimeout",2e4);_e(this,"resubscribeBackoff",[1e4,1e4,1e4,2e4,2e4,3e4,6e4]);_e(this,"openSubs",new Map);_e(this,"enablePing");_e(this,"enableReconnect");_e(this,"connectionTimeoutHandle");_e(this,"reconnectTimeoutHandle");_e(this,"pingIntervalHandle");_e(this,"reconnectAttempts",0);_e(this,"closedIntentionally",!1);_e(this,"connectionPromise");_e(this,"openCountRequests",new Map);_e(this,"openEventPublishes",new Map);_e(this,"ws");_e(this,"incomingMessageQueue",new Queue);_e(this,"queueRunning",!1);_e(this,"challenge");_e(this,"authPromise");_e(this,"serial",0);_e(this,"verifyEvent");_e(this,"_WebSocket");this.url=normalizeURL(e),this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation||WebSocket,this.enablePing=t.enablePing,this.enableReconnect=t.enableReconnect||!1}static async connect(e,t){const a=new AbstractRelay(e,t);return await a.connect(),a}closeAllSubscriptions(e){for(let[t,a]of this.openSubs)a.close(e);this.openSubs.clear();for(let[t,a]of this.openEventPublishes)a.reject(new Error(e));this.openEventPublishes.clear();for(let[t,a]of this.openCountRequests)a.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 a;this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0;const t=this.closedIntentionally;this.closedIntentionally=!1,(a=this.onclose)==null||a.call(this),this.enableReconnect&&!t?this.reconnect():this.closeAllSubscriptions(e)}async connect(){return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise((e,t)=>{this.connectionTimeoutHandle=setTimeout(()=>{var a;t("connection timed out"),this.connectionPromise=void 0,(a=this.onclose)==null||a.call(this),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(a){clearTimeout(this.connectionTimeoutHandle),t(a);return}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(this.connectionTimeoutHandle),this._connected=!0;const a=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const u of this.openSubs.values()){if(u.eosed=!1,a)for(let d=0;d<u.filters.length;d++)u.lastEmitted&&(u.filters[d].since=u.lastEmitted+1);u.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),e()},this.ws.onerror=a=>{clearTimeout(this.connectionTimeoutHandle),t(a.message||"websocket error"),this.handleHardClose("relay connection errored")},this.ws.onclose=a=>{clearTimeout(this.connectionTimeoutHandle),t(a.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}waitForPingPong(){return new Promise(e=>{this.ws.once("pong",()=>e(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((e,t)=>{if(!this.connectionPromise)return t(new Error(`no connection to ${this.url}, can't ping`));try{const a=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"forced-ping",oneose:()=>{e(!0),a.close()},onclose(){e(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(a){t(a)}})}async pingpong(){var e,t,a;((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(d=>setTimeout(()=>d(!1),this.pingTimeout))])||((t=this.ws)==null?void 0:t.readyState)===this._WebSocket.OPEN&&((a=this.ws)==null||a.close()))}async runQueue(){for(this.queueRunning=!0;this.handleNext()!==!1;)await yieldThread();this.queueRunning=!1}handleNext(){var a,u,d;const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const t=getSubscriptionId(e);if(t){const h=this.openSubs.get(t);if(!h)return;const w=getHex64(e,"id"),x=(a=h.alreadyHaveEvent)==null?void 0:a.call(h,w);if((u=h.receivedEvent)==null||u.call(h,this,w),x)return}try{let h=JSON.parse(e);switch(h[0]){case"EVENT":{const w=this.openSubs.get(h[1]),x=h[2];this.verifyEvent(x)&&matchFilters(w.filters,x)&&w.onevent(x),(!w.lastEmitted||w.lastEmitted<x.created_at)&&(w.lastEmitted=x.created_at);return}case"COUNT":{const w=h[1],x=h[2],M=this.openCountRequests.get(w);M&&(M.resolve(x.count),this.openCountRequests.delete(w));return}case"EOSE":{const w=this.openSubs.get(h[1]);if(!w)return;w.receivedEose();return}case"OK":{const w=h[1],x=h[2],M=h[3],B=this.openEventPublishes.get(w);B&&(clearTimeout(B.timeout),x?B.resolve(M):B.reject(new Error(M)),this.openEventPublishes.delete(w));return}case"CLOSED":{const w=h[1],x=this.openSubs.get(w);if(!x)return;x.closed=!0,x.close(h[2]);return}case"NOTICE":{this.onnotice(h[1]);return}case"AUTH":{this.challenge=h[1],this.onauth&&this.auth(this.onauth);return}default:{const w=this.openSubs.get(h[1]);(d=w==null?void 0:w.oncustom)==null||d.call(w,h);return}}}catch{return}}async send(e){if(!this.connectionPromise)throw new SendingOnClosedConnection(e,this.url);this.connectionPromise.then(()=>{var t;(t=this.ws)==null||t.send(e)})}async auth(e){const t=this.challenge;if(!t)throw new Error("can't perform auth, no challenge was received");return this.authPromise?this.authPromise:(this.authPromise=new Promise(async(a,u)=>{try{let d=await e(makeAuthEvent(this.url,t)),h=setTimeout(()=>{let w=this.openEventPublishes.get(d.id);w&&(w.reject(new Error("auth timed out")),this.openEventPublishes.delete(d.id))},this.publishTimeout);this.openEventPublishes.set(d.id,{resolve:a,reject:u,timeout:h}),this.send('["AUTH",'+JSON.stringify(d)+"]")}catch(d){console.warn("subscribe auth function failed:",d)}}),this.authPromise)}async publish(e){const t=new Promise((a,u)=>{const d=setTimeout(()=>{const h=this.openEventPublishes.get(e.id);h&&(h.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:a,reject:u,timeout:d})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),t}async count(e,t){this.serial++;const a=(t==null?void 0:t.id)||"count:"+this.serial,u=new Promise((d,h)=>{this.openCountRequests.set(a,{resolve:d,reject:h})});return this.send('["COUNT","'+a+'",'+JSON.stringify(e).substring(1)),u}subscribe(e,t){const a=this.prepareSubscription(e,t);return a.fire(),a}prepareSubscription(e,t){this.serial++;const a=t.id||(t.label?t.label+":":"sub:")+this.serial,u=new Subscription(this,a,e,t);return this.openSubs.set(a,u),u}close(){var e,t,a;this.closedIntentionally=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,(e=this.onclose)==null||e.call(this),((t=this.ws)==null?void 0:t.readyState)===this._WebSocket.OPEN&&((a=this.ws)==null||a.close())}_onmessage(e){this.incomingMessageQueue.enqueue(e.data),this.queueRunning||this.runQueue()}},Subscription=class{constructor(e,t,a,u){_e(this,"relay");_e(this,"id");_e(this,"lastEmitted");_e(this,"closed",!1);_e(this,"eosed",!1);_e(this,"filters");_e(this,"alreadyHaveEvent");_e(this,"receivedEvent");_e(this,"onevent");_e(this,"oneose");_e(this,"onclose");_e(this,"oncustom");_e(this,"eoseTimeout");_e(this,"eoseTimeoutHandle");if(a.length===0)throw new Error("subscription can't be created with zero filters");this.relay=e,this.filters=a,this.id=t,this.alreadyHaveEvent=u.alreadyHaveEvent,this.receivedEvent=u.receivedEvent,this.eoseTimeout=u.eoseTimeout||e.baseEoseTimeout,this.oneose=u.oneose,this.onclose=u.onclose,this.onevent=u.onevent||(d=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,d)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){var e;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(e=this.oneose)==null||e.call(this))}close(e="closed by caller"){var t;if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(a){if(!(a instanceof SendingOnClosedConnection))throw a}this.closed=!0}this.relay.openSubs.delete(this.id),(t=this.onclose)==null||t.call(this,e)}},_WebSocket;try{_WebSocket=WebSocket}catch{}var AbstractSimplePool=class{constructor(e){_e(this,"relays",new Map);_e(this,"seenOn",new Map);_e(this,"trackRelays",!1);_e(this,"verifyEvent");_e(this,"enablePing");_e(this,"enableReconnect");_e(this,"automaticallyAuth");_e(this,"trustedRelayURLs",new Set);_e(this,"_WebSocket");this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation,this.enablePing=e.enablePing,this.enableReconnect=e.enableReconnect||!1,this.automaticallyAuth=e.automaticallyAuth}async ensureRelay(e,t){e=normalizeURL(e);let a=this.relays.get(e);if(a||(a=new AbstractRelay(e,{verifyEvent:this.trustedRelayURLs.has(e)?alwaysTrue:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),a.onclose=()=>{a&&!a.enableReconnect&&this.relays.delete(e)},t!=null&&t.connectionTimeout&&(a.connectionTimeout=t.connectionTimeout),this.relays.set(e,a)),this.automaticallyAuth){const u=this.automaticallyAuth(e);u&&(a.onauth=u)}return await a.connect(),a}close(e){e.map(normalizeURL).forEach(t=>{var a;(a=this.relays.get(t))==null||a.close(),this.relays.delete(t)})}subscribe(e,t,a){const u=[];for(let d=0;d<e.length;d++){const h=normalizeURL(e[d]);u.find(w=>w.url===h)||u.push({url:h,filter:t})}return this.subscribeMap(u,a)}subscribeMany(e,t,a){const u=[],d=[];for(let h=0;h<e.length;h++){const w=normalizeURL(e[h]);d.indexOf(w)===-1&&(d.push(w),u.push({url:w,filter:t}))}return this.subscribeMap(u,a)}subscribeMap(e,t){const a=new Map;for(const k of e){const{url:C,filter:D}=k;a.has(C)||a.set(C,[]),a.get(C).push(D)}const u=Array.from(a.entries()).map(([k,C])=>({url:k,filters:C}));this.trackRelays&&(t.receivedEvent=(k,C)=>{let D=this.seenOn.get(C);D||(D=new Set,this.seenOn.set(C,D)),D.add(k)});const d=new Set,h=[],w=[];let x=k=>{var C;w[k]||(w[k]=!0,w.filter(D=>D).length===u.length&&((C=t.oneose)==null||C.call(t),x=()=>{}))};const M=[];let B=(k,C)=>{var D;M[k]||(x(k),M[k]=C,M.filter(O=>O).length===u.length&&((D=t.onclose)==null||D.call(t,M),B=()=>{}))};const E=k=>{var D;if((D=t.alreadyHaveEvent)!=null&&D.call(t,k))return!0;const C=d.has(k);return d.add(k),C},S=Promise.all(u.map(async({url:k,filters:C},D)=>{let O;try{O=await this.ensureRelay(k,{connectionTimeout:t.maxWait?Math.max(t.maxWait*.8,t.maxWait-1e3):void 0})}catch(P){B(D,(P==null?void 0:P.message)||String(P));return}let F=O.subscribe(C,{...t,oneose:()=>x(D),onclose:P=>{P.startsWith("auth-required: ")&&t.onauth?O.auth(t.onauth).then(()=>{O.subscribe(C,{...t,oneose:()=>x(D),onclose:L=>{B(D,L)},alreadyHaveEvent:E,eoseTimeout:t.maxWait})}).catch(L=>{B(D,`auth was required and attempted, but failed with: ${L}`)}):B(D,P)},alreadyHaveEvent:E,eoseTimeout:t.maxWait});h.push(F)}));return{async close(k){await S,h.forEach(C=>{C.close(k)})}}}subscribeEose(e,t,a){const u=this.subscribe(e,t,{...a,oneose(){u.close("closed automatically on eose")}});return u}subscribeManyEose(e,t,a){const u=this.subscribeMany(e,t,{...a,oneose(){u.close("closed automatically on eose")}});return u}async querySync(e,t,a){return new Promise(async u=>{const d=[];this.subscribeEose(e,t,{...a,onevent(h){d.push(h)},onclose(h){u(d)}})})}async get(e,t,a){t.limit=1;const u=await this.querySync(e,t,a);return u.sort((d,h)=>h.created_at-d.created_at),u[0]||null}publish(e,t,a){return e.map(normalizeURL).map(async(u,d,h)=>{if(h.indexOf(u)!==d)return Promise.reject("duplicate url");let w=await this.ensureRelay(u);return w.publish(t).catch(async x=>{if(x instanceof Error&&x.message.startsWith("auth-required: ")&&(a!=null&&a.onauth))return await w.auth(a.onauth),w.publish(t);throw x}).then(x=>{if(this.trackRelays){let M=this.seenOn.get(t.id);M||(M=new Set,this.seenOn.set(t.id,M)),M.add(w)}return x})})}listConnectionStatus(){const e=new Map;return this.relays.forEach((t,a)=>e.set(a,t.connected)),e}destroy(){this.relays.forEach(e=>e.close()),this.relays=new Map}},_WebSocket2;try{_WebSocket2=WebSocket}catch{}var SimplePool=class extends AbstractSimplePool{constructor(e){super({verifyEvent:verifyEvent2,websocketImplementation:_WebSocket2,...e})}},nip19_exports={};__export2(nip19_exports,{BECH32_REGEX:()=>BECH32_REGEX,Bech32MaxSize:()=>Bech32MaxSize,NostrTypeGuard:()=>NostrTypeGuard,decode:()=>decode,decodeNostrURI:()=>decodeNostrURI,encodeBytes:()=>encodeBytes,naddrEncode:()=>naddrEncode,neventEncode:()=>neventEncode,noteEncode:()=>noteEncode,nprofileEncode:()=>nprofileEncode,npubEncode:()=>npubEncode,nsecEncode:()=>nsecEncode});var NostrTypeGuard={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Bech32MaxSize=5e3,BECH32_REGEX=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function integerToUint8Array(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=e&255,t}function decodeNostrURI(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),decode(e)}catch{return{type:"invalid",data:null}}}function decode(e){var d,h,w,x,M,B,E;let{prefix:t,words:a}=bech32.decode(e,Bech32MaxSize),u=new Uint8Array(bech32.fromWords(a));switch(t){case"nprofile":{let S=parseTLV(u);if(!((d=S[0])!=null&&d[0]))throw new Error("missing TLV 0 for nprofile");if(S[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:bytesToHex2(S[0][0]),relays:S[1]?S[1].map(k=>utf8Decoder3.decode(k)):[]}}}case"nevent":{let S=parseTLV(u);if(!((h=S[0])!=null&&h[0]))throw new Error("missing TLV 0 for nevent");if(S[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(S[2]&&S[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(S[3]&&S[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:bytesToHex2(S[0][0]),relays:S[1]?S[1].map(k=>utf8Decoder3.decode(k)):[],author:(w=S[2])!=null&&w[0]?bytesToHex2(S[2][0]):void 0,kind:(x=S[3])!=null&&x[0]?parseInt(bytesToHex2(S[3][0]),16):void 0}}}case"naddr":{let S=parseTLV(u);if(!((M=S[0])!=null&&M[0]))throw new Error("missing TLV 0 for naddr");if(!((B=S[2])!=null&&B[0]))throw new Error("missing TLV 2 for naddr");if(S[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((E=S[3])!=null&&E[0]))throw new Error("missing TLV 3 for naddr");if(S[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:utf8Decoder3.decode(S[0][0]),pubkey:bytesToHex2(S[2][0]),kind:parseInt(bytesToHex2(S[3][0]),16),relays:S[1]?S[1].map(k=>utf8Decoder3.decode(k)):[]}}}case"nsec":return{type:t,data:u};case"npub":case"note":return{type:t,data:bytesToHex2(u)};default:throw new Error(`unknown prefix ${t}`)}}function parseTLV(e){let t={},a=e;for(;a.length>0;){let u=a[0],d=a[1],h=a.slice(2,2+d);if(a=a.slice(2+d),h.length<d)throw new Error(`not enough data to read on TLV ${u}`);t[u]=t[u]||[],t[u].push(h)}return t}function nsecEncode(e){return encodeBytes("nsec",e)}function npubEncode(e){return encodeBytes("npub",hexToBytes2(e))}function noteEncode(e){return encodeBytes("note",hexToBytes2(e))}function encodeBech32(e,t){let a=bech32.toWords(t);return bech32.encode(e,a,Bech32MaxSize)}function encodeBytes(e,t){return encodeBech32(e,t)}function nprofileEncode(e){let t=encodeTLV({0:[hexToBytes2(e.pubkey)],1:(e.relays||[]).map(a=>utf8Encoder3.encode(a))});return encodeBech32("nprofile",t)}function neventEncode(e){let t;e.kind!==void 0&&(t=integerToUint8Array(e.kind));let a=encodeTLV({0:[hexToBytes2(e.id)],1:(e.relays||[]).map(u=>utf8Encoder3.encode(u)),2:e.author?[hexToBytes2(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return encodeBech32("nevent",a)}function naddrEncode(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let a=encodeTLV({0:[utf8Encoder3.encode(e.identifier)],1:(e.relays||[]).map(u=>utf8Encoder3.encode(u)),2:[hexToBytes2(e.pubkey)],3:[new Uint8Array(t)]});return encodeBech32("naddr",a)}function encodeTLV(e){let t=[];return Object.entries(e).reverse().forEach(([a,u])=>{u.forEach(d=>{let h=new Uint8Array(d.length+2);h.set([parseInt(a)],0),h.set([d.length],1),h.set(d,2),t.push(h)})}),concatBytes3(...t)}var nip04_exports={};__export2(nip04_exports,{decrypt:()=>decrypt2,encrypt:()=>encrypt2});function encrypt2(e,t,a){const u=e instanceof Uint8Array?bytesToHex2(e):e,d=secp256k1.getSharedSecret(u,"02"+t),h=getNormalizedX(d);let w=Uint8Array.from(randomBytes2(16)),x=utf8Encoder3.encode(a),M=cbc(h,w).encrypt(x),B=base64.encode(new Uint8Array(M)),E=base64.encode(new Uint8Array(w.buffer));return`${B}?iv=${E}`}function decrypt2(e,t,a){const u=e instanceof Uint8Array?bytesToHex2(e):e;let[d,h]=a.split("?iv="),w=secp256k1.getSharedSecret(u,"02"+t),x=getNormalizedX(w),M=base64.decode(h),B=base64.decode(d),E=cbc(x,M).decrypt(B);return utf8Decoder3.decode(E)}function getNormalizedX(e){return e.slice(1,33)}var nip05_exports={};__export2(nip05_exports,{NIP05_REGEX:()=>NIP05_REGEX,isNip05:()=>isNip05,isValid:()=>isValid,queryProfile:()=>queryProfile,searchDomain:()=>searchDomain,useFetchImplementation:()=>useFetchImplementation});var NIP05_REGEX=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,isNip05=e=>NIP05_REGEX.test(e||""),_fetch;try{_fetch=fetch}catch(e){}function useFetchImplementation(e){_fetch=e}async function searchDomain(e,t=""){try{const a=`https://${e}/.well-known/nostr.json?name=${t}`,u=await _fetch(a,{redirect:"manual"});if(u.status!==200)throw Error("Wrong response code");return(await u.json()).names}catch{return{}}}async function queryProfile(e){var d;const t=e.match(NIP05_REGEX);if(!t)return null;const[,a="_",u]=t;try{const h=`https://${u}/.well-known/nostr.json?name=${a}`,w=await _fetch(h,{redirect:"manual"});if(w.status!==200)throw Error("Wrong response code");const x=await w.json(),M=x.names[a];return M?{pubkey:M,relays:(d=x.relays)==null?void 0:d[M]}:null}catch{return null}}async function isValid(e,t){const a=await queryProfile(t);return a?a.pubkey===e:!1}var nip10_exports={};__export2(nip10_exports,{parse:()=>parse});function parse(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let a,u;for(let d=e.tags.length-1;d>=0;d--){const h=e.tags[d];if(h[0]==="e"&&h[1]){const[w,x,M,B,E]=h,S={id:x,relays:M?[M]:[],author:E};if(B==="root"){t.root=S;continue}if(B==="reply"){t.reply=S;continue}if(B==="mention"){t.mentions.push(S);continue}a?u=S:a=S,t.mentions.push(S);continue}if(h[0]==="q"&&h[1]){const[w,x,M]=h;t.quotes.push({id:x,relays:M?[M]:[]})}if(h[0]==="p"&&h[1]){t.profiles.push({pubkey:h[1],relays:h[2]?[h[2]]:[]});continue}}return t.root||(t.root=u||a||t.reply),t.reply||(t.reply=a||t.root),[t.reply,t.root].forEach(d=>{if(!d)return;let h=t.mentions.indexOf(d);if(h!==-1&&t.mentions.splice(h,1),d.author){let w=t.profiles.find(x=>x.pubkey===d.author);w&&w.relays&&(d.relays||(d.relays=[]),w.relays.forEach(x=>{var M;((M=d.relays)==null?void 0:M.indexOf(x))===-1&&d.relays.push(x)}),w.relays=d.relays)}}),t.mentions.forEach(d=>{if(d.author){let h=t.profiles.find(w=>w.pubkey===d.author);h&&h.relays&&(d.relays||(d.relays=[]),h.relays.forEach(w=>{d.relays.indexOf(w)===-1&&d.relays.push(w)}),h.relays=d.relays)}}),t}var nip11_exports={};__export2(nip11_exports,{fetchRelayInformation:()=>fetchRelayInformation,useFetchImplementation:()=>useFetchImplementation2});var _fetch2;try{_fetch2=fetch}catch{}function useFetchImplementation2(e){_fetch2=e}async function fetchRelayInformation(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var nip13_exports={};__export2(nip13_exports,{fastEventHash:()=>fastEventHash,getPow:()=>getPow,minePow:()=>minePow});function getPow(e){let t=0;for(let a=0;a<64;a+=8){const u=parseInt(e.substring(a,a+8),16);if(u===0)t+=32;else{t+=Math.clz32(u);break}}return t}function minePow(e,t){let a=0;const u=e,d=["nonce",a.toString(),t.toString()];for(u.tags.push(d);;){const h=Math.floor(new Date().getTime()/1e3);if(h!==u.created_at&&(a=0,u.created_at=h),d[1]=(++a).toString(),u.id=fastEventHash(u),getPow(u.id)>=t)break}return u}function fastEventHash(e){return bytesToHex2(sha2562(utf8Encoder3.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}var nip17_exports={};__export2(nip17_exports,{unwrapEvent:()=>unwrapEvent2,unwrapManyEvents:()=>unwrapManyEvents2,wrapEvent:()=>wrapEvent2,wrapManyEvents:()=>wrapManyEvents2});var nip59_exports={};__export2(nip59_exports,{createRumor:()=>createRumor,createSeal:()=>createSeal,createWrap:()=>createWrap,unwrapEvent:()=>unwrapEvent,unwrapManyEvents:()=>unwrapManyEvents,wrapEvent:()=>wrapEvent,wrapManyEvents:()=>wrapManyEvents});var nip44_exports={};__export2(nip44_exports,{decrypt:()=>decrypt22,encrypt:()=>encrypt22,getConversationKey:()=>getConversationKey,v2:()=>v2});var minPlaintextSize=1,maxPlaintextSize=65535;function getConversationKey(e,t){const a=secp256k1.getSharedSecret(e,"02"+t).subarray(1,33);return extract(sha2562,a,"nip44-v2")}function getMessageKeys(e,t){const a=expand(sha2562,e,t,76);return{chacha_key:a.subarray(0,32),chacha_nonce:a.subarray(32,44),hmac_key:a.subarray(44,76)}}function calcPaddedLen(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,a=t<=256?32:t/8;return a*(Math.floor((e-1)/a)+1)}function writeU16BE(e){if(!Number.isSafeInteger(e)||e<minPlaintextSize||e>maxPlaintextSize)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}function pad(e){const t=utf8Encoder3.encode(e),a=t.length,u=writeU16BE(a),d=new Uint8Array(calcPaddedLen(a)-a);return concatBytes3(u,t,d)}function unpad(e){const t=new DataView(e.buffer).getUint16(0),a=e.subarray(2,2+t);if(t<minPlaintextSize||t>maxPlaintextSize||a.length!==t||e.length!==2+calcPaddedLen(t))throw new Error("invalid padding");return utf8Decoder3.decode(a)}function hmacAad(e,t,a){if(a.length!==32)throw new Error("AAD associated data must be 32 bytes");const u=concatBytes3(a,t);return hmac2(sha2562,e,u)}function decodePayload(e){if(typeof e!="string")throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if(e[0]==="#")throw new Error("unknown encryption version");let a;try{a=base64.decode(e)}catch(h){throw new Error("invalid base64: "+h.message)}const u=a.length;if(u<99||u>65603)throw new Error("invalid data length: "+u);const d=a[0];if(d!==2)throw new Error("unknown encryption version "+d);return{nonce:a.subarray(1,33),ciphertext:a.subarray(33,-32),mac:a.subarray(-32)}}function encrypt22(e,t,a=randomBytes2(32)){const{chacha_key:u,chacha_nonce:d,hmac_key:h}=getMessageKeys(t,a),w=pad(e),x=chacha20(u,d,w),M=hmacAad(h,x,a);return base64.encode(concatBytes3(new Uint8Array([2]),a,x,M))}function decrypt22(e,t){const{nonce:a,ciphertext:u,mac:d}=decodePayload(e),{chacha_key:h,chacha_nonce:w,hmac_key:x}=getMessageKeys(t,a),M=hmacAad(x,u,a);if(!equalBytes2(M,d))throw new Error("invalid MAC");const B=chacha20(h,w,u);return unpad(B)}var v2={utils:{getConversationKey,calcPaddedLen},encrypt:encrypt22,decrypt:decrypt22},TWO_DAYS=2*24*60*60,now=()=>Math.round(Date.now()/1e3),randomNow=()=>Math.round(now()-Math.random()*TWO_DAYS),nip44ConversationKey=(e,t)=>getConversationKey(e,t),nip44Encrypt=(e,t,a)=>encrypt22(JSON.stringify(e),nip44ConversationKey(t,a)),nip44Decrypt=(e,t)=>JSON.parse(decrypt22(e.content,nip44ConversationKey(t,e.pubkey)));function createRumor(e,t){const a={created_at:now(),content:"",tags:[],...e,pubkey:getPublicKey2(t)};return a.id=getEventHash2(a),a}function createSeal(e,t,a){return finalizeEvent2({kind:Seal,content:nip44Encrypt(e,t,a),created_at:randomNow(),tags:[]},t)}function createWrap(e,t){const a=generateSecretKey2();return finalizeEvent2({kind:GiftWrap,content:nip44Encrypt(e,a,t),created_at:randomNow(),tags:[["p",t]]},a)}function wrapEvent(e,t,a){const u=createRumor(e,t),d=createSeal(u,t,a);return createWrap(d,a)}function wrapManyEvents(e,t,a){if(!a||a.length===0)throw new Error("At least one recipient is required.");const u=getPublicKey2(t),d=[wrapEvent(e,t,u)];return a.forEach(h=>{d.push(wrapEvent(e,t,h))}),d}function unwrapEvent(e,t){const a=nip44Decrypt(e,t);return nip44Decrypt(a,t)}function unwrapManyEvents(e,t){let a=[];return e.forEach(u=>{a.push(unwrapEvent(u,t))}),a.sort((u,d)=>u.created_at-d.created_at),a}function createEvent(e,t,a,u){const d={created_at:Math.ceil(Date.now()/1e3),kind:PrivateDirectMessage,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:w,relayUrl:x})=>{d.tags.push(x?["p",w,x]:["p",w])}),u&&d.tags.push(["e",u.eventId,u.relayUrl||"","reply"]),a&&d.tags.push(["subject",a]),d}function wrapEvent2(e,t,a,u,d){const h=createEvent(t,a,u,d);return wrapEvent(h,e,t.publicKey)}function wrapManyEvents2(e,t,a,u,d){if(!t||t.length===0)throw new Error("At least one recipient is required.");return[{publicKey:getPublicKey2(e)},...t].map(w=>wrapEvent2(e,w,a,u,d))}var unwrapEvent2=unwrapEvent,unwrapManyEvents2=unwrapManyEvents,nip18_exports={};__export2(nip18_exports,{finishRepostEvent:()=>finishRepostEvent,getRepostedEvent:()=>getRepostedEvent,getRepostedEventPointer:()=>getRepostedEventPointer});function finishRepostEvent(e,t,a,u){var w;let d;const h=[...e.tags??[],["e",t.id,a],["p",t.pubkey]];return t.kind===ShortTextNote?d=Repost:(d=GenericRepost,h.push(["k",String(t.kind)])),finalizeEvent2({kind:d,tags:h,content:e.content===""||(w=t.tags)!=null&&w.find(x=>x[0]==="-")?"":JSON.stringify(t),created_at:e.created_at},u)}function getRepostedEventPointer(e){if(![Repost,GenericRepost].includes(e.kind))return;let t,a;for(let u=e.tags.length-1;u>=0&&(t===void 0||a===void 0);u--){const d=e.tags[u];d.length>=2&&(d[0]==="e"&&t===void 0?t=d:d[0]==="p"&&a===void 0&&(a=d))}if(t!==void 0)return{id:t[1],relays:[t[2],a==null?void 0:a[2]].filter(u=>typeof u=="string"),author:a==null?void 0:a[1]}}function getRepostedEvent(e,{skipVerification:t}={}){const a=getRepostedEventPointer(e);if(a===void 0||e.content==="")return;let u;try{u=JSON.parse(e.content)}catch{return}if(u.id===a.id&&!(!t&&!verifyEvent2(u)))return u}var nip21_exports={};__export2(nip21_exports,{NOSTR_URI_REGEX:()=>NOSTR_URI_REGEX,parse:()=>parse2,test:()=>test});var NOSTR_URI_REGEX=new RegExp(`nostr:(${BECH32_REGEX.source})`);function test(e){return typeof e=="string"&&new RegExp(`^${NOSTR_URI_REGEX.source}$`).test(e)}function parse2(e){const t=e.match(new RegExp(`^${NOSTR_URI_REGEX.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:decode(t[1])}}var nip25_exports={};__export2(nip25_exports,{finishReactionEvent:()=>finishReactionEvent,getReactedEventPointer:()=>getReactedEventPointer});function finishReactionEvent(e,t,a){const u=t.tags.filter(d=>d.length>=2&&(d[0]==="e"||d[0]==="p"));return finalizeEvent2({...e,kind:Reaction,tags:[...e.tags??[],...u,["e",t.id],["p",t.pubkey]],content:e.content??"+"},a)}function getReactedEventPointer(e){if(e.kind!==Reaction)return;let t,a;for(let u=e.tags.length-1;u>=0&&(t===void 0||a===void 0);u--){const d=e.tags[u];d.length>=2&&(d[0]==="e"&&t===void 0?t=d:d[0]==="p"&&a===void 0&&(a=d))}if(!(t===void 0||a===void 0))return{id:t[1],relays:[t[2],a[2]].filter(u=>u!==void 0),author:a[1]}}var nip27_exports={};__export2(nip27_exports,{parse:()=>parse3});var noCharacter=/\W/m,noURLCharacter=/[^\w\/] |[^\w\/]$|$|,| /m,MAX_HASHTAG_LENGTH=42;function*parse3(e){let t=[];if(typeof e!="string"){for(let h=0;h<e.tags.length;h++){const w=e.tags[h];w[0]==="emoji"&&w.length>=3&&t.push({type:"emoji",shortcode:w[1],url:w[2]})}e=e.content}const a=e.length;let u=0,d=0;e:for(;d<a;){const h=e.indexOf(":",d),w=e.indexOf("#",d);if(h===-1&&w===-1)break e;if(h===-1||w>=0&&w<h){if(w===0||e[w-1]===" "){const x=e.slice(w+1,w+MAX_HASHTAG_LENGTH).match(noCharacter),M=x?w+1+x.index:a;yield{type:"text",text:e.slice(u,w)},yield{type:"hashtag",value:e.slice(w+1,M)},d=M,u=d;continue e}d=w+1;continue e}if(e.slice(h-5,h)==="nostr"){const x=e.slice(h+60).match(noCharacter),M=x?h+60+x.index:a;try{let B,{data:E,type:S}=decode(e.slice(h+1,M));switch(S){case"npub":B={pubkey:E};break;case"note":B={id:E};break;case"nsec":d=M+1;continue;default:B=E}u!==h-5&&(yield{type:"text",text:e.slice(u,h-5)}),yield{type:"reference",pointer:B},d=M,u=d;continue e}catch{d=h+1;continue e}}else if(e.slice(h-5,h)==="https"||e.slice(h-4,h)==="http"){const x=e.slice(h+4).match(noURLCharacter),M=x?h+4+x.index:a,B=e[h-1]==="s"?5:4;try{let E=new URL(e.slice(h-B,M));if(E.hostname.indexOf(".")===-1)throw new Error("invalid url");if(u!==h-B&&(yield{type:"text",text:e.slice(u,h-B)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(E.pathname)){yield{type:"image",url:E.toString()},d=M,u=d;continue e}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(E.pathname)){yield{type:"video",url:E.toString()},d=M,u=d;continue e}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(E.pathname)){yield{type:"audio",url:E.toString()},d=M,u=d;continue e}yield{type:"url",url:E.toString()},d=M,u=d;continue e}catch{d=M+1;continue e}}else if(e.slice(h-3,h)==="wss"||e.slice(h-2,h)==="ws"){const x=e.slice(h+4).match(noURLCharacter),M=x?h+4+x.index:a,B=e[h-1]==="s"?3:2;try{let E=new URL(e.slice(h-B,M));if(E.hostname.indexOf(".")===-1)throw new Error("invalid ws url");u!==h-B&&(yield{type:"text",text:e.slice(u,h-B)}),yield{type:"relay",url:E.toString()},d=M,u=d;continue e}catch{d=M+1;continue e}}else{for(let x=0;x<t.length;x++){const M=t[x];if(e[h+M.shortcode.length+1]===":"&&e.slice(h+1,h+M.shortcode.length+1)===M.shortcode){u!==h&&(yield{type:"text",text:e.slice(u,h)}),yield M,d=h+M.shortcode.length+2,u=d;continue e}}d=h+1;continue e}}u!==a&&(yield{type:"text",text:e.slice(u)})}var nip28_exports={};__export2(nip28_exports,{channelCreateEvent:()=>channelCreateEvent,channelHideMessageEvent:()=>channelHideMessageEvent,channelMessageEvent:()=>channelMessageEvent,channelMetadataEvent:()=>channelMetadataEvent,channelMuteUserEvent:()=>channelMuteUserEvent});var channelCreateEvent=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent2({kind:ChannelCreation,tags:[...e.tags??[]],content:a,created_at:e.created_at},t)},channelMetadataEvent=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent2({kind:ChannelMetadata,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:a,created_at:e.created_at},t)},channelMessageEvent=(e,t)=>{const a=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&a.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),finalizeEvent2({kind:ChannelMessage,tags:[...a,...e.tags??[]],content:e.content,created_at:e.created_at},t)},channelHideMessageEvent=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent2({kind:ChannelHideMessage,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:a,created_at:e.created_at},t)},channelMuteUserEvent=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent2({kind:ChannelMuteUser,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:a,created_at:e.created_at},t)},nip30_exports={};__export2(nip30_exports,{EMOJI_SHORTCODE_REGEX:()=>EMOJI_SHORTCODE_REGEX,matchAll:()=>matchAll,regex:()=>regex,replaceAll:()=>replaceAll});var EMOJI_SHORTCODE_REGEX=/:(\w+):/,regex=()=>new RegExp(`\\B${EMOJI_SHORTCODE_REGEX.source}\\B`,"g");function*matchAll(e){const t=e.matchAll(regex());for(const a of t)try{const[u,d]=a;yield{shortcode:u,name:d,start:a.index,end:a.index+u.length}}catch{}}function replaceAll(e,t){return e.replaceAll(regex(),(a,u)=>t({shortcode:a,name:u}))}var nip39_exports={};__export2(nip39_exports,{useFetchImplementation:()=>useFetchImplementation3,validateGithub:()=>validateGithub});var _fetch3;try{_fetch3=fetch}catch{}function useFetchImplementation3(e){_fetch3=e}async function validateGithub(e,t,a){try{return await(await _fetch3(`https://gist.github.com/${t}/${a}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var nip47_exports={};__export2(nip47_exports,{makeNwcRequestEvent:()=>makeNwcRequestEvent,parseConnectionString:()=>parseConnectionString});function parseConnectionString(e){const{host:t,pathname:a,searchParams:u}=new URL(e),d=a||t,h=u.get("relay"),w=u.get("secret");if(!d||!h||!w)throw new Error("invalid connection string");return{pubkey:d,relay:h,secret:w}}async function makeNwcRequestEvent(e,t,a){const d=encrypt2(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:a}})),h={kind:NWCWalletRequest,created_at:Math.round(Date.now()/1e3),content:d,tags:[["p",e]]};return finalizeEvent2(h,t)}var nip54_exports={};__export2(nip54_exports,{normalizeIdentifier:()=>normalizeIdentifier});function normalizeIdentifier(e){return e=e.trim().toLowerCase(),e=e.normalize("NFKC"),Array.from(e).map(t=>new RegExp("\\p{Letter}","u").test(t)||new RegExp("\\p{Number}","u").test(t)?t:"-").join("")}var nip57_exports={};__export2(nip57_exports,{getSatoshisAmountFromBolt11:()=>getSatoshisAmountFromBolt11,getZapEndpoint:()=>getZapEndpoint,makeZapReceipt:()=>makeZapReceipt,makeZapRequest:()=>makeZapRequest,useFetchImplementation:()=>useFetchImplementation4,validateZapRequest:()=>validateZapRequest});var _fetch4;try{_fetch4=fetch}catch{}function useFetchImplementation4(e){_fetch4=e}async function getZapEndpoint(e){try{let t="",{lud06:a,lud16:u}=JSON.parse(e.content);if(u){let[w,x]=u.split("@");t=new URL(`/.well-known/lnurlp/${w}`,`https://${x}`).toString()}else if(a){let{words:w}=bech32.decode(a,1e3),x=bech32.fromWords(w);t=utf8Decoder3.decode(x)}else return null;let h=await(await _fetch4(t)).json();if(h.allowsNostr&&h.nostrPubkey)return h.callback}catch{}return null}function makeZapRequest(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),isReplaceableKind(e.event.kind)){const a=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(a)}else if(isAddressableKind(e.event.kind)){let a=e.event.tags.find(([d,h])=>d==="d"&&h);if(!a)throw new Error("d tag not found or is empty");const u=["a",`${e.event.kind}:${e.event.pubkey}:${a[1]}`];t.tags.push(u)}t.tags.push(["k",e.event.kind.toString()])}return t}function validateZapRequest(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!validateEvent2(t))return"Zap request is not a valid Nostr event.";if(!verifyEvent2(t))return"Invalid signature on zap request.";let a=t.tags.find(([h,w])=>h==="p"&&w);if(!a)return"Zap request doesn't have a 'p' tag.";if(!a[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let u=t.tags.find(([h,w])=>h==="e"&&w);return u&&!u[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([h,w])=>h==="relays"&&w)?null:"Zap request doesn't have a 'relays' tag."}function makeZapReceipt({zapRequest:e,preimage:t,bolt11:a,paidAt:u}){let d=JSON.parse(e),h=d.tags.filter(([x])=>x==="e"||x==="p"||x==="a"),w={kind:9735,created_at:Math.round(u.getTime()/1e3),content:"",tags:[...h,["P",d.pubkey],["bolt11",a],["description",e]]};return t&&w.tags.push(["preimage",t]),w}function getSatoshisAmountFromBolt11(e){if(e.length<50)return 0;e=e.substring(0,50);const t=e.lastIndexOf("1");if(t===-1)return 0;const a=e.substring(0,t);if(!a.startsWith("lnbc"))return 0;const u=a.substring(4);if(u.length<1)return 0;const d=u[u.length-1],h=d.charCodeAt(0)-48,w=h>=0&&h<=9;let x=u.length-1;if(w&&x++,x<1)return 0;const M=parseInt(u.substring(0,x));switch(d){case"m":return M*1e5;case"u":return M*100;case"n":return M/10;case"p":return M/1e4;default:return M*1e8}}var nip77_exports={};__export2(nip77_exports,{Negentropy:()=>Negentropy,NegentropyStorageVector:()=>NegentropyStorageVector,NegentropySync:()=>NegentropySync});var PROTOCOL_VERSION=97,ID_SIZE=32,FINGERPRINT_SIZE=16,Mode={Skip:0,Fingerprint:1,IdList:2},WrappedBuffer=class{constructor(e){_e(this,"_raw");_e(this,"length");typeof e=="number"?(this._raw=new Uint8Array(e),this.length=0):e instanceof Uint8Array?(this._raw=new Uint8Array(e),this.length=e.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(e){if(e instanceof WrappedBuffer&&(e=e.unwrap()),typeof e.length!="number")throw Error("bad length");const t=e.length+this.length;if(this.capacity<t){const a=this._raw,u=Math.max(this.capacity*2,t);this._raw=new Uint8Array(u),this._raw.set(a)}this._raw.set(e,this.length),this.length+=e.length}shift(){const e=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,e}shiftN(e=1){const t=this._raw.subarray(0,e);return this._raw=this._raw.subarray(e),this.length-=e,t}};function decodeVarInt(e){let t=0;for(;;){if(e.length===0)throw Error("parse ends prematurely");let a=e.shift();if(t=t<<7|a&127,!(a&128))break}return t}function encodeVarInt(e){if(e===0)return new WrappedBuffer(new Uint8Array([0]));let t=[];for(;e!==0;)t.push(e&127),e>>>=7;t.reverse();for(let a=0;a<t.length-1;a++)t[a]|=128;return new WrappedBuffer(new Uint8Array(t))}function getByte(e){return getBytes(e,1)[0]}function getBytes(e,t){if(e.length<t)throw Error("parse ends prematurely");return e.shiftN(t)}var Accumulator=class{constructor(){_e(this,"buf");this.setToZero()}setToZero(){this.buf=new Uint8Array(ID_SIZE)}add(e){let t=0,a=0,u=new DataView(this.buf.buffer),d=new DataView(e.buffer);for(let h=0;h<8;h++){let w=h*4,x=u.getUint32(w,!0),M=d.getUint32(w,!0),B=x;B+=t,B+=M,B>4294967295&&(a=1),u.setUint32(w,B&4294967295,!0),t=a,a=0}}negate(){let e=new DataView(this.buf.buffer);for(let a=0;a<8;a++){let u=a*4;e.setUint32(u,~e.getUint32(u,!0))}let t=new Uint8Array(ID_SIZE);t[0]=1,this.add(t)}getFingerprint(e){let t=new WrappedBuffer;return t.extend(this.buf),t.extend(encodeVarInt(e)),sha2562(t.unwrap()).subarray(0,FINGERPRINT_SIZE)}},NegentropyStorageVector=class{constructor(){_e(this,"items");_e(this,"sealed");this.items=[],this.sealed=!1}insert(e,t){if(this.sealed)throw Error("already sealed");const a=hexToBytes3(t);if(a.byteLength!==ID_SIZE)throw Error("bad id size for added item");this.items.push({timestamp:e,id:a})}seal(){if(this.sealed)throw Error("already sealed");this.sealed=!0,this.items.sort(itemCompare);for(let e=1;e<this.items.length;e++)if(itemCompare(this.items[e-1],this.items[e])===0)throw Error("duplicate item inserted")}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(e){if(this._checkSealed(),e>=this.items.length)throw Error("out of range");return this.items[e]}iterate(e,t,a){this._checkSealed(),this._checkBounds(e,t);for(let u=e;u<t&&a(this.items[u],u);++u);}findLowerBound(e,t,a){return this._checkSealed(),this._checkBounds(e,t),this._binarySearch(this.items,e,t,u=>itemCompare(u,a)<0)}fingerprint(e,t){let a=new Accumulator;return a.setToZero(),this.iterate(e,t,u=>(a.add(u.id),!0)),a.getFingerprint(t-e)}_checkSealed(){if(!this.sealed)throw Error("not sealed")}_checkBounds(e,t){if(e>t||t>this.items.length)throw Error("bad range")}_binarySearch(e,t,a,u){let d=a-t;for(;d>0;){let h=t,w=Math.floor(d/2);h+=w,u(e[h])?(t=++h,d-=w+1):d=w}return t}},Negentropy=class{constructor(e,t=6e4){_e(this,"storage");_e(this,"frameSizeLimit");_e(this,"lastTimestampIn");_e(this,"lastTimestampOut");if(t<4096)throw Error("frameSizeLimit too small");this.storage=e,this.frameSizeLimit=t,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(e,t){return{timestamp:e,id:t||new Uint8Array(0)}}initiate(){let e=new WrappedBuffer;return e.extend(new Uint8Array([PROTOCOL_VERSION])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),e),bytesToHex3(e.unwrap())}reconcile(e,t,a){const u=new WrappedBuffer(hexToBytes3(e));this.lastTimestampIn=this.lastTimestampOut=0;let d=new WrappedBuffer;d.extend(new Uint8Array([PROTOCOL_VERSION]));let h=getByte(u);if(h<96||h>111)throw Error("invalid negentropy protocol version byte");if(h!==PROTOCOL_VERSION)throw Error("unsupported negentropy protocol version requested: "+(h-96));let w=this.storage.size(),x=this._bound(0),M=0,B=!1;for(;u.length!==0;){let E=new WrappedBuffer,S=()=>{B&&(B=!1,E.extend(this.encodeBound(x)),E.extend(encodeVarInt(Mode.Skip)))},k=this.decodeBound(u),C=decodeVarInt(u),D=M,O=this.storage.findLowerBound(M,w,k);if(C===Mode.Skip)B=!0;else if(C===Mode.Fingerprint){let F=getBytes(u,FINGERPRINT_SIZE),P=this.storage.fingerprint(D,O);compareUint8Array(F,P)!==0?(S(),this.splitRange(D,O,k,E)):B=!0}else if(C===Mode.IdList){let F=decodeVarInt(u),P={};for(let L=0;L<F;L++){let J=getBytes(u,ID_SIZE);P[bytesToHex3(J)]=J}if(B=!0,this.storage.iterate(D,O,L=>{let J=L.id;const Y=bytesToHex3(J);return P[Y]?delete P[bytesToHex3(J)]:t==null||t(Y),!0}),a)for(let L of Object.values(P))a(bytesToHex3(L))}else throw Error("unexpected mode");if(this.exceededFrameSizeLimit(d.length+E.length)){let F=this.storage.fingerprint(O,w);d.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),d.extend(encodeVarInt(Mode.Fingerprint)),d.extend(F);break}else d.extend(E);M=O,x=k}return d.length===1?null:bytesToHex3(d.unwrap())}splitRange(e,t,a,u){let d=t-e,h=16;if(d<h*2)u.extend(this.encodeBound(a)),u.extend(encodeVarInt(Mode.IdList)),u.extend(encodeVarInt(d)),this.storage.iterate(e,t,w=>(u.extend(w.id),!0));else{let w=Math.floor(d/h),x=d%h,M=e;for(let B=0;B<h;B++){let E=w+(B<x?1:0),S=this.storage.fingerprint(M,M+E);M+=E;let k;if(M===t)k=a;else{let C,D;this.storage.iterate(M-1,M+1,(O,F)=>(F===M-1?C=O:D=O,!0)),k=this.getMinimalBound(C,D)}u.extend(this.encodeBound(k)),u.extend(encodeVarInt(Mode.Fingerprint)),u.extend(S)}}}exceededFrameSizeLimit(e){return e>this.frameSizeLimit-200}decodeTimestampIn(e){let t=decodeVarInt(e);return t=t===0?Number.MAX_VALUE:t-1,this.lastTimestampIn===Number.MAX_VALUE||t===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(t+=this.lastTimestampIn,this.lastTimestampIn=t,t)}decodeBound(e){let t=this.decodeTimestampIn(e),a=decodeVarInt(e);if(a>ID_SIZE)throw Error("bound key too long");let u=getBytes(e,a);return{timestamp:t,id:u}}encodeTimestampOut(e){if(e===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,encodeVarInt(0);let t=e;return e-=this.lastTimestampOut,this.lastTimestampOut=t,encodeVarInt(e+1)}encodeBound(e){let t=new WrappedBuffer;return t.extend(this.encodeTimestampOut(e.timestamp)),t.extend(encodeVarInt(e.id.length)),t.extend(e.id),t}getMinimalBound(e,t){if(t.timestamp!==e.timestamp)return this._bound(t.timestamp);{let a=0,u=t.id,d=e.id;for(let h=0;h<ID_SIZE&&u[h]===d[h];h++)a++;return this._bound(t.timestamp,t.id.subarray(0,a+1))}}};function compareUint8Array(e,t){for(let a=0;a<e.byteLength;a++){if(e[a]<t[a])return-1;if(e[a]>t[a])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function itemCompare(e,t){return e.timestamp===t.timestamp?compareUint8Array(e.id,t.id):e.timestamp-t.timestamp}var NegentropySync=class{constructor(e,t,a,u={}){_e(this,"relay");_e(this,"storage");_e(this,"neg");_e(this,"filter");_e(this,"subscription");_e(this,"onhave");_e(this,"onneed");this.relay=e,this.storage=t,this.neg=new Negentropy(t),this.onhave=u.onhave,this.onneed=u.onneed,this.filter=a,this.subscription=this.relay.prepareSubscription([{}],{label:u.label||"negentropy"}),this.subscription.oncustom=d=>{var h,w,x,M;switch(d[0]){case"NEG-MSG":{d.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${d}`);try{const B=this.neg.reconcile(d[2],this.onhave,this.onneed);B?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${B}"]`):(this.close(),(h=u.onclose)==null||h.call(u))}catch(B){console.error("negentropy reconcile error:",B),(w=u==null?void 0:u.onclose)==null||w.call(u,`reconcile error: ${B}`)}break}case"NEG-CLOSE":{const B=d[2];console.warn("negentropy error:",B),(x=u.onclose)==null||x.call(u,B);break}case"NEG-ERR":(M=u.onclose)==null||M.call(u)}}}async start(){const e=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${e}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}},nip98_exports={};__export2(nip98_exports,{getToken:()=>getToken,hashPayload:()=>hashPayload,unpackEventFromToken:()=>unpackEventFromToken,validateEvent:()=>validateEvent22,validateEventKind:()=>validateEventKind,validateEventMethodTag:()=>validateEventMethodTag,validateEventPayloadTag:()=>validateEventPayloadTag,validateEventTimestamp:()=>validateEventTimestamp,validateEventUrlTag:()=>validateEventUrlTag,validateToken:()=>validateToken});var _authorizationScheme="Nostr ";async function getToken(e,t,a,u=!1,d){const h={kind:HTTPAuth,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};d&&h.tags.push(["payload",hashPayload(d)]);const w=await a(h);return(u?_authorizationScheme:"")+base64.encode(utf8Encoder3.encode(JSON.stringify(w)))}async function validateToken(e,t,a){const u=await unpackEventFromToken(e).catch(h=>{throw h});return await validateEvent22(u,t,a).catch(h=>{throw h})}async function unpackEventFromToken(e){if(!e)throw new Error("Missing token");e=e.replace(_authorizationScheme,"");const t=utf8Decoder3.decode(base64.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function validateEventTimestamp(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function validateEventKind(e){return e.kind===HTTPAuth}function validateEventUrlTag(e,t){const a=e.tags.find(u=>u[0]==="u");return a?a.length>0&&a[1]===t:!1}function validateEventMethodTag(e,t){const a=e.tags.find(u=>u[0]==="method");return a?a.length>0&&a[1].toLowerCase()===t.toLowerCase():!1}function hashPayload(e){const t=sha2562(utf8Encoder3.encode(JSON.stringify(e)));return bytesToHex2(t)}function validateEventPayloadTag(e,t){const a=e.tags.find(d=>d[0]==="payload");if(!a)return!1;const u=hashPayload(t);return a.length>0&&a[1]===u}async function validateEvent22(e,t,a,u){if(!verifyEvent2(e))throw new Error("Invalid nostr event, signature invalid");if(!validateEventKind(e))throw new Error("Invalid nostr event, kind invalid");if(!validateEventTimestamp(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!validateEventUrlTag(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!validateEventMethodTag(e,a))throw new Error("Invalid nostr event, method tag invalid");if(u&&typeof u=="object"&&Object.keys(u).length>0&&!validateEventPayloadTag(e,u))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}var PRIVATE_TAG="private",PRIVATE_RECIPIENTS_TAG="privateRecipients";function parsePrivateFlag(e){if(!Array.isArray(e))return null;const t=e.find(u=>Array.isArray(u)&&u[0]===PRIVATE_TAG);if(!t||typeof t[1]!="string")return null;const a=t[1].toLowerCase();return a==="true"?!0:a==="false"?!1:null}function collectPrivateRecipients(e){return Array.isArray(e)?e.filter(t=>Array.isArray(t)&&t[0]===PRIVATE_RECIPIENTS_TAG&&typeof t[1]=="string").map(t=>t[1]):[]}var NCC02Error=class extends Error{constructor(e,t,a){super(t),this.code=e,a&&(this.cause=a)}},NCC02Resolver=class{constructor(e,t={}){if(!Array.isArray(e))throw new Error("NCC02Resolver expects an array of relay URLs.");this.relays=e,this.pool=t.pool||new SimplePool,this.ownsPool=!t.pool,this.trustedCAPubkeys=new Set(t.trustedCAPubkeys||[])}close(){this.ownsPool&&this.pool&&this.pool.close(this.relays)}async _query(e){return new Promise(t=>{const a=[],u=this.pool.subscribeMany(this.relays,[e],{onevent(d){a.push(d)},oneose(){u.close(),t(a)}})})}_freshestEvent(e){return!e||!e.length?null:e.sort((t,a)=>a.created_at!==t.created_at?a.created_at-t.created_at:t.id.localeCompare(a.id))[0]}async _queryFreshest(e){const t=await this._query(e);return this._freshestEvent(t)}async resolve(e,t,a={}){const{requireAttestation:u=!1,minLevel:d=null,standard:h="nostr-service-trust-v0.1"}=a;let w;try{w=await this._queryFreshest({kinds:[KINDS.SERVICE_RECORD],authors:[e],"#d":[t]})}catch(k){throw new NCC02Error("RELAY_ERROR",`Failed to query relay for ${t}`,k)}if(!w)throw new NCC02Error("NOT_FOUND",`No service record found for ${t}`);if(!verifyEvent2(w))throw new NCC02Error("INVALID_SIGNATURE","Service record signature verification failed");const x=Object.fromEntries(w.tags),M=Math.floor(Date.now()/1e3),B=parsePrivateFlag(w.tags);if(B===null)throw new NCC02Error("MALFORMED_RECORD","Service record is missing required tag (private)");if(!x.exp)throw new NCC02Error("MALFORMED_RECORD","Service record is missing required tag (exp)");if(x.u&&(x.u.startsWith("wss://")||x.u.startsWith("https://"))&&!x.k)throw new NCC02Error("MALFORMED_RECORD","Service record with 'https' or 'wss' endpoint must have a 'k' tag");const E=parseInt(x.exp);if(isNaN(E))throw new NCC02Error("MALFORMED_RECORD","Service record expiry tag is not a valid number");if(E<M)throw new NCC02Error("EXPIRED","Service record has expired");let S;try{S=await this._buildTrustData(w,{pubkey:e,serviceId:t,standard:h,minLevel:d})}catch(k){throw new NCC02Error("RELAY_ERROR","Failed to query relay for attestations/revocations",k)}if(u&&S.validAttestations.length===0)throw new NCC02Error("POLICY_FAILURE",`No trusted attestations meet the required policy for ${t}`);return{endpoint:x.u,fingerprint:x.k,expiry:E,attestations:S.validAttestations,attestationCount:S.validAttestations.length,isRevoked:S.isRevoked,isPrivate:B,privateRecipients:collectPrivateRecipients(w.tags),eventId:w.id,pubkey:w.pubkey,serviceEvent:w}}async _buildTrustData(e,t){const a=await this._query({kinds:[KINDS.ATTESTATION],"#e":[e.id]}),u=a.map(M=>M.id);let d=[];u.length&&(d=await this._query({kinds:[KINDS.REVOCATION],"#e":u}));const h=this._groupValidRevocations(d),w=[];let x=!1;for(const M of a){if(!this.trustedCAPubkeys.has(M.pubkey))continue;const B=Object.fromEntries(M.tags);if(B.subj!==t.pubkey||B.srv!==t.serviceId||t.standard&&B.std!==t.standard)continue;const{valid:E,revoked:S}=this._evaluateAttestation(M,B,h[M.id]);if(S){x=!0;continue}E&&(t.minLevel&&!this._isLevelSufficient(B.lvl,t.minLevel)||w.push({pubkey:M.pubkey,level:B.lvl,eventId:M.id}))}return{validAttestations:w,isRevoked:x}}_groupValidRevocations(e){const t={};for(const a of e){if(!verifyEvent2(a))continue;const d=Object.fromEntries(a.tags).e;d&&(t[d]||(t[d]=[]),t[d].push(a))}return t}_evaluateAttestation(e,t,a=[]){for(const d of a)if(d.pubkey===e.pubkey)return{valid:!1,revoked:!0};if(!verifyEvent2(e))return{valid:!1,revoked:!1};const u=Math.floor(Date.now()/1e3);if(t.nbf){const d=parseInt(t.nbf,10);if(isNaN(d)||d>u)return{valid:!1,revoked:!1}}if(t.exp){const d=parseInt(t.exp,10);if(isNaN(d)||d<u)return{valid:!1,revoked:!1}}return{valid:!0,revoked:!1}}_isLevelSufficient(e,t){const a={self:0,verified:1,hardened:2},u=e?a[e]??-1:-1,d=a[t]??0;return u>=d}verifyEndpoint(e,t){return e.fingerprint===t}};/*! Bundled license information:
22
+ https://github.com/browserify/crypto-browserify`)},cryptoBrowserify.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6},cryptoBrowserify}var cryptoBrowserifyExports=requireCryptoBrowserify();const index=getDefaultExportFromCjs$1(cryptoBrowserifyExports),nc2=_mergeNamespaces({__proto__:null,default:index},[cryptoBrowserifyExports]);var __defProp=Object.defineProperty,__export=(e,t)=>{for(var a in t)__defProp(e,a,{get:t[a],enumerable:!0})};function number(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function bytes(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function hash(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number(e.outputLen),number(e.blockLen)}function exists(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output(e,t){bytes(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}var crypto=nc2&&typeof nc2=="object"&&"webcrypto"in nc2?cryptoBrowserifyExports.webcrypto:void 0,u8a=e=>e instanceof Uint8Array,createView=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),rotr=(e,t)=>e<<32-t|e>>>t,isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE)throw new Error("Non little-endian hardware is not supported");function utf8ToBytes(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes(e){if(typeof e=="string"&&(e=utf8ToBytes(e)),!u8a(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function concatBytes(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}var Hash=class{clone(){return this._cloneInto()}};function wrapConstructor(e){const t=u=>e().update(toBytes(u)).digest(),a=e();return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=()=>e(),t}function randomBytes(e=32){if(crypto&&typeof crypto.getRandomValues=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function setBigUint64(e,t,a,u){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,a,u);const d=BigInt(32),h=BigInt(4294967295),w=Number(a>>d&h),x=Number(a&h),M=u?4:0,B=u?0:4;e.setUint32(t+M,w,u),e.setUint32(t+B,x,u)}var SHA2=class extends Hash{constructor(e,t,a,u){super(),this.blockLen=e,this.outputLen=t,this.padOffset=a,this.isLE=u,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=createView(this.buffer)}update(e){exists(this);const{view:t,buffer:a,blockLen:u}=this;e=toBytes(e);const d=e.length;for(let h=0;h<d;){const w=Math.min(u-this.pos,d-h);if(w===u){const x=createView(e);for(;u<=d-h;h+=u)this.process(x,h);continue}a.set(e.subarray(h,h+w),this.pos),this.pos+=w,h+=w,this.pos===u&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){exists(this),output(e,this),this.finished=!0;const{buffer:t,view:a,blockLen:u,isLE:d}=this;let{pos:h}=this;t[h++]=128,this.buffer.subarray(h).fill(0),this.padOffset>u-h&&(this.process(a,0),h=0);for(let E=h;E<u;E++)t[E]=0;setBigUint64(a,u-8,BigInt(this.length*8),d),this.process(a,0);const w=createView(e),x=this.outputLen;if(x%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const M=x/4,B=this.get();if(M>B.length)throw new Error("_sha2: outputLen bigger than state");for(let E=0;E<M;E++)w.setUint32(4*E,B[E],d)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const a=e.slice(0,t);return this.destroy(),a}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:a,length:u,finished:d,destroyed:h,pos:w}=this;return e.length=u,e.pos=w,e.finished=d,e.destroyed=h,u%t&&e.buffer.set(a),e}},Chi=(e,t,a)=>e&t^~e&a,Maj=(e,t,a)=>e&t^e&a^t&a,SHA256_K=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),IV=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W=new Uint32Array(64),SHA256=class extends SHA2{constructor(){super(64,32,8,!1),this.A=IV[0]|0,this.B=IV[1]|0,this.C=IV[2]|0,this.D=IV[3]|0,this.E=IV[4]|0,this.F=IV[5]|0,this.G=IV[6]|0,this.H=IV[7]|0}get(){const{A:e,B:t,C:a,D:u,E:d,F:h,G:w,H:x}=this;return[e,t,a,u,d,h,w,x]}set(e,t,a,u,d,h,w,x){this.A=e|0,this.B=t|0,this.C=a|0,this.D=u|0,this.E=d|0,this.F=h|0,this.G=w|0,this.H=x|0}process(e,t){for(let E=0;E<16;E++,t+=4)SHA256_W[E]=e.getUint32(t,!1);for(let E=16;E<64;E++){const S=SHA256_W[E-15],k=SHA256_W[E-2],C=rotr(S,7)^rotr(S,18)^S>>>3,D=rotr(k,17)^rotr(k,19)^k>>>10;SHA256_W[E]=D+SHA256_W[E-7]+C+SHA256_W[E-16]|0}let{A:a,B:u,C:d,D:h,E:w,F:x,G:M,H:B}=this;for(let E=0;E<64;E++){const S=rotr(w,6)^rotr(w,11)^rotr(w,25),k=B+S+Chi(w,x,M)+SHA256_K[E]+SHA256_W[E]|0,D=(rotr(a,2)^rotr(a,13)^rotr(a,22))+Maj(a,u,d)|0;B=M,M=x,x=w,w=h+k|0,h=d,d=u,u=a,a=k+D|0}a=a+this.A|0,u=u+this.B|0,d=d+this.C|0,h=h+this.D|0,w=w+this.E|0,x=x+this.F|0,M=M+this.G|0,B=B+this.H|0,this.set(a,u,d,h,w,x,M,B)}roundClean(){SHA256_W.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},sha256=wrapConstructor(()=>new SHA256),utils_exports={};__export(utils_exports,{bitGet:()=>bitGet,bitLen:()=>bitLen,bitMask:()=>bitMask,bitSet:()=>bitSet,bytesToHex:()=>bytesToHex,bytesToNumberBE:()=>bytesToNumberBE,bytesToNumberLE:()=>bytesToNumberLE,concatBytes:()=>concatBytes2,createHmacDrbg:()=>createHmacDrbg,ensureBytes:()=>ensureBytes,equalBytes:()=>equalBytes,hexToBytes:()=>hexToBytes,hexToNumber:()=>hexToNumber,numberToBytesBE:()=>numberToBytesBE,numberToBytesLE:()=>numberToBytesLE,numberToHexUnpadded:()=>numberToHexUnpadded,numberToVarBytesBE:()=>numberToVarBytesBE,utf8ToBytes:()=>utf8ToBytes2,validateObject:()=>validateObject});var _0n=BigInt(0),_1n=BigInt(1),_2n=BigInt(2),u8a2=e=>e instanceof Uint8Array,hexes=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex(e){if(!u8a2(e))throw new Error("Uint8Array expected");let t="";for(let a=0;a<e.length;a++)t+=hexes[e[a]];return t}function numberToHexUnpadded(e){const t=e.toString(16);return t.length&1?`0${t}`:t}function hexToNumber(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function hexToBytes(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const a=new Uint8Array(t/2);for(let u=0;u<a.length;u++){const d=u*2,h=e.slice(d,d+2),w=Number.parseInt(h,16);if(Number.isNaN(w)||w<0)throw new Error("Invalid byte sequence");a[u]=w}return a}function bytesToNumberBE(e){return hexToNumber(bytesToHex(e))}function bytesToNumberLE(e){if(!u8a2(e))throw new Error("Uint8Array expected");return hexToNumber(bytesToHex(Uint8Array.from(e).reverse()))}function numberToBytesBE(e,t){return hexToBytes(e.toString(16).padStart(t*2,"0"))}function numberToBytesLE(e,t){return numberToBytesBE(e,t).reverse()}function numberToVarBytesBE(e){return hexToBytes(numberToHexUnpadded(e))}function ensureBytes(e,t,a){let u;if(typeof t=="string")try{u=hexToBytes(t)}catch(h){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${h}`)}else if(u8a2(t))u=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const d=u.length;if(typeof a=="number"&&d!==a)throw new Error(`${e} expected ${a} bytes, got ${d}`);return u}function concatBytes2(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a2(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}function equalBytes(e,t){if(e.length!==t.length)return!1;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}function utf8ToBytes2(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function bitLen(e){let t;for(t=0;e>_0n;e>>=_1n,t+=1);return t}function bitGet(e,t){return e>>BigInt(t)&_1n}var bitSet=(e,t,a)=>e|(a?_1n:_0n)<<BigInt(t),bitMask=e=>(_2n<<BigInt(e-1))-_1n,u8n=e=>new Uint8Array(e),u8fr=e=>Uint8Array.from(e);function createHmacDrbg(e,t,a){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof a!="function")throw new Error("hmacFn must be a function");let u=u8n(e),d=u8n(e),h=0;const w=()=>{u.fill(1),d.fill(0),h=0},x=(...S)=>a(d,u,...S),M=(S=u8n())=>{d=x(u8fr([0]),S),u=x(),S.length!==0&&(d=x(u8fr([1]),S),u=x())},B=()=>{if(h++>=1e3)throw new Error("drbg: tried 1000 values");let S=0;const k=[];for(;S<t;){u=x();const C=u.slice();k.push(C),S+=u.length}return concatBytes2(...k)};return(S,k)=>{w(),M(S);let C;for(;!(C=k(B()));)M();return w(),C}}var validatorFns={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function validateObject(e,t,a={}){const u=(d,h,w)=>{const x=validatorFns[h];if(typeof x!="function")throw new Error(`Invalid validator "${h}", expected function`);const M=e[d];if(!(w&&M===void 0)&&!x(M,e))throw new Error(`Invalid param ${String(d)}=${M} (${typeof M}), expected ${h}`)};for(const[d,h]of Object.entries(t))u(d,h,!1);for(const[d,h]of Object.entries(a))u(d,h,!0);return e}var _0n2=BigInt(0),_1n2=BigInt(1),_2n2=BigInt(2),_3n=BigInt(3),_4n=BigInt(4),_5n=BigInt(5),_8n=BigInt(8);BigInt(9);BigInt(16);function mod(e,t){const a=e%t;return a>=_0n2?a:t+a}function pow(e,t,a){if(a<=_0n2||t<_0n2)throw new Error("Expected power/modulo > 0");if(a===_1n2)return _0n2;let u=_1n2;for(;t>_0n2;)t&_1n2&&(u=u*e%a),e=e*e%a,t>>=_1n2;return u}function pow2(e,t,a){let u=e;for(;t-- >_0n2;)u*=u,u%=a;return u}function invert(e,t){if(e===_0n2||t<=_0n2)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let a=mod(e,t),u=t,d=_0n2,h=_1n2;for(;a!==_0n2;){const x=u/a,M=u%a,B=d-h*x;u=a,a=M,d=h,h=B}if(u!==_1n2)throw new Error("invert: does not exist");return mod(d,t)}function tonelliShanks(e){const t=(e-_1n2)/_2n2;let a,u,d;for(a=e-_1n2,u=0;a%_2n2===_0n2;a/=_2n2,u++);for(d=_2n2;d<e&&pow(d,t,e)!==e-_1n2;d++);if(u===1){const w=(e+_1n2)/_4n;return function(M,B){const E=M.pow(B,w);if(!M.eql(M.sqr(E),B))throw new Error("Cannot find square root");return E}}const h=(a+_1n2)/_2n2;return function(x,M){if(x.pow(M,t)===x.neg(x.ONE))throw new Error("Cannot find square root");let B=u,E=x.pow(x.mul(x.ONE,d),a),S=x.pow(M,h),k=x.pow(M,a);for(;!x.eql(k,x.ONE);){if(x.eql(k,x.ZERO))return x.ZERO;let C=1;for(let O=x.sqr(k);C<B&&!x.eql(O,x.ONE);C++)O=x.sqr(O);const D=x.pow(E,_1n2<<BigInt(B-C-1));E=x.sqr(D),S=x.mul(S,D),k=x.mul(k,E),B=C}return S}}function FpSqrt(e){if(e%_4n===_3n){const t=(e+_1n2)/_4n;return function(u,d){const h=u.pow(d,t);if(!u.eql(u.sqr(h),d))throw new Error("Cannot find square root");return h}}if(e%_8n===_5n){const t=(e-_5n)/_8n;return function(u,d){const h=u.mul(d,_2n2),w=u.pow(h,t),x=u.mul(d,w),M=u.mul(u.mul(x,_2n2),w),B=u.mul(x,u.sub(M,u.ONE));if(!u.eql(u.sqr(B),d))throw new Error("Cannot find square root");return B}}return tonelliShanks(e)}var FIELD_FIELDS=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function validateField(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},a=FIELD_FIELDS.reduce((u,d)=>(u[d]="function",u),t);return validateObject(e,a)}function FpPow(e,t,a){if(a<_0n2)throw new Error("Expected power > 0");if(a===_0n2)return e.ONE;if(a===_1n2)return t;let u=e.ONE,d=t;for(;a>_0n2;)a&_1n2&&(u=e.mul(u,d)),d=e.sqr(d),a>>=_1n2;return u}function FpInvertBatch(e,t){const a=new Array(t.length),u=t.reduce((h,w,x)=>e.is0(w)?h:(a[x]=h,e.mul(h,w)),e.ONE),d=e.inv(u);return t.reduceRight((h,w,x)=>e.is0(w)?h:(a[x]=e.mul(h,a[x]),e.mul(h,w)),d),a}function nLength(e,t){const a=t!==void 0?t:e.toString(2).length,u=Math.ceil(a/8);return{nBitLength:a,nByteLength:u}}function Field(e,t,a=!1,u={}){if(e<=_0n2)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:d,nByteLength:h}=nLength(e,t);if(h>2048)throw new Error("Field lengths over 2048 bytes are not supported");const w=FpSqrt(e),x=Object.freeze({ORDER:e,BITS:d,BYTES:h,MASK:bitMask(d),ZERO:_0n2,ONE:_1n2,create:M=>mod(M,e),isValid:M=>{if(typeof M!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof M}`);return _0n2<=M&&M<e},is0:M=>M===_0n2,isOdd:M=>(M&_1n2)===_1n2,neg:M=>mod(-M,e),eql:(M,B)=>M===B,sqr:M=>mod(M*M,e),add:(M,B)=>mod(M+B,e),sub:(M,B)=>mod(M-B,e),mul:(M,B)=>mod(M*B,e),pow:(M,B)=>FpPow(x,M,B),div:(M,B)=>mod(M*invert(B,e),e),sqrN:M=>M*M,addN:(M,B)=>M+B,subN:(M,B)=>M-B,mulN:(M,B)=>M*B,inv:M=>invert(M,e),sqrt:u.sqrt||(M=>w(x,M)),invertBatch:M=>FpInvertBatch(x,M),cmov:(M,B,E)=>E?B:M,toBytes:M=>a?numberToBytesLE(M,h):numberToBytesBE(M,h),fromBytes:M=>{if(M.length!==h)throw new Error(`Fp.fromBytes: expected ${h}, got ${M.length}`);return a?bytesToNumberLE(M):bytesToNumberBE(M)}});return Object.freeze(x)}function getFieldBytesLength(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function getMinHashLength(e){const t=getFieldBytesLength(e);return t+Math.ceil(t/2)}function mapHashToField(e,t,a=!1){const u=e.length,d=getFieldBytesLength(t),h=getMinHashLength(t);if(u<16||u<h||u>1024)throw new Error(`expected ${h}-1024 bytes of input, got ${u}`);const w=a?bytesToNumberBE(e):bytesToNumberLE(e),x=mod(w,t-_1n2)+_1n2;return a?numberToBytesLE(x,d):numberToBytesBE(x,d)}var _0n3=BigInt(0),_1n3=BigInt(1);function wNAF(e,t){const a=(d,h)=>{const w=h.negate();return d?w:h},u=d=>{const h=Math.ceil(t/d)+1,w=2**(d-1);return{windows:h,windowSize:w}};return{constTimeNegate:a,unsafeLadder(d,h){let w=e.ZERO,x=d;for(;h>_0n3;)h&_1n3&&(w=w.add(x)),x=x.double(),h>>=_1n3;return w},precomputeWindow(d,h){const{windows:w,windowSize:x}=u(h),M=[];let B=d,E=B;for(let S=0;S<w;S++){E=B,M.push(E);for(let k=1;k<x;k++)E=E.add(B),M.push(E);B=E.double()}return M},wNAF(d,h,w){const{windows:x,windowSize:M}=u(d);let B=e.ZERO,E=e.BASE;const S=BigInt(2**d-1),k=2**d,C=BigInt(d);for(let D=0;D<x;D++){const O=D*M;let F=Number(w&S);w>>=C,F>M&&(F-=k,w+=_1n3);const P=O,L=O+Math.abs(F)-1,J=D%2!==0,Y=F<0;F===0?E=E.add(a(J,h[P])):B=B.add(a(Y,h[L]))}return{p:B,f:E}},wNAFCached(d,h,w,x){const M=d._WINDOW_SIZE||1;let B=h.get(d);return B||(B=this.precomputeWindow(d,M),M!==1&&h.set(d,x(B))),this.wNAF(M,B,w)}}}function validateBasic(e){return validateField(e.Fp),validateObject(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...nLength(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}function validatePointOpts(e){const t=validateBasic(e);validateObject(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:a,Fp:u,a:d}=t;if(a){if(!u.eql(d,u.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof a!="object"||typeof a.beta!="bigint"||typeof a.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:b2n,hexToBytes:h2b}=utils_exports,DER={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=DER;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const a=e[1],u=e.subarray(2,a+2);if(!a||u.length!==a)throw new t("Invalid signature integer: wrong length");if(u[0]&128)throw new t("Invalid signature integer: negative");if(u[0]===0&&!(u[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:b2n(u),l:e.subarray(a+2)}},toSig(e){const{Err:t}=DER,a=typeof e=="string"?h2b(e):e;if(!(a instanceof Uint8Array))throw new Error("ui8a expected");let u=a.length;if(u<2||a[0]!=48)throw new t("Invalid signature tag");if(a[1]!==u-2)throw new t("Invalid signature: incorrect length");const{d,l:h}=DER._parseInt(a.subarray(2)),{d:w,l:x}=DER._parseInt(h);if(x.length)throw new t("Invalid signature: left bytes after parsing");return{r:d,s:w}},hexFromSig(e){const t=B=>Number.parseInt(B[0],16)&8?"00"+B:B,a=B=>{const E=B.toString(16);return E.length&1?`0${E}`:E},u=t(a(e.s)),d=t(a(e.r)),h=u.length/2,w=d.length/2,x=a(h),M=a(w);return`30${a(w+h+4)}02${M}${d}02${x}${u}`}},_0n4=BigInt(0),_1n4=BigInt(1);BigInt(2);var _3n2=BigInt(3);BigInt(4);function weierstrassPoints(e){const t=validatePointOpts(e),{Fp:a}=t,u=t.toBytes||((D,O,F)=>{const P=O.toAffine();return concatBytes2(Uint8Array.from([4]),a.toBytes(P.x),a.toBytes(P.y))}),d=t.fromBytes||(D=>{const O=D.subarray(1),F=a.fromBytes(O.subarray(0,a.BYTES)),P=a.fromBytes(O.subarray(a.BYTES,2*a.BYTES));return{x:F,y:P}});function h(D){const{a:O,b:F}=t,P=a.sqr(D),L=a.mul(P,D);return a.add(a.add(L,a.mul(D,O)),F)}if(!a.eql(a.sqr(t.Gy),h(t.Gx)))throw new Error("bad generator point: equation left != right");function w(D){return typeof D=="bigint"&&_0n4<D&&D<t.n}function x(D){if(!w(D))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function M(D){const{allowedPrivateKeyLengths:O,nByteLength:F,wrapPrivateKey:P,n:L}=t;if(O&&typeof D!="bigint"){if(D instanceof Uint8Array&&(D=bytesToHex(D)),typeof D!="string"||!O.includes(D.length))throw new Error("Invalid key");D=D.padStart(F*2,"0")}let J;try{J=typeof D=="bigint"?D:bytesToNumberBE(ensureBytes("private key",D,F))}catch{throw new Error(`private key must be ${F} bytes, hex or bigint, not ${typeof D}`)}return P&&(J=mod(J,L)),x(J),J}const B=new Map;function E(D){if(!(D instanceof S))throw new Error("ProjectivePoint expected")}class S{constructor(O,F,P){if(this.px=O,this.py=F,this.pz=P,O==null||!a.isValid(O))throw new Error("x required");if(F==null||!a.isValid(F))throw new Error("y required");if(P==null||!a.isValid(P))throw new Error("z required")}static fromAffine(O){const{x:F,y:P}=O||{};if(!O||!a.isValid(F)||!a.isValid(P))throw new Error("invalid affine point");if(O instanceof S)throw new Error("projective point not allowed");const L=J=>a.eql(J,a.ZERO);return L(F)&&L(P)?S.ZERO:new S(F,P,a.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(O){const F=a.invertBatch(O.map(P=>P.pz));return O.map((P,L)=>P.toAffine(F[L])).map(S.fromAffine)}static fromHex(O){const F=S.fromAffine(d(ensureBytes("pointHex",O)));return F.assertValidity(),F}static fromPrivateKey(O){return S.BASE.multiply(M(O))}_setWindowSize(O){this._WINDOW_SIZE=O,B.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!a.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:O,y:F}=this.toAffine();if(!a.isValid(O)||!a.isValid(F))throw new Error("bad point: x or y not FE");const P=a.sqr(F),L=h(O);if(!a.eql(P,L))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:O}=this.toAffine();if(a.isOdd)return!a.isOdd(O);throw new Error("Field doesn't support isOdd")}equals(O){E(O);const{px:F,py:P,pz:L}=this,{px:J,py:Y,pz:ae}=O,oe=a.eql(a.mul(F,ae),a.mul(J,L)),ue=a.eql(a.mul(P,ae),a.mul(Y,L));return oe&&ue}negate(){return new S(this.px,a.neg(this.py),this.pz)}double(){const{a:O,b:F}=t,P=a.mul(F,_3n2),{px:L,py:J,pz:Y}=this;let ae=a.ZERO,oe=a.ZERO,ue=a.ZERO,se=a.mul(L,L),ie=a.mul(J,J),ce=a.mul(Y,Y),$=a.mul(L,J);return $=a.add($,$),ue=a.mul(L,Y),ue=a.add(ue,ue),ae=a.mul(O,ue),oe=a.mul(P,ce),oe=a.add(ae,oe),ae=a.sub(ie,oe),oe=a.add(ie,oe),oe=a.mul(ae,oe),ae=a.mul($,ae),ue=a.mul(P,ue),ce=a.mul(O,ce),$=a.sub(se,ce),$=a.mul(O,$),$=a.add($,ue),ue=a.add(se,se),se=a.add(ue,se),se=a.add(se,ce),se=a.mul(se,$),oe=a.add(oe,se),ce=a.mul(J,Y),ce=a.add(ce,ce),se=a.mul(ce,$),ae=a.sub(ae,se),ue=a.mul(ce,ie),ue=a.add(ue,ue),ue=a.add(ue,ue),new S(ae,oe,ue)}add(O){E(O);const{px:F,py:P,pz:L}=this,{px:J,py:Y,pz:ae}=O;let oe=a.ZERO,ue=a.ZERO,se=a.ZERO;const ie=t.a,ce=a.mul(t.b,_3n2);let $=a.mul(F,J),n=a.mul(P,Y),l=a.mul(L,ae),c=a.add(F,P),p=a.add(J,Y);c=a.mul(c,p),p=a.add($,n),c=a.sub(c,p),p=a.add(F,L);let y=a.add(J,ae);return p=a.mul(p,y),y=a.add($,l),p=a.sub(p,y),y=a.add(P,L),oe=a.add(Y,ae),y=a.mul(y,oe),oe=a.add(n,l),y=a.sub(y,oe),se=a.mul(ie,p),oe=a.mul(ce,l),se=a.add(oe,se),oe=a.sub(n,se),se=a.add(n,se),ue=a.mul(oe,se),n=a.add($,$),n=a.add(n,$),l=a.mul(ie,l),p=a.mul(ce,p),n=a.add(n,l),l=a.sub($,l),l=a.mul(ie,l),p=a.add(p,l),$=a.mul(n,p),ue=a.add(ue,$),$=a.mul(y,p),oe=a.mul(c,oe),oe=a.sub(oe,$),$=a.mul(c,n),se=a.mul(y,se),se=a.add(se,$),new S(oe,ue,se)}subtract(O){return this.add(O.negate())}is0(){return this.equals(S.ZERO)}wNAF(O){return C.wNAFCached(this,B,O,F=>{const P=a.invertBatch(F.map(L=>L.pz));return F.map((L,J)=>L.toAffine(P[J])).map(S.fromAffine)})}multiplyUnsafe(O){const F=S.ZERO;if(O===_0n4)return F;if(x(O),O===_1n4)return this;const{endo:P}=t;if(!P)return C.unsafeLadder(this,O);let{k1neg:L,k1:J,k2neg:Y,k2:ae}=P.splitScalar(O),oe=F,ue=F,se=this;for(;J>_0n4||ae>_0n4;)J&_1n4&&(oe=oe.add(se)),ae&_1n4&&(ue=ue.add(se)),se=se.double(),J>>=_1n4,ae>>=_1n4;return L&&(oe=oe.negate()),Y&&(ue=ue.negate()),ue=new S(a.mul(ue.px,P.beta),ue.py,ue.pz),oe.add(ue)}multiply(O){x(O);let F=O,P,L;const{endo:J}=t;if(J){const{k1neg:Y,k1:ae,k2neg:oe,k2:ue}=J.splitScalar(F);let{p:se,f:ie}=this.wNAF(ae),{p:ce,f:$}=this.wNAF(ue);se=C.constTimeNegate(Y,se),ce=C.constTimeNegate(oe,ce),ce=new S(a.mul(ce.px,J.beta),ce.py,ce.pz),P=se.add(ce),L=ie.add($)}else{const{p:Y,f:ae}=this.wNAF(F);P=Y,L=ae}return S.normalizeZ([P,L])[0]}multiplyAndAddUnsafe(O,F,P){const L=S.BASE,J=(ae,oe)=>oe===_0n4||oe===_1n4||!ae.equals(L)?ae.multiplyUnsafe(oe):ae.multiply(oe),Y=J(this,F).add(J(O,P));return Y.is0()?void 0:Y}toAffine(O){const{px:F,py:P,pz:L}=this,J=this.is0();O==null&&(O=J?a.ONE:a.inv(L));const Y=a.mul(F,O),ae=a.mul(P,O),oe=a.mul(L,O);if(J)return{x:a.ZERO,y:a.ZERO};if(!a.eql(oe,a.ONE))throw new Error("invZ was invalid");return{x:Y,y:ae}}isTorsionFree(){const{h:O,isTorsionFree:F}=t;if(O===_1n4)return!0;if(F)return F(S,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:O,clearCofactor:F}=t;return O===_1n4?this:F?F(S,this):this.multiplyUnsafe(t.h)}toRawBytes(O=!0){return this.assertValidity(),u(S,this,O)}toHex(O=!0){return bytesToHex(this.toRawBytes(O))}}S.BASE=new S(t.Gx,t.Gy,a.ONE),S.ZERO=new S(a.ZERO,a.ONE,a.ZERO);const k=t.nBitLength,C=wNAF(S,t.endo?Math.ceil(k/2):k);return{CURVE:t,ProjectivePoint:S,normPrivateKeyToScalar:M,weierstrassEquation:h,isWithinCurveOrder:w}}function validateOpts(e){const t=validateBasic(e);return validateObject(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function weierstrass(e){const t=validateOpts(e),{Fp:a,n:u}=t,d=a.BYTES+1,h=2*a.BYTES+1;function w(p){return _0n4<p&&p<a.ORDER}function x(p){return mod(p,u)}function M(p){return invert(p,u)}const{ProjectivePoint:B,normPrivateKeyToScalar:E,weierstrassEquation:S,isWithinCurveOrder:k}=weierstrassPoints({...t,toBytes(p,y,b){const _=y.toAffine(),v=a.toBytes(_.x),o=concatBytes2;return b?o(Uint8Array.from([y.hasEvenY()?2:3]),v):o(Uint8Array.from([4]),v,a.toBytes(_.y))},fromBytes(p){const y=p.length,b=p[0],_=p.subarray(1);if(y===d&&(b===2||b===3)){const v=bytesToNumberBE(_);if(!w(v))throw new Error("Point is not on curve");const o=S(v);let m=a.sqrt(o);const A=(m&_1n4)===_1n4;return(b&1)===1!==A&&(m=a.neg(m)),{x:v,y:m}}else if(y===h&&b===4){const v=a.fromBytes(_.subarray(0,a.BYTES)),o=a.fromBytes(_.subarray(a.BYTES,2*a.BYTES));return{x:v,y:o}}else throw new Error(`Point of length ${y} was invalid. Expected ${d} compressed bytes or ${h} uncompressed bytes`)}}),C=p=>bytesToHex(numberToBytesBE(p,t.nByteLength));function D(p){const y=u>>_1n4;return p>y}function O(p){return D(p)?x(-p):p}const F=(p,y,b)=>bytesToNumberBE(p.slice(y,b));class P{constructor(y,b,_){this.r=y,this.s=b,this.recovery=_,this.assertValidity()}static fromCompact(y){const b=t.nByteLength;return y=ensureBytes("compactSignature",y,b*2),new P(F(y,0,b),F(y,b,2*b))}static fromDER(y){const{r:b,s:_}=DER.toSig(ensureBytes("DER",y));return new P(b,_)}assertValidity(){if(!k(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!k(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(y){return new P(this.r,this.s,y)}recoverPublicKey(y){const{r:b,s:_,recovery:v}=this,o=ue(ensureBytes("msgHash",y));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");const m=v===2||v===3?b+t.n:b;if(m>=a.ORDER)throw new Error("recovery id 2 or 3 invalid");const A=v&1?"03":"02",I=B.fromHex(A+C(m)),U=M(m),X=x(-o*U),V=x(_*U),T=B.BASE.multiplyAndAddUnsafe(I,X,V);if(!T)throw new Error("point at infinify");return T.assertValidity(),T}hasHighS(){return D(this.s)}normalizeS(){return this.hasHighS()?new P(this.r,x(-this.s),this.recovery):this}toDERRawBytes(){return hexToBytes(this.toDERHex())}toDERHex(){return DER.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hexToBytes(this.toCompactHex())}toCompactHex(){return C(this.r)+C(this.s)}}const L={isValidPrivateKey(p){try{return E(p),!0}catch{return!1}},normPrivateKeyToScalar:E,randomPrivateKey:()=>{const p=getMinHashLength(t.n);return mapHashToField(t.randomBytes(p),t.n)},precompute(p=8,y=B.BASE){return y._setWindowSize(p),y.multiply(BigInt(3)),y}};function J(p,y=!0){return B.fromPrivateKey(p).toRawBytes(y)}function Y(p){const y=p instanceof Uint8Array,b=typeof p=="string",_=(y||b)&&p.length;return y?_===d||_===h:b?_===2*d||_===2*h:p instanceof B}function ae(p,y,b=!0){if(Y(p))throw new Error("first arg must be private key");if(!Y(y))throw new Error("second arg must be public key");return B.fromHex(y).multiply(E(p)).toRawBytes(b)}const oe=t.bits2int||function(p){const y=bytesToNumberBE(p),b=p.length*8-t.nBitLength;return b>0?y>>BigInt(b):y},ue=t.bits2int_modN||function(p){return x(oe(p))},se=bitMask(t.nBitLength);function ie(p){if(typeof p!="bigint")throw new Error("bigint expected");if(!(_0n4<=p&&p<se))throw new Error(`bigint expected < 2^${t.nBitLength}`);return numberToBytesBE(p,t.nByteLength)}function ce(p,y,b=$){if(["recovered","canonical"].some(Z=>Z in b))throw new Error("sign() legacy options not supported");const{hash:_,randomBytes:v}=t;let{lowS:o,prehash:m,extraEntropy:A}=b;o==null&&(o=!0),p=ensureBytes("msgHash",p),m&&(p=ensureBytes("prehashed msgHash",_(p)));const I=ue(p),U=E(y),X=[ie(U),ie(I)];if(A!=null){const Z=A===!0?v(a.BYTES):A;X.push(ensureBytes("extraEntropy",Z))}const V=concatBytes2(...X),T=I;function q(Z){const te=oe(Z);if(!k(te))return;const ee=M(te),j=B.BASE.multiply(te).toAffine(),re=x(j.x);if(re===_0n4)return;const qe=x(ee*x(T+re*U));if(qe===_0n4)return;let de=(j.x===re?0:2)|Number(j.y&_1n4),pe=qe;return o&&D(qe)&&(pe=O(qe),de^=1),new P(re,pe,de)}return{seed:V,k2sig:q}}const $={lowS:t.lowS,prehash:!1},n={lowS:t.lowS,prehash:!1};function l(p,y,b=$){const{seed:_,k2sig:v}=ce(p,y,b),o=t;return createHmacDrbg(o.hash.outputLen,o.nByteLength,o.hmac)(_,v)}B.BASE._setWindowSize(8);function c(p,y,b,_=n){var j;const v=p;if(y=ensureBytes("msgHash",y),b=ensureBytes("publicKey",b),"strict"in _)throw new Error("options.strict was renamed to lowS");const{lowS:o,prehash:m}=_;let A,I;try{if(typeof v=="string"||v instanceof Uint8Array)try{A=P.fromDER(v)}catch(re){if(!(re instanceof DER.Err))throw re;A=P.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){const{r:re,s:qe}=v;A=new P(re,qe)}else throw new Error("PARSE");I=B.fromHex(b)}catch(re){if(re.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(o&&A.hasHighS())return!1;m&&(y=t.hash(y));const{r:U,s:X}=A,V=ue(y),T=M(X),q=x(V*T),Z=x(U*T),te=(j=B.BASE.multiplyAndAddUnsafe(I,q,Z))==null?void 0:j.toAffine();return te?x(te.x)===U:!1}return{CURVE:t,getPublicKey:J,getSharedSecret:ae,sign:l,verify:c,ProjectivePoint:B,Signature:P,utils:L}}var HMAC=class extends Hash{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,hash(e);const a=toBytes(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const u=this.blockLen,d=new Uint8Array(u);d.set(a.length>u?e.create().update(a).digest():a);for(let h=0;h<d.length;h++)d[h]^=54;this.iHash.update(d),this.oHash=e.create();for(let h=0;h<d.length;h++)d[h]^=106;this.oHash.update(d),d.fill(0)}update(e){return exists(this),this.iHash.update(e),this}digestInto(e){exists(this),bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:a,finished:u,destroyed:d,blockLen:h,outputLen:w}=this;return e=e,e.finished=u,e.destroyed=d,e.blockLen=h,e.outputLen=w,e.oHash=t._cloneInto(e.oHash),e.iHash=a._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},hmac=(e,t,a)=>new HMAC(e,t).update(a).digest();hmac.create=(e,t)=>new HMAC(e,t);function getHash(e){return{hash:e,hmac:(t,...a)=>hmac(e,t,concatBytes(...a)),randomBytes}}function createCurve(e,t){const a=u=>weierstrass({...e,...getHash(u)});return Object.freeze({...a(t),create:a})}var secp256k1P=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),secp256k1N=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),_1n5=BigInt(1),_2n4=BigInt(2),divNearest=(e,t)=>(e+t/_2n4)/t;function sqrtMod(e){const t=secp256k1P,a=BigInt(3),u=BigInt(6),d=BigInt(11),h=BigInt(22),w=BigInt(23),x=BigInt(44),M=BigInt(88),B=e*e*e%t,E=B*B*e%t,S=pow2(E,a,t)*E%t,k=pow2(S,a,t)*E%t,C=pow2(k,_2n4,t)*B%t,D=pow2(C,d,t)*C%t,O=pow2(D,h,t)*D%t,F=pow2(O,x,t)*O%t,P=pow2(F,M,t)*F%t,L=pow2(P,x,t)*O%t,J=pow2(L,a,t)*E%t,Y=pow2(J,w,t)*D%t,ae=pow2(Y,u,t)*B%t,oe=pow2(ae,_2n4,t);if(!Fp.eql(Fp.sqr(oe),e))throw new Error("Cannot find square root");return oe}var Fp=Field(secp256k1P,void 0,void 0,{sqrt:sqrtMod}),secp256k1=createCurve({a:BigInt(0),b:BigInt(7),Fp,n:secp256k1N,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=secp256k1N,a=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),u=-_1n5*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),d=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),h=a,w=BigInt("0x100000000000000000000000000000000"),x=divNearest(h*e,t),M=divNearest(-u*e,t);let B=mod(e-x*a-M*d,t),E=mod(-x*u-M*h,t);const S=B>w,k=E>w;if(S&&(B=t-B),k&&(E=t-E),B>w||E>w)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:S,k1:B,k2neg:k,k2:E}}}},sha256),_0n5=BigInt(0),fe=e=>typeof e=="bigint"&&_0n5<e&&e<secp256k1P,ge=e=>typeof e=="bigint"&&_0n5<e&&e<secp256k1N,TAGGED_HASH_PREFIXES={};function taggedHash(e,...t){let a=TAGGED_HASH_PREFIXES[e];if(a===void 0){const u=sha256(Uint8Array.from(e,d=>d.charCodeAt(0)));a=concatBytes2(u,u),TAGGED_HASH_PREFIXES[e]=a}return sha256(concatBytes2(a,...t))}var pointToBytes=e=>e.toRawBytes(!0).slice(1),numTo32b=e=>numberToBytesBE(e,32),modP=e=>mod(e,secp256k1P),modN=e=>mod(e,secp256k1N),Point=secp256k1.ProjectivePoint,GmulAdd=(e,t,a)=>Point.BASE.multiplyAndAddUnsafe(e,t,a);function schnorrGetExtPubKey(e){let t=secp256k1.utils.normPrivateKeyToScalar(e),a=Point.fromPrivateKey(t);return{scalar:a.hasEvenY()?t:modN(-t),bytes:pointToBytes(a)}}function lift_x(e){if(!fe(e))throw new Error("bad x: need 0 < x < p");const t=modP(e*e),a=modP(t*e+BigInt(7));let u=sqrtMod(a);u%_2n4!==_0n5&&(u=modP(-u));const d=new Point(e,u,_1n5);return d.assertValidity(),d}function challenge(...e){return modN(bytesToNumberBE(taggedHash("BIP0340/challenge",...e)))}function schnorrGetPublicKey(e){return schnorrGetExtPubKey(e).bytes}function schnorrSign(e,t,a=randomBytes(32)){const u=ensureBytes("message",e),{bytes:d,scalar:h}=schnorrGetExtPubKey(t),w=ensureBytes("auxRand",a,32),x=numTo32b(h^bytesToNumberBE(taggedHash("BIP0340/aux",w))),M=taggedHash("BIP0340/nonce",x,d,u),B=modN(bytesToNumberBE(M));if(B===_0n5)throw new Error("sign failed: k is zero");const{bytes:E,scalar:S}=schnorrGetExtPubKey(B),k=challenge(E,d,u),C=new Uint8Array(64);if(C.set(E,0),C.set(numTo32b(modN(S+k*h)),32),!schnorrVerify(C,u,d))throw new Error("sign: Invalid signature produced");return C}function schnorrVerify(e,t,a){const u=ensureBytes("signature",e,64),d=ensureBytes("message",t),h=ensureBytes("publicKey",a,32);try{const w=lift_x(bytesToNumberBE(h)),x=bytesToNumberBE(u.subarray(0,32));if(!fe(x))return!1;const M=bytesToNumberBE(u.subarray(32,64));if(!ge(M))return!1;const B=challenge(numTo32b(x),pointToBytes(w),d),E=GmulAdd(w,M,modN(-B));return!(!E||!E.hasEvenY()||E.toAffine().x!==x)}catch{return!1}}var schnorr={getPublicKey:schnorrGetPublicKey,sign:schnorrSign,verify:schnorrVerify,utils:{randomPrivateKey:secp256k1.utils.randomPrivateKey,lift_x,pointToBytes,numberToBytesBE,bytesToNumberBE,taggedHash,mod}},crypto2=nc2&&typeof nc2=="object"&&"webcrypto"in nc2?cryptoBrowserifyExports.webcrypto:void 0,u8a3=e=>e instanceof Uint8Array,createView2=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),rotr2=(e,t)=>e<<32-t|e>>>t,isLE2=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE2)throw new Error("Non little-endian hardware is not supported");var hexes2=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex2(e){if(!u8a3(e))throw new Error("Uint8Array expected");let t="";for(let a=0;a<e.length;a++)t+=hexes2[e[a]];return t}function hexToBytes2(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const a=new Uint8Array(t/2);for(let u=0;u<a.length;u++){const d=u*2,h=e.slice(d,d+2),w=Number.parseInt(h,16);if(Number.isNaN(w)||w<0)throw new Error("Invalid byte sequence");a[u]=w}return a}function utf8ToBytes3(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes2(e){if(typeof e=="string"&&(e=utf8ToBytes3(e)),!u8a3(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function concatBytes3(...e){const t=new Uint8Array(e.reduce((u,d)=>u+d.length,0));let a=0;return e.forEach(u=>{if(!u8a3(u))throw new Error("Uint8Array expected");t.set(u,a),a+=u.length}),t}var Hash2=class{clone(){return this._cloneInto()}};function wrapConstructor2(e){const t=u=>e().update(toBytes2(u)).digest(),a=e();return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=()=>e(),t}function randomBytes2(e=32){if(crypto2&&typeof crypto2.getRandomValues=="function")return crypto2.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function number2(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function bool(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function bytes2(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function hash2(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");number2(e.outputLen),number2(e.blockLen)}function exists2(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output2(e,t){bytes2(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}var assert={number:number2,bool,bytes:bytes2,hash:hash2,exists:exists2,output:output2},assert_default=assert;function setBigUint642(e,t,a,u){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,a,u);const d=BigInt(32),h=BigInt(4294967295),w=Number(a>>d&h),x=Number(a&h),M=u?4:0,B=u?0:4;e.setUint32(t+M,w,u),e.setUint32(t+B,x,u)}var SHA22=class extends Hash2{constructor(e,t,a,u){super(),this.blockLen=e,this.outputLen=t,this.padOffset=a,this.isLE=u,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=createView2(this.buffer)}update(e){assert_default.exists(this);const{view:t,buffer:a,blockLen:u}=this;e=toBytes2(e);const d=e.length;for(let h=0;h<d;){const w=Math.min(u-this.pos,d-h);if(w===u){const x=createView2(e);for(;u<=d-h;h+=u)this.process(x,h);continue}a.set(e.subarray(h,h+w),this.pos),this.pos+=w,h+=w,this.pos===u&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){assert_default.exists(this),assert_default.output(e,this),this.finished=!0;const{buffer:t,view:a,blockLen:u,isLE:d}=this;let{pos:h}=this;t[h++]=128,this.buffer.subarray(h).fill(0),this.padOffset>u-h&&(this.process(a,0),h=0);for(let E=h;E<u;E++)t[E]=0;setBigUint642(a,u-8,BigInt(this.length*8),d),this.process(a,0);const w=createView2(e),x=this.outputLen;if(x%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const M=x/4,B=this.get();if(M>B.length)throw new Error("_sha2: outputLen bigger than state");for(let E=0;E<M;E++)w.setUint32(4*E,B[E],d)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const a=e.slice(0,t);return this.destroy(),a}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:a,length:u,finished:d,destroyed:h,pos:w}=this;return e.length=u,e.pos=w,e.finished=d,e.destroyed=h,u%t&&e.buffer.set(a),e}},Chi2=(e,t,a)=>e&t^~e&a,Maj2=(e,t,a)=>e&t^e&a^t&a,SHA256_K2=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]),IV2=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),SHA256_W2=new Uint32Array(64),SHA2562=class extends SHA22{constructor(){super(64,32,8,!1),this.A=IV2[0]|0,this.B=IV2[1]|0,this.C=IV2[2]|0,this.D=IV2[3]|0,this.E=IV2[4]|0,this.F=IV2[5]|0,this.G=IV2[6]|0,this.H=IV2[7]|0}get(){const{A:e,B:t,C:a,D:u,E:d,F:h,G:w,H:x}=this;return[e,t,a,u,d,h,w,x]}set(e,t,a,u,d,h,w,x){this.A=e|0,this.B=t|0,this.C=a|0,this.D=u|0,this.E=d|0,this.F=h|0,this.G=w|0,this.H=x|0}process(e,t){for(let E=0;E<16;E++,t+=4)SHA256_W2[E]=e.getUint32(t,!1);for(let E=16;E<64;E++){const S=SHA256_W2[E-15],k=SHA256_W2[E-2],C=rotr2(S,7)^rotr2(S,18)^S>>>3,D=rotr2(k,17)^rotr2(k,19)^k>>>10;SHA256_W2[E]=D+SHA256_W2[E-7]+C+SHA256_W2[E-16]|0}let{A:a,B:u,C:d,D:h,E:w,F:x,G:M,H:B}=this;for(let E=0;E<64;E++){const S=rotr2(w,6)^rotr2(w,11)^rotr2(w,25),k=B+S+Chi2(w,x,M)+SHA256_K2[E]+SHA256_W2[E]|0,D=(rotr2(a,2)^rotr2(a,13)^rotr2(a,22))+Maj2(a,u,d)|0;B=M,M=x,x=w,w=h+k|0,h=d,d=u,u=a,a=k+D|0}a=a+this.A|0,u=u+this.B|0,d=d+this.C|0,h=h+this.D|0,w=w+this.E|0,x=x+this.F|0,M=M+this.G|0,B=B+this.H|0,this.set(a,u,d,h,w,x,M,B)}roundClean(){SHA256_W2.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},SHA224=class extends SHA2562{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}},sha2562=wrapConstructor2(()=>new SHA2562);wrapConstructor2(()=>new SHA224);var verifiedSymbol=Symbol("verified"),isRecord=e=>e instanceof Object;function validateEvent(e){if(!isRecord(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let a=e.tags[t];if(!Array.isArray(a))return!1;for(let u=0;u<a.length;u++)if(typeof a[u]!="string")return!1}return!0}new TextDecoder("utf-8");var utf8Encoder=new TextEncoder,JS=class{generateSecretKey(){return schnorr.utils.randomPrivateKey()}getPublicKey(e){return bytesToHex2(schnorr.getPublicKey(e))}finalizeEvent(e,t){const a=e;return a.pubkey=bytesToHex2(schnorr.getPublicKey(t)),a.id=getEventHash(a),a.sig=bytesToHex2(schnorr.sign(getEventHash(a),t)),a[verifiedSymbol]=!0,a}verifyEvent(e){if(typeof e[verifiedSymbol]=="boolean")return e[verifiedSymbol];const t=getEventHash(e);if(t!==e.id)return e[verifiedSymbol]=!1,!1;try{const a=schnorr.verify(e.sig,t,e.pubkey);return e[verifiedSymbol]=a,a}catch{return e[verifiedSymbol]=!1,!1}}};function serializeEvent(e){if(!validateEvent(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function getEventHash(e){let t=sha2562(utf8Encoder.encode(serializeEvent(e)));return bytesToHex2(t)}var i=new JS;i.generateSecretKey;var getPublicKey=i.getPublicKey,finalizeEvent=i.finalizeEvent;i.verifyEvent;new TextDecoder("utf-8");new TextEncoder;var KINDS={SERVICE_RECORD:30059,ATTESTATION:30060,REVOCATION:30061},NCC02Builder=class{constructor(e){if(!e)throw new Error("Signer or private key is required");this.signer=this._normalizeSigner(e),this._pubkeyPromise=this.signer.getPublicKey(),this._pubkey=void 0}async _getPublicKey(){return this._pubkey||(this._pubkey=await this._pubkeyPromise),this._pubkey}async _finalizeEvent(e){const t=await this._getPublicKey(),a={...e,pubkey:t},u=await this.signer.signEvent(a);if(!u||typeof u.id!="string"||typeof u.sig!="string")throw new Error("Signer must return a signed event with id and sig");return u}_normalizeSigner(e){if(typeof e=="string"||e instanceof Uint8Array){const t=typeof e=="string"?hexToBytes2(e):e,a=getPublicKey(t);return{getPublicKey:async()=>a,signEvent:async u=>{const d={...u,tags:Array.isArray(u.tags)?u.tags.map(h=>[...h]):[]};return finalizeEvent(d,t)}}}if(typeof e=="object"&&e!==null&&typeof e.getPublicKey=="function"&&typeof e.signEvent=="function")return{getPublicKey:async()=>{const t=await e.getPublicKey();if(typeof t!="string")throw new Error("Signer.getPublicKey must return a hex string");return t},signEvent:async t=>{const a=await e.signEvent(t);if(!a||typeof a.id!="string"||typeof a.sig!="string")throw new Error("Signer.signEvent must return a signed event");return a},decryptEvent:typeof e.decryptEvent=="function"?e.decryptEvent.bind(e):void 0};throw new Error("Unsupported signer provided to NCC02Builder")}async createServiceRecord(e){const{serviceId:t,endpoint:a,fingerprint:u,expiryDays:d=14,isPrivate:h=!1,privateRecipients:w}=e;if(!t)throw new Error("serviceId (d tag) is required");if(typeof h!="boolean")throw new Error("isPrivate must be a boolean value");const x=Math.floor(Date.now()/1e3)+d*24*60*60,M=[["d",t],["exp",x.toString()]];if(M.push(["private",h?"true":"false"]),a&&M.push(["u",a]),u&&M.push(["k",u]),w){if(!Array.isArray(w))throw new Error("privateRecipients must be an array");w.forEach(E=>{if(typeof E!="string")throw new Error("privateRecipients entries must be strings");M.push(["privateRecipients",E])})}const B={kind:KINDS.SERVICE_RECORD,created_at:Math.floor(Date.now()/1e3),tags:M,content:`NCC-02 Service Record for ${t}`};return this._finalizeEvent(B)}async createAttestation(e){const{subjectPubkey:t,serviceId:a,serviceEventId:u,level:d="verified",validDays:h=30}=e;if(!t)throw new Error("subjectPubkey is required");if(!a)throw new Error("serviceId is required");if(!u)throw new Error("serviceEventId (e tag) is required");const w=Math.floor(Date.now()/1e3),x=w+h*24*60*60,M={kind:KINDS.ATTESTATION,created_at:w,tags:[["subj",t],["srv",a],["e",u],["std","nostr-service-trust-v0.1"],["lvl",d],["nbf",w.toString()],["exp",x.toString()]],content:"NCC-02 Attestation"};return this._finalizeEvent(M)}async createRevocation(e){const{attestationId:t,reason:a=""}=e;if(!t)throw new Error("attestationId (e tag) is required");const u=[["e",t]];a&&u.push(["reason",a]);const d={kind:KINDS.REVOCATION,created_at:Math.floor(Date.now()/1e3),tags:u,content:"NCC-02 Revocation"};return this._finalizeEvent(d)}};function assertNumber(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function chain(...e){const t=(d,h)=>w=>d(h(w)),a=Array.from(e).reverse().reduce((d,h)=>d?t(d,h.encode):h.encode,void 0),u=e.reduce((d,h)=>d?t(d,h.decode):h.decode,void 0);return{encode:a,decode:u}}function alphabet(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return t.map(a=>{if(assertNumber(a),a<0||a>=e.length)throw new Error(`Digit index outside alphabet: ${a} (alphabet: ${e.length})`);return e[a]})},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("alphabet.decode input should be array of strings");return t.map(a=>{if(typeof a!="string")throw new Error(`alphabet.decode: not string element=${a}`);const u=e.indexOf(a);if(u===-1)throw new Error(`Unknown letter: "${a}". Allowed: ${e}`);return u})}}}function join(e=""){if(typeof e!="string")throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="string")throw new Error("join.encode input should be array of strings");for(let a of t)if(typeof a!="string")throw new Error(`join.encode: non-string input=${a}`);return t.join(e)},decode:t=>{if(typeof t!="string")throw new Error("join.decode input should be string");return t.split(e)}}}function padding(e,t="="){if(assertNumber(e),typeof t!="string")throw new Error("padding chr should be string");return{encode(a){if(!Array.isArray(a)||a.length&&typeof a[0]!="string")throw new Error("padding.encode input should be array of strings");for(let u of a)if(typeof u!="string")throw new Error(`padding.encode: non-string input=${u}`);for(;a.length*e%8;)a.push(t);return a},decode(a){if(!Array.isArray(a)||a.length&&typeof a[0]!="string")throw new Error("padding.encode input should be array of strings");for(let d of a)if(typeof d!="string")throw new Error(`padding.decode: non-string input=${d}`);let u=a.length;if(u*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;u>0&&a[u-1]===t;u--)if(!((u-1)*e%8))throw new Error("Invalid padding: string has too much padding");return a.slice(0,u)}}}function normalize(e){if(typeof e!="function")throw new Error("normalize fn should be function");return{encode:t=>t,decode:t=>e(t)}}function convertRadix(e,t,a){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(a<2)throw new Error(`convertRadix: wrong to=${a}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let u=0;const d=[],h=Array.from(e);for(h.forEach(w=>{if(assertNumber(w),w<0||w>=t)throw new Error(`Wrong integer: ${w}`)});;){let w=0,x=!0;for(let M=u;M<h.length;M++){const B=h[M],E=t*w+B;if(!Number.isSafeInteger(E)||t*w/t!==w||E-B!==t*w)throw new Error("convertRadix: carry overflow");if(w=E%a,h[M]=Math.floor(E/a),!Number.isSafeInteger(h[M])||h[M]*a+w!==E)throw new Error("convertRadix: carry overflow");if(x)h[M]?x=!1:u=M;else continue}if(d.push(w),x)break}for(let w=0;w<e.length-1&&e[w]===0;w++)d.push(0);return d.reverse()}var gcd=(e,t)=>t?gcd(t,e%t):e,radix2carry=(e,t)=>e+(t-gcd(e,t));function convertRadix2(e,t,a,u){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(a<=0||a>32)throw new Error(`convertRadix2: wrong to=${a}`);if(radix2carry(t,a)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${a} carryBits=${radix2carry(t,a)}`);let d=0,h=0;const w=2**a-1,x=[];for(const M of e){if(assertNumber(M),M>=2**t)throw new Error(`convertRadix2: invalid data word=${M} from=${t}`);if(d=d<<t|M,h+t>32)throw new Error(`convertRadix2: carry overflow pos=${h} from=${t}`);for(h+=t;h>=a;h-=a)x.push((d>>h-a&w)>>>0);d&=2**h-1}if(d=d<<a-h&w,!u&&h>=t)throw new Error("Excess padding");if(!u&&d)throw new Error(`Non-zero padding: ${d}`);return u&&h>0&&x.push(d>>>0),x}function radix(e){return assertNumber(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return convertRadix(Array.from(t),2**8,e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix.decode input should be array of strings");return Uint8Array.from(convertRadix(t,e,2**8))}}}function radix2(e,t=!1){if(assertNumber(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(radix2carry(8,e)>32||radix2carry(e,8)>32)throw new Error("radix2: carry overflow");return{encode:a=>{if(!(a instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return convertRadix2(Array.from(a),8,e,!t)},decode:a=>{if(!Array.isArray(a)||a.length&&typeof a[0]!="number")throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(convertRadix2(a,e,8,t))}}}function unsafeWrapper(e){if(typeof e!="function")throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch{}}}var base16=chain(radix2(4),alphabet("0123456789ABCDEF"),join("")),base32=chain(radix2(5),alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),padding(5),join(""));chain(radix2(5),alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"),padding(5),join(""));chain(radix2(5),alphabet("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),join(""),normalize(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));var base64=chain(radix2(6),alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),padding(6),join("")),base64url=chain(radix2(6),alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),padding(6),join("")),genBase58=e=>chain(radix(58),alphabet(e),join("")),base58=genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");genBase58("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");genBase58("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");var XMR_BLOCK_LEN=[0,2,3,5,6,7,9,10,11],base58xmr={encode(e){let t="";for(let a=0;a<e.length;a+=8){const u=e.subarray(a,a+8);t+=base58.encode(u).padStart(XMR_BLOCK_LEN[u.length],"1")}return t},decode(e){let t=[];for(let a=0;a<e.length;a+=11){const u=e.slice(a,a+11),d=XMR_BLOCK_LEN.indexOf(u.length),h=base58.decode(u);for(let w=0;w<h.length-d;w++)if(h[w]!==0)throw new Error("base58xmr: wrong padding");t=t.concat(Array.from(h.slice(h.length-d)))}return Uint8Array.from(t)}},BECH_ALPHABET=chain(alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),join("")),POLYMOD_GENERATORS=[996825010,642813549,513874426,1027748829,705979059];function bech32Polymod(e){const t=e>>25;let a=(e&33554431)<<5;for(let u=0;u<POLYMOD_GENERATORS.length;u++)(t>>u&1)===1&&(a^=POLYMOD_GENERATORS[u]);return a}function bechChecksum(e,t,a=1){const u=e.length;let d=1;for(let h=0;h<u;h++){const w=e.charCodeAt(h);if(w<33||w>126)throw new Error(`Invalid prefix (${e})`);d=bech32Polymod(d)^w>>5}d=bech32Polymod(d);for(let h=0;h<u;h++)d=bech32Polymod(d)^e.charCodeAt(h)&31;for(let h of t)d=bech32Polymod(d)^h;for(let h=0;h<6;h++)d=bech32Polymod(d);return d^=a,BECH_ALPHABET.encode(convertRadix2([d%2**30],30,5,!1))}function genBech32(e){const t=e==="bech32"?1:734539939,a=radix2(5),u=a.decode,d=a.encode,h=unsafeWrapper(u);function w(E,S,k=90){if(typeof E!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof E}`);if(!Array.isArray(S)||S.length&&typeof S[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof S}`);const C=E.length+7+S.length;if(k!==!1&&C>k)throw new TypeError(`Length ${C} exceeds limit ${k}`);return E=E.toLowerCase(),`${E}1${BECH_ALPHABET.encode(S)}${bechChecksum(E,S,t)}`}function x(E,S=90){if(typeof E!="string")throw new Error(`bech32.decode input should be string, not ${typeof E}`);if(E.length<8||S!==!1&&E.length>S)throw new TypeError(`Wrong string length: ${E.length} (${E}). Expected (8..${S})`);const k=E.toLowerCase();if(E!==k&&E!==E.toUpperCase())throw new Error("String must be lowercase or uppercase");E=k;const C=E.lastIndexOf("1");if(C===0||C===-1)throw new Error('Letter "1" must be present between prefix and data only');const D=E.slice(0,C),O=E.slice(C+1);if(O.length<6)throw new Error("Data must be at least 6 characters long");const F=BECH_ALPHABET.decode(O).slice(0,-6),P=bechChecksum(D,F,t);if(!O.endsWith(P))throw new Error(`Invalid checksum in ${E}: expected "${P}"`);return{prefix:D,words:F}}const M=unsafeWrapper(x);function B(E){const{prefix:S,words:k}=x(E,!1);return{prefix:S,words:k,bytes:u(k)}}return{encode:w,decode:x,decodeToBytes:B,decodeUnsafe:M,fromWords:u,fromWordsUnsafe:h,toWords:d}}var bech32=genBech32("bech32");genBech32("bech32m");var utf8={encode:e=>new TextDecoder().decode(e),decode:e=>new TextEncoder().encode(e)},hex=chain(radix2(4),alphabet("0123456789abcdef"),join(""),normalize(e=>{if(typeof e!="string"||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})),CODERS={utf8,hex,base16,base32,base64,base64url,base58,base58xmr};`${Object.keys(CODERS).join(", ")}`;function number3(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function bool2(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function isBytes(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function bytes3(e,...t){if(!isBytes(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function exists3(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function output3(e,t){bytes3(e);const a=t.outputLen;if(e.length<a)throw new Error(`digestInto() expects output buffer of length at least ${a}`)}var u32=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),createView3=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),isLE3=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!isLE3)throw new Error("Non little-endian hardware is not supported");var hexes3=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bytesToHex3(e){bytes3(e);let t="";for(let a=0;a<e.length;a++)t+=hexes3[e[a]];return t}var asciis={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function asciiToBase16(e){if(e>=asciis._0&&e<=asciis._9)return e-asciis._0;if(e>=asciis._A&&e<=asciis._F)return e-(asciis._A-10);if(e>=asciis._a&&e<=asciis._f)return e-(asciis._a-10)}function hexToBytes3(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length,a=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const u=new Uint8Array(a);for(let d=0,h=0;d<a;d++,h+=2){const w=asciiToBase16(e.charCodeAt(h)),x=asciiToBase16(e.charCodeAt(h+1));if(w===void 0||x===void 0){const M=e[h]+e[h+1];throw new Error('hex string expected, got non-hex character "'+M+'" at index '+h)}u[d]=w*16+x}return u}function utf8ToBytes4(e){if(typeof e!="string")throw new Error(`string expected, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function toBytes3(e){if(typeof e=="string")e=utf8ToBytes4(e);else if(isBytes(e))e=e.slice();else throw new Error(`Uint8Array expected, got ${typeof e}`);return e}function checkOpts(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function equalBytes2(e,t){if(e.length!==t.length)return!1;let a=0;for(let u=0;u<e.length;u++)a|=e[u]^t[u];return a===0}var wrapCipher=(e,t)=>(Object.assign(t,e),t),BLOCK_SIZE=16,ZEROS16=new Uint8Array(16),ZEROS32=u32(ZEROS16),POLY=225,mul2=(e,t,a,u)=>{const d=u&1;return{s3:a<<31|u>>>1,s2:t<<31|a>>>1,s1:e<<31|t>>>1,s0:e>>>1^POLY<<24&-(d&1)}},swapLE=e=>(e>>>0&255)<<24|(e>>>8&255)<<16|(e>>>16&255)<<8|e>>>24&255|0;function _toGHASHKey(e){e.reverse();const t=e[15]&1;let a=0;for(let u=0;u<e.length;u++){const d=e[u];e[u]=d>>>1|a,a=(d&1)<<7}return e[0]^=-t&225,e}var estimateWindow=e=>e>64*1024?8:e>1024?4:2,GHASH=class{constructor(e,t){this.blockLen=BLOCK_SIZE,this.outputLen=BLOCK_SIZE,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=toBytes3(e),bytes3(e,16);const a=createView3(e);let u=a.getUint32(0,!1),d=a.getUint32(4,!1),h=a.getUint32(8,!1),w=a.getUint32(12,!1);const x=[];for(let C=0;C<128;C++)x.push({s0:swapLE(u),s1:swapLE(d),s2:swapLE(h),s3:swapLE(w)}),{s0:u,s1:d,s2:h,s3:w}=mul2(u,d,h,w);const M=estimateWindow(t||1024);if(![1,2,4,8].includes(M))throw new Error(`ghash: wrong window size=${M}, should be 2, 4 or 8`);this.W=M;const E=128/M,S=this.windowSize=2**M,k=[];for(let C=0;C<E;C++)for(let D=0;D<S;D++){let O=0,F=0,P=0,L=0;for(let J=0;J<M;J++){if(!(D>>>M-J-1&1))continue;const{s0:ae,s1:oe,s2:ue,s3:se}=x[M*C+J];O^=ae,F^=oe,P^=ue,L^=se}k.push({s0:O,s1:F,s2:P,s3:L})}this.t=k}_updateBlock(e,t,a,u){e^=this.s0,t^=this.s1,a^=this.s2,u^=this.s3;const{W:d,t:h,windowSize:w}=this;let x=0,M=0,B=0,E=0;const S=(1<<d)-1;let k=0;for(const C of[e,t,a,u])for(let D=0;D<4;D++){const O=C>>>8*D&255;for(let F=8/d-1;F>=0;F--){const P=O>>>d*F&S,{s0:L,s1:J,s2:Y,s3:ae}=h[k*w+P];x^=L,M^=J,B^=Y,E^=ae,k+=1}}this.s0=x,this.s1=M,this.s2=B,this.s3=E}update(e){e=toBytes3(e),exists3(this);const t=u32(e),a=Math.floor(e.length/BLOCK_SIZE),u=e.length%BLOCK_SIZE;for(let d=0;d<a;d++)this._updateBlock(t[d*4+0],t[d*4+1],t[d*4+2],t[d*4+3]);return u&&(ZEROS16.set(e.subarray(a*BLOCK_SIZE)),this._updateBlock(ZEROS32[0],ZEROS32[1],ZEROS32[2],ZEROS32[3]),ZEROS32.fill(0)),this}destroy(){const{t:e}=this;for(const t of e)t.s0=0,t.s1=0,t.s2=0,t.s3=0}digestInto(e){exists3(this),output3(e,this),this.finished=!0;const{s0:t,s1:a,s2:u,s3:d}=this,h=u32(e);return h[0]=t,h[1]=a,h[2]=u,h[3]=d,e}digest(){const e=new Uint8Array(BLOCK_SIZE);return this.digestInto(e),this.destroy(),e}},Polyval=class extends GHASH{constructor(e,t){e=toBytes3(e);const a=_toGHASHKey(e.slice());super(a,t),a.fill(0)}update(e){e=toBytes3(e),exists3(this);const t=u32(e),a=e.length%BLOCK_SIZE,u=Math.floor(e.length/BLOCK_SIZE);for(let d=0;d<u;d++)this._updateBlock(swapLE(t[d*4+3]),swapLE(t[d*4+2]),swapLE(t[d*4+1]),swapLE(t[d*4+0]));return a&&(ZEROS16.set(e.subarray(u*BLOCK_SIZE)),this._updateBlock(swapLE(ZEROS32[3]),swapLE(ZEROS32[2]),swapLE(ZEROS32[1]),swapLE(ZEROS32[0])),ZEROS32.fill(0)),this}digestInto(e){exists3(this),output3(e,this),this.finished=!0;const{s0:t,s1:a,s2:u,s3:d}=this,h=u32(e);return h[0]=t,h[1]=a,h[2]=u,h[3]=d,e.reverse()}};function wrapConstructorWithKey(e){const t=(u,d)=>e(d,u.length).update(toBytes3(u)).digest(),a=e(new Uint8Array(16),0);return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=(u,d)=>e(u,d),t}wrapConstructorWithKey((e,t)=>new GHASH(e,t));wrapConstructorWithKey((e,t)=>new Polyval(e,t));var BLOCK_SIZE2=16,POLY2=283;function mul22(e){return e<<1^POLY2&-(e>>7)}function mul(e,t){let a=0;for(;t>0;t>>=1)a^=e&-(t&1),e=mul22(e);return a}var sbox=(()=>{let e=new Uint8Array(256);for(let a=0,u=1;a<256;a++,u^=mul22(u))e[a]=u;const t=new Uint8Array(256);t[0]=99;for(let a=0;a<255;a++){let u=e[255-a];u|=u<<8,t[e[a]]=(u^u>>4^u>>5^u>>6^u>>7^99)&255}return t})(),invSbox=sbox.map((e,t)=>sbox.indexOf(t)),rotr32_8=e=>e<<24|e>>>8,rotl32_8=e=>e<<8|e>>>24;function genTtable(e,t){if(e.length!==256)throw new Error("Wrong sbox length");const a=new Uint32Array(256).map((B,E)=>t(e[E])),u=a.map(rotl32_8),d=u.map(rotl32_8),h=d.map(rotl32_8),w=new Uint32Array(256*256),x=new Uint32Array(256*256),M=new Uint16Array(256*256);for(let B=0;B<256;B++)for(let E=0;E<256;E++){const S=B*256+E;w[S]=a[B]^u[E],x[S]=d[B]^h[E],M[S]=e[B]<<8|e[E]}return{sbox:e,sbox2:M,T0:a,T1:u,T2:d,T3:h,T01:w,T23:x}}var tableEncoding=genTtable(sbox,e=>mul(e,3)<<24|e<<16|e<<8|mul(e,2)),tableDecoding=genTtable(invSbox,e=>mul(e,11)<<24|mul(e,13)<<16|mul(e,9)<<8|mul(e,14)),xPowers=(()=>{const e=new Uint8Array(16);for(let t=0,a=1;t<16;t++,a=mul22(a))e[t]=a;return e})();function expandKeyLE(e){bytes3(e);const t=e.length;if(![16,24,32].includes(t))throw new Error(`aes: wrong key size: should be 16, 24 or 32, got: ${t}`);const{sbox2:a}=tableEncoding,u=u32(e),d=u.length,h=x=>applySbox(a,x,x,x,x),w=new Uint32Array(t+28);w.set(u);for(let x=d;x<w.length;x++){let M=w[x-1];x%d===0?M=h(rotr32_8(M))^xPowers[x/d-1]:d>6&&x%d===4&&(M=h(M)),w[x]=w[x-d]^M}return w}function expandKeyDecLE(e){const t=expandKeyLE(e),a=t.slice(),u=t.length,{sbox2:d}=tableEncoding,{T0:h,T1:w,T2:x,T3:M}=tableDecoding;for(let B=0;B<u;B+=4)for(let E=0;E<4;E++)a[B+E]=t[u-B-4+E];t.fill(0);for(let B=4;B<u-4;B++){const E=a[B],S=applySbox(d,E,E,E,E);a[B]=h[S&255]^w[S>>>8&255]^x[S>>>16&255]^M[S>>>24]}return a}function apply0123(e,t,a,u,d,h){return e[a<<8&65280|u>>>8&255]^t[d>>>8&65280|h>>>24&255]}function applySbox(e,t,a,u,d){return e[t&255|a&65280]|e[u>>>16&255|d>>>16&65280]<<16}function encrypt(e,t,a,u,d){const{sbox2:h,T01:w,T23:x}=tableEncoding;let M=0;t^=e[M++],a^=e[M++],u^=e[M++],d^=e[M++];const B=e.length/4-2;for(let D=0;D<B;D++){const O=e[M++]^apply0123(w,x,t,a,u,d),F=e[M++]^apply0123(w,x,a,u,d,t),P=e[M++]^apply0123(w,x,u,d,t,a),L=e[M++]^apply0123(w,x,d,t,a,u);t=O,a=F,u=P,d=L}const E=e[M++]^applySbox(h,t,a,u,d),S=e[M++]^applySbox(h,a,u,d,t),k=e[M++]^applySbox(h,u,d,t,a),C=e[M++]^applySbox(h,d,t,a,u);return{s0:E,s1:S,s2:k,s3:C}}function decrypt(e,t,a,u,d){const{sbox2:h,T01:w,T23:x}=tableDecoding;let M=0;t^=e[M++],a^=e[M++],u^=e[M++],d^=e[M++];const B=e.length/4-2;for(let D=0;D<B;D++){const O=e[M++]^apply0123(w,x,t,d,u,a),F=e[M++]^apply0123(w,x,a,t,d,u),P=e[M++]^apply0123(w,x,u,a,t,d),L=e[M++]^apply0123(w,x,d,u,a,t);t=O,a=F,u=P,d=L}const E=e[M++]^applySbox(h,t,d,u,a),S=e[M++]^applySbox(h,a,t,d,u),k=e[M++]^applySbox(h,u,a,t,d),C=e[M++]^applySbox(h,d,u,a,t);return{s0:E,s1:S,s2:k,s3:C}}function getDst(e,t){if(!t)return new Uint8Array(e);if(bytes3(t),t.length<e)throw new Error(`aes: wrong destination length, expected at least ${e}, got: ${t.length}`);return t}function validateBlockDecrypt(e){if(bytes3(e),e.length%BLOCK_SIZE2!==0)throw new Error(`aes/(cbc-ecb).decrypt ciphertext should consist of blocks with size ${BLOCK_SIZE2}`)}function validateBlockEncrypt(e,t,a){let u=e.length;const d=u%BLOCK_SIZE2;if(!t&&d!==0)throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");const h=u32(e);if(t){let M=BLOCK_SIZE2-d;M||(M=BLOCK_SIZE2),u=u+M}const w=getDst(u,a),x=u32(w);return{b:h,o:x,out:w}}function validatePCKS(e,t){if(!t)return e;const a=e.length;if(!a)throw new Error("aes/pcks5: empty ciphertext not allowed");const u=e[a-1];if(u<=0||u>16)throw new Error(`aes/pcks5: wrong padding byte: ${u}`);const d=e.subarray(0,-u);for(let h=0;h<u;h++)if(e[a-h-1]!==u)throw new Error("aes/pcks5: wrong padding");return d}function padPCKS(e){const t=new Uint8Array(16),a=u32(t);t.set(e);const u=BLOCK_SIZE2-e.length;for(let d=BLOCK_SIZE2-u;d<BLOCK_SIZE2;d++)t[d]=u;return a}var cbc=wrapCipher({blockSize:16,nonceLength:16},function e(t,a,u={}){bytes3(t),bytes3(a,16);const d=!u.disablePadding;return{encrypt:(h,w)=>{const x=expandKeyLE(t),{b:M,o:B,out:E}=validateBlockEncrypt(h,d,w),S=u32(a);let k=S[0],C=S[1],D=S[2],O=S[3],F=0;for(;F+4<=M.length;)k^=M[F+0],C^=M[F+1],D^=M[F+2],O^=M[F+3],{s0:k,s1:C,s2:D,s3:O}=encrypt(x,k,C,D,O),B[F++]=k,B[F++]=C,B[F++]=D,B[F++]=O;if(d){const P=padPCKS(h.subarray(F*4));k^=P[0],C^=P[1],D^=P[2],O^=P[3],{s0:k,s1:C,s2:D,s3:O}=encrypt(x,k,C,D,O),B[F++]=k,B[F++]=C,B[F++]=D,B[F++]=O}return x.fill(0),E},decrypt:(h,w)=>{validateBlockDecrypt(h);const x=expandKeyDecLE(t),M=u32(a),B=getDst(h.length,w),E=u32(h),S=u32(B);let k=M[0],C=M[1],D=M[2],O=M[3];for(let F=0;F+4<=E.length;){const P=k,L=C,J=D,Y=O;k=E[F+0],C=E[F+1],D=E[F+2],O=E[F+3];const{s0:ae,s1:oe,s2:ue,s3:se}=decrypt(x,k,C,D,O);S[F++]=ae^P,S[F++]=oe^L,S[F++]=ue^J,S[F++]=se^Y}return x.fill(0),validatePCKS(B,d)}}}),u8to16=(e,t)=>e[t++]&255|(e[t++]&255)<<8,Poly1305=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=toBytes3(e),bytes3(e,32);const t=u8to16(e,0),a=u8to16(e,2),u=u8to16(e,4),d=u8to16(e,6),h=u8to16(e,8),w=u8to16(e,10),x=u8to16(e,12),M=u8to16(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|a<<3)&8191,this.r[2]=(a>>>10|u<<6)&7939,this.r[3]=(u>>>7|d<<9)&8191,this.r[4]=(d>>>4|h<<12)&255,this.r[5]=h>>>1&8190,this.r[6]=(h>>>14|w<<2)&8191,this.r[7]=(w>>>11|x<<5)&8065,this.r[8]=(x>>>8|M<<8)&8191,this.r[9]=M>>>5&127;for(let B=0;B<8;B++)this.pad[B]=u8to16(e,16+2*B)}process(e,t,a=!1){const u=a?0:2048,{h:d,r:h}=this,w=h[0],x=h[1],M=h[2],B=h[3],E=h[4],S=h[5],k=h[6],C=h[7],D=h[8],O=h[9],F=u8to16(e,t+0),P=u8to16(e,t+2),L=u8to16(e,t+4),J=u8to16(e,t+6),Y=u8to16(e,t+8),ae=u8to16(e,t+10),oe=u8to16(e,t+12),ue=u8to16(e,t+14);let se=d[0]+(F&8191),ie=d[1]+((F>>>13|P<<3)&8191),ce=d[2]+((P>>>10|L<<6)&8191),$=d[3]+((L>>>7|J<<9)&8191),n=d[4]+((J>>>4|Y<<12)&8191),l=d[5]+(Y>>>1&8191),c=d[6]+((Y>>>14|ae<<2)&8191),p=d[7]+((ae>>>11|oe<<5)&8191),y=d[8]+((oe>>>8|ue<<8)&8191),b=d[9]+(ue>>>5|u),_=0,v=_+se*w+ie*(5*O)+ce*(5*D)+$*(5*C)+n*(5*k);_=v>>>13,v&=8191,v+=l*(5*S)+c*(5*E)+p*(5*B)+y*(5*M)+b*(5*x),_+=v>>>13,v&=8191;let o=_+se*x+ie*w+ce*(5*O)+$*(5*D)+n*(5*C);_=o>>>13,o&=8191,o+=l*(5*k)+c*(5*S)+p*(5*E)+y*(5*B)+b*(5*M),_+=o>>>13,o&=8191;let m=_+se*M+ie*x+ce*w+$*(5*O)+n*(5*D);_=m>>>13,m&=8191,m+=l*(5*C)+c*(5*k)+p*(5*S)+y*(5*E)+b*(5*B),_+=m>>>13,m&=8191;let A=_+se*B+ie*M+ce*x+$*w+n*(5*O);_=A>>>13,A&=8191,A+=l*(5*D)+c*(5*C)+p*(5*k)+y*(5*S)+b*(5*E),_+=A>>>13,A&=8191;let I=_+se*E+ie*B+ce*M+$*x+n*w;_=I>>>13,I&=8191,I+=l*(5*O)+c*(5*D)+p*(5*C)+y*(5*k)+b*(5*S),_+=I>>>13,I&=8191;let U=_+se*S+ie*E+ce*B+$*M+n*x;_=U>>>13,U&=8191,U+=l*w+c*(5*O)+p*(5*D)+y*(5*C)+b*(5*k),_+=U>>>13,U&=8191;let X=_+se*k+ie*S+ce*E+$*B+n*M;_=X>>>13,X&=8191,X+=l*x+c*w+p*(5*O)+y*(5*D)+b*(5*C),_+=X>>>13,X&=8191;let V=_+se*C+ie*k+ce*S+$*E+n*B;_=V>>>13,V&=8191,V+=l*M+c*x+p*w+y*(5*O)+b*(5*D),_+=V>>>13,V&=8191;let T=_+se*D+ie*C+ce*k+$*S+n*E;_=T>>>13,T&=8191,T+=l*B+c*M+p*x+y*w+b*(5*O),_+=T>>>13,T&=8191;let q=_+se*O+ie*D+ce*C+$*k+n*S;_=q>>>13,q&=8191,q+=l*E+c*B+p*M+y*x+b*w,_+=q>>>13,q&=8191,_=(_<<2)+_|0,_=_+v|0,v=_&8191,_=_>>>13,o+=_,d[0]=v,d[1]=o,d[2]=m,d[3]=A,d[4]=I,d[5]=U,d[6]=X,d[7]=V,d[8]=T,d[9]=q}finalize(){const{h:e,pad:t}=this,a=new Uint16Array(10);let u=e[1]>>>13;e[1]&=8191;for(let w=2;w<10;w++)e[w]+=u,u=e[w]>>>13,e[w]&=8191;e[0]+=u*5,u=e[0]>>>13,e[0]&=8191,e[1]+=u,u=e[1]>>>13,e[1]&=8191,e[2]+=u,a[0]=e[0]+5,u=a[0]>>>13,a[0]&=8191;for(let w=1;w<10;w++)a[w]=e[w]+u,u=a[w]>>>13,a[w]&=8191;a[9]-=8192;let d=(u^1)-1;for(let w=0;w<10;w++)a[w]&=d;d=~d;for(let w=0;w<10;w++)e[w]=e[w]&d|a[w];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let h=e[0]+t[0];e[0]=h&65535;for(let w=1;w<8;w++)h=(e[w]+t[w]|0)+(h>>>16)|0,e[w]=h&65535}update(e){exists3(this);const{buffer:t,blockLen:a}=this;e=toBytes3(e);const u=e.length;for(let d=0;d<u;){const h=Math.min(a-this.pos,u-d);if(h===a){for(;a<=u-d;d+=a)this.process(e,d);continue}t.set(e.subarray(d,d+h),this.pos),this.pos+=h,d+=h,this.pos===a&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){exists3(this),output3(e,this),this.finished=!0;const{buffer:t,h:a}=this;let{pos:u}=this;if(u){for(t[u++]=1;u<16;u++)t[u]=0;this.process(t,0,!0)}this.finalize();let d=0;for(let h=0;h<8;h++)e[d++]=a[h]>>>0,e[d++]=a[h]>>>8;return e}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const a=e.slice(0,t);return this.destroy(),a}};function wrapConstructorWithKey2(e){const t=(u,d)=>e(d).update(toBytes3(u)).digest(),a=e(new Uint8Array(32));return t.outputLen=a.outputLen,t.blockLen=a.blockLen,t.create=u=>e(u),t}wrapConstructorWithKey2(e=>new Poly1305(e));var _utf8ToBytes=e=>Uint8Array.from(e.split("").map(t=>t.charCodeAt(0))),sigma16=_utf8ToBytes("expand 16-byte k"),sigma32=_utf8ToBytes("expand 32-byte k"),sigma16_32=u32(sigma16),sigma32_32=u32(sigma32);sigma32_32.slice();function rotl(e,t){return e<<t|e>>>32-t}function isAligned32(e){return e.byteOffset%4===0}var BLOCK_LEN=64,BLOCK_LEN32=16,MAX_COUNTER=2**32-1,U32_EMPTY=new Uint32Array;function runCipher(e,t,a,u,d,h,w,x){const M=d.length,B=new Uint8Array(BLOCK_LEN),E=u32(B),S=isAligned32(d)&&isAligned32(h),k=S?u32(d):U32_EMPTY,C=S?u32(h):U32_EMPTY;for(let D=0;D<M;w++){if(e(t,a,u,E,w,x),w>=MAX_COUNTER)throw new Error("arx: counter overflow");const O=Math.min(BLOCK_LEN,M-D);if(S&&O===BLOCK_LEN){const F=D/4;if(D%4!==0)throw new Error("arx: invalid block position");for(let P=0,L;P<BLOCK_LEN32;P++)L=F+P,C[L]=k[L]^E[P];D+=BLOCK_LEN;continue}for(let F=0,P;F<O;F++)P=D+F,h[P]=d[P]^B[F];D+=O}}function createCipher(e,t){const{allowShortKeys:a,extendNonceFn:u,counterLength:d,counterRight:h,rounds:w}=checkOpts({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return number3(d),number3(w),bool2(h),bool2(a),(x,M,B,E,S=0)=>{bytes3(x),bytes3(M),bytes3(B);const k=B.length;if(E||(E=new Uint8Array(k)),bytes3(E),number3(S),S<0||S>=MAX_COUNTER)throw new Error("arx: counter overflow");if(E.length<k)throw new Error(`arx: output (${E.length}) is shorter than data (${k})`);const C=[];let D=x.length,O,F;if(D===32)O=x.slice(),C.push(O),F=sigma32_32;else if(D===16&&a)O=new Uint8Array(32),O.set(x),O.set(x,16),F=sigma16_32,C.push(O);else throw new Error(`arx: invalid 32-byte key, got length=${D}`);isAligned32(M)||(M=M.slice(),C.push(M));const P=u32(O);if(u){if(M.length!==24)throw new Error("arx: extended nonce must be 24 bytes");u(F,P,u32(M.subarray(0,16)),P),M=M.subarray(16)}const L=16-d;if(L!==M.length)throw new Error(`arx: nonce must be ${L} or 16 bytes`);if(L!==12){const Y=new Uint8Array(12);Y.set(M,h?0:12-M.length),M=Y,C.push(M)}const J=u32(M);for(runCipher(e,F,P,J,B,E,S,w);C.length>0;)C.pop().fill(0);return E}}function chachaCore(e,t,a,u,d,h=20){let w=e[0],x=e[1],M=e[2],B=e[3],E=t[0],S=t[1],k=t[2],C=t[3],D=t[4],O=t[5],F=t[6],P=t[7],L=d,J=a[0],Y=a[1],ae=a[2],oe=w,ue=x,se=M,ie=B,ce=E,$=S,n=k,l=C,c=D,p=O,y=F,b=P,_=L,v=J,o=Y,m=ae;for(let I=0;I<h;I+=2)oe=oe+ce|0,_=rotl(_^oe,16),c=c+_|0,ce=rotl(ce^c,12),oe=oe+ce|0,_=rotl(_^oe,8),c=c+_|0,ce=rotl(ce^c,7),ue=ue+$|0,v=rotl(v^ue,16),p=p+v|0,$=rotl($^p,12),ue=ue+$|0,v=rotl(v^ue,8),p=p+v|0,$=rotl($^p,7),se=se+n|0,o=rotl(o^se,16),y=y+o|0,n=rotl(n^y,12),se=se+n|0,o=rotl(o^se,8),y=y+o|0,n=rotl(n^y,7),ie=ie+l|0,m=rotl(m^ie,16),b=b+m|0,l=rotl(l^b,12),ie=ie+l|0,m=rotl(m^ie,8),b=b+m|0,l=rotl(l^b,7),oe=oe+$|0,m=rotl(m^oe,16),y=y+m|0,$=rotl($^y,12),oe=oe+$|0,m=rotl(m^oe,8),y=y+m|0,$=rotl($^y,7),ue=ue+n|0,_=rotl(_^ue,16),b=b+_|0,n=rotl(n^b,12),ue=ue+n|0,_=rotl(_^ue,8),b=b+_|0,n=rotl(n^b,7),se=se+l|0,v=rotl(v^se,16),c=c+v|0,l=rotl(l^c,12),se=se+l|0,v=rotl(v^se,8),c=c+v|0,l=rotl(l^c,7),ie=ie+ce|0,o=rotl(o^ie,16),p=p+o|0,ce=rotl(ce^p,12),ie=ie+ce|0,o=rotl(o^ie,8),p=p+o|0,ce=rotl(ce^p,7);let A=0;u[A++]=w+oe|0,u[A++]=x+ue|0,u[A++]=M+se|0,u[A++]=B+ie|0,u[A++]=E+ce|0,u[A++]=S+$|0,u[A++]=k+n|0,u[A++]=C+l|0,u[A++]=D+c|0,u[A++]=O+p|0,u[A++]=F+y|0,u[A++]=P+b|0,u[A++]=L+_|0,u[A++]=J+v|0,u[A++]=Y+o|0,u[A++]=ae+m|0}var chacha20=createCipher(chachaCore,{counterRight:!1,counterLength:4,allowShortKeys:!1}),HMAC2=class extends Hash2{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,assert_default.hash(e);const a=toBytes2(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const u=this.blockLen,d=new Uint8Array(u);d.set(a.length>u?e.create().update(a).digest():a);for(let h=0;h<d.length;h++)d[h]^=54;this.iHash.update(d),this.oHash=e.create();for(let h=0;h<d.length;h++)d[h]^=106;this.oHash.update(d),d.fill(0)}update(e){return assert_default.exists(this),this.iHash.update(e),this}digestInto(e){assert_default.exists(this),assert_default.bytes(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:a,finished:u,destroyed:d,blockLen:h,outputLen:w}=this;return e=e,e.finished=u,e.destroyed=d,e.blockLen=h,e.outputLen=w,e.oHash=t._cloneInto(e.oHash),e.iHash=a._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},hmac2=(e,t,a)=>new HMAC2(e,t).update(a).digest();hmac2.create=(e,t)=>new HMAC2(e,t);function extract(e,t,a){return assert_default.hash(e),hmac2(e,toBytes2(a),toBytes2(t))}var HKDF_COUNTER=new Uint8Array([0]),EMPTY_BUFFER=new Uint8Array;function expand(e,t,a,u=32){if(assert_default.hash(e),assert_default.number(u),u>255*e.outputLen)throw new Error("Length should be <= 255*HashLen");const d=Math.ceil(u/e.outputLen);a===void 0&&(a=EMPTY_BUFFER);const h=new Uint8Array(d*e.outputLen),w=hmac2.create(e,t),x=w._cloneInto(),M=new Uint8Array(w.outputLen);for(let B=0;B<d;B++)HKDF_COUNTER[0]=B+1,x.update(B===0?EMPTY_BUFFER:M).update(a).update(HKDF_COUNTER).digestInto(M),h.set(M,e.outputLen*B),w._cloneInto(x);return w.destroy(),x.destroy(),M.fill(0),HKDF_COUNTER.fill(0),h.slice(0,u)}var __defProp2=Object.defineProperty,__export2=(e,t)=>{for(var a in t)__defProp2(e,a,{get:t[a],enumerable:!0})},verifiedSymbol2=Symbol("verified"),isRecord2=e=>e instanceof Object;function validateEvent2(e){if(!isRecord2(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let a=e.tags[t];if(!Array.isArray(a))return!1;for(let u=0;u<a.length;u++)if(typeof a[u]!="string")return!1}return!0}var utils_exports2={};__export2(utils_exports2,{Queue:()=>Queue,QueueNode:()=>QueueNode,binarySearch:()=>binarySearch,bytesToHex:()=>bytesToHex2,hexToBytes:()=>hexToBytes2,insertEventIntoAscendingList:()=>insertEventIntoAscendingList,insertEventIntoDescendingList:()=>insertEventIntoDescendingList,normalizeURL:()=>normalizeURL,utf8Decoder:()=>utf8Decoder3,utf8Encoder:()=>utf8Encoder3});var utf8Decoder3=new TextDecoder("utf-8"),utf8Encoder3=new TextEncoder;function normalizeURL(e){try{e.indexOf("://")===-1&&(e="wss://"+e);let t=new URL(e);return t.protocol==="http:"?t.protocol="ws:":t.protocol==="https:"&&(t.protocol="wss:"),t.pathname=t.pathname.replace(/\/+/g,"/"),t.pathname.endsWith("/")&&(t.pathname=t.pathname.slice(0,-1)),(t.port==="80"&&t.protocol==="ws:"||t.port==="443"&&t.protocol==="wss:")&&(t.port=""),t.searchParams.sort(),t.hash="",t.toString()}catch{throw new Error(`Invalid URL: ${e}`)}}function insertEventIntoDescendingList(e,t){const[a,u]=binarySearch(e,d=>t.id===d.id?0:t.created_at===d.created_at?-1:d.created_at-t.created_at);return u||e.splice(a,0,t),e}function insertEventIntoAscendingList(e,t){const[a,u]=binarySearch(e,d=>t.id===d.id?0:t.created_at===d.created_at?-1:t.created_at-d.created_at);return u||e.splice(a,0,t),e}function binarySearch(e,t){let a=0,u=e.length-1;for(;a<=u;){const d=Math.floor((a+u)/2),h=t(e[d]);if(h===0)return[d,!0];h<0?u=d-1:a=d+1}return[a,!1]}var QueueNode=class{constructor(e){_e(this,"value");_e(this,"next",null);_e(this,"prev",null);this.value=e}},Queue=class{constructor(){_e(this,"first");_e(this,"last");this.first=null,this.last=null}enqueue(e){const t=new QueueNode(e);return this.last?this.last===this.first?(this.last=t,this.last.prev=this.first,this.first.next=t):(t.prev=this.last,this.last.next=t,this.last=t):(this.first=t,this.last=t),!0}dequeue(){if(!this.first)return null;if(this.first===this.last){const t=this.first;return this.first=null,this.last=null,t.value}const e=this.first;return this.first=e.next,this.first&&(this.first.prev=null),e.value}},JS2=class{generateSecretKey(){return schnorr.utils.randomPrivateKey()}getPublicKey(e){return bytesToHex2(schnorr.getPublicKey(e))}finalizeEvent(e,t){const a=e;return a.pubkey=bytesToHex2(schnorr.getPublicKey(t)),a.id=getEventHash2(a),a.sig=bytesToHex2(schnorr.sign(getEventHash2(a),t)),a[verifiedSymbol2]=!0,a}verifyEvent(e){if(typeof e[verifiedSymbol2]=="boolean")return e[verifiedSymbol2];const t=getEventHash2(e);if(t!==e.id)return e[verifiedSymbol2]=!1,!1;try{const a=schnorr.verify(e.sig,t,e.pubkey);return e[verifiedSymbol2]=a,a}catch{return e[verifiedSymbol2]=!1,!1}}};function serializeEvent2(e){if(!validateEvent2(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function getEventHash2(e){let t=sha2562(utf8Encoder3.encode(serializeEvent2(e)));return bytesToHex2(t)}var i2=new JS2,generateSecretKey2=i2.generateSecretKey,getPublicKey2=i2.getPublicKey,finalizeEvent2=i2.finalizeEvent,verifyEvent2=i2.verifyEvent,kinds_exports={};__export2(kinds_exports,{Application:()=>Application,BadgeAward:()=>BadgeAward,BadgeDefinition:()=>BadgeDefinition,BlockedRelaysList:()=>BlockedRelaysList,BlossomServerList:()=>BlossomServerList,BookmarkList:()=>BookmarkList,Bookmarksets:()=>Bookmarksets,Calendar:()=>Calendar,CalendarEventRSVP:()=>CalendarEventRSVP,ChannelCreation:()=>ChannelCreation,ChannelHideMessage:()=>ChannelHideMessage,ChannelMessage:()=>ChannelMessage,ChannelMetadata:()=>ChannelMetadata,ChannelMuteUser:()=>ChannelMuteUser,ChatMessage:()=>ChatMessage,ClassifiedListing:()=>ClassifiedListing,ClientAuth:()=>ClientAuth,Comment:()=>Comment,CommunitiesList:()=>CommunitiesList,CommunityDefinition:()=>CommunityDefinition,CommunityPostApproval:()=>CommunityPostApproval,Contacts:()=>Contacts,CreateOrUpdateProduct:()=>CreateOrUpdateProduct,CreateOrUpdateStall:()=>CreateOrUpdateStall,Curationsets:()=>Curationsets,Date:()=>Date2,DirectMessageRelaysList:()=>DirectMessageRelaysList,DraftClassifiedListing:()=>DraftClassifiedListing,DraftLong:()=>DraftLong,Emojisets:()=>Emojisets,EncryptedDirectMessage:()=>EncryptedDirectMessage,EventDeletion:()=>EventDeletion,FavoriteRelays:()=>FavoriteRelays,FileMessage:()=>FileMessage,FileMetadata:()=>FileMetadata,FileServerPreference:()=>FileServerPreference,Followsets:()=>Followsets,ForumThread:()=>ForumThread,GenericRepost:()=>GenericRepost,Genericlists:()=>Genericlists,GiftWrap:()=>GiftWrap,GroupMetadata:()=>GroupMetadata,HTTPAuth:()=>HTTPAuth,Handlerinformation:()=>Handlerinformation,Handlerrecommendation:()=>Handlerrecommendation,Highlights:()=>Highlights,InterestsList:()=>InterestsList,Interestsets:()=>Interestsets,JobFeedback:()=>JobFeedback,JobRequest:()=>JobRequest,JobResult:()=>JobResult,Label:()=>Label,LightningPubRPC:()=>LightningPubRPC,LiveChatMessage:()=>LiveChatMessage,LiveEvent:()=>LiveEvent,LongFormArticle:()=>LongFormArticle,Metadata:()=>Metadata,Mutelist:()=>Mutelist,NWCWalletInfo:()=>NWCWalletInfo,NWCWalletRequest:()=>NWCWalletRequest,NWCWalletResponse:()=>NWCWalletResponse,NormalVideo:()=>NormalVideo,NostrConnect:()=>NostrConnect,OpenTimestamps:()=>OpenTimestamps,Photo:()=>Photo,Pinlist:()=>Pinlist,Poll:()=>Poll,PollResponse:()=>PollResponse,PrivateDirectMessage:()=>PrivateDirectMessage,ProblemTracker:()=>ProblemTracker,ProfileBadges:()=>ProfileBadges,PublicChatsList:()=>PublicChatsList,Reaction:()=>Reaction,RecommendRelay:()=>RecommendRelay,RelayList:()=>RelayList,RelayReview:()=>RelayReview,Relaysets:()=>Relaysets,Report:()=>Report,Reporting:()=>Reporting,Repost:()=>Repost,Seal:()=>Seal,SearchRelaysList:()=>SearchRelaysList,ShortTextNote:()=>ShortTextNote,ShortVideo:()=>ShortVideo,Time:()=>Time,UserEmojiList:()=>UserEmojiList,UserStatuses:()=>UserStatuses,Voice:()=>Voice,VoiceComment:()=>VoiceComment,Zap:()=>Zap,ZapGoal:()=>ZapGoal,ZapRequest:()=>ZapRequest,classifyKind:()=>classifyKind,isAddressableKind:()=>isAddressableKind,isEphemeralKind:()=>isEphemeralKind,isKind:()=>isKind,isRegularKind:()=>isRegularKind,isReplaceableKind:()=>isReplaceableKind});function isRegularKind(e){return e<1e4&&e!==0&&e!==3}function isReplaceableKind(e){return e===0||e===3||1e4<=e&&e<2e4}function isEphemeralKind(e){return 2e4<=e&&e<3e4}function isAddressableKind(e){return 3e4<=e&&e<4e4}function classifyKind(e){return isRegularKind(e)?"regular":isReplaceableKind(e)?"replaceable":isEphemeralKind(e)?"ephemeral":isAddressableKind(e)?"parameterized":"unknown"}function isKind(e,t){const a=t instanceof Array?t:[t];return validateEvent2(e)&&a.includes(e.kind)||!1}var Metadata=0,ShortTextNote=1,RecommendRelay=2,Contacts=3,EncryptedDirectMessage=4,EventDeletion=5,Repost=6,Reaction=7,BadgeAward=8,ChatMessage=9,ForumThread=11,Seal=13,PrivateDirectMessage=14,FileMessage=15,GenericRepost=16,Photo=20,NormalVideo=21,ShortVideo=22,ChannelCreation=40,ChannelMetadata=41,ChannelMessage=42,ChannelHideMessage=43,ChannelMuteUser=44,OpenTimestamps=1040,GiftWrap=1059,Poll=1068,FileMetadata=1063,Comment=1111,LiveChatMessage=1311,Voice=1222,VoiceComment=1244,ProblemTracker=1971,Report=1984,Reporting=1984,Label=1985,CommunityPostApproval=4550,JobRequest=5999,JobResult=6999,JobFeedback=7e3,ZapGoal=9041,ZapRequest=9734,Zap=9735,Highlights=9802,PollResponse=1018,Mutelist=1e4,Pinlist=10001,RelayList=10002,BookmarkList=10003,CommunitiesList=10004,PublicChatsList=10005,BlockedRelaysList=10006,SearchRelaysList=10007,FavoriteRelays=10012,InterestsList=10015,UserEmojiList=10030,DirectMessageRelaysList=10050,FileServerPreference=10096,BlossomServerList=10063,NWCWalletInfo=13194,LightningPubRPC=21e3,ClientAuth=22242,NWCWalletRequest=23194,NWCWalletResponse=23195,NostrConnect=24133,HTTPAuth=27235,Followsets=3e4,Genericlists=30001,Relaysets=30002,Bookmarksets=30003,Curationsets=30004,ProfileBadges=30008,BadgeDefinition=30009,Interestsets=30015,CreateOrUpdateStall=30017,CreateOrUpdateProduct=30018,LongFormArticle=30023,DraftLong=30024,Emojisets=30030,Application=30078,LiveEvent=30311,UserStatuses=30315,ClassifiedListing=30402,DraftClassifiedListing=30403,Date2=31922,Time=31923,Calendar=31924,CalendarEventRSVP=31925,RelayReview=31987,Handlerrecommendation=31989,Handlerinformation=31990,CommunityDefinition=34550,GroupMetadata=39e3;function matchFilter(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1)return!1;for(let a in e)if(a[0]==="#"){let u=a.slice(1),d=e[`#${u}`];if(d&&!t.tags.find(([h,w])=>h===a.slice(1)&&d.indexOf(w)!==-1))return!1}return!(e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)}function matchFilters(e,t){for(let a=0;a<e.length;a++)if(matchFilter(e[a],t))return!0;return!1}var fakejson_exports={};__export2(fakejson_exports,{getHex64:()=>getHex64,getInt:()=>getInt,getSubscriptionId:()=>getSubscriptionId,matchEventId:()=>matchEventId,matchEventKind:()=>matchEventKind,matchEventPubkey:()=>matchEventPubkey});function getHex64(e,t){let a=t.length+3,u=e.indexOf(`"${t}":`)+a,d=e.slice(u).indexOf('"')+u+1;return e.slice(d,d+64)}function getInt(e,t){let a=t.length,u=e.indexOf(`"${t}":`)+a+3,d=e.slice(u),h=Math.min(d.indexOf(","),d.indexOf("}"));return parseInt(d.slice(0,h),10)}function getSubscriptionId(e){let t=e.slice(0,22).indexOf('"EVENT"');if(t===-1)return null;let a=e.slice(t+7+1).indexOf('"');if(a===-1)return null;let u=t+7+1+a,d=e.slice(u+1,80).indexOf('"');if(d===-1)return null;let h=u+1+d;return e.slice(u+1,h)}function matchEventId(e,t){return t===getHex64(e,"id")}function matchEventPubkey(e,t){return t===getHex64(e,"pubkey")}function matchEventKind(e,t){return t===getInt(e,"kind")}var nip42_exports={};__export2(nip42_exports,{makeAuthEvent:()=>makeAuthEvent});function makeAuthEvent(e,t){return{kind:ClientAuth,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",t]],content:""}}async function yieldThread(){return new Promise((e,t)=>{try{if(typeof MessageChannel<"u"){const a=new MessageChannel,u=()=>{a.port1.removeEventListener("message",u),e()};a.port1.addEventListener("message",u),a.port2.postMessage(0),a.port1.start()}else typeof setImmediate<"u"?setImmediate(e):typeof setTimeout<"u"?setTimeout(e,0):e()}catch(a){console.error("during yield: ",a),t(a)}})}var alwaysTrue=e=>(e[verifiedSymbol2]=!0,!0),SendingOnClosedConnection=class extends Error{constructor(e,t){super(`Tried to send message '${e} on a closed connection to ${t}.`),this.name="SendingOnClosedConnection"}},AbstractRelay=class{constructor(e,t){_e(this,"url");_e(this,"_connected",!1);_e(this,"onclose",null);_e(this,"onnotice",e=>console.debug(`NOTICE from ${this.url}: ${e}`));_e(this,"onauth");_e(this,"baseEoseTimeout",4400);_e(this,"connectionTimeout",4400);_e(this,"publishTimeout",4400);_e(this,"pingFrequency",29e3);_e(this,"pingTimeout",2e4);_e(this,"resubscribeBackoff",[1e4,1e4,1e4,2e4,2e4,3e4,6e4]);_e(this,"openSubs",new Map);_e(this,"enablePing");_e(this,"enableReconnect");_e(this,"connectionTimeoutHandle");_e(this,"reconnectTimeoutHandle");_e(this,"pingIntervalHandle");_e(this,"reconnectAttempts",0);_e(this,"closedIntentionally",!1);_e(this,"connectionPromise");_e(this,"openCountRequests",new Map);_e(this,"openEventPublishes",new Map);_e(this,"ws");_e(this,"incomingMessageQueue",new Queue);_e(this,"queueRunning",!1);_e(this,"challenge");_e(this,"authPromise");_e(this,"serial",0);_e(this,"verifyEvent");_e(this,"_WebSocket");this.url=normalizeURL(e),this.verifyEvent=t.verifyEvent,this._WebSocket=t.websocketImplementation||WebSocket,this.enablePing=t.enablePing,this.enableReconnect=t.enableReconnect||!1}static async connect(e,t){const a=new AbstractRelay(e,t);return await a.connect(),a}closeAllSubscriptions(e){for(let[t,a]of this.openSubs)a.close(e);this.openSubs.clear();for(let[t,a]of this.openEventPublishes)a.reject(new Error(e));this.openEventPublishes.clear();for(let[t,a]of this.openCountRequests)a.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 a;this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0;const t=this.closedIntentionally;this.closedIntentionally=!1,(a=this.onclose)==null||a.call(this),this.enableReconnect&&!t?this.reconnect():this.closeAllSubscriptions(e)}async connect(){return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.authPromise=void 0,this.connectionPromise=new Promise((e,t)=>{this.connectionTimeoutHandle=setTimeout(()=>{var a;t("connection timed out"),this.connectionPromise=void 0,(a=this.onclose)==null||a.call(this),this.closeAllSubscriptions("relay connection timed out")},this.connectionTimeout);try{this.ws=new this._WebSocket(this.url)}catch(a){clearTimeout(this.connectionTimeoutHandle),t(a);return}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(this.connectionTimeoutHandle),this._connected=!0;const a=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const u of this.openSubs.values()){if(u.eosed=!1,a)for(let d=0;d<u.filters.length;d++)u.lastEmitted&&(u.filters[d].since=u.lastEmitted+1);u.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),e()},this.ws.onerror=a=>{clearTimeout(this.connectionTimeoutHandle),t(a.message||"websocket error"),this.handleHardClose("relay connection errored")},this.ws.onclose=a=>{clearTimeout(this.connectionTimeoutHandle),t(a.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}waitForPingPong(){return new Promise(e=>{this.ws.once("pong",()=>e(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((e,t)=>{if(!this.connectionPromise)return t(new Error(`no connection to ${this.url}, can't ping`));try{const a=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"forced-ping",oneose:()=>{e(!0),a.close()},onclose(){e(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(a){t(a)}})}async pingpong(){var e,t,a;((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(d=>setTimeout(()=>d(!1),this.pingTimeout))])||((t=this.ws)==null?void 0:t.readyState)===this._WebSocket.OPEN&&((a=this.ws)==null||a.close()))}async runQueue(){for(this.queueRunning=!0;this.handleNext()!==!1;)await yieldThread();this.queueRunning=!1}handleNext(){var a,u,d;const e=this.incomingMessageQueue.dequeue();if(!e)return!1;const t=getSubscriptionId(e);if(t){const h=this.openSubs.get(t);if(!h)return;const w=getHex64(e,"id"),x=(a=h.alreadyHaveEvent)==null?void 0:a.call(h,w);if((u=h.receivedEvent)==null||u.call(h,this,w),x)return}try{let h=JSON.parse(e);switch(h[0]){case"EVENT":{const w=this.openSubs.get(h[1]),x=h[2];this.verifyEvent(x)&&matchFilters(w.filters,x)&&w.onevent(x),(!w.lastEmitted||w.lastEmitted<x.created_at)&&(w.lastEmitted=x.created_at);return}case"COUNT":{const w=h[1],x=h[2],M=this.openCountRequests.get(w);M&&(M.resolve(x.count),this.openCountRequests.delete(w));return}case"EOSE":{const w=this.openSubs.get(h[1]);if(!w)return;w.receivedEose();return}case"OK":{const w=h[1],x=h[2],M=h[3],B=this.openEventPublishes.get(w);B&&(clearTimeout(B.timeout),x?B.resolve(M):B.reject(new Error(M)),this.openEventPublishes.delete(w));return}case"CLOSED":{const w=h[1],x=this.openSubs.get(w);if(!x)return;x.closed=!0,x.close(h[2]);return}case"NOTICE":{this.onnotice(h[1]);return}case"AUTH":{this.challenge=h[1],this.onauth&&this.auth(this.onauth);return}default:{const w=this.openSubs.get(h[1]);(d=w==null?void 0:w.oncustom)==null||d.call(w,h);return}}}catch{return}}async send(e){if(!this.connectionPromise)throw new SendingOnClosedConnection(e,this.url);this.connectionPromise.then(()=>{var t;(t=this.ws)==null||t.send(e)})}async auth(e){const t=this.challenge;if(!t)throw new Error("can't perform auth, no challenge was received");return this.authPromise?this.authPromise:(this.authPromise=new Promise(async(a,u)=>{try{let d=await e(makeAuthEvent(this.url,t)),h=setTimeout(()=>{let w=this.openEventPublishes.get(d.id);w&&(w.reject(new Error("auth timed out")),this.openEventPublishes.delete(d.id))},this.publishTimeout);this.openEventPublishes.set(d.id,{resolve:a,reject:u,timeout:h}),this.send('["AUTH",'+JSON.stringify(d)+"]")}catch(d){console.warn("subscribe auth function failed:",d)}}),this.authPromise)}async publish(e){const t=new Promise((a,u)=>{const d=setTimeout(()=>{const h=this.openEventPublishes.get(e.id);h&&(h.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:a,reject:u,timeout:d})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),t}async count(e,t){this.serial++;const a=(t==null?void 0:t.id)||"count:"+this.serial,u=new Promise((d,h)=>{this.openCountRequests.set(a,{resolve:d,reject:h})});return this.send('["COUNT","'+a+'",'+JSON.stringify(e).substring(1)),u}subscribe(e,t){const a=this.prepareSubscription(e,t);return a.fire(),a}prepareSubscription(e,t){this.serial++;const a=t.id||(t.label?t.label+":":"sub:")+this.serial,u=new Subscription(this,a,e,t);return this.openSubs.set(a,u),u}close(){var e,t,a;this.closedIntentionally=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,(e=this.onclose)==null||e.call(this),((t=this.ws)==null?void 0:t.readyState)===this._WebSocket.OPEN&&((a=this.ws)==null||a.close())}_onmessage(e){this.incomingMessageQueue.enqueue(e.data),this.queueRunning||this.runQueue()}},Subscription=class{constructor(e,t,a,u){_e(this,"relay");_e(this,"id");_e(this,"lastEmitted");_e(this,"closed",!1);_e(this,"eosed",!1);_e(this,"filters");_e(this,"alreadyHaveEvent");_e(this,"receivedEvent");_e(this,"onevent");_e(this,"oneose");_e(this,"onclose");_e(this,"oncustom");_e(this,"eoseTimeout");_e(this,"eoseTimeoutHandle");if(a.length===0)throw new Error("subscription can't be created with zero filters");this.relay=e,this.filters=a,this.id=t,this.alreadyHaveEvent=u.alreadyHaveEvent,this.receivedEvent=u.receivedEvent,this.eoseTimeout=u.eoseTimeout||e.baseEoseTimeout,this.oneose=u.oneose,this.onclose=u.onclose,this.onevent=u.onevent||(d=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,d)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){var e;this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,(e=this.oneose)==null||e.call(this))}close(e="closed by caller"){var t;if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(a){if(!(a instanceof SendingOnClosedConnection))throw a}this.closed=!0}this.relay.openSubs.delete(this.id),(t=this.onclose)==null||t.call(this,e)}},_WebSocket;try{_WebSocket=WebSocket}catch{}var AbstractSimplePool=class{constructor(e){_e(this,"relays",new Map);_e(this,"seenOn",new Map);_e(this,"trackRelays",!1);_e(this,"verifyEvent");_e(this,"enablePing");_e(this,"enableReconnect");_e(this,"automaticallyAuth");_e(this,"trustedRelayURLs",new Set);_e(this,"_WebSocket");this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation,this.enablePing=e.enablePing,this.enableReconnect=e.enableReconnect||!1,this.automaticallyAuth=e.automaticallyAuth}async ensureRelay(e,t){e=normalizeURL(e);let a=this.relays.get(e);if(a||(a=new AbstractRelay(e,{verifyEvent:this.trustedRelayURLs.has(e)?alwaysTrue:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),a.onclose=()=>{a&&!a.enableReconnect&&this.relays.delete(e)},t!=null&&t.connectionTimeout&&(a.connectionTimeout=t.connectionTimeout),this.relays.set(e,a)),this.automaticallyAuth){const u=this.automaticallyAuth(e);u&&(a.onauth=u)}return await a.connect(),a}close(e){e.map(normalizeURL).forEach(t=>{var a;(a=this.relays.get(t))==null||a.close(),this.relays.delete(t)})}subscribe(e,t,a){const u=[];for(let d=0;d<e.length;d++){const h=normalizeURL(e[d]);u.find(w=>w.url===h)||u.push({url:h,filter:t})}return this.subscribeMap(u,a)}subscribeMany(e,t,a){const u=[],d=[];for(let h=0;h<e.length;h++){const w=normalizeURL(e[h]);d.indexOf(w)===-1&&(d.push(w),u.push({url:w,filter:t}))}return this.subscribeMap(u,a)}subscribeMap(e,t){const a=new Map;for(const k of e){const{url:C,filter:D}=k;a.has(C)||a.set(C,[]),a.get(C).push(D)}const u=Array.from(a.entries()).map(([k,C])=>({url:k,filters:C}));this.trackRelays&&(t.receivedEvent=(k,C)=>{let D=this.seenOn.get(C);D||(D=new Set,this.seenOn.set(C,D)),D.add(k)});const d=new Set,h=[],w=[];let x=k=>{var C;w[k]||(w[k]=!0,w.filter(D=>D).length===u.length&&((C=t.oneose)==null||C.call(t),x=()=>{}))};const M=[];let B=(k,C)=>{var D;M[k]||(x(k),M[k]=C,M.filter(O=>O).length===u.length&&((D=t.onclose)==null||D.call(t,M),B=()=>{}))};const E=k=>{var D;if((D=t.alreadyHaveEvent)!=null&&D.call(t,k))return!0;const C=d.has(k);return d.add(k),C},S=Promise.all(u.map(async({url:k,filters:C},D)=>{let O;try{O=await this.ensureRelay(k,{connectionTimeout:t.maxWait?Math.max(t.maxWait*.8,t.maxWait-1e3):void 0})}catch(P){B(D,(P==null?void 0:P.message)||String(P));return}let F=O.subscribe(C,{...t,oneose:()=>x(D),onclose:P=>{P.startsWith("auth-required: ")&&t.onauth?O.auth(t.onauth).then(()=>{O.subscribe(C,{...t,oneose:()=>x(D),onclose:L=>{B(D,L)},alreadyHaveEvent:E,eoseTimeout:t.maxWait})}).catch(L=>{B(D,`auth was required and attempted, but failed with: ${L}`)}):B(D,P)},alreadyHaveEvent:E,eoseTimeout:t.maxWait});h.push(F)}));return{async close(k){await S,h.forEach(C=>{C.close(k)})}}}subscribeEose(e,t,a){const u=this.subscribe(e,t,{...a,oneose(){u.close("closed automatically on eose")}});return u}subscribeManyEose(e,t,a){const u=this.subscribeMany(e,t,{...a,oneose(){u.close("closed automatically on eose")}});return u}async querySync(e,t,a){return new Promise(async u=>{const d=[];this.subscribeEose(e,t,{...a,onevent(h){d.push(h)},onclose(h){u(d)}})})}async get(e,t,a){t.limit=1;const u=await this.querySync(e,t,a);return u.sort((d,h)=>h.created_at-d.created_at),u[0]||null}publish(e,t,a){return e.map(normalizeURL).map(async(u,d,h)=>{if(h.indexOf(u)!==d)return Promise.reject("duplicate url");let w=await this.ensureRelay(u);return w.publish(t).catch(async x=>{if(x instanceof Error&&x.message.startsWith("auth-required: ")&&(a!=null&&a.onauth))return await w.auth(a.onauth),w.publish(t);throw x}).then(x=>{if(this.trackRelays){let M=this.seenOn.get(t.id);M||(M=new Set,this.seenOn.set(t.id,M)),M.add(w)}return x})})}listConnectionStatus(){const e=new Map;return this.relays.forEach((t,a)=>e.set(a,t.connected)),e}destroy(){this.relays.forEach(e=>e.close()),this.relays=new Map}},_WebSocket2;try{_WebSocket2=WebSocket}catch{}var SimplePool=class extends AbstractSimplePool{constructor(e){super({verifyEvent:verifyEvent2,websocketImplementation:_WebSocket2,...e})}},nip19_exports={};__export2(nip19_exports,{BECH32_REGEX:()=>BECH32_REGEX,Bech32MaxSize:()=>Bech32MaxSize,NostrTypeGuard:()=>NostrTypeGuard,decode:()=>decode,decodeNostrURI:()=>decodeNostrURI,encodeBytes:()=>encodeBytes,naddrEncode:()=>naddrEncode,neventEncode:()=>neventEncode,noteEncode:()=>noteEncode,nprofileEncode:()=>nprofileEncode,npubEncode:()=>npubEncode,nsecEncode:()=>nsecEncode});var NostrTypeGuard={isNProfile:e=>/^nprofile1[a-z\d]+$/.test(e||""),isNEvent:e=>/^nevent1[a-z\d]+$/.test(e||""),isNAddr:e=>/^naddr1[a-z\d]+$/.test(e||""),isNSec:e=>/^nsec1[a-z\d]{58}$/.test(e||""),isNPub:e=>/^npub1[a-z\d]{58}$/.test(e||""),isNote:e=>/^note1[a-z\d]+$/.test(e||""),isNcryptsec:e=>/^ncryptsec1[a-z\d]+$/.test(e||"")},Bech32MaxSize=5e3,BECH32_REGEX=/[\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,}/;function integerToUint8Array(e){const t=new Uint8Array(4);return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=e&255,t}function decodeNostrURI(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),decode(e)}catch{return{type:"invalid",data:null}}}function decode(e){var d,h,w,x,M,B,E;let{prefix:t,words:a}=bech32.decode(e,Bech32MaxSize),u=new Uint8Array(bech32.fromWords(a));switch(t){case"nprofile":{let S=parseTLV(u);if(!((d=S[0])!=null&&d[0]))throw new Error("missing TLV 0 for nprofile");if(S[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:bytesToHex2(S[0][0]),relays:S[1]?S[1].map(k=>utf8Decoder3.decode(k)):[]}}}case"nevent":{let S=parseTLV(u);if(!((h=S[0])!=null&&h[0]))throw new Error("missing TLV 0 for nevent");if(S[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(S[2]&&S[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(S[3]&&S[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:bytesToHex2(S[0][0]),relays:S[1]?S[1].map(k=>utf8Decoder3.decode(k)):[],author:(w=S[2])!=null&&w[0]?bytesToHex2(S[2][0]):void 0,kind:(x=S[3])!=null&&x[0]?parseInt(bytesToHex2(S[3][0]),16):void 0}}}case"naddr":{let S=parseTLV(u);if(!((M=S[0])!=null&&M[0]))throw new Error("missing TLV 0 for naddr");if(!((B=S[2])!=null&&B[0]))throw new Error("missing TLV 2 for naddr");if(S[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!((E=S[3])!=null&&E[0]))throw new Error("missing TLV 3 for naddr");if(S[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:utf8Decoder3.decode(S[0][0]),pubkey:bytesToHex2(S[2][0]),kind:parseInt(bytesToHex2(S[3][0]),16),relays:S[1]?S[1].map(k=>utf8Decoder3.decode(k)):[]}}}case"nsec":return{type:t,data:u};case"npub":case"note":return{type:t,data:bytesToHex2(u)};default:throw new Error(`unknown prefix ${t}`)}}function parseTLV(e){let t={},a=e;for(;a.length>0;){let u=a[0],d=a[1],h=a.slice(2,2+d);if(a=a.slice(2+d),h.length<d)throw new Error(`not enough data to read on TLV ${u}`);t[u]=t[u]||[],t[u].push(h)}return t}function nsecEncode(e){return encodeBytes("nsec",e)}function npubEncode(e){return encodeBytes("npub",hexToBytes2(e))}function noteEncode(e){return encodeBytes("note",hexToBytes2(e))}function encodeBech32(e,t){let a=bech32.toWords(t);return bech32.encode(e,a,Bech32MaxSize)}function encodeBytes(e,t){return encodeBech32(e,t)}function nprofileEncode(e){let t=encodeTLV({0:[hexToBytes2(e.pubkey)],1:(e.relays||[]).map(a=>utf8Encoder3.encode(a))});return encodeBech32("nprofile",t)}function neventEncode(e){let t;e.kind!==void 0&&(t=integerToUint8Array(e.kind));let a=encodeTLV({0:[hexToBytes2(e.id)],1:(e.relays||[]).map(u=>utf8Encoder3.encode(u)),2:e.author?[hexToBytes2(e.author)]:[],3:t?[new Uint8Array(t)]:[]});return encodeBech32("nevent",a)}function naddrEncode(e){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,e.kind,!1);let a=encodeTLV({0:[utf8Encoder3.encode(e.identifier)],1:(e.relays||[]).map(u=>utf8Encoder3.encode(u)),2:[hexToBytes2(e.pubkey)],3:[new Uint8Array(t)]});return encodeBech32("naddr",a)}function encodeTLV(e){let t=[];return Object.entries(e).reverse().forEach(([a,u])=>{u.forEach(d=>{let h=new Uint8Array(d.length+2);h.set([parseInt(a)],0),h.set([d.length],1),h.set(d,2),t.push(h)})}),concatBytes3(...t)}var nip04_exports={};__export2(nip04_exports,{decrypt:()=>decrypt2,encrypt:()=>encrypt2});function encrypt2(e,t,a){const u=e instanceof Uint8Array?bytesToHex2(e):e,d=secp256k1.getSharedSecret(u,"02"+t),h=getNormalizedX(d);let w=Uint8Array.from(randomBytes2(16)),x=utf8Encoder3.encode(a),M=cbc(h,w).encrypt(x),B=base64.encode(new Uint8Array(M)),E=base64.encode(new Uint8Array(w.buffer));return`${B}?iv=${E}`}function decrypt2(e,t,a){const u=e instanceof Uint8Array?bytesToHex2(e):e;let[d,h]=a.split("?iv="),w=secp256k1.getSharedSecret(u,"02"+t),x=getNormalizedX(w),M=base64.decode(h),B=base64.decode(d),E=cbc(x,M).decrypt(B);return utf8Decoder3.decode(E)}function getNormalizedX(e){return e.slice(1,33)}var nip05_exports={};__export2(nip05_exports,{NIP05_REGEX:()=>NIP05_REGEX,isNip05:()=>isNip05,isValid:()=>isValid,queryProfile:()=>queryProfile,searchDomain:()=>searchDomain,useFetchImplementation:()=>useFetchImplementation});var NIP05_REGEX=/^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/,isNip05=e=>NIP05_REGEX.test(e||""),_fetch;try{_fetch=fetch}catch(e){}function useFetchImplementation(e){_fetch=e}async function searchDomain(e,t=""){try{const a=`https://${e}/.well-known/nostr.json?name=${t}`,u=await _fetch(a,{redirect:"manual"});if(u.status!==200)throw Error("Wrong response code");return(await u.json()).names}catch{return{}}}async function queryProfile(e){var d;const t=e.match(NIP05_REGEX);if(!t)return null;const[,a="_",u]=t;try{const h=`https://${u}/.well-known/nostr.json?name=${a}`,w=await _fetch(h,{redirect:"manual"});if(w.status!==200)throw Error("Wrong response code");const x=await w.json(),M=x.names[a];return M?{pubkey:M,relays:(d=x.relays)==null?void 0:d[M]}:null}catch{return null}}async function isValid(e,t){const a=await queryProfile(t);return a?a.pubkey===e:!1}var nip10_exports={};__export2(nip10_exports,{parse:()=>parse});function parse(e){const t={reply:void 0,root:void 0,mentions:[],profiles:[],quotes:[]};let a,u;for(let d=e.tags.length-1;d>=0;d--){const h=e.tags[d];if(h[0]==="e"&&h[1]){const[w,x,M,B,E]=h,S={id:x,relays:M?[M]:[],author:E};if(B==="root"){t.root=S;continue}if(B==="reply"){t.reply=S;continue}if(B==="mention"){t.mentions.push(S);continue}a?u=S:a=S,t.mentions.push(S);continue}if(h[0]==="q"&&h[1]){const[w,x,M]=h;t.quotes.push({id:x,relays:M?[M]:[]})}if(h[0]==="p"&&h[1]){t.profiles.push({pubkey:h[1],relays:h[2]?[h[2]]:[]});continue}}return t.root||(t.root=u||a||t.reply),t.reply||(t.reply=a||t.root),[t.reply,t.root].forEach(d=>{if(!d)return;let h=t.mentions.indexOf(d);if(h!==-1&&t.mentions.splice(h,1),d.author){let w=t.profiles.find(x=>x.pubkey===d.author);w&&w.relays&&(d.relays||(d.relays=[]),w.relays.forEach(x=>{var M;((M=d.relays)==null?void 0:M.indexOf(x))===-1&&d.relays.push(x)}),w.relays=d.relays)}}),t.mentions.forEach(d=>{if(d.author){let h=t.profiles.find(w=>w.pubkey===d.author);h&&h.relays&&(d.relays||(d.relays=[]),h.relays.forEach(w=>{d.relays.indexOf(w)===-1&&d.relays.push(w)}),h.relays=d.relays)}}),t}var nip11_exports={};__export2(nip11_exports,{fetchRelayInformation:()=>fetchRelayInformation,useFetchImplementation:()=>useFetchImplementation2});var _fetch2;try{_fetch2=fetch}catch{}function useFetchImplementation2(e){_fetch2=e}async function fetchRelayInformation(e){return await(await fetch(e.replace("ws://","http://").replace("wss://","https://"),{headers:{Accept:"application/nostr+json"}})).json()}var nip13_exports={};__export2(nip13_exports,{fastEventHash:()=>fastEventHash,getPow:()=>getPow,minePow:()=>minePow});function getPow(e){let t=0;for(let a=0;a<64;a+=8){const u=parseInt(e.substring(a,a+8),16);if(u===0)t+=32;else{t+=Math.clz32(u);break}}return t}function minePow(e,t){let a=0;const u=e,d=["nonce",a.toString(),t.toString()];for(u.tags.push(d);;){const h=Math.floor(new Date().getTime()/1e3);if(h!==u.created_at&&(a=0,u.created_at=h),d[1]=(++a).toString(),u.id=fastEventHash(u),getPow(u.id)>=t)break}return u}function fastEventHash(e){return bytesToHex2(sha2562(utf8Encoder3.encode(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]))))}var nip17_exports={};__export2(nip17_exports,{unwrapEvent:()=>unwrapEvent2,unwrapManyEvents:()=>unwrapManyEvents2,wrapEvent:()=>wrapEvent2,wrapManyEvents:()=>wrapManyEvents2});var nip59_exports={};__export2(nip59_exports,{createRumor:()=>createRumor,createSeal:()=>createSeal,createWrap:()=>createWrap,unwrapEvent:()=>unwrapEvent,unwrapManyEvents:()=>unwrapManyEvents,wrapEvent:()=>wrapEvent,wrapManyEvents:()=>wrapManyEvents});var nip44_exports={};__export2(nip44_exports,{decrypt:()=>decrypt22,encrypt:()=>encrypt22,getConversationKey:()=>getConversationKey,v2:()=>v2});var minPlaintextSize=1,maxPlaintextSize=65535;function getConversationKey(e,t){const a=secp256k1.getSharedSecret(e,"02"+t).subarray(1,33);return extract(sha2562,a,"nip44-v2")}function getMessageKeys(e,t){const a=expand(sha2562,e,t,76);return{chacha_key:a.subarray(0,32),chacha_nonce:a.subarray(32,44),hmac_key:a.subarray(44,76)}}function calcPaddedLen(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;const t=1<<Math.floor(Math.log2(e-1))+1,a=t<=256?32:t/8;return a*(Math.floor((e-1)/a)+1)}function writeU16BE(e){if(!Number.isSafeInteger(e)||e<minPlaintextSize||e>maxPlaintextSize)throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");const t=new Uint8Array(2);return new DataView(t.buffer).setUint16(0,e,!1),t}function pad(e){const t=utf8Encoder3.encode(e),a=t.length,u=writeU16BE(a),d=new Uint8Array(calcPaddedLen(a)-a);return concatBytes3(u,t,d)}function unpad(e){const t=new DataView(e.buffer).getUint16(0),a=e.subarray(2,2+t);if(t<minPlaintextSize||t>maxPlaintextSize||a.length!==t||e.length!==2+calcPaddedLen(t))throw new Error("invalid padding");return utf8Decoder3.decode(a)}function hmacAad(e,t,a){if(a.length!==32)throw new Error("AAD associated data must be 32 bytes");const u=concatBytes3(a,t);return hmac2(sha2562,e,u)}function decodePayload(e){if(typeof e!="string")throw new Error("payload must be a valid string");const t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if(e[0]==="#")throw new Error("unknown encryption version");let a;try{a=base64.decode(e)}catch(h){throw new Error("invalid base64: "+h.message)}const u=a.length;if(u<99||u>65603)throw new Error("invalid data length: "+u);const d=a[0];if(d!==2)throw new Error("unknown encryption version "+d);return{nonce:a.subarray(1,33),ciphertext:a.subarray(33,-32),mac:a.subarray(-32)}}function encrypt22(e,t,a=randomBytes2(32)){const{chacha_key:u,chacha_nonce:d,hmac_key:h}=getMessageKeys(t,a),w=pad(e),x=chacha20(u,d,w),M=hmacAad(h,x,a);return base64.encode(concatBytes3(new Uint8Array([2]),a,x,M))}function decrypt22(e,t){const{nonce:a,ciphertext:u,mac:d}=decodePayload(e),{chacha_key:h,chacha_nonce:w,hmac_key:x}=getMessageKeys(t,a),M=hmacAad(x,u,a);if(!equalBytes2(M,d))throw new Error("invalid MAC");const B=chacha20(h,w,u);return unpad(B)}var v2={utils:{getConversationKey,calcPaddedLen},encrypt:encrypt22,decrypt:decrypt22},TWO_DAYS=2*24*60*60,now=()=>Math.round(Date.now()/1e3),randomNow=()=>Math.round(now()-Math.random()*TWO_DAYS),nip44ConversationKey=(e,t)=>getConversationKey(e,t),nip44Encrypt=(e,t,a)=>encrypt22(JSON.stringify(e),nip44ConversationKey(t,a)),nip44Decrypt=(e,t)=>JSON.parse(decrypt22(e.content,nip44ConversationKey(t,e.pubkey)));function createRumor(e,t){const a={created_at:now(),content:"",tags:[],...e,pubkey:getPublicKey2(t)};return a.id=getEventHash2(a),a}function createSeal(e,t,a){return finalizeEvent2({kind:Seal,content:nip44Encrypt(e,t,a),created_at:randomNow(),tags:[]},t)}function createWrap(e,t){const a=generateSecretKey2();return finalizeEvent2({kind:GiftWrap,content:nip44Encrypt(e,a,t),created_at:randomNow(),tags:[["p",t]]},a)}function wrapEvent(e,t,a){const u=createRumor(e,t),d=createSeal(u,t,a);return createWrap(d,a)}function wrapManyEvents(e,t,a){if(!a||a.length===0)throw new Error("At least one recipient is required.");const u=getPublicKey2(t),d=[wrapEvent(e,t,u)];return a.forEach(h=>{d.push(wrapEvent(e,t,h))}),d}function unwrapEvent(e,t){const a=nip44Decrypt(e,t);return nip44Decrypt(a,t)}function unwrapManyEvents(e,t){let a=[];return e.forEach(u=>{a.push(unwrapEvent(u,t))}),a.sort((u,d)=>u.created_at-d.created_at),a}function createEvent(e,t,a,u){const d={created_at:Math.ceil(Date.now()/1e3),kind:PrivateDirectMessage,tags:[],content:t};return(Array.isArray(e)?e:[e]).forEach(({publicKey:w,relayUrl:x})=>{d.tags.push(x?["p",w,x]:["p",w])}),u&&d.tags.push(["e",u.eventId,u.relayUrl||"","reply"]),a&&d.tags.push(["subject",a]),d}function wrapEvent2(e,t,a,u,d){const h=createEvent(t,a,u,d);return wrapEvent(h,e,t.publicKey)}function wrapManyEvents2(e,t,a,u,d){if(!t||t.length===0)throw new Error("At least one recipient is required.");return[{publicKey:getPublicKey2(e)},...t].map(w=>wrapEvent2(e,w,a,u,d))}var unwrapEvent2=unwrapEvent,unwrapManyEvents2=unwrapManyEvents,nip18_exports={};__export2(nip18_exports,{finishRepostEvent:()=>finishRepostEvent,getRepostedEvent:()=>getRepostedEvent,getRepostedEventPointer:()=>getRepostedEventPointer});function finishRepostEvent(e,t,a,u){var w;let d;const h=[...e.tags??[],["e",t.id,a],["p",t.pubkey]];return t.kind===ShortTextNote?d=Repost:(d=GenericRepost,h.push(["k",String(t.kind)])),finalizeEvent2({kind:d,tags:h,content:e.content===""||(w=t.tags)!=null&&w.find(x=>x[0]==="-")?"":JSON.stringify(t),created_at:e.created_at},u)}function getRepostedEventPointer(e){if(![Repost,GenericRepost].includes(e.kind))return;let t,a;for(let u=e.tags.length-1;u>=0&&(t===void 0||a===void 0);u--){const d=e.tags[u];d.length>=2&&(d[0]==="e"&&t===void 0?t=d:d[0]==="p"&&a===void 0&&(a=d))}if(t!==void 0)return{id:t[1],relays:[t[2],a==null?void 0:a[2]].filter(u=>typeof u=="string"),author:a==null?void 0:a[1]}}function getRepostedEvent(e,{skipVerification:t}={}){const a=getRepostedEventPointer(e);if(a===void 0||e.content==="")return;let u;try{u=JSON.parse(e.content)}catch{return}if(u.id===a.id&&!(!t&&!verifyEvent2(u)))return u}var nip21_exports={};__export2(nip21_exports,{NOSTR_URI_REGEX:()=>NOSTR_URI_REGEX,parse:()=>parse2,test:()=>test});var NOSTR_URI_REGEX=new RegExp(`nostr:(${BECH32_REGEX.source})`);function test(e){return typeof e=="string"&&new RegExp(`^${NOSTR_URI_REGEX.source}$`).test(e)}function parse2(e){const t=e.match(new RegExp(`^${NOSTR_URI_REGEX.source}$`));if(!t)throw new Error(`Invalid Nostr URI: ${e}`);return{uri:t[0],value:t[1],decoded:decode(t[1])}}var nip25_exports={};__export2(nip25_exports,{finishReactionEvent:()=>finishReactionEvent,getReactedEventPointer:()=>getReactedEventPointer});function finishReactionEvent(e,t,a){const u=t.tags.filter(d=>d.length>=2&&(d[0]==="e"||d[0]==="p"));return finalizeEvent2({...e,kind:Reaction,tags:[...e.tags??[],...u,["e",t.id],["p",t.pubkey]],content:e.content??"+"},a)}function getReactedEventPointer(e){if(e.kind!==Reaction)return;let t,a;for(let u=e.tags.length-1;u>=0&&(t===void 0||a===void 0);u--){const d=e.tags[u];d.length>=2&&(d[0]==="e"&&t===void 0?t=d:d[0]==="p"&&a===void 0&&(a=d))}if(!(t===void 0||a===void 0))return{id:t[1],relays:[t[2],a[2]].filter(u=>u!==void 0),author:a[1]}}var nip27_exports={};__export2(nip27_exports,{parse:()=>parse3});var noCharacter=/\W/m,noURLCharacter=/[^\w\/] |[^\w\/]$|$|,| /m,MAX_HASHTAG_LENGTH=42;function*parse3(e){let t=[];if(typeof e!="string"){for(let h=0;h<e.tags.length;h++){const w=e.tags[h];w[0]==="emoji"&&w.length>=3&&t.push({type:"emoji",shortcode:w[1],url:w[2]})}e=e.content}const a=e.length;let u=0,d=0;e:for(;d<a;){const h=e.indexOf(":",d),w=e.indexOf("#",d);if(h===-1&&w===-1)break e;if(h===-1||w>=0&&w<h){if(w===0||e[w-1]===" "){const x=e.slice(w+1,w+MAX_HASHTAG_LENGTH).match(noCharacter),M=x?w+1+x.index:a;yield{type:"text",text:e.slice(u,w)},yield{type:"hashtag",value:e.slice(w+1,M)},d=M,u=d;continue e}d=w+1;continue e}if(e.slice(h-5,h)==="nostr"){const x=e.slice(h+60).match(noCharacter),M=x?h+60+x.index:a;try{let B,{data:E,type:S}=decode(e.slice(h+1,M));switch(S){case"npub":B={pubkey:E};break;case"note":B={id:E};break;case"nsec":d=M+1;continue;default:B=E}u!==h-5&&(yield{type:"text",text:e.slice(u,h-5)}),yield{type:"reference",pointer:B},d=M,u=d;continue e}catch{d=h+1;continue e}}else if(e.slice(h-5,h)==="https"||e.slice(h-4,h)==="http"){const x=e.slice(h+4).match(noURLCharacter),M=x?h+4+x.index:a,B=e[h-1]==="s"?5:4;try{let E=new URL(e.slice(h-B,M));if(E.hostname.indexOf(".")===-1)throw new Error("invalid url");if(u!==h-B&&(yield{type:"text",text:e.slice(u,h-B)}),/\.(png|jpe?g|gif|webp|heic|svg)$/i.test(E.pathname)){yield{type:"image",url:E.toString()},d=M,u=d;continue e}if(/\.(mp4|avi|webm|mkv|mov)$/i.test(E.pathname)){yield{type:"video",url:E.toString()},d=M,u=d;continue e}if(/\.(mp3|aac|ogg|opus|wav|flac)$/i.test(E.pathname)){yield{type:"audio",url:E.toString()},d=M,u=d;continue e}yield{type:"url",url:E.toString()},d=M,u=d;continue e}catch{d=M+1;continue e}}else if(e.slice(h-3,h)==="wss"||e.slice(h-2,h)==="ws"){const x=e.slice(h+4).match(noURLCharacter),M=x?h+4+x.index:a,B=e[h-1]==="s"?3:2;try{let E=new URL(e.slice(h-B,M));if(E.hostname.indexOf(".")===-1)throw new Error("invalid ws url");u!==h-B&&(yield{type:"text",text:e.slice(u,h-B)}),yield{type:"relay",url:E.toString()},d=M,u=d;continue e}catch{d=M+1;continue e}}else{for(let x=0;x<t.length;x++){const M=t[x];if(e[h+M.shortcode.length+1]===":"&&e.slice(h+1,h+M.shortcode.length+1)===M.shortcode){u!==h&&(yield{type:"text",text:e.slice(u,h)}),yield M,d=h+M.shortcode.length+2,u=d;continue e}}d=h+1;continue e}}u!==a&&(yield{type:"text",text:e.slice(u)})}var nip28_exports={};__export2(nip28_exports,{channelCreateEvent:()=>channelCreateEvent,channelHideMessageEvent:()=>channelHideMessageEvent,channelMessageEvent:()=>channelMessageEvent,channelMetadataEvent:()=>channelMetadataEvent,channelMuteUserEvent:()=>channelMuteUserEvent});var channelCreateEvent=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent2({kind:ChannelCreation,tags:[...e.tags??[]],content:a,created_at:e.created_at},t)},channelMetadataEvent=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent2({kind:ChannelMetadata,tags:[["e",e.channel_create_event_id],...e.tags??[]],content:a,created_at:e.created_at},t)},channelMessageEvent=(e,t)=>{const a=[["e",e.channel_create_event_id,e.relay_url,"root"]];return e.reply_to_channel_message_event_id&&a.push(["e",e.reply_to_channel_message_event_id,e.relay_url,"reply"]),finalizeEvent2({kind:ChannelMessage,tags:[...a,...e.tags??[]],content:e.content,created_at:e.created_at},t)},channelHideMessageEvent=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent2({kind:ChannelHideMessage,tags:[["e",e.channel_message_event_id],...e.tags??[]],content:a,created_at:e.created_at},t)},channelMuteUserEvent=(e,t)=>{let a;if(typeof e.content=="object")a=JSON.stringify(e.content);else if(typeof e.content=="string")a=e.content;else return;return finalizeEvent2({kind:ChannelMuteUser,tags:[["p",e.pubkey_to_mute],...e.tags??[]],content:a,created_at:e.created_at},t)},nip30_exports={};__export2(nip30_exports,{EMOJI_SHORTCODE_REGEX:()=>EMOJI_SHORTCODE_REGEX,matchAll:()=>matchAll,regex:()=>regex,replaceAll:()=>replaceAll});var EMOJI_SHORTCODE_REGEX=/:(\w+):/,regex=()=>new RegExp(`\\B${EMOJI_SHORTCODE_REGEX.source}\\B`,"g");function*matchAll(e){const t=e.matchAll(regex());for(const a of t)try{const[u,d]=a;yield{shortcode:u,name:d,start:a.index,end:a.index+u.length}}catch{}}function replaceAll(e,t){return e.replaceAll(regex(),(a,u)=>t({shortcode:a,name:u}))}var nip39_exports={};__export2(nip39_exports,{useFetchImplementation:()=>useFetchImplementation3,validateGithub:()=>validateGithub});var _fetch3;try{_fetch3=fetch}catch{}function useFetchImplementation3(e){_fetch3=e}async function validateGithub(e,t,a){try{return await(await _fetch3(`https://gist.github.com/${t}/${a}/raw`)).text()===`Verifying that I control the following Nostr public key: ${e}`}catch{return!1}}var nip47_exports={};__export2(nip47_exports,{makeNwcRequestEvent:()=>makeNwcRequestEvent,parseConnectionString:()=>parseConnectionString});function parseConnectionString(e){const{host:t,pathname:a,searchParams:u}=new URL(e),d=a||t,h=u.get("relay"),w=u.get("secret");if(!d||!h||!w)throw new Error("invalid connection string");return{pubkey:d,relay:h,secret:w}}async function makeNwcRequestEvent(e,t,a){const d=encrypt2(t,e,JSON.stringify({method:"pay_invoice",params:{invoice:a}})),h={kind:NWCWalletRequest,created_at:Math.round(Date.now()/1e3),content:d,tags:[["p",e]]};return finalizeEvent2(h,t)}var nip54_exports={};__export2(nip54_exports,{normalizeIdentifier:()=>normalizeIdentifier});function normalizeIdentifier(e){return e=e.trim().toLowerCase(),e=e.normalize("NFKC"),Array.from(e).map(t=>new RegExp("\\p{Letter}","u").test(t)||new RegExp("\\p{Number}","u").test(t)?t:"-").join("")}var nip57_exports={};__export2(nip57_exports,{getSatoshisAmountFromBolt11:()=>getSatoshisAmountFromBolt11,getZapEndpoint:()=>getZapEndpoint,makeZapReceipt:()=>makeZapReceipt,makeZapRequest:()=>makeZapRequest,useFetchImplementation:()=>useFetchImplementation4,validateZapRequest:()=>validateZapRequest});var _fetch4;try{_fetch4=fetch}catch{}function useFetchImplementation4(e){_fetch4=e}async function getZapEndpoint(e){try{let t="",{lud06:a,lud16:u}=JSON.parse(e.content);if(u){let[w,x]=u.split("@");t=new URL(`/.well-known/lnurlp/${w}`,`https://${x}`).toString()}else if(a){let{words:w}=bech32.decode(a,1e3),x=bech32.fromWords(w);t=utf8Decoder3.decode(x)}else return null;let h=await(await _fetch4(t)).json();if(h.allowsNostr&&h.nostrPubkey)return h.callback}catch{}return null}function makeZapRequest(e){let t={kind:9734,created_at:Math.round(Date.now()/1e3),content:e.comment||"",tags:[["p","pubkey"in e?e.pubkey:e.event.pubkey],["amount",e.amount.toString()],["relays",...e.relays]]};if("event"in e){if(t.tags.push(["e",e.event.id]),isReplaceableKind(e.event.kind)){const a=["a",`${e.event.kind}:${e.event.pubkey}:`];t.tags.push(a)}else if(isAddressableKind(e.event.kind)){let a=e.event.tags.find(([d,h])=>d==="d"&&h);if(!a)throw new Error("d tag not found or is empty");const u=["a",`${e.event.kind}:${e.event.pubkey}:${a[1]}`];t.tags.push(u)}t.tags.push(["k",e.event.kind.toString()])}return t}function validateZapRequest(e){let t;try{t=JSON.parse(e)}catch{return"Invalid zap request JSON."}if(!validateEvent2(t))return"Zap request is not a valid Nostr event.";if(!verifyEvent2(t))return"Invalid signature on zap request.";let a=t.tags.find(([h,w])=>h==="p"&&w);if(!a)return"Zap request doesn't have a 'p' tag.";if(!a[1].match(/^[a-f0-9]{64}$/))return"Zap request 'p' tag is not valid hex.";let u=t.tags.find(([h,w])=>h==="e"&&w);return u&&!u[1].match(/^[a-f0-9]{64}$/)?"Zap request 'e' tag is not valid hex.":t.tags.find(([h,w])=>h==="relays"&&w)?null:"Zap request doesn't have a 'relays' tag."}function makeZapReceipt({zapRequest:e,preimage:t,bolt11:a,paidAt:u}){let d=JSON.parse(e),h=d.tags.filter(([x])=>x==="e"||x==="p"||x==="a"),w={kind:9735,created_at:Math.round(u.getTime()/1e3),content:"",tags:[...h,["P",d.pubkey],["bolt11",a],["description",e]]};return t&&w.tags.push(["preimage",t]),w}function getSatoshisAmountFromBolt11(e){if(e.length<50)return 0;e=e.substring(0,50);const t=e.lastIndexOf("1");if(t===-1)return 0;const a=e.substring(0,t);if(!a.startsWith("lnbc"))return 0;const u=a.substring(4);if(u.length<1)return 0;const d=u[u.length-1],h=d.charCodeAt(0)-48,w=h>=0&&h<=9;let x=u.length-1;if(w&&x++,x<1)return 0;const M=parseInt(u.substring(0,x));switch(d){case"m":return M*1e5;case"u":return M*100;case"n":return M/10;case"p":return M/1e4;default:return M*1e8}}var nip77_exports={};__export2(nip77_exports,{Negentropy:()=>Negentropy,NegentropyStorageVector:()=>NegentropyStorageVector,NegentropySync:()=>NegentropySync});var PROTOCOL_VERSION=97,ID_SIZE=32,FINGERPRINT_SIZE=16,Mode={Skip:0,Fingerprint:1,IdList:2},WrappedBuffer=class{constructor(e){_e(this,"_raw");_e(this,"length");typeof e=="number"?(this._raw=new Uint8Array(e),this.length=0):e instanceof Uint8Array?(this._raw=new Uint8Array(e),this.length=e.length):(this._raw=new Uint8Array(512),this.length=0)}unwrap(){return this._raw.subarray(0,this.length)}get capacity(){return this._raw.byteLength}extend(e){if(e instanceof WrappedBuffer&&(e=e.unwrap()),typeof e.length!="number")throw Error("bad length");const t=e.length+this.length;if(this.capacity<t){const a=this._raw,u=Math.max(this.capacity*2,t);this._raw=new Uint8Array(u),this._raw.set(a)}this._raw.set(e,this.length),this.length+=e.length}shift(){const e=this._raw[0];return this._raw=this._raw.subarray(1),this.length--,e}shiftN(e=1){const t=this._raw.subarray(0,e);return this._raw=this._raw.subarray(e),this.length-=e,t}};function decodeVarInt(e){let t=0;for(;;){if(e.length===0)throw Error("parse ends prematurely");let a=e.shift();if(t=t<<7|a&127,!(a&128))break}return t}function encodeVarInt(e){if(e===0)return new WrappedBuffer(new Uint8Array([0]));let t=[];for(;e!==0;)t.push(e&127),e>>>=7;t.reverse();for(let a=0;a<t.length-1;a++)t[a]|=128;return new WrappedBuffer(new Uint8Array(t))}function getByte(e){return getBytes(e,1)[0]}function getBytes(e,t){if(e.length<t)throw Error("parse ends prematurely");return e.shiftN(t)}var Accumulator=class{constructor(){_e(this,"buf");this.setToZero()}setToZero(){this.buf=new Uint8Array(ID_SIZE)}add(e){let t=0,a=0,u=new DataView(this.buf.buffer),d=new DataView(e.buffer);for(let h=0;h<8;h++){let w=h*4,x=u.getUint32(w,!0),M=d.getUint32(w,!0),B=x;B+=t,B+=M,B>4294967295&&(a=1),u.setUint32(w,B&4294967295,!0),t=a,a=0}}negate(){let e=new DataView(this.buf.buffer);for(let a=0;a<8;a++){let u=a*4;e.setUint32(u,~e.getUint32(u,!0))}let t=new Uint8Array(ID_SIZE);t[0]=1,this.add(t)}getFingerprint(e){let t=new WrappedBuffer;return t.extend(this.buf),t.extend(encodeVarInt(e)),sha2562(t.unwrap()).subarray(0,FINGERPRINT_SIZE)}},NegentropyStorageVector=class{constructor(){_e(this,"items");_e(this,"sealed");this.items=[],this.sealed=!1}insert(e,t){if(this.sealed)throw Error("already sealed");const a=hexToBytes3(t);if(a.byteLength!==ID_SIZE)throw Error("bad id size for added item");this.items.push({timestamp:e,id:a})}seal(){if(this.sealed)throw Error("already sealed");this.sealed=!0,this.items.sort(itemCompare);for(let e=1;e<this.items.length;e++)if(itemCompare(this.items[e-1],this.items[e])===0)throw Error("duplicate item inserted")}unseal(){this.sealed=!1}size(){return this._checkSealed(),this.items.length}getItem(e){if(this._checkSealed(),e>=this.items.length)throw Error("out of range");return this.items[e]}iterate(e,t,a){this._checkSealed(),this._checkBounds(e,t);for(let u=e;u<t&&a(this.items[u],u);++u);}findLowerBound(e,t,a){return this._checkSealed(),this._checkBounds(e,t),this._binarySearch(this.items,e,t,u=>itemCompare(u,a)<0)}fingerprint(e,t){let a=new Accumulator;return a.setToZero(),this.iterate(e,t,u=>(a.add(u.id),!0)),a.getFingerprint(t-e)}_checkSealed(){if(!this.sealed)throw Error("not sealed")}_checkBounds(e,t){if(e>t||t>this.items.length)throw Error("bad range")}_binarySearch(e,t,a,u){let d=a-t;for(;d>0;){let h=t,w=Math.floor(d/2);h+=w,u(e[h])?(t=++h,d-=w+1):d=w}return t}},Negentropy=class{constructor(e,t=6e4){_e(this,"storage");_e(this,"frameSizeLimit");_e(this,"lastTimestampIn");_e(this,"lastTimestampOut");if(t<4096)throw Error("frameSizeLimit too small");this.storage=e,this.frameSizeLimit=t,this.lastTimestampIn=0,this.lastTimestampOut=0}_bound(e,t){return{timestamp:e,id:t||new Uint8Array(0)}}initiate(){let e=new WrappedBuffer;return e.extend(new Uint8Array([PROTOCOL_VERSION])),this.splitRange(0,this.storage.size(),this._bound(Number.MAX_VALUE),e),bytesToHex3(e.unwrap())}reconcile(e,t,a){const u=new WrappedBuffer(hexToBytes3(e));this.lastTimestampIn=this.lastTimestampOut=0;let d=new WrappedBuffer;d.extend(new Uint8Array([PROTOCOL_VERSION]));let h=getByte(u);if(h<96||h>111)throw Error("invalid negentropy protocol version byte");if(h!==PROTOCOL_VERSION)throw Error("unsupported negentropy protocol version requested: "+(h-96));let w=this.storage.size(),x=this._bound(0),M=0,B=!1;for(;u.length!==0;){let E=new WrappedBuffer,S=()=>{B&&(B=!1,E.extend(this.encodeBound(x)),E.extend(encodeVarInt(Mode.Skip)))},k=this.decodeBound(u),C=decodeVarInt(u),D=M,O=this.storage.findLowerBound(M,w,k);if(C===Mode.Skip)B=!0;else if(C===Mode.Fingerprint){let F=getBytes(u,FINGERPRINT_SIZE),P=this.storage.fingerprint(D,O);compareUint8Array(F,P)!==0?(S(),this.splitRange(D,O,k,E)):B=!0}else if(C===Mode.IdList){let F=decodeVarInt(u),P={};for(let L=0;L<F;L++){let J=getBytes(u,ID_SIZE);P[bytesToHex3(J)]=J}if(B=!0,this.storage.iterate(D,O,L=>{let J=L.id;const Y=bytesToHex3(J);return P[Y]?delete P[bytesToHex3(J)]:t==null||t(Y),!0}),a)for(let L of Object.values(P))a(bytesToHex3(L))}else throw Error("unexpected mode");if(this.exceededFrameSizeLimit(d.length+E.length)){let F=this.storage.fingerprint(O,w);d.extend(this.encodeBound(this._bound(Number.MAX_VALUE))),d.extend(encodeVarInt(Mode.Fingerprint)),d.extend(F);break}else d.extend(E);M=O,x=k}return d.length===1?null:bytesToHex3(d.unwrap())}splitRange(e,t,a,u){let d=t-e,h=16;if(d<h*2)u.extend(this.encodeBound(a)),u.extend(encodeVarInt(Mode.IdList)),u.extend(encodeVarInt(d)),this.storage.iterate(e,t,w=>(u.extend(w.id),!0));else{let w=Math.floor(d/h),x=d%h,M=e;for(let B=0;B<h;B++){let E=w+(B<x?1:0),S=this.storage.fingerprint(M,M+E);M+=E;let k;if(M===t)k=a;else{let C,D;this.storage.iterate(M-1,M+1,(O,F)=>(F===M-1?C=O:D=O,!0)),k=this.getMinimalBound(C,D)}u.extend(this.encodeBound(k)),u.extend(encodeVarInt(Mode.Fingerprint)),u.extend(S)}}}exceededFrameSizeLimit(e){return e>this.frameSizeLimit-200}decodeTimestampIn(e){let t=decodeVarInt(e);return t=t===0?Number.MAX_VALUE:t-1,this.lastTimestampIn===Number.MAX_VALUE||t===Number.MAX_VALUE?(this.lastTimestampIn=Number.MAX_VALUE,Number.MAX_VALUE):(t+=this.lastTimestampIn,this.lastTimestampIn=t,t)}decodeBound(e){let t=this.decodeTimestampIn(e),a=decodeVarInt(e);if(a>ID_SIZE)throw Error("bound key too long");let u=getBytes(e,a);return{timestamp:t,id:u}}encodeTimestampOut(e){if(e===Number.MAX_VALUE)return this.lastTimestampOut=Number.MAX_VALUE,encodeVarInt(0);let t=e;return e-=this.lastTimestampOut,this.lastTimestampOut=t,encodeVarInt(e+1)}encodeBound(e){let t=new WrappedBuffer;return t.extend(this.encodeTimestampOut(e.timestamp)),t.extend(encodeVarInt(e.id.length)),t.extend(e.id),t}getMinimalBound(e,t){if(t.timestamp!==e.timestamp)return this._bound(t.timestamp);{let a=0,u=t.id,d=e.id;for(let h=0;h<ID_SIZE&&u[h]===d[h];h++)a++;return this._bound(t.timestamp,t.id.subarray(0,a+1))}}};function compareUint8Array(e,t){for(let a=0;a<e.byteLength;a++){if(e[a]<t[a])return-1;if(e[a]>t[a])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function itemCompare(e,t){return e.timestamp===t.timestamp?compareUint8Array(e.id,t.id):e.timestamp-t.timestamp}var NegentropySync=class{constructor(e,t,a,u={}){_e(this,"relay");_e(this,"storage");_e(this,"neg");_e(this,"filter");_e(this,"subscription");_e(this,"onhave");_e(this,"onneed");this.relay=e,this.storage=t,this.neg=new Negentropy(t),this.onhave=u.onhave,this.onneed=u.onneed,this.filter=a,this.subscription=this.relay.prepareSubscription([{}],{label:u.label||"negentropy"}),this.subscription.oncustom=d=>{var h,w,x,M;switch(d[0]){case"NEG-MSG":{d.length<3&&console.warn(`got invalid NEG-MSG from ${this.relay.url}: ${d}`);try{const B=this.neg.reconcile(d[2],this.onhave,this.onneed);B?this.relay.send(`["NEG-MSG", "${this.subscription.id}", "${B}"]`):(this.close(),(h=u.onclose)==null||h.call(u))}catch(B){console.error("negentropy reconcile error:",B),(w=u==null?void 0:u.onclose)==null||w.call(u,`reconcile error: ${B}`)}break}case"NEG-CLOSE":{const B=d[2];console.warn("negentropy error:",B),(x=u.onclose)==null||x.call(u,B);break}case"NEG-ERR":(M=u.onclose)==null||M.call(u)}}}async start(){const e=this.neg.initiate();this.relay.send(`["NEG-OPEN","${this.subscription.id}",${JSON.stringify(this.filter)},"${e}"]`)}close(){this.relay.send(`["NEG-CLOSE","${this.subscription.id}"]`),this.subscription.close()}},nip98_exports={};__export2(nip98_exports,{getToken:()=>getToken,hashPayload:()=>hashPayload,unpackEventFromToken:()=>unpackEventFromToken,validateEvent:()=>validateEvent22,validateEventKind:()=>validateEventKind,validateEventMethodTag:()=>validateEventMethodTag,validateEventPayloadTag:()=>validateEventPayloadTag,validateEventTimestamp:()=>validateEventTimestamp,validateEventUrlTag:()=>validateEventUrlTag,validateToken:()=>validateToken});var _authorizationScheme="Nostr ";async function getToken(e,t,a,u=!1,d){const h={kind:HTTPAuth,tags:[["u",e],["method",t]],created_at:Math.round(new Date().getTime()/1e3),content:""};d&&h.tags.push(["payload",hashPayload(d)]);const w=await a(h);return(u?_authorizationScheme:"")+base64.encode(utf8Encoder3.encode(JSON.stringify(w)))}async function validateToken(e,t,a){const u=await unpackEventFromToken(e).catch(h=>{throw h});return await validateEvent22(u,t,a).catch(h=>{throw h})}async function unpackEventFromToken(e){if(!e)throw new Error("Missing token");e=e.replace(_authorizationScheme,"");const t=utf8Decoder3.decode(base64.decode(e));if(!t||t.length===0||!t.startsWith("{"))throw new Error("Invalid token");return JSON.parse(t)}function validateEventTimestamp(e){return e.created_at?Math.round(new Date().getTime()/1e3)-e.created_at<60:!1}function validateEventKind(e){return e.kind===HTTPAuth}function validateEventUrlTag(e,t){const a=e.tags.find(u=>u[0]==="u");return a?a.length>0&&a[1]===t:!1}function validateEventMethodTag(e,t){const a=e.tags.find(u=>u[0]==="method");return a?a.length>0&&a[1].toLowerCase()===t.toLowerCase():!1}function hashPayload(e){const t=sha2562(utf8Encoder3.encode(JSON.stringify(e)));return bytesToHex2(t)}function validateEventPayloadTag(e,t){const a=e.tags.find(d=>d[0]==="payload");if(!a)return!1;const u=hashPayload(t);return a.length>0&&a[1]===u}async function validateEvent22(e,t,a,u){if(!verifyEvent2(e))throw new Error("Invalid nostr event, signature invalid");if(!validateEventKind(e))throw new Error("Invalid nostr event, kind invalid");if(!validateEventTimestamp(e))throw new Error("Invalid nostr event, created_at timestamp invalid");if(!validateEventUrlTag(e,t))throw new Error("Invalid nostr event, url tag invalid");if(!validateEventMethodTag(e,a))throw new Error("Invalid nostr event, method tag invalid");if(u&&typeof u=="object"&&Object.keys(u).length>0&&!validateEventPayloadTag(e,u))throw new Error("Invalid nostr event, payload tag does not match request body hash");return!0}var PRIVATE_TAG="private",PRIVATE_RECIPIENTS_TAG="privateRecipients",HEX_REGEX=/^[0-9a-f]{64}$/i;function normalizeHexPubkey(e){if(typeof e!="string")throw new Error("Pubkey must be a string");const t=e.toLowerCase();if(HEX_REGEX.test(t))return t;try{const a=nip19_exports.decode(e);if(a.type==="npub"&&typeof a.data=="string")return a.data.toLowerCase()}catch{}throw new Error("Unsupported pubkey format")}function toNpub(e){return nip19_exports.npubEncode(e)}function toUint8ArrayKey(e){if(typeof e=="string")return hexToBytes2(e);if(e instanceof Uint8Array)return e;throw new Error("Private key must be a hex string or Uint8Array")}function createNip44Encryptor(e){if(typeof e=="string"||e instanceof Uint8Array){const t=toUint8ArrayKey(e);return async(a,u)=>{const d=nip44_exports.getConversationKey(t,a);return nip44_exports.encrypt(u,d)}}if(e&&typeof e=="object"){if(typeof e.nip44Encrypt=="function"){const t=e.nip44Encrypt.bind(e);return(a,u)=>Promise.resolve(t(a,u))}if(e.nip04&&typeof e.nip04.encrypt=="function"){const t=e.nip04.encrypt.bind(e.nip04);return(a,u)=>Promise.resolve(t(a,u))}}throw new Error("Unsupported owner signer; must be private key or NIP-44/NIP-04 capable signer")}function createNip44Decryptor(e){if(typeof e=="string"||e instanceof Uint8Array){const t=toUint8ArrayKey(e);return async(a,u)=>{const d=nip44_exports.getConversationKey(t,a);return nip44_exports.decrypt(u,d)}}if(e&&typeof e=="object"){if(typeof e.nip44Decrypt=="function"){const t=e.nip44Decrypt.bind(e);return(a,u)=>Promise.resolve(t(a,u))}if(e.nip04&&typeof e.nip04.decrypt=="function"){const t=e.nip04.decrypt.bind(e.nip04);return(a,u)=>Promise.resolve(t(a,u))}}throw new Error("Unsupported recipient signer; must be private key or NIP-44/NIP-04 capable signer")}async function resolveRecipientPubkey(e){if(typeof e=="string"||e instanceof Uint8Array)return normalizeHexPubkey(getPublicKey(toUint8ArrayKey(e)));if(e&&typeof e.getPublicKey=="function"){const t=await e.getPublicKey();return normalizeHexPubkey(t)}throw new Error("Recipient must provide a private key or a NIP signer with getPublicKey()")}function parsePrivateFlag(e){if(!Array.isArray(e))return null;const t=e.find(u=>Array.isArray(u)&&u[0]===PRIVATE_TAG);if(!t||typeof t[1]!="string")return null;const a=t[1].toLowerCase();return a==="true"?!0:a==="false"?!1:null}function collectPrivateRecipients(e){return Array.isArray(e)?e.filter(t=>Array.isArray(t)&&t[0]===PRIVATE_RECIPIENTS_TAG&&typeof t[1]=="string").map(t=>t[1]):[]}async function encryptPrivateRecipients(e,t){if(!Array.isArray(t))throw new Error("recipients must be an array of pubkeys");const a=createNip44Encryptor(e),u=[];for(const d of t){const h=normalizeHexPubkey(d),w=toNpub(h);u.push(await a(h,w))}return u}async function isPrivateRecipientAuthorized(e,t,a){if(!Array.isArray(e)||e.length===0)return!1;const u=normalizeHexPubkey(t),d=await resolveRecipientPubkey(a),h=toNpub(normalizeHexPubkey(d)),w=createNip44Decryptor(a);for(const x of e)try{if(await w(u,x)===h)return!0}catch{}return!1}var NCC02Error=class extends Error{constructor(e,t,a){super(t),this.code=e,a&&(this.cause=a)}},NCC02Resolver=class{constructor(e,t={}){if(!Array.isArray(e))throw new Error("NCC02Resolver expects an array of relay URLs.");this.relays=e,this.pool=t.pool||new SimplePool,this.ownsPool=!t.pool,this.trustedCAPubkeys=new Set(t.trustedCAPubkeys||[])}close(){this.ownsPool&&this.pool&&this.pool.close(this.relays)}async _query(e){return new Promise(t=>{const a=[],u=this.pool.subscribeMany(this.relays,[e],{onevent(d){a.push(d)},oneose(){u.close(),t(a)}})})}_freshestEvent(e){return!e||!e.length?null:e.sort((t,a)=>a.created_at!==t.created_at?a.created_at-t.created_at:t.id.localeCompare(a.id))[0]}async _queryFreshest(e){const t=await this._query(e);return this._freshestEvent(t)}async resolve(e,t,a={}){const{requireAttestation:u=!1,minLevel:d=null,standard:h="nostr-service-trust-v0.1"}=a;let w;try{w=await this._queryFreshest({kinds:[KINDS.SERVICE_RECORD],authors:[e],"#d":[t]})}catch(k){throw new NCC02Error("RELAY_ERROR",`Failed to query relay for ${t}`,k)}if(!w)throw new NCC02Error("NOT_FOUND",`No service record found for ${t}`);if(!verifyEvent2(w))throw new NCC02Error("INVALID_SIGNATURE","Service record signature verification failed");const x=Object.fromEntries(w.tags),M=Math.floor(Date.now()/1e3),B=parsePrivateFlag(w.tags);if(B===null)throw new NCC02Error("MALFORMED_RECORD","Service record is missing required tag (private)");if(!x.exp)throw new NCC02Error("MALFORMED_RECORD","Service record is missing required tag (exp)");if(x.u&&(x.u.startsWith("wss://")||x.u.startsWith("https://"))&&!x.k)throw new NCC02Error("MALFORMED_RECORD","Service record with 'https' or 'wss' endpoint must have a 'k' tag");const E=parseInt(x.exp);if(isNaN(E))throw new NCC02Error("MALFORMED_RECORD","Service record expiry tag is not a valid number");if(E<M)throw new NCC02Error("EXPIRED","Service record has expired");let S;try{S=await this._buildTrustData(w,{pubkey:e,serviceId:t,standard:h,minLevel:d})}catch(k){throw new NCC02Error("RELAY_ERROR","Failed to query relay for attestations/revocations",k)}if(u&&S.validAttestations.length===0)throw new NCC02Error("POLICY_FAILURE",`No trusted attestations meet the required policy for ${t}`);return{endpoint:x.u,fingerprint:x.k,expiry:E,attestations:S.validAttestations,attestationCount:S.validAttestations.length,isRevoked:S.isRevoked,isPrivate:B,privateRecipients:collectPrivateRecipients(w.tags),eventId:w.id,pubkey:w.pubkey,serviceEvent:w}}async _buildTrustData(e,t){const a=await this._query({kinds:[KINDS.ATTESTATION],"#e":[e.id]}),u=a.map(M=>M.id);let d=[];u.length&&(d=await this._query({kinds:[KINDS.REVOCATION],"#e":u}));const h=this._groupValidRevocations(d),w=[];let x=!1;for(const M of a){if(!this.trustedCAPubkeys.has(M.pubkey))continue;const B=Object.fromEntries(M.tags);if(B.subj!==t.pubkey||B.srv!==t.serviceId||t.standard&&B.std!==t.standard)continue;const{valid:E,revoked:S}=this._evaluateAttestation(M,B,h[M.id]);if(S){x=!0;continue}E&&(t.minLevel&&!this._isLevelSufficient(B.lvl,t.minLevel)||w.push({pubkey:M.pubkey,level:B.lvl,eventId:M.id}))}return{validAttestations:w,isRevoked:x}}_groupValidRevocations(e){const t={};for(const a of e){if(!verifyEvent2(a))continue;const d=Object.fromEntries(a.tags).e;d&&(t[d]||(t[d]=[]),t[d].push(a))}return t}_evaluateAttestation(e,t,a=[]){for(const d of a)if(d.pubkey===e.pubkey)return{valid:!1,revoked:!0};if(!verifyEvent2(e))return{valid:!1,revoked:!1};const u=Math.floor(Date.now()/1e3);if(t.nbf){const d=parseInt(t.nbf,10);if(isNaN(d)||d>u)return{valid:!1,revoked:!1}}if(t.exp){const d=parseInt(t.exp,10);if(isNaN(d)||d<u)return{valid:!1,revoked:!1}}return{valid:!0,revoked:!1}}_isLevelSufficient(e,t){const a={self:0,verified:1,hardened:2},u=e?a[e]??-1:-1,d=a[t]??0;return u>=d}verifyEndpoint(e,t){return e.fingerprint===t}};/*! Bundled license information:
23
23
 
24
24
  @noble/hashes/esm/utils.js:
25
25
  @noble/hashes/esm/utils.js:
@@ -38,4 +38,4 @@ https://github.com/browserify/crypto-browserify`)},cryptoBrowserify.constants={D
38
38
 
39
39
  @noble/ciphers/esm/utils.js:
40
40
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
41
- */export{NCC05Resolver as N,NCC05Publisher as a,NCC02Resolver as b};
41
+ */export{NCC05Resolver as N,NCC05Publisher as a,NCC02Resolver as b,collectPrivateRecipients as c,NCC02Builder as d,encryptPrivateRecipients as e,isPrivateRecipientAuthorized as i,parsePrivateFlag as p};