Merge pull request #21 from ethereumjs/fix-travis-build

Fix travis build / Update Buffer usage
This commit is contained in:
Alex Beregszaszi 2018-02-03 23:09:17 +00:00 committed by GitHub
commit cfe0f60088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 47 deletions

1
.gitignore vendored
View File

@ -26,6 +26,7 @@ build/Release
# Dependency directory # Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules node_modules
package-lock.json
# Optional npm cache directory # Optional npm cache directory
.npm .npm

View File

@ -1,9 +1,8 @@
language: node_js language: node_js
node_js: node_js:
- "0.11"
- "0.12"
- "4" - "4"
- "5" - "6"
- "8"
env: env:
- CXX=g++-4.8 - CXX=g++-4.8
addons: addons:
@ -12,6 +11,11 @@ addons:
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
packages: packages:
- g++-4.8 - g++-4.8
branches:
# We need to whitelist the branches which we want to have "push" automation.
# Pull request automation is not constrained to this set of branches.
only:
- master
env: env:
matrix: matrix:
- CXX=g++-4.8 TEST_SUITE=test - CXX=g++-4.8 TEST_SUITE=test
@ -19,9 +23,9 @@ matrix:
fast_finish: true fast_finish: true
include: include:
- os: linux - os: linux
node_js: "4" node_js: "8"
env: CXX=g++-4.8 TEST_SUITE=coveralls env: CXX=g++-4.8 TEST_SUITE=coveralls
- os: linux - os: linux
node_js: "4" node_js: "8"
env: CXX=g++-4.8 TEST_SUITE=lint env: CXX=g++-4.8 TEST_SUITE=lint
script: npm run $TEST_SUITE script: npm run $TEST_SUITE

View File

