-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomx.js
44 lines (36 loc) · 876 Bytes
/
randomx.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
var rx = require("./build/Release/randomx.node");
function createVM(seed) {
if (typeof seed !== "string") {
throw new Error("Invalid seed, seed should be a String");
}
return new Promise((resolve, reject) => {
let vm;
try {
vm = rx.RandomxVM(seed, ["jit", "ssse3"]);
resolve(vm);
} catch (err) {
reject(err);
}
});
}
function batchVM(vm, hashes) {
if (!vm) {
throw new Error("Invalid VM");
}
if (!Array.isArray(hashes)) {
throw new Error("Invalid hashes, hashes should be an Array of string");
}
return new Promise((resolve, reject) => {
const result = [];
try {
for (const [nonce, blob] of hashes) {
result.push([nonce, rx.hash(vm, blob)]);
}
resolve(result);
} catch (err) {
reject(err);
}
});
}
exports.createVM = createVM;
exports.batchVM = batchVM;