Skip to content

Commit

Permalink
Use named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycodes committed May 14, 2021
1 parent 4376569 commit b6643c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/keyring/KeyringController.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as ethUtil from 'ethereumjs-util';
import { bufferToHex } from 'ethereumjs-util';
import {
recoverPersonalSignature,
recoverTypedSignature,
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('KeyringController', () => {
});

it('should sign personal message', async () => {
const data = ethUtil.bufferToHex(Buffer.from('Hello from test', 'utf8'));
const data = bufferToHex(Buffer.from('Hello from test', 'utf8'));
const account = initialState.keyrings[0].accounts[0];
const signature = await keyringController.signPersonalMessage({
data,
Expand Down
22 changes: 12 additions & 10 deletions src/keyring/KeyringController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import * as ethUtil from 'ethereumjs-util';
import {
addHexPrefix,
bufferToHex,
isValidPrivate,
toChecksumAddress,
toBuffer,
} from 'ethereumjs-util';
import { stripHexPrefix } from 'ethjs-util';
import {
normalize as normalizeAddress,
Expand Down Expand Up @@ -332,8 +338,8 @@ export class KeyringController extends BaseController<
if (!importedKey) {
throw new Error('Cannot import an empty key.');
}
const prefixed = ethUtil.addHexPrefix(importedKey);
if (!ethUtil.isValidPrivate(ethUtil.toBuffer(prefixed))) {
const prefixed = addHexPrefix(importedKey);
if (!isValidPrivate(toBuffer(prefixed))) {
throw new Error('Cannot import invalid private key.');
}
privateKey = stripHexPrefix(prefixed);
Expand All @@ -346,7 +352,7 @@ export class KeyringController extends BaseController<
} catch (e) {
wallet = wallet || (await Wallet.fromV3(input, password, true));
}
privateKey = ethUtil.bufferToHex(wallet.getPrivateKey());
privateKey = bufferToHex(wallet.getPrivateKey());
break;
default:
throw new Error(`Unexpected import strategy: '${strategy}'`);
Expand Down Expand Up @@ -418,9 +424,7 @@ export class KeyringController extends BaseController<
const address = normalizeAddress(messageParams.from);
const { password } = privates.get(this).keyring;
const privateKey = await this.exportAccount(password, address);
const privateKeyBuffer = ethUtil.toBuffer(
ethUtil.addHexPrefix(privateKey),
);
const privateKeyBuffer = toBuffer(addHexPrefix(privateKey));
switch (version) {
case SignTypedDataVersion.V1:
// signTypedDataLegacy will throw if the data is invalid.
Expand Down Expand Up @@ -561,9 +565,7 @@ export class KeyringController extends BaseController<
async (keyring: KeyringObject, index: number): Promise<Keyring> => {
const keyringAccounts = await keyring.getAccounts();
const accounts = Array.isArray(keyringAccounts)
? keyringAccounts.map((address) =>
ethUtil.toChecksumAddress(address),
)
? keyringAccounts.map((address) => toChecksumAddress(address))
: /* istanbul ignore next */ [];
return {
accounts,
Expand Down

0 comments on commit b6643c0

Please sign in to comment.