Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(29917): Trezor accounts not able to add multiple HD path accounts into the account list #187

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/keyring-eth-trezor/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module.exports = merge(baseConfig, {
coverageThreshold: {
global: {
branches: 48.27,
functions: 91.22,
lines: 89.94,
statements: 90.15,
functions: 92.98,
lines: 90.21,
statements: 90.42,
},
},
});
15 changes: 9 additions & 6 deletions packages/keyring-eth-trezor/src/trezor-keyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ describe('TrezorKeyring', function () {
});
});

describe('getModel', function () {
it('gets bridge model', async function () {
keyring.bridge.model = 'foo';
const model = keyring.getModel();

expect(model).toBe('foo');
});
});

describe('init', function () {
it('initialises the bridge', async function () {
const initStub = sinon.stub().resolves();
Expand Down Expand Up @@ -722,16 +731,10 @@ describe('TrezorKeyring', function () {

it('should update the hdPath and reset account and page properties if passed a new hdPath', async function () {
const SLIP0044TestnetPath = `m/44'/1'/0'/0`;

keyring.setHdPath(SLIP0044TestnetPath);

expect(keyring.hdPath).toBe(SLIP0044TestnetPath);
expect(keyring.accounts).toStrictEqual([]);
expect(keyring.page).toBe(0);
expect(keyring.perPage).toBe(5);
expect(keyring.hdk.publicKey).toBeNull();
expect(keyring.unlockedAccount).toBe(0);
expect(keyring.paths).toStrictEqual({});
Comment on lines -729 to -734
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we test that these ones are unchanged instead?

});

it('should throw an error if passed an unsupported hdPath', async function () {
Expand Down
5 changes: 0 additions & 5 deletions packages/keyring-eth-trezor/src/trezor-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,6 @@ export class TrezorKeyring extends EventEmitter {
// Reset HDKey if the path changes
if (this.hdPath !== hdPath) {
this.hdk = new HDKey();
this.accounts = [];
this.page = 0;
this.perPage = 5;
this.unlockedAccount = 0;
this.paths = {};
Comment on lines -542 to -546
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the keyring still be able to sign transactions with the accounts previously derived with a different path? Since this.hdk is specific to a path, after changing path we won't have the original public key used to derive the first accounts

Copy link
Contributor Author

@Akaryatrh Akaryatrh Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, previously derived accounts are not able to sign or send tx. I guess i need to check what we're doing with Ledger keyring as it's working there.
Thanks for catching this 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's warranted to add a test case for this scenario as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the LedgerKeyring stores a map of AccountDetails for each derived address, so even if the path is switched it can be retrieved again when signing:

const { hdPath } = accountDetails;

}
this.hdPath = hdPath;
}
Expand Down
Loading