Keyring: {
    approveRequest?(id, data?): Promise<void>;
    createAccount(options?): Promise<{
        address: string;
        id: string;
        methods: string[];
        options: Record<string, Json>;
        type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
    }>;
    deleteAccount(id): Promise<void>;
    exportAccount?(id): Promise<Record<string, Json>>;
    filterAccountChains(id, chains): Promise<string[]>;
    getAccount(id): Promise<undefined | {
        address: string;
        id: string;
        methods: string[];
        options: Record<string, Json>;
        type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
    }>;
    getAccountBalances?(id, assets): Promise<Record<string, {
        amount: string;
        unit: string;
    }>>;
    getRequest?(id): Promise<undefined | {
        account: string;
        id: string;
        request: {
            method: string;
            params?: Json[] | Record<string, Json>;
        };
        scope: string;
    }>;
    listAccounts(): Promise<{
        address: string;
        id: string;
        methods: string[];
        options: Record<string, Json>;
        type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
    }[]>;
    listRequests?(): Promise<{
        account: string;
        id: string;
        request: {
            method: string;
            params?: Json[] | Record<string, Json>;
        };
        scope: string;
    }[]>;
    rejectRequest?(id): Promise<void>;
    submitRequest(request): Promise<{
        pending: true;
        redirect?: {
            message?: string;
            url?: string;
        };
    } | {
        pending: false;
        result: Json;
    }>;
    updateAccount(account): Promise<void>;
}

Keyring interface.

Represents the functionality and operations related to managing accounts and handling requests.

Type declaration

  • approveRequest?:function
    • Approve a request.

      Approves the request with the given ID and sets the response if provided.

      Parameters

      • id: string

        The ID of the request to approve.

      • Optional data: Record<string, Json>

        The response to the request (optional).

      Returns Promise<void>

      A promise that resolves when the request is successfully approved.

  • createAccount:function
    • Create an account.

      Creates a new account with optional, keyring-defined, account options.

      Parameters

      • Optional options: Record<string, Json>

        Keyring-defined options for the account (optional).

      Returns Promise<{
          address: string;
          id: string;
          methods: string[];
          options: Record<string, Json>;
          type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
      }>

      A promise that resolves to the newly created KeyringAccount object without any private information.

  • deleteAccount:function
    • Delete an account from the keyring.

      Deletes the account with the given ID from the keyring.

      Parameters

      • id: string

        The ID of the account to delete.

      Returns Promise<void>

      A promise that resolves when the account is successfully deleted.

  • exportAccount?:function
    • Exports an account's private key.

      If the keyring cannot export a private key, this function should throw an error.

      Parameters

      • id: string

        The ID of the account to export.

      Returns Promise<Record<string, Json>>

      A promise that resolves to the exported account.

  • filterAccountChains:function
    • Filter supported chains for a given account.

      Parameters

      • id: string

        ID of the account to be checked.

      • chains: string[]

        List of chains (CAIP-2) to be checked.

      Returns Promise<string[]>

      A Promise that resolves to a filtered list of CAIP-2 IDs representing the supported chains.

  • getAccount:function
    • Get an account.

      Retrieves the KeyringAccount object for the given account ID.

      Parameters

      • id: string

        The ID of the account to retrieve.

      Returns Promise<undefined | {
          address: string;
          id: string;
          methods: string[];
          options: Record<string, Json>;
          type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
      }>

      A promise that resolves to the KeyringAccount object if found, or undefined otherwise.

  • getAccountBalances?:function
    • Retrieve the balances of a given account.

      This method fetches the balances of specified assets for a given account ID. It returns a promise that resolves to an object where the keys are asset types and the values are balance objects containing the amount and unit.

      Parameters

      • id: string

        ID of the account to retrieve the balances for.

      • assets: string[]

        Array of asset types (CAIP-19) to retrieve balances for.

      Returns Promise<Record<string, {
          amount: string;
          unit: string;
      }>>

      A promise that resolves to an object mapping asset types to their respective balances.

      Example

      await keyring.getAccountBalances(
      '43550276-c7d6-4fac-87c7-00390ad0ce90',
      ['bip122:000000000019d6689c085ae165831e93/slip44:0']
      );
      // Returns something similar to:
      // {
      // 'bip122:000000000019d6689c085ae165831e93/slip44:0': {
      // amount: '0.0001',
      // unit: 'BTC',
      // }
      // }
  • getRequest?:function
    • Get a request.

      Retrieves the KeyringRequest object for the given request ID.

      Parameters

      • id: string

        The ID of the request to retrieve.

      Returns Promise<undefined | {
          account: string;
          id: string;
          request: {
              method: string;
              params?: Json[] | Record<string, Json>;
          };
          scope: string;
      }>

      A promise that resolves to the KeyringRequest object if found, or undefined otherwise.

  • listAccounts:function
    • List accounts.

      Retrieves an array of KeyringAccount objects representing the available accounts.

      Returns Promise<{
          address: string;
          id: string;
          methods: string[];
          options: Record<string, Json>;
          type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
      }[]>

      A promise that resolves to an array of KeyringAccount objects.

  • listRequests?:function
    • List all submitted requests.

      Retrieves an array of KeyringRequest objects representing the submitted requests.

      Returns Promise<{
          account: string;
          id: string;
          request: {
              method: string;
              params?: Json[] | Record<string, Json>;
          };
          scope: string;
      }[]>

      A promise that resolves to an array of KeyringRequest objects.

  • rejectRequest?:function
    • Reject a request.

      Rejects the request with the given ID.

      Parameters

      • id: string

        The ID of the request to reject.

      Returns Promise<void>

      A promise that resolves when the request is successfully rejected.

  • submitRequest:function
    • Submit a request.

      Submits the given KeyringRequest object.

      Parameters

      • request: {
            account: string;
            id: string;
            request: {
                method: string;
                params?: Json[] | Record<string, Json>;
            };
            scope: string;
        }

        The KeyringRequest object to submit.

        • account: string

          Account ID (UUIDv4).

        • id: string

          Keyring request ID (UUIDv4).

        • request: {
              method: string;
              params?: Json[] | Record<string, Json>;
          }

          Inner request sent by the client application.

          • method: string
          • Optional params?: Json[] | Record<string, Json>
        • scope: string

          Request's scope (CAIP-2 chain ID).

      Returns Promise<{
          pending: true;
          redirect?: {
              message?: string;
              url?: string;
          };
      } | {
          pending: false;
          result: Json;
      }>

      A promise that resolves to the request response.

  • updateAccount:function
    • Update an account.

      Updates the account with the given account object. Does nothing if the account does not exist.

      Parameters

      • account: {
            address: string;
            id: string;
            methods: string[];
            options: Record<string, Json>;
            type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
        }

        The updated account object.

        • address: string

          Account main address.

        • id: string

          Account ID (UUIDv4).

        • methods: string[]

          Account supported methods.

        • options: Record<string, Json>

          Account options.

        • type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh"

          Account type.

      Returns Promise<void>

      A promise that resolves when the account is successfully updated.