From fd098a90952269db708f4d2d21de085c968e835e Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Fri, 5 Sep 2025 19:43:20 -0500 Subject: Remove need for explicit key entry If window.nostr is available, I don't need the sender's SK, I can do everything with its functions. Otherwise, I'll ask for the SK using getPrivateKey(). The override public key was only for testing, but I still don't need it because I can get the users' private keys from the settings tab. --- src/routes/(app)/dm/[recipient]/+page.svelte | 40 +++++++++------------------- 1 file changed, 13 insertions(+), 27 deletions(-) (limited to 'src/routes') diff --git a/src/routes/(app)/dm/[recipient]/+page.svelte b/src/routes/(app)/dm/[recipient]/+page.svelte index 33edfcc6..446a1068 100644 --- a/src/routes/(app)/dm/[recipient]/+page.svelte +++ b/src/routes/(app)/dm/[recipient]/+page.svelte @@ -2,33 +2,26 @@ import Icon from "$comp/Icon.svelte"; import { hexToBytes, bytesToHex } from '@noble/hashes/utils'; import * as nip17 from 'nostr-tools/nip17'; - import { createNIP17Message } from '$lib/nip17'; + import { createNIP17MessageSK, createNIP17MessageNIP07 } from '$lib/nip17'; import { sign, getPrivateKey } from '$lib/nostr'; let { data } = $props(); const { user, recipient } = data; - let senderSK = $state(""); - let overridePK = $state(""); let text = $state(""); - getPrivateKey(user) - .then(key => senderSK = bytesToHex(key)) - .catch(console.log); - - const btnCreateMessage = () => { - try { - const recipientPK = overridePK || recipient.pubkey; - const skBytes = hexToBytes(senderSK); - const event = createNIP17Message(text, skBytes, recipientPK); - event.then(displayEvent); - } catch (error) { - console.log(error); + const btnCreateMessage = async () => { + let event; + if (window.nostr) { + event = await createNIP17MessageNIP07( + text, user.pubkey, recipient.pubkey); + } else { + const sk = await getPrivateKey(user); + event = createNIP17MessageSK(text, sk, recipient.pubkey); } - } - const displayEvent = (event: object) => { - console.log(JSON.stringify(event)); + // TODO send event to relays instead of displaying it + text = JSON.stringify(event); } @@ -45,17 +38,10 @@

Direct Messages

-

Testing Message: You are sending nostr messages to {recipient.username}. Their pubkey is {recipient.pubkey}.

- - - - - - +

You are sending nostr messages to {recipient.username}.

- - + -- cgit v1.2.3