@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
|
@@ -34,42 +34,7 @@ module.exports = __toCommonJS(nip46_exports);
|
|
|
34
34
|
|
|
35
35
|
// pure.ts
|
|
36
36
|
var import_secp256k1 = require("@noble/curves/secp256k1.js");
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
// utils.ts
|
|
40
|
-
var import_utils = require("@noble/hashes/utils.js");
|
|
41
|
-
var utf8Decoder = new TextDecoder("utf-8");
|
|
42
|
-
var utf8Encoder = new TextEncoder();
|
|
43
|
-
function normalizeURL(url) {
|
|
44
|
-
try {
|
|
45
|
-
if (url.indexOf("://") === -1)
|
|
46
|
-
url = "wss://" + url;
|
|
47
|
-
let p = new URL(url);
|
|
48
|
-
if (p.protocol === "http:")
|
|
49
|
-
p.protocol = "ws:";
|
|
50
|
-
else if (p.protocol === "https:")
|
|
51
|
-
p.protocol = "wss:";
|
|
52
|
-
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
53
|
-
if (p.pathname.endsWith("/"))
|
|
54
|
-
p.pathname = p.pathname.slice(0, -1);
|
|
55
|
-
if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
|
|
56
|
-
p.port = "";
|
|
57
|
-
p.searchParams.sort();
|
|
58
|
-
p.hash = "";
|
|
59
|
-
return p.toString();
|
|
60
|
-
} catch (e) {
|
|
61
|
-
throw new Error(`Invalid URL: ${url}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function isHex32(input) {
|
|
65
|
-
for (let i2 = 0; i2 < 64; i2++) {
|
|
66
|
-
let cc = input.charCodeAt(i2);
|
|
67
|
-
if (isNaN(cc) || cc < 48 || cc > 102 || cc > 57 && cc < 97) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
37
|
+
var import_utils2 = require("@noble/hashes/utils.js");
|
|
73
38
|
|
|
74
39
|
// core.ts
|
|
75
40
|
var verifiedSymbol = Symbol("verified");
|
|
@@ -85,7 +50,7 @@ function validateEvent(event) {
|
|
|
85
50
|
return false;
|
|
86
51
|
if (typeof event.pubkey !== "string")
|
|
87
52
|
return false;
|
|
88
|
-
if (!
|
|
53
|
+
if (!event.pubkey.match(/^[a-f0-9]{64}$/))
|
|
89
54
|
return false;
|
|
90
55
|
if (!Array.isArray(event.tags))
|
|
91
56
|
return false;
|
|
@@ -103,18 +68,46 @@ function validateEvent(event) {
|
|
|
103
68
|
|
|
104
69
|
// pure.ts
|
|
105
70
|
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
71
|
+
|
|
72
|
+
// utils.ts
|
|
73
|
+
var import_utils = require("@noble/hashes/utils.js");
|
|
74
|
+
var utf8Decoder = new TextDecoder("utf-8");
|
|
75
|
+
var utf8Encoder = new TextEncoder();
|
|
76
|
+
function normalizeURL(url) {
|
|
77
|
+
try {
|
|
78
|
+
if (url.indexOf("://") === -1)
|
|
79
|
+
url = "wss://" + url;
|
|
80
|
+
let p = new URL(url);
|
|
81
|
+
if (p.protocol === "http:")
|
|
82
|
+
p.protocol = "ws:";
|
|
83
|
+
else if (p.protocol === "https:")
|
|
84
|
+
p.protocol = "wss:";
|
|
85
|
+
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
86
|
+
if (p.pathname.endsWith("/"))
|
|
87
|
+
p.pathname = p.pathname.slice(0, -1);
|
|
88
|
+
if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
|
|
89
|
+
p.port = "";
|
|
90
|
+
p.searchParams.sort();
|
|
91
|
+
p.hash = "";
|
|
92
|
+
return p.toString();
|
|
93
|
+
} catch (e) {
|
|
94
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// pure.ts
|
|
106
99
|
var JS = class {
|
|
107
100
|
generateSecretKey() {
|
|
108
101
|
return import_secp256k1.schnorr.utils.randomSecretKey();
|
|
109
102
|
}
|
|
110
103
|
getPublicKey(secretKey) {
|
|
111
|
-
return (0,
|
|
104
|
+
return (0, import_utils2.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
|
|
112
105
|
}
|
|
113
106
|
finalizeEvent(t, secretKey) {
|
|
114
107
|
const event = t;
|
|
115
|
-
event.pubkey = (0,
|
|
108
|
+
event.pubkey = (0, import_utils2.bytesToHex)(import_secp256k1.schnorr.getPublicKey(secretKey));
|
|
116
109
|
event.id = getEventHash(event);
|
|
117
|
-
event.sig = (0,
|
|
110
|
+
event.sig = (0, import_utils2.bytesToHex)(import_secp256k1.schnorr.sign((0, import_utils2.hexToBytes)(getEventHash(event)), secretKey));
|
|
118
111
|
event[verifiedSymbol] = true;
|
|
119
112
|
return event;
|
|
120
113
|
}
|
|
@@ -127,7 +120,7 @@ var JS = class {
|
|
|
127
120
|
event[verifiedSymbol] = false;
|
|
128
121
|
return false;
|
|
129
122
|
}
|
|
130
|
-
const valid = import_secp256k1.schnorr.verify((0,
|
|
123
|
+
const valid = import_secp256k1.schnorr.verify((0, import_utils2.hexToBytes)(event.sig), (0, import_utils2.hexToBytes)(hash), (0, import_utils2.hexToBytes)(event.pubkey));
|
|
131
124
|
event[verifiedSymbol] = valid;
|
|
132
125
|
return valid;
|
|
133
126
|
} catch (err) {
|
|
@@ -143,7 +136,7 @@ function serializeEvent(evt) {
|
|
|
143
136
|
}
|
|
144
137
|
function getEventHash(event) {
|
|
145
138
|
let eventHash = (0, import_sha2.sha256)(utf8Encoder.encode(serializeEvent(event)));
|
|
146
|
-
return (0,
|
|
139
|
+
return (0, import_utils2.bytesToHex)(eventHash);
|
|
147
140
|
}
|
|
148
141
|
var i = new JS();
|
|
149
142
|
var generateSecretKey = i.generateSecretKey;
|
|
@@ -153,18 +146,18 @@ var verifyEvent = i.verifyEvent;
|
|
|
153
146
|
|
|
154
147
|
// nip44.ts
|
|
155
148
|
var import_chacha = require("@noble/ciphers/chacha.js");
|
|
156
|
-
var
|
|
149
|
+
var import_utils4 = require("@noble/ciphers/utils.js");
|
|
157
150
|
var import_secp256k12 = require("@noble/curves/secp256k1.js");
|
|
158
151
|
var import_hkdf = require("@noble/hashes/hkdf.js");
|
|
159
152
|
var import_hmac = require("@noble/hashes/hmac.js");
|
|
160
153
|
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
161
|
-
var
|
|
154
|
+
var import_utils5 = require("@noble/hashes/utils.js");
|
|
162
155
|
var import_base = require("@scure/base");
|
|
163
156
|
var minPlaintextSize = 1;
|
|
164
157
|
var maxPlaintextSize = 4294967295;
|
|
165
158
|
var extendedPrefixThreshold = 65536;
|
|
166
159
|
function getConversationKey(privkeyA, pubkeyB) {
|
|
167
|
-
const sharedX = import_secp256k12.secp256k1.getSharedSecret(privkeyA, (0,
|
|
160
|
+
const sharedX = import_secp256k12.secp256k1.getSharedSecret(privkeyA, (0, import_utils5.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
|
|
168
161
|
return (0, import_hkdf.extract)(import_sha22.sha256, sharedX, utf8Encoder.encode("nip44-v2"));
|
|
169
162
|
}
|
|
170
163
|
function getMessageKeys(conversationKey, nonce) {
|
|
@@ -203,9 +196,9 @@ function pad(plaintext) {
|
|
|
203
196
|
const unpaddedLen = unpadded.length;
|
|
204
197
|
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)
|
|
205
198
|
throw new Error("invalid plaintext size: must be between 1 and 4294967295 bytes");
|
|
206
|
-
const prefix = unpaddedLen >= extendedPrefixThreshold ? (0,
|
|
199
|
+
const prefix = unpaddedLen >= extendedPrefixThreshold ? (0, import_utils5.concatBytes)(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
|
|
207
200
|
const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
|
|
208
|
-
return (0,
|
|
201
|
+
return (0, import_utils5.concatBytes)(prefix, unpadded, suffix);
|
|
209
202
|
}
|
|
210
203
|
function unpad(padded) {
|
|
211
204
|
const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
|
|
@@ -229,7 +222,7 @@ function unpad(padded) {
|
|
|
229
222
|
function hmacAad(key, message, aad) {
|
|
230
223
|
if (aad.length !== 32)
|
|
231
224
|
throw new Error("AAD associated data must be 32 bytes");
|
|
232
|
-
const combined = (0,
|
|
225
|
+
const combined = (0, import_utils5.concatBytes)(aad, message);
|
|
233
226
|
return (0, import_hmac.hmac)(import_sha22.sha256, key, combined);
|
|
234
227
|
}
|
|
235
228
|
function decodePayload(payload) {
|
|
@@ -258,18 +251,18 @@ function decodePayload(payload) {
|
|
|
258
251
|
mac: data.subarray(-32)
|
|
259
252
|
};
|
|
260
253
|
}
|
|
261
|
-
function encrypt(plaintext, conversationKey, nonce = (0,
|
|
254
|
+
function encrypt(plaintext, conversationKey, nonce = (0, import_utils5.randomBytes)(32)) {
|
|
262
255
|
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
|
|
263
256
|
const padded = pad(plaintext);
|
|
264
257
|
const ciphertext = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, padded);
|
|
265
258
|
const mac = hmacAad(hmac_key, ciphertext, nonce);
|
|
266
|
-
return import_base.base64.encode((0,
|
|
259
|
+
return import_base.base64.encode((0, import_utils5.concatBytes)(new Uint8Array([2]), nonce, ciphertext, mac));
|
|
267
260
|
}
|
|
268
261
|
function decrypt(payload, conversationKey) {
|
|
269
262
|
const { nonce, ciphertext, mac } = decodePayload(payload);
|
|
270
263
|
const { chacha_key, chacha_nonce, hmac_key } = getMessageKeys(conversationKey, nonce);
|
|
271
264
|
const calculatedMac = hmacAad(hmac_key, ciphertext, nonce);
|
|
272
|
-
if (!(0,
|
|
265
|
+
if (!(0, import_utils4.equalBytes)(calculatedMac, mac))
|
|
273
266
|
throw new Error("invalid MAC");
|
|
274
267
|
const padded = (0, import_chacha.chacha20)(chacha_key, chacha_nonce, ciphertext);
|
|
275
268
|
return unpad(padded);
|
|
@@ -379,14 +372,12 @@ var AbstractRelay = class {
|
|
|
379
372
|
openSubs = /* @__PURE__ */ new Map();
|
|
380
373
|
enablePing;
|
|
381
374
|
enableReconnect;
|
|
382
|
-
idleTimeout = 0;
|
|
383
375
|
idleSince = Date.now();
|
|
384
376
|
ongoingOperations = 0;
|
|
385
377
|
reconnectTimeoutHandle;
|
|
386
378
|
pingIntervalHandle;
|
|
387
379
|
reconnectAttempts = 0;
|
|
388
380
|
skipReconnection = false;
|
|
389
|
-
idleTimeoutHandle;
|
|
390
381
|
connectionPromise;
|
|
391
382
|
openCountRequests = /* @__PURE__ */ new Map();
|
|
392
383
|
openEventPublishes = /* @__PURE__ */ new Map();
|
|
@@ -402,8 +393,6 @@ var AbstractRelay = class {
|
|
|
402
393
|
this._WebSocket = opts.websocketImplementation || WebSocket;
|
|
403
394
|
this.enablePing = opts.enablePing;
|
|
404
395
|
this.enableReconnect = opts.enableReconnect || false;
|
|
405
|
-
if (opts.idleTimeout)
|
|
406
|
-
this.idleTimeout = opts.idleTimeout;
|
|
407
396
|
}
|
|
408
397
|
static async connect(url, opts) {
|
|
409
398
|
const relay = new AbstractRelay(url, opts);
|
|
@@ -427,22 +416,6 @@ var AbstractRelay = class {
|
|
|
427
416
|
get connected() {
|
|
428
417
|
return this._connected;
|
|
429
418
|
}
|
|
430
|
-
clearIdleTimeout() {
|
|
431
|
-
if (this.idleTimeoutHandle) {
|
|
432
|
-
clearTimeout(this.idleTimeoutHandle);
|
|
433
|
-
this.idleTimeoutHandle = void 0;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
scheduleIdleClose() {
|
|
437
|
-
this.clearIdleTimeout();
|
|
438
|
-
if (this.idleTimeout > 0) {
|
|
439
|
-
this.idleTimeoutHandle = setTimeout(() => {
|
|
440
|
-
if (this.ongoingOperations === 0 && this.idleSince) {
|
|
441
|
-
this.close();
|
|
442
|
-
}
|
|
443
|
-
}, this.idleTimeout);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
419
|
async reconnect() {
|
|
447
420
|
const backoff = this.resubscribeBackoff[Math.min(this.reconnectAttempts, this.resubscribeBackoff.length - 1)];
|
|
448
421
|
this.reconnectAttempts++;
|
|
@@ -454,11 +427,6 @@ var AbstractRelay = class {
|
|
|
454
427
|
}, backoff);
|
|
455
428
|
}
|
|
456
429
|
handleHardClose(reason) {
|
|
457
|
-
if (this.ws) {
|
|
458
|
-
this.ws.onopen = null;
|
|
459
|
-
this.ws.onerror = null;
|
|
460
|
-
this.ws.onclose = null;
|
|
461
|
-
}
|
|
462
430
|
if (this.pingIntervalHandle) {
|
|
463
431
|
clearInterval(this.pingIntervalHandle);
|
|
464
432
|
this.pingIntervalHandle = void 0;
|
|
@@ -466,7 +434,6 @@ var AbstractRelay = class {
|
|
|
466
434
|
this._connected = false;
|
|
467
435
|
this.connectionPromise = void 0;
|
|
468
436
|
this.idleSince = void 0;
|
|
469
|
-
this.clearIdleTimeout();
|
|
470
437
|
if (this.enableReconnect && !this.skipReconnection) {
|
|
471
438
|
this.reconnect();
|
|
472
439
|
} else {
|
|
@@ -489,6 +456,7 @@ var AbstractRelay = class {
|
|
|
489
456
|
if (this.reconnectAttempts === 0) {
|
|
490
457
|
this.skipReconnection = true;
|
|
491
458
|
}
|
|
459
|
+
this.onclose?.();
|
|
492
460
|
this.handleHardClose("relay connection timed out");
|
|
493
461
|
}, opts.timeout);
|
|
494
462
|
}
|
|
@@ -534,6 +502,7 @@ var AbstractRelay = class {
|
|
|
534
502
|
if (this.reconnectAttempts === 0) {
|
|
535
503
|
this.skipReconnection = true;
|
|
536
504
|
}
|
|
505
|
+
this.onclose?.();
|
|
537
506
|
this.handleHardClose("relay connection failed");
|
|
538
507
|
};
|
|
539
508
|
this.ws.onclose = (ev) => {
|
|
@@ -622,7 +591,6 @@ var AbstractRelay = class {
|
|
|
622
591
|
}
|
|
623
592
|
async publish(event) {
|
|
624
593
|
this.idleSince = void 0;
|
|
625
|
-
this.clearIdleTimeout();
|
|
626
594
|
this.ongoingOperations++;
|
|
627
595
|
const ret = new Promise((resolve, reject) => {
|
|
628
596
|
const timeout = setTimeout(() => {
|
|
@@ -644,10 +612,8 @@ var AbstractRelay = class {
|
|
|
644
612
|
}
|
|
645
613
|
}
|
|
646
614
|
this.ongoingOperations--;
|
|
647
|
-
if (this.ongoingOperations === 0)
|
|
615
|
+
if (this.ongoingOperations === 0)
|
|
648
616
|
this.idleSince = Date.now();
|
|
649
|
-
this.scheduleIdleClose();
|
|
650
|
-
}
|
|
651
617
|
return ret;
|
|
652
618
|
}
|
|
653
619
|
async count(filters, params) {
|
|
@@ -673,7 +639,6 @@ var AbstractRelay = class {
|
|
|
673
639
|
subscribe(filters, params) {
|
|
674
640
|
if (params.label !== "<forced-ping>") {
|
|
675
641
|
this.idleSince = void 0;
|
|
676
|
-
this.clearIdleTimeout();
|
|
677
642
|
this.ongoingOperations++;
|
|
678
643
|
}
|
|
679
644
|
const sub = this.prepareSubscription(filters, params);
|
|
@@ -702,17 +667,10 @@ var AbstractRelay = class {
|
|
|
702
667
|
}
|
|
703
668
|
this.closeAllSubscriptions("relay connection closed by us");
|
|
704
669
|
this._connected = false;
|
|
705
|
-
this.connectionPromise = void 0;
|
|
706
670
|
this.idleSince = void 0;
|
|
707
|
-
this.clearIdleTimeout();
|
|
708
671
|
this.onclose?.();
|
|
709
|
-
if (this.ws) {
|
|
710
|
-
this.ws
|
|
711
|
-
this.ws.onerror = null;
|
|
712
|
-
this.ws.onclose = null;
|
|
713
|
-
if (this.ws.readyState !== this._WebSocket.CLOSING && this.ws.readyState !== this._WebSocket.CLOSED) {
|
|
714
|
-
this.ws.close();
|
|
715
|
-
}
|
|
672
|
+
if (this.ws?.readyState === this._WebSocket.OPEN) {
|
|
673
|
+
this.ws?.close();
|
|
716
674
|
}
|
|
717
675
|
}
|
|
718
676
|
_onmessage(ev) {
|
|
@@ -739,7 +697,7 @@ var AbstractRelay = class {
|
|
|
739
697
|
case "EVENT": {
|
|
740
698
|
const so = this.openSubs.get(data[1]);
|
|
741
699
|
const event = data[2];
|
|
742
|
-
if (
|
|
700
|
+
if (this.verifyEvent(event) && matchFilters(so.filters, event)) {
|
|
743
701
|
so.onevent(event);
|
|
744
702
|
} else {
|
|
745
703
|
so.oninvalidevent?.(event);
|
|
@@ -887,17 +845,21 @@ var Subscription = class {
|
|
|
887
845
|
}
|
|
888
846
|
this.relay.openSubs.delete(this.id);
|
|
889
847
|
this.relay.ongoingOperations--;
|
|
890
|
-
if (this.relay.ongoingOperations === 0)
|
|
848
|
+
if (this.relay.ongoingOperations === 0)
|
|
891
849
|
this.relay.idleSince = Date.now();
|
|
892
|
-
this.relay.scheduleIdleClose();
|
|
893
|
-
}
|
|
894
850
|
this.onclose?.(reason);
|
|
895
851
|
}
|
|
896
852
|
};
|
|
897
853
|
|
|
854
|
+
// helpers.ts
|
|
855
|
+
var alwaysTrue = (t) => {
|
|
856
|
+
t[verifiedSymbol] = true;
|
|
857
|
+
return true;
|
|
858
|
+
};
|
|
859
|
+
|
|
898
860
|
// nip45.ts
|
|
899
861
|
var import_sha23 = require("@noble/hashes/sha2.js");
|
|
900
|
-
var
|
|
862
|
+
var import_utils8 = require("@noble/hashes/utils.js");
|
|
901
863
|
var M = 256;
|
|
902
864
|
var HLL_HEX_LENGTH = M * 2;
|
|
903
865
|
var utf8Encoder2 = new TextEncoder();
|
|
@@ -921,7 +883,7 @@ function newHll() {
|
|
|
921
883
|
return new Uint8Array(M);
|
|
922
884
|
}
|
|
923
885
|
function hllDecode(hex) {
|
|
924
|
-
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-
|
|
886
|
+
if (hex.length !== HLL_HEX_LENGTH || !/^[0-9a-fA-F]+$/.test(hex))
|
|
925
887
|
return void 0;
|
|
926
888
|
const registers = new Uint8Array(M);
|
|
927
889
|
for (let i2 = 0; i2 < M; i2++) {
|
|
@@ -960,8 +922,8 @@ var AbstractSimplePool = class {
|
|
|
960
922
|
verifyEvent;
|
|
961
923
|
enablePing;
|
|
962
924
|
enableReconnect;
|
|
963
|
-
idleTimeout = 2e4;
|
|
964
925
|
automaticallyAuth;
|
|
926
|
+
trustedRelayURLs = /* @__PURE__ */ new Set();
|
|
965
927
|
onRelayConnectionFailure;
|
|
966
928
|
onRelayConnectionSuccess;
|
|
967
929
|
allowConnectingToRelay;
|
|
@@ -972,8 +934,6 @@ var AbstractSimplePool = class {
|
|
|
972
934
|
this._WebSocket = opts.websocketImplementation;
|
|
973
935
|
this.enablePing = opts.enablePing;
|
|
974
936
|
this.enableReconnect = opts.enableReconnect || false;
|
|
975
|
-
if (opts.idleTimeout)
|
|
976
|
-
this.idleTimeout = opts.idleTimeout;
|
|
977
937
|
this.automaticallyAuth = opts.automaticallyAuth;
|
|
978
938
|
this.onRelayConnectionFailure = opts.onRelayConnectionFailure;
|
|
979
939
|
this.onRelayConnectionSuccess = opts.onRelayConnectionSuccess;
|
|
@@ -985,11 +945,10 @@ var AbstractSimplePool = class {
|
|
|
985
945
|
let relay = this.relays.get(url);
|
|
986
946
|
if (!relay) {
|
|
987
947
|
relay = new AbstractRelay(url, {
|
|
988
|
-
verifyEvent: this.verifyEvent,
|
|
948
|
+
verifyEvent: this.trustedRelayURLs.has(url) ? alwaysTrue : this.verifyEvent,
|
|
989
949
|
websocketImplementation: this._WebSocket,
|
|
990
950
|
enablePing: this.enablePing,
|
|
991
|
-
enableReconnect: this.enableReconnect
|
|
992
|
-
idleTimeout: this.idleTimeout
|
|
951
|
+
enableReconnect: this.enableReconnect
|
|
993
952
|
});
|
|
994
953
|
relay.onclose = () => {
|
|
995
954
|
this.relays.delete(url);
|
|
@@ -1069,11 +1028,11 @@ var AbstractSimplePool = class {
|
|
|
1069
1028
|
}
|
|
1070
1029
|
};
|
|
1071
1030
|
const closesReceived = [];
|
|
1072
|
-
let handleClose = (i2,
|
|
1031
|
+
let handleClose = (i2, reason) => {
|
|
1073
1032
|
if (closesReceived[i2])
|
|
1074
1033
|
return;
|
|
1075
1034
|
handleEose(i2);
|
|
1076
|
-
closesReceived[i2] =
|
|
1035
|
+
closesReceived[i2] = reason;
|
|
1077
1036
|
if (closesReceived.filter((a) => a).length === groupedRequests.length) {
|
|
1078
1037
|
params.onclose?.(closesReceived);
|
|
1079
1038
|
handleClose = () => {
|
|
@@ -1091,7 +1050,7 @@ var AbstractSimplePool = class {
|
|
|
1091
1050
|
const allOpened = Promise.all(
|
|
1092
1051
|
groupedRequests.map(async ({ url, filters }, i2) => {
|
|
1093
1052
|
if (this.allowConnectingToRelay?.(url, ["read", filters]) === false) {
|
|
1094
|
-
handleClose(i2,
|
|
1053
|
+
handleClose(i2, "connection skipped by allowConnectingToRelay");
|
|
1095
1054
|
return;
|
|
1096
1055
|
}
|
|
1097
1056
|
let relay;
|
|
@@ -1102,7 +1061,7 @@ var AbstractSimplePool = class {
|
|
|
1102
1061
|
});
|
|
1103
1062
|
} catch (err) {
|
|
1104
1063
|
this.onRelayConnectionFailure?.(url);
|
|
1105
|
-
handleClose(i2,
|
|
1064
|
+
handleClose(i2, err?.message || String(err));
|
|
1106
1065
|
return;
|
|
1107
1066
|
}
|
|
1108
1067
|
this.onRelayConnectionSuccess?.(url);
|
|
@@ -1116,17 +1075,17 @@ var AbstractSimplePool = class {
|
|
|
1116
1075
|
...params,
|
|
1117
1076
|
oneose: () => handleEose(i2),
|
|
1118
1077
|
onclose: (reason2) => {
|
|
1119
|
-
handleClose(i2,
|
|
1078
|
+
handleClose(i2, reason2);
|
|
1120
1079
|
},
|
|
1121
1080
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
1122
1081
|
eoseTimeout: params.maxWait,
|
|
1123
1082
|
abort: params.abort
|
|
1124
1083
|
});
|
|
1125
1084
|
}).catch((err) => {
|
|
1126
|
-
handleClose(i2,
|
|
1085
|
+
handleClose(i2, `auth was required and attempted, but failed with: ${err}`);
|
|
1127
1086
|
});
|
|
1128
1087
|
} else {
|
|
1129
|
-
handleClose(i2,
|
|
1088
|
+
handleClose(i2, reason);
|
|
1130
1089
|
}
|
|
1131
1090
|
},
|
|
1132
1091
|
alreadyHaveEvent: localAlreadyHaveEventHandler,
|
|
@@ -1154,7 +1113,7 @@ var AbstractSimplePool = class {
|
|
|
1154
1113
|
if (subcloser)
|
|
1155
1114
|
subcloser.close(reason);
|
|
1156
1115
|
else
|
|
1157
|
-
params.onclose?.(relays.map((
|
|
1116
|
+
params.onclose?.(relays.map((_) => reason));
|
|
1158
1117
|
}
|
|
1159
1118
|
});
|
|
1160
1119
|
return subcloser;
|