Skip to content

Commit ad6515d

Browse files
committed
fix: address PR feedbacks
1 parent bf8a46f commit ad6515d

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

packages/keyring-eth-trezor/src/trezor-keyring-v2.test.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import HDKey from 'hdkey';
1111

1212
import type { TrezorBridge } from './trezor-bridge';
1313
import { TrezorKeyring } from './trezor-keyring';
14-
import { TrezorKeyringV2 } from './trezor-keyring-v2';
14+
import {
15+
BIP44_HD_PATH_PREFIX,
16+
LEGACY_MEW_PATH,
17+
TrezorKeyringV2,
18+
} from './trezor-keyring-v2';
1519

1620
/**
1721
* Type alias for Trezor keyring accounts (always BIP-44 derived).
@@ -354,7 +358,9 @@ describe('TrezorKeyringV2', () => {
354358
// getAccounts should work and populate the registry
355359
const accounts = await wrapper.getAccounts();
356360
expect(accounts).toHaveLength(3);
357-
expect(accounts[0]?.address).toBe(EXPECTED_ACCOUNTS[0]);
361+
accounts.forEach((account, index) => {
362+
expect(account.address).toBe(EXPECTED_ACCOUNTS[index]);
363+
});
358364
});
359365
});
360366

@@ -462,33 +468,37 @@ describe('TrezorKeyringV2', () => {
462468
const { wrapper, inner } = createEmptyWrapper();
463469

464470
const newAccounts = await wrapper.createAccounts(
465-
derivePathOptions(`m/44'/60'/0'/0/5`),
471+
derivePathOptions(`${BIP44_HD_PATH_PREFIX}/5`),
466472
);
467473
const account = getFirstAccount(newAccounts);
468474

469475
expect(account.address).toBe(EXPECTED_ACCOUNTS[5]);
470476
expect(account.options.entropy.groupIndex).toBe(5);
471-
expect(account.options.entropy.derivationPath).toBe(`m/44'/60'/0'/0/5`);
472-
expect(inner.hdPath).toBe(`m/44'/60'/0'/0`);
477+
expect(account.options.entropy.derivationPath).toBe(
478+
`${BIP44_HD_PATH_PREFIX}/5`,
479+
);
480+
expect(inner.hdPath).toBe(BIP44_HD_PATH_PREFIX);
473481
});
474482

475483
it('creates an account with legacy MEW path', async () => {
476484
// Create wrapper with legacy MEW path pre-set to avoid HDKey reset
477-
const inner = createInnerKeyring(`m/44'/60'/0'`);
485+
const inner = createInnerKeyring(LEGACY_MEW_PATH);
478486
const wrapper = new TrezorKeyringV2({
479487
legacyKeyring: inner,
480488
entropySource,
481489
});
482490

483491
const newAccounts = await wrapper.createAccounts(
484-
derivePathOptions(`m/44'/60'/0'/3`),
492+
derivePathOptions(`${LEGACY_MEW_PATH}/3`),
485493
);
486494
const account = getFirstAccount(newAccounts);
487495

488496
expect(account.address).toBe(EXPECTED_ACCOUNTS[3]);
489497
expect(account.options.entropy.groupIndex).toBe(3);
490-
expect(account.options.entropy.derivationPath).toBe(`m/44'/60'/0'/3`);
491-
expect(inner.hdPath).toBe(`m/44'/60'/0'`);
498+
expect(account.options.entropy.derivationPath).toBe(
499+
`${LEGACY_MEW_PATH}/3`,
500+
);
501+
expect(inner.hdPath).toBe(LEGACY_MEW_PATH);
492502
});
493503

494504
it('returns existing account if path already exists', async () => {
@@ -654,7 +664,7 @@ describe('TrezorKeyringV2', () => {
654664
describe('different HD paths', () => {
655665
it('uses the correct derivation path from the inner keyring', async () => {
656666
const inner = createInnerKeyring();
657-
inner.setHdPath(`m/44'/60'/0'`); // Legacy MEW path
667+
inner.setHdPath(LEGACY_MEW_PATH);
658668
inner.hdk = fakeHdKey; // Reset after setHdPath clears it
659669
inner.setAccountToUnlock(0);
660670
await inner.addAccounts(1);
@@ -667,7 +677,9 @@ describe('TrezorKeyringV2', () => {
667677
const accounts = await wrapper.getAccounts();
668678
const account = getFirstAccount(accounts);
669679

670-
expect(account.options.entropy.derivationPath).toBe(`m/44'/60'/0'/0`);
680+
expect(account.options.entropy.derivationPath).toBe(
681+
`${LEGACY_MEW_PATH}/0`,
682+
);
671683
});
672684

673685
it('clears registry when switching HD paths via createAccounts', async () => {

packages/keyring-eth-trezor/src/trezor-keyring-v2.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ const trezorKeyringV2Capabilities: KeyringCapabilities = {
4141
* BIP-44 standard HD path prefix constant for Ethereum.
4242
* Used as default for derive-index operations.
4343
*/
44-
const BIP44_HD_PATH_PREFIX = `m/44'/60'/0'/0`;
44+
export const BIP44_HD_PATH_PREFIX = `m/44'/60'/0'/0`;
4545

4646
/**
4747
* SLIP-0044 testnet HD path prefix constant.
4848
*/
49-
const SLIP0044_TESTNET_PATH = `m/44'/1'/0'/0`;
49+
export const SLIP0044_TESTNET_PATH = `m/44'/1'/0'/0`;
5050

5151
/**
5252
* Legacy MEW (MyEtherWallet) HD path prefix constant.
5353
*/
54-
const LEGACY_MEW_PATH = `m/44'/60'/0'`;
54+
export const LEGACY_MEW_PATH = `m/44'/60'/0'`;
5555

5656
/**
5757
* Allowed HD paths for Trezor keyring.

0 commit comments

Comments
 (0)