nostr-tools 2.23.2 → 2.23.4
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/lib/cjs/abstract-pool.js +6 -2
- package/lib/cjs/abstract-pool.js.map +2 -2
- package/lib/cjs/abstract-relay.js +6 -2
- package/lib/cjs/abstract-relay.js.map +2 -2
- package/lib/cjs/index.js +181 -17
- package/lib/cjs/index.js.map +4 -4
- package/lib/cjs/nip17.js +31 -9
- package/lib/cjs/nip17.js.map +2 -2
- package/lib/cjs/nip22.js +154 -0
- package/lib/cjs/nip22.js.map +7 -0
- package/lib/cjs/nip44.js +34 -10
- package/lib/cjs/nip44.js.map +2 -2
- package/lib/cjs/nip46.js +40 -12
- package/lib/cjs/nip46.js.map +2 -2
- package/lib/cjs/nip47.js +3 -3
- package/lib/cjs/nip47.js.map +2 -2
- package/lib/cjs/nip59.js +31 -9
- package/lib/cjs/nip59.js.map +2 -2
- package/lib/cjs/pool.js +6 -2
- package/lib/cjs/pool.js.map +2 -2
- package/lib/cjs/relay.js +6 -2
- package/lib/cjs/relay.js.map +2 -2
- package/lib/esm/abstract-pool.js +6 -2
- package/lib/esm/abstract-pool.js.map +2 -2
- package/lib/esm/abstract-relay.js +6 -2
- package/lib/esm/abstract-relay.js.map +2 -2
- package/lib/esm/index.js +181 -17
- package/lib/esm/index.js.map +4 -4
- package/lib/esm/nip17.js +31 -9
- package/lib/esm/nip17.js.map +2 -2
- package/lib/esm/nip22.js +133 -0
- package/lib/esm/nip22.js.map +7 -0
- package/lib/esm/nip44.js +34 -10
- package/lib/esm/nip44.js.map +2 -2
- package/lib/esm/nip46.js +40 -12
- package/lib/esm/nip46.js.map +2 -2
- package/lib/esm/nip47.js +3 -3
- package/lib/esm/nip47.js.map +2 -2
- package/lib/esm/nip59.js +31 -9
- package/lib/esm/nip59.js.map +2 -2
- package/lib/esm/pool.js +6 -2
- package/lib/esm/pool.js.map +2 -2
- package/lib/esm/relay.js +6 -2
- package/lib/esm/relay.js.map +2 -2
- package/lib/nostr.bundle.js +189 -25
- package/lib/nostr.bundle.js.map +4 -4
- package/package.json +8 -2
- package/lib/types/abstract-pool.d.ts +0 -60
- package/lib/types/abstract-relay.d.ts +0 -110
- package/lib/types/benchmarks.d.ts +0 -1
- package/lib/types/core.d.ts +0 -32
- package/lib/types/core.test.d.ts +0 -1
- package/lib/types/fakejson.d.ts +0 -6
- package/lib/types/fakejson.test.d.ts +0 -1
- package/lib/types/filter.d.ts +0 -19
- package/lib/types/filter.test.d.ts +0 -1
- package/lib/types/helpers.d.ts +0 -2
- package/lib/types/index.d.ts +0 -30
- package/lib/types/kinds.d.ts +0 -200
- package/lib/types/kinds.test.d.ts +0 -1
- package/lib/types/nip04.d.ts +0 -2
- package/lib/types/nip04.test.d.ts +0 -1
- package/lib/types/nip05.d.ts +0 -17
- package/lib/types/nip05.test.d.ts +0 -1
- package/lib/types/nip06.d.ts +0 -15
- package/lib/types/nip06.test.d.ts +0 -1
- package/lib/types/nip07.d.ts +0 -13
- package/lib/types/nip10.d.ts +0 -24
- package/lib/types/nip10.test.d.ts +0 -1
- package/lib/types/nip11.d.ts +0 -266
- package/lib/types/nip11.test.d.ts +0 -1
- package/lib/types/nip13.d.ts +0 -8
- package/lib/types/nip13.test.d.ts +0 -1
- package/lib/types/nip17.d.ts +0 -15
- package/lib/types/nip17.test.d.ts +0 -1
- package/lib/types/nip18.d.ts +0 -22
- package/lib/types/nip18.test.d.ts +0 -1
- package/lib/types/nip19.d.ts +0 -81
- package/lib/types/nip19.test.d.ts +0 -1
- package/lib/types/nip21.d.ts +0 -34
- package/lib/types/nip21.test.d.ts +0 -1
- package/lib/types/nip25.d.ts +0 -15
- package/lib/types/nip25.test.d.ts +0 -1
- package/lib/types/nip27.d.ts +0 -32
- package/lib/types/nip27.test.d.ts +0 -1
- package/lib/types/nip28.d.ts +0 -46
- package/lib/types/nip28.test.d.ts +0 -1
- package/lib/types/nip29.d.ts +0 -265
- package/lib/types/nip30.d.ts +0 -22
- package/lib/types/nip30.test.d.ts +0 -1
- package/lib/types/nip39.d.ts +0 -2
- package/lib/types/nip39.test.d.ts +0 -1
- package/lib/types/nip40.d.ts +0 -10
- package/lib/types/nip40.test.d.ts +0 -1
- package/lib/types/nip42.d.ts +0 -5
- package/lib/types/nip42.test.d.ts +0 -1
- package/lib/types/nip44.d.ts +0 -13
- package/lib/types/nip44.test.d.ts +0 -1
- package/lib/types/nip46.d.ts +0 -117
- package/lib/types/nip47.d.ts +0 -9
- package/lib/types/nip47.test.d.ts +0 -1
- package/lib/types/nip49.d.ts +0 -3
- package/lib/types/nip49.test.d.ts +0 -1
- package/lib/types/nip54.d.ts +0 -1
- package/lib/types/nip54.test.d.ts +0 -1
- package/lib/types/nip55.d.ts +0 -30
- package/lib/types/nip55.test.d.ts +0 -1
- package/lib/types/nip57.d.ts +0 -25
- package/lib/types/nip57.test.d.ts +0 -1
- package/lib/types/nip58.d.ts +0 -134
- package/lib/types/nip58.test.d.ts +0 -1
- package/lib/types/nip59.d.ts +0 -12
- package/lib/types/nip59.test.d.ts +0 -1
- package/lib/types/nip75.d.ts +0 -61
- package/lib/types/nip75.test.d.ts +0 -1
- package/lib/types/nip77.d.ts +0 -102
- package/lib/types/nip77.test.d.ts +0 -1
- package/lib/types/nip94.d.ts +0 -87
- package/lib/types/nip94.test.d.ts +0 -1
- package/lib/types/nip98.d.ts +0 -74
- package/lib/types/nip98.test.d.ts +0 -1
- package/lib/types/nip99.d.ts +0 -92
- package/lib/types/nip99.test.d.ts +0 -1
- package/lib/types/nipb7.d.ts +0 -23
- package/lib/types/nipb7.test.d.ts +0 -1
- package/lib/types/pool.d.ts +0 -6
- package/lib/types/pool.test.d.ts +0 -1
- package/lib/types/pure.d.ts +0 -8
- package/lib/types/pure.test.d.ts +0 -1
- package/lib/types/references.d.ts +0 -10
- package/lib/types/references.test.d.ts +0 -1
- package/lib/types/relay.d.ts +0 -11
- package/lib/types/relay.test.d.ts +0 -1
- package/lib/types/signer.d.ts +0 -11
- package/lib/types/test-helpers.d.ts +0 -14
- package/lib/types/utils.d.ts +0 -9
- package/lib/types/utils.test.d.ts +0 -1
- package/lib/types/wasm.d.ts +0 -8
package/lib/cjs/nip46.js
CHANGED
|
@@ -154,7 +154,8 @@ var import_sha22 = require("@noble/hashes/sha2.js");
|
|
|
154
154
|
var import_utils5 = require("@noble/hashes/utils.js");
|
|
155
155
|
var import_base = require("@scure/base");
|
|
156
156
|
var minPlaintextSize = 1;
|
|
157
|
-
var maxPlaintextSize =
|
|
157
|
+
var maxPlaintextSize = 4294967295;
|
|
158
|
+
var extendedPrefixThreshold = 65536;
|
|
158
159
|
function getConversationKey(privkeyA, pubkeyB) {
|
|
159
160
|
const sharedX = import_secp256k12.secp256k1.getSharedSecret(privkeyA, (0, import_utils5.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
|
|
160
161
|
return (0, import_hkdf.extract)(import_sha22.sha256, sharedX, utf8Encoder.encode("nip44-v2"));
|
|
@@ -172,28 +173,49 @@ function calcPaddedLen(len) {
|
|
|
172
173
|
throw new Error("expected positive integer");
|
|
173
174
|
if (len <= 32)
|
|
174
175
|
return 32;
|
|
175
|
-
const nextPower =
|
|
176
|
+
const nextPower = 2 ** (Math.floor(Math.log2(len - 1)) + 1);
|
|
176
177
|
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
|
|
177
178
|
return chunk * (Math.floor((len - 1) / chunk) + 1);
|
|
178
179
|
}
|
|
179
180
|
function writeU16BE(num) {
|
|
180
|
-
if (!Number.isSafeInteger(num) || num < minPlaintextSize || num >
|
|
181
|
+
if (!Number.isSafeInteger(num) || num < minPlaintextSize || num > 65535)
|
|
181
182
|
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
|
|
182
183
|
const arr = new Uint8Array(2);
|
|
183
184
|
new DataView(arr.buffer).setUint16(0, num, false);
|
|
184
185
|
return arr;
|
|
185
186
|
}
|
|
187
|
+
function writeU32BE(num) {
|
|
188
|
+
if (!Number.isSafeInteger(num) || num < extendedPrefixThreshold || num > maxPlaintextSize)
|
|
189
|
+
throw new Error("invalid plaintext size: must be between 65536 and 4294967295 bytes");
|
|
190
|
+
const arr = new Uint8Array(4);
|
|
191
|
+
new DataView(arr.buffer).setUint32(0, num, false);
|
|
192
|
+
return arr;
|
|
193
|
+
}
|
|
186
194
|
function pad(plaintext) {
|
|
187
195
|
const unpadded = utf8Encoder.encode(plaintext);
|
|
188
196
|
const unpaddedLen = unpadded.length;
|
|
189
|
-
|
|
197
|
+
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)
|
|
198
|
+
throw new Error("invalid plaintext size: must be between 1 and 4294967295 bytes");
|
|
199
|
+
const prefix = unpaddedLen >= extendedPrefixThreshold ? (0, import_utils5.concatBytes)(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
|
|
190
200
|
const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
|
|
191
201
|
return (0, import_utils5.concatBytes)(prefix, unpadded, suffix);
|
|
192
202
|
}
|
|
193
203
|
function unpad(padded) {
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
|
|
204
|
+
const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
|
|
205
|
+
const firstTwo = dv.getUint16(0);
|
|
206
|
+
let unpaddedLen;
|
|
207
|
+
let prefixLen;
|
|
208
|
+
if (firstTwo === 0) {
|
|
209
|
+
unpaddedLen = dv.getUint32(2);
|
|
210
|
+
if (unpaddedLen < extendedPrefixThreshold)
|
|
211
|
+
throw new Error("invalid padding");
|
|
212
|
+
prefixLen = 6;
|
|
213
|
+
} else {
|
|
214
|
+
unpaddedLen = firstTwo;
|
|
215
|
+
prefixLen = 2;
|
|
216
|
+
}
|
|
217
|
+
const unpadded = padded.subarray(prefixLen, prefixLen + unpaddedLen);
|
|
218
|
+
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== prefixLen + calcPaddedLen(unpaddedLen))
|
|
197
219
|
throw new Error("invalid padding");
|
|
198
220
|
return utf8Decoder.decode(unpadded);
|
|
199
221
|
}
|
|
@@ -207,7 +229,7 @@ function decodePayload(payload) {
|
|
|
207
229
|
if (typeof payload !== "string")
|
|
208
230
|
throw new Error("payload must be a valid string");
|
|
209
231
|
const plen = payload.length;
|
|
210
|
-
if (plen < 132
|
|
232
|
+
if (plen < 132)
|
|
211
233
|
throw new Error("invalid payload length: " + plen);
|
|
212
234
|
if (payload[0] === "#")
|
|
213
235
|
throw new Error("unknown encryption version");
|
|
@@ -218,7 +240,7 @@ function decodePayload(payload) {
|
|
|
218
240
|
throw new Error("invalid base64: " + error.message);
|
|
219
241
|
}
|
|
220
242
|
const dlen = data.length;
|
|
221
|
-
if (dlen < 99
|
|
243
|
+
if (dlen < 99)
|
|
222
244
|
throw new Error("invalid data length: " + dlen);
|
|
223
245
|
const vers = data[0];
|
|
224
246
|
if (vers !== 2)
|
|
@@ -720,8 +742,12 @@ var AbstractRelay = class {
|
|
|
720
742
|
}
|
|
721
743
|
}
|
|
722
744
|
} catch (err) {
|
|
723
|
-
|
|
724
|
-
|
|
745
|
+
try {
|
|
746
|
+
const [_, __, event] = JSON.parse(json);
|
|
747
|
+
console.warn(`[nostr] relay ${this.url} error processing message:`, err, event);
|
|
748
|
+
} catch (_) {
|
|
749
|
+
console.warn(`[nostr] relay ${this.url} error processing message:`, err);
|
|
750
|
+
}
|
|
725
751
|
return;
|
|
726
752
|
}
|
|
727
753
|
}
|
|
@@ -1230,7 +1256,9 @@ var BunkerSigner = class {
|
|
|
1230
1256
|
signer.conversationKey = getConversationKey(clientSecretKey, event.pubkey);
|
|
1231
1257
|
signer.setupSubscription();
|
|
1232
1258
|
success = true;
|
|
1233
|
-
|
|
1259
|
+
if (!bunkerParams.skipSwitchRelays) {
|
|
1260
|
+
await Promise.race([new Promise((resolve2) => setTimeout(resolve2, 1e3)), signer.switchRelays()]);
|
|
1261
|
+
}
|
|
1234
1262
|
resolve(signer);
|
|
1235
1263
|
}
|
|
1236
1264
|
} catch (e) {
|