-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
107 lines (98 loc) · 4.09 KB
/
index.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
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>Nano Currency (RaiBlocks) Paper Wallet Generator</title>
<script src="nacl.js"></script>
<script src="blake2b.js"></script>
<script src="functions.js"></script>
<style>
body { max-width: 960px; margin: 10px auto 50px; font-family: sans-serif; padding: 0 10px; }
input { width: 100%; padding: 3px; margin: 2px 0 0 0; }
input.param { width: auto; margin-right: 5px; }
.dont-break-out {
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
</style>
<style media="print">
#pairs li { page-break-inside: avoid; }
.no-print { display:none; }
</style>
</head>
<body>
<h1>Nano Currency (RaiBlocks) Paper Wallet Generator</h1>
<div class="no-print">
<p>Based on the <a href="https://github.com/jaimehgb/RaiWebWallet">RaiWebWallet</a> source code. <a href="https://github.com/numtel/rai-paper-wallet/">This code</a> is licensed GPL v3.</p>
<p>This page may be used offline, <a href="https://github.com/numtel/rai-paper-wallet/archive/master.zip">download the source code zip</a> and open index.html in your web browser.</p>
<hr />
</div>
<ol class="no-print">
<li>
<p>The wallet accounts are generated from a 32 byte seed input as a 64 character long hexadecimal string.</p>
<p>Click "Use Random" to select a random value using <a href="https://github.com/dchest/tweetnacl-js#naclrandombyteslength">nacl.js</a>.
<p><label>Seed: <input autocomplete="off" class="param" id="seed" /></label><button id="randomSeed">Use Random</button></p>
<p><strong>Back up the wallet seed somewhere safe.</strong> You may also print this page after generation.</p>
<p>Anyone who knows it is able to generate your private keys, thus having access to your funds.</p>
</li>
<li>
<p>Up to 2<sup>32</sup> accounts may be addressed from a single seed. Please select which account to generate a private key/address pair.</p>
<p>By default, <a href="https://raiwallet.com/">RaiWallet</a> uses the 0th account. The desktop wallet seems to start with 0-2.</a></p>
<p><label>Account Number: <input class="param" id="accountIndex" type="number" min="0" max="4294967295" value="0" /></p>
</li>
<li>
<p>Click the button to generate a account key/address pair that you may import into other wallet applications.</p>
<p><button id="generatePair">Generate account pair</button></p>
</li>
</ol>
<hr />
<ol id="pairs"></ol>
<script>
function newPair(seed, accountIndex) {
var index = hex_uint8(dec2hex(accountIndex, 4));
var context = blake2bInit(32);
blake2bUpdate(context, seed);
blake2bUpdate(context, index);
var newKey = blake2bFinal(context);
return {
secret: uint8_hex(newKey),
address: accountFromHexKey(uint8_hex(nacl.sign.keyPair.fromSecretKey(newKey).publicKey))
};
}
var pairList = document.getElementById('pairs');
var seedInput = document.getElementById('seed');
var accountIndexInput = document.getElementById('accountIndex');
document.getElementById('randomSeed').addEventListener('click', function() {
seedInput.value = uint8_hex(nacl.randomBytes(32));
}, false);
document.getElementById('generatePair').addEventListener('click', function() {
if(!/[0-9A-F]{64}/i.test(seedInput.value)) {
alert('Seed must be 64 character hexadecimal string!');
return;
}
var accountIndex = parseInt(accountIndexInput.value, 10);
if(accountIndex < 0 || accountIndex >= Math.pow(2,32)) {
alert('Account index must be 32 bit unsigned integer!');
return;
}
var pair = newPair(hex_uint8(seedInput.value), accountIndex);
pairList.innerHTML += '<li><dl>' + [
{ label: 'Wallet Seed', value: seedInput.value },
{ label: 'Account Key #' + accountIndex, value: pair.secret },
{ label: 'Address', value: pair.address },
].map(function(item) {
return '<div><dt>' + item.label + ':</dt></div>' +
'<div><dd>' +
'<span class="dont-break-out">' + item.value + '</span>' +
'</dd></div>';
}).join('') + '</dl></li>';
}, false);
</script>
</body>
</html>