@candypoets/nipworker 0.89.1 → 0.90.0

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.
@@ -21,15 +21,15 @@ export interface InitOutput {
21
21
  readonly wsrust_close: (a: number, b: number, c: number) => void;
22
22
  readonly wsrust_new: (a: any, b: any, c: any, d: any, e: any) => [number, number, number];
23
23
  readonly init_tracing: (a: number, b: number) => void;
24
+ readonly wasm_bindgen__convert__closures_____invoke__hbfefea57f0386d0d: (a: number, b: number) => void;
25
+ readonly wasm_bindgen__closure__destroy__h8f3ce6e75229a5a8: (a: number, b: number) => void;
26
+ readonly wasm_bindgen__convert__closures_____invoke__h911638d95040c9f2: (a: number, b: number, c: any) => void;
27
+ readonly wasm_bindgen__closure__destroy__h063e4a13178b0c12: (a: number, b: number) => void;
24
28
  readonly wasm_bindgen__convert__closures_____invoke__h9f24d583ae866fa6: (a: number, b: number, c: any) => void;
25
29
  readonly wasm_bindgen__closure__destroy__h8c04b6ea827d767b: (a: number, b: number) => void;
30
+ readonly wasm_bindgen__convert__closures_____invoke__hd724dca759e5a136: (a: number, b: number) => void;
26
31
  readonly wasm_bindgen__convert__closures_____invoke__h6e43682478e95d85: (a: number, b: number, c: any) => void;
27
32
  readonly wasm_bindgen__closure__destroy__h2312464f5f444124: (a: number, b: number) => void;
28
- readonly wasm_bindgen__convert__closures_____invoke__h911638d95040c9f2: (a: number, b: number, c: any) => void;
29
- readonly wasm_bindgen__closure__destroy__h063e4a13178b0c12: (a: number, b: number) => void;
30
- readonly wasm_bindgen__convert__closures_____invoke__hbfefea57f0386d0d: (a: number, b: number) => void;
31
- readonly wasm_bindgen__closure__destroy__h8f3ce6e75229a5a8: (a: number, b: number) => void;
32
- readonly wasm_bindgen__convert__closures_____invoke__hd724dca759e5a136: (a: number, b: number) => void;
33
33
  readonly __wbindgen_malloc: (a: number, b: number) => number;
34
34
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
35
35
  readonly __wbindgen_exn_store: (a: number) => void;
@@ -5,15 +5,15 @@ export const __wbg_wsrust_free: (a: number, b: number) => void;
5
5
  export const wsrust_close: (a: number, b: number, c: number) => void;
6
6
  export const wsrust_new: (a: any, b: any, c: any, d: any, e: any) => [number, number, number];
7
7
  export const init_tracing: (a: number, b: number) => void;
8
+ export const wasm_bindgen__convert__closures_____invoke__hbfefea57f0386d0d: (a: number, b: number) => void;
9
+ export const wasm_bindgen__closure__destroy__h8f3ce6e75229a5a8: (a: number, b: number) => void;
10
+ export const wasm_bindgen__convert__closures_____invoke__h911638d95040c9f2: (a: number, b: number, c: any) => void;
11
+ export const wasm_bindgen__closure__destroy__h063e4a13178b0c12: (a: number, b: number) => void;
8
12
  export const wasm_bindgen__convert__closures_____invoke__h9f24d583ae866fa6: (a: number, b: number, c: any) => void;
9
13
  export const wasm_bindgen__closure__destroy__h8c04b6ea827d767b: (a: number, b: number) => void;
14
+ export const wasm_bindgen__convert__closures_____invoke__hd724dca759e5a136: (a: number, b: number) => void;
10
15
  export const wasm_bindgen__convert__closures_____invoke__h6e43682478e95d85: (a: number, b: number, c: any) => void;
11
16
  export const wasm_bindgen__closure__destroy__h2312464f5f444124: (a: number, b: number) => void;
12
- export const wasm_bindgen__convert__closures_____invoke__h911638d95040c9f2: (a: number, b: number, c: any) => void;
13
- export const wasm_bindgen__closure__destroy__h063e4a13178b0c12: (a: number, b: number) => void;
14
- export const wasm_bindgen__convert__closures_____invoke__hbfefea57f0386d0d: (a: number, b: number) => void;
15
- export const wasm_bindgen__closure__destroy__h8f3ce6e75229a5a8: (a: number, b: number) => void;
16
- export const wasm_bindgen__convert__closures_____invoke__hd724dca759e5a136: (a: number, b: number) => void;
17
17
  export const __wbindgen_malloc: (a: number, b: number) => number;
18
18
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
19
19
  export const __wbindgen_exn_store: (a: number) => void;
@@ -1 +1 @@
1
- import*as c from"flatbuffers";import{W as f,M as p,d,e as g}from"../worker-message.js";import{S as w,a as S,b}from"../signer-response.js";const u=0x8000000000000000n;function l(s){if(s instanceof Uint8Array)return s;if(s instanceof ArrayBuffer)return new Uint8Array(s);if(ArrayBuffer.isView(s)){const t=s;return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return typeof s=="string"?new TextEncoder().encode(s):null}function i(s){return typeof s=="string"?s:s instanceof Uint8Array?new TextDecoder().decode(s):s&&typeof s=="object"&&"toString"in s?String(s):""}class m{constructor(t,e,n,r,o){this.proxyUrl=t,this.mainPort=e,this.cachePort=n,this.parserPort=r,this.cryptoPort=o,this.ws=null,this.pendingFrames=[],this.authCounter=1n}start(){this.cachePort.onmessage=t=>{const e=l(t.data);!e||e.byteLength===0||this.sendBinary(e)},this.cryptoPort.onmessage=t=>{const e=l(t.data);!e||e.byteLength===0||this.handleCryptoResponse(e)},this.openSocket()}close(t){t&&this.ws?.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"close_sub",subscription_id:t}))}postRelayStatus(t,e){this.mainPort.postMessage(JSON.stringify({type:"relay:status",status:t,url:e}))}openSocket(){this.ws=new WebSocket(this.proxyUrl),this.ws.binaryType="arraybuffer",this.ws.onopen=()=>{this.postRelayStatus("connected",this.proxyUrl);const t=this.pendingFrames.splice(0,this.pendingFrames.length);for(const e of t)this.ws?.send(e)},this.ws.onclose=()=>{this.postRelayStatus("close",this.proxyUrl)},this.ws.onerror=()=>{this.postRelayStatus("failed",this.proxyUrl)},this.ws.onmessage=async t=>{const e=await this.messageToBytes(t.data);!e||e.byteLength===0||this.handleProxyMessage(e)}}async messageToBytes(t){return t instanceof ArrayBuffer?new Uint8Array(t):t instanceof Blob?new Uint8Array(await t.arrayBuffer()):typeof t=="string"?new TextEncoder().encode(t):null}sendBinary(t){const e=t.slice().buffer;if(this.ws?.readyState===WebSocket.OPEN){this.ws.send(e);return}this.pendingFrames.push(e)}handleProxyMessage(t){let e;try{e=f.getRootAsWorkerMessage(new c.ByteBuffer(t))}catch{return}if(e.type()===p.ConnectionStatus&&e.contentType()===d.ConnectionStatus){const n=e.content(new g);if(i(n?.status())==="AUTH"){const r=i(n?.message()),o=i(n?.relayUrl())||i(e.url())||i(e.subId());this.forwardAuthChallenge(r,o);return}}this.parserPort.postMessage(t,[t.buffer])}forwardAuthChallenge(t,e){if(!t||!e)return;const n=this.authCounter|u;this.authCounter+=1n;const r=JSON.stringify({challenge:t,relay:e,created_at:Date.now()}),o=new w(n,S.AuthEvent,r,null,null,null),a=new c.Builder(256);a.finish(o.pack(a));const h=a.asUint8Array();this.cryptoPort.postMessage(h,[h.buffer])}handleCryptoResponse(t){let e;try{e=b.getRootAsSignerResponse(new c.ByteBuffer(t))}catch{return}if((e.requestId()&u)===0n)return;const n=i(e.result());if(!(!n||this.ws?.readyState!==WebSocket.OPEN))try{const r=JSON.parse(n);if(!r?.relay||r?.event===void 0)return;const o=typeof r.event=="string"?JSON.parse(r.event):r.event;this.ws.send(JSON.stringify({type:"auth_response",relay:r.relay,event:o}))}catch{}}}let y=null;self.addEventListener("message",s=>{const t=s.data;if(t?.type==="init"){const{mainPort:e,cachePort:n,parserPort:r,cryptoPort:o,proxy:a}=t.payload;if(!a?.url){console.error("[connections proxy worker] Missing proxy URL in init payload");return}y=new m(a.url,e,n,r,o),y.start();return}t?.type!=="wake"&&typeof t=="string"&&y?.close(t)});
1
+ import*as a from"flatbuffers";import{W as l,d as S,M as U,e as b}from"../worker-message.js";import{S as m,a as A,b as B}from"../signer-response.js";const p=0x8000000000000000n,P=new TextDecoder,g=new TextEncoder,T=new Uint8Array([110,52,54,58]),u=new Uint8Array([65,85,84,72]),E="n46:",x="AUTH";function d(n){if(n instanceof Uint8Array)return n;if(n instanceof ArrayBuffer)return new Uint8Array(n);if(ArrayBuffer.isView(n)){const t=n;return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return typeof n=="string"?g.encode(n):null}function h(n){return typeof n=="string"?n:n instanceof Uint8Array?P.decode(n):n&&typeof n=="object"&&"toString"in n?String(n):""}function k(n){if(typeof n=="string")return n===x;if(!(n instanceof Uint8Array)||n.length!==u.length)return!1;for(let t=0;t<u.length;t++)if(n[t]!==u[t])return!1;return!0}function R(n,t,e){if(typeof n=="string")return n.startsWith(e);if(!(n instanceof Uint8Array)||n.length<t.length)return!1;for(let r=0;r<t.length;r++)if(n[r]!==t[r])return!1;return!0}class M{constructor(t,e,r,s,o){this.proxyUrl=t,this.mainPort=e,this.cachePort=r,this.parserPort=s,this.cryptoPort=o,this.ws=null,this.pendingFrames=[],this.authCounter=1n,this.workerMessageView=new l,this.connectionStatusView=new S}start(){this.cachePort.onmessage=t=>{const e=d(t.data);!e||e.byteLength===0||this.sendBinary(e)},this.cryptoPort.onmessage=t=>{const e=d(t.data);!e||e.byteLength===0||this.handleCryptoResponse(e)},this.openSocket()}close(t){t&&this.ws?.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"close_sub",subscription_id:t}))}postRelayStatus(t,e){this.mainPort.postMessage(JSON.stringify({type:"relay:status",status:t,url:e}))}openSocket(){this.ws=new WebSocket(this.proxyUrl),this.ws.binaryType="arraybuffer",this.ws.onopen=()=>{this.postRelayStatus("connected",this.proxyUrl);const t=this.pendingFrames.splice(0,this.pendingFrames.length);for(const e of t)this.ws?.send(e)},this.ws.onclose=()=>{this.postRelayStatus("close",this.proxyUrl)},this.ws.onerror=()=>{this.postRelayStatus("failed",this.proxyUrl)},this.ws.onmessage=async t=>{const e=await this.messageToBytes(t.data);!e||e.byteLength===0||this.handleProxyMessage(e)}}async messageToBytes(t){return t instanceof ArrayBuffer?new Uint8Array(t):t instanceof Blob?new Uint8Array(await t.arrayBuffer()):typeof t=="string"?g.encode(t):null}sendBinary(t){const e=t.slice().buffer;if(this.ws?.readyState===WebSocket.OPEN){this.ws.send(e);return}this.pendingFrames.push(e)}handleProxyMessage(t){let e;try{e=l.getRootAsWorkerMessage(new a.ByteBuffer(t),this.workerMessageView)}catch{return}const r=e.subId(a.Encoding.UTF8_BYTES),s=R(r,T,E);if(e.type()===U.ConnectionStatus&&e.contentType()===b.ConnectionStatus){const o=e.content(this.connectionStatusView),i=o?.status(a.Encoding.UTF8_BYTES),c=o?.relayUrl(a.Encoding.UTF8_BYTES)||e.url(a.Encoding.UTF8_BYTES)||r;if(k(i)){const w=h(o?.message(a.Encoding.UTF8_BYTES));this.forwardAuthChallenge(w,h(c));return}const y=h(c);y&&y!==this.proxyUrl&&this.postRelayStatus(h(i),y)}(s?this.cryptoPort:this.parserPort).postMessage(t,[t.buffer])}forwardAuthChallenge(t,e){if(!t||!e)return;const r=this.authCounter|p;this.authCounter+=1n;const s=JSON.stringify({challenge:t,relay:e,created_at:Date.now()}),o=new m(r,A.AuthEvent,s,null,null,null),i=new a.Builder(256);i.finish(o.pack(i));const c=i.asUint8Array();this.cryptoPort.postMessage(c,[c.buffer])}handleCryptoResponse(t){let e;try{e=B.getRootAsSignerResponse(new a.ByteBuffer(t))}catch{return}if((e.requestId()&p)===0n)return;const r=h(e.result());if(!(!r||this.ws?.readyState!==WebSocket.OPEN))try{const s=JSON.parse(r);if(!s?.relay||s?.event===void 0)return;const o=typeof s.event=="string"?JSON.parse(s.event):s.event;this.ws.send(JSON.stringify({type:"auth_response",relay:s.relay,event:o}))}catch{}}}let f=null;self.addEventListener("message",n=>{const t=n.data;if(t?.type==="init"){const{mainPort:e,cachePort:r,parserPort:s,cryptoPort:o,proxy:i}=t.payload;if(!i?.url)return;f=new M(i.url,e,r,s,o),f.start();return}t?.type!=="wake"&&typeof t=="string"&&f?.close(t)});
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.js","sources":["../../src/connections/proxy.ts"],"sourcesContent":["import * as flatbuffers from 'flatbuffers';\n\nimport {\n\tConnectionStatus,\n\tMessage,\n\tMessageType,\n\tSignerOp,\n\tSignerRequestT,\n\tSignerResponse,\n\tWorkerMessage\n} from '../generated/nostr/fb';\nimport type { InitConnectionsMsg } from './types';\n\nconst AUTH_REQUEST_ID_MASK = 0x8000000000000000n;\n\nfunction toUint8Array(data: unknown): Uint8Array | null {\n\tif (data instanceof Uint8Array) return data;\n\tif (data instanceof ArrayBuffer) return new Uint8Array(data);\n\tif (ArrayBuffer.isView(data)) {\n\t\tconst view = data as ArrayBufferView;\n\t\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n\t}\n\tif (typeof data === 'string') {\n\t\treturn new TextEncoder().encode(data);\n\t}\n\treturn null;\n}\n\nfunction readString(value: unknown): string {\n\tif (typeof value === 'string') return value;\n\tif (value instanceof Uint8Array) return new TextDecoder().decode(value);\n\tif (value && typeof value === 'object' && 'toString' in value) {\n\t\treturn String(value);\n\t}\n\treturn '';\n}\n\nclass ProxyRuntime {\n\tprivate ws: WebSocket | null = null;\n\tprivate pendingFrames: ArrayBuffer[] = [];\n\tprivate authCounter = 1n;\n\n\tconstructor(\n\t\tprivate readonly proxyUrl: string,\n\t\tprivate readonly mainPort: MessagePort,\n\t\tprivate readonly cachePort: MessagePort,\n\t\tprivate readonly parserPort: MessagePort,\n\t\tprivate readonly cryptoPort: MessagePort\n\t) {}\n\n\tstart() {\n\t\tthis.cachePort.onmessage = (event) => {\n\t\t\tconst bytes = toUint8Array(event.data);\n\t\t\tif (!bytes || bytes.byteLength === 0) return;\n\t\t\tthis.sendBinary(bytes);\n\t\t};\n\n\t\tthis.cryptoPort.onmessage = (event) => {\n\t\t\tconst bytes = toUint8Array(event.data);\n\t\t\tif (!bytes || bytes.byteLength === 0) return;\n\t\t\tthis.handleCryptoResponse(bytes);\n\t\t};\n\n\t\tthis.openSocket();\n\t}\n\n\tclose(subId?: string) {\n\t\tif (subId && this.ws?.readyState === WebSocket.OPEN) {\n\t\t\tthis.ws.send(JSON.stringify({ type: 'close_sub', subscription_id: subId }));\n\t\t}\n\t}\n\n\tprivate postRelayStatus(status: string, url: string) {\n\t\tthis.mainPort.postMessage(\n\t\t\tJSON.stringify({\n\t\t\t\ttype: 'relay:status',\n\t\t\t\tstatus,\n\t\t\t\turl\n\t\t\t})\n\t\t);\n\t}\n\n\tprivate openSocket() {\n\t\tthis.ws = new WebSocket(this.proxyUrl);\n\t\tthis.ws.binaryType = 'arraybuffer';\n\n\t\tthis.ws.onopen = () => {\n\t\t\tthis.postRelayStatus('connected', this.proxyUrl);\n\t\t\tconst queued = this.pendingFrames.splice(0, this.pendingFrames.length);\n\t\t\tfor (const frame of queued) {\n\t\t\t\tthis.ws?.send(frame);\n\t\t\t}\n\t\t};\n\n\t\tthis.ws.onclose = () => {\n\t\t\tthis.postRelayStatus('close', this.proxyUrl);\n\t\t};\n\n\t\tthis.ws.onerror = () => {\n\t\t\tthis.postRelayStatus('failed', this.proxyUrl);\n\t\t};\n\n\t\tthis.ws.onmessage = async (event: MessageEvent<ArrayBuffer | Blob | string>) => {\n\t\t\tconst bytes = await this.messageToBytes(event.data);\n\t\t\tif (!bytes || bytes.byteLength === 0) return;\n\t\t\tthis.handleProxyMessage(bytes);\n\t\t};\n\t}\n\n\tprivate async messageToBytes(payload: ArrayBuffer | Blob | string): Promise<Uint8Array | null> {\n\t\tif (payload instanceof ArrayBuffer) return new Uint8Array(payload);\n\t\tif (payload instanceof Blob) return new Uint8Array(await payload.arrayBuffer());\n\t\tif (typeof payload === 'string') return new TextEncoder().encode(payload);\n\t\treturn null;\n\t}\n\n\tprivate sendBinary(bytes: Uint8Array) {\n\t\tconst frame = bytes.slice().buffer;\n\t\tif (this.ws?.readyState === WebSocket.OPEN) {\n\t\t\tthis.ws.send(frame);\n\t\t\treturn;\n\t\t}\n\t\tthis.pendingFrames.push(frame);\n\t}\n\n\tprivate handleProxyMessage(bytes: Uint8Array) {\n\t\tlet message: WorkerMessage;\n\t\ttry {\n\t\t\tmessage = WorkerMessage.getRootAsWorkerMessage(new flatbuffers.ByteBuffer(bytes));\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tmessage.type() === MessageType.ConnectionStatus &&\n\t\t\tmessage.contentType() === Message.ConnectionStatus\n\t\t) {\n\t\t\tconst content = message.content(new ConnectionStatus());\n\t\t\tconst status = readString(content?.status());\n\t\t\tif (status === 'AUTH') {\n\t\t\t\tconst challenge = readString(content?.message());\n\t\t\t\tconst relay =\n\t\t\t\t\treadString(content?.relayUrl()) ||\n\t\t\t\t\treadString(message.url()) ||\n\t\t\t\t\treadString(message.subId());\n\t\t\t\tthis.forwardAuthChallenge(challenge, relay);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tthis.parserPort.postMessage(bytes, [bytes.buffer]);\n\t}\n\n\tprivate forwardAuthChallenge(challenge: string, relay: string) {\n\t\tif (!challenge || !relay) return;\n\n\t\tconst requestId = this.authCounter | AUTH_REQUEST_ID_MASK;\n\t\tthis.authCounter += 1n;\n\n\t\tconst payload = JSON.stringify({\n\t\t\tchallenge,\n\t\t\trelay,\n\t\t\tcreated_at: Date.now()\n\t\t});\n\n\t\tconst request = new SignerRequestT(requestId, SignerOp.AuthEvent, payload, null, null, null);\n\t\tconst builder = new flatbuffers.Builder(256);\n\t\tbuilder.finish(request.pack(builder));\n\t\tconst packet = builder.asUint8Array();\n\t\tthis.cryptoPort.postMessage(packet, [packet.buffer]);\n\t}\n\n\tprivate handleCryptoResponse(bytes: Uint8Array) {\n\t\tlet response: SignerResponse;\n\t\ttry {\n\t\t\tresponse = SignerResponse.getRootAsSignerResponse(new flatbuffers.ByteBuffer(bytes));\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\n\t\tif ((response.requestId() & AUTH_REQUEST_ID_MASK) === 0n) return;\n\n\t\tconst resultText = readString(response.result());\n\t\tif (!resultText || this.ws?.readyState !== WebSocket.OPEN) return;\n\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(resultText) as { relay?: string; event?: unknown };\n\t\t\tif (!parsed?.relay || parsed?.event === undefined) return;\n\n\t\t\tconst signedEvent =\n\t\t\t\ttypeof parsed.event === 'string' ? JSON.parse(parsed.event) : parsed.event;\n\n\t\t\tthis.ws.send(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\ttype: 'auth_response',\n\t\t\t\t\trelay: parsed.relay,\n\t\t\t\t\tevent: signedEvent\n\t\t\t\t})\n\t\t\t);\n\t\t} catch {\n\t\t\t// Ignore malformed signer response payloads.\n\t\t}\n\t}\n}\n\nlet proxyRuntime: ProxyRuntime | null = null;\n\nself.addEventListener(\n\t'message',\n\t(evt: MessageEvent<InitConnectionsMsg | { type: 'wake' } | string>) => {\n\t\tconst msg = evt.data;\n\n\t\tif (msg?.type === 'init') {\n\t\t\tconst { mainPort, cachePort, parserPort, cryptoPort, proxy } = msg.payload;\n\t\t\tif (!proxy?.url) {\n\t\t\t\tconsole.error('[connections proxy worker] Missing proxy URL in init payload');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tproxyRuntime = new ProxyRuntime(proxy.url, mainPort, cachePort, parserPort, cryptoPort);\n\t\t\tproxyRuntime.start();\n\t\t\treturn;\n\t\t}\n\n\t\t// Optional: wake signal; the proxy loops are event-driven, so this is a no-op.\n\t\tif (msg?.type === 'wake') {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof msg === 'string') {\n\t\t\tproxyRuntime?.close(msg);\n\t\t}\n\t}\n);\n"],"names":["AUTH_REQUEST_ID_MASK","toUint8Array","data","view","readString","value","ProxyRuntime","proxyUrl","mainPort","cachePort","parserPort","cryptoPort","event","bytes","subId","status","url","queued","frame","payload","message","WorkerMessage","flatbuffers","MessageType","Message","content","ConnectionStatus","challenge","relay","requestId","request","SignerRequestT","SignerOp","builder","packet","response","SignerResponse","resultText","parsed","signedEvent","proxyRuntime","evt","msg","proxy"],"mappings":"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"}
1
+ {"version":3,"file":"proxy.js","sources":["../../src/connections/proxy.ts"],"sourcesContent":["import * as flatbuffers from 'flatbuffers';\n\nimport {\n\tConnectionStatus,\n\tMessage,\n\tMessageType,\n\tSignerOp,\n\tSignerRequestT,\n\tSignerResponse,\n\tWorkerMessage\n} from '../generated/nostr/fb';\nimport type { InitConnectionsMsg } from './types';\n\nconst AUTH_REQUEST_ID_MASK = 0x8000000000000000n;\nconst TEXT_DECODER = new TextDecoder();\nconst TEXT_ENCODER = new TextEncoder();\nconst N46_PREFIX = new Uint8Array([110, 52, 54, 58]); // \"n46:\"\nconst AUTH_STATUS = new Uint8Array([65, 85, 84, 72]); // \"AUTH\"\nconst N46_PREFIX_TEXT = 'n46:';\nconst AUTH_STATUS_TEXT = 'AUTH';\n\nfunction toUint8Array(data: unknown): Uint8Array | null {\n\tif (data instanceof Uint8Array) return data;\n\tif (data instanceof ArrayBuffer) return new Uint8Array(data);\n\tif (ArrayBuffer.isView(data)) {\n\t\tconst view = data as ArrayBufferView;\n\t\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n\t}\n\tif (typeof data === 'string') {\n\t\treturn TEXT_ENCODER.encode(data);\n\t}\n\treturn null;\n}\n\nfunction readString(value: unknown): string {\n\tif (typeof value === 'string') return value;\n\tif (value instanceof Uint8Array) return TEXT_DECODER.decode(value);\n\tif (value && typeof value === 'object' && 'toString' in value) {\n\t\treturn String(value);\n\t}\n\treturn '';\n}\n\nfunction isAuthStatus(value: string | Uint8Array | null | undefined): boolean {\n\tif (typeof value === 'string') return value === AUTH_STATUS_TEXT;\n\tif (!(value instanceof Uint8Array) || value.length !== AUTH_STATUS.length) {\n\t\treturn false;\n\t}\n\tfor (let i = 0; i < AUTH_STATUS.length; i++) {\n\t\tif (value[i] !== AUTH_STATUS[i]) return false;\n\t}\n\treturn true;\n}\n\nfunction hasPrefix(\n\tvalue: string | Uint8Array | null | undefined,\n\tprefix: Uint8Array,\n\tprefixText: string\n): boolean {\n\tif (typeof value === 'string') return value.startsWith(prefixText);\n\tif (!(value instanceof Uint8Array) || value.length < prefix.length) return false;\n\tfor (let i = 0; i < prefix.length; i++) {\n\t\tif (value[i] !== prefix[i]) return false;\n\t}\n\treturn true;\n}\n\nclass ProxyRuntime {\n\tprivate ws: WebSocket | null = null;\n\tprivate pendingFrames: ArrayBuffer[] = [];\n\tprivate authCounter = 1n;\n\tprivate readonly workerMessageView = new WorkerMessage();\n\tprivate readonly connectionStatusView = new ConnectionStatus();\n\n\tconstructor(\n\t\tprivate readonly proxyUrl: string,\n\t\tprivate readonly mainPort: MessagePort,\n\t\tprivate readonly cachePort: MessagePort,\n\t\tprivate readonly parserPort: MessagePort,\n\t\tprivate readonly cryptoPort: MessagePort\n\t) {}\n\n\tstart() {\n\t\tthis.cachePort.onmessage = (event) => {\n\t\t\tconst bytes = toUint8Array(event.data);\n\t\t\tif (!bytes || bytes.byteLength === 0) return;\n\t\t\tthis.sendBinary(bytes);\n\t\t};\n\n\t\tthis.cryptoPort.onmessage = (event) => {\n\t\t\tconst bytes = toUint8Array(event.data);\n\t\t\tif (!bytes || bytes.byteLength === 0) return;\n\t\t\tthis.handleCryptoResponse(bytes);\n\t\t};\n\n\t\tthis.openSocket();\n\t}\n\n\tclose(subId?: string) {\n\t\tif (subId && this.ws?.readyState === WebSocket.OPEN) {\n\t\t\tthis.ws.send(JSON.stringify({ type: 'close_sub', subscription_id: subId }));\n\t\t}\n\t}\n\n\tprivate postRelayStatus(status: string, url: string) {\n\t\tthis.mainPort.postMessage(\n\t\t\tJSON.stringify({\n\t\t\t\ttype: 'relay:status',\n\t\t\t\tstatus,\n\t\t\t\turl\n\t\t\t})\n\t\t);\n\t}\n\n\tprivate openSocket() {\n\t\tthis.ws = new WebSocket(this.proxyUrl);\n\t\tthis.ws.binaryType = 'arraybuffer';\n\n\t\tthis.ws.onopen = () => {\n\t\t\tthis.postRelayStatus('connected', this.proxyUrl);\n\t\t\tconst queued = this.pendingFrames.splice(0, this.pendingFrames.length);\n\t\t\tfor (const frame of queued) {\n\t\t\t\tthis.ws?.send(frame);\n\t\t\t}\n\t\t};\n\n\t\tthis.ws.onclose = () => {\n\t\t\tthis.postRelayStatus('close', this.proxyUrl);\n\t\t};\n\n\t\tthis.ws.onerror = () => {\n\t\t\tthis.postRelayStatus('failed', this.proxyUrl);\n\t\t};\n\n\t\tthis.ws.onmessage = async (event: MessageEvent<ArrayBuffer | Blob | string>) => {\n\t\t\tconst bytes = await this.messageToBytes(event.data);\n\t\t\tif (!bytes || bytes.byteLength === 0) return;\n\t\t\tthis.handleProxyMessage(bytes);\n\t\t};\n\t}\n\n\tprivate async messageToBytes(payload: ArrayBuffer | Blob | string): Promise<Uint8Array | null> {\n\t\tif (payload instanceof ArrayBuffer) return new Uint8Array(payload);\n\t\tif (payload instanceof Blob) return new Uint8Array(await payload.arrayBuffer());\n\t\tif (typeof payload === 'string') return TEXT_ENCODER.encode(payload);\n\t\treturn null;\n\t}\n\n\tprivate sendBinary(bytes: Uint8Array) {\n\t\tconst frame = bytes.slice().buffer;\n\t\tif (this.ws?.readyState === WebSocket.OPEN) {\n\t\t\tthis.ws.send(frame);\n\t\t\treturn;\n\t\t}\n\t\tthis.pendingFrames.push(frame);\n\t}\n\n\tprivate handleProxyMessage(bytes: Uint8Array) {\n\t\tlet message: WorkerMessage;\n\t\ttry {\n\t\t\tmessage = WorkerMessage.getRootAsWorkerMessage(\n\t\t\t\tnew flatbuffers.ByteBuffer(bytes),\n\t\t\t\tthis.workerMessageView\n\t\t\t);\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tconst subId = message.subId(flatbuffers.Encoding.UTF8_BYTES);\n\t\tconst isNip46 = hasPrefix(subId, N46_PREFIX, N46_PREFIX_TEXT);\n\t\tif (\n\t\t\tmessage.type() === MessageType.ConnectionStatus &&\n\t\t\tmessage.contentType() === Message.ConnectionStatus\n\t\t) {\n\t\t\tconst content = message.content(this.connectionStatusView);\n\t\t\tconst status = content?.status(flatbuffers.Encoding.UTF8_BYTES);\n\t\t\tconst relayUrl =\n\t\t\t\tcontent?.relayUrl(flatbuffers.Encoding.UTF8_BYTES) ||\n\t\t\t\tmessage.url(flatbuffers.Encoding.UTF8_BYTES) ||\n\t\t\t\tsubId;\n\n\t\t\tif (isAuthStatus(status)) {\n\t\t\t\tconst challenge = readString(content?.message(flatbuffers.Encoding.UTF8_BYTES));\n\t\t\t\tthis.forwardAuthChallenge(challenge, readString(relayUrl));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Forward upstream relay status to main thread\n\t\t\t// (NOTICE, OK, CLOSED, EOSE, etc.)\n\t\t\tconst relayUrlText = readString(relayUrl);\n\t\t\tif (relayUrlText && relayUrlText !== this.proxyUrl) {\n\t\t\t\tthis.postRelayStatus(readString(status), relayUrlText);\n\t\t\t}\n\t\t}\n\n\t\tconst targetPort = isNip46 ? this.cryptoPort : this.parserPort;\n\t\ttargetPort.postMessage(bytes, [bytes.buffer]);\n\t}\n\n\tprivate forwardAuthChallenge(challenge: string, relay: string) {\n\t\tif (!challenge || !relay) return;\n\n\t\tconst requestId = this.authCounter | AUTH_REQUEST_ID_MASK;\n\t\tthis.authCounter += 1n;\n\n\t\tconst payload = JSON.stringify({\n\t\t\tchallenge,\n\t\t\trelay,\n\t\t\tcreated_at: Date.now()\n\t\t});\n\n\t\tconst request = new SignerRequestT(requestId, SignerOp.AuthEvent, payload, null, null, null);\n\t\tconst builder = new flatbuffers.Builder(256);\n\t\tbuilder.finish(request.pack(builder));\n\t\tconst packet = builder.asUint8Array();\n\t\tthis.cryptoPort.postMessage(packet, [packet.buffer]);\n\t}\n\n\tprivate handleCryptoResponse(bytes: Uint8Array) {\n\t\tlet response: SignerResponse;\n\t\ttry {\n\t\t\tresponse = SignerResponse.getRootAsSignerResponse(new flatbuffers.ByteBuffer(bytes));\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\n\t\tif ((response.requestId() & AUTH_REQUEST_ID_MASK) === 0n) return;\n\n\t\tconst resultText = readString(response.result());\n\t\tif (!resultText || this.ws?.readyState !== WebSocket.OPEN) return;\n\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(resultText) as { relay?: string; event?: unknown };\n\t\t\tif (!parsed?.relay || parsed?.event === undefined) return;\n\n\t\t\tconst signedEvent =\n\t\t\t\ttypeof parsed.event === 'string' ? JSON.parse(parsed.event) : parsed.event;\n\n\t\t\tthis.ws.send(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\ttype: 'auth_response',\n\t\t\t\t\trelay: parsed.relay,\n\t\t\t\t\tevent: signedEvent\n\t\t\t\t})\n\t\t\t);\n\t\t} catch {\n\t\t\t// Ignore malformed signer response payloads.\n\t\t}\n\t}\n}\n\nlet proxyRuntime: ProxyRuntime | null = null;\n\nself.addEventListener(\n\t'message',\n\t(evt: MessageEvent<InitConnectionsMsg | { type: 'wake' } | string>) => {\n\t\tconst msg = evt.data;\n\n\t\tif (msg?.type === 'init') {\n\t\t\tconst { mainPort, cachePort, parserPort, cryptoPort, proxy } = msg.payload;\n\t\t\tif (!proxy?.url) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tproxyRuntime = new ProxyRuntime(proxy.url, mainPort, cachePort, parserPort, cryptoPort);\n\t\t\tproxyRuntime.start();\n\t\t\treturn;\n\t\t}\n\n\t\t// Optional: wake signal; the proxy loops are event-driven, so this is a no-op.\n\t\tif (msg?.type === 'wake') {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof msg === 'string') {\n\t\t\tproxyRuntime?.close(msg);\n\t\t}\n\t}\n);\n"],"names":["AUTH_REQUEST_ID_MASK","TEXT_DECODER","TEXT_ENCODER","N46_PREFIX","AUTH_STATUS","N46_PREFIX_TEXT","AUTH_STATUS_TEXT","toUint8Array","data","view","readString","value","isAuthStatus","i","hasPrefix","prefix","prefixText","ProxyRuntime","proxyUrl","mainPort","cachePort","parserPort","cryptoPort","WorkerMessage","ConnectionStatus","event","bytes","subId","status","url","queued","frame","payload","message","flatbuffers","isNip46","MessageType","Message","content","relayUrl","challenge","relayUrlText","relay","requestId","request","SignerRequestT","SignerOp","builder","packet","response","SignerResponse","resultText","parsed","signedEvent","proxyRuntime","evt","msg","proxy"],"mappings":"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"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import"flatbuffers";import{C as a,v as s,w as e,x as i,y as n,z as r,B as t,D as d,E as o,G as P,F as T,K as g,H as p,M as f,I as b,J as C,L as K,O as u,N as c,P as l,Q as v,R as S,S as m,T as D,U as M,W as R,V as E,X as h,Y as k,Z as L,_ as y,$ as I,a0 as N,a1 as V,a2 as F,a3 as q,a4 as W,a5 as G,a6 as H,a7 as j,a8 as w,a9 as A,aa as B,ab as x,ac as z,ae as U,ad as Q,af as Z,ag as O,ah as J,ai as X,aj as Y,ak as _,c as $,d as aa,t as sa,e as ea,g as ia,i as na,q as ra,f as ta,j as da,m as oa,b as Pa,k as Ta,l as ga,n as pa,h as fa,p as ba,o as Ca,r as Ka,a as ua,s as ca,u as la}from"./index2.js";import{B as va,t as Sa,v as ma,m as Da,w as Ma,l as Ra,e as Ea,g as ha,x as ka,y as La,z as ya,h as Ia,b as Na,A as Va,D as Fa,C as qa,F as Wa,G as Ga,J as Ha,K as ja,O as wa,E as Aa,Q as Ba,T as xa,U as za,X as Ua,Y as Qa,Z as Za,H as Oa,_ as Ja,$ as Xa,a0 as Ya,I as _a,a1 as $a,a2 as as,a3 as ss,a4 as es,a5 as is,a6 as ns,a7 as rs,a8 as ts,a9 as ds,aa as os,ab as Ps,ac as Ts,ad as gs,ae as ps,af as fs,ag as bs,ah as Cs,ai as Ks,aj as us,ak as cs,al as ls,am as vs,an as Ss,ao as ms,ap as Ds,aq as Ms,ar as Rs,as as Es,at as hs,au as ks,av as Ls,aw as ys,ax as Is,ay as Ns,az as Vs,aA as Fs,aB as qs,aC as Ws,aD as Gs,aE as Hs,aF as js,aG as ws,aH as As,L as Bs,aI as xs,aJ as zs,aK as Us,aL as Qs,aM as Zs,aN as Os,aO as Js,aP as Xs,aQ as Ys,k as _s,aR as $s,i as ae,d as se,M as ee,aS as ie,aT as ne,aU as re,aV as te,aW as de,n as oe,p as Pe,N as Te,aX as ge,aY as pe,P as fe,q as be,aZ as Ce,a_ as Ke,a$ as ue,b0 as ce,b1 as le,b2 as ve,b3 as Se,b4 as me,b5 as De,b6 as Me,b7 as Re,b8 as Ee,b9 as he,ba as ke,R as Le,bb as ye,bc as Ie,bd as Ne,o as Ve,s as Fe,be as qe,bf as We,r as Ge,S as He,bg as je,bh as we,V as Ae,bi as Be,bj as xe,j as ze,bk as Ue,bl as Qe,bm as Ze,bn as Oe,bo as Je,W as Xe,f as Ye,bp as _e,bq as $e}from"./worker-message.js";import{a as ai,c as si,S as ei,b as ii,d as ni}from"./signer-response.js";export{va as BufferFull,Sa as BufferFullT,a as CacheInput,s as CacheInputMessage,e as CacheInputMessageT,i as CacheRequest,n as CacheRequestT,r as CacheResponse,t as CacheResponseT,ma as CashuData,Da as CashuDataT,Ma as CodeData,Ra as CodeDataT,Ea as ConnectionStatus,ha as ConnectionStatusT,ka as Contact,La as ContactT,ya as ContentBlock,Ia as ContentBlockT,Na as ContentData,Va as Coordinate,Fa as CoordinateT,qa as CountResponse,Wa as CountResponseT,d as CounterPipeConfig,o as CounterPipeConfigT,Ga as DLEQProof,Ha as DLEQProofT,ja as Emoji,wa as EmojiT,Aa as Eoce,Ba as EoceT,xa as EventPointer,za as EventPointerT,P as GetPublicKey,T as GetPublicKeyT,Ua as HTLCWitness,Qa as HTLCWitnessT,Za as HashtagData,Oa as HashtagDataT,Ja as HistoryTag,Xa as HistoryTagT,Ya as ImageData,_a as ImageDataT,$a as ImetaTag,as as ImetaTagT,ss as Kind0Parsed,es as Kind0ParsedT,is as Kind10002Parsed,ns as Kind10002ParsedT,rs as Kind10019Parsed,ts as Kind10019ParsedT,ds as Kind1111Parsed,os as Kind1111ParsedT,Ps as Kind1311Parsed,Ts as Kind1311ParsedT,gs as Kind17375Parsed,ps as Kind17375ParsedT,fs as Kind17Parsed,bs as Kind17ParsedT,Cs as Kind1Parsed,Ks as Kind1ParsedT,us as Kind20Parsed,cs as Kind20ParsedT,ls as Kind22Parsed,vs as Kind22ParsedT,Ss as Kind30023Parsed,ms as Kind30023ParsedT,Ds as Kind3Parsed,Ms as Kind3ParsedT,Rs as Kind4Parsed,Es as Kind4ParsedT,hs as Kind6Parsed,ks as Kind6ParsedT,Ls as Kind7374Parsed,ys as Kind7374ParsedT,Is as Kind7375Parsed,Ns as Kind7375ParsedT,Vs as Kind7376Parsed,Fs as Kind7376ParsedT,qs as Kind7Parsed,Ws as Kind7ParsedT,Gs as Kind9321Parsed,Hs as Kind9321ParsedT,js as Kind9735Parsed,ws as Kind9735ParsedT,g as KindFilterPipeConfig,p as KindFilterPipeConfigT,As as LinkPreviewData,Bs as LinkPreviewDataT,xs as ListParsed,zs as ListParsedT,Us as LiveActivityRef,Qs as LiveActivityRefT,Zs as LiveChatParticipant,Os as LiveChatParticipantT,Js as LiveChatThreadRef,Xs as LiveChatThreadRefT,f as MainContent,b as MainMessage,C as MainMessageT,Ys as MediaGroupData,_s as MediaGroupDataT,$s as MediaItem,ae as MediaItemT,se as Message,ee as MessageType,ie as MintInfo,ne as MintInfoT,re as MintProofs,te as MintProofsT,K as MuteFilterPipeConfig,u as MuteFilterPipeConfigT,de as NostrData,oe as NostrDataT,Pe as NostrEvent,Te as NostrEventT,c as NostrManager,l as NpubLimiterPipeConfig,v as NpubLimiterPipeConfigT,ge as P2PKWitness,pe as P2PKWitnessT,S as ParsePipeConfig,m as ParsePipeConfigT,fe as ParsedData,D as ParsedDataUnion,be as ParsedEvent,Ce as ParsedEventT,M as Pipe,R as PipeConfig,E as PipeT,h as PipelineConfig,k as PipelineConfigT,Ke as PreGenericParsed,ue as PreGenericParsedT,ce as PreParticipant,le as PreParticipantT,ve as PreRefEvent,Se as PreRefEventT,L as PrivateKey,y as PrivateKeyT,me as ProfilePointer,De as ProfilePointerT,Me as Proof,Re as ProofT,I as ProofVerificationPipeConfig,N as ProofVerificationPipeConfigT,Ee as Pubkey,he as PubkeyT,V as Publish,F as PublishT,ke as Raw,Le as RawT,ye as ReactionType,Ie as RelayInfo,Ne as RelayInfoT,Ve as Request,Fe as RequestT,q as SaveToDbPipeConfig,W as SaveToDbPipeConfigT,G as SerializeEventsPipeConfig,H as SerializeEventsPipeConfigT,j as SetSigner,w as SetSignerT,A as SignEvent,B as SignEventT,qe as SignedEvent,We as SignedEventT,ai as SignerOp,si as SignerRequest,ei as SignerRequestT,ii as SignerResponse,ni as SignerResponseT,x as SignerType,Ge as StringVec,He as StringVecT,z as Subscribe,U as SubscribeKind,Q as SubscribeT,Z as SubscriptionConfig,O as SubscriptionConfigT,je as Tag,we as TagT,J as Template,X as TemplateT,Y as Unsubscribe,_ as UnsubscribeT,Ae as ValidProofs,Be as ValidProofsT,xe as VideoData,ze as VideoDataT,Ue as VideoVariant,Qe as VideoVariantT,Ze as Witness,Oe as WitnessString,Je as WitnessStringT,Xe as WorkerMessage,Ye as WorkerMessageT,_e as ZapRequest,$e as ZapRequestT,$ as createNostrManager,aa as ensureD,sa as ensureDTagForPre,ea as extractDFromTags,ia as getManager,na as isHex64,ra as isPreKind,ta as makeAPointer,da as makeAPointerForEvent,oa as makeNaddr,Pa as makeNaddrForEvent,Ta as makeNaddrLike,ga as makeNaddrLikeForEvent,pa as normalizeSlug,fa as parseAPointer,ba as parseNaddr,Ca as parseNaddrLike,Ka as randomId,ua as setGlobalManager,ca as setManager,la as upsertDTag};
1
+ import"flatbuffers";import{C as a,v as s,w as e,x as i,y as n,z as r,B as t,D as d,E as o,G as P,F as T,K as g,H as p,M as f,I as b,J as C,L as K,O as u,N as c,P as l,Q as v,R as S,S as m,T as D,U as M,W as R,V as E,X as h,Y as k,Z as L,_ as y,$ as I,a0 as N,a1 as V,a2 as F,a3 as q,a4 as W,a5 as G,a6 as H,a7 as j,a8 as w,a9 as A,aa as B,ab as x,ac as z,ae as U,ad as Q,af as Z,ag as O,ah as J,ai as X,aj as Y,ak as _,c as $,d as aa,t as sa,e as ea,g as ia,i as na,q as ra,f as ta,j as da,m as oa,b as Pa,k as Ta,l as ga,n as pa,h as fa,p as ba,o as Ca,r as Ka,a as ua,s as ca,u as la}from"./index2.js";import{B as va,q as Sa,r as ma,k as Da,s as Ma,j as Ra,d as Ea,t as ha,v as ka,w as La,x as ya,f as Ia,b as Na,y as Va,z as Fa,C as qa,A as Wa,D as Ga,F as Ha,G as ja,J as wa,E as Aa,K as Ba,O as xa,Q as za,T as Ua,U as Qa,X as Za,H as Oa,Y as Ja,Z as Xa,_ as Ya,I as _a,$ as $a,a0 as as,a1 as ss,a2 as es,a3 as is,a4 as ns,a5 as rs,a6 as ts,a7 as ds,a8 as os,a9 as Ps,aa as Ts,ab as gs,ac as ps,ad as fs,ae as bs,af as Cs,ag as Ks,ah as us,ai as cs,aj as ls,ak as vs,al as Ss,am as ms,an as Ds,ao as Ms,ap as Rs,aq as Es,ar as hs,as as ks,at as Ls,au as ys,av as Is,aw as Ns,ax as Vs,ay as Fs,az as qs,aA as Ws,aB as Gs,aC as Hs,aD as js,aE as ws,aF as As,L as Bs,aG as xs,aH as zs,aI as Us,aJ as Qs,aK as Zs,aL as Os,aM as Js,aN as Xs,aO as Ys,i as _s,aP as $s,g as ae,e as se,M as ee,aQ as ie,aR as ne,aS as re,aT as te,aU as de,l as oe,N as Pe,aV as Te,aW as ge,aX as pe,P as fe,n as be,aY as Ce,aZ as Ke,a_ as ue,a$ as ce,b0 as le,b1 as ve,b2 as Se,b3 as me,b4 as De,b5 as Me,b6 as Re,b7 as Ee,b8 as he,R as ke,b9 as Le,ba as ye,bb as Ie,bc as Ne,m as Ve,o as Fe,bd as qe,be as We,S as Ge,p as He,bf as je,bg as we,V as Ae,bh as Be,bi as xe,h as ze,bj as Ue,bk as Qe,bl as Ze,bm as Oe,bn as Je,W as Xe,bo as Ye,bp as _e,bq as $e}from"./worker-message.js";import{a as ai,c as si,S as ei,b as ii,d as ni}from"./signer-response.js";export{va as BufferFull,Sa as BufferFullT,a as CacheInput,s as CacheInputMessage,e as CacheInputMessageT,i as CacheRequest,n as CacheRequestT,r as CacheResponse,t as CacheResponseT,ma as CashuData,Da as CashuDataT,Ma as CodeData,Ra as CodeDataT,Ea as ConnectionStatus,ha as ConnectionStatusT,ka as Contact,La as ContactT,ya as ContentBlock,Ia as ContentBlockT,Na as ContentData,Va as Coordinate,Fa as CoordinateT,qa as CountResponse,Wa as CountResponseT,d as CounterPipeConfig,o as CounterPipeConfigT,Ga as DLEQProof,Ha as DLEQProofT,ja as Emoji,wa as EmojiT,Aa as Eoce,Ba as EoceT,xa as EventPointer,za as EventPointerT,P as GetPublicKey,T as GetPublicKeyT,Ua as HTLCWitness,Qa as HTLCWitnessT,Za as HashtagData,Oa as HashtagDataT,Ja as HistoryTag,Xa as HistoryTagT,Ya as ImageData,_a as ImageDataT,$a as ImetaTag,as as ImetaTagT,ss as Kind0Parsed,es as Kind0ParsedT,is as Kind10002Parsed,ns as Kind10002ParsedT,rs as Kind10019Parsed,ts as Kind10019ParsedT,ds as Kind1111Parsed,os as Kind1111ParsedT,Ps as Kind1311Parsed,Ts as Kind1311ParsedT,gs as Kind17375Parsed,ps as Kind17375ParsedT,fs as Kind17Parsed,bs as Kind17ParsedT,Cs as Kind1Parsed,Ks as Kind1ParsedT,us as Kind20Parsed,cs as Kind20ParsedT,ls as Kind22Parsed,vs as Kind22ParsedT,Ss as Kind30023Parsed,ms as Kind30023ParsedT,Ds as Kind3Parsed,Ms as Kind3ParsedT,Rs as Kind4Parsed,Es as Kind4ParsedT,hs as Kind6Parsed,ks as Kind6ParsedT,Ls as Kind7374Parsed,ys as Kind7374ParsedT,Is as Kind7375Parsed,Ns as Kind7375ParsedT,Vs as Kind7376Parsed,Fs as Kind7376ParsedT,qs as Kind7Parsed,Ws as Kind7ParsedT,Gs as Kind9321Parsed,Hs as Kind9321ParsedT,js as Kind9735Parsed,ws as Kind9735ParsedT,g as KindFilterPipeConfig,p as KindFilterPipeConfigT,As as LinkPreviewData,Bs as LinkPreviewDataT,xs as ListParsed,zs as ListParsedT,Us as LiveActivityRef,Qs as LiveActivityRefT,Zs as LiveChatParticipant,Os as LiveChatParticipantT,Js as LiveChatThreadRef,Xs as LiveChatThreadRefT,f as MainContent,b as MainMessage,C as MainMessageT,Ys as MediaGroupData,_s as MediaGroupDataT,$s as MediaItem,ae as MediaItemT,se as Message,ee as MessageType,ie as MintInfo,ne as MintInfoT,re as MintProofs,te as MintProofsT,K as MuteFilterPipeConfig,u as MuteFilterPipeConfigT,de as NostrData,oe as NostrDataT,Pe as NostrEvent,Te as NostrEventT,c as NostrManager,l as NpubLimiterPipeConfig,v as NpubLimiterPipeConfigT,ge as P2PKWitness,pe as P2PKWitnessT,S as ParsePipeConfig,m as ParsePipeConfigT,fe as ParsedData,D as ParsedDataUnion,be as ParsedEvent,Ce as ParsedEventT,M as Pipe,R as PipeConfig,E as PipeT,h as PipelineConfig,k as PipelineConfigT,Ke as PreGenericParsed,ue as PreGenericParsedT,ce as PreParticipant,le as PreParticipantT,ve as PreRefEvent,Se as PreRefEventT,L as PrivateKey,y as PrivateKeyT,me as ProfilePointer,De as ProfilePointerT,Me as Proof,Re as ProofT,I as ProofVerificationPipeConfig,N as ProofVerificationPipeConfigT,Ee as Pubkey,he as PubkeyT,V as Publish,F as PublishT,ke as Raw,Le as RawT,ye as ReactionType,Ie as RelayInfo,Ne as RelayInfoT,Ve as Request,Fe as RequestT,q as SaveToDbPipeConfig,W as SaveToDbPipeConfigT,G as SerializeEventsPipeConfig,H as SerializeEventsPipeConfigT,j as SetSigner,w as SetSignerT,A as SignEvent,B as SignEventT,qe as SignedEvent,We as SignedEventT,ai as SignerOp,si as SignerRequest,ei as SignerRequestT,ii as SignerResponse,ni as SignerResponseT,x as SignerType,Ge as StringVec,He as StringVecT,z as Subscribe,U as SubscribeKind,Q as SubscribeT,Z as SubscriptionConfig,O as SubscriptionConfigT,je as Tag,we as TagT,J as Template,X as TemplateT,Y as Unsubscribe,_ as UnsubscribeT,Ae as ValidProofs,Be as ValidProofsT,xe as VideoData,ze as VideoDataT,Ue as VideoVariant,Qe as VideoVariantT,Ze as Witness,Oe as WitnessString,Je as WitnessStringT,Xe as WorkerMessage,Ye as WorkerMessageT,_e as ZapRequest,$e as ZapRequestT,$ as createNostrManager,aa as ensureD,sa as ensureDTagForPre,ea as extractDFromTags,ia as getManager,na as isHex64,ra as isPreKind,ta as makeAPointer,da as makeAPointerForEvent,oa as makeNaddr,Pa as makeNaddrForEvent,Ta as makeNaddrLike,ga as makeNaddrLikeForEvent,pa as normalizeSlug,fa as parseAPointer,ba as parseNaddr,Ca as parseNaddrLike,Ka as randomId,ua as setGlobalManager,ca as setManager,la as upsertDTag};
package/dist/index2.js CHANGED
@@ -1 +1 @@
1
- import*as c from"flatbuffers";import{ByteBuffer as qt}from"flatbuffers";import{o as ct,p as zt,q as Gt,W as bt,r as Bt,s as $t,S as ht}from"./worker-message.js";import"./signer-response.js";import{nip19 as dt}from"nostr-tools";class _{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCacheRequest(t,e){return(e||new _).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCacheRequest(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new _).__init(t.readInt32(t.position())+t.position(),t)}subId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}requests(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new ct).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}requestsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}event(t){const e=this.bb.__offset(this.bb_pos,8);return e?(t||new zt).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}parsedEvent(t){const e=this.bb.__offset(this.bb_pos,10);return e?(t||new Gt).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}relays(t,e){const s=this.bb.__offset(this.bb_pos,12);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}relaysLength(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}static startCacheRequest(t){t.startObject(5)}static addSubId(t,e){t.addFieldOffset(0,e,0)}static addRequests(t,e){t.addFieldOffset(1,e,0)}static createRequestsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRequestsVector(t,e){t.startVector(4,e,4)}static addEvent(t,e){t.addFieldOffset(2,e,0)}static addParsedEvent(t,e){t.addFieldOffset(3,e,0)}static addRelays(t,e){t.addFieldOffset(4,e,0)}static createRelaysVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRelaysVector(t,e){t.startVector(4,e,4)}static endCacheRequest(t){const e=t.endObject();return t.requiredField(e,4),e}unpack(){return new pt(this.subId(),this.bb.createObjList(this.requests.bind(this),this.requestsLength()),this.event()!==null?this.event().unpack():null,this.parsedEvent()!==null?this.parsedEvent().unpack():null,this.bb.createScalarList(this.relays.bind(this),this.relaysLength()))}unpackTo(t){t.subId=this.subId(),t.requests=this.bb.createObjList(this.requests.bind(this),this.requestsLength()),t.event=this.event()!==null?this.event().unpack():null,t.parsedEvent=this.parsedEvent()!==null?this.parsedEvent().unpack():null,t.relays=this.bb.createScalarList(this.relays.bind(this),this.relaysLength())}}class pt{constructor(t=null,e=[],s=null,n=null,r=[]){this.subId=t,this.requests=e,this.event=s,this.parsedEvent=n,this.relays=r}pack(t){const e=this.subId!==null?t.createString(this.subId):0,s=_.createRequestsVector(t,t.createObjectOffsetList(this.requests)),n=this.event!==null?this.event.pack(t):0,r=this.parsedEvent!==null?this.parsedEvent.pack(t):0,o=_.createRelaysVector(t,t.createObjectOffsetList(this.relays));return _.startCacheRequest(t),_.addSubId(t,e),_.addRequests(t,s),_.addEvent(t,n),_.addParsedEvent(t,r),_.addRelays(t,o),_.endCacheRequest(t)}}var B=(i=>(i[i.NONE=0]="NONE",i[i.WorkerMessage=1]="WorkerMessage",i[i.CacheRequest=2]="CacheRequest",i))(B||{});function ut(i,t){switch(B[i]){case"NONE":return null;case"WorkerMessage":return t(new bt);case"CacheRequest":return t(new _);default:return null}}class N{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCacheInputMessage(t,e){return(e||new N).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCacheInputMessage(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new N).__init(t.readInt32(t.position())+t.position(),t)}contentType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):B.NONE}content(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startCacheInputMessage(t){t.startObject(2)}static addContentType(t,e){t.addFieldInt8(0,e,B.NONE)}static addContent(t,e){t.addFieldOffset(1,e,0)}static endCacheInputMessage(t){const e=t.endObject();return t.requiredField(e,6),e}static createCacheInputMessage(t,e,s){return N.startCacheInputMessage(t),N.addContentType(t,e),N.addContent(t,s),N.endCacheInputMessage(t)}unpack(){return new lt(this.contentType(),(()=>{const t=ut(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.contentType=this.contentType(),t.content=(()=>{const e=ut(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class lt{constructor(t=B.NONE,e=null){this.contentType=t,this.content=e}pack(t){const e=t.createObjectOffset(this.content);return N.createCacheInputMessage(t,this.contentType,e)}}class m{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCacheResponse(t,e){return(e||new m).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCacheResponse(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new m).__init(t.readInt32(t.position())+t.position(),t)}subId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}payload(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb.__vector(this.bb_pos+e)+t):0}payloadLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}payloadArray(){const t=this.bb.__offset(this.bb_pos,6);return t?new Uint8Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startCacheResponse(t){t.startObject(2)}static addSubId(t,e){t.addFieldOffset(0,e,0)}static addPayload(t,e){t.addFieldOffset(1,e,0)}static createPayloadVector(t,e){t.startVector(1,e.length,1);for(let s=e.length-1;s>=0;s--)t.addInt8(e[s]);return t.endVector()}static startPayloadVector(t,e){t.startVector(1,e,1)}static endCacheResponse(t){const e=t.endObject();return t.requiredField(e,4),e}static createCacheResponse(t,e,s){return m.startCacheResponse(t),m.addSubId(t,e),m.addPayload(t,s),m.endCacheResponse(t)}unpack(){return new ft(this.subId(),this.bb.createScalarList(this.payload.bind(this),this.payloadLength()))}unpackTo(t){t.subId=this.subId(),t.payload=this.bb.createScalarList(this.payload.bind(this),this.payloadLength())}}class ft{constructor(t=null,e=[]){this.subId=t,this.payload=e}pack(t){const e=this.subId!==null?t.createString(this.subId):0,s=m.createPayloadVector(t,this.payload);return m.createCacheResponse(t,e,s)}}class I{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCounterPipeConfig(t,e){return(e||new I).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCounterPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new I).__init(t.readInt32(t.position())+t.position(),t)}kinds(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint16(this.bb.__vector(this.bb_pos+e)+t*2):0}kindsLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}kindsArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint16Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}pubkey(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,t):null}static startCounterPipeConfig(t){t.startObject(2)}static addKinds(t,e){t.addFieldOffset(0,e,0)}static createKindsVector(t,e){t.startVector(2,e.length,2);for(let s=e.length-1;s>=0;s--)t.addInt16(e[s]);return t.endVector()}static startKindsVector(t,e){t.startVector(2,e,2)}static addPubkey(t,e){t.addFieldOffset(1,e,0)}static endCounterPipeConfig(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),e}static createCounterPipeConfig(t,e,s){return I.startCounterPipeConfig(t),I.addKinds(t,e),I.addPubkey(t,s),I.endCounterPipeConfig(t)}unpack(){return new gt(this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()),this.pubkey())}unpackTo(t){t.kinds=this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()),t.pubkey=this.pubkey()}}class gt{constructor(t=[],e=null){this.kinds=t,this.pubkey=e}pack(t){const e=I.createKindsVector(t,this.kinds),s=this.pubkey!==null?t.createString(this.pubkey):0;return I.createCounterPipeConfig(t,e,s)}}class U{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsGetPublicKey(t,e){return(e||new U).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsGetPublicKey(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new U).__init(t.readInt32(t.position())+t.position(),t)}static startGetPublicKey(t){t.startObject(0)}static endGetPublicKey(t){return t.endObject()}static createGetPublicKey(t){return U.startGetPublicKey(t),U.endGetPublicKey(t)}unpack(){return new J}unpackTo(t){}}class J{constructor(){}pack(t){return U.createGetPublicKey(t)}}class F{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsKindFilterPipeConfig(t,e){return(e||new F).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsKindFilterPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new F).__init(t.readInt32(t.position())+t.position(),t)}kinds(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint16(this.bb.__vector(this.bb_pos+e)+t*2):0}kindsLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}kindsArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint16Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startKindFilterPipeConfig(t){t.startObject(1)}static addKinds(t,e){t.addFieldOffset(0,e,0)}static createKindsVector(t,e){t.startVector(2,e.length,2);for(let s=e.length-1;s>=0;s--)t.addInt16(e[s]);return t.endVector()}static startKindsVector(t,e){t.startVector(2,e,2)}static endKindFilterPipeConfig(t){const e=t.endObject();return t.requiredField(e,4),e}static createKindFilterPipeConfig(t,e){return F.startKindFilterPipeConfig(t),F.addKinds(t,e),F.endKindFilterPipeConfig(t)}unpack(){return new _t(this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()))}unpackTo(t){t.kinds=this.bb.createScalarList(this.kinds.bind(this),this.kindsLength())}}class _t{constructor(t=[]){this.kinds=t}pack(t){const e=F.createKindsVector(t,this.kinds);return F.createKindFilterPipeConfig(t,e)}}class P{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsTemplate(t,e){return(e||new P).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsTemplate(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new P).__init(t.readInt32(t.position())+t.position(),t)}kind(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint16(this.bb_pos+t):0}createdAt(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readInt32(this.bb_pos+t):0}content(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,t):null}tags(t,e){const s=this.bb.__offset(this.bb_pos,10);return s?(e||new Bt).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}tagsLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}static startTemplate(t){t.startObject(4)}static addKind(t,e){t.addFieldInt16(0,e,0)}static addCreatedAt(t,e){t.addFieldInt32(1,e,0)}static addContent(t,e){t.addFieldOffset(2,e,0)}static addTags(t,e){t.addFieldOffset(3,e,0)}static createTagsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startTagsVector(t,e){t.startVector(4,e,4)}static endTemplate(t){const e=t.endObject();return t.requiredField(e,8),t.requiredField(e,10),e}static createTemplate(t,e,s,n,r){return P.startTemplate(t),P.addKind(t,e),P.addCreatedAt(t,s),P.addContent(t,n),P.addTags(t,r),P.endTemplate(t)}unpack(){return new Q(this.kind(),this.createdAt(),this.content(),this.bb.createObjList(this.tags.bind(this),this.tagsLength()))}unpackTo(t){t.kind=this.kind(),t.createdAt=this.createdAt(),t.content=this.content(),t.tags=this.bb.createObjList(this.tags.bind(this),this.tagsLength())}}class Q{constructor(t=0,e=0,s=null,n=[]){this.kind=t,this.createdAt=e,this.content=s,this.tags=n}pack(t){const e=this.content!==null?t.createString(this.content):0,s=P.createTagsVector(t,t.createObjectOffsetList(this.tags));return P.createTemplate(t,this.kind,this.createdAt,e,s)}}class k{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPublish(t,e){return(e||new k).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPublish(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new k).__init(t.readInt32(t.position())+t.position(),t)}publishId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}template(t){const e=this.bb.__offset(this.bb_pos,6);return e?(t||new P).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}relays(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}relaysLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}static startPublish(t){t.startObject(3)}static addPublishId(t,e){t.addFieldOffset(0,e,0)}static addTemplate(t,e){t.addFieldOffset(1,e,0)}static addRelays(t,e){t.addFieldOffset(2,e,0)}static createRelaysVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRelaysVector(t,e){t.startVector(4,e,4)}static endPublish(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),t.requiredField(e,8),e}unpack(){return new Y(this.publishId(),this.template()!==null?this.template().unpack():null,this.bb.createScalarList(this.relays.bind(this),this.relaysLength()))}unpackTo(t){t.publishId=this.publishId(),t.template=this.template()!==null?this.template().unpack():null,t.relays=this.bb.createScalarList(this.relays.bind(this),this.relaysLength())}}class Y{constructor(t=null,e=null,s=[]){this.publishId=t,this.template=e,this.relays=s}pack(t){const e=this.publishId!==null?t.createString(this.publishId):0,s=this.template!==null?this.template.pack(t):0,n=k.createRelaysVector(t,t.createObjectOffsetList(this.relays));return k.startPublish(t),k.addPublishId(t,e),k.addTemplate(t,s),k.addRelays(t,n),k.endPublish(t)}}class K{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPrivateKey(t,e){return(e||new K).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPrivateKey(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new K).__init(t.readInt32(t.position())+t.position(),t)}privateKey(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}static startPrivateKey(t){t.startObject(1)}static addPrivateKey(t,e){t.addFieldOffset(0,e,0)}static endPrivateKey(t){const e=t.endObject();return t.requiredField(e,4),e}static createPrivateKey(t,e){return K.startPrivateKey(t),K.addPrivateKey(t,e),K.endPrivateKey(t)}unpack(){return new Pt(this.privateKey())}unpackTo(t){t.privateKey=this.privateKey()}}class Pt{constructor(t=null){this.privateKey=t}pack(t){const e=this.privateKey!==null?t.createString(this.privateKey):0;return K.createPrivateKey(t,e)}}var $=(i=>(i[i.NONE=0]="NONE",i[i.PrivateKey=1]="PrivateKey",i))($||{});function yt(i,t){switch($[i]){case"NONE":return null;case"PrivateKey":return t(new K);default:return null}}class O{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSetSigner(t,e){return(e||new O).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSetSigner(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new O).__init(t.readInt32(t.position())+t.position(),t)}signerTypeType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):$.NONE}signerType(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startSetSigner(t){t.startObject(2)}static addSignerTypeType(t,e){t.addFieldInt8(0,e,$.NONE)}static addSignerType(t,e){t.addFieldOffset(1,e,0)}static endSetSigner(t){const e=t.endObject();return t.requiredField(e,6),e}static createSetSigner(t,e,s){return O.startSetSigner(t),O.addSignerTypeType(t,e),O.addSignerType(t,s),O.endSetSigner(t)}unpack(){return new kt(this.signerTypeType(),(()=>{const t=yt(this.signerTypeType(),this.signerType.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.signerTypeType=this.signerTypeType(),t.signerType=(()=>{const e=yt(this.signerTypeType(),this.signerType.bind(this));return e===null?null:e.unpack()})()}}class kt{constructor(t=$.NONE,e=null){this.signerTypeType=t,this.signerType=e}pack(t){const e=t.createObjectOffset(this.signerType);return O.createSetSigner(t,this.signerTypeType,e)}}class V{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSignEvent(t,e){return(e||new V).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSignEvent(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new V).__init(t.readInt32(t.position())+t.position(),t)}template(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new P).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}static startSignEvent(t){t.startObject(1)}static addTemplate(t,e){t.addFieldOffset(0,e,0)}static endSignEvent(t){const e=t.endObject();return t.requiredField(e,4),e}static createSignEvent(t,e){return V.startSignEvent(t),V.addTemplate(t,e),V.endSignEvent(t)}unpack(){return new wt(this.template()!==null?this.template().unpack():null)}unpackTo(t){t.template=this.template()!==null?this.template().unpack():null}}class wt{constructor(t=null){this.template=t}pack(t){const e=this.template!==null?this.template.pack(t):0;return V.createSignEvent(t,e)}}class l{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsMuteFilterPipeConfig(t,e){return(e||new l).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMuteFilterPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new l).__init(t.readInt32(t.position())+t.position(),t)}pubkeys(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}pubkeysLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}hashtags(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}hashtagsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}words(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}wordsLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}eventIds(t,e){const s=this.bb.__offset(this.bb_pos,10);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}eventIdsLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}static startMuteFilterPipeConfig(t){t.startObject(4)}static addPubkeys(t,e){t.addFieldOffset(0,e,0)}static createPubkeysVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startPubkeysVector(t,e){t.startVector(4,e,4)}static addHashtags(t,e){t.addFieldOffset(1,e,0)}static createHashtagsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startHashtagsVector(t,e){t.startVector(4,e,4)}static addWords(t,e){t.addFieldOffset(2,e,0)}static createWordsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startWordsVector(t,e){t.startVector(4,e,4)}static addEventIds(t,e){t.addFieldOffset(3,e,0)}static createEventIdsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startEventIdsVector(t,e){t.startVector(4,e,4)}static endMuteFilterPipeConfig(t){return t.endObject()}static createMuteFilterPipeConfig(t,e,s,n,r){return l.startMuteFilterPipeConfig(t),l.addPubkeys(t,e),l.addHashtags(t,s),l.addWords(t,n),l.addEventIds(t,r),l.endMuteFilterPipeConfig(t)}unpack(){return new St(this.bb.createScalarList(this.pubkeys.bind(this),this.pubkeysLength()),this.bb.createScalarList(this.hashtags.bind(this),this.hashtagsLength()),this.bb.createScalarList(this.words.bind(this),this.wordsLength()),this.bb.createScalarList(this.eventIds.bind(this),this.eventIdsLength()))}unpackTo(t){t.pubkeys=this.bb.createScalarList(this.pubkeys.bind(this),this.pubkeysLength()),t.hashtags=this.bb.createScalarList(this.hashtags.bind(this),this.hashtagsLength()),t.words=this.bb.createScalarList(this.words.bind(this),this.wordsLength()),t.eventIds=this.bb.createScalarList(this.eventIds.bind(this),this.eventIdsLength())}}class St{constructor(t=[],e=[],s=[],n=[]){this.pubkeys=t,this.hashtags=e,this.words=s,this.eventIds=n}pack(t){const e=l.createPubkeysVector(t,t.createObjectOffsetList(this.pubkeys)),s=l.createHashtagsVector(t,t.createObjectOffsetList(this.hashtags)),n=l.createWordsVector(t,t.createObjectOffsetList(this.words)),r=l.createEventIdsVector(t,t.createObjectOffsetList(this.eventIds));return l.createMuteFilterPipeConfig(t,e,s,n,r)}}class S{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsNpubLimiterPipeConfig(t,e){return(e||new S).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsNpubLimiterPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new S).__init(t.readInt32(t.position())+t.position(),t)}kind(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint16(this.bb_pos+t):0}limitPerNpub(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readUint32(this.bb_pos+t):0}maxTotalNpubs(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.readUint32(this.bb_pos+t):0}static startNpubLimiterPipeConfig(t){t.startObject(3)}static addKind(t,e){t.addFieldInt16(0,e,0)}static addLimitPerNpub(t,e){t.addFieldInt32(1,e,0)}static addMaxTotalNpubs(t,e){t.addFieldInt32(2,e,0)}static endNpubLimiterPipeConfig(t){return t.endObject()}static createNpubLimiterPipeConfig(t,e,s,n){return S.startNpubLimiterPipeConfig(t),S.addKind(t,e),S.addLimitPerNpub(t,s),S.addMaxTotalNpubs(t,n),S.endNpubLimiterPipeConfig(t)}unpack(){return new It(this.kind(),this.limitPerNpub(),this.maxTotalNpubs())}unpackTo(t){t.kind=this.kind(),t.limitPerNpub=this.limitPerNpub(),t.maxTotalNpubs=this.maxTotalNpubs()}}class It{constructor(t=0,e=0,s=0){this.kind=t,this.limitPerNpub=e,this.maxTotalNpubs=s}pack(t){return S.createNpubLimiterPipeConfig(t,this.kind,this.limitPerNpub,this.maxTotalNpubs)}}class q{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsParsePipeConfig(t,e){return(e||new q).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsParsePipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new q).__init(t.readInt32(t.position())+t.position(),t)}static startParsePipeConfig(t){t.startObject(0)}static endParsePipeConfig(t){return t.endObject()}static createParsePipeConfig(t){return q.startParsePipeConfig(t),q.endParsePipeConfig(t)}unpack(){return new vt}unpackTo(t){}}class vt{constructor(){}pack(t){return q.createParsePipeConfig(t)}}class A{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsProofVerificationPipeConfig(t,e){return(e||new A).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsProofVerificationPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new A).__init(t.readInt32(t.position())+t.position(),t)}maxProofs(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint32(this.bb_pos+t):0}static startProofVerificationPipeConfig(t){t.startObject(1)}static addMaxProofs(t,e){t.addFieldInt32(0,e,0)}static endProofVerificationPipeConfig(t){return t.endObject()}static createProofVerificationPipeConfig(t,e){return A.startProofVerificationPipeConfig(t),A.addMaxProofs(t,e),A.endProofVerificationPipeConfig(t)}unpack(){return new Ct(this.maxProofs())}unpackTo(t){t.maxProofs=this.maxProofs()}}class Ct{constructor(t=0){this.maxProofs=t}pack(t){return A.createProofVerificationPipeConfig(t,this.maxProofs)}}class z{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSaveToDbPipeConfig(t,e){return(e||new z).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSaveToDbPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new z).__init(t.readInt32(t.position())+t.position(),t)}static startSaveToDbPipeConfig(t){t.startObject(0)}static endSaveToDbPipeConfig(t){return t.endObject()}static createSaveToDbPipeConfig(t){return z.startSaveToDbPipeConfig(t),z.endSaveToDbPipeConfig(t)}unpack(){return new Et}unpackTo(t){}}class Et{constructor(){}pack(t){return z.createSaveToDbPipeConfig(t)}}class x{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSerializeEventsPipeConfig(t,e){return(e||new x).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSerializeEventsPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new x).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}static startSerializeEventsPipeConfig(t){t.startObject(1)}static addSubscriptionId(t,e){t.addFieldOffset(0,e,0)}static endSerializeEventsPipeConfig(t){const e=t.endObject();return t.requiredField(e,4),e}static createSerializeEventsPipeConfig(t,e){return x.startSerializeEventsPipeConfig(t),x.addSubscriptionId(t,e),x.endSerializeEventsPipeConfig(t)}unpack(){return new mt(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class mt{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return x.createSerializeEventsPipeConfig(t,e)}}var H=(i=>(i[i.NONE=0]="NONE",i[i.ParsePipeConfig=1]="ParsePipeConfig",i[i.KindFilterPipeConfig=2]="KindFilterPipeConfig",i[i.CounterPipeConfig=3]="CounterPipeConfig",i[i.NpubLimiterPipeConfig=4]="NpubLimiterPipeConfig",i[i.SaveToDbPipeConfig=5]="SaveToDbPipeConfig",i[i.SerializeEventsPipeConfig=6]="SerializeEventsPipeConfig",i[i.ProofVerificationPipeConfig=7]="ProofVerificationPipeConfig",i[i.MuteFilterPipeConfig=8]="MuteFilterPipeConfig",i))(H||{});function Ot(i,t){switch(H[i]){case"NONE":return null;case"ParsePipeConfig":return t(new q);case"KindFilterPipeConfig":return t(new F);case"CounterPipeConfig":return t(new I);case"NpubLimiterPipeConfig":return t(new S);case"SaveToDbPipeConfig":return t(new z);case"SerializeEventsPipeConfig":return t(new x);case"ProofVerificationPipeConfig":return t(new A);case"MuteFilterPipeConfig":return t(new l);default:return null}}class T{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPipe(t,e){return(e||new T).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipe(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new T).__init(t.readInt32(t.position())+t.position(),t)}configType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):H.NONE}config(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startPipe(t){t.startObject(2)}static addConfigType(t,e){t.addFieldInt8(0,e,H.NONE)}static addConfig(t,e){t.addFieldOffset(1,e,0)}static endPipe(t){const e=t.endObject();return t.requiredField(e,6),e}static createPipe(t,e,s){return T.startPipe(t),T.addConfigType(t,e),T.addConfig(t,s),T.endPipe(t)}unpack(){return new Tt(this.configType(),(()=>{const t=Ot(this.configType(),this.config.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.configType=this.configType(),t.config=(()=>{const e=Ot(this.configType(),this.config.bind(this));return e===null?null:e.unpack()})()}}class Tt{constructor(t=H.NONE,e=null){this.configType=t,this.config=e}pack(t){const e=t.createObjectOffset(this.config);return T.createPipe(t,this.configType,e)}}class R{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPipelineConfig(t,e){return(e||new R).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipelineConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new R).__init(t.readInt32(t.position())+t.position(),t)}pipes(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?(e||new T).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}pipesLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}static startPipelineConfig(t){t.startObject(1)}static addPipes(t,e){t.addFieldOffset(0,e,0)}static createPipesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startPipesVector(t,e){t.startVector(4,e,4)}static endPipelineConfig(t){const e=t.endObject();return t.requiredField(e,4),e}static createPipelineConfig(t,e){return R.startPipelineConfig(t),R.addPipes(t,e),R.endPipelineConfig(t)}unpack(){return new tt(this.bb.createObjList(this.pipes.bind(this),this.pipesLength()))}unpackTo(t){t.pipes=this.bb.createObjList(this.pipes.bind(this),this.pipesLength())}}class tt{constructor(t=[]){this.pipes=t}pack(t){const e=R.createPipesVector(t,t.createObjectOffsetList(this.pipes));return R.createPipelineConfig(t,e)}}class p{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSubscriptionConfig(t,e){return(e||new p).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscriptionConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new p).__init(t.readInt32(t.position())+t.position(),t)}pipeline(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new R).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}closeOnEose(){const t=this.bb.__offset(this.bb_pos,6);return t?!!this.bb.readInt8(this.bb_pos+t):!1}cacheFirst(){const t=this.bb.__offset(this.bb_pos,8);return t?!!this.bb.readInt8(this.bb_pos+t):!0}timeoutMs(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.readUint64(this.bb_pos+t):BigInt("0")}maxEvents(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.readUint32(this.bb_pos+t):0}skipCache(){const t=this.bb.__offset(this.bb_pos,14);return t?!!this.bb.readInt8(this.bb_pos+t):!1}force(){const t=this.bb.__offset(this.bb_pos,16);return t?!!this.bb.readInt8(this.bb_pos+t):!1}bytesPerEvent(){const t=this.bb.__offset(this.bb_pos,18);return t?this.bb.readUint32(this.bb_pos+t):0}isSlow(){const t=this.bb.__offset(this.bb_pos,20);return t?!!this.bb.readInt8(this.bb_pos+t):!1}pagination(t){const e=this.bb.__offset(this.bb_pos,22);return e?this.bb.__string(this.bb_pos+e,t):null}static startSubscriptionConfig(t){t.startObject(10)}static addPipeline(t,e){t.addFieldOffset(0,e,0)}static addCloseOnEose(t,e){t.addFieldInt8(1,+e,0)}static addCacheFirst(t,e){t.addFieldInt8(2,+e,1)}static addTimeoutMs(t,e){t.addFieldInt64(3,e,BigInt("0"))}static addMaxEvents(t,e){t.addFieldInt32(4,e,0)}static addSkipCache(t,e){t.addFieldInt8(5,+e,0)}static addForce(t,e){t.addFieldInt8(6,+e,0)}static addBytesPerEvent(t,e){t.addFieldInt32(7,e,0)}static addIsSlow(t,e){t.addFieldInt8(8,+e,0)}static addPagination(t,e){t.addFieldOffset(9,e,0)}static endSubscriptionConfig(t){return t.endObject()}static createSubscriptionConfig(t,e,s,n,r,o,a,b,f,u,y){return p.startSubscriptionConfig(t),p.addPipeline(t,e),p.addCloseOnEose(t,s),p.addCacheFirst(t,n),p.addTimeoutMs(t,r),p.addMaxEvents(t,o),p.addSkipCache(t,a),p.addForce(t,b),p.addBytesPerEvent(t,f),p.addIsSlow(t,u),p.addPagination(t,y),p.endSubscriptionConfig(t)}unpack(){return new et(this.pipeline()!==null?this.pipeline().unpack():null,this.closeOnEose(),this.cacheFirst(),this.timeoutMs(),this.maxEvents(),this.skipCache(),this.force(),this.bytesPerEvent(),this.isSlow(),this.pagination())}unpackTo(t){t.pipeline=this.pipeline()!==null?this.pipeline().unpack():null,t.closeOnEose=this.closeOnEose(),t.cacheFirst=this.cacheFirst(),t.timeoutMs=this.timeoutMs(),t.maxEvents=this.maxEvents(),t.skipCache=this.skipCache(),t.force=this.force(),t.bytesPerEvent=this.bytesPerEvent(),t.isSlow=this.isSlow(),t.pagination=this.pagination()}}class et{constructor(t=null,e=!1,s=!0,n=BigInt("0"),r=0,o=!1,a=!1,b=0,f=!1,u=null){this.pipeline=t,this.closeOnEose=e,this.cacheFirst=s,this.timeoutMs=n,this.maxEvents=r,this.skipCache=o,this.force=a,this.bytesPerEvent=b,this.isSlow=f,this.pagination=u}pack(t){const e=this.pipeline!==null?this.pipeline.pack(t):0,s=this.pagination!==null?t.createString(this.pagination):0;return p.createSubscriptionConfig(t,e,this.closeOnEose,this.cacheFirst,this.timeoutMs,this.maxEvents,this.skipCache,this.force,this.bytesPerEvent,this.isSlow,s)}}class w{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSubscribe(t,e){return(e||new w).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscribe(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new w).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}requests(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new ct).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}requestsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}config(t){const e=this.bb.__offset(this.bb_pos,8);return e?(t||new p).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}static startSubscribe(t){t.startObject(3)}static addSubscriptionId(t,e){t.addFieldOffset(0,e,0)}static addRequests(t,e){t.addFieldOffset(1,e,0)}static createRequestsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRequestsVector(t,e){t.startVector(4,e,4)}static addConfig(t,e){t.addFieldOffset(2,e,0)}static endSubscribe(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),t.requiredField(e,8),e}unpack(){return new st(this.subscriptionId(),this.bb.createObjList(this.requests.bind(this),this.requestsLength()),this.config()!==null?this.config().unpack():null)}unpackTo(t){t.subscriptionId=this.subscriptionId(),t.requests=this.bb.createObjList(this.requests.bind(this),this.requestsLength()),t.config=this.config()!==null?this.config().unpack():null}}class st{constructor(t=null,e=[],s=null){this.subscriptionId=t,this.requests=e,this.config=s}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0,s=w.createRequestsVector(t,t.createObjectOffsetList(this.requests)),n=this.config!==null?this.config.pack(t):0;return w.startSubscribe(t),w.addSubscriptionId(t,e),w.addRequests(t,s),w.addConfig(t,n),w.endSubscribe(t)}}class j{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsUnsubscribe(t,e){return(e||new j).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsUnsubscribe(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new j).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}static startUnsubscribe(t){t.startObject(1)}static addSubscriptionId(t,e){t.addFieldOffset(0,e,0)}static endUnsubscribe(t){const e=t.endObject();return t.requiredField(e,4),e}static createUnsubscribe(t,e){return j.startUnsubscribe(t),j.addSubscriptionId(t,e),j.endUnsubscribe(t)}unpack(){return new it(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class it{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return j.createUnsubscribe(t,e)}}var E=(i=>(i[i.NONE=0]="NONE",i[i.Subscribe=1]="Subscribe",i[i.Unsubscribe=2]="Unsubscribe",i[i.Publish=3]="Publish",i[i.SignEvent=4]="SignEvent",i[i.SetSigner=5]="SetSigner",i[i.GetPublicKey=6]="GetPublicKey",i))(E||{});function Ft(i,t){switch(E[i]){case"NONE":return null;case"Subscribe":return t(new w);case"Unsubscribe":return t(new j);case"Publish":return t(new k);case"SignEvent":return t(new V);case"SetSigner":return t(new O);case"GetPublicKey":return t(new U);default:return null}}class M{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsMainMessage(t,e){return(e||new M).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMainMessage(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new M).__init(t.readInt32(t.position())+t.position(),t)}contentType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):E.NONE}content(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startMainMessage(t){t.startObject(2)}static addContentType(t,e){t.addFieldInt8(0,e,E.NONE)}static addContent(t,e){t.addFieldOffset(1,e,0)}static endMainMessage(t){const e=t.endObject();return t.requiredField(e,6),e}static createMainMessage(t,e,s){return M.startMainMessage(t),M.addContentType(t,e),M.addContent(t,s),M.endMainMessage(t)}unpack(){return new D(this.contentType(),(()=>{const t=Ft(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.contentType=this.contentType(),t.content=(()=>{const e=Ft(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class D{constructor(t=E.NONE,e=null){this.contentType=t,this.content=e}pack(t){const e=t.createObjectOffset(this.content);return M.createMainMessage(t,this.contentType,e)}}var Rt=(i=>(i[i.Kind0Parsed=0]="Kind0Parsed",i[i.Kind1Parsed=1]="Kind1Parsed",i[i.Kind3Parsed=3]="Kind3Parsed",i[i.Kind4Parsed=4]="Kind4Parsed",i[i.Kind6Parsed=6]="Kind6Parsed",i[i.Kind7Parsed=7]="Kind7Parsed",i[i.Kind17Parsed=17]="Kind17Parsed",i[i.Kind20Parsed=20]="Kind20Parsed",i[i.Kind22Parsed=22]="Kind22Parsed",i[i.Kind1111Parsed=1111]="Kind1111Parsed",i[i.Kind1311Parsed=1311]="Kind1311Parsed",i[i.Kind7374Parsed=7374]="Kind7374Parsed",i[i.Kind7375Parsed=7375]="Kind7375Parsed",i[i.Kind7376Parsed=7376]="Kind7376Parsed",i[i.Kind9321Parsed=9321]="Kind9321Parsed",i[i.Kind9735Parsed=9735]="Kind9735Parsed",i[i.Kind10002Parsed=10002]="Kind10002Parsed",i[i.Kind10019Parsed=10019]="Kind10019Parsed",i[i.Kind17375Parsed=17375]="Kind17375Parsed",i[i.Kind30023Parsed=30023]="Kind30023Parsed",i[i.Kind39089Parsed=39089]="Kind39089Parsed",i[i.ListParsed=51e3]="ListParsed",i[i.PreGenericParsed=52e3]="PreGenericParsed",i))(Rt||{}),Lt=(i=>(i[i.CachedEvent=0]="CachedEvent",i[i.FetchedEvent=1]="FetchedEvent",i[i.Count=2]="Count",i[i.ConnectionStatus=3]="ConnectionStatus",i[i.Eoce=4]="Eoce",i[i.BufferFull=5]="BufferFull",i))(Lt||{});class W{static initializeBuffer(t){new DataView(t).setUint32(0,4,!0)}static writeMessage(t,e){const s=new DataView(t),n=new Uint8Array(t),r=s.getUint32(0,!0),o=4+e.length;if(r+o>t.byteLength)return console.warn("Buffer full, cannot write message"),!1;s.setUint32(r,e.length,!0),n.set(e,r+4);const a=r+o;return s.setUint32(0,a,!0),!0}static writeBatchedData(t,e,s){const n=new DataView(t),r=new Uint8Array(t),o=n.getUint32(0,!0);if(o+e.length>t.byteLength)return console.warn(`[ArrayBufferReader] Dropping ${s?`event for subscription '${s}'`:"event"}: buffer full (${o}/${t.byteLength} bytes used, need ${e.length} more bytes). Consider increasing 'bytesPerEvent' or reducing subscription limits.`),!1;r.set(e,o);const a=o+e.length;return n.setUint32(0,a,!0),!0}static readMessages(t,e=0,s){const n=new DataView(t),r=new Uint8Array(t),o=n.getUint32(0,!0),a=4;let b=e<a?a:e;if(o<=b)return{messages:[],newReadPosition:b,hasNewData:!1};const f=128,u=new Array(f);let y=0;try{for(;b<o&&!(y>=f||b+4>o);){const v=b,G=n.getUint32(v,!0),d=v+4,g=d+G;if(g>o)break;const h=new Uint8Array(r.subarray(d,g)),C=new qt(h),L=bt.getRootAsWorkerMessage(C);u[y++]=L,b=g}return u.length=y,{messages:u,newReadPosition:b,hasNewData:y>0}}catch(v){return console.error("Failed to decode FlatBuffer data from ArrayBuffer:",v),u.length=y,{messages:u,newReadPosition:e<a?a:e,hasNewData:!1}}}static readAllMessages(t){const e=this.readMessages(t,0);return{messages:e.messages,totalMessages:e.messages.length}}static getCurrentWritePosition(t){return new DataView(t).getUint32(0,!0)}static hasNewData(t,e){const s=this.getCurrentWritePosition(t),n=Math.max(e,4);return s>n}static calculateBufferSize(t=100,e=3072){const s=t*e,n=Math.floor(s*.25);return 4+s+n}}function Nt(i,t,e,s){if(!Number.isInteger(i)||i<0||i>65535)throw new Error(`Invalid kind: ${i}`);if(!Z(t))throw new Error(`Invalid pubkey hex (expected 64 lowercase hex chars): ${t}`);if(!e||typeof e!="string")throw new Error(`Invalid d tag: ${e}`);return dt.naddrEncode({identifier:e,kind:i,pubkey:t,relays:s&&s.length?s:void 0})}function Ht(i,t){const e=X(i.tags);if(!e)throw new Error(`Missing "d" tag for PRE event of kind ${i.kind}`);return Nt(i.kind,i.pubkey,e,t)}function Dt(i){const t=dt.decode(i);if(t.type!=="naddr")throw new Error(`Invalid naddr type: ${t.type}`);const{identifier:e,kind:s,pubkey:n,relays:r}=t.data;return{kind:s,pubkey:n,d:e,relays:r}}function Z(i){return/^[0-9a-f]{64}$/.test(i)}function Mt(i){return i.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")}function nt(i=9){const t=Math.max(1,Math.min(i,64));let e;if(typeof globalThis<"u"&&globalThis.crypto?.getRandomValues)e=new Uint8Array(t),globalThis.crypto.getRandomValues(e);else{e=new Uint8Array(t);for(let s=0;s<t;s++)e[s]=Math.floor(Math.random()*256)}return(typeof Buffer<"u"?Buffer.from(e).toString("base64"):btoa(String.fromCharCode(...e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function X(i){for(const t of i)if(t[0]==="d"&&typeof t[1]=="string"&&t[1].length>0)return t[1]}function Kt(i,t,e){const s=X(i);if(s)return s;if(t&&t.trim().length>0){const n=Mt(t.trim());return n.length>0?n:nt(e?.randomBytes??9)}return nt(e?.randomBytes??9)}function rt(i,t,e){if(!Number.isInteger(i)||i<0||i>65535)throw new Error(`Invalid kind: ${i}`);if(!Z(t))throw new Error(`Invalid pubkey hex (expected 64 lowercase hex chars): ${t}`);if(!e||typeof e!="string")throw new Error(`Invalid d tag: ${e}`);return`${i}:${t}:${e}`}function Vt(i){const t=i.split(":");if(t.length!==3)throw new Error(`Invalid a-pointer format: ${i}`);const e=Number(t[0]),s=t[1],n=t[2];if(!Number.isInteger(e))throw new Error(`Invalid kind in a-pointer: ${t[0]}`);if(!Z(s))throw new Error(`Invalid pubkey in a-pointer: ${s}`);if(!n)throw new Error(`Invalid d in a-pointer: ${n}`);return{kind:e,pubkey:s,d:n}}function Wt(i){const t=X(i.tags);if(!t)throw new Error(`Missing "d" tag for PRE event of kind ${i.kind}`);return rt(i.kind,i.pubkey,t)}function At(i,t,e,s){const n=rt(i,t,e);if(s&&s.length>0){const r=s.map(o=>encodeURIComponent(o)).join(",");return`naddr-like:${n}?relays=${r}`}return`naddr-like:${n}`}function Xt(i,t){const e=X(i.tags);if(!e)throw new Error(`Missing "d" tag for PRE event of kind ${i.kind}`);return At(i.kind,i.pubkey,e,t)}function Zt(i){if(!i.startsWith("naddr-like:"))throw new Error(`Invalid naddr-like prefix: ${i}`);const t=i.slice(11),[e,s]=t.split("?",2),n=Vt(e);if(!s)return{a:n};const r=new URLSearchParams(s).get("relays"),o=r?r.split(",").map(decodeURIComponent):void 0;return{a:n,relays:o}}function Jt(i){return Number.isInteger(i)&&i>=3e4&&i<4e4}function xt(i,t){const e=[];let s=!1;for(const n of i)!s&&n[0]==="d"?(e.push(["d",t]),s=!0):e.push(n);return s||e.push(["d",t]),e}function Qt(i,t,e){if(X(i))return i.slice();const s=Kt(i,t,e);return xt(i,s)}class jt{constructor(t={}){this.textEncoder=new TextEncoder,this.subscriptions=new Map,this.publishes=new Map,this.activePubkey=null,this._pendingSession=null,this.signCB=g=>{},this.eventTarget=new EventTarget,this.relayStatuses=new Map,this.PERPETUAL_SUBSCRIPTIONS=["notifications","starterpack"];const e=new MessageChannel,s=new MessageChannel,n=new MessageChannel,r=new MessageChannel,o=new MessageChannel,a=new MessageChannel,b=new MessageChannel,f=new MessageChannel,u=!!t.proxy,y=u?new URL("./connections/proxy.js",import.meta.url):new URL("./connections/index.js",import.meta.url),v=new URL("./cache/index.js",import.meta.url),G=new URL("./parser/index.js",import.meta.url),d=new URL("./crypto/index.js",import.meta.url);console.log("constructing crates"),this.connections=new Worker(y,{type:"module"}),this.cache=new Worker(v,{type:"module"}),this.parser=new Worker(G,{type:"module"}),this.crypto=new Worker(d,{type:"module"}),console.log("connectionMode",u?"proxy":"rust"),this.connections.postMessage({type:"init",payload:{mainPort:f.port2,cachePort:r.port1,parserPort:s.port1,cryptoPort:o.port1,...t.proxy?{proxy:t.proxy}:{}}},[f.port2,r.port1,s.port1,o.port1]),this.cache.postMessage({type:"init",payload:{parserPort:e.port1,connectionsPort:r.port2}},[e.port1,r.port2]),this.parserMainPort=b.port1,this.parserMainPort.onmessage=g=>{const{subId:h,data:C}=g.data;if(!h||!C){console.log("[main] ignoring message - missing subId or data");return}const L=this.subscriptions.get(h);if(L){W.writeBatchedData(L.buffer,C,h)&&this.dispatch(`subscription:${h}`,h);return}const at=this.publishes.get(h);if(at){W.writeBatchedData(at.buffer,C,h)&&this.dispatch(`publish:${h}`,h);return}console.log("[main] no subscription or publish found for subId:",h)},this.connectionsMainPort=f.port1,this.connectionsMainPort.onmessage=g=>{const{type:h,status:C,url:L}=JSON.parse(g.data);h==="relay:status"&&L&&C?(this.relayStatuses.set(L,{status:C,timestamp:Date.now()}),this.dispatch("relay:status",{status:C,url:L})):console.log("[main] ignoring message - type:",h,"url:",L,"status:",C)},this.parser.postMessage({type:"init",payload:{connectionsPort:s.port2,cachePort:e.port2,cryptoPort:n.port1,mainPort:b.port2}},[s.port2,e.port2,n.port1,b.port2]),this.crypto.postMessage({type:"init",payload:{parserPort:n.port2,connectionsPort:o.port2,mainPort:a.port1}},[n.port2,o.port2,a.port1]),a.port2.onmessage=g=>{const h=g.data;h.type==="response"&&this.handleCryptoResponse(h)},this.setupWorkerListener(),queueMicrotask(()=>this.restoreSession())}postToWorker(t,e){e&&e.length?this.parser.postMessage(t,e):this.parser.postMessage(t)}handleCryptoResponse(t){if(t.op==="get_pubkey"){console.log("[main] get_pubkey:",t.ok?"success":"failed",t.result),t.ok&&(this.activePubkey=t.result,this._discoveredBunkerUrl&&this._pendingSession?.type==="nip46_qr"&&this._pendingSession?.payload?.clientSecret?(console.log("[main] Converting QR to bunker for pubkey:",this.activePubkey),this.saveSession(this.activePubkey,"nip46_bunker",{url:this._discoveredBunkerUrl,clientSecret:this._pendingSession.payload.clientSecret}),this._pendingSession=null,this._discoveredBunkerUrl=null):this._pendingSession&&(this.saveSession(this.activePubkey,this._pendingSession.type,this._pendingSession.payload),this._pendingSession=null));const e=t.ok&&!!this._pendingSession;this.dispatch("auth",{pubkey:this.activePubkey,hasSigner:e})}else if(t.op==="sign_event"&&t.ok){const e=JSON.parse(t.result);this.signCB(e)}}setupWorkerListener(){this.parser.onmessage=async t=>{const e=typeof t.data=="string"?t.data:void 0;if(e){if(this.subscriptions.has(e)){this.dispatch(`subscription:${e}`,e);return}if(this.publishes.has(e)){this.dispatch(`publish:${e}`,e);return}}},this.crypto.onmessage=async t=>{const e=t.data;if(console.log("[main] crypto.onmessage:",e?.type,e),e?.type==="signer_ready"){console.log("[main] signer_ready:",e.signer_type,e.pubkey),this.activePubkey=e.pubkey,e.signer_type==="nip46"&&e.bunker_url&&this._pendingSession?.payload?.clientSecret?(console.log("[main] NIP-46 session saved for:",e.pubkey),this.saveSession(e.pubkey,"nip46",{url:e.bunker_url,clientSecret:this._pendingSession.payload.clientSecret}),this._pendingSession=null):this._pendingSession&&(this.saveSession(e.pubkey,e.signer_type,this._pendingSession.payload),this._pendingSession=null),this.dispatch("auth",{pubkey:e.pubkey,hasSigner:!0});return}if(e?.type==="response"){this.handleCryptoResponse(e);return}if(e?.type==="extension_request"){const{id:s,op:n,payload:r}=e;try{const o=window.nostr;if(!o)throw new Error("NIP-07 extension (window.nostr) not found");let a;switch(n){case"getPublicKey":a=await o.getPublicKey();break;case"signEvent":a=await o.signEvent(JSON.parse(r));break;case"nip04Encrypt":a=await o.nip04.encrypt(r.pubkey,r.plaintext);break;case"nip04Decrypt":a=await o.nip04.decrypt(r.pubkey,r.ciphertext);break;case"nip44Encrypt":a=await o.nip44.encrypt(r.pubkey,r.plaintext);break;case"nip44Decrypt":a=await o.nip44.decrypt(r.pubkey,r.ciphertext);break;default:throw new Error(`Unknown extension operation: ${n}`)}this.crypto.postMessage({type:"extension_response",id:s,ok:!0,result:a})}catch(o){this.crypto.postMessage({type:"extension_response",id:s,ok:!1,error:o.message||String(o)})}return}}}createShortId(t){if(t.length<64)return t;let e=0;for(let s=0;s<t.length;s++){const n=t.charCodeAt(s);e=(e<<5)-e+n,e=e&e}return Math.abs(e).toString(36).substring(0,63)}addEventListener(t,e,s){this.eventTarget.addEventListener(t,e,s)}removeEventListener(t,e,s){this.eventTarget.removeEventListener(t,e,s)}dispatch(t,e){this.eventTarget.dispatchEvent(new CustomEvent(t,{detail:e}))}subscribe(t,e,s){const n=this.createShortId(t),r=this.subscriptions.get(n);if(r)return r.refCount++,r.buffer;const o=e.reduce((d,g)=>d+(g.limit||100),0),a=W.calculateBufferSize(o,s.bytesPerEvent),b=new ArrayBuffer(a);W.initializeBuffer(b),this.subscriptions.set(n,{buffer:b,options:s,refCount:1});const f=new et(new tt(s.pipeline||[]),s.closeOnEose,s.cacheFirst,s.timeoutMs?BigInt(s.timeoutMs):void 0,s.maxEvents,s.skipCache,s.force,s.bytesPerEvent,s.isSlow,s.pagination?this.textEncoder.encode(s.pagination):null),u=new st(this.textEncoder.encode(n),e.map(d=>new $t(d.ids,d.authors,d.kinds,Object.entries(d.tags||{}).flatMap(([g,h])=>new ht([g,...h])),d.limit,d.since,d.until,this.textEncoder.encode(d.search),d.relays,d.closeOnEOSE,d.cacheFirst,d.noCache)),f),y=new D(E.Subscribe,u),v=new c.Builder(2048);v.finish(y.pack(v));const G=v.asUint8Array();return this.postToWorker({serializedMessage:G},[G.buffer]),b}getBuffer(t){const e=this.subscriptions.get(t);if(e)return e.refCount++,e.buffer}getRelayStatuses(){return new Map(this.relayStatuses)}unsubscribe(t){const e=t.length<64?t:this.createShortId(t),s=this.subscriptions.get(e);s&&s.refCount--}publish(t,e,s=[]){const n=new ArrayBuffer(3072);W.initializeBuffer(n);const r=new Q(e.kind,e.created_at,this.textEncoder.encode(e.content),e.tags.map(u=>new ht(u))||[]),o=new Y(this.textEncoder.encode(t),r,s),a=new D(E.Publish,o),b=new c.Builder(2048);b.finish(a.pack(b));const f=b.asUint8Array();return this.postToWorker({serializedMessage:f},[f.buffer]),this.publishes.set(t,{buffer:n}),n}setSigner(t,e){switch(this._pendingSession={type:t,payload:e},console.log("[main] set pending session:",t),t){case"pubkey":this.activePubkey=e,this.saveSession(this.activePubkey,"pubkey",e),this._pendingSession=null,this.dispatch("auth",{pubkey:this.activePubkey,hasSigner:!1});break;case"privkey":this.crypto.postMessage({type:"set_private_key",payload:e});break;case"nip07":this.crypto.postMessage({type:"set_nip07"});break;case"nip46":e?.url?.startsWith("bunker://")?this.crypto.postMessage({type:"set_nip46_bunker",payload:e}):e?.url?.startsWith("nostrconnect://")?this.crypto.postMessage({type:"set_nip46_qr",payload:e}):console.error("[main] Unknown NIP-46 URL format:",e?.url);break}}signEvent(t,e){this.signCB=e,this.crypto.postMessage({type:"sign_event",payload:JSON.stringify(t)})}getPublicKey(){const t=new D(E.GetPublicKey,new J),e=new c.Builder(2048);e.finish(t.pack(e));const s=e.asUint8Array();this.parser.postMessage({serializedMessage:s},[s.buffer])}generateClientSecret(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}setNip46Bunker(t,e){const s=e||this.generateClientSecret();console.log("[main] NIP-46 bunker:",t.slice(0,50)+"..."),this.setSigner("nip46",{url:t,clientSecret:s})}setNip46QR(t,e){const s=e||this.generateClientSecret();console.log("[main] NIP-46 QR:",t.slice(0,50)+"..."),this.setSigner("nip46",{url:t,clientSecret:s})}setNip07(){this.setSigner("nip07","")}setPubkey(t){this.setSigner("pubkey",t)}getActivePubkey(){return this.activePubkey}getSubscriptionCount(){return this.subscriptions.size}getAccounts(){const t=localStorage.getItem("nostr_signer_accounts")||"{}";try{return JSON.parse(t)}catch{return{}}}switchAccount(t){const e=this.getAccounts()[t];e&&this.setSigner(e.type,e.payload)}saveSession(t,e,s){console.log("[main] saveSession:",{pubkey:t.slice(0,16)+"...",type:e,hasClientSecret:!!s?.clientSecret});const n=this.getAccounts();n[t]={type:e,payload:s},localStorage.setItem("nostr_signer_accounts",JSON.stringify(n)),localStorage.setItem("nostr_active_pubkey",t),console.log("[main] Session saved to localStorage")}restoreSession(){const t=localStorage.getItem("nostr_active_pubkey");t?this.switchAccount(t):this.dispatch("auth",{pubkey:null,hasSigner:!1})}logout(){this._pendingSession=null,this.activePubkey=null,this.crypto.postMessage({type:"clear_signer"}),localStorage.removeItem("nostr_active_pubkey"),this.dispatch("logout")}removeAccount(){const t=this.activePubkey;if(!t)return;const e=this.getAccounts();delete e[t],localStorage.setItem("nostr_signer_accounts",JSON.stringify(e));const s=Object.keys(e);if(s.length>0){const n=s[0];n&&this.switchAccount(n)}else this.logout()}cleanup(){const t=[];for(const[e,s]of this.subscriptions.entries())s.refCount<=0&&!this.PERPETUAL_SUBSCRIPTIONS.includes(e)&&t.push(e);for(const e of t){const s=new it(this.textEncoder.encode(e)),n=new D(E.Unsubscribe,s),r=new c.Builder(256);r.finish(n.pack(r));const o=r.asUint8Array();this.postToWorker({serializedMessage:o},[o.buffer]),this.connections.postMessage(e),this.subscriptions.delete(e)}}}function Yt(i){return new jt(i)}let ot=null;function te(){if(!ot)throw new Error("[nipworker] Global manager is not set. Call setManager(createNostrManager(...)) before using hooks.");return ot}function Ut(i){ot=i}function ee(i){Ut(i)}export{A as $,W as A,ft as B,B as C,I as D,gt as E,J as F,U as G,_t as H,M as I,D as J,F as K,l as L,E as M,jt as N,St as O,S as P,It as Q,q as R,vt as S,Rt as T,T as U,Tt as V,H as W,R as X,tt as Y,K as Z,Pt as _,ee as a,Ct as a0,k as a1,Y as a2,z as a3,Et as a4,x as a5,mt as a6,O as a7,kt as a8,V as a9,wt as aa,$ as ab,w as ac,st as ad,Lt as ae,p as af,et as ag,P as ah,Q as ai,j as aj,it as ak,Ht as b,Yt as c,Kt as d,X as e,rt as f,te as g,Vt as h,Z as i,Wt as j,At as k,Xt as l,Nt as m,Mt as n,Zt as o,Dt as p,Jt as q,nt as r,Ut as s,Qt as t,xt as u,N as v,lt as w,_ as x,pt as y,m as z};
1
+ import*as c from"flatbuffers";import{ByteBuffer as qt}from"flatbuffers";import{m as ct,N as zt,n as Gt,W as bt,S as Bt,o as $t,p as ht}from"./worker-message.js";import"./signer-response.js";import{nip19 as dt}from"nostr-tools";class _{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCacheRequest(t,e){return(e||new _).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCacheRequest(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new _).__init(t.readInt32(t.position())+t.position(),t)}subId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}requests(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new ct).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}requestsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}event(t){const e=this.bb.__offset(this.bb_pos,8);return e?(t||new zt).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}parsedEvent(t){const e=this.bb.__offset(this.bb_pos,10);return e?(t||new Gt).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}relays(t,e){const s=this.bb.__offset(this.bb_pos,12);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}relaysLength(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}static startCacheRequest(t){t.startObject(5)}static addSubId(t,e){t.addFieldOffset(0,e,0)}static addRequests(t,e){t.addFieldOffset(1,e,0)}static createRequestsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRequestsVector(t,e){t.startVector(4,e,4)}static addEvent(t,e){t.addFieldOffset(2,e,0)}static addParsedEvent(t,e){t.addFieldOffset(3,e,0)}static addRelays(t,e){t.addFieldOffset(4,e,0)}static createRelaysVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRelaysVector(t,e){t.startVector(4,e,4)}static endCacheRequest(t){const e=t.endObject();return t.requiredField(e,4),e}unpack(){return new pt(this.subId(),this.bb.createObjList(this.requests.bind(this),this.requestsLength()),this.event()!==null?this.event().unpack():null,this.parsedEvent()!==null?this.parsedEvent().unpack():null,this.bb.createScalarList(this.relays.bind(this),this.relaysLength()))}unpackTo(t){t.subId=this.subId(),t.requests=this.bb.createObjList(this.requests.bind(this),this.requestsLength()),t.event=this.event()!==null?this.event().unpack():null,t.parsedEvent=this.parsedEvent()!==null?this.parsedEvent().unpack():null,t.relays=this.bb.createScalarList(this.relays.bind(this),this.relaysLength())}}class pt{constructor(t=null,e=[],s=null,n=null,r=[]){this.subId=t,this.requests=e,this.event=s,this.parsedEvent=n,this.relays=r}pack(t){const e=this.subId!==null?t.createString(this.subId):0,s=_.createRequestsVector(t,t.createObjectOffsetList(this.requests)),n=this.event!==null?this.event.pack(t):0,r=this.parsedEvent!==null?this.parsedEvent.pack(t):0,o=_.createRelaysVector(t,t.createObjectOffsetList(this.relays));return _.startCacheRequest(t),_.addSubId(t,e),_.addRequests(t,s),_.addEvent(t,n),_.addParsedEvent(t,r),_.addRelays(t,o),_.endCacheRequest(t)}}var B=(i=>(i[i.NONE=0]="NONE",i[i.WorkerMessage=1]="WorkerMessage",i[i.CacheRequest=2]="CacheRequest",i))(B||{});function ut(i,t){switch(B[i]){case"NONE":return null;case"WorkerMessage":return t(new bt);case"CacheRequest":return t(new _);default:return null}}class N{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCacheInputMessage(t,e){return(e||new N).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCacheInputMessage(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new N).__init(t.readInt32(t.position())+t.position(),t)}contentType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):B.NONE}content(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startCacheInputMessage(t){t.startObject(2)}static addContentType(t,e){t.addFieldInt8(0,e,B.NONE)}static addContent(t,e){t.addFieldOffset(1,e,0)}static endCacheInputMessage(t){const e=t.endObject();return t.requiredField(e,6),e}static createCacheInputMessage(t,e,s){return N.startCacheInputMessage(t),N.addContentType(t,e),N.addContent(t,s),N.endCacheInputMessage(t)}unpack(){return new lt(this.contentType(),(()=>{const t=ut(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.contentType=this.contentType(),t.content=(()=>{const e=ut(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class lt{constructor(t=B.NONE,e=null){this.contentType=t,this.content=e}pack(t){const e=t.createObjectOffset(this.content);return N.createCacheInputMessage(t,this.contentType,e)}}class m{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCacheResponse(t,e){return(e||new m).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCacheResponse(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new m).__init(t.readInt32(t.position())+t.position(),t)}subId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}payload(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb.__vector(this.bb_pos+e)+t):0}payloadLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}payloadArray(){const t=this.bb.__offset(this.bb_pos,6);return t?new Uint8Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startCacheResponse(t){t.startObject(2)}static addSubId(t,e){t.addFieldOffset(0,e,0)}static addPayload(t,e){t.addFieldOffset(1,e,0)}static createPayloadVector(t,e){t.startVector(1,e.length,1);for(let s=e.length-1;s>=0;s--)t.addInt8(e[s]);return t.endVector()}static startPayloadVector(t,e){t.startVector(1,e,1)}static endCacheResponse(t){const e=t.endObject();return t.requiredField(e,4),e}static createCacheResponse(t,e,s){return m.startCacheResponse(t),m.addSubId(t,e),m.addPayload(t,s),m.endCacheResponse(t)}unpack(){return new ft(this.subId(),this.bb.createScalarList(this.payload.bind(this),this.payloadLength()))}unpackTo(t){t.subId=this.subId(),t.payload=this.bb.createScalarList(this.payload.bind(this),this.payloadLength())}}class ft{constructor(t=null,e=[]){this.subId=t,this.payload=e}pack(t){const e=this.subId!==null?t.createString(this.subId):0,s=m.createPayloadVector(t,this.payload);return m.createCacheResponse(t,e,s)}}class I{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCounterPipeConfig(t,e){return(e||new I).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCounterPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new I).__init(t.readInt32(t.position())+t.position(),t)}kinds(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint16(this.bb.__vector(this.bb_pos+e)+t*2):0}kindsLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}kindsArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint16Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}pubkey(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,t):null}static startCounterPipeConfig(t){t.startObject(2)}static addKinds(t,e){t.addFieldOffset(0,e,0)}static createKindsVector(t,e){t.startVector(2,e.length,2);for(let s=e.length-1;s>=0;s--)t.addInt16(e[s]);return t.endVector()}static startKindsVector(t,e){t.startVector(2,e,2)}static addPubkey(t,e){t.addFieldOffset(1,e,0)}static endCounterPipeConfig(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),e}static createCounterPipeConfig(t,e,s){return I.startCounterPipeConfig(t),I.addKinds(t,e),I.addPubkey(t,s),I.endCounterPipeConfig(t)}unpack(){return new gt(this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()),this.pubkey())}unpackTo(t){t.kinds=this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()),t.pubkey=this.pubkey()}}class gt{constructor(t=[],e=null){this.kinds=t,this.pubkey=e}pack(t){const e=I.createKindsVector(t,this.kinds),s=this.pubkey!==null?t.createString(this.pubkey):0;return I.createCounterPipeConfig(t,e,s)}}class U{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsGetPublicKey(t,e){return(e||new U).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsGetPublicKey(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new U).__init(t.readInt32(t.position())+t.position(),t)}static startGetPublicKey(t){t.startObject(0)}static endGetPublicKey(t){return t.endObject()}static createGetPublicKey(t){return U.startGetPublicKey(t),U.endGetPublicKey(t)}unpack(){return new J}unpackTo(t){}}class J{constructor(){}pack(t){return U.createGetPublicKey(t)}}class F{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsKindFilterPipeConfig(t,e){return(e||new F).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsKindFilterPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new F).__init(t.readInt32(t.position())+t.position(),t)}kinds(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint16(this.bb.__vector(this.bb_pos+e)+t*2):0}kindsLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}kindsArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint16Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startKindFilterPipeConfig(t){t.startObject(1)}static addKinds(t,e){t.addFieldOffset(0,e,0)}static createKindsVector(t,e){t.startVector(2,e.length,2);for(let s=e.length-1;s>=0;s--)t.addInt16(e[s]);return t.endVector()}static startKindsVector(t,e){t.startVector(2,e,2)}static endKindFilterPipeConfig(t){const e=t.endObject();return t.requiredField(e,4),e}static createKindFilterPipeConfig(t,e){return F.startKindFilterPipeConfig(t),F.addKinds(t,e),F.endKindFilterPipeConfig(t)}unpack(){return new _t(this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()))}unpackTo(t){t.kinds=this.bb.createScalarList(this.kinds.bind(this),this.kindsLength())}}class _t{constructor(t=[]){this.kinds=t}pack(t){const e=F.createKindsVector(t,this.kinds);return F.createKindFilterPipeConfig(t,e)}}class P{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsTemplate(t,e){return(e||new P).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsTemplate(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new P).__init(t.readInt32(t.position())+t.position(),t)}kind(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint16(this.bb_pos+t):0}createdAt(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readInt32(this.bb_pos+t):0}content(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,t):null}tags(t,e){const s=this.bb.__offset(this.bb_pos,10);return s?(e||new Bt).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}tagsLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}static startTemplate(t){t.startObject(4)}static addKind(t,e){t.addFieldInt16(0,e,0)}static addCreatedAt(t,e){t.addFieldInt32(1,e,0)}static addContent(t,e){t.addFieldOffset(2,e,0)}static addTags(t,e){t.addFieldOffset(3,e,0)}static createTagsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startTagsVector(t,e){t.startVector(4,e,4)}static endTemplate(t){const e=t.endObject();return t.requiredField(e,8),t.requiredField(e,10),e}static createTemplate(t,e,s,n,r){return P.startTemplate(t),P.addKind(t,e),P.addCreatedAt(t,s),P.addContent(t,n),P.addTags(t,r),P.endTemplate(t)}unpack(){return new Q(this.kind(),this.createdAt(),this.content(),this.bb.createObjList(this.tags.bind(this),this.tagsLength()))}unpackTo(t){t.kind=this.kind(),t.createdAt=this.createdAt(),t.content=this.content(),t.tags=this.bb.createObjList(this.tags.bind(this),this.tagsLength())}}class Q{constructor(t=0,e=0,s=null,n=[]){this.kind=t,this.createdAt=e,this.content=s,this.tags=n}pack(t){const e=this.content!==null?t.createString(this.content):0,s=P.createTagsVector(t,t.createObjectOffsetList(this.tags));return P.createTemplate(t,this.kind,this.createdAt,e,s)}}class k{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPublish(t,e){return(e||new k).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPublish(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new k).__init(t.readInt32(t.position())+t.position(),t)}publishId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}template(t){const e=this.bb.__offset(this.bb_pos,6);return e?(t||new P).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}relays(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}relaysLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}static startPublish(t){t.startObject(3)}static addPublishId(t,e){t.addFieldOffset(0,e,0)}static addTemplate(t,e){t.addFieldOffset(1,e,0)}static addRelays(t,e){t.addFieldOffset(2,e,0)}static createRelaysVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRelaysVector(t,e){t.startVector(4,e,4)}static endPublish(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),t.requiredField(e,8),e}unpack(){return new Y(this.publishId(),this.template()!==null?this.template().unpack():null,this.bb.createScalarList(this.relays.bind(this),this.relaysLength()))}unpackTo(t){t.publishId=this.publishId(),t.template=this.template()!==null?this.template().unpack():null,t.relays=this.bb.createScalarList(this.relays.bind(this),this.relaysLength())}}class Y{constructor(t=null,e=null,s=[]){this.publishId=t,this.template=e,this.relays=s}pack(t){const e=this.publishId!==null?t.createString(this.publishId):0,s=this.template!==null?this.template.pack(t):0,n=k.createRelaysVector(t,t.createObjectOffsetList(this.relays));return k.startPublish(t),k.addPublishId(t,e),k.addTemplate(t,s),k.addRelays(t,n),k.endPublish(t)}}class K{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPrivateKey(t,e){return(e||new K).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPrivateKey(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new K).__init(t.readInt32(t.position())+t.position(),t)}privateKey(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}static startPrivateKey(t){t.startObject(1)}static addPrivateKey(t,e){t.addFieldOffset(0,e,0)}static endPrivateKey(t){const e=t.endObject();return t.requiredField(e,4),e}static createPrivateKey(t,e){return K.startPrivateKey(t),K.addPrivateKey(t,e),K.endPrivateKey(t)}unpack(){return new Pt(this.privateKey())}unpackTo(t){t.privateKey=this.privateKey()}}class Pt{constructor(t=null){this.privateKey=t}pack(t){const e=this.privateKey!==null?t.createString(this.privateKey):0;return K.createPrivateKey(t,e)}}var $=(i=>(i[i.NONE=0]="NONE",i[i.PrivateKey=1]="PrivateKey",i))($||{});function yt(i,t){switch($[i]){case"NONE":return null;case"PrivateKey":return t(new K);default:return null}}class O{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSetSigner(t,e){return(e||new O).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSetSigner(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new O).__init(t.readInt32(t.position())+t.position(),t)}signerTypeType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):$.NONE}signerType(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startSetSigner(t){t.startObject(2)}static addSignerTypeType(t,e){t.addFieldInt8(0,e,$.NONE)}static addSignerType(t,e){t.addFieldOffset(1,e,0)}static endSetSigner(t){const e=t.endObject();return t.requiredField(e,6),e}static createSetSigner(t,e,s){return O.startSetSigner(t),O.addSignerTypeType(t,e),O.addSignerType(t,s),O.endSetSigner(t)}unpack(){return new kt(this.signerTypeType(),(()=>{const t=yt(this.signerTypeType(),this.signerType.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.signerTypeType=this.signerTypeType(),t.signerType=(()=>{const e=yt(this.signerTypeType(),this.signerType.bind(this));return e===null?null:e.unpack()})()}}class kt{constructor(t=$.NONE,e=null){this.signerTypeType=t,this.signerType=e}pack(t){const e=t.createObjectOffset(this.signerType);return O.createSetSigner(t,this.signerTypeType,e)}}class V{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSignEvent(t,e){return(e||new V).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSignEvent(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new V).__init(t.readInt32(t.position())+t.position(),t)}template(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new P).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}static startSignEvent(t){t.startObject(1)}static addTemplate(t,e){t.addFieldOffset(0,e,0)}static endSignEvent(t){const e=t.endObject();return t.requiredField(e,4),e}static createSignEvent(t,e){return V.startSignEvent(t),V.addTemplate(t,e),V.endSignEvent(t)}unpack(){return new wt(this.template()!==null?this.template().unpack():null)}unpackTo(t){t.template=this.template()!==null?this.template().unpack():null}}class wt{constructor(t=null){this.template=t}pack(t){const e=this.template!==null?this.template.pack(t):0;return V.createSignEvent(t,e)}}class l{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsMuteFilterPipeConfig(t,e){return(e||new l).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMuteFilterPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new l).__init(t.readInt32(t.position())+t.position(),t)}pubkeys(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}pubkeysLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}hashtags(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}hashtagsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}words(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}wordsLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}eventIds(t,e){const s=this.bb.__offset(this.bb_pos,10);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+t*4,e):null}eventIdsLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}static startMuteFilterPipeConfig(t){t.startObject(4)}static addPubkeys(t,e){t.addFieldOffset(0,e,0)}static createPubkeysVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startPubkeysVector(t,e){t.startVector(4,e,4)}static addHashtags(t,e){t.addFieldOffset(1,e,0)}static createHashtagsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startHashtagsVector(t,e){t.startVector(4,e,4)}static addWords(t,e){t.addFieldOffset(2,e,0)}static createWordsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startWordsVector(t,e){t.startVector(4,e,4)}static addEventIds(t,e){t.addFieldOffset(3,e,0)}static createEventIdsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startEventIdsVector(t,e){t.startVector(4,e,4)}static endMuteFilterPipeConfig(t){return t.endObject()}static createMuteFilterPipeConfig(t,e,s,n,r){return l.startMuteFilterPipeConfig(t),l.addPubkeys(t,e),l.addHashtags(t,s),l.addWords(t,n),l.addEventIds(t,r),l.endMuteFilterPipeConfig(t)}unpack(){return new St(this.bb.createScalarList(this.pubkeys.bind(this),this.pubkeysLength()),this.bb.createScalarList(this.hashtags.bind(this),this.hashtagsLength()),this.bb.createScalarList(this.words.bind(this),this.wordsLength()),this.bb.createScalarList(this.eventIds.bind(this),this.eventIdsLength()))}unpackTo(t){t.pubkeys=this.bb.createScalarList(this.pubkeys.bind(this),this.pubkeysLength()),t.hashtags=this.bb.createScalarList(this.hashtags.bind(this),this.hashtagsLength()),t.words=this.bb.createScalarList(this.words.bind(this),this.wordsLength()),t.eventIds=this.bb.createScalarList(this.eventIds.bind(this),this.eventIdsLength())}}class St{constructor(t=[],e=[],s=[],n=[]){this.pubkeys=t,this.hashtags=e,this.words=s,this.eventIds=n}pack(t){const e=l.createPubkeysVector(t,t.createObjectOffsetList(this.pubkeys)),s=l.createHashtagsVector(t,t.createObjectOffsetList(this.hashtags)),n=l.createWordsVector(t,t.createObjectOffsetList(this.words)),r=l.createEventIdsVector(t,t.createObjectOffsetList(this.eventIds));return l.createMuteFilterPipeConfig(t,e,s,n,r)}}class S{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsNpubLimiterPipeConfig(t,e){return(e||new S).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsNpubLimiterPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new S).__init(t.readInt32(t.position())+t.position(),t)}kind(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint16(this.bb_pos+t):0}limitPerNpub(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readUint32(this.bb_pos+t):0}maxTotalNpubs(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.readUint32(this.bb_pos+t):0}static startNpubLimiterPipeConfig(t){t.startObject(3)}static addKind(t,e){t.addFieldInt16(0,e,0)}static addLimitPerNpub(t,e){t.addFieldInt32(1,e,0)}static addMaxTotalNpubs(t,e){t.addFieldInt32(2,e,0)}static endNpubLimiterPipeConfig(t){return t.endObject()}static createNpubLimiterPipeConfig(t,e,s,n){return S.startNpubLimiterPipeConfig(t),S.addKind(t,e),S.addLimitPerNpub(t,s),S.addMaxTotalNpubs(t,n),S.endNpubLimiterPipeConfig(t)}unpack(){return new It(this.kind(),this.limitPerNpub(),this.maxTotalNpubs())}unpackTo(t){t.kind=this.kind(),t.limitPerNpub=this.limitPerNpub(),t.maxTotalNpubs=this.maxTotalNpubs()}}class It{constructor(t=0,e=0,s=0){this.kind=t,this.limitPerNpub=e,this.maxTotalNpubs=s}pack(t){return S.createNpubLimiterPipeConfig(t,this.kind,this.limitPerNpub,this.maxTotalNpubs)}}class q{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsParsePipeConfig(t,e){return(e||new q).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsParsePipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new q).__init(t.readInt32(t.position())+t.position(),t)}static startParsePipeConfig(t){t.startObject(0)}static endParsePipeConfig(t){return t.endObject()}static createParsePipeConfig(t){return q.startParsePipeConfig(t),q.endParsePipeConfig(t)}unpack(){return new vt}unpackTo(t){}}class vt{constructor(){}pack(t){return q.createParsePipeConfig(t)}}class A{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsProofVerificationPipeConfig(t,e){return(e||new A).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsProofVerificationPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new A).__init(t.readInt32(t.position())+t.position(),t)}maxProofs(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint32(this.bb_pos+t):0}static startProofVerificationPipeConfig(t){t.startObject(1)}static addMaxProofs(t,e){t.addFieldInt32(0,e,0)}static endProofVerificationPipeConfig(t){return t.endObject()}static createProofVerificationPipeConfig(t,e){return A.startProofVerificationPipeConfig(t),A.addMaxProofs(t,e),A.endProofVerificationPipeConfig(t)}unpack(){return new Ct(this.maxProofs())}unpackTo(t){t.maxProofs=this.maxProofs()}}class Ct{constructor(t=0){this.maxProofs=t}pack(t){return A.createProofVerificationPipeConfig(t,this.maxProofs)}}class z{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSaveToDbPipeConfig(t,e){return(e||new z).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSaveToDbPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new z).__init(t.readInt32(t.position())+t.position(),t)}static startSaveToDbPipeConfig(t){t.startObject(0)}static endSaveToDbPipeConfig(t){return t.endObject()}static createSaveToDbPipeConfig(t){return z.startSaveToDbPipeConfig(t),z.endSaveToDbPipeConfig(t)}unpack(){return new Et}unpackTo(t){}}class Et{constructor(){}pack(t){return z.createSaveToDbPipeConfig(t)}}class x{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSerializeEventsPipeConfig(t,e){return(e||new x).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSerializeEventsPipeConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new x).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}static startSerializeEventsPipeConfig(t){t.startObject(1)}static addSubscriptionId(t,e){t.addFieldOffset(0,e,0)}static endSerializeEventsPipeConfig(t){const e=t.endObject();return t.requiredField(e,4),e}static createSerializeEventsPipeConfig(t,e){return x.startSerializeEventsPipeConfig(t),x.addSubscriptionId(t,e),x.endSerializeEventsPipeConfig(t)}unpack(){return new mt(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class mt{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return x.createSerializeEventsPipeConfig(t,e)}}var H=(i=>(i[i.NONE=0]="NONE",i[i.ParsePipeConfig=1]="ParsePipeConfig",i[i.KindFilterPipeConfig=2]="KindFilterPipeConfig",i[i.CounterPipeConfig=3]="CounterPipeConfig",i[i.NpubLimiterPipeConfig=4]="NpubLimiterPipeConfig",i[i.SaveToDbPipeConfig=5]="SaveToDbPipeConfig",i[i.SerializeEventsPipeConfig=6]="SerializeEventsPipeConfig",i[i.ProofVerificationPipeConfig=7]="ProofVerificationPipeConfig",i[i.MuteFilterPipeConfig=8]="MuteFilterPipeConfig",i))(H||{});function Ot(i,t){switch(H[i]){case"NONE":return null;case"ParsePipeConfig":return t(new q);case"KindFilterPipeConfig":return t(new F);case"CounterPipeConfig":return t(new I);case"NpubLimiterPipeConfig":return t(new S);case"SaveToDbPipeConfig":return t(new z);case"SerializeEventsPipeConfig":return t(new x);case"ProofVerificationPipeConfig":return t(new A);case"MuteFilterPipeConfig":return t(new l);default:return null}}class T{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPipe(t,e){return(e||new T).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipe(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new T).__init(t.readInt32(t.position())+t.position(),t)}configType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):H.NONE}config(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startPipe(t){t.startObject(2)}static addConfigType(t,e){t.addFieldInt8(0,e,H.NONE)}static addConfig(t,e){t.addFieldOffset(1,e,0)}static endPipe(t){const e=t.endObject();return t.requiredField(e,6),e}static createPipe(t,e,s){return T.startPipe(t),T.addConfigType(t,e),T.addConfig(t,s),T.endPipe(t)}unpack(){return new Tt(this.configType(),(()=>{const t=Ot(this.configType(),this.config.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.configType=this.configType(),t.config=(()=>{const e=Ot(this.configType(),this.config.bind(this));return e===null?null:e.unpack()})()}}class Tt{constructor(t=H.NONE,e=null){this.configType=t,this.config=e}pack(t){const e=t.createObjectOffset(this.config);return T.createPipe(t,this.configType,e)}}class R{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsPipelineConfig(t,e){return(e||new R).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipelineConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new R).__init(t.readInt32(t.position())+t.position(),t)}pipes(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?(e||new T).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}pipesLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}static startPipelineConfig(t){t.startObject(1)}static addPipes(t,e){t.addFieldOffset(0,e,0)}static createPipesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startPipesVector(t,e){t.startVector(4,e,4)}static endPipelineConfig(t){const e=t.endObject();return t.requiredField(e,4),e}static createPipelineConfig(t,e){return R.startPipelineConfig(t),R.addPipes(t,e),R.endPipelineConfig(t)}unpack(){return new tt(this.bb.createObjList(this.pipes.bind(this),this.pipesLength()))}unpackTo(t){t.pipes=this.bb.createObjList(this.pipes.bind(this),this.pipesLength())}}class tt{constructor(t=[]){this.pipes=t}pack(t){const e=R.createPipesVector(t,t.createObjectOffsetList(this.pipes));return R.createPipelineConfig(t,e)}}class p{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSubscriptionConfig(t,e){return(e||new p).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscriptionConfig(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new p).__init(t.readInt32(t.position())+t.position(),t)}pipeline(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new R).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}closeOnEose(){const t=this.bb.__offset(this.bb_pos,6);return t?!!this.bb.readInt8(this.bb_pos+t):!1}cacheFirst(){const t=this.bb.__offset(this.bb_pos,8);return t?!!this.bb.readInt8(this.bb_pos+t):!0}timeoutMs(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.readUint64(this.bb_pos+t):BigInt("0")}maxEvents(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.readUint32(this.bb_pos+t):0}skipCache(){const t=this.bb.__offset(this.bb_pos,14);return t?!!this.bb.readInt8(this.bb_pos+t):!1}force(){const t=this.bb.__offset(this.bb_pos,16);return t?!!this.bb.readInt8(this.bb_pos+t):!1}bytesPerEvent(){const t=this.bb.__offset(this.bb_pos,18);return t?this.bb.readUint32(this.bb_pos+t):0}isSlow(){const t=this.bb.__offset(this.bb_pos,20);return t?!!this.bb.readInt8(this.bb_pos+t):!1}pagination(t){const e=this.bb.__offset(this.bb_pos,22);return e?this.bb.__string(this.bb_pos+e,t):null}static startSubscriptionConfig(t){t.startObject(10)}static addPipeline(t,e){t.addFieldOffset(0,e,0)}static addCloseOnEose(t,e){t.addFieldInt8(1,+e,0)}static addCacheFirst(t,e){t.addFieldInt8(2,+e,1)}static addTimeoutMs(t,e){t.addFieldInt64(3,e,BigInt("0"))}static addMaxEvents(t,e){t.addFieldInt32(4,e,0)}static addSkipCache(t,e){t.addFieldInt8(5,+e,0)}static addForce(t,e){t.addFieldInt8(6,+e,0)}static addBytesPerEvent(t,e){t.addFieldInt32(7,e,0)}static addIsSlow(t,e){t.addFieldInt8(8,+e,0)}static addPagination(t,e){t.addFieldOffset(9,e,0)}static endSubscriptionConfig(t){return t.endObject()}static createSubscriptionConfig(t,e,s,n,r,o,a,b,f,u,y){return p.startSubscriptionConfig(t),p.addPipeline(t,e),p.addCloseOnEose(t,s),p.addCacheFirst(t,n),p.addTimeoutMs(t,r),p.addMaxEvents(t,o),p.addSkipCache(t,a),p.addForce(t,b),p.addBytesPerEvent(t,f),p.addIsSlow(t,u),p.addPagination(t,y),p.endSubscriptionConfig(t)}unpack(){return new et(this.pipeline()!==null?this.pipeline().unpack():null,this.closeOnEose(),this.cacheFirst(),this.timeoutMs(),this.maxEvents(),this.skipCache(),this.force(),this.bytesPerEvent(),this.isSlow(),this.pagination())}unpackTo(t){t.pipeline=this.pipeline()!==null?this.pipeline().unpack():null,t.closeOnEose=this.closeOnEose(),t.cacheFirst=this.cacheFirst(),t.timeoutMs=this.timeoutMs(),t.maxEvents=this.maxEvents(),t.skipCache=this.skipCache(),t.force=this.force(),t.bytesPerEvent=this.bytesPerEvent(),t.isSlow=this.isSlow(),t.pagination=this.pagination()}}class et{constructor(t=null,e=!1,s=!0,n=BigInt("0"),r=0,o=!1,a=!1,b=0,f=!1,u=null){this.pipeline=t,this.closeOnEose=e,this.cacheFirst=s,this.timeoutMs=n,this.maxEvents=r,this.skipCache=o,this.force=a,this.bytesPerEvent=b,this.isSlow=f,this.pagination=u}pack(t){const e=this.pipeline!==null?this.pipeline.pack(t):0,s=this.pagination!==null?t.createString(this.pagination):0;return p.createSubscriptionConfig(t,e,this.closeOnEose,this.cacheFirst,this.timeoutMs,this.maxEvents,this.skipCache,this.force,this.bytesPerEvent,this.isSlow,s)}}class w{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSubscribe(t,e){return(e||new w).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscribe(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new w).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}requests(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new ct).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+t*4),this.bb):null}requestsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}config(t){const e=this.bb.__offset(this.bb_pos,8);return e?(t||new p).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}static startSubscribe(t){t.startObject(3)}static addSubscriptionId(t,e){t.addFieldOffset(0,e,0)}static addRequests(t,e){t.addFieldOffset(1,e,0)}static createRequestsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRequestsVector(t,e){t.startVector(4,e,4)}static addConfig(t,e){t.addFieldOffset(2,e,0)}static endSubscribe(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),t.requiredField(e,8),e}unpack(){return new st(this.subscriptionId(),this.bb.createObjList(this.requests.bind(this),this.requestsLength()),this.config()!==null?this.config().unpack():null)}unpackTo(t){t.subscriptionId=this.subscriptionId(),t.requests=this.bb.createObjList(this.requests.bind(this),this.requestsLength()),t.config=this.config()!==null?this.config().unpack():null}}class st{constructor(t=null,e=[],s=null){this.subscriptionId=t,this.requests=e,this.config=s}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0,s=w.createRequestsVector(t,t.createObjectOffsetList(this.requests)),n=this.config!==null?this.config.pack(t):0;return w.startSubscribe(t),w.addSubscriptionId(t,e),w.addRequests(t,s),w.addConfig(t,n),w.endSubscribe(t)}}class j{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsUnsubscribe(t,e){return(e||new j).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsUnsubscribe(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new j).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}static startUnsubscribe(t){t.startObject(1)}static addSubscriptionId(t,e){t.addFieldOffset(0,e,0)}static endUnsubscribe(t){const e=t.endObject();return t.requiredField(e,4),e}static createUnsubscribe(t,e){return j.startUnsubscribe(t),j.addSubscriptionId(t,e),j.endUnsubscribe(t)}unpack(){return new it(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class it{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return j.createUnsubscribe(t,e)}}var E=(i=>(i[i.NONE=0]="NONE",i[i.Subscribe=1]="Subscribe",i[i.Unsubscribe=2]="Unsubscribe",i[i.Publish=3]="Publish",i[i.SignEvent=4]="SignEvent",i[i.SetSigner=5]="SetSigner",i[i.GetPublicKey=6]="GetPublicKey",i))(E||{});function Ft(i,t){switch(E[i]){case"NONE":return null;case"Subscribe":return t(new w);case"Unsubscribe":return t(new j);case"Publish":return t(new k);case"SignEvent":return t(new V);case"SetSigner":return t(new O);case"GetPublicKey":return t(new U);default:return null}}class M{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsMainMessage(t,e){return(e||new M).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMainMessage(t,e){return t.setPosition(t.position()+c.SIZE_PREFIX_LENGTH),(e||new M).__init(t.readInt32(t.position())+t.position(),t)}contentType(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint8(this.bb_pos+t):E.NONE}content(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__union(t,this.bb_pos+e):null}static startMainMessage(t){t.startObject(2)}static addContentType(t,e){t.addFieldInt8(0,e,E.NONE)}static addContent(t,e){t.addFieldOffset(1,e,0)}static endMainMessage(t){const e=t.endObject();return t.requiredField(e,6),e}static createMainMessage(t,e,s){return M.startMainMessage(t),M.addContentType(t,e),M.addContent(t,s),M.endMainMessage(t)}unpack(){return new D(this.contentType(),(()=>{const t=Ft(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.contentType=this.contentType(),t.content=(()=>{const e=Ft(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class D{constructor(t=E.NONE,e=null){this.contentType=t,this.content=e}pack(t){const e=t.createObjectOffset(this.content);return M.createMainMessage(t,this.contentType,e)}}var Rt=(i=>(i[i.Kind0Parsed=0]="Kind0Parsed",i[i.Kind1Parsed=1]="Kind1Parsed",i[i.Kind3Parsed=3]="Kind3Parsed",i[i.Kind4Parsed=4]="Kind4Parsed",i[i.Kind6Parsed=6]="Kind6Parsed",i[i.Kind7Parsed=7]="Kind7Parsed",i[i.Kind17Parsed=17]="Kind17Parsed",i[i.Kind20Parsed=20]="Kind20Parsed",i[i.Kind22Parsed=22]="Kind22Parsed",i[i.Kind1111Parsed=1111]="Kind1111Parsed",i[i.Kind1311Parsed=1311]="Kind1311Parsed",i[i.Kind7374Parsed=7374]="Kind7374Parsed",i[i.Kind7375Parsed=7375]="Kind7375Parsed",i[i.Kind7376Parsed=7376]="Kind7376Parsed",i[i.Kind9321Parsed=9321]="Kind9321Parsed",i[i.Kind9735Parsed=9735]="Kind9735Parsed",i[i.Kind10002Parsed=10002]="Kind10002Parsed",i[i.Kind10019Parsed=10019]="Kind10019Parsed",i[i.Kind17375Parsed=17375]="Kind17375Parsed",i[i.Kind30023Parsed=30023]="Kind30023Parsed",i[i.Kind39089Parsed=39089]="Kind39089Parsed",i[i.ListParsed=51e3]="ListParsed",i[i.PreGenericParsed=52e3]="PreGenericParsed",i))(Rt||{}),Lt=(i=>(i[i.CachedEvent=0]="CachedEvent",i[i.FetchedEvent=1]="FetchedEvent",i[i.Count=2]="Count",i[i.ConnectionStatus=3]="ConnectionStatus",i[i.Eoce=4]="Eoce",i[i.BufferFull=5]="BufferFull",i))(Lt||{});class W{static initializeBuffer(t){new DataView(t).setUint32(0,4,!0)}static writeMessage(t,e){const s=new DataView(t),n=new Uint8Array(t),r=s.getUint32(0,!0),o=4+e.length;if(r+o>t.byteLength)return console.warn("Buffer full, cannot write message"),!1;s.setUint32(r,e.length,!0),n.set(e,r+4);const a=r+o;return s.setUint32(0,a,!0),!0}static writeBatchedData(t,e,s){const n=new DataView(t),r=new Uint8Array(t),o=n.getUint32(0,!0);if(o+e.length>t.byteLength)return console.warn(`[ArrayBufferReader] Dropping ${s?`event for subscription '${s}'`:"event"}: buffer full (${o}/${t.byteLength} bytes used, need ${e.length} more bytes). Consider increasing 'bytesPerEvent' or reducing subscription limits.`),!1;r.set(e,o);const a=o+e.length;return n.setUint32(0,a,!0),!0}static readMessages(t,e=0,s){const n=new DataView(t),r=new Uint8Array(t),o=n.getUint32(0,!0),a=4;let b=e<a?a:e;if(o<=b)return{messages:[],newReadPosition:b,hasNewData:!1};const f=128,u=new Array(f);let y=0;try{for(;b<o&&!(y>=f||b+4>o);){const v=b,G=n.getUint32(v,!0),d=v+4,g=d+G;if(g>o)break;const h=new Uint8Array(r.subarray(d,g)),C=new qt(h),L=bt.getRootAsWorkerMessage(C);u[y++]=L,b=g}return u.length=y,{messages:u,newReadPosition:b,hasNewData:y>0}}catch(v){return console.error("Failed to decode FlatBuffer data from ArrayBuffer:",v),u.length=y,{messages:u,newReadPosition:e<a?a:e,hasNewData:!1}}}static readAllMessages(t){const e=this.readMessages(t,0);return{messages:e.messages,totalMessages:e.messages.length}}static getCurrentWritePosition(t){return new DataView(t).getUint32(0,!0)}static hasNewData(t,e){const s=this.getCurrentWritePosition(t),n=Math.max(e,4);return s>n}static calculateBufferSize(t=100,e=3072){const s=t*e,n=Math.floor(s*.25);return 4+s+n}}function Nt(i,t,e,s){if(!Number.isInteger(i)||i<0||i>65535)throw new Error(`Invalid kind: ${i}`);if(!Z(t))throw new Error(`Invalid pubkey hex (expected 64 lowercase hex chars): ${t}`);if(!e||typeof e!="string")throw new Error(`Invalid d tag: ${e}`);return dt.naddrEncode({identifier:e,kind:i,pubkey:t,relays:s&&s.length?s:void 0})}function Ht(i,t){const e=X(i.tags);if(!e)throw new Error(`Missing "d" tag for PRE event of kind ${i.kind}`);return Nt(i.kind,i.pubkey,e,t)}function Dt(i){const t=dt.decode(i);if(t.type!=="naddr")throw new Error(`Invalid naddr type: ${t.type}`);const{identifier:e,kind:s,pubkey:n,relays:r}=t.data;return{kind:s,pubkey:n,d:e,relays:r}}function Z(i){return/^[0-9a-f]{64}$/.test(i)}function Mt(i){return i.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")}function nt(i=9){const t=Math.max(1,Math.min(i,64));let e;if(typeof globalThis<"u"&&globalThis.crypto?.getRandomValues)e=new Uint8Array(t),globalThis.crypto.getRandomValues(e);else{e=new Uint8Array(t);for(let s=0;s<t;s++)e[s]=Math.floor(Math.random()*256)}return(typeof Buffer<"u"?Buffer.from(e).toString("base64"):btoa(String.fromCharCode(...e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function X(i){for(const t of i)if(t[0]==="d"&&typeof t[1]=="string"&&t[1].length>0)return t[1]}function Kt(i,t,e){const s=X(i);if(s)return s;if(t&&t.trim().length>0){const n=Mt(t.trim());return n.length>0?n:nt(e?.randomBytes??9)}return nt(e?.randomBytes??9)}function rt(i,t,e){if(!Number.isInteger(i)||i<0||i>65535)throw new Error(`Invalid kind: ${i}`);if(!Z(t))throw new Error(`Invalid pubkey hex (expected 64 lowercase hex chars): ${t}`);if(!e||typeof e!="string")throw new Error(`Invalid d tag: ${e}`);return`${i}:${t}:${e}`}function Vt(i){const t=i.split(":");if(t.length!==3)throw new Error(`Invalid a-pointer format: ${i}`);const e=Number(t[0]),s=t[1],n=t[2];if(!Number.isInteger(e))throw new Error(`Invalid kind in a-pointer: ${t[0]}`);if(!Z(s))throw new Error(`Invalid pubkey in a-pointer: ${s}`);if(!n)throw new Error(`Invalid d in a-pointer: ${n}`);return{kind:e,pubkey:s,d:n}}function Wt(i){const t=X(i.tags);if(!t)throw new Error(`Missing "d" tag for PRE event of kind ${i.kind}`);return rt(i.kind,i.pubkey,t)}function At(i,t,e,s){const n=rt(i,t,e);if(s&&s.length>0){const r=s.map(o=>encodeURIComponent(o)).join(",");return`naddr-like:${n}?relays=${r}`}return`naddr-like:${n}`}function Xt(i,t){const e=X(i.tags);if(!e)throw new Error(`Missing "d" tag for PRE event of kind ${i.kind}`);return At(i.kind,i.pubkey,e,t)}function Zt(i){if(!i.startsWith("naddr-like:"))throw new Error(`Invalid naddr-like prefix: ${i}`);const t=i.slice(11),[e,s]=t.split("?",2),n=Vt(e);if(!s)return{a:n};const r=new URLSearchParams(s).get("relays"),o=r?r.split(",").map(decodeURIComponent):void 0;return{a:n,relays:o}}function Jt(i){return Number.isInteger(i)&&i>=3e4&&i<4e4}function xt(i,t){const e=[];let s=!1;for(const n of i)!s&&n[0]==="d"?(e.push(["d",t]),s=!0):e.push(n);return s||e.push(["d",t]),e}function Qt(i,t,e){if(X(i))return i.slice();const s=Kt(i,t,e);return xt(i,s)}class jt{constructor(t={}){this.textEncoder=new TextEncoder,this.subscriptions=new Map,this.publishes=new Map,this.activePubkey=null,this._pendingSession=null,this.signCB=g=>{},this.eventTarget=new EventTarget,this.relayStatuses=new Map,this.PERPETUAL_SUBSCRIPTIONS=["notifications","starterpack"];const e=new MessageChannel,s=new MessageChannel,n=new MessageChannel,r=new MessageChannel,o=new MessageChannel,a=new MessageChannel,b=new MessageChannel,f=new MessageChannel,u=!!t.proxy,y=u?new URL("./connections/proxy.js",import.meta.url):new URL("./connections/index.js",import.meta.url),v=new URL("./cache/index.js",import.meta.url),G=new URL("./parser/index.js",import.meta.url),d=new URL("./crypto/index.js",import.meta.url);console.log("constructing crates"),this.connections=new Worker(y,{type:"module"}),this.cache=new Worker(v,{type:"module"}),this.parser=new Worker(G,{type:"module"}),this.crypto=new Worker(d,{type:"module"}),console.log("connectionMode",u?"proxy":"rust"),this.connections.postMessage({type:"init",payload:{mainPort:f.port2,cachePort:r.port1,parserPort:s.port1,cryptoPort:o.port1,...t.proxy?{proxy:t.proxy}:{}}},[f.port2,r.port1,s.port1,o.port1]),this.cache.postMessage({type:"init",payload:{parserPort:e.port1,connectionsPort:r.port2}},[e.port1,r.port2]),this.parserMainPort=b.port1,this.parserMainPort.onmessage=g=>{const{subId:h,data:C}=g.data;if(!h||!C){console.log("[main] ignoring message - missing subId or data");return}const L=this.subscriptions.get(h);if(L){W.writeBatchedData(L.buffer,C,h)&&this.dispatch(`subscription:${h}`,h);return}const at=this.publishes.get(h);if(at){W.writeBatchedData(at.buffer,C,h)&&this.dispatch(`publish:${h}`,h);return}console.log("[main] no subscription or publish found for subId:",h)},this.connectionsMainPort=f.port1,this.connectionsMainPort.onmessage=g=>{const{type:h,status:C,url:L}=JSON.parse(g.data);h==="relay:status"&&L&&C?(this.relayStatuses.set(L,{status:C,timestamp:Date.now()}),this.dispatch("relay:status",{status:C,url:L})):console.log("[main] ignoring message - type:",h,"url:",L,"status:",C)},this.parser.postMessage({type:"init",payload:{connectionsPort:s.port2,cachePort:e.port2,cryptoPort:n.port1,mainPort:b.port2}},[s.port2,e.port2,n.port1,b.port2]),this.crypto.postMessage({type:"init",payload:{parserPort:n.port2,connectionsPort:o.port2,mainPort:a.port1}},[n.port2,o.port2,a.port1]),a.port2.onmessage=g=>{const h=g.data;h.type==="response"&&this.handleCryptoResponse(h)},this.setupWorkerListener(),queueMicrotask(()=>this.restoreSession())}postToWorker(t,e){e&&e.length?this.parser.postMessage(t,e):this.parser.postMessage(t)}handleCryptoResponse(t){if(t.op==="get_pubkey"){console.log("[main] get_pubkey:",t.ok?"success":"failed",t.result),t.ok&&(this.activePubkey=t.result,this._discoveredBunkerUrl&&this._pendingSession?.type==="nip46_qr"&&this._pendingSession?.payload?.clientSecret?(console.log("[main] Converting QR to bunker for pubkey:",this.activePubkey),this.saveSession(this.activePubkey,"nip46_bunker",{url:this._discoveredBunkerUrl,clientSecret:this._pendingSession.payload.clientSecret}),this._pendingSession=null,this._discoveredBunkerUrl=null):this._pendingSession&&(this.saveSession(this.activePubkey,this._pendingSession.type,this._pendingSession.payload),this._pendingSession=null));const e=t.ok&&!!this._pendingSession;this.dispatch("auth",{pubkey:this.activePubkey,hasSigner:e})}else if(t.op==="sign_event"&&t.ok){const e=JSON.parse(t.result);this.signCB(e)}}setupWorkerListener(){this.parser.onmessage=async t=>{const e=typeof t.data=="string"?t.data:void 0;if(e){if(this.subscriptions.has(e)){this.dispatch(`subscription:${e}`,e);return}if(this.publishes.has(e)){this.dispatch(`publish:${e}`,e);return}}},this.crypto.onmessage=async t=>{const e=t.data;if(console.log("[main] crypto.onmessage:",e?.type,e),e?.type==="signer_ready"){console.log("[main] signer_ready:",e.signer_type,e.pubkey),this.activePubkey=e.pubkey,e.signer_type==="nip46"&&e.bunker_url&&this._pendingSession?.payload?.clientSecret?(console.log("[main] NIP-46 session saved for:",e.pubkey),this.saveSession(e.pubkey,"nip46",{url:e.bunker_url,clientSecret:this._pendingSession.payload.clientSecret}),this._pendingSession=null):this._pendingSession&&(this.saveSession(e.pubkey,e.signer_type,this._pendingSession.payload),this._pendingSession=null),this.dispatch("auth",{pubkey:e.pubkey,hasSigner:!0});return}if(e?.type==="response"){this.handleCryptoResponse(e);return}if(e?.type==="extension_request"){const{id:s,op:n,payload:r}=e;try{const o=window.nostr;if(!o)throw new Error("NIP-07 extension (window.nostr) not found");let a;switch(n){case"getPublicKey":a=await o.getPublicKey();break;case"signEvent":a=await o.signEvent(JSON.parse(r));break;case"nip04Encrypt":a=await o.nip04.encrypt(r.pubkey,r.plaintext);break;case"nip04Decrypt":a=await o.nip04.decrypt(r.pubkey,r.ciphertext);break;case"nip44Encrypt":a=await o.nip44.encrypt(r.pubkey,r.plaintext);break;case"nip44Decrypt":a=await o.nip44.decrypt(r.pubkey,r.ciphertext);break;default:throw new Error(`Unknown extension operation: ${n}`)}this.crypto.postMessage({type:"extension_response",id:s,ok:!0,result:a})}catch(o){this.crypto.postMessage({type:"extension_response",id:s,ok:!1,error:o.message||String(o)})}return}}}createShortId(t){if(t.length<64)return t;let e=0;for(let s=0;s<t.length;s++){const n=t.charCodeAt(s);e=(e<<5)-e+n,e=e&e}return Math.abs(e).toString(36).substring(0,63)}addEventListener(t,e,s){this.eventTarget.addEventListener(t,e,s)}removeEventListener(t,e,s){this.eventTarget.removeEventListener(t,e,s)}dispatch(t,e){this.eventTarget.dispatchEvent(new CustomEvent(t,{detail:e}))}subscribe(t,e,s){const n=this.createShortId(t),r=this.subscriptions.get(n);if(r)return r.refCount++,r.buffer;const o=e.reduce((d,g)=>d+(g.limit||100),0),a=W.calculateBufferSize(o,s.bytesPerEvent),b=new ArrayBuffer(a);W.initializeBuffer(b),this.subscriptions.set(n,{buffer:b,options:s,refCount:1});const f=new et(new tt(s.pipeline||[]),s.closeOnEose,s.cacheFirst,s.timeoutMs?BigInt(s.timeoutMs):void 0,s.maxEvents,s.skipCache,s.force,s.bytesPerEvent,s.isSlow,s.pagination?this.textEncoder.encode(s.pagination):null),u=new st(this.textEncoder.encode(n),e.map(d=>new $t(d.ids,d.authors,d.kinds,Object.entries(d.tags||{}).flatMap(([g,h])=>new ht([g,...h])),d.limit,d.since,d.until,this.textEncoder.encode(d.search),d.relays,d.closeOnEOSE,d.cacheFirst,d.noCache)),f),y=new D(E.Subscribe,u),v=new c.Builder(2048);v.finish(y.pack(v));const G=v.asUint8Array();return this.postToWorker({serializedMessage:G},[G.buffer]),b}getBuffer(t){const e=this.subscriptions.get(t);if(e)return e.refCount++,e.buffer}getRelayStatuses(){return new Map(this.relayStatuses)}unsubscribe(t){const e=t.length<64?t:this.createShortId(t),s=this.subscriptions.get(e);s&&s.refCount--}publish(t,e,s=[]){const n=new ArrayBuffer(3072);W.initializeBuffer(n);const r=new Q(e.kind,e.created_at,this.textEncoder.encode(e.content),e.tags.map(u=>new ht(u))||[]),o=new Y(this.textEncoder.encode(t),r,s),a=new D(E.Publish,o),b=new c.Builder(2048);b.finish(a.pack(b));const f=b.asUint8Array();return this.postToWorker({serializedMessage:f},[f.buffer]),this.publishes.set(t,{buffer:n}),n}setSigner(t,e){switch(this._pendingSession={type:t,payload:e},console.log("[main] set pending session:",t),t){case"pubkey":this.activePubkey=e,this.saveSession(this.activePubkey,"pubkey",e),this._pendingSession=null,this.dispatch("auth",{pubkey:this.activePubkey,hasSigner:!1});break;case"privkey":this.crypto.postMessage({type:"set_private_key",payload:e});break;case"nip07":this.crypto.postMessage({type:"set_nip07"});break;case"nip46":e?.url?.startsWith("bunker://")?this.crypto.postMessage({type:"set_nip46_bunker",payload:e}):e?.url?.startsWith("nostrconnect://")?this.crypto.postMessage({type:"set_nip46_qr",payload:e}):console.error("[main] Unknown NIP-46 URL format:",e?.url);break}}signEvent(t,e){this.signCB=e,this.crypto.postMessage({type:"sign_event",payload:JSON.stringify(t)})}getPublicKey(){const t=new D(E.GetPublicKey,new J),e=new c.Builder(2048);e.finish(t.pack(e));const s=e.asUint8Array();this.parser.postMessage({serializedMessage:s},[s.buffer])}generateClientSecret(){const t=new Uint8Array(32);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}setNip46Bunker(t,e){const s=e||this.generateClientSecret();console.log("[main] NIP-46 bunker:",t.slice(0,50)+"..."),this.setSigner("nip46",{url:t,clientSecret:s})}setNip46QR(t,e){const s=e||this.generateClientSecret();console.log("[main] NIP-46 QR:",t.slice(0,50)+"..."),this.setSigner("nip46",{url:t,clientSecret:s})}setNip07(){this.setSigner("nip07","")}setPubkey(t){this.setSigner("pubkey",t)}getActivePubkey(){return this.activePubkey}getSubscriptionCount(){return this.subscriptions.size}getAccounts(){const t=localStorage.getItem("nostr_signer_accounts")||"{}";try{return JSON.parse(t)}catch{return{}}}switchAccount(t){const e=this.getAccounts()[t];e&&this.setSigner(e.type,e.payload)}saveSession(t,e,s){console.log("[main] saveSession:",{pubkey:t.slice(0,16)+"...",type:e,hasClientSecret:!!s?.clientSecret});const n=this.getAccounts();n[t]={type:e,payload:s},localStorage.setItem("nostr_signer_accounts",JSON.stringify(n)),localStorage.setItem("nostr_active_pubkey",t),console.log("[main] Session saved to localStorage")}restoreSession(){const t=localStorage.getItem("nostr_active_pubkey");t?this.switchAccount(t):this.dispatch("auth",{pubkey:null,hasSigner:!1})}logout(){this._pendingSession=null,this.activePubkey=null,this.crypto.postMessage({type:"clear_signer"}),localStorage.removeItem("nostr_active_pubkey"),this.dispatch("logout")}removeAccount(){const t=this.activePubkey;if(!t)return;const e=this.getAccounts();delete e[t],localStorage.setItem("nostr_signer_accounts",JSON.stringify(e));const s=Object.keys(e);if(s.length>0){const n=s[0];n&&this.switchAccount(n)}else this.logout()}cleanup(){const t=[];for(const[e,s]of this.subscriptions.entries())s.refCount<=0&&!this.PERPETUAL_SUBSCRIPTIONS.includes(e)&&t.push(e);for(const e of t){const s=new it(this.textEncoder.encode(e)),n=new D(E.Unsubscribe,s),r=new c.Builder(256);r.finish(n.pack(r));const o=r.asUint8Array();this.postToWorker({serializedMessage:o},[o.buffer]),this.connections.postMessage(e),this.subscriptions.delete(e)}}}function Yt(i){return new jt(i)}let ot=null;function te(){if(!ot)throw new Error("[nipworker] Global manager is not set. Call setManager(createNostrManager(...)) before using hooks.");return ot}function Ut(i){ot=i}function ee(i){Ut(i)}export{A as $,W as A,ft as B,B as C,I as D,gt as E,J as F,U as G,_t as H,M as I,D as J,F as K,l as L,E as M,jt as N,St as O,S as P,It as Q,q as R,vt as S,Rt as T,T as U,Tt as V,H as W,R as X,tt as Y,K as Z,Pt as _,ee as a,Ct as a0,k as a1,Y as a2,z as a3,Et as a4,x as a5,mt as a6,O as a7,kt as a8,V as a9,wt as aa,$ as ab,w as ac,st as ad,Lt as ae,p as af,et as ag,P as ah,Q as ai,j as aj,it as ak,Ht as b,Yt as c,Kt as d,X as e,rt as f,te as g,Vt as h,Z as i,Wt as j,At as k,Xt as l,Nt as m,Mt as n,Zt as o,Dt as p,Jt as q,nt as r,Ut as s,Qt as t,xt as u,N as v,lt as w,_ as x,pt as y,m as z};