applesauce-core 4.4.1 → 4.4.2

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.
@@ -1,4 +1,4 @@
1
- import { NostrEvent, VerifiedEvent } from "nostr-tools";
1
+ import { NostrEvent, VerifiedEvent } from "nostr-tools/pure";
2
2
  import { IEventStore } from "../event-store/interface.js";
3
3
  export { NostrEvent, EventTemplate, UnsignedEvent, verifiedSymbol, verifyEvent, VerifiedEvent } from "nostr-tools/pure";
4
4
  export { bytesToHex, hexToBytes, insertEventIntoAscendingList, insertEventIntoDescendingList, binarySearch, } from "nostr-tools/utils";
@@ -36,6 +36,12 @@ export declare function getReplaceableAddress(event: NostrEvent): string;
36
36
  export declare function createReplaceableAddress(kind: number, pubkey: string, identifier?: string): string;
37
37
  /** @deprecated use createReplaceableAddress instead */
38
38
  export declare const getReplaceableUID: typeof createReplaceableAddress;
39
+ /** Method used to verify an events signature */
40
+ export type VerifyEventMethod = (event: NostrEvent) => event is VerifiedEvent;
41
+ /** Sets the internal method used to verify events in helpers (zaps, gift-wraps, etc) */
42
+ export declare function setVerifyWrappedEventMethod(method: VerifyEventMethod): void;
43
+ /** Verifies an internal (wrapped) event using the set internal verification method */
44
+ export declare function verifyWrappedEvent(event: NostrEvent): event is VerifiedEvent;
39
45
  /** Sets events verified flag without checking anything */
40
46
  export declare function fakeVerifyEvent(event: NostrEvent): event is VerifiedEvent;
41
47
  /** Marks an event as being from a cache */
@@ -1,4 +1,4 @@
1
- import { verifiedSymbol } from "nostr-tools";
1
+ import { verifiedSymbol, verifyEvent } from "nostr-tools/pure";
2
2
  import { isAddressableKind, isReplaceableKind } from "nostr-tools/kinds";
3
3
  import { getOrComputeCachedValue } from "./cache.js";
4
4
  // Re-export types from nostr-tools
@@ -65,6 +65,16 @@ export function createReplaceableAddress(kind, pubkey, identifier) {
65
65
  }
66
66
  /** @deprecated use createReplaceableAddress instead */
67
67
  export const getReplaceableUID = createReplaceableAddress;
68
+ // Internal method for verifying events (used by zaps, gift-wraps, etc)
69
+ let verifyWrappedEventMethod = verifyEvent;
70
+ /** Sets the internal method used to verify events in helpers (zaps, gift-wraps, etc) */
71
+ export function setVerifyWrappedEventMethod(method) {
72
+ verifyWrappedEventMethod = method;
73
+ }
74
+ /** Verifies an internal (wrapped) event using the set internal verification method */
75
+ export function verifyWrappedEvent(event) {
76
+ return verifyWrappedEventMethod(event);
77
+ }
68
78
  /** Sets events verified flag without checking anything */
69
79
  export function fakeVerifyEvent(event) {
70
80
  event[verifiedSymbol] = true;
@@ -1,7 +1,7 @@
1
- import { kinds, verifyEvent } from "nostr-tools";
1
+ import { kinds } from "nostr-tools";
2
2
  import { EventMemory } from "../event-store/event-memory.js";
3
3
  import { getEncryptedContent, isEncryptedContentUnlocked, lockEncryptedContent, unlockEncryptedContent, } from "./encrypted-content.js";
4
- import { notifyEventUpdate } from "./event.js";
4
+ import { notifyEventUpdate, verifyWrappedEvent } from "./event.js";
5
5
  /**
6
6
  * An internal event set to keep track of seals and rumors
7
7
  * This is intentionally isolated from the main applications event store so to prevent seals and rumors from being leaked
@@ -130,7 +130,7 @@ export function getGiftWrapSeal(gift) {
130
130
  }
131
131
  else {
132
132
  // Verify the seal event
133
- verifyEvent(seal);
133
+ verifyWrappedEvent(seal);
134
134
  // Add to the internal event set
135
135
  internalGiftWrapEvents.add(seal);
136
136
  // Set the reference to the parent gift wrap event (upstream)
@@ -1,7 +1,8 @@
1
- import { kinds, nip57 } from "nostr-tools";
1
+ import { kinds, validateEvent } from "nostr-tools";
2
2
  import { parseBolt11 } from "./bolt11.js";
3
3
  import { getOrComputeCachedValue } from "./cache.js";
4
4
  import { getTagValue } from "./event-tags.js";
5
+ import { verifyWrappedEvent } from "./index.js";
5
6
  import { getAddressPointerFromATag, getEventPointerFromETag } from "./pointers.js";
6
7
  import { isATag, isETag } from "./tags.js";
7
8
  export const ZapRequestSymbol = Symbol.for("zap-request");
@@ -60,10 +61,30 @@ export function getZapRequest(zap) {
60
61
  return;
61
62
  // Attempt to parse the zap request
62
63
  try {
63
- const error = nip57.validateZapRequest(description);
64
- if (error)
65
- return;
66
- return JSON.parse(description);
64
+ // Copied from nostr-tools/nip57 and modified to use the internal verifyZap method and return the zap request event
65
+ let zapRequest;
66
+ try {
67
+ zapRequest = JSON.parse(description);
68
+ }
69
+ catch (err) {
70
+ throw new Error("Invalid zap request JSON.");
71
+ }
72
+ if (!validateEvent(zapRequest))
73
+ throw new Error("Zap request is not a valid Nostr event.");
74
+ if (!verifyWrappedEvent(zapRequest))
75
+ throw new Error("Invalid signature on zap request.");
76
+ let p = zapRequest.tags.find(([t, v]) => t === "p" && v);
77
+ if (!p)
78
+ throw new Error("Zap request doesn't have a 'p' tag.");
79
+ if (!p[1].match(/^[a-f0-9]{64}$/))
80
+ throw new Error("Zap request 'p' tag is not valid hex.");
81
+ let e = zapRequest.tags.find(([t, v]) => t === "e" && v);
82
+ if (e && !e[1].match(/^[a-f0-9]{64}$/))
83
+ throw new Error("Zap request 'e' tag is not valid hex.");
84
+ let relays = zapRequest.tags.find(([t, v]) => t === "relays" && v);
85
+ if (!relays)
86
+ throw new Error("Zap request doesn't have a 'relays' tag.");
87
+ return zapRequest;
67
88
  }
68
89
  catch (error) {
69
90
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "4.4.1",
3
+ "version": "4.4.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",