Merge pull request #1 from embark-framework/web3-js-scrypt-shim
Web3 js scrypt shim
This commit is contained in:
commit
8fa52c876d
|
@ -42,3 +42,6 @@ package-lock.json
|
|||
|
||||
# build output
|
||||
dist
|
||||
|
||||
# pack output
|
||||
embarklabs-ethereumjs-wallet-*.tgz
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
/* global module require */
|
||||
|
||||
module.exports = require('./dist/hdkey').default;
|
|
@ -1,11 +1,12 @@
|
|||
{
|
||||
"name": "ethereumjs-wallet",
|
||||
"name": "@embarklabs/ethereumjs-wallet",
|
||||
"version": "0.6.3",
|
||||
"description": "Utilities for handling Ethereum keys",
|
||||
"main": "dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"hdkey.js"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "ethereumjs-config-build",
|
||||
|
@ -14,6 +15,7 @@
|
|||
"coveralls": "ethereumjs-config-coveralls",
|
||||
"format": "ethereumjs-config-format",
|
||||
"format-fix": "ethereumjs-config-format-fix",
|
||||
"format:fix": "ethereumjs-config-format-fix",
|
||||
"lint": "ethereumjs-config-lint",
|
||||
"lint-fix": "ethereumjs-config-lint-fix",
|
||||
"pretest": "npm run build",
|
||||
|
@ -43,12 +45,12 @@
|
|||
},
|
||||
"homepage": "https://github.com/ethereumjs/ethereumjs-wallet",
|
||||
"dependencies": {
|
||||
"@web3-js/scrypt-shim": "^0.1.0",
|
||||
"aes-js": "^3.1.1",
|
||||
"bs58check": "^2.1.2",
|
||||
"ethereumjs-util": "^6.0.0",
|
||||
"hdkey": "^1.1.1",
|
||||
"randombytes": "^2.0.6",
|
||||
"scrypt.js": "^0.3.0",
|
||||
"utf8": "^3.0.0",
|
||||
"uuid": "^3.3.2"
|
||||
},
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as ethUtil from 'ethereumjs-util'
|
|||
|
||||
const bs58check = require('bs58check')
|
||||
const randomBytes = require('randombytes')
|
||||
const scryptsy = require('scrypt.js')
|
||||
const scrypt = require('@web3-js/scrypt-shim')
|
||||
const uuidv4 = require('uuid/v4')
|
||||
|
||||
// parameters for the toV3() method
|
||||
|
@ -313,7 +313,7 @@ export default class Wallet {
|
|||
}
|
||||
|
||||
const kdfparams = json.Crypto.KeyHeader.KdfParams
|
||||
const derivedKey = scryptsy(
|
||||
const derivedKey = scrypt(
|
||||
Buffer.from(password),
|
||||
Buffer.from(json.Crypto.Salt, 'hex'),
|
||||
kdfparams.N,
|
||||
|
@ -354,7 +354,7 @@ export default class Wallet {
|
|||
kdfparams = json.crypto.kdfparams
|
||||
|
||||
// FIXME: support progress reporting callback
|
||||
derivedKey = scryptsy(
|
||||
derivedKey = scrypt(
|
||||
Buffer.from(password),
|
||||
Buffer.from(kdfparams.salt, 'hex'),
|
||||
kdfparams.n,
|
||||
|
@ -491,7 +491,7 @@ export default class Wallet {
|
|||
case KDFFunctions.Scrypt:
|
||||
kdfParams = kdfParamsForScrypt(v3Params)
|
||||
// FIXME: support progress reporting callback
|
||||
derivedKey = scryptsy(
|
||||
derivedKey = scrypt(
|
||||
Buffer.from(password),
|
||||
kdfParams.salt,
|
||||
kdfParams.n,
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as ethUtil from 'ethereumjs-util'
|
|||
|
||||
import Wallet from './index'
|
||||
|
||||
const scryptsy = require('scrypt.js')
|
||||
const scrypt = require('@web3-js/scrypt-shim')
|
||||
const utf8 = require('utf8')
|
||||
const aesjs = require('aes-js')
|
||||
|
||||
|
@ -213,7 +213,7 @@ function fromKryptoKit(entropy: string, password: string): Wallet {
|
|||
const checksum = entropy.slice(30, 46)
|
||||
|
||||
const salt = kryptoKitBrokenScryptSeed(encryptedSeed)
|
||||
const aesKey = scryptsy(Buffer.from(password, 'utf8'), salt, 16384, 8, 1, 32)
|
||||
const aesKey = scrypt(Buffer.from(password, 'utf8'), salt, 16384, 8, 1, 32)
|
||||
|
||||
/* FIXME: try to use `crypto` instead of `aesjs`
|
||||
|
||||
|
|
|
@ -297,12 +297,14 @@ describe('.toV3()', function() {
|
|||
p: p,
|
||||
})
|
||||
|
||||
const encFixtureEthersWallet = (await fixtureEthersWallet.encrypt(pw, {
|
||||
const encFixtureEthersWallet = (
|
||||
await fixtureEthersWallet.encrypt(pw, {
|
||||
scrypt: { N: n, r: r, p: p },
|
||||
salt: ethersOpts.salt,
|
||||
iv: ethersOpts.iv,
|
||||
uuid: ethersOpts.uuid,
|
||||
})).toLowerCase()
|
||||
})
|
||||
).toLowerCase()
|
||||
|
||||
const encRandomWallet = wRandom.toV3String(pw, {
|
||||
kdf: 'scrypt',
|
||||
|
@ -314,12 +316,14 @@ describe('.toV3()', function() {
|
|||
p: p,
|
||||
})
|
||||
|
||||
const encEthersWallet = (await wEthers.encrypt(pw, {
|
||||
const encEthersWallet = (
|
||||
await wEthers.encrypt(pw, {
|
||||
scrypt: { N: n, r: r, p: p },
|
||||
salt: ethersOpts.salt,
|
||||
iv: ethersOpts.iv,
|
||||
uuid: ethersOpts.uuid,
|
||||
})).toLowerCase()
|
||||
})
|
||||
).toLowerCase()
|
||||
|
||||
assert.deepStrictEqual(JSON.parse(wStatic), JSON.parse(encFixtureWallet))
|
||||
assert.deepStrictEqual(JSON.parse(wStatic), JSON.parse(encFixtureEthersWallet))
|
||||
|
|
Loading…
Reference in New Issue