diff options
| author | Adam Soltys <[email protected]> | 2025-01-23 20:39:51 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-01-23 20:39:51 -0800 |
| commit | dbca79c616ec2fec6bae94fb33587b84e1a66055 (patch) | |
| tree | d2a8d10898648ae0d21d0995a0bc1a3d6f8a238e /src | |
| parent | 3f258ea37faf150f201fa76504a874596ee7905f (diff) | |
| download | coinos-ui-dbca79c616ec2fec6bae94fb33587b84e1a66055.tar.gz coinos-ui-dbca79c616ec2fec6bae94fb33587b84e1a66055.zip | |
fix nostr connect
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Nostr.svelte | 27 | ||||
| -rw-r--r-- | src/lib/nostr.ts | 11 |
2 files changed, 20 insertions, 18 deletions
diff --git a/src/components/Nostr.svelte b/src/components/Nostr.svelte index a4f20d23..5a97473c 100644 --- a/src/components/Nostr.svelte +++ b/src/components/Nostr.svelte @@ -12,6 +12,7 @@ generateSecretKey, getPublicKey, } from "nostr-tools"; + import { getConversationKey, decrypt } from "nostr-tools/nip44"; import { AmberClipboardSigner } from "applesauce-signer"; import { copy, focus, fail, post } from "$lib/utils"; @@ -52,10 +53,17 @@ async onevent(event) { let pk = event.pubkey; try { - let { result } = JSON.parse( - await nip04.decrypt(sk, pk, event.content), - ); - if (result === connectionSecret) { + let result; + try { + ({ result } = JSON.parse( + await nip04.decrypt(sk, pk, event.content), + )); + } catch (e) { + let ck = await getConversationKey(sk, pk); + ({ result } = JSON.parse(await decrypt(event.content, ck))); + } + + if (result === connectionSecret || result === "ack") { $signer = { method: "connect", params: { @@ -156,17 +164,6 @@ </button> {/if} - {#if $signer?.method === "signer"} - <a href={signUrl} type="button" class="btn" onclick={signerSign}> - <iconify-icon - icon="material-symbols:diamond-rounded" - width="32" - class="text-orange-400" - ></iconify-icon> - <div class="my-auto">NIP-55 Signer</div> - </a> - {/if} - {#if !$signer} {#if extensionAvailable} <button type="button" class="btn" onclick={extensionSign}> diff --git a/src/lib/nostr.ts b/src/lib/nostr.ts index a5b2d990..bfaa14c1 100644 --- a/src/lib/nostr.ts +++ b/src/lib/nostr.ts @@ -17,6 +17,7 @@ import { nip04, nip19, } from "nostr-tools"; +import { decrypt as nip44decrypt, getConversationKey } from "nostr-tools/nip44"; import { Relay } from "nostr-tools/relay"; import { get } from "svelte/store"; @@ -168,9 +169,13 @@ const signingMethods = { async onevent(event) { pk = event.pubkey; try { - const response = JSON.parse( - await nip04.decrypt(sk, pk, event.content), - ); + let response; + try { + response = JSON.parse(await nip04.decrypt(sk, pk, event.content)); + } catch (e) { + const ck = await getConversationKey(sk, pk); + response = JSON.parse(await nip44decrypt(event.content, ck)); + } if (response.id === id) resolve(JSON.parse(response.result)); } catch (e) { |
