feat: check zap service pubkeys
This commit is contained in:
parent
c702d1b760
commit
b71c279a0d
@ -10,6 +10,7 @@ import Text from "Element/Text";
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import { RootState } from "State/Store";
|
||||
import { ZapperSpam } from "Const";
|
||||
import { UserCache } from "State/Users/UserCache";
|
||||
|
||||
import messages from "./messages";
|
||||
|
||||
@ -75,6 +76,10 @@ export function parseZap(zapReceipt: TaggedRawEvent): ParsedZap {
|
||||
ret.valid = false;
|
||||
ret.errors.push("amount tag does not match invoice amount");
|
||||
}
|
||||
if (UserCache.get(ret.receiver)?.zapService !== ret.zapService) {
|
||||
ret.valid = false;
|
||||
ret.errors.push("zap service pubkey doesn't match");
|
||||
}
|
||||
if (!ret.valid) {
|
||||
console.debug("Invalid zap", ret);
|
||||
}
|
||||
|
@ -111,6 +111,13 @@ export class LNURL {
|
||||
return this.#service?.nostrPubkey ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return pubkey of zap service
|
||||
*/
|
||||
get zapperPubkey() {
|
||||
return this.#service?.nostrPubkey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the max allowed comment length
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { HexKey } from "@snort/nostr";
|
||||
import { db } from "Db";
|
||||
import { LNURL } from "LNURL";
|
||||
import { unixNowMs, unwrap } from "Util";
|
||||
import { MetadataCache } from ".";
|
||||
|
||||
@ -99,6 +100,18 @@ export class UserProfileCache {
|
||||
if (!existing || existing.created < m.created || refresh) {
|
||||
this.#cache.set(m.pubkey, m);
|
||||
if (db.ready) {
|
||||
// fetch zapper key
|
||||
const lnurl = m.lud16 || m.lud06;
|
||||
if (lnurl) {
|
||||
try {
|
||||
const svc = new LNURL(lnurl);
|
||||
await svc.load();
|
||||
m.zapService = svc.zapperPubkey;
|
||||
} catch {
|
||||
console.debug("Failed to load LNURL for zapper pubkey", lnurl);
|
||||
}
|
||||
// ignored
|
||||
}
|
||||
await db.users.put(m);
|
||||
this.#diskCache.add(m.pubkey);
|
||||
}
|
||||
|
@ -21,6 +21,11 @@ export interface MetadataCache extends UserMetadata {
|
||||
* The bech32 encoded pubkey
|
||||
*/
|
||||
npub: string;
|
||||
|
||||
/**
|
||||
* Pubkey of zapper service
|
||||
*/
|
||||
zapService?: HexKey;
|
||||
}
|
||||
|
||||
export function mapEventToProfile(ev: TaggedRawEvent) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user