@openclaw/nostr 2026.7.2-beta.7 → 2026.7.33
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
|
@@ -2,41 +2,6 @@
|
|
|
2
2
|
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
3
3
|
import { bytesToHex as bytesToHex2, hexToBytes as hexToBytes2 } from "@noble/hashes/utils.js";
|
|
4
4
|
|
|
5
|
-
// utils.ts
|
|
6
|
-
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
7
|
-
var utf8Decoder = new TextDecoder("utf-8");
|
|
8
|
-
var utf8Encoder = new TextEncoder();
|
|
9
|
-
function normalizeURL(url) {
|
|
10
|
-
try {
|
|
11
|
-
if (url.indexOf("://") === -1)
|
|
12
|
-
url = "wss://" + url;
|
|
13
|
-
let p = new URL(url);
|
|
14
|
-
if (p.protocol === "http:")
|
|
15
|
-
p.protocol = "ws:";
|
|
16
|
-
else if (p.protocol === "https:")
|
|
17
|
-
p.protocol = "wss:";
|
|
18
|
-
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
19
|
-
if (p.pathname.endsWith("/"))
|
|
20
|
-
p.pathname = p.pathname.slice(0, -1);
|
|
21
|
-
if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
|
|
22
|
-
p.port = "";
|
|
23
|
-
p.searchParams.sort();
|
|
24
|
-
p.hash = "";
|
|
25
|
-
return p.toString();
|
|
26
|
-
} catch (e) {
|
|
27
|
-
throw new Error(`Invalid URL: ${url}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function isHex32(input) {
|
|
31
|
-
for (let i2 = 0; i2 < 64; i2++) {
|
|
32
|
-
let cc = input.charCodeAt(i2);
|
|
33
|
-
if (isNaN(cc) || cc < 48 || cc > 102 || cc > 57 && cc < 97) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
5
|
// core.ts
|
|
41
6
|
var verifiedSymbol = Symbol("verified");
|
|
42
7
|
var isRecord = (obj) => obj instanceof Object;
|
|
@@ -51,7 +16,7 @@ function validateEvent(event) {
|
|
|
51
16
|
return false;
|
|
52
17
|
if (typeof event.pubkey !== "string")
|
|
53
18
|
return false;
|
|
54
|
-
if (!
|
|
19
|
+
if (!event.pubkey.match(/^[a-f0-9]{64}$/))
|
|
55
20
|
return false;
|
|
56
21
|
if (!Array.isArray(event.tags))
|
|
57
22
|
return false;
|
|
@@ -69,6 +34,34 @@ function validateEvent(event) {
|
|
|
69
34
|
|
|
70
35
|
// pure.ts
|
|
71
36
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
37
|
+
|
|
38
|
+
// utils.ts
|
|
39
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
40
|
+
var utf8Decoder = new TextDecoder("utf-8");
|
|
41
|
+
var utf8Encoder = new TextEncoder();
|
|
42
|
+
function normalizeURL(url) {
|
|
43
|
+
try {
|
|
44
|
+
if (url.indexOf("://") === -1)
|
|
45
|
+
url = "wss://" + url;
|
|
46
|
+
let p = new URL(url);
|
|
47
|
+
if (p.protocol === "http:")
|
|
48
|
+
p.protocol = "ws:";
|
|
49
|
+
else if (p.protocol === "https:")
|
|
50
|
+
p.protocol = "wss:";
|
|
51
|
+
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
52
|
+
if (p.pathname.endsWith("/"))
|
|
53
|
+
p.pathname = p.pathname.slice(0, -1);
|
|
54
|
+
if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
|
|
55
|
+
p.port = "";
|
|
56
|
+
p.searchParams.sort();
|
|
57
|
+
p.hash = "";
|
|
58
|
+
return p.toString();
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// pure.ts
|
|
72
65
|
var JS = class {
|
|
73
66
|
generateSecretKey() {
|
|
74
67
|
return schnorr.utils.randomSecretKey();
|
|
@@ -210,14 +203,12 @@ var AbstractRelay = class {
|
|
|
210
203
|
openSubs = /* @__PURE__ */ new Map();
|
|
211
204
|
enablePing;
|
|
212
205
|
enableReconnect;
|
|
213
|
-
idleTimeout = 0;
|
|
214
206
|
idleSince = Date.now();
|
|
215
207
|
ongoingOperations = 0;
|
|
216
208
|
reconnectTimeoutHandle;
|
|
217
209
|
pingIntervalHandle;
|
|
218
210
|
reconnectAttempts = 0;
|
|
219
211
|
skipReconnection = false;
|
|
220
|
-
idleTimeoutHandle;
|
|
221
212
|
connectionPromise;
|
|
222
213
|
openCountRequests = /* @__PURE__ */ new Map();
|
|
223
214
|
openEventPublishes = /* @__PURE__ */ new Map();
|
|
@@ -233,8 +224,6 @@ var AbstractRelay = class {
|
|
|
233
224
|
this._WebSocket = opts.websocketImplementation || WebSocket;
|
|
234
225
|
this.enablePing = opts.enablePing;
|
|
235
226
|
this.enableReconnect = opts.enableReconnect || false;
|
|
236
|
-
if (opts.idleTimeout)
|
|
237
|
-
this.idleTimeout = opts.idleTimeout;
|
|
238
227
|
}
|
|
239
228
|
static async connect(url, opts) {
|
|
240
229
|
const relay = new AbstractRelay(url, opts);
|
|
@@ -258,22 +247,6 @@ var AbstractRelay = class {
|
|
|
258
247
|
get connected() {
|
|
259
248
|
return this._connected;
|
|
260
249
|
}
|
|
261
|
-
clearIdleTimeout() {
|
|
262
|
-
if (this.idleTimeoutHandle) {
|
|
263
|
-
clearTimeout(this.idleTimeoutHandle);
|
|
264
|
-
this.idleTimeoutHandle = void 0;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
scheduleIdleClose() {
|
|
268
|
-
this.clearIdleTimeout();
|
|
269
|
-
if (this.idleTimeout > 0) {
|
|
270
|
-
this.idleTimeoutHandle = setTimeout(() => {
|
|
271
|
-
if (this.ongoingOperations === 0 && this.idleSince) {
|
|
272
|
-
this.close();
|
|
273
|
-
}
|
|
274
|
-
}, this.idleTimeout);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
250
|
async reconnect() {
|
|
278
251
|
const backoff = this.resubscribeBackoff[Math.min(this.reconnectAttempts, this.resubscribeBackoff.length - 1)];
|
|
279
252
|
this.reconnectAttempts++;
|
|
@@ -285,11 +258,6 @@ var AbstractRelay = class {
|
|
|
285
258
|
}, backoff);
|
|
286
259
|
}
|
|
287
260
|
handleHardClose(reason) {
|
|
288
|
-
if (this.ws) {
|
|
289
|
-
this.ws.onopen = null;
|
|
290
|
-
this.ws.onerror = null;
|
|
291
|
-
this.ws.onclose = null;
|
|
292
|
-
}
|
|
293
261
|
if (this.pingIntervalHandle) {
|
|
294
262
|
clearInterval(this.pingIntervalHandle);
|
|
295
263
|
this.pingIntervalHandle = void 0;
|
|
@@ -297,7 +265,6 @@ var AbstractRelay = class {
|
|
|
297
265
|
this._connected = false;
|
|
298
266
|
this.connectionPromise = void 0;
|
|
299
267
|
this.idleSince = void 0;
|
|
300
|
-
this.clearIdleTimeout();
|
|
301
268
|
if (this.enableReconnect && !this.skipReconnection) {
|
|
302
269
|
this.reconnect();
|
|
303
270
|
} else {
|
|
@@ -320,6 +287,7 @@ var AbstractRelay = class {
|
|
|
320
287
|
if (this.reconnectAttempts === 0) {
|
|
321
288
|
this.skipReconnection = true;
|
|
322
289
|
}
|
|
290
|
+
this.onclose?.();
|
|
323
291
|
this.handleHardClose("relay connection timed out");
|
|
324
292
|
}, opts.timeout);
|
|
325
293
|
}
|
|
@@ -365,6 +333,7 @@ var AbstractRelay = class {
|
|
|
365
333
|
if (this.reconnectAttempts === 0) {
|
|
366
334
|
this.skipReconnection = true;
|
|
367
335
|
}
|
|
336
|
+
this.onclose?.();
|
|
368
337
|
this.handleHardClose("relay connection failed");
|
|
369
338
|
};
|
|
370
339
|
this.ws.onclose = (ev) => {
|
|
@@ -453,7 +422,6 @@ var AbstractRelay = class {
|
|
|
453
422
|
}
|
|
454
423
|
async publish(event) {
|
|
455
424
|
this.idleSince = void 0;
|
|
456
|
-
this.clearIdleTimeout();
|
|
457
425
|
this.ongoingOperations++;
|
|
458
426
|
const ret = new Promise((resolve, reject) => {
|
|
459
427
|
const timeout = setTimeout(() => {
|
|
@@ -475,10 +443,8 @@ var AbstractRelay = class {
|
|
|
475
443
|
}
|
|
476
444
|
}
|
|
477
445
|
this.ongoingOperations--;
|
|
478
|
-
if (this.ongoingOperations === 0)
|
|
446
|
+
if (this.ongoingOperations === 0)
|
|
479
447
|
this.idleSince = Date.now();
|
|
480
|
-
this.scheduleIdleClose();
|
|
481
|
-
}
|
|
482
448
|
return ret;
|
|
483
449
|
}
|
|
484
450
|
async count(filters, params) {
|
|
@@ -504,7 +470,6 @@ var AbstractRelay = class {
|
|
|
504
470
|
subscribe(filters, params) {
|
|
505
471
|
if (params.label !== "<forced-ping>") {
|
|
506
472
|
this.idleSince = void 0;
|
|
507
|
-
this.clearIdleTimeout();
|
|
508
473
|
this.ongoingOperations++;
|
|
509
474
|
}
|
|
510
475
|
const sub = this.prepareSubscription(filters, params);
|
|
@@ -533,17 +498,10 @@ var AbstractRelay = class {
|
|
|
533
498
|
}
|
|
534
499
|
this.closeAllSubscriptions("relay connection closed by us");
|
|
535
500
|
this._connected = false;
|
|
536
|
-
this.connectionPromise = void 0;
|
|
537
501
|
this.idleSince = void 0;
|
|
538
|
-
this.clearIdleTimeout();
|
|
539
502
|
this.onclose?.();
|
|
540
|
-
if (this.ws) {
|
|
541
|
-
this.ws
|
|
542
|
-
this.ws.onerror = null;
|
|
543
|
-
this.ws.onclose = null;
|
|
544
|
-
if (this.ws.readyState !== this._WebSocket.CLOSING && this.ws.readyState !== this._WebSocket.CLOSED) {
|
|
545
|
-
this.ws.close();
|
|
546
|
-
}
|
|
503
|
+
if (this.ws?.readyState === this._WebSocket.OPEN) {
|
|
504
|
+
this.ws?.close();
|
|
547
505
|
}
|
|
548
506
|
}
|
|
549
507
|
_onmessage(ev) {
|
|
@@ -570,7 +528,7 @@ var AbstractRelay = class {
|
|
|
570
528
|
case "EVENT": {
|
|
571
529
|
const so = this.openSubs.get(data[1]);
|
|
572
530
|
const event = data[2];
|
|
573
|
-
if (
|
|
531
|
+
if (this.verifyEvent(event) && matchFilters(so.filters, event)) {
|
|
574
532
|
so.onevent(event);
|
|
575
533
|
} else {
|
|
576
534
|
so.oninvalidevent?.(event);
|
|
@@ -718,14 +676,18 @@ var Subscription = class {
|
|
|
718
676
|
}
|
|
719
677
|
this.relay.openSubs.delete(this.id);
|
|
720
678
|
this.relay.ongoingOperations--;
|
|
721
|
-
if (this.relay.ongoingOperations === 0)
|
|
679
|
+
if (this.relay.ongoingOperations === 0)
|
|
722
680
|
this.relay.idleSince = Date.now();
|
|
723
|
-
this.relay.scheduleIdleClose();
|
|
724
|
-
}
|
|
725
681
|
this.onclose?.(reason);
|
|
726
682
|
}
|
|
727
683
|
};
|
|
728
684
|
|
|
685
|
+
// helpers.ts
|
|
686
|
+
var alwaysTrue = (t) => {
|
|
687
|
+
t[verifiedSymbol] = true;
|
|
688
|
+
return true;
|
|
689
|
+
};
|
|
690
|
+
|
|
729
691
|
// nip45.ts
|
|
730
692
|
import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
|
|
731
693
|
import { bytesToHex as bytesToHex3 } from "@noble/hashes/utils.js";
|
|
@@ -752,7 +714,7 @@ function newHll() {
|
|
|
752
714
|
return new Uint8Array(M);
|
|
753
715
|
}
|
|
754
716
|
function hllDecode(hex) {
|
|
755
|
-
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-
|
|
717
|
+
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-fA-F]+$/.test(hex))
|
|
756
718
|
return void 0;
|
|
757
719
|
const registers = new Uint8Array(M);
|
|
758
720
|
for (let i2 = 0; i2 < M; i2++) {
|
|
@@ -791,8 +753,8 @@ var AbstractSimplePool = class {
|
|
|
791
753
|
verifyEvent;
|
|
792
754
|
enablePing;
|
|
793
755
|
enableReconnect;
|
|
794
|
-
idleTimeout = 2e4;
|
|
795
756
|
automaticallyAuth;
|
|
757
|
+
trustedRelayURLs = /* @__PURE__ */ new Set();
|
|
796
758
|
onRelayConnectionFailure;
|
|
797
759
|
onRelayConnectionSuccess;
|
|
798
760
|
allowConnectingToRelay;
|
|
@@ -803,8 +765,6 @@ var AbstractSimplePool = class {
|
|
|
803
765
|
this._WebSocket = opts.websocketImplementation;
|
|
804
766
|
this.enablePing = opts.enablePing;
|
|
805
767
|
this.enableReconnect = opts.enableReconnect || false;
|
|
806
|
-
if (opts.idleTimeout)
|
|
807
|
-
this.idleTimeout = opts.idleTimeout;
|
|
808
768
|
this.automaticallyAuth = opts.automaticallyAuth;
|
|
809
769
|
this.onRelayConnectionFailure = opts.onRelayConnectionFailure;
|
|
810
770
|
this.onRelayConnectionSuccess = opts.onRelayConnectionSuccess;
|
|
@@ -816,11 +776,10 @@ var AbstractSimplePool = class {
|
|
|
816
776
|
let relay = this.relays.get(url);
|
|
817
777
|
if (!relay) {
|
|
818
778
|
relay = new AbstractRelay(url, {
|
|
819
|
-
verifyEvent: this.verifyEvent,
|
|
779
|
+
verifyEvent: this.trustedRelayURLs.has(url) ? alwaysTrue : this.verifyEvent,
|
|
820
780
|
websocketImplementation: this._WebSocket,
|
|
821
781
|
enablePing: this.enablePing,
|
|
822
|
-
enableReconnect: this.enableReconnect
|
|
823
|
-
idleTimeout: this.idleTimeout
|
|
782
|
+
enableReconnect: this.enableReconnect
|
|
824
783
|
});
|
|
825
784
|
relay.onclose = () => {
|
|
826
785
|
this.relays.delete(url);
|
|
@@ -900,11 +859,11 @@ var AbstractSimplePool = class {
|
|
|
900
859
|
}
|
|
901
860
|
};
|
|
902
861
|
const closesReceived = [];
|
|
903
|
-
let handleClose = (i2,
|
|
862
|
+
let handleClose = (i2, reason) => {
|
|
904
863
|
if (closesReceived[i2])
|
|
905
864
|
return;
|
|
906
865
|
handleEose(i2);
|
|
907
|
-
closesReceived[i2] =
|
|
866
|
+
closesReceived[i2] = reason;
|
|
908
867
|
if (closesReceived.filter((a) => a).length === groupedRequests.length) {
|
|
909
868
|
params.onclose?.(closesReceived);
|
|
910
869
|
handleClose = () => {
|
|
@@ -922,7 +881,7 @@ var AbstractSimplePool = class {
|
|
|
922
881
|
const allOpened = Promise.all(
|
|
923
882
|
groupedRequests.map(async ({ url, filters }, i2) => {
|
|
924
883
|
if (this.allowConnectingToRelay?.(url, ["read", filters]) === false) {
|
|
925
|
-
handleClose(i2,
|
|
884
|
+
handleClose(i2, "connection skipped by allowConnectingToRelay");
|
|
926
885
|
return;
|
|
927
886
|
}
|
|
928
887
|
let relay;
|
|
@@ -933,7 +892,7 @@ var AbstractSimplePool = class {
|
|
|
933
892
|
});
|
|
934
893
|
} catch (err) {
|
|
935
894
|
this.onRelayConnectionFailure?.(url);
|
|
936
|
-
handleClose(i2,
|
|
895
|
+
handleClose(i2, err?.message || String(err));
|
|
937
896
|
return;
|
|
938
897
|
}
|
|
939
898
|
this.onRelayConnectionSuccess?.(url);
|
|
@@ -947,17 +906,17 @@ var AbstractSimplePool = class {
|
|
|
947
906
|
...params,
|
|
948
907
|
oneose: () => handleEose(i2),
|
|
949
908
|
onclose: (reason2) => {
|
|
950
|
-
handleClose(i2,
|
|
909
|
+
handleClose(i2, reason2);
|
|
951
910
|
},
|
|
952
911
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
953
912
|
eoseTimeout: params.maxWait,
|
|
954
913
|
abort: params.abort
|
|
955
914
|
});
|
|
956
915
|
}).catch((err) => {
|
|
957
|
-
handleClose(i2,
|
|
916
|
+
handleClose(i2, `auth was required and attempted, but failed with: ${err}`);
|
|
958
917
|
});
|
|
959
918
|
} else {
|
|
960
|
-
handleClose(i2,
|
|
919
|
+
handleClose(i2, reason);
|
|
961
920
|
}
|
|
962
921
|
},
|
|
963
922
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
@@ -985,7 +944,7 @@ var AbstractSimplePool = class {
|
|
|
985
944
|
if (subcloser)
|
|
986
945
|
subcloser.close(reason);
|
|
987
946
|
else
|
|
988
|
-
params.onclose?.(relays.map((
|
|
947
|
+
params.onclose?.(relays.map((_) => reason));
|
|
989
948
|
}
|
|
990
949
|
});
|
|
991
950
|
return subcloser;
|