Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
secretKey: uint8_hex(key.priv),
});
break;
default: throw "Unsupported key type"
}
}
pack = JSON.stringify(pack);
pack = stringToHex(pack);
pack = new Buffer(pack, 'hex');
var context = blake.blake2bInit(32);
blake.blake2bUpdate(context, pack);
var 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]);
// decrypt to check if wallet was corrupted during ecryption somehow
if(api.decryptAndCheck(payload).toString('hex') === false)
return api.pack(); // try again, shouldnt happen often
return payload.toString('hex');
}
api.setLoginKey = function(lk = false)
{
if(loginKey === false)
if(lk)
loginKey = lk;
else
loginKey = uint8_hex(nacl.randomBytes(32));
// cannot be changed
}
generateSeed(entropy = null) {
return uint8_hex(nacl.randomBytes(32));
}
api.setRandomSeed = function (overwrite = false) {
if (seed && !overwrite)
throw "Seed already exists. To overwrite use setSeed or set overwrite to true";
seed = nacl.randomBytes(32);
}
api.createWallet = function (setSeed = false) {
if (!setSeed)
seed = nacl.randomBytes(32);
else
api.setSeed(setSeed);
api.newKeyFromSeed();
api.useAccount(keys[0].account);
loginKey = uint8_hex(nacl.randomBytes(32));
return uint8_hex(seed);
}