@metamask-previews/keyring-snap-client 9.0.2-e5bc458 → 9.1.0-5951828

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,10 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Add `resolveAccountAddress` to v2 `KeyringClient` ([#585](https://github.com/MetaMask/accounts/pull/585))
13
+
14
+ ## [9.1.0]
15
+
16
+ ### Added
17
+
18
+ - Implements `KeyringSnapRpc` (v2) in `KeyringClient` (v2) ([#582](https://github.com/MetaMask/accounts/pull/582))
19
+ - Exposes all core v2 keyring methods plus optional snap-specific ones: `setSelectedAccounts`, `getAccountTransactions`, `getAccountAssets`, and `getAccountBalances`.
20
+
10
21
  ### Changed
11
22
 
12
23
  - Bump `@metamask/keyring-utils` from `^3.2.0` to `^3.3.1` ([#544](https://github.com/MetaMask/accounts/pull/544), [#546](https://github.com/MetaMask/accounts/pull/546))
13
- - Bump `@metamask/keyring-api` from `^23.1.0` to `^23.2.0` ([#562](https://github.com/MetaMask/accounts/pull/562))
24
+ - Bump `@metamask/keyring-api` from `^23.1.0` to `^23.4.0` ([#562](https://github.com/MetaMask/accounts/pull/562), [#569](https://github.com/MetaMask/accounts/pull/569), [#583](https://github.com/MetaMask/accounts/pull/583))
14
25
 
15
26
  ## [9.0.2]
16
27
 
@@ -188,7 +199,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
188
199
  - This new version fixes a bug with CJS re-exports.
189
200
  - Initial release ([#24](https://github.com/MetaMask/accounts/pull/24))
190
201
 
191
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-snap-client@9.0.2...HEAD
202
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-snap-client@9.1.0...HEAD
203
+ [9.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-snap-client@9.0.2...@metamask/keyring-snap-client@9.1.0
192
204
  [9.0.2]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-snap-client@9.0.1...@metamask/keyring-snap-client@9.0.2
193
205
  [9.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-snap-client@9.0.0...@metamask/keyring-snap-client@9.0.1
194
206
  [9.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-snap-client@8.2.1...@metamask/keyring-snap-client@9.0.0
@@ -38,6 +38,11 @@ class KeyringClient {
38
38
  ...request,
39
39
  });
40
40
  }
41
+ /**
42
+ * Returns all accounts.
43
+ *
44
+ * @returns A promise that resolves to the list of accounts.
45
+ */
41
46
  async getAccounts() {
42
47
  return (0, keyring_utils_1.strictMask)(await this.send({
43
48
  jsonrpc: '2.0',
@@ -45,6 +50,12 @@ class KeyringClient {
45
50
  method: v2_1.KeyringRpcMethod.GetAccounts,
46
51
  }), v2_1.GetAccountsResponseStruct);
47
52
  }
53
+ /**
54
+ * Returns the account with the specified ID.
55
+ *
56
+ * @param id - ID of the account to retrieve.
57
+ * @returns A promise that resolves to the account with the given ID.
58
+ */
48
59
  async getAccount(id) {
49
60
  return (0, keyring_utils_1.strictMask)(await this.send({
50
61
  jsonrpc: '2.0',
@@ -53,6 +64,12 @@ class KeyringClient {
53
64
  params: { id },
54
65
  }), v2_1.GetAccountResponseStruct);
55
66
  }
67
+ /**
68
+ * Creates one or more new accounts according to the provided options.
69
+ *
70
+ * @param params - Options describing how to create the account(s).
71
+ * @returns A promise that resolves to the list of created accounts.
72
+ */
56
73
  async createAccounts(params) {
57
74
  return (0, keyring_utils_1.strictMask)(await this.send({
58
75
  jsonrpc: '2.0',
@@ -61,6 +78,13 @@ class KeyringClient {
61
78
  params,
62
79
  }), v2_1.CreateAccountsResponseStruct);
63
80
  }
81
+ /**
82
+ * Exports the private key or secret material for the specified account.
83
+ *
84
+ * @param id - ID of the account to export.
85
+ * @param options - Optional export options.
86
+ * @returns A promise that resolves to the exported account data.
87
+ */
64
88
  async exportAccount(id, options) {
65
89
  return (0, keyring_utils_1.strictMask)(await this.send({
66
90
  jsonrpc: '2.0',
@@ -69,6 +93,12 @@ class KeyringClient {
69
93
  params: { id, ...(options && { options }) },
70
94
  }), v2_1.ExportAccountResponseStruct);
71
95
  }
96
+ /**
97
+ * Deletes the account with the specified ID.
98
+ *
99
+ * @param id - ID of the account to delete.
100
+ * @returns A promise that resolves when the account has been deleted.
101
+ */
72
102
  async deleteAccount(id) {
73
103
  (0, superstruct_1.assert)(await this.send({
74
104
  jsonrpc: '2.0',
@@ -77,6 +107,12 @@ class KeyringClient {
77
107
  params: { id },
78
108
  }), v2_1.DeleteAccountResponseStruct);
79
109
  }
110
+ /**
111
+ * Submits a request to the keyring.
112
+ *
113
+ * @param request - The `KeyringRequest` object to submit.
114
+ * @returns A promise that resolves to the response for the request.
115
+ */
80
116
  async submitRequest(request) {
81
117
  return (0, keyring_utils_1.strictMask)(await this.send({
82
118
  jsonrpc: '2.0',
@@ -85,6 +121,80 @@ class KeyringClient {
85
121
  params: request,
86
122
  }), v2_1.SubmitRequestResponseStruct);
87
123
  }
124
+ /**
125
+ * Notifies the Snap of the currently selected accounts.
126
+ *
127
+ * @param accounts - List of selected account IDs.
128
+ * @returns A promise that resolves when the notification has been sent.
129
+ */
130
+ async setSelectedAccounts(accounts) {
131
+ (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
132
+ jsonrpc: '2.0',
133
+ id: (0, uuid_1.v4)(),
134
+ method: v2_1.KeyringSnapRpcMethod.SetSelectedAccounts,
135
+ params: { accounts },
136
+ }), v2_1.SetSelectedAccountsResponseStruct);
137
+ }
138
+ /**
139
+ * Gets transactions for an account with pagination.
140
+ *
141
+ * @param id - ID of the account.
142
+ * @param pagination - Pagination options.
143
+ * @returns A promise that resolves to a page of transactions.
144
+ */
145
+ async getAccountTransactions(id, pagination) {
146
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
147
+ jsonrpc: '2.0',
148
+ id: (0, uuid_1.v4)(),
149
+ method: v2_1.KeyringSnapRpcMethod.GetAccountTransactions,
150
+ params: { id, pagination },
151
+ }), v2_1.GetAccountTransactionsResponseStruct);
152
+ }
153
+ /**
154
+ * Gets the asset types supported by an account.
155
+ *
156
+ * @param id - ID of the account.
157
+ * @returns A promise that resolves to the list of CAIP asset type IDs.
158
+ */
159
+ async getAccountAssets(id) {
160
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
161
+ jsonrpc: '2.0',
162
+ id: (0, uuid_1.v4)(),
163
+ method: v2_1.KeyringSnapRpcMethod.GetAccountAssets,
164
+ params: { id },
165
+ }), v2_1.GetAccountAssetsResponseStruct);
166
+ }
167
+ /**
168
+ * Gets balances for an account for the requested asset types.
169
+ *
170
+ * @param id - ID of the account.
171
+ * @param assets - List of CAIP asset types to fetch balances for.
172
+ * @returns A promise that resolves to a map of asset type to balance.
173
+ */
174
+ async getAccountBalances(id, assets) {
175
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
176
+ jsonrpc: '2.0',
177
+ id: (0, uuid_1.v4)(),
178
+ method: v2_1.KeyringSnapRpcMethod.GetAccountBalances,
179
+ params: { id, assets },
180
+ }), v2_1.GetAccountBalancesResponseStruct);
181
+ }
182
+ /**
183
+ * Resolves the account address to use for routing a signing request.
184
+ *
185
+ * @param scope - CAIP-2 chain ID of the signing request.
186
+ * @param request - The signing JSON-RPC request.
187
+ * @returns A promise that resolves to the resolved address, or `null` if
188
+ * the Snap cannot determine an address for this request.
189
+ */
190
+ async resolveAccountAddress(scope, request) {
191
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
192
+ jsonrpc: '2.0',
193
+ id: (0, uuid_1.v4)(),
194
+ method: v2_1.KeyringSnapRpcMethod.ResolveAccountAddress,
195
+ params: { scope, request },
196
+ }), v2_1.ResolveAccountAddressResponseStruct);
197
+ }
88
198
  }
89
199
  exports.KeyringClient = KeyringClient;
90
200
  _KeyringClient_sender = new WeakMap();
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringClient.cjs","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,iDAQkC;AASlC,2DAAqD;AACrD,uDAA+C;AAE/C,+BAAkC;AAIlC,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;QAPjB,wCAAgB;QAQvB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,IAAI,CAClB,OAAyC;QAEzC,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;YACvB,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,WAAW;QACf,OAAO,IAAA,0BAAU,EACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,qBAAgB,CAAC,WAAW;SACrC,CAAC,EACF,8BAAyB,CAC1B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,0BAAU,EACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,qBAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,6BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,MAA4B;QAE5B,OAAO,IAAA,0BAAU,EACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,qBAAgB,CAAC,cAAc;YACvC,MAAM;SACP,CAAC,EACF,iCAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,EAAa,EACb,OAA8B;QAE9B,OAAO,IAAA,0BAAU,EACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,qBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE;SAC5C,CAAC,EACF,gCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAa;QAC/B,IAAA,oBAAM,EACJ,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,qBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,gCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,OAAO,IAAA,0BAAU,EACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,qBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,gCAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AArGD,sCAqGC","sourcesContent":["import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n CreateAccountsResponseStruct,\n DeleteAccountResponseStruct,\n GetAccountResponseStruct,\n GetAccountsResponseStruct,\n SubmitRequestResponseStruct,\n KeyringRpcMethod,\n ExportAccountResponseStruct,\n} from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringRpc,\n KeyringRpcRequest,\n} from '@metamask/keyring-api/v2';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Sender } from '../KeyringClient';\n\nexport class KeyringClient implements KeyringRpc {\n readonly #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 request - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n protected async send<RequestMethod extends KeyringRpcMethod>(\n request: KeyringRpcRequest<RequestMethod>,\n ): Promise<Json> {\n return this.#sender.send({\n ...request,\n });\n }\n\n async getAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccounts,\n }),\n GetAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async createAccounts(\n params: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.CreateAccounts,\n params,\n }),\n CreateAccountsResponseStruct,\n );\n }\n\n async exportAccount(\n id: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.ExportAccount,\n params: { id, ...(options && { options }) },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: AccountId): Promise<void> {\n assert(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<Json> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"KeyringClient.cjs","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAaA,iDAckC;AAUlC,2DAAqD;AACrD,uDAA+C;AAE/C,+BAAkC;AAIlC,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;QAPjB,wCAAgB;QAQvB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,IAAI,CAClB,OAAyC;QAEzC,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;YACvB,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW;QACf,OAAO,IAAA,0BAAU,EACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,qBAAgB,CAAC,WAAW;SACrC,CAAC,EACF,8BAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,0BAAU,EACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,qBAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,6BAAwB,CACzB,CAAC;IACJ,CAAC;IAED;;;;;OAKG;I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gC,CACjC,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,qBAAqB,CACzB,KAAkB,EAClB,OAAuB;QAEvB,OAAO,IAAA,0BAAU,EACf,MAAM,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,yBAAoB,CAAC,qBAAqB;YAClD,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;SAC3B,CAAC,EACF,wCAAmC,CACpC,CAAC;IACJ,CAAC;CACF;AAhPD,sCAgPC","sourcesContent":["import type {\n CaipChainId,\n KeyringAccount,\n KeyringRequest,\n ResolvedAccountAddress,\n} from '@metamask/keyring-api';\nimport type {\n Balance,\n CaipAssetType,\n CaipAssetTypeOrId,\n Pagination,\n TransactionsPage,\n} from '@metamask/keyring-api';\nimport {\n CreateAccountsResponseStruct,\n DeleteAccountResponseStruct,\n GetAccountResponseStruct,\n GetAccountsResponseStruct,\n SubmitRequestResponseStruct,\n KeyringRpcMethod,\n ExportAccountResponseStruct,\n KeyringSnapRpcMethod,\n SetSelectedAccountsResponseStruct,\n GetAccountTransactionsResponseStruct,\n GetAccountAssetsResponseStruct,\n GetAccountBalancesResponseStruct,\n ResolveAccountAddressResponseStruct,\n} from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringSnapRpc,\n KeyringRpcRequest,\n} from '@metamask/keyring-api/v2';\nimport type { JsonRpcRequest } from '@metamask/keyring-utils';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Sender } from '../KeyringClient';\n\nexport class KeyringClient implements KeyringSnapRpc {\n readonly #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 request - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n protected async send<RequestMethod extends KeyringRpcMethod>(\n request: KeyringRpcRequest<RequestMethod>,\n ): Promise<Json> {\n return this.#sender.send({\n ...request,\n });\n }\n\n /**\n * Returns all accounts.\n *\n * @returns A promise that resolves to the list of accounts.\n */\n async getAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccounts,\n }),\n GetAccountsResponseStruct,\n );\n }\n\n /**\n * Returns the account with the specified ID.\n *\n * @param id - ID of the account to retrieve.\n * @returns A promise that resolves to the account with the given ID.\n */\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n /**\n * Creates one or more new accounts according to the provided options.\n *\n * @param params - Options describing how to create the account(s).\n * @returns A promise that resolves to the list of created accounts.\n */\n async createAccounts(\n params: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.CreateAccounts,\n params,\n }),\n CreateAccountsResponseStruct,\n );\n }\n\n /**\n * Exports the private key or secret material for the specified account.\n *\n * @param id - ID of the account to export.\n * @param options - Optional export options.\n * @returns A promise that resolves to the exported account data.\n */\n async exportAccount(\n id: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.ExportAccount,\n params: { id, ...(options && { options }) },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n /**\n * Deletes the account with the specified ID.\n *\n * @param id - ID of the account to delete.\n * @returns A promise that resolves when the account has been deleted.\n */\n async deleteAccount(id: AccountId): Promise<void> {\n assert(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n /**\n * Submits a request to the keyring.\n *\n * @param request - The `KeyringRequest` object to submit.\n * @returns A promise that resolves to the response for the request.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n /**\n * Notifies the Snap of the currently selected accounts.\n *\n * @param accounts - List of selected account IDs.\n * @returns A promise that resolves when the notification has been sent.\n */\n async setSelectedAccounts(accounts: AccountId[]): Promise<void> {\n assert(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.SetSelectedAccounts,\n params: { accounts },\n }),\n SetSelectedAccountsResponseStruct,\n );\n }\n\n /**\n * Gets transactions for an account with pagination.\n *\n * @param id - ID of the account.\n * @param pagination - Pagination options.\n * @returns A promise that resolves to a page of transactions.\n */\n async getAccountTransactions(\n id: AccountId,\n pagination: Pagination,\n ): Promise<TransactionsPage> {\n return strictMask(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.GetAccountTransactions,\n params: { id, pagination },\n }),\n GetAccountTransactionsResponseStruct,\n );\n }\n\n /**\n * Gets the asset types supported by an account.\n *\n * @param id - ID of the account.\n * @returns A promise that resolves to the list of CAIP asset type IDs.\n */\n async getAccountAssets(id: AccountId): Promise<CaipAssetTypeOrId[]> {\n return strictMask(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.GetAccountAssets,\n params: { id },\n }),\n GetAccountAssetsResponseStruct,\n );\n }\n\n /**\n * Gets balances for an account for the requested asset types.\n *\n * @param id - ID of the account.\n * @param assets - List of CAIP asset types to fetch balances for.\n * @returns A promise that resolves to a map of asset type to balance.\n */\n async getAccountBalances(\n id: AccountId,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n /**\n * Resolves the account address to use for routing a signing request.\n *\n * @param scope - CAIP-2 chain ID of the signing request.\n * @param request - The signing JSON-RPC request.\n * @returns A promise that resolves to the resolved address, or `null` if\n * the Snap cannot determine an address for this request.\n */\n async resolveAccountAddress(\n scope: CaipChainId,\n request: JsonRpcRequest,\n ): Promise<ResolvedAccountAddress | null> {\n return strictMask(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.ResolveAccountAddress,\n params: { scope, request },\n }),\n ResolveAccountAddressResponseStruct,\n );\n }\n}\n"]}
@@ -1,10 +1,12 @@
1
- import type { KeyringAccount, KeyringRequest } from "@metamask/keyring-api";
1
+ import type { CaipChainId, KeyringAccount, KeyringRequest, ResolvedAccountAddress } from "@metamask/keyring-api";
2
+ import type { Balance, CaipAssetType, CaipAssetTypeOrId, Pagination, TransactionsPage } from "@metamask/keyring-api";
2
3
  import { KeyringRpcMethod } from "@metamask/keyring-api/v2";
3
- import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, KeyringRpc, KeyringRpcRequest } from "@metamask/keyring-api/v2";
4
+ import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, KeyringSnapRpc, KeyringRpcRequest } from "@metamask/keyring-api/v2";
5
+ import type { JsonRpcRequest } from "@metamask/keyring-utils";
4
6
  import type { AccountId } from "@metamask/keyring-utils";
