-
Notifications
You must be signed in to change notification settings - Fork 0
/
ninja.seeder.js
112 lines (104 loc) · 3.9 KB
/
ninja.seeder.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
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
108
109
110
111
112
ninja.seeder = {
init: (function () {
document.getElementById("generatekeyinput").value = "";
})(),
// number of mouse movements to wait for
seedLimit: (function () {
var num = Crypto.util.randomBytes(12)[11];
return 200 + Math.floor(num);
})(),
seedCount: 0, // counter
lastInputTime: new Date().getTime(),
seedPoints: [],
isStillSeeding: true,
seederDependentWallets: ["singlewallet", "paperwallet", "bulkwallet", "vanitywallet", "splitwallet"],
// seed function exists to wait for mouse movement to add more entropy before generating an address
seed: function (evt) {
if (!evt) var evt = window.event;
var timeStamp = new Date().getTime();
// seeding is over now we generate and display the address
if (ninja.seeder.seedCount == ninja.seeder.seedLimit) {
ninja.seeder.seedCount++;
ninja.seeder.seedingOver();
}
// seed mouse position X and Y when mouse movements are greater than 40ms apart.
else if ((ninja.seeder.seedCount < ninja.seeder.seedLimit) && evt && (timeStamp - ninja.seeder.lastInputTime) > 40) {
SecureRandom.seedTime();
SecureRandom.seedInt16((evt.clientX * evt.clientY));
ninja.seeder.showPoint(evt.clientX, evt.clientY);
ninja.seeder.seedCount++;
ninja.seeder.lastInputTime = new Date().getTime();
ninja.seeder.showPool();
}
},
// seed function exists to wait for mouse movement to add more entropy before generating an address
seedKeyPress: function (evt) {
if (!evt) var evt = window.event;
// seeding is over now we generate and display the address
if (ninja.seeder.seedCount == ninja.seeder.seedLimit) {
ninja.seeder.seedCount++;
ninja.seeder.seedingOver();
}
// seed key press character
else if ((ninja.seeder.seedCount < ninja.seeder.seedLimit) && evt.which) {
var timeStamp = new Date().getTime();
// seed a bunch (minimum seedLimit) of times
SecureRandom.seedTime();
SecureRandom.seedInt8(evt.which);
var keyPressTimeDiff = timeStamp - ninja.seeder.lastInputTime;
SecureRandom.seedInt8(keyPressTimeDiff);
ninja.seeder.seedCount++;
ninja.seeder.lastInputTime = new Date().getTime();
ninja.seeder.showPool();
}
},
showPool: function () {
var poolHex;
if (SecureRandom.poolCopyOnInit != null) {
poolHex = Crypto.util.bytesToHex(SecureRandom.poolCopyOnInit);
document.getElementById("seedpool").innerHTML = poolHex;
document.getElementById("seedpooldisplay").innerHTML = poolHex;
}
else {
poolHex = Crypto.util.bytesToHex(SecureRandom.pool);
document.getElementById("seedpool").innerHTML = poolHex;
document.getElementById("seedpooldisplay").innerHTML = poolHex;
}
var percentSeeded = Math.round((ninja.seeder.seedCount / ninja.seeder.seedLimit) * 100) + "%";
document.getElementById("mousemovelimit").innerHTML = percentSeeded;
for (var wIndex in ninja.seeder.seederDependentWallets) {
document.getElementById(ninja.seeder.seederDependentWallets[wIndex]).innerHTML = percentSeeded;
}
},
showPoint: function (x, y) {
var div = document.createElement("div");
div.setAttribute("class", "seedpoint");
div.style.top = y + "px";
div.style.left = x + "px";
document.body.appendChild(div);
ninja.seeder.seedPoints.push(div);
},
removePoints: function () {
for (var i = 0; i < ninja.seeder.seedPoints.length; i++) {
document.body.removeChild(ninja.seeder.seedPoints[i]);
}
ninja.seeder.seedPoints = [];
},
seedingOver: function () {
ninja.seeder.isStillSeeding = false;
// run sync unit tests
ninja.status.unitTests();
// open selected tab
var walletType = ninja.tab.whichIsOpen();
if (walletType == null) {
ninja.tab.select("singlewallet");
} else {
ninja.tab.select(walletType)
}
document.getElementById("generate").style.display = "none";
// update labels for dependent wallets
var culture = (ninja.getQueryString()["culture"] == null ? "en" : ninja.getQueryString()["culture"]);
ninja.translator.translate(culture);
ninja.seeder.removePoints();
}
};