Do not use crypto.randomBytes but rely on the randombytes package

This commit is contained in:
Alex Beregszaszi 2018-07-28 20:10:07 +01:00 committed by holgerd77
parent 95683dd4bc
commit 1d719ea2ae
2 changed files with 8 additions and 6 deletions

View File

@ -36,6 +36,7 @@
"bs58check": "^2.1.2",
"ethereumjs-util": "^5.2.0",
"hdkey": "^1.0.0",
"randombytes": "^2.0.6",
"safe-buffer": "^5.1.2",
"scrypt.js": "^0.2.0",
"utf8": "^3.0.0",

View File

@ -1,6 +1,7 @@
var Buffer = require('safe-buffer').Buffer
var ethUtil = require('ethereumjs-util')
var crypto = require('crypto')
var randomBytes = require('randombytes')
var scryptsy = require('scrypt.js')
var uuidv4 = require('uuid/v4')
var bs58check = require('bs58check')
@ -52,13 +53,13 @@ Wallet.generate = function (icapDirect) {
if (icapDirect) {
var max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
while (true) {
var privKey = crypto.randomBytes(32)
var privKey = randomBytes(32)
if (new ethUtil.BN(ethUtil.privateToAddress(privKey)).lte(max)) {
return new Wallet(privKey)
}
}
} else {
return new Wallet(crypto.randomBytes(32))
return new Wallet(randomBytes(32))
}
}
@ -68,7 +69,7 @@ Wallet.generateVanityAddress = function (pattern) {
}
while (true) {
var privKey = crypto.randomBytes(32)
var privKey = randomBytes(32)
var address = ethUtil.privateToAddress(privKey)
if (pattern.test(address.toString('hex'))) {
@ -110,8 +111,8 @@ Wallet.prototype.toV3 = function (password, opts) {
assert(this._privKey, 'This is a public key only wallet')
opts = opts || {}
var salt = opts.salt || crypto.randomBytes(32)
var iv = opts.iv || crypto.randomBytes(16)
var salt = opts.salt || randomBytes(32)
var iv = opts.iv || randomBytes(16)
var derivedKey
var kdf = opts.kdf || 'scrypt'
@ -145,7 +146,7 @@ Wallet.prototype.toV3 = function (password, opts) {
return {
version: 3,
id: uuidv4({ random: opts.uuid || crypto.randomBytes(16) }),
id: uuidv4({ random: opts.uuid || randomBytes(16) }),
address: this.getAddress().toString('hex'),
crypto: {
ciphertext: ciphertext.toString('hex'),