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

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
@@ -1,4 +1,5 @@
1
1
  # Changelog
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -6,32 +7,54 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
7
 
7
8
  ## [Unreleased]
8
9
 
10
+ ## [1.0.0-rc.1]
11
+
12
+ ### Added
13
+
14
+ - Document how to migrate from API 0.1.x to 0.2.x ([#124](https://github.com/MetaMask/keyring-api/pull/124)).
15
+
16
+ ### Changed
17
+
18
+ - **BREAKING:** Use the `onKeyringRequest` snap export ([#145](https://github.com/MetaMask/keyring-api/pull/145)).
19
+ - **BREAKING:** Change the events' prefix to `notify:` ([#139](https://github.com/MetaMask/keyring-api/pull/139)).
20
+
9
21
  ## [0.2.7]
22
+
10
23
  ### Added
24
+
11
25
  - Export events types ([#125](https://github.com/MetaMask/keyring-api/pull/125))
12
26
 
13
27
  ## [0.2.6]
28
+
14
29
  ### Changed
30
+
15
31
  - Remove unused lavamoat allowed scripts ([#122](https://github.com/MetaMask/keyring-api/pull/122)).
16
32
  - Update events in sequence diagram ([#121](https://github.com/MetaMask/keyring-api/pull/121)).
17
33
  - Update Snap and ESLint dependencies ([#117](https://github.com/MetaMask/keyring-api/pull/117)).
18
34
  - Bump @metamask/rpc-methods from 0.38.1-flask.1 to 2.0.0 ([#120](https://github.com/MetaMask/keyring-api/pull/120)).
19
35
 
20
36
  ## [0.2.5]
37
+
21
38
  ### Changed
39
+
22
40
  - Remove `buildHandlersChain` ([#114](https://github.com/MetaMask/keyring-api/pull/114)).
23
41
  - Update doc for `eth_signTransaction` ([#111](https://github.com/MetaMask/keyring-api/pull/111)).
24
42
  - Remove un-versioned `eth_signTypedData` method ([#113](https://github.com/MetaMask/keyring-api/pull/113)).
25
43
 
26
44
  ## [0.2.4]
45
+
27
46
  ### Changed
47
+
28
48
  - Fix linting and compatibility with older `tsc` ([#108](https://github.com/MetaMask/keyring-api/pull/108)).
29
49
 
30
50
  ## [0.2.3]
51
+
31
52
  ### Added
53
+
32
54
  - Add redirection message to snap async response ([#102](https://github.com/MetaMask/keyring-api/pull/102)).
33
55
 
34
56
  ### Changed
57
+
35
58
  - Use `Omit` instead of `OmitUnion` ([#106](https://github.com/MetaMask/keyring-api/pull/106)).
36
59
  - Update `KeyringResponse` comment ([#103](https://github.com/MetaMask/keyring-api/pull/103)).
37
60
  - Use `KeyringRpcMethod` enum instead of string ([#105](https://github.com/MetaMask/keyring-api/pull/105)).
@@ -41,21 +64,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
41
64
  - Bump @metamask/providers from 11.1.1 to 11.1.2 ([#98](https://github.com/MetaMask/keyring-api/pull/98)).
42
65
 
43
66
  ## [0.2.2]
67
+
44
68
  ### Added
69
+
45
70
  - Add architecture and EVM methods docs ([#86](https://github.com/MetaMask/keyring-api/pull/86)).
46
71
  - Add `lastSelected` and `lastActive` to metadata ([#92](https://github.com/MetaMask/keyring-api/pull/92)).
47
72
 
48
73
  ### Changed
74
+
49
75
  - Make request `params` optional ([#96](https://github.com/MetaMask/keyring-api/pull/96)).
50
76
  - Remove `lastActive` field from internal account model ([#95](https://github.com/MetaMask/keyring-api/pull/95)).
51
77
  - Move request ID to outer request ([#94](https://github.com/MetaMask/keyring-api/pull/94)).
52
78
 
53
79
  ## [0.2.1]
80
+
54
81
  ### Changed
82
+
55
83
  - Set `snap` object keys to be mandatory and move `name` to `metadata` ([#87](https://github.com/MetaMask/keyring-api/pull/87)).
56
84
 
57
85
  ## [0.2.0]
86
+
58
87
  ### Added
88
+
59
89
  - Add `InternalAccount` type and create submodule `internal` ([#65](https://github.com/MetaMask/keyring-api/pull/65)).
60
90
  - Add keyring events and helper functions ([#74](https://github.com/MetaMask/keyring-api/pull/74)).
61
91
  - Add a `redirect` field to asynchronous request responses ([#75](https://github.com/MetaMask/keyring-api/pull/75)).
@@ -63,6 +93,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
63
93
  - Add `getController` to client ([#43](https://github.com/MetaMask/keyring-api/pull/43)).
64
94
 
65
95
  ### Changed
96
+
66
97
  - Rename `erc4337` -> `eip4337` ([#42](https://github.com/MetaMask/keyring-api/pull/42)).
67
98
  - Make `options` a mandatory field of `KeyringAccount` ([#30](https://github.com/MetaMask/keyring-api/pull/30)).
68
99
  - Make `approveRequest` and `rejectRequest` optional ([#63](https://github.com/MetaMask/keyring-api/pull/63)).
@@ -74,29 +105,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
74
105
  - Rename `supportedMethods` to `methods` ([#35](https://github.com/MetaMask/keyring-api/pull/35)).
75
106
 
76
107
  ## [0.1.3]
108
+
77
109
  ### Changed
110
+
78
111
  - Downgrade snaps dependencies to `0.35.2-flask.1` ([#25](https://github.com/MetaMask/keyring-api/pull/25)).
79
112
 
80
113
  ## [0.1.2]
114
+
81
115
  ### Changed
116
+
82
117
  - Update snaps dependencies ([#21](https://github.com/MetaMask/keyring-api/pull/21)).
83
118
 
84
119
  ## [0.1.1]
120
+
85
121
  ### Added
122
+
86
123
  - Validate snap responses for type correctness ([#15](https://github.com/MetaMask/keyring-api/pull/15)).
87
124
 
88
125
  ### Changed
126
+
89
127
  - Rename RPC handling functions ([#16](https://github.com/MetaMask/keyring-api/pull/16)).
90
128
 
91
129
  ## [0.1.0] - 2023-06-20
130
+
92
131
  ### Added
132
+
93
133
  - Usage examples to [`README.md`](./README.md).
94
134
  - Keyring API definition.
95
- - JSON-RPC snap keyring client. It is intended to be used by a snap's companion dApp to send requests to the snap.
135
+ - JSON-RPC snap keyring client. It is intended to be used by a snap's companion dapp to send requests to the snap.
96
136
  - SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
97
137
  - Helper functions to create keyring handler in the snap.
98
138
 
99
- [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v0.2.7...HEAD
139
+ [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v1.0.0-rc.1...HEAD
140
+ [1.0.0-rc.1]: https://github.com/MetaMask/keyring-api/compare/v0.2.7...v1.0.0-rc.1
100
141
  [0.2.7]: https://github.com/MetaMask/keyring-api/compare/v0.2.6...v0.2.7
101
142
  [0.2.6]: https://github.com/MetaMask/keyring-api/compare/v0.2.5...v0.2.6
102
143
  [0.2.5]: https://github.com/MetaMask/keyring-api/compare/v0.2.4...v0.2.5
package/README.md CHANGED
@@ -11,8 +11,8 @@ Features:
11
11
  Keyring API. Snaps can implement this interface to seamlessly interact with
12
12
  MetaMask and leverage its functionality.
13
13
 
14
- - **DApp Client**: The module includes a client that enables dApps to
15
- communicate with the Keyring snap. This client allows dApps to send requests
14
+ - **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
16
  to the snap, such as retrieving account information or submitting requests.
17
17
 
18
18
  - **MetaMask Client**: The module provides a client specifically designed for
@@ -23,7 +23,7 @@ Features:
23
23
  - **Request Handler Helper Functions**: The module offers a set of helper
24
24
  functions to simplify the implementation of the request handler in the
25
25
  Keyring snap. These functions assist in processing incoming requests,
26
- validating data, and handling various request types from dApps and MetaMask.
26
+ validating data, and handling various request types from dapps and MetaMask.
27
27
 
28
28
  ## Installation
29
29
 
@@ -80,6 +80,106 @@ export const onRpcRequest: OnRpcRequestHandler = chainHandlers(
80
80
  );
81
81
  ```
82
82
 
83
+ ### Migrating from API 0.1.x to 0.2.x
84
+
85
+ The following changes were made to the API, which may require changes to your
86
+ implementation:
87
+
88
+ - In the `KeyringAccount` type, the `supportedMethods` property was renamed to
89
+ `methods`.
90
+
91
+ ```diff
92
+ - supportedMethods: string[];
93
+ + methods: string[];
94
+ ```
95
+
96
+ - In the `KeyringAccount` type, the `name` property was removed.
97
+
98
+ ```diff
99
+ - name: string;
100
+ ```
101
+
102
+ - In the `KeyringAccount` type, add the `options` property can no longer be
103
+ null.
104
+
105
+ ```diff
106
+ - options: Record<string, unknown> | null;
107
+ + options: Record<string, unknown>;
108
+ ```
109
+
110
+ - In the `KeyringAccount` type, the `eth_signTypedData` method was removed from
111
+ the list of available methods.
112
+
113
+ ```diff
114
+ - 'eth_signTypedData',
115
+ ```
116
+
117
+ It was an alias for the `eth_signTypedData_v1` method, which is still
118
+ present.
119
+
120
+ - Snaps should now use the `emitSnapKeyringEvent()` helper function to notify
121
+ MetaMask about events:
122
+
123
+ ```ts
124
+ // Emit an event to indicate that an account was created.
125
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountCreated, { account });
126
+
127
+ // Emit an event to indicate that an account was updated.
128
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountUpdated, { account });
129
+
130
+ // Emit an event to indicate that an account was deleted.
131
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountDeleted, { id: account.id });
132
+
133
+ // Emit an event to indicate that a request was approved.
134
+ emitSnapKeyringEvent(snap, KeyringEvent.RequestApproved, {
135
+ id: request.id,
136
+ result,
137
+ });
138
+
139
+ // Emit an event to indicate that a request was rejected.
140
+ emitSnapKeyringEvent(snap, KeyringEvent.RequestRejected, { id: request.id });
141
+ ```
142
+
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.
146
+
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.
152
+
153
+ ```ts
154
+ return {
155
+ pending: true,
156
+ redirect: {
157
+ message: 'Please go to the Snap Dapp to finish sining the transaction.',
158
+ url: 'https://example.com/sign?tx=1234',
159
+ },
160
+ };
161
+ ```
162
+
163
+ - The `buildHandlersChain` helper function was removed from the API. Instead,
164
+ you must implement your own handler. For example:
165
+
166
+ ```ts
167
+ export const onRpcRequest: OnRpcRequestHandler = async ({
168
+ request,
169
+ origin,
170
+ }) => {
171
+ // Check if origin is allowed to call the method.
172
+ if (!hasPermission(origin, request.method)) {
173
+ throw new Error(
174
+ `Origin '${origin}' is not allowed to call '${request.method}'`,
175
+ );
176
+ }
177
+
178
+ // Dispatch the request to the keyring.
179
+ return handleKeyringRequest(keyring, request);
180
+ };
181
+ ```
182
+
83
183
  ## API
84
184
 
85
185
  See our documentation:
@@ -124,7 +224,7 @@ The project follows the same release process as the other libraries in the MetaM
124
224
  - Generally any changes that don't affect consumers of the package (e.g. lockfile changes or development environment changes) are omitted. Exceptions may be made for changes that might be of interest despite not having an effect upon the published package (e.g. major test improvements, security improvements, improved documentation, etc.).
125
225
  - Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
126
226
  - Consolidate related changes into one change entry if it makes it easier to explain.
127
- - Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.
227
+ - Run `yarn auto-changelog validate --prettier --rc` to check that the changelog is correctly formatted.
128
228
 
129
229
  5. Review and QA the release.
130
230
 
@@ -18,7 +18,7 @@ export declare class KeyringSnapControllerClient extends KeyringClient {
18
18
  * @param args.controller - The `SnapController` instance to use.
19
19
  * @param args.snapId - The ID of the snap to use (default: `'undefined'`).
20
20
  * @param args.origin - The sender's origin (default: `'metamask'`).
21
- * @param args.handler - The handler type (default: `'onRpcRequest'`).
21
+ * @param args.handler - The handler type (default: `'onKeyringRequest'`).
22
22
  */
23
23
  constructor({ controller, snapId, origin, handler, }: {
24
24
  controller: SnapController;
@@ -69,9 +69,9 @@ class KeyringSnapControllerClient extends KeyringClient_1.KeyringClient {
69
69
  * @param args.controller - The `SnapController` instance to use.
70
70
  * @param args.snapId - The ID of the snap to use (default: `'undefined'`).
71
71
  * @param args.origin - The sender's origin (default: `'metamask'`).
72
- * @param args.handler - The handler type (default: `'onRpcRequest'`).
72
+ * @param args.handler - The handler type (default: `'onKeyringRequest'`).
73
73
  */
74
- constructor({ controller, snapId = 'undefined', origin = 'metamask', handler = 'onRpcRequest', }) {
74
+ constructor({ controller, snapId = 'undefined', origin = 'metamask', handler = 'onKeyringRequest', }) {
75
75
  super(new SnapControllerSender(controller, snapId, origin, handler));
76
76
  _KeyringSnapControllerClient_controller.set(this, void 0);
77
77
  __classPrivateFieldSet(this, _KeyringSnapControllerClient_controller, controller, "f");
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringSnapControllerClient.js","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,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,oCAA2B;YACvC,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,WAAW,EACpB,MAAM,GAAG,UAAU,EACnB,OAAO,GAAG,cAA6B,GAMxC;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 { 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: `'onRpcRequest'`).\n */\n constructor({\n controller,\n snapId = 'undefined',\n origin = 'metamask',\n handler = 'onRpcRequest' 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":";;;;;;;;;;;;;;;AAKA,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,oCAA2B;YACvC,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,WAAW,EACpB,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 { 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"]}
@@ -39,7 +39,7 @@ class SnapRpcSender {
39
39
  */
40
40
  async send(request) {
41
41
  return __classPrivateFieldGet(this, _SnapRpcSender_provider, "f").request({
42
- method: 'wallet_invokeSnap',
42
+ method: 'wallet_invokeKeyring',
43
43
  params: {
44
44
  snapId: __classPrivateFieldGet(this, _SnapRpcSender_origin, "f"),
45
45
  request,
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringSnapRpcClient.js","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mDAAgD;AAEhD;;;GAGG;AACH,MAAa,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAV5D,wCAAgB;QAEhB,0CAAkC;QAShC,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2BAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,+BAAU,CAAC,OAAO,CAAC;YAC5B,MAAM,EAAE,mBAAmB;YAC3B,MAAM,EAAE;gBACN,MAAM,EAAE,uBAAA,IAAI,6BAAQ;gBACpB,OAAO;aACR;SACF,CAAkB,CAAC;IACtB,CAAC;CACF;AA/BD,sCA+BC;;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,6BAAa;IACrD;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAC1D,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAVD,oDAUC","sourcesContent":["import type { MetaMaskInpageProvider } from '@metamask/providers';\nimport type { Json } from '@metamask/utils';\n\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport type { Sender } from './KeyringClient';\nimport { KeyringClient } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through the snap JSON-RPC API.\n */\nexport class SnapRpcSender implements Sender {\n #origin: string;\n\n #provider: MetaMaskInpageProvider;\n\n /**\n * Create a new instance of `SnapRpcSender`.\n *\n * @param origin - The caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n this.#origin = origin;\n this.#provider = provider;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - The 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.#provider.request({\n method: 'wallet_invokeSnap',\n params: {\n snapId: this.#origin,\n request,\n },\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the snap\n * JSON-RPC API.\n */\nexport class KeyringSnapRpcClient extends KeyringClient {\n /**\n * Create a new instance of `KeyringSnapRpcClient`.\n *\n * @param origin - Caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n super(new SnapRpcSender(origin, provider));\n }\n}\n"]}
1
+ {"version":3,"file":"KeyringSnapRpcClient.js","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mDAAgD;AAEhD;;;GAGG;AACH,MAAa,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAV5D,wCAAgB;QAEhB,0CAAkC;QAShC,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2BAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,+BAAU,CAAC,OAAO,CAAC;YAC5B,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,MAAM,EAAE,uBAAA,IAAI,6BAAQ;gBACpB,OAAO;aACR;SACF,CAAkB,CAAC;IACtB,CAAC;CACF;AA/BD,sCA+BC;;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,6BAAa;IACrD;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAC1D,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAVD,oDAUC","sourcesContent":["import type { MetaMaskInpageProvider } from '@metamask/providers';\nimport type { Json } from '@metamask/utils';\n\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport type { Sender } from './KeyringClient';\nimport { KeyringClient } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through the snap JSON-RPC API.\n */\nexport class SnapRpcSender implements Sender {\n #origin: string;\n\n #provider: MetaMaskInpageProvider;\n\n /**\n * Create a new instance of `SnapRpcSender`.\n *\n * @param origin - The caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n this.#origin = origin;\n this.#provider = provider;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - The 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.#provider.request({\n method: 'wallet_invokeKeyring',\n params: {\n snapId: this.#origin,\n request,\n },\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the snap\n * JSON-RPC API.\n */\nexport class KeyringSnapRpcClient extends KeyringClient {\n /**\n * Create a new instance of `KeyringSnapRpcClient`.\n *\n * @param origin - Caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n super(new SnapRpcSender(origin, provider));\n }\n}\n"]}
package/dist/events.d.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  * Supported keyring events.
3
3
  */
4
4
  export declare enum KeyringEvent {
5
- AccountCreated = "event:accountCreated",
6
- AccountUpdated = "event:accountUpdated",
7
- AccountDeleted = "event:accountDeleted",
8
- RequestApproved = "event:requestApproved",
9
- RequestRejected = "event:requestRejected"
5
+ AccountCreated = "notify:accountCreated",
6
+ AccountUpdated = "notify:accountUpdated",
7
+ AccountDeleted = "notify:accountDeleted",
8
+ RequestApproved = "notify:requestApproved",
9
+ RequestRejected = "notify:requestRejected"
10
10
  }
package/dist/events.js CHANGED
@@ -7,11 +7,11 @@ exports.KeyringEvent = void 0;
7
7
  var KeyringEvent;
8
8
  (function (KeyringEvent) {
9
9
  // Account events
10
- KeyringEvent["AccountCreated"] = "event:accountCreated";
11
- KeyringEvent["AccountUpdated"] = "event:accountUpdated";
12
- KeyringEvent["AccountDeleted"] = "event:accountDeleted";
10
+ KeyringEvent["AccountCreated"] = "notify:accountCreated";
11
+ KeyringEvent["AccountUpdated"] = "notify:accountUpdated";
12
+ KeyringEvent["AccountDeleted"] = "notify:accountDeleted";
13
13
  // Request events
14
- KeyringEvent["RequestApproved"] = "event:requestApproved";
15
- KeyringEvent["RequestRejected"] = "event:requestRejected";
14
+ KeyringEvent["RequestApproved"] = "notify:requestApproved";
15
+ KeyringEvent["RequestRejected"] = "notify:requestRejected";
16
16
  })(KeyringEvent = exports.KeyringEvent || (exports.KeyringEvent = {}));
17
17
  //# sourceMappingURL=events.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,YASX;AATD,WAAY,YAAY;IACtB,iBAAiB;IACjB,uDAAuC,CAAA;IACvC,uDAAuC,CAAA;IACvC,uDAAuC,CAAA;IAEvC,iBAAiB;IACjB,yDAAyC,CAAA;IACzC,yDAAyC,CAAA;AAC3C,CAAC,EATW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QASvB","sourcesContent":["/**\n * Supported keyring events.\n */\nexport enum KeyringEvent {\n // Account events\n AccountCreated = 'event:accountCreated',\n AccountUpdated = 'event:accountUpdated',\n AccountDeleted = 'event:accountDeleted',\n\n // Request events\n RequestApproved = 'event:requestApproved',\n RequestRejected = 'event:requestRejected',\n}\n"]}
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,YASX;AATD,WAAY,YAAY;IACtB,iBAAiB;IACjB,wDAAwC,CAAA;IACxC,wDAAwC,CAAA;IACxC,wDAAwC,CAAA;IAExC,iBAAiB;IACjB,0DAA0C,CAAA;IAC1C,0DAA0C,CAAA;AAC5C,CAAC,EATW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QASvB","sourcesContent":["/**\n * Supported keyring events.\n */\nexport enum KeyringEvent {\n // Account events\n AccountCreated = 'notify:accountCreated',\n AccountUpdated = 'notify:accountUpdated',\n AccountDeleted = 'notify:accountDeleted',\n\n // Request events\n RequestApproved = 'notify:requestApproved',\n RequestRejected = 'notify:requestRejected',\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
2
- method: "event:accountCreated";
2
+ method: "notify:accountCreated";
3
3
  params: {
4
4
  account: {
5
5
  type: "eip155:eoa" | "eip155:eip4337";
@@ -10,7 +10,7 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
10
10
  };
11
11
  };
12
12
  }, {
13
- method: import("superstruct").Struct<"event:accountCreated", "event:accountCreated">;
13
+ method: import("superstruct").Struct<"notify:accountCreated", "notify:accountCreated">;
14
14
  params: import("superstruct").Struct<{
15
15
  account: {
16
16
  type: "eip155:eoa" | "eip155:eip4337";
@@ -49,7 +49,7 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
49
49
  }>;
50
50
  }>;
51
51
  export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
52
- method: "event:accountUpdated";
52
+ method: "notify:accountUpdated";
53
53
  params: {
54
54
  account: {
55
55
  type: "eip155:eoa" | "eip155:eip4337";
@@ -60,7 +60,7 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
60
60
  };
61
61
  };
62
62
  }, {
63
- method: import("superstruct").Struct<"event:accountUpdated", "event:accountUpdated">;
63
+ method: import("superstruct").Struct<"notify:accountUpdated", "notify:accountUpdated">;
64
64
  params: import("superstruct").Struct<{
65
65
  account: {
66
66
  type: "eip155:eoa" | "eip155:eip4337";
@@ -99,12 +99,12 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
99
99
  }>;
100
100
  }>;
101
101
  export declare const AccountDeletedEventStruct: import("superstruct").Struct<{
102
- method: "event:accountDeleted";
102
+ method: "notify:accountDeleted";
103
103
  params: {
104
104
  id: string;
105
105
  };
106
106
  }, {
107
- method: import("superstruct").Struct<"event:accountDeleted", "event:accountDeleted">;
107
+ method: import("superstruct").Struct<"notify:accountDeleted", "notify:accountDeleted">;
108
108
  params: import("superstruct").Struct<{
109
109
  id: string;
110
110
  }, {
@@ -115,13 +115,13 @@ export declare const AccountDeletedEventStruct: import("superstruct").Struct<{
115
115
  }>;
116
116
  }>;
117
117
  export declare const RequestApprovedEventStruct: import("superstruct").Struct<{
118
- method: "event:requestApproved";
118
+ method: "notify:requestApproved";
119
119
  params: {
120
120
  id: string;
121
121
  result: import("@metamask/utils").Json;
122
122
  };
123
123
  }, {
124
- method: import("superstruct").Struct<"event:requestApproved", "event:requestApproved">;
124
+ method: import("superstruct").Struct<"notify:requestApproved", "notify:requestApproved">;
125
125
  params: import("superstruct").Struct<{
126
126
  id: string;
127
127
  result: import("@metamask/utils").Json;
@@ -137,12 +137,12 @@ export declare const RequestApprovedEventStruct: import("superstruct").Struct<{
137
137
  }>;
138
138
  }>;
139
139
  export declare const RequestRejectedEventStruct: import("superstruct").Struct<{
140
- method: "event:requestRejected";
140
+ method: "notify:requestRejected";
141
141
  params: {
142
142
  id: string;
143
143
  };
144
144
  }, {
145
- method: import("superstruct").Struct<"event:requestRejected", "event:requestRejected">;
145
+ method: import("superstruct").Struct<"notify:requestRejected", "notify:requestRejected">;
146
146
  params: import("superstruct").Struct<{
147
147
  id: string;
148
148
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "0.2.7",
3
+ "version": "1.0.0-rc.1",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",
@@ -25,7 +25,7 @@
25
25
  "build:clean": "rimraf dist && yarn build",
26
26
  "build:docs": "typedoc",
27
27
  "lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog",
28
- "lint:changelog": "auto-changelog validate",
28
+ "lint:changelog": "auto-changelog validate --prettier",
29
29
  "lint:constraints": "yarn constraints",
30
30
  "lint:dependencies": "depcheck && yarn dedupe",
31
31
  "lint:eslint": "eslint . --cache --ext js,ts",
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@metamask/providers": "^13.0.0",
42
- "@metamask/rpc-methods": "^2.0.0",
43
- "@metamask/snaps-controllers": "^2.0.0",
44
- "@metamask/snaps-utils": "^2.0.0",
42
+ "@metamask/rpc-methods": "^3.0.0",
43
+ "@metamask/snaps-controllers": "^3.0.0",
44
+ "@metamask/snaps-utils": "^3.0.0",
45
45
  "@metamask/utils": "^8.1.0",
46
46
  "@types/uuid": "^9.0.1",
47
47
  "superstruct": "^1.0.3",