feat: check zap service pubkeys

This commit is contained in:
Kieran 2023-03-05 17:54:55 +00:00
parent c702d1b760
commit b71c279a0d
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
4 changed files with 30 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import Text from "Element/Text";
import ProfileImage from "Element/ProfileImage"; import ProfileImage from "Element/ProfileImage";
import { RootState } from "State/Store"; import { RootState } from "State/Store";
import { ZapperSpam } from "Const"; import { ZapperSpam } from "Const";
import { UserCache } from "State/Users/UserCache";
import messages from "./messages"; import messages from "./messages";
@ -75,6 +76,10 @@ export function parseZap(zapReceipt: TaggedRawEvent): ParsedZap {
ret.valid = false; ret.valid = false;
ret.errors.push("amount tag does not match invoice amount"); 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) { if (!ret.valid) {
console.debug("Invalid zap", ret); console.debug("Invalid zap", ret);
} }

View File

@ -111,6 +111,13 @@ export class LNURL {
return this.#service?.nostrPubkey ? true : false; return this.#service?.nostrPubkey ? true : false;
} }
/**
* Return pubkey of zap service
*/
get zapperPubkey() {
return this.#service?.nostrPubkey;
}
/** /**
* Get the max allowed comment length * Get the max allowed comment length
*/ */

View File

@ -1,5 +1,6 @@
import { HexKey } from "@snort/nostr"; import { HexKey } from "@snort/nostr";
import { db } from "Db"; import { db } from "Db";
import { LNURL } from "LNURL";
import { unixNowMs, unwrap } from "Util"; import { unixNowMs, unwrap } from "Util";
import { MetadataCache } from "."; import { MetadataCache } from ".";
@ -99,6 +100,18 @@ export class UserProfileCache {
if (!existing || existing.created < m.created || refresh) { if (!existing || existing.created < m.created || refresh) {
this.#cache.set(m.pubkey, m); this.#cache.set(m.pubkey, m);
if (db.ready) { 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); await db.users.put(m);
this.#diskCache.add(m.pubkey); this.#diskCache.add(m.pubkey);
} }

View File

@ -21,6 +21,11 @@ export interface MetadataCache extends UserMetadata {
* The bech32 encoded pubkey * The bech32 encoded pubkey
*/ */
npub: string; npub: string;
/**
* Pubkey of zapper service
*/
zapService?: HexKey;
} }
export function mapEventToProfile(ev: TaggedRawEvent) { export function mapEventToProfile(ev: TaggedRawEvent) {