@openclaw/nostr 2026.7.2-beta.7 → 2026.7.34
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.
- package/dist/{channel-O6-jXoT5.js → .setup/channel-B4SX7Iq6.mjs} +554 -877
- package/dist/{config-schema-CelPzg1N.js → .setup/config-schema-DIiXiBKr.mjs} +1 -1
- package/dist/.setup/inbound-direct-dm-runtime-EdLLVtkh.mjs +2 -0
- package/dist/{setup-adapter-BjKmSwdW.js → .setup/setup-adapter-DEU3o8MF.mjs} +1 -31
- package/dist/.setup/setup-plugin-api-DzlCumkz.mjs +2 -0
- package/dist/.setup/setup-plugin-api-csfJrRxD.mjs +111 -0
- package/dist/{setup-surface-BJCFpe02.js → .setup/setup-surface-DWa6-9ku.mjs} +70 -41
- package/dist/api.js +72 -61
- package/dist/channel-plugin-api.js +1 -1
- package/dist/doctor-contract-api.js +3 -2
- package/dist/setup-api.js +1 -1
- package/dist/setup-entry.js +2 -1
- package/dist/setup-plugin-api.js +1 -112
- package/node_modules/nostr-tools/lib/cjs/abstract-pool.js +28 -59
- package/node_modules/nostr-tools/lib/cjs/abstract-pool.js.map +3 -3
- package/node_modules/nostr-tools/lib/cjs/abstract-relay.js +7 -44
- package/node_modules/nostr-tools/lib/cjs/abstract-relay.js.map +2 -2
- package/node_modules/nostr-tools/lib/cjs/core.js +1 -17
- package/node_modules/nostr-tools/lib/cjs/core.js.map +3 -3
- package/node_modules/nostr-tools/lib/cjs/filter.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/index.js +130 -172
- package/node_modules/nostr-tools/lib/cjs/index.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/kinds.js +1 -17
- package/node_modules/nostr-tools/lib/cjs/kinds.js.map +3 -3
- package/node_modules/nostr-tools/lib/cjs/nip04.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/nip10.js +5 -20
- package/node_modules/nostr-tools/lib/cjs/nip10.js.map +3 -3
- package/node_modules/nostr-tools/lib/cjs/nip13.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/nip17.js +23 -30
- package/node_modules/nostr-tools/lib/cjs/nip17.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nip18.js +14 -21
- package/node_modules/nostr-tools/lib/cjs/nip18.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nip19.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/nip21.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/nip22.js +7 -22
- package/node_modules/nostr-tools/lib/cjs/nip22.js.map +3 -3
- package/node_modules/nostr-tools/lib/cjs/nip25.js +14 -21
- package/node_modules/nostr-tools/lib/cjs/nip25.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nip27.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/nip28.js +14 -21
- package/node_modules/nostr-tools/lib/cjs/nip28.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nip29.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/nip30.js.map +2 -2
- package/node_modules/nostr-tools/lib/cjs/nip42.js.map +2 -2
- package/node_modules/nostr-tools/lib/cjs/nip44.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/nip45.js +9 -22
- package/node_modules/nostr-tools/lib/cjs/nip45.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nip46.js +70 -111
- package/node_modules/nostr-tools/lib/cjs/nip46.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nip47.js +18 -25
- package/node_modules/nostr-tools/lib/cjs/nip47.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nip57.js +16 -23
- package/node_modules/nostr-tools/lib/cjs/nip57.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nip58.js.map +2 -2
- package/node_modules/nostr-tools/lib/cjs/nip59.js +7 -16
- package/node_modules/nostr-tools/lib/cjs/nip59.js.map +3 -3
- package/node_modules/nostr-tools/lib/cjs/nip75.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/nip94.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/nip98.js +16 -23
- package/node_modules/nostr-tools/lib/cjs/nip98.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nip99.js.map +2 -2
- package/node_modules/nostr-tools/lib/cjs/nipb0.js +17 -38
- package/node_modules/nostr-tools/lib/cjs/nipb0.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/nipb7.js +7 -13
- package/node_modules/nostr-tools/lib/cjs/nipb7.js.map +2 -2
- package/node_modules/nostr-tools/lib/cjs/pool.js +61 -102
- package/node_modules/nostr-tools/lib/cjs/pool.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/pure.js +14 -21
- package/node_modules/nostr-tools/lib/cjs/pure.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/references.js.map +1 -1
- package/node_modules/nostr-tools/lib/cjs/relay.js +42 -86
- package/node_modules/nostr-tools/lib/cjs/relay.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/signer.js +14 -21
- package/node_modules/nostr-tools/lib/cjs/signer.js.map +4 -4
- package/node_modules/nostr-tools/lib/cjs/utils.js +0 -10
- package/node_modules/nostr-tools/lib/cjs/utils.js.map +2 -2
- package/node_modules/nostr-tools/lib/cjs/wasm.js +2 -16
- package/node_modules/nostr-tools/lib/cjs/wasm.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/abstract-pool.js +28 -59
- package/node_modules/nostr-tools/lib/esm/abstract-pool.js.map +3 -3
- package/node_modules/nostr-tools/lib/esm/abstract-relay.js +7 -44
- package/node_modules/nostr-tools/lib/esm/abstract-relay.js.map +2 -2
- package/node_modules/nostr-tools/lib/esm/core.js +1 -15
- package/node_modules/nostr-tools/lib/esm/core.js.map +3 -3
- package/node_modules/nostr-tools/lib/esm/filter.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/index.js +80 -122
- package/node_modules/nostr-tools/lib/esm/index.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/kinds.js +1 -17
- package/node_modules/nostr-tools/lib/esm/kinds.js.map +3 -3
- package/node_modules/nostr-tools/lib/esm/nip04.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/nip10.js +5 -18
- package/node_modules/nostr-tools/lib/esm/nip10.js.map +3 -3
- package/node_modules/nostr-tools/lib/esm/nip13.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/nip17.js +8 -15
- package/node_modules/nostr-tools/lib/esm/nip17.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nip18.js +8 -15
- package/node_modules/nostr-tools/lib/esm/nip18.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nip19.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/nip21.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/nip22.js +7 -20
- package/node_modules/nostr-tools/lib/esm/nip22.js.map +3 -3
- package/node_modules/nostr-tools/lib/esm/nip25.js +8 -15
- package/node_modules/nostr-tools/lib/esm/nip25.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nip27.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/nip28.js +8 -15
- package/node_modules/nostr-tools/lib/esm/nip28.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nip29.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/nip30.js.map +2 -2
- package/node_modules/nostr-tools/lib/esm/nip42.js.map +2 -2
- package/node_modules/nostr-tools/lib/esm/nip44.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/nip45.js +10 -23
- package/node_modules/nostr-tools/lib/esm/nip45.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nip46.js +54 -95
- package/node_modules/nostr-tools/lib/esm/nip46.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nip47.js +8 -15
- package/node_modules/nostr-tools/lib/esm/nip47.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nip57.js +10 -17
- package/node_modules/nostr-tools/lib/esm/nip57.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nip58.js.map +2 -2
- package/node_modules/nostr-tools/lib/esm/nip59.js +1 -10
- package/node_modules/nostr-tools/lib/esm/nip59.js.map +3 -3
- package/node_modules/nostr-tools/lib/esm/nip75.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/nip94.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/nip98.js +8 -15
- package/node_modules/nostr-tools/lib/esm/nip98.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nip99.js.map +2 -2
- package/node_modules/nostr-tools/lib/esm/nipb0.js +18 -39
- package/node_modules/nostr-tools/lib/esm/nipb0.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/nipb7.js +7 -13
- package/node_modules/nostr-tools/lib/esm/nipb7.js.map +2 -2
- package/node_modules/nostr-tools/lib/esm/pool.js +54 -95
- package/node_modules/nostr-tools/lib/esm/pool.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/pure.js +8 -15
- package/node_modules/nostr-tools/lib/esm/pure.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/references.js.map +1 -1
- package/node_modules/nostr-tools/lib/esm/relay.js +36 -80
- package/node_modules/nostr-tools/lib/esm/relay.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/signer.js +8 -15
- package/node_modules/nostr-tools/lib/esm/signer.js.map +4 -4
- package/node_modules/nostr-tools/lib/esm/utils.js +0 -10
- package/node_modules/nostr-tools/lib/esm/utils.js.map +2 -2
- package/node_modules/nostr-tools/lib/esm/wasm.js +3 -17
- package/node_modules/nostr-tools/lib/esm/wasm.js.map +4 -4
- package/node_modules/nostr-tools/lib/nostr.bundle.js +77 -121
- package/node_modules/nostr-tools/lib/nostr.bundle.js.map +4 -4
- package/node_modules/nostr-tools/lib/types/abstract-pool.d.ts +4 -7
- package/node_modules/nostr-tools/lib/types/abstract-relay.d.ts +2 -7
- package/node_modules/nostr-tools/lib/types/helpers.d.ts +2 -0
- package/node_modules/nostr-tools/lib/types/kinds.d.ts +0 -2
- package/node_modules/nostr-tools/lib/types/nipb0.d.ts +1 -0
- package/node_modules/nostr-tools/lib/types/nipb7.d.ts +1 -0
- package/node_modules/nostr-tools/lib/types/relay.d.ts +2 -2
- package/node_modules/nostr-tools/lib/types/utils.d.ts +0 -4
- package/node_modules/nostr-tools/package.json +1 -1
- package/openclaw.plugin.json +5 -0
- package/package.json +15 -41
- package/dist/inbound-direct-dm-runtime-DHn9NoYN.js +0 -2
- package/node_modules/nostr-tools/lib/types/nipb0.test.d.ts +0 -1
- /package/dist/{state-account-id-CvBZ9s6P.js → .setup/state-account-id-CvBZ9s6P.mjs} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../wasm.ts", "../../
|
|
4
|
-
"sourcesContent": ["import { bytesToHex } from '@noble/hashes/utils.js'\nimport { Nostr as NostrWasm } from 'nostr-wasm'\nimport { EventTemplate, Event, Nostr, VerifiedEvent, verifiedSymbol } from './core.ts'\n\nlet nw: NostrWasm\n\nexport function setNostrWasm(x: NostrWasm) {\n nw = x\n}\n\nclass Wasm implements Nostr {\n generateSecretKey(): Uint8Array {\n return nw.generateSecretKey()\n }\n getPublicKey(secretKey: Uint8Array): string {\n return bytesToHex(nw.getPublicKey(secretKey))\n }\n finalizeEvent(t: EventTemplate, secretKey: Uint8Array): VerifiedEvent {\n nw.finalizeEvent(t as any, secretKey)\n return t as VerifiedEvent\n }\n verifyEvent(event: Event): event is VerifiedEvent {\n try {\n nw.verifyEvent(event)\n event[verifiedSymbol] = true\n return true\n } catch (err) {\n return false\n }\n }\n}\n\nconst i: Wasm = new Wasm()\nexport const generateSecretKey = i.generateSecretKey\nexport const getPublicKey = i.getPublicKey\nexport const finalizeEvent = i.finalizeEvent\nexport const verifyEvent = i.verifyEvent\nexport * from './core.ts'\n", "
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../wasm.ts", "../../core.ts"],
|
|
4
|
+
"sourcesContent": ["import { bytesToHex } from '@noble/hashes/utils.js'\nimport { Nostr as NostrWasm } from 'nostr-wasm'\nimport { EventTemplate, Event, Nostr, VerifiedEvent, verifiedSymbol } from './core.ts'\n\nlet nw: NostrWasm\n\nexport function setNostrWasm(x: NostrWasm) {\n nw = x\n}\n\nclass Wasm implements Nostr {\n generateSecretKey(): Uint8Array {\n return nw.generateSecretKey()\n }\n getPublicKey(secretKey: Uint8Array): string {\n return bytesToHex(nw.getPublicKey(secretKey))\n }\n finalizeEvent(t: EventTemplate, secretKey: Uint8Array): VerifiedEvent {\n nw.finalizeEvent(t as any, secretKey)\n return t as VerifiedEvent\n }\n verifyEvent(event: Event): event is VerifiedEvent {\n try {\n nw.verifyEvent(event)\n event[verifiedSymbol] = true\n return true\n } catch (err) {\n return false\n }\n }\n}\n\nconst i: Wasm = new Wasm()\nexport const generateSecretKey = i.generateSecretKey\nexport const getPublicKey = i.getPublicKey\nexport const finalizeEvent = i.finalizeEvent\nexport const verifyEvent = i.verifyEvent\nexport * from './core.ts'\n", "export interface Nostr {\n generateSecretKey(): Uint8Array\n getPublicKey(secretKey: Uint8Array): string\n finalizeEvent(event: EventTemplate, secretKey: Uint8Array): VerifiedEvent\n verifyEvent(event: Event): event is VerifiedEvent\n}\n\n/** Designates a verified event signature. */\nexport const verifiedSymbol = Symbol('verified')\n\nexport type NostrEvent = {\n kind: number\n tags: string[][]\n content: string\n created_at: number\n pubkey: string\n id: string\n sig: string\n [verifiedSymbol]?: boolean\n}\n\nexport type Event = NostrEvent\nexport type EventTemplate = Pick<Event, 'kind' | 'tags' | 'content' | 'created_at'>\nexport type UnsignedEvent = Pick<Event, 'kind' | 'tags' | 'content' | 'created_at' | 'pubkey'>\n\n/** An event whose signature has been verified. */\nexport interface VerifiedEvent extends Event {\n [verifiedSymbol]: true\n}\n\nconst isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceof Object\n\nexport function validateEvent<T>(event: T): event is T & UnsignedEvent {\n if (!isRecord(event)) return false\n if (typeof event.kind !== 'number') return false\n if (typeof event.content !== 'string') return false\n if (typeof event.created_at !== 'number') return false\n if (typeof event.pubkey !== 'string') return false\n if (!event.pubkey.match(/^[a-f0-9]{64}$/)) return false\n\n if (!Array.isArray(event.tags)) return false\n for (let i = 0; i < event.tags.length; i++) {\n let tag = event.tags[i]\n if (!Array.isArray(tag)) return false\n for (let j = 0; j < tag.length; j++) {\n if (typeof tag[j] !== 'string') return false\n }\n }\n\n return true\n}\n\n/**\n * Sort events in reverse-chronological order by the `created_at` timestamp,\n * and then by the event `id` (lexicographically) in case of ties.\n * This mutates the array.\n */\nexport function sortEvents(events: Event[]): Event[] {\n return events.sort((a: NostrEvent, b: NostrEvent): number => {\n if (a.created_at !== b.created_at) {\n return b.created_at - a.created_at\n }\n return a.id.localeCompare(b.id)\n })\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2B;;;ACQpB,IAAM,iBAAiB,OAAO,UAAU;AAsB/C,IAAM,WAAW,CAAC,QAAiD,eAAe;AAE3E,SAAS,cAAiB,OAAsC;AACrE,MAAI,CAAC,SAAS,KAAK;AAAG,WAAO;AAC7B,MAAI,OAAO,MAAM,SAAS;AAAU,WAAO;AAC3C,MAAI,OAAO,MAAM,YAAY;AAAU,WAAO;AAC9C,MAAI,OAAO,MAAM,eAAe;AAAU,WAAO;AACjD,MAAI,OAAO,MAAM,WAAW;AAAU,WAAO;AAC7C,MAAI,CAAC,MAAM,OAAO,MAAM,gBAAgB;AAAG,WAAO;AAElD,MAAI,CAAC,MAAM,QAAQ,MAAM,IAAI;AAAG,WAAO;AACvC,WAASA,KAAI,GAAGA,KAAI,MAAM,KAAK,QAAQA,MAAK;AAC1C,QAAI,MAAM,MAAM,KAAKA;AACrB,QAAI,CAAC,MAAM,QAAQ,GAAG;AAAG,aAAO;AAChC,aAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,UAAI,OAAO,IAAI,OAAO;AAAU,eAAO;AAAA,IACzC;AAAA,EACF;AAEA,SAAO;AACT;AAOO,SAAS,WAAW,QAA0B;AACnD,SAAO,OAAO,KAAK,CAAC,GAAe,MAA0B;AAC3D,QAAI,EAAE,eAAe,EAAE,YAAY;AACjC,aAAO,EAAE,aAAa,EAAE;AAAA,IAC1B;AACA,WAAO,EAAE,GAAG,cAAc,EAAE,EAAE;AAAA,EAChC,CAAC;AACH;;;AD5DA,IAAI;AAEG,SAAS,aAAa,GAAc;AACzC,OAAK;AACP;AAEA,IAAM,OAAN,MAA4B;AAAA,EAC1B,oBAAgC;AAC9B,WAAO,GAAG,kBAAkB;AAAA,EAC9B;AAAA,EACA,aAAa,WAA+B;AAC1C,eAAO,yBAAW,GAAG,aAAa,SAAS,CAAC;AAAA,EAC9C;AAAA,EACA,cAAc,GAAkB,WAAsC;AACpE,OAAG,cAAc,GAAU,SAAS;AACpC,WAAO;AAAA,EACT;AAAA,EACA,YAAY,OAAsC;AAChD,QAAI;AACF,SAAG,YAAY,KAAK;AACpB,YAAM,kBAAkB;AACxB,aAAO;AAAA,IACT,SAAS,KAAP;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,IAAM,IAAU,IAAI,KAAK;AAClB,IAAM,oBAAoB,EAAE;AAC5B,IAAM,eAAe,EAAE;AACvB,IAAM,gBAAgB,EAAE;AACxB,IAAM,cAAc,EAAE;",
|
|
6
|
+
"names": ["i"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// core.ts
|
|
2
|
+
var verifiedSymbol = Symbol("verified");
|
|
3
|
+
|
|
1
4
|
// utils.ts
|
|
2
5
|
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
3
6
|
var utf8Decoder = new TextDecoder("utf-8");
|
|
@@ -117,14 +120,12 @@ var AbstractRelay = class {
|
|
|
117
120
|
openSubs = /* @__PURE__ */ new Map();
|
|
118
121
|
enablePing;
|
|
119
122
|
enableReconnect;
|
|
120
|
-
idleTimeout = 0;
|
|
121
123
|
idleSince = Date.now();
|
|
122
124
|
ongoingOperations = 0;
|
|
123
125
|
reconnectTimeoutHandle;
|
|
124
126
|
pingIntervalHandle;
|
|
125
127
|
reconnectAttempts = 0;
|
|
126
128
|
skipReconnection = false;
|
|
127
|
-
idleTimeoutHandle;
|
|
128
129
|
connectionPromise;
|
|
129
130
|
openCountRequests = /* @__PURE__ */ new Map();
|
|
130
131
|
openEventPublishes = /* @__PURE__ */ new Map();
|
|
@@ -140,8 +141,6 @@ var AbstractRelay = class {
|
|
|
140
141
|
this._WebSocket = opts.websocketImplementation || WebSocket;
|
|
141
142
|
this.enablePing = opts.enablePing;
|
|
142
143
|
this.enableReconnect = opts.enableReconnect || false;
|
|
143
|
-
if (opts.idleTimeout)
|
|
144
|
-
this.idleTimeout = opts.idleTimeout;
|
|
145
144
|
}
|
|
146
145
|
static async connect(url, opts) {
|
|
147
146
|
const relay = new AbstractRelay(url, opts);
|
|
@@ -165,22 +164,6 @@ var AbstractRelay = class {
|
|
|
165
164
|
get connected() {
|
|
166
165
|
return this._connected;
|
|
167
166
|
}
|
|
168
|
-
clearIdleTimeout() {
|
|
169
|
-
if (this.idleTimeoutHandle) {
|
|
170
|
-
clearTimeout(this.idleTimeoutHandle);
|
|
171
|
-
this.idleTimeoutHandle = void 0;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
scheduleIdleClose() {
|
|
175
|
-
this.clearIdleTimeout();
|
|
176
|
-
if (this.idleTimeout > 0) {
|
|
177
|
-
this.idleTimeoutHandle = setTimeout(() => {
|
|
178
|
-
if (this.ongoingOperations === 0 && this.idleSince) {
|
|
179
|
-
this.close();
|
|
180
|
-
}
|
|
181
|
-
}, this.idleTimeout);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
167
|
async reconnect() {
|
|
185
168
|
const backoff = this.resubscribeBackoff[Math.min(this.reconnectAttempts, this.resubscribeBackoff.length - 1)];
|
|
186
169
|
this.reconnectAttempts++;
|
|
@@ -192,11 +175,6 @@ var AbstractRelay = class {
|
|
|
192
175
|
}, backoff);
|
|
193
176
|
}
|
|
194
177
|
handleHardClose(reason) {
|
|
195
|
-
if (this.ws) {
|
|
196
|
-
this.ws.onopen = null;
|
|
197
|
-
this.ws.onerror = null;
|
|
198
|
-
this.ws.onclose = null;
|
|
199
|
-
}
|
|
200
178
|
if (this.pingIntervalHandle) {
|
|
201
179
|
clearInterval(this.pingIntervalHandle);
|
|
202
180
|
this.pingIntervalHandle = void 0;
|
|
@@ -204,7 +182,6 @@ var AbstractRelay = class {
|
|
|
204
182
|
this._connected = false;
|
|
205
183
|
this.connectionPromise = void 0;
|
|
206
184
|
this.idleSince = void 0;
|
|
207
|
-
this.clearIdleTimeout();
|
|
208
185
|
if (this.enableReconnect && !this.skipReconnection) {
|
|
209
186
|
this.reconnect();
|
|
210
187
|
} else {
|
|
@@ -227,6 +204,7 @@ var AbstractRelay = class {
|
|
|
227
204
|
if (this.reconnectAttempts === 0) {
|
|
228
205
|
this.skipReconnection = true;
|
|
229
206
|
}
|
|
207
|
+
this.onclose?.();
|
|
230
208
|
this.handleHardClose("relay connection timed out");
|
|
231
209
|
}, opts.timeout);
|
|
232
210
|
}
|
|
@@ -272,6 +250,7 @@ var AbstractRelay = class {
|
|
|
272
250
|
if (this.reconnectAttempts === 0) {
|
|
273
251
|
this.skipReconnection = true;
|
|
274
252
|
}
|
|
253
|
+
this.onclose?.();
|
|
275
254
|
this.handleHardClose("relay connection failed");
|
|
276
255
|
};
|
|
277
256
|
this.ws.onclose = (ev) => {
|
|
@@ -360,7 +339,6 @@ var AbstractRelay = class {
|
|
|
360
339
|
}
|
|
361
340
|
async publish(event) {
|
|
362
341
|
this.idleSince = void 0;
|
|
363
|
-
this.clearIdleTimeout();
|
|
364
342
|
this.ongoingOperations++;
|
|
365
343
|
const ret = new Promise((resolve, reject) => {
|
|
366
344
|
const timeout = setTimeout(() => {
|
|
@@ -382,10 +360,8 @@ var AbstractRelay = class {
|
|
|
382
360
|
}
|
|
383
361
|
}
|
|
384
362
|
this.ongoingOperations--;
|
|
385
|
-
if (this.ongoingOperations === 0)
|
|
363
|
+
if (this.ongoingOperations === 0)
|
|
386
364
|
this.idleSince = Date.now();
|
|
387
|
-
this.scheduleIdleClose();
|
|
388
|
-
}
|
|
389
365
|
return ret;
|
|
390
366
|
}
|
|
391
367
|
async count(filters, params) {
|
|
@@ -411,7 +387,6 @@ var AbstractRelay = class {
|
|
|
411
387
|
subscribe(filters, params) {
|
|
412
388
|
if (params.label !== "<forced-ping>") {
|
|
413
389
|
this.idleSince = void 0;
|
|
414
|
-
this.clearIdleTimeout();
|
|
415
390
|
this.ongoingOperations++;
|
|
416
391
|
}
|
|
417
392
|
const sub = this.prepareSubscription(filters, params);
|
|
@@ -440,17 +415,10 @@ var AbstractRelay = class {
|
|
|
440
415
|
}
|
|
441
416
|
this.closeAllSubscriptions("relay connection closed by us");
|
|
442
417
|
this._connected = false;
|
|
443
|
-
this.connectionPromise = void 0;
|
|
444
418
|
this.idleSince = void 0;
|
|
445
|
-
this.clearIdleTimeout();
|
|
446
419
|
this.onclose?.();
|
|
447
|
-
if (this.ws) {
|
|
448
|
-
this.ws
|
|
449
|
-
this.ws.onerror = null;
|
|
450
|
-
this.ws.onclose = null;
|
|
451
|
-
if (this.ws.readyState !== this._WebSocket.CLOSING && this.ws.readyState !== this._WebSocket.CLOSED) {
|
|
452
|
-
this.ws.close();
|
|
453
|
-
}
|
|
420
|
+
if (this.ws?.readyState === this._WebSocket.OPEN) {
|
|
421
|
+
this.ws?.close();
|
|
454
422
|
}
|
|
455
423
|
}
|
|
456
424
|
_onmessage(ev) {
|
|
@@ -477,7 +445,7 @@ var AbstractRelay = class {
|
|
|
477
445
|
case "EVENT": {
|
|
478
446
|
const so = this.openSubs.get(data[1]);
|
|
479
447
|
const event = data[2];
|
|
480
|
-
if (
|
|
448
|
+
if (this.verifyEvent(event) && matchFilters(so.filters, event)) {
|
|
481
449
|
so.onevent(event);
|
|
482
450
|
} else {
|
|
483
451
|
so.oninvalidevent?.(event);
|
|
@@ -625,14 +593,18 @@ var Subscription = class {
|
|
|
625
593
|
}
|
|
626
594
|
this.relay.openSubs.delete(this.id);
|
|
627
595
|
this.relay.ongoingOperations--;
|
|
628
|
-
if (this.relay.ongoingOperations === 0)
|
|
596
|
+
if (this.relay.ongoingOperations === 0)
|
|
629
597
|
this.relay.idleSince = Date.now();
|
|
630
|
-
this.relay.scheduleIdleClose();
|
|
631
|
-
}
|
|
632
598
|
this.onclose?.(reason);
|
|
633
599
|
}
|
|
634
600
|
};
|
|
635
601
|
|
|
602
|
+
// helpers.ts
|
|
603
|
+
var alwaysTrue = (t) => {
|
|
604
|
+
t[verifiedSymbol] = true;
|
|
605
|
+
return true;
|
|
606
|
+
};
|
|
607
|
+
|
|
636
608
|
// nip45.ts
|
|
637
609
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
638
610
|
import { bytesToHex as bytesToHex2 } from "@noble/hashes/utils.js";
|
|
@@ -659,7 +631,7 @@ function newHll() {
|
|
|
659
631
|
return new Uint8Array(M);
|
|
660
632
|
}
|
|
661
633
|
function hllDecode(hex) {
|
|
662
|
-
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-
|
|
634
|
+
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-fA-F]+$/.test(hex))
|
|
663
635
|
return void 0;
|
|
664
636
|
const registers = new Uint8Array(M);
|
|
665
637
|
for (let i = 0; i < M; i++) {
|
|
@@ -698,8 +670,8 @@ var AbstractSimplePool = class {
|
|
|
698
670
|
verifyEvent;
|
|
699
671
|
enablePing;
|
|
700
672
|
enableReconnect;
|
|
701
|
-
idleTimeout = 2e4;
|
|
702
673
|
automaticallyAuth;
|
|
674
|
+
trustedRelayURLs = /* @__PURE__ */ new Set();
|
|
703
675
|
onRelayConnectionFailure;
|
|
704
676
|
onRelayConnectionSuccess;
|
|
705
677
|
allowConnectingToRelay;
|
|
@@ -710,8 +682,6 @@ var AbstractSimplePool = class {
|
|
|
710
682
|
this._WebSocket = opts.websocketImplementation;
|
|
711
683
|
this.enablePing = opts.enablePing;
|
|
712
684
|
this.enableReconnect = opts.enableReconnect || false;
|
|
713
|
-
if (opts.idleTimeout)
|
|
714
|
-
this.idleTimeout = opts.idleTimeout;
|
|
715
685
|
this.automaticallyAuth = opts.automaticallyAuth;
|
|
716
686
|
this.onRelayConnectionFailure = opts.onRelayConnectionFailure;
|
|
717
687
|
this.onRelayConnectionSuccess = opts.onRelayConnectionSuccess;
|
|
@@ -723,11 +693,10 @@ var AbstractSimplePool = class {
|
|
|
723
693
|
let relay = this.relays.get(url);
|
|
724
694
|
if (!relay) {
|
|
725
695
|
relay = new AbstractRelay(url, {
|
|
726
|
-
verifyEvent: this.verifyEvent,
|
|
696
|
+
verifyEvent: this.trustedRelayURLs.has(url) ? alwaysTrue : this.verifyEvent,
|
|
727
697
|
websocketImplementation: this._WebSocket,
|
|
728
698
|
enablePing: this.enablePing,
|
|
729
|
-
enableReconnect: this.enableReconnect
|
|
730
|
-
idleTimeout: this.idleTimeout
|
|
699
|
+
enableReconnect: this.enableReconnect
|
|
731
700
|
});
|
|
732
701
|
relay.onclose = () => {
|
|
733
702
|
this.relays.delete(url);
|
|
@@ -807,11 +776,11 @@ var AbstractSimplePool = class {
|
|
|
807
776
|
}
|
|
808
777
|
};
|
|
809
778
|
const closesReceived = [];
|
|
810
|
-
let handleClose = (i,
|
|
779
|
+
let handleClose = (i, reason) => {
|
|
811
780
|
if (closesReceived[i])
|
|
812
781
|
return;
|
|
813
782
|
handleEose(i);
|
|
814
|
-
closesReceived[i] =
|
|
783
|
+
closesReceived[i] = reason;
|
|
815
784
|
if (closesReceived.filter((a) => a).length === groupedRequests.length) {
|
|
816
785
|
params.onclose?.(closesReceived);
|
|
817
786
|
handleClose = () => {
|
|
@@ -829,7 +798,7 @@ var AbstractSimplePool = class {
|
|
|
829
798
|
const allOpened = Promise.all(
|
|
830
799
|
groupedRequests.map(async ({ url, filters }, i) => {
|
|
831
800
|
if (this.allowConnectingToRelay?.(url, ["read", filters]) === false) {
|
|
832
|
-
handleClose(i,
|
|
801
|
+
handleClose(i, "connection skipped by allowConnectingToRelay");
|
|
833
802
|
return;
|
|
834
803
|
}
|
|
835
804
|
let relay;
|
|
@@ -840,7 +809,7 @@ var AbstractSimplePool = class {
|
|
|
840
809
|
});
|
|
841
810
|
} catch (err) {
|
|
842
811
|
this.onRelayConnectionFailure?.(url);
|
|
843
|
-
handleClose(i,
|
|
812
|
+
handleClose(i, err?.message || String(err));
|
|
844
813
|
return;
|
|
845
814
|
}
|
|
846
815
|
this.onRelayConnectionSuccess?.(url);
|
|
@@ -854,17 +823,17 @@ var AbstractSimplePool = class {
|
|
|
854
823
|
...params,
|
|
855
824
|
oneose: () => handleEose(i),
|
|
856
825
|
onclose: (reason2) => {
|
|
857
|
-
handleClose(i,
|
|
826
|
+
handleClose(i, reason2);
|
|
858
827
|
},
|
|
859
828
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
860
829
|
eoseTimeout: params.maxWait,
|
|
861
830
|
abort: params.abort
|
|
862
831
|
});
|
|
863
832
|
}).catch((err) => {
|
|
864
|
-
handleClose(i,
|
|
833
|
+
handleClose(i, `auth was required and attempted, but failed with: ${err}`);
|
|
865
834
|
});
|
|
866
835
|
} else {
|
|
867
|
-
handleClose(i,
|
|
836
|
+
handleClose(i, reason);
|
|
868
837
|
}
|
|
869
838
|
},
|
|
870
839
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
@@ -892,7 +861,7 @@ var AbstractSimplePool = class {
|
|
|
892
861
|
if (subcloser)
|
|
893
862
|
subcloser.close(reason);
|
|
894
863
|
else
|
|
895
|
-
params.onclose?.(relays.map((
|
|
864
|
+
params.onclose?.(relays.map((_) => reason));
|
|
896
865
|
}
|
|
897
866
|
});
|
|
898
867
|
return subcloser;
|