bug: catch invalid zap
This commit is contained in:
parent
77c6f3d22e
commit
db001fbba5
@ -37,16 +37,23 @@ 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) {
|
||||||
const rawEvent: TaggedRawEvent = JSON.parse(zapRequest);
|
try {
|
||||||
if (Array.isArray(rawEvent)) {
|
if (zapRequest.startsWith("%")) {
|
||||||
// old format, ignored
|
zapRequest = decodeURIComponent(zapRequest);
|
||||||
return { isValid: false };
|
}
|
||||||
|
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 };
|
return { isValid: false };
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user