@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
|
@@ -28,42 +28,7 @@ module.exports = __toCommonJS(pool_exports);
|
|
|
28
28
|
|
|
29
29
|
// pure.ts
|
|
30
30
|
var import_secp256k1 = require("@noble/curves/secp256k1.js");
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
// utils.ts
|
|
34
|
-
var import_utils = require("@noble/hashes/utils.js");
|
|
35
|
-
var utf8Decoder = new TextDecoder("utf-8");
|
|
36
|
-
var utf8Encoder = new TextEncoder();
|
|
37
|
-
function normalizeURL(url) {
|
|
38
|
-
try {
|
|
39
|
-
if (url.indexOf("://") === -1)
|
|
40
|
-
url = "wss://" + url;
|
|
41
|
-
let p = new URL(url);
|
|
42
|
-
if (p.protocol === "http:")
|
|
43
|
-
p.protocol = "ws:";
|
|
44
|
-
else if (p.protocol === "https:")
|
|
45
|
-
p.protocol = "wss:";
|
|
46
|
-
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
47
|
-
if (p.pathname.endsWith("/"))
|
|
48
|
-
p.pathname = p.pathname.slice(0, -1);
|
|
49
|
-
if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
|
|
50
|
-
p.port = "";
|
|
51
|
-
p.searchParams.sort();
|
|
52
|
-
p.hash = "";
|
|
53
|
-
return p.toString();
|
|
54
|
-
} catch (e) {
|
|
55
|
-
throw new Error(`Invalid URL: ${url}`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function isHex32(input) {
|
|
59
|
-
for (let i2 = 0; i2 < 64; i2++) {
|
|
60
|
-
let cc = input.charCodeAt(i2);
|
|
61
|
-
if (isNaN(cc) || cc < 48 || cc > 102 || cc > 57 && cc < 97) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
31
|
+
var import_utils2 = require("@noble/hashes/utils.js");
|
|
67
32
|
|
|
68
33
|
// core.ts
|
|
69
34
|
var verifiedSymbol = Symbol("verified");
|
|
@@ -79,7 +44,7 @@ function validateEvent(event) {
|
|
|
79
44
|
return false;
|
|
80
45
|
if (typeof event.pubkey !== "string")
|
|
81
46
|
return false;
|
|
82
|
-
if (!
|
|
47
|
+
if (!event.pubkey.match(/^[a-f0-9]{64}$/))
|
|
83
48
|
return false;
|
|
84
49
|
if (!Array.isArray(event.tags))
|
|
85
50
|
return false;
|
|
@@ -97,18 +62,46 @@ function validateEvent(event) {
|
|
|
97
62
|
|
|
98
63
|
// pure.ts
|
|
99
64
|
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
65
|
+
|
|
66
|
+
// utils.ts
|
|
67
|
+
var import_utils = require("@noble/hashes/utils.js");
|
|
68
|
+
var utf8Decoder = new TextDecoder("utf-8");
|
|
69
|
+
var utf8Encoder = new TextEncoder();
|
|
70
|
+
function normalizeURL(url) {
|
|
71
|
+
try {
|
|
72
|
+
if (url.indexOf("://") === -1)
|
|
73
|
+
url = "wss://" + url;
|
|
74
|
+
let p = new URL(url);
|
|
75
|
+
if (p.protocol === "http:")
|
|
76
|
+
p.protocol = "ws:";
|
|
77
|
+
else if (p.protocol === "https:")
|
|
78
|
+
p.protocol = "wss:";
|
|
79
|
+
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
80
|
+
if (p.pathname.endsWith("/"))
|
|
81
|
+
p.pathname = p.pathname.slice(0, -1);
|
|
82
|
+
if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
|
|
83
|
+
p.port = "";
|
|
84
|
+
p.searchParams.sort();
|
|
85
|
+
p.hash = "";
|
|
86
|
+
return p.toString();
|
|
87
|
+
} catch (e) {
|
|
88
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// pure.ts
|
|
100
93
|
var JS = class {
|
|
101
94
|
generateSecretKey() {
|
|
102
95
|
return import_secp256k1.schnorr.utils.randomSecretKey();
|
|
103
96
|
}
|
|
104
97
|
getPublicKey(secretKey) {
|
|
105
|
-
return (0,
|
|
98
|
+
return (0, import_utils2.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
|
|
106
99
|
}
|
|
107
100
|
finalizeEvent(t, secretKey) {
|
|
108
101
|
const event = t;
|
|
109
|
-
event.pubkey = (0,
|
|
102
|
+
event.pubkey = (0, import_utils2.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
|
|
110
103
|
event.id = getEventHash(event);
|
|
111
|
-
event.sig = (0,
|
|
104
|
+
event.sig = (0, import_utils2.bytesToHex)(import_secp256k1.schnorr.sign((0, import_utils2.hexToBytes)(getEventHash(event)), secretKey));
|
|
112
105
|
event[verifiedSymbol] = true;
|
|
113
106
|
return event;
|
|
114
107
|
}
|
|
@@ -121,7 +114,7 @@ var JS = class {
|
|
|
121
114
|
event[verifiedSymbol] = false;
|
|
122
115
|
return false;
|
|
123
116
|
}
|
|
124
|
-
const valid = import_secp256k1.schnorr.verify((0,
|
|
117
|
+
const valid = import_secp256k1.schnorr.verify((0, import_utils2.hexToBytes)(event.sig), (0, import_utils2.hexToBytes)(hash), (0, import_utils2.hexToBytes)(event.pubkey));
|
|
125
118
|
event[verifiedSymbol] = valid;
|
|
126
119
|
return valid;
|
|
127
120
|
} catch (err) {
|
|
@@ -137,7 +130,7 @@ function serializeEvent(evt) {
|
|
|
137
130
|
}
|
|
138
131
|
function getEventHash(event) {
|
|
139
132
|
let eventHash = (0, import_sha2.sha256)(utf8Encoder.encode(serializeEvent(event)));
|
|
140
|
-
return (0,
|
|
133
|
+
return (0, import_utils2.bytesToHex)(eventHash);
|
|
141
134
|
}
|
|
142
135
|
var i = new JS();
|
|
143
136
|
var generateSecretKey = i.generateSecretKey;
|
|
@@ -238,14 +231,12 @@ var AbstractRelay = class {
|
|
|
238
231
|
openSubs = /* @__PURE__ */ new Map();
|
|
239
232
|
enablePing;
|
|
240
233
|
enableReconnect;
|
|
241
|
-
idleTimeout = 0;
|
|
242
234
|
idleSince = Date.now();
|
|
243
235
|
ongoingOperations = 0;
|
|
244
236
|
reconnectTimeoutHandle;
|
|
245
237
|
pingIntervalHandle;
|
|
246
238
|
reconnectAttempts = 0;
|
|
247
239
|
skipReconnection = false;
|
|
248
|
-
idleTimeoutHandle;
|
|
249
240
|
connectionPromise;
|
|
250
241
|
openCountRequests = /* @__PURE__ */ new Map();
|
|
251
242
|
openEventPublishes = /* @__PURE__ */ new Map();
|
|
@@ -261,8 +252,6 @@ var AbstractRelay = class {
|
|
|
261
252
|
this._WebSocket = opts.websocketImplementation || WebSocket;
|
|
262
253
|
this.enablePing = opts.enablePing;
|
|
263
254
|
this.enableReconnect = opts.enableReconnect || false;
|
|
264
|
-
if (opts.idleTimeout)
|
|
265
|
-
this.idleTimeout = opts.idleTimeout;
|
|
266
255
|
}
|
|
267
256
|
static async connect(url, opts) {
|
|
268
257
|
const relay = new AbstractRelay(url, opts);
|
|
@@ -286,22 +275,6 @@ var AbstractRelay = class {
|
|
|
286
275
|
get connected() {
|
|
287
276
|
return this._connected;
|
|
288
277
|
}
|
|
289
|
-
clearIdleTimeout() {
|
|
290
|
-
if (this.idleTimeoutHandle) {
|
|
291
|
-
clearTimeout(this.idleTimeoutHandle);
|
|
292
|
-
this.idleTimeoutHandle = void 0;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
scheduleIdleClose() {
|
|
296
|
-
this.clearIdleTimeout();
|
|
297
|
-
if (this.idleTimeout > 0) {
|
|
298
|
-
this.idleTimeoutHandle = setTimeout(() => {
|
|
299
|
-
if (this.ongoingOperations === 0 && this.idleSince) {
|
|
300
|
-
this.close();
|
|
301
|
-
}
|
|
302
|
-
}, this.idleTimeout);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
278
|
async reconnect() {
|
|
306
279
|
const backoff = this.resubscribeBackoff[Math.min(this.reconnectAttempts, this.resubscribeBackoff.length - 1)];
|
|
307
280
|
this.reconnectAttempts++;
|
|
@@ -313,11 +286,6 @@ var AbstractRelay = class {
|
|
|
313
286
|
}, backoff);
|
|
314
287
|
}
|
|
315
288
|
handleHardClose(reason) {
|
|
316
|
-
if (this.ws) {
|
|
317
|
-
this.ws.onopen = null;
|
|
318
|
-
this.ws.onerror = null;
|
|
319
|
-
this.ws.onclose = null;
|
|
320
|
-
}
|
|
321
289
|
if (this.pingIntervalHandle) {
|
|
322
290
|
clearInterval(this.pingIntervalHandle);
|
|
323
291
|
this.pingIntervalHandle = void 0;
|
|
@@ -325,7 +293,6 @@ var AbstractRelay = class {
|
|
|
325
293
|
this._connected = false;
|
|
326
294
|
this.connectionPromise = void 0;
|
|
327
295
|
this.idleSince = void 0;
|
|
328
|
-
this.clearIdleTimeout();
|
|
329
296
|
if (this.enableReconnect && !this.skipReconnection) {
|
|
330
297
|
this.reconnect();
|
|
331
298
|
} else {
|
|
@@ -348,6 +315,7 @@ var AbstractRelay = class {
|
|
|
348
315
|
if (this.reconnectAttempts === 0) {
|
|
349
316
|
this.skipReconnection = true;
|
|
350
317
|
}
|
|
318
|
+
this.onclose?.();
|
|
351
319
|
this.handleHardClose("relay connection timed out");
|
|
352
320
|
}, opts.timeout);
|
|
353
321
|
}
|
|
@@ -393,6 +361,7 @@ var AbstractRelay = class {
|
|
|
393
361
|
if (this.reconnectAttempts === 0) {
|
|
394
362
|
this.skipReconnection = true;
|
|
395
363
|
}
|
|
364
|
+
this.onclose?.();
|
|
396
365
|
this.handleHardClose("relay connection failed");
|
|
397
366
|
};
|
|
398
367
|
this.ws.onclose = (ev) => {
|
|
@@ -481,7 +450,6 @@ var AbstractRelay = class {
|
|
|
481
450
|
}
|
|
482
451
|
async publish(event) {
|
|
483
452
|
this.idleSince = void 0;
|
|
484
|
-
this.clearIdleTimeout();
|
|
485
453
|
this.ongoingOperations++;
|
|
486
454
|
const ret = new Promise((resolve, reject) => {
|
|
487
455
|
const timeout = setTimeout(() => {
|
|
@@ -503,10 +471,8 @@ var AbstractRelay = class {
|
|
|
503
471
|
}
|
|
504
472
|
}
|
|
505
473
|
this.ongoingOperations--;
|
|
506
|
-
if (this.ongoingOperations === 0)
|
|
474
|
+
if (this.ongoingOperations === 0)
|
|
507
475
|
this.idleSince = Date.now();
|
|
508
|
-
this.scheduleIdleClose();
|
|
509
|
-
}
|
|
510
476
|
return ret;
|
|
511
477
|
}
|
|
512
478
|
async count(filters, params) {
|
|
@@ -532,7 +498,6 @@ var AbstractRelay = class {
|
|
|
532
498
|
subscribe(filters, params) {
|
|
533
499
|
if (params.label !== "<forced-ping>") {
|
|
534
500
|
this.idleSince = void 0;
|
|
535
|
-
this.clearIdleTimeout();
|
|
536
501
|
this.ongoingOperations++;
|
|
537
502
|
}
|
|
538
503
|
const sub = this.prepareSubscription(filters, params);
|
|
@@ -561,17 +526,10 @@ var AbstractRelay = class {
|
|
|
561
526
|
}
|
|
562
527
|
this.closeAllSubscriptions("relay connection closed by us");
|
|
563
528
|
this._connected = false;
|
|
564
|
-
this.connectionPromise = void 0;
|
|
565
529
|
this.idleSince = void 0;
|
|
566
|
-
this.clearIdleTimeout();
|
|
567
530
|
this.onclose?.();
|
|
568
|
-
if (this.ws) {
|
|
569
|
-
this.ws
|
|
570
|
-
this.ws.onerror = null;
|
|
571
|
-
this.ws.onclose = null;
|
|
572
|
-
if (this.ws.readyState !== this._WebSocket.CLOSING && this.ws.readyState !== this._WebSocket.CLOSED) {
|
|
573
|
-
this.ws.close();
|
|
574
|
-
}
|
|
531
|
+
if (this.ws?.readyState === this._WebSocket.OPEN) {
|
|
532
|
+
this.ws?.close();
|
|
575
533
|
}
|
|
576
534
|
}
|
|
577
535
|
_onmessage(ev) {
|
|
@@ -598,7 +556,7 @@ var AbstractRelay = class {
|
|
|
598
556
|
case "EVENT": {
|
|
599
557
|
const so = this.openSubs.get(data[1]);
|
|
600
558
|
const event = data[2];
|
|
601
|
-
if (
|
|
559
|
+
if (this.verifyEvent(event) && matchFilters(so.filters, event)) {
|
|
602
560
|
so.onevent(event);
|
|
603
561
|
} else {
|
|
604
562
|
so.oninvalidevent?.(event);
|
|
@@ -746,17 +704,21 @@ var Subscription = class {
|
|
|
746
704
|
}
|
|
747
705
|
this.relay.openSubs.delete(this.id);
|
|
748
706
|
this.relay.ongoingOperations--;
|
|
749
|
-
if (this.relay.ongoingOperations === 0)
|
|
707
|
+
if (this.relay.ongoingOperations === 0)
|
|
750
708
|
this.relay.idleSince = Date.now();
|
|
751
|
-
this.relay.scheduleIdleClose();
|
|
752
|
-
}
|
|
753
709
|
this.onclose?.(reason);
|
|
754
710
|
}
|
|
755
711
|
};
|
|
756
712
|
|
|
713
|
+
// helpers.ts
|
|
714
|
+
var alwaysTrue = (t) => {
|
|
715
|
+
t[verifiedSymbol] = true;
|
|
716
|
+
return true;
|
|
717
|
+
};
|
|
718
|
+
|
|
757
719
|
// nip45.ts
|
|
758
720
|
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
759
|
-
var
|
|
721
|
+
var import_utils5 = require("@noble/hashes/utils.js");
|
|
760
722
|
var M = 256;
|
|
761
723
|
var HLL_HEX_LENGTH = M * 2;
|
|
762
724
|
var utf8Encoder2 = new TextEncoder();
|
|
@@ -780,7 +742,7 @@ function newHll() {
|
|
|
780
742
|
return new Uint8Array(M);
|
|
781
743
|
}
|
|
782
744
|
function hllDecode(hex) {
|
|
783
|
-
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-
|
|
745
|
+
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-fA-F]+$/.test(hex))
|
|
784
746
|
return void 0;
|
|
785
747
|
const registers = new Uint8Array(M);
|
|
786
748
|
for (let i2 = 0; i2 < M; i2++) {
|
|
@@ -819,8 +781,8 @@ var AbstractSimplePool = class {
|
|
|
819
781
|
verifyEvent;
|
|
820
782
|
enablePing;
|
|
821
783
|
enableReconnect;
|
|
822
|
-
idleTimeout = 2e4;
|
|
823
784
|
automaticallyAuth;
|
|
785
|
+
trustedRelayURLs = /* @__PURE__ */ new Set();
|
|
824
786
|
onRelayConnectionFailure;
|
|
825
787
|
onRelayConnectionSuccess;
|
|
826
788
|
allowConnectingToRelay;
|
|
@@ -831,8 +793,6 @@ var AbstractSimplePool = class {
|
|
|
831
793
|
this._WebSocket = opts.websocketImplementation;
|
|
832
794
|
this.enablePing = opts.enablePing;
|
|
833
795
|
this.enableReconnect = opts.enableReconnect || false;
|
|
834
|
-
if (opts.idleTimeout)
|
|
835
|
-
this.idleTimeout = opts.idleTimeout;
|
|
836
796
|
this.automaticallyAuth = opts.automaticallyAuth;
|
|
837
797
|
this.onRelayConnectionFailure = opts.onRelayConnectionFailure;
|
|
838
798
|
this.onRelayConnectionSuccess = opts.onRelayConnectionSuccess;
|
|
@@ -844,11 +804,10 @@ var AbstractSimplePool = class {
|
|
|
844
804
|
let relay = this.relays.get(url);
|
|
845
805
|
if (!relay) {
|
|
846
806
|
relay = new AbstractRelay(url, {
|
|
847
|
-
verifyEvent: this.verifyEvent,
|
|
807
|
+
verifyEvent: this.trustedRelayURLs.has(url) ? alwaysTrue : this.verifyEvent,
|
|
848
808
|
websocketImplementation: this._WebSocket,
|
|
849
809
|
enablePing: this.enablePing,
|
|
850
|
-
enableReconnect: this.enableReconnect
|
|
851
|
-
idleTimeout: this.idleTimeout
|
|
810
|
+
enableReconnect: this.enableReconnect
|
|
852
811
|
});
|
|
853
812
|
relay.onclose = () => {
|
|
854
813
|
this.relays.delete(url);
|
|
@@ -928,11 +887,11 @@ var AbstractSimplePool = class {
|
|
|
928
887
|
}
|
|
929
888
|
};
|
|
930
889
|
const closesReceived = [];
|
|
931
|
-
let handleClose = (i2,
|
|
890
|
+
let handleClose = (i2, reason) => {
|
|
932
891
|
if (closesReceived[i2])
|
|
933
892
|
return;
|
|
934
893
|
handleEose(i2);
|
|
935
|
-
closesReceived[i2] =
|
|
894
|
+
closesReceived[i2] = reason;
|
|
936
895
|
if (closesReceived.filter((a) => a).length === groupedRequests.length) {
|
|
937
896
|
params.onclose?.(closesReceived);
|
|
938
897
|
handleClose = () => {
|
|
@@ -950,7 +909,7 @@ var AbstractSimplePool = class {
|
|
|
950
909
|
const allOpened = Promise.all(
|
|
951
910
|
groupedRequests.map(async ({ url, filters }, i2) => {
|
|
952
911
|
if (this.allowConnectingToRelay?.(url, ["read", filters]) === false) {
|
|
953
|
-
handleClose(i2,
|
|
912
|
+
handleClose(i2, "connection skipped by allowConnectingToRelay");
|
|
954
913
|
return;
|
|
955
914
|
}
|
|
956
915
|
let relay;
|
|
@@ -961,7 +920,7 @@ var AbstractSimplePool = class {
|
|
|
961
920
|
});
|
|
962
921
|
} catch (err) {
|
|
963
922
|
this.onRelayConnectionFailure?.(url);
|
|
964
|
-
handleClose(i2,
|
|
923
|
+
handleClose(i2, err?.message || String(err));
|
|
965
924
|
return;
|
|
966
925
|
}
|
|
967
926
|
this.onRelayConnectionSuccess?.(url);
|
|
@@ -975,17 +934,17 @@ var AbstractSimplePool = class {
|
|
|
975
934
|
...params,
|
|
976
935
|
oneose: () => handleEose(i2),
|
|
977
936
|
onclose: (reason2) => {
|
|
978
|
-
handleClose(i2,
|
|
937
|
+
handleClose(i2, reason2);
|
|
979
938
|
},
|
|
980
939
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
981
940
|
eoseTimeout: params.maxWait,
|
|
982
941
|
abort: params.abort
|
|
983
942
|
});
|
|
984
943
|
}).catch((err) => {
|
|
985
|
-
handleClose(i2,
|
|
944
|
+
handleClose(i2, `auth was required and attempted, but failed with: ${err}`);
|
|
986
945
|
});
|
|
987
946
|
} else {
|
|
988
|
-
handleClose(i2,
|
|
947
|
+
handleClose(i2, reason);
|
|
989
948
|
}
|
|
990
949
|
},
|
|
991
950
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
@@ -1013,7 +972,7 @@ var AbstractSimplePool = class {
|
|
|
1013
972
|
if (subcloser)
|
|
1014
973
|
subcloser.close(reason);
|
|
1015
974
|
else
|
|
1016
|
-
params.onclose?.(relays.map((
|
|
975
|
+
params.onclose?.(relays.map((_) => reason));
|
|
1017
976
|
}
|
|
1018
977
|
});
|
|
1019
978
|
return subcloser;
|