aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/nostr.ts37
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);
+};