-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaezeed.html
101 lines (100 loc) · 4.16 KB
/
aezeed.html
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<html>
<head>
<title>LND seed (Aezeed) Generator / Decoder</title>
<meta property="og:title" content="LND seed (Aezeed) Generator / Decoder">
<meta property="og:description" content="Simple HTML file for LND seed (Aezeed) Generator / Decoder">
<meta property="og:image" content="https://github.com/lightningnetwork/lnd/blob/fac3c84806c5629c8438e29198de90ea40bf7f26/logo.png?raw=true">
<meta name="twitter:card" content="summary_large_image">
</head>
<body>
<center>
<h1>LND seed (Aezeed) Generator / Decoder</h1>
<form onsubmit="decode();return false;">
Seed <textarea style="width:30%;" id="mnemonic" rows="5" cols="70" oninput="clearOutput();clearNewPw()"></textarea><br>
Password (optional) <input style="width:30%;" type="password" id="password" oninput="clearOutput();clearNewPw()"></input><br>
New Password (For change password) <input style="width:30%;" type="password" id="newpassword" oninput="clearOutput()"></input><br>
<input type="button" value="Decode" onclick="decode()"></input><br>
<input type="button" value="Change Password" onclick="changePw()"></input><br>
<input type="button" value="Generate" onclick="generate()"></input><br>
</form>
<h2 id="output"></h2>
</center>
<script src="./js/aezeed.js"></script>
<script>
function toHex(uint8array) {
return Array.from(uint8array).reduce(
(final, byte) => {
return final + ('0' + byte.toString(16)).slice(-2)
},
'',
)
}
function clearOutput() {
document.getElementById('output').innerHTML = ''
}
function clearNewPw() {
document.getElementById('newpassword').value = ''
}
function decode() {
clearOutput()
clearNewPw()
const mnemonic = document.getElementById('mnemonic').value
if (!mnemonic) {
const msg = 'Need mnemonic to decode!'
alert(msg)
throw new Error(msg)
}
const password = document.getElementById('password').value
const pw = !password ? 'aezeed' : password;
try {
const decoded = aezeed.CipherSeed.fromMnemonic(mnemonic, pw)
document.getElementById('output').innerHTML =
'Entropy: ' + toHex(decoded.entropy) + '<br>' +
'BirthDate: ' + decoded.birthDate.toString()
} catch (err) {
const msg = 'Invalid Password'
if (err.message === msg) {
alert(msg)
throw err
}
}
}
function generate() {
clearOutput()
clearNewPw()
const password = document.getElementById('password').value
const pw = !password ? 'aezeed' : password;
const randomSeed = aezeed.CipherSeed.random()
const mnemonic = randomSeed.toMnemonic(pw)
document.getElementById('mnemonic').value = mnemonic
document.getElementById('output').innerHTML =
'Entropy: ' + toHex(randomSeed.entropy) + '<br>' +
'BirthDate: ' + randomSeed.birthDate.toString()
}
function changePw() {
clearOutput()
const mnemonic = document.getElementById('mnemonic').value
if (!mnemonic) {
const msg = 'Need mnemonic to change password!'
alert(msg)
throw new Error(msg)
}
const password = document.getElementById('password').value
const pw = !password ? 'aezeed' : password;
const newpassword = document.getElementById('newpassword').value
const newpw = !newpassword ? 'aezeed' : newpassword;
try {
const newMnemonic = aezeed.CipherSeed.changePassword(mnemonic, pw, newpw)
document.getElementById('output').innerHTML =
'New Mnemonic:<br><div style="width:50%;">' + newMnemonic + '</div>'
} catch (err) {
const msg = 'Invalid Password'
if (err.message === msg) {
alert(msg)
throw err
}
}
}
</script>
</body>
</html>