feat(keyring-watch-only): add keyring-watch-only (EVM only) - #644
Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions (from the Expand for full list of packages and versions. |
a1e782a to
487a8e0
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions (from the Expand for full list of packages and versions. |
487a8e0 to
17a6744
Compare
| /** | ||
| * Get an account by its ID, synchronously. | ||
| * | ||
| * @param accountId - The account ID to look up. | ||
| * @returns The account, or `undefined` if not found. | ||
| */ | ||
| lookupAccount(accountId: AccountId): KeyringAccount | undefined { | ||
| return this.#registry.get(accountId); | ||
| } | ||
|
|
||
| /** | ||
| * Get an account by its address (case-insensitive), synchronously. | ||
| * | ||
| * Performs an O(1) exact lookup first; falls back to a linear scan to | ||
| * handle addresses passed with a different casing (e.g. lowercase vs | ||
| * EIP-55 checksummed). All addresses held by the keyring are valid EVM | ||
| * addresses, so the fallback comparison is safe. | ||
| * | ||
| * @param address - The address to look up. | ||
| * @returns The account, or `undefined` if not found. | ||
| */ | ||
| lookupByAddress(address: string): KeyringAccount | undefined { | ||
| const accountId = this.#registry.getAccountId(address); | ||
|
|
||
| if (accountId !== undefined) { | ||
| return this.#registry.get(accountId); | ||
| } | ||
|
|
||
| return this.#registry | ||
| .values() | ||
| .find( | ||
| (account) => account.address.toLowerCase() === address.toLowerCase(), | ||
| ); | ||
| } |
There was a problem hiding this comment.
Mostly added to make the integration easier on the AccountsController.
I plan on using the same pattern than for SnapKeyringV2: https://github.com/MetaMask/core/blob/42a92c3bef4bbf2025d26b45acc4cc068260e668/packages/accounts-controller/src/AccountsController.ts#L903-L950
We would use the account objects from the keyring rather than re-constructing them manually in the controller.
NOTE: That's also used by the v1 adapter too (v1 are still required by the KeyringController for now).
|
bugbot review |
Adding new watch-only keyring for EVM addresses only for now.