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/esm/index.js CHANGED
@@ -1765,6 +1765,7 @@ var nip10_exports = {};
1765
1765
  __export(nip10_exports, {
1766
1766
  parse: () => parse
1767
1767
  });
1768
+ var HEX64 = /^[0-9a-fA-F]{64}$/;
1768
1769
  function parse(event) {
1769
1770
  const result = {
1770
1771
  reply: void 0,
@@ -1777,12 +1778,12 @@ function parse(event) {
1777
1778
  let maybeRoot;
1778
1779
  for (let i2 = event.tags.length - 1; i2 >= 0; i2--) {
1779
1780
  const tag = event.tags[i2];
1780
- if (tag[0] === "e" && tag[1]) {
1781
+ if (tag[0] === "e" && tag[1] && HEX64.test(tag[1])) {
1781
1782
  const [_, eTagEventId, eTagRelayUrl, eTagMarker, eTagAuthor] = tag;
1782
1783
  const eventPointer = {
1783
1784
  id: eTagEventId,
1784
1785
  relays: eTagRelayUrl ? [eTagRelayUrl] : [],
1785
- author: eTagAuthor
1786
+ author: eTagAuthor && HEX64.test(eTagAuthor) ? eTagAuthor : void 0
1786
1787
  };
1787
1788
  if (eTagMarker === "root") {
1788
1789
  result.root = eventPointer;
@@ -1804,14 +1805,14 @@ function parse(event) {
1804
1805
  result.mentions.push(eventPointer);
1805
1806
  continue;
1806
1807
  }
1807
- if (tag[0] === "q" && tag[1]) {
1808
+ if (tag[0] === "q" && tag[1] && HEX64.test(tag[1])) {
1808
1809
  const [_, eTagEventId, eTagRelayUrl] = tag;
1809
1810
  result.quotes.push({
1810
1811
  id: eTagEventId,
1811
1812
  relays: eTagRelayUrl ? [eTagRelayUrl] : []
1812
1813
  });
1813
1814
  }
1814
- if (tag[0] === "p" && tag[1]) {
1815
+ if (tag[0] === "p" && tag[1] && HEX64.test(tag[1])) {
1815
1816
  result.profiles.push({
1816
1817
  pubkey: tag[1],
1817
1818
  relays: tag[2] ? [tag[2]] : []
@@ -2308,6 +2309,7 @@ var nip22_exports = {};
2308
2309
  __export(nip22_exports, {
2309
2310
  parse: () => parse3
2310
2311
  });
2312
+ var HEX642 = /^[0-9a-fA-F]{64}$/;
2311
2313
  function parseKind(kind) {
2312
2314
  if (!kind)
2313
2315
  return void 0;
@@ -2321,9 +2323,12 @@ function parseAddressPointer(value, relayUrl) {
2321
2323
  const kind = parseInt(value.slice(0, idx), 10);
2322
2324
  if (Number.isNaN(kind))
2323
2325
  return void 0;
2326
+ const pubkey = value.slice(idx + 1, idx2);
2327
+ if (!HEX642.test(pubkey))
2328
+ return void 0;
2324
2329
  return {
2325
2330
  kind,
2326
- pubkey: value.slice(idx + 1, idx2),
2331
+ pubkey,
2327
2332
  identifier: value.slice(idx2 + 1),
2328
2333
  relays: relayUrl ? [relayUrl] : []
2329
2334
  };
@@ -2332,12 +2337,12 @@ function parsePointer(tag) {
2332
2337
  switch (tag[0]) {
2333
2338
  case "E":
2334
2339
  case "e":
2335
- if (!tag[1])
2340
+ if (!tag[1] || !HEX642.test(tag[1]))
2336
2341
  return void 0;
2337
2342
  return {
2338
2343
  id: tag[1],
2339
2344
  relays: tag[2] ? [tag[2]] : [],
2340
- author: tag[3]
2345
+ author: tag[3] && HEX642.test(tag[3]) ? tag[3] : void 0
2341
2346
  };
2342
2347
  case "A":
2343
2348
  case "a":
@@ -2360,10 +2365,12 @@ function parseQuote(tag) {
2360
2365
  if (tag[1].includes(":")) {
2361
2366
  return parseAddressPointer(tag[1], tag[2]);
2362
2367
  }
2368
+ if (!HEX642.test(tag[1]))
2369
+ return void 0;
2363
2370
  return {
2364
2371
  id: tag[1],
2365
2372
  relays: tag[2] ? [tag[2]] : [],
2366
- author: tag[3]
2373
+ author: tag[3] && HEX642.test(tag[3]) ? tag[3] : void 0
2367
2374
  };
2368
2375
  }
2369
2376
  function choosePointer(candidates) {
@@ -2423,7 +2430,7 @@ function parse3(event) {
2423
2430
  result.quotes.push(pointer);
2424
2431
  continue;
2425
2432
  }
2426
- if ((tag[0] === "P" || tag[0] === "p") && tag[1]) {
2433
+ if ((tag[0] === "P" || tag[0] === "p") && tag[1] && HEX642.test(tag[1])) {
2427
2434
  result.profiles.push({
2428
2435
  pubkey: tag[1],
2429
2436
  relays: tag[2] ? [tag[2]] : []