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
1 changed files with 15 additions and 8 deletions

View File

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