@metamask/keyring-api 1.0.0-rc.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.1.0]
11
+
12
+ ### Changed
13
+
14
+ - `UuidStruct` is now a named type ([#159](https://github.com/MetaMask/keyring-api/pull/159))
15
+ - Migrate from `@metamask/rpc-methods` to `@metamask/snaps-rpc-methods` ([#175](https://github.com/MetaMask/keyring-api/pull/175))
16
+
17
+ ### Fixed
18
+
19
+ - Allow the request ID to be a string, number or null ([#156](https://github.com/MetaMask/keyring-api/pull/156))
20
+ - Documentation fixes ([#160](https://github.com/MetaMask/keyring-api/pull/160)) ([#174](https://github.com/MetaMask/keyring-api/pull/174)) ([#173](https://github.com/MetaMask/keyring-api/pull/173)) ([#172](https://github.com/MetaMask/keyring-api/pull/172))
21
+ - Use `UuidStruct` for IDs in the internal API ([#158](https://github.com/MetaMask/keyring-api/pull/158))
22
+ - Bump `@metamask/json-rpc-engine` from `^7.1.1` to `^7.2.0` ([#164](https://github.com/MetaMask/keyring-api/pull/164))
23
+
24
+ ## [1.0.0]
25
+
26
+ ### Added
27
+
28
+ - Add migration steps to 1.0.0 ([#149](https://github.com/MetaMask/keyring-api/pull/149)).
29
+ - Add Account Snaps security guidelines ([#143](https://github.com/MetaMask/keyring-api/pull/143)).
30
+
31
+ ### Changed
32
+
33
+ - Bump @metamask/rpc-errors from 6.0.0 to 6.1.0 ([#151](https://github.com/MetaMask/keyring-api/pull/151)).
34
+ - Bump postcss from 8.4.24 to 8.4.31 ([#150](https://github.com/MetaMask/keyring-api/pull/150)).
35
+
10
36
  ## [1.0.0-rc.1]
11
37
 
12
38
  ### Added
@@ -136,7 +162,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
136
162
  - SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
137
163
  - Helper functions to create keyring handler in the snap.
138
164
 
139
- [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v1.0.0-rc.1...HEAD
165
+ [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v1.1.0...HEAD
166
+ [1.1.0]: https://github.com/MetaMask/keyring-api/compare/v1.0.0...v1.1.0
167
+ [1.0.0]: https://github.com/MetaMask/keyring-api/compare/v1.0.0-rc.1...v1.0.0
140
168
  [1.0.0-rc.1]: https://github.com/MetaMask/keyring-api/compare/v0.2.7...v1.0.0-rc.1
141
169
  [0.2.7]: https://github.com/MetaMask/keyring-api/compare/v0.2.6...v0.2.7
142
170
  [0.2.6]: https://github.com/MetaMask/keyring-api/compare/v0.2.5...v0.2.6
package/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # MetaMask Keyring API
2
2
 
3
- > This TypeScript module is maintained in the style of the MetaMask team.
4
-
5
- This TypeScript module simplifies the integration of snaps with MetaMask using
3
+ This TypeScript module simplifies the integration of Snaps with MetaMask using
6
4
  the Keyring API.
7
5
 
8
6
  Features:
@@ -12,75 +10,220 @@ Features:
12
10
  MetaMask and leverage its functionality.
13
11
 
14
12
  - **Dapp Client**: The module includes a client that enables dapps to
15
- communicate with the Keyring snap. This client allows dapps to send requests
16
- to the snap, such as retrieving account information or submitting requests.
13
+ communicate with the account Snap. This client allows dapps to send requests
14
+ to the Snap, such as retrieving account information or submitting requests.
17
15
 
18
16
  - **MetaMask Client**: The module provides a client specifically designed for
19
17
  MetaMask integration. This client enables MetaMask to send requests directly
20
- to the Keyring snap, facilitating smooth interoperability between the two
18
+ to the account Snap, facilitating smooth interoperability between the two
21
19
  applications.
22
20
 
23
21
  - **Request Handler Helper Functions**: The module offers a set of helper
24
22
  functions to simplify the implementation of the request handler in the
25
- Keyring snap. These functions assist in processing incoming requests,
23
+ account Snap. These functions assist in processing incoming requests,
26
24
  validating data, and handling various request types from dapps and MetaMask.
27
25
 
28
26
  ## Installation
29
27
 
30
- `yarn add @metamask/keyring-api`
28
+ ```bash
29
+ yarn add @metamask/keyring-api
30
+ ```
31
31
 
32
32
  or
33
33
 
34
- `npm install @metamask/keyring-api`
34
+ ```bash
35
+ npm install @metamask/keyring-api
36
+ ```
35
37
 
36
- ## Usage
38
+ ## Account Snaps
37
39
 
38
- ### In a snap
40
+ > **:point_up: Important**: Before implementing your Snap, please make sure to
41
+ > read the [security recommendations](./docs/security.md) and the [architecture
42
+ > document](./docs/architecture.md).
39
43
 
40
- Inside the snap, implement the `Keyring` API:
44
+ Starting with MetaMask 11.4, Snaps can implement the Keyring API. This allows
45
+ users to manage their accounts in a more flexible way, and enables developers
46
+ to build new types of accounts.
41
47
 
42
- ```typescript
43
- class MySnapKeyring implements Keyring {
44
- // Implement the required methods.
45
- }
46
- ```
48
+ > **:pencil: Note:** You can also build MetaMask from [source][extension-repo]
49
+ > from the `develop` branch.
47
50
 
48
- Then create a handler that uses an instance of your keyring:
51
+ Follow these steps to implement the Keyring API in your Snap. Please note that
52
+ these instruction assume that you are already familiar with the process of
53
+ [developing a Snap](https://docs.metamask.io/snaps/).
49
54
 
50
- ```typescript
51
- import { keyringRpcDispatcher } from '@metamask/keyring-api';
55
+ 1. **Implement the Keyring API:**
52
56
 
53
- // Create a new MySnapKeyring instance
54
- keyring = new MySnapKeyring(keyringState);
55
- // ...
57
+ Inside your Snap, implement the `Keyring` API:
56
58
 
57
- // And wrap it in a handler
58
- const keyringHandler: OnRpcRequestHandler = async ({ request }) => {
59
- // Load the keyring state if needed
60
- // ...
61
- return await keyringRpcDispatcher(keyring, request);
62
- };
63
- ```
59
+ ```typescript
60
+ class MySnapKeyring implements Keyring {
61
+ // Implement the required methods here...
62
+ }
63
+ ```
64
64
 
65
- Now expose this handler:
65
+ > **:point_up: Important**: Ensure that your keyring implements the [methods
66
+ > called by MetaMask][exposed-methods], otherwise some features may not
67
+ > work.
66
68
 
67
- ```typescript
68
- export const onRpcRequest: OnRpcRequestHandler = keyringHandler;
69
- ```
69
+ 2. **Handle requests submitted by MetaMask:**
70
70
 
71
- Or chain it with other handlers:
71
+ MetaMask will submit requests through the `submitRequest` method of your the
72
+ Keyring API (check the supported [EVM methods](./docs/evm_methods.md)). Here
73
+ is an example of request:
72
74
 
73
- ```typescript
74
- import { chainHandlers } from '@metamask/keyring-api';
75
+ ```json
76
+ {
77
+ "id": "d6e23af6-4bea-48dd-aeb0-7d3c30ea67f9",
78
+ "scope": "",
79
+ "account": "69438371-bef3-4957-9f91-c3f22c1d75f3",
80
+ "request": {
81
+ "method": "personal_sign",
82
+ "params": [
83
+ "0x4578616d706c652060706572736f6e616c5f7369676e60206d657373616765",
84
+ "0x5874174dcf1ab6F7Efd8496f4f09404CD1c5bA84"
85
+ ]
86
+ }
87
+ }
88
+ ```
75
89
 
76
- export const onRpcRequest: OnRpcRequestHandler = chainHandlers(
77
- // Other handlers...
78
- keyringHandler,
79
- // Other handlers...
80
- );
81
- ```
90
+ Where:
91
+
92
+ - `id` is unique identifier for the request.
93
+
94
+ - `scope` is the CAIP-2 chain ID of the selected chain. Currently, this
95
+ property is always an empty string. Your Snap should use the chain ID
96
+ present in the request object instead.
97
+
98
+ - `account` is the ID of the account that should handle the request.
99
+
100
+ - `request` is the request object.
101
+
102
+ Your Snap must respond with either a synchronous result:
103
+
104
+ ```typescript
105
+ return { pending: false, result };
106
+ ```
107
+
108
+ Or an asynchronous result:
109
+
110
+ ```typescript
111
+ return { pending: true, redirect: { message, url } };
112
+ ```
113
+
114
+ The redirect message and URL will be displayed to the user to inform them
115
+ about how to continue the transaction flow.
116
+
117
+ 3. **Notify MetaMask about events:**
118
+
119
+ The following actions must be notified to MetaMask:
120
+
121
+ 1. When an account is created:
122
+
123
+ ```typescript
124
+ try {
125
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountCreated, { account });
126
+ // Update your snap's state...
127
+ } catch (error) {
128
+ // Handle the error...
129
+ }
130
+ ```
131
+
132
+ MetaMask will return an error if the account already exists or if the
133
+ account object is invalid.
134
+
135
+ 2. When an account is updated:
136
+
137
+ ```typescript
138
+ try {
139
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountUpdated, { account });
140
+ // Update your snap's state...
141
+ } catch (error) {
142
+ // Handle the error...
143
+ }
144
+ ```
82
145
 
83
- ### Migrating from API 0.1.x to 0.2.x
146
+ MetaMask will return an error if the account does not exist, if the
147
+ account object is invalid, or if the account address changed.
148
+
149
+ 3. When an account is deleted:
150
+
151
+ ```typescript
152
+ try {
153
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountDeleted, {
154
+ id: account.id,
155
+ });
156
+ // Update your snap's state...
157
+ } catch (error) {
158
+ // Handle the error...
159
+ }
160
+ ```
161
+
162
+ The delete event is idempotent, so it is safe to emit it even if the
163
+ account does not exist.
164
+
165
+ 4. When a request is approved:
166
+
167
+ ```typescript
168
+ try {
169
+ emitSnapKeyringEvent(snap, KeyringEvent.RequestApproved, {
170
+ id: request.id,
171
+ result,
172
+ });
173
+ // Update your snap's state...
174
+ } catch (error) {
175
+ // Handle the error...
176
+ }
177
+ ```
178
+
179
+ MetaMask will return an error if the request does not exist.
180
+
181
+ > **:pencil: Note:** This only applies to Snaps that implement the
182
+ > [asynchronous transaction flow][async-flow].
183
+
184
+ 5. When a request is rejected:
185
+
186
+ ```typescript
187
+ try {
188
+ emitSnapKeyringEvent(snap, KeyringEvent.RequestRejected, {
189
+ id: request.id,
190
+ });
191
+ // Update your snap's state...
192
+ } catch (error) {
193
+ // Handle the error...
194
+ }
195
+ ```
196
+
197
+ MetaMask will return an error if the request does not exist.
198
+
199
+ > **:pencil: Note:** This only applies to Snaps that implement the
200
+ > [asynchronous transaction flow][async-flow].
201
+
202
+ 4. **Expose the Keyring API:**
203
+
204
+ Then create a handler to expose the keyring methods to MetaMask and your dapp:
205
+
206
+ ```typescript
207
+ export const onKeyringRequest: OnKeyringRequestHandler = async ({
208
+ origin,
209
+ request,
210
+ }) => {
211
+ // Your custom logic here...
212
+ return handleKeyringRequest(keyring, request);
213
+ };
214
+ ```
215
+
216
+ 5. **Call the keyring methods from your dapp:**
217
+
218
+ Now you should be able to call your account Snap from your dapp, for
219
+ example:
220
+
221
+ ```typescript
222
+ const client = new KeyringSnapRpcClient(snapId, window.ethereum);
223
+ const accounts = await client.listAccounts();
224
+ ```
225
+
226
+ ## Migrating from 0.1.x to 0.2.x
84
227
 
85
228
  The following changes were made to the API, which may require changes to your
86
229
  implementation:
@@ -140,15 +283,14 @@ implementation:
140
283
  emitSnapKeyringEvent(snap, KeyringEvent.RequestRejected, { id: request.id });
141
284
  ```
142
285
 
143
- > [!IMPORTANT]
144
- > For all events above, MetaMask may return an error indicating that the
145
- > event was not handled, possibly because it contains invalid arguments.
286
+ > **:point_up: Important**: For all events above, MetaMask may return an error
287
+ > indicating that the event was not handled, possibly because it contains
288
+ > invalid arguments.
146
289
 
147
- - Keyrings that implement the [async transaction
148
- flow](./docs/architecture.md#transaction-flow) can now return an optional
149
- `redirect` property that contains an URL and a message to be displayed to the
150
- user. This will, in a future release of MetaMask, be used to inform the user
151
- on how to continue the transaction flow.
290
+ - Keyrings that implement the [asynchronous transaction flow][async-flow] can
291
+ now return an optional `redirect` property that contains an URL and a message
292
+ to be displayed to the user. This will, in a future release of MetaMask, be
293
+ used to inform the user on how to continue the transaction flow.
152
294
 
153
295
  ```ts
154
296
  return {
@@ -180,6 +322,20 @@ implementation:
180
322
  };
181
323
  ```
182
324
 
325
+ ## Migrating from 0.2.x to 1.x.x
326
+
327
+ The following changes were made to the API, which may require changes to your
328
+ implementation:
329
+
330
+ - Your Snap must expose the Keyring methods through the `onKeyringRequest`
331
+ export instead of the `onRpcRequest` export.
332
+
333
+ - Your Snap must request the new `endowment:keyring` endowment, and list any
334
+ dapp that should be allowed to call the Keyring methods.
335
+
336
+ For more details about the changes, please refer to the [security
337
+ guidelines](./docs/security.md).
338
+
183
339
  ## API
184
340
 
185
341
  See our documentation:
@@ -239,3 +395,7 @@ The project follows the same release process as the other libraries in the MetaM
239
395
  - Wait for the `publish-release` GitHub Action workflow to finish. This should trigger a second job (`publish-npm`), which will wait for a run approval by the [`npm publishers`](https://github.com/orgs/MetaMask/teams/npm-publishers) team.
240
396
  - Approve the `publish-npm` job (or ask somebody on the npm publishers team to approve it for you).
241
397
  - Once the `publish-npm` job has finished, check npm to verify that it has been published.
398
+
399
+ [extension-repo]: https://github.com/MetaMask/metamask-extension
400
+ [exposed-methods]: ./docs/security.md#limit-the-methods-exposed-to-dapps
401
+ [async-flow]: ./docs/architecture.md#asynchronous-transaction-flow
@@ -16,7 +16,7 @@ exports.KeyringClient = void 0;
16
16
  const superstruct_1 = require("superstruct");
17
17
  const uuid_1 = require("uuid");
18
18
  const api_1 = require("./internal/api");
19
- const rpc_handler_1 = require("./rpc-handler");
19
+ const rpc_1 = require("./internal/rpc");
20
20
  const utils_1 = require("./utils");
21
21
  class KeyringClient {
22
22
  /**
@@ -31,71 +31,71 @@ class KeyringClient {
31
31
  }
32
32
  async listAccounts() {
33
33
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
34
- method: rpc_handler_1.KeyringRpcMethod.ListAccounts,
34
+ method: rpc_1.KeyringRpcMethod.ListAccounts,
35
35
  }), api_1.ListAccountsResponseStruct);
36
36
  }
37
37
  async getAccount(id) {
38
38
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
39
- method: rpc_handler_1.KeyringRpcMethod.GetAccount,
39
+ method: rpc_1.KeyringRpcMethod.GetAccount,
40
40
  params: { id },
41
41
  }), api_1.GetAccountResponseStruct);
42
42
  }
43
43
  async createAccount(options = {}) {
44
44
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
45
- method: rpc_handler_1.KeyringRpcMethod.CreateAccount,
45
+ method: rpc_1.KeyringRpcMethod.CreateAccount,
46
46
  params: { options },
47
47
  }), api_1.CreateAccountResponseStruct);
48
48
  }
49
49
  async filterAccountChains(id, chains) {
50
50
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
51
- method: rpc_handler_1.KeyringRpcMethod.FilterAccountChains,
51
+ method: rpc_1.KeyringRpcMethod.FilterAccountChains,
52
52
  params: { id, chains },
53
53
  }), api_1.FilterAccountChainsResponseStruct);
54
54
  }
55
55
  async updateAccount(account) {
56
56
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
57
- method: rpc_handler_1.KeyringRpcMethod.UpdateAccount,
57
+ method: rpc_1.KeyringRpcMethod.UpdateAccount,
58
58
  params: { account },
59
59
  }), api_1.UpdateAccountResponseStruct);
60
60
  }
61
61
  async deleteAccount(id) {
62
62
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
63
- method: rpc_handler_1.KeyringRpcMethod.DeleteAccount,
63
+ method: rpc_1.KeyringRpcMethod.DeleteAccount,
64
64
  params: { id },
65
65
  }), api_1.DeleteAccountResponseStruct);
66
66
  }
67
67
  async exportAccount(id) {
68
68
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
69
- method: rpc_handler_1.KeyringRpcMethod.ExportAccount,
69
+ method: rpc_1.KeyringRpcMethod.ExportAccount,
70
70
  params: { id },
71
71
  }), api_1.ExportAccountResponseStruct);
72
72
  }
73
73
  async listRequests() {
74
74
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
75
- method: rpc_handler_1.KeyringRpcMethod.ListRequests,
75
+ method: rpc_1.KeyringRpcMethod.ListRequests,
76
76
  }), api_1.ListRequestsResponseStruct);
77
77
  }
78
78
  async getRequest(id) {
79
79
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
80
- method: rpc_handler_1.KeyringRpcMethod.GetRequest,
80
+ method: rpc_1.KeyringRpcMethod.GetRequest,
81
81
  params: { id },
82
82
  }), api_1.GetRequestResponseStruct);
83
83
  }
84
84
  async submitRequest(request) {
85
85
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
86
- method: rpc_handler_1.KeyringRpcMethod.SubmitRequest,
86
+ method: rpc_1.KeyringRpcMethod.SubmitRequest,
87
87
  params: request,
88
88
  }), api_1.SubmitRequestResponseStruct);
89
89
  }
90
90
  async approveRequest(id, data = {}) {
91
91
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
92
- method: rpc_handler_1.KeyringRpcMethod.ApproveRequest,
92
+ method: rpc_1.KeyringRpcMethod.ApproveRequest,
93
93
  params: { id, data },
94
94
  }), api_1.ApproveRequestResponseStruct);
95
95
  }
96
96
  async rejectRequest(id) {
97
97
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
98
- method: rpc_handler_1.KeyringRpcMethod.RejectRequest,
98
+ method: rpc_1.KeyringRpcMethod.RejectRequest,
99
99
  params: { id },
100
100
  }), api_1.RejectRequestResponseStruct);
101
101
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AASlC,wCAawB;AAExB,+CAAiD;AACjD,mCAAqC;AAMrC,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,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM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AU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AApJD,sCAoJC;;AAxIC;;;;;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} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './internal/api';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { KeyringRpcMethod } from './rpc-handler';\nimport { strictMask } from './utils';\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 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"]}
1
+ {"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AASlC,wCAawB;AACxB,wCAAkD;AAElD,mCAAqC;AAMrC,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,kBAAU,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,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,UAAgC,EAAE;QAElC,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,OAAO,EAAE;SACpB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,EAAU,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AAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,EAAU,EACV,OAA6B,EAAE;QAE/B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,cAAc;YACvC,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE;SACrB,CAAC,EACF,kCAA4B,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;AApJD,sCAoJC;;AAxIC;;;;;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} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\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 './utils';\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 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"]}
@@ -1,12 +1,12 @@
1
1
  import type { Infer } from 'superstruct';
2
2
  export declare const ListAccountsRequestStruct: import("superstruct").Struct<{
3
3
  jsonrpc: "2.0";
4
- id: string;
4
+ id: string | number | null;
5
5
  method: "keyring_listAccounts";
6
6
  }, {
7
7
  method: import("superstruct").Struct<"keyring_listAccounts", "keyring_listAccounts">;
8
8
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
9
- id: import("superstruct").Struct<string, null>;
9
+ id: import("superstruct").Struct<string | number | null, null>;
10
10
  }>;
11
11
  export declare type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;
12
12
  export declare const ListAccountsResponseStruct: import("superstruct").Struct<{
@@ -41,7 +41,7 @@ export declare const ListAccountsResponseStruct: import("superstruct").Struct<{
41
41
  export declare type ListAccountsResponse = Infer<typeof ListAccountsResponseStruct>;
42
42
  export declare const GetAccountRequestStruct: import("superstruct").Struct<{
43
43
  jsonrpc: "2.0";
44
- id: string;
44
+ id: string | number | null;
45
45
  method: "keyring_getAccount";
46
46
  params: {
47
47
  id: string;
@@ -54,7 +54,7 @@ export declare const GetAccountRequestStruct: import("superstruct").Struct<{
54
54
  id: import("superstruct").Struct<string, null>;
55
55
  }>;
56
56
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
57
- id: import("superstruct").Struct<string, null>;
57
+ id: import("superstruct").Struct<string | number | null, null>;
58
58
  }>;
59
59
  export declare type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;
60
60
  export declare const GetAccountResponseStruct: import("superstruct").Struct<{
@@ -83,7 +83,7 @@ export declare const GetAccountResponseStruct: import("superstruct").Struct<{
83
83
  export declare type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;
84
84
  export declare const CreateAccountRequestStruct: import("superstruct").Struct<{
85
85
  jsonrpc: "2.0";
86
- id: string;
86
+ id: string | number | null;
87
87
  method: "keyring_createAccount";
88
88
  params: {
89
89
  options: Record<string, import("@metamask/utils").Json>;
@@ -96,7 +96,7 @@ export declare const CreateAccountRequestStruct: import("superstruct").Struct<{
96
96
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
97
97
  }>;
98
98
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
99
- id: import("superstruct").Struct<string, null>;
99
+ id: import("superstruct").Struct<string | number | null, null>;
100
100
  }>;
101
101
  export declare type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;
102
102
  export declare const CreateAccountResponseStruct: import("superstruct").Struct<{
@@ -125,7 +125,7 @@ export declare const CreateAccountResponseStruct: import("superstruct").Struct<{
125
125
  export declare type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;
126
126
  export declare const FilterAccountChainsStruct: import("superstruct").Struct<{
127
127
  jsonrpc: "2.0";
128
- id: string;
128
+ id: string | number | null;
129
129
  method: "keyring_filterAccountChains";
130
130
  params: {
131
131
  id: string;
@@ -141,14 +141,14 @@ export declare const FilterAccountChainsStruct: import("superstruct").Struct<{
141
141
  chains: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
142
142
  }>;
143
143
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
144
- id: import("superstruct").Struct<string, null>;
144
+ id: import("superstruct").Struct<string | number | null, null>;
145
145
  }>;
146
146
  export declare type FilterAccountChainsRequest = Infer<typeof FilterAccountChainsStruct>;
147
147
  export declare const FilterAccountChainsResponseStruct: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
148
148
  export declare type FilterAccountChainsResponse = Infer<typeof FilterAccountChainsResponseStruct>;
149
149
  export declare const UpdateAccountRequestStruct: import("superstruct").Struct<{
150
150
  jsonrpc: "2.0";
151
- id: string;
151
+ id: string | number | null;
152
152
  method: "keyring_updateAccount";
153
153
  params: {
154
154
  account: {
@@ -195,14 +195,14 @@ export declare const UpdateAccountRequestStruct: import("superstruct").Struct<{
195
195
  }>;
196
196
  }>;
197
197
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
198
- id: import("superstruct").Struct<string, null>;
198
+ id: import("superstruct").Struct<string | number | null, null>;
199
199
  }>;
200
200
  export declare type UpdateAccountRequest = Infer<typeof UpdateAccountRequestStruct>;
201
201
  export declare const UpdateAccountResponseStruct: import("superstruct").Struct<null, null>;
202
202
  export declare type UpdateAccountResponse = Infer<typeof UpdateAccountResponseStruct>;
203
203
  export declare const DeleteAccountRequestStruct: import("superstruct").Struct<{
204
204
  jsonrpc: "2.0";
205
- id: string;
205
+ id: string | number | null;
206
206
  method: "keyring_deleteAccount";
207
207
  params: {
208
208
  id: string;
@@ -215,14 +215,14 @@ export declare const DeleteAccountRequestStruct: import("superstruct").Struct<{
215
215
  id: import("superstruct").Struct<string, null>;
216
216
  }>;
217
217
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
218
- id: import("superstruct").Struct<string, null>;
218
+ id: import("superstruct").Struct<string | number | null, null>;
219
219
  }>;
220
220
  export declare type DeleteAccountRequest = Infer<typeof DeleteAccountRequestStruct>;
221
221
  export declare const DeleteAccountResponseStruct: import("superstruct").Struct<null, null>;
222
222
  export declare type DeleteAccountResponse = Infer<typeof DeleteAccountResponseStruct>;
223
223
  export declare const ExportAccountRequestStruct: import("superstruct").Struct<{
224
224
  jsonrpc: "2.0";
225
- id: string;
225
+ id: string | number | null;
226
226
  method: "keyring_exportAccount";
227
227
  params: {
228
228
  id: string;
@@ -235,19 +235,19 @@ export declare const ExportAccountRequestStruct: import("superstruct").Struct<{
235
235
  id: import("superstruct").Struct<string, null>;
236
236
  }>;
237
237
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
238
- id: import("superstruct").Struct<string, null>;
238
+ id: import("superstruct").Struct<string | number | null, null>;
239
239
  }>;
240
240
  export declare type ExportAccountRequest = Infer<typeof ExportAccountRequestStruct>;
241
241
  export declare const ExportAccountResponseStruct: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
242
242
  export declare type ExportAccountResponse = Infer<typeof ExportAccountResponseStruct>;
243
243
  export declare const ListRequestsRequestStruct: import("superstruct").Struct<{
244
244
  jsonrpc: "2.0";
245
- id: string;
245
+ id: string | number | null;
246
246
  method: "keyring_listRequests";
247
247
  }, {
248
248
  method: import("superstruct").Struct<"keyring_listRequests", "keyring_listRequests">;
249
249
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
250
- id: import("superstruct").Struct<string, null>;
250
+ id: import("superstruct").Struct<string | number | null, null>;
251
251
  }>;
252
252
  export declare type ListRequestsRequest = Infer<typeof ListRequestsRequestStruct>;
253
253
  export declare const ListRequestsResponseStruct: import("superstruct").Struct<{
@@ -281,7 +281,7 @@ export declare const ListRequestsResponseStruct: import("superstruct").Struct<{
281
281
  export declare type ListRequestsResponse = Infer<typeof ListRequestsResponseStruct>;
282
282
  export declare const GetRequestRequestStruct: import("superstruct").Struct<{
283
283
  jsonrpc: "2.0";
284
- id: string;
284
+ id: string | number | null;
285
285
  method: "keyring_getRequest";
286
286
  params: {
287
287
  id: string;
@@ -294,7 +294,7 @@ export declare const GetRequestRequestStruct: import("superstruct").Struct<{
294
294
  id: import("superstruct").Struct<string, null>;
295
295
  }>;
296
296
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
297
- id: import("superstruct").Struct<string, null>;
297
+ id: import("superstruct").Struct<string | number | null, null>;
298
298
  }>;
299
299
  export declare type GetRequestRequest = Infer<typeof GetRequestRequestStruct>;
300
300
  export declare const GetRequestResponseStruct: import("superstruct").Struct<{
@@ -320,7 +320,7 @@ export declare const GetRequestResponseStruct: import("superstruct").Struct<{
320
320
  export declare type GetRequestResponse = Infer<typeof GetRequestResponseStruct>;
321
321
  export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
322
322
  jsonrpc: "2.0";
323
- id: string;
323
+ id: string | number | null;
324
324
  method: "keyring_submitRequest";
325
325
  params: {
326
326
  id: string;
@@ -354,7 +354,7 @@ export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
354
354
  }>;
355
355
  }>;
356
356
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
357
- id: import("superstruct").Struct<string, null>;
357
+ id: import("superstruct").Struct<string | number | null, null>;
358
358
  }>;
359
359
  export declare type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;
360
360
  export declare const SubmitRequestResponseStruct: import("superstruct").Struct<{
@@ -370,7 +370,7 @@ export declare const SubmitRequestResponseStruct: import("superstruct").Struct<{
370
370
  export declare type SubmitRequestResponse = Infer<typeof SubmitRequestResponseStruct>;
371
371
  export declare const ApproveRequestRequestStruct: import("superstruct").Struct<{
372
372
  jsonrpc: "2.0";
373
- id: string;
373
+ id: string | number | null;
374
374
  method: "keyring_approveRequest";
375
375
  params: {
376
376
  id: string;
@@ -386,14 +386,14 @@ export declare const ApproveRequestRequestStruct: import("superstruct").Struct<{
386
386
  data: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
387
387
  }>;
388
388
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
389
- id: import("superstruct").Struct<string, null>;
389
+ id: import("superstruct").Struct<string | number | null, null>;
390
390
  }>;
391
391
  export declare type ApproveRequestRequest = Infer<typeof ApproveRequestRequestStruct>;
392
392
  export declare const ApproveRequestResponseStruct: import("superstruct").Struct<null, null>;
393
393
  export declare type ApproveRequestResponse = Infer<typeof ApproveRequestResponseStruct>;
394
394
  export declare const RejectRequestRequestStruct: import("superstruct").Struct<{
395
395
  jsonrpc: "2.0";
396
- id: string;
396
+ id: string | number | null;
397
397
  method: "keyring_rejectRequest";
398
398
  params: {
399
399
  id: string;
@@ -406,7 +406,7 @@ export declare const RejectRequestRequestStruct: import("superstruct").Struct<{
406
406
  id: import("superstruct").Struct<string, null>;
407
407
  }>;
408
408
  jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
409
- id: import("superstruct").Struct<string, null>;
409
+ id: import("superstruct").Struct<string | number | null, null>;
410
410
  }>;
411
411
  export declare type RejectRequestRequest = Infer<typeof RejectRequestRequestStruct>;
412
412
  export declare const RejectRequestResponseStruct: import("superstruct").Struct<null, null>;
@@ -7,7 +7,7 @@ const api_1 = require("../api");
7
7
  const utils_2 = require("../utils");
8
8
  const CommonHeader = {
9
9
  jsonrpc: (0, superstruct_1.literal)('2.0'),
10
- id: utils_2.UuidStruct,
10
+ id: (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)(), (0, superstruct_1.literal)(null)]),
11
11
  };
12
12
  // ----------------------------------------------------------------------------
13
13
  // List accounts
@@ -22,7 +22,7 @@ exports.GetAccountRequestStruct = (0, superstruct_1.object)({
22
22
  ...CommonHeader,
23
23
  method: (0, superstruct_1.literal)('keyring_getAccount'),
24
24
  params: (0, superstruct_1.object)({
25
- id: (0, superstruct_1.string)(),
25
+ id: utils_2.UuidStruct,
26
26
  }),
27
27
  });
28
28
  exports.GetAccountResponseStruct = api_1.KeyringAccountStruct;
@@ -42,7 +42,7 @@ exports.FilterAccountChainsStruct = (0, superstruct_1.object)({
42
42
  ...CommonHeader,
43
43
  method: (0, superstruct_1.literal)('keyring_filterAccountChains'),
44
44
  params: (0, superstruct_1.object)({
45
- id: (0, superstruct_1.string)(),
45
+ id: utils_2.UuidStruct,
46
46
  chains: (0, superstruct_1.array)((0, superstruct_1.string)()),
47
47
  }),
48
48
  });
@@ -63,7 +63,7 @@ exports.DeleteAccountRequestStruct = (0, superstruct_1.object)({
63
63
  ...CommonHeader,
64
64
  method: (0, superstruct_1.literal)('keyring_deleteAccount'),
65
65
  params: (0, superstruct_1.object)({
66
- id: (0, superstruct_1.string)(),
66
+ id: utils_2.UuidStruct,
67
67
  }),
68
68
  });
69
69
  exports.DeleteAccountResponseStruct = (0, superstruct_1.literal)(null);
@@ -73,7 +73,7 @@ exports.ExportAccountRequestStruct = (0, superstruct_1.object)({
73
73
  ...CommonHeader,
74
74
  method: (0, superstruct_1.literal)('keyring_exportAccount'),
75
75
  params: (0, superstruct_1.object)({
76
- id: (0, superstruct_1.string)(),
76
+ id: utils_2.UuidStruct,
77
77
  }),
78
78
  });
79
79
  exports.ExportAccountResponseStruct = api_1.KeyringAccountDataStruct;
@@ -90,7 +90,7 @@ exports.GetRequestRequestStruct = (0, superstruct_1.object)({
90
90
  ...CommonHeader,
91
91
  method: (0, superstruct_1.literal)('keyring_getRequest'),
92
92
  params: (0, superstruct_1.object)({
93
- id: (0, superstruct_1.string)(),
93
+ id: utils_2.UuidStruct,
94
94
  }),
95
95
  });
96
96
  exports.GetRequestResponseStruct = api_1.KeyringRequestStruct;
@@ -108,7 +108,7 @@ exports.ApproveRequestRequestStruct = (0, superstruct_1.object)({
108
108
  ...CommonHeader,
109
109
  method: (0, superstruct_1.literal)('keyring_approveRequest'),
110
110
  params: (0, superstruct_1.object)({
111
- id: (0, superstruct_1.string)(),
111
+ id: utils_2.UuidStruct,
112
112
  data: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
113
113
  }),
114
114
  });
@@ -119,7 +119,7 @@ exports.RejectRequestRequestStruct = (0, superstruct_1.object)({
119
119
  ...CommonHeader,
120
120
  method: (0, superstruct_1.literal)('keyring_rejectRequest'),
121
121
  params: (0, superstruct_1.object)({
122
- id: (0, superstruct_1.string)(),
122
+ id: utils_2.UuidStruct,
123
123
  }),
124
124
  });
125
125
  exports.RejectRequestResponseStruct = (0, superstruct_1.literal)(null);
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/internal/api.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAAqE;AAErE,gCAKgB;AAChB,oCAAsC;AAEtC,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,kBAAU;CACf,CAAC;AAEF,+EAA+E;AAC/E,gBAAgB;AAEH,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,sBAAsB,CAAC;CACxC,CAAC,CAAC;AAIU,QAAA,0BAA0B,GAAG,IAAA,mBAAK,EAAC,0BAAoB,CAAC,CAAC;AAItE,+EAA+E;AAC/E,cAAc;AAED,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IAC5C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,oBAAoB,CAAC;IACrC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,EAAE,EAAE,IAAA,oBAAM,GAAE;KACb,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,wBAAwB,GAAG,0BAAoB,CAAC;AAI7D,+EAA+E;AAC/E,iBAAiB;AAEJ,QAAA,0BAA0B,GAAG,IAAA,oBAAM,E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E,IAAA,oBAAM,EAAC;QACb,EAAE,EAAE,IAAA,oBAAM,GAAE;QACZ,IAAI,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;KACnC,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,4BAA4B,GAAG,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC;AAI1D,+EAA+E;AAC/E,iBAAiB;AAEJ,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,uBAAuB,CAAC;IACxC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,EAAE,EAAE,IAAA,oBAAM,GAAE;KACb,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,2BAA2B,GAAG,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, literal, object, record, string } from 'superstruct';\n\nimport {\n KeyringAccountDataStruct,\n KeyringAccountStruct,\n KeyringRequestStruct,\n KeyringResponseStruct,\n} from '../api';\nimport { UuidStruct } from '../utils';\n\nconst CommonHeader = {\n jsonrpc: literal('2.0'),\n id: UuidStruct,\n};\n\n// ----------------------------------------------------------------------------\n// List accounts\n\nexport const ListAccountsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listAccounts'),\n});\n\nexport type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;\n\nexport const ListAccountsResponseStruct = array(KeyringAccountStruct);\n\nexport type ListAccountsResponse = Infer<typeof ListAccountsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get account\n\nexport const GetAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;\n\nexport const GetAccountResponseStruct = KeyringAccountStruct;\n\nexport type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Create account\n\nexport const CreateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_createAccount'),\n params: object({\n options: record(string(), JsonStruct),\n }),\n});\n\nexport type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;\n\nexport const CreateAccountResponseStruct = KeyringAccountStruct;\n\nexport type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Filter account chains\n\nexport const FilterAccountChainsStruct = object({\n ...CommonHeader,\n method: literal('keyring_filterAccountChains'),\n params: object({\n id: string(),\n chains: array(string()),\n }),\n});\n\nexport type FilterAccountChainsRequest = Infer<\n typeof FilterAccountChainsStruct\n>;\n\nexport const FilterAccountChainsResponseStruct = array(string());\n\nexport type FilterAccountChainsResponse = Infer<\n typeof FilterAccountChainsResponseStruct\n>;\n\n// ----------------------------------------------------------------------------\n// Update account\n\nexport const UpdateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_updateAccount'),\n params: object({\n account: KeyringAccountStruct,\n }),\n});\n\nexport type UpdateAccountRequest = Infer<typeof UpdateAccountRequestStruct>;\n\nexport const UpdateAccountResponseStruct = literal(null);\n\nexport type UpdateAccountResponse = Infer<typeof UpdateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Delete account\n\nexport const DeleteAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_deleteAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type DeleteAccountRequest = Infer<typeof DeleteAccountRequestStruct>;\n\nexport const DeleteAccountResponseStruct = literal(null);\n\nexport type DeleteAccountResponse = Infer<typeof DeleteAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Export account\n\nexport const ExportAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_exportAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type ExportAccountRequest = Infer<typeof ExportAccountRequestStruct>;\n\nexport const ExportAccountResponseStruct = KeyringAccountDataStruct;\n\nexport type ExportAccountResponse = Infer<typeof ExportAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// List requests\n\nexport const ListRequestsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listRequests'),\n});\n\nexport type ListRequestsRequest = Infer<typeof ListRequestsRequestStruct>;\n\nexport const ListRequestsResponseStruct = array(KeyringRequestStruct);\n\nexport type ListRequestsResponse = Infer<typeof ListRequestsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get request\n\nexport const GetRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetRequestRequest = Infer<typeof GetRequestRequestStruct>;\n\nexport const GetRequestResponseStruct = KeyringRequestStruct;\n\nexport type GetRequestResponse = Infer<typeof GetRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Submit request\n\nexport const SubmitRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_submitRequest'),\n params: KeyringRequestStruct,\n});\n\nexport type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;\n\nexport const SubmitRequestResponseStruct = KeyringResponseStruct;\n\nexport type SubmitRequestResponse = Infer<typeof SubmitRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Approve request\n\nexport const ApproveRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_approveRequest'),\n params: object({\n id: string(),\n data: record(string(), JsonStruct),\n }),\n});\n\nexport type ApproveRequestRequest = Infer<typeof ApproveRequestRequestStruct>;\n\nexport const ApproveRequestResponseStruct = literal(null);\n\nexport type ApproveRequestResponse = Infer<typeof ApproveRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Reject request\n\nexport const RejectRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_rejectRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type RejectRequestRequest = Infer<typeof RejectRequestRequestStruct>;\n\nexport const RejectRequestResponseStruct = literal(null);\n\nexport type RejectRequestResponse = Infer<typeof RejectRequestResponseStruct>;\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/internal/api.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAQqB;AAErB,gCAKgB;AAChB,oCAAsC;AAEtC,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,+EAA+E;AAC/E,gBAAgB;AAEH,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,sBAAsB,CAAC;CACxC,CAAC,CAAC;AAIU,QAAA,0BAA0B,GAAG,IAAA,mBAAK,EAAC,0BAAoB,CAAC,CAAC;AAItE,+EAA+E;AAC/E,cAAc;AAED,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IAC5C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,oBAAoB,CAAC;IACrC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,EAAE,EAAE,kBAAU;KACf,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,wBAAwB,GAAG,0BAAoB,CAAC;AAI7D,+EAA+E;AAC/E,iBAAiB;AAEJ,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,uBAAuB,CAAC;IACxC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;KACtC,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,2BAA2B,GAAG,0BAAoB,CAAC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YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,uBAAuB,CAAC;IACxC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,EAAE,EAAE,kBAAU;KACf,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,2BAA2B,GAAG,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n literal,\n number,\n object,\n record,\n string,\n union,\n} from 'superstruct';\n\nimport {\n KeyringAccountDataStruct,\n KeyringAccountStruct,\n KeyringRequestStruct,\n KeyringResponseStruct,\n} from '../api';\nimport { UuidStruct } from '../utils';\n\nconst CommonHeader = {\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n};\n\n// ----------------------------------------------------------------------------\n// List accounts\n\nexport const ListAccountsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listAccounts'),\n});\n\nexport type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;\n\nexport const ListAccountsResponseStruct = array(KeyringAccountStruct);\n\nexport type ListAccountsResponse = Infer<typeof ListAccountsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get account\n\nexport const GetAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getAccount'),\n params: object({\n id: UuidStruct,\n }),\n});\n\nexport type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;\n\nexport const GetAccountResponseStruct = KeyringAccountStruct;\n\nexport type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Create account\n\nexport const CreateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_createAccount'),\n params: object({\n options: record(string(), JsonStruct),\n }),\n});\n\nexport type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;\n\nexport const CreateAccountResponseStruct = KeyringAccountStruct;\n\nexport type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Filter account chains\n\nexport const FilterAccountChainsStruct = object({\n ...CommonHeader,\n method: literal('keyring_filterAccountChains'),\n params: object({\n id: UuidStruct,\n chains: array(string()),\n }),\n});\n\nexport type FilterAccountChainsRequest = Infer<\n typeof FilterAccountChainsStruct\n>;\n\nexport const FilterAccountChainsResponseStruct = array(string());\n\nexport type FilterAccountChainsResponse = Infer<\n typeof FilterAccountChainsResponseStruct\n>;\n\n// ----------------------------------------------------------------------------\n// Update account\n\nexport const UpdateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_updateAccount'),\n params: object({\n account: KeyringAccountStruct,\n }),\n});\n\nexport type UpdateAccountRequest = Infer<typeof UpdateAccountRequestStruct>;\n\nexport const UpdateAccountResponseStruct = literal(null);\n\nexport type UpdateAccountResponse = Infer<typeof UpdateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Delete account\n\nexport const DeleteAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_deleteAccount'),\n params: object({\n id: UuidStruct,\n }),\n});\n\nexport type DeleteAccountRequest = Infer<typeof DeleteAccountRequestStruct>;\n\nexport const DeleteAccountResponseStruct = literal(null);\n\nexport type DeleteAccountResponse = Infer<typeof DeleteAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Export account\n\nexport const ExportAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_exportAccount'),\n params: object({\n id: UuidStruct,\n }),\n});\n\nexport type ExportAccountRequest = Infer<typeof ExportAccountRequestStruct>;\n\nexport const ExportAccountResponseStruct = KeyringAccountDataStruct;\n\nexport type ExportAccountResponse = Infer<typeof ExportAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// List requests\n\nexport const ListRequestsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listRequests'),\n});\n\nexport type ListRequestsRequest = Infer<typeof ListRequestsRequestStruct>;\n\nexport const ListRequestsResponseStruct = array(KeyringRequestStruct);\n\nexport type ListRequestsResponse = Infer<typeof ListRequestsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get request\n\nexport const GetRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getRequest'),\n params: object({\n id: UuidStruct,\n }),\n});\n\nexport type GetRequestRequest = Infer<typeof GetRequestRequestStruct>;\n\nexport const GetRequestResponseStruct = KeyringRequestStruct;\n\nexport type GetRequestResponse = Infer<typeof GetRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Submit request\n\nexport const SubmitRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_submitRequest'),\n params: KeyringRequestStruct,\n});\n\nexport type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;\n\nexport const SubmitRequestResponseStruct = KeyringResponseStruct;\n\nexport type SubmitRequestResponse = Infer<typeof SubmitRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Approve request\n\nexport const ApproveRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_approveRequest'),\n params: object({\n id: UuidStruct,\n data: record(string(), JsonStruct),\n }),\n});\n\nexport type ApproveRequestRequest = Infer<typeof ApproveRequestRequestStruct>;\n\nexport const ApproveRequestResponseStruct = literal(null);\n\nexport type ApproveRequestResponse = Infer<typeof ApproveRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Reject request\n\nexport const RejectRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_rejectRequest'),\n params: object({\n id: UuidStruct,\n }),\n});\n\nexport type RejectRequestRequest = Infer<typeof RejectRequestRequestStruct>;\n\nexport const RejectRequestResponseStruct = literal(null);\n\nexport type RejectRequestResponse = Infer<typeof RejectRequestResponseStruct>;\n"]}
@@ -1,3 +1,4 @@
1
1
  export * from './api';
2
2
  export * from './events';
3
+ export * from './rpc';
3
4
  export * from './types';
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api"), exports);
18
18
  __exportStar(require("./events"), exports);
19
+ __exportStar(require("./rpc"), exports);
19
20
  __exportStar(require("./types"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,2CAAyB;AACzB,0CAAwB","sourcesContent":["export * from './api';\nexport * from './events';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,2CAAyB;AACzB,wCAAsB;AACtB,0CAAwB","sourcesContent":["export * from './api';\nexport * from './events';\nexport * from './rpc';\nexport * from './types';\n"]}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Keyring RPC methods used by the API.
3
+ */
4
+ export declare enum KeyringRpcMethod {
5
+ ListAccounts = "keyring_listAccounts",
6
+ GetAccount = "keyring_getAccount",
7
+ CreateAccount = "keyring_createAccount",
8
+ FilterAccountChains = "keyring_filterAccountChains",
9
+ UpdateAccount = "keyring_updateAccount",
10
+ DeleteAccount = "keyring_deleteAccount",
11
+ ExportAccount = "keyring_exportAccount",
12
+ ListRequests = "keyring_listRequests",
13
+ GetRequest = "keyring_getRequest",
14
+ SubmitRequest = "keyring_submitRequest",
15
+ ApproveRequest = "keyring_approveRequest",
16
+ RejectRequest = "keyring_rejectRequest"
17
+ }
18
+ /**
19
+ * Check if a method is a keyring RPC method.
20
+ *
21
+ * @param method - Method to check.
22
+ * @returns Whether the method is a keyring RPC method.
23
+ */
24
+ export declare function isKeyringRpcMethod(method: string): boolean;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isKeyringRpcMethod = exports.KeyringRpcMethod = void 0;
4
+ /**
5
+ * Keyring RPC methods used by the API.
6
+ */
7
+ var KeyringRpcMethod;
8
+ (function (KeyringRpcMethod) {
9
+ KeyringRpcMethod["ListAccounts"] = "keyring_listAccounts";
10
+ KeyringRpcMethod["GetAccount"] = "keyring_getAccount";
11
+ KeyringRpcMethod["CreateAccount"] = "keyring_createAccount";
12
+ KeyringRpcMethod["FilterAccountChains"] = "keyring_filterAccountChains";
13
+ KeyringRpcMethod["UpdateAccount"] = "keyring_updateAccount";
14
+ KeyringRpcMethod["DeleteAccount"] = "keyring_deleteAccount";
15
+ KeyringRpcMethod["ExportAccount"] = "keyring_exportAccount";
16
+ KeyringRpcMethod["ListRequests"] = "keyring_listRequests";
17
+ KeyringRpcMethod["GetRequest"] = "keyring_getRequest";
18
+ KeyringRpcMethod["SubmitRequest"] = "keyring_submitRequest";
19
+ KeyringRpcMethod["ApproveRequest"] = "keyring_approveRequest";
20
+ KeyringRpcMethod["RejectRequest"] = "keyring_rejectRequest";
21
+ })(KeyringRpcMethod = exports.KeyringRpcMethod || (exports.KeyringRpcMethod = {}));
22
+ /**
23
+ * Check if a method is a keyring RPC method.
24
+ *
25
+ * @param method - Method to check.
26
+ * @returns Whether the method is a keyring RPC method.
27
+ */
28
+ function isKeyringRpcMethod(method) {
29
+ return Object.values(KeyringRpcMethod).includes(method);
30
+ }
31
+ exports.isKeyringRpcMethod = isKeyringRpcMethod;
32
+ //# sourceMappingURL=rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/internal/rpc.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,gBAaX;AAbD,WAAY,gBAAgB;IAC1B,yDAAqC,CAAA;IACrC,qDAAiC,CAAA;IACjC,2DAAuC,CAAA;IACvC,uEAAmD,CAAA;IACnD,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,yDAAqC,CAAA;IACrC,qDAAiC,CAAA;IACjC,2DAAuC,CAAA;IACvC,6DAAyC,CAAA;IACzC,2DAAuC,CAAA;AACzC,CAAC,EAbW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAa3B;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAc;IAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,MAA0B,CAAC,CAAC;AAC9E,CAAC;AAFD,gDAEC","sourcesContent":["/**\n * Keyring RPC methods used by the API.\n */\nexport enum KeyringRpcMethod {\n ListAccounts = 'keyring_listAccounts',\n GetAccount = 'keyring_getAccount',\n CreateAccount = 'keyring_createAccount',\n FilterAccountChains = 'keyring_filterAccountChains',\n UpdateAccount = 'keyring_updateAccount',\n DeleteAccount = 'keyring_deleteAccount',\n ExportAccount = 'keyring_exportAccount',\n ListRequests = 'keyring_listRequests',\n GetRequest = 'keyring_getRequest',\n SubmitRequest = 'keyring_submitRequest',\n ApproveRequest = 'keyring_approveRequest',\n RejectRequest = 'keyring_rejectRequest',\n}\n\n/**\n * Check if a method is a keyring RPC method.\n *\n * @param method - Method to check.\n * @returns Whether the method is a keyring RPC method.\n */\nexport function isKeyringRpcMethod(method: string): boolean {\n return Object.values(KeyringRpcMethod).includes(method as KeyringRpcMethod);\n}\n"]}
@@ -7,20 +7,6 @@ import type { JsonRpcRequest } from './JsonRpcRequest';
7
7
  export declare class MethodNotSupportedError extends Error {
8
8
  constructor(method: string);
9
9
  }
10
- export declare enum KeyringRpcMethod {
11
- ListAccounts = "keyring_listAccounts",
12
- GetAccount = "keyring_getAccount",
13
- CreateAccount = "keyring_createAccount",
14
- FilterAccountChains = "keyring_filterAccountChains",
15
- UpdateAccount = "keyring_updateAccount",
16
- DeleteAccount = "keyring_deleteAccount",
17
- ExportAccount = "keyring_exportAccount",
18
- ListRequests = "keyring_listRequests",
19
- GetRequest = "keyring_getRequest",
20
- SubmitRequest = "keyring_submitRequest",
21
- ApproveRequest = "keyring_approveRequest",
22
- RejectRequest = "keyring_rejectRequest"
23
- }
24
10
  /**
25
11
  * Handles a keyring JSON-RPC request.
26
12
  *
@@ -29,10 +15,3 @@ export declare enum KeyringRpcMethod {
29
15
  * @returns A promise that resolves to the keyring response.
30
16
  */
31
17
  export declare function handleKeyringRequest(keyring: Keyring, request: JsonRpcRequest): Promise<Json | void>;
32
- /**
33
- * Check if a method is a keyring RPC method.
34
- *
35
- * @param method - Method to check.
36
- * @returns Whether the method is a keyring RPC method.
37
- */
38
- export declare function isKeyringRpcMethod(method: string): boolean;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isKeyringRpcMethod = exports.handleKeyringRequest = exports.KeyringRpcMethod = exports.MethodNotSupportedError = void 0;
3
+ exports.handleKeyringRequest = exports.MethodNotSupportedError = void 0;
4
4
  const superstruct_1 = require("superstruct");
5
5
  const api_1 = require("./internal/api");
6
+ const rpc_1 = require("./internal/rpc");
6
7
  const JsonRpcRequest_1 = require("./JsonRpcRequest");
7
8
  /**
8
9
  * Error thrown when a keyring JSON-RPC method is not supported.
@@ -13,21 +14,6 @@ class MethodNotSupportedError extends Error {
13
14
  }
14
15
  }
15
16
  exports.MethodNotSupportedError = MethodNotSupportedError;
16
- var KeyringRpcMethod;
17
- (function (KeyringRpcMethod) {
18
- KeyringRpcMethod["ListAccounts"] = "keyring_listAccounts";
19
- KeyringRpcMethod["GetAccount"] = "keyring_getAccount";
20
- KeyringRpcMethod["CreateAccount"] = "keyring_createAccount";
21
- KeyringRpcMethod["FilterAccountChains"] = "keyring_filterAccountChains";
22
- KeyringRpcMethod["UpdateAccount"] = "keyring_updateAccount";
23
- KeyringRpcMethod["DeleteAccount"] = "keyring_deleteAccount";
24
- KeyringRpcMethod["ExportAccount"] = "keyring_exportAccount";
25
- KeyringRpcMethod["ListRequests"] = "keyring_listRequests";
26
- KeyringRpcMethod["GetRequest"] = "keyring_getRequest";
27
- KeyringRpcMethod["SubmitRequest"] = "keyring_submitRequest";
28
- KeyringRpcMethod["ApproveRequest"] = "keyring_approveRequest";
29
- KeyringRpcMethod["RejectRequest"] = "keyring_rejectRequest";
30
- })(KeyringRpcMethod = exports.KeyringRpcMethod || (exports.KeyringRpcMethod = {}));
31
17
  /**
32
18
  * Handles a keyring JSON-RPC request.
33
19
  *
@@ -40,63 +26,63 @@ async function handleKeyringRequest(keyring, request) {
40
26
  // we can check its method name.
41
27
  (0, superstruct_1.assert)(request, JsonRpcRequest_1.JsonRpcRequestStruct);
42
28
  switch (request.method) {
43
- case KeyringRpcMethod.ListAccounts: {
29
+ case rpc_1.KeyringRpcMethod.ListAccounts: {
44
30
  (0, superstruct_1.assert)(request, api_1.ListAccountsRequestStruct);
45
31
  return keyring.listAccounts();
46
32
  }
47
- case KeyringRpcMethod.GetAccount: {
33
+ case rpc_1.KeyringRpcMethod.GetAccount: {
48
34
  (0, superstruct_1.assert)(request, api_1.GetAccountRequestStruct);
49
35
  return keyring.getAccount(request.params.id);
50
36
  }
51
- case KeyringRpcMethod.CreateAccount: {
37
+ case rpc_1.KeyringRpcMethod.CreateAccount: {
52
38
  (0, superstruct_1.assert)(request, api_1.CreateAccountRequestStruct);
53
39
  return keyring.createAccount(request.params.options);
54
40
  }
55
- case KeyringRpcMethod.FilterAccountChains: {
41
+ case rpc_1.KeyringRpcMethod.FilterAccountChains: {
56
42
  (0, superstruct_1.assert)(request, api_1.FilterAccountChainsStruct);
57
43
  return keyring.filterAccountChains(request.params.id, request.params.chains);
58
44
  }
59
- case KeyringRpcMethod.UpdateAccount: {
45
+ case rpc_1.KeyringRpcMethod.UpdateAccount: {
60
46
  (0, superstruct_1.assert)(request, api_1.UpdateAccountRequestStruct);
61
47
  return keyring.updateAccount(request.params.account);
62
48
  }
63
- case KeyringRpcMethod.DeleteAccount: {
49
+ case rpc_1.KeyringRpcMethod.DeleteAccount: {
64
50
  (0, superstruct_1.assert)(request, api_1.DeleteAccountRequestStruct);
65
51
  return keyring.deleteAccount(request.params.id);
66
52
  }
67
- case KeyringRpcMethod.ExportAccount: {
53
+ case rpc_1.KeyringRpcMethod.ExportAccount: {
68
54
  if (keyring.exportAccount === undefined) {
69
55
  throw new MethodNotSupportedError(request.method);
70
56
  }
71
57
  (0, superstruct_1.assert)(request, api_1.ExportAccountRequestStruct);
72
58
  return keyring.exportAccount(request.params.id);
73
59
  }
74
- case KeyringRpcMethod.ListRequests: {
60
+ case rpc_1.KeyringRpcMethod.ListRequests: {
75
61
  if (keyring.listRequests === undefined) {
76
62
  throw new MethodNotSupportedError(request.method);
77
63
  }
78
64
  (0, superstruct_1.assert)(request, api_1.ListRequestsRequestStruct);
79
65
  return keyring.listRequests();
80
66
  }
81
- case KeyringRpcMethod.GetRequest: {
67
+ case rpc_1.KeyringRpcMethod.GetRequest: {
82
68
  if (keyring.getRequest === undefined) {
83
69
  throw new MethodNotSupportedError(request.method);
84
70
  }
85
71
  (0, superstruct_1.assert)(request, api_1.GetRequestRequestStruct);
86
72
  return keyring.getRequest(request.params.id);
87
73
  }
88
- case KeyringRpcMethod.SubmitRequest: {
74
+ case rpc_1.KeyringRpcMethod.SubmitRequest: {
89
75
  (0, superstruct_1.assert)(request, api_1.SubmitRequestRequestStruct);
90
76
  return keyring.submitRequest(request.params);
91
77
  }
92
- case KeyringRpcMethod.ApproveRequest: {
78
+ case rpc_1.KeyringRpcMethod.ApproveRequest: {
93
79
  if (keyring.approveRequest === undefined) {
94
80
  throw new MethodNotSupportedError(request.method);
95
81
  }
96
82
  (0, superstruct_1.assert)(request, api_1.ApproveRequestRequestStruct);
97
83
  return keyring.approveRequest(request.params.id, request.params.data);
98
84
  }
99
- case KeyringRpcMethod.RejectRequest: {
85
+ case rpc_1.KeyringRpcMethod.RejectRequest: {
100
86
  if (keyring.rejectRequest === undefined) {
101
87
  throw new MethodNotSupportedError(request.method);
102
88
  }
@@ -109,14 +95,4 @@ async function handleKeyringRequest(keyring, request) {
109
95
  }
110
96
  }
111
97
  exports.handleKeyringRequest = handleKeyringRequest;
112
- /**
113
- * Check if a method is a keyring RPC method.
114
- *
115
- * @param method - Method to check.
116
- * @returns Whether the method is a keyring RPC method.
117
- */
118
- function isKeyringRpcMethod(method) {
119
- return Object.values(KeyringRpcMethod).includes(method);
120
- }
121
- exports.isKeyringRpcMethod = isKeyringRpcMethod;
122
98
  //# sourceMappingURL=rpc-handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AACA,6CAAqC;AAGrC,wCAawB;AAExB,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,IAAY,gBAaX;AAbD,WAAY,gBAAgB;IAC1B,yDAAqC,CAAA;IACrC,qDAAiC,CAAA;IACjC,2DAAuC,CAAA;IACvC,uEAAmD,CAAA;IACnD,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,yDAAqC,CAAA;IACrC,qDAAiC,CAAA;IACjC,2DAAuC,CAAA;IACvC,6DAAyC,CAAA;IACzC,2DAAuC,CAAA;AACzC,CAAC,EAbW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAa3B;AAED;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,OAAgB,EAChB,OAAuB;IAEvB,6EAA6E;IAC7E,gCAAgC;IAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,qCAAoB,CAAC,CAAC;IAEtC,QAAQ,OAAO,CAAC,MAAM,EAAE;QACtB,KAAK,gBAAgB,CAAC,YAAY,CAAC,CAAC;YAClC,IAAA,oBAAM,EAAC,OAAO,EAAE,+BAAyB,CAAC,CAAC;YAC3C,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC;SAC/B;QAED,KAAK,gBAAgB,CAAC,UAAU,CAAC,CAAC;YAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,6BAAuB,CAAC,CAAC;YACzC,OAAO,OAAO,CAA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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;AA3FD,oDA2FC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAc;IAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,MAA0B,CAAC,CAAC;AAC9E,CAAC;AAFD,gDAEC","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} from './internal/api';\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\nexport enum KeyringRpcMethod {\n ListAccounts = 'keyring_listAccounts',\n GetAccount = 'keyring_getAccount',\n CreateAccount = 'keyring_createAccount',\n FilterAccountChains = 'keyring_filterAccountChains',\n UpdateAccount = 'keyring_updateAccount',\n DeleteAccount = 'keyring_deleteAccount',\n ExportAccount = 'keyring_exportAccount',\n ListRequests = 'keyring_listRequests',\n GetRequest = 'keyring_getRequest',\n SubmitRequest = 'keyring_submitRequest',\n ApproveRequest = 'keyring_approveRequest',\n RejectRequest = 'keyring_rejectRequest',\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nexport async function handleKeyringRequest(\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.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 * Check if a method is a keyring RPC method.\n *\n * @param method - Method to check.\n * @returns Whether the method is a keyring RPC method.\n */\nexport function isKeyringRpcMethod(method: string): boolean {\n return Object.values(KeyringRpcMethod).includes(method as KeyringRpcMethod);\n}\n"]}
1
+ {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AACA,6CAAqC;AAGrC,wCAawB;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;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,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,CA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AC;YACP,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACnD;KACF;AACH,CAAC;AA3FD,oDA2FC","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} 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 * Handles a keyring JSON-RPC request.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nexport async function handleKeyringRequest(\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.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"]}
@@ -1,4 +1,4 @@
1
- import type { SnapsGlobalObject } from '@metamask/rpc-methods';
1
+ import type { SnapsGlobalObject } from '@metamask/snaps-rpc-methods';
2
2
  import type { Json } from '@metamask/utils';
3
3
  import type { KeyringEvent } from './events';
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"snap-utils.js","sourceRoot":"","sources":["../src/snap-utils.ts"],"names":[],"mappings":";;;AAKA;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,IAAuB,EACvB,KAAmB,EACnB,IAA0B;IAE1B,MAAM,IAAI,CAAC,OAAO,CAAC;QACjB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE;SACpB;KACF,CAAC,CAAC;AACL,CAAC;AAZD,oDAYC","sourcesContent":["import type { SnapsGlobalObject } from '@metamask/rpc-methods';\nimport type { Json } from '@metamask/utils';\n\nimport type { KeyringEvent } from './events';\n\n/**\n * Emit a keyring event from a snap.\n *\n * @param snap - The global snap object.\n * @param event - The event name.\n * @param data - The event data.\n */\nexport async function emitSnapKeyringEvent(\n snap: SnapsGlobalObject,\n event: KeyringEvent,\n data: Record<string, Json>,\n): Promise<void> {\n await snap.request({\n method: 'snap_manageAccounts',\n params: {\n method: event,\n params: { ...data },\n },\n });\n}\n"]}
1
+ {"version":3,"file":"snap-utils.js","sourceRoot":"","sources":["../src/snap-utils.ts"],"names":[],"mappings":";;;AAKA;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,IAAuB,EACvB,KAAmB,EACnB,IAA0B;IAE1B,MAAM,IAAI,CAAC,OAAO,CAAC;QACjB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE;SACpB;KACF,CAAC,CAAC;AACL,CAAC;AAZD,oDAYC","sourcesContent":["import type { SnapsGlobalObject } from '@metamask/snaps-rpc-methods';\nimport type { Json } from '@metamask/utils';\n\nimport type { KeyringEvent } from './events';\n\n/**\n * Emit a keyring event from a snap.\n *\n * @param snap - The global snap object.\n * @param event - The event name.\n * @param data - The event data.\n */\nexport async function emitSnapKeyringEvent(\n snap: SnapsGlobalObject,\n event: KeyringEvent,\n data: Record<string, Json>,\n): Promise<void> {\n await snap.request({\n method: 'snap_manageAccounts',\n params: {\n method: event,\n params: { ...data },\n },\n });\n}\n"]}
package/dist/utils.js CHANGED
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.strictMask = exports.UuidStruct = void 0;
4
4
  const superstruct_1 = require("superstruct");
5
+ const UUID_V4_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
5
6
  /**
6
7
  * UUIDv4 struct.
7
8
  */
8
- exports.UuidStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu);
9
+ exports.UuidStruct = (0, superstruct_1.define)('UuidV4', (id) => typeof id === 'string' && UUID_V4_REGEX.test(id));
9
10
  /**
10
11
  * Assert that a value is valid according to a struct.
11
12
  *
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAGtD;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,qBAAO,EAC/B,IAAA,oBAAM,GAAE,EACR,yEAAyE,CAC1E,CAAC;AAcF;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import { assert, pattern, string } from 'superstruct';\nimport type { Struct } from 'superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = pattern(\n string(),\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAG7C,MAAM,aAAa,GACjB,yEAAyE,CAAC;AAE5E;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,oBAAM,EAC9B,QAAQ,EACR,CAAC,EAAW,EAAW,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAC3E,CAAC;AAcF;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import { assert, define } from 'superstruct';\nimport type { Struct } from 'superstruct';\n\nconst UUID_V4_REGEX =\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = define<string>(\n 'UuidV4',\n (id: unknown): boolean => typeof id === 'string' && UUID_V4_REGEX.test(id),\n);\n\n/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "1.0.0-rc.1",
3
+ "version": "1.1.0",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",
@@ -39,8 +39,8 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@metamask/providers": "^13.0.0",
42
- "@metamask/rpc-methods": "^3.0.0",
43
- "@metamask/snaps-controllers": "^3.0.0",
42
+ "@metamask/snaps-controllers": "^3.1.0",
43
+ "@metamask/snaps-rpc-methods": "^3.1.0",
44
44
  "@metamask/snaps-utils": "^3.0.0",
45
45
  "@metamask/utils": "^8.1.0",
46
46
  "@types/uuid": "^9.0.1",
@@ -90,8 +90,8 @@
90
90
  "lavamoat": {
91
91
  "allowScripts": {
92
92
  "@lavamoat/preinstall-always-fail": false,
93
- "@metamask/rpc-methods>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
94
- "@metamask/rpc-methods>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false
93
+ "@metamask/snaps-utils>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
94
+ "@metamask/snaps-utils>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false
95
95
  }
96
96
  },
97
97
  "tsd": {