-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmnemonicHandler.js
36 lines (32 loc) · 1.01 KB
/
mnemonicHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const KEY = "MNEMONIC";
import RavencoinKey from "@ravenrebels/ravencoin-key";
//Example "fish divorce have gadget trip token furnace marine little learn sheriff insect";
//Example few seminar drill peace insect object say parrot point forest also cotton
export function getMnemonic() {
const m = localStorage.getItem(KEY);
if (!m) {
const newWords = RavencoinKey.generateMnemonic();
localStorage.setItem(KEY, newWords);
return newWords;
}
return localStorage.getItem(KEY);
}
export function setMnemonic(mnemonic) {
//Validate mnemonic
const isValid = RavencoinKey.isMnemonicValid(mnemonic);
if (isValid) {
//Warn if user is over-writing existing mnemonic
if (getMnemonic() !== mnemonic) {
const conf = confirm(
"Do you really want to over-write your existing 12 words?"
);
if (conf) {
localStorage.setItem(KEY, mnemonic);
//Reload the app
window.location.reload();
}
}
} else {
alert(mnemonic + " does not seem to be valid");
}
}