UNPKG

@metamask/keyring-api

Version:
1 lines 4.26 kB
{"version":3,"file":"keyring.mjs","sourceRoot":"","sources":["../../../src/api/v2/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountId } from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\n\nimport type { CreateAccountOptions } from './create-account';\nimport type { ExportedAccount, ExportAccountOptions } from './export-account';\nimport type { KeyringCapabilities } from './keyring-capabilities';\nimport type { KeyringType } from './keyring-type';\nimport type { KeyringAccount } from '../account';\nimport type { KeyringRequest } from '../request';\n\n/**\n * The KeyringV2 interface defines methods for managing accounts and signing\n * requests. This interface unifies the existing EVM and Snap keyring interfaces\n * to provide a consistent API for all keyring type.\n *\n * This interface supports both EVM and non-EVM chains, and includes\n * account metadata needed for features like Multi-SRP and Backup and Sync.\n */\nexport type KeyringV2 = {\n /**\n * Type of the keyring.\n */\n type: `${KeyringType}`;\n\n /**\n * List of capabilities supported by the keyring.\n */\n capabilities: KeyringCapabilities;\n\n /**\n * Serialize the keyring state to a JSON object.\n *\n * @returns A promise that resolves to a JSON-serializable representation of\n * the keyring state.\n */\n serialize(): Promise<Json>;\n\n /**\n * Restores the keyring state from a serialized JSON object.\n *\n * @param state - A JSON object representing a serialized keyring state.\n * @returns A promise that resolves when the keyring state has been restored.\n */\n deserialize(state: Json): Promise<void>;\n\n /**\n * Initialize the keyring.\n *\n * This method is called after the constructor to allow the keyring to\n * perform any necessary asynchronous initialization tasks.\n *\n * @returns A promise that resolves when initialization is complete.\n */\n init?(): Promise<void>;\n\n /**\n * Destroy the keyring.\n *\n * This method is called before the keyring is removed from the Keyring\n * Controller, allowing the keyring to perform any necessary cleanup tasks.\n *\n * @returns A promise that resolves when cleanup is complete.\n */\n destroy?(): Promise<void>;\n\n /**\n * Returns all accounts managed by the keyring.\n *\n * @returns A promise that resolves to an array of all accounts managed by\n * this keyring.\n */\n getAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Returns the account with the specified ID.\n *\n * @param accountId - ID of the account to retrieve.\n * @returns A promise that resolves to the account with the given ID.\n */\n getAccount(accountId: AccountId): Promise<KeyringAccount>;\n\n /**\n * Creates one or more new accounts according to the provided options.\n *\n * Deterministic account creation MUST be idempotent, meaning that for\n * deterministic algorithms, like BIP-44, calling this method with the same\n * options should always return the same accounts, even if the accounts\n * already exist in the keyring.\n *\n * @param options - Options describing how to create the account(s).\n * @returns A promise that resolves to an array of the created account objects.\n */\n createAccounts(options: CreateAccountOptions): Promise<KeyringAccount[]>;\n\n /**\n * Deletes the account with the specified ID.\n *\n * @param accountId - ID of the account to delete.\n * @returns A promise that resolves when the account has been deleted.\n */\n deleteAccount(accountId: AccountId): Promise<void>;\n\n /**\n * Exports the private key or secret material for the specified account.\n *\n * @param accountId - ID of the account to export.\n * @param options - Optional export options.\n * @returns A promise that resolves to the exported account data.\n */\n exportAccount?(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount>;\n\n /**\n * Submits a request to the keyring.\n *\n * @param request - The `KeyringRequest` object to submit.\n * @returns A promise that resolves to the response for the request.\n */\n submitRequest(request: KeyringRequest): Promise<Json>;\n};\n"]}