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

Commit 5735026

Browse files
authored
Merge pull request #63 from ethereumjs/remove-crypto
Remove dependency on crypto
2 parents 95683dd + 1d719ea commit 5735026

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"bs58check": "^2.1.2",
3737
"ethereumjs-util": "^5.2.0",
3838
"hdkey": "^1.0.0",
39+
"randombytes": "^2.0.6",
3940
"safe-buffer": "^5.1.2",
4041
"scrypt.js": "^0.2.0",
4142
"utf8": "^3.0.0",

src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var Buffer = require('safe-buffer').Buffer
22
var ethUtil = require('ethereumjs-util')
33
var crypto = require('crypto')
4+
var randomBytes = require('randombytes')
45
var scryptsy = require('scrypt.js')
56
var uuidv4 = require('uuid/v4')
67
var bs58check = require('bs58check')
@@ -52,13 +53,13 @@ Wallet.generate = function (icapDirect) {
5253
if (icapDirect) {
5354
var max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
5455
while (true) {
55-
var privKey = crypto.randomBytes(32)
56+
var privKey = randomBytes(32)
5657
if (new ethUtil.BN(ethUtil.privateToAddress(privKey)).lte(max)) {
5758
return new Wallet(privKey)
5859
}
5960
}
6061
} else {
61-
return new Wallet(crypto.randomBytes(32))
62+
return new Wallet(randomBytes(32))
6263
}
6364
}
6465

@@ -68,7 +69,7 @@ Wallet.generateVanityAddress = function (pattern) {
6869
}
6970

7071
while (true) {
71-
var privKey = crypto.randomBytes(32)
72+
var privKey = randomBytes(32)
7273
var address = ethUtil.privateToAddress(privKey)
7374

7475
if (pattern.test(address.toString('hex'))) {
@@ -110,8 +111,8 @@ Wallet.prototype.toV3 = function (password, opts) {
110111
assert(this._privKey, 'This is a public key only wallet')
111112

112113
opts = opts || {}
113-
var salt = opts.salt || crypto.randomBytes(32)
114-
var iv = opts.iv || crypto.randomBytes(16)
114+
var salt = opts.salt || randomBytes(32)
115+
var iv = opts.iv || randomBytes(16)
115116

116117
var derivedKey
117118
var kdf = opts.kdf || 'scrypt'
@@ -145,7 +146,7 @@ Wallet.prototype.toV3 = function (password, opts) {
145146

146147
return {
147148
version: 3,
148-
id: uuidv4({ random: opts.uuid || crypto.randomBytes(16) }),
149+
id: uuidv4({ random: opts.uuid || randomBytes(16) }),
149150
address: this.getAddress().toString('hex'),
150151
crypto: {
151152
ciphertext: ciphertext.toString('hex'),

0 commit comments

Comments
 (0)