diff options
| author | Adam Soltys <[email protected]> | 2025-01-20 00:19:09 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-01-20 00:19:09 -0800 |
| commit | 263ffd68ec8051dfad47d20fcb1ab1ea22ade520 (patch) | |
| tree | b3d2db9cfd9b7b8a5f1fd328cf8b55d9196862ab /lib | |
| parent | a55eb812c4ea6dc9573f2bdf40f058a1d3ba90ee (diff) | |
| download | coinos-server-263ffd68ec8051dfad47d20fcb1ab1ea22ade520.tar.gz coinos-server-263ffd68ec8051dfad47d20fcb1ab1ea22ade520.zip | |
nostr threads
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/nostr.ts | 37 |
1 files changed, 36 insertions, 1 deletions
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); +}; |
