Skip to content

feat: implement keyring_createAccounts#601

Open
gantunesr wants to merge 27 commits into
mainfrom
gar/feat/create-accounts
Open

feat: implement keyring_createAccounts#601
gantunesr wants to merge 27 commits into
mainfrom
gar/feat/create-accounts

Conversation

@gantunesr
Copy link
Copy Markdown
Member

@gantunesr gantunesr commented Apr 28, 2026

Explanation

Batch account creation via keyring_createAccounts.

What changed

  • Added AccountUseCases.createMany, which accepts a list of account creation requests and handles the batch as a single operation.
  • Added repository batch APIs:
    • getByDerivationPaths
    • insertMany
  • Updated BdkAccountRepository so batch account creation can:
    • read the derivationPaths namespace once,
    • read the accounts namespace once,
    • create only the missing accounts,
    • persist all new accounts with one accounts write,
    • persist all derivation path mappings with one derivationPaths write.
  • Updated KeyringHandler.createAccounts to call createMany once instead of invoking AccountUseCases.create once per account.
  • Removed the added performance console.log.
  • Added validation so batch index ranges must use non-negative safe integers.
  • Added a small mutation queue around account create/delete state mutations to avoid interleaved account state writes from overlapping requests.

References


Note

Medium Risk
Adds a new keyring RPC for batch account creation and changes account persistence/read paths to support bulk operations and cached metadata, which could affect state consistency and account loading behavior.

Overview
Implements the keyring_createAccounts RPC, adding KeyringHandler.createAccounts to validate index ranges, enforce P2WPKH-only v1 constraints, trace batch creation, and internally split large requests into 100-account chunks.

Adds AccountUseCases.createMany plus repository batch APIs (getByDerivationPaths, insertMany) to reuse existing accounts, dedupe duplicate derivation paths, limit creation concurrency, and bulk-persist new accounts with fewer state reads/writes.

Extends persisted AccountState with optional cached metadata and introduces StoredAccountAdapter so lookups can return KeyringAccount-relevant fields without loading full BDK wallets; also bumps @metamask/keyring-api/keyring-snap-sdk to the versions that include the new RPC structs.

Reviewed by Cursor Bugbot for commit 947d0ea. Bugbot is set up for automated code reviews on this repo. Configure here.

- Route KeyringRpcMethod.CreateAccounts and validate with CreateAccountsRequestStruct
- Support Bip44DeriveIndex and Bip44DeriveIndexRange on mainnet P2WPKH via AccountUseCases.create
- Bump @metamask/keyring-api to ^22.0.0 and @metamask/keyring-snap-sdk to ^8.0.0
- Add unit tests and changelog; release snap 1.11.0

Made-with: Cursor
@gantunesr gantunesr requested a review from a team as a code owner April 28, 2026 02:27
@gantunesr gantunesr marked this pull request as draft April 28, 2026 02:28
@gantunesr gantunesr changed the title feat: implement keyring_createAccounts (MUL-1782) feat: implement keyring_createAccounts Apr 28, 2026
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 28, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​metamask/​keyring-api@​21.3.0 ⏵ 22.0.010010010096 -150
Updated@​metamask/​keyring-snap-sdk@​7.1.1 ⏵ 8.0.099 +110075 +195100

View full report

Comment thread packages/snap/snap.manifest.json
@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@gantunesr gantunesr marked this pull request as ready for review April 29, 2026 17:11
@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-fa702f3"
}

@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-7238495"
}

@gantunesr gantunesr force-pushed the gar/feat/create-accounts branch from 7238495 to fa702f3 Compare April 30, 2026 16:14
@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-112cb8e"
}

@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-d66fa0d"
}

@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-811268a"
}

@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-e8b9ff2"
}

@gantunesr gantunesr force-pushed the gar/feat/create-accounts branch from 8ac45b4 to e8b9ff2 Compare May 6, 2026 23:19
@MetaMask MetaMask deleted a comment from github-actions Bot May 6, 2026
@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-063ba19"
}

@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-e706b82"
}

@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b88ce08. Configure here.

Comment thread packages/snap/src/handlers/KeyringHandler.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-b88ce08"
}

@gantunesr
Copy link
Copy Markdown
Member Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/bitcoin-wallet-snap": "1.10.1-preview-e83f11e"
}

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.

1 participant