Skip to main content

KeyringController Actions

36 actions registered.

NameDeprecated
addNewAccount
addNewKeyring
changePassword
createNewVaultAndKeychain
createNewVaultAndRestore
decryptMessage
exportAccount
exportEncryptionKey
exportSeedPhrase
getAccountKeyringType
getAccounts
getEncryptionPublicKey
getKeyringForAccountYes
getKeyringsByTypeYes
getState
importAccountWithStrategy
isUnlocked
patchUserOperation
persistAllKeyringsYes
prepareUserOperation
removeAccount
setLocked
signEip7702Authorization
signMessage
signPersonalMessage
signTransaction
signTypedMessage
signUserOperation
submitEncryptionKey
submitPassword
verifyPassword
withController
withKeyringYes
withKeyringUnsafe
withKeyringV2
withKeyringV2Unsafe

KeyringController:addNewAccount​

Package: @metamask/keyring-controller

Adds a new account to the default (first) HD seed phrase keyring.

Parameters:

NameDescription
accountCountNumber of accounts before adding a new one, used to make the method idempotent.

Returns: Promise resolving to the added account address.

Handler signature:

(accountCount?: number) => Promise<string>

KeyringController:addNewKeyring​

Package: @metamask/keyring-controller

Adds a new keyring of the given type.

Parameters:

NameDescription
typeKeyring type name.
optsKeyring options.

Returns: Promise resolving to the new keyring metadata.

Handler signature:

(type: KeyringTypes | string, opts?: unknown) => Promise<KeyringMetadata>

KeyringController:changePassword​

Package: @metamask/keyring-controller

Changes the password used to encrypt the vault.

Parameters:

NameDescription
passwordThe new password.

Returns: Promise resolving when the operation completes.

Handler signature:

(password: string) => Promise<void>

KeyringController:createNewVaultAndKeychain​

Package: @metamask/keyring-controller

Create a new vault and primary keyring.

This only works if keyrings are empty. If there is a pre-existing unlocked vault, calling this will have no effect. If there is a pre-existing locked vault, it will be replaced.

Parameters:

NameDescription
passwordPassword to unlock the new vault.

Returns: Promise resolving when the operation ends successfully.

Handler signature:

(password: string) => Promise<void>

KeyringController:createNewVaultAndRestore​

Package: @metamask/keyring-controller

Effectively the same as creating a new keychain then populating it using the given seed phrase.

Parameters:

NameDescription
passwordPassword to unlock keychain.
seedA BIP39-compliant seed phrase as Uint8Array, either as a string or an array of UTF-8 bytes that represent the string.

Returns: Promise resolving when the operation ends successfully.

Handler signature:

(password: string, seed: Uint8Array) => Promise<void>

KeyringController:decryptMessage​

Package: @metamask/keyring-controller

Attempts to decrypt the provided message parameters.

Parameters:

NameDescription
messageParamsThe decryption message parameters.
messageParams.fromThe address of the account you want to use to decrypt the message.
messageParams.dataThe encrypted data that you want to decrypt.

Returns: The raw decryption result.

Handler signature:

(messageParams: {
from: string;
data: Eip1024EncryptedData;
}) => Promise<string>

KeyringController:exportAccount​

Package: @metamask/keyring-controller

Gets the private key from the keyring controlling an address.

Parameters:

NameDescription
credentialsObject holding either the password or the vault encryptionKey.
addressAddress to export.

Returns: Promise resolving to the private key for an address.

Handler signature:

(credentials: Credentials, address: string) => Promise<string>

KeyringController:exportEncryptionKey​

Package: @metamask/keyring-controller

Exports the vault encryption key.

Returns: The vault encryption key.

Handler signature:

() => Promise<string>

KeyringController:exportSeedPhrase​

Package: @metamask/keyring-controller

Gets the seed phrase of the HD keyring.

Parameters:

NameDescription
credentialsObject holding either the password or the vault encryptionKey.
keyringIdThe id of the keyring.

Returns: Promise resolving to the seed phrase.

Handler signature:

(credentials: Credentials, keyringId?: string) => Promise<Uint8Array>

KeyringController:getAccountKeyringType​

Package: @metamask/keyring-controller

Gets the type of the keyring that manages the specified account.

Parameters:

