@candypoets/nipworker 0.0.53 → 0.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAc,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAGnE,wBAAgB,eAAe,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,aAAa,EAAE,EACzB,QAAQ,GAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAe,EACrD,OAAO,GAAE,kBAA2C,GAClD,MAAM,IAAI,CA8CZ;AAED,wBAAgB,UAAU,CACzB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,aAAa,EACpB,QAAQ,GAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAe,EACrD,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAA0B,GACxD,MAAM,IAAI,CA2CZ;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,QAIrF"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAc,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAiCnE,wBAAgB,eAAe,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,aAAa,EAAE,EACzB,QAAQ,GAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAe,EACrD,OAAO,GAAE,kBAA2C,GAClD,MAAM,IAAI,CAuLZ;AAED,wBAAgB,UAAU,CACzB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,aAAa,EACpB,QAAQ,GAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAe,EACrD,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAA0B,GACxD,MAAM,IAAI,CAwCZ;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,QAIrF"}
package/dist/hooks.js CHANGED
@@ -1 +1 @@
1
- import{n as c,Z as f}from"./index2.js";function p(s,a,b=()=>{},g={closeOnEose:!1}){if(!s)return console.warn("useSharedSubscription: No subscription ID provided"),()=>{};let t=null,r=4,i=!0,n=!1,d=!1;s=c.createShortId(s);const e=c.getManager(s),u=()=>{i=!1,d&&!n&&(e.removeEventListener(`subscription:${s}`,o),e.unsubscribe(s),n=!0)};e.ready.then(()=>{t=e.subscribe(s,a,g),d=!0});const o=()=>{if(!i||!t)return;let l=f.readMessages(t,r);for(;l.hasNewData;){for(const h of l.messages)b(h);r=l.newReadPosition,l=f.readMessages(t,r)}};return e.addEventListener(`subscription:${s}`,o),queueMicrotask(o),u}function v(s,a,b=()=>{},g={trackStatus:!0}){if(!s)return console.warn("usePublish: No publish ID provided"),()=>{};let t=null,r=4,i=!0;s=c.createShortId(s);const n=c.getManager(s),d=()=>{i=!1,n.removeEventListener(`publish:${s}`,e)};n.ready.then(()=>{t=n.publish(s,a)});const e=()=>{if(!i||!t)return;const u=f.readMessages(t,r);u.hasNewData&&(u.messages.forEach(o=>{console.log(o),b(o)}),r=u.newReadPosition)};return g.trackStatus&&(n.addEventListener(`publish:${s}`,e),queueMicrotask(e)),d}function E(s,a){c.getManager("").signEvent(s,a)}export{v as usePublish,E as useSignEvent,p as useSubscription};
1
+ import{n as c,S}from"./index2.js";const B=Date.now();let L=0,M=0,y=!1;function A(e=2e3){return Date.now()-B<e}function R(){y||(y=!0,(typeof requestAnimationFrame=="function"?requestAnimationFrame:e=>setTimeout(()=>e(performance?.now?.()??Date.now()),16))(()=>{L=A()?200:1500,M=L,y=!1}))}function x(e,f,q=()=>{},E={closeOnEose:!1}){if(!e)return console.warn("useSharedSubscription: No subscription ID provided"),()=>{};let o=null,i=4,r=!0,a=!1,g=!1;const s=5e3,m=4,I=8;let p=!1,t=[],k=!1,w=null,d=null,b=null;const T=typeof requestAnimationFrame=="function"?requestAnimationFrame:n=>setTimeout(()=>n(performance?.now?.()??Date.now()),16),C=typeof cancelAnimationFrame=="function"?cancelAnimationFrame:n=>clearTimeout(n),N=n=>{if(t.length>=s){const u=t.length-s+1;u>0&&t.splice(0,u)}t.push(n)},F=()=>{if(!r||t.length===0)return;if(R(),M<=0){h();return}const n=Math.min(M,t.length);if(n<=0)return;const u=t.splice(0,n);M-=n;for(const l of u){if(!r)break;q(l)}t.length>0&&h()},h=()=>{if(!(k||!r)){if(k=!0,A()&&typeof window<"u"&&typeof window.requestIdleCallback=="function"){d=window.requestIdleCallback(()=>{d=null,k=!1,F()},{timeout:100});return}w=T(()=>{k=!1,w=null,F()})}};e=c.createShortId(e);const v=c.getManager(e),P=()=>(r=!1,w!=null&&(C(w),w=null),d!=null&&typeof window?.cancelIdleCallback=="function"&&(window.cancelIdleCallback(d),d=null),b&&(clearTimeout(b),b=null),g&&!a&&(v.removeEventListener(`subscription:${e}`,D),v.unsubscribe(e),a=!0),t=[],()=>{});c.resetInputLoopBackoff(),o=v.subscribe(e,f,E),g=!0;const D=()=>{if(!r||!o||p)return;p=!0;const n=performance?.now?.()??Date.now(),u=A()?m:I;let l=S.readMessages(o,i);for(;l.hasNewData;){for(const $ of l.messages)N($);if(i=l.newReadPosition,(performance?.now?.()??Date.now())-n>=u){p=!1,h(),b=setTimeout(()=>{b=null,D()},0);return}if(t.length>=s){p=!1,h();return}l=S.readMessages(o,i)}p=!1,h()};return v.addEventListener(`subscription:${e}`,D),queueMicrotask(D),P}function G(e,f,q=()=>{},E={trackStatus:!0}){if(!e)return console.warn("usePublish: No publish ID provided"),()=>{};let o=null,i=4,r=!0;e=c.createShortId(e);const a=c.getManager(e),g=()=>{r=!1,a.removeEventListener(`publish:${e}`,s)};o=a.publish(e,f);const s=()=>{if(!r||!o)return;const m=S.readMessages(o,i);m.hasNewData&&(m.messages.forEach(I=>{q(I)}),i=m.newReadPosition)};return E.trackStatus&&(a.addEventListener(`publish:${e}`,s),queueMicrotask(s)),g}function H(e,f){c.getManager("").signEvent(e,f)}export{G as usePublish,H as useSignEvent,x as useSubscription};
package/dist/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sources":["../src/hooks.ts"],"sourcesContent":["import { Event, EventTemplate, NostrEvent } from 'nostr-tools';\nimport { SharedBufferReader } from 'src/lib/SharedBuffer';\nimport { WorkerMessage } from './generated/nostr/fb';\nimport { RequestObject, type SubscriptionConfig } from './manager';\nimport { nipWorker } from './ws';\n\nexport function useSubscription(\n\tsubId: string,\n\trequests: RequestObject[],\n\tcallback: (message: WorkerMessage) => void = () => {},\n\toptions: SubscriptionConfig = { closeOnEose: false }\n): () => void {\n\tif (!subId) {\n\t\tconsole.warn('useSharedSubscription: No subscription ID provided');\n\t\treturn () => {};\n\t}\n\tlet buffer: SharedArrayBuffer | null = null;\n\tlet lastReadPos: number = 4;\n\tlet running: boolean = true;\n\tlet hasUnsubscribed = false;\n\tlet hasSubscribed = false;\n\n\tsubId = nipWorker.createShortId(subId);\n\n\tconst manager = nipWorker.getManager(subId);\n\n\tconst unsubscribe = (): void => {\n\t\trunning = false;\n\t\tif (hasSubscribed && !hasUnsubscribed) {\n\t\t\tmanager.removeEventListener(`subscription:${subId}`, processEvents);\n\t\t\tmanager.unsubscribe(subId);\n\t\t\thasUnsubscribed = true;\n\t\t}\n\t};\n\n\tmanager.ready.then(() => {\n\t\tbuffer = manager.subscribe(subId, requests, options);\n\t\thasSubscribed = true;\n\t});\n\n\tconst processEvents = (): void => {\n\t\tif (!running || !buffer) return;\n\t\tlet result = SharedBufferReader.readMessages(buffer, lastReadPos);\n\t\twhile (result.hasNewData) {\n\t\t\tfor (const message of result.messages) {\n\t\t\t\tcallback(message);\n\t\t\t}\n\t\t\tlastReadPos = result.newReadPosition;\n\t\t\tresult = SharedBufferReader.readMessages(buffer, lastReadPos);\n\t\t}\n\t};\n\n\tmanager.addEventListener(`subscription:${subId}`, processEvents);\n\n\tqueueMicrotask(processEvents);\n\n\treturn unsubscribe;\n}\n\nexport function usePublish(\n\tpubId: string,\n\tevent: EventTemplate,\n\tcallback: (message: WorkerMessage) => void = () => {},\n\toptions: { trackStatus?: boolean } = { trackStatus: true }\n): () => void {\n\tif (!pubId) {\n\t\tconsole.warn('usePublish: No publish ID provided');\n\t\treturn () => {};\n\t}\n\n\tlet buffer: SharedArrayBuffer | null = null;\n\tlet lastReadPos: number = 4;\n\tlet running = true;\n\n\tpubId = nipWorker.createShortId(pubId);\n\n\tconst manager = nipWorker.getManager(pubId);\n\n\tconst unsubscribe = (): void => {\n\t\trunning = false;\n\t\tmanager.removeEventListener(`publish:${pubId}`, processEvents);\n\t};\n\n\tmanager.ready.then(() => {\n\t\tbuffer = manager.publish(pubId, event);\n\t});\n\n\tconst processEvents = (): void => {\n\t\tif (!running || !buffer) {\n\t\t\treturn;\n\t\t}\n\t\tconst result = SharedBufferReader.readMessages(buffer, lastReadPos);\n\t\tif (result.hasNewData) {\n\t\t\tresult.messages.forEach((message: WorkerMessage) => {\n\t\t\t\tconsole.log(message);\n\t\t\t\tcallback(message);\n\t\t\t});\n\t\t\tlastReadPos = result.newReadPosition;\n\t\t}\n\t};\n\n\tif (options.trackStatus) {\n\t\tmanager.addEventListener(`publish:${pubId}`, processEvents);\n\t\tqueueMicrotask(processEvents);\n\t}\n\n\treturn unsubscribe;\n}\n\nexport function useSignEvent(template: EventTemplate, callback: (event: Event) => void) {\n\tconst manager = nipWorker.getManager('');\n\n\tmanager.signEvent(template, callback);\n}\n"],"names":["useSubscription","subId","requests","callback","options","buffer","lastReadPos","running","hasUnsubscribed","hasSubscribed","nipWorker","manager","unsubscribe","processEvents","result","SharedBufferReader","message","usePublish","pubId","event","useSignEvent","template"],"mappings":";AAMO,SAASA,EACfC,GACAC,GACAC,IAA6C,MAAM;AAAC,GACpDC,IAA8B,EAAE,aAAa,MAChC;AACb,MAAI,CAACH;AACJ,mBAAQ,KAAK,oDAAoD,GAC1D,MAAM;AAAA,IAAC;AAEf,MAAII,IAAmC,MACnCC,IAAsB,GACtBC,IAAmB,IACnBC,IAAkB,IAClBC,IAAgB;AAEpB,EAAAR,IAAQS,EAAU,cAAcT,CAAK;AAErC,QAAMU,IAAUD,EAAU,WAAWT,CAAK,GAEpCW,IAAc,MAAY;AAC/B,IAAAL,IAAU,IACNE,KAAiB,CAACD,MACrBG,EAAQ,oBAAoB,gBAAgBV,CAAK,IAAIY,CAAa,GAClEF,EAAQ,YAAYV,CAAK,GACzBO,IAAkB;AAAA,EAEpB;AAEA,EAAAG,EAAQ,MAAM,KAAK,MAAM;AACxB,IAAAN,IAASM,EAAQ,UAAUV,GAAOC,GAAUE,CAAO,GACnDK,IAAgB;AAAA,EACjB,CAAC;AAED,QAAMI,IAAgB,MAAY;AACjC,QAAI,CAACN,KAAW,CAACF,EAAQ;AACzB,QAAIS,IAASC,EAAmB,aAAaV,GAAQC,CAAW;AAChE,WAAOQ,EAAO,cAAY;AACzB,iBAAWE,KAAWF,EAAO;AAC5B,QAAAX,EAASa,CAAO;AAEjB,MAAAV,IAAcQ,EAAO,iBACrBA,IAASC,EAAmB,aAAaV,GAAQC,CAAW;AAAA,IAC7D;AAAA,EACD;AAEA,SAAAK,EAAQ,iBAAiB,gBAAgBV,CAAK,IAAIY,CAAa,GAE/D,eAAeA,CAAa,GAErBD;AACR;AAEO,SAASK,EACfC,GACAC,GACAhB,IAA6C,MAAM;AAAC,GACpDC,IAAqC,EAAE,aAAa,MACvC;AACb,MAAI,CAACc;AACJ,mBAAQ,KAAK,oCAAoC,GAC1C,MAAM;AAAA,IAAC;AAGf,MAAIb,IAAmC,MACnCC,IAAsB,GACtBC,IAAU;AAEd,EAAAW,IAAQR,EAAU,cAAcQ,CAAK;AAErC,QAAMP,IAAUD,EAAU,WAAWQ,CAAK,GAEpCN,IAAc,MAAY;AAC/B,IAAAL,IAAU,IACVI,EAAQ,oBAAoB,WAAWO,CAAK,IAAIL,CAAa;AAAA,EAC9D;AAEA,EAAAF,EAAQ,MAAM,KAAK,MAAM;AACxB,IAAAN,IAASM,EAAQ,QAAQO,GAAOC,CAAK;AAAA,EACtC,CAAC;AAED,QAAMN,IAAgB,MAAY;AACjC,QAAI,CAACN,KAAW,CAACF;AAChB;AAED,UAAMS,IAASC,EAAmB,aAAaV,GAAQC,CAAW;AAClE,IAAIQ,EAAO,eACVA,EAAO,SAAS,QAAQ,CAACE,MAA2B;AACnD,cAAQ,IAAIA,CAAO,GACnBb,EAASa,CAAO;AAAA,IACjB,CAAC,GACDV,IAAcQ,EAAO;AAAA,EAEvB;AAEA,SAAIV,EAAQ,gBACXO,EAAQ,iBAAiB,WAAWO,CAAK,IAAIL,CAAa,GAC1D,eAAeA,CAAa,IAGtBD;AACR;AAEO,SAASQ,EAAaC,GAAyBlB,GAAkC;AAGvF,EAFgBO,EAAU,WAAW,EAAE,EAE/B,UAAUW,GAAUlB,CAAQ;AACrC;"}
1
+ {"version":3,"file":"hooks.js","sources":["../src/hooks.ts"],"sourcesContent":["import { Event, EventTemplate, NostrEvent } from 'nostr-tools';\nimport { SharedBufferReader } from 'src/lib/SharedBuffer';\nimport { WorkerMessage } from './generated/nostr/fb';\nimport { RequestObject, type SubscriptionConfig } from './manager';\nimport { nipWorker } from '.';\n\n// Global cold-start timestamp and per-frame token bucket shared by all subscriptions in this module.\nconst APP_START_TS = Date.now();\n\n// Global tokens replenished once per frame. All useSubscription instances share this.\nlet TOKENS_PER_FRAME = 0;\nlet tokensRemaining = 0;\nlet tokenRefillScheduled = false;\n\nfunction inColdStart(coldMs = 2000) {\n\treturn Date.now() - APP_START_TS < coldMs;\n}\n\nfunction scheduleTokenRefill() {\n\tif (tokenRefillScheduled) return;\n\ttokenRefillScheduled = true;\n\tconst raf =\n\t\ttypeof requestAnimationFrame === 'function'\n\t\t\t? requestAnimationFrame\n\t\t\t: (fn: FrameRequestCallback) =>\n\t\t\t\t\tsetTimeout(() => fn(performance?.now?.() ?? Date.now()), 16) as unknown as number;\n\n\traf(() => {\n\t\t// Refill once per frame with cold/hot limits\n\t\tTOKENS_PER_FRAME = inColdStart() ? 200 : 1500; // tune these\n\t\ttokensRemaining = TOKENS_PER_FRAME;\n\t\ttokenRefillScheduled = false;\n\t\t// We don't call any flushers here; each subscription already schedules its own flush.\n\t});\n}\n\nexport function useSubscription(\n\tsubId: string,\n\trequests: RequestObject[],\n\tcallback: (message: WorkerMessage) => void = () => {},\n\toptions: SubscriptionConfig = { closeOnEose: false }\n): () => void {\n\tif (!subId) {\n\t\tconsole.warn('useSharedSubscription: No subscription ID provided');\n\t\treturn () => {};\n\t}\n\n\tlet buffer: SharedArrayBuffer | null = null;\n\tlet lastReadPos: number = 4;\n\tlet running = true;\n\tlet hasUnsubscribed = false;\n\tlet hasSubscribed = false;\n\n\t// Per-instance queues and scheduling\n\tconst MAX_PENDING_BUFFER = 5000; // cap per-subscription memory\n\tconst READ_BUDGET_MS_COLD = 4;\n\tconst READ_BUDGET_MS_HOT = 8;\n\n\tlet processing = false;\n\tlet pending: WorkerMessage[] = [];\n\tlet flushScheduled = false;\n\tlet rafHandle: number | null = null;\n\tlet idleHandle: number | null = null;\n\tlet sliceTimeout: ReturnType<typeof setTimeout> | null = null;\n\n\t// Polyfills\n\tconst raf =\n\t\ttypeof requestAnimationFrame === 'function'\n\t\t\t? requestAnimationFrame\n\t\t\t: (fn: FrameRequestCallback) =>\n\t\t\t\t\tsetTimeout(() => fn(performance?.now?.() ?? Date.now()), 16) as unknown as number;\n\n\tconst caf =\n\t\ttypeof cancelAnimationFrame === 'function'\n\t\t\t? cancelAnimationFrame\n\t\t\t: (id: number) => clearTimeout(id as unknown as number);\n\n\t// Minimal typings for requestIdleCallback\n\tdeclare const window: any;\n\n\tconst pushPending = (msg: WorkerMessage) => {\n\t\tif (pending.length >= MAX_PENDING_BUFFER) {\n\t\t\t// Drop oldest to keep memory bounded during surges\n\t\t\tconst drop = pending.length - MAX_PENDING_BUFFER + 1;\n\t\t\tif (drop > 0) pending.splice(0, drop);\n\t\t}\n\t\tpending.push(msg);\n\t};\n\n\tconst flushSomeWithGlobalTokens = () => {\n\t\tif (!running || pending.length === 0) return;\n\n\t\t// Ensure tokens will be refilled this or next frame\n\t\tscheduleTokenRefill();\n\n\t\t// Nothing to do if global tokens are out; try again next frame\n\t\tif (tokensRemaining <= 0) {\n\t\t\tscheduleFlush(); // reschedule for next frame when tokens are refilled\n\t\t\treturn;\n\t\t}\n\n\t\t// Deliver up to the available global tokens\n\t\tconst deliverCount = Math.min(tokensRemaining, pending.length);\n\t\tif (deliverCount <= 0) return;\n\n\t\tconst chunk = pending.splice(0, deliverCount);\n\t\ttokensRemaining -= deliverCount;\n\n\t\tfor (const msg of chunk) {\n\t\t\tif (!running) break;\n\t\t\tcallback(msg);\n\t\t}\n\n\t\t// If we still have backlog, schedule another flush (may run next frame if tokens are depleted)\n\t\tif (pending.length > 0) scheduleFlush();\n\t};\n\n\tconst scheduleFlush = () => {\n\t\tif (flushScheduled || !running) return;\n\t\tflushScheduled = true;\n\n\t\t// During cold start, prefer idle time if available to avoid competing with first paint/hydration\n\t\tif (\n\t\t\tinColdStart() &&\n\t\t\ttypeof window !== 'undefined' &&\n\t\t\ttypeof window.requestIdleCallback === 'function'\n\t\t) {\n\t\t\tidleHandle = window.requestIdleCallback!(\n\t\t\t\t() => {\n\t\t\t\t\tidleHandle = null;\n\t\t\t\t\tflushScheduled = false;\n\t\t\t\t\tflushSomeWithGlobalTokens();\n\t\t\t\t},\n\t\t\t\t{ timeout: 100 }\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\trafHandle = raf(() => {\n\t\t\tflushScheduled = false;\n\t\t\trafHandle = null;\n\t\t\tflushSomeWithGlobalTokens();\n\t\t});\n\t};\n\n\tsubId = nipWorker.createShortId(subId);\n\tconst manager = nipWorker.getManager(subId);\n\n\tconst unsubscribe = (): (() => void) => {\n\t\trunning = false;\n\n\t\tif (rafHandle != null) {\n\t\t\tcaf(rafHandle);\n\t\t\trafHandle = null;\n\t\t}\n\t\tif (idleHandle != null && typeof window?.cancelIdleCallback === 'function') {\n\t\t\twindow.cancelIdleCallback(idleHandle);\n\t\t\tidleHandle = null;\n\t\t}\n\t\tif (sliceTimeout) {\n\t\t\tclearTimeout(sliceTimeout);\n\t\t\tsliceTimeout = null;\n\t\t}\n\n\t\tif (hasSubscribed && !hasUnsubscribed) {\n\t\t\tmanager.removeEventListener(`subscription:${subId}`, processEvents);\n\t\t\tmanager.unsubscribe(subId);\n\t\t\thasUnsubscribed = true;\n\t\t}\n\n\t\tpending = [];\n\t\treturn () => {};\n\t};\n\n\tnipWorker.resetInputLoopBackoff();\n\tbuffer = manager.subscribe(subId, requests, options);\n\thasSubscribed = true;\n\n\tconst processEvents = (): void => {\n\t\tif (!running || !buffer) return;\n\t\tif (processing) return;\n\n\t\tprocessing = true;\n\n\t\tconst start = performance?.now?.() ?? Date.now();\n\t\tconst budget = inColdStart() ? READ_BUDGET_MS_COLD : READ_BUDGET_MS_HOT;\n\n\t\tlet result = SharedBufferReader.readMessages(buffer, lastReadPos);\n\t\twhile (result.hasNewData) {\n\t\t\tfor (const message of result.messages) pushPending(message);\n\t\t\tlastReadPos = result.newReadPosition;\n\n\t\t\tconst now = performance?.now?.() ?? Date.now();\n\t\t\tif (now - start >= budget) {\n\t\t\t\tprocessing = false;\n\t\t\t\tscheduleFlush();\n\t\t\t\t// Yield to keep the main thread responsive\n\t\t\t\tsliceTimeout = setTimeout(() => {\n\t\t\t\t\tsliceTimeout = null;\n\t\t\t\t\tprocessEvents();\n\t\t\t\t}, 0);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If we’re already backed up, stop reading for now and let the UI catch up\n\t\t\tif (pending.length >= MAX_PENDING_BUFFER) {\n\t\t\t\tprocessing = false;\n\t\t\t\tscheduleFlush();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tresult = SharedBufferReader.readMessages(buffer, lastReadPos);\n\t\t}\n\n\t\tprocessing = false;\n\t\tscheduleFlush();\n\t};\n\n\tmanager.addEventListener(`subscription:${subId}`, processEvents);\n\n\t// Kick off initial read without blocking the current stack\n\tqueueMicrotask(processEvents);\n\n\treturn unsubscribe;\n}\n\nexport function usePublish(\n\tpubId: string,\n\tevent: EventTemplate,\n\tcallback: (message: WorkerMessage) => void = () => {},\n\toptions: { trackStatus?: boolean } = { trackStatus: true }\n): () => void {\n\tif (!pubId) {\n\t\tconsole.warn('usePublish: No publish ID provided');\n\t\treturn () => {};\n\t}\n\n\tlet buffer: SharedArrayBuffer | null = null;\n\tlet lastReadPos: number = 4;\n\tlet running = true;\n\n\tpubId = nipWorker.createShortId(pubId);\n\n\tconst manager = nipWorker.getManager(pubId);\n\n\tconst unsubscribe = (): void => {\n\t\trunning = false;\n\t\tmanager.removeEventListener(`publish:${pubId}`, processEvents);\n\t};\n\n\tbuffer = manager.publish(pubId, event);\n\n\tconst processEvents = (): void => {\n\t\tif (!running || !buffer) {\n\t\t\treturn;\n\t\t}\n\t\tconst result = SharedBufferReader.readMessages(buffer, lastReadPos);\n\t\tif (result.hasNewData) {\n\t\t\tresult.messages.forEach((message: WorkerMessage) => {\n\t\t\t\tcallback(message);\n\t\t\t});\n\t\t\tlastReadPos = result.newReadPosition;\n\t\t}\n\t};\n\n\tif (options.trackStatus) {\n\t\tmanager.addEventListener(`publish:${pubId}`, processEvents);\n\t\tqueueMicrotask(processEvents);\n\t}\n\n\treturn unsubscribe;\n}\n\nexport function useSignEvent(template: EventTemplate, callback: (event: Event) => void) {\n\tconst manager = nipWorker.getManager('');\n\n\tmanager.signEvent(template, callback);\n}\n"],"names":["APP_START_TS","TOKENS_PER_FRAME","tokensRemaining","tokenRefillScheduled","inColdStart","coldMs","scheduleTokenRefill","fn","useSubscription","subId","requests","callback","options","buffer","lastReadPos","running","hasUnsubscribed","hasSubscribed","MAX_PENDING_BUFFER","READ_BUDGET_MS_COLD","READ_BUDGET_MS_HOT","processing","pending","flushScheduled","rafHandle","idleHandle","sliceTimeout","raf","caf","id","pushPending","msg","drop","flushSomeWithGlobalTokens","scheduleFlush","deliverCount","chunk","nipWorker","manager","unsubscribe","processEvents","start","budget","result","SharedBufferReader","message","usePublish","pubId","event","useSignEvent","template"],"mappings":";AAOA,MAAMA,IAAe,KAAK,IAAA;AAG1B,IAAIC,IAAmB,GACnBC,IAAkB,GAClBC,IAAuB;AAE3B,SAASC,EAAYC,IAAS,KAAM;AACnC,SAAO,KAAK,QAAQL,IAAeK;AACpC;AAEA,SAASC,IAAsB;AAC9B,MAAIH,EAAsB;AAC1B,EAAAA,IAAuB,KAEtB,OAAO,yBAA0B,aAC9B,wBACA,CAACI,MACD,WAAW,MAAMA,EAAG,aAAa,MAAA,KAAW,KAAK,IAAA,CAAK,GAAG,EAAE,GAE3D,MAAM;AAET,IAAAN,IAAmBG,MAAgB,MAAM,MACzCF,IAAkBD,GAClBE,IAAuB;AAAA,EAExB,CAAC;AACF;AAEO,SAASK,EACfC,GACAC,GACAC,IAA6C,MAAM;AAAC,GACpDC,IAA8B,EAAE,aAAa,MAChC;AACb,MAAI,CAACH;AACJ,mBAAQ,KAAK,oDAAoD,GAC1D,MAAM;AAAA,IAAC;AAGf,MAAII,IAAmC,MACnCC,IAAsB,GACtBC,IAAU,IACVC,IAAkB,IAClBC,IAAgB;AAGpB,QAAMC,IAAqB,KACrBC,IAAsB,GACtBC,IAAqB;AAE3B,MAAIC,IAAa,IACbC,IAA2B,CAAA,GAC3BC,IAAiB,IACjBC,IAA2B,MAC3BC,IAA4B,MAC5BC,IAAqD;AAGzD,QAAMC,IACL,OAAO,yBAA0B,aAC9B,wBACA,CAACpB,MACD,WAAW,MAAMA,EAAG,aAAa,MAAA,KAAW,KAAK,IAAA,CAAK,GAAG,EAAE,GAEzDqB,IACL,OAAO,wBAAyB,aAC7B,uBACA,CAACC,MAAe,aAAaA,CAAuB,GAKlDC,IAAc,CAACC,MAAuB;AAC3C,QAAIT,EAAQ,UAAUJ,GAAoB;AAEzC,YAAMc,IAAOV,EAAQ,SAASJ,IAAqB;AACnD,MAAIc,IAAO,KAAGV,EAAQ,OAAO,GAAGU,CAAI;AAAA,IACrC;AACA,IAAAV,EAAQ,KAAKS,CAAG;AAAA,EACjB,GAEME,IAA4B,MAAM;AACvC,QAAI,CAAClB,KAAWO,EAAQ,WAAW,EAAG;AAMtC,QAHAhB,EAAA,GAGIJ,KAAmB,GAAG;AACzB,MAAAgC,EAAA;AACA;AAAA,IACD;AAGA,UAAMC,IAAe,KAAK,IAAIjC,GAAiBoB,EAAQ,MAAM;AAC7D,QAAIa,KAAgB,EAAG;AAEvB,UAAMC,IAAQd,EAAQ,OAAO,GAAGa,CAAY;AAC5C,IAAAjC,KAAmBiC;AAEnB,eAAWJ,KAAOK,GAAO;AACxB,UAAI,CAACrB,EAAS;AACd,MAAAJ,EAASoB,CAAG;AAAA,IACb;AAGA,IAAIT,EAAQ,SAAS,KAAGY,EAAA;AAAA,EACzB,GAEMA,IAAgB,MAAM;AAC3B,QAAI,EAAAX,KAAkB,CAACR,IAIvB;AAAA,UAHAQ,IAAiB,IAIhBnB,EAAA,KACA,OAAO,SAAW,OAClB,OAAO,OAAO,uBAAwB,YACrC;AACD,QAAAqB,IAAa,OAAO;AAAA,UACnB,MAAM;AACL,YAAAA,IAAa,MACbF,IAAiB,IACjBU,EAAA;AAAA,UACD;AAAA,UACA,EAAE,SAAS,IAAA;AAAA,QAAI;AAEhB;AAAA,MACD;AAEA,MAAAT,IAAYG,EAAI,MAAM;AACrB,QAAAJ,IAAiB,IACjBC,IAAY,MACZS,EAAA;AAAA,MACD,CAAC;AAAA;AAAA,EACF;AAEA,EAAAxB,IAAQ4B,EAAU,cAAc5B,CAAK;AACrC,QAAM6B,IAAUD,EAAU,WAAW5B,CAAK,GAEpC8B,IAAc,OACnBxB,IAAU,IAENS,KAAa,SAChBI,EAAIJ,CAAS,GACbA,IAAY,OAETC,KAAc,QAAQ,OAAO,QAAQ,sBAAuB,eAC/D,OAAO,mBAAmBA,CAAU,GACpCA,IAAa,OAEVC,MACH,aAAaA,CAAY,GACzBA,IAAe,OAGZT,KAAiB,CAACD,MACrBsB,EAAQ,oBAAoB,gBAAgB7B,CAAK,IAAI+B,CAAa,GAClEF,EAAQ,YAAY7B,CAAK,GACzBO,IAAkB,KAGnBM,IAAU,CAAA,GACH,MAAM;AAAA,EAAC;AAGf,EAAAe,EAAU,sBAAA,GACVxB,IAASyB,EAAQ,UAAU7B,GAAOC,GAAUE,CAAO,GACnDK,IAAgB;AAEhB,QAAMuB,IAAgB,MAAY;AAEjC,QADI,CAACzB,KAAW,CAACF,KACbQ,EAAY;AAEhB,IAAAA,IAAa;AAEb,UAAMoB,IAAQ,aAAa,MAAA,KAAW,KAAK,IAAA,GACrCC,IAAStC,MAAgBe,IAAsBC;AAErD,QAAIuB,IAASC,EAAmB,aAAa/B,GAAQC,CAAW;AAChE,WAAO6B,EAAO,cAAY;AACzB,iBAAWE,KAAWF,EAAO,SAAU,CAAAb,EAAYe,CAAO;AAI1D,UAHA/B,IAAc6B,EAAO,kBAET,aAAa,MAAA,KAAW,KAAK,IAAA,KAC/BF,KAASC,GAAQ;AAC1B,QAAArB,IAAa,IACba,EAAA,GAEAR,IAAe,WAAW,MAAM;AAC/B,UAAAA,IAAe,MACfc,EAAA;AAAA,QACD,GAAG,CAAC;AACJ;AAAA,MACD;AAGA,UAAIlB,EAAQ,UAAUJ,GAAoB;AACzC,QAAAG,IAAa,IACba,EAAA;AACA;AAAA,MACD;AAEA,MAAAS,IAASC,EAAmB,aAAa/B,GAAQC,CAAW;AAAA,IAC7D;AAEA,IAAAO,IAAa,IACba,EAAA;AAAA,EACD;AAEA,SAAAI,EAAQ,iBAAiB,gBAAgB7B,CAAK,IAAI+B,CAAa,GAG/D,eAAeA,CAAa,GAErBD;AACR;AAEO,SAASO,EACfC,GACAC,GACArC,IAA6C,MAAM;AAAC,GACpDC,IAAqC,EAAE,aAAa,MACvC;AACb,MAAI,CAACmC;AACJ,mBAAQ,KAAK,oCAAoC,GAC1C,MAAM;AAAA,IAAC;AAGf,MAAIlC,IAAmC,MACnCC,IAAsB,GACtBC,IAAU;AAEd,EAAAgC,IAAQV,EAAU,cAAcU,CAAK;AAErC,QAAMT,IAAUD,EAAU,WAAWU,CAAK,GAEpCR,IAAc,MAAY;AAC/B,IAAAxB,IAAU,IACVuB,EAAQ,oBAAoB,WAAWS,CAAK,IAAIP,CAAa;AAAA,EAC9D;AAEA,EAAA3B,IAASyB,EAAQ,QAAQS,GAAOC,CAAK;AAErC,QAAMR,IAAgB,MAAY;AACjC,QAAI,CAACzB,KAAW,CAACF;AAChB;AAED,UAAM8B,IAASC,EAAmB,aAAa/B,GAAQC,CAAW;AAClE,IAAI6B,EAAO,eACVA,EAAO,SAAS,QAAQ,CAACE,MAA2B;AACnD,MAAAlC,EAASkC,CAAO;AAAA,IACjB,CAAC,GACD/B,IAAc6B,EAAO;AAAA,EAEvB;AAEA,SAAI/B,EAAQ,gBACX0B,EAAQ,iBAAiB,WAAWS,CAAK,IAAIP,CAAa,GAC1D,eAAeA,CAAa,IAGtBD;AACR;AAEO,SAASU,EAAaC,GAAyBvC,GAAkC;AAGvF,EAFgB0B,EAAU,WAAW,EAAE,EAE/B,UAAUa,GAAUvC,CAAQ;AACrC;"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,18 @@
1
- export * from './ws';
1
+ import { NostrManager } from './manager';
2
+
2
3
  export * from './manager';
4
+ export declare class NipWorker {
5
+ private inRings;
6
+ private outRings;
7
+ private managers;
8
+ private worker;
9
+ private hashSubId;
10
+ createShortId(input: string): string;
11
+ constructor(config?: any, scale?: number);
12
+ cleanup(): void;
13
+ setSigner(name: string, secretKeyHex: string): void;
14
+ getManager(subId: string): NostrManager;
15
+ resetInputLoopBackoff(): void;
16
+ }
17
+ export declare const nipWorker: NipWorker;
3
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,cAAc,aAAa,CAAC;AAE5B,qBAAa,SAAS;IACrB,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,SAAS;IASV,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;gBA2B/B,MAAM,GAAE,GAAQ,EAAE,KAAK,SAAI;IAuChC,OAAO,IAAI,IAAI;IAMf,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAMnD,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;IAUvC,qBAAqB,IAAI,IAAI;CAGpC;AAED,eAAO,MAAM,SAAS,WAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{C as i,b as n,G as d,c as r,K as P,d as t,M as o,e as T,f as K,g as f,N as g,a as u,h as C,i as p,P as c,j as l,k as E,m as v,l as S,o as b,p as D,q as M,r as y,s as m,t as k,u as R,v as h,R as F,w as I,S as L,x as N,y as V,z as B,A as W,B as q,D as G,E as H,F as j,H as w,I as z,J as x,L as Q,T as U,O as A,U as J,Q as Z,W as O,V as X,X as Y,Y as _,n as $}from"./index2.js";import{B as aa,a as sa,C as ea,b as ia,c as na,d as da,e as ra,f as Pa,g as ta,h as oa,i as Ta,j as Ka,k as fa,l as ga,m as ua,D as Ca,n as pa,E as ca,o as la,p as Ea,q as va,r as Sa,s as ba,H as Da,t as Ma,u as ya,v as ma,I as ka,w as Ra,K as ha,x as Fa,y as Ia,z as La,A as Na,F as Va,G as Ba,J as Wa,L as qa,M as Ga,N as Ha,O as ja,P as wa,Q as za,R as xa,S as Qa,T as Ua,U as Aa,V as Ja,W as Za,X as Oa,Y as Xa,Z as Ya,_ as _a,$ as $a,a0 as as,a1 as ss,a2 as es,a3 as is,a4 as ns,a5 as ds,a6 as rs,a7 as Ps,a8 as ts,a9 as os,aa as Ts,ab as Ks,ac as fs,ad as gs,ae as us,af as Cs,ag as ps,ah as cs,ai as ls,aj as Es,ak as vs,al as Ss,am as bs,an as Ds,ao as Ms,ap as ys,aq as ms,ar as ks,as as Rs,at as hs,au as Fs,av as Is,aw as Ls,ax as Ns,ay as Vs,az as Bs,aA as Ws,aB as qs,aC as Gs,aD as Hs,aE as js,aF as ws,aG as zs,aH as xs,aI as Qs,aJ as Us,aK as As}from"./message-type.js";var s=(a=>(a[a.Kind0Parsed=0]="Kind0Parsed",a[a.Kind1Parsed=1]="Kind1Parsed",a[a.Kind3Parsed=3]="Kind3Parsed",a[a.Kind4Parsed=4]="Kind4Parsed",a[a.Kind6Parsed=6]="Kind6Parsed",a[a.Kind7Parsed=7]="Kind7Parsed",a[a.Kind17Parsed=17]="Kind17Parsed",a[a.Kind7374Parsed=7374]="Kind7374Parsed",a[a.Kind7375Parsed=7375]="Kind7375Parsed",a[a.Kind7376Parsed=7376]="Kind7376Parsed",a[a.Kind9321Parsed=9321]="Kind9321Parsed",a[a.Kind9735Parsed=9735]="Kind9735Parsed",a[a.Kind10002Parsed=10002]="Kind10002Parsed",a[a.Kind10019Parsed=10019]="Kind10019Parsed",a[a.Kind17375Parsed=17375]="Kind17375Parsed",a[a.Kind39089Parsed=39089]="Kind39089Parsed",a))(s||{}),e=(a=>(a[a.CachedEvent=0]="CachedEvent",a[a.FetchedEvent=1]="FetchedEvent",a[a.Count=2]="Count",a[a.ConnectionStatus=3]="ConnectionStatus",a[a.Eoce=4]="Eoce",a[a.BufferFull=5]="BufferFull",a))(e||{});export{aa as BufferFull,sa as BufferFullT,ea as CashuData,ia as CashuDataT,na as CodeData,da as CodeDataT,ra as ConnectionStatus,Pa as ConnectionStatusT,ta as Contact,oa as ContactT,Ta as ContentBlock,Ka as ContentBlockT,fa as ContentData,ga as CountResponse,ua as CountResponseT,i as CounterPipeConfig,n as CounterPipeConfigT,Ca as DLEQProof,pa as DLEQProofT,ca as Emoji,la as EmojiT,Ea as Eoce,va as EoceT,Sa as EventPointer,ba as EventPointerT,d as GetPublicKey,r as GetPublicKeyT,Da as HashtagData,Ma as HashtagDataT,ya as HistoryTag,ma as HistoryTagT,ka as ImageData,Ra as ImageDataT,ha as Kind0Parsed,Fa as Kind0ParsedT,Ia as Kind10002Parsed,La as Kind10002ParsedT,Na as Kind10019Parsed,Va as Kind10019ParsedT,Ba as Kind17375Parsed,Wa as Kind17375ParsedT,qa as Kind17Parsed,Ga as Kind17ParsedT,Ha as Kind1Parsed,ja as Kind1ParsedT,wa as Kind39089Parsed,za as Kind39089ParsedT,xa as Kind3Parsed,Qa as Kind3ParsedT,Ua as Kind4Parsed,Aa as Kind4ParsedT,Ja as Kind6Parsed,Za as Kind6ParsedT,Oa as Kind7374Parsed,Xa as Kind7374ParsedT,Ya as Kind7375Parsed,_a as Kind7375ParsedT,$a as Kind7376Parsed,as as Kind7376ParsedT,ss as Kind7Parsed,es as Kind7ParsedT,is as Kind9321Parsed,ns as Kind9321ParsedT,ds as Kind9735Parsed,rs as Kind9735ParsedT,P as KindFilterPipeConfig,t as KindFilterPipeConfigT,Ps as LinkPreviewData,ts as LinkPreviewDataT,o as MainContent,T as MainMessage,K as MainMessageT,os as MediaGroupData,Ts as MediaGroupDataT,Ks as MediaItem,fs as MediaItemT,gs as Message,us as MessageType,Cs as MintInfo,ps as MintInfoT,cs as MintProofs,ls as MintProofsT,f as MsgKind,g as NipWorker,Es as NostrData,vs as NostrDataT,Ss as NostrEvent,bs as NostrEventT,u as NostrManager,C as NpubLimiterPipeConfig,p as NpubLimiterPipeConfigT,c as ParsePipeConfig,l as ParsePipeConfigT,Ds as ParsedData,s as ParsedDataUnion,Ms as ParsedEvent,ys as ParsedEventT,E as Pipe,v as PipeConfig,S as PipeT,b as PipelineConfig,D as PipelineConfigT,M as PrivateKey,y as PrivateKeyT,ms as ProfilePointer,ks as ProfilePointerT,Rs as Proof,hs as ProofT,m as ProofVerificationPipeConfig,k as ProofVerificationPipeConfigT,Fs as Pubkey,Is as PubkeyT,R as Publish,h as PublishT,Ls as ReactionType,Ns as RelayInfo,Vs as RelayInfoT,F as RelayRef,I as RelayRefT,Bs as Request,Ws as RequestT,L as SaveToDbPipeConfig,N as SaveToDbPipeConfigT,V as SerializeEventsPipeConfig,B as SerializeEventsPipeConfigT,W as SetSigner,q as SetSignerT,G as SignEvent,H as SignEventT,qs as SignedEvent,Gs as SignedEventT,j as SignerType,Hs as StringVec,js as StringVecT,w as Subscribe,e as SubscribeKind,z as SubscribeT,x as SubscriptionConfig,Q as SubscriptionConfigT,U as Template,A as TemplateT,J as Unsubscribe,Z as UnsubscribeT,ws as ValidProofs,zs as ValidProofsT,xs as VideoData,Qs as VideoDataT,O as WorkerLine,X as WorkerLineT,Y as WorkerMessage,_ as WorkerMessageT,Us as ZapRequest,As as ZapRequestT,$ as nipWorker};
1
+ import{C as a,b as s,G as e,c as i,K as n,d as r,M as o,e as t,f as P,g as d,N as T,a as f,h as g,i as p,P as K,j as C,k as u,l,o as D,m as b,p as c,q as S,r as M,s as v,t as E,u as m,v as y,w as R,R as k,x as I,y as L,z as N,A as V,B as h,D as W,E as q,F as G,H,I as B,J as j,O as w,L as z,Q as F,T as Q,U,V as x,W as Z,X as A,Y as J,Z as O,_,$,n as X}from"./index2.js";import"./ring-buffer.js";import{B as Y,k as aa,l as sa,m as ea,n as ia,o as na,p as ra,q as oa,r as ta,s as Pa,t as da,v as Ta,b as fa,C as ga,w as pa,D as Ka,x as Ca,y as ua,z as la,E as Da,A as ba,G as ca,H as Sa,I as Ma,J as va,K as Ea,L as ma,N as ya,O as Ra,Q as ka,T as Ia,U as La,W as Na,X as Va,Y as ha,Z as Wa,_ as qa,$ as Ga,a0 as Ha,a1 as Ba,a2 as ja,a3 as wa,a4 as za,a5 as Fa,a6 as Qa,a7 as Ua,a8 as xa,a9 as Za,aa as Aa,ab as Ja,ac as Oa,ad as _a,ae as $a,af as Xa,ag as Ya,ah as as,ai as ss,aj as es,ak as is,al as ns,am as rs,an as os,ao as ts,ap as Ps,aq as ds,ar as Ts,as as fs,h as gs,M as ps,at as Ks,au as Cs,av as us,aw as ls,ax as Ds,ay as bs,az as cs,aA as Ss,P as Ms,aB as vs,aC as Es,aD as ms,aE as ys,aF as Rs,aG as ks,aH as Is,aI as Ls,aJ as Ns,aK as Vs,aL as hs,R as Ws,i as qs,aM as Gs,aN as Hs,g as Bs,j as js,V as ws,aO as zs,aP as Fs,aQ as Qs,aR as Us,aS as xs}from"./message-type.js";export{Y as BufferFull,aa as BufferFullT,sa as CashuData,ea as CashuDataT,ia as CodeData,na as CodeDataT,ra as ConnectionStatus,oa as ConnectionStatusT,ta as Contact,Pa as ContactT,da as ContentBlock,Ta as ContentBlockT,fa as ContentData,ga as CountResponse,pa as CountResponseT,a as CounterPipeConfig,s as CounterPipeConfigT,Ka as DLEQProof,Ca as DLEQProofT,ua as Emoji,la as EmojiT,Da as Eoce,ba as EoceT,ca as EventPointer,Sa as EventPointerT,e as GetPublicKey,i as GetPublicKeyT,Ma as HashtagData,va as HashtagDataT,Ea as HistoryTag,ma as HistoryTagT,ya as ImageData,Ra as ImageDataT,ka as Kind0Parsed,Ia as Kind0ParsedT,La as Kind10002Parsed,Na as Kind10002ParsedT,Va as Kind10019Parsed,ha as Kind10019ParsedT,Wa as Kind17375Parsed,qa as Kind17375ParsedT,Ga as Kind17Parsed,Ha as Kind17ParsedT,Ba as Kind1Parsed,ja as Kind1ParsedT,wa as Kind39089Parsed,za as Kind39089ParsedT,Fa as Kind3Parsed,Qa as Kind3ParsedT,Ua as Kind4Parsed,xa as Kind4ParsedT,Za as Kind6Parsed,Aa as Kind6ParsedT,Ja as Kind7374Parsed,Oa as Kind7374ParsedT,_a as Kind7375Parsed,$a as Kind7375ParsedT,Xa as Kind7376Parsed,Ya as Kind7376ParsedT,as as Kind7Parsed,ss as Kind7ParsedT,es as Kind9321Parsed,is as Kind9321ParsedT,ns as Kind9735Parsed,rs as Kind9735ParsedT,n as KindFilterPipeConfig,r as KindFilterPipeConfigT,os as LinkPreviewData,ts as LinkPreviewDataT,o as MainContent,t as MainMessage,P as MainMessageT,Ps as MediaGroupData,ds as MediaGroupDataT,Ts as MediaItem,fs as MediaItemT,gs as Message,ps as MessageType,Ks as MintInfo,Cs as MintInfoT,us as MintProofs,ls as MintProofsT,d as MsgKind,T as NipWorker,Ds as NostrData,bs as NostrDataT,cs as NostrEvent,Ss as NostrEventT,f as NostrManager,g as NpubLimiterPipeConfig,p as NpubLimiterPipeConfigT,K as ParsePipeConfig,C as ParsePipeConfigT,Ms as ParsedData,u as ParsedDataUnion,vs as ParsedEvent,Es as ParsedEventT,l as Pipe,D as PipeConfig,b as PipeT,c as PipelineConfig,S as PipelineConfigT,M as PrivateKey,v as PrivateKeyT,ms as ProfilePointer,ys as ProfilePointerT,Rs as Proof,ks as ProofT,E as ProofVerificationPipeConfig,m as ProofVerificationPipeConfigT,Is as Pubkey,Ls as PubkeyT,y as Publish,R as PublishT,Ns as ReactionType,Vs as RelayInfo,hs as RelayInfoT,k as RelayRef,I as RelayRefT,Ws as Request,qs as RequestT,L as SaveToDbPipeConfig,N as SaveToDbPipeConfigT,V as SerializeEventsPipeConfig,h as SerializeEventsPipeConfigT,W as SetSigner,q as SetSignerT,G as SignEvent,H as SignEventT,Gs as SignedEvent,Hs as SignedEventT,B as SignerType,Bs as StringVec,js as StringVecT,j as Subscribe,w as SubscribeKind,z as SubscribeT,F as SubscriptionConfig,Q as SubscriptionConfigT,U as Template,x as TemplateT,Z as Unsubscribe,A as UnsubscribeT,ws as ValidProofs,zs as ValidProofsT,Fs as VideoData,Qs as VideoDataT,J as WorkerLine,O as WorkerLineT,_ as WorkerMessage,$ as WorkerMessageT,Us as ZapRequest,xs as ZapRequestT,X as nipWorker};
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/generated/nostr/fb/parsed-data-union.ts","../src/generated/nostr/fb/subscribe-kind.ts"],"sourcesContent":["import { ByteString } from \"src/lib/ByteString\";\n// automatically generated by the FlatBuffers compiler, do not modify\n\n/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */\n\nexport enum ParsedDataUnion {\n Kind0Parsed = 0,\n Kind1Parsed = 1,\n Kind3Parsed = 3,\n Kind4Parsed = 4,\n Kind6Parsed = 6,\n Kind7Parsed = 7,\n Kind17Parsed = 17,\n Kind7374Parsed = 7374,\n Kind7375Parsed = 7375,\n Kind7376Parsed = 7376,\n Kind9321Parsed = 9321,\n Kind9735Parsed = 9735,\n Kind10002Parsed = 10002,\n Kind10019Parsed = 10019,\n Kind17375Parsed = 17375,\n Kind39089Parsed = 39089\n}\n","import { ByteString } from \"src/lib/ByteString\";\n// automatically generated by the FlatBuffers compiler, do not modify\n\n/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */\n\nexport enum SubscribeKind {\n CachedEvent = 0,\n FetchedEvent = 1,\n Count = 2,\n ConnectionStatus = 3,\n Eoce = 4,\n BufferFull = 5\n}\n"],"names":["ParsedDataUnion","SubscribeKind"],"mappings":";;AAKO,IAAKA,sBAAAA,OACVA,EAAAA,EAAA,cAAc,CAAA,IAAd,eACAA,EAAAA,EAAA,cAAc,CAAA,IAAd,eACAA,EAAAA,EAAA,cAAc,CAAA,IAAd,eACAA,EAAAA,EAAA,cAAc,CAAA,IAAd,eACAA,EAAAA,EAAA,cAAc,CAAA,IAAd,eACAA,EAAAA,EAAA,cAAc,CAAA,IAAd,eACAA,EAAAA,EAAA,eAAe,EAAA,IAAf,gBACAA,EAAAA,EAAA,iBAAiB,IAAA,IAAjB,kBACAA,EAAAA,EAAA,iBAAiB,IAAA,IAAjB,kBACAA,EAAAA,EAAA,iBAAiB,IAAA,IAAjB,kBACAA,EAAAA,EAAA,iBAAiB,IAAA,IAAjB,kBACAA,EAAAA,EAAA,iBAAiB,IAAA,IAAjB,kBACAA,EAAAA,EAAA,kBAAkB,KAAA,IAAlB,mBACAA,EAAAA,EAAA,kBAAkB,KAAA,IAAlB,mBACAA,EAAAA,EAAA,kBAAkB,KAAA,IAAlB,mBACAA,EAAAA,EAAA,kBAAkB,KAAA,IAAlB,mBAhBUA,IAAAA,KAAA,CAAA,CAAA,GCAAC,sBAAAA,OACVA,EAAAA,EAAA,cAAc,CAAA,IAAd,eACAA,EAAAA,EAAA,eAAe,CAAA,IAAf,gBACAA,EAAAA,EAAA,QAAQ,CAAA,IAAR,SACAA,EAAAA,EAAA,mBAAmB,CAAA,IAAnB,oBACAA,EAAAA,EAAA,OAAO,CAAA,IAAP,QACAA,EAAAA,EAAA,aAAa,CAAA,IAAb,cANUA,IAAAA,KAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
package/dist/index2.js CHANGED
@@ -1 +1 @@
1
- import{aO as tt,aP as G,aQ as et,aR as J,aS as b,aD as Lt,az as Ut,ae as st,ad as it,aL as ft,aA as xt,aE as nt}from"./message-type.js";import Vt from"@candypoets/rust-worker/worker.js?worker";import Bt from"@candypoets/rust-worker/rust_worker_bg.wasm?url";import{encode as Kt}from"@msgpack/msgpack";class R{constructor(t){this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null,this.text_encoder=new TextEncoder;let e;t?e=t:e=1024,this.bb=tt.allocate(e),this.space=e}clear(){this.bb.clear(),this.space=this.bb.capacity(),this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null}forceDefaults(t){this.force_defaults=t}dataBuffer(){return this.bb}asUint8Array(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())}prep(t,e){t>this.minalign&&(this.minalign=t);const s=~(this.bb.capacity()-this.space+e)+1&t-1;for(;this.space<s+t+e;){const n=this.bb.capacity();this.bb=R.growByteBuffer(this.bb),this.space+=this.bb.capacity()-n}this.pad(s)}pad(t){for(let e=0;e<t;e++)this.bb.writeInt8(--this.space,0)}writeInt8(t){this.bb.writeInt8(this.space-=1,t)}writeInt16(t){this.bb.writeInt16(this.space-=2,t)}writeInt32(t){this.bb.writeInt32(this.space-=4,t)}writeInt64(t){this.bb.writeInt64(this.space-=8,t)}writeFloat32(t){this.bb.writeFloat32(this.space-=4,t)}writeFloat64(t){this.bb.writeFloat64(this.space-=8,t)}addInt8(t){this.prep(1,0),this.writeInt8(t)}addInt16(t){this.prep(2,0),this.writeInt16(t)}addInt32(t){this.prep(4,0),this.writeInt32(t)}addInt64(t){this.prep(8,0),this.writeInt64(t)}addFloat32(t){this.prep(4,0),this.writeFloat32(t)}addFloat64(t){this.prep(8,0),this.writeFloat64(t)}addFieldInt8(t,e,s){(this.force_defaults||e!=s)&&(this.addInt8(e),this.slot(t))}addFieldInt16(t,e,s){(this.force_defaults||e!=s)&&(this.addInt16(e),this.slot(t))}addFieldInt32(t,e,s){(this.force_defaults||e!=s)&&(this.addInt32(e),this.slot(t))}addFieldInt64(t,e,s){(this.force_defaults||e!==s)&&(this.addInt64(e),this.slot(t))}addFieldFloat32(t,e,s){(this.force_defaults||e!=s)&&(this.addFloat32(e),this.slot(t))}addFieldFloat64(t,e,s){(this.force_defaults||e!=s)&&(this.addFloat64(e),this.slot(t))}addFieldOffset(t,e,s){(this.force_defaults||e!=s)&&(this.addOffset(e),this.slot(t))}addFieldStruct(t,e,s){e!=s&&(this.nested(e),this.slot(t))}nested(t){if(t!=this.offset())throw new TypeError("FlatBuffers: struct must be serialized inline.")}notNested(){if(this.isNested)throw new TypeError("FlatBuffers: object serialization must not be nested.")}slot(t){this.vtable!==null&&(this.vtable[t]=this.offset())}offset(){return this.bb.capacity()-this.space}static growByteBuffer(t){const e=t.capacity();if(e&3221225472)throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");const s=e<<1,n=tt.allocate(s);return n.setPosition(s-e),n.bytes().set(t.bytes(),s-e),n}addOffset(t){this.prep(G,0),this.writeInt32(this.offset()-t+G)}startObject(t){this.notNested(),this.vtable==null&&(this.vtable=[]),this.vtable_in_use=t;for(let e=0;e<t;e++)this.vtable[e]=0;this.isNested=!0,this.object_start=this.offset()}endObject(){if(this.vtable==null||!this.isNested)throw new Error("FlatBuffers: endObject called without startObject");this.addInt32(0);const t=this.offset();let e=this.vtable_in_use-1;for(;e>=0&&this.vtable[e]==0;e--);const s=e+1;for(;e>=0;e--)this.addInt16(this.vtable[e]!=0?t-this.vtable[e]:0);const n=2;this.addInt16(t-this.object_start);const o=(s+n)*et;this.addInt16(o);let r=0;const a=this.space;t:for(e=0;e<this.vtables.length;e++){const h=this.bb.capacity()-this.vtables[e];if(o==this.bb.readInt16(h)){for(let c=et;c<o;c+=et)if(this.bb.readInt16(a+c)!=this.bb.readInt16(h+c))continue t;r=this.vtables[e];break}}return r?(this.space=this.bb.capacity()-t,this.bb.writeInt32(this.space,r-t)):(this.vtables.push(this.offset()),this.bb.writeInt32(this.bb.capacity()-t,this.offset()-t)),this.isNested=!1,t}finish(t,e,s){const n=s?b:0;if(e){const o=e;if(this.prep(this.minalign,G+J+n),o.length!=J)throw new TypeError("FlatBuffers: file identifier must be length "+J);for(let r=J-1;r>=0;r--)this.writeInt8(o.charCodeAt(r))}this.prep(this.minalign,G+n),this.addOffset(t),n&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)}finishSizePrefixed(t,e){this.finish(t,e,!0)}requiredField(t,e){const s=this.bb.capacity()-t,n=s-this.bb.readInt32(s);if(!(e<this.bb.readInt16(n)&&this.bb.readInt16(n+e)!=0))throw new TypeError("FlatBuffers: field "+e+" must be set")}startVector(t,e,s){this.notNested(),this.vector_num_elems=e,this.prep(G,t*e),this.prep(s,t*e)}endVector(){return this.writeInt32(this.vector_num_elems),this.offset()}createSharedString(t){if(!t)return 0;if(this.string_maps||(this.string_maps=new Map),this.string_maps.has(t))return this.string_maps.get(t);const e=this.createString(t);return this.string_maps.set(t,e),e}createString(t){if(t==null)return 0;let e;return t instanceof Uint8Array?e=t:e=this.text_encoder.encode(t),this.addInt8(0),this.startVector(1,e.length,1),this.bb.setPosition(this.space-=e.length),this.bb.bytes().set(e,this.space),this.endVector()}createByteVector(t){return t==null?0:(this.startVector(1,t.length,1),this.bb.setPosition(this.space-=t.length),this.bb.bytes().set(t,this.space),this.endVector())}createObjectOffset(t){return t===null?0:typeof t=="string"?this.createString(t):t.pack(this)}createObjectOffsetList(t){const e=[];for(let s=0;s<t.length;++s){const n=t[s];if(n!==null)e.push(this.createObjectOffset(n));else throw new TypeError("FlatBuffers: Argument for createObjectOffsetList cannot contain null.")}return e}createStructOffsetList(t,e){return e(this,t.length),this.createObjectOffsetList(t.slice().reverse()),this.endVector()}}class k{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 k).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCounterPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new k).__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.__stringByteString(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 k.startCounterPipeConfig(t),k.addKinds(t,e),k.addPubkey(t,s),k.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=k.createKindsVector(t,this.kinds),s=this.pubkey!==null?t.createString(this.pubkey):0;return k.createCounterPipeConfig(t,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 getRootAsGetPublicKey(t,e){return(e||new K).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsGetPublicKey(t,e){return t.setPosition(t.position()+b),(e||new K).__init(t.readInt32(t.position())+t.position(),t)}static startGetPublicKey(t){t.startObject(0)}static endGetPublicKey(t){return t.endObject()}static createGetPublicKey(t){return K.startGetPublicKey(t),K.endGetPublicKey(t)}unpack(){return new rt}unpackTo(t){}}class rt{constructor(){}pack(t){return K.createGetPublicKey(t)}}class T{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 T).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsKindFilterPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new T).__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 T.startKindFilterPipeConfig(t),T.addKinds(t,e),T.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=T.createKindsVector(t,this.kinds);return T.createKindFilterPipeConfig(t,e)}}class _{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 _).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsTemplate(t,e){return t.setPosition(t.position()+b),(e||new _).__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}content(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__stringByteString(this.bb_pos+e,t):null}tags(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?(e||new Lt).__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,8);return t?this.bb.__vector_len(this.bb_pos+t):0}static startTemplate(t){t.startObject(3)}static addKind(t,e){t.addFieldInt16(0,e,0)}static addContent(t,e){t.addFieldOffset(1,e,0)}static addTags(t,e){t.addFieldOffset(2,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,6),t.requiredField(e,8),e}static createTemplate(t,e,s,n){return _.startTemplate(t),_.addKind(t,e),_.addContent(t,s),_.addTags(t,n),_.endTemplate(t)}unpack(){return new X(this.kind(),this.content(),this.bb.createObjList(this.tags.bind(this),this.tagsLength()))}unpackTo(t){t.kind=this.kind(),t.content=this.content(),t.tags=this.bb.createObjList(this.tags.bind(this),this.tagsLength())}}class X{constructor(t=0,e=null,s=[]){this.kind=t,this.content=e,this.tags=s}pack(t){const e=this.content!==null?t.createString(this.content):0,s=_.createTagsVector(t,t.createObjectOffsetList(this.tags));return _.createTemplate(t,this.kind,e,s)}}class F{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 F).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPublish(t,e){return t.setPosition(t.position()+b),(e||new F).__init(t.readInt32(t.position())+t.position(),t)}publishId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(this.bb_pos+e,t):null}template(t){const e=this.bb.__offset(this.bb_pos,6);return e?(t||new _).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}static startPublish(t){t.startObject(2)}static addPublishId(t,e){t.addFieldOffset(0,e,0)}static addTemplate(t,e){t.addFieldOffset(1,e,0)}static endPublish(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),e}unpack(){return new ot(this.publishId(),this.template()!==null?this.template().unpack():null)}unpackTo(t){t.publishId=this.publishId(),t.template=this.template()!==null?this.template().unpack():null}}class ot{constructor(t=null,e=null){this.publishId=t,this.template=e}pack(t){const e=this.publishId!==null?t.createString(this.publishId):0,s=this.template!==null?this.template.pack(t):0;return F.startPublish(t),F.addPublishId(t,e),F.addTemplate(t,s),F.endPublish(t)}}class A{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 A).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPrivateKey(t,e){return t.setPosition(t.position()+b),(e||new A).__init(t.readInt32(t.position())+t.position(),t)}privateKey(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(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 A.startPrivateKey(t),A.addPrivateKey(t,e),A.endPrivateKey(t)}unpack(){return new at(this.privateKey())}unpackTo(t){t.privateKey=this.privateKey()}}class at{constructor(t=null){this.privateKey=t}pack(t){const e=this.privateKey!==null?t.createString(this.privateKey):0;return A.createPrivateKey(t,e)}}var q=(i=>(i[i.NONE=0]="NONE",i[i.PrivateKey=1]="PrivateKey",i))(q||{});function yt(i,t){switch(q[i]){case"NONE":return null;case"PrivateKey":return t(new A);default:return null}}class C{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 C).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSetSigner(t,e){return t.setPosition(t.position()+b),(e||new C).__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):q.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,q.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 C.startSetSigner(t),C.addSignerTypeType(t,e),C.addSignerType(t,s),C.endSetSigner(t)}unpack(){return new ct(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 ct{constructor(t=q.NONE,e=null){this.signerTypeType=t,this.signerType=e}pack(t){const e=t.createObjectOffset(this.signerType);return C.createSetSigner(t,this.signerTypeType,e)}}class M{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 M).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSignEvent(t,e){return t.setPosition(t.position()+b),(e||new M).__init(t.readInt32(t.position())+t.position(),t)}template(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new _).__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 M.startSignEvent(t),M.addTemplate(t,e),M.endSignEvent(t)}unpack(){return new ht(this.template()!==null?this.template().unpack():null)}unpackTo(t){t.template=this.template()!==null?this.template().unpack():null}}class ht{constructor(t=null){this.template=t}pack(t){const e=this.template!==null?this.template.pack(t):0;return M.createSignEvent(t,e)}}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()+b),(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 wt(this.kind(),this.limitPerNpub(),this.maxTotalNpubs())}unpackTo(t){t.kind=this.kind(),t.limitPerNpub=this.limitPerNpub(),t.maxTotalNpubs=this.maxTotalNpubs()}}class wt{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 j{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 j).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsParsePipeConfig(t,e){return t.setPosition(t.position()+b),(e||new j).__init(t.readInt32(t.position())+t.position(),t)}static startParsePipeConfig(t){t.startObject(0)}static endParsePipeConfig(t){return t.endObject()}static createParsePipeConfig(t){return j.startParsePipeConfig(t),j.endParsePipeConfig(t)}unpack(){return new Pt}unpackTo(t){}}class Pt{constructor(){}pack(t){return j.createParsePipeConfig(t)}}class N{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 N).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsProofVerificationPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new N).__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 N.startProofVerificationPipeConfig(t),N.addMaxProofs(t,e),N.endProofVerificationPipeConfig(t)}unpack(){return new St(this.maxProofs())}unpackTo(t){t.maxProofs=this.maxProofs()}}class St{constructor(t=0){this.maxProofs=t}pack(t){return N.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()+b),(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 mt}unpackTo(t){}}class mt{constructor(){}pack(t){return z.createSaveToDbPipeConfig(t)}}class L{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 L).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSerializeEventsPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new L).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(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 L.startSerializeEventsPipeConfig(t),L.addSubscriptionId(t,e),L.endSerializeEventsPipeConfig(t)}unpack(){return new kt(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class kt{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return L.createSerializeEventsPipeConfig(t,e)}}var D=(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))(D||{});function Ct(i,t){switch(D[i]){case"NONE":return null;case"ParsePipeConfig":return t(new j);case"KindFilterPipeConfig":return t(new T);case"CounterPipeConfig":return t(new k);case"NpubLimiterPipeConfig":return t(new S);case"SaveToDbPipeConfig":return t(new z);case"SerializeEventsPipeConfig":return t(new L);case"ProofVerificationPipeConfig":return t(new N);default:return null}}class I{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 I).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipe(t,e){return t.setPosition(t.position()+b),(e||new I).__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):D.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,D.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 I.startPipe(t),I.addConfigType(t,e),I.addConfig(t,s),I.endPipe(t)}unpack(){return new It(this.configType(),(()=>{const t=Ct(this.configType(),this.config.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.configType=this.configType(),t.config=(()=>{const e=Ct(this.configType(),this.config.bind(this));return e===null?null:e.unpack()})()}}class It{constructor(t=D.NONE,e=null){this.configType=t,this.config=e}pack(t){const e=t.createObjectOffset(this.config);return I.createPipe(t,this.configType,e)}}class v{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 v).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipelineConfig(t,e){return t.setPosition(t.position()+b),(e||new v).__init(t.readInt32(t.position())+t.position(),t)}pipes(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?(e||new I).__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 v.startPipelineConfig(t),v.addPipes(t,e),v.endPipelineConfig(t)}unpack(){return new bt(this.bb.createObjList(this.pipes.bind(this),this.pipesLength()))}unpackTo(t){t.pipes=this.bb.createObjList(this.pipes.bind(this),this.pipesLength())}}class bt{constructor(t=[]){this.pipes=t}pack(t){const e=v.createPipesVector(t,t.createObjectOffsetList(this.pipes));return v.createPipelineConfig(t,e)}}class g{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 g).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscriptionConfig(t,e){return t.setPosition(t.position()+b),(e||new g).__init(t.readInt32(t.position())+t.position(),t)}pipeline(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new v).__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}static startSubscriptionConfig(t){t.startObject(8)}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 endSubscriptionConfig(t){return t.endObject()}static createSubscriptionConfig(t,e,s,n,o,r,a,h,c){return g.startSubscriptionConfig(t),g.addPipeline(t,e),g.addCloseOnEose(t,s),g.addCacheFirst(t,n),g.addTimeoutMs(t,o),g.addMaxEvents(t,r),g.addSkipCache(t,a),g.addForce(t,h),g.addBytesPerEvent(t,c),g.endSubscriptionConfig(t)}unpack(){return new dt(this.pipeline()!==null?this.pipeline().unpack():null,this.closeOnEose(),this.cacheFirst(),this.timeoutMs(),this.maxEvents(),this.skipCache(),this.force(),this.bytesPerEvent())}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()}}class dt{constructor(t=null,e=!1,s=!0,n=BigInt("0"),o=0,r=!1,a=!1,h=0){this.pipeline=t,this.closeOnEose=e,this.cacheFirst=s,this.timeoutMs=n,this.maxEvents=o,this.skipCache=r,this.force=a,this.bytesPerEvent=h}pack(t){const e=this.pipeline!==null?this.pipeline.pack(t):0;return g.createSubscriptionConfig(t,e,this.closeOnEose,this.cacheFirst,this.timeoutMs,this.maxEvents,this.skipCache,this.force,this.bytesPerEvent)}}class P{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 P).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscribe(t,e){return t.setPosition(t.position()+b),(e||new P).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(this.bb_pos+e,t):null}requests(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new Ut).__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 g).__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 ut(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 ut{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=P.createRequestsVector(t,t.createObjectOffsetList(this.requests)),n=this.config!==null?this.config.pack(t):0;return P.startSubscribe(t),P.addSubscriptionId(t,e),P.addRequests(t,s),P.addConfig(t,n),P.endSubscribe(t)}}class U{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 U).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsUnsubscribe(t,e){return t.setPosition(t.position()+b),(e||new U).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(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 U.startUnsubscribe(t),U.addSubscriptionId(t,e),U.endUnsubscribe(t)}unpack(){return new lt(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class lt{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return U.createUnsubscribe(t,e)}}var y=(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))(y||{});function Tt(i,t){switch(y[i]){case"NONE":return null;case"Subscribe":return t(new P);case"Unsubscribe":return t(new U);case"Publish":return t(new F);case"SignEvent":return t(new M);case"SetSigner":return t(new C);case"GetPublicKey":return t(new K);default:return null}}class E{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 E).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMainMessage(t,e){return t.setPosition(t.position()+b),(e||new E).__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):y.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,y.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 E.startMainMessage(t),E.addContentType(t,e),E.addContent(t,s),E.endMainMessage(t)}unpack(){return new V(this.contentType(),(()=>{const t=Tt(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.contentType=this.contentType(),t.content=(()=>{const e=Tt(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class V{constructor(t=y.NONE,e=null){this.contentType=t,this.content=e}pack(t){const e=t.createObjectOffset(this.content);return E.createMainMessage(t,this.contentType,e)}}var $=(i=>(i[i.Unknown=0]="Unknown",i[i.Event=1]="Event",i[i.Eose=2]="Eose",i[i.Ok=3]="Ok",i[i.Closed=4]="Closed",i[i.Notice=5]="Notice",i[i.Auth=6]="Auth",i))($||{});class O{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsRelayRef(t,e){return(e||new O).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsRelayRef(t,e){return t.setPosition(t.position()+b),(e||new O).__init(t.readInt32(t.position())+t.position(),t)}url(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(this.bb_pos+e,t):null}static startRelayRef(t){t.startObject(1)}static addUrl(t,e){t.addFieldOffset(0,e,0)}static endRelayRef(t){const e=t.endObject();return t.requiredField(e,4),e}static createRelayRef(t,e){return O.startRelayRef(t),O.addUrl(t,e),O.endRelayRef(t)}unpack(){return new vt(this.url())}unpackTo(t){t.url=this.url()}}class vt{constructor(t=null){this.url=t}pack(t){const e=this.url!==null?t.createString(this.url):0;return O.createRelayRef(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 getRootAsWorkerLine(t,e){return(e||new l).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsWorkerLine(t,e){return t.setPosition(t.position()+b),(e||new l).__init(t.readInt32(t.position())+t.position(),t)}relay(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new O).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}kind(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readInt16(this.bb_pos+t):$.Unknown}subId(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__stringByteString(this.bb_pos+e,t):null}raw(t){const e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readUint8(this.bb.__vector(this.bb_pos+e)+t):0}rawLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}rawArray(){const t=this.bb.__offset(this.bb_pos,10);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 startWorkerLine(t){t.startObject(4)}static addRelay(t,e){t.addFieldOffset(0,e,0)}static addKind(t,e){t.addFieldInt16(1,e,$.Unknown)}static addSubId(t,e){t.addFieldOffset(2,e,0)}static addRaw(t,e){t.addFieldOffset(3,e,0)}static createRawVector(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 startRawVector(t,e){t.startVector(1,e,1)}static endWorkerLine(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,10),e}static createWorkerLine(t,e,s,n,o){return l.startWorkerLine(t),l.addRelay(t,e),l.addKind(t,s),l.addSubId(t,n),l.addRaw(t,o),l.endWorkerLine(t)}unpack(){return new Ot(this.relay()!==null?this.relay().unpack():null,this.kind(),this.subId(),this.bb.createScalarList(this.raw.bind(this),this.rawLength()))}unpackTo(t){t.relay=this.relay()!==null?this.relay().unpack():null,t.kind=this.kind(),t.subId=this.subId(),t.raw=this.bb.createScalarList(this.raw.bind(this),this.rawLength())}}class Ot{constructor(t=null,e=$.Unknown,s=null,n=[]){this.relay=t,this.kind=e,this.subId=s,this.raw=n}pack(t){const e=this.relay!==null?this.relay.pack(t):0,s=this.subId!==null?t.createString(this.subId):0,n=l.createRawVector(t,this.raw);return l.createWorkerLine(t,e,this.kind,s,n)}}class m{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsWorkerMessage(t,e){return(e||new m).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsWorkerMessage(t,e){return t.setPosition(t.position()+b),(e||new m).__init(t.readInt32(t.position())+t.position(),t)}type(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint32(this.bb_pos+t):st.ParsedNostrEvent}contentType(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readUint8(this.bb_pos+t):it.NONE}content(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__union(t,this.bb_pos+e):null}static startWorkerMessage(t){t.startObject(3)}static addType(t,e){t.addFieldInt32(0,e,st.ParsedNostrEvent)}static addContentType(t,e){t.addFieldInt8(1,e,it.NONE)}static addContent(t,e){t.addFieldOffset(2,e,0)}static endWorkerMessage(t){return t.endObject()}static finishWorkerMessageBuffer(t,e){t.finish(e)}static finishSizePrefixedWorkerMessageBuffer(t,e){t.finish(e,void 0,!0)}static createWorkerMessage(t,e,s,n){return m.startWorkerMessage(t),m.addType(t,e),m.addContentType(t,s),m.addContent(t,n),m.endWorkerMessage(t)}unpack(){return new Rt(this.type(),this.contentType(),(()=>{const t=ft(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.type=this.type(),t.contentType=this.contentType(),t.content=(()=>{const e=ft(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class Rt{constructor(t=st.ParsedNostrEvent,e=it.NONE,s=null){this.type=t,this.contentType=e,this.content=s}pack(t){const e=t.createObjectOffset(this.content);return m.createWorkerMessage(t,this.type,this.contentType,e)}}class Ft{constructor(t){this.dataStart=32,this.dropped=0,this.sab=t,this.dataView=new DataView(t),this.capacity=this.dataView.getUint32(0,!0)}getHead(){return this.dataView.getUint32(4,!0)%this.capacity}setHead(t){this.dataView.setUint32(4,t%this.capacity,!0)}getTail(){return this.dataView.getUint32(8,!0)%this.capacity}setTail(t){this.dataView.setUint32(8,t%this.capacity,!0)}getSeq(){return this.dataView.getUint32(12,!0)}setSeq(t){this.dataView.setUint32(12,t,!0)}getFreeSpace(){const t=this.getHead(),e=this.getTail(),s=(t-e+this.capacity)%this.capacity;return this.capacity-s}getDropped(){return this.dropped}hasRecords(){return this.getHead()!==this.getTail()}readNext(){const t=this.read();return t?{payload:t}:null}write(t){const e=t.byteLength,s=8+e,n=4+s+4;let o=0;for(;this.getFreeSpace()<n;){if(!this.skipRecord())return this.dropped+=o+1,-1;o++}const r=this.getSeq()+1;this.setSeq(r);let a=this.getHead();return this.dataView.setUint32(this.dataStart+a,s,!0),a=(a+4)%this.capacity,this.dataView.setUint16(this.dataStart+a,0,!0),a=(a+2)%this.capacity,this.dataView.setUint16(this.dataStart+a,0,!0),a=(a+2)%this.capacity,this.dataView.setUint32(this.dataStart+a,r,!0),a=(a+4)%this.capacity,this.copyBytes(a,t,0,e),a=(a+e)%this.capacity,this.dataView.setUint32(this.dataStart+a,s,!0),a=(a+4)%this.capacity,this.setHead(a),this.dropped+=o,r}read(){let t=this.getTail();if(t===this.getHead())return null;const e=this.dataView.getUint32(this.dataStart+t,!0);if(e===0)return null;const s=(t+4+e)%this.capacity;if(this.dataView.getUint32(this.dataStart+s,!0)!==e)return null;const n=new Uint8Array(e);this.copyFromRing((t+4)%this.capacity,n,0,e);const o=n.subarray(8),r=4+e+4;return this.setTail((this.getTail()+r)%this.capacity),o}skipRecord(){let t=this.getTail();if(t===this.getHead())return!1;const e=this.dataView.getUint32(this.dataStart+t,!0);if(e===0)return!1;const s=(t+4+e)%this.capacity;if(this.dataView.getUint32(this.dataStart+s,!0)!==e)return!1;const n=4+e+4;return this.setTail((this.getTail()+n)%this.capacity),!0}copyBytes(t,e,s,n){let o=n,r=s,a=t;for(;o>0;){const h=this.capacity-a%this.capacity,c=Math.min(o,h),d=this.dataStart+a%this.capacity,f=e.subarray(r,r+c);new Uint8Array(this.sab,d,c).set(f),o-=c,r+=c,a+=c}}copyFromRing(t,e,s,n){let o=n,r=s,a=t;for(;o>0;){const h=this.capacity-a%this.capacity,c=Math.min(o,h),d=this.dataStart+a%this.capacity,f=new Uint8Array(this.sab,d,c);e.set(f,r),o-=c,r+=c,a+=c}}}function Et(i){const t=new DataView(i),e=i.byteLength;if(e<32)throw new Error(`Ring buffer too small: ${e} bytes`);if(t.getUint32(0,!0)!==0)return;const s=e-32;if(s<=0)throw new Error(`Invalid ring capacity computed from total=${e}`);t.setUint32(0,s,!0),t.setUint32(4,0,!0),t.setUint32(8,0,!0),t.setUint32(12,0,!0);for(let n=16;n<32;n+=4)t.setUint32(n,0,!0)}var u=(i=>(i.Idle="idle",i.Connecting="connecting",i.Ready="ready",i.Closing="closing",i.Closed="closed",i.Error="error",i))(u||{});class jt{constructor(t,e={}){this.status=u.Closed,this.ws=null,this.reconnectTimer=null,this.abortController=null,this.attempts=0,this.givenUp=!1,this.lastActivity=Date.now(),this.stats={dropped:0,sent:0,received:0,reconnects:0,lastActivity:Date.now()},this.readyWaiters=[],this.messageHandler=null,this.url=t,this.config={connectTimeoutMs:5e3,writeTimeoutMs:1e4,retry:{baseMs:300,maxMs:1e4,multiplier:1.6,jitter:.1},maxReconnectAttempts:2,idleTimeoutMs:3e5,...e}}getUrl(){return this.url}getStatus(){return this.status}getStats(){return{...this.stats,reconnects:this.attempts,lastActivity:this.lastActivity}}getLastActivity(){return this.lastActivity}hasGivenUp(){return this.givenUp}setMessageHandler(t){this.messageHandler=t}connect(){if(this.givenUp||this.status===u.Connecting||this.status===u.Ready)return;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.status=u.Connecting,this.abortController=new AbortController;const t=this.abortController.signal;try{this.ws=new WebSocket(this.url),this.ws.binaryType="arraybuffer";const e=()=>{this.ws&&(this.ws.onopen=null,this.ws.onclose=null,this.ws.onerror=null,this.ws.onmessage=null)},s=()=>{this.status=u.Ready,this.attempts=0,this.givenUp=!1,this.lastActivity=Date.now(),this.stats.lastActivity=this.lastActivity,this.resolveReady(!0)},n=h=>{e(),this.status=u.Closed,this.resolveReady(!1),h.code!==1e3&&this.scheduleReconnect()},o=h=>{e(),this.status=u.Closed,this.resolveReady(!1),this.scheduleReconnect()},r=h=>{if(this.lastActivity=Date.now(),this.stats.lastActivity=this.lastActivity,this.stats.received++,typeof h.data=="string"){const c=h.data,{kind:d,subId:f}=this.shallowScan(c);this.messageHandler&&this.messageHandler(this.url,d,f,c)}};this.ws.onopen=s,this.ws.onclose=n,this.ws.onerror=o,this.ws.onmessage=r;const a=setTimeout(()=>{if(this.status===u.Connecting){e();try{this.ws?.close()}catch{}this.status=u.Closed,this.resolveReady(!1),this.scheduleReconnect()}},this.config.connectTimeoutMs);t.addEventListener("abort",()=>{clearTimeout(a),e();try{this.ws?.close()}catch{}this.status=u.Closed,this.resolveReady(!1),this.scheduleReconnect()})}catch{this.status=u.Closed,this.resolveReady(!1),this.scheduleReconnect()}}async sendMessage(t){if(this.status!==u.Ready||!this.ws)throw new Error("Connection not ready");this.ws.send(t),this.stats.sent++,this.lastActivity=Date.now(),this.stats.lastActivity=this.lastActivity}async waitForReady(t=this.config.connectTimeoutMs??5e3){if(this.status!==u.Ready)return new Promise((e,s)=>{const n=setTimeout(()=>{this.removeReadyResolver(o),s(new Error("Timeout waiting for ready"))},t),o=r=>{clearTimeout(n),r?e():s(new Error("Connection closed"))};this.readyWaiters.push(o)})}async close(){this.abortController&&this.abortController.abort(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.closeWebSocket(),this.status=u.Closed,this.resolveReady(!1)}shouldCloseDueToInactivity(){return Date.now()-this.lastActivity>(this.config.idleTimeoutMs??3e5)}resolveReady(t){if(this.readyWaiters.length===0)return;const e=this.readyWaiters.slice();this.readyWaiters.length=0;for(const s of e)try{s(t)}catch{}}removeReadyResolver(t){const e=this.readyWaiters.indexOf(t);e>=0&&this.readyWaiters.splice(e,1)}closeWebSocket(){if(this.ws){try{this.ws.close(1e3,"Normal closure")}catch{}this.ws=null}}scheduleReconnect(){if(this.status!==u.Closed||!this.config.retry?.baseMs)return;const t=this.config.maxReconnectAttempts??2;if(t>0&&this.attempts>=t){this.givenUp=!0;return}const e=this.config.retry.baseMs,s=this.config.retry.maxMs??1e4,n=this.config.retry.multiplier??1.6,o=this.config.retry.jitter??.1,r=Math.min(e*Math.pow(n,this.attempts),s)*(1+(Math.random()-.5)*o*2);this.reconnectTimer=setTimeout(()=>{this.attempts++,this.stats.reconnects=this.attempts,this.connect()},r)}shallowScan(t){let e=0;const s=t.length;for(;e<s&&t.charCodeAt(e)<=32;)e++;if(e>=s||t[e]!=="[")return{kind:0,subId:null};for(e++;e<s&&t.charCodeAt(e)<=32;)e++;if(e>=s||t[e]!=='"')return{kind:0,subId:null};e++;let n=e;for(;e<s&&t[e]!=='"';)e++;const o=t.slice(n,e).toUpperCase();e++;let r=0;if(o==="EVENT"?r=1:o==="EOSE"?r=2:o==="OK"?r=3:o==="CLOSED"?r=4:o==="NOTICE"?r=5:o==="AUTH"&&(r=6),r===1||r===2||r===3||r===4){for(;e<s&&t[e]!==",";)e++;for(e<s&&t[e]===","&&e++;e<s&&t.charCodeAt(e)<=32;)e++;if(e<s&&t[e]==='"'){for(e++,n=e;e<s&&t[e]!=='"';)e++;const a=t.slice(n,e);return{kind:r,subId:a}}}return{kind:r,subId:null}}}class zt{constructor(t){this.connections=new Map,this.disabledRelays=new Set,this.nextAllowed=new Map,this.subCounts=new Map,this.disconnectTimers=new Map,this.cooldownMs=6e4,this.closeDelayMs=1e3,this.config={maxReconnectAttempts:2,...t}}now(){return Date.now()}detectKind(t){const e=t.match(/^\s*\[\s*"([^"]+)"/);if(!e)return"OTHER";const s=e[1].toUpperCase();return s==="REQ"?"REQ":s==="CLOSE"?"CLOSE":"OTHER"}getCount(t){return this.subCounts.get(t)??0}setCount(t,e){this.subCounts.set(t,Math.max(0,e))}cancelPendingDisconnect(t){const e=this.disconnectTimers.get(t);typeof e=="number"&&(clearTimeout(e),this.disconnectTimers.delete(t))}scheduleDisconnectIfIdle(t){if(this.disconnectTimers.has(t))return;const e=setTimeout(async()=>{this.disconnectTimers.delete(t),this.getCount(t)===0&&await this.disconnect(t)},this.closeDelayMs);this.disconnectTimers.set(t,e)}bumpCount(t,e){const s=this.getCount(t)+e;this.setCount(t,s),e>0?this.cancelPendingDisconnect(t):e<0&&this.getCount(t)===0&&this.scheduleDisconnectIfIdle(t)}giveUpOrCooldown(t,e){e?.hasGivenUp()?(this.disabledRelays.has(t)||console.warn(`[registry] disabling relay ${t}: max attempts reached`),this.disabledRelays.add(t),this.nextAllowed.set(t,this.now()+this.cooldownMs)):this.nextAllowed.set(t,this.now()+Math.min(this.cooldownMs,1e4))}isCoolingDown(t){const e=this.nextAllowed.get(t)??0;return this.now()<e}async ensureConnection(t){if(this.disabledRelays.has(t))throw new Error(`Relay disabled: ${t}`);if(this.isCoolingDown(t))throw new Error(`Relay ${t} cooling down until ${new Date(this.nextAllowed.get(t)).toISOString()}`);let e=this.connections.get(t);if(e||(e=new jt(t,this.config),this.connections.set(t,e),e.connect()),e.getStatus()!==u.Ready)try{await e.waitForReady(this.config.connectTimeoutMs??5e3)}catch(s){throw this.giveUpOrCooldown(t,e),s}if(e.getStatus()!==u.Ready)throw this.giveUpOrCooldown(t,e),new Error(`Relay ${t} not ready`);return e}async sendFrame(t,e){if(this.disabledRelays.has(t)||this.isCoolingDown(t))return;const s=this.detectKind(e),n=await this.ensureConnection(t);try{await n.sendMessage(e)}catch(o){throw this.giveUpOrCooldown(t,n),await this.disconnect(t),o}s==="REQ"?this.bumpCount(t,1):s==="CLOSE"&&this.bumpCount(t,-1)}async sendToRelays(t,e){for(const s of t)if(!(this.disabledRelays.has(s)||this.isCoolingDown(s)))try{for(const n of e)await this.sendFrame(s,n)}catch(n){console.error(`[registry] failed to send to ${s}:`,n)}}async disconnect(t){const e=this.connections.get(t);e&&(await e.close(),this.connections.delete(t)),this.cancelPendingDisconnect(t),this.subCounts.delete(t)}async disconnectAll(){for(const[t]of this.connections)await this.disconnect(t)}enableRelay(t){this.disabledRelays.delete(t),this.nextAllowed.delete(t)}isRelayDisabled(t){return this.disabledRelays.has(t)}getActiveReqCount(t){return this.getCount(t)}getConnectionStatus(t){const e=this.connections.get(t);return e?e.getStatus():void 0}getAllStatuses(){return new Map(Array.from(this.connections.entries()).map(([t,e])=>[t,e.getStatus()]))}}class Q{static initializeBuffer(t){new DataView(t).setUint32(0,4,!0)}static writeMessage(t,e){const s=new DataView(t),n=new Uint8Array(t),o=s.getUint32(0,!0),r=4+e.length;if(o+r>t.byteLength)return console.warn("Buffer full, cannot write message"),!1;s.setUint32(o,e.length,!0),n.set(e,o+4);const a=o+r;return s.setUint32(0,a,!0),!0}static writeMessageObject(t,e){try{const s=Kt(e);return this.writeMessage(t,new Uint8Array(s))}catch(s){return console.error("Failed to encode message:",s),!1}}static readMessages(t,e=0){const s=new DataView(t),n=new Uint8Array(t),o=s.getUint32(0,!0),r=4;let a=e<r?r:e;if(o<=a)return{messages:[],newReadPosition:a,hasNewData:!1};const h=128,c=new Array(h);let d=0;try{for(;a<o&&!(d>=h||a+4>o);){const f=a,w=s.getUint32(f,!0),x=f+4,W=x+w;if(W>o)break;const Y=n.subarray(x,W),p=new tt(Y),H=m.getRootAsWorkerMessage(p);c[d++]=H,a=W}return c.length=d,{messages:c,newReadPosition:a,hasNewData:d>0}}catch(f){return console.error("Failed to decode FlatBuffer data from SharedArrayBuffer:",f),c.length=d,{messages:c,newReadPosition:e<r?r: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}}let At=null,pt=null;async function qt(){return pt||(pt=fetch(Bt).then(i=>{if(!i.ok)throw new Error(`Failed to fetch WASM: ${i.status} ${i.statusText}`);return i.arrayBuffer()}).then(i=>{At=i}).catch(i=>{throw console.error("WASM fetch failed:",i),i}),pt)}class Mt{constructor(t){this.textEncoder=new TextEncoder,this.subscriptions=new Map,this.publishes=new Map,this.signers=new Map,this.signCB=e=>{},this.eventTarget=new EventTarget,this.PERPETUAL_SUBSCRIPTIONS=["notifications","starterpack"],this.worker=this.createWorker(),this.setupWorkerListener(),this.ready=(async()=>{await qt(),this.worker.postMessage({type:"init",payload:{bufferKey:t.bufferKey,maxBufferSize:t.maxBufferSize,wasmBuffer:At,inRing:t.inRing,outRing:t.outRing}})})().catch(e=>{console.error("Failed to initialize worker with WASM:",e)})}createWorker(){return new Vt}setupWorkerListener(){this.worker.onmessage=async t=>{const e=typeof t.data=="string"?t.data:void 0;try{if(t.data.startsWith('{"id":')){const s=JSON.parse(t.data);this.signCB(s)}}catch{}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.worker.onerror=t=>{console.error("Worker error:",t)}}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),o=this.subscriptions.get(n);if(o)return o.refCount++,o.buffer;const r=e.reduce((p,H)=>p+(H.limit||100),0),a=Q.calculateBufferSize(r,s.bytesPerEvent);let h=new Uint8Array;const c=new SharedArrayBuffer(a+h.length);Q.initializeBuffer(c),h.length>0&&(Q.writeMessage(c,h)||console.error("Failed to write initial message to buffer")),this.subscriptions.set(n,{buffer:c,options:s,refCount:1});const d=new dt(new bt(s.pipeline||[]),s.closeOnEose,s.cacheFirst,s.timeoutMs?BigInt(s.timeoutMs):void 0,s.maxEvents,s.skipCache,s.force,s.bytesPerEvent),f=new ut(this.textEncoder.encode(n),e.map(p=>new xt(p.ids,p.authors,p.kinds,Object.entries(p.tags||{}).flatMap(([H,Nt])=>new nt([H,...Nt])),p.limit,p.since,p.until,this.textEncoder.encode(p.search),p.relays,p.closeOnEOSE,p.cacheFirst)),d),w=new V(y.Subscribe,f),x=new R(2048),W=w.pack(x);x.finish(W);const Y=x.asUint8Array();try{return Z.resetInputLoopBackoff(),this.worker.postMessage({serializedMessage:Y,sharedBuffer:c}),c}catch(p){throw this.subscriptions.delete(n),p}}getBuffer(t){const e=this.subscriptions.get(t);if(e)return e.refCount++,e.buffer}unsubscribe(t){const e=t.length<64?t:this.createShortId(t),s=this.subscriptions.get(e);s&&s.refCount--}publish(t,e){const s=new SharedArrayBuffer(3072);Q.initializeBuffer(s);try{const n=new X(e.kind,this.textEncoder.encode(e.content),e.tags.map(d=>new nt(d))||[]),o=new ot(this.textEncoder.encode(t),n),r=new V(y.Publish,o),a=new R(2048),h=r.pack(a);a.finish(h);const c=a.asUint8Array();return Z.resetInputLoopBackoff(),this.worker.postMessage({serializedMessage:c,sharedBuffer:s}),this.publishes.set(t,{buffer:s}),s}catch(n){throw console.error("Failed to publish event:",n),n}}setSigner(t,e){this.ready.then(()=>{console.log("setSigner",t,e);const s=new at(this.textEncoder.encode(e)),n=new ct(q.PrivateKey,s),o=new V(y.SetSigner,n),r=new R(2048),a=o.pack(r);r.finish(a);const h=r.asUint8Array();this.worker.postMessage(h),this.signers.set(t,e)})}signEvent(t,e){const s=new V(y.SignEvent,new ht(new X(t.kind,this.textEncoder.encode(t.content),t.tags.map(a=>new nt(a))))),n=new R(2048),o=s.pack(n);n.finish(o);const r=n.asUint8Array();this.signCB=e,this.worker.postMessage(r)}getPublicKey(){const t=new V(y.GetPublicKey,new rt),e=new R(2048),s=t.pack(e);e.finish(s);const n=e.asUint8Array();this.worker.postMessage(n)}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)if(this.subscriptions.get(e)){const s=new V(y.Unsubscribe,new lt(this.textEncoder.encode(e))),n=new R(2048),o=s.pack(n);n.finish(o);const r=n.asUint8Array();Z.resetInputLoopBackoff(),this.worker.postMessage(r),this.subscriptions.delete(e)}}}function Dt(i,t,e,s,n){const o=new TextEncoder().encode(n),r=new R(1024),a=O.createRelayRef(r,r.createString(t)),h=e;let c=null;s&&(c=r.createString(s));const d=r.createByteVector(o);l.startWorkerLine(r),l.addRelay(r,a),l.addKind(r,h),c&&l.addSubId(r,c),l.addRaw(r,d);const f=l.endWorkerLine(r);r.finish(f);const w=new Uint8Array(r.asUint8Array());i.write(w)}class B{constructor(t,e=2){this.inRings=[],this.outRings=[],this.inputRings=[],this.outputRings=[],this.managers=[],this.lastRingIndex=0,this.inputLoopBackoffMs=B.MIN_BACKOFF_MS,this.inputLoopTimer=null,this.decoder=new TextDecoder,this.processInputLoop=()=>{let o=0;const r=this.inputRings.length;if(r===0){this.scheduleInputLoop();return}let a;do{a=!1;for(let h=0;h<r;h++){const c=(this.lastRingIndex+h)%r,d=this.inputRings[c].read();if(!d)continue;a=!0,o++;const f=this.decoder.decode(d);let w;try{w=JSON.parse(f)}catch(x){console.warn("Invalid envelope JSON:",x);continue}if(!Array.isArray(w.relays)||!Array.isArray(w.frames)){console.warn("Invalid envelope structure");continue}this.registry.sendToRelays(w.relays,w.frames).catch(console.error),this.lastRingIndex=(c+1)%r}}while(a);this.inputLoopBackoffMs=o>0?B.MIN_BACKOFF_MS:Math.min(this.inputLoopBackoffMs*B.BACKOFF_MULTIPLIER,B.MAX_BACKOFF_MS),this.scheduleInputLoop()};for(let o=0;o<e;o++)this.inRings.push(new SharedArrayBuffer(1*1024*1024)),this.outRings.push(new SharedArrayBuffer(5*1024*1024)),Et(this.inRings[o]),Et(this.outRings[o]),this.managers.push(new Mt({bufferKey:o.toString(),maxBufferSize:2e6,inRing:this.inRings[o],outRing:this.outRings[o]})),this.inputRings.push(new Ft(this.inRings[o])),this.outputRings.push(new Ft(this.outRings[o]));this.registry=new zt(t||{});const s=(o,r,a,h)=>{const c=this.outputRings[this.hashSubId(a||"")];Dt(c,o,r,a,h)},n=this.registry.ensureConnection.bind(this.registry);this.registry.ensureConnection=async o=>{const r=await n(o);return r.messageHandler||r.setMessageHandler(s),r},this.processInputLoop(),console.log("WS Manager initialized")}static{this.MIN_BACKOFF_MS=10}static{this.MAX_BACKOFF_MS=1e3}static{this.BACKOFF_MULTIPLIER=2}hashSubId(t){let e=0;for(let s=0;s<t.length;s++)e=(e<<5)-e+t.charCodeAt(s);return Math.abs(e)%this.managers.length}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)}cleanup(){for(const t of this.managers)t.cleanup()}setSigner(t,e){for(const s of this.managers)s.setSigner(t,e)}getManager(t){t=this.createShortId(t);const e=this.hashSubId(t||"");return this.managers[e]}resetInputLoopBackoff(){this.inputLoopBackoffMs=B.MIN_BACKOFF_MS,this.inputLoopTimer!==null&&(clearTimeout(this.inputLoopTimer),this.inputLoopTimer=null),this.scheduleInputLoop()}scheduleInputLoop(){const t=globalThis;typeof t.requestIdleCallback=="function"?t.requestIdleCallback(()=>this.processInputLoop(),{timeout:this.inputLoopBackoffMs}):this.inputLoopTimer=setTimeout(()=>this.processInputLoop(),this.inputLoopBackoffMs)}}const Z=new B({});export{C as A,ct as B,k as C,M as D,ht as E,q as F,K as G,P as H,ut as I,g as J,T as K,dt as L,y as M,B as N,X as O,j as P,lt as Q,O as R,z as S,_ as T,U,Ot as V,l as W,m as X,Rt as Y,Q as Z,Mt as a,gt as b,rt as c,_t as d,E as e,V as f,$ as g,S as h,wt as i,Pt as j,I as k,It as l,D as m,Z as n,v as o,bt as p,A as q,at as r,N as s,St as t,F as u,ot as v,vt as w,mt as x,L as y,kt as z};
1
+ import At from"@candypoets/rust-worker/worker.js?worker";import Mt from"@candypoets/rust-worker/rust_worker_bg.wasm?url";import{encode as jt}from"@msgpack/msgpack";import{d as Q,S as W,e as Y,F as $,f as b,g as xt,R as Lt,M as Z,h as tt,u as ut,i as Ut,j as et}from"./message-type.js";import{i as pt}from"./ring-buffer.js";class A{constructor(t){this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null,this.text_encoder=new TextEncoder;let e;t?e=t:e=1024,this.bb=Q.allocate(e),this.space=e}clear(){this.bb.clear(),this.space=this.bb.capacity(),this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null}forceDefaults(t){this.force_defaults=t}dataBuffer(){return this.bb}asUint8Array(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())}prep(t,e){t>this.minalign&&(this.minalign=t);const s=~(this.bb.capacity()-this.space+e)+1&t-1;for(;this.space<s+t+e;){const n=this.bb.capacity();this.bb=A.growByteBuffer(this.bb),this.space+=this.bb.capacity()-n}this.pad(s)}pad(t){for(let e=0;e<t;e++)this.bb.writeInt8(--this.space,0)}writeInt8(t){this.bb.writeInt8(this.space-=1,t)}writeInt16(t){this.bb.writeInt16(this.space-=2,t)}writeInt32(t){this.bb.writeInt32(this.space-=4,t)}writeInt64(t){this.bb.writeInt64(this.space-=8,t)}writeFloat32(t){this.bb.writeFloat32(this.space-=4,t)}writeFloat64(t){this.bb.writeFloat64(this.space-=8,t)}addInt8(t){this.prep(1,0),this.writeInt8(t)}addInt16(t){this.prep(2,0),this.writeInt16(t)}addInt32(t){this.prep(4,0),this.writeInt32(t)}addInt64(t){this.prep(8,0),this.writeInt64(t)}addFloat32(t){this.prep(4,0),this.writeFloat32(t)}addFloat64(t){this.prep(8,0),this.writeFloat64(t)}addFieldInt8(t,e,s){(this.force_defaults||e!=s)&&(this.addInt8(e),this.slot(t))}addFieldInt16(t,e,s){(this.force_defaults||e!=s)&&(this.addInt16(e),this.slot(t))}addFieldInt32(t,e,s){(this.force_defaults||e!=s)&&(this.addInt32(e),this.slot(t))}addFieldInt64(t,e,s){(this.force_defaults||e!==s)&&(this.addInt64(e),this.slot(t))}addFieldFloat32(t,e,s){(this.force_defaults||e!=s)&&(this.addFloat32(e),this.slot(t))}addFieldFloat64(t,e,s){(this.force_defaults||e!=s)&&(this.addFloat64(e),this.slot(t))}addFieldOffset(t,e,s){(this.force_defaults||e!=s)&&(this.addOffset(e),this.slot(t))}addFieldStruct(t,e,s){e!=s&&(this.nested(e),this.slot(t))}nested(t){if(t!=this.offset())throw new TypeError("FlatBuffers: struct must be serialized inline.")}notNested(){if(this.isNested)throw new TypeError("FlatBuffers: object serialization must not be nested.")}slot(t){this.vtable!==null&&(this.vtable[t]=this.offset())}offset(){return this.bb.capacity()-this.space}static growByteBuffer(t){const e=t.capacity();if(e&3221225472)throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");const s=e<<1,n=Q.allocate(s);return n.setPosition(s-e),n.bytes().set(t.bytes(),s-e),n}addOffset(t){this.prep(W,0),this.writeInt32(this.offset()-t+W)}startObject(t){this.notNested(),this.vtable==null&&(this.vtable=[]),this.vtable_in_use=t;for(let e=0;e<t;e++)this.vtable[e]=0;this.isNested=!0,this.object_start=this.offset()}endObject(){if(this.vtable==null||!this.isNested)throw new Error("FlatBuffers: endObject called without startObject");this.addInt32(0);const t=this.offset();let e=this.vtable_in_use-1;for(;e>=0&&this.vtable[e]==0;e--);const s=e+1;for(;e>=0;e--)this.addInt16(this.vtable[e]!=0?t-this.vtable[e]:0);const n=2;this.addInt16(t-this.object_start);const r=(s+n)*Y;this.addInt16(r);let o=0;const a=this.space;t:for(e=0;e<this.vtables.length;e++){const h=this.bb.capacity()-this.vtables[e];if(r==this.bb.readInt16(h)){for(let c=Y;c<r;c+=Y)if(this.bb.readInt16(a+c)!=this.bb.readInt16(h+c))continue t;o=this.vtables[e];break}}return o?(this.space=this.bb.capacity()-t,this.bb.writeInt32(this.space,o-t)):(this.vtables.push(this.offset()),this.bb.writeInt32(this.bb.capacity()-t,this.offset()-t)),this.isNested=!1,t}finish(t,e,s){const n=s?b:0;if(e){const r=e;if(this.prep(this.minalign,W+$+n),r.length!=$)throw new TypeError("FlatBuffers: file identifier must be length "+$);for(let o=$-1;o>=0;o--)this.writeInt8(r.charCodeAt(o))}this.prep(this.minalign,W+n),this.addOffset(t),n&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)}finishSizePrefixed(t,e){this.finish(t,e,!0)}requiredField(t,e){const s=this.bb.capacity()-t,n=s-this.bb.readInt32(s);if(!(e<this.bb.readInt16(n)&&this.bb.readInt16(n+e)!=0))throw new TypeError("FlatBuffers: field "+e+" must be set")}startVector(t,e,s){this.notNested(),this.vector_num_elems=e,this.prep(W,t*e),this.prep(s,t*e)}endVector(){return this.writeInt32(this.vector_num_elems),this.offset()}createSharedString(t){if(!t)return 0;if(this.string_maps||(this.string_maps=new Map),this.string_maps.has(t))return this.string_maps.get(t);const e=this.createString(t);return this.string_maps.set(t,e),e}createString(t){if(t==null)return 0;let e;return t instanceof Uint8Array?e=t:e=this.text_encoder.encode(t),this.addInt8(0),this.startVector(1,e.length,1),this.bb.setPosition(this.space-=e.length),this.bb.bytes().set(e,this.space),this.endVector()}createByteVector(t){return t==null?0:(this.startVector(1,t.length,1),this.bb.setPosition(this.space-=t.length),this.bb.bytes().set(t,this.space),this.endVector())}createObjectOffset(t){return t===null?0:typeof t=="string"?this.createString(t):t.pack(this)}createObjectOffsetList(t){const e=[];for(let s=0;s<t.length;++s){const n=t[s];if(n!==null)e.push(this.createObjectOffset(n));else throw new TypeError("FlatBuffers: Argument for createObjectOffsetList cannot contain null.")}return e}createStructOffsetList(t,e){return e(this,t.length),this.createObjectOffsetList(t.slice().reverse()),this.endVector()}}class w{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 w).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCounterPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new w).__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.__stringByteString(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 w.startCounterPipeConfig(t),w.addKinds(t,e),w.addPubkey(t,s),w.endCounterPipeConfig(t)}unpack(){return new lt(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 lt{constructor(t=[],e=null){this.kinds=t,this.pubkey=e}pack(t){const e=w.createKindsVector(t,this.kinds),s=this.pubkey!==null?t.createString(this.pubkey):0;return w.createCounterPipeConfig(t,e,s)}}class M{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 M).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsGetPublicKey(t,e){return t.setPosition(t.position()+b),(e||new M).__init(t.readInt32(t.position())+t.position(),t)}static startGetPublicKey(t){t.startObject(0)}static endGetPublicKey(t){return t.endObject()}static createGetPublicKey(t){return M.startGetPublicKey(t),M.endGetPublicKey(t)}unpack(){return new st}unpackTo(t){}}class st{constructor(){}pack(t){return M.createGetPublicKey(t)}}class S{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 S).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsKindFilterPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new S).__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 S.startKindFilterPipeConfig(t),S.addKinds(t,e),S.endKindFilterPipeConfig(t)}unpack(){return new ft(this.bb.createScalarList(this.kinds.bind(this),this.kindsLength()))}unpackTo(t){t.kinds=this.bb.createScalarList(this.kinds.bind(this),this.kindsLength())}}class ft{constructor(t=[]){this.kinds=t}pack(t){const e=S.createKindsVector(t,this.kinds);return S.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()+b),(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}content(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__stringByteString(this.bb_pos+e,t):null}tags(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?(e||new xt).__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,8);return t?this.bb.__vector_len(this.bb_pos+t):0}static startTemplate(t){t.startObject(3)}static addKind(t,e){t.addFieldInt16(0,e,0)}static addContent(t,e){t.addFieldOffset(1,e,0)}static addTags(t,e){t.addFieldOffset(2,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,6),t.requiredField(e,8),e}static createTemplate(t,e,s,n){return p.startTemplate(t),p.addKind(t,e),p.addContent(t,s),p.addTags(t,n),p.endTemplate(t)}unpack(){return new J(this.kind(),this.content(),this.bb.createObjList(this.tags.bind(this),this.tagsLength()))}unpackTo(t){t.kind=this.kind(),t.content=this.content(),t.tags=this.bb.createObjList(this.tags.bind(this),this.tagsLength())}}class J{constructor(t=0,e=null,s=[]){this.kind=t,this.content=e,this.tags=s}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,e,s)}}class O{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 O).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPublish(t,e){return t.setPosition(t.position()+b),(e||new O).__init(t.readInt32(t.position())+t.position(),t)}publishId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(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}static startPublish(t){t.startObject(2)}static addPublishId(t,e){t.addFieldOffset(0,e,0)}static addTemplate(t,e){t.addFieldOffset(1,e,0)}static endPublish(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),e}unpack(){return new it(this.publishId(),this.template()!==null?this.template().unpack():null)}unpackTo(t){t.publishId=this.publishId(),t.template=this.template()!==null?this.template().unpack():null}}class it{constructor(t=null,e=null){this.publishId=t,this.template=e}pack(t){const e=this.publishId!==null?t.createString(this.publishId):0,s=this.template!==null?this.template.pack(t):0;return O.startPublish(t),O.addPublishId(t,e),O.addTemplate(t,s),O.endPublish(t)}}class v{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 v).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPrivateKey(t,e){return t.setPosition(t.position()+b),(e||new v).__init(t.readInt32(t.position())+t.position(),t)}privateKey(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(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 v.startPrivateKey(t),v.addPrivateKey(t,e),v.endPrivateKey(t)}unpack(){return new nt(this.privateKey())}unpackTo(t){t.privateKey=this.privateKey()}}class nt{constructor(t=null){this.privateKey=t}pack(t){const e=this.privateKey!==null?t.createString(this.privateKey):0;return v.createPrivateKey(t,e)}}var L=(i=>(i[i.NONE=0]="NONE",i[i.PrivateKey=1]="PrivateKey",i))(L||{});function gt(i,t){switch(L[i]){case"NONE":return null;case"PrivateKey":return t(new v);default:return null}}class y{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 y).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSetSigner(t,e){return t.setPosition(t.position()+b),(e||new y).__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):L.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,L.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 y.startSetSigner(t),y.addSignerTypeType(t,e),y.addSignerType(t,s),y.endSetSigner(t)}unpack(){return new rt(this.signerTypeType(),(()=>{const t=gt(this.signerTypeType(),this.signerType.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.signerTypeType=this.signerTypeType(),t.signerType=(()=>{const e=gt(this.signerTypeType(),this.signerType.bind(this));return e===null?null:e.unpack()})()}}class rt{constructor(t=L.NONE,e=null){this.signerTypeType=t,this.signerType=e}pack(t){const e=t.createObjectOffset(this.signerType);return y.createSetSigner(t,this.signerTypeType,e)}}class T{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 T).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSignEvent(t,e){return t.setPosition(t.position()+b),(e||new T).__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 T.startSignEvent(t),T.addTemplate(t,e),T.endSignEvent(t)}unpack(){return new ot(this.template()!==null?this.template().unpack():null)}unpackTo(t){t.template=this.template()!==null?this.template().unpack():null}}class ot{constructor(t=null){this.template=t}pack(t){const e=this.template!==null?this.template.pack(t):0;return T.createSignEvent(t,e)}}class _{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 _).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsNpubLimiterPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new _).__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 _.startNpubLimiterPipeConfig(t),_.addKind(t,e),_.addLimitPerNpub(t,s),_.addMaxTotalNpubs(t,n),_.endNpubLimiterPipeConfig(t)}unpack(){return new _t(this.kind(),this.limitPerNpub(),this.maxTotalNpubs())}unpackTo(t){t.kind=this.kind(),t.limitPerNpub=this.limitPerNpub(),t.maxTotalNpubs=this.maxTotalNpubs()}}class _t{constructor(t=0,e=0,s=0){this.kind=t,this.limitPerNpub=e,this.maxTotalNpubs=s}pack(t){return _.createNpubLimiterPipeConfig(t,this.kind,this.limitPerNpub,this.maxTotalNpubs)}}class j{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 j).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsParsePipeConfig(t,e){return t.setPosition(t.position()+b),(e||new j).__init(t.readInt32(t.position())+t.position(),t)}static startParsePipeConfig(t){t.startObject(0)}static endParsePipeConfig(t){return t.endObject()}static createParsePipeConfig(t){return j.startParsePipeConfig(t),j.endParsePipeConfig(t)}unpack(){return new Pt}unpackTo(t){}}class Pt{constructor(){}pack(t){return j.createParsePipeConfig(t)}}class F{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 F).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsProofVerificationPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new F).__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 F.startProofVerificationPipeConfig(t),F.addMaxProofs(t,e),F.endProofVerificationPipeConfig(t)}unpack(){return new wt(this.maxProofs())}unpackTo(t){t.maxProofs=this.maxProofs()}}class wt{constructor(t=0){this.maxProofs=t}pack(t){return F.createProofVerificationPipeConfig(t,this.maxProofs)}}class x{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 x).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSaveToDbPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new x).__init(t.readInt32(t.position())+t.position(),t)}static startSaveToDbPipeConfig(t){t.startObject(0)}static endSaveToDbPipeConfig(t){return t.endObject()}static createSaveToDbPipeConfig(t){return x.startSaveToDbPipeConfig(t),x.endSaveToDbPipeConfig(t)}unpack(){return new yt}unpackTo(t){}}class yt{constructor(){}pack(t){return x.createSaveToDbPipeConfig(t)}}class E{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 E).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSerializeEventsPipeConfig(t,e){return t.setPosition(t.position()+b),(e||new E).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(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 E.startSerializeEventsPipeConfig(t),E.addSubscriptionId(t,e),E.endSerializeEventsPipeConfig(t)}unpack(){return new kt(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class kt{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return E.createSerializeEventsPipeConfig(t,e)}}var B=(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))(B||{});function St(i,t){switch(B[i]){case"NONE":return null;case"ParsePipeConfig":return t(new j);case"KindFilterPipeConfig":return t(new S);case"CounterPipeConfig":return t(new w);case"NpubLimiterPipeConfig":return t(new _);case"SaveToDbPipeConfig":return t(new x);case"SerializeEventsPipeConfig":return t(new E);case"ProofVerificationPipeConfig":return t(new F);default:return null}}class k{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 k).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipe(t,e){return t.setPosition(t.position()+b),(e||new k).__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):B.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,B.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 k.startPipe(t),k.addConfigType(t,e),k.addConfig(t,s),k.endPipe(t)}unpack(){return new It(this.configType(),(()=>{const t=St(this.configType(),this.config.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.configType=this.configType(),t.config=(()=>{const e=St(this.configType(),this.config.bind(this));return e===null?null:e.unpack()})()}}class It{constructor(t=B.NONE,e=null){this.configType=t,this.config=e}pack(t){const e=t.createObjectOffset(this.config);return k.createPipe(t,this.configType,e)}}class I{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 I).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsPipelineConfig(t,e){return t.setPosition(t.position()+b),(e||new I).__init(t.readInt32(t.position())+t.position(),t)}pipes(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?(e||new k).__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 I.startPipelineConfig(t),I.addPipes(t,e),I.endPipelineConfig(t)}unpack(){return new at(this.bb.createObjList(this.pipes.bind(this),this.pipesLength()))}unpackTo(t){t.pipes=this.bb.createObjList(this.pipes.bind(this),this.pipesLength())}}class at{constructor(t=[]){this.pipes=t}pack(t){const e=I.createPipesVector(t,t.createObjectOffsetList(this.pipes));return I.createPipelineConfig(t,e)}}class u{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 u).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscriptionConfig(t,e){return t.setPosition(t.position()+b),(e||new u).__init(t.readInt32(t.position())+t.position(),t)}pipeline(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new I).__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}static startSubscriptionConfig(t){t.startObject(8)}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 endSubscriptionConfig(t){return t.endObject()}static createSubscriptionConfig(t,e,s,n,r,o,a,h,c){return u.startSubscriptionConfig(t),u.addPipeline(t,e),u.addCloseOnEose(t,s),u.addCacheFirst(t,n),u.addTimeoutMs(t,r),u.addMaxEvents(t,o),u.addSkipCache(t,a),u.addForce(t,h),u.addBytesPerEvent(t,c),u.endSubscriptionConfig(t)}unpack(){return new ct(this.pipeline()!==null?this.pipeline().unpack():null,this.closeOnEose(),this.cacheFirst(),this.timeoutMs(),this.maxEvents(),this.skipCache(),this.force(),this.bytesPerEvent())}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()}}class ct{constructor(t=null,e=!1,s=!0,n=BigInt("0"),r=0,o=!1,a=!1,h=0){this.pipeline=t,this.closeOnEose=e,this.cacheFirst=s,this.timeoutMs=n,this.maxEvents=r,this.skipCache=o,this.force=a,this.bytesPerEvent=h}pack(t){const e=this.pipeline!==null?this.pipeline.pack(t):0;return u.createSubscriptionConfig(t,e,this.closeOnEose,this.cacheFirst,this.timeoutMs,this.maxEvents,this.skipCache,this.force,this.bytesPerEvent)}}class g{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 g).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSubscribe(t,e){return t.setPosition(t.position()+b),(e||new g).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(this.bb_pos+e,t):null}requests(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new Lt).__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 u).__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 bt(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 bt{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=g.createRequestsVector(t,t.createObjectOffsetList(this.requests)),n=this.config!==null?this.config.pack(t):0;return g.startSubscribe(t),g.addSubscriptionId(t,e),g.addRequests(t,s),g.addConfig(t,n),g.endSubscribe(t)}}class K{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 K).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsUnsubscribe(t,e){return t.setPosition(t.position()+b),(e||new K).__init(t.readInt32(t.position())+t.position(),t)}subscriptionId(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(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 K.startUnsubscribe(t),K.addSubscriptionId(t,e),K.endUnsubscribe(t)}unpack(){return new ht(this.subscriptionId())}unpackTo(t){t.subscriptionId=this.subscriptionId()}}class ht{constructor(t=null){this.subscriptionId=t}pack(t){const e=this.subscriptionId!==null?t.createString(this.subscriptionId):0;return K.createUnsubscribe(t,e)}}var l=(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))(l||{});function Ct(i,t){switch(l[i]){case"NONE":return null;case"Subscribe":return t(new g);case"Unsubscribe":return t(new K);case"Publish":return t(new O);case"SignEvent":return t(new T);case"SetSigner":return t(new y);case"GetPublicKey":return t(new M);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()+b),(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):l.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,l.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 N(this.contentType(),(()=>{const t=Ct(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.contentType=this.contentType(),t.content=(()=>{const e=Ct(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class N{constructor(t=l.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 D=(i=>(i[i.Unknown=0]="Unknown",i[i.Event=1]="Event",i[i.Eose=2]="Eose",i[i.Ok=3]="Ok",i[i.Closed=4]="Closed",i[i.Notice=5]="Notice",i[i.Auth=6]="Auth",i))(D||{}),Ot=(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.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.Kind39089Parsed=39089]="Kind39089Parsed",i))(Ot||{});class R{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsRelayRef(t,e){return(e||new R).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsRelayRef(t,e){return t.setPosition(t.position()+b),(e||new R).__init(t.readInt32(t.position())+t.position(),t)}url(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__stringByteString(this.bb_pos+e,t):null}static startRelayRef(t){t.startObject(1)}static addUrl(t,e){t.addFieldOffset(0,e,0)}static endRelayRef(t){const e=t.endObject();return t.requiredField(e,4),e}static createRelayRef(t,e){return R.startRelayRef(t),R.addUrl(t,e),R.endRelayRef(t)}unpack(){return new mt(this.url())}unpackTo(t){t.url=this.url()}}class mt{constructor(t=null){this.url=t}pack(t){const e=this.url!==null?t.createString(this.url):0;return R.createRelayRef(t,e)}}var vt=(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))(vt||{});class f{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsWorkerLine(t,e){return(e||new f).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsWorkerLine(t,e){return t.setPosition(t.position()+b),(e||new f).__init(t.readInt32(t.position())+t.position(),t)}relay(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}kind(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readInt16(this.bb_pos+t):D.Unknown}subId(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__stringByteString(this.bb_pos+e,t):null}raw(t){const e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readUint8(this.bb.__vector(this.bb_pos+e)+t):0}rawLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}rawArray(){const t=this.bb.__offset(this.bb_pos,10);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 startWorkerLine(t){t.startObject(4)}static addRelay(t,e){t.addFieldOffset(0,e,0)}static addKind(t,e){t.addFieldInt16(1,e,D.Unknown)}static addSubId(t,e){t.addFieldOffset(2,e,0)}static addRaw(t,e){t.addFieldOffset(3,e,0)}static createRawVector(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 startRawVector(t,e){t.startVector(1,e,1)}static endWorkerLine(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,10),e}static createWorkerLine(t,e,s,n,r){return f.startWorkerLine(t),f.addRelay(t,e),f.addKind(t,s),f.addSubId(t,n),f.addRaw(t,r),f.endWorkerLine(t)}unpack(){return new Tt(this.relay()!==null?this.relay().unpack():null,this.kind(),this.subId(),this.bb.createScalarList(this.raw.bind(this),this.rawLength()))}unpackTo(t){t.relay=this.relay()!==null?this.relay().unpack():null,t.kind=this.kind(),t.subId=this.subId(),t.raw=this.bb.createScalarList(this.raw.bind(this),this.rawLength())}}class Tt{constructor(t=null,e=D.Unknown,s=null,n=[]){this.relay=t,this.kind=e,this.subId=s,this.raw=n}pack(t){const e=this.relay!==null?this.relay.pack(t):0,s=this.subId!==null?t.createString(this.subId):0,n=f.createRawVector(t,this.raw);return f.createWorkerLine(t,e,this.kind,s,n)}}class P{constructor(){this.bb=null,this.bb_pos=0}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsWorkerMessage(t,e){return(e||new P).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsWorkerMessage(t,e){return t.setPosition(t.position()+b),(e||new P).__init(t.readInt32(t.position())+t.position(),t)}type(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint32(this.bb_pos+t):Z.ParsedNostrEvent}contentType(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readUint8(this.bb_pos+t):tt.NONE}content(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__union(t,this.bb_pos+e):null}static startWorkerMessage(t){t.startObject(3)}static addType(t,e){t.addFieldInt32(0,e,Z.ParsedNostrEvent)}static addContentType(t,e){t.addFieldInt8(1,e,tt.NONE)}static addContent(t,e){t.addFieldOffset(2,e,0)}static endWorkerMessage(t){return t.endObject()}static finishWorkerMessageBuffer(t,e){t.finish(e)}static finishSizePrefixedWorkerMessageBuffer(t,e){t.finish(e,void 0,!0)}static createWorkerMessage(t,e,s,n){return P.startWorkerMessage(t),P.addType(t,e),P.addContentType(t,s),P.addContent(t,n),P.endWorkerMessage(t)}unpack(){return new Ft(this.type(),this.contentType(),(()=>{const t=ut(this.contentType(),this.content.bind(this));return t===null?null:t.unpack()})())}unpackTo(t){t.type=this.type(),t.contentType=this.contentType(),t.content=(()=>{const e=ut(this.contentType(),this.content.bind(this));return e===null?null:e.unpack()})()}}class Ft{constructor(t=Z.ParsedNostrEvent,e=tt.NONE,s=null){this.type=t,this.contentType=e,this.content=s}pack(t){const e=t.createObjectOffset(this.content);return P.createWorkerMessage(t,this.type,this.contentType,e)}}class G{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 writeMessageObject(t,e){try{const s=jt(e);return this.writeMessage(t,new Uint8Array(s))}catch(s){return console.error("Failed to encode message:",s),!1}}static readMessages(t,e=0){const s=new DataView(t),n=new Uint8Array(t),r=s.getUint32(0,!0),o=4;let a=e<o?o:e;if(r<=a)return{messages:[],newReadPosition:a,hasNewData:!1};const h=128,c=new Array(h);let C=0;try{for(;a<r&&!(C>=h||a+4>r);){const U=a,X=s.getUint32(U,!0),V=U+4,z=V+X;if(z>r)break;const H=n.subarray(V,z),d=new Q(H),q=P.getRootAsWorkerMessage(d);c[C++]=q,a=z}return c.length=C,{messages:c,newReadPosition:a,hasNewData:C>0}}catch(U){return console.error("Failed to decode FlatBuffer data from SharedArrayBuffer:",U),c.length=C,{messages:c,newReadPosition:e<o?o: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}}let Et=null,dt=null;async function Vt(){return dt||(dt=fetch(Mt).then(i=>{if(!i.ok)throw new Error(`Failed to fetch WASM: ${i.status} ${i.statusText}`);return i.arrayBuffer()}).then(i=>{Et=i}).catch(i=>{throw console.error("WASM fetch failed:",i),i}),dt)}class Kt{constructor(t){this.textEncoder=new TextEncoder,this.subscriptions=new Map,this.publishes=new Map,this.signers=new Map,this.signCB=s=>{},this.eventTarget=new EventTarget,this.PERPETUAL_SUBSCRIPTIONS=["notifications","starterpack"],this._ready=null,this.config=t;const e=()=>void this.init();"requestIdleCallback"in window?window.requestIdleCallback(e,{timeout:2e3}):setTimeout(e,1500)}init(){return this._ready?this._ready:(this.worker=this.createWorker(),this.setupWorkerListener(),this._ready=(async()=>{await Vt();const t=Et.slice(0);this.worker.postMessage({type:"init",payload:{bufferKey:this.config.bufferKey,maxBufferSize:this.config.maxBufferSize,wasmBuffer:t,inRing:this.config.inRing,outRing:this.config.outRing}},[t])})(),this._ready)}postToWorker(t,e){return this.init().then(()=>{e&&e.length?this.worker.postMessage(t,e):this.worker.postMessage(t)})}createWorker(){return new At}setupWorkerListener(){this.worker.onmessage=async t=>{const e=typeof t.data=="string"?t.data:void 0;try{if(t.data.startsWith('{"id":')){const s=JSON.parse(t.data);this.signCB(s)}}catch{}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.worker.onerror=t=>{console.error("Worker error:",t)}}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,q)=>d+(q.limit||100),0),a=G.calculateBufferSize(o,s.bytesPerEvent);let h=new Uint8Array;const c=new SharedArrayBuffer(a+h.length);G.initializeBuffer(c),h.length>0&&(G.writeMessage(c,h)||console.error("Failed to write initial message to buffer")),this.subscriptions.set(n,{buffer:c,options:s,refCount:1});const C=new ct(new at(s.pipeline||[]),s.closeOnEose,s.cacheFirst,s.timeoutMs?BigInt(s.timeoutMs):void 0,s.maxEvents,s.skipCache,s.force,s.bytesPerEvent),U=new bt(this.textEncoder.encode(n),e.map(d=>new Ut(d.ids,d.authors,d.kinds,Object.entries(d.tags||{}).flatMap(([q,Nt])=>new et([q,...Nt])),d.limit,d.since,d.until,this.textEncoder.encode(d.search),d.relays,d.closeOnEOSE,d.cacheFirst)),C),X=new N(l.Subscribe,U),V=new A(2048),z=X.pack(V);V.finish(z);const H=V.asUint8Array();try{return this.postToWorker({serializedMessage:H,sharedBuffer:c}),c}catch(d){throw this.subscriptions.delete(n),d}}getBuffer(t){const e=this.subscriptions.get(t);if(e)return e.refCount++,e.buffer}unsubscribe(t){const e=t.length<64?t:this.createShortId(t),s=this.subscriptions.get(e);s&&s.refCount--}publish(t,e){const s=new SharedArrayBuffer(3072);G.initializeBuffer(s);try{const n=new J(e.kind,this.textEncoder.encode(e.content),e.tags.map(C=>new et(C))||[]),r=new it(this.textEncoder.encode(t),n),o=new N(l.Publish,r),a=new A(2048),h=o.pack(a);a.finish(h);const c=a.asUint8Array();return this.postToWorker({serializedMessage:c,sharedBuffer:s}),this.publishes.set(t,{buffer:s}),s}catch(n){throw console.error("Failed to publish event:",n),n}}setSigner(t,e){console.log("setSigner",t,e);const s=new nt(this.textEncoder.encode(e)),n=new rt(L.PrivateKey,s),r=new N(l.SetSigner,n),o=new A(2048),a=r.pack(o);o.finish(a);const h=o.asUint8Array();this.postToWorker(h),this.signers.set(t,e)}signEvent(t,e){const s=new N(l.SignEvent,new ot(new J(t.kind,this.textEncoder.encode(t.content),t.tags.map(a=>new et(a))))),n=new A(2048),r=s.pack(n);n.finish(r);const o=n.asUint8Array();this.signCB=e,this.worker.postMessage(o)}getPublicKey(){const t=new N(l.GetPublicKey,new st),e=new A(2048),s=t.pack(e);e.finish(s);const n=e.asUint8Array();this.worker.postMessage(n)}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)if(this.subscriptions.get(e)){const s=new N(l.Unsubscribe,new ht(this.textEncoder.encode(e))),n=new A(2048),r=s.pack(n);n.finish(r);const o=n.asUint8Array();this.worker.postMessage(o),this.subscriptions.delete(e)}}}class Rt{constructor(t={},e=2){this.inRings=[],this.outRings=[],this.managers=[];for(let n=0;n<e;n++){const r=new SharedArrayBuffer(1048576),o=new SharedArrayBuffer(5*1024*1024);pt(r),pt(o),this.inRings.push(r),this.outRings.push(o),this.managers.push(new Kt({bufferKey:n.toString(),maxBufferSize:2e6,inRing:r,outRing:o}))}const s=new URL("./ws/index.js",import.meta.url);this.worker=new Worker(s,{type:"module"}),this.worker.onerror=n=>{console.error("WS Worker error:",n)},console.log("ok",s,this.worker),this.worker.postMessage({type:"init",payload:{inRings:this.inRings,outRings:this.outRings,relayConfig:t}})}hashSubId(t){const e=t.includes("_")?t.split("_")[1]??"":t;let s=0;for(let n=0;n<e.length;n++)s=(s<<5)-s+e.charCodeAt(n);return Math.abs(s)%this.managers.length}createShortId(t){const e=(s,n)=>{let r=0;for(let o=0;o<s.length;o++){const a=s.charCodeAt(o);r=(r<<5)-r+a,r=r&r}return Math.abs(r).toString(36).substring(0,Math.max(1,n))};if(t.includes("_")){const[s,...n]=t.split("_"),r=n.join("_"),o=Math.max(1,Math.floor(62/2)),a=e(s??"",o),h=e(r??"",o),c=`${a}_${h}`;return c.length>63?c.substring(0,63):c}return t.length<64?t:e(t,63)}cleanup(){for(const t of this.managers)t.cleanup()}setSigner(t,e){for(const s of this.managers)s.setSigner(t,e)}getManager(t){if(t?.length>64)throw new Error("subId cannot exceed 64 characters");const e=this.hashSubId(t||"");return this.managers[e]}resetInputLoopBackoff(){this.worker.postMessage({type:"wake"})}}const Bt=new Rt({});export{Ft as $,E as A,kt as B,w as C,y as D,rt as E,T as F,M as G,ot as H,L as I,g as J,S as K,bt as L,l as M,Rt as N,vt as O,j as P,u as Q,R,G as S,ct as T,p as U,J as V,K as W,ht as X,f as Y,Tt as Z,P as _,Kt as a,lt as b,st as c,ft as d,m as e,N as f,D as g,_ as h,_t as i,Pt as j,Ot as k,k as l,It as m,Bt as n,B as o,I as p,at as q,v as r,nt as s,F as t,wt as u,O as v,it as w,mt as x,x as y,yt as z};