summaryrefslogtreecommitdiff
path: root/gui/src/logic/nostr.ts
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-11-19 05:47:30 +0700
committerpolwex <polwex@sortug.com>2025-11-19 05:47:30 +0700
commit74d84cb2f22600b6246343e9ea606cf0db7517f0 (patch)
tree0d68285c8e74e6543645e17ab2751d543c1ff9a6 /gui/src/logic/nostr.ts
parente6e657be3a3b1dae426b46f3bc16f9a5cf4861c2 (diff)
Big GUI improvements on Nostr rendering and fetchingpolwex/iris
Diffstat (limited to 'gui/src/logic/nostr.ts')
-rw-r--r--gui/src/logic/nostr.ts30
1 files changed, 19 insertions, 11 deletions
diff --git a/gui/src/logic/nostr.ts b/gui/src/logic/nostr.ts
index 3a9a586..3112f4b 100644
--- a/gui/src/logic/nostr.ts
+++ b/gui/src/logic/nostr.ts
@@ -21,26 +21,32 @@ export function generateNprofile(pubkey: string) {
const nprofile = nip19.nprofileEncode(prof);
return nprofile;
}
-export function isValidNostrKey(key: string): boolean {
+export function decodeNostrKey(key: string): string | null {
try {
- nip19.decode(key);
- return true;
+ const { type, data } = nip19.decode(key);
+ if (type === "nevent") return data.id;
+ else if (type === "nprofile") return data.pubkey;
+ else if (type === "naddr") return data.pubkey;
+ else if (type === "npub") return data;
+ else if (type === "nsec") return uint8ArrayToHexString(data);
+ else if (type === "note") return data;
+ else return null;
} catch (e) {
try {
+ // TODO do we want this for something
nip19.npubEncode(key);
- return true;
+ return key;
} catch (e2) {
console.error(e2, "not valid nostr key");
- return false;
+ return null;
}
}
}
-
-// let sk = generateSecretKey()
-// let nsec = nip19.nsecEncode(sk)
-// let { type, data } = nip19.decode(nsec)
-// assert(type === 'nsec')
-// assert(data === sk)
+function uint8ArrayToHexString(uint8Array: Uint8Array) {
+ return Array.from(uint8Array)
+ .map((byte) => byte.toString(16).padStart(2, "0"))
+ .join("");
+}
// let pk = getPublicKey(generateSecretKey())
// let npub = nip19.npubEncode(pk)
@@ -55,3 +61,5 @@ export function isValidNostrKey(key: string): boolean {
// assert(type === 'nprofile')
// assert(data.pubkey === pk)
// assert(data.relays.length === 2)
+//
+// nevent1qqsp3faj5jy9fpc6779rcs9kdccc0mxwlv2pnhymwqtjmletn72u5echttguv;