Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// console.log('digestBigNumber',digestBigNumber.toString())
// console.log('miningTarget',miningTarget.toString())
if ( digestBigNumber.lt(miningTarget) )
{
console.log(minerEthAddress)
console.log('------')
console.log(solution_number)
console.log(challenge_number)
console.log(solution_number)
console.log('------')
console.log( web3utils.bytesToHex(digestBytes32))
}
if ( digestBigNumber.lt(miningTarget) )
{
//pass in digest bytes or trimmed ?
if(this.testMode){
this.mining = false;
this.networkInterface.checkMiningSolution( minerEthAddress, solution_number , web3utils.bytesToHex( digestBytes32 ),challenge_number,miningTarget,
function(result){
console.log('checked mining soln:' ,result)
})
}else {
console.log('submit mined solution with challenge ', challenge_number)
// NOTE: with potential introduction of chainId this might need to be updated
if (sig.length !== 65) {
throw new Error('Invalid signature length');
}
let v = sig[64];
// support both versions of `eth_sign` responses
if (v < 27) {
v += 27;
}
return {
v,
r: bytesToHex(sig.slice(0, 32)),
s: bytesToHex(sig.slice(32, 64)),
};
}
const sig = hexToBytes(sigString);
// NOTE: with potential introduction of chainId this might need to be updated
if (sig.length !== 65) {
throw new Error('Invalid signature length');
}
let v = sig[64];
// support both versions of `eth_sign` responses
if (v < 27) {
v += 27;
}
return {
v,
r: bytesToHex(sig.slice(0, 32)),
s: bytesToHex(sig.slice(32, 64)),
};
}
view.setUint8(cursor, v);
cursor++;
});
// time is little-endian
view.setUint32(cursor, metaResponse.epoch.time, true);
cursor += 7;
view.setUint8(cursor, metaResponse.epoch.level);
cursor++;
dataBytes.forEach((v) => {
view.setUint8(cursor, v);
cursor++;
});
return sha3(padLeft(bytesToHex(new Uint8Array(buf)),264));
}
function decodeContents(contents) {
// JSON
try {
return JSON.parse(contents);
} catch (e) {
/* no-op */
}
// hex string
if (contents.toString().startsWith("0x")) {
return contents.toString();
}
// raw binary
return web3Utils.bytesToHex(contents);
}
console.log(solution_number)
console.log(challenge_number)
console.log(solution_number)
console.log('------')
console.log( web3utils.bytesToHex(digestBytes32))
}
if ( digestBigNumber.lt(miningTarget) )
{
//pass in digest bytes or trimmed ?
if(this.testMode){
this.mining = false;
this.networkInterface.checkMiningSolution( minerEthAddress, solution_number , web3utils.bytesToHex( digestBytes32 ),challenge_number,miningTarget,
function(result){
console.log('checked mining soln:' ,result)
})
}else {
console.log('submit mined solution with challenge ', challenge_number)
console.log('submit mined solution with solution ', solution_number)
this.submitNewMinedBlock( minerEthAddress, solution_number, web3utils.bytesToHex( digestBytes32 ) , challenge_number);
}
}
},
//console.log('digestBigNumber',digestBigNumber.toString())
//console.log('miningTarget',miningTarget.toString())
if ( digestBigNumber.lt(miningTarget) )
{
if(this.testMode){
console.log(minerEthAddress)
console.log('------')
console.log(solution_number)
console.log(challenge_number)
console.log(solution_number)
console.log('------')
console.log( web3utils.bytesToHex(digestBytes32))
//pass in digest bytes or trimmed ?
this.mining = false;
/*this.networkInterface.checkMiningSolution( minerEthAddress, solution_number , web3utils.bytesToHex( digestBytes32 ),challenge_number,miningTarget,
function(result){
console.log('checked mining soln:' ,result)
})*/
}else {
console.log('submit mined solution with challenge ', challenge_number)
this.submitNewMinedBlock( addressFrom, minerEthAddress, solution_number, web3utils.bytesToHex( digestBytes32 ) , challenge_number, target, difficulty );
reject(e);
}
});
} catch (e) {
sig_ = await new Promise((resolve, reject) => {
web3.eth.sign(hash, account, (err, res) => {
if (err) reject(err);
else resolve(res);
});
});
}
let signature = ethUtils.fromRpcSig(sig_);
let sig =
web3Utils.bytesToHex(signature.r) +
removeHexPrefix(web3Utils.bytesToHex(signature.s)) +
removeHexPrefix(web3Utils.toHex(signature.v));
return sig;
},
return this.SF.get(address, key, 'arraybuffer').then((t) => {
let ivAndEncryptedString = bytesToHex(encryptedBuffer);
let iv = ivAndEncryptedString.substring(0, 34);
let encryptedString = ivAndEncryptedString.substring(34);
return Crypto.decryptString(encryptedString, password, iv);
});
}