Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
Do not use crypto.randomBytes but rely on the randombytes package
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jul 28, 2018
1 parent 71a51f1 commit bfe1848
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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))
}
}

Expand All @@ -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'))) {
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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",
Expand Down

0 comments on commit bfe1848

Please sign in to comment.