From 263ffd68ec8051dfad47d20fcb1ab1ea22ade520 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 20 Jan 2025 00:19:09 -0800 Subject: nostr threads --- lib/nostr.ts | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/nostr.ts b/lib/nostr.ts index 4fb79dfd..190873e2 100644 --- a/lib/nostr.ts +++ b/lib/nostr.ts @@ -2,7 +2,7 @@ import config from "$config"; import { db, g, s } from "$lib/db"; import { l, warn } from "$lib/logging"; import { count, scan, sync } from "$lib/strfry"; -import { fail } from "$lib/utils"; +import { fail, fields, getUser, pick } from "$lib/utils"; import { finalizeEvent, getPublicKey, nip19 } from "nostr-tools"; import { AbstractSimplePool } from "nostr-tools/abstract-pool"; import { Relay } from "nostr-tools/relay"; @@ -156,3 +156,38 @@ export const getCount = async (pubkey) => { console.log(e); } }; + +export const getNostrUser = async (key) => { + let user = await getUser(key); + + if (key.length === 64) { + const nostr: any = await getProfile(key); + if (nostr) { + nostr.username = nostr.name || key.substr(0, 6); + nostr.display = nostr.display_name || nostr.displayName; + nostr.display_name = undefined; + nostr.displayName = undefined; + nostr.name = undefined; + } + + if (user) { + user.anon = false; + nostr.display = undefined; + } + + user = { + ...nostr, + currency: "USD", + pubkey: key, + anon: true, + ...user, + }; + } + + if (!user) fail("User not found"); + + if (user.pubkey) user.npub = nip19.npubEncode(user.pubkey); + user.prompt = !!user.prompt; + + return pick(user, fields); +}; -- cgit v1.2.3