@ -1,7 +1,7 @@
# ethereumjs-wallet # ethereumjs-wallet
[![NPM Package](https://img.shields.io/npm/v/ethereumjs-wallet.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-wallet) [![NPM Package](https://img.shields.io/npm/v/ethereumjs-wallet.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-wallet)
[![Build Status](https://img.shields.io/travis/ethereumjs/ethereumjs-wallet.svg?branch=master&style=flat-square)](https://travis-ci.org/ethereumjs/ethereumjs-wallet) [![Build Status](https://travis-ci.org/ethereumjs/ethereumjs-wallet.svg?branch=master)](https://travis-ci.org/ethereumjs/ethereumjs-wallet)
[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-wallet.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-wallet) [![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-wallet.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-wallet)
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode [![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode

View File

@ -1,3 +1,4 @@
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 scryptsy = require('scrypt.js') var scryptsy = require('scrypt.js')
@ -122,13 +123,13 @@ Wallet.prototype.toV3 = function (password, opts) {
if (kdf === 'pbkdf2') { if (kdf === 'pbkdf2') {
kdfparams.c = opts.c || 262144 kdfparams.c = opts.c || 262144
kdfparams.prf = 'hmac-sha256' kdfparams.prf = 'hmac-sha256'
derivedKey = crypto.pbkdf2Sync(new Buffer(password), salt, kdfparams.c, kdfparams.dklen, 'sha256') derivedKey = crypto.pbkdf2Sync(Buffer.from(password), salt, kdfparams.c, kdfparams.dklen, 'sha256')
} else if (kdf === 'scrypt') { } else if (kdf === 'scrypt') {
// FIXME: support progress reporting callback // FIXME: support progress reporting callback
kdfparams.n = opts.n || 262144 kdfparams.n = opts.n || 262144
kdfparams.r = opts.r || 8 kdfparams.r = opts.r || 8
kdfparams.p = opts.p || 1 kdfparams.p = opts.p || 1
derivedKey = scryptsy(new Buffer(password), salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen) derivedKey = scryptsy(Buffer.from(password), salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen)
} else { } else {
throw new Error('Unsupported kdf') throw new Error('Unsupported kdf')
} }
@ -140,7 +141,7 @@ Wallet.prototype.toV3 = function (password, opts) {
var ciphertext = Buffer.concat([ cipher.update(this.privKey), cipher.final() ]) var ciphertext = Buffer.concat([ cipher.update(this.privKey), cipher.final() ])
var mac = ethUtil.sha3(Buffer.concat([ derivedKey.slice(16, 32), new Buffer(ciphertext, 'hex') ])) var mac = ethUtil.sha3(Buffer.concat([ derivedKey.slice(16, 32), Buffer.from(ciphertext, 'hex') ]))
return { return {
version: 3, version: 3,
@ -224,9 +225,9 @@ Wallet.fromV1 = function (input, password) {
} }
var kdfparams = json.Crypto.KeyHeader.KdfParams var kdfparams = json.Crypto.KeyHeader.KdfParams
var derivedKey = scryptsy(new Buffer(password), new Buffer(json.Crypto.Salt, 'hex'), kdfparams.N, kdfparams.R, kdfparams.P, kdfparams.DkLen) var derivedKey = scryptsy(Buffer.from(password), Buffer.from(json.Crypto.Salt, 'hex'), kdfparams.N, kdfparams.R, kdfparams.P, kdfparams.DkLen)
var ciphertext = new Buffer(json.Crypto.CipherText, 'hex') var ciphertext = Buffer.from(json.Crypto.CipherText, 'hex')
var mac = ethUtil.sha3(Buffer.concat([ derivedKey.slice(16, 32), ciphertext ])) var mac = ethUtil.sha3(Buffer.concat([ derivedKey.slice(16, 32), ciphertext ]))
@ -234,7 +235,7 @@ Wallet.fromV1 = function (input, password) {
throw new Error('Key derivation failed - possibly wrong passphrase') throw new Error('Key derivation failed - possibly wrong passphrase')
} }
var decipher = crypto.createDecipheriv('aes-128-cbc', ethUtil.sha3(derivedKey.slice(0, 16)).slice(0, 16), new Buffer(json.Crypto.IV, 'hex')) var decipher = crypto.createDecipheriv('aes-128-cbc', ethUtil.sha3(derivedKey.slice(0, 16)).slice(0, 16), Buffer.from(json.Crypto.IV, 'hex'))
var seed = decipherBuffer(decipher, ciphertext) var seed = decipherBuffer(decipher, ciphertext)
return new Wallet(seed) return new Wallet(seed)
@ -254,7 +255,7 @@ Wallet.fromV3 = function (input, password, nonStrict) {
kdfparams = json.crypto.kdfparams kdfparams = json.crypto.kdfparams
// FIXME: support progress reporting callback // FIXME: support progress reporting callback
derivedKey = scryptsy(new Buffer(password), new Buffer(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen) derivedKey = scryptsy(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen)
} else if (json.crypto.kdf === 'pbkdf2') { } else if (json.crypto.kdf === 'pbkdf2') {
kdfparams = json.crypto.kdfparams kdfparams = json.crypto.kdfparams
@ -262,19 +263,19 @@ Wallet.fromV3 = function (input, password, nonStrict) {
throw new Error('Unsupported parameters to PBKDF2') throw new Error('Unsupported parameters to PBKDF2')
} }
derivedKey = crypto.pbkdf2Sync(new Buffer(password), new Buffer(kdfparams.salt, 'hex'), kdfparams.c, kdfparams.dklen, 'sha256') derivedKey = crypto.pbkdf2Sync(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.c, kdfparams.dklen, 'sha256')
} else { } else {
throw new Error('Unsupported key derivation scheme') throw new Error('Unsupported key derivation scheme')
} }
var ciphertext = new Buffer(json.crypto.ciphertext, 'hex') var ciphertext = Buffer.from(json.crypto.ciphertext, 'hex')
var mac = ethUtil.sha3(Buffer.concat([ derivedKey.slice(16, 32), ciphertext ])) var mac = ethUtil.sha3(Buffer.concat([ derivedKey.slice(16, 32), ciphertext ]))
if (mac.toString('hex') !== json.crypto.mac) { if (mac.toString('hex') !== json.crypto.mac) {
throw new Error('Key derivation failed - possibly wrong passphrase') throw new Error('Key derivation failed - possibly wrong passphrase')
} }
var decipher = crypto.createDecipheriv(json.crypto.cipher, derivedKey.slice(0, 16), new Buffer(json.crypto.cipherparams.iv, 'hex')) var decipher = crypto.createDecipheriv(json.crypto.cipher, derivedKey.slice(0, 16), Buffer.from(json.crypto.cipherparams.iv, 'hex'))
var seed = decipherBuffer(decipher, ciphertext, 'hex') var seed = decipherBuffer(decipher, ciphertext, 'hex')
return new Wallet(seed) return new Wallet(seed)
@ -288,7 +289,7 @@ Wallet.fromEthSale = function (input, password) {
assert(typeof password === 'string') assert(typeof password === 'string')
var json = (typeof input === 'object') ? input : JSON.parse(input) var json = (typeof input === 'object') ? input : JSON.parse(input)
var encseed = new Buffer(json.encseed, 'hex') var encseed = Buffer.from(json.encseed, 'hex')
// key derivation // key derivation
var derivedKey = crypto.pbkdf2Sync(password, password, 2000, 32, 'sha256').slice(0, 16) var derivedKey = crypto.pbkdf2Sync(password, password, 2000, 32, 'sha256').slice(0, 16)

View File

@ -30,15 +30,16 @@
"bs58check": "^1.0.8", "bs58check": "^1.0.8",
"ethereumjs-util": "^4.4.0", "ethereumjs-util": "^4.4.0",
"hdkey": "^0.7.0", "hdkey": "^0.7.0",
"safe-buffer": "^5.1.1",
"scrypt.js": "^0.2.0", "scrypt.js": "^0.2.0",
"uuid": "^2.0.1", "utf8": "^2.1.1",
"utf8": "^2.1.1" "uuid": "^2.0.1"
}, },
"devDependencies": { "devDependencies": {
"coveralls": "^2.11.4", "coveralls": "^2.11.4",
"istanbul": "^0.4.1", "istanbul": "^0.4.1",
"mocha": "^2.3.4", "mocha": "^2.3.4",
"standard": "^5.4.1" "standard": "^10.0.0"
}, },
"standard": { "standard": {
"globals": [ "globals": [

View File

@ -14,10 +14,10 @@ function WalletSubprovider (wallet, opts) {
opts.getPrivateKey = function (address, cb) { opts.getPrivateKey = function (address, cb) {
if (address !== wallet.getAddressString()) { if (address !== wallet.getAddressString()) {
return cb('Account not found') cb(new Error('Account not found'))
} else {
cb(null, wallet.getPrivateKey())
} }
cb(null, wallet.getPrivateKey())
} }
WalletSubprovider.super_.call(this, opts) WalletSubprovider.super_.call(this, opts)

View File

@ -1,8 +1,9 @@
var assert = require('assert') var assert = require('assert')
var HDKey = require('../hdkey.js') var HDKey = require('../hdkey.js')
var Buffer = require('safe-buffer').Buffer
// from BIP39 mnemonic: awake book subject inch gentle blur grant damage process float month clown // from BIP39 mnemonic: awake book subject inch gentle blur grant damage process float month clown
var fixtureseed = new Buffer('747f302d9c916698912d5f70be53a6cf53bc495803a5523d3a7c3afa2afba94ec3803f838b3e1929ab5481f9da35441372283690fdcf27372c38f40ba134fe03', 'hex') var fixtureseed = Buffer.from('747f302d9c916698912d5f70be53a6cf53bc495803a5523d3a7c3afa2afba94ec3803f838b3e1929ab5481f9da35441372283690fdcf27372c38f40ba134fe03', 'hex')
var fixturehd = HDKey.fromMasterSeed(fixtureseed) var fixturehd = HDKey.fromMasterSeed(fixtureseed)
describe('.fromMasterSeed()', function () { describe('.fromMasterSeed()', function () {

View File

@ -1,9 +1,10 @@
var assert = require('assert') var assert = require('assert')
var Buffer = require('safe-buffer').Buffer
var Wallet = require('../') var Wallet = require('../')
var Thirdparty = require('../thirdparty.js') var Thirdparty = require('../thirdparty.js')
var ethUtil = require('ethereumjs-util') var ethUtil = require('ethereumjs-util')
var fixturekey = new Buffer('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex') var fixturekey = Buffer.from('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex')
var fixturewallet = Wallet.fromPrivateKey(fixturekey) var fixturewallet = Wallet.fromPrivateKey(fixturekey)
describe('.getPrivateKey()', function () { describe('.getPrivateKey()', function () {
@ -12,7 +13,7 @@ describe('.getPrivateKey()', function () {
}) })
it('should fail', function () { it('should fail', function () {
assert.throws(function () { assert.throws(function () {
Wallet.fromPrivateKey(new Buffer('001122', 'hex')) Wallet.fromPrivateKey(Buffer.from('001122', 'hex'))
}, /^Error: Private key does not satisfy the curve requirements \(ie. it is invalid\)$/) }, /^Error: Private key does not satisfy the curve requirements \(ie. it is invalid\)$/)
}) })
}) })
@ -54,18 +55,18 @@ describe('.getChecksumAddressString()', function () {
}) })
describe('public key only wallet', function () { describe('public key only wallet', function () {
var pubKey = new Buffer('5d4392f450262b276652c1fc037606abac500f3160830ce9df53aa70d95ce7cfb8b06010b2f3691c78c65c21eb4cf3dfdbfc0745d89b664ee10435bb3a0f906c', 'hex') var pubKey = Buffer.from('5d4392f450262b276652c1fc037606abac500f3160830ce9df53aa70d95ce7cfb8b06010b2f3691c78c65c21eb4cf3dfdbfc0745d89b664ee10435bb3a0f906c', 'hex')
it('.fromPublicKey() should work', function () { it('.fromPublicKey() should work', function () {
assert.equal(Wallet.fromPublicKey(pubKey).getPublicKey().toString('hex'), assert.equal(Wallet.fromPublicKey(pubKey).getPublicKey().toString('hex'),
'5d4392f450262b276652c1fc037606abac500f3160830ce9df53aa70d95ce7cfb8b06010b2f3691c78c65c21eb4cf3dfdbfc0745d89b664ee10435bb3a0f906c') '5d4392f450262b276652c1fc037606abac500f3160830ce9df53aa70d95ce7cfb8b06010b2f3691c78c65c21eb4cf3dfdbfc0745d89b664ee10435bb3a0f906c')
}) })
it('.fromPublicKey() should not accept compressed keys in strict mode', function () { it('.fromPublicKey() should not accept compressed keys in strict mode', function () {
assert.throws(function () { assert.throws(function () {
Wallet.fromPublicKey(new Buffer('030639797f6cc72aea0f3d309730844a9e67d9f1866e55845c5f7e0ab48402973d', 'hex')) Wallet.fromPublicKey(Buffer.from('030639797f6cc72aea0f3d309730844a9e67d9f1866e55845c5f7e0ab48402973d', 'hex'))
}, /^Error: Invalid public key$/) }, /^Error: Invalid public key$/)
}) })
it('.fromPublicKey() should accept compressed keys in non-strict mode', function () { it('.fromPublicKey() should accept compressed keys in non-strict mode', function () {
var tmp = new Buffer('030639797f6cc72aea0f3d309730844a9e67d9f1866e55845c5f7e0ab48402973d', 'hex') var tmp = Buffer.from('030639797f6cc72aea0f3d309730844a9e67d9f1866e55845c5f7e0ab48402973d', 'hex')
assert.equal(Wallet.fromPublicKey(tmp, true).getPublicKey().toString('hex'), assert.equal(Wallet.fromPublicKey(tmp, true).getPublicKey().toString('hex'),
'0639797f6cc72aea0f3d309730844a9e67d9f1866e55845c5f7e0ab48402973defa5cb69df462bcc6d73c31e1c663c225650e80ef14a507b203f2a12aea55bc1') '0639797f6cc72aea0f3d309730844a9e67d9f1866e55845c5f7e0ab48402973defa5cb69df462bcc6d73c31e1c663c225650e80ef14a507b203f2a12aea55bc1')
}) })
@ -126,19 +127,19 @@ describe('.getV3Filename()', function () {
}) })
describe('.toV3()', function () { describe('.toV3()', function () {
var salt = new Buffer('dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6', 'hex') var salt = Buffer.from('dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6', 'hex')
var iv = new Buffer('cecacd85e9cb89788b5aab2f93361233', 'hex') var iv = Buffer.from('cecacd85e9cb89788b5aab2f93361233', 'hex')
var uuid = new Buffer('7e59dc028d42d09db29aa8a0f862cc81', 'hex') var uuid = Buffer.from('7e59dc028d42d09db29aa8a0f862cc81', 'hex')
it('should work with PBKDF2', function () { it('should work with PBKDF2', function () {
var key = new Buffer('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex') var key = Buffer.from('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex')
var wallet = Wallet.fromPrivateKey(key) var wallet = Wallet.fromPrivateKey(key)
var w = '{"version":3,"id":"7e59dc02-8d42-409d-b29a-a8a0f862cc81","address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"ciphertext":"01ee7f1a3c8d187ea244c92eea9e332ab0bb2b4c902d89bdd71f80dc384da1be","cipherparams":{"iv":"cecacd85e9cb89788b5aab2f93361233"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6","c":262144,"prf":"hmac-sha256"},"mac":"0c02cd0badfebd5e783e0cf41448f84086a96365fc3456716c33641a86ebc7cc"}}' var w = '{"version":3,"id":"7e59dc02-8d42-409d-b29a-a8a0f862cc81","address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"ciphertext":"01ee7f1a3c8d187ea244c92eea9e332ab0bb2b4c902d89bdd71f80dc384da1be","cipherparams":{"iv":"cecacd85e9cb89788b5aab2f93361233"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6","c":262144,"prf":"hmac-sha256"},"mac":"0c02cd0badfebd5e783e0cf41448f84086a96365fc3456716c33641a86ebc7cc"}}'
// FIXME: just test for ciphertext and mac? // FIXME: just test for ciphertext and mac?
assert.equal(wallet.toV3String('testtest', { kdf: 'pbkdf2', uuid: uuid, salt: salt, iv: iv }), w) assert.equal(wallet.toV3String('testtest', { kdf: 'pbkdf2', uuid: uuid, salt: salt, iv: iv }), w)
}) })
it('should work with Scrypt', function () { it('should work with Scrypt', function () {
var key = new Buffer('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex') var key = Buffer.from('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex')
var wallet = Wallet.fromPrivateKey(key) var wallet = Wallet.fromPrivateKey(key)
var w = '{"version":3,"id":"7e59dc02-8d42-409d-b29a-a8a0f862cc81","address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"ciphertext":"c52682025b1e5d5c06b816791921dbf439afe7a053abb9fac19f38a57499652c","cipherparams":{"iv":"cecacd85e9cb89788b5aab2f93361233"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6","n":262144,"r":8,"p":1},"mac":"27b98c8676dc6619d077453b38db645a4c7c17a3e686ee5adaf53c11ac1b890e"}}' var w = '{"version":3,"id":"7e59dc02-8d42-409d-b29a-a8a0f862cc81","address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"ciphertext":"c52682025b1e5d5c06b816791921dbf439afe7a053abb9fac19f38a57499652c","cipherparams":{"iv":"cecacd85e9cb89788b5aab2f93361233"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"dc9e4a98886738bd8aae134a1f89aaa5a502c3fbd10e336136d4d5fe47448ad6","n":262144,"r":8,"p":1},"mac":"27b98c8676dc6619d077453b38db645a4c7c17a3e686ee5adaf53c11ac1b890e"}}'
this.timeout(180000) // 3minutes this.timeout(180000) // 3minutes

View File

@ -4,6 +4,7 @@ var crypto = require('crypto')
var scryptsy = require('scrypt.js') var scryptsy = require('scrypt.js')
var utf8 = require('utf8') var utf8 = require('utf8')
var aesjs = require('aes-js') var aesjs = require('aes-js')
var Buffer = require('safe-buffer').Buffer
function assert (val, msg) { function assert (val, msg) {
if (!val) { if (!val) {
@ -28,7 +29,7 @@ var Thirdparty = {}
* *
* FIXME: not optimised at all * FIXME: not optimised at all
*/ */
function evp_kdf (data, salt, opts) { function evp_kdf (data, salt, opts) { // eslint-disable-line
// A single EVP iteration, returns `D_i`, where block equlas to `D_(i-1)` // A single EVP iteration, returns `D_i`, where block equlas to `D_(i-1)`
function iter (block) { function iter (block) {
var hash = crypto.createHash(opts.digest || 'md5') var hash = crypto.createHash(opts.digest || 'md5')
@ -53,7 +54,7 @@ function evp_kdf (data, salt, opts) {
var i = 0 var i = 0
while (Buffer.concat(ret).length < (keysize + ivsize)) { while (Buffer.concat(ret).length < (keysize + ivsize)) {
ret[i] = iter((i === 0) ? new Buffer(0) : ret[i - 1]) ret[i] = iter((i === 0) ? Buffer.alloc(0) : ret[i - 1])
i++ i++
} }
@ -67,7 +68,7 @@ function evp_kdf (data, salt, opts) {
// http://stackoverflow.com/questions/25288311/cryptojs-aes-pattern-always-ends-with // http://stackoverflow.com/questions/25288311/cryptojs-aes-pattern-always-ends-with
function decodeCryptojsSalt (input) { function decodeCryptojsSalt (input) {
var ciphertext = new Buffer(input, 'base64') var ciphertext = Buffer.from(input, 'base64')
if (ciphertext.slice(0, 8).toString() === 'Salted__') { if (ciphertext.slice(0, 8).toString() === 'Salted__') {
return { return {
salt: ciphertext.slice(8, 16), salt: ciphertext.slice(8, 16),
@ -93,7 +94,7 @@ Thirdparty.fromEtherWallet = function (input, password) {
throw new Error('Invalid private key length') throw new Error('Invalid private key length')
} }
privKey = new Buffer(json.private, 'hex') privKey = Buffer.from(json.private, 'hex')
} else { } else {
if (typeof password !== 'string') { if (typeof password !== 'string') {
throw new Error('Password required') throw new Error('Password required')
@ -114,13 +115,13 @@ Thirdparty.fromEtherWallet = function (input, password) {
} }
// derive key/iv using OpenSSL EVP as implemented in CryptoJS // derive key/iv using OpenSSL EVP as implemented in CryptoJS
var evp = evp_kdf(new Buffer(password), cipher.salt, { keysize: 32, ivsize: 16 }) var evp = evp_kdf(Buffer.from(password), cipher.salt, { keysize: 32, ivsize: 16 })
var decipher = crypto.createDecipheriv('aes-256-cbc', evp.key, evp.iv) var decipher = crypto.createDecipheriv('aes-256-cbc', evp.key, evp.iv)
privKey = decipherBuffer(decipher, new Buffer(cipher.ciphertext)) privKey = decipherBuffer(decipher, Buffer.from(cipher.ciphertext))
// NOTE: yes, they've run it through UTF8 // NOTE: yes, they've run it through UTF8
privKey = new Buffer(utf8.decode(privKey.toString()), 'hex') privKey = Buffer.from(utf8.decode(privKey.toString()), 'hex')
} }
var wallet = new Wallet(privKey) var wallet = new Wallet(privKey)
@ -133,12 +134,12 @@ Thirdparty.fromEtherWallet = function (input, password) {
} }
Thirdparty.fromEtherCamp = function (passphrase) { Thirdparty.fromEtherCamp = function (passphrase) {
return new Wallet(ethUtil.sha3(new Buffer(passphrase))) return new Wallet(ethUtil.sha3(Buffer.from(passphrase)))
} }
Thirdparty.fromKryptoKit = function (entropy, password) { Thirdparty.fromKryptoKit = function (entropy, password) {
function kryptoKitBrokenScryptSeed (buf) { function kryptoKitBrokenScryptSeed (buf) {
// js-scrypt calls `new Buffer(String(salt), 'utf8')` on the seed even though it is a buffer // js-scrypt calls `Buffer.from(String(salt), 'utf8')` on the seed even though it is a buffer
// //
// The `buffer`` implementation used does the below transformation (doesn't matches the current version): // The `buffer`` implementation used does the below transformation (doesn't matches the current version):
// https://github.com/feross/buffer/blob/67c61181b938b17d10dbfc0a545f713b8bd59de8/index.js // https://github.com/feross/buffer/blob/67c61181b938b17d10dbfc0a545f713b8bd59de8/index.js
@ -163,7 +164,7 @@ Thirdparty.fromKryptoKit = function (entropy, password) {
} }
} }
return new Buffer(res + decodeUtf8Char(tmp)) return Buffer.from(res + decodeUtf8Char(tmp))
} }
if (entropy[0] === '#') { if (entropy[0] === '#') {
@ -181,16 +182,16 @@ Thirdparty.fromKryptoKit = function (entropy, password) {
throw new Error('Password required') throw new Error('Password required')
} }
var encryptedSeed = ethUtil.sha256(new Buffer(entropy.slice(0, 30))) var encryptedSeed = ethUtil.sha256(Buffer.from(entropy.slice(0, 30)))
var checksum = entropy.slice(30, 46) var checksum = entropy.slice(30, 46)
var salt = kryptoKitBrokenScryptSeed(encryptedSeed) var salt = kryptoKitBrokenScryptSeed(encryptedSeed)
var aesKey = scryptsy(new Buffer(password, 'utf8'), salt, 16384, 8, 1, 32) var aesKey = scryptsy(Buffer.from(password, 'utf8'), salt, 16384, 8, 1, 32)
/* FIXME: try to use `crypto` instead of `aesjs` /* FIXME: try to use `crypto` instead of `aesjs`
// NOTE: ECB doesn't use the IV, so it can be anything // NOTE: ECB doesn't use the IV, so it can be anything
var decipher = crypto.createDecipheriv("aes-256-ecb", aesKey, new Buffer(0)) var decipher = crypto.createDecipheriv("aes-256-ecb", aesKey, Buffer.from(0))
// FIXME: this is a clear abuse, but seems to match how ECB in aesjs works // FIXME: this is a clear abuse, but seems to match how ECB in aesjs works
privKey = Buffer.concat([ privKey = Buffer.concat([