NameDescription
accountThe account address to look up.

Returns: A promise that resolves to the type of the keyring managing the account.

Handler signature:

(account: string) => Promise<string>

KeyringController:getAccounts​

Package: @metamask/keyring-controller

Returns the public addresses of all accounts from every keyring.

Returns: A promise resolving to an array of addresses.

Handler signature:

() => Promise<string[]>

KeyringController:getEncryptionPublicKey​

Package: @metamask/keyring-controller

Get encryption public key.

Parameters:

NameDescription
accountAn account address.
optsAdditional encryption options.

Returns: Promise resolving to encyption public key of the account if one exists.

Handler signature:

(account: string, opts?: Record<string, unknown>) => Promise<string>

KeyringController:getKeyringForAccount​

Deprecated

Package: @metamask/keyring-controller

Returns the currently initialized keyring that manages the specified address if one exists. Deprecated: Use of this method is discouraged as actions executed directly on keyrings are not being reflected in the KeyringController state and not persisted in the vault. Use withKeyring instead.

Parameters:

NameDescription
accountAn account address.

Returns: Promise resolving to keyring of the account if one exists.

Handler signature:

(account: string) => Promise<unknown>

KeyringController:getKeyringsByType​

Deprecated

Package: @metamask/keyring-controller

Returns all keyrings of the given type. Deprecated: Use of this method is discouraged as actions executed directly on keyrings are not being reflected in the KeyringController state and not persisted in the vault. Use withKeyring instead.

Parameters:

NameDescription
typeKeyring type name.

Returns: An array of keyrings of the given type.

Handler signature:

(type: KeyringTypes | string) => unknown[]

KeyringController:getState​

Package: @metamask/keyring-controller

Handler signature:

() => KeyringControllerState

KeyringController:importAccountWithStrategy​

Package: @metamask/keyring-controller

Imports an account with the specified import strategy.

Parameters:

NameDescription
strategyImport strategy name.
argsArray of arguments to pass to the underlying stategy.

Returns: Promise resolving to the imported account address.

Handler signature:

(strategy: AccountImportStrategy, args: any[]) => Promise<string>

KeyringController:isUnlocked​

Package: @metamask/keyring-controller

Returns the status of the vault.

Returns: Boolean returning true if the vault is unlocked.

Handler signature:

() => boolean

KeyringController:patchUserOperation​

Package: @metamask/keyring-controller

Patches properties of a UserOperation. Currently, only the paymasterAndData can be patched.

Parameters:

NameDescription
fromAddress of the sender.
userOpUserOperation to patch.
executionContextThe execution context to use for the UserOperation.

Returns: A patch to apply to the UserOperation.

Handler signature:

(from: string, userOp: EthUserOperation, executionContext: KeyringExecutionContext) => Promise<EthUserOperationPatch>

KeyringController:persistAllKeyrings​

Deprecated

Package: @metamask/keyring-controller

Persist all serialized keyrings in the vault. Deprecated: This method is being phased out in favor of withKeyring.

Returns: Promise resolving with true value when the operation completes.

Handler signature:

() => Promise<boolean>

KeyringController:prepareUserOperation​

Package: @metamask/keyring-controller

Convert a base transaction to a base UserOperation.

Parameters:

NameDescription
fromAddress of the sender.
transactionsBase transactions to include in the UserOperation.
executionContextThe execution context to use for the UserOperation.

Returns: A pseudo-UserOperation that can be used to construct a real.

Handler signature:

(from: string, transactions: EthBaseTransaction[], executionContext: KeyringExecutionContext) => Promise<EthBaseUserOperation>

KeyringController:removeAccount​

Package: @metamask/keyring-controller

Removes an account from keyring state.

Parameters:

NameDescription
addressAddress of the account to remove.

Returns: Promise resolving when the account is removed.

Handler signature:

(address: string) => Promise<void>

KeyringController:setLocked​

Package: @metamask/keyring-controller

Deallocates all secrets and locks the wallet.

Returns: Promise resolving when the operation completes.

Handler signature:

() => Promise<void>

KeyringController:signEip7702Authorization​

Package: @metamask/keyring-controller

Signs EIP-7702 Authorization message by calling down into a specific keyring.

Parameters:

