-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathninja.brainwallet.js
68 lines (61 loc) · 2.59 KB
/
ninja.brainwallet.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
ninja.wallets.brainwallet = {
isOpen: function () {
return (document.getElementById("brainwallet").className.indexOf("selected") != -1);
},
open: function () {
document.getElementById("brainarea").style.display = "block";
document.getElementById("brainpassphrase").focus();
document.getElementById("brainwarning").innerHTML = ninja.translator.get("brainalertpassphrasewarning");
},
close: function () {
document.getElementById("brainarea").style.display = "none";
},
minPassphraseLength: 15,
view: function () {
var key = document.getElementById("brainpassphrase").value.toString()
document.getElementById("brainpassphrase").value = key;
var keyConfirm = document.getElementById("brainpassphraseconfirm").value.toString()
document.getElementById("brainpassphraseconfirm").value = keyConfirm;
if (key == keyConfirm || document.getElementById("brainpassphraseshow").checked) {
// enforce a minimum passphrase length
if (key.length >= ninja.wallets.brainwallet.minPassphraseLength) {
var bytes = Crypto.SHA256(key, { asBytes: true });
var btcKey = new Bitcoin.ECKey(bytes);
var isCompressed = document.getElementById("braincompressed").checked;
btcKey.setCompressed(isCompressed);
var bitcoinAddress = btcKey.getBitcoinAddress();
var privWif = btcKey.getBitcoinWalletImportFormat();
document.getElementById("brainbtcaddress").innerHTML = bitcoinAddress;
document.getElementById("brainbtcprivwif").innerHTML = privWif;
ninja.qrCode.showQrCode({
"brainqrcodepublic": bitcoinAddress,
"brainqrcodeprivate": privWif
});
document.getElementById("brainkeyarea").style.visibility = "visible";
}
else {
alert(ninja.translator.get("brainalertpassphrasetooshort") + ninja.translator.get("brainalertpassphrasewarning"));
ninja.wallets.brainwallet.clear();
}
}
else {
alert(ninja.translator.get("brainalertpassphrasedoesnotmatch"));
ninja.wallets.brainwallet.clear();
}
},
clear: function () {
document.getElementById("brainkeyarea").style.visibility = "hidden";
},
showToggle: function (element) {
if (element.checked) {
document.getElementById("brainpassphrase").setAttribute("type", "text");
document.getElementById("brainpassphraseconfirm").style.visibility = "hidden";
document.getElementById("brainlabelconfirm").style.visibility = "hidden";
}
else {
document.getElementById("brainpassphrase").setAttribute("type", "password");
document.getElementById("brainpassphraseconfirm").style.visibility = "visible";
document.getElementById("brainlabelconfirm").style.visibility = "visible";
}
}
};