5
7
  import type { Json } from "@metamask/utils";
6
8
  import type { Sender } from "../KeyringClient.cjs";
7
- export declare class KeyringClient implements KeyringRpc {
9
+ export declare class KeyringClient implements KeyringSnapRpc {
8
10
  #private;
9
11
  /**
10
12
  * Create a new instance of `KeyringClient`.
@@ -19,11 +21,86 @@ export declare class KeyringClient implements KeyringRpc {
19
21
  * @returns A promise that resolves to the response to the request.
20
22
  */
21
23
  protected send<RequestMethod extends KeyringRpcMethod>(request: KeyringRpcRequest<RequestMethod>): Promise<Json>;
24
+ /**
25
+ * Returns all accounts.
26
+ *
27
+ * @returns A promise that resolves to the list of accounts.
28
+ */
22
29
  getAccounts(): Promise<KeyringAccount[]>;
30
+ /**
31
+ * Returns the account with the specified ID.
32
+ *
33
+ * @param id - ID of the account to retrieve.
34
+ * @returns A promise that resolves to the account with the given ID.
35
+ */
23
36
  getAccount(id: string): Promise<KeyringAccount>;
37
+ /**
38
+ * Creates one or more new accounts according to the provided options.
39
+ *
40
+ * @param params - Options describing how to create the account(s).
41
+ * @returns A promise that resolves to the list of created accounts.
42
+ */
24
43
  createAccounts(params: CreateAccountOptions): Promise<KeyringAccount[]>;
44
+ /**
45
+ * Exports the private key or secret material for the specified account.
46
+ *
47
+ * @param id - ID of the account to export.
48
+ * @param options - Optional export options.
49
+ * @returns A promise that resolves to the exported account data.
50
+ */
25
51
  exportAccount(id: AccountId, options?: ExportAccountOptions): Promise<ExportedAccount>;
52
+ /**
53
+ * Deletes the account with the specified ID.
54
+ *
55
+ * @param id - ID of the account to delete.
56
+ * @returns A promise that resolves when the account has been deleted.
57
+ */
26
58
  deleteAccount(id: AccountId): Promise<void>;
59
+ /**
60
+ * Submits a request to the keyring.
61
+ *
62
+ * @param request - The `KeyringRequest` object to submit.
63
+ * @returns A promise that resolves to the response for the request.
64
+ */
27
65
  submitRequest(request: KeyringRequest): Promise<Json>;
66
+ /**
67
+ * Notifies the Snap of the currently selected accounts.
68
+ *
69
+ * @param accounts - List of selected account IDs.
70
+ * @returns A promise that resolves when the notification has been sent.
71
+ */
72
+ setSelectedAccounts(accounts: AccountId[]): Promise<void>;
73
+ /**
74
+ * Gets transactions for an account with pagination.
75
+ *
76
+ * @param id - ID of the account.
77
+ * @param pagination - Pagination options.
78
+ * @returns A promise that resolves to a page of transactions.
79
+ */
80
+ getAccountTransactions(id: AccountId, pagination: Pagination): Promise<TransactionsPage>;
81
+ /**
82
+ * Gets the asset types supported by an account.
83
+ *
84
+ * @param id - ID of the account.
85
+ * @returns A promise that resolves to the list of CAIP asset type IDs.
86
+ */
87
+ getAccountAssets(id: AccountId): Promise<CaipAssetTypeOrId[]>;
88
+ /**
89
+ * Gets balances for an account for the requested asset types.
90
+ *
91
+ * @param id - ID of the account.
92
+ * @param assets - List of CAIP asset types to fetch balances for.
93
+ * @returns A promise that resolves to a map of asset type to balance.
94
+ */
95
+ getAccountBalances(id: AccountId, assets: CaipAssetType[]): Promise<Record<CaipAssetType, Balance>>;
96
+ /**
97
+ * Resolves the account address to use for routing a signing request.
98
+ *
99
+ * @param scope - CAIP-2 chain ID of the signing request.
100
+ * @param request - The signing JSON-RPC request.
101
+ * @returns A promise that resolves to the resolved address, or `null` if
102
+ * the Snap cannot determine an address for this request.
103
+ */
104
+ resolveAccountAddress(scope: CaipChainId, request: JsonRpcRequest): Promise<ResolvedAccountAddress | null>;
28
105
  }
29
106
  //# sourceMappingURL=KeyringClient.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringClient.d.cts","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAC5E,OAAO,EAML,gBAAgB,EAEjB,iCAAiC;AAClC,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,iBAAiB,EAClB,iCAAiC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAGzD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,MAAM,EAAE,6BAAyB;AAE/C,qBAAa,aAAc,YAAW,UAAU;;IAG9C;;;;OAIG;gBACS,MA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@@ -1,10 +1,12 @@
1
- import type { KeyringAccount, KeyringRequest } from "@metamask/keyring-api";
1
+ import type { CaipChainId, KeyringAccount, KeyringRequest, ResolvedAccountAddress } from "@metamask/keyring-api";
2
+ import type { Balance, CaipAssetType, CaipAssetTypeOrId, Pagination, TransactionsPage } from "@metamask/keyring-api";
2
3
  import { KeyringRpcMethod } from "@metamask/keyring-api/v2";
3
- import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, KeyringRpc, KeyringRpcRequest } from "@metamask/keyring-api/v2";
4
+ import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, KeyringSnapRpc, KeyringRpcRequest } from "@metamask/keyring-api/v2";
5
+ import type { JsonRpcRequest } from "@metamask/keyring-utils";
4
6
  import type { AccountId } from "@metamask/keyring-utils";
