Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ultraviolet
GitHub Repository: ultraviolet/bitaddress.org
Path: blob/master/src/ninja.bulkwallet.js
248 views
1
(function (wallets, translator, privateKey) {
2
var bulk = wallets.bulkwallet = {
3
isOpen: function () {
4
return (document.getElementById("bulkwallet").className.indexOf("selected") != -1);
5
},
6
7
open: function () {
8
document.getElementById("bulkarea").style.display = "block";
9
// show a default CSV list if the text area is empty
10
if (document.getElementById("bulktextarea").value == "") {
11
// return control of the thread to the browser to render the tab switch UI then build a default CSV list
12
setTimeout(function () { bulk.buildCSV(3, 1, document.getElementById("bulkcompressed").checked); }, 200);
13
}
14
15
document.getElementById("bulkpassphrase").disabled = !document.getElementById("bulkencrypt").checked;
16
},
17
18
close: function () {
19
document.getElementById("bulkarea").style.display = "none";
20
},
21
22
// use this function to bulk generate addresses
23
// rowLimit: number of Bitcoin Addresses to generate
24
// startIndex: add this number to the row index for output purposes
25
// returns:
26
// index,bitcoinAddress,privateKeyWif
27
buildCSV: function (rowLimit, startIndex, compressedAddrs, passphrase) {
28
document.getElementById("bulktextarea").value = translator.get("bulkgeneratingaddresses") + rowLimit;
29
bulk.csv = [];
30
bulk.csvRowLimit = rowLimit;
31
bulk.csvRowsRemaining = rowLimit;
32
bulk.csvStartIndex = --startIndex;
33
bulk.compressedAddrs = !!compressedAddrs;
34
if (bulk.encrypt) {
35
if (passphrase == "") {
36
alert(translator.get("bip38alertpassphraserequired"));
37
return;
38
}
39
document.getElementById("busyblock").className = "busy";
40
privateKey.BIP38GenerateIntermediatePointAsync(passphrase, null, null, function (intermediate) {
41
bulk.intermediatePoint = intermediate;
42
document.getElementById("busyblock").className = "";
43
setTimeout(bulk.batchCSV, 0);
44
});
45
}
46
else {
47
setTimeout(bulk.batchCSV, 0);
48
}
49
},
50
51
csv: [],
52
csvRowsRemaining: null, // use to keep track of how many rows are left to process when building a large CSV array
53
csvRowLimit: 0,
54
csvStartIndex: 0,
55
56
batchCSV: function () {
57
if (bulk.csvRowsRemaining > 0) {
58
bulk.csvRowsRemaining--;
59
60
if (bulk.encrypt) {
61
privateKey.BIP38GenerateECAddressAsync(bulk.intermediatePoint, bulk.compressedAddrs, function (address, encryptedKey) {
62
Bitcoin.KeyPool.push(new Bitcoin.Bip38Key(address, encryptedKey));
63
64
bulk.csv.push((bulk.csvRowLimit - bulk.csvRowsRemaining + bulk.csvStartIndex)
65
+ ",\"" + address + "\",\"" + encryptedKey
66
+ "\"");
67
document.getElementById("bulktextarea").value = translator.get("bulkgeneratingaddresses") + bulk.csvRowsRemaining;
68
69
// release thread to browser to render UI
70
setTimeout(bulk.batchCSV, 0);
71
72
});
73
}
74
else {
75
var key = new Bitcoin.ECKey(false);
76
key.setCompressed(bulk.compressedAddrs);
77
bulk.csv.push((bulk.csvRowLimit - bulk.csvRowsRemaining + bulk.csvStartIndex)
78
+ ",\"" + key.getBitcoinAddress() + "\",\"" + key.toString("wif")
79
//+ "\",\"" + key.toString("wifcomp") // uncomment these lines to add different private key formats to the CSV
80
//+ "\",\"" + key.getBitcoinHexFormat()
81
//+ "\",\"" + key.toString("base64")
82
+ "\"");
83
document.getElementById("bulktextarea").value = translator.get("bulkgeneratingaddresses") + bulk.csvRowsRemaining;
84
85
// release thread to browser to render UI
86
setTimeout(bulk.batchCSV, 0);
87
}
88
}
89
// processing is finished so put CSV in text area
90
else if (bulk.csvRowsRemaining === 0) {
91
document.getElementById("bulktextarea").value = bulk.csv.join("\n");
92
}
93
},
94
95
openCloseFaq: function (faqNum) {
96
// do close
97
if (document.getElementById("bulka" + faqNum).style.display == "block") {
98
document.getElementById("bulka" + faqNum).style.display = "none";
99
document.getElementById("bulke" + faqNum).setAttribute("class", "more");
100
}
101
// do open
102
else {
103
document.getElementById("bulka" + faqNum).style.display = "block";
104
document.getElementById("bulke" + faqNum).setAttribute("class", "less");
105
}
106
},
107
108
toggleEncrypt: function (element) {
109
// enable/disable passphrase textbox
110
document.getElementById("bulkpassphrase").disabled = !element.checked;
111
bulk.encrypt = element.checked;
112
}
113
};
114
})(ninja.wallets, ninja.translator, ninja.privateKey);
115