-
Notifications
You must be signed in to change notification settings - Fork 2
/
ninja.singlewallet.js
43 lines (40 loc) · 1.46 KB
/
ninja.singlewallet.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
(function (wallets, qrCode) {
var single = wallets.singlewallet = {
isOpen: function () {
return (document.getElementById("singlewallet").className.indexOf("selected") != -1);
},
open: function () {
if (document.getElementById("btcaddress").innerHTML == "") {
single.generateNewAddressAndKey();
}
document.getElementById("singlearea").style.display = "block";
},
close: function () {
document.getElementById("singlearea").style.display = "none";
},
// generate bitcoin address and private key and update information in the HTML
generateNewAddressAndKey: function () {
try {
var key = new Bitcoin.ECKey(false);
key.setCompressed(true);
var bitcoinAddress = key.getBitcoinAddress();
var privateKeyWif = key.getBitcoinWalletImportFormat();
document.getElementById("btcaddress").innerHTML = bitcoinAddress;
document.getElementById("btcprivwif").innerHTML = privateKeyWif;
var keyValuePair = {
"qrcode_public": bitcoinAddress,
"qrcode_private": privateKeyWif
};
qrCode.showQrCode(keyValuePair, 4);
}
catch (e) {
// browser does not have sufficient JavaScript support to generate a bitcoin address
alert(e);
document.getElementById("btcaddress").innerHTML = "error";
document.getElementById("btcprivwif").innerHTML = "error";
document.getElementById("qrcode_public").innerHTML = "";
document.getElementById("qrcode_private").innerHTML = "";
}
}
};
})(ninja.wallets, ninja.qrCode);