Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function encode(name, data, desc) {
assert(typeof name === 'string');
assert(Buffer.isBuffer(data));
assert(!desc || typeof desc === 'string');
const blake2b = BLAKE2b.digest(data);
const sha256 = SHA256.digest(data);
const sha3 = SHA3.digest(data);
const hex = data.toString('hex');
// Digit Sum (used for RSA-2048 -- see challengenumbers.txt)
const num = BN.fromBuffer(data);
const base10 = num.toString(10);
let sum = 0;
for (let i = 0; i < base10.length; i++)
sum += Number(base10[i]);
// Checksum (used for RSA-617 -- see rsa-fact.txt)
const checksum = num.modrn(991889);
let out = '';
hash() {
if (this.mutable)
return BLAKE2b256.digest(this.toHead());
if (!this._hash)
this._hash = BLAKE2b256.digest(this.toHead());
return this._hash;
}
verifyPOW() {
const data = this.toPrehead();
const key = KMAC256.digest(data, this.nonce);
const hash = BLAKE2b256.digest(data, key);
return consensus.verifyPOW(hash, this.bits);
}
hash() {
if (this.mutable)
return BLAKE2b256.digest(this.toHead());
if (!this._hash)
this._hash = BLAKE2b256.digest(this.toHead());
return this._hash;
}
powHash() {
const data = this.hdr.slice(0, -consensus.NONCE_SIZE);
const key = KMAC256.digest(data, this.nonce);
return BLAKE2b256.digest(data, key);
}