Skip to content
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

feat!: add SnapKeyring.createAccount + internal options #252

Merged
merged 15 commits into from
Mar 20, 2025

Conversation

ccharly
Copy link
Contributor

@ccharly ccharly commented Mar 18, 2025

Introducing a new way of handling internal options (display* flags) that were used to configure the account creation flow.

Initially those flags were being sent by the Snap (only interpreted for preinstalled Snaps) itself to allow to skip some specific steps of the flow (e.g display the account name input OR display the confirmation about the account creation action).

The main problem with the previous approach is that the caller (MetaMask here) of keyring_createAccount cannot skip those steps programmatically. It's up to the Snap to the Snap to emit the right flags with the correct values during the flow.


With the new approach, we "hide" those flags behind a context that is owned by the Snap keyring. In addition to that, we've added a new SnapKeyring.createAccount method that allows the caller (MetaMask here, again) to enable those flags if needed.

This way, we can configure the flow to behave differently:

const BITCOIN_SNAP_ID = 'npm:...';
const SOLANA_SNAP_ID = 'npm:...';

const keyring = new SnapKeyring(...);

// Basic flow
keyring.createAccount(SOLANA_SNAP_ID, { scope: '...' }, {
  // We don't want to display those intermediary screens.
  displayConfirmations: false,
});

// Creating a Solana account "on-the-fly" with a default name
keyring.createAccount(SOLANA_SNAP_ID, { scope: '...' }, {
  // We don't want to display those intermediary screens.
  displayConfirmations: false,
  // Will defaults to a generic account name.
  displayAccountNameSuggestion: false,
});

Caution

The current flow will still select the newly created account at the end of the flow, but with this new approach we could easily extend our "internal options" and skip that step too, like

// Could be used by the new bridge EVM <> Solana flow
// OR could be used by profile-sync to create account without selecting them.
keyring.createAccount(SOLANA_SNAP_ID, { scope: '...' }, {
 displayConfirmations: false,
 displayAccountNameSuggestion: false,
 // The Snap keyring won't select this account automatically.
 setSelectedAccount: false,
});

@ccharly ccharly force-pushed the feat/snap-keyring-add-account branch 2 times, most recently from 179b52b to a0e42f8 Compare March 18, 2025 11:03
@ccharly
Copy link
Contributor Author

ccharly commented Mar 18, 2025

@metamaskbot publish-preview

@ccharly ccharly force-pushed the feat/snap-keyring-add-account branch from a0e42f8 to a4296e9 Compare March 18, 2025 11:21
@ccharly
Copy link
Contributor Author

ccharly commented Mar 18, 2025

@metamaskbot publish-preview

Copy link

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/keyring-api": "17.2.1-a4296e9",
  "@metamask-previews/eth-hd-keyring": "12.1.0-a4296e9",
  "@metamask-previews/eth-ledger-bridge-keyring": "10.0.0-a4296e9",
  "@metamask-previews/eth-simple-keyring": "10.0.0-a4296e9",
  "@metamask-previews/eth-trezor-keyring": "8.0.0-a4296e9",
  "@metamask-previews/keyring-internal-api": "6.0.0-a4296e9",
  "@metamask-previews/keyring-internal-snap-client": "4.0.1-a4296e9",
  "@metamask-previews/eth-snap-keyring": "12.0.0-a4296e9",
  "@metamask-previews/keyring-snap-client": "4.0.1-a4296e9",
  "@metamask-previews/keyring-snap-sdk": "3.1.0-a4296e9",
  "@metamask-previews/keyring-utils": "3.0.0-a4296e9"
}

@ccharly ccharly force-pushed the feat/snap-keyring-add-account branch from a4296e9 to 1ddff34 Compare March 18, 2025 13:16
@ccharly
Copy link
Contributor Author

ccharly commented Mar 18, 2025

@metamaskbot publish-preview

Copy link

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/keyring-api": "17.2.1-1ddff34",
  "@metamask-previews/eth-hd-keyring": "12.1.0-1ddff34",
  "@metamask-previews/eth-ledger-bridge-keyring": "10.0.0-1ddff34",
  "@metamask-previews/eth-simple-keyring": "10.0.0-1ddff34",
  "@metamask-previews/eth-trezor-keyring": "8.0.0-1ddff34",
  "@metamask-previews/keyring-internal-api": "6.0.0-1ddff34",
  "@metamask-previews/keyring-internal-snap-client": "4.0.1-1ddff34",
  "@metamask-previews/eth-snap-keyring": "12.0.0-1ddff34",
  "@metamask-previews/keyring-snap-client": "4.0.1-1ddff34",
  "@metamask-previews/keyring-snap-sdk": "3.1.0-1ddff34",
  "@metamask-previews/keyring-utils": "3.0.0-1ddff34"
}

@ccharly ccharly marked this pull request as ready for review March 19, 2025 13:11
@ccharly ccharly requested a review from a team as a code owner March 19, 2025 13:11
@ccharly ccharly changed the title feat!: add SnapKeyring.createAccount + internal options feat!: add SnapKeyring.createAccount + internal options Mar 19, 2025
Copy link
Contributor Author

@ccharly ccharly left a comment

Choose a reason for hiding this comment

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

Review session with @danroc

@ccharly
Copy link
Contributor Author

ccharly commented Mar 20, 2025

@metamaskbot publish-preview

Copy link

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/keyring-api": "17.2.1-93b83f1",
  "@metamask-previews/eth-hd-keyring": "12.1.0-93b83f1",
  "@metamask-previews/eth-ledger-bridge-keyring": "10.0.0-93b83f1",
  "@metamask-previews/eth-simple-keyring": "10.0.0-93b83f1",
  "@metamask-previews/eth-trezor-keyring": "8.0.0-93b83f1",
  "@metamask-previews/keyring-internal-api": "6.0.0-93b83f1",
  "@metamask-previews/keyring-internal-snap-client": "4.0.1-93b83f1",
  "@metamask-previews/eth-snap-keyring": "12.0.0-93b83f1",
  "@metamask-previews/keyring-snap-client": "4.0.1-93b83f1",
  "@metamask-previews/keyring-snap-sdk": "3.1.0-93b83f1",
  "@metamask-previews/keyring-utils": "3.0.0-93b83f1"
}

ccharly and others added 3 commits March 20, 2025 17:55
Co-authored-by: Daniel Rocha <68558152+danroc@users.noreply.github.com>
Copy link
Contributor

@danroc danroc left a comment

Choose a reason for hiding this comment

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

LGTM

@ccharly ccharly enabled auto-merge March 20, 2025 17:28
@ccharly ccharly added this pull request to the merge queue Mar 20, 2025
Merged via the queue into main with commit 0a893d7 Mar 20, 2025
31 checks passed
@ccharly ccharly deleted the feat/snap-keyring-add-account branch March 20, 2025 17:37
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