5
7
  import type { Json } from "@metamask/utils";
6
8
  import type { Sender } from "../KeyringClient.mjs";
7
- export declare class KeyringClient implements KeyringRpc {
9
+ export declare class KeyringClient implements KeyringSnapRpc {
8
10
  #private;
9
11
  /**
10
12
  * Create a new instance of `KeyringClient`.
@@ -19,11 +21,86 @@ export declare class KeyringClient implements KeyringRpc {
19
21
  * @returns A promise that resolves to the response to the request.
20
22
  */
21
23
  protected send<RequestMethod extends KeyringRpcMethod>(request: KeyringRpcRequest<RequestMethod>): Promise<Json>;
24
+ /**
25
+ * Returns all accounts.
26
+ *
27
+ * @returns A promise that resolves to the list of accounts.
28
+ */
22
29
  getAccounts(): Promise<KeyringAccount[]>;
30
+ /**
31
+ * Returns the account with the specified ID.
32
+ *
33
+ * @param id - ID of the account to retrieve.
34
+ * @returns A promise that resolves to the account with the given ID.
35
+ */
23
36
  getAccount(id: string): Promise<KeyringAccount>;
37
+ /**
38
+ * Creates one or more new accounts according to the provided options.
39
+ *
40
+ * @param params - Options describing how to create the account(s).
41
+ * @returns A promise that resolves to the list of created accounts.
42
+ */
24
43
  createAccounts(params: CreateAccountOptions): Promise<KeyringAccount[]>;
44
+ /**
45
+ * Exports the private key or secret material for the specified account.
46
+ *
47
+ * @param id - ID of the account to export.
48
+ * @param options - Optional export options.
49
+ * @returns A promise that resolves to the exported account data.
50
+ */
25
51
  exportAccount(id: AccountId, options?: ExportAccountOptions): Promise<ExportedAccount>;
52
+ /**
53
+ * Deletes the account with the specified ID.
54
+ *
55
+ * @param id - ID of the account to delete.
56
+ * @returns A promise that resolves when the account has been deleted.
57
+ */
26
58
  deleteAccount(id: AccountId): Promise<void>;
59
+ /**
60
+ * Submits a request to the keyring.
61
+ *
62
+ * @param request - The `KeyringRequest` object to submit.
63
+ * @returns A promise that resolves to the response for the request.
64
+ */
27
65
  submitRequest(request: KeyringRequest): Promise<Json>;
66
+ /**
67
+ * Notifies the Snap of the currently selected accounts.
68
+ *
69
+ * @param accounts - List of selected account IDs.
70
+ * @returns A promise that resolves when the notification has been sent.
71
+ */
72
+ setSelectedAccounts(accounts: AccountId[]): Promise<void>;
73
+ /**
74
+ * Gets transactions for an account with pagination.
75
+ *
76
+ * @param id - ID of the account.
77
+ * @param pagination - Pagination options.
78
+ * @returns A promise that resolves to a page of transactions.
79
+ */
80
+ getAccountTransactions(id: AccountId, pagination: Pagination): Promise<TransactionsPage>;
81
+ /**
82
+ * Gets the asset types supported by an account.
83
+ *
84
+ * @param id - ID of the account.
85
+ * @returns A promise that resolves to the list of CAIP asset type IDs.
86
+ */
87
+ getAccountAssets(id: AccountId): Promise<CaipAssetTypeOrId[]>;
88
+ /**
89
+ * Gets balances for an account for the requested asset types.
90
+ *
91
+ * @param id - ID of the account.
92
+ * @param assets - List of CAIP asset types to fetch balances for.
93
+ * @returns A promise that resolves to a map of asset type to balance.
94
+ */
95
+ getAccountBalances(id: AccountId, assets: CaipAssetType[]): Promise<Record<CaipAssetType, Balance>>;
96
+ /**
97
+ * Resolves the account address to use for routing a signing request.
98
+ *
99
+ * @param scope - CAIP-2 chain ID of the signing request.
100
+ * @param request - The signing JSON-RPC request.
101
+ * @returns A promise that resolves to the resolved address, or `null` if
102
+ * the Snap cannot determine an address for this request.
103
+ */
104
+ resolveAccountAddress(scope: CaipChainId, request: JsonRpcRequest): Promise<ResolvedAccountAddress | null>;
28
105
  }
29
106
  //# sourceMappingURL=KeyringClient.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringClient.d.mts","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAC5E,OAAO,EAML,gBAAgB,EAEjB,iCAAiC;AAClC,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,iBAAiB,EAClB,iCAAiC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAGzD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,MAAM,EAAE,6BAAyB;AAE/C,qBAAa,aAAc,YAAW,UAAU;;IAG9C;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;OAKG;cACa,IAAI,CAAC,aAAa,SAAS,gBAAgB,EACzD,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC;IAMV,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAWxC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAY/C,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,cAAc,EAAE,CAAC;IAYtB,aAAa,CACjB,EAAE,EAAE,SAAS,EACb,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,eAAe,CAAC;IAYrB,aAAa,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAY3C,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAW5D"}
1
+ {"version":3,"file":"KeyringClient.d.mts","sourceRoot":"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AG,OAAO,CAAC,IAAI,CAAC;IAY3D;;;;;OAKG;IACG,mBAAmB,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/D;;;;;;OAMG;IACG,sBAAsB,CAC1B,EAAE,EAAE,SAAS,EACb,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,gBAAgB,CAAC;IAY5B;;;;;OAKG;IACG,gBAAgB,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAYnE;;;;;;OAMG;IACG,kBAAkB,CACtB,EAAE,EAAE,SAAS,EACb,MAAM,EAAE,aAAa,EAAE,GACtB,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAY1C;;;;;;;OAOG;IACG,qBAAqB,CACzB,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC;CAW1C"}
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _KeyringClient_sender;
13
- import { CreateAccountsResponseStruct, DeleteAccountResponseStruct, GetAccountResponseStruct, GetAccountsResponseStruct, SubmitRequestResponseStruct, KeyringRpcMethod, ExportAccountResponseStruct } from "@metamask/keyring-api/v2";
13
+ import { CreateAccountsResponseStruct, DeleteAccountResponseStruct, GetAccountResponseStruct, GetAccountsResponseStruct, SubmitRequestResponseStruct, KeyringRpcMethod, ExportAccountResponseStruct, KeyringSnapRpcMethod, SetSelectedAccountsResponseStruct, GetAccountTransactionsResponseStruct, GetAccountAssetsResponseStruct, GetAccountBalancesResponseStruct, ResolveAccountAddressResponseStruct } from "@metamask/keyring-api/v2";
14
14
  import { strictMask } from "@metamask/keyring-utils";
15
15
  import { assert } from "@metamask/superstruct";
16
16
  import { v4 as uuid } from "uuid";
@@ -35,6 +35,11 @@ export class KeyringClient {
35
35
  ...request,
36
36
  });
