applesauce-common 7.1.1 → 7.1.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.
- package/dist/helpers/zap.d.ts +4 -3
- package/dist/helpers/zap.js +18 -7
- package/package.json +1 -1
package/dist/helpers/zap.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const ZapReceiverSymbol: unique symbol;
|
|
|
11
11
|
export declare const ZapInvoiceSymbol: unique symbol;
|
|
12
12
|
export declare const ZapEventPointerSymbol: unique symbol;
|
|
13
13
|
export declare const ZapAddressPointerSymbol: unique symbol;
|
|
14
|
-
/** Returns the senders pubkey */
|
|
14
|
+
/** Returns the senders pubkey from the signed zap request */
|
|
15
15
|
export declare function getZapSender(zap: ZapEvent): string;
|
|
16
16
|
export declare function getZapSender(zap: NostrEvent): string | undefined;
|
|
17
17
|
/** Gets the receivers pubkey */
|
|
@@ -38,8 +38,9 @@ export declare function getZapRequest(zap: NostrEvent): ZapRequestEvent | undefi
|
|
|
38
38
|
*/
|
|
39
39
|
export declare function isValidZapRequest(event?: NostrEvent): event is ZapRequestEvent;
|
|
40
40
|
/**
|
|
41
|
-
* Checks if a zap
|
|
42
|
-
* DOES NOT validate LNURL
|
|
41
|
+
* Checks if a zap receipt is valid and its sender, recipient and amount match the signed zap request
|
|
42
|
+
* @note DOES NOT validate that the receipt was signed by the recipient's LNURL server
|
|
43
|
+
* @see https://github.com/nostr-protocol/nips/blob/master/57.md
|
|
43
44
|
*/
|
|
44
45
|
export declare function isValidZap(zap?: NostrEvent): zap is ZapEvent;
|
|
45
46
|
export type ZapSplit = {
|
package/dist/helpers/zap.js
CHANGED
|
@@ -13,7 +13,8 @@ export const ZapEventPointerSymbol = Symbol.for("zap-event-pointer");
|
|
|
13
13
|
export const ZapAddressPointerSymbol = Symbol.for("zap-address-pointer");
|
|
14
14
|
export function getZapSender(zap) {
|
|
15
15
|
return getOrComputeCachedValue(zap, ZapSenderSymbol, () => {
|
|
16
|
-
|
|
16
|
+
// Use the signature-verified zap request author, the receipt P tag is only a claim made by the LNURL server
|
|
17
|
+
return getZapRequest(zap)?.pubkey;
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
export function getZapRecipient(zap) {
|
|
@@ -97,8 +98,9 @@ export function isValidZapRequest(event) {
|
|
|
97
98
|
return true;
|
|
98
99
|
}
|
|
99
100
|
/**
|
|
100
|
-
* Checks if a zap
|
|
101
|
-
* DOES NOT validate LNURL
|
|
101
|
+
* Checks if a zap receipt is valid and its sender, recipient and amount match the signed zap request
|
|
102
|
+
* @note DOES NOT validate that the receipt was signed by the recipient's LNURL server
|
|
103
|
+
* @see https://github.com/nostr-protocol/nips/blob/master/57.md
|
|
102
104
|
*/
|
|
103
105
|
export function isValidZap(zap) {
|
|
104
106
|
if (!zap)
|
|
@@ -106,13 +108,22 @@ export function isValidZap(zap) {
|
|
|
106
108
|
if (zap.kind !== kinds.Zap)
|
|
107
109
|
return false;
|
|
108
110
|
// Is not a valid zap kind if any of these is undefined
|
|
109
|
-
|
|
111
|
+
const payment = getZapPayment(zap);
|
|
112
|
+
const request = getZapRequest(zap);
|
|
113
|
+
const recipient = getZapRecipient(zap);
|
|
114
|
+
if (!payment || !request || !recipient)
|
|
110
115
|
return false;
|
|
111
|
-
|
|
116
|
+
// The optional P tag must match the zap request author (anonymous zaps use the same ephemeral key for both)
|
|
117
|
+
const senderTag = getTagValue(zap, "P");
|
|
118
|
+
if (senderTag && senderTag !== request.pubkey)
|
|
112
119
|
return false;
|
|
113
|
-
|
|
120
|
+
// The receipt p tag must match the recipient of the zap request
|
|
121
|
+
const requestRecipient = getTagValue(request, "p");
|
|
122
|
+
if (requestRecipient !== recipient)
|
|
114
123
|
return false;
|
|
115
|
-
|
|
124
|
+
// The invoice amount must match the amount requested by the sender
|
|
125
|
+
const requestAmount = getTagValue(request, "amount");
|
|
126
|
+
if (requestAmount && parseInt(requestAmount) !== payment.amount)
|
|
116
127
|
return false;
|
|
117
128
|
return true;
|
|
118
129
|
}
|