-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.js
76 lines (59 loc) · 2.14 KB
/
index.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
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
var ethereumGen = require('./generators/ethereum')
var qrCode = require('qrcode-npm').qrcode
var recover = require('recover-bip39')
window.addEventListener('load', setup)
function setup() {
console.log('setting up')
var generateButton = document.querySelector('button.generate')
generateButton.addEventListener('click', generateAccounts)
var resetButton = document.querySelector('.results button.reset')
resetButton.addEventListener('click', showMnemonic)
}
function generateAccounts() {
console.log('generating accounts')
var mnemonic = document.querySelector('textarea.mnemonic').value
var recovered
try {
recovered = recover(mnemonic)
} catch (e) {}
console.log(mnemonic)
var accountCount = document.querySelector('input.accountCount').value
var accounts = ethereumGen(recovered || mnemonic, accountCount)
var resultEl = document.querySelector('section.results > ol.accounts')
resultEl.innerHTML = ''
hideMnemonic()
const showKey = displayKeys.checked;
for (var i = 0; i < accounts.length; i++) {
var { address, privKey } = accounts[i]
var accountEl = document.createElement('div')
var accountLabel = document.createElement('p')
accountLabel.innerText = address
var qrImage = qrCode(4, 'M')
qrImage.addData(address)
qrImage.make()
var qrEl = qrImage.createImgTag(4)
accountEl.innerHTML = qrEl
accountEl.appendChild(accountLabel)
resultEl.appendChild(accountEl)
if (displayKeys.checked) {
const privKeyEl = document.createElement('p');
privKeyEl.innerText = 'Private key: ' + privKey;
resultEl.appendChild(privKeyEl);
}
}
console.log('results added')
}
function showMnemonic () {
console.log('hiding mnemonic')
var mnemonic = document.querySelector('section.mnemonic-input')
mnemonic.style.display = 'block'
var results = document.querySelector('section.results')
results.style.display = 'none'
}
function hideMnemonic () {
console.log('showing mnemonic')
var mnemonic = document.querySelector('section.mnemonic-input')
mnemonic.style.display = 'none'
var results = document.querySelector('section.results')
results.style.display = 'block'
}