From 60735521a3549089f639fdefb921030c23a4d74b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 28 Nov 2023 15:43:30 -0800 Subject: nostr key reveal --- src/lib/nostr.js | 6 ++- src/locales/en.json | 7 +++ .../[username]/settings/[...tab]/_security.svelte | 53 ++++++++++++++++++++-- 3 files changed, 61 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/lib/nostr.js b/src/lib/nostr.js index 28dbe50f..c2634c83 100644 --- a/src/lib/nostr.js +++ b/src/lib/nostr.js @@ -3,7 +3,7 @@ import { Buffer } from 'buffer'; import { fail, wait, post, stretch } from '$lib/utils'; import { decrypted, password as pw, passwordPrompt, pin, loginRedirect } from '$lib/store'; import { goto, invalidate } from '$app/navigation'; -import { getPublicKey, signEvent, getEventHash, nip04, nip06 } from 'nostr-tools'; +import { getPublicKey, signEvent, getEventHash, nip04, nip06, nip19 } from 'nostr-tools'; import { mnemonicToEntropy, entropyToMnemonic } from '@scure/bip39'; import wordlist from '$lib/english'; import { bech32m } from '@scure/base'; @@ -92,6 +92,10 @@ let getPrivateKey = async (user) => { return privateKeyFromSeedWords(await getMnemonic(user)); }; +export let getNsec = async (user) => { + return nip19.nsecEncode(await getPrivateKey(user)); +}; + export let sign = async ({ event, user }) => { event.id = getEventHash(event); event.sig = signEvent(event, await getPrivateKey(user)); diff --git a/src/locales/en.json b/src/locales/en.json index 2e7b2079..608668a9 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -197,6 +197,13 @@ "placeholder": "Paste a bitcoin address, lightning invoice or coinos username" }, "settings": { + "seedPhrase": "Seed phrase", + "nostrKeys": "Nostr key", + "nostrDescription": "Your nostr key is used to sign and decrypt messages, keep it safe or someone may be able to impersonate you.", + "seedDescription": "This 12 word seed phrase is used to derive your nostr private key and your self-custodial wallet keys which determine your auto-withdrawal addresses. Back it up and don't let anyone see it.", + "emailDescription": "For password resets and notifications", + "hideNsec": "Hide nostr secret key", + "revealNsec": "Reveal nostr secret key", "hideSeed": "Hide seed phrase", "revealSeed": "Reveal seed phrase", "saveSettings": "Save Settings", diff --git a/src/routes/(app)/[username]/settings/[...tab]/_security.svelte b/src/routes/(app)/[username]/settings/[...tab]/_security.svelte index 170df744..113f7d7e 100644 --- a/src/routes/(app)/[username]/settings/[...tab]/_security.svelte +++ b/src/routes/(app)/[username]/settings/[...tab]/_security.svelte @@ -1,5 +1,5 @@