Repository navigation
Expand file tree
/
Copy pathtestresult.js
More file actions
65 lines (58 loc) · 1.81 KB
/
Copy pathtestresult.js
File metadata and controls
65 lines (58 loc) · 1.81 KB
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
const crypto = require("crypto");
const util = require("util");
const scryptAsync = util.promisify(crypto.scrypt);
async function calculateHashForBlock(block) {
const data = [
block.blockHeader.version,
block.blockHeader.previousBlockHeader,
block.blockHeader.merkleRoot,
block.blockHeader.time,
block.nonce.toString(),
].join("");
const salt = "someConstantSalt"; // Generate a random salt
const keylen = 32; // Length of the output key
// Adjust these for CPU-friendly mining
const N = 1024; // Lower CPU/memory cost factor
const r = 4; // Lower block size
const p = 1; // Lower parallelization factor
try {
const derivedKey = await scryptAsync(data, salt, keylen, { N, r, p });
return derivedKey.toString("hex");
} catch (err) {
throw err; // Handle the error as you see fit
}
}
const object = {
blockHeader: {
version: "1.0.0",
previousBlockHeader:
"7af5c7cc90143c05f24f32d5dac0684a89177a686200a9871e1405fb9451e1ab",
merkleRoot:
"efb1e41da0922dc8a3163622be0786a42ba7fb765def75b3b604639b9bef5e29",
time: 1693296300007,
difficulty: "0x10",
hash: "0000aefc9ee641c5ce15813b3cbd53b2bdf579b2bd2435fe914d4a4ea3218ec0",
},
index: 1,
transactions: [
{
sender: "coinbase",
receiver:
"04c590a6b268f13a042e1b0f9c52f291db78f042659ad257a39fead537452b6657d161b988cd5b90b29c16192ecc139ff48b181c7b99555514d6ec375308c19bbd",
amount: 40,
signature: undefined,
fee: 0,
time: 1693296300015,
id: "48fbaf2ee4d231db4b974ae6e93f8a5bf7985c44f036934d5923585f443af76b",
},
],
tx: [],
nonce: 12728,
target:
1766847064752673320875153656334247122350025295235263710221081515927797760n,
};
async function call() {
const value = await calculateHashForBlock(object);
console.log(`value`, value);
}
call();