mirror of
https://github.com/embarklabs/ethereumjs-wallet.git
synced 2025-01-15 13:15:22 +00:00
Merge pull request #63 from ethereumjs/remove-crypto
Remove dependency on crypto
This commit is contained in:
commit
573502611f
@ -36,6 +36,7 @@
|
|||||||
"bs58check": "^2.1.2",
|
"bs58check": "^2.1.2",
|
||||||
"ethereumjs-util": "^5.2.0",
|
"ethereumjs-util": "^5.2.0",
|
||||||
"hdkey": "^1.0.0",
|
"hdkey": "^1.0.0",
|
||||||
|
"randombytes": "^2.0.6",
|
||||||
"safe-buffer": "^5.1.2",
|
"safe-buffer": "^5.1.2",
|
||||||
"scrypt.js": "^0.2.0",
|
"scrypt.js": "^0.2.0",
|
||||||
"utf8": "^3.0.0",
|
"utf8": "^3.0.0",
|
||||||
|
13
src/index.js
13
src/index.js
@ -1,6 +1,7 @@
|
|||||||
var Buffer = require('safe-buffer').Buffer
|
var Buffer = require('safe-buffer').Buffer
|
||||||
var ethUtil = require('ethereumjs-util')
|
var ethUtil = require('ethereumjs-util')
|
||||||
var crypto = require('crypto')
|
var crypto = require('crypto')
|
||||||
|
var randomBytes = require('randombytes')
|
||||||
var scryptsy = require('scrypt.js')
|
var scryptsy = require('scrypt.js')
|
||||||
var uuidv4 = require('uuid/v4')
|
var uuidv4 = require('uuid/v4')
|
||||||
var bs58check = require('bs58check')
|
var bs58check = require('bs58check')
|
||||||
@ -52,13 +53,13 @@ Wallet.generate = function (icapDirect) {
|
|||||||
if (icapDirect) {
|
if (icapDirect) {
|
||||||
var max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
|
var max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
|
||||||
while (true) {
|
while (true) {
|
||||||
var privKey = crypto.randomBytes(32)
|
var privKey = randomBytes(32)
|
||||||
if (new ethUtil.BN(ethUtil.privateToAddress(privKey)).lte(max)) {
|
if (new ethUtil.BN(ethUtil.privateToAddress(privKey)).lte(max)) {
|
||||||
return new Wallet(privKey)
|
return new Wallet(privKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new Wallet(crypto.randomBytes(32))
|
return new Wallet(randomBytes(32))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ Wallet.generateVanityAddress = function (pattern) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
var privKey = crypto.randomBytes(32)
|
var privKey = randomBytes(32)
|
||||||
var address = ethUtil.privateToAddress(privKey)
|
var address = ethUtil.privateToAddress(privKey)
|
||||||
|
|
||||||
if (pattern.test(address.toString('hex'))) {
|
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')
|
assert(this._privKey, 'This is a public key only wallet')
|
||||||
|
|
||||||
opts = opts || {}
|
opts = opts || {}
|
||||||
var salt = opts.salt || crypto.randomBytes(32)
|
var salt = opts.salt || randomBytes(32)
|
||||||
var iv = opts.iv || crypto.randomBytes(16)
|
var iv = opts.iv || randomBytes(16)
|
||||||
|
|
||||||
var derivedKey
|
var derivedKey
|
||||||
var kdf = opts.kdf || 'scrypt'
|
var kdf = opts.kdf || 'scrypt'
|
||||||
@ -145,7 +146,7 @@ Wallet.prototype.toV3 = function (password, opts) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
version: 3,
|
version: 3,
|
||||||
id: uuidv4({ random: opts.uuid || crypto.randomBytes(16) }),
|
id: uuidv4({ random: opts.uuid || randomBytes(16) }),
|
||||||
address: this.getAddress().toString('hex'),
|
address: this.getAddress().toString('hex'),
|
||||||
crypto: {
|
crypto: {
|
||||||
ciphertext: ciphertext.toString('hex'),
|
ciphertext: ciphertext.toString('hex'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user