@metamask-previews/keyring-api 8.1.0-672cc7b

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/README.md ADDED
@@ -0,0 +1,401 @@
1
+ # MetaMask Keyring API
2
+
3
+ This TypeScript module simplifies the integration of Snaps with MetaMask using
4
+ the Keyring API.
5
+
6
+ Features:
7
+
8
+ - **Keyring API Interface**: The module exposes an interface representing the
9
+ Keyring API. Snaps can implement this interface to seamlessly interact with
10
+ MetaMask and leverage its functionality.
11
+
12
+ - **Dapp Client**: The module includes a client that enables dapps to
13
+ communicate with the account Snap. This client allows dapps to send requests
14
+ to the Snap, such as retrieving account information or submitting requests.
15
+
16
+ - **MetaMask Client**: The module provides a client specifically designed for
17
+ MetaMask integration. This client enables MetaMask to send requests directly
18
+ to the account Snap, facilitating smooth interoperability between the two
19
+ applications.
20
+
21
+ - **Request Handler Helper Functions**: The module offers a set of helper
22
+ functions to simplify the implementation of the request handler in the
23
+ account Snap. These functions assist in processing incoming requests,
24
+ validating data, and handling various request types from dapps and MetaMask.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ yarn add @metamask/keyring-api
30
+ ```
31
+
32
+ or
33
+
34
+ ```bash
35
+ npm install @metamask/keyring-api
36
+ ```
37
+
38
+ ## Account Snaps
39
+
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).
43
+
44
+ Starting with MetaMask 11.4, Snaps can implement the Keyring API. This allows
45
+ users to manage their accounts in a more flexible way, and enables developers
46
+ to build new types of accounts.
47
+
48
+ > :pencil2: **Note:** You can also build MetaMask from [source][extension-repo]
49
+ > from the `develop` branch.
50
+
51
+ Follow these steps to implement the Keyring API in your Snap. Please note that
52
+ these instruction assume that you are already familiar with the process of
53
+ [developing a Snap](https://docs.metamask.io/snaps/).
54
+
55
+ 1. **Implement the Keyring API:**
56
+
57
+ Inside your Snap, implement the `Keyring` API:
58
+
59
+ ```typescript
60
+ class MySnapKeyring implements Keyring {
61
+ // Implement the required methods here...
62
+ }
63
+ ```
64
+
65
+ > :point_up: **Important**: Ensure that your keyring implements the [methods
66
+ > called by MetaMask][exposed-methods], otherwise some features may not
67
+ > work.
68
+
69
+ 2. **Handle requests submitted by MetaMask:**
70
+
71
+ MetaMask will submit requests through the `submitRequest` method of your the
72
+ Keyring API (check the supported [EVM methods](./docs/evm-methods.md)). Here
73
+ is an example of request:
74
+
75
+ ```json
76
+ {
77
+ "id": "d6e23af6-4bea-48dd-aeb0-7d3c30ea67f9",
78
+ "scope": "",
79
+ "account": "69438371-bef3-4957-9f91-c3f22c1d75f3",
80
+ "request": {
81
+ "method": "personal_sign",
82
+ "params": [
83
+ "0x4578616d706c652060706572736f6e616c5f7369676e60206d657373616765",
84
+ "0x5874174dcf1ab6F7Efd8496f4f09404CD1c5bA84"
85
+ ]
86
+ }
87
+ }
88
+ ```
89
+
90
+ Where:
91
+
92
+ - `id` is unique identifier for the request.
93
+
94
+ - `scope` is the CAIP-2 chain ID of the selected chain. Currently, this
95
+ property is always an empty string. Your Snap should use the chain ID
96
+ present in the request object instead.
97
+
98
+ - `account` is the ID of the account that should handle the request.
99
+
100
+ - `request` is the request object.
101
+
102
+ Your Snap must respond with either a synchronous result:
103
+
104
+ ```typescript
105
+ return { pending: false, result };
106
+ ```
107
+
108
+ Or an asynchronous result:
109
+
110
+ ```typescript
111
+ return { pending: true, redirect: { message, url } };
112
+ ```
113
+
114
+ The redirect message and URL will be displayed to the user to inform them
115
+ about how to continue the transaction flow.
116
+
117
+ 3. **Notify MetaMask about events:**
118
+
119
+ The following actions must be notified to MetaMask:
120
+
121
+ 1. When an account is created:
122
+
123
+ ```typescript
124
+ try {
125
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountCreated, { account });
126
+ // Update your snap's state...
127
+ } catch (error) {
128
+ // Handle the error...
129
+ }
130
+ ```
131
+
132
+ MetaMask will return an error if the account already exists or if the
133
+ account object is invalid.
134
+
135
+ 2. When an account is updated:
136
+
137
+ ```typescript
138
+ try {
139
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountUpdated, { account });
140
+ // Update your snap's state...
141
+ } catch (error) {
142
+ // Handle the error...
143
+ }
144
+ ```
145
+
146
+ MetaMask will return an error if the account does not exist, if the
147
+ account object is invalid, or if the account address changed.
148
+
149
+ 3. When an account is deleted:
150
+
151
+ ```typescript
152
+ try {
153
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountDeleted, {
154
+ id: account.id,
155
+ });
156
+ // Update your snap's state...
157
+ } catch (error) {
158
+ // Handle the error...
159
+ }
160
+ ```
161
+
162
+ The delete event is idempotent, so it is safe to emit it even if the
163
+ account does not exist.
164
+
165
+ 4. When a request is approved:
166
+
167
+ ```typescript
168
+ try {
169
+ emitSnapKeyringEvent(snap, KeyringEvent.RequestApproved, {
170
+ id: request.id,
171
+ result,
172
+ });
173
+ // Update your snap's state...
174
+ } catch (error) {
175
+ // Handle the error...
176
+ }
177
+ ```
178
+
179
+ MetaMask will return an error if the request does not exist.
180
+
181
+ > :pencil2: **Note:** This only applies to Snaps that implement the
182
+ > [asynchronous transaction flow][async-flow].
183
+
184
+ 5. When a request is rejected:
185
+
186
+ ```typescript
187
+ try {
188
+ emitSnapKeyringEvent(snap, KeyringEvent.RequestRejected, {
189
+ id: request.id,
190
+ });
191
+ // Update your snap's state...
192
+ } catch (error) {
193
+ // Handle the error...
194
+ }
195
+ ```
196
+
197
+ MetaMask will return an error if the request does not exist.
198
+
199
+ > :pencil2: **Note:** This only applies to Snaps that implement the
200
+ > [asynchronous transaction flow][async-flow].
201
+
202
+ 4. **Expose the Keyring API:**
203
+
204
+ Then create a handler to expose the keyring methods to MetaMask and your dapp:
205
+
206
+ ```typescript
207
+ export const onKeyringRequest: OnKeyringRequestHandler = async ({
208
+ origin,
209
+ request,
210
+ }) => {
211
+ // Your custom logic here...
212
+ return handleKeyringRequest(keyring, request);
213
+ };
214
+ ```
215
+
216
+ 5. **Call the keyring methods from your dapp:**
217
+
218
+ Now you should be able to call your account Snap from your dapp, for
219
+ example:
220
+
221
+ ```typescript
222
+ const client = new KeyringSnapRpcClient(snapId, window.ethereum);
223
+ const accounts = await client.listAccounts();
224
+ ```
225
+
226
+ ## Migrating from 0.1.x to 0.2.x
227
+
228
+ The following changes were made to the API, which may require changes to your
229
+ implementation:
230
+
231
+ - In the `KeyringAccount` type, the `supportedMethods` property was renamed to
232
+ `methods`.
233
+
234
+ ```diff
235
+ - supportedMethods: string[];
236
+ + methods: string[];
237
+ ```
238
+
239
+ - In the `KeyringAccount` type, the `name` property was removed.
240
+
241
+ ```diff
242
+ - name: string;
243
+ ```
244
+
245
+ - In the `KeyringAccount` type, add the `options` property can no longer be
246
+ null.
247
+
248
+ ```diff
249
+ - options: Record<string, unknown> | null;
250
+ + options: Record<string, unknown>;
251
+ ```
252
+
253
+ - In the `KeyringAccount` type, the `eth_signTypedData` method was removed from
254
+ the list of available methods.
255
+
256
+ ```diff
257
+ - 'eth_signTypedData',
258
+ ```
259
+
260
+ It was an alias for the `eth_signTypedData_v1` method, which is still
261
+ present.
262
+
263
+ - Snaps should now use the `emitSnapKeyringEvent()` helper function to notify
264
+ MetaMask about events:
265
+
266
+ ```ts
267
+ // Emit an event to indicate that an account was created.
268
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountCreated, { account });
269
+
270
+ // Emit an event to indicate that an account was updated.
271
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountUpdated, { account });
272
+
273
+ // Emit an event to indicate that an account was deleted.
274
+ emitSnapKeyringEvent(snap, KeyringEvent.AccountDeleted, { id: account.id });
275
+
276
+ // Emit an event to indicate that a request was approved.
277
+ emitSnapKeyringEvent(snap, KeyringEvent.RequestApproved, {
278
+ id: request.id,
279
+ result,
280
+ });
281
+
282
+ // Emit an event to indicate that a request was rejected.
283
+ emitSnapKeyringEvent(snap, KeyringEvent.RequestRejected, { id: request.id });
284
+ ```
285
+
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.
289
+
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
+
295
+ ```ts
296
+ return {
297
+ pending: true,
298
+ redirect: {
299
+ message: 'Please go to the Snap Dapp to finish sining the transaction.',
300
+ url: 'https://example.com/sign?tx=1234',
301
+ },
302
+ };
303
+ ```
304
+
305
+ - The `buildHandlersChain` helper function was removed from the API. Instead,
306
+ you must implement your own handler. For example:
307
+
308
+ ```ts
309
+ export const onRpcRequest: OnRpcRequestHandler = async ({
310
+ request,
311
+ origin,
312
+ }) => {
313
+ // Check if origin is allowed to call the method.
314
+ if (!hasPermission(origin, request.method)) {
315
+ throw new Error(
316
+ `Origin '${origin}' is not allowed to call '${request.method}'`,
317
+ );
318
+ }
319
+
320
+ // Dispatch the request to the keyring.
321
+ return handleKeyringRequest(keyring, request);
322
+ };
323
+ ```
324
+
325
+ ## Migrating from 0.2.x to 1.x.x
326
+
327
+ The following changes were made to the API, which may require changes to your
328
+ implementation:
329
+
330
+ - Your Snap must expose the Keyring methods through the `onKeyringRequest`
331
+ export instead of the `onRpcRequest` export.
332
+
333
+ - Your Snap must request the new `endowment:keyring` endowment, and list any
334
+ dapp that should be allowed to call the Keyring methods.
335
+
336
+ For more details about the changes, please refer to the [security
337
+ guidelines](./docs/security.md).
338
+
339
+ ## API
340
+
341
+ See our documentation:
342
+
343
+ - [Latest published API documentation](https://metamask.github.io/keyring-api/latest/)
344
+ - [Latest development API documentation](https://metamask.github.io/keyring-api/staging/)
345
+
346
+ ## Contributing
347
+
348
+ ### Setup
349
+
350
+ - Install [Node.js](https://nodejs.org) version 16
351
+ - If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
352
+ - Install [Yarn v3](https://yarnpkg.com/getting-started/install)
353
+ - Run `yarn install` to install dependencies and run any required post-install scripts
354
+
355
+ ### Testing and Linting
356
+
357
+ Run `yarn test` to run the tests once. To run tests on file changes, run `yarn test:watch`.
358
+
359
+ Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
360
+
361
+ ### Release & Publishing
362
+
363
+ The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.
364
+
365
+ 1. Choose a release version.
366
+
367
+ - The release version should be chosen according to SemVer. Analyze the changes to see whether they include any breaking changes, new features, or deprecations, then choose the appropriate SemVer version. See [the SemVer specification](https://semver.org/) for more information.
368
+
369
+ 2. If this release is backporting changes onto a previous release, then ensure there is a major version branch for that version (e.g. `1.x` for a `v1` backport release).
370
+
371
+ - The major version branch should be set to the most recent release with that major version. For example, when backporting a `v1.0.2` release, you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` tag.
372
+
373
+ 3. Trigger the [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) for the `Create Release Pull Request` action to create the release PR.
374
+
375
+ - For a backport release, the base branch should be the major version branch that you ensured existed in step 2. For a normal release, the base branch should be the main branch for that repository (which should be the default value).
376
+ - This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.
377
+
378
+ 4. Update the changelog to move each change entry into the appropriate change category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the full list of change categories, and the correct ordering), and edit them to be more easily understood by users of the package.
379
+
380
+ - 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.).
381
+ - Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
382
+ - Consolidate related changes into one change entry if it makes it easier to explain.
383
+ - Run `yarn auto-changelog validate --prettier --rc` to check that the changelog is correctly formatted.
384
+
385
+ 5. Review and QA the release.
386
+
387
+ - If changes are made to the base branch, the release branch will need to be updated with these changes and review/QA will need to restart again. As such, it's probably best to avoid merging other PRs into the base branch while review is underway.
388
+
389
+ 6. Squash & Merge the release.
390
+
391
+ - This should trigger the [`action-publish-release`](https://github.com/MetaMask/action-publish-release) workflow to tag the final release commit and publish the release on GitHub.
392
+
393
+ 7. Publish the release on npm.
394
+
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
+ - Approve the `publish-npm` job (or ask somebody on the npm publishers team to approve it for you).
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
@@ -0,0 +1,62 @@
1
+ import type { Infer } from '@metamask/superstruct';
2
+ /**
3
+ * Supported Ethereum account types.
4
+ */
5
+ export declare enum EthAccountType {
6
+ Eoa = "eip155:eoa",
7
+ Erc4337 = "eip155:erc4337"
8
+ }
9
+ /**
10
+ * Supported Bitcoin account types.
11
+ */
12
+ export declare enum BtcAccountType {
13
+ P2wpkh = "bip122:p2wpkh"
14
+ }
15
+ /**
16
+ * Supported account types.
17
+ */
18
+ export declare type KeyringAccountType = `${EthAccountType.Eoa}` | `${EthAccountType.Erc4337}` | `${BtcAccountType.P2wpkh}`;
19
+ /**
20
+ * A struct which represents a Keyring account object. It is abstract enough to
21
+ * be used with any blockchain. Specific blockchain account types should extend
22
+ * this struct.
23
+ *
24
+ * See {@link KeyringAccount}.
25
+ */
26
+ export declare const KeyringAccountStruct: import("@metamask/superstruct").Struct<{
27
+ id: string;
28
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
29
+ address: string;
30
+ options: Record<string, import("@metamask/utils").Json>;
31
+ methods: string[];
32
+ }, {
33
+ /**
34
+ * Account ID (UUIDv4).
35
+ */
36
+ id: import("@metamask/superstruct").Struct<string, null>;
37
+ /**
38
+ * Account type.
39
+ */
40
+ type: import("@metamask/superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
41
+ "eip155:eoa": "eip155:eoa";
42
+ "eip155:erc4337": "eip155:erc4337";
43
+ "bip122:p2wpkh": "bip122:p2wpkh";
44
+ }>;
45
+ /**
46
+ * Account main address.
47
+ */
48
+ address: import("@metamask/superstruct").Struct<string, null>;
49
+ /**
50
+ * Account options.
51
+ */
52
+ options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
53
+ /**
54
+ * Account supported methods.
55
+ */
56
+ methods: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
57
+ }>;
58
+ /**
59
+ * Keyring Account type represents an account and its properties from the
60
+ * point of view of the keyring.
61
+ */
62
+ export declare type KeyringAccount = Infer<typeof KeyringAccountStruct>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringAccountStruct = exports.BtcAccountType = exports.EthAccountType = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ const utils_1 = require("@metamask/utils");
6
+ const keyring_utils_1 = require("@metamask/keyring-utils");
7
+ /**
8
+ * Supported Ethereum account types.
9
+ */
10
+ var EthAccountType;
11
+ (function (EthAccountType) {
12
+ EthAccountType["Eoa"] = "eip155:eoa";
13
+ EthAccountType["Erc4337"] = "eip155:erc4337";
14
+ })(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
15
+ /**
16
+ * Supported Bitcoin account types.
17
+ */
18
+ var BtcAccountType;
19
+ (function (BtcAccountType) {
20
+ BtcAccountType["P2wpkh"] = "bip122:p2wpkh";
21
+ })(BtcAccountType = exports.BtcAccountType || (exports.BtcAccountType = {}));
22
+ /**
23
+ * A struct which represents a Keyring account object. It is abstract enough to
24
+ * be used with any blockchain. Specific blockchain account types should extend
25
+ * this struct.
26
+ *
27
+ * See {@link KeyringAccount}.
28
+ */
29
+ exports.KeyringAccountStruct = (0, keyring_utils_1.object)({
30
+ /**
31
+ * Account ID (UUIDv4).
32
+ */
33
+ id: keyring_utils_1.UuidStruct,
34
+ /**
35
+ * Account type.
36
+ */
37
+ type: (0, superstruct_1.enums)([
38
+ `${EthAccountType.Eoa}`,
39
+ `${EthAccountType.Erc4337}`,
40
+ `${BtcAccountType.P2wpkh}`,
41
+ ]),
42
+ /**
43
+ * Account main address.
44
+ */
45
+ address: (0, superstruct_1.string)(),
46
+ /**
47
+ * Account options.
48
+ */
49
+ options: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
50
+ /**
51
+ * Account supported methods.
52
+ */
53
+ methods: (0, superstruct_1.array)((0, superstruct_1.string)()),
54
+ });
55
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/api/account.ts"],"names":[],"mappings":";;;AACA,uDAAqE;AACrE,2CAA6C;AAE7C,2DAA6D;AAE7D;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAED;;GAEG;AACH,IAAY,cAEX;AAFD,WAAY,cAAc;IACxB,0CAAwB,CAAA;AAC1B,CAAC,EAFW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAEzB;AAUD;;;;;;GAMG;AACU,QAAA,oBAAoB,GAAG,IAAA,sBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,0BAAU;IAEd;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC;QACV,GAAG,cAAc,CAAC,GAAG,EAAE;QACvB,GAAG,cAAc,CAAC,OAAO,EAAE;QAC3B,GAAG,cAAc,CAAC,MAAM,EAAE;KAC3B,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,GAAE;IAEjB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;IAErC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC;CACzB,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { array, enums, record, string } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { object, UuidStruct } from '@metamask/keyring-utils';\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Erc4337 = 'eip155:erc4337',\n}\n\n/**\n * Supported Bitcoin account types.\n */\nexport enum BtcAccountType {\n P2wpkh = 'bip122:p2wpkh',\n}\n\n/**\n * Supported account types.\n */\nexport type KeyringAccountType =\n | `${EthAccountType.Eoa}`\n | `${EthAccountType.Erc4337}`\n | `${BtcAccountType.P2wpkh}`;\n\n/**\n * A struct which represents a Keyring account object. It is abstract enough to\n * be used with any blockchain. Specific blockchain account types should extend\n * this struct.\n *\n * See {@link KeyringAccount}.\n */\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account type.\n */\n type: enums([\n `${EthAccountType.Eoa}`,\n `${EthAccountType.Erc4337}`,\n `${BtcAccountType.P2wpkh}`,\n ]),\n\n /**\n * Account main address.\n */\n address: string(),\n\n /**\n * Account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(string()),\n});\n\n/**\n * Keyring Account type represents an account and its properties from the\n * point of view of the keyring.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n"]}
@@ -0,0 +1,9 @@
1
+ import type { Infer } from '@metamask/superstruct';
2
+ export declare const BalanceStruct: import("@metamask/superstruct").Struct<{
3
+ amount: string;
4
+ unit: string;
5
+ }, {
6
+ amount: import("@metamask/superstruct").Struct<string, null>;
7
+ unit: import("@metamask/superstruct").Struct<string, null>;
8
+ }>;
9
+ export declare type Balance = Infer<typeof BalanceStruct>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BalanceStruct = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ const keyring_utils_1 = require("@metamask/keyring-utils");
6
+ exports.BalanceStruct = (0, keyring_utils_1.object)({
7
+ amount: keyring_utils_1.StringNumberStruct,
8
+ unit: (0, superstruct_1.string)(),
9
+ });
10
+ //# sourceMappingURL=balance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/api/balance.ts"],"names":[],"mappings":";;;AACA,uDAA+C;AAE/C,2DAAqE;AAExD,QAAA,aAAa,GAAG,IAAA,sBAAM,EAAC;IAClC,MAAM,EAAE,kCAAkB;IAC1B,IAAI,EAAE,IAAA,oBAAM,GAAE;CACf,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { string } from '@metamask/superstruct';\n\nimport { object, StringNumberStruct } from '@metamask/keyring-utils';\n\nexport const BalanceStruct = object({\n amount: StringNumberStruct,\n unit: string(),\n});\n\nexport type Balance = Infer<typeof BalanceStruct>;\n"]}
@@ -0,0 +1,37 @@
1
+ import { type Infer } from '@metamask/superstruct';
2
+ /**
3
+ * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
4
+ */
5
+ export declare const CaipAssetTypeStruct: import("@metamask/superstruct").Struct<string, null>;
6
+ export declare type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;
7
+ /**
8
+ * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
9
+ */
10
+ export declare const CaipAssetIdStruct: import("@metamask/superstruct").Struct<string, null>;
11
+ export declare type CaipAssetId = Infer<typeof CaipAssetIdStruct>;
12
+ /**
13
+ * Check if the given value is a {@link CaipAssetType}.
14
+ *
15
+ * @param value - The value to check.
16
+ * @returns Whether the value is a {@link CaipAssetType}.
17
+ * @example
18
+ * ```ts
19
+ * isCaipAssetType('eip155:1/slip44:60'); // true
20
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true
21
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false
22
+ * ```
23
+ */
24
+ export declare function isCaipAssetType(value: unknown): value is CaipAssetType;
25
+ /**
26
+ * Check if the given value is a {@link CaipAssetId}.
27
+ *
28
+ * @param value - The value to check.
29
+ * @returns Whether the value is a {@link CaipAssetId}.
30
+ * @example
31
+ * ```ts
32
+ * isCaipAssetType('eip155:1/slip44:60'); // false
33
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false
34
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true
35
+ * ```
36
+ */
37
+ export declare function isCaipAssetId(value: unknown): value is CaipAssetId;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCaipAssetId = exports.isCaipAssetType = exports.CaipAssetIdStruct = exports.CaipAssetTypeStruct = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ const keyring_utils_1 = require("@metamask/keyring-utils");
6
+ const CAIP_ASSET_TYPE_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;
7
+ const CAIP_ASSET_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;
8
+ /**
9
+ * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
10
+ */
11
+ exports.CaipAssetTypeStruct = (0, keyring_utils_1.definePattern)('CaipAssetType', CAIP_ASSET_TYPE_REGEX);
12
+ /**
13
+ * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
14
+ */
15
+ exports.CaipAssetIdStruct = (0, keyring_utils_1.definePattern)('CaipAssetId', CAIP_ASSET_ID_REGEX);
16
+ /**
17
+ * Check if the given value is a {@link CaipAssetType}.
18
+ *
19
+ * @param value - The value to check.
20
+ * @returns Whether the value is a {@link CaipAssetType}.
21
+ * @example
22
+ * ```ts
23
+ * isCaipAssetType('eip155:1/slip44:60'); // true
24
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true
25
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false
26
+ * ```
27
+ */
28
+ function isCaipAssetType(value) {
29
+ return (0, superstruct_1.is)(value, exports.CaipAssetTypeStruct);
30
+ }
31
+ exports.isCaipAssetType = isCaipAssetType;
32
+ /**
33
+ * Check if the given value is a {@link CaipAssetId}.
34
+ *
35
+ * @param value - The value to check.
36
+ * @returns Whether the value is a {@link CaipAssetId}.
37
+ * @example
38
+ * ```ts
39
+ * isCaipAssetType('eip155:1/slip44:60'); // false
40
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false
41
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true
42
+ * ```
43
+ */
44
+ function isCaipAssetId(value) {
45
+ return (0, superstruct_1.is)(value, exports.CaipAssetIdStruct);
46
+ }
47
+ exports.isCaipAssetId = isCaipAssetId;
48
+ //# sourceMappingURL=caip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip.js","sourceRoot":"","sources":["../../src/api/caip.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AAEvD,2DAAwD;AAExD,MAAM,qBAAqB,GACzB,2JAA2J,CAAC;AAE9J,MAAM,mBAAmB,GACvB,6LAA6L,CAAC;AAEhM;;GAEG;AACU,QAAA,mBAAmB,GAAG,IAAA,6BAAa,EAC9C,eAAe,EACf,qBAAqB,CACtB,CAAC;AAGF;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,6BAAa,EAC5C,aAAa,EACb,mBAAmB,CACpB,CAAC;AAGF;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,2BAAmB,CAAC,CAAC;AACxC,CAAC;AAFD,0CAEC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,yBAAiB,CAAC,CAAC;AACtC,CAAC;AAFD,sCAEC","sourcesContent":["import { is, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '@metamask/keyring-utils';\n\nconst CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nconst CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct = definePattern(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n);\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct = definePattern(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n);\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // true\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false\n * ```\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // false\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true\n * ```\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { Infer } from '@metamask/superstruct';
2
+ export declare const KeyringAccountDataStruct: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
3
+ /**
4
+ * Response to a call to `exportAccount`.
5
+ *
6
+ * The exact response depends on the keyring implementation.
7
+ */
8
+ export declare type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringAccountDataStruct = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ const utils_1 = require("@metamask/utils");
6
+ exports.KeyringAccountDataStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct);
7
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/api/export.ts"],"names":[],"mappings":";;;AACA,uDAAuD;AACvD,2CAA6C;AAEhC,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { record, string } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\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"]}
@@ -0,0 +1,7 @@
1
+ export * from './account';
2
+ export * from './balance';
3
+ export * from './caip';
4
+ export * from './export';
5
+ export * from './keyring';
6
+ export * from './request';
7
+ export * from './response';