Skip to content

Commit

Permalink
Reveal nsec and mnemonic.
Browse files Browse the repository at this point in the history
  • Loading branch information
chmac committed Nov 23, 2024
1 parent 7e31acd commit 042066f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
25 changes: 15 additions & 10 deletions nr-app/app/(tabs)/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { getPrivateKeyHex } from "@/nostr/keystore.nostr";
import {
getPrivateKeyHex,
getPrivateKeyMnemonic,
} from "@/nostr/keystore.nostr";
import { setVisiblePlusCodes } from "@/redux/actions/map.actions";
import { useAppDispatch, useAppSelector } from "@/redux/hooks";
import { setPrivateKeyPromiseAction } from "@/redux/sagas/keystore.saga";
Expand All @@ -16,6 +19,7 @@ import {

export default function TabThreeScreen() {
const [nsec, setNsec] = useState("");
const [mnemonic, setMnemonic] = useState("");
const hasPrivateKey = useAppSelector(
keystoreSelectors.selectHasPrivateKeyInSecureStorage,
);
Expand All @@ -40,28 +44,29 @@ export default function TabThreeScreen() {
<Text style={styles.settings}>pub key hex</Text>
<TextInput style={styles.input} value={pubHex} />
<Text style={styles.settings}>nsec</Text>
{/* <TextInput style={styles.input} value={account.privateKey.bech32} /> */}
<Text style={styles.settings}>seed</Text>
{/* <TextInput style={styles.input} value={mnemonic} /> */}
<Text style={styles.header}>Relays</Text>
<TextInput style={styles.input} value="['relay1', 'relay2']" />
<Text style={styles.header}>Help</Text>
<Text style={styles.q}>How does this work?</Text>

<Button
title="Get nsec"
title="Get nsec and mnemonic"
onPress={async () => {
const keyHex = await getPrivateKeyHex();
const mnemonic = await getPrivateKeyMnemonic();
const { bech32PrivateKey } = getBech32PrivateKey({
privateKey: keyHex,
});
setNsec(bech32PrivateKey);
setMnemonic(mnemonic);
setTimeout(() => {
setNsec("");
setMnemonic("");
}, 3e3);
}}
/>
<TextInput style={styles.input} value={nsec} />
<Text style={styles.settings}>seed</Text>
<TextInput style={styles.input} value={mnemonic} />
<Text style={styles.header}>Relays</Text>
<TextInput style={styles.input} value="['relay1', 'relay2']" />
<Text style={styles.header}>Help</Text>
<Text style={styles.q}>How does this work?</Text>

<Text style={styles.a}>
Scroll around on the map. Long press (or right click) to add a note to
Expand Down
10 changes: 10 additions & 0 deletions nr-app/src/nostr/keystore.nostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ export async function getPrivateKeyBytes(): Promise<Uint8Array> {
return keyBytes;
}

export async function getPrivateKeyMnemonic(): Promise<string> {
const mnemonic = await SecureStore.getItemAsync(
SECURE_STORE_PRIVATE_KEY_HEX_NMEONIC,
);
if (mnemonic === null) {
throw new Error("#ATaXag-failed-to-get-mnemonic");
}
return mnemonic;
}

export async function setPrivateKeyMnemonic(keyMnemonic: string) {
const account = accountFromSeedWords({ mnemonic: keyMnemonic });
await SecureStore.setItemAsync(
Expand Down

0 comments on commit 042066f

Please sign in to comment.