NameDescription
paramsEIP7702AuthorizationParams object to sign.

Returns: Promise resolving to an EIP-7702 Authorization signature.

Handler signature:

(params: Eip7702AuthorizationParams) => Promise<string>

KeyringController:signMessage​

Package: @metamask/keyring-controller

Signs message by calling down into a specific keyring.

Parameters:

NameDescription
messageParamsPersonalMessageParams object to sign.

Returns: Promise resolving to a signed message string.

Handler signature:

(messageParams: PersonalMessageParams) => Promise<string>

KeyringController:signPersonalMessage​

Package: @metamask/keyring-controller

Signs personal message by calling down into a specific keyring.

Parameters:

NameDescription
messageParamsPersonalMessageParams object to sign.

Returns: Promise resolving to a signed message string.

Handler signature:

(messageParams: PersonalMessageParams) => Promise<string>

KeyringController:signTransaction​

Package: @metamask/keyring-controller

Signs a transaction by calling down into a specific keyring.

Parameters:

NameDescription
transactionTransaction object to sign. Must be a ethereumjs-tx transaction instance.
fromAddress to sign from, should be in keychain.
optsAn optional options object.

Returns: Promise resolving to a signed transaction string.

Handler signature:

(transaction: TypedTransaction, from: string, opts?: Record<string, unknown>) => Promise<TypedTxData>

KeyringController:signTypedMessage​

Package: @metamask/keyring-controller

Signs typed message by calling down into a specific keyring.

Parameters:

NameDescription
messageParamsTypedMessageParams object to sign.
versionCompatibility version EIP712.

Returns: Promise resolving to a signed message string or an error if any.

Handler signature:

(messageParams: TypedMessageParams, version: SignTypedDataVersion) => Promise<string>

KeyringController:signUserOperation​

Package: @metamask/keyring-controller

Signs an UserOperation.

Parameters:

NameDescription
fromAddress of the sender.
userOpUserOperation to sign.
executionContextThe execution context to use for the UserOperation.

Returns: The signature of the UserOperation.

Handler signature:

(from: string, userOp: EthUserOperation, executionContext: KeyringExecutionContext) => Promise<string>

KeyringController:submitEncryptionKey​

Package: @metamask/keyring-controller

Attempts to decrypt the current vault and load its keyrings, using the given encryption key and salt. The optional salt can be used to check for consistency with the vault salt.

Parameters:

NameDescription
encryptionKeyKey to unlock the keychain.
encryptionSaltOptional salt to unlock the keychain.

Returns: Promise resolving when the operation completes.

Handler signature:

(encryptionKey: string, encryptionSalt?: string) => Promise<void>

KeyringController:submitPassword​

Package: @metamask/keyring-controller

Attempts to decrypt the current vault and load its keyrings, using the given password.

Parameters:

NameDescription
passwordPassword to unlock the keychain.

Returns: Promise resolving when the operation completes.

Handler signature:

(password: string) => Promise<void>

KeyringController:verifyPassword​

Package: @metamask/keyring-controller

Method to verify a given password validity. Throws an error if the password is invalid.

Parameters:

NameDescription
passwordPassword of the keyring.

Handler signature:

(password: string) => Promise<void>

KeyringController:withController​

Package: @metamask/keyring-controller

Execute an operation against all keyrings as a mutually exclusive atomic operation. The operation receives a RestrictedController instance that exposes a read-only live view of all keyrings as well as addNewKeyring and removeKeyring methods to stage mutations.

The method automatically persists changes at the end of the function execution, or rolls back the changes if an error is thrown.

Parameters:

NameDescription
operationFunction to execute with the restricted controller.

Returns: Promise resolving to the result of the function execution.

Handler signature:

(operation: (restrictedController: RestrictedController) => Promise<CallbackResult>) => Promise<CallbackResult>

KeyringController:withKeyring​

Deprecated

Package: @metamask/keyring-controller

Select a keyring and execute the given operation with the selected keyring, as a mutually exclusive atomic operation.

The method automatically persists changes at the end of the function execution, or rolls back the changes if an error is thrown. Deprecated: This method overload is deprecated. Use withKeyring without options instead.

Parameters:

