-
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add KeyringV2 wrapper and adapters
#398
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
base: main
Are you sure you want to change the base?
Conversation
KeyringV2 wrapper and adapters
|
|
||
| // Get the updated addresses after adding new accounts | ||
| const updatedAddresses = await this.inner.getAccounts(); | ||
| const targetAddress = updatedAddresses[targetIndex]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Creating accounts at higher groupIndex fails after account deletion
The createAccounts method conflates array indices with groupIndex values, which breaks after account deletion. When accounts are deleted, gaps appear in the groupIndex sequence but the underlying address array remains dense. The calculation accountsToAdd = targetIndex - currentCount + 1 uses the count of remaining accounts rather than the maximum existing groupIndex. Subsequently, updatedAddresses[targetIndex] accesses by array position rather than derivation index, returning undefined when targetIndex exceeds the array length. For example, after creating accounts at indices 0, 1, 2 and deleting index 1, attempting to create at groupIndex 3 will fail because the array has only 3 elements after addAccounts but the code tries to access index 3.
Additional Locations (1)
packages/keyring-eth-hd/src/index.ts
Outdated
| HDKeyringOptions, | ||
| HDKeyringAccountSelectionOptions, | ||
| } from './hd-keyring'; | ||
| export { HdKeyringV2 } from './hd-keyring-v2'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: HdKeyringV2Options type not exported from package
The HdKeyringV2Options type is defined and exported in hd-keyring-v2.ts, but is not re-exported from the package's index.ts. Other keyring packages (Ledger, QR, Trezor) consistently export both the V2 class and the options type (e.g., export { LedgerKeyringV2, type LedgerKeyringV2Options }), but keyring-eth-hd only exports HdKeyringV2. This inconsistency prevents consumers from importing the type needed to construct the wrapper.
Related to: https://consensyssoftware.atlassian.net/browse/MUL-1217
Examples
Note
Introduce a unified KeyringV2 with a base wrapper and add V2 adapters for HD, Ledger, QR, and Simple keyrings, plus tests, exports, and build/config updates.
KeyringV2interface andKeyringWrapperbase with in‑memoryKeyringAddressResolver(packages/keyring-api/src/api/v2/wrapper/*).src/api/v2/index.ts), update README and changelog; adduuiddeps.HdKeyringV2: wrap legacy HD keyring; supports BIP‑44 derive-index, account export, and EVM sign/decrypt utilities.LedgerKeyringV2: wrap Ledger keyring; supports tx/message/EIP‑712(v4) signing.QrKeyringV2: wrap QR keyring; supports tx/personal/EIP‑712(v4) signing.SimpleKeyringV2: wrap simple keyring; supports random/create, hex private‑key import/export, EIP‑712(v1/v3/v4) signing.@metamask/keyring-apideps and TS project references across keyring packages.keyring_api.Written by Cursor Bugbot for commit 956d921. This will update automatically on new commits. Configure here.