@metamask/keyring-api 6.3.1 → 7.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 +34 -2
- package/dist/KeyringClient.d.ts +2 -1
- package/dist/KeyringClient.js +6 -0
- package/dist/KeyringClient.js.map +1 -1
- package/dist/api/account.d.ts +29 -3
- package/dist/api/account.js +28 -2
- package/dist/api/account.js.map +1 -1
- package/dist/api/keyring.d.ts +6 -1
- package/dist/api/keyring.js.map +1 -1
- package/dist/internal/api.d.ts +11 -11
- package/dist/internal/events.d.ts +8 -8
- package/dist/internal/types.d.ts +2 -2
- package/dist/rpc-handler.js +3 -0
- package/dist/rpc-handler.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -7,8 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [7.0.0]
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- 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)).
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- **BREAKING:** Keep all ETH methods in the same `enum` ([#313](https://github.com/MetaMask/keyring-api/pull/313)).
|
20
|
+
- Bump @metamask/snaps-sdk from 4.4.1 to 4.4.2 ([#339](https://github.com/MetaMask/keyring-api/pull/339)).
|
21
|
+
- Bump @metamask/rpc-errors from 6.2.1 to 6.3.0 ([#337](https://github.com/MetaMask/keyring-api/pull/337)).
|
22
|
+
- Bump @metamask/json-rpc-middleware-stream from 7.0.1 to 7.0.2 ([#333](https://github.com/MetaMask/keyring-api/pull/333)).
|
23
|
+
- Bump @metamask/snaps-sdk from 4.4.0 to 4.4.1 ([#334](https://github.com/MetaMask/keyring-api/pull/334)).
|
24
|
+
|
25
|
+
### Fixed
|
26
|
+
|
27
|
+
- Allow stale action to be run manually and fix permissions ([#336](https://github.com/MetaMask/keyring-api/pull/336)).
|
28
|
+
|
29
|
+
## [6.4.0]
|
30
|
+
|
31
|
+
### Changed
|
32
|
+
|
33
|
+
- **BREAKING:** Keep all ETH methods in the same `enum` ([#313](https://github.com/MetaMask/keyring-api/pull/313)).
|
34
|
+
- Add support for `@metamask/providers` v17 ([#329](https://github.com/MetaMask/keyring-api/pull/329)).
|
35
|
+
|
10
36
|
## [6.3.1]
|
11
37
|
|
38
|
+
### Changed
|
39
|
+
|
40
|
+
- **BREAKING:** Keep all ETH methods in the same `enum` ([#313](https://github.com/MetaMask/keyring-api/pull/313)).
|
41
|
+
|
12
42
|
### Fixed
|
13
43
|
|
14
44
|
- Export `Caip*` types used in the API ([#325](https://github.com/MetaMask/keyring-api/pull/325)).
|
@@ -22,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
22
52
|
|
23
53
|
### Changed
|
24
54
|
|
55
|
+
- **BREAKING:** Keep all ETH methods in the same `enum` ([#313](https://github.com/MetaMask/keyring-api/pull/313)).
|
25
56
|
- Bump @metamask/snaps-sdk from 4.2.0 to 4.3.0 ([#323](https://github.com/MetaMask/keyring-api/pull/323)).
|
26
57
|
- Split `api.ts` into different files ([#319](https://github.com/MetaMask/keyring-api/pull/319)).
|
27
58
|
- Make the `KeyringAccount` type less rigid ([#311](https://github.com/MetaMask/keyring-api/pull/311)).
|
@@ -30,7 +61,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
30
61
|
|
31
62
|
- Ensure that errors are JSON-serializable ([#162](https://github.com/MetaMask/keyring-api/pull/162)).
|
32
63
|
- Don't use internal types in the public API ([#312](https://github.com/MetaMask/keyring-api/pull/312)).
|
33
|
-
- Keep all ETH methods in the same `enum` ([#313](https://github.com/MetaMask/keyring-api/pull/313)).
|
34
64
|
|
35
65
|
## [6.2.1]
|
36
66
|
|
@@ -325,7 +355,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
325
355
|
- SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
|
326
356
|
- Helper functions to create keyring handler in the snap.
|
327
357
|
|
328
|
-
[Unreleased]: https://github.com/MetaMask/keyring-api/compare/
|
358
|
+
[Unreleased]: https://github.com/MetaMask/keyring-api/compare/v7.0.0...HEAD
|
359
|
+
[7.0.0]: https://github.com/MetaMask/keyring-api/compare/v6.4.0...v7.0.0
|
360
|
+
[6.4.0]: https://github.com/MetaMask/keyring-api/compare/v6.3.1...v6.4.0
|
329
361
|
[6.3.1]: https://github.com/MetaMask/keyring-api/compare/v6.3.0...v6.3.1
|
330
362
|
[6.3.0]: https://github.com/MetaMask/keyring-api/compare/v6.2.1...v6.3.0
|
331
363
|
[6.2.1]: https://github.com/MetaMask/keyring-api/compare/v6.2.0...v6.2.1
|
package/dist/KeyringClient.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Json } from '@metamask/utils';
|
2
|
-
import type { Keyring, KeyringAccount, KeyringRequest, KeyringAccountData, KeyringResponse } from './api';
|
2
|
+
import type { Keyring, KeyringAccount, KeyringRequest, KeyringAccountData, KeyringResponse, CaipAssetType, Balance } from './api';
|
3
3
|
import type { JsonRpcRequest } from './JsonRpcRequest';
|
4
4
|
export declare type Sender = {
|
5
5
|
send(request: JsonRpcRequest): Promise<Json>;
|
@@ -14,6 +14,7 @@ export declare class KeyringClient implements Keyring {
|
|
14
14
|
constructor(sender: Sender);
|
15
15
|
listAccounts(): Promise<KeyringAccount[]>;
|
16
16
|
getAccount(id: string): Promise<KeyringAccount>;
|
17
|
+
getAccountBalances(id: string, assets: CaipAssetType[]): Promise<Record<CaipAssetType, Balance>>;
|
17
18
|
createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;
|
18
19
|
filterAccountChains(id: string, chains: string[]): Promise<string[]>;
|
19
20
|
updateAccount(account: KeyringAccount): Promise<void>;
|
package/dist/KeyringClient.js
CHANGED
@@ -40,6 +40,12 @@ class KeyringClient {
|
|
40
40
|
params: { id },
|
41
41
|
}), api_1.GetAccountResponseStruct);
|
42
42
|
}
|
43
|
+
async getAccountBalances(id, assets) {
|
44
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
45
|
+
method: rpc_1.KeyringRpcMethod.GetAccountBalances,
|
46
|
+
params: { id, assets },
|
47
|
+
}), api_1.GetAccountBalancesResponseStruct);
|
48
|
+
}
|
43
49
|
async createAccount(options = {}) {
|
44
50
|
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
45
51
|
method: rpc_1.KeyringRpcMethod.CreateAccount,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;
|
1
|
+
{"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AAWlC,wCAcwB;AACxB,wCAAkD;AAElD,+CAA2C;AAM3C,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAP1B,wCAAgB;QAQd,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAgBD,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,YAAY;SACtC,CAAC,EACF,gCAA0B,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV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4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AAjKD,sCAiKC;;AArJC;;;;;GAKG;AACH,KAAK,8BAAO,OAA+C;IACzD,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;QACvB,OAAO,EAAE,KAAK;QACd,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n CaipAssetType,\n Balance,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountBalancesResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { strictMask } from './superstruct';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param partial - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n async #send(partial: Omit<JsonRpcRequest, 'jsonrpc' | 'id'>): Promise<Json> {\n return this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n ...partial,\n });\n }\n\n async listAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccounts,\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async getAccountBalances(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.CreateAccount,\n params: { options },\n }),\n CreateAccountResponseStruct,\n );\n }\n\n async filterAccountChains(id: string, chains: string[]): Promise<string[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.FilterAccountChains,\n params: { id, chains },\n }),\n FilterAccountChainsResponseStruct,\n );\n }\n\n async updateAccount(account: KeyringAccount): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.UpdateAccount,\n params: { account },\n }),\n UpdateAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async exportAccount(id: string): Promise<KeyringAccountData> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ExportAccount,\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListRequests,\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetRequest,\n params: { id },\n }),\n GetRequestResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n async approveRequest(\n id: string,\n data: Record<string, Json> = {},\n ): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.ApproveRequest,\n params: { id, data },\n }),\n ApproveRequestResponseStruct,\n );\n }\n\n async rejectRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.RejectRequest,\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
|
package/dist/api/account.d.ts
CHANGED
@@ -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
|
29
|
+
address: string | Record<string, string[]>;
|
30
30
|
options: Record<string, import("@metamask/utils").Json>;
|
31
31
|
methods: string[];
|
32
32
|
}, {
|
@@ -43,9 +43,35 @@ export declare const KeyringAccountStruct: import("superstruct").Struct<{
|
|
43
43
|
"bip122:p2wpkh": "bip122:p2wpkh";
|
44
44
|
}>;
|
45
45
|
/**
|
46
|
-
* Account
|
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
|
+
* ```
|
47
73
|
*/
|
48
|
-
address: import("superstruct").Struct<string, null>;
|
74
|
+
address: import("superstruct").Struct<string | Record<string, string[]>, null>;
|
49
75
|
/**
|
50
76
|
* Account options.
|
51
77
|
*/
|
package/dist/api/account.js
CHANGED
@@ -41,9 +41,35 @@ exports.KeyringAccountStruct = (0, superstruct_2.object)({
|
|
41
41
|
`${BtcAccountType.P2wpkh}`,
|
42
42
|
]),
|
43
43
|
/**
|
44
|
-
* Account
|
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
|
+
* ```
|
45
71
|
*/
|
46
|
-
address: (0, superstruct_1.string)(),
|
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)()))]),
|
47
73
|
/**
|
48
74
|
* Account options.
|
49
75
|
*/
|
package/dist/api/account.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/api/account.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,
|
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"]}
|
package/dist/api/keyring.d.ts
CHANGED
@@ -72,12 +72,17 @@ 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.
|
75
80
|
* @param id - ID of the account to be checked.
|
76
81
|
* @param chains - List of chains (CAIP-2) to be checked.
|
77
82
|
* @returns A Promise that resolves to a filtered list of CAIP-2 IDs
|
78
83
|
* representing the supported chains.
|
79
84
|
*/
|
80
|
-
filterAccountChains(id: string, chains: string[]): Promise<string[]>;
|
85
|
+
filterAccountChains?(id: string, chains: string[]): Promise<string[]>;
|
81
86
|
/**
|
82
87
|
* Update an account.
|
83
88
|
*
|
package/dist/api/keyring.js.map
CHANGED
@@ -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 * @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 * 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"]}
|
package/dist/internal/api.d.ts
CHANGED
@@ -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
|
15
|
+
address: string | Record<string, 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
|
21
|
+
address: string | Record<string, 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, null>;
|
31
|
+
address: import("superstruct").Struct<string | Record<string, 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
|
57
|
+
address: string | Record<string, 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, null>;
|
67
|
+
address: import("superstruct").Struct<string | Record<string, 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
|
93
|
+
address: string | Record<string, 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, null>;
|
103
|
+
address: import("superstruct").Struct<string | Record<string, 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
|
165
|
+
address: string | Record<string, 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
|
176
|
+
address: string | Record<string, 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
|
184
|
+
address: string | Record<string, 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, null>;
|
194
|
+
address: import("superstruct").Struct<string | Record<string, 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
|
7
|
+
address: string | Record<string, 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
|
20
|
+
address: string | Record<string, 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
|
33
|
+
address: string | Record<string, 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, null>;
|
43
|
+
address: import("superstruct").Struct<string | Record<string, 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
|
68
|
+
address: string | Record<string, 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
|
79
|
+
address: string | Record<string, 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
|
90
|
+
address: string | Record<string, 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, null>;
|
100
|
+
address: import("superstruct").Struct<string | Record<string, 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
|
}>;
|
package/dist/internal/types.d.ts
CHANGED
@@ -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
|
251
|
+
address: string | Record<string, 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, null>;
|
305
|
+
address: Struct<string | Record<string, string[]>, null>;
|
306
306
|
options: Struct<Record<string, import("@metamask/utils").Json>, null>;
|
307
307
|
methods: Struct<string[], Struct<string, null>>;
|
308
308
|
}>;
|
package/dist/rpc-handler.js
CHANGED
@@ -47,6 +47,9 @@ 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
|
+
}
|
50
53
|
(0, superstruct_1.assert)(request, api_1.FilterAccountChainsStruct);
|
51
54
|
return keyring.filterAccountChains(request.params.id, request.params.chains);
|
52
55
|
}
|
package/dist/rpc-handler.js.map
CHANGED
@@ -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,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,CAAC;SAC9C;QAED,KAAK,sBAAgB,CAAC,aAAa,CAAC,CAAC;YACnC,IAAA,oBAAM,EAAC,OAAO,EAAE,gCAA0B,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SACtD;QAED,KAAK,sBAAgB,CAAC,kBAAkB,CAAC,CAAC;YACxC,IAAI,OAAO,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AAE,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"]}
|
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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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 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"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask/keyring-api",
|
3
|
-
"version": "
|
3
|
+
"version": "7.0.0",
|
4
4
|
"description": "MetaMask Keyring API",
|
5
5
|
"keywords": [
|
6
6
|
"metamask",
|
@@ -53,7 +53,7 @@
|
|
53
53
|
"@metamask/eslint-config-jest": "^12.1.0",
|
54
54
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
55
55
|
"@metamask/eslint-config-typescript": "^12.1.0",
|
56
|
-
"@metamask/providers": "^
|
56
|
+
"@metamask/providers": "^17.0.0",
|
57
57
|
"@types/jest": "^29.5.12",
|
58
58
|
"@types/node": "^20.12.12",
|
59
59
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
@@ -79,7 +79,7 @@
|
|
79
79
|
"typescript": "~4.8.4"
|
80
80
|
},
|
81
81
|
"peerDependencies": {
|
82
|
-
"@metamask/providers": ">=15 <
|
82
|
+
"@metamask/providers": ">=15 <18"
|
83
83
|
},
|
84
84
|
"packageManager": "yarn@3.2.1",
|
85
85
|
"engines": {
|