-
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add QrKeyringV2 wrapper
#411
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
QrKeyringV2 wrapperQrKeyringV2 wrapper
QrKeyringV2 wrapperQrKeyringV2 wrapper
QrKeyringV2 wrapperQrKeyringV2 wrapper
| entropy: { | ||
| type: KeyringAccountEntropyTypeOption.Mnemonic, | ||
| id: this.entropySource, | ||
| groupIndex: addressIndex, |
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.
I think the addressIndex only make sense for DeviceMode.HD? Since for DeviceMode.ACCOUNT we're defaulting to the arrayIndex, this won't really match the real account/address index used during the derivation?
This might also be pretty hard to go from derivation path -> index if the "QR device" can use any arbitrary path. So I wonder if DeviceMode.ACCOUNT should be treated as private key here? 🤔
NOTE: I might have misunderstood the legacy QR keyring, so correct me if I'm wrong 😅
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.
I'm a bit confused here as well. I'll set up something internally so we can share knowledge around this area 😅
| const currentAccounts = await this.getAccounts(); | ||
| const existingAccount = currentAccounts.find( | ||
| (account) => account.options.entropy.groupIndex === 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.
Following-up my previous questions, we would have to consider only BIP-44 accounts in this case.
| this.inner.setAccountToUnlock(targetIndex); | ||
| const [newAddress] = await this.inner.addAccounts(1); |
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.
Question: (Might be a bit too much) but, I wonder if we should reset the #accountToUnlock back to what it was here? Like if for some reason the previous value had to be kept, then, our implementation side effect could have an impact on that? 🤔
Basically I'm thinking about something like:
const previousAccountToUnlock = this.inner.getAccountToUnlock();
let newAddress;
try {
this.inner.setAccountToUnlock(targetIndex);
[newAddress] = await this.inner.addAccounts(1);
} finally {
this.inner.setAccountToUnlock(previousAccountToUnlock);
}But even this, is not entirely concurrent-safe (if another addAccounts happens in parallel 🙃).
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.
We can discuss this internally, but I think the legacy implementation is a bit fragile regarding this logic anyway, like, if you use setAccountToUnlock(n) and addAccounts(2), this will try to create the same account twice (since #accountToUnlock is not cleared after creating an account 😅)
The legacy logic should probably be fixed to only accept addAccounts(1) if #accountToUnlock is set!
But our wrapper implementation is good otherwise!
Related to: https://consensyssoftware.atlassian.net/browse/MUL-1320
Examples
Note
Adds
QrKeyringV2adapter around the legacyQrKeyring, exposes BIP-44 accounts via Keyring V2, exports it, adds derivation-path lookup, and introduces comprehensive tests and wiring updates.QrKeyringV2implementingKeyringV2, extendingEthKeyringWrapper, exposing EOA BIP-44 accounts and methods (SignTransaction,PersonalSign,SignTypedDataV4).scopes: [Eoa],bip44.deriveIndex: true.bip44:derive-index(with entropy source validation), deletion, serialization.QrKeyring#getPathFromAddress(address)to retrieve derivation paths used by the adapter.QrKeyringV2andQrKeyringV2Optionsfromsrc/index.ts.CHANGELOG.mdwith the new adapter.eth-qr-keyringtokeyring_apiandaccount_api.qr-keyring-v2.test.tscovering constructor/capabilities,getAccounts,deserialize,createAccounts,deleteAccount,getAccount,serialize, and Account mode behavior.@metamask/keyring-apiand@metamask/account-apideps and TS project references; updateyarn.lock.Written by Cursor Bugbot for commit aa6f016. This will update automatically on new commits. Configure here.