nostr-tools 2.23.3 → 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/index.js +175 -15
- 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 +34 -10
- 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/esm/index.js +175 -15
- 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 +34 -10
- 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/nostr.bundle.js +175 -15
- 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/index.js
CHANGED
|
@@ -41,6 +41,7 @@ __export(nostr_tools_exports, {
|
|
|
41
41
|
nip18: () => nip18_exports,
|
|
42
42
|
nip19: () => nip19_exports,
|
|
43
43
|
nip21: () => nip21_exports,
|
|
44
|
+
nip22: () => nip22_exports,
|
|
44
45
|
nip25: () => nip25_exports,
|
|
45
46
|
nip27: () => nip27_exports,
|
|
46
47
|
nip28: () => nip28_exports,
|
|
@@ -2030,7 +2031,8 @@ var import_sha23 = require("@noble/hashes/sha2.js");
|
|
|
2030
2031
|
var import_utils13 = require("@noble/hashes/utils.js");
|
|
2031
2032
|
var import_base3 = require("@scure/base");
|
|
2032
2033
|
var minPlaintextSize = 1;
|
|
2033
|
-
var maxPlaintextSize =
|
|
2034
|
+
var maxPlaintextSize = 4294967295;
|
|
2035
|
+
var extendedPrefixThreshold = 65536;
|
|
2034
2036
|
function getConversationKey(privkeyA, pubkeyB) {
|
|
2035
2037
|
const sharedX = import_secp256k13.secp256k1.getSharedSecret(privkeyA, (0, import_utils13.hexToBytes)("02" + pubkeyB)).subarray(1, 33);
|
|
2036
2038
|
return (0, import_hkdf.extract)(import_sha23.sha256, sharedX, utf8Encoder.encode("nip44-v2"));
|
|
@@ -2048,28 +2050,49 @@ function calcPaddedLen(len) {
|
|
|
2048
2050
|
throw new Error("expected positive integer");
|
|
2049
2051
|
if (len <= 32)
|
|
2050
2052
|
return 32;
|
|
2051
|
-
const nextPower =
|
|
2053
|
+
const nextPower = 2 ** (Math.floor(Math.log2(len - 1)) + 1);
|
|
2052
2054
|
const chunk = nextPower <= 256 ? 32 : nextPower / 8;
|
|
2053
2055
|
return chunk * (Math.floor((len - 1) / chunk) + 1);
|
|
2054
2056
|
}
|
|
2055
2057
|
function writeU16BE(num) {
|
|
2056
|
-
if (!Number.isSafeInteger(num) || num < minPlaintextSize || num >
|
|
2058
|
+
if (!Number.isSafeInteger(num) || num < minPlaintextSize || num > 65535)
|
|
2057
2059
|
throw new Error("invalid plaintext size: must be between 1 and 65535 bytes");
|
|
2058
2060
|
const arr = new Uint8Array(2);
|
|
2059
2061
|
new DataView(arr.buffer).setUint16(0, num, false);
|
|
2060
2062
|
return arr;
|
|
2061
2063
|
}
|
|
2064
|
+
function writeU32BE(num) {
|
|
2065
|
+
if (!Number.isSafeInteger(num) || num < extendedPrefixThreshold || num > maxPlaintextSize)
|
|
2066
|
+
throw new Error("invalid plaintext size: must be between 65536 and 4294967295 bytes");
|
|
2067
|
+
const arr = new Uint8Array(4);
|
|
2068
|
+
new DataView(arr.buffer).setUint32(0, num, false);
|
|
2069
|
+
return arr;
|
|
2070
|
+
}
|
|
2062
2071
|
function pad(plaintext) {
|
|
2063
2072
|
const unpadded = utf8Encoder.encode(plaintext);
|
|
2064
2073
|
const unpaddedLen = unpadded.length;
|
|
2065
|
-
|
|
2074
|
+
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize)
|
|
2075
|
+
throw new Error("invalid plaintext size: must be between 1 and 4294967295 bytes");
|
|
2076
|
+
const prefix = unpaddedLen >= extendedPrefixThreshold ? (0, import_utils13.concatBytes)(new Uint8Array([0, 0]), writeU32BE(unpaddedLen)) : writeU16BE(unpaddedLen);
|
|
2066
2077
|
const suffix = new Uint8Array(calcPaddedLen(unpaddedLen) - unpaddedLen);
|
|
2067
2078
|
return (0, import_utils13.concatBytes)(prefix, unpadded, suffix);
|
|
2068
2079
|
}
|
|
2069
2080
|
function unpad(padded) {
|
|
2070
|
-
const
|
|
2071
|
-
const
|
|
2072
|
-
|
|
2081
|
+
const dv = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
|
|
2082
|
+
const firstTwo = dv.getUint16(0);
|
|
2083
|
+
let unpaddedLen;
|
|
2084
|
+
let prefixLen;
|
|
2085
|
+
if (firstTwo === 0) {
|
|
2086
|
+
unpaddedLen = dv.getUint32(2);
|
|
2087
|
+
if (unpaddedLen < extendedPrefixThreshold)
|
|
2088
|
+
throw new Error("invalid padding");
|
|
2089
|
+
prefixLen = 6;
|
|
2090
|
+
} else {
|
|
2091
|
+
unpaddedLen = firstTwo;
|
|
2092
|
+
prefixLen = 2;
|
|
2093
|
+
}
|
|
2094
|
+
const unpadded = padded.subarray(prefixLen, prefixLen + unpaddedLen);
|
|
2095
|
+
if (unpaddedLen < minPlaintextSize || unpaddedLen > maxPlaintextSize || unpadded.length !== unpaddedLen || padded.length !== prefixLen + calcPaddedLen(unpaddedLen))
|
|
2073
2096
|
throw new Error("invalid padding");
|
|
2074
2097
|
return utf8Decoder.decode(unpadded);
|
|
2075
2098
|
}
|
|
@@ -2083,7 +2106,7 @@ function decodePayload(payload) {
|
|
|
2083
2106
|
if (typeof payload !== "string")
|
|
2084
2107
|
throw new Error("payload must be a valid string");
|
|
2085
2108
|
const plen = payload.length;
|
|
2086
|
-
if (plen < 132
|
|
2109
|
+
if (plen < 132)
|
|
2087
2110
|
throw new Error("invalid payload length: " + plen);
|
|
2088
2111
|
if (payload[0] === "#")
|
|
2089
2112
|
throw new Error("unknown encryption version");
|
|
@@ -2094,7 +2117,7 @@ function decodePayload(payload) {
|
|
|
2094
2117
|
throw new Error("invalid base64: " + error.message);
|
|
2095
2118
|
}
|
|
2096
2119
|
const dlen = data.length;
|
|
2097
|
-
if (dlen < 99
|
|
2120
|
+
if (dlen < 99)
|
|
2098
2121
|
throw new Error("invalid data length: " + dlen);
|
|
2099
2122
|
const vers = data[0];
|
|
2100
2123
|
if (vers !== 2)
|
|
@@ -2124,7 +2147,9 @@ function decrypt2(payload, conversationKey) {
|
|
|
2124
2147
|
var v2 = {
|
|
2125
2148
|
utils: {
|
|
2126
2149
|
getConversationKey,
|
|
2127
|
-
calcPaddedLen
|
|
2150
|
+
calcPaddedLen,
|
|
2151
|
+
pad,
|
|
2152
|
+
unpad
|
|
2128
2153
|
},
|
|
2129
2154
|
encrypt: encrypt2,
|
|
2130
2155
|
decrypt: decrypt2
|
|
@@ -2329,6 +2354,141 @@ function parse2(uri) {
|
|
|
2329
2354
|
};
|
|
2330
2355
|
}
|
|
2331
2356
|
|
|
2357
|
+
// nip22.ts
|
|
2358
|
+
var nip22_exports = {};
|
|
2359
|
+
__export(nip22_exports, {
|
|
2360
|
+
parse: () => parse3
|
|
2361
|
+
});
|
|
2362
|
+
function parseKind(kind) {
|
|
2363
|
+
if (!kind)
|
|
2364
|
+
return void 0;
|
|
2365
|
+
return /^\d+$/.test(kind) ? parseInt(kind, 10) : kind;
|
|
2366
|
+
}
|
|
2367
|
+
function parseAddressPointer(value, relayUrl) {
|
|
2368
|
+
const idx = value.indexOf(":");
|
|
2369
|
+
const idx2 = value.indexOf(":", idx + 1);
|
|
2370
|
+
if (idx === -1 || idx2 === -1)
|
|
2371
|
+
return void 0;
|
|
2372
|
+
const kind = parseInt(value.slice(0, idx), 10);
|
|
2373
|
+
if (Number.isNaN(kind))
|
|
2374
|
+
return void 0;
|
|
2375
|
+
return {
|
|
2376
|
+
kind,
|
|
2377
|
+
pubkey: value.slice(idx + 1, idx2),
|
|
2378
|
+
identifier: value.slice(idx2 + 1),
|
|
2379
|
+
relays: relayUrl ? [relayUrl] : []
|
|
2380
|
+
};
|
|
2381
|
+
}
|
|
2382
|
+
function parsePointer(tag) {
|
|
2383
|
+
switch (tag[0]) {
|
|
2384
|
+
case "E":
|
|
2385
|
+
case "e":
|
|
2386
|
+
if (!tag[1])
|
|
2387
|
+
return void 0;
|
|
2388
|
+
return {
|
|
2389
|
+
id: tag[1],
|
|
2390
|
+
relays: tag[2] ? [tag[2]] : [],
|
|
2391
|
+
author: tag[3]
|
|
2392
|
+
};
|
|
2393
|
+
case "A":
|
|
2394
|
+
case "a":
|
|
2395
|
+
if (!tag[1])
|
|
2396
|
+
return void 0;
|
|
2397
|
+
return parseAddressPointer(tag[1], tag[2]);
|
|
2398
|
+
case "I":
|
|
2399
|
+
case "i":
|
|
2400
|
+
if (!tag[1])
|
|
2401
|
+
return void 0;
|
|
2402
|
+
return {
|
|
2403
|
+
value: tag[1],
|
|
2404
|
+
hint: tag[2]
|
|
2405
|
+
};
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
function parseQuote(tag) {
|
|
2409
|
+
if (!tag[1])
|
|
2410
|
+
return void 0;
|
|
2411
|
+
if (tag[1].includes(":")) {
|
|
2412
|
+
return parseAddressPointer(tag[1], tag[2]);
|
|
2413
|
+
}
|
|
2414
|
+
return {
|
|
2415
|
+
id: tag[1],
|
|
2416
|
+
relays: tag[2] ? [tag[2]] : [],
|
|
2417
|
+
author: tag[3]
|
|
2418
|
+
};
|
|
2419
|
+
}
|
|
2420
|
+
function choosePointer(candidates) {
|
|
2421
|
+
return candidates.findLast((candidate) => candidate.tagName === "A" || candidate.tagName === "a")?.pointer || candidates.findLast((candidate) => candidate.tagName === "I" || candidate.tagName === "i")?.pointer || candidates.findLast((candidate) => candidate.tagName === "E" || candidate.tagName === "e")?.pointer;
|
|
2422
|
+
}
|
|
2423
|
+
function inheritRelayHints(pointer, profiles) {
|
|
2424
|
+
if (!pointer || !("id" in pointer) || !pointer.author)
|
|
2425
|
+
return;
|
|
2426
|
+
const author = profiles.find((profile) => profile.pubkey === pointer.author);
|
|
2427
|
+
if (!author || !author.relays)
|
|
2428
|
+
return;
|
|
2429
|
+
if (!pointer.relays) {
|
|
2430
|
+
pointer.relays = [];
|
|
2431
|
+
}
|
|
2432
|
+
author.relays.forEach((url) => {
|
|
2433
|
+
if (pointer.relays.indexOf(url) === -1)
|
|
2434
|
+
pointer.relays.push(url);
|
|
2435
|
+
});
|
|
2436
|
+
author.relays = pointer.relays;
|
|
2437
|
+
}
|
|
2438
|
+
function parse3(event) {
|
|
2439
|
+
const result = {
|
|
2440
|
+
root: void 0,
|
|
2441
|
+
rootKind: void 0,
|
|
2442
|
+
reply: void 0,
|
|
2443
|
+
replyKind: void 0,
|
|
2444
|
+
mentions: [],
|
|
2445
|
+
quotes: [],
|
|
2446
|
+
profiles: []
|
|
2447
|
+
};
|
|
2448
|
+
const rootCandidates = [];
|
|
2449
|
+
const replyCandidates = [];
|
|
2450
|
+
for (const tag of event.tags) {
|
|
2451
|
+
if ((tag[0] === "E" || tag[0] === "A" || tag[0] === "I") && tag[1]) {
|
|
2452
|
+
const pointer = parsePointer(tag);
|
|
2453
|
+
if (pointer)
|
|
2454
|
+
rootCandidates.push({ tagName: tag[0], pointer });
|
|
2455
|
+
continue;
|
|
2456
|
+
}
|
|
2457
|
+
if ((tag[0] === "e" || tag[0] === "a" || tag[0] === "i") && tag[1]) {
|
|
2458
|
+
const pointer = parsePointer(tag);
|
|
2459
|
+
if (pointer)
|
|
2460
|
+
replyCandidates.push({ tagName: tag[0], pointer });
|
|
2461
|
+
continue;
|
|
2462
|
+
}
|
|
2463
|
+
if (tag[0] === "K") {
|
|
2464
|
+
result.rootKind = parseKind(tag[1]);
|
|
2465
|
+
continue;
|
|
2466
|
+
}
|
|
2467
|
+
if (tag[0] === "k") {
|
|
2468
|
+
result.replyKind = parseKind(tag[1]);
|
|
2469
|
+
continue;
|
|
2470
|
+
}
|
|
2471
|
+
if (tag[0] === "q") {
|
|
2472
|
+
const pointer = parseQuote(tag);
|
|
2473
|
+
if (pointer)
|
|
2474
|
+
result.quotes.push(pointer);
|
|
2475
|
+
continue;
|
|
2476
|
+
}
|
|
2477
|
+
if ((tag[0] === "P" || tag[0] === "p") && tag[1]) {
|
|
2478
|
+
result.profiles.push({
|
|
2479
|
+
pubkey: tag[1],
|
|
2480
|
+
relays: tag[2] ? [tag[2]] : []
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
result.root = choosePointer(rootCandidates);
|
|
2485
|
+
result.reply = choosePointer(replyCandidates);
|
|
2486
|
+
inheritRelayHints(result.root, result.profiles);
|
|
2487
|
+
inheritRelayHints(result.reply, result.profiles);
|
|
2488
|
+
result.quotes.forEach((pointer) => inheritRelayHints(pointer, result.profiles));
|
|
2489
|
+
return result;
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2332
2492
|
// nip25.ts
|
|
2333
2493
|
var nip25_exports = {};
|
|
2334
2494
|
__export(nip25_exports, {
|
|
@@ -2376,12 +2536,12 @@ function getReactedEventPointer(event) {
|
|
|
2376
2536
|
// nip27.ts
|
|
2377
2537
|
var nip27_exports = {};
|
|
2378
2538
|
__export(nip27_exports, {
|
|
2379
|
-
parse: () =>
|
|
2539
|
+
parse: () => parse4
|
|
2380
2540
|
});
|
|
2381
2541
|
var noCharacter = /\W/m;
|
|
2382
2542
|
var noURLCharacter = /[^\w\/] |[^\w\/]$|$|,| /m;
|
|
2383
2543
|
var MAX_HASHTAG_LENGTH = 42;
|
|
2384
|
-
function*
|
|
2544
|
+
function* parse4(content) {
|
|
2385
2545
|
let emojis = [];
|
|
2386
2546
|
if (typeof content !== "string") {
|
|
2387
2547
|
for (let i2 = 0; i2 < content.tags.length; i2++) {
|
|
@@ -2692,12 +2852,12 @@ __export(nip47_exports, {
|
|
|
2692
2852
|
function parseConnectionString(connectionString) {
|
|
2693
2853
|
const { host, pathname, searchParams } = new URL(connectionString);
|
|
2694
2854
|
const pubkey = pathname || host;
|
|
2695
|
-
const
|
|
2855
|
+
const relays = searchParams.getAll("relay");
|
|
2696
2856
|
const secret = searchParams.get("secret");
|
|
2697
|
-
if (!pubkey ||
|
|
2857
|
+
if (!pubkey || relays.length === 0 || !secret) {
|
|
2698
2858
|
throw new Error("invalid connection string");
|
|
2699
2859
|
}
|
|
2700
|
-
return { pubkey, relay, secret };
|
|
2860
|
+
return { pubkey, relay: relays[0], relays, secret };
|
|
2701
2861
|
}
|
|
2702
2862
|
async function makeNwcRequestEvent(pubkey, secretKey, invoice) {
|
|
2703
2863
|
const content = {
|