Mint INJS
Last updated
const {sha256} = require('js-sha256');
function generateNonce() {
let nonce = '';
const characters = '0123456789abcdef';
for (let i = 0; i < 20; i++) {
nonce += characters.charAt(Math.floor(Math.random() * characters.length));
}
return nonce;
}
// Function to compute Proof of Work
async function computeProofOfWork(seed,address,target) {
let nonce = 0;
let hash;
do {
nonce = generateNonce();
hash = sha256(seed + address + nonce);
} while (BigInt('0x'+hash) >= target);
return nonce;
}
// Example usage
(async () => {
const address = 'userAddress';
const seed = 'Block Hash Of Deploy Operation';
const target = 0x000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn;
const nonce = await computeProofOfWork(seed, address, target);
console.log('Found nonce:', nonce);
})();