@metamask/keyring-api 7.0.0 → 8.0.0

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 CHANGED
@@ -7,12 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [8.0.0]
11
+
12
+ ### Changed
13
+
14
+ - **BREAKING:** Revert "feat: allow multiple address per account (#315)" ([#342](https://github.com/MetaMask/keyring-api/pull/342)).
15
+
10
16
  ## [7.0.0]
11
17
 
12
18
  ### Added
13
19
 
14
20
  - Add `getAccountBalances` to `KeyringClient` ([#340](https://github.com/MetaMask/keyring-api/pull/340)).
15
- - Allow multiple address per account ([#315](https://github.com/MetaMask/keyring-api/pull/315)).
21
+ - **BREAKING:** Allow multiple address per account ([#315](https://github.com/MetaMask/keyring-api/pull/315)).
16
22
 
17
23
  ### Changed
18
24
 
@@ -355,7 +361,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
355
361
  - SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
356
362
  - Helper functions to create keyring handler in the snap.
357
363
 
358
- [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v7.0.0...HEAD
364
+ [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v8.0.0...HEAD
365
+ [8.0.0]: https://github.com/MetaMask/keyring-api/compare/v7.0.0...v8.0.0
359
366
  [7.0.0]: https://github.com/MetaMask/keyring-api/compare/v6.4.0...v7.0.0
360
367
  [6.4.0]: https://github.com/MetaMask/keyring-api/compare/v6.3.1...v6.4.0
361
368
  [6.3.1]: https://github.com/MetaMask/keyring-api/compare/v6.3.0...v6.3.1
@@ -26,7 +26,7 @@ export declare type KeyringAccountType = `${EthAccountType.Eoa}` | `${EthAccount
26
26
  export declare const KeyringAccountStruct: import("superstruct").Struct<{
27
27
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
28
28
  id: string;
29
- address: string | Record<string, string[]>;
29
+ address: string;
30
30
  options: Record<string, import("@metamask/utils").Json>;
31
31
  methods: string[];
32
32
  }, {
@@ -43,35 +43,9 @@ export declare const KeyringAccountStruct: import("superstruct").Struct<{
43
43
  "bip122:p2wpkh": "bip122:p2wpkh";
44
44
  }>;
45
45
  /**
46
- * Account addresses. It can be a single address or a map of addresses per
47
- * chain.
48
- *
49
- * If the address is a string, it's assumed to be under the 'eip155'
50
- * namespace. Otherwise, it must be a map of addresses per chain, where the
51
- * key is the chain ID (CAIP-2) and the value is an array of addresses.
52
- *
53
- * @example
54
- * ```ts
55
- * address: {
56
- * // Different addresses per chain.
57
- * 'eip155:1': ['0x1234...'],
58
- * 'eip155:137': ['0x5678...'],
59
- * }
60
- * ```
61
- * @example
62
- * ```ts
63
- * address: {
64
- * // The address is the same across all 'eip155' chains.
65
- * 'eip155': ['0x1234...'],
66
- * }
67
- * ```
68
- * @example
69
- * ```ts
70
- * // Assumed to be under the 'eip155' namespace.
71
- * address: '0x1234...',
72
- * ```
46
+ * Account main address.
73
47
  */
74
- address: import("superstruct").Struct<string | Record<string, string[]>, null>;
48
+ address: import("superstruct").Struct<string, null>;
75
49
  /**
76
50
  * Account options.
77
51
  */
@@ -41,35 +41,9 @@ exports.KeyringAccountStruct = (0, superstruct_2.object)({
41
41
  `${BtcAccountType.P2wpkh}`,
42
42
  ]),
43
43
  /**
44
- * Account addresses. It can be a single address or a map of addresses per
45
- * chain.
46
- *
47
- * If the address is a string, it's assumed to be under the 'eip155'
48
- * namespace. Otherwise, it must be a map of addresses per chain, where the
49
- * key is the chain ID (CAIP-2) and the value is an array of addresses.
50
- *
51
- * @example
52
- * ```ts
53
- * address: {
54
- * // Different addresses per chain.
55
- * 'eip155:1': ['0x1234...'],
56
- * 'eip155:137': ['0x5678...'],
57
- * }
58
- * ```
59
- * @example
60
- * ```ts
61
- * address: {
62
- * // The address is the same across all 'eip155' chains.
63
- * 'eip155': ['0x1234...'],
64
- * }
65
- * ```
66
- * @example
67
- * ```ts
68
- * // Assumed to be under the 'eip155' namespace.
69
- * address: '0x1234...',
70
- * ```
44
+ * Account main address.
71
45
  */
72
- address: (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.array)((0, superstruct_1.string)()))]),
46
+ address: (0, superstruct_1.string)(),
73
47
  /**
74
48
  * Account options.
75
49
  */
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/api/account.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAAkE;AAElE,gDAAwC;AACxC,oCAAsC;AAEtC;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAED;;GAEG;AACH,IAAY,cAEX;AAFD,WAAY,cAAc;IACxB,0CAAwB,CAAA;AAC1B,CAAC,EAFW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAEzB;AAUD;;;;;;GAMG;AACU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC;QACV,GAAG,cAAc,CAAC,GAAG,EAAE;QACvB,GAAG,cAAc,CAAC,OAAO,EAAE;QAC3B,GAAG,cAAc,CAAC,MAAM,EAAE;KAC3B,CAAC;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC,CAAC,CAAC,CAAC;IAE7D;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;IAErC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC;CACzB,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, enums, record, string, union } from 'superstruct';\n\nimport { object } from '../superstruct';\nimport { UuidStruct } from '../utils';\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Erc4337 = 'eip155:erc4337',\n}\n\n/**\n * Supported Bitcoin account types.\n */\nexport enum BtcAccountType {\n P2wpkh = 'bip122:p2wpkh',\n}\n\n/**\n * Supported account types.\n */\nexport type KeyringAccountType =\n | `${EthAccountType.Eoa}`\n | `${EthAccountType.Erc4337}`\n | `${BtcAccountType.P2wpkh}`;\n\n/**\n * A struct which represents a Keyring account object. It is abstract enough to\n * be used with any blockchain. Specific blockchain account types should extend\n * this struct.\n *\n * See {@link KeyringAccount}.\n */\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account type.\n */\n type: enums([\n `${EthAccountType.Eoa}`,\n `${EthAccountType.Erc4337}`,\n `${BtcAccountType.P2wpkh}`,\n ]),\n\n /**\n * Account addresses. It can be a single address or a map of addresses per\n * chain.\n *\n * If the address is a string, it's assumed to be under the 'eip155'\n * namespace. Otherwise, it must be a map of addresses per chain, where the\n * key is the chain ID (CAIP-2) and the value is an array of addresses.\n *\n * @example\n * ```ts\n * address: {\n * // Different addresses per chain.\n * 'eip155:1': ['0x1234...'],\n * 'eip155:137': ['0x5678...'],\n * }\n * ```\n * @example\n * ```ts\n * address: {\n * // The address is the same across all 'eip155' chains.\n * 'eip155': ['0x1234...'],\n * }\n * ```\n * @example\n * ```ts\n * // Assumed to be under the 'eip155' namespace.\n * address: '0x1234...',\n * ```\n */\n address: union([string(), record(string(), array(string()))]),\n\n /**\n * Account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(string()),\n});\n\n/**\n * Keyring Account type represents an account and its properties from the\n * point of view of the keyring.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/api/account.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAA2D;AAE3D,gDAAwC;AACxC,oCAAsC;AAEtC;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAED;;GAEG;AACH,IAAY,cAEX;AAFD,WAAY,cAAc;IACxB,0CAAwB,CAAA;AAC1B,CAAC,EAFW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAEzB;AAUD;;;;;;GAMG;AACU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC;QACV,GAAG,cAAc,CAAC,GAAG,EAAE;QACvB,GAAG,cAAc,CAAC,OAAO,EAAE;QAC3B,GAAG,cAAc,CAAC,MAAM,EAAE;KAC3B,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,GAAE;IAEjB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;IAErC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC;CACzB,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, enums, record, string } from 'superstruct';\n\nimport { object } from '../superstruct';\nimport { UuidStruct } from '../utils';\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Erc4337 = 'eip155:erc4337',\n}\n\n/**\n * Supported Bitcoin account types.\n */\nexport enum BtcAccountType {\n P2wpkh = 'bip122:p2wpkh',\n}\n\n/**\n * Supported account types.\n */\nexport type KeyringAccountType =\n | `${EthAccountType.Eoa}`\n | `${EthAccountType.Erc4337}`\n | `${BtcAccountType.P2wpkh}`;\n\n/**\n * A struct which represents a Keyring account object. It is abstract enough to\n * be used with any blockchain. Specific blockchain account types should extend\n * this struct.\n *\n * See {@link KeyringAccount}.\n */\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account type.\n */\n type: enums([\n `${EthAccountType.Eoa}`,\n `${EthAccountType.Erc4337}`,\n `${BtcAccountType.P2wpkh}`,\n ]),\n\n /**\n * Account main address.\n */\n address: string(),\n\n /**\n * Account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(string()),\n});\n\n/**\n * Keyring Account type represents an account and its properties from the\n * point of view of the keyring.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n"]}
@@ -72,17 +72,12 @@ export declare type Keyring = {
72
72
  /**
73
73
  * Filter supported chains for a given account.
74
74
  *
75
- * See {@link KeyringAccount}.
76
- *
77
- * @deprecated Use the keys of the `address` map of the account object to
78
- * indicate the supported chains. This method will be removed in a future
79
- * version of the Keyring API.
80
75
  * @param id - ID of the account to be checked.
81
76
  * @param chains - List of chains (CAIP-2) to be checked.
82
77
  * @returns A Promise that resolves to a filtered list of CAIP-2 IDs
83
78
  * representing the supported chains.
84
79
  */
85
- filterAccountChains?(id: string, chains: string[]): Promise<string[]>;
80
+ filterAccountChains(id: string, chains: string[]): Promise<string[]>;
86
81
  /**
87
82
  * Update an account.
88
83
  *
@@ -1 +1 @@
1
- {"version":3,"file":"keyring.js","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport type { KeyringAccount } from './account';\nimport type { Balance } from './balance';\nimport type { CaipAssetType } from './caip';\nimport type { KeyringAccountData } from './export';\nimport type { KeyringRequest } from './request';\nimport type { KeyringResponse } from './response';\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).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\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 * Filter supported chains for a given account.\n *\n * See {@link KeyringAccount}.\n *\n * @deprecated Use the keys of the `address` map of the account object to\n * indicate the supported chains. This method will be removed in a future\n * version of the Keyring API.\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
+ {"version":3,"file":"keyring.js","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport type { KeyringAccount } from './account';\nimport type { Balance } from './balance';\nimport type { CaipAssetType } from './caip';\nimport type { KeyringAccountData } from './export';\nimport type { KeyringRequest } from './request';\nimport type { KeyringResponse } from './response';\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).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\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 * 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"]}
@@ -12,13 +12,13 @@ export declare type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct
12
12
  export declare const ListAccountsResponseStruct: import("superstruct").Struct<{
13
13
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
14
14
  id: string;
15
- address: string | Record<string, string[]>;
15
+ address: string;
16
16
  options: Record<string, import("@metamask/utils").Json>;
17
17
  methods: string[];
18
18
  }[], import("superstruct").Struct<{
19
19
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
20
20
  id: string;
21
- address: string | Record<string, string[]>;
21
+ address: string;
22
22
  options: Record<string, import("@metamask/utils").Json>;
23
23
  methods: string[];
24
24
  }, {
@@ -28,7 +28,7 @@ export declare const ListAccountsResponseStruct: import("superstruct").Struct<{
28
28
  "eip155:erc4337": "eip155:erc4337";
29
29
  "bip122:p2wpkh": "bip122:p2wpkh";
30
30
  }>;
31
- address: import("superstruct").Struct<string | Record<string, string[]>, null>;
31
+ address: import("superstruct").Struct<string, null>;
32
32
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
33
33
  methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
34
34
  }>>;
@@ -54,7 +54,7 @@ export declare type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;
54
54
  export declare const GetAccountResponseStruct: import("superstruct").Struct<{
55
55
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
56
56
  id: string;
57
- address: string | Record<string, string[]>;
57
+ address: string;
58
58
  options: Record<string, import("@metamask/utils").Json>;
59
59
  methods: string[];
60
60
  }, {
@@ -64,7 +64,7 @@ export declare const GetAccountResponseStruct: import("superstruct").Struct<{
64
64
  "eip155:erc4337": "eip155:erc4337";
65
65
  "bip122:p2wpkh": "bip122:p2wpkh";
66
66
  }>;
67
- address: import("superstruct").Struct<string | Record<string, string[]>, null>;
67
+ address: import("superstruct").Struct<string, null>;
68
68
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
69
69
  methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
70
70
  }>;
@@ -90,7 +90,7 @@ export declare type CreateAccountRequest = Infer<typeof CreateAccountRequestStru
90
90
  export declare const CreateAccountResponseStruct: import("superstruct").Struct<{
91
91
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
92
92
  id: string;
93
- address: string | Record<string, string[]>;
93
+ address: string;
94
94
  options: Record<string, import("@metamask/utils").Json>;
95
95
  methods: string[];
96
96
  }, {
@@ -100,7 +100,7 @@ export declare const CreateAccountResponseStruct: import("superstruct").Struct<{
100
100
  "eip155:erc4337": "eip155:erc4337";
101
101
  "bip122:p2wpkh": "bip122:p2wpkh";
102
102
  }>;
103
- address: import("superstruct").Struct<string | Record<string, string[]>, null>;
103
+ address: import("superstruct").Struct<string, null>;
104
104
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
105
105
  methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
106
106
  }>;
@@ -162,7 +162,7 @@ export declare const UpdateAccountRequestStruct: import("superstruct").Struct<{
162
162
  account: {
163
163
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
164
164
  id: string;
165
- address: string | Record<string, string[]>;
165
+ address: string;
166
166
  options: Record<string, import("@metamask/utils").Json>;
167
167
  methods: string[];
168
168
  };
@@ -173,7 +173,7 @@ export declare const UpdateAccountRequestStruct: import("superstruct").Struct<{
173
173
  account: {
174
174
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
175
175
  id: string;
176
- address: string | Record<string, string[]>;
176
+ address: string;
177
177
  options: Record<string, import("@metamask/utils").Json>;
178
178
  methods: string[];
179
179
  };
@@ -181,7 +181,7 @@ export declare const UpdateAccountRequestStruct: import("superstruct").Struct<{
181
181
  account: import("superstruct").Struct<{
182
182
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
183
183
  id: string;
184
- address: string | Record<string, string[]>;
184
+ address: string;
185
185
  options: Record<string, import("@metamask/utils").Json>;
186
186
  methods: string[];
187
187
  }, {
@@ -191,7 +191,7 @@ export declare const UpdateAccountRequestStruct: import("superstruct").Struct<{
191
191
  "eip155:erc4337": "eip155:erc4337";
192
192
  "bip122:p2wpkh": "bip122:p2wpkh";
193
193
  }>;
194
- address: import("superstruct").Struct<string | Record<string, string[]>, null>;
194
+ address: import("superstruct").Struct<string, null>;
195
195
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
196
196
  methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
197
197
  }>;
@@ -4,7 +4,7 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
4
4
  account: {
5
5
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
6
6
  id: string;
7
- address: string | Record<string, string[]>;
7
+ address: string;
8
8
  options: Record<string, import("@metamask/utils").Json>;
9
9
  methods: string[];
10
10
  };
@@ -17,7 +17,7 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
17
17
  account: {
18
18
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
19
19
  id: string;
20
- address: string | Record<string, string[]>;
20
+ address: string;
21
21
  options: Record<string, import("@metamask/utils").Json>;
22
22
  methods: string[];
23
23
  };
@@ -30,7 +30,7 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
30
30
  account: import("superstruct").Struct<{
31
31
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
32
32
  id: string;
33
- address: string | Record<string, string[]>;
33
+ address: string;
34
34
  options: Record<string, import("@metamask/utils").Json>;
35
35
  methods: string[];
36
36
  }, {
@@ -40,7 +40,7 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
40
40
  "eip155:erc4337": "eip155:erc4337";
41
41
  "bip122:p2wpkh": "bip122:p2wpkh";
42
42
  }>;
43
- address: import("superstruct").Struct<string | Record<string, string[]>, null>;
43
+ address: import("superstruct").Struct<string, null>;
44
44
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
45
45
  methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
46
46
  }>;
@@ -65,7 +65,7 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
65
65
  account: {
66
66
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
67
67
  id: string;
68
- address: string | Record<string, string[]>;
68
+ address: string;
69
69
  options: Record<string, import("@metamask/utils").Json>;
70
70
  methods: string[];
71
71
  };
@@ -76,7 +76,7 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
76
76
  account: {
77
77
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
78
78
  id: string;
79
- address: string | Record<string, string[]>;
79
+ address: string;
80
80
  options: Record<string, import("@metamask/utils").Json>;
81
81
  methods: string[];
82
82
  };
@@ -87,7 +87,7 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
87
87
  account: import("superstruct").Struct<{
88
88
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
89
89
  id: string;
90
- address: string | Record<string, string[]>;
90
+ address: string;
91
91
  options: Record<string, import("@metamask/utils").Json>;
92
92
  methods: string[];
93
93
  }, {
@@ -97,7 +97,7 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
97
97
  "eip155:erc4337": "eip155:erc4337";
98
98
  "bip122:p2wpkh": "bip122:p2wpkh";
99
99
  }>;
100
- address: import("superstruct").Struct<string | Record<string, string[]>, null>;
100
+ address: import("superstruct").Struct<string, null>;
101
101
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
102
102
  methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
103
103
  }>;
@@ -248,7 +248,7 @@ export declare type InternalAccountTypes = InternalEthEoaAccount | InternalEthEr
248
248
  export declare const InternalAccountStruct: Struct<{
249
249
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
250
250
  id: string;
251
- address: string | Record<string, string[]>;
251
+ address: string;
252
252
  options: Record<string, import("@metamask/utils").Json>;
253
253
  methods: string[];
254
254
  metadata: {
@@ -302,7 +302,7 @@ export declare const InternalAccountStruct: Struct<{
302
302
  "eip155:erc4337": "eip155:erc4337";
303
303
  "bip122:p2wpkh": "bip122:p2wpkh";
304
304
  }>;
305
- address: Struct<string | Record<string, string[]>, null>;
305
+ address: Struct<string, null>;
306
306
  options: Struct<Record<string, import("@metamask/utils").Json>, null>;
307
307
  methods: Struct<string[], Struct<string, null>>;
308
308
  }>;
@@ -47,9 +47,6 @@ async function dispatchRequest(keyring, request) {
47
47
  return keyring.getAccountBalances(request.params.id, request.params.assets);
48
48
  }
49
49
  case rpc_1.KeyringRpcMethod.FilterAccountChains: {
50
- if (keyring.filterAccountChains === undefined) {
51
- throw new MethodNotSupportedError(request.method);
52
- }
53
50
  (0, superstruct_1.assert)(request, api_1.FilterAccountChainsStruct);
54
51
  return keyring.filterAccountChains(request.params.id, request.params.chains);
55
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AACA,6CAAqC;AAGrC,wCAcwB;AACxB,wCAAkD;AAElD,qDAAwD;AAExD;;GAEG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc;QACxB,KAAK,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAJD,0DAIC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,eAAe,CAC5B,OAAgB,EAChB,OAAuB;IAEvB,6EAA6E;IAC7E,gCAAgC;IAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,qCAAoB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O,KAAK,QAAQ;YACzD,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,8DAA8D,CAAC;QAErE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;AACH,CAAC;AAdD,oDAcC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n GetAccountBalancesRequestStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Inner function that dispatches JSON-RPC request to the associated Keyring\n * methods.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nasync function dispatchRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case KeyringRpcMethod.ListAccounts: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case KeyringRpcMethod.GetAccount: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case KeyringRpcMethod.CreateAccount: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case KeyringRpcMethod.GetAccountBalances: {\n if (keyring.getAccountBalances === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetAccountBalancesRequestStruct);\n return keyring.getAccountBalances(\n request.params.id,\n request.params.assets,\n );\n }\n\n case KeyringRpcMethod.FilterAccountChains: {\n if (keyring.filterAccountChains === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case KeyringRpcMethod.UpdateAccount: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case KeyringRpcMethod.DeleteAccount: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ExportAccount: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ListRequests: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case KeyringRpcMethod.GetRequest: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case KeyringRpcMethod.SubmitRequest: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case KeyringRpcMethod.ApproveRequest: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case KeyringRpcMethod.RejectRequest: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * This function is meant to be used as a handler for Keyring JSON-RPC requests\n * in an Accounts Snap.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n * @example\n * ```ts\n * export const onKeyringRequest: OnKeyringRequestHandler = async ({\n * origin,\n * request,\n * }) => {\n * return await handleKeyringRequest(keyring, request);\n * };\n * ```\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n try {\n return await dispatchRequest(keyring, request);\n } catch (error) {\n const message =\n error instanceof Error && typeof error.message === 'string'\n ? error.message\n : 'An unknown error occurred while handling the keyring request';\n\n throw new Error(message);\n }\n}\n"]}
1
+ {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AACA,6CAAqC;AAGrC,wCAcwB;AACxB,wCAAkD;AAElD,qDAAwD;AAExD;;GAEG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc;QACxB,KAAK,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAJD,0DAIC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,eAAe,CAC5B,OAAgB,EAChB,OAAuB;IAEvB,6EAA6E;IAC7E,gCAAgC;IAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,qCAAoB,CAAC,CAAC;IAEtC,QAAQ,OAAO,CAAC,MAAM,EAAE;QACtB,KAAK,sBAAgB,CAAC,YAAY,CAAC,CAAC;YAClC,IAAA,oBAAM,EAAC,OAAO,EAAE,+BAAyB,CAAC,CAAC;YAC3C,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC;SAC/B;QAED,KAAK,sBAAgB,CAAC,UAAU,CAAC,CAAC;YAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,6BAAuB,CAAC,CAAC;YACzC,OAAO,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC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MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;SACvE;QAED,KAAK,sBAAgB,CAAC,aAAa,CAAC,CAAC;YACnC,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE;gBACvC,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aACnD;YACD,IAAA,oBAAM,EAAC,OAAO,EAAE,gCAA0B,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACjD;QAED,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACnD;KACF;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,oBAAoB,CACxC,OAAgB,EAChB,OAAuB;IAEvB,IAAI;QACF,OAAO,MAAM,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KAChD;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;YACzD,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,8DAA8D,CAAC;QAErE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;AACH,CAAC;AAdD,oDAcC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n GetAccountBalancesRequestStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Inner function that dispatches JSON-RPC request to the associated Keyring\n * methods.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nasync function dispatchRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case KeyringRpcMethod.ListAccounts: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case KeyringRpcMethod.GetAccount: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case KeyringRpcMethod.CreateAccount: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case KeyringRpcMethod.GetAccountBalances: {\n if (keyring.getAccountBalances === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetAccountBalancesRequestStruct);\n return keyring.getAccountBalances(\n request.params.id,\n request.params.assets,\n );\n }\n\n case KeyringRpcMethod.FilterAccountChains: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case KeyringRpcMethod.UpdateAccount: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case KeyringRpcMethod.DeleteAccount: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ExportAccount: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ListRequests: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case KeyringRpcMethod.GetRequest: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case KeyringRpcMethod.SubmitRequest: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case KeyringRpcMethod.ApproveRequest: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case KeyringRpcMethod.RejectRequest: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * This function is meant to be used as a handler for Keyring JSON-RPC requests\n * in an Accounts Snap.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n * @example\n * ```ts\n * export const onKeyringRequest: OnKeyringRequestHandler = async ({\n * origin,\n * request,\n * }) => {\n * return await handleKeyringRequest(keyring, request);\n * };\n * ```\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n try {\n return await dispatchRequest(keyring, request);\n } catch (error) {\n const message =\n error instanceof Error && typeof error.message === 'string'\n ? error.message\n : 'An unknown error occurred while handling the keyring request';\n\n throw new Error(message);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",