-
Notifications
You must be signed in to change notification settings - Fork 2
/
brainwallet.html
172 lines (134 loc) · 5.9 KB
/
brainwallet.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<html style='height:100%'>
<head>
<title>Qora Brain Wallet</title>
<script src="jquery-2.2.0.js"></script>
<script src="nacl-fast.js" charset="utf-8"></script>
<script src="Base58.js" charset="utf-8"></script>
<script src="sha256.js" charset="utf-8"></script>
<script src="ripemd160.js" charset="utf-8"></script>
<script src="qora.js" charset="utf-8"></script>
<script src="common.js" charset="utf-8"></script>
<link href="bootstrap.css" rel="stylesheet">
<link href="common.css" rel="stylesheet">
</head>
<script type="text/javascript">
function doAccountAddressFromPublicKey() {
var base58AccountPublicKey = document.getElementById('base58AccountPublicKey').value;
if(Base58.decode(base58AccountPublicKey).length != 32) {
document.getElementById('base58AccountAddress').value = '';
alert("invalid PublicKey!");
return;
}
var base58AccountAddress = getAccountAddressFromPublicKey(base58AccountPublicKey);
document.getElementById('base58AccountAddress').value = base58AccountAddress;
}
function doBrain()
{
var brainWalletPassphrase = document.getElementById('brainWalletPassphrase').value;
if(brainWalletPassphrase.length < 8) {
document.getElementById('base58BaseSeed').value = '';
document.getElementById('output').innerHTML = '';
alert("invalid passphrase length!\nIt should be at least 8 characters.");
return;
}
var byteSeed = new Uint8Array(SHA256.digest(SHA256.digest(brainWalletPassphrase)));
var base58BaseSeed = Base58.encode(byteSeed);
document.getElementById('base58BaseSeed').value = base58BaseSeed;
doAccounts();
}
function doAccountFromSeed(base58AccountSeed)
{
if(base58AccountSeed) {
document.getElementById('base58AccountSeed').value = base58AccountSeed;
} else {
base58AccountSeed = document.getElementById('base58AccountSeed').value;
}
if(Base58.decode(base58AccountSeed).length != 32) {
document.getElementById('base58AccountPublicKey').value = '';
document.getElementById('base58AccountPrivateKey').value = '';
document.getElementById('base58AccountAddress').value = '';
alert("invalid seed!");
return;
}
keyPair = getKeyPairFromSeed(base58AccountSeed, false);
var base58AccountAddress = getAccountAddressFromPublicKey(keyPair.publicKey);
var base58AccountPublicKey = Base58.encode(keyPair.publicKey);
var base58AccountPrivateKey = Base58.encode(keyPair.privateKey);
document.getElementById('base58AccountPublicKey').value = base58AccountPublicKey;
document.getElementById('base58AccountPrivateKey').value = base58AccountPrivateKey;
document.getElementById('base58AccountAddress').value = base58AccountAddress;
}
function doAccounts(){
var base58BaseSeed = document.getElementById('base58BaseSeed').value;
document.getElementById('output').innerHTML = '';
if(base58BaseSeed == '') {
return;
}
countAddrs = document.getElementById('countAddrs').value;
if(isNaN(countAddrs) || countAddrs < 1) {
alert("invalid count!");
return;
}
seed = Base58.decode(base58BaseSeed);
if(seed.length != 32) {
alert("invalid seed!");
return;
}
for (var nonce = 0; nonce < countAddrs; nonce ++) {
var accountSeed = generateAccountSeed(seed, nonce, false);
var keyPair = getKeyPairFromSeed(accountSeed);
var base58addressSeed = Base58.encode(accountSeed);
document.getElementById('output').innerHTML += '<hr><span style="cursor: pointer;" onclick="doAccountFromSeed(\''+base58addressSeed+'\')">'
+ '' + (nonce+1) + ' '
+ 'addr: <b>' + getAccountAddressFromPublicKey(keyPair.publicKey) + '</b><br>'
+ 'seed: ' + base58addressSeed + ' '
+ '</span>';
}
}
function onLoad()
{
if (/test/.test(window.location.hash))
{
$("#brainWalletPassphrase").val("12345678фыва");
$("#doBrainButton").click();
if($("#base58BaseSeed").val() == 'CjCmqGrNJoy499fMFGmonRipBc4GKk9RGRHF4BY7XSBN') {
$("#base58BaseSeed").css({"color": "green"});
} else {
$("#base58BaseSeed").css({"color": "red"});
}
$("#base58AccountSeed").val("8stsVtM4gQsJbvVbDx1eszkd5zUWEtt6tmUwYBB4PmA3");
$("#doAccountFromSeedButton").click();
if($("#base58AccountAddress").val() == 'QMBKyCtSjjNETmNLQwfCxd6sADJNVXAShk') {
$("#base58AccountAddress").css({"color": "green"});
} else {
$("#base58AccountAddress").css({"color": "red"});
}
}
}
</script>
<body style="margin:4; padding:25" onload="onLoad()">
<center>
<div style='height: 140px;' id='menu'></div>
<h3>Qora BrainWallet</h3>
<table>
<tr><td>
Passphrase:<br>
<input style='width:485px;' type="text" size=60 value="" autofocus id="brainWalletPassphrase"/><input style='width:80px;' type="button" id='doBrainButton' value="Сonvert" OnClick="doBrain()"/><br><br>
Base Seed:<br>
<input style='width:485px;' type="text" size=60 value="" id="base58BaseSeed"/><input style='width:80px;' type="button" value="Сonvert" OnClick="doAccounts()"/><br><br>
Count: <input type="text" size=5 value="10" id="countAddrs"/><br>
<br>
<div id="output"></div><br>
<b>Account:</b><br>
<span style='width:80px; display: inline-block;'>Seed:</span> <input style='width:400px;' type="text" value="" id="base58AccountSeed"/><input style='width:80px;' type="button" id='doAccountFromSeedButton' value="Сonvert" OnClick="doAccountFromSeed()"/><br>
<span style='width:80px; display: inline-block;'>privateKey:</span>
<input style='width:480px;' type="text" class="readonly" value="" readonly id="base58AccountPrivateKey"/><br>
<span style='width:80px; display: inline-block;'>publicKey:</span>
<input style='width:400px;' type="text" value="" id="base58AccountPublicKey"/><input style='width:80px;' type="button" value="Сonvert" OnClick="doAccountAddressFromPublicKey()"/><br>
<span style='width:80px; display: inline-block;'>Address:</span>
<input style='width:480px;' type="text" class="readonly" value="" readonly id="base58AccountAddress"/><br>
</table>
<br><br>
<div id='bottom'></div>
</center>
</body>