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

Commit 6a388e4

Browse files
committed
Added Buffer conversion for entropy in Thirdparty API fromKryptoKit(), some Buffer type assertions
1 parent d305a65 commit 6a388e4

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export default class Wallet {
255255
if (icapDirect) {
256256
const max = new ethUtil.BN('088f924eeceeda7fe92e1f5b0fffffffffffffff', 16)
257257
while (true) {
258-
const privateKey = randomBytes(32)
258+
const privateKey = randomBytes(32) as Buffer
259259
if (new ethUtil.BN(ethUtil.privateToAddress(privateKey)).lte(max)) {
260260
return new Wallet(privateKey)
261261
}
@@ -274,7 +274,7 @@ export default class Wallet {
274274
}
275275

276276
while (true) {
277-
const privateKey = randomBytes(32)
277+
const privateKey = randomBytes(32) as Buffer
278278
const address = ethUtil.privateToAddress(privateKey)
279279

280280
if (pattern.test(address.toString('hex'))) {
@@ -352,7 +352,7 @@ export default class Wallet {
352352
kdfparams.R,
353353
kdfparams.P,
354354
kdfparams.DkLen,
355-
)
355+
) as Buffer
356356

357357
const ciphertext = Buffer.from(json.Crypto.CipherText, 'hex')
358358
const mac = ethUtil.keccak256(Buffer.concat([derivedKey.slice(16, 32), ciphertext]))
@@ -399,7 +399,7 @@ export default class Wallet {
399399
kdfparams.r,
400400
kdfparams.p,
401401
kdfparams.dklen,
402-
)
402+
) as Buffer
403403
} else if (json.crypto.kdf === 'pbkdf2') {
404404
kdfparams = json.crypto.kdfparams
405405

@@ -572,7 +572,7 @@ export default class Wallet {
572572
kdfParams.r,
573573
kdfParams.p,
574574
kdfParams.dklen,
575-
)
575+
) as Buffer
576576
break
577577
default:
578578
throw new Error('Unsupported kdf')

src/thirdparty.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as crypto from 'crypto'
2-
import * as ethUtil from 'ethereumjs-util'
2+
import { keccak256, sha256, toBuffer } from 'ethereumjs-util'
33

44
import Wallet from './index'
55

@@ -167,7 +167,7 @@ export function fromEtherWallet(input: string | EtherWalletOptions, password: st
167167
* Third Party API: Import a brain wallet used by Ether.Camp
168168
*/
169169
export function fromEtherCamp(passphrase: string): Wallet {
170-
return new Wallet(ethUtil.keccak256(Buffer.from(passphrase)))
170+
return new Wallet(keccak256(Buffer.from(passphrase)))
171171
}
172172

173173
/**
@@ -210,13 +210,13 @@ export function fromKryptoKit(entropy: string, password: string): Wallet {
210210

211211
let privateKey: Buffer
212212
if (type === 'd') {
213-
privateKey = ethUtil.sha256(entropy)
213+
privateKey = sha256(toBuffer(entropy))
214214
} else if (type === 'q') {
215215
if (typeof password !== 'string') {
216216
throw new Error('Password required')
217217
}
218218

219-
const encryptedSeed = ethUtil.sha256(Buffer.from(entropy.slice(0, 30)))
219+
const encryptedSeed = sha256(Buffer.from(entropy.slice(0, 30)))
220220
const checksum = entropy.slice(30, 46)
221221

222222
const salt = kryptoKitBrokenScryptSeed(encryptedSeed)
@@ -244,8 +244,7 @@ export function fromKryptoKit(entropy: string, password: string): Wallet {
244244
if (checksum.length > 0) {
245245
if (
246246
checksum !==
247-
ethUtil
248-
.sha256(ethUtil.sha256(privateKey))
247+
sha256(sha256(privateKey))
249248
.slice(0, 8)
250249
.toString('hex')
251250
) {

0 commit comments

Comments
 (0)