bug: catch invalid zap

This commit is contained in:
2023-02-14 14:53:00 +00:00
parent 3924aa0206
commit b75dc2d8d8

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 };
} }