From cbc2f7a8e89d049a68ff520e6d640753c877bf57 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 22 Jan 2025 15:29:37 -0800 Subject: use nsec if available --- src/lib/nostr.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/nostr.ts b/src/lib/nostr.ts index 85f1bdaa..a5b2d990 100644 --- a/src/lib/nostr.ts +++ b/src/lib/nostr.ts @@ -8,6 +8,7 @@ import { signer as $signer, } from "$lib/store"; import { post, wait } from "$lib/utils"; +import { bytesToHex } from "@noble/hashes/utils"; import { type EventTemplate, finalizeEvent, @@ -102,7 +103,17 @@ export const encryptNsec = async (nsec: string) => { return nip49encrypt(d, await getPassword()); }; -export const sign = async (event) => { +export const sign = async (event, user) => { + if (user?.nsec && !get($signer)?.ready) { + const sk = await getPrivateKey(user); + + $signer.set({ + method: "nsec", + ready: true, + params: { sk: bytesToHex(sk), pk: getPublicKey(sk) }, + }); + } + eventToSign.set(event); let unsubscribe; const { method, params } = await new Promise((r) => { -- cgit v1.2.3