nostr-tools 2.23.7 → 2.23.8

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 CHANGED
@@ -1826,6 +1826,7 @@ var nip10_exports = {};
1826
1826
  __export(nip10_exports, {
1827
1827
  parse: () => parse
1828
1828
  });
1829
+ var HEX64 = /^[0-9a-fA-F]{64}$/;
1829
1830
  function parse(event) {
1830
1831
  const result = {
1831
1832
  reply: void 0,
@@ -1838,12 +1839,12 @@ function parse(event) {
1838
1839
  let maybeRoot;
1839
1840
  for (let i2 = event.tags.length - 1; i2 >= 0; i2--) {
1840
1841
  const tag = event.tags[i2];
1841
- if (tag[0] === "e" && tag[1]) {
1842
+ if (tag[0] === "e" && tag[1] && HEX64.test(tag[1])) {
1842
1843
  const [_, eTagEventId, eTagRelayUrl, eTagMarker, eTagAuthor] = tag;
1843
1844
  const eventPointer = {
1844
1845
  id: eTagEventId,
1845
1846
  relays: eTagRelayUrl ? [eTagRelayUrl] : [],
1846
- author: eTagAuthor
1847
+ author: eTagAuthor && HEX64.test(eTagAuthor) ? eTagAuthor : void 0
1847
1848
  };
1848
1849
  if (eTagMarker === "root") {
1849
1850
  result.root = eventPointer;
@@ -1865,14 +1866,14 @@ function parse(event) {
1865
1866
  result.mentions.push(eventPointer);
1866
1867
  continue;
1867
1868
  }
1868
- if (tag[0] === "q" && tag[1]) {
1869
+ if (tag[0] === "q" && tag[1] && HEX64.test(tag[1])) {
1869
1870
  const [_, eTagEventId, eTagRelayUrl] = tag;
1870
1871
  result.quotes.push({
1871
1872
  id: eTagEventId,
1872
1873
  relays: eTagRelayUrl ? [eTagRelayUrl] : []
1873
1874
  });
1874
1875
  }
1875
- if (tag[0] === "p" && tag[1]) {
1876
+ if (tag[0] === "p" && tag[1] && HEX64.test(tag[1])) {
1876
1877
  result.profiles.push({
1877
1878
  pubkey: tag[1],
1878
1879
  relays: tag[2] ? [tag[2]] : []
@@ -2369,6 +2370,7 @@ var nip22_exports = {};
2369
2370
  __export(nip22_exports, {
2370
2371
  parse: () => parse3
2371
2372
  });
2373
+ var HEX642 = /^[0-9a-fA-F]{64}$/;
2372
2374
  function parseKind(kind) {
2373
2375
  if (!kind)
2374
2376
  return void 0;
@@ -2382,9 +2384,12 @@ function parseAddressPointer(value, relayUrl) {
2382
2384
  const kind = parseInt(value.slice(0, idx), 10);
2383
2385
  if (Number.isNaN(kind))
2384
2386
  return void 0;
2387
+ const pubkey = value.slice(idx + 1, idx2);
2388
+ if (!HEX642.test(pubkey))
2389
+ return void 0;
2385
2390
  return {
2386
2391
  kind,
2387
- pubkey: value.slice(idx + 1, idx2),
2392
+ pubkey,
2388
2393
  identifier: value.slice(idx2 + 1),
2389
2394
  relays: relayUrl ? [relayUrl] : []
2390
2395
  };
@@ -2393,12 +2398,12 @@ function parsePointer(tag) {
2393
2398
  switch (tag[0]) {
2394
2399
  case "E":
2395
2400
  case "e":
2396
- if (!tag[1])
2401
+ if (!tag[1] || !HEX642.test(tag[1]))
2397
2402
  return void 0;
2398
2403
  return {
2399
2404
  id: tag[1],
2400
2405
  relays: tag[2] ? [tag[2]] : [],
2401
- author: tag[3]
2406
+ author: tag[3] && HEX642.test(tag[3]) ? tag[3] : void 0
2402
2407
  };
2403
2408
  case "A":
2404
2409
  case "a":
@@ -2421,10 +2426,12 @@ function parseQuote(tag) {
2421
2426
  if (tag[1].includes(":")) {
2422
2427
  return parseAddressPointer(tag[1], tag[2]);
2423
2428
  }
2429
+ if (!HEX642.test(tag[1]))
2430
+ return void 0;
2424
2431
  return {
2425
2432
  id: tag[1],
2426
2433
  relays: tag[2] ? [tag[2]] : [],
2427
- author: tag[3]
2434
+ author: tag[3] && HEX642.test(tag[3]) ? tag[3] : void 0
2428
2435
  };
2429
2436
  }
2430
2437
  function choosePointer(candidates) {
@@ -2484,7 +2491,7 @@ function parse3(event) {
2484
2491
  result.quotes.push(pointer);
2485
2492
  continue;
2486
2493
  }
2487
- if ((tag[0] === "P" || tag[0] === "p") && tag[1]) {
2494
+ if ((tag[0] === "P" || tag[0] === "p") && tag[1] && HEX642.test(tag[1])) {
2488
2495
  result.profiles.push({
2489
2496
  pubkey: tag[1],
2490
2497
  relays: tag[2] ? [tag[2]] : []