Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.addressHash = function(input) {
const serializedInput = cbor.encode(input)
const firstHash = new Buffer(sha3256(serializedInput), 'hex')
const context = blake2.blake2bInit(28) // blake2b-224
blake2.blake2bUpdate(context, firstHash)
return new Buffer(blake2.blake2bFinal(context)).toString('hex')
}
_generatePair(seed, accountIndex = 0) {
if (!this._isValidSeed(seed)) {
alert("This is not a valid SEED!");
return null;
}
if(!this._isValidIndexAccount(accountIndex)) {
alert("Invalid account index!");
return null;
}
let index = hex_uint8(dec2hex(accountIndex, 4)); // 00000000 - FFFFFFFF
let context = blake.blake2bInit(32);
blake.blake2bUpdate(context, hex_uint8(seed));
blake.blake2bUpdate(context, index);
let key = blake.blake2bFinal(context);
return {
public_key: accountFromHexKey(uint8_hex(nacl.sign.keyPair.fromSecretKey(key).publicKey)),
private_key: uint8_hex(key),
}
}
for (var _i7 in readyBlocks) {
pack.readyBlocks.push(readyBlocks[_i7].getEntireJSON());
}
pack.keys = tempKeys;
pack.seed = (0, _functions.uint8_hex)(seed);
pack.last = lastKeyFromSeed;
pack.recent = recentTxs;
pack.remoteWork = remoteWork;
pack.autoWork = autoWork;
pack.minimumReceive = minimumReceive.toString();
pack = JSON.stringify(pack);
pack = (0, _functions.stringToHex)(pack);
pack = new Buffer(pack, 'hex');
var context = blake.blake2bInit(32);
blake.blake2bUpdate(context, pack);
checksum = blake.blake2bFinal(context);
var salt = new Buffer(nacl.randomBytes(16));
var key = pbkdf2.pbkdf2Sync(passPhrase, salt, iterations, 32, 'sha1');
var options = { mode: AES.CBC, padding: Iso10126 };
var encryptedBytes = AES.encrypt(pack, key, salt, options);
var payload = Buffer.concat([new Buffer(checksum), salt, encryptedBytes]);
return payload.toString('hex');
};
api.checkWork = function (work) {
var blockHash = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (blockHash === false) {
blockHash = api.getPrevious();
}
var t = (0, _functions.hex_uint8)(MAIN_NET_WORK_THRESHOLD);
var context = blake.blake2bInit(8, null);
blake.blake2bUpdate(context, (0, _functions.hex_uint8)(work).reverse());
blake.blake2bUpdate(context, (0, _functions.hex_uint8)(blockHash));
var threshold = blake.blake2bFinal(context).reverse();
if (threshold[0] == t[0]) if (threshold[1] == t[1]) if (threshold[2] == t[2]) if (threshold[3] >= t[3]) return true;
return false;
};
signOpenBlock(walletAccount, previousBlock, sourceBlock, newBalancePadded, representative) {
const context = blake.blake2bInit(32, null);
blake.blake2bUpdate(context, this.util.hex.toUint8(STATE_BLOCK_PREAMBLE));
blake.blake2bUpdate(context, this.util.hex.toUint8(this.util.account.getAccountPublicKey(walletAccount.id)));
blake.blake2bUpdate(context, this.util.hex.toUint8(previousBlock));
blake.blake2bUpdate(context, this.util.hex.toUint8(this.util.account.getAccountPublicKey(representative)));
blake.blake2bUpdate(context, this.util.hex.toUint8(newBalancePadded));
blake.blake2bUpdate(context, this.util.hex.toUint8(sourceBlock));
const hashBytes = blake.blake2bFinal(context);
const privKey = walletAccount.keyPair.secretKey;
const signed = nacl.sign.detached(hashBytes, privKey);
const signature = this.util.hex.fromUint8(signed);
return signature;
}
function generateAccountSecretKeyBytes(seedBytes, accountIndex) {
const accountBytes = hexToUint8(decToHex(accountIndex, 4));
const context = blake.blake2bInit(32);
blake.blake2bUpdate(context, seedBytes);
blake.blake2bUpdate(context, accountBytes);
const newKey = blake.blake2bFinal(context);
return newKey;
}
api.build = function () {
switch (type) {
case 'send':
data = "";
data += MAGIC_NUMBER + VERSION_MAX + VERSION_USING + VERSION_MIN + uint8_hex(blockID[type]) + EXTENSIONS;
data += previous;
data += destination
data += balance;
var context = blake.blake2bInit(32, null);
blake.blake2bUpdate(context, hex_uint8(previous));
blake.blake2bUpdate(context, hex_uint8(destination));
blake.blake2bUpdate(context, hex_uint8(balance));
hash = uint8_hex(blake.blake2bFinal(context));
break;
case 'receive':
data = "";
data += MAGIC_NUMBER + VERSION_MAX + VERSION_USING + VERSION_MIN + uint8_hex(blockID[type]) + EXTENSIONS;
data += previous;
data += source;
var context = blake.blake2bInit(32, null);
blake.blake2bUpdate(context, hex_uint8(previous));
blake.blake2bUpdate(context, hex_uint8(source));
hash = uint8_hex(blake.blake2bFinal(context));
export function signOpenBlock(
account,
previousBlock,
sourceBlock,
newBalancePadded,
representative,
privKey
) {
const context = blake.blake2bInit(32, null)
blake.blake2bUpdate(context, hexToUint8(STATE_BLOCK_PREAMBLE))
blake.blake2bUpdate(context, hexToUint8(getAccountPublicKey(account)))
blake.blake2bUpdate(context, hexToUint8(previousBlock))
blake.blake2bUpdate(context, hexToUint8(getAccountPublicKey(representative)))
blake.blake2bUpdate(context, hexToUint8(newBalancePadded))
blake.blake2bUpdate(context, hexToUint8(sourceBlock))
const hashBytes = blake.blake2bFinal(context)
const signed = nacl.sign.detached(hashBytes, privKey)
const signature = uint8ToHex(signed)
return signature
}
api.checkWork = function (hash, work) {
var t = (0, _functions.hex_uint8)(MAIN_NET_WORK_THRESHOLD);
var context = blake.blake2bInit(8, null);
blake.blake2bUpdate(context, (0, _functions.hex_uint8)(work).reverse());
blake.blake2bUpdate(context, (0, _functions.hex_uint8)(hash));
var threshold = blake.blake2bFinal(context).reverse();
if (threshold[0] == t[0]) if (threshold[1] == t[1]) if (threshold[2] == t[2]) if (threshold[3] >= t[3]) return true;
return false;
};