mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-17 05:54:19 +01:00
feat: detailed error in verifyInvoice
This commit is contained in:
@@ -247,16 +247,11 @@ const ZapDialog: Component<ZapDialogProps> = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const invoice = callbackResponse.pr;
|
const invoice = callbackResponse.pr;
|
||||||
console.log(callbackResponse, invoice);
|
await verifyInvoice(invoice, {
|
||||||
if (
|
|
||||||
!(await verifyInvoice(invoice, {
|
|
||||||
amountMilliSats,
|
amountMilliSats,
|
||||||
metadata: endpointData.metadata,
|
metadata: endpointData.metadata,
|
||||||
zapRequest: callbackParams.zapRequest,
|
zapRequest: callbackParams.zapRequest,
|
||||||
}))
|
});
|
||||||
) {
|
|
||||||
throw new Error('Invalid invoice');
|
|
||||||
}
|
|
||||||
|
|
||||||
return invoice;
|
return invoice;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,17 +6,26 @@ import sha256Hex from '@/utils/sha256Hex';
|
|||||||
const verifyInvoice = async (
|
const verifyInvoice = async (
|
||||||
bolt11: string,
|
bolt11: string,
|
||||||
requirements: { amountMilliSats: string; metadata: string; zapRequest?: NostrEvent },
|
requirements: { amountMilliSats: string; metadata: string; zapRequest?: NostrEvent },
|
||||||
): Promise<boolean> => {
|
): Promise<void> => {
|
||||||
const payReq = parseBolt11(bolt11);
|
const payReq = parseBolt11(bolt11);
|
||||||
|
|
||||||
return (
|
const description =
|
||||||
(requirements.zapRequest != null
|
requirements.zapRequest != null
|
||||||
? payReq.tagsObject.purpose_commit_hash ===
|
? JSON.stringify(requirements.zapRequest)
|
||||||
(await sha256Hex(JSON.stringify(requirements.zapRequest)))
|
: requirements.metadata;
|
||||||
: payReq.tagsObject.purpose_commit_hash === (await sha256Hex(requirements.metadata))) &&
|
|
||||||
payReq.millisatoshis != null &&
|
if (payReq.tagsObject.description !== null && description === payReq.tagsObject.description) {
|
||||||
payReq.millisatoshis === requirements.amountMilliSats
|
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");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default verifyInvoice;
|
export default verifyInvoice;
|
||||||
|
|||||||
Reference in New Issue
Block a user