Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 9ee22af

Browse files
committed
Refactor decipherBuffer
1 parent 444d833 commit 9ee22af

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function assert (val, msg) {
1212
}
1313
}
1414

15-
function decipherBuffer (decipher, data) {
16-
return Buffer.concat([ decipher.update(data), decipher.final() ])
15+
function runCipherBuffer (cipher, data) {
16+
return Buffer.concat([ cipher.update(data), cipher.final() ])
1717
}
1818

1919
var Wallet = function (priv, pub) {
@@ -140,7 +140,7 @@ Wallet.prototype.toV3 = function (password, opts) {
140140
throw new Error('Unsupported cipher')
141141
}
142142

143-
var ciphertext = Buffer.concat([ cipher.update(this.privKey), cipher.final() ])
143+
var ciphertext = runCipherBuffer(cipher, this.privKey)
144144

145145
var mac = ethUtil.keccak256(Buffer.concat([ derivedKey.slice(16, 32), Buffer.from(ciphertext, 'hex') ]))
146146

@@ -237,7 +237,7 @@ Wallet.fromV1 = function (input, password) {
237237
}
238238

239239
var decipher = crypto.createDecipheriv('aes-128-cbc', ethUtil.keccak256(derivedKey.slice(0, 16)).slice(0, 16), Buffer.from(json.Crypto.IV, 'hex'))
240-
var seed = decipherBuffer(decipher, ciphertext)
240+
var seed = runCipherBuffer(decipher, ciphertext)
241241

242242
return new Wallet(seed)
243243
}
@@ -277,7 +277,7 @@ Wallet.fromV3 = function (input, password, nonStrict) {
277277
}
278278

279279
var decipher = crypto.createDecipheriv(json.crypto.cipher, derivedKey.slice(0, 16), Buffer.from(json.crypto.cipherparams.iv, 'hex'))
280-
var seed = decipherBuffer(decipher, ciphertext)
280+
var seed = runCipherBuffer(decipher, ciphertext)
281281

282282
return new Wallet(seed)
283283
}
@@ -299,7 +299,7 @@ Wallet.fromEthSale = function (input, password) {
299299
// NOTE: crypto (derived from openssl) when used with aes-*-cbc will handle PKCS#7 padding internally
300300
// see also http://stackoverflow.com/a/31614770/4964819
301301
var decipher = crypto.createDecipheriv('aes-128-cbc', derivedKey, encseed.slice(0, 16))
302-
var seed = decipherBuffer(decipher, encseed.slice(16))
302+
var seed = runCipherBuffer(decipher, encseed.slice(16))
303303

304304
var wallet = new Wallet(ethUtil.keccak256(seed))
305305
if (wallet.getAddress().toString('hex') !== json.ethaddr) {

src/thirdparty.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function assert (val, msg) {
1212
}
1313
}
1414

15-
function decipherBuffer (decipher, data) {
16-
return Buffer.concat([ decipher.update(data), decipher.final() ])
15+
function runCipherBuffer (cipher, data) {
16+
return Buffer.concat([ cipher.update(data), cipher.final() ])
1717
}
1818

1919
var Thirdparty = {}
@@ -118,7 +118,7 @@ Thirdparty.fromEtherWallet = function (input, password) {
118118
var evp = evp_kdf(Buffer.from(password), cipher.salt, { keysize: 32, ivsize: 16 })
119119

120120
var decipher = crypto.createDecipheriv('aes-256-cbc', evp.key, evp.iv)
121-
privKey = decipherBuffer(decipher, Buffer.from(cipher.ciphertext))
121+
privKey = runCipherBuffer(decipher, Buffer.from(cipher.ciphertext))
122122

123123
// NOTE: yes, they've run it through UTF8
124124
privKey = Buffer.from(utf8.decode(privKey.toString()), 'hex')

0 commit comments

Comments
 (0)