Skip to content

Commit

Permalink
fix: drop hash validation from NIP-57
Browse files Browse the repository at this point in the history
  • Loading branch information
syusui-s committed Feb 12, 2024
1 parent ff73a0e commit ee0be6b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 deletions.
7 changes: 2 additions & 5 deletions src/components/modal/ZapRequestModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,8 @@ const ZapDialog: Component<ZapDialogProps> = (props) => {
}

const invoice = callbackResponse.pr;
await verifyInvoice(invoice, {
amountMilliSats,
metadata: endpointData.metadata,
zapRequest: callbackParams.zapRequest,
});

verifyInvoice(invoice, { amountMilliSats });

return invoice;
};
Expand Down
2 changes: 1 addition & 1 deletion src/nostr/zap/fetchLnurlCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const fetchLnurlCallback = async ({
callbackUrl.searchParams.set('nostr', JSON.stringify(zapRequest));
}

const res = await fetch(callbackUrl, { mode: 'cors' });
const res = await fetch(callbackUrl, { mode: 'cors', redirect: 'error' });
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const body = await res.json();

Expand Down
2 changes: 1 addition & 1 deletion src/nostr/zap/fetchLnurlEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const parseLnurlEndpointMetadata = (
};

const fetchLnurlEndpoint = async (lnurl: string): Promise<LnurlEndpoint | LnurlError> => {
const res = await fetch(lnurl, { mode: 'cors' });
const res = await fetch(lnurl, { mode: 'cors', redirect: 'error' });

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const body = await res.json();
Expand Down
22 changes: 1 addition & 21 deletions src/nostr/zap/verifyInvoice.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
import { type Event as NostrEvent } from 'nostr-tools/pure';

import { parseBolt11 } from '@/nostr/zap/bolt11';
import sha256Hex from '@/utils/sha256Hex';

const verifyInvoice = async (
bolt11: string,
requirements: { amountMilliSats: string; metadata: string; zapRequest?: NostrEvent },
): Promise<void> => {
const verifyInvoice = (bolt11: string, requirements: { amountMilliSats: string }) => {
const payReq = parseBolt11(bolt11);

const description =
requirements.zapRequest != null
? JSON.stringify(requirements.zapRequest)
: requirements.metadata;

if (payReq.tagsObject.description !== null && description === payReq.tagsObject.description) {
throw new Error("invalid invoice: description and didn't match");
}

const purposeCommitHash = await sha256Hex(description);
if (purposeCommitHash !== payReq.tagsObject.purpose_commit_hash) {
throw new Error("invalid invoice: hash value of purpose_commit_hash and didn't match");
}

if (payReq.millisatoshis != null && payReq.millisatoshis !== requirements.amountMilliSats) {
throw new Error("invalid invoice: amount didn't match");
}
Expand Down

0 comments on commit ee0be6b

Please sign in to comment.