@endpass/utils
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -5,2 +5,3 @@ 'use strict'; | ||
var constants = require('./constants.js'); | ||
var keythereum = _interopDefault(require('keythereum')); | ||
@@ -24,9 +25,13 @@ var bs58check = _interopDefault(require('bs58check')); | ||
encrypt: function encrypt(password, privateKey) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : constants.KDF_ENCRYPT_OPTIONS; | ||
// Generate random salt and iv for each encryption | ||
var dk = keythereum.create(); | ||
var options = { | ||
kdf: ENV.kdfParams.kdf, | ||
kdfparams: ENV.kdfParams | ||
var dumpOptions = { | ||
kdf: options.kdf, | ||
kdfparams: { | ||
kdf: options.kdf, | ||
n: options.n | ||
} | ||
}; | ||
var encrypted = keythereum.dump(password, privateKey, dk.salt, dk.iv, options); | ||
var encrypted = keythereum.dump(password, privateKey, dk.salt, dk.iv, dumpOptions); | ||
delete encrypted.address; | ||
@@ -48,4 +53,4 @@ return encrypted; | ||
// Encrypts an ethereumjs Wallet | ||
encryptWallet: function encryptWallet(password, wallet) { | ||
var json = this.encrypt(password, wallet.getPrivateKey()); | ||
encryptWallet: function encryptWallet(password, wallet, encryptOptions) { | ||
var json = this.encrypt(password, wallet.getPrivateKey(), encryptOptions); | ||
json.address = wallet.getChecksumAddressString(); | ||
@@ -60,5 +65,5 @@ return json; | ||
// Encrypts an ethereumjs Wallet | ||
encryptHDWallet: function encryptHDWallet(password, wallet) { | ||
encryptHDWallet: function encryptHDWallet(password, wallet, encryptOptions) { | ||
var xPrv = this.decodeBase58(wallet.privateExtendedKey()); | ||
var json = this.encrypt(password, xPrv); | ||
var json = this.encrypt(password, xPrv, encryptOptions); | ||
json.address = wallet.publicExtendedKey(); | ||
@@ -65,0 +70,0 @@ return json; |
{ | ||
"name": "@endpass/utils", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Utils and helper functions", | ||
@@ -47,4 +47,3 @@ "author": "Endpass, Inc", | ||
"access": "public" | ||
}, | ||
"gitHead": "8e5e46a50c6e2954980dc8f0f90974b797c0e08b" | ||
} | ||
} |
@@ -5,2 +5,3 @@ import keythereum from 'keythereum'; | ||
import HDKey from 'ethereumjs-wallet/hdkey'; | ||
import { KDF_ENCRYPT_OPTIONS } from './constants'; | ||
@@ -19,9 +20,14 @@ // Monkey patch keythereum to skip generating address for private keys | ||
// The exported keystore does NOT include an address | ||
encrypt(password, privateKey) { | ||
encrypt(password, privateKey, options = KDF_ENCRYPT_OPTIONS) { | ||
// Generate random salt and iv for each encryption | ||
const dk = keythereum.create(); | ||
const options = { | ||
kdf: ENV.kdfParams.kdf, | ||
kdfparams: ENV.kdfParams, | ||
const dumpOptions = { | ||
kdf: options.kdf, | ||
kdfparams: { | ||
kdf: options.kdf, | ||
n: options.n, | ||
}, | ||
}; | ||
const encrypted = keythereum.dump( | ||
@@ -32,3 +38,3 @@ password, | ||
dk.iv, | ||
options, | ||
dumpOptions, | ||
); | ||
@@ -55,4 +61,4 @@ | ||
// Encrypts an ethereumjs Wallet | ||
encryptWallet(password, wallet) { | ||
const json = this.encrypt(password, wallet.getPrivateKey()); | ||
encryptWallet(password, wallet, encryptOptions) { | ||
const json = this.encrypt(password, wallet.getPrivateKey(), encryptOptions); | ||
@@ -72,5 +78,5 @@ json.address = wallet.getChecksumAddressString(); | ||
// Encrypts an ethereumjs Wallet | ||
encryptHDWallet(password, wallet) { | ||
encryptHDWallet(password, wallet, encryptOptions) { | ||
const xPrv = this.decodeBase58(wallet.privateExtendedKey()); | ||
const json = this.encrypt(password, xPrv); | ||
const json = this.encrypt(password, xPrv, encryptOptions); | ||
@@ -77,0 +83,0 @@ json.address = wallet.publicExtendedKey(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
15627
24
416
0