From 54fe377aa078fc141c2d77c0681f2d42f08f16de Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Thu, 15 Aug 2024 23:41:07 +0200 Subject: [PATCH] fix --- src/stores/nostr.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/stores/nostr.ts b/src/stores/nostr.ts index 69cb9213..d02f343b 100644 --- a/src/stores/nostr.ts +++ b/src/stores/nostr.ts @@ -1,7 +1,7 @@ import { defineStore } from "pinia"; import NDK, { NDKEvent, NDKSigner, NDKNip07Signer, NDKNip46Signer, NDKFilter, NDKPrivateKeySigner, NostrEvent } from "@nostr-dev-kit/ndk"; import { nip19 } from 'nostr-tools' -import { bytesToHex } from '@noble/hashes/utils' // already an installed dependency +import { bytesToHex, hexToBytes } from '@noble/hashes/utils' // already an installed dependency import { useWalletStore } from "./wallet"; import { generateSecretKey, getPublicKey } from 'nostr-tools' import { useLocalStorage } from "@vueuse/core"; @@ -126,23 +126,25 @@ export const useNostrStore = defineStore("nostr", { await this.initWalletSeedPrivateKeySigner(); }, initPrivateKeySigner: async function (nsec?: string) { + let privateKeyBytes: Uint8Array; if (!nsec && !this.privateKeySignerPrivateKey.length) { nsec = await prompt("Enter your nsec") as string; if (!nsec) { return; } - const privateKeyBytes = nip19.decode(nsec).data as Uint8Array - this.privateKeySignerPrivateKey = bytesToHex(privateKeyBytes); + privateKeyBytes = nip19.decode(nsec).data as Uint8Array } else { if (nsec) { - const privateKeyBytes = nip19.decode(nsec).data as Uint8Array - this.privateKeySignerPrivateKey = bytesToHex(privateKeyBytes); + privateKeyBytes = nip19.decode(nsec).data as Uint8Array + } else { + privateKeyBytes = hexToBytes(this.privateKeySignerPrivateKey); } } this.privateKeySigner = new NDKPrivateKeySigner(this.privateKeySignerPrivateKey); this.signerType = SignerType.PRIVATEKEY; await this.setSigner(this.privateKeySigner); - this.setPubkey(this.privateKeySignerPrivateKey); + const publicKeyHex = getPublicKey(privateKeyBytes); + this.setPubkey(publicKeyHex); }, resetPrivateKeySigner: async function () { this.privateKeySignerPrivateKey = "";