@metamask-previews/keyring-api 21.3.0-8508712 → 21.3.0-ca02a28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +4 -0
- package/dist/api/keyring.cjs +0 -2
- package/dist/api/keyring.cjs.map +1 -1
- package/dist/api/keyring.d.cts.map +1 -1
- package/dist/api/keyring.d.mts.map +1 -1
- package/dist/api/keyring.mjs +0 -2
- package/dist/api/keyring.mjs.map +1 -1
- package/dist/api/v2/index.cjs +1 -0
- package/dist/api/v2/index.cjs.map +1 -1
- package/dist/api/v2/index.d.cts +1 -0
- package/dist/api/v2/index.d.cts.map +1 -1
- package/dist/api/v2/index.d.mts +1 -0
- package/dist/api/v2/index.d.mts.map +1 -1
- package/dist/api/v2/index.mjs +1 -0
- package/dist/api/v2/index.mjs.map +1 -1
- package/dist/api/v2/wrapper/index.cjs +19 -0
- package/dist/api/v2/wrapper/index.cjs.map +1 -0
- package/dist/api/v2/wrapper/index.d.cts +3 -0
- package/dist/api/v2/wrapper/index.d.cts.map +1 -0
- package/dist/api/v2/wrapper/index.d.mts +3 -0
- package/dist/api/v2/wrapper/index.d.mts.map +1 -0
- package/dist/api/v2/wrapper/index.mjs +3 -0
- package/dist/api/v2/wrapper/index.mjs.map +1 -0
- package/dist/api/v2/wrapper/keyring-account-registry.cjs +135 -0
- package/dist/api/v2/wrapper/keyring-account-registry.cjs.map +1 -0
- package/dist/api/v2/wrapper/keyring-account-registry.d.cts +88 -0
- package/dist/api/v2/wrapper/keyring-account-registry.d.cts.map +1 -0
- package/dist/api/v2/wrapper/keyring-account-registry.d.mts +88 -0
- package/dist/api/v2/wrapper/keyring-account-registry.d.mts.map +1 -0
- package/dist/api/v2/wrapper/keyring-account-registry.mjs +131 -0
- package/dist/api/v2/wrapper/keyring-account-registry.mjs.map +1 -0
- package/dist/api/v2/wrapper/keyring-wrapper.cjs +116 -0
- package/dist/api/v2/wrapper/keyring-wrapper.cjs.map +1 -0
- package/dist/api/v2/wrapper/keyring-wrapper.d.cts +146 -0
- package/dist/api/v2/wrapper/keyring-wrapper.d.cts.map +1 -0
- package/dist/api/v2/wrapper/keyring-wrapper.d.mts +146 -0
- package/dist/api/v2/wrapper/keyring-wrapper.d.mts.map +1 -0
- package/dist/api/v2/wrapper/keyring-wrapper.mjs +112 -0
- package/dist/api/v2/wrapper/keyring-wrapper.mjs.map +1 -0
- package/dist/eth/erc4337/types.d.cts +4 -4
- package/dist/eth/erc4337/types.d.mts +4 -4
- package/dist/eth/index.cjs +2 -0
- package/dist/eth/index.cjs.map +1 -1
- package/dist/eth/index.d.cts +2 -0
- package/dist/eth/index.d.cts.map +1 -1
- package/dist/eth/index.d.mts +2 -0
- package/dist/eth/index.d.mts.map +1 -1
- package/dist/eth/index.mjs +2 -0
- package/dist/eth/index.mjs.map +1 -1
- package/dist/eth/rpc/index.cjs +18 -0
- package/dist/eth/rpc/index.cjs.map +1 -0
- package/dist/eth/rpc/index.d.cts +2 -0
- package/dist/eth/rpc/index.d.cts.map +1 -0
- package/dist/eth/rpc/index.d.mts +2 -0
- package/dist/eth/rpc/index.d.mts.map +1 -0
- package/dist/eth/rpc/index.mjs +2 -0
- package/dist/eth/rpc/index.mjs.map +1 -0
- package/dist/eth/rpc/params.cjs +151 -0
- package/dist/eth/rpc/params.cjs.map +1 -0
- package/dist/eth/rpc/params.d.cts +215 -0
- package/dist/eth/rpc/params.d.cts.map +1 -0
- package/dist/eth/rpc/params.d.mts +215 -0
- package/dist/eth/rpc/params.d.mts.map +1 -0
- package/dist/eth/rpc/params.mjs +148 -0
- package/dist/eth/rpc/params.mjs.map +1 -0
- package/dist/eth/types.cjs.map +1 -1
- package/dist/eth/types.d.cts +5 -5
- package/dist/eth/types.d.cts.map +1 -1
- package/dist/eth/types.d.mts +5 -5
- package/dist/eth/types.d.mts.map +1 -1
- package/dist/eth/types.mjs.map +1 -1
- package/dist/eth/v2/eth-keyring-wrapper.cjs +165 -0
- package/dist/eth/v2/eth-keyring-wrapper.cjs.map +1 -0
- package/dist/eth/v2/eth-keyring-wrapper.d.cts +54 -0
- package/dist/eth/v2/eth-keyring-wrapper.d.cts.map +1 -0
- package/dist/eth/v2/eth-keyring-wrapper.d.mts +54 -0
- package/dist/eth/v2/eth-keyring-wrapper.d.mts.map +1 -0
- package/dist/eth/v2/eth-keyring-wrapper.mjs +161 -0
- package/dist/eth/v2/eth-keyring-wrapper.mjs.map +1 -0
- package/dist/eth/v2/index.cjs +18 -0
- package/dist/eth/v2/index.cjs.map +1 -0
- package/dist/eth/v2/index.d.cts +2 -0
- package/dist/eth/v2/index.d.cts.map +1 -0
- package/dist/eth/v2/index.d.mts +2 -0
- package/dist/eth/v2/index.d.mts.map +1 -0
- package/dist/eth/v2/index.mjs +2 -0
- package/dist/eth/v2/index.mjs.map +1 -0
- package/dist/events.cjs +0 -2
- package/dist/events.cjs.map +1 -1
- package/dist/events.d.cts.map +1 -1
- package/dist/events.d.mts.map +1 -1
- package/dist/events.mjs +0 -2
- package/dist/events.mjs.map +1 -1
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `EthKeyringWrapper` abstract class for Ethereum-based `KeyringV2` implementations ([#404](https://github.com/MetaMask/accounts/pull/404))
|
|
13
|
+
- Provides common Ethereum signing method routing (`submitRequest`) for all Ethereum-based keyrings.
|
|
14
|
+
- Add `KeyringWrapper` base class to adapt legacy keyrings to `KeyringV2` ([#398](https://github.com/MetaMask/accounts/pull/398)), ([#410](https://github.com/MetaMask/accounts/pull/410))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Refine `EthAddressStruct` in order to make it compatible with the `Hex` type from `@metamask/utils` ([#405](https://github.com/MetaMask/accounts/pull/405))
|
|
19
|
+
|
|
10
20
|
## [21.3.0]
|
|
11
21
|
|
|
12
22
|
### Added
|
package/README.md
CHANGED
|
@@ -230,6 +230,10 @@ A unified keyring interface, designed to work for both native (EVM) keyrings and
|
|
|
230
230
|
- Interface name: `KeyringV2`
|
|
231
231
|
- Location: `@metamask/keyring-api/src/api/v2/keyring.ts`
|
|
232
232
|
|
|
233
|
+
### Keyring wrapper
|
|
234
|
+
|
|
235
|
+
The `KeyringWrapper` helper adapts existing keyrings that implement the legacy `Keyring` interface to the new `KeyringV2` interface. It is intended to be subclassed in concrete keyrings, overriding the account management and request-handling methods to delegate to the underlying implementation.
|
|
236
|
+
|
|
233
237
|
## Migrating from 0.1.x to 0.2.x
|
|
234
238
|
|
|
235
239
|
The following changes were made to the API, which may require changes to your
|
package/dist/api/keyring.cjs
CHANGED
package/dist/api/keyring.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyring.cjs","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyring.cjs","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountId, JsonRpcRequest } from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\n\nimport type { KeyringAccount } from './account';\nimport type { ResolvedAccountAddress } from './address';\nimport type { Balance } from './balance';\nimport type { CaipChainId, CaipAssetType, CaipAssetTypeOrId } from './caip';\nimport type { DiscoveredAccount } from './discovery';\nimport type { EntropySourceId } from './entropy';\nimport type { KeyringAccountData } from './export';\nimport type { MetaMaskOptions } from './options';\nimport type { Paginated, Pagination } from './pagination';\nimport type { KeyringRequest } from './request';\nimport type { KeyringResponse } from './response';\nimport type { Transaction } from './transaction';\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional). The\n * 'metamask' internal options needs to be re-emitted during `notify:*` events.\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(\n options?: Record<string, Json> & MetaMaskOptions,\n ): Promise<KeyringAccount>;\n\n /**\n * Lists the assets of an account (fungibles and non-fungibles) represented\n * by their respective CAIP-19:\n * - Asset types for fungibles assets.\n * - Asset IDs for non-fungible ones.\n *\n * @param id - The ID of the account to list the assets for.\n * @returns A promise that resolves to list of assets for that account.\n */\n listAccountAssets?(id: string): Promise<CaipAssetTypeOrId[]>;\n\n /**\n * Lists the transactions of an account, paginated and ordered by the most\n * recent first.\n *\n * The pagination options are used to limit the number of transactions in the\n * response and to iterate over the results.\n *\n * @param id - The ID of the account to list the transactions for.\n * @param pagination - The pagination options.\n * @returns A promise that resolves to the next page of transactions.\n */\n listAccountTransactions?(\n id: string,\n pagination: Pagination,\n ): Promise<Paginated<Transaction>>;\n\n /**\n * Discover accounts.\n *\n * This method is called by the client to allow the keyring to discover\n * existing accounts based on the provided scopes and entropy source ID. Are\n * considered existing accounts, accounts that have at least one transaction,\n * as per BIP-44.\n *\n * The `groupIndex` is used to group accounts with the same value. In\n * strictly BIP-44 wallets, it matches `account_index`, but in wallets that\n * deviate from BIP-44 recommendations, it may align with a different path\n * level for compatibility.\n *\n * @param scopes - The list of scopes for account discovery.\n * @param entropySource - The ID of the entropy source used to derive the accounts.\n * @param groupIndex - The group index that should be used to derive the accounts.\n * @returns A promise resolving to a list of discovered accounts.\n */\n discoverAccounts?(\n scopes: CaipChainId[],\n entropySource: EntropySourceId,\n groupIndex: number,\n ): Promise<DiscoveredAccount[]>;\n\n /**\n * Retrieve the balances of a given account.\n *\n * This method fetches the balances of specified assets for a given account\n * ID. It returns a promise that resolves to an object where the keys are\n * asset types and the values are balance objects containing the amount and\n * unit.\n *\n * @example\n * ```ts\n * await keyring.getAccountBalances(\n * '43550276-c7d6-4fac-87c7-00390ad0ce90',\n * ['bip122:000000000019d6689c085ae165831e93/slip44:0']\n * );\n * // Returns something similar to:\n * // {\n * // 'bip122:000000000019d6689c085ae165831e93/slip44:0': {\n * // amount: '0.0001',\n * // unit: 'BTC',\n * // }\n * // }\n * ```\n * @param id - ID of the account to retrieve the balances for.\n * @param assets - Array of asset types (CAIP-19) to retrieve balances for.\n * @returns A promise that resolves to an object mapping asset types to their\n * respective balances.\n */\n getAccountBalances?(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>>;\n\n /**\n * Resolves the address of an account from a signing request.\n *\n * This is required by the routing system of MetaMask to dispatch\n * incoming non-EVM dapp signing requests.\n *\n * @param scope - Request's scope (CAIP-2).\n * @param request - Signing request object.\n * @returns A Promise that resolves to the account address that must\n * be used to process this signing request, or null if none candidates\n * could be found.\n */\n resolveAccountAddress?(\n scope: CaipChainId,\n request: JsonRpcRequest,\n ): Promise<ResolvedAccountAddress | null>;\n\n /**\n * Set the selected accounts.\n *\n * @param accounts - The accounts to set as selected.\n */\n setSelectedAccounts?(accounts: AccountId[]): Promise<void>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyring.d.cts","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyring.d.cts","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,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AG,SAAS,CAAC,CAAC;IAE7D;;;;;;;OAOG;IACH,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEjE;;;;;;;;;OASG;IACH,cAAc,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExE;;;;;;;;OAQG;IACH,aAAa,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyring.d.mts","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyring.d.mts","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gCAAgC;AACzE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAkB;AAChD,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAkB;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,sBAAkB;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,mBAAe;AAC5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAoB;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAiB;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,yBAAqB;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAkB;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAmB;AAClD,OAAO,KAAK,EAAE,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CAAC,CAAC;IAE3D;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAErE;;;;;;;;OAQG;IACH,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC;;;;;;;;OAQG;IACH,aAAa,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAExD;;;;;;;OAOG;IACH,YAAY,CAAC,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAE3C;;;;;;;;OAQG;IACH,UAAU,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC;IAE7D;;;;;;;OAOG;IACH,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEjE;;;;;;;;;OASG;IACH,cAAc,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExE;;;;;;;;OAQG;IACH,aAAa,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C,CAAC"}
|
package/dist/api/keyring.mjs
CHANGED
package/dist/api/keyring.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyring.mjs","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyring.mjs","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountId, JsonRpcRequest } from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\n\nimport type { KeyringAccount } from './account';\nimport type { ResolvedAccountAddress } from './address';\nimport type { Balance } from './balance';\nimport type { CaipChainId, CaipAssetType, CaipAssetTypeOrId } from './caip';\nimport type { DiscoveredAccount } from './discovery';\nimport type { EntropySourceId } from './entropy';\nimport type { KeyringAccountData } from './export';\nimport type { MetaMaskOptions } from './options';\nimport type { Paginated, Pagination } from './pagination';\nimport type { KeyringRequest } from './request';\nimport type { KeyringResponse } from './response';\nimport type { Transaction } from './transaction';\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional). The\n * 'metamask' internal options needs to be re-emitted during `notify:*` events.\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(\n options?: Record<string, Json> & MetaMaskOptions,\n ): Promise<KeyringAccount>;\n\n /**\n * Lists the assets of an account (fungibles and non-fungibles) represented\n * by their respective CAIP-19:\n * - Asset types for fungibles assets.\n * - Asset IDs for non-fungible ones.\n *\n * @param id - The ID of the account to list the assets for.\n * @returns A promise that resolves to list of assets for that account.\n */\n listAccountAssets?(id: string): Promise<CaipAssetTypeOrId[]>;\n\n /**\n * Lists the transactions of an account, paginated and ordered by the most\n * recent first.\n *\n * The pagination options are used to limit the number of transactions in the\n * response and to iterate over the results.\n *\n * @param id - The ID of the account to list the transactions for.\n * @param pagination - The pagination options.\n * @returns A promise that resolves to the next page of transactions.\n */\n listAccountTransactions?(\n id: string,\n pagination: Pagination,\n ): Promise<Paginated<Transaction>>;\n\n /**\n * Discover accounts.\n *\n * This method is called by the client to allow the keyring to discover\n * existing accounts based on the provided scopes and entropy source ID. Are\n * considered existing accounts, accounts that have at least one transaction,\n * as per BIP-44.\n *\n * The `groupIndex` is used to group accounts with the same value. In\n * strictly BIP-44 wallets, it matches `account_index`, but in wallets that\n * deviate from BIP-44 recommendations, it may align with a different path\n * level for compatibility.\n *\n * @param scopes - The list of scopes for account discovery.\n * @param entropySource - The ID of the entropy source used to derive the accounts.\n * @param groupIndex - The group index that should be used to derive the accounts.\n * @returns A promise resolving to a list of discovered accounts.\n */\n discoverAccounts?(\n scopes: CaipChainId[],\n entropySource: EntropySourceId,\n groupIndex: number,\n ): Promise<DiscoveredAccount[]>;\n\n /**\n * Retrieve the balances of a given account.\n *\n * This method fetches the balances of specified assets for a given account\n * ID. It returns a promise that resolves to an object where the keys are\n * asset types and the values are balance objects containing the amount and\n * unit.\n *\n * @example\n * ```ts\n * await keyring.getAccountBalances(\n * '43550276-c7d6-4fac-87c7-00390ad0ce90',\n * ['bip122:000000000019d6689c085ae165831e93/slip44:0']\n * );\n * // Returns something similar to:\n * // {\n * // 'bip122:000000000019d6689c085ae165831e93/slip44:0': {\n * // amount: '0.0001',\n * // unit: 'BTC',\n * // }\n * // }\n * ```\n * @param id - ID of the account to retrieve the balances for.\n * @param assets - Array of asset types (CAIP-19) to retrieve balances for.\n * @returns A promise that resolves to an object mapping asset types to their\n * respective balances.\n */\n getAccountBalances?(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>>;\n\n /**\n * Resolves the address of an account from a signing request.\n *\n * This is required by the routing system of MetaMask to dispatch\n * incoming non-EVM dapp signing requests.\n *\n * @param scope - Request's scope (CAIP-2).\n * @param request - Signing request object.\n * @returns A Promise that resolves to the account address that must\n * be used to process this signing request, or null if none candidates\n * could be found.\n */\n resolveAccountAddress?(\n scope: CaipChainId,\n request: JsonRpcRequest,\n ): Promise<ResolvedAccountAddress | null>;\n\n /**\n * Set the selected accounts.\n *\n * @param accounts - The accounts to set as selected.\n */\n setSelectedAccounts?(accounts: AccountId[]): Promise<void>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
|
package/dist/api/v2/index.cjs
CHANGED
|
@@ -19,4 +19,5 @@ __exportStar(require("./keyring-type.cjs"), exports);
|
|
|
19
19
|
__exportStar(require("./create-account/index.cjs"), exports);
|
|
20
20
|
__exportStar(require("./export-account/index.cjs"), exports);
|
|
21
21
|
__exportStar(require("./private-key.cjs"), exports);
|
|
22
|
+
__exportStar(require("./wrapper/index.cjs"), exports);
|
|
22
23
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/api/v2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,6DAAuC;AACvC,qDAA+B;AAC/B,6DAAiC;AACjC,6DAAiC;AACjC,oDAA8B","sourcesContent":["export type * from './keyring';\nexport * from './keyring-capabilities';\nexport * from './keyring-type';\nexport * from './create-account';\nexport * from './export-account';\nexport * from './private-key';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/api/v2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,6DAAuC;AACvC,qDAA+B;AAC/B,6DAAiC;AACjC,6DAAiC;AACjC,oDAA8B;AAC9B,sDAA0B","sourcesContent":["export type * from './keyring';\nexport * from './keyring-capabilities';\nexport * from './keyring-type';\nexport * from './create-account';\nexport * from './export-account';\nexport * from './private-key';\nexport * from './wrapper';\n"]}
|
package/dist/api/v2/index.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/api/v2/index.ts"],"names":[],"mappings":"AAAA,mCAA+B;AAC/B,2CAAuC;AACvC,mCAA+B;AAC/B,2CAAiC;AACjC,2CAAiC;AACjC,kCAA8B"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/api/v2/index.ts"],"names":[],"mappings":"AAAA,mCAA+B;AAC/B,2CAAuC;AACvC,mCAA+B;AAC/B,2CAAiC;AACjC,2CAAiC;AACjC,kCAA8B;AAC9B,oCAA0B"}
|
package/dist/api/v2/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/api/v2/index.ts"],"names":[],"mappings":"AAAA,mCAA+B;AAC/B,2CAAuC;AACvC,mCAA+B;AAC/B,2CAAiC;AACjC,2CAAiC;AACjC,kCAA8B"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/api/v2/index.ts"],"names":[],"mappings":"AAAA,mCAA+B;AAC/B,2CAAuC;AACvC,mCAA+B;AAC/B,2CAAiC;AACjC,2CAAiC;AACjC,kCAA8B;AAC9B,oCAA0B"}
|
package/dist/api/v2/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/api/v2/index.ts"],"names":[],"mappings":"AACA,2CAAuC;AACvC,mCAA+B;AAC/B,2CAAiC;AACjC,2CAAiC;AACjC,kCAA8B","sourcesContent":["export type * from './keyring';\nexport * from './keyring-capabilities';\nexport * from './keyring-type';\nexport * from './create-account';\nexport * from './export-account';\nexport * from './private-key';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/api/v2/index.ts"],"names":[],"mappings":"AACA,2CAAuC;AACvC,mCAA+B;AAC/B,2CAAiC;AACjC,2CAAiC;AACjC,kCAA8B;AAC9B,oCAA0B","sourcesContent":["export type * from './keyring';\nexport * from './keyring-capabilities';\nexport * from './keyring-type';\nexport * from './create-account';\nexport * from './export-account';\nexport * from './private-key';\nexport * from './wrapper';\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./keyring-wrapper.cjs"), exports);
|
|
18
|
+
__exportStar(require("./keyring-account-registry.cjs"), exports);
|
|
19
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAkC;AAClC,iEAA2C","sourcesContent":["export * from './keyring-wrapper';\nexport * from './keyring-account-registry';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,+CAA2C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,+CAA2C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,+CAA2C","sourcesContent":["export * from './keyring-wrapper';\nexport * from './keyring-account-registry';\n"]}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _KeyringAccountRegistry_accountById, _KeyringAccountRegistry_idByAddress;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.KeyringAccountRegistry = void 0;
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
/**
|
|
12
|
+
* In-memory registry for KeyringAccount objects.
|
|
13
|
+
*
|
|
14
|
+
* Provides O(1) lookups by account ID or address, and stores the full
|
|
15
|
+
* KeyringAccount objects for efficient retrieval.
|
|
16
|
+
*/
|
|
17
|
+
class KeyringAccountRegistry {
|
|
18
|
+
constructor() {
|
|
19
|
+
_KeyringAccountRegistry_accountById.set(this, new Map());
|
|
20
|
+
_KeyringAccountRegistry_idByAddress.set(this, new Map());
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get an account by its account ID.
|
|
24
|
+
*
|
|
25
|
+
* @param accountId - The account ID to look up.
|
|
26
|
+
* @returns The KeyringAccount, or undefined if not found.
|
|
27
|
+
*/
|
|
28
|
+
get(accountId) {
|
|
29
|
+
return __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").get(accountId);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get an account's address by its account ID.
|
|
33
|
+
*
|
|
34
|
+
* @param accountId - The account ID to look up.
|
|
35
|
+
* @returns The address, or undefined if not found.
|
|
36
|
+
*/
|
|
37
|
+
getAddress(accountId) {
|
|
38
|
+
return __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").get(accountId)?.address;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get an account ID by the underlying address.
|
|
42
|
+
*
|
|
43
|
+
* @param address - The address to look up.
|
|
44
|
+
* @returns The account ID, or undefined if not found.
|
|
45
|
+
*/
|
|
46
|
+
getAccountId(address) {
|
|
47
|
+
return __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").get(address);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Register a new address and generate an account ID for it.
|
|
51
|
+
* If the address is already registered, returns the existing account ID.
|
|
52
|
+
*
|
|
53
|
+
* @param address - The address to register.
|
|
54
|
+
* @returns The account ID for this address.
|
|
55
|
+
*/
|
|
56
|
+
register(address) {
|
|
57
|
+
const existing = __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").get(address);
|
|
58
|
+
if (existing) {
|
|
59
|
+
return existing;
|
|
60
|
+
}
|
|
61
|
+
const id = (0, uuid_1.v4)();
|
|
62
|
+
__classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").set(address, id);
|
|
63
|
+
return id;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Add an account to the registry.
|
|
67
|
+
* Also registers the address → account ID mapping.
|
|
68
|
+
*
|
|
69
|
+
* ⚠️ If an address was previously registered via `register()` with a
|
|
70
|
+
* different account ID, calling `set()` with an account that has a new ID for
|
|
71
|
+
* the same address will overwrite the address → ID mapping. The old ID
|
|
72
|
+
* becomes "dangling" (i.e., `get(oldId)` will return undefined).
|
|
73
|
+
*
|
|
74
|
+
* @param account - The KeyringAccount to cache.
|
|
75
|
+
*/
|
|
76
|
+
set(account) {
|
|
77
|
+
__classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").set(account.id, account);
|
|
78
|
+
__classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").set(account.address, account.id);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Remove an account from the registry.
|
|
82
|
+
*
|
|
83
|
+
* @param accountId - The account ID to remove.
|
|
84
|
+
*/
|
|
85
|
+
delete(accountId) {
|
|
86
|
+
const account = __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").get(accountId);
|
|
87
|
+
if (account) {
|
|
88
|
+
__classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").delete(account.address);
|
|
89
|
+
__classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").delete(accountId);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Clear all accounts from the registry.
|
|
94
|
+
*/
|
|
95
|
+
clear() {
|
|
96
|
+
__classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").clear();
|
|
97
|
+
__classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").clear();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get all cached accounts as an array.
|
|
101
|
+
*
|
|
102
|
+
* @returns Array of all KeyringAccountType objects in the registry.
|
|
103
|
+
*/
|
|
104
|
+
values() {
|
|
105
|
+
return Array.from(__classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").values());
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get all account IDs in the registry.
|
|
109
|
+
*
|
|
110
|
+
* @returns Array of all account IDs.
|
|
111
|
+
*/
|
|
112
|
+
keys() {
|
|
113
|
+
return Array.from(__classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").keys());
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Check if an account exists in the registry.
|
|
117
|
+
*
|
|
118
|
+
* @param accountId - The account ID to check.
|
|
119
|
+
* @returns True if the account exists.
|
|
120
|
+
*/
|
|
121
|
+
has(accountId) {
|
|
122
|
+
return __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").has(accountId);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get the number of accounts in the registry.
|
|
126
|
+
*
|
|
127
|
+
* @returns The number of accounts.
|
|
128
|
+
*/
|
|
129
|
+
get size() {
|
|
130
|
+
return __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").size;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.KeyringAccountRegistry = KeyringAccountRegistry;
|
|
134
|
+
_KeyringAccountRegistry_accountById = new WeakMap(), _KeyringAccountRegistry_idByAddress = new WeakMap();
|
|
135
|
+
//# sourceMappingURL=keyring-account-registry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring-account-registry.cjs","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/keyring-account-registry.ts"],"names":[],"mappings":";;;;;;;;;AACA,+BAAoC;AAIpC;;;;;GAKG;AACH,MAAa,sBAAsB;IAAnC;QAGW,8CAAe,IAAI,GAAG,EAAiC,EAAC;QAExD,8CAAe,IAAI,GAAG,EAAqB,EAAC;IA0HvD,CAAC;IAxHC;;;;;OAKG;IACH,GAAG,CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,SAAoB;QAC7B,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,OAAe;QAC1B,OAAO,uBAAA,IAAI,2CAAa,CAAC,GA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F,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,2CAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,2CAAa,CAAC,IAAI,CAAC;IAChC,CAAC;CACF;AA/HD,wDA+HC","sourcesContent":["import type { AccountId } from '@metamask/keyring-utils';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport type { KeyringAccount } from '../../account';\n\n/**\n * In-memory registry for KeyringAccount objects.\n *\n * Provides O(1) lookups by account ID or address, and stores the full\n * KeyringAccount objects for efficient retrieval.\n */\nexport class KeyringAccountRegistry<\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> {\n readonly #accountById = new Map<AccountId, KeyringAccountType>();\n\n readonly #idByAddress = new Map<string, AccountId>();\n\n /**\n * Get an account by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The KeyringAccount, or undefined if not found.\n */\n get(accountId: AccountId): KeyringAccountType | undefined {\n return this.#accountById.get(accountId);\n }\n\n /**\n * Get an account's address by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The address, or undefined if not found.\n */\n getAddress(accountId: AccountId): string | undefined {\n return this.#accountById.get(accountId)?.address;\n }\n\n /**\n * Get an account ID by the underlying address.\n *\n * @param address - The address to look up.\n * @returns The account ID, or undefined if not found.\n */\n getAccountId(address: string): AccountId | undefined {\n return this.#idByAddress.get(address);\n }\n\n /**\n * Register a new address and generate an account ID for it.\n * If the address is already registered, returns the existing account ID.\n *\n * @param address - The address to register.\n * @returns The account ID for this address.\n */\n register(address: string): AccountId {\n const existing = this.#idByAddress.get(address);\n if (existing) {\n return existing;\n }\n const id = uuidv4();\n this.#idByAddress.set(address, id);\n return id;\n }\n\n /**\n * Add an account to the registry.\n * Also registers the address → account ID mapping.\n *\n * ⚠️ If an address was previously registered via `register()` with a\n * different account ID, calling `set()` with an account that has a new ID for\n * the same address will overwrite the address → ID mapping. The old ID\n * becomes \"dangling\" (i.e., `get(oldId)` will return undefined).\n *\n * @param account - The KeyringAccount to cache.\n */\n set(account: KeyringAccountType): void {\n this.#accountById.set(account.id, account);\n this.#idByAddress.set(account.address, account.id);\n }\n\n /**\n * Remove an account from the registry.\n *\n * @param accountId - The account ID to remove.\n */\n delete(accountId: AccountId): void {\n const account = this.#accountById.get(accountId);\n if (account) {\n this.#idByAddress.delete(account.address);\n this.#accountById.delete(accountId);\n }\n }\n\n /**\n * Clear all accounts from the registry.\n */\n clear(): void {\n this.#accountById.clear();\n this.#idByAddress.clear();\n }\n\n /**\n * Get all cached accounts as an array.\n *\n * @returns Array of all KeyringAccountType objects in the registry.\n */\n values(): KeyringAccountType[] {\n return Array.from(this.#accountById.values());\n }\n\n /**\n * Get all account IDs in the registry.\n *\n * @returns Array of all account IDs.\n */\n keys(): AccountId[] {\n return Array.from(this.#accountById.keys());\n }\n\n /**\n * Check if an account exists in the registry.\n *\n * @param accountId - The account ID to check.\n * @returns True if the account exists.\n */\n has(accountId: AccountId): boolean {\n return this.#accountById.has(accountId);\n }\n\n /**\n * Get the number of accounts in the registry.\n *\n * @returns The number of accounts.\n */\n get size(): number {\n return this.#accountById.size;\n }\n}\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { AccountId } from "@metamask/keyring-utils";
|
|
2
|
+
import type { KeyringAccount } from "../../account.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* In-memory registry for KeyringAccount objects.
|
|
5
|
+
*
|
|
6
|
+
* Provides O(1) lookups by account ID or address, and stores the full
|
|
7
|
+
* KeyringAccount objects for efficient retrieval.
|
|
8
|
+
*/
|
|
9
|
+
export declare class KeyringAccountRegistry<KeyringAccountType extends KeyringAccount = KeyringAccount> {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Get an account by its account ID.
|
|
13
|
+
*
|
|
14
|
+
* @param accountId - The account ID to look up.
|
|
15
|
+
* @returns The KeyringAccount, or undefined if not found.
|
|
16
|
+
*/
|
|
17
|
+
get(accountId: AccountId): KeyringAccountType | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Get an account's address by its account ID.
|
|
20
|
+
*
|
|
21
|
+
* @param accountId - The account ID to look up.
|
|
22
|
+
* @returns The address, or undefined if not found.
|
|
23
|
+
*/
|
|
24
|
+
getAddress(accountId: AccountId): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Get an account ID by the underlying address.
|
|
27
|
+
*
|
|
28
|
+
* @param address - The address to look up.
|
|
29
|
+
* @returns The account ID, or undefined if not found.
|
|
30
|
+
*/
|
|
31
|
+
getAccountId(address: string): AccountId | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Register a new address and generate an account ID for it.
|
|
34
|
+
* If the address is already registered, returns the existing account ID.
|
|
35
|
+
*
|
|
36
|
+
* @param address - The address to register.
|
|
37
|
+
* @returns The account ID for this address.
|
|
38
|
+
*/
|
|
39
|
+
register(address: string): AccountId;
|
|
40
|
+
/**
|
|
41
|
+
* Add an account to the registry.
|
|
42
|
+
* Also registers the address → account ID mapping.
|
|
43
|
+
*
|
|
44
|
+
* ⚠️ If an address was previously registered via `register()` with a
|
|
45
|
+
* different account ID, calling `set()` with an account that has a new ID for
|
|
46
|
+
* the same address will overwrite the address → ID mapping. The old ID
|
|
47
|
+
* becomes "dangling" (i.e., `get(oldId)` will return undefined).
|
|
48
|
+
*
|
|
49
|
+
* @param account - The KeyringAccount to cache.
|
|
50
|
+
*/
|
|
51
|
+
set(account: KeyringAccountType): void;
|
|
52
|
+
/**
|
|
53
|
+
* Remove an account from the registry.
|
|
54
|
+
*
|
|
55
|
+
* @param accountId - The account ID to remove.
|
|
56
|
+
*/
|
|
57
|
+
delete(accountId: AccountId): void;
|
|
58
|
+
/**
|
|
59
|
+
* Clear all accounts from the registry.
|
|
60
|
+
*/
|
|
61
|
+
clear(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Get all cached accounts as an array.
|
|
64
|
+
*
|
|
65
|
+
* @returns Array of all KeyringAccountType objects in the registry.
|
|
66
|
+
*/
|
|
67
|
+
values(): KeyringAccountType[];
|
|
68
|
+
/**
|
|
69
|
+
* Get all account IDs in the registry.
|
|
70
|
+
*
|
|
71
|
+
* @returns Array of all account IDs.
|
|
72
|
+
*/
|
|
73
|
+
keys(): AccountId[];
|
|
74
|
+
/**
|
|
75
|
+
* Check if an account exists in the registry.
|
|
76
|
+
*
|
|
77
|
+
* @param accountId - The account ID to check.
|
|
78
|
+
* @returns True if the account exists.
|
|
79
|
+
*/
|
|
80
|
+
has(accountId: AccountId): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Get the number of accounts in the registry.
|
|
83
|
+
*
|
|
84
|
+
* @returns The number of accounts.
|
|
85
|
+
*/
|
|
86
|
+
get size(): number;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=keyring-account-registry.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring-account-registry.d.cts","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/keyring-account-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAGzD,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAsB;AAEpD;;;;;GAKG;AACH,qBAAa,sBAAsB,CACjC,kBAAkB,SAAS,cAAc,GAAG,cAAc;;IAM1D;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB,GAAG,SAAS;IAIzD;;;;;OAKG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAIpD;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAIpD;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;IAUpC;;;;;;;;;;OAUG;IACH,GAAG,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAKtC;;;;OAIG;IACH,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAQlC;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;;;OAIG;IACH,MAAM,IAAI,kBAAkB,EAAE;IAI9B;;;;OAIG;IACH,IAAI,IAAI,SAAS,EAAE;IAInB;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO;IAIlC;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { AccountId } from "@metamask/keyring-utils";
|
|
2
|
+
import type { KeyringAccount } from "../../account.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* In-memory registry for KeyringAccount objects.
|
|
5
|
+
*
|
|
6
|
+
* Provides O(1) lookups by account ID or address, and stores the full
|
|
7
|
+
* KeyringAccount objects for efficient retrieval.
|
|
8
|
+
*/
|
|
9
|
+
export declare class KeyringAccountRegistry<KeyringAccountType extends KeyringAccount = KeyringAccount> {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Get an account by its account ID.
|
|
13
|
+
*
|
|
14
|
+
* @param accountId - The account ID to look up.
|
|
15
|
+
* @returns The KeyringAccount, or undefined if not found.
|
|
16
|
+
*/
|
|
17
|
+
get(accountId: AccountId): KeyringAccountType | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Get an account's address by its account ID.
|
|
20
|
+
*
|
|
21
|
+
* @param accountId - The account ID to look up.
|
|
22
|
+
* @returns The address, or undefined if not found.
|
|
23
|
+
*/
|
|
24
|
+
getAddress(accountId: AccountId): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Get an account ID by the underlying address.
|
|
27
|
+
*
|
|
28
|
+
* @param address - The address to look up.
|
|
29
|
+
* @returns The account ID, or undefined if not found.
|
|
30
|
+
*/
|
|
31
|
+
getAccountId(address: string): AccountId | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Register a new address and generate an account ID for it.
|
|
34
|
+
* If the address is already registered, returns the existing account ID.
|
|
35
|
+
*
|
|
36
|
+
* @param address - The address to register.
|
|
37
|
+
* @returns The account ID for this address.
|
|
38
|
+
*/
|
|
39
|
+
register(address: string): AccountId;
|
|
40
|
+
/**
|
|
41
|
+
* Add an account to the registry.
|
|
42
|
+
* Also registers the address → account ID mapping.
|
|
43
|
+
*
|
|
44
|
+
* ⚠️ If an address was previously registered via `register()` with a
|
|
45
|
+
* different account ID, calling `set()` with an account that has a new ID for
|
|
46
|
+
* the same address will overwrite the address → ID mapping. The old ID
|
|
47
|
+
* becomes "dangling" (i.e., `get(oldId)` will return undefined).
|
|
48
|
+
*
|
|
49
|
+
* @param account - The KeyringAccount to cache.
|
|
50
|
+
*/
|
|
51
|
+
set(account: KeyringAccountType): void;
|
|
52
|
+
/**
|
|
53
|
+
* Remove an account from the registry.
|
|
54
|
+
*
|
|
55
|
+
* @param accountId - The account ID to remove.
|
|
56
|
+
*/
|
|
57
|
+
delete(accountId: AccountId): void;
|
|
58
|
+
/**
|
|
59
|
+
* Clear all accounts from the registry.
|
|
60
|
+
*/
|
|
61
|
+
clear(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Get all cached accounts as an array.
|
|
64
|
+
*
|
|
65
|
+
* @returns Array of all KeyringAccountType objects in the registry.
|
|
66
|
+
*/
|
|
67
|
+
values(): KeyringAccountType[];
|
|
68
|
+
/**
|
|
69
|
+
* Get all account IDs in the registry.
|
|
70
|
+
*
|
|
71
|
+
* @returns Array of all account IDs.
|
|
72
|
+
*/
|
|
73
|
+
keys(): AccountId[];
|
|
74
|
+
/**
|
|
75
|
+
* Check if an account exists in the registry.
|
|
76
|
+
*
|
|
77
|
+
* @param accountId - The account ID to check.
|
|
78
|
+
* @returns True if the account exists.
|
|
79
|
+
*/
|
|
80
|
+
has(accountId: AccountId): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Get the number of accounts in the registry.
|
|
83
|
+
*
|
|
84
|
+
* @returns The number of accounts.
|
|
85
|
+
*/
|
|
86
|
+
get size(): number;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=keyring-account-registry.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring-account-registry.d.mts","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/keyring-account-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAGzD,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAsB;AAEpD;;;;;GAKG;AACH,qBAAa,sBAAsB,CACjC,kBAAkB,SAAS,cAAc,GAAG,cAAc;;IAM1D;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB,GAAG,SAAS;IAIzD;;;;;OAKG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAIpD;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAIpD;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;IAUpC;;;;;;;;;;OAUG;IACH,GAAG,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAKtC;;;;OAIG;IACH,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAQlC;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;;;OAIG;IACH,MAAM,IAAI,kBAAkB,EAAE;IAI9B;;;;OAIG;IACH,IAAI,IAAI,SAAS,EAAE;IAInB;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO;IAIlC;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|