bug: catch invalid zap

This commit is contained in:
Kieran 2023-02-14 14:53:00 +00:00
parent 77c6f3d22e
commit db001fbba5
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941

View File

@ -37,8 +37,12 @@ interface Zapper {
} }
function getZapper(zap: TaggedRawEvent, dhash: string): Zapper { function getZapper(zap: TaggedRawEvent, dhash: string): Zapper {
const zapRequest = findTag(zap, "description"); let zapRequest = findTag(zap, "description");
if (zapRequest) { if (zapRequest) {
try {
if (zapRequest.startsWith("%")) {
zapRequest = decodeURIComponent(zapRequest);
}
const rawEvent: TaggedRawEvent = JSON.parse(zapRequest); const rawEvent: TaggedRawEvent = JSON.parse(zapRequest);
if (Array.isArray(rawEvent)) { if (Array.isArray(rawEvent)) {
// old format, ignored // old format, ignored
@ -47,6 +51,9 @@ function getZapper(zap: TaggedRawEvent, dhash: string): Zapper {
const metaHash = sha256(zapRequest); const metaHash = sha256(zapRequest);
const ev = new Event(rawEvent); const ev = new Event(rawEvent);
return { pubkey: ev.PubKey, isValid: dhash === metaHash }; return { pubkey: ev.PubKey, isValid: dhash === metaHash };
} catch (e) {
console.warn("Invalid zap", zapRequest);
}
} }
return { isValid: false }; return { isValid: false };
} }