Skip to content

feat(keyring-watch-only): add keyring-watch-only (EVM only) - #644

Merged
ccharly merged 13 commits into
mainfrom
cc/feat/watch-only-keyring
Oct 1, 2026
Merged

ccharly merged 13 commits into
mainfrom
cc/feat/watch-only-keyring

Conversation

@ccharly

@ccharly ccharly commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Adding new watch-only keyring for EVM addresses only for now.

@ccharly
ccharly added this pull request to stack #645 September 30, 2026 12:16
@ccharly ccharly changed the title feat(keying-watch-only): add keyring-watch-only (EVM only) feat(keyring-watch-only): add keyring-watch-only (EVM only) Sep 30, 2026
@ccharly
ccharly marked this pull request as ready for review September 30, 2026 12:27
@ccharly
ccharly requested a review from a team as a code owner September 30, 2026 12:27
@ccharly

ccharly commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "2.0.0-a1e782a",
  "@metamask-previews/hw-wallet-sdk": "1.0.0-a1e782a",
  "@metamask-previews/keyring-api": "24.1.0-a1e782a",
  "@metamask-previews/eth-hd-keyring": "15.0.0-a1e782a",
  "@metamask-previews/eth-ledger-bridge-keyring": "13.1.0-a1e782a",
  "@metamask-previews/eth-money-keyring": "4.0.0-a1e782a",
  "@metamask-previews/eth-qr-keyring": "3.0.0-a1e782a",
  "@metamask-previews/eth-simple-keyring": "13.0.0-a1e782a",
  "@metamask-previews/eth-trezor-keyring": "11.0.0-a1e782a",
  "@metamask-previews/keyring-internal-api": "12.1.0-a1e782a",
  "@metamask-previews/keyring-internal-snap-client": "11.1.0-a1e782a",
  "@metamask-previews/keyring-sdk": "3.1.0-a1e782a",
  "@metamask-previews/eth-snap-keyring": "24.1.0-a1e782a",
  "@metamask-previews/keyring-snap-client": "10.0.0-a1e782a",
  "@metamask-previews/keyring-snap-sdk": "10.0.0-a1e782a",
  "@metamask-previews/keyring-utils": "5.0.0-a1e782a",
  "@metamask-previews/watch-only-keyring": "0.1.0-a1e782a"
}

@ccharly
ccharly force-pushed the cc/feat/watch-only-keyring branch from a1e782a to 487a8e0 Compare September 30, 2026 19:40
@ccharly

ccharly commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "2.0.0-487a8e0",
  "@metamask-previews/hw-wallet-sdk": "1.0.0-487a8e0",
  "@metamask-previews/keyring-api": "24.1.0-487a8e0",
  "@metamask-previews/eth-hd-keyring": "15.0.0-487a8e0",
  "@metamask-previews/eth-ledger-bridge-keyring": "13.1.0-487a8e0",
  "@metamask-previews/eth-money-keyring": "4.0.0-487a8e0",
  "@metamask-previews/eth-qr-keyring": "3.0.0-487a8e0",
  "@metamask-previews/eth-simple-keyring": "13.0.0-487a8e0",
  "@metamask-previews/eth-trezor-keyring": "11.0.0-487a8e0",
  "@metamask-previews/keyring-internal-api": "12.1.0-487a8e0",
  "@metamask-previews/keyring-internal-snap-client": "11.1.0-487a8e0",
  "@metamask-previews/keyring-sdk": "3.1.0-487a8e0",
  "@metamask-previews/eth-snap-keyring": "24.1.0-487a8e0",
  "@metamask-previews/keyring-snap-client": "10.0.0-487a8e0",
  "@metamask-previews/keyring-snap-sdk": "10.0.0-487a8e0",
  "@metamask-previews/keyring-utils": "5.0.0-487a8e0",
  "@metamask-previews/watch-only-keyring": "0.1.0-487a8e0"
}

Base automatically changed from cc/feat/address-import-ctor to main October 1, 2026 07:41
@ccharly
ccharly force-pushed the cc/feat/watch-only-keyring branch from 487a8e0 to 17a6744 Compare October 1, 2026 07:41
Comment on lines +363 to +396
/**
* 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(),
);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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).

Comment thread packages/keyring-watch-only/src/watch-only-keyring.ts Outdated
Comment thread packages/keyring-watch-only/src/watch-only-keyring.ts Outdated
Comment thread packages/keyring-watch-only/src/watch-only-keyring.ts Outdated
@ccharly

ccharly commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

bugbot review

@ccharly
ccharly added this pull request to the merge queue Oct 1, 2026
Merged via the queue into main with commit adc10bf Oct 1, 2026
21 checks passed
@ccharly
ccharly deleted the cc/feat/watch-only-keyring branch October 1, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants