@metamask/keyring-api 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.md +38 -34
  3. package/dist/KeyringClient.js +13 -13
  4. package/dist/KeyringClient.js.map +1 -1
  5. package/dist/KeyringSnapControllerClient.d.ts +3 -2
  6. package/dist/KeyringSnapControllerClient.js.map +1 -1
  7. package/dist/api.d.ts +13 -7
  8. package/dist/api.js +10 -2
  9. package/dist/api.js.map +1 -1
  10. package/dist/eth/erc4337/index.d.ts +1 -0
  11. package/dist/eth/erc4337/index.js +18 -0
  12. package/dist/eth/erc4337/index.js.map +1 -0
  13. package/dist/eth/erc4337/types.d.ts +90 -0
  14. package/dist/eth/erc4337/types.js +58 -0
  15. package/dist/eth/erc4337/types.js.map +1 -0
  16. package/dist/eth/index.d.ts +2 -0
  17. package/dist/eth/index.js +19 -0
  18. package/dist/eth/index.js.map +1 -0
  19. package/dist/eth/types.d.ts +3 -0
  20. package/dist/eth/types.js +8 -0
  21. package/dist/eth/types.js.map +1 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +1 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/internal/api.d.ts +62 -50
  26. package/dist/internal/api.js +8 -8
  27. package/dist/internal/api.js.map +1 -1
  28. package/dist/internal/eth/EthKeyring.d.ts +29 -0
  29. package/dist/internal/eth/EthKeyring.js +3 -0
  30. package/dist/internal/eth/EthKeyring.js.map +1 -0
  31. package/dist/internal/eth/index.d.ts +1 -0
  32. package/dist/internal/eth/index.js +18 -0
  33. package/dist/internal/eth/index.js.map +1 -0
  34. package/dist/internal/events.d.ts +30 -20
  35. package/dist/internal/index.d.ts +2 -0
  36. package/dist/internal/index.js +2 -0
  37. package/dist/internal/index.js.map +1 -1
  38. package/dist/internal/rpc.d.ts +24 -0
  39. package/dist/internal/rpc.js +32 -0
  40. package/dist/internal/rpc.js.map +1 -0
  41. package/dist/internal/types.d.ts +8 -5
  42. package/dist/rpc-handler.d.ts +0 -21
  43. package/dist/rpc-handler.js +14 -38
  44. package/dist/rpc-handler.js.map +1 -1
  45. package/dist/snap-utils.d.ts +2 -2
  46. package/dist/snap-utils.js.map +1 -1
  47. package/dist/superstruct.d.ts +14 -0
  48. package/dist/superstruct.js +18 -1
  49. package/dist/superstruct.js.map +1 -1
  50. package/dist/utils.js +2 -1
  51. package/dist/utils.js.map +1 -1
  52. package/package.json +7 -7
  53. package/dist/superstruct.test-d.d.ts +0 -1
  54. package/dist/superstruct.test-d.js +0 -17
  55. package/dist/superstruct.test-d.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.0]
11
+
12
+ ### Added
13
+
14
+ - **BREAKING**: Add support for ERC-4337 transactions ([#213](https://github.com/MetaMask/keyring-api/pull/213))
15
+ - Enum `EthMethods` has been extended with `eth_prepareUserOperation`, `eth_patchUserOperation`, `eth_signUserOperation`
16
+ - Enum `EthAccountType` has been extended with `eip155:erc4337`
17
+
18
+ ### Changed
19
+
20
+ - **BREAKING**: Update `@metamask/providers` from `^13.0.0` to `^14.0.1` ([#209](https://github.com/MetaMask/keyring-api/pull/209))
21
+ - Consolidation on `readable-stream@^3.6.2`. Users should upgrade to `extension-port-stream@^3.0.0` and `json-rpc-middleware-stream@^5.0.0`.
22
+ - Replace deprecated `@metamask/snaps-ui` with `@metamask/snaps-sdk` ([#204](https://github.com/MetaMask/keyring-api/pull/204))
23
+ - Replace `@metamask/snaps-rpc-methods` with `@metamask/snaps-sdk`
24
+ - Update `@metamask/snaps-controllers` and `@metamask/snaps-utils` to versions that don't rely on `@metamask/snaps-ui`
25
+ - Documentation updates ([#185](https://github.com/MetaMask/keyring-api/pull/185)) ([#201](https://github.com/MetaMask/keyring-api/pull/201))
26
+
27
+ ### Removed
28
+
29
+ - **BREAKING** `EthAccountType.Eip4337` has been removed. `eip155:eip4337` should be replaced with `erc:4337`
30
+
31
+ ### Fixed
32
+
33
+ - Exclude `*.test-d.ts` files from builds ([#184](https://github.com/MetaMask/keyring-api/pull/184))
34
+ - Remove `@metamask/snaps-ui` from dependency tree ([#204](https://github.com/MetaMask/keyring-api/pull/204))
35
+
36
+ ## [1.1.0]
37
+
38
+ ### Changed
39
+
40
+ - `UuidStruct` is now a named type ([#159](https://github.com/MetaMask/keyring-api/pull/159))
41
+ - Migrate from `@metamask/rpc-methods` to `@metamask/snaps-rpc-methods` ([#175](https://github.com/MetaMask/keyring-api/pull/175))
42
+
43
+ ### Fixed
44
+
45
+ - Allow the request ID to be a string, number or null ([#156](https://github.com/MetaMask/keyring-api/pull/156))
46
+ - 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))
47
+ - Use `UuidStruct` for IDs in the internal API ([#158](https://github.com/MetaMask/keyring-api/pull/158))
48
+ - Bump `@metamask/json-rpc-engine` from `^7.1.1` to `^7.2.0` ([#164](https://github.com/MetaMask/keyring-api/pull/164))
49
+
10
50
  ## [1.0.0]
11
51
 
12
52
  ### Added
@@ -148,7 +188,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
148
188
  - SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
149
189
  - Helper functions to create keyring handler in the snap.
150
190
 
151
- [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v1.0.0...HEAD
191
+ [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v2.0.0...HEAD
192
+ [2.0.0]: https://github.com/MetaMask/keyring-api/compare/v1.1.0...v2.0.0
193
+ [1.1.0]: https://github.com/MetaMask/keyring-api/compare/v1.0.0...v1.1.0
152
194
  [1.0.0]: https://github.com/MetaMask/keyring-api/compare/v1.0.0-rc.1...v1.0.0
153
195
  [1.0.0-rc.1]: https://github.com/MetaMask/keyring-api/compare/v0.2.7...v1.0.0-rc.1
154
196
  [0.2.7]: https://github.com/MetaMask/keyring-api/compare/v0.2.6...v0.2.7
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # MetaMask Keyring API
2
2
 
3
- > This TypeScript module is maintained in the style of the MetaMask team.
4
-
5
3
  This TypeScript module simplifies the integration of Snaps with MetaMask using
6
4
  the Keyring API.
7
5
 
@@ -12,41 +10,47 @@ 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
13
+ communicate with the account Snap. This client allows dapps to send requests
16
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
+ ```
37
+
38
+ ## Account Snaps
35
39
 
36
- ## Keyring Snaps
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).
37
43
 
38
- Starting with MetaMask 11.5, Snaps can implement the Keyring API. This allows
44
+ Starting with MetaMask 11.4, Snaps can implement the Keyring API. This allows
39
45
  users to manage their accounts in a more flexible way, and enables developers
40
46
  to build new types of accounts.
41
47
 
42
- > [!IMPORTANT]
43
- > Before implementing your Snap, please make sure to read the [security
44
- > recommendations](./docs/security.md) and the [architecture
45
- > document](./docs/architecture.md).
48
+ > :pencil2: **Note:** You can also build MetaMask from [source][extension-repo]
49
+ > from the `develop` branch.
46
50
 
47
51
  Follow these steps to implement the Keyring API in your Snap. Please note that
48
52
  these instruction assume that you are already familiar with the process of
49
- [developing a Snap](https://docs.metamask.io/).
53
+ [developing a Snap](https://docs.metamask.io/snaps/).
50
54
 
51
55
  1. **Implement the Keyring API:**
52
56
 
@@ -58,15 +62,14 @@ these instruction assume that you are already familiar with the process of
58
62
  }
59
63
  ```
60
64
 
61
- > [!WARNING]
62
- > Ensure that your keyring implements the [methods called by
63
- > MetaMask](./docs/security.md#limit-the-methods-exposed-to-dapps),
64
- > otherwise some features may not work.
65
+ > :point_up: **Important**: Ensure that your keyring implements the [methods
66
+ > called by MetaMask][exposed-methods], otherwise some features may not
67
+ > work.
65
68
 
66
69
  2. **Handle requests submitted by MetaMask:**
67
70
 
68
71
  MetaMask will submit requests through the `submitRequest` method of your the
69
- Keyring API (check the supported [EVM methods](./docs/evm_methods.md)). Here
72
+ Keyring API (check the supported [EVM methods](./docs/evm-methods.md)). Here
70
73
  is an example of request:
71
74
 
72
75
  ```json
@@ -175,9 +178,8 @@ these instruction assume that you are already familiar with the process of
175
178
 
176
179
  MetaMask will return an error if the request does not exist.
177
180
 
178
- > [!NOTE]
179
- > This only applies to Snaps that implement the [async
180
- > flow](./docs/architecture.md#transaction-flow).
181
+ > :pencil2: **Note:** This only applies to Snaps that implement the
182
+ > [asynchronous transaction flow][async-flow].
181
183
 
182
184
  5. When a request is rejected:
183
185
 
@@ -194,9 +196,8 @@ these instruction assume that you are already familiar with the process of
194
196
 
195
197
  MetaMask will return an error if the request does not exist.
196
198
 
197
- > [!NOTE]
198
- > This only applies to Snaps that implement the [async
199
- > flow](./docs/architecture.md#transaction-flow).
199
+ > :pencil2: **Note:** This only applies to Snaps that implement the
200
+ > [asynchronous transaction flow][async-flow].
200
201
 
201
202
  4. **Expose the Keyring API:**
202
203
 
@@ -214,7 +215,7 @@ these instruction assume that you are already familiar with the process of
214
215
 
215
216
  5. **Call the keyring methods from your dapp:**
216
217
 
217
- Now you should be able to call your Keyring Snap from your dapp, for
218
+ Now you should be able to call your account Snap from your dapp, for
218
219
  example:
219
220
 
220
221
  ```typescript
@@ -282,15 +283,14 @@ implementation:
282
283
  emitSnapKeyringEvent(snap, KeyringEvent.RequestRejected, { id: request.id });
283
284
  ```
284
285
 
285
- > [!IMPORTANT]
286
- > For all events above, MetaMask may return an error indicating that the
287
- > 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.
288
289
 
289
- - Keyrings that implement the [async transaction
290
- flow](./docs/architecture.md#transaction-flow) can now return an optional
291
- `redirect` property that contains an URL and a message to be displayed to the
292
- user. This will, in a future release of MetaMask, be used to inform the user
293
- 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.
294
294
 
295
295
  ```ts
296
296
  return {
@@ -395,3 +395,7 @@ The project follows the same release process as the other libraries in the MetaM
395
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.
396
396
  - Approve the `publish-npm` job (or ask somebody on the npm publishers team to approve it for you).
397
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,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,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,8BAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;I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d,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":";;;;;;;;;;;;;;;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C,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,4 +1,5 @@
1
1
  import type { SnapController } from '@metamask/snaps-controllers';
2
+ import type { SnapId } from '@metamask/snaps-sdk';
2
3
  import type { HandlerType } from '@metamask/snaps-utils';
3
4
  import { KeyringClient } from './KeyringClient';
4
5
  /**
@@ -22,7 +23,7 @@ export declare class KeyringSnapControllerClient extends KeyringClient {
22
23
  */
23
24
  constructor({ controller, snapId, origin, handler, }: {
24
25
  controller: SnapController;
25
- snapId?: string;
26
+ snapId?: SnapId;
26
27
  origin?: string;
27
28
  handler?: HandlerType;
28
29
  });
@@ -34,7 +35,7 @@ export declare class KeyringSnapControllerClient extends KeyringClient {
34
35
  * @returns A new instance of `KeyringSnapControllerClient` with the
35
36
  * specified snap ID.
36
37
  */
37
- withSnapId(snapId: string): KeyringSnapControllerClient;
38
+ withSnapId(snapId: SnapId): KeyringSnapControllerClient;
38
39
  /**
39
40
  * Get the `SnapController` instance used by this client.
40
41
  *
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringSnapControllerClient.js","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mDAA6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cesContent":["import type { SnapController } from '@metamask/snaps-controllers';\nimport type { HandlerType, ValidatedSnapId } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { KeyringClient, type Sender } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through a `SnapController`.\n */\nclass SnapControllerSender implements Sender {\n #snapId: string;\n\n #origin: string;\n\n #controller: SnapController;\n\n #handler: HandlerType;\n\n /**\n * Create a new instance of `SnapControllerSender`.\n *\n * @param controller - The `SnapController` instance to send requests to.\n * @param snapId - The ID of the snap to use.\n * @param origin - The sender's origin.\n * @param handler - The handler type.\n */\n constructor(\n controller: any,\n snapId: string,\n origin: string,\n handler: HandlerType,\n ) {\n this.#controller = controller;\n this.#snapId = snapId;\n this.#origin = origin;\n this.#handler = handler;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#controller.handleRequest({\n snapId: this.#snapId as ValidatedSnapId,\n origin: this.#origin,\n handler: this.#handler,\n request,\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the\n * `SnapController`.\n */\nexport class KeyringSnapControllerClient extends KeyringClient {\n #controller: SnapController;\n\n /**\n * Create a new instance of `KeyringSnapControllerClient`.\n *\n * The `handlerType` argument has a hard-coded default `string` value instead\n * of a `HandlerType` value to prevent the `@metamask/snaps-utils` module\n * from being required at runtime.\n *\n * @param args - Constructor arguments.\n * @param args.controller - The `SnapController` instance to use.\n * @param args.snapId - The ID of the snap to use (default: `'undefined'`).\n * @param args.origin - The sender's origin (default: `'metamask'`).\n * @param args.handler - The handler type (default: `'onKeyringRequest'`).\n */\n constructor({\n controller,\n snapId = 'undefined',\n origin = 'metamask',\n handler = 'onKeyringRequest' as HandlerType,\n }: {\n controller: SnapController;\n snapId?: string;\n origin?: string;\n handler?: HandlerType;\n }) {\n super(new SnapControllerSender(controller, snapId, origin, handler));\n this.#controller = controller;\n }\n\n /**\n * Create a new instance of `KeyringSnapControllerClient` with the specified\n * `snapId`.\n *\n * @param snapId - The ID of the snap to use in the new instance.\n * @returns A new instance of `KeyringSnapControllerClient` with the\n * specified snap ID.\n */\n withSnapId(snapId: string): KeyringSnapControllerClient {\n return new KeyringSnapControllerClient({\n controller: this.#controller,\n snapId,\n });\n }\n\n /**\n * Get the `SnapController` instance used by this client.\n *\n * @returns The `SnapController` instance used by this client.\n */\n getController(): SnapController {\n return this.#controller;\n }\n}\n"]}
1
+ {"version":3,"file":"KeyringSnapControllerClient.js","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,mDAA6D;AAE7D;;;GAGG;AACH,MAAM,oBAAoB;IASxB;;;;;;;OAOG;IACH,YACE,UAAe,EACf,MAAc,EACd,MAAc,EACd,OAAoB;QApBtB,+CAAgB;QAEhB,+CAAgB;QAEhB,mDAA4B;QAE5B,gDAAsB;QAgBpB,uBAAA,IAAI,oCAAe,UAAU,MAAA,CAAC;QAC9B,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,wCAAY,CAAC,aAAa,CAAC;YACpC,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,OAAO,EAAE,uBAAA,IAAI,qCAAS;YACtB,OAAO;SACR,CAAkB,CAAC;IACtB,CAAC;CACF;;AAED;;;GAGG;AACH,MAAa,2BAA4B,SAAQ,6BAAa;IAG5D;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,UAAU,EACV,MAAM,GAAG,WAAqB,EAC9B,MAAM,GAAG,UAAU,EACnB,OAAO,GAAG,kBAAiC,GAM5C;QACC,KAAK,CAAC,IAAI,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QA1BvE,0DAA4B;QA2B1B,uBAAA,IAAI,2CAAe,UAAU,MAAA,CAAC;IAChC,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAC,MAAc;QACvB,OAAO,IAAI,2BAA2B,CAAC;YACrC,UAAU,EAAE,uBAAA,IAAI,+CAAY;YAC5B,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,OAAO,uBAAA,IAAI,+CAAY,CAAC;IAC1B,CAAC;CACF;AAtDD,kEAsDC","sourcesContent":["import type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { KeyringClient, type Sender } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through a `SnapController`.\n */\nclass SnapControllerSender implements Sender {\n #snapId: SnapId;\n\n #origin: string;\n\n #controller: SnapController;\n\n #handler: HandlerType;\n\n /**\n * Create a new instance of `SnapControllerSender`.\n *\n * @param controller - The `SnapController` instance to send requests to.\n * @param snapId - The ID of the snap to use.\n * @param origin - The sender's origin.\n * @param handler - The handler type.\n */\n constructor(\n controller: any,\n snapId: SnapId,\n origin: string,\n handler: HandlerType,\n ) {\n this.#controller = controller;\n this.#snapId = snapId;\n this.#origin = origin;\n this.#handler = handler;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#controller.handleRequest({\n snapId: this.#snapId,\n origin: this.#origin,\n handler: this.#handler,\n request,\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the\n * `SnapController`.\n */\nexport class KeyringSnapControllerClient extends KeyringClient {\n #controller: SnapController;\n\n /**\n * Create a new instance of `KeyringSnapControllerClient`.\n *\n * The `handlerType` argument has a hard-coded default `string` value instead\n * of a `HandlerType` value to prevent the `@metamask/snaps-utils` module\n * from being required at runtime.\n *\n * @param args - Constructor arguments.\n * @param args.controller - The `SnapController` instance to use.\n * @param args.snapId - The ID of the snap to use (default: `'undefined'`).\n * @param args.origin - The sender's origin (default: `'metamask'`).\n * @param args.handler - The handler type (default: `'onKeyringRequest'`).\n */\n constructor({\n controller,\n snapId = 'undefined' as SnapId,\n origin = 'metamask',\n handler = 'onKeyringRequest' as HandlerType,\n }: {\n controller: SnapController;\n snapId?: SnapId;\n origin?: string;\n handler?: HandlerType;\n }) {\n super(new SnapControllerSender(controller, snapId, origin, handler));\n this.#controller = controller;\n }\n\n /**\n * Create a new instance of `KeyringSnapControllerClient` with the specified\n * `snapId`.\n *\n * @param snapId - The ID of the snap to use in the new instance.\n * @returns A new instance of `KeyringSnapControllerClient` with the\n * specified snap ID.\n */\n withSnapId(snapId: SnapId): KeyringSnapControllerClient {\n return new KeyringSnapControllerClient({\n controller: this.#controller,\n snapId,\n });\n }\n\n /**\n * Get the `SnapController` instance used by this client.\n *\n * @returns The `SnapController` instance used by this client.\n */\n getController(): SnapController {\n return this.#controller;\n }\n}\n"]}
package/dist/api.d.ts CHANGED
@@ -9,21 +9,24 @@ export declare enum EthMethod {
9
9
  SignTransaction = "eth_signTransaction",
10
10
  SignTypedDataV1 = "eth_signTypedData_v1",
11
11
  SignTypedDataV3 = "eth_signTypedData_v3",
12
- SignTypedDataV4 = "eth_signTypedData_v4"
12
+ SignTypedDataV4 = "eth_signTypedData_v4",
13
+ PrepareUserOperation = "eth_prepareUserOperation",
14
+ PatchUserOperation = "eth_patchUserOperation",
15
+ SignUserOperation = "eth_signUserOperation"
13
16
  }
14
17
  /**
15
18
  * Supported Ethereum account types.
16
19
  */
17
20
  export declare enum EthAccountType {
18
21
  Eoa = "eip155:eoa",
19
- Eip4337 = "eip155:eip4337"
22
+ Erc4337 = "eip155:erc4337"
20
23
  }
21
24
  export declare const KeyringAccountStruct: import("superstruct").Struct<{
22
- type: "eip155:eoa" | "eip155:eip4337";
25
+ type: "eip155:eoa" | "eip155:erc4337";
23
26
  id: string;
24
27
  address: string;
25
28
  options: Record<string, Json>;
26
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
29
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
27
30
  }, {
28
31
  /**
29
32
  * Account ID (UUIDv4).
@@ -40,20 +43,23 @@ export declare const KeyringAccountStruct: import("superstruct").Struct<{
40
43
  /**
41
44
  * Account supported methods.
42
45
  */
43
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
46
+ methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
44
47
  personal_sign: "personal_sign";
45
48
  eth_sign: "eth_sign";
46
49
  eth_signTransaction: "eth_signTransaction";
47
50
  eth_signTypedData_v1: "eth_signTypedData_v1";
48
51
  eth_signTypedData_v3: "eth_signTypedData_v3";
49
52
  eth_signTypedData_v4: "eth_signTypedData_v4";
53
+ eth_prepareUserOperation: "eth_prepareUserOperation";
54
+ eth_patchUserOperation: "eth_patchUserOperation";
55
+ eth_signUserOperation: "eth_signUserOperation";
50
56
  }>>;
51
57
  /**
52
58
  * Account type.
53
59
  */
54
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:eip4337", {
60
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
55
61
  "eip155:eoa": "eip155:eoa";
56
- "eip155:eip4337": "eip155:eip4337";
62
+ "eip155:erc4337": "eip155:erc4337";
57
63
  }>;
58
64
  }>;
59
65
  /**
package/dist/api.js CHANGED
@@ -10,12 +10,17 @@ const utils_2 = require("./utils");
10
10
  */
11
11
  var EthMethod;
12
12
  (function (EthMethod) {
13
+ // General signing methods
13
14
  EthMethod["PersonalSign"] = "personal_sign";
14
15
  EthMethod["Sign"] = "eth_sign";
15
16
  EthMethod["SignTransaction"] = "eth_signTransaction";
16
17
  EthMethod["SignTypedDataV1"] = "eth_signTypedData_v1";
17
18
  EthMethod["SignTypedDataV3"] = "eth_signTypedData_v3";
18
19
  EthMethod["SignTypedDataV4"] = "eth_signTypedData_v4";
20
+ // ERC-4337 methods
21
+ EthMethod["PrepareUserOperation"] = "eth_prepareUserOperation";
22
+ EthMethod["PatchUserOperation"] = "eth_patchUserOperation";
23
+ EthMethod["SignUserOperation"] = "eth_signUserOperation";
19
24
  })(EthMethod = exports.EthMethod || (exports.EthMethod = {}));
20
25
  /**
21
26
  * Supported Ethereum account types.
@@ -23,7 +28,7 @@ var EthMethod;
23
28
  var EthAccountType;
24
29
  (function (EthAccountType) {
25
30
  EthAccountType["Eoa"] = "eip155:eoa";
26
- EthAccountType["Eip4337"] = "eip155:eip4337";
31
+ EthAccountType["Erc4337"] = "eip155:erc4337";
27
32
  })(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
28
33
  exports.KeyringAccountStruct = (0, superstruct_2.object)({
29
34
  /**
@@ -48,11 +53,14 @@ exports.KeyringAccountStruct = (0, superstruct_2.object)({
48
53
  `${EthMethod.SignTypedDataV1}`,
49
54
  `${EthMethod.SignTypedDataV3}`,
50
55
  `${EthMethod.SignTypedDataV4}`,
56
+ `${EthMethod.PrepareUserOperation}`,
57
+ `${EthMethod.PatchUserOperation}`,
58
+ `${EthMethod.SignUserOperation}`,
51
59
  ])),
52
60
  /**
53
61
  * Account type.
54
62
  */
55
- type: (0, superstruct_1.enums)([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),
63
+ type: (0, superstruct_1.enums)([`${EthAccountType.Eoa}`, `${EthAccountType.Erc4337}`]),
56
64
  });
57
65
  exports.KeyringRequestStruct = (0, superstruct_2.object)({
58
66
  /**
package/dist/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAE7C,6CAA2E;AAE3E,+CAAsD;AACtD,mCAAqC;AAErC;;GAEG;AACH,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;AAC1C,CAAC,EAPW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAOpB;AAED;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAEY,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,GAAE;IAEjB;;OAEG;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AMG;QACH,QAAQ,EAAE,IAAA,2BAAa,EACrB,IAAA,oBAAM,EAAC;YACL,OAAO,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;YAChC,GAAG,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;SAC7B,CAAC,CACH;KACF,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, enums, literal, record, string, union } from 'superstruct';\n\nimport { exactOptional, object } from './superstruct';\nimport { UuidStruct } from './utils';\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Eip4337 = 'eip155:eip4337',\n}\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),\n});\n\n/**\n * Account object.\n *\n * Represents an account with its properties and capabilities.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n\nexport const KeyringRequestStruct = object({\n /**\n * Keyring request ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Inner request sent by the client application.\n */\n request: object({\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n }),\n});\n\n/**\n * Keyring request.\n *\n * Represents a request made to the keyring for account-related operations.\n */\nexport type KeyringRequest = Infer<typeof KeyringRequestStruct>;\n\nexport const KeyringAccountDataStruct = record(string(), JsonStruct);\n\n/**\n * Response to a call to `exportAccount`.\n *\n * The exact response depends on the keyring implementation.\n */\nexport type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;\n\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: exactOptional(\n object({\n message: exactOptional(string()),\n url: exactOptional(string()),\n }),\n ),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL and message\n * to be shown to the user. The user can choose to follow the link or cancel\n * the request. The main use case for this is to redirect the user to the snap\n * dapp to review the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAE7C,6CAA2E;AAE3E,+CAAsD;AACtD,mCAAqC;AAErC;;GAEG;AACH,IAAY,SAYX;AAZD,WAAY,SAAS;IACnB,0BAA0B;IAC1B,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,mBAAmB;IACnB,8DAAiD,CAAA;IACjD,0DAA6C,CAAA;IAC7C,wDAA2C,CAAA;AAC7C,CAAC,EAZW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAYpB;AAED;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAEY,QAA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,CAAC,CAAC;AASU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC;AASxD,QAAA,qBAAqB,GAAG,IAAA,mBAAK,EAAC;IACzC,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC;QAEtB;;;;;;WAMG;QACH,QAAQ,EAAE,IAAA,2BAAa,EACrB,IAAA,oBAAM,EAAC;YACL,OAAO,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;YAChC,GAAG,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;SAC7B,CAAC,CACH;KACF,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, enums, literal, record, string, union } from 'superstruct';\n\nimport { exactOptional, object } from './superstruct';\nimport { UuidStruct } from './utils';\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n // General signing methods\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n // ERC-4337 methods\n PrepareUserOperation = 'eth_prepareUserOperation',\n PatchUserOperation = 'eth_patchUserOperation',\n SignUserOperation = 'eth_signUserOperation',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Erc4337 = 'eip155:erc4337',\n}\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n `${EthMethod.PrepareUserOperation}`,\n `${EthMethod.PatchUserOperation}`,\n `${EthMethod.SignUserOperation}`,\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums([`${EthAccountType.Eoa}`, `${EthAccountType.Erc4337}`]),\n});\n\n/**\n * Account object.\n *\n * Represents an account with its properties and capabilities.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n\nexport const KeyringRequestStruct = object({\n /**\n * Keyring request ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Inner request sent by the client application.\n */\n request: object({\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n }),\n});\n\n/**\n * Keyring request.\n *\n * Represents a request made to the keyring for account-related operations.\n */\nexport type KeyringRequest = Infer<typeof KeyringRequestStruct>;\n\nexport const KeyringAccountDataStruct = record(string(), JsonStruct);\n\n/**\n * Response to a call to `exportAccount`.\n *\n * The exact response depends on the keyring implementation.\n */\nexport type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;\n\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: exactOptional(\n object({\n message: exactOptional(string()),\n url: exactOptional(string()),\n }),\n ),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL and message\n * to be shown to the user. The user can choose to follow the link or cancel\n * the request. The main use case for this is to redirect the user to the snap\n * dapp to review the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
@@ -0,0 +1 @@
1
+ export * from './types';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/eth/erc4337/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB","sourcesContent":["export * from './types';\n"]}