NameDescription
selectorKeyring selector object.
operationFunction to execute with the selected keyring.
optionsAdditional options.
options.createIfMissingWhether to create a new keyring if the selected one is missing.
options.createWithDataOptional data to use when creating a new keyring.

Returns: Promise resolving to the result of the function execution.

Handler signature:

(selector: KeyringSelector<SelectedKeyring>, operation: ({ keyring, metadata }: KeyringEntry) => Promise<CallbackResult>, options: {
createIfMissing?: false;
} | {
createIfMissing: true;
createWithData?: unknown;
}) => Promise<CallbackResult>

KeyringController:withKeyringUnsafe​

Package: @metamask/keyring-controller

Select a keyring and execute the given operation with the selected keyring, without acquiring the controller's mutual exclusion lock.

When to use this method​

This method is an escape hatch for read-only access to keyring data that is immutable once the keyring is initialized. A typical safe use case is reading the mnemonic from an HdKeyring: the mnemonic is set during deserialize() and never mutated afterwards, so it can safely be read without holding the lock.

Why it is "unsafe"​

The "unsafe" designation mirrors the semantics of unsafe { } blocks in Rust: the method itself does not enforce thread-safety guarantees. By calling this method the caller explicitly takes responsibility for ensuring that:

  • The operation is read-only — no state is mutated.
  • The data being read is immutable after the keyring is initialized, so concurrent locked operations cannot alter it while this callback runs.

Do not use this method to:

  • Mutate keyring state (add accounts, sign, etc.) — use withKeyring.
  • Read mutable fields that could change during concurrent operations.

Parameters:

NameDescription
selectorKeyring selector object.
operationRead-only function to execute with the selected keyring.

Returns: Promise resolving to the result of the function execution.

Handler signature:

(selector: KeyringSelector<SelectedKeyring>, operation: ({ keyring, metadata, }: {
keyring: SelectedKeyring;
metadata: KeyringMetadata;
}) => Promise<CallbackResult>) => Promise<CallbackResult>

KeyringController:withKeyringV2​

Package: @metamask/keyring-controller

Select a keyring using its KeyringV2 adapter, and execute the given operation with the wrapped keyring as a mutually exclusive atomic operation.

The cached KeyringV2 adapter is retrieved from the keyring entry.

A KeyringV2Builder for the selected keyring's type must exist (either as a default or registered via the keyringV2Builders constructor option); otherwise an error is thrown.

The method automatically persists changes at the end of the function execution, or rolls back the changes if an error is thrown.

Parameters:

NameDescription
selectorKeyring selector object.
operationFunction to execute with the wrapped V2 keyring.

Returns: Promise resolving to the result of the function execution.

Handler signature:

(selector: KeyringSelectorV2<SelectedKeyring>, operation: ({ keyring, metadata, }: {
keyring: SelectedKeyring;
metadata: KeyringMetadata;
}) => Promise<CallbackResult>) => Promise<CallbackResult>

KeyringController:withKeyringV2Unsafe​

Package: @metamask/keyring-controller

Select a keyring, wrap it in a KeyringV2 adapter, and execute the given read-only operation without acquiring the controller's mutual exclusion lock.

When to use this method​

This method is an escape hatch for read-only access to keyring data that is immutable once the keyring is initialized. A typical safe use case is reading immutable fields from a KeyringV2 adapter: data that is set during initialization and never mutated afterwards.

Why it is "unsafe"​

The "unsafe" designation mirrors the semantics of unsafe { } blocks in Rust: the method itself does not enforce thread-safety guarantees. By calling this method the caller explicitly takes responsibility for ensuring that:

  • The operation is read-only — no state is mutated.
  • The data being read is immutable after the keyring is initialized, so concurrent locked operations cannot alter it while this callback runs.

Do not use this method to:

  • Mutate keyring state (add accounts, sign, etc.) — use withKeyringV2.
  • Read mutable fields that could change during concurrent operations.

Parameters:

NameDescription
selectorKeyring selector object.
operationRead-only function to execute with the wrapped V2 keyring.

Returns: Promise resolving to the result of the function execution.

Handler signature:

(selector: KeyringSelectorV2<SelectedKeyring>, operation: ({ keyring, metadata, }: {
keyring: SelectedKeyring;
metadata: KeyringMetadata;
}) => Promise<CallbackResult>) => Promise<CallbackResult>