Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Remove scrypt.js dependency (help wanted) #91

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"hdkey": "^1.1.1",
"randombytes": "^2.0.6",
"safe-buffer": "^5.1.2",
"scrypt.js": "^0.3.0",
"utf8": "^3.0.0",
"uuid": "^3.3.2"
},
Expand All @@ -54,7 +53,7 @@
"husky": "^2.1.0",
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"standard": "^12.0.0"
"standard": "^12.0.1"
},
"standard": {
"globals": [
Expand Down
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 @@ -130,7 +129,7 @@ Wallet.prototype.toV3 = function (password, opts) {
kdfparams.n = opts.n || 262144
kdfparams.r = opts.r || 8
kdfparams.p = opts.p || 1
derivedKey = scryptsy(Buffer.from(password), salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen)
derivedKey = crypto.scryptSync(Buffer.from(password), salt, kdfparams.dklen, { 'cost': kdfparams.n, 'blockSize': kdfparams.r, 'parallelization': kdfparams.p })
} else {
throw new Error('Unsupported kdf')
}
Expand Down Expand Up @@ -226,7 +225,7 @@ Wallet.fromV1 = function (input, password) {
}

var kdfparams = json.Crypto.KeyHeader.KdfParams
var derivedKey = scryptsy(Buffer.from(password), Buffer.from(json.Crypto.Salt, 'hex'), kdfparams.N, kdfparams.R, kdfparams.P, kdfparams.DkLen)
var derivedKey = crypto.scryptSync(Buffer.from(password), Buffer.from(json.Crypto.Salt, 'hex'), kdfparams.dklen, { 'cost': kdfparams.n, 'blockSize': kdfparams.r, 'parallelization': kdfparams.p })

var ciphertext = Buffer.from(json.Crypto.CipherText, 'hex')

Expand Down Expand Up @@ -256,7 +255,7 @@ Wallet.fromV3 = function (input, password, nonStrict) {
kdfparams = json.crypto.kdfparams

// FIXME: support progress reporting callback
derivedKey = scryptsy(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen)
derivedKey = crypto.scryptSync(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.dklen, { 'cost': kdfparams.n, 'blockSize': kdfparams.r, 'parallelization': kdfparams.p })
} else if (json.crypto.kdf === 'pbkdf2') {
kdfparams = json.crypto.kdfparams

Expand Down
8 changes: 6 additions & 2 deletions src/thirdparty.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var Wallet = require('./index.js')
var ethUtil = require('ethereumjs-util')
var crypto = require('crypto')
var scryptsy = require('scrypt.js')
var utf8 = require('utf8')
var aesjs = require('aes-js')
var Buffer = require('safe-buffer').Buffer
Expand Down Expand Up @@ -186,7 +185,12 @@ Thirdparty.fromKryptoKit = function (entropy, password) {
var checksum = entropy.slice(30, 46)

var salt = kryptoKitBrokenScryptSeed(encryptedSeed)
var aesKey = scryptsy(Buffer.from(password, 'utf8'), salt, 16384, 8, 1, 32)
var dklen = 32
var n = 16384
var r = 8
var p = 1

var aesKey = crypto.scryptSync(Buffer.from(password, 'utf8'), salt, dklen, { 'cost': n, 'blockSize': r, 'parallelization': p })

/* FIXME: try to use `crypto` instead of `aesjs`

Expand Down