37
37
  }
38
+ /**
39
+ * Returns all accounts.
40
+ *
41
+ * @returns A promise that resolves to the list of accounts.
42
+ */
38
43
  async getAccounts() {
39
44
  return strictMask(await this.send({
40
45
  jsonrpc: '2.0',
@@ -42,6 +47,12 @@ export class KeyringClient {
42
47
  method: KeyringRpcMethod.GetAccounts,
43
48
  }), GetAccountsResponseStruct);
44
49
  }
50
+ /**
51
+ * Returns the account with the specified ID.
52
+ *
53
+ * @param id - ID of the account to retrieve.
54
+ * @returns A promise that resolves to the account with the given ID.
55
+ */
45
56
  async getAccount(id) {
46
57
  return strictMask(await this.send({
47
58
  jsonrpc: '2.0',
@@ -50,6 +61,12 @@ export class KeyringClient {
50
61
  params: { id },
51
62
  }), GetAccountResponseStruct);
52
63
  }
64
+ /**
65
+ * Creates one or more new accounts according to the provided options.
66
+ *
67
+ * @param params - Options describing how to create the account(s).
68
+ * @returns A promise that resolves to the list of created accounts.
69
+ */
53
70
  async createAccounts(params) {
54
71
  return strictMask(await this.send({
55
72
  jsonrpc: '2.0',
@@ -58,6 +75,13 @@ export class KeyringClient {
58
75
  params,
59
76
  }), CreateAccountsResponseStruct);
60
77
  }
78
+ /**
79
+ * Exports the private key or secret material for the specified account.
80
+ *
81
+ * @param id - ID of the account to export.
82
+ * @param options - Optional export options.
83
+ * @returns A promise that resolves to the exported account data.
84
+ */
61
85
  async exportAccount(id, options) {
62
86
  return strictMask(await this.send({
63
87
  jsonrpc: '2.0',
@@ -66,6 +90,12 @@ export class KeyringClient {
66
90
  params: { id, ...(options && { options }) },
67
91
  }), ExportAccountResponseStruct);
68
92
  }
93
+ /**
94
+ * Deletes the account with the specified ID.
95
+ *
96
+ * @param id - ID of the account to delete.
97
+ * @returns A promise that resolves when the account has been deleted.
98
+ */
69
99
  async deleteAccount(id) {
70
100
  assert(await this.send({
71
101
  jsonrpc: '2.0',
@@ -74,6 +104,12 @@ export class KeyringClient {
74
104
  params: { id },
75
105
  }), DeleteAccountResponseStruct);
76
106
  }
107
+ /**
108
+ * Submits a request to the keyring.
109
+ *
110
+ * @param request - The `KeyringRequest` object to submit.
111
+ * @returns A promise that resolves to the response for the request.
112
+ */
77
113
  async submitRequest(request) {
78
114
  return strictMask(await this.send({
79
115
  jsonrpc: '2.0',
@@ -82,6 +118,80 @@ export class KeyringClient {
82
118
  params: request,
83
119
  }), SubmitRequestResponseStruct);
84
120
  }
121
+ /**
122
+ * Notifies the Snap of the currently selected accounts.
123
+ *
124
+ * @param accounts - List of selected account IDs.
125
+ * @returns A promise that resolves when the notification has been sent.
126
+ */
127
+ async setSelectedAccounts(accounts) {
128
+ assert(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
129
+ jsonrpc: '2.0',
130
+ id: uuid(),
131
+ method: KeyringSnapRpcMethod.SetSelectedAccounts,
132
+ params: { accounts },
133
+ }), SetSelectedAccountsResponseStruct);
134
+ }
135
+ /**
136
+ * Gets transactions for an account with pagination.
137
+ *
138
+ * @param id - ID of the account.
139
+ * @param pagination - Pagination options.
140
+ * @returns A promise that resolves to a page of transactions.
141
+ */
142
+ async getAccountTransactions(id, pagination) {
143
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
144
+ jsonrpc: '2.0',
145
+ id: uuid(),
146
+ method: KeyringSnapRpcMethod.GetAccountTransactions,
147
+ params: { id, pagination },
148
+ }), GetAccountTransactionsResponseStruct);
149
+ }
150
+ /**
151
+ * Gets the asset types supported by an account.
152
+ *
153
+ * @param id - ID of the account.
154
+ * @returns A promise that resolves to the list of CAIP asset type IDs.
155
+ */
156
+ async getAccountAssets(id) {
157
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
158
+ jsonrpc: '2.0',
159
+ id: uuid(),
160
+ method: KeyringSnapRpcMethod.GetAccountAssets,
161
+ params: { id },
162
+ }), GetAccountAssetsResponseStruct);
163
+ }
164
+ /**
165
+ * Gets balances for an account for the requested asset types.
166
+ *
167
+ * @param id - ID of the account.
168
+ * @param assets - List of CAIP asset types to fetch balances for.
169
+ * @returns A promise that resolves to a map of asset type to balance.
170
+ */
171
+ async getAccountBalances(id, assets) {
172
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
173
+ jsonrpc: '2.0',
174
+ id: uuid(),
175
+ method: KeyringSnapRpcMethod.GetAccountBalances,
176
+ params: { id, assets },
177
+ }), GetAccountBalancesResponseStruct);
178
+ }
179
+ /**
180
+ * Resolves the account address to use for routing a signing request.
181
+ *
182
+ * @param scope - CAIP-2 chain ID of the signing request.
183
+ * @param request - The signing JSON-RPC request.
184
+ * @returns A promise that resolves to the resolved address, or `null` if
185
+ * the Snap cannot determine an address for this request.
186
+ */
187
+ async resolveAccountAddress(scope, request) {
188
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
189
+ jsonrpc: '2.0',
190
+ id: uuid(),
191
+ method: KeyringSnapRpcMethod.ResolveAccountAddress,
192
+ params: { scope, request },
193
+ }), ResolveAccountAddressResponseStruct);
194
+ }
85
195
  }
86
196
  _KeyringClient_sender = new WeakMap();
87
197
  //# sourceMappingURL=KeyringClient.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringClient.mjs","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,gBAAgB,EAChB,2BAA2B,EAC5B,iCAAiC;AASlC,OAAO,EAAE,UAAU,EAAE,gCAAgC;AACrD,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAE/C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAIlC,MAAM,OAAO,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;QAPjB,wCAAgB;QAQvB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,C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EAAa;QAC/B,MAAM,CACJ,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAI,EAAE;YACV,MAAM,EAAE,gBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,2BAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,OAAO,UAAU,CACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAI,EAAE;YACV,MAAM,EAAE,gBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,2BAA2B,CAC5B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n CreateAccountsResponseStruct,\n DeleteAccountResponseStruct,\n GetAccountResponseStruct,\n GetAccountsResponseStruct,\n SubmitRequestResponseStruct,\n KeyringRpcMethod,\n ExportAccountResponseStruct,\n} from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringRpc,\n KeyringRpcRequest,\n} from '@metamask/keyring-api/v2';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Sender } from '../KeyringClient';\n\nexport class KeyringClient implements KeyringRpc {\n readonly #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 request - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n protected async send<RequestMethod extends KeyringRpcMethod>(\n request: KeyringRpcRequest<RequestMethod>,\n ): Promise<Json> {\n return this.#sender.send({\n ...request,\n });\n }\n\n async getAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccounts,\n }),\n GetAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async createAccounts(\n params: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.CreateAccounts,\n params,\n }),\n CreateAccountsResponseStruct,\n );\n }\n\n async exportAccount(\n id: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.ExportAccount,\n params: { id, ...(options && { options }) },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: AccountId): Promise<void> {\n assert(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<Json> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"KeyringClient.mjs","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAaA,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,gBAAgB,EAChB,2BAA2B,EAC3B,oBAAoB,EACpB,iCAAiC,EACjC,oCAAoC,EACpC,8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AAC;CACF","sourcesContent":["import type {\n CaipChainId,\n KeyringAccount,\n KeyringRequest,\n ResolvedAccountAddress,\n} from '@metamask/keyring-api';\nimport type {\n Balance,\n CaipAssetType,\n CaipAssetTypeOrId,\n Pagination,\n TransactionsPage,\n} from '@metamask/keyring-api';\nimport {\n CreateAccountsResponseStruct,\n DeleteAccountResponseStruct,\n GetAccountResponseStruct,\n GetAccountsResponseStruct,\n SubmitRequestResponseStruct,\n KeyringRpcMethod,\n ExportAccountResponseStruct,\n KeyringSnapRpcMethod,\n SetSelectedAccountsResponseStruct,\n GetAccountTransactionsResponseStruct,\n GetAccountAssetsResponseStruct,\n GetAccountBalancesResponseStruct,\n ResolveAccountAddressResponseStruct,\n} from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringSnapRpc,\n KeyringRpcRequest,\n} from '@metamask/keyring-api/v2';\nimport type { JsonRpcRequest } from '@metamask/keyring-utils';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Sender } from '../KeyringClient';\n\nexport class KeyringClient implements KeyringSnapRpc {\n readonly #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 request - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n protected async send<RequestMethod extends KeyringRpcMethod>(\n request: KeyringRpcRequest<RequestMethod>,\n ): Promise<Json> {\n return this.#sender.send({\n ...request,\n });\n }\n\n /**\n * Returns all accounts.\n *\n * @returns A promise that resolves to the list of accounts.\n */\n async getAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccounts,\n }),\n GetAccountsResponseStruct,\n );\n }\n\n /**\n * Returns the account with the specified ID.\n *\n * @param id - ID of the account to retrieve.\n * @returns A promise that resolves to the account with the given ID.\n */\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n /**\n * Creates one or more new accounts according to the provided options.\n *\n * @param params - Options describing how to create the account(s).\n * @returns A promise that resolves to the list of created accounts.\n */\n async createAccounts(\n params: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.CreateAccounts,\n params,\n }),\n CreateAccountsResponseStruct,\n );\n }\n\n /**\n * Exports the private key or secret material for the specified account.\n *\n * @param id - ID of the account to export.\n * @param options - Optional export options.\n * @returns A promise that resolves to the exported account data.\n */\n async exportAccount(\n id: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.ExportAccount,\n params: { id, ...(options && { options }) },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n /**\n * Deletes the account with the specified ID.\n *\n * @param id - ID of the account to delete.\n * @returns A promise that resolves when the account has been deleted.\n */\n async deleteAccount(id: AccountId): Promise<void> {\n assert(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n /**\n * Submits a request to the keyring.\n *\n * @param request - The `KeyringRequest` object to submit.\n * @returns A promise that resolves to the response for the request.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n /**\n * Notifies the Snap of the currently selected accounts.\n *\n * @param accounts - List of selected account IDs.\n * @returns A promise that resolves when the notification has been sent.\n */\n async setSelectedAccounts(accounts: AccountId[]): Promise<void> {\n assert(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.SetSelectedAccounts,\n params: { accounts },\n }),\n SetSelectedAccountsResponseStruct,\n );\n }\n\n /**\n * Gets transactions for an account with pagination.\n *\n * @param id - ID of the account.\n * @param pagination - Pagination options.\n * @returns A promise that resolves to a page of transactions.\n */\n async getAccountTransactions(\n id: AccountId,\n pagination: Pagination,\n ): Promise<TransactionsPage> {\n return strictMask(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.GetAccountTransactions,\n params: { id, pagination },\n }),\n GetAccountTransactionsResponseStruct,\n );\n }\n\n /**\n * Gets the asset types supported by an account.\n *\n * @param id - ID of the account.\n * @returns A promise that resolves to the list of CAIP asset type IDs.\n */\n async getAccountAssets(id: AccountId): Promise<CaipAssetTypeOrId[]> {\n return strictMask(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.GetAccountAssets,\n params: { id },\n }),\n GetAccountAssetsResponseStruct,\n );\n }\n\n /**\n * Gets balances for an account for the requested asset types.\n *\n * @param id - ID of the account.\n * @param assets - List of CAIP asset types to fetch balances for.\n * @returns A promise that resolves to a map of asset type to balance.\n */\n async getAccountBalances(\n id: AccountId,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n /**\n * Resolves the account address to use for routing a signing request.\n *\n * @param scope - CAIP-2 chain ID of the signing request.\n * @param request - The signing JSON-RPC request.\n * @returns A promise that resolves to the resolved address, or `null` if\n * the Snap cannot determine an address for this request.\n */\n async resolveAccountAddress(\n scope: CaipChainId,\n request: JsonRpcRequest,\n ): Promise<ResolvedAccountAddress | null> {\n return strictMask(\n await this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringSnapRpcMethod.ResolveAccountAddress,\n params: { scope, request },\n }),\n ResolveAccountAddressResponseStruct,\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/keyring-snap-client",
3
- "version": "9.0.2-e5bc458",
3
+ "version": "9.1.0-5951828",
4
4
  "description": "MetaMask Keyring Snap clients",
5
5
  "keywords": [
6
6
  "keyring",
@@ -66,9 +66,9 @@
66
66
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
67
67
  },
68
68
  "dependencies": {
69
- "@metamask/keyring-api": "23.2.0",
69
+ "@metamask/keyring-api": "23.4.0",
70
70
  "@metamask/keyring-utils": "3.3.1",
71
- "@metamask/superstruct": "^3.1.0",
71
+ "@metamask/superstruct": "^3.3.0",
72
72
  "@types/uuid": "^9.0.8",
73
73
  "uuid": "^9.0.1",
74
74
  "webextension-polyfill": "